2 * NXP Wireless LAN device driver: SDIO specific handling
4 * Copyright 2011-2020 NXP
6 * This software file (the "File") is distributed by NXP
7 * 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 void mwifiex_sdio_work(struct work_struct
*work
);
36 static struct mwifiex_if_ops sdio_ops
;
38 static struct memory_type_mapping generic_mem_type_map
[] = {
39 {"DUMP", NULL
, 0, 0xDD},
42 static struct memory_type_mapping mem_type_mapping_tbl
[] = {
43 {"ITCM", NULL
, 0, 0xF0},
44 {"DTCM", NULL
, 0, 0xF1},
45 {"SQRAM", NULL
, 0, 0xF2},
46 {"APU", NULL
, 0, 0xF3},
47 {"CIU", NULL
, 0, 0xF4},
48 {"ICU", NULL
, 0, 0xF5},
49 {"MAC", NULL
, 0, 0xF6},
50 {"EXT7", NULL
, 0, 0xF7},
51 {"EXT8", NULL
, 0, 0xF8},
52 {"EXT9", NULL
, 0, 0xF9},
53 {"EXT10", NULL
, 0, 0xFA},
54 {"EXT11", NULL
, 0, 0xFB},
55 {"EXT12", NULL
, 0, 0xFC},
56 {"EXT13", NULL
, 0, 0xFD},
57 {"EXTLAST", NULL
, 0, 0xFE},
60 static const struct of_device_id mwifiex_sdio_of_match_table
[] = {
61 { .compatible
= "marvell,sd8897" },
62 { .compatible
= "marvell,sd8997" },
66 /* This function parse device tree node using mmc subnode devicetree API.
67 * The device node is saved in card->plt_of_node.
68 * if the device tree node exist and include interrupts attributes, this
69 * function will also request platform specific wakeup interrupt.
71 static int mwifiex_sdio_probe_of(struct device
*dev
)
73 if (!of_match_node(mwifiex_sdio_of_match_table
, dev
->of_node
)) {
74 dev_err(dev
, "required compatible string missing\n");
84 * This function probes an mwifiex device and registers it. It allocates
85 * the card structure, enables SDIO function number and initiates the
86 * device registration and initialization procedure by adding a logical
90 mwifiex_sdio_probe(struct sdio_func
*func
, const struct sdio_device_id
*id
)
93 struct sdio_mmc_card
*card
= NULL
;
95 pr_debug("info: vendor=0x%4.04X device=0x%4.04X class=%d function=%d\n",
96 func
->vendor
, func
->device
, func
->class, func
->num
);
98 card
= devm_kzalloc(&func
->dev
, sizeof(*card
), GFP_KERNEL
);
102 init_completion(&card
->fw_done
);
106 func
->card
->quirks
|= MMC_QUIRK_BLKSZ_FOR_BYTE_MODE
;
108 if (id
->driver_data
) {
109 struct mwifiex_sdio_device
*data
= (void *)id
->driver_data
;
111 card
->firmware
= data
->firmware
;
112 card
->reg
= data
->reg
;
113 card
->max_ports
= data
->max_ports
;
114 card
->mp_agg_pkt_limit
= data
->mp_agg_pkt_limit
;
115 card
->supports_sdio_new_mode
= data
->supports_sdio_new_mode
;
116 card
->has_control_mask
= data
->has_control_mask
;
117 card
->tx_buf_size
= data
->tx_buf_size
;
118 card
->mp_tx_agg_buf_size
= data
->mp_tx_agg_buf_size
;
119 card
->mp_rx_agg_buf_size
= data
->mp_rx_agg_buf_size
;
120 card
->can_dump_fw
= data
->can_dump_fw
;
121 card
->fw_dump_enh
= data
->fw_dump_enh
;
122 card
->can_auto_tdls
= data
->can_auto_tdls
;
123 card
->can_ext_scan
= data
->can_ext_scan
;
124 INIT_WORK(&card
->work
, mwifiex_sdio_work
);
127 sdio_claim_host(func
);
128 ret
= sdio_enable_func(func
);
129 sdio_release_host(func
);
132 dev_err(&func
->dev
, "failed to enable function\n");
136 /* device tree node parsing and platform specific configuration*/
137 if (func
->dev
.of_node
) {
138 ret
= mwifiex_sdio_probe_of(&func
->dev
);
143 ret
= mwifiex_add_card(card
, &card
->fw_done
, &sdio_ops
,
144 MWIFIEX_SDIO
, &func
->dev
);
146 dev_err(&func
->dev
, "add card failed\n");
153 sdio_claim_host(func
);
154 sdio_disable_func(func
);
155 sdio_release_host(func
);
163 * Kernel needs to suspend all functions separately. Therefore all
164 * registered functions must have drivers with suspend and resume
165 * methods. Failing that the kernel simply removes the whole card.
167 * If already not resumed, this function turns on the traffic and
168 * sends a host sleep cancel request to the firmware.
170 static int mwifiex_sdio_resume(struct device
*dev
)
172 struct sdio_func
*func
= dev_to_sdio_func(dev
);
173 struct sdio_mmc_card
*card
;
174 struct mwifiex_adapter
*adapter
;
176 card
= sdio_get_drvdata(func
);
177 if (!card
|| !card
->adapter
) {
178 dev_err(dev
, "resume: invalid card or adapter\n");
182 adapter
= card
->adapter
;
184 if (!test_bit(MWIFIEX_IS_SUSPENDED
, &adapter
->work_flags
)) {
185 mwifiex_dbg(adapter
, WARN
,
186 "device already resumed\n");
190 clear_bit(MWIFIEX_IS_SUSPENDED
, &adapter
->work_flags
);
192 /* Disable Host Sleep */
193 mwifiex_cancel_hs(mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
),
196 mwifiex_disable_wake(adapter
);
201 /* Write data into SDIO card register. Caller claims SDIO device. */
203 mwifiex_write_reg_locked(struct sdio_func
*func
, u32 reg
, u8 data
)
207 sdio_writeb(func
, data
, reg
, &ret
);
211 /* This function writes data into SDIO card register.
214 mwifiex_write_reg(struct mwifiex_adapter
*adapter
, u32 reg
, u8 data
)
216 struct sdio_mmc_card
*card
= adapter
->card
;
219 sdio_claim_host(card
->func
);
220 ret
= mwifiex_write_reg_locked(card
->func
, reg
, data
);
221 sdio_release_host(card
->func
);
226 /* This function reads data from SDIO card register.
229 mwifiex_read_reg(struct mwifiex_adapter
*adapter
, u32 reg
, u8
*data
)
231 struct sdio_mmc_card
*card
= adapter
->card
;
235 sdio_claim_host(card
->func
);
236 val
= sdio_readb(card
->func
, reg
, &ret
);
237 sdio_release_host(card
->func
);
244 /* This function writes multiple data into SDIO card memory.
246 * This does not work in suspended mode.
249 mwifiex_write_data_sync(struct mwifiex_adapter
*adapter
,
250 u8
*buffer
, u32 pkt_len
, u32 port
)
252 struct sdio_mmc_card
*card
= adapter
->card
;
255 (port
& MWIFIEX_SDIO_BYTE_MODE_MASK
) ? BYTE_MODE
: BLOCK_MODE
;
256 u32 blk_size
= (blk_mode
== BLOCK_MODE
) ? MWIFIEX_SDIO_BLOCK_SIZE
: 1;
259 BLOCK_MODE
) ? (pkt_len
/
260 MWIFIEX_SDIO_BLOCK_SIZE
) : pkt_len
;
261 u32 ioport
= (port
& MWIFIEX_SDIO_IO_PORT_MASK
);
263 if (test_bit(MWIFIEX_IS_SUSPENDED
, &adapter
->work_flags
)) {
264 mwifiex_dbg(adapter
, ERROR
,
265 "%s: not allowed while suspended\n", __func__
);
269 sdio_claim_host(card
->func
);
271 ret
= sdio_writesb(card
->func
, ioport
, buffer
, blk_cnt
* blk_size
);
273 sdio_release_host(card
->func
);
278 /* This function reads multiple data from SDIO card memory.
280 static int mwifiex_read_data_sync(struct mwifiex_adapter
*adapter
, u8
*buffer
,
281 u32 len
, u32 port
, u8 claim
)
283 struct sdio_mmc_card
*card
= adapter
->card
;
285 u8 blk_mode
= (port
& MWIFIEX_SDIO_BYTE_MODE_MASK
) ? BYTE_MODE
287 u32 blk_size
= (blk_mode
== BLOCK_MODE
) ? MWIFIEX_SDIO_BLOCK_SIZE
: 1;
288 u32 blk_cnt
= (blk_mode
== BLOCK_MODE
) ? (len
/ MWIFIEX_SDIO_BLOCK_SIZE
)
290 u32 ioport
= (port
& MWIFIEX_SDIO_IO_PORT_MASK
);
293 sdio_claim_host(card
->func
);
295 ret
= sdio_readsb(card
->func
, buffer
, ioport
, blk_cnt
* blk_size
);
298 sdio_release_host(card
->func
);
303 /* This function reads the firmware status.
306 mwifiex_sdio_read_fw_status(struct mwifiex_adapter
*adapter
, u16
*dat
)
308 struct sdio_mmc_card
*card
= adapter
->card
;
309 const struct mwifiex_sdio_card_reg
*reg
= card
->reg
;
312 if (mwifiex_read_reg(adapter
, reg
->status_reg_0
, &fws0
))
315 if (mwifiex_read_reg(adapter
, reg
->status_reg_1
, &fws1
))
318 *dat
= (u16
)((fws1
<< 8) | fws0
);
322 /* This function checks the firmware status in card.
324 static int mwifiex_check_fw_status(struct mwifiex_adapter
*adapter
,
331 for (tries
= 0; tries
< poll_num
; tries
++) {
332 ret
= mwifiex_sdio_read_fw_status(adapter
, &firmware_stat
);
335 if (firmware_stat
== FIRMWARE_READY_SDIO
) {
347 /* This function checks if WLAN is the winner.
349 static int mwifiex_check_winner_status(struct mwifiex_adapter
*adapter
)
353 struct sdio_mmc_card
*card
= adapter
->card
;
355 if (mwifiex_read_reg(adapter
, card
->reg
->status_reg_0
, &winner
))
369 * This function removes the interface and frees up the card structure.
372 mwifiex_sdio_remove(struct sdio_func
*func
)
374 struct sdio_mmc_card
*card
;
375 struct mwifiex_adapter
*adapter
;
376 struct mwifiex_private
*priv
;
380 card
= sdio_get_drvdata(func
);
384 wait_for_completion(&card
->fw_done
);
386 adapter
= card
->adapter
;
387 if (!adapter
|| !adapter
->priv_num
)
390 mwifiex_dbg(adapter
, INFO
, "info: SDIO func num=%d\n", func
->num
);
392 ret
= mwifiex_sdio_read_fw_status(adapter
, &firmware_stat
);
393 if (!ret
&& firmware_stat
== FIRMWARE_READY_SDIO
&&
394 !adapter
->mfg_mode
) {
395 mwifiex_deauthenticate_all(adapter
);
397 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
398 mwifiex_disable_auto_ds(priv
);
399 mwifiex_init_shutdown_fw(priv
, MWIFIEX_FUNC_SHUTDOWN
);
402 mwifiex_remove_card(adapter
);
408 * Kernel needs to suspend all functions separately. Therefore all
409 * registered functions must have drivers with suspend and resume
410 * methods. Failing that the kernel simply removes the whole card.
412 * If already not suspended, this function allocates and sends a host
413 * sleep activate request to the firmware and turns off the traffic.
415 static int mwifiex_sdio_suspend(struct device
*dev
)
417 struct sdio_func
*func
= dev_to_sdio_func(dev
);
418 struct sdio_mmc_card
*card
;
419 struct mwifiex_adapter
*adapter
;
420 mmc_pm_flag_t pm_flag
= 0;
423 pm_flag
= sdio_get_host_pm_caps(func
);
424 pr_debug("cmd: %s: suspend: PM flag = 0x%x\n",
425 sdio_func_id(func
), pm_flag
);
426 if (!(pm_flag
& MMC_PM_KEEP_POWER
)) {
427 dev_err(dev
, "%s: cannot remain alive while host is"
428 " suspended\n", sdio_func_id(func
));
432 card
= sdio_get_drvdata(func
);
434 dev_err(dev
, "suspend: invalid card\n");
438 /* Might still be loading firmware */
439 wait_for_completion(&card
->fw_done
);
441 adapter
= card
->adapter
;
443 dev_err(dev
, "adapter is not valid\n");
450 mwifiex_enable_wake(adapter
);
452 /* Enable the Host Sleep */
453 if (!mwifiex_enable_hs(adapter
)) {
454 mwifiex_dbg(adapter
, ERROR
,
455 "cmd: failed to suspend\n");
456 clear_bit(MWIFIEX_IS_HS_ENABLING
, &adapter
->work_flags
);
457 mwifiex_disable_wake(adapter
);
461 mwifiex_dbg(adapter
, INFO
,
462 "cmd: suspend with MMC_PM_KEEP_POWER\n");
463 ret
= sdio_set_host_pm_flags(func
, MMC_PM_KEEP_POWER
);
465 /* Indicate device suspended */
466 set_bit(MWIFIEX_IS_SUSPENDED
, &adapter
->work_flags
);
467 clear_bit(MWIFIEX_IS_HS_ENABLING
, &adapter
->work_flags
);
472 static void mwifiex_sdio_coredump(struct device
*dev
)
474 struct sdio_func
*func
= dev_to_sdio_func(dev
);
475 struct sdio_mmc_card
*card
;
477 card
= sdio_get_drvdata(func
);
478 if (!test_and_set_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP
,
480 schedule_work(&card
->work
);
483 /* Device ID for SD8786 */
484 #define SDIO_DEVICE_ID_MARVELL_8786 (0x9116)
485 /* Device ID for SD8787 */
486 #define SDIO_DEVICE_ID_MARVELL_8787 (0x9119)
487 /* Device ID for SD8797 */
488 #define SDIO_DEVICE_ID_MARVELL_8797 (0x9129)
489 /* Device ID for SD8897 */
490 #define SDIO_DEVICE_ID_MARVELL_8897 (0x912d)
491 /* Device ID for SD8887 */
492 #define SDIO_DEVICE_ID_MARVELL_8887 (0x9135)
493 /* Device ID for SD8801 */
494 #define SDIO_DEVICE_ID_MARVELL_8801 (0x9139)
495 /* Device ID for SD8977 */
496 #define SDIO_DEVICE_ID_MARVELL_8977 (0x9145)
497 /* Device ID for SD8987 */
498 #define SDIO_DEVICE_ID_MARVELL_8987 (0x9149)
499 /* Device ID for SD8997 */
500 #define SDIO_DEVICE_ID_MARVELL_8997 (0x9141)
504 static const struct sdio_device_id mwifiex_ids
[] = {
505 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8786
),
506 .driver_data
= (unsigned long) &mwifiex_sdio_sd8786
},
507 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8787
),
508 .driver_data
= (unsigned long) &mwifiex_sdio_sd8787
},
509 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8797
),
510 .driver_data
= (unsigned long) &mwifiex_sdio_sd8797
},
511 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8897
),
512 .driver_data
= (unsigned long) &mwifiex_sdio_sd8897
},
513 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8887
),
514 .driver_data
= (unsigned long)&mwifiex_sdio_sd8887
},
515 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8801
),
516 .driver_data
= (unsigned long)&mwifiex_sdio_sd8801
},
517 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8977
),
518 .driver_data
= (unsigned long)&mwifiex_sdio_sd8977
},
519 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8987
),
520 .driver_data
= (unsigned long)&mwifiex_sdio_sd8987
},
521 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8997
),
522 .driver_data
= (unsigned long)&mwifiex_sdio_sd8997
},
526 MODULE_DEVICE_TABLE(sdio
, mwifiex_ids
);
528 static const struct dev_pm_ops mwifiex_sdio_pm_ops
= {
529 .suspend
= mwifiex_sdio_suspend
,
530 .resume
= mwifiex_sdio_resume
,
533 static struct sdio_driver mwifiex_sdio
= {
534 .name
= "mwifiex_sdio",
535 .id_table
= mwifiex_ids
,
536 .probe
= mwifiex_sdio_probe
,
537 .remove
= mwifiex_sdio_remove
,
539 .owner
= THIS_MODULE
,
540 .coredump
= mwifiex_sdio_coredump
,
541 .pm
= &mwifiex_sdio_pm_ops
,
546 * This function wakes up the card.
548 * A host power up command is written to the card configuration
549 * register to wake up the card.
551 static int mwifiex_pm_wakeup_card(struct mwifiex_adapter
*adapter
)
553 mwifiex_dbg(adapter
, EVENT
,
554 "event: wakeup device...\n");
556 return mwifiex_write_reg(adapter
, CONFIGURATION_REG
, HOST_POWER_UP
);
560 * This function is called after the card has woken up.
562 * The card configuration register is reset.
564 static int mwifiex_pm_wakeup_card_complete(struct mwifiex_adapter
*adapter
)
566 mwifiex_dbg(adapter
, EVENT
,
567 "cmd: wakeup device completed\n");
569 return mwifiex_write_reg(adapter
, CONFIGURATION_REG
, 0);
572 static int mwifiex_sdio_dnld_fw(struct mwifiex_adapter
*adapter
,
573 struct mwifiex_fw_image
*fw
)
575 struct sdio_mmc_card
*card
= adapter
->card
;
578 sdio_claim_host(card
->func
);
579 ret
= mwifiex_dnld_fw(adapter
, fw
);
580 sdio_release_host(card
->func
);
586 * This function is used to initialize IO ports for the
587 * chipsets supporting SDIO new mode eg SD8897.
589 static int mwifiex_init_sdio_new_mode(struct mwifiex_adapter
*adapter
)
592 struct sdio_mmc_card
*card
= adapter
->card
;
594 adapter
->ioport
= MEM_PORT
;
596 /* enable sdio new mode */
597 if (mwifiex_read_reg(adapter
, card
->reg
->card_cfg_2_1_reg
, ®
))
599 if (mwifiex_write_reg(adapter
, card
->reg
->card_cfg_2_1_reg
,
600 reg
| CMD53_NEW_MODE
))
603 /* Configure cmd port and enable reading rx length from the register */
604 if (mwifiex_read_reg(adapter
, card
->reg
->cmd_cfg_0
, ®
))
606 if (mwifiex_write_reg(adapter
, card
->reg
->cmd_cfg_0
,
607 reg
| CMD_PORT_RD_LEN_EN
))
610 /* Enable Dnld/Upld ready auto reset for cmd port after cmd53 is
613 if (mwifiex_read_reg(adapter
, card
->reg
->cmd_cfg_1
, ®
))
615 if (mwifiex_write_reg(adapter
, card
->reg
->cmd_cfg_1
,
616 reg
| CMD_PORT_AUTO_EN
))
622 /* This function initializes the IO ports.
624 * The following operations are performed -
625 * - Read the IO ports (0, 1 and 2)
626 * - Set host interrupt Reset-To-Read to clear
627 * - Set auto re-enable interrupt
629 static int mwifiex_init_sdio_ioport(struct mwifiex_adapter
*adapter
)
632 struct sdio_mmc_card
*card
= adapter
->card
;
636 if (card
->supports_sdio_new_mode
) {
637 if (mwifiex_init_sdio_new_mode(adapter
))
642 /* Read the IO port */
643 if (!mwifiex_read_reg(adapter
, card
->reg
->io_port_0_reg
, ®
))
644 adapter
->ioport
|= (reg
& 0xff);
648 if (!mwifiex_read_reg(adapter
, card
->reg
->io_port_1_reg
, ®
))
649 adapter
->ioport
|= ((reg
& 0xff) << 8);
653 if (!mwifiex_read_reg(adapter
, card
->reg
->io_port_2_reg
, ®
))
654 adapter
->ioport
|= ((reg
& 0xff) << 16);
658 mwifiex_dbg(adapter
, INFO
,
659 "info: SDIO FUNC1 IO port: %#x\n", adapter
->ioport
);
661 /* Set Host interrupt reset to read to clear */
662 if (!mwifiex_read_reg(adapter
, card
->reg
->host_int_rsr_reg
, ®
))
663 mwifiex_write_reg(adapter
, card
->reg
->host_int_rsr_reg
,
664 reg
| card
->reg
->sdio_int_mask
);
668 /* Dnld/Upld ready set to auto reset */
669 if (!mwifiex_read_reg(adapter
, card
->reg
->card_misc_cfg_reg
, ®
))
670 mwifiex_write_reg(adapter
, card
->reg
->card_misc_cfg_reg
,
671 reg
| AUTO_RE_ENABLE_INT
);
679 * This function sends data to the card.
681 static int mwifiex_write_data_to_card(struct mwifiex_adapter
*adapter
,
682 u8
*payload
, u32 pkt_len
, u32 port
)
688 ret
= mwifiex_write_data_sync(adapter
, payload
, pkt_len
, port
);
691 mwifiex_dbg(adapter
, ERROR
,
692 "host_to_card, write iomem\t"
693 "(%d) failed: %d\n", i
, ret
);
694 if (mwifiex_write_reg(adapter
, CONFIGURATION_REG
, 0x04))
695 mwifiex_dbg(adapter
, ERROR
,
696 "write CFG reg failed\n");
699 if (i
> MAX_WRITE_IOMEM_RETRY
)
708 * This function gets the read port.
710 * If control port bit is set in MP read bitmap, the control port
711 * is returned, otherwise the current read port is returned and
712 * the value is increased (provided it does not reach the maximum
713 * limit, in which case it is reset to 1)
715 static int mwifiex_get_rd_port(struct mwifiex_adapter
*adapter
, u8
*port
)
717 struct sdio_mmc_card
*card
= adapter
->card
;
718 const struct mwifiex_sdio_card_reg
*reg
= card
->reg
;
719 u32 rd_bitmap
= card
->mp_rd_bitmap
;
721 mwifiex_dbg(adapter
, DATA
,
722 "data: mp_rd_bitmap=0x%08x\n", rd_bitmap
);
724 if (card
->supports_sdio_new_mode
) {
725 if (!(rd_bitmap
& reg
->data_port_mask
))
728 if (!(rd_bitmap
& (CTRL_PORT_MASK
| reg
->data_port_mask
)))
732 if ((card
->has_control_mask
) &&
733 (card
->mp_rd_bitmap
& CTRL_PORT_MASK
)) {
734 card
->mp_rd_bitmap
&= (u32
) (~CTRL_PORT_MASK
);
736 mwifiex_dbg(adapter
, DATA
,
737 "data: port=%d mp_rd_bitmap=0x%08x\n",
738 *port
, card
->mp_rd_bitmap
);
742 if (!(card
->mp_rd_bitmap
& (1 << card
->curr_rd_port
)))
745 /* We are now handling the SDIO data ports */
746 card
->mp_rd_bitmap
&= (u32
)(~(1 << card
->curr_rd_port
));
747 *port
= card
->curr_rd_port
;
749 if (++card
->curr_rd_port
== card
->max_ports
)
750 card
->curr_rd_port
= reg
->start_rd_port
;
752 mwifiex_dbg(adapter
, DATA
,
753 "data: port=%d mp_rd_bitmap=0x%08x -> 0x%08x\n",
754 *port
, rd_bitmap
, card
->mp_rd_bitmap
);
760 * This function gets the write port for data.
762 * The current write port is returned if available and the value is
763 * increased (provided it does not reach the maximum limit, in which
764 * case it is reset to 1)
766 static int mwifiex_get_wr_port_data(struct mwifiex_adapter
*adapter
, u32
*port
)
768 struct sdio_mmc_card
*card
= adapter
->card
;
769 const struct mwifiex_sdio_card_reg
*reg
= card
->reg
;
770 u32 wr_bitmap
= card
->mp_wr_bitmap
;
772 mwifiex_dbg(adapter
, DATA
,
773 "data: mp_wr_bitmap=0x%08x\n", wr_bitmap
);
775 if (!(wr_bitmap
& card
->mp_data_port_mask
)) {
776 adapter
->data_sent
= true;
780 if (card
->mp_wr_bitmap
& (1 << card
->curr_wr_port
)) {
781 card
->mp_wr_bitmap
&= (u32
) (~(1 << card
->curr_wr_port
));
782 *port
= card
->curr_wr_port
;
783 if (++card
->curr_wr_port
== card
->mp_end_port
)
784 card
->curr_wr_port
= reg
->start_wr_port
;
786 adapter
->data_sent
= true;
790 if ((card
->has_control_mask
) && (*port
== CTRL_PORT
)) {
791 mwifiex_dbg(adapter
, ERROR
,
792 "invalid data port=%d cur port=%d mp_wr_bitmap=0x%08x -> 0x%08x\n",
793 *port
, card
->curr_wr_port
, wr_bitmap
,
798 mwifiex_dbg(adapter
, DATA
,
799 "data: port=%d mp_wr_bitmap=0x%08x -> 0x%08x\n",
800 *port
, wr_bitmap
, card
->mp_wr_bitmap
);
806 * This function polls the card status.
809 mwifiex_sdio_poll_card_status(struct mwifiex_adapter
*adapter
, u8 bits
)
811 struct sdio_mmc_card
*card
= adapter
->card
;
815 for (tries
= 0; tries
< MAX_POLL_TRIES
; tries
++) {
816 if (mwifiex_read_reg(adapter
, card
->reg
->poll_reg
, &cs
))
818 else if ((cs
& bits
) == bits
)
821 usleep_range(10, 20);
824 mwifiex_dbg(adapter
, ERROR
,
825 "poll card status failed, tries = %d\n", tries
);
831 * This function disables the host interrupt.
833 * The host interrupt mask is read, the disable bit is reset and
834 * written back to the card host interrupt mask register.
836 static void mwifiex_sdio_disable_host_int(struct mwifiex_adapter
*adapter
)
838 struct sdio_mmc_card
*card
= adapter
->card
;
839 struct sdio_func
*func
= card
->func
;
841 sdio_claim_host(func
);
842 mwifiex_write_reg_locked(func
, card
->reg
->host_int_mask_reg
, 0);
843 sdio_release_irq(func
);
844 sdio_release_host(func
);
848 * This function reads the interrupt status from card.
850 static void mwifiex_interrupt_status(struct mwifiex_adapter
*adapter
)
852 struct sdio_mmc_card
*card
= adapter
->card
;
856 if (mwifiex_read_data_sync(adapter
, card
->mp_regs
,
857 card
->reg
->max_mp_regs
,
858 REG_PORT
| MWIFIEX_SDIO_BYTE_MODE_MASK
, 0)) {
859 mwifiex_dbg(adapter
, ERROR
, "read mp_regs failed\n");
863 sdio_ireg
= card
->mp_regs
[card
->reg
->host_int_status_reg
];
866 * DN_LD_HOST_INT_STATUS and/or UP_LD_HOST_INT_STATUS
867 * For SDIO new mode CMD port interrupts
868 * DN_LD_CMD_PORT_HOST_INT_STATUS and/or
869 * UP_LD_CMD_PORT_HOST_INT_STATUS
870 * Clear the interrupt status register
872 mwifiex_dbg(adapter
, INTR
,
873 "int: sdio_ireg = %#x\n", sdio_ireg
);
874 spin_lock_irqsave(&adapter
->int_lock
, flags
);
875 adapter
->int_status
|= sdio_ireg
;
876 spin_unlock_irqrestore(&adapter
->int_lock
, flags
);
881 * SDIO interrupt handler.
883 * This function reads the interrupt status from firmware and handles
884 * the interrupt in current thread (ksdioirqd) right away.
887 mwifiex_sdio_interrupt(struct sdio_func
*func
)
889 struct mwifiex_adapter
*adapter
;
890 struct sdio_mmc_card
*card
;
892 card
= sdio_get_drvdata(func
);
893 if (!card
|| !card
->adapter
) {
894 pr_err("int: func=%p card=%p adapter=%p\n",
895 func
, card
, card
? card
->adapter
: NULL
);
898 adapter
= card
->adapter
;
900 if (!adapter
->pps_uapsd_mode
&& adapter
->ps_state
== PS_STATE_SLEEP
)
901 adapter
->ps_state
= PS_STATE_AWAKE
;
903 mwifiex_interrupt_status(adapter
);
904 mwifiex_main_process(adapter
);
908 * This function enables the host interrupt.
910 * The host interrupt enable mask is written to the card
911 * host interrupt mask register.
913 static int mwifiex_sdio_enable_host_int(struct mwifiex_adapter
*adapter
)
915 struct sdio_mmc_card
*card
= adapter
->card
;
916 struct sdio_func
*func
= card
->func
;
919 sdio_claim_host(func
);
921 /* Request the SDIO IRQ */
922 ret
= sdio_claim_irq(func
, mwifiex_sdio_interrupt
);
924 mwifiex_dbg(adapter
, ERROR
,
925 "claim irq failed: ret=%d\n", ret
);
929 /* Simply write the mask to the register */
930 ret
= mwifiex_write_reg_locked(func
, card
->reg
->host_int_mask_reg
,
931 card
->reg
->host_int_enable
);
933 mwifiex_dbg(adapter
, ERROR
,
934 "enable host interrupt failed\n");
935 sdio_release_irq(func
);
939 sdio_release_host(func
);
944 * This function sends a data buffer to the card.
946 static int mwifiex_sdio_card_to_host(struct mwifiex_adapter
*adapter
,
947 u32
*type
, u8
*buffer
,
948 u32 npayload
, u32 ioport
)
954 mwifiex_dbg(adapter
, ERROR
,
955 "%s: buffer is NULL\n", __func__
);
959 ret
= mwifiex_read_data_sync(adapter
, buffer
, npayload
, ioport
, 1);
962 mwifiex_dbg(adapter
, ERROR
,
963 "%s: read iomem failed: %d\n", __func__
,
968 nb
= get_unaligned_le16((buffer
));
970 mwifiex_dbg(adapter
, ERROR
,
971 "%s: invalid packet, nb=%d npayload=%d\n",
972 __func__
, nb
, npayload
);
976 *type
= get_unaligned_le16((buffer
+ 2));
982 * This function downloads the firmware to the card.
984 * Firmware is downloaded to the card in blocks. Every block download
985 * is tested for CRC errors, and retried a number of times before
988 static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter
*adapter
,
989 struct mwifiex_fw_image
*fw
)
991 struct sdio_mmc_card
*card
= adapter
->card
;
992 const struct mwifiex_sdio_card_reg
*reg
= card
->reg
;
994 u8
*firmware
= fw
->fw_buf
;
995 u32 firmware_len
= fw
->fw_len
;
1000 u32 txlen
, tx_blocks
= 0, tries
;
1003 if (!firmware_len
) {
1004 mwifiex_dbg(adapter
, ERROR
,
1005 "firmware image not found! Terminating download\n");
1009 mwifiex_dbg(adapter
, INFO
,
1010 "info: downloading FW image (%d bytes)\n",
1013 /* Assume that the allocated buffer is 8-byte aligned */
1014 fwbuf
= kzalloc(MWIFIEX_UPLD_SIZE
, GFP_KERNEL
);
1018 sdio_claim_host(card
->func
);
1020 /* Perform firmware data transfer */
1022 /* The host polls for the DN_LD_CARD_RDY and CARD_IO_READY
1024 ret
= mwifiex_sdio_poll_card_status(adapter
, CARD_IO_READY
|
1027 mwifiex_dbg(adapter
, ERROR
,
1028 "FW download with helper:\t"
1029 "poll status timeout @ %d\n", offset
);
1034 if (offset
>= firmware_len
)
1037 for (tries
= 0; tries
< MAX_POLL_TRIES
; tries
++) {
1038 ret
= mwifiex_read_reg(adapter
, reg
->base_0_reg
,
1041 mwifiex_dbg(adapter
, ERROR
,
1042 "dev BASE0 register read failed:\t"
1043 "base0=%#04X(%d). Terminating dnld\n",
1047 ret
= mwifiex_read_reg(adapter
, reg
->base_1_reg
,
1050 mwifiex_dbg(adapter
, ERROR
,
1051 "dev BASE1 register read failed:\t"
1052 "base1=%#04X(%d). Terminating dnld\n",
1056 len
= (u16
) (((base1
& 0xff) << 8) | (base0
& 0xff));
1061 usleep_range(10, 20);
1066 } else if (len
> MWIFIEX_UPLD_SIZE
) {
1067 mwifiex_dbg(adapter
, ERROR
,
1068 "FW dnld failed @ %d, invalid length %d\n",
1078 if (i
> MAX_WRITE_IOMEM_RETRY
) {
1079 mwifiex_dbg(adapter
, ERROR
,
1080 "FW dnld failed @ %d, over max retry\n",
1085 mwifiex_dbg(adapter
, ERROR
,
1086 "CRC indicated by the helper:\t"
1087 "len = 0x%04X, txlen = %d\n", len
, txlen
);
1089 /* Setting this to 0 to resend from same offset */
1094 /* Set blocksize to transfer - checking for last
1096 if (firmware_len
- offset
< txlen
)
1097 txlen
= firmware_len
- offset
;
1099 tx_blocks
= (txlen
+ MWIFIEX_SDIO_BLOCK_SIZE
- 1)
1100 / MWIFIEX_SDIO_BLOCK_SIZE
;
1102 /* Copy payload to buffer */
1103 memmove(fwbuf
, &firmware
[offset
], txlen
);
1106 ret
= mwifiex_write_data_sync(adapter
, fwbuf
, tx_blocks
*
1107 MWIFIEX_SDIO_BLOCK_SIZE
,
1110 mwifiex_dbg(adapter
, ERROR
,
1111 "FW download, write iomem (%d) failed @ %d\n",
1113 if (mwifiex_write_reg(adapter
, CONFIGURATION_REG
, 0x04))
1114 mwifiex_dbg(adapter
, ERROR
,
1115 "write CFG reg failed\n");
1124 mwifiex_dbg(adapter
, MSG
,
1125 "info: FW download over, size %d bytes\n", offset
);
1129 sdio_release_host(card
->func
);
1135 * This function decode sdio aggreation pkt.
1137 * Based on the the data block size and pkt_len,
1138 * skb data will be decoded to few packets.
1140 static void mwifiex_deaggr_sdio_pkt(struct mwifiex_adapter
*adapter
,
1141 struct sk_buff
*skb
)
1143 u32 total_pkt_len
, pkt_len
;
1144 struct sk_buff
*skb_deaggr
;
1150 total_pkt_len
= skb
->len
;
1152 while (total_pkt_len
>= (SDIO_HEADER_OFFSET
+ adapter
->intf_hdr_len
)) {
1153 if (total_pkt_len
< adapter
->sdio_rx_block_size
)
1155 blk_num
= *(data
+ BLOCK_NUMBER_OFFSET
);
1156 blk_size
= adapter
->sdio_rx_block_size
* blk_num
;
1157 if (blk_size
> total_pkt_len
) {
1158 mwifiex_dbg(adapter
, ERROR
,
1159 "%s: error in blk_size,\t"
1160 "blk_num=%d, blk_size=%d, total_pkt_len=%d\n",
1161 __func__
, blk_num
, blk_size
, total_pkt_len
);
1164 pkt_len
= get_unaligned_le16((data
+
1165 SDIO_HEADER_OFFSET
));
1166 if ((pkt_len
+ SDIO_HEADER_OFFSET
) > blk_size
) {
1167 mwifiex_dbg(adapter
, ERROR
,
1168 "%s: error in pkt_len,\t"
1169 "pkt_len=%d, blk_size=%d\n",
1170 __func__
, pkt_len
, blk_size
);
1174 skb_deaggr
= mwifiex_alloc_dma_align_buf(pkt_len
, GFP_KERNEL
);
1177 skb_put(skb_deaggr
, pkt_len
);
1178 memcpy(skb_deaggr
->data
, data
+ SDIO_HEADER_OFFSET
, pkt_len
);
1179 skb_pull(skb_deaggr
, adapter
->intf_hdr_len
);
1181 mwifiex_handle_rx_packet(adapter
, skb_deaggr
);
1183 total_pkt_len
-= blk_size
;
1188 * This function decodes a received packet.
1190 * Based on the type, the packet is treated as either a data, or
1191 * a command response, or an event, and the correct handler
1192 * function is invoked.
1194 static int mwifiex_decode_rx_packet(struct mwifiex_adapter
*adapter
,
1195 struct sk_buff
*skb
, u32 upld_typ
)
1199 struct mwifiex_rxinfo
*rx_info
;
1201 pkt_len
= get_unaligned_le16(skb
->data
);
1203 if (upld_typ
!= MWIFIEX_TYPE_AGGR_DATA
) {
1204 skb_trim(skb
, pkt_len
);
1205 skb_pull(skb
, adapter
->intf_hdr_len
);
1209 case MWIFIEX_TYPE_AGGR_DATA
:
1210 mwifiex_dbg(adapter
, INFO
,
1211 "info: --- Rx: Aggr Data packet ---\n");
1212 rx_info
= MWIFIEX_SKB_RXCB(skb
);
1213 rx_info
->buf_type
= MWIFIEX_TYPE_AGGR_DATA
;
1214 if (adapter
->rx_work_enabled
) {
1215 skb_queue_tail(&adapter
->rx_data_q
, skb
);
1216 atomic_inc(&adapter
->rx_pending
);
1217 adapter
->data_received
= true;
1219 mwifiex_deaggr_sdio_pkt(adapter
, skb
);
1220 dev_kfree_skb_any(skb
);
1224 case MWIFIEX_TYPE_DATA
:
1225 mwifiex_dbg(adapter
, DATA
,
1226 "info: --- Rx: Data packet ---\n");
1227 if (adapter
->rx_work_enabled
) {
1228 skb_queue_tail(&adapter
->rx_data_q
, skb
);
1229 adapter
->data_received
= true;
1230 atomic_inc(&adapter
->rx_pending
);
1232 mwifiex_handle_rx_packet(adapter
, skb
);
1236 case MWIFIEX_TYPE_CMD
:
1237 mwifiex_dbg(adapter
, CMD
,
1238 "info: --- Rx: Cmd Response ---\n");
1239 /* take care of curr_cmd = NULL case */
1240 if (!adapter
->curr_cmd
) {
1241 cmd_buf
= adapter
->upld_buf
;
1243 if (adapter
->ps_state
== PS_STATE_SLEEP_CFM
)
1244 mwifiex_process_sleep_confirm_resp(adapter
,
1248 memcpy(cmd_buf
, skb
->data
,
1249 min_t(u32
, MWIFIEX_SIZE_OF_CMD_BUFFER
,
1252 dev_kfree_skb_any(skb
);
1254 adapter
->cmd_resp_received
= true;
1255 adapter
->curr_cmd
->resp_skb
= skb
;
1259 case MWIFIEX_TYPE_EVENT
:
1260 mwifiex_dbg(adapter
, EVENT
,
1261 "info: --- Rx: Event ---\n");
1262 adapter
->event_cause
= get_unaligned_le32(skb
->data
);
1264 if ((skb
->len
> 0) && (skb
->len
< MAX_EVENT_SIZE
))
1265 memcpy(adapter
->event_body
,
1266 skb
->data
+ MWIFIEX_EVENT_HEADER_LEN
,
1269 /* event cause has been saved to adapter->event_cause */
1270 adapter
->event_received
= true;
1271 adapter
->event_skb
= skb
;
1276 mwifiex_dbg(adapter
, ERROR
,
1277 "unknown upload type %#x\n", upld_typ
);
1278 dev_kfree_skb_any(skb
);
1286 * This function transfers received packets from card to driver, performing
1287 * aggregation if required.
1289 * For data received on control port, or if aggregation is disabled, the
1290 * received buffers are uploaded as separate packets. However, if aggregation
1291 * is enabled and required, the buffers are copied onto an aggregation buffer,
1292 * provided there is space left, processed and finally uploaded.
1294 static int mwifiex_sdio_card_to_host_mp_aggr(struct mwifiex_adapter
*adapter
,
1295 u16 rx_len
, u8 port
)
1297 struct sdio_mmc_card
*card
= adapter
->card
;
1298 s32 f_do_rx_aggr
= 0;
1299 s32 f_do_rx_cur
= 0;
1301 s32 f_post_aggr_cur
= 0;
1302 struct sk_buff
*skb_deaggr
;
1303 struct sk_buff
*skb
= NULL
;
1304 u32 pkt_len
, pkt_type
, mport
, pind
;
1307 if ((card
->has_control_mask
) && (port
== CTRL_PORT
)) {
1308 /* Read the command Resp without aggr */
1309 mwifiex_dbg(adapter
, CMD
,
1310 "info: %s: no aggregation for cmd\t"
1311 "response\n", __func__
);
1314 goto rx_curr_single
;
1317 if (!card
->mpa_rx
.enabled
) {
1318 mwifiex_dbg(adapter
, WARN
,
1319 "info: %s: rx aggregation disabled\n",
1323 goto rx_curr_single
;
1326 if ((!card
->has_control_mask
&& (card
->mp_rd_bitmap
&
1327 card
->reg
->data_port_mask
)) ||
1328 (card
->has_control_mask
&& (card
->mp_rd_bitmap
&
1329 (~((u32
) CTRL_PORT_MASK
))))) {
1330 /* Some more data RX pending */
1331 mwifiex_dbg(adapter
, INFO
,
1332 "info: %s: not last packet\n", __func__
);
1334 if (MP_RX_AGGR_IN_PROGRESS(card
)) {
1335 if (MP_RX_AGGR_BUF_HAS_ROOM(card
, rx_len
)) {
1338 /* No room in Aggr buf, do rx aggr now */
1340 f_post_aggr_cur
= 1;
1343 /* Rx aggr not in progress */
1348 /* No more data RX pending */
1349 mwifiex_dbg(adapter
, INFO
,
1350 "info: %s: last packet\n", __func__
);
1352 if (MP_RX_AGGR_IN_PROGRESS(card
)) {
1354 if (MP_RX_AGGR_BUF_HAS_ROOM(card
, rx_len
))
1357 /* No room in Aggr buf, do rx aggr now */
1365 mwifiex_dbg(adapter
, INFO
,
1366 "info: current packet aggregation\n");
1367 /* Curr pkt can be aggregated */
1368 mp_rx_aggr_setup(card
, rx_len
, port
);
1370 if (MP_RX_AGGR_PKT_LIMIT_REACHED(card
) ||
1371 mp_rx_aggr_port_limit_reached(card
)) {
1372 mwifiex_dbg(adapter
, INFO
,
1373 "info: %s: aggregated packet\t"
1374 "limit reached\n", __func__
);
1375 /* No more pkts allowed in Aggr buf, rx it */
1381 /* do aggr RX now */
1382 mwifiex_dbg(adapter
, DATA
,
1383 "info: do_rx_aggr: num of packets: %d\n",
1384 card
->mpa_rx
.pkt_cnt
);
1386 if (card
->supports_sdio_new_mode
) {
1390 for (i
= 0, port_count
= 0; i
< card
->max_ports
; i
++)
1391 if (card
->mpa_rx
.ports
& BIT(i
))
1394 /* Reading data from "start_port + 0" to "start_port +
1395 * port_count -1", so decrease the count by 1
1398 mport
= (adapter
->ioport
| SDIO_MPA_ADDR_BASE
|
1399 (port_count
<< 8)) + card
->mpa_rx
.start_port
;
1401 mport
= (adapter
->ioport
| SDIO_MPA_ADDR_BASE
|
1402 (card
->mpa_rx
.ports
<< 4)) +
1403 card
->mpa_rx
.start_port
;
1406 if (card
->mpa_rx
.pkt_cnt
== 1)
1407 mport
= adapter
->ioport
+ card
->mpa_rx
.start_port
;
1409 if (mwifiex_read_data_sync(adapter
, card
->mpa_rx
.buf
,
1410 card
->mpa_rx
.buf_len
, mport
, 1))
1413 curr_ptr
= card
->mpa_rx
.buf
;
1415 for (pind
= 0; pind
< card
->mpa_rx
.pkt_cnt
; pind
++) {
1416 u32
*len_arr
= card
->mpa_rx
.len_arr
;
1418 /* get curr PKT len & type */
1419 pkt_len
= get_unaligned_le16(&curr_ptr
[0]);
1420 pkt_type
= get_unaligned_le16(&curr_ptr
[2]);
1422 /* copy pkt to deaggr buf */
1423 skb_deaggr
= mwifiex_alloc_dma_align_buf(len_arr
[pind
],
1426 mwifiex_dbg(adapter
, ERROR
, "skb allocation failure\t"
1427 "drop pkt len=%d type=%d\n",
1429 curr_ptr
+= len_arr
[pind
];
1433 skb_put(skb_deaggr
, len_arr
[pind
]);
1435 if ((pkt_type
== MWIFIEX_TYPE_DATA
||
1436 (pkt_type
== MWIFIEX_TYPE_AGGR_DATA
&&
1437 adapter
->sdio_rx_aggr_enable
)) &&
1438 (pkt_len
<= len_arr
[pind
])) {
1440 memcpy(skb_deaggr
->data
, curr_ptr
, pkt_len
);
1442 skb_trim(skb_deaggr
, pkt_len
);
1444 /* Process de-aggr packet */
1445 mwifiex_decode_rx_packet(adapter
, skb_deaggr
,
1448 mwifiex_dbg(adapter
, ERROR
,
1449 "drop wrong aggr pkt:\t"
1450 "sdio_single_port_rx_aggr=%d\t"
1451 "type=%d len=%d max_len=%d\n",
1452 adapter
->sdio_rx_aggr_enable
,
1453 pkt_type
, pkt_len
, len_arr
[pind
]);
1454 dev_kfree_skb_any(skb_deaggr
);
1456 curr_ptr
+= len_arr
[pind
];
1458 MP_RX_AGGR_BUF_RESET(card
);
1463 mwifiex_dbg(adapter
, INFO
, "info: RX: port: %d, rx_len: %d\n",
1466 skb
= mwifiex_alloc_dma_align_buf(rx_len
, GFP_KERNEL
);
1468 mwifiex_dbg(adapter
, ERROR
,
1469 "single skb allocated fail,\t"
1470 "drop pkt port=%d len=%d\n", port
, rx_len
);
1471 if (mwifiex_sdio_card_to_host(adapter
, &pkt_type
,
1472 card
->mpa_rx
.buf
, rx_len
,
1473 adapter
->ioport
+ port
))
1478 skb_put(skb
, rx_len
);
1480 if (mwifiex_sdio_card_to_host(adapter
, &pkt_type
,
1481 skb
->data
, skb
->len
,
1482 adapter
->ioport
+ port
))
1484 if (!adapter
->sdio_rx_aggr_enable
&&
1485 pkt_type
== MWIFIEX_TYPE_AGGR_DATA
) {
1486 mwifiex_dbg(adapter
, ERROR
, "drop wrong pkt type %d\t"
1487 "current SDIO RX Aggr not enabled\n",
1489 dev_kfree_skb_any(skb
);
1493 mwifiex_decode_rx_packet(adapter
, skb
, pkt_type
);
1495 if (f_post_aggr_cur
) {
1496 mwifiex_dbg(adapter
, INFO
,
1497 "info: current packet aggregation\n");
1498 /* Curr pkt can be aggregated */
1499 mp_rx_aggr_setup(card
, rx_len
, port
);
1504 if (MP_RX_AGGR_IN_PROGRESS(card
))
1505 MP_RX_AGGR_BUF_RESET(card
);
1507 if (f_do_rx_cur
&& skb
)
1508 /* Single transfer pending. Free curr buff also */
1509 dev_kfree_skb_any(skb
);
1515 * This function checks the current interrupt status.
1517 * The following interrupts are checked and handled by this function -
1520 * - Packets received
1522 * Since the firmware does not generate download ready interrupt if the
1523 * port updated is command port only, command sent interrupt checking
1524 * should be done manually, and for every SDIO interrupt.
1526 * In case of Rx packets received, the packets are uploaded from card to
1527 * host and processed accordingly.
1529 static int mwifiex_process_int_status(struct mwifiex_adapter
*adapter
)
1531 struct sdio_mmc_card
*card
= adapter
->card
;
1532 const struct mwifiex_sdio_card_reg
*reg
= card
->reg
;
1535 struct sk_buff
*skb
;
1536 u8 port
= CTRL_PORT
;
1537 u32 len_reg_l
, len_reg_u
;
1540 unsigned long flags
;
1544 spin_lock_irqsave(&adapter
->int_lock
, flags
);
1545 sdio_ireg
= adapter
->int_status
;
1546 adapter
->int_status
= 0;
1547 spin_unlock_irqrestore(&adapter
->int_lock
, flags
);
1552 /* Following interrupt is only for SDIO new mode */
1553 if (sdio_ireg
& DN_LD_CMD_PORT_HOST_INT_STATUS
&& adapter
->cmd_sent
)
1554 adapter
->cmd_sent
= false;
1556 /* Following interrupt is only for SDIO new mode */
1557 if (sdio_ireg
& UP_LD_CMD_PORT_HOST_INT_STATUS
) {
1560 /* read the len of control packet */
1561 rx_len
= card
->mp_regs
[reg
->cmd_rd_len_1
] << 8;
1562 rx_len
|= (u16
)card
->mp_regs
[reg
->cmd_rd_len_0
];
1563 rx_blocks
= DIV_ROUND_UP(rx_len
, MWIFIEX_SDIO_BLOCK_SIZE
);
1564 if (rx_len
<= adapter
->intf_hdr_len
||
1565 (rx_blocks
* MWIFIEX_SDIO_BLOCK_SIZE
) >
1566 MWIFIEX_RX_DATA_BUF_SIZE
)
1568 rx_len
= (u16
) (rx_blocks
* MWIFIEX_SDIO_BLOCK_SIZE
);
1569 mwifiex_dbg(adapter
, INFO
, "info: rx_len = %d\n", rx_len
);
1571 skb
= mwifiex_alloc_dma_align_buf(rx_len
, GFP_KERNEL
);
1575 skb_put(skb
, rx_len
);
1577 if (mwifiex_sdio_card_to_host(adapter
, &pkt_type
, skb
->data
,
1578 skb
->len
, adapter
->ioport
|
1580 mwifiex_dbg(adapter
, ERROR
,
1581 "%s: failed to card_to_host", __func__
);
1582 dev_kfree_skb_any(skb
);
1586 if ((pkt_type
!= MWIFIEX_TYPE_CMD
) &&
1587 (pkt_type
!= MWIFIEX_TYPE_EVENT
))
1588 mwifiex_dbg(adapter
, ERROR
,
1589 "%s:Received wrong packet on cmd port",
1592 mwifiex_decode_rx_packet(adapter
, skb
, pkt_type
);
1595 if (sdio_ireg
& DN_LD_HOST_INT_STATUS
) {
1596 bitmap
= (u32
) card
->mp_regs
[reg
->wr_bitmap_l
];
1597 bitmap
|= ((u32
) card
->mp_regs
[reg
->wr_bitmap_u
]) << 8;
1598 if (card
->supports_sdio_new_mode
) {
1600 ((u32
) card
->mp_regs
[reg
->wr_bitmap_1l
]) << 16;
1602 ((u32
) card
->mp_regs
[reg
->wr_bitmap_1u
]) << 24;
1604 card
->mp_wr_bitmap
= bitmap
;
1606 mwifiex_dbg(adapter
, INTR
,
1607 "int: DNLD: wr_bitmap=0x%x\n",
1608 card
->mp_wr_bitmap
);
1609 if (adapter
->data_sent
&&
1610 (card
->mp_wr_bitmap
& card
->mp_data_port_mask
)) {
1611 mwifiex_dbg(adapter
, INTR
,
1612 "info: <--- Tx DONE Interrupt --->\n");
1613 adapter
->data_sent
= false;
1617 /* As firmware will not generate download ready interrupt if the port
1618 updated is command port only, cmd_sent should be done for any SDIO
1620 if (card
->has_control_mask
&& adapter
->cmd_sent
) {
1621 /* Check if firmware has attach buffer at command port and
1622 update just that in wr_bit_map. */
1623 card
->mp_wr_bitmap
|=
1624 (u32
) card
->mp_regs
[reg
->wr_bitmap_l
] & CTRL_PORT_MASK
;
1625 if (card
->mp_wr_bitmap
& CTRL_PORT_MASK
)
1626 adapter
->cmd_sent
= false;
1629 mwifiex_dbg(adapter
, INTR
, "info: cmd_sent=%d data_sent=%d\n",
1630 adapter
->cmd_sent
, adapter
->data_sent
);
1631 if (sdio_ireg
& UP_LD_HOST_INT_STATUS
) {
1632 bitmap
= (u32
) card
->mp_regs
[reg
->rd_bitmap_l
];
1633 bitmap
|= ((u32
) card
->mp_regs
[reg
->rd_bitmap_u
]) << 8;
1634 if (card
->supports_sdio_new_mode
) {
1636 ((u32
) card
->mp_regs
[reg
->rd_bitmap_1l
]) << 16;
1638 ((u32
) card
->mp_regs
[reg
->rd_bitmap_1u
]) << 24;
1640 card
->mp_rd_bitmap
= bitmap
;
1641 mwifiex_dbg(adapter
, INTR
,
1642 "int: UPLD: rd_bitmap=0x%x\n",
1643 card
->mp_rd_bitmap
);
1646 ret
= mwifiex_get_rd_port(adapter
, &port
);
1648 mwifiex_dbg(adapter
, INFO
,
1649 "info: no more rd_port available\n");
1652 len_reg_l
= reg
->rd_len_p0_l
+ (port
<< 1);
1653 len_reg_u
= reg
->rd_len_p0_u
+ (port
<< 1);
1654 rx_len
= ((u16
) card
->mp_regs
[len_reg_u
]) << 8;
1655 rx_len
|= (u16
) card
->mp_regs
[len_reg_l
];
1656 mwifiex_dbg(adapter
, INFO
,
1657 "info: RX: port=%d rx_len=%u\n",
1660 (rx_len
+ MWIFIEX_SDIO_BLOCK_SIZE
-
1661 1) / MWIFIEX_SDIO_BLOCK_SIZE
;
1662 if (rx_len
<= adapter
->intf_hdr_len
||
1663 (card
->mpa_rx
.enabled
&&
1664 ((rx_blocks
* MWIFIEX_SDIO_BLOCK_SIZE
) >
1665 card
->mpa_rx
.buf_size
))) {
1666 mwifiex_dbg(adapter
, ERROR
,
1667 "invalid rx_len=%d\n",
1672 rx_len
= (u16
) (rx_blocks
* MWIFIEX_SDIO_BLOCK_SIZE
);
1673 mwifiex_dbg(adapter
, INFO
, "info: rx_len = %d\n",
1676 if (mwifiex_sdio_card_to_host_mp_aggr(adapter
, rx_len
,
1678 mwifiex_dbg(adapter
, ERROR
,
1679 "card_to_host_mpa failed: int status=%#x\n",
1690 if (mwifiex_read_reg(adapter
, CONFIGURATION_REG
, &cr
))
1691 mwifiex_dbg(adapter
, ERROR
, "read CFG reg failed\n");
1693 mwifiex_dbg(adapter
, INFO
,
1694 "info: CFG reg val = %d\n", cr
);
1696 if (mwifiex_write_reg(adapter
, CONFIGURATION_REG
, (cr
| 0x04)))
1697 mwifiex_dbg(adapter
, ERROR
,
1698 "write CFG reg failed\n");
1700 mwifiex_dbg(adapter
, INFO
, "info: write success\n");
1702 if (mwifiex_read_reg(adapter
, CONFIGURATION_REG
, &cr
))
1703 mwifiex_dbg(adapter
, ERROR
,
1704 "read CFG reg failed\n");
1706 mwifiex_dbg(adapter
, INFO
,
1707 "info: CFG reg val =%x\n", cr
);
1713 * This function aggregates transmission buffers in driver and downloads
1714 * the aggregated packet to card.
1716 * The individual packets are aggregated by copying into an aggregation
1717 * buffer and then downloaded to the card. Previous unsent packets in the
1718 * aggregation buffer are pre-copied first before new packets are added.
1719 * Aggregation is done till there is space left in the aggregation buffer,
1720 * or till new packets are available.
1722 * The function will only download the packet to the card when aggregation
1723 * stops, otherwise it will just aggregate the packet in aggregation buffer
1726 static int mwifiex_host_to_card_mp_aggr(struct mwifiex_adapter
*adapter
,
1727 u8
*payload
, u32 pkt_len
, u32 port
,
1730 struct sdio_mmc_card
*card
= adapter
->card
;
1732 s32 f_send_aggr_buf
= 0;
1733 s32 f_send_cur_buf
= 0;
1734 s32 f_precopy_cur_buf
= 0;
1735 s32 f_postcopy_cur_buf
= 0;
1739 if (!card
->mpa_tx
.enabled
||
1740 (card
->has_control_mask
&& (port
== CTRL_PORT
)) ||
1741 (card
->supports_sdio_new_mode
&& (port
== CMD_PORT_SLCT
))) {
1742 mwifiex_dbg(adapter
, WARN
,
1743 "info: %s: tx aggregation disabled\n",
1747 goto tx_curr_single
;
1751 /* More pkt in TX queue */
1752 mwifiex_dbg(adapter
, INFO
,
1753 "info: %s: more packets in queue.\n",
1756 if (MP_TX_AGGR_IN_PROGRESS(card
)) {
1757 if (MP_TX_AGGR_BUF_HAS_ROOM(card
, pkt_len
)) {
1758 f_precopy_cur_buf
= 1;
1760 if (!(card
->mp_wr_bitmap
&
1761 (1 << card
->curr_wr_port
)) ||
1762 !MP_TX_AGGR_BUF_HAS_ROOM(
1763 card
, pkt_len
+ next_pkt_len
))
1764 f_send_aggr_buf
= 1;
1766 /* No room in Aggr buf, send it */
1767 f_send_aggr_buf
= 1;
1769 if (!(card
->mp_wr_bitmap
&
1770 (1 << card
->curr_wr_port
)))
1773 f_postcopy_cur_buf
= 1;
1776 if (MP_TX_AGGR_BUF_HAS_ROOM(card
, pkt_len
) &&
1777 (card
->mp_wr_bitmap
& (1 << card
->curr_wr_port
)))
1778 f_precopy_cur_buf
= 1;
1783 /* Last pkt in TX queue */
1784 mwifiex_dbg(adapter
, INFO
,
1785 "info: %s: Last packet in Tx Queue.\n",
1788 if (MP_TX_AGGR_IN_PROGRESS(card
)) {
1789 /* some packs in Aggr buf already */
1790 f_send_aggr_buf
= 1;
1792 if (MP_TX_AGGR_BUF_HAS_ROOM(card
, pkt_len
))
1793 f_precopy_cur_buf
= 1;
1795 /* No room in Aggr buf, send it */
1802 if (f_precopy_cur_buf
) {
1803 mwifiex_dbg(adapter
, DATA
,
1804 "data: %s: precopy current buffer\n",
1806 MP_TX_AGGR_BUF_PUT(card
, payload
, pkt_len
, port
);
1808 if (MP_TX_AGGR_PKT_LIMIT_REACHED(card
) ||
1809 mp_tx_aggr_port_limit_reached(card
))
1810 /* No more pkts allowed in Aggr buf, send it */
1811 f_send_aggr_buf
= 1;
1814 if (f_send_aggr_buf
) {
1815 mwifiex_dbg(adapter
, DATA
,
1816 "data: %s: send aggr buffer: %d %d\n",
1817 __func__
, card
->mpa_tx
.start_port
,
1818 card
->mpa_tx
.ports
);
1819 if (card
->supports_sdio_new_mode
) {
1823 for (i
= 0, port_count
= 0; i
< card
->max_ports
; i
++)
1824 if (card
->mpa_tx
.ports
& BIT(i
))
1827 /* Writing data from "start_port + 0" to "start_port +
1828 * port_count -1", so decrease the count by 1
1831 mport
= (adapter
->ioport
| SDIO_MPA_ADDR_BASE
|
1832 (port_count
<< 8)) + card
->mpa_tx
.start_port
;
1834 mport
= (adapter
->ioport
| SDIO_MPA_ADDR_BASE
|
1835 (card
->mpa_tx
.ports
<< 4)) +
1836 card
->mpa_tx
.start_port
;
1839 if (card
->mpa_tx
.pkt_cnt
== 1)
1840 mport
= adapter
->ioport
+ card
->mpa_tx
.start_port
;
1842 ret
= mwifiex_write_data_to_card(adapter
, card
->mpa_tx
.buf
,
1843 card
->mpa_tx
.buf_len
, mport
);
1845 /* Save the last multi port tx aggreagation info to debug log */
1846 index
= adapter
->dbg
.last_sdio_mp_index
;
1847 index
= (index
+ 1) % MWIFIEX_DBG_SDIO_MP_NUM
;
1848 adapter
->dbg
.last_sdio_mp_index
= index
;
1849 adapter
->dbg
.last_mp_wr_ports
[index
] = mport
;
1850 adapter
->dbg
.last_mp_wr_bitmap
[index
] = card
->mp_wr_bitmap
;
1851 adapter
->dbg
.last_mp_wr_len
[index
] = card
->mpa_tx
.buf_len
;
1852 adapter
->dbg
.last_mp_curr_wr_port
[index
] = card
->curr_wr_port
;
1854 MP_TX_AGGR_BUF_RESET(card
);
1858 if (f_send_cur_buf
) {
1859 mwifiex_dbg(adapter
, DATA
,
1860 "data: %s: send current buffer %d\n",
1862 ret
= mwifiex_write_data_to_card(adapter
, payload
, pkt_len
,
1863 adapter
->ioport
+ port
);
1866 if (f_postcopy_cur_buf
) {
1867 mwifiex_dbg(adapter
, DATA
,
1868 "data: %s: postcopy current buffer\n",
1870 MP_TX_AGGR_BUF_PUT(card
, payload
, pkt_len
, port
);
1877 * This function downloads data from driver to card.
1879 * Both commands and data packets are transferred to the card by this
1882 * This function adds the SDIO specific header to the front of the buffer
1883 * before transferring. The header contains the length of the packet and
1884 * the type. The firmware handles the packets based upon this set type.
1886 static int mwifiex_sdio_host_to_card(struct mwifiex_adapter
*adapter
,
1887 u8 type
, struct sk_buff
*skb
,
1888 struct mwifiex_tx_param
*tx_param
)
1890 struct sdio_mmc_card
*card
= adapter
->card
;
1894 u32 port
= CTRL_PORT
;
1895 u8
*payload
= (u8
*)skb
->data
;
1896 u32 pkt_len
= skb
->len
;
1898 /* Allocate buffer and copy payload */
1899 blk_size
= MWIFIEX_SDIO_BLOCK_SIZE
;
1900 buf_block_len
= (pkt_len
+ blk_size
- 1) / blk_size
;
1901 put_unaligned_le16((u16
)pkt_len
, payload
+ 0);
1902 put_unaligned_le16((u32
)type
, payload
+ 2);
1906 * This is SDIO specific header
1908 * u16 type (MWIFIEX_TYPE_DATA = 0, MWIFIEX_TYPE_CMD = 1,
1909 * MWIFIEX_TYPE_EVENT = 3)
1911 if (type
== MWIFIEX_TYPE_DATA
) {
1912 ret
= mwifiex_get_wr_port_data(adapter
, &port
);
1914 mwifiex_dbg(adapter
, ERROR
,
1915 "%s: no wr_port available\n",
1920 adapter
->cmd_sent
= true;
1921 /* Type must be MWIFIEX_TYPE_CMD */
1923 if (pkt_len
<= adapter
->intf_hdr_len
||
1924 pkt_len
> MWIFIEX_UPLD_SIZE
)
1925 mwifiex_dbg(adapter
, ERROR
,
1926 "%s: payload=%p, nb=%d\n",
1927 __func__
, payload
, pkt_len
);
1929 if (card
->supports_sdio_new_mode
)
1930 port
= CMD_PORT_SLCT
;
1933 /* Transfer data to card */
1934 pkt_len
= buf_block_len
* blk_size
;
1937 ret
= mwifiex_host_to_card_mp_aggr(adapter
, payload
, pkt_len
,
1938 port
, tx_param
->next_pkt_len
1941 ret
= mwifiex_host_to_card_mp_aggr(adapter
, payload
, pkt_len
,
1945 if (type
== MWIFIEX_TYPE_CMD
)
1946 adapter
->cmd_sent
= false;
1947 if (type
== MWIFIEX_TYPE_DATA
) {
1948 adapter
->data_sent
= false;
1949 /* restore curr_wr_port in error cases */
1950 card
->curr_wr_port
= port
;
1951 card
->mp_wr_bitmap
|= (u32
)(1 << card
->curr_wr_port
);
1954 if (type
== MWIFIEX_TYPE_DATA
) {
1955 if (!(card
->mp_wr_bitmap
& (1 << card
->curr_wr_port
)))
1956 adapter
->data_sent
= true;
1958 adapter
->data_sent
= false;
1966 * This function allocates the MPA Tx and Rx buffers.
1968 static int mwifiex_alloc_sdio_mpa_buffers(struct mwifiex_adapter
*adapter
,
1969 u32 mpa_tx_buf_size
, u32 mpa_rx_buf_size
)
1971 struct sdio_mmc_card
*card
= adapter
->card
;
1975 card
->mpa_tx
.buf
= kzalloc(mpa_tx_buf_size
, GFP_KERNEL
);
1976 if (!card
->mpa_tx
.buf
) {
1981 card
->mpa_tx
.buf_size
= mpa_tx_buf_size
;
1983 rx_buf_size
= max_t(u32
, mpa_rx_buf_size
,
1984 (u32
)SDIO_MAX_AGGR_BUF_SIZE
);
1985 card
->mpa_rx
.buf
= kzalloc(rx_buf_size
, GFP_KERNEL
);
1986 if (!card
->mpa_rx
.buf
) {
1991 card
->mpa_rx
.buf_size
= rx_buf_size
;
1995 kfree(card
->mpa_tx
.buf
);
1996 kfree(card
->mpa_rx
.buf
);
1997 card
->mpa_tx
.buf_size
= 0;
1998 card
->mpa_rx
.buf_size
= 0;
2005 * This function unregisters the SDIO device.
2007 * The SDIO IRQ is released, the function is disabled and driver
2008 * data is set to null.
2011 mwifiex_unregister_dev(struct mwifiex_adapter
*adapter
)
2013 struct sdio_mmc_card
*card
= adapter
->card
;
2015 if (adapter
->card
) {
2016 card
->adapter
= NULL
;
2017 sdio_claim_host(card
->func
);
2018 sdio_disable_func(card
->func
);
2019 sdio_release_host(card
->func
);
2024 * This function registers the SDIO device.
2026 * SDIO IRQ is claimed, block size is set and driver data is initialized.
2028 static int mwifiex_register_dev(struct mwifiex_adapter
*adapter
)
2031 struct sdio_mmc_card
*card
= adapter
->card
;
2032 struct sdio_func
*func
= card
->func
;
2034 /* save adapter pointer in card */
2035 card
->adapter
= adapter
;
2036 adapter
->tx_buf_size
= card
->tx_buf_size
;
2038 sdio_claim_host(func
);
2040 /* Set block size */
2041 ret
= sdio_set_block_size(card
->func
, MWIFIEX_SDIO_BLOCK_SIZE
);
2042 sdio_release_host(func
);
2044 mwifiex_dbg(adapter
, ERROR
,
2045 "cannot set SDIO block size\n");
2049 strcpy(adapter
->fw_name
, card
->firmware
);
2050 if (card
->fw_dump_enh
) {
2051 adapter
->mem_type_mapping_tbl
= generic_mem_type_map
;
2052 adapter
->num_mem_types
= 1;
2054 adapter
->mem_type_mapping_tbl
= mem_type_mapping_tbl
;
2055 adapter
->num_mem_types
= ARRAY_SIZE(mem_type_mapping_tbl
);
2062 * This function initializes the SDIO driver.
2064 * The following initializations steps are followed -
2065 * - Read the Host interrupt status register to acknowledge
2066 * the first interrupt got from bootloader
2067 * - Disable host interrupt mask register
2069 * - Initialize SDIO variables in card
2070 * - Allocate MP registers
2071 * - Allocate MPA Tx and Rx buffers
2073 static int mwifiex_init_sdio(struct mwifiex_adapter
*adapter
)
2075 struct sdio_mmc_card
*card
= adapter
->card
;
2076 const struct mwifiex_sdio_card_reg
*reg
= card
->reg
;
2080 sdio_set_drvdata(card
->func
, card
);
2083 * Read the host_int_status_reg for ACK the first interrupt got
2084 * from the bootloader. If we don't do this we get a interrupt
2085 * as soon as we register the irq.
2087 mwifiex_read_reg(adapter
, card
->reg
->host_int_status_reg
, &sdio_ireg
);
2089 /* Get SDIO ioport */
2090 mwifiex_init_sdio_ioport(adapter
);
2092 /* Initialize SDIO variables in card */
2093 card
->mp_rd_bitmap
= 0;
2094 card
->mp_wr_bitmap
= 0;
2095 card
->curr_rd_port
= reg
->start_rd_port
;
2096 card
->curr_wr_port
= reg
->start_wr_port
;
2098 card
->mp_data_port_mask
= reg
->data_port_mask
;
2100 card
->mpa_tx
.buf_len
= 0;
2101 card
->mpa_tx
.pkt_cnt
= 0;
2102 card
->mpa_tx
.start_port
= 0;
2104 card
->mpa_tx
.enabled
= 1;
2105 card
->mpa_tx
.pkt_aggr_limit
= card
->mp_agg_pkt_limit
;
2107 card
->mpa_rx
.buf_len
= 0;
2108 card
->mpa_rx
.pkt_cnt
= 0;
2109 card
->mpa_rx
.start_port
= 0;
2111 card
->mpa_rx
.enabled
= 1;
2112 card
->mpa_rx
.pkt_aggr_limit
= card
->mp_agg_pkt_limit
;
2114 /* Allocate buffers for SDIO MP-A */
2115 card
->mp_regs
= kzalloc(reg
->max_mp_regs
, GFP_KERNEL
);
2119 /* Allocate skb pointer buffers */
2120 card
->mpa_rx
.skb_arr
= kcalloc(card
->mp_agg_pkt_limit
, sizeof(void *),
2122 if (!card
->mpa_rx
.skb_arr
) {
2123 kfree(card
->mp_regs
);
2127 card
->mpa_rx
.len_arr
= kcalloc(card
->mp_agg_pkt_limit
,
2128 sizeof(*card
->mpa_rx
.len_arr
),
2130 if (!card
->mpa_rx
.len_arr
) {
2131 kfree(card
->mp_regs
);
2132 kfree(card
->mpa_rx
.skb_arr
);
2136 ret
= mwifiex_alloc_sdio_mpa_buffers(adapter
,
2137 card
->mp_tx_agg_buf_size
,
2138 card
->mp_rx_agg_buf_size
);
2140 /* Allocate 32k MPA Tx/Rx buffers if 64k memory allocation fails */
2141 if (ret
&& (card
->mp_tx_agg_buf_size
== MWIFIEX_MP_AGGR_BUF_SIZE_MAX
||
2142 card
->mp_rx_agg_buf_size
== MWIFIEX_MP_AGGR_BUF_SIZE_MAX
)) {
2143 /* Disable rx single port aggregation */
2144 adapter
->host_disable_sdio_rx_aggr
= true;
2146 ret
= mwifiex_alloc_sdio_mpa_buffers
2147 (adapter
, MWIFIEX_MP_AGGR_BUF_SIZE_32K
,
2148 MWIFIEX_MP_AGGR_BUF_SIZE_32K
);
2150 /* Disable multi port aggregation */
2151 card
->mpa_tx
.enabled
= 0;
2152 card
->mpa_rx
.enabled
= 0;
2156 adapter
->auto_tdls
= card
->can_auto_tdls
;
2157 adapter
->ext_scan
= card
->can_ext_scan
;
2162 * This function resets the MPA Tx and Rx buffers.
2164 static void mwifiex_cleanup_mpa_buf(struct mwifiex_adapter
*adapter
)
2166 struct sdio_mmc_card
*card
= adapter
->card
;
2168 MP_TX_AGGR_BUF_RESET(card
);
2169 MP_RX_AGGR_BUF_RESET(card
);
2173 * This function cleans up the allocated card buffers.
2175 * The following are freed by this function -
2180 static void mwifiex_cleanup_sdio(struct mwifiex_adapter
*adapter
)
2182 struct sdio_mmc_card
*card
= adapter
->card
;
2184 cancel_work_sync(&card
->work
);
2186 kfree(card
->mp_regs
);
2187 kfree(card
->mpa_rx
.skb_arr
);
2188 kfree(card
->mpa_rx
.len_arr
);
2189 kfree(card
->mpa_tx
.buf
);
2190 kfree(card
->mpa_rx
.buf
);
2194 * This function updates the MP end port in card.
2197 mwifiex_update_mp_end_port(struct mwifiex_adapter
*adapter
, u16 port
)
2199 struct sdio_mmc_card
*card
= adapter
->card
;
2200 const struct mwifiex_sdio_card_reg
*reg
= card
->reg
;
2203 card
->mp_end_port
= port
;
2205 card
->mp_data_port_mask
= reg
->data_port_mask
;
2207 if (reg
->start_wr_port
) {
2208 for (i
= 1; i
<= card
->max_ports
- card
->mp_end_port
; i
++)
2209 card
->mp_data_port_mask
&=
2210 ~(1 << (card
->max_ports
- i
));
2213 card
->curr_wr_port
= reg
->start_wr_port
;
2215 mwifiex_dbg(adapter
, CMD
,
2216 "cmd: mp_end_port %d, data port mask 0x%x\n",
2217 port
, card
->mp_data_port_mask
);
2220 static void mwifiex_sdio_card_reset_work(struct mwifiex_adapter
*adapter
)
2222 struct sdio_mmc_card
*card
= adapter
->card
;
2223 struct sdio_func
*func
= card
->func
;
2226 /* Prepare the adapter for the reset. */
2227 mwifiex_shutdown_sw(adapter
);
2228 clear_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP
, &card
->work_flags
);
2229 clear_bit(MWIFIEX_IFACE_WORK_CARD_RESET
, &card
->work_flags
);
2231 /* Run a HW reset of the SDIO interface. */
2232 sdio_claim_host(func
);
2233 ret
= mmc_hw_reset(func
->card
->host
);
2234 sdio_release_host(func
);
2238 dev_dbg(&func
->dev
, "SDIO HW reset asynchronous\n");
2239 complete_all(adapter
->fw_done
);
2242 ret
= mwifiex_reinit_sw(adapter
);
2244 dev_err(&func
->dev
, "reinit failed: %d\n", ret
);
2247 dev_err(&func
->dev
, "SDIO HW reset failed: %d\n", ret
);
2252 /* This function read/write firmware */
2254 rdwr_status
mwifiex_sdio_rdwr_firmware(struct mwifiex_adapter
*adapter
,
2257 struct sdio_mmc_card
*card
= adapter
->card
;
2261 sdio_writeb(card
->func
, card
->reg
->fw_dump_host_ready
,
2262 card
->reg
->fw_dump_ctrl
, &ret
);
2264 mwifiex_dbg(adapter
, ERROR
, "SDIO Write ERR\n");
2265 return RDWR_STATUS_FAILURE
;
2267 for (tries
= 0; tries
< MAX_POLL_TRIES
; tries
++) {
2268 ctrl_data
= sdio_readb(card
->func
, card
->reg
->fw_dump_ctrl
,
2271 mwifiex_dbg(adapter
, ERROR
, "SDIO read err\n");
2272 return RDWR_STATUS_FAILURE
;
2274 if (ctrl_data
== FW_DUMP_DONE
)
2276 if (doneflag
&& ctrl_data
== doneflag
)
2277 return RDWR_STATUS_DONE
;
2278 if (ctrl_data
!= card
->reg
->fw_dump_host_ready
) {
2279 mwifiex_dbg(adapter
, WARN
,
2280 "The ctrl reg was changed, re-try again\n");
2281 sdio_writeb(card
->func
, card
->reg
->fw_dump_host_ready
,
2282 card
->reg
->fw_dump_ctrl
, &ret
);
2284 mwifiex_dbg(adapter
, ERROR
, "SDIO write err\n");
2285 return RDWR_STATUS_FAILURE
;
2288 usleep_range(100, 200);
2290 if (ctrl_data
== card
->reg
->fw_dump_host_ready
) {
2291 mwifiex_dbg(adapter
, ERROR
,
2292 "Fail to pull ctrl_data\n");
2293 return RDWR_STATUS_FAILURE
;
2296 return RDWR_STATUS_SUCCESS
;
2299 /* This function dump firmware memory to file */
2300 static void mwifiex_sdio_fw_dump(struct mwifiex_adapter
*adapter
)
2302 struct sdio_mmc_card
*card
= adapter
->card
;
2304 unsigned int reg
, reg_start
, reg_end
;
2305 u8
*dbg_ptr
, *end_ptr
, dump_num
, idx
, i
, read_reg
, doneflag
= 0;
2306 enum rdwr_status stat
;
2309 if (!card
->can_dump_fw
)
2312 for (idx
= 0; idx
< ARRAY_SIZE(mem_type_mapping_tbl
); idx
++) {
2313 struct memory_type_mapping
*entry
= &mem_type_mapping_tbl
[idx
];
2315 if (entry
->mem_ptr
) {
2316 vfree(entry
->mem_ptr
);
2317 entry
->mem_ptr
= NULL
;
2319 entry
->mem_size
= 0;
2322 mwifiex_pm_wakeup_card(adapter
);
2323 sdio_claim_host(card
->func
);
2325 mwifiex_dbg(adapter
, MSG
, "== mwifiex firmware dump start ==\n");
2327 stat
= mwifiex_sdio_rdwr_firmware(adapter
, doneflag
);
2328 if (stat
== RDWR_STATUS_FAILURE
)
2331 reg
= card
->reg
->fw_dump_start
;
2332 /* Read the number of the memories which will dump */
2333 dump_num
= sdio_readb(card
->func
, reg
, &ret
);
2335 mwifiex_dbg(adapter
, ERROR
, "SDIO read memory length err\n");
2339 /* Read the length of every memory which will dump */
2340 for (idx
= 0; idx
< dump_num
; idx
++) {
2341 struct memory_type_mapping
*entry
= &mem_type_mapping_tbl
[idx
];
2343 stat
= mwifiex_sdio_rdwr_firmware(adapter
, doneflag
);
2344 if (stat
== RDWR_STATUS_FAILURE
)
2348 reg
= card
->reg
->fw_dump_start
;
2349 for (i
= 0; i
< 4; i
++) {
2350 read_reg
= sdio_readb(card
->func
, reg
, &ret
);
2352 mwifiex_dbg(adapter
, ERROR
, "SDIO read err\n");
2355 memory_size
|= (read_reg
<< i
*8);
2359 if (memory_size
== 0) {
2360 mwifiex_dbg(adapter
, DUMP
, "Firmware dump Finished!\n");
2361 ret
= mwifiex_write_reg(adapter
,
2362 card
->reg
->fw_dump_ctrl
,
2365 mwifiex_dbg(adapter
, ERROR
, "SDIO write err\n");
2371 mwifiex_dbg(adapter
, DUMP
,
2372 "%s_SIZE=0x%x\n", entry
->mem_name
, memory_size
);
2373 entry
->mem_ptr
= vmalloc(memory_size
+ 1);
2374 entry
->mem_size
= memory_size
;
2375 if (!entry
->mem_ptr
) {
2376 mwifiex_dbg(adapter
, ERROR
, "Vmalloc %s failed\n",
2380 dbg_ptr
= entry
->mem_ptr
;
2381 end_ptr
= dbg_ptr
+ memory_size
;
2383 doneflag
= entry
->done_flag
;
2384 mwifiex_dbg(adapter
, DUMP
,
2385 "Start %s output, please wait...\n",
2389 stat
= mwifiex_sdio_rdwr_firmware(adapter
, doneflag
);
2390 if (stat
== RDWR_STATUS_FAILURE
)
2393 reg_start
= card
->reg
->fw_dump_start
;
2394 reg_end
= card
->reg
->fw_dump_end
;
2395 for (reg
= reg_start
; reg
<= reg_end
; reg
++) {
2396 *dbg_ptr
= sdio_readb(card
->func
, reg
, &ret
);
2398 mwifiex_dbg(adapter
, ERROR
,
2402 if (dbg_ptr
< end_ptr
)
2405 mwifiex_dbg(adapter
, ERROR
,
2406 "Allocated buf not enough\n");
2409 if (stat
!= RDWR_STATUS_DONE
)
2412 mwifiex_dbg(adapter
, DUMP
, "%s done: size=0x%tx\n",
2413 entry
->mem_name
, dbg_ptr
- entry
->mem_ptr
);
2417 mwifiex_dbg(adapter
, MSG
, "== mwifiex firmware dump end ==\n");
2420 sdio_release_host(card
->func
);
2423 static void mwifiex_sdio_generic_fw_dump(struct mwifiex_adapter
*adapter
)
2425 struct sdio_mmc_card
*card
= adapter
->card
;
2426 struct memory_type_mapping
*entry
= &generic_mem_type_map
[0];
2427 unsigned int reg
, reg_start
, reg_end
;
2428 u8 start_flag
= 0, done_flag
= 0;
2429 u8
*dbg_ptr
, *end_ptr
;
2430 enum rdwr_status stat
;
2431 int ret
= -1, tries
;
2433 if (!card
->fw_dump_enh
)
2436 if (entry
->mem_ptr
) {
2437 vfree(entry
->mem_ptr
);
2438 entry
->mem_ptr
= NULL
;
2440 entry
->mem_size
= 0;
2442 mwifiex_pm_wakeup_card(adapter
);
2443 sdio_claim_host(card
->func
);
2445 mwifiex_dbg(adapter
, MSG
, "== mwifiex firmware dump start ==\n");
2447 stat
= mwifiex_sdio_rdwr_firmware(adapter
, done_flag
);
2448 if (stat
== RDWR_STATUS_FAILURE
)
2451 reg_start
= card
->reg
->fw_dump_start
;
2452 reg_end
= card
->reg
->fw_dump_end
;
2453 for (reg
= reg_start
; reg
<= reg_end
; reg
++) {
2454 for (tries
= 0; tries
< MAX_POLL_TRIES
; tries
++) {
2455 start_flag
= sdio_readb(card
->func
, reg
, &ret
);
2457 mwifiex_dbg(adapter
, ERROR
,
2461 if (start_flag
== 0)
2463 if (tries
== MAX_POLL_TRIES
) {
2464 mwifiex_dbg(adapter
, ERROR
,
2465 "FW not ready to dump\n");
2470 usleep_range(100, 200);
2473 entry
->mem_ptr
= vmalloc(0xf0000 + 1);
2474 if (!entry
->mem_ptr
) {
2478 dbg_ptr
= entry
->mem_ptr
;
2479 entry
->mem_size
= 0xf0000;
2480 end_ptr
= dbg_ptr
+ entry
->mem_size
;
2482 done_flag
= entry
->done_flag
;
2483 mwifiex_dbg(adapter
, DUMP
,
2484 "Start %s output, please wait...\n", entry
->mem_name
);
2487 stat
= mwifiex_sdio_rdwr_firmware(adapter
, done_flag
);
2488 if (stat
== RDWR_STATUS_FAILURE
)
2490 for (reg
= reg_start
; reg
<= reg_end
; reg
++) {
2491 *dbg_ptr
= sdio_readb(card
->func
, reg
, &ret
);
2493 mwifiex_dbg(adapter
, ERROR
,
2498 if (dbg_ptr
>= end_ptr
) {
2501 tmp_ptr
= vmalloc(entry
->mem_size
+ 0x4000 + 1);
2505 memcpy(tmp_ptr
, entry
->mem_ptr
,
2507 vfree(entry
->mem_ptr
);
2508 entry
->mem_ptr
= tmp_ptr
;
2510 dbg_ptr
= entry
->mem_ptr
+ entry
->mem_size
;
2511 entry
->mem_size
+= 0x4000;
2512 end_ptr
= entry
->mem_ptr
+ entry
->mem_size
;
2515 if (stat
== RDWR_STATUS_DONE
) {
2516 entry
->mem_size
= dbg_ptr
- entry
->mem_ptr
;
2517 mwifiex_dbg(adapter
, DUMP
, "dump %s done size=0x%x\n",
2518 entry
->mem_name
, entry
->mem_size
);
2523 mwifiex_dbg(adapter
, MSG
, "== mwifiex firmware dump end ==\n");
2527 mwifiex_dbg(adapter
, ERROR
, "firmware dump failed\n");
2528 if (entry
->mem_ptr
) {
2529 vfree(entry
->mem_ptr
);
2530 entry
->mem_ptr
= NULL
;
2532 entry
->mem_size
= 0;
2534 sdio_release_host(card
->func
);
2537 static void mwifiex_sdio_device_dump_work(struct mwifiex_adapter
*adapter
)
2539 struct sdio_mmc_card
*card
= adapter
->card
;
2541 adapter
->devdump_data
= vzalloc(MWIFIEX_FW_DUMP_SIZE
);
2542 if (!adapter
->devdump_data
) {
2543 mwifiex_dbg(adapter
, ERROR
,
2544 "vzalloc devdump data failure!\n");
2548 mwifiex_drv_info_dump(adapter
);
2549 if (card
->fw_dump_enh
)
2550 mwifiex_sdio_generic_fw_dump(adapter
);
2552 mwifiex_sdio_fw_dump(adapter
);
2553 mwifiex_prepare_fw_dump_info(adapter
);
2554 mwifiex_upload_device_dump(adapter
);
2557 static void mwifiex_sdio_work(struct work_struct
*work
)
2559 struct sdio_mmc_card
*card
=
2560 container_of(work
, struct sdio_mmc_card
, work
);
2562 if (test_and_clear_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP
,
2564 mwifiex_sdio_device_dump_work(card
->adapter
);
2565 if (test_and_clear_bit(MWIFIEX_IFACE_WORK_CARD_RESET
,
2567 mwifiex_sdio_card_reset_work(card
->adapter
);
2570 /* This function resets the card */
2571 static void mwifiex_sdio_card_reset(struct mwifiex_adapter
*adapter
)
2573 struct sdio_mmc_card
*card
= adapter
->card
;
2575 if (!test_and_set_bit(MWIFIEX_IFACE_WORK_CARD_RESET
, &card
->work_flags
))
2576 schedule_work(&card
->work
);
2579 /* This function dumps FW information */
2580 static void mwifiex_sdio_device_dump(struct mwifiex_adapter
*adapter
)
2582 struct sdio_mmc_card
*card
= adapter
->card
;
2584 if (!test_and_set_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP
,
2586 schedule_work(&card
->work
);
2589 /* Function to dump SDIO function registers and SDIO scratch registers in case
2593 mwifiex_sdio_reg_dump(struct mwifiex_adapter
*adapter
, char *drv_buf
)
2596 struct sdio_mmc_card
*cardp
= adapter
->card
;
2598 u8 count
, func
, data
, index
= 0, size
= 0;
2599 u8 reg
, reg_start
, reg_end
;
2600 char buf
[256], *ptr
;
2605 mwifiex_dbg(adapter
, MSG
, "SDIO register dump start\n");
2607 mwifiex_pm_wakeup_card(adapter
);
2609 sdio_claim_host(cardp
->func
);
2611 for (count
= 0; count
< 5; count
++) {
2612 memset(buf
, 0, sizeof(buf
));
2617 /* Read the registers of SDIO function0 */
2623 /* Read the registers of SDIO function1 */
2625 reg_start
= cardp
->reg
->func1_dump_reg_start
;
2626 reg_end
= cardp
->reg
->func1_dump_reg_end
;
2631 reg_start
= cardp
->reg
->func1_spec_reg_table
[index
++];
2632 size
= cardp
->reg
->func1_spec_reg_num
;
2633 reg_end
= cardp
->reg
->func1_spec_reg_table
[size
-1];
2636 /* Read the scratch registers of SDIO function1 */
2640 reg_start
= cardp
->reg
->func1_scratch_reg
;
2641 reg_end
= reg_start
+ MWIFIEX_SDIO_SCRATCH_SIZE
;
2645 ptr
+= sprintf(ptr
, "SDIO Func%d (%#x-%#x): ",
2646 func
, reg_start
, reg_end
);
2648 ptr
+= sprintf(ptr
, "SDIO Func%d: ", func
);
2650 for (reg
= reg_start
; reg
<= reg_end
;) {
2652 data
= sdio_f0_readb(cardp
->func
, reg
, &ret
);
2654 data
= sdio_readb(cardp
->func
, reg
, &ret
);
2657 ptr
+= sprintf(ptr
, "(%#x) ", reg
);
2659 ptr
+= sprintf(ptr
, "%02x ", data
);
2661 ptr
+= sprintf(ptr
, "ERR");
2665 if (count
== 2 && reg
< reg_end
)
2666 reg
= cardp
->reg
->func1_spec_reg_table
[index
++];
2671 mwifiex_dbg(adapter
, MSG
, "%s\n", buf
);
2672 p
+= sprintf(p
, "%s\n", buf
);
2675 sdio_release_host(cardp
->func
);
2677 mwifiex_dbg(adapter
, MSG
, "SDIO register dump end\n");
2682 /* sdio device/function initialization, code is extracted
2683 * from init_if handler and register_dev handler.
2685 static void mwifiex_sdio_up_dev(struct mwifiex_adapter
*adapter
)
2687 struct sdio_mmc_card
*card
= adapter
->card
;
2690 sdio_claim_host(card
->func
);
2691 sdio_enable_func(card
->func
);
2692 sdio_set_block_size(card
->func
, MWIFIEX_SDIO_BLOCK_SIZE
);
2693 sdio_release_host(card
->func
);
2695 /* tx_buf_size might be changed to 3584 by firmware during
2696 * data transfer, we will reset to default size.
2698 adapter
->tx_buf_size
= card
->tx_buf_size
;
2700 /* Read the host_int_status_reg for ACK the first interrupt got
2701 * from the bootloader. If we don't do this we get a interrupt
2702 * as soon as we register the irq.
2704 mwifiex_read_reg(adapter
, card
->reg
->host_int_status_reg
, &sdio_ireg
);
2706 mwifiex_init_sdio_ioport(adapter
);
2709 static struct mwifiex_if_ops sdio_ops
= {
2710 .init_if
= mwifiex_init_sdio
,
2711 .cleanup_if
= mwifiex_cleanup_sdio
,
2712 .check_fw_status
= mwifiex_check_fw_status
,
2713 .check_winner_status
= mwifiex_check_winner_status
,
2714 .prog_fw
= mwifiex_prog_fw_w_helper
,
2715 .register_dev
= mwifiex_register_dev
,
2716 .unregister_dev
= mwifiex_unregister_dev
,
2717 .enable_int
= mwifiex_sdio_enable_host_int
,
2718 .disable_int
= mwifiex_sdio_disable_host_int
,
2719 .process_int_status
= mwifiex_process_int_status
,
2720 .host_to_card
= mwifiex_sdio_host_to_card
,
2721 .wakeup
= mwifiex_pm_wakeup_card
,
2722 .wakeup_complete
= mwifiex_pm_wakeup_card_complete
,
2725 .update_mp_end_port
= mwifiex_update_mp_end_port
,
2726 .cleanup_mpa_buf
= mwifiex_cleanup_mpa_buf
,
2727 .cmdrsp_complete
= mwifiex_sdio_cmdrsp_complete
,
2728 .event_complete
= mwifiex_sdio_event_complete
,
2729 .dnld_fw
= mwifiex_sdio_dnld_fw
,
2730 .card_reset
= mwifiex_sdio_card_reset
,
2731 .reg_dump
= mwifiex_sdio_reg_dump
,
2732 .device_dump
= mwifiex_sdio_device_dump
,
2733 .deaggr_pkt
= mwifiex_deaggr_sdio_pkt
,
2734 .up_dev
= mwifiex_sdio_up_dev
,
2737 module_driver(mwifiex_sdio
, sdio_register_driver
, sdio_unregister_driver
);
2739 MODULE_AUTHOR("Marvell International Ltd.");
2740 MODULE_DESCRIPTION("Marvell WiFi-Ex SDIO Driver version " SDIO_VERSION
);
2741 MODULE_VERSION(SDIO_VERSION
);
2742 MODULE_LICENSE("GPL v2");
2743 MODULE_FIRMWARE(SD8786_DEFAULT_FW_NAME
);
2744 MODULE_FIRMWARE(SD8787_DEFAULT_FW_NAME
);
2745 MODULE_FIRMWARE(SD8797_DEFAULT_FW_NAME
);
2746 MODULE_FIRMWARE(SD8897_DEFAULT_FW_NAME
);
2747 MODULE_FIRMWARE(SD8887_DEFAULT_FW_NAME
);
2748 MODULE_FIRMWARE(SD8977_DEFAULT_FW_NAME
);
2749 MODULE_FIRMWARE(SD8987_DEFAULT_FW_NAME
);
2750 MODULE_FIRMWARE(SD8997_DEFAULT_FW_NAME
);