2 * Marvell Wireless LAN device driver: SDIO specific handling
4 * Copyright (C) 2011, Marvell International Ltd.
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
20 #include <linux/firmware.h>
32 #define SDIO_VERSION "1.0"
34 /* The mwifiex_sdio_remove() callback function is called when
35 * user removes this module from kernel space or ejects
36 * the card from the slot. The driver handles these 2 cases
38 * If the user is removing the module, the few commands (FUNC_SHUTDOWN,
39 * HS_CANCEL etc.) are sent to the firmware.
40 * If the card is removed, there is no need to send these command.
42 * The variable 'user_rmmod' is used to distinguish these two
43 * scenarios. This flag is initialized as FALSE in case the card
44 * is removed, and will be set to TRUE for module removal when
45 * module_exit function is called.
49 static struct mwifiex_if_ops sdio_ops
;
51 static struct semaphore add_remove_card_sem
;
53 static int mwifiex_sdio_resume(struct device
*dev
);
58 * This function probes an mwifiex device and registers it. It allocates
59 * the card structure, enables SDIO function number and initiates the
60 * device registration and initialization procedure by adding a logical
64 mwifiex_sdio_probe(struct sdio_func
*func
, const struct sdio_device_id
*id
)
67 struct sdio_mmc_card
*card
= NULL
;
69 pr_debug("info: vendor=0x%4.04X device=0x%4.04X class=%d function=%d\n",
70 func
->vendor
, func
->device
, func
->class, func
->num
);
72 card
= kzalloc(sizeof(struct sdio_mmc_card
), GFP_KERNEL
);
74 pr_err("%s: failed to alloc memory\n", __func__
);
80 func
->card
->quirks
|= MMC_QUIRK_BLKSZ_FOR_BYTE_MODE
;
82 sdio_claim_host(func
);
83 ret
= sdio_enable_func(func
);
84 sdio_release_host(func
);
87 pr_err("%s: failed to enable function\n", __func__
);
92 if (mwifiex_add_card(card
, &add_remove_card_sem
, &sdio_ops
,
94 pr_err("%s: add card failed\n", __func__
);
96 sdio_claim_host(func
);
97 ret
= sdio_disable_func(func
);
98 sdio_release_host(func
);
108 * This function removes the interface and frees up the card structure.
111 mwifiex_sdio_remove(struct sdio_func
*func
)
113 struct sdio_mmc_card
*card
;
114 struct mwifiex_adapter
*adapter
;
117 pr_debug("info: SDIO func num=%d\n", func
->num
);
119 card
= sdio_get_drvdata(func
);
123 adapter
= card
->adapter
;
124 if (!adapter
|| !adapter
->priv_num
)
128 if (adapter
->is_suspended
)
129 mwifiex_sdio_resume(adapter
->dev
);
131 for (i
= 0; i
< adapter
->priv_num
; i
++)
132 if ((GET_BSS_ROLE(adapter
->priv
[i
]) ==
133 MWIFIEX_BSS_ROLE_STA
) &&
134 adapter
->priv
[i
]->media_connected
)
135 mwifiex_deauthenticate(adapter
->priv
[i
], NULL
);
137 mwifiex_disable_auto_ds(mwifiex_get_priv(adapter
,
138 MWIFIEX_BSS_ROLE_ANY
));
140 mwifiex_init_shutdown_fw(mwifiex_get_priv(adapter
,
141 MWIFIEX_BSS_ROLE_ANY
),
142 MWIFIEX_FUNC_SHUTDOWN
);
145 mwifiex_remove_card(card
->adapter
, &add_remove_card_sem
);
152 * Kernel needs to suspend all functions separately. Therefore all
153 * registered functions must have drivers with suspend and resume
154 * methods. Failing that the kernel simply removes the whole card.
156 * If already not suspended, this function allocates and sends a host
157 * sleep activate request to the firmware and turns off the traffic.
159 static int mwifiex_sdio_suspend(struct device
*dev
)
161 struct sdio_func
*func
= dev_to_sdio_func(dev
);
162 struct sdio_mmc_card
*card
;
163 struct mwifiex_adapter
*adapter
;
164 mmc_pm_flag_t pm_flag
= 0;
170 pm_flag
= sdio_get_host_pm_caps(func
);
171 pr_debug("cmd: %s: suspend: PM flag = 0x%x\n",
172 sdio_func_id(func
), pm_flag
);
173 if (!(pm_flag
& MMC_PM_KEEP_POWER
)) {
174 pr_err("%s: cannot remain alive while host is"
175 " suspended\n", sdio_func_id(func
));
179 card
= sdio_get_drvdata(func
);
180 if (!card
|| !card
->adapter
) {
181 pr_err("suspend: invalid card or adapter\n");
185 pr_err("suspend: sdio_func is not specified\n");
189 adapter
= card
->adapter
;
191 /* Enable the Host Sleep */
192 hs_actived
= mwifiex_enable_hs(adapter
);
194 pr_debug("cmd: suspend with MMC_PM_KEEP_POWER\n");
195 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 SD8787 */
258 #define SDIO_DEVICE_ID_MARVELL_8787 (0x9119)
261 static const struct sdio_device_id mwifiex_ids
[] = {
262 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8787
)},
266 MODULE_DEVICE_TABLE(sdio
, mwifiex_ids
);
268 static const struct dev_pm_ops mwifiex_sdio_pm_ops
= {
269 .suspend
= mwifiex_sdio_suspend
,
270 .resume
= mwifiex_sdio_resume
,
273 static struct sdio_driver mwifiex_sdio
= {
274 .name
= "mwifiex_sdio",
275 .id_table
= mwifiex_ids
,
276 .probe
= mwifiex_sdio_probe
,
277 .remove
= mwifiex_sdio_remove
,
279 .owner
= THIS_MODULE
,
280 .pm
= &mwifiex_sdio_pm_ops
,
285 * This function writes data into SDIO card register.
288 mwifiex_write_reg(struct mwifiex_adapter
*adapter
, u32 reg
, u32 data
)
290 struct sdio_mmc_card
*card
= adapter
->card
;
293 sdio_claim_host(card
->func
);
294 sdio_writeb(card
->func
, (u8
) data
, reg
, &ret
);
295 sdio_release_host(card
->func
);
301 * This function reads data from SDIO card register.
304 mwifiex_read_reg(struct mwifiex_adapter
*adapter
, u32 reg
, u32
*data
)
306 struct sdio_mmc_card
*card
= adapter
->card
;
310 sdio_claim_host(card
->func
);
311 val
= sdio_readb(card
->func
, reg
, &ret
);
312 sdio_release_host(card
->func
);
320 * This function writes multiple data into SDIO card memory.
322 * This does not work in suspended mode.
325 mwifiex_write_data_sync(struct mwifiex_adapter
*adapter
,
326 u8
*buffer
, u32 pkt_len
, u32 port
)
328 struct sdio_mmc_card
*card
= adapter
->card
;
331 (port
& MWIFIEX_SDIO_BYTE_MODE_MASK
) ? BYTE_MODE
: BLOCK_MODE
;
332 u32 blk_size
= (blk_mode
== BLOCK_MODE
) ? MWIFIEX_SDIO_BLOCK_SIZE
: 1;
335 BLOCK_MODE
) ? (pkt_len
/
336 MWIFIEX_SDIO_BLOCK_SIZE
) : pkt_len
;
337 u32 ioport
= (port
& MWIFIEX_SDIO_IO_PORT_MASK
);
339 if (adapter
->is_suspended
) {
340 dev_err(adapter
->dev
,
341 "%s: not allowed while suspended\n", __func__
);
345 sdio_claim_host(card
->func
);
347 if (!sdio_writesb(card
->func
, ioport
, buffer
, blk_cnt
* blk_size
))
350 sdio_release_host(card
->func
);
356 * This function reads multiple data from SDIO card memory.
358 static int mwifiex_read_data_sync(struct mwifiex_adapter
*adapter
, u8
*buffer
,
359 u32 len
, u32 port
, u8 claim
)
361 struct sdio_mmc_card
*card
= adapter
->card
;
364 (port
& MWIFIEX_SDIO_BYTE_MODE_MASK
) ? BYTE_MODE
: BLOCK_MODE
;
365 u32 blk_size
= (blk_mode
== BLOCK_MODE
) ? MWIFIEX_SDIO_BLOCK_SIZE
: 1;
368 BLOCK_MODE
) ? (len
/ MWIFIEX_SDIO_BLOCK_SIZE
) : len
;
369 u32 ioport
= (port
& MWIFIEX_SDIO_IO_PORT_MASK
);
372 sdio_claim_host(card
->func
);
374 if (!sdio_readsb(card
->func
, buffer
, ioport
, blk_cnt
* blk_size
))
378 sdio_release_host(card
->func
);
384 * This function wakes up the card.
386 * A host power up command is written to the card configuration
387 * register to wake up the card.
389 static int mwifiex_pm_wakeup_card(struct mwifiex_adapter
*adapter
)
391 dev_dbg(adapter
->dev
, "event: wakeup device...\n");
393 return mwifiex_write_reg(adapter
, CONFIGURATION_REG
, HOST_POWER_UP
);
397 * This function is called after the card has woken up.
399 * The card configuration register is reset.
401 static int mwifiex_pm_wakeup_card_complete(struct mwifiex_adapter
*adapter
)
403 dev_dbg(adapter
->dev
, "cmd: wakeup device completed\n");
405 return mwifiex_write_reg(adapter
, CONFIGURATION_REG
, 0);
409 * This function initializes the IO ports.
411 * The following operations are performed -
412 * - Read the IO ports (0, 1 and 2)
413 * - Set host interrupt Reset-To-Read to clear
414 * - Set auto re-enable interrupt
416 static int mwifiex_init_sdio_ioport(struct mwifiex_adapter
*adapter
)
422 /* Read the IO port */
423 if (!mwifiex_read_reg(adapter
, IO_PORT_0_REG
, ®
))
424 adapter
->ioport
|= (reg
& 0xff);
428 if (!mwifiex_read_reg(adapter
, IO_PORT_1_REG
, ®
))
429 adapter
->ioport
|= ((reg
& 0xff) << 8);
433 if (!mwifiex_read_reg(adapter
, IO_PORT_2_REG
, ®
))
434 adapter
->ioport
|= ((reg
& 0xff) << 16);
438 pr_debug("info: SDIO FUNC1 IO port: %#x\n", adapter
->ioport
);
440 /* Set Host interrupt reset to read to clear */
441 if (!mwifiex_read_reg(adapter
, HOST_INT_RSR_REG
, ®
))
442 mwifiex_write_reg(adapter
, HOST_INT_RSR_REG
,
443 reg
| SDIO_INT_MASK
);
447 /* Dnld/Upld ready set to auto reset */
448 if (!mwifiex_read_reg(adapter
, CARD_MISC_CFG_REG
, ®
))
449 mwifiex_write_reg(adapter
, CARD_MISC_CFG_REG
,
450 reg
| AUTO_RE_ENABLE_INT
);
458 * This function sends data to the card.
460 static int mwifiex_write_data_to_card(struct mwifiex_adapter
*adapter
,
461 u8
*payload
, u32 pkt_len
, u32 port
)
467 ret
= mwifiex_write_data_sync(adapter
, payload
, pkt_len
, port
);
470 dev_err(adapter
->dev
, "host_to_card, write iomem"
471 " (%d) failed: %d\n", i
, ret
);
472 if (mwifiex_write_reg(adapter
,
473 CONFIGURATION_REG
, 0x04))
474 dev_err(adapter
->dev
, "write CFG reg failed\n");
477 if (i
> MAX_WRITE_IOMEM_RETRY
)
486 * This function gets the read port.
488 * If control port bit is set in MP read bitmap, the control port
489 * is returned, otherwise the current read port is returned and
490 * the value is increased (provided it does not reach the maximum
491 * limit, in which case it is reset to 1)
493 static int mwifiex_get_rd_port(struct mwifiex_adapter
*adapter
, u8
*port
)
495 struct sdio_mmc_card
*card
= adapter
->card
;
496 u16 rd_bitmap
= card
->mp_rd_bitmap
;
498 dev_dbg(adapter
->dev
, "data: mp_rd_bitmap=0x%04x\n", rd_bitmap
);
500 if (!(rd_bitmap
& (CTRL_PORT_MASK
| DATA_PORT_MASK
)))
503 if (card
->mp_rd_bitmap
& CTRL_PORT_MASK
) {
504 card
->mp_rd_bitmap
&= (u16
) (~CTRL_PORT_MASK
);
506 dev_dbg(adapter
->dev
, "data: port=%d mp_rd_bitmap=0x%04x\n",
507 *port
, card
->mp_rd_bitmap
);
509 if (card
->mp_rd_bitmap
& (1 << card
->curr_rd_port
)) {
510 card
->mp_rd_bitmap
&=
511 (u16
) (~(1 << card
->curr_rd_port
));
512 *port
= card
->curr_rd_port
;
514 if (++card
->curr_rd_port
== MAX_PORT
)
515 card
->curr_rd_port
= 1;
520 dev_dbg(adapter
->dev
,
521 "data: port=%d mp_rd_bitmap=0x%04x -> 0x%04x\n",
522 *port
, rd_bitmap
, card
->mp_rd_bitmap
);
528 * This function gets the write port for data.
530 * The current write port is returned if available and the value is
531 * increased (provided it does not reach the maximum limit, in which
532 * case it is reset to 1)
534 static int mwifiex_get_wr_port_data(struct mwifiex_adapter
*adapter
, u8
*port
)
536 struct sdio_mmc_card
*card
= adapter
->card
;
537 u16 wr_bitmap
= card
->mp_wr_bitmap
;
539 dev_dbg(adapter
->dev
, "data: mp_wr_bitmap=0x%04x\n", wr_bitmap
);
541 if (!(wr_bitmap
& card
->mp_data_port_mask
))
544 if (card
->mp_wr_bitmap
& (1 << card
->curr_wr_port
)) {
545 card
->mp_wr_bitmap
&= (u16
) (~(1 << card
->curr_wr_port
));
546 *port
= card
->curr_wr_port
;
547 if (++card
->curr_wr_port
== card
->mp_end_port
)
548 card
->curr_wr_port
= 1;
550 adapter
->data_sent
= true;
554 if (*port
== CTRL_PORT
) {
555 dev_err(adapter
->dev
, "invalid data port=%d cur port=%d"
556 " mp_wr_bitmap=0x%04x -> 0x%04x\n",
557 *port
, card
->curr_wr_port
, wr_bitmap
,
562 dev_dbg(adapter
->dev
, "data: port=%d mp_wr_bitmap=0x%04x -> 0x%04x\n",
563 *port
, wr_bitmap
, card
->mp_wr_bitmap
);
569 * This function polls the card status.
572 mwifiex_sdio_poll_card_status(struct mwifiex_adapter
*adapter
, u8 bits
)
577 for (tries
= 0; tries
< MAX_POLL_TRIES
; tries
++) {
578 if (mwifiex_read_reg(adapter
, CARD_STATUS_REG
, &cs
))
580 else if ((cs
& bits
) == bits
)
586 dev_err(adapter
->dev
, "poll card status failed, tries = %d\n",
592 * This function reads the firmware status.
595 mwifiex_sdio_read_fw_status(struct mwifiex_adapter
*adapter
, u16
*dat
)
599 if (mwifiex_read_reg(adapter
, CARD_FW_STATUS0_REG
, &fws0
))
602 if (mwifiex_read_reg(adapter
, CARD_FW_STATUS1_REG
, &fws1
))
605 *dat
= (u16
) ((fws1
<< 8) | fws0
);
611 * This function disables the host interrupt.
613 * The host interrupt mask is read, the disable bit is reset and
614 * written back to the card host interrupt mask register.
616 static int mwifiex_sdio_disable_host_int(struct mwifiex_adapter
*adapter
)
620 /* Read back the host_int_mask register */
621 if (mwifiex_read_reg(adapter
, HOST_INT_MASK_REG
, &host_int_mask
))
624 /* Update with the mask and write back to the register */
625 host_int_mask
&= ~HOST_INT_DISABLE
;
627 if (mwifiex_write_reg(adapter
, HOST_INT_MASK_REG
, host_int_mask
)) {
628 dev_err(adapter
->dev
, "disable host interrupt failed\n");
636 * This function enables the host interrupt.
638 * The host interrupt enable mask is written to the card
639 * host interrupt mask register.
641 static int mwifiex_sdio_enable_host_int(struct mwifiex_adapter
*adapter
)
643 /* Simply write the mask to the register */
644 if (mwifiex_write_reg(adapter
, HOST_INT_MASK_REG
, HOST_INT_ENABLE
)) {
645 dev_err(adapter
->dev
, "enable host interrupt failed\n");
652 * This function sends a data buffer to the card.
654 static int mwifiex_sdio_card_to_host(struct mwifiex_adapter
*adapter
,
655 u32
*type
, u8
*buffer
,
656 u32 npayload
, u32 ioport
)
662 dev_err(adapter
->dev
, "%s: buffer is NULL\n", __func__
);
666 ret
= mwifiex_read_data_sync(adapter
, buffer
, npayload
, ioport
, 1);
669 dev_err(adapter
->dev
, "%s: read iomem failed: %d\n", __func__
,
674 nb
= le16_to_cpu(*(__le16
*) (buffer
));
676 dev_err(adapter
->dev
, "%s: invalid packet, nb=%d, npayload=%d\n",
677 __func__
, nb
, npayload
);
681 *type
= le16_to_cpu(*(__le16
*) (buffer
+ 2));
687 * This function downloads the firmware to the card.
689 * Firmware is downloaded to the card in blocks. Every block download
690 * is tested for CRC errors, and retried a number of times before
693 static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter
*adapter
,
694 struct mwifiex_fw_image
*fw
)
697 u8
*firmware
= fw
->fw_buf
;
698 u32 firmware_len
= fw
->fw_len
;
703 u32 txlen
, tx_blocks
= 0, tries
;
707 dev_err(adapter
->dev
, "firmware image not found!"
708 " Terminating download\n");
712 dev_dbg(adapter
->dev
, "info: downloading FW image (%d bytes)\n",
715 /* Assume that the allocated buffer is 8-byte aligned */
716 fwbuf
= kzalloc(MWIFIEX_UPLD_SIZE
, GFP_KERNEL
);
718 dev_err(adapter
->dev
, "unable to alloc buffer for firmware."
719 " Terminating download\n");
723 /* Perform firmware data transfer */
725 /* The host polls for the DN_LD_CARD_RDY and CARD_IO_READY
727 ret
= mwifiex_sdio_poll_card_status(adapter
, CARD_IO_READY
|
730 dev_err(adapter
->dev
, "FW download with helper:"
731 " poll status timeout @ %d\n", offset
);
736 if (offset
>= firmware_len
)
739 for (tries
= 0; tries
< MAX_POLL_TRIES
; tries
++) {
740 ret
= mwifiex_read_reg(adapter
, HOST_F1_RD_BASE_0
,
743 dev_err(adapter
->dev
, "dev BASE0 register read"
744 " failed: base0=0x%04X(%d). Terminating "
745 "download\n", base0
, base0
);
748 ret
= mwifiex_read_reg(adapter
, HOST_F1_RD_BASE_1
,
751 dev_err(adapter
->dev
, "dev BASE1 register read"
752 " failed: base1=0x%04X(%d). Terminating "
753 "download\n", base1
, base1
);
756 len
= (u16
) (((base1
& 0xff) << 8) | (base0
& 0xff));
766 } else if (len
> MWIFIEX_UPLD_SIZE
) {
767 dev_err(adapter
->dev
, "FW download failed @ %d,"
768 " invalid length %d\n", offset
, len
);
777 if (i
> MAX_WRITE_IOMEM_RETRY
) {
778 dev_err(adapter
->dev
, "FW download failed @"
779 " %d, over max retry count\n", offset
);
783 dev_err(adapter
->dev
, "CRC indicated by the helper:"
784 " len = 0x%04X, txlen = %d\n", len
, txlen
);
786 /* Setting this to 0 to resend from same offset */
791 /* Set blocksize to transfer - checking for last
793 if (firmware_len
- offset
< txlen
)
794 txlen
= firmware_len
- offset
;
796 tx_blocks
= (txlen
+ MWIFIEX_SDIO_BLOCK_SIZE
-
797 1) / MWIFIEX_SDIO_BLOCK_SIZE
;
799 /* Copy payload to buffer */
800 memmove(fwbuf
, &firmware
[offset
], txlen
);
803 ret
= mwifiex_write_data_sync(adapter
, fwbuf
, tx_blocks
*
804 MWIFIEX_SDIO_BLOCK_SIZE
,
807 dev_err(adapter
->dev
, "FW download, write iomem (%d)"
808 " failed @ %d\n", i
, offset
);
809 if (mwifiex_write_reg(adapter
, CONFIGURATION_REG
, 0x04))
810 dev_err(adapter
->dev
, "write CFG reg failed\n");
819 dev_dbg(adapter
->dev
, "info: FW download over, size %d bytes\n",
829 * This function checks the firmware status in card.
831 * The winner interface is also determined by this function.
833 static int mwifiex_check_fw_status(struct mwifiex_adapter
*adapter
,
841 /* Wait for firmware initialization event */
842 for (tries
= 0; tries
< poll_num
; tries
++) {
843 ret
= mwifiex_sdio_read_fw_status(adapter
, &firmware_stat
);
846 if (firmware_stat
== FIRMWARE_READY_SDIO
) {
857 (adapter
, CARD_FW_STATUS0_REG
, &winner_status
))
869 * This function reads the interrupt status from card.
871 static void mwifiex_interrupt_status(struct mwifiex_adapter
*adapter
)
873 struct sdio_mmc_card
*card
= adapter
->card
;
877 if (mwifiex_read_data_sync(adapter
, card
->mp_regs
, MAX_MP_REGS
,
878 REG_PORT
| MWIFIEX_SDIO_BYTE_MODE_MASK
,
880 dev_err(adapter
->dev
, "read mp_regs failed\n");
884 sdio_ireg
= card
->mp_regs
[HOST_INTSTATUS_REG
];
887 * DN_LD_HOST_INT_STATUS and/or UP_LD_HOST_INT_STATUS
888 * Clear the interrupt status register
890 dev_dbg(adapter
->dev
, "int: sdio_ireg = %#x\n", sdio_ireg
);
891 spin_lock_irqsave(&adapter
->int_lock
, flags
);
892 adapter
->int_status
|= sdio_ireg
;
893 spin_unlock_irqrestore(&adapter
->int_lock
, flags
);
898 * SDIO interrupt handler.
900 * This function reads the interrupt status from firmware and assigns
901 * the main process in workqueue which will handle the interrupt.
904 mwifiex_sdio_interrupt(struct sdio_func
*func
)
906 struct mwifiex_adapter
*adapter
;
907 struct sdio_mmc_card
*card
;
909 card
= sdio_get_drvdata(func
);
910 if (!card
|| !card
->adapter
) {
911 pr_debug("int: func=%p card=%p adapter=%p\n",
912 func
, card
, card
? card
->adapter
: NULL
);
915 adapter
= card
->adapter
;
917 if (adapter
->surprise_removed
)
920 if (!adapter
->pps_uapsd_mode
&& adapter
->ps_state
== PS_STATE_SLEEP
)
921 adapter
->ps_state
= PS_STATE_AWAKE
;
923 mwifiex_interrupt_status(adapter
);
924 queue_work(adapter
->workqueue
, &adapter
->main_work
);
928 * This function decodes a received packet.
930 * Based on the type, the packet is treated as either a data, or
931 * a command response, or an event, and the correct handler
932 * function is invoked.
934 static int mwifiex_decode_rx_packet(struct mwifiex_adapter
*adapter
,
935 struct sk_buff
*skb
, u32 upld_typ
)
939 skb_pull(skb
, INTF_HEADER_LEN
);
942 case MWIFIEX_TYPE_DATA
:
943 dev_dbg(adapter
->dev
, "info: --- Rx: Data packet ---\n");
944 mwifiex_handle_rx_packet(adapter
, skb
);
947 case MWIFIEX_TYPE_CMD
:
948 dev_dbg(adapter
->dev
, "info: --- Rx: Cmd Response ---\n");
949 /* take care of curr_cmd = NULL case */
950 if (!adapter
->curr_cmd
) {
951 cmd_buf
= adapter
->upld_buf
;
953 if (adapter
->ps_state
== PS_STATE_SLEEP_CFM
)
954 mwifiex_process_sleep_confirm_resp(adapter
,
955 skb
->data
, skb
->len
);
957 memcpy(cmd_buf
, skb
->data
, min_t(u32
,
958 MWIFIEX_SIZE_OF_CMD_BUFFER
, skb
->len
));
960 dev_kfree_skb_any(skb
);
962 adapter
->cmd_resp_received
= true;
963 adapter
->curr_cmd
->resp_skb
= skb
;
967 case MWIFIEX_TYPE_EVENT
:
968 dev_dbg(adapter
->dev
, "info: --- Rx: Event ---\n");
969 adapter
->event_cause
= *(u32
*) skb
->data
;
971 skb_pull(skb
, MWIFIEX_EVENT_HEADER_LEN
);
973 if ((skb
->len
> 0) && (skb
->len
< MAX_EVENT_SIZE
))
974 memcpy(adapter
->event_body
, skb
->data
, skb
->len
);
976 /* event cause has been saved to adapter->event_cause */
977 adapter
->event_received
= true;
978 adapter
->event_skb
= skb
;
983 dev_err(adapter
->dev
, "unknown upload type %#x\n", upld_typ
);
984 dev_kfree_skb_any(skb
);
992 * This function transfers received packets from card to driver, performing
993 * aggregation if required.
995 * For data received on control port, or if aggregation is disabled, the
996 * received buffers are uploaded as separate packets. However, if aggregation
997 * is enabled and required, the buffers are copied onto an aggregation buffer,
998 * provided there is space left, processed and finally uploaded.
1000 static int mwifiex_sdio_card_to_host_mp_aggr(struct mwifiex_adapter
*adapter
,
1001 struct sk_buff
*skb
, u8 port
)
1003 struct sdio_mmc_card
*card
= adapter
->card
;
1004 s32 f_do_rx_aggr
= 0;
1005 s32 f_do_rx_cur
= 0;
1007 struct sk_buff
*skb_deaggr
;
1009 u32 pkt_len
, pkt_type
= 0;
1011 u32 rx_len
= skb
->len
;
1013 if (port
== CTRL_PORT
) {
1014 /* Read the command Resp without aggr */
1015 dev_dbg(adapter
->dev
, "info: %s: no aggregation for cmd "
1016 "response\n", __func__
);
1019 goto rx_curr_single
;
1022 if (!card
->mpa_rx
.enabled
) {
1023 dev_dbg(adapter
->dev
, "info: %s: rx aggregation disabled\n",
1027 goto rx_curr_single
;
1030 if (card
->mp_rd_bitmap
& (~((u16
) CTRL_PORT_MASK
))) {
1031 /* Some more data RX pending */
1032 dev_dbg(adapter
->dev
, "info: %s: not last packet\n", __func__
);
1034 if (MP_RX_AGGR_IN_PROGRESS(card
)) {
1035 if (MP_RX_AGGR_BUF_HAS_ROOM(card
, skb
->len
)) {
1038 /* No room in Aggr buf, do rx aggr now */
1043 /* Rx aggr not in progress */
1048 /* No more data RX pending */
1049 dev_dbg(adapter
->dev
, "info: %s: last packet\n", __func__
);
1051 if (MP_RX_AGGR_IN_PROGRESS(card
)) {
1053 if (MP_RX_AGGR_BUF_HAS_ROOM(card
, skb
->len
))
1056 /* No room in Aggr buf, do rx aggr now */
1064 dev_dbg(adapter
->dev
, "info: current packet aggregation\n");
1065 /* Curr pkt can be aggregated */
1066 MP_RX_AGGR_SETUP(card
, skb
, port
);
1068 if (MP_RX_AGGR_PKT_LIMIT_REACHED(card
) ||
1069 MP_RX_AGGR_PORT_LIMIT_REACHED(card
)) {
1070 dev_dbg(adapter
->dev
, "info: %s: aggregated packet "
1071 "limit reached\n", __func__
);
1072 /* No more pkts allowed in Aggr buf, rx it */
1078 /* do aggr RX now */
1079 dev_dbg(adapter
->dev
, "info: do_rx_aggr: num of packets: %d\n",
1080 card
->mpa_rx
.pkt_cnt
);
1082 if (mwifiex_read_data_sync(adapter
, card
->mpa_rx
.buf
,
1083 card
->mpa_rx
.buf_len
,
1084 (adapter
->ioport
| 0x1000 |
1085 (card
->mpa_rx
.ports
<< 4)) +
1086 card
->mpa_rx
.start_port
, 1))
1089 curr_ptr
= card
->mpa_rx
.buf
;
1091 for (pind
= 0; pind
< card
->mpa_rx
.pkt_cnt
; pind
++) {
1093 /* get curr PKT len & type */
1094 pkt_len
= *(u16
*) &curr_ptr
[0];
1095 pkt_type
= *(u16
*) &curr_ptr
[2];
1097 /* copy pkt to deaggr buf */
1098 skb_deaggr
= card
->mpa_rx
.skb_arr
[pind
];
1100 if ((pkt_type
== MWIFIEX_TYPE_DATA
) && (pkt_len
<=
1101 card
->mpa_rx
.len_arr
[pind
])) {
1103 memcpy(skb_deaggr
->data
, curr_ptr
, pkt_len
);
1105 skb_trim(skb_deaggr
, pkt_len
);
1107 /* Process de-aggr packet */
1108 mwifiex_decode_rx_packet(adapter
, skb_deaggr
,
1111 dev_err(adapter
->dev
, "wrong aggr pkt:"
1112 " type=%d len=%d max_len=%d\n",
1114 card
->mpa_rx
.len_arr
[pind
]);
1115 dev_kfree_skb_any(skb_deaggr
);
1117 curr_ptr
+= card
->mpa_rx
.len_arr
[pind
];
1119 MP_RX_AGGR_BUF_RESET(card
);
1124 dev_dbg(adapter
->dev
, "info: RX: port: %d, rx_len: %d\n",
1127 if (mwifiex_sdio_card_to_host(adapter
, &pkt_type
,
1128 skb
->data
, skb
->len
,
1129 adapter
->ioport
+ port
))
1132 mwifiex_decode_rx_packet(adapter
, skb
, pkt_type
);
1139 * This function checks the current interrupt status.
1141 * The following interrupts are checked and handled by this function -
1144 * - Packets received
1146 * Since the firmware does not generate download ready interrupt if the
1147 * port updated is command port only, command sent interrupt checking
1148 * should be done manually, and for every SDIO interrupt.
1150 * In case of Rx packets received, the packets are uploaded from card to
1151 * host and processed accordingly.
1153 static int mwifiex_process_int_status(struct mwifiex_adapter
*adapter
)
1155 struct sdio_mmc_card
*card
= adapter
->card
;
1158 struct sk_buff
*skb
;
1159 u8 port
= CTRL_PORT
;
1160 u32 len_reg_l
, len_reg_u
;
1163 unsigned long flags
;
1165 spin_lock_irqsave(&adapter
->int_lock
, flags
);
1166 sdio_ireg
= adapter
->int_status
;
1167 adapter
->int_status
= 0;
1168 spin_unlock_irqrestore(&adapter
->int_lock
, flags
);
1173 if (sdio_ireg
& DN_LD_HOST_INT_STATUS
) {
1174 card
->mp_wr_bitmap
= ((u16
) card
->mp_regs
[WR_BITMAP_U
]) << 8;
1175 card
->mp_wr_bitmap
|= (u16
) card
->mp_regs
[WR_BITMAP_L
];
1176 dev_dbg(adapter
->dev
, "int: DNLD: wr_bitmap=0x%04x\n",
1177 card
->mp_wr_bitmap
);
1178 if (adapter
->data_sent
&&
1179 (card
->mp_wr_bitmap
& card
->mp_data_port_mask
)) {
1180 dev_dbg(adapter
->dev
,
1181 "info: <--- Tx DONE Interrupt --->\n");
1182 adapter
->data_sent
= false;
1186 /* As firmware will not generate download ready interrupt if the port
1187 updated is command port only, cmd_sent should be done for any SDIO
1189 if (adapter
->cmd_sent
) {
1190 /* Check if firmware has attach buffer at command port and
1191 update just that in wr_bit_map. */
1192 card
->mp_wr_bitmap
|=
1193 (u16
) card
->mp_regs
[WR_BITMAP_L
] & CTRL_PORT_MASK
;
1194 if (card
->mp_wr_bitmap
& CTRL_PORT_MASK
)
1195 adapter
->cmd_sent
= false;
1198 dev_dbg(adapter
->dev
, "info: cmd_sent=%d data_sent=%d\n",
1199 adapter
->cmd_sent
, adapter
->data_sent
);
1200 if (sdio_ireg
& UP_LD_HOST_INT_STATUS
) {
1201 card
->mp_rd_bitmap
= ((u16
) card
->mp_regs
[RD_BITMAP_U
]) << 8;
1202 card
->mp_rd_bitmap
|= (u16
) card
->mp_regs
[RD_BITMAP_L
];
1203 dev_dbg(adapter
->dev
, "int: UPLD: rd_bitmap=0x%04x\n",
1204 card
->mp_rd_bitmap
);
1207 ret
= mwifiex_get_rd_port(adapter
, &port
);
1209 dev_dbg(adapter
->dev
,
1210 "info: no more rd_port available\n");
1213 len_reg_l
= RD_LEN_P0_L
+ (port
<< 1);
1214 len_reg_u
= RD_LEN_P0_U
+ (port
<< 1);
1215 rx_len
= ((u16
) card
->mp_regs
[len_reg_u
]) << 8;
1216 rx_len
|= (u16
) card
->mp_regs
[len_reg_l
];
1217 dev_dbg(adapter
->dev
, "info: RX: port=%d rx_len=%u\n",
1220 (rx_len
+ MWIFIEX_SDIO_BLOCK_SIZE
-
1221 1) / MWIFIEX_SDIO_BLOCK_SIZE
;
1222 if (rx_len
<= INTF_HEADER_LEN
1223 || (rx_blocks
* MWIFIEX_SDIO_BLOCK_SIZE
) >
1224 MWIFIEX_RX_DATA_BUF_SIZE
) {
1225 dev_err(adapter
->dev
, "invalid rx_len=%d\n",
1229 rx_len
= (u16
) (rx_blocks
* MWIFIEX_SDIO_BLOCK_SIZE
);
1231 skb
= dev_alloc_skb(rx_len
);
1234 dev_err(adapter
->dev
, "%s: failed to alloc skb",
1239 skb_put(skb
, rx_len
);
1241 dev_dbg(adapter
->dev
, "info: rx_len = %d skb->len = %d\n",
1244 if (mwifiex_sdio_card_to_host_mp_aggr(adapter
, skb
,
1248 dev_err(adapter
->dev
, "card_to_host_mpa failed:"
1249 " int status=%#x\n", sdio_ireg
);
1250 if (mwifiex_read_reg(adapter
,
1251 CONFIGURATION_REG
, &cr
))
1252 dev_err(adapter
->dev
,
1253 "read CFG reg failed\n");
1255 dev_dbg(adapter
->dev
,
1256 "info: CFG reg val = %d\n", cr
);
1257 if (mwifiex_write_reg(adapter
,
1260 dev_err(adapter
->dev
,
1261 "write CFG reg failed\n");
1263 dev_dbg(adapter
->dev
, "info: write success\n");
1264 if (mwifiex_read_reg(adapter
,
1265 CONFIGURATION_REG
, &cr
))
1266 dev_err(adapter
->dev
,
1267 "read CFG reg failed\n");
1269 dev_dbg(adapter
->dev
,
1270 "info: CFG reg val =%x\n", cr
);
1271 dev_kfree_skb_any(skb
);
1281 * This function aggregates transmission buffers in driver and downloads
1282 * the aggregated packet to card.
1284 * The individual packets are aggregated by copying into an aggregation
1285 * buffer and then downloaded to the card. Previous unsent packets in the
1286 * aggregation buffer are pre-copied first before new packets are added.
1287 * Aggregation is done till there is space left in the aggregation buffer,
1288 * or till new packets are available.
1290 * The function will only download the packet to the card when aggregation
1291 * stops, otherwise it will just aggregate the packet in aggregation buffer
1294 static int mwifiex_host_to_card_mp_aggr(struct mwifiex_adapter
*adapter
,
1295 u8
*payload
, u32 pkt_len
, u8 port
,
1298 struct sdio_mmc_card
*card
= adapter
->card
;
1300 s32 f_send_aggr_buf
= 0;
1301 s32 f_send_cur_buf
= 0;
1302 s32 f_precopy_cur_buf
= 0;
1303 s32 f_postcopy_cur_buf
= 0;
1305 if ((!card
->mpa_tx
.enabled
) || (port
== CTRL_PORT
)) {
1306 dev_dbg(adapter
->dev
, "info: %s: tx aggregation disabled\n",
1310 goto tx_curr_single
;
1314 /* More pkt in TX queue */
1315 dev_dbg(adapter
->dev
, "info: %s: more packets in queue.\n",
1318 if (MP_TX_AGGR_IN_PROGRESS(card
)) {
1319 if (!MP_TX_AGGR_PORT_LIMIT_REACHED(card
) &&
1320 MP_TX_AGGR_BUF_HAS_ROOM(card
, pkt_len
)) {
1321 f_precopy_cur_buf
= 1;
1323 if (!(card
->mp_wr_bitmap
&
1324 (1 << card
->curr_wr_port
))
1325 || !MP_TX_AGGR_BUF_HAS_ROOM(
1326 card
, pkt_len
+ next_pkt_len
))
1327 f_send_aggr_buf
= 1;
1329 /* No room in Aggr buf, send it */
1330 f_send_aggr_buf
= 1;
1332 if (MP_TX_AGGR_PORT_LIMIT_REACHED(card
) ||
1333 !(card
->mp_wr_bitmap
&
1334 (1 << card
->curr_wr_port
)))
1337 f_postcopy_cur_buf
= 1;
1340 if (MP_TX_AGGR_BUF_HAS_ROOM(card
, pkt_len
)
1341 && (card
->mp_wr_bitmap
& (1 << card
->curr_wr_port
)))
1342 f_precopy_cur_buf
= 1;
1347 /* Last pkt in TX queue */
1348 dev_dbg(adapter
->dev
, "info: %s: Last packet in Tx Queue.\n",
1351 if (MP_TX_AGGR_IN_PROGRESS(card
)) {
1352 /* some packs in Aggr buf already */
1353 f_send_aggr_buf
= 1;
1355 if (MP_TX_AGGR_BUF_HAS_ROOM(card
, pkt_len
))
1356 f_precopy_cur_buf
= 1;
1358 /* No room in Aggr buf, send it */
1365 if (f_precopy_cur_buf
) {
1366 dev_dbg(adapter
->dev
, "data: %s: precopy current buffer\n",
1368 MP_TX_AGGR_BUF_PUT(card
, payload
, pkt_len
, port
);
1370 if (MP_TX_AGGR_PKT_LIMIT_REACHED(card
) ||
1371 MP_TX_AGGR_PORT_LIMIT_REACHED(card
))
1372 /* No more pkts allowed in Aggr buf, send it */
1373 f_send_aggr_buf
= 1;
1376 if (f_send_aggr_buf
) {
1377 dev_dbg(adapter
->dev
, "data: %s: send aggr buffer: %d %d\n",
1379 card
->mpa_tx
.start_port
, card
->mpa_tx
.ports
);
1380 ret
= mwifiex_write_data_to_card(adapter
, card
->mpa_tx
.buf
,
1381 card
->mpa_tx
.buf_len
,
1382 (adapter
->ioport
| 0x1000 |
1383 (card
->mpa_tx
.ports
<< 4)) +
1384 card
->mpa_tx
.start_port
);
1386 MP_TX_AGGR_BUF_RESET(card
);
1390 if (f_send_cur_buf
) {
1391 dev_dbg(adapter
->dev
, "data: %s: send current buffer %d\n",
1393 ret
= mwifiex_write_data_to_card(adapter
, payload
, pkt_len
,
1394 adapter
->ioport
+ port
);
1397 if (f_postcopy_cur_buf
) {
1398 dev_dbg(adapter
->dev
, "data: %s: postcopy current buffer\n",
1400 MP_TX_AGGR_BUF_PUT(card
, payload
, pkt_len
, port
);
1407 * This function downloads data from driver to card.
1409 * Both commands and data packets are transferred to the card by this
1412 * This function adds the SDIO specific header to the front of the buffer
1413 * before transferring. The header contains the length of the packet and
1414 * the type. The firmware handles the packets based upon this set type.
1416 static int mwifiex_sdio_host_to_card(struct mwifiex_adapter
*adapter
,
1417 u8 type
, struct sk_buff
*skb
,
1418 struct mwifiex_tx_param
*tx_param
)
1420 struct sdio_mmc_card
*card
= adapter
->card
;
1424 u8 port
= CTRL_PORT
;
1425 u8
*payload
= (u8
*)skb
->data
;
1426 u32 pkt_len
= skb
->len
;
1428 /* Allocate buffer and copy payload */
1429 blk_size
= MWIFIEX_SDIO_BLOCK_SIZE
;
1430 buf_block_len
= (pkt_len
+ blk_size
- 1) / blk_size
;
1431 *(u16
*) &payload
[0] = (u16
) pkt_len
;
1432 *(u16
*) &payload
[2] = type
;
1435 * This is SDIO specific header
1437 * u16 type (MWIFIEX_TYPE_DATA = 0, MWIFIEX_TYPE_CMD = 1,
1438 * MWIFIEX_TYPE_EVENT = 3)
1440 if (type
== MWIFIEX_TYPE_DATA
) {
1441 ret
= mwifiex_get_wr_port_data(adapter
, &port
);
1443 dev_err(adapter
->dev
, "%s: no wr_port available\n",
1448 adapter
->cmd_sent
= true;
1449 /* Type must be MWIFIEX_TYPE_CMD */
1451 if (pkt_len
<= INTF_HEADER_LEN
||
1452 pkt_len
> MWIFIEX_UPLD_SIZE
)
1453 dev_err(adapter
->dev
, "%s: payload=%p, nb=%d\n",
1454 __func__
, payload
, pkt_len
);
1457 /* Transfer data to card */
1458 pkt_len
= buf_block_len
* blk_size
;
1461 ret
= mwifiex_host_to_card_mp_aggr(adapter
, payload
, pkt_len
,
1462 port
, tx_param
->next_pkt_len
);
1464 ret
= mwifiex_host_to_card_mp_aggr(adapter
, payload
, pkt_len
,
1468 if (type
== MWIFIEX_TYPE_CMD
)
1469 adapter
->cmd_sent
= false;
1470 if (type
== MWIFIEX_TYPE_DATA
)
1471 adapter
->data_sent
= false;
1473 if (type
== MWIFIEX_TYPE_DATA
) {
1474 if (!(card
->mp_wr_bitmap
& (1 << card
->curr_wr_port
)))
1475 adapter
->data_sent
= true;
1477 adapter
->data_sent
= false;
1485 * This function allocates the MPA Tx and Rx buffers.
1487 static int mwifiex_alloc_sdio_mpa_buffers(struct mwifiex_adapter
*adapter
,
1488 u32 mpa_tx_buf_size
, u32 mpa_rx_buf_size
)
1490 struct sdio_mmc_card
*card
= adapter
->card
;
1493 card
->mpa_tx
.buf
= kzalloc(mpa_tx_buf_size
, GFP_KERNEL
);
1494 if (!card
->mpa_tx
.buf
) {
1495 dev_err(adapter
->dev
, "could not alloc buffer for MP-A TX\n");
1500 card
->mpa_tx
.buf_size
= mpa_tx_buf_size
;
1502 card
->mpa_rx
.buf
= kzalloc(mpa_rx_buf_size
, GFP_KERNEL
);
1503 if (!card
->mpa_rx
.buf
) {
1504 dev_err(adapter
->dev
, "could not alloc buffer for MP-A RX\n");
1509 card
->mpa_rx
.buf_size
= mpa_rx_buf_size
;
1513 kfree(card
->mpa_tx
.buf
);
1514 kfree(card
->mpa_rx
.buf
);
1521 * This function unregisters the SDIO device.
1523 * The SDIO IRQ is released, the function is disabled and driver
1524 * data is set to null.
1527 mwifiex_unregister_dev(struct mwifiex_adapter
*adapter
)
1529 struct sdio_mmc_card
*card
= adapter
->card
;
1531 if (adapter
->card
) {
1532 /* Release the SDIO IRQ */
1533 sdio_claim_host(card
->func
);
1534 sdio_release_irq(card
->func
);
1535 sdio_disable_func(card
->func
);
1536 sdio_release_host(card
->func
);
1537 sdio_set_drvdata(card
->func
, NULL
);
1542 * This function registers the SDIO device.
1544 * SDIO IRQ is claimed, block size is set and driver data is initialized.
1546 static int mwifiex_register_dev(struct mwifiex_adapter
*adapter
)
1549 struct sdio_mmc_card
*card
= adapter
->card
;
1550 struct sdio_func
*func
= card
->func
;
1552 /* save adapter pointer in card */
1553 card
->adapter
= adapter
;
1555 sdio_claim_host(func
);
1557 /* Request the SDIO IRQ */
1558 ret
= sdio_claim_irq(func
, mwifiex_sdio_interrupt
);
1560 pr_err("claim irq failed: ret=%d\n", ret
);
1564 /* Set block size */
1565 ret
= sdio_set_block_size(card
->func
, MWIFIEX_SDIO_BLOCK_SIZE
);
1567 pr_err("cannot set SDIO block size\n");
1572 sdio_release_host(func
);
1573 sdio_set_drvdata(func
, card
);
1575 adapter
->dev
= &func
->dev
;
1576 strcpy(adapter
->fw_name
, SD8787_DEFAULT_FW_NAME
);
1581 sdio_release_irq(func
);
1583 sdio_disable_func(func
);
1584 sdio_release_host(func
);
1585 adapter
->card
= NULL
;
1591 * This function initializes the SDIO driver.
1593 * The following initializations steps are followed -
1594 * - Read the Host interrupt status register to acknowledge
1595 * the first interrupt got from bootloader
1596 * - Disable host interrupt mask register
1598 * - Initialize SDIO variables in card
1599 * - Allocate MP registers
1600 * - Allocate MPA Tx and Rx buffers
1602 static int mwifiex_init_sdio(struct mwifiex_adapter
*adapter
)
1604 struct sdio_mmc_card
*card
= adapter
->card
;
1609 * Read the HOST_INT_STATUS_REG for ACK the first interrupt got
1610 * from the bootloader. If we don't do this we get a interrupt
1611 * as soon as we register the irq.
1613 mwifiex_read_reg(adapter
, HOST_INTSTATUS_REG
, &sdio_ireg
);
1615 /* Disable host interrupt mask register for SDIO */
1616 mwifiex_sdio_disable_host_int(adapter
);
1618 /* Get SDIO ioport */
1619 mwifiex_init_sdio_ioport(adapter
);
1621 /* Initialize SDIO variables in card */
1622 card
->mp_rd_bitmap
= 0;
1623 card
->mp_wr_bitmap
= 0;
1624 card
->curr_rd_port
= 1;
1625 card
->curr_wr_port
= 1;
1627 card
->mp_data_port_mask
= DATA_PORT_MASK
;
1629 card
->mpa_tx
.buf_len
= 0;
1630 card
->mpa_tx
.pkt_cnt
= 0;
1631 card
->mpa_tx
.start_port
= 0;
1633 card
->mpa_tx
.enabled
= 0;
1634 card
->mpa_tx
.pkt_aggr_limit
= SDIO_MP_AGGR_DEF_PKT_LIMIT
;
1636 card
->mpa_rx
.buf_len
= 0;
1637 card
->mpa_rx
.pkt_cnt
= 0;
1638 card
->mpa_rx
.start_port
= 0;
1640 card
->mpa_rx
.enabled
= 0;
1641 card
->mpa_rx
.pkt_aggr_limit
= SDIO_MP_AGGR_DEF_PKT_LIMIT
;
1643 /* Allocate buffers for SDIO MP-A */
1644 card
->mp_regs
= kzalloc(MAX_MP_REGS
, GFP_KERNEL
);
1645 if (!card
->mp_regs
) {
1646 dev_err(adapter
->dev
, "failed to alloc mp_regs\n");
1650 ret
= mwifiex_alloc_sdio_mpa_buffers(adapter
,
1651 SDIO_MP_TX_AGGR_DEF_BUF_SIZE
,
1652 SDIO_MP_RX_AGGR_DEF_BUF_SIZE
);
1654 dev_err(adapter
->dev
, "failed to alloc sdio mp-a buffers\n");
1655 kfree(card
->mp_regs
);
1663 * This function resets the MPA Tx and Rx buffers.
1665 static void mwifiex_cleanup_mpa_buf(struct mwifiex_adapter
*adapter
)
1667 struct sdio_mmc_card
*card
= adapter
->card
;
1669 MP_TX_AGGR_BUF_RESET(card
);
1670 MP_RX_AGGR_BUF_RESET(card
);
1674 * This function cleans up the allocated card buffers.
1676 * The following are freed by this function -
1681 static void mwifiex_cleanup_sdio(struct mwifiex_adapter
*adapter
)
1683 struct sdio_mmc_card
*card
= adapter
->card
;
1685 kfree(card
->mp_regs
);
1686 kfree(card
->mpa_tx
.buf
);
1687 kfree(card
->mpa_rx
.buf
);
1691 * This function updates the MP end port in card.
1694 mwifiex_update_mp_end_port(struct mwifiex_adapter
*adapter
, u16 port
)
1696 struct sdio_mmc_card
*card
= adapter
->card
;
1699 card
->mp_end_port
= port
;
1701 card
->mp_data_port_mask
= DATA_PORT_MASK
;
1703 for (i
= 1; i
<= MAX_PORT
- card
->mp_end_port
; i
++)
1704 card
->mp_data_port_mask
&= ~(1 << (MAX_PORT
- i
));
1706 card
->curr_wr_port
= 1;
1708 dev_dbg(adapter
->dev
, "cmd: mp_end_port %d, data port mask 0x%x\n",
1709 port
, card
->mp_data_port_mask
);
1712 static struct mwifiex_if_ops sdio_ops
= {
1713 .init_if
= mwifiex_init_sdio
,
1714 .cleanup_if
= mwifiex_cleanup_sdio
,
1715 .check_fw_status
= mwifiex_check_fw_status
,
1716 .prog_fw
= mwifiex_prog_fw_w_helper
,
1717 .register_dev
= mwifiex_register_dev
,
1718 .unregister_dev
= mwifiex_unregister_dev
,
1719 .enable_int
= mwifiex_sdio_enable_host_int
,
1720 .process_int_status
= mwifiex_process_int_status
,
1721 .host_to_card
= mwifiex_sdio_host_to_card
,
1722 .wakeup
= mwifiex_pm_wakeup_card
,
1723 .wakeup_complete
= mwifiex_pm_wakeup_card_complete
,
1726 .update_mp_end_port
= mwifiex_update_mp_end_port
,
1727 .cleanup_mpa_buf
= mwifiex_cleanup_mpa_buf
,
1728 .cmdrsp_complete
= mwifiex_sdio_cmdrsp_complete
,
1729 .event_complete
= mwifiex_sdio_event_complete
,
1733 * This function initializes the SDIO driver.
1735 * This initiates the semaphore and registers the device with
1739 mwifiex_sdio_init_module(void)
1741 sema_init(&add_remove_card_sem
, 1);
1743 /* Clear the flag in case user removes the card. */
1746 return sdio_register_driver(&mwifiex_sdio
);
1750 * This function cleans up the SDIO driver.
1752 * The following major steps are followed for cleanup -
1753 * - Resume the device if its suspended
1754 * - Disconnect the device if connected
1755 * - Shutdown the firmware
1756 * - Unregister the device from SDIO bus.
1759 mwifiex_sdio_cleanup_module(void)
1761 if (!down_interruptible(&add_remove_card_sem
))
1762 up(&add_remove_card_sem
);
1764 /* Set the flag as user is removing this module. */
1767 sdio_unregister_driver(&mwifiex_sdio
);
1770 module_init(mwifiex_sdio_init_module
);
1771 module_exit(mwifiex_sdio_cleanup_module
);
1773 MODULE_AUTHOR("Marvell International Ltd.");
1774 MODULE_DESCRIPTION("Marvell WiFi-Ex SDIO Driver version " SDIO_VERSION
);
1775 MODULE_VERSION(SDIO_VERSION
);
1776 MODULE_LICENSE("GPL v2");
1777 MODULE_FIRMWARE("mrvl/sd8787_uapsta.bin");