sdio.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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. #ifndef _MWIFIEX_SDIO_H
  20. #define _MWIFIEX_SDIO_H
  21. #include <linux/mmc/sdio.h>
  22. #include <linux/mmc/sdio_ids.h>
  23. #include <linux/mmc/sdio_func.h>
  24. #include <linux/mmc/card.h>
  25. #include "main.h"
  26. #define SD8787_DEFAULT_FW_NAME "mrvl/sd8787_uapsta.bin"
  27. #define SD8797_DEFAULT_FW_NAME "mrvl/sd8797_uapsta.bin"
  28. #define BLOCK_MODE 1
  29. #define BYTE_MODE 0
  30. #define REG_PORT 0
  31. #define RD_BITMAP_L 0x04
  32. #define RD_BITMAP_U 0x05
  33. #define WR_BITMAP_L 0x06
  34. #define WR_BITMAP_U 0x07
  35. #define RD_LEN_P0_L 0x08
  36. #define RD_LEN_P0_U 0x09
  37. #define MWIFIEX_SDIO_IO_PORT_MASK 0xfffff
  38. #define MWIFIEX_SDIO_BYTE_MODE_MASK 0x80000000
  39. #define CTRL_PORT 0
  40. #define CTRL_PORT_MASK 0x0001
  41. #define DATA_PORT_MASK 0xfffe
  42. #define MAX_MP_REGS 64
  43. #define MAX_PORT 16
  44. #define SDIO_MP_AGGR_DEF_PKT_LIMIT 8
  45. #define SDIO_MP_TX_AGGR_DEF_BUF_SIZE (8192) /* 8K */
  46. /* Multi port RX aggregation buffer size */
  47. #define SDIO_MP_RX_AGGR_DEF_BUF_SIZE (16384) /* 16K */
  48. /* Misc. Config Register : Auto Re-enable interrupts */
  49. #define AUTO_RE_ENABLE_INT BIT(4)
  50. /* Host Control Registers */
  51. /* Host Control Registers : I/O port 0 */
  52. #define IO_PORT_0_REG 0x78
  53. /* Host Control Registers : I/O port 1 */
  54. #define IO_PORT_1_REG 0x79
  55. /* Host Control Registers : I/O port 2 */
  56. #define IO_PORT_2_REG 0x7A
  57. /* Host Control Registers : Configuration */
  58. #define CONFIGURATION_REG 0x00
  59. /* Host Control Registers : Host without Command 53 finish host*/
  60. #define HOST_TO_CARD_EVENT (0x1U << 3)
  61. /* Host Control Registers : Host without Command 53 finish host */
  62. #define HOST_WO_CMD53_FINISH_HOST (0x1U << 2)
  63. /* Host Control Registers : Host power up */
  64. #define HOST_POWER_UP (0x1U << 1)
  65. /* Host Control Registers : Host power down */
  66. #define HOST_POWER_DOWN (0x1U << 0)
  67. /* Host Control Registers : Host interrupt mask */
  68. #define HOST_INT_MASK_REG 0x02
  69. /* Host Control Registers : Upload host interrupt mask */
  70. #define UP_LD_HOST_INT_MASK (0x1U)
  71. /* Host Control Registers : Download host interrupt mask */
  72. #define DN_LD_HOST_INT_MASK (0x2U)
  73. /* Enable Host interrupt mask */
  74. #define HOST_INT_ENABLE (UP_LD_HOST_INT_MASK | DN_LD_HOST_INT_MASK)
  75. /* Disable Host interrupt mask */
  76. #define HOST_INT_DISABLE 0xff
  77. /* Host Control Registers : Host interrupt status */
  78. #define HOST_INTSTATUS_REG 0x03
  79. /* Host Control Registers : Upload host interrupt status */
  80. #define UP_LD_HOST_INT_STATUS (0x1U)
  81. /* Host Control Registers : Download host interrupt status */
  82. #define DN_LD_HOST_INT_STATUS (0x2U)
  83. /* Host Control Registers : Host interrupt RSR */
  84. #define HOST_INT_RSR_REG 0x01
  85. /* Host Control Registers : Upload host interrupt RSR */
  86. #define UP_LD_HOST_INT_RSR (0x1U)
  87. #define SDIO_INT_MASK 0x3F
  88. /* Host Control Registers : Host interrupt status */
  89. #define HOST_INT_STATUS_REG 0x28
  90. /* Host Control Registers : Upload CRC error */
  91. #define UP_LD_CRC_ERR (0x1U << 2)
  92. /* Host Control Registers : Upload restart */
  93. #define UP_LD_RESTART (0x1U << 1)
  94. /* Host Control Registers : Download restart */
  95. #define DN_LD_RESTART (0x1U << 0)
  96. /* Card Control Registers : Card status register */
  97. #define CARD_STATUS_REG 0x30
  98. /* Card Control Registers : Card I/O ready */
  99. #define CARD_IO_READY (0x1U << 3)
  100. /* Card Control Registers : CIS card ready */
  101. #define CIS_CARD_RDY (0x1U << 2)
  102. /* Card Control Registers : Upload card ready */
  103. #define UP_LD_CARD_RDY (0x1U << 1)
  104. /* Card Control Registers : Download card ready */
  105. #define DN_LD_CARD_RDY (0x1U << 0)
  106. /* Card Control Registers : Host interrupt mask register */
  107. #define HOST_INTERRUPT_MASK_REG 0x34
  108. /* Card Control Registers : Host power interrupt mask */
  109. #define HOST_POWER_INT_MASK (0x1U << 3)
  110. /* Card Control Registers : Abort card interrupt mask */
  111. #define ABORT_CARD_INT_MASK (0x1U << 2)
  112. /* Card Control Registers : Upload card interrupt mask */
  113. #define UP_LD_CARD_INT_MASK (0x1U << 1)
  114. /* Card Control Registers : Download card interrupt mask */
  115. #define DN_LD_CARD_INT_MASK (0x1U << 0)
  116. /* Card Control Registers : Card interrupt status register */
  117. #define CARD_INTERRUPT_STATUS_REG 0x38
  118. /* Card Control Registers : Power up interrupt */
  119. #define POWER_UP_INT (0x1U << 4)
  120. /* Card Control Registers : Power down interrupt */
  121. #define POWER_DOWN_INT (0x1U << 3)
  122. /* Card Control Registers : Card interrupt RSR register */
  123. #define CARD_INTERRUPT_RSR_REG 0x3c
  124. /* Card Control Registers : Power up RSR */
  125. #define POWER_UP_RSR (0x1U << 4)
  126. /* Card Control Registers : Power down RSR */
  127. #define POWER_DOWN_RSR (0x1U << 3)
  128. /* Card Control Registers : Miscellaneous Configuration Register */
  129. #define CARD_MISC_CFG_REG 0x6C
  130. /* Host F1 read base 0 */
  131. #define HOST_F1_RD_BASE_0 0x0040
  132. /* Host F1 read base 1 */
  133. #define HOST_F1_RD_BASE_1 0x0041
  134. /* Host F1 card ready */
  135. #define HOST_F1_CARD_RDY 0x0020
  136. /* Firmware status 0 register */
  137. #define CARD_FW_STATUS0_REG 0x60
  138. /* Firmware status 1 register */
  139. #define CARD_FW_STATUS1_REG 0x61
  140. /* Rx length register */
  141. #define CARD_RX_LEN_REG 0x62
  142. /* Rx unit register */
  143. #define CARD_RX_UNIT_REG 0x63
  144. /* Max retry number of CMD53 write */
  145. #define MAX_WRITE_IOMEM_RETRY 2
  146. /* SDIO Tx aggregation in progress ? */
  147. #define MP_TX_AGGR_IN_PROGRESS(a) (a->mpa_tx.pkt_cnt > 0)
  148. /* SDIO Tx aggregation buffer room for next packet ? */
  149. #define MP_TX_AGGR_BUF_HAS_ROOM(a, len) ((a->mpa_tx.buf_len+len) \
  150. <= a->mpa_tx.buf_size)
  151. /* Copy current packet (SDIO Tx aggregation buffer) to SDIO buffer */
  152. #define MP_TX_AGGR_BUF_PUT(a, payload, pkt_len, port) do { \
  153. memmove(&a->mpa_tx.buf[a->mpa_tx.buf_len], \
  154. payload, pkt_len); \
  155. a->mpa_tx.buf_len += pkt_len; \
  156. if (!a->mpa_tx.pkt_cnt) \
  157. a->mpa_tx.start_port = port; \
  158. if (a->mpa_tx.start_port <= port) \
  159. a->mpa_tx.ports |= (1<<(a->mpa_tx.pkt_cnt)); \
  160. else \
  161. a->mpa_tx.ports |= (1<<(a->mpa_tx.pkt_cnt+1+(MAX_PORT - \
  162. a->mp_end_port))); \
  163. a->mpa_tx.pkt_cnt++; \
  164. } while (0);
  165. /* SDIO Tx aggregation limit ? */
  166. #define MP_TX_AGGR_PKT_LIMIT_REACHED(a) \
  167. (a->mpa_tx.pkt_cnt == a->mpa_tx.pkt_aggr_limit)
  168. /* SDIO Tx aggregation port limit ? */
  169. #define MP_TX_AGGR_PORT_LIMIT_REACHED(a) ((a->curr_wr_port < \
  170. a->mpa_tx.start_port) && (((MAX_PORT - \
  171. a->mpa_tx.start_port) + a->curr_wr_port) >= \
  172. SDIO_MP_AGGR_DEF_PKT_LIMIT))
  173. /* Reset SDIO Tx aggregation buffer parameters */
  174. #define MP_TX_AGGR_BUF_RESET(a) do { \
  175. a->mpa_tx.pkt_cnt = 0; \
  176. a->mpa_tx.buf_len = 0; \
  177. a->mpa_tx.ports = 0; \
  178. a->mpa_tx.start_port = 0; \
  179. } while (0);
  180. /* SDIO Rx aggregation limit ? */
  181. #define MP_RX_AGGR_PKT_LIMIT_REACHED(a) \
  182. (a->mpa_rx.pkt_cnt == a->mpa_rx.pkt_aggr_limit)
  183. /* SDIO Tx aggregation port limit ? */
  184. #define MP_RX_AGGR_PORT_LIMIT_REACHED(a) ((a->curr_rd_port < \
  185. a->mpa_rx.start_port) && (((MAX_PORT - \
  186. a->mpa_rx.start_port) + a->curr_rd_port) >= \
  187. SDIO_MP_AGGR_DEF_PKT_LIMIT))
  188. /* SDIO Rx aggregation in progress ? */
  189. #define MP_RX_AGGR_IN_PROGRESS(a) (a->mpa_rx.pkt_cnt > 0)
  190. /* SDIO Rx aggregation buffer room for next packet ? */
  191. #define MP_RX_AGGR_BUF_HAS_ROOM(a, rx_len) \
  192. ((a->mpa_rx.buf_len+rx_len) <= a->mpa_rx.buf_size)
  193. /* Prepare to copy current packet from card to SDIO Rx aggregation buffer */
  194. #define MP_RX_AGGR_SETUP(a, skb, port) do { \
  195. a->mpa_rx.buf_len += skb->len; \
  196. if (!a->mpa_rx.pkt_cnt) \
  197. a->mpa_rx.start_port = port; \
  198. if (a->mpa_rx.start_port <= port) \
  199. a->mpa_rx.ports |= (1<<(a->mpa_rx.pkt_cnt)); \
  200. else \
  201. a->mpa_rx.ports |= (1<<(a->mpa_rx.pkt_cnt+1)); \
  202. a->mpa_rx.skb_arr[a->mpa_rx.pkt_cnt] = skb; \
  203. a->mpa_rx.len_arr[a->mpa_rx.pkt_cnt] = skb->len; \
  204. a->mpa_rx.pkt_cnt++; \
  205. } while (0);
  206. /* Reset SDIO Rx aggregation buffer parameters */
  207. #define MP_RX_AGGR_BUF_RESET(a) do { \
  208. a->mpa_rx.pkt_cnt = 0; \
  209. a->mpa_rx.buf_len = 0; \
  210. a->mpa_rx.ports = 0; \
  211. a->mpa_rx.start_port = 0; \
  212. } while (0);
  213. /* data structure for SDIO MPA TX */
  214. struct mwifiex_sdio_mpa_tx {
  215. /* multiport tx aggregation buffer pointer */
  216. u8 *buf;
  217. u32 buf_len;
  218. u32 pkt_cnt;
  219. u16 ports;
  220. u16 start_port;
  221. u8 enabled;
  222. u32 buf_size;
  223. u32 pkt_aggr_limit;
  224. };
  225. struct mwifiex_sdio_mpa_rx {
  226. u8 *buf;
  227. u32 buf_len;
  228. u32 pkt_cnt;
  229. u16 ports;
  230. u16 start_port;
  231. struct sk_buff *skb_arr[SDIO_MP_AGGR_DEF_PKT_LIMIT];
  232. u32 len_arr[SDIO_MP_AGGR_DEF_PKT_LIMIT];
  233. u8 enabled;
  234. u32 buf_size;
  235. u32 pkt_aggr_limit;
  236. };
  237. int mwifiex_bus_register(void);
  238. void mwifiex_bus_unregister(void);
  239. struct sdio_mmc_card {
  240. struct sdio_func *func;
  241. struct mwifiex_adapter *adapter;
  242. u16 mp_rd_bitmap;
  243. u16 mp_wr_bitmap;
  244. u16 mp_end_port;
  245. u16 mp_data_port_mask;
  246. u8 curr_rd_port;
  247. u8 curr_wr_port;
  248. u8 *mp_regs;
  249. struct mwifiex_sdio_mpa_tx mpa_tx;
  250. struct mwifiex_sdio_mpa_rx mpa_rx;
  251. };
  252. /*
  253. * .cmdrsp_complete handler
  254. */
  255. static inline int mwifiex_sdio_cmdrsp_complete(struct mwifiex_adapter *adapter,
  256. struct sk_buff *skb)
  257. {
  258. dev_kfree_skb_any(skb);
  259. return 0;
  260. }
  261. /*
  262. * .event_complete handler
  263. */
  264. static inline int mwifiex_sdio_event_complete(struct mwifiex_adapter *adapter,
  265. struct sk_buff *skb)
  266. {
  267. dev_kfree_skb_any(skb);
  268. return 0;
  269. }
  270. #endif /* _MWIFIEX_SDIO_H */