hal_rx.c 8.8 KB

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