hal_api.h 52 KB

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