hal_srng.c 32 KB

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