hal_api.h 57 KB

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