hal_be_generic_api.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  1. /*
  2. * Copyright (c) 2016-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for
  6. * any purpose with or without fee is hereby granted, provided that the
  7. * above copyright notice and this permission notice appear in all
  8. * copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  13. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  14. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  15. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. * PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. #include <qdf_module.h>
  20. #include "hal_be_api.h"
  21. #include "hal_be_hw_headers.h"
  22. #include "hal_be_reo.h"
  23. #include "hal_tx.h" //HAL_SET_FLD
  24. #include "hal_be_rx.h" //HAL_RX_BUF_RBM_GET
  25. /*
  26. * The 4 bits REO destination ring value is defined as: 0: TCL
  27. * 1:SW1 2:SW2 3:SW3 4:SW4 5:Release 6:FW(WIFI) 7:SW5
  28. * 8:SW6 9:SW7 10:SW8 11: NOT_USED.
  29. *
  30. */
  31. uint32_t reo_dest_ring_remap[] = {REO_REMAP_SW1, REO_REMAP_SW2,
  32. REO_REMAP_SW3, REO_REMAP_SW4,
  33. REO_REMAP_SW5, REO_REMAP_SW6,
  34. REO_REMAP_SW7, REO_REMAP_SW8};
  35. #if defined(QDF_BIG_ENDIAN_MACHINE)
  36. void hal_setup_reo_swap(struct hal_soc *soc)
  37. {
  38. uint32_t reg_val;
  39. reg_val = HAL_REG_READ(soc, HWIO_REO_R0_CACHE_CTL_CONFIG_ADDR(
  40. REO_REG_REG_BASE));
  41. reg_val |= HAL_SM(HWIO_REO_R0_CACHE_CTL_CONFIG, WRITE_STRUCT_SWAP, 1);
  42. reg_val |= HAL_SM(HWIO_REO_R0_CACHE_CTL_CONFIG, READ_STRUCT_SWAP, 1);
  43. HAL_REG_WRITE(soc, HWIO_REO_R0_CACHE_CTL_CONFIG_ADDR(
  44. REO_REG_REG_BASE), reg_val);
  45. }
  46. #else
  47. void hal_setup_reo_swap(struct hal_soc *soc)
  48. {
  49. }
  50. #endif
  51. /**
  52. * hal_tx_init_data_ring_be() - Initialize all the TCL Descriptors in SRNG
  53. * @hal_soc_hdl: Handle to HAL SoC structure
  54. * @hal_srng: Handle to HAL SRNG structure
  55. *
  56. * Return: none
  57. */
  58. static void
  59. hal_tx_init_data_ring_be(hal_soc_handle_t hal_soc_hdl,
  60. hal_ring_handle_t hal_ring_hdl)
  61. {
  62. }
  63. void hal_reo_setup_generic_be(struct hal_soc *soc, void *reoparams)
  64. {
  65. uint32_t reg_val;
  66. struct hal_reo_params *reo_params = (struct hal_reo_params *)reoparams;
  67. reg_val = HAL_REG_READ(soc, HWIO_REO_R0_GENERAL_ENABLE_ADDR(
  68. REO_REG_REG_BASE));
  69. hal_reo_config(soc, reg_val, reo_params);
  70. /* Other ring enable bits and REO_ENABLE will be set by FW */
  71. /* TODO: Setup destination ring mapping if enabled */
  72. /* TODO: Error destination ring setting is left to default.
  73. * Default setting is to send all errors to release ring.
  74. */
  75. /* Set the reo descriptor swap bits in case of BIG endian platform */
  76. hal_setup_reo_swap(soc);
  77. HAL_REG_WRITE(soc,
  78. HWIO_REO_R0_AGING_THRESHOLD_IX_0_ADDR(REO_REG_REG_BASE),
  79. HAL_DEFAULT_BE_BK_VI_REO_TIMEOUT_MS * 1000);
  80. HAL_REG_WRITE(soc,
  81. HWIO_REO_R0_AGING_THRESHOLD_IX_1_ADDR(REO_REG_REG_BASE),
  82. (HAL_DEFAULT_BE_BK_VI_REO_TIMEOUT_MS * 1000));
  83. HAL_REG_WRITE(soc,
  84. HWIO_REO_R0_AGING_THRESHOLD_IX_2_ADDR(REO_REG_REG_BASE),
  85. (HAL_DEFAULT_BE_BK_VI_REO_TIMEOUT_MS * 1000));
  86. HAL_REG_WRITE(soc,
  87. HWIO_REO_R0_AGING_THRESHOLD_IX_3_ADDR(REO_REG_REG_BASE),
  88. (HAL_DEFAULT_VO_REO_TIMEOUT_MS * 1000));
  89. /*
  90. * When hash based routing is enabled, routing of the rx packet
  91. * is done based on the following value: 1 _ _ _ _ The last 4
  92. * bits are based on hash[3:0]. This means the possible values
  93. * are 0x10 to 0x1f. This value is used to look-up the
  94. * ring ID configured in Destination_Ring_Ctrl_IX_* register.
  95. * The Destination_Ring_Ctrl_IX_2 and Destination_Ring_Ctrl_IX_3
  96. * registers need to be configured to set-up the 16 entries to
  97. * map the hash values to a ring number. There are 3 bits per
  98. * hash entry – which are mapped as follows:
  99. * 0: TCL, 1:SW1, 2:SW2, * 3:SW3, 4:SW4, 5:Release, 6:FW(WIFI),
  100. * 7: NOT_USED.
  101. */
  102. if (reo_params->rx_hash_enabled) {
  103. HAL_REG_WRITE(soc,
  104. HWIO_REO_R0_DESTINATION_RING_CTRL_IX_2_ADDR(
  105. REO_REG_REG_BASE),
  106. reo_params->remap1);
  107. hal_debug("HWIO_REO_R0_DESTINATION_RING_CTRL_IX_2_ADDR 0x%x",
  108. HAL_REG_READ(soc,
  109. HWIO_REO_R0_DESTINATION_RING_CTRL_IX_2_ADDR(
  110. REO_REG_REG_BASE)));
  111. HAL_REG_WRITE(soc,
  112. HWIO_REO_R0_DESTINATION_RING_CTRL_IX_3_ADDR(
  113. REO_REG_REG_BASE),
  114. reo_params->remap2);
  115. hal_debug("HWIO_REO_R0_DESTINATION_RING_CTRL_IX_3_ADDR 0x%x",
  116. HAL_REG_READ(soc,
  117. HWIO_REO_R0_DESTINATION_RING_CTRL_IX_3_ADDR(
  118. REO_REG_REG_BASE)));
  119. }
  120. /* TODO: Check if the following registers shoould be setup by host:
  121. * AGING_CONTROL
  122. * HIGH_MEMORY_THRESHOLD
  123. * GLOBAL_LINK_DESC_COUNT_THRESH_IX_0[1,2]
  124. * GLOBAL_LINK_DESC_COUNT_CTRL
  125. */
  126. }
  127. void hal_set_link_desc_addr_be(void *desc, uint32_t cookie,
  128. qdf_dma_addr_t link_desc_paddr,
  129. uint8_t bm_id)
  130. {
  131. uint32_t *buf_addr = (uint32_t *)desc;
  132. HAL_DESC_SET_FIELD(buf_addr, BUFFER_ADDR_INFO, BUFFER_ADDR_31_0,
  133. link_desc_paddr & 0xffffffff);
  134. HAL_DESC_SET_FIELD(buf_addr, BUFFER_ADDR_INFO, BUFFER_ADDR_39_32,
  135. (uint64_t)link_desc_paddr >> 32);
  136. HAL_DESC_SET_FIELD(buf_addr, BUFFER_ADDR_INFO, RETURN_BUFFER_MANAGER,
  137. bm_id);
  138. HAL_DESC_SET_FIELD(buf_addr, BUFFER_ADDR_INFO, SW_BUFFER_COOKIE,
  139. cookie);
  140. }
  141. static uint16_t hal_get_rx_max_ba_window_be(int tid)
  142. {
  143. return HAL_RX_BA_WINDOW_256;
  144. }
  145. static uint32_t hal_get_reo_qdesc_size_be(uint32_t ba_window_size, int tid)
  146. {
  147. /* Hardcode the ba_window_size to HAL_RX_MAX_BA_WINDOW for
  148. * NON_QOS_TID until HW issues are resolved.
  149. */
  150. if (tid != HAL_NON_QOS_TID)
  151. ba_window_size = hal_get_rx_max_ba_window_be(tid);
  152. /* Return descriptor size corresponding to window size of 2 since
  153. * we set ba_window_size to 2 while setting up REO descriptors as
  154. * a WAR to get 2k jump exception aggregates are received without
  155. * a BA session.
  156. */
  157. if (ba_window_size <= 1) {
  158. if (tid != HAL_NON_QOS_TID)
  159. return sizeof(struct rx_reo_queue) +
  160. sizeof(struct rx_reo_queue_ext);
  161. else
  162. return sizeof(struct rx_reo_queue);
  163. }
  164. if (ba_window_size <= 105)
  165. return sizeof(struct rx_reo_queue) +
  166. sizeof(struct rx_reo_queue_ext);
  167. if (ba_window_size <= 210)
  168. return sizeof(struct rx_reo_queue) +
  169. (2 * sizeof(struct rx_reo_queue_ext));
  170. return sizeof(struct rx_reo_queue) +
  171. (3 * sizeof(struct rx_reo_queue_ext));
  172. }
  173. void *hal_rx_msdu_ext_desc_info_get_ptr_be(void *msdu_details_ptr)
  174. {
  175. return HAL_RX_MSDU_EXT_DESC_INFO_GET(msdu_details_ptr);
  176. }
  177. #if defined(QCA_WIFI_KIWI) && !defined(QCA_WIFI_KIWI_V2)
  178. static inline uint32_t
  179. hal_wbm2sw_release_source_get(void *hal_desc, enum hal_be_wbm_release_dir dir)
  180. {
  181. uint32_t buf_src;
  182. buf_src = HAL_WBM2SW_RELEASE_SRC_GET(hal_desc);
  183. switch (buf_src) {
  184. case HAL_BE_RX_WBM_ERR_SRC_RXDMA:
  185. return HAL_RX_WBM_ERR_SRC_RXDMA;
  186. case HAL_BE_RX_WBM_ERR_SRC_REO:
  187. return HAL_RX_WBM_ERR_SRC_REO;
  188. case HAL_BE_RX_WBM_ERR_SRC_FW_RX:
  189. if (dir != HAL_BE_WBM_RELEASE_DIR_RX)
  190. qdf_assert_always(0);
  191. return HAL_RX_WBM_ERR_SRC_FW;
  192. case HAL_BE_RX_WBM_ERR_SRC_SW_RX:
  193. if (dir != HAL_BE_WBM_RELEASE_DIR_RX)
  194. qdf_assert_always(0);
  195. return HAL_RX_WBM_ERR_SRC_SW;
  196. case HAL_BE_RX_WBM_ERR_SRC_TQM:
  197. return HAL_RX_WBM_ERR_SRC_TQM;
  198. case HAL_BE_RX_WBM_ERR_SRC_FW_TX:
  199. if (dir != HAL_BE_WBM_RELEASE_DIR_TX)
  200. qdf_assert_always(0);
  201. return HAL_RX_WBM_ERR_SRC_FW;
  202. case HAL_BE_RX_WBM_ERR_SRC_SW_TX:
  203. if (dir != HAL_BE_WBM_RELEASE_DIR_TX)
  204. qdf_assert_always(0);
  205. return HAL_RX_WBM_ERR_SRC_SW;
  206. default:
  207. qdf_assert_always(0);
  208. }
  209. return buf_src;
  210. }
  211. #else
  212. static inline uint32_t
  213. hal_wbm2sw_release_source_get(void *hal_desc, enum hal_be_wbm_release_dir dir)
  214. {
  215. return HAL_WBM2SW_RELEASE_SRC_GET(hal_desc);
  216. }
  217. #endif
  218. uint32_t hal_tx_comp_get_buffer_source_generic_be(void *hal_desc)
  219. {
  220. return hal_wbm2sw_release_source_get(hal_desc,
  221. HAL_BE_WBM_RELEASE_DIR_TX);
  222. }
  223. /**
  224. * hal_tx_comp_get_release_reason_generic_be() - TQM Release reason
  225. * @hal_desc: completion ring descriptor pointer
  226. *
  227. * This function will return the type of pointer - buffer or descriptor
  228. *
  229. * Return: buffer type
  230. */
  231. static uint8_t hal_tx_comp_get_release_reason_generic_be(void *hal_desc)
  232. {
  233. uint32_t comp_desc = *(uint32_t *)(((uint8_t *)hal_desc) +
  234. WBM2SW_COMPLETION_RING_TX_TQM_RELEASE_REASON_OFFSET);
  235. return (comp_desc &
  236. WBM2SW_COMPLETION_RING_TX_TQM_RELEASE_REASON_MASK) >>
  237. WBM2SW_COMPLETION_RING_TX_TQM_RELEASE_REASON_LSB;
  238. }
  239. /**
  240. * hal_get_wbm_internal_error_generic_be() - is WBM internal error
  241. * @hal_desc: completion ring descriptor pointer
  242. *
  243. * This function will return 0 or 1 - is it WBM internal error or not
  244. *
  245. * Return: uint8_t
  246. */
  247. static uint8_t hal_get_wbm_internal_error_generic_be(void *hal_desc)
  248. {
  249. /*
  250. * TODO - This func is called by tx comp and wbm error handler
  251. * Check if one needs to use WBM2SW-TX and other WBM2SW-RX
  252. */
  253. uint32_t comp_desc =
  254. *(uint32_t *)(((uint8_t *)hal_desc) +
  255. HAL_WBM_INTERNAL_ERROR_OFFSET);
  256. return (comp_desc & HAL_WBM_INTERNAL_ERROR_MASK) >>
  257. HAL_WBM_INTERNAL_ERROR_LSB;
  258. }
  259. /**
  260. * hal_rx_wbm_err_src_get_be() - Get WBM error source from descriptor
  261. * @ring_desc: ring descriptor
  262. *
  263. * Return: wbm error source
  264. */
  265. static uint32_t hal_rx_wbm_err_src_get_be(hal_ring_desc_t ring_desc)
  266. {
  267. return hal_wbm2sw_release_source_get(ring_desc,
  268. HAL_BE_WBM_RELEASE_DIR_RX);
  269. }
  270. /**
  271. * hal_rx_ret_buf_manager_get_be() - Get return buffer manager from ring desc
  272. * @ring_desc: ring descriptor
  273. *
  274. * Return: rbm
  275. */
  276. uint8_t hal_rx_ret_buf_manager_get_be(hal_ring_desc_t ring_desc)
  277. {
  278. /*
  279. * The following macro takes buf_addr_info as argument,
  280. * but since buf_addr_info is the first field in ring_desc
  281. * Hence the following call is OK
  282. */
  283. return HAL_RX_BUF_RBM_GET(ring_desc);
  284. }
  285. #define HAL_RX_WBM_REO_PUSH_REASON_GET(wbm_desc) (((*(((uint32_t *)wbm_desc) + \
  286. (WBM2SW_COMPLETION_RING_RX_REO_PUSH_REASON_OFFSET >> 2))) & \
  287. WBM2SW_COMPLETION_RING_RX_REO_PUSH_REASON_MASK) >> \
  288. WBM2SW_COMPLETION_RING_RX_REO_PUSH_REASON_LSB)
  289. #define HAL_RX_WBM_REO_ERROR_CODE_GET(wbm_desc) (((*(((uint32_t *)wbm_desc) + \
  290. (WBM2SW_COMPLETION_RING_RX_REO_ERROR_CODE_OFFSET >> 2))) & \
  291. WBM2SW_COMPLETION_RING_RX_REO_ERROR_CODE_MASK) >> \
  292. WBM2SW_COMPLETION_RING_RX_REO_ERROR_CODE_LSB)
  293. #define HAL_RX_WBM_RXDMA_PUSH_REASON_GET(wbm_desc) \
  294. (((*(((uint32_t *)wbm_desc) + \
  295. (WBM2SW_COMPLETION_RING_RX_RXDMA_PUSH_REASON_OFFSET >> 2))) & \
  296. WBM2SW_COMPLETION_RING_RX_RXDMA_PUSH_REASON_MASK) >> \
  297. WBM2SW_COMPLETION_RING_RX_RXDMA_PUSH_REASON_LSB)
  298. #define HAL_RX_WBM_RXDMA_ERROR_CODE_GET(wbm_desc) \
  299. (((*(((uint32_t *)wbm_desc) + \
  300. (WBM2SW_COMPLETION_RING_RX_RXDMA_ERROR_CODE_OFFSET >> 2))) & \
  301. WBM2SW_COMPLETION_RING_RX_RXDMA_ERROR_CODE_MASK) >> \
  302. WBM2SW_COMPLETION_RING_RX_RXDMA_ERROR_CODE_LSB)
  303. /**
  304. * hal_rx_wbm_err_info_get_generic_be(): Retrieves WBM error code and reason and
  305. * save it to hal_wbm_err_desc_info structure passed by caller
  306. * @wbm_desc: wbm ring descriptor
  307. * @wbm_er_info1: hal_wbm_err_desc_info structure, output parameter.
  308. * Return: void
  309. */
  310. void hal_rx_wbm_err_info_get_generic_be(void *wbm_desc, void *wbm_er_info1)
  311. {
  312. struct hal_wbm_err_desc_info *wbm_er_info =
  313. (struct hal_wbm_err_desc_info *)wbm_er_info1;
  314. wbm_er_info->wbm_err_src = hal_rx_wbm_err_src_get_be(wbm_desc);
  315. wbm_er_info->reo_psh_rsn = HAL_RX_WBM_REO_PUSH_REASON_GET(wbm_desc);
  316. wbm_er_info->reo_err_code = HAL_RX_WBM_REO_ERROR_CODE_GET(wbm_desc);
  317. wbm_er_info->rxdma_psh_rsn = HAL_RX_WBM_RXDMA_PUSH_REASON_GET(wbm_desc);
  318. wbm_er_info->rxdma_err_code = HAL_RX_WBM_RXDMA_ERROR_CODE_GET(wbm_desc);
  319. }
  320. static void hal_rx_reo_buf_paddr_get_be(hal_ring_desc_t rx_desc,
  321. struct hal_buf_info *buf_info)
  322. {
  323. struct reo_destination_ring *reo_ring =
  324. (struct reo_destination_ring *)rx_desc;
  325. buf_info->paddr =
  326. (HAL_RX_REO_BUFFER_ADDR_31_0_GET(reo_ring) |
  327. ((uint64_t)(HAL_RX_REO_BUFFER_ADDR_39_32_GET(reo_ring)) << 32));
  328. buf_info->sw_cookie = HAL_RX_REO_BUF_COOKIE_GET(reo_ring);
  329. }
  330. static void hal_rx_msdu_link_desc_set_be(hal_soc_handle_t hal_soc_hdl,
  331. void *src_srng_desc,
  332. hal_buff_addrinfo_t buf_addr_info,
  333. uint8_t bm_action)
  334. {
  335. /*
  336. * The offsets for fields used in this function are same in
  337. * wbm_release_ring for Lithium and wbm_release_ring_tx
  338. * for Beryllium. hence we can use wbm_release_ring directly.
  339. */
  340. struct wbm_release_ring *wbm_rel_srng =
  341. (struct wbm_release_ring *)src_srng_desc;
  342. uint32_t addr_31_0;
  343. uint8_t addr_39_32;
  344. /* Structure copy !!! */
  345. wbm_rel_srng->released_buff_or_desc_addr_info =
  346. *((struct buffer_addr_info *)buf_addr_info);
  347. addr_31_0 =
  348. wbm_rel_srng->released_buff_or_desc_addr_info.buffer_addr_31_0;
  349. addr_39_32 =
  350. wbm_rel_srng->released_buff_or_desc_addr_info.buffer_addr_39_32;
  351. HAL_DESC_SET_FIELD(src_srng_desc, HAL_SW2WBM_RELEASE_RING,
  352. RELEASE_SOURCE_MODULE, HAL_RX_WBM_ERR_SRC_SW);
  353. HAL_DESC_SET_FIELD(src_srng_desc, HAL_SW2WBM_RELEASE_RING, BM_ACTION,
  354. bm_action);
  355. HAL_DESC_SET_FIELD(src_srng_desc, HAL_SW2WBM_RELEASE_RING,
  356. BUFFER_OR_DESC_TYPE,
  357. HAL_RX_WBM_BUF_TYPE_MSDU_LINK_DESC);
  358. /* WBM error is indicated when any of the link descriptors given to
  359. * WBM has a NULL address, and one those paths is the link descriptors
  360. * released from host after processing RXDMA errors,
  361. * or from Rx defrag path, and we want to add an assert here to ensure
  362. * host is not releasing descriptors with NULL address.
  363. */
  364. if (qdf_unlikely(!addr_31_0 && !addr_39_32)) {
  365. hal_dump_wbm_rel_desc(src_srng_desc);
  366. qdf_assert_always(0);
  367. }
  368. }
  369. /**
  370. * hal_rx_reo_ent_buf_paddr_get_be: Gets the physical address and
  371. * cookie from the REO entrance ring element
  372. *
  373. * @ hal_rx_desc_cookie: Opaque cookie pointer used by HAL to get to
  374. * the current descriptor
  375. * @ buf_info: structure to return the buffer information
  376. * @ msdu_cnt: pointer to msdu count in MPDU
  377. * Return: void
  378. */
  379. static
  380. void hal_rx_buf_cookie_rbm_get_be(uint32_t *buf_addr_info_hdl,
  381. hal_buf_info_t buf_info_hdl)
  382. {
  383. struct hal_buf_info *buf_info =
  384. (struct hal_buf_info *)buf_info_hdl;
  385. struct buffer_addr_info *buf_addr_info =
  386. (struct buffer_addr_info *)buf_addr_info_hdl;
  387. buf_info->sw_cookie = HAL_RX_BUF_COOKIE_GET(buf_addr_info);
  388. /*
  389. * buffer addr info is the first member of ring desc, so the typecast
  390. * can be done.
  391. */
  392. buf_info->rbm = hal_rx_ret_buf_manager_get_be(
  393. (hal_ring_desc_t)buf_addr_info);
  394. }
  395. /*
  396. * hal_rxdma_buff_addr_info_set_be() - set the buffer_addr_info of the
  397. * rxdma ring entry.
  398. * @rxdma_entry: descriptor entry
  399. * @paddr: physical address of nbuf data pointer.
  400. * @cookie: SW cookie used as a index to SW rx desc.
  401. * @manager: who owns the nbuf (host, NSS, etc...).
  402. *
  403. */
  404. static inline void
  405. hal_rxdma_buff_addr_info_set_be(void *rxdma_entry,
  406. qdf_dma_addr_t paddr, uint32_t cookie,
  407. uint8_t manager)
  408. {
  409. uint32_t paddr_lo = ((u64)paddr & 0x00000000ffffffff);
  410. uint32_t paddr_hi = ((u64)paddr & 0xffffffff00000000) >> 32;
  411. HAL_RXDMA_PADDR_LO_SET(rxdma_entry, paddr_lo);
  412. HAL_RXDMA_PADDR_HI_SET(rxdma_entry, paddr_hi);
  413. HAL_RXDMA_COOKIE_SET(rxdma_entry, cookie);
  414. HAL_RXDMA_MANAGER_SET(rxdma_entry, manager);
  415. }
  416. /**
  417. * hal_rx_get_reo_error_code_be() - Get REO error code from ring desc
  418. * @rx_desc: rx descriptor
  419. *
  420. * Return: REO error code
  421. */
  422. static uint32_t hal_rx_get_reo_error_code_be(hal_ring_desc_t rx_desc)
  423. {
  424. struct reo_destination_ring *reo_desc =
  425. (struct reo_destination_ring *)rx_desc;
  426. return HAL_RX_REO_ERROR_GET(reo_desc);
  427. }
  428. /**
  429. * hal_gen_reo_remap_val_generic_be() - Generate the reo map value
  430. * @ix0_map: mapping values for reo
  431. *
  432. * Return: IX0 reo remap register value to be written
  433. */
  434. static uint32_t
  435. hal_gen_reo_remap_val_generic_be(enum hal_reo_remap_reg remap_reg,
  436. uint8_t *ix0_map)
  437. {
  438. uint32_t ix_val = 0;
  439. switch (remap_reg) {
  440. case HAL_REO_REMAP_REG_IX0:
  441. ix_val = HAL_REO_REMAP_IX0(ix0_map[0], 0) |
  442. HAL_REO_REMAP_IX0(ix0_map[1], 1) |
  443. HAL_REO_REMAP_IX0(ix0_map[2], 2) |
  444. HAL_REO_REMAP_IX0(ix0_map[3], 3) |
  445. HAL_REO_REMAP_IX0(ix0_map[4], 4) |
  446. HAL_REO_REMAP_IX0(ix0_map[5], 5) |
  447. HAL_REO_REMAP_IX0(ix0_map[6], 6) |
  448. HAL_REO_REMAP_IX0(ix0_map[7], 7);
  449. break;
  450. case HAL_REO_REMAP_REG_IX2:
  451. ix_val = HAL_REO_REMAP_IX2(ix0_map[0], 16) |
  452. HAL_REO_REMAP_IX2(ix0_map[1], 17) |
  453. HAL_REO_REMAP_IX2(ix0_map[2], 18) |
  454. HAL_REO_REMAP_IX2(ix0_map[3], 19) |
  455. HAL_REO_REMAP_IX2(ix0_map[4], 20) |
  456. HAL_REO_REMAP_IX2(ix0_map[5], 21) |
  457. HAL_REO_REMAP_IX2(ix0_map[6], 22) |
  458. HAL_REO_REMAP_IX2(ix0_map[7], 23);
  459. break;
  460. default:
  461. break;
  462. }
  463. return ix_val;
  464. }
  465. static uint8_t hal_rx_err_status_get_be(hal_ring_desc_t rx_desc)
  466. {
  467. return HAL_RX_ERROR_STATUS_GET(rx_desc);
  468. }
  469. static QDF_STATUS hal_reo_status_update_be(hal_soc_handle_t hal_soc_hdl,
  470. hal_ring_desc_t reo_desc,
  471. void *st_handle,
  472. uint32_t tlv, int *num_ref)
  473. {
  474. union hal_reo_status *reo_status_ref;
  475. reo_status_ref = (union hal_reo_status *)st_handle;
  476. switch (tlv) {
  477. case HAL_REO_QUEUE_STATS_STATUS_TLV:
  478. hal_reo_queue_stats_status_be(reo_desc,
  479. &reo_status_ref->queue_status,
  480. hal_soc_hdl);
  481. *num_ref = reo_status_ref->queue_status.header.cmd_num;
  482. break;
  483. case HAL_REO_FLUSH_QUEUE_STATUS_TLV:
  484. hal_reo_flush_queue_status_be(reo_desc,
  485. &reo_status_ref->fl_queue_status,
  486. hal_soc_hdl);
  487. *num_ref = reo_status_ref->fl_queue_status.header.cmd_num;
  488. break;
  489. case HAL_REO_FLUSH_CACHE_STATUS_TLV:
  490. hal_reo_flush_cache_status_be(reo_desc,
  491. &reo_status_ref->fl_cache_status,
  492. hal_soc_hdl);
  493. *num_ref = reo_status_ref->fl_cache_status.header.cmd_num;
  494. break;
  495. case HAL_REO_UNBLK_CACHE_STATUS_TLV:
  496. hal_reo_unblock_cache_status_be
  497. (reo_desc, hal_soc_hdl,
  498. &reo_status_ref->unblk_cache_status);
  499. *num_ref = reo_status_ref->unblk_cache_status.header.cmd_num;
  500. break;
  501. case HAL_REO_TIMOUT_LIST_STATUS_TLV:
  502. hal_reo_flush_timeout_list_status_be(
  503. reo_desc,
  504. &reo_status_ref->fl_timeout_status,
  505. hal_soc_hdl);
  506. *num_ref = reo_status_ref->fl_timeout_status.header.cmd_num;
  507. break;
  508. case HAL_REO_DESC_THRES_STATUS_TLV:
  509. hal_reo_desc_thres_reached_status_be(
  510. reo_desc,
  511. &reo_status_ref->thres_status,
  512. hal_soc_hdl);
  513. *num_ref = reo_status_ref->thres_status.header.cmd_num;
  514. break;
  515. case HAL_REO_UPDATE_RX_QUEUE_STATUS_TLV:
  516. hal_reo_rx_update_queue_status_be(
  517. reo_desc,
  518. &reo_status_ref->rx_queue_status,
  519. hal_soc_hdl);
  520. *num_ref = reo_status_ref->rx_queue_status.header.cmd_num;
  521. break;
  522. default:
  523. QDF_TRACE(QDF_MODULE_ID_DP_REO, QDF_TRACE_LEVEL_WARN,
  524. "hal_soc %pK: no handler for TLV:%d",
  525. hal_soc_hdl, tlv);
  526. return QDF_STATUS_E_FAILURE;
  527. } /* switch */
  528. return QDF_STATUS_SUCCESS;
  529. }
  530. static uint8_t hal_rx_reo_buf_type_get_be(hal_ring_desc_t rx_desc)
  531. {
  532. return HAL_RX_REO_BUF_TYPE_GET(rx_desc);
  533. }
  534. #ifdef DP_HW_COOKIE_CONVERT_EXCEPTION
  535. #define HAL_WBM_MISC_CONTROL_SPARE_CONTROL_FIELD_BIT15 0x8000
  536. #endif
  537. void hal_cookie_conversion_reg_cfg_be(hal_soc_handle_t hal_soc_hdl,
  538. struct hal_hw_cc_config *cc_cfg)
  539. {
  540. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  541. hal_soc->ops->hal_cookie_conversion_reg_cfg_be(hal_soc_hdl, cc_cfg);
  542. }
  543. qdf_export_symbol(hal_cookie_conversion_reg_cfg_be);
  544. static inline void
  545. hal_msdu_desc_info_set_be(hal_soc_handle_t hal_soc_hdl,
  546. void *msdu_desc, uint32_t dst_ind,
  547. uint32_t nbuf_len)
  548. {
  549. struct rx_msdu_desc_info *msdu_desc_info =
  550. (struct rx_msdu_desc_info *)msdu_desc;
  551. HAL_RX_MSDU_DESC_INFO_SET(msdu_desc_info,
  552. FIRST_MSDU_IN_MPDU_FLAG, 1);
  553. HAL_RX_MSDU_DESC_INFO_SET(msdu_desc_info,
  554. LAST_MSDU_IN_MPDU_FLAG, 1);
  555. HAL_RX_MSDU_DESC_INFO_SET(msdu_desc_info,
  556. MSDU_CONTINUATION, 0x0);
  557. HAL_RX_MSDU_DESC_INFO_SET(msdu_desc_info,
  558. MSDU_LENGTH, nbuf_len);
  559. HAL_RX_MSDU_DESC_INFO_SET(msdu_desc_info,
  560. SA_IS_VALID, 1);
  561. HAL_RX_MSDU_DESC_INFO_SET(msdu_desc_info,
  562. DA_IS_VALID, 1);
  563. }
  564. static inline void
  565. hal_mpdu_desc_info_set_be(hal_soc_handle_t hal_soc_hdl,
  566. void *mpdu_desc, uint32_t seq_no)
  567. {
  568. struct rx_mpdu_desc_info *mpdu_desc_info =
  569. (struct rx_mpdu_desc_info *)mpdu_desc;
  570. HAL_RX_MPDU_DESC_INFO_SET(mpdu_desc_info,
  571. MSDU_COUNT, 0x1);
  572. /* unset frag bit */
  573. HAL_RX_MPDU_DESC_INFO_SET(mpdu_desc_info,
  574. FRAGMENT_FLAG, 0x0);
  575. HAL_RX_MPDU_DESC_INFO_SET(mpdu_desc_info,
  576. RAW_MPDU, 0x0);
  577. }
  578. /**
  579. * hal_rx_msdu_reo_dst_ind_get: Gets the REO
  580. * destination ring ID from the msdu desc info
  581. *
  582. * @msdu_link_desc : Opaque cookie pointer used by HAL to get to
  583. * the current descriptor
  584. *
  585. * Return: dst_ind (REO destination ring ID)
  586. */
  587. static inline
  588. uint32_t hal_rx_msdu_reo_dst_ind_get_be(hal_soc_handle_t hal_soc_hdl,
  589. void *msdu_link_desc)
  590. {
  591. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  592. struct rx_msdu_details *msdu_details;
  593. struct rx_msdu_desc_info *msdu_desc_info;
  594. struct rx_msdu_link *msdu_link = (struct rx_msdu_link *)msdu_link_desc;
  595. uint32_t dst_ind;
  596. msdu_details = hal_rx_link_desc_msdu0_ptr(msdu_link, hal_soc);
  597. /* The first msdu in the link should exsist */
  598. msdu_desc_info = hal_rx_msdu_ext_desc_info_get_ptr(&msdu_details[0],
  599. hal_soc);
  600. dst_ind = HAL_RX_MSDU_REO_DST_IND_GET(msdu_desc_info);
  601. return dst_ind;
  602. }
  603. uint32_t
  604. hal_reo_ix_remap_value_get_be(hal_soc_handle_t hal_soc_hdl,
  605. uint8_t rx_ring_mask)
  606. {
  607. uint32_t num_rings = 0;
  608. uint32_t i = 0;
  609. uint32_t ring_remap_arr[HAL_MAX_REO2SW_RINGS] = {0};
  610. uint32_t reo_remap_val = 0;
  611. uint32_t ring_idx = 0;
  612. uint8_t ix_map[HAL_NUM_RX_RING_PER_IX_MAP] = {0};
  613. /* create reo ring remap array */
  614. while (i < HAL_MAX_REO2SW_RINGS) {
  615. if (rx_ring_mask & (1 << i)) {
  616. ring_remap_arr[num_rings] = reo_dest_ring_remap[i];
  617. num_rings++;
  618. }
  619. i++;
  620. }
  621. for (i = 0; i < HAL_NUM_RX_RING_PER_IX_MAP; i++) {
  622. if (rx_ring_mask) {
  623. ix_map[i] = ring_remap_arr[ring_idx];
  624. ring_idx = ((ring_idx + 1) % num_rings);
  625. } else {
  626. /* if ring mask is zero configure to release to WBM */
  627. ix_map[i] = REO_REMAP_RELEASE;
  628. }
  629. }
  630. reo_remap_val = HAL_REO_REMAP_IX0(ix_map[0], 0) |
  631. HAL_REO_REMAP_IX0(ix_map[1], 1) |
  632. HAL_REO_REMAP_IX0(ix_map[2], 2) |
  633. HAL_REO_REMAP_IX0(ix_map[3], 3) |
  634. HAL_REO_REMAP_IX0(ix_map[4], 4) |
  635. HAL_REO_REMAP_IX0(ix_map[5], 5) |
  636. HAL_REO_REMAP_IX0(ix_map[6], 6) |
  637. HAL_REO_REMAP_IX0(ix_map[7], 7);
  638. return reo_remap_val;
  639. }
  640. qdf_export_symbol(hal_reo_ix_remap_value_get_be);
  641. uint8_t hal_reo_ring_remap_value_get_be(uint8_t rx_ring_id)
  642. {
  643. if (rx_ring_id >= HAL_MAX_REO2SW_RINGS)
  644. return REO_REMAP_RELEASE;
  645. return reo_dest_ring_remap[rx_ring_id];
  646. }
  647. qdf_export_symbol(hal_reo_ring_remap_value_get_be);
  648. uint8_t hal_get_idle_link_bm_id_be(uint8_t chip_id)
  649. {
  650. return (WBM_IDLE_DESC_LIST + chip_id);
  651. }
  652. #ifdef DP_FEATURE_HW_COOKIE_CONVERSION
  653. #ifdef DP_HW_COOKIE_CONVERT_EXCEPTION
  654. static inline void
  655. hal_rx_wbm_rel_buf_paddr_get_be(hal_ring_desc_t rx_desc,
  656. struct hal_buf_info *buf_info)
  657. {
  658. if (hal_rx_wbm_get_cookie_convert_done(rx_desc))
  659. buf_info->paddr =
  660. (HAL_RX_WBM_COMP_BUF_ADDR_31_0_GET(rx_desc) |
  661. ((uint64_t)(HAL_RX_WBM_COMP_BUF_ADDR_39_32_GET(rx_desc)) << 32));
  662. else
  663. buf_info->paddr =
  664. (HAL_RX_WBM_BUF_ADDR_31_0_GET(rx_desc) |
  665. ((uint64_t)(HAL_RX_WBM_BUF_ADDR_39_32_GET(rx_desc)) << 32));
  666. }
  667. #else
  668. static inline void
  669. hal_rx_wbm_rel_buf_paddr_get_be(hal_ring_desc_t rx_desc,
  670. struct hal_buf_info *buf_info)
  671. {
  672. buf_info->paddr =
  673. (HAL_RX_WBM_COMP_BUF_ADDR_31_0_GET(rx_desc) |
  674. ((uint64_t)(HAL_RX_WBM_COMP_BUF_ADDR_39_32_GET(rx_desc)) << 32));
  675. }
  676. #endif
  677. #else /* !DP_FEATURE_HW_COOKIE_CONVERSION */
  678. static inline void
  679. hal_rx_wbm_rel_buf_paddr_get_be(hal_ring_desc_t rx_desc,
  680. struct hal_buf_info *buf_info)
  681. {
  682. buf_info->paddr =
  683. (HAL_RX_WBM_BUF_ADDR_31_0_GET(rx_desc) |
  684. ((uint64_t)(HAL_RX_WBM_BUF_ADDR_39_32_GET(rx_desc)) << 32));
  685. }
  686. #endif
  687. #ifdef DP_UMAC_HW_RESET_SUPPORT
  688. /**
  689. * hal_unregister_reo_send_cmd_be() - Unregister Reo send command callback.
  690. * @hal_soc_hdl: HAL soc handle
  691. *
  692. * Return: status
  693. */
  694. static
  695. void hal_unregister_reo_send_cmd_be(struct hal_soc *hal_soc)
  696. {
  697. hal_soc->ops->hal_reo_send_cmd = NULL;
  698. }
  699. /**
  700. * hal_register_reo_send_cmd_be() - Register Reo send command callback.
  701. * @hal_soc_hdl: HAL soc handle
  702. *
  703. * Return: status
  704. */
  705. static
  706. void hal_register_reo_send_cmd_be(struct hal_soc *hal_soc)
  707. {
  708. hal_soc->ops->hal_reo_send_cmd = hal_reo_send_cmd_be;
  709. }
  710. #endif
  711. /**
  712. * hal_hw_txrx_default_ops_attach_be() - Attach the default hal ops for
  713. * beryllium chipsets.
  714. * @hal_soc_hdl: HAL soc handle
  715. *
  716. * Return: None
  717. */
  718. void hal_hw_txrx_default_ops_attach_be(struct hal_soc *hal_soc)
  719. {
  720. hal_soc->ops->hal_get_reo_qdesc_size = hal_get_reo_qdesc_size_be;
  721. hal_soc->ops->hal_get_rx_max_ba_window = hal_get_rx_max_ba_window_be;
  722. hal_soc->ops->hal_set_link_desc_addr = hal_set_link_desc_addr_be;
  723. hal_soc->ops->hal_tx_init_data_ring = hal_tx_init_data_ring_be;
  724. hal_soc->ops->hal_get_reo_reg_base_offset =
  725. hal_get_reo_reg_base_offset_be;
  726. hal_soc->ops->hal_reo_setup = hal_reo_setup_generic_be;
  727. hal_soc->ops->hal_rx_reo_buf_paddr_get = hal_rx_reo_buf_paddr_get_be;
  728. hal_soc->ops->hal_rx_msdu_link_desc_set = hal_rx_msdu_link_desc_set_be;
  729. hal_soc->ops->hal_rx_buf_cookie_rbm_get = hal_rx_buf_cookie_rbm_get_be;
  730. hal_soc->ops->hal_rx_ret_buf_manager_get =
  731. hal_rx_ret_buf_manager_get_be;
  732. hal_soc->ops->hal_rxdma_buff_addr_info_set =
  733. hal_rxdma_buff_addr_info_set_be;
  734. hal_soc->ops->hal_rx_msdu_flags_get = hal_rx_msdu_flags_get_be;
  735. hal_soc->ops->hal_rx_get_reo_error_code = hal_rx_get_reo_error_code_be;
  736. hal_soc->ops->hal_gen_reo_remap_val =
  737. hal_gen_reo_remap_val_generic_be;
  738. hal_soc->ops->hal_tx_comp_get_buffer_source =
  739. hal_tx_comp_get_buffer_source_generic_be;
  740. hal_soc->ops->hal_tx_comp_get_release_reason =
  741. hal_tx_comp_get_release_reason_generic_be;
  742. hal_soc->ops->hal_get_wbm_internal_error =
  743. hal_get_wbm_internal_error_generic_be;
  744. hal_soc->ops->hal_rx_mpdu_desc_info_get =
  745. hal_rx_mpdu_desc_info_get_be;
  746. hal_soc->ops->hal_rx_err_status_get = hal_rx_err_status_get_be;
  747. hal_soc->ops->hal_rx_reo_buf_type_get = hal_rx_reo_buf_type_get_be;
  748. hal_soc->ops->hal_rx_wbm_err_src_get = hal_rx_wbm_err_src_get_be;
  749. hal_soc->ops->hal_rx_wbm_rel_buf_paddr_get =
  750. hal_rx_wbm_rel_buf_paddr_get_be;
  751. hal_soc->ops->hal_reo_send_cmd = hal_reo_send_cmd_be;
  752. hal_soc->ops->hal_reo_qdesc_setup = hal_reo_qdesc_setup_be;
  753. hal_soc->ops->hal_reo_status_update = hal_reo_status_update_be;
  754. hal_soc->ops->hal_get_tlv_hdr_size = hal_get_tlv_hdr_size_be;
  755. hal_soc->ops->hal_rx_msdu_reo_dst_ind_get =
  756. hal_rx_msdu_reo_dst_ind_get_be;
  757. hal_soc->ops->hal_get_idle_link_bm_id = hal_get_idle_link_bm_id_be;
  758. hal_soc->ops->hal_rx_msdu_ext_desc_info_get_ptr =
  759. hal_rx_msdu_ext_desc_info_get_ptr_be;
  760. hal_soc->ops->hal_msdu_desc_info_set = hal_msdu_desc_info_set_be;
  761. hal_soc->ops->hal_mpdu_desc_info_set = hal_mpdu_desc_info_set_be;
  762. #ifdef DP_UMAC_HW_RESET_SUPPORT
  763. hal_soc->ops->hal_unregister_reo_send_cmd =
  764. hal_unregister_reo_send_cmd_be;
  765. hal_soc->ops->hal_register_reo_send_cmd = hal_register_reo_send_cmd_be;
  766. #endif
  767. }