hal_generic_api.h 20 KB

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