hal_srng.c 26 KB

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