blob: 339608ba61711a0f4ab7aeedf7359596d1749144 [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
2 * Marvell Wireless LAN device driver: SDIO specific definitions
3 *
4 * Copyright (C) 2011, Marvell International Ltd.
5 *
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.
13 *
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.
18 */
19
20#ifndef _MWIFIEX_SDIO_H
21#define _MWIFIEX_SDIO_H
22
23
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>
Amitkumar Karward31ab352012-11-01 18:44:14 -070028#include <linux/mmc/host.h>
Bing Zhao5e6e3a92011-03-21 18:00:50 -070029
30#include "main.h"
31
WarheadsSE98e6b9d2012-04-24 15:57:21 -040032#define SD8786_DEFAULT_FW_NAME "mrvl/sd8786_uapsta.bin"
Amitkumar Karwar4a7f5db2011-05-23 18:00:17 -070033#define SD8787_DEFAULT_FW_NAME "mrvl/sd8787_uapsta.bin"
Bing Zhaoe3bea1c2011-11-16 20:40:35 -080034#define SD8797_DEFAULT_FW_NAME "mrvl/sd8797_uapsta.bin"
Amitkumar Karwar4a7f5db2011-05-23 18:00:17 -070035
Bing Zhao5e6e3a92011-03-21 18:00:50 -070036#define BLOCK_MODE 1
37#define BYTE_MODE 0
38
39#define REG_PORT 0
Bing Zhao5e6e3a92011-03-21 18:00:50 -070040
41#define MWIFIEX_SDIO_IO_PORT_MASK 0xfffff
42
43#define MWIFIEX_SDIO_BYTE_MODE_MASK 0x80000000
44
Amitkumar Karwar248eb4c2013-05-17 17:54:34 -070045#define SDIO_MPA_ADDR_BASE 0x1000
Bing Zhao5e6e3a92011-03-21 18:00:50 -070046#define CTRL_PORT 0
47#define CTRL_PORT_MASK 0x0001
Bing Zhao5e6e3a92011-03-21 18:00:50 -070048
Amitkumar Karwar05889f82013-05-17 17:50:27 -070049#define SDIO_MP_AGGR_DEF_PKT_LIMIT 8
Bing Zhao5e6e3a92011-03-21 18:00:50 -070050
Amitkumar Karwarf0c717e2011-07-05 18:01:11 -070051#define SDIO_MP_TX_AGGR_DEF_BUF_SIZE (8192) /* 8K */
Bing Zhao5e6e3a92011-03-21 18:00:50 -070052
53/* Multi port RX aggregation buffer size */
Amitkumar Karwarf0c717e2011-07-05 18:01:11 -070054#define SDIO_MP_RX_AGGR_DEF_BUF_SIZE (16384) /* 16K */
Bing Zhao5e6e3a92011-03-21 18:00:50 -070055
56/* Misc. Config Register : Auto Re-enable interrupts */
57#define AUTO_RE_ENABLE_INT BIT(4)
58
59/* Host Control Registers */
60/* Host Control Registers : I/O port 0 */
61#define IO_PORT_0_REG 0x78
62/* Host Control Registers : I/O port 1 */
63#define IO_PORT_1_REG 0x79
64/* Host Control Registers : I/O port 2 */
65#define IO_PORT_2_REG 0x7A
66
67/* Host Control Registers : Configuration */
68#define CONFIGURATION_REG 0x00
Bing Zhao5e6e3a92011-03-21 18:00:50 -070069/* Host Control Registers : Host power up */
70#define HOST_POWER_UP (0x1U << 1)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070071
72/* Host Control Registers : Host interrupt mask */
73#define HOST_INT_MASK_REG 0x02
74/* Host Control Registers : Upload host interrupt mask */
75#define UP_LD_HOST_INT_MASK (0x1U)
76/* Host Control Registers : Download host interrupt mask */
77#define DN_LD_HOST_INT_MASK (0x2U)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070078/* Disable Host interrupt mask */
79#define HOST_INT_DISABLE 0xff
80
81/* Host Control Registers : Host interrupt status */
82#define HOST_INTSTATUS_REG 0x03
83/* Host Control Registers : Upload host interrupt status */
84#define UP_LD_HOST_INT_STATUS (0x1U)
85/* Host Control Registers : Download host interrupt status */
86#define DN_LD_HOST_INT_STATUS (0x2U)
87
88/* Host Control Registers : Host interrupt RSR */
89#define HOST_INT_RSR_REG 0x01
Bing Zhao5e6e3a92011-03-21 18:00:50 -070090
91/* Host Control Registers : Host interrupt status */
92#define HOST_INT_STATUS_REG 0x28
Bing Zhao5e6e3a92011-03-21 18:00:50 -070093
Bing Zhao5e6e3a92011-03-21 18:00:50 -070094/* Card Control Registers : Card I/O ready */
95#define CARD_IO_READY (0x1U << 3)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070096/* Card Control Registers : Download card ready */
97#define DN_LD_CARD_RDY (0x1U << 0)
98
Bing Zhao5e6e3a92011-03-21 18:00:50 -070099/* Max retry number of CMD53 write */
100#define MAX_WRITE_IOMEM_RETRY 2
101
102/* SDIO Tx aggregation in progress ? */
103#define MP_TX_AGGR_IN_PROGRESS(a) (a->mpa_tx.pkt_cnt > 0)
104
105/* SDIO Tx aggregation buffer room for next packet ? */
106#define MP_TX_AGGR_BUF_HAS_ROOM(a, len) ((a->mpa_tx.buf_len+len) \
107 <= a->mpa_tx.buf_size)
108
109/* Copy current packet (SDIO Tx aggregation buffer) to SDIO buffer */
110#define MP_TX_AGGR_BUF_PUT(a, payload, pkt_len, port) do { \
111 memmove(&a->mpa_tx.buf[a->mpa_tx.buf_len], \
112 payload, pkt_len); \
113 a->mpa_tx.buf_len += pkt_len; \
114 if (!a->mpa_tx.pkt_cnt) \
115 a->mpa_tx.start_port = port; \
116 if (a->mpa_tx.start_port <= port) \
117 a->mpa_tx.ports |= (1<<(a->mpa_tx.pkt_cnt)); \
118 else \
Amitkumar Karwar05889f82013-05-17 17:50:27 -0700119 a->mpa_tx.ports |= (1<<(a->mpa_tx.pkt_cnt+1+ \
120 (a->max_ports - \
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700121 a->mp_end_port))); \
122 a->mpa_tx.pkt_cnt++; \
Joe Perchesda951c22012-04-03 14:46:49 -0700123} while (0)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700124
125/* SDIO Tx aggregation limit ? */
126#define MP_TX_AGGR_PKT_LIMIT_REACHED(a) \
127 (a->mpa_tx.pkt_cnt == a->mpa_tx.pkt_aggr_limit)
128
129/* SDIO Tx aggregation port limit ? */
130#define MP_TX_AGGR_PORT_LIMIT_REACHED(a) ((a->curr_wr_port < \
Amitkumar Karwar05889f82013-05-17 17:50:27 -0700131 a->mpa_tx.start_port) && (((a->max_ports -\
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700132 a->mpa_tx.start_port) + a->curr_wr_port) >= \
Amitkumar Karwar05889f82013-05-17 17:50:27 -0700133 a->mp_agg_pkt_limit))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700134
135/* Reset SDIO Tx aggregation buffer parameters */
136#define MP_TX_AGGR_BUF_RESET(a) do { \
137 a->mpa_tx.pkt_cnt = 0; \
138 a->mpa_tx.buf_len = 0; \
139 a->mpa_tx.ports = 0; \
140 a->mpa_tx.start_port = 0; \
Joe Perchesda951c22012-04-03 14:46:49 -0700141} while (0)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700142
143/* SDIO Rx aggregation limit ? */
144#define MP_RX_AGGR_PKT_LIMIT_REACHED(a) \
145 (a->mpa_rx.pkt_cnt == a->mpa_rx.pkt_aggr_limit)
146
147/* SDIO Tx aggregation port limit ? */
148#define MP_RX_AGGR_PORT_LIMIT_REACHED(a) ((a->curr_rd_port < \
Amitkumar Karwar05889f82013-05-17 17:50:27 -0700149 a->mpa_rx.start_port) && (((a->max_ports -\
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700150 a->mpa_rx.start_port) + a->curr_rd_port) >= \
Amitkumar Karwar05889f82013-05-17 17:50:27 -0700151 a->mp_agg_pkt_limit))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700152
153/* SDIO Rx aggregation in progress ? */
154#define MP_RX_AGGR_IN_PROGRESS(a) (a->mpa_rx.pkt_cnt > 0)
155
156/* SDIO Rx aggregation buffer room for next packet ? */
157#define MP_RX_AGGR_BUF_HAS_ROOM(a, rx_len) \
158 ((a->mpa_rx.buf_len+rx_len) <= a->mpa_rx.buf_size)
159
160/* Prepare to copy current packet from card to SDIO Rx aggregation buffer */
161#define MP_RX_AGGR_SETUP(a, skb, port) do { \
162 a->mpa_rx.buf_len += skb->len; \
163 if (!a->mpa_rx.pkt_cnt) \
164 a->mpa_rx.start_port = port; \
165 if (a->mpa_rx.start_port <= port) \
166 a->mpa_rx.ports |= (1<<(a->mpa_rx.pkt_cnt)); \
167 else \
168 a->mpa_rx.ports |= (1<<(a->mpa_rx.pkt_cnt+1)); \
169 a->mpa_rx.skb_arr[a->mpa_rx.pkt_cnt] = skb; \
170 a->mpa_rx.len_arr[a->mpa_rx.pkt_cnt] = skb->len; \
171 a->mpa_rx.pkt_cnt++; \
Joe Perchesda951c22012-04-03 14:46:49 -0700172} while (0)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700173
174/* Reset SDIO Rx aggregation buffer parameters */
175#define MP_RX_AGGR_BUF_RESET(a) do { \
176 a->mpa_rx.pkt_cnt = 0; \
177 a->mpa_rx.buf_len = 0; \
178 a->mpa_rx.ports = 0; \
179 a->mpa_rx.start_port = 0; \
Joe Perchesda951c22012-04-03 14:46:49 -0700180} while (0)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700181
182
183/* data structure for SDIO MPA TX */
184struct mwifiex_sdio_mpa_tx {
185 /* multiport tx aggregation buffer pointer */
186 u8 *buf;
187 u32 buf_len;
188 u32 pkt_cnt;
Amitkumar Karwar5ac253d2013-05-17 17:50:26 -0700189 u32 ports;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700190 u16 start_port;
191 u8 enabled;
192 u32 buf_size;
193 u32 pkt_aggr_limit;
194};
195
196struct mwifiex_sdio_mpa_rx {
197 u8 *buf;
198 u32 buf_len;
199 u32 pkt_cnt;
Amitkumar Karwar5ac253d2013-05-17 17:50:26 -0700200 u32 ports;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700201 u16 start_port;
202
203 struct sk_buff *skb_arr[SDIO_MP_AGGR_DEF_PKT_LIMIT];
204 u32 len_arr[SDIO_MP_AGGR_DEF_PKT_LIMIT];
205
206 u8 enabled;
207 u32 buf_size;
208 u32 pkt_aggr_limit;
209};
210
211int mwifiex_bus_register(void);
212void mwifiex_bus_unregister(void);
213
Amitkumar Karwar05889f82013-05-17 17:50:27 -0700214struct mwifiex_sdio_card_reg {
215 u8 start_rd_port;
216 u8 start_wr_port;
217 u8 base_0_reg;
218 u8 base_1_reg;
219 u8 poll_reg;
220 u8 host_int_enable;
221 u8 status_reg_0;
222 u8 status_reg_1;
223 u8 sdio_int_mask;
224 u32 data_port_mask;
225 u8 max_mp_regs;
226 u8 rd_bitmap_l;
227 u8 rd_bitmap_u;
228 u8 wr_bitmap_l;
229 u8 wr_bitmap_u;
230 u8 rd_len_p0_l;
231 u8 rd_len_p0_u;
232 u8 card_misc_cfg_reg;
233};
234
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700235struct sdio_mmc_card {
236 struct sdio_func *func;
237 struct mwifiex_adapter *adapter;
238
Amitkumar Karwar05889f82013-05-17 17:50:27 -0700239 const char *firmware;
240 const struct mwifiex_sdio_card_reg *reg;
241 u8 max_ports;
242 u8 mp_agg_pkt_limit;
243
Amitkumar Karwar5ac253d2013-05-17 17:50:26 -0700244 u32 mp_rd_bitmap;
245 u32 mp_wr_bitmap;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700246
247 u16 mp_end_port;
Amitkumar Karwar5ac253d2013-05-17 17:50:26 -0700248 u32 mp_data_port_mask;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700249
250 u8 curr_rd_port;
251 u8 curr_wr_port;
252
253 u8 *mp_regs;
254
255 struct mwifiex_sdio_mpa_tx mpa_tx;
256 struct mwifiex_sdio_mpa_rx mpa_rx;
257};
Amitkumar Karward930fae2011-10-11 17:41:21 -0700258
Amitkumar Karwar05889f82013-05-17 17:50:27 -0700259struct mwifiex_sdio_device {
260 const char *firmware;
261 const struct mwifiex_sdio_card_reg *reg;
262 u8 max_ports;
263 u8 mp_agg_pkt_limit;
264};
265
266static const struct mwifiex_sdio_card_reg mwifiex_reg_sd87xx = {
267 .start_rd_port = 1,
268 .start_wr_port = 1,
269 .base_0_reg = 0x0040,
270 .base_1_reg = 0x0041,
271 .poll_reg = 0x30,
272 .host_int_enable = UP_LD_HOST_INT_MASK | DN_LD_HOST_INT_MASK,
273 .status_reg_0 = 0x60,
274 .status_reg_1 = 0x61,
275 .sdio_int_mask = 0x3f,
276 .data_port_mask = 0x0000fffe,
277 .max_mp_regs = 64,
278 .rd_bitmap_l = 0x04,
279 .rd_bitmap_u = 0x05,
280 .wr_bitmap_l = 0x06,
281 .wr_bitmap_u = 0x07,
282 .rd_len_p0_l = 0x08,
283 .rd_len_p0_u = 0x09,
284 .card_misc_cfg_reg = 0x6c,
285};
286
287static const struct mwifiex_sdio_device mwifiex_sdio_sd8786 = {
288 .firmware = SD8786_DEFAULT_FW_NAME,
289 .reg = &mwifiex_reg_sd87xx,
290 .max_ports = 16,
291 .mp_agg_pkt_limit = 8,
292};
293
294static const struct mwifiex_sdio_device mwifiex_sdio_sd8787 = {
295 .firmware = SD8787_DEFAULT_FW_NAME,
296 .reg = &mwifiex_reg_sd87xx,
297 .max_ports = 16,
298 .mp_agg_pkt_limit = 8,
299};
300
301static const struct mwifiex_sdio_device mwifiex_sdio_sd8797 = {
302 .firmware = SD8797_DEFAULT_FW_NAME,
303 .reg = &mwifiex_reg_sd87xx,
304 .max_ports = 16,
305 .mp_agg_pkt_limit = 8,
306};
307
Amitkumar Karward930fae2011-10-11 17:41:21 -0700308/*
309 * .cmdrsp_complete handler
310 */
311static inline int mwifiex_sdio_cmdrsp_complete(struct mwifiex_adapter *adapter,
312 struct sk_buff *skb)
313{
314 dev_kfree_skb_any(skb);
315 return 0;
316}
317
318/*
319 * .event_complete handler
320 */
321static inline int mwifiex_sdio_event_complete(struct mwifiex_adapter *adapter,
322 struct sk_buff *skb)
323{
324 dev_kfree_skb_any(skb);
325 return 0;
326}
327
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700328#endif /* _MWIFIEX_SDIO_H */