hal_api.h 37 KB

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