hal_api.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  1. /*
  2. * Copyright (c) 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. /**
  124. * hal_srng_setup - Initalize HW SRNG ring.
  125. *
  126. * @hal_soc: Opaque HAL SOC handle
  127. * @ring_type: one of the types from hal_ring_type
  128. * @ring_num: Ring number if there are multiple rings of
  129. * same type (staring from 0)
  130. * @mac_id: valid MAC Id should be passed if ring type is one of lmac rings
  131. * @ring_params: SRNG ring params in hal_srng_params structure.
  132. * Callers are expected to allocate contiguous ring memory of size
  133. * 'num_entries * entry_size' bytes and pass the physical and virtual base
  134. * addresses through 'ring_base_paddr' and 'ring_base_vaddr' in hal_srng_params
  135. * structure. Ring base address should be 8 byte aligned and size of each ring
  136. * entry should be queried using the API hal_srng_get_entrysize
  137. *
  138. * Return: Opaque pointer to ring on success
  139. * NULL on failure (if given ring is not available)
  140. */
  141. extern void *hal_srng_setup(void *hal_soc, int ring_type, int ring_num,
  142. int mac_id, struct hal_srng_params *ring_params);
  143. /**
  144. * hal_srng_cleanup - Deinitialize HW SRNG ring.
  145. * @hal_soc: Opaque HAL SOC handle
  146. * @hal_srng: Opaque HAL SRNG pointer
  147. */
  148. extern void hal_srng_cleanup(void *hal_soc, void *hal_srng);
  149. /**
  150. * hal_srng_access_start_unlocked - Start ring access (unlocked). Should use
  151. * hal_srng_access_start if locked access is required
  152. *
  153. * @hal_soc: Opaque HAL SOC handle
  154. * @hal_ring: Ring pointer (Source or Destination ring)
  155. *
  156. * Return: 0 on success; error on failire
  157. */
  158. static inline int hal_srng_access_start_unlocked(void *hal_soc, void *hal_ring)
  159. {
  160. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  161. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  162. srng->u.src_ring.cached_tp =
  163. *(volatile uint32_t *)(srng->u.src_ring.tp_addr);
  164. else
  165. srng->u.dst_ring.cached_hp =
  166. *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  167. return 0;
  168. }
  169. /**
  170. * hal_srng_access_start - Start (locked) ring access
  171. *
  172. * @hal_soc: Opaque HAL SOC handle
  173. * @hal_ring: Ring pointer (Source or Destination ring)
  174. *
  175. * Return: 0 on success; error on failire
  176. */
  177. static inline int hal_srng_access_start(void *hal_soc, void *hal_ring)
  178. {
  179. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  180. SRNG_LOCK(&(srng->lock));
  181. return hal_srng_access_start_unlocked(hal_soc, hal_ring);
  182. }
  183. /**
  184. * hal_srng_dst_get_next - Get next entry from a destination ring and move
  185. * cached tail pointer
  186. *
  187. * @hal_soc: Opaque HAL SOC handle
  188. * @hal_ring: Destination ring pointer
  189. *
  190. * Return: Opaque pointer for next ring entry; NULL on failire
  191. */
  192. static inline void *hal_srng_dst_get_next(void *hal_soc, void *hal_ring)
  193. {
  194. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  195. volatile uint32_t *desc = &(srng->ring_base_vaddr[srng->u.dst_ring.tp]);
  196. uint32_t desc_loop_cnt;
  197. desc_loop_cnt = (desc[srng->entry_size - 1] & SRNG_LOOP_CNT_MASK)
  198. >> SRNG_LOOP_CNT_LSB;
  199. if (srng->u.dst_ring.loop_cnt == desc_loop_cnt) {
  200. /* TODO: Using % is expensive, but we have to do this since
  201. * size of some SRNG rings is not power of 2 (due to descriptor
  202. * sizes). Need to create separate API for rings used
  203. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  204. * SW2RXDMA and CE rings)
  205. */
  206. srng->u.dst_ring.tp = (srng->u.dst_ring.tp + srng->entry_size) %
  207. srng->ring_size;
  208. srng->u.dst_ring.loop_cnt = (srng->u.dst_ring.loop_cnt +
  209. !srng->u.dst_ring.tp) &
  210. (SRNG_LOOP_CNT_MASK >> SRNG_LOOP_CNT_LSB);
  211. /* TODO: Confirm if loop count mask is same for all rings */
  212. return (void *)desc;
  213. }
  214. return NULL;
  215. }
  216. /**
  217. * hal_srng_dst_peek - Get next entry from a ring without moving tail pointer.
  218. * hal_srng_dst_get_next should be called subsequently to move the tail pointer
  219. * TODO: See if we need an optimized version of get_next that doesn't check for
  220. * loop_cnt
  221. *
  222. * @hal_soc: Opaque HAL SOC handle
  223. * @hal_ring: Destination ring pointer
  224. *
  225. * Return: Opaque pointer for next ring entry; NULL on failire
  226. */
  227. static inline void *hal_srng_dst_peek(void *hal_soc, void *hal_ring)
  228. {
  229. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  230. uint32_t *desc = &(srng->ring_base_vaddr[srng->u.dst_ring.tp]);
  231. uint32_t desc_loop_cnt;
  232. desc_loop_cnt = (desc[srng->entry_size - 1] & SRNG_LOOP_CNT_MASK)
  233. >> SRNG_LOOP_CNT_LSB;
  234. if (srng->u.dst_ring.loop_cnt == desc_loop_cnt)
  235. return (void *)desc;
  236. return NULL;
  237. }
  238. /**
  239. * hal_srng_dst_num_valid - Returns number of valid entries (to be processed
  240. * by SW) in destination ring
  241. *
  242. * @hal_soc: Opaque HAL SOC handle
  243. * @hal_ring: Destination ring pointer
  244. * @sync_hw_ptr: Sync cached head pointer with HW
  245. *
  246. */
  247. static inline uint32_t hal_srng_dst_num_valid(void *hal_soc, void *hal_ring,
  248. int sync_hw_ptr)
  249. {
  250. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  251. uint32 hp;
  252. uint32 tp = srng->u.dst_ring.tp;
  253. if (sync_hw_ptr) {
  254. hp = *(srng->u.dst_ring.hp_addr);
  255. srng->u.dst_ring.cached_hp = hp;
  256. } else {
  257. hp = srng->u.dst_ring.cached_hp;
  258. }
  259. if (hp >= tp)
  260. return (hp - tp) / srng->entry_size;
  261. else
  262. return (srng->ring_size - tp + hp) / srng->entry_size;
  263. }
  264. /**
  265. * hal_srng_src_reap_next - Reap next entry from a source ring and move reap
  266. * pointer. This can be used to release any buffers associated with completed
  267. * ring entries. Note that this should not be used for posting new descriptor
  268. * entries. Posting of new entries should be done only using
  269. * hal_srng_src_get_next_reaped when this function is used for reaping.
  270. *
  271. * @hal_soc: Opaque HAL SOC handle
  272. * @hal_ring: Source ring pointer
  273. *
  274. * Return: Opaque pointer for next ring entry; NULL on failire
  275. */
  276. static inline void *hal_srng_src_reap_next(void *hal_soc, void *hal_ring)
  277. {
  278. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  279. uint32_t *desc;
  280. /* TODO: Using % is expensive, but we have to do this since
  281. * size of some SRNG rings is not power of 2 (due to descriptor
  282. * sizes). Need to create separate API for rings used
  283. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  284. * SW2RXDMA and CE rings)
  285. */
  286. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  287. srng->ring_size;
  288. if (next_reap_hp != srng->u.src_ring.cached_tp) {
  289. desc = &(srng->ring_base_vaddr[next_reap_hp]);
  290. srng->u.src_ring.reap_hp = next_reap_hp;
  291. return (void *)desc;
  292. }
  293. return NULL;
  294. }
  295. /**
  296. * hal_srng_src_get_next_reaped - Get next entry from a source ring that is
  297. * already reaped using hal_srng_src_reap_next, for posting new entries to
  298. * the ring
  299. *
  300. * @hal_soc: Opaque HAL SOC handle
  301. * @hal_ring: Source ring pointer
  302. *
  303. * Return: Opaque pointer for next (reaped) source ring entry; NULL on failire
  304. */
  305. static inline void *hal_srng_src_get_next_reaped(void *hal_soc, void *hal_ring)
  306. {
  307. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  308. uint32_t *desc;
  309. if (srng->u.src_ring.hp != srng->u.src_ring.reap_hp) {
  310. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  311. srng->u.src_ring.hp = (srng->u.src_ring.hp + srng->entry_size) %
  312. srng->ring_size;
  313. return (void *)desc;
  314. }
  315. return NULL;
  316. }
  317. /**
  318. * hal_srng_src_done_val -
  319. *
  320. * @hal_soc: Opaque HAL SOC handle
  321. * @hal_ring: Source ring pointer
  322. *
  323. * Return: Opaque pointer for next ring entry; NULL on failire
  324. */
  325. static inline uint32_t hal_srng_src_done_val(void *hal_soc, void *hal_ring)
  326. {
  327. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  328. /* TODO: Using % is expensive, but we have to do this since
  329. * size of some SRNG rings is not power of 2 (due to descriptor
  330. * sizes). Need to create separate API for rings used
  331. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  332. * SW2RXDMA and CE rings)
  333. */
  334. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  335. srng->ring_size;
  336. if (next_reap_hp == srng->u.src_ring.cached_tp)
  337. return 0;
  338. if (srng->u.src_ring.cached_tp > next_reap_hp)
  339. return (srng->u.src_ring.cached_tp - next_reap_hp) /
  340. srng->entry_size;
  341. else
  342. return ((srng->ring_size - next_reap_hp) +
  343. srng->u.src_ring.cached_tp) / srng->entry_size;
  344. }
  345. /**
  346. * hal_srng_src_get_next - Get next entry from a source ring and move cached tail pointer
  347. *
  348. * @hal_soc: Opaque HAL SOC handle
  349. * @hal_ring: Source ring pointer
  350. *
  351. * Return: Opaque pointer for next ring entry; NULL on failire
  352. */
  353. static inline void *hal_srng_src_get_next(void *hal_soc, void *hal_ring)
  354. {
  355. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  356. uint32_t *desc;
  357. /* TODO: Using % is expensive, but we have to do this since
  358. * size of some SRNG rings is not power of 2 (due to descriptor
  359. * sizes). Need to create separate API for rings used
  360. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  361. * SW2RXDMA and CE rings)
  362. */
  363. uint32_t next_hp = (srng->u.src_ring.hp + srng->entry_size) %
  364. srng->ring_size;
  365. if (next_hp != srng->u.src_ring.cached_tp) {
  366. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  367. srng->u.src_ring.hp = next_hp;
  368. /* TODO: Since reap function is not used by all rings, we can
  369. * remove the following update of reap_hp in this function
  370. * if we can ensure that only hal_srng_src_get_next_reaped
  371. * is used for the rings requiring reap functionality
  372. */
  373. srng->u.src_ring.reap_hp = next_hp;
  374. return (void *)desc;
  375. }
  376. return NULL;
  377. }
  378. /**
  379. * hal_srng_src_peek - Get next entry from a ring without moving head pointer.
  380. * hal_srng_src_get_next should be called subsequently to move the head pointer
  381. *
  382. * @hal_soc: Opaque HAL SOC handle
  383. * @hal_ring: Source ring pointer
  384. *
  385. * Return: Opaque pointer for next ring entry; NULL on failire
  386. */
  387. static inline void *hal_srng_src_peek(void *hal_soc, void *hal_ring)
  388. {
  389. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  390. uint32_t *desc;
  391. /* TODO: Using % is expensive, but we have to do this since
  392. * size of some SRNG rings is not power of 2 (due to descriptor
  393. * sizes). Need to create separate API for rings used
  394. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  395. * SW2RXDMA and CE rings)
  396. */
  397. if (((srng->u.src_ring.hp + srng->entry_size) %
  398. srng->ring_size) != srng->u.src_ring.cached_tp) {
  399. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  400. return (void *)desc;
  401. }
  402. return NULL;
  403. }
  404. /**
  405. * hal_srng_src_num_avail - Returns number of available entries in src ring
  406. *
  407. * @hal_soc: Opaque HAL SOC handle
  408. * @hal_ring: Source ring pointer
  409. * @sync_hw_ptr: Sync cached tail pointer with HW
  410. *
  411. */
  412. static inline uint32_t hal_srng_src_num_avail(void *hal_soc,
  413. void *hal_ring, int sync_hw_ptr)
  414. {
  415. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  416. uint32 tp;
  417. uint32 hp = srng->u.src_ring.hp;
  418. if (sync_hw_ptr) {
  419. tp = *(srng->u.src_ring.tp_addr);
  420. srng->u.src_ring.cached_tp = tp;
  421. } else {
  422. tp = srng->u.src_ring.cached_tp;
  423. }
  424. if (tp > hp)
  425. return ((tp - hp) / srng->entry_size) - 1;
  426. else
  427. return ((srng->ring_size - hp + tp) / srng->entry_size) - 1;
  428. }
  429. /**
  430. * hal_srng_access_end_unlocked - End ring access (unlocked) - update cached
  431. * ring head/tail pointers to HW.
  432. * This should be used only if hal_srng_access_start_unlocked to start ring
  433. * access
  434. *
  435. * @hal_soc: Opaque HAL SOC handle
  436. * @hal_ring: Ring pointer (Source or Destination ring)
  437. *
  438. * Return: 0 on success; error on failire
  439. */
  440. static inline void hal_srng_access_end_unlocked(void *hal_soc, void *hal_ring)
  441. {
  442. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  443. /* TODO: See if we need a write memory barrier here */
  444. if (srng->flags & HAL_SRNG_LMAC_RING) {
  445. /* For LMAC rings, ring pointer updates are done through FW and
  446. * hence written to a shared memory location that is read by FW
  447. */
  448. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  449. *(srng->u.src_ring.hp_addr) = srng->u.src_ring.hp;
  450. else
  451. *(srng->u.src_ring.tp_addr) = srng->u.dst_ring.tp;
  452. } else {
  453. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  454. hif_write32_mb(srng->u.src_ring.hp_addr,
  455. srng->u.src_ring.hp);
  456. else
  457. hif_write32_mb(srng->u.dst_ring.tp_addr,
  458. srng->u.dst_ring.tp);
  459. }
  460. }
  461. /**
  462. * hal_srng_access_end - Unlock ring access and update cached ring head/tail
  463. * pointers to HW
  464. * This should be used only if hal_srng_access_start to start ring access
  465. *
  466. * @hal_soc: Opaque HAL SOC handle
  467. * @hal_ring: Ring pointer (Source or Destination ring)
  468. *
  469. * Return: 0 on success; error on failire
  470. */
  471. static inline void hal_srng_access_end(void *hal_soc, void *hal_ring)
  472. {
  473. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  474. hal_srng_access_end_unlocked(hal_soc, hal_ring);
  475. SRNG_UNLOCK(&(srng->lock));
  476. }
  477. /**
  478. * hal_srng_access_end_reap - Unlock ring access
  479. * This should be used only if hal_srng_access_start to start ring access
  480. * and should be used only while reaping SRC ring completions
  481. *
  482. * @hal_soc: Opaque HAL SOC handle
  483. * @hal_ring: Ring pointer (Source or Destination ring)
  484. *
  485. * Return: 0 on success; error on failire
  486. */
  487. static inline void hal_srng_access_end_reap(void *hal_soc, void *hal_ring)
  488. {
  489. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  490. SRNG_UNLOCK(&(srng->lock));
  491. }
  492. /* TODO: Check if the following definitions is available in HW headers */
  493. #define WBM_IDLE_DESC_LIST 1
  494. #define WBM_IDLE_SCATTER_BUF_SIZE 32704
  495. #define NUM_MPDUS_PER_LINK_DESC 6
  496. #define NUM_MSDUS_PER_LINK_DESC 7
  497. #define REO_QUEUE_DESC_ALIGN 128
  498. #define LINK_DESC_SIZE (NUM_OF_DWORDS_RX_MSDU_LINK << 2)
  499. #define LINK_DESC_ALIGN 128
  500. /* Number of mpdu link pointers is 9 in case of TX_MPDU_QUEUE_HEAD and 14 in
  501. * of TX_MPDU_QUEUE_EXT. We are defining a common average count here
  502. */
  503. #define NUM_MPDU_LINKS_PER_QUEUE_DESC 12
  504. /* TODO: Check with HW team on the scatter buffer size supported. As per WBM
  505. * MLD, scatter_buffer_size in IDLE_LIST_CONTROL register is 9 bits and size
  506. * should be specified in 16 word units. But the number of bits defined for
  507. * this field in HW header files is 5.
  508. */
  509. #define WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE 8
  510. /**
  511. * hal_set_link_desc_addr - Setup link descriptor in a buffer_addr_info
  512. * HW structure
  513. *
  514. * @desc: Descriptor entry (from WBM_IDLE_LINK ring)
  515. * @cookie: SW cookie for the buffer/descriptor
  516. * @link_desc_paddr: Physical address of link descriptor entry
  517. *
  518. */
  519. static inline void hal_set_link_desc_addr(void *desc, uint32_t cookie,
  520. qdf_dma_addr_t link_desc_paddr)
  521. {
  522. uint32_t *buf_addr = (uint32_t *)desc;
  523. HAL_DESC_SET_FIELD(buf_addr, BUFFER_ADDR_INFO_0, BUFFER_ADDR_31_0,
  524. link_desc_paddr & 0xffffffff);
  525. HAL_DESC_SET_FIELD(buf_addr, BUFFER_ADDR_INFO_1, BUFFER_ADDR_39_32,
  526. (uint64_t)link_desc_paddr >> 32);
  527. HAL_DESC_SET_FIELD(buf_addr, BUFFER_ADDR_INFO_1, RETURN_BUFFER_MANAGER,
  528. WBM_IDLE_DESC_LIST);
  529. HAL_DESC_SET_FIELD(buf_addr, BUFFER_ADDR_INFO_1, SW_BUFFER_COOKIE,
  530. cookie);
  531. }
  532. /**
  533. * hal_idle_list_scatter_buf_size - Get the size of each scatter buffer
  534. * in an idle list
  535. *
  536. * @hal_soc: Opaque HAL SOC handle
  537. *
  538. */
  539. static inline uint32_t hal_idle_list_scatter_buf_size(void *hal_soc)
  540. {
  541. return WBM_IDLE_SCATTER_BUF_SIZE;
  542. }
  543. /**
  544. * hal_get_link_desc_size - Get the size of each link descriptor
  545. *
  546. * @hal_soc: Opaque HAL SOC handle
  547. *
  548. */
  549. static inline uint32_t hal_get_link_desc_size(void *hal_soc)
  550. {
  551. return LINK_DESC_SIZE;
  552. }
  553. /**
  554. * hal_get_link_desc_align - Get the required start address alignment for
  555. * link descriptors
  556. *
  557. * @hal_soc: Opaque HAL SOC handle
  558. *
  559. */
  560. static inline uint32_t hal_get_link_desc_align(void *hal_soc)
  561. {
  562. return LINK_DESC_ALIGN;
  563. }
  564. /**
  565. * hal_num_mpdus_per_link_desc - Get number of mpdus each link desc can hold
  566. *
  567. * @hal_soc: Opaque HAL SOC handle
  568. *
  569. */
  570. static inline uint32_t hal_num_mpdus_per_link_desc(void *hal_soc)
  571. {
  572. return NUM_MPDUS_PER_LINK_DESC;
  573. }
  574. /**
  575. * hal_num_msdus_per_link_desc - Get number of msdus each link desc can hold
  576. *
  577. * @hal_soc: Opaque HAL SOC handle
  578. *
  579. */
  580. static inline uint32_t hal_num_msdus_per_link_desc(void *hal_soc)
  581. {
  582. return NUM_MSDUS_PER_LINK_DESC;
  583. }
  584. /**
  585. * hal_num_mpdu_links_per_queue_desc - Get number of mpdu links each queue
  586. * descriptor can hold
  587. *
  588. * @hal_soc: Opaque HAL SOC handle
  589. *
  590. */
  591. static inline uint32_t hal_num_mpdu_links_per_queue_desc(void *hal_soc)
  592. {
  593. return NUM_MPDU_LINKS_PER_QUEUE_DESC;
  594. }
  595. /**
  596. * hal_idle_list_scatter_buf_num_entries - Get the number of link desc entries
  597. * that the given buffer size
  598. *
  599. * @hal_soc: Opaque HAL SOC handle
  600. * @scatter_buf_size: Size of scatter buffer
  601. *
  602. */
  603. static inline uint32_t hal_idle_scatter_buf_num_entries(void *hal_soc,
  604. uint32_t scatter_buf_size)
  605. {
  606. return (scatter_buf_size - WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE) /
  607. hal_srng_get_entrysize(hal_soc, WBM_IDLE_LINK);
  608. }
  609. /**
  610. * hal_idle_scatter_buf_setup - Setup scattered idle list using the buffer list
  611. * provided
  612. *
  613. * @hal_soc: Opaque HAL SOC handle
  614. * @idle_scatter_bufs_base_paddr: Array of physical base addresses
  615. * @idle_scatter_bufs_base_vaddr: Array of virtual base addresses
  616. * @num_scatter_bufs: Number of scatter buffers in the above lists
  617. * @scatter_buf_size: Size of each scatter buffer
  618. *
  619. */
  620. extern void hal_setup_link_idle_list(void *hal_soc,
  621. qdf_dma_addr_t scatter_bufs_base_paddr[],
  622. void *scatter_bufs_base_vaddr[], uint32_t num_scatter_bufs,
  623. uint32_t scatter_buf_size, uint32_t last_buf_end_offset);
  624. /**
  625. * hal_reo_setup - Initialize HW REO block
  626. *
  627. * @hal_soc: Opaque HAL SOC handle
  628. */
  629. extern void hal_reo_setup(void *hal_soc);
  630. enum hal_pn_type {
  631. HAL_PN_NONE,
  632. HAL_PN_WPA,
  633. HAL_PN_WAPI_EVEN,
  634. HAL_PN_WAPI_UNEVEN,
  635. };
  636. #define HAL_RX_MAX_BA_WINDOW 256
  637. /**
  638. * hal_get_reo_qdesc_size - Get size of reo queue descriptor
  639. *
  640. * @hal_soc: Opaque HAL SOC handle
  641. * @ba_window_size: BlockAck window size
  642. *
  643. */
  644. static inline uint32_t hal_get_reo_qdesc_size(void *hal_soc,
  645. uint32_t ba_window_size)
  646. {
  647. if (ba_window_size <= 1)
  648. return sizeof(struct rx_reo_queue);
  649. if (ba_window_size <= 105)
  650. return sizeof(struct rx_reo_queue) +
  651. sizeof(struct rx_reo_queue_ext);
  652. if (ba_window_size <= 210)
  653. return sizeof(struct rx_reo_queue) +
  654. (2 * sizeof(struct rx_reo_queue_ext));
  655. return sizeof(struct rx_reo_queue) +
  656. (3 * sizeof(struct rx_reo_queue_ext));
  657. }
  658. /**
  659. * hal_get_reo_qdesc_align - Get start address alignment for reo
  660. * queue descriptors
  661. *
  662. * @hal_soc: Opaque HAL SOC handle
  663. *
  664. */
  665. static inline uint32_t hal_get_reo_qdesc_align(void *hal_soc)
  666. {
  667. return REO_QUEUE_DESC_ALIGN;
  668. }
  669. /**
  670. * hal_reo_qdesc_setup - Setup HW REO queue descriptor
  671. *
  672. * @hal_soc: Opaque HAL SOC handle
  673. * @ba_window_size: BlockAck window size
  674. * @start_seq: Starting sequence number
  675. * @hw_qdesc_vaddr: Virtual address of REO queue descriptor memory
  676. * @hw_qdesc_paddr: Physical address of REO queue descriptor memory
  677. * @pn_type: PN type (one of the types defined in 'enum hal_pn_type')
  678. *
  679. */
  680. extern void hal_reo_qdesc_setup(void *hal_soc, int tid, uint32_t ba_window_size,
  681. uint32_t start_seq, void *hw_qdesc_vaddr, qdf_dma_addr_t hw_qdesc_paddr,
  682. int pn_type);
  683. /**
  684. * hal_srng_get_hp_addr - Get head pointer physical address
  685. *
  686. * @hal_soc: Opaque HAL SOC handle
  687. * @hal_ring: Ring pointer (Source or Destination ring)
  688. *
  689. */
  690. static inline qdf_dma_addr_t hal_srng_get_hp_addr(void *hal_soc, void *hal_ring)
  691. {
  692. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  693. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  694. if (!(srng->flags & HAL_SRNG_LMAC_RING)) {
  695. /* Currently this interface is required only for LMAC rings */
  696. return (qdf_dma_addr_t)NULL;
  697. }
  698. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  699. return hal->shadow_wrptr_mem_paddr + (srng->u.src_ring.hp_addr -
  700. hal->shadow_wrptr_mem_vaddr);
  701. } else {
  702. return hal->shadow_rdptr_mem_paddr + (srng->u.dst_ring.hp_addr -
  703. hal->shadow_rdptr_mem_vaddr);
  704. }
  705. }
  706. /**
  707. * hal_srng_get_tp_addr - Get tail pointer physical address
  708. *
  709. * @hal_soc: Opaque HAL SOC handle
  710. * @hal_ring: Ring pointer (Source or Destination ring)
  711. *
  712. */
  713. static inline qdf_dma_addr_t hal_srng_get_tp_addr(void *hal_soc, void *hal_ring)
  714. {
  715. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  716. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  717. if (!(srng->flags & HAL_SRNG_LMAC_RING)) {
  718. /* Currently this interface is required only for LMAC rings */
  719. return (qdf_dma_addr_t)NULL;
  720. }
  721. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  722. return hal->shadow_rdptr_mem_paddr +
  723. ((unsigned long)(srng->u.src_ring.tp_addr) -
  724. (unsigned long)(hal->shadow_rdptr_mem_vaddr));
  725. } else {
  726. return hal->shadow_wrptr_mem_paddr +
  727. ((unsigned long)(srng->u.dst_ring.tp_addr) -
  728. (unsigned long)(hal->shadow_wrptr_mem_vaddr));
  729. }
  730. }
  731. /**
  732. * hal_get_srng_params - Retreive SRNG parameters for a given ring from HAL
  733. *
  734. * @hal_soc: Opaque HAL SOC handle
  735. * @hal_ring: Ring pointer (Source or Destination ring)
  736. * @ring_params: SRNG parameters will be returned through this structure
  737. */
  738. extern void hal_get_srng_params(void *hal_soc, void *hal_ring,
  739. struct hal_srng_params *ring_params);
  740. #endif /* _HAL_API_H_ */