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;
169 pm_flag = sdio_get_host_pm_caps(func);
170 pr_debug("cmd: %s: suspend: PM flag = 0x%x\n",
171 sdio_func_id(func), pm_flag);
172 if (!(pm_flag & MMC_PM_KEEP_POWER)) {
173 pr_err("%s: cannot remain alive while host is"
174 " suspended\n", sdio_func_id(func));
178 card = sdio_get_drvdata(func);
179 if (!card || !card->adapter) {
180 pr_err("suspend: invalid card or adapter\n");
184 pr_err("suspend: sdio_func is not specified\n");
188 adapter = card->adapter;
190 /* Enable the Host Sleep */
191 hs_actived = mwifiex_enable_hs(adapter);
193 pr_debug("cmd: suspend with MMC_PM_KEEP_POWER\n");
194 ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER);
197 /* Indicate device suspended */
198 adapter->is_suspended = true;
200 for (i = 0; i < adapter->priv_num; i++)
201 netif_carrier_off(adapter->priv[i]->netdev);
209 * Kernel needs to suspend all functions separately. Therefore all
210 * registered functions must have drivers with suspend and resume
211 * methods. Failing that the kernel simply removes the whole card.
213 * If already not resumed, this function turns on the traffic and
214 * sends a host sleep cancel request to the firmware.
216 static int mwifiex_sdio_resume(struct device *dev)
218 struct sdio_func *func = dev_to_sdio_func(dev);
219 struct sdio_mmc_card *card;
220 struct mwifiex_adapter *adapter;
221 mmc_pm_flag_t pm_flag = 0;
225 pm_flag = sdio_get_host_pm_caps(func);
226 card = sdio_get_drvdata(func);
227 if (!card || !card->adapter) {
228 pr_err("resume: invalid card or adapter\n");
232 pr_err("resume: sdio_func is not specified\n");
236 adapter = card->adapter;
238 if (!adapter->is_suspended) {
239 dev_warn(adapter->dev, "device already resumed\n");
243 adapter->is_suspended = false;
245 for (i = 0; i < adapter->priv_num; i++)
246 if (adapter->priv[i]->media_connected)
247 netif_carrier_on(adapter->priv[i]->netdev);
249 /* Disable Host Sleep */
250 mwifiex_cancel_hs(mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA),
256 /* Device ID for SD8786 */
257 #define SDIO_DEVICE_ID_MARVELL_8786 (0x9116)
258 /* Device ID for SD8787 */
259 #define SDIO_DEVICE_ID_MARVELL_8787 (0x9119)
260 /* Device ID for SD8797 */
261 #define SDIO_DEVICE_ID_MARVELL_8797 (0x9129)
264 static const struct sdio_device_id mwifiex_ids[] = {
265 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8786)},
266 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8787)},
267 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8797)},
271 MODULE_DEVICE_TABLE(sdio, mwifiex_ids);
273 static const struct dev_pm_ops mwifiex_sdio_pm_ops = {
274 .suspend = mwifiex_sdio_suspend,
275 .resume = mwifiex_sdio_resume,
278 static struct sdio_driver mwifiex_sdio = {
279 .name = "mwifiex_sdio",
280 .id_table = mwifiex_ids,
281 .probe = mwifiex_sdio_probe,
282 .remove = mwifiex_sdio_remove,
284 .owner = THIS_MODULE,
285 .pm = &mwifiex_sdio_pm_ops,
290 * This function writes data into SDIO card register.
293 mwifiex_write_reg(struct mwifiex_adapter *adapter, u32 reg, u32 data)
295 struct sdio_mmc_card *card = adapter->card;
298 sdio_claim_host(card->func);
299 sdio_writeb(card->func, (u8) data, reg, &ret);
300 sdio_release_host(card->func);
306 * This function reads data from SDIO card register.
309 mwifiex_read_reg(struct mwifiex_adapter *adapter, u32 reg, u32 *data)
311 struct sdio_mmc_card *card = adapter->card;
315 sdio_claim_host(card->func);
316 val = sdio_readb(card->func, reg, &ret);
317 sdio_release_host(card->func);
325 * This function writes multiple data into SDIO card memory.
327 * This does not work in suspended mode.
330 mwifiex_write_data_sync(struct mwifiex_adapter *adapter,
331 u8 *buffer, u32 pkt_len, u32 port)
333 struct sdio_mmc_card *card = adapter->card;
336 (port & MWIFIEX_SDIO_BYTE_MODE_MASK) ? BYTE_MODE : BLOCK_MODE;
337 u32 blk_size = (blk_mode == BLOCK_MODE) ? MWIFIEX_SDIO_BLOCK_SIZE : 1;
340 BLOCK_MODE) ? (pkt_len /
341 MWIFIEX_SDIO_BLOCK_SIZE) : pkt_len;
342 u32 ioport = (port & MWIFIEX_SDIO_IO_PORT_MASK);
344 if (adapter->is_suspended) {
345 dev_err(adapter->dev,
346 "%s: not allowed while suspended\n", __func__);
350 sdio_claim_host(card->func);
352 if (!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 if (!sdio_readsb(card->func, buffer, ioport, blk_cnt * blk_size))
382 sdio_release_host(card->func);
388 * This function wakes up the card.
390 * A host power up command is written to the card configuration
391 * register to wake up the card.
393 static int mwifiex_pm_wakeup_card(struct mwifiex_adapter *adapter)
395 dev_dbg(adapter->dev, "event: wakeup device...\n");
397 return mwifiex_write_reg(adapter, CONFIGURATION_REG, HOST_POWER_UP);
401 * This function is called after the card has woken up.
403 * The card configuration register is reset.
405 static int mwifiex_pm_wakeup_card_complete(struct mwifiex_adapter *adapter)
407 dev_dbg(adapter->dev, "cmd: wakeup device completed\n");
409 return mwifiex_write_reg(adapter, CONFIGURATION_REG, 0);
413 * This function initializes the IO ports.
415 * The following operations are performed -
416 * - Read the IO ports (0, 1 and 2)
417 * - Set host interrupt Reset-To-Read to clear
418 * - Set auto re-enable interrupt
420 static int mwifiex_init_sdio_ioport(struct mwifiex_adapter *adapter)
426 /* Read the IO port */
427 if (!mwifiex_read_reg(adapter, IO_PORT_0_REG, ®))
428 adapter->ioport |= (reg & 0xff);
432 if (!mwifiex_read_reg(adapter, IO_PORT_1_REG, ®))
433 adapter->ioport |= ((reg & 0xff) << 8);
437 if (!mwifiex_read_reg(adapter, IO_PORT_2_REG, ®))
438 adapter->ioport |= ((reg & 0xff) << 16);
442 pr_debug("info: SDIO FUNC1 IO port: %#x\n", adapter->ioport);
444 /* Set Host interrupt reset to read to clear */
445 if (!mwifiex_read_reg(adapter, HOST_INT_RSR_REG, ®))
446 mwifiex_write_reg(adapter, HOST_INT_RSR_REG,
447 reg | SDIO_INT_MASK);
451 /* Dnld/Upld ready set to auto reset */
452 if (!mwifiex_read_reg(adapter, CARD_MISC_CFG_REG, ®))
453 mwifiex_write_reg(adapter, CARD_MISC_CFG_REG,
454 reg | AUTO_RE_ENABLE_INT);
462 * This function sends data to the card.
464 static int mwifiex_write_data_to_card(struct mwifiex_adapter *adapter,
465 u8 *payload, u32 pkt_len, u32 port)
471 ret = mwifiex_write_data_sync(adapter, payload, pkt_len, port);
474 dev_err(adapter->dev, "host_to_card, write iomem"
475 " (%d) failed: %d\n", i, ret);
476 if (mwifiex_write_reg(adapter, CONFIGURATION_REG, 0x04))
477 dev_err(adapter->dev, "write CFG reg failed\n");
480 if (i > MAX_WRITE_IOMEM_RETRY)
489 * This function gets the read port.
491 * If control port bit is set in MP read bitmap, the control port
492 * is returned, otherwise the current read port is returned and
493 * the value is increased (provided it does not reach the maximum
494 * limit, in which case it is reset to 1)
496 static int mwifiex_get_rd_port(struct mwifiex_adapter *adapter, u8 *port)
498 struct sdio_mmc_card *card = adapter->card;
499 u16 rd_bitmap = card->mp_rd_bitmap;
501 dev_dbg(adapter->dev, "data: mp_rd_bitmap=0x%04x\n", rd_bitmap);
503 if (!(rd_bitmap & (CTRL_PORT_MASK | DATA_PORT_MASK)))
506 if (card->mp_rd_bitmap & CTRL_PORT_MASK) {
507 card->mp_rd_bitmap &= (u16) (~CTRL_PORT_MASK);
509 dev_dbg(adapter->dev, "data: port=%d mp_rd_bitmap=0x%04x\n",
510 *port, card->mp_rd_bitmap);
512 if (card->mp_rd_bitmap & (1 << card->curr_rd_port)) {
513 card->mp_rd_bitmap &= (u16)
514 (~(1 << card->curr_rd_port));
515 *port = card->curr_rd_port;
517 if (++card->curr_rd_port == MAX_PORT)
518 card->curr_rd_port = 1;
523 dev_dbg(adapter->dev,
524 "data: port=%d mp_rd_bitmap=0x%04x -> 0x%04x\n",
525 *port, rd_bitmap, card->mp_rd_bitmap);
531 * This function gets the write port for data.
533 * The current write port is returned if available and the value is
534 * increased (provided it does not reach the maximum limit, in which
535 * case it is reset to 1)
537 static int mwifiex_get_wr_port_data(struct mwifiex_adapter *adapter, u8 *port)
539 struct sdio_mmc_card *card = adapter->card;
540 u16 wr_bitmap = card->mp_wr_bitmap;
542 dev_dbg(adapter->dev, "data: mp_wr_bitmap=0x%04x\n", wr_bitmap);
544 if (!(wr_bitmap & card->mp_data_port_mask))
547 if (card->mp_wr_bitmap & (1 << card->curr_wr_port)) {
548 card->mp_wr_bitmap &= (u16) (~(1 << card->curr_wr_port));
549 *port = card->curr_wr_port;
550 if (++card->curr_wr_port == card->mp_end_port)
551 card->curr_wr_port = 1;
553 adapter->data_sent = true;
557 if (*port == CTRL_PORT) {
558 dev_err(adapter->dev, "invalid data port=%d cur port=%d"
559 " mp_wr_bitmap=0x%04x -> 0x%04x\n",
560 *port, card->curr_wr_port, wr_bitmap,
565 dev_dbg(adapter->dev, "data: port=%d mp_wr_bitmap=0x%04x -> 0x%04x\n",
566 *port, wr_bitmap, card->mp_wr_bitmap);
572 * This function polls the card status.
575 mwifiex_sdio_poll_card_status(struct mwifiex_adapter *adapter, u8 bits)
580 for (tries = 0; tries < MAX_POLL_TRIES; tries++) {
581 if (mwifiex_read_reg(adapter, CARD_STATUS_REG, &cs))
583 else if ((cs & bits) == bits)
586 usleep_range(10, 20);
589 dev_err(adapter->dev, "poll card status failed, tries = %d\n", tries);
595 * This function reads the firmware status.
598 mwifiex_sdio_read_fw_status(struct mwifiex_adapter *adapter, u16 *dat)
602 if (mwifiex_read_reg(adapter, CARD_FW_STATUS0_REG, &fws0))
605 if (mwifiex_read_reg(adapter, CARD_FW_STATUS1_REG, &fws1))
608 *dat = (u16) ((fws1 << 8) | fws0);
614 * This function disables the host interrupt.
616 * The host interrupt mask is read, the disable bit is reset and
617 * written back to the card host interrupt mask register.
619 static int mwifiex_sdio_disable_host_int(struct mwifiex_adapter *adapter)
623 /* Read back the host_int_mask register */
624 if (mwifiex_read_reg(adapter, HOST_INT_MASK_REG, &host_int_mask))
627 /* Update with the mask and write back to the register */
628 host_int_mask &= ~HOST_INT_DISABLE;
630 if (mwifiex_write_reg(adapter, HOST_INT_MASK_REG, host_int_mask)) {
631 dev_err(adapter->dev, "disable host interrupt failed\n");
639 * This function enables the host interrupt.
641 * The host interrupt enable mask is written to the card
642 * host interrupt mask register.
644 static int mwifiex_sdio_enable_host_int(struct mwifiex_adapter *adapter)
646 /* Simply write the mask to the register */
647 if (mwifiex_write_reg(adapter, HOST_INT_MASK_REG, HOST_INT_ENABLE)) {
648 dev_err(adapter->dev, "enable host interrupt failed\n");
655 * This function sends a data buffer to the card.
657 static int mwifiex_sdio_card_to_host(struct mwifiex_adapter *adapter,
658 u32 *type, u8 *buffer,
659 u32 npayload, u32 ioport)
665 dev_err(adapter->dev, "%s: buffer is NULL\n", __func__);
669 ret = mwifiex_read_data_sync(adapter, buffer, npayload, ioport, 1);
672 dev_err(adapter->dev, "%s: read iomem failed: %d\n", __func__,
677 nb = le16_to_cpu(*(__le16 *) (buffer));
679 dev_err(adapter->dev, "%s: invalid packet, nb=%d npayload=%d\n",
680 __func__, nb, npayload);
684 *type = le16_to_cpu(*(__le16 *) (buffer + 2));
690 * This function downloads the firmware to the card.
692 * Firmware is downloaded to the card in blocks. Every block download
693 * is tested for CRC errors, and retried a number of times before
696 static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter,
697 struct mwifiex_fw_image *fw)
700 u8 *firmware = fw->fw_buf;
701 u32 firmware_len = fw->fw_len;
706 u32 txlen, tx_blocks = 0, tries;
710 dev_err(adapter->dev,
711 "firmware image not found! Terminating download\n");
715 dev_dbg(adapter->dev, "info: downloading FW image (%d bytes)\n",
718 /* Assume that the allocated buffer is 8-byte aligned */
719 fwbuf = kzalloc(MWIFIEX_UPLD_SIZE, GFP_KERNEL);
721 dev_err(adapter->dev,
722 "unable to alloc buffer for FW. Terminating dnld\n");
726 /* Perform firmware data transfer */
728 /* The host polls for the DN_LD_CARD_RDY and CARD_IO_READY
730 ret = mwifiex_sdio_poll_card_status(adapter, CARD_IO_READY |
733 dev_err(adapter->dev, "FW download with helper:"
734 " poll status timeout @ %d\n", offset);
739 if (offset >= firmware_len)
742 for (tries = 0; tries < MAX_POLL_TRIES; tries++) {
743 ret = mwifiex_read_reg(adapter, HOST_F1_RD_BASE_0,
746 dev_err(adapter->dev,
747 "dev BASE0 register read failed: "
748 "base0=%#04X(%d). Terminating dnld\n",
752 ret = mwifiex_read_reg(adapter, HOST_F1_RD_BASE_1,
755 dev_err(adapter->dev,
756 "dev BASE1 register read failed: "
757 "base1=%#04X(%d). Terminating dnld\n",
761 len = (u16) (((base1 & 0xff) << 8) | (base0 & 0xff));
766 usleep_range(10, 20);
771 } else if (len > MWIFIEX_UPLD_SIZE) {
772 dev_err(adapter->dev,
773 "FW dnld failed @ %d, invalid length %d\n",
783 if (i > MAX_WRITE_IOMEM_RETRY) {
784 dev_err(adapter->dev,
785 "FW dnld failed @ %d, over max retry\n",
790 dev_err(adapter->dev, "CRC indicated by the helper:"
791 " len = 0x%04X, txlen = %d\n", len, txlen);
793 /* Setting this to 0 to resend from same offset */
798 /* Set blocksize to transfer - checking for last
800 if (firmware_len - offset < txlen)
801 txlen = firmware_len - offset;
803 tx_blocks = (txlen + MWIFIEX_SDIO_BLOCK_SIZE - 1)
804 / MWIFIEX_SDIO_BLOCK_SIZE;
806 /* Copy payload to buffer */
807 memmove(fwbuf, &firmware[offset], txlen);
810 ret = mwifiex_write_data_sync(adapter, fwbuf, tx_blocks *
811 MWIFIEX_SDIO_BLOCK_SIZE,
814 dev_err(adapter->dev,
815 "FW download, write iomem (%d) failed @ %d\n",
817 if (mwifiex_write_reg(adapter, CONFIGURATION_REG, 0x04))
818 dev_err(adapter->dev, "write CFG reg failed\n");
827 dev_dbg(adapter->dev, "info: FW download over, size %d bytes\n",
837 * This function checks the firmware status in card.
839 * The winner interface is also determined by this function.
841 static int mwifiex_check_fw_status(struct mwifiex_adapter *adapter,
849 /* Wait for firmware initialization event */
850 for (tries = 0; tries < poll_num; tries++) {
851 ret = mwifiex_sdio_read_fw_status(adapter, &firmware_stat);
854 if (firmware_stat == FIRMWARE_READY_SDIO) {
865 (adapter, CARD_FW_STATUS0_REG, &winner_status))
877 * This function reads the interrupt status from card.
879 static void mwifiex_interrupt_status(struct mwifiex_adapter *adapter)
881 struct sdio_mmc_card *card = adapter->card;
885 if (mwifiex_read_data_sync(adapter, card->mp_regs, MAX_MP_REGS,
886 REG_PORT | MWIFIEX_SDIO_BYTE_MODE_MASK,
888 dev_err(adapter->dev, "read mp_regs failed\n");
892 sdio_ireg = card->mp_regs[HOST_INTSTATUS_REG];
895 * DN_LD_HOST_INT_STATUS and/or UP_LD_HOST_INT_STATUS
896 * Clear the interrupt status register
898 dev_dbg(adapter->dev, "int: sdio_ireg = %#x\n", sdio_ireg);
899 spin_lock_irqsave(&adapter->int_lock, flags);
900 adapter->int_status |= sdio_ireg;
901 spin_unlock_irqrestore(&adapter->int_lock, flags);
906 * SDIO interrupt handler.
908 * This function reads the interrupt status from firmware and assigns
909 * the main process in workqueue which will handle the interrupt.
912 mwifiex_sdio_interrupt(struct sdio_func *func)
914 struct mwifiex_adapter *adapter;
915 struct sdio_mmc_card *card;
917 card = sdio_get_drvdata(func);
918 if (!card || !card->adapter) {
919 pr_debug("int: func=%p card=%p adapter=%p\n",
920 func, card, card ? card->adapter : NULL);
923 adapter = card->adapter;
925 if (adapter->surprise_removed)
928 if (!adapter->pps_uapsd_mode && adapter->ps_state == PS_STATE_SLEEP)
929 adapter->ps_state = PS_STATE_AWAKE;
931 mwifiex_interrupt_status(adapter);
932 queue_work(adapter->workqueue, &adapter->main_work);
936 * This function decodes a received packet.
938 * Based on the type, the packet is treated as either a data, or
939 * a command response, or an event, and the correct handler
940 * function is invoked.
942 static int mwifiex_decode_rx_packet(struct mwifiex_adapter *adapter,
943 struct sk_buff *skb, u32 upld_typ)
947 skb_pull(skb, INTF_HEADER_LEN);
950 case MWIFIEX_TYPE_DATA:
951 dev_dbg(adapter->dev, "info: --- Rx: Data packet ---\n");
952 mwifiex_handle_rx_packet(adapter, skb);
955 case MWIFIEX_TYPE_CMD:
956 dev_dbg(adapter->dev, "info: --- Rx: Cmd Response ---\n");
957 /* take care of curr_cmd = NULL case */
958 if (!adapter->curr_cmd) {
959 cmd_buf = adapter->upld_buf;
961 if (adapter->ps_state == PS_STATE_SLEEP_CFM)
962 mwifiex_process_sleep_confirm_resp(adapter,
966 memcpy(cmd_buf, skb->data,
967 min_t(u32, MWIFIEX_SIZE_OF_CMD_BUFFER,
970 dev_kfree_skb_any(skb);
972 adapter->cmd_resp_received = true;
973 adapter->curr_cmd->resp_skb = skb;
977 case MWIFIEX_TYPE_EVENT:
978 dev_dbg(adapter->dev, "info: --- Rx: Event ---\n");
979 adapter->event_cause = *(u32 *) skb->data;
981 skb_pull(skb, MWIFIEX_EVENT_HEADER_LEN);
983 if ((skb->len > 0) && (skb->len < MAX_EVENT_SIZE))
984 memcpy(adapter->event_body, skb->data, skb->len);
986 /* event cause has been saved to adapter->event_cause */
987 adapter->event_received = true;
988 adapter->event_skb = skb;
993 dev_err(adapter->dev, "unknown upload type %#x\n", upld_typ);
994 dev_kfree_skb_any(skb);
1002 * This function transfers received packets from card to driver, performing
1003 * aggregation if required.
1005 * For data received on control port, or if aggregation is disabled, the
1006 * received buffers are uploaded as separate packets. However, if aggregation
1007 * is enabled and required, the buffers are copied onto an aggregation buffer,
1008 * provided there is space left, processed and finally uploaded.
1010 static int mwifiex_sdio_card_to_host_mp_aggr(struct mwifiex_adapter *adapter,
1011 struct sk_buff *skb, u8 port)
1013 struct sdio_mmc_card *card = adapter->card;
1014 s32 f_do_rx_aggr = 0;
1015 s32 f_do_rx_cur = 0;
1017 struct sk_buff *skb_deaggr;
1019 u32 pkt_len, pkt_type = 0;
1021 u32 rx_len = skb->len;
1023 if (port == CTRL_PORT) {
1024 /* Read the command Resp without aggr */
1025 dev_dbg(adapter->dev, "info: %s: no aggregation for cmd "
1026 "response\n", __func__);
1029 goto rx_curr_single;
1032 if (!card->mpa_rx.enabled) {
1033 dev_dbg(adapter->dev, "info: %s: rx aggregation disabled\n",
1037 goto rx_curr_single;
1040 if (card->mp_rd_bitmap & (~((u16) CTRL_PORT_MASK))) {
1041 /* Some more data RX pending */
1042 dev_dbg(adapter->dev, "info: %s: not last packet\n", __func__);
1044 if (MP_RX_AGGR_IN_PROGRESS(card)) {
1045 if (MP_RX_AGGR_BUF_HAS_ROOM(card, skb->len)) {
1048 /* No room in Aggr buf, do rx aggr now */
1053 /* Rx aggr not in progress */
1058 /* No more data RX pending */
1059 dev_dbg(adapter->dev, "info: %s: last packet\n", __func__);
1061 if (MP_RX_AGGR_IN_PROGRESS(card)) {
1063 if (MP_RX_AGGR_BUF_HAS_ROOM(card, skb->len))
1066 /* No room in Aggr buf, do rx aggr now */
1074 dev_dbg(adapter->dev, "info: current packet aggregation\n");
1075 /* Curr pkt can be aggregated */
1076 MP_RX_AGGR_SETUP(card, skb, port);
1078 if (MP_RX_AGGR_PKT_LIMIT_REACHED(card) ||
1079 MP_RX_AGGR_PORT_LIMIT_REACHED(card)) {
1080 dev_dbg(adapter->dev, "info: %s: aggregated packet "
1081 "limit reached\n", __func__);
1082 /* No more pkts allowed in Aggr buf, rx it */
1088 /* do aggr RX now */
1089 dev_dbg(adapter->dev, "info: do_rx_aggr: num of packets: %d\n",
1090 card->mpa_rx.pkt_cnt);
1092 if (mwifiex_read_data_sync(adapter, card->mpa_rx.buf,
1093 card->mpa_rx.buf_len,
1094 (adapter->ioport | 0x1000 |
1095 (card->mpa_rx.ports << 4)) +
1096 card->mpa_rx.start_port, 1))
1099 curr_ptr = card->mpa_rx.buf;
1101 for (pind = 0; pind < card->mpa_rx.pkt_cnt; pind++) {
1103 /* get curr PKT len & type */
1104 pkt_len = *(u16 *) &curr_ptr[0];
1105 pkt_type = *(u16 *) &curr_ptr[2];
1107 /* copy pkt to deaggr buf */
1108 skb_deaggr = card->mpa_rx.skb_arr[pind];
1110 if ((pkt_type == MWIFIEX_TYPE_DATA) && (pkt_len <=
1111 card->mpa_rx.len_arr[pind])) {
1113 memcpy(skb_deaggr->data, curr_ptr, pkt_len);
1115 skb_trim(skb_deaggr, pkt_len);
1117 /* Process de-aggr packet */
1118 mwifiex_decode_rx_packet(adapter, skb_deaggr,
1121 dev_err(adapter->dev, "wrong aggr pkt:"
1122 " type=%d len=%d max_len=%d\n",
1124 card->mpa_rx.len_arr[pind]);
1125 dev_kfree_skb_any(skb_deaggr);
1127 curr_ptr += card->mpa_rx.len_arr[pind];
1129 MP_RX_AGGR_BUF_RESET(card);
1134 dev_dbg(adapter->dev, "info: RX: port: %d, rx_len: %d\n",
1137 if (mwifiex_sdio_card_to_host(adapter, &pkt_type,
1138 skb->data, skb->len,
1139 adapter->ioport + port))
1142 mwifiex_decode_rx_packet(adapter, skb, pkt_type);
1148 if (MP_RX_AGGR_IN_PROGRESS(card)) {
1149 /* Multiport-aggregation transfer failed - cleanup */
1150 for (pind = 0; pind < card->mpa_rx.pkt_cnt; pind++) {
1151 /* copy pkt to deaggr buf */
1152 skb_deaggr = card->mpa_rx.skb_arr[pind];
1153 dev_kfree_skb_any(skb_deaggr);
1155 MP_RX_AGGR_BUF_RESET(card);
1159 /* Single transfer pending. Free curr buff also */
1160 dev_kfree_skb_any(skb);
1166 * This function checks the current interrupt status.
1168 * The following interrupts are checked and handled by this function -
1171 * - Packets received
1173 * Since the firmware does not generate download ready interrupt if the
1174 * port updated is command port only, command sent interrupt checking
1175 * should be done manually, and for every SDIO interrupt.
1177 * In case of Rx packets received, the packets are uploaded from card to
1178 * host and processed accordingly.
1180 static int mwifiex_process_int_status(struct mwifiex_adapter *adapter)
1182 struct sdio_mmc_card *card = adapter->card;
1185 struct sk_buff *skb;
1186 u8 port = CTRL_PORT;
1187 u32 len_reg_l, len_reg_u;
1190 unsigned long flags;
1192 spin_lock_irqsave(&adapter->int_lock, flags);
1193 sdio_ireg = adapter->int_status;
1194 adapter->int_status = 0;
1195 spin_unlock_irqrestore(&adapter->int_lock, flags);
1200 if (sdio_ireg & DN_LD_HOST_INT_STATUS) {
1201 card->mp_wr_bitmap = ((u16) card->mp_regs[WR_BITMAP_U]) << 8;
1202 card->mp_wr_bitmap |= (u16) card->mp_regs[WR_BITMAP_L];
1203 dev_dbg(adapter->dev, "int: DNLD: wr_bitmap=0x%04x\n",
1204 card->mp_wr_bitmap);
1205 if (adapter->data_sent &&
1206 (card->mp_wr_bitmap & card->mp_data_port_mask)) {
1207 dev_dbg(adapter->dev,
1208 "info: <--- Tx DONE Interrupt --->\n");
1209 adapter->data_sent = false;
1213 /* As firmware will not generate download ready interrupt if the port
1214 updated is command port only, cmd_sent should be done for any SDIO
1216 if (adapter->cmd_sent) {
1217 /* Check if firmware has attach buffer at command port and
1218 update just that in wr_bit_map. */
1219 card->mp_wr_bitmap |=
1220 (u16) card->mp_regs[WR_BITMAP_L] & CTRL_PORT_MASK;
1221 if (card->mp_wr_bitmap & CTRL_PORT_MASK)
1222 adapter->cmd_sent = false;
1225 dev_dbg(adapter->dev, "info: cmd_sent=%d data_sent=%d\n",
1226 adapter->cmd_sent, adapter->data_sent);
1227 if (sdio_ireg & UP_LD_HOST_INT_STATUS) {
1228 card->mp_rd_bitmap = ((u16) card->mp_regs[RD_BITMAP_U]) << 8;
1229 card->mp_rd_bitmap |= (u16) card->mp_regs[RD_BITMAP_L];
1230 dev_dbg(adapter->dev, "int: UPLD: rd_bitmap=0x%04x\n",
1231 card->mp_rd_bitmap);
1234 ret = mwifiex_get_rd_port(adapter, &port);
1236 dev_dbg(adapter->dev,
1237 "info: no more rd_port available\n");
1240 len_reg_l = RD_LEN_P0_L + (port << 1);
1241 len_reg_u = RD_LEN_P0_U + (port << 1);
1242 rx_len = ((u16) card->mp_regs[len_reg_u]) << 8;
1243 rx_len |= (u16) card->mp_regs[len_reg_l];
1244 dev_dbg(adapter->dev, "info: RX: port=%d rx_len=%u\n",
1247 (rx_len + MWIFIEX_SDIO_BLOCK_SIZE -
1248 1) / MWIFIEX_SDIO_BLOCK_SIZE;
1249 if (rx_len <= INTF_HEADER_LEN ||
1250 (rx_blocks * MWIFIEX_SDIO_BLOCK_SIZE) >
1251 MWIFIEX_RX_DATA_BUF_SIZE) {
1252 dev_err(adapter->dev, "invalid rx_len=%d\n",
1256 rx_len = (u16) (rx_blocks * MWIFIEX_SDIO_BLOCK_SIZE);
1258 skb = dev_alloc_skb(rx_len);
1261 dev_err(adapter->dev, "%s: failed to alloc skb",
1266 skb_put(skb, rx_len);
1268 dev_dbg(adapter->dev, "info: rx_len = %d skb->len = %d\n",
1271 if (mwifiex_sdio_card_to_host_mp_aggr(adapter, skb,
1275 dev_err(adapter->dev, "card_to_host_mpa failed:"
1276 " int status=%#x\n", sdio_ireg);
1277 if (mwifiex_read_reg(adapter,
1278 CONFIGURATION_REG, &cr))
1279 dev_err(adapter->dev,
1280 "read CFG reg failed\n");
1282 dev_dbg(adapter->dev,
1283 "info: CFG reg val = %d\n", cr);
1284 if (mwifiex_write_reg(adapter,
1287 dev_err(adapter->dev,
1288 "write CFG reg failed\n");
1290 dev_dbg(adapter->dev, "info: write success\n");
1291 if (mwifiex_read_reg(adapter,
1292 CONFIGURATION_REG, &cr))
1293 dev_err(adapter->dev,
1294 "read CFG reg failed\n");
1296 dev_dbg(adapter->dev,
1297 "info: CFG reg val =%x\n", cr);
1307 * This function aggregates transmission buffers in driver and downloads
1308 * the aggregated packet to card.
1310 * The individual packets are aggregated by copying into an aggregation
1311 * buffer and then downloaded to the card. Previous unsent packets in the
1312 * aggregation buffer are pre-copied first before new packets are added.
1313 * Aggregation is done till there is space left in the aggregation buffer,
1314 * or till new packets are available.
1316 * The function will only download the packet to the card when aggregation
1317 * stops, otherwise it will just aggregate the packet in aggregation buffer
1320 static int mwifiex_host_to_card_mp_aggr(struct mwifiex_adapter *adapter,
1321 u8 *payload, u32 pkt_len, u8 port,
1324 struct sdio_mmc_card *card = adapter->card;
1326 s32 f_send_aggr_buf = 0;
1327 s32 f_send_cur_buf = 0;
1328 s32 f_precopy_cur_buf = 0;
1329 s32 f_postcopy_cur_buf = 0;
1331 if ((!card->mpa_tx.enabled) || (port == CTRL_PORT)) {
1332 dev_dbg(adapter->dev, "info: %s: tx aggregation disabled\n",
1336 goto tx_curr_single;
1340 /* More pkt in TX queue */
1341 dev_dbg(adapter->dev, "info: %s: more packets in queue.\n",
1344 if (MP_TX_AGGR_IN_PROGRESS(card)) {
1345 if (!MP_TX_AGGR_PORT_LIMIT_REACHED(card) &&
1346 MP_TX_AGGR_BUF_HAS_ROOM(card, pkt_len)) {
1347 f_precopy_cur_buf = 1;
1349 if (!(card->mp_wr_bitmap &
1350 (1 << card->curr_wr_port)) ||
1351 !MP_TX_AGGR_BUF_HAS_ROOM(
1352 card, pkt_len + next_pkt_len))
1353 f_send_aggr_buf = 1;
1355 /* No room in Aggr buf, send it */
1356 f_send_aggr_buf = 1;
1358 if (MP_TX_AGGR_PORT_LIMIT_REACHED(card) ||
1359 !(card->mp_wr_bitmap &
1360 (1 << card->curr_wr_port)))
1363 f_postcopy_cur_buf = 1;
1366 if (MP_TX_AGGR_BUF_HAS_ROOM(card, pkt_len) &&
1367 (card->mp_wr_bitmap & (1 << card->curr_wr_port)))
1368 f_precopy_cur_buf = 1;
1373 /* Last pkt in TX queue */
1374 dev_dbg(adapter->dev, "info: %s: Last packet in Tx Queue.\n",
1377 if (MP_TX_AGGR_IN_PROGRESS(card)) {
1378 /* some packs in Aggr buf already */
1379 f_send_aggr_buf = 1;
1381 if (MP_TX_AGGR_BUF_HAS_ROOM(card, pkt_len))
1382 f_precopy_cur_buf = 1;
1384 /* No room in Aggr buf, send it */
1391 if (f_precopy_cur_buf) {
1392 dev_dbg(adapter->dev, "data: %s: precopy current buffer\n",
1394 MP_TX_AGGR_BUF_PUT(card, payload, pkt_len, port);
1396 if (MP_TX_AGGR_PKT_LIMIT_REACHED(card) ||
1397 MP_TX_AGGR_PORT_LIMIT_REACHED(card))
1398 /* No more pkts allowed in Aggr buf, send it */
1399 f_send_aggr_buf = 1;
1402 if (f_send_aggr_buf) {
1403 dev_dbg(adapter->dev, "data: %s: send aggr buffer: %d %d\n",
1405 card->mpa_tx.start_port, card->mpa_tx.ports);
1406 ret = mwifiex_write_data_to_card(adapter, card->mpa_tx.buf,
1407 card->mpa_tx.buf_len,
1408 (adapter->ioport | 0x1000 |
1409 (card->mpa_tx.ports << 4)) +
1410 card->mpa_tx.start_port);
1412 MP_TX_AGGR_BUF_RESET(card);
1416 if (f_send_cur_buf) {
1417 dev_dbg(adapter->dev, "data: %s: send current buffer %d\n",
1419 ret = mwifiex_write_data_to_card(adapter, payload, pkt_len,
1420 adapter->ioport + port);
1423 if (f_postcopy_cur_buf) {
1424 dev_dbg(adapter->dev, "data: %s: postcopy current buffer\n",
1426 MP_TX_AGGR_BUF_PUT(card, payload, pkt_len, port);
1433 * This function downloads data from driver to card.
1435 * Both commands and data packets are transferred to the card by this
1438 * This function adds the SDIO specific header to the front of the buffer
1439 * before transferring. The header contains the length of the packet and
1440 * the type. The firmware handles the packets based upon this set type.
1442 static int mwifiex_sdio_host_to_card(struct mwifiex_adapter *adapter,
1443 u8 type, struct sk_buff *skb,
1444 struct mwifiex_tx_param *tx_param)
1446 struct sdio_mmc_card *card = adapter->card;
1450 u8 port = CTRL_PORT;
1451 u8 *payload = (u8 *)skb->data;
1452 u32 pkt_len = skb->len;
1454 /* Allocate buffer and copy payload */
1455 blk_size = MWIFIEX_SDIO_BLOCK_SIZE;
1456 buf_block_len = (pkt_len + blk_size - 1) / blk_size;
1457 *(u16 *) &payload[0] = (u16) pkt_len;
1458 *(u16 *) &payload[2] = type;
1461 * This is SDIO specific header
1463 * u16 type (MWIFIEX_TYPE_DATA = 0, MWIFIEX_TYPE_CMD = 1,
1464 * MWIFIEX_TYPE_EVENT = 3)
1466 if (type == MWIFIEX_TYPE_DATA) {
1467 ret = mwifiex_get_wr_port_data(adapter, &port);
1469 dev_err(adapter->dev, "%s: no wr_port available\n",
1474 adapter->cmd_sent = true;
1475 /* Type must be MWIFIEX_TYPE_CMD */
1477 if (pkt_len <= INTF_HEADER_LEN ||
1478 pkt_len > MWIFIEX_UPLD_SIZE)
1479 dev_err(adapter->dev, "%s: payload=%p, nb=%d\n",
1480 __func__, payload, pkt_len);
1483 /* Transfer data to card */
1484 pkt_len = buf_block_len * blk_size;
1487 ret = mwifiex_host_to_card_mp_aggr(adapter, payload, pkt_len,
1488 port, tx_param->next_pkt_len
1491 ret = mwifiex_host_to_card_mp_aggr(adapter, payload, pkt_len,
1495 if (type == MWIFIEX_TYPE_CMD)
1496 adapter->cmd_sent = false;
1497 if (type == MWIFIEX_TYPE_DATA)
1498 adapter->data_sent = false;
1500 if (type == MWIFIEX_TYPE_DATA) {
1501 if (!(card->mp_wr_bitmap & (1 << card->curr_wr_port)))
1502 adapter->data_sent = true;
1504 adapter->data_sent = false;
1512 * This function allocates the MPA Tx and Rx buffers.
1514 static int mwifiex_alloc_sdio_mpa_buffers(struct mwifiex_adapter *adapter,
1515 u32 mpa_tx_buf_size, u32 mpa_rx_buf_size)
1517 struct sdio_mmc_card *card = adapter->card;
1520 card->mpa_tx.buf = kzalloc(mpa_tx_buf_size, GFP_KERNEL);
1521 if (!card->mpa_tx.buf) {
1522 dev_err(adapter->dev, "could not alloc buffer for MP-A TX\n");
1527 card->mpa_tx.buf_size = mpa_tx_buf_size;
1529 card->mpa_rx.buf = kzalloc(mpa_rx_buf_size, GFP_KERNEL);
1530 if (!card->mpa_rx.buf) {
1531 dev_err(adapter->dev, "could not alloc buffer for MP-A RX\n");
1536 card->mpa_rx.buf_size = mpa_rx_buf_size;
1540 kfree(card->mpa_tx.buf);
1541 kfree(card->mpa_rx.buf);
1548 * This function unregisters the SDIO device.
1550 * The SDIO IRQ is released, the function is disabled and driver
1551 * data is set to null.
1554 mwifiex_unregister_dev(struct mwifiex_adapter *adapter)
1556 struct sdio_mmc_card *card = adapter->card;
1558 if (adapter->card) {
1559 /* Release the SDIO IRQ */
1560 sdio_claim_host(card->func);
1561 sdio_release_irq(card->func);
1562 sdio_disable_func(card->func);
1563 sdio_release_host(card->func);
1564 sdio_set_drvdata(card->func, NULL);
1569 * This function registers the SDIO device.
1571 * SDIO IRQ is claimed, block size is set and driver data is initialized.
1573 static int mwifiex_register_dev(struct mwifiex_adapter *adapter)
1576 struct sdio_mmc_card *card = adapter->card;
1577 struct sdio_func *func = card->func;
1579 /* save adapter pointer in card */
1580 card->adapter = adapter;
1582 sdio_claim_host(func);
1584 /* Request the SDIO IRQ */
1585 ret = sdio_claim_irq(func, mwifiex_sdio_interrupt);
1587 pr_err("claim irq failed: ret=%d\n", ret);
1591 /* Set block size */
1592 ret = sdio_set_block_size(card->func, MWIFIEX_SDIO_BLOCK_SIZE);
1594 pr_err("cannot set SDIO block size\n");
1599 sdio_release_host(func);
1600 sdio_set_drvdata(func, card);
1602 adapter->dev = &func->dev;
1604 switch (func->device) {
1605 case SDIO_DEVICE_ID_MARVELL_8786:
1606 strcpy(adapter->fw_name, SD8786_DEFAULT_FW_NAME);
1608 case SDIO_DEVICE_ID_MARVELL_8797:
1609 strcpy(adapter->fw_name, SD8797_DEFAULT_FW_NAME);
1611 case SDIO_DEVICE_ID_MARVELL_8787:
1613 strcpy(adapter->fw_name, SD8787_DEFAULT_FW_NAME);
1620 sdio_release_irq(func);
1622 sdio_disable_func(func);
1623 sdio_release_host(func);
1624 adapter->card = NULL;
1630 * This function initializes the SDIO driver.
1632 * The following initializations steps are followed -
1633 * - Read the Host interrupt status register to acknowledge
1634 * the first interrupt got from bootloader
1635 * - Disable host interrupt mask register
1637 * - Initialize SDIO variables in card
1638 * - Allocate MP registers
1639 * - Allocate MPA Tx and Rx buffers
1641 static int mwifiex_init_sdio(struct mwifiex_adapter *adapter)
1643 struct sdio_mmc_card *card = adapter->card;
1648 * Read the HOST_INT_STATUS_REG for ACK the first interrupt got
1649 * from the bootloader. If we don't do this we get a interrupt
1650 * as soon as we register the irq.
1652 mwifiex_read_reg(adapter, HOST_INTSTATUS_REG, &sdio_ireg);
1654 /* Disable host interrupt mask register for SDIO */
1655 mwifiex_sdio_disable_host_int(adapter);
1657 /* Get SDIO ioport */
1658 mwifiex_init_sdio_ioport(adapter);
1660 /* Initialize SDIO variables in card */
1661 card->mp_rd_bitmap = 0;
1662 card->mp_wr_bitmap = 0;
1663 card->curr_rd_port = 1;
1664 card->curr_wr_port = 1;
1666 card->mp_data_port_mask = DATA_PORT_MASK;
1668 card->mpa_tx.buf_len = 0;
1669 card->mpa_tx.pkt_cnt = 0;
1670 card->mpa_tx.start_port = 0;
1672 card->mpa_tx.enabled = 1;
1673 card->mpa_tx.pkt_aggr_limit = SDIO_MP_AGGR_DEF_PKT_LIMIT;
1675 card->mpa_rx.buf_len = 0;
1676 card->mpa_rx.pkt_cnt = 0;
1677 card->mpa_rx.start_port = 0;
1679 card->mpa_rx.enabled = 1;
1680 card->mpa_rx.pkt_aggr_limit = SDIO_MP_AGGR_DEF_PKT_LIMIT;
1682 /* Allocate buffers for SDIO MP-A */
1683 card->mp_regs = kzalloc(MAX_MP_REGS, GFP_KERNEL);
1684 if (!card->mp_regs) {
1685 dev_err(adapter->dev, "failed to alloc mp_regs\n");
1689 ret = mwifiex_alloc_sdio_mpa_buffers(adapter,
1690 SDIO_MP_TX_AGGR_DEF_BUF_SIZE,
1691 SDIO_MP_RX_AGGR_DEF_BUF_SIZE);
1693 dev_err(adapter->dev, "failed to alloc sdio mp-a buffers\n");
1694 kfree(card->mp_regs);
1702 * This function resets the MPA Tx and Rx buffers.
1704 static void mwifiex_cleanup_mpa_buf(struct mwifiex_adapter *adapter)
1706 struct sdio_mmc_card *card = adapter->card;
1708 MP_TX_AGGR_BUF_RESET(card);
1709 MP_RX_AGGR_BUF_RESET(card);
1713 * This function cleans up the allocated card buffers.
1715 * The following are freed by this function -
1720 static void mwifiex_cleanup_sdio(struct mwifiex_adapter *adapter)
1722 struct sdio_mmc_card *card = adapter->card;
1724 kfree(card->mp_regs);
1725 kfree(card->mpa_tx.buf);
1726 kfree(card->mpa_rx.buf);
1730 * This function updates the MP end port in card.
1733 mwifiex_update_mp_end_port(struct mwifiex_adapter *adapter, u16 port)
1735 struct sdio_mmc_card *card = adapter->card;
1738 card->mp_end_port = port;
1740 card->mp_data_port_mask = DATA_PORT_MASK;
1742 for (i = 1; i <= MAX_PORT - card->mp_end_port; i++)
1743 card->mp_data_port_mask &= ~(1 << (MAX_PORT - i));
1745 card->curr_wr_port = 1;
1747 dev_dbg(adapter->dev, "cmd: mp_end_port %d, data port mask 0x%x\n",
1748 port, card->mp_data_port_mask);
1751 static struct mwifiex_if_ops sdio_ops = {
1752 .init_if = mwifiex_init_sdio,
1753 .cleanup_if = mwifiex_cleanup_sdio,
1754 .check_fw_status = mwifiex_check_fw_status,
1755 .prog_fw = mwifiex_prog_fw_w_helper,
1756 .register_dev = mwifiex_register_dev,
1757 .unregister_dev = mwifiex_unregister_dev,
1758 .enable_int = mwifiex_sdio_enable_host_int,
1759 .process_int_status = mwifiex_process_int_status,
1760 .host_to_card = mwifiex_sdio_host_to_card,
1761 .wakeup = mwifiex_pm_wakeup_card,
1762 .wakeup_complete = mwifiex_pm_wakeup_card_complete,
1765 .update_mp_end_port = mwifiex_update_mp_end_port,
1766 .cleanup_mpa_buf = mwifiex_cleanup_mpa_buf,
1767 .cmdrsp_complete = mwifiex_sdio_cmdrsp_complete,
1768 .event_complete = mwifiex_sdio_event_complete,
1772 * This function initializes the SDIO driver.
1774 * This initiates the semaphore and registers the device with
1778 mwifiex_sdio_init_module(void)
1780 sema_init(&add_remove_card_sem, 1);
1782 /* Clear the flag in case user removes the card. */
1785 return sdio_register_driver(&mwifiex_sdio);
1789 * This function cleans up the SDIO driver.
1791 * The following major steps are followed for cleanup -
1792 * - Resume the device if its suspended
1793 * - Disconnect the device if connected
1794 * - Shutdown the firmware
1795 * - Unregister the device from SDIO bus.
1798 mwifiex_sdio_cleanup_module(void)
1800 if (!down_interruptible(&add_remove_card_sem))
1801 up(&add_remove_card_sem);
1803 /* Set the flag as user is removing this module. */
1806 sdio_unregister_driver(&mwifiex_sdio);
1809 module_init(mwifiex_sdio_init_module);
1810 module_exit(mwifiex_sdio_cleanup_module);
1812 MODULE_AUTHOR("Marvell International Ltd.");
1813 MODULE_DESCRIPTION("Marvell WiFi-Ex SDIO Driver version " SDIO_VERSION);
1814 MODULE_VERSION(SDIO_VERSION);
1815 MODULE_LICENSE("GPL v2");
1816 MODULE_FIRMWARE(SD8786_DEFAULT_FW_NAME);
1817 MODULE_FIRMWARE(SD8787_DEFAULT_FW_NAME);
1818 MODULE_FIRMWARE(SD8797_DEFAULT_FW_NAME);