hal_api.h 72 KB

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