hal_api.h 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286
  1. /*
  2. * Copyright (c) 2016-2018 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #ifndef _HAL_API_H_
  19. #define _HAL_API_H_
  20. #include "qdf_types.h"
  21. #include "qdf_util.h"
  22. #include "hal_internal.h"
  23. #define MAX_UNWINDOWED_ADDRESS 0x80000
  24. #ifdef QCA_WIFI_QCA6390
  25. #define WINDOW_ENABLE_BIT 0x40000000
  26. #else
  27. #define WINDOW_ENABLE_BIT 0x80000000
  28. #endif
  29. #define WINDOW_REG_ADDRESS 0x310C
  30. #define WINDOW_SHIFT 19
  31. #define WINDOW_VALUE_MASK 0x3F
  32. #define WINDOW_START MAX_UNWINDOWED_ADDRESS
  33. #define WINDOW_RANGE_MASK 0x7FFFF
  34. /*
  35. * BAR + 4K is always accessible, any access outside this
  36. * space requires force wake procedure.
  37. * OFFSET = 4K - 32 bytes = 0x4063
  38. */
  39. #define MAPPED_REF_OFF 0x4063
  40. #define FORCE_WAKE_DELAY_TIMEOUT 50
  41. #define FORCE_WAKE_DELAY_MS 5
  42. #ifndef QCA_WIFI_QCA6390
  43. static inline int hal_force_wake_request(struct hal_soc *soc)
  44. {
  45. return 0;
  46. }
  47. static inline int hal_force_wake_release(struct hal_soc *soc)
  48. {
  49. return 0;
  50. }
  51. #else
  52. static inline int hal_force_wake_request(struct hal_soc *soc)
  53. {
  54. uint32_t timeout = 0;
  55. if (pld_force_wake_request(soc->qdf_dev->dev)) {
  56. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  57. "%s: Request send failed \n", __func__);
  58. return -EINVAL;
  59. }
  60. while (!pld_is_device_awake(soc->qdf_dev->dev) &&
  61. timeout <= FORCE_WAKE_DELAY_TIMEOUT) {
  62. mdelay(FORCE_WAKE_DELAY_MS);
  63. timeout += FORCE_WAKE_DELAY_MS;
  64. }
  65. if (pld_is_device_awake(soc->qdf_dev->dev) == true)
  66. return 0;
  67. else
  68. return -ETIMEDOUT;
  69. }
  70. static inline int hal_force_wake_release(struct hal_soc *soc)
  71. {
  72. return pld_force_wake_release(soc->qdf_dev->dev);
  73. }
  74. #endif
  75. static inline void hal_select_window(struct hal_soc *hal_soc, uint32_t offset)
  76. {
  77. uint32_t window = (offset >> WINDOW_SHIFT) & WINDOW_VALUE_MASK;
  78. if (window != hal_soc->register_window) {
  79. qdf_iowrite32(hal_soc->dev_base_addr + WINDOW_REG_ADDRESS,
  80. WINDOW_ENABLE_BIT | window);
  81. hal_soc->register_window = window;
  82. }
  83. }
  84. /**
  85. * note1: WINDOW_RANGE_MASK = (1 << WINDOW_SHIFT) -1
  86. * note2: 1 << WINDOW_SHIFT = MAX_UNWINDOWED_ADDRESS
  87. * note3: WINDOW_VALUE_MASK = big enough that trying to write past that window
  88. * would be a bug
  89. */
  90. #ifndef QCA_WIFI_QCA6390
  91. static inline void hal_write32_mb(struct hal_soc *hal_soc, uint32_t offset,
  92. uint32_t value)
  93. {
  94. if (!hal_soc->use_register_windowing ||
  95. offset < MAX_UNWINDOWED_ADDRESS) {
  96. qdf_iowrite32(hal_soc->dev_base_addr + offset, value);
  97. } else {
  98. qdf_spin_lock_irqsave(&hal_soc->register_access_lock);
  99. hal_select_window(hal_soc, offset);
  100. qdf_iowrite32(hal_soc->dev_base_addr + WINDOW_START +
  101. (offset & WINDOW_RANGE_MASK), value);
  102. qdf_spin_unlock_irqrestore(&hal_soc->register_access_lock);
  103. }
  104. }
  105. #else
  106. static inline void hal_write32_mb(struct hal_soc *hal_soc, uint32_t offset,
  107. uint32_t value)
  108. {
  109. if ((offset > MAPPED_REF_OFF) &&
  110. hal_force_wake_request(hal_soc)) {
  111. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  112. "%s: Wake up request failed\n", __func__);
  113. return;
  114. }
  115. if (!hal_soc->use_register_windowing ||
  116. offset < MAX_UNWINDOWED_ADDRESS) {
  117. qdf_iowrite32(hal_soc->dev_base_addr + offset, value);
  118. } else {
  119. qdf_spin_lock_irqsave(&hal_soc->register_access_lock);
  120. hal_select_window(hal_soc, offset);
  121. qdf_iowrite32(hal_soc->dev_base_addr + WINDOW_START +
  122. (offset & WINDOW_RANGE_MASK), value);
  123. qdf_spin_unlock_irqrestore(&hal_soc->register_access_lock);
  124. }
  125. if ((offset > MAPPED_REF_OFF) &&
  126. hal_force_wake_release(hal_soc))
  127. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  128. "%s: Wake up release failed\n", __func__);
  129. }
  130. #endif
  131. /**
  132. * hal_write_address_32_mb - write a value to a register
  133. *
  134. */
  135. static inline void hal_write_address_32_mb(struct hal_soc *hal_soc,
  136. void __iomem *addr, uint32_t value)
  137. {
  138. uint32_t offset;
  139. if (!hal_soc->use_register_windowing)
  140. return qdf_iowrite32(addr, value);
  141. offset = addr - hal_soc->dev_base_addr;
  142. hal_write32_mb(hal_soc, offset, value);
  143. }
  144. #ifndef QCA_WIFI_QCA6390
  145. static inline uint32_t hal_read32_mb(struct hal_soc *hal_soc, uint32_t offset)
  146. {
  147. uint32_t ret;
  148. if (!hal_soc->use_register_windowing ||
  149. offset < MAX_UNWINDOWED_ADDRESS) {
  150. return qdf_ioread32(hal_soc->dev_base_addr + offset);
  151. }
  152. qdf_spin_lock_irqsave(&hal_soc->register_access_lock);
  153. hal_select_window(hal_soc, offset);
  154. ret = qdf_ioread32(hal_soc->dev_base_addr + WINDOW_START +
  155. (offset & WINDOW_RANGE_MASK));
  156. qdf_spin_unlock_irqrestore(&hal_soc->register_access_lock);
  157. return ret;
  158. }
  159. #else
  160. static inline uint32_t hal_read32_mb(struct hal_soc *hal_soc, uint32_t offset)
  161. {
  162. uint32_t ret;
  163. if ((offset > MAPPED_REF_OFF) &&
  164. hal_force_wake_request(hal_soc)) {
  165. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  166. "%s: Wake up request failed\n", __func__);
  167. return -EINVAL;
  168. }
  169. if (!hal_soc->use_register_windowing ||
  170. offset < MAX_UNWINDOWED_ADDRESS) {
  171. return qdf_ioread32(hal_soc->dev_base_addr + offset);
  172. }
  173. qdf_spin_lock_irqsave(&hal_soc->register_access_lock);
  174. hal_select_window(hal_soc, offset);
  175. ret = qdf_ioread32(hal_soc->dev_base_addr + WINDOW_START +
  176. (offset & WINDOW_RANGE_MASK));
  177. qdf_spin_unlock_irqrestore(&hal_soc->register_access_lock);
  178. if ((offset > MAPPED_REF_OFF) &&
  179. hal_force_wake_release(hal_soc))
  180. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  181. "%s: Wake up release failed\n", __func__);
  182. return ret;
  183. }
  184. #endif
  185. #include "hif_io32.h"
  186. /**
  187. * hal_attach - Initialize HAL layer
  188. * @hif_handle: Opaque HIF handle
  189. * @qdf_dev: QDF device
  190. *
  191. * Return: Opaque HAL SOC handle
  192. * NULL on failure (if given ring is not available)
  193. *
  194. * This function should be called as part of HIF initialization (for accessing
  195. * copy engines). DP layer will get hal_soc handle using hif_get_hal_handle()
  196. */
  197. extern void *hal_attach(void *hif_handle, qdf_device_t qdf_dev);
  198. /**
  199. * hal_detach - Detach HAL layer
  200. * @hal_soc: HAL SOC handle
  201. *
  202. * This function should be called as part of HIF detach
  203. *
  204. */
  205. extern void hal_detach(void *hal_soc);
  206. /* SRNG type to be passed in APIs hal_srng_get_entrysize and hal_srng_setup */
  207. enum hal_ring_type {
  208. REO_DST = 0,
  209. REO_EXCEPTION = 1,
  210. REO_REINJECT = 2,
  211. REO_CMD = 3,
  212. REO_STATUS = 4,
  213. TCL_DATA = 5,
  214. TCL_CMD = 6,
  215. TCL_STATUS = 7,
  216. CE_SRC = 8,
  217. CE_DST = 9,
  218. CE_DST_STATUS = 10,
  219. WBM_IDLE_LINK = 11,
  220. SW2WBM_RELEASE = 12,
  221. WBM2SW_RELEASE = 13,
  222. RXDMA_BUF = 14,
  223. RXDMA_DST = 15,
  224. RXDMA_MONITOR_BUF = 16,
  225. RXDMA_MONITOR_STATUS = 17,
  226. RXDMA_MONITOR_DST = 18,
  227. RXDMA_MONITOR_DESC = 19,
  228. DIR_BUF_RX_DMA_SRC = 20,
  229. #ifdef WLAN_FEATURE_CIF_CFR
  230. WIFI_POS_SRC,
  231. #endif
  232. MAX_RING_TYPES
  233. };
  234. #define HAL_SRNG_LMAC_RING 0x80000000
  235. /* SRNG flags passed in hal_srng_params.flags */
  236. #define HAL_SRNG_MSI_SWAP 0x00000008
  237. #define HAL_SRNG_RING_PTR_SWAP 0x00000010
  238. #define HAL_SRNG_DATA_TLV_SWAP 0x00000020
  239. #define HAL_SRNG_LOW_THRES_INTR_ENABLE 0x00010000
  240. #define HAL_SRNG_MSI_INTR 0x00020000
  241. #define PN_SIZE_24 0
  242. #define PN_SIZE_48 1
  243. #define PN_SIZE_128 2
  244. /**
  245. * hal_srng_get_entrysize - Returns size of ring entry in bytes. Should be
  246. * used by callers for calculating the size of memory to be allocated before
  247. * calling hal_srng_setup to setup the ring
  248. *
  249. * @hal_soc: Opaque HAL SOC handle
  250. * @ring_type: one of the types from hal_ring_type
  251. *
  252. */
  253. extern uint32_t hal_srng_get_entrysize(void *hal_soc, int ring_type);
  254. /**
  255. * hal_srng_max_entries - Returns maximum possible number of ring entries
  256. * @hal_soc: Opaque HAL SOC handle
  257. * @ring_type: one of the types from hal_ring_type
  258. *
  259. * Return: Maximum number of entries for the given ring_type
  260. */
  261. uint32_t hal_srng_max_entries(void *hal_soc, int ring_type);
  262. /**
  263. * hal_srng_dump - Dump ring status
  264. * @srng: hal srng pointer
  265. */
  266. void hal_srng_dump(struct hal_srng *srng);
  267. /**
  268. * hal_srng_get_dir - Returns the direction of the ring
  269. * @hal_soc: Opaque HAL SOC handle
  270. * @ring_type: one of the types from hal_ring_type
  271. *
  272. * Return: Ring direction
  273. */
  274. enum hal_srng_dir hal_srng_get_dir(void *hal_soc, int ring_type);
  275. /* HAL memory information */
  276. struct hal_mem_info {
  277. /* dev base virutal addr */
  278. void *dev_base_addr;
  279. /* dev base physical addr */
  280. void *dev_base_paddr;
  281. /* Remote virtual pointer memory for HW/FW updates */
  282. void *shadow_rdptr_mem_vaddr;
  283. /* Remote physical pointer memory for HW/FW updates */
  284. void *shadow_rdptr_mem_paddr;
  285. /* Shared memory for ring pointer updates from host to FW */
  286. void *shadow_wrptr_mem_vaddr;
  287. /* Shared physical memory for ring pointer updates from host to FW */
  288. void *shadow_wrptr_mem_paddr;
  289. };
  290. /* SRNG parameters to be passed to hal_srng_setup */
  291. struct hal_srng_params {
  292. /* Physical base address of the ring */
  293. qdf_dma_addr_t ring_base_paddr;
  294. /* Virtual base address of the ring */
  295. void *ring_base_vaddr;
  296. /* Number of entries in ring */
  297. uint32_t num_entries;
  298. /* max transfer length */
  299. uint16_t max_buffer_length;
  300. /* MSI Address */
  301. qdf_dma_addr_t msi_addr;
  302. /* MSI data */
  303. uint32_t msi_data;
  304. /* Interrupt timer threshold – in micro seconds */
  305. uint32_t intr_timer_thres_us;
  306. /* Interrupt batch counter threshold – in number of ring entries */
  307. uint32_t intr_batch_cntr_thres_entries;
  308. /* Low threshold – in number of ring entries
  309. * (valid for src rings only)
  310. */
  311. uint32_t low_threshold;
  312. /* Misc flags */
  313. uint32_t flags;
  314. /* Unique ring id */
  315. uint8_t ring_id;
  316. /* Source or Destination ring */
  317. enum hal_srng_dir ring_dir;
  318. /* Size of ring entry */
  319. uint32_t entry_size;
  320. /* hw register base address */
  321. void *hwreg_base[MAX_SRNG_REG_GROUPS];
  322. };
  323. /* hal_construct_shadow_config() - initialize the shadow registers for dp rings
  324. * @hal_soc: hal handle
  325. *
  326. * Return: QDF_STATUS_OK on success
  327. */
  328. extern QDF_STATUS hal_construct_shadow_config(void *hal_soc);
  329. /* hal_set_one_shadow_config() - add a config for the specified ring
  330. * @hal_soc: hal handle
  331. * @ring_type: ring type
  332. * @ring_num: ring num
  333. *
  334. * The ring type and ring num uniquely specify the ring. After this call,
  335. * the hp/tp will be added as the next entry int the shadow register
  336. * configuration table. The hal code will use the shadow register address
  337. * in place of the hp/tp address.
  338. *
  339. * This function is exposed, so that the CE module can skip configuring shadow
  340. * registers for unused ring and rings assigned to the firmware.
  341. *
  342. * Return: QDF_STATUS_OK on success
  343. */
  344. extern QDF_STATUS hal_set_one_shadow_config(void *hal_soc, int ring_type,
  345. int ring_num);
  346. /**
  347. * hal_get_shadow_config() - retrieve the config table
  348. * @hal_soc: hal handle
  349. * @shadow_config: will point to the table after
  350. * @num_shadow_registers_configured: will contain the number of valid entries
  351. */
  352. extern void hal_get_shadow_config(void *hal_soc,
  353. struct pld_shadow_reg_v2_cfg **shadow_config,
  354. int *num_shadow_registers_configured);
  355. /**
  356. * hal_srng_setup - Initialize HW SRNG ring.
  357. *
  358. * @hal_soc: Opaque HAL SOC handle
  359. * @ring_type: one of the types from hal_ring_type
  360. * @ring_num: Ring number if there are multiple rings of
  361. * same type (staring from 0)
  362. * @mac_id: valid MAC Id should be passed if ring type is one of lmac rings
  363. * @ring_params: SRNG ring params in hal_srng_params structure.
  364. * Callers are expected to allocate contiguous ring memory of size
  365. * 'num_entries * entry_size' bytes and pass the physical and virtual base
  366. * addresses through 'ring_base_paddr' and 'ring_base_vaddr' in hal_srng_params
  367. * structure. Ring base address should be 8 byte aligned and size of each ring
  368. * entry should be queried using the API hal_srng_get_entrysize
  369. *
  370. * Return: Opaque pointer to ring on success
  371. * NULL on failure (if given ring is not available)
  372. */
  373. extern void *hal_srng_setup(void *hal_soc, int ring_type, int ring_num,
  374. int mac_id, struct hal_srng_params *ring_params);
  375. /* Remapping ids of REO rings */
  376. #define REO_REMAP_TCL 0
  377. #define REO_REMAP_SW1 1
  378. #define REO_REMAP_SW2 2
  379. #define REO_REMAP_SW3 3
  380. #define REO_REMAP_SW4 4
  381. #define REO_REMAP_RELEASE 5
  382. #define REO_REMAP_FW 6
  383. #define REO_REMAP_UNUSED 7
  384. /*
  385. * currently this macro only works for IX0 since all the rings we are remapping
  386. * can be remapped from HWIO_REO_R0_DESTINATION_RING_CTRL_IX_0
  387. */
  388. #define HAL_REO_REMAP_VAL(_ORIGINAL_DEST, _NEW_DEST) \
  389. HAL_REO_REMAP_VAL_(_ORIGINAL_DEST, _NEW_DEST)
  390. /* allow the destination macros to be expanded */
  391. #define HAL_REO_REMAP_VAL_(_ORIGINAL_DEST, _NEW_DEST) \
  392. (_NEW_DEST << \
  393. (HWIO_REO_R0_DESTINATION_RING_CTRL_IX_0_DEST_RING_MAPPING_ ## \
  394. _ORIGINAL_DEST ## _SHFT))
  395. /**
  396. * hal_reo_remap_IX0 - Remap REO ring destination
  397. * @hal: HAL SOC handle
  398. * @remap_val: Remap value
  399. */
  400. extern void hal_reo_remap_IX0(struct hal_soc *hal, uint32_t remap_val);
  401. /**
  402. * hal_srng_set_hp_paddr() - Set physical address to dest SRNG head pointer
  403. * @sring: sring pointer
  404. * @paddr: physical address
  405. */
  406. extern void hal_srng_dst_set_hp_paddr(struct hal_srng *sring, uint64_t paddr);
  407. /**
  408. * hal_srng_dst_init_hp() - Initilaize head pointer with cached head pointer
  409. * @srng: sring pointer
  410. * @vaddr: virtual address
  411. */
  412. extern void hal_srng_dst_init_hp(struct hal_srng *srng, uint32_t *vaddr);
  413. /**
  414. * hal_srng_cleanup - Deinitialize HW SRNG ring.
  415. * @hal_soc: Opaque HAL SOC handle
  416. * @hal_srng: Opaque HAL SRNG pointer
  417. */
  418. extern void hal_srng_cleanup(void *hal_soc, void *hal_srng);
  419. static inline bool hal_srng_initialized(void *hal_ring)
  420. {
  421. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  422. return !!srng->initialized;
  423. }
  424. /**
  425. * hal_srng_access_start_unlocked - Start ring access (unlocked). Should use
  426. * hal_srng_access_start if locked access is required
  427. *
  428. * @hal_soc: Opaque HAL SOC handle
  429. * @hal_ring: Ring pointer (Source or Destination ring)
  430. *
  431. * Return: 0 on success; error on failire
  432. */
  433. static inline int hal_srng_access_start_unlocked(void *hal_soc, void *hal_ring)
  434. {
  435. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  436. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  437. srng->u.src_ring.cached_tp =
  438. *(volatile uint32_t *)(srng->u.src_ring.tp_addr);
  439. else
  440. srng->u.dst_ring.cached_hp =
  441. *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  442. return 0;
  443. }
  444. /**
  445. * hal_srng_access_start - Start (locked) ring access
  446. *
  447. * @hal_soc: Opaque HAL SOC handle
  448. * @hal_ring: Ring pointer (Source or Destination ring)
  449. *
  450. * Return: 0 on success; error on failire
  451. */
  452. static inline int hal_srng_access_start(void *hal_soc, void *hal_ring)
  453. {
  454. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  455. if (qdf_unlikely(!hal_ring)) {
  456. qdf_print("Error: Invalid hal_ring\n");
  457. return -EINVAL;
  458. }
  459. SRNG_LOCK(&(srng->lock));
  460. return hal_srng_access_start_unlocked(hal_soc, hal_ring);
  461. }
  462. /**
  463. * hal_srng_dst_get_next - Get next entry from a destination ring and move
  464. * cached tail pointer
  465. *
  466. * @hal_soc: Opaque HAL SOC handle
  467. * @hal_ring: Destination ring pointer
  468. *
  469. * Return: Opaque pointer for next ring entry; NULL on failire
  470. */
  471. static inline void *hal_srng_dst_get_next(void *hal_soc, void *hal_ring)
  472. {
  473. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  474. uint32_t *desc;
  475. if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp) {
  476. desc = &(srng->ring_base_vaddr[srng->u.dst_ring.tp]);
  477. /* TODO: Using % is expensive, but we have to do this since
  478. * size of some SRNG rings is not power of 2 (due to descriptor
  479. * sizes). Need to create separate API for rings used
  480. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  481. * SW2RXDMA and CE rings)
  482. */
  483. srng->u.dst_ring.tp = (srng->u.dst_ring.tp + srng->entry_size) %
  484. srng->ring_size;
  485. return (void *)desc;
  486. }
  487. return NULL;
  488. }
  489. /**
  490. * hal_srng_dst_get_next_hp - Get next entry from a destination ring and move
  491. * cached head pointer
  492. *
  493. * @hal_soc: Opaque HAL SOC handle
  494. * @hal_ring: Destination ring pointer
  495. *
  496. * Return: Opaque pointer for next ring entry; NULL on failire
  497. */
  498. static inline void *hal_srng_dst_get_next_hp(void *hal_soc, void *hal_ring)
  499. {
  500. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  501. uint32_t *desc;
  502. /* TODO: Using % is expensive, but we have to do this since
  503. * size of some SRNG rings is not power of 2 (due to descriptor
  504. * sizes). Need to create separate API for rings used
  505. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  506. * SW2RXDMA and CE rings)
  507. */
  508. uint32_t next_hp = (srng->u.dst_ring.cached_hp + srng->entry_size) %
  509. srng->ring_size;
  510. if (next_hp != srng->u.dst_ring.tp) {
  511. desc = &(srng->ring_base_vaddr[srng->u.dst_ring.cached_hp]);
  512. srng->u.dst_ring.cached_hp = next_hp;
  513. return (void *)desc;
  514. }
  515. return NULL;
  516. }
  517. /**
  518. * hal_srng_dst_peek - Get next entry from a ring without moving tail pointer.
  519. * hal_srng_dst_get_next should be called subsequently to move the tail pointer
  520. * TODO: See if we need an optimized version of get_next that doesn't check for
  521. * loop_cnt
  522. *
  523. * @hal_soc: Opaque HAL SOC handle
  524. * @hal_ring: Destination ring pointer
  525. *
  526. * Return: Opaque pointer for next ring entry; NULL on failire
  527. */
  528. static inline void *hal_srng_dst_peek(void *hal_soc, void *hal_ring)
  529. {
  530. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  531. if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp)
  532. return (void *)(&(srng->ring_base_vaddr[srng->u.dst_ring.tp]));
  533. return NULL;
  534. }
  535. /**
  536. * hal_srng_dst_num_valid - Returns number of valid entries (to be processed
  537. * by SW) in destination ring
  538. *
  539. * @hal_soc: Opaque HAL SOC handle
  540. * @hal_ring: Destination ring pointer
  541. * @sync_hw_ptr: Sync cached head pointer with HW
  542. *
  543. */
  544. static inline uint32_t hal_srng_dst_num_valid(void *hal_soc, void *hal_ring,
  545. int sync_hw_ptr)
  546. {
  547. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  548. uint32_t hp;
  549. uint32_t tp = srng->u.dst_ring.tp;
  550. if (sync_hw_ptr) {
  551. hp = *(srng->u.dst_ring.hp_addr);
  552. srng->u.dst_ring.cached_hp = hp;
  553. } else {
  554. hp = srng->u.dst_ring.cached_hp;
  555. }
  556. if (hp >= tp)
  557. return (hp - tp) / srng->entry_size;
  558. else
  559. return (srng->ring_size - tp + hp) / srng->entry_size;
  560. }
  561. /**
  562. * hal_srng_src_reap_next - Reap next entry from a source ring and move reap
  563. * pointer. This can be used to release any buffers associated with completed
  564. * ring entries. Note that this should not be used for posting new descriptor
  565. * entries. Posting of new entries should be done only using
  566. * hal_srng_src_get_next_reaped when this function is used for reaping.
  567. *
  568. * @hal_soc: Opaque HAL SOC handle
  569. * @hal_ring: Source ring pointer
  570. *
  571. * Return: Opaque pointer for next ring entry; NULL on failire
  572. */
  573. static inline void *hal_srng_src_reap_next(void *hal_soc, void *hal_ring)
  574. {
  575. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  576. uint32_t *desc;
  577. /* TODO: Using % is expensive, but we have to do this since
  578. * size of some SRNG rings is not power of 2 (due to descriptor
  579. * sizes). Need to create separate API for rings used
  580. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  581. * SW2RXDMA and CE rings)
  582. */
  583. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  584. srng->ring_size;
  585. if (next_reap_hp != srng->u.src_ring.cached_tp) {
  586. desc = &(srng->ring_base_vaddr[next_reap_hp]);
  587. srng->u.src_ring.reap_hp = next_reap_hp;
  588. return (void *)desc;
  589. }
  590. return NULL;
  591. }
  592. /**
  593. * hal_srng_src_get_next_reaped - Get next entry from a source ring that is
  594. * already reaped using hal_srng_src_reap_next, for posting new entries to
  595. * the ring
  596. *
  597. * @hal_soc: Opaque HAL SOC handle
  598. * @hal_ring: Source ring pointer
  599. *
  600. * Return: Opaque pointer for next (reaped) source ring entry; NULL on failire
  601. */
  602. static inline void *hal_srng_src_get_next_reaped(void *hal_soc, void *hal_ring)
  603. {
  604. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  605. uint32_t *desc;
  606. if (srng->u.src_ring.hp != srng->u.src_ring.reap_hp) {
  607. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  608. srng->u.src_ring.hp = (srng->u.src_ring.hp + srng->entry_size) %
  609. srng->ring_size;
  610. return (void *)desc;
  611. }
  612. return NULL;
  613. }
  614. /**
  615. * hal_srng_src_pending_reap_next - Reap next entry from a source ring and
  616. * move reap pointer. This API is used in detach path to release any buffers
  617. * associated with ring entries which are pending reap.
  618. *
  619. * @hal_soc: Opaque HAL SOC handle
  620. * @hal_ring: Source ring pointer
  621. *
  622. * Return: Opaque pointer for next ring entry; NULL on failire
  623. */
  624. static inline void *hal_srng_src_pending_reap_next(void *hal_soc, void *hal_ring)
  625. {
  626. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  627. uint32_t *desc;
  628. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  629. srng->ring_size;
  630. if (next_reap_hp != srng->u.src_ring.hp) {
  631. desc = &(srng->ring_base_vaddr[next_reap_hp]);
  632. srng->u.src_ring.reap_hp = next_reap_hp;
  633. return (void *)desc;
  634. }
  635. return NULL;
  636. }
  637. /**
  638. * hal_srng_src_done_val -
  639. *
  640. * @hal_soc: Opaque HAL SOC handle
  641. * @hal_ring: Source ring pointer
  642. *
  643. * Return: Opaque pointer for next ring entry; NULL on failire
  644. */
  645. static inline uint32_t hal_srng_src_done_val(void *hal_soc, void *hal_ring)
  646. {
  647. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  648. /* TODO: Using % is expensive, but we have to do this since
  649. * size of some SRNG rings is not power of 2 (due to descriptor
  650. * sizes). Need to create separate API for rings used
  651. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  652. * SW2RXDMA and CE rings)
  653. */
  654. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  655. srng->ring_size;
  656. if (next_reap_hp == srng->u.src_ring.cached_tp)
  657. return 0;
  658. if (srng->u.src_ring.cached_tp > next_reap_hp)
  659. return (srng->u.src_ring.cached_tp - next_reap_hp) /
  660. srng->entry_size;
  661. else
  662. return ((srng->ring_size - next_reap_hp) +
  663. srng->u.src_ring.cached_tp) / srng->entry_size;
  664. }
  665. /**
  666. * hal_api_get_tphp - Get head and tail pointer location for any ring
  667. * @hal_soc: Opaque HAL SOC handle
  668. * @hal_ring: Source ring pointer
  669. * @tailp: Tail Pointer
  670. * @headp: Head Pointer
  671. *
  672. * Return: Update tail pointer and head pointer in arguments.
  673. */
  674. static inline void hal_api_get_tphp(void *hal_soc, void *hal_ring,
  675. uint32_t *tailp, uint32_t *headp)
  676. {
  677. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  678. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  679. *headp = srng->u.src_ring.hp / srng->entry_size;
  680. *tailp = *(srng->u.src_ring.tp_addr) / srng->entry_size;
  681. } else {
  682. *tailp = srng->u.dst_ring.tp / srng->entry_size;
  683. *headp = *(srng->u.dst_ring.hp_addr) / srng->entry_size;
  684. }
  685. }
  686. /**
  687. * hal_srng_src_get_next - Get next entry from a source ring and move cached tail pointer
  688. *
  689. * @hal_soc: Opaque HAL SOC handle
  690. * @hal_ring: Source ring pointer
  691. *
  692. * Return: Opaque pointer for next ring entry; NULL on failire
  693. */
  694. static inline void *hal_srng_src_get_next(void *hal_soc, void *hal_ring)
  695. {
  696. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  697. uint32_t *desc;
  698. /* TODO: Using % is expensive, but we have to do this since
  699. * size of some SRNG rings is not power of 2 (due to descriptor
  700. * sizes). Need to create separate API for rings used
  701. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  702. * SW2RXDMA and CE rings)
  703. */
  704. uint32_t next_hp = (srng->u.src_ring.hp + srng->entry_size) %
  705. srng->ring_size;
  706. if (next_hp != srng->u.src_ring.cached_tp) {
  707. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  708. srng->u.src_ring.hp = next_hp;
  709. /* TODO: Since reap function is not used by all rings, we can
  710. * remove the following update of reap_hp in this function
  711. * if we can ensure that only hal_srng_src_get_next_reaped
  712. * is used for the rings requiring reap functionality
  713. */
  714. srng->u.src_ring.reap_hp = next_hp;
  715. return (void *)desc;
  716. }
  717. return NULL;
  718. }
  719. /**
  720. * hal_srng_src_peek - Get next entry from a ring without moving head pointer.
  721. * hal_srng_src_get_next should be called subsequently to move the head pointer
  722. *
  723. * @hal_soc: Opaque HAL SOC handle
  724. * @hal_ring: Source ring pointer
  725. *
  726. * Return: Opaque pointer for next ring entry; NULL on failire
  727. */
  728. static inline void *hal_srng_src_peek(void *hal_soc, void *hal_ring)
  729. {
  730. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  731. uint32_t *desc;
  732. /* TODO: Using % is expensive, but we have to do this since
  733. * size of some SRNG rings is not power of 2 (due to descriptor
  734. * sizes). Need to create separate API for rings used
  735. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  736. * SW2RXDMA and CE rings)
  737. */
  738. if (((srng->u.src_ring.hp + srng->entry_size) %
  739. srng->ring_size) != srng->u.src_ring.cached_tp) {
  740. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  741. return (void *)desc;
  742. }
  743. return NULL;
  744. }
  745. /**
  746. * hal_srng_src_num_avail - Returns number of available entries in src ring
  747. *
  748. * @hal_soc: Opaque HAL SOC handle
  749. * @hal_ring: Source ring pointer
  750. * @sync_hw_ptr: Sync cached tail pointer with HW
  751. *
  752. */
  753. static inline uint32_t hal_srng_src_num_avail(void *hal_soc,
  754. void *hal_ring, int sync_hw_ptr)
  755. {
  756. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  757. uint32_t tp;
  758. uint32_t hp = srng->u.src_ring.hp;
  759. if (sync_hw_ptr) {
  760. tp = *(srng->u.src_ring.tp_addr);
  761. srng->u.src_ring.cached_tp = tp;
  762. } else {
  763. tp = srng->u.src_ring.cached_tp;
  764. }
  765. if (tp > hp)
  766. return ((tp - hp) / srng->entry_size) - 1;
  767. else
  768. return ((srng->ring_size - hp + tp) / srng->entry_size) - 1;
  769. }
  770. /**
  771. * hal_srng_access_end_unlocked - End ring access (unlocked) - update cached
  772. * ring head/tail pointers to HW.
  773. * This should be used only if hal_srng_access_start_unlocked to start ring
  774. * access
  775. *
  776. * @hal_soc: Opaque HAL SOC handle
  777. * @hal_ring: Ring pointer (Source or Destination ring)
  778. *
  779. * Return: 0 on success; error on failire
  780. */
  781. static inline void hal_srng_access_end_unlocked(void *hal_soc, void *hal_ring)
  782. {
  783. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  784. /* TODO: See if we need a write memory barrier here */
  785. if (srng->flags & HAL_SRNG_LMAC_RING) {
  786. /* For LMAC rings, ring pointer updates are done through FW and
  787. * hence written to a shared memory location that is read by FW
  788. */
  789. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  790. *(srng->u.src_ring.hp_addr) = srng->u.src_ring.hp;
  791. } else {
  792. *(srng->u.dst_ring.tp_addr) = srng->u.dst_ring.tp;
  793. }
  794. } else {
  795. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  796. hal_write_address_32_mb(hal_soc,
  797. srng->u.src_ring.hp_addr,
  798. srng->u.src_ring.hp);
  799. else
  800. hal_write_address_32_mb(hal_soc,
  801. srng->u.dst_ring.tp_addr,
  802. srng->u.dst_ring.tp);
  803. }
  804. }
  805. /**
  806. * hal_srng_access_end - Unlock ring access and update cached ring head/tail
  807. * pointers to HW
  808. * This should be used only if hal_srng_access_start to start ring access
  809. *
  810. * @hal_soc: Opaque HAL SOC handle
  811. * @hal_ring: Ring pointer (Source or Destination ring)
  812. *
  813. * Return: 0 on success; error on failire
  814. */
  815. static inline void hal_srng_access_end(void *hal_soc, void *hal_ring)
  816. {
  817. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  818. if (qdf_unlikely(!hal_ring)) {
  819. qdf_print("Error: Invalid hal_ring\n");
  820. return;
  821. }
  822. hal_srng_access_end_unlocked(hal_soc, hal_ring);
  823. SRNG_UNLOCK(&(srng->lock));
  824. }
  825. /**
  826. * hal_srng_access_end_reap - Unlock ring access
  827. * This should be used only if hal_srng_access_start to start ring access
  828. * and should be used only while reaping SRC ring completions
  829. *
  830. * @hal_soc: Opaque HAL SOC handle
  831. * @hal_ring: Ring pointer (Source or Destination ring)
  832. *
  833. * Return: 0 on success; error on failire
  834. */
  835. static inline void hal_srng_access_end_reap(void *hal_soc, void *hal_ring)
  836. {
  837. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  838. SRNG_UNLOCK(&(srng->lock));
  839. }
  840. /* TODO: Check if the following definitions is available in HW headers */
  841. #define WBM_IDLE_SCATTER_BUF_SIZE 32704
  842. #define NUM_MPDUS_PER_LINK_DESC 6
  843. #define NUM_MSDUS_PER_LINK_DESC 7
  844. #define REO_QUEUE_DESC_ALIGN 128
  845. #define LINK_DESC_ALIGN 128
  846. #define ADDRESS_MATCH_TAG_VAL 0x5
  847. /* Number of mpdu link pointers is 9 in case of TX_MPDU_QUEUE_HEAD and 14 in
  848. * of TX_MPDU_QUEUE_EXT. We are defining a common average count here
  849. */
  850. #define NUM_MPDU_LINKS_PER_QUEUE_DESC 12
  851. /* TODO: Check with HW team on the scatter buffer size supported. As per WBM
  852. * MLD, scatter_buffer_size in IDLE_LIST_CONTROL register is 9 bits and size
  853. * should be specified in 16 word units. But the number of bits defined for
  854. * this field in HW header files is 5.
  855. */
  856. #define WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE 8
  857. /**
  858. * hal_idle_list_scatter_buf_size - Get the size of each scatter buffer
  859. * in an idle list
  860. *
  861. * @hal_soc: Opaque HAL SOC handle
  862. *
  863. */
  864. static inline uint32_t hal_idle_list_scatter_buf_size(void *hal_soc)
  865. {
  866. return WBM_IDLE_SCATTER_BUF_SIZE;
  867. }
  868. /**
  869. * hal_get_link_desc_size - Get the size of each link descriptor
  870. *
  871. * @hal_soc: Opaque HAL SOC handle
  872. *
  873. */
  874. static inline uint32_t hal_get_link_desc_size(struct hal_soc *hal_soc)
  875. {
  876. if (!hal_soc || !hal_soc->ops) {
  877. qdf_print("Error: Invalid ops\n");
  878. QDF_BUG(0);
  879. return -EINVAL;
  880. }
  881. if (!hal_soc->ops->hal_get_link_desc_size) {
  882. qdf_print("Error: Invalid function pointer\n");
  883. QDF_BUG(0);
  884. return -EINVAL;
  885. }
  886. return hal_soc->ops->hal_get_link_desc_size();
  887. }
  888. /**
  889. * hal_get_link_desc_align - Get the required start address alignment for
  890. * link descriptors
  891. *
  892. * @hal_soc: Opaque HAL SOC handle
  893. *
  894. */
  895. static inline uint32_t hal_get_link_desc_align(void *hal_soc)
  896. {
  897. return LINK_DESC_ALIGN;
  898. }
  899. /**
  900. * hal_num_mpdus_per_link_desc - Get number of mpdus each link desc can hold
  901. *
  902. * @hal_soc: Opaque HAL SOC handle
  903. *
  904. */
  905. static inline uint32_t hal_num_mpdus_per_link_desc(void *hal_soc)
  906. {
  907. return NUM_MPDUS_PER_LINK_DESC;
  908. }
  909. /**
  910. * hal_num_msdus_per_link_desc - Get number of msdus each link desc can hold
  911. *
  912. * @hal_soc: Opaque HAL SOC handle
  913. *
  914. */
  915. static inline uint32_t hal_num_msdus_per_link_desc(void *hal_soc)
  916. {
  917. return NUM_MSDUS_PER_LINK_DESC;
  918. }
  919. /**
  920. * hal_num_mpdu_links_per_queue_desc - Get number of mpdu links each queue
  921. * descriptor can hold
  922. *
  923. * @hal_soc: Opaque HAL SOC handle
  924. *
  925. */
  926. static inline uint32_t hal_num_mpdu_links_per_queue_desc(void *hal_soc)
  927. {
  928. return NUM_MPDU_LINKS_PER_QUEUE_DESC;
  929. }
  930. /**
  931. * hal_idle_list_scatter_buf_num_entries - Get the number of link desc entries
  932. * that the given buffer size
  933. *
  934. * @hal_soc: Opaque HAL SOC handle
  935. * @scatter_buf_size: Size of scatter buffer
  936. *
  937. */
  938. static inline uint32_t hal_idle_scatter_buf_num_entries(void *hal_soc,
  939. uint32_t scatter_buf_size)
  940. {
  941. return (scatter_buf_size - WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE) /
  942. hal_srng_get_entrysize(hal_soc, WBM_IDLE_LINK);
  943. }
  944. /**
  945. * hal_idle_list_num_scatter_bufs - Get the number of sctater buffer
  946. * each given buffer size
  947. *
  948. * @hal_soc: Opaque HAL SOC handle
  949. * @total_mem: size of memory to be scattered
  950. * @scatter_buf_size: Size of scatter buffer
  951. *
  952. */
  953. static inline uint32_t hal_idle_list_num_scatter_bufs(void *hal_soc,
  954. uint32_t total_mem, uint32_t scatter_buf_size)
  955. {
  956. uint8_t rem = (total_mem % (scatter_buf_size -
  957. WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE)) ? 1 : 0;
  958. uint32_t num_scatter_bufs = (total_mem / (scatter_buf_size -
  959. WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE)) + rem;
  960. return num_scatter_bufs;
  961. }
  962. /* REO parameters to be passed to hal_reo_setup */
  963. struct hal_reo_params {
  964. /** rx hash steering enabled or disabled */
  965. bool rx_hash_enabled;
  966. /** reo remap 1 register */
  967. uint32_t remap1;
  968. /** reo remap 2 register */
  969. uint32_t remap2;
  970. /** fragment destination ring */
  971. uint8_t frag_dst_ring;
  972. /** padding */
  973. uint8_t padding[3];
  974. };
  975. enum hal_pn_type {
  976. HAL_PN_NONE,
  977. HAL_PN_WPA,
  978. HAL_PN_WAPI_EVEN,
  979. HAL_PN_WAPI_UNEVEN,
  980. };
  981. #define HAL_RX_MAX_BA_WINDOW 256
  982. /**
  983. * hal_get_reo_qdesc_align - Get start address alignment for reo
  984. * queue descriptors
  985. *
  986. * @hal_soc: Opaque HAL SOC handle
  987. *
  988. */
  989. static inline uint32_t hal_get_reo_qdesc_align(void *hal_soc)
  990. {
  991. return REO_QUEUE_DESC_ALIGN;
  992. }
  993. /**
  994. * hal_reo_qdesc_setup - Setup HW REO queue descriptor
  995. *
  996. * @hal_soc: Opaque HAL SOC handle
  997. * @ba_window_size: BlockAck window size
  998. * @start_seq: Starting sequence number
  999. * @hw_qdesc_vaddr: Virtual address of REO queue descriptor memory
  1000. * @hw_qdesc_paddr: Physical address of REO queue descriptor memory
  1001. * @pn_type: PN type (one of the types defined in 'enum hal_pn_type')
  1002. *
  1003. */
  1004. extern void hal_reo_qdesc_setup(void *hal_soc, int tid, uint32_t ba_window_size,
  1005. uint32_t start_seq, void *hw_qdesc_vaddr, qdf_dma_addr_t hw_qdesc_paddr,
  1006. int pn_type);
  1007. /**
  1008. * hal_srng_get_hp_addr - Get head pointer physical address
  1009. *
  1010. * @hal_soc: Opaque HAL SOC handle
  1011. * @hal_ring: Ring pointer (Source or Destination ring)
  1012. *
  1013. */
  1014. static inline qdf_dma_addr_t hal_srng_get_hp_addr(void *hal_soc, void *hal_ring)
  1015. {
  1016. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  1017. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  1018. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1019. return hal->shadow_wrptr_mem_paddr +
  1020. ((unsigned long)(srng->u.src_ring.hp_addr) -
  1021. (unsigned long)(hal->shadow_wrptr_mem_vaddr));
  1022. } else {
  1023. return hal->shadow_rdptr_mem_paddr +
  1024. ((unsigned long)(srng->u.dst_ring.hp_addr) -
  1025. (unsigned long)(hal->shadow_rdptr_mem_vaddr));
  1026. }
  1027. }
  1028. /**
  1029. * hal_srng_get_tp_addr - Get tail pointer physical address
  1030. *
  1031. * @hal_soc: Opaque HAL SOC handle
  1032. * @hal_ring: Ring pointer (Source or Destination ring)
  1033. *
  1034. */
  1035. static inline qdf_dma_addr_t hal_srng_get_tp_addr(void *hal_soc, void *hal_ring)
  1036. {
  1037. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  1038. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  1039. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1040. return hal->shadow_rdptr_mem_paddr +
  1041. ((unsigned long)(srng->u.src_ring.tp_addr) -
  1042. (unsigned long)(hal->shadow_rdptr_mem_vaddr));
  1043. } else {
  1044. return hal->shadow_wrptr_mem_paddr +
  1045. ((unsigned long)(srng->u.dst_ring.tp_addr) -
  1046. (unsigned long)(hal->shadow_wrptr_mem_vaddr));
  1047. }
  1048. }
  1049. /**
  1050. * hal_get_srng_params - Retrieve SRNG parameters for a given ring from HAL
  1051. *
  1052. * @hal_soc: Opaque HAL SOC handle
  1053. * @hal_ring: Ring pointer (Source or Destination ring)
  1054. * @ring_params: SRNG parameters will be returned through this structure
  1055. */
  1056. extern void hal_get_srng_params(void *hal_soc, void *hal_ring,
  1057. struct hal_srng_params *ring_params);
  1058. /**
  1059. * hal_mem_info - Retrieve hal memory base address
  1060. *
  1061. * @hal_soc: Opaque HAL SOC handle
  1062. * @mem: pointer to structure to be updated with hal mem info
  1063. */
  1064. extern void hal_get_meminfo(void *hal_soc,struct hal_mem_info *mem );
  1065. /**
  1066. * hal_get_target_type - Return target type
  1067. *
  1068. * @hal_soc: Opaque HAL SOC handle
  1069. */
  1070. uint32_t hal_get_target_type(struct hal_soc *hal);
  1071. /**
  1072. * hal_get_ba_aging_timeout - Retrieve BA aging timeout
  1073. *
  1074. * @hal_soc: Opaque HAL SOC handle
  1075. * @ac: Access category
  1076. * @value: timeout duration in millisec
  1077. */
  1078. void hal_get_ba_aging_timeout(void *hal_soc, uint8_t ac,
  1079. uint32_t *value);
  1080. /**
  1081. * hal_set_aging_timeout - Set BA aging timeout
  1082. *
  1083. * @hal_soc: Opaque HAL SOC handle
  1084. * @ac: Access category in millisec
  1085. * @value: timeout duration value
  1086. */
  1087. void hal_set_ba_aging_timeout(void *hal_soc, uint8_t ac,
  1088. uint32_t value);
  1089. /**
  1090. * hal_srng_dst_hw_init - Private function to initialize SRNG
  1091. * destination ring HW
  1092. * @hal_soc: HAL SOC handle
  1093. * @srng: SRNG ring pointer
  1094. */
  1095. static inline void hal_srng_dst_hw_init(struct hal_soc *hal,
  1096. struct hal_srng *srng)
  1097. {
  1098. hal->ops->hal_srng_dst_hw_init(hal, srng);
  1099. }
  1100. /**
  1101. * hal_srng_src_hw_init - Private function to initialize SRNG
  1102. * source ring HW
  1103. * @hal_soc: HAL SOC handle
  1104. * @srng: SRNG ring pointer
  1105. */
  1106. static inline void hal_srng_src_hw_init(struct hal_soc *hal,
  1107. struct hal_srng *srng)
  1108. {
  1109. hal->ops->hal_srng_src_hw_init(hal, srng);
  1110. }
  1111. /**
  1112. * hal_reo_setup - Initialize HW REO block
  1113. *
  1114. * @hal_soc: Opaque HAL SOC handle
  1115. * @reo_params: parameters needed by HAL for REO config
  1116. */
  1117. static inline void hal_reo_setup(void *halsoc,
  1118. void *reoparams)
  1119. {
  1120. struct hal_soc *hal_soc = (struct hal_soc *)halsoc;
  1121. hal_soc->ops->hal_reo_setup(halsoc, reoparams);
  1122. }
  1123. /**
  1124. * hal_setup_link_idle_list - Setup scattered idle list using the
  1125. * buffer list provided
  1126. *
  1127. * @hal_soc: Opaque HAL SOC handle
  1128. * @scatter_bufs_base_paddr: Array of physical base addresses
  1129. * @scatter_bufs_base_vaddr: Array of virtual base addresses
  1130. * @num_scatter_bufs: Number of scatter buffers in the above lists
  1131. * @scatter_buf_size: Size of each scatter buffer
  1132. * @last_buf_end_offset: Offset to the last entry
  1133. * @num_entries: Total entries of all scatter bufs
  1134. *
  1135. */
  1136. static inline void hal_setup_link_idle_list(void *halsoc,
  1137. qdf_dma_addr_t scatter_bufs_base_paddr[],
  1138. void *scatter_bufs_base_vaddr[], uint32_t num_scatter_bufs,
  1139. uint32_t scatter_buf_size, uint32_t last_buf_end_offset,
  1140. uint32_t num_entries)
  1141. {
  1142. struct hal_soc *hal_soc = (struct hal_soc *)halsoc;
  1143. hal_soc->ops->hal_setup_link_idle_list(halsoc, scatter_bufs_base_paddr,
  1144. scatter_bufs_base_vaddr, num_scatter_bufs,
  1145. scatter_buf_size, last_buf_end_offset,
  1146. num_entries);
  1147. }
  1148. #endif /* _HAL_APIH_ */