wlan.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
  4. * All rights reserved.
  5. */
  6. #ifndef WILC_WLAN_H
  7. #define WILC_WLAN_H
  8. #include <linux/types.h>
  9. #include <linux/bitfield.h>
  10. /********************************************
  11. *
  12. * Mac eth header length
  13. *
  14. ********************************************/
  15. #define MAX_MAC_HDR_LEN 26 /* QOS_MAC_HDR_LEN */
  16. #define SUB_MSDU_HEADER_LENGTH 14
  17. #define SNAP_HDR_LEN 8
  18. #define ETHERNET_HDR_LEN 14
  19. #define WORD_ALIGNMENT_PAD 0
  20. #define ETH_ETHERNET_HDR_OFFSET (MAX_MAC_HDR_LEN + \
  21. SUB_MSDU_HEADER_LENGTH + \
  22. SNAP_HDR_LEN - \
  23. ETHERNET_HDR_LEN + \
  24. WORD_ALIGNMENT_PAD)
  25. #define HOST_HDR_OFFSET 4
  26. #define ETHERNET_HDR_LEN 14
  27. #define IP_HDR_LEN 20
  28. #define IP_HDR_OFFSET ETHERNET_HDR_LEN
  29. #define UDP_HDR_OFFSET (IP_HDR_LEN + IP_HDR_OFFSET)
  30. #define UDP_HDR_LEN 8
  31. #define UDP_DATA_OFFSET (UDP_HDR_OFFSET + UDP_HDR_LEN)
  32. #define ETH_CONFIG_PKT_HDR_LEN UDP_DATA_OFFSET
  33. #define ETH_CONFIG_PKT_HDR_OFFSET (ETH_ETHERNET_HDR_OFFSET + \
  34. ETH_CONFIG_PKT_HDR_LEN)
  35. /********************************************
  36. *
  37. * Register Defines
  38. *
  39. ********************************************/
  40. #define WILC_PERIPH_REG_BASE 0x1000
  41. #define WILC_CHANGING_VIR_IF 0x108c
  42. #define WILC_CHIPID WILC_PERIPH_REG_BASE
  43. #define WILC_GLB_RESET_0 (WILC_PERIPH_REG_BASE + 0x400)
  44. #define WILC_PIN_MUX_0 (WILC_PERIPH_REG_BASE + 0x408)
  45. #define WILC_HOST_TX_CTRL (WILC_PERIPH_REG_BASE + 0x6c)
  46. #define WILC_HOST_RX_CTRL_0 (WILC_PERIPH_REG_BASE + 0x70)
  47. #define WILC_HOST_RX_CTRL_1 (WILC_PERIPH_REG_BASE + 0x74)
  48. #define WILC_HOST_VMM_CTL (WILC_PERIPH_REG_BASE + 0x78)
  49. #define WILC_HOST_RX_CTRL (WILC_PERIPH_REG_BASE + 0x80)
  50. #define WILC_HOST_RX_EXTRA_SIZE (WILC_PERIPH_REG_BASE + 0x84)
  51. #define WILC_HOST_TX_CTRL_1 (WILC_PERIPH_REG_BASE + 0x88)
  52. #define WILC_MISC (WILC_PERIPH_REG_BASE + 0x428)
  53. #define WILC_INTR_REG_BASE (WILC_PERIPH_REG_BASE + 0xa00)
  54. #define WILC_INTR_ENABLE WILC_INTR_REG_BASE
  55. #define WILC_INTR2_ENABLE (WILC_INTR_REG_BASE + 4)
  56. #define WILC_INTR_POLARITY (WILC_INTR_REG_BASE + 0x10)
  57. #define WILC_INTR_TYPE (WILC_INTR_REG_BASE + 0x20)
  58. #define WILC_INTR_CLEAR (WILC_INTR_REG_BASE + 0x30)
  59. #define WILC_INTR_STATUS (WILC_INTR_REG_BASE + 0x40)
  60. #define WILC_RF_REVISION_ID 0x13f4
  61. #define WILC_VMM_TBL_SIZE 64
  62. #define WILC_VMM_TX_TBL_BASE 0x150400
  63. #define WILC_VMM_RX_TBL_BASE 0x150500
  64. #define WILC_VMM_BASE 0x150000
  65. #define WILC_VMM_CORE_CTL WILC_VMM_BASE
  66. #define WILC_VMM_TBL_CTL (WILC_VMM_BASE + 0x4)
  67. #define WILC_VMM_TBL_ENTRY (WILC_VMM_BASE + 0x8)
  68. #define WILC_VMM_TBL0_SIZE (WILC_VMM_BASE + 0xc)
  69. #define WILC_VMM_TO_HOST_SIZE (WILC_VMM_BASE + 0x10)
  70. #define WILC_VMM_CORE_CFG (WILC_VMM_BASE + 0x14)
  71. #define WILC_VMM_TBL_ACTIVE (WILC_VMM_BASE + 040)
  72. #define WILC_VMM_TBL_STATUS (WILC_VMM_BASE + 0x44)
  73. #define WILC_SPI_REG_BASE 0xe800
  74. #define WILC_SPI_CTL WILC_SPI_REG_BASE
  75. #define WILC_SPI_MASTER_DMA_ADDR (WILC_SPI_REG_BASE + 0x4)
  76. #define WILC_SPI_MASTER_DMA_COUNT (WILC_SPI_REG_BASE + 0x8)
  77. #define WILC_SPI_SLAVE_DMA_ADDR (WILC_SPI_REG_BASE + 0xc)
  78. #define WILC_SPI_SLAVE_DMA_COUNT (WILC_SPI_REG_BASE + 0x10)
  79. #define WILC_SPI_TX_MODE (WILC_SPI_REG_BASE + 0x20)
  80. #define WILC_SPI_PROTOCOL_CONFIG (WILC_SPI_REG_BASE + 0x24)
  81. #define WILC_SPI_INTR_CTL (WILC_SPI_REG_BASE + 0x2c)
  82. #define WILC_SPI_INT_STATUS (WILC_SPI_REG_BASE + 0x40)
  83. #define WILC_SPI_INT_CLEAR (WILC_SPI_REG_BASE + 0x44)
  84. #define WILC_SPI_WAKEUP_REG 0x1
  85. #define WILC_SPI_WAKEUP_BIT BIT(1)
  86. #define WILC_SPI_CLK_STATUS_REG 0x0f
  87. #define WILC_SPI_CLK_STATUS_BIT BIT(2)
  88. #define WILC_SPI_HOST_TO_FW_REG 0x0b
  89. #define WILC_SPI_HOST_TO_FW_BIT BIT(0)
  90. #define WILC_SPI_FW_TO_HOST_REG 0x10
  91. #define WILC_SPI_FW_TO_HOST_BIT BIT(0)
  92. #define WILC_SPI_PROTOCOL_OFFSET (WILC_SPI_PROTOCOL_CONFIG - \
  93. WILC_SPI_REG_BASE)
  94. #define WILC_SPI_CLOCKLESS_ADDR_LIMIT 0x30
  95. /* Functions IO enables bits */
  96. #define WILC_SDIO_CCCR_IO_EN_FUNC1 BIT(1)
  97. /* Function/Interrupt enables bits */
  98. #define WILC_SDIO_CCCR_IEN_MASTER BIT(0)
  99. #define WILC_SDIO_CCCR_IEN_FUNC1 BIT(1)
  100. /* Abort CCCR register bits */
  101. #define WILC_SDIO_CCCR_ABORT_RESET BIT(3)
  102. /* Vendor specific CCCR registers */
  103. #define WILC_SDIO_WAKEUP_REG 0xf0
  104. #define WILC_SDIO_WAKEUP_BIT BIT(0)
  105. #define WILC_SDIO_CLK_STATUS_REG 0xf1
  106. #define WILC_SDIO_CLK_STATUS_BIT BIT(0)
  107. #define WILC_SDIO_INTERRUPT_DATA_SZ_REG 0xf2 /* Read size (2 bytes) */
  108. #define WILC_SDIO_VMM_TBL_CTRL_REG 0xf6
  109. #define WILC_SDIO_IRQ_FLAG_REG 0xf7
  110. #define WILC_SDIO_IRQ_CLEAR_FLAG_REG 0xf8
  111. #define WILC_SDIO_HOST_TO_FW_REG 0xfa
  112. #define WILC_SDIO_HOST_TO_FW_BIT BIT(0)
  113. #define WILC_SDIO_FW_TO_HOST_REG 0xfc
  114. #define WILC_SDIO_FW_TO_HOST_BIT BIT(0)
  115. /* Function 1 specific FBR register */
  116. #define WILC_SDIO_FBR_CSA_REG 0x10C /* CSA pointer (3 bytes) */
  117. #define WILC_SDIO_FBR_DATA_REG 0x10F
  118. #define WILC_SDIO_F1_DATA_REG 0x0
  119. #define WILC_SDIO_EXT_IRQ_FLAG_REG 0x4
  120. #define WILC_AHB_DATA_MEM_BASE 0x30000
  121. #define WILC_AHB_SHARE_MEM_BASE 0xd0000
  122. #define WILC_VMM_TBL_RX_SHADOW_BASE WILC_AHB_SHARE_MEM_BASE
  123. #define WILC_VMM_TBL_RX_SHADOW_SIZE 256
  124. #define WILC_FW_HOST_COMM 0x13c0
  125. #define WILC_GP_REG_0 0x149c
  126. #define WILC_GP_REG_1 0x14a0
  127. #define WILC_HAVE_SDIO_IRQ_GPIO BIT(0)
  128. #define WILC_HAVE_USE_PMU BIT(1)
  129. #define WILC_HAVE_SLEEP_CLK_SRC_RTC BIT(2)
  130. #define WILC_HAVE_SLEEP_CLK_SRC_XO BIT(3)
  131. #define WILC_HAVE_EXT_PA_INV_TX_RX BIT(4)
  132. #define WILC_HAVE_LEGACY_RF_SETTINGS BIT(5)
  133. #define WILC_HAVE_XTAL_24 BIT(6)
  134. #define WILC_HAVE_DISABLE_WILC_UART BIT(7)
  135. #define WILC_HAVE_USE_IRQ_AS_HOST_WAKE BIT(8)
  136. #define WILC_CORTUS_INTERRUPT_BASE 0x10A8
  137. #define WILC_CORTUS_INTERRUPT_1 (WILC_CORTUS_INTERRUPT_BASE + 0x4)
  138. #define WILC_CORTUS_INTERRUPT_2 (WILC_CORTUS_INTERRUPT_BASE + 0x8)
  139. /* tx control register 1 to 4 for RX */
  140. #define WILC_REG_4_TO_1_RX 0x1e1c
  141. /* tx control register 1 to 4 for TX Bank_0 */
  142. #define WILC_REG_4_TO_1_TX_BANK0 0x1e9c
  143. #define WILC_CORTUS_RESET_MUX_SEL 0x1118
  144. #define WILC_CORTUS_BOOT_REGISTER 0xc0000
  145. #define WILC_CORTUS_BOOT_FROM_IRAM 0x71
  146. #define WILC_1000_BASE_ID 0x100000
  147. #define WILC_1000_BASE_ID_2A 0x1002A0
  148. #define WILC_1000_BASE_ID_2A_REV1 (WILC_1000_BASE_ID_2A + 1)
  149. #define WILC_1000_BASE_ID_2B 0x1002B0
  150. #define WILC_1000_BASE_ID_2B_REV1 (WILC_1000_BASE_ID_2B + 1)
  151. #define WILC_1000_BASE_ID_2B_REV2 (WILC_1000_BASE_ID_2B + 2)
  152. #define WILC_CHIP_REV_FIELD GENMASK(11, 0)
  153. /********************************************
  154. *
  155. * Wlan Defines
  156. *
  157. ********************************************/
  158. #define WILC_CFG_PKT 1
  159. #define WILC_NET_PKT 0
  160. #define WILC_MGMT_PKT 2
  161. #define WILC_CFG_SET 1
  162. #define WILC_CFG_QUERY 0
  163. #define WILC_CFG_RSP 1
  164. #define WILC_CFG_RSP_STATUS 2
  165. #define WILC_CFG_RSP_SCAN 3
  166. #define WILC_ABORT_REQ_BIT BIT(31)
  167. #define WILC_RX_BUFF_SIZE (96 * 1024)
  168. #define WILC_TX_BUFF_SIZE (64 * 1024)
  169. #define NQUEUES 4
  170. #define AC_BUFFER_SIZE 1000
  171. #define VO_AC_COUNT_FIELD GENMASK(31, 25)
  172. #define VO_AC_ACM_STAT_FIELD BIT(24)
  173. #define VI_AC_COUNT_FIELD GENMASK(23, 17)
  174. #define VI_AC_ACM_STAT_FIELD BIT(16)
  175. #define BE_AC_COUNT_FIELD GENMASK(15, 9)
  176. #define BE_AC_ACM_STAT_FIELD BIT(8)
  177. #define BK_AC_COUNT_FIELD GENMASK(7, 3)
  178. #define BK_AC_ACM_STAT_FIELD BIT(1)
  179. #define WILC_PKT_HDR_CONFIG_FIELD BIT(31)
  180. #define WILC_PKT_HDR_OFFSET_FIELD GENMASK(30, 22)
  181. #define WILC_PKT_HDR_TOTAL_LEN_FIELD GENMASK(21, 11)
  182. #define WILC_PKT_HDR_LEN_FIELD GENMASK(10, 0)
  183. #define WILC_INTERRUPT_DATA_SIZE GENMASK(14, 0)
  184. #define WILC_VMM_BUFFER_SIZE GENMASK(9, 0)
  185. #define WILC_VMM_HDR_TYPE BIT(31)
  186. #define WILC_VMM_HDR_MGMT_FIELD BIT(30)
  187. #define WILC_VMM_HDR_PKT_SIZE GENMASK(29, 15)
  188. #define WILC_VMM_HDR_BUFF_SIZE GENMASK(14, 0)
  189. #define WILC_VMM_ENTRY_COUNT GENMASK(8, 3)
  190. #define WILC_VMM_ENTRY_AVAILABLE BIT(2)
  191. /*******************************************/
  192. /* E0 and later Interrupt flags. */
  193. /*******************************************/
  194. /*******************************************/
  195. /* E0 and later Interrupt flags. */
  196. /* IRQ Status word */
  197. /* 15:0 = DMA count in words. */
  198. /* 16: INT0 flag */
  199. /* 17: INT1 flag */
  200. /* 18: INT2 flag */
  201. /* 19: INT3 flag */
  202. /* 20: INT4 flag */
  203. /* 21: INT5 flag */
  204. /*******************************************/
  205. #define IRG_FLAGS_OFFSET 16
  206. #define IRQ_DMA_WD_CNT_MASK GENMASK(IRG_FLAGS_OFFSET - 1, 0)
  207. #define INT_0 BIT(IRG_FLAGS_OFFSET)
  208. #define INT_1 BIT(IRG_FLAGS_OFFSET + 1)
  209. #define INT_2 BIT(IRG_FLAGS_OFFSET + 2)
  210. #define INT_3 BIT(IRG_FLAGS_OFFSET + 3)
  211. #define INT_4 BIT(IRG_FLAGS_OFFSET + 4)
  212. #define INT_5 BIT(IRG_FLAGS_OFFSET + 5)
  213. #define MAX_NUM_INT 5
  214. #define IRG_FLAGS_MASK GENMASK(IRG_FLAGS_OFFSET + MAX_NUM_INT, \
  215. IRG_FLAGS_OFFSET)
  216. /*******************************************/
  217. /* E0 and later Interrupt flags. */
  218. /* IRQ Clear word */
  219. /* 0: Clear INT0 */
  220. /* 1: Clear INT1 */
  221. /* 2: Clear INT2 */
  222. /* 3: Clear INT3 */
  223. /* 4: Clear INT4 */
  224. /* 5: Clear INT5 */
  225. /* 6: Select VMM table 1 */
  226. /* 7: Select VMM table 2 */
  227. /* 8: Enable VMM */
  228. /*******************************************/
  229. #define CLR_INT0 BIT(0)
  230. #define CLR_INT1 BIT(1)
  231. #define CLR_INT2 BIT(2)
  232. #define CLR_INT3 BIT(3)
  233. #define CLR_INT4 BIT(4)
  234. #define CLR_INT5 BIT(5)
  235. #define SEL_VMM_TBL0 BIT(6)
  236. #define SEL_VMM_TBL1 BIT(7)
  237. #define EN_VMM BIT(8)
  238. #define DATA_INT_EXT INT_0
  239. #define ALL_INT_EXT DATA_INT_EXT
  240. #define NUM_INT_EXT 1
  241. #define UNHANDLED_IRQ_MASK GENMASK(MAX_NUM_INT - 1, NUM_INT_EXT)
  242. #define DATA_INT_CLR CLR_INT0
  243. #define ENABLE_RX_VMM (SEL_VMM_TBL1 | EN_VMM)
  244. #define ENABLE_TX_VMM (SEL_VMM_TBL0 | EN_VMM)
  245. /* time for expiring the completion of cfg packets */
  246. #define WILC_CFG_PKTS_TIMEOUT msecs_to_jiffies(3000)
  247. #define IS_MANAGMEMENT 0x100
  248. #define IS_MANAGMEMENT_CALLBACK 0x080
  249. #define IS_MGMT_STATUS_SUCCES 0x040
  250. #define IS_MGMT_AUTH_PKT 0x010
  251. #define WILC_WID_TYPE GENMASK(15, 12)
  252. #define WILC_VMM_ENTRY_FULL_RETRY 1
  253. /********************************************
  254. *
  255. * Tx/Rx Queue Structure
  256. *
  257. ********************************************/
  258. enum ip_pkt_priority {
  259. AC_VO_Q = 0,
  260. AC_VI_Q = 1,
  261. AC_BE_Q = 2,
  262. AC_BK_Q = 3
  263. };
  264. struct txq_entry_t {
  265. struct list_head list;
  266. int type;
  267. u8 q_num;
  268. int ack_idx;
  269. u8 *buffer;
  270. int buffer_size;
  271. void *priv;
  272. int status;
  273. struct wilc_vif *vif;
  274. void (*tx_complete_func)(void *priv, int status);
  275. };
  276. struct txq_fw_recv_queue_stat {
  277. u8 acm;
  278. u8 count;
  279. };
  280. struct txq_handle {
  281. struct txq_entry_t txq_head;
  282. u16 count;
  283. struct txq_fw_recv_queue_stat fw;
  284. };
  285. struct rxq_entry_t {
  286. struct list_head list;
  287. u8 *buffer;
  288. int buffer_size;
  289. };
  290. /********************************************
  291. *
  292. * Host IF Structure
  293. *
  294. ********************************************/
  295. struct wilc;
  296. struct wilc_hif_func {
  297. int (*hif_init)(struct wilc *wilc, bool resume);
  298. int (*hif_deinit)(struct wilc *wilc);
  299. int (*hif_read_reg)(struct wilc *wilc, u32 addr, u32 *data);
  300. int (*hif_write_reg)(struct wilc *wilc, u32 addr, u32 data);
  301. int (*hif_block_rx)(struct wilc *wilc, u32 addr, u8 *buf, u32 size);
  302. int (*hif_block_tx)(struct wilc *wilc, u32 addr, u8 *buf, u32 size);
  303. int (*hif_read_int)(struct wilc *wilc, u32 *int_status);
  304. int (*hif_clear_int_ext)(struct wilc *wilc, u32 val);
  305. int (*hif_read_size)(struct wilc *wilc, u32 *size);
  306. int (*hif_block_tx_ext)(struct wilc *wilc, u32 addr, u8 *buf, u32 size);
  307. int (*hif_block_rx_ext)(struct wilc *wilc, u32 addr, u8 *buf, u32 size);
  308. int (*hif_sync_ext)(struct wilc *wilc, int nint);
  309. int (*enable_interrupt)(struct wilc *nic);
  310. void (*disable_interrupt)(struct wilc *nic);
  311. int (*hif_reset)(struct wilc *wilc);
  312. bool (*hif_is_init)(struct wilc *wilc);
  313. };
  314. #define WILC_MAX_CFG_FRAME_SIZE 1468
  315. struct tx_complete_data {
  316. int size;
  317. void *buff;
  318. struct sk_buff *skb;
  319. };
  320. struct wilc_cfg_cmd_hdr {
  321. u8 cmd_type;
  322. u8 seq_no;
  323. __le16 total_len;
  324. __le32 driver_handler;
  325. };
  326. struct wilc_cfg_frame {
  327. struct wilc_cfg_cmd_hdr hdr;
  328. u8 frame[WILC_MAX_CFG_FRAME_SIZE];
  329. };
  330. struct wilc_cfg_rsp {
  331. u8 type;
  332. u8 seq_no;
  333. };
  334. struct wilc_vif;
  335. int wilc_wlan_firmware_download(struct wilc *wilc, const u8 *buffer,
  336. u32 buffer_size);
  337. int wilc_wlan_start(struct wilc *wilc);
  338. int wilc_wlan_stop(struct wilc *wilc, struct wilc_vif *vif);
  339. int wilc_wlan_txq_add_net_pkt(struct net_device *dev,
  340. struct tx_complete_data *tx_data, u8 *buffer,
  341. u32 buffer_size,
  342. void (*tx_complete_fn)(void *, int));
  343. int wilc_wlan_handle_txq(struct wilc *wl, u32 *txq_count);
  344. void wilc_handle_isr(struct wilc *wilc);
  345. void wilc_wlan_cleanup(struct net_device *dev);
  346. int wilc_wlan_cfg_set(struct wilc_vif *vif, int start, u16 wid, u8 *buffer,
  347. u32 buffer_size, int commit, u32 drv_handler);
  348. int wilc_wlan_cfg_get(struct wilc_vif *vif, int start, u16 wid, int commit,
  349. u32 drv_handler);
  350. int wilc_wlan_txq_add_mgmt_pkt(struct net_device *dev, void *priv, u8 *buffer,
  351. u32 buffer_size, void (*func)(void *, int));
  352. void wilc_enable_tcp_ack_filter(struct wilc_vif *vif, bool value);
  353. int wilc_wlan_get_num_conn_ifcs(struct wilc *wilc);
  354. netdev_tx_t wilc_mac_xmit(struct sk_buff *skb, struct net_device *dev);
  355. void wilc_wfi_p2p_rx(struct wilc_vif *vif, u8 *buff, u32 size);
  356. bool wilc_wfi_mgmt_frame_rx(struct wilc_vif *vif, u8 *buff, u32 size);
  357. void host_wakeup_notify(struct wilc *wilc);
  358. void host_sleep_notify(struct wilc *wilc);
  359. void chip_allow_sleep(struct wilc *wilc);
  360. void chip_wakeup(struct wilc *wilc);
  361. int wilc_send_config_pkt(struct wilc_vif *vif, u8 mode, struct wid *wids,
  362. u32 count);
  363. int wilc_wlan_init(struct net_device *dev);
  364. u32 wilc_get_chipid(struct wilc *wilc, bool update);
  365. #endif