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 static struct mwifiex_if_ops sdio_ops
;
36 static struct semaphore add_remove_card_sem
;
41 * This function probes an mwifiex device and registers it. It allocates
42 * the card structure, enables SDIO function number and initiates the
43 * device registration and initialization procedure by adding a logical
47 mwifiex_sdio_probe(struct sdio_func
*func
, const struct sdio_device_id
*id
)
50 struct sdio_mmc_card
*card
= NULL
;
52 pr_debug("info: vendor=0x%4.04X device=0x%4.04X class=%d function=%d\n",
53 func
->vendor
, func
->device
, func
->class, func
->num
);
55 card
= kzalloc(sizeof(struct sdio_mmc_card
), GFP_KERNEL
);
57 pr_err("%s: failed to alloc memory\n", __func__
);
63 func
->card
->quirks
|= MMC_QUIRK_BLKSZ_FOR_BYTE_MODE
;
65 sdio_claim_host(func
);
66 ret
= sdio_enable_func(func
);
67 sdio_release_host(func
);
70 pr_err("%s: failed to enable function\n", __func__
);
75 if (mwifiex_add_card(card
, &add_remove_card_sem
, &sdio_ops
)) {
76 pr_err("%s: add card failed\n", __func__
);
78 sdio_claim_host(func
);
79 ret
= sdio_disable_func(func
);
80 sdio_release_host(func
);
90 * This function removes the interface and frees up the card structure.
93 mwifiex_sdio_remove(struct sdio_func
*func
)
95 struct sdio_mmc_card
*card
;
97 pr_debug("info: SDIO func num=%d\n", func
->num
);
100 card
= sdio_get_drvdata(func
);
102 mwifiex_remove_card(card
->adapter
,
103 &add_remove_card_sem
);
112 * Kernel needs to suspend all functions separately. Therefore all
113 * registered functions must have drivers with suspend and resume
114 * methods. Failing that the kernel simply removes the whole card.
116 * If already not suspended, this function allocates and sends a host
117 * sleep activate request to the firmware and turns off the traffic.
119 static int mwifiex_sdio_suspend(struct device
*dev
)
121 struct sdio_func
*func
= dev_to_sdio_func(dev
);
122 struct sdio_mmc_card
*card
;
123 struct mwifiex_adapter
*adapter
;
124 mmc_pm_flag_t pm_flag
= 0;
130 pm_flag
= sdio_get_host_pm_caps(func
);
131 pr_debug("cmd: %s: suspend: PM flag = 0x%x\n",
132 sdio_func_id(func
), pm_flag
);
133 if (!(pm_flag
& MMC_PM_KEEP_POWER
)) {
134 pr_err("%s: cannot remain alive while host is"
135 " suspended\n", sdio_func_id(func
));
139 card
= sdio_get_drvdata(func
);
140 if (!card
|| !card
->adapter
) {
141 pr_err("suspend: invalid card or adapter\n");
145 pr_err("suspend: sdio_func is not specified\n");
149 adapter
= card
->adapter
;
151 /* Enable the Host Sleep */
152 hs_actived
= mwifiex_enable_hs(adapter
);
154 pr_debug("cmd: suspend with MMC_PM_KEEP_POWER\n");
155 ret
= sdio_set_host_pm_flags(func
, MMC_PM_KEEP_POWER
);
158 /* Indicate device suspended */
159 adapter
->is_suspended
= true;
161 for (i
= 0; i
< adapter
->priv_num
; i
++)
162 netif_carrier_off(adapter
->priv
[i
]->netdev
);
170 * Kernel needs to suspend all functions separately. Therefore all
171 * registered functions must have drivers with suspend and resume
172 * methods. Failing that the kernel simply removes the whole card.
174 * If already not resumed, this function turns on the traffic and
175 * sends a host sleep cancel request to the firmware.
177 static int mwifiex_sdio_resume(struct device
*dev
)
179 struct sdio_func
*func
= dev_to_sdio_func(dev
);
180 struct sdio_mmc_card
*card
;
181 struct mwifiex_adapter
*adapter
;
182 mmc_pm_flag_t pm_flag
= 0;
186 pm_flag
= sdio_get_host_pm_caps(func
);
187 card
= sdio_get_drvdata(func
);
188 if (!card
|| !card
->adapter
) {
189 pr_err("resume: invalid card or adapter\n");
193 pr_err("resume: sdio_func is not specified\n");
197 adapter
= card
->adapter
;
199 if (!adapter
->is_suspended
) {
200 dev_warn(adapter
->dev
, "device already resumed\n");
204 adapter
->is_suspended
= false;
206 for (i
= 0; i
< adapter
->priv_num
; i
++)
207 if (adapter
->priv
[i
]->media_connected
)
208 netif_carrier_on(adapter
->priv
[i
]->netdev
);
210 /* Disable Host Sleep */
211 mwifiex_cancel_hs(mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
),
217 /* Device ID for SD8787 */
218 #define SDIO_DEVICE_ID_MARVELL_8787 (0x9119)
221 static const struct sdio_device_id mwifiex_ids
[] = {
222 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8787
)},
226 MODULE_DEVICE_TABLE(sdio
, mwifiex_ids
);
228 static const struct dev_pm_ops mwifiex_sdio_pm_ops
= {
229 .suspend
= mwifiex_sdio_suspend
,
230 .resume
= mwifiex_sdio_resume
,
233 static struct sdio_driver mwifiex_sdio
= {
234 .name
= "mwifiex_sdio",
235 .id_table
= mwifiex_ids
,
236 .probe
= mwifiex_sdio_probe
,
237 .remove
= mwifiex_sdio_remove
,
239 .owner
= THIS_MODULE
,
240 .pm
= &mwifiex_sdio_pm_ops
,
245 * This function writes data into SDIO card register.
248 mwifiex_write_reg(struct mwifiex_adapter
*adapter
, u32 reg
, u32 data
)
250 struct sdio_mmc_card
*card
= adapter
->card
;
253 sdio_claim_host(card
->func
);
254 sdio_writeb(card
->func
, (u8
) data
, reg
, &ret
);
255 sdio_release_host(card
->func
);
261 * This function reads data from SDIO card register.
264 mwifiex_read_reg(struct mwifiex_adapter
*adapter
, u32 reg
, u32
*data
)
266 struct sdio_mmc_card
*card
= adapter
->card
;
270 sdio_claim_host(card
->func
);
271 val
= sdio_readb(card
->func
, reg
, &ret
);
272 sdio_release_host(card
->func
);
280 * This function writes multiple data into SDIO card memory.
282 * This does not work in suspended mode.
285 mwifiex_write_data_sync(struct mwifiex_adapter
*adapter
,
286 u8
*buffer
, u32 pkt_len
, u32 port
)
288 struct sdio_mmc_card
*card
= adapter
->card
;
291 (port
& MWIFIEX_SDIO_BYTE_MODE_MASK
) ? BYTE_MODE
: BLOCK_MODE
;
292 u32 blk_size
= (blk_mode
== BLOCK_MODE
) ? MWIFIEX_SDIO_BLOCK_SIZE
: 1;
295 BLOCK_MODE
) ? (pkt_len
/
296 MWIFIEX_SDIO_BLOCK_SIZE
) : pkt_len
;
297 u32 ioport
= (port
& MWIFIEX_SDIO_IO_PORT_MASK
);
299 if (adapter
->is_suspended
) {
300 dev_err(adapter
->dev
,
301 "%s: not allowed while suspended\n", __func__
);
305 sdio_claim_host(card
->func
);
307 if (!sdio_writesb(card
->func
, ioport
, buffer
, blk_cnt
* blk_size
))
310 sdio_release_host(card
->func
);
316 * This function reads multiple data from SDIO card memory.
318 static int mwifiex_read_data_sync(struct mwifiex_adapter
*adapter
, u8
*buffer
,
319 u32 len
, u32 port
, u8 claim
)
321 struct sdio_mmc_card
*card
= adapter
->card
;
324 (port
& MWIFIEX_SDIO_BYTE_MODE_MASK
) ? BYTE_MODE
: BLOCK_MODE
;
325 u32 blk_size
= (blk_mode
== BLOCK_MODE
) ? MWIFIEX_SDIO_BLOCK_SIZE
: 1;
328 BLOCK_MODE
) ? (len
/ MWIFIEX_SDIO_BLOCK_SIZE
) : len
;
329 u32 ioport
= (port
& MWIFIEX_SDIO_IO_PORT_MASK
);
332 sdio_claim_host(card
->func
);
334 if (!sdio_readsb(card
->func
, buffer
, ioport
, blk_cnt
* blk_size
))
338 sdio_release_host(card
->func
);
344 * This function wakes up the card.
346 * A host power up command is written to the card configuration
347 * register to wake up the card.
349 static int mwifiex_pm_wakeup_card(struct mwifiex_adapter
*adapter
)
351 dev_dbg(adapter
->dev
, "event: wakeup device...\n");
353 return mwifiex_write_reg(adapter
, CONFIGURATION_REG
, HOST_POWER_UP
);
357 * This function is called after the card has woken up.
359 * The card configuration register is reset.
361 static int mwifiex_pm_wakeup_card_complete(struct mwifiex_adapter
*adapter
)
363 dev_dbg(adapter
->dev
, "cmd: wakeup device completed\n");
365 return mwifiex_write_reg(adapter
, CONFIGURATION_REG
, 0);
369 * This function initializes the IO ports.
371 * The following operations are performed -
372 * - Read the IO ports (0, 1 and 2)
373 * - Set host interrupt Reset-To-Read to clear
374 * - Set auto re-enable interrupt
376 static int mwifiex_init_sdio_ioport(struct mwifiex_adapter
*adapter
)
382 /* Read the IO port */
383 if (!mwifiex_read_reg(adapter
, IO_PORT_0_REG
, ®
))
384 adapter
->ioport
|= (reg
& 0xff);
388 if (!mwifiex_read_reg(adapter
, IO_PORT_1_REG
, ®
))
389 adapter
->ioport
|= ((reg
& 0xff) << 8);
393 if (!mwifiex_read_reg(adapter
, IO_PORT_2_REG
, ®
))
394 adapter
->ioport
|= ((reg
& 0xff) << 16);
398 pr_debug("info: SDIO FUNC1 IO port: %#x\n", adapter
->ioport
);
400 /* Set Host interrupt reset to read to clear */
401 if (!mwifiex_read_reg(adapter
, HOST_INT_RSR_REG
, ®
))
402 mwifiex_write_reg(adapter
, HOST_INT_RSR_REG
,
403 reg
| SDIO_INT_MASK
);
407 /* Dnld/Upld ready set to auto reset */
408 if (!mwifiex_read_reg(adapter
, CARD_MISC_CFG_REG
, ®
))
409 mwifiex_write_reg(adapter
, CARD_MISC_CFG_REG
,
410 reg
| AUTO_RE_ENABLE_INT
);
418 * This function sends data to the card.
420 static int mwifiex_write_data_to_card(struct mwifiex_adapter
*adapter
,
421 u8
*payload
, u32 pkt_len
, u32 port
)
427 ret
= mwifiex_write_data_sync(adapter
, payload
, pkt_len
, port
);
430 dev_err(adapter
->dev
, "host_to_card, write iomem"
431 " (%d) failed: %d\n", i
, ret
);
432 if (mwifiex_write_reg(adapter
,
433 CONFIGURATION_REG
, 0x04))
434 dev_err(adapter
->dev
, "write CFG reg failed\n");
437 if (i
> MAX_WRITE_IOMEM_RETRY
)
446 * This function gets the read port.
448 * If control port bit is set in MP read bitmap, the control port
449 * is returned, otherwise the current read port is returned and
450 * the value is increased (provided it does not reach the maximum
451 * limit, in which case it is reset to 1)
453 static int mwifiex_get_rd_port(struct mwifiex_adapter
*adapter
, u8
*port
)
455 struct sdio_mmc_card
*card
= adapter
->card
;
456 u16 rd_bitmap
= card
->mp_rd_bitmap
;
458 dev_dbg(adapter
->dev
, "data: mp_rd_bitmap=0x%04x\n", rd_bitmap
);
460 if (!(rd_bitmap
& (CTRL_PORT_MASK
| DATA_PORT_MASK
)))
463 if (card
->mp_rd_bitmap
& CTRL_PORT_MASK
) {
464 card
->mp_rd_bitmap
&= (u16
) (~CTRL_PORT_MASK
);
466 dev_dbg(adapter
->dev
, "data: port=%d mp_rd_bitmap=0x%04x\n",
467 *port
, card
->mp_rd_bitmap
);
469 if (card
->mp_rd_bitmap
& (1 << card
->curr_rd_port
)) {
470 card
->mp_rd_bitmap
&=
471 (u16
) (~(1 << card
->curr_rd_port
));
472 *port
= card
->curr_rd_port
;
474 if (++card
->curr_rd_port
== MAX_PORT
)
475 card
->curr_rd_port
= 1;
480 dev_dbg(adapter
->dev
,
481 "data: port=%d mp_rd_bitmap=0x%04x -> 0x%04x\n",
482 *port
, rd_bitmap
, card
->mp_rd_bitmap
);
488 * This function gets the write port for data.
490 * The current write port is returned if available and the value is
491 * increased (provided it does not reach the maximum limit, in which
492 * case it is reset to 1)
494 static int mwifiex_get_wr_port_data(struct mwifiex_adapter
*adapter
, u8
*port
)
496 struct sdio_mmc_card
*card
= adapter
->card
;
497 u16 wr_bitmap
= card
->mp_wr_bitmap
;
499 dev_dbg(adapter
->dev
, "data: mp_wr_bitmap=0x%04x\n", wr_bitmap
);
501 if (!(wr_bitmap
& card
->mp_data_port_mask
))
504 if (card
->mp_wr_bitmap
& (1 << card
->curr_wr_port
)) {
505 card
->mp_wr_bitmap
&= (u16
) (~(1 << card
->curr_wr_port
));
506 *port
= card
->curr_wr_port
;
507 if (++card
->curr_wr_port
== card
->mp_end_port
)
508 card
->curr_wr_port
= 1;
510 adapter
->data_sent
= true;
514 if (*port
== CTRL_PORT
) {
515 dev_err(adapter
->dev
, "invalid data port=%d cur port=%d"
516 " mp_wr_bitmap=0x%04x -> 0x%04x\n",
517 *port
, card
->curr_wr_port
, wr_bitmap
,
522 dev_dbg(adapter
->dev
, "data: port=%d mp_wr_bitmap=0x%04x -> 0x%04x\n",
523 *port
, wr_bitmap
, card
->mp_wr_bitmap
);
529 * This function polls the card status.
532 mwifiex_sdio_poll_card_status(struct mwifiex_adapter
*adapter
, u8 bits
)
537 for (tries
= 0; tries
< MAX_POLL_TRIES
; tries
++) {
538 if (mwifiex_read_reg(adapter
, CARD_STATUS_REG
, &cs
))
540 else if ((cs
& bits
) == bits
)
546 dev_err(adapter
->dev
, "poll card status failed, tries = %d\n",
552 * This function reads the firmware status.
555 mwifiex_sdio_read_fw_status(struct mwifiex_adapter
*adapter
, u16
*dat
)
559 if (mwifiex_read_reg(adapter
, CARD_FW_STATUS0_REG
, &fws0
))
562 if (mwifiex_read_reg(adapter
, CARD_FW_STATUS1_REG
, &fws1
))
565 *dat
= (u16
) ((fws1
<< 8) | fws0
);
571 * This function disables the host interrupt.
573 * The host interrupt mask is read, the disable bit is reset and
574 * written back to the card host interrupt mask register.
576 static int mwifiex_sdio_disable_host_int(struct mwifiex_adapter
*adapter
)
580 /* Read back the host_int_mask register */
581 if (mwifiex_read_reg(adapter
, HOST_INT_MASK_REG
, &host_int_mask
))
584 /* Update with the mask and write back to the register */
585 host_int_mask
&= ~HOST_INT_DISABLE
;
587 if (mwifiex_write_reg(adapter
, HOST_INT_MASK_REG
, host_int_mask
)) {
588 dev_err(adapter
->dev
, "disable host interrupt failed\n");
596 * This function enables the host interrupt.
598 * The host interrupt enable mask is written to the card
599 * host interrupt mask register.
601 static int mwifiex_sdio_enable_host_int(struct mwifiex_adapter
*adapter
)
603 /* Simply write the mask to the register */
604 if (mwifiex_write_reg(adapter
, HOST_INT_MASK_REG
, HOST_INT_ENABLE
)) {
605 dev_err(adapter
->dev
, "enable host interrupt failed\n");
612 * This function sends a data buffer to the card.
614 static int mwifiex_sdio_card_to_host(struct mwifiex_adapter
*adapter
,
615 u32
*type
, u8
*buffer
,
616 u32 npayload
, u32 ioport
)
622 dev_err(adapter
->dev
, "%s: buffer is NULL\n", __func__
);
626 ret
= mwifiex_read_data_sync(adapter
, buffer
, npayload
, ioport
, 1);
629 dev_err(adapter
->dev
, "%s: read iomem failed: %d\n", __func__
,
634 nb
= le16_to_cpu(*(__le16
*) (buffer
));
636 dev_err(adapter
->dev
, "%s: invalid packet, nb=%d, npayload=%d\n",
637 __func__
, nb
, npayload
);
641 *type
= le16_to_cpu(*(__le16
*) (buffer
+ 2));
647 * This function downloads the firmware to the card.
649 * Firmware is downloaded to the card in blocks. Every block download
650 * is tested for CRC errors, and retried a number of times before
653 static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter
*adapter
,
654 struct mwifiex_fw_image
*fw
)
657 u8
*firmware
= fw
->fw_buf
;
658 u32 firmware_len
= fw
->fw_len
;
663 u32 txlen
, tx_blocks
= 0, tries
;
667 dev_err(adapter
->dev
, "firmware image not found!"
668 " Terminating download\n");
672 dev_dbg(adapter
->dev
, "info: downloading FW image (%d bytes)\n",
675 /* Assume that the allocated buffer is 8-byte aligned */
676 fwbuf
= kzalloc(MWIFIEX_UPLD_SIZE
, GFP_KERNEL
);
678 dev_err(adapter
->dev
, "unable to alloc buffer for firmware."
679 " Terminating download\n");
683 /* Perform firmware data transfer */
685 /* The host polls for the DN_LD_CARD_RDY and CARD_IO_READY
687 ret
= mwifiex_sdio_poll_card_status(adapter
, CARD_IO_READY
|
690 dev_err(adapter
->dev
, "FW download with helper:"
691 " poll status timeout @ %d\n", offset
);
696 if (offset
>= firmware_len
)
699 for (tries
= 0; tries
< MAX_POLL_TRIES
; tries
++) {
700 ret
= mwifiex_read_reg(adapter
, HOST_F1_RD_BASE_0
,
703 dev_err(adapter
->dev
, "dev BASE0 register read"
704 " failed: base0=0x%04X(%d). Terminating "
705 "download\n", base0
, base0
);
708 ret
= mwifiex_read_reg(adapter
, HOST_F1_RD_BASE_1
,
711 dev_err(adapter
->dev
, "dev BASE1 register read"
712 " failed: base1=0x%04X(%d). Terminating "
713 "download\n", base1
, base1
);
716 len
= (u16
) (((base1
& 0xff) << 8) | (base0
& 0xff));
726 } else if (len
> MWIFIEX_UPLD_SIZE
) {
727 dev_err(adapter
->dev
, "FW download failed @ %d,"
728 " invalid length %d\n", offset
, len
);
737 if (i
> MAX_WRITE_IOMEM_RETRY
) {
738 dev_err(adapter
->dev
, "FW download failed @"
739 " %d, over max retry count\n", offset
);
743 dev_err(adapter
->dev
, "CRC indicated by the helper:"
744 " len = 0x%04X, txlen = %d\n", len
, txlen
);
746 /* Setting this to 0 to resend from same offset */
751 /* Set blocksize to transfer - checking for last
753 if (firmware_len
- offset
< txlen
)
754 txlen
= firmware_len
- offset
;
756 tx_blocks
= (txlen
+ MWIFIEX_SDIO_BLOCK_SIZE
-
757 1) / MWIFIEX_SDIO_BLOCK_SIZE
;
759 /* Copy payload to buffer */
760 memmove(fwbuf
, &firmware
[offset
], txlen
);
763 ret
= mwifiex_write_data_sync(adapter
, fwbuf
, tx_blocks
*
764 MWIFIEX_SDIO_BLOCK_SIZE
,
767 dev_err(adapter
->dev
, "FW download, write iomem (%d)"
768 " failed @ %d\n", i
, offset
);
769 if (mwifiex_write_reg(adapter
, CONFIGURATION_REG
, 0x04))
770 dev_err(adapter
->dev
, "write CFG reg failed\n");
779 dev_dbg(adapter
->dev
, "info: FW download over, size %d bytes\n",
789 * This function checks the firmware status in card.
791 * The winner interface is also determined by this function.
793 static int mwifiex_check_fw_status(struct mwifiex_adapter
*adapter
,
794 u32 poll_num
, int *winner
)
801 /* Wait for firmware initialization event */
802 for (tries
= 0; tries
< poll_num
; tries
++) {
803 ret
= mwifiex_sdio_read_fw_status(adapter
, &firmware_stat
);
806 if (firmware_stat
== FIRMWARE_READY
) {
817 (adapter
, CARD_FW_STATUS0_REG
, &winner_status
))
829 * This function reads the interrupt status from card.
831 static void mwifiex_interrupt_status(struct mwifiex_adapter
*adapter
)
833 struct sdio_mmc_card
*card
= adapter
->card
;
837 if (mwifiex_read_data_sync(adapter
, card
->mp_regs
, MAX_MP_REGS
,
838 REG_PORT
| MWIFIEX_SDIO_BYTE_MODE_MASK
,
840 dev_err(adapter
->dev
, "read mp_regs failed\n");
844 sdio_ireg
= card
->mp_regs
[HOST_INTSTATUS_REG
];
847 * DN_LD_HOST_INT_STATUS and/or UP_LD_HOST_INT_STATUS
848 * Clear the interrupt status register
850 dev_dbg(adapter
->dev
, "int: sdio_ireg = %#x\n", sdio_ireg
);
851 spin_lock_irqsave(&adapter
->int_lock
, flags
);
852 adapter
->int_status
|= sdio_ireg
;
853 spin_unlock_irqrestore(&adapter
->int_lock
, flags
);
858 * SDIO interrupt handler.
860 * This function reads the interrupt status from firmware and assigns
861 * the main process in workqueue which will handle the interrupt.
864 mwifiex_sdio_interrupt(struct sdio_func
*func
)
866 struct mwifiex_adapter
*adapter
;
867 struct sdio_mmc_card
*card
;
869 card
= sdio_get_drvdata(func
);
870 if (!card
|| !card
->adapter
) {
871 pr_debug("int: func=%p card=%p adapter=%p\n",
872 func
, card
, card
? card
->adapter
: NULL
);
875 adapter
= card
->adapter
;
877 if (adapter
->surprise_removed
)
880 if (!adapter
->pps_uapsd_mode
&& adapter
->ps_state
== PS_STATE_SLEEP
)
881 adapter
->ps_state
= PS_STATE_AWAKE
;
883 mwifiex_interrupt_status(adapter
);
884 queue_work(adapter
->workqueue
, &adapter
->main_work
);
888 * This function decodes a received packet.
890 * Based on the type, the packet is treated as either a data, or
891 * a command response, or an event, and the correct handler
892 * function is invoked.
894 static int mwifiex_decode_rx_packet(struct mwifiex_adapter
*adapter
,
895 struct sk_buff
*skb
, u32 upld_typ
)
899 skb_pull(skb
, INTF_HEADER_LEN
);
902 case MWIFIEX_TYPE_DATA
:
903 dev_dbg(adapter
->dev
, "info: --- Rx: Data packet ---\n");
904 mwifiex_handle_rx_packet(adapter
, skb
);
907 case MWIFIEX_TYPE_CMD
:
908 dev_dbg(adapter
->dev
, "info: --- Rx: Cmd Response ---\n");
909 /* take care of curr_cmd = NULL case */
910 if (!adapter
->curr_cmd
) {
911 cmd_buf
= adapter
->upld_buf
;
913 if (adapter
->ps_state
== PS_STATE_SLEEP_CFM
)
914 mwifiex_process_sleep_confirm_resp(adapter
,
915 skb
->data
, skb
->len
);
917 memcpy(cmd_buf
, skb
->data
, min_t(u32
,
918 MWIFIEX_SIZE_OF_CMD_BUFFER
, skb
->len
));
920 dev_kfree_skb_any(skb
);
922 adapter
->cmd_resp_received
= true;
923 adapter
->curr_cmd
->resp_skb
= skb
;
927 case MWIFIEX_TYPE_EVENT
:
928 dev_dbg(adapter
->dev
, "info: --- Rx: Event ---\n");
929 adapter
->event_cause
= *(u32
*) skb
->data
;
931 skb_pull(skb
, MWIFIEX_EVENT_HEADER_LEN
);
933 if ((skb
->len
> 0) && (skb
->len
< MAX_EVENT_SIZE
))
934 memcpy(adapter
->event_body
, skb
->data
, skb
->len
);
936 /* event cause has been saved to adapter->event_cause */
937 adapter
->event_received
= true;
938 adapter
->event_skb
= skb
;
943 dev_err(adapter
->dev
, "unknown upload type %#x\n", upld_typ
);
944 dev_kfree_skb_any(skb
);
952 * This function transfers received packets from card to driver, performing
953 * aggregation if required.
955 * For data received on control port, or if aggregation is disabled, the
956 * received buffers are uploaded as separate packets. However, if aggregation
957 * is enabled and required, the buffers are copied onto an aggregation buffer,
958 * provided there is space left, processed and finally uploaded.
960 static int mwifiex_sdio_card_to_host_mp_aggr(struct mwifiex_adapter
*adapter
,
961 struct sk_buff
*skb
, u8 port
)
963 struct sdio_mmc_card
*card
= adapter
->card
;
964 s32 f_do_rx_aggr
= 0;
967 struct sk_buff
*skb_deaggr
;
969 u32 pkt_len
, pkt_type
= 0;
971 u32 rx_len
= skb
->len
;
973 if (port
== CTRL_PORT
) {
974 /* Read the command Resp without aggr */
975 dev_dbg(adapter
->dev
, "info: %s: no aggregation for cmd "
976 "response\n", __func__
);
982 if (!card
->mpa_rx
.enabled
) {
983 dev_dbg(adapter
->dev
, "info: %s: rx aggregation disabled\n",
990 if (card
->mp_rd_bitmap
& (~((u16
) CTRL_PORT_MASK
))) {
991 /* Some more data RX pending */
992 dev_dbg(adapter
->dev
, "info: %s: not last packet\n", __func__
);
994 if (MP_RX_AGGR_IN_PROGRESS(card
)) {
995 if (MP_RX_AGGR_BUF_HAS_ROOM(card
, skb
->len
)) {
998 /* No room in Aggr buf, do rx aggr now */
1003 /* Rx aggr not in progress */
1008 /* No more data RX pending */
1009 dev_dbg(adapter
->dev
, "info: %s: last packet\n", __func__
);
1011 if (MP_RX_AGGR_IN_PROGRESS(card
)) {
1013 if (MP_RX_AGGR_BUF_HAS_ROOM(card
, skb
->len
))
1016 /* No room in Aggr buf, do rx aggr now */
1024 dev_dbg(adapter
->dev
, "info: current packet aggregation\n");
1025 /* Curr pkt can be aggregated */
1026 MP_RX_AGGR_SETUP(card
, skb
, port
);
1028 if (MP_RX_AGGR_PKT_LIMIT_REACHED(card
) ||
1029 MP_RX_AGGR_PORT_LIMIT_REACHED(card
)) {
1030 dev_dbg(adapter
->dev
, "info: %s: aggregated packet "
1031 "limit reached\n", __func__
);
1032 /* No more pkts allowed in Aggr buf, rx it */
1038 /* do aggr RX now */
1039 dev_dbg(adapter
->dev
, "info: do_rx_aggr: num of packets: %d\n",
1040 card
->mpa_rx
.pkt_cnt
);
1042 if (mwifiex_read_data_sync(adapter
, card
->mpa_rx
.buf
,
1043 card
->mpa_rx
.buf_len
,
1044 (adapter
->ioport
| 0x1000 |
1045 (card
->mpa_rx
.ports
<< 4)) +
1046 card
->mpa_rx
.start_port
, 1))
1049 curr_ptr
= card
->mpa_rx
.buf
;
1051 for (pind
= 0; pind
< card
->mpa_rx
.pkt_cnt
; pind
++) {
1053 /* get curr PKT len & type */
1054 pkt_len
= *(u16
*) &curr_ptr
[0];
1055 pkt_type
= *(u16
*) &curr_ptr
[2];
1057 /* copy pkt to deaggr buf */
1058 skb_deaggr
= card
->mpa_rx
.skb_arr
[pind
];
1060 if ((pkt_type
== MWIFIEX_TYPE_DATA
) && (pkt_len
<=
1061 card
->mpa_rx
.len_arr
[pind
])) {
1063 memcpy(skb_deaggr
->data
, curr_ptr
, pkt_len
);
1065 skb_trim(skb_deaggr
, pkt_len
);
1067 /* Process de-aggr packet */
1068 mwifiex_decode_rx_packet(adapter
, skb_deaggr
,
1071 dev_err(adapter
->dev
, "wrong aggr pkt:"
1072 " type=%d len=%d max_len=%d\n",
1074 card
->mpa_rx
.len_arr
[pind
]);
1075 dev_kfree_skb_any(skb_deaggr
);
1077 curr_ptr
+= card
->mpa_rx
.len_arr
[pind
];
1079 MP_RX_AGGR_BUF_RESET(card
);
1084 dev_dbg(adapter
->dev
, "info: RX: port: %d, rx_len: %d\n",
1087 if (mwifiex_sdio_card_to_host(adapter
, &pkt_type
,
1088 skb
->data
, skb
->len
,
1089 adapter
->ioport
+ port
))
1092 mwifiex_decode_rx_packet(adapter
, skb
, pkt_type
);
1099 * This function checks the current interrupt status.
1101 * The following interrupts are checked and handled by this function -
1104 * - Packets received
1106 * Since the firmware does not generate download ready interrupt if the
1107 * port updated is command port only, command sent interrupt checking
1108 * should be done manually, and for every SDIO interrupt.
1110 * In case of Rx packets received, the packets are uploaded from card to
1111 * host and processed accordingly.
1113 static int mwifiex_process_int_status(struct mwifiex_adapter
*adapter
)
1115 struct sdio_mmc_card
*card
= adapter
->card
;
1118 struct sk_buff
*skb
;
1119 u8 port
= CTRL_PORT
;
1120 u32 len_reg_l
, len_reg_u
;
1123 unsigned long flags
;
1125 spin_lock_irqsave(&adapter
->int_lock
, flags
);
1126 sdio_ireg
= adapter
->int_status
;
1127 adapter
->int_status
= 0;
1128 spin_unlock_irqrestore(&adapter
->int_lock
, flags
);
1133 if (sdio_ireg
& DN_LD_HOST_INT_STATUS
) {
1134 card
->mp_wr_bitmap
= ((u16
) card
->mp_regs
[WR_BITMAP_U
]) << 8;
1135 card
->mp_wr_bitmap
|= (u16
) card
->mp_regs
[WR_BITMAP_L
];
1136 dev_dbg(adapter
->dev
, "int: DNLD: wr_bitmap=0x%04x\n",
1137 card
->mp_wr_bitmap
);
1138 if (adapter
->data_sent
&&
1139 (card
->mp_wr_bitmap
& card
->mp_data_port_mask
)) {
1140 dev_dbg(adapter
->dev
,
1141 "info: <--- Tx DONE Interrupt --->\n");
1142 adapter
->data_sent
= false;
1146 /* As firmware will not generate download ready interrupt if the port
1147 updated is command port only, cmd_sent should be done for any SDIO
1149 if (adapter
->cmd_sent
) {
1150 /* Check if firmware has attach buffer at command port and
1151 update just that in wr_bit_map. */
1152 card
->mp_wr_bitmap
|=
1153 (u16
) card
->mp_regs
[WR_BITMAP_L
] & CTRL_PORT_MASK
;
1154 if (card
->mp_wr_bitmap
& CTRL_PORT_MASK
)
1155 adapter
->cmd_sent
= false;
1158 dev_dbg(adapter
->dev
, "info: cmd_sent=%d data_sent=%d\n",
1159 adapter
->cmd_sent
, adapter
->data_sent
);
1160 if (sdio_ireg
& UP_LD_HOST_INT_STATUS
) {
1161 card
->mp_rd_bitmap
= ((u16
) card
->mp_regs
[RD_BITMAP_U
]) << 8;
1162 card
->mp_rd_bitmap
|= (u16
) card
->mp_regs
[RD_BITMAP_L
];
1163 dev_dbg(adapter
->dev
, "int: UPLD: rd_bitmap=0x%04x\n",
1164 card
->mp_rd_bitmap
);
1167 ret
= mwifiex_get_rd_port(adapter
, &port
);
1169 dev_dbg(adapter
->dev
,
1170 "info: no more rd_port available\n");
1173 len_reg_l
= RD_LEN_P0_L
+ (port
<< 1);
1174 len_reg_u
= RD_LEN_P0_U
+ (port
<< 1);
1175 rx_len
= ((u16
) card
->mp_regs
[len_reg_u
]) << 8;
1176 rx_len
|= (u16
) card
->mp_regs
[len_reg_l
];
1177 dev_dbg(adapter
->dev
, "info: RX: port=%d rx_len=%u\n",
1180 (rx_len
+ MWIFIEX_SDIO_BLOCK_SIZE
-
1181 1) / MWIFIEX_SDIO_BLOCK_SIZE
;
1182 if (rx_len
<= INTF_HEADER_LEN
1183 || (rx_blocks
* MWIFIEX_SDIO_BLOCK_SIZE
) >
1184 MWIFIEX_RX_DATA_BUF_SIZE
) {
1185 dev_err(adapter
->dev
, "invalid rx_len=%d\n",
1189 rx_len
= (u16
) (rx_blocks
* MWIFIEX_SDIO_BLOCK_SIZE
);
1191 skb
= dev_alloc_skb(rx_len
);
1194 dev_err(adapter
->dev
, "%s: failed to alloc skb",
1199 skb_put(skb
, rx_len
);
1201 dev_dbg(adapter
->dev
, "info: rx_len = %d skb->len = %d\n",
1204 if (mwifiex_sdio_card_to_host_mp_aggr(adapter
, skb
,
1208 dev_err(adapter
->dev
, "card_to_host_mpa failed:"
1209 " int status=%#x\n", sdio_ireg
);
1210 if (mwifiex_read_reg(adapter
,
1211 CONFIGURATION_REG
, &cr
))
1212 dev_err(adapter
->dev
,
1213 "read CFG reg failed\n");
1215 dev_dbg(adapter
->dev
,
1216 "info: CFG reg val = %d\n", cr
);
1217 if (mwifiex_write_reg(adapter
,
1220 dev_err(adapter
->dev
,
1221 "write CFG reg failed\n");
1223 dev_dbg(adapter
->dev
, "info: write success\n");
1224 if (mwifiex_read_reg(adapter
,
1225 CONFIGURATION_REG
, &cr
))
1226 dev_err(adapter
->dev
,
1227 "read CFG reg failed\n");
1229 dev_dbg(adapter
->dev
,
1230 "info: CFG reg val =%x\n", cr
);
1231 dev_kfree_skb_any(skb
);
1241 * This function aggregates transmission buffers in driver and downloads
1242 * the aggregated packet to card.
1244 * The individual packets are aggregated by copying into an aggregation
1245 * buffer and then downloaded to the card. Previous unsent packets in the
1246 * aggregation buffer are pre-copied first before new packets are added.
1247 * Aggregation is done till there is space left in the aggregation buffer,
1248 * or till new packets are available.
1250 * The function will only download the packet to the card when aggregation
1251 * stops, otherwise it will just aggregate the packet in aggregation buffer
1254 static int mwifiex_host_to_card_mp_aggr(struct mwifiex_adapter
*adapter
,
1255 u8
*payload
, u32 pkt_len
, u8 port
,
1258 struct sdio_mmc_card
*card
= adapter
->card
;
1260 s32 f_send_aggr_buf
= 0;
1261 s32 f_send_cur_buf
= 0;
1262 s32 f_precopy_cur_buf
= 0;
1263 s32 f_postcopy_cur_buf
= 0;
1265 if ((!card
->mpa_tx
.enabled
) || (port
== CTRL_PORT
)) {
1266 dev_dbg(adapter
->dev
, "info: %s: tx aggregation disabled\n",
1270 goto tx_curr_single
;
1274 /* More pkt in TX queue */
1275 dev_dbg(adapter
->dev
, "info: %s: more packets in queue.\n",
1278 if (MP_TX_AGGR_IN_PROGRESS(card
)) {
1279 if (!MP_TX_AGGR_PORT_LIMIT_REACHED(card
) &&
1280 MP_TX_AGGR_BUF_HAS_ROOM(card
, pkt_len
)) {
1281 f_precopy_cur_buf
= 1;
1283 if (!(card
->mp_wr_bitmap
&
1284 (1 << card
->curr_wr_port
))
1285 || !MP_TX_AGGR_BUF_HAS_ROOM(
1286 card
, next_pkt_len
))
1287 f_send_aggr_buf
= 1;
1289 /* No room in Aggr buf, send it */
1290 f_send_aggr_buf
= 1;
1292 if (MP_TX_AGGR_PORT_LIMIT_REACHED(card
) ||
1293 !(card
->mp_wr_bitmap
&
1294 (1 << card
->curr_wr_port
)))
1297 f_postcopy_cur_buf
= 1;
1300 if (MP_TX_AGGR_BUF_HAS_ROOM(card
, pkt_len
)
1301 && (card
->mp_wr_bitmap
& (1 << card
->curr_wr_port
)))
1302 f_precopy_cur_buf
= 1;
1307 /* Last pkt in TX queue */
1308 dev_dbg(adapter
->dev
, "info: %s: Last packet in Tx Queue.\n",
1311 if (MP_TX_AGGR_IN_PROGRESS(card
)) {
1312 /* some packs in Aggr buf already */
1313 f_send_aggr_buf
= 1;
1315 if (MP_TX_AGGR_BUF_HAS_ROOM(card
, pkt_len
))
1316 f_precopy_cur_buf
= 1;
1318 /* No room in Aggr buf, send it */
1325 if (f_precopy_cur_buf
) {
1326 dev_dbg(adapter
->dev
, "data: %s: precopy current buffer\n",
1328 MP_TX_AGGR_BUF_PUT(card
, payload
, pkt_len
, port
);
1330 if (MP_TX_AGGR_PKT_LIMIT_REACHED(card
) ||
1331 MP_TX_AGGR_PORT_LIMIT_REACHED(card
))
1332 /* No more pkts allowed in Aggr buf, send it */
1333 f_send_aggr_buf
= 1;
1336 if (f_send_aggr_buf
) {
1337 dev_dbg(adapter
->dev
, "data: %s: send aggr buffer: %d %d\n",
1339 card
->mpa_tx
.start_port
, card
->mpa_tx
.ports
);
1340 ret
= mwifiex_write_data_to_card(adapter
, card
->mpa_tx
.buf
,
1341 card
->mpa_tx
.buf_len
,
1342 (adapter
->ioport
| 0x1000 |
1343 (card
->mpa_tx
.ports
<< 4)) +
1344 card
->mpa_tx
.start_port
);
1346 MP_TX_AGGR_BUF_RESET(card
);
1350 if (f_send_cur_buf
) {
1351 dev_dbg(adapter
->dev
, "data: %s: send current buffer %d\n",
1353 ret
= mwifiex_write_data_to_card(adapter
, payload
, pkt_len
,
1354 adapter
->ioport
+ port
);
1357 if (f_postcopy_cur_buf
) {
1358 dev_dbg(adapter
->dev
, "data: %s: postcopy current buffer\n",
1360 MP_TX_AGGR_BUF_PUT(card
, payload
, pkt_len
, port
);
1367 * This function downloads data from driver to card.
1369 * Both commands and data packets are transferred to the card by this
1372 * This function adds the SDIO specific header to the front of the buffer
1373 * before transferring. The header contains the length of the packet and
1374 * the type. The firmware handles the packets based upon this set type.
1376 static int mwifiex_sdio_host_to_card(struct mwifiex_adapter
*adapter
,
1377 u8 type
, u8
*payload
, u32 pkt_len
,
1378 struct mwifiex_tx_param
*tx_param
)
1380 struct sdio_mmc_card
*card
= adapter
->card
;
1384 u8 port
= CTRL_PORT
;
1386 /* Allocate buffer and copy payload */
1387 blk_size
= MWIFIEX_SDIO_BLOCK_SIZE
;
1388 buf_block_len
= (pkt_len
+ blk_size
- 1) / blk_size
;
1389 *(u16
*) &payload
[0] = (u16
) pkt_len
;
1390 *(u16
*) &payload
[2] = type
;
1393 * This is SDIO specific header
1395 * u16 type (MWIFIEX_TYPE_DATA = 0, MWIFIEX_TYPE_CMD = 1,
1396 * MWIFIEX_TYPE_EVENT = 3)
1398 if (type
== MWIFIEX_TYPE_DATA
) {
1399 ret
= mwifiex_get_wr_port_data(adapter
, &port
);
1401 dev_err(adapter
->dev
, "%s: no wr_port available\n",
1406 adapter
->cmd_sent
= true;
1407 /* Type must be MWIFIEX_TYPE_CMD */
1409 if (pkt_len
<= INTF_HEADER_LEN
||
1410 pkt_len
> MWIFIEX_UPLD_SIZE
)
1411 dev_err(adapter
->dev
, "%s: payload=%p, nb=%d\n",
1412 __func__
, payload
, pkt_len
);
1415 /* Transfer data to card */
1416 pkt_len
= buf_block_len
* blk_size
;
1419 ret
= mwifiex_host_to_card_mp_aggr(adapter
, payload
, pkt_len
,
1420 port
, tx_param
->next_pkt_len
);
1422 ret
= mwifiex_host_to_card_mp_aggr(adapter
, payload
, pkt_len
,
1426 if (type
== MWIFIEX_TYPE_CMD
)
1427 adapter
->cmd_sent
= false;
1428 if (type
== MWIFIEX_TYPE_DATA
)
1429 adapter
->data_sent
= false;
1431 if (type
== MWIFIEX_TYPE_DATA
) {
1432 if (!(card
->mp_wr_bitmap
& (1 << card
->curr_wr_port
)))
1433 adapter
->data_sent
= true;
1435 adapter
->data_sent
= false;
1443 * This function allocates the MPA Tx and Rx buffers.
1445 static int mwifiex_alloc_sdio_mpa_buffers(struct mwifiex_adapter
*adapter
,
1446 u32 mpa_tx_buf_size
, u32 mpa_rx_buf_size
)
1448 struct sdio_mmc_card
*card
= adapter
->card
;
1451 card
->mpa_tx
.buf
= kzalloc(mpa_tx_buf_size
, GFP_KERNEL
);
1452 if (!card
->mpa_tx
.buf
) {
1453 dev_err(adapter
->dev
, "could not alloc buffer for MP-A TX\n");
1458 card
->mpa_tx
.buf_size
= mpa_tx_buf_size
;
1460 card
->mpa_rx
.buf
= kzalloc(mpa_rx_buf_size
, GFP_KERNEL
);
1461 if (!card
->mpa_rx
.buf
) {
1462 dev_err(adapter
->dev
, "could not alloc buffer for MP-A RX\n");
1467 card
->mpa_rx
.buf_size
= mpa_rx_buf_size
;
1471 kfree(card
->mpa_tx
.buf
);
1472 kfree(card
->mpa_rx
.buf
);
1479 * This function unregisters the SDIO device.
1481 * The SDIO IRQ is released, the function is disabled and driver
1482 * data is set to null.
1485 mwifiex_unregister_dev(struct mwifiex_adapter
*adapter
)
1487 struct sdio_mmc_card
*card
= adapter
->card
;
1489 if (adapter
->card
) {
1490 /* Release the SDIO IRQ */
1491 sdio_claim_host(card
->func
);
1492 sdio_release_irq(card
->func
);
1493 sdio_disable_func(card
->func
);
1494 sdio_release_host(card
->func
);
1495 sdio_set_drvdata(card
->func
, NULL
);
1500 * This function registers the SDIO device.
1502 * SDIO IRQ is claimed, block size is set and driver data is initialized.
1504 static int mwifiex_register_dev(struct mwifiex_adapter
*adapter
)
1507 struct sdio_mmc_card
*card
= adapter
->card
;
1508 struct sdio_func
*func
= card
->func
;
1510 /* save adapter pointer in card */
1511 card
->adapter
= adapter
;
1513 sdio_claim_host(func
);
1515 /* Request the SDIO IRQ */
1516 ret
= sdio_claim_irq(func
, mwifiex_sdio_interrupt
);
1518 pr_err("claim irq failed: ret=%d\n", ret
);
1522 /* Set block size */
1523 ret
= sdio_set_block_size(card
->func
, MWIFIEX_SDIO_BLOCK_SIZE
);
1525 pr_err("cannot set SDIO block size\n");
1530 sdio_release_host(func
);
1531 sdio_set_drvdata(func
, card
);
1533 adapter
->dev
= &func
->dev
;
1538 sdio_release_irq(func
);
1540 sdio_disable_func(func
);
1541 sdio_release_host(func
);
1542 adapter
->card
= NULL
;
1548 * This function initializes the SDIO driver.
1550 * The following initializations steps are followed -
1551 * - Read the Host interrupt status register to acknowledge
1552 * the first interrupt got from bootloader
1553 * - Disable host interrupt mask register
1556 * - Initialize SDIO variables in card
1557 * - Allocate MP registers
1558 * - Allocate MPA Tx and Rx buffers
1560 static int mwifiex_init_sdio(struct mwifiex_adapter
*adapter
)
1562 struct sdio_mmc_card
*card
= adapter
->card
;
1567 * Read the HOST_INT_STATUS_REG for ACK the first interrupt got
1568 * from the bootloader. If we don't do this we get a interrupt
1569 * as soon as we register the irq.
1571 mwifiex_read_reg(adapter
, HOST_INTSTATUS_REG
, &sdio_ireg
);
1573 /* Disable host interrupt mask register for SDIO */
1574 mwifiex_sdio_disable_host_int(adapter
);
1576 /* Get SDIO ioport */
1577 mwifiex_init_sdio_ioport(adapter
);
1579 /* Get revision ID */
1580 #define REV_ID_REG 0x5c
1581 mwifiex_read_reg(adapter
, REV_ID_REG
, &adapter
->revision_id
);
1583 /* Initialize SDIO variables in card */
1584 card
->mp_rd_bitmap
= 0;
1585 card
->mp_wr_bitmap
= 0;
1586 card
->curr_rd_port
= 1;
1587 card
->curr_wr_port
= 1;
1589 card
->mp_data_port_mask
= DATA_PORT_MASK
;
1591 card
->mpa_tx
.buf_len
= 0;
1592 card
->mpa_tx
.pkt_cnt
= 0;
1593 card
->mpa_tx
.start_port
= 0;
1595 card
->mpa_tx
.enabled
= 0;
1596 card
->mpa_tx
.pkt_aggr_limit
= SDIO_MP_AGGR_DEF_PKT_LIMIT
;
1598 card
->mpa_rx
.buf_len
= 0;
1599 card
->mpa_rx
.pkt_cnt
= 0;
1600 card
->mpa_rx
.start_port
= 0;
1602 card
->mpa_rx
.enabled
= 0;
1603 card
->mpa_rx
.pkt_aggr_limit
= SDIO_MP_AGGR_DEF_PKT_LIMIT
;
1605 /* Allocate buffers for SDIO MP-A */
1606 card
->mp_regs
= kzalloc(MAX_MP_REGS
, GFP_KERNEL
);
1607 if (!card
->mp_regs
) {
1608 dev_err(adapter
->dev
, "failed to alloc mp_regs\n");
1612 ret
= mwifiex_alloc_sdio_mpa_buffers(adapter
,
1613 SDIO_MP_TX_AGGR_DEF_BUF_SIZE
,
1614 SDIO_MP_RX_AGGR_DEF_BUF_SIZE
);
1616 dev_err(adapter
->dev
, "failed to alloc sdio mp-a buffers\n");
1617 kfree(card
->mp_regs
);
1625 * This function resets the MPA Tx and Rx buffers.
1627 static void mwifiex_cleanup_mpa_buf(struct mwifiex_adapter
*adapter
)
1629 struct sdio_mmc_card
*card
= adapter
->card
;
1631 MP_TX_AGGR_BUF_RESET(card
);
1632 MP_RX_AGGR_BUF_RESET(card
);
1636 * This function cleans up the allocated card buffers.
1638 * The following are freed by this function -
1643 static void mwifiex_cleanup_sdio(struct mwifiex_adapter
*adapter
)
1645 struct sdio_mmc_card
*card
= adapter
->card
;
1647 kfree(card
->mp_regs
);
1648 kfree(card
->mpa_tx
.buf
);
1649 kfree(card
->mpa_rx
.buf
);
1653 * This function updates the MP end port in card.
1656 mwifiex_update_mp_end_port(struct mwifiex_adapter
*adapter
, u16 port
)
1658 struct sdio_mmc_card
*card
= adapter
->card
;
1661 card
->mp_end_port
= port
;
1663 card
->mp_data_port_mask
= DATA_PORT_MASK
;
1665 for (i
= 1; i
<= MAX_PORT
- card
->mp_end_port
; i
++)
1666 card
->mp_data_port_mask
&= ~(1 << (MAX_PORT
- i
));
1668 card
->curr_wr_port
= 1;
1670 dev_dbg(adapter
->dev
, "cmd: mp_end_port %d, data port mask 0x%x\n",
1671 port
, card
->mp_data_port_mask
);
1674 static struct mwifiex_if_ops sdio_ops
= {
1675 .init_if
= mwifiex_init_sdio
,
1676 .cleanup_if
= mwifiex_cleanup_sdio
,
1677 .check_fw_status
= mwifiex_check_fw_status
,
1678 .prog_fw
= mwifiex_prog_fw_w_helper
,
1679 .register_dev
= mwifiex_register_dev
,
1680 .unregister_dev
= mwifiex_unregister_dev
,
1681 .enable_int
= mwifiex_sdio_enable_host_int
,
1682 .process_int_status
= mwifiex_process_int_status
,
1683 .host_to_card
= mwifiex_sdio_host_to_card
,
1684 .wakeup
= mwifiex_pm_wakeup_card
,
1685 .wakeup_complete
= mwifiex_pm_wakeup_card_complete
,
1688 .update_mp_end_port
= mwifiex_update_mp_end_port
,
1689 .cleanup_mpa_buf
= mwifiex_cleanup_mpa_buf
,
1693 * This function initializes the SDIO driver.
1695 * This initiates the semaphore and registers the device with
1699 mwifiex_sdio_init_module(void)
1701 sema_init(&add_remove_card_sem
, 1);
1703 return sdio_register_driver(&mwifiex_sdio
);
1707 * This function cleans up the SDIO driver.
1709 * The following major steps are followed for cleanup -
1710 * - Resume the device if its suspended
1711 * - Disconnect the device if connected
1712 * - Shutdown the firmware
1713 * - Unregister the device from SDIO bus.
1716 mwifiex_sdio_cleanup_module(void)
1718 struct mwifiex_adapter
*adapter
= g_adapter
;
1721 if (down_interruptible(&add_remove_card_sem
))
1724 if (!adapter
|| !adapter
->priv_num
)
1727 if (adapter
->is_suspended
)
1728 mwifiex_sdio_resume(adapter
->dev
);
1730 for (i
= 0; i
< adapter
->priv_num
; i
++)
1731 if ((GET_BSS_ROLE(adapter
->priv
[i
]) == MWIFIEX_BSS_ROLE_STA
) &&
1732 adapter
->priv
[i
]->media_connected
)
1733 mwifiex_deauthenticate(adapter
->priv
[i
], NULL
);
1735 if (!adapter
->surprise_removed
)
1736 mwifiex_init_shutdown_fw(mwifiex_get_priv(adapter
,
1737 MWIFIEX_BSS_ROLE_ANY
),
1738 MWIFIEX_FUNC_SHUTDOWN
);
1741 up(&add_remove_card_sem
);
1744 sdio_unregister_driver(&mwifiex_sdio
);
1747 module_init(mwifiex_sdio_init_module
);
1748 module_exit(mwifiex_sdio_cleanup_module
);
1750 MODULE_AUTHOR("Marvell International Ltd.");
1751 MODULE_DESCRIPTION("Marvell WiFi-Ex SDIO Driver version " SDIO_VERSION
);
1752 MODULE_VERSION(SDIO_VERSION
);
1753 MODULE_LICENSE("GPL v2");
1754 MODULE_FIRMWARE("sd8787.bin");