hal_srng.c 22 KB

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