hal_api.h 76 KB

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