2 * NXP Wireless LAN device driver: SDIO specific definitions
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 #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 SD8977_DEFAULT_FW_NAME "mrvl/sdsd8977_combo_v2.bin"
40 #define SD8987_DEFAULT_FW_NAME "mrvl/sd8987_uapsta.bin"
41 #define SD8997_DEFAULT_FW_NAME "mrvl/sdsd8997_combo_v4.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
;
292 * .cmdrsp_complete handler
294 static inline int mwifiex_sdio_cmdrsp_complete(struct mwifiex_adapter
*adapter
,
297 dev_kfree_skb_any(skb
);
302 * .event_complete handler
304 static inline int mwifiex_sdio_event_complete(struct mwifiex_adapter
*adapter
,
307 dev_kfree_skb_any(skb
);
312 mp_rx_aggr_port_limit_reached(struct sdio_mmc_card
*card
)
316 if (card
->curr_rd_port
< card
->mpa_rx
.start_port
) {
317 if (card
->supports_sdio_new_mode
)
318 tmp
= card
->mp_end_port
>> 1;
320 tmp
= card
->mp_agg_pkt_limit
;
322 if (((card
->max_ports
- card
->mpa_rx
.start_port
) +
323 card
->curr_rd_port
) >= tmp
)
327 if (!card
->supports_sdio_new_mode
)
330 if ((card
->curr_rd_port
- card
->mpa_rx
.start_port
) >=
331 (card
->mp_end_port
>> 1))
338 mp_tx_aggr_port_limit_reached(struct sdio_mmc_card
*card
)
342 if (card
->curr_wr_port
< card
->mpa_tx
.start_port
) {
343 if (card
->supports_sdio_new_mode
)
344 tmp
= card
->mp_end_port
>> 1;
346 tmp
= card
->mp_agg_pkt_limit
;
348 if (((card
->max_ports
- card
->mpa_tx
.start_port
) +
349 card
->curr_wr_port
) >= tmp
)
353 if (!card
->supports_sdio_new_mode
)
356 if ((card
->curr_wr_port
- card
->mpa_tx
.start_port
) >=
357 (card
->mp_end_port
>> 1))
363 /* Prepare to copy current packet from card to SDIO Rx aggregation buffer */
364 static inline void mp_rx_aggr_setup(struct sdio_mmc_card
*card
,
367 card
->mpa_rx
.buf_len
+= rx_len
;
369 if (!card
->mpa_rx
.pkt_cnt
)
370 card
->mpa_rx
.start_port
= port
;
372 if (card
->supports_sdio_new_mode
) {
373 card
->mpa_rx
.ports
|= (1 << port
);
375 if (card
->mpa_rx
.start_port
<= port
)
376 card
->mpa_rx
.ports
|= 1 << (card
->mpa_rx
.pkt_cnt
);
378 card
->mpa_rx
.ports
|= 1 << (card
->mpa_rx
.pkt_cnt
+ 1);
380 card
->mpa_rx
.skb_arr
[card
->mpa_rx
.pkt_cnt
] = NULL
;
381 card
->mpa_rx
.len_arr
[card
->mpa_rx
.pkt_cnt
] = rx_len
;
382 card
->mpa_rx
.pkt_cnt
++;
384 #endif /* _MWIFIEX_SDIO_H */