hal_api.h 22 KB

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