2 * Marvell Wireless LAN device driver: SDIO specific definitions
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 #ifndef _MWIFIEX_SDIO_H
21 #define _MWIFIEX_SDIO_H
24 #include <linux/completion.h>
25 #include <linux/mmc/sdio.h>
26 #include <linux/mmc/sdio_ids.h>
27 #include <linux/mmc/sdio_func.h>
28 #include <linux/mmc/card.h>
29 #include <linux/mmc/host.h>
33 #define SD8786_DEFAULT_FW_NAME "mrvl/sd8786_uapsta.bin"
34 #define SD8787_DEFAULT_FW_NAME "mrvl/sd8787_uapsta.bin"
35 #define SD8797_DEFAULT_FW_NAME "mrvl/sd8797_uapsta.bin"
36 #define SD8897_DEFAULT_FW_NAME "mrvl/sd8897_uapsta.bin"
37 #define SD8887_DEFAULT_FW_NAME "mrvl/sd8887_uapsta.bin"
38 #define SD8801_DEFAULT_FW_NAME "mrvl/sd8801_uapsta.bin"
39 #define SD8997_DEFAULT_FW_NAME "mrvl/sd8997_uapsta.bin"
46 #define MWIFIEX_SDIO_IO_PORT_MASK 0xfffff
48 #define MWIFIEX_SDIO_BYTE_MODE_MASK 0x80000000
50 #define MWIFIEX_MAX_FUNC2_REG_NUM 13
51 #define MWIFIEX_SDIO_SCRATCH_SIZE 10
53 #define SDIO_MPA_ADDR_BASE 0x1000
55 #define CTRL_PORT_MASK 0x0001
57 #define CMD_PORT_UPLD_INT_MASK (0x1U<<6)
58 #define CMD_PORT_DNLD_INT_MASK (0x1U<<7)
59 #define HOST_TERM_CMD53 (0x1U << 2)
61 #define MEM_PORT 0x10000
63 #define CMD53_NEW_MODE (0x1U << 0)
64 #define CMD_PORT_RD_LEN_EN (0x1U << 2)
65 #define CMD_PORT_AUTO_EN (0x1U << 0)
66 #define CMD_PORT_SLCT 0x8000
67 #define UP_LD_CMD_PORT_HOST_INT_STATUS (0x40U)
68 #define DN_LD_CMD_PORT_HOST_INT_STATUS (0x80U)
70 #define MWIFIEX_MP_AGGR_BUF_SIZE_16K (16384)
71 #define MWIFIEX_MP_AGGR_BUF_SIZE_32K (32768)
72 /* we leave one block of 256 bytes for DMA alignment*/
73 #define MWIFIEX_MP_AGGR_BUF_SIZE_MAX (65280)
75 /* Misc. Config Register : Auto Re-enable interrupts */
76 #define AUTO_RE_ENABLE_INT BIT(4)
78 /* Host Control Registers : Configuration */
79 #define CONFIGURATION_REG 0x00
80 /* Host Control Registers : Host power up */
81 #define HOST_POWER_UP (0x1U << 1)
83 /* Host Control Registers : Upload host interrupt mask */
84 #define UP_LD_HOST_INT_MASK (0x1U)
85 /* Host Control Registers : Download host interrupt mask */
86 #define DN_LD_HOST_INT_MASK (0x2U)
88 /* Host Control Registers : Upload host interrupt status */
89 #define UP_LD_HOST_INT_STATUS (0x1U)
90 /* Host Control Registers : Download host interrupt status */
91 #define DN_LD_HOST_INT_STATUS (0x2U)
93 /* Host Control Registers : Host interrupt status */
94 #define CARD_INT_STATUS_REG 0x28
96 /* Card Control Registers : Card I/O ready */
97 #define CARD_IO_READY (0x1U << 3)
98 /* Card Control Registers : Download card ready */
99 #define DN_LD_CARD_RDY (0x1U << 0)
101 /* Max retry number of CMD53 write */
102 #define MAX_WRITE_IOMEM_RETRY 2
104 /* SDIO Tx aggregation in progress ? */
105 #define MP_TX_AGGR_IN_PROGRESS(a) (a->mpa_tx.pkt_cnt > 0)
107 /* SDIO Tx aggregation buffer room for next packet ? */
108 #define MP_TX_AGGR_BUF_HAS_ROOM(a, len) ((a->mpa_tx.buf_len+len) \
109 <= a->mpa_tx.buf_size)
111 /* Copy current packet (SDIO Tx aggregation buffer) to SDIO buffer */
112 #define MP_TX_AGGR_BUF_PUT(a, payload, pkt_len, port) do { \
113 memmove(&a->mpa_tx.buf[a->mpa_tx.buf_len], \
115 a->mpa_tx.buf_len += pkt_len; \
116 if (!a->mpa_tx.pkt_cnt) \
117 a->mpa_tx.start_port = port; \
118 if (a->mpa_tx.start_port <= port) \
119 a->mpa_tx.ports |= (1<<(a->mpa_tx.pkt_cnt)); \
121 a->mpa_tx.ports |= (1<<(a->mpa_tx.pkt_cnt+1+ \
124 a->mpa_tx.pkt_cnt++; \
127 /* SDIO Tx aggregation limit ? */
128 #define MP_TX_AGGR_PKT_LIMIT_REACHED(a) \
129 (a->mpa_tx.pkt_cnt == a->mpa_tx.pkt_aggr_limit)
131 /* Reset SDIO Tx aggregation buffer parameters */
132 #define MP_TX_AGGR_BUF_RESET(a) do { \
133 a->mpa_tx.pkt_cnt = 0; \
134 a->mpa_tx.buf_len = 0; \
135 a->mpa_tx.ports = 0; \
136 a->mpa_tx.start_port = 0; \
139 /* SDIO Rx aggregation limit ? */
140 #define MP_RX_AGGR_PKT_LIMIT_REACHED(a) \
141 (a->mpa_rx.pkt_cnt == a->mpa_rx.pkt_aggr_limit)
143 /* SDIO Rx aggregation in progress ? */
144 #define MP_RX_AGGR_IN_PROGRESS(a) (a->mpa_rx.pkt_cnt > 0)
146 /* SDIO Rx aggregation buffer room for next packet ? */
147 #define MP_RX_AGGR_BUF_HAS_ROOM(a, rx_len) \
148 ((a->mpa_rx.buf_len+rx_len) <= a->mpa_rx.buf_size)
150 /* Reset SDIO Rx aggregation buffer parameters */
151 #define MP_RX_AGGR_BUF_RESET(a) do { \
152 a->mpa_rx.pkt_cnt = 0; \
153 a->mpa_rx.buf_len = 0; \
154 a->mpa_rx.ports = 0; \
155 a->mpa_rx.start_port = 0; \
158 /* data structure for SDIO MPA TX */
159 struct mwifiex_sdio_mpa_tx
{
160 /* multiport tx aggregation buffer pointer */
171 struct mwifiex_sdio_mpa_rx
{
178 struct sk_buff
**skb_arr
;
186 int mwifiex_bus_register(void);
187 void mwifiex_bus_unregister(void);
189 struct mwifiex_sdio_card_reg
{
197 u8 host_int_status_reg
;
198 u8 host_int_mask_reg
;
217 u8 card_misc_cfg_reg
;
227 u8 fw_dump_host_ready
;
231 u8 func1_dump_reg_start
;
232 u8 func1_dump_reg_end
;
233 u8 func1_scratch_reg
;
234 u8 func1_spec_reg_num
;
235 u8 func1_spec_reg_table
[MWIFIEX_MAX_FUNC2_REG_NUM
];
238 struct sdio_mmc_card
{
239 struct sdio_func
*func
;
240 struct mwifiex_adapter
*adapter
;
242 struct completion fw_done
;
243 const char *firmware
;
244 const struct mwifiex_sdio_card_reg
*reg
;
248 u32 mp_tx_agg_buf_size
;
249 u32 mp_rx_agg_buf_size
;
255 u32 mp_data_port_mask
;
261 bool supports_sdio_new_mode
;
262 bool has_control_mask
;
268 struct mwifiex_sdio_mpa_tx mpa_tx
;
269 struct mwifiex_sdio_mpa_rx mpa_rx
;
271 struct work_struct work
;
272 unsigned long work_flags
;
275 struct mwifiex_sdio_device
{
276 const char *firmware
;
277 const struct mwifiex_sdio_card_reg
*reg
;
281 u32 mp_tx_agg_buf_size
;
282 u32 mp_rx_agg_buf_size
;
283 bool supports_sdio_new_mode
;
284 bool has_control_mask
;
291 static const struct mwifiex_sdio_card_reg mwifiex_reg_sd87xx
= {
294 .base_0_reg
= 0x0040,
295 .base_1_reg
= 0x0041,
297 .host_int_enable
= UP_LD_HOST_INT_MASK
| DN_LD_HOST_INT_MASK
,
298 .host_int_rsr_reg
= 0x1,
299 .host_int_mask_reg
= 0x02,
300 .host_int_status_reg
= 0x03,
301 .status_reg_0
= 0x60,
302 .status_reg_1
= 0x61,
303 .sdio_int_mask
= 0x3f,
304 .data_port_mask
= 0x0000fffe,
305 .io_port_0_reg
= 0x78,
306 .io_port_1_reg
= 0x79,
307 .io_port_2_reg
= 0x7A,
315 .card_misc_cfg_reg
= 0x6c,
316 .func1_dump_reg_start
= 0x0,
317 .func1_dump_reg_end
= 0x9,
318 .func1_scratch_reg
= 0x60,
319 .func1_spec_reg_num
= 5,
320 .func1_spec_reg_table
= {0x28, 0x30, 0x34, 0x38, 0x3c},
323 static const struct mwifiex_sdio_card_reg mwifiex_reg_sd8897
= {
329 .host_int_enable
= UP_LD_HOST_INT_MASK
| DN_LD_HOST_INT_MASK
|
330 CMD_PORT_UPLD_INT_MASK
| CMD_PORT_DNLD_INT_MASK
,
331 .host_int_rsr_reg
= 0x1,
332 .host_int_status_reg
= 0x03,
333 .host_int_mask_reg
= 0x02,
334 .status_reg_0
= 0xc0,
335 .status_reg_1
= 0xc1,
336 .sdio_int_mask
= 0xff,
337 .data_port_mask
= 0xffffffff,
338 .io_port_0_reg
= 0xD8,
339 .io_port_1_reg
= 0xD9,
340 .io_port_2_reg
= 0xDA,
344 .rd_bitmap_1l
= 0x06,
345 .rd_bitmap_1u
= 0x07,
348 .wr_bitmap_1l
= 0x0a,
349 .wr_bitmap_1u
= 0x0b,
352 .card_misc_cfg_reg
= 0xcc,
353 .card_cfg_2_1_reg
= 0xcd,
354 .cmd_rd_len_0
= 0xb4,
355 .cmd_rd_len_1
= 0xb5,
356 .cmd_rd_len_2
= 0xb6,
357 .cmd_rd_len_3
= 0xb7,
362 .fw_dump_host_ready
= 0xee,
363 .fw_dump_ctrl
= 0xe2,
364 .fw_dump_start
= 0xe3,
366 .func1_dump_reg_start
= 0x0,
367 .func1_dump_reg_end
= 0xb,
368 .func1_scratch_reg
= 0xc0,
369 .func1_spec_reg_num
= 8,
370 .func1_spec_reg_table
= {0x4C, 0x50, 0x54, 0x55, 0x58,
374 static const struct mwifiex_sdio_card_reg mwifiex_reg_sd8997
= {
380 .host_int_enable
= UP_LD_HOST_INT_MASK
| DN_LD_HOST_INT_MASK
|
381 CMD_PORT_UPLD_INT_MASK
| CMD_PORT_DNLD_INT_MASK
,
382 .host_int_rsr_reg
= 0x4,
383 .host_int_status_reg
= 0x0C,
384 .host_int_mask_reg
= 0x08,
385 .status_reg_0
= 0xE8,
386 .status_reg_1
= 0xE9,
387 .sdio_int_mask
= 0xff,
388 .data_port_mask
= 0xffffffff,
389 .io_port_0_reg
= 0xE4,
390 .io_port_1_reg
= 0xE5,
391 .io_port_2_reg
= 0xE6,
395 .rd_bitmap_1l
= 0x12,
396 .rd_bitmap_1u
= 0x13,
399 .wr_bitmap_1l
= 0x16,
400 .wr_bitmap_1u
= 0x17,
403 .card_misc_cfg_reg
= 0xd8,
404 .card_cfg_2_1_reg
= 0xd9,
405 .cmd_rd_len_0
= 0xc0,
406 .cmd_rd_len_1
= 0xc1,
407 .cmd_rd_len_2
= 0xc2,
408 .cmd_rd_len_3
= 0xc3,
413 .fw_dump_host_ready
= 0xcc,
414 .fw_dump_ctrl
= 0xf0,
415 .fw_dump_start
= 0xf1,
417 .func1_dump_reg_start
= 0x10,
418 .func1_dump_reg_end
= 0x17,
419 .func1_scratch_reg
= 0xe8,
420 .func1_spec_reg_num
= 13,
421 .func1_spec_reg_table
= {0x08, 0x58, 0x5C, 0x5D,
422 0x60, 0x61, 0x62, 0x64,
423 0x65, 0x66, 0x68, 0x69,
427 static const struct mwifiex_sdio_card_reg mwifiex_reg_sd8887
= {
433 .host_int_enable
= UP_LD_HOST_INT_MASK
| DN_LD_HOST_INT_MASK
|
434 CMD_PORT_UPLD_INT_MASK
| CMD_PORT_DNLD_INT_MASK
,
435 .host_int_rsr_reg
= 0x4,
436 .host_int_status_reg
= 0x0C,
437 .host_int_mask_reg
= 0x08,
438 .status_reg_0
= 0x90,
439 .status_reg_1
= 0x91,
440 .sdio_int_mask
= 0xff,
441 .data_port_mask
= 0xffffffff,
442 .io_port_0_reg
= 0xE4,
443 .io_port_1_reg
= 0xE5,
444 .io_port_2_reg
= 0xE6,
448 .rd_bitmap_1l
= 0x12,
449 .rd_bitmap_1u
= 0x13,
452 .wr_bitmap_1l
= 0x16,
453 .wr_bitmap_1u
= 0x17,
456 .card_misc_cfg_reg
= 0xd8,
457 .card_cfg_2_1_reg
= 0xd9,
458 .cmd_rd_len_0
= 0xc0,
459 .cmd_rd_len_1
= 0xc1,
460 .cmd_rd_len_2
= 0xc2,
461 .cmd_rd_len_3
= 0xc3,
466 .func1_dump_reg_start
= 0x10,
467 .func1_dump_reg_end
= 0x17,
468 .func1_scratch_reg
= 0x90,
469 .func1_spec_reg_num
= 13,
470 .func1_spec_reg_table
= {0x08, 0x58, 0x5C, 0x5D, 0x60,
471 0x61, 0x62, 0x64, 0x65, 0x66,
475 static const struct mwifiex_sdio_device mwifiex_sdio_sd8786
= {
476 .firmware
= SD8786_DEFAULT_FW_NAME
,
477 .reg
= &mwifiex_reg_sd87xx
,
479 .mp_agg_pkt_limit
= 8,
480 .tx_buf_size
= MWIFIEX_TX_DATA_BUF_SIZE_2K
,
481 .mp_tx_agg_buf_size
= MWIFIEX_MP_AGGR_BUF_SIZE_16K
,
482 .mp_rx_agg_buf_size
= MWIFIEX_MP_AGGR_BUF_SIZE_16K
,
483 .supports_sdio_new_mode
= false,
484 .has_control_mask
= true,
485 .can_dump_fw
= false,
486 .can_auto_tdls
= false,
487 .can_ext_scan
= false,
490 static const struct mwifiex_sdio_device mwifiex_sdio_sd8787
= {
491 .firmware
= SD8787_DEFAULT_FW_NAME
,
492 .reg
= &mwifiex_reg_sd87xx
,
494 .mp_agg_pkt_limit
= 8,
495 .tx_buf_size
= MWIFIEX_TX_DATA_BUF_SIZE_2K
,
496 .mp_tx_agg_buf_size
= MWIFIEX_MP_AGGR_BUF_SIZE_16K
,
497 .mp_rx_agg_buf_size
= MWIFIEX_MP_AGGR_BUF_SIZE_16K
,
498 .supports_sdio_new_mode
= false,
499 .has_control_mask
= true,
500 .can_dump_fw
= false,
501 .can_auto_tdls
= false,
502 .can_ext_scan
= true,
505 static const struct mwifiex_sdio_device mwifiex_sdio_sd8797
= {
506 .firmware
= SD8797_DEFAULT_FW_NAME
,
507 .reg
= &mwifiex_reg_sd87xx
,
509 .mp_agg_pkt_limit
= 8,
510 .tx_buf_size
= MWIFIEX_TX_DATA_BUF_SIZE_2K
,
511 .mp_tx_agg_buf_size
= MWIFIEX_MP_AGGR_BUF_SIZE_16K
,
512 .mp_rx_agg_buf_size
= MWIFIEX_MP_AGGR_BUF_SIZE_16K
,
513 .supports_sdio_new_mode
= false,
514 .has_control_mask
= true,
515 .can_dump_fw
= false,
516 .can_auto_tdls
= false,
517 .can_ext_scan
= true,
520 static const struct mwifiex_sdio_device mwifiex_sdio_sd8897
= {
521 .firmware
= SD8897_DEFAULT_FW_NAME
,
522 .reg
= &mwifiex_reg_sd8897
,
524 .mp_agg_pkt_limit
= 16,
525 .tx_buf_size
= MWIFIEX_TX_DATA_BUF_SIZE_4K
,
526 .mp_tx_agg_buf_size
= MWIFIEX_MP_AGGR_BUF_SIZE_MAX
,
527 .mp_rx_agg_buf_size
= MWIFIEX_MP_AGGR_BUF_SIZE_MAX
,
528 .supports_sdio_new_mode
= true,
529 .has_control_mask
= false,
531 .can_auto_tdls
= false,
532 .can_ext_scan
= true,
535 static const struct mwifiex_sdio_device mwifiex_sdio_sd8997
= {
536 .firmware
= SD8997_DEFAULT_FW_NAME
,
537 .reg
= &mwifiex_reg_sd8997
,
539 .mp_agg_pkt_limit
= 16,
540 .tx_buf_size
= MWIFIEX_TX_DATA_BUF_SIZE_4K
,
541 .mp_tx_agg_buf_size
= MWIFIEX_MP_AGGR_BUF_SIZE_MAX
,
542 .mp_rx_agg_buf_size
= MWIFIEX_MP_AGGR_BUF_SIZE_MAX
,
543 .supports_sdio_new_mode
= true,
544 .has_control_mask
= false,
547 .can_auto_tdls
= false,
548 .can_ext_scan
= true,
551 static const struct mwifiex_sdio_device mwifiex_sdio_sd8887
= {
552 .firmware
= SD8887_DEFAULT_FW_NAME
,
553 .reg
= &mwifiex_reg_sd8887
,
555 .mp_agg_pkt_limit
= 16,
556 .tx_buf_size
= MWIFIEX_TX_DATA_BUF_SIZE_2K
,
557 .mp_tx_agg_buf_size
= MWIFIEX_MP_AGGR_BUF_SIZE_32K
,
558 .mp_rx_agg_buf_size
= MWIFIEX_MP_AGGR_BUF_SIZE_32K
,
559 .supports_sdio_new_mode
= true,
560 .has_control_mask
= false,
561 .can_dump_fw
= false,
562 .can_auto_tdls
= true,
563 .can_ext_scan
= true,
566 static const struct mwifiex_sdio_device mwifiex_sdio_sd8801
= {
567 .firmware
= SD8801_DEFAULT_FW_NAME
,
568 .reg
= &mwifiex_reg_sd87xx
,
570 .mp_agg_pkt_limit
= 8,
571 .supports_sdio_new_mode
= false,
572 .has_control_mask
= true,
573 .tx_buf_size
= MWIFIEX_TX_DATA_BUF_SIZE_2K
,
574 .mp_tx_agg_buf_size
= MWIFIEX_MP_AGGR_BUF_SIZE_16K
,
575 .mp_rx_agg_buf_size
= MWIFIEX_MP_AGGR_BUF_SIZE_16K
,
576 .can_dump_fw
= false,
577 .can_auto_tdls
= false,
578 .can_ext_scan
= true,
582 * .cmdrsp_complete handler
584 static inline int mwifiex_sdio_cmdrsp_complete(struct mwifiex_adapter
*adapter
,
587 dev_kfree_skb_any(skb
);
592 * .event_complete handler
594 static inline int mwifiex_sdio_event_complete(struct mwifiex_adapter
*adapter
,
597 dev_kfree_skb_any(skb
);
602 mp_rx_aggr_port_limit_reached(struct sdio_mmc_card
*card
)
606 if (card
->curr_rd_port
< card
->mpa_rx
.start_port
) {
607 if (card
->supports_sdio_new_mode
)
608 tmp
= card
->mp_end_port
>> 1;
610 tmp
= card
->mp_agg_pkt_limit
;
612 if (((card
->max_ports
- card
->mpa_rx
.start_port
) +
613 card
->curr_rd_port
) >= tmp
)
617 if (!card
->supports_sdio_new_mode
)
620 if ((card
->curr_rd_port
- card
->mpa_rx
.start_port
) >=
621 (card
->mp_end_port
>> 1))
628 mp_tx_aggr_port_limit_reached(struct sdio_mmc_card
*card
)
632 if (card
->curr_wr_port
< card
->mpa_tx
.start_port
) {
633 if (card
->supports_sdio_new_mode
)
634 tmp
= card
->mp_end_port
>> 1;
636 tmp
= card
->mp_agg_pkt_limit
;
638 if (((card
->max_ports
- card
->mpa_tx
.start_port
) +
639 card
->curr_wr_port
) >= tmp
)
643 if (!card
->supports_sdio_new_mode
)
646 if ((card
->curr_wr_port
- card
->mpa_tx
.start_port
) >=
647 (card
->mp_end_port
>> 1))
653 /* Prepare to copy current packet from card to SDIO Rx aggregation buffer */
654 static inline void mp_rx_aggr_setup(struct sdio_mmc_card
*card
,
657 card
->mpa_rx
.buf_len
+= rx_len
;
659 if (!card
->mpa_rx
.pkt_cnt
)
660 card
->mpa_rx
.start_port
= port
;
662 if (card
->supports_sdio_new_mode
) {
663 card
->mpa_rx
.ports
|= (1 << port
);
665 if (card
->mpa_rx
.start_port
<= port
)
666 card
->mpa_rx
.ports
|= 1 << (card
->mpa_rx
.pkt_cnt
);
668 card
->mpa_rx
.ports
|= 1 << (card
->mpa_rx
.pkt_cnt
+ 1);
670 card
->mpa_rx
.skb_arr
[card
->mpa_rx
.pkt_cnt
] = NULL
;
671 card
->mpa_rx
.len_arr
[card
->mpa_rx
.pkt_cnt
] = rx_len
;
672 card
->mpa_rx
.pkt_cnt
++;
674 #endif /* _MWIFIEX_SDIO_H */