hal_rx.c 11 KB

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