hal_api.h 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025
  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. #define hal_srng_write_address_32_mb(_a, _b, _c) qdf_iowrite32(_b, _c)
  394. #else
  395. #define hal_srng_write_address_32_mb(_a, _b, _c) \
  396. hal_write_address_32_mb(_a, _b, _c)
  397. #endif
  398. #if !defined(QCA_WIFI_QCA6390) && !defined(QCA_WIFI_QCA6490) && \
  399. !defined(QCA_WIFI_QCA6750)
  400. /**
  401. * hal_read32_mb() - Access registers to read configuration
  402. * @hal_soc: hal soc handle
  403. * @offset: offset address from the BAR
  404. * @value: value to write
  405. *
  406. * Description: Register address space is split below:
  407. * SHADOW REGION UNWINDOWED REGION WINDOWED REGION
  408. * |--------------------|-------------------|------------------|
  409. * BAR NO FORCE WAKE BAR+4K FORCE WAKE BAR+512K FORCE WAKE
  410. *
  411. * 1. Any access to the shadow region, doesn't need force wake
  412. * and windowing logic to access.
  413. * 2. Any access beyond BAR + 4K:
  414. * If init_phase enabled, no force wake is needed and access
  415. * should be based on windowed or unwindowed access.
  416. * If init_phase disabled, force wake is needed and access
  417. * should be based on windowed or unwindowed access.
  418. *
  419. * Return: < 0 for failure/>= 0 for success
  420. */
  421. static inline
  422. uint32_t hal_read32_mb(struct hal_soc *hal_soc, uint32_t offset)
  423. {
  424. uint32_t ret;
  425. unsigned long flags;
  426. qdf_iomem_t new_addr;
  427. if (!hal_soc->use_register_windowing ||
  428. offset < MAX_UNWINDOWED_ADDRESS) {
  429. return qdf_ioread32(hal_soc->dev_base_addr + offset);
  430. } else if (hal_soc->static_window_map) {
  431. new_addr = hal_get_window_address(hal_soc, hal_soc->dev_base_addr + offset);
  432. return qdf_ioread32(new_addr);
  433. }
  434. hal_lock_reg_access(hal_soc, &flags);
  435. hal_select_window(hal_soc, offset);
  436. ret = qdf_ioread32(hal_soc->dev_base_addr + WINDOW_START +
  437. (offset & WINDOW_RANGE_MASK));
  438. hal_unlock_reg_access(hal_soc, &flags);
  439. return ret;
  440. }
  441. #else
  442. static
  443. uint32_t hal_read32_mb(struct hal_soc *hal_soc, uint32_t offset)
  444. {
  445. uint32_t ret;
  446. unsigned long flags;
  447. qdf_iomem_t new_addr;
  448. /* Region < BAR + 4K can be directly accessed */
  449. if (offset < MAPPED_REF_OFF)
  450. return qdf_ioread32(hal_soc->dev_base_addr + offset);
  451. if ((!hal_soc->init_phase) &&
  452. hif_force_wake_request(hal_soc->hif_handle)) {
  453. hal_err("Wake up request failed");
  454. qdf_check_state_before_panic();
  455. return 0;
  456. }
  457. if (!hal_soc->use_register_windowing ||
  458. offset < MAX_UNWINDOWED_ADDRESS) {
  459. ret = qdf_ioread32(hal_soc->dev_base_addr + offset);
  460. } else if (hal_soc->static_window_map) {
  461. new_addr = hal_get_window_address(
  462. hal_soc,
  463. hal_soc->dev_base_addr + offset);
  464. ret = qdf_ioread32(new_addr);
  465. } else {
  466. hal_lock_reg_access(hal_soc, &flags);
  467. hal_select_window(hal_soc, offset);
  468. ret = qdf_ioread32(hal_soc->dev_base_addr + WINDOW_START +
  469. (offset & WINDOW_RANGE_MASK));
  470. hal_unlock_reg_access(hal_soc, &flags);
  471. }
  472. if ((!hal_soc->init_phase) &&
  473. hif_force_wake_release(hal_soc->hif_handle)) {
  474. hal_err("Wake up release failed");
  475. qdf_check_state_before_panic();
  476. return 0;
  477. }
  478. return ret;
  479. }
  480. #endif
  481. /**
  482. * hal_read_address_32_mb() - Read 32-bit value from the register
  483. * @soc: soc handle
  484. * @addr: register address to read
  485. *
  486. * Return: 32-bit value
  487. */
  488. static inline
  489. uint32_t hal_read_address_32_mb(struct hal_soc *soc,
  490. qdf_iomem_t addr)
  491. {
  492. uint32_t offset;
  493. uint32_t ret;
  494. if (!soc->use_register_windowing)
  495. return qdf_ioread32(addr);
  496. offset = addr - soc->dev_base_addr;
  497. ret = hal_read32_mb(soc, offset);
  498. return ret;
  499. }
  500. /**
  501. * hal_attach - Initialize HAL layer
  502. * @hif_handle: Opaque HIF handle
  503. * @qdf_dev: QDF device
  504. *
  505. * Return: Opaque HAL SOC handle
  506. * NULL on failure (if given ring is not available)
  507. *
  508. * This function should be called as part of HIF initialization (for accessing
  509. * copy engines). DP layer will get hal_soc handle using hif_get_hal_handle()
  510. */
  511. void *hal_attach(struct hif_opaque_softc *hif_handle, qdf_device_t qdf_dev);
  512. /**
  513. * hal_detach - Detach HAL layer
  514. * @hal_soc: HAL SOC handle
  515. *
  516. * This function should be called as part of HIF detach
  517. *
  518. */
  519. extern void hal_detach(void *hal_soc);
  520. /* SRNG type to be passed in APIs hal_srng_get_entrysize and hal_srng_setup */
  521. enum hal_ring_type {
  522. REO_DST = 0,
  523. REO_EXCEPTION = 1,
  524. REO_REINJECT = 2,
  525. REO_CMD = 3,
  526. REO_STATUS = 4,
  527. TCL_DATA = 5,
  528. TCL_CMD_CREDIT = 6,
  529. TCL_STATUS = 7,
  530. CE_SRC = 8,
  531. CE_DST = 9,
  532. CE_DST_STATUS = 10,
  533. WBM_IDLE_LINK = 11,
  534. SW2WBM_RELEASE = 12,
  535. WBM2SW_RELEASE = 13,
  536. RXDMA_BUF = 14,
  537. RXDMA_DST = 15,
  538. RXDMA_MONITOR_BUF = 16,
  539. RXDMA_MONITOR_STATUS = 17,
  540. RXDMA_MONITOR_DST = 18,
  541. RXDMA_MONITOR_DESC = 19,
  542. DIR_BUF_RX_DMA_SRC = 20,
  543. #ifdef WLAN_FEATURE_CIF_CFR
  544. WIFI_POS_SRC,
  545. #endif
  546. MAX_RING_TYPES
  547. };
  548. #define HAL_SRNG_LMAC_RING 0x80000000
  549. /* SRNG flags passed in hal_srng_params.flags */
  550. #define HAL_SRNG_MSI_SWAP 0x00000008
  551. #define HAL_SRNG_RING_PTR_SWAP 0x00000010
  552. #define HAL_SRNG_DATA_TLV_SWAP 0x00000020
  553. #define HAL_SRNG_LOW_THRES_INTR_ENABLE 0x00010000
  554. #define HAL_SRNG_MSI_INTR 0x00020000
  555. #define HAL_SRNG_CACHED_DESC 0x00040000
  556. #define PN_SIZE_24 0
  557. #define PN_SIZE_48 1
  558. #define PN_SIZE_128 2
  559. #ifdef FORCE_WAKE
  560. /**
  561. * hal_set_init_phase() - Indicate initialization of
  562. * datapath rings
  563. * @soc: hal_soc handle
  564. * @init_phase: flag to indicate datapath rings
  565. * initialization status
  566. *
  567. * Return: None
  568. */
  569. void hal_set_init_phase(hal_soc_handle_t soc, bool init_phase);
  570. #else
  571. static inline
  572. void hal_set_init_phase(hal_soc_handle_t soc, bool init_phase)
  573. {
  574. }
  575. #endif /* FORCE_WAKE */
  576. /**
  577. * hal_srng_get_entrysize - Returns size of ring entry in bytes. Should be
  578. * used by callers for calculating the size of memory to be allocated before
  579. * calling hal_srng_setup to setup the ring
  580. *
  581. * @hal_soc: Opaque HAL SOC handle
  582. * @ring_type: one of the types from hal_ring_type
  583. *
  584. */
  585. extern uint32_t hal_srng_get_entrysize(void *hal_soc, int ring_type);
  586. /**
  587. * hal_srng_max_entries - Returns maximum possible number of ring entries
  588. * @hal_soc: Opaque HAL SOC handle
  589. * @ring_type: one of the types from hal_ring_type
  590. *
  591. * Return: Maximum number of entries for the given ring_type
  592. */
  593. uint32_t hal_srng_max_entries(void *hal_soc, int ring_type);
  594. /**
  595. * hal_srng_dump - Dump ring status
  596. * @srng: hal srng pointer
  597. */
  598. void hal_srng_dump(struct hal_srng *srng);
  599. /**
  600. * hal_srng_get_dir - Returns the direction of the ring
  601. * @hal_soc: Opaque HAL SOC handle
  602. * @ring_type: one of the types from hal_ring_type
  603. *
  604. * Return: Ring direction
  605. */
  606. enum hal_srng_dir hal_srng_get_dir(void *hal_soc, int ring_type);
  607. /* HAL memory information */
  608. struct hal_mem_info {
  609. /* dev base virutal addr */
  610. void *dev_base_addr;
  611. /* dev base physical addr */
  612. void *dev_base_paddr;
  613. /* Remote virtual pointer memory for HW/FW updates */
  614. void *shadow_rdptr_mem_vaddr;
  615. /* Remote physical pointer memory for HW/FW updates */
  616. void *shadow_rdptr_mem_paddr;
  617. /* Shared memory for ring pointer updates from host to FW */
  618. void *shadow_wrptr_mem_vaddr;
  619. /* Shared physical memory for ring pointer updates from host to FW */
  620. void *shadow_wrptr_mem_paddr;
  621. };
  622. /* SRNG parameters to be passed to hal_srng_setup */
  623. struct hal_srng_params {
  624. /* Physical base address of the ring */
  625. qdf_dma_addr_t ring_base_paddr;
  626. /* Virtual base address of the ring */
  627. void *ring_base_vaddr;
  628. /* Number of entries in ring */
  629. uint32_t num_entries;
  630. /* max transfer length */
  631. uint16_t max_buffer_length;
  632. /* MSI Address */
  633. qdf_dma_addr_t msi_addr;
  634. /* MSI data */
  635. uint32_t msi_data;
  636. /* Interrupt timer threshold – in micro seconds */
  637. uint32_t intr_timer_thres_us;
  638. /* Interrupt batch counter threshold – in number of ring entries */
  639. uint32_t intr_batch_cntr_thres_entries;
  640. /* Low threshold – in number of ring entries
  641. * (valid for src rings only)
  642. */
  643. uint32_t low_threshold;
  644. /* Misc flags */
  645. uint32_t flags;
  646. /* Unique ring id */
  647. uint8_t ring_id;
  648. /* Source or Destination ring */
  649. enum hal_srng_dir ring_dir;
  650. /* Size of ring entry */
  651. uint32_t entry_size;
  652. /* hw register base address */
  653. void *hwreg_base[MAX_SRNG_REG_GROUPS];
  654. };
  655. /* hal_construct_shadow_config() - initialize the shadow registers for dp rings
  656. * @hal_soc: hal handle
  657. *
  658. * Return: QDF_STATUS_OK on success
  659. */
  660. extern QDF_STATUS hal_construct_shadow_config(void *hal_soc);
  661. /* hal_set_one_shadow_config() - add a config for the specified ring
  662. * @hal_soc: hal handle
  663. * @ring_type: ring type
  664. * @ring_num: ring num
  665. *
  666. * The ring type and ring num uniquely specify the ring. After this call,
  667. * the hp/tp will be added as the next entry int the shadow register
  668. * configuration table. The hal code will use the shadow register address
  669. * in place of the hp/tp address.
  670. *
  671. * This function is exposed, so that the CE module can skip configuring shadow
  672. * registers for unused ring and rings assigned to the firmware.
  673. *
  674. * Return: QDF_STATUS_OK on success
  675. */
  676. extern QDF_STATUS hal_set_one_shadow_config(void *hal_soc, int ring_type,
  677. int ring_num);
  678. /**
  679. * hal_get_shadow_config() - retrieve the config table
  680. * @hal_soc: hal handle
  681. * @shadow_config: will point to the table after
  682. * @num_shadow_registers_configured: will contain the number of valid entries
  683. */
  684. extern void hal_get_shadow_config(void *hal_soc,
  685. struct pld_shadow_reg_v2_cfg **shadow_config,
  686. int *num_shadow_registers_configured);
  687. /**
  688. * hal_srng_setup - Initialize HW SRNG ring.
  689. *
  690. * @hal_soc: Opaque HAL SOC handle
  691. * @ring_type: one of the types from hal_ring_type
  692. * @ring_num: Ring number if there are multiple rings of
  693. * same type (staring from 0)
  694. * @mac_id: valid MAC Id should be passed if ring type is one of lmac rings
  695. * @ring_params: SRNG ring params in hal_srng_params structure.
  696. * Callers are expected to allocate contiguous ring memory of size
  697. * 'num_entries * entry_size' bytes and pass the physical and virtual base
  698. * addresses through 'ring_base_paddr' and 'ring_base_vaddr' in hal_srng_params
  699. * structure. Ring base address should be 8 byte aligned and size of each ring
  700. * entry should be queried using the API hal_srng_get_entrysize
  701. *
  702. * Return: Opaque pointer to ring on success
  703. * NULL on failure (if given ring is not available)
  704. */
  705. extern void *hal_srng_setup(void *hal_soc, int ring_type, int ring_num,
  706. int mac_id, struct hal_srng_params *ring_params);
  707. /* Remapping ids of REO rings */
  708. #define REO_REMAP_TCL 0
  709. #define REO_REMAP_SW1 1
  710. #define REO_REMAP_SW2 2
  711. #define REO_REMAP_SW3 3
  712. #define REO_REMAP_SW4 4
  713. #define REO_REMAP_RELEASE 5
  714. #define REO_REMAP_FW 6
  715. #define REO_REMAP_UNUSED 7
  716. /*
  717. * Macro to access HWIO_REO_R0_DESTINATION_RING_CTRL_IX_0
  718. * to map destination to rings
  719. */
  720. #define HAL_REO_REMAP_IX0(_VALUE, _OFFSET) \
  721. ((_VALUE) << \
  722. (HWIO_REO_R0_DESTINATION_RING_CTRL_IX_0_DEST_RING_MAPPING_ ## \
  723. _OFFSET ## _SHFT))
  724. /*
  725. * Macro to access HWIO_REO_R0_DESTINATION_RING_CTRL_IX_1
  726. * to map destination to rings
  727. */
  728. #define HAL_REO_REMAP_IX2(_VALUE, _OFFSET) \
  729. ((_VALUE) << \
  730. (HWIO_REO_R0_DESTINATION_RING_CTRL_IX_2_DEST_RING_MAPPING_ ## \
  731. _OFFSET ## _SHFT))
  732. /*
  733. * Macro to access HWIO_REO_R0_DESTINATION_RING_CTRL_IX_3
  734. * to map destination to rings
  735. */
  736. #define HAL_REO_REMAP_IX3(_VALUE, _OFFSET) \
  737. ((_VALUE) << \
  738. (HWIO_REO_R0_DESTINATION_RING_CTRL_IX_3_DEST_RING_MAPPING_ ## \
  739. _OFFSET ## _SHFT))
  740. /**
  741. * hal_reo_read_write_ctrl_ix - Read or write REO_DESTINATION_RING_CTRL_IX
  742. * @hal_soc_hdl: HAL SOC handle
  743. * @read: boolean value to indicate if read or write
  744. * @ix0: pointer to store IX0 reg value
  745. * @ix1: pointer to store IX1 reg value
  746. * @ix2: pointer to store IX2 reg value
  747. * @ix3: pointer to store IX3 reg value
  748. */
  749. void hal_reo_read_write_ctrl_ix(hal_soc_handle_t hal_soc_hdl, bool read,
  750. uint32_t *ix0, uint32_t *ix1,
  751. uint32_t *ix2, uint32_t *ix3);
  752. /**
  753. * hal_srng_set_hp_paddr() - Set physical address to dest SRNG head pointer
  754. * @sring: sring pointer
  755. * @paddr: physical address
  756. */
  757. extern void hal_srng_dst_set_hp_paddr(struct hal_srng *sring, uint64_t paddr);
  758. /**
  759. * hal_srng_dst_init_hp() - Initilaize head pointer with cached head pointer
  760. * @srng: sring pointer
  761. * @vaddr: virtual address
  762. */
  763. extern void hal_srng_dst_init_hp(struct hal_srng *srng, uint32_t *vaddr);
  764. /**
  765. * hal_srng_cleanup - Deinitialize HW SRNG ring.
  766. * @hal_soc: Opaque HAL SOC handle
  767. * @hal_srng: Opaque HAL SRNG pointer
  768. */
  769. void hal_srng_cleanup(void *hal_soc, hal_ring_handle_t hal_ring_hdl);
  770. static inline bool hal_srng_initialized(hal_ring_handle_t hal_ring_hdl)
  771. {
  772. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  773. return !!srng->initialized;
  774. }
  775. /**
  776. * hal_srng_dst_peek - Check if there are any entries in the ring (peek)
  777. * @hal_soc: Opaque HAL SOC handle
  778. * @hal_ring_hdl: Destination ring pointer
  779. *
  780. * Caller takes responsibility for any locking needs.
  781. *
  782. * Return: Opaque pointer for next ring entry; NULL on failire
  783. */
  784. static inline
  785. void *hal_srng_dst_peek(hal_soc_handle_t hal_soc_hdl,
  786. hal_ring_handle_t hal_ring_hdl)
  787. {
  788. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  789. if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp)
  790. return (void *)(&srng->ring_base_vaddr[srng->u.dst_ring.tp]);
  791. return NULL;
  792. }
  793. /**
  794. * hal_srng_access_start_unlocked - Start ring access (unlocked). Should use
  795. * hal_srng_access_start if locked access is required
  796. *
  797. * @hal_soc: Opaque HAL SOC handle
  798. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  799. *
  800. * Return: 0 on success; error on failire
  801. */
  802. static inline int
  803. hal_srng_access_start_unlocked(hal_soc_handle_t hal_soc_hdl,
  804. hal_ring_handle_t hal_ring_hdl)
  805. {
  806. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  807. struct hal_soc *soc = (struct hal_soc *)hal_soc_hdl;
  808. uint32_t *desc;
  809. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  810. srng->u.src_ring.cached_tp =
  811. *(volatile uint32_t *)(srng->u.src_ring.tp_addr);
  812. else {
  813. srng->u.dst_ring.cached_hp =
  814. *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  815. if (srng->flags & HAL_SRNG_CACHED_DESC) {
  816. desc = hal_srng_dst_peek(hal_soc_hdl, hal_ring_hdl);
  817. if (qdf_likely(desc)) {
  818. qdf_mem_dma_cache_sync(soc->qdf_dev,
  819. qdf_mem_virt_to_phys
  820. (desc),
  821. QDF_DMA_FROM_DEVICE,
  822. (srng->entry_size *
  823. sizeof(uint32_t)));
  824. qdf_prefetch(desc);
  825. }
  826. }
  827. }
  828. return 0;
  829. }
  830. /**
  831. * hal_srng_access_start - Start (locked) ring access
  832. *
  833. * @hal_soc: Opaque HAL SOC handle
  834. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  835. *
  836. * Return: 0 on success; error on failire
  837. */
  838. static inline int hal_srng_access_start(hal_soc_handle_t hal_soc_hdl,
  839. hal_ring_handle_t hal_ring_hdl)
  840. {
  841. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  842. if (qdf_unlikely(!hal_ring_hdl)) {
  843. qdf_print("Error: Invalid hal_ring\n");
  844. return -EINVAL;
  845. }
  846. SRNG_LOCK(&(srng->lock));
  847. return hal_srng_access_start_unlocked(hal_soc_hdl, hal_ring_hdl);
  848. }
  849. /**
  850. * hal_srng_dst_get_next - Get next entry from a destination ring and move
  851. * cached tail pointer
  852. *
  853. * @hal_soc: Opaque HAL SOC handle
  854. * @hal_ring_hdl: Destination ring pointer
  855. *
  856. * Return: Opaque pointer for next ring entry; NULL on failire
  857. */
  858. static inline
  859. void *hal_srng_dst_get_next(void *hal_soc,
  860. hal_ring_handle_t hal_ring_hdl)
  861. {
  862. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  863. struct hal_soc *soc = (struct hal_soc *)hal_soc;
  864. uint32_t *desc;
  865. uint32_t *desc_next;
  866. uint32_t tp;
  867. if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp) {
  868. desc = &(srng->ring_base_vaddr[srng->u.dst_ring.tp]);
  869. /* TODO: Using % is expensive, but we have to do this since
  870. * size of some SRNG rings is not power of 2 (due to descriptor
  871. * sizes). Need to create separate API for rings used
  872. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  873. * SW2RXDMA and CE rings)
  874. */
  875. srng->u.dst_ring.tp = (srng->u.dst_ring.tp + srng->entry_size) %
  876. srng->ring_size;
  877. if (srng->flags & HAL_SRNG_CACHED_DESC) {
  878. tp = srng->u.dst_ring.tp;
  879. desc_next = &srng->ring_base_vaddr[tp];
  880. qdf_mem_dma_cache_sync(soc->qdf_dev,
  881. qdf_mem_virt_to_phys(desc_next),
  882. QDF_DMA_FROM_DEVICE,
  883. (srng->entry_size *
  884. sizeof(uint32_t)));
  885. qdf_prefetch(desc_next);
  886. }
  887. return (void *)desc;
  888. }
  889. return NULL;
  890. }
  891. /**
  892. * hal_srng_dst_get_next_hp - Get next entry from a destination ring and move
  893. * cached head pointer
  894. *
  895. * @hal_soc: Opaque HAL SOC handle
  896. * @hal_ring_hdl: Destination ring pointer
  897. *
  898. * Return: Opaque pointer for next ring entry; NULL on failire
  899. */
  900. static inline void *
  901. hal_srng_dst_get_next_hp(hal_soc_handle_t hal_soc_hdl,
  902. hal_ring_handle_t hal_ring_hdl)
  903. {
  904. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  905. uint32_t *desc;
  906. /* TODO: Using % is expensive, but we have to do this since
  907. * size of some SRNG rings is not power of 2 (due to descriptor
  908. * sizes). Need to create separate API for rings used
  909. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  910. * SW2RXDMA and CE rings)
  911. */
  912. uint32_t next_hp = (srng->u.dst_ring.cached_hp + srng->entry_size) %
  913. srng->ring_size;
  914. if (next_hp != srng->u.dst_ring.tp) {
  915. desc = &(srng->ring_base_vaddr[srng->u.dst_ring.cached_hp]);
  916. srng->u.dst_ring.cached_hp = next_hp;
  917. return (void *)desc;
  918. }
  919. return NULL;
  920. }
  921. /**
  922. * hal_srng_dst_peek_sync - Check if there are any entries in the ring (peek)
  923. * @hal_soc: Opaque HAL SOC handle
  924. * @hal_ring_hdl: Destination ring pointer
  925. *
  926. * Sync cached head pointer with HW.
  927. * Caller takes responsibility for any locking needs.
  928. *
  929. * Return: Opaque pointer for next ring entry; NULL on failire
  930. */
  931. static inline
  932. void *hal_srng_dst_peek_sync(hal_soc_handle_t hal_soc_hdl,
  933. hal_ring_handle_t hal_ring_hdl)
  934. {
  935. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  936. srng->u.dst_ring.cached_hp =
  937. *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  938. if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp)
  939. return (void *)(&(srng->ring_base_vaddr[srng->u.dst_ring.tp]));
  940. return NULL;
  941. }
  942. /**
  943. * hal_srng_dst_peek_sync_locked - Peek for any entries in the ring
  944. * @hal_soc: Opaque HAL SOC handle
  945. * @hal_ring_hdl: Destination ring pointer
  946. *
  947. * Sync cached head pointer with HW.
  948. * This function takes up SRNG_LOCK. Should not be called with SRNG lock held.
  949. *
  950. * Return: Opaque pointer for next ring entry; NULL on failire
  951. */
  952. static inline
  953. void *hal_srng_dst_peek_sync_locked(hal_soc_handle_t hal_soc_hdl,
  954. hal_ring_handle_t hal_ring_hdl)
  955. {
  956. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  957. void *ring_desc_ptr = NULL;
  958. if (qdf_unlikely(!hal_ring_hdl)) {
  959. qdf_print("Error: Invalid hal_ring\n");
  960. return NULL;
  961. }
  962. SRNG_LOCK(&srng->lock);
  963. ring_desc_ptr = hal_srng_dst_peek_sync(hal_soc_hdl, hal_ring_hdl);
  964. SRNG_UNLOCK(&srng->lock);
  965. return ring_desc_ptr;
  966. }
  967. /**
  968. * hal_srng_dst_num_valid - Returns number of valid entries (to be processed
  969. * by SW) in destination ring
  970. *
  971. * @hal_soc: Opaque HAL SOC handle
  972. * @hal_ring_hdl: Destination ring pointer
  973. * @sync_hw_ptr: Sync cached head pointer with HW
  974. *
  975. */
  976. static inline
  977. uint32_t hal_srng_dst_num_valid(void *hal_soc,
  978. hal_ring_handle_t hal_ring_hdl,
  979. int sync_hw_ptr)
  980. {
  981. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  982. uint32_t hp;
  983. uint32_t tp = srng->u.dst_ring.tp;
  984. if (sync_hw_ptr) {
  985. hp = *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  986. srng->u.dst_ring.cached_hp = hp;
  987. } else {
  988. hp = srng->u.dst_ring.cached_hp;
  989. }
  990. if (hp >= tp)
  991. return (hp - tp) / srng->entry_size;
  992. else
  993. return (srng->ring_size - tp + hp) / srng->entry_size;
  994. }
  995. /**
  996. * hal_srng_dst_num_valid_locked - Returns num valid entries to be processed
  997. *
  998. * @hal_soc: Opaque HAL SOC handle
  999. * @hal_ring_hdl: Destination ring pointer
  1000. * @sync_hw_ptr: Sync cached head pointer with HW
  1001. *
  1002. * Returns number of valid entries to be processed by the host driver. The
  1003. * function takes up SRNG lock.
  1004. *
  1005. * Return: Number of valid destination entries
  1006. */
  1007. static inline uint32_t
  1008. hal_srng_dst_num_valid_locked(hal_soc_handle_t hal_soc,
  1009. hal_ring_handle_t hal_ring_hdl,
  1010. int sync_hw_ptr)
  1011. {
  1012. uint32_t num_valid;
  1013. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1014. SRNG_LOCK(&srng->lock);
  1015. num_valid = hal_srng_dst_num_valid(hal_soc, hal_ring_hdl, sync_hw_ptr);
  1016. SRNG_UNLOCK(&srng->lock);
  1017. return num_valid;
  1018. }
  1019. /**
  1020. * hal_srng_src_reap_next - Reap next entry from a source ring and move reap
  1021. * pointer. This can be used to release any buffers associated with completed
  1022. * ring entries. Note that this should not be used for posting new descriptor
  1023. * entries. Posting of new entries should be done only using
  1024. * hal_srng_src_get_next_reaped when this function is used for reaping.
  1025. *
  1026. * @hal_soc: Opaque HAL SOC handle
  1027. * @hal_ring_hdl: Source ring pointer
  1028. *
  1029. * Return: Opaque pointer for next ring entry; NULL on failire
  1030. */
  1031. static inline void *
  1032. hal_srng_src_reap_next(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1033. {
  1034. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1035. uint32_t *desc;
  1036. /* TODO: Using % is expensive, but we have to do this since
  1037. * size of some SRNG rings is not power of 2 (due to descriptor
  1038. * sizes). Need to create separate API for rings used
  1039. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1040. * SW2RXDMA and CE rings)
  1041. */
  1042. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  1043. srng->ring_size;
  1044. if (next_reap_hp != srng->u.src_ring.cached_tp) {
  1045. desc = &(srng->ring_base_vaddr[next_reap_hp]);
  1046. srng->u.src_ring.reap_hp = next_reap_hp;
  1047. return (void *)desc;
  1048. }
  1049. return NULL;
  1050. }
  1051. /**
  1052. * hal_srng_src_get_next_reaped - Get next entry from a source ring that is
  1053. * already reaped using hal_srng_src_reap_next, for posting new entries to
  1054. * the ring
  1055. *
  1056. * @hal_soc: Opaque HAL SOC handle
  1057. * @hal_ring_hdl: Source ring pointer
  1058. *
  1059. * Return: Opaque pointer for next (reaped) source ring entry; NULL on failire
  1060. */
  1061. static inline void *
  1062. hal_srng_src_get_next_reaped(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1063. {
  1064. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1065. uint32_t *desc;
  1066. if (srng->u.src_ring.hp != srng->u.src_ring.reap_hp) {
  1067. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  1068. srng->u.src_ring.hp = (srng->u.src_ring.hp + srng->entry_size) %
  1069. srng->ring_size;
  1070. return (void *)desc;
  1071. }
  1072. return NULL;
  1073. }
  1074. /**
  1075. * hal_srng_src_pending_reap_next - Reap next entry from a source ring and
  1076. * move reap pointer. This API is used in detach path to release any buffers
  1077. * associated with ring entries which are pending reap.
  1078. *
  1079. * @hal_soc: Opaque HAL SOC handle
  1080. * @hal_ring_hdl: Source ring pointer
  1081. *
  1082. * Return: Opaque pointer for next ring entry; NULL on failire
  1083. */
  1084. static inline void *
  1085. hal_srng_src_pending_reap_next(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1086. {
  1087. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1088. uint32_t *desc;
  1089. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  1090. srng->ring_size;
  1091. if (next_reap_hp != srng->u.src_ring.hp) {
  1092. desc = &(srng->ring_base_vaddr[next_reap_hp]);
  1093. srng->u.src_ring.reap_hp = next_reap_hp;
  1094. return (void *)desc;
  1095. }
  1096. return NULL;
  1097. }
  1098. /**
  1099. * hal_srng_src_done_val -
  1100. *
  1101. * @hal_soc: Opaque HAL SOC handle
  1102. * @hal_ring_hdl: Source ring pointer
  1103. *
  1104. * Return: Opaque pointer for next ring entry; NULL on failire
  1105. */
  1106. static inline uint32_t
  1107. hal_srng_src_done_val(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1108. {
  1109. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1110. /* TODO: Using % is expensive, but we have to do this since
  1111. * size of some SRNG rings is not power of 2 (due to descriptor
  1112. * sizes). Need to create separate API for rings used
  1113. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1114. * SW2RXDMA and CE rings)
  1115. */
  1116. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  1117. srng->ring_size;
  1118. if (next_reap_hp == srng->u.src_ring.cached_tp)
  1119. return 0;
  1120. if (srng->u.src_ring.cached_tp > next_reap_hp)
  1121. return (srng->u.src_ring.cached_tp - next_reap_hp) /
  1122. srng->entry_size;
  1123. else
  1124. return ((srng->ring_size - next_reap_hp) +
  1125. srng->u.src_ring.cached_tp) / srng->entry_size;
  1126. }
  1127. /**
  1128. * hal_get_entrysize_from_srng() - Retrieve ring entry size
  1129. * @hal_ring_hdl: Source ring pointer
  1130. *
  1131. * Return: uint8_t
  1132. */
  1133. static inline
  1134. uint8_t hal_get_entrysize_from_srng(hal_ring_handle_t hal_ring_hdl)
  1135. {
  1136. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1137. return srng->entry_size;
  1138. }
  1139. /**
  1140. * hal_get_sw_hptp - Get SW head and tail pointer location for any ring
  1141. * @hal_soc: Opaque HAL SOC handle
  1142. * @hal_ring_hdl: Source ring pointer
  1143. * @tailp: Tail Pointer
  1144. * @headp: Head Pointer
  1145. *
  1146. * Return: Update tail pointer and head pointer in arguments.
  1147. */
  1148. static inline
  1149. void hal_get_sw_hptp(void *hal_soc, hal_ring_handle_t hal_ring_hdl,
  1150. uint32_t *tailp, uint32_t *headp)
  1151. {
  1152. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1153. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1154. *headp = srng->u.src_ring.hp;
  1155. *tailp = *srng->u.src_ring.tp_addr;
  1156. } else {
  1157. *tailp = srng->u.dst_ring.tp;
  1158. *headp = *srng->u.dst_ring.hp_addr;
  1159. }
  1160. }
  1161. /**
  1162. * hal_srng_src_get_next - Get next entry from a source ring and move cached tail pointer
  1163. *
  1164. * @hal_soc: Opaque HAL SOC handle
  1165. * @hal_ring_hdl: Source ring pointer
  1166. *
  1167. * Return: Opaque pointer for next ring entry; NULL on failire
  1168. */
  1169. static inline
  1170. void *hal_srng_src_get_next(void *hal_soc,
  1171. hal_ring_handle_t hal_ring_hdl)
  1172. {
  1173. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1174. uint32_t *desc;
  1175. /* TODO: Using % is expensive, but we have to do this since
  1176. * size of some SRNG rings is not power of 2 (due to descriptor
  1177. * sizes). Need to create separate API for rings used
  1178. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1179. * SW2RXDMA and CE rings)
  1180. */
  1181. uint32_t next_hp = (srng->u.src_ring.hp + srng->entry_size) %
  1182. srng->ring_size;
  1183. if (next_hp != srng->u.src_ring.cached_tp) {
  1184. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  1185. srng->u.src_ring.hp = next_hp;
  1186. /* TODO: Since reap function is not used by all rings, we can
  1187. * remove the following update of reap_hp in this function
  1188. * if we can ensure that only hal_srng_src_get_next_reaped
  1189. * is used for the rings requiring reap functionality
  1190. */
  1191. srng->u.src_ring.reap_hp = next_hp;
  1192. return (void *)desc;
  1193. }
  1194. return NULL;
  1195. }
  1196. /**
  1197. * hal_srng_src_peek_n_get_next - Get next entry from a ring without
  1198. * moving head pointer.
  1199. * hal_srng_src_get_next should be called subsequently to move the head pointer
  1200. *
  1201. * @hal_soc: Opaque HAL SOC handle
  1202. * @hal_ring_hdl: Source ring pointer
  1203. *
  1204. * Return: Opaque pointer for next ring entry; NULL on failire
  1205. */
  1206. static inline
  1207. void *hal_srng_src_peek_n_get_next(hal_soc_handle_t hal_soc_hdl,
  1208. hal_ring_handle_t hal_ring_hdl)
  1209. {
  1210. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1211. uint32_t *desc;
  1212. /* TODO: Using % is expensive, but we have to do this since
  1213. * size of some SRNG rings is not power of 2 (due to descriptor
  1214. * sizes). Need to create separate API for rings used
  1215. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1216. * SW2RXDMA and CE rings)
  1217. */
  1218. if (((srng->u.src_ring.hp + srng->entry_size) %
  1219. srng->ring_size) != srng->u.src_ring.cached_tp) {
  1220. desc = &(srng->ring_base_vaddr[(srng->u.src_ring.hp +
  1221. srng->entry_size) %
  1222. srng->ring_size]);
  1223. return (void *)desc;
  1224. }
  1225. return NULL;
  1226. }
  1227. /**
  1228. * hal_srng_src_get_cur_hp_n_move_next () - API returns current hp
  1229. * and move hp to next in src ring
  1230. *
  1231. * Usage: This API should only be used at init time replenish.
  1232. *
  1233. * @hal_soc_hdl: HAL soc handle
  1234. * @hal_ring_hdl: Source ring pointer
  1235. *
  1236. */
  1237. static inline void *
  1238. hal_srng_src_get_cur_hp_n_move_next(hal_soc_handle_t hal_soc_hdl,
  1239. hal_ring_handle_t hal_ring_hdl)
  1240. {
  1241. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1242. uint32_t *cur_desc = NULL;
  1243. uint32_t next_hp;
  1244. cur_desc = &srng->ring_base_vaddr[(srng->u.src_ring.hp)];
  1245. next_hp = (srng->u.src_ring.hp + srng->entry_size) %
  1246. srng->ring_size;
  1247. if (next_hp != srng->u.src_ring.cached_tp)
  1248. srng->u.src_ring.hp = next_hp;
  1249. return (void *)cur_desc;
  1250. }
  1251. /**
  1252. * hal_srng_src_num_avail - Returns number of available entries in src ring
  1253. *
  1254. * @hal_soc: Opaque HAL SOC handle
  1255. * @hal_ring_hdl: Source ring pointer
  1256. * @sync_hw_ptr: Sync cached tail pointer with HW
  1257. *
  1258. */
  1259. static inline uint32_t
  1260. hal_srng_src_num_avail(void *hal_soc,
  1261. hal_ring_handle_t hal_ring_hdl, int sync_hw_ptr)
  1262. {
  1263. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1264. uint32_t tp;
  1265. uint32_t hp = srng->u.src_ring.hp;
  1266. if (sync_hw_ptr) {
  1267. tp = *(srng->u.src_ring.tp_addr);
  1268. srng->u.src_ring.cached_tp = tp;
  1269. } else {
  1270. tp = srng->u.src_ring.cached_tp;
  1271. }
  1272. if (tp > hp)
  1273. return ((tp - hp) / srng->entry_size) - 1;
  1274. else
  1275. return ((srng->ring_size - hp + tp) / srng->entry_size) - 1;
  1276. }
  1277. /**
  1278. * hal_srng_access_end_unlocked - End ring access (unlocked) - update cached
  1279. * ring head/tail pointers to HW.
  1280. * This should be used only if hal_srng_access_start_unlocked to start ring
  1281. * access
  1282. *
  1283. * @hal_soc: Opaque HAL SOC handle
  1284. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1285. *
  1286. * Return: 0 on success; error on failire
  1287. */
  1288. static inline void
  1289. hal_srng_access_end_unlocked(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1290. {
  1291. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1292. /* TODO: See if we need a write memory barrier here */
  1293. if (srng->flags & HAL_SRNG_LMAC_RING) {
  1294. /* For LMAC rings, ring pointer updates are done through FW and
  1295. * hence written to a shared memory location that is read by FW
  1296. */
  1297. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1298. *(srng->u.src_ring.hp_addr) = srng->u.src_ring.hp;
  1299. } else {
  1300. *(srng->u.dst_ring.tp_addr) = srng->u.dst_ring.tp;
  1301. }
  1302. } else {
  1303. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  1304. hal_srng_write_address_32_mb(hal_soc,
  1305. srng->u.src_ring.hp_addr,
  1306. srng->u.src_ring.hp);
  1307. else
  1308. hal_srng_write_address_32_mb(hal_soc,
  1309. srng->u.dst_ring.tp_addr,
  1310. srng->u.dst_ring.tp);
  1311. }
  1312. }
  1313. /**
  1314. * hal_srng_access_end - Unlock ring access and update cached ring head/tail
  1315. * pointers to HW
  1316. * This should be used only if hal_srng_access_start to start ring access
  1317. *
  1318. * @hal_soc: Opaque HAL SOC handle
  1319. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1320. *
  1321. * Return: 0 on success; error on failire
  1322. */
  1323. static inline void
  1324. hal_srng_access_end(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1325. {
  1326. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1327. if (qdf_unlikely(!hal_ring_hdl)) {
  1328. qdf_print("Error: Invalid hal_ring\n");
  1329. return;
  1330. }
  1331. hal_srng_access_end_unlocked(hal_soc, hal_ring_hdl);
  1332. SRNG_UNLOCK(&(srng->lock));
  1333. }
  1334. /**
  1335. * hal_srng_access_end_reap - Unlock ring access
  1336. * This should be used only if hal_srng_access_start to start ring access
  1337. * and should be used only while reaping SRC ring completions
  1338. *
  1339. * @hal_soc: Opaque HAL SOC handle
  1340. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1341. *
  1342. * Return: 0 on success; error on failire
  1343. */
  1344. static inline void
  1345. hal_srng_access_end_reap(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1346. {
  1347. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1348. SRNG_UNLOCK(&(srng->lock));
  1349. }
  1350. /* TODO: Check if the following definitions is available in HW headers */
  1351. #define WBM_IDLE_SCATTER_BUF_SIZE 32704
  1352. #define NUM_MPDUS_PER_LINK_DESC 6
  1353. #define NUM_MSDUS_PER_LINK_DESC 7
  1354. #define REO_QUEUE_DESC_ALIGN 128
  1355. #define LINK_DESC_ALIGN 128
  1356. #define ADDRESS_MATCH_TAG_VAL 0x5
  1357. /* Number of mpdu link pointers is 9 in case of TX_MPDU_QUEUE_HEAD and 14 in
  1358. * of TX_MPDU_QUEUE_EXT. We are defining a common average count here
  1359. */
  1360. #define NUM_MPDU_LINKS_PER_QUEUE_DESC 12
  1361. /* TODO: Check with HW team on the scatter buffer size supported. As per WBM
  1362. * MLD, scatter_buffer_size in IDLE_LIST_CONTROL register is 9 bits and size
  1363. * should be specified in 16 word units. But the number of bits defined for
  1364. * this field in HW header files is 5.
  1365. */
  1366. #define WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE 8
  1367. /**
  1368. * hal_idle_list_scatter_buf_size - Get the size of each scatter buffer
  1369. * in an idle list
  1370. *
  1371. * @hal_soc: Opaque HAL SOC handle
  1372. *
  1373. */
  1374. static inline
  1375. uint32_t hal_idle_list_scatter_buf_size(hal_soc_handle_t hal_soc_hdl)
  1376. {
  1377. return WBM_IDLE_SCATTER_BUF_SIZE;
  1378. }
  1379. /**
  1380. * hal_get_link_desc_size - Get the size of each link descriptor
  1381. *
  1382. * @hal_soc: Opaque HAL SOC handle
  1383. *
  1384. */
  1385. static inline uint32_t hal_get_link_desc_size(hal_soc_handle_t hal_soc_hdl)
  1386. {
  1387. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  1388. if (!hal_soc || !hal_soc->ops) {
  1389. qdf_print("Error: Invalid ops\n");
  1390. QDF_BUG(0);
  1391. return -EINVAL;
  1392. }
  1393. if (!hal_soc->ops->hal_get_link_desc_size) {
  1394. qdf_print("Error: Invalid function pointer\n");
  1395. QDF_BUG(0);
  1396. return -EINVAL;
  1397. }
  1398. return hal_soc->ops->hal_get_link_desc_size();
  1399. }
  1400. /**
  1401. * hal_get_link_desc_align - Get the required start address alignment for
  1402. * link descriptors
  1403. *
  1404. * @hal_soc: Opaque HAL SOC handle
  1405. *
  1406. */
  1407. static inline
  1408. uint32_t hal_get_link_desc_align(hal_soc_handle_t hal_soc_hdl)
  1409. {
  1410. return LINK_DESC_ALIGN;
  1411. }
  1412. /**
  1413. * hal_num_mpdus_per_link_desc - Get number of mpdus each link desc can hold
  1414. *
  1415. * @hal_soc: Opaque HAL SOC handle
  1416. *
  1417. */
  1418. static inline
  1419. uint32_t hal_num_mpdus_per_link_desc(hal_soc_handle_t hal_soc_hdl)
  1420. {
  1421. return NUM_MPDUS_PER_LINK_DESC;
  1422. }
  1423. /**
  1424. * hal_num_msdus_per_link_desc - Get number of msdus each link desc can hold
  1425. *
  1426. * @hal_soc: Opaque HAL SOC handle
  1427. *
  1428. */
  1429. static inline
  1430. uint32_t hal_num_msdus_per_link_desc(hal_soc_handle_t hal_soc_hdl)
  1431. {
  1432. return NUM_MSDUS_PER_LINK_DESC;
  1433. }
  1434. /**
  1435. * hal_num_mpdu_links_per_queue_desc - Get number of mpdu links each queue
  1436. * descriptor can hold
  1437. *
  1438. * @hal_soc: Opaque HAL SOC handle
  1439. *
  1440. */
  1441. static inline
  1442. uint32_t hal_num_mpdu_links_per_queue_desc(hal_soc_handle_t hal_soc_hdl)
  1443. {
  1444. return NUM_MPDU_LINKS_PER_QUEUE_DESC;
  1445. }
  1446. /**
  1447. * hal_idle_list_scatter_buf_num_entries - Get the number of link desc entries
  1448. * that the given buffer size
  1449. *
  1450. * @hal_soc: Opaque HAL SOC handle
  1451. * @scatter_buf_size: Size of scatter buffer
  1452. *
  1453. */
  1454. static inline
  1455. uint32_t hal_idle_scatter_buf_num_entries(hal_soc_handle_t hal_soc_hdl,
  1456. uint32_t scatter_buf_size)
  1457. {
  1458. return (scatter_buf_size - WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE) /
  1459. hal_srng_get_entrysize(hal_soc_hdl, WBM_IDLE_LINK);
  1460. }
  1461. /**
  1462. * hal_idle_list_num_scatter_bufs - Get the number of sctater buffer
  1463. * each given buffer size
  1464. *
  1465. * @hal_soc: Opaque HAL SOC handle
  1466. * @total_mem: size of memory to be scattered
  1467. * @scatter_buf_size: Size of scatter buffer
  1468. *
  1469. */
  1470. static inline
  1471. uint32_t hal_idle_list_num_scatter_bufs(hal_soc_handle_t hal_soc_hdl,
  1472. uint32_t total_mem,
  1473. uint32_t scatter_buf_size)
  1474. {
  1475. uint8_t rem = (total_mem % (scatter_buf_size -
  1476. WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE)) ? 1 : 0;
  1477. uint32_t num_scatter_bufs = (total_mem / (scatter_buf_size -
  1478. WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE)) + rem;
  1479. return num_scatter_bufs;
  1480. }
  1481. enum hal_pn_type {
  1482. HAL_PN_NONE,
  1483. HAL_PN_WPA,
  1484. HAL_PN_WAPI_EVEN,
  1485. HAL_PN_WAPI_UNEVEN,
  1486. };
  1487. #define HAL_RX_MAX_BA_WINDOW 256
  1488. /**
  1489. * hal_get_reo_qdesc_align - Get start address alignment for reo
  1490. * queue descriptors
  1491. *
  1492. * @hal_soc: Opaque HAL SOC handle
  1493. *
  1494. */
  1495. static inline
  1496. uint32_t hal_get_reo_qdesc_align(hal_soc_handle_t hal_soc_hdl)
  1497. {
  1498. return REO_QUEUE_DESC_ALIGN;
  1499. }
  1500. /**
  1501. * hal_reo_qdesc_setup - Setup HW REO queue descriptor
  1502. *
  1503. * @hal_soc: Opaque HAL SOC handle
  1504. * @ba_window_size: BlockAck window size
  1505. * @start_seq: Starting sequence number
  1506. * @hw_qdesc_vaddr: Virtual address of REO queue descriptor memory
  1507. * @hw_qdesc_paddr: Physical address of REO queue descriptor memory
  1508. * @pn_type: PN type (one of the types defined in 'enum hal_pn_type')
  1509. *
  1510. */
  1511. void hal_reo_qdesc_setup(hal_soc_handle_t hal_soc_hdl,
  1512. int tid, uint32_t ba_window_size,
  1513. uint32_t start_seq, void *hw_qdesc_vaddr,
  1514. qdf_dma_addr_t hw_qdesc_paddr,
  1515. int pn_type);
  1516. /**
  1517. * hal_srng_get_hp_addr - Get head pointer physical address
  1518. *
  1519. * @hal_soc: Opaque HAL SOC handle
  1520. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1521. *
  1522. */
  1523. static inline qdf_dma_addr_t
  1524. hal_srng_get_hp_addr(void *hal_soc,
  1525. hal_ring_handle_t hal_ring_hdl)
  1526. {
  1527. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1528. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  1529. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1530. return hal->shadow_wrptr_mem_paddr +
  1531. ((unsigned long)(srng->u.src_ring.hp_addr) -
  1532. (unsigned long)(hal->shadow_wrptr_mem_vaddr));
  1533. } else {
  1534. return hal->shadow_rdptr_mem_paddr +
  1535. ((unsigned long)(srng->u.dst_ring.hp_addr) -
  1536. (unsigned long)(hal->shadow_rdptr_mem_vaddr));
  1537. }
  1538. }
  1539. /**
  1540. * hal_srng_get_tp_addr - Get tail 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_tp_addr(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1548. {
  1549. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1550. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  1551. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1552. return hal->shadow_rdptr_mem_paddr +
  1553. ((unsigned long)(srng->u.src_ring.tp_addr) -
  1554. (unsigned long)(hal->shadow_rdptr_mem_vaddr));
  1555. } else {
  1556. return hal->shadow_wrptr_mem_paddr +
  1557. ((unsigned long)(srng->u.dst_ring.tp_addr) -
  1558. (unsigned long)(hal->shadow_wrptr_mem_vaddr));
  1559. }
  1560. }
  1561. /**
  1562. * hal_srng_get_num_entries - Get total entries in the HAL Srng
  1563. *
  1564. * @hal_soc: Opaque HAL SOC handle
  1565. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1566. *
  1567. * Return: total number of entries in hal ring
  1568. */
  1569. static inline
  1570. uint32_t hal_srng_get_num_entries(hal_soc_handle_t hal_soc_hdl,
  1571. hal_ring_handle_t hal_ring_hdl)
  1572. {
  1573. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1574. return srng->num_entries;
  1575. }
  1576. /**
  1577. * hal_get_srng_params - Retrieve SRNG parameters for a given ring from HAL
  1578. *
  1579. * @hal_soc: Opaque HAL SOC handle
  1580. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1581. * @ring_params: SRNG parameters will be returned through this structure
  1582. */
  1583. void hal_get_srng_params(hal_soc_handle_t hal_soc_hdl,
  1584. hal_ring_handle_t hal_ring_hdl,
  1585. struct hal_srng_params *ring_params);
  1586. /**
  1587. * hal_mem_info - Retrieve hal memory base address
  1588. *
  1589. * @hal_soc: Opaque HAL SOC handle
  1590. * @mem: pointer to structure to be updated with hal mem info
  1591. */
  1592. void hal_get_meminfo(hal_soc_handle_t hal_soc_hdl, struct hal_mem_info *mem);
  1593. /**
  1594. * hal_get_target_type - Return target type
  1595. *
  1596. * @hal_soc: Opaque HAL SOC handle
  1597. */
  1598. uint32_t hal_get_target_type(hal_soc_handle_t hal_soc_hdl);
  1599. /**
  1600. * hal_get_ba_aging_timeout - Retrieve BA aging timeout
  1601. *
  1602. * @hal_soc: Opaque HAL SOC handle
  1603. * @ac: Access category
  1604. * @value: timeout duration in millisec
  1605. */
  1606. void hal_get_ba_aging_timeout(hal_soc_handle_t hal_soc_hdl, uint8_t ac,
  1607. uint32_t *value);
  1608. /**
  1609. * hal_set_aging_timeout - Set BA aging timeout
  1610. *
  1611. * @hal_soc: Opaque HAL SOC handle
  1612. * @ac: Access category in millisec
  1613. * @value: timeout duration value
  1614. */
  1615. void hal_set_ba_aging_timeout(hal_soc_handle_t hal_soc_hdl, uint8_t ac,
  1616. uint32_t value);
  1617. /**
  1618. * hal_srng_dst_hw_init - Private function to initialize SRNG
  1619. * destination ring HW
  1620. * @hal_soc: HAL SOC handle
  1621. * @srng: SRNG ring pointer
  1622. */
  1623. static inline void hal_srng_dst_hw_init(struct hal_soc *hal,
  1624. struct hal_srng *srng)
  1625. {
  1626. hal->ops->hal_srng_dst_hw_init(hal, srng);
  1627. }
  1628. /**
  1629. * hal_srng_src_hw_init - Private function to initialize SRNG
  1630. * source ring HW
  1631. * @hal_soc: HAL SOC handle
  1632. * @srng: SRNG ring pointer
  1633. */
  1634. static inline void hal_srng_src_hw_init(struct hal_soc *hal,
  1635. struct hal_srng *srng)
  1636. {
  1637. hal->ops->hal_srng_src_hw_init(hal, srng);
  1638. }
  1639. /**
  1640. * hal_get_hw_hptp() - Get HW head and tail pointer value for any ring
  1641. * @hal_soc: Opaque HAL SOC handle
  1642. * @hal_ring_hdl: Source ring pointer
  1643. * @headp: Head Pointer
  1644. * @tailp: Tail Pointer
  1645. * @ring_type: Ring
  1646. *
  1647. * Return: Update tail pointer and head pointer in arguments.
  1648. */
  1649. static inline
  1650. void hal_get_hw_hptp(hal_soc_handle_t hal_soc_hdl,
  1651. hal_ring_handle_t hal_ring_hdl,
  1652. uint32_t *headp, uint32_t *tailp,
  1653. uint8_t ring_type)
  1654. {
  1655. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  1656. hal_soc->ops->hal_get_hw_hptp(hal_soc, hal_ring_hdl,
  1657. headp, tailp, ring_type);
  1658. }
  1659. /**
  1660. * hal_reo_setup - Initialize HW REO block
  1661. *
  1662. * @hal_soc: Opaque HAL SOC handle
  1663. * @reo_params: parameters needed by HAL for REO config
  1664. */
  1665. static inline void hal_reo_setup(hal_soc_handle_t hal_soc_hdl,
  1666. void *reoparams)
  1667. {
  1668. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  1669. hal_soc->ops->hal_reo_setup(hal_soc, reoparams);
  1670. }
  1671. /**
  1672. * hal_setup_link_idle_list - Setup scattered idle list using the
  1673. * buffer list provided
  1674. *
  1675. * @hal_soc: Opaque HAL SOC handle
  1676. * @scatter_bufs_base_paddr: Array of physical base addresses
  1677. * @scatter_bufs_base_vaddr: Array of virtual base addresses
  1678. * @num_scatter_bufs: Number of scatter buffers in the above lists
  1679. * @scatter_buf_size: Size of each scatter buffer
  1680. * @last_buf_end_offset: Offset to the last entry
  1681. * @num_entries: Total entries of all scatter bufs
  1682. *
  1683. */
  1684. static inline
  1685. void hal_setup_link_idle_list(hal_soc_handle_t hal_soc_hdl,
  1686. qdf_dma_addr_t scatter_bufs_base_paddr[],
  1687. void *scatter_bufs_base_vaddr[],
  1688. uint32_t num_scatter_bufs,
  1689. uint32_t scatter_buf_size,
  1690. uint32_t last_buf_end_offset,
  1691. uint32_t num_entries)
  1692. {
  1693. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  1694. hal_soc->ops->hal_setup_link_idle_list(hal_soc, scatter_bufs_base_paddr,
  1695. scatter_bufs_base_vaddr, num_scatter_bufs,
  1696. scatter_buf_size, last_buf_end_offset,
  1697. num_entries);
  1698. }
  1699. /**
  1700. * hal_srng_dump_ring_desc() - Dump ring descriptor info
  1701. *
  1702. * @hal_soc: Opaque HAL SOC handle
  1703. * @hal_ring_hdl: Source ring pointer
  1704. * @ring_desc: Opaque ring descriptor handle
  1705. */
  1706. static inline void hal_srng_dump_ring_desc(hal_soc_handle_t hal_soc_hdl,
  1707. hal_ring_handle_t hal_ring_hdl,
  1708. hal_ring_desc_t ring_desc)
  1709. {
  1710. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1711. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_HIGH,
  1712. ring_desc, (srng->entry_size << 2));
  1713. }
  1714. /**
  1715. * hal_srng_dump_ring() - Dump last 128 descs of the ring
  1716. *
  1717. * @hal_soc: Opaque HAL SOC handle
  1718. * @hal_ring_hdl: Source ring pointer
  1719. */
  1720. static inline void hal_srng_dump_ring(hal_soc_handle_t hal_soc_hdl,
  1721. hal_ring_handle_t hal_ring_hdl)
  1722. {
  1723. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1724. uint32_t *desc;
  1725. uint32_t tp, i;
  1726. tp = srng->u.dst_ring.tp;
  1727. for (i = 0; i < 128; i++) {
  1728. if (!tp)
  1729. tp = srng->ring_size;
  1730. desc = &srng->ring_base_vaddr[tp - srng->entry_size];
  1731. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_DP,
  1732. QDF_TRACE_LEVEL_DEBUG,
  1733. desc, (srng->entry_size << 2));
  1734. tp -= srng->entry_size;
  1735. }
  1736. }
  1737. /*
  1738. * hal_rxdma_desc_to_hal_ring_desc - API to convert rxdma ring desc
  1739. * to opaque dp_ring desc type
  1740. * @ring_desc - rxdma ring desc
  1741. *
  1742. * Return: hal_rxdma_desc_t type
  1743. */
  1744. static inline
  1745. hal_ring_desc_t hal_rxdma_desc_to_hal_ring_desc(hal_rxdma_desc_t ring_desc)
  1746. {
  1747. return (hal_ring_desc_t)ring_desc;
  1748. }
  1749. /**
  1750. * hal_srng_set_event() - Set hal_srng event
  1751. * @hal_ring_hdl: Source ring pointer
  1752. * @event: SRNG ring event
  1753. *
  1754. * Return: None
  1755. */
  1756. static inline void hal_srng_set_event(hal_ring_handle_t hal_ring_hdl, int event)
  1757. {
  1758. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1759. qdf_atomic_set_bit(event, &srng->srng_event);
  1760. }
  1761. /**
  1762. * hal_srng_clear_event() - Clear hal_srng event
  1763. * @hal_ring_hdl: Source ring pointer
  1764. * @event: SRNG ring event
  1765. *
  1766. * Return: None
  1767. */
  1768. static inline
  1769. void hal_srng_clear_event(hal_ring_handle_t hal_ring_hdl, int event)
  1770. {
  1771. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1772. qdf_atomic_clear_bit(event, &srng->srng_event);
  1773. }
  1774. /**
  1775. * hal_srng_get_clear_event() - Clear srng event and return old value
  1776. * @hal_ring_hdl: Source ring pointer
  1777. * @event: SRNG ring event
  1778. *
  1779. * Return: Return old event value
  1780. */
  1781. static inline
  1782. int hal_srng_get_clear_event(hal_ring_handle_t hal_ring_hdl, int event)
  1783. {
  1784. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1785. return qdf_atomic_test_and_clear_bit(event, &srng->srng_event);
  1786. }
  1787. /**
  1788. * hal_srng_set_flush_last_ts() - Record last flush time stamp
  1789. * @hal_ring_hdl: Source ring pointer
  1790. *
  1791. * Return: None
  1792. */
  1793. static inline void hal_srng_set_flush_last_ts(hal_ring_handle_t hal_ring_hdl)
  1794. {
  1795. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1796. srng->last_flush_ts = qdf_get_log_timestamp();
  1797. }
  1798. /**
  1799. * hal_srng_inc_flush_cnt() - Increment flush counter
  1800. * @hal_ring_hdl: Source ring pointer
  1801. *
  1802. * Return: None
  1803. */
  1804. static inline void hal_srng_inc_flush_cnt(hal_ring_handle_t hal_ring_hdl)
  1805. {
  1806. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1807. srng->flush_count++;
  1808. }
  1809. #endif /* _HAL_APIH_ */