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 const struct mwifiex_sdio_card_reg mwifiex_reg_sd87xx = {
44 .host_int_enable = UP_LD_HOST_INT_MASK | DN_LD_HOST_INT_MASK,
45 .host_int_rsr_reg = 0x1,
46 .host_int_mask_reg = 0x02,
47 .host_int_status_reg = 0x03,
50 .sdio_int_mask = 0x3f,
51 .data_port_mask = 0x0000fffe,
52 .io_port_0_reg = 0x78,
53 .io_port_1_reg = 0x79,
54 .io_port_2_reg = 0x7A,
62 .card_misc_cfg_reg = 0x6c,
63 .func1_dump_reg_start = 0x0,
64 .func1_dump_reg_end = 0x9,
65 .func1_scratch_reg = 0x60,
66 .func1_spec_reg_num = 5,
67 .func1_spec_reg_table = {0x28, 0x30, 0x34, 0x38, 0x3c},
70 static const struct mwifiex_sdio_card_reg mwifiex_reg_sd8897 = {
76 .host_int_enable = UP_LD_HOST_INT_MASK | DN_LD_HOST_INT_MASK |
77 CMD_PORT_UPLD_INT_MASK | CMD_PORT_DNLD_INT_MASK,
78 .host_int_rsr_reg = 0x1,
79 .host_int_status_reg = 0x03,
80 .host_int_mask_reg = 0x02,
83 .sdio_int_mask = 0xff,
84 .data_port_mask = 0xffffffff,
85 .io_port_0_reg = 0xD8,
86 .io_port_1_reg = 0xD9,
87 .io_port_2_reg = 0xDA,
99 .card_misc_cfg_reg = 0xcc,
100 .card_cfg_2_1_reg = 0xcd,
101 .cmd_rd_len_0 = 0xb4,
102 .cmd_rd_len_1 = 0xb5,
103 .cmd_rd_len_2 = 0xb6,
104 .cmd_rd_len_3 = 0xb7,
109 .fw_dump_host_ready = 0xee,
110 .fw_dump_ctrl = 0xe2,
111 .fw_dump_start = 0xe3,
113 .func1_dump_reg_start = 0x0,
114 .func1_dump_reg_end = 0xb,
115 .func1_scratch_reg = 0xc0,
116 .func1_spec_reg_num = 8,
117 .func1_spec_reg_table = {0x4C, 0x50, 0x54, 0x55, 0x58,
121 static const struct mwifiex_sdio_card_reg mwifiex_reg_sd8977 = {
127 .host_int_enable = UP_LD_HOST_INT_MASK | DN_LD_HOST_INT_MASK |
128 CMD_PORT_UPLD_INT_MASK | CMD_PORT_DNLD_INT_MASK,
129 .host_int_rsr_reg = 0x4,
130 .host_int_status_reg = 0x0C,
131 .host_int_mask_reg = 0x08,
132 .status_reg_0 = 0xE8,
133 .status_reg_1 = 0xE9,
134 .sdio_int_mask = 0xff,
135 .data_port_mask = 0xffffffff,
136 .io_port_0_reg = 0xE4,
137 .io_port_1_reg = 0xE5,
138 .io_port_2_reg = 0xE6,
142 .rd_bitmap_1l = 0x12,
143 .rd_bitmap_1u = 0x13,
146 .wr_bitmap_1l = 0x16,
147 .wr_bitmap_1u = 0x17,
150 .card_misc_cfg_reg = 0xd8,
151 .card_cfg_2_1_reg = 0xd9,
152 .cmd_rd_len_0 = 0xc0,
153 .cmd_rd_len_1 = 0xc1,
154 .cmd_rd_len_2 = 0xc2,
155 .cmd_rd_len_3 = 0xc3,
160 .fw_dump_host_ready = 0xcc,
161 .fw_dump_ctrl = 0xf0,
162 .fw_dump_start = 0xf1,
164 .func1_dump_reg_start = 0x10,
165 .func1_dump_reg_end = 0x17,
166 .func1_scratch_reg = 0xe8,
167 .func1_spec_reg_num = 13,
168 .func1_spec_reg_table = {0x08, 0x58, 0x5C, 0x5D,
169 0x60, 0x61, 0x62, 0x64,
170 0x65, 0x66, 0x68, 0x69,
174 static const struct mwifiex_sdio_card_reg mwifiex_reg_sd8997 = {
180 .host_int_enable = UP_LD_HOST_INT_MASK | DN_LD_HOST_INT_MASK |
181 CMD_PORT_UPLD_INT_MASK | CMD_PORT_DNLD_INT_MASK,
182 .host_int_rsr_reg = 0x4,
183 .host_int_status_reg = 0x0C,
184 .host_int_mask_reg = 0x08,
185 .status_reg_0 = 0xE8,
186 .status_reg_1 = 0xE9,
187 .sdio_int_mask = 0xff,
188 .data_port_mask = 0xffffffff,
189 .io_port_0_reg = 0xE4,
190 .io_port_1_reg = 0xE5,
191 .io_port_2_reg = 0xE6,
195 .rd_bitmap_1l = 0x12,
196 .rd_bitmap_1u = 0x13,
199 .wr_bitmap_1l = 0x16,
200 .wr_bitmap_1u = 0x17,
203 .card_misc_cfg_reg = 0xd8,
204 .card_cfg_2_1_reg = 0xd9,
205 .cmd_rd_len_0 = 0xc0,
206 .cmd_rd_len_1 = 0xc1,
207 .cmd_rd_len_2 = 0xc2,
208 .cmd_rd_len_3 = 0xc3,
213 .fw_dump_host_ready = 0xcc,
214 .fw_dump_ctrl = 0xf0,
215 .fw_dump_start = 0xf1,
217 .func1_dump_reg_start = 0x10,
218 .func1_dump_reg_end = 0x17,
219 .func1_scratch_reg = 0xe8,
220 .func1_spec_reg_num = 13,
221 .func1_spec_reg_table = {0x08, 0x58, 0x5C, 0x5D,
222 0x60, 0x61, 0x62, 0x64,
223 0x65, 0x66, 0x68, 0x69,
227 static const struct mwifiex_sdio_card_reg mwifiex_reg_sd8887 = {
233 .host_int_enable = UP_LD_HOST_INT_MASK | DN_LD_HOST_INT_MASK |
234 CMD_PORT_UPLD_INT_MASK | CMD_PORT_DNLD_INT_MASK,
235 .host_int_rsr_reg = 0x4,
236 .host_int_status_reg = 0x0C,
237 .host_int_mask_reg = 0x08,
238 .status_reg_0 = 0x90,
239 .status_reg_1 = 0x91,
240 .sdio_int_mask = 0xff,
241 .data_port_mask = 0xffffffff,
242 .io_port_0_reg = 0xE4,
243 .io_port_1_reg = 0xE5,
244 .io_port_2_reg = 0xE6,
248 .rd_bitmap_1l = 0x12,
249 .rd_bitmap_1u = 0x13,
252 .wr_bitmap_1l = 0x16,
253 .wr_bitmap_1u = 0x17,
256 .card_misc_cfg_reg = 0xd8,
257 .card_cfg_2_1_reg = 0xd9,
258 .cmd_rd_len_0 = 0xc0,
259 .cmd_rd_len_1 = 0xc1,
260 .cmd_rd_len_2 = 0xc2,
261 .cmd_rd_len_3 = 0xc3,
266 .func1_dump_reg_start = 0x10,
267 .func1_dump_reg_end = 0x17,
268 .func1_scratch_reg = 0x90,
269 .func1_spec_reg_num = 13,
270 .func1_spec_reg_table = {0x08, 0x58, 0x5C, 0x5D, 0x60,
271 0x61, 0x62, 0x64, 0x65, 0x66,
275 static const struct mwifiex_sdio_card_reg mwifiex_reg_sd8987 = {
281 .host_int_enable = UP_LD_HOST_INT_MASK | DN_LD_HOST_INT_MASK |
282 CMD_PORT_UPLD_INT_MASK | CMD_PORT_DNLD_INT_MASK,
283 .host_int_rsr_reg = 0x4,
284 .host_int_status_reg = 0x0C,
285 .host_int_mask_reg = 0x08,
286 .status_reg_0 = 0xE8,
287 .status_reg_1 = 0xE9,
288 .sdio_int_mask = 0xff,
289 .data_port_mask = 0xffffffff,
290 .io_port_0_reg = 0xE4,
291 .io_port_1_reg = 0xE5,
292 .io_port_2_reg = 0xE6,
296 .rd_bitmap_1l = 0x12,
297 .rd_bitmap_1u = 0x13,
300 .wr_bitmap_1l = 0x16,
301 .wr_bitmap_1u = 0x17,
304 .card_misc_cfg_reg = 0xd8,
305 .card_cfg_2_1_reg = 0xd9,
306 .cmd_rd_len_0 = 0xc0,
307 .cmd_rd_len_1 = 0xc1,
308 .cmd_rd_len_2 = 0xc2,
309 .cmd_rd_len_3 = 0xc3,
314 .fw_dump_host_ready = 0xcc,
315 .fw_dump_ctrl = 0xf9,
316 .fw_dump_start = 0xf1,
318 .func1_dump_reg_start = 0x10,
319 .func1_dump_reg_end = 0x17,
320 .func1_scratch_reg = 0xE8,
321 .func1_spec_reg_num = 13,
322 .func1_spec_reg_table = {0x08, 0x58, 0x5C, 0x5D, 0x60,
323 0x61, 0x62, 0x64, 0x65, 0x66,
327 static const struct mwifiex_sdio_device mwifiex_sdio_sd8786 = {
328 .firmware = SD8786_DEFAULT_FW_NAME,
329 .reg = &mwifiex_reg_sd87xx,
331 .mp_agg_pkt_limit = 8,
332 .tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K,
333 .mp_tx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_16K,
334 .mp_rx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_16K,
335 .supports_sdio_new_mode = false,
336 .has_control_mask = true,
337 .can_dump_fw = false,
338 .can_auto_tdls = false,
339 .can_ext_scan = false,
342 static const struct mwifiex_sdio_device mwifiex_sdio_sd8787 = {
343 .firmware = SD8787_DEFAULT_FW_NAME,
344 .reg = &mwifiex_reg_sd87xx,
346 .mp_agg_pkt_limit = 8,
347 .tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K,
348 .mp_tx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_16K,
349 .mp_rx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_16K,
350 .supports_sdio_new_mode = false,
351 .has_control_mask = true,
352 .can_dump_fw = false,
353 .can_auto_tdls = false,
354 .can_ext_scan = true,
357 static const struct mwifiex_sdio_device mwifiex_sdio_sd8797 = {
358 .firmware = SD8797_DEFAULT_FW_NAME,
359 .reg = &mwifiex_reg_sd87xx,
361 .mp_agg_pkt_limit = 8,
362 .tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K,
363 .mp_tx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_16K,
364 .mp_rx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_16K,
365 .supports_sdio_new_mode = false,
366 .has_control_mask = true,
367 .can_dump_fw = false,
368 .can_auto_tdls = false,
369 .can_ext_scan = true,
372 static const struct mwifiex_sdio_device mwifiex_sdio_sd8897 = {
373 .firmware = SD8897_DEFAULT_FW_NAME,
374 .reg = &mwifiex_reg_sd8897,
376 .mp_agg_pkt_limit = 16,
377 .tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_4K,
378 .mp_tx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_MAX,
379 .mp_rx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_MAX,
380 .supports_sdio_new_mode = true,
381 .has_control_mask = false,
383 .can_auto_tdls = false,
384 .can_ext_scan = true,
387 static const struct mwifiex_sdio_device mwifiex_sdio_sd8977 = {
388 .firmware = SD8977_DEFAULT_FW_NAME,
389 .reg = &mwifiex_reg_sd8977,
391 .mp_agg_pkt_limit = 16,
392 .tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_4K,
393 .mp_tx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_MAX,
394 .mp_rx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_MAX,
395 .supports_sdio_new_mode = true,
396 .has_control_mask = false,
399 .can_auto_tdls = false,
400 .can_ext_scan = true,
403 static const struct mwifiex_sdio_device mwifiex_sdio_sd8997 = {
404 .firmware = SD8997_DEFAULT_FW_NAME,
405 .reg = &mwifiex_reg_sd8997,
407 .mp_agg_pkt_limit = 16,
408 .tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_4K,
409 .mp_tx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_MAX,
410 .mp_rx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_MAX,
411 .supports_sdio_new_mode = true,
412 .has_control_mask = false,
415 .can_auto_tdls = false,
416 .can_ext_scan = true,
419 static const struct mwifiex_sdio_device mwifiex_sdio_sd8887 = {
420 .firmware = SD8887_DEFAULT_FW_NAME,
421 .reg = &mwifiex_reg_sd8887,
423 .mp_agg_pkt_limit = 16,
424 .tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K,
425 .mp_tx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_32K,
426 .mp_rx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_32K,
427 .supports_sdio_new_mode = true,
428 .has_control_mask = false,
429 .can_dump_fw = false,
430 .can_auto_tdls = true,
431 .can_ext_scan = true,
434 static const struct mwifiex_sdio_device mwifiex_sdio_sd8987 = {
435 .firmware = SD8987_DEFAULT_FW_NAME,
436 .reg = &mwifiex_reg_sd8987,
438 .mp_agg_pkt_limit = 16,
439 .tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K,
440 .mp_tx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_MAX,
441 .mp_rx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_MAX,
442 .supports_sdio_new_mode = true,
443 .has_control_mask = false,
446 .can_auto_tdls = true,
447 .can_ext_scan = true,
450 static const struct mwifiex_sdio_device mwifiex_sdio_sd8801 = {
451 .firmware = SD8801_DEFAULT_FW_NAME,
452 .reg = &mwifiex_reg_sd87xx,
454 .mp_agg_pkt_limit = 8,
455 .supports_sdio_new_mode = false,
456 .has_control_mask = true,
457 .tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K,
458 .mp_tx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_16K,
459 .mp_rx_agg_buf_size = MWIFIEX_MP_AGGR_BUF_SIZE_16K,
460 .can_dump_fw = false,
461 .can_auto_tdls = false,
462 .can_ext_scan = true,
465 static struct memory_type_mapping generic_mem_type_map[] = {
466 {"DUMP", NULL, 0, 0xDD},
469 static struct memory_type_mapping mem_type_mapping_tbl[] = {
470 {"ITCM", NULL, 0, 0xF0},
471 {"DTCM", NULL, 0, 0xF1},
472 {"SQRAM", NULL, 0, 0xF2},
473 {"APU", NULL, 0, 0xF3},
474 {"CIU", NULL, 0, 0xF4},
475 {"ICU", NULL, 0, 0xF5},
476 {"MAC", NULL, 0, 0xF6},
477 {"EXT7", NULL, 0, 0xF7},
478 {"EXT8", NULL, 0, 0xF8},
479 {"EXT9", NULL, 0, 0xF9},
480 {"EXT10", NULL, 0, 0xFA},
481 {"EXT11", NULL, 0, 0xFB},
482 {"EXT12", NULL, 0, 0xFC},
483 {"EXT13", NULL, 0, 0xFD},
484 {"EXTLAST", NULL, 0, 0xFE},
487 static const struct of_device_id mwifiex_sdio_of_match_table[] = {
488 { .compatible = "marvell,sd8897" },
489 { .compatible = "marvell,sd8997" },
493 /* This function parse device tree node using mmc subnode devicetree API.
494 * The device node is saved in card->plt_of_node.
495 * if the device tree node exist and include interrupts attributes, this
496 * function will also request platform specific wakeup interrupt.
498 static int mwifiex_sdio_probe_of(struct device *dev)
500 if (!of_match_node(mwifiex_sdio_of_match_table, dev->of_node)) {
501 dev_err(dev, "required compatible string missing\n");
511 * This function probes an mwifiex device and registers it. It allocates
512 * the card structure, enables SDIO function number and initiates the
513 * device registration and initialization procedure by adding a logical
517 mwifiex_sdio_probe(struct sdio_func *func, const struct sdio_device_id *id)
520 struct sdio_mmc_card *card = NULL;
522 pr_debug("info: vendor=0x%4.04X device=0x%4.04X class=%d function=%d\n",
523 func->vendor, func->device, func->class, func->num);
525 card = devm_kzalloc(&func->dev, sizeof(*card), GFP_KERNEL);
529 init_completion(&card->fw_done);
533 func->card->quirks |= MMC_QUIRK_BLKSZ_FOR_BYTE_MODE;
535 if (id->driver_data) {
536 struct mwifiex_sdio_device *data = (void *)id->driver_data;
538 card->firmware = data->firmware;
539 card->reg = data->reg;
540 card->max_ports = data->max_ports;
541 card->mp_agg_pkt_limit = data->mp_agg_pkt_limit;
542 card->supports_sdio_new_mode = data->supports_sdio_new_mode;
543 card->has_control_mask = data->has_control_mask;
544 card->tx_buf_size = data->tx_buf_size;
545 card->mp_tx_agg_buf_size = data->mp_tx_agg_buf_size;
546 card->mp_rx_agg_buf_size = data->mp_rx_agg_buf_size;
547 card->can_dump_fw = data->can_dump_fw;
548 card->fw_dump_enh = data->fw_dump_enh;
549 card->can_auto_tdls = data->can_auto_tdls;
550 card->can_ext_scan = data->can_ext_scan;
551 INIT_WORK(&card->work, mwifiex_sdio_work);
554 sdio_claim_host(func);
555 ret = sdio_enable_func(func);
556 sdio_release_host(func);
559 dev_err(&func->dev, "failed to enable function\n");
563 /* device tree node parsing and platform specific configuration*/
564 if (func->dev.of_node) {
565 ret = mwifiex_sdio_probe_of(&func->dev);
570 ret = mwifiex_add_card(card, &card->fw_done, &sdio_ops,
571 MWIFIEX_SDIO, &func->dev);
573 dev_err(&func->dev, "add card failed\n");
580 sdio_claim_host(func);
581 sdio_disable_func(func);
582 sdio_release_host(func);
590 * Kernel needs to suspend all functions separately. Therefore all
591 * registered functions must have drivers with suspend and resume
592 * methods. Failing that the kernel simply removes the whole card.
594 * If already not resumed, this function turns on the traffic and
595 * sends a host sleep cancel request to the firmware.
597 static int mwifiex_sdio_resume(struct device *dev)
599 struct sdio_func *func = dev_to_sdio_func(dev);
600 struct sdio_mmc_card *card;
601 struct mwifiex_adapter *adapter;
603 card = sdio_get_drvdata(func);
604 if (!card || !card->adapter) {
605 dev_err(dev, "resume: invalid card or adapter\n");
609 adapter = card->adapter;
611 if (!test_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags)) {
612 mwifiex_dbg(adapter, WARN,
613 "device already resumed\n");
617 clear_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags);
619 /* Disable Host Sleep */
620 mwifiex_cancel_hs(mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA),
623 mwifiex_disable_wake(adapter);
628 /* Write data into SDIO card register. Caller claims SDIO device. */
630 mwifiex_write_reg_locked(struct sdio_func *func, u32 reg, u8 data)
634 sdio_writeb(func, data, reg, &ret);
638 /* This function writes data into SDIO card register.
641 mwifiex_write_reg(struct mwifiex_adapter *adapter, u32 reg, u8 data)
643 struct sdio_mmc_card *card = adapter->card;
646 sdio_claim_host(card->func);
647 ret = mwifiex_write_reg_locked(card->func, reg, data);
648 sdio_release_host(card->func);
653 /* This function reads data from SDIO card register.
656 mwifiex_read_reg(struct mwifiex_adapter *adapter, u32 reg, u8 *data)
658 struct sdio_mmc_card *card = adapter->card;
662 sdio_claim_host(card->func);
663 val = sdio_readb(card->func, reg, &ret);
664 sdio_release_host(card->func);
671 /* This function writes multiple data into SDIO card memory.
673 * This does not work in suspended mode.
676 mwifiex_write_data_sync(struct mwifiex_adapter *adapter,
677 u8 *buffer, u32 pkt_len, u32 port)
679 struct sdio_mmc_card *card = adapter->card;
682 (port & MWIFIEX_SDIO_BYTE_MODE_MASK) ? BYTE_MODE : BLOCK_MODE;
683 u32 blk_size = (blk_mode == BLOCK_MODE) ? MWIFIEX_SDIO_BLOCK_SIZE : 1;
686 BLOCK_MODE) ? (pkt_len /
687 MWIFIEX_SDIO_BLOCK_SIZE) : pkt_len;
688 u32 ioport = (port & MWIFIEX_SDIO_IO_PORT_MASK);
690 if (test_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags)) {
691 mwifiex_dbg(adapter, ERROR,
692 "%s: not allowed while suspended\n", __func__);
696 sdio_claim_host(card->func);
698 ret = sdio_writesb(card->func, ioport, buffer, blk_cnt * blk_size);
700 sdio_release_host(card->func);
705 /* This function reads multiple data from SDIO card memory.
707 static int mwifiex_read_data_sync(struct mwifiex_adapter *adapter, u8 *buffer,
708 u32 len, u32 port, u8 claim)
710 struct sdio_mmc_card *card = adapter->card;
712 u8 blk_mode = (port & MWIFIEX_SDIO_BYTE_MODE_MASK) ? BYTE_MODE
714 u32 blk_size = (blk_mode == BLOCK_MODE) ? MWIFIEX_SDIO_BLOCK_SIZE : 1;
715 u32 blk_cnt = (blk_mode == BLOCK_MODE) ? (len / MWIFIEX_SDIO_BLOCK_SIZE)
717 u32 ioport = (port & MWIFIEX_SDIO_IO_PORT_MASK);
720 sdio_claim_host(card->func);
722 ret = sdio_readsb(card->func, buffer, ioport, blk_cnt * blk_size);
725 sdio_release_host(card->func);
730 /* This function reads the firmware status.
733 mwifiex_sdio_read_fw_status(struct mwifiex_adapter *adapter, u16 *dat)
735 struct sdio_mmc_card *card = adapter->card;
736 const struct mwifiex_sdio_card_reg *reg = card->reg;
739 if (mwifiex_read_reg(adapter, reg->status_reg_0, &fws0))
742 if (mwifiex_read_reg(adapter, reg->status_reg_1, &fws1))
745 *dat = (u16)((fws1 << 8) | fws0);
749 /* This function checks the firmware status in card.
751 static int mwifiex_check_fw_status(struct mwifiex_adapter *adapter,
758 for (tries = 0; tries < poll_num; tries++) {
759 ret = mwifiex_sdio_read_fw_status(adapter, &firmware_stat);
762 if (firmware_stat == FIRMWARE_READY_SDIO) {
774 /* This function checks if WLAN is the winner.
776 static int mwifiex_check_winner_status(struct mwifiex_adapter *adapter)
780 struct sdio_mmc_card *card = adapter->card;
782 if (mwifiex_read_reg(adapter, card->reg->status_reg_0, &winner))
796 * This function removes the interface and frees up the card structure.
799 mwifiex_sdio_remove(struct sdio_func *func)
801 struct sdio_mmc_card *card;
802 struct mwifiex_adapter *adapter;
803 struct mwifiex_private *priv;
807 card = sdio_get_drvdata(func);
811 wait_for_completion(&card->fw_done);
813 adapter = card->adapter;
814 if (!adapter || !adapter->priv_num)
817 mwifiex_dbg(adapter, INFO, "info: SDIO func num=%d\n", func->num);
819 ret = mwifiex_sdio_read_fw_status(adapter, &firmware_stat);
820 if (!ret && firmware_stat == FIRMWARE_READY_SDIO &&
821 !adapter->mfg_mode) {
822 mwifiex_deauthenticate_all(adapter);
824 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
825 mwifiex_disable_auto_ds(priv);
826 mwifiex_init_shutdown_fw(priv, MWIFIEX_FUNC_SHUTDOWN);
829 mwifiex_remove_card(adapter);
835 * Kernel needs to suspend all functions separately. Therefore all
836 * registered functions must have drivers with suspend and resume
837 * methods. Failing that the kernel simply removes the whole card.
839 * If already not suspended, this function allocates and sends a host
840 * sleep activate request to the firmware and turns off the traffic.
842 static int mwifiex_sdio_suspend(struct device *dev)
844 struct sdio_func *func = dev_to_sdio_func(dev);
845 struct sdio_mmc_card *card;
846 struct mwifiex_adapter *adapter;
847 mmc_pm_flag_t pm_flag = 0;
850 pm_flag = sdio_get_host_pm_caps(func);
851 pr_debug("cmd: %s: suspend: PM flag = 0x%x\n",
852 sdio_func_id(func), pm_flag);
853 if (!(pm_flag & MMC_PM_KEEP_POWER)) {
854 dev_err(dev, "%s: cannot remain alive while host is"
855 " suspended\n", sdio_func_id(func));
859 card = sdio_get_drvdata(func);
861 dev_err(dev, "suspend: invalid card\n");
865 /* Might still be loading firmware */
866 wait_for_completion(&card->fw_done);
868 adapter = card->adapter;
870 dev_err(dev, "adapter is not valid\n");
877 mwifiex_enable_wake(adapter);
879 /* Enable the Host Sleep */
880 if (!mwifiex_enable_hs(adapter)) {
881 mwifiex_dbg(adapter, ERROR,
882 "cmd: failed to suspend\n");
883 clear_bit(MWIFIEX_IS_HS_ENABLING, &adapter->work_flags);
884 mwifiex_disable_wake(adapter);
888 mwifiex_dbg(adapter, INFO,
889 "cmd: suspend with MMC_PM_KEEP_POWER\n");
890 ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER);
892 /* Indicate device suspended */
893 set_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags);
894 clear_bit(MWIFIEX_IS_HS_ENABLING, &adapter->work_flags);
899 static void mwifiex_sdio_coredump(struct device *dev)
901 struct sdio_func *func = dev_to_sdio_func(dev);
902 struct sdio_mmc_card *card;
904 card = sdio_get_drvdata(func);
905 if (!test_and_set_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP,
907 schedule_work(&card->work);
911 static const struct sdio_device_id mwifiex_ids[] = {
912 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8786_WLAN),
913 .driver_data = (unsigned long) &mwifiex_sdio_sd8786},
914 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8787_WLAN),
915 .driver_data = (unsigned long) &mwifiex_sdio_sd8787},
916 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8797_WLAN),
917 .driver_data = (unsigned long) &mwifiex_sdio_sd8797},
918 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8897_WLAN),
919 .driver_data = (unsigned long) &mwifiex_sdio_sd8897},
920 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8887_WLAN),
921 .driver_data = (unsigned long)&mwifiex_sdio_sd8887},
922 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8801_WLAN),
923 .driver_data = (unsigned long)&mwifiex_sdio_sd8801},
924 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8977_WLAN),
925 .driver_data = (unsigned long)&mwifiex_sdio_sd8977},
926 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8987_WLAN),
927 .driver_data = (unsigned long)&mwifiex_sdio_sd8987},
928 {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8997_WLAN),
929 .driver_data = (unsigned long)&mwifiex_sdio_sd8997},
933 MODULE_DEVICE_TABLE(sdio, mwifiex_ids);
935 static const struct dev_pm_ops mwifiex_sdio_pm_ops = {
936 .suspend = mwifiex_sdio_suspend,
937 .resume = mwifiex_sdio_resume,
940 static struct sdio_driver mwifiex_sdio = {
941 .name = "mwifiex_sdio",
942 .id_table = mwifiex_ids,
943 .probe = mwifiex_sdio_probe,
944 .remove = mwifiex_sdio_remove,
946 .owner = THIS_MODULE,
947 .coredump = mwifiex_sdio_coredump,
948 .pm = &mwifiex_sdio_pm_ops,
953 * This function wakes up the card.
955 * A host power up command is written to the card configuration
956 * register to wake up the card.
958 static int mwifiex_pm_wakeup_card(struct mwifiex_adapter *adapter)
960 mwifiex_dbg(adapter, EVENT,
961 "event: wakeup device...\n");
963 return mwifiex_write_reg(adapter, CONFIGURATION_REG, HOST_POWER_UP);
967 * This function is called after the card has woken up.
969 * The card configuration register is reset.
971 static int mwifiex_pm_wakeup_card_complete(struct mwifiex_adapter *adapter)
973 mwifiex_dbg(adapter, EVENT,
974 "cmd: wakeup device completed\n");
976 return mwifiex_write_reg(adapter, CONFIGURATION_REG, 0);
979 static int mwifiex_sdio_dnld_fw(struct mwifiex_adapter *adapter,
980 struct mwifiex_fw_image *fw)
982 struct sdio_mmc_card *card = adapter->card;
985 sdio_claim_host(card->func);
986 ret = mwifiex_dnld_fw(adapter, fw);
987 sdio_release_host(card->func);
993 * This function is used to initialize IO ports for the
994 * chipsets supporting SDIO new mode eg SD8897.
996 static int mwifiex_init_sdio_new_mode(struct mwifiex_adapter *adapter)
999 struct sdio_mmc_card *card = adapter->card;
1001 adapter->ioport = MEM_PORT;
1003 /* enable sdio new mode */
1004 if (mwifiex_read_reg(adapter, card->reg->card_cfg_2_1_reg, ®))
1006 if (mwifiex_write_reg(adapter, card->reg->card_cfg_2_1_reg,
1007 reg | CMD53_NEW_MODE))
1010 /* Configure cmd port and enable reading rx length from the register */
1011 if (mwifiex_read_reg(adapter, card->reg->cmd_cfg_0, ®))
1013 if (mwifiex_write_reg(adapter, card->reg->cmd_cfg_0,
1014 reg | CMD_PORT_RD_LEN_EN))
1017 /* Enable Dnld/Upld ready auto reset for cmd port after cmd53 is
1020 if (mwifiex_read_reg(adapter, card->reg->cmd_cfg_1, ®))
1022 if (mwifiex_write_reg(adapter, card->reg->cmd_cfg_1,
1023 reg | CMD_PORT_AUTO_EN))
1029 /* This function initializes the IO ports.
1031 * The following operations are performed -
1032 * - Read the IO ports (0, 1 and 2)
1033 * - Set host interrupt Reset-To-Read to clear
1034 * - Set auto re-enable interrupt
1036 static int mwifiex_init_sdio_ioport(struct mwifiex_adapter *adapter)
1039 struct sdio_mmc_card *card = adapter->card;
1041 adapter->ioport = 0;
1043 if (card->supports_sdio_new_mode) {
1044 if (mwifiex_init_sdio_new_mode(adapter))
1049 /* Read the IO port */
1050 if (!mwifiex_read_reg(adapter, card->reg->io_port_0_reg, ®))
1051 adapter->ioport |= (reg & 0xff);
1055 if (!mwifiex_read_reg(adapter, card->reg->io_port_1_reg, ®))
1056 adapter->ioport |= ((reg & 0xff) << 8);
1060 if (!mwifiex_read_reg(adapter, card->reg->io_port_2_reg, ®))
1061 adapter->ioport |= ((reg & 0xff) << 16);
1065 mwifiex_dbg(adapter, INFO,
1066 "info: SDIO FUNC1 IO port: %#x\n", adapter->ioport);
1068 /* Set Host interrupt reset to read to clear */
1069 if (!mwifiex_read_reg(adapter, card->reg->host_int_rsr_reg, ®))
1070 mwifiex_write_reg(adapter, card->reg->host_int_rsr_reg,
1071 reg | card->reg->sdio_int_mask);
1075 /* Dnld/Upld ready set to auto reset */
1076 if (!mwifiex_read_reg(adapter, card->reg->card_misc_cfg_reg, ®))
1077 mwifiex_write_reg(adapter, card->reg->card_misc_cfg_reg,
1078 reg | AUTO_RE_ENABLE_INT);
1086 * This function sends data to the card.
1088 static int mwifiex_write_data_to_card(struct mwifiex_adapter *adapter,
1089 u8 *payload, u32 pkt_len, u32 port)
1095 ret = mwifiex_write_data_sync(adapter, payload, pkt_len, port);
1098 mwifiex_dbg(adapter, ERROR,
1099 "host_to_card, write iomem\t"
1100 "(%d) failed: %d\n", i, ret);
1101 if (mwifiex_write_reg(adapter, CONFIGURATION_REG, 0x04))
1102 mwifiex_dbg(adapter, ERROR,
1103 "write CFG reg failed\n");
1106 if (i > MAX_WRITE_IOMEM_RETRY)
1109 } while (ret == -1);
1115 * This function gets the read port.
1117 * If control port bit is set in MP read bitmap, the control port
1118 * is returned, otherwise the current read port is returned and
1119 * the value is increased (provided it does not reach the maximum
1120 * limit, in which case it is reset to 1)
1122 static int mwifiex_get_rd_port(struct mwifiex_adapter *adapter, u8 *port)
1124 struct sdio_mmc_card *card = adapter->card;
1125 const struct mwifiex_sdio_card_reg *reg = card->reg;
1126 u32 rd_bitmap = card->mp_rd_bitmap;
1128 mwifiex_dbg(adapter, DATA,
1129 "data: mp_rd_bitmap=0x%08x\n", rd_bitmap);
1131 if (card->supports_sdio_new_mode) {
1132 if (!(rd_bitmap & reg->data_port_mask))
1135 if (!(rd_bitmap & (CTRL_PORT_MASK | reg->data_port_mask)))
1139 if ((card->has_control_mask) &&
1140 (card->mp_rd_bitmap & CTRL_PORT_MASK)) {
1141 card->mp_rd_bitmap &= (u32) (~CTRL_PORT_MASK);
1143 mwifiex_dbg(adapter, DATA,
1144 "data: port=%d mp_rd_bitmap=0x%08x\n",
1145 *port, card->mp_rd_bitmap);
1149 if (!(card->mp_rd_bitmap & (1 << card->curr_rd_port)))
1152 /* We are now handling the SDIO data ports */
1153 card->mp_rd_bitmap &= (u32)(~(1 << card->curr_rd_port));
1154 *port = card->curr_rd_port;
1156 if (++card->curr_rd_port == card->max_ports)
1157 card->curr_rd_port = reg->start_rd_port;
1159 mwifiex_dbg(adapter, DATA,
1160 "data: port=%d mp_rd_bitmap=0x%08x -> 0x%08x\n",
1161 *port, rd_bitmap, card->mp_rd_bitmap);
1167 * This function gets the write port for data.
1169 * The current write port is returned if available and the value is
1170 * increased (provided it does not reach the maximum limit, in which
1171 * case it is reset to 1)
1173 static int mwifiex_get_wr_port_data(struct mwifiex_adapter *adapter, u32 *port)
1175 struct sdio_mmc_card *card = adapter->card;
1176 const struct mwifiex_sdio_card_reg *reg = card->reg;
1177 u32 wr_bitmap = card->mp_wr_bitmap;
1179 mwifiex_dbg(adapter, DATA,
1180 "data: mp_wr_bitmap=0x%08x\n", wr_bitmap);
1182 if (!(wr_bitmap & card->mp_data_port_mask)) {
1183 adapter->data_sent = true;
1187 if (card->mp_wr_bitmap & (1 << card->curr_wr_port)) {
1188 card->mp_wr_bitmap &= (u32) (~(1 << card->curr_wr_port));
1189 *port = card->curr_wr_port;
1190 if (++card->curr_wr_port == card->mp_end_port)
1191 card->curr_wr_port = reg->start_wr_port;
1193 adapter->data_sent = true;
1197 if ((card->has_control_mask) && (*port == CTRL_PORT)) {
1198 mwifiex_dbg(adapter, ERROR,
1199 "invalid data port=%d cur port=%d mp_wr_bitmap=0x%08x -> 0x%08x\n",
1200 *port, card->curr_wr_port, wr_bitmap,
1201 card->mp_wr_bitmap);
1205 mwifiex_dbg(adapter, DATA,
1206 "data: port=%d mp_wr_bitmap=0x%08x -> 0x%08x\n",
1207 *port, wr_bitmap, card->mp_wr_bitmap);
1213 * This function polls the card status.
1216 mwifiex_sdio_poll_card_status(struct mwifiex_adapter *adapter, u8 bits)
1218 struct sdio_mmc_card *card = adapter->card;
1222 for (tries = 0; tries < MAX_POLL_TRIES; tries++) {
1223 if (mwifiex_read_reg(adapter, card->reg->poll_reg, &cs))
1225 else if ((cs & bits) == bits)
1228 usleep_range(10, 20);
1231 mwifiex_dbg(adapter, ERROR,
1232 "poll card status failed, tries = %d\n", tries);
1238 * This function disables the host interrupt.
1240 * The host interrupt mask is read, the disable bit is reset and
1241 * written back to the card host interrupt mask register.
1243 static void mwifiex_sdio_disable_host_int(struct mwifiex_adapter *adapter)
1245 struct sdio_mmc_card *card = adapter->card;
1246 struct sdio_func *func = card->func;
1248 sdio_claim_host(func);
1249 mwifiex_write_reg_locked(func, card->reg->host_int_mask_reg, 0);
1250 sdio_release_irq(func);
1251 sdio_release_host(func);
1255 * This function reads the interrupt status from card.
1257 static void mwifiex_interrupt_status(struct mwifiex_adapter *adapter)
1259 struct sdio_mmc_card *card = adapter->card;
1261 unsigned long flags;
1263 if (mwifiex_read_data_sync(adapter, card->mp_regs,
1264 card->reg->max_mp_regs,
1265 REG_PORT | MWIFIEX_SDIO_BYTE_MODE_MASK, 0)) {
1266 mwifiex_dbg(adapter, ERROR, "read mp_regs failed\n");
1270 sdio_ireg = card->mp_regs[card->reg->host_int_status_reg];
1273 * DN_LD_HOST_INT_STATUS and/or UP_LD_HOST_INT_STATUS
1274 * For SDIO new mode CMD port interrupts
1275 * DN_LD_CMD_PORT_HOST_INT_STATUS and/or
1276 * UP_LD_CMD_PORT_HOST_INT_STATUS
1277 * Clear the interrupt status register
1279 mwifiex_dbg(adapter, INTR,
1280 "int: sdio_ireg = %#x\n", sdio_ireg);
1281 spin_lock_irqsave(&adapter->int_lock, flags);
1282 adapter->int_status |= sdio_ireg;
1283 spin_unlock_irqrestore(&adapter->int_lock, flags);
1288 * SDIO interrupt handler.
1290 * This function reads the interrupt status from firmware and handles
1291 * the interrupt in current thread (ksdioirqd) right away.
1294 mwifiex_sdio_interrupt(struct sdio_func *func)
1296 struct mwifiex_adapter *adapter;
1297 struct sdio_mmc_card *card;
1299 card = sdio_get_drvdata(func);
1300 if (!card || !card->adapter) {
1301 pr_err("int: func=%p card=%p adapter=%p\n",
1302 func, card, card ? card->adapter : NULL);
1305 adapter = card->adapter;
1307 if (!adapter->pps_uapsd_mode && adapter->ps_state == PS_STATE_SLEEP)
1308 adapter->ps_state = PS_STATE_AWAKE;
1310 mwifiex_interrupt_status(adapter);
1311 mwifiex_main_process(adapter);
1315 * This function enables the host interrupt.
1317 * The host interrupt enable mask is written to the card
1318 * host interrupt mask register.
1320 static int mwifiex_sdio_enable_host_int(struct mwifiex_adapter *adapter)
1322 struct sdio_mmc_card *card = adapter->card;
1323 struct sdio_func *func = card->func;
1326 sdio_claim_host(func);
1328 /* Request the SDIO IRQ */
1329 ret = sdio_claim_irq(func, mwifiex_sdio_interrupt);
1331 mwifiex_dbg(adapter, ERROR,
1332 "claim irq failed: ret=%d\n", ret);
1336 /* Simply write the mask to the register */
1337 ret = mwifiex_write_reg_locked(func, card->reg->host_int_mask_reg,
1338 card->reg->host_int_enable);
1340 mwifiex_dbg(adapter, ERROR,
1341 "enable host interrupt failed\n");
1342 sdio_release_irq(func);
1346 sdio_release_host(func);
1351 * This function sends a data buffer to the card.
1353 static int mwifiex_sdio_card_to_host(struct mwifiex_adapter *adapter,
1354 u32 *type, u8 *buffer,
1355 u32 npayload, u32 ioport)
1361 mwifiex_dbg(adapter, ERROR,
1362 "%s: buffer is NULL\n", __func__);
1366 ret = mwifiex_read_data_sync(adapter, buffer, npayload, ioport, 1);
1369 mwifiex_dbg(adapter, ERROR,
1370 "%s: read iomem failed: %d\n", __func__,
1375 nb = get_unaligned_le16((buffer));
1376 if (nb > npayload) {
1377 mwifiex_dbg(adapter, ERROR,
1378 "%s: invalid packet, nb=%d npayload=%d\n",
1379 __func__, nb, npayload);
1383 *type = get_unaligned_le16((buffer + 2));
1389 * This function downloads the firmware to the card.
1391 * Firmware is downloaded to the card in blocks. Every block download
1392 * is tested for CRC errors, and retried a number of times before
1393 * returning failure.
1395 static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter,
1396 struct mwifiex_fw_image *fw)
1398 struct sdio_mmc_card *card = adapter->card;
1399 const struct mwifiex_sdio_card_reg *reg = card->reg;
1401 u8 *firmware = fw->fw_buf;
1402 u32 firmware_len = fw->fw_len;
1407 u32 txlen, tx_blocks = 0, tries;
1410 if (!firmware_len) {
1411 mwifiex_dbg(adapter, ERROR,
1412 "firmware image not found! Terminating download\n");
1416 mwifiex_dbg(adapter, INFO,
1417 "info: downloading FW image (%d bytes)\n",
1420 /* Assume that the allocated buffer is 8-byte aligned */
1421 fwbuf = kzalloc(MWIFIEX_UPLD_SIZE, GFP_KERNEL);
1425 sdio_claim_host(card->func);
1427 /* Perform firmware data transfer */
1429 /* The host polls for the DN_LD_CARD_RDY and CARD_IO_READY
1431 ret = mwifiex_sdio_poll_card_status(adapter, CARD_IO_READY |
1434 mwifiex_dbg(adapter, ERROR,
1435 "FW download with helper:\t"
1436 "poll status timeout @ %d\n", offset);
1441 if (offset >= firmware_len)
1444 for (tries = 0; tries < MAX_POLL_TRIES; tries++) {
1445 ret = mwifiex_read_reg(adapter, reg->base_0_reg,
1448 mwifiex_dbg(adapter, ERROR,
1449 "dev BASE0 register read failed:\t"
1450 "base0=%#04X(%d). Terminating dnld\n",
1454 ret = mwifiex_read_reg(adapter, reg->base_1_reg,
1457 mwifiex_dbg(adapter, ERROR,
1458 "dev BASE1 register read failed:\t"
1459 "base1=%#04X(%d). Terminating dnld\n",
1463 len = (u16) (((base1 & 0xff) << 8) | (base0 & 0xff));
1468 usleep_range(10, 20);
1473 } else if (len > MWIFIEX_UPLD_SIZE) {
1474 mwifiex_dbg(adapter, ERROR,
1475 "FW dnld failed @ %d, invalid length %d\n",
1485 if (i > MAX_WRITE_IOMEM_RETRY) {
1486 mwifiex_dbg(adapter, ERROR,
1487 "FW dnld failed @ %d, over max retry\n",
1492 mwifiex_dbg(adapter, ERROR,
1493 "CRC indicated by the helper:\t"
1494 "len = 0x%04X, txlen = %d\n", len, txlen);
1496 /* Setting this to 0 to resend from same offset */
1501 /* Set blocksize to transfer - checking for last
1503 if (firmware_len - offset < txlen)
1504 txlen = firmware_len - offset;
1506 tx_blocks = (txlen + MWIFIEX_SDIO_BLOCK_SIZE - 1)
1507 / MWIFIEX_SDIO_BLOCK_SIZE;
1509 /* Copy payload to buffer */
1510 memmove(fwbuf, &firmware[offset], txlen);
1513 ret = mwifiex_write_data_sync(adapter, fwbuf, tx_blocks *
1514 MWIFIEX_SDIO_BLOCK_SIZE,
1517 mwifiex_dbg(adapter, ERROR,
1518 "FW download, write iomem (%d) failed @ %d\n",
1520 if (mwifiex_write_reg(adapter, CONFIGURATION_REG, 0x04))
1521 mwifiex_dbg(adapter, ERROR,
1522 "write CFG reg failed\n");
1531 mwifiex_dbg(adapter, MSG,
1532 "info: FW download over, size %d bytes\n", offset);
1536 sdio_release_host(card->func);
1542 * This function decode sdio aggreation pkt.
1544 * Based on the the data block size and pkt_len,
1545 * skb data will be decoded to few packets.
1547 static void mwifiex_deaggr_sdio_pkt(struct mwifiex_adapter *adapter,
1548 struct sk_buff *skb)
1550 u32 total_pkt_len, pkt_len;
1551 struct sk_buff *skb_deaggr;
1557 total_pkt_len = skb->len;
1559 while (total_pkt_len >= (SDIO_HEADER_OFFSET + adapter->intf_hdr_len)) {
1560 if (total_pkt_len < adapter->sdio_rx_block_size)
1562 blk_num = *(data + BLOCK_NUMBER_OFFSET);
1563 blk_size = adapter->sdio_rx_block_size * blk_num;
1564 if (blk_size > total_pkt_len) {
1565 mwifiex_dbg(adapter, ERROR,
1566 "%s: error in blk_size,\t"
1567 "blk_num=%d, blk_size=%d, total_pkt_len=%d\n",
1568 __func__, blk_num, blk_size, total_pkt_len);
1571 pkt_len = get_unaligned_le16((data +
1572 SDIO_HEADER_OFFSET));
1573 if ((pkt_len + SDIO_HEADER_OFFSET) > blk_size) {
1574 mwifiex_dbg(adapter, ERROR,
1575 "%s: error in pkt_len,\t"
1576 "pkt_len=%d, blk_size=%d\n",
1577 __func__, pkt_len, blk_size);
1581 skb_deaggr = mwifiex_alloc_dma_align_buf(pkt_len, GFP_KERNEL);
1584 skb_put(skb_deaggr, pkt_len);
1585 memcpy(skb_deaggr->data, data + SDIO_HEADER_OFFSET, pkt_len);
1586 skb_pull(skb_deaggr, adapter->intf_hdr_len);
1588 mwifiex_handle_rx_packet(adapter, skb_deaggr);
1590 total_pkt_len -= blk_size;
1595 * This function decodes a received packet.
1597 * Based on the type, the packet is treated as either a data, or
1598 * a command response, or an event, and the correct handler
1599 * function is invoked.
1601 static int mwifiex_decode_rx_packet(struct mwifiex_adapter *adapter,
1602 struct sk_buff *skb, u32 upld_typ)
1606 struct mwifiex_rxinfo *rx_info;
1608 pkt_len = get_unaligned_le16(skb->data);
1610 if (upld_typ != MWIFIEX_TYPE_AGGR_DATA) {
1611 skb_trim(skb, pkt_len);
1612 skb_pull(skb, adapter->intf_hdr_len);
1616 case MWIFIEX_TYPE_AGGR_DATA:
1617 mwifiex_dbg(adapter, INFO,
1618 "info: --- Rx: Aggr Data packet ---\n");
1619 rx_info = MWIFIEX_SKB_RXCB(skb);
1620 rx_info->buf_type = MWIFIEX_TYPE_AGGR_DATA;
1621 if (adapter->rx_work_enabled) {
1622 skb_queue_tail(&adapter->rx_data_q, skb);
1623 atomic_inc(&adapter->rx_pending);
1624 adapter->data_received = true;
1626 mwifiex_deaggr_sdio_pkt(adapter, skb);
1627 dev_kfree_skb_any(skb);
1631 case MWIFIEX_TYPE_DATA:
1632 mwifiex_dbg(adapter, DATA,
1633 "info: --- Rx: Data packet ---\n");
1634 if (adapter->rx_work_enabled) {
1635 skb_queue_tail(&adapter->rx_data_q, skb);
1636 adapter->data_received = true;
1637 atomic_inc(&adapter->rx_pending);
1639 mwifiex_handle_rx_packet(adapter, skb);
1643 case MWIFIEX_TYPE_CMD:
1644 mwifiex_dbg(adapter, CMD,
1645 "info: --- Rx: Cmd Response ---\n");
1646 /* take care of curr_cmd = NULL case */
1647 if (!adapter->curr_cmd) {
1648 cmd_buf = adapter->upld_buf;
1650 if (adapter->ps_state == PS_STATE_SLEEP_CFM)
1651 mwifiex_process_sleep_confirm_resp(adapter,
1655 memcpy(cmd_buf, skb->data,
1656 min_t(u32, MWIFIEX_SIZE_OF_CMD_BUFFER,
1659 dev_kfree_skb_any(skb);
1661 adapter->cmd_resp_received = true;
1662 adapter->curr_cmd->resp_skb = skb;
1666 case MWIFIEX_TYPE_EVENT:
1667 mwifiex_dbg(adapter, EVENT,
1668 "info: --- Rx: Event ---\n");
1669 adapter->event_cause = get_unaligned_le32(skb->data);
1671 if ((skb->len > 0) && (skb->len < MAX_EVENT_SIZE))
1672 memcpy(adapter->event_body,
1673 skb->data + MWIFIEX_EVENT_HEADER_LEN,
1676 /* event cause has been saved to adapter->event_cause */
1677 adapter->event_received = true;
1678 adapter->event_skb = skb;
1683 mwifiex_dbg(adapter, ERROR,
1684 "unknown upload type %#x\n", upld_typ);
1685 dev_kfree_skb_any(skb);
1693 * This function transfers received packets from card to driver, performing
1694 * aggregation if required.
1696 * For data received on control port, or if aggregation is disabled, the
1697 * received buffers are uploaded as separate packets. However, if aggregation
1698 * is enabled and required, the buffers are copied onto an aggregation buffer,
1699 * provided there is space left, processed and finally uploaded.
1701 static int mwifiex_sdio_card_to_host_mp_aggr(struct mwifiex_adapter *adapter,
1702 u16 rx_len, u8 port)
1704 struct sdio_mmc_card *card = adapter->card;
1705 s32 f_do_rx_aggr = 0;
1706 s32 f_do_rx_cur = 0;
1708 s32 f_post_aggr_cur = 0;
1709 struct sk_buff *skb_deaggr;
1710 struct sk_buff *skb = NULL;
1711 u32 pkt_len, pkt_type, mport, pind;
1714 if ((card->has_control_mask) && (port == CTRL_PORT)) {
1715 /* Read the command Resp without aggr */
1716 mwifiex_dbg(adapter, CMD,
1717 "info: %s: no aggregation for cmd\t"
1718 "response\n", __func__);
1721 goto rx_curr_single;
1724 if (!card->mpa_rx.enabled) {
1725 mwifiex_dbg(adapter, WARN,
1726 "info: %s: rx aggregation disabled\n",
1730 goto rx_curr_single;
1733 if ((!card->has_control_mask && (card->mp_rd_bitmap &
1734 card->reg->data_port_mask)) ||
1735 (card->has_control_mask && (card->mp_rd_bitmap &
1736 (~((u32) CTRL_PORT_MASK))))) {
1737 /* Some more data RX pending */
1738 mwifiex_dbg(adapter, INFO,
1739 "info: %s: not last packet\n", __func__);
1741 if (MP_RX_AGGR_IN_PROGRESS(card)) {
1742 if (MP_RX_AGGR_BUF_HAS_ROOM(card, rx_len)) {
1745 /* No room in Aggr buf, do rx aggr now */
1747 f_post_aggr_cur = 1;
1750 /* Rx aggr not in progress */
1755 /* No more data RX pending */
1756 mwifiex_dbg(adapter, INFO,
1757 "info: %s: last packet\n", __func__);
1759 if (MP_RX_AGGR_IN_PROGRESS(card)) {
1761 if (MP_RX_AGGR_BUF_HAS_ROOM(card, rx_len))
1764 /* No room in Aggr buf, do rx aggr now */
1772 mwifiex_dbg(adapter, INFO,
1773 "info: current packet aggregation\n");
1774 /* Curr pkt can be aggregated */
1775 mp_rx_aggr_setup(card, rx_len, port);
1777 if (MP_RX_AGGR_PKT_LIMIT_REACHED(card) ||
1778 mp_rx_aggr_port_limit_reached(card)) {
1779 mwifiex_dbg(adapter, INFO,
1780 "info: %s: aggregated packet\t"
1781 "limit reached\n", __func__);
1782 /* No more pkts allowed in Aggr buf, rx it */
1788 /* do aggr RX now */
1789 mwifiex_dbg(adapter, DATA,
1790 "info: do_rx_aggr: num of packets: %d\n",
1791 card->mpa_rx.pkt_cnt);
1793 if (card->supports_sdio_new_mode) {
1797 for (i = 0, port_count = 0; i < card->max_ports; i++)
1798 if (card->mpa_rx.ports & BIT(i))
1801 /* Reading data from "start_port + 0" to "start_port +
1802 * port_count -1", so decrease the count by 1
1805 mport = (adapter->ioport | SDIO_MPA_ADDR_BASE |
1806 (port_count << 8)) + card->mpa_rx.start_port;
1808 mport = (adapter->ioport | SDIO_MPA_ADDR_BASE |
1809 (card->mpa_rx.ports << 4)) +
1810 card->mpa_rx.start_port;
1813 if (card->mpa_rx.pkt_cnt == 1)
1814 mport = adapter->ioport + card->mpa_rx.start_port;
1816 if (mwifiex_read_data_sync(adapter, card->mpa_rx.buf,
1817 card->mpa_rx.buf_len, mport, 1))
1820 curr_ptr = card->mpa_rx.buf;
1822 for (pind = 0; pind < card->mpa_rx.pkt_cnt; pind++) {
1823 u32 *len_arr = card->mpa_rx.len_arr;
1825 /* get curr PKT len & type */
1826 pkt_len = get_unaligned_le16(&curr_ptr[0]);
1827 pkt_type = get_unaligned_le16(&curr_ptr[2]);
1829 /* copy pkt to deaggr buf */
1830 skb_deaggr = mwifiex_alloc_dma_align_buf(len_arr[pind],
1833 mwifiex_dbg(adapter, ERROR, "skb allocation failure\t"
1834 "drop pkt len=%d type=%d\n",
1836 curr_ptr += len_arr[pind];
1840 skb_put(skb_deaggr, len_arr[pind]);
1842 if ((pkt_type == MWIFIEX_TYPE_DATA ||
1843 (pkt_type == MWIFIEX_TYPE_AGGR_DATA &&
1844 adapter->sdio_rx_aggr_enable)) &&
1845 (pkt_len <= len_arr[pind])) {
1847 memcpy(skb_deaggr->data, curr_ptr, pkt_len);
1849 skb_trim(skb_deaggr, pkt_len);
1851 /* Process de-aggr packet */
1852 mwifiex_decode_rx_packet(adapter, skb_deaggr,
1855 mwifiex_dbg(adapter, ERROR,
1856 "drop wrong aggr pkt:\t"
1857 "sdio_single_port_rx_aggr=%d\t"
1858 "type=%d len=%d max_len=%d\n",
1859 adapter->sdio_rx_aggr_enable,
1860 pkt_type, pkt_len, len_arr[pind]);
1861 dev_kfree_skb_any(skb_deaggr);
1863 curr_ptr += len_arr[pind];
1865 MP_RX_AGGR_BUF_RESET(card);
1870 mwifiex_dbg(adapter, INFO, "info: RX: port: %d, rx_len: %d\n",
1873 skb = mwifiex_alloc_dma_align_buf(rx_len, GFP_KERNEL);
1875 mwifiex_dbg(adapter, ERROR,
1876 "single skb allocated fail,\t"
1877 "drop pkt port=%d len=%d\n", port, rx_len);
1878 if (mwifiex_sdio_card_to_host(adapter, &pkt_type,
1879 card->mpa_rx.buf, rx_len,
1880 adapter->ioport + port))
1885 skb_put(skb, rx_len);
1887 if (mwifiex_sdio_card_to_host(adapter, &pkt_type,
1888 skb->data, skb->len,
1889 adapter->ioport + port))
1891 if (!adapter->sdio_rx_aggr_enable &&
1892 pkt_type == MWIFIEX_TYPE_AGGR_DATA) {
1893 mwifiex_dbg(adapter, ERROR, "drop wrong pkt type %d\t"
1894 "current SDIO RX Aggr not enabled\n",
1896 dev_kfree_skb_any(skb);
1900 mwifiex_decode_rx_packet(adapter, skb, pkt_type);
1902 if (f_post_aggr_cur) {
1903 mwifiex_dbg(adapter, INFO,
1904 "info: current packet aggregation\n");
1905 /* Curr pkt can be aggregated */
1906 mp_rx_aggr_setup(card, rx_len, port);
1911 if (MP_RX_AGGR_IN_PROGRESS(card))
1912 MP_RX_AGGR_BUF_RESET(card);
1914 if (f_do_rx_cur && skb)
1915 /* Single transfer pending. Free curr buff also */
1916 dev_kfree_skb_any(skb);
1922 * This function checks the current interrupt status.
1924 * The following interrupts are checked and handled by this function -
1927 * - Packets received
1929 * Since the firmware does not generate download ready interrupt if the
1930 * port updated is command port only, command sent interrupt checking
1931 * should be done manually, and for every SDIO interrupt.
1933 * In case of Rx packets received, the packets are uploaded from card to
1934 * host and processed accordingly.
1936 static int mwifiex_process_int_status(struct mwifiex_adapter *adapter)
1938 struct sdio_mmc_card *card = adapter->card;
1939 const struct mwifiex_sdio_card_reg *reg = card->reg;
1942 struct sk_buff *skb;
1943 u8 port = CTRL_PORT;
1944 u32 len_reg_l, len_reg_u;
1947 unsigned long flags;
1951 spin_lock_irqsave(&adapter->int_lock, flags);
1952 sdio_ireg = adapter->int_status;
1953 adapter->int_status = 0;
1954 spin_unlock_irqrestore(&adapter->int_lock, flags);
1959 /* Following interrupt is only for SDIO new mode */
1960 if (sdio_ireg & DN_LD_CMD_PORT_HOST_INT_STATUS && adapter->cmd_sent)
1961 adapter->cmd_sent = false;
1963 /* Following interrupt is only for SDIO new mode */
1964 if (sdio_ireg & UP_LD_CMD_PORT_HOST_INT_STATUS) {
1967 /* read the len of control packet */
1968 rx_len = card->mp_regs[reg->cmd_rd_len_1] << 8;
1969 rx_len |= (u16)card->mp_regs[reg->cmd_rd_len_0];
1970 rx_blocks = DIV_ROUND_UP(rx_len, MWIFIEX_SDIO_BLOCK_SIZE);
1971 if (rx_len <= adapter->intf_hdr_len ||
1972 (rx_blocks * MWIFIEX_SDIO_BLOCK_SIZE) >
1973 MWIFIEX_RX_DATA_BUF_SIZE)
1975 rx_len = (u16) (rx_blocks * MWIFIEX_SDIO_BLOCK_SIZE);
1976 mwifiex_dbg(adapter, INFO, "info: rx_len = %d\n", rx_len);
1978 skb = mwifiex_alloc_dma_align_buf(rx_len, GFP_KERNEL);
1982 skb_put(skb, rx_len);
1984 if (mwifiex_sdio_card_to_host(adapter, &pkt_type, skb->data,
1985 skb->len, adapter->ioport |
1987 mwifiex_dbg(adapter, ERROR,
1988 "%s: failed to card_to_host", __func__);
1989 dev_kfree_skb_any(skb);
1993 if ((pkt_type != MWIFIEX_TYPE_CMD) &&
1994 (pkt_type != MWIFIEX_TYPE_EVENT))
1995 mwifiex_dbg(adapter, ERROR,
1996 "%s:Received wrong packet on cmd port",
1999 mwifiex_decode_rx_packet(adapter, skb, pkt_type);
2002 if (sdio_ireg & DN_LD_HOST_INT_STATUS) {
2003 bitmap = (u32) card->mp_regs[reg->wr_bitmap_l];
2004 bitmap |= ((u32) card->mp_regs[reg->wr_bitmap_u]) << 8;
2005 if (card->supports_sdio_new_mode) {
2007 ((u32) card->mp_regs[reg->wr_bitmap_1l]) << 16;
2009 ((u32) card->mp_regs[reg->wr_bitmap_1u]) << 24;
2011 card->mp_wr_bitmap = bitmap;
2013 mwifiex_dbg(adapter, INTR,
2014 "int: DNLD: wr_bitmap=0x%x\n",
2015 card->mp_wr_bitmap);
2016 if (adapter->data_sent &&
2017 (card->mp_wr_bitmap & card->mp_data_port_mask)) {
2018 mwifiex_dbg(adapter, INTR,
2019 "info: <--- Tx DONE Interrupt --->\n");
2020 adapter->data_sent = false;
2024 /* As firmware will not generate download ready interrupt if the port
2025 updated is command port only, cmd_sent should be done for any SDIO
2027 if (card->has_control_mask && adapter->cmd_sent) {
2028 /* Check if firmware has attach buffer at command port and
2029 update just that in wr_bit_map. */
2030 card->mp_wr_bitmap |=
2031 (u32) card->mp_regs[reg->wr_bitmap_l] & CTRL_PORT_MASK;
2032 if (card->mp_wr_bitmap & CTRL_PORT_MASK)
2033 adapter->cmd_sent = false;
2036 mwifiex_dbg(adapter, INTR, "info: cmd_sent=%d data_sent=%d\n",
2037 adapter->cmd_sent, adapter->data_sent);
2038 if (sdio_ireg & UP_LD_HOST_INT_STATUS) {
2039 bitmap = (u32) card->mp_regs[reg->rd_bitmap_l];
2040 bitmap |= ((u32) card->mp_regs[reg->rd_bitmap_u]) << 8;
2041 if (card->supports_sdio_new_mode) {
2043 ((u32) card->mp_regs[reg->rd_bitmap_1l]) << 16;
2045 ((u32) card->mp_regs[reg->rd_bitmap_1u]) << 24;
2047 card->mp_rd_bitmap = bitmap;
2048 mwifiex_dbg(adapter, INTR,
2049 "int: UPLD: rd_bitmap=0x%x\n",
2050 card->mp_rd_bitmap);
2053 ret = mwifiex_get_rd_port(adapter, &port);
2055 mwifiex_dbg(adapter, INFO,
2056 "info: no more rd_port available\n");
2059 len_reg_l = reg->rd_len_p0_l + (port << 1);
2060 len_reg_u = reg->rd_len_p0_u + (port << 1);
2061 rx_len = ((u16) card->mp_regs[len_reg_u]) << 8;
2062 rx_len |= (u16) card->mp_regs[len_reg_l];
2063 mwifiex_dbg(adapter, INFO,
2064 "info: RX: port=%d rx_len=%u\n",
2067 (rx_len + MWIFIEX_SDIO_BLOCK_SIZE -
2068 1) / MWIFIEX_SDIO_BLOCK_SIZE;
2069 if (rx_len <= adapter->intf_hdr_len ||
2070 (card->mpa_rx.enabled &&
2071 ((rx_blocks * MWIFIEX_SDIO_BLOCK_SIZE) >
2072 card->mpa_rx.buf_size))) {
2073 mwifiex_dbg(adapter, ERROR,
2074 "invalid rx_len=%d\n",
2079 rx_len = (u16) (rx_blocks * MWIFIEX_SDIO_BLOCK_SIZE);
2080 mwifiex_dbg(adapter, INFO, "info: rx_len = %d\n",
2083 if (mwifiex_sdio_card_to_host_mp_aggr(adapter, rx_len,
2085 mwifiex_dbg(adapter, ERROR,
2086 "card_to_host_mpa failed: int status=%#x\n",
2097 if (mwifiex_read_reg(adapter, CONFIGURATION_REG, &cr))
2098 mwifiex_dbg(adapter, ERROR, "read CFG reg failed\n");
2100 mwifiex_dbg(adapter, INFO,
2101 "info: CFG reg val = %d\n", cr);
2103 if (mwifiex_write_reg(adapter, CONFIGURATION_REG, (cr | 0x04)))
2104 mwifiex_dbg(adapter, ERROR,
2105 "write CFG reg failed\n");
2107 mwifiex_dbg(adapter, INFO, "info: write success\n");
2109 if (mwifiex_read_reg(adapter, CONFIGURATION_REG, &cr))
2110 mwifiex_dbg(adapter, ERROR,
2111 "read CFG reg failed\n");
2113 mwifiex_dbg(adapter, INFO,
2114 "info: CFG reg val =%x\n", cr);
2120 * This function aggregates transmission buffers in driver and downloads
2121 * the aggregated packet to card.
2123 * The individual packets are aggregated by copying into an aggregation
2124 * buffer and then downloaded to the card. Previous unsent packets in the
2125 * aggregation buffer are pre-copied first before new packets are added.
2126 * Aggregation is done till there is space left in the aggregation buffer,
2127 * or till new packets are available.
2129 * The function will only download the packet to the card when aggregation
2130 * stops, otherwise it will just aggregate the packet in aggregation buffer
2133 static int mwifiex_host_to_card_mp_aggr(struct mwifiex_adapter *adapter,
2134 u8 *payload, u32 pkt_len, u32 port,
2137 struct sdio_mmc_card *card = adapter->card;
2139 s32 f_send_aggr_buf = 0;
2140 s32 f_send_cur_buf = 0;
2141 s32 f_precopy_cur_buf = 0;
2142 s32 f_postcopy_cur_buf = 0;
2146 if (!card->mpa_tx.enabled ||
2147 (card->has_control_mask && (port == CTRL_PORT)) ||
2148 (card->supports_sdio_new_mode && (port == CMD_PORT_SLCT))) {
2149 mwifiex_dbg(adapter, WARN,
2150 "info: %s: tx aggregation disabled\n",
2154 goto tx_curr_single;
2158 /* More pkt in TX queue */
2159 mwifiex_dbg(adapter, INFO,
2160 "info: %s: more packets in queue.\n",
2163 if (MP_TX_AGGR_IN_PROGRESS(card)) {
2164 if (MP_TX_AGGR_BUF_HAS_ROOM(card, pkt_len)) {
2165 f_precopy_cur_buf = 1;
2167 if (!(card->mp_wr_bitmap &
2168 (1 << card->curr_wr_port)) ||
2169 !MP_TX_AGGR_BUF_HAS_ROOM(
2170 card, pkt_len + next_pkt_len))
2171 f_send_aggr_buf = 1;
2173 /* No room in Aggr buf, send it */
2174 f_send_aggr_buf = 1;
2176 if (!(card->mp_wr_bitmap &
2177 (1 << card->curr_wr_port)))
2180 f_postcopy_cur_buf = 1;
2183 if (MP_TX_AGGR_BUF_HAS_ROOM(card, pkt_len) &&
2184 (card->mp_wr_bitmap & (1 << card->curr_wr_port)))
2185 f_precopy_cur_buf = 1;
2190 /* Last pkt in TX queue */
2191 mwifiex_dbg(adapter, INFO,
2192 "info: %s: Last packet in Tx Queue.\n",
2195 if (MP_TX_AGGR_IN_PROGRESS(card)) {
2196 /* some packs in Aggr buf already */
2197 f_send_aggr_buf = 1;
2199 if (MP_TX_AGGR_BUF_HAS_ROOM(card, pkt_len))
2200 f_precopy_cur_buf = 1;
2202 /* No room in Aggr buf, send it */
2209 if (f_precopy_cur_buf) {
2210 mwifiex_dbg(adapter, DATA,
2211 "data: %s: precopy current buffer\n",
2213 MP_TX_AGGR_BUF_PUT(card, payload, pkt_len, port);
2215 if (MP_TX_AGGR_PKT_LIMIT_REACHED(card) ||
2216 mp_tx_aggr_port_limit_reached(card))
2217 /* No more pkts allowed in Aggr buf, send it */
2218 f_send_aggr_buf = 1;
2221 if (f_send_aggr_buf) {
2222 mwifiex_dbg(adapter, DATA,
2223 "data: %s: send aggr buffer: %d %d\n",
2224 __func__, card->mpa_tx.start_port,
2225 card->mpa_tx.ports);
2226 if (card->supports_sdio_new_mode) {
2230 for (i = 0, port_count = 0; i < card->max_ports; i++)
2231 if (card->mpa_tx.ports & BIT(i))
2234 /* Writing data from "start_port + 0" to "start_port +
2235 * port_count -1", so decrease the count by 1
2238 mport = (adapter->ioport | SDIO_MPA_ADDR_BASE |
2239 (port_count << 8)) + card->mpa_tx.start_port;
2241 mport = (adapter->ioport | SDIO_MPA_ADDR_BASE |
2242 (card->mpa_tx.ports << 4)) +
2243 card->mpa_tx.start_port;
2246 if (card->mpa_tx.pkt_cnt == 1)
2247 mport = adapter->ioport + card->mpa_tx.start_port;
2249 ret = mwifiex_write_data_to_card(adapter, card->mpa_tx.buf,
2250 card->mpa_tx.buf_len, mport);
2252 /* Save the last multi port tx aggreagation info to debug log */
2253 index = adapter->dbg.last_sdio_mp_index;
2254 index = (index + 1) % MWIFIEX_DBG_SDIO_MP_NUM;
2255 adapter->dbg.last_sdio_mp_index = index;
2256 adapter->dbg.last_mp_wr_ports[index] = mport;
2257 adapter->dbg.last_mp_wr_bitmap[index] = card->mp_wr_bitmap;
2258 adapter->dbg.last_mp_wr_len[index] = card->mpa_tx.buf_len;
2259 adapter->dbg.last_mp_curr_wr_port[index] = card->curr_wr_port;
2261 MP_TX_AGGR_BUF_RESET(card);
2265 if (f_send_cur_buf) {
2266 mwifiex_dbg(adapter, DATA,
2267 "data: %s: send current buffer %d\n",
2269 ret = mwifiex_write_data_to_card(adapter, payload, pkt_len,
2270 adapter->ioport + port);
2273 if (f_postcopy_cur_buf) {
2274 mwifiex_dbg(adapter, DATA,
2275 "data: %s: postcopy current buffer\n",
2277 MP_TX_AGGR_BUF_PUT(card, payload, pkt_len, port);
2284 * This function downloads data from driver to card.
2286 * Both commands and data packets are transferred to the card by this
2289 * This function adds the SDIO specific header to the front of the buffer
2290 * before transferring. The header contains the length of the packet and
2291 * the type. The firmware handles the packets based upon this set type.
2293 static int mwifiex_sdio_host_to_card(struct mwifiex_adapter *adapter,
2294 u8 type, struct sk_buff *skb,
2295 struct mwifiex_tx_param *tx_param)
2297 struct sdio_mmc_card *card = adapter->card;
2301 u32 port = CTRL_PORT;
2302 u8 *payload = (u8 *)skb->data;
2303 u32 pkt_len = skb->len;
2305 /* Allocate buffer and copy payload */
2306 blk_size = MWIFIEX_SDIO_BLOCK_SIZE;
2307 buf_block_len = (pkt_len + blk_size - 1) / blk_size;
2308 put_unaligned_le16((u16)pkt_len, payload + 0);
2309 put_unaligned_le16((u32)type, payload + 2);
2313 * This is SDIO specific header
2315 * u16 type (MWIFIEX_TYPE_DATA = 0, MWIFIEX_TYPE_CMD = 1,
2316 * MWIFIEX_TYPE_EVENT = 3)
2318 if (type == MWIFIEX_TYPE_DATA) {
2319 ret = mwifiex_get_wr_port_data(adapter, &port);
2321 mwifiex_dbg(adapter, ERROR,
2322 "%s: no wr_port available\n",
2327 adapter->cmd_sent = true;
2328 /* Type must be MWIFIEX_TYPE_CMD */
2330 if (pkt_len <= adapter->intf_hdr_len ||
2331 pkt_len > MWIFIEX_UPLD_SIZE)
2332 mwifiex_dbg(adapter, ERROR,
2333 "%s: payload=%p, nb=%d\n",
2334 __func__, payload, pkt_len);
2336 if (card->supports_sdio_new_mode)
2337 port = CMD_PORT_SLCT;
2340 /* Transfer data to card */
2341 pkt_len = buf_block_len * blk_size;
2344 ret = mwifiex_host_to_card_mp_aggr(adapter, payload, pkt_len,
2345 port, tx_param->next_pkt_len
2348 ret = mwifiex_host_to_card_mp_aggr(adapter, payload, pkt_len,
2352 if (type == MWIFIEX_TYPE_CMD)
2353 adapter->cmd_sent = false;
2354 if (type == MWIFIEX_TYPE_DATA) {
2355 adapter->data_sent = false;
2356 /* restore curr_wr_port in error cases */
2357 card->curr_wr_port = port;
2358 card->mp_wr_bitmap |= (u32)(1 << card->curr_wr_port);
2361 if (type == MWIFIEX_TYPE_DATA) {
2362 if (!(card->mp_wr_bitmap & (1 << card->curr_wr_port)))
2363 adapter->data_sent = true;
2365 adapter->data_sent = false;
2373 * This function allocates the MPA Tx and Rx buffers.
2375 static int mwifiex_alloc_sdio_mpa_buffers(struct mwifiex_adapter *adapter,
2376 u32 mpa_tx_buf_size, u32 mpa_rx_buf_size)
2378 struct sdio_mmc_card *card = adapter->card;
2382 card->mpa_tx.buf = kzalloc(mpa_tx_buf_size, GFP_KERNEL);
2383 if (!card->mpa_tx.buf) {
2388 card->mpa_tx.buf_size = mpa_tx_buf_size;
2390 rx_buf_size = max_t(u32, mpa_rx_buf_size,
2391 (u32)SDIO_MAX_AGGR_BUF_SIZE);
2392 card->mpa_rx.buf = kzalloc(rx_buf_size, GFP_KERNEL);
2393 if (!card->mpa_rx.buf) {
2398 card->mpa_rx.buf_size = rx_buf_size;
2402 kfree(card->mpa_tx.buf);
2403 kfree(card->mpa_rx.buf);
2404 card->mpa_tx.buf_size = 0;
2405 card->mpa_rx.buf_size = 0;
2406 card->mpa_tx.buf = NULL;
2407 card->mpa_rx.buf = NULL;
2414 * This function unregisters the SDIO device.
2416 * The SDIO IRQ is released, the function is disabled and driver
2417 * data is set to null.
2420 mwifiex_unregister_dev(struct mwifiex_adapter *adapter)
2422 struct sdio_mmc_card *card = adapter->card;
2424 if (adapter->card) {
2425 card->adapter = NULL;
2426 sdio_claim_host(card->func);
2427 sdio_disable_func(card->func);
2428 sdio_release_host(card->func);
2433 * This function registers the SDIO device.
2435 * SDIO IRQ is claimed, block size is set and driver data is initialized.
2437 static int mwifiex_register_dev(struct mwifiex_adapter *adapter)
2440 struct sdio_mmc_card *card = adapter->card;
2441 struct sdio_func *func = card->func;
2443 /* save adapter pointer in card */
2444 card->adapter = adapter;
2445 adapter->tx_buf_size = card->tx_buf_size;
2447 sdio_claim_host(func);
2449 /* Set block size */
2450 ret = sdio_set_block_size(card->func, MWIFIEX_SDIO_BLOCK_SIZE);
2451 sdio_release_host(func);
2453 mwifiex_dbg(adapter, ERROR,
2454 "cannot set SDIO block size\n");
2458 strcpy(adapter->fw_name, card->firmware);
2459 if (card->fw_dump_enh) {
2460 adapter->mem_type_mapping_tbl = generic_mem_type_map;
2461 adapter->num_mem_types = 1;
2463 adapter->mem_type_mapping_tbl = mem_type_mapping_tbl;
2464 adapter->num_mem_types = ARRAY_SIZE(mem_type_mapping_tbl);
2471 * This function initializes the SDIO driver.
2473 * The following initializations steps are followed -
2474 * - Read the Host interrupt status register to acknowledge
2475 * the first interrupt got from bootloader
2476 * - Disable host interrupt mask register
2478 * - Initialize SDIO variables in card
2479 * - Allocate MP registers
2480 * - Allocate MPA Tx and Rx buffers
2482 static int mwifiex_init_sdio(struct mwifiex_adapter *adapter)
2484 struct sdio_mmc_card *card = adapter->card;
2485 const struct mwifiex_sdio_card_reg *reg = card->reg;
2489 sdio_set_drvdata(card->func, card);
2492 * Read the host_int_status_reg for ACK the first interrupt got
2493 * from the bootloader. If we don't do this we get a interrupt
2494 * as soon as we register the irq.
2496 mwifiex_read_reg(adapter, card->reg->host_int_status_reg, &sdio_ireg);
2498 /* Get SDIO ioport */
2499 mwifiex_init_sdio_ioport(adapter);
2501 /* Initialize SDIO variables in card */
2502 card->mp_rd_bitmap = 0;
2503 card->mp_wr_bitmap = 0;
2504 card->curr_rd_port = reg->start_rd_port;
2505 card->curr_wr_port = reg->start_wr_port;
2507 card->mp_data_port_mask = reg->data_port_mask;
2509 card->mpa_tx.buf_len = 0;
2510 card->mpa_tx.pkt_cnt = 0;
2511 card->mpa_tx.start_port = 0;
2513 card->mpa_tx.enabled = 1;
2514 card->mpa_tx.pkt_aggr_limit = card->mp_agg_pkt_limit;
2516 card->mpa_rx.buf_len = 0;
2517 card->mpa_rx.pkt_cnt = 0;
2518 card->mpa_rx.start_port = 0;
2520 card->mpa_rx.enabled = 1;
2521 card->mpa_rx.pkt_aggr_limit = card->mp_agg_pkt_limit;
2523 /* Allocate buffers for SDIO MP-A */
2524 card->mp_regs = kzalloc(reg->max_mp_regs, GFP_KERNEL);
2528 /* Allocate skb pointer buffers */
2529 card->mpa_rx.skb_arr = kcalloc(card->mp_agg_pkt_limit, sizeof(void *),
2531 if (!card->mpa_rx.skb_arr) {
2532 kfree(card->mp_regs);
2536 card->mpa_rx.len_arr = kcalloc(card->mp_agg_pkt_limit,
2537 sizeof(*card->mpa_rx.len_arr),
2539 if (!card->mpa_rx.len_arr) {
2540 kfree(card->mp_regs);
2541 kfree(card->mpa_rx.skb_arr);
2545 ret = mwifiex_alloc_sdio_mpa_buffers(adapter,
2546 card->mp_tx_agg_buf_size,
2547 card->mp_rx_agg_buf_size);
2549 /* Allocate 32k MPA Tx/Rx buffers if 64k memory allocation fails */
2550 if (ret && (card->mp_tx_agg_buf_size == MWIFIEX_MP_AGGR_BUF_SIZE_MAX ||
2551 card->mp_rx_agg_buf_size == MWIFIEX_MP_AGGR_BUF_SIZE_MAX)) {
2552 /* Disable rx single port aggregation */
2553 adapter->host_disable_sdio_rx_aggr = true;
2555 ret = mwifiex_alloc_sdio_mpa_buffers
2556 (adapter, MWIFIEX_MP_AGGR_BUF_SIZE_32K,
2557 MWIFIEX_MP_AGGR_BUF_SIZE_32K);
2559 /* Disable multi port aggregation */
2560 card->mpa_tx.enabled = 0;
2561 card->mpa_rx.enabled = 0;
2565 adapter->auto_tdls = card->can_auto_tdls;
2566 adapter->ext_scan = card->can_ext_scan;
2571 * This function resets the MPA Tx and Rx buffers.
2573 static void mwifiex_cleanup_mpa_buf(struct mwifiex_adapter *adapter)
2575 struct sdio_mmc_card *card = adapter->card;
2577 MP_TX_AGGR_BUF_RESET(card);
2578 MP_RX_AGGR_BUF_RESET(card);
2582 * This function cleans up the allocated card buffers.
2584 * The following are freed by this function -
2589 static void mwifiex_cleanup_sdio(struct mwifiex_adapter *adapter)
2591 struct sdio_mmc_card *card = adapter->card;
2593 cancel_work_sync(&card->work);
2595 kfree(card->mp_regs);
2596 kfree(card->mpa_rx.skb_arr);
2597 kfree(card->mpa_rx.len_arr);
2598 kfree(card->mpa_tx.buf);
2599 kfree(card->mpa_rx.buf);
2603 * This function updates the MP end port in card.
2606 mwifiex_update_mp_end_port(struct mwifiex_adapter *adapter, u16 port)
2608 struct sdio_mmc_card *card = adapter->card;
2609 const struct mwifiex_sdio_card_reg *reg = card->reg;
2612 card->mp_end_port = port;
2614 card->mp_data_port_mask = reg->data_port_mask;
2616 if (reg->start_wr_port) {
2617 for (i = 1; i <= card->max_ports - card->mp_end_port; i++)
2618 card->mp_data_port_mask &=
2619 ~(1 << (card->max_ports - i));
2622 card->curr_wr_port = reg->start_wr_port;
2624 mwifiex_dbg(adapter, CMD,
2625 "cmd: mp_end_port %d, data port mask 0x%x\n",
2626 port, card->mp_data_port_mask);
2629 static void mwifiex_sdio_card_reset_work(struct mwifiex_adapter *adapter)
2631 struct sdio_mmc_card *card = adapter->card;
2632 struct sdio_func *func = card->func;
2635 /* Prepare the adapter for the reset. */
2636 mwifiex_shutdown_sw(adapter);
2637 clear_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP, &card->work_flags);
2638 clear_bit(MWIFIEX_IFACE_WORK_CARD_RESET, &card->work_flags);
2640 /* Run a HW reset of the SDIO interface. */
2641 sdio_claim_host(func);
2642 ret = mmc_hw_reset(func->card->host);
2643 sdio_release_host(func);
2647 dev_dbg(&func->dev, "SDIO HW reset asynchronous\n");
2648 complete_all(adapter->fw_done);
2651 ret = mwifiex_reinit_sw(adapter);
2653 dev_err(&func->dev, "reinit failed: %d\n", ret);
2656 dev_err(&func->dev, "SDIO HW reset failed: %d\n", ret);
2661 /* This function read/write firmware */
2663 rdwr_status mwifiex_sdio_rdwr_firmware(struct mwifiex_adapter *adapter,
2666 struct sdio_mmc_card *card = adapter->card;
2670 sdio_writeb(card->func, card->reg->fw_dump_host_ready,
2671 card->reg->fw_dump_ctrl, &ret);
2673 mwifiex_dbg(adapter, ERROR, "SDIO Write ERR\n");
2674 return RDWR_STATUS_FAILURE;
2676 for (tries = 0; tries < MAX_POLL_TRIES; tries++) {
2677 ctrl_data = sdio_readb(card->func, card->reg->fw_dump_ctrl,
2680 mwifiex_dbg(adapter, ERROR, "SDIO read err\n");
2681 return RDWR_STATUS_FAILURE;
2683 if (ctrl_data == FW_DUMP_DONE)
2685 if (doneflag && ctrl_data == doneflag)
2686 return RDWR_STATUS_DONE;
2687 if (ctrl_data != card->reg->fw_dump_host_ready) {
2688 mwifiex_dbg(adapter, WARN,
2689 "The ctrl reg was changed, re-try again\n");
2690 sdio_writeb(card->func, card->reg->fw_dump_host_ready,
2691 card->reg->fw_dump_ctrl, &ret);
2693 mwifiex_dbg(adapter, ERROR, "SDIO write err\n");
2694 return RDWR_STATUS_FAILURE;
2697 usleep_range(100, 200);
2699 if (ctrl_data == card->reg->fw_dump_host_ready) {
2700 mwifiex_dbg(adapter, ERROR,
2701 "Fail to pull ctrl_data\n");
2702 return RDWR_STATUS_FAILURE;
2705 return RDWR_STATUS_SUCCESS;
2708 /* This function dump firmware memory to file */
2709 static void mwifiex_sdio_fw_dump(struct mwifiex_adapter *adapter)
2711 struct sdio_mmc_card *card = adapter->card;
2713 unsigned int reg, reg_start, reg_end;
2714 u8 *dbg_ptr, *end_ptr, dump_num, idx, i, read_reg, doneflag = 0;
2715 enum rdwr_status stat;
2718 if (!card->can_dump_fw)
2721 for (idx = 0; idx < ARRAY_SIZE(mem_type_mapping_tbl); idx++) {
2722 struct memory_type_mapping *entry = &mem_type_mapping_tbl[idx];
2724 if (entry->mem_ptr) {
2725 vfree(entry->mem_ptr);
2726 entry->mem_ptr = NULL;
2728 entry->mem_size = 0;
2731 mwifiex_pm_wakeup_card(adapter);
2732 sdio_claim_host(card->func);
2734 mwifiex_dbg(adapter, MSG, "== mwifiex firmware dump start ==\n");
2736 stat = mwifiex_sdio_rdwr_firmware(adapter, doneflag);
2737 if (stat == RDWR_STATUS_FAILURE)
2740 reg = card->reg->fw_dump_start;
2741 /* Read the number of the memories which will dump */
2742 dump_num = sdio_readb(card->func, reg, &ret);
2744 mwifiex_dbg(adapter, ERROR, "SDIO read memory length err\n");
2748 /* Read the length of every memory which will dump */
2749 for (idx = 0; idx < dump_num; idx++) {
2750 struct memory_type_mapping *entry = &mem_type_mapping_tbl[idx];
2752 stat = mwifiex_sdio_rdwr_firmware(adapter, doneflag);
2753 if (stat == RDWR_STATUS_FAILURE)
2757 reg = card->reg->fw_dump_start;
2758 for (i = 0; i < 4; i++) {
2759 read_reg = sdio_readb(card->func, reg, &ret);
2761 mwifiex_dbg(adapter, ERROR, "SDIO read err\n");
2764 memory_size |= (read_reg << i*8);
2768 if (memory_size == 0) {
2769 mwifiex_dbg(adapter, DUMP, "Firmware dump Finished!\n");
2770 ret = mwifiex_write_reg(adapter,
2771 card->reg->fw_dump_ctrl,
2774 mwifiex_dbg(adapter, ERROR, "SDIO write err\n");
2780 mwifiex_dbg(adapter, DUMP,
2781 "%s_SIZE=0x%x\n", entry->mem_name, memory_size);
2782 entry->mem_ptr = vmalloc(memory_size + 1);
2783 entry->mem_size = memory_size;
2784 if (!entry->mem_ptr) {
2785 mwifiex_dbg(adapter, ERROR, "Vmalloc %s failed\n",
2789 dbg_ptr = entry->mem_ptr;
2790 end_ptr = dbg_ptr + memory_size;
2792 doneflag = entry->done_flag;
2793 mwifiex_dbg(adapter, DUMP,
2794 "Start %s output, please wait...\n",
2798 stat = mwifiex_sdio_rdwr_firmware(adapter, doneflag);
2799 if (stat == RDWR_STATUS_FAILURE)
2802 reg_start = card->reg->fw_dump_start;
2803 reg_end = card->reg->fw_dump_end;
2804 for (reg = reg_start; reg <= reg_end; reg++) {
2805 *dbg_ptr = sdio_readb(card->func, reg, &ret);
2807 mwifiex_dbg(adapter, ERROR,
2811 if (dbg_ptr < end_ptr)
2814 mwifiex_dbg(adapter, ERROR,
2815 "Allocated buf not enough\n");
2818 if (stat != RDWR_STATUS_DONE)
2821 mwifiex_dbg(adapter, DUMP, "%s done: size=0x%tx\n",
2822 entry->mem_name, dbg_ptr - entry->mem_ptr);
2826 mwifiex_dbg(adapter, MSG, "== mwifiex firmware dump end ==\n");
2829 sdio_release_host(card->func);
2832 static void mwifiex_sdio_generic_fw_dump(struct mwifiex_adapter *adapter)
2834 struct sdio_mmc_card *card = adapter->card;
2835 struct memory_type_mapping *entry = &generic_mem_type_map[0];
2836 unsigned int reg, reg_start, reg_end;
2837 u8 start_flag = 0, done_flag = 0;
2838 u8 *dbg_ptr, *end_ptr;
2839 enum rdwr_status stat;
2840 int ret = -1, tries;
2842 if (!card->fw_dump_enh)
2845 if (entry->mem_ptr) {
2846 vfree(entry->mem_ptr);
2847 entry->mem_ptr = NULL;
2849 entry->mem_size = 0;
2851 mwifiex_pm_wakeup_card(adapter);
2852 sdio_claim_host(card->func);
2854 mwifiex_dbg(adapter, MSG, "== mwifiex firmware dump start ==\n");
2856 stat = mwifiex_sdio_rdwr_firmware(adapter, done_flag);
2857 if (stat == RDWR_STATUS_FAILURE)
2860 reg_start = card->reg->fw_dump_start;
2861 reg_end = card->reg->fw_dump_end;
2862 for (reg = reg_start; reg <= reg_end; reg++) {
2863 for (tries = 0; tries < MAX_POLL_TRIES; tries++) {
2864 start_flag = sdio_readb(card->func, reg, &ret);
2866 mwifiex_dbg(adapter, ERROR,
2870 if (start_flag == 0)
2872 if (tries == MAX_POLL_TRIES) {
2873 mwifiex_dbg(adapter, ERROR,
2874 "FW not ready to dump\n");
2879 usleep_range(100, 200);
2882 entry->mem_ptr = vmalloc(0xf0000 + 1);
2883 if (!entry->mem_ptr) {
2887 dbg_ptr = entry->mem_ptr;
2888 entry->mem_size = 0xf0000;
2889 end_ptr = dbg_ptr + entry->mem_size;
2891 done_flag = entry->done_flag;
2892 mwifiex_dbg(adapter, DUMP,
2893 "Start %s output, please wait...\n", entry->mem_name);
2896 stat = mwifiex_sdio_rdwr_firmware(adapter, done_flag);
2897 if (stat == RDWR_STATUS_FAILURE)
2899 for (reg = reg_start; reg <= reg_end; reg++) {
2900 *dbg_ptr = sdio_readb(card->func, reg, &ret);
2902 mwifiex_dbg(adapter, ERROR,
2907 if (dbg_ptr >= end_ptr) {
2910 tmp_ptr = vmalloc(entry->mem_size + 0x4000 + 1);
2914 memcpy(tmp_ptr, entry->mem_ptr,
2916 vfree(entry->mem_ptr);
2917 entry->mem_ptr = tmp_ptr;
2919 dbg_ptr = entry->mem_ptr + entry->mem_size;
2920 entry->mem_size += 0x4000;
2921 end_ptr = entry->mem_ptr + entry->mem_size;
2924 if (stat == RDWR_STATUS_DONE) {
2925 entry->mem_size = dbg_ptr - entry->mem_ptr;
2926 mwifiex_dbg(adapter, DUMP, "dump %s done size=0x%x\n",
2927 entry->mem_name, entry->mem_size);
2932 mwifiex_dbg(adapter, MSG, "== mwifiex firmware dump end ==\n");
2936 mwifiex_dbg(adapter, ERROR, "firmware dump failed\n");
2937 if (entry->mem_ptr) {
2938 vfree(entry->mem_ptr);
2939 entry->mem_ptr = NULL;
2941 entry->mem_size = 0;
2943 sdio_release_host(card->func);
2946 static void mwifiex_sdio_device_dump_work(struct mwifiex_adapter *adapter)
2948 struct sdio_mmc_card *card = adapter->card;
2950 adapter->devdump_data = vzalloc(MWIFIEX_FW_DUMP_SIZE);
2951 if (!adapter->devdump_data) {
2952 mwifiex_dbg(adapter, ERROR,
2953 "vzalloc devdump data failure!\n");
2957 mwifiex_drv_info_dump(adapter);
2958 if (card->fw_dump_enh)
2959 mwifiex_sdio_generic_fw_dump(adapter);
2961 mwifiex_sdio_fw_dump(adapter);
2962 mwifiex_prepare_fw_dump_info(adapter);
2963 mwifiex_upload_device_dump(adapter);
2966 static void mwifiex_sdio_work(struct work_struct *work)
2968 struct sdio_mmc_card *card =
2969 container_of(work, struct sdio_mmc_card, work);
2971 if (test_and_clear_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP,
2973 mwifiex_sdio_device_dump_work(card->adapter);
2974 if (test_and_clear_bit(MWIFIEX_IFACE_WORK_CARD_RESET,
2976 mwifiex_sdio_card_reset_work(card->adapter);
2979 /* This function resets the card */
2980 static void mwifiex_sdio_card_reset(struct mwifiex_adapter *adapter)
2982 struct sdio_mmc_card *card = adapter->card;
2984 if (!test_and_set_bit(MWIFIEX_IFACE_WORK_CARD_RESET, &card->work_flags))
2985 schedule_work(&card->work);
2988 /* This function dumps FW information */
2989 static void mwifiex_sdio_device_dump(struct mwifiex_adapter *adapter)
2991 struct sdio_mmc_card *card = adapter->card;
2993 if (!test_and_set_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP,
2995 schedule_work(&card->work);
2998 /* Function to dump SDIO function registers and SDIO scratch registers in case
3002 mwifiex_sdio_reg_dump(struct mwifiex_adapter *adapter, char *drv_buf)
3005 struct sdio_mmc_card *cardp = adapter->card;
3007 u8 count, func, data, index = 0, size = 0;
3008 u8 reg, reg_start, reg_end;
3009 char buf[256], *ptr;
3014 mwifiex_dbg(adapter, MSG, "SDIO register dump start\n");
3016 mwifiex_pm_wakeup_card(adapter);
3018 sdio_claim_host(cardp->func);
3020 for (count = 0; count < 5; count++) {
3021 memset(buf, 0, sizeof(buf));
3026 /* Read the registers of SDIO function0 */
3032 /* Read the registers of SDIO function1 */
3034 reg_start = cardp->reg->func1_dump_reg_start;
3035 reg_end = cardp->reg->func1_dump_reg_end;
3040 reg_start = cardp->reg->func1_spec_reg_table[index++];
3041 size = cardp->reg->func1_spec_reg_num;
3042 reg_end = cardp->reg->func1_spec_reg_table[size-1];
3045 /* Read the scratch registers of SDIO function1 */
3049 reg_start = cardp->reg->func1_scratch_reg;
3050 reg_end = reg_start + MWIFIEX_SDIO_SCRATCH_SIZE;
3054 ptr += sprintf(ptr, "SDIO Func%d (%#x-%#x): ",
3055 func, reg_start, reg_end);
3057 ptr += sprintf(ptr, "SDIO Func%d: ", func);
3059 for (reg = reg_start; reg <= reg_end;) {
3061 data = sdio_f0_readb(cardp->func, reg, &ret);
3063 data = sdio_readb(cardp->func, reg, &ret);
3066 ptr += sprintf(ptr, "(%#x) ", reg);
3068 ptr += sprintf(ptr, "%02x ", data);
3070 ptr += sprintf(ptr, "ERR");
3074 if (count == 2 && reg < reg_end)
3075 reg = cardp->reg->func1_spec_reg_table[index++];
3080 mwifiex_dbg(adapter, MSG, "%s\n", buf);
3081 p += sprintf(p, "%s\n", buf);
3084 sdio_release_host(cardp->func);
3086 mwifiex_dbg(adapter, MSG, "SDIO register dump end\n");
3091 /* sdio device/function initialization, code is extracted
3092 * from init_if handler and register_dev handler.
3094 static void mwifiex_sdio_up_dev(struct mwifiex_adapter *adapter)
3096 struct sdio_mmc_card *card = adapter->card;
3099 sdio_claim_host(card->func);
3100 sdio_enable_func(card->func);
3101 sdio_set_block_size(card->func, MWIFIEX_SDIO_BLOCK_SIZE);
3102 sdio_release_host(card->func);
3104 /* tx_buf_size might be changed to 3584 by firmware during
3105 * data transfer, we will reset to default size.
3107 adapter->tx_buf_size = card->tx_buf_size;
3109 /* Read the host_int_status_reg for ACK the first interrupt got
3110 * from the bootloader. If we don't do this we get a interrupt
3111 * as soon as we register the irq.
3113 mwifiex_read_reg(adapter, card->reg->host_int_status_reg, &sdio_ireg);
3115 mwifiex_init_sdio_ioport(adapter);
3118 static struct mwifiex_if_ops sdio_ops = {
3119 .init_if = mwifiex_init_sdio,
3120 .cleanup_if = mwifiex_cleanup_sdio,
3121 .check_fw_status = mwifiex_check_fw_status,
3122 .check_winner_status = mwifiex_check_winner_status,
3123 .prog_fw = mwifiex_prog_fw_w_helper,
3124 .register_dev = mwifiex_register_dev,
3125 .unregister_dev = mwifiex_unregister_dev,
3126 .enable_int = mwifiex_sdio_enable_host_int,
3127 .disable_int = mwifiex_sdio_disable_host_int,
3128 .process_int_status = mwifiex_process_int_status,
3129 .host_to_card = mwifiex_sdio_host_to_card,
3130 .wakeup = mwifiex_pm_wakeup_card,
3131 .wakeup_complete = mwifiex_pm_wakeup_card_complete,
3134 .update_mp_end_port = mwifiex_update_mp_end_port,
3135 .cleanup_mpa_buf = mwifiex_cleanup_mpa_buf,
3136 .cmdrsp_complete = mwifiex_sdio_cmdrsp_complete,
3137 .event_complete = mwifiex_sdio_event_complete,
3138 .dnld_fw = mwifiex_sdio_dnld_fw,
3139 .card_reset = mwifiex_sdio_card_reset,
3140 .reg_dump = mwifiex_sdio_reg_dump,
3141 .device_dump = mwifiex_sdio_device_dump,
3142 .deaggr_pkt = mwifiex_deaggr_sdio_pkt,
3143 .up_dev = mwifiex_sdio_up_dev,
3146 module_driver(mwifiex_sdio, sdio_register_driver, sdio_unregister_driver);
3148 MODULE_AUTHOR("Marvell International Ltd.");
3149 MODULE_DESCRIPTION("Marvell WiFi-Ex SDIO Driver version " SDIO_VERSION);
3150 MODULE_VERSION(SDIO_VERSION);
3151 MODULE_LICENSE("GPL v2");
3152 MODULE_FIRMWARE(SD8786_DEFAULT_FW_NAME);
3153 MODULE_FIRMWARE(SD8787_DEFAULT_FW_NAME);
3154 MODULE_FIRMWARE(SD8797_DEFAULT_FW_NAME);
3155 MODULE_FIRMWARE(SD8897_DEFAULT_FW_NAME);
3156 MODULE_FIRMWARE(SD8887_DEFAULT_FW_NAME);
3157 MODULE_FIRMWARE(SD8977_DEFAULT_FW_NAME);
3158 MODULE_FIRMWARE(SD8987_DEFAULT_FW_NAME);
3159 MODULE_FIRMWARE(SD8997_DEFAULT_FW_NAME);