hal_api.h 29 KB

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