hal_api.h 49 KB

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