hal_api.h 73 KB

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