hal_srng.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  1. /*
  2. * Copyright (c) 2016-2019 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #include "hal_hw_headers.h"
  19. #include "hal_api.h"
  20. #include "target_type.h"
  21. #include "wcss_version.h"
  22. #include "qdf_module.h"
  23. #ifdef QCA_WIFI_QCA8074
  24. void hal_qca6290_attach(struct hal_soc *hal);
  25. #endif
  26. #ifdef QCA_WIFI_QCA8074
  27. void hal_qca8074_attach(struct hal_soc *hal);
  28. #endif
  29. #if defined(QCA_WIFI_QCA8074V2) || defined(QCA_WIFI_QCA6018)
  30. void hal_qca8074v2_attach(struct hal_soc *hal);
  31. #endif
  32. #ifdef QCA_WIFI_QCA6390
  33. void hal_qca6390_attach(struct hal_soc *hal);
  34. #endif
  35. #ifdef QCA_WIFI_QCA6490
  36. void hal_qca6490_attach(struct hal_soc *hal);
  37. #endif
  38. #ifdef QCA_WIFI_QCN9000
  39. void hal_qcn9000_attach(struct hal_soc *hal);
  40. #endif
  41. #ifdef ENABLE_VERBOSE_DEBUG
  42. bool is_hal_verbose_debug_enabled;
  43. #endif
  44. /**
  45. * hal_get_srng_ring_id() - get the ring id of a descriped ring
  46. * @hal: hal_soc data structure
  47. * @ring_type: type enum describing the ring
  48. * @ring_num: which ring of the ring type
  49. * @mac_id: which mac does the ring belong to (or 0 for non-lmac rings)
  50. *
  51. * Return: the ring id or -EINVAL if the ring does not exist.
  52. */
  53. static int hal_get_srng_ring_id(struct hal_soc *hal, int ring_type,
  54. int ring_num, int mac_id)
  55. {
  56. struct hal_hw_srng_config *ring_config =
  57. HAL_SRNG_CONFIG(hal, ring_type);
  58. int ring_id;
  59. if (ring_num >= ring_config->max_rings) {
  60. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO,
  61. "%s: ring_num exceeded maximum no. of supported rings",
  62. __func__);
  63. /* TODO: This is a programming error. Assert if this happens */
  64. return -EINVAL;
  65. }
  66. if (ring_config->lmac_ring) {
  67. ring_id = ring_config->start_ring_id + ring_num +
  68. (mac_id * HAL_MAX_RINGS_PER_LMAC);
  69. } else {
  70. ring_id = ring_config->start_ring_id + ring_num;
  71. }
  72. return ring_id;
  73. }
  74. static struct hal_srng *hal_get_srng(struct hal_soc *hal, int ring_id)
  75. {
  76. /* TODO: Should we allocate srng structures dynamically? */
  77. return &(hal->srng_list[ring_id]);
  78. }
  79. #define HP_OFFSET_IN_REG_START 1
  80. #define OFFSET_FROM_HP_TO_TP 4
  81. static void hal_update_srng_hp_tp_address(struct hal_soc *hal_soc,
  82. int shadow_config_index,
  83. int ring_type,
  84. int ring_num)
  85. {
  86. struct hal_srng *srng;
  87. int ring_id;
  88. struct hal_hw_srng_config *ring_config =
  89. HAL_SRNG_CONFIG(hal_soc, ring_type);
  90. ring_id = hal_get_srng_ring_id(hal_soc, ring_type, ring_num, 0);
  91. if (ring_id < 0)
  92. return;
  93. srng = hal_get_srng(hal_soc, ring_id);
  94. if (ring_config->ring_dir == HAL_SRNG_DST_RING) {
  95. srng->u.dst_ring.tp_addr = SHADOW_REGISTER(shadow_config_index)
  96. + hal_soc->dev_base_addr;
  97. hal_debug("tp_addr=%pK dev base addr %pK index %u",
  98. srng->u.dst_ring.tp_addr, hal_soc->dev_base_addr,
  99. shadow_config_index);
  100. } else {
  101. srng->u.src_ring.hp_addr = SHADOW_REGISTER(shadow_config_index)
  102. + hal_soc->dev_base_addr;
  103. hal_debug("hp_addr=%pK dev base addr %pK index %u",
  104. srng->u.src_ring.hp_addr,
  105. hal_soc->dev_base_addr, shadow_config_index);
  106. }
  107. }
  108. QDF_STATUS hal_set_one_shadow_config(void *hal_soc,
  109. int ring_type,
  110. int ring_num)
  111. {
  112. uint32_t target_register;
  113. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  114. struct hal_hw_srng_config *srng_config = &hal->hw_srng_table[ring_type];
  115. int shadow_config_index = hal->num_shadow_registers_configured;
  116. if (shadow_config_index >= MAX_SHADOW_REGISTERS) {
  117. QDF_ASSERT(0);
  118. return QDF_STATUS_E_RESOURCES;
  119. }
  120. hal->num_shadow_registers_configured++;
  121. target_register = srng_config->reg_start[HP_OFFSET_IN_REG_START];
  122. target_register += (srng_config->reg_size[HP_OFFSET_IN_REG_START]
  123. *ring_num);
  124. /* if the ring is a dst ring, we need to shadow the tail pointer */
  125. if (srng_config->ring_dir == HAL_SRNG_DST_RING)
  126. target_register += OFFSET_FROM_HP_TO_TP;
  127. hal->shadow_config[shadow_config_index].addr = target_register;
  128. /* update hp/tp addr in the hal_soc structure*/
  129. hal_update_srng_hp_tp_address(hal_soc, shadow_config_index, ring_type,
  130. ring_num);
  131. hal_debug("target_reg %x, shadow register 0x%x shadow_index 0x%x, ring_type %d, ring num %d",
  132. target_register,
  133. SHADOW_REGISTER(shadow_config_index),
  134. shadow_config_index,
  135. ring_type, ring_num);
  136. return QDF_STATUS_SUCCESS;
  137. }
  138. qdf_export_symbol(hal_set_one_shadow_config);
  139. QDF_STATUS hal_construct_shadow_config(void *hal_soc)
  140. {
  141. int ring_type, ring_num;
  142. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  143. for (ring_type = 0; ring_type < MAX_RING_TYPES; ring_type++) {
  144. struct hal_hw_srng_config *srng_config =
  145. &hal->hw_srng_table[ring_type];
  146. if (ring_type == CE_SRC ||
  147. ring_type == CE_DST ||
  148. ring_type == CE_DST_STATUS)
  149. continue;
  150. if (srng_config->lmac_ring)
  151. continue;
  152. for (ring_num = 0; ring_num < srng_config->max_rings;
  153. ring_num++)
  154. hal_set_one_shadow_config(hal_soc, ring_type, ring_num);
  155. }
  156. return QDF_STATUS_SUCCESS;
  157. }
  158. qdf_export_symbol(hal_construct_shadow_config);
  159. void hal_get_shadow_config(void *hal_soc,
  160. struct pld_shadow_reg_v2_cfg **shadow_config,
  161. int *num_shadow_registers_configured)
  162. {
  163. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  164. *shadow_config = hal->shadow_config;
  165. *num_shadow_registers_configured =
  166. hal->num_shadow_registers_configured;
  167. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  168. "%s", __func__);
  169. }
  170. qdf_export_symbol(hal_get_shadow_config);
  171. static void hal_validate_shadow_register(struct hal_soc *hal,
  172. uint32_t *destination,
  173. uint32_t *shadow_address)
  174. {
  175. unsigned int index;
  176. uint32_t *shadow_0_offset = SHADOW_REGISTER(0) + hal->dev_base_addr;
  177. int destination_ba_offset =
  178. ((char *)destination) - (char *)hal->dev_base_addr;
  179. index = shadow_address - shadow_0_offset;
  180. if (index >= MAX_SHADOW_REGISTERS) {
  181. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  182. "%s: index %x out of bounds", __func__, index);
  183. goto error;
  184. } else if (hal->shadow_config[index].addr != destination_ba_offset) {
  185. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  186. "%s: sanity check failure, expected %x, found %x",
  187. __func__, destination_ba_offset,
  188. hal->shadow_config[index].addr);
  189. goto error;
  190. }
  191. return;
  192. error:
  193. qdf_print("%s: baddr %pK, desination %pK, shadow_address %pK s0offset %pK index %x",
  194. __func__, hal->dev_base_addr, destination, shadow_address,
  195. shadow_0_offset, index);
  196. QDF_BUG(0);
  197. return;
  198. }
  199. static void hal_target_based_configure(struct hal_soc *hal)
  200. {
  201. switch (hal->target_type) {
  202. #ifdef QCA_WIFI_QCA6290
  203. case TARGET_TYPE_QCA6290:
  204. hal->use_register_windowing = true;
  205. hal_qca6290_attach(hal);
  206. break;
  207. #endif
  208. #ifdef QCA_WIFI_QCA6390
  209. case TARGET_TYPE_QCA6390:
  210. hal->use_register_windowing = true;
  211. hal_qca6390_attach(hal);
  212. break;
  213. #endif
  214. #ifdef QCA_WIFI_QCA6490
  215. case TARGET_TYPE_QCA6490:
  216. hal->use_register_windowing = true;
  217. hal_qca6490_attach(hal);
  218. break;
  219. #endif
  220. #if defined(QCA_WIFI_QCA8074) && defined(WIFI_TARGET_TYPE_3_0)
  221. case TARGET_TYPE_QCA8074:
  222. hal_qca8074_attach(hal);
  223. break;
  224. #endif
  225. #if defined(QCA_WIFI_QCA8074V2)
  226. case TARGET_TYPE_QCA8074V2:
  227. hal_qca8074v2_attach(hal);
  228. break;
  229. #endif
  230. #if defined(QCA_WIFI_QCA6018)
  231. case TARGET_TYPE_QCA6018:
  232. hal_qca8074v2_attach(hal);
  233. break;
  234. #endif
  235. #ifdef QCA_WIFI_QCN9000
  236. case TARGET_TYPE_QCN9000:
  237. hal->use_register_windowing = true;
  238. hal_qcn9000_attach(hal);
  239. break;
  240. #endif
  241. default:
  242. break;
  243. }
  244. }
  245. uint32_t hal_get_target_type(hal_soc_handle_t hal_soc_hdl)
  246. {
  247. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  248. struct hif_target_info *tgt_info =
  249. hif_get_target_info_handle(hal_soc->hif_handle);
  250. return tgt_info->target_type;
  251. }
  252. qdf_export_symbol(hal_get_target_type);
  253. /**
  254. * hal_attach - Initialize HAL layer
  255. * @hif_handle: Opaque HIF handle
  256. * @qdf_dev: QDF device
  257. *
  258. * Return: Opaque HAL SOC handle
  259. * NULL on failure (if given ring is not available)
  260. *
  261. * This function should be called as part of HIF initialization (for accessing
  262. * copy engines). DP layer will get hal_soc handle using hif_get_hal_handle()
  263. *
  264. */
  265. void *hal_attach(struct hif_opaque_softc *hif_handle, qdf_device_t qdf_dev)
  266. {
  267. struct hal_soc *hal;
  268. int i;
  269. hal = qdf_mem_malloc(sizeof(*hal));
  270. if (!hal) {
  271. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  272. "%s: hal_soc allocation failed", __func__);
  273. goto fail0;
  274. }
  275. qdf_minidump_log(hal, sizeof(*hal), "hal_soc");
  276. hal->hif_handle = hif_handle;
  277. hal->dev_base_addr = hif_get_dev_ba(hif_handle);
  278. hal->qdf_dev = qdf_dev;
  279. hal->shadow_rdptr_mem_vaddr = (uint32_t *)qdf_mem_alloc_consistent(
  280. qdf_dev, qdf_dev->dev, sizeof(*(hal->shadow_rdptr_mem_vaddr)) *
  281. HAL_SRNG_ID_MAX, &(hal->shadow_rdptr_mem_paddr));
  282. if (!hal->shadow_rdptr_mem_paddr) {
  283. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  284. "%s: hal->shadow_rdptr_mem_paddr allocation failed",
  285. __func__);
  286. goto fail1;
  287. }
  288. qdf_mem_zero(hal->shadow_rdptr_mem_vaddr,
  289. sizeof(*(hal->shadow_rdptr_mem_vaddr)) * HAL_SRNG_ID_MAX);
  290. hal->shadow_wrptr_mem_vaddr =
  291. (uint32_t *)qdf_mem_alloc_consistent(qdf_dev, qdf_dev->dev,
  292. sizeof(*(hal->shadow_wrptr_mem_vaddr)) * HAL_MAX_LMAC_RINGS,
  293. &(hal->shadow_wrptr_mem_paddr));
  294. if (!hal->shadow_wrptr_mem_vaddr) {
  295. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  296. "%s: hal->shadow_wrptr_mem_vaddr allocation failed",
  297. __func__);
  298. goto fail2;
  299. }
  300. qdf_mem_zero(hal->shadow_wrptr_mem_vaddr,
  301. sizeof(*(hal->shadow_wrptr_mem_vaddr)) * HAL_MAX_LMAC_RINGS);
  302. for (i = 0; i < HAL_SRNG_ID_MAX; i++) {
  303. hal->srng_list[i].initialized = 0;
  304. hal->srng_list[i].ring_id = i;
  305. }
  306. qdf_spinlock_create(&hal->register_access_lock);
  307. hal->register_window = 0;
  308. hal->target_type = hal_get_target_type(hal_soc_to_hal_soc_handle(hal));
  309. hal_target_based_configure(hal);
  310. return (void *)hal;
  311. fail2:
  312. qdf_mem_free_consistent(qdf_dev, qdf_dev->dev,
  313. sizeof(*(hal->shadow_rdptr_mem_vaddr)) * HAL_SRNG_ID_MAX,
  314. hal->shadow_rdptr_mem_vaddr, hal->shadow_rdptr_mem_paddr, 0);
  315. fail1:
  316. qdf_mem_free(hal);
  317. fail0:
  318. return NULL;
  319. }
  320. qdf_export_symbol(hal_attach);
  321. /**
  322. * hal_mem_info - Retrieve hal memory base address
  323. *
  324. * @hal_soc: Opaque HAL SOC handle
  325. * @mem: pointer to structure to be updated with hal mem info
  326. */
  327. void hal_get_meminfo(hal_soc_handle_t hal_soc_hdl, struct hal_mem_info *mem)
  328. {
  329. struct hal_soc *hal = (struct hal_soc *)hal_soc_hdl;
  330. mem->dev_base_addr = (void *)hal->dev_base_addr;
  331. mem->shadow_rdptr_mem_vaddr = (void *)hal->shadow_rdptr_mem_vaddr;
  332. mem->shadow_wrptr_mem_vaddr = (void *)hal->shadow_wrptr_mem_vaddr;
  333. mem->shadow_rdptr_mem_paddr = (void *)hal->shadow_rdptr_mem_paddr;
  334. mem->shadow_wrptr_mem_paddr = (void *)hal->shadow_wrptr_mem_paddr;
  335. hif_read_phy_mem_base((void *)hal->hif_handle,
  336. (qdf_dma_addr_t *)&mem->dev_base_paddr);
  337. return;
  338. }
  339. qdf_export_symbol(hal_get_meminfo);
  340. /**
  341. * hal_detach - Detach HAL layer
  342. * @hal_soc: HAL SOC handle
  343. *
  344. * Return: Opaque HAL SOC handle
  345. * NULL on failure (if given ring is not available)
  346. *
  347. * This function should be called as part of HIF initialization (for accessing
  348. * copy engines). DP layer will get hal_soc handle using hif_get_hal_handle()
  349. *
  350. */
  351. extern void hal_detach(void *hal_soc)
  352. {
  353. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  354. qdf_mem_free_consistent(hal->qdf_dev, hal->qdf_dev->dev,
  355. sizeof(*(hal->shadow_rdptr_mem_vaddr)) * HAL_SRNG_ID_MAX,
  356. hal->shadow_rdptr_mem_vaddr, hal->shadow_rdptr_mem_paddr, 0);
  357. qdf_mem_free_consistent(hal->qdf_dev, hal->qdf_dev->dev,
  358. sizeof(*(hal->shadow_wrptr_mem_vaddr)) * HAL_MAX_LMAC_RINGS,
  359. hal->shadow_wrptr_mem_vaddr, hal->shadow_wrptr_mem_paddr, 0);
  360. qdf_minidump_remove(hal);
  361. qdf_mem_free(hal);
  362. return;
  363. }
  364. qdf_export_symbol(hal_detach);
  365. /**
  366. * hal_ce_dst_setup - Initialize CE destination ring registers
  367. * @hal_soc: HAL SOC handle
  368. * @srng: SRNG ring pointer
  369. */
  370. static inline void hal_ce_dst_setup(struct hal_soc *hal, struct hal_srng *srng,
  371. int ring_num)
  372. {
  373. uint32_t reg_val = 0;
  374. uint32_t reg_addr;
  375. struct hal_hw_srng_config *ring_config =
  376. HAL_SRNG_CONFIG(hal, CE_DST);
  377. /* set DEST_MAX_LENGTH according to ce assignment */
  378. reg_addr = HWIO_WFSS_CE_CHANNEL_DST_R0_DEST_CTRL_ADDR(
  379. ring_config->reg_start[R0_INDEX] +
  380. (ring_num * ring_config->reg_size[R0_INDEX]));
  381. reg_val = HAL_REG_READ(hal, reg_addr);
  382. reg_val &= ~HWIO_WFSS_CE_CHANNEL_DST_R0_DEST_CTRL_DEST_MAX_LENGTH_BMSK;
  383. reg_val |= srng->u.dst_ring.max_buffer_length &
  384. HWIO_WFSS_CE_CHANNEL_DST_R0_DEST_CTRL_DEST_MAX_LENGTH_BMSK;
  385. HAL_REG_WRITE(hal, reg_addr, reg_val);
  386. }
  387. /**
  388. * hal_reo_read_write_ctrl_ix - Read or write REO_DESTINATION_RING_CTRL_IX
  389. * @hal: HAL SOC handle
  390. * @read: boolean value to indicate if read or write
  391. * @ix0: pointer to store IX0 reg value
  392. * @ix1: pointer to store IX1 reg value
  393. * @ix2: pointer to store IX2 reg value
  394. * @ix3: pointer to store IX3 reg value
  395. */
  396. void hal_reo_read_write_ctrl_ix(hal_soc_handle_t hal_soc_hdl, bool read,
  397. uint32_t *ix0, uint32_t *ix1,
  398. uint32_t *ix2, uint32_t *ix3)
  399. {
  400. uint32_t reg_offset;
  401. struct hal_soc *hal = (struct hal_soc *)hal_soc_hdl;
  402. if (read) {
  403. if (ix0) {
  404. reg_offset =
  405. HWIO_REO_R0_DESTINATION_RING_CTRL_IX_0_ADDR(
  406. SEQ_WCSS_UMAC_REO_REG_OFFSET);
  407. *ix0 = HAL_REG_READ(hal, reg_offset);
  408. }
  409. if (ix1) {
  410. reg_offset =
  411. HWIO_REO_R0_DESTINATION_RING_CTRL_IX_1_ADDR(
  412. SEQ_WCSS_UMAC_REO_REG_OFFSET);
  413. *ix1 = HAL_REG_READ(hal, reg_offset);
  414. }
  415. if (ix2) {
  416. reg_offset =
  417. HWIO_REO_R0_DESTINATION_RING_CTRL_IX_2_ADDR(
  418. SEQ_WCSS_UMAC_REO_REG_OFFSET);
  419. *ix2 = HAL_REG_READ(hal, reg_offset);
  420. }
  421. if (ix3) {
  422. reg_offset =
  423. HWIO_REO_R0_DESTINATION_RING_CTRL_IX_3_ADDR(
  424. SEQ_WCSS_UMAC_REO_REG_OFFSET);
  425. *ix3 = HAL_REG_READ(hal, reg_offset);
  426. }
  427. } else {
  428. if (ix0) {
  429. reg_offset =
  430. HWIO_REO_R0_DESTINATION_RING_CTRL_IX_0_ADDR(
  431. SEQ_WCSS_UMAC_REO_REG_OFFSET);
  432. HAL_REG_WRITE(hal, reg_offset, *ix0);
  433. }
  434. if (ix1) {
  435. reg_offset =
  436. HWIO_REO_R0_DESTINATION_RING_CTRL_IX_1_ADDR(
  437. SEQ_WCSS_UMAC_REO_REG_OFFSET);
  438. HAL_REG_WRITE(hal, reg_offset, *ix1);
  439. }
  440. if (ix2) {
  441. reg_offset =
  442. HWIO_REO_R0_DESTINATION_RING_CTRL_IX_2_ADDR(
  443. SEQ_WCSS_UMAC_REO_REG_OFFSET);
  444. HAL_REG_WRITE(hal, reg_offset, *ix2);
  445. }
  446. if (ix3) {
  447. reg_offset =
  448. HWIO_REO_R0_DESTINATION_RING_CTRL_IX_3_ADDR(
  449. SEQ_WCSS_UMAC_REO_REG_OFFSET);
  450. HAL_REG_WRITE(hal, reg_offset, *ix3);
  451. }
  452. }
  453. }
  454. /**
  455. * hal_srng_dst_set_hp_paddr() - Set physical address to dest ring head pointer
  456. * @srng: sring pointer
  457. * @paddr: physical address
  458. */
  459. void hal_srng_dst_set_hp_paddr(struct hal_srng *srng,
  460. uint64_t paddr)
  461. {
  462. SRNG_DST_REG_WRITE(srng, HP_ADDR_LSB,
  463. paddr & 0xffffffff);
  464. SRNG_DST_REG_WRITE(srng, HP_ADDR_MSB,
  465. paddr >> 32);
  466. }
  467. /**
  468. * hal_srng_dst_init_hp() - Initilaize destination ring head pointer
  469. * @srng: sring pointer
  470. * @vaddr: virtual address
  471. */
  472. void hal_srng_dst_init_hp(struct hal_srng *srng,
  473. uint32_t *vaddr)
  474. {
  475. if (!srng)
  476. return;
  477. srng->u.dst_ring.hp_addr = vaddr;
  478. SRNG_DST_REG_WRITE(srng, HP, srng->u.dst_ring.cached_hp);
  479. if (vaddr) {
  480. *srng->u.dst_ring.hp_addr = srng->u.dst_ring.cached_hp;
  481. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  482. "hp_addr=%pK, cached_hp=%d, hp=%d",
  483. (void *)srng->u.dst_ring.hp_addr,
  484. srng->u.dst_ring.cached_hp,
  485. *srng->u.dst_ring.hp_addr);
  486. }
  487. }
  488. /**
  489. * hal_srng_hw_init - Private function to initialize SRNG HW
  490. * @hal_soc: HAL SOC handle
  491. * @srng: SRNG ring pointer
  492. */
  493. static inline void hal_srng_hw_init(struct hal_soc *hal,
  494. struct hal_srng *srng)
  495. {
  496. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  497. hal_srng_src_hw_init(hal, srng);
  498. else
  499. hal_srng_dst_hw_init(hal, srng);
  500. }
  501. #ifdef CONFIG_SHADOW_V2
  502. #define ignore_shadow false
  503. #define CHECK_SHADOW_REGISTERS true
  504. #else
  505. #define ignore_shadow true
  506. #define CHECK_SHADOW_REGISTERS false
  507. #endif
  508. /**
  509. * hal_srng_setup - Initialize HW SRNG ring.
  510. * @hal_soc: Opaque HAL SOC handle
  511. * @ring_type: one of the types from hal_ring_type
  512. * @ring_num: Ring number if there are multiple rings of same type (staring
  513. * from 0)
  514. * @mac_id: valid MAC Id should be passed if ring type is one of lmac rings
  515. * @ring_params: SRNG ring params in hal_srng_params structure.
  516. * Callers are expected to allocate contiguous ring memory of size
  517. * 'num_entries * entry_size' bytes and pass the physical and virtual base
  518. * addresses through 'ring_base_paddr' and 'ring_base_vaddr' in
  519. * hal_srng_params structure. Ring base address should be 8 byte aligned
  520. * and size of each ring entry should be queried using the API
  521. * hal_srng_get_entrysize
  522. *
  523. * Return: Opaque pointer to ring on success
  524. * NULL on failure (if given ring is not available)
  525. */
  526. void *hal_srng_setup(void *hal_soc, int ring_type, int ring_num,
  527. int mac_id, struct hal_srng_params *ring_params)
  528. {
  529. int ring_id;
  530. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  531. struct hal_srng *srng;
  532. struct hal_hw_srng_config *ring_config =
  533. HAL_SRNG_CONFIG(hal, ring_type);
  534. void *dev_base_addr;
  535. int i;
  536. ring_id = hal_get_srng_ring_id(hal_soc, ring_type, ring_num, mac_id);
  537. if (ring_id < 0)
  538. return NULL;
  539. hal_verbose_debug("mac_id %d ring_id %d", mac_id, ring_id);
  540. srng = hal_get_srng(hal_soc, ring_id);
  541. if (srng->initialized) {
  542. hal_verbose_debug("Ring (ring_type, ring_num) already initialized");
  543. return NULL;
  544. }
  545. dev_base_addr = hal->dev_base_addr;
  546. srng->ring_id = ring_id;
  547. srng->ring_dir = ring_config->ring_dir;
  548. srng->ring_base_paddr = ring_params->ring_base_paddr;
  549. srng->ring_base_vaddr = ring_params->ring_base_vaddr;
  550. srng->entry_size = ring_config->entry_size;
  551. srng->num_entries = ring_params->num_entries;
  552. srng->ring_size = srng->num_entries * srng->entry_size;
  553. srng->ring_size_mask = srng->ring_size - 1;
  554. srng->msi_addr = ring_params->msi_addr;
  555. srng->msi_data = ring_params->msi_data;
  556. srng->intr_timer_thres_us = ring_params->intr_timer_thres_us;
  557. srng->intr_batch_cntr_thres_entries =
  558. ring_params->intr_batch_cntr_thres_entries;
  559. srng->hal_soc = hal_soc;
  560. for (i = 0 ; i < MAX_SRNG_REG_GROUPS; i++) {
  561. srng->hwreg_base[i] = dev_base_addr + ring_config->reg_start[i]
  562. + (ring_num * ring_config->reg_size[i]);
  563. }
  564. /* Zero out the entire ring memory */
  565. qdf_mem_zero(srng->ring_base_vaddr, (srng->entry_size *
  566. srng->num_entries) << 2);
  567. srng->flags = ring_params->flags;
  568. #ifdef BIG_ENDIAN_HOST
  569. /* TODO: See if we should we get these flags from caller */
  570. srng->flags |= HAL_SRNG_DATA_TLV_SWAP;
  571. srng->flags |= HAL_SRNG_MSI_SWAP;
  572. srng->flags |= HAL_SRNG_RING_PTR_SWAP;
  573. #endif
  574. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  575. srng->u.src_ring.hp = 0;
  576. srng->u.src_ring.reap_hp = srng->ring_size -
  577. srng->entry_size;
  578. srng->u.src_ring.tp_addr =
  579. &(hal->shadow_rdptr_mem_vaddr[ring_id]);
  580. srng->u.src_ring.low_threshold =
  581. ring_params->low_threshold * srng->entry_size;
  582. if (ring_config->lmac_ring) {
  583. /* For LMAC rings, head pointer updates will be done
  584. * through FW by writing to a shared memory location
  585. */
  586. srng->u.src_ring.hp_addr =
  587. &(hal->shadow_wrptr_mem_vaddr[ring_id -
  588. HAL_SRNG_LMAC1_ID_START]);
  589. srng->flags |= HAL_SRNG_LMAC_RING;
  590. } else if (ignore_shadow || (srng->u.src_ring.hp_addr == 0)) {
  591. srng->u.src_ring.hp_addr = SRNG_SRC_ADDR(srng, HP);
  592. if (CHECK_SHADOW_REGISTERS) {
  593. QDF_TRACE(QDF_MODULE_ID_TXRX,
  594. QDF_TRACE_LEVEL_ERROR,
  595. "%s: Ring (%d, %d) missing shadow config",
  596. __func__, ring_type, ring_num);
  597. }
  598. } else {
  599. hal_validate_shadow_register(hal,
  600. SRNG_SRC_ADDR(srng, HP),
  601. srng->u.src_ring.hp_addr);
  602. }
  603. } else {
  604. /* During initialization loop count in all the descriptors
  605. * will be set to zero, and HW will set it to 1 on completing
  606. * descriptor update in first loop, and increments it by 1 on
  607. * subsequent loops (loop count wraps around after reaching
  608. * 0xffff). The 'loop_cnt' in SW ring state is the expected
  609. * loop count in descriptors updated by HW (to be processed
  610. * by SW).
  611. */
  612. srng->u.dst_ring.loop_cnt = 1;
  613. srng->u.dst_ring.tp = 0;
  614. srng->u.dst_ring.hp_addr =
  615. &(hal->shadow_rdptr_mem_vaddr[ring_id]);
  616. if (ring_config->lmac_ring) {
  617. /* For LMAC rings, tail pointer updates will be done
  618. * through FW by writing to a shared memory location
  619. */
  620. srng->u.dst_ring.tp_addr =
  621. &(hal->shadow_wrptr_mem_vaddr[ring_id -
  622. HAL_SRNG_LMAC1_ID_START]);
  623. srng->flags |= HAL_SRNG_LMAC_RING;
  624. } else if (ignore_shadow || srng->u.dst_ring.tp_addr == 0) {
  625. srng->u.dst_ring.tp_addr = SRNG_DST_ADDR(srng, TP);
  626. if (CHECK_SHADOW_REGISTERS) {
  627. QDF_TRACE(QDF_MODULE_ID_TXRX,
  628. QDF_TRACE_LEVEL_ERROR,
  629. "%s: Ring (%d, %d) missing shadow config",
  630. __func__, ring_type, ring_num);
  631. }
  632. } else {
  633. hal_validate_shadow_register(hal,
  634. SRNG_DST_ADDR(srng, TP),
  635. srng->u.dst_ring.tp_addr);
  636. }
  637. }
  638. if (!(ring_config->lmac_ring)) {
  639. hal_srng_hw_init(hal, srng);
  640. if (ring_type == CE_DST) {
  641. srng->u.dst_ring.max_buffer_length = ring_params->max_buffer_length;
  642. hal_ce_dst_setup(hal, srng, ring_num);
  643. }
  644. }
  645. SRNG_LOCK_INIT(&srng->lock);
  646. srng->srng_event = 0;
  647. srng->initialized = true;
  648. return (void *)srng;
  649. }
  650. qdf_export_symbol(hal_srng_setup);
  651. /**
  652. * hal_srng_cleanup - Deinitialize HW SRNG ring.
  653. * @hal_soc: Opaque HAL SOC handle
  654. * @hal_srng: Opaque HAL SRNG pointer
  655. */
  656. void hal_srng_cleanup(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  657. {
  658. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  659. SRNG_LOCK_DESTROY(&srng->lock);
  660. srng->initialized = 0;
  661. }
  662. qdf_export_symbol(hal_srng_cleanup);
  663. /**
  664. * hal_srng_get_entrysize - Returns size of ring entry in bytes
  665. * @hal_soc: Opaque HAL SOC handle
  666. * @ring_type: one of the types from hal_ring_type
  667. *
  668. */
  669. uint32_t hal_srng_get_entrysize(void *hal_soc, int ring_type)
  670. {
  671. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  672. struct hal_hw_srng_config *ring_config =
  673. HAL_SRNG_CONFIG(hal, ring_type);
  674. return ring_config->entry_size << 2;
  675. }
  676. qdf_export_symbol(hal_srng_get_entrysize);
  677. /**
  678. * hal_srng_max_entries - Returns maximum possible number of ring entries
  679. * @hal_soc: Opaque HAL SOC handle
  680. * @ring_type: one of the types from hal_ring_type
  681. *
  682. * Return: Maximum number of entries for the given ring_type
  683. */
  684. uint32_t hal_srng_max_entries(void *hal_soc, int ring_type)
  685. {
  686. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  687. struct hal_hw_srng_config *ring_config =
  688. HAL_SRNG_CONFIG(hal, ring_type);
  689. return ring_config->max_size / ring_config->entry_size;
  690. }
  691. qdf_export_symbol(hal_srng_max_entries);
  692. enum hal_srng_dir hal_srng_get_dir(void *hal_soc, int ring_type)
  693. {
  694. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  695. struct hal_hw_srng_config *ring_config =
  696. HAL_SRNG_CONFIG(hal, ring_type);
  697. return ring_config->ring_dir;
  698. }
  699. /**
  700. * hal_srng_dump - Dump ring status
  701. * @srng: hal srng pointer
  702. */
  703. void hal_srng_dump(struct hal_srng *srng)
  704. {
  705. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  706. qdf_print("=== SRC RING %d ===", srng->ring_id);
  707. qdf_print("hp %u, reap_hp %u, tp %u, cached tp %u",
  708. srng->u.src_ring.hp,
  709. srng->u.src_ring.reap_hp,
  710. *srng->u.src_ring.tp_addr,
  711. srng->u.src_ring.cached_tp);
  712. } else {
  713. qdf_print("=== DST RING %d ===", srng->ring_id);
  714. qdf_print("tp %u, hp %u, cached tp %u, loop_cnt %u",
  715. srng->u.dst_ring.tp,
  716. *srng->u.dst_ring.hp_addr,
  717. srng->u.dst_ring.cached_hp,
  718. srng->u.dst_ring.loop_cnt);
  719. }
  720. }
  721. /**
  722. * hal_get_srng_params - Retrieve SRNG parameters for a given ring from HAL
  723. *
  724. * @hal_soc: Opaque HAL SOC handle
  725. * @hal_ring: Ring pointer (Source or Destination ring)
  726. * @ring_params: SRNG parameters will be returned through this structure
  727. */
  728. extern void hal_get_srng_params(hal_soc_handle_t hal_soc_hdl,
  729. hal_ring_handle_t hal_ring_hdl,
  730. struct hal_srng_params *ring_params)
  731. {
  732. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  733. int i =0;
  734. ring_params->ring_id = srng->ring_id;
  735. ring_params->ring_dir = srng->ring_dir;
  736. ring_params->entry_size = srng->entry_size;
  737. ring_params->ring_base_paddr = srng->ring_base_paddr;
  738. ring_params->ring_base_vaddr = srng->ring_base_vaddr;
  739. ring_params->num_entries = srng->num_entries;
  740. ring_params->msi_addr = srng->msi_addr;
  741. ring_params->msi_data = srng->msi_data;
  742. ring_params->intr_timer_thres_us = srng->intr_timer_thres_us;
  743. ring_params->intr_batch_cntr_thres_entries =
  744. srng->intr_batch_cntr_thres_entries;
  745. ring_params->low_threshold = srng->u.src_ring.low_threshold;
  746. ring_params->flags = srng->flags;
  747. ring_params->ring_id = srng->ring_id;
  748. for (i = 0 ; i < MAX_SRNG_REG_GROUPS; i++)
  749. ring_params->hwreg_base[i] = srng->hwreg_base[i];
  750. }
  751. qdf_export_symbol(hal_get_srng_params);