hal_api.h 47 KB

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