dxe.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /*
  2. * Copyright (c) 2013 Eugene Krasnikov <k.eugene.e@gmail.com>
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  11. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  13. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef _DXE_H_
  17. #define _DXE_H_
  18. #include "wcn36xx.h"
  19. /*
  20. TX_LOW = DMA0
  21. TX_HIGH = DMA4
  22. RX_LOW = DMA1
  23. RX_HIGH = DMA3
  24. H2H_TEST_RX_TX = DMA2
  25. */
  26. /* DXE registers */
  27. #define WCN36XX_DXE_MEM_REG 0x202000
  28. #define WCN36XX_DXE_CCU_INT 0xA0011
  29. #define WCN36XX_DXE_REG_CCU_INT_3660 0x200b10
  30. #define WCN36XX_DXE_REG_CCU_INT_3680 0x2050dc
  31. /* TODO This must calculated properly but not hardcoded */
  32. #define WCN36XX_DXE_CTRL_TX_L 0x328a44
  33. #define WCN36XX_DXE_CTRL_TX_H 0x32ce44
  34. #define WCN36XX_DXE_CTRL_RX_L 0x12ad2f
  35. #define WCN36XX_DXE_CTRL_RX_H 0x12d12f
  36. #define WCN36XX_DXE_CTRL_TX_H_BD 0x30ce45
  37. #define WCN36XX_DXE_CTRL_TX_H_SKB 0x32ce4d
  38. #define WCN36XX_DXE_CTRL_TX_L_BD 0x308a45
  39. #define WCN36XX_DXE_CTRL_TX_L_SKB 0x328a4d
  40. /* TODO This must calculated properly but not hardcoded */
  41. #define WCN36XX_DXE_WQ_TX_L 0x17
  42. #define WCN36XX_DXE_WQ_TX_H 0x17
  43. #define WCN36XX_DXE_WQ_RX_L 0xB
  44. #define WCN36XX_DXE_WQ_RX_H 0x4
  45. /* DXE descriptor control filed */
  46. #define WCN36XX_DXE_CTRL_VALID_MASK (0x00000001)
  47. /* TODO This must calculated properly but not hardcoded */
  48. /* DXE default control register values */
  49. #define WCN36XX_DXE_CH_DEFAULT_CTL_RX_L 0x847EAD2F
  50. #define WCN36XX_DXE_CH_DEFAULT_CTL_RX_H 0x84FED12F
  51. #define WCN36XX_DXE_CH_DEFAULT_CTL_TX_H 0x853ECF4D
  52. #define WCN36XX_DXE_CH_DEFAULT_CTL_TX_L 0x843e8b4d
  53. /* Common DXE registers */
  54. #define WCN36XX_DXE_MEM_CSR (WCN36XX_DXE_MEM_REG + 0x00)
  55. #define WCN36XX_DXE_REG_CSR_RESET (WCN36XX_DXE_MEM_REG + 0x00)
  56. #define WCN36XX_DXE_ENCH_ADDR (WCN36XX_DXE_MEM_REG + 0x04)
  57. #define WCN36XX_DXE_REG_CH_EN (WCN36XX_DXE_MEM_REG + 0x08)
  58. #define WCN36XX_DXE_REG_CH_DONE (WCN36XX_DXE_MEM_REG + 0x0C)
  59. #define WCN36XX_DXE_REG_CH_ERR (WCN36XX_DXE_MEM_REG + 0x10)
  60. #define WCN36XX_DXE_INT_MASK_REG (WCN36XX_DXE_MEM_REG + 0x18)
  61. #define WCN36XX_DXE_INT_SRC_RAW_REG (WCN36XX_DXE_MEM_REG + 0x20)
  62. /* #define WCN36XX_DXE_INT_CH6_MASK 0x00000040 */
  63. /* #define WCN36XX_DXE_INT_CH5_MASK 0x00000020 */
  64. #define WCN36XX_DXE_INT_CH4_MASK 0x00000010
  65. #define WCN36XX_DXE_INT_CH3_MASK 0x00000008
  66. /* #define WCN36XX_DXE_INT_CH2_MASK 0x00000004 */
  67. #define WCN36XX_DXE_INT_CH1_MASK 0x00000002
  68. #define WCN36XX_DXE_INT_CH0_MASK 0x00000001
  69. #define WCN36XX_DXE_0_INT_CLR (WCN36XX_DXE_MEM_REG + 0x30)
  70. #define WCN36XX_DXE_0_INT_ED_CLR (WCN36XX_DXE_MEM_REG + 0x34)
  71. #define WCN36XX_DXE_0_INT_DONE_CLR (WCN36XX_DXE_MEM_REG + 0x38)
  72. #define WCN36XX_DXE_0_INT_ERR_CLR (WCN36XX_DXE_MEM_REG + 0x3C)
  73. #define WCN36XX_DXE_0_CH0_STATUS (WCN36XX_DXE_MEM_REG + 0x404)
  74. #define WCN36XX_DXE_0_CH1_STATUS (WCN36XX_DXE_MEM_REG + 0x444)
  75. #define WCN36XX_DXE_0_CH2_STATUS (WCN36XX_DXE_MEM_REG + 0x484)
  76. #define WCN36XX_DXE_0_CH3_STATUS (WCN36XX_DXE_MEM_REG + 0x4C4)
  77. #define WCN36XX_DXE_0_CH4_STATUS (WCN36XX_DXE_MEM_REG + 0x504)
  78. #define WCN36XX_DXE_REG_RESET 0x5c89
  79. /* Temporary BMU Workqueue 4 */
  80. #define WCN36XX_DXE_BMU_WQ_RX_LOW 0xB
  81. #define WCN36XX_DXE_BMU_WQ_RX_HIGH 0x4
  82. /* DMA channel offset */
  83. #define WCN36XX_DXE_TX_LOW_OFFSET 0x400
  84. #define WCN36XX_DXE_TX_HIGH_OFFSET 0x500
  85. #define WCN36XX_DXE_RX_LOW_OFFSET 0x440
  86. #define WCN36XX_DXE_RX_HIGH_OFFSET 0x4C0
  87. /* Address of the next DXE descriptor */
  88. #define WCN36XX_DXE_CH_NEXT_DESC_ADDR 0x001C
  89. #define WCN36XX_DXE_CH_NEXT_DESC_ADDR_TX_L (WCN36XX_DXE_MEM_REG + \
  90. WCN36XX_DXE_TX_LOW_OFFSET + \
  91. WCN36XX_DXE_CH_NEXT_DESC_ADDR)
  92. #define WCN36XX_DXE_CH_NEXT_DESC_ADDR_TX_H (WCN36XX_DXE_MEM_REG + \
  93. WCN36XX_DXE_TX_HIGH_OFFSET + \
  94. WCN36XX_DXE_CH_NEXT_DESC_ADDR)
  95. #define WCN36XX_DXE_CH_NEXT_DESC_ADDR_RX_L (WCN36XX_DXE_MEM_REG + \
  96. WCN36XX_DXE_RX_LOW_OFFSET + \
  97. WCN36XX_DXE_CH_NEXT_DESC_ADDR)
  98. #define WCN36XX_DXE_CH_NEXT_DESC_ADDR_RX_H (WCN36XX_DXE_MEM_REG + \
  99. WCN36XX_DXE_RX_HIGH_OFFSET + \
  100. WCN36XX_DXE_CH_NEXT_DESC_ADDR)
  101. /* DXE Descriptor source address */
  102. #define WCN36XX_DXE_CH_SRC_ADDR 0x000C
  103. #define WCN36XX_DXE_CH_SRC_ADDR_RX_L (WCN36XX_DXE_MEM_REG + \
  104. WCN36XX_DXE_RX_LOW_OFFSET + \
  105. WCN36XX_DXE_CH_SRC_ADDR)
  106. #define WCN36XX_DXE_CH_SRC_ADDR_RX_H (WCN36XX_DXE_MEM_REG + \
  107. WCN36XX_DXE_RX_HIGH_OFFSET + \
  108. WCN36XX_DXE_CH_SRC_ADDR)
  109. /* DXE Descriptor address destination address */
  110. #define WCN36XX_DXE_CH_DEST_ADDR 0x0014
  111. #define WCN36XX_DXE_CH_DEST_ADDR_TX_L (WCN36XX_DXE_MEM_REG + \
  112. WCN36XX_DXE_TX_LOW_OFFSET + \
  113. WCN36XX_DXE_CH_DEST_ADDR)
  114. #define WCN36XX_DXE_CH_DEST_ADDR_TX_H (WCN36XX_DXE_MEM_REG + \
  115. WCN36XX_DXE_TX_HIGH_OFFSET + \
  116. WCN36XX_DXE_CH_DEST_ADDR)
  117. #define WCN36XX_DXE_CH_DEST_ADDR_RX_L (WCN36XX_DXE_MEM_REG + \
  118. WCN36XX_DXE_RX_LOW_OFFSET + \
  119. WCN36XX_DXE_CH_DEST_ADDR)
  120. #define WCN36XX_DXE_CH_DEST_ADDR_RX_H (WCN36XX_DXE_MEM_REG + \
  121. WCN36XX_DXE_RX_HIGH_OFFSET + \
  122. WCN36XX_DXE_CH_DEST_ADDR)
  123. /* Interrupt status */
  124. #define WCN36XX_DXE_CH_STATUS_REG_ADDR 0x0004
  125. #define WCN36XX_DXE_CH_STATUS_REG_ADDR_TX_L (WCN36XX_DXE_MEM_REG + \
  126. WCN36XX_DXE_TX_LOW_OFFSET + \
  127. WCN36XX_DXE_CH_STATUS_REG_ADDR)
  128. #define WCN36XX_DXE_CH_STATUS_REG_ADDR_TX_H (WCN36XX_DXE_MEM_REG + \
  129. WCN36XX_DXE_TX_HIGH_OFFSET + \
  130. WCN36XX_DXE_CH_STATUS_REG_ADDR)
  131. #define WCN36XX_DXE_CH_STATUS_REG_ADDR_RX_L (WCN36XX_DXE_MEM_REG + \
  132. WCN36XX_DXE_RX_LOW_OFFSET + \
  133. WCN36XX_DXE_CH_STATUS_REG_ADDR)
  134. #define WCN36XX_DXE_CH_STATUS_REG_ADDR_RX_H (WCN36XX_DXE_MEM_REG + \
  135. WCN36XX_DXE_RX_HIGH_OFFSET + \
  136. WCN36XX_DXE_CH_STATUS_REG_ADDR)
  137. /* DXE default control register */
  138. #define WCN36XX_DXE_REG_CTL_RX_L (WCN36XX_DXE_MEM_REG + \
  139. WCN36XX_DXE_RX_LOW_OFFSET)
  140. #define WCN36XX_DXE_REG_CTL_RX_H (WCN36XX_DXE_MEM_REG + \
  141. WCN36XX_DXE_RX_HIGH_OFFSET)
  142. #define WCN36XX_DXE_REG_CTL_TX_H (WCN36XX_DXE_MEM_REG + \
  143. WCN36XX_DXE_TX_HIGH_OFFSET)
  144. #define WCN36XX_DXE_REG_CTL_TX_L (WCN36XX_DXE_MEM_REG + \
  145. WCN36XX_DXE_TX_LOW_OFFSET)
  146. #define WCN36XX_SMSM_WLAN_TX_ENABLE 0x00000400
  147. #define WCN36XX_SMSM_WLAN_TX_RINGS_EMPTY 0x00000200
  148. /* Interrupt control channel mask */
  149. #define WCN36XX_INT_MASK_CHAN_TX_L 0x00000001
  150. #define WCN36XX_INT_MASK_CHAN_RX_L 0x00000002
  151. #define WCN36XX_INT_MASK_CHAN_RX_H 0x00000008
  152. #define WCN36XX_INT_MASK_CHAN_TX_H 0x00000010
  153. #define WCN36XX_BD_CHUNK_SIZE 128
  154. #define WCN36XX_PKT_SIZE 0xF20
  155. enum wcn36xx_dxe_ch_type {
  156. WCN36XX_DXE_CH_TX_L,
  157. WCN36XX_DXE_CH_TX_H,
  158. WCN36XX_DXE_CH_RX_L,
  159. WCN36XX_DXE_CH_RX_H
  160. };
  161. /* amount of descriptors per channel */
  162. enum wcn36xx_dxe_ch_desc_num {
  163. WCN36XX_DXE_CH_DESC_NUMB_TX_L = 128,
  164. WCN36XX_DXE_CH_DESC_NUMB_TX_H = 10,
  165. WCN36XX_DXE_CH_DESC_NUMB_RX_L = 512,
  166. WCN36XX_DXE_CH_DESC_NUMB_RX_H = 40
  167. };
  168. /**
  169. * struct wcn36xx_dxe_desc - describes descriptor of one DXE buffer
  170. *
  171. * @ctrl: is a union that consists of following bits:
  172. * union {
  173. * u32 valid :1; //0 = DMA stop, 1 = DMA continue with this
  174. * //descriptor
  175. * u32 transfer_type :2; //0 = Host to Host space
  176. * u32 eop :1; //End of Packet
  177. * u32 bd_handling :1; //if transferType = Host to BMU, then 0
  178. * // means first 128 bytes contain BD, and 1
  179. * // means create new empty BD
  180. * u32 siq :1; // SIQ
  181. * u32 diq :1; // DIQ
  182. * u32 pdu_rel :1; //0 = don't release BD and PDUs when done,
  183. * // 1 = release them
  184. * u32 bthld_sel :4; //BMU Threshold Select
  185. * u32 prio :3; //Specifies the priority level to use for
  186. * // the transfer
  187. * u32 stop_channel :1; //1 = DMA stops processing further, channel
  188. * //requires re-enabling after this
  189. * u32 intr :1; //Interrupt on Descriptor Done
  190. * u32 rsvd :1; //reserved
  191. * u32 size :14;//14 bits used - ignored for BMU transfers,
  192. * //only used for host to host transfers?
  193. * } ctrl;
  194. */
  195. struct wcn36xx_dxe_desc {
  196. u32 ctrl;
  197. u32 fr_len;
  198. u32 src_addr_l;
  199. u32 dst_addr_l;
  200. u32 phy_next_l;
  201. u32 src_addr_h;
  202. u32 dst_addr_h;
  203. u32 phy_next_h;
  204. } __packed;
  205. /* DXE Control block */
  206. struct wcn36xx_dxe_ctl {
  207. struct wcn36xx_dxe_ctl *next;
  208. struct wcn36xx_dxe_desc *desc;
  209. unsigned int desc_phy_addr;
  210. int ctl_blk_order;
  211. struct sk_buff *skb;
  212. spinlock_t skb_lock;
  213. void *bd_cpu_addr;
  214. dma_addr_t bd_phy_addr;
  215. };
  216. struct wcn36xx_dxe_ch {
  217. spinlock_t lock; /* protects head/tail ptrs */
  218. enum wcn36xx_dxe_ch_type ch_type;
  219. void *cpu_addr;
  220. dma_addr_t dma_addr;
  221. enum wcn36xx_dxe_ch_desc_num desc_num;
  222. /* DXE control block ring */
  223. struct wcn36xx_dxe_ctl *head_blk_ctl;
  224. struct wcn36xx_dxe_ctl *tail_blk_ctl;
  225. /* DXE channel specific configs */
  226. u32 dxe_wq;
  227. u32 ctrl_bd;
  228. u32 ctrl_skb;
  229. u32 reg_ctrl;
  230. u32 def_ctrl;
  231. };
  232. /* Memory Pool for BD headers */
  233. struct wcn36xx_dxe_mem_pool {
  234. int chunk_size;
  235. void *virt_addr;
  236. dma_addr_t phy_addr;
  237. };
  238. struct wcn36xx_vif;
  239. int wcn36xx_dxe_allocate_mem_pools(struct wcn36xx *wcn);
  240. void wcn36xx_dxe_free_mem_pools(struct wcn36xx *wcn);
  241. void wcn36xx_dxe_rx_frame(struct wcn36xx *wcn);
  242. int wcn36xx_dxe_alloc_ctl_blks(struct wcn36xx *wcn);
  243. void wcn36xx_dxe_free_ctl_blks(struct wcn36xx *wcn);
  244. int wcn36xx_dxe_init(struct wcn36xx *wcn);
  245. void wcn36xx_dxe_deinit(struct wcn36xx *wcn);
  246. int wcn36xx_dxe_init_channels(struct wcn36xx *wcn);
  247. int wcn36xx_dxe_tx_frame(struct wcn36xx *wcn,
  248. struct wcn36xx_vif *vif_priv,
  249. struct sk_buff *skb,
  250. bool is_low);
  251. void wcn36xx_dxe_tx_ack_ind(struct wcn36xx *wcn, u32 status);
  252. void *wcn36xx_dxe_get_next_bd(struct wcn36xx *wcn, bool is_low);
  253. #endif /* _DXE_H_ */