hal_rx.c 10 KB

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