2 * Marvell Wireless LAN device driver: SDIO specific handling
4 * Copyright (C) 2011-2014, Marvell International Ltd.
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
20 #include <linux/firmware.h>
32 #define SDIO_VERSION "1.0"
34 static 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 (!adapter
->is_suspended
) {
185 mwifiex_dbg(adapter
, WARN
,
186 "device already resumed\n");
190 adapter
->is_suspended
= false;
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 (adapter
->is_suspended
) {
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");
447 mwifiex_enable_wake(adapter
);
449 /* Enable the Host Sleep */
450 if (!mwifiex_enable_hs(adapter
)) {
451 mwifiex_dbg(adapter
, ERROR
,
452 "cmd: failed to suspend\n");
453 adapter
->hs_enabling
= false;
454 mwifiex_disable_wake(adapter
);
458 mwifiex_dbg(adapter
, INFO
,
459 "cmd: suspend with MMC_PM_KEEP_POWER\n");
460 ret
= sdio_set_host_pm_flags(func
, MMC_PM_KEEP_POWER
);
462 /* Indicate device suspended */
463 adapter
->is_suspended
= true;
464 adapter
->hs_enabling
= false;
469 static void mwifiex_sdio_coredump(struct device
*dev
)
471 struct sdio_func
*func
= dev_to_sdio_func(dev
);
472 struct sdio_mmc_card
*card
;
474 card
= sdio_get_drvdata(func
);
475 if (!test_and_set_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP
,
477 schedule_work(&card
->work
);
480 /* Device ID for SD8786 */
481 #define SDIO_DEVICE_ID_MARVELL_8786 (0x9116)
482 /* Device ID for SD8787 */
483 #define SDIO_DEVICE_ID_MARVELL_8787 (0x9119)
484 /* Device ID for SD8797 */
485 #define SDIO_DEVICE_ID_MARVELL_8797 (0x9129)
486 /* Device ID for SD8897 */
487 #define SDIO_DEVICE_ID_MARVELL_8897 (0x912d)
488 /* Device ID for SD8887 */
489 #define SDIO_DEVICE_ID_MARVELL_8887 (0x9135)
490 /* Device ID for SD8801 */
491 #define SDIO_DEVICE_ID_MARVELL_8801 (0x9139)
492 /* Device ID for SD8997 */
493 #define SDIO_DEVICE_ID_MARVELL_8997 (0x9141)
497 static const struct sdio_device_id mwifiex_ids
[] = {
498 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8786
),
499 .driver_data
= (unsigned long) &mwifiex_sdio_sd8786
},
500 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8787
),
501 .driver_data
= (unsigned long) &mwifiex_sdio_sd8787
},
502 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8797
),
503 .driver_data
= (unsigned long) &mwifiex_sdio_sd8797
},
504 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8897
),
505 .driver_data
= (unsigned long) &mwifiex_sdio_sd8897
},
506 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8887
),
507 .driver_data
= (unsigned long)&mwifiex_sdio_sd8887
},
508 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8801
),
509 .driver_data
= (unsigned long)&mwifiex_sdio_sd8801
},
510 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8997
),
511 .driver_data
= (unsigned long)&mwifiex_sdio_sd8997
},
515 MODULE_DEVICE_TABLE(sdio
, mwifiex_ids
);
517 static const struct dev_pm_ops mwifiex_sdio_pm_ops
= {
518 .suspend
= mwifiex_sdio_suspend
,
519 .resume
= mwifiex_sdio_resume
,
522 static struct sdio_driver mwifiex_sdio
= {
523 .name
= "mwifiex_sdio",
524 .id_table
= mwifiex_ids
,
525 .probe
= mwifiex_sdio_probe
,
526 .remove
= mwifiex_sdio_remove
,
528 .owner
= THIS_MODULE
,
529 .coredump
= mwifiex_sdio_coredump
,
530 .pm
= &mwifiex_sdio_pm_ops
,
535 * This function wakes up the card.
537 * A host power up command is written to the card configuration
538 * register to wake up the card.
540 static int mwifiex_pm_wakeup_card(struct mwifiex_adapter
*adapter
)
542 mwifiex_dbg(adapter
, EVENT
,
543 "event: wakeup device...\n");
545 return mwifiex_write_reg(adapter
, CONFIGURATION_REG
, HOST_POWER_UP
);
549 * This function is called after the card has woken up.
551 * The card configuration register is reset.
553 static int mwifiex_pm_wakeup_card_complete(struct mwifiex_adapter
*adapter
)
555 mwifiex_dbg(adapter
, EVENT
,
556 "cmd: wakeup device completed\n");
558 return mwifiex_write_reg(adapter
, CONFIGURATION_REG
, 0);
561 static int mwifiex_sdio_dnld_fw(struct mwifiex_adapter
*adapter
,
562 struct mwifiex_fw_image
*fw
)
564 struct sdio_mmc_card
*card
= adapter
->card
;
567 sdio_claim_host(card
->func
);
568 ret
= mwifiex_dnld_fw(adapter
, fw
);
569 sdio_release_host(card
->func
);
575 * This function is used to initialize IO ports for the
576 * chipsets supporting SDIO new mode eg SD8897.
578 static int mwifiex_init_sdio_new_mode(struct mwifiex_adapter
*adapter
)
581 struct sdio_mmc_card
*card
= adapter
->card
;
583 adapter
->ioport
= MEM_PORT
;
585 /* enable sdio new mode */
586 if (mwifiex_read_reg(adapter
, card
->reg
->card_cfg_2_1_reg
, ®
))
588 if (mwifiex_write_reg(adapter
, card
->reg
->card_cfg_2_1_reg
,
589 reg
| CMD53_NEW_MODE
))
592 /* Configure cmd port and enable reading rx length from the register */
593 if (mwifiex_read_reg(adapter
, card
->reg
->cmd_cfg_0
, ®
))
595 if (mwifiex_write_reg(adapter
, card
->reg
->cmd_cfg_0
,
596 reg
| CMD_PORT_RD_LEN_EN
))
599 /* Enable Dnld/Upld ready auto reset for cmd port after cmd53 is
602 if (mwifiex_read_reg(adapter
, card
->reg
->cmd_cfg_1
, ®
))
604 if (mwifiex_write_reg(adapter
, card
->reg
->cmd_cfg_1
,
605 reg
| CMD_PORT_AUTO_EN
))
611 /* This function initializes the IO ports.
613 * The following operations are performed -
614 * - Read the IO ports (0, 1 and 2)
615 * - Set host interrupt Reset-To-Read to clear
616 * - Set auto re-enable interrupt
618 static int mwifiex_init_sdio_ioport(struct mwifiex_adapter
*adapter
)
621 struct sdio_mmc_card
*card
= adapter
->card
;
625 if (card
->supports_sdio_new_mode
) {
626 if (mwifiex_init_sdio_new_mode(adapter
))
631 /* Read the IO port */
632 if (!mwifiex_read_reg(adapter
, card
->reg
->io_port_0_reg
, ®
))
633 adapter
->ioport
|= (reg
& 0xff);
637 if (!mwifiex_read_reg(adapter
, card
->reg
->io_port_1_reg
, ®
))
638 adapter
->ioport
|= ((reg
& 0xff) << 8);
642 if (!mwifiex_read_reg(adapter
, card
->reg
->io_port_2_reg
, ®
))
643 adapter
->ioport
|= ((reg
& 0xff) << 16);
647 mwifiex_dbg(adapter
, INFO
,
648 "info: SDIO FUNC1 IO port: %#x\n", adapter
->ioport
);
650 /* Set Host interrupt reset to read to clear */
651 if (!mwifiex_read_reg(adapter
, card
->reg
->host_int_rsr_reg
, ®
))
652 mwifiex_write_reg(adapter
, card
->reg
->host_int_rsr_reg
,
653 reg
| card
->reg
->sdio_int_mask
);
657 /* Dnld/Upld ready set to auto reset */
658 if (!mwifiex_read_reg(adapter
, card
->reg
->card_misc_cfg_reg
, ®
))
659 mwifiex_write_reg(adapter
, card
->reg
->card_misc_cfg_reg
,
660 reg
| AUTO_RE_ENABLE_INT
);
668 * This function sends data to the card.
670 static int mwifiex_write_data_to_card(struct mwifiex_adapter
*adapter
,
671 u8
*payload
, u32 pkt_len
, u32 port
)
677 ret
= mwifiex_write_data_sync(adapter
, payload
, pkt_len
, port
);
680 mwifiex_dbg(adapter
, ERROR
,
681 "host_to_card, write iomem\t"
682 "(%d) failed: %d\n", i
, ret
);
683 if (mwifiex_write_reg(adapter
, CONFIGURATION_REG
, 0x04))
684 mwifiex_dbg(adapter
, ERROR
,
685 "write CFG reg failed\n");
688 if (i
> MAX_WRITE_IOMEM_RETRY
)
697 * This function gets the read port.
699 * If control port bit is set in MP read bitmap, the control port
700 * is returned, otherwise the current read port is returned and
701 * the value is increased (provided it does not reach the maximum
702 * limit, in which case it is reset to 1)
704 static int mwifiex_get_rd_port(struct mwifiex_adapter
*adapter
, u8
*port
)
706 struct sdio_mmc_card
*card
= adapter
->card
;
707 const struct mwifiex_sdio_card_reg
*reg
= card
->reg
;
708 u32 rd_bitmap
= card
->mp_rd_bitmap
;
710 mwifiex_dbg(adapter
, DATA
,
711 "data: mp_rd_bitmap=0x%08x\n", rd_bitmap
);
713 if (card
->supports_sdio_new_mode
) {
714 if (!(rd_bitmap
& reg
->data_port_mask
))
717 if (!(rd_bitmap
& (CTRL_PORT_MASK
| reg
->data_port_mask
)))
721 if ((card
->has_control_mask
) &&
722 (card
->mp_rd_bitmap
& CTRL_PORT_MASK
)) {
723 card
->mp_rd_bitmap
&= (u32
) (~CTRL_PORT_MASK
);
725 mwifiex_dbg(adapter
, DATA
,
726 "data: port=%d mp_rd_bitmap=0x%08x\n",
727 *port
, card
->mp_rd_bitmap
);
731 if (!(card
->mp_rd_bitmap
& (1 << card
->curr_rd_port
)))
734 /* We are now handling the SDIO data ports */
735 card
->mp_rd_bitmap
&= (u32
)(~(1 << card
->curr_rd_port
));
736 *port
= card
->curr_rd_port
;
738 if (++card
->curr_rd_port
== card
->max_ports
)
739 card
->curr_rd_port
= reg
->start_rd_port
;
741 mwifiex_dbg(adapter
, DATA
,
742 "data: port=%d mp_rd_bitmap=0x%08x -> 0x%08x\n",
743 *port
, rd_bitmap
, card
->mp_rd_bitmap
);
749 * This function gets the write port for data.
751 * The current write port is returned if available and the value is
752 * increased (provided it does not reach the maximum limit, in which
753 * case it is reset to 1)
755 static int mwifiex_get_wr_port_data(struct mwifiex_adapter
*adapter
, u32
*port
)
757 struct sdio_mmc_card
*card
= adapter
->card
;
758 const struct mwifiex_sdio_card_reg
*reg
= card
->reg
;
759 u32 wr_bitmap
= card
->mp_wr_bitmap
;
761 mwifiex_dbg(adapter
, DATA
,
762 "data: mp_wr_bitmap=0x%08x\n", wr_bitmap
);
764 if (!(wr_bitmap
& card
->mp_data_port_mask
)) {
765 adapter
->data_sent
= true;
769 if (card
->mp_wr_bitmap
& (1 << card
->curr_wr_port
)) {
770 card
->mp_wr_bitmap
&= (u32
) (~(1 << card
->curr_wr_port
));
771 *port
= card
->curr_wr_port
;
772 if (++card
->curr_wr_port
== card
->mp_end_port
)
773 card
->curr_wr_port
= reg
->start_wr_port
;
775 adapter
->data_sent
= true;
779 if ((card
->has_control_mask
) && (*port
== CTRL_PORT
)) {
780 mwifiex_dbg(adapter
, ERROR
,
781 "invalid data port=%d cur port=%d mp_wr_bitmap=0x%08x -> 0x%08x\n",
782 *port
, card
->curr_wr_port
, wr_bitmap
,
787 mwifiex_dbg(adapter
, DATA
,
788 "data: port=%d mp_wr_bitmap=0x%08x -> 0x%08x\n",
789 *port
, wr_bitmap
, card
->mp_wr_bitmap
);
795 * This function polls the card status.
798 mwifiex_sdio_poll_card_status(struct mwifiex_adapter
*adapter
, u8 bits
)
800 struct sdio_mmc_card
*card
= adapter
->card
;
804 for (tries
= 0; tries
< MAX_POLL_TRIES
; tries
++) {
805 if (mwifiex_read_reg(adapter
, card
->reg
->poll_reg
, &cs
))
807 else if ((cs
& bits
) == bits
)
810 usleep_range(10, 20);
813 mwifiex_dbg(adapter
, ERROR
,
814 "poll card status failed, tries = %d\n", tries
);
820 * This function disables the host interrupt.
822 * The host interrupt mask is read, the disable bit is reset and
823 * written back to the card host interrupt mask register.
825 static void mwifiex_sdio_disable_host_int(struct mwifiex_adapter
*adapter
)
827 struct sdio_mmc_card
*card
= adapter
->card
;
828 struct sdio_func
*func
= card
->func
;
830 sdio_claim_host(func
);
831 mwifiex_write_reg_locked(func
, card
->reg
->host_int_mask_reg
, 0);
832 sdio_release_irq(func
);
833 sdio_release_host(func
);
837 * This function reads the interrupt status from card.
839 static void mwifiex_interrupt_status(struct mwifiex_adapter
*adapter
)
841 struct sdio_mmc_card
*card
= adapter
->card
;
845 if (mwifiex_read_data_sync(adapter
, card
->mp_regs
,
846 card
->reg
->max_mp_regs
,
847 REG_PORT
| MWIFIEX_SDIO_BYTE_MODE_MASK
, 0)) {
848 mwifiex_dbg(adapter
, ERROR
, "read mp_regs failed\n");
852 sdio_ireg
= card
->mp_regs
[card
->reg
->host_int_status_reg
];
855 * DN_LD_HOST_INT_STATUS and/or UP_LD_HOST_INT_STATUS
856 * For SDIO new mode CMD port interrupts
857 * DN_LD_CMD_PORT_HOST_INT_STATUS and/or
858 * UP_LD_CMD_PORT_HOST_INT_STATUS
859 * Clear the interrupt status register
861 mwifiex_dbg(adapter
, INTR
,
862 "int: sdio_ireg = %#x\n", sdio_ireg
);
863 spin_lock_irqsave(&adapter
->int_lock
, flags
);
864 adapter
->int_status
|= sdio_ireg
;
865 spin_unlock_irqrestore(&adapter
->int_lock
, flags
);
870 * SDIO interrupt handler.
872 * This function reads the interrupt status from firmware and handles
873 * the interrupt in current thread (ksdioirqd) right away.
876 mwifiex_sdio_interrupt(struct sdio_func
*func
)
878 struct mwifiex_adapter
*adapter
;
879 struct sdio_mmc_card
*card
;
881 card
= sdio_get_drvdata(func
);
882 if (!card
|| !card
->adapter
) {
883 pr_err("int: func=%p card=%p adapter=%p\n",
884 func
, card
, card
? card
->adapter
: NULL
);
887 adapter
= card
->adapter
;
889 if (!adapter
->pps_uapsd_mode
&& adapter
->ps_state
== PS_STATE_SLEEP
)
890 adapter
->ps_state
= PS_STATE_AWAKE
;
892 mwifiex_interrupt_status(adapter
);
893 mwifiex_main_process(adapter
);
897 * This function enables the host interrupt.
899 * The host interrupt enable mask is written to the card
900 * host interrupt mask register.
902 static int mwifiex_sdio_enable_host_int(struct mwifiex_adapter
*adapter
)
904 struct sdio_mmc_card
*card
= adapter
->card
;
905 struct sdio_func
*func
= card
->func
;
908 sdio_claim_host(func
);
910 /* Request the SDIO IRQ */
911 ret
= sdio_claim_irq(func
, mwifiex_sdio_interrupt
);
913 mwifiex_dbg(adapter
, ERROR
,
914 "claim irq failed: ret=%d\n", ret
);
918 /* Simply write the mask to the register */
919 ret
= mwifiex_write_reg_locked(func
, card
->reg
->host_int_mask_reg
,
920 card
->reg
->host_int_enable
);
922 mwifiex_dbg(adapter
, ERROR
,
923 "enable host interrupt failed\n");
924 sdio_release_irq(func
);
928 sdio_release_host(func
);
933 * This function sends a data buffer to the card.
935 static int mwifiex_sdio_card_to_host(struct mwifiex_adapter
*adapter
,
936 u32
*type
, u8
*buffer
,
937 u32 npayload
, u32 ioport
)
943 mwifiex_dbg(adapter
, ERROR
,
944 "%s: buffer is NULL\n", __func__
);
948 ret
= mwifiex_read_data_sync(adapter
, buffer
, npayload
, ioport
, 1);
951 mwifiex_dbg(adapter
, ERROR
,
952 "%s: read iomem failed: %d\n", __func__
,
957 nb
= get_unaligned_le16((buffer
));
959 mwifiex_dbg(adapter
, ERROR
,
960 "%s: invalid packet, nb=%d npayload=%d\n",
961 __func__
, nb
, npayload
);
965 *type
= get_unaligned_le16((buffer
+ 2));
971 * This function downloads the firmware to the card.
973 * Firmware is downloaded to the card in blocks. Every block download
974 * is tested for CRC errors, and retried a number of times before
977 static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter
*adapter
,
978 struct mwifiex_fw_image
*fw
)
980 struct sdio_mmc_card
*card
= adapter
->card
;
981 const struct mwifiex_sdio_card_reg
*reg
= card
->reg
;
983 u8
*firmware
= fw
->fw_buf
;
984 u32 firmware_len
= fw
->fw_len
;
989 u32 txlen
, tx_blocks
= 0, tries
;
993 mwifiex_dbg(adapter
, ERROR
,
994 "firmware image not found! Terminating download\n");
998 mwifiex_dbg(adapter
, INFO
,
999 "info: downloading FW image (%d bytes)\n",
1002 /* Assume that the allocated buffer is 8-byte aligned */
1003 fwbuf
= kzalloc(MWIFIEX_UPLD_SIZE
, GFP_KERNEL
);
1007 sdio_claim_host(card
->func
);
1009 /* Perform firmware data transfer */
1011 /* The host polls for the DN_LD_CARD_RDY and CARD_IO_READY
1013 ret
= mwifiex_sdio_poll_card_status(adapter
, CARD_IO_READY
|
1016 mwifiex_dbg(adapter
, ERROR
,
1017 "FW download with helper:\t"
1018 "poll status timeout @ %d\n", offset
);
1023 if (offset
>= firmware_len
)
1026 for (tries
= 0; tries
< MAX_POLL_TRIES
; tries
++) {
1027 ret
= mwifiex_read_reg(adapter
, reg
->base_0_reg
,
1030 mwifiex_dbg(adapter
, ERROR
,
1031 "dev BASE0 register read failed:\t"
1032 "base0=%#04X(%d). Terminating dnld\n",
1036 ret
= mwifiex_read_reg(adapter
, reg
->base_1_reg
,
1039 mwifiex_dbg(adapter
, ERROR
,
1040 "dev BASE1 register read failed:\t"
1041 "base1=%#04X(%d). Terminating dnld\n",
1045 len
= (u16
) (((base1
& 0xff) << 8) | (base0
& 0xff));
1050 usleep_range(10, 20);
1055 } else if (len
> MWIFIEX_UPLD_SIZE
) {
1056 mwifiex_dbg(adapter
, ERROR
,
1057 "FW dnld failed @ %d, invalid length %d\n",
1067 if (i
> MAX_WRITE_IOMEM_RETRY
) {
1068 mwifiex_dbg(adapter
, ERROR
,
1069 "FW dnld failed @ %d, over max retry\n",
1074 mwifiex_dbg(adapter
, ERROR
,
1075 "CRC indicated by the helper:\t"
1076 "len = 0x%04X, txlen = %d\n", len
, txlen
);
1078 /* Setting this to 0 to resend from same offset */
1083 /* Set blocksize to transfer - checking for last
1085 if (firmware_len
- offset
< txlen
)
1086 txlen
= firmware_len
- offset
;
1088 tx_blocks
= (txlen
+ MWIFIEX_SDIO_BLOCK_SIZE
- 1)
1089 / MWIFIEX_SDIO_BLOCK_SIZE
;
1091 /* Copy payload to buffer */
1092 memmove(fwbuf
, &firmware
[offset
], txlen
);
1095 ret
= mwifiex_write_data_sync(adapter
, fwbuf
, tx_blocks
*
1096 MWIFIEX_SDIO_BLOCK_SIZE
,
1099 mwifiex_dbg(adapter
, ERROR
,
1100 "FW download, write iomem (%d) failed @ %d\n",
1102 if (mwifiex_write_reg(adapter
, CONFIGURATION_REG
, 0x04))
1103 mwifiex_dbg(adapter
, ERROR
,
1104 "write CFG reg failed\n");
1113 mwifiex_dbg(adapter
, MSG
,
1114 "info: FW download over, size %d bytes\n", offset
);
1118 sdio_release_host(card
->func
);
1124 * This function decode sdio aggreation pkt.
1126 * Based on the the data block size and pkt_len,
1127 * skb data will be decoded to few packets.
1129 static void mwifiex_deaggr_sdio_pkt(struct mwifiex_adapter
*adapter
,
1130 struct sk_buff
*skb
)
1132 u32 total_pkt_len
, pkt_len
;
1133 struct sk_buff
*skb_deaggr
;
1139 total_pkt_len
= skb
->len
;
1141 while (total_pkt_len
>= (SDIO_HEADER_OFFSET
+ adapter
->intf_hdr_len
)) {
1142 if (total_pkt_len
< adapter
->sdio_rx_block_size
)
1144 blk_num
= *(data
+ BLOCK_NUMBER_OFFSET
);
1145 blk_size
= adapter
->sdio_rx_block_size
* blk_num
;
1146 if (blk_size
> total_pkt_len
) {
1147 mwifiex_dbg(adapter
, ERROR
,
1148 "%s: error in blk_size,\t"
1149 "blk_num=%d, blk_size=%d, total_pkt_len=%d\n",
1150 __func__
, blk_num
, blk_size
, total_pkt_len
);
1153 pkt_len
= get_unaligned_le16((data
+
1154 SDIO_HEADER_OFFSET
));
1155 if ((pkt_len
+ SDIO_HEADER_OFFSET
) > blk_size
) {
1156 mwifiex_dbg(adapter
, ERROR
,
1157 "%s: error in pkt_len,\t"
1158 "pkt_len=%d, blk_size=%d\n",
1159 __func__
, pkt_len
, blk_size
);
1163 skb_deaggr
= mwifiex_alloc_dma_align_buf(pkt_len
, GFP_KERNEL
);
1166 skb_put(skb_deaggr
, pkt_len
);
1167 memcpy(skb_deaggr
->data
, data
+ SDIO_HEADER_OFFSET
, pkt_len
);
1168 skb_pull(skb_deaggr
, adapter
->intf_hdr_len
);
1170 mwifiex_handle_rx_packet(adapter
, skb_deaggr
);
1172 total_pkt_len
-= blk_size
;
1177 * This function decodes a received packet.
1179 * Based on the type, the packet is treated as either a data, or
1180 * a command response, or an event, and the correct handler
1181 * function is invoked.
1183 static int mwifiex_decode_rx_packet(struct mwifiex_adapter
*adapter
,
1184 struct sk_buff
*skb
, u32 upld_typ
)
1188 struct mwifiex_rxinfo
*rx_info
;
1190 pkt_len
= get_unaligned_le16(skb
->data
);
1192 if (upld_typ
!= MWIFIEX_TYPE_AGGR_DATA
) {
1193 skb_trim(skb
, pkt_len
);
1194 skb_pull(skb
, adapter
->intf_hdr_len
);
1198 case MWIFIEX_TYPE_AGGR_DATA
:
1199 mwifiex_dbg(adapter
, INFO
,
1200 "info: --- Rx: Aggr Data packet ---\n");
1201 rx_info
= MWIFIEX_SKB_RXCB(skb
);
1202 rx_info
->buf_type
= MWIFIEX_TYPE_AGGR_DATA
;
1203 if (adapter
->rx_work_enabled
) {
1204 skb_queue_tail(&adapter
->rx_data_q
, skb
);
1205 atomic_inc(&adapter
->rx_pending
);
1206 adapter
->data_received
= true;
1208 mwifiex_deaggr_sdio_pkt(adapter
, skb
);
1209 dev_kfree_skb_any(skb
);
1213 case MWIFIEX_TYPE_DATA
:
1214 mwifiex_dbg(adapter
, DATA
,
1215 "info: --- Rx: Data packet ---\n");
1216 if (adapter
->rx_work_enabled
) {
1217 skb_queue_tail(&adapter
->rx_data_q
, skb
);
1218 adapter
->data_received
= true;
1219 atomic_inc(&adapter
->rx_pending
);
1221 mwifiex_handle_rx_packet(adapter
, skb
);
1225 case MWIFIEX_TYPE_CMD
:
1226 mwifiex_dbg(adapter
, CMD
,
1227 "info: --- Rx: Cmd Response ---\n");
1228 /* take care of curr_cmd = NULL case */
1229 if (!adapter
->curr_cmd
) {
1230 cmd_buf
= adapter
->upld_buf
;
1232 if (adapter
->ps_state
== PS_STATE_SLEEP_CFM
)
1233 mwifiex_process_sleep_confirm_resp(adapter
,
1237 memcpy(cmd_buf
, skb
->data
,
1238 min_t(u32
, MWIFIEX_SIZE_OF_CMD_BUFFER
,
1241 dev_kfree_skb_any(skb
);
1243 adapter
->cmd_resp_received
= true;
1244 adapter
->curr_cmd
->resp_skb
= skb
;
1248 case MWIFIEX_TYPE_EVENT
:
1249 mwifiex_dbg(adapter
, EVENT
,
1250 "info: --- Rx: Event ---\n");
1251 adapter
->event_cause
= get_unaligned_le32(skb
->data
);
1253 if ((skb
->len
> 0) && (skb
->len
< MAX_EVENT_SIZE
))
1254 memcpy(adapter
->event_body
,
1255 skb
->data
+ MWIFIEX_EVENT_HEADER_LEN
,
1258 /* event cause has been saved to adapter->event_cause */
1259 adapter
->event_received
= true;
1260 adapter
->event_skb
= skb
;
1265 mwifiex_dbg(adapter
, ERROR
,
1266 "unknown upload type %#x\n", upld_typ
);
1267 dev_kfree_skb_any(skb
);
1275 * This function transfers received packets from card to driver, performing
1276 * aggregation if required.
1278 * For data received on control port, or if aggregation is disabled, the
1279 * received buffers are uploaded as separate packets. However, if aggregation
1280 * is enabled and required, the buffers are copied onto an aggregation buffer,
1281 * provided there is space left, processed and finally uploaded.
1283 static int mwifiex_sdio_card_to_host_mp_aggr(struct mwifiex_adapter
*adapter
,
1284 u16 rx_len
, u8 port
)
1286 struct sdio_mmc_card
*card
= adapter
->card
;
1287 s32 f_do_rx_aggr
= 0;
1288 s32 f_do_rx_cur
= 0;
1290 s32 f_post_aggr_cur
= 0;
1291 struct sk_buff
*skb_deaggr
;
1292 struct sk_buff
*skb
= NULL
;
1293 u32 pkt_len
, pkt_type
, mport
, pind
;
1296 if ((card
->has_control_mask
) && (port
== CTRL_PORT
)) {
1297 /* Read the command Resp without aggr */
1298 mwifiex_dbg(adapter
, CMD
,
1299 "info: %s: no aggregation for cmd\t"
1300 "response\n", __func__
);
1303 goto rx_curr_single
;
1306 if (!card
->mpa_rx
.enabled
) {
1307 mwifiex_dbg(adapter
, WARN
,
1308 "info: %s: rx aggregation disabled\n",
1312 goto rx_curr_single
;
1315 if ((!card
->has_control_mask
&& (card
->mp_rd_bitmap
&
1316 card
->reg
->data_port_mask
)) ||
1317 (card
->has_control_mask
&& (card
->mp_rd_bitmap
&
1318 (~((u32
) CTRL_PORT_MASK
))))) {
1319 /* Some more data RX pending */
1320 mwifiex_dbg(adapter
, INFO
,
1321 "info: %s: not last packet\n", __func__
);
1323 if (MP_RX_AGGR_IN_PROGRESS(card
)) {
1324 if (MP_RX_AGGR_BUF_HAS_ROOM(card
, rx_len
)) {
1327 /* No room in Aggr buf, do rx aggr now */
1329 f_post_aggr_cur
= 1;
1332 /* Rx aggr not in progress */
1337 /* No more data RX pending */
1338 mwifiex_dbg(adapter
, INFO
,
1339 "info: %s: last packet\n", __func__
);
1341 if (MP_RX_AGGR_IN_PROGRESS(card
)) {
1343 if (MP_RX_AGGR_BUF_HAS_ROOM(card
, rx_len
))
1346 /* No room in Aggr buf, do rx aggr now */
1354 mwifiex_dbg(adapter
, INFO
,
1355 "info: current packet aggregation\n");
1356 /* Curr pkt can be aggregated */
1357 mp_rx_aggr_setup(card
, rx_len
, port
);
1359 if (MP_RX_AGGR_PKT_LIMIT_REACHED(card
) ||
1360 mp_rx_aggr_port_limit_reached(card
)) {
1361 mwifiex_dbg(adapter
, INFO
,
1362 "info: %s: aggregated packet\t"
1363 "limit reached\n", __func__
);
1364 /* No more pkts allowed in Aggr buf, rx it */
1370 /* do aggr RX now */
1371 mwifiex_dbg(adapter
, DATA
,
1372 "info: do_rx_aggr: num of packets: %d\n",
1373 card
->mpa_rx
.pkt_cnt
);
1375 if (card
->supports_sdio_new_mode
) {
1379 for (i
= 0, port_count
= 0; i
< card
->max_ports
; i
++)
1380 if (card
->mpa_rx
.ports
& BIT(i
))
1383 /* Reading data from "start_port + 0" to "start_port +
1384 * port_count -1", so decrease the count by 1
1387 mport
= (adapter
->ioport
| SDIO_MPA_ADDR_BASE
|
1388 (port_count
<< 8)) + card
->mpa_rx
.start_port
;
1390 mport
= (adapter
->ioport
| SDIO_MPA_ADDR_BASE
|
1391 (card
->mpa_rx
.ports
<< 4)) +
1392 card
->mpa_rx
.start_port
;
1395 if (card
->mpa_rx
.pkt_cnt
== 1)
1396 mport
= adapter
->ioport
+ card
->mpa_rx
.start_port
;
1398 if (mwifiex_read_data_sync(adapter
, card
->mpa_rx
.buf
,
1399 card
->mpa_rx
.buf_len
, mport
, 1))
1402 curr_ptr
= card
->mpa_rx
.buf
;
1404 for (pind
= 0; pind
< card
->mpa_rx
.pkt_cnt
; pind
++) {
1405 u32
*len_arr
= card
->mpa_rx
.len_arr
;
1407 /* get curr PKT len & type */
1408 pkt_len
= get_unaligned_le16(&curr_ptr
[0]);
1409 pkt_type
= get_unaligned_le16(&curr_ptr
[2]);
1411 /* copy pkt to deaggr buf */
1412 skb_deaggr
= mwifiex_alloc_dma_align_buf(len_arr
[pind
],
1415 mwifiex_dbg(adapter
, ERROR
, "skb allocation failure\t"
1416 "drop pkt len=%d type=%d\n",
1418 curr_ptr
+= len_arr
[pind
];
1422 skb_put(skb_deaggr
, len_arr
[pind
]);
1424 if ((pkt_type
== MWIFIEX_TYPE_DATA
||
1425 (pkt_type
== MWIFIEX_TYPE_AGGR_DATA
&&
1426 adapter
->sdio_rx_aggr_enable
)) &&
1427 (pkt_len
<= len_arr
[pind
])) {
1429 memcpy(skb_deaggr
->data
, curr_ptr
, pkt_len
);
1431 skb_trim(skb_deaggr
, pkt_len
);
1433 /* Process de-aggr packet */
1434 mwifiex_decode_rx_packet(adapter
, skb_deaggr
,
1437 mwifiex_dbg(adapter
, ERROR
,
1438 "drop wrong aggr pkt:\t"
1439 "sdio_single_port_rx_aggr=%d\t"
1440 "type=%d len=%d max_len=%d\n",
1441 adapter
->sdio_rx_aggr_enable
,
1442 pkt_type
, pkt_len
, len_arr
[pind
]);
1443 dev_kfree_skb_any(skb_deaggr
);
1445 curr_ptr
+= len_arr
[pind
];
1447 MP_RX_AGGR_BUF_RESET(card
);
1452 mwifiex_dbg(adapter
, INFO
, "info: RX: port: %d, rx_len: %d\n",
1455 skb
= mwifiex_alloc_dma_align_buf(rx_len
, GFP_KERNEL
);
1457 mwifiex_dbg(adapter
, ERROR
,
1458 "single skb allocated fail,\t"
1459 "drop pkt port=%d len=%d\n", port
, rx_len
);
1460 if (mwifiex_sdio_card_to_host(adapter
, &pkt_type
,
1461 card
->mpa_rx
.buf
, rx_len
,
1462 adapter
->ioport
+ port
))
1467 skb_put(skb
, rx_len
);
1469 if (mwifiex_sdio_card_to_host(adapter
, &pkt_type
,
1470 skb
->data
, skb
->len
,
1471 adapter
->ioport
+ port
))
1473 if (!adapter
->sdio_rx_aggr_enable
&&
1474 pkt_type
== MWIFIEX_TYPE_AGGR_DATA
) {
1475 mwifiex_dbg(adapter
, ERROR
, "drop wrong pkt type %d\t"
1476 "current SDIO RX Aggr not enabled\n",
1478 dev_kfree_skb_any(skb
);
1482 mwifiex_decode_rx_packet(adapter
, skb
, pkt_type
);
1484 if (f_post_aggr_cur
) {
1485 mwifiex_dbg(adapter
, INFO
,
1486 "info: current packet aggregation\n");
1487 /* Curr pkt can be aggregated */
1488 mp_rx_aggr_setup(card
, rx_len
, port
);
1493 if (MP_RX_AGGR_IN_PROGRESS(card
))
1494 MP_RX_AGGR_BUF_RESET(card
);
1496 if (f_do_rx_cur
&& skb
)
1497 /* Single transfer pending. Free curr buff also */
1498 dev_kfree_skb_any(skb
);
1504 * This function checks the current interrupt status.
1506 * The following interrupts are checked and handled by this function -
1509 * - Packets received
1511 * Since the firmware does not generate download ready interrupt if the
1512 * port updated is command port only, command sent interrupt checking
1513 * should be done manually, and for every SDIO interrupt.
1515 * In case of Rx packets received, the packets are uploaded from card to
1516 * host and processed accordingly.
1518 static int mwifiex_process_int_status(struct mwifiex_adapter
*adapter
)
1520 struct sdio_mmc_card
*card
= adapter
->card
;
1521 const struct mwifiex_sdio_card_reg
*reg
= card
->reg
;
1524 struct sk_buff
*skb
;
1525 u8 port
= CTRL_PORT
;
1526 u32 len_reg_l
, len_reg_u
;
1529 unsigned long flags
;
1533 spin_lock_irqsave(&adapter
->int_lock
, flags
);
1534 sdio_ireg
= adapter
->int_status
;
1535 adapter
->int_status
= 0;
1536 spin_unlock_irqrestore(&adapter
->int_lock
, flags
);
1541 /* Following interrupt is only for SDIO new mode */
1542 if (sdio_ireg
& DN_LD_CMD_PORT_HOST_INT_STATUS
&& adapter
->cmd_sent
)
1543 adapter
->cmd_sent
= false;
1545 /* Following interrupt is only for SDIO new mode */
1546 if (sdio_ireg
& UP_LD_CMD_PORT_HOST_INT_STATUS
) {
1549 /* read the len of control packet */
1550 rx_len
= card
->mp_regs
[reg
->cmd_rd_len_1
] << 8;
1551 rx_len
|= (u16
)card
->mp_regs
[reg
->cmd_rd_len_0
];
1552 rx_blocks
= DIV_ROUND_UP(rx_len
, MWIFIEX_SDIO_BLOCK_SIZE
);
1553 if (rx_len
<= adapter
->intf_hdr_len
||
1554 (rx_blocks
* MWIFIEX_SDIO_BLOCK_SIZE
) >
1555 MWIFIEX_RX_DATA_BUF_SIZE
)
1557 rx_len
= (u16
) (rx_blocks
* MWIFIEX_SDIO_BLOCK_SIZE
);
1558 mwifiex_dbg(adapter
, INFO
, "info: rx_len = %d\n", rx_len
);
1560 skb
= mwifiex_alloc_dma_align_buf(rx_len
, GFP_KERNEL
);
1564 skb_put(skb
, rx_len
);
1566 if (mwifiex_sdio_card_to_host(adapter
, &pkt_type
, skb
->data
,
1567 skb
->len
, adapter
->ioport
|
1569 mwifiex_dbg(adapter
, ERROR
,
1570 "%s: failed to card_to_host", __func__
);
1571 dev_kfree_skb_any(skb
);
1575 if ((pkt_type
!= MWIFIEX_TYPE_CMD
) &&
1576 (pkt_type
!= MWIFIEX_TYPE_EVENT
))
1577 mwifiex_dbg(adapter
, ERROR
,
1578 "%s:Received wrong packet on cmd port",
1581 mwifiex_decode_rx_packet(adapter
, skb
, pkt_type
);
1584 if (sdio_ireg
& DN_LD_HOST_INT_STATUS
) {
1585 bitmap
= (u32
) card
->mp_regs
[reg
->wr_bitmap_l
];
1586 bitmap
|= ((u32
) card
->mp_regs
[reg
->wr_bitmap_u
]) << 8;
1587 if (card
->supports_sdio_new_mode
) {
1589 ((u32
) card
->mp_regs
[reg
->wr_bitmap_1l
]) << 16;
1591 ((u32
) card
->mp_regs
[reg
->wr_bitmap_1u
]) << 24;
1593 card
->mp_wr_bitmap
= bitmap
;
1595 mwifiex_dbg(adapter
, INTR
,
1596 "int: DNLD: wr_bitmap=0x%x\n",
1597 card
->mp_wr_bitmap
);
1598 if (adapter
->data_sent
&&
1599 (card
->mp_wr_bitmap
& card
->mp_data_port_mask
)) {
1600 mwifiex_dbg(adapter
, INTR
,
1601 "info: <--- Tx DONE Interrupt --->\n");
1602 adapter
->data_sent
= false;
1606 /* As firmware will not generate download ready interrupt if the port
1607 updated is command port only, cmd_sent should be done for any SDIO
1609 if (card
->has_control_mask
&& adapter
->cmd_sent
) {
1610 /* Check if firmware has attach buffer at command port and
1611 update just that in wr_bit_map. */
1612 card
->mp_wr_bitmap
|=
1613 (u32
) card
->mp_regs
[reg
->wr_bitmap_l
] & CTRL_PORT_MASK
;
1614 if (card
->mp_wr_bitmap
& CTRL_PORT_MASK
)
1615 adapter
->cmd_sent
= false;
1618 mwifiex_dbg(adapter
, INTR
, "info: cmd_sent=%d data_sent=%d\n",
1619 adapter
->cmd_sent
, adapter
->data_sent
);
1620 if (sdio_ireg
& UP_LD_HOST_INT_STATUS
) {
1621 bitmap
= (u32
) card
->mp_regs
[reg
->rd_bitmap_l
];
1622 bitmap
|= ((u32
) card
->mp_regs
[reg
->rd_bitmap_u
]) << 8;
1623 if (card
->supports_sdio_new_mode
) {
1625 ((u32
) card
->mp_regs
[reg
->rd_bitmap_1l
]) << 16;
1627 ((u32
) card
->mp_regs
[reg
->rd_bitmap_1u
]) << 24;
1629 card
->mp_rd_bitmap
= bitmap
;
1630 mwifiex_dbg(adapter
, INTR
,
1631 "int: UPLD: rd_bitmap=0x%x\n",
1632 card
->mp_rd_bitmap
);
1635 ret
= mwifiex_get_rd_port(adapter
, &port
);
1637 mwifiex_dbg(adapter
, INFO
,
1638 "info: no more rd_port available\n");
1641 len_reg_l
= reg
->rd_len_p0_l
+ (port
<< 1);
1642 len_reg_u
= reg
->rd_len_p0_u
+ (port
<< 1);
1643 rx_len
= ((u16
) card
->mp_regs
[len_reg_u
]) << 8;
1644 rx_len
|= (u16
) card
->mp_regs
[len_reg_l
];
1645 mwifiex_dbg(adapter
, INFO
,
1646 "info: RX: port=%d rx_len=%u\n",
1649 (rx_len
+ MWIFIEX_SDIO_BLOCK_SIZE
-
1650 1) / MWIFIEX_SDIO_BLOCK_SIZE
;
1651 if (rx_len
<= adapter
->intf_hdr_len
||
1652 (card
->mpa_rx
.enabled
&&
1653 ((rx_blocks
* MWIFIEX_SDIO_BLOCK_SIZE
) >
1654 card
->mpa_rx
.buf_size
))) {
1655 mwifiex_dbg(adapter
, ERROR
,
1656 "invalid rx_len=%d\n",
1661 rx_len
= (u16
) (rx_blocks
* MWIFIEX_SDIO_BLOCK_SIZE
);
1662 mwifiex_dbg(adapter
, INFO
, "info: rx_len = %d\n",
1665 if (mwifiex_sdio_card_to_host_mp_aggr(adapter
, rx_len
,
1667 mwifiex_dbg(adapter
, ERROR
,
1668 "card_to_host_mpa failed: int status=%#x\n",
1679 if (mwifiex_read_reg(adapter
, CONFIGURATION_REG
, &cr
))
1680 mwifiex_dbg(adapter
, ERROR
, "read CFG reg failed\n");
1682 mwifiex_dbg(adapter
, INFO
,
1683 "info: CFG reg val = %d\n", cr
);
1685 if (mwifiex_write_reg(adapter
, CONFIGURATION_REG
, (cr
| 0x04)))
1686 mwifiex_dbg(adapter
, ERROR
,
1687 "write CFG reg failed\n");
1689 mwifiex_dbg(adapter
, INFO
, "info: write success\n");
1691 if (mwifiex_read_reg(adapter
, CONFIGURATION_REG
, &cr
))
1692 mwifiex_dbg(adapter
, ERROR
,
1693 "read CFG reg failed\n");
1695 mwifiex_dbg(adapter
, INFO
,
1696 "info: CFG reg val =%x\n", cr
);
1702 * This function aggregates transmission buffers in driver and downloads
1703 * the aggregated packet to card.
1705 * The individual packets are aggregated by copying into an aggregation
1706 * buffer and then downloaded to the card. Previous unsent packets in the
1707 * aggregation buffer are pre-copied first before new packets are added.
1708 * Aggregation is done till there is space left in the aggregation buffer,
1709 * or till new packets are available.
1711 * The function will only download the packet to the card when aggregation
1712 * stops, otherwise it will just aggregate the packet in aggregation buffer
1715 static int mwifiex_host_to_card_mp_aggr(struct mwifiex_adapter
*adapter
,
1716 u8
*payload
, u32 pkt_len
, u32 port
,
1719 struct sdio_mmc_card
*card
= adapter
->card
;
1721 s32 f_send_aggr_buf
= 0;
1722 s32 f_send_cur_buf
= 0;
1723 s32 f_precopy_cur_buf
= 0;
1724 s32 f_postcopy_cur_buf
= 0;
1728 if (!card
->mpa_tx
.enabled
||
1729 (card
->has_control_mask
&& (port
== CTRL_PORT
)) ||
1730 (card
->supports_sdio_new_mode
&& (port
== CMD_PORT_SLCT
))) {
1731 mwifiex_dbg(adapter
, WARN
,
1732 "info: %s: tx aggregation disabled\n",
1736 goto tx_curr_single
;
1740 /* More pkt in TX queue */
1741 mwifiex_dbg(adapter
, INFO
,
1742 "info: %s: more packets in queue.\n",
1745 if (MP_TX_AGGR_IN_PROGRESS(card
)) {
1746 if (MP_TX_AGGR_BUF_HAS_ROOM(card
, pkt_len
)) {
1747 f_precopy_cur_buf
= 1;
1749 if (!(card
->mp_wr_bitmap
&
1750 (1 << card
->curr_wr_port
)) ||
1751 !MP_TX_AGGR_BUF_HAS_ROOM(
1752 card
, pkt_len
+ next_pkt_len
))
1753 f_send_aggr_buf
= 1;
1755 /* No room in Aggr buf, send it */
1756 f_send_aggr_buf
= 1;
1758 if (!(card
->mp_wr_bitmap
&
1759 (1 << card
->curr_wr_port
)))
1762 f_postcopy_cur_buf
= 1;
1765 if (MP_TX_AGGR_BUF_HAS_ROOM(card
, pkt_len
) &&
1766 (card
->mp_wr_bitmap
& (1 << card
->curr_wr_port
)))
1767 f_precopy_cur_buf
= 1;
1772 /* Last pkt in TX queue */
1773 mwifiex_dbg(adapter
, INFO
,
1774 "info: %s: Last packet in Tx Queue.\n",
1777 if (MP_TX_AGGR_IN_PROGRESS(card
)) {
1778 /* some packs in Aggr buf already */
1779 f_send_aggr_buf
= 1;
1781 if (MP_TX_AGGR_BUF_HAS_ROOM(card
, pkt_len
))
1782 f_precopy_cur_buf
= 1;
1784 /* No room in Aggr buf, send it */
1791 if (f_precopy_cur_buf
) {
1792 mwifiex_dbg(adapter
, DATA
,
1793 "data: %s: precopy current buffer\n",
1795 MP_TX_AGGR_BUF_PUT(card
, payload
, pkt_len
, port
);
1797 if (MP_TX_AGGR_PKT_LIMIT_REACHED(card
) ||
1798 mp_tx_aggr_port_limit_reached(card
))
1799 /* No more pkts allowed in Aggr buf, send it */
1800 f_send_aggr_buf
= 1;
1803 if (f_send_aggr_buf
) {
1804 mwifiex_dbg(adapter
, DATA
,
1805 "data: %s: send aggr buffer: %d %d\n",
1806 __func__
, card
->mpa_tx
.start_port
,
1807 card
->mpa_tx
.ports
);
1808 if (card
->supports_sdio_new_mode
) {
1812 for (i
= 0, port_count
= 0; i
< card
->max_ports
; i
++)
1813 if (card
->mpa_tx
.ports
& BIT(i
))
1816 /* Writing data from "start_port + 0" to "start_port +
1817 * port_count -1", so decrease the count by 1
1820 mport
= (adapter
->ioport
| SDIO_MPA_ADDR_BASE
|
1821 (port_count
<< 8)) + card
->mpa_tx
.start_port
;
1823 mport
= (adapter
->ioport
| SDIO_MPA_ADDR_BASE
|
1824 (card
->mpa_tx
.ports
<< 4)) +
1825 card
->mpa_tx
.start_port
;
1828 if (card
->mpa_tx
.pkt_cnt
== 1)
1829 mport
= adapter
->ioport
+ card
->mpa_tx
.start_port
;
1831 ret
= mwifiex_write_data_to_card(adapter
, card
->mpa_tx
.buf
,
1832 card
->mpa_tx
.buf_len
, mport
);
1834 /* Save the last multi port tx aggreagation info to debug log */
1835 index
= adapter
->dbg
.last_sdio_mp_index
;
1836 index
= (index
+ 1) % MWIFIEX_DBG_SDIO_MP_NUM
;
1837 adapter
->dbg
.last_sdio_mp_index
= index
;
1838 adapter
->dbg
.last_mp_wr_ports
[index
] = mport
;
1839 adapter
->dbg
.last_mp_wr_bitmap
[index
] = card
->mp_wr_bitmap
;
1840 adapter
->dbg
.last_mp_wr_len
[index
] = card
->mpa_tx
.buf_len
;
1841 adapter
->dbg
.last_mp_curr_wr_port
[index
] = card
->curr_wr_port
;
1843 MP_TX_AGGR_BUF_RESET(card
);
1847 if (f_send_cur_buf
) {
1848 mwifiex_dbg(adapter
, DATA
,
1849 "data: %s: send current buffer %d\n",
1851 ret
= mwifiex_write_data_to_card(adapter
, payload
, pkt_len
,
1852 adapter
->ioport
+ port
);
1855 if (f_postcopy_cur_buf
) {
1856 mwifiex_dbg(adapter
, DATA
,
1857 "data: %s: postcopy current buffer\n",
1859 MP_TX_AGGR_BUF_PUT(card
, payload
, pkt_len
, port
);
1866 * This function downloads data from driver to card.
1868 * Both commands and data packets are transferred to the card by this
1871 * This function adds the SDIO specific header to the front of the buffer
1872 * before transferring. The header contains the length of the packet and
1873 * the type. The firmware handles the packets based upon this set type.
1875 static int mwifiex_sdio_host_to_card(struct mwifiex_adapter
*adapter
,
1876 u8 type
, struct sk_buff
*skb
,
1877 struct mwifiex_tx_param
*tx_param
)
1879 struct sdio_mmc_card
*card
= adapter
->card
;
1883 u32 port
= CTRL_PORT
;
1884 u8
*payload
= (u8
*)skb
->data
;
1885 u32 pkt_len
= skb
->len
;
1887 /* Allocate buffer and copy payload */
1888 blk_size
= MWIFIEX_SDIO_BLOCK_SIZE
;
1889 buf_block_len
= (pkt_len
+ blk_size
- 1) / blk_size
;
1890 put_unaligned_le16((u16
)pkt_len
, payload
+ 0);
1891 put_unaligned_le16((u32
)type
, payload
+ 2);
1895 * This is SDIO specific header
1897 * u16 type (MWIFIEX_TYPE_DATA = 0, MWIFIEX_TYPE_CMD = 1,
1898 * MWIFIEX_TYPE_EVENT = 3)
1900 if (type
== MWIFIEX_TYPE_DATA
) {
1901 ret
= mwifiex_get_wr_port_data(adapter
, &port
);
1903 mwifiex_dbg(adapter
, ERROR
,
1904 "%s: no wr_port available\n",
1909 adapter
->cmd_sent
= true;
1910 /* Type must be MWIFIEX_TYPE_CMD */
1912 if (pkt_len
<= adapter
->intf_hdr_len
||
1913 pkt_len
> MWIFIEX_UPLD_SIZE
)
1914 mwifiex_dbg(adapter
, ERROR
,
1915 "%s: payload=%p, nb=%d\n",
1916 __func__
, payload
, pkt_len
);
1918 if (card
->supports_sdio_new_mode
)
1919 port
= CMD_PORT_SLCT
;
1922 /* Transfer data to card */
1923 pkt_len
= buf_block_len
* blk_size
;
1926 ret
= mwifiex_host_to_card_mp_aggr(adapter
, payload
, pkt_len
,
1927 port
, tx_param
->next_pkt_len
1930 ret
= mwifiex_host_to_card_mp_aggr(adapter
, payload
, pkt_len
,
1934 if (type
== MWIFIEX_TYPE_CMD
)
1935 adapter
->cmd_sent
= false;
1936 if (type
== MWIFIEX_TYPE_DATA
) {
1937 adapter
->data_sent
= false;
1938 /* restore curr_wr_port in error cases */
1939 card
->curr_wr_port
= port
;
1940 card
->mp_wr_bitmap
|= (u32
)(1 << card
->curr_wr_port
);
1943 if (type
== MWIFIEX_TYPE_DATA
) {
1944 if (!(card
->mp_wr_bitmap
& (1 << card
->curr_wr_port
)))
1945 adapter
->data_sent
= true;
1947 adapter
->data_sent
= false;
1955 * This function allocates the MPA Tx and Rx buffers.
1957 static int mwifiex_alloc_sdio_mpa_buffers(struct mwifiex_adapter
*adapter
,
1958 u32 mpa_tx_buf_size
, u32 mpa_rx_buf_size
)
1960 struct sdio_mmc_card
*card
= adapter
->card
;
1964 card
->mpa_tx
.buf
= kzalloc(mpa_tx_buf_size
, GFP_KERNEL
);
1965 if (!card
->mpa_tx
.buf
) {
1970 card
->mpa_tx
.buf_size
= mpa_tx_buf_size
;
1972 rx_buf_size
= max_t(u32
, mpa_rx_buf_size
,
1973 (u32
)SDIO_MAX_AGGR_BUF_SIZE
);
1974 card
->mpa_rx
.buf
= kzalloc(rx_buf_size
, GFP_KERNEL
);
1975 if (!card
->mpa_rx
.buf
) {
1980 card
->mpa_rx
.buf_size
= rx_buf_size
;
1984 kfree(card
->mpa_tx
.buf
);
1985 kfree(card
->mpa_rx
.buf
);
1986 card
->mpa_tx
.buf_size
= 0;
1987 card
->mpa_rx
.buf_size
= 0;
1994 * This function unregisters the SDIO device.
1996 * The SDIO IRQ is released, the function is disabled and driver
1997 * data is set to null.
2000 mwifiex_unregister_dev(struct mwifiex_adapter
*adapter
)
2002 struct sdio_mmc_card
*card
= adapter
->card
;
2004 if (adapter
->card
) {
2005 card
->adapter
= NULL
;
2006 sdio_claim_host(card
->func
);
2007 sdio_disable_func(card
->func
);
2008 sdio_release_host(card
->func
);
2013 * This function registers the SDIO device.
2015 * SDIO IRQ is claimed, block size is set and driver data is initialized.
2017 static int mwifiex_register_dev(struct mwifiex_adapter
*adapter
)
2020 struct sdio_mmc_card
*card
= adapter
->card
;
2021 struct sdio_func
*func
= card
->func
;
2023 /* save adapter pointer in card */
2024 card
->adapter
= adapter
;
2025 adapter
->tx_buf_size
= card
->tx_buf_size
;
2027 sdio_claim_host(func
);
2029 /* Set block size */
2030 ret
= sdio_set_block_size(card
->func
, MWIFIEX_SDIO_BLOCK_SIZE
);
2031 sdio_release_host(func
);
2033 mwifiex_dbg(adapter
, ERROR
,
2034 "cannot set SDIO block size\n");
2038 strcpy(adapter
->fw_name
, card
->firmware
);
2039 if (card
->fw_dump_enh
) {
2040 adapter
->mem_type_mapping_tbl
= generic_mem_type_map
;
2041 adapter
->num_mem_types
= 1;
2043 adapter
->mem_type_mapping_tbl
= mem_type_mapping_tbl
;
2044 adapter
->num_mem_types
= ARRAY_SIZE(mem_type_mapping_tbl
);
2051 * This function initializes the SDIO driver.
2053 * The following initializations steps are followed -
2054 * - Read the Host interrupt status register to acknowledge
2055 * the first interrupt got from bootloader
2056 * - Disable host interrupt mask register
2058 * - Initialize SDIO variables in card
2059 * - Allocate MP registers
2060 * - Allocate MPA Tx and Rx buffers
2062 static int mwifiex_init_sdio(struct mwifiex_adapter
*adapter
)
2064 struct sdio_mmc_card
*card
= adapter
->card
;
2065 const struct mwifiex_sdio_card_reg
*reg
= card
->reg
;
2069 sdio_set_drvdata(card
->func
, card
);
2072 * Read the host_int_status_reg for ACK the first interrupt got
2073 * from the bootloader. If we don't do this we get a interrupt
2074 * as soon as we register the irq.
2076 mwifiex_read_reg(adapter
, card
->reg
->host_int_status_reg
, &sdio_ireg
);
2078 /* Get SDIO ioport */
2079 mwifiex_init_sdio_ioport(adapter
);
2081 /* Initialize SDIO variables in card */
2082 card
->mp_rd_bitmap
= 0;
2083 card
->mp_wr_bitmap
= 0;
2084 card
->curr_rd_port
= reg
->start_rd_port
;
2085 card
->curr_wr_port
= reg
->start_wr_port
;
2087 card
->mp_data_port_mask
= reg
->data_port_mask
;
2089 card
->mpa_tx
.buf_len
= 0;
2090 card
->mpa_tx
.pkt_cnt
= 0;
2091 card
->mpa_tx
.start_port
= 0;
2093 card
->mpa_tx
.enabled
= 1;
2094 card
->mpa_tx
.pkt_aggr_limit
= card
->mp_agg_pkt_limit
;
2096 card
->mpa_rx
.buf_len
= 0;
2097 card
->mpa_rx
.pkt_cnt
= 0;
2098 card
->mpa_rx
.start_port
= 0;
2100 card
->mpa_rx
.enabled
= 1;
2101 card
->mpa_rx
.pkt_aggr_limit
= card
->mp_agg_pkt_limit
;
2103 /* Allocate buffers for SDIO MP-A */
2104 card
->mp_regs
= kzalloc(reg
->max_mp_regs
, GFP_KERNEL
);
2108 /* Allocate skb pointer buffers */
2109 card
->mpa_rx
.skb_arr
= kcalloc(card
->mp_agg_pkt_limit
, sizeof(void *),
2111 if (!card
->mpa_rx
.skb_arr
) {
2112 kfree(card
->mp_regs
);
2116 card
->mpa_rx
.len_arr
= kcalloc(card
->mp_agg_pkt_limit
,
2117 sizeof(*card
->mpa_rx
.len_arr
),
2119 if (!card
->mpa_rx
.len_arr
) {
2120 kfree(card
->mp_regs
);
2121 kfree(card
->mpa_rx
.skb_arr
);
2125 ret
= mwifiex_alloc_sdio_mpa_buffers(adapter
,
2126 card
->mp_tx_agg_buf_size
,
2127 card
->mp_rx_agg_buf_size
);
2129 /* Allocate 32k MPA Tx/Rx buffers if 64k memory allocation fails */
2130 if (ret
&& (card
->mp_tx_agg_buf_size
== MWIFIEX_MP_AGGR_BUF_SIZE_MAX
||
2131 card
->mp_rx_agg_buf_size
== MWIFIEX_MP_AGGR_BUF_SIZE_MAX
)) {
2132 /* Disable rx single port aggregation */
2133 adapter
->host_disable_sdio_rx_aggr
= true;
2135 ret
= mwifiex_alloc_sdio_mpa_buffers
2136 (adapter
, MWIFIEX_MP_AGGR_BUF_SIZE_32K
,
2137 MWIFIEX_MP_AGGR_BUF_SIZE_32K
);
2139 /* Disable multi port aggregation */
2140 card
->mpa_tx
.enabled
= 0;
2141 card
->mpa_rx
.enabled
= 0;
2145 adapter
->auto_tdls
= card
->can_auto_tdls
;
2146 adapter
->ext_scan
= card
->can_ext_scan
;
2151 * This function resets the MPA Tx and Rx buffers.
2153 static void mwifiex_cleanup_mpa_buf(struct mwifiex_adapter
*adapter
)
2155 struct sdio_mmc_card
*card
= adapter
->card
;
2157 MP_TX_AGGR_BUF_RESET(card
);
2158 MP_RX_AGGR_BUF_RESET(card
);
2162 * This function cleans up the allocated card buffers.
2164 * The following are freed by this function -
2169 static void mwifiex_cleanup_sdio(struct mwifiex_adapter
*adapter
)
2171 struct sdio_mmc_card
*card
= adapter
->card
;
2173 cancel_work_sync(&card
->work
);
2175 kfree(card
->mp_regs
);
2176 kfree(card
->mpa_rx
.skb_arr
);
2177 kfree(card
->mpa_rx
.len_arr
);
2178 kfree(card
->mpa_tx
.buf
);
2179 kfree(card
->mpa_rx
.buf
);
2183 * This function updates the MP end port in card.
2186 mwifiex_update_mp_end_port(struct mwifiex_adapter
*adapter
, u16 port
)
2188 struct sdio_mmc_card
*card
= adapter
->card
;
2189 const struct mwifiex_sdio_card_reg
*reg
= card
->reg
;
2192 card
->mp_end_port
= port
;
2194 card
->mp_data_port_mask
= reg
->data_port_mask
;
2196 if (reg
->start_wr_port
) {
2197 for (i
= 1; i
<= card
->max_ports
- card
->mp_end_port
; i
++)
2198 card
->mp_data_port_mask
&=
2199 ~(1 << (card
->max_ports
- i
));
2202 card
->curr_wr_port
= reg
->start_wr_port
;
2204 mwifiex_dbg(adapter
, CMD
,
2205 "cmd: mp_end_port %d, data port mask 0x%x\n",
2206 port
, card
->mp_data_port_mask
);
2209 static void mwifiex_sdio_card_reset_work(struct mwifiex_adapter
*adapter
)
2211 struct sdio_mmc_card
*card
= adapter
->card
;
2212 struct sdio_func
*func
= card
->func
;
2215 mwifiex_shutdown_sw(adapter
);
2217 /* power cycle the adapter */
2218 sdio_claim_host(func
);
2219 mmc_hw_reset(func
->card
->host
);
2220 sdio_release_host(func
);
2222 /* Previous save_adapter won't be valid after this. We will cancel
2223 * pending work requests.
2225 clear_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP
, &card
->work_flags
);
2226 clear_bit(MWIFIEX_IFACE_WORK_CARD_RESET
, &card
->work_flags
);
2228 ret
= mwifiex_reinit_sw(adapter
);
2230 dev_err(&func
->dev
, "reinit failed: %d\n", ret
);
2233 /* This function read/write firmware */
2235 rdwr_status
mwifiex_sdio_rdwr_firmware(struct mwifiex_adapter
*adapter
,
2238 struct sdio_mmc_card
*card
= adapter
->card
;
2242 sdio_writeb(card
->func
, card
->reg
->fw_dump_host_ready
,
2243 card
->reg
->fw_dump_ctrl
, &ret
);
2245 mwifiex_dbg(adapter
, ERROR
, "SDIO Write ERR\n");
2246 return RDWR_STATUS_FAILURE
;
2248 for (tries
= 0; tries
< MAX_POLL_TRIES
; tries
++) {
2249 ctrl_data
= sdio_readb(card
->func
, card
->reg
->fw_dump_ctrl
,
2252 mwifiex_dbg(adapter
, ERROR
, "SDIO read err\n");
2253 return RDWR_STATUS_FAILURE
;
2255 if (ctrl_data
== FW_DUMP_DONE
)
2257 if (doneflag
&& ctrl_data
== doneflag
)
2258 return RDWR_STATUS_DONE
;
2259 if (ctrl_data
!= card
->reg
->fw_dump_host_ready
) {
2260 mwifiex_dbg(adapter
, WARN
,
2261 "The ctrl reg was changed, re-try again\n");
2262 sdio_writeb(card
->func
, card
->reg
->fw_dump_host_ready
,
2263 card
->reg
->fw_dump_ctrl
, &ret
);
2265 mwifiex_dbg(adapter
, ERROR
, "SDIO write err\n");
2266 return RDWR_STATUS_FAILURE
;
2269 usleep_range(100, 200);
2271 if (ctrl_data
== card
->reg
->fw_dump_host_ready
) {
2272 mwifiex_dbg(adapter
, ERROR
,
2273 "Fail to pull ctrl_data\n");
2274 return RDWR_STATUS_FAILURE
;
2277 return RDWR_STATUS_SUCCESS
;
2280 /* This function dump firmware memory to file */
2281 static void mwifiex_sdio_fw_dump(struct mwifiex_adapter
*adapter
)
2283 struct sdio_mmc_card
*card
= adapter
->card
;
2285 unsigned int reg
, reg_start
, reg_end
;
2286 u8
*dbg_ptr
, *end_ptr
, dump_num
, idx
, i
, read_reg
, doneflag
= 0;
2287 enum rdwr_status stat
;
2290 if (!card
->can_dump_fw
)
2293 for (idx
= 0; idx
< ARRAY_SIZE(mem_type_mapping_tbl
); idx
++) {
2294 struct memory_type_mapping
*entry
= &mem_type_mapping_tbl
[idx
];
2296 if (entry
->mem_ptr
) {
2297 vfree(entry
->mem_ptr
);
2298 entry
->mem_ptr
= NULL
;
2300 entry
->mem_size
= 0;
2303 mwifiex_pm_wakeup_card(adapter
);
2304 sdio_claim_host(card
->func
);
2306 mwifiex_dbg(adapter
, MSG
, "== mwifiex firmware dump start ==\n");
2308 stat
= mwifiex_sdio_rdwr_firmware(adapter
, doneflag
);
2309 if (stat
== RDWR_STATUS_FAILURE
)
2312 reg
= card
->reg
->fw_dump_start
;
2313 /* Read the number of the memories which will dump */
2314 dump_num
= sdio_readb(card
->func
, reg
, &ret
);
2316 mwifiex_dbg(adapter
, ERROR
, "SDIO read memory length err\n");
2320 /* Read the length of every memory which will dump */
2321 for (idx
= 0; idx
< dump_num
; idx
++) {
2322 struct memory_type_mapping
*entry
= &mem_type_mapping_tbl
[idx
];
2324 stat
= mwifiex_sdio_rdwr_firmware(adapter
, doneflag
);
2325 if (stat
== RDWR_STATUS_FAILURE
)
2329 reg
= card
->reg
->fw_dump_start
;
2330 for (i
= 0; i
< 4; i
++) {
2331 read_reg
= sdio_readb(card
->func
, reg
, &ret
);
2333 mwifiex_dbg(adapter
, ERROR
, "SDIO read err\n");
2336 memory_size
|= (read_reg
<< i
*8);
2340 if (memory_size
== 0) {
2341 mwifiex_dbg(adapter
, DUMP
, "Firmware dump Finished!\n");
2342 ret
= mwifiex_write_reg(adapter
,
2343 card
->reg
->fw_dump_ctrl
,
2346 mwifiex_dbg(adapter
, ERROR
, "SDIO write err\n");
2352 mwifiex_dbg(adapter
, DUMP
,
2353 "%s_SIZE=0x%x\n", entry
->mem_name
, memory_size
);
2354 entry
->mem_ptr
= vmalloc(memory_size
+ 1);
2355 entry
->mem_size
= memory_size
;
2356 if (!entry
->mem_ptr
) {
2357 mwifiex_dbg(adapter
, ERROR
, "Vmalloc %s failed\n",
2361 dbg_ptr
= entry
->mem_ptr
;
2362 end_ptr
= dbg_ptr
+ memory_size
;
2364 doneflag
= entry
->done_flag
;
2365 mwifiex_dbg(adapter
, DUMP
,
2366 "Start %s output, please wait...\n",
2370 stat
= mwifiex_sdio_rdwr_firmware(adapter
, doneflag
);
2371 if (stat
== RDWR_STATUS_FAILURE
)
2374 reg_start
= card
->reg
->fw_dump_start
;
2375 reg_end
= card
->reg
->fw_dump_end
;
2376 for (reg
= reg_start
; reg
<= reg_end
; reg
++) {
2377 *dbg_ptr
= sdio_readb(card
->func
, reg
, &ret
);
2379 mwifiex_dbg(adapter
, ERROR
,
2383 if (dbg_ptr
< end_ptr
)
2386 mwifiex_dbg(adapter
, ERROR
,
2387 "Allocated buf not enough\n");
2390 if (stat
!= RDWR_STATUS_DONE
)
2393 mwifiex_dbg(adapter
, DUMP
, "%s done: size=0x%tx\n",
2394 entry
->mem_name
, dbg_ptr
- entry
->mem_ptr
);
2398 mwifiex_dbg(adapter
, MSG
, "== mwifiex firmware dump end ==\n");
2401 sdio_release_host(card
->func
);
2404 static void mwifiex_sdio_generic_fw_dump(struct mwifiex_adapter
*adapter
)
2406 struct sdio_mmc_card
*card
= adapter
->card
;
2407 struct memory_type_mapping
*entry
= &generic_mem_type_map
[0];
2408 unsigned int reg
, reg_start
, reg_end
;
2409 u8 start_flag
= 0, done_flag
= 0;
2410 u8
*dbg_ptr
, *end_ptr
;
2411 enum rdwr_status stat
;
2412 int ret
= -1, tries
;
2414 if (!card
->fw_dump_enh
)
2417 if (entry
->mem_ptr
) {
2418 vfree(entry
->mem_ptr
);
2419 entry
->mem_ptr
= NULL
;
2421 entry
->mem_size
= 0;
2423 mwifiex_pm_wakeup_card(adapter
);
2424 sdio_claim_host(card
->func
);
2426 mwifiex_dbg(adapter
, MSG
, "== mwifiex firmware dump start ==\n");
2428 stat
= mwifiex_sdio_rdwr_firmware(adapter
, done_flag
);
2429 if (stat
== RDWR_STATUS_FAILURE
)
2432 reg_start
= card
->reg
->fw_dump_start
;
2433 reg_end
= card
->reg
->fw_dump_end
;
2434 for (reg
= reg_start
; reg
<= reg_end
; reg
++) {
2435 for (tries
= 0; tries
< MAX_POLL_TRIES
; tries
++) {
2436 start_flag
= sdio_readb(card
->func
, reg
, &ret
);
2438 mwifiex_dbg(adapter
, ERROR
,
2442 if (start_flag
== 0)
2444 if (tries
== MAX_POLL_TRIES
) {
2445 mwifiex_dbg(adapter
, ERROR
,
2446 "FW not ready to dump\n");
2451 usleep_range(100, 200);
2454 entry
->mem_ptr
= vmalloc(0xf0000 + 1);
2455 if (!entry
->mem_ptr
) {
2459 dbg_ptr
= entry
->mem_ptr
;
2460 entry
->mem_size
= 0xf0000;
2461 end_ptr
= dbg_ptr
+ entry
->mem_size
;
2463 done_flag
= entry
->done_flag
;
2464 mwifiex_dbg(adapter
, DUMP
,
2465 "Start %s output, please wait...\n", entry
->mem_name
);
2468 stat
= mwifiex_sdio_rdwr_firmware(adapter
, done_flag
);
2469 if (stat
== RDWR_STATUS_FAILURE
)
2471 for (reg
= reg_start
; reg
<= reg_end
; reg
++) {
2472 *dbg_ptr
= sdio_readb(card
->func
, reg
, &ret
);
2474 mwifiex_dbg(adapter
, ERROR
,
2479 if (dbg_ptr
>= end_ptr
) {
2482 tmp_ptr
= vmalloc(entry
->mem_size
+ 0x4000 + 1);
2486 memcpy(tmp_ptr
, entry
->mem_ptr
,
2488 vfree(entry
->mem_ptr
);
2489 entry
->mem_ptr
= tmp_ptr
;
2491 dbg_ptr
= entry
->mem_ptr
+ entry
->mem_size
;
2492 entry
->mem_size
+= 0x4000;
2493 end_ptr
= entry
->mem_ptr
+ entry
->mem_size
;
2496 if (stat
== RDWR_STATUS_DONE
) {
2497 entry
->mem_size
= dbg_ptr
- entry
->mem_ptr
;
2498 mwifiex_dbg(adapter
, DUMP
, "dump %s done size=0x%x\n",
2499 entry
->mem_name
, entry
->mem_size
);
2504 mwifiex_dbg(adapter
, MSG
, "== mwifiex firmware dump end ==\n");
2508 mwifiex_dbg(adapter
, ERROR
, "firmware dump failed\n");
2509 if (entry
->mem_ptr
) {
2510 vfree(entry
->mem_ptr
);
2511 entry
->mem_ptr
= NULL
;
2513 entry
->mem_size
= 0;
2515 sdio_release_host(card
->func
);
2518 static void mwifiex_sdio_device_dump_work(struct mwifiex_adapter
*adapter
)
2520 struct sdio_mmc_card
*card
= adapter
->card
;
2522 adapter
->devdump_data
= vzalloc(MWIFIEX_FW_DUMP_SIZE
);
2523 if (!adapter
->devdump_data
) {
2524 mwifiex_dbg(adapter
, ERROR
,
2525 "vzalloc devdump data failure!\n");
2529 mwifiex_drv_info_dump(adapter
);
2530 if (card
->fw_dump_enh
)
2531 mwifiex_sdio_generic_fw_dump(adapter
);
2533 mwifiex_sdio_fw_dump(adapter
);
2534 mwifiex_prepare_fw_dump_info(adapter
);
2535 mwifiex_upload_device_dump(adapter
);
2538 static void mwifiex_sdio_work(struct work_struct
*work
)
2540 struct sdio_mmc_card
*card
=
2541 container_of(work
, struct sdio_mmc_card
, work
);
2543 if (test_and_clear_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP
,
2545 mwifiex_sdio_device_dump_work(card
->adapter
);
2546 if (test_and_clear_bit(MWIFIEX_IFACE_WORK_CARD_RESET
,
2548 mwifiex_sdio_card_reset_work(card
->adapter
);
2551 /* This function resets the card */
2552 static void mwifiex_sdio_card_reset(struct mwifiex_adapter
*adapter
)
2554 struct sdio_mmc_card
*card
= adapter
->card
;
2556 if (!test_and_set_bit(MWIFIEX_IFACE_WORK_CARD_RESET
, &card
->work_flags
))
2557 schedule_work(&card
->work
);
2560 /* This function dumps FW information */
2561 static void mwifiex_sdio_device_dump(struct mwifiex_adapter
*adapter
)
2563 struct sdio_mmc_card
*card
= adapter
->card
;
2565 if (!test_and_set_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP
,
2567 schedule_work(&card
->work
);
2570 /* Function to dump SDIO function registers and SDIO scratch registers in case
2574 mwifiex_sdio_reg_dump(struct mwifiex_adapter
*adapter
, char *drv_buf
)
2577 struct sdio_mmc_card
*cardp
= adapter
->card
;
2579 u8 count
, func
, data
, index
= 0, size
= 0;
2580 u8 reg
, reg_start
, reg_end
;
2581 char buf
[256], *ptr
;
2586 mwifiex_dbg(adapter
, MSG
, "SDIO register dump start\n");
2588 mwifiex_pm_wakeup_card(adapter
);
2590 sdio_claim_host(cardp
->func
);
2592 for (count
= 0; count
< 5; count
++) {
2593 memset(buf
, 0, sizeof(buf
));
2598 /* Read the registers of SDIO function0 */
2604 /* Read the registers of SDIO function1 */
2606 reg_start
= cardp
->reg
->func1_dump_reg_start
;
2607 reg_end
= cardp
->reg
->func1_dump_reg_end
;
2612 reg_start
= cardp
->reg
->func1_spec_reg_table
[index
++];
2613 size
= cardp
->reg
->func1_spec_reg_num
;
2614 reg_end
= cardp
->reg
->func1_spec_reg_table
[size
-1];
2617 /* Read the scratch registers of SDIO function1 */
2621 reg_start
= cardp
->reg
->func1_scratch_reg
;
2622 reg_end
= reg_start
+ MWIFIEX_SDIO_SCRATCH_SIZE
;
2626 ptr
+= sprintf(ptr
, "SDIO Func%d (%#x-%#x): ",
2627 func
, reg_start
, reg_end
);
2629 ptr
+= sprintf(ptr
, "SDIO Func%d: ", func
);
2631 for (reg
= reg_start
; reg
<= reg_end
;) {
2633 data
= sdio_f0_readb(cardp
->func
, reg
, &ret
);
2635 data
= sdio_readb(cardp
->func
, reg
, &ret
);
2638 ptr
+= sprintf(ptr
, "(%#x) ", reg
);
2640 ptr
+= sprintf(ptr
, "%02x ", data
);
2642 ptr
+= sprintf(ptr
, "ERR");
2646 if (count
== 2 && reg
< reg_end
)
2647 reg
= cardp
->reg
->func1_spec_reg_table
[index
++];
2652 mwifiex_dbg(adapter
, MSG
, "%s\n", buf
);
2653 p
+= sprintf(p
, "%s\n", buf
);
2656 sdio_release_host(cardp
->func
);
2658 mwifiex_dbg(adapter
, MSG
, "SDIO register dump end\n");
2663 /* sdio device/function initialization, code is extracted
2664 * from init_if handler and register_dev handler.
2666 static void mwifiex_sdio_up_dev(struct mwifiex_adapter
*adapter
)
2668 struct sdio_mmc_card
*card
= adapter
->card
;
2671 sdio_claim_host(card
->func
);
2672 sdio_enable_func(card
->func
);
2673 sdio_set_block_size(card
->func
, MWIFIEX_SDIO_BLOCK_SIZE
);
2674 sdio_release_host(card
->func
);
2676 /* tx_buf_size might be changed to 3584 by firmware during
2677 * data transfer, we will reset to default size.
2679 adapter
->tx_buf_size
= card
->tx_buf_size
;
2681 /* Read the host_int_status_reg for ACK the first interrupt got
2682 * from the bootloader. If we don't do this we get a interrupt
2683 * as soon as we register the irq.
2685 mwifiex_read_reg(adapter
, card
->reg
->host_int_status_reg
, &sdio_ireg
);
2687 mwifiex_init_sdio_ioport(adapter
);
2690 static struct mwifiex_if_ops sdio_ops
= {
2691 .init_if
= mwifiex_init_sdio
,
2692 .cleanup_if
= mwifiex_cleanup_sdio
,
2693 .check_fw_status
= mwifiex_check_fw_status
,
2694 .check_winner_status
= mwifiex_check_winner_status
,
2695 .prog_fw
= mwifiex_prog_fw_w_helper
,
2696 .register_dev
= mwifiex_register_dev
,
2697 .unregister_dev
= mwifiex_unregister_dev
,
2698 .enable_int
= mwifiex_sdio_enable_host_int
,
2699 .disable_int
= mwifiex_sdio_disable_host_int
,
2700 .process_int_status
= mwifiex_process_int_status
,
2701 .host_to_card
= mwifiex_sdio_host_to_card
,
2702 .wakeup
= mwifiex_pm_wakeup_card
,
2703 .wakeup_complete
= mwifiex_pm_wakeup_card_complete
,
2706 .update_mp_end_port
= mwifiex_update_mp_end_port
,
2707 .cleanup_mpa_buf
= mwifiex_cleanup_mpa_buf
,
2708 .cmdrsp_complete
= mwifiex_sdio_cmdrsp_complete
,
2709 .event_complete
= mwifiex_sdio_event_complete
,
2710 .dnld_fw
= mwifiex_sdio_dnld_fw
,
2711 .card_reset
= mwifiex_sdio_card_reset
,
2712 .reg_dump
= mwifiex_sdio_reg_dump
,
2713 .device_dump
= mwifiex_sdio_device_dump
,
2714 .deaggr_pkt
= mwifiex_deaggr_sdio_pkt
,
2715 .up_dev
= mwifiex_sdio_up_dev
,
2718 module_driver(mwifiex_sdio
, sdio_register_driver
, sdio_unregister_driver
);
2720 MODULE_AUTHOR("Marvell International Ltd.");
2721 MODULE_DESCRIPTION("Marvell WiFi-Ex SDIO Driver version " SDIO_VERSION
);
2722 MODULE_VERSION(SDIO_VERSION
);
2723 MODULE_LICENSE("GPL v2");
2724 MODULE_FIRMWARE(SD8786_DEFAULT_FW_NAME
);
2725 MODULE_FIRMWARE(SD8787_DEFAULT_FW_NAME
);
2726 MODULE_FIRMWARE(SD8797_DEFAULT_FW_NAME
);
2727 MODULE_FIRMWARE(SD8897_DEFAULT_FW_NAME
);
2728 MODULE_FIRMWARE(SD8887_DEFAULT_FW_NAME
);
2729 MODULE_FIRMWARE(SD8997_DEFAULT_FW_NAME
);