hal_srng.c 24 KB

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