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;
115 pr_debug("info: SDIO func num=%d\n", func->num);
117 card = sdio_get_drvdata(func);
121 adapter = card->adapter;
122 if (!adapter || !adapter->priv_num)
126 if (adapter->is_suspended)
127 mwifiex_sdio_resume(adapter->dev);
129 for (i = 0; i < adapter->priv_num; i++)
130 if ((GET_BSS_ROLE(adapter->priv[i]) ==
131 MWIFIEX_BSS_ROLE_STA) &&
132 adapter->priv[i]->media_connected)
133 mwifiex_deauthenticate(adapter->priv[i], NULL);
135 mwifiex_disable_auto_ds(mwifiex_get_priv(adapter,
136 MWIFIEX_BSS_ROLE_ANY));
138 mwifiex_init_shutdown_fw(mwifiex_get_priv(adapter,
139 MWIFIEX_BSS_ROLE_ANY),
140 MWIFIEX_FUNC_SHUTDOWN);
143 mwifiex_remove_card(card->adapter, &add_remove_card_sem);
150 * Kernel needs to suspend all functions separately. Therefore all
151 * registered functions must have drivers with suspend and resume
152 * methods. Failing that the kernel simply removes the whole card.
154 * If already not suspended, this function allocates and sends a host
155 * sleep activate request to the firmware and turns off the traffic.
157 static int mwifiex_sdio_suspend(struct device *dev)
159 struct sdio_func *func = dev_to_sdio_func(dev);
160 struct sdio_mmc_card *card;
161 struct mwifiex_adapter *adapter;
162 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 hs_actived = mwifiex_enable_hs(adapter);
192 pr_debug("cmd: suspend with MMC_PM_KEEP_POWER\n");
193 ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER);
196 /* Indicate device suspended */
197 adapter->is_suspended = true;
199 for (i = 0; i < adapter->priv_num; i++)
200 netif_carrier_off(adapter->priv[i]->netdev);
208 * Kernel needs to suspend all functions separately. Therefore all
209 * registered functions must have drivers with suspend and resume
210 * methods. Failing that the kernel simply removes the whole card.
212 * If already not resumed, this function turns on the traffic and
213 * sends a host sleep cancel request to the firmware.
215 static int mwifiex_sdio_resume(struct device *dev)
217 struct sdio_func *func = dev_to_sdio_func(dev);
218 struct sdio_mmc_card *card;
219 struct mwifiex_adapter *adapter;
220 mmc_pm_flag_t pm_flag = 0;
224 pm_flag = sdio_get_host_pm_caps(func);
225 card = sdio_get_drvdata(func);
226 if (!card || !card->adapter) {
227 pr_err("resume: invalid card or adapter\n");
231 pr_err("resume: sdio_func is not specified\n");
235 adapter = card->adapter;
237 if (!adapter->is_suspended) {
238 dev_warn(adapter->dev, "device already resumed\n");
242 adapter->is_suspended = false;
244 for (i = 0; i < adapter->priv_num; i++)
245 if (adapter->priv[i]->media_connected)
246 netif_carrier_on(adapter->priv[i]->netdev);
248 /* Disable Host Sleep */
249 mwifiex_cancel_hs(mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA),
255 /* Device ID for SD8787 */
256 #define SDIO_DEVICE_ID_MARVELL_8787 (0x9119)
257 /* Device ID for SD8797 */
258 #define SDIO_DEVICE_ID_MARVELL_8797 (0x9129)
261 static const struct sdio_device_id mwifiex_ids[] = {
262 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8787)},
263 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8797)},
267 MODULE_DEVICE_TABLE(sdio, mwifiex_ids);
269 static const struct dev_pm_ops mwifiex_sdio_pm_ops = {
270 .suspend = mwifiex_sdio_suspend,
271 .resume = mwifiex_sdio_resume,
274 static struct sdio_driver mwifiex_sdio = {
275 .name = "mwifiex_sdio",
276 .id_table = mwifiex_ids,
277 .probe = mwifiex_sdio_probe,
278 .remove = mwifiex_sdio_remove,
280 .owner = THIS_MODULE,
281 .pm = &mwifiex_sdio_pm_ops,
286 * This function writes data into SDIO card register.
289 mwifiex_write_reg(struct mwifiex_adapter *adapter, u32 reg, u32 data)
291 struct sdio_mmc_card *card = adapter->card;
294 sdio_claim_host(card->func);
295 sdio_writeb(card->func, (u8) data, reg, &ret);
296 sdio_release_host(card->func);
302 * This function reads data from SDIO card register.
305 mwifiex_read_reg(struct mwifiex_adapter *adapter, u32 reg, u32 *data)
307 struct sdio_mmc_card *card = adapter->card;
311 sdio_claim_host(card->func);
312 val = sdio_readb(card->func, reg, &ret);
313 sdio_release_host(card->func);
321 * This function writes multiple data into SDIO card memory.
323 * This does not work in suspended mode.
326 mwifiex_write_data_sync(struct mwifiex_adapter *adapter,
327 u8 *buffer, u32 pkt_len, u32 port)
329 struct sdio_mmc_card *card = adapter->card;
332 (port & MWIFIEX_SDIO_BYTE_MODE_MASK) ? BYTE_MODE : BLOCK_MODE;
333 u32 blk_size = (blk_mode == BLOCK_MODE) ? MWIFIEX_SDIO_BLOCK_SIZE : 1;
336 BLOCK_MODE) ? (pkt_len /
337 MWIFIEX_SDIO_BLOCK_SIZE) : pkt_len;
338 u32 ioport = (port & MWIFIEX_SDIO_IO_PORT_MASK);
340 if (adapter->is_suspended) {
341 dev_err(adapter->dev,
342 "%s: not allowed while suspended\n", __func__);
346 sdio_claim_host(card->func);
348 if (!sdio_writesb(card->func, ioport, buffer, blk_cnt * blk_size))
351 sdio_release_host(card->func);
357 * This function reads multiple data from SDIO card memory.
359 static int mwifiex_read_data_sync(struct mwifiex_adapter *adapter, u8 *buffer,
360 u32 len, u32 port, u8 claim)
362 struct sdio_mmc_card *card = adapter->card;
365 (port & MWIFIEX_SDIO_BYTE_MODE_MASK) ? BYTE_MODE : BLOCK_MODE;
366 u32 blk_size = (blk_mode == BLOCK_MODE) ? MWIFIEX_SDIO_BLOCK_SIZE : 1;
369 BLOCK_MODE) ? (len / MWIFIEX_SDIO_BLOCK_SIZE) : len;
370 u32 ioport = (port & MWIFIEX_SDIO_IO_PORT_MASK);
373 sdio_claim_host(card->func);
375 if (!sdio_readsb(card->func, buffer, ioport, blk_cnt * blk_size))
379 sdio_release_host(card->func);
385 * This function wakes up the card.
387 * A host power up command is written to the card configuration
388 * register to wake up the card.
390 static int mwifiex_pm_wakeup_card(struct mwifiex_adapter *adapter)
392 dev_dbg(adapter->dev, "event: wakeup device...\n");
394 return mwifiex_write_reg(adapter, CONFIGURATION_REG, HOST_POWER_UP);
398 * This function is called after the card has woken up.
400 * The card configuration register is reset.
402 static int mwifiex_pm_wakeup_card_complete(struct mwifiex_adapter *adapter)
404 dev_dbg(adapter->dev, "cmd: wakeup device completed\n");
406 return mwifiex_write_reg(adapter, CONFIGURATION_REG, 0);
410 * This function initializes the IO ports.
412 * The following operations are performed -
413 * - Read the IO ports (0, 1 and 2)
414 * - Set host interrupt Reset-To-Read to clear
415 * - Set auto re-enable interrupt
417 static int mwifiex_init_sdio_ioport(struct mwifiex_adapter *adapter)
423 /* Read the IO port */
424 if (!mwifiex_read_reg(adapter, IO_PORT_0_REG, ®))
425 adapter->ioport |= (reg & 0xff);
429 if (!mwifiex_read_reg(adapter, IO_PORT_1_REG, ®))
430 adapter->ioport |= ((reg & 0xff) << 8);
434 if (!mwifiex_read_reg(adapter, IO_PORT_2_REG, ®))
435 adapter->ioport |= ((reg & 0xff) << 16);
439 pr_debug("info: SDIO FUNC1 IO port: %#x\n", adapter->ioport);
441 /* Set Host interrupt reset to read to clear */
442 if (!mwifiex_read_reg(adapter, HOST_INT_RSR_REG, ®))
443 mwifiex_write_reg(adapter, HOST_INT_RSR_REG,
444 reg | SDIO_INT_MASK);
448 /* Dnld/Upld ready set to auto reset */
449 if (!mwifiex_read_reg(adapter, CARD_MISC_CFG_REG, ®))
450 mwifiex_write_reg(adapter, CARD_MISC_CFG_REG,
451 reg | AUTO_RE_ENABLE_INT);
459 * This function sends data to the card.
461 static int mwifiex_write_data_to_card(struct mwifiex_adapter *adapter,
462 u8 *payload, u32 pkt_len, u32 port)
468 ret = mwifiex_write_data_sync(adapter, payload, pkt_len, port);
471 dev_err(adapter->dev, "host_to_card, write iomem"
472 " (%d) failed: %d\n", i, ret);
473 if (mwifiex_write_reg(adapter,
474 CONFIGURATION_REG, 0x04))
475 dev_err(adapter->dev, "write CFG reg failed\n");
478 if (i > MAX_WRITE_IOMEM_RETRY)
487 * This function gets the read port.
489 * If control port bit is set in MP read bitmap, the control port
490 * is returned, otherwise the current read port is returned and
491 * the value is increased (provided it does not reach the maximum
492 * limit, in which case it is reset to 1)
494 static int mwifiex_get_rd_port(struct mwifiex_adapter *adapter, u8 *port)
496 struct sdio_mmc_card *card = adapter->card;
497 u16 rd_bitmap = card->mp_rd_bitmap;
499 dev_dbg(adapter->dev, "data: mp_rd_bitmap=0x%04x\n", rd_bitmap);
501 if (!(rd_bitmap & (CTRL_PORT_MASK | DATA_PORT_MASK)))
504 if (card->mp_rd_bitmap & CTRL_PORT_MASK) {
505 card->mp_rd_bitmap &= (u16) (~CTRL_PORT_MASK);
507 dev_dbg(adapter->dev, "data: port=%d mp_rd_bitmap=0x%04x\n",
508 *port, card->mp_rd_bitmap);
510 if (card->mp_rd_bitmap & (1 << card->curr_rd_port)) {
511 card->mp_rd_bitmap &=
512 (u16) (~(1 << card->curr_rd_port));
513 *port = card->curr_rd_port;
515 if (++card->curr_rd_port == MAX_PORT)
516 card->curr_rd_port = 1;
521 dev_dbg(adapter->dev,
522 "data: port=%d mp_rd_bitmap=0x%04x -> 0x%04x\n",
523 *port, rd_bitmap, card->mp_rd_bitmap);
529 * This function gets the write port for data.
531 * The current write port is returned if available and the value is
532 * increased (provided it does not reach the maximum limit, in which
533 * case it is reset to 1)
535 static int mwifiex_get_wr_port_data(struct mwifiex_adapter *adapter, u8 *port)
537 struct sdio_mmc_card *card = adapter->card;
538 u16 wr_bitmap = card->mp_wr_bitmap;
540 dev_dbg(adapter->dev, "data: mp_wr_bitmap=0x%04x\n", wr_bitmap);
542 if (!(wr_bitmap & card->mp_data_port_mask))
545 if (card->mp_wr_bitmap & (1 << card->curr_wr_port)) {
546 card->mp_wr_bitmap &= (u16) (~(1 << card->curr_wr_port));
547 *port = card->curr_wr_port;
548 if (++card->curr_wr_port == card->mp_end_port)
549 card->curr_wr_port = 1;
551 adapter->data_sent = true;
555 if (*port == CTRL_PORT) {
556 dev_err(adapter->dev, "invalid data port=%d cur port=%d"
557 " mp_wr_bitmap=0x%04x -> 0x%04x\n",
558 *port, card->curr_wr_port, wr_bitmap,
563 dev_dbg(adapter->dev, "data: port=%d mp_wr_bitmap=0x%04x -> 0x%04x\n",
564 *port, wr_bitmap, card->mp_wr_bitmap);
570 * This function polls the card status.
573 mwifiex_sdio_poll_card_status(struct mwifiex_adapter *adapter, u8 bits)
578 for (tries = 0; tries < MAX_POLL_TRIES; tries++) {
579 if (mwifiex_read_reg(adapter, CARD_STATUS_REG, &cs))
581 else if ((cs & bits) == bits)
587 dev_err(adapter->dev, "poll card status failed, tries = %d\n",
593 * This function reads the firmware status.
596 mwifiex_sdio_read_fw_status(struct mwifiex_adapter *adapter, u16 *dat)
600 if (mwifiex_read_reg(adapter, CARD_FW_STATUS0_REG, &fws0))
603 if (mwifiex_read_reg(adapter, CARD_FW_STATUS1_REG, &fws1))
606 *dat = (u16) ((fws1 << 8) | fws0);
612 * This function disables the host interrupt.
614 * The host interrupt mask is read, the disable bit is reset and
615 * written back to the card host interrupt mask register.
617 static int mwifiex_sdio_disable_host_int(struct mwifiex_adapter *adapter)
621 /* Read back the host_int_mask register */
622 if (mwifiex_read_reg(adapter, HOST_INT_MASK_REG, &host_int_mask))
625 /* Update with the mask and write back to the register */
626 host_int_mask &= ~HOST_INT_DISABLE;
628 if (mwifiex_write_reg(adapter, HOST_INT_MASK_REG, host_int_mask)) {
629 dev_err(adapter->dev, "disable host interrupt failed\n");
637 * This function enables the host interrupt.
639 * The host interrupt enable mask is written to the card
640 * host interrupt mask register.
642 static int mwifiex_sdio_enable_host_int(struct mwifiex_adapter *adapter)
644 /* Simply write the mask to the register */
645 if (mwifiex_write_reg(adapter, HOST_INT_MASK_REG, HOST_INT_ENABLE)) {
646 dev_err(adapter->dev, "enable host interrupt failed\n");
653 * This function sends a data buffer to the card.
655 static int mwifiex_sdio_card_to_host(struct mwifiex_adapter *adapter,
656 u32 *type, u8 *buffer,
657 u32 npayload, u32 ioport)
663 dev_err(adapter->dev, "%s: buffer is NULL\n", __func__);
667 ret = mwifiex_read_data_sync(adapter, buffer, npayload, ioport, 1);
670 dev_err(adapter->dev, "%s: read iomem failed: %d\n", __func__,
675 nb = le16_to_cpu(*(__le16 *) (buffer));
677 dev_err(adapter->dev, "%s: invalid packet, nb=%d, npayload=%d\n",
678 __func__, nb, npayload);
682 *type = le16_to_cpu(*(__le16 *) (buffer + 2));
688 * This function downloads the firmware to the card.
690 * Firmware is downloaded to the card in blocks. Every block download
691 * is tested for CRC errors, and retried a number of times before
694 static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter,
695 struct mwifiex_fw_image *fw)
698 u8 *firmware = fw->fw_buf;
699 u32 firmware_len = fw->fw_len;
704 u32 txlen, tx_blocks = 0, tries;
708 dev_err(adapter->dev, "firmware image not found!"
709 " Terminating download\n");
713 dev_dbg(adapter->dev, "info: downloading FW image (%d bytes)\n",
716 /* Assume that the allocated buffer is 8-byte aligned */
717 fwbuf = kzalloc(MWIFIEX_UPLD_SIZE, GFP_KERNEL);
719 dev_err(adapter->dev, "unable to alloc buffer for firmware."
720 " Terminating download\n");
724 /* Perform firmware data transfer */
726 /* The host polls for the DN_LD_CARD_RDY and CARD_IO_READY
728 ret = mwifiex_sdio_poll_card_status(adapter, CARD_IO_READY |
731 dev_err(adapter->dev, "FW download with helper:"
732 " poll status timeout @ %d\n", offset);
737 if (offset >= firmware_len)
740 for (tries = 0; tries < MAX_POLL_TRIES; tries++) {
741 ret = mwifiex_read_reg(adapter, HOST_F1_RD_BASE_0,
744 dev_err(adapter->dev, "dev BASE0 register read"
745 " failed: base0=0x%04X(%d). Terminating "
746 "download\n", base0, base0);
749 ret = mwifiex_read_reg(adapter, HOST_F1_RD_BASE_1,
752 dev_err(adapter->dev, "dev BASE1 register read"
753 " failed: base1=0x%04X(%d). Terminating "
754 "download\n", base1, base1);
757 len = (u16) (((base1 & 0xff) << 8) | (base0 & 0xff));
767 } else if (len > MWIFIEX_UPLD_SIZE) {
768 dev_err(adapter->dev, "FW download failed @ %d,"
769 " invalid length %d\n", offset, len);
778 if (i > MAX_WRITE_IOMEM_RETRY) {
779 dev_err(adapter->dev, "FW download failed @"
780 " %d, over max retry count\n", offset);
784 dev_err(adapter->dev, "CRC indicated by the helper:"
785 " len = 0x%04X, txlen = %d\n", len, txlen);
787 /* Setting this to 0 to resend from same offset */
792 /* Set blocksize to transfer - checking for last
794 if (firmware_len - offset < txlen)
795 txlen = firmware_len - offset;
797 tx_blocks = (txlen + MWIFIEX_SDIO_BLOCK_SIZE -
798 1) / MWIFIEX_SDIO_BLOCK_SIZE;
800 /* Copy payload to buffer */
801 memmove(fwbuf, &firmware[offset], txlen);
804 ret = mwifiex_write_data_sync(adapter, fwbuf, tx_blocks *
805 MWIFIEX_SDIO_BLOCK_SIZE,
808 dev_err(adapter->dev, "FW download, write iomem (%d)"
809 " failed @ %d\n", i, offset);
810 if (mwifiex_write_reg(adapter, CONFIGURATION_REG, 0x04))
811 dev_err(adapter->dev, "write CFG reg failed\n");
820 dev_dbg(adapter->dev, "info: FW download over, size %d bytes\n",
830 * This function checks the firmware status in card.
832 * The winner interface is also determined by this function.
834 static int mwifiex_check_fw_status(struct mwifiex_adapter *adapter,
842 /* Wait for firmware initialization event */
843 for (tries = 0; tries < poll_num; tries++) {
844 ret = mwifiex_sdio_read_fw_status(adapter, &firmware_stat);
847 if (firmware_stat == FIRMWARE_READY_SDIO) {
858 (adapter, CARD_FW_STATUS0_REG, &winner_status))
870 * This function reads the interrupt status from card.
872 static void mwifiex_interrupt_status(struct mwifiex_adapter *adapter)
874 struct sdio_mmc_card *card = adapter->card;
878 if (mwifiex_read_data_sync(adapter, card->mp_regs, MAX_MP_REGS,
879 REG_PORT | MWIFIEX_SDIO_BYTE_MODE_MASK,
881 dev_err(adapter->dev, "read mp_regs failed\n");
885 sdio_ireg = card->mp_regs[HOST_INTSTATUS_REG];
888 * DN_LD_HOST_INT_STATUS and/or UP_LD_HOST_INT_STATUS
889 * Clear the interrupt status register
891 dev_dbg(adapter->dev, "int: sdio_ireg = %#x\n", sdio_ireg);
892 spin_lock_irqsave(&adapter->int_lock, flags);
893 adapter->int_status |= sdio_ireg;
894 spin_unlock_irqrestore(&adapter->int_lock, flags);
899 * SDIO interrupt handler.
901 * This function reads the interrupt status from firmware and assigns
902 * the main process in workqueue which will handle the interrupt.
905 mwifiex_sdio_interrupt(struct sdio_func *func)
907 struct mwifiex_adapter *adapter;
908 struct sdio_mmc_card *card;
910 card = sdio_get_drvdata(func);
911 if (!card || !card->adapter) {
912 pr_debug("int: func=%p card=%p adapter=%p\n",
913 func, card, card ? card->adapter : NULL);
916 adapter = card->adapter;
918 if (adapter->surprise_removed)
921 if (!adapter->pps_uapsd_mode && adapter->ps_state == PS_STATE_SLEEP)
922 adapter->ps_state = PS_STATE_AWAKE;
924 mwifiex_interrupt_status(adapter);
925 queue_work(adapter->workqueue, &adapter->main_work);
929 * This function decodes a received packet.
931 * Based on the type, the packet is treated as either a data, or
932 * a command response, or an event, and the correct handler
933 * function is invoked.
935 static int mwifiex_decode_rx_packet(struct mwifiex_adapter *adapter,
936 struct sk_buff *skb, u32 upld_typ)
940 skb_pull(skb, INTF_HEADER_LEN);
943 case MWIFIEX_TYPE_DATA:
944 dev_dbg(adapter->dev, "info: --- Rx: Data packet ---\n");
945 mwifiex_handle_rx_packet(adapter, skb);
948 case MWIFIEX_TYPE_CMD:
949 dev_dbg(adapter->dev, "info: --- Rx: Cmd Response ---\n");
950 /* take care of curr_cmd = NULL case */
951 if (!adapter->curr_cmd) {
952 cmd_buf = adapter->upld_buf;
954 if (adapter->ps_state == PS_STATE_SLEEP_CFM)
955 mwifiex_process_sleep_confirm_resp(adapter,
956 skb->data, skb->len);
958 memcpy(cmd_buf, skb->data, min_t(u32,
959 MWIFIEX_SIZE_OF_CMD_BUFFER, skb->len));
961 dev_kfree_skb_any(skb);
963 adapter->cmd_resp_received = true;
964 adapter->curr_cmd->resp_skb = skb;
968 case MWIFIEX_TYPE_EVENT:
969 dev_dbg(adapter->dev, "info: --- Rx: Event ---\n");
970 adapter->event_cause = *(u32 *) skb->data;
972 skb_pull(skb, MWIFIEX_EVENT_HEADER_LEN);
974 if ((skb->len > 0) && (skb->len < MAX_EVENT_SIZE))
975 memcpy(adapter->event_body, skb->data, skb->len);
977 /* event cause has been saved to adapter->event_cause */
978 adapter->event_received = true;
979 adapter->event_skb = skb;
984 dev_err(adapter->dev, "unknown upload type %#x\n", upld_typ);
985 dev_kfree_skb_any(skb);
993 * This function transfers received packets from card to driver, performing
994 * aggregation if required.
996 * For data received on control port, or if aggregation is disabled, the
997 * received buffers are uploaded as separate packets. However, if aggregation
998 * is enabled and required, the buffers are copied onto an aggregation buffer,
999 * provided there is space left, processed and finally uploaded.
1001 static int mwifiex_sdio_card_to_host_mp_aggr(struct mwifiex_adapter *adapter,
1002 struct sk_buff *skb, u8 port)
1004 struct sdio_mmc_card *card = adapter->card;
1005 s32 f_do_rx_aggr = 0;
1006 s32 f_do_rx_cur = 0;
1008 struct sk_buff *skb_deaggr;
1010 u32 pkt_len, pkt_type = 0;
1012 u32 rx_len = skb->len;
1014 if (port == CTRL_PORT) {
1015 /* Read the command Resp without aggr */
1016 dev_dbg(adapter->dev, "info: %s: no aggregation for cmd "
1017 "response\n", __func__);
1020 goto rx_curr_single;
1023 if (!card->mpa_rx.enabled) {
1024 dev_dbg(adapter->dev, "info: %s: rx aggregation disabled\n",
1028 goto rx_curr_single;
1031 if (card->mp_rd_bitmap & (~((u16) CTRL_PORT_MASK))) {
1032 /* Some more data RX pending */
1033 dev_dbg(adapter->dev, "info: %s: not last packet\n", __func__);
1035 if (MP_RX_AGGR_IN_PROGRESS(card)) {
1036 if (MP_RX_AGGR_BUF_HAS_ROOM(card, skb->len)) {
1039 /* No room in Aggr buf, do rx aggr now */
1044 /* Rx aggr not in progress */
1049 /* No more data RX pending */
1050 dev_dbg(adapter->dev, "info: %s: last packet\n", __func__);
1052 if (MP_RX_AGGR_IN_PROGRESS(card)) {
1054 if (MP_RX_AGGR_BUF_HAS_ROOM(card, skb->len))
1057 /* No room in Aggr buf, do rx aggr now */
1065 dev_dbg(adapter->dev, "info: current packet aggregation\n");
1066 /* Curr pkt can be aggregated */
1067 MP_RX_AGGR_SETUP(card, skb, port);
1069 if (MP_RX_AGGR_PKT_LIMIT_REACHED(card) ||
1070 MP_RX_AGGR_PORT_LIMIT_REACHED(card)) {
1071 dev_dbg(adapter->dev, "info: %s: aggregated packet "
1072 "limit reached\n", __func__);
1073 /* No more pkts allowed in Aggr buf, rx it */
1079 /* do aggr RX now */
1080 dev_dbg(adapter->dev, "info: do_rx_aggr: num of packets: %d\n",
1081 card->mpa_rx.pkt_cnt);
1083 if (mwifiex_read_data_sync(adapter, card->mpa_rx.buf,
1084 card->mpa_rx.buf_len,
1085 (adapter->ioport | 0x1000 |
1086 (card->mpa_rx.ports << 4)) +
1087 card->mpa_rx.start_port, 1))
1090 curr_ptr = card->mpa_rx.buf;
1092 for (pind = 0; pind < card->mpa_rx.pkt_cnt; pind++) {
1094 /* get curr PKT len & type */
1095 pkt_len = *(u16 *) &curr_ptr[0];
1096 pkt_type = *(u16 *) &curr_ptr[2];
1098 /* copy pkt to deaggr buf */
1099 skb_deaggr = card->mpa_rx.skb_arr[pind];
1101 if ((pkt_type == MWIFIEX_TYPE_DATA) && (pkt_len <=
1102 card->mpa_rx.len_arr[pind])) {
1104 memcpy(skb_deaggr->data, curr_ptr, pkt_len);
1106 skb_trim(skb_deaggr, pkt_len);
1108 /* Process de-aggr packet */
1109 mwifiex_decode_rx_packet(adapter, skb_deaggr,
1112 dev_err(adapter->dev, "wrong aggr pkt:"
1113 " type=%d len=%d max_len=%d\n",
1115 card->mpa_rx.len_arr[pind]);
1116 dev_kfree_skb_any(skb_deaggr);
1118 curr_ptr += card->mpa_rx.len_arr[pind];
1120 MP_RX_AGGR_BUF_RESET(card);
1125 dev_dbg(adapter->dev, "info: RX: port: %d, rx_len: %d\n",
1128 if (mwifiex_sdio_card_to_host(adapter, &pkt_type,
1129 skb->data, skb->len,
1130 adapter->ioport + port))
1133 mwifiex_decode_rx_packet(adapter, skb, pkt_type);
1139 if (MP_RX_AGGR_IN_PROGRESS(card)) {
1140 /* Multiport-aggregation transfer failed - cleanup */
1141 for (pind = 0; pind < card->mpa_rx.pkt_cnt; pind++) {
1142 /* copy pkt to deaggr buf */
1143 skb_deaggr = card->mpa_rx.skb_arr[pind];
1144 dev_kfree_skb_any(skb_deaggr);
1146 MP_RX_AGGR_BUF_RESET(card);
1150 /* Single transfer pending. Free curr buff also */
1151 dev_kfree_skb_any(skb);
1157 * This function checks the current interrupt status.
1159 * The following interrupts are checked and handled by this function -
1162 * - Packets received
1164 * Since the firmware does not generate download ready interrupt if the
1165 * port updated is command port only, command sent interrupt checking
1166 * should be done manually, and for every SDIO interrupt.
1168 * In case of Rx packets received, the packets are uploaded from card to
1169 * host and processed accordingly.
1171 static int mwifiex_process_int_status(struct mwifiex_adapter *adapter)
1173 struct sdio_mmc_card *card = adapter->card;
1176 struct sk_buff *skb;
1177 u8 port = CTRL_PORT;
1178 u32 len_reg_l, len_reg_u;
1181 unsigned long flags;
1183 spin_lock_irqsave(&adapter->int_lock, flags);
1184 sdio_ireg = adapter->int_status;
1185 adapter->int_status = 0;
1186 spin_unlock_irqrestore(&adapter->int_lock, flags);
1191 if (sdio_ireg & DN_LD_HOST_INT_STATUS) {
1192 card->mp_wr_bitmap = ((u16) card->mp_regs[WR_BITMAP_U]) << 8;
1193 card->mp_wr_bitmap |= (u16) card->mp_regs[WR_BITMAP_L];
1194 dev_dbg(adapter->dev, "int: DNLD: wr_bitmap=0x%04x\n",
1195 card->mp_wr_bitmap);
1196 if (adapter->data_sent &&
1197 (card->mp_wr_bitmap & card->mp_data_port_mask)) {
1198 dev_dbg(adapter->dev,
1199 "info: <--- Tx DONE Interrupt --->\n");
1200 adapter->data_sent = false;
1204 /* As firmware will not generate download ready interrupt if the port
1205 updated is command port only, cmd_sent should be done for any SDIO
1207 if (adapter->cmd_sent) {
1208 /* Check if firmware has attach buffer at command port and
1209 update just that in wr_bit_map. */
1210 card->mp_wr_bitmap |=
1211 (u16) card->mp_regs[WR_BITMAP_L] & CTRL_PORT_MASK;
1212 if (card->mp_wr_bitmap & CTRL_PORT_MASK)
1213 adapter->cmd_sent = false;
1216 dev_dbg(adapter->dev, "info: cmd_sent=%d data_sent=%d\n",
1217 adapter->cmd_sent, adapter->data_sent);
1218 if (sdio_ireg & UP_LD_HOST_INT_STATUS) {
1219 card->mp_rd_bitmap = ((u16) card->mp_regs[RD_BITMAP_U]) << 8;
1220 card->mp_rd_bitmap |= (u16) card->mp_regs[RD_BITMAP_L];
1221 dev_dbg(adapter->dev, "int: UPLD: rd_bitmap=0x%04x\n",
1222 card->mp_rd_bitmap);
1225 ret = mwifiex_get_rd_port(adapter, &port);
1227 dev_dbg(adapter->dev,
1228 "info: no more rd_port available\n");
1231 len_reg_l = RD_LEN_P0_L + (port << 1);
1232 len_reg_u = RD_LEN_P0_U + (port << 1);
1233 rx_len = ((u16) card->mp_regs[len_reg_u]) << 8;
1234 rx_len |= (u16) card->mp_regs[len_reg_l];
1235 dev_dbg(adapter->dev, "info: RX: port=%d rx_len=%u\n",
1238 (rx_len + MWIFIEX_SDIO_BLOCK_SIZE -
1239 1) / MWIFIEX_SDIO_BLOCK_SIZE;
1240 if (rx_len <= INTF_HEADER_LEN
1241 || (rx_blocks * MWIFIEX_SDIO_BLOCK_SIZE) >
1242 MWIFIEX_RX_DATA_BUF_SIZE) {
1243 dev_err(adapter->dev, "invalid rx_len=%d\n",
1247 rx_len = (u16) (rx_blocks * MWIFIEX_SDIO_BLOCK_SIZE);
1249 skb = dev_alloc_skb(rx_len);
1252 dev_err(adapter->dev, "%s: failed to alloc skb",
1257 skb_put(skb, rx_len);
1259 dev_dbg(adapter->dev, "info: rx_len = %d skb->len = %d\n",
1262 if (mwifiex_sdio_card_to_host_mp_aggr(adapter, skb,
1266 dev_err(adapter->dev, "card_to_host_mpa failed:"
1267 " int status=%#x\n", sdio_ireg);
1268 if (mwifiex_read_reg(adapter,
1269 CONFIGURATION_REG, &cr))
1270 dev_err(adapter->dev,
1271 "read CFG reg failed\n");
1273 dev_dbg(adapter->dev,
1274 "info: CFG reg val = %d\n", cr);
1275 if (mwifiex_write_reg(adapter,
1278 dev_err(adapter->dev,
1279 "write CFG reg failed\n");
1281 dev_dbg(adapter->dev, "info: write success\n");
1282 if (mwifiex_read_reg(adapter,
1283 CONFIGURATION_REG, &cr))
1284 dev_err(adapter->dev,
1285 "read CFG reg failed\n");
1287 dev_dbg(adapter->dev,
1288 "info: CFG reg val =%x\n", cr);
1298 * This function aggregates transmission buffers in driver and downloads
1299 * the aggregated packet to card.
1301 * The individual packets are aggregated by copying into an aggregation
1302 * buffer and then downloaded to the card. Previous unsent packets in the
1303 * aggregation buffer are pre-copied first before new packets are added.
1304 * Aggregation is done till there is space left in the aggregation buffer,
1305 * or till new packets are available.
1307 * The function will only download the packet to the card when aggregation
1308 * stops, otherwise it will just aggregate the packet in aggregation buffer
1311 static int mwifiex_host_to_card_mp_aggr(struct mwifiex_adapter *adapter,
1312 u8 *payload, u32 pkt_len, u8 port,
1315 struct sdio_mmc_card *card = adapter->card;
1317 s32 f_send_aggr_buf = 0;
1318 s32 f_send_cur_buf = 0;
1319 s32 f_precopy_cur_buf = 0;
1320 s32 f_postcopy_cur_buf = 0;
1322 if ((!card->mpa_tx.enabled) || (port == CTRL_PORT)) {
1323 dev_dbg(adapter->dev, "info: %s: tx aggregation disabled\n",
1327 goto tx_curr_single;
1331 /* More pkt in TX queue */
1332 dev_dbg(adapter->dev, "info: %s: more packets in queue.\n",
1335 if (MP_TX_AGGR_IN_PROGRESS(card)) {
1336 if (!MP_TX_AGGR_PORT_LIMIT_REACHED(card) &&
1337 MP_TX_AGGR_BUF_HAS_ROOM(card, pkt_len)) {
1338 f_precopy_cur_buf = 1;
1340 if (!(card->mp_wr_bitmap &
1341 (1 << card->curr_wr_port))
1342 || !MP_TX_AGGR_BUF_HAS_ROOM(
1343 card, pkt_len + next_pkt_len))
1344 f_send_aggr_buf = 1;
1346 /* No room in Aggr buf, send it */
1347 f_send_aggr_buf = 1;
1349 if (MP_TX_AGGR_PORT_LIMIT_REACHED(card) ||
1350 !(card->mp_wr_bitmap &
1351 (1 << card->curr_wr_port)))
1354 f_postcopy_cur_buf = 1;
1357 if (MP_TX_AGGR_BUF_HAS_ROOM(card, pkt_len)
1358 && (card->mp_wr_bitmap & (1 << card->curr_wr_port)))
1359 f_precopy_cur_buf = 1;
1364 /* Last pkt in TX queue */
1365 dev_dbg(adapter->dev, "info: %s: Last packet in Tx Queue.\n",
1368 if (MP_TX_AGGR_IN_PROGRESS(card)) {
1369 /* some packs in Aggr buf already */
1370 f_send_aggr_buf = 1;
1372 if (MP_TX_AGGR_BUF_HAS_ROOM(card, pkt_len))
1373 f_precopy_cur_buf = 1;
1375 /* No room in Aggr buf, send it */
1382 if (f_precopy_cur_buf) {
1383 dev_dbg(adapter->dev, "data: %s: precopy current buffer\n",
1385 MP_TX_AGGR_BUF_PUT(card, payload, pkt_len, port);
1387 if (MP_TX_AGGR_PKT_LIMIT_REACHED(card) ||
1388 MP_TX_AGGR_PORT_LIMIT_REACHED(card))
1389 /* No more pkts allowed in Aggr buf, send it */
1390 f_send_aggr_buf = 1;
1393 if (f_send_aggr_buf) {
1394 dev_dbg(adapter->dev, "data: %s: send aggr buffer: %d %d\n",
1396 card->mpa_tx.start_port, card->mpa_tx.ports);
1397 ret = mwifiex_write_data_to_card(adapter, card->mpa_tx.buf,
1398 card->mpa_tx.buf_len,
1399 (adapter->ioport | 0x1000 |
1400 (card->mpa_tx.ports << 4)) +
1401 card->mpa_tx.start_port);
1403 MP_TX_AGGR_BUF_RESET(card);
1407 if (f_send_cur_buf) {
1408 dev_dbg(adapter->dev, "data: %s: send current buffer %d\n",
1410 ret = mwifiex_write_data_to_card(adapter, payload, pkt_len,
1411 adapter->ioport + port);
1414 if (f_postcopy_cur_buf) {
1415 dev_dbg(adapter->dev, "data: %s: postcopy current buffer\n",
1417 MP_TX_AGGR_BUF_PUT(card, payload, pkt_len, port);
1424 * This function downloads data from driver to card.
1426 * Both commands and data packets are transferred to the card by this
1429 * This function adds the SDIO specific header to the front of the buffer
1430 * before transferring. The header contains the length of the packet and
1431 * the type. The firmware handles the packets based upon this set type.
1433 static int mwifiex_sdio_host_to_card(struct mwifiex_adapter *adapter,
1434 u8 type, struct sk_buff *skb,
1435 struct mwifiex_tx_param *tx_param)
1437 struct sdio_mmc_card *card = adapter->card;
1441 u8 port = CTRL_PORT;
1442 u8 *payload = (u8 *)skb->data;
1443 u32 pkt_len = skb->len;
1445 /* Allocate buffer and copy payload */
1446 blk_size = MWIFIEX_SDIO_BLOCK_SIZE;
1447 buf_block_len = (pkt_len + blk_size - 1) / blk_size;
1448 *(u16 *) &payload[0] = (u16) pkt_len;
1449 *(u16 *) &payload[2] = type;
1452 * This is SDIO specific header
1454 * u16 type (MWIFIEX_TYPE_DATA = 0, MWIFIEX_TYPE_CMD = 1,
1455 * MWIFIEX_TYPE_EVENT = 3)
1457 if (type == MWIFIEX_TYPE_DATA) {
1458 ret = mwifiex_get_wr_port_data(adapter, &port);
1460 dev_err(adapter->dev, "%s: no wr_port available\n",
1465 adapter->cmd_sent = true;
1466 /* Type must be MWIFIEX_TYPE_CMD */
1468 if (pkt_len <= INTF_HEADER_LEN ||
1469 pkt_len > MWIFIEX_UPLD_SIZE)
1470 dev_err(adapter->dev, "%s: payload=%p, nb=%d\n",
1471 __func__, payload, pkt_len);
1474 /* Transfer data to card */
1475 pkt_len = buf_block_len * blk_size;
1478 ret = mwifiex_host_to_card_mp_aggr(adapter, payload, pkt_len,
1479 port, tx_param->next_pkt_len);
1481 ret = mwifiex_host_to_card_mp_aggr(adapter, payload, pkt_len,
1485 if (type == MWIFIEX_TYPE_CMD)
1486 adapter->cmd_sent = false;
1487 if (type == MWIFIEX_TYPE_DATA)
1488 adapter->data_sent = false;
1490 if (type == MWIFIEX_TYPE_DATA) {
1491 if (!(card->mp_wr_bitmap & (1 << card->curr_wr_port)))
1492 adapter->data_sent = true;
1494 adapter->data_sent = false;
1502 * This function allocates the MPA Tx and Rx buffers.
1504 static int mwifiex_alloc_sdio_mpa_buffers(struct mwifiex_adapter *adapter,
1505 u32 mpa_tx_buf_size, u32 mpa_rx_buf_size)
1507 struct sdio_mmc_card *card = adapter->card;
1510 card->mpa_tx.buf = kzalloc(mpa_tx_buf_size, GFP_KERNEL);
1511 if (!card->mpa_tx.buf) {
1512 dev_err(adapter->dev, "could not alloc buffer for MP-A TX\n");
1517 card->mpa_tx.buf_size = mpa_tx_buf_size;
1519 card->mpa_rx.buf = kzalloc(mpa_rx_buf_size, GFP_KERNEL);
1520 if (!card->mpa_rx.buf) {
1521 dev_err(adapter->dev, "could not alloc buffer for MP-A RX\n");
1526 card->mpa_rx.buf_size = mpa_rx_buf_size;
1530 kfree(card->mpa_tx.buf);
1531 kfree(card->mpa_rx.buf);
1538 * This function unregisters the SDIO device.
1540 * The SDIO IRQ is released, the function is disabled and driver
1541 * data is set to null.
1544 mwifiex_unregister_dev(struct mwifiex_adapter *adapter)
1546 struct sdio_mmc_card *card = adapter->card;
1548 if (adapter->card) {
1549 /* Release the SDIO IRQ */
1550 sdio_claim_host(card->func);
1551 sdio_release_irq(card->func);
1552 sdio_disable_func(card->func);
1553 sdio_release_host(card->func);
1554 sdio_set_drvdata(card->func, NULL);
1559 * This function registers the SDIO device.
1561 * SDIO IRQ is claimed, block size is set and driver data is initialized.
1563 static int mwifiex_register_dev(struct mwifiex_adapter *adapter)
1566 struct sdio_mmc_card *card = adapter->card;
1567 struct sdio_func *func = card->func;
1569 /* save adapter pointer in card */
1570 card->adapter = adapter;
1572 sdio_claim_host(func);
1574 /* Request the SDIO IRQ */
1575 ret = sdio_claim_irq(func, mwifiex_sdio_interrupt);
1577 pr_err("claim irq failed: ret=%d\n", ret);
1581 /* Set block size */
1582 ret = sdio_set_block_size(card->func, MWIFIEX_SDIO_BLOCK_SIZE);
1584 pr_err("cannot set SDIO block size\n");
1589 sdio_release_host(func);
1590 sdio_set_drvdata(func, card);
1592 adapter->dev = &func->dev;
1594 switch (func->device) {
1595 case SDIO_DEVICE_ID_MARVELL_8797:
1596 strcpy(adapter->fw_name, SD8797_DEFAULT_FW_NAME);
1598 case SDIO_DEVICE_ID_MARVELL_8787:
1600 strcpy(adapter->fw_name, SD8787_DEFAULT_FW_NAME);
1607 sdio_release_irq(func);
1609 sdio_disable_func(func);
1610 sdio_release_host(func);
1611 adapter->card = NULL;
1617 * This function initializes the SDIO driver.
1619 * The following initializations steps are followed -
1620 * - Read the Host interrupt status register to acknowledge
1621 * the first interrupt got from bootloader
1622 * - Disable host interrupt mask register
1624 * - Initialize SDIO variables in card
1625 * - Allocate MP registers
1626 * - Allocate MPA Tx and Rx buffers
1628 static int mwifiex_init_sdio(struct mwifiex_adapter *adapter)
1630 struct sdio_mmc_card *card = adapter->card;
1635 * Read the HOST_INT_STATUS_REG for ACK the first interrupt got
1636 * from the bootloader. If we don't do this we get a interrupt
1637 * as soon as we register the irq.
1639 mwifiex_read_reg(adapter, HOST_INTSTATUS_REG, &sdio_ireg);
1641 /* Disable host interrupt mask register for SDIO */
1642 mwifiex_sdio_disable_host_int(adapter);
1644 /* Get SDIO ioport */
1645 mwifiex_init_sdio_ioport(adapter);
1647 /* Initialize SDIO variables in card */
1648 card->mp_rd_bitmap = 0;
1649 card->mp_wr_bitmap = 0;
1650 card->curr_rd_port = 1;
1651 card->curr_wr_port = 1;
1653 card->mp_data_port_mask = DATA_PORT_MASK;
1655 card->mpa_tx.buf_len = 0;
1656 card->mpa_tx.pkt_cnt = 0;
1657 card->mpa_tx.start_port = 0;
1659 card->mpa_tx.enabled = 1;
1660 card->mpa_tx.pkt_aggr_limit = SDIO_MP_AGGR_DEF_PKT_LIMIT;
1662 card->mpa_rx.buf_len = 0;
1663 card->mpa_rx.pkt_cnt = 0;
1664 card->mpa_rx.start_port = 0;
1666 card->mpa_rx.enabled = 1;
1667 card->mpa_rx.pkt_aggr_limit = SDIO_MP_AGGR_DEF_PKT_LIMIT;
1669 /* Allocate buffers for SDIO MP-A */
1670 card->mp_regs = kzalloc(MAX_MP_REGS, GFP_KERNEL);
1671 if (!card->mp_regs) {
1672 dev_err(adapter->dev, "failed to alloc mp_regs\n");
1676 ret = mwifiex_alloc_sdio_mpa_buffers(adapter,
1677 SDIO_MP_TX_AGGR_DEF_BUF_SIZE,
1678 SDIO_MP_RX_AGGR_DEF_BUF_SIZE);
1680 dev_err(adapter->dev, "failed to alloc sdio mp-a buffers\n");
1681 kfree(card->mp_regs);
1689 * This function resets the MPA Tx and Rx buffers.
1691 static void mwifiex_cleanup_mpa_buf(struct mwifiex_adapter *adapter)
1693 struct sdio_mmc_card *card = adapter->card;
1695 MP_TX_AGGR_BUF_RESET(card);
1696 MP_RX_AGGR_BUF_RESET(card);
1700 * This function cleans up the allocated card buffers.
1702 * The following are freed by this function -
1707 static void mwifiex_cleanup_sdio(struct mwifiex_adapter *adapter)
1709 struct sdio_mmc_card *card = adapter->card;
1711 kfree(card->mp_regs);
1712 kfree(card->mpa_tx.buf);
1713 kfree(card->mpa_rx.buf);
1717 * This function updates the MP end port in card.
1720 mwifiex_update_mp_end_port(struct mwifiex_adapter *adapter, u16 port)
1722 struct sdio_mmc_card *card = adapter->card;
1725 card->mp_end_port = port;
1727 card->mp_data_port_mask = DATA_PORT_MASK;
1729 for (i = 1; i <= MAX_PORT - card->mp_end_port; i++)
1730 card->mp_data_port_mask &= ~(1 << (MAX_PORT - i));
1732 card->curr_wr_port = 1;
1734 dev_dbg(adapter->dev, "cmd: mp_end_port %d, data port mask 0x%x\n",
1735 port, card->mp_data_port_mask);
1738 static struct mwifiex_if_ops sdio_ops = {
1739 .init_if = mwifiex_init_sdio,
1740 .cleanup_if = mwifiex_cleanup_sdio,
1741 .check_fw_status = mwifiex_check_fw_status,
1742 .prog_fw = mwifiex_prog_fw_w_helper,
1743 .register_dev = mwifiex_register_dev,
1744 .unregister_dev = mwifiex_unregister_dev,
1745 .enable_int = mwifiex_sdio_enable_host_int,
1746 .process_int_status = mwifiex_process_int_status,
1747 .host_to_card = mwifiex_sdio_host_to_card,
1748 .wakeup = mwifiex_pm_wakeup_card,
1749 .wakeup_complete = mwifiex_pm_wakeup_card_complete,
1752 .update_mp_end_port = mwifiex_update_mp_end_port,
1753 .cleanup_mpa_buf = mwifiex_cleanup_mpa_buf,
1754 .cmdrsp_complete = mwifiex_sdio_cmdrsp_complete,
1755 .event_complete = mwifiex_sdio_event_complete,
1759 * This function initializes the SDIO driver.
1761 * This initiates the semaphore and registers the device with
1765 mwifiex_sdio_init_module(void)
1767 sema_init(&add_remove_card_sem, 1);
1769 /* Clear the flag in case user removes the card. */
1772 return sdio_register_driver(&mwifiex_sdio);
1776 * This function cleans up the SDIO driver.
1778 * The following major steps are followed for cleanup -
1779 * - Resume the device if its suspended
1780 * - Disconnect the device if connected
1781 * - Shutdown the firmware
1782 * - Unregister the device from SDIO bus.
1785 mwifiex_sdio_cleanup_module(void)
1787 if (!down_interruptible(&add_remove_card_sem))
1788 up(&add_remove_card_sem);
1790 /* Set the flag as user is removing this module. */
1793 sdio_unregister_driver(&mwifiex_sdio);
1796 module_init(mwifiex_sdio_init_module);
1797 module_exit(mwifiex_sdio_cleanup_module);
1799 MODULE_AUTHOR("Marvell International Ltd.");
1800 MODULE_DESCRIPTION("Marvell WiFi-Ex SDIO Driver version " SDIO_VERSION);
1801 MODULE_VERSION(SDIO_VERSION);
1802 MODULE_LICENSE("GPL v2");
1803 MODULE_FIRMWARE(SD8787_DEFAULT_FW_NAME);
1804 MODULE_FIRMWARE(SD8797_DEFAULT_FW_NAME);