summaryrefslogtreecommitdiff
path: root/drivers/crypto/intel/qat/qat_common/adf_tl_debugfs.c
blob: c8241f5a0a26ee996525a0038a5d74b3e15ec094 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
// SPDX-License-Identifier: GPL-2.0-only
/* Copyright (c) 2023 Intel Corporation. */
#define dev_fmt(fmt) "Telemetry debugfs: " fmt

#include <linux/atomic.h>
#include <linux/debugfs.h>
#include <linux/dev_printk.h>
#include <linux/dcache.h>
#include <linux/file.h>
#include <linux/kernel.h>
#include <linux/math64.h>
#include <linux/mutex.h>
#include <linux/seq_file.h>
#include <linux/slab.h>
#include <linux/units.h>

#include "adf_accel_devices.h"
#include "adf_cfg_strings.h"
#include "adf_telemetry.h"
#include "adf_tl_debugfs.h"

#define TL_VALUE_MIN_PADDING	20
#define TL_KEY_MIN_PADDING	23
#define TL_RP_SRV_UNKNOWN	"Unknown"

static int tl_collect_values_u32(struct adf_telemetry *telemetry,
				 size_t counter_offset, u64 *arr)
{
	unsigned int samples, hb_idx, i;
	u32 *regs_hist_buff;
	u32 counter_val;

	samples = min(telemetry->msg_cnt, telemetry->hbuffs);
	hb_idx = telemetry->hb_num + telemetry->hbuffs - samples;

	mutex_lock(&telemetry->regs_hist_lock);

	for (i = 0; i < samples; i++) {
		regs_hist_buff = telemetry->regs_hist_buff[hb_idx % telemetry->hbuffs];
		counter_val = regs_hist_buff[counter_offset / sizeof(counter_val)];
		arr[i] = counter_val;
		hb_idx++;
	}

	mutex_unlock(&telemetry->regs_hist_lock);

	return samples;
}

static int tl_collect_values_u64(struct adf_telemetry *telemetry,
				 size_t counter_offset, u64 *arr)
{
	unsigned int samples, hb_idx, i;
	u64 *regs_hist_buff;
	u64 counter_val;

	samples = min(telemetry->msg_cnt, telemetry->hbuffs);
	hb_idx = telemetry->hb_num + telemetry->hbuffs - samples;

	mutex_lock(&telemetry->regs_hist_lock);

	for (i = 0; i < samples; i++) {
		regs_hist_buff = telemetry->regs_hist_buff[hb_idx % telemetry->hbuffs];
		counter_val = regs_hist_buff[counter_offset / sizeof(counter_val)];
		arr[i] = counter_val;
		hb_idx++;
	}

	mutex_unlock(&telemetry->regs_hist_lock);

	return samples;
}

/**
 * avg_array() - Return average of values within an array.
 * @array: Array of values.
 * @len: Number of elements.
 *
 * This algorithm computes average of an array without running into overflow.
 *
 * Return: average of values.
 */
#define avg_array(array, len) (				\
{							\
	typeof(&(array)[0]) _array = (array);		\
	__unqual_scalar_typeof(_array[0]) _x = 0;	\
	__unqual_scalar_typeof(_array[0]) _y = 0;	\
	__unqual_scalar_typeof(_array[0]) _a, _b;	\
	typeof(len) _len = (len);			\
	size_t _i;					\
							\
	for (_i = 0; _i < _len; _i++) {			\
		_a = _array[_i];			\
		_b = do_div(_a, _len);			\
		_x += _a;				\
		if (_y >= _len - _b) {			\
			_x++;				\
			_y -= _len - _b;		\
		} else {				\
			_y += _b;			\
		}					\
	}						\
	do_div(_y, _len);				\
	(_x + _y);					\
})

/* Calculation function for simple counter. */
static int tl_calc_count(struct adf_telemetry *telemetry,
			 const struct adf_tl_dbg_counter *ctr,
			 struct adf_tl_dbg_aggr_values *vals)
{
	struct adf_tl_hw_data *tl_data = &GET_TL_DATA(telemetry->accel_dev);
	u64 *hist_vals;
	int sample_cnt;
	int ret = 0;

	hist_vals = kmalloc_array(tl_data->num_hbuff, sizeof(*hist_vals),
				  GFP_KERNEL);
	if (!hist_vals)
		return -ENOMEM;

	memset(vals, 0, sizeof(*vals));
	sample_cnt = tl_collect_values_u32(telemetry, ctr->offset1, hist_vals);
	if (!sample_cnt)
		goto out_free_hist_vals;

	vals->curr = hist_vals[sample_cnt - 1];
	vals->min = min_array(hist_vals, sample_cnt);
	vals->max = max_array(hist_vals, sample_cnt);
	vals->avg = avg_array(hist_vals, sample_cnt);

out_free_hist_vals:
	kfree(hist_vals);
	return ret;
}

/* Convert CPP bus cycles to ns. */
static int tl_cycles_to_ns(struct adf_telemetry *telemetry,
			   const struct adf_tl_dbg_counter *ctr,
			   struct adf_tl_dbg_aggr_values *vals)
{
	struct adf_tl_hw_data *tl_data = &GET_TL_DATA(telemetry->accel_dev);
	u8 cpp_ns_per_cycle = tl_data->cpp_ns_per_cycle;
	int ret;

	ret = tl_calc_count(telemetry, ctr, vals);
	if (ret)
		return ret;

	vals->curr *= cpp_ns_per_cycle;
	vals->min *= cpp_ns_per_cycle;
	vals->max *= cpp_ns_per_cycle;
	vals->avg *= cpp_ns_per_cycle;

	return 0;
}

/*
 * Compute latency cumulative average with division of accumulated value
 * by sample count. Returned value is in ns.
 */
static int tl_lat_acc_avg(struct adf_telemetry *telemetry,
			  const struct adf_tl_dbg_counter *ctr,
			  struct adf_tl_dbg_aggr_values *vals)
{
	struct adf_tl_hw_data *tl_data = &GET_TL_DATA(telemetry->accel_dev);
	u8 cpp_ns_per_cycle = tl_data->cpp_ns_per_cycle;
	u8 num_hbuff = tl_data->num_hbuff;
	int sample_cnt, i;
	u64 *hist_vals;
	u64 *hist_cnt;
	int ret = 0;

	hist_vals = kmalloc_array(num_hbuff, sizeof(*hist_vals), GFP_KERNEL);
	if (!hist_vals)
		return -ENOMEM;

	hist_cnt = kmalloc_array(num_hbuff, sizeof(*hist_cnt), GFP_KERNEL);
	if (!hist_cnt) {
		ret = -ENOMEM;
		goto out_free_hist_vals;
	}

	memset(vals, 0, sizeof(*vals));
	sample_cnt = tl_collect_values_u64(telemetry, ctr->offset1, hist_vals);
	if (!sample_cnt)
		goto out_free_hist_cnt;

	tl_collect_values_u32(telemetry, ctr->offset2, hist_cnt);

	for (i = 0; i < sample_cnt; i++) {
		/* Avoid division by 0 if count is 0. */
		if (hist_cnt[i])
			hist_vals[i] = div_u64(hist_vals[i] * cpp_ns_per_cycle,
					       hist_cnt[i]);
		else
			hist_vals[i] = 0;
	}

	vals->curr = hist_vals[sample_cnt - 1];
	vals->min = min_array(hist_vals, sample_cnt);
	vals->max = max_array(hist_vals, sample_cnt);
	vals->avg = avg_array(hist_vals, sample_cnt);

out_free_hist_cnt:
	kfree(hist_cnt);
out_free_hist_vals:
	kfree(hist_vals);
	return ret;
}

/* Convert HW raw bandwidth units to Mbps. */
static int tl_bw_hw_units_to_mbps(struct adf_telemetry *telemetry,
				  const struct adf_tl_dbg_counter *ctr,
				  struct adf_tl_dbg_aggr_values *vals)
{
	struct adf_tl_hw_data *tl_data = &GET_TL_DATA(telemetry->accel_dev);
	u16 bw_hw_2_bits = tl_data->bw_units_to_bytes * BITS_PER_BYTE;
	u64 *hist_vals;
	int sample_cnt;
	int ret = 0;

	hist_vals = kmalloc_array(tl_data->num_hbuff, sizeof(*hist_vals),
				  GFP_KERNEL);
	if (!hist_vals)
		return -ENOMEM;

	memset(vals, 0, sizeof(*vals));
	sample_cnt = tl_collect_values_u32(telemetry, ctr->offset1, hist_vals);
	if (!sample_cnt)
		goto out_free_hist_vals;

	vals->curr = div_u64(hist_vals[sample_cnt - 1] * bw_hw_2_bits, MEGA);
	vals->min = div_u64(min_array(hist_vals, sample_cnt) * bw_hw_2_bits, MEGA);
	vals->max = div_u64(max_array(hist_vals, sample_cnt) * bw_hw_2_bits, MEGA);
	vals->avg = div_u64(avg_array(hist_vals, sample_cnt) * bw_hw_2_bits, MEGA);

out_free_hist_vals:
	kfree(hist_vals);
	return ret;
}

static void tl_seq_printf_counter(struct adf_telemetry *telemetry,
				  struct seq_file *s, const char *name,
				  struct adf_tl_dbg_aggr_values *vals)
{
	seq_printf(s, "%-*s", TL_KEY_MIN_PADDING, name);
	seq_printf(s, "%*llu", TL_VALUE_MIN_PADDING, vals->curr);
	if (atomic_read(&telemetry->state) > 1) {
		seq_printf(s, "%*llu", TL_VALUE_MIN_PADDING, vals->min);
		seq_printf(s, "%*llu", TL_VALUE_MIN_PADDING, vals->max);
		seq_printf(s, "%*llu", TL_VALUE_MIN_PADDING, vals->avg);
	}
	seq_puts(s, "\n");
}

static int tl_calc_and_print_counter(struct adf_telemetry *telemetry,
				     struct seq_file *s,
				     const struct adf_tl_dbg_counter *ctr,
				     const char *name)
{
	const char *counter_name = name ? name : ctr->name;
	enum adf_tl_counter_type type = ctr->type;
	struct adf_tl_dbg_aggr_values vals;
	int ret;

	switch (type) {
	case ADF_TL_SIMPLE_COUNT:
		ret = tl_calc_count(telemetry, ctr, &vals);
		break;
	case ADF_TL_COUNTER_NS:
		ret = tl_cycles_to_ns(telemetry, ctr, &vals);
		break;
	case ADF_TL_COUNTER_NS_AVG:
		ret = tl_lat_acc_avg(telemetry, ctr, &vals);
		break;
	case ADF_TL_COUNTER_MBPS:
		ret = tl_bw_hw_units_to_mbps(telemetry, ctr, &vals);
		break;
	default:
		return -EINVAL;
	}

	if (ret)
		return ret;

	tl_seq_printf_counter(telemetry, s, counter_name, &vals);

	return 0;
}

static int tl_print_sl_counter(struct adf_telemetry *telemetry,
			       const struct adf_tl_dbg_counter *ctr,
			       struct seq_file *s, u8 cnt_id)
{
	size_t sl_regs_sz = GET_TL_DATA(telemetry->accel_dev).slice_reg_sz;
	struct adf_tl_dbg_counter slice_ctr;
	size_t offset_inc = cnt_id * sl_regs_sz;
	char cnt_name[MAX_COUNT_NAME_SIZE];

	snprintf(cnt_name, MAX_COUNT_NAME_SIZE, "%s%d", ctr->name, cnt_id);
	slice_ctr = *ctr;
	slice_ctr.offset1 += offset_inc;

	return tl_calc_and_print_counter(telemetry, s, &slice_ctr, cnt_name);
}

static int tl_calc_and_print_sl_counters(struct adf_accel_dev *accel_dev,
					 struct seq_file *s, u8 cnt_type, u8 cnt_id)
{
	struct adf_tl_hw_data *tl_data = &GET_TL_DATA(accel_dev);
	struct adf_telemetry *telemetry = accel_dev->telemetry;
	const struct adf_tl_dbg_counter *sl_tl_util_counters;
	const struct adf_tl_dbg_counter *sl_tl_exec_counters;
	const struct adf_tl_dbg_counter *ctr;
	int ret;

	sl_tl_util_counters = tl_data->sl_util_counters;
	sl_tl_exec_counters = tl_data->sl_exec_counters;

	ctr = &sl_tl_util_counters[cnt_type];

	ret = tl_print_sl_counter(telemetry, ctr, s, cnt_id);
	if (ret) {
		dev_notice(&GET_DEV(accel_dev),
			   "invalid slice utilization counter type\n");
		return ret;
	}

	ctr = &sl_tl_exec_counters[cnt_type];

	ret = tl_print_sl_counter(telemetry, ctr, s, cnt_id);
	if (ret) {
		dev_notice(&GET_DEV(accel_dev),
			   "invalid slice execution counter type\n");
		return ret;
	}

	return 0;
}

static void tl_print_msg_cnt(struct seq_file *s, u32 msg_cnt)
{
	seq_printf(s, "%-*s", TL_KEY_MIN_PADDING, SNAPSHOT_CNT_MSG);
	seq_printf(s, "%*u\n", TL_VALUE_MIN_PADDING, msg_cnt);
}

static int tl_print_dev_data(struct adf_accel_dev *accel_dev,
			     struct seq_file *s)
{
	struct adf_tl_hw_data *tl_data = &GET_TL_DATA(accel_dev);
	struct adf_telemetry *telemetry = accel_dev->telemetry;
	const struct adf_tl_dbg_counter *dev_tl_counters;
	u8 num_dev_counters = tl_data->num_dev_counters;
	u8 *sl_cnt = (u8 *)&telemetry->slice_cnt;
	const struct adf_tl_dbg_counter *ctr;
	unsigned int i;
	int ret;
	u8 j;

	if (!atomic_read(&telemetry->state)) {
		dev_info(&GET_DEV(accel_dev), "not enabled\n");
		return -EPERM;
	}

	dev_tl_counters = tl_data->dev_counters;

	tl_print_msg_cnt(s, telemetry->msg_cnt);

	/* Print device level telemetry. */
	for (i = 0; i < num_dev_counters; i++) {
		ctr = &dev_tl_counters[i];
		ret = tl_calc_and_print_counter(telemetry, s, ctr, NULL);
		if (ret) {
			dev_notice(&GET_DEV(accel_dev),
				   "invalid counter type\n");
			return ret;
		}
	}

	/* Print per slice telemetry. */
	for (i = 0; i < ADF_TL_SL_CNT_COUNT; i++) {
		for (j = 0; j < sl_cnt[i]; j++) {
			ret = tl_calc_and_print_sl_counters(accel_dev, s, i, j);
			if (ret)
				return ret;
		}
	}

	return 0;
}

static int tl_dev_data_show(struct seq_file *s, void *unused)
{
	struct adf_accel_dev *accel_dev = s->private;

	if (!accel_dev)
		return -EINVAL;

	return tl_print_dev_data(accel_dev, s);
}
DEFINE_SHOW_ATTRIBUTE(tl_dev_data);

static int tl_control_show(struct seq_file *s, void *unused)
{
	struct adf_accel_dev *accel_dev = s->private;

	if (!accel_dev)
		return -EINVAL;

	seq_printf(s, "%d\n", atomic_read(&accel_dev->telemetry->state));

	return 0;
}

static ssize_t tl_control_write(struct file *file, const char __user *userbuf,
				size_t count, loff_t *ppos)
{
	struct seq_file *seq_f = file->private_data;
	struct adf_accel_dev *accel_dev;
	struct adf_telemetry *telemetry;
	struct adf_tl_hw_data *tl_data;
	struct device *dev;
	u32 input;
	int ret;

	accel_dev = seq_f->private;
	if (!accel_dev)
		return -EINVAL;

	tl_data = &GET_TL_DATA(accel_dev);
	telemetry = accel_dev->telemetry;
	dev = &GET_DEV(accel_dev);

	mutex_lock(&telemetry->wr_lock);

	ret = kstrtou32_from_user(userbuf, count, 10, &input);
	if (ret)
		goto unlock_and_exit;

	if (input > tl_data->num_hbuff) {
		dev_info(dev, "invalid control input\n");
		ret = -EINVAL;
		goto unlock_and_exit;
	}

	/* If input is 0, just stop telemetry. */
	if (!input) {
		ret = adf_tl_halt(accel_dev);
		if (!ret)
			ret = count;

		goto unlock_and_exit;
	}

	/* If TL is already enabled, stop it. */
	if (atomic_read(&telemetry->state)) {
		dev_info(dev, "already enabled, restarting.\n");
		ret = adf_tl_halt(accel_dev);
		if (ret)
			goto unlock_and_exit;
	}

	ret = adf_tl_run(accel_dev, input);
	if (ret)
		goto unlock_and_exit;

	ret = count;

unlock_and_exit:
	mutex_unlock(&telemetry->wr_lock);
	return ret;
}
DEFINE_SHOW_STORE_ATTRIBUTE(tl_control);

static int get_rp_index_from_file(const struct file *f, u8 *rp_id, u8 rp_num)
{
	char alpha;
	u8 index;
	int ret;

	ret = sscanf(f->f_path.dentry->d_name.name, ADF_TL_RP_REGS_FNAME, &alpha);
	if (ret != 1)
		return -EINVAL;

	index = ADF_TL_DBG_RP_INDEX_ALPHA(alpha);
	*rp_id = index;

	return 0;
}

static int adf_tl_dbg_change_rp_index(struct adf_accel_dev *accel_dev,
				      unsigned int new_rp_num,
				      unsigned int rp_regs_index)
{
	struct adf_hw_device_data *hw_data = GET_HW_DATA(accel_dev);
	struct adf_telemetry *telemetry = accel_dev->telemetry;
	struct device *dev = &GET_DEV(accel_dev);
	unsigned int i;
	u8 curr_state;
	int ret;

	if (new_rp_num >= hw_data->num_rps) {
		dev_info(dev, "invalid Ring Pair number selected\n");
		return -EINVAL;
	}

	for (i = 0; i < hw_data->tl_data.max_rp; i++) {
		if (telemetry->rp_num_indexes[i] == new_rp_num) {
			dev_info(dev, "RP nr: %d is already selected in slot rp_%c_data\n",
				 new_rp_num, ADF_TL_DBG_RP_ALPHA_INDEX(i));
			return 0;
		}
	}

	dev_dbg(dev, "selecting RP nr %u into slot rp_%c_data\n",
		new_rp_num, ADF_TL_DBG_RP_ALPHA_INDEX(rp_regs_index));

	curr_state = atomic_read(&telemetry->state);

	if (curr_state) {
		ret = adf_tl_halt(accel_dev);
		if (ret)
			return ret;

		telemetry->rp_num_indexes[rp_regs_index] = new_rp_num;

		ret = adf_tl_run(accel_dev, curr_state);
		if (ret)
			return ret;
	} else {
		telemetry->rp_num_indexes[rp_regs_index] = new_rp_num;
	}

	return 0;
}

static void tl_print_rp_srv(struct adf_accel_dev *accel_dev, struct seq_file *s,
			    u8 rp_idx)
{
	u32 banks_per_vf = GET_HW_DATA(accel_dev)->num_banks_per_vf;
	enum adf_cfg_service_type svc;

	seq_printf(s, "%-*s", TL_KEY_MIN_PADDING, RP_SERVICE_TYPE);

	svc = GET_SRV_TYPE(accel_dev, rp_idx % banks_per_vf);
	switch (svc) {
	case COMP:
		seq_printf(s, "%*s\n", TL_VALUE_MIN_PADDING, ADF_CFG_DC);
		break;
	case SYM:
		seq_printf(s, "%*s\n", TL_VALUE_MIN_PADDING, ADF_CFG_SYM);
		break;
	case ASYM:
		seq_printf(s, "%*s\n", TL_VALUE_MIN_PADDING, ADF_CFG_ASYM);
		break;
	default:
		seq_printf(s, "%*s\n", TL_VALUE_MIN_PADDING, TL_RP_SRV_UNKNOWN);
		break;
	}
}

static int tl_print_rp_data(struct adf_accel_dev *accel_dev, struct seq_file *s,
			    u8 rp_regs_index)
{
	struct adf_tl_hw_data *tl_data = &GET_TL_DATA(accel_dev);
	struct adf_telemetry *telemetry = accel_dev->telemetry;
	const struct adf_tl_dbg_counter *rp_tl_counters;
	u8 num_rp_counters = tl_data->num_rp_counters;
	size_t rp_regs_sz = tl_data->rp_reg_sz;
	struct adf_tl_dbg_counter ctr;
	unsigned int i;
	u8 rp_idx;
	int ret;

	if (!atomic_read(&telemetry->state)) {
		dev_info(&GET_DEV(accel_dev), "not enabled\n");
		return -EPERM;
	}

	rp_tl_counters = tl_data->rp_counters;
	rp_idx = telemetry->rp_num_indexes[rp_regs_index];

	if (rp_idx == ADF_TL_RP_REGS_DISABLED) {
		dev_info(&GET_DEV(accel_dev), "no RP number selected in rp_%c_data\n",
			 ADF_TL_DBG_RP_ALPHA_INDEX(rp_regs_index));
		return -EPERM;
	}

	tl_print_msg_cnt(s, telemetry->msg_cnt);
	seq_printf(s, "%-*s", TL_KEY_MIN_PADDING, RP_NUM_INDEX);
	seq_printf(s, "%*d\n", TL_VALUE_MIN_PADDING, rp_idx);
	tl_print_rp_srv(accel_dev, s, rp_idx);

	for (i = 0; i < num_rp_counters; i++) {
		ctr = rp_tl_counters[i];
		ctr.offset1 += rp_regs_sz * rp_regs_index;
		ctr.offset2 += rp_regs_sz * rp_regs_index;
		ret = tl_calc_and_print_counter(telemetry, s, &ctr, NULL);
		if (ret) {
			dev_dbg(&GET_DEV(accel_dev),
				"invalid RP counter type\n");
			return ret;
		}
	}

	return 0;
}

static int tl_rp_data_show(struct seq_file *s, void *unused)
{
	struct adf_accel_dev *accel_dev = s->private;
	u8 rp_regs_index;
	u8 max_rp;
	int ret;

	if (!accel_dev)
		return -EINVAL;

	max_rp = GET_TL_DATA(accel_dev).max_rp;
	ret = get_rp_index_from_file(s->file, &rp_regs_index, max_rp);
	if (ret) {
		dev_dbg(&GET_DEV(accel_dev), "invalid RP data file name\n");
		return ret;
	}

	return tl_print_rp_data(accel_dev, s, rp_regs_index);
}

static ssize_t tl_rp_data_write(struct file *file, const char __user *userbuf,
				size_t count, loff_t *ppos)
{
	struct seq_file *seq_f = file->private_data;
	struct adf_accel_dev *accel_dev;
	struct adf_telemetry *telemetry;
	unsigned int new_rp_num;
	u8 rp_regs_index;
	u8 max_rp;
	int ret;

	accel_dev = seq_f->private;
	if (!accel_dev)
		return -EINVAL;

	telemetry = accel_dev->telemetry;
	max_rp = GET_TL_DATA(accel_dev).max_rp;

	mutex_lock(&telemetry->wr_lock);

	ret = get_rp_index_from_file(file, &rp_regs_index, max_rp);
	if (ret) {
		dev_dbg(&GET_DEV(accel_dev), "invalid RP data file name\n");
		goto unlock_and_exit;
	}

	ret = kstrtou32_from_user(userbuf, count, 10, &new_rp_num);
	if (ret)
		goto unlock_and_exit;

	ret = adf_tl_dbg_change_rp_index(accel_dev, new_rp_num, rp_regs_index);
	if (ret)
		goto unlock_and_exit;

	ret = count;

unlock_and_exit:
	mutex_unlock(&telemetry->wr_lock);
	return ret;
}
DEFINE_SHOW_STORE_ATTRIBUTE(tl_rp_data);

void adf_tl_dbgfs_add(struct adf_accel_dev *accel_dev)
{
	struct adf_telemetry *telemetry = accel_dev->telemetry;
	struct dentry *parent = accel_dev->debugfs_dir;
	u8 max_rp = GET_TL_DATA(accel_dev).max_rp;
	char name[ADF_TL_RP_REGS_FNAME_SIZE];
	struct dentry *dir;
	unsigned int i;

	if (!telemetry)
		return;

	dir = debugfs_create_dir("telemetry", parent);
	accel_dev->telemetry->dbg_dir = dir;
	debugfs_create_file("device_data", 0444, dir, accel_dev, &tl_dev_data_fops);
	debugfs_create_file("control", 0644, dir, accel_dev, &tl_control_fops);

	for (i = 0; i < max_rp; i++) {
		snprintf(name, sizeof(name), ADF_TL_RP_REGS_FNAME,
			 ADF_TL_DBG_RP_ALPHA_INDEX(i));
		debugfs_create_file(name, 0644, dir, accel_dev, &tl_rp_data_fops);
	}
}

void adf_tl_dbgfs_rm(struct adf_accel_dev *accel_dev)
{
	struct adf_telemetry *telemetry = accel_dev->telemetry;
	struct dentry *dbg_dir;

	if (!telemetry)
		return;

	dbg_dir = telemetry->dbg_dir;

	debugfs_remove_recursive(dbg_dir);

	if (atomic_read(&telemetry->state))
		adf_tl_halt(accel_dev);
}