hal_api.h 29 KB

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