blob: e8a242b5651915d001ad83d4d881dc4280fa8c4b [file] [log] [blame]
Maxime Chevallier21da57a2018-07-14 13:29:25 +02001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Driver for Marvell PPv2 network controller for Armada 375 SoC.
4 *
5 * Copyright (C) 2018 Marvell
6 */
7
8#include <linux/kernel.h>
9#include <linux/slab.h>
10#include <linux/debugfs.h>
11
12#include "mvpp2.h"
13#include "mvpp2_prs.h"
14
15struct mvpp2_dbgfs_prs_entry {
16 int tid;
17 struct mvpp2 *priv;
18};
19
20static int mvpp2_dbgfs_port_vid_show(struct seq_file *s, void *unused)
21{
22 struct mvpp2_port *port = s->private;
23 unsigned char byte[2], enable[2];
24 struct mvpp2 *priv = port->priv;
25 struct mvpp2_prs_entry pe;
26 unsigned long pmap;
27 u16 rvid;
28 int tid;
29
30 for (tid = MVPP2_PRS_VID_PORT_FIRST(port->id);
31 tid <= MVPP2_PRS_VID_PORT_LAST(port->id); tid++) {
32 mvpp2_prs_init_from_hw(priv, &pe, tid);
33
34 pmap = mvpp2_prs_tcam_port_map_get(&pe);
35
36 if (!priv->prs_shadow[tid].valid)
37 continue;
38
39 if (!test_bit(port->id, &pmap))
40 continue;
41
42 mvpp2_prs_tcam_data_byte_get(&pe, 2, &byte[0], &enable[0]);
43 mvpp2_prs_tcam_data_byte_get(&pe, 3, &byte[1], &enable[1]);
44
45 rvid = ((byte[0] & 0xf) << 8) + byte[1];
46
47 seq_printf(s, "%u\n", rvid);
48 }
49
50 return 0;
51}
52
53DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_port_vid);
54
55static int mvpp2_dbgfs_port_parser_show(struct seq_file *s, void *unused)
56{
57 struct mvpp2_port *port = s->private;
58 struct mvpp2 *priv = port->priv;
59 struct mvpp2_prs_entry pe;
60 unsigned long pmap;
61 int i;
62
63 for (i = 0; i < MVPP2_PRS_TCAM_SRAM_SIZE; i++) {
64 mvpp2_prs_init_from_hw(port->priv, &pe, i);
65
66 pmap = mvpp2_prs_tcam_port_map_get(&pe);
67 if (priv->prs_shadow[i].valid && test_bit(port->id, &pmap))
68 seq_printf(s, "%03d\n", i);
69 }
70
71 return 0;
72}
73
74DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_port_parser);
75
76static int mvpp2_dbgfs_filter_show(struct seq_file *s, void *unused)
77{
78 struct mvpp2_port *port = s->private;
79 struct mvpp2 *priv = port->priv;
80 struct mvpp2_prs_entry pe;
81 unsigned long pmap;
82 int index, tid;
83
84 for (tid = MVPP2_PE_MAC_RANGE_START;
85 tid <= MVPP2_PE_MAC_RANGE_END; tid++) {
86 unsigned char da[ETH_ALEN], da_mask[ETH_ALEN];
87
88 if (!priv->prs_shadow[tid].valid ||
89 priv->prs_shadow[tid].lu != MVPP2_PRS_LU_MAC ||
90 priv->prs_shadow[tid].udf != MVPP2_PRS_UDF_MAC_DEF)
91 continue;
92
93 mvpp2_prs_init_from_hw(priv, &pe, tid);
94
95 pmap = mvpp2_prs_tcam_port_map_get(&pe);
96
97 /* We only want entries active on this port */
98 if (!test_bit(port->id, &pmap))
99 continue;
100
101 /* Read mac addr from entry */
102 for (index = 0; index < ETH_ALEN; index++)
103 mvpp2_prs_tcam_data_byte_get(&pe, index, &da[index],
104 &da_mask[index]);
105
106 seq_printf(s, "%pM\n", da);
107 }
108
109 return 0;
110}
111
112DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_filter);
113
114static int mvpp2_dbgfs_prs_lu_show(struct seq_file *s, void *unused)
115{
116 struct mvpp2_dbgfs_prs_entry *entry = s->private;
117 struct mvpp2 *priv = entry->priv;
118
119 seq_printf(s, "%x\n", priv->prs_shadow[entry->tid].lu);
120
121 return 0;
122}
123
124DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_prs_lu);
125
126static int mvpp2_dbgfs_prs_pmap_show(struct seq_file *s, void *unused)
127{
128 struct mvpp2_dbgfs_prs_entry *entry = s->private;
129 struct mvpp2_prs_entry pe;
130 unsigned int pmap;
131
132 mvpp2_prs_init_from_hw(entry->priv, &pe, entry->tid);
133
134 pmap = mvpp2_prs_tcam_port_map_get(&pe);
135 pmap &= MVPP2_PRS_PORT_MASK;
136
137 seq_printf(s, "%02x\n", pmap);
138
139 return 0;
140}
141
142DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_prs_pmap);
143
144static int mvpp2_dbgfs_prs_ai_show(struct seq_file *s, void *unused)
145{
146 struct mvpp2_dbgfs_prs_entry *entry = s->private;
147 struct mvpp2_prs_entry pe;
148 unsigned char ai, ai_mask;
149
150 mvpp2_prs_init_from_hw(entry->priv, &pe, entry->tid);
151
152 ai = pe.tcam[MVPP2_PRS_TCAM_AI_WORD] & MVPP2_PRS_AI_MASK;
153 ai_mask = (pe.tcam[MVPP2_PRS_TCAM_AI_WORD] >> 16) & MVPP2_PRS_AI_MASK;
154
155 seq_printf(s, "%02x %02x\n", ai, ai_mask);
156
157 return 0;
158}
159
160DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_prs_ai);
161
162static int mvpp2_dbgfs_prs_hdata_show(struct seq_file *s, void *unused)
163{
164 struct mvpp2_dbgfs_prs_entry *entry = s->private;
165 struct mvpp2_prs_entry pe;
166 unsigned char data[8], mask[8];
167 int i;
168
169 mvpp2_prs_init_from_hw(entry->priv, &pe, entry->tid);
170
171 for (i = 0; i < 8; i++)
172 mvpp2_prs_tcam_data_byte_get(&pe, i, &data[i], &mask[i]);
173
174 seq_printf(s, "%*phN %*phN\n", 8, data, 8, mask);
175
176 return 0;
177}
178
179DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_prs_hdata);
180
181static int mvpp2_dbgfs_prs_sram_show(struct seq_file *s, void *unused)
182{
183 struct mvpp2_dbgfs_prs_entry *entry = s->private;
184 struct mvpp2_prs_entry pe;
185
186 mvpp2_prs_init_from_hw(entry->priv, &pe, entry->tid);
187
188 seq_printf(s, "%*phN\n", 14, pe.sram);
189
190 return 0;
191}
192
193DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_prs_sram);
194
195static int mvpp2_dbgfs_prs_valid_show(struct seq_file *s, void *unused)
196{
197 struct mvpp2_dbgfs_prs_entry *entry = s->private;
198 struct mvpp2 *priv = entry->priv;
199 int tid = entry->tid;
200
201 seq_printf(s, "%d\n", priv->prs_shadow[tid].valid ? 1 : 0);
202
203 return 0;
204}
205
206static int mvpp2_dbgfs_prs_valid_open(struct inode *inode, struct file *file)
207{
208 return single_open(file, mvpp2_dbgfs_prs_valid_show, inode->i_private);
209}
210
211static int mvpp2_dbgfs_prs_valid_release(struct inode *inode, struct file *file)
212{
213 struct seq_file *seq = file->private_data;
214 struct mvpp2_dbgfs_prs_entry *entry = seq->private;
215
216 kfree(entry);
217 return single_release(inode, file);
218}
219
220static const struct file_operations mvpp2_dbgfs_prs_valid_fops = {
221 .open = mvpp2_dbgfs_prs_valid_open,
222 .read = seq_read,
223 .release = mvpp2_dbgfs_prs_valid_release,
224};
225
226static int mvpp2_dbgfs_prs_entry_init(struct dentry *parent,
227 struct mvpp2 *priv, int tid)
228{
229 struct mvpp2_dbgfs_prs_entry *entry;
230 struct dentry *prs_entry_dir;
231 char prs_entry_name[10];
232
233 if (tid >= MVPP2_PRS_TCAM_SRAM_SIZE)
234 return -EINVAL;
235
236 sprintf(prs_entry_name, "%03d", tid);
237
238 prs_entry_dir = debugfs_create_dir(prs_entry_name, parent);
239 if (!prs_entry_dir)
240 return -ENOMEM;
241
242 /* The 'valid' entry's ops will free that */
243 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
244 if (!entry)
245 return -ENOMEM;
246
247 entry->tid = tid;
248 entry->priv = priv;
249
250 /* Create each attr */
251 debugfs_create_file("sram", 0444, prs_entry_dir, entry,
252 &mvpp2_dbgfs_prs_sram_fops);
253
254 debugfs_create_file("valid", 0644, prs_entry_dir, entry,
255 &mvpp2_dbgfs_prs_valid_fops);
256
257 debugfs_create_file("lookup_id", 0644, prs_entry_dir, entry,
258 &mvpp2_dbgfs_prs_lu_fops);
259
260 debugfs_create_file("ai", 0644, prs_entry_dir, entry,
261 &mvpp2_dbgfs_prs_ai_fops);
262
263 debugfs_create_file("header_data", 0644, prs_entry_dir, entry,
264 &mvpp2_dbgfs_prs_hdata_fops);
265
266 return 0;
267}
268
269static int mvpp2_dbgfs_prs_init(struct dentry *parent, struct mvpp2 *priv)
270{
271 struct dentry *prs_dir;
272 int i, ret;
273
274 prs_dir = debugfs_create_dir("parser", parent);
275 if (!prs_dir)
276 return -ENOMEM;
277
278 for (i = 0; i < MVPP2_PRS_TCAM_SRAM_SIZE; i++) {
279 ret = mvpp2_dbgfs_prs_entry_init(prs_dir, priv, i);
280 if (ret)
281 return ret;
282 }
283
284 return 0;
285}
286
287static int mvpp2_dbgfs_port_init(struct dentry *parent,
288 struct mvpp2_port *port)
289{
290 struct dentry *port_dir;
291
292 port_dir = debugfs_create_dir(port->dev->name, parent);
293 if (IS_ERR(port_dir))
294 return PTR_ERR(port_dir);
295
296 debugfs_create_file("parser_entries", 0444, port_dir, port,
297 &mvpp2_dbgfs_port_parser_fops);
298
299 debugfs_create_file("mac_filter", 0444, port_dir, port,
300 &mvpp2_dbgfs_filter_fops);
301
302 debugfs_create_file("vid_filter", 0444, port_dir, port,
303 &mvpp2_dbgfs_port_vid_fops);
304
305 return 0;
306}
307
308void mvpp2_dbgfs_cleanup(struct mvpp2 *priv)
309{
310 debugfs_remove_recursive(priv->dbgfs_dir);
311}
312
313void mvpp2_dbgfs_init(struct mvpp2 *priv, const char *name)
314{
315 struct dentry *mvpp2_dir, *mvpp2_root;
316 int ret, i;
317
318 mvpp2_root = debugfs_lookup(MVPP2_DRIVER_NAME, NULL);
319 if (!mvpp2_root) {
320 mvpp2_root = debugfs_create_dir(MVPP2_DRIVER_NAME, NULL);
321 if (IS_ERR(mvpp2_root))
322 return;
323 }
324
325 mvpp2_dir = debugfs_create_dir(name, mvpp2_root);
326 if (IS_ERR(mvpp2_dir))
327 return;
328
329 priv->dbgfs_dir = mvpp2_dir;
330
331 ret = mvpp2_dbgfs_prs_init(mvpp2_dir, priv);
332 if (ret)
333 goto err;
334
335 for (i = 0; i < priv->port_count; i++) {
336 ret = mvpp2_dbgfs_port_init(mvpp2_dir, priv->port_list[i]);
337 if (ret)
338 goto err;
339 }
340
341 return;
342err:
343 mvpp2_dbgfs_cleanup(priv);
344}