hal_api.h 26 KB

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