hal_srng.c 24 KB

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