hal_api.h 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739
  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. * Macro to access HWIO_REO_R0_DESTINATION_RING_CTRL_IX_0
  480. * to map destination to rings
  481. */
  482. #define HAL_REO_REMAP_IX0(_VALUE, _OFFSET) \
  483. ((_VALUE) << \
  484. (HWIO_REO_R0_DESTINATION_RING_CTRL_IX_0_DEST_RING_MAPPING_ ## \
  485. _OFFSET ## _SHFT))
  486. /*
  487. * Macro to access HWIO_REO_R0_DESTINATION_RING_CTRL_IX_1
  488. * to map destination to rings
  489. */
  490. #define HAL_REO_REMAP_IX2(_VALUE, _OFFSET) \
  491. ((_VALUE) << \
  492. (HWIO_REO_R0_DESTINATION_RING_CTRL_IX_2_DEST_RING_MAPPING_ ## \
  493. _OFFSET ## _SHFT))
  494. /*
  495. * Macro to access HWIO_REO_R0_DESTINATION_RING_CTRL_IX_3
  496. * to map destination to rings
  497. */
  498. #define HAL_REO_REMAP_IX3(_VALUE, _OFFSET) \
  499. ((_VALUE) << \
  500. (HWIO_REO_R0_DESTINATION_RING_CTRL_IX_3_DEST_RING_MAPPING_ ## \
  501. _OFFSET ## _SHFT))
  502. /**
  503. * hal_reo_read_write_ctrl_ix - Read or write REO_DESTINATION_RING_CTRL_IX
  504. * @hal_soc_hdl: HAL SOC handle
  505. * @read: boolean value to indicate if read or write
  506. * @ix0: pointer to store IX0 reg value
  507. * @ix1: pointer to store IX1 reg value
  508. * @ix2: pointer to store IX2 reg value
  509. * @ix3: pointer to store IX3 reg value
  510. */
  511. void hal_reo_read_write_ctrl_ix(hal_soc_handle_t hal_soc_hdl, bool read,
  512. uint32_t *ix0, uint32_t *ix1,
  513. uint32_t *ix2, uint32_t *ix3);
  514. /**
  515. * hal_srng_set_hp_paddr() - Set physical address to dest SRNG head pointer
  516. * @sring: sring pointer
  517. * @paddr: physical address
  518. */
  519. extern void hal_srng_dst_set_hp_paddr(struct hal_srng *sring, uint64_t paddr);
  520. /**
  521. * hal_srng_dst_init_hp() - Initilaize head pointer with cached head pointer
  522. * @srng: sring pointer
  523. * @vaddr: virtual address
  524. */
  525. extern void hal_srng_dst_init_hp(struct hal_srng *srng, uint32_t *vaddr);
  526. /**
  527. * hal_srng_cleanup - Deinitialize HW SRNG ring.
  528. * @hal_soc: Opaque HAL SOC handle
  529. * @hal_srng: Opaque HAL SRNG pointer
  530. */
  531. void hal_srng_cleanup(void *hal_soc, hal_ring_handle_t hal_ring_hdl);
  532. static inline bool hal_srng_initialized(hal_ring_handle_t hal_ring_hdl)
  533. {
  534. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  535. return !!srng->initialized;
  536. }
  537. /**
  538. * hal_srng_dst_peek - Check if there are any entries in the ring (peek)
  539. * @hal_soc: Opaque HAL SOC handle
  540. * @hal_ring_hdl: Destination ring pointer
  541. *
  542. * Caller takes responsibility for any locking needs.
  543. *
  544. * Return: Opaque pointer for next ring entry; NULL on failire
  545. */
  546. static inline
  547. void *hal_srng_dst_peek(hal_soc_handle_t hal_soc_hdl,
  548. hal_ring_handle_t hal_ring_hdl)
  549. {
  550. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  551. if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp)
  552. return (void *)(&srng->ring_base_vaddr[srng->u.dst_ring.tp]);
  553. return NULL;
  554. }
  555. /**
  556. * hal_srng_access_start_unlocked - Start ring access (unlocked). Should use
  557. * hal_srng_access_start if locked access is required
  558. *
  559. * @hal_soc: Opaque HAL SOC handle
  560. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  561. *
  562. * Return: 0 on success; error on failire
  563. */
  564. static inline int
  565. hal_srng_access_start_unlocked(hal_soc_handle_t hal_soc_hdl,
  566. hal_ring_handle_t hal_ring_hdl)
  567. {
  568. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  569. struct hal_soc *soc = (struct hal_soc *)hal_soc_hdl;
  570. uint32_t *desc;
  571. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  572. srng->u.src_ring.cached_tp =
  573. *(volatile uint32_t *)(srng->u.src_ring.tp_addr);
  574. else {
  575. srng->u.dst_ring.cached_hp =
  576. *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  577. if (srng->flags & HAL_SRNG_CACHED_DESC) {
  578. desc = hal_srng_dst_peek(hal_soc_hdl, hal_ring_hdl);
  579. if (qdf_likely(desc)) {
  580. qdf_mem_dma_cache_sync(soc->qdf_dev,
  581. qdf_mem_virt_to_phys
  582. (desc),
  583. QDF_DMA_FROM_DEVICE,
  584. (srng->entry_size *
  585. sizeof(uint32_t)));
  586. qdf_prefetch(desc);
  587. }
  588. }
  589. }
  590. return 0;
  591. }
  592. /**
  593. * hal_srng_access_start - Start (locked) ring access
  594. *
  595. * @hal_soc: Opaque HAL SOC handle
  596. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  597. *
  598. * Return: 0 on success; error on failire
  599. */
  600. static inline int hal_srng_access_start(hal_soc_handle_t hal_soc_hdl,
  601. hal_ring_handle_t hal_ring_hdl)
  602. {
  603. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  604. if (qdf_unlikely(!hal_ring_hdl)) {
  605. qdf_print("Error: Invalid hal_ring\n");
  606. return -EINVAL;
  607. }
  608. SRNG_LOCK(&(srng->lock));
  609. return hal_srng_access_start_unlocked(hal_soc_hdl, hal_ring_hdl);
  610. }
  611. /**
  612. * hal_srng_dst_get_next - Get next entry from a destination ring and move
  613. * cached tail pointer
  614. *
  615. * @hal_soc: Opaque HAL SOC handle
  616. * @hal_ring_hdl: Destination ring pointer
  617. *
  618. * Return: Opaque pointer for next ring entry; NULL on failire
  619. */
  620. static inline
  621. void *hal_srng_dst_get_next(void *hal_soc,
  622. hal_ring_handle_t hal_ring_hdl)
  623. {
  624. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  625. struct hal_soc *soc = (struct hal_soc *)hal_soc;
  626. uint32_t *desc;
  627. uint32_t *desc_next;
  628. uint32_t tp;
  629. if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp) {
  630. desc = &(srng->ring_base_vaddr[srng->u.dst_ring.tp]);
  631. /* TODO: Using % is expensive, but we have to do this since
  632. * size of some SRNG rings is not power of 2 (due to descriptor
  633. * sizes). Need to create separate API for rings used
  634. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  635. * SW2RXDMA and CE rings)
  636. */
  637. srng->u.dst_ring.tp = (srng->u.dst_ring.tp + srng->entry_size) %
  638. srng->ring_size;
  639. if (srng->flags & HAL_SRNG_CACHED_DESC) {
  640. tp = srng->u.dst_ring.tp;
  641. desc_next = &srng->ring_base_vaddr[tp];
  642. qdf_mem_dma_cache_sync(soc->qdf_dev,
  643. qdf_mem_virt_to_phys(desc_next),
  644. QDF_DMA_FROM_DEVICE,
  645. (srng->entry_size *
  646. sizeof(uint32_t)));
  647. qdf_prefetch(desc_next);
  648. }
  649. return (void *)desc;
  650. }
  651. return NULL;
  652. }
  653. /**
  654. * hal_srng_dst_get_next_hp - Get next entry from a destination ring and move
  655. * cached head pointer
  656. *
  657. * @hal_soc: Opaque HAL SOC handle
  658. * @hal_ring_hdl: Destination ring pointer
  659. *
  660. * Return: Opaque pointer for next ring entry; NULL on failire
  661. */
  662. static inline void *
  663. hal_srng_dst_get_next_hp(hal_soc_handle_t hal_soc_hdl,
  664. hal_ring_handle_t hal_ring_hdl)
  665. {
  666. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  667. uint32_t *desc;
  668. /* TODO: Using % is expensive, but we have to do this since
  669. * size of some SRNG rings is not power of 2 (due to descriptor
  670. * sizes). Need to create separate API for rings used
  671. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  672. * SW2RXDMA and CE rings)
  673. */
  674. uint32_t next_hp = (srng->u.dst_ring.cached_hp + srng->entry_size) %
  675. srng->ring_size;
  676. if (next_hp != srng->u.dst_ring.tp) {
  677. desc = &(srng->ring_base_vaddr[srng->u.dst_ring.cached_hp]);
  678. srng->u.dst_ring.cached_hp = next_hp;
  679. return (void *)desc;
  680. }
  681. return NULL;
  682. }
  683. /**
  684. * hal_srng_dst_peek_sync - Check if there are any entries in the ring (peek)
  685. * @hal_soc: Opaque HAL SOC handle
  686. * @hal_ring_hdl: Destination ring pointer
  687. *
  688. * Sync cached head pointer with HW.
  689. * Caller takes responsibility for any locking needs.
  690. *
  691. * Return: Opaque pointer for next ring entry; NULL on failire
  692. */
  693. static inline
  694. void *hal_srng_dst_peek_sync(hal_soc_handle_t hal_soc_hdl,
  695. hal_ring_handle_t hal_ring_hdl)
  696. {
  697. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  698. srng->u.dst_ring.cached_hp =
  699. *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  700. if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp)
  701. return (void *)(&(srng->ring_base_vaddr[srng->u.dst_ring.tp]));
  702. return NULL;
  703. }
  704. /**
  705. * hal_srng_dst_peek_sync_locked - Peek for any entries in the ring
  706. * @hal_soc: Opaque HAL SOC handle
  707. * @hal_ring_hdl: Destination ring pointer
  708. *
  709. * Sync cached head pointer with HW.
  710. * This function takes up SRNG_LOCK. Should not be called with SRNG lock held.
  711. *
  712. * Return: Opaque pointer for next ring entry; NULL on failire
  713. */
  714. static inline
  715. void *hal_srng_dst_peek_sync_locked(hal_soc_handle_t hal_soc_hdl,
  716. hal_ring_handle_t hal_ring_hdl)
  717. {
  718. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  719. void *ring_desc_ptr = NULL;
  720. if (qdf_unlikely(!hal_ring_hdl)) {
  721. qdf_print("Error: Invalid hal_ring\n");
  722. return NULL;
  723. }
  724. SRNG_LOCK(&srng->lock);
  725. ring_desc_ptr = hal_srng_dst_peek_sync(hal_soc_hdl, hal_ring_hdl);
  726. SRNG_UNLOCK(&srng->lock);
  727. return ring_desc_ptr;
  728. }
  729. /**
  730. * hal_srng_dst_num_valid - Returns number of valid entries (to be processed
  731. * by SW) in destination ring
  732. *
  733. * @hal_soc: Opaque HAL SOC handle
  734. * @hal_ring_hdl: Destination ring pointer
  735. * @sync_hw_ptr: Sync cached head pointer with HW
  736. *
  737. */
  738. static inline
  739. uint32_t hal_srng_dst_num_valid(void *hal_soc,
  740. hal_ring_handle_t hal_ring_hdl,
  741. int sync_hw_ptr)
  742. {
  743. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  744. uint32_t hp;
  745. uint32_t tp = srng->u.dst_ring.tp;
  746. if (sync_hw_ptr) {
  747. hp = *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  748. srng->u.dst_ring.cached_hp = hp;
  749. } else {
  750. hp = srng->u.dst_ring.cached_hp;
  751. }
  752. if (hp >= tp)
  753. return (hp - tp) / srng->entry_size;
  754. else
  755. return (srng->ring_size - tp + hp) / srng->entry_size;
  756. }
  757. /**
  758. * hal_srng_dst_num_valid_locked - Returns num valid entries to be processed
  759. *
  760. * @hal_soc: Opaque HAL SOC handle
  761. * @hal_ring_hdl: Destination ring pointer
  762. * @sync_hw_ptr: Sync cached head pointer with HW
  763. *
  764. * Returns number of valid entries to be processed by the host driver. The
  765. * function takes up SRNG lock.
  766. *
  767. * Return: Number of valid destination entries
  768. */
  769. static inline uint32_t
  770. hal_srng_dst_num_valid_locked(hal_soc_handle_t hal_soc,
  771. hal_ring_handle_t hal_ring_hdl,
  772. int sync_hw_ptr)
  773. {
  774. uint32_t num_valid;
  775. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  776. SRNG_LOCK(&srng->lock);
  777. num_valid = hal_srng_dst_num_valid(hal_soc, hal_ring_hdl, sync_hw_ptr);
  778. SRNG_UNLOCK(&srng->lock);
  779. return num_valid;
  780. }
  781. /**
  782. * hal_srng_src_reap_next - Reap next entry from a source ring and move reap
  783. * pointer. This can be used to release any buffers associated with completed
  784. * ring entries. Note that this should not be used for posting new descriptor
  785. * entries. Posting of new entries should be done only using
  786. * hal_srng_src_get_next_reaped when this function is used for reaping.
  787. *
  788. * @hal_soc: Opaque HAL SOC handle
  789. * @hal_ring_hdl: Source ring pointer
  790. *
  791. * Return: Opaque pointer for next ring entry; NULL on failire
  792. */
  793. static inline void *
  794. hal_srng_src_reap_next(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  795. {
  796. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  797. uint32_t *desc;
  798. /* TODO: Using % is expensive, but we have to do this since
  799. * size of some SRNG rings is not power of 2 (due to descriptor
  800. * sizes). Need to create separate API for rings used
  801. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  802. * SW2RXDMA and CE rings)
  803. */
  804. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  805. srng->ring_size;
  806. if (next_reap_hp != srng->u.src_ring.cached_tp) {
  807. desc = &(srng->ring_base_vaddr[next_reap_hp]);
  808. srng->u.src_ring.reap_hp = next_reap_hp;
  809. return (void *)desc;
  810. }
  811. return NULL;
  812. }
  813. /**
  814. * hal_srng_src_get_next_reaped - Get next entry from a source ring that is
  815. * already reaped using hal_srng_src_reap_next, for posting new entries to
  816. * the ring
  817. *
  818. * @hal_soc: Opaque HAL SOC handle
  819. * @hal_ring_hdl: Source ring pointer
  820. *
  821. * Return: Opaque pointer for next (reaped) source ring entry; NULL on failire
  822. */
  823. static inline void *
  824. hal_srng_src_get_next_reaped(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  825. {
  826. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  827. uint32_t *desc;
  828. if (srng->u.src_ring.hp != srng->u.src_ring.reap_hp) {
  829. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  830. srng->u.src_ring.hp = (srng->u.src_ring.hp + srng->entry_size) %
  831. srng->ring_size;
  832. return (void *)desc;
  833. }
  834. return NULL;
  835. }
  836. /**
  837. * hal_srng_src_pending_reap_next - Reap next entry from a source ring and
  838. * move reap pointer. This API is used in detach path to release any buffers
  839. * associated with ring entries which are pending reap.
  840. *
  841. * @hal_soc: Opaque HAL SOC handle
  842. * @hal_ring_hdl: Source ring pointer
  843. *
  844. * Return: Opaque pointer for next ring entry; NULL on failire
  845. */
  846. static inline void *
  847. hal_srng_src_pending_reap_next(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  848. {
  849. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  850. uint32_t *desc;
  851. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  852. srng->ring_size;
  853. if (next_reap_hp != srng->u.src_ring.hp) {
  854. desc = &(srng->ring_base_vaddr[next_reap_hp]);
  855. srng->u.src_ring.reap_hp = next_reap_hp;
  856. return (void *)desc;
  857. }
  858. return NULL;
  859. }
  860. /**
  861. * hal_srng_src_done_val -
  862. *
  863. * @hal_soc: Opaque HAL SOC handle
  864. * @hal_ring_hdl: Source ring pointer
  865. *
  866. * Return: Opaque pointer for next ring entry; NULL on failire
  867. */
  868. static inline uint32_t
  869. hal_srng_src_done_val(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  870. {
  871. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  872. /* TODO: Using % is expensive, but we have to do this since
  873. * size of some SRNG rings is not power of 2 (due to descriptor
  874. * sizes). Need to create separate API for rings used
  875. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  876. * SW2RXDMA and CE rings)
  877. */
  878. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  879. srng->ring_size;
  880. if (next_reap_hp == srng->u.src_ring.cached_tp)
  881. return 0;
  882. if (srng->u.src_ring.cached_tp > next_reap_hp)
  883. return (srng->u.src_ring.cached_tp - next_reap_hp) /
  884. srng->entry_size;
  885. else
  886. return ((srng->ring_size - next_reap_hp) +
  887. srng->u.src_ring.cached_tp) / srng->entry_size;
  888. }
  889. /**
  890. * hal_get_entrysize_from_srng() - Retrieve ring entry size
  891. * @hal_ring_hdl: Source ring pointer
  892. *
  893. * Return: uint8_t
  894. */
  895. static inline
  896. uint8_t hal_get_entrysize_from_srng(hal_ring_handle_t hal_ring_hdl)
  897. {
  898. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  899. return srng->entry_size;
  900. }
  901. /**
  902. * hal_get_sw_hptp - Get SW head and tail pointer location for any ring
  903. * @hal_soc: Opaque HAL SOC handle
  904. * @hal_ring_hdl: Source ring pointer
  905. * @tailp: Tail Pointer
  906. * @headp: Head Pointer
  907. *
  908. * Return: Update tail pointer and head pointer in arguments.
  909. */
  910. static inline
  911. void hal_get_sw_hptp(void *hal_soc, hal_ring_handle_t hal_ring_hdl,
  912. uint32_t *tailp, uint32_t *headp)
  913. {
  914. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  915. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  916. *headp = srng->u.src_ring.hp;
  917. *tailp = *srng->u.src_ring.tp_addr;
  918. } else {
  919. *tailp = srng->u.dst_ring.tp;
  920. *headp = *srng->u.dst_ring.hp_addr;
  921. }
  922. }
  923. /**
  924. * hal_srng_src_get_next - Get next entry from a source ring and move cached tail pointer
  925. *
  926. * @hal_soc: Opaque HAL SOC handle
  927. * @hal_ring_hdl: Source ring pointer
  928. *
  929. * Return: Opaque pointer for next ring entry; NULL on failire
  930. */
  931. static inline
  932. void *hal_srng_src_get_next(void *hal_soc,
  933. hal_ring_handle_t hal_ring_hdl)
  934. {
  935. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  936. uint32_t *desc;
  937. /* TODO: Using % is expensive, but we have to do this since
  938. * size of some SRNG rings is not power of 2 (due to descriptor
  939. * sizes). Need to create separate API for rings used
  940. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  941. * SW2RXDMA and CE rings)
  942. */
  943. uint32_t next_hp = (srng->u.src_ring.hp + srng->entry_size) %
  944. srng->ring_size;
  945. if (next_hp != srng->u.src_ring.cached_tp) {
  946. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  947. srng->u.src_ring.hp = next_hp;
  948. /* TODO: Since reap function is not used by all rings, we can
  949. * remove the following update of reap_hp in this function
  950. * if we can ensure that only hal_srng_src_get_next_reaped
  951. * is used for the rings requiring reap functionality
  952. */
  953. srng->u.src_ring.reap_hp = next_hp;
  954. return (void *)desc;
  955. }
  956. return NULL;
  957. }
  958. /**
  959. * hal_srng_src_peek - Get next entry from a ring without moving head pointer.
  960. * hal_srng_src_get_next should be called subsequently to move the head pointer
  961. *
  962. * @hal_soc: Opaque HAL SOC handle
  963. * @hal_ring_hdl: Source ring pointer
  964. *
  965. * Return: Opaque pointer for next ring entry; NULL on failire
  966. */
  967. static inline
  968. void *hal_srng_src_peek(hal_soc_handle_t hal_soc_hdl,
  969. hal_ring_handle_t hal_ring_hdl)
  970. {
  971. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  972. uint32_t *desc;
  973. /* TODO: Using % is expensive, but we have to do this since
  974. * size of some SRNG rings is not power of 2 (due to descriptor
  975. * sizes). Need to create separate API for rings used
  976. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  977. * SW2RXDMA and CE rings)
  978. */
  979. if (((srng->u.src_ring.hp + srng->entry_size) %
  980. srng->ring_size) != srng->u.src_ring.cached_tp) {
  981. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  982. return (void *)desc;
  983. }
  984. return NULL;
  985. }
  986. /**
  987. * hal_srng_src_num_avail - Returns number of available entries in src ring
  988. *
  989. * @hal_soc: Opaque HAL SOC handle
  990. * @hal_ring_hdl: Source ring pointer
  991. * @sync_hw_ptr: Sync cached tail pointer with HW
  992. *
  993. */
  994. static inline uint32_t
  995. hal_srng_src_num_avail(void *hal_soc,
  996. hal_ring_handle_t hal_ring_hdl, int sync_hw_ptr)
  997. {
  998. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  999. uint32_t tp;
  1000. uint32_t hp = srng->u.src_ring.hp;
  1001. if (sync_hw_ptr) {
  1002. tp = *(srng->u.src_ring.tp_addr);
  1003. srng->u.src_ring.cached_tp = tp;
  1004. } else {
  1005. tp = srng->u.src_ring.cached_tp;
  1006. }
  1007. if (tp > hp)
  1008. return ((tp - hp) / srng->entry_size) - 1;
  1009. else
  1010. return ((srng->ring_size - hp + tp) / srng->entry_size) - 1;
  1011. }
  1012. /**
  1013. * hal_srng_access_end_unlocked - End ring access (unlocked) - update cached
  1014. * ring head/tail pointers to HW.
  1015. * This should be used only if hal_srng_access_start_unlocked to start ring
  1016. * access
  1017. *
  1018. * @hal_soc: Opaque HAL SOC handle
  1019. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1020. *
  1021. * Return: 0 on success; error on failire
  1022. */
  1023. static inline void
  1024. hal_srng_access_end_unlocked(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1025. {
  1026. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1027. /* TODO: See if we need a write memory barrier here */
  1028. if (srng->flags & HAL_SRNG_LMAC_RING) {
  1029. /* For LMAC rings, ring pointer updates are done through FW and
  1030. * hence written to a shared memory location that is read by FW
  1031. */
  1032. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1033. *(srng->u.src_ring.hp_addr) = srng->u.src_ring.hp;
  1034. } else {
  1035. *(srng->u.dst_ring.tp_addr) = srng->u.dst_ring.tp;
  1036. }
  1037. } else {
  1038. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  1039. hal_write_address_32_mb(hal_soc,
  1040. srng->u.src_ring.hp_addr,
  1041. srng->u.src_ring.hp);
  1042. else
  1043. hal_write_address_32_mb(hal_soc,
  1044. srng->u.dst_ring.tp_addr,
  1045. srng->u.dst_ring.tp);
  1046. }
  1047. }
  1048. /**
  1049. * hal_srng_access_end - Unlock ring access and update cached ring head/tail
  1050. * pointers to HW
  1051. * This should be used only if hal_srng_access_start to start ring access
  1052. *
  1053. * @hal_soc: Opaque HAL SOC handle
  1054. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1055. *
  1056. * Return: 0 on success; error on failire
  1057. */
  1058. static inline void
  1059. hal_srng_access_end(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1060. {
  1061. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1062. if (qdf_unlikely(!hal_ring_hdl)) {
  1063. qdf_print("Error: Invalid hal_ring\n");
  1064. return;
  1065. }
  1066. hal_srng_access_end_unlocked(hal_soc, hal_ring_hdl);
  1067. SRNG_UNLOCK(&(srng->lock));
  1068. }
  1069. /**
  1070. * hal_srng_access_end_reap - Unlock ring access
  1071. * This should be used only if hal_srng_access_start to start ring access
  1072. * and should be used only while reaping SRC ring completions
  1073. *
  1074. * @hal_soc: Opaque HAL SOC handle
  1075. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1076. *
  1077. * Return: 0 on success; error on failire
  1078. */
  1079. static inline void
  1080. hal_srng_access_end_reap(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1081. {
  1082. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1083. SRNG_UNLOCK(&(srng->lock));
  1084. }
  1085. /* TODO: Check if the following definitions is available in HW headers */
  1086. #define WBM_IDLE_SCATTER_BUF_SIZE 32704
  1087. #define NUM_MPDUS_PER_LINK_DESC 6
  1088. #define NUM_MSDUS_PER_LINK_DESC 7
  1089. #define REO_QUEUE_DESC_ALIGN 128
  1090. #define LINK_DESC_ALIGN 128
  1091. #define ADDRESS_MATCH_TAG_VAL 0x5
  1092. /* Number of mpdu link pointers is 9 in case of TX_MPDU_QUEUE_HEAD and 14 in
  1093. * of TX_MPDU_QUEUE_EXT. We are defining a common average count here
  1094. */
  1095. #define NUM_MPDU_LINKS_PER_QUEUE_DESC 12
  1096. /* TODO: Check with HW team on the scatter buffer size supported. As per WBM
  1097. * MLD, scatter_buffer_size in IDLE_LIST_CONTROL register is 9 bits and size
  1098. * should be specified in 16 word units. But the number of bits defined for
  1099. * this field in HW header files is 5.
  1100. */
  1101. #define WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE 8
  1102. /**
  1103. * hal_idle_list_scatter_buf_size - Get the size of each scatter buffer
  1104. * in an idle list
  1105. *
  1106. * @hal_soc: Opaque HAL SOC handle
  1107. *
  1108. */
  1109. static inline
  1110. uint32_t hal_idle_list_scatter_buf_size(hal_soc_handle_t hal_soc_hdl)
  1111. {
  1112. return WBM_IDLE_SCATTER_BUF_SIZE;
  1113. }
  1114. /**
  1115. * hal_get_link_desc_size - Get the size of each link descriptor
  1116. *
  1117. * @hal_soc: Opaque HAL SOC handle
  1118. *
  1119. */
  1120. static inline uint32_t hal_get_link_desc_size(hal_soc_handle_t hal_soc_hdl)
  1121. {
  1122. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  1123. if (!hal_soc || !hal_soc->ops) {
  1124. qdf_print("Error: Invalid ops\n");
  1125. QDF_BUG(0);
  1126. return -EINVAL;
  1127. }
  1128. if (!hal_soc->ops->hal_get_link_desc_size) {
  1129. qdf_print("Error: Invalid function pointer\n");
  1130. QDF_BUG(0);
  1131. return -EINVAL;
  1132. }
  1133. return hal_soc->ops->hal_get_link_desc_size();
  1134. }
  1135. /**
  1136. * hal_get_link_desc_align - Get the required start address alignment for
  1137. * link descriptors
  1138. *
  1139. * @hal_soc: Opaque HAL SOC handle
  1140. *
  1141. */
  1142. static inline
  1143. uint32_t hal_get_link_desc_align(hal_soc_handle_t hal_soc_hdl)
  1144. {
  1145. return LINK_DESC_ALIGN;
  1146. }
  1147. /**
  1148. * hal_num_mpdus_per_link_desc - Get number of mpdus each link desc can hold
  1149. *
  1150. * @hal_soc: Opaque HAL SOC handle
  1151. *
  1152. */
  1153. static inline
  1154. uint32_t hal_num_mpdus_per_link_desc(hal_soc_handle_t hal_soc_hdl)
  1155. {
  1156. return NUM_MPDUS_PER_LINK_DESC;
  1157. }
  1158. /**
  1159. * hal_num_msdus_per_link_desc - Get number of msdus each link desc can hold
  1160. *
  1161. * @hal_soc: Opaque HAL SOC handle
  1162. *
  1163. */
  1164. static inline
  1165. uint32_t hal_num_msdus_per_link_desc(hal_soc_handle_t hal_soc_hdl)
  1166. {
  1167. return NUM_MSDUS_PER_LINK_DESC;
  1168. }
  1169. /**
  1170. * hal_num_mpdu_links_per_queue_desc - Get number of mpdu links each queue
  1171. * descriptor can hold
  1172. *
  1173. * @hal_soc: Opaque HAL SOC handle
  1174. *
  1175. */
  1176. static inline
  1177. uint32_t hal_num_mpdu_links_per_queue_desc(hal_soc_handle_t hal_soc_hdl)
  1178. {
  1179. return NUM_MPDU_LINKS_PER_QUEUE_DESC;
  1180. }
  1181. /**
  1182. * hal_idle_list_scatter_buf_num_entries - Get the number of link desc entries
  1183. * that the given buffer size
  1184. *
  1185. * @hal_soc: Opaque HAL SOC handle
  1186. * @scatter_buf_size: Size of scatter buffer
  1187. *
  1188. */
  1189. static inline
  1190. uint32_t hal_idle_scatter_buf_num_entries(hal_soc_handle_t hal_soc_hdl,
  1191. uint32_t scatter_buf_size)
  1192. {
  1193. return (scatter_buf_size - WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE) /
  1194. hal_srng_get_entrysize(hal_soc_hdl, WBM_IDLE_LINK);
  1195. }
  1196. /**
  1197. * hal_idle_list_num_scatter_bufs - Get the number of sctater buffer
  1198. * each given buffer size
  1199. *
  1200. * @hal_soc: Opaque HAL SOC handle
  1201. * @total_mem: size of memory to be scattered
  1202. * @scatter_buf_size: Size of scatter buffer
  1203. *
  1204. */
  1205. static inline
  1206. uint32_t hal_idle_list_num_scatter_bufs(hal_soc_handle_t hal_soc_hdl,
  1207. uint32_t total_mem,
  1208. uint32_t scatter_buf_size)
  1209. {
  1210. uint8_t rem = (total_mem % (scatter_buf_size -
  1211. WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE)) ? 1 : 0;
  1212. uint32_t num_scatter_bufs = (total_mem / (scatter_buf_size -
  1213. WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE)) + rem;
  1214. return num_scatter_bufs;
  1215. }
  1216. enum hal_pn_type {
  1217. HAL_PN_NONE,
  1218. HAL_PN_WPA,
  1219. HAL_PN_WAPI_EVEN,
  1220. HAL_PN_WAPI_UNEVEN,
  1221. };
  1222. #define HAL_RX_MAX_BA_WINDOW 256
  1223. /**
  1224. * hal_get_reo_qdesc_align - Get start address alignment for reo
  1225. * queue descriptors
  1226. *
  1227. * @hal_soc: Opaque HAL SOC handle
  1228. *
  1229. */
  1230. static inline
  1231. uint32_t hal_get_reo_qdesc_align(hal_soc_handle_t hal_soc_hdl)
  1232. {
  1233. return REO_QUEUE_DESC_ALIGN;
  1234. }
  1235. /**
  1236. * hal_reo_qdesc_setup - Setup HW REO queue descriptor
  1237. *
  1238. * @hal_soc: Opaque HAL SOC handle
  1239. * @ba_window_size: BlockAck window size
  1240. * @start_seq: Starting sequence number
  1241. * @hw_qdesc_vaddr: Virtual address of REO queue descriptor memory
  1242. * @hw_qdesc_paddr: Physical address of REO queue descriptor memory
  1243. * @pn_type: PN type (one of the types defined in 'enum hal_pn_type')
  1244. *
  1245. */
  1246. void hal_reo_qdesc_setup(hal_soc_handle_t hal_soc_hdl,
  1247. int tid, uint32_t ba_window_size,
  1248. uint32_t start_seq, void *hw_qdesc_vaddr,
  1249. qdf_dma_addr_t hw_qdesc_paddr,
  1250. int pn_type);
  1251. /**
  1252. * hal_srng_get_hp_addr - Get head pointer physical address
  1253. *
  1254. * @hal_soc: Opaque HAL SOC handle
  1255. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1256. *
  1257. */
  1258. static inline qdf_dma_addr_t
  1259. hal_srng_get_hp_addr(void *hal_soc,
  1260. hal_ring_handle_t hal_ring_hdl)
  1261. {
  1262. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1263. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  1264. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1265. return hal->shadow_wrptr_mem_paddr +
  1266. ((unsigned long)(srng->u.src_ring.hp_addr) -
  1267. (unsigned long)(hal->shadow_wrptr_mem_vaddr));
  1268. } else {
  1269. return hal->shadow_rdptr_mem_paddr +
  1270. ((unsigned long)(srng->u.dst_ring.hp_addr) -
  1271. (unsigned long)(hal->shadow_rdptr_mem_vaddr));
  1272. }
  1273. }
  1274. /**
  1275. * hal_srng_get_tp_addr - Get tail pointer physical address
  1276. *
  1277. * @hal_soc: Opaque HAL SOC handle
  1278. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1279. *
  1280. */
  1281. static inline qdf_dma_addr_t
  1282. hal_srng_get_tp_addr(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1283. {
  1284. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1285. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  1286. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1287. return hal->shadow_rdptr_mem_paddr +
  1288. ((unsigned long)(srng->u.src_ring.tp_addr) -
  1289. (unsigned long)(hal->shadow_rdptr_mem_vaddr));
  1290. } else {
  1291. return hal->shadow_wrptr_mem_paddr +
  1292. ((unsigned long)(srng->u.dst_ring.tp_addr) -
  1293. (unsigned long)(hal->shadow_wrptr_mem_vaddr));
  1294. }
  1295. }
  1296. /**
  1297. * hal_srng_get_num_entries - Get total entries in the HAL Srng
  1298. *
  1299. * @hal_soc: Opaque HAL SOC handle
  1300. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1301. *
  1302. * Return: total number of entries in hal ring
  1303. */
  1304. static inline
  1305. uint32_t hal_srng_get_num_entries(hal_soc_handle_t hal_soc_hdl,
  1306. hal_ring_handle_t hal_ring_hdl)
  1307. {
  1308. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1309. return srng->num_entries;
  1310. }
  1311. /**
  1312. * hal_get_srng_params - Retrieve SRNG parameters for a given ring from HAL
  1313. *
  1314. * @hal_soc: Opaque HAL SOC handle
  1315. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1316. * @ring_params: SRNG parameters will be returned through this structure
  1317. */
  1318. void hal_get_srng_params(hal_soc_handle_t hal_soc_hdl,
  1319. hal_ring_handle_t hal_ring_hdl,
  1320. struct hal_srng_params *ring_params);
  1321. /**
  1322. * hal_mem_info - Retrieve hal memory base address
  1323. *
  1324. * @hal_soc: Opaque HAL SOC handle
  1325. * @mem: pointer to structure to be updated with hal mem info
  1326. */
  1327. void hal_get_meminfo(hal_soc_handle_t hal_soc_hdl, struct hal_mem_info *mem);
  1328. /**
  1329. * hal_get_target_type - Return target type
  1330. *
  1331. * @hal_soc: Opaque HAL SOC handle
  1332. */
  1333. uint32_t hal_get_target_type(hal_soc_handle_t hal_soc_hdl);
  1334. /**
  1335. * hal_get_ba_aging_timeout - Retrieve BA aging timeout
  1336. *
  1337. * @hal_soc: Opaque HAL SOC handle
  1338. * @ac: Access category
  1339. * @value: timeout duration in millisec
  1340. */
  1341. void hal_get_ba_aging_timeout(hal_soc_handle_t hal_soc_hdl, uint8_t ac,
  1342. uint32_t *value);
  1343. /**
  1344. * hal_set_aging_timeout - Set BA aging timeout
  1345. *
  1346. * @hal_soc: Opaque HAL SOC handle
  1347. * @ac: Access category in millisec
  1348. * @value: timeout duration value
  1349. */
  1350. void hal_set_ba_aging_timeout(hal_soc_handle_t hal_soc_hdl, uint8_t ac,
  1351. uint32_t value);
  1352. /**
  1353. * hal_srng_dst_hw_init - Private function to initialize SRNG
  1354. * destination ring HW
  1355. * @hal_soc: HAL SOC handle
  1356. * @srng: SRNG ring pointer
  1357. */
  1358. static inline void hal_srng_dst_hw_init(struct hal_soc *hal,
  1359. struct hal_srng *srng)
  1360. {
  1361. hal->ops->hal_srng_dst_hw_init(hal, srng);
  1362. }
  1363. /**
  1364. * hal_srng_src_hw_init - Private function to initialize SRNG
  1365. * source ring HW
  1366. * @hal_soc: HAL SOC handle
  1367. * @srng: SRNG ring pointer
  1368. */
  1369. static inline void hal_srng_src_hw_init(struct hal_soc *hal,
  1370. struct hal_srng *srng)
  1371. {
  1372. hal->ops->hal_srng_src_hw_init(hal, srng);
  1373. }
  1374. /**
  1375. * hal_get_hw_hptp() - Get HW head and tail pointer value for any ring
  1376. * @hal_soc: Opaque HAL SOC handle
  1377. * @hal_ring_hdl: Source ring pointer
  1378. * @headp: Head Pointer
  1379. * @tailp: Tail Pointer
  1380. * @ring_type: Ring
  1381. *
  1382. * Return: Update tail pointer and head pointer in arguments.
  1383. */
  1384. static inline
  1385. void hal_get_hw_hptp(hal_soc_handle_t hal_soc_hdl,
  1386. hal_ring_handle_t hal_ring_hdl,
  1387. uint32_t *headp, uint32_t *tailp,
  1388. uint8_t ring_type)
  1389. {
  1390. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  1391. hal_soc->ops->hal_get_hw_hptp(hal_soc, hal_ring_hdl,
  1392. headp, tailp, ring_type);
  1393. }
  1394. /**
  1395. * hal_reo_setup - Initialize HW REO block
  1396. *
  1397. * @hal_soc: Opaque HAL SOC handle
  1398. * @reo_params: parameters needed by HAL for REO config
  1399. */
  1400. static inline void hal_reo_setup(hal_soc_handle_t hal_soc_hdl,
  1401. void *reoparams)
  1402. {
  1403. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  1404. hal_soc->ops->hal_reo_setup(hal_soc, reoparams);
  1405. }
  1406. /**
  1407. * hal_setup_link_idle_list - Setup scattered idle list using the
  1408. * buffer list provided
  1409. *
  1410. * @hal_soc: Opaque HAL SOC handle
  1411. * @scatter_bufs_base_paddr: Array of physical base addresses
  1412. * @scatter_bufs_base_vaddr: Array of virtual base addresses
  1413. * @num_scatter_bufs: Number of scatter buffers in the above lists
  1414. * @scatter_buf_size: Size of each scatter buffer
  1415. * @last_buf_end_offset: Offset to the last entry
  1416. * @num_entries: Total entries of all scatter bufs
  1417. *
  1418. */
  1419. static inline
  1420. void hal_setup_link_idle_list(hal_soc_handle_t hal_soc_hdl,
  1421. qdf_dma_addr_t scatter_bufs_base_paddr[],
  1422. void *scatter_bufs_base_vaddr[],
  1423. uint32_t num_scatter_bufs,
  1424. uint32_t scatter_buf_size,
  1425. uint32_t last_buf_end_offset,
  1426. uint32_t num_entries)
  1427. {
  1428. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  1429. hal_soc->ops->hal_setup_link_idle_list(hal_soc, scatter_bufs_base_paddr,
  1430. scatter_bufs_base_vaddr, num_scatter_bufs,
  1431. scatter_buf_size, last_buf_end_offset,
  1432. num_entries);
  1433. }
  1434. /**
  1435. * hal_srng_dump_ring_desc() - Dump ring descriptor info
  1436. *
  1437. * @hal_soc: Opaque HAL SOC handle
  1438. * @hal_ring_hdl: Source ring pointer
  1439. * @ring_desc: Opaque ring descriptor handle
  1440. */
  1441. static inline void hal_srng_dump_ring_desc(hal_soc_handle_t hal_soc_hdl,
  1442. hal_ring_handle_t hal_ring_hdl,
  1443. hal_ring_desc_t ring_desc)
  1444. {
  1445. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1446. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_HIGH,
  1447. ring_desc, (srng->entry_size << 2));
  1448. }
  1449. /**
  1450. * hal_srng_dump_ring() - Dump last 128 descs of the ring
  1451. *
  1452. * @hal_soc: Opaque HAL SOC handle
  1453. * @hal_ring_hdl: Source ring pointer
  1454. */
  1455. static inline void hal_srng_dump_ring(hal_soc_handle_t hal_soc_hdl,
  1456. hal_ring_handle_t hal_ring_hdl)
  1457. {
  1458. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1459. uint32_t *desc;
  1460. uint32_t tp, i;
  1461. tp = srng->u.dst_ring.tp;
  1462. for (i = 0; i < 128; i++) {
  1463. if (!tp)
  1464. tp = srng->ring_size;
  1465. desc = &srng->ring_base_vaddr[tp - srng->entry_size];
  1466. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_DP,
  1467. QDF_TRACE_LEVEL_DEBUG,
  1468. desc, (srng->entry_size << 2));
  1469. tp -= srng->entry_size;
  1470. }
  1471. }
  1472. /*
  1473. * hal_rxdma_desc_to_hal_ring_desc - API to convert rxdma ring desc
  1474. * to opaque dp_ring desc type
  1475. * @ring_desc - rxdma ring desc
  1476. *
  1477. * Return: hal_rxdma_desc_t type
  1478. */
  1479. static inline
  1480. hal_ring_desc_t hal_rxdma_desc_to_hal_ring_desc(hal_rxdma_desc_t ring_desc)
  1481. {
  1482. return (hal_ring_desc_t)ring_desc;
  1483. }
  1484. /**
  1485. * hal_srng_set_event() - Set hal_srng event
  1486. * @hal_ring_hdl: Source ring pointer
  1487. * @event: SRNG ring event
  1488. *
  1489. * Return: None
  1490. */
  1491. static inline void hal_srng_set_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_set_bit(event, &srng->srng_event);
  1495. }
  1496. /**
  1497. * hal_srng_clear_event() - Clear hal_srng event
  1498. * @hal_ring_hdl: Source ring pointer
  1499. * @event: SRNG ring event
  1500. *
  1501. * Return: None
  1502. */
  1503. static inline
  1504. void hal_srng_clear_event(hal_ring_handle_t hal_ring_hdl, int event)
  1505. {
  1506. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1507. qdf_atomic_clear_bit(event, &srng->srng_event);
  1508. }
  1509. /**
  1510. * hal_srng_get_clear_event() - Clear srng event and return old value
  1511. * @hal_ring_hdl: Source ring pointer
  1512. * @event: SRNG ring event
  1513. *
  1514. * Return: Return old event value
  1515. */
  1516. static inline
  1517. int hal_srng_get_clear_event(hal_ring_handle_t hal_ring_hdl, int event)
  1518. {
  1519. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1520. return qdf_atomic_test_and_clear_bit(event, &srng->srng_event);
  1521. }
  1522. /**
  1523. * hal_srng_set_flush_last_ts() - Record last flush time stamp
  1524. * @hal_ring_hdl: Source ring pointer
  1525. *
  1526. * Return: None
  1527. */
  1528. static inline void hal_srng_set_flush_last_ts(hal_ring_handle_t hal_ring_hdl)
  1529. {
  1530. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1531. srng->last_flush_ts = qdf_get_log_timestamp();
  1532. }
  1533. /**
  1534. * hal_srng_inc_flush_cnt() - Increment flush counter
  1535. * @hal_ring_hdl: Source ring pointer
  1536. *
  1537. * Return: None
  1538. */
  1539. static inline void hal_srng_inc_flush_cnt(hal_ring_handle_t hal_ring_hdl)
  1540. {
  1541. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1542. srng->flush_count++;
  1543. }
  1544. #endif /* _HAL_APIH_ */