2 * Marvell Wireless LAN device driver: SDIO specific handling
4 * Copyright (C) 2011, Marvell International Ltd.
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
20 #include <linux/firmware.h>
32 #define SDIO_VERSION "1.0"
34 /* The mwifiex_sdio_remove() callback function is called when
35 * user removes this module from kernel space or ejects
36 * the card from the slot. The driver handles these 2 cases
38 * If the user is removing the module, the few commands (FUNC_SHUTDOWN,
39 * HS_CANCEL etc.) are sent to the firmware.
40 * If the card is removed, there is no need to send these command.
42 * The variable 'user_rmmod' is used to distinguish these two
43 * scenarios. This flag is initialized as FALSE in case the card
44 * is removed, and will be set to TRUE for module removal when
45 * module_exit function is called.
49 static struct mwifiex_if_ops sdio_ops;
51 static struct semaphore add_remove_card_sem;
53 static int mwifiex_sdio_resume(struct device *dev);
58 * This function probes an mwifiex device and registers it. It allocates
59 * the card structure, enables SDIO function number and initiates the
60 * device registration and initialization procedure by adding a logical
64 mwifiex_sdio_probe(struct sdio_func *func, const struct sdio_device_id *id)
67 struct sdio_mmc_card *card = NULL;
69 pr_debug("info: vendor=0x%4.04X device=0x%4.04X class=%d function=%d\n",
70 func->vendor, func->device, func->class, func->num);
72 card = kzalloc(sizeof(struct sdio_mmc_card), GFP_KERNEL);
74 pr_err("%s: failed to alloc memory\n", __func__);
80 func->card->quirks |= MMC_QUIRK_BLKSZ_FOR_BYTE_MODE;
82 sdio_claim_host(func);
83 ret = sdio_enable_func(func);
84 sdio_release_host(func);
87 pr_err("%s: failed to enable function\n", __func__);
92 if (mwifiex_add_card(card, &add_remove_card_sem, &sdio_ops)) {
93 pr_err("%s: add card failed\n", __func__);
95 sdio_claim_host(func);
96 ret = sdio_disable_func(func);
97 sdio_release_host(func);
107 * This function removes the interface and frees up the card structure.
110 mwifiex_sdio_remove(struct sdio_func *func)
112 struct sdio_mmc_card *card;
113 struct mwifiex_adapter *adapter;
116 pr_debug("info: SDIO func num=%d\n", func->num);
118 card = sdio_get_drvdata(func);
122 adapter = card->adapter;
123 if (!adapter || !adapter->priv_num)
127 if (adapter->is_suspended)
128 mwifiex_sdio_resume(adapter->dev);
130 for (i = 0; i < adapter->priv_num; i++)
131 if ((GET_BSS_ROLE(adapter->priv[i]) ==
132 MWIFIEX_BSS_ROLE_STA) &&
133 adapter->priv[i]->media_connected)
134 mwifiex_deauthenticate(adapter->priv[i], NULL);
136 mwifiex_init_shutdown_fw(mwifiex_get_priv(adapter,
137 MWIFIEX_BSS_ROLE_ANY),
138 MWIFIEX_FUNC_SHUTDOWN);
141 mwifiex_remove_card(card->adapter, &add_remove_card_sem);
148 * Kernel needs to suspend all functions separately. Therefore all
149 * registered functions must have drivers with suspend and resume
150 * methods. Failing that the kernel simply removes the whole card.
152 * If already not suspended, this function allocates and sends a host
153 * sleep activate request to the firmware and turns off the traffic.
155 static int mwifiex_sdio_suspend(struct device *dev)
157 struct sdio_func *func = dev_to_sdio_func(dev);
158 struct sdio_mmc_card *card;
159 struct mwifiex_adapter *adapter;
160 mmc_pm_flag_t pm_flag = 0;
166 pm_flag = sdio_get_host_pm_caps(func);
167 pr_debug("cmd: %s: suspend: PM flag = 0x%x\n",
168 sdio_func_id(func), pm_flag);
169 if (!(pm_flag & MMC_PM_KEEP_POWER)) {
170 pr_err("%s: cannot remain alive while host is"
171 " suspended\n", sdio_func_id(func));
175 card = sdio_get_drvdata(func);
176 if (!card || !card->adapter) {
177 pr_err("suspend: invalid card or adapter\n");
181 pr_err("suspend: sdio_func is not specified\n");
185 adapter = card->adapter;
187 /* Enable the Host Sleep */
188 hs_actived = mwifiex_enable_hs(adapter);
190 pr_debug("cmd: suspend with MMC_PM_KEEP_POWER\n");
191 ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER);
194 /* Indicate device suspended */
195 adapter->is_suspended = true;
197 for (i = 0; i < adapter->priv_num; i++)
198 netif_carrier_off(adapter->priv[i]->netdev);
206 * Kernel needs to suspend all functions separately. Therefore all
207 * registered functions must have drivers with suspend and resume
208 * methods. Failing that the kernel simply removes the whole card.
210 * If already not resumed, this function turns on the traffic and
211 * sends a host sleep cancel request to the firmware.
213 static int mwifiex_sdio_resume(struct device *dev)
215 struct sdio_func *func = dev_to_sdio_func(dev);
216 struct sdio_mmc_card *card;
217 struct mwifiex_adapter *adapter;
218 mmc_pm_flag_t pm_flag = 0;
222 pm_flag = sdio_get_host_pm_caps(func);
223 card = sdio_get_drvdata(func);
224 if (!card || !card->adapter) {
225 pr_err("resume: invalid card or adapter\n");
229 pr_err("resume: sdio_func is not specified\n");
233 adapter = card->adapter;
235 if (!adapter->is_suspended) {
236 dev_warn(adapter->dev, "device already resumed\n");
240 adapter->is_suspended = false;
242 for (i = 0; i < adapter->priv_num; i++)
243 if (adapter->priv[i]->media_connected)
244 netif_carrier_on(adapter->priv[i]->netdev);
246 /* Disable Host Sleep */
247 mwifiex_cancel_hs(mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA),
253 /* Device ID for SD8787 */
254 #define SDIO_DEVICE_ID_MARVELL_8787 (0x9119)
257 static const struct sdio_device_id mwifiex_ids[] = {
258 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8787)},
262 MODULE_DEVICE_TABLE(sdio, mwifiex_ids);
264 static const struct dev_pm_ops mwifiex_sdio_pm_ops = {
265 .suspend = mwifiex_sdio_suspend,
266 .resume = mwifiex_sdio_resume,
269 static struct sdio_driver mwifiex_sdio = {
270 .name = "mwifiex_sdio",
271 .id_table = mwifiex_ids,
272 .probe = mwifiex_sdio_probe,
273 .remove = mwifiex_sdio_remove,
275 .owner = THIS_MODULE,
276 .pm = &mwifiex_sdio_pm_ops,
281 * This function writes data into SDIO card register.
284 mwifiex_write_reg(struct mwifiex_adapter *adapter, u32 reg, u32 data)
286 struct sdio_mmc_card *card = adapter->card;
289 sdio_claim_host(card->func);
290 sdio_writeb(card->func, (u8) data, reg, &ret);
291 sdio_release_host(card->func);
297 * This function reads data from SDIO card register.
300 mwifiex_read_reg(struct mwifiex_adapter *adapter, u32 reg, u32 *data)
302 struct sdio_mmc_card *card = adapter->card;
306 sdio_claim_host(card->func);
307 val = sdio_readb(card->func, reg, &ret);
308 sdio_release_host(card->func);
316 * This function writes multiple data into SDIO card memory.
318 * This does not work in suspended mode.
321 mwifiex_write_data_sync(struct mwifiex_adapter *adapter,
322 u8 *buffer, u32 pkt_len, u32 port)
324 struct sdio_mmc_card *card = adapter->card;
327 (port & MWIFIEX_SDIO_BYTE_MODE_MASK) ? BYTE_MODE : BLOCK_MODE;
328 u32 blk_size = (blk_mode == BLOCK_MODE) ? MWIFIEX_SDIO_BLOCK_SIZE : 1;
331 BLOCK_MODE) ? (pkt_len /
332 MWIFIEX_SDIO_BLOCK_SIZE) : pkt_len;
333 u32 ioport = (port & MWIFIEX_SDIO_IO_PORT_MASK);
335 if (adapter->is_suspended) {
336 dev_err(adapter->dev,
337 "%s: not allowed while suspended\n", __func__);
341 sdio_claim_host(card->func);
343 if (!sdio_writesb(card->func, ioport, buffer, blk_cnt * blk_size))
346 sdio_release_host(card->func);
352 * This function reads multiple data from SDIO card memory.
354 static int mwifiex_read_data_sync(struct mwifiex_adapter *adapter, u8 *buffer,
355 u32 len, u32 port, u8 claim)
357 struct sdio_mmc_card *card = adapter->card;
360 (port & MWIFIEX_SDIO_BYTE_MODE_MASK) ? BYTE_MODE : BLOCK_MODE;
361 u32 blk_size = (blk_mode == BLOCK_MODE) ? MWIFIEX_SDIO_BLOCK_SIZE : 1;
364 BLOCK_MODE) ? (len / MWIFIEX_SDIO_BLOCK_SIZE) : len;
365 u32 ioport = (port & MWIFIEX_SDIO_IO_PORT_MASK);
368 sdio_claim_host(card->func);
370 if (!sdio_readsb(card->func, buffer, ioport, blk_cnt * blk_size))
374 sdio_release_host(card->func);
380 * This function wakes up the card.
382 * A host power up command is written to the card configuration
383 * register to wake up the card.
385 static int mwifiex_pm_wakeup_card(struct mwifiex_adapter *adapter)
387 dev_dbg(adapter->dev, "event: wakeup device...\n");
389 return mwifiex_write_reg(adapter, CONFIGURATION_REG, HOST_POWER_UP);
393 * This function is called after the card has woken up.
395 * The card configuration register is reset.
397 static int mwifiex_pm_wakeup_card_complete(struct mwifiex_adapter *adapter)
399 dev_dbg(adapter->dev, "cmd: wakeup device completed\n");
401 return mwifiex_write_reg(adapter, CONFIGURATION_REG, 0);
405 * This function initializes the IO ports.
407 * The following operations are performed -
408 * - Read the IO ports (0, 1 and 2)
409 * - Set host interrupt Reset-To-Read to clear
410 * - Set auto re-enable interrupt
412 static int mwifiex_init_sdio_ioport(struct mwifiex_adapter *adapter)
418 /* Read the IO port */
419 if (!mwifiex_read_reg(adapter, IO_PORT_0_REG, ®))
420 adapter->ioport |= (reg & 0xff);
424 if (!mwifiex_read_reg(adapter, IO_PORT_1_REG, ®))
425 adapter->ioport |= ((reg & 0xff) << 8);
429 if (!mwifiex_read_reg(adapter, IO_PORT_2_REG, ®))
430 adapter->ioport |= ((reg & 0xff) << 16);
434 pr_debug("info: SDIO FUNC1 IO port: %#x\n", adapter->ioport);
436 /* Set Host interrupt reset to read to clear */
437 if (!mwifiex_read_reg(adapter, HOST_INT_RSR_REG, ®))
438 mwifiex_write_reg(adapter, HOST_INT_RSR_REG,
439 reg | SDIO_INT_MASK);
443 /* Dnld/Upld ready set to auto reset */
444 if (!mwifiex_read_reg(adapter, CARD_MISC_CFG_REG, ®))
445 mwifiex_write_reg(adapter, CARD_MISC_CFG_REG,
446 reg | AUTO_RE_ENABLE_INT);
454 * This function sends data to the card.
456 static int mwifiex_write_data_to_card(struct mwifiex_adapter *adapter,
457 u8 *payload, u32 pkt_len, u32 port)
463 ret = mwifiex_write_data_sync(adapter, payload, pkt_len, port);
466 dev_err(adapter->dev, "host_to_card, write iomem"
467 " (%d) failed: %d\n", i, ret);
468 if (mwifiex_write_reg(adapter,
469 CONFIGURATION_REG, 0x04))
470 dev_err(adapter->dev, "write CFG reg failed\n");
473 if (i > MAX_WRITE_IOMEM_RETRY)
482 * This function gets the read port.
484 * If control port bit is set in MP read bitmap, the control port
485 * is returned, otherwise the current read port is returned and
486 * the value is increased (provided it does not reach the maximum
487 * limit, in which case it is reset to 1)
489 static int mwifiex_get_rd_port(struct mwifiex_adapter *adapter, u8 *port)
491 struct sdio_mmc_card *card = adapter->card;
492 u16 rd_bitmap = card->mp_rd_bitmap;
494 dev_dbg(adapter->dev, "data: mp_rd_bitmap=0x%04x\n", rd_bitmap);
496 if (!(rd_bitmap & (CTRL_PORT_MASK | DATA_PORT_MASK)))
499 if (card->mp_rd_bitmap & CTRL_PORT_MASK) {
500 card->mp_rd_bitmap &= (u16) (~CTRL_PORT_MASK);
502 dev_dbg(adapter->dev, "data: port=%d mp_rd_bitmap=0x%04x\n",
503 *port, card->mp_rd_bitmap);
505 if (card->mp_rd_bitmap & (1 << card->curr_rd_port)) {
506 card->mp_rd_bitmap &=
507 (u16) (~(1 << card->curr_rd_port));
508 *port = card->curr_rd_port;
510 if (++card->curr_rd_port == MAX_PORT)
511 card->curr_rd_port = 1;
516 dev_dbg(adapter->dev,
517 "data: port=%d mp_rd_bitmap=0x%04x -> 0x%04x\n",
518 *port, rd_bitmap, card->mp_rd_bitmap);
524 * This function gets the write port for data.
526 * The current write port is returned if available and the value is
527 * increased (provided it does not reach the maximum limit, in which
528 * case it is reset to 1)
530 static int mwifiex_get_wr_port_data(struct mwifiex_adapter *adapter, u8 *port)
532 struct sdio_mmc_card *card = adapter->card;
533 u16 wr_bitmap = card->mp_wr_bitmap;
535 dev_dbg(adapter->dev, "data: mp_wr_bitmap=0x%04x\n", wr_bitmap);
537 if (!(wr_bitmap & card->mp_data_port_mask))
540 if (card->mp_wr_bitmap & (1 << card->curr_wr_port)) {
541 card->mp_wr_bitmap &= (u16) (~(1 << card->curr_wr_port));
542 *port = card->curr_wr_port;
543 if (++card->curr_wr_port == card->mp_end_port)
544 card->curr_wr_port = 1;
546 adapter->data_sent = true;
550 if (*port == CTRL_PORT) {
551 dev_err(adapter->dev, "invalid data port=%d cur port=%d"
552 " mp_wr_bitmap=0x%04x -> 0x%04x\n",
553 *port, card->curr_wr_port, wr_bitmap,
558 dev_dbg(adapter->dev, "data: port=%d mp_wr_bitmap=0x%04x -> 0x%04x\n",
559 *port, wr_bitmap, card->mp_wr_bitmap);
565 * This function polls the card status.
568 mwifiex_sdio_poll_card_status(struct mwifiex_adapter *adapter, u8 bits)
573 for (tries = 0; tries < MAX_POLL_TRIES; tries++) {
574 if (mwifiex_read_reg(adapter, CARD_STATUS_REG, &cs))
576 else if ((cs & bits) == bits)
582 dev_err(adapter->dev, "poll card status failed, tries = %d\n",
588 * This function reads the firmware status.
591 mwifiex_sdio_read_fw_status(struct mwifiex_adapter *adapter, u16 *dat)
595 if (mwifiex_read_reg(adapter, CARD_FW_STATUS0_REG, &fws0))
598 if (mwifiex_read_reg(adapter, CARD_FW_STATUS1_REG, &fws1))
601 *dat = (u16) ((fws1 << 8) | fws0);
607 * This function disables the host interrupt.
609 * The host interrupt mask is read, the disable bit is reset and
610 * written back to the card host interrupt mask register.
612 static int mwifiex_sdio_disable_host_int(struct mwifiex_adapter *adapter)
616 /* Read back the host_int_mask register */
617 if (mwifiex_read_reg(adapter, HOST_INT_MASK_REG, &host_int_mask))
620 /* Update with the mask and write back to the register */
621 host_int_mask &= ~HOST_INT_DISABLE;
623 if (mwifiex_write_reg(adapter, HOST_INT_MASK_REG, host_int_mask)) {
624 dev_err(adapter->dev, "disable host interrupt failed\n");
632 * This function enables the host interrupt.
634 * The host interrupt enable mask is written to the card
635 * host interrupt mask register.
637 static int mwifiex_sdio_enable_host_int(struct mwifiex_adapter *adapter)
639 /* Simply write the mask to the register */
640 if (mwifiex_write_reg(adapter, HOST_INT_MASK_REG, HOST_INT_ENABLE)) {
641 dev_err(adapter->dev, "enable host interrupt failed\n");
648 * This function sends a data buffer to the card.
650 static int mwifiex_sdio_card_to_host(struct mwifiex_adapter *adapter,
651 u32 *type, u8 *buffer,
652 u32 npayload, u32 ioport)
658 dev_err(adapter->dev, "%s: buffer is NULL\n", __func__);
662 ret = mwifiex_read_data_sync(adapter, buffer, npayload, ioport, 1);
665 dev_err(adapter->dev, "%s: read iomem failed: %d\n", __func__,
670 nb = le16_to_cpu(*(__le16 *) (buffer));
672 dev_err(adapter->dev, "%s: invalid packet, nb=%d, npayload=%d\n",
673 __func__, nb, npayload);
677 *type = le16_to_cpu(*(__le16 *) (buffer + 2));
683 * This function downloads the firmware to the card.
685 * Firmware is downloaded to the card in blocks. Every block download
686 * is tested for CRC errors, and retried a number of times before
689 static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter,
690 struct mwifiex_fw_image *fw)
693 u8 *firmware = fw->fw_buf;
694 u32 firmware_len = fw->fw_len;
699 u32 txlen, tx_blocks = 0, tries;
703 dev_err(adapter->dev, "firmware image not found!"
704 " Terminating download\n");
708 dev_dbg(adapter->dev, "info: downloading FW image (%d bytes)\n",
711 /* Assume that the allocated buffer is 8-byte aligned */
712 fwbuf = kzalloc(MWIFIEX_UPLD_SIZE, GFP_KERNEL);
714 dev_err(adapter->dev, "unable to alloc buffer for firmware."
715 " Terminating download\n");
719 /* Perform firmware data transfer */
721 /* The host polls for the DN_LD_CARD_RDY and CARD_IO_READY
723 ret = mwifiex_sdio_poll_card_status(adapter, CARD_IO_READY |
726 dev_err(adapter->dev, "FW download with helper:"
727 " poll status timeout @ %d\n", offset);
732 if (offset >= firmware_len)
735 for (tries = 0; tries < MAX_POLL_TRIES; tries++) {
736 ret = mwifiex_read_reg(adapter, HOST_F1_RD_BASE_0,
739 dev_err(adapter->dev, "dev BASE0 register read"
740 " failed: base0=0x%04X(%d). Terminating "
741 "download\n", base0, base0);
744 ret = mwifiex_read_reg(adapter, HOST_F1_RD_BASE_1,
747 dev_err(adapter->dev, "dev BASE1 register read"
748 " failed: base1=0x%04X(%d). Terminating "
749 "download\n", base1, base1);
752 len = (u16) (((base1 & 0xff) << 8) | (base0 & 0xff));
762 } else if (len > MWIFIEX_UPLD_SIZE) {
763 dev_err(adapter->dev, "FW download failed @ %d,"
764 " invalid length %d\n", offset, len);
773 if (i > MAX_WRITE_IOMEM_RETRY) {
774 dev_err(adapter->dev, "FW download failed @"
775 " %d, over max retry count\n", offset);
779 dev_err(adapter->dev, "CRC indicated by the helper:"
780 " len = 0x%04X, txlen = %d\n", len, txlen);
782 /* Setting this to 0 to resend from same offset */
787 /* Set blocksize to transfer - checking for last
789 if (firmware_len - offset < txlen)
790 txlen = firmware_len - offset;
792 tx_blocks = (txlen + MWIFIEX_SDIO_BLOCK_SIZE -
793 1) / MWIFIEX_SDIO_BLOCK_SIZE;
795 /* Copy payload to buffer */
796 memmove(fwbuf, &firmware[offset], txlen);
799 ret = mwifiex_write_data_sync(adapter, fwbuf, tx_blocks *
800 MWIFIEX_SDIO_BLOCK_SIZE,
803 dev_err(adapter->dev, "FW download, write iomem (%d)"
804 " failed @ %d\n", i, offset);
805 if (mwifiex_write_reg(adapter, CONFIGURATION_REG, 0x04))
806 dev_err(adapter->dev, "write CFG reg failed\n");
815 dev_dbg(adapter->dev, "info: FW download over, size %d bytes\n",
825 * This function checks the firmware status in card.
827 * The winner interface is also determined by this function.
829 static int mwifiex_check_fw_status(struct mwifiex_adapter *adapter,
830 u32 poll_num, int *winner)
837 /* Wait for firmware initialization event */
838 for (tries = 0; tries < poll_num; tries++) {
839 ret = mwifiex_sdio_read_fw_status(adapter, &firmware_stat);
842 if (firmware_stat == FIRMWARE_READY) {
853 (adapter, CARD_FW_STATUS0_REG, &winner_status))
865 * This function reads the interrupt status from card.
867 static void mwifiex_interrupt_status(struct mwifiex_adapter *adapter)
869 struct sdio_mmc_card *card = adapter->card;
873 if (mwifiex_read_data_sync(adapter, card->mp_regs, MAX_MP_REGS,
874 REG_PORT | MWIFIEX_SDIO_BYTE_MODE_MASK,
876 dev_err(adapter->dev, "read mp_regs failed\n");
880 sdio_ireg = card->mp_regs[HOST_INTSTATUS_REG];
883 * DN_LD_HOST_INT_STATUS and/or UP_LD_HOST_INT_STATUS
884 * Clear the interrupt status register
886 dev_dbg(adapter->dev, "int: sdio_ireg = %#x\n", sdio_ireg);
887 spin_lock_irqsave(&adapter->int_lock, flags);
888 adapter->int_status |= sdio_ireg;
889 spin_unlock_irqrestore(&adapter->int_lock, flags);
894 * SDIO interrupt handler.
896 * This function reads the interrupt status from firmware and assigns
897 * the main process in workqueue which will handle the interrupt.
900 mwifiex_sdio_interrupt(struct sdio_func *func)
902 struct mwifiex_adapter *adapter;
903 struct sdio_mmc_card *card;
905 card = sdio_get_drvdata(func);
906 if (!card || !card->adapter) {
907 pr_debug("int: func=%p card=%p adapter=%p\n",
908 func, card, card ? card->adapter : NULL);
911 adapter = card->adapter;
913 if (adapter->surprise_removed)
916 if (!adapter->pps_uapsd_mode && adapter->ps_state == PS_STATE_SLEEP)
917 adapter->ps_state = PS_STATE_AWAKE;
919 mwifiex_interrupt_status(adapter);
920 queue_work(adapter->workqueue, &adapter->main_work);
924 * This function decodes a received packet.
926 * Based on the type, the packet is treated as either a data, or
927 * a command response, or an event, and the correct handler
928 * function is invoked.
930 static int mwifiex_decode_rx_packet(struct mwifiex_adapter *adapter,
931 struct sk_buff *skb, u32 upld_typ)
935 skb_pull(skb, INTF_HEADER_LEN);
938 case MWIFIEX_TYPE_DATA:
939 dev_dbg(adapter->dev, "info: --- Rx: Data packet ---\n");
940 mwifiex_handle_rx_packet(adapter, skb);
943 case MWIFIEX_TYPE_CMD:
944 dev_dbg(adapter->dev, "info: --- Rx: Cmd Response ---\n");
945 /* take care of curr_cmd = NULL case */
946 if (!adapter->curr_cmd) {
947 cmd_buf = adapter->upld_buf;
949 if (adapter->ps_state == PS_STATE_SLEEP_CFM)
950 mwifiex_process_sleep_confirm_resp(adapter,
951 skb->data, skb->len);
953 memcpy(cmd_buf, skb->data, min_t(u32,
954 MWIFIEX_SIZE_OF_CMD_BUFFER, skb->len));
956 dev_kfree_skb_any(skb);
958 adapter->cmd_resp_received = true;
959 adapter->curr_cmd->resp_skb = skb;
963 case MWIFIEX_TYPE_EVENT:
964 dev_dbg(adapter->dev, "info: --- Rx: Event ---\n");
965 adapter->event_cause = *(u32 *) skb->data;
967 skb_pull(skb, MWIFIEX_EVENT_HEADER_LEN);
969 if ((skb->len > 0) && (skb->len < MAX_EVENT_SIZE))
970 memcpy(adapter->event_body, skb->data, skb->len);
972 /* event cause has been saved to adapter->event_cause */
973 adapter->event_received = true;
974 adapter->event_skb = skb;
979 dev_err(adapter->dev, "unknown upload type %#x\n", upld_typ);
980 dev_kfree_skb_any(skb);
988 * This function transfers received packets from card to driver, performing
989 * aggregation if required.
991 * For data received on control port, or if aggregation is disabled, the
992 * received buffers are uploaded as separate packets. However, if aggregation
993 * is enabled and required, the buffers are copied onto an aggregation buffer,
994 * provided there is space left, processed and finally uploaded.
996 static int mwifiex_sdio_card_to_host_mp_aggr(struct mwifiex_adapter *adapter,
997 struct sk_buff *skb, u8 port)
999 struct sdio_mmc_card *card = adapter->card;
1000 s32 f_do_rx_aggr = 0;
1001 s32 f_do_rx_cur = 0;
1003 struct sk_buff *skb_deaggr;
1005 u32 pkt_len, pkt_type = 0;
1007 u32 rx_len = skb->len;
1009 if (port == CTRL_PORT) {
1010 /* Read the command Resp without aggr */
1011 dev_dbg(adapter->dev, "info: %s: no aggregation for cmd "
1012 "response\n", __func__);
1015 goto rx_curr_single;
1018 if (!card->mpa_rx.enabled) {
1019 dev_dbg(adapter->dev, "info: %s: rx aggregation disabled\n",
1023 goto rx_curr_single;
1026 if (card->mp_rd_bitmap & (~((u16) CTRL_PORT_MASK))) {
1027 /* Some more data RX pending */
1028 dev_dbg(adapter->dev, "info: %s: not last packet\n", __func__);
1030 if (MP_RX_AGGR_IN_PROGRESS(card)) {
1031 if (MP_RX_AGGR_BUF_HAS_ROOM(card, skb->len)) {
1034 /* No room in Aggr buf, do rx aggr now */
1039 /* Rx aggr not in progress */
1044 /* No more data RX pending */
1045 dev_dbg(adapter->dev, "info: %s: last packet\n", __func__);
1047 if (MP_RX_AGGR_IN_PROGRESS(card)) {
1049 if (MP_RX_AGGR_BUF_HAS_ROOM(card, skb->len))
1052 /* No room in Aggr buf, do rx aggr now */
1060 dev_dbg(adapter->dev, "info: current packet aggregation\n");
1061 /* Curr pkt can be aggregated */
1062 MP_RX_AGGR_SETUP(card, skb, port);
1064 if (MP_RX_AGGR_PKT_LIMIT_REACHED(card) ||
1065 MP_RX_AGGR_PORT_LIMIT_REACHED(card)) {
1066 dev_dbg(adapter->dev, "info: %s: aggregated packet "
1067 "limit reached\n", __func__);
1068 /* No more pkts allowed in Aggr buf, rx it */
1074 /* do aggr RX now */
1075 dev_dbg(adapter->dev, "info: do_rx_aggr: num of packets: %d\n",
1076 card->mpa_rx.pkt_cnt);
1078 if (mwifiex_read_data_sync(adapter, card->mpa_rx.buf,
1079 card->mpa_rx.buf_len,
1080 (adapter->ioport | 0x1000 |
1081 (card->mpa_rx.ports << 4)) +
1082 card->mpa_rx.start_port, 1))
1085 curr_ptr = card->mpa_rx.buf;
1087 for (pind = 0; pind < card->mpa_rx.pkt_cnt; pind++) {
1089 /* get curr PKT len & type */
1090 pkt_len = *(u16 *) &curr_ptr[0];
1091 pkt_type = *(u16 *) &curr_ptr[2];
1093 /* copy pkt to deaggr buf */
1094 skb_deaggr = card->mpa_rx.skb_arr[pind];
1096 if ((pkt_type == MWIFIEX_TYPE_DATA) && (pkt_len <=
1097 card->mpa_rx.len_arr[pind])) {
1099 memcpy(skb_deaggr->data, curr_ptr, pkt_len);
1101 skb_trim(skb_deaggr, pkt_len);
1103 /* Process de-aggr packet */
1104 mwifiex_decode_rx_packet(adapter, skb_deaggr,
1107 dev_err(adapter->dev, "wrong aggr pkt:"
1108 " type=%d len=%d max_len=%d\n",
1110 card->mpa_rx.len_arr[pind]);
1111 dev_kfree_skb_any(skb_deaggr);
1113 curr_ptr += card->mpa_rx.len_arr[pind];
1115 MP_RX_AGGR_BUF_RESET(card);
1120 dev_dbg(adapter->dev, "info: RX: port: %d, rx_len: %d\n",
1123 if (mwifiex_sdio_card_to_host(adapter, &pkt_type,
1124 skb->data, skb->len,
1125 adapter->ioport + port))
1128 mwifiex_decode_rx_packet(adapter, skb, pkt_type);
1135 * This function checks the current interrupt status.
1137 * The following interrupts are checked and handled by this function -
1140 * - Packets received
1142 * Since the firmware does not generate download ready interrupt if the
1143 * port updated is command port only, command sent interrupt checking
1144 * should be done manually, and for every SDIO interrupt.
1146 * In case of Rx packets received, the packets are uploaded from card to
1147 * host and processed accordingly.
1149 static int mwifiex_process_int_status(struct mwifiex_adapter *adapter)
1151 struct sdio_mmc_card *card = adapter->card;
1154 struct sk_buff *skb;
1155 u8 port = CTRL_PORT;
1156 u32 len_reg_l, len_reg_u;
1159 unsigned long flags;
1161 spin_lock_irqsave(&adapter->int_lock, flags);
1162 sdio_ireg = adapter->int_status;
1163 adapter->int_status = 0;
1164 spin_unlock_irqrestore(&adapter->int_lock, flags);
1169 if (sdio_ireg & DN_LD_HOST_INT_STATUS) {
1170 card->mp_wr_bitmap = ((u16) card->mp_regs[WR_BITMAP_U]) << 8;
1171 card->mp_wr_bitmap |= (u16) card->mp_regs[WR_BITMAP_L];
1172 dev_dbg(adapter->dev, "int: DNLD: wr_bitmap=0x%04x\n",
1173 card->mp_wr_bitmap);
1174 if (adapter->data_sent &&
1175 (card->mp_wr_bitmap & card->mp_data_port_mask)) {
1176 dev_dbg(adapter->dev,
1177 "info: <--- Tx DONE Interrupt --->\n");
1178 adapter->data_sent = false;
1182 /* As firmware will not generate download ready interrupt if the port
1183 updated is command port only, cmd_sent should be done for any SDIO
1185 if (adapter->cmd_sent) {
1186 /* Check if firmware has attach buffer at command port and
1187 update just that in wr_bit_map. */
1188 card->mp_wr_bitmap |=
1189 (u16) card->mp_regs[WR_BITMAP_L] & CTRL_PORT_MASK;
1190 if (card->mp_wr_bitmap & CTRL_PORT_MASK)
1191 adapter->cmd_sent = false;
1194 dev_dbg(adapter->dev, "info: cmd_sent=%d data_sent=%d\n",
1195 adapter->cmd_sent, adapter->data_sent);
1196 if (sdio_ireg & UP_LD_HOST_INT_STATUS) {
1197 card->mp_rd_bitmap = ((u16) card->mp_regs[RD_BITMAP_U]) << 8;
1198 card->mp_rd_bitmap |= (u16) card->mp_regs[RD_BITMAP_L];
1199 dev_dbg(adapter->dev, "int: UPLD: rd_bitmap=0x%04x\n",
1200 card->mp_rd_bitmap);
1203 ret = mwifiex_get_rd_port(adapter, &port);
1205 dev_dbg(adapter->dev,
1206 "info: no more rd_port available\n");
1209 len_reg_l = RD_LEN_P0_L + (port << 1);
1210 len_reg_u = RD_LEN_P0_U + (port << 1);
1211 rx_len = ((u16) card->mp_regs[len_reg_u]) << 8;
1212 rx_len |= (u16) card->mp_regs[len_reg_l];
1213 dev_dbg(adapter->dev, "info: RX: port=%d rx_len=%u\n",
1216 (rx_len + MWIFIEX_SDIO_BLOCK_SIZE -
1217 1) / MWIFIEX_SDIO_BLOCK_SIZE;
1218 if (rx_len <= INTF_HEADER_LEN
1219 || (rx_blocks * MWIFIEX_SDIO_BLOCK_SIZE) >
1220 MWIFIEX_RX_DATA_BUF_SIZE) {
1221 dev_err(adapter->dev, "invalid rx_len=%d\n",
1225 rx_len = (u16) (rx_blocks * MWIFIEX_SDIO_BLOCK_SIZE);
1227 skb = dev_alloc_skb(rx_len);
1230 dev_err(adapter->dev, "%s: failed to alloc skb",
1235 skb_put(skb, rx_len);
1237 dev_dbg(adapter->dev, "info: rx_len = %d skb->len = %d\n",
1240 if (mwifiex_sdio_card_to_host_mp_aggr(adapter, skb,
1244 dev_err(adapter->dev, "card_to_host_mpa failed:"
1245 " int status=%#x\n", sdio_ireg);
1246 if (mwifiex_read_reg(adapter,
1247 CONFIGURATION_REG, &cr))
1248 dev_err(adapter->dev,
1249 "read CFG reg failed\n");
1251 dev_dbg(adapter->dev,
1252 "info: CFG reg val = %d\n", cr);
1253 if (mwifiex_write_reg(adapter,
1256 dev_err(adapter->dev,
1257 "write CFG reg failed\n");
1259 dev_dbg(adapter->dev, "info: write success\n");
1260 if (mwifiex_read_reg(adapter,
1261 CONFIGURATION_REG, &cr))
1262 dev_err(adapter->dev,
1263 "read CFG reg failed\n");
1265 dev_dbg(adapter->dev,
1266 "info: CFG reg val =%x\n", cr);
1267 dev_kfree_skb_any(skb);
1277 * This function aggregates transmission buffers in driver and downloads
1278 * the aggregated packet to card.
1280 * The individual packets are aggregated by copying into an aggregation
1281 * buffer and then downloaded to the card. Previous unsent packets in the
1282 * aggregation buffer are pre-copied first before new packets are added.
1283 * Aggregation is done till there is space left in the aggregation buffer,
1284 * or till new packets are available.
1286 * The function will only download the packet to the card when aggregation
1287 * stops, otherwise it will just aggregate the packet in aggregation buffer
1290 static int mwifiex_host_to_card_mp_aggr(struct mwifiex_adapter *adapter,
1291 u8 *payload, u32 pkt_len, u8 port,
1294 struct sdio_mmc_card *card = adapter->card;
1296 s32 f_send_aggr_buf = 0;
1297 s32 f_send_cur_buf = 0;
1298 s32 f_precopy_cur_buf = 0;
1299 s32 f_postcopy_cur_buf = 0;
1301 if ((!card->mpa_tx.enabled) || (port == CTRL_PORT)) {
1302 dev_dbg(adapter->dev, "info: %s: tx aggregation disabled\n",
1306 goto tx_curr_single;
1310 /* More pkt in TX queue */
1311 dev_dbg(adapter->dev, "info: %s: more packets in queue.\n",
1314 if (MP_TX_AGGR_IN_PROGRESS(card)) {
1315 if (!MP_TX_AGGR_PORT_LIMIT_REACHED(card) &&
1316 MP_TX_AGGR_BUF_HAS_ROOM(card, pkt_len)) {
1317 f_precopy_cur_buf = 1;
1319 if (!(card->mp_wr_bitmap &
1320 (1 << card->curr_wr_port))
1321 || !MP_TX_AGGR_BUF_HAS_ROOM(
1322 card, next_pkt_len))
1323 f_send_aggr_buf = 1;
1325 /* No room in Aggr buf, send it */
1326 f_send_aggr_buf = 1;
1328 if (MP_TX_AGGR_PORT_LIMIT_REACHED(card) ||
1329 !(card->mp_wr_bitmap &
1330 (1 << card->curr_wr_port)))
1333 f_postcopy_cur_buf = 1;
1336 if (MP_TX_AGGR_BUF_HAS_ROOM(card, pkt_len)
1337 && (card->mp_wr_bitmap & (1 << card->curr_wr_port)))
1338 f_precopy_cur_buf = 1;
1343 /* Last pkt in TX queue */
1344 dev_dbg(adapter->dev, "info: %s: Last packet in Tx Queue.\n",
1347 if (MP_TX_AGGR_IN_PROGRESS(card)) {
1348 /* some packs in Aggr buf already */
1349 f_send_aggr_buf = 1;
1351 if (MP_TX_AGGR_BUF_HAS_ROOM(card, pkt_len))
1352 f_precopy_cur_buf = 1;
1354 /* No room in Aggr buf, send it */
1361 if (f_precopy_cur_buf) {
1362 dev_dbg(adapter->dev, "data: %s: precopy current buffer\n",
1364 MP_TX_AGGR_BUF_PUT(card, payload, pkt_len, port);
1366 if (MP_TX_AGGR_PKT_LIMIT_REACHED(card) ||
1367 MP_TX_AGGR_PORT_LIMIT_REACHED(card))
1368 /* No more pkts allowed in Aggr buf, send it */
1369 f_send_aggr_buf = 1;
1372 if (f_send_aggr_buf) {
1373 dev_dbg(adapter->dev, "data: %s: send aggr buffer: %d %d\n",
1375 card->mpa_tx.start_port, card->mpa_tx.ports);
1376 ret = mwifiex_write_data_to_card(adapter, card->mpa_tx.buf,
1377 card->mpa_tx.buf_len,
1378 (adapter->ioport | 0x1000 |
1379 (card->mpa_tx.ports << 4)) +
1380 card->mpa_tx.start_port);
1382 MP_TX_AGGR_BUF_RESET(card);
1386 if (f_send_cur_buf) {
1387 dev_dbg(adapter->dev, "data: %s: send current buffer %d\n",
1389 ret = mwifiex_write_data_to_card(adapter, payload, pkt_len,
1390 adapter->ioport + port);
1393 if (f_postcopy_cur_buf) {
1394 dev_dbg(adapter->dev, "data: %s: postcopy current buffer\n",
1396 MP_TX_AGGR_BUF_PUT(card, payload, pkt_len, port);
1403 * This function downloads data from driver to card.
1405 * Both commands and data packets are transferred to the card by this
1408 * This function adds the SDIO specific header to the front of the buffer
1409 * before transferring. The header contains the length of the packet and
1410 * the type. The firmware handles the packets based upon this set type.
1412 static int mwifiex_sdio_host_to_card(struct mwifiex_adapter *adapter,
1413 u8 type, u8 *payload, u32 pkt_len,
1414 struct mwifiex_tx_param *tx_param)
1416 struct sdio_mmc_card *card = adapter->card;
1420 u8 port = CTRL_PORT;
1422 /* Allocate buffer and copy payload */
1423 blk_size = MWIFIEX_SDIO_BLOCK_SIZE;
1424 buf_block_len = (pkt_len + blk_size - 1) / blk_size;
1425 *(u16 *) &payload[0] = (u16) pkt_len;
1426 *(u16 *) &payload[2] = type;
1429 * This is SDIO specific header
1431 * u16 type (MWIFIEX_TYPE_DATA = 0, MWIFIEX_TYPE_CMD = 1,
1432 * MWIFIEX_TYPE_EVENT = 3)
1434 if (type == MWIFIEX_TYPE_DATA) {
1435 ret = mwifiex_get_wr_port_data(adapter, &port);
1437 dev_err(adapter->dev, "%s: no wr_port available\n",
1442 adapter->cmd_sent = true;
1443 /* Type must be MWIFIEX_TYPE_CMD */
1445 if (pkt_len <= INTF_HEADER_LEN ||
1446 pkt_len > MWIFIEX_UPLD_SIZE)
1447 dev_err(adapter->dev, "%s: payload=%p, nb=%d\n",
1448 __func__, payload, pkt_len);
1451 /* Transfer data to card */
1452 pkt_len = buf_block_len * blk_size;
1455 ret = mwifiex_host_to_card_mp_aggr(adapter, payload, pkt_len,
1456 port, tx_param->next_pkt_len);
1458 ret = mwifiex_host_to_card_mp_aggr(adapter, payload, pkt_len,
1462 if (type == MWIFIEX_TYPE_CMD)
1463 adapter->cmd_sent = false;
1464 if (type == MWIFIEX_TYPE_DATA)
1465 adapter->data_sent = false;
1467 if (type == MWIFIEX_TYPE_DATA) {
1468 if (!(card->mp_wr_bitmap & (1 << card->curr_wr_port)))
1469 adapter->data_sent = true;
1471 adapter->data_sent = false;
1479 * This function allocates the MPA Tx and Rx buffers.
1481 static int mwifiex_alloc_sdio_mpa_buffers(struct mwifiex_adapter *adapter,
1482 u32 mpa_tx_buf_size, u32 mpa_rx_buf_size)
1484 struct sdio_mmc_card *card = adapter->card;
1487 card->mpa_tx.buf = kzalloc(mpa_tx_buf_size, GFP_KERNEL);
1488 if (!card->mpa_tx.buf) {
1489 dev_err(adapter->dev, "could not alloc buffer for MP-A TX\n");
1494 card->mpa_tx.buf_size = mpa_tx_buf_size;
1496 card->mpa_rx.buf = kzalloc(mpa_rx_buf_size, GFP_KERNEL);
1497 if (!card->mpa_rx.buf) {
1498 dev_err(adapter->dev, "could not alloc buffer for MP-A RX\n");
1503 card->mpa_rx.buf_size = mpa_rx_buf_size;
1507 kfree(card->mpa_tx.buf);
1508 kfree(card->mpa_rx.buf);
1515 * This function unregisters the SDIO device.
1517 * The SDIO IRQ is released, the function is disabled and driver
1518 * data is set to null.
1521 mwifiex_unregister_dev(struct mwifiex_adapter *adapter)
1523 struct sdio_mmc_card *card = adapter->card;
1525 if (adapter->card) {
1526 /* Release the SDIO IRQ */
1527 sdio_claim_host(card->func);
1528 sdio_release_irq(card->func);
1529 sdio_disable_func(card->func);
1530 sdio_release_host(card->func);
1531 sdio_set_drvdata(card->func, NULL);
1536 * This function registers the SDIO device.
1538 * SDIO IRQ is claimed, block size is set and driver data is initialized.
1540 static int mwifiex_register_dev(struct mwifiex_adapter *adapter)
1543 struct sdio_mmc_card *card = adapter->card;
1544 struct sdio_func *func = card->func;
1546 /* save adapter pointer in card */
1547 card->adapter = adapter;
1549 sdio_claim_host(func);
1551 /* Request the SDIO IRQ */
1552 ret = sdio_claim_irq(func, mwifiex_sdio_interrupt);
1554 pr_err("claim irq failed: ret=%d\n", ret);
1558 /* Set block size */
1559 ret = sdio_set_block_size(card->func, MWIFIEX_SDIO_BLOCK_SIZE);
1561 pr_err("cannot set SDIO block size\n");
1566 sdio_release_host(func);
1567 sdio_set_drvdata(func, card);
1569 adapter->dev = &func->dev;
1570 strcpy(adapter->fw_name, SD8787_DEFAULT_FW_NAME);
1575 sdio_release_irq(func);
1577 sdio_disable_func(func);
1578 sdio_release_host(func);
1579 adapter->card = NULL;
1585 * This function initializes the SDIO driver.
1587 * The following initializations steps are followed -
1588 * - Read the Host interrupt status register to acknowledge
1589 * the first interrupt got from bootloader
1590 * - Disable host interrupt mask register
1592 * - Initialize SDIO variables in card
1593 * - Allocate MP registers
1594 * - Allocate MPA Tx and Rx buffers
1596 static int mwifiex_init_sdio(struct mwifiex_adapter *adapter)
1598 struct sdio_mmc_card *card = adapter->card;
1603 * Read the HOST_INT_STATUS_REG for ACK the first interrupt got
1604 * from the bootloader. If we don't do this we get a interrupt
1605 * as soon as we register the irq.
1607 mwifiex_read_reg(adapter, HOST_INTSTATUS_REG, &sdio_ireg);
1609 /* Disable host interrupt mask register for SDIO */
1610 mwifiex_sdio_disable_host_int(adapter);
1612 /* Get SDIO ioport */
1613 mwifiex_init_sdio_ioport(adapter);
1615 /* Initialize SDIO variables in card */
1616 card->mp_rd_bitmap = 0;
1617 card->mp_wr_bitmap = 0;
1618 card->curr_rd_port = 1;
1619 card->curr_wr_port = 1;
1621 card->mp_data_port_mask = DATA_PORT_MASK;
1623 card->mpa_tx.buf_len = 0;
1624 card->mpa_tx.pkt_cnt = 0;
1625 card->mpa_tx.start_port = 0;
1627 card->mpa_tx.enabled = 0;
1628 card->mpa_tx.pkt_aggr_limit = SDIO_MP_AGGR_DEF_PKT_LIMIT;
1630 card->mpa_rx.buf_len = 0;
1631 card->mpa_rx.pkt_cnt = 0;
1632 card->mpa_rx.start_port = 0;
1634 card->mpa_rx.enabled = 0;
1635 card->mpa_rx.pkt_aggr_limit = SDIO_MP_AGGR_DEF_PKT_LIMIT;
1637 /* Allocate buffers for SDIO MP-A */
1638 card->mp_regs = kzalloc(MAX_MP_REGS, GFP_KERNEL);
1639 if (!card->mp_regs) {
1640 dev_err(adapter->dev, "failed to alloc mp_regs\n");
1644 ret = mwifiex_alloc_sdio_mpa_buffers(adapter,
1645 SDIO_MP_TX_AGGR_DEF_BUF_SIZE,
1646 SDIO_MP_RX_AGGR_DEF_BUF_SIZE);
1648 dev_err(adapter->dev, "failed to alloc sdio mp-a buffers\n");
1649 kfree(card->mp_regs);
1657 * This function resets the MPA Tx and Rx buffers.
1659 static void mwifiex_cleanup_mpa_buf(struct mwifiex_adapter *adapter)
1661 struct sdio_mmc_card *card = adapter->card;
1663 MP_TX_AGGR_BUF_RESET(card);
1664 MP_RX_AGGR_BUF_RESET(card);
1668 * This function cleans up the allocated card buffers.
1670 * The following are freed by this function -
1675 static void mwifiex_cleanup_sdio(struct mwifiex_adapter *adapter)
1677 struct sdio_mmc_card *card = adapter->card;
1679 kfree(card->mp_regs);
1680 kfree(card->mpa_tx.buf);
1681 kfree(card->mpa_rx.buf);
1685 * This function updates the MP end port in card.
1688 mwifiex_update_mp_end_port(struct mwifiex_adapter *adapter, u16 port)
1690 struct sdio_mmc_card *card = adapter->card;
1693 card->mp_end_port = port;
1695 card->mp_data_port_mask = DATA_PORT_MASK;
1697 for (i = 1; i <= MAX_PORT - card->mp_end_port; i++)
1698 card->mp_data_port_mask &= ~(1 << (MAX_PORT - i));
1700 card->curr_wr_port = 1;
1702 dev_dbg(adapter->dev, "cmd: mp_end_port %d, data port mask 0x%x\n",
1703 port, card->mp_data_port_mask);
1706 static struct mwifiex_if_ops sdio_ops = {
1707 .init_if = mwifiex_init_sdio,
1708 .cleanup_if = mwifiex_cleanup_sdio,
1709 .check_fw_status = mwifiex_check_fw_status,
1710 .prog_fw = mwifiex_prog_fw_w_helper,
1711 .register_dev = mwifiex_register_dev,
1712 .unregister_dev = mwifiex_unregister_dev,
1713 .enable_int = mwifiex_sdio_enable_host_int,
1714 .process_int_status = mwifiex_process_int_status,
1715 .host_to_card = mwifiex_sdio_host_to_card,
1716 .wakeup = mwifiex_pm_wakeup_card,
1717 .wakeup_complete = mwifiex_pm_wakeup_card_complete,
1720 .update_mp_end_port = mwifiex_update_mp_end_port,
1721 .cleanup_mpa_buf = mwifiex_cleanup_mpa_buf,
1725 * This function initializes the SDIO driver.
1727 * This initiates the semaphore and registers the device with
1731 mwifiex_sdio_init_module(void)
1733 sema_init(&add_remove_card_sem, 1);
1735 /* Clear the flag in case user removes the card. */
1738 return sdio_register_driver(&mwifiex_sdio);
1742 * This function cleans up the SDIO driver.
1744 * The following major steps are followed for cleanup -
1745 * - Resume the device if its suspended
1746 * - Disconnect the device if connected
1747 * - Shutdown the firmware
1748 * - Unregister the device from SDIO bus.
1751 mwifiex_sdio_cleanup_module(void)
1753 if (!down_interruptible(&add_remove_card_sem))
1754 up(&add_remove_card_sem);
1756 /* Set the flag as user is removing this module. */
1759 sdio_unregister_driver(&mwifiex_sdio);
1762 module_init(mwifiex_sdio_init_module);
1763 module_exit(mwifiex_sdio_cleanup_module);
1765 MODULE_AUTHOR("Marvell International Ltd.");
1766 MODULE_DESCRIPTION("Marvell WiFi-Ex SDIO Driver version " SDIO_VERSION);
1767 MODULE_VERSION(SDIO_VERSION);
1768 MODULE_LICENSE("GPL v2");
1769 MODULE_FIRMWARE("mrvl/sd8787_uapsta.bin");