hal_api.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  1. /*
  2. * Copyright (c) 2016-2017 The Linux Foundation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above
  10. * copyright notice, this list of conditions and the following
  11. * disclaimer in the documentation and/or other materials provided
  12. * with the distribution.
  13. * * Neither the name of The Linux Foundation nor the names of its
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  21. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  24. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  25. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  26. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  27. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #ifndef _HAL_API_H_
  30. #define _HAL_API_H_
  31. #include "qdf_types.h"
  32. #include "hal_internal.h"
  33. #include "hif_io32.h"
  34. #include "rx_msdu_link.h"
  35. #include "rx_reo_queue.h"
  36. #include "rx_reo_queue_ext.h"
  37. /**
  38. * hal_attach - Initalize HAL layer
  39. * @hif_handle: Opaque HIF handle
  40. * @qdf_dev: QDF device
  41. *
  42. * Return: Opaque HAL SOC handle
  43. * NULL on failure (if given ring is not available)
  44. *
  45. * This function should be called as part of HIF initialization (for accessing
  46. * copy engines). DP layer will get hal_soc handle using hif_get_hal_handle()
  47. */
  48. extern void *hal_attach(void *hif_handle, qdf_device_t qdf_dev);
  49. /**
  50. * hal_detach - Detach HAL layer
  51. * @hal_soc: HAL SOC handle
  52. *
  53. * This function should be called as part of HIF detach
  54. *
  55. */
  56. extern void hal_detach(void *hal_soc);
  57. /* SRNG type to be passed in APIs hal_srng_get_entrysize and hal_srng_setup */
  58. enum hal_ring_type {
  59. REO_DST,
  60. REO_EXCEPTION,
  61. REO_REINJECT,
  62. REO_CMD,
  63. REO_STATUS,
  64. TCL_DATA,
  65. TCL_CMD,
  66. TCL_STATUS,
  67. CE_SRC,
  68. CE_DST,
  69. CE_DST_STATUS,
  70. WBM_IDLE_LINK,
  71. SW2WBM_RELEASE,
  72. WBM2SW_RELEASE,
  73. RXDMA_BUF,
  74. RXDMA_DST,
  75. RXDMA_MONITOR_BUF,
  76. RXDMA_MONITOR_STATUS,
  77. RXDMA_MONITOR_DST,
  78. MAX_RING_TYPES
  79. };
  80. /* SRNG flags passed in hal_srng_params.flags */
  81. #define HAL_SRNG_MSI_SWAP 0x00000008
  82. #define HAL_SRNG_RING_PTR_SWAP 0x00000010
  83. #define HAL_SRNG_DATA_TLV_SWAP 0x00000020
  84. #define HAL_SRNG_LOW_THRES_INTR_ENABLE 0x00010000
  85. #define HAL_SRNG_MSI_INTR 0x00020000
  86. /**
  87. * hal_srng_get_entrysize - Returns size of ring entry in bytes. Should be
  88. * used by callers for calculating the size of memory to be allocated before
  89. * calling hal_srng_setup to setup the ring
  90. *
  91. * @hal_soc: Opaque HAL SOC handle
  92. * @ring_type: one of the types from hal_ring_type
  93. *
  94. */
  95. extern uint32_t hal_srng_get_entrysize(void *hal_soc, int ring_type);
  96. /* SRNG parameters to be passed to hal_srng_setup */
  97. struct hal_srng_params {
  98. /* Physical base address of the ring */
  99. qdf_dma_addr_t ring_base_paddr;
  100. /* Virtual base address of the ring */
  101. void *ring_base_vaddr;
  102. /* Number of entries in ring */
  103. uint32_t num_entries;
  104. /* max transfer length */
  105. uint16_t max_buffer_length;
  106. /* MSI Address */
  107. qdf_dma_addr_t msi_addr;
  108. /* MSI data */
  109. uint32_t msi_data;
  110. /* Interrupt timer threshold – in micro seconds */
  111. uint32_t intr_timer_thres_us;
  112. /* Interrupt batch counter threshold – in number of ring entries */
  113. uint32_t intr_batch_cntr_thres_entries;
  114. /* Low threshold – in number of ring entries
  115. * (valid for src rings only)
  116. */
  117. uint32_t low_threshold;
  118. /* Misc flags */
  119. uint32_t flags;
  120. /* Unique ring id */
  121. uint8_t ring_id;
  122. };
  123. /* hal_construct_shadow_config() - initialize the shadow registers for dp rings
  124. * @hal_soc: hal handle
  125. *
  126. * Return: QDF_STATUS_OK on success
  127. */
  128. extern QDF_STATUS hal_construct_shadow_config(void *hal_soc);
  129. /* hal_set_one_shadow_config() - add a config for the specified ring
  130. * @hal_soc: hal handle
  131. * @ring_type: ring type
  132. * @ring_num: ring num
  133. *
  134. * The ring type and ring num uniquely specify the ring. After this call,
  135. * the hp/tp will be added as the next entry int the shadow register
  136. * configuration table. The hal code will use the shadow register address
  137. * in place of the hp/tp address.
  138. *
  139. * This function is exposed, so that the CE module can skip configuring shadow
  140. * registers for unused ring and rings assigned to the firmware.
  141. *
  142. * Return: QDF_STATUS_OK on success
  143. */
  144. extern QDF_STATUS hal_set_one_shadow_config(void *hal_soc, int ring_type,
  145. int ring_num);
  146. /**
  147. * hal_get_shadow_config() - retrieve the config table
  148. * @hal_soc: hal handle
  149. * @shadow_config: will point to the table after
  150. * @num_shadow_registers_configured: will contain the number of valid entries
  151. */
  152. extern void hal_get_shadow_config(void *hal_soc,
  153. struct pld_shadow_reg_v2_cfg **shadow_config,
  154. int *num_shadow_registers_configured);
  155. /**
  156. * hal_srng_setup - Initalize HW SRNG ring.
  157. *
  158. * @hal_soc: Opaque HAL SOC handle
  159. * @ring_type: one of the types from hal_ring_type
  160. * @ring_num: Ring number if there are multiple rings of
  161. * same type (staring from 0)
  162. * @mac_id: valid MAC Id should be passed if ring type is one of lmac rings
  163. * @ring_params: SRNG ring params in hal_srng_params structure.
  164. * Callers are expected to allocate contiguous ring memory of size
  165. * 'num_entries * entry_size' bytes and pass the physical and virtual base
  166. * addresses through 'ring_base_paddr' and 'ring_base_vaddr' in hal_srng_params
  167. * structure. Ring base address should be 8 byte aligned and size of each ring
  168. * entry should be queried using the API hal_srng_get_entrysize
  169. *
  170. * Return: Opaque pointer to ring on success
  171. * NULL on failure (if given ring is not available)
  172. */
  173. extern void *hal_srng_setup(void *hal_soc, int ring_type, int ring_num,
  174. int mac_id, struct hal_srng_params *ring_params);
  175. /**
  176. * hal_srng_cleanup - Deinitialize HW SRNG ring.
  177. * @hal_soc: Opaque HAL SOC handle
  178. * @hal_srng: Opaque HAL SRNG pointer
  179. */
  180. extern void hal_srng_cleanup(void *hal_soc, void *hal_srng);
  181. /**
  182. * hal_srng_access_start_unlocked - Start ring access (unlocked). Should use
  183. * hal_srng_access_start if locked access is required
  184. *
  185. * @hal_soc: Opaque HAL SOC handle
  186. * @hal_ring: Ring pointer (Source or Destination ring)
  187. *
  188. * Return: 0 on success; error on failire
  189. */
  190. static inline int hal_srng_access_start_unlocked(void *hal_soc, void *hal_ring)
  191. {
  192. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  193. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  194. srng->u.src_ring.cached_tp =
  195. *(volatile uint32_t *)(srng->u.src_ring.tp_addr);
  196. else
  197. srng->u.dst_ring.cached_hp =
  198. *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  199. return 0;
  200. }
  201. /**
  202. * hal_srng_access_start - Start (locked) ring access
  203. *
  204. * @hal_soc: Opaque HAL SOC handle
  205. * @hal_ring: Ring pointer (Source or Destination ring)
  206. *
  207. * Return: 0 on success; error on failire
  208. */
  209. static inline int hal_srng_access_start(void *hal_soc, void *hal_ring)
  210. {
  211. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  212. SRNG_LOCK(&(srng->lock));
  213. return hal_srng_access_start_unlocked(hal_soc, hal_ring);
  214. }
  215. /**
  216. * hal_srng_dst_get_next - Get next entry from a destination ring and move
  217. * cached tail pointer
  218. *
  219. * @hal_soc: Opaque HAL SOC handle
  220. * @hal_ring: Destination ring pointer
  221. *
  222. * Return: Opaque pointer for next ring entry; NULL on failire
  223. */
  224. static inline void *hal_srng_dst_get_next(void *hal_soc, void *hal_ring)
  225. {
  226. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  227. volatile uint32_t *desc = &(srng->ring_base_vaddr[srng->u.dst_ring.tp]);
  228. uint32_t desc_loop_cnt;
  229. desc_loop_cnt = (desc[srng->entry_size - 1] & SRNG_LOOP_CNT_MASK)
  230. >> SRNG_LOOP_CNT_LSB;
  231. if (srng->u.dst_ring.loop_cnt == desc_loop_cnt) {
  232. /* TODO: Using % is expensive, but we have to do this since
  233. * size of some SRNG rings is not power of 2 (due to descriptor
  234. * sizes). Need to create separate API for rings used
  235. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  236. * SW2RXDMA and CE rings)
  237. */
  238. srng->u.dst_ring.tp = (srng->u.dst_ring.tp + srng->entry_size) %
  239. srng->ring_size;
  240. srng->u.dst_ring.loop_cnt = (srng->u.dst_ring.loop_cnt +
  241. !srng->u.dst_ring.tp) &
  242. (SRNG_LOOP_CNT_MASK >> SRNG_LOOP_CNT_LSB);
  243. /* TODO: Confirm if loop count mask is same for all rings */
  244. return (void *)desc;
  245. }
  246. return NULL;
  247. }
  248. /**
  249. * hal_srng_dst_peek - Get next entry from a ring without moving tail pointer.
  250. * hal_srng_dst_get_next should be called subsequently to move the tail pointer
  251. * TODO: See if we need an optimized version of get_next that doesn't check for
  252. * loop_cnt
  253. *
  254. * @hal_soc: Opaque HAL SOC handle
  255. * @hal_ring: Destination ring pointer
  256. *
  257. * Return: Opaque pointer for next ring entry; NULL on failire
  258. */
  259. static inline void *hal_srng_dst_peek(void *hal_soc, void *hal_ring)
  260. {
  261. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  262. uint32_t *desc = &(srng->ring_base_vaddr[srng->u.dst_ring.tp]);
  263. uint32_t desc_loop_cnt;
  264. desc_loop_cnt = (desc[srng->entry_size - 1] & SRNG_LOOP_CNT_MASK)
  265. >> SRNG_LOOP_CNT_LSB;
  266. if (srng->u.dst_ring.loop_cnt == desc_loop_cnt)
  267. return (void *)desc;
  268. return NULL;
  269. }
  270. /**
  271. * hal_srng_dst_num_valid - Returns number of valid entries (to be processed
  272. * by SW) in destination ring
  273. *
  274. * @hal_soc: Opaque HAL SOC handle
  275. * @hal_ring: Destination ring pointer
  276. * @sync_hw_ptr: Sync cached head pointer with HW
  277. *
  278. */
  279. static inline uint32_t hal_srng_dst_num_valid(void *hal_soc, void *hal_ring,
  280. int sync_hw_ptr)
  281. {
  282. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  283. uint32 hp;
  284. uint32 tp = srng->u.dst_ring.tp;
  285. if (sync_hw_ptr) {
  286. hp = *(srng->u.dst_ring.hp_addr);
  287. srng->u.dst_ring.cached_hp = hp;
  288. } else {
  289. hp = srng->u.dst_ring.cached_hp;
  290. }
  291. if (hp >= tp)
  292. return (hp - tp) / srng->entry_size;
  293. else
  294. return (srng->ring_size - tp + hp) / srng->entry_size;
  295. }
  296. /**
  297. * hal_srng_src_reap_next - Reap next entry from a source ring and move reap
  298. * pointer. This can be used to release any buffers associated with completed
  299. * ring entries. Note that this should not be used for posting new descriptor
  300. * entries. Posting of new entries should be done only using
  301. * hal_srng_src_get_next_reaped when this function is used for reaping.
  302. *
  303. * @hal_soc: Opaque HAL SOC handle
  304. * @hal_ring: Source ring pointer
  305. *
  306. * Return: Opaque pointer for next ring entry; NULL on failire
  307. */
  308. static inline void *hal_srng_src_reap_next(void *hal_soc, void *hal_ring)
  309. {
  310. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  311. uint32_t *desc;
  312. /* TODO: Using % is expensive, but we have to do this since
  313. * size of some SRNG rings is not power of 2 (due to descriptor
  314. * sizes). Need to create separate API for rings used
  315. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  316. * SW2RXDMA and CE rings)
  317. */
  318. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  319. srng->ring_size;
  320. if (next_reap_hp != srng->u.src_ring.cached_tp) {
  321. desc = &(srng->ring_base_vaddr[next_reap_hp]);
  322. srng->u.src_ring.reap_hp = next_reap_hp;
  323. return (void *)desc;
  324. }
  325. return NULL;
  326. }
  327. /**
  328. * hal_srng_src_get_next_reaped - Get next entry from a source ring that is
  329. * already reaped using hal_srng_src_reap_next, for posting new entries to
  330. * the ring
  331. *
  332. * @hal_soc: Opaque HAL SOC handle
  333. * @hal_ring: Source ring pointer
  334. *
  335. * Return: Opaque pointer for next (reaped) source ring entry; NULL on failire
  336. */
  337. static inline void *hal_srng_src_get_next_reaped(void *hal_soc, void *hal_ring)
  338. {
  339. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  340. uint32_t *desc;
  341. if (srng->u.src_ring.hp != srng->u.src_ring.reap_hp) {
  342. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  343. srng->u.src_ring.hp = (srng->u.src_ring.hp + srng->entry_size) %
  344. srng->ring_size;
  345. return (void *)desc;
  346. }
  347. return NULL;
  348. }
  349. /**
  350. * hal_srng_src_done_val -
  351. *
  352. * @hal_soc: Opaque HAL SOC handle
  353. * @hal_ring: Source ring pointer
  354. *
  355. * Return: Opaque pointer for next ring entry; NULL on failire
  356. */
  357. static inline uint32_t hal_srng_src_done_val(void *hal_soc, void *hal_ring)
  358. {
  359. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  360. /* TODO: Using % is expensive, but we have to do this since
  361. * size of some SRNG rings is not power of 2 (due to descriptor
  362. * sizes). Need to create separate API for rings used
  363. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  364. * SW2RXDMA and CE rings)
  365. */
  366. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  367. srng->ring_size;
  368. if (next_reap_hp == srng->u.src_ring.cached_tp)
  369. return 0;
  370. if (srng->u.src_ring.cached_tp > next_reap_hp)
  371. return (srng->u.src_ring.cached_tp - next_reap_hp) /
  372. srng->entry_size;
  373. else
  374. return ((srng->ring_size - next_reap_hp) +
  375. srng->u.src_ring.cached_tp) / srng->entry_size;
  376. }
  377. /**
  378. * hal_srng_src_get_next - Get next entry from a source ring and move cached tail pointer
  379. *
  380. * @hal_soc: Opaque HAL SOC handle
  381. * @hal_ring: Source ring pointer
  382. *
  383. * Return: Opaque pointer for next ring entry; NULL on failire
  384. */
  385. static inline void *hal_srng_src_get_next(void *hal_soc, void *hal_ring)
  386. {
  387. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  388. uint32_t *desc;
  389. /* TODO: Using % is expensive, but we have to do this since
  390. * size of some SRNG rings is not power of 2 (due to descriptor
  391. * sizes). Need to create separate API for rings used
  392. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  393. * SW2RXDMA and CE rings)
  394. */
  395. uint32_t next_hp = (srng->u.src_ring.hp + srng->entry_size) %
  396. srng->ring_size;
  397. if (next_hp != srng->u.src_ring.cached_tp) {
  398. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  399. srng->u.src_ring.hp = next_hp;
  400. /* TODO: Since reap function is not used by all rings, we can
  401. * remove the following update of reap_hp in this function
  402. * if we can ensure that only hal_srng_src_get_next_reaped
  403. * is used for the rings requiring reap functionality
  404. */
  405. srng->u.src_ring.reap_hp = next_hp;
  406. return (void *)desc;
  407. }
  408. return NULL;
  409. }
  410. /**
  411. * hal_srng_src_peek - Get next entry from a ring without moving head pointer.
  412. * hal_srng_src_get_next should be called subsequently to move the head pointer
  413. *
  414. * @hal_soc: Opaque HAL SOC handle
  415. * @hal_ring: Source ring pointer
  416. *
  417. * Return: Opaque pointer for next ring entry; NULL on failire
  418. */
  419. static inline void *hal_srng_src_peek(void *hal_soc, void *hal_ring)
  420. {
  421. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  422. uint32_t *desc;
  423. /* TODO: Using % is expensive, but we have to do this since
  424. * size of some SRNG rings is not power of 2 (due to descriptor
  425. * sizes). Need to create separate API for rings used
  426. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  427. * SW2RXDMA and CE rings)
  428. */
  429. if (((srng->u.src_ring.hp + srng->entry_size) %
  430. srng->ring_size) != srng->u.src_ring.cached_tp) {
  431. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  432. return (void *)desc;
  433. }
  434. return NULL;
  435. }
  436. /**
  437. * hal_srng_src_num_avail - Returns number of available entries in src ring
  438. *
  439. * @hal_soc: Opaque HAL SOC handle
  440. * @hal_ring: Source ring pointer
  441. * @sync_hw_ptr: Sync cached tail pointer with HW
  442. *
  443. */
  444. static inline uint32_t hal_srng_src_num_avail(void *hal_soc,
  445. void *hal_ring, int sync_hw_ptr)
  446. {
  447. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  448. uint32 tp;
  449. uint32 hp = srng->u.src_ring.hp;
  450. if (sync_hw_ptr) {
  451. tp = *(srng->u.src_ring.tp_addr);
  452. srng->u.src_ring.cached_tp = tp;
  453. } else {
  454. tp = srng->u.src_ring.cached_tp;
  455. }
  456. if (tp > hp)
  457. return ((tp - hp) / srng->entry_size) - 1;
  458. else
  459. return ((srng->ring_size - hp + tp) / srng->entry_size) - 1;
  460. }
  461. /**
  462. * hal_srng_access_end_unlocked - End ring access (unlocked) - update cached
  463. * ring head/tail pointers to HW.
  464. * This should be used only if hal_srng_access_start_unlocked to start ring
  465. * access
  466. *
  467. * @hal_soc: Opaque HAL SOC handle
  468. * @hal_ring: Ring pointer (Source or Destination ring)
  469. *
  470. * Return: 0 on success; error on failire
  471. */
  472. static inline void hal_srng_access_end_unlocked(void *hal_soc, void *hal_ring)
  473. {
  474. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  475. /* TODO: See if we need a write memory barrier here */
  476. if (srng->flags & HAL_SRNG_LMAC_RING) {
  477. /* For LMAC rings, ring pointer updates are done through FW and
  478. * hence written to a shared memory location that is read by FW
  479. */
  480. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  481. *(srng->u.src_ring.hp_addr) = srng->u.src_ring.hp;
  482. else
  483. *(srng->u.src_ring.tp_addr) = srng->u.dst_ring.tp;
  484. } else {
  485. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  486. hif_write32_mb(srng->u.src_ring.hp_addr,
  487. srng->u.src_ring.hp);
  488. else
  489. hif_write32_mb(srng->u.dst_ring.tp_addr,
  490. srng->u.dst_ring.tp);
  491. }
  492. }
  493. /**
  494. * hal_srng_access_end - Unlock ring access and update cached ring head/tail
  495. * pointers to HW
  496. * This should be used only if hal_srng_access_start to start ring access
  497. *
  498. * @hal_soc: Opaque HAL SOC handle
  499. * @hal_ring: Ring pointer (Source or Destination ring)
  500. *
  501. * Return: 0 on success; error on failire
  502. */
  503. static inline void hal_srng_access_end(void *hal_soc, void *hal_ring)
  504. {
  505. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  506. hal_srng_access_end_unlocked(hal_soc, hal_ring);
  507. SRNG_UNLOCK(&(srng->lock));
  508. }
  509. /**
  510. * hal_srng_access_end_reap - Unlock ring access
  511. * This should be used only if hal_srng_access_start to start ring access
  512. * and should be used only while reaping SRC ring completions
  513. *
  514. * @hal_soc: Opaque HAL SOC handle
  515. * @hal_ring: Ring pointer (Source or Destination ring)
  516. *
  517. * Return: 0 on success; error on failire
  518. */
  519. static inline void hal_srng_access_end_reap(void *hal_soc, void *hal_ring)
  520. {
  521. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  522. SRNG_UNLOCK(&(srng->lock));
  523. }
  524. /* TODO: Check if the following definitions is available in HW headers */
  525. #define WBM_IDLE_DESC_LIST 1
  526. #define WBM_IDLE_SCATTER_BUF_SIZE 32704
  527. #define NUM_MPDUS_PER_LINK_DESC 6
  528. #define NUM_MSDUS_PER_LINK_DESC 7
  529. #define REO_QUEUE_DESC_ALIGN 128
  530. #define LINK_DESC_SIZE (NUM_OF_DWORDS_RX_MSDU_LINK << 2)
  531. #define LINK_DESC_ALIGN 128
  532. /* Number of mpdu link pointers is 9 in case of TX_MPDU_QUEUE_HEAD and 14 in
  533. * of TX_MPDU_QUEUE_EXT. We are defining a common average count here
  534. */
  535. #define NUM_MPDU_LINKS_PER_QUEUE_DESC 12
  536. /* TODO: Check with HW team on the scatter buffer size supported. As per WBM
  537. * MLD, scatter_buffer_size in IDLE_LIST_CONTROL register is 9 bits and size
  538. * should be specified in 16 word units. But the number of bits defined for
  539. * this field in HW header files is 5.
  540. */
  541. #define WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE 8
  542. /**
  543. * hal_set_link_desc_addr - Setup link descriptor in a buffer_addr_info
  544. * HW structure
  545. *
  546. * @desc: Descriptor entry (from WBM_IDLE_LINK ring)
  547. * @cookie: SW cookie for the buffer/descriptor
  548. * @link_desc_paddr: Physical address of link descriptor entry
  549. *
  550. */
  551. static inline void hal_set_link_desc_addr(void *desc, uint32_t cookie,
  552. qdf_dma_addr_t link_desc_paddr)
  553. {
  554. uint32_t *buf_addr = (uint32_t *)desc;
  555. HAL_DESC_SET_FIELD(buf_addr, BUFFER_ADDR_INFO_0, BUFFER_ADDR_31_0,
  556. link_desc_paddr & 0xffffffff);
  557. HAL_DESC_SET_FIELD(buf_addr, BUFFER_ADDR_INFO_1, BUFFER_ADDR_39_32,
  558. (uint64_t)link_desc_paddr >> 32);
  559. HAL_DESC_SET_FIELD(buf_addr, BUFFER_ADDR_INFO_1, RETURN_BUFFER_MANAGER,
  560. WBM_IDLE_DESC_LIST);
  561. HAL_DESC_SET_FIELD(buf_addr, BUFFER_ADDR_INFO_1, SW_BUFFER_COOKIE,
  562. cookie);
  563. }
  564. /**
  565. * hal_idle_list_scatter_buf_size - Get the size of each scatter buffer
  566. * in an idle list
  567. *
  568. * @hal_soc: Opaque HAL SOC handle
  569. *
  570. */
  571. static inline uint32_t hal_idle_list_scatter_buf_size(void *hal_soc)
  572. {
  573. return WBM_IDLE_SCATTER_BUF_SIZE;
  574. }
  575. /**
  576. * hal_get_link_desc_size - Get the size of each link descriptor
  577. *
  578. * @hal_soc: Opaque HAL SOC handle
  579. *
  580. */
  581. static inline uint32_t hal_get_link_desc_size(void *hal_soc)
  582. {
  583. return LINK_DESC_SIZE;
  584. }
  585. /**
  586. * hal_get_link_desc_align - Get the required start address alignment for
  587. * link descriptors
  588. *
  589. * @hal_soc: Opaque HAL SOC handle
  590. *
  591. */
  592. static inline uint32_t hal_get_link_desc_align(void *hal_soc)
  593. {
  594. return LINK_DESC_ALIGN;
  595. }
  596. /**
  597. * hal_num_mpdus_per_link_desc - Get number of mpdus each link desc can hold
  598. *
  599. * @hal_soc: Opaque HAL SOC handle
  600. *
  601. */
  602. static inline uint32_t hal_num_mpdus_per_link_desc(void *hal_soc)
  603. {
  604. return NUM_MPDUS_PER_LINK_DESC;
  605. }
  606. /**
  607. * hal_num_msdus_per_link_desc - Get number of msdus each link desc can hold
  608. *
  609. * @hal_soc: Opaque HAL SOC handle
  610. *
  611. */
  612. static inline uint32_t hal_num_msdus_per_link_desc(void *hal_soc)
  613. {
  614. return NUM_MSDUS_PER_LINK_DESC;
  615. }
  616. /**
  617. * hal_num_mpdu_links_per_queue_desc - Get number of mpdu links each queue
  618. * descriptor can hold
  619. *
  620. * @hal_soc: Opaque HAL SOC handle
  621. *
  622. */
  623. static inline uint32_t hal_num_mpdu_links_per_queue_desc(void *hal_soc)
  624. {
  625. return NUM_MPDU_LINKS_PER_QUEUE_DESC;
  626. }
  627. /**
  628. * hal_idle_list_scatter_buf_num_entries - Get the number of link desc entries
  629. * that the given buffer size
  630. *
  631. * @hal_soc: Opaque HAL SOC handle
  632. * @scatter_buf_size: Size of scatter buffer
  633. *
  634. */
  635. static inline uint32_t hal_idle_scatter_buf_num_entries(void *hal_soc,
  636. uint32_t scatter_buf_size)
  637. {
  638. return (scatter_buf_size - WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE) /
  639. hal_srng_get_entrysize(hal_soc, WBM_IDLE_LINK);
  640. }
  641. /**
  642. * hal_idle_scatter_buf_setup - Setup scattered idle list using the buffer list
  643. * provided
  644. *
  645. * @hal_soc: Opaque HAL SOC handle
  646. * @idle_scatter_bufs_base_paddr: Array of physical base addresses
  647. * @idle_scatter_bufs_base_vaddr: Array of virtual base addresses
  648. * @num_scatter_bufs: Number of scatter buffers in the above lists
  649. * @scatter_buf_size: Size of each scatter buffer
  650. *
  651. */
  652. extern void hal_setup_link_idle_list(void *hal_soc,
  653. qdf_dma_addr_t scatter_bufs_base_paddr[],
  654. void *scatter_bufs_base_vaddr[], uint32_t num_scatter_bufs,
  655. uint32_t scatter_buf_size, uint32_t last_buf_end_offset);
  656. /**
  657. * hal_reo_setup - Initialize HW REO block
  658. *
  659. * @hal_soc: Opaque HAL SOC handle
  660. */
  661. extern void hal_reo_setup(void *hal_soc);
  662. enum hal_pn_type {
  663. HAL_PN_NONE,
  664. HAL_PN_WPA,
  665. HAL_PN_WAPI_EVEN,
  666. HAL_PN_WAPI_UNEVEN,
  667. };
  668. #define HAL_RX_MAX_BA_WINDOW 256
  669. /**
  670. * hal_get_reo_qdesc_size - Get size of reo queue descriptor
  671. *
  672. * @hal_soc: Opaque HAL SOC handle
  673. * @ba_window_size: BlockAck window size
  674. *
  675. */
  676. static inline uint32_t hal_get_reo_qdesc_size(void *hal_soc,
  677. uint32_t ba_window_size)
  678. {
  679. if (ba_window_size <= 1)
  680. return sizeof(struct rx_reo_queue);
  681. if (ba_window_size <= 105)
  682. return sizeof(struct rx_reo_queue) +
  683. sizeof(struct rx_reo_queue_ext);
  684. if (ba_window_size <= 210)
  685. return sizeof(struct rx_reo_queue) +
  686. (2 * sizeof(struct rx_reo_queue_ext));
  687. return sizeof(struct rx_reo_queue) +
  688. (3 * sizeof(struct rx_reo_queue_ext));
  689. }
  690. /**
  691. * hal_get_reo_qdesc_align - Get start address alignment for reo
  692. * queue descriptors
  693. *
  694. * @hal_soc: Opaque HAL SOC handle
  695. *
  696. */
  697. static inline uint32_t hal_get_reo_qdesc_align(void *hal_soc)
  698. {
  699. return REO_QUEUE_DESC_ALIGN;
  700. }
  701. /**
  702. * hal_reo_qdesc_setup - Setup HW REO queue descriptor
  703. *
  704. * @hal_soc: Opaque HAL SOC handle
  705. * @ba_window_size: BlockAck window size
  706. * @start_seq: Starting sequence number
  707. * @hw_qdesc_vaddr: Virtual address of REO queue descriptor memory
  708. * @hw_qdesc_paddr: Physical address of REO queue descriptor memory
  709. * @pn_type: PN type (one of the types defined in 'enum hal_pn_type')
  710. *
  711. */
  712. extern void hal_reo_qdesc_setup(void *hal_soc, int tid, uint32_t ba_window_size,
  713. uint32_t start_seq, void *hw_qdesc_vaddr, qdf_dma_addr_t hw_qdesc_paddr,
  714. int pn_type);
  715. /**
  716. * hal_srng_get_hp_addr - Get head pointer physical address
  717. *
  718. * @hal_soc: Opaque HAL SOC handle
  719. * @hal_ring: Ring pointer (Source or Destination ring)
  720. *
  721. */
  722. static inline qdf_dma_addr_t hal_srng_get_hp_addr(void *hal_soc, void *hal_ring)
  723. {
  724. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  725. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  726. if (!(srng->flags & HAL_SRNG_LMAC_RING)) {
  727. /* Currently this interface is required only for LMAC rings */
  728. return (qdf_dma_addr_t)NULL;
  729. }
  730. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  731. return hal->shadow_wrptr_mem_paddr +
  732. ((unsigned long)(srng->u.src_ring.hp_addr) -
  733. (unsigned long)(hal->shadow_wrptr_mem_vaddr));
  734. } else {
  735. return hal->shadow_rdptr_mem_paddr +
  736. ((unsigned long)(srng->u.dst_ring.hp_addr) -
  737. (unsigned long)(hal->shadow_rdptr_mem_vaddr));
  738. }
  739. }
  740. /**
  741. * hal_srng_get_tp_addr - Get tail pointer physical address
  742. *
  743. * @hal_soc: Opaque HAL SOC handle
  744. * @hal_ring: Ring pointer (Source or Destination ring)
  745. *
  746. */
  747. static inline qdf_dma_addr_t hal_srng_get_tp_addr(void *hal_soc, void *hal_ring)
  748. {
  749. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  750. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  751. if (!(srng->flags & HAL_SRNG_LMAC_RING)) {
  752. /* Currently this interface is required only for LMAC rings */
  753. return (qdf_dma_addr_t)NULL;
  754. }
  755. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  756. return hal->shadow_rdptr_mem_paddr +
  757. ((unsigned long)(srng->u.src_ring.tp_addr) -
  758. (unsigned long)(hal->shadow_rdptr_mem_vaddr));
  759. } else {
  760. return hal->shadow_wrptr_mem_paddr +
  761. ((unsigned long)(srng->u.dst_ring.tp_addr) -
  762. (unsigned long)(hal->shadow_wrptr_mem_vaddr));
  763. }
  764. }
  765. /**
  766. * hal_get_srng_params - Retreive SRNG parameters for a given ring from HAL
  767. *
  768. * @hal_soc: Opaque HAL SOC handle
  769. * @hal_ring: Ring pointer (Source or Destination ring)
  770. * @ring_params: SRNG parameters will be returned through this structure
  771. */
  772. extern void hal_get_srng_params(void *hal_soc, void *hal_ring,
  773. struct hal_srng_params *ring_params);
  774. #endif /* _HAL_API_H_ */