hal_srng.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945
  1. /*
  2. * Copyright (c) 2016, The Linux Foundation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above
  10. * copyright notice, this list of conditions and the following
  11. * disclaimer in the documentation and/or other materials provided
  12. * with the distribution.
  13. * * Neither the name of The Linux Foundation nor the names of its
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  21. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  24. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  25. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  26. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  27. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #include "hw/reg_header/wcss/wcss_seq_hwiobase.h"
  30. #include "hw/reg_header/wcss/wcss_seq_hwioreg.h"
  31. #include "hw/data/common/sw_xml_headers.h"
  32. #include "hw/data/datastruct/reo_destination_ring.h"
  33. #include "hw/data/tlv_32/tcl_data_cmd.h"
  34. #include "hw/data/common/tlv_hdr.h"
  35. #include "hal_api.h"
  36. /**
  37. * Common SRNG register access macros:
  38. * The SRNG registers are distributed accross various UMAC and LMAC HW blocks,
  39. * but the register group and format is exactly same for all rings, with some
  40. * difference between producer rings (these are 'producer rings' with respect
  41. * to HW and refered as 'destination rings' in SW) and consumer rings (these
  42. * are 'consumer rings' with respect to HW and refered as 'source rings' in SW).
  43. * The following macros provide uniform access to all SRNG rings.
  44. */
  45. /* SRNG registers are split among two groups R0 and R2 and following
  46. * definitions identify the group to which each register belongs to
  47. */
  48. #define R0_INDEX 0
  49. #define R2_INDEX 1
  50. #define HWREG_INDEX(_reg_group) _reg_group ## _ ## INDEX
  51. /* Registers in R0 group */
  52. #define BASE_LSB_GROUP R0
  53. #define BASE_MSB_GROUP R0
  54. #define ID_GROUP R0
  55. #define STATUS_GROUP R0
  56. #define MISC_GROUP R0
  57. #define HP_ADDR_LSB_GROUP R0
  58. #define HP_ADDR_MSB_GROUP R0
  59. #define PRODUCER_INT_SETUP_GROUP R0
  60. #define PRODUCER_INT_STATUS_GROUP R0
  61. #define PRODUCER_FULL_COUNTER_GROUP R0
  62. #define MSI1_BASE_LSB_GROUP R0
  63. #define MSI1_BASE_MSB_GROUP R0
  64. #define MSI1_DATA_GROUP R0
  65. #define HP_TP_SW_OFFSET_GROUP R0
  66. #define TP_ADDR_LSB_GROUP R0
  67. #define TP_ADDR_MSB_GROUP R0
  68. #define CONSUMER_INT_SETUP_IX0_GROUP R0
  69. #define CONSUMER_INT_SETUP_IX1_GROUP R0
  70. #define CONSUMER_INT_STATUS_GROUP R0
  71. #define CONSUMER_EMPTY_COUNTER_GROUP R0
  72. #define CONSUMER_PREFETCH_TIMER_GROUP R0
  73. #define CONSUMER_PREFETCH_STATUS_GROUP R0
  74. /* Registers in R2 group */
  75. #define HP_GROUP R2
  76. #define TP_GROUP R2
  77. /**
  78. * Register definitions for all SRNG based rings are same, except few
  79. * differences between source (HW consumer) and destination (HW producer)
  80. * registers. Following macros definitions provide generic access to all
  81. * SRNG based rings.
  82. * For source rings, we will use the register/field definitions of SW2TCL1
  83. * ring defined in the HW header file mac_tcl_reg_seq_hwioreg.h. To setup
  84. * individual fields, SRNG_SM macros should be used with fields specified
  85. * using SRNG_SRC_FLD(<register>, <field>), Register writes should be done
  86. * using SRNG_SRC_REG_WRITE(<hal_srng>, <register>, <value>).
  87. * Similarly for destination rings we will use definitions of REO2SW1 ring
  88. * defined in the register reo_destination_ring.h. To setup individual
  89. * fields SRNG_SM macros should be used with fields specified using
  90. * SRNG_DST_FLD(<register>, <field>). Register writes should be done using
  91. * SRNG_DST_REG_WRITE(<hal_srng>, <register>, <value>).
  92. */
  93. #define SRNG_DST_REG_OFFSET(_reg, _reg_group) \
  94. HWIO_REO_ ## _reg_group ## _REO2SW1_RING_ ## _reg##_ADDR(0)
  95. #define SRNG_SRC_REG_OFFSET(_reg, _reg_group) \
  96. HWIO_TCL_ ## _reg_group ## _SW2TCL1_RING_ ## _reg ## _ADDR(0)
  97. #define _SRNG_DST_FLD(_reg_group, _reg_fld) \
  98. HWIO_REO_ ## _reg_group ## _REO2SW1_RING_ ## _reg_fld
  99. #define _SRNG_SRC_FLD(_reg_group, _reg_fld) \
  100. HWIO_TCL_ ## _reg_group ## _SW2TCL1_RING_ ## _reg_fld
  101. #define _SRNG_FLD(_reg_group, _reg_fld, _dir) \
  102. _SRNG_ ## _dir ## _FLD(_reg_group, _reg_fld)
  103. #define SRNG_DST_FLD(_reg, _f) _SRNG_FLD(_reg ## _GROUP, _reg ## _ ## _f, DST)
  104. #define SRNG_SRC_FLD(_reg, _f) _SRNG_FLD(_reg ## _GROUP, _reg ## _ ## _f, SRC)
  105. #define SRNG_SRC_R0_START_OFFSET SRNG_SRC_REG_OFFSET(BASE_LSB, R0)
  106. #define SRNG_DST_R0_START_OFFSET SRNG_DST_REG_OFFSET(BASE_LSB, R0)
  107. #define SRNG_SRC_R2_START_OFFSET SRNG_SRC_REG_OFFSET(HP, R2)
  108. #define SRNG_DST_R2_START_OFFSET SRNG_DST_REG_OFFSET(HP, R2)
  109. #define SRNG_SRC_START_OFFSET(_reg_group) \
  110. SRNG_SRC_ ## _reg_group ## _START_OFFSET
  111. #define SRNG_DST_START_OFFSET(_reg_group) \
  112. SRNG_DST_ ## _reg_group ## _START_OFFSET
  113. #define SRNG_REG_ADDR(_srng, _reg, _reg_group, _dir) \
  114. ((_srng)->hwreg_base[HWREG_INDEX(_reg_group)] + \
  115. SRNG_ ## _dir ## _REG_OFFSET(_reg, _reg_group) - \
  116. SRNG_ ## _dir ## _START_OFFSET(_reg_group))
  117. #define SRNG_DST_ADDR(_srng, _reg) \
  118. SRNG_REG_ADDR(_srng, _reg, _reg ## _GROUP, DST)
  119. #define SRNG_SRC_ADDR(_srng, _reg) \
  120. SRNG_REG_ADDR(_srng, _reg, _reg ## _GROUP, SRC)
  121. #define SRNG_REG_WRITE(_srng, _reg, _value, _dir) \
  122. hif_write32_mb(SRNG_ ## _dir ## _ADDR(_srng, _reg), (_value))
  123. #define SRNG_REG_READ(_srng, _reg, _dir) \
  124. hif_read32_mb(SRNG_ ## _dir ## _ADDR(_srng, _reg))
  125. #define SRNG_SRC_REG_WRITE(_srng, _reg, _value) \
  126. SRNG_REG_WRITE(_srng, _reg, _value, SRC)
  127. #define SRNG_DST_REG_WRITE(_srng, _reg, _value) \
  128. SRNG_REG_WRITE(_srng, _reg, _value, DST)
  129. #define SRNG_SRC_REG_READ(_srng, _reg) \
  130. SRNG_REG_READ(_srng, _reg, SRC)
  131. #define _SRNG_FM(_reg_fld) _reg_fld ## _BMSK
  132. #define _SRNG_FS(_reg_fld) _reg_fld ## _SHFT
  133. #define SRNG_SM(_reg_fld, _val) \
  134. (((_val) << _SRNG_FS(_reg_fld)) & _SRNG_FM(_reg_fld))
  135. #define SRNG_MS(_reg_fld, _val) \
  136. (((_val) & _SRNG_FM(_reg_fld)) >> _SRNG_FS(_reg_fld))
  137. /**
  138. * HW ring configuration table to identify hardware ring attributes like
  139. * register addresses, number of rings, ring entry size etc., for each type
  140. * of SRNG ring.
  141. *
  142. * Currently there is just one HW ring table, but there could be multiple
  143. * configurations in future based on HW variants from the same wifi3.0 family
  144. * and hence need to be attached with hal_soc based on HW type
  145. */
  146. #define HAL_SRNG_CONFIG(_hal_soc, _ring_type) (&hw_srng_table[_ring_type])
  147. static struct hal_hw_srng_config hw_srng_table[] = {
  148. /* TODO: max_rings can populated by querying HW capabilities */
  149. { /* REO_DST */
  150. .start_ring_id = HAL_SRNG_REO2SW1,
  151. .max_rings = 4,
  152. .entry_size = sizeof(struct reo_destination_ring) >> 2,
  153. .lmac_ring = FALSE,
  154. .ring_dir = HAL_SRNG_DST_RING,
  155. .reg_start = {
  156. HWIO_REO_R0_REO2SW1_RING_BASE_LSB_ADDR(
  157. SEQ_WCSS_UMAC_REO_REG_OFFSET),
  158. HWIO_REO_R2_REO2SW1_RING_HP_ADDR(
  159. SEQ_WCSS_UMAC_REO_REG_OFFSET)
  160. },
  161. .reg_size = {
  162. HWIO_REO_R0_REO2SW2_RING_BASE_LSB_ADDR(0) -
  163. HWIO_REO_R0_REO2SW1_RING_BASE_LSB_ADDR(0),
  164. HWIO_REO_R2_REO2SW1_RING_HP_ADDR(0) -
  165. HWIO_REO_R2_REO2SW2_RING_HP_ADDR(0),
  166. },
  167. },
  168. { /* REO_EXCEPTION */
  169. /* Designating REO2TCL ring as exception ring. This ring is
  170. * similar to other REO2SW rings though it is named as REO2TCL.
  171. * Any of theREO2SW rings can be used as exception ring.
  172. */
  173. .start_ring_id = HAL_SRNG_REO2TCL,
  174. .max_rings = 1,
  175. .entry_size = sizeof(struct reo_destination_ring) >> 2,
  176. .lmac_ring = FALSE,
  177. .ring_dir = HAL_SRNG_DST_RING,
  178. .reg_start = {
  179. HWIO_REO_R0_REO2TCL_RING_BASE_LSB_ADDR(
  180. SEQ_WCSS_UMAC_REO_REG_OFFSET),
  181. HWIO_REO_R2_REO2TCL_RING_HP_ADDR(
  182. SEQ_WCSS_UMAC_REO_REG_OFFSET)
  183. },
  184. /* Single ring - provide ring size if multiple rings of this
  185. * type are supported */
  186. .reg_size = {},
  187. },
  188. { /* REO_REINJECT */
  189. .start_ring_id = HAL_SRNG_SW2REO,
  190. .max_rings = 1,
  191. .entry_size = sizeof(struct reo_entrance_ring) >> 2,
  192. .lmac_ring = FALSE,
  193. .ring_dir = HAL_SRNG_SRC_RING,
  194. .reg_start = {
  195. HWIO_REO_R0_SW2REO_RING_BASE_LSB_ADDR(
  196. SEQ_WCSS_UMAC_REO_REG_OFFSET),
  197. HWIO_REO_R2_SW2REO_RING_HP_ADDR(
  198. SEQ_WCSS_UMAC_REO_REG_OFFSET)
  199. },
  200. /* Single ring - provide ring size if multiple rings of this
  201. * type are supported */
  202. .reg_size = {},
  203. },
  204. { /* REO_CMD */
  205. .start_ring_id = HAL_SRNG_REO_CMD,
  206. .max_rings = 1,
  207. .entry_size = (sizeof(struct tlv_32_hdr) +
  208. sizeof(struct reo_get_queue_stats)) >> 2,
  209. .lmac_ring = FALSE,
  210. .ring_dir = HAL_SRNG_SRC_RING,
  211. .reg_start = {
  212. HWIO_REO_R0_REO_CMD_RING_BASE_LSB_ADDR(
  213. SEQ_WCSS_UMAC_REO_REG_OFFSET),
  214. HWIO_REO_R2_REO_CMD_RING_HP_ADDR(
  215. SEQ_WCSS_UMAC_REO_REG_OFFSET),
  216. },
  217. /* Single ring - provide ring size if multiple rings of this
  218. * type are supported */
  219. .reg_size = {},
  220. },
  221. { /* REO_STATUS */
  222. .start_ring_id = HAL_SRNG_REO_STATUS,
  223. .max_rings = 1,
  224. .entry_size = (sizeof(struct tlv_32_hdr) +
  225. sizeof(struct reo_get_queue_stats_status)) >> 2,
  226. .lmac_ring = FALSE,
  227. .ring_dir = HAL_SRNG_DST_RING,
  228. .reg_start = {
  229. HWIO_REO_R0_REO_STATUS_RING_BASE_LSB_ADDR(
  230. SEQ_WCSS_UMAC_REO_REG_OFFSET),
  231. HWIO_REO_R2_REO_STATUS_RING_HP_ADDR(
  232. SEQ_WCSS_UMAC_REO_REG_OFFSET),
  233. },
  234. /* Single ring - provide ring size if multiple rings of this
  235. * type are supported */
  236. .reg_size = {},
  237. },
  238. { /* TCL_DATA */
  239. .start_ring_id = HAL_SRNG_SW2TCL1,
  240. .max_rings = 3,
  241. .entry_size = (sizeof(struct tlv_32_hdr) +
  242. sizeof(struct tcl_data_cmd)) >> 2,
  243. .lmac_ring = FALSE,
  244. .ring_dir = HAL_SRNG_SRC_RING,
  245. .reg_start = {
  246. HWIO_TCL_R0_SW2TCL1_RING_BASE_LSB_ADDR(
  247. SEQ_WCSS_UMAC_MAC_TCL_REG_OFFSET),
  248. HWIO_TCL_R2_SW2TCL1_RING_HP_ADDR(
  249. SEQ_WCSS_UMAC_MAC_TCL_REG_OFFSET),
  250. },
  251. .reg_size = {
  252. HWIO_TCL_R0_SW2TCL2_RING_BASE_LSB_ADDR(0) -
  253. HWIO_TCL_R0_SW2TCL1_RING_BASE_LSB_ADDR(0),
  254. HWIO_TCL_R2_SW2TCL2_RING_HP_ADDR(0) -
  255. HWIO_TCL_R2_SW2TCL1_RING_HP_ADDR(0),
  256. },
  257. },
  258. { /* TCL_CMD */
  259. .start_ring_id = HAL_SRNG_SW2TCL_CMD,
  260. .max_rings = 1,
  261. .entry_size = (sizeof(struct tlv_32_hdr) +
  262. sizeof(struct tcl_gse_cmd)) >> 2,
  263. .lmac_ring = FALSE,
  264. .ring_dir = HAL_SRNG_SRC_RING,
  265. .reg_start = {
  266. HWIO_TCL_R0_SW2TCL_CMD_RING_BASE_LSB_ADDR(
  267. SEQ_WCSS_UMAC_MAC_TCL_REG_OFFSET),
  268. HWIO_TCL_R2_SW2TCL_CMD_RING_HP_ADDR(
  269. SEQ_WCSS_UMAC_MAC_TCL_REG_OFFSET),
  270. },
  271. /* Single ring - provide ring size if multiple rings of this
  272. * type are supported */
  273. .reg_size = {},
  274. },
  275. { /* TCL_STATUS */
  276. .start_ring_id = HAL_SRNG_TCL_STATUS,
  277. .max_rings = 1,
  278. .entry_size = (sizeof(struct tlv_32_hdr) +
  279. sizeof(struct tcl_status_ring)) >> 2,
  280. .lmac_ring = FALSE,
  281. .ring_dir = HAL_SRNG_DST_RING,
  282. .reg_start = {
  283. HWIO_TCL_R0_TCL_STATUS1_RING_BASE_LSB_ADDR(
  284. SEQ_WCSS_UMAC_MAC_TCL_REG_OFFSET),
  285. HWIO_TCL_R2_TCL_STATUS1_RING_HP_ADDR(
  286. SEQ_WCSS_UMAC_MAC_TCL_REG_OFFSET),
  287. },
  288. /* Single ring - provide ring size if multiple rings of this
  289. * type are supported */
  290. .reg_size = {},
  291. },
  292. { /* CE_SRC */
  293. .start_ring_id = HAL_SRNG_CE_0_SRC,
  294. .max_rings = 12,
  295. .entry_size = sizeof(struct ce_src_desc) >> 2,
  296. .lmac_ring = FALSE,
  297. .ring_dir = HAL_SRNG_SRC_RING,
  298. .reg_start = {
  299. HWIO_WFSS_CE_CHANNEL_DST_R0_DEST_RING_BASE_LSB_ADDR(
  300. SEQ_WCSS_UMAC_WFSS_CE_0_REG_WFSS_CE_0_CHANNEL_SRC_REG_OFFSET),
  301. HWIO_WFSS_CE_CHANNEL_DST_R2_DEST_RING_HP_ADDR(
  302. SEQ_WCSS_UMAC_WFSS_CE_0_REG_WFSS_CE_0_CHANNEL_SRC_REG_OFFSET),
  303. },
  304. .reg_size = {
  305. SEQ_WCSS_UMAC_WFSS_CE_0_REG_WFSS_CE_1_CHANNEL_SRC_REG_OFFSET -
  306. SEQ_WCSS_UMAC_WFSS_CE_0_REG_WFSS_CE_0_CHANNEL_SRC_REG_OFFSET,
  307. SEQ_WCSS_UMAC_WFSS_CE_0_REG_WFSS_CE_1_CHANNEL_SRC_REG_OFFSET -
  308. SEQ_WCSS_UMAC_WFSS_CE_0_REG_WFSS_CE_0_CHANNEL_SRC_REG_OFFSET,
  309. },
  310. },
  311. { /* CE_DST */
  312. .start_ring_id = HAL_SRNG_CE_0_DST,
  313. .max_rings = 12,
  314. .entry_size = 8 >> 2,
  315. /*TODO: entry_size above should actually be
  316. * sizeof(struct ce_dst_desc) >> 2, but couldn't find definition
  317. * of struct ce_dst_desc in HW header files
  318. */
  319. .lmac_ring = FALSE,
  320. .ring_dir = HAL_SRNG_SRC_RING,
  321. .reg_start = {
  322. HWIO_WFSS_CE_CHANNEL_DST_R0_DEST_RING_BASE_LSB_ADDR(
  323. SEQ_WCSS_UMAC_WFSS_CE_0_REG_WFSS_CE_0_CHANNEL_DST_REG_OFFSET),
  324. HWIO_WFSS_CE_CHANNEL_DST_R2_DEST_RING_HP_ADDR(
  325. SEQ_WCSS_UMAC_WFSS_CE_0_REG_WFSS_CE_0_CHANNEL_DST_REG_OFFSET),
  326. },
  327. .reg_size = {
  328. SEQ_WCSS_UMAC_WFSS_CE_0_REG_WFSS_CE_1_CHANNEL_DST_REG_OFFSET -
  329. SEQ_WCSS_UMAC_WFSS_CE_0_REG_WFSS_CE_0_CHANNEL_DST_REG_OFFSET,
  330. SEQ_WCSS_UMAC_WFSS_CE_0_REG_WFSS_CE_1_CHANNEL_DST_REG_OFFSET -
  331. SEQ_WCSS_UMAC_WFSS_CE_0_REG_WFSS_CE_0_CHANNEL_DST_REG_OFFSET,
  332. },
  333. },
  334. { /* CE_DST_STATUS */
  335. .start_ring_id = HAL_SRNG_CE_0_DST_STATUS,
  336. .max_rings = 12,
  337. .entry_size = sizeof(struct ce_stat_desc) >> 2,
  338. .lmac_ring = FALSE,
  339. .ring_dir = HAL_SRNG_DST_RING,
  340. .reg_start = {
  341. HWIO_WFSS_CE_CHANNEL_DST_R0_STATUS_RING_BASE_LSB_ADDR(
  342. SEQ_WCSS_UMAC_WFSS_CE_0_REG_WFSS_CE_0_CHANNEL_DST_REG_OFFSET),
  343. HWIO_WFSS_CE_CHANNEL_DST_R2_STATUS_RING_HP_ADDR(
  344. SEQ_WCSS_UMAC_WFSS_CE_0_REG_WFSS_CE_0_CHANNEL_DST_REG_OFFSET),
  345. },
  346. /* TODO: check destination status ring registers */
  347. .reg_size = {
  348. SEQ_WCSS_UMAC_WFSS_CE_0_REG_WFSS_CE_1_CHANNEL_DST_REG_OFFSET -
  349. SEQ_WCSS_UMAC_WFSS_CE_0_REG_WFSS_CE_0_CHANNEL_DST_REG_OFFSET,
  350. SEQ_WCSS_UMAC_WFSS_CE_0_REG_WFSS_CE_1_CHANNEL_DST_REG_OFFSET -
  351. SEQ_WCSS_UMAC_WFSS_CE_0_REG_WFSS_CE_0_CHANNEL_DST_REG_OFFSET,
  352. },
  353. },
  354. { /* WBM_IDLE_LINK */
  355. .start_ring_id = HAL_SRNG_WBM_IDLE_LINK,
  356. .max_rings = 1,
  357. .entry_size = sizeof(struct wbm_link_descriptor_ring) >> 2,
  358. .lmac_ring = FALSE,
  359. .ring_dir = HAL_SRNG_SRC_RING,
  360. .reg_start = {
  361. HWIO_WBM_R0_WBM_IDLE_LINK_RING_BASE_LSB_ADDR(SEQ_WCSS_UMAC_WBM_REG_OFFSET),
  362. HWIO_WBM_R2_WBM_IDLE_LINK_RING_HP_ADDR(SEQ_WCSS_UMAC_WBM_REG_OFFSET),
  363. },
  364. /* Single ring - provide ring size if multiple rings of this
  365. * type are supported */
  366. .reg_size = {},
  367. },
  368. { /* SW2WBM_RELEASE */
  369. .start_ring_id = HAL_SRNG_WBM_SW_RELEASE,
  370. .max_rings = 1,
  371. .entry_size = sizeof(struct wbm_release_ring) >> 2,
  372. .lmac_ring = FALSE,
  373. .ring_dir = HAL_SRNG_SRC_RING,
  374. .reg_start = {
  375. HWIO_WBM_R0_SW_RELEASE_RING_BASE_LSB_ADDR(SEQ_WCSS_UMAC_WBM_REG_OFFSET),
  376. HWIO_WBM_R2_SW_RELEASE_RING_HP_ADDR(SEQ_WCSS_UMAC_WBM_REG_OFFSET),
  377. },
  378. /* Single ring - provide ring size if multiple rings of this
  379. * type are supported */
  380. .reg_size = {},
  381. },
  382. { /* WBM2SW_RELEASE */
  383. .start_ring_id = HAL_SRNG_WBM2SW0_RELEASE,
  384. .max_rings = 4,
  385. .entry_size = sizeof(struct wbm_release_ring) >> 2,
  386. .lmac_ring = FALSE,
  387. .ring_dir = HAL_SRNG_DST_RING,
  388. .reg_start = {
  389. HWIO_WBM_R0_WBM2SW0_RELEASE_RING_BASE_LSB_ADDR(SEQ_WCSS_UMAC_WBM_REG_OFFSET),
  390. HWIO_WBM_R2_WBM2SW0_RELEASE_RING_HP_ADDR(SEQ_WCSS_UMAC_WBM_REG_OFFSET),
  391. },
  392. .reg_size = {
  393. HWIO_WBM_R0_WBM2SW1_RELEASE_RING_BASE_LSB_ADDR(SEQ_WCSS_UMAC_WBM_REG_OFFSET) -
  394. HWIO_WBM_R0_WBM2SW0_RELEASE_RING_BASE_LSB_ADDR(SEQ_WCSS_UMAC_WBM_REG_OFFSET),
  395. HWIO_WBM_R2_WBM2SW1_RELEASE_RING_HP_ADDR(SEQ_WCSS_UMAC_WBM_REG_OFFSET) -
  396. HWIO_WBM_R2_WBM2SW0_RELEASE_RING_HP_ADDR(SEQ_WCSS_UMAC_WBM_REG_OFFSET),
  397. },
  398. },
  399. { /* RXDMA_BUF */
  400. .start_ring_id = HAL_SRNG_WMAC1_SW2RXDMA0_BUF,
  401. .max_rings = 2,
  402. /* TODO: Check if the additional IPA buffer ring needs to be
  403. * setup here (in which case max_rings should be set to 2),
  404. * or it will be setup by IPA host driver
  405. */
  406. .entry_size = sizeof(struct wbm_buffer_ring) >> 2,
  407. .lmac_ring = TRUE,
  408. .ring_dir = HAL_SRNG_SRC_RING,
  409. /* reg_start is not set because LMAC rings are not accessed
  410. * from host
  411. */
  412. .reg_start = {},
  413. .reg_size = {},
  414. },
  415. { /* RXDMA_DST */
  416. .start_ring_id = HAL_SRNG_WMAC1_RXDMA2SW0,
  417. .max_rings = 1,
  418. .entry_size = sizeof(struct reo_entrance_ring) >> 2,
  419. .lmac_ring = TRUE,
  420. .ring_dir = HAL_SRNG_DST_RING,
  421. /* reg_start is not set because LMAC rings are not accessed
  422. * from host
  423. */
  424. .reg_start = {},
  425. .reg_size = {},
  426. },
  427. { /* RXDMA_MONITOR_BUF */
  428. .start_ring_id = HAL_SRNG_WMAC1_SW2RXDMA2_BUF,
  429. .max_rings = 1,
  430. .entry_size = sizeof(struct wbm_buffer_ring) >> 2,
  431. .lmac_ring = TRUE,
  432. .ring_dir = HAL_SRNG_SRC_RING,
  433. /* reg_start is not set because LMAC rings are not accessed
  434. * from host
  435. */
  436. .reg_start = {},
  437. .reg_size = {},
  438. },
  439. { /* RXDMA_MONITOR_STATUS */
  440. .start_ring_id = HAL_SRNG_WMAC1_SW2RXDMA1_STATBUF,
  441. .max_rings = 1,
  442. .entry_size = sizeof(struct wbm_buffer_ring) >> 2,
  443. .lmac_ring = TRUE,
  444. .ring_dir = HAL_SRNG_SRC_RING,
  445. /* reg_start is not set because LMAC rings are not accessed
  446. * from host
  447. */
  448. .reg_start = {},
  449. .reg_size = {},
  450. },
  451. { /* RXDMA_MONITOR_DST */
  452. .start_ring_id = HAL_SRNG_WMAC1_RXDMA2SW1,
  453. .max_rings = 1,
  454. .entry_size = sizeof(struct reo_entrance_ring) >> 2,
  455. .lmac_ring = TRUE,
  456. .ring_dir = HAL_SRNG_DST_RING,
  457. /* reg_start is not set because LMAC rings are not accessed
  458. * from host
  459. */
  460. .reg_start = {},
  461. .reg_size = {},
  462. },
  463. };
  464. /**
  465. * hal_attach - Initalize HAL layer
  466. * @hif_handle: Opaque HIF handle
  467. * @qdf_dev: QDF device
  468. *
  469. * Return: Opaque HAL SOC handle
  470. * NULL on failure (if given ring is not available)
  471. *
  472. * This function should be called as part of HIF initialization (for accessing
  473. * copy engines). DP layer will get hal_soc handle using hif_get_hal_handle()
  474. *
  475. */
  476. void *hal_attach(void *hif_handle, qdf_device_t qdf_dev)
  477. {
  478. struct hal_soc *hal;
  479. int i;
  480. hal = qdf_mem_malloc(sizeof(*hal));
  481. if (!hal) {
  482. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  483. "%s: hal_soc allocation failed\n", __func__);
  484. goto fail0;
  485. }
  486. hal->hif_handle = hif_handle;
  487. hal->dev_base_addr = hif_get_dev_ba(hif_handle);
  488. hal->qdf_dev = qdf_dev;
  489. hal->shadow_rdptr_mem_vaddr = (uint32_t *)qdf_mem_alloc_consistent(
  490. qdf_dev, qdf_dev->dev, sizeof(*(hal->shadow_rdptr_mem_vaddr)) *
  491. HAL_SRNG_ID_MAX, &(hal->shadow_rdptr_mem_paddr));
  492. if (!hal->shadow_rdptr_mem_paddr) {
  493. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  494. "%s: hal->shadow_rdptr_mem_paddr allocation failed\n",
  495. __func__);
  496. goto fail1;
  497. }
  498. hal->shadow_wrptr_mem_vaddr =
  499. (uint32_t *)qdf_mem_alloc_consistent(qdf_dev, qdf_dev->dev,
  500. sizeof(*(hal->shadow_wrptr_mem_vaddr)) * HAL_MAX_LMAC_RINGS,
  501. &(hal->shadow_wrptr_mem_paddr));
  502. if (!hal->shadow_wrptr_mem_vaddr) {
  503. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  504. "%s: hal->shadow_wrptr_mem_vaddr allocation failed\n",
  505. __func__);
  506. goto fail2;
  507. }
  508. for (i = 0; i < HAL_SRNG_ID_MAX; i++) {
  509. hal->srng_list[i].initialized = 0;
  510. hal->srng_list[i].ring_id = i;
  511. }
  512. return (void *)hal;
  513. fail2:
  514. qdf_mem_free_consistent(hal->qdf_dev, NULL,
  515. sizeof(*(hal->shadow_rdptr_mem_vaddr)) * HAL_SRNG_ID_MAX,
  516. hal->shadow_rdptr_mem_vaddr, hal->shadow_rdptr_mem_paddr, 0);
  517. fail1:
  518. qdf_mem_free(hal);
  519. fail0:
  520. return NULL;
  521. }
  522. /**
  523. * hal_detach - Detach HAL layer
  524. * @hal_soc: HAL SOC handle
  525. *
  526. * Return: Opaque HAL SOC handle
  527. * NULL on failure (if given ring is not available)
  528. *
  529. * This function should be called as part of HIF initialization (for accessing
  530. * copy engines). DP layer will get hal_soc handle using hif_get_hal_handle()
  531. *
  532. */
  533. extern void hal_detach(void *hal_soc)
  534. {
  535. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  536. qdf_mem_free_consistent(hal->qdf_dev, NULL,
  537. sizeof(*(hal->shadow_rdptr_mem_vaddr)) * HAL_SRNG_ID_MAX,
  538. hal->shadow_rdptr_mem_vaddr, hal->shadow_rdptr_mem_paddr, 0);
  539. qdf_mem_free_consistent(hal->qdf_dev, NULL,
  540. sizeof(*(hal->shadow_wrptr_mem_vaddr)) * HAL_MAX_LMAC_RINGS,
  541. hal->shadow_wrptr_mem_vaddr, hal->shadow_wrptr_mem_paddr, 0);
  542. qdf_mem_free(hal);
  543. return;
  544. }
  545. /**
  546. * hal_srng_src_hw_init - Private function to initialize SRNG
  547. * source ring HW
  548. * @hal_soc: HAL SOC handle
  549. * @srng: SRNG ring pointer
  550. */
  551. static inline void hal_srng_src_hw_init(struct hal_soc *hal,
  552. struct hal_srng *srng)
  553. {
  554. uint32_t reg_val = 0;
  555. uint64_t tp_addr = 0;
  556. SRNG_SRC_REG_WRITE(srng, BASE_LSB, srng->ring_base_paddr & 0xffffffff);
  557. reg_val = SRNG_SM(SRNG_SRC_FLD(BASE_MSB, RING_BASE_ADDR_MSB),
  558. ((uint64_t)(srng->ring_base_paddr) >> 32)) |
  559. SRNG_SM(SRNG_SRC_FLD(BASE_MSB, RING_SIZE),
  560. srng->entry_size * srng->num_entries);
  561. SRNG_SRC_REG_WRITE(srng, BASE_MSB, reg_val);
  562. reg_val = SRNG_SM(SRNG_SRC_FLD(ID, RING_ID), srng->ring_id) |
  563. SRNG_SM(SRNG_SRC_FLD(ID, ENTRY_SIZE), srng->entry_size);
  564. SRNG_SRC_REG_WRITE(srng, ID, reg_val);
  565. reg_val = ((srng->flags & HAL_SRNG_DATA_TLV_SWAP) ?
  566. SRNG_SM(SRNG_SRC_FLD(MISC, DATA_TLV_SWAP_BIT), 1) : 0) |
  567. ((srng->flags & HAL_SRNG_RING_PTR_SWAP) ?
  568. SRNG_SM(SRNG_SRC_FLD(MISC, HOST_FW_SWAP_BIT), 1) : 0) |
  569. ((srng->flags & HAL_SRNG_MSI_SWAP) ?
  570. SRNG_SM(SRNG_SRC_FLD(MISC, MSI_SWAP_BIT), 1) : 0);
  571. /* Loop count is not used for SRC rings */
  572. reg_val |= SRNG_SM(SRNG_SRC_FLD(MISC, LOOPCNT_DISABLE), 1);
  573. SRNG_SRC_REG_WRITE(srng, MISC, reg_val);
  574. /**
  575. * Interrupt setup:
  576. * Default interrupt mode is 'pulse'. Need to setup SW_INTERRUPT_MODE
  577. * if level mode is required
  578. */
  579. reg_val = 0;
  580. if (srng->intr_timer_thres_us) {
  581. reg_val |= SRNG_SM(SRNG_SRC_FLD(CONSUMER_INT_SETUP_IX0,
  582. INTERRUPT_TIMER_THRESHOLD),
  583. srng->intr_timer_thres_us >> 3);
  584. }
  585. if (srng->intr_batch_cntr_thres_entries) {
  586. reg_val |= SRNG_SM(SRNG_SRC_FLD(CONSUMER_INT_SETUP_IX0,
  587. BATCH_COUNTER_THRESHOLD),
  588. srng->intr_batch_cntr_thres_entries *
  589. srng->entry_size);
  590. }
  591. SRNG_SRC_REG_WRITE(srng, CONSUMER_INT_SETUP_IX0, reg_val);
  592. if (srng->flags & HAL_SRNG_LOW_THRES_INTR_ENABLE) {
  593. reg_val |= SRNG_SM(SRNG_SRC_FLD(CONSUMER_INT_SETUP_IX1,
  594. LOW_THRESHOLD), srng->u.src_ring.low_threshold);
  595. }
  596. SRNG_SRC_REG_WRITE(srng, CONSUMER_INT_SETUP_IX1, reg_val);
  597. if (srng->flags & HAL_SRNG_MSI_INTR) {
  598. SRNG_SRC_REG_WRITE(srng, MSI1_BASE_LSB,
  599. srng->msi_addr & 0xffffffff);
  600. reg_val = SRNG_SM(SRNG_SRC_FLD(MSI1_BASE_MSB, ADDR),
  601. (uint64_t)(srng->msi_addr) >> 32) |
  602. SRNG_SM(SRNG_SRC_FLD(MSI1_BASE_MSB,
  603. MSI1_ENABLE), 1);
  604. SRNG_SRC_REG_WRITE(srng, MSI1_BASE_MSB, reg_val);
  605. SRNG_SRC_REG_WRITE(srng, MSI1_DATA, srng->msi_data);
  606. }
  607. tp_addr = (uint64_t)(hal->shadow_rdptr_mem_paddr +
  608. ((unsigned long)(srng->u.src_ring.tp_addr) -
  609. (unsigned long)(hal->shadow_rdptr_mem_vaddr)));
  610. SRNG_SRC_REG_WRITE(srng, TP_ADDR_LSB, tp_addr & 0xffffffff);
  611. SRNG_SRC_REG_WRITE(srng, TP_ADDR_MSB, tp_addr >> 32);
  612. /* Initilaize head and tail pointers to indicate ring is empty */
  613. SRNG_SRC_REG_WRITE(srng, HP, 0);
  614. SRNG_SRC_REG_WRITE(srng, TP, 0);
  615. *(srng->u.src_ring.tp_addr) = 0;
  616. }
  617. /**
  618. * hal_srng_dst_hw_init - Private function to initialize SRNG
  619. * destination ring HW
  620. * @hal_soc: HAL SOC handle
  621. * @srng: SRNG ring pointer
  622. */
  623. static inline void hal_srng_dst_hw_init(struct hal_soc *hal,
  624. struct hal_srng *srng)
  625. {
  626. uint32_t reg_val = 0;
  627. uint64_t hp_addr = 0;
  628. SRNG_DST_REG_WRITE(srng, BASE_LSB, srng->ring_base_paddr & 0xffffffff);
  629. reg_val = SRNG_SM(SRNG_DST_FLD(BASE_MSB, RING_BASE_ADDR_MSB),
  630. ((uint64_t)(srng->ring_base_paddr) >> 32)) |
  631. SRNG_SM(SRNG_DST_FLD(BASE_MSB, RING_SIZE),
  632. srng->entry_size * srng->num_entries);
  633. SRNG_DST_REG_WRITE(srng, BASE_MSB, reg_val);
  634. reg_val = SRNG_SM(SRNG_DST_FLD(ID, RING_ID), srng->ring_id) |
  635. SRNG_SM(SRNG_DST_FLD(ID, ENTRY_SIZE), srng->entry_size);
  636. SRNG_DST_REG_WRITE(srng, ID, reg_val);
  637. reg_val = ((srng->flags & HAL_SRNG_DATA_TLV_SWAP) ?
  638. SRNG_SM(SRNG_DST_FLD(MISC, DATA_TLV_SWAP_BIT), 1) : 0) |
  639. ((srng->flags & HAL_SRNG_RING_PTR_SWAP) ?
  640. SRNG_SM(SRNG_DST_FLD(MISC, HOST_FW_SWAP_BIT), 1) : 0) |
  641. ((srng->flags & HAL_SRNG_MSI_SWAP) ?
  642. SRNG_SM(SRNG_DST_FLD(MISC, MSI_SWAP_BIT), 1) : 0);
  643. SRNG_DST_REG_WRITE(srng, MISC, reg_val);
  644. /**
  645. * Interrupt setup:
  646. * Default interrupt mode is 'pulse'. Need to setup SW_INTERRUPT_MODE
  647. * if level mode is required
  648. */
  649. reg_val = 0;
  650. if (srng->intr_timer_thres_us) {
  651. reg_val |= SRNG_SM(SRNG_DST_FLD(PRODUCER_INT_SETUP,
  652. INTERRUPT_TIMER_THRESHOLD),
  653. srng->intr_timer_thres_us >> 3);
  654. }
  655. if (srng->intr_batch_cntr_thres_entries) {
  656. reg_val |= SRNG_SM(SRNG_DST_FLD(PRODUCER_INT_SETUP,
  657. BATCH_COUNTER_THRESHOLD),
  658. srng->intr_batch_cntr_thres_entries *
  659. srng->entry_size);
  660. }
  661. SRNG_DST_REG_WRITE(srng, PRODUCER_INT_SETUP, reg_val);
  662. if (srng->flags & HAL_SRNG_MSI_INTR) {
  663. SRNG_DST_REG_WRITE(srng, MSI1_BASE_LSB,
  664. srng->msi_addr & 0xffffffff);
  665. reg_val = SRNG_SM(SRNG_DST_FLD(MSI1_BASE_MSB, ADDR),
  666. (uint64_t)(srng->msi_addr) >> 32) |
  667. SRNG_SM(SRNG_DST_FLD(MSI1_BASE_MSB,
  668. MSI1_ENABLE), 1);
  669. SRNG_DST_REG_WRITE(srng, MSI1_BASE_MSB, reg_val);
  670. SRNG_DST_REG_WRITE(srng, MSI1_DATA, srng->msi_data);
  671. }
  672. hp_addr = (uint64_t)(hal->shadow_rdptr_mem_paddr +
  673. ((unsigned long)(srng->u.dst_ring.hp_addr) -
  674. (unsigned long)(hal->shadow_rdptr_mem_vaddr)));
  675. SRNG_DST_REG_WRITE(srng, HP_ADDR_LSB, hp_addr & 0xffffffff);
  676. SRNG_DST_REG_WRITE(srng, HP_ADDR_MSB, hp_addr >> 32);
  677. /* Initilaize head and tail pointers to indicate ring is empty */
  678. SRNG_DST_REG_WRITE(srng, HP, 0);
  679. SRNG_DST_REG_WRITE(srng, TP, 0);
  680. *(srng->u.dst_ring.hp_addr) = 0;
  681. }
  682. /**
  683. * hal_srng_hw_init - Private function to initialize SRNG HW
  684. * @hal_soc: HAL SOC handle
  685. * @srng: SRNG ring pointer
  686. */
  687. static inline void hal_srng_hw_init(struct hal_soc *hal,
  688. struct hal_srng *srng)
  689. {
  690. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  691. hal_srng_src_hw_init(hal, srng);
  692. else
  693. hal_srng_dst_hw_init(hal, srng);
  694. }
  695. /**
  696. * hal_srng_setup - Initalize HW SRNG ring.
  697. * @hal_soc: Opaque HAL SOC handle
  698. * @ring_type: one of the types from hal_ring_type
  699. * @ring_num: Ring number if there are multiple rings of same type (staring
  700. * from 0)
  701. * @mac_id: valid MAC Id should be passed if ring type is one of lmac rings
  702. * @ring_params: SRNG ring params in hal_srng_params structure.
  703. * Callers are expected to allocate contiguous ring memory of size
  704. * 'num_entries * entry_size' bytes and pass the physical and virtual base
  705. * addresses through 'ring_base_paddr' and 'ring_base_vaddr' in
  706. * hal_srng_params structure. Ring base address should be 8 byte aligned
  707. * and size of each ring entry should be queried using the API
  708. * hal_srng_get_entrysize
  709. *
  710. * Return: Opaque pointer to ring on success
  711. * NULL on failure (if given ring is not available)
  712. */
  713. void *hal_srng_setup(void *hal_soc, int ring_type, int ring_num,
  714. int mac_id, struct hal_srng_params *ring_params)
  715. {
  716. int ring_id;
  717. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  718. struct hal_srng *srng;
  719. struct hal_hw_srng_config *ring_config =
  720. HAL_SRNG_CONFIG(hal, ring_type);
  721. void *dev_base_addr;
  722. int i;
  723. if (ring_num >= ring_config->max_rings) {
  724. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  725. "%s: ring_num exceeded maximum no. of supported rings\n",
  726. __func__);
  727. return NULL;
  728. }
  729. if (ring_config->lmac_ring) {
  730. ring_id = ring_config->start_ring_id + ring_num +
  731. (mac_id * HAL_MAX_RINGS_PER_LMAC);
  732. } else {
  733. ring_id = ring_config->start_ring_id + ring_num;
  734. }
  735. /* TODO: Should we allocate srng structures dynamically? */
  736. srng = &(hal->srng_list[ring_id]);
  737. if (srng->initialized) {
  738. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  739. "%s: Ring (ring_type, ring_num) already initialized\n",
  740. __func__);
  741. return NULL;
  742. }
  743. dev_base_addr = hal->dev_base_addr;
  744. srng->ring_id = ring_id;
  745. srng->ring_dir = ring_config->ring_dir;
  746. srng->ring_base_paddr = ring_params->ring_base_paddr;
  747. srng->ring_base_vaddr = ring_params->ring_base_vaddr;
  748. srng->entry_size = ring_config->entry_size;
  749. srng->num_entries = ring_params->num_entries;
  750. srng->ring_size = srng->num_entries * srng->entry_size;
  751. srng->ring_size_mask = srng->ring_size - 1;
  752. srng->msi_addr = ring_params->msi_addr;
  753. srng->msi_data = ring_params->msi_data;
  754. srng->intr_timer_thres_us = ring_params->intr_timer_thres_us;
  755. srng->intr_batch_cntr_thres_entries =
  756. ring_params->intr_batch_cntr_thres_entries;
  757. for (i = 0 ; i < MAX_SRNG_REG_GROUPS; i++) {
  758. srng->hwreg_base[i] = dev_base_addr + ring_config->reg_start[i]
  759. + (ring_num * ring_config->reg_size[i]);
  760. }
  761. /* Zero out the entire ring memory */
  762. qdf_mem_zero(srng->ring_base_vaddr, (srng->entry_size *
  763. srng->num_entries) << 2);
  764. srng->flags = ring_params->flags;
  765. #ifdef BIG_ENDIAN_HOST
  766. /* TODO: See if we should we get these flags from caller */
  767. srng->flags |= HAL_SRNG_DATA_TLV_SWAP;
  768. srng->flags |= HAL_SRNG_MSI_SWAP;
  769. srng->flags |= HAL_SRNG_RING_PTR_SWAP;
  770. #endif
  771. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  772. srng->u.src_ring.hp = 0;
  773. srng->u.src_ring.reap_hp = srng->ring_size -
  774. srng->entry_size;
  775. srng->u.src_ring.tp_addr =
  776. &(hal->shadow_rdptr_mem_vaddr[ring_id]);
  777. srng->u.src_ring.low_threshold = ring_params->low_threshold;
  778. if (ring_config->lmac_ring) {
  779. /* For LMAC rings, head pointer updates will be done
  780. * through FW by writing to a shared memory location
  781. */
  782. srng->u.src_ring.hp_addr =
  783. &(hal->shadow_wrptr_mem_vaddr[ring_id -
  784. HAL_SRNG_LMAC1_ID_START]);
  785. srng->flags |= HAL_SRNG_LMAC_RING;
  786. } else {
  787. srng->u.src_ring.hp_addr = SRNG_SRC_ADDR(srng, HP);
  788. }
  789. } else {
  790. /* During initialization loop count in all the descriptors
  791. * will be set to zero, and HW will set it to 1 on completing
  792. * descriptor update in first loop, and increments it by 1 on
  793. * subsequent loops (loop count wraps around after reaching
  794. * 0xffff). The 'loop_cnt' in SW ring state is the expected
  795. * loop count in descriptors updated by HW (to be processed
  796. * by SW).
  797. */
  798. srng->u.dst_ring.loop_cnt = 1;
  799. srng->u.dst_ring.tp = 0;
  800. srng->u.dst_ring.hp_addr =
  801. &(hal->shadow_rdptr_mem_vaddr[ring_id]);
  802. if (ring_config->lmac_ring) {
  803. /* For LMAC rings, tail pointer updates will be done
  804. * through FW by writing to a shared memory location
  805. */
  806. srng->u.dst_ring.tp_addr =
  807. &(hal->shadow_wrptr_mem_vaddr[ring_id -
  808. HAL_SRNG_LMAC1_ID_START]);
  809. srng->flags |= HAL_SRNG_LMAC_RING;
  810. } else {
  811. srng->u.dst_ring.tp_addr = SRNG_DST_ADDR(srng, TP);
  812. }
  813. }
  814. if (!(ring_config->lmac_ring))
  815. hal_srng_hw_init(hal, srng);
  816. SRNG_LOCK_INIT(&srng->lock);
  817. return (void *)srng;
  818. }
  819. /**
  820. * hal_srng_cleanup - Deinitialize HW SRNG ring.
  821. * @hal_soc: Opaque HAL SOC handle
  822. * @hal_srng: Opaque HAL SRNG pointer
  823. */
  824. void hal_srng_cleanup(void *hal_soc, void *hal_srng)
  825. {
  826. struct hal_srng *srng = (struct hal_srng *)hal_srng;
  827. SRNG_LOCK_DESTROY(&srng->lock);
  828. srng->initialized = 0;
  829. }
  830. /**
  831. * hal_srng_get_entrysize - Returns size of ring entry in bytes
  832. * @hal_soc: Opaque HAL SOC handle
  833. * @ring_type: one of the types from hal_ring_type
  834. *
  835. */
  836. uint32_t hal_srng_get_entrysize(void *hal_soc, int ring_type)
  837. {
  838. struct hal_hw_srng_config *ring_config =
  839. HAL_SRNG_CONFIG(hal, ring_type);
  840. return ring_config->entry_size << 2;
  841. }
  842. /**
  843. * hal_get_srng_params - Retreive SRNG parameters for a given ring from HAL
  844. *
  845. * @hal_soc: Opaque HAL SOC handle
  846. * @hal_ring: Ring pointer (Source or Destination ring)
  847. * @ring_params: SRNG parameters will be returned through this structure
  848. */
  849. extern void hal_get_srng_params(void *hal_soc, void *hal_ring,
  850. struct hal_srng_params *ring_params)
  851. {
  852. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  853. ring_params->ring_base_paddr = srng->ring_base_paddr;
  854. ring_params->ring_base_vaddr = srng->ring_base_vaddr;
  855. ring_params->num_entries = srng->num_entries;
  856. ring_params->msi_addr = srng->msi_addr;
  857. ring_params->msi_data = srng->msi_data;
  858. ring_params->intr_timer_thres_us = srng->intr_timer_thres_us;
  859. ring_params->intr_batch_cntr_thres_entries =
  860. srng->intr_batch_cntr_thres_entries;
  861. ring_params->low_threshold = srng->u.src_ring.low_threshold;
  862. ring_params->flags = srng->flags;
  863. ring_params->ring_id = srng->ring_id;
  864. }