hal_srng.c 24 KB

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