hal_srng.c 32 KB

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