hal_srng.c 24 KB

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