wlan.h 14 KB

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