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);
78 func->card->quirks |= MMC_QUIRK_BLKSZ_FOR_BYTE_MODE;
80 sdio_claim_host(func);
81 ret = sdio_enable_func(func);
82 sdio_release_host(func);
85 pr_err("%s: failed to enable function\n", __func__);
90 if (mwifiex_add_card(card, &add_remove_card_sem, &sdio_ops,
92 pr_err("%s: add card failed\n", __func__);
94 sdio_claim_host(func);
95 ret = sdio_disable_func(func);
96 sdio_release_host(func);
106 * This function removes the interface and frees up the card structure.
109 mwifiex_sdio_remove(struct sdio_func *func)
111 struct sdio_mmc_card *card;
112 struct mwifiex_adapter *adapter;
113 struct mwifiex_private *priv;
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)
126 /* In case driver is removed when asynchronous FW load is in progress */
127 wait_for_completion(&adapter->fw_load);
130 if (adapter->is_suspended)
131 mwifiex_sdio_resume(adapter->dev);
133 for (i = 0; i < adapter->priv_num; i++)
134 if ((GET_BSS_ROLE(adapter->priv[i]) ==
135 MWIFIEX_BSS_ROLE_STA) &&
136 adapter->priv[i]->media_connected)
137 mwifiex_deauthenticate(adapter->priv[i], NULL);
139 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
140 mwifiex_disable_auto_ds(priv);
141 mwifiex_init_shutdown_fw(priv, MWIFIEX_FUNC_SHUTDOWN);
144 mwifiex_remove_card(card->adapter, &add_remove_card_sem);
151 * Kernel needs to suspend all functions separately. Therefore all
152 * registered functions must have drivers with suspend and resume
153 * methods. Failing that the kernel simply removes the whole card.
155 * If already not suspended, this function allocates and sends a host
156 * sleep activate request to the firmware and turns off the traffic.
158 static int mwifiex_sdio_suspend(struct device *dev)
160 struct sdio_func *func = dev_to_sdio_func(dev);
161 struct sdio_mmc_card *card;
162 struct mwifiex_adapter *adapter;
163 mmc_pm_flag_t pm_flag = 0;
168 pm_flag = sdio_get_host_pm_caps(func);
169 pr_debug("cmd: %s: suspend: PM flag = 0x%x\n",
170 sdio_func_id(func), pm_flag);
171 if (!(pm_flag & MMC_PM_KEEP_POWER)) {
172 pr_err("%s: cannot remain alive while host is"
173 " suspended\n", sdio_func_id(func));
177 card = sdio_get_drvdata(func);
178 if (!card || !card->adapter) {
179 pr_err("suspend: invalid card or adapter\n");
183 pr_err("suspend: sdio_func is not specified\n");
187 adapter = card->adapter;
189 /* Enable the Host Sleep */
190 if (!mwifiex_enable_hs(adapter)) {
191 dev_err(adapter->dev, "cmd: failed to suspend\n");
195 dev_dbg(adapter->dev, "cmd: suspend with MMC_PM_KEEP_POWER\n");
196 ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER);
198 /* Indicate device suspended */
199 adapter->is_suspended = true;
201 for (i = 0; i < adapter->priv_num; i++)
202 netif_carrier_off(adapter->priv[i]->netdev);
210 * Kernel needs to suspend all functions separately. Therefore all
211 * registered functions must have drivers with suspend and resume
212 * methods. Failing that the kernel simply removes the whole card.
214 * If already not resumed, this function turns on the traffic and
215 * sends a host sleep cancel request to the firmware.
217 static int mwifiex_sdio_resume(struct device *dev)
219 struct sdio_func *func = dev_to_sdio_func(dev);
220 struct sdio_mmc_card *card;
221 struct mwifiex_adapter *adapter;
222 mmc_pm_flag_t pm_flag = 0;
226 pm_flag = sdio_get_host_pm_caps(func);
227 card = sdio_get_drvdata(func);
228 if (!card || !card->adapter) {
229 pr_err("resume: invalid card or adapter\n");
233 pr_err("resume: sdio_func is not specified\n");
237 adapter = card->adapter;
239 if (!adapter->is_suspended) {
240 dev_warn(adapter->dev, "device already resumed\n");
244 adapter->is_suspended = false;
246 for (i = 0; i < adapter->priv_num; i++)
247 if (adapter->priv[i]->media_connected)
248 netif_carrier_on(adapter->priv[i]->netdev);
250 /* Disable Host Sleep */
251 mwifiex_cancel_hs(mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA),
257 /* Device ID for SD8786 */
258 #define SDIO_DEVICE_ID_MARVELL_8786 (0x9116)
259 /* Device ID for SD8787 */
260 #define SDIO_DEVICE_ID_MARVELL_8787 (0x9119)
261 /* Device ID for SD8797 */
262 #define SDIO_DEVICE_ID_MARVELL_8797 (0x9129)
265 static const struct sdio_device_id mwifiex_ids[] = {
266 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8786)},
267 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8787)},
268 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8797)},
272 MODULE_DEVICE_TABLE(sdio, mwifiex_ids);
274 static const struct dev_pm_ops mwifiex_sdio_pm_ops = {
275 .suspend = mwifiex_sdio_suspend,
276 .resume = mwifiex_sdio_resume,
279 static struct sdio_driver mwifiex_sdio = {
280 .name = "mwifiex_sdio",
281 .id_table = mwifiex_ids,
282 .probe = mwifiex_sdio_probe,
283 .remove = mwifiex_sdio_remove,
285 .owner = THIS_MODULE,
286 .pm = &mwifiex_sdio_pm_ops,
291 * This function writes data into SDIO card register.
294 mwifiex_write_reg(struct mwifiex_adapter *adapter, u32 reg, u32 data)
296 struct sdio_mmc_card *card = adapter->card;
299 sdio_claim_host(card->func);
300 sdio_writeb(card->func, (u8) data, reg, &ret);
301 sdio_release_host(card->func);
307 * This function reads data from SDIO card register.
310 mwifiex_read_reg(struct mwifiex_adapter *adapter, u32 reg, u32 *data)
312 struct sdio_mmc_card *card = adapter->card;
316 sdio_claim_host(card->func);
317 val = sdio_readb(card->func, reg, &ret);
318 sdio_release_host(card->func);
326 * This function writes multiple data into SDIO card memory.
328 * This does not work in suspended mode.
331 mwifiex_write_data_sync(struct mwifiex_adapter *adapter,
332 u8 *buffer, u32 pkt_len, u32 port)
334 struct sdio_mmc_card *card = adapter->card;
337 (port & MWIFIEX_SDIO_BYTE_MODE_MASK) ? BYTE_MODE : BLOCK_MODE;
338 u32 blk_size = (blk_mode == BLOCK_MODE) ? MWIFIEX_SDIO_BLOCK_SIZE : 1;
341 BLOCK_MODE) ? (pkt_len /
342 MWIFIEX_SDIO_BLOCK_SIZE) : pkt_len;
343 u32 ioport = (port & MWIFIEX_SDIO_IO_PORT_MASK);
345 if (adapter->is_suspended) {
346 dev_err(adapter->dev,
347 "%s: not allowed while suspended\n", __func__);
351 sdio_claim_host(card->func);
353 ret = sdio_writesb(card->func, ioport, buffer, blk_cnt * blk_size);
355 sdio_release_host(card->func);
361 * This function reads multiple data from SDIO card memory.
363 static int mwifiex_read_data_sync(struct mwifiex_adapter *adapter, u8 *buffer,
364 u32 len, u32 port, u8 claim)
366 struct sdio_mmc_card *card = adapter->card;
368 u8 blk_mode = (port & MWIFIEX_SDIO_BYTE_MODE_MASK) ? BYTE_MODE
370 u32 blk_size = (blk_mode == BLOCK_MODE) ? MWIFIEX_SDIO_BLOCK_SIZE : 1;
371 u32 blk_cnt = (blk_mode == BLOCK_MODE) ? (len / MWIFIEX_SDIO_BLOCK_SIZE)
373 u32 ioport = (port & MWIFIEX_SDIO_IO_PORT_MASK);
376 sdio_claim_host(card->func);
378 ret = sdio_readsb(card->func, buffer, ioport, blk_cnt * blk_size);
381 sdio_release_host(card->func);
387 * This function wakes up the card.
389 * A host power up command is written to the card configuration
390 * register to wake up the card.
392 static int mwifiex_pm_wakeup_card(struct mwifiex_adapter *adapter)
394 dev_dbg(adapter->dev, "event: wakeup device...\n");
396 return mwifiex_write_reg(adapter, CONFIGURATION_REG, HOST_POWER_UP);
400 * This function is called after the card has woken up.
402 * The card configuration register is reset.
404 static int mwifiex_pm_wakeup_card_complete(struct mwifiex_adapter *adapter)
406 dev_dbg(adapter->dev, "cmd: wakeup device completed\n");
408 return mwifiex_write_reg(adapter, CONFIGURATION_REG, 0);
412 * This function initializes the IO ports.
414 * The following operations are performed -
415 * - Read the IO ports (0, 1 and 2)
416 * - Set host interrupt Reset-To-Read to clear
417 * - Set auto re-enable interrupt
419 static int mwifiex_init_sdio_ioport(struct mwifiex_adapter *adapter)
425 /* Read the IO port */
426 if (!mwifiex_read_reg(adapter, IO_PORT_0_REG, ®))
427 adapter->ioport |= (reg & 0xff);
431 if (!mwifiex_read_reg(adapter, IO_PORT_1_REG, ®))
432 adapter->ioport |= ((reg & 0xff) << 8);
436 if (!mwifiex_read_reg(adapter, IO_PORT_2_REG, ®))
437 adapter->ioport |= ((reg & 0xff) << 16);
441 pr_debug("info: SDIO FUNC1 IO port: %#x\n", adapter->ioport);
443 /* Set Host interrupt reset to read to clear */
444 if (!mwifiex_read_reg(adapter, HOST_INT_RSR_REG, ®))
445 mwifiex_write_reg(adapter, HOST_INT_RSR_REG,
446 reg | SDIO_INT_MASK);
450 /* Dnld/Upld ready set to auto reset */
451 if (!mwifiex_read_reg(adapter, CARD_MISC_CFG_REG, ®))
452 mwifiex_write_reg(adapter, CARD_MISC_CFG_REG,
453 reg | AUTO_RE_ENABLE_INT);
461 * This function sends data to the card.
463 static int mwifiex_write_data_to_card(struct mwifiex_adapter *adapter,
464 u8 *payload, u32 pkt_len, u32 port)
470 ret = mwifiex_write_data_sync(adapter, payload, pkt_len, port);
473 dev_err(adapter->dev, "host_to_card, write iomem"
474 " (%d) failed: %d\n", i, ret);
475 if (mwifiex_write_reg(adapter, CONFIGURATION_REG, 0x04))
476 dev_err(adapter->dev, "write CFG reg failed\n");
479 if (i > MAX_WRITE_IOMEM_RETRY)
488 * This function gets the read port.
490 * If control port bit is set in MP read bitmap, the control port
491 * is returned, otherwise the current read port is returned and
492 * the value is increased (provided it does not reach the maximum
493 * limit, in which case it is reset to 1)
495 static int mwifiex_get_rd_port(struct mwifiex_adapter *adapter, u8 *port)
497 struct sdio_mmc_card *card = adapter->card;
498 u16 rd_bitmap = card->mp_rd_bitmap;
500 dev_dbg(adapter->dev, "data: mp_rd_bitmap=0x%04x\n", rd_bitmap);
502 if (!(rd_bitmap & (CTRL_PORT_MASK | DATA_PORT_MASK)))
505 if (card->mp_rd_bitmap & CTRL_PORT_MASK) {
506 card->mp_rd_bitmap &= (u16) (~CTRL_PORT_MASK);
508 dev_dbg(adapter->dev, "data: port=%d mp_rd_bitmap=0x%04x\n",
509 *port, card->mp_rd_bitmap);
511 if (card->mp_rd_bitmap & (1 << card->curr_rd_port)) {
512 card->mp_rd_bitmap &= (u16)
513 (~(1 << card->curr_rd_port));
514 *port = card->curr_rd_port;
516 if (++card->curr_rd_port == MAX_PORT)
517 card->curr_rd_port = 1;
522 dev_dbg(adapter->dev,
523 "data: port=%d mp_rd_bitmap=0x%04x -> 0x%04x\n",
524 *port, rd_bitmap, card->mp_rd_bitmap);
530 * This function gets the write port for data.
532 * The current write port is returned if available and the value is
533 * increased (provided it does not reach the maximum limit, in which
534 * case it is reset to 1)
536 static int mwifiex_get_wr_port_data(struct mwifiex_adapter *adapter, u8 *port)
538 struct sdio_mmc_card *card = adapter->card;
539 u16 wr_bitmap = card->mp_wr_bitmap;
541 dev_dbg(adapter->dev, "data: mp_wr_bitmap=0x%04x\n", wr_bitmap);
543 if (!(wr_bitmap & card->mp_data_port_mask))
546 if (card->mp_wr_bitmap & (1 << card->curr_wr_port)) {
547 card->mp_wr_bitmap &= (u16) (~(1 << card->curr_wr_port));
548 *port = card->curr_wr_port;
549 if (++card->curr_wr_port == card->mp_end_port)
550 card->curr_wr_port = 1;
552 adapter->data_sent = true;
556 if (*port == CTRL_PORT) {
557 dev_err(adapter->dev, "invalid data port=%d cur port=%d"
558 " mp_wr_bitmap=0x%04x -> 0x%04x\n",
559 *port, card->curr_wr_port, wr_bitmap,
564 dev_dbg(adapter->dev, "data: port=%d mp_wr_bitmap=0x%04x -> 0x%04x\n",
565 *port, wr_bitmap, card->mp_wr_bitmap);
571 * This function polls the card status.
574 mwifiex_sdio_poll_card_status(struct mwifiex_adapter *adapter, u8 bits)
579 for (tries = 0; tries < MAX_POLL_TRIES; tries++) {
580 if (mwifiex_read_reg(adapter, CARD_STATUS_REG, &cs))
582 else if ((cs & bits) == bits)
585 usleep_range(10, 20);
588 dev_err(adapter->dev, "poll card status failed, tries = %d\n", tries);
594 * This function reads the firmware status.
597 mwifiex_sdio_read_fw_status(struct mwifiex_adapter *adapter, u16 *dat)
601 if (mwifiex_read_reg(adapter, CARD_FW_STATUS0_REG, &fws0))
604 if (mwifiex_read_reg(adapter, CARD_FW_STATUS1_REG, &fws1))
607 *dat = (u16) ((fws1 << 8) | fws0);
613 * This function disables the host interrupt.
615 * The host interrupt mask is read, the disable bit is reset and
616 * written back to the card host interrupt mask register.
618 static int mwifiex_sdio_disable_host_int(struct mwifiex_adapter *adapter)
622 /* Read back the host_int_mask register */
623 if (mwifiex_read_reg(adapter, HOST_INT_MASK_REG, &host_int_mask))
626 /* Update with the mask and write back to the register */
627 host_int_mask &= ~HOST_INT_DISABLE;
629 if (mwifiex_write_reg(adapter, HOST_INT_MASK_REG, host_int_mask)) {
630 dev_err(adapter->dev, "disable host interrupt failed\n");
638 * This function enables the host interrupt.
640 * The host interrupt enable mask is written to the card
641 * host interrupt mask register.
643 static int mwifiex_sdio_enable_host_int(struct mwifiex_adapter *adapter)
645 /* Simply write the mask to the register */
646 if (mwifiex_write_reg(adapter, HOST_INT_MASK_REG, HOST_INT_ENABLE)) {
647 dev_err(adapter->dev, "enable host interrupt failed\n");
654 * This function sends a data buffer to the card.
656 static int mwifiex_sdio_card_to_host(struct mwifiex_adapter *adapter,
657 u32 *type, u8 *buffer,
658 u32 npayload, u32 ioport)
664 dev_err(adapter->dev, "%s: buffer is NULL\n", __func__);
668 ret = mwifiex_read_data_sync(adapter, buffer, npayload, ioport, 1);
671 dev_err(adapter->dev, "%s: read iomem failed: %d\n", __func__,
676 nb = le16_to_cpu(*(__le16 *) (buffer));
678 dev_err(adapter->dev, "%s: invalid packet, nb=%d npayload=%d\n",
679 __func__, nb, npayload);
683 *type = le16_to_cpu(*(__le16 *) (buffer + 2));
689 * This function downloads the firmware to the card.
691 * Firmware is downloaded to the card in blocks. Every block download
692 * is tested for CRC errors, and retried a number of times before
695 static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter,
696 struct mwifiex_fw_image *fw)
699 u8 *firmware = fw->fw_buf;
700 u32 firmware_len = fw->fw_len;
705 u32 txlen, tx_blocks = 0, tries;
709 dev_err(adapter->dev,
710 "firmware image not found! Terminating download\n");
714 dev_dbg(adapter->dev, "info: downloading FW image (%d bytes)\n",
717 /* Assume that the allocated buffer is 8-byte aligned */
718 fwbuf = kzalloc(MWIFIEX_UPLD_SIZE, GFP_KERNEL);
722 /* Perform firmware data transfer */
724 /* The host polls for the DN_LD_CARD_RDY and CARD_IO_READY
726 ret = mwifiex_sdio_poll_card_status(adapter, CARD_IO_READY |
729 dev_err(adapter->dev, "FW download with helper:"
730 " poll status timeout @ %d\n", offset);
735 if (offset >= firmware_len)
738 for (tries = 0; tries < MAX_POLL_TRIES; tries++) {
739 ret = mwifiex_read_reg(adapter, HOST_F1_RD_BASE_0,
742 dev_err(adapter->dev,
743 "dev BASE0 register read failed: "
744 "base0=%#04X(%d). Terminating dnld\n",
748 ret = mwifiex_read_reg(adapter, HOST_F1_RD_BASE_1,
751 dev_err(adapter->dev,
752 "dev BASE1 register read failed: "
753 "base1=%#04X(%d). Terminating dnld\n",
757 len = (u16) (((base1 & 0xff) << 8) | (base0 & 0xff));
762 usleep_range(10, 20);
767 } else if (len > MWIFIEX_UPLD_SIZE) {
768 dev_err(adapter->dev,
769 "FW dnld failed @ %d, invalid length %d\n",
779 if (i > MAX_WRITE_IOMEM_RETRY) {
780 dev_err(adapter->dev,
781 "FW dnld failed @ %d, over max retry\n",
786 dev_err(adapter->dev, "CRC indicated by the helper:"
787 " len = 0x%04X, txlen = %d\n", len, txlen);
789 /* Setting this to 0 to resend from same offset */
794 /* Set blocksize to transfer - checking for last
796 if (firmware_len - offset < txlen)
797 txlen = firmware_len - offset;
799 tx_blocks = (txlen + MWIFIEX_SDIO_BLOCK_SIZE - 1)
800 / MWIFIEX_SDIO_BLOCK_SIZE;
802 /* Copy payload to buffer */
803 memmove(fwbuf, &firmware[offset], txlen);
806 ret = mwifiex_write_data_sync(adapter, fwbuf, tx_blocks *
807 MWIFIEX_SDIO_BLOCK_SIZE,
810 dev_err(adapter->dev,
811 "FW download, write iomem (%d) failed @ %d\n",
813 if (mwifiex_write_reg(adapter, CONFIGURATION_REG, 0x04))
814 dev_err(adapter->dev, "write CFG reg failed\n");
823 dev_dbg(adapter->dev, "info: FW download over, size %d bytes\n",
833 * This function checks the firmware status in card.
835 * The winner interface is also determined by this function.
837 static int mwifiex_check_fw_status(struct mwifiex_adapter *adapter,
845 /* Wait for firmware initialization event */
846 for (tries = 0; tries < poll_num; tries++) {
847 ret = mwifiex_sdio_read_fw_status(adapter, &firmware_stat);
850 if (firmware_stat == FIRMWARE_READY_SDIO) {
861 (adapter, CARD_FW_STATUS0_REG, &winner_status))
873 * This function reads the interrupt status from card.
875 static void mwifiex_interrupt_status(struct mwifiex_adapter *adapter)
877 struct sdio_mmc_card *card = adapter->card;
881 if (mwifiex_read_data_sync(adapter, card->mp_regs, MAX_MP_REGS,
882 REG_PORT | MWIFIEX_SDIO_BYTE_MODE_MASK,
884 dev_err(adapter->dev, "read mp_regs failed\n");
888 sdio_ireg = card->mp_regs[HOST_INTSTATUS_REG];
891 * DN_LD_HOST_INT_STATUS and/or UP_LD_HOST_INT_STATUS
892 * Clear the interrupt status register
894 dev_dbg(adapter->dev, "int: sdio_ireg = %#x\n", sdio_ireg);
895 spin_lock_irqsave(&adapter->int_lock, flags);
896 adapter->int_status |= sdio_ireg;
897 spin_unlock_irqrestore(&adapter->int_lock, flags);
902 * SDIO interrupt handler.
904 * This function reads the interrupt status from firmware and handles
905 * the interrupt in current thread (ksdioirqd) right away.
908 mwifiex_sdio_interrupt(struct sdio_func *func)
910 struct mwifiex_adapter *adapter;
911 struct sdio_mmc_card *card;
913 card = sdio_get_drvdata(func);
914 if (!card || !card->adapter) {
915 pr_debug("int: func=%p card=%p adapter=%p\n",
916 func, card, card ? card->adapter : NULL);
919 adapter = card->adapter;
921 if (adapter->surprise_removed)
924 if (!adapter->pps_uapsd_mode && adapter->ps_state == PS_STATE_SLEEP)
925 adapter->ps_state = PS_STATE_AWAKE;
927 mwifiex_interrupt_status(adapter);
928 mwifiex_main_process(adapter);
932 * This function decodes a received packet.
934 * Based on the type, the packet is treated as either a data, or
935 * a command response, or an event, and the correct handler
936 * function is invoked.
938 static int mwifiex_decode_rx_packet(struct mwifiex_adapter *adapter,
939 struct sk_buff *skb, u32 upld_typ)
943 skb_pull(skb, INTF_HEADER_LEN);
946 case MWIFIEX_TYPE_DATA:
947 dev_dbg(adapter->dev, "info: --- Rx: Data packet ---\n");
948 mwifiex_handle_rx_packet(adapter, skb);
951 case MWIFIEX_TYPE_CMD:
952 dev_dbg(adapter->dev, "info: --- Rx: Cmd Response ---\n");
953 /* take care of curr_cmd = NULL case */
954 if (!adapter->curr_cmd) {
955 cmd_buf = adapter->upld_buf;
957 if (adapter->ps_state == PS_STATE_SLEEP_CFM)
958 mwifiex_process_sleep_confirm_resp(adapter,
962 memcpy(cmd_buf, skb->data,
963 min_t(u32, MWIFIEX_SIZE_OF_CMD_BUFFER,
966 dev_kfree_skb_any(skb);
968 adapter->cmd_resp_received = true;
969 adapter->curr_cmd->resp_skb = skb;
973 case MWIFIEX_TYPE_EVENT:
974 dev_dbg(adapter->dev, "info: --- Rx: Event ---\n");
975 adapter->event_cause = *(u32 *) skb->data;
977 if ((skb->len > 0) && (skb->len < MAX_EVENT_SIZE))
978 memcpy(adapter->event_body,
979 skb->data + MWIFIEX_EVENT_HEADER_LEN,
982 /* event cause has been saved to adapter->event_cause */
983 adapter->event_received = true;
984 adapter->event_skb = skb;
989 dev_err(adapter->dev, "unknown upload type %#x\n", upld_typ);
990 dev_kfree_skb_any(skb);
998 * This function transfers received packets from card to driver, performing
999 * aggregation if required.
1001 * For data received on control port, or if aggregation is disabled, the
1002 * received buffers are uploaded as separate packets. However, if aggregation
1003 * is enabled and required, the buffers are copied onto an aggregation buffer,
1004 * provided there is space left, processed and finally uploaded.
1006 static int mwifiex_sdio_card_to_host_mp_aggr(struct mwifiex_adapter *adapter,
1007 struct sk_buff *skb, u8 port)
1009 struct sdio_mmc_card *card = adapter->card;
1010 s32 f_do_rx_aggr = 0;
1011 s32 f_do_rx_cur = 0;
1013 struct sk_buff *skb_deaggr;
1015 u32 pkt_len, pkt_type = 0;
1017 u32 rx_len = skb->len;
1019 if (port == CTRL_PORT) {
1020 /* Read the command Resp without aggr */
1021 dev_dbg(adapter->dev, "info: %s: no aggregation for cmd "
1022 "response\n", __func__);
1025 goto rx_curr_single;
1028 if (!card->mpa_rx.enabled) {
1029 dev_dbg(adapter->dev, "info: %s: rx aggregation disabled\n",
1033 goto rx_curr_single;
1036 if (card->mp_rd_bitmap & (~((u16) CTRL_PORT_MASK))) {
1037 /* Some more data RX pending */
1038 dev_dbg(adapter->dev, "info: %s: not last packet\n", __func__);
1040 if (MP_RX_AGGR_IN_PROGRESS(card)) {
1041 if (MP_RX_AGGR_BUF_HAS_ROOM(card, skb->len)) {
1044 /* No room in Aggr buf, do rx aggr now */
1049 /* Rx aggr not in progress */
1054 /* No more data RX pending */
1055 dev_dbg(adapter->dev, "info: %s: last packet\n", __func__);
1057 if (MP_RX_AGGR_IN_PROGRESS(card)) {
1059 if (MP_RX_AGGR_BUF_HAS_ROOM(card, skb->len))
1062 /* No room in Aggr buf, do rx aggr now */
1070 dev_dbg(adapter->dev, "info: current packet aggregation\n");
1071 /* Curr pkt can be aggregated */
1072 MP_RX_AGGR_SETUP(card, skb, port);
1074 if (MP_RX_AGGR_PKT_LIMIT_REACHED(card) ||
1075 MP_RX_AGGR_PORT_LIMIT_REACHED(card)) {
1076 dev_dbg(adapter->dev, "info: %s: aggregated packet "
1077 "limit reached\n", __func__);
1078 /* No more pkts allowed in Aggr buf, rx it */
1084 /* do aggr RX now */
1085 dev_dbg(adapter->dev, "info: do_rx_aggr: num of packets: %d\n",
1086 card->mpa_rx.pkt_cnt);
1088 if (mwifiex_read_data_sync(adapter, card->mpa_rx.buf,
1089 card->mpa_rx.buf_len,
1090 (adapter->ioport | 0x1000 |
1091 (card->mpa_rx.ports << 4)) +
1092 card->mpa_rx.start_port, 1))
1095 curr_ptr = card->mpa_rx.buf;
1097 for (pind = 0; pind < card->mpa_rx.pkt_cnt; pind++) {
1099 /* get curr PKT len & type */
1100 pkt_len = *(u16 *) &curr_ptr[0];
1101 pkt_type = *(u16 *) &curr_ptr[2];
1103 /* copy pkt to deaggr buf */
1104 skb_deaggr = card->mpa_rx.skb_arr[pind];
1106 if ((pkt_type == MWIFIEX_TYPE_DATA) && (pkt_len <=
1107 card->mpa_rx.len_arr[pind])) {
1109 memcpy(skb_deaggr->data, curr_ptr, pkt_len);
1111 skb_trim(skb_deaggr, pkt_len);
1113 /* Process de-aggr packet */
1114 mwifiex_decode_rx_packet(adapter, skb_deaggr,
1117 dev_err(adapter->dev, "wrong aggr pkt:"
1118 " type=%d len=%d max_len=%d\n",
1120 card->mpa_rx.len_arr[pind]);
1121 dev_kfree_skb_any(skb_deaggr);
1123 curr_ptr += card->mpa_rx.len_arr[pind];
1125 MP_RX_AGGR_BUF_RESET(card);
1130 dev_dbg(adapter->dev, "info: RX: port: %d, rx_len: %d\n",
1133 if (mwifiex_sdio_card_to_host(adapter, &pkt_type,
1134 skb->data, skb->len,
1135 adapter->ioport + port))
1138 mwifiex_decode_rx_packet(adapter, skb, pkt_type);
1144 if (MP_RX_AGGR_IN_PROGRESS(card)) {
1145 /* Multiport-aggregation transfer failed - cleanup */
1146 for (pind = 0; pind < card->mpa_rx.pkt_cnt; pind++) {
1147 /* copy pkt to deaggr buf */
1148 skb_deaggr = card->mpa_rx.skb_arr[pind];
1149 dev_kfree_skb_any(skb_deaggr);
1151 MP_RX_AGGR_BUF_RESET(card);
1155 /* Single transfer pending. Free curr buff also */
1156 dev_kfree_skb_any(skb);
1162 * This function checks the current interrupt status.
1164 * The following interrupts are checked and handled by this function -
1167 * - Packets received
1169 * Since the firmware does not generate download ready interrupt if the
1170 * port updated is command port only, command sent interrupt checking
1171 * should be done manually, and for every SDIO interrupt.
1173 * In case of Rx packets received, the packets are uploaded from card to
1174 * host and processed accordingly.
1176 static int mwifiex_process_int_status(struct mwifiex_adapter *adapter)
1178 struct sdio_mmc_card *card = adapter->card;
1181 struct sk_buff *skb;
1182 u8 port = CTRL_PORT;
1183 u32 len_reg_l, len_reg_u;
1186 unsigned long flags;
1188 spin_lock_irqsave(&adapter->int_lock, flags);
1189 sdio_ireg = adapter->int_status;
1190 adapter->int_status = 0;
1191 spin_unlock_irqrestore(&adapter->int_lock, flags);
1196 if (sdio_ireg & DN_LD_HOST_INT_STATUS) {
1197 card->mp_wr_bitmap = ((u16) card->mp_regs[WR_BITMAP_U]) << 8;
1198 card->mp_wr_bitmap |= (u16) card->mp_regs[WR_BITMAP_L];
1199 dev_dbg(adapter->dev, "int: DNLD: wr_bitmap=0x%04x\n",
1200 card->mp_wr_bitmap);
1201 if (adapter->data_sent &&
1202 (card->mp_wr_bitmap & card->mp_data_port_mask)) {
1203 dev_dbg(adapter->dev,
1204 "info: <--- Tx DONE Interrupt --->\n");
1205 adapter->data_sent = false;
1209 /* As firmware will not generate download ready interrupt if the port
1210 updated is command port only, cmd_sent should be done for any SDIO
1212 if (adapter->cmd_sent) {
1213 /* Check if firmware has attach buffer at command port and
1214 update just that in wr_bit_map. */
1215 card->mp_wr_bitmap |=
1216 (u16) card->mp_regs[WR_BITMAP_L] & CTRL_PORT_MASK;
1217 if (card->mp_wr_bitmap & CTRL_PORT_MASK)
1218 adapter->cmd_sent = false;
1221 dev_dbg(adapter->dev, "info: cmd_sent=%d data_sent=%d\n",
1222 adapter->cmd_sent, adapter->data_sent);
1223 if (sdio_ireg & UP_LD_HOST_INT_STATUS) {
1224 card->mp_rd_bitmap = ((u16) card->mp_regs[RD_BITMAP_U]) << 8;
1225 card->mp_rd_bitmap |= (u16) card->mp_regs[RD_BITMAP_L];
1226 dev_dbg(adapter->dev, "int: UPLD: rd_bitmap=0x%04x\n",
1227 card->mp_rd_bitmap);
1230 ret = mwifiex_get_rd_port(adapter, &port);
1232 dev_dbg(adapter->dev,
1233 "info: no more rd_port available\n");
1236 len_reg_l = RD_LEN_P0_L + (port << 1);
1237 len_reg_u = RD_LEN_P0_U + (port << 1);
1238 rx_len = ((u16) card->mp_regs[len_reg_u]) << 8;
1239 rx_len |= (u16) card->mp_regs[len_reg_l];
1240 dev_dbg(adapter->dev, "info: RX: port=%d rx_len=%u\n",
1243 (rx_len + MWIFIEX_SDIO_BLOCK_SIZE -
1244 1) / MWIFIEX_SDIO_BLOCK_SIZE;
1245 if (rx_len <= INTF_HEADER_LEN ||
1246 (rx_blocks * MWIFIEX_SDIO_BLOCK_SIZE) >
1247 MWIFIEX_RX_DATA_BUF_SIZE) {
1248 dev_err(adapter->dev, "invalid rx_len=%d\n",
1252 rx_len = (u16) (rx_blocks * MWIFIEX_SDIO_BLOCK_SIZE);
1254 skb = dev_alloc_skb(rx_len);
1257 dev_err(adapter->dev, "%s: failed to alloc skb",
1262 skb_put(skb, rx_len);
1264 dev_dbg(adapter->dev, "info: rx_len = %d skb->len = %d\n",
1267 if (mwifiex_sdio_card_to_host_mp_aggr(adapter, skb,
1271 dev_err(adapter->dev, "card_to_host_mpa failed:"
1272 " int status=%#x\n", sdio_ireg);
1273 if (mwifiex_read_reg(adapter,
1274 CONFIGURATION_REG, &cr))
1275 dev_err(adapter->dev,
1276 "read CFG reg failed\n");
1278 dev_dbg(adapter->dev,
1279 "info: CFG reg val = %d\n", cr);
1280 if (mwifiex_write_reg(adapter,
1283 dev_err(adapter->dev,
1284 "write CFG reg failed\n");
1286 dev_dbg(adapter->dev, "info: write success\n");
1287 if (mwifiex_read_reg(adapter,
1288 CONFIGURATION_REG, &cr))
1289 dev_err(adapter->dev,
1290 "read CFG reg failed\n");
1292 dev_dbg(adapter->dev,
1293 "info: CFG reg val =%x\n", cr);
1303 * This function aggregates transmission buffers in driver and downloads
1304 * the aggregated packet to card.
1306 * The individual packets are aggregated by copying into an aggregation
1307 * buffer and then downloaded to the card. Previous unsent packets in the
1308 * aggregation buffer are pre-copied first before new packets are added.
1309 * Aggregation is done till there is space left in the aggregation buffer,
1310 * or till new packets are available.
1312 * The function will only download the packet to the card when aggregation
1313 * stops, otherwise it will just aggregate the packet in aggregation buffer
1316 static int mwifiex_host_to_card_mp_aggr(struct mwifiex_adapter *adapter,
1317 u8 *payload, u32 pkt_len, u8 port,
1320 struct sdio_mmc_card *card = adapter->card;
1322 s32 f_send_aggr_buf = 0;
1323 s32 f_send_cur_buf = 0;
1324 s32 f_precopy_cur_buf = 0;
1325 s32 f_postcopy_cur_buf = 0;
1327 if ((!card->mpa_tx.enabled) || (port == CTRL_PORT)) {
1328 dev_dbg(adapter->dev, "info: %s: tx aggregation disabled\n",
1332 goto tx_curr_single;
1336 /* More pkt in TX queue */
1337 dev_dbg(adapter->dev, "info: %s: more packets in queue.\n",
1340 if (MP_TX_AGGR_IN_PROGRESS(card)) {
1341 if (!MP_TX_AGGR_PORT_LIMIT_REACHED(card) &&
1342 MP_TX_AGGR_BUF_HAS_ROOM(card, pkt_len)) {
1343 f_precopy_cur_buf = 1;
1345 if (!(card->mp_wr_bitmap &
1346 (1 << card->curr_wr_port)) ||
1347 !MP_TX_AGGR_BUF_HAS_ROOM(
1348 card, pkt_len + next_pkt_len))
1349 f_send_aggr_buf = 1;
1351 /* No room in Aggr buf, send it */
1352 f_send_aggr_buf = 1;
1354 if (MP_TX_AGGR_PORT_LIMIT_REACHED(card) ||
1355 !(card->mp_wr_bitmap &
1356 (1 << card->curr_wr_port)))
1359 f_postcopy_cur_buf = 1;
1362 if (MP_TX_AGGR_BUF_HAS_ROOM(card, pkt_len) &&
1363 (card->mp_wr_bitmap & (1 << card->curr_wr_port)))
1364 f_precopy_cur_buf = 1;
1369 /* Last pkt in TX queue */
1370 dev_dbg(adapter->dev, "info: %s: Last packet in Tx Queue.\n",
1373 if (MP_TX_AGGR_IN_PROGRESS(card)) {
1374 /* some packs in Aggr buf already */
1375 f_send_aggr_buf = 1;
1377 if (MP_TX_AGGR_BUF_HAS_ROOM(card, pkt_len))
1378 f_precopy_cur_buf = 1;
1380 /* No room in Aggr buf, send it */
1387 if (f_precopy_cur_buf) {
1388 dev_dbg(adapter->dev, "data: %s: precopy current buffer\n",
1390 MP_TX_AGGR_BUF_PUT(card, payload, pkt_len, port);
1392 if (MP_TX_AGGR_PKT_LIMIT_REACHED(card) ||
1393 MP_TX_AGGR_PORT_LIMIT_REACHED(card))
1394 /* No more pkts allowed in Aggr buf, send it */
1395 f_send_aggr_buf = 1;
1398 if (f_send_aggr_buf) {
1399 dev_dbg(adapter->dev, "data: %s: send aggr buffer: %d %d\n",
1401 card->mpa_tx.start_port, card->mpa_tx.ports);
1402 ret = mwifiex_write_data_to_card(adapter, card->mpa_tx.buf,
1403 card->mpa_tx.buf_len,
1404 (adapter->ioport | 0x1000 |
1405 (card->mpa_tx.ports << 4)) +
1406 card->mpa_tx.start_port);
1408 MP_TX_AGGR_BUF_RESET(card);
1412 if (f_send_cur_buf) {
1413 dev_dbg(adapter->dev, "data: %s: send current buffer %d\n",
1415 ret = mwifiex_write_data_to_card(adapter, payload, pkt_len,
1416 adapter->ioport + port);
1419 if (f_postcopy_cur_buf) {
1420 dev_dbg(adapter->dev, "data: %s: postcopy current buffer\n",
1422 MP_TX_AGGR_BUF_PUT(card, payload, pkt_len, port);
1429 * This function downloads data from driver to card.
1431 * Both commands and data packets are transferred to the card by this
1434 * This function adds the SDIO specific header to the front of the buffer
1435 * before transferring. The header contains the length of the packet and
1436 * the type. The firmware handles the packets based upon this set type.
1438 static int mwifiex_sdio_host_to_card(struct mwifiex_adapter *adapter,
1439 u8 type, struct sk_buff *skb,
1440 struct mwifiex_tx_param *tx_param)
1442 struct sdio_mmc_card *card = adapter->card;
1446 u8 port = CTRL_PORT;
1447 u8 *payload = (u8 *)skb->data;
1448 u32 pkt_len = skb->len;
1450 /* Allocate buffer and copy payload */
1451 blk_size = MWIFIEX_SDIO_BLOCK_SIZE;
1452 buf_block_len = (pkt_len + blk_size - 1) / blk_size;
1453 *(u16 *) &payload[0] = (u16) pkt_len;
1454 *(u16 *) &payload[2] = type;
1457 * This is SDIO specific header
1459 * u16 type (MWIFIEX_TYPE_DATA = 0, MWIFIEX_TYPE_CMD = 1,
1460 * MWIFIEX_TYPE_EVENT = 3)
1462 if (type == MWIFIEX_TYPE_DATA) {
1463 ret = mwifiex_get_wr_port_data(adapter, &port);
1465 dev_err(adapter->dev, "%s: no wr_port available\n",
1470 adapter->cmd_sent = true;
1471 /* Type must be MWIFIEX_TYPE_CMD */
1473 if (pkt_len <= INTF_HEADER_LEN ||
1474 pkt_len > MWIFIEX_UPLD_SIZE)
1475 dev_err(adapter->dev, "%s: payload=%p, nb=%d\n",
1476 __func__, payload, pkt_len);
1479 /* Transfer data to card */
1480 pkt_len = buf_block_len * blk_size;
1483 ret = mwifiex_host_to_card_mp_aggr(adapter, payload, pkt_len,
1484 port, tx_param->next_pkt_len
1487 ret = mwifiex_host_to_card_mp_aggr(adapter, payload, pkt_len,
1491 if (type == MWIFIEX_TYPE_CMD)
1492 adapter->cmd_sent = false;
1493 if (type == MWIFIEX_TYPE_DATA)
1494 adapter->data_sent = false;
1496 if (type == MWIFIEX_TYPE_DATA) {
1497 if (!(card->mp_wr_bitmap & (1 << card->curr_wr_port)))
1498 adapter->data_sent = true;
1500 adapter->data_sent = false;
1508 * This function allocates the MPA Tx and Rx buffers.
1510 static int mwifiex_alloc_sdio_mpa_buffers(struct mwifiex_adapter *adapter,
1511 u32 mpa_tx_buf_size, u32 mpa_rx_buf_size)
1513 struct sdio_mmc_card *card = adapter->card;
1516 card->mpa_tx.buf = kzalloc(mpa_tx_buf_size, GFP_KERNEL);
1517 if (!card->mpa_tx.buf) {
1522 card->mpa_tx.buf_size = mpa_tx_buf_size;
1524 card->mpa_rx.buf = kzalloc(mpa_rx_buf_size, GFP_KERNEL);
1525 if (!card->mpa_rx.buf) {
1530 card->mpa_rx.buf_size = mpa_rx_buf_size;
1534 kfree(card->mpa_tx.buf);
1535 kfree(card->mpa_rx.buf);
1542 * This function unregisters the SDIO device.
1544 * The SDIO IRQ is released, the function is disabled and driver
1545 * data is set to null.
1548 mwifiex_unregister_dev(struct mwifiex_adapter *adapter)
1550 struct sdio_mmc_card *card = adapter->card;
1552 if (adapter->card) {
1553 /* Release the SDIO IRQ */
1554 sdio_claim_host(card->func);
1555 sdio_release_irq(card->func);
1556 sdio_disable_func(card->func);
1557 sdio_release_host(card->func);
1558 sdio_set_drvdata(card->func, NULL);
1563 * This function registers the SDIO device.
1565 * SDIO IRQ is claimed, block size is set and driver data is initialized.
1567 static int mwifiex_register_dev(struct mwifiex_adapter *adapter)
1570 struct sdio_mmc_card *card = adapter->card;
1571 struct sdio_func *func = card->func;
1573 /* save adapter pointer in card */
1574 card->adapter = adapter;
1576 sdio_claim_host(func);
1578 /* Request the SDIO IRQ */
1579 ret = sdio_claim_irq(func, mwifiex_sdio_interrupt);
1581 pr_err("claim irq failed: ret=%d\n", ret);
1585 /* Set block size */
1586 ret = sdio_set_block_size(card->func, MWIFIEX_SDIO_BLOCK_SIZE);
1588 pr_err("cannot set SDIO block size\n");
1593 sdio_release_host(func);
1594 sdio_set_drvdata(func, card);
1596 adapter->dev = &func->dev;
1598 switch (func->device) {
1599 case SDIO_DEVICE_ID_MARVELL_8786:
1600 strcpy(adapter->fw_name, SD8786_DEFAULT_FW_NAME);
1602 case SDIO_DEVICE_ID_MARVELL_8797:
1603 strcpy(adapter->fw_name, SD8797_DEFAULT_FW_NAME);
1605 case SDIO_DEVICE_ID_MARVELL_8787:
1607 strcpy(adapter->fw_name, SD8787_DEFAULT_FW_NAME);
1614 sdio_release_irq(func);
1616 sdio_disable_func(func);
1617 sdio_release_host(func);
1618 adapter->card = NULL;
1624 * This function initializes the SDIO driver.
1626 * The following initializations steps are followed -
1627 * - Read the Host interrupt status register to acknowledge
1628 * the first interrupt got from bootloader
1629 * - Disable host interrupt mask register
1631 * - Initialize SDIO variables in card
1632 * - Allocate MP registers
1633 * - Allocate MPA Tx and Rx buffers
1635 static int mwifiex_init_sdio(struct mwifiex_adapter *adapter)
1637 struct sdio_mmc_card *card = adapter->card;
1642 * Read the HOST_INT_STATUS_REG for ACK the first interrupt got
1643 * from the bootloader. If we don't do this we get a interrupt
1644 * as soon as we register the irq.
1646 mwifiex_read_reg(adapter, HOST_INTSTATUS_REG, &sdio_ireg);
1648 /* Disable host interrupt mask register for SDIO */
1649 mwifiex_sdio_disable_host_int(adapter);
1651 /* Get SDIO ioport */
1652 mwifiex_init_sdio_ioport(adapter);
1654 /* Initialize SDIO variables in card */
1655 card->mp_rd_bitmap = 0;
1656 card->mp_wr_bitmap = 0;
1657 card->curr_rd_port = 1;
1658 card->curr_wr_port = 1;
1660 card->mp_data_port_mask = DATA_PORT_MASK;
1662 card->mpa_tx.buf_len = 0;
1663 card->mpa_tx.pkt_cnt = 0;
1664 card->mpa_tx.start_port = 0;
1666 card->mpa_tx.enabled = 1;
1667 card->mpa_tx.pkt_aggr_limit = SDIO_MP_AGGR_DEF_PKT_LIMIT;
1669 card->mpa_rx.buf_len = 0;
1670 card->mpa_rx.pkt_cnt = 0;
1671 card->mpa_rx.start_port = 0;
1673 card->mpa_rx.enabled = 1;
1674 card->mpa_rx.pkt_aggr_limit = SDIO_MP_AGGR_DEF_PKT_LIMIT;
1676 /* Allocate buffers for SDIO MP-A */
1677 card->mp_regs = kzalloc(MAX_MP_REGS, GFP_KERNEL);
1681 ret = mwifiex_alloc_sdio_mpa_buffers(adapter,
1682 SDIO_MP_TX_AGGR_DEF_BUF_SIZE,
1683 SDIO_MP_RX_AGGR_DEF_BUF_SIZE);
1685 dev_err(adapter->dev, "failed to alloc sdio mp-a buffers\n");
1686 kfree(card->mp_regs);
1694 * This function resets the MPA Tx and Rx buffers.
1696 static void mwifiex_cleanup_mpa_buf(struct mwifiex_adapter *adapter)
1698 struct sdio_mmc_card *card = adapter->card;
1700 MP_TX_AGGR_BUF_RESET(card);
1701 MP_RX_AGGR_BUF_RESET(card);
1705 * This function cleans up the allocated card buffers.
1707 * The following are freed by this function -
1712 static void mwifiex_cleanup_sdio(struct mwifiex_adapter *adapter)
1714 struct sdio_mmc_card *card = adapter->card;
1716 kfree(card->mp_regs);
1717 kfree(card->mpa_tx.buf);
1718 kfree(card->mpa_rx.buf);
1722 * This function updates the MP end port in card.
1725 mwifiex_update_mp_end_port(struct mwifiex_adapter *adapter, u16 port)
1727 struct sdio_mmc_card *card = adapter->card;
1730 card->mp_end_port = port;
1732 card->mp_data_port_mask = DATA_PORT_MASK;
1734 for (i = 1; i <= MAX_PORT - card->mp_end_port; i++)
1735 card->mp_data_port_mask &= ~(1 << (MAX_PORT - i));
1737 card->curr_wr_port = 1;
1739 dev_dbg(adapter->dev, "cmd: mp_end_port %d, data port mask 0x%x\n",
1740 port, card->mp_data_port_mask);
1743 static struct mmc_host *reset_host;
1744 static void sdio_card_reset_worker(struct work_struct *work)
1746 struct mmc_host *target = reset_host;
1748 /* The actual reset operation must be run outside of driver thread.
1749 * This is because mmc_remove_host() will cause the device to be
1750 * instantly destroyed, and the driver then needs to end its thread,
1751 * leading to a deadlock.
1753 * We run it in a totally independent workqueue.
1756 pr_err("Resetting card...\n");
1757 mmc_remove_host(target);
1758 /* 20ms delay is based on experiment with sdhci controller */
1760 mmc_add_host(target);
1762 static DECLARE_WORK(card_reset_work, sdio_card_reset_worker);
1764 /* This function resets the card */
1765 static void mwifiex_sdio_card_reset(struct mwifiex_adapter *adapter)
1767 struct sdio_mmc_card *card = adapter->card;
1769 reset_host = card->func->card->host;
1770 schedule_work(&card_reset_work);
1773 static struct mwifiex_if_ops sdio_ops = {
1774 .init_if = mwifiex_init_sdio,
1775 .cleanup_if = mwifiex_cleanup_sdio,
1776 .check_fw_status = mwifiex_check_fw_status,
1777 .prog_fw = mwifiex_prog_fw_w_helper,
1778 .register_dev = mwifiex_register_dev,
1779 .unregister_dev = mwifiex_unregister_dev,
1780 .enable_int = mwifiex_sdio_enable_host_int,
1781 .process_int_status = mwifiex_process_int_status,
1782 .host_to_card = mwifiex_sdio_host_to_card,
1783 .wakeup = mwifiex_pm_wakeup_card,
1784 .wakeup_complete = mwifiex_pm_wakeup_card_complete,
1787 .update_mp_end_port = mwifiex_update_mp_end_port,
1788 .cleanup_mpa_buf = mwifiex_cleanup_mpa_buf,
1789 .cmdrsp_complete = mwifiex_sdio_cmdrsp_complete,
1790 .event_complete = mwifiex_sdio_event_complete,
1791 .card_reset = mwifiex_sdio_card_reset,
1795 * This function initializes the SDIO driver.
1797 * This initiates the semaphore and registers the device with
1801 mwifiex_sdio_init_module(void)
1803 sema_init(&add_remove_card_sem, 1);
1805 /* Clear the flag in case user removes the card. */
1808 return sdio_register_driver(&mwifiex_sdio);
1812 * This function cleans up the SDIO driver.
1814 * The following major steps are followed for cleanup -
1815 * - Resume the device if its suspended
1816 * - Disconnect the device if connected
1817 * - Shutdown the firmware
1818 * - Unregister the device from SDIO bus.
1821 mwifiex_sdio_cleanup_module(void)
1823 if (!down_interruptible(&add_remove_card_sem))
1824 up(&add_remove_card_sem);
1826 /* Set the flag as user is removing this module. */
1829 cancel_work_sync(&card_reset_work);
1830 sdio_unregister_driver(&mwifiex_sdio);
1833 module_init(mwifiex_sdio_init_module);
1834 module_exit(mwifiex_sdio_cleanup_module);
1836 MODULE_AUTHOR("Marvell International Ltd.");
1837 MODULE_DESCRIPTION("Marvell WiFi-Ex SDIO Driver version " SDIO_VERSION);
1838 MODULE_VERSION(SDIO_VERSION);
1839 MODULE_LICENSE("GPL v2");
1840 MODULE_FIRMWARE(SD8786_DEFAULT_FW_NAME);
1841 MODULE_FIRMWARE(SD8787_DEFAULT_FW_NAME);
1842 MODULE_FIRMWARE(SD8797_DEFAULT_FW_NAME);