hal_srng.c 25 KB

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