hal_api.h 58 KB

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