hal_api.h 49 KB

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