1 // SPDX-License-Identifier: BSD-3-Clause-Clear
3 * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
5 #include <linux/dma-mapping.h>
11 static const struct hal_srng_config hw_srng_config_template[] = {
12 /* TODO: max_rings can populated by querying HW capabilities */
14 .start_ring_id = HAL_SRNG_RING_ID_REO2SW1,
16 .entry_size = sizeof(struct hal_reo_dest_ring) >> 2,
18 .ring_dir = HAL_SRNG_DIR_DST,
19 .max_size = HAL_REO_REO2SW1_RING_BASE_MSB_RING_SIZE,
22 /* Designating REO2TCL ring as exception ring. This ring is
23 * similar to other REO2SW rings though it is named as REO2TCL.
24 * Any of theREO2SW rings can be used as exception ring.
26 .start_ring_id = HAL_SRNG_RING_ID_REO2TCL,
28 .entry_size = sizeof(struct hal_reo_dest_ring) >> 2,
30 .ring_dir = HAL_SRNG_DIR_DST,
31 .max_size = HAL_REO_REO2TCL_RING_BASE_MSB_RING_SIZE,
34 .start_ring_id = HAL_SRNG_RING_ID_SW2REO,
36 .entry_size = sizeof(struct hal_reo_entrance_ring) >> 2,
38 .ring_dir = HAL_SRNG_DIR_SRC,
39 .max_size = HAL_REO_SW2REO_RING_BASE_MSB_RING_SIZE,
42 .start_ring_id = HAL_SRNG_RING_ID_REO_CMD,
44 .entry_size = (sizeof(struct hal_tlv_hdr) +
45 sizeof(struct hal_reo_get_queue_stats)) >> 2,
47 .ring_dir = HAL_SRNG_DIR_SRC,
48 .max_size = HAL_REO_CMD_RING_BASE_MSB_RING_SIZE,
51 .start_ring_id = HAL_SRNG_RING_ID_REO_STATUS,
53 .entry_size = (sizeof(struct hal_tlv_hdr) +
54 sizeof(struct hal_reo_get_queue_stats_status)) >> 2,
56 .ring_dir = HAL_SRNG_DIR_DST,
57 .max_size = HAL_REO_STATUS_RING_BASE_MSB_RING_SIZE,
60 .start_ring_id = HAL_SRNG_RING_ID_SW2TCL1,
62 .entry_size = (sizeof(struct hal_tlv_hdr) +
63 sizeof(struct hal_tcl_data_cmd)) >> 2,
65 .ring_dir = HAL_SRNG_DIR_SRC,
66 .max_size = HAL_SW2TCL1_RING_BASE_MSB_RING_SIZE,
69 .start_ring_id = HAL_SRNG_RING_ID_SW2TCL_CMD,
71 .entry_size = (sizeof(struct hal_tlv_hdr) +
72 sizeof(struct hal_tcl_gse_cmd)) >> 2,
74 .ring_dir = HAL_SRNG_DIR_SRC,
75 .max_size = HAL_SW2TCL1_CMD_RING_BASE_MSB_RING_SIZE,
78 .start_ring_id = HAL_SRNG_RING_ID_TCL_STATUS,
80 .entry_size = (sizeof(struct hal_tlv_hdr) +
81 sizeof(struct hal_tcl_status_ring)) >> 2,
83 .ring_dir = HAL_SRNG_DIR_DST,
84 .max_size = HAL_TCL_STATUS_RING_BASE_MSB_RING_SIZE,
87 .start_ring_id = HAL_SRNG_RING_ID_CE0_SRC,
89 .entry_size = sizeof(struct hal_ce_srng_src_desc) >> 2,
91 .ring_dir = HAL_SRNG_DIR_SRC,
92 .max_size = HAL_CE_SRC_RING_BASE_MSB_RING_SIZE,
95 .start_ring_id = HAL_SRNG_RING_ID_CE0_DST,
97 .entry_size = sizeof(struct hal_ce_srng_dest_desc) >> 2,
99 .ring_dir = HAL_SRNG_DIR_SRC,
100 .max_size = HAL_CE_DST_RING_BASE_MSB_RING_SIZE,
102 { /* CE_DST_STATUS */
103 .start_ring_id = HAL_SRNG_RING_ID_CE0_DST_STATUS,
105 .entry_size = sizeof(struct hal_ce_srng_dst_status_desc) >> 2,
107 .ring_dir = HAL_SRNG_DIR_DST,
108 .max_size = HAL_CE_DST_STATUS_RING_BASE_MSB_RING_SIZE,
110 { /* WBM_IDLE_LINK */
111 .start_ring_id = HAL_SRNG_RING_ID_WBM_IDLE_LINK,
113 .entry_size = sizeof(struct hal_wbm_link_desc) >> 2,
115 .ring_dir = HAL_SRNG_DIR_SRC,
116 .max_size = HAL_WBM_IDLE_LINK_RING_BASE_MSB_RING_SIZE,
118 { /* SW2WBM_RELEASE */
119 .start_ring_id = HAL_SRNG_RING_ID_WBM_SW_RELEASE,
121 .entry_size = sizeof(struct hal_wbm_release_ring) >> 2,
123 .ring_dir = HAL_SRNG_DIR_SRC,
124 .max_size = HAL_SW2WBM_RELEASE_RING_BASE_MSB_RING_SIZE,
126 { /* WBM2SW_RELEASE */
127 .start_ring_id = HAL_SRNG_RING_ID_WBM2SW0_RELEASE,
129 .entry_size = sizeof(struct hal_wbm_release_ring) >> 2,
131 .ring_dir = HAL_SRNG_DIR_DST,
132 .max_size = HAL_WBM2SW_RELEASE_RING_BASE_MSB_RING_SIZE,
135 .start_ring_id = HAL_SRNG_RING_ID_WMAC1_SW2RXDMA0_BUF,
137 .entry_size = sizeof(struct hal_wbm_buffer_ring) >> 2,
139 .ring_dir = HAL_SRNG_DIR_SRC,
140 .max_size = HAL_RXDMA_RING_MAX_SIZE,
143 .start_ring_id = HAL_SRNG_RING_ID_WMAC1_RXDMA2SW0,
145 .entry_size = sizeof(struct hal_reo_entrance_ring) >> 2,
147 .ring_dir = HAL_SRNG_DIR_DST,
148 .max_size = HAL_RXDMA_RING_MAX_SIZE,
150 { /* RXDMA_MONITOR_BUF */
151 .start_ring_id = HAL_SRNG_RING_ID_WMAC1_SW2RXDMA2_BUF,
153 .entry_size = sizeof(struct hal_wbm_buffer_ring) >> 2,
155 .ring_dir = HAL_SRNG_DIR_SRC,
156 .max_size = HAL_RXDMA_RING_MAX_SIZE,
158 { /* RXDMA_MONITOR_STATUS */
159 .start_ring_id = HAL_SRNG_RING_ID_WMAC1_SW2RXDMA1_STATBUF,
161 .entry_size = sizeof(struct hal_wbm_buffer_ring) >> 2,
163 .ring_dir = HAL_SRNG_DIR_SRC,
164 .max_size = HAL_RXDMA_RING_MAX_SIZE,
166 { /* RXDMA_MONITOR_DST */
167 .start_ring_id = HAL_SRNG_RING_ID_WMAC1_RXDMA2SW1,
169 .entry_size = sizeof(struct hal_reo_entrance_ring) >> 2,
171 .ring_dir = HAL_SRNG_DIR_DST,
172 .max_size = HAL_RXDMA_RING_MAX_SIZE,
174 { /* RXDMA_MONITOR_DESC */
175 .start_ring_id = HAL_SRNG_RING_ID_WMAC1_SW2RXDMA1_DESC,
177 .entry_size = sizeof(struct hal_wbm_buffer_ring) >> 2,
179 .ring_dir = HAL_SRNG_DIR_SRC,
180 .max_size = HAL_RXDMA_RING_MAX_SIZE,
182 { /* RXDMA DIR BUF */
183 .start_ring_id = HAL_SRNG_RING_ID_RXDMA_DIR_BUF,
185 .entry_size = 8 >> 2, /* TODO: Define the struct */
187 .ring_dir = HAL_SRNG_DIR_SRC,
188 .max_size = HAL_RXDMA_RING_MAX_SIZE,
192 static int ath11k_hal_alloc_cont_rdp(struct ath11k_base *ab)
194 struct ath11k_hal *hal = &ab->hal;
197 size = sizeof(u32) * HAL_SRNG_RING_ID_MAX;
198 hal->rdp.vaddr = dma_alloc_coherent(ab->dev, size, &hal->rdp.paddr,
206 static void ath11k_hal_free_cont_rdp(struct ath11k_base *ab)
208 struct ath11k_hal *hal = &ab->hal;
214 size = sizeof(u32) * HAL_SRNG_RING_ID_MAX;
215 dma_free_coherent(ab->dev, size,
216 hal->rdp.vaddr, hal->rdp.paddr);
217 hal->rdp.vaddr = NULL;
220 static int ath11k_hal_alloc_cont_wrp(struct ath11k_base *ab)
222 struct ath11k_hal *hal = &ab->hal;
225 size = sizeof(u32) * HAL_SRNG_NUM_LMAC_RINGS;
226 hal->wrp.vaddr = dma_alloc_coherent(ab->dev, size, &hal->wrp.paddr,
234 static void ath11k_hal_free_cont_wrp(struct ath11k_base *ab)
236 struct ath11k_hal *hal = &ab->hal;
242 size = sizeof(u32) * HAL_SRNG_NUM_LMAC_RINGS;
243 dma_free_coherent(ab->dev, size,
244 hal->wrp.vaddr, hal->wrp.paddr);
245 hal->wrp.vaddr = NULL;
248 static void ath11k_hal_ce_dst_setup(struct ath11k_base *ab,
249 struct hal_srng *srng, int ring_num)
251 struct hal_srng_config *srng_config = &ab->hal.srng_config[HAL_CE_DST];
255 addr = HAL_CE_DST_RING_CTRL +
256 srng_config->reg_start[HAL_SRNG_REG_GRP_R0] +
257 ring_num * srng_config->reg_size[HAL_SRNG_REG_GRP_R0];
259 val = ath11k_hif_read32(ab, addr);
260 val &= ~HAL_CE_DST_R0_DEST_CTRL_MAX_LEN;
261 val |= FIELD_PREP(HAL_CE_DST_R0_DEST_CTRL_MAX_LEN,
262 srng->u.dst_ring.max_buffer_length);
263 ath11k_hif_write32(ab, addr, val);
266 static void ath11k_hal_srng_dst_hw_init(struct ath11k_base *ab,
267 struct hal_srng *srng)
269 struct ath11k_hal *hal = &ab->hal;
274 reg_base = srng->hwreg_base[HAL_SRNG_REG_GRP_R0];
276 if (srng->flags & HAL_SRNG_FLAGS_MSI_INTR) {
277 ath11k_hif_write32(ab, reg_base +
278 HAL_REO1_RING_MSI1_BASE_LSB_OFFSET(ab),
281 val = FIELD_PREP(HAL_REO1_RING_MSI1_BASE_MSB_ADDR,
282 ((u64)srng->msi_addr >>
283 HAL_ADDR_MSB_REG_SHIFT)) |
284 HAL_REO1_RING_MSI1_BASE_MSB_MSI1_ENABLE;
285 ath11k_hif_write32(ab, reg_base +
286 HAL_REO1_RING_MSI1_BASE_MSB_OFFSET(ab), val);
288 ath11k_hif_write32(ab,
289 reg_base + HAL_REO1_RING_MSI1_DATA_OFFSET(ab),
293 ath11k_hif_write32(ab, reg_base, srng->ring_base_paddr);
295 val = FIELD_PREP(HAL_REO1_RING_BASE_MSB_RING_BASE_ADDR_MSB,
296 ((u64)srng->ring_base_paddr >>
297 HAL_ADDR_MSB_REG_SHIFT)) |
298 FIELD_PREP(HAL_REO1_RING_BASE_MSB_RING_SIZE,
299 (srng->entry_size * srng->num_entries));
300 ath11k_hif_write32(ab, reg_base + HAL_REO1_RING_BASE_MSB_OFFSET(ab), val);
302 val = FIELD_PREP(HAL_REO1_RING_ID_RING_ID, srng->ring_id) |
303 FIELD_PREP(HAL_REO1_RING_ID_ENTRY_SIZE, srng->entry_size);
304 ath11k_hif_write32(ab, reg_base + HAL_REO1_RING_ID_OFFSET(ab), val);
306 /* interrupt setup */
307 val = FIELD_PREP(HAL_REO1_RING_PRDR_INT_SETUP_INTR_TMR_THOLD,
308 (srng->intr_timer_thres_us >> 3));
310 val |= FIELD_PREP(HAL_REO1_RING_PRDR_INT_SETUP_BATCH_COUNTER_THOLD,
311 (srng->intr_batch_cntr_thres_entries *
314 ath11k_hif_write32(ab,
315 reg_base + HAL_REO1_RING_PRODUCER_INT_SETUP_OFFSET(ab),
318 hp_addr = hal->rdp.paddr +
319 ((unsigned long)srng->u.dst_ring.hp_addr -
320 (unsigned long)hal->rdp.vaddr);
321 ath11k_hif_write32(ab, reg_base + HAL_REO1_RING_HP_ADDR_LSB_OFFSET(ab),
322 hp_addr & HAL_ADDR_LSB_REG_MASK);
323 ath11k_hif_write32(ab, reg_base + HAL_REO1_RING_HP_ADDR_MSB_OFFSET(ab),
324 hp_addr >> HAL_ADDR_MSB_REG_SHIFT);
326 /* Initialize head and tail pointers to indicate ring is empty */
327 reg_base = srng->hwreg_base[HAL_SRNG_REG_GRP_R2];
328 ath11k_hif_write32(ab, reg_base, 0);
329 ath11k_hif_write32(ab, reg_base + HAL_REO1_RING_TP_OFFSET(ab), 0);
330 *srng->u.dst_ring.hp_addr = 0;
332 reg_base = srng->hwreg_base[HAL_SRNG_REG_GRP_R0];
334 if (srng->flags & HAL_SRNG_FLAGS_DATA_TLV_SWAP)
335 val |= HAL_REO1_RING_MISC_DATA_TLV_SWAP;
336 if (srng->flags & HAL_SRNG_FLAGS_RING_PTR_SWAP)
337 val |= HAL_REO1_RING_MISC_HOST_FW_SWAP;
338 if (srng->flags & HAL_SRNG_FLAGS_MSI_SWAP)
339 val |= HAL_REO1_RING_MISC_MSI_SWAP;
340 val |= HAL_REO1_RING_MISC_SRNG_ENABLE;
342 ath11k_hif_write32(ab, reg_base + HAL_REO1_RING_MISC_OFFSET(ab), val);
345 static void ath11k_hal_srng_src_hw_init(struct ath11k_base *ab,
346 struct hal_srng *srng)
348 struct ath11k_hal *hal = &ab->hal;
353 reg_base = srng->hwreg_base[HAL_SRNG_REG_GRP_R0];
355 if (srng->flags & HAL_SRNG_FLAGS_MSI_INTR) {
356 ath11k_hif_write32(ab, reg_base +
357 HAL_TCL1_RING_MSI1_BASE_LSB_OFFSET(ab),
360 val = FIELD_PREP(HAL_TCL1_RING_MSI1_BASE_MSB_ADDR,
361 ((u64)srng->msi_addr >>
362 HAL_ADDR_MSB_REG_SHIFT)) |
363 HAL_TCL1_RING_MSI1_BASE_MSB_MSI1_ENABLE;
364 ath11k_hif_write32(ab, reg_base +
365 HAL_TCL1_RING_MSI1_BASE_MSB_OFFSET(ab),
368 ath11k_hif_write32(ab, reg_base +
369 HAL_TCL1_RING_MSI1_DATA_OFFSET(ab),
373 ath11k_hif_write32(ab, reg_base, srng->ring_base_paddr);
375 val = FIELD_PREP(HAL_TCL1_RING_BASE_MSB_RING_BASE_ADDR_MSB,
376 ((u64)srng->ring_base_paddr >>
377 HAL_ADDR_MSB_REG_SHIFT)) |
378 FIELD_PREP(HAL_TCL1_RING_BASE_MSB_RING_SIZE,
379 (srng->entry_size * srng->num_entries));
380 ath11k_hif_write32(ab, reg_base + HAL_TCL1_RING_BASE_MSB_OFFSET(ab), val);
382 val = FIELD_PREP(HAL_REO1_RING_ID_ENTRY_SIZE, srng->entry_size);
383 ath11k_hif_write32(ab, reg_base + HAL_TCL1_RING_ID_OFFSET(ab), val);
385 if (srng->ring_id == HAL_SRNG_RING_ID_WBM_IDLE_LINK) {
386 ath11k_hif_write32(ab, reg_base, (u32)srng->ring_base_paddr);
387 val = FIELD_PREP(HAL_TCL1_RING_BASE_MSB_RING_BASE_ADDR_MSB,
388 ((u64)srng->ring_base_paddr >>
389 HAL_ADDR_MSB_REG_SHIFT)) |
390 FIELD_PREP(HAL_TCL1_RING_BASE_MSB_RING_SIZE,
391 (srng->entry_size * srng->num_entries));
392 ath11k_hif_write32(ab, reg_base + HAL_TCL1_RING_BASE_MSB_OFFSET(ab), val);
395 /* interrupt setup */
396 /* NOTE: IPQ8074 v2 requires the interrupt timer threshold in the
397 * unit of 8 usecs instead of 1 usec (as required by v1).
399 val = FIELD_PREP(HAL_TCL1_RING_CONSR_INT_SETUP_IX0_INTR_TMR_THOLD,
400 srng->intr_timer_thres_us);
402 val |= FIELD_PREP(HAL_TCL1_RING_CONSR_INT_SETUP_IX0_BATCH_COUNTER_THOLD,
403 (srng->intr_batch_cntr_thres_entries *
406 ath11k_hif_write32(ab,
407 reg_base + HAL_TCL1_RING_CONSR_INT_SETUP_IX0_OFFSET(ab),
411 if (srng->flags & HAL_SRNG_FLAGS_LOW_THRESH_INTR_EN) {
412 val |= FIELD_PREP(HAL_TCL1_RING_CONSR_INT_SETUP_IX1_LOW_THOLD,
413 srng->u.src_ring.low_threshold);
415 ath11k_hif_write32(ab,
416 reg_base + HAL_TCL1_RING_CONSR_INT_SETUP_IX1_OFFSET(ab),
419 if (srng->ring_id != HAL_SRNG_RING_ID_WBM_IDLE_LINK) {
420 tp_addr = hal->rdp.paddr +
421 ((unsigned long)srng->u.src_ring.tp_addr -
422 (unsigned long)hal->rdp.vaddr);
423 ath11k_hif_write32(ab,
424 reg_base + HAL_TCL1_RING_TP_ADDR_LSB_OFFSET(ab),
425 tp_addr & HAL_ADDR_LSB_REG_MASK);
426 ath11k_hif_write32(ab,
427 reg_base + HAL_TCL1_RING_TP_ADDR_MSB_OFFSET(ab),
428 tp_addr >> HAL_ADDR_MSB_REG_SHIFT);
431 /* Initialize head and tail pointers to indicate ring is empty */
432 reg_base = srng->hwreg_base[HAL_SRNG_REG_GRP_R2];
433 ath11k_hif_write32(ab, reg_base, 0);
434 ath11k_hif_write32(ab, reg_base + HAL_TCL1_RING_TP_OFFSET, 0);
435 *srng->u.src_ring.tp_addr = 0;
437 reg_base = srng->hwreg_base[HAL_SRNG_REG_GRP_R0];
439 if (srng->flags & HAL_SRNG_FLAGS_DATA_TLV_SWAP)
440 val |= HAL_TCL1_RING_MISC_DATA_TLV_SWAP;
441 if (srng->flags & HAL_SRNG_FLAGS_RING_PTR_SWAP)
442 val |= HAL_TCL1_RING_MISC_HOST_FW_SWAP;
443 if (srng->flags & HAL_SRNG_FLAGS_MSI_SWAP)
444 val |= HAL_TCL1_RING_MISC_MSI_SWAP;
446 /* Loop count is not used for SRC rings */
447 val |= HAL_TCL1_RING_MISC_MSI_LOOPCNT_DISABLE;
449 val |= HAL_TCL1_RING_MISC_SRNG_ENABLE;
451 ath11k_hif_write32(ab, reg_base + HAL_TCL1_RING_MISC_OFFSET(ab), val);
454 static void ath11k_hal_srng_hw_init(struct ath11k_base *ab,
455 struct hal_srng *srng)
457 if (srng->ring_dir == HAL_SRNG_DIR_SRC)
458 ath11k_hal_srng_src_hw_init(ab, srng);
460 ath11k_hal_srng_dst_hw_init(ab, srng);
463 static int ath11k_hal_srng_get_ring_id(struct ath11k_base *ab,
464 enum hal_ring_type type,
465 int ring_num, int mac_id)
467 struct hal_srng_config *srng_config = &ab->hal.srng_config[type];
470 if (ring_num >= srng_config->max_rings) {
471 ath11k_warn(ab, "invalid ring number :%d\n", ring_num);
475 ring_id = srng_config->start_ring_id + ring_num;
476 if (srng_config->lmac_ring)
477 ring_id += mac_id * HAL_SRNG_RINGS_PER_LMAC;
479 if (WARN_ON(ring_id >= HAL_SRNG_RING_ID_MAX))
485 int ath11k_hal_srng_get_entrysize(struct ath11k_base *ab, u32 ring_type)
487 struct hal_srng_config *srng_config;
489 if (WARN_ON(ring_type >= HAL_MAX_RING_TYPES))
492 srng_config = &ab->hal.srng_config[ring_type];
494 return (srng_config->entry_size << 2);
497 int ath11k_hal_srng_get_max_entries(struct ath11k_base *ab, u32 ring_type)
499 struct hal_srng_config *srng_config;
501 if (WARN_ON(ring_type >= HAL_MAX_RING_TYPES))
504 srng_config = &ab->hal.srng_config[ring_type];
506 return (srng_config->max_size / srng_config->entry_size);
509 void ath11k_hal_srng_get_params(struct ath11k_base *ab, struct hal_srng *srng,
510 struct hal_srng_params *params)
512 params->ring_base_paddr = srng->ring_base_paddr;
513 params->ring_base_vaddr = srng->ring_base_vaddr;
514 params->num_entries = srng->num_entries;
515 params->intr_timer_thres_us = srng->intr_timer_thres_us;
516 params->intr_batch_cntr_thres_entries =
517 srng->intr_batch_cntr_thres_entries;
518 params->low_threshold = srng->u.src_ring.low_threshold;
519 params->msi_addr = srng->msi_addr;
520 params->msi_data = srng->msi_data;
521 params->flags = srng->flags;
524 dma_addr_t ath11k_hal_srng_get_hp_addr(struct ath11k_base *ab,
525 struct hal_srng *srng)
527 if (!(srng->flags & HAL_SRNG_FLAGS_LMAC_RING))
530 if (srng->ring_dir == HAL_SRNG_DIR_SRC)
531 return ab->hal.wrp.paddr +
532 ((unsigned long)srng->u.src_ring.hp_addr -
533 (unsigned long)ab->hal.wrp.vaddr);
535 return ab->hal.rdp.paddr +
536 ((unsigned long)srng->u.dst_ring.hp_addr -
537 (unsigned long)ab->hal.rdp.vaddr);
540 dma_addr_t ath11k_hal_srng_get_tp_addr(struct ath11k_base *ab,
541 struct hal_srng *srng)
543 if (!(srng->flags & HAL_SRNG_FLAGS_LMAC_RING))
546 if (srng->ring_dir == HAL_SRNG_DIR_SRC)
547 return ab->hal.rdp.paddr +
548 ((unsigned long)srng->u.src_ring.tp_addr -
549 (unsigned long)ab->hal.rdp.vaddr);
551 return ab->hal.wrp.paddr +
552 ((unsigned long)srng->u.dst_ring.tp_addr -
553 (unsigned long)ab->hal.wrp.vaddr);
556 u32 ath11k_hal_ce_get_desc_size(enum hal_ce_desc type)
559 case HAL_CE_DESC_SRC:
560 return sizeof(struct hal_ce_srng_src_desc);
561 case HAL_CE_DESC_DST:
562 return sizeof(struct hal_ce_srng_dest_desc);
563 case HAL_CE_DESC_DST_STATUS:
564 return sizeof(struct hal_ce_srng_dst_status_desc);
570 void ath11k_hal_ce_src_set_desc(void *buf, dma_addr_t paddr, u32 len, u32 id,
573 struct hal_ce_srng_src_desc *desc = (struct hal_ce_srng_src_desc *)buf;
575 desc->buffer_addr_low = paddr & HAL_ADDR_LSB_REG_MASK;
576 desc->buffer_addr_info =
577 FIELD_PREP(HAL_CE_SRC_DESC_ADDR_INFO_ADDR_HI,
578 ((u64)paddr >> HAL_ADDR_MSB_REG_SHIFT)) |
579 FIELD_PREP(HAL_CE_SRC_DESC_ADDR_INFO_BYTE_SWAP,
581 FIELD_PREP(HAL_CE_SRC_DESC_ADDR_INFO_GATHER, 0) |
582 FIELD_PREP(HAL_CE_SRC_DESC_ADDR_INFO_LEN, len);
583 desc->meta_info = FIELD_PREP(HAL_CE_SRC_DESC_META_INFO_DATA, id);
586 void ath11k_hal_ce_dst_set_desc(void *buf, dma_addr_t paddr)
588 struct hal_ce_srng_dest_desc *desc =
589 (struct hal_ce_srng_dest_desc *)buf;
591 desc->buffer_addr_low = paddr & HAL_ADDR_LSB_REG_MASK;
592 desc->buffer_addr_info =
593 FIELD_PREP(HAL_CE_DEST_DESC_ADDR_INFO_ADDR_HI,
594 ((u64)paddr >> HAL_ADDR_MSB_REG_SHIFT));
597 u32 ath11k_hal_ce_dst_status_get_length(void *buf)
599 struct hal_ce_srng_dst_status_desc *desc =
600 (struct hal_ce_srng_dst_status_desc *)buf;
603 len = FIELD_GET(HAL_CE_DST_STATUS_DESC_FLAGS_LEN, desc->flags);
604 desc->flags &= ~HAL_CE_DST_STATUS_DESC_FLAGS_LEN;
609 void ath11k_hal_set_link_desc_addr(struct hal_wbm_link_desc *desc, u32 cookie,
612 desc->buf_addr_info.info0 = FIELD_PREP(BUFFER_ADDR_INFO0_ADDR,
613 (paddr & HAL_ADDR_LSB_REG_MASK));
614 desc->buf_addr_info.info1 = FIELD_PREP(BUFFER_ADDR_INFO1_ADDR,
615 ((u64)paddr >> HAL_ADDR_MSB_REG_SHIFT)) |
616 FIELD_PREP(BUFFER_ADDR_INFO1_RET_BUF_MGR, 1) |
617 FIELD_PREP(BUFFER_ADDR_INFO1_SW_COOKIE, cookie);
620 u32 *ath11k_hal_srng_dst_peek(struct ath11k_base *ab, struct hal_srng *srng)
622 lockdep_assert_held(&srng->lock);
624 if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp)
625 return (srng->ring_base_vaddr + srng->u.dst_ring.tp);
630 u32 *ath11k_hal_srng_dst_get_next_entry(struct ath11k_base *ab,
631 struct hal_srng *srng)
635 lockdep_assert_held(&srng->lock);
637 if (srng->u.dst_ring.tp == srng->u.dst_ring.cached_hp)
640 desc = srng->ring_base_vaddr + srng->u.dst_ring.tp;
642 srng->u.dst_ring.tp = (srng->u.dst_ring.tp + srng->entry_size) %
648 int ath11k_hal_srng_dst_num_free(struct ath11k_base *ab, struct hal_srng *srng,
653 lockdep_assert_held(&srng->lock);
655 tp = srng->u.dst_ring.tp;
658 hp = *srng->u.dst_ring.hp_addr;
659 srng->u.dst_ring.cached_hp = hp;
661 hp = srng->u.dst_ring.cached_hp;
665 return (hp - tp) / srng->entry_size;
667 return (srng->ring_size - tp + hp) / srng->entry_size;
670 /* Returns number of available entries in src ring */
671 int ath11k_hal_srng_src_num_free(struct ath11k_base *ab, struct hal_srng *srng,
676 lockdep_assert_held(&srng->lock);
678 hp = srng->u.src_ring.hp;
681 tp = *srng->u.src_ring.tp_addr;
682 srng->u.src_ring.cached_tp = tp;
684 tp = srng->u.src_ring.cached_tp;
688 return ((tp - hp) / srng->entry_size) - 1;
690 return ((srng->ring_size - hp + tp) / srng->entry_size) - 1;
693 u32 *ath11k_hal_srng_src_get_next_entry(struct ath11k_base *ab,
694 struct hal_srng *srng)
699 lockdep_assert_held(&srng->lock);
701 /* TODO: Using % is expensive, but we have to do this since size of some
702 * SRNG rings is not power of 2 (due to descriptor sizes). Need to see
703 * if separate function is defined for rings having power of 2 ring size
704 * (TCL2SW, REO2SW, SW2RXDMA and CE rings) so that we can avoid the
705 * overhead of % by using mask (with &).
707 next_hp = (srng->u.src_ring.hp + srng->entry_size) % srng->ring_size;
709 if (next_hp == srng->u.src_ring.cached_tp)
712 desc = srng->ring_base_vaddr + srng->u.src_ring.hp;
713 srng->u.src_ring.hp = next_hp;
715 /* TODO: Reap functionality is not used by all rings. If particular
716 * ring does not use reap functionality, we need not update reap_hp
717 * with next_hp pointer. Need to make sure a separate function is used
718 * before doing any optimization by removing below code updating
721 srng->u.src_ring.reap_hp = next_hp;
726 u32 *ath11k_hal_srng_src_reap_next(struct ath11k_base *ab,
727 struct hal_srng *srng)
732 lockdep_assert_held(&srng->lock);
734 next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
737 if (next_reap_hp == srng->u.src_ring.cached_tp)
740 desc = srng->ring_base_vaddr + next_reap_hp;
741 srng->u.src_ring.reap_hp = next_reap_hp;
746 u32 *ath11k_hal_srng_src_get_next_reaped(struct ath11k_base *ab,
747 struct hal_srng *srng)
751 lockdep_assert_held(&srng->lock);
753 if (srng->u.src_ring.hp == srng->u.src_ring.reap_hp)
756 desc = srng->ring_base_vaddr + srng->u.src_ring.hp;
757 srng->u.src_ring.hp = (srng->u.src_ring.hp + srng->entry_size) %
763 u32 *ath11k_hal_srng_src_peek(struct ath11k_base *ab, struct hal_srng *srng)
765 lockdep_assert_held(&srng->lock);
767 if (((srng->u.src_ring.hp + srng->entry_size) % srng->ring_size) ==
768 srng->u.src_ring.cached_tp)
771 return srng->ring_base_vaddr + srng->u.src_ring.hp;
774 void ath11k_hal_srng_access_begin(struct ath11k_base *ab, struct hal_srng *srng)
776 lockdep_assert_held(&srng->lock);
778 if (srng->ring_dir == HAL_SRNG_DIR_SRC)
779 srng->u.src_ring.cached_tp =
780 *(volatile u32 *)srng->u.src_ring.tp_addr;
782 srng->u.dst_ring.cached_hp = *srng->u.dst_ring.hp_addr;
785 /* Update cached ring head/tail pointers to HW. ath11k_hal_srng_access_begin()
786 * should have been called before this.
788 void ath11k_hal_srng_access_end(struct ath11k_base *ab, struct hal_srng *srng)
790 lockdep_assert_held(&srng->lock);
792 /* TODO: See if we need a write memory barrier here */
793 if (srng->flags & HAL_SRNG_FLAGS_LMAC_RING) {
794 /* For LMAC rings, ring pointer updates are done through FW and
795 * hence written to a shared memory location that is read by FW
797 if (srng->ring_dir == HAL_SRNG_DIR_SRC) {
798 srng->u.src_ring.last_tp =
799 *(volatile u32 *)srng->u.src_ring.tp_addr;
800 *srng->u.src_ring.hp_addr = srng->u.src_ring.hp;
802 srng->u.dst_ring.last_hp = *srng->u.dst_ring.hp_addr;
803 *srng->u.dst_ring.tp_addr = srng->u.dst_ring.tp;
806 if (srng->ring_dir == HAL_SRNG_DIR_SRC) {
807 srng->u.src_ring.last_tp =
808 *(volatile u32 *)srng->u.src_ring.tp_addr;
809 ath11k_hif_write32(ab,
810 (unsigned long)srng->u.src_ring.hp_addr -
811 (unsigned long)ab->mem,
812 srng->u.src_ring.hp);
814 srng->u.dst_ring.last_hp = *srng->u.dst_ring.hp_addr;
815 ath11k_hif_write32(ab,
816 (unsigned long)srng->u.dst_ring.tp_addr -
817 (unsigned long)ab->mem,
818 srng->u.dst_ring.tp);
822 srng->timestamp = jiffies;
825 void ath11k_hal_setup_link_idle_list(struct ath11k_base *ab,
826 struct hal_wbm_idle_scatter_list *sbuf,
827 u32 nsbufs, u32 tot_link_desc,
830 struct ath11k_buffer_addr *link_addr;
832 u32 reg_scatter_buf_sz = HAL_WBM_IDLE_SCATTER_BUF_SIZE / 64;
834 link_addr = (void *)sbuf[0].vaddr + HAL_WBM_IDLE_SCATTER_BUF_SIZE;
836 for (i = 1; i < nsbufs; i++) {
837 link_addr->info0 = sbuf[i].paddr & HAL_ADDR_LSB_REG_MASK;
838 link_addr->info1 = FIELD_PREP(
839 HAL_WBM_SCATTERED_DESC_MSB_BASE_ADDR_39_32,
840 (u64)sbuf[i].paddr >> HAL_ADDR_MSB_REG_SHIFT) |
842 HAL_WBM_SCATTERED_DESC_MSB_BASE_ADDR_MATCH_TAG,
843 BASE_ADDR_MATCH_TAG_VAL);
845 link_addr = (void *)sbuf[i].vaddr +
846 HAL_WBM_IDLE_SCATTER_BUF_SIZE;
849 ath11k_hif_write32(ab,
850 HAL_SEQ_WCSS_UMAC_WBM_REG + HAL_WBM_R0_IDLE_LIST_CONTROL_ADDR,
851 FIELD_PREP(HAL_WBM_SCATTER_BUFFER_SIZE, reg_scatter_buf_sz) |
852 FIELD_PREP(HAL_WBM_LINK_DESC_IDLE_LIST_MODE, 0x1));
853 ath11k_hif_write32(ab,
854 HAL_SEQ_WCSS_UMAC_WBM_REG + HAL_WBM_R0_IDLE_LIST_SIZE_ADDR,
855 FIELD_PREP(HAL_WBM_SCATTER_RING_SIZE_OF_IDLE_LINK_DESC_LIST,
856 reg_scatter_buf_sz * nsbufs));
857 ath11k_hif_write32(ab,
858 HAL_SEQ_WCSS_UMAC_WBM_REG +
859 HAL_WBM_SCATTERED_RING_BASE_LSB,
860 FIELD_PREP(BUFFER_ADDR_INFO0_ADDR,
861 sbuf[0].paddr & HAL_ADDR_LSB_REG_MASK));
862 ath11k_hif_write32(ab,
863 HAL_SEQ_WCSS_UMAC_WBM_REG +
864 HAL_WBM_SCATTERED_RING_BASE_MSB,
866 HAL_WBM_SCATTERED_DESC_MSB_BASE_ADDR_39_32,
867 (u64)sbuf[0].paddr >> HAL_ADDR_MSB_REG_SHIFT) |
869 HAL_WBM_SCATTERED_DESC_MSB_BASE_ADDR_MATCH_TAG,
870 BASE_ADDR_MATCH_TAG_VAL));
872 /* Setup head and tail pointers for the idle list */
873 ath11k_hif_write32(ab,
874 HAL_SEQ_WCSS_UMAC_WBM_REG +
875 HAL_WBM_SCATTERED_DESC_PTR_HEAD_INFO_IX0,
876 FIELD_PREP(BUFFER_ADDR_INFO0_ADDR,
877 sbuf[nsbufs - 1].paddr));
878 ath11k_hif_write32(ab,
879 HAL_SEQ_WCSS_UMAC_WBM_REG +
880 HAL_WBM_SCATTERED_DESC_PTR_HEAD_INFO_IX1,
882 HAL_WBM_SCATTERED_DESC_MSB_BASE_ADDR_39_32,
883 ((u64)sbuf[nsbufs - 1].paddr >>
884 HAL_ADDR_MSB_REG_SHIFT)) |
885 FIELD_PREP(HAL_WBM_SCATTERED_DESC_HEAD_P_OFFSET_IX1,
887 ath11k_hif_write32(ab,
888 HAL_SEQ_WCSS_UMAC_WBM_REG +
889 HAL_WBM_SCATTERED_DESC_PTR_HEAD_INFO_IX0,
890 FIELD_PREP(BUFFER_ADDR_INFO0_ADDR,
893 ath11k_hif_write32(ab,
894 HAL_SEQ_WCSS_UMAC_WBM_REG +
895 HAL_WBM_SCATTERED_DESC_PTR_TAIL_INFO_IX0,
896 FIELD_PREP(BUFFER_ADDR_INFO0_ADDR,
898 ath11k_hif_write32(ab,
899 HAL_SEQ_WCSS_UMAC_WBM_REG +
900 HAL_WBM_SCATTERED_DESC_PTR_TAIL_INFO_IX1,
902 HAL_WBM_SCATTERED_DESC_MSB_BASE_ADDR_39_32,
903 ((u64)sbuf[0].paddr >> HAL_ADDR_MSB_REG_SHIFT)) |
904 FIELD_PREP(HAL_WBM_SCATTERED_DESC_TAIL_P_OFFSET_IX1,
906 ath11k_hif_write32(ab,
907 HAL_SEQ_WCSS_UMAC_WBM_REG +
908 HAL_WBM_SCATTERED_DESC_PTR_HP_ADDR,
911 /* Enable the SRNG */
912 ath11k_hif_write32(ab,
913 HAL_SEQ_WCSS_UMAC_WBM_REG +
914 HAL_WBM_IDLE_LINK_RING_MISC_ADDR(ab), 0x40);
917 int ath11k_hal_srng_setup(struct ath11k_base *ab, enum hal_ring_type type,
918 int ring_num, int mac_id,
919 struct hal_srng_params *params)
921 struct ath11k_hal *hal = &ab->hal;
922 struct hal_srng_config *srng_config = &ab->hal.srng_config[type];
923 struct hal_srng *srng;
929 ring_id = ath11k_hal_srng_get_ring_id(ab, type, ring_num, mac_id);
933 srng = &hal->srng_list[ring_id];
935 srng->ring_id = ring_id;
936 srng->ring_dir = srng_config->ring_dir;
937 srng->ring_base_paddr = params->ring_base_paddr;
938 srng->ring_base_vaddr = params->ring_base_vaddr;
939 srng->entry_size = srng_config->entry_size;
940 srng->num_entries = params->num_entries;
941 srng->ring_size = srng->entry_size * srng->num_entries;
942 srng->intr_batch_cntr_thres_entries =
943 params->intr_batch_cntr_thres_entries;
944 srng->intr_timer_thres_us = params->intr_timer_thres_us;
945 srng->flags = params->flags;
946 srng->msi_addr = params->msi_addr;
947 srng->msi_data = params->msi_data;
948 srng->initialized = 1;
949 spin_lock_init(&srng->lock);
951 for (i = 0; i < HAL_SRNG_NUM_REG_GRP; i++) {
952 srng->hwreg_base[i] = srng_config->reg_start[i] +
953 (ring_num * srng_config->reg_size[i]);
956 memset(srng->ring_base_vaddr, 0,
957 (srng->entry_size * srng->num_entries) << 2);
959 /* TODO: Add comments on these swap configurations */
960 if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))
961 srng->flags |= HAL_SRNG_FLAGS_MSI_SWAP | HAL_SRNG_FLAGS_DATA_TLV_SWAP |
962 HAL_SRNG_FLAGS_RING_PTR_SWAP;
964 reg_base = srng->hwreg_base[HAL_SRNG_REG_GRP_R2];
966 if (srng->ring_dir == HAL_SRNG_DIR_SRC) {
967 srng->u.src_ring.hp = 0;
968 srng->u.src_ring.cached_tp = 0;
969 srng->u.src_ring.reap_hp = srng->ring_size - srng->entry_size;
970 srng->u.src_ring.tp_addr = (void *)(hal->rdp.vaddr + ring_id);
971 srng->u.src_ring.low_threshold = params->low_threshold *
973 if (srng_config->lmac_ring) {
974 lmac_idx = ring_id - HAL_SRNG_RING_ID_LMAC1_ID_START;
975 srng->u.src_ring.hp_addr = (void *)(hal->wrp.vaddr +
977 srng->flags |= HAL_SRNG_FLAGS_LMAC_RING;
979 if (!ab->hw_params.supports_shadow_regs)
980 srng->u.src_ring.hp_addr =
981 (u32 *)((unsigned long)ab->mem + reg_base);
983 ath11k_dbg(ab, ATH11k_DBG_HAL,
984 "hal type %d ring_num %d reg_base 0x%x shadow 0x%lx\n",
987 (unsigned long)srng->u.src_ring.hp_addr -
988 (unsigned long)ab->mem);
991 /* During initialization loop count in all the descriptors
992 * will be set to zero, and HW will set it to 1 on completing
993 * descriptor update in first loop, and increments it by 1 on
994 * subsequent loops (loop count wraps around after reaching
995 * 0xffff). The 'loop_cnt' in SW ring state is the expected
996 * loop count in descriptors updated by HW (to be processed
999 srng->u.dst_ring.loop_cnt = 1;
1000 srng->u.dst_ring.tp = 0;
1001 srng->u.dst_ring.cached_hp = 0;
1002 srng->u.dst_ring.hp_addr = (void *)(hal->rdp.vaddr + ring_id);
1003 if (srng_config->lmac_ring) {
1004 /* For LMAC rings, tail pointer updates will be done
1005 * through FW by writing to a shared memory location
1007 lmac_idx = ring_id - HAL_SRNG_RING_ID_LMAC1_ID_START;
1008 srng->u.dst_ring.tp_addr = (void *)(hal->wrp.vaddr +
1010 srng->flags |= HAL_SRNG_FLAGS_LMAC_RING;
1012 if (!ab->hw_params.supports_shadow_regs)
1013 srng->u.dst_ring.tp_addr =
1014 (u32 *)((unsigned long)ab->mem + reg_base +
1015 (HAL_REO1_RING_TP(ab) - HAL_REO1_RING_HP(ab)));
1017 ath11k_dbg(ab, ATH11k_DBG_HAL,
1018 "type %d ring_num %d target_reg 0x%x shadow 0x%lx\n",
1020 reg_base + (HAL_REO1_RING_TP(ab) -
1021 HAL_REO1_RING_HP(ab)),
1022 (unsigned long)srng->u.dst_ring.tp_addr -
1023 (unsigned long)ab->mem);
1027 if (srng_config->lmac_ring)
1030 ath11k_hal_srng_hw_init(ab, srng);
1032 if (type == HAL_CE_DST) {
1033 srng->u.dst_ring.max_buffer_length = params->max_buffer_len;
1034 ath11k_hal_ce_dst_setup(ab, srng, ring_num);
1040 static void ath11k_hal_srng_update_hp_tp_addr(struct ath11k_base *ab,
1042 enum hal_ring_type ring_type,
1045 struct hal_srng *srng;
1046 struct ath11k_hal *hal = &ab->hal;
1048 struct hal_srng_config *srng_config = &hal->srng_config[ring_type];
1050 ring_id = ath11k_hal_srng_get_ring_id(ab, ring_type, ring_num, 0);
1054 srng = &hal->srng_list[ring_id];
1056 if (srng_config->ring_dir == HAL_SRNG_DIR_DST)
1057 srng->u.dst_ring.tp_addr = (u32 *)(HAL_SHADOW_REG(shadow_cfg_idx) +
1058 (unsigned long)ab->mem);
1060 srng->u.src_ring.hp_addr = (u32 *)(HAL_SHADOW_REG(shadow_cfg_idx) +
1061 (unsigned long)ab->mem);
1064 int ath11k_hal_srng_update_shadow_config(struct ath11k_base *ab,
1065 enum hal_ring_type ring_type,
1068 struct ath11k_hal *hal = &ab->hal;
1069 struct hal_srng_config *srng_config = &hal->srng_config[ring_type];
1070 int shadow_cfg_idx = hal->num_shadow_reg_configured;
1073 if (shadow_cfg_idx >= HAL_SHADOW_NUM_REGS)
1076 hal->num_shadow_reg_configured++;
1078 target_reg = srng_config->reg_start[HAL_HP_OFFSET_IN_REG_START];
1079 target_reg += srng_config->reg_size[HAL_HP_OFFSET_IN_REG_START] *
1082 /* For destination ring, shadow the TP */
1083 if (srng_config->ring_dir == HAL_SRNG_DIR_DST)
1084 target_reg += HAL_OFFSET_FROM_HP_TO_TP;
1086 hal->shadow_reg_addr[shadow_cfg_idx] = target_reg;
1088 /* update hp/tp addr to hal structure*/
1089 ath11k_hal_srng_update_hp_tp_addr(ab, shadow_cfg_idx, ring_type,
1092 ath11k_dbg(ab, ATH11k_DBG_HAL,
1093 "target_reg %x, shadow reg 0x%x shadow_idx 0x%x, ring_type %d, ring num %d",
1095 HAL_SHADOW_REG(shadow_cfg_idx),
1097 ring_type, ring_num);
1102 void ath11k_hal_srng_shadow_config(struct ath11k_base *ab)
1104 struct ath11k_hal *hal = &ab->hal;
1105 int ring_type, ring_num;
1107 /* update all the non-CE srngs. */
1108 for (ring_type = 0; ring_type < HAL_MAX_RING_TYPES; ring_type++) {
1109 struct hal_srng_config *srng_config = &hal->srng_config[ring_type];
1111 if (ring_type == HAL_CE_SRC ||
1112 ring_type == HAL_CE_DST ||
1113 ring_type == HAL_CE_DST_STATUS)
1116 if (srng_config->lmac_ring)
1119 for (ring_num = 0; ring_num < srng_config->max_rings; ring_num++)
1120 ath11k_hal_srng_update_shadow_config(ab, ring_type, ring_num);
1124 void ath11k_hal_srng_get_shadow_config(struct ath11k_base *ab,
1125 u32 **cfg, u32 *len)
1127 struct ath11k_hal *hal = &ab->hal;
1129 *len = hal->num_shadow_reg_configured;
1130 *cfg = hal->shadow_reg_addr;
1133 void ath11k_hal_srng_shadow_update_hp_tp(struct ath11k_base *ab,
1134 struct hal_srng *srng)
1136 lockdep_assert_held(&srng->lock);
1138 /* check whether the ring is emptry. Update the shadow
1139 * HP only when then ring isn't' empty.
1141 if (srng->ring_dir == HAL_SRNG_DIR_SRC &&
1142 *srng->u.src_ring.tp_addr != srng->u.src_ring.hp)
1143 ath11k_hal_srng_access_end(ab, srng);
1146 static int ath11k_hal_srng_create_config(struct ath11k_base *ab)
1148 struct ath11k_hal *hal = &ab->hal;
1149 struct hal_srng_config *s;
1151 hal->srng_config = kmemdup(hw_srng_config_template,
1152 sizeof(hw_srng_config_template),
1154 if (!hal->srng_config)
1157 s = &hal->srng_config[HAL_REO_DST];
1158 s->reg_start[0] = HAL_SEQ_WCSS_UMAC_REO_REG + HAL_REO1_RING_BASE_LSB(ab);
1159 s->reg_start[1] = HAL_SEQ_WCSS_UMAC_REO_REG + HAL_REO1_RING_HP(ab);
1160 s->reg_size[0] = HAL_REO2_RING_BASE_LSB(ab) - HAL_REO1_RING_BASE_LSB(ab);
1161 s->reg_size[1] = HAL_REO2_RING_HP(ab) - HAL_REO1_RING_HP(ab);
1163 s = &hal->srng_config[HAL_REO_EXCEPTION];
1164 s->reg_start[0] = HAL_SEQ_WCSS_UMAC_REO_REG + HAL_REO_TCL_RING_BASE_LSB(ab);
1165 s->reg_start[1] = HAL_SEQ_WCSS_UMAC_REO_REG + HAL_REO_TCL_RING_HP(ab);
1167 s = &hal->srng_config[HAL_REO_REINJECT];
1168 s->reg_start[0] = HAL_SEQ_WCSS_UMAC_REO_REG + HAL_SW2REO_RING_BASE_LSB;
1169 s->reg_start[1] = HAL_SEQ_WCSS_UMAC_REO_REG + HAL_SW2REO_RING_HP;
1171 s = &hal->srng_config[HAL_REO_CMD];
1172 s->reg_start[0] = HAL_SEQ_WCSS_UMAC_REO_REG + HAL_REO_CMD_RING_BASE_LSB;
1173 s->reg_start[1] = HAL_SEQ_WCSS_UMAC_REO_REG + HAL_REO_CMD_HP;
1175 s = &hal->srng_config[HAL_REO_STATUS];
1176 s->reg_start[0] = HAL_SEQ_WCSS_UMAC_REO_REG + HAL_REO_STATUS_RING_BASE_LSB(ab);
1177 s->reg_start[1] = HAL_SEQ_WCSS_UMAC_REO_REG + HAL_REO_STATUS_HP(ab);
1179 s = &hal->srng_config[HAL_TCL_DATA];
1180 s->reg_start[0] = HAL_SEQ_WCSS_UMAC_TCL_REG + HAL_TCL1_RING_BASE_LSB(ab);
1181 s->reg_start[1] = HAL_SEQ_WCSS_UMAC_TCL_REG + HAL_TCL1_RING_HP;
1182 s->reg_size[0] = HAL_TCL2_RING_BASE_LSB(ab) - HAL_TCL1_RING_BASE_LSB(ab);
1183 s->reg_size[1] = HAL_TCL2_RING_HP - HAL_TCL1_RING_HP;
1185 s = &hal->srng_config[HAL_TCL_CMD];
1186 s->reg_start[0] = HAL_SEQ_WCSS_UMAC_TCL_REG + HAL_TCL_RING_BASE_LSB(ab);
1187 s->reg_start[1] = HAL_SEQ_WCSS_UMAC_TCL_REG + HAL_TCL_RING_HP;
1189 s = &hal->srng_config[HAL_TCL_STATUS];
1190 s->reg_start[0] = HAL_SEQ_WCSS_UMAC_TCL_REG + HAL_TCL_STATUS_RING_BASE_LSB(ab);
1191 s->reg_start[1] = HAL_SEQ_WCSS_UMAC_TCL_REG + HAL_TCL_STATUS_RING_HP;
1193 s = &hal->srng_config[HAL_CE_SRC];
1194 s->reg_start[0] = HAL_SEQ_WCSS_UMAC_CE0_SRC_REG(ab) + HAL_CE_DST_RING_BASE_LSB;
1195 s->reg_start[1] = HAL_SEQ_WCSS_UMAC_CE0_SRC_REG(ab) + HAL_CE_DST_RING_HP;
1196 s->reg_size[0] = HAL_SEQ_WCSS_UMAC_CE1_SRC_REG(ab) -
1197 HAL_SEQ_WCSS_UMAC_CE0_SRC_REG(ab);
1198 s->reg_size[1] = HAL_SEQ_WCSS_UMAC_CE1_SRC_REG(ab) -
1199 HAL_SEQ_WCSS_UMAC_CE0_SRC_REG(ab);
1201 s = &hal->srng_config[HAL_CE_DST];
1202 s->reg_start[0] = HAL_SEQ_WCSS_UMAC_CE0_DST_REG(ab) + HAL_CE_DST_RING_BASE_LSB;
1203 s->reg_start[1] = HAL_SEQ_WCSS_UMAC_CE0_DST_REG(ab) + HAL_CE_DST_RING_HP;
1204 s->reg_size[0] = HAL_SEQ_WCSS_UMAC_CE1_DST_REG(ab) -
1205 HAL_SEQ_WCSS_UMAC_CE0_DST_REG(ab);
1206 s->reg_size[1] = HAL_SEQ_WCSS_UMAC_CE1_DST_REG(ab) -
1207 HAL_SEQ_WCSS_UMAC_CE0_DST_REG(ab);
1209 s = &hal->srng_config[HAL_CE_DST_STATUS];
1210 s->reg_start[0] = HAL_SEQ_WCSS_UMAC_CE0_DST_REG(ab) +
1211 HAL_CE_DST_STATUS_RING_BASE_LSB;
1212 s->reg_start[1] = HAL_SEQ_WCSS_UMAC_CE0_DST_REG(ab) + HAL_CE_DST_STATUS_RING_HP;
1213 s->reg_size[0] = HAL_SEQ_WCSS_UMAC_CE1_DST_REG(ab) -
1214 HAL_SEQ_WCSS_UMAC_CE0_DST_REG(ab);
1215 s->reg_size[1] = HAL_SEQ_WCSS_UMAC_CE1_DST_REG(ab) -
1216 HAL_SEQ_WCSS_UMAC_CE0_DST_REG(ab);
1218 s = &hal->srng_config[HAL_WBM_IDLE_LINK];
1219 s->reg_start[0] = HAL_SEQ_WCSS_UMAC_WBM_REG + HAL_WBM_IDLE_LINK_RING_BASE_LSB(ab);
1220 s->reg_start[1] = HAL_SEQ_WCSS_UMAC_WBM_REG + HAL_WBM_IDLE_LINK_RING_HP;
1222 s = &hal->srng_config[HAL_SW2WBM_RELEASE];
1223 s->reg_start[0] = HAL_SEQ_WCSS_UMAC_WBM_REG + HAL_WBM_RELEASE_RING_BASE_LSB(ab);
1224 s->reg_start[1] = HAL_SEQ_WCSS_UMAC_WBM_REG + HAL_WBM_RELEASE_RING_HP;
1226 s = &hal->srng_config[HAL_WBM2SW_RELEASE];
1227 s->reg_start[0] = HAL_SEQ_WCSS_UMAC_WBM_REG + HAL_WBM0_RELEASE_RING_BASE_LSB(ab);
1228 s->reg_start[1] = HAL_SEQ_WCSS_UMAC_WBM_REG + HAL_WBM0_RELEASE_RING_HP;
1229 s->reg_size[0] = HAL_WBM1_RELEASE_RING_BASE_LSB(ab) -
1230 HAL_WBM0_RELEASE_RING_BASE_LSB(ab);
1231 s->reg_size[1] = HAL_WBM1_RELEASE_RING_HP - HAL_WBM0_RELEASE_RING_HP;
1236 int ath11k_hal_srng_init(struct ath11k_base *ab)
1238 struct ath11k_hal *hal = &ab->hal;
1241 memset(hal, 0, sizeof(*hal));
1243 ret = ath11k_hal_srng_create_config(ab);
1247 ret = ath11k_hal_alloc_cont_rdp(ab);
1251 ret = ath11k_hal_alloc_cont_wrp(ab);
1253 goto err_free_cont_rdp;
1258 ath11k_hal_free_cont_rdp(ab);
1263 EXPORT_SYMBOL(ath11k_hal_srng_init);
1265 void ath11k_hal_srng_deinit(struct ath11k_base *ab)
1267 struct ath11k_hal *hal = &ab->hal;
1269 ath11k_hal_free_cont_rdp(ab);
1270 ath11k_hal_free_cont_wrp(ab);
1271 kfree(hal->srng_config);
1273 EXPORT_SYMBOL(ath11k_hal_srng_deinit);
1275 void ath11k_hal_dump_srng_stats(struct ath11k_base *ab)
1277 struct hal_srng *srng;
1278 struct ath11k_ext_irq_grp *irq_grp;
1279 struct ath11k_ce_pipe *ce_pipe;
1282 ath11k_err(ab, "Last interrupt received for each CE:\n");
1283 for (i = 0; i < ab->hw_params.ce_count; i++) {
1284 ce_pipe = &ab->ce.ce_pipe[i];
1286 if (ath11k_ce_get_attr_flags(ab, i) & CE_ATTR_DIS_INTR)
1289 ath11k_err(ab, "CE_id %d pipe_num %d %ums before\n",
1290 i, ce_pipe->pipe_num,
1291 jiffies_to_msecs(jiffies - ce_pipe->timestamp));
1294 ath11k_err(ab, "\nLast interrupt received for each group:\n");
1295 for (i = 0; i < ATH11K_EXT_IRQ_GRP_NUM_MAX; i++) {
1296 irq_grp = &ab->ext_irq_grp[i];
1297 ath11k_err(ab, "group_id %d %ums before\n",
1299 jiffies_to_msecs(jiffies - irq_grp->timestamp));
1302 for (i = 0; i < HAL_SRNG_RING_ID_MAX; i++) {
1303 srng = &ab->hal.srng_list[i];
1305 if (!srng->initialized)
1308 if (srng->ring_dir == HAL_SRNG_DIR_SRC)
1310 "src srng id %u hp %u, reap_hp %u, cur tp %u, cached tp %u last tp %u napi processed before %ums\n",
1311 srng->ring_id, srng->u.src_ring.hp,
1312 srng->u.src_ring.reap_hp,
1313 *srng->u.src_ring.tp_addr, srng->u.src_ring.cached_tp,
1314 srng->u.src_ring.last_tp,
1315 jiffies_to_msecs(jiffies - srng->timestamp));
1316 else if (srng->ring_dir == HAL_SRNG_DIR_DST)
1318 "dst srng id %u tp %u, cur hp %u, cached hp %u last hp %u napi processed before %ums\n",
1319 srng->ring_id, srng->u.dst_ring.tp,
1320 *srng->u.dst_ring.hp_addr,
1321 srng->u.dst_ring.cached_hp,
1322 srng->u.dst_ring.last_hp,
1323 jiffies_to_msecs(jiffies - srng->timestamp));