hal.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  1. // SPDX-License-Identifier: BSD-3-Clause-Clear
  2. /*
  3. * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
  4. * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
  5. */
  6. #include <linux/dma-mapping.h>
  7. #include "debug.h"
  8. #include "hif.h"
  9. static void ath12k_hal_ce_dst_setup(struct ath12k_base *ab,
  10. struct hal_srng *srng, int ring_num)
  11. {
  12. ab->hal.ops->ce_dst_setup(ab, srng, ring_num);
  13. }
  14. static void ath12k_hal_srng_src_hw_init(struct ath12k_base *ab,
  15. struct hal_srng *srng)
  16. {
  17. ab->hal.ops->srng_src_hw_init(ab, srng);
  18. }
  19. static void ath12k_hal_srng_dst_hw_init(struct ath12k_base *ab,
  20. struct hal_srng *srng)
  21. {
  22. ab->hal.ops->srng_dst_hw_init(ab, srng);
  23. }
  24. static void ath12k_hal_set_umac_srng_ptr_addr(struct ath12k_base *ab,
  25. struct hal_srng *srng)
  26. {
  27. ab->hal.ops->set_umac_srng_ptr_addr(ab, srng);
  28. }
  29. static int ath12k_hal_srng_get_ring_id(struct ath12k_hal *hal,
  30. enum hal_ring_type type,
  31. int ring_num, int mac_id)
  32. {
  33. return hal->ops->srng_get_ring_id(hal, type, ring_num, mac_id);
  34. }
  35. int ath12k_hal_srng_update_shadow_config(struct ath12k_base *ab,
  36. enum hal_ring_type ring_type,
  37. int ring_num)
  38. {
  39. return ab->hal.ops->srng_update_shadow_config(ab, ring_type,
  40. ring_num);
  41. }
  42. u32 ath12k_hal_ce_get_desc_size(struct ath12k_hal *hal, enum hal_ce_desc type)
  43. {
  44. return hal->ops->ce_get_desc_size(type);
  45. }
  46. void ath12k_hal_tx_set_dscp_tid_map(struct ath12k_base *ab, int id)
  47. {
  48. ab->hal.ops->tx_set_dscp_tid_map(ab, id);
  49. }
  50. void ath12k_hal_tx_configure_bank_register(struct ath12k_base *ab,
  51. u32 bank_config, u8 bank_id)
  52. {
  53. ab->hal.ops->tx_configure_bank_register(ab, bank_config, bank_id);
  54. }
  55. void ath12k_hal_reoq_lut_addr_read_enable(struct ath12k_base *ab)
  56. {
  57. ab->hal.ops->reoq_lut_addr_read_enable(ab);
  58. }
  59. void ath12k_hal_reoq_lut_set_max_peerid(struct ath12k_base *ab)
  60. {
  61. ab->hal.ops->reoq_lut_set_max_peerid(ab);
  62. }
  63. void ath12k_hal_write_ml_reoq_lut_addr(struct ath12k_base *ab, dma_addr_t paddr)
  64. {
  65. ab->hal.ops->write_ml_reoq_lut_addr(ab, paddr);
  66. }
  67. void ath12k_hal_write_reoq_lut_addr(struct ath12k_base *ab, dma_addr_t paddr)
  68. {
  69. ab->hal.ops->write_reoq_lut_addr(ab, paddr);
  70. }
  71. void ath12k_hal_setup_link_idle_list(struct ath12k_base *ab,
  72. struct hal_wbm_idle_scatter_list *sbuf,
  73. u32 nsbufs, u32 tot_link_desc,
  74. u32 end_offset)
  75. {
  76. ab->hal.ops->setup_link_idle_list(ab, sbuf, nsbufs, tot_link_desc,
  77. end_offset);
  78. }
  79. void ath12k_hal_reo_hw_setup(struct ath12k_base *ab, u32 ring_hash_map)
  80. {
  81. ab->hal.ops->reo_hw_setup(ab, ring_hash_map);
  82. }
  83. void ath12k_hal_reo_init_cmd_ring(struct ath12k_base *ab, struct hal_srng *srng)
  84. {
  85. ab->hal.ops->reo_init_cmd_ring(ab, srng);
  86. }
  87. void ath12k_hal_reo_shared_qaddr_cache_clear(struct ath12k_base *ab)
  88. {
  89. ab->hal.ops->reo_shared_qaddr_cache_clear(ab);
  90. }
  91. EXPORT_SYMBOL(ath12k_hal_reo_shared_qaddr_cache_clear);
  92. void ath12k_hal_rx_buf_addr_info_set(struct ath12k_hal *hal,
  93. struct ath12k_buffer_addr *binfo,
  94. dma_addr_t paddr, u32 cookie, u8 manager)
  95. {
  96. hal->ops->rx_buf_addr_info_set(binfo, paddr, cookie, manager);
  97. }
  98. void ath12k_hal_rx_buf_addr_info_get(struct ath12k_hal *hal,
  99. struct ath12k_buffer_addr *binfo,
  100. dma_addr_t *paddr, u32 *msdu_cookies,
  101. u8 *rbm)
  102. {
  103. hal->ops->rx_buf_addr_info_get(binfo, paddr, msdu_cookies, rbm);
  104. }
  105. void ath12k_hal_rx_msdu_list_get(struct ath12k_hal *hal, struct ath12k *ar,
  106. void *link_desc,
  107. void *msdu_list,
  108. u16 *num_msdus)
  109. {
  110. hal->ops->rx_msdu_list_get(ar, link_desc, msdu_list, num_msdus);
  111. }
  112. void ath12k_hal_rx_reo_ent_buf_paddr_get(struct ath12k_hal *hal, void *rx_desc,
  113. dma_addr_t *paddr,
  114. u32 *sw_cookie,
  115. struct ath12k_buffer_addr **pp_buf_addr,
  116. u8 *rbm, u32 *msdu_cnt)
  117. {
  118. hal->ops->rx_reo_ent_buf_paddr_get(rx_desc, paddr, sw_cookie,
  119. pp_buf_addr, rbm, msdu_cnt);
  120. }
  121. void ath12k_hal_cc_config(struct ath12k_base *ab)
  122. {
  123. ab->hal.ops->cc_config(ab);
  124. }
  125. enum hal_rx_buf_return_buf_manager
  126. ath12k_hal_get_idle_link_rbm(struct ath12k_hal *hal, u8 device_id)
  127. {
  128. return hal->ops->get_idle_link_rbm(hal, device_id);
  129. }
  130. static int ath12k_hal_alloc_cont_rdp(struct ath12k_hal *hal)
  131. {
  132. size_t size;
  133. size = sizeof(u32) * HAL_SRNG_RING_ID_MAX;
  134. hal->rdp.vaddr = dma_alloc_coherent(hal->dev, size, &hal->rdp.paddr,
  135. GFP_KERNEL);
  136. if (!hal->rdp.vaddr)
  137. return -ENOMEM;
  138. return 0;
  139. }
  140. static void ath12k_hal_free_cont_rdp(struct ath12k_hal *hal)
  141. {
  142. size_t size;
  143. if (!hal->rdp.vaddr)
  144. return;
  145. size = sizeof(u32) * HAL_SRNG_RING_ID_MAX;
  146. dma_free_coherent(hal->dev, size,
  147. hal->rdp.vaddr, hal->rdp.paddr);
  148. hal->rdp.vaddr = NULL;
  149. }
  150. static int ath12k_hal_alloc_cont_wrp(struct ath12k_hal *hal)
  151. {
  152. size_t size;
  153. size = sizeof(u32) * (HAL_SRNG_NUM_PMAC_RINGS + HAL_SRNG_NUM_DMAC_RINGS);
  154. hal->wrp.vaddr = dma_alloc_coherent(hal->dev, size, &hal->wrp.paddr,
  155. GFP_KERNEL);
  156. if (!hal->wrp.vaddr)
  157. return -ENOMEM;
  158. return 0;
  159. }
  160. static void ath12k_hal_free_cont_wrp(struct ath12k_hal *hal)
  161. {
  162. size_t size;
  163. if (!hal->wrp.vaddr)
  164. return;
  165. size = sizeof(u32) * (HAL_SRNG_NUM_PMAC_RINGS + HAL_SRNG_NUM_DMAC_RINGS);
  166. dma_free_coherent(hal->dev, size,
  167. hal->wrp.vaddr, hal->wrp.paddr);
  168. hal->wrp.vaddr = NULL;
  169. }
  170. static void ath12k_hal_srng_hw_init(struct ath12k_base *ab,
  171. struct hal_srng *srng)
  172. {
  173. if (srng->ring_dir == HAL_SRNG_DIR_SRC)
  174. ath12k_hal_srng_src_hw_init(ab, srng);
  175. else
  176. ath12k_hal_srng_dst_hw_init(ab, srng);
  177. }
  178. int ath12k_hal_srng_get_entrysize(struct ath12k_base *ab, u32 ring_type)
  179. {
  180. struct hal_srng_config *srng_config;
  181. if (WARN_ON(ring_type >= HAL_MAX_RING_TYPES))
  182. return -EINVAL;
  183. srng_config = &ab->hal.srng_config[ring_type];
  184. return (srng_config->entry_size << 2);
  185. }
  186. EXPORT_SYMBOL(ath12k_hal_srng_get_entrysize);
  187. int ath12k_hal_srng_get_max_entries(struct ath12k_base *ab, u32 ring_type)
  188. {
  189. struct hal_srng_config *srng_config;
  190. if (WARN_ON(ring_type >= HAL_MAX_RING_TYPES))
  191. return -EINVAL;
  192. srng_config = &ab->hal.srng_config[ring_type];
  193. return (srng_config->max_size / srng_config->entry_size);
  194. }
  195. void ath12k_hal_srng_get_params(struct ath12k_base *ab, struct hal_srng *srng,
  196. struct hal_srng_params *params)
  197. {
  198. params->ring_base_paddr = srng->ring_base_paddr;
  199. params->ring_base_vaddr = srng->ring_base_vaddr;
  200. params->num_entries = srng->num_entries;
  201. params->intr_timer_thres_us = srng->intr_timer_thres_us;
  202. params->intr_batch_cntr_thres_entries =
  203. srng->intr_batch_cntr_thres_entries;
  204. params->low_threshold = srng->u.src_ring.low_threshold;
  205. params->msi_addr = srng->msi_addr;
  206. params->msi2_addr = srng->msi2_addr;
  207. params->msi_data = srng->msi_data;
  208. params->msi2_data = srng->msi2_data;
  209. params->flags = srng->flags;
  210. }
  211. EXPORT_SYMBOL(ath12k_hal_srng_get_params);
  212. dma_addr_t ath12k_hal_srng_get_hp_addr(struct ath12k_base *ab,
  213. struct hal_srng *srng)
  214. {
  215. if (!(srng->flags & HAL_SRNG_FLAGS_LMAC_RING))
  216. return 0;
  217. if (srng->ring_dir == HAL_SRNG_DIR_SRC)
  218. return ab->hal.wrp.paddr +
  219. ((unsigned long)srng->u.src_ring.hp_addr -
  220. (unsigned long)ab->hal.wrp.vaddr);
  221. else
  222. return ab->hal.rdp.paddr +
  223. ((unsigned long)srng->u.dst_ring.hp_addr -
  224. (unsigned long)ab->hal.rdp.vaddr);
  225. }
  226. dma_addr_t ath12k_hal_srng_get_tp_addr(struct ath12k_base *ab,
  227. struct hal_srng *srng)
  228. {
  229. if (!(srng->flags & HAL_SRNG_FLAGS_LMAC_RING))
  230. return 0;
  231. if (srng->ring_dir == HAL_SRNG_DIR_SRC)
  232. return ab->hal.rdp.paddr +
  233. ((unsigned long)srng->u.src_ring.tp_addr -
  234. (unsigned long)ab->hal.rdp.vaddr);
  235. else
  236. return ab->hal.wrp.paddr +
  237. ((unsigned long)srng->u.dst_ring.tp_addr -
  238. (unsigned long)ab->hal.wrp.vaddr);
  239. }
  240. void ath12k_hal_ce_src_set_desc(struct ath12k_hal *hal,
  241. struct hal_ce_srng_src_desc *desc,
  242. dma_addr_t paddr, u32 len, u32 id,
  243. u8 byte_swap_data)
  244. {
  245. hal->ops->ce_src_set_desc(desc, paddr, len, id, byte_swap_data);
  246. }
  247. void ath12k_hal_ce_dst_set_desc(struct ath12k_hal *hal,
  248. struct hal_ce_srng_dest_desc *desc,
  249. dma_addr_t paddr)
  250. {
  251. hal->ops->ce_dst_set_desc(desc, paddr);
  252. }
  253. u32 ath12k_hal_ce_dst_status_get_length(struct ath12k_hal *hal,
  254. struct hal_ce_srng_dst_status_desc *desc)
  255. {
  256. return hal->ops->ce_dst_status_get_length(desc);
  257. }
  258. void ath12k_hal_set_link_desc_addr(struct ath12k_hal *hal,
  259. struct hal_wbm_link_desc *desc, u32 cookie,
  260. dma_addr_t paddr, int rbm)
  261. {
  262. hal->ops->set_link_desc_addr(desc, cookie, paddr, rbm);
  263. }
  264. void *ath12k_hal_srng_dst_peek(struct ath12k_base *ab, struct hal_srng *srng)
  265. {
  266. lockdep_assert_held(&srng->lock);
  267. if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp)
  268. return (srng->ring_base_vaddr + srng->u.dst_ring.tp);
  269. return NULL;
  270. }
  271. EXPORT_SYMBOL(ath12k_hal_srng_dst_peek);
  272. void *ath12k_hal_srng_dst_get_next_entry(struct ath12k_base *ab,
  273. struct hal_srng *srng)
  274. {
  275. void *desc;
  276. lockdep_assert_held(&srng->lock);
  277. if (srng->u.dst_ring.tp == srng->u.dst_ring.cached_hp)
  278. return NULL;
  279. desc = srng->ring_base_vaddr + srng->u.dst_ring.tp;
  280. srng->u.dst_ring.tp = (srng->u.dst_ring.tp + srng->entry_size) %
  281. srng->ring_size;
  282. return desc;
  283. }
  284. EXPORT_SYMBOL(ath12k_hal_srng_dst_get_next_entry);
  285. int ath12k_hal_srng_dst_num_free(struct ath12k_base *ab, struct hal_srng *srng,
  286. bool sync_hw_ptr)
  287. {
  288. u32 tp, hp;
  289. lockdep_assert_held(&srng->lock);
  290. tp = srng->u.dst_ring.tp;
  291. if (sync_hw_ptr) {
  292. hp = *srng->u.dst_ring.hp_addr;
  293. srng->u.dst_ring.cached_hp = hp;
  294. } else {
  295. hp = srng->u.dst_ring.cached_hp;
  296. }
  297. if (hp >= tp)
  298. return (hp - tp) / srng->entry_size;
  299. else
  300. return (srng->ring_size - tp + hp) / srng->entry_size;
  301. }
  302. EXPORT_SYMBOL(ath12k_hal_srng_dst_num_free);
  303. /* Returns number of available entries in src ring */
  304. int ath12k_hal_srng_src_num_free(struct ath12k_base *ab, struct hal_srng *srng,
  305. bool sync_hw_ptr)
  306. {
  307. u32 tp, hp;
  308. lockdep_assert_held(&srng->lock);
  309. hp = srng->u.src_ring.hp;
  310. if (sync_hw_ptr) {
  311. tp = *srng->u.src_ring.tp_addr;
  312. srng->u.src_ring.cached_tp = tp;
  313. } else {
  314. tp = srng->u.src_ring.cached_tp;
  315. }
  316. if (tp > hp)
  317. return ((tp - hp) / srng->entry_size) - 1;
  318. else
  319. return ((srng->ring_size - hp + tp) / srng->entry_size) - 1;
  320. }
  321. void *ath12k_hal_srng_src_next_peek(struct ath12k_base *ab,
  322. struct hal_srng *srng)
  323. {
  324. void *desc;
  325. u32 next_hp;
  326. lockdep_assert_held(&srng->lock);
  327. next_hp = (srng->u.src_ring.hp + srng->entry_size) % srng->ring_size;
  328. if (next_hp == srng->u.src_ring.cached_tp)
  329. return NULL;
  330. desc = srng->ring_base_vaddr + next_hp;
  331. return desc;
  332. }
  333. EXPORT_SYMBOL(ath12k_hal_srng_src_next_peek);
  334. void *ath12k_hal_srng_src_get_next_entry(struct ath12k_base *ab,
  335. struct hal_srng *srng)
  336. {
  337. void *desc;
  338. u32 next_hp;
  339. lockdep_assert_held(&srng->lock);
  340. /* TODO: Using % is expensive, but we have to do this since size of some
  341. * SRNG rings is not power of 2 (due to descriptor sizes). Need to see
  342. * if separate function is defined for rings having power of 2 ring size
  343. * (TCL2SW, REO2SW, SW2RXDMA and CE rings) so that we can avoid the
  344. * overhead of % by using mask (with &).
  345. */
  346. next_hp = (srng->u.src_ring.hp + srng->entry_size) % srng->ring_size;
  347. if (next_hp == srng->u.src_ring.cached_tp)
  348. return NULL;
  349. desc = srng->ring_base_vaddr + srng->u.src_ring.hp;
  350. srng->u.src_ring.hp = next_hp;
  351. /* TODO: Reap functionality is not used by all rings. If particular
  352. * ring does not use reap functionality, we need not update reap_hp
  353. * with next_hp pointer. Need to make sure a separate function is used
  354. * before doing any optimization by removing below code updating
  355. * reap_hp.
  356. */
  357. srng->u.src_ring.reap_hp = next_hp;
  358. return desc;
  359. }
  360. EXPORT_SYMBOL(ath12k_hal_srng_src_get_next_entry);
  361. void *ath12k_hal_srng_src_peek(struct ath12k_base *ab, struct hal_srng *srng)
  362. {
  363. lockdep_assert_held(&srng->lock);
  364. if (((srng->u.src_ring.hp + srng->entry_size) % srng->ring_size) ==
  365. srng->u.src_ring.cached_tp)
  366. return NULL;
  367. return srng->ring_base_vaddr + srng->u.src_ring.hp;
  368. }
  369. EXPORT_SYMBOL(ath12k_hal_srng_src_peek);
  370. void *ath12k_hal_srng_src_reap_next(struct ath12k_base *ab,
  371. struct hal_srng *srng)
  372. {
  373. void *desc;
  374. u32 next_reap_hp;
  375. lockdep_assert_held(&srng->lock);
  376. next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  377. srng->ring_size;
  378. if (next_reap_hp == srng->u.src_ring.cached_tp)
  379. return NULL;
  380. desc = srng->ring_base_vaddr + next_reap_hp;
  381. srng->u.src_ring.reap_hp = next_reap_hp;
  382. return desc;
  383. }
  384. void *ath12k_hal_srng_src_get_next_reaped(struct ath12k_base *ab,
  385. struct hal_srng *srng)
  386. {
  387. void *desc;
  388. lockdep_assert_held(&srng->lock);
  389. if (srng->u.src_ring.hp == srng->u.src_ring.reap_hp)
  390. return NULL;
  391. desc = srng->ring_base_vaddr + srng->u.src_ring.hp;
  392. srng->u.src_ring.hp = (srng->u.src_ring.hp + srng->entry_size) %
  393. srng->ring_size;
  394. return desc;
  395. }
  396. void ath12k_hal_srng_access_begin(struct ath12k_base *ab, struct hal_srng *srng)
  397. {
  398. u32 hp;
  399. lockdep_assert_held(&srng->lock);
  400. if (srng->ring_dir == HAL_SRNG_DIR_SRC) {
  401. srng->u.src_ring.cached_tp =
  402. *(volatile u32 *)srng->u.src_ring.tp_addr;
  403. } else {
  404. hp = READ_ONCE(*srng->u.dst_ring.hp_addr);
  405. if (hp != srng->u.dst_ring.cached_hp) {
  406. srng->u.dst_ring.cached_hp = hp;
  407. /* Make sure descriptor is read after the head
  408. * pointer.
  409. */
  410. dma_rmb();
  411. }
  412. }
  413. }
  414. EXPORT_SYMBOL(ath12k_hal_srng_access_begin);
  415. /* Update cached ring head/tail pointers to HW. ath12k_hal_srng_access_begin()
  416. * should have been called before this.
  417. */
  418. void ath12k_hal_srng_access_end(struct ath12k_base *ab, struct hal_srng *srng)
  419. {
  420. lockdep_assert_held(&srng->lock);
  421. if (srng->flags & HAL_SRNG_FLAGS_LMAC_RING) {
  422. /* For LMAC rings, ring pointer updates are done through FW and
  423. * hence written to a shared memory location that is read by FW
  424. */
  425. if (srng->ring_dir == HAL_SRNG_DIR_SRC) {
  426. srng->u.src_ring.last_tp =
  427. *(volatile u32 *)srng->u.src_ring.tp_addr;
  428. /* Make sure descriptor is written before updating the
  429. * head pointer.
  430. */
  431. dma_wmb();
  432. WRITE_ONCE(*srng->u.src_ring.hp_addr, srng->u.src_ring.hp);
  433. } else {
  434. srng->u.dst_ring.last_hp = *srng->u.dst_ring.hp_addr;
  435. /* Make sure descriptor is read before updating the
  436. * tail pointer.
  437. */
  438. dma_mb();
  439. WRITE_ONCE(*srng->u.dst_ring.tp_addr, srng->u.dst_ring.tp);
  440. }
  441. } else {
  442. if (srng->ring_dir == HAL_SRNG_DIR_SRC) {
  443. srng->u.src_ring.last_tp =
  444. *(volatile u32 *)srng->u.src_ring.tp_addr;
  445. /* Assume implementation use an MMIO write accessor
  446. * which has the required wmb() so that the descriptor
  447. * is written before the updating the head pointer.
  448. */
  449. ath12k_hif_write32(ab,
  450. (unsigned long)srng->u.src_ring.hp_addr -
  451. (unsigned long)ab->mem,
  452. srng->u.src_ring.hp);
  453. } else {
  454. srng->u.dst_ring.last_hp = *srng->u.dst_ring.hp_addr;
  455. /* Make sure descriptor is read before updating the
  456. * tail pointer.
  457. */
  458. mb();
  459. ath12k_hif_write32(ab,
  460. (unsigned long)srng->u.dst_ring.tp_addr -
  461. (unsigned long)ab->mem,
  462. srng->u.dst_ring.tp);
  463. }
  464. }
  465. srng->timestamp = jiffies;
  466. }
  467. EXPORT_SYMBOL(ath12k_hal_srng_access_end);
  468. int ath12k_hal_srng_setup(struct ath12k_base *ab, enum hal_ring_type type,
  469. int ring_num, int mac_id,
  470. struct hal_srng_params *params)
  471. {
  472. struct ath12k_hal *hal = &ab->hal;
  473. struct hal_srng_config *srng_config = &ab->hal.srng_config[type];
  474. struct hal_srng *srng;
  475. int ring_id;
  476. u32 idx;
  477. int i;
  478. ring_id = ath12k_hal_srng_get_ring_id(hal, type, ring_num, mac_id);
  479. if (ring_id < 0)
  480. return ring_id;
  481. srng = &hal->srng_list[ring_id];
  482. srng->ring_id = ring_id;
  483. srng->ring_dir = srng_config->ring_dir;
  484. srng->ring_base_paddr = params->ring_base_paddr;
  485. srng->ring_base_vaddr = params->ring_base_vaddr;
  486. srng->entry_size = srng_config->entry_size;
  487. srng->num_entries = params->num_entries;
  488. srng->ring_size = srng->entry_size * srng->num_entries;
  489. srng->intr_batch_cntr_thres_entries =
  490. params->intr_batch_cntr_thres_entries;
  491. srng->intr_timer_thres_us = params->intr_timer_thres_us;
  492. srng->flags = params->flags;
  493. srng->msi_addr = params->msi_addr;
  494. srng->msi2_addr = params->msi2_addr;
  495. srng->msi_data = params->msi_data;
  496. srng->msi2_data = params->msi2_data;
  497. srng->initialized = 1;
  498. spin_lock_init(&srng->lock);
  499. lockdep_set_class(&srng->lock, &srng->lock_key);
  500. for (i = 0; i < HAL_SRNG_NUM_REG_GRP; i++) {
  501. srng->hwreg_base[i] = srng_config->reg_start[i] +
  502. (ring_num * srng_config->reg_size[i]);
  503. }
  504. memset(srng->ring_base_vaddr, 0,
  505. (srng->entry_size * srng->num_entries) << 2);
  506. if (srng->ring_dir == HAL_SRNG_DIR_SRC) {
  507. srng->u.src_ring.hp = 0;
  508. srng->u.src_ring.cached_tp = 0;
  509. srng->u.src_ring.reap_hp = srng->ring_size - srng->entry_size;
  510. srng->u.src_ring.tp_addr = (void *)(hal->rdp.vaddr + ring_id);
  511. srng->u.src_ring.low_threshold = params->low_threshold *
  512. srng->entry_size;
  513. if (srng_config->mac_type == ATH12K_HAL_SRNG_UMAC) {
  514. ath12k_hal_set_umac_srng_ptr_addr(ab, srng);
  515. } else {
  516. idx = ring_id - HAL_SRNG_RING_ID_DMAC_CMN_ID_START;
  517. srng->u.src_ring.hp_addr = (void *)(hal->wrp.vaddr +
  518. idx);
  519. srng->flags |= HAL_SRNG_FLAGS_LMAC_RING;
  520. }
  521. } else {
  522. /* During initialization loop count in all the descriptors
  523. * will be set to zero, and HW will set it to 1 on completing
  524. * descriptor update in first loop, and increments it by 1 on
  525. * subsequent loops (loop count wraps around after reaching
  526. * 0xffff). The 'loop_cnt' in SW ring state is the expected
  527. * loop count in descriptors updated by HW (to be processed
  528. * by SW).
  529. */
  530. srng->u.dst_ring.loop_cnt = 1;
  531. srng->u.dst_ring.tp = 0;
  532. srng->u.dst_ring.cached_hp = 0;
  533. srng->u.dst_ring.hp_addr = (void *)(hal->rdp.vaddr + ring_id);
  534. if (srng_config->mac_type == ATH12K_HAL_SRNG_UMAC) {
  535. ath12k_hal_set_umac_srng_ptr_addr(ab, srng);
  536. } else {
  537. /* For PMAC & DMAC rings, tail pointer updates will be done
  538. * through FW by writing to a shared memory location
  539. */
  540. idx = ring_id - HAL_SRNG_RING_ID_DMAC_CMN_ID_START;
  541. srng->u.dst_ring.tp_addr = (void *)(hal->wrp.vaddr +
  542. idx);
  543. srng->flags |= HAL_SRNG_FLAGS_LMAC_RING;
  544. }
  545. }
  546. if (srng_config->mac_type != ATH12K_HAL_SRNG_UMAC)
  547. return ring_id;
  548. ath12k_hal_srng_hw_init(ab, srng);
  549. if (type == HAL_CE_DST) {
  550. srng->u.dst_ring.max_buffer_length = params->max_buffer_len;
  551. ath12k_hal_ce_dst_setup(ab, srng, ring_num);
  552. }
  553. return ring_id;
  554. }
  555. void ath12k_hal_srng_shadow_config(struct ath12k_base *ab)
  556. {
  557. struct ath12k_hal *hal = &ab->hal;
  558. int ring_type, ring_num;
  559. /* update all the non-CE srngs. */
  560. for (ring_type = 0; ring_type < HAL_MAX_RING_TYPES; ring_type++) {
  561. struct hal_srng_config *srng_config = &hal->srng_config[ring_type];
  562. if (ring_type == HAL_CE_SRC ||
  563. ring_type == HAL_CE_DST ||
  564. ring_type == HAL_CE_DST_STATUS)
  565. continue;
  566. if (srng_config->mac_type == ATH12K_HAL_SRNG_DMAC ||
  567. srng_config->mac_type == ATH12K_HAL_SRNG_PMAC)
  568. continue;
  569. for (ring_num = 0; ring_num < srng_config->max_rings; ring_num++)
  570. ath12k_hal_srng_update_shadow_config(ab, ring_type, ring_num);
  571. }
  572. }
  573. void ath12k_hal_srng_get_shadow_config(struct ath12k_base *ab,
  574. u32 **cfg, u32 *len)
  575. {
  576. struct ath12k_hal *hal = &ab->hal;
  577. *len = hal->num_shadow_reg_configured;
  578. *cfg = hal->shadow_reg_addr;
  579. }
  580. void ath12k_hal_srng_shadow_update_hp_tp(struct ath12k_base *ab,
  581. struct hal_srng *srng)
  582. {
  583. lockdep_assert_held(&srng->lock);
  584. /* check whether the ring is empty. Update the shadow
  585. * HP only when then ring isn't' empty.
  586. */
  587. if (srng->ring_dir == HAL_SRNG_DIR_SRC &&
  588. *srng->u.src_ring.tp_addr != srng->u.src_ring.hp)
  589. ath12k_hal_srng_access_end(ab, srng);
  590. }
  591. static void ath12k_hal_register_srng_lock_keys(struct ath12k_hal *hal)
  592. {
  593. u32 ring_id;
  594. for (ring_id = 0; ring_id < HAL_SRNG_RING_ID_MAX; ring_id++)
  595. lockdep_register_key(&hal->srng_list[ring_id].lock_key);
  596. }
  597. static void ath12k_hal_unregister_srng_lock_keys(struct ath12k_hal *hal)
  598. {
  599. u32 ring_id;
  600. for (ring_id = 0; ring_id < HAL_SRNG_RING_ID_MAX; ring_id++)
  601. lockdep_unregister_key(&hal->srng_list[ring_id].lock_key);
  602. }
  603. int ath12k_hal_srng_init(struct ath12k_base *ab)
  604. {
  605. struct ath12k_hal *hal = &ab->hal;
  606. int ret;
  607. ret = hal->ops->create_srng_config(hal);
  608. if (ret)
  609. goto err_hal;
  610. hal->dev = ab->dev;
  611. ret = ath12k_hal_alloc_cont_rdp(hal);
  612. if (ret)
  613. goto err_hal;
  614. ret = ath12k_hal_alloc_cont_wrp(hal);
  615. if (ret)
  616. goto err_free_cont_rdp;
  617. ath12k_hal_register_srng_lock_keys(hal);
  618. return 0;
  619. err_free_cont_rdp:
  620. ath12k_hal_free_cont_rdp(hal);
  621. err_hal:
  622. return ret;
  623. }
  624. void ath12k_hal_srng_deinit(struct ath12k_base *ab)
  625. {
  626. struct ath12k_hal *hal = &ab->hal;
  627. ath12k_hal_unregister_srng_lock_keys(hal);
  628. ath12k_hal_free_cont_rdp(hal);
  629. ath12k_hal_free_cont_wrp(hal);
  630. kfree(hal->srng_config);
  631. hal->srng_config = NULL;
  632. }
  633. void ath12k_hal_dump_srng_stats(struct ath12k_base *ab)
  634. {
  635. struct hal_srng *srng;
  636. struct ath12k_ext_irq_grp *irq_grp;
  637. struct ath12k_ce_pipe *ce_pipe;
  638. int i;
  639. ath12k_err(ab, "Last interrupt received for each CE:\n");
  640. for (i = 0; i < ab->hw_params->ce_count; i++) {
  641. ce_pipe = &ab->ce.ce_pipe[i];
  642. if (ath12k_ce_get_attr_flags(ab, i) & CE_ATTR_DIS_INTR)
  643. continue;
  644. ath12k_err(ab, "CE_id %d pipe_num %d %ums before\n",
  645. i, ce_pipe->pipe_num,
  646. jiffies_to_msecs(jiffies - ce_pipe->timestamp));
  647. }
  648. ath12k_err(ab, "\nLast interrupt received for each group:\n");
  649. for (i = 0; i < ATH12K_EXT_IRQ_GRP_NUM_MAX; i++) {
  650. irq_grp = &ab->ext_irq_grp[i];
  651. ath12k_err(ab, "group_id %d %ums before\n",
  652. irq_grp->grp_id,
  653. jiffies_to_msecs(jiffies - irq_grp->timestamp));
  654. }
  655. for (i = 0; i < HAL_SRNG_RING_ID_MAX; i++) {
  656. srng = &ab->hal.srng_list[i];
  657. if (!srng->initialized)
  658. continue;
  659. if (srng->ring_dir == HAL_SRNG_DIR_SRC)
  660. ath12k_err(ab,
  661. "src srng id %u hp %u, reap_hp %u, cur tp %u, cached tp %u last tp %u napi processed before %ums\n",
  662. srng->ring_id, srng->u.src_ring.hp,
  663. srng->u.src_ring.reap_hp,
  664. *srng->u.src_ring.tp_addr, srng->u.src_ring.cached_tp,
  665. srng->u.src_ring.last_tp,
  666. jiffies_to_msecs(jiffies - srng->timestamp));
  667. else if (srng->ring_dir == HAL_SRNG_DIR_DST)
  668. ath12k_err(ab,
  669. "dst srng id %u tp %u, cur hp %u, cached hp %u last hp %u napi processed before %ums\n",
  670. srng->ring_id, srng->u.dst_ring.tp,
  671. *srng->u.dst_ring.hp_addr,
  672. srng->u.dst_ring.cached_hp,
  673. srng->u.dst_ring.last_hp,
  674. jiffies_to_msecs(jiffies - srng->timestamp));
  675. }
  676. }
  677. void *ath12k_hal_encode_tlv64_hdr(void *tlv, u64 tag, u64 len)
  678. {
  679. struct hal_tlv_64_hdr *tlv64 = tlv;
  680. tlv64->tl = le64_encode_bits(tag, HAL_TLV_HDR_TAG) |
  681. le64_encode_bits(len, HAL_TLV_HDR_LEN);
  682. return tlv64->value;
  683. }
  684. EXPORT_SYMBOL(ath12k_hal_encode_tlv64_hdr);
  685. void *ath12k_hal_encode_tlv32_hdr(void *tlv, u64 tag, u64 len)
  686. {
  687. struct hal_tlv_hdr *tlv32 = tlv;
  688. tlv32->tl = le32_encode_bits(tag, HAL_TLV_HDR_TAG) |
  689. le32_encode_bits(len, HAL_TLV_HDR_LEN);
  690. return tlv32->value;
  691. }
  692. EXPORT_SYMBOL(ath12k_hal_encode_tlv32_hdr);
  693. u16 ath12k_hal_decode_tlv64_hdr(void *tlv, void **desc)
  694. {
  695. struct hal_tlv_64_hdr *tlv64 = tlv;
  696. u16 tag;
  697. tag = le64_get_bits(tlv64->tl, HAL_SRNG_TLV_HDR_TAG);
  698. *desc = tlv64->value;
  699. return tag;
  700. }
  701. EXPORT_SYMBOL(ath12k_hal_decode_tlv64_hdr);
  702. u16 ath12k_hal_decode_tlv32_hdr(void *tlv, void **desc)
  703. {
  704. struct hal_tlv_hdr *tlv32 = tlv;
  705. u16 tag;
  706. tag = le32_get_bits(tlv32->tl, HAL_SRNG_TLV_HDR_TAG);
  707. *desc = tlv32->value;
  708. return tag;
  709. }
  710. EXPORT_SYMBOL(ath12k_hal_decode_tlv32_hdr);