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/mmc/sdio.h>
25 #include <linux/mmc/sdio_ids.h>
26 #include <linux/mmc/sdio_func.h>
27 #include <linux/mmc/card.h>
28 #include <linux/mmc/host.h>
32 #define SD8786_DEFAULT_FW_NAME "mrvl/sd8786_uapsta.bin"
33 #define SD8787_DEFAULT_FW_NAME "mrvl/sd8787_uapsta.bin"
34 #define SD8797_DEFAULT_FW_NAME "mrvl/sd8797_uapsta.bin"
35 #define SD8897_DEFAULT_FW_NAME "mrvl/sd8897_uapsta.bin"
36 #define SD8887_DEFAULT_FW_NAME "mrvl/sd8887_uapsta.bin"
43 #define MWIFIEX_SDIO_IO_PORT_MASK 0xfffff
45 #define MWIFIEX_SDIO_BYTE_MODE_MASK 0x80000000
47 #define SDIO_MPA_ADDR_BASE 0x1000
49 #define CTRL_PORT_MASK 0x0001
51 #define CMD_PORT_UPLD_INT_MASK (0x1U<<6)
52 #define CMD_PORT_DNLD_INT_MASK (0x1U<<7)
53 #define HOST_TERM_CMD53 (0x1U << 2)
55 #define MEM_PORT 0x10000
57 #define CMD53_NEW_MODE (0x1U << 0)
58 #define CMD_PORT_RD_LEN_EN (0x1U << 2)
59 #define CMD_PORT_AUTO_EN (0x1U << 0)
60 #define CMD_PORT_SLCT 0x8000
61 #define UP_LD_CMD_PORT_HOST_INT_STATUS (0x40U)
62 #define DN_LD_CMD_PORT_HOST_INT_STATUS (0x80U)
64 #define MWIFIEX_MP_AGGR_BUF_SIZE_16K (16384)
65 #define MWIFIEX_MP_AGGR_BUF_SIZE_32K (32768)
67 /* Misc. Config Register : Auto Re-enable interrupts */
68 #define AUTO_RE_ENABLE_INT BIT(4)
70 /* Host Control Registers : Configuration */
71 #define CONFIGURATION_REG 0x00
72 /* Host Control Registers : Host power up */
73 #define HOST_POWER_UP (0x1U << 1)
75 /* Host Control Registers : Upload host interrupt mask */
76 #define UP_LD_HOST_INT_MASK (0x1U)
77 /* Host Control Registers : Download host interrupt mask */
78 #define DN_LD_HOST_INT_MASK (0x2U)
80 /* Host Control Registers : Upload host interrupt status */
81 #define UP_LD_HOST_INT_STATUS (0x1U)
82 /* Host Control Registers : Download host interrupt status */
83 #define DN_LD_HOST_INT_STATUS (0x2U)
85 /* Host Control Registers : Host interrupt status */
86 #define CARD_INT_STATUS_REG 0x28
88 /* Card Control Registers : Card I/O ready */
89 #define CARD_IO_READY (0x1U << 3)
90 /* Card Control Registers : Download card ready */
91 #define DN_LD_CARD_RDY (0x1U << 0)
93 /* Max retry number of CMD53 write */
94 #define MAX_WRITE_IOMEM_RETRY 2
96 /* SDIO Tx aggregation in progress ? */
97 #define MP_TX_AGGR_IN_PROGRESS(a) (a->mpa_tx.pkt_cnt > 0)
99 /* SDIO Tx aggregation buffer room for next packet ? */
100 #define MP_TX_AGGR_BUF_HAS_ROOM(a, len) ((a->mpa_tx.buf_len+len) \
101 <= a->mpa_tx.buf_size)
103 /* Copy current packet (SDIO Tx aggregation buffer) to SDIO buffer */
104 #define MP_TX_AGGR_BUF_PUT(a, payload, pkt_len, port) do { \
105 memmove(&a->mpa_tx.buf[a->mpa_tx.buf_len], \
107 a->mpa_tx.buf_len += pkt_len; \
108 if (!a->mpa_tx.pkt_cnt) \
109 a->mpa_tx.start_port = port; \
110 if (a->mpa_tx.start_port <= port) \
111 a->mpa_tx.ports |= (1<<(a->mpa_tx.pkt_cnt)); \
113 a->mpa_tx.ports |= (1<<(a->mpa_tx.pkt_cnt+1+ \
116 a->mpa_tx.pkt_cnt++; \
119 /* SDIO Tx aggregation limit ? */
120 #define MP_TX_AGGR_PKT_LIMIT_REACHED(a) \
121 (a->mpa_tx.pkt_cnt == a->mpa_tx.pkt_aggr_limit)
123 /* Reset SDIO Tx aggregation buffer parameters */
124 #define MP_TX_AGGR_BUF_RESET(a) do { \
125 a->mpa_tx.pkt_cnt = 0; \
126 a->mpa_tx.buf_len = 0; \
127 a->mpa_tx.ports = 0; \
128 a->mpa_tx.start_port = 0; \
131 /* SDIO Rx aggregation limit ? */
132 #define MP_RX_AGGR_PKT_LIMIT_REACHED(a) \
133 (a->mpa_rx.pkt_cnt == a->mpa_rx.pkt_aggr_limit)
135 /* SDIO Rx aggregation in progress ? */
136 #define MP_RX_AGGR_IN_PROGRESS(a) (a->mpa_rx.pkt_cnt > 0)
138 /* SDIO Rx aggregation buffer room for next packet ? */
139 #define MP_RX_AGGR_BUF_HAS_ROOM(a, rx_len) \
140 ((a->mpa_rx.buf_len+rx_len) <= a->mpa_rx.buf_size)
142 /* Reset SDIO Rx aggregation buffer parameters */
143 #define MP_RX_AGGR_BUF_RESET(a) do { \
144 a->mpa_rx.pkt_cnt = 0; \
145 a->mpa_rx.buf_len = 0; \
146 a->mpa_rx.ports = 0; \
147 a->mpa_rx.start_port = 0; \
150 /* data structure for SDIO MPA TX */
151 struct mwifiex_sdio_mpa_tx
{
152 /* multiport tx aggregation buffer pointer */
163 struct mwifiex_sdio_mpa_rx
{
170 struct sk_buff
**skb_arr
;
178 int mwifiex_bus_register(void);
179 void mwifiex_bus_unregister(void);
181 struct mwifiex_sdio_card_reg
{
189 u8 host_int_status_reg
;
190 u8 host_int_mask_reg
;
209 u8 card_misc_cfg_reg
;
224 struct sdio_mmc_card
{
225 struct sdio_func
*func
;
226 struct mwifiex_adapter
*adapter
;
228 const char *firmware
;
229 const struct mwifiex_sdio_card_reg
*reg
;
232 bool supports_sdio_new_mode
;
233 bool has_control_mask
;
234 bool supports_fw_dump
;
236 u32 mp_tx_agg_buf_size
;
237 u32 mp_rx_agg_buf_size
;
243 u32 mp_data_port_mask
;
251 struct mwifiex_sdio_mpa_tx mpa_tx
;
252 struct mwifiex_sdio_mpa_rx mpa_rx
;
255 struct mwifiex_sdio_device
{
256 const char *firmware
;
257 const struct mwifiex_sdio_card_reg
*reg
;
260 bool supports_sdio_new_mode
;
261 bool has_control_mask
;
262 bool supports_fw_dump
;
264 u32 mp_tx_agg_buf_size
;
265 u32 mp_rx_agg_buf_size
;
269 static const struct mwifiex_sdio_card_reg mwifiex_reg_sd87xx
= {
272 .base_0_reg
= 0x0040,
273 .base_1_reg
= 0x0041,
275 .host_int_enable
= UP_LD_HOST_INT_MASK
| DN_LD_HOST_INT_MASK
,
276 .host_int_rsr_reg
= 0x1,
277 .host_int_mask_reg
= 0x02,
278 .host_int_status_reg
= 0x03,
279 .status_reg_0
= 0x60,
280 .status_reg_1
= 0x61,
281 .sdio_int_mask
= 0x3f,
282 .data_port_mask
= 0x0000fffe,
283 .io_port_0_reg
= 0x78,
284 .io_port_1_reg
= 0x79,
285 .io_port_2_reg
= 0x7A,
293 .card_misc_cfg_reg
= 0x6c,
296 static const struct mwifiex_sdio_card_reg mwifiex_reg_sd8897
= {
302 .host_int_enable
= UP_LD_HOST_INT_MASK
| DN_LD_HOST_INT_MASK
|
303 CMD_PORT_UPLD_INT_MASK
| CMD_PORT_DNLD_INT_MASK
,
304 .host_int_rsr_reg
= 0x1,
305 .host_int_status_reg
= 0x03,
306 .host_int_mask_reg
= 0x02,
307 .status_reg_0
= 0xc0,
308 .status_reg_1
= 0xc1,
309 .sdio_int_mask
= 0xff,
310 .data_port_mask
= 0xffffffff,
311 .io_port_0_reg
= 0xD8,
312 .io_port_1_reg
= 0xD9,
313 .io_port_2_reg
= 0xDA,
317 .rd_bitmap_1l
= 0x06,
318 .rd_bitmap_1u
= 0x07,
321 .wr_bitmap_1l
= 0x0a,
322 .wr_bitmap_1u
= 0x0b,
325 .card_misc_cfg_reg
= 0xcc,
326 .card_cfg_2_1_reg
= 0xcd,
327 .cmd_rd_len_0
= 0xb4,
328 .cmd_rd_len_1
= 0xb5,
329 .cmd_rd_len_2
= 0xb6,
330 .cmd_rd_len_3
= 0xb7,
335 .fw_dump_ctrl
= 0xe2,
336 .fw_dump_start
= 0xe3,
340 static const struct mwifiex_sdio_card_reg mwifiex_reg_sd8887
= {
346 .host_int_enable
= UP_LD_HOST_INT_MASK
| DN_LD_HOST_INT_MASK
|
347 CMD_PORT_UPLD_INT_MASK
| CMD_PORT_DNLD_INT_MASK
,
348 .host_int_rsr_reg
= 0x4,
349 .host_int_status_reg
= 0x0C,
350 .host_int_mask_reg
= 0x08,
351 .status_reg_0
= 0x90,
352 .status_reg_1
= 0x91,
353 .sdio_int_mask
= 0xff,
354 .data_port_mask
= 0xffffffff,
355 .io_port_0_reg
= 0xE4,
356 .io_port_1_reg
= 0xE5,
357 .io_port_2_reg
= 0xE6,
361 .rd_bitmap_1l
= 0x12,
362 .rd_bitmap_1u
= 0x13,
365 .wr_bitmap_1l
= 0x16,
366 .wr_bitmap_1u
= 0x17,
369 .card_misc_cfg_reg
= 0xd8,
370 .card_cfg_2_1_reg
= 0xd9,
371 .cmd_rd_len_0
= 0xc0,
372 .cmd_rd_len_1
= 0xc1,
373 .cmd_rd_len_2
= 0xc2,
374 .cmd_rd_len_3
= 0xc3,
381 static const struct mwifiex_sdio_device mwifiex_sdio_sd8786
= {
382 .firmware
= SD8786_DEFAULT_FW_NAME
,
383 .reg
= &mwifiex_reg_sd87xx
,
385 .mp_agg_pkt_limit
= 8,
386 .supports_sdio_new_mode
= false,
387 .has_control_mask
= true,
388 .tx_buf_size
= MWIFIEX_TX_DATA_BUF_SIZE_2K
,
389 .mp_tx_agg_buf_size
= MWIFIEX_MP_AGGR_BUF_SIZE_16K
,
390 .mp_rx_agg_buf_size
= MWIFIEX_MP_AGGR_BUF_SIZE_16K
,
391 .supports_fw_dump
= false,
395 static const struct mwifiex_sdio_device mwifiex_sdio_sd8787
= {
396 .firmware
= SD8787_DEFAULT_FW_NAME
,
397 .reg
= &mwifiex_reg_sd87xx
,
399 .mp_agg_pkt_limit
= 8,
400 .supports_sdio_new_mode
= false,
401 .has_control_mask
= true,
402 .tx_buf_size
= MWIFIEX_TX_DATA_BUF_SIZE_2K
,
403 .mp_tx_agg_buf_size
= MWIFIEX_MP_AGGR_BUF_SIZE_16K
,
404 .mp_rx_agg_buf_size
= MWIFIEX_MP_AGGR_BUF_SIZE_16K
,
405 .supports_fw_dump
= false,
409 static const struct mwifiex_sdio_device mwifiex_sdio_sd8797
= {
410 .firmware
= SD8797_DEFAULT_FW_NAME
,
411 .reg
= &mwifiex_reg_sd87xx
,
413 .mp_agg_pkt_limit
= 8,
414 .supports_sdio_new_mode
= false,
415 .has_control_mask
= true,
416 .tx_buf_size
= MWIFIEX_TX_DATA_BUF_SIZE_2K
,
417 .mp_tx_agg_buf_size
= MWIFIEX_MP_AGGR_BUF_SIZE_16K
,
418 .mp_rx_agg_buf_size
= MWIFIEX_MP_AGGR_BUF_SIZE_16K
,
419 .supports_fw_dump
= false,
423 static const struct mwifiex_sdio_device mwifiex_sdio_sd8897
= {
424 .firmware
= SD8897_DEFAULT_FW_NAME
,
425 .reg
= &mwifiex_reg_sd8897
,
427 .mp_agg_pkt_limit
= 16,
428 .supports_sdio_new_mode
= true,
429 .has_control_mask
= false,
430 .tx_buf_size
= MWIFIEX_TX_DATA_BUF_SIZE_4K
,
431 .mp_tx_agg_buf_size
= MWIFIEX_MP_AGGR_BUF_SIZE_32K
,
432 .mp_rx_agg_buf_size
= MWIFIEX_MP_AGGR_BUF_SIZE_32K
,
433 .supports_fw_dump
= true,
437 static const struct mwifiex_sdio_device mwifiex_sdio_sd8887
= {
438 .firmware
= SD8887_DEFAULT_FW_NAME
,
439 .reg
= &mwifiex_reg_sd8887
,
441 .mp_agg_pkt_limit
= 16,
442 .supports_sdio_new_mode
= true,
443 .has_control_mask
= false,
444 .tx_buf_size
= MWIFIEX_TX_DATA_BUF_SIZE_4K
,
445 .mp_tx_agg_buf_size
= MWIFIEX_MP_AGGR_BUF_SIZE_32K
,
446 .mp_rx_agg_buf_size
= MWIFIEX_MP_AGGR_BUF_SIZE_32K
,
447 .supports_fw_dump
= false,
452 * .cmdrsp_complete handler
454 static inline int mwifiex_sdio_cmdrsp_complete(struct mwifiex_adapter
*adapter
,
457 dev_kfree_skb_any(skb
);
462 * .event_complete handler
464 static inline int mwifiex_sdio_event_complete(struct mwifiex_adapter
*adapter
,
467 dev_kfree_skb_any(skb
);
472 mp_rx_aggr_port_limit_reached(struct sdio_mmc_card
*card
)
476 if (card
->curr_rd_port
< card
->mpa_rx
.start_port
) {
477 if (card
->supports_sdio_new_mode
)
478 tmp
= card
->mp_end_port
>> 1;
480 tmp
= card
->mp_agg_pkt_limit
;
482 if (((card
->max_ports
- card
->mpa_rx
.start_port
) +
483 card
->curr_rd_port
) >= tmp
)
487 if (!card
->supports_sdio_new_mode
)
490 if ((card
->curr_rd_port
- card
->mpa_rx
.start_port
) >=
491 (card
->mp_end_port
>> 1))
498 mp_tx_aggr_port_limit_reached(struct sdio_mmc_card
*card
)
502 if (card
->curr_wr_port
< card
->mpa_tx
.start_port
) {
503 if (card
->supports_sdio_new_mode
)
504 tmp
= card
->mp_end_port
>> 1;
506 tmp
= card
->mp_agg_pkt_limit
;
508 if (((card
->max_ports
- card
->mpa_tx
.start_port
) +
509 card
->curr_wr_port
) >= tmp
)
513 if (!card
->supports_sdio_new_mode
)
516 if ((card
->curr_wr_port
- card
->mpa_tx
.start_port
) >=
517 (card
->mp_end_port
>> 1))
523 /* Prepare to copy current packet from card to SDIO Rx aggregation buffer */
524 static inline void mp_rx_aggr_setup(struct sdio_mmc_card
*card
,
525 struct sk_buff
*skb
, u8 port
)
527 card
->mpa_rx
.buf_len
+= skb
->len
;
529 if (!card
->mpa_rx
.pkt_cnt
)
530 card
->mpa_rx
.start_port
= port
;
532 if (card
->supports_sdio_new_mode
) {
533 card
->mpa_rx
.ports
|= (1 << port
);
535 if (card
->mpa_rx
.start_port
<= port
)
536 card
->mpa_rx
.ports
|= 1 << (card
->mpa_rx
.pkt_cnt
);
538 card
->mpa_rx
.ports
|= 1 << (card
->mpa_rx
.pkt_cnt
+ 1);
540 card
->mpa_rx
.skb_arr
[card
->mpa_rx
.pkt_cnt
] = skb
;
541 card
->mpa_rx
.len_arr
[card
->mpa_rx
.pkt_cnt
] = skb
->len
;
542 card
->mpa_rx
.pkt_cnt
++;
544 #endif /* _MWIFIEX_SDIO_H */