hal_api.h 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724
  1. /*
  2. * Copyright (c) 2016-2019 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 "qdf_atomic.h"
  23. #include "hal_internal.h"
  24. #define MAX_UNWINDOWED_ADDRESS 0x80000
  25. #if defined(QCA_WIFI_QCA6390) || defined(QCA_WIFI_QCA6490)
  26. #define WINDOW_ENABLE_BIT 0x40000000
  27. #else
  28. #define WINDOW_ENABLE_BIT 0x80000000
  29. #endif
  30. #define WINDOW_REG_ADDRESS 0x310C
  31. #define WINDOW_SHIFT 19
  32. #define WINDOW_VALUE_MASK 0x3F
  33. #define WINDOW_START MAX_UNWINDOWED_ADDRESS
  34. #define WINDOW_RANGE_MASK 0x7FFFF
  35. /*
  36. * BAR + 4K is always accessible, any access outside this
  37. * space requires force wake procedure.
  38. * OFFSET = 4K - 32 bytes = 0x4063
  39. */
  40. #define MAPPED_REF_OFF 0x4063
  41. #define FORCE_WAKE_DELAY_TIMEOUT 50
  42. #define FORCE_WAKE_DELAY_MS 5
  43. /**
  44. * hal_ring_desc - opaque handle for DP ring descriptor
  45. */
  46. struct hal_ring_desc;
  47. typedef struct hal_ring_desc *hal_ring_desc_t;
  48. /**
  49. * hal_link_desc - opaque handle for DP link descriptor
  50. */
  51. struct hal_link_desc;
  52. typedef struct hal_link_desc *hal_link_desc_t;
  53. /**
  54. * hal_rxdma_desc - opaque handle for DP rxdma dst ring descriptor
  55. */
  56. struct hal_rxdma_desc;
  57. typedef struct hal_rxdma_desc *hal_rxdma_desc_t;
  58. #ifdef ENABLE_VERBOSE_DEBUG
  59. static inline void
  60. hal_set_verbose_debug(bool flag)
  61. {
  62. is_hal_verbose_debug_enabled = flag;
  63. }
  64. #endif
  65. #if !defined(QCA_WIFI_QCA6390) && !defined(QCA_WIFI_QCA6490)
  66. static inline int hal_force_wake_request(struct hal_soc *soc)
  67. {
  68. return 0;
  69. }
  70. static inline int hal_force_wake_release(struct hal_soc *soc)
  71. {
  72. return 0;
  73. }
  74. static inline void hal_lock_reg_access(struct hal_soc *soc,
  75. unsigned long *flags)
  76. {
  77. qdf_spin_lock_irqsave(&soc->register_access_lock);
  78. }
  79. static inline void hal_unlock_reg_access(struct hal_soc *soc,
  80. unsigned long *flags)
  81. {
  82. qdf_spin_unlock_irqrestore(&soc->register_access_lock);
  83. }
  84. #else
  85. static inline int hal_force_wake_request(struct hal_soc *soc)
  86. {
  87. uint32_t timeout = 0;
  88. int ret;
  89. ret = pld_force_wake_request(soc->qdf_dev->dev);
  90. if (ret) {
  91. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  92. "%s: Request send failed %d\n", __func__, ret);
  93. return -EINVAL;
  94. }
  95. while (!pld_is_device_awake(soc->qdf_dev->dev) &&
  96. timeout <= FORCE_WAKE_DELAY_TIMEOUT) {
  97. mdelay(FORCE_WAKE_DELAY_MS);
  98. timeout += FORCE_WAKE_DELAY_MS;
  99. }
  100. if (pld_is_device_awake(soc->qdf_dev->dev) == true)
  101. return 0;
  102. else
  103. return -ETIMEDOUT;
  104. }
  105. static inline int hal_force_wake_release(struct hal_soc *soc)
  106. {
  107. return pld_force_wake_release(soc->qdf_dev->dev);
  108. }
  109. static inline void hal_lock_reg_access(struct hal_soc *soc,
  110. unsigned long *flags)
  111. {
  112. pld_lock_reg_window(soc->qdf_dev->dev, flags);
  113. }
  114. static inline void hal_unlock_reg_access(struct hal_soc *soc,
  115. unsigned long *flags)
  116. {
  117. pld_unlock_reg_window(soc->qdf_dev->dev, flags);
  118. }
  119. #endif
  120. #ifdef PCIE_REG_WINDOW_LOCAL_NO_CACHE
  121. static inline void hal_select_window(struct hal_soc *hal_soc, uint32_t offset)
  122. {
  123. uint32_t window = (offset >> WINDOW_SHIFT) & WINDOW_VALUE_MASK;
  124. qdf_iowrite32(hal_soc->dev_base_addr + WINDOW_REG_ADDRESS,
  125. WINDOW_ENABLE_BIT | window);
  126. hal_soc->register_window = window;
  127. }
  128. #else
  129. static inline void hal_select_window(struct hal_soc *hal_soc, uint32_t offset)
  130. {
  131. uint32_t window = (offset >> WINDOW_SHIFT) & WINDOW_VALUE_MASK;
  132. if (window != hal_soc->register_window) {
  133. qdf_iowrite32(hal_soc->dev_base_addr + WINDOW_REG_ADDRESS,
  134. WINDOW_ENABLE_BIT | window);
  135. hal_soc->register_window = window;
  136. }
  137. }
  138. #endif
  139. /**
  140. * note1: WINDOW_RANGE_MASK = (1 << WINDOW_SHIFT) -1
  141. * note2: 1 << WINDOW_SHIFT = MAX_UNWINDOWED_ADDRESS
  142. * note3: WINDOW_VALUE_MASK = big enough that trying to write past that window
  143. * would be a bug
  144. */
  145. #if !defined(QCA_WIFI_QCA6390) && !defined(QCA_WIFI_QCA6490)
  146. static inline void hal_write32_mb(struct hal_soc *hal_soc, uint32_t offset,
  147. uint32_t value)
  148. {
  149. unsigned long flags;
  150. if (!hal_soc->use_register_windowing ||
  151. offset < MAX_UNWINDOWED_ADDRESS) {
  152. qdf_iowrite32(hal_soc->dev_base_addr + offset, value);
  153. } else {
  154. hal_lock_reg_access(hal_soc, &flags);
  155. hal_select_window(hal_soc, offset);
  156. qdf_iowrite32(hal_soc->dev_base_addr + WINDOW_START +
  157. (offset & WINDOW_RANGE_MASK), value);
  158. hal_unlock_reg_access(hal_soc, &flags);
  159. }
  160. }
  161. #else
  162. static inline void hal_write32_mb(struct hal_soc *hal_soc, uint32_t offset,
  163. uint32_t value)
  164. {
  165. int ret;
  166. unsigned long flags;
  167. if (offset > MAPPED_REF_OFF) {
  168. ret = hal_force_wake_request(hal_soc);
  169. if (ret) {
  170. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  171. "%s: Wake up request failed %d\n",
  172. __func__, ret);
  173. QDF_BUG(0);
  174. return;
  175. }
  176. }
  177. if (!hal_soc->use_register_windowing ||
  178. offset < MAX_UNWINDOWED_ADDRESS) {
  179. qdf_iowrite32(hal_soc->dev_base_addr + offset, value);
  180. } else {
  181. hal_lock_reg_access(hal_soc, &flags);
  182. hal_select_window(hal_soc, offset);
  183. qdf_iowrite32(hal_soc->dev_base_addr + WINDOW_START +
  184. (offset & WINDOW_RANGE_MASK), value);
  185. hal_unlock_reg_access(hal_soc, &flags);
  186. }
  187. if ((offset > MAPPED_REF_OFF) &&
  188. hal_force_wake_release(hal_soc))
  189. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  190. "%s: Wake up release failed\n", __func__);
  191. }
  192. #endif
  193. /**
  194. * hal_write_address_32_mb - write a value to a register
  195. *
  196. */
  197. static inline void hal_write_address_32_mb(struct hal_soc *hal_soc,
  198. void __iomem *addr, uint32_t value)
  199. {
  200. uint32_t offset;
  201. if (!hal_soc->use_register_windowing)
  202. return qdf_iowrite32(addr, value);
  203. offset = addr - hal_soc->dev_base_addr;
  204. hal_write32_mb(hal_soc, offset, value);
  205. }
  206. #if !defined(QCA_WIFI_QCA6390) && !defined(QCA_WIFI_QCA6490)
  207. static inline uint32_t hal_read32_mb(struct hal_soc *hal_soc, uint32_t offset)
  208. {
  209. uint32_t ret;
  210. unsigned long flags;
  211. if (!hal_soc->use_register_windowing ||
  212. offset < MAX_UNWINDOWED_ADDRESS) {
  213. return qdf_ioread32(hal_soc->dev_base_addr + offset);
  214. }
  215. hal_lock_reg_access(hal_soc, &flags);
  216. hal_select_window(hal_soc, offset);
  217. ret = qdf_ioread32(hal_soc->dev_base_addr + WINDOW_START +
  218. (offset & WINDOW_RANGE_MASK));
  219. hal_unlock_reg_access(hal_soc, &flags);
  220. return ret;
  221. }
  222. /**
  223. * hal_read_address_32_mb() - Read 32-bit value from the register
  224. * @soc: soc handle
  225. * @addr: register address to read
  226. *
  227. * Return: 32-bit value
  228. */
  229. static inline uint32_t hal_read_address_32_mb(struct hal_soc *soc,
  230. void __iomem *addr)
  231. {
  232. uint32_t offset;
  233. uint32_t ret;
  234. if (!soc->use_register_windowing)
  235. return qdf_ioread32(addr);
  236. offset = addr - soc->dev_base_addr;
  237. ret = hal_read32_mb(soc, offset);
  238. return ret;
  239. }
  240. #else
  241. static inline uint32_t hal_read32_mb(struct hal_soc *hal_soc, uint32_t offset)
  242. {
  243. uint32_t ret;
  244. unsigned long flags;
  245. if ((offset > MAPPED_REF_OFF) &&
  246. hal_force_wake_request(hal_soc)) {
  247. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  248. "%s: Wake up request failed\n", __func__);
  249. return -EINVAL;
  250. }
  251. if (!hal_soc->use_register_windowing ||
  252. offset < MAX_UNWINDOWED_ADDRESS) {
  253. return qdf_ioread32(hal_soc->dev_base_addr + offset);
  254. }
  255. hal_lock_reg_access(hal_soc, &flags);
  256. hal_select_window(hal_soc, offset);
  257. ret = qdf_ioread32(hal_soc->dev_base_addr + WINDOW_START +
  258. (offset & WINDOW_RANGE_MASK));
  259. hal_unlock_reg_access(hal_soc, &flags);
  260. if ((offset > MAPPED_REF_OFF) &&
  261. hal_force_wake_release(hal_soc))
  262. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  263. "%s: Wake up release failed\n", __func__);
  264. return ret;
  265. }
  266. static inline uint32_t hal_read_address_32_mb(struct hal_soc *soc,
  267. void __iomem *addr)
  268. {
  269. uint32_t offset;
  270. uint32_t ret;
  271. if (!soc->use_register_windowing)
  272. return qdf_ioread32(addr);
  273. offset = addr - soc->dev_base_addr;
  274. ret = hal_read32_mb(soc, offset);
  275. return ret;
  276. }
  277. #endif
  278. #include "hif_io32.h"
  279. /**
  280. * hal_attach - Initialize HAL layer
  281. * @hif_handle: Opaque HIF handle
  282. * @qdf_dev: QDF device
  283. *
  284. * Return: Opaque HAL SOC handle
  285. * NULL on failure (if given ring is not available)
  286. *
  287. * This function should be called as part of HIF initialization (for accessing
  288. * copy engines). DP layer will get hal_soc handle using hif_get_hal_handle()
  289. */
  290. void *hal_attach(struct hif_opaque_softc *hif_handle, qdf_device_t qdf_dev);
  291. /**
  292. * hal_detach - Detach HAL layer
  293. * @hal_soc: HAL SOC handle
  294. *
  295. * This function should be called as part of HIF detach
  296. *
  297. */
  298. extern void hal_detach(void *hal_soc);
  299. /* SRNG type to be passed in APIs hal_srng_get_entrysize and hal_srng_setup */
  300. enum hal_ring_type {
  301. REO_DST = 0,
  302. REO_EXCEPTION = 1,
  303. REO_REINJECT = 2,
  304. REO_CMD = 3,
  305. REO_STATUS = 4,
  306. TCL_DATA = 5,
  307. TCL_CMD = 6,
  308. TCL_STATUS = 7,
  309. CE_SRC = 8,
  310. CE_DST = 9,
  311. CE_DST_STATUS = 10,
  312. WBM_IDLE_LINK = 11,
  313. SW2WBM_RELEASE = 12,
  314. WBM2SW_RELEASE = 13,
  315. RXDMA_BUF = 14,
  316. RXDMA_DST = 15,
  317. RXDMA_MONITOR_BUF = 16,
  318. RXDMA_MONITOR_STATUS = 17,
  319. RXDMA_MONITOR_DST = 18,
  320. RXDMA_MONITOR_DESC = 19,
  321. DIR_BUF_RX_DMA_SRC = 20,
  322. #ifdef WLAN_FEATURE_CIF_CFR
  323. WIFI_POS_SRC,
  324. #endif
  325. MAX_RING_TYPES
  326. };
  327. #define HAL_SRNG_LMAC_RING 0x80000000
  328. /* SRNG flags passed in hal_srng_params.flags */
  329. #define HAL_SRNG_MSI_SWAP 0x00000008
  330. #define HAL_SRNG_RING_PTR_SWAP 0x00000010
  331. #define HAL_SRNG_DATA_TLV_SWAP 0x00000020
  332. #define HAL_SRNG_LOW_THRES_INTR_ENABLE 0x00010000
  333. #define HAL_SRNG_MSI_INTR 0x00020000
  334. #define HAL_SRNG_CACHED_DESC 0x00040000
  335. #define PN_SIZE_24 0
  336. #define PN_SIZE_48 1
  337. #define PN_SIZE_128 2
  338. /**
  339. * hal_srng_get_entrysize - Returns size of ring entry in bytes. Should be
  340. * used by callers for calculating the size of memory to be allocated before
  341. * calling hal_srng_setup to setup the ring
  342. *
  343. * @hal_soc: Opaque HAL SOC handle
  344. * @ring_type: one of the types from hal_ring_type
  345. *
  346. */
  347. extern uint32_t hal_srng_get_entrysize(void *hal_soc, int ring_type);
  348. /**
  349. * hal_srng_max_entries - Returns maximum possible number of ring entries
  350. * @hal_soc: Opaque HAL SOC handle
  351. * @ring_type: one of the types from hal_ring_type
  352. *
  353. * Return: Maximum number of entries for the given ring_type
  354. */
  355. uint32_t hal_srng_max_entries(void *hal_soc, int ring_type);
  356. /**
  357. * hal_srng_dump - Dump ring status
  358. * @srng: hal srng pointer
  359. */
  360. void hal_srng_dump(struct hal_srng *srng);
  361. /**
  362. * hal_srng_get_dir - Returns the direction of the ring
  363. * @hal_soc: Opaque HAL SOC handle
  364. * @ring_type: one of the types from hal_ring_type
  365. *
  366. * Return: Ring direction
  367. */
  368. enum hal_srng_dir hal_srng_get_dir(void *hal_soc, int ring_type);
  369. /* HAL memory information */
  370. struct hal_mem_info {
  371. /* dev base virutal addr */
  372. void *dev_base_addr;
  373. /* dev base physical addr */
  374. void *dev_base_paddr;
  375. /* Remote virtual pointer memory for HW/FW updates */
  376. void *shadow_rdptr_mem_vaddr;
  377. /* Remote physical pointer memory for HW/FW updates */
  378. void *shadow_rdptr_mem_paddr;
  379. /* Shared memory for ring pointer updates from host to FW */
  380. void *shadow_wrptr_mem_vaddr;
  381. /* Shared physical memory for ring pointer updates from host to FW */
  382. void *shadow_wrptr_mem_paddr;
  383. };
  384. /* SRNG parameters to be passed to hal_srng_setup */
  385. struct hal_srng_params {
  386. /* Physical base address of the ring */
  387. qdf_dma_addr_t ring_base_paddr;
  388. /* Virtual base address of the ring */
  389. void *ring_base_vaddr;
  390. /* Number of entries in ring */
  391. uint32_t num_entries;
  392. /* max transfer length */
  393. uint16_t max_buffer_length;
  394. /* MSI Address */
  395. qdf_dma_addr_t msi_addr;
  396. /* MSI data */
  397. uint32_t msi_data;
  398. /* Interrupt timer threshold – in micro seconds */
  399. uint32_t intr_timer_thres_us;
  400. /* Interrupt batch counter threshold – in number of ring entries */
  401. uint32_t intr_batch_cntr_thres_entries;
  402. /* Low threshold – in number of ring entries
  403. * (valid for src rings only)
  404. */
  405. uint32_t low_threshold;
  406. /* Misc flags */
  407. uint32_t flags;
  408. /* Unique ring id */
  409. uint8_t ring_id;
  410. /* Source or Destination ring */
  411. enum hal_srng_dir ring_dir;
  412. /* Size of ring entry */
  413. uint32_t entry_size;
  414. /* hw register base address */
  415. void *hwreg_base[MAX_SRNG_REG_GROUPS];
  416. };
  417. /* hal_construct_shadow_config() - initialize the shadow registers for dp rings
  418. * @hal_soc: hal handle
  419. *
  420. * Return: QDF_STATUS_OK on success
  421. */
  422. extern QDF_STATUS hal_construct_shadow_config(void *hal_soc);
  423. /* hal_set_one_shadow_config() - add a config for the specified ring
  424. * @hal_soc: hal handle
  425. * @ring_type: ring type
  426. * @ring_num: ring num
  427. *
  428. * The ring type and ring num uniquely specify the ring. After this call,
  429. * the hp/tp will be added as the next entry int the shadow register
  430. * configuration table. The hal code will use the shadow register address
  431. * in place of the hp/tp address.
  432. *
  433. * This function is exposed, so that the CE module can skip configuring shadow
  434. * registers for unused ring and rings assigned to the firmware.
  435. *
  436. * Return: QDF_STATUS_OK on success
  437. */
  438. extern QDF_STATUS hal_set_one_shadow_config(void *hal_soc, int ring_type,
  439. int ring_num);
  440. /**
  441. * hal_get_shadow_config() - retrieve the config table
  442. * @hal_soc: hal handle
  443. * @shadow_config: will point to the table after
  444. * @num_shadow_registers_configured: will contain the number of valid entries
  445. */
  446. extern void hal_get_shadow_config(void *hal_soc,
  447. struct pld_shadow_reg_v2_cfg **shadow_config,
  448. int *num_shadow_registers_configured);
  449. /**
  450. * hal_srng_setup - Initialize HW SRNG ring.
  451. *
  452. * @hal_soc: Opaque HAL SOC handle
  453. * @ring_type: one of the types from hal_ring_type
  454. * @ring_num: Ring number if there are multiple rings of
  455. * same type (staring from 0)
  456. * @mac_id: valid MAC Id should be passed if ring type is one of lmac rings
  457. * @ring_params: SRNG ring params in hal_srng_params structure.
  458. * Callers are expected to allocate contiguous ring memory of size
  459. * 'num_entries * entry_size' bytes and pass the physical and virtual base
  460. * addresses through 'ring_base_paddr' and 'ring_base_vaddr' in hal_srng_params
  461. * structure. Ring base address should be 8 byte aligned and size of each ring
  462. * entry should be queried using the API hal_srng_get_entrysize
  463. *
  464. * Return: Opaque pointer to ring on success
  465. * NULL on failure (if given ring is not available)
  466. */
  467. extern void *hal_srng_setup(void *hal_soc, int ring_type, int ring_num,
  468. int mac_id, struct hal_srng_params *ring_params);
  469. /* Remapping ids of REO rings */
  470. #define REO_REMAP_TCL 0
  471. #define REO_REMAP_SW1 1
  472. #define REO_REMAP_SW2 2
  473. #define REO_REMAP_SW3 3
  474. #define REO_REMAP_SW4 4
  475. #define REO_REMAP_RELEASE 5
  476. #define REO_REMAP_FW 6
  477. #define REO_REMAP_UNUSED 7
  478. /*
  479. * currently this macro only works for IX0 since all the rings we are remapping
  480. * can be remapped from HWIO_REO_R0_DESTINATION_RING_CTRL_IX_0
  481. */
  482. #define HAL_REO_REMAP_VAL(_ORIGINAL_DEST, _NEW_DEST) \
  483. HAL_REO_REMAP_VAL_(_ORIGINAL_DEST, _NEW_DEST)
  484. /* allow the destination macros to be expanded */
  485. #define HAL_REO_REMAP_VAL_(_ORIGINAL_DEST, _NEW_DEST) \
  486. (_NEW_DEST << \
  487. (HWIO_REO_R0_DESTINATION_RING_CTRL_IX_0_DEST_RING_MAPPING_ ## \
  488. _ORIGINAL_DEST ## _SHFT))
  489. /**
  490. * hal_reo_read_write_ctrl_ix - Read or write REO_DESTINATION_RING_CTRL_IX
  491. * @hal_soc_hdl: HAL SOC handle
  492. * @read: boolean value to indicate if read or write
  493. * @ix0: pointer to store IX0 reg value
  494. * @ix1: pointer to store IX1 reg value
  495. * @ix2: pointer to store IX2 reg value
  496. * @ix3: pointer to store IX3 reg value
  497. */
  498. void hal_reo_read_write_ctrl_ix(hal_soc_handle_t hal_soc_hdl, bool read,
  499. uint32_t *ix0, uint32_t *ix1,
  500. uint32_t *ix2, uint32_t *ix3);
  501. /**
  502. * hal_srng_set_hp_paddr() - Set physical address to dest SRNG head pointer
  503. * @sring: sring pointer
  504. * @paddr: physical address
  505. */
  506. extern void hal_srng_dst_set_hp_paddr(struct hal_srng *sring, uint64_t paddr);
  507. /**
  508. * hal_srng_dst_init_hp() - Initilaize head pointer with cached head pointer
  509. * @srng: sring pointer
  510. * @vaddr: virtual address
  511. */
  512. extern void hal_srng_dst_init_hp(struct hal_srng *srng, uint32_t *vaddr);
  513. /**
  514. * hal_srng_cleanup - Deinitialize HW SRNG ring.
  515. * @hal_soc: Opaque HAL SOC handle
  516. * @hal_srng: Opaque HAL SRNG pointer
  517. */
  518. void hal_srng_cleanup(void *hal_soc, hal_ring_handle_t hal_ring_hdl);
  519. static inline bool hal_srng_initialized(hal_ring_handle_t hal_ring_hdl)
  520. {
  521. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  522. return !!srng->initialized;
  523. }
  524. /**
  525. * hal_srng_dst_peek - Check if there are any entries in the ring (peek)
  526. * @hal_soc: Opaque HAL SOC handle
  527. * @hal_ring_hdl: Destination ring pointer
  528. *
  529. * Caller takes responsibility for any locking needs.
  530. *
  531. * Return: Opaque pointer for next ring entry; NULL on failire
  532. */
  533. static inline
  534. void *hal_srng_dst_peek(hal_soc_handle_t hal_soc_hdl,
  535. hal_ring_handle_t hal_ring_hdl)
  536. {
  537. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  538. if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp)
  539. return (void *)(&srng->ring_base_vaddr[srng->u.dst_ring.tp]);
  540. return NULL;
  541. }
  542. /**
  543. * hal_srng_access_start_unlocked - Start ring access (unlocked). Should use
  544. * hal_srng_access_start if locked access is required
  545. *
  546. * @hal_soc: Opaque HAL SOC handle
  547. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  548. *
  549. * Return: 0 on success; error on failire
  550. */
  551. static inline int
  552. hal_srng_access_start_unlocked(hal_soc_handle_t hal_soc_hdl,
  553. hal_ring_handle_t hal_ring_hdl)
  554. {
  555. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  556. struct hal_soc *soc = (struct hal_soc *)hal_soc_hdl;
  557. uint32_t *desc;
  558. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  559. srng->u.src_ring.cached_tp =
  560. *(volatile uint32_t *)(srng->u.src_ring.tp_addr);
  561. else {
  562. srng->u.dst_ring.cached_hp =
  563. *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  564. if (srng->flags & HAL_SRNG_CACHED_DESC) {
  565. desc = hal_srng_dst_peek(hal_soc_hdl, hal_ring_hdl);
  566. if (qdf_likely(desc)) {
  567. qdf_mem_dma_cache_sync(soc->qdf_dev,
  568. qdf_mem_virt_to_phys
  569. (desc),
  570. QDF_DMA_FROM_DEVICE,
  571. (srng->entry_size *
  572. sizeof(uint32_t)));
  573. qdf_prefetch(desc);
  574. }
  575. }
  576. }
  577. return 0;
  578. }
  579. /**
  580. * hal_srng_access_start - Start (locked) ring access
  581. *
  582. * @hal_soc: Opaque HAL SOC handle
  583. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  584. *
  585. * Return: 0 on success; error on failire
  586. */
  587. static inline int hal_srng_access_start(hal_soc_handle_t hal_soc_hdl,
  588. hal_ring_handle_t hal_ring_hdl)
  589. {
  590. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  591. if (qdf_unlikely(!hal_ring_hdl)) {
  592. qdf_print("Error: Invalid hal_ring\n");
  593. return -EINVAL;
  594. }
  595. SRNG_LOCK(&(srng->lock));
  596. return hal_srng_access_start_unlocked(hal_soc_hdl, hal_ring_hdl);
  597. }
  598. /**
  599. * hal_srng_dst_get_next - Get next entry from a destination ring and move
  600. * cached tail pointer
  601. *
  602. * @hal_soc: Opaque HAL SOC handle
  603. * @hal_ring_hdl: Destination ring pointer
  604. *
  605. * Return: Opaque pointer for next ring entry; NULL on failire
  606. */
  607. static inline
  608. void *hal_srng_dst_get_next(void *hal_soc,
  609. hal_ring_handle_t hal_ring_hdl)
  610. {
  611. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  612. struct hal_soc *soc = (struct hal_soc *)hal_soc;
  613. uint32_t *desc;
  614. uint32_t *desc_next;
  615. uint32_t tp;
  616. if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp) {
  617. desc = &(srng->ring_base_vaddr[srng->u.dst_ring.tp]);
  618. /* TODO: Using % is expensive, but we have to do this since
  619. * size of some SRNG rings is not power of 2 (due to descriptor
  620. * sizes). Need to create separate API for rings used
  621. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  622. * SW2RXDMA and CE rings)
  623. */
  624. srng->u.dst_ring.tp = (srng->u.dst_ring.tp + srng->entry_size) %
  625. srng->ring_size;
  626. if (srng->flags & HAL_SRNG_CACHED_DESC) {
  627. tp = srng->u.dst_ring.tp;
  628. desc_next = &srng->ring_base_vaddr[tp];
  629. qdf_mem_dma_cache_sync(soc->qdf_dev,
  630. qdf_mem_virt_to_phys(desc_next),
  631. QDF_DMA_FROM_DEVICE,
  632. (srng->entry_size *
  633. sizeof(uint32_t)));
  634. qdf_prefetch(desc_next);
  635. }
  636. return (void *)desc;
  637. }
  638. return NULL;
  639. }
  640. /**
  641. * hal_srng_dst_get_next_hp - Get next entry from a destination ring and move
  642. * cached head pointer
  643. *
  644. * @hal_soc: Opaque HAL SOC handle
  645. * @hal_ring_hdl: Destination ring pointer
  646. *
  647. * Return: Opaque pointer for next ring entry; NULL on failire
  648. */
  649. static inline void *
  650. hal_srng_dst_get_next_hp(hal_soc_handle_t hal_soc_hdl,
  651. hal_ring_handle_t hal_ring_hdl)
  652. {
  653. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  654. uint32_t *desc;
  655. /* TODO: Using % is expensive, but we have to do this since
  656. * size of some SRNG rings is not power of 2 (due to descriptor
  657. * sizes). Need to create separate API for rings used
  658. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  659. * SW2RXDMA and CE rings)
  660. */
  661. uint32_t next_hp = (srng->u.dst_ring.cached_hp + srng->entry_size) %
  662. srng->ring_size;
  663. if (next_hp != srng->u.dst_ring.tp) {
  664. desc = &(srng->ring_base_vaddr[srng->u.dst_ring.cached_hp]);
  665. srng->u.dst_ring.cached_hp = next_hp;
  666. return (void *)desc;
  667. }
  668. return NULL;
  669. }
  670. /**
  671. * hal_srng_dst_peek_sync - Check if there are any entries in the ring (peek)
  672. * @hal_soc: Opaque HAL SOC handle
  673. * @hal_ring_hdl: Destination ring pointer
  674. *
  675. * Sync cached head pointer with HW.
  676. * Caller takes responsibility for any locking needs.
  677. *
  678. * Return: Opaque pointer for next ring entry; NULL on failire
  679. */
  680. static inline
  681. void *hal_srng_dst_peek_sync(hal_soc_handle_t hal_soc_hdl,
  682. hal_ring_handle_t hal_ring_hdl)
  683. {
  684. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  685. srng->u.dst_ring.cached_hp =
  686. *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  687. if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp)
  688. return (void *)(&(srng->ring_base_vaddr[srng->u.dst_ring.tp]));
  689. return NULL;
  690. }
  691. /**
  692. * hal_srng_dst_peek_sync_locked - Peek for any entries in the ring
  693. * @hal_soc: Opaque HAL SOC handle
  694. * @hal_ring_hdl: Destination ring pointer
  695. *
  696. * Sync cached head pointer with HW.
  697. * This function takes up SRNG_LOCK. Should not be called with SRNG lock held.
  698. *
  699. * Return: Opaque pointer for next ring entry; NULL on failire
  700. */
  701. static inline
  702. void *hal_srng_dst_peek_sync_locked(hal_soc_handle_t hal_soc_hdl,
  703. hal_ring_handle_t hal_ring_hdl)
  704. {
  705. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  706. void *ring_desc_ptr = NULL;
  707. if (qdf_unlikely(!hal_ring_hdl)) {
  708. qdf_print("Error: Invalid hal_ring\n");
  709. return NULL;
  710. }
  711. SRNG_LOCK(&srng->lock);
  712. ring_desc_ptr = hal_srng_dst_peek_sync(hal_soc_hdl, hal_ring_hdl);
  713. SRNG_UNLOCK(&srng->lock);
  714. return ring_desc_ptr;
  715. }
  716. /**
  717. * hal_srng_dst_num_valid - Returns number of valid entries (to be processed
  718. * by SW) in destination ring
  719. *
  720. * @hal_soc: Opaque HAL SOC handle
  721. * @hal_ring_hdl: Destination ring pointer
  722. * @sync_hw_ptr: Sync cached head pointer with HW
  723. *
  724. */
  725. static inline
  726. uint32_t hal_srng_dst_num_valid(void *hal_soc,
  727. hal_ring_handle_t hal_ring_hdl,
  728. int sync_hw_ptr)
  729. {
  730. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  731. uint32_t hp;
  732. uint32_t tp = srng->u.dst_ring.tp;
  733. if (sync_hw_ptr) {
  734. hp = *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  735. srng->u.dst_ring.cached_hp = hp;
  736. } else {
  737. hp = srng->u.dst_ring.cached_hp;
  738. }
  739. if (hp >= tp)
  740. return (hp - tp) / srng->entry_size;
  741. else
  742. return (srng->ring_size - tp + hp) / srng->entry_size;
  743. }
  744. /**
  745. * hal_srng_dst_num_valid_locked - Returns num valid entries to be processed
  746. *
  747. * @hal_soc: Opaque HAL SOC handle
  748. * @hal_ring_hdl: Destination ring pointer
  749. * @sync_hw_ptr: Sync cached head pointer with HW
  750. *
  751. * Returns number of valid entries to be processed by the host driver. The
  752. * function takes up SRNG lock.
  753. *
  754. * Return: Number of valid destination entries
  755. */
  756. static inline uint32_t
  757. hal_srng_dst_num_valid_locked(hal_soc_handle_t hal_soc,
  758. hal_ring_handle_t hal_ring_hdl,
  759. int sync_hw_ptr)
  760. {
  761. uint32_t num_valid;
  762. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  763. SRNG_LOCK(&srng->lock);
  764. num_valid = hal_srng_dst_num_valid(hal_soc, hal_ring_hdl, sync_hw_ptr);
  765. SRNG_UNLOCK(&srng->lock);
  766. return num_valid;
  767. }
  768. /**
  769. * hal_srng_src_reap_next - Reap next entry from a source ring and move reap
  770. * pointer. This can be used to release any buffers associated with completed
  771. * ring entries. Note that this should not be used for posting new descriptor
  772. * entries. Posting of new entries should be done only using
  773. * hal_srng_src_get_next_reaped when this function is used for reaping.
  774. *
  775. * @hal_soc: Opaque HAL SOC handle
  776. * @hal_ring_hdl: Source ring pointer
  777. *
  778. * Return: Opaque pointer for next ring entry; NULL on failire
  779. */
  780. static inline void *
  781. hal_srng_src_reap_next(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  782. {
  783. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  784. uint32_t *desc;
  785. /* TODO: Using % is expensive, but we have to do this since
  786. * size of some SRNG rings is not power of 2 (due to descriptor
  787. * sizes). Need to create separate API for rings used
  788. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  789. * SW2RXDMA and CE rings)
  790. */
  791. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  792. srng->ring_size;
  793. if (next_reap_hp != srng->u.src_ring.cached_tp) {
  794. desc = &(srng->ring_base_vaddr[next_reap_hp]);
  795. srng->u.src_ring.reap_hp = next_reap_hp;
  796. return (void *)desc;
  797. }
  798. return NULL;
  799. }
  800. /**
  801. * hal_srng_src_get_next_reaped - Get next entry from a source ring that is
  802. * already reaped using hal_srng_src_reap_next, for posting new entries to
  803. * the ring
  804. *
  805. * @hal_soc: Opaque HAL SOC handle
  806. * @hal_ring_hdl: Source ring pointer
  807. *
  808. * Return: Opaque pointer for next (reaped) source ring entry; NULL on failire
  809. */
  810. static inline void *
  811. hal_srng_src_get_next_reaped(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  812. {
  813. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  814. uint32_t *desc;
  815. if (srng->u.src_ring.hp != srng->u.src_ring.reap_hp) {
  816. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  817. srng->u.src_ring.hp = (srng->u.src_ring.hp + srng->entry_size) %
  818. srng->ring_size;
  819. return (void *)desc;
  820. }
  821. return NULL;
  822. }
  823. /**
  824. * hal_srng_src_pending_reap_next - Reap next entry from a source ring and
  825. * move reap pointer. This API is used in detach path to release any buffers
  826. * associated with ring entries which are pending reap.
  827. *
  828. * @hal_soc: Opaque HAL SOC handle
  829. * @hal_ring_hdl: Source ring pointer
  830. *
  831. * Return: Opaque pointer for next ring entry; NULL on failire
  832. */
  833. static inline void *
  834. hal_srng_src_pending_reap_next(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  835. {
  836. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  837. uint32_t *desc;
  838. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  839. srng->ring_size;
  840. if (next_reap_hp != srng->u.src_ring.hp) {
  841. desc = &(srng->ring_base_vaddr[next_reap_hp]);
  842. srng->u.src_ring.reap_hp = next_reap_hp;
  843. return (void *)desc;
  844. }
  845. return NULL;
  846. }
  847. /**
  848. * hal_srng_src_done_val -
  849. *
  850. * @hal_soc: Opaque HAL SOC handle
  851. * @hal_ring_hdl: Source ring pointer
  852. *
  853. * Return: Opaque pointer for next ring entry; NULL on failire
  854. */
  855. static inline uint32_t
  856. hal_srng_src_done_val(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  857. {
  858. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  859. /* TODO: Using % is expensive, but we have to do this since
  860. * size of some SRNG rings is not power of 2 (due to descriptor
  861. * sizes). Need to create separate API for rings used
  862. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  863. * SW2RXDMA and CE rings)
  864. */
  865. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  866. srng->ring_size;
  867. if (next_reap_hp == srng->u.src_ring.cached_tp)
  868. return 0;
  869. if (srng->u.src_ring.cached_tp > next_reap_hp)
  870. return (srng->u.src_ring.cached_tp - next_reap_hp) /
  871. srng->entry_size;
  872. else
  873. return ((srng->ring_size - next_reap_hp) +
  874. srng->u.src_ring.cached_tp) / srng->entry_size;
  875. }
  876. /**
  877. * hal_get_entrysize_from_srng() - Retrieve ring entry size
  878. * @hal_ring_hdl: Source ring pointer
  879. *
  880. * Return: uint8_t
  881. */
  882. static inline
  883. uint8_t hal_get_entrysize_from_srng(hal_ring_handle_t hal_ring_hdl)
  884. {
  885. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  886. return srng->entry_size;
  887. }
  888. /**
  889. * hal_get_sw_hptp - Get SW head and tail pointer location for any ring
  890. * @hal_soc: Opaque HAL SOC handle
  891. * @hal_ring_hdl: Source ring pointer
  892. * @tailp: Tail Pointer
  893. * @headp: Head Pointer
  894. *
  895. * Return: Update tail pointer and head pointer in arguments.
  896. */
  897. static inline
  898. void hal_get_sw_hptp(void *hal_soc, hal_ring_handle_t hal_ring_hdl,
  899. uint32_t *tailp, uint32_t *headp)
  900. {
  901. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  902. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  903. *headp = srng->u.src_ring.hp;
  904. *tailp = *srng->u.src_ring.tp_addr;
  905. } else {
  906. *tailp = srng->u.dst_ring.tp;
  907. *headp = *srng->u.dst_ring.hp_addr;
  908. }
  909. }
  910. /**
  911. * hal_srng_src_get_next - Get next entry from a source ring and move cached tail pointer
  912. *
  913. * @hal_soc: Opaque HAL SOC handle
  914. * @hal_ring_hdl: Source ring pointer
  915. *
  916. * Return: Opaque pointer for next ring entry; NULL on failire
  917. */
  918. static inline
  919. void *hal_srng_src_get_next(void *hal_soc,
  920. hal_ring_handle_t hal_ring_hdl)
  921. {
  922. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  923. uint32_t *desc;
  924. /* TODO: Using % is expensive, but we have to do this since
  925. * size of some SRNG rings is not power of 2 (due to descriptor
  926. * sizes). Need to create separate API for rings used
  927. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  928. * SW2RXDMA and CE rings)
  929. */
  930. uint32_t next_hp = (srng->u.src_ring.hp + srng->entry_size) %
  931. srng->ring_size;
  932. if (next_hp != srng->u.src_ring.cached_tp) {
  933. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  934. srng->u.src_ring.hp = next_hp;
  935. /* TODO: Since reap function is not used by all rings, we can
  936. * remove the following update of reap_hp in this function
  937. * if we can ensure that only hal_srng_src_get_next_reaped
  938. * is used for the rings requiring reap functionality
  939. */
  940. srng->u.src_ring.reap_hp = next_hp;
  941. return (void *)desc;
  942. }
  943. return NULL;
  944. }
  945. /**
  946. * hal_srng_src_peek - Get next entry from a ring without moving head pointer.
  947. * hal_srng_src_get_next should be called subsequently to move the head pointer
  948. *
  949. * @hal_soc: Opaque HAL SOC handle
  950. * @hal_ring_hdl: Source ring pointer
  951. *
  952. * Return: Opaque pointer for next ring entry; NULL on failire
  953. */
  954. static inline
  955. void *hal_srng_src_peek(hal_soc_handle_t hal_soc_hdl,
  956. hal_ring_handle_t hal_ring_hdl)
  957. {
  958. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  959. uint32_t *desc;
  960. /* TODO: Using % is expensive, but we have to do this since
  961. * size of some SRNG rings is not power of 2 (due to descriptor
  962. * sizes). Need to create separate API for rings used
  963. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  964. * SW2RXDMA and CE rings)
  965. */
  966. if (((srng->u.src_ring.hp + srng->entry_size) %
  967. srng->ring_size) != srng->u.src_ring.cached_tp) {
  968. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  969. return (void *)desc;
  970. }
  971. return NULL;
  972. }
  973. /**
  974. * hal_srng_src_num_avail - Returns number of available entries in src ring
  975. *
  976. * @hal_soc: Opaque HAL SOC handle
  977. * @hal_ring_hdl: Source ring pointer
  978. * @sync_hw_ptr: Sync cached tail pointer with HW
  979. *
  980. */
  981. static inline uint32_t
  982. hal_srng_src_num_avail(void *hal_soc,
  983. hal_ring_handle_t hal_ring_hdl, int sync_hw_ptr)
  984. {
  985. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  986. uint32_t tp;
  987. uint32_t hp = srng->u.src_ring.hp;
  988. if (sync_hw_ptr) {
  989. tp = *(srng->u.src_ring.tp_addr);
  990. srng->u.src_ring.cached_tp = tp;
  991. } else {
  992. tp = srng->u.src_ring.cached_tp;
  993. }
  994. if (tp > hp)
  995. return ((tp - hp) / srng->entry_size) - 1;
  996. else
  997. return ((srng->ring_size - hp + tp) / srng->entry_size) - 1;
  998. }
  999. /**
  1000. * hal_srng_access_end_unlocked - End ring access (unlocked) - update cached
  1001. * ring head/tail pointers to HW.
  1002. * This should be used only if hal_srng_access_start_unlocked to start ring
  1003. * access
  1004. *
  1005. * @hal_soc: Opaque HAL SOC handle
  1006. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1007. *
  1008. * Return: 0 on success; error on failire
  1009. */
  1010. static inline void
  1011. hal_srng_access_end_unlocked(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1012. {
  1013. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1014. /* TODO: See if we need a write memory barrier here */
  1015. if (srng->flags & HAL_SRNG_LMAC_RING) {
  1016. /* For LMAC rings, ring pointer updates are done through FW and
  1017. * hence written to a shared memory location that is read by FW
  1018. */
  1019. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1020. *(srng->u.src_ring.hp_addr) = srng->u.src_ring.hp;
  1021. } else {
  1022. *(srng->u.dst_ring.tp_addr) = srng->u.dst_ring.tp;
  1023. }
  1024. } else {
  1025. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  1026. hal_write_address_32_mb(hal_soc,
  1027. srng->u.src_ring.hp_addr,
  1028. srng->u.src_ring.hp);
  1029. else
  1030. hal_write_address_32_mb(hal_soc,
  1031. srng->u.dst_ring.tp_addr,
  1032. srng->u.dst_ring.tp);
  1033. }
  1034. }
  1035. /**
  1036. * hal_srng_access_end - Unlock ring access and update cached ring head/tail
  1037. * pointers to HW
  1038. * This should be used only if hal_srng_access_start to start ring access
  1039. *
  1040. * @hal_soc: Opaque HAL SOC handle
  1041. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1042. *
  1043. * Return: 0 on success; error on failire
  1044. */
  1045. static inline void
  1046. hal_srng_access_end(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1047. {
  1048. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1049. if (qdf_unlikely(!hal_ring_hdl)) {
  1050. qdf_print("Error: Invalid hal_ring\n");
  1051. return;
  1052. }
  1053. hal_srng_access_end_unlocked(hal_soc, hal_ring_hdl);
  1054. SRNG_UNLOCK(&(srng->lock));
  1055. }
  1056. /**
  1057. * hal_srng_access_end_reap - Unlock ring access
  1058. * This should be used only if hal_srng_access_start to start ring access
  1059. * and should be used only while reaping SRC ring completions
  1060. *
  1061. * @hal_soc: Opaque HAL SOC handle
  1062. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1063. *
  1064. * Return: 0 on success; error on failire
  1065. */
  1066. static inline void
  1067. hal_srng_access_end_reap(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1068. {
  1069. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1070. SRNG_UNLOCK(&(srng->lock));
  1071. }
  1072. /* TODO: Check if the following definitions is available in HW headers */
  1073. #define WBM_IDLE_SCATTER_BUF_SIZE 32704
  1074. #define NUM_MPDUS_PER_LINK_DESC 6
  1075. #define NUM_MSDUS_PER_LINK_DESC 7
  1076. #define REO_QUEUE_DESC_ALIGN 128
  1077. #define LINK_DESC_ALIGN 128
  1078. #define ADDRESS_MATCH_TAG_VAL 0x5
  1079. /* Number of mpdu link pointers is 9 in case of TX_MPDU_QUEUE_HEAD and 14 in
  1080. * of TX_MPDU_QUEUE_EXT. We are defining a common average count here
  1081. */
  1082. #define NUM_MPDU_LINKS_PER_QUEUE_DESC 12
  1083. /* TODO: Check with HW team on the scatter buffer size supported. As per WBM
  1084. * MLD, scatter_buffer_size in IDLE_LIST_CONTROL register is 9 bits and size
  1085. * should be specified in 16 word units. But the number of bits defined for
  1086. * this field in HW header files is 5.
  1087. */
  1088. #define WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE 8
  1089. /**
  1090. * hal_idle_list_scatter_buf_size - Get the size of each scatter buffer
  1091. * in an idle list
  1092. *
  1093. * @hal_soc: Opaque HAL SOC handle
  1094. *
  1095. */
  1096. static inline
  1097. uint32_t hal_idle_list_scatter_buf_size(hal_soc_handle_t hal_soc_hdl)
  1098. {
  1099. return WBM_IDLE_SCATTER_BUF_SIZE;
  1100. }
  1101. /**
  1102. * hal_get_link_desc_size - Get the size of each link descriptor
  1103. *
  1104. * @hal_soc: Opaque HAL SOC handle
  1105. *
  1106. */
  1107. static inline uint32_t hal_get_link_desc_size(hal_soc_handle_t hal_soc_hdl)
  1108. {
  1109. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  1110. if (!hal_soc || !hal_soc->ops) {
  1111. qdf_print("Error: Invalid ops\n");
  1112. QDF_BUG(0);
  1113. return -EINVAL;
  1114. }
  1115. if (!hal_soc->ops->hal_get_link_desc_size) {
  1116. qdf_print("Error: Invalid function pointer\n");
  1117. QDF_BUG(0);
  1118. return -EINVAL;
  1119. }
  1120. return hal_soc->ops->hal_get_link_desc_size();
  1121. }
  1122. /**
  1123. * hal_get_link_desc_align - Get the required start address alignment for
  1124. * link descriptors
  1125. *
  1126. * @hal_soc: Opaque HAL SOC handle
  1127. *
  1128. */
  1129. static inline
  1130. uint32_t hal_get_link_desc_align(hal_soc_handle_t hal_soc_hdl)
  1131. {
  1132. return LINK_DESC_ALIGN;
  1133. }
  1134. /**
  1135. * hal_num_mpdus_per_link_desc - Get number of mpdus each link desc can hold
  1136. *
  1137. * @hal_soc: Opaque HAL SOC handle
  1138. *
  1139. */
  1140. static inline
  1141. uint32_t hal_num_mpdus_per_link_desc(hal_soc_handle_t hal_soc_hdl)
  1142. {
  1143. return NUM_MPDUS_PER_LINK_DESC;
  1144. }
  1145. /**
  1146. * hal_num_msdus_per_link_desc - Get number of msdus each link desc can hold
  1147. *
  1148. * @hal_soc: Opaque HAL SOC handle
  1149. *
  1150. */
  1151. static inline
  1152. uint32_t hal_num_msdus_per_link_desc(hal_soc_handle_t hal_soc_hdl)
  1153. {
  1154. return NUM_MSDUS_PER_LINK_DESC;
  1155. }
  1156. /**
  1157. * hal_num_mpdu_links_per_queue_desc - Get number of mpdu links each queue
  1158. * descriptor can hold
  1159. *
  1160. * @hal_soc: Opaque HAL SOC handle
  1161. *
  1162. */
  1163. static inline
  1164. uint32_t hal_num_mpdu_links_per_queue_desc(hal_soc_handle_t hal_soc_hdl)
  1165. {
  1166. return NUM_MPDU_LINKS_PER_QUEUE_DESC;
  1167. }
  1168. /**
  1169. * hal_idle_list_scatter_buf_num_entries - Get the number of link desc entries
  1170. * that the given buffer size
  1171. *
  1172. * @hal_soc: Opaque HAL SOC handle
  1173. * @scatter_buf_size: Size of scatter buffer
  1174. *
  1175. */
  1176. static inline
  1177. uint32_t hal_idle_scatter_buf_num_entries(hal_soc_handle_t hal_soc_hdl,
  1178. uint32_t scatter_buf_size)
  1179. {
  1180. return (scatter_buf_size - WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE) /
  1181. hal_srng_get_entrysize(hal_soc_hdl, WBM_IDLE_LINK);
  1182. }
  1183. /**
  1184. * hal_idle_list_num_scatter_bufs - Get the number of sctater buffer
  1185. * each given buffer size
  1186. *
  1187. * @hal_soc: Opaque HAL SOC handle
  1188. * @total_mem: size of memory to be scattered
  1189. * @scatter_buf_size: Size of scatter buffer
  1190. *
  1191. */
  1192. static inline
  1193. uint32_t hal_idle_list_num_scatter_bufs(hal_soc_handle_t hal_soc_hdl,
  1194. uint32_t total_mem,
  1195. uint32_t scatter_buf_size)
  1196. {
  1197. uint8_t rem = (total_mem % (scatter_buf_size -
  1198. WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE)) ? 1 : 0;
  1199. uint32_t num_scatter_bufs = (total_mem / (scatter_buf_size -
  1200. WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE)) + rem;
  1201. return num_scatter_bufs;
  1202. }
  1203. enum hal_pn_type {
  1204. HAL_PN_NONE,
  1205. HAL_PN_WPA,
  1206. HAL_PN_WAPI_EVEN,
  1207. HAL_PN_WAPI_UNEVEN,
  1208. };
  1209. #define HAL_RX_MAX_BA_WINDOW 256
  1210. /**
  1211. * hal_get_reo_qdesc_align - Get start address alignment for reo
  1212. * queue descriptors
  1213. *
  1214. * @hal_soc: Opaque HAL SOC handle
  1215. *
  1216. */
  1217. static inline
  1218. uint32_t hal_get_reo_qdesc_align(hal_soc_handle_t hal_soc_hdl)
  1219. {
  1220. return REO_QUEUE_DESC_ALIGN;
  1221. }
  1222. /**
  1223. * hal_reo_qdesc_setup - Setup HW REO queue descriptor
  1224. *
  1225. * @hal_soc: Opaque HAL SOC handle
  1226. * @ba_window_size: BlockAck window size
  1227. * @start_seq: Starting sequence number
  1228. * @hw_qdesc_vaddr: Virtual address of REO queue descriptor memory
  1229. * @hw_qdesc_paddr: Physical address of REO queue descriptor memory
  1230. * @pn_type: PN type (one of the types defined in 'enum hal_pn_type')
  1231. *
  1232. */
  1233. void hal_reo_qdesc_setup(hal_soc_handle_t hal_soc_hdl,
  1234. int tid, uint32_t ba_window_size,
  1235. uint32_t start_seq, void *hw_qdesc_vaddr,
  1236. qdf_dma_addr_t hw_qdesc_paddr,
  1237. int pn_type);
  1238. /**
  1239. * hal_srng_get_hp_addr - Get head pointer physical address
  1240. *
  1241. * @hal_soc: Opaque HAL SOC handle
  1242. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1243. *
  1244. */
  1245. static inline qdf_dma_addr_t
  1246. hal_srng_get_hp_addr(void *hal_soc,
  1247. hal_ring_handle_t hal_ring_hdl)
  1248. {
  1249. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1250. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  1251. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1252. return hal->shadow_wrptr_mem_paddr +
  1253. ((unsigned long)(srng->u.src_ring.hp_addr) -
  1254. (unsigned long)(hal->shadow_wrptr_mem_vaddr));
  1255. } else {
  1256. return hal->shadow_rdptr_mem_paddr +
  1257. ((unsigned long)(srng->u.dst_ring.hp_addr) -
  1258. (unsigned long)(hal->shadow_rdptr_mem_vaddr));
  1259. }
  1260. }
  1261. /**
  1262. * hal_srng_get_tp_addr - Get tail pointer physical address
  1263. *
  1264. * @hal_soc: Opaque HAL SOC handle
  1265. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1266. *
  1267. */
  1268. static inline qdf_dma_addr_t
  1269. hal_srng_get_tp_addr(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1270. {
  1271. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1272. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  1273. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1274. return hal->shadow_rdptr_mem_paddr +
  1275. ((unsigned long)(srng->u.src_ring.tp_addr) -
  1276. (unsigned long)(hal->shadow_rdptr_mem_vaddr));
  1277. } else {
  1278. return hal->shadow_wrptr_mem_paddr +
  1279. ((unsigned long)(srng->u.dst_ring.tp_addr) -
  1280. (unsigned long)(hal->shadow_wrptr_mem_vaddr));
  1281. }
  1282. }
  1283. /**
  1284. * hal_srng_get_num_entries - Get total entries in the HAL Srng
  1285. *
  1286. * @hal_soc: Opaque HAL SOC handle
  1287. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1288. *
  1289. * Return: total number of entries in hal ring
  1290. */
  1291. static inline
  1292. uint32_t hal_srng_get_num_entries(hal_soc_handle_t hal_soc_hdl,
  1293. hal_ring_handle_t hal_ring_hdl)
  1294. {
  1295. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1296. return srng->num_entries;
  1297. }
  1298. /**
  1299. * hal_get_srng_params - Retrieve SRNG parameters for a given ring from HAL
  1300. *
  1301. * @hal_soc: Opaque HAL SOC handle
  1302. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1303. * @ring_params: SRNG parameters will be returned through this structure
  1304. */
  1305. void hal_get_srng_params(hal_soc_handle_t hal_soc_hdl,
  1306. hal_ring_handle_t hal_ring_hdl,
  1307. struct hal_srng_params *ring_params);
  1308. /**
  1309. * hal_mem_info - Retrieve hal memory base address
  1310. *
  1311. * @hal_soc: Opaque HAL SOC handle
  1312. * @mem: pointer to structure to be updated with hal mem info
  1313. */
  1314. void hal_get_meminfo(hal_soc_handle_t hal_soc_hdl, struct hal_mem_info *mem);
  1315. /**
  1316. * hal_get_target_type - Return target type
  1317. *
  1318. * @hal_soc: Opaque HAL SOC handle
  1319. */
  1320. uint32_t hal_get_target_type(hal_soc_handle_t hal_soc_hdl);
  1321. /**
  1322. * hal_get_ba_aging_timeout - Retrieve BA aging timeout
  1323. *
  1324. * @hal_soc: Opaque HAL SOC handle
  1325. * @ac: Access category
  1326. * @value: timeout duration in millisec
  1327. */
  1328. void hal_get_ba_aging_timeout(hal_soc_handle_t hal_soc_hdl, uint8_t ac,
  1329. uint32_t *value);
  1330. /**
  1331. * hal_set_aging_timeout - Set BA aging timeout
  1332. *
  1333. * @hal_soc: Opaque HAL SOC handle
  1334. * @ac: Access category in millisec
  1335. * @value: timeout duration value
  1336. */
  1337. void hal_set_ba_aging_timeout(hal_soc_handle_t hal_soc_hdl, uint8_t ac,
  1338. uint32_t value);
  1339. /**
  1340. * hal_srng_dst_hw_init - Private function to initialize SRNG
  1341. * destination ring HW
  1342. * @hal_soc: HAL SOC handle
  1343. * @srng: SRNG ring pointer
  1344. */
  1345. static inline void hal_srng_dst_hw_init(struct hal_soc *hal,
  1346. struct hal_srng *srng)
  1347. {
  1348. hal->ops->hal_srng_dst_hw_init(hal, srng);
  1349. }
  1350. /**
  1351. * hal_srng_src_hw_init - Private function to initialize SRNG
  1352. * source ring HW
  1353. * @hal_soc: HAL SOC handle
  1354. * @srng: SRNG ring pointer
  1355. */
  1356. static inline void hal_srng_src_hw_init(struct hal_soc *hal,
  1357. struct hal_srng *srng)
  1358. {
  1359. hal->ops->hal_srng_src_hw_init(hal, srng);
  1360. }
  1361. /**
  1362. * hal_get_hw_hptp() - Get HW head and tail pointer value for any ring
  1363. * @hal_soc: Opaque HAL SOC handle
  1364. * @hal_ring_hdl: Source ring pointer
  1365. * @headp: Head Pointer
  1366. * @tailp: Tail Pointer
  1367. * @ring_type: Ring
  1368. *
  1369. * Return: Update tail pointer and head pointer in arguments.
  1370. */
  1371. static inline
  1372. void hal_get_hw_hptp(hal_soc_handle_t hal_soc_hdl,
  1373. hal_ring_handle_t hal_ring_hdl,
  1374. uint32_t *headp, uint32_t *tailp,
  1375. uint8_t ring_type)
  1376. {
  1377. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  1378. hal_soc->ops->hal_get_hw_hptp(hal_soc, hal_ring_hdl,
  1379. headp, tailp, ring_type);
  1380. }
  1381. /**
  1382. * hal_reo_setup - Initialize HW REO block
  1383. *
  1384. * @hal_soc: Opaque HAL SOC handle
  1385. * @reo_params: parameters needed by HAL for REO config
  1386. */
  1387. static inline void hal_reo_setup(hal_soc_handle_t hal_soc_hdl,
  1388. void *reoparams)
  1389. {
  1390. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  1391. hal_soc->ops->hal_reo_setup(hal_soc, reoparams);
  1392. }
  1393. /**
  1394. * hal_setup_link_idle_list - Setup scattered idle list using the
  1395. * buffer list provided
  1396. *
  1397. * @hal_soc: Opaque HAL SOC handle
  1398. * @scatter_bufs_base_paddr: Array of physical base addresses
  1399. * @scatter_bufs_base_vaddr: Array of virtual base addresses
  1400. * @num_scatter_bufs: Number of scatter buffers in the above lists
  1401. * @scatter_buf_size: Size of each scatter buffer
  1402. * @last_buf_end_offset: Offset to the last entry
  1403. * @num_entries: Total entries of all scatter bufs
  1404. *
  1405. */
  1406. static inline
  1407. void hal_setup_link_idle_list(hal_soc_handle_t hal_soc_hdl,
  1408. qdf_dma_addr_t scatter_bufs_base_paddr[],
  1409. void *scatter_bufs_base_vaddr[],
  1410. uint32_t num_scatter_bufs,
  1411. uint32_t scatter_buf_size,
  1412. uint32_t last_buf_end_offset,
  1413. uint32_t num_entries)
  1414. {
  1415. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  1416. hal_soc->ops->hal_setup_link_idle_list(hal_soc, scatter_bufs_base_paddr,
  1417. scatter_bufs_base_vaddr, num_scatter_bufs,
  1418. scatter_buf_size, last_buf_end_offset,
  1419. num_entries);
  1420. }
  1421. /**
  1422. * hal_srng_dump_ring_desc() - Dump ring descriptor info
  1423. *
  1424. * @hal_soc: Opaque HAL SOC handle
  1425. * @hal_ring_hdl: Source ring pointer
  1426. * @ring_desc: Opaque ring descriptor handle
  1427. */
  1428. static inline void hal_srng_dump_ring_desc(hal_soc_handle_t hal_soc_hdl,
  1429. hal_ring_handle_t hal_ring_hdl,
  1430. hal_ring_desc_t ring_desc)
  1431. {
  1432. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1433. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_HIGH,
  1434. ring_desc, (srng->entry_size << 2));
  1435. }
  1436. /**
  1437. * hal_srng_dump_ring() - Dump last 128 descs of the ring
  1438. *
  1439. * @hal_soc: Opaque HAL SOC handle
  1440. * @hal_ring_hdl: Source ring pointer
  1441. */
  1442. static inline void hal_srng_dump_ring(hal_soc_handle_t hal_soc_hdl,
  1443. hal_ring_handle_t hal_ring_hdl)
  1444. {
  1445. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1446. uint32_t *desc;
  1447. uint32_t tp, i;
  1448. tp = srng->u.dst_ring.tp;
  1449. for (i = 0; i < 128; i++) {
  1450. if (!tp)
  1451. tp = srng->ring_size;
  1452. desc = &srng->ring_base_vaddr[tp - srng->entry_size];
  1453. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_DP,
  1454. QDF_TRACE_LEVEL_DEBUG,
  1455. desc, (srng->entry_size << 2));
  1456. tp -= srng->entry_size;
  1457. }
  1458. }
  1459. /*
  1460. * hal_rxdma_desc_to_hal_ring_desc - API to convert rxdma ring desc
  1461. * to opaque dp_ring desc type
  1462. * @ring_desc - rxdma ring desc
  1463. *
  1464. * Return: hal_rxdma_desc_t type
  1465. */
  1466. static inline
  1467. hal_ring_desc_t hal_rxdma_desc_to_hal_ring_desc(hal_rxdma_desc_t ring_desc)
  1468. {
  1469. return (hal_ring_desc_t)ring_desc;
  1470. }
  1471. /**
  1472. * hal_srng_set_event() - Set hal_srng event
  1473. * @hal_ring_hdl: Source ring pointer
  1474. * @event: SRNG ring event
  1475. *
  1476. * Return: None
  1477. */
  1478. static inline void hal_srng_set_event(hal_ring_handle_t hal_ring_hdl, int event)
  1479. {
  1480. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1481. qdf_atomic_set_bit(event, &srng->srng_event);
  1482. }
  1483. /**
  1484. * hal_srng_clear_event() - Clear hal_srng event
  1485. * @hal_ring_hdl: Source ring pointer
  1486. * @event: SRNG ring event
  1487. *
  1488. * Return: None
  1489. */
  1490. static inline
  1491. void hal_srng_clear_event(hal_ring_handle_t hal_ring_hdl, int event)
  1492. {
  1493. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1494. qdf_atomic_clear_bit(event, &srng->srng_event);
  1495. }
  1496. /**
  1497. * hal_srng_get_clear_event() - Clear srng event and return old value
  1498. * @hal_ring_hdl: Source ring pointer
  1499. * @event: SRNG ring event
  1500. *
  1501. * Return: Return old event value
  1502. */
  1503. static inline
  1504. int hal_srng_get_clear_event(hal_ring_handle_t hal_ring_hdl, int event)
  1505. {
  1506. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1507. return qdf_atomic_test_and_clear_bit(event, &srng->srng_event);
  1508. }
  1509. /**
  1510. * hal_srng_set_flush_last_ts() - Record last flush time stamp
  1511. * @hal_ring_hdl: Source ring pointer
  1512. *
  1513. * Return: None
  1514. */
  1515. static inline void hal_srng_set_flush_last_ts(hal_ring_handle_t hal_ring_hdl)
  1516. {
  1517. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1518. srng->last_flush_ts = qdf_get_log_timestamp();
  1519. }
  1520. /**
  1521. * hal_srng_inc_flush_cnt() - Increment flush counter
  1522. * @hal_ring_hdl: Source ring pointer
  1523. *
  1524. * Return: None
  1525. */
  1526. static inline void hal_srng_inc_flush_cnt(hal_ring_handle_t hal_ring_hdl)
  1527. {
  1528. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1529. srng->flush_count++;
  1530. }
  1531. #endif /* _HAL_APIH_ */