hal_generic_api.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  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. if (idle_check) {
  232. reg_val = SRNG_SRC_REG_READ(srng, MISC);
  233. if (!(reg_val & SRNG_IDLE_STATE_BIT)) {
  234. hal_err("ring_id %d not in idle state", srng->ring_id);
  235. qdf_assert_always(0);
  236. }
  237. hal_srng_src_hw_write_cons_prefetch_timer(srng,
  238. srng->prefetch_timer);
  239. }
  240. hal_debug("hw_init srng %d", srng->ring_id);
  241. reg_val = SRNG_SRC_REG_READ(srng, MISC) & ~(SRNG_ENABLE_BIT);
  242. SRNG_SRC_REG_WRITE(srng, MISC, reg_val);
  243. reg_val = 0;
  244. if (srng->flags & HAL_SRNG_MSI_INTR) {
  245. SRNG_SRC_REG_WRITE(srng, MSI1_BASE_LSB,
  246. srng->msi_addr & 0xffffffff);
  247. reg_val = SRNG_SM(SRNG_SRC_FLD(MSI1_BASE_MSB, ADDR),
  248. (uint64_t)(srng->msi_addr) >> 32) |
  249. SRNG_SM(SRNG_SRC_FLD(MSI1_BASE_MSB,
  250. MSI1_ENABLE), 1);
  251. SRNG_SRC_REG_WRITE(srng, MSI1_BASE_MSB, reg_val);
  252. SRNG_SRC_REG_WRITE(srng, MSI1_DATA,
  253. qdf_cpu_to_le32(srng->msi_data));
  254. }
  255. SRNG_SRC_REG_WRITE(srng, BASE_LSB, srng->ring_base_paddr & 0xffffffff);
  256. hal_wbm_idle_lsb_write_confirm(srng);
  257. reg_val = SRNG_SM(SRNG_SRC_FLD(BASE_MSB, RING_BASE_ADDR_MSB),
  258. ((uint64_t)(srng->ring_base_paddr) >> 32)) |
  259. SRNG_SM(SRNG_SRC_FLD(BASE_MSB, RING_SIZE),
  260. srng->entry_size * srng->num_entries);
  261. SRNG_SRC_REG_WRITE(srng, BASE_MSB, reg_val);
  262. reg_val = SRNG_SM(SRNG_SRC_FLD(ID, ENTRY_SIZE), srng->entry_size);
  263. SRNG_SRC_REG_WRITE(srng, ID, reg_val);
  264. /**
  265. * Interrupt setup:
  266. * Default interrupt mode is 'pulse'. Need to setup SW_INTERRUPT_MODE
  267. * if level mode is required
  268. */
  269. reg_val = 0;
  270. /*
  271. * WAR - Hawkeye v1 has a hardware bug which requires timer value to be
  272. * programmed in terms of 1us resolution instead of 8us resolution as
  273. * given in MLD.
  274. */
  275. if (srng->intr_timer_thres_us) {
  276. reg_val |= SRNG_SM(SRNG_SRC_FLD(CONSUMER_INT_SETUP_IX0,
  277. INTERRUPT_TIMER_THRESHOLD),
  278. srng->intr_timer_thres_us);
  279. /* For HK v2 this should be (srng->intr_timer_thres_us >> 3) */
  280. }
  281. if (srng->intr_batch_cntr_thres_entries) {
  282. reg_val |= SRNG_SM(SRNG_SRC_FLD(CONSUMER_INT_SETUP_IX0,
  283. BATCH_COUNTER_THRESHOLD),
  284. srng->intr_batch_cntr_thres_entries *
  285. srng->entry_size);
  286. }
  287. SRNG_SRC_REG_WRITE(srng, CONSUMER_INT_SETUP_IX0, reg_val);
  288. reg_val = 0;
  289. if (srng->flags & HAL_SRNG_LOW_THRES_INTR_ENABLE) {
  290. reg_val |= SRNG_SM(SRNG_SRC_FLD(CONSUMER_INT_SETUP_IX1,
  291. LOW_THRESHOLD), srng->u.src_ring.low_threshold);
  292. }
  293. SRNG_SRC_REG_WRITE(srng, CONSUMER_INT_SETUP_IX1, reg_val);
  294. /* As per HW team, TP_ADDR and HP_ADDR for Idle link ring should
  295. * remain 0 to avoid some WBM stability issues. Remote head/tail
  296. * pointers are not required since this ring is completely managed
  297. * by WBM HW
  298. */
  299. reg_val = 0;
  300. if (srng->ring_id != HAL_SRNG_WBM_IDLE_LINK) {
  301. tp_addr = (uint64_t)(hal->shadow_rdptr_mem_paddr +
  302. ((unsigned long)(srng->u.src_ring.tp_addr) -
  303. (unsigned long)(hal->shadow_rdptr_mem_vaddr)));
  304. SRNG_SRC_REG_WRITE(srng, TP_ADDR_LSB, tp_addr & 0xffffffff);
  305. SRNG_SRC_REG_WRITE(srng, TP_ADDR_MSB, tp_addr >> 32);
  306. } else {
  307. reg_val |= SRNG_SM(SRNG_SRC_FLD(MISC, RING_ID_DISABLE), 1);
  308. }
  309. /* Initilaize head and tail pointers to indicate ring is empty */
  310. SRNG_SRC_REG_WRITE(srng, HP, idx * srng->entry_size);
  311. SRNG_SRC_REG_WRITE(srng, TP, idx * srng->entry_size);
  312. *srng->u.src_ring.tp_addr = idx * srng->entry_size;
  313. srng->u.src_ring.hp = idx * srng->entry_size;
  314. reg_val |= ((srng->flags & HAL_SRNG_DATA_TLV_SWAP) ?
  315. SRNG_SM(SRNG_SRC_FLD(MISC, DATA_TLV_SWAP_BIT), 1) : 0) |
  316. ((srng->flags & HAL_SRNG_RING_PTR_SWAP) ?
  317. SRNG_SM(SRNG_SRC_FLD(MISC, HOST_FW_SWAP_BIT), 1) : 0) |
  318. ((srng->flags & HAL_SRNG_MSI_SWAP) ?
  319. SRNG_SM(SRNG_SRC_FLD(MISC, MSI_SWAP_BIT), 1) : 0);
  320. /* Loop count is not used for SRC rings */
  321. reg_val |= SRNG_SM(SRNG_SRC_FLD(MISC, LOOPCNT_DISABLE), 1);
  322. /*
  323. * reg_val |= SRNG_SM(SRNG_SRC_FLD(MISC, SRNG_ENABLE), 1);
  324. * todo: update fw_api and replace with above line
  325. * (when SRNG_ENABLE field for the MISC register is available in fw_api)
  326. * (WCSS_UMAC_CE_0_SRC_WFSS_CE_CHANNEL_SRC_R0_SRC_RING_MISC)
  327. */
  328. reg_val |= SRNG_ENABLE_BIT;
  329. SRNG_SRC_REG_WRITE(srng, MISC, reg_val);
  330. }
  331. #ifdef WLAN_FEATURE_NEAR_FULL_IRQ
  332. /**
  333. * hal_srng_dst_msi2_setup() - Configure MSI2 register for a SRNG
  334. * @srng: SRNG handle
  335. *
  336. * Return: None
  337. */
  338. static inline void hal_srng_dst_msi2_setup(struct hal_srng *srng)
  339. {
  340. uint32_t reg_val = 0;
  341. if (srng->u.dst_ring.nf_irq_support) {
  342. SRNG_DST_REG_WRITE(srng, MSI2_BASE_LSB,
  343. srng->msi2_addr & 0xffffffff);
  344. reg_val = SRNG_SM(SRNG_DST_FLD(MSI2_BASE_MSB, ADDR),
  345. (uint64_t)(srng->msi2_addr) >> 32) |
  346. SRNG_SM(SRNG_DST_FLD(MSI2_BASE_MSB,
  347. MSI2_ENABLE), 1);
  348. SRNG_DST_REG_WRITE(srng, MSI2_BASE_MSB, reg_val);
  349. SRNG_DST_REG_WRITE(srng, MSI2_DATA,
  350. qdf_cpu_to_le32(srng->msi2_data));
  351. }
  352. }
  353. /**
  354. * hal_srng_dst_near_full_int_setup() - Configure near-full params for SRNG
  355. * @srng: SRNG handle
  356. *
  357. * Return: None
  358. */
  359. static inline void hal_srng_dst_near_full_int_setup(struct hal_srng *srng)
  360. {
  361. uint32_t reg_val = 0;
  362. if (srng->u.dst_ring.nf_irq_support) {
  363. if (srng->intr_timer_thres_us) {
  364. reg_val |= SRNG_SM(SRNG_DST_FLD(PRODUCER_INT2_SETUP,
  365. INTERRUPT2_TIMER_THRESHOLD),
  366. srng->intr_timer_thres_us >> 3);
  367. }
  368. reg_val |= SRNG_SM(SRNG_DST_FLD(PRODUCER_INT2_SETUP,
  369. HIGH_THRESHOLD),
  370. srng->u.dst_ring.high_thresh *
  371. srng->entry_size);
  372. }
  373. SRNG_DST_REG_WRITE(srng, PRODUCER_INT2_SETUP, reg_val);
  374. }
  375. #else
  376. static inline void hal_srng_dst_msi2_setup(struct hal_srng *srng)
  377. {
  378. }
  379. static inline void hal_srng_dst_near_full_int_setup(struct hal_srng *srng)
  380. {
  381. }
  382. #endif
  383. /**
  384. * hal_srng_dst_hw_init_generic() - Private function to initialize SRNG
  385. * destination ring HW
  386. * @hal: HAL SOC handle
  387. * @srng: SRNG ring pointer
  388. * @idle_check: Check if ring is idle
  389. * @idx: Ring index
  390. */
  391. static inline
  392. void hal_srng_dst_hw_init_generic(struct hal_soc *hal,
  393. struct hal_srng *srng, bool idle_check,
  394. uint32_t idx)
  395. {
  396. uint32_t reg_val = 0;
  397. uint64_t hp_addr = 0;
  398. if (idle_check) {
  399. reg_val = SRNG_DST_REG_READ(srng, MISC);
  400. if (!(reg_val & SRNG_IDLE_STATE_BIT)) {
  401. hal_err("ring_id %d not in idle state", srng->ring_id);
  402. qdf_assert_always(0);
  403. }
  404. }
  405. hal_debug("hw_init srng %d", srng->ring_id);
  406. reg_val = SRNG_DST_REG_READ(srng, MISC) & ~(SRNG_ENABLE_BIT);
  407. SRNG_DST_REG_WRITE(srng, MISC, reg_val);
  408. reg_val = 0;
  409. if (srng->flags & HAL_SRNG_MSI_INTR) {
  410. SRNG_DST_REG_WRITE(srng, MSI1_BASE_LSB,
  411. srng->msi_addr & 0xffffffff);
  412. reg_val = SRNG_SM(SRNG_DST_FLD(MSI1_BASE_MSB, ADDR),
  413. (uint64_t)(srng->msi_addr) >> 32) |
  414. SRNG_SM(SRNG_DST_FLD(MSI1_BASE_MSB,
  415. MSI1_ENABLE), 1);
  416. SRNG_DST_REG_WRITE(srng, MSI1_BASE_MSB, reg_val);
  417. SRNG_DST_REG_WRITE(srng, MSI1_DATA,
  418. qdf_cpu_to_le32(srng->msi_data));
  419. hal_srng_dst_msi2_setup(srng);
  420. }
  421. SRNG_DST_REG_WRITE(srng, BASE_LSB, srng->ring_base_paddr & 0xffffffff);
  422. reg_val = SRNG_SM(SRNG_DST_FLD(BASE_MSB, RING_BASE_ADDR_MSB),
  423. ((uint64_t)(srng->ring_base_paddr) >> 32)) |
  424. SRNG_SM(SRNG_DST_FLD(BASE_MSB, RING_SIZE),
  425. srng->entry_size * srng->num_entries);
  426. SRNG_DST_REG_WRITE(srng, BASE_MSB, reg_val);
  427. reg_val = SRNG_SM(SRNG_DST_FLD(ID, RING_ID), srng->ring_id) |
  428. SRNG_SM(SRNG_DST_FLD(ID, ENTRY_SIZE), srng->entry_size);
  429. SRNG_DST_REG_WRITE(srng, ID, reg_val);
  430. /**
  431. * Interrupt setup:
  432. * Default interrupt mode is 'pulse'. Need to setup SW_INTERRUPT_MODE
  433. * if level mode is required
  434. */
  435. reg_val = 0;
  436. if (srng->intr_timer_thres_us) {
  437. reg_val |= SRNG_SM(SRNG_DST_FLD(PRODUCER_INT_SETUP,
  438. INTERRUPT_TIMER_THRESHOLD),
  439. srng->intr_timer_thres_us >> 3);
  440. }
  441. if (srng->intr_batch_cntr_thres_entries) {
  442. reg_val |= SRNG_SM(SRNG_DST_FLD(PRODUCER_INT_SETUP,
  443. BATCH_COUNTER_THRESHOLD),
  444. srng->intr_batch_cntr_thres_entries *
  445. srng->entry_size);
  446. }
  447. SRNG_DST_REG_WRITE(srng, PRODUCER_INT_SETUP, reg_val);
  448. /**
  449. * Near-Full Interrupt setup:
  450. * Default interrupt mode is 'pulse'. Need to setup SW_INTERRUPT_MODE
  451. * if level mode is required
  452. */
  453. hal_srng_dst_near_full_int_setup(srng);
  454. hp_addr = (uint64_t)(hal->shadow_rdptr_mem_paddr +
  455. ((unsigned long)(srng->u.dst_ring.hp_addr) -
  456. (unsigned long)(hal->shadow_rdptr_mem_vaddr)));
  457. SRNG_DST_REG_WRITE(srng, HP_ADDR_LSB, hp_addr & 0xffffffff);
  458. SRNG_DST_REG_WRITE(srng, HP_ADDR_MSB, hp_addr >> 32);
  459. /* Initilaize head and tail pointers to indicate ring is empty */
  460. SRNG_DST_REG_WRITE(srng, HP, idx * srng->entry_size);
  461. SRNG_DST_REG_WRITE(srng, TP, idx * srng->entry_size);
  462. *srng->u.dst_ring.hp_addr = idx * srng->entry_size;
  463. srng->u.dst_ring.tp = idx * srng->entry_size;
  464. reg_val = ((srng->flags & HAL_SRNG_DATA_TLV_SWAP) ?
  465. SRNG_SM(SRNG_DST_FLD(MISC, DATA_TLV_SWAP_BIT), 1) : 0) |
  466. ((srng->flags & HAL_SRNG_RING_PTR_SWAP) ?
  467. SRNG_SM(SRNG_DST_FLD(MISC, HOST_FW_SWAP_BIT), 1) : 0) |
  468. ((srng->flags & HAL_SRNG_MSI_SWAP) ?
  469. SRNG_SM(SRNG_DST_FLD(MISC, MSI_SWAP_BIT), 1) : 0);
  470. /*
  471. * reg_val |= SRNG_SM(SRNG_SRC_FLD(MISC, SRNG_ENABLE), 1);
  472. * todo: update fw_api and replace with above line
  473. * (when SRNG_ENABLE field for the MISC register is available in fw_api)
  474. * (WCSS_UMAC_CE_0_SRC_WFSS_CE_CHANNEL_SRC_R0_SRC_RING_MISC)
  475. */
  476. reg_val |= 0x40;
  477. SRNG_DST_REG_WRITE(srng, MISC, reg_val);
  478. }
  479. /**
  480. * hal_srng_hw_reg_offset_init_generic() - Initialize the HW srng reg offset
  481. * @hal_soc: HAL Soc handle
  482. *
  483. * Return: None
  484. */
  485. static inline void hal_srng_hw_reg_offset_init_generic(struct hal_soc *hal_soc)
  486. {
  487. int32_t *hw_reg_offset = hal_soc->hal_hw_reg_offset;
  488. /* dst */
  489. hw_reg_offset[DST_HP] = REG_OFFSET(DST, HP);
  490. hw_reg_offset[DST_TP] = REG_OFFSET(DST, TP);
  491. hw_reg_offset[DST_ID] = REG_OFFSET(DST, ID);
  492. hw_reg_offset[DST_MISC] = REG_OFFSET(DST, MISC);
  493. hw_reg_offset[DST_HP_ADDR_LSB] = REG_OFFSET(DST, HP_ADDR_LSB);
  494. hw_reg_offset[DST_HP_ADDR_MSB] = REG_OFFSET(DST, HP_ADDR_MSB);
  495. hw_reg_offset[DST_MSI1_BASE_LSB] = REG_OFFSET(DST, MSI1_BASE_LSB);
  496. hw_reg_offset[DST_MSI1_BASE_MSB] = REG_OFFSET(DST, MSI1_BASE_MSB);
  497. hw_reg_offset[DST_MSI1_DATA] = REG_OFFSET(DST, MSI1_DATA);
  498. hw_reg_offset[DST_BASE_LSB] = REG_OFFSET(DST, BASE_LSB);
  499. hw_reg_offset[DST_BASE_MSB] = REG_OFFSET(DST, BASE_MSB);
  500. hw_reg_offset[DST_PRODUCER_INT_SETUP] =
  501. REG_OFFSET(DST, PRODUCER_INT_SETUP);
  502. /* src */
  503. hw_reg_offset[SRC_HP] = REG_OFFSET(SRC, HP);
  504. hw_reg_offset[SRC_TP] = REG_OFFSET(SRC, TP);
  505. hw_reg_offset[SRC_ID] = REG_OFFSET(SRC, ID);
  506. hw_reg_offset[SRC_MISC] = REG_OFFSET(SRC, MISC);
  507. hw_reg_offset[SRC_TP_ADDR_LSB] = REG_OFFSET(SRC, TP_ADDR_LSB);
  508. hw_reg_offset[SRC_TP_ADDR_MSB] = REG_OFFSET(SRC, TP_ADDR_MSB);
  509. hw_reg_offset[SRC_MSI1_BASE_LSB] = REG_OFFSET(SRC, MSI1_BASE_LSB);
  510. hw_reg_offset[SRC_MSI1_BASE_MSB] = REG_OFFSET(SRC, MSI1_BASE_MSB);
  511. hw_reg_offset[SRC_MSI1_DATA] = REG_OFFSET(SRC, MSI1_DATA);
  512. hw_reg_offset[SRC_BASE_LSB] = REG_OFFSET(SRC, BASE_LSB);
  513. hw_reg_offset[SRC_BASE_MSB] = REG_OFFSET(SRC, BASE_MSB);
  514. hw_reg_offset[SRC_CONSUMER_INT_SETUP_IX0] =
  515. REG_OFFSET(SRC, CONSUMER_INT_SETUP_IX0);
  516. hw_reg_offset[SRC_CONSUMER_INT_SETUP_IX1] =
  517. REG_OFFSET(SRC, CONSUMER_INT_SETUP_IX1);
  518. #ifdef DP_UMAC_HW_RESET_SUPPORT
  519. hw_reg_offset[SRC_CONSUMER_PREFETCH_TIMER] =
  520. REG_OFFSET(SRC, CONSUMER_PREFETCH_TIMER);
  521. #endif
  522. }
  523. #else
  524. static inline
  525. void hal_srng_src_hw_init_generic(struct hal_soc *hal,
  526. struct hal_srng *srng, bool idle_check,
  527. uint32_t idx) {}
  528. static inline
  529. void hal_srng_dst_hw_init_generic(struct hal_soc *hal,
  530. struct hal_srng *srng, bool idle_check,
  531. uint32_t idx) {}
  532. #endif
  533. #ifdef FEATURE_DIRECT_LINK
  534. /**
  535. * hal_srng_set_msi_config() - Set the MSI config and enable the SRNG
  536. * @ring_hdl: srng handle
  537. * @params: ring parameters
  538. *
  539. * Return: QDF status
  540. */
  541. static inline
  542. QDF_STATUS hal_srng_set_msi_config(hal_ring_handle_t ring_hdl,
  543. void *params)
  544. {
  545. struct hal_srng *srng = (struct hal_srng *)ring_hdl;
  546. struct hal_srng_params *ring_params = (struct hal_srng_params *)params;
  547. uint32_t reg_val;
  548. srng->intr_timer_thres_us = ring_params->intr_timer_thres_us;
  549. srng->intr_batch_cntr_thres_entries =
  550. ring_params->intr_batch_cntr_thres_entries;
  551. srng->msi_addr = ring_params->msi_addr;
  552. srng->msi_data = ring_params->msi_data;
  553. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  554. reg_val = 0;
  555. SRNG_SRC_REG_WRITE(srng, MSI1_BASE_LSB,
  556. srng->msi_addr & 0xffffffff);
  557. reg_val = SRNG_SM(SRNG_SRC_FLD(MSI1_BASE_MSB, ADDR),
  558. (uint64_t)(srng->msi_addr) >> 32) |
  559. SRNG_SM(SRNG_SRC_FLD(MSI1_BASE_MSB,
  560. MSI1_ENABLE), 1);
  561. SRNG_SRC_REG_WRITE(srng, MSI1_BASE_MSB, reg_val);
  562. SRNG_SRC_REG_WRITE(srng, MSI1_DATA,
  563. qdf_cpu_to_le32(srng->msi_data));
  564. reg_val = 0;
  565. if (srng->intr_timer_thres_us) {
  566. reg_val |= SRNG_SM(SRNG_SRC_FLD(CONSUMER_INT_SETUP_IX0,
  567. INTERRUPT_TIMER_THRESHOLD),
  568. srng->intr_timer_thres_us);
  569. }
  570. if (srng->intr_batch_cntr_thres_entries) {
  571. reg_val |= SRNG_SM(SRNG_SRC_FLD(CONSUMER_INT_SETUP_IX0,
  572. BATCH_COUNTER_THRESHOLD),
  573. srng->intr_batch_cntr_thres_entries *
  574. srng->entry_size);
  575. }
  576. SRNG_SRC_REG_WRITE(srng, CONSUMER_INT_SETUP_IX0, reg_val);
  577. } else {
  578. reg_val = 0;
  579. SRNG_DST_REG_WRITE(srng, MSI1_BASE_LSB,
  580. srng->msi_addr & 0xffffffff);
  581. reg_val = SRNG_SM(SRNG_DST_FLD(MSI1_BASE_MSB, ADDR),
  582. (uint64_t)(srng->msi_addr) >> 32) |
  583. SRNG_SM(SRNG_DST_FLD(MSI1_BASE_MSB,
  584. MSI1_ENABLE), 1);
  585. SRNG_DST_REG_WRITE(srng, MSI1_BASE_MSB, reg_val);
  586. SRNG_DST_REG_WRITE(srng, MSI1_DATA,
  587. qdf_cpu_to_le32(srng->msi_data));
  588. reg_val = 0;
  589. if (srng->intr_timer_thres_us) {
  590. reg_val |= SRNG_SM(SRNG_DST_FLD(PRODUCER_INT_SETUP,
  591. INTERRUPT_TIMER_THRESHOLD),
  592. srng->intr_timer_thres_us >> 3);
  593. }
  594. if (srng->intr_batch_cntr_thres_entries) {
  595. reg_val |= SRNG_SM(SRNG_DST_FLD(PRODUCER_INT_SETUP,
  596. BATCH_COUNTER_THRESHOLD),
  597. srng->intr_batch_cntr_thres_entries *
  598. srng->entry_size);
  599. }
  600. SRNG_DST_REG_WRITE(srng, PRODUCER_INT_SETUP, reg_val);
  601. }
  602. return QDF_STATUS_SUCCESS;
  603. }
  604. #else
  605. static inline
  606. QDF_STATUS hal_srng_set_msi_config(hal_ring_handle_t ring_hdl,
  607. void *params)
  608. {
  609. return QDF_STATUS_E_NOSUPPORT;
  610. }
  611. #endif
  612. #endif /* HAL_GENERIC_API_H_ */