hal_api.h 56 KB

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