hal_api.h 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054
  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. /**
  176. * hal_srng_get_dir - Returns the direction of the ring
  177. * @hal_soc: Opaque HAL SOC handle
  178. * @ring_type: one of the types from hal_ring_type
  179. *
  180. * Return: Ring direction
  181. */
  182. enum hal_srng_dir hal_srng_get_dir(void *hal_soc, int ring_type);
  183. /* HAL memory information */
  184. struct hal_mem_info {
  185. /* dev base virutal addr */
  186. void *dev_base_addr;
  187. /* dev base physical addr */
  188. void *dev_base_paddr;
  189. /* Remote virtual pointer memory for HW/FW updates */
  190. void *shadow_rdptr_mem_vaddr;
  191. /* Remote physical pointer memory for HW/FW updates */
  192. void *shadow_rdptr_mem_paddr;
  193. /* Shared memory for ring pointer updates from host to FW */
  194. void *shadow_wrptr_mem_vaddr;
  195. /* Shared physical memory for ring pointer updates from host to FW */
  196. void *shadow_wrptr_mem_paddr;
  197. };
  198. /* SRNG parameters to be passed to hal_srng_setup */
  199. struct hal_srng_params {
  200. /* Physical base address of the ring */
  201. qdf_dma_addr_t ring_base_paddr;
  202. /* Virtual base address of the ring */
  203. void *ring_base_vaddr;
  204. /* Number of entries in ring */
  205. uint32_t num_entries;
  206. /* max transfer length */
  207. uint16_t max_buffer_length;
  208. /* MSI Address */
  209. qdf_dma_addr_t msi_addr;
  210. /* MSI data */
  211. uint32_t msi_data;
  212. /* Interrupt timer threshold – in micro seconds */
  213. uint32_t intr_timer_thres_us;
  214. /* Interrupt batch counter threshold – in number of ring entries */
  215. uint32_t intr_batch_cntr_thres_entries;
  216. /* Low threshold – in number of ring entries
  217. * (valid for src rings only)
  218. */
  219. uint32_t low_threshold;
  220. /* Misc flags */
  221. uint32_t flags;
  222. /* Unique ring id */
  223. uint8_t ring_id;
  224. /* Source or Destination ring */
  225. enum hal_srng_dir ring_dir;
  226. /* Size of ring entry */
  227. uint32_t entry_size;
  228. /* hw register base address */
  229. void *hwreg_base[MAX_SRNG_REG_GROUPS];
  230. };
  231. /* hal_construct_shadow_config() - initialize the shadow registers for dp rings
  232. * @hal_soc: hal handle
  233. *
  234. * Return: QDF_STATUS_OK on success
  235. */
  236. extern QDF_STATUS hal_construct_shadow_config(void *hal_soc);
  237. /* hal_set_one_shadow_config() - add a config for the specified ring
  238. * @hal_soc: hal handle
  239. * @ring_type: ring type
  240. * @ring_num: ring num
  241. *
  242. * The ring type and ring num uniquely specify the ring. After this call,
  243. * the hp/tp will be added as the next entry int the shadow register
  244. * configuration table. The hal code will use the shadow register address
  245. * in place of the hp/tp address.
  246. *
  247. * This function is exposed, so that the CE module can skip configuring shadow
  248. * registers for unused ring and rings assigned to the firmware.
  249. *
  250. * Return: QDF_STATUS_OK on success
  251. */
  252. extern QDF_STATUS hal_set_one_shadow_config(void *hal_soc, int ring_type,
  253. int ring_num);
  254. /**
  255. * hal_get_shadow_config() - retrieve the config table
  256. * @hal_soc: hal handle
  257. * @shadow_config: will point to the table after
  258. * @num_shadow_registers_configured: will contain the number of valid entries
  259. */
  260. extern void hal_get_shadow_config(void *hal_soc,
  261. struct pld_shadow_reg_v2_cfg **shadow_config,
  262. int *num_shadow_registers_configured);
  263. /**
  264. * hal_srng_setup - Initalize HW SRNG ring.
  265. *
  266. * @hal_soc: Opaque HAL SOC handle
  267. * @ring_type: one of the types from hal_ring_type
  268. * @ring_num: Ring number if there are multiple rings of
  269. * same type (staring from 0)
  270. * @mac_id: valid MAC Id should be passed if ring type is one of lmac rings
  271. * @ring_params: SRNG ring params in hal_srng_params structure.
  272. * Callers are expected to allocate contiguous ring memory of size
  273. * 'num_entries * entry_size' bytes and pass the physical and virtual base
  274. * addresses through 'ring_base_paddr' and 'ring_base_vaddr' in hal_srng_params
  275. * structure. Ring base address should be 8 byte aligned and size of each ring
  276. * entry should be queried using the API hal_srng_get_entrysize
  277. *
  278. * Return: Opaque pointer to ring on success
  279. * NULL on failure (if given ring is not available)
  280. */
  281. extern void *hal_srng_setup(void *hal_soc, int ring_type, int ring_num,
  282. int mac_id, struct hal_srng_params *ring_params);
  283. /* Remapping ids of REO rings */
  284. #define REO_REMAP_TCL 0
  285. #define REO_REMAP_SW1 1
  286. #define REO_REMAP_SW2 2
  287. #define REO_REMAP_SW3 3
  288. #define REO_REMAP_SW4 4
  289. #define REO_REMAP_RELEASE 5
  290. #define REO_REMAP_FW 6
  291. #define REO_REMAP_UNUSED 7
  292. /*
  293. * currently this macro only works for IX0 since all the rings we are remapping
  294. * can be remapped from HWIO_REO_R0_DESTINATION_RING_CTRL_IX_0
  295. */
  296. #define HAL_REO_REMAP_VAL(_ORIGINAL_DEST, _NEW_DEST) \
  297. HAL_REO_REMAP_VAL_(_ORIGINAL_DEST, _NEW_DEST)
  298. /* allow the destination macros to be expanded */
  299. #define HAL_REO_REMAP_VAL_(_ORIGINAL_DEST, _NEW_DEST) \
  300. (_NEW_DEST << \
  301. (HWIO_REO_R0_DESTINATION_RING_CTRL_IX_0_DEST_RING_MAPPING_ ## \
  302. _ORIGINAL_DEST ## _SHFT))
  303. /**
  304. * hal_reo_remap_IX0 - Remap REO ring destination
  305. * @hal: HAL SOC handle
  306. * @remap_val: Remap value
  307. */
  308. extern void hal_reo_remap_IX0(struct hal_soc *hal, uint32_t remap_val);
  309. /**
  310. * hal_srng_set_hp_paddr() - Set physical address to SRNG head pointer
  311. * @sring: sring pointer
  312. * @paddr: physical address
  313. */
  314. extern void hal_srng_set_hp_paddr(struct hal_srng *sring, uint64_t paddr);
  315. /**
  316. * hal_srng_cleanup - Deinitialize HW SRNG ring.
  317. * @hal_soc: Opaque HAL SOC handle
  318. * @hal_srng: Opaque HAL SRNG pointer
  319. */
  320. extern void hal_srng_cleanup(void *hal_soc, void *hal_srng);
  321. static inline bool hal_srng_initialized(void *hal_ring)
  322. {
  323. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  324. return !!srng->initialized;
  325. }
  326. /**
  327. * hal_srng_access_start_unlocked - Start ring access (unlocked). Should use
  328. * hal_srng_access_start if locked access is required
  329. *
  330. * @hal_soc: Opaque HAL SOC handle
  331. * @hal_ring: Ring pointer (Source or Destination ring)
  332. *
  333. * Return: 0 on success; error on failire
  334. */
  335. static inline int hal_srng_access_start_unlocked(void *hal_soc, void *hal_ring)
  336. {
  337. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  338. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  339. srng->u.src_ring.cached_tp =
  340. *(volatile uint32_t *)(srng->u.src_ring.tp_addr);
  341. else
  342. srng->u.dst_ring.cached_hp =
  343. *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  344. return 0;
  345. }
  346. /**
  347. * hal_srng_access_start - Start (locked) ring access
  348. *
  349. * @hal_soc: Opaque HAL SOC handle
  350. * @hal_ring: Ring pointer (Source or Destination ring)
  351. *
  352. * Return: 0 on success; error on failire
  353. */
  354. static inline int hal_srng_access_start(void *hal_soc, void *hal_ring)
  355. {
  356. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  357. SRNG_LOCK(&(srng->lock));
  358. return hal_srng_access_start_unlocked(hal_soc, hal_ring);
  359. }
  360. /**
  361. * hal_srng_dst_get_next - Get next entry from a destination ring and move
  362. * cached tail pointer
  363. *
  364. * @hal_soc: Opaque HAL SOC handle
  365. * @hal_ring: Destination ring pointer
  366. *
  367. * Return: Opaque pointer for next ring entry; NULL on failire
  368. */
  369. static inline void *hal_srng_dst_get_next(void *hal_soc, void *hal_ring)
  370. {
  371. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  372. volatile uint32_t *desc = &(srng->ring_base_vaddr[srng->u.dst_ring.tp]);
  373. uint32_t desc_loop_cnt;
  374. desc_loop_cnt = (desc[srng->entry_size - 1] & SRNG_LOOP_CNT_MASK)
  375. >> SRNG_LOOP_CNT_LSB;
  376. if (srng->u.dst_ring.loop_cnt == desc_loop_cnt) {
  377. /* TODO: Using % is expensive, but we have to do this since
  378. * size of some SRNG rings is not power of 2 (due to descriptor
  379. * sizes). Need to create separate API for rings used
  380. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  381. * SW2RXDMA and CE rings)
  382. */
  383. srng->u.dst_ring.tp = (srng->u.dst_ring.tp + srng->entry_size) %
  384. srng->ring_size;
  385. srng->u.dst_ring.loop_cnt = (srng->u.dst_ring.loop_cnt +
  386. !srng->u.dst_ring.tp) &
  387. (SRNG_LOOP_CNT_MASK >> SRNG_LOOP_CNT_LSB);
  388. /* TODO: Confirm if loop count mask is same for all rings */
  389. return (void *)desc;
  390. }
  391. return NULL;
  392. }
  393. /**
  394. * hal_srng_dst_peek - Get next entry from a ring without moving tail pointer.
  395. * hal_srng_dst_get_next should be called subsequently to move the tail pointer
  396. * TODO: See if we need an optimized version of get_next that doesn't check for
  397. * loop_cnt
  398. *
  399. * @hal_soc: Opaque HAL SOC handle
  400. * @hal_ring: Destination ring pointer
  401. *
  402. * Return: Opaque pointer for next ring entry; NULL on failire
  403. */
  404. static inline void *hal_srng_dst_peek(void *hal_soc, void *hal_ring)
  405. {
  406. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  407. uint32_t *desc = &(srng->ring_base_vaddr[srng->u.dst_ring.tp]);
  408. uint32_t desc_loop_cnt;
  409. desc_loop_cnt = (desc[srng->entry_size - 1] & SRNG_LOOP_CNT_MASK)
  410. >> SRNG_LOOP_CNT_LSB;
  411. if (srng->u.dst_ring.loop_cnt == desc_loop_cnt)
  412. return (void *)desc;
  413. return NULL;
  414. }
  415. /**
  416. * hal_srng_dst_num_valid - Returns number of valid entries (to be processed
  417. * by SW) in destination ring
  418. *
  419. * @hal_soc: Opaque HAL SOC handle
  420. * @hal_ring: Destination ring pointer
  421. * @sync_hw_ptr: Sync cached head pointer with HW
  422. *
  423. */
  424. static inline uint32_t hal_srng_dst_num_valid(void *hal_soc, void *hal_ring,
  425. int sync_hw_ptr)
  426. {
  427. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  428. uint32 hp;
  429. uint32 tp = srng->u.dst_ring.tp;
  430. if (sync_hw_ptr) {
  431. hp = *(srng->u.dst_ring.hp_addr);
  432. srng->u.dst_ring.cached_hp = hp;
  433. } else {
  434. hp = srng->u.dst_ring.cached_hp;
  435. }
  436. if (hp >= tp)
  437. return (hp - tp) / srng->entry_size;
  438. else
  439. return (srng->ring_size - tp + hp) / srng->entry_size;
  440. }
  441. /**
  442. * hal_srng_src_reap_next - Reap next entry from a source ring and move reap
  443. * pointer. This can be used to release any buffers associated with completed
  444. * ring entries. Note that this should not be used for posting new descriptor
  445. * entries. Posting of new entries should be done only using
  446. * hal_srng_src_get_next_reaped when this function is used for reaping.
  447. *
  448. * @hal_soc: Opaque HAL SOC handle
  449. * @hal_ring: Source ring pointer
  450. *
  451. * Return: Opaque pointer for next ring entry; NULL on failire
  452. */
  453. static inline void *hal_srng_src_reap_next(void *hal_soc, void *hal_ring)
  454. {
  455. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  456. uint32_t *desc;
  457. /* TODO: Using % is expensive, but we have to do this since
  458. * size of some SRNG rings is not power of 2 (due to descriptor
  459. * sizes). Need to create separate API for rings used
  460. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  461. * SW2RXDMA and CE rings)
  462. */
  463. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  464. srng->ring_size;
  465. if (next_reap_hp != srng->u.src_ring.cached_tp) {
  466. desc = &(srng->ring_base_vaddr[next_reap_hp]);
  467. srng->u.src_ring.reap_hp = next_reap_hp;
  468. return (void *)desc;
  469. }
  470. return NULL;
  471. }
  472. /**
  473. * hal_srng_src_get_next_reaped - Get next entry from a source ring that is
  474. * already reaped using hal_srng_src_reap_next, for posting new entries to
  475. * the ring
  476. *
  477. * @hal_soc: Opaque HAL SOC handle
  478. * @hal_ring: Source ring pointer
  479. *
  480. * Return: Opaque pointer for next (reaped) source ring entry; NULL on failire
  481. */
  482. static inline void *hal_srng_src_get_next_reaped(void *hal_soc, void *hal_ring)
  483. {
  484. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  485. uint32_t *desc;
  486. if (srng->u.src_ring.hp != srng->u.src_ring.reap_hp) {
  487. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  488. srng->u.src_ring.hp = (srng->u.src_ring.hp + srng->entry_size) %
  489. srng->ring_size;
  490. return (void *)desc;
  491. }
  492. return NULL;
  493. }
  494. /**
  495. * hal_srng_src_done_val -
  496. *
  497. * @hal_soc: Opaque HAL SOC handle
  498. * @hal_ring: Source ring pointer
  499. *
  500. * Return: Opaque pointer for next ring entry; NULL on failire
  501. */
  502. static inline uint32_t hal_srng_src_done_val(void *hal_soc, void *hal_ring)
  503. {
  504. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  505. /* TODO: Using % is expensive, but we have to do this since
  506. * size of some SRNG rings is not power of 2 (due to descriptor
  507. * sizes). Need to create separate API for rings used
  508. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  509. * SW2RXDMA and CE rings)
  510. */
  511. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  512. srng->ring_size;
  513. if (next_reap_hp == srng->u.src_ring.cached_tp)
  514. return 0;
  515. if (srng->u.src_ring.cached_tp > next_reap_hp)
  516. return (srng->u.src_ring.cached_tp - next_reap_hp) /
  517. srng->entry_size;
  518. else
  519. return ((srng->ring_size - next_reap_hp) +
  520. srng->u.src_ring.cached_tp) / srng->entry_size;
  521. }
  522. /**
  523. * hal_srng_src_get_next - Get next entry from a source ring and move cached tail pointer
  524. *
  525. * @hal_soc: Opaque HAL SOC handle
  526. * @hal_ring: Source ring pointer
  527. *
  528. * Return: Opaque pointer for next ring entry; NULL on failire
  529. */
  530. static inline void *hal_srng_src_get_next(void *hal_soc, void *hal_ring)
  531. {
  532. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  533. uint32_t *desc;
  534. /* TODO: Using % is expensive, but we have to do this since
  535. * size of some SRNG rings is not power of 2 (due to descriptor
  536. * sizes). Need to create separate API for rings used
  537. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  538. * SW2RXDMA and CE rings)
  539. */
  540. uint32_t next_hp = (srng->u.src_ring.hp + srng->entry_size) %
  541. srng->ring_size;
  542. if (next_hp != srng->u.src_ring.cached_tp) {
  543. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  544. srng->u.src_ring.hp = next_hp;
  545. /* TODO: Since reap function is not used by all rings, we can
  546. * remove the following update of reap_hp in this function
  547. * if we can ensure that only hal_srng_src_get_next_reaped
  548. * is used for the rings requiring reap functionality
  549. */
  550. srng->u.src_ring.reap_hp = next_hp;
  551. return (void *)desc;
  552. }
  553. return NULL;
  554. }
  555. /**
  556. * hal_srng_src_peek - Get next entry from a ring without moving head pointer.
  557. * hal_srng_src_get_next should be called subsequently to move the head pointer
  558. *
  559. * @hal_soc: Opaque HAL SOC handle
  560. * @hal_ring: Source ring pointer
  561. *
  562. * Return: Opaque pointer for next ring entry; NULL on failire
  563. */
  564. static inline void *hal_srng_src_peek(void *hal_soc, void *hal_ring)
  565. {
  566. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  567. uint32_t *desc;
  568. /* TODO: Using % is expensive, but we have to do this since
  569. * size of some SRNG rings is not power of 2 (due to descriptor
  570. * sizes). Need to create separate API for rings used
  571. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  572. * SW2RXDMA and CE rings)
  573. */
  574. if (((srng->u.src_ring.hp + srng->entry_size) %
  575. srng->ring_size) != srng->u.src_ring.cached_tp) {
  576. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  577. return (void *)desc;
  578. }
  579. return NULL;
  580. }
  581. /**
  582. * hal_srng_src_num_avail - Returns number of available entries in src ring
  583. *
  584. * @hal_soc: Opaque HAL SOC handle
  585. * @hal_ring: Source ring pointer
  586. * @sync_hw_ptr: Sync cached tail pointer with HW
  587. *
  588. */
  589. static inline uint32_t hal_srng_src_num_avail(void *hal_soc,
  590. void *hal_ring, int sync_hw_ptr)
  591. {
  592. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  593. uint32 tp;
  594. uint32 hp = srng->u.src_ring.hp;
  595. if (sync_hw_ptr) {
  596. tp = *(srng->u.src_ring.tp_addr);
  597. srng->u.src_ring.cached_tp = tp;
  598. } else {
  599. tp = srng->u.src_ring.cached_tp;
  600. }
  601. if (tp > hp)
  602. return ((tp - hp) / srng->entry_size) - 1;
  603. else
  604. return ((srng->ring_size - hp + tp) / srng->entry_size) - 1;
  605. }
  606. /**
  607. * hal_srng_access_end_unlocked - End ring access (unlocked) - update cached
  608. * ring head/tail pointers to HW.
  609. * This should be used only if hal_srng_access_start_unlocked to start ring
  610. * access
  611. *
  612. * @hal_soc: Opaque HAL SOC handle
  613. * @hal_ring: Ring pointer (Source or Destination ring)
  614. *
  615. * Return: 0 on success; error on failire
  616. */
  617. static inline void hal_srng_access_end_unlocked(void *hal_soc, void *hal_ring)
  618. {
  619. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  620. /* TODO: See if we need a write memory barrier here */
  621. if (srng->flags & HAL_SRNG_LMAC_RING) {
  622. /* For LMAC rings, ring pointer updates are done through FW and
  623. * hence written to a shared memory location that is read by FW
  624. */
  625. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  626. *(srng->u.src_ring.hp_addr) = srng->u.src_ring.hp;
  627. } else {
  628. *(srng->u.dst_ring.tp_addr) = srng->u.dst_ring.tp;
  629. }
  630. } else {
  631. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  632. hal_write_address_32_mb(hal_soc,
  633. srng->u.src_ring.hp_addr,
  634. srng->u.src_ring.hp);
  635. else
  636. hal_write_address_32_mb(hal_soc,
  637. srng->u.dst_ring.tp_addr,
  638. srng->u.dst_ring.tp);
  639. }
  640. }
  641. /**
  642. * hal_srng_access_end - Unlock ring access and update cached ring head/tail
  643. * pointers to HW
  644. * This should be used only if hal_srng_access_start to start ring access
  645. *
  646. * @hal_soc: Opaque HAL SOC handle
  647. * @hal_ring: Ring pointer (Source or Destination ring)
  648. *
  649. * Return: 0 on success; error on failire
  650. */
  651. static inline void hal_srng_access_end(void *hal_soc, void *hal_ring)
  652. {
  653. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  654. hal_srng_access_end_unlocked(hal_soc, hal_ring);
  655. SRNG_UNLOCK(&(srng->lock));
  656. }
  657. /**
  658. * hal_srng_access_end_reap - Unlock ring access
  659. * This should be used only if hal_srng_access_start to start ring access
  660. * and should be used only while reaping SRC ring completions
  661. *
  662. * @hal_soc: Opaque HAL SOC handle
  663. * @hal_ring: Ring pointer (Source or Destination ring)
  664. *
  665. * Return: 0 on success; error on failire
  666. */
  667. static inline void hal_srng_access_end_reap(void *hal_soc, void *hal_ring)
  668. {
  669. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  670. SRNG_UNLOCK(&(srng->lock));
  671. }
  672. /* TODO: Check if the following definitions is available in HW headers */
  673. #define WBM_IDLE_DESC_LIST 1
  674. #define WBM_IDLE_SCATTER_BUF_SIZE 32704
  675. #define NUM_MPDUS_PER_LINK_DESC 6
  676. #define NUM_MSDUS_PER_LINK_DESC 7
  677. #define REO_QUEUE_DESC_ALIGN 128
  678. #define LINK_DESC_SIZE (NUM_OF_DWORDS_RX_MSDU_LINK << 2)
  679. #define LINK_DESC_ALIGN 128
  680. #define ADDRESS_MATCH_TAG_VAL 0x5
  681. /* Number of mpdu link pointers is 9 in case of TX_MPDU_QUEUE_HEAD and 14 in
  682. * of TX_MPDU_QUEUE_EXT. We are defining a common average count here
  683. */
  684. #define NUM_MPDU_LINKS_PER_QUEUE_DESC 12
  685. /* TODO: Check with HW team on the scatter buffer size supported. As per WBM
  686. * MLD, scatter_buffer_size in IDLE_LIST_CONTROL register is 9 bits and size
  687. * should be specified in 16 word units. But the number of bits defined for
  688. * this field in HW header files is 5.
  689. */
  690. #define WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE 8
  691. /**
  692. * hal_set_link_desc_addr - Setup link descriptor in a buffer_addr_info
  693. * HW structure
  694. *
  695. * @desc: Descriptor entry (from WBM_IDLE_LINK ring)
  696. * @cookie: SW cookie for the buffer/descriptor
  697. * @link_desc_paddr: Physical address of link descriptor entry
  698. *
  699. */
  700. static inline void hal_set_link_desc_addr(void *desc, uint32_t cookie,
  701. qdf_dma_addr_t link_desc_paddr)
  702. {
  703. uint32_t *buf_addr = (uint32_t *)desc;
  704. HAL_DESC_SET_FIELD(buf_addr, BUFFER_ADDR_INFO_0, BUFFER_ADDR_31_0,
  705. link_desc_paddr & 0xffffffff);
  706. HAL_DESC_SET_FIELD(buf_addr, BUFFER_ADDR_INFO_1, BUFFER_ADDR_39_32,
  707. (uint64_t)link_desc_paddr >> 32);
  708. HAL_DESC_SET_FIELD(buf_addr, BUFFER_ADDR_INFO_1, RETURN_BUFFER_MANAGER,
  709. WBM_IDLE_DESC_LIST);
  710. HAL_DESC_SET_FIELD(buf_addr, BUFFER_ADDR_INFO_1, SW_BUFFER_COOKIE,
  711. cookie);
  712. }
  713. /**
  714. * hal_idle_list_scatter_buf_size - Get the size of each scatter buffer
  715. * in an idle list
  716. *
  717. * @hal_soc: Opaque HAL SOC handle
  718. *
  719. */
  720. static inline uint32_t hal_idle_list_scatter_buf_size(void *hal_soc)
  721. {
  722. return WBM_IDLE_SCATTER_BUF_SIZE;
  723. }
  724. /**
  725. * hal_get_link_desc_size - Get the size of each link descriptor
  726. *
  727. * @hal_soc: Opaque HAL SOC handle
  728. *
  729. */
  730. static inline uint32_t hal_get_link_desc_size(void *hal_soc)
  731. {
  732. return LINK_DESC_SIZE;
  733. }
  734. /**
  735. * hal_get_link_desc_align - Get the required start address alignment for
  736. * link descriptors
  737. *
  738. * @hal_soc: Opaque HAL SOC handle
  739. *
  740. */
  741. static inline uint32_t hal_get_link_desc_align(void *hal_soc)
  742. {
  743. return LINK_DESC_ALIGN;
  744. }
  745. /**
  746. * hal_num_mpdus_per_link_desc - Get number of mpdus each link desc can hold
  747. *
  748. * @hal_soc: Opaque HAL SOC handle
  749. *
  750. */
  751. static inline uint32_t hal_num_mpdus_per_link_desc(void *hal_soc)
  752. {
  753. return NUM_MPDUS_PER_LINK_DESC;
  754. }
  755. /**
  756. * hal_num_msdus_per_link_desc - Get number of msdus each link desc can hold
  757. *
  758. * @hal_soc: Opaque HAL SOC handle
  759. *
  760. */
  761. static inline uint32_t hal_num_msdus_per_link_desc(void *hal_soc)
  762. {
  763. return NUM_MSDUS_PER_LINK_DESC;
  764. }
  765. /**
  766. * hal_num_mpdu_links_per_queue_desc - Get number of mpdu links each queue
  767. * descriptor can hold
  768. *
  769. * @hal_soc: Opaque HAL SOC handle
  770. *
  771. */
  772. static inline uint32_t hal_num_mpdu_links_per_queue_desc(void *hal_soc)
  773. {
  774. return NUM_MPDU_LINKS_PER_QUEUE_DESC;
  775. }
  776. /**
  777. * hal_idle_list_scatter_buf_num_entries - Get the number of link desc entries
  778. * that the given buffer size
  779. *
  780. * @hal_soc: Opaque HAL SOC handle
  781. * @scatter_buf_size: Size of scatter buffer
  782. *
  783. */
  784. static inline uint32_t hal_idle_scatter_buf_num_entries(void *hal_soc,
  785. uint32_t scatter_buf_size)
  786. {
  787. return (scatter_buf_size - WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE) /
  788. hal_srng_get_entrysize(hal_soc, WBM_IDLE_LINK);
  789. }
  790. /**
  791. * hal_idle_list_num_scatter_bufs - Get the number of sctater buffer
  792. * each given buffer size
  793. *
  794. * @hal_soc: Opaque HAL SOC handle
  795. * @total_mem: size of memory to be scattered
  796. * @scatter_buf_size: Size of scatter buffer
  797. *
  798. */
  799. static inline uint32_t hal_idle_list_num_scatter_bufs(void *hal_soc,
  800. uint32_t total_mem, uint32_t scatter_buf_size)
  801. {
  802. uint8_t rem = (total_mem % (scatter_buf_size -
  803. WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE)) ? 1 : 0;
  804. uint32_t num_scatter_bufs = (total_mem / (scatter_buf_size -
  805. WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE)) + rem;
  806. return num_scatter_bufs;
  807. }
  808. /**
  809. * hal_idle_scatter_buf_setup - Setup scattered idle list using the buffer list
  810. * provided
  811. *
  812. * @hal_soc: Opaque HAL SOC handle
  813. * @idle_scatter_bufs_base_paddr: Array of physical base addresses
  814. * @idle_scatter_bufs_base_vaddr: Array of virtual base addresses
  815. * @num_scatter_bufs: Number of scatter buffers in the above lists
  816. * @scatter_buf_size: Size of each scatter buffer
  817. * @last_buf_end_offset: Offset to the last entry
  818. * @num_entries: Total entries of all scatter bufs
  819. *
  820. */
  821. extern void hal_setup_link_idle_list(void *hal_soc,
  822. qdf_dma_addr_t scatter_bufs_base_paddr[],
  823. void *scatter_bufs_base_vaddr[], uint32_t num_scatter_bufs,
  824. uint32_t scatter_buf_size, uint32_t last_buf_end_offset,
  825. uint32_t num_entries);
  826. /* REO parameters to be passed to hal_reo_setup */
  827. struct hal_reo_params {
  828. bool rx_hash_enabled;
  829. };
  830. /**
  831. * hal_reo_setup - Initialize HW REO block
  832. *
  833. * @hal_soc: Opaque HAL SOC handle
  834. * @reo_params: parameters needed by HAL for REO config
  835. */
  836. extern void hal_reo_setup(void *hal_soc,
  837. struct hal_reo_params *reo_params);
  838. enum hal_pn_type {
  839. HAL_PN_NONE,
  840. HAL_PN_WPA,
  841. HAL_PN_WAPI_EVEN,
  842. HAL_PN_WAPI_UNEVEN,
  843. };
  844. #define HAL_RX_MAX_BA_WINDOW 256
  845. /**
  846. * hal_get_reo_qdesc_size - Get size of reo queue descriptor
  847. *
  848. * @hal_soc: Opaque HAL SOC handle
  849. * @ba_window_size: BlockAck window size
  850. *
  851. */
  852. static inline uint32_t hal_get_reo_qdesc_size(void *hal_soc,
  853. uint32_t ba_window_size)
  854. {
  855. if (ba_window_size <= 1)
  856. return sizeof(struct rx_reo_queue);
  857. if (ba_window_size <= 105)
  858. return sizeof(struct rx_reo_queue) +
  859. sizeof(struct rx_reo_queue_ext);
  860. if (ba_window_size <= 210)
  861. return sizeof(struct rx_reo_queue) +
  862. (2 * sizeof(struct rx_reo_queue_ext));
  863. return sizeof(struct rx_reo_queue) +
  864. (3 * sizeof(struct rx_reo_queue_ext));
  865. }
  866. /**
  867. * hal_get_reo_qdesc_align - Get start address alignment for reo
  868. * queue descriptors
  869. *
  870. * @hal_soc: Opaque HAL SOC handle
  871. *
  872. */
  873. static inline uint32_t hal_get_reo_qdesc_align(void *hal_soc)
  874. {
  875. return REO_QUEUE_DESC_ALIGN;
  876. }
  877. /**
  878. * hal_reo_qdesc_setup - Setup HW REO queue descriptor
  879. *
  880. * @hal_soc: Opaque HAL SOC handle
  881. * @ba_window_size: BlockAck window size
  882. * @start_seq: Starting sequence number
  883. * @hw_qdesc_vaddr: Virtual address of REO queue descriptor memory
  884. * @hw_qdesc_paddr: Physical address of REO queue descriptor memory
  885. * @pn_type: PN type (one of the types defined in 'enum hal_pn_type')
  886. *
  887. */
  888. extern void hal_reo_qdesc_setup(void *hal_soc, int tid, uint32_t ba_window_size,
  889. uint32_t start_seq, void *hw_qdesc_vaddr, qdf_dma_addr_t hw_qdesc_paddr,
  890. int pn_type);
  891. /**
  892. * hal_srng_get_hp_addr - Get head pointer physical address
  893. *
  894. * @hal_soc: Opaque HAL SOC handle
  895. * @hal_ring: Ring pointer (Source or Destination ring)
  896. *
  897. */
  898. static inline qdf_dma_addr_t hal_srng_get_hp_addr(void *hal_soc, void *hal_ring)
  899. {
  900. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  901. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  902. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  903. return hal->shadow_wrptr_mem_paddr +
  904. ((unsigned long)(srng->u.src_ring.hp_addr) -
  905. (unsigned long)(hal->shadow_wrptr_mem_vaddr));
  906. } else {
  907. return hal->shadow_rdptr_mem_paddr +
  908. ((unsigned long)(srng->u.dst_ring.hp_addr) -
  909. (unsigned long)(hal->shadow_rdptr_mem_vaddr));
  910. }
  911. }
  912. /**
  913. * hal_srng_get_tp_addr - Get tail pointer physical address
  914. *
  915. * @hal_soc: Opaque HAL SOC handle
  916. * @hal_ring: Ring pointer (Source or Destination ring)
  917. *
  918. */
  919. static inline qdf_dma_addr_t hal_srng_get_tp_addr(void *hal_soc, void *hal_ring)
  920. {
  921. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  922. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  923. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  924. return hal->shadow_rdptr_mem_paddr +
  925. ((unsigned long)(srng->u.src_ring.tp_addr) -
  926. (unsigned long)(hal->shadow_rdptr_mem_vaddr));
  927. } else {
  928. return hal->shadow_wrptr_mem_paddr +
  929. ((unsigned long)(srng->u.dst_ring.tp_addr) -
  930. (unsigned long)(hal->shadow_wrptr_mem_vaddr));
  931. }
  932. }
  933. /**
  934. * hal_get_srng_params - Retreive SRNG parameters for a given ring from HAL
  935. *
  936. * @hal_soc: Opaque HAL SOC handle
  937. * @hal_ring: Ring pointer (Source or Destination ring)
  938. * @ring_params: SRNG parameters will be returned through this structure
  939. */
  940. extern void hal_get_srng_params(void *hal_soc, void *hal_ring,
  941. struct hal_srng_params *ring_params);
  942. /**
  943. * hal_mem_info - Retreive hal memory base address
  944. *
  945. * @hal_soc: Opaque HAL SOC handle
  946. * @mem: pointer to structure to be updated with hal mem info
  947. */
  948. extern void hal_get_meminfo(void *hal_soc,struct hal_mem_info *mem );
  949. #endif /* _HAL_APIH_ */