Merge tag 'regmap-fix-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux/fpc-iii.git] / drivers / crypto / qat / qat_common / adf_transport_debug.c
blob1205186ad51ecfeb3503a72b9afc3d416f242c87
1 // SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only)
2 /* Copyright(c) 2014 - 2020 Intel Corporation */
3 #include <linux/mutex.h>
4 #include <linux/slab.h>
5 #include <linux/seq_file.h>
6 #include "adf_accel_devices.h"
7 #include "adf_transport_internal.h"
8 #include "adf_transport_access_macros.h"
10 static DEFINE_MUTEX(ring_read_lock);
11 static DEFINE_MUTEX(bank_read_lock);
13 static void *adf_ring_start(struct seq_file *sfile, loff_t *pos)
15 struct adf_etr_ring_data *ring = sfile->private;
17 mutex_lock(&ring_read_lock);
18 if (*pos == 0)
19 return SEQ_START_TOKEN;
21 if (*pos >= (ADF_SIZE_TO_RING_SIZE_IN_BYTES(ring->ring_size) /
22 ADF_MSG_SIZE_TO_BYTES(ring->msg_size)))
23 return NULL;
25 return ring->base_addr +
26 (ADF_MSG_SIZE_TO_BYTES(ring->msg_size) * (*pos)++);
29 static void *adf_ring_next(struct seq_file *sfile, void *v, loff_t *pos)
31 struct adf_etr_ring_data *ring = sfile->private;
33 if (*pos >= (ADF_SIZE_TO_RING_SIZE_IN_BYTES(ring->ring_size) /
34 ADF_MSG_SIZE_TO_BYTES(ring->msg_size)))
35 return NULL;
37 return ring->base_addr +
38 (ADF_MSG_SIZE_TO_BYTES(ring->msg_size) * (*pos)++);
41 static int adf_ring_show(struct seq_file *sfile, void *v)
43 struct adf_etr_ring_data *ring = sfile->private;
44 struct adf_etr_bank_data *bank = ring->bank;
45 struct adf_hw_csr_ops *csr_ops = GET_CSR_OPS(bank->accel_dev);
46 void __iomem *csr = ring->bank->csr_addr;
48 if (v == SEQ_START_TOKEN) {
49 int head, tail, empty;
51 head = csr_ops->read_csr_ring_head(csr, bank->bank_number,
52 ring->ring_number);
53 tail = csr_ops->read_csr_ring_tail(csr, bank->bank_number,
54 ring->ring_number);
55 empty = csr_ops->read_csr_e_stat(csr, bank->bank_number);
57 seq_puts(sfile, "------- Ring configuration -------\n");
58 seq_printf(sfile, "ring name: %s\n",
59 ring->ring_debug->ring_name);
60 seq_printf(sfile, "ring num %d, bank num %d\n",
61 ring->ring_number, ring->bank->bank_number);
62 seq_printf(sfile, "head %x, tail %x, empty: %d\n",
63 head, tail, (empty & 1 << ring->ring_number)
64 >> ring->ring_number);
65 seq_printf(sfile, "ring size %d, msg size %d\n",
66 ADF_SIZE_TO_RING_SIZE_IN_BYTES(ring->ring_size),
67 ADF_MSG_SIZE_TO_BYTES(ring->msg_size));
68 seq_puts(sfile, "----------- Ring data ------------\n");
69 return 0;
71 seq_hex_dump(sfile, "", DUMP_PREFIX_ADDRESS, 32, 4,
72 v, ADF_MSG_SIZE_TO_BYTES(ring->msg_size), false);
73 return 0;
76 static void adf_ring_stop(struct seq_file *sfile, void *v)
78 mutex_unlock(&ring_read_lock);
81 static const struct seq_operations adf_ring_debug_sops = {
82 .start = adf_ring_start,
83 .next = adf_ring_next,
84 .stop = adf_ring_stop,
85 .show = adf_ring_show
88 DEFINE_SEQ_ATTRIBUTE(adf_ring_debug);
90 int adf_ring_debugfs_add(struct adf_etr_ring_data *ring, const char *name)
92 struct adf_etr_ring_debug_entry *ring_debug;
93 char entry_name[8];
95 ring_debug = kzalloc(sizeof(*ring_debug), GFP_KERNEL);
96 if (!ring_debug)
97 return -ENOMEM;
99 strlcpy(ring_debug->ring_name, name, sizeof(ring_debug->ring_name));
100 snprintf(entry_name, sizeof(entry_name), "ring_%02d",
101 ring->ring_number);
103 ring_debug->debug = debugfs_create_file(entry_name, S_IRUSR,
104 ring->bank->bank_debug_dir,
105 ring, &adf_ring_debug_fops);
106 ring->ring_debug = ring_debug;
107 return 0;
110 void adf_ring_debugfs_rm(struct adf_etr_ring_data *ring)
112 if (ring->ring_debug) {
113 debugfs_remove(ring->ring_debug->debug);
114 kfree(ring->ring_debug);
115 ring->ring_debug = NULL;
119 static void *adf_bank_start(struct seq_file *sfile, loff_t *pos)
121 struct adf_etr_bank_data *bank = sfile->private;
122 u8 num_rings_per_bank = GET_NUM_RINGS_PER_BANK(bank->accel_dev);
124 mutex_lock(&bank_read_lock);
125 if (*pos == 0)
126 return SEQ_START_TOKEN;
128 if (*pos >= num_rings_per_bank)
129 return NULL;
131 return pos;
134 static void *adf_bank_next(struct seq_file *sfile, void *v, loff_t *pos)
136 struct adf_etr_bank_data *bank = sfile->private;
137 u8 num_rings_per_bank = GET_NUM_RINGS_PER_BANK(bank->accel_dev);
139 if (++(*pos) >= num_rings_per_bank)
140 return NULL;
142 return pos;
145 static int adf_bank_show(struct seq_file *sfile, void *v)
147 struct adf_etr_bank_data *bank = sfile->private;
148 struct adf_hw_csr_ops *csr_ops = GET_CSR_OPS(bank->accel_dev);
150 if (v == SEQ_START_TOKEN) {
151 seq_printf(sfile, "------- Bank %d configuration -------\n",
152 bank->bank_number);
153 } else {
154 int ring_id = *((int *)v) - 1;
155 struct adf_etr_ring_data *ring = &bank->rings[ring_id];
156 void __iomem *csr = bank->csr_addr;
157 int head, tail, empty;
159 if (!(bank->ring_mask & 1 << ring_id))
160 return 0;
162 head = csr_ops->read_csr_ring_head(csr, bank->bank_number,
163 ring->ring_number);
164 tail = csr_ops->read_csr_ring_tail(csr, bank->bank_number,
165 ring->ring_number);
166 empty = csr_ops->read_csr_e_stat(csr, bank->bank_number);
168 seq_printf(sfile,
169 "ring num %02d, head %04x, tail %04x, empty: %d\n",
170 ring->ring_number, head, tail,
171 (empty & 1 << ring->ring_number) >>
172 ring->ring_number);
174 return 0;
177 static void adf_bank_stop(struct seq_file *sfile, void *v)
179 mutex_unlock(&bank_read_lock);
182 static const struct seq_operations adf_bank_debug_sops = {
183 .start = adf_bank_start,
184 .next = adf_bank_next,
185 .stop = adf_bank_stop,
186 .show = adf_bank_show
189 DEFINE_SEQ_ATTRIBUTE(adf_bank_debug);
191 int adf_bank_debugfs_add(struct adf_etr_bank_data *bank)
193 struct adf_accel_dev *accel_dev = bank->accel_dev;
194 struct dentry *parent = accel_dev->transport->debug;
195 char name[8];
197 snprintf(name, sizeof(name), "bank_%02d", bank->bank_number);
198 bank->bank_debug_dir = debugfs_create_dir(name, parent);
199 bank->bank_debug_cfg = debugfs_create_file("config", S_IRUSR,
200 bank->bank_debug_dir, bank,
201 &adf_bank_debug_fops);
202 return 0;
205 void adf_bank_debugfs_rm(struct adf_etr_bank_data *bank)
207 debugfs_remove(bank->bank_debug_cfg);
208 debugfs_remove(bank->bank_debug_dir);