Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1 | /* |
| 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 Karwar | d31ab35 | 2012-11-01 18:44:14 -0700 | [diff] [blame] | 28 | #include <linux/mmc/host.h> |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 29 | |
| 30 | #include "main.h" |
| 31 | |
WarheadsSE | 98e6b9d | 2012-04-24 15:57:21 -0400 | [diff] [blame] | 32 | #define SD8786_DEFAULT_FW_NAME "mrvl/sd8786_uapsta.bin" |
Amitkumar Karwar | 4a7f5db | 2011-05-23 18:00:17 -0700 | [diff] [blame] | 33 | #define SD8787_DEFAULT_FW_NAME "mrvl/sd8787_uapsta.bin" |
Bing Zhao | e3bea1c | 2011-11-16 20:40:35 -0800 | [diff] [blame] | 34 | #define SD8797_DEFAULT_FW_NAME "mrvl/sd8797_uapsta.bin" |
Amitkumar Karwar | 4a7f5db | 2011-05-23 18:00:17 -0700 | [diff] [blame] | 35 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 36 | #define BLOCK_MODE 1 |
| 37 | #define BYTE_MODE 0 |
| 38 | |
| 39 | #define REG_PORT 0 |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 40 | |
| 41 | #define MWIFIEX_SDIO_IO_PORT_MASK 0xfffff |
| 42 | |
| 43 | #define MWIFIEX_SDIO_BYTE_MODE_MASK 0x80000000 |
| 44 | |
Amitkumar Karwar | 248eb4c | 2013-05-17 17:54:34 -0700 | [diff] [blame] | 45 | #define SDIO_MPA_ADDR_BASE 0x1000 |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 46 | #define CTRL_PORT 0 |
| 47 | #define CTRL_PORT_MASK 0x0001 |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 48 | |
Amitkumar Karwar | f0c717e | 2011-07-05 18:01:11 -0700 | [diff] [blame] | 49 | #define SDIO_MP_TX_AGGR_DEF_BUF_SIZE (8192) /* 8K */ |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 50 | |
| 51 | /* Multi port RX aggregation buffer size */ |
Amitkumar Karwar | f0c717e | 2011-07-05 18:01:11 -0700 | [diff] [blame] | 52 | #define SDIO_MP_RX_AGGR_DEF_BUF_SIZE (16384) /* 16K */ |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 53 | |
| 54 | /* Misc. Config Register : Auto Re-enable interrupts */ |
| 55 | #define AUTO_RE_ENABLE_INT BIT(4) |
| 56 | |
| 57 | /* Host Control Registers */ |
| 58 | /* Host Control Registers : I/O port 0 */ |
| 59 | #define IO_PORT_0_REG 0x78 |
| 60 | /* Host Control Registers : I/O port 1 */ |
| 61 | #define IO_PORT_1_REG 0x79 |
| 62 | /* Host Control Registers : I/O port 2 */ |
| 63 | #define IO_PORT_2_REG 0x7A |
| 64 | |
| 65 | /* Host Control Registers : Configuration */ |
| 66 | #define CONFIGURATION_REG 0x00 |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 67 | /* Host Control Registers : Host power up */ |
| 68 | #define HOST_POWER_UP (0x1U << 1) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 69 | |
| 70 | /* Host Control Registers : Host interrupt mask */ |
| 71 | #define HOST_INT_MASK_REG 0x02 |
| 72 | /* Host Control Registers : Upload host interrupt mask */ |
| 73 | #define UP_LD_HOST_INT_MASK (0x1U) |
| 74 | /* Host Control Registers : Download host interrupt mask */ |
| 75 | #define DN_LD_HOST_INT_MASK (0x2U) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 76 | /* Disable Host interrupt mask */ |
| 77 | #define HOST_INT_DISABLE 0xff |
| 78 | |
| 79 | /* Host Control Registers : Host interrupt status */ |
| 80 | #define HOST_INTSTATUS_REG 0x03 |
| 81 | /* Host Control Registers : Upload host interrupt status */ |
| 82 | #define UP_LD_HOST_INT_STATUS (0x1U) |
| 83 | /* Host Control Registers : Download host interrupt status */ |
| 84 | #define DN_LD_HOST_INT_STATUS (0x2U) |
| 85 | |
| 86 | /* Host Control Registers : Host interrupt RSR */ |
| 87 | #define HOST_INT_RSR_REG 0x01 |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 88 | |
| 89 | /* Host Control Registers : Host interrupt status */ |
| 90 | #define HOST_INT_STATUS_REG 0x28 |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 91 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 92 | /* Card Control Registers : Card I/O ready */ |
| 93 | #define CARD_IO_READY (0x1U << 3) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 94 | /* Card Control Registers : Download card ready */ |
| 95 | #define DN_LD_CARD_RDY (0x1U << 0) |
| 96 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 97 | /* Max retry number of CMD53 write */ |
| 98 | #define MAX_WRITE_IOMEM_RETRY 2 |
| 99 | |
| 100 | /* SDIO Tx aggregation in progress ? */ |
| 101 | #define MP_TX_AGGR_IN_PROGRESS(a) (a->mpa_tx.pkt_cnt > 0) |
| 102 | |
| 103 | /* SDIO Tx aggregation buffer room for next packet ? */ |
| 104 | #define MP_TX_AGGR_BUF_HAS_ROOM(a, len) ((a->mpa_tx.buf_len+len) \ |
| 105 | <= a->mpa_tx.buf_size) |
| 106 | |
| 107 | /* Copy current packet (SDIO Tx aggregation buffer) to SDIO buffer */ |
| 108 | #define MP_TX_AGGR_BUF_PUT(a, payload, pkt_len, port) do { \ |
| 109 | memmove(&a->mpa_tx.buf[a->mpa_tx.buf_len], \ |
| 110 | payload, pkt_len); \ |
| 111 | a->mpa_tx.buf_len += pkt_len; \ |
| 112 | if (!a->mpa_tx.pkt_cnt) \ |
| 113 | a->mpa_tx.start_port = port; \ |
| 114 | if (a->mpa_tx.start_port <= port) \ |
| 115 | a->mpa_tx.ports |= (1<<(a->mpa_tx.pkt_cnt)); \ |
| 116 | else \ |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 117 | a->mpa_tx.ports |= (1<<(a->mpa_tx.pkt_cnt+1+ \ |
| 118 | (a->max_ports - \ |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 119 | a->mp_end_port))); \ |
| 120 | a->mpa_tx.pkt_cnt++; \ |
Joe Perches | da951c2 | 2012-04-03 14:46:49 -0700 | [diff] [blame] | 121 | } while (0) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 122 | |
| 123 | /* SDIO Tx aggregation limit ? */ |
| 124 | #define MP_TX_AGGR_PKT_LIMIT_REACHED(a) \ |
| 125 | (a->mpa_tx.pkt_cnt == a->mpa_tx.pkt_aggr_limit) |
| 126 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 127 | /* Reset SDIO Tx aggregation buffer parameters */ |
| 128 | #define MP_TX_AGGR_BUF_RESET(a) do { \ |
| 129 | a->mpa_tx.pkt_cnt = 0; \ |
| 130 | a->mpa_tx.buf_len = 0; \ |
| 131 | a->mpa_tx.ports = 0; \ |
| 132 | a->mpa_tx.start_port = 0; \ |
Joe Perches | da951c2 | 2012-04-03 14:46:49 -0700 | [diff] [blame] | 133 | } while (0) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 134 | |
| 135 | /* SDIO Rx aggregation limit ? */ |
| 136 | #define MP_RX_AGGR_PKT_LIMIT_REACHED(a) \ |
| 137 | (a->mpa_rx.pkt_cnt == a->mpa_rx.pkt_aggr_limit) |
| 138 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 139 | /* SDIO Rx aggregation in progress ? */ |
| 140 | #define MP_RX_AGGR_IN_PROGRESS(a) (a->mpa_rx.pkt_cnt > 0) |
| 141 | |
| 142 | /* SDIO Rx aggregation buffer room for next packet ? */ |
| 143 | #define MP_RX_AGGR_BUF_HAS_ROOM(a, rx_len) \ |
| 144 | ((a->mpa_rx.buf_len+rx_len) <= a->mpa_rx.buf_size) |
| 145 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 146 | /* Reset SDIO Rx aggregation buffer parameters */ |
| 147 | #define MP_RX_AGGR_BUF_RESET(a) do { \ |
| 148 | a->mpa_rx.pkt_cnt = 0; \ |
| 149 | a->mpa_rx.buf_len = 0; \ |
| 150 | a->mpa_rx.ports = 0; \ |
| 151 | a->mpa_rx.start_port = 0; \ |
Joe Perches | da951c2 | 2012-04-03 14:46:49 -0700 | [diff] [blame] | 152 | } while (0) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 153 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 154 | /* data structure for SDIO MPA TX */ |
| 155 | struct mwifiex_sdio_mpa_tx { |
| 156 | /* multiport tx aggregation buffer pointer */ |
| 157 | u8 *buf; |
| 158 | u32 buf_len; |
| 159 | u32 pkt_cnt; |
Amitkumar Karwar | 5ac253d | 2013-05-17 17:50:26 -0700 | [diff] [blame] | 160 | u32 ports; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 161 | u16 start_port; |
| 162 | u8 enabled; |
| 163 | u32 buf_size; |
| 164 | u32 pkt_aggr_limit; |
| 165 | }; |
| 166 | |
| 167 | struct mwifiex_sdio_mpa_rx { |
| 168 | u8 *buf; |
| 169 | u32 buf_len; |
| 170 | u32 pkt_cnt; |
Amitkumar Karwar | 5ac253d | 2013-05-17 17:50:26 -0700 | [diff] [blame] | 171 | u32 ports; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 172 | u16 start_port; |
| 173 | |
Amitkumar Karwar | c23b7c8 | 2013-05-17 17:54:51 -0700 | [diff] [blame^] | 174 | struct sk_buff **skb_arr; |
| 175 | u32 *len_arr; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 176 | |
| 177 | u8 enabled; |
| 178 | u32 buf_size; |
| 179 | u32 pkt_aggr_limit; |
| 180 | }; |
| 181 | |
| 182 | int mwifiex_bus_register(void); |
| 183 | void mwifiex_bus_unregister(void); |
| 184 | |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 185 | struct mwifiex_sdio_card_reg { |
| 186 | u8 start_rd_port; |
| 187 | u8 start_wr_port; |
| 188 | u8 base_0_reg; |
| 189 | u8 base_1_reg; |
| 190 | u8 poll_reg; |
| 191 | u8 host_int_enable; |
| 192 | u8 status_reg_0; |
| 193 | u8 status_reg_1; |
| 194 | u8 sdio_int_mask; |
| 195 | u32 data_port_mask; |
| 196 | u8 max_mp_regs; |
| 197 | u8 rd_bitmap_l; |
| 198 | u8 rd_bitmap_u; |
| 199 | u8 wr_bitmap_l; |
| 200 | u8 wr_bitmap_u; |
| 201 | u8 rd_len_p0_l; |
| 202 | u8 rd_len_p0_u; |
| 203 | u8 card_misc_cfg_reg; |
| 204 | }; |
| 205 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 206 | struct sdio_mmc_card { |
| 207 | struct sdio_func *func; |
| 208 | struct mwifiex_adapter *adapter; |
| 209 | |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 210 | const char *firmware; |
| 211 | const struct mwifiex_sdio_card_reg *reg; |
| 212 | u8 max_ports; |
| 213 | u8 mp_agg_pkt_limit; |
| 214 | |
Amitkumar Karwar | 5ac253d | 2013-05-17 17:50:26 -0700 | [diff] [blame] | 215 | u32 mp_rd_bitmap; |
| 216 | u32 mp_wr_bitmap; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 217 | |
| 218 | u16 mp_end_port; |
Amitkumar Karwar | 5ac253d | 2013-05-17 17:50:26 -0700 | [diff] [blame] | 219 | u32 mp_data_port_mask; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 220 | |
| 221 | u8 curr_rd_port; |
| 222 | u8 curr_wr_port; |
| 223 | |
| 224 | u8 *mp_regs; |
| 225 | |
| 226 | struct mwifiex_sdio_mpa_tx mpa_tx; |
| 227 | struct mwifiex_sdio_mpa_rx mpa_rx; |
| 228 | }; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 229 | |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 230 | struct mwifiex_sdio_device { |
| 231 | const char *firmware; |
| 232 | const struct mwifiex_sdio_card_reg *reg; |
| 233 | u8 max_ports; |
| 234 | u8 mp_agg_pkt_limit; |
| 235 | }; |
| 236 | |
| 237 | static const struct mwifiex_sdio_card_reg mwifiex_reg_sd87xx = { |
| 238 | .start_rd_port = 1, |
| 239 | .start_wr_port = 1, |
| 240 | .base_0_reg = 0x0040, |
| 241 | .base_1_reg = 0x0041, |
| 242 | .poll_reg = 0x30, |
| 243 | .host_int_enable = UP_LD_HOST_INT_MASK | DN_LD_HOST_INT_MASK, |
| 244 | .status_reg_0 = 0x60, |
| 245 | .status_reg_1 = 0x61, |
| 246 | .sdio_int_mask = 0x3f, |
| 247 | .data_port_mask = 0x0000fffe, |
| 248 | .max_mp_regs = 64, |
| 249 | .rd_bitmap_l = 0x04, |
| 250 | .rd_bitmap_u = 0x05, |
| 251 | .wr_bitmap_l = 0x06, |
| 252 | .wr_bitmap_u = 0x07, |
| 253 | .rd_len_p0_l = 0x08, |
| 254 | .rd_len_p0_u = 0x09, |
| 255 | .card_misc_cfg_reg = 0x6c, |
| 256 | }; |
| 257 | |
| 258 | static const struct mwifiex_sdio_device mwifiex_sdio_sd8786 = { |
| 259 | .firmware = SD8786_DEFAULT_FW_NAME, |
| 260 | .reg = &mwifiex_reg_sd87xx, |
| 261 | .max_ports = 16, |
| 262 | .mp_agg_pkt_limit = 8, |
| 263 | }; |
| 264 | |
| 265 | static const struct mwifiex_sdio_device mwifiex_sdio_sd8787 = { |
| 266 | .firmware = SD8787_DEFAULT_FW_NAME, |
| 267 | .reg = &mwifiex_reg_sd87xx, |
| 268 | .max_ports = 16, |
| 269 | .mp_agg_pkt_limit = 8, |
| 270 | }; |
| 271 | |
| 272 | static const struct mwifiex_sdio_device mwifiex_sdio_sd8797 = { |
| 273 | .firmware = SD8797_DEFAULT_FW_NAME, |
| 274 | .reg = &mwifiex_reg_sd87xx, |
| 275 | .max_ports = 16, |
| 276 | .mp_agg_pkt_limit = 8, |
| 277 | }; |
| 278 | |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 279 | /* |
| 280 | * .cmdrsp_complete handler |
| 281 | */ |
| 282 | static inline int mwifiex_sdio_cmdrsp_complete(struct mwifiex_adapter *adapter, |
| 283 | struct sk_buff *skb) |
| 284 | { |
| 285 | dev_kfree_skb_any(skb); |
| 286 | return 0; |
| 287 | } |
| 288 | |
| 289 | /* |
| 290 | * .event_complete handler |
| 291 | */ |
| 292 | static inline int mwifiex_sdio_event_complete(struct mwifiex_adapter *adapter, |
| 293 | struct sk_buff *skb) |
| 294 | { |
| 295 | dev_kfree_skb_any(skb); |
| 296 | return 0; |
| 297 | } |
| 298 | |
Amitkumar Karwar | c23b7c8 | 2013-05-17 17:54:51 -0700 | [diff] [blame^] | 299 | static inline bool |
| 300 | mp_rx_aggr_port_limit_reached(struct sdio_mmc_card *card) |
| 301 | { |
| 302 | u8 tmp; |
| 303 | |
| 304 | if (card->curr_rd_port < card->mpa_rx.start_port) { |
| 305 | tmp = card->mp_agg_pkt_limit; |
| 306 | |
| 307 | if (((card->max_ports - card->mpa_rx.start_port) + |
| 308 | card->curr_rd_port) >= tmp) |
| 309 | return true; |
| 310 | } |
| 311 | |
| 312 | return false; |
| 313 | } |
| 314 | |
| 315 | static inline bool |
| 316 | mp_tx_aggr_port_limit_reached(struct sdio_mmc_card *card) |
| 317 | { |
| 318 | u16 tmp; |
| 319 | |
| 320 | if (card->curr_wr_port < card->mpa_tx.start_port) { |
| 321 | tmp = card->mp_agg_pkt_limit; |
| 322 | |
| 323 | if (((card->max_ports - card->mpa_tx.start_port) + |
| 324 | card->curr_wr_port) >= tmp) |
| 325 | return true; |
| 326 | } |
| 327 | |
| 328 | return false; |
| 329 | } |
| 330 | |
| 331 | /* Prepare to copy current packet from card to SDIO Rx aggregation buffer */ |
| 332 | static inline void mp_rx_aggr_setup(struct sdio_mmc_card *card, |
| 333 | struct sk_buff *skb, u8 port) |
| 334 | { |
| 335 | card->mpa_rx.buf_len += skb->len; |
| 336 | |
| 337 | if (!card->mpa_rx.pkt_cnt) |
| 338 | card->mpa_rx.start_port = port; |
| 339 | |
| 340 | if (card->mpa_rx.start_port <= port) |
| 341 | card->mpa_rx.ports |= 1 << (card->mpa_rx.pkt_cnt); |
| 342 | else |
| 343 | card->mpa_rx.ports |= 1 << (card->mpa_rx.pkt_cnt + 1); |
| 344 | |
| 345 | card->mpa_rx.skb_arr[card->mpa_rx.pkt_cnt] = skb; |
| 346 | card->mpa_rx.len_arr[card->mpa_rx.pkt_cnt] = skb->len; |
| 347 | card->mpa_rx.pkt_cnt++; |
| 348 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 349 | #endif /* _MWIFIEX_SDIO_H */ |