hal_rx.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /*
  2. * Copyright (c) 2016-2018 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #include "hal_api.h"
  19. #include "hal_hw_headers.h"
  20. #include "qdf_module.h"
  21. /* TODO: See if the following definition is available in HW headers */
  22. #define HAL_REO_OWNED 4
  23. #define HAL_REO_QUEUE_DESC 8
  24. #define HAL_REO_QUEUE_EXT_DESC 9
  25. /* TODO: Using associated link desc counter 1 for Rx. Check with FW on
  26. * how these counters are assigned
  27. */
  28. #define HAL_RX_LINK_DESC_CNTR 1
  29. /* TODO: Following definition should be from HW headers */
  30. #define HAL_DESC_REO_OWNED 4
  31. /* TODO: Move this to common header file */
  32. static inline void hal_uniform_desc_hdr_setup(uint32_t *desc, uint32_t owner,
  33. uint32_t buffer_type)
  34. {
  35. HAL_DESC_SET_FIELD(desc, UNIFORM_DESCRIPTOR_HEADER_0, OWNER,
  36. owner);
  37. HAL_DESC_SET_FIELD(desc, UNIFORM_DESCRIPTOR_HEADER_0, BUFFER_TYPE,
  38. buffer_type);
  39. }
  40. #ifndef TID_TO_WME_AC
  41. #define WME_AC_BE 0 /* best effort */
  42. #define WME_AC_BK 1 /* background */
  43. #define WME_AC_VI 2 /* video */
  44. #define WME_AC_VO 3 /* voice */
  45. #define TID_TO_WME_AC(_tid) ( \
  46. (((_tid) == 0) || ((_tid) == 3)) ? WME_AC_BE : \
  47. (((_tid) == 1) || ((_tid) == 2)) ? WME_AC_BK : \
  48. (((_tid) == 4) || ((_tid) == 5)) ? WME_AC_VI : \
  49. WME_AC_VO)
  50. #endif
  51. #define HAL_NON_QOS_TID 16
  52. /**
  53. * hal_reo_qdesc_setup - Setup HW REO queue descriptor
  54. *
  55. * @hal_soc: Opaque HAL SOC handle
  56. * @ba_window_size: BlockAck window size
  57. * @start_seq: Starting sequence number
  58. * @hw_qdesc_vaddr: Virtual address of REO queue descriptor memory
  59. * @hw_qdesc_paddr: Physical address of REO queue descriptor memory
  60. * @tid: TID
  61. *
  62. */
  63. void hal_reo_qdesc_setup(void *hal_soc, int tid, uint32_t ba_window_size,
  64. uint32_t start_seq, void *hw_qdesc_vaddr, qdf_dma_addr_t hw_qdesc_paddr,
  65. int pn_type)
  66. {
  67. uint32_t *reo_queue_desc = (uint32_t *)hw_qdesc_vaddr;
  68. uint32_t *reo_queue_ext_desc;
  69. uint32_t reg_val;
  70. uint32_t pn_enable;
  71. uint32_t pn_size = 0;
  72. qdf_mem_zero(hw_qdesc_vaddr, sizeof(struct rx_reo_queue));
  73. hal_uniform_desc_hdr_setup(reo_queue_desc, HAL_DESC_REO_OWNED,
  74. HAL_REO_QUEUE_DESC);
  75. /* Fixed pattern in reserved bits for debugging */
  76. HAL_DESC_SET_FIELD(reo_queue_desc, UNIFORM_DESCRIPTOR_HEADER_0,
  77. RESERVED_0A, 0xDDBEEF);
  78. /* This a just a SW meta data and will be copied to REO destination
  79. * descriptors indicated by hardware.
  80. * TODO: Setting TID in this field. See if we should set something else.
  81. */
  82. HAL_DESC_SET_FIELD(reo_queue_desc, RX_REO_QUEUE_1,
  83. RECEIVE_QUEUE_NUMBER, tid);
  84. HAL_DESC_SET_FIELD(reo_queue_desc, RX_REO_QUEUE_2,
  85. VLD, 1);
  86. HAL_DESC_SET_FIELD(reo_queue_desc, RX_REO_QUEUE_2,
  87. ASSOCIATED_LINK_DESCRIPTOR_COUNTER, HAL_RX_LINK_DESC_CNTR);
  88. /*
  89. * Fields DISABLE_DUPLICATE_DETECTION and SOFT_REORDER_ENABLE will be 0
  90. */
  91. reg_val = TID_TO_WME_AC(tid);
  92. HAL_DESC_SET_FIELD(reo_queue_desc, RX_REO_QUEUE_2, AC, reg_val);
  93. if (ba_window_size < 1)
  94. ba_window_size = 1;
  95. /* Set RTY bit for non-BA case. Duplicate detection is currently not
  96. * done by HW in non-BA case if RTY bit is not set.
  97. * TODO: This is a temporary War and should be removed once HW fix is
  98. * made to check and discard duplicates even if RTY bit is not set.
  99. */
  100. if (ba_window_size == 1)
  101. HAL_DESC_SET_FIELD(reo_queue_desc, RX_REO_QUEUE_2, RTY, 1);
  102. HAL_DESC_SET_FIELD(reo_queue_desc, RX_REO_QUEUE_2, BA_WINDOW_SIZE,
  103. ba_window_size - 1);
  104. switch (pn_type) {
  105. case HAL_PN_WPA:
  106. pn_enable = 1;
  107. pn_size = PN_SIZE_48;
  108. case HAL_PN_WAPI_EVEN:
  109. case HAL_PN_WAPI_UNEVEN:
  110. pn_enable = 1;
  111. pn_size = PN_SIZE_128;
  112. default:
  113. pn_enable = 0;
  114. }
  115. HAL_DESC_SET_FIELD(reo_queue_desc, RX_REO_QUEUE_2, PN_CHECK_NEEDED,
  116. pn_enable);
  117. if (pn_type == HAL_PN_WAPI_EVEN)
  118. HAL_DESC_SET_FIELD(reo_queue_desc, RX_REO_QUEUE_2,
  119. PN_SHALL_BE_EVEN, 1);
  120. else if (pn_type == HAL_PN_WAPI_UNEVEN)
  121. HAL_DESC_SET_FIELD(reo_queue_desc, RX_REO_QUEUE_2,
  122. PN_SHALL_BE_UNEVEN, 1);
  123. HAL_DESC_SET_FIELD(reo_queue_desc, RX_REO_QUEUE_2, PN_HANDLING_ENABLE,
  124. pn_enable);
  125. HAL_DESC_SET_FIELD(reo_queue_desc, RX_REO_QUEUE_2, PN_SIZE,
  126. pn_size);
  127. /* TODO: Check if RX_REO_QUEUE_2_IGNORE_AMPDU_FLAG need to be set
  128. * based on BA window size and/or AMPDU capabilities
  129. */
  130. HAL_DESC_SET_FIELD(reo_queue_desc, RX_REO_QUEUE_2,
  131. IGNORE_AMPDU_FLAG, 1);
  132. if (start_seq <= 0xfff)
  133. HAL_DESC_SET_FIELD(reo_queue_desc, RX_REO_QUEUE_3, SSN,
  134. start_seq);
  135. /* TODO: SVLD should be set to 1 if a valid SSN is received in ADDBA,
  136. * but REO is not delivering packets if we set it to 1. Need to enable
  137. * this once the issue is resolved */
  138. HAL_DESC_SET_FIELD(reo_queue_desc, RX_REO_QUEUE_3, SVLD, 0);
  139. /* TODO: Check if we should set start PN for WAPI */
  140. #ifdef notyet
  141. /* Setup first queue extension if BA window size is more than 1 */
  142. if (ba_window_size > 1) {
  143. reo_queue_ext_desc =
  144. (uint32_t *)(((struct rx_reo_queue *)reo_queue_desc) +
  145. 1);
  146. qdf_mem_zero(reo_queue_ext_desc,
  147. sizeof(struct rx_reo_queue_ext));
  148. hal_uniform_desc_hdr_setup(reo_queue_ext_desc,
  149. HAL_DESC_REO_OWNED, HAL_REO_QUEUE_EXT_DESC);
  150. }
  151. /* Setup second queue extension if BA window size is more than 105 */
  152. if (ba_window_size > 105) {
  153. reo_queue_ext_desc = (uint32_t *)
  154. (((struct rx_reo_queue_ext *)reo_queue_ext_desc) + 1);
  155. qdf_mem_zero(reo_queue_ext_desc,
  156. sizeof(struct rx_reo_queue_ext));
  157. hal_uniform_desc_hdr_setup(reo_queue_ext_desc,
  158. HAL_DESC_REO_OWNED, HAL_REO_QUEUE_EXT_DESC);
  159. }
  160. /* Setup third queue extension if BA window size is more than 210 */
  161. if (ba_window_size > 210) {
  162. reo_queue_ext_desc = (uint32_t *)
  163. (((struct rx_reo_queue_ext *)reo_queue_ext_desc) + 1);
  164. qdf_mem_zero(reo_queue_ext_desc,
  165. sizeof(struct rx_reo_queue_ext));
  166. hal_uniform_desc_hdr_setup(reo_queue_ext_desc,
  167. HAL_DESC_REO_OWNED, HAL_REO_QUEUE_EXT_DESC);
  168. }
  169. #else
  170. /* TODO: HW queue descriptors are currently allocated for max BA
  171. * window size for all QOS TIDs so that same descriptor can be used
  172. * later when ADDBA request is recevied. This should be changed to
  173. * allocate HW queue descriptors based on BA window size being
  174. * negotiated (0 for non BA cases), and reallocate when BA window
  175. * size changes and also send WMI message to FW to change the REO
  176. * queue descriptor in Rx peer entry as part of dp_rx_tid_update.
  177. */
  178. if (tid != HAL_NON_QOS_TID) {
  179. reo_queue_ext_desc = (uint32_t *)
  180. (((struct rx_reo_queue *)reo_queue_desc) + 1);
  181. qdf_mem_zero(reo_queue_ext_desc, 3 *
  182. sizeof(struct rx_reo_queue_ext));
  183. /* Initialize first reo queue extension descriptor */
  184. hal_uniform_desc_hdr_setup(reo_queue_ext_desc,
  185. HAL_DESC_REO_OWNED, HAL_REO_QUEUE_EXT_DESC);
  186. /* Fixed pattern in reserved bits for debugging */
  187. HAL_DESC_SET_FIELD(reo_queue_ext_desc,
  188. UNIFORM_DESCRIPTOR_HEADER_0, RESERVED_0A, 0xADBEEF);
  189. /* Initialize second reo queue extension descriptor */
  190. reo_queue_ext_desc = (uint32_t *)
  191. (((struct rx_reo_queue_ext *)reo_queue_ext_desc) + 1);
  192. hal_uniform_desc_hdr_setup(reo_queue_ext_desc,
  193. HAL_DESC_REO_OWNED, HAL_REO_QUEUE_EXT_DESC);
  194. /* Fixed pattern in reserved bits for debugging */
  195. HAL_DESC_SET_FIELD(reo_queue_ext_desc,
  196. UNIFORM_DESCRIPTOR_HEADER_0, RESERVED_0A, 0xBDBEEF);
  197. /* Initialize third reo queue extension descriptor */
  198. reo_queue_ext_desc = (uint32_t *)
  199. (((struct rx_reo_queue_ext *)reo_queue_ext_desc) + 1);
  200. hal_uniform_desc_hdr_setup(reo_queue_ext_desc,
  201. HAL_DESC_REO_OWNED, HAL_REO_QUEUE_EXT_DESC);
  202. /* Fixed pattern in reserved bits for debugging */
  203. HAL_DESC_SET_FIELD(reo_queue_ext_desc,
  204. UNIFORM_DESCRIPTOR_HEADER_0, RESERVED_0A, 0xCDBEEF);
  205. }
  206. #endif
  207. }
  208. qdf_export_symbol(hal_reo_qdesc_setup);
  209. /**
  210. * hal_reo_setup - Initialize HW REO block
  211. *
  212. * @hal_soc: Opaque HAL SOC handle
  213. * @reo_params: parameters needed by HAL for REO config
  214. */
  215. void hal_reo_setup(void *hal_soc,
  216. struct hal_reo_params *reo_params)
  217. {
  218. struct hal_soc *soc = (struct hal_soc *)hal_soc;
  219. HAL_REG_WRITE(soc, HWIO_REO_R0_GENERAL_ENABLE_ADDR(
  220. SEQ_WCSS_UMAC_REO_REG_OFFSET),
  221. HAL_SM(HWIO_REO_R0_GENERAL_ENABLE,
  222. FRAGMENT_DEST_RING, reo_params->frag_dst_ring) |
  223. HAL_SM(HWIO_REO_R0_GENERAL_ENABLE, AGING_LIST_ENABLE, 1) |
  224. HAL_SM(HWIO_REO_R0_GENERAL_ENABLE, AGING_FLUSH_ENABLE, 1));
  225. /* Other ring enable bits and REO_ENABLE will be set by FW */
  226. /* TODO: Setup destination ring mapping if enabled */
  227. /* TODO: Error destination ring setting is left to default.
  228. * Default setting is to send all errors to release ring.
  229. */
  230. HAL_REG_WRITE(soc,
  231. HWIO_REO_R0_AGING_THRESHOLD_IX_0_ADDR(
  232. SEQ_WCSS_UMAC_REO_REG_OFFSET),
  233. HAL_DEFAULT_REO_TIMEOUT_MS * 1000);
  234. HAL_REG_WRITE(soc,
  235. HWIO_REO_R0_AGING_THRESHOLD_IX_1_ADDR(
  236. SEQ_WCSS_UMAC_REO_REG_OFFSET),
  237. (HAL_DEFAULT_REO_TIMEOUT_MS * 1000));
  238. HAL_REG_WRITE(soc,
  239. HWIO_REO_R0_AGING_THRESHOLD_IX_2_ADDR(
  240. SEQ_WCSS_UMAC_REO_REG_OFFSET),
  241. (HAL_DEFAULT_REO_TIMEOUT_MS * 1000));
  242. HAL_REG_WRITE(soc,
  243. HWIO_REO_R0_AGING_THRESHOLD_IX_3_ADDR(
  244. SEQ_WCSS_UMAC_REO_REG_OFFSET),
  245. (HAL_DEFAULT_REO_TIMEOUT_MS * 1000));
  246. /*
  247. * When hash based routing is enabled, routing of the rx packet
  248. * is done based on the following value: 1 _ _ _ _ The last 4
  249. * bits are based on hash[3:0]. This means the possible values
  250. * are 0x10 to 0x1f. This value is used to look-up the
  251. * ring ID configured in Destination_Ring_Ctrl_IX_* register.
  252. * The Destination_Ring_Ctrl_IX_2 and Destination_Ring_Ctrl_IX_3
  253. * registers need to be configured to set-up the 16 entries to
  254. * map the hash values to a ring number. There are 3 bits per
  255. * hash entry – which are mapped as follows:
  256. * 0: TCL, 1:SW1, 2:SW2, * 3:SW3, 4:SW4, 5:Release, 6:FW(WIFI),
  257. * 7: NOT_USED.
  258. */
  259. if (reo_params->rx_hash_enabled) {
  260. HAL_REG_WRITE(soc,
  261. HWIO_REO_R0_DESTINATION_RING_CTRL_IX_2_ADDR(
  262. SEQ_WCSS_UMAC_REO_REG_OFFSET),
  263. reo_params->remap1);
  264. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  265. FL("HWIO_REO_R0_DESTINATION_RING_CTRL_IX_2_ADDR 0x%x\n"),
  266. HAL_REG_READ(soc,
  267. HWIO_REO_R0_DESTINATION_RING_CTRL_IX_2_ADDR(
  268. SEQ_WCSS_UMAC_REO_REG_OFFSET)));
  269. HAL_REG_WRITE(soc,
  270. HWIO_REO_R0_DESTINATION_RING_CTRL_IX_3_ADDR(
  271. SEQ_WCSS_UMAC_REO_REG_OFFSET),
  272. reo_params->remap2);
  273. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  274. FL("HWIO_REO_R0_DESTINATION_RING_CTRL_IX_3_ADDR 0x%x\n"),
  275. HAL_REG_READ(soc,
  276. HWIO_REO_R0_DESTINATION_RING_CTRL_IX_3_ADDR(
  277. SEQ_WCSS_UMAC_REO_REG_OFFSET)));
  278. }
  279. /* TODO: Check if the following registers shoould be setup by host:
  280. * AGING_CONTROL
  281. * HIGH_MEMORY_THRESHOLD
  282. * GLOBAL_LINK_DESC_COUNT_THRESH_IX_0[1,2]
  283. * GLOBAL_LINK_DESC_COUNT_CTRL
  284. */
  285. }
  286. qdf_export_symbol(hal_reo_setup);