hal_generic_api.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. /*
  2. * Copyright (c) 2016-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2022-2023 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. #ifndef _HAL_GENERIC_API_H_
  20. #define _HAL_GENERIC_API_H_
  21. #include <hal_rx.h>
  22. #define SRNG_ENABLE_BIT 0x40
  23. #define SRNG_IDLE_STATE_BIT 0x80
  24. /**
  25. * hal_get_radiotap_he_gi_ltf() - Convert HE ltf and GI value
  26. * from stats enum to radiotap enum
  27. * @he_gi: HE GI value used in stats
  28. * @he_ltf: HE LTF value used in stats
  29. *
  30. * Return: void
  31. */
  32. static inline void hal_get_radiotap_he_gi_ltf(uint16_t *he_gi, uint16_t *he_ltf)
  33. {
  34. switch (*he_gi) {
  35. case HE_GI_0_8:
  36. *he_gi = HE_GI_RADIOTAP_0_8;
  37. break;
  38. case HE_GI_1_6:
  39. *he_gi = HE_GI_RADIOTAP_1_6;
  40. break;
  41. case HE_GI_3_2:
  42. *he_gi = HE_GI_RADIOTAP_3_2;
  43. break;
  44. default:
  45. *he_gi = HE_GI_RADIOTAP_RESERVED;
  46. }
  47. switch (*he_ltf) {
  48. case HE_LTF_1_X:
  49. *he_ltf = HE_LTF_RADIOTAP_1_X;
  50. break;
  51. case HE_LTF_2_X:
  52. *he_ltf = HE_LTF_RADIOTAP_2_X;
  53. break;
  54. case HE_LTF_4_X:
  55. *he_ltf = HE_LTF_RADIOTAP_4_X;
  56. break;
  57. default:
  58. *he_ltf = HE_LTF_RADIOTAP_UNKNOWN;
  59. }
  60. }
  61. /* channel number to freq conversion */
  62. #define CHANNEL_NUM_14 14
  63. #define CHANNEL_NUM_15 15
  64. #define CHANNEL_NUM_27 27
  65. #define CHANNEL_NUM_35 35
  66. #define CHANNEL_NUM_182 182
  67. #define CHANNEL_NUM_197 197
  68. #define CHANNEL_FREQ_2484 2484
  69. #define CHANNEL_FREQ_2407 2407
  70. #define CHANNEL_FREQ_2512 2512
  71. #define CHANNEL_FREQ_5000 5000
  72. #define CHANNEL_FREQ_5950 5950
  73. #define CHANNEL_FREQ_4000 4000
  74. #define CHANNEL_FREQ_5150 5150
  75. #define CHANNEL_FREQ_5920 5920
  76. #define CHANNEL_FREQ_5935 5935
  77. #define FREQ_MULTIPLIER_CONST_5MHZ 5
  78. #define FREQ_MULTIPLIER_CONST_20MHZ 20
  79. /**
  80. * hal_rx_radiotap_num_to_freq() - Get frequency from chan number
  81. * @chan_num: Input channel number
  82. * @center_freq: Input Channel Center frequency
  83. *
  84. * Return - Channel frequency in Mhz
  85. */
  86. static inline uint16_t
  87. hal_rx_radiotap_num_to_freq(uint16_t chan_num, qdf_freq_t center_freq)
  88. {
  89. if (center_freq > CHANNEL_FREQ_5920 && center_freq < CHANNEL_FREQ_5950)
  90. return CHANNEL_FREQ_5935;
  91. if (center_freq < CHANNEL_FREQ_5950) {
  92. if (chan_num == CHANNEL_NUM_14)
  93. return CHANNEL_FREQ_2484;
  94. if (chan_num < CHANNEL_NUM_14)
  95. return CHANNEL_FREQ_2407 +
  96. (chan_num * FREQ_MULTIPLIER_CONST_5MHZ);
  97. if (chan_num < CHANNEL_NUM_27)
  98. return CHANNEL_FREQ_2512 +
  99. ((chan_num - CHANNEL_NUM_15) *
  100. FREQ_MULTIPLIER_CONST_20MHZ);
  101. if (chan_num > CHANNEL_NUM_182 &&
  102. chan_num < CHANNEL_NUM_197)
  103. return ((chan_num * FREQ_MULTIPLIER_CONST_5MHZ) +
  104. CHANNEL_FREQ_4000);
  105. return CHANNEL_FREQ_5000 +
  106. (chan_num * FREQ_MULTIPLIER_CONST_5MHZ);
  107. } else {
  108. return CHANNEL_FREQ_5950 +
  109. (chan_num * FREQ_MULTIPLIER_CONST_5MHZ);
  110. }
  111. }
  112. /**
  113. * hal_get_hw_hptp_generic() - Get HW head and tail pointer value for any ring
  114. * @hal_soc: Opaque HAL SOC handle
  115. * @hal_ring_hdl: Source ring pointer
  116. * @headp: Head Pointer
  117. * @tailp: Tail Pointer
  118. * @ring: Ring type
  119. *
  120. * Return: Update tail pointer and head pointer in arguments.
  121. */
  122. static inline
  123. void hal_get_hw_hptp_generic(struct hal_soc *hal_soc,
  124. hal_ring_handle_t hal_ring_hdl,
  125. uint32_t *headp, uint32_t *tailp,
  126. uint8_t ring)
  127. {
  128. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  129. struct hal_hw_srng_config *ring_config;
  130. enum hal_ring_type ring_type = (enum hal_ring_type)ring;
  131. if (!hal_soc || !srng) {
  132. QDF_TRACE(QDF_MODULE_ID_HAL, QDF_TRACE_LEVEL_ERROR,
  133. "%s: Context is Null", __func__);
  134. return;
  135. }
  136. ring_config = HAL_SRNG_CONFIG(hal_soc, ring_type);
  137. if (!ring_config->lmac_ring) {
  138. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  139. *headp = SRNG_SRC_REG_READ(srng, HP);
  140. *tailp = SRNG_SRC_REG_READ(srng, TP);
  141. } else {
  142. *headp = SRNG_DST_REG_READ(srng, HP);
  143. *tailp = SRNG_DST_REG_READ(srng, TP);
  144. }
  145. }
  146. }
  147. #ifdef DP_UMAC_HW_RESET_SUPPORT
  148. /**
  149. * hal_srng_src_hw_write_cons_prefetch_timer() - Write cons prefetch timer reg
  150. * @srng: srng handle
  151. * @value: value to set
  152. *
  153. * Return: None
  154. */
  155. static inline
  156. void hal_srng_src_hw_write_cons_prefetch_timer(struct hal_srng *srng,
  157. uint32_t value)
  158. {
  159. SRNG_SRC_REG_WRITE(srng, CONSUMER_PREFETCH_TIMER, value);
  160. }
  161. /**
  162. * hal_srng_hw_disable_generic() - Private function to disable SRNG
  163. * source ring HW
  164. * @hal: HAL SOC handle
  165. * @srng: SRNG ring pointer
  166. */
  167. static inline
  168. void hal_srng_hw_disable_generic(struct hal_soc *hal, struct hal_srng *srng)
  169. {
  170. uint32_t reg_val = 0;
  171. if (srng->ring_dir == HAL_SRNG_DST_RING) {
  172. reg_val = SRNG_DST_REG_READ(srng, MISC) & ~(SRNG_ENABLE_BIT);
  173. SRNG_DST_REG_WRITE(srng, MISC, reg_val);
  174. } else {
  175. reg_val = SRNG_SRC_REG_READ(srng, MISC) & ~(SRNG_ENABLE_BIT);
  176. SRNG_SRC_REG_WRITE(srng, MISC, reg_val);
  177. srng->prefetch_timer =
  178. SRNG_SRC_REG_READ(srng, CONSUMER_PREFETCH_TIMER);
  179. hal_srng_src_hw_write_cons_prefetch_timer(srng, 0);
  180. }
  181. }
  182. #else
  183. static inline
  184. void hal_srng_hw_disable_generic(struct hal_soc *hal, struct hal_srng *srng)
  185. {
  186. }
  187. static inline
  188. void hal_srng_src_hw_write_cons_prefetch_timer(struct hal_srng *srng,
  189. uint32_t value)
  190. {
  191. }
  192. #endif
  193. #ifndef WLAN_SOFTUMAC_SUPPORT
  194. #if defined(WBM_IDLE_LSB_WRITE_CONFIRM_WAR)
  195. /**
  196. * hal_wbm_idle_lsb_write_confirm() - Check and update WBM_IDLE_LINK ring LSB
  197. * @srng: srng handle
  198. *
  199. * Return: None
  200. */
  201. static void hal_wbm_idle_lsb_write_confirm(struct hal_srng *srng)
  202. {
  203. if (srng->ring_id == HAL_SRNG_WBM_IDLE_LINK) {
  204. while (SRNG_SRC_REG_READ(srng, BASE_LSB) !=
  205. ((unsigned int)srng->ring_base_paddr & 0xffffffff))
  206. SRNG_SRC_REG_WRITE(srng, BASE_LSB,
  207. srng->ring_base_paddr &
  208. 0xffffffff);
  209. }
  210. }
  211. #else
  212. static void hal_wbm_idle_lsb_write_confirm(struct hal_srng *srng)
  213. {
  214. }
  215. #endif
  216. /**
  217. * hal_srng_src_hw_init_generic() - Private function to initialize SRNG
  218. * source ring HW
  219. * @hal: HAL SOC handle
  220. * @srng: SRNG ring pointer
  221. * @idle_check: Check if ring is idle
  222. * @idx: ring index
  223. */
  224. static inline
  225. void hal_srng_src_hw_init_generic(struct hal_soc *hal,
  226. struct hal_srng *srng, bool idle_check,
  227. uint32_t idx)
  228. {
  229. uint32_t reg_val = 0;
  230. uint64_t tp_addr = 0;
  231. hal_debug("hw_init srng %d", srng->ring_id);
  232. if (idle_check) {
  233. reg_val = SRNG_SRC_REG_READ(srng, MISC);
  234. if (!(reg_val & SRNG_IDLE_STATE_BIT)) {
  235. hal_err("ring_id %d not in idle state", srng->ring_id);
  236. qdf_assert_always(0);
  237. }
  238. hal_srng_src_hw_write_cons_prefetch_timer(srng,
  239. srng->prefetch_timer);
  240. } else {
  241. reg_val = SRNG_SRC_REG_READ(srng, MISC) & ~(SRNG_ENABLE_BIT);
  242. SRNG_SRC_REG_WRITE(srng, MISC, reg_val);
  243. }
  244. reg_val = 0;
  245. if (srng->flags & HAL_SRNG_MSI_INTR) {
  246. SRNG_SRC_REG_WRITE(srng, MSI1_BASE_LSB,
  247. srng->msi_addr & 0xffffffff);
  248. reg_val = SRNG_SM(SRNG_SRC_FLD(MSI1_BASE_MSB, ADDR),
  249. (uint64_t)(srng->msi_addr) >> 32) |
  250. SRNG_SM(SRNG_SRC_FLD(MSI1_BASE_MSB,
  251. MSI1_ENABLE), 1);
  252. SRNG_SRC_REG_WRITE(srng, MSI1_BASE_MSB, reg_val);
  253. SRNG_SRC_REG_WRITE(srng, MSI1_DATA,
  254. qdf_cpu_to_le32(srng->msi_data));
  255. }
  256. SRNG_SRC_REG_WRITE(srng, BASE_LSB, srng->ring_base_paddr & 0xffffffff);
  257. hal_wbm_idle_lsb_write_confirm(srng);
  258. reg_val = SRNG_SM(SRNG_SRC_FLD(BASE_MSB, RING_BASE_ADDR_MSB),
  259. ((uint64_t)(srng->ring_base_paddr) >> 32)) |
  260. SRNG_SM(SRNG_SRC_FLD(BASE_MSB, RING_SIZE),
  261. srng->entry_size * srng->num_entries);
  262. SRNG_SRC_REG_WRITE(srng, BASE_MSB, reg_val);
  263. reg_val = SRNG_SM(SRNG_SRC_FLD(ID, ENTRY_SIZE), srng->entry_size);
  264. SRNG_SRC_REG_WRITE(srng, ID, reg_val);
  265. /**
  266. * Interrupt setup:
  267. * Default interrupt mode is 'pulse'. Need to setup SW_INTERRUPT_MODE
  268. * if level mode is required
  269. */
  270. reg_val = 0;
  271. /*
  272. * WAR - Hawkeye v1 has a hardware bug which requires timer value to be
  273. * programmed in terms of 1us resolution instead of 8us resolution as
  274. * given in MLD.
  275. */
  276. if (srng->intr_timer_thres_us) {
  277. reg_val |= SRNG_SM(SRNG_SRC_FLD(CONSUMER_INT_SETUP_IX0,
  278. INTERRUPT_TIMER_THRESHOLD),
  279. srng->intr_timer_thres_us >> 3);
  280. /* For HK v2 this should be (srng->intr_timer_thres_us >> 3) */
  281. }
  282. if (srng->intr_batch_cntr_thres_entries) {
  283. reg_val |= SRNG_SM(SRNG_SRC_FLD(CONSUMER_INT_SETUP_IX0,
  284. BATCH_COUNTER_THRESHOLD),
  285. srng->intr_batch_cntr_thres_entries *
  286. srng->entry_size);
  287. }
  288. SRNG_SRC_REG_WRITE(srng, CONSUMER_INT_SETUP_IX0, reg_val);
  289. reg_val = 0;
  290. if (srng->flags & HAL_SRNG_LOW_THRES_INTR_ENABLE) {
  291. reg_val |= SRNG_SM(SRNG_SRC_FLD(CONSUMER_INT_SETUP_IX1,
  292. LOW_THRESHOLD), srng->u.src_ring.low_threshold);
  293. }
  294. SRNG_SRC_REG_WRITE(srng, CONSUMER_INT_SETUP_IX1, reg_val);
  295. /* As per HW team, TP_ADDR and HP_ADDR for Idle link ring should
  296. * remain 0 to avoid some WBM stability issues. Remote head/tail
  297. * pointers are not required since this ring is completely managed
  298. * by WBM HW
  299. */
  300. reg_val = 0;
  301. if (srng->ring_id != HAL_SRNG_WBM_IDLE_LINK) {
  302. tp_addr = (uint64_t)(hal->shadow_rdptr_mem_paddr +
  303. ((unsigned long)(srng->u.src_ring.tp_addr) -
  304. (unsigned long)(hal->shadow_rdptr_mem_vaddr)));
  305. SRNG_SRC_REG_WRITE(srng, TP_ADDR_LSB, tp_addr & 0xffffffff);
  306. SRNG_SRC_REG_WRITE(srng, TP_ADDR_MSB, tp_addr >> 32);
  307. } else {
  308. reg_val |= SRNG_SM(SRNG_SRC_FLD(MISC, RING_ID_DISABLE), 1);
  309. }
  310. /* Initilaize head and tail pointers to indicate ring is empty */
  311. SRNG_SRC_REG_WRITE(srng, HP, idx * srng->entry_size);
  312. SRNG_SRC_REG_WRITE(srng, TP, idx * srng->entry_size);
  313. *srng->u.src_ring.tp_addr = idx * srng->entry_size;
  314. srng->u.src_ring.hp = idx * srng->entry_size;
  315. reg_val |= ((srng->flags & HAL_SRNG_DATA_TLV_SWAP) ?
  316. SRNG_SM(SRNG_SRC_FLD(MISC, DATA_TLV_SWAP_BIT), 1) : 0) |
  317. ((srng->flags & HAL_SRNG_RING_PTR_SWAP) ?
  318. SRNG_SM(SRNG_SRC_FLD(MISC, HOST_FW_SWAP_BIT), 1) : 0) |
  319. ((srng->flags & HAL_SRNG_MSI_SWAP) ?
  320. SRNG_SM(SRNG_SRC_FLD(MISC, MSI_SWAP_BIT), 1) : 0);
  321. /* Loop count is not used for SRC rings */
  322. reg_val |= SRNG_SM(SRNG_SRC_FLD(MISC, LOOPCNT_DISABLE), 1);
  323. /*
  324. * reg_val |= SRNG_SM(SRNG_SRC_FLD(MISC, SRNG_ENABLE), 1);
  325. * todo: update fw_api and replace with above line
  326. * (when SRNG_ENABLE field for the MISC register is available in fw_api)
  327. * (WCSS_UMAC_CE_0_SRC_WFSS_CE_CHANNEL_SRC_R0_SRC_RING_MISC)
  328. */
  329. reg_val |= SRNG_ENABLE_BIT;
  330. SRNG_SRC_REG_WRITE(srng, MISC, reg_val);
  331. }
  332. #ifdef WLAN_FEATURE_NEAR_FULL_IRQ
  333. /**
  334. * hal_srng_dst_msi2_setup() - Configure MSI2 register for a SRNG
  335. * @srng: SRNG handle
  336. *
  337. * Return: None
  338. */
  339. static inline void hal_srng_dst_msi2_setup(struct hal_srng *srng)
  340. {
  341. uint32_t reg_val = 0;
  342. if (srng->u.dst_ring.nf_irq_support) {
  343. SRNG_DST_REG_WRITE(srng, MSI2_BASE_LSB,
  344. srng->msi2_addr & 0xffffffff);
  345. reg_val = SRNG_SM(SRNG_DST_FLD(MSI2_BASE_MSB, ADDR),
  346. (uint64_t)(srng->msi2_addr) >> 32) |
  347. SRNG_SM(SRNG_DST_FLD(MSI2_BASE_MSB,
  348. MSI2_ENABLE), 1);
  349. SRNG_DST_REG_WRITE(srng, MSI2_BASE_MSB, reg_val);
  350. SRNG_DST_REG_WRITE(srng, MSI2_DATA,
  351. qdf_cpu_to_le32(srng->msi2_data));
  352. }
  353. }
  354. /**
  355. * hal_srng_dst_near_full_int_setup() - Configure near-full params for SRNG
  356. * @srng: SRNG handle
  357. *
  358. * Return: None
  359. */
  360. static inline void hal_srng_dst_near_full_int_setup(struct hal_srng *srng)
  361. {
  362. uint32_t reg_val = 0;
  363. if (srng->u.dst_ring.nf_irq_support) {
  364. if (srng->intr_timer_thres_us) {
  365. reg_val |= SRNG_SM(SRNG_DST_FLD(PRODUCER_INT2_SETUP,
  366. INTERRUPT2_TIMER_THRESHOLD),
  367. srng->intr_timer_thres_us >> 3);
  368. }
  369. reg_val |= SRNG_SM(SRNG_DST_FLD(PRODUCER_INT2_SETUP,
  370. HIGH_THRESHOLD),
  371. srng->u.dst_ring.high_thresh *
  372. srng->entry_size);
  373. }
  374. SRNG_DST_REG_WRITE(srng, PRODUCER_INT2_SETUP, reg_val);
  375. }
  376. #else
  377. static inline void hal_srng_dst_msi2_setup(struct hal_srng *srng)
  378. {
  379. }
  380. static inline void hal_srng_dst_near_full_int_setup(struct hal_srng *srng)
  381. {
  382. }
  383. #endif
  384. /**
  385. * hal_srng_dst_hw_init_generic() - Private function to initialize SRNG
  386. * destination ring HW
  387. * @hal: HAL SOC handle
  388. * @srng: SRNG ring pointer
  389. * @idle_check: Check if ring is idle
  390. * @idx: Ring index
  391. */
  392. static inline
  393. void hal_srng_dst_hw_init_generic(struct hal_soc *hal,
  394. struct hal_srng *srng, bool idle_check,
  395. uint32_t idx)
  396. {
  397. uint32_t reg_val = 0;
  398. uint64_t hp_addr = 0;
  399. hal_debug("hw_init srng %d", srng->ring_id);
  400. if (idle_check) {
  401. reg_val = SRNG_DST_REG_READ(srng, MISC);
  402. if (!(reg_val & SRNG_IDLE_STATE_BIT)) {
  403. hal_err("ring_id %d not in idle state", srng->ring_id);
  404. qdf_assert_always(0);
  405. }
  406. } else {
  407. reg_val = SRNG_DST_REG_READ(srng, MISC) & ~(SRNG_ENABLE_BIT);
  408. SRNG_DST_REG_WRITE(srng, MISC, reg_val);
  409. }
  410. reg_val = 0;
  411. if (srng->flags & HAL_SRNG_MSI_INTR) {
  412. SRNG_DST_REG_WRITE(srng, MSI1_BASE_LSB,
  413. srng->msi_addr & 0xffffffff);
  414. reg_val = SRNG_SM(SRNG_DST_FLD(MSI1_BASE_MSB, ADDR),
  415. (uint64_t)(srng->msi_addr) >> 32) |
  416. SRNG_SM(SRNG_DST_FLD(MSI1_BASE_MSB,
  417. MSI1_ENABLE), 1);
  418. SRNG_DST_REG_WRITE(srng, MSI1_BASE_MSB, reg_val);
  419. SRNG_DST_REG_WRITE(srng, MSI1_DATA,
  420. qdf_cpu_to_le32(srng->msi_data));
  421. hal_srng_dst_msi2_setup(srng);
  422. }
  423. SRNG_DST_REG_WRITE(srng, BASE_LSB, srng->ring_base_paddr & 0xffffffff);
  424. reg_val = SRNG_SM(SRNG_DST_FLD(BASE_MSB, RING_BASE_ADDR_MSB),
  425. ((uint64_t)(srng->ring_base_paddr) >> 32)) |
  426. SRNG_SM(SRNG_DST_FLD(BASE_MSB, RING_SIZE),
  427. srng->entry_size * srng->num_entries);
  428. SRNG_DST_REG_WRITE(srng, BASE_MSB, reg_val);
  429. reg_val = SRNG_SM(SRNG_DST_FLD(ID, RING_ID), srng->ring_id) |
  430. SRNG_SM(SRNG_DST_FLD(ID, ENTRY_SIZE), srng->entry_size);
  431. SRNG_DST_REG_WRITE(srng, ID, reg_val);
  432. /**
  433. * Interrupt setup:
  434. * Default interrupt mode is 'pulse'. Need to setup SW_INTERRUPT_MODE
  435. * if level mode is required
  436. */
  437. reg_val = 0;
  438. if (srng->intr_timer_thres_us) {
  439. reg_val |= SRNG_SM(SRNG_DST_FLD(PRODUCER_INT_SETUP,
  440. INTERRUPT_TIMER_THRESHOLD),
  441. srng->intr_timer_thres_us >> 3);
  442. }
  443. if (srng->intr_batch_cntr_thres_entries) {
  444. reg_val |= SRNG_SM(SRNG_DST_FLD(PRODUCER_INT_SETUP,
  445. BATCH_COUNTER_THRESHOLD),
  446. srng->intr_batch_cntr_thres_entries *
  447. srng->entry_size);
  448. }
  449. SRNG_DST_REG_WRITE(srng, PRODUCER_INT_SETUP, reg_val);
  450. /**
  451. * Near-Full Interrupt setup:
  452. * Default interrupt mode is 'pulse'. Need to setup SW_INTERRUPT_MODE
  453. * if level mode is required
  454. */
  455. hal_srng_dst_near_full_int_setup(srng);
  456. hp_addr = (uint64_t)(hal->shadow_rdptr_mem_paddr +
  457. ((unsigned long)(srng->u.dst_ring.hp_addr) -
  458. (unsigned long)(hal->shadow_rdptr_mem_vaddr)));
  459. SRNG_DST_REG_WRITE(srng, HP_ADDR_LSB, hp_addr & 0xffffffff);
  460. SRNG_DST_REG_WRITE(srng, HP_ADDR_MSB, hp_addr >> 32);
  461. /* Initilaize head and tail pointers to indicate ring is empty */
  462. SRNG_DST_REG_WRITE(srng, HP, idx * srng->entry_size);
  463. SRNG_DST_REG_WRITE(srng, TP, idx * srng->entry_size);
  464. *srng->u.dst_ring.hp_addr = idx * srng->entry_size;
  465. srng->u.dst_ring.tp = idx * srng->entry_size;
  466. reg_val = ((srng->flags & HAL_SRNG_DATA_TLV_SWAP) ?
  467. SRNG_SM(SRNG_DST_FLD(MISC, DATA_TLV_SWAP_BIT), 1) : 0) |
  468. ((srng->flags & HAL_SRNG_RING_PTR_SWAP) ?
  469. SRNG_SM(SRNG_DST_FLD(MISC, HOST_FW_SWAP_BIT), 1) : 0) |
  470. ((srng->flags & HAL_SRNG_MSI_SWAP) ?
  471. SRNG_SM(SRNG_DST_FLD(MISC, MSI_SWAP_BIT), 1) : 0);
  472. /*
  473. * reg_val |= SRNG_SM(SRNG_SRC_FLD(MISC, SRNG_ENABLE), 1);
  474. * todo: update fw_api and replace with above line
  475. * (when SRNG_ENABLE field for the MISC register is available in fw_api)
  476. * (WCSS_UMAC_CE_0_SRC_WFSS_CE_CHANNEL_SRC_R0_SRC_RING_MISC)
  477. */
  478. reg_val |= SRNG_ENABLE_BIT;
  479. SRNG_DST_REG_WRITE(srng, MISC, reg_val);
  480. }
  481. /**
  482. * hal_srng_hw_reg_offset_init_generic() - Initialize the HW srng reg offset
  483. * @hal_soc: HAL Soc handle
  484. *
  485. * Return: None
  486. */
  487. static inline void hal_srng_hw_reg_offset_init_generic(struct hal_soc *hal_soc)
  488. {
  489. int32_t *hw_reg_offset = hal_soc->hal_hw_reg_offset;
  490. /* dst */
  491. hw_reg_offset[DST_HP] = REG_OFFSET(DST, HP);
  492. hw_reg_offset[DST_TP] = REG_OFFSET(DST, TP);
  493. hw_reg_offset[DST_ID] = REG_OFFSET(DST, ID);
  494. hw_reg_offset[DST_MISC] = REG_OFFSET(DST, MISC);
  495. hw_reg_offset[DST_HP_ADDR_LSB] = REG_OFFSET(DST, HP_ADDR_LSB);
  496. hw_reg_offset[DST_HP_ADDR_MSB] = REG_OFFSET(DST, HP_ADDR_MSB);
  497. hw_reg_offset[DST_MSI1_BASE_LSB] = REG_OFFSET(DST, MSI1_BASE_LSB);
  498. hw_reg_offset[DST_MSI1_BASE_MSB] = REG_OFFSET(DST, MSI1_BASE_MSB);
  499. hw_reg_offset[DST_MSI1_DATA] = REG_OFFSET(DST, MSI1_DATA);
  500. hw_reg_offset[DST_BASE_LSB] = REG_OFFSET(DST, BASE_LSB);
  501. hw_reg_offset[DST_BASE_MSB] = REG_OFFSET(DST, BASE_MSB);
  502. hw_reg_offset[DST_PRODUCER_INT_SETUP] =
  503. REG_OFFSET(DST, PRODUCER_INT_SETUP);
  504. /* src */
  505. hw_reg_offset[SRC_HP] = REG_OFFSET(SRC, HP);
  506. hw_reg_offset[SRC_TP] = REG_OFFSET(SRC, TP);
  507. hw_reg_offset[SRC_ID] = REG_OFFSET(SRC, ID);
  508. hw_reg_offset[SRC_MISC] = REG_OFFSET(SRC, MISC);
  509. hw_reg_offset[SRC_TP_ADDR_LSB] = REG_OFFSET(SRC, TP_ADDR_LSB);
  510. hw_reg_offset[SRC_TP_ADDR_MSB] = REG_OFFSET(SRC, TP_ADDR_MSB);
  511. hw_reg_offset[SRC_MSI1_BASE_LSB] = REG_OFFSET(SRC, MSI1_BASE_LSB);
  512. hw_reg_offset[SRC_MSI1_BASE_MSB] = REG_OFFSET(SRC, MSI1_BASE_MSB);
  513. hw_reg_offset[SRC_MSI1_DATA] = REG_OFFSET(SRC, MSI1_DATA);
  514. hw_reg_offset[SRC_BASE_LSB] = REG_OFFSET(SRC, BASE_LSB);
  515. hw_reg_offset[SRC_BASE_MSB] = REG_OFFSET(SRC, BASE_MSB);
  516. hw_reg_offset[SRC_CONSUMER_INT_SETUP_IX0] =
  517. REG_OFFSET(SRC, CONSUMER_INT_SETUP_IX0);
  518. hw_reg_offset[SRC_CONSUMER_INT_SETUP_IX1] =
  519. REG_OFFSET(SRC, CONSUMER_INT_SETUP_IX1);
  520. #ifdef DP_UMAC_HW_RESET_SUPPORT
  521. hw_reg_offset[SRC_CONSUMER_PREFETCH_TIMER] =
  522. REG_OFFSET(SRC, CONSUMER_PREFETCH_TIMER);
  523. #endif
  524. }
  525. #else
  526. static inline
  527. void hal_srng_src_hw_init_generic(struct hal_soc *hal,
  528. struct hal_srng *srng, bool idle_check,
  529. uint32_t idx) {}
  530. static inline
  531. void hal_srng_dst_hw_init_generic(struct hal_soc *hal,
  532. struct hal_srng *srng, bool idle_check,
  533. uint32_t idx) {}
  534. #endif
  535. #ifdef FEATURE_DIRECT_LINK
  536. /**
  537. * hal_srng_set_msi_config() - Set the MSI config and enable the SRNG
  538. * @ring_hdl: srng handle
  539. * @params: ring parameters
  540. *
  541. * Return: QDF status
  542. */
  543. static inline
  544. QDF_STATUS hal_srng_set_msi_config(hal_ring_handle_t ring_hdl,
  545. void *params)
  546. {
  547. struct hal_srng *srng = (struct hal_srng *)ring_hdl;
  548. struct hal_srng_params *ring_params = (struct hal_srng_params *)params;
  549. uint32_t reg_val;
  550. srng->intr_timer_thres_us = ring_params->intr_timer_thres_us;
  551. srng->intr_batch_cntr_thres_entries =
  552. ring_params->intr_batch_cntr_thres_entries;
  553. srng->msi_addr = ring_params->msi_addr;
  554. srng->msi_data = ring_params->msi_data;
  555. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  556. reg_val = 0;
  557. SRNG_SRC_REG_WRITE(srng, MSI1_BASE_LSB,
  558. srng->msi_addr & 0xffffffff);
  559. reg_val = SRNG_SM(SRNG_SRC_FLD(MSI1_BASE_MSB, ADDR),
  560. (uint64_t)(srng->msi_addr) >> 32) |
  561. SRNG_SM(SRNG_SRC_FLD(MSI1_BASE_MSB,
  562. MSI1_ENABLE), 1);
  563. SRNG_SRC_REG_WRITE(srng, MSI1_BASE_MSB, reg_val);
  564. SRNG_SRC_REG_WRITE(srng, MSI1_DATA,
  565. qdf_cpu_to_le32(srng->msi_data));
  566. reg_val = 0;
  567. if (srng->intr_timer_thres_us) {
  568. reg_val |= SRNG_SM(SRNG_SRC_FLD(CONSUMER_INT_SETUP_IX0,
  569. INTERRUPT_TIMER_THRESHOLD),
  570. srng->intr_timer_thres_us);
  571. }
  572. if (srng->intr_batch_cntr_thres_entries) {
  573. reg_val |= SRNG_SM(SRNG_SRC_FLD(CONSUMER_INT_SETUP_IX0,
  574. BATCH_COUNTER_THRESHOLD),
  575. srng->intr_batch_cntr_thres_entries *
  576. srng->entry_size);
  577. }
  578. SRNG_SRC_REG_WRITE(srng, CONSUMER_INT_SETUP_IX0, reg_val);
  579. } else {
  580. reg_val = 0;
  581. SRNG_DST_REG_WRITE(srng, MSI1_BASE_LSB,
  582. srng->msi_addr & 0xffffffff);
  583. reg_val = SRNG_SM(SRNG_DST_FLD(MSI1_BASE_MSB, ADDR),
  584. (uint64_t)(srng->msi_addr) >> 32) |
  585. SRNG_SM(SRNG_DST_FLD(MSI1_BASE_MSB,
  586. MSI1_ENABLE), 1);
  587. SRNG_DST_REG_WRITE(srng, MSI1_BASE_MSB, reg_val);
  588. SRNG_DST_REG_WRITE(srng, MSI1_DATA,
  589. qdf_cpu_to_le32(srng->msi_data));
  590. reg_val = 0;
  591. if (srng->intr_timer_thres_us) {
  592. reg_val |= SRNG_SM(SRNG_DST_FLD(PRODUCER_INT_SETUP,
  593. INTERRUPT_TIMER_THRESHOLD),
  594. srng->intr_timer_thres_us >> 3);
  595. }
  596. if (srng->intr_batch_cntr_thres_entries) {
  597. reg_val |= SRNG_SM(SRNG_DST_FLD(PRODUCER_INT_SETUP,
  598. BATCH_COUNTER_THRESHOLD),
  599. srng->intr_batch_cntr_thres_entries *
  600. srng->entry_size);
  601. }
  602. SRNG_DST_REG_WRITE(srng, PRODUCER_INT_SETUP, reg_val);
  603. }
  604. return QDF_STATUS_SUCCESS;
  605. }
  606. #else
  607. static inline
  608. QDF_STATUS hal_srng_set_msi_config(hal_ring_handle_t ring_hdl,
  609. void *params)
  610. {
  611. return QDF_STATUS_E_NOSUPPORT;
  612. }
  613. #endif
  614. #endif /* HAL_GENERIC_API_H_ */