hal_srng.c 21 KB

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