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 SD8787 */
257 #define SDIO_DEVICE_ID_MARVELL_8787 (0x9119)
258 /* Device ID for SD8797 */
259 #define SDIO_DEVICE_ID_MARVELL_8797 (0x9129)
262 static const struct sdio_device_id mwifiex_ids
[] = {
263 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8787
)},
264 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8797
)},
268 MODULE_DEVICE_TABLE(sdio
, mwifiex_ids
);
270 static const struct dev_pm_ops mwifiex_sdio_pm_ops
= {
271 .suspend
= mwifiex_sdio_suspend
,
272 .resume
= mwifiex_sdio_resume
,
275 static struct sdio_driver mwifiex_sdio
= {
276 .name
= "mwifiex_sdio",
277 .id_table
= mwifiex_ids
,
278 .probe
= mwifiex_sdio_probe
,
279 .remove
= mwifiex_sdio_remove
,
281 .owner
= THIS_MODULE
,
282 .pm
= &mwifiex_sdio_pm_ops
,
287 * This function writes data into SDIO card register.
290 mwifiex_write_reg(struct mwifiex_adapter
*adapter
, u32 reg
, u32 data
)
292 struct sdio_mmc_card
*card
= adapter
->card
;
295 sdio_claim_host(card
->func
);
296 sdio_writeb(card
->func
, (u8
) data
, reg
, &ret
);
297 sdio_release_host(card
->func
);
303 * This function reads data from SDIO card register.
306 mwifiex_read_reg(struct mwifiex_adapter
*adapter
, u32 reg
, u32
*data
)
308 struct sdio_mmc_card
*card
= adapter
->card
;
312 sdio_claim_host(card
->func
);
313 val
= sdio_readb(card
->func
, reg
, &ret
);
314 sdio_release_host(card
->func
);
322 * This function writes multiple data into SDIO card memory.
324 * This does not work in suspended mode.
327 mwifiex_write_data_sync(struct mwifiex_adapter
*adapter
,
328 u8
*buffer
, u32 pkt_len
, u32 port
)
330 struct sdio_mmc_card
*card
= adapter
->card
;
333 (port
& MWIFIEX_SDIO_BYTE_MODE_MASK
) ? BYTE_MODE
: BLOCK_MODE
;
334 u32 blk_size
= (blk_mode
== BLOCK_MODE
) ? MWIFIEX_SDIO_BLOCK_SIZE
: 1;
337 BLOCK_MODE
) ? (pkt_len
/
338 MWIFIEX_SDIO_BLOCK_SIZE
) : pkt_len
;
339 u32 ioport
= (port
& MWIFIEX_SDIO_IO_PORT_MASK
);
341 if (adapter
->is_suspended
) {
342 dev_err(adapter
->dev
,
343 "%s: not allowed while suspended\n", __func__
);
347 sdio_claim_host(card
->func
);
349 if (!sdio_writesb(card
->func
, ioport
, buffer
, blk_cnt
* blk_size
))
352 sdio_release_host(card
->func
);
358 * This function reads multiple data from SDIO card memory.
360 static int mwifiex_read_data_sync(struct mwifiex_adapter
*adapter
, u8
*buffer
,
361 u32 len
, u32 port
, u8 claim
)
363 struct sdio_mmc_card
*card
= adapter
->card
;
365 u8 blk_mode
= (port
& MWIFIEX_SDIO_BYTE_MODE_MASK
) ? BYTE_MODE
367 u32 blk_size
= (blk_mode
== BLOCK_MODE
) ? MWIFIEX_SDIO_BLOCK_SIZE
: 1;
368 u32 blk_cnt
= (blk_mode
== BLOCK_MODE
) ? (len
/ MWIFIEX_SDIO_BLOCK_SIZE
)
370 u32 ioport
= (port
& MWIFIEX_SDIO_IO_PORT_MASK
);
373 sdio_claim_host(card
->func
);
375 if (!sdio_readsb(card
->func
, buffer
, ioport
, blk_cnt
* blk_size
))
379 sdio_release_host(card
->func
);
385 * This function wakes up the card.
387 * A host power up command is written to the card configuration
388 * register to wake up the card.
390 static int mwifiex_pm_wakeup_card(struct mwifiex_adapter
*adapter
)
392 dev_dbg(adapter
->dev
, "event: wakeup device...\n");
394 return mwifiex_write_reg(adapter
, CONFIGURATION_REG
, HOST_POWER_UP
);
398 * This function is called after the card has woken up.
400 * The card configuration register is reset.
402 static int mwifiex_pm_wakeup_card_complete(struct mwifiex_adapter
*adapter
)
404 dev_dbg(adapter
->dev
, "cmd: wakeup device completed\n");
406 return mwifiex_write_reg(adapter
, CONFIGURATION_REG
, 0);
410 * This function initializes the IO ports.
412 * The following operations are performed -
413 * - Read the IO ports (0, 1 and 2)
414 * - Set host interrupt Reset-To-Read to clear
415 * - Set auto re-enable interrupt
417 static int mwifiex_init_sdio_ioport(struct mwifiex_adapter
*adapter
)
423 /* Read the IO port */
424 if (!mwifiex_read_reg(adapter
, IO_PORT_0_REG
, ®
))
425 adapter
->ioport
|= (reg
& 0xff);
429 if (!mwifiex_read_reg(adapter
, IO_PORT_1_REG
, ®
))
430 adapter
->ioport
|= ((reg
& 0xff) << 8);
434 if (!mwifiex_read_reg(adapter
, IO_PORT_2_REG
, ®
))
435 adapter
->ioport
|= ((reg
& 0xff) << 16);
439 pr_debug("info: SDIO FUNC1 IO port: %#x\n", adapter
->ioport
);
441 /* Set Host interrupt reset to read to clear */
442 if (!mwifiex_read_reg(adapter
, HOST_INT_RSR_REG
, ®
))
443 mwifiex_write_reg(adapter
, HOST_INT_RSR_REG
,
444 reg
| SDIO_INT_MASK
);
448 /* Dnld/Upld ready set to auto reset */
449 if (!mwifiex_read_reg(adapter
, CARD_MISC_CFG_REG
, ®
))
450 mwifiex_write_reg(adapter
, CARD_MISC_CFG_REG
,
451 reg
| AUTO_RE_ENABLE_INT
);
459 * This function sends data to the card.
461 static int mwifiex_write_data_to_card(struct mwifiex_adapter
*adapter
,
462 u8
*payload
, u32 pkt_len
, u32 port
)
468 ret
= mwifiex_write_data_sync(adapter
, payload
, pkt_len
, port
);
471 dev_err(adapter
->dev
, "host_to_card, write iomem"
472 " (%d) failed: %d\n", i
, ret
);
473 if (mwifiex_write_reg(adapter
, 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
&= (u16
)
511 (~(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
)
583 usleep_range(10, 20);
586 dev_err(adapter
->dev
, "poll card status failed, tries = %d\n", tries
);
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
,
708 "firmware image not found! 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
,
719 "unable to alloc buffer for FW. Terminating dnld\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
,
744 "dev BASE0 register read failed: "
745 "base0=%#04X(%d). Terminating dnld\n",
749 ret
= mwifiex_read_reg(adapter
, HOST_F1_RD_BASE_1
,
752 dev_err(adapter
->dev
,
753 "dev BASE1 register read failed: "
754 "base1=%#04X(%d). Terminating dnld\n",
758 len
= (u16
) (((base1
& 0xff) << 8) | (base0
& 0xff));
763 usleep_range(10, 20);
768 } else if (len
> MWIFIEX_UPLD_SIZE
) {
769 dev_err(adapter
->dev
,
770 "FW dnld failed @ %d, invalid length %d\n",
780 if (i
> MAX_WRITE_IOMEM_RETRY
) {
781 dev_err(adapter
->dev
,
782 "FW dnld failed @ %d, over max retry\n",
787 dev_err(adapter
->dev
, "CRC indicated by the helper:"
788 " len = 0x%04X, txlen = %d\n", len
, txlen
);
790 /* Setting this to 0 to resend from same offset */
795 /* Set blocksize to transfer - checking for last
797 if (firmware_len
- offset
< txlen
)
798 txlen
= firmware_len
- offset
;
800 tx_blocks
= (txlen
+ MWIFIEX_SDIO_BLOCK_SIZE
- 1)
801 / MWIFIEX_SDIO_BLOCK_SIZE
;
803 /* Copy payload to buffer */
804 memmove(fwbuf
, &firmware
[offset
], txlen
);
807 ret
= mwifiex_write_data_sync(adapter
, fwbuf
, tx_blocks
*
808 MWIFIEX_SDIO_BLOCK_SIZE
,
811 dev_err(adapter
->dev
,
812 "FW download, write iomem (%d) failed @ %d\n",
814 if (mwifiex_write_reg(adapter
, CONFIGURATION_REG
, 0x04))
815 dev_err(adapter
->dev
, "write CFG reg failed\n");
824 dev_dbg(adapter
->dev
, "info: FW download over, size %d bytes\n",
834 * This function checks the firmware status in card.
836 * The winner interface is also determined by this function.
838 static int mwifiex_check_fw_status(struct mwifiex_adapter
*adapter
,
846 /* Wait for firmware initialization event */
847 for (tries
= 0; tries
< poll_num
; tries
++) {
848 ret
= mwifiex_sdio_read_fw_status(adapter
, &firmware_stat
);
851 if (firmware_stat
== FIRMWARE_READY_SDIO
) {
862 (adapter
, CARD_FW_STATUS0_REG
, &winner_status
))
874 * This function reads the interrupt status from card.
876 static void mwifiex_interrupt_status(struct mwifiex_adapter
*adapter
)
878 struct sdio_mmc_card
*card
= adapter
->card
;
882 if (mwifiex_read_data_sync(adapter
, card
->mp_regs
, MAX_MP_REGS
,
883 REG_PORT
| MWIFIEX_SDIO_BYTE_MODE_MASK
,
885 dev_err(adapter
->dev
, "read mp_regs failed\n");
889 sdio_ireg
= card
->mp_regs
[HOST_INTSTATUS_REG
];
892 * DN_LD_HOST_INT_STATUS and/or UP_LD_HOST_INT_STATUS
893 * Clear the interrupt status register
895 dev_dbg(adapter
->dev
, "int: sdio_ireg = %#x\n", sdio_ireg
);
896 spin_lock_irqsave(&adapter
->int_lock
, flags
);
897 adapter
->int_status
|= sdio_ireg
;
898 spin_unlock_irqrestore(&adapter
->int_lock
, flags
);
903 * SDIO interrupt handler.
905 * This function reads the interrupt status from firmware and assigns
906 * the main process in workqueue which will handle the interrupt.
909 mwifiex_sdio_interrupt(struct sdio_func
*func
)
911 struct mwifiex_adapter
*adapter
;
912 struct sdio_mmc_card
*card
;
914 card
= sdio_get_drvdata(func
);
915 if (!card
|| !card
->adapter
) {
916 pr_debug("int: func=%p card=%p adapter=%p\n",
917 func
, card
, card
? card
->adapter
: NULL
);
920 adapter
= card
->adapter
;
922 if (adapter
->surprise_removed
)
925 if (!adapter
->pps_uapsd_mode
&& adapter
->ps_state
== PS_STATE_SLEEP
)
926 adapter
->ps_state
= PS_STATE_AWAKE
;
928 mwifiex_interrupt_status(adapter
);
929 queue_work(adapter
->workqueue
, &adapter
->main_work
);
933 * This function decodes a received packet.
935 * Based on the type, the packet is treated as either a data, or
936 * a command response, or an event, and the correct handler
937 * function is invoked.
939 static int mwifiex_decode_rx_packet(struct mwifiex_adapter
*adapter
,
940 struct sk_buff
*skb
, u32 upld_typ
)
944 skb_pull(skb
, INTF_HEADER_LEN
);
947 case MWIFIEX_TYPE_DATA
:
948 dev_dbg(adapter
->dev
, "info: --- Rx: Data packet ---\n");
949 mwifiex_handle_rx_packet(adapter
, skb
);
952 case MWIFIEX_TYPE_CMD
:
953 dev_dbg(adapter
->dev
, "info: --- Rx: Cmd Response ---\n");
954 /* take care of curr_cmd = NULL case */
955 if (!adapter
->curr_cmd
) {
956 cmd_buf
= adapter
->upld_buf
;
958 if (adapter
->ps_state
== PS_STATE_SLEEP_CFM
)
959 mwifiex_process_sleep_confirm_resp(adapter
,
963 memcpy(cmd_buf
, skb
->data
,
964 min_t(u32
, MWIFIEX_SIZE_OF_CMD_BUFFER
,
967 dev_kfree_skb_any(skb
);
969 adapter
->cmd_resp_received
= true;
970 adapter
->curr_cmd
->resp_skb
= skb
;
974 case MWIFIEX_TYPE_EVENT
:
975 dev_dbg(adapter
->dev
, "info: --- Rx: Event ---\n");
976 adapter
->event_cause
= *(u32
*) skb
->data
;
978 skb_pull(skb
, MWIFIEX_EVENT_HEADER_LEN
);
980 if ((skb
->len
> 0) && (skb
->len
< MAX_EVENT_SIZE
))
981 memcpy(adapter
->event_body
, skb
->data
, skb
->len
);
983 /* event cause has been saved to adapter->event_cause */
984 adapter
->event_received
= true;
985 adapter
->event_skb
= skb
;
990 dev_err(adapter
->dev
, "unknown upload type %#x\n", upld_typ
);
991 dev_kfree_skb_any(skb
);
999 * This function transfers received packets from card to driver, performing
1000 * aggregation if required.
1002 * For data received on control port, or if aggregation is disabled, the
1003 * received buffers are uploaded as separate packets. However, if aggregation
1004 * is enabled and required, the buffers are copied onto an aggregation buffer,
1005 * provided there is space left, processed and finally uploaded.
1007 static int mwifiex_sdio_card_to_host_mp_aggr(struct mwifiex_adapter
*adapter
,
1008 struct sk_buff
*skb
, u8 port
)
1010 struct sdio_mmc_card
*card
= adapter
->card
;
1011 s32 f_do_rx_aggr
= 0;
1012 s32 f_do_rx_cur
= 0;
1014 struct sk_buff
*skb_deaggr
;
1016 u32 pkt_len
, pkt_type
= 0;
1018 u32 rx_len
= skb
->len
;
1020 if (port
== CTRL_PORT
) {
1021 /* Read the command Resp without aggr */
1022 dev_dbg(adapter
->dev
, "info: %s: no aggregation for cmd "
1023 "response\n", __func__
);
1026 goto rx_curr_single
;
1029 if (!card
->mpa_rx
.enabled
) {
1030 dev_dbg(adapter
->dev
, "info: %s: rx aggregation disabled\n",
1034 goto rx_curr_single
;
1037 if (card
->mp_rd_bitmap
& (~((u16
) CTRL_PORT_MASK
))) {
1038 /* Some more data RX pending */
1039 dev_dbg(adapter
->dev
, "info: %s: not last packet\n", __func__
);
1041 if (MP_RX_AGGR_IN_PROGRESS(card
)) {
1042 if (MP_RX_AGGR_BUF_HAS_ROOM(card
, skb
->len
)) {
1045 /* No room in Aggr buf, do rx aggr now */
1050 /* Rx aggr not in progress */
1055 /* No more data RX pending */
1056 dev_dbg(adapter
->dev
, "info: %s: last packet\n", __func__
);
1058 if (MP_RX_AGGR_IN_PROGRESS(card
)) {
1060 if (MP_RX_AGGR_BUF_HAS_ROOM(card
, skb
->len
))
1063 /* No room in Aggr buf, do rx aggr now */
1071 dev_dbg(adapter
->dev
, "info: current packet aggregation\n");
1072 /* Curr pkt can be aggregated */
1073 MP_RX_AGGR_SETUP(card
, skb
, port
);
1075 if (MP_RX_AGGR_PKT_LIMIT_REACHED(card
) ||
1076 MP_RX_AGGR_PORT_LIMIT_REACHED(card
)) {
1077 dev_dbg(adapter
->dev
, "info: %s: aggregated packet "
1078 "limit reached\n", __func__
);
1079 /* No more pkts allowed in Aggr buf, rx it */
1085 /* do aggr RX now */
1086 dev_dbg(adapter
->dev
, "info: do_rx_aggr: num of packets: %d\n",
1087 card
->mpa_rx
.pkt_cnt
);
1089 if (mwifiex_read_data_sync(adapter
, card
->mpa_rx
.buf
,
1090 card
->mpa_rx
.buf_len
,
1091 (adapter
->ioport
| 0x1000 |
1092 (card
->mpa_rx
.ports
<< 4)) +
1093 card
->mpa_rx
.start_port
, 1))
1096 curr_ptr
= card
->mpa_rx
.buf
;
1098 for (pind
= 0; pind
< card
->mpa_rx
.pkt_cnt
; pind
++) {
1100 /* get curr PKT len & type */
1101 pkt_len
= *(u16
*) &curr_ptr
[0];
1102 pkt_type
= *(u16
*) &curr_ptr
[2];
1104 /* copy pkt to deaggr buf */
1105 skb_deaggr
= card
->mpa_rx
.skb_arr
[pind
];
1107 if ((pkt_type
== MWIFIEX_TYPE_DATA
) && (pkt_len
<=
1108 card
->mpa_rx
.len_arr
[pind
])) {
1110 memcpy(skb_deaggr
->data
, curr_ptr
, pkt_len
);
1112 skb_trim(skb_deaggr
, pkt_len
);
1114 /* Process de-aggr packet */
1115 mwifiex_decode_rx_packet(adapter
, skb_deaggr
,
1118 dev_err(adapter
->dev
, "wrong aggr pkt:"
1119 " type=%d len=%d max_len=%d\n",
1121 card
->mpa_rx
.len_arr
[pind
]);
1122 dev_kfree_skb_any(skb_deaggr
);
1124 curr_ptr
+= card
->mpa_rx
.len_arr
[pind
];
1126 MP_RX_AGGR_BUF_RESET(card
);
1131 dev_dbg(adapter
->dev
, "info: RX: port: %d, rx_len: %d\n",
1134 if (mwifiex_sdio_card_to_host(adapter
, &pkt_type
,
1135 skb
->data
, skb
->len
,
1136 adapter
->ioport
+ port
))
1139 mwifiex_decode_rx_packet(adapter
, skb
, pkt_type
);
1145 if (MP_RX_AGGR_IN_PROGRESS(card
)) {
1146 /* Multiport-aggregation transfer failed - cleanup */
1147 for (pind
= 0; pind
< card
->mpa_rx
.pkt_cnt
; pind
++) {
1148 /* copy pkt to deaggr buf */
1149 skb_deaggr
= card
->mpa_rx
.skb_arr
[pind
];
1150 dev_kfree_skb_any(skb_deaggr
);
1152 MP_RX_AGGR_BUF_RESET(card
);
1156 /* Single transfer pending. Free curr buff also */
1157 dev_kfree_skb_any(skb
);
1163 * This function checks the current interrupt status.
1165 * The following interrupts are checked and handled by this function -
1168 * - Packets received
1170 * Since the firmware does not generate download ready interrupt if the
1171 * port updated is command port only, command sent interrupt checking
1172 * should be done manually, and for every SDIO interrupt.
1174 * In case of Rx packets received, the packets are uploaded from card to
1175 * host and processed accordingly.
1177 static int mwifiex_process_int_status(struct mwifiex_adapter
*adapter
)
1179 struct sdio_mmc_card
*card
= adapter
->card
;
1182 struct sk_buff
*skb
;
1183 u8 port
= CTRL_PORT
;
1184 u32 len_reg_l
, len_reg_u
;
1187 unsigned long flags
;
1189 spin_lock_irqsave(&adapter
->int_lock
, flags
);
1190 sdio_ireg
= adapter
->int_status
;
1191 adapter
->int_status
= 0;
1192 spin_unlock_irqrestore(&adapter
->int_lock
, flags
);
1197 if (sdio_ireg
& DN_LD_HOST_INT_STATUS
) {
1198 card
->mp_wr_bitmap
= ((u16
) card
->mp_regs
[WR_BITMAP_U
]) << 8;
1199 card
->mp_wr_bitmap
|= (u16
) card
->mp_regs
[WR_BITMAP_L
];
1200 dev_dbg(adapter
->dev
, "int: DNLD: wr_bitmap=0x%04x\n",
1201 card
->mp_wr_bitmap
);
1202 if (adapter
->data_sent
&&
1203 (card
->mp_wr_bitmap
& card
->mp_data_port_mask
)) {
1204 dev_dbg(adapter
->dev
,
1205 "info: <--- Tx DONE Interrupt --->\n");
1206 adapter
->data_sent
= false;
1210 /* As firmware will not generate download ready interrupt if the port
1211 updated is command port only, cmd_sent should be done for any SDIO
1213 if (adapter
->cmd_sent
) {
1214 /* Check if firmware has attach buffer at command port and
1215 update just that in wr_bit_map. */
1216 card
->mp_wr_bitmap
|=
1217 (u16
) card
->mp_regs
[WR_BITMAP_L
] & CTRL_PORT_MASK
;
1218 if (card
->mp_wr_bitmap
& CTRL_PORT_MASK
)
1219 adapter
->cmd_sent
= false;
1222 dev_dbg(adapter
->dev
, "info: cmd_sent=%d data_sent=%d\n",
1223 adapter
->cmd_sent
, adapter
->data_sent
);
1224 if (sdio_ireg
& UP_LD_HOST_INT_STATUS
) {
1225 card
->mp_rd_bitmap
= ((u16
) card
->mp_regs
[RD_BITMAP_U
]) << 8;
1226 card
->mp_rd_bitmap
|= (u16
) card
->mp_regs
[RD_BITMAP_L
];
1227 dev_dbg(adapter
->dev
, "int: UPLD: rd_bitmap=0x%04x\n",
1228 card
->mp_rd_bitmap
);
1231 ret
= mwifiex_get_rd_port(adapter
, &port
);
1233 dev_dbg(adapter
->dev
,
1234 "info: no more rd_port available\n");
1237 len_reg_l
= RD_LEN_P0_L
+ (port
<< 1);
1238 len_reg_u
= RD_LEN_P0_U
+ (port
<< 1);
1239 rx_len
= ((u16
) card
->mp_regs
[len_reg_u
]) << 8;
1240 rx_len
|= (u16
) card
->mp_regs
[len_reg_l
];
1241 dev_dbg(adapter
->dev
, "info: RX: port=%d rx_len=%u\n",
1244 (rx_len
+ MWIFIEX_SDIO_BLOCK_SIZE
-
1245 1) / MWIFIEX_SDIO_BLOCK_SIZE
;
1246 if (rx_len
<= INTF_HEADER_LEN
||
1247 (rx_blocks
* MWIFIEX_SDIO_BLOCK_SIZE
) >
1248 MWIFIEX_RX_DATA_BUF_SIZE
) {
1249 dev_err(adapter
->dev
, "invalid rx_len=%d\n",
1253 rx_len
= (u16
) (rx_blocks
* MWIFIEX_SDIO_BLOCK_SIZE
);
1255 skb
= dev_alloc_skb(rx_len
);
1258 dev_err(adapter
->dev
, "%s: failed to alloc skb",
1263 skb_put(skb
, rx_len
);
1265 dev_dbg(adapter
->dev
, "info: rx_len = %d skb->len = %d\n",
1268 if (mwifiex_sdio_card_to_host_mp_aggr(adapter
, skb
,
1272 dev_err(adapter
->dev
, "card_to_host_mpa failed:"
1273 " int status=%#x\n", sdio_ireg
);
1274 if (mwifiex_read_reg(adapter
,
1275 CONFIGURATION_REG
, &cr
))
1276 dev_err(adapter
->dev
,
1277 "read CFG reg failed\n");
1279 dev_dbg(adapter
->dev
,
1280 "info: CFG reg val = %d\n", cr
);
1281 if (mwifiex_write_reg(adapter
,
1284 dev_err(adapter
->dev
,
1285 "write CFG reg failed\n");
1287 dev_dbg(adapter
->dev
, "info: write success\n");
1288 if (mwifiex_read_reg(adapter
,
1289 CONFIGURATION_REG
, &cr
))
1290 dev_err(adapter
->dev
,
1291 "read CFG reg failed\n");
1293 dev_dbg(adapter
->dev
,
1294 "info: CFG reg val =%x\n", cr
);
1304 * This function aggregates transmission buffers in driver and downloads
1305 * the aggregated packet to card.
1307 * The individual packets are aggregated by copying into an aggregation
1308 * buffer and then downloaded to the card. Previous unsent packets in the
1309 * aggregation buffer are pre-copied first before new packets are added.
1310 * Aggregation is done till there is space left in the aggregation buffer,
1311 * or till new packets are available.
1313 * The function will only download the packet to the card when aggregation
1314 * stops, otherwise it will just aggregate the packet in aggregation buffer
1317 static int mwifiex_host_to_card_mp_aggr(struct mwifiex_adapter
*adapter
,
1318 u8
*payload
, u32 pkt_len
, u8 port
,
1321 struct sdio_mmc_card
*card
= adapter
->card
;
1323 s32 f_send_aggr_buf
= 0;
1324 s32 f_send_cur_buf
= 0;
1325 s32 f_precopy_cur_buf
= 0;
1326 s32 f_postcopy_cur_buf
= 0;
1328 if ((!card
->mpa_tx
.enabled
) || (port
== CTRL_PORT
)) {
1329 dev_dbg(adapter
->dev
, "info: %s: tx aggregation disabled\n",
1333 goto tx_curr_single
;
1337 /* More pkt in TX queue */
1338 dev_dbg(adapter
->dev
, "info: %s: more packets in queue.\n",
1341 if (MP_TX_AGGR_IN_PROGRESS(card
)) {
1342 if (!MP_TX_AGGR_PORT_LIMIT_REACHED(card
) &&
1343 MP_TX_AGGR_BUF_HAS_ROOM(card
, pkt_len
)) {
1344 f_precopy_cur_buf
= 1;
1346 if (!(card
->mp_wr_bitmap
&
1347 (1 << card
->curr_wr_port
)) ||
1348 !MP_TX_AGGR_BUF_HAS_ROOM(
1349 card
, pkt_len
+ next_pkt_len
))
1350 f_send_aggr_buf
= 1;
1352 /* No room in Aggr buf, send it */
1353 f_send_aggr_buf
= 1;
1355 if (MP_TX_AGGR_PORT_LIMIT_REACHED(card
) ||
1356 !(card
->mp_wr_bitmap
&
1357 (1 << card
->curr_wr_port
)))
1360 f_postcopy_cur_buf
= 1;
1363 if (MP_TX_AGGR_BUF_HAS_ROOM(card
, pkt_len
) &&
1364 (card
->mp_wr_bitmap
& (1 << card
->curr_wr_port
)))
1365 f_precopy_cur_buf
= 1;
1370 /* Last pkt in TX queue */
1371 dev_dbg(adapter
->dev
, "info: %s: Last packet in Tx Queue.\n",
1374 if (MP_TX_AGGR_IN_PROGRESS(card
)) {
1375 /* some packs in Aggr buf already */
1376 f_send_aggr_buf
= 1;
1378 if (MP_TX_AGGR_BUF_HAS_ROOM(card
, pkt_len
))
1379 f_precopy_cur_buf
= 1;
1381 /* No room in Aggr buf, send it */
1388 if (f_precopy_cur_buf
) {
1389 dev_dbg(adapter
->dev
, "data: %s: precopy current buffer\n",
1391 MP_TX_AGGR_BUF_PUT(card
, payload
, pkt_len
, port
);
1393 if (MP_TX_AGGR_PKT_LIMIT_REACHED(card
) ||
1394 MP_TX_AGGR_PORT_LIMIT_REACHED(card
))
1395 /* No more pkts allowed in Aggr buf, send it */
1396 f_send_aggr_buf
= 1;
1399 if (f_send_aggr_buf
) {
1400 dev_dbg(adapter
->dev
, "data: %s: send aggr buffer: %d %d\n",
1402 card
->mpa_tx
.start_port
, card
->mpa_tx
.ports
);
1403 ret
= mwifiex_write_data_to_card(adapter
, card
->mpa_tx
.buf
,
1404 card
->mpa_tx
.buf_len
,
1405 (adapter
->ioport
| 0x1000 |
1406 (card
->mpa_tx
.ports
<< 4)) +
1407 card
->mpa_tx
.start_port
);
1409 MP_TX_AGGR_BUF_RESET(card
);
1413 if (f_send_cur_buf
) {
1414 dev_dbg(adapter
->dev
, "data: %s: send current buffer %d\n",
1416 ret
= mwifiex_write_data_to_card(adapter
, payload
, pkt_len
,
1417 adapter
->ioport
+ port
);
1420 if (f_postcopy_cur_buf
) {
1421 dev_dbg(adapter
->dev
, "data: %s: postcopy current buffer\n",
1423 MP_TX_AGGR_BUF_PUT(card
, payload
, pkt_len
, port
);
1430 * This function downloads data from driver to card.
1432 * Both commands and data packets are transferred to the card by this
1435 * This function adds the SDIO specific header to the front of the buffer
1436 * before transferring. The header contains the length of the packet and
1437 * the type. The firmware handles the packets based upon this set type.
1439 static int mwifiex_sdio_host_to_card(struct mwifiex_adapter
*adapter
,
1440 u8 type
, struct sk_buff
*skb
,
1441 struct mwifiex_tx_param
*tx_param
)
1443 struct sdio_mmc_card
*card
= adapter
->card
;
1447 u8 port
= CTRL_PORT
;
1448 u8
*payload
= (u8
*)skb
->data
;
1449 u32 pkt_len
= skb
->len
;
1451 /* Allocate buffer and copy payload */
1452 blk_size
= MWIFIEX_SDIO_BLOCK_SIZE
;
1453 buf_block_len
= (pkt_len
+ blk_size
- 1) / blk_size
;
1454 *(u16
*) &payload
[0] = (u16
) pkt_len
;
1455 *(u16
*) &payload
[2] = type
;
1458 * This is SDIO specific header
1460 * u16 type (MWIFIEX_TYPE_DATA = 0, MWIFIEX_TYPE_CMD = 1,
1461 * MWIFIEX_TYPE_EVENT = 3)
1463 if (type
== MWIFIEX_TYPE_DATA
) {
1464 ret
= mwifiex_get_wr_port_data(adapter
, &port
);
1466 dev_err(adapter
->dev
, "%s: no wr_port available\n",
1471 adapter
->cmd_sent
= true;
1472 /* Type must be MWIFIEX_TYPE_CMD */
1474 if (pkt_len
<= INTF_HEADER_LEN
||
1475 pkt_len
> MWIFIEX_UPLD_SIZE
)
1476 dev_err(adapter
->dev
, "%s: payload=%p, nb=%d\n",
1477 __func__
, payload
, pkt_len
);
1480 /* Transfer data to card */
1481 pkt_len
= buf_block_len
* blk_size
;
1484 ret
= mwifiex_host_to_card_mp_aggr(adapter
, payload
, pkt_len
,
1485 port
, tx_param
->next_pkt_len
1488 ret
= mwifiex_host_to_card_mp_aggr(adapter
, payload
, pkt_len
,
1492 if (type
== MWIFIEX_TYPE_CMD
)
1493 adapter
->cmd_sent
= false;
1494 if (type
== MWIFIEX_TYPE_DATA
)
1495 adapter
->data_sent
= false;
1497 if (type
== MWIFIEX_TYPE_DATA
) {
1498 if (!(card
->mp_wr_bitmap
& (1 << card
->curr_wr_port
)))
1499 adapter
->data_sent
= true;
1501 adapter
->data_sent
= false;
1509 * This function allocates the MPA Tx and Rx buffers.
1511 static int mwifiex_alloc_sdio_mpa_buffers(struct mwifiex_adapter
*adapter
,
1512 u32 mpa_tx_buf_size
, u32 mpa_rx_buf_size
)
1514 struct sdio_mmc_card
*card
= adapter
->card
;
1517 card
->mpa_tx
.buf
= kzalloc(mpa_tx_buf_size
, GFP_KERNEL
);
1518 if (!card
->mpa_tx
.buf
) {
1519 dev_err(adapter
->dev
, "could not alloc buffer for MP-A TX\n");
1524 card
->mpa_tx
.buf_size
= mpa_tx_buf_size
;
1526 card
->mpa_rx
.buf
= kzalloc(mpa_rx_buf_size
, GFP_KERNEL
);
1527 if (!card
->mpa_rx
.buf
) {
1528 dev_err(adapter
->dev
, "could not alloc buffer for MP-A RX\n");
1533 card
->mpa_rx
.buf_size
= mpa_rx_buf_size
;
1537 kfree(card
->mpa_tx
.buf
);
1538 kfree(card
->mpa_rx
.buf
);
1545 * This function unregisters the SDIO device.
1547 * The SDIO IRQ is released, the function is disabled and driver
1548 * data is set to null.
1551 mwifiex_unregister_dev(struct mwifiex_adapter
*adapter
)
1553 struct sdio_mmc_card
*card
= adapter
->card
;
1555 if (adapter
->card
) {
1556 /* Release the SDIO IRQ */
1557 sdio_claim_host(card
->func
);
1558 sdio_release_irq(card
->func
);
1559 sdio_disable_func(card
->func
);
1560 sdio_release_host(card
->func
);
1561 sdio_set_drvdata(card
->func
, NULL
);
1566 * This function registers the SDIO device.
1568 * SDIO IRQ is claimed, block size is set and driver data is initialized.
1570 static int mwifiex_register_dev(struct mwifiex_adapter
*adapter
)
1573 struct sdio_mmc_card
*card
= adapter
->card
;
1574 struct sdio_func
*func
= card
->func
;
1576 /* save adapter pointer in card */
1577 card
->adapter
= adapter
;
1579 sdio_claim_host(func
);
1581 /* Request the SDIO IRQ */
1582 ret
= sdio_claim_irq(func
, mwifiex_sdio_interrupt
);
1584 pr_err("claim irq failed: ret=%d\n", ret
);
1588 /* Set block size */
1589 ret
= sdio_set_block_size(card
->func
, MWIFIEX_SDIO_BLOCK_SIZE
);
1591 pr_err("cannot set SDIO block size\n");
1596 sdio_release_host(func
);
1597 sdio_set_drvdata(func
, card
);
1599 adapter
->dev
= &func
->dev
;
1601 switch (func
->device
) {
1602 case SDIO_DEVICE_ID_MARVELL_8797
:
1603 strcpy(adapter
->fw_name
, SD8797_DEFAULT_FW_NAME
);
1605 case SDIO_DEVICE_ID_MARVELL_8787
:
1607 strcpy(adapter
->fw_name
, SD8787_DEFAULT_FW_NAME
);
1614 sdio_release_irq(func
);
1616 sdio_disable_func(func
);
1617 sdio_release_host(func
);
1618 adapter
->card
= NULL
;
1624 * This function initializes the SDIO driver.
1626 * The following initializations steps are followed -
1627 * - Read the Host interrupt status register to acknowledge
1628 * the first interrupt got from bootloader
1629 * - Disable host interrupt mask register
1631 * - Initialize SDIO variables in card
1632 * - Allocate MP registers
1633 * - Allocate MPA Tx and Rx buffers
1635 static int mwifiex_init_sdio(struct mwifiex_adapter
*adapter
)
1637 struct sdio_mmc_card
*card
= adapter
->card
;
1642 * Read the HOST_INT_STATUS_REG for ACK the first interrupt got
1643 * from the bootloader. If we don't do this we get a interrupt
1644 * as soon as we register the irq.
1646 mwifiex_read_reg(adapter
, HOST_INTSTATUS_REG
, &sdio_ireg
);
1648 /* Disable host interrupt mask register for SDIO */
1649 mwifiex_sdio_disable_host_int(adapter
);
1651 /* Get SDIO ioport */
1652 mwifiex_init_sdio_ioport(adapter
);
1654 /* Initialize SDIO variables in card */
1655 card
->mp_rd_bitmap
= 0;
1656 card
->mp_wr_bitmap
= 0;
1657 card
->curr_rd_port
= 1;
1658 card
->curr_wr_port
= 1;
1660 card
->mp_data_port_mask
= DATA_PORT_MASK
;
1662 card
->mpa_tx
.buf_len
= 0;
1663 card
->mpa_tx
.pkt_cnt
= 0;
1664 card
->mpa_tx
.start_port
= 0;
1666 card
->mpa_tx
.enabled
= 1;
1667 card
->mpa_tx
.pkt_aggr_limit
= SDIO_MP_AGGR_DEF_PKT_LIMIT
;
1669 card
->mpa_rx
.buf_len
= 0;
1670 card
->mpa_rx
.pkt_cnt
= 0;
1671 card
->mpa_rx
.start_port
= 0;
1673 card
->mpa_rx
.enabled
= 1;
1674 card
->mpa_rx
.pkt_aggr_limit
= SDIO_MP_AGGR_DEF_PKT_LIMIT
;
1676 /* Allocate buffers for SDIO MP-A */
1677 card
->mp_regs
= kzalloc(MAX_MP_REGS
, GFP_KERNEL
);
1678 if (!card
->mp_regs
) {
1679 dev_err(adapter
->dev
, "failed to alloc mp_regs\n");
1683 ret
= mwifiex_alloc_sdio_mpa_buffers(adapter
,
1684 SDIO_MP_TX_AGGR_DEF_BUF_SIZE
,
1685 SDIO_MP_RX_AGGR_DEF_BUF_SIZE
);
1687 dev_err(adapter
->dev
, "failed to alloc sdio mp-a buffers\n");
1688 kfree(card
->mp_regs
);
1696 * This function resets the MPA Tx and Rx buffers.
1698 static void mwifiex_cleanup_mpa_buf(struct mwifiex_adapter
*adapter
)
1700 struct sdio_mmc_card
*card
= adapter
->card
;
1702 MP_TX_AGGR_BUF_RESET(card
);
1703 MP_RX_AGGR_BUF_RESET(card
);
1707 * This function cleans up the allocated card buffers.
1709 * The following are freed by this function -
1714 static void mwifiex_cleanup_sdio(struct mwifiex_adapter
*adapter
)
1716 struct sdio_mmc_card
*card
= adapter
->card
;
1718 kfree(card
->mp_regs
);
1719 kfree(card
->mpa_tx
.buf
);
1720 kfree(card
->mpa_rx
.buf
);
1724 * This function updates the MP end port in card.
1727 mwifiex_update_mp_end_port(struct mwifiex_adapter
*adapter
, u16 port
)
1729 struct sdio_mmc_card
*card
= adapter
->card
;
1732 card
->mp_end_port
= port
;
1734 card
->mp_data_port_mask
= DATA_PORT_MASK
;
1736 for (i
= 1; i
<= MAX_PORT
- card
->mp_end_port
; i
++)
1737 card
->mp_data_port_mask
&= ~(1 << (MAX_PORT
- i
));
1739 card
->curr_wr_port
= 1;
1741 dev_dbg(adapter
->dev
, "cmd: mp_end_port %d, data port mask 0x%x\n",
1742 port
, card
->mp_data_port_mask
);
1745 static struct mwifiex_if_ops sdio_ops
= {
1746 .init_if
= mwifiex_init_sdio
,
1747 .cleanup_if
= mwifiex_cleanup_sdio
,
1748 .check_fw_status
= mwifiex_check_fw_status
,
1749 .prog_fw
= mwifiex_prog_fw_w_helper
,
1750 .register_dev
= mwifiex_register_dev
,
1751 .unregister_dev
= mwifiex_unregister_dev
,
1752 .enable_int
= mwifiex_sdio_enable_host_int
,
1753 .process_int_status
= mwifiex_process_int_status
,
1754 .host_to_card
= mwifiex_sdio_host_to_card
,
1755 .wakeup
= mwifiex_pm_wakeup_card
,
1756 .wakeup_complete
= mwifiex_pm_wakeup_card_complete
,
1759 .update_mp_end_port
= mwifiex_update_mp_end_port
,
1760 .cleanup_mpa_buf
= mwifiex_cleanup_mpa_buf
,
1761 .cmdrsp_complete
= mwifiex_sdio_cmdrsp_complete
,
1762 .event_complete
= mwifiex_sdio_event_complete
,
1766 * This function initializes the SDIO driver.
1768 * This initiates the semaphore and registers the device with
1772 mwifiex_sdio_init_module(void)
1774 sema_init(&add_remove_card_sem
, 1);
1776 /* Clear the flag in case user removes the card. */
1779 return sdio_register_driver(&mwifiex_sdio
);
1783 * This function cleans up the SDIO driver.
1785 * The following major steps are followed for cleanup -
1786 * - Resume the device if its suspended
1787 * - Disconnect the device if connected
1788 * - Shutdown the firmware
1789 * - Unregister the device from SDIO bus.
1792 mwifiex_sdio_cleanup_module(void)
1794 if (!down_interruptible(&add_remove_card_sem
))
1795 up(&add_remove_card_sem
);
1797 /* Set the flag as user is removing this module. */
1800 sdio_unregister_driver(&mwifiex_sdio
);
1803 module_init(mwifiex_sdio_init_module
);
1804 module_exit(mwifiex_sdio_cleanup_module
);
1806 MODULE_AUTHOR("Marvell International Ltd.");
1807 MODULE_DESCRIPTION("Marvell WiFi-Ex SDIO Driver version " SDIO_VERSION
);
1808 MODULE_VERSION(SDIO_VERSION
);
1809 MODULE_LICENSE("GPL v2");
1810 MODULE_FIRMWARE(SD8787_DEFAULT_FW_NAME
);
1811 MODULE_FIRMWARE(SD8797_DEFAULT_FW_NAME
);