blob: e4016d2692d4fe838c20954d0b9a1882de67d938 [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
69/* Host Control Registers : Host without Command 53 finish host*/
70#define HOST_TO_CARD_EVENT (0x1U << 3)
71/* Host Control Registers : Host without Command 53 finish host */
72#define HOST_WO_CMD53_FINISH_HOST (0x1U << 2)
73/* Host Control Registers : Host power up */
74#define HOST_POWER_UP (0x1U << 1)
75/* Host Control Registers : Host power down */
76#define HOST_POWER_DOWN (0x1U << 0)
77
78/* Host Control Registers : Host interrupt mask */
79#define HOST_INT_MASK_REG 0x02
80/* Host Control Registers : Upload host interrupt mask */
81#define UP_LD_HOST_INT_MASK (0x1U)
82/* Host Control Registers : Download host interrupt mask */
83#define DN_LD_HOST_INT_MASK (0x2U)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070084/* Disable Host interrupt mask */
85#define HOST_INT_DISABLE 0xff
86
87/* Host Control Registers : Host interrupt status */
88#define HOST_INTSTATUS_REG 0x03
89/* Host Control Registers : Upload host interrupt status */
90#define UP_LD_HOST_INT_STATUS (0x1U)
91/* Host Control Registers : Download host interrupt status */
92#define DN_LD_HOST_INT_STATUS (0x2U)
93
94/* Host Control Registers : Host interrupt RSR */
95#define HOST_INT_RSR_REG 0x01
96/* Host Control Registers : Upload host interrupt RSR */
97#define UP_LD_HOST_INT_RSR (0x1U)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070098
99/* Host Control Registers : Host interrupt status */
100#define HOST_INT_STATUS_REG 0x28
101/* Host Control Registers : Upload CRC error */
102#define UP_LD_CRC_ERR (0x1U << 2)
103/* Host Control Registers : Upload restart */
104#define UP_LD_RESTART (0x1U << 1)
105/* Host Control Registers : Download restart */
106#define DN_LD_RESTART (0x1U << 0)
107
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700108/* Card Control Registers : Card I/O ready */
109#define CARD_IO_READY (0x1U << 3)
110/* Card Control Registers : CIS card ready */
111#define CIS_CARD_RDY (0x1U << 2)
112/* Card Control Registers : Upload card ready */
113#define UP_LD_CARD_RDY (0x1U << 1)
114/* Card Control Registers : Download card ready */
115#define DN_LD_CARD_RDY (0x1U << 0)
116
117/* Card Control Registers : Host interrupt mask register */
118#define HOST_INTERRUPT_MASK_REG 0x34
119/* Card Control Registers : Host power interrupt mask */
120#define HOST_POWER_INT_MASK (0x1U << 3)
121/* Card Control Registers : Abort card interrupt mask */
122#define ABORT_CARD_INT_MASK (0x1U << 2)
123/* Card Control Registers : Upload card interrupt mask */
124#define UP_LD_CARD_INT_MASK (0x1U << 1)
125/* Card Control Registers : Download card interrupt mask */
126#define DN_LD_CARD_INT_MASK (0x1U << 0)
127
128/* Card Control Registers : Card interrupt status register */
129#define CARD_INTERRUPT_STATUS_REG 0x38
130/* Card Control Registers : Power up interrupt */
131#define POWER_UP_INT (0x1U << 4)
132/* Card Control Registers : Power down interrupt */
133#define POWER_DOWN_INT (0x1U << 3)
134
135/* Card Control Registers : Card interrupt RSR register */
136#define CARD_INTERRUPT_RSR_REG 0x3c
137/* Card Control Registers : Power up RSR */
138#define POWER_UP_RSR (0x1U << 4)
139/* Card Control Registers : Power down RSR */
140#define POWER_DOWN_RSR (0x1U << 3)
141
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700142/* Host F1 card ready */
143#define HOST_F1_CARD_RDY 0x0020
144
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700145/* Rx length register */
146#define CARD_RX_LEN_REG 0x62
147/* Rx unit register */
148#define CARD_RX_UNIT_REG 0x63
149
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700150/* Max retry number of CMD53 write */
151#define MAX_WRITE_IOMEM_RETRY 2
152
153/* SDIO Tx aggregation in progress ? */
154#define MP_TX_AGGR_IN_PROGRESS(a) (a->mpa_tx.pkt_cnt > 0)
155
156/* SDIO Tx aggregation buffer room for next packet ? */
157#define MP_TX_AGGR_BUF_HAS_ROOM(a, len) ((a->mpa_tx.buf_len+len) \
158 <= a->mpa_tx.buf_size)
159
160/* Copy current packet (SDIO Tx aggregation buffer) to SDIO buffer */
161#define MP_TX_AGGR_BUF_PUT(a, payload, pkt_len, port) do { \
162 memmove(&a->mpa_tx.buf[a->mpa_tx.buf_len], \
163 payload, pkt_len); \
164 a->mpa_tx.buf_len += pkt_len; \
165 if (!a->mpa_tx.pkt_cnt) \
166 a->mpa_tx.start_port = port; \
167 if (a->mpa_tx.start_port <= port) \
168 a->mpa_tx.ports |= (1<<(a->mpa_tx.pkt_cnt)); \
169 else \
Amitkumar Karwar05889f82013-05-17 17:50:27 -0700170 a->mpa_tx.ports |= (1<<(a->mpa_tx.pkt_cnt+1+ \
171 (a->max_ports - \
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700172 a->mp_end_port))); \
173 a->mpa_tx.pkt_cnt++; \
Joe Perchesda951c22012-04-03 14:46:49 -0700174} while (0)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700175
176/* SDIO Tx aggregation limit ? */
177#define MP_TX_AGGR_PKT_LIMIT_REACHED(a) \
178 (a->mpa_tx.pkt_cnt == a->mpa_tx.pkt_aggr_limit)
179
180/* SDIO Tx aggregation port limit ? */
181#define MP_TX_AGGR_PORT_LIMIT_REACHED(a) ((a->curr_wr_port < \
Amitkumar Karwar05889f82013-05-17 17:50:27 -0700182 a->mpa_tx.start_port) && (((a->max_ports -\
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700183 a->mpa_tx.start_port) + a->curr_wr_port) >= \
Amitkumar Karwar05889f82013-05-17 17:50:27 -0700184 a->mp_agg_pkt_limit))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700185
186/* Reset SDIO Tx aggregation buffer parameters */
187#define MP_TX_AGGR_BUF_RESET(a) do { \
188 a->mpa_tx.pkt_cnt = 0; \
189 a->mpa_tx.buf_len = 0; \
190 a->mpa_tx.ports = 0; \
191 a->mpa_tx.start_port = 0; \
Joe Perchesda951c22012-04-03 14:46:49 -0700192} while (0)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700193
194/* SDIO Rx aggregation limit ? */
195#define MP_RX_AGGR_PKT_LIMIT_REACHED(a) \
196 (a->mpa_rx.pkt_cnt == a->mpa_rx.pkt_aggr_limit)
197
198/* SDIO Tx aggregation port limit ? */
199#define MP_RX_AGGR_PORT_LIMIT_REACHED(a) ((a->curr_rd_port < \
Amitkumar Karwar05889f82013-05-17 17:50:27 -0700200 a->mpa_rx.start_port) && (((a->max_ports -\
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700201 a->mpa_rx.start_port) + a->curr_rd_port) >= \
Amitkumar Karwar05889f82013-05-17 17:50:27 -0700202 a->mp_agg_pkt_limit))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700203
204/* SDIO Rx aggregation in progress ? */
205#define MP_RX_AGGR_IN_PROGRESS(a) (a->mpa_rx.pkt_cnt > 0)
206
207/* SDIO Rx aggregation buffer room for next packet ? */
208#define MP_RX_AGGR_BUF_HAS_ROOM(a, rx_len) \
209 ((a->mpa_rx.buf_len+rx_len) <= a->mpa_rx.buf_size)
210
211/* Prepare to copy current packet from card to SDIO Rx aggregation buffer */
212#define MP_RX_AGGR_SETUP(a, skb, port) do { \
213 a->mpa_rx.buf_len += skb->len; \
214 if (!a->mpa_rx.pkt_cnt) \
215 a->mpa_rx.start_port = port; \
216 if (a->mpa_rx.start_port <= port) \
217 a->mpa_rx.ports |= (1<<(a->mpa_rx.pkt_cnt)); \
218 else \
219 a->mpa_rx.ports |= (1<<(a->mpa_rx.pkt_cnt+1)); \
220 a->mpa_rx.skb_arr[a->mpa_rx.pkt_cnt] = skb; \
221 a->mpa_rx.len_arr[a->mpa_rx.pkt_cnt] = skb->len; \
222 a->mpa_rx.pkt_cnt++; \
Joe Perchesda951c22012-04-03 14:46:49 -0700223} while (0)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700224
225/* Reset SDIO Rx aggregation buffer parameters */
226#define MP_RX_AGGR_BUF_RESET(a) do { \
227 a->mpa_rx.pkt_cnt = 0; \
228 a->mpa_rx.buf_len = 0; \
229 a->mpa_rx.ports = 0; \
230 a->mpa_rx.start_port = 0; \
Joe Perchesda951c22012-04-03 14:46:49 -0700231} while (0)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700232
233
234/* data structure for SDIO MPA TX */
235struct mwifiex_sdio_mpa_tx {
236 /* multiport tx aggregation buffer pointer */
237 u8 *buf;
238 u32 buf_len;
239 u32 pkt_cnt;
Amitkumar Karwar5ac253d2013-05-17 17:50:26 -0700240 u32 ports;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700241 u16 start_port;
242 u8 enabled;
243 u32 buf_size;
244 u32 pkt_aggr_limit;
245};
246
247struct mwifiex_sdio_mpa_rx {
248 u8 *buf;
249 u32 buf_len;
250 u32 pkt_cnt;
Amitkumar Karwar5ac253d2013-05-17 17:50:26 -0700251 u32 ports;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700252 u16 start_port;
253
254 struct sk_buff *skb_arr[SDIO_MP_AGGR_DEF_PKT_LIMIT];
255 u32 len_arr[SDIO_MP_AGGR_DEF_PKT_LIMIT];
256
257 u8 enabled;
258 u32 buf_size;
259 u32 pkt_aggr_limit;
260};
261
262int mwifiex_bus_register(void);
263void mwifiex_bus_unregister(void);
264
Amitkumar Karwar05889f82013-05-17 17:50:27 -0700265struct mwifiex_sdio_card_reg {
266 u8 start_rd_port;
267 u8 start_wr_port;
268 u8 base_0_reg;
269 u8 base_1_reg;
270 u8 poll_reg;
271 u8 host_int_enable;
272 u8 status_reg_0;
273 u8 status_reg_1;
274 u8 sdio_int_mask;
275 u32 data_port_mask;
276 u8 max_mp_regs;
277 u8 rd_bitmap_l;
278 u8 rd_bitmap_u;
279 u8 wr_bitmap_l;
280 u8 wr_bitmap_u;
281 u8 rd_len_p0_l;
282 u8 rd_len_p0_u;
283 u8 card_misc_cfg_reg;
284};
285
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700286struct sdio_mmc_card {
287 struct sdio_func *func;
288 struct mwifiex_adapter *adapter;
289
Amitkumar Karwar05889f82013-05-17 17:50:27 -0700290 const char *firmware;
291 const struct mwifiex_sdio_card_reg *reg;
292 u8 max_ports;
293 u8 mp_agg_pkt_limit;
294
Amitkumar Karwar5ac253d2013-05-17 17:50:26 -0700295 u32 mp_rd_bitmap;
296 u32 mp_wr_bitmap;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700297
298 u16 mp_end_port;
Amitkumar Karwar5ac253d2013-05-17 17:50:26 -0700299 u32 mp_data_port_mask;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700300
301 u8 curr_rd_port;
302 u8 curr_wr_port;
303
304 u8 *mp_regs;
305
306 struct mwifiex_sdio_mpa_tx mpa_tx;
307 struct mwifiex_sdio_mpa_rx mpa_rx;
308};
Amitkumar Karward930fae2011-10-11 17:41:21 -0700309
Amitkumar Karwar05889f82013-05-17 17:50:27 -0700310struct mwifiex_sdio_device {
311 const char *firmware;
312 const struct mwifiex_sdio_card_reg *reg;
313 u8 max_ports;
314 u8 mp_agg_pkt_limit;
315};
316
317static const struct mwifiex_sdio_card_reg mwifiex_reg_sd87xx = {
318 .start_rd_port = 1,
319 .start_wr_port = 1,
320 .base_0_reg = 0x0040,
321 .base_1_reg = 0x0041,
322 .poll_reg = 0x30,
323 .host_int_enable = UP_LD_HOST_INT_MASK | DN_LD_HOST_INT_MASK,
324 .status_reg_0 = 0x60,
325 .status_reg_1 = 0x61,
326 .sdio_int_mask = 0x3f,
327 .data_port_mask = 0x0000fffe,
328 .max_mp_regs = 64,
329 .rd_bitmap_l = 0x04,
330 .rd_bitmap_u = 0x05,
331 .wr_bitmap_l = 0x06,
332 .wr_bitmap_u = 0x07,
333 .rd_len_p0_l = 0x08,
334 .rd_len_p0_u = 0x09,
335 .card_misc_cfg_reg = 0x6c,
336};
337
338static const struct mwifiex_sdio_device mwifiex_sdio_sd8786 = {
339 .firmware = SD8786_DEFAULT_FW_NAME,
340 .reg = &mwifiex_reg_sd87xx,
341 .max_ports = 16,
342 .mp_agg_pkt_limit = 8,
343};
344
345static const struct mwifiex_sdio_device mwifiex_sdio_sd8787 = {
346 .firmware = SD8787_DEFAULT_FW_NAME,
347 .reg = &mwifiex_reg_sd87xx,
348 .max_ports = 16,
349 .mp_agg_pkt_limit = 8,
350};
351
352static const struct mwifiex_sdio_device mwifiex_sdio_sd8797 = {
353 .firmware = SD8797_DEFAULT_FW_NAME,
354 .reg = &mwifiex_reg_sd87xx,
355 .max_ports = 16,
356 .mp_agg_pkt_limit = 8,
357};
358
Amitkumar Karward930fae2011-10-11 17:41:21 -0700359/*
360 * .cmdrsp_complete handler
361 */
362static inline int mwifiex_sdio_cmdrsp_complete(struct mwifiex_adapter *adapter,
363 struct sk_buff *skb)
364{
365 dev_kfree_skb_any(skb);
366 return 0;
367}
368
369/*
370 * .event_complete handler
371 */
372static inline int mwifiex_sdio_event_complete(struct mwifiex_adapter *adapter,
373 struct sk_buff *skb)
374{
375 dev_kfree_skb_any(skb);
376 return 0;
377}
378
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700379#endif /* _MWIFIEX_SDIO_H */