hal_api.h 26 KB

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