1 // SPDX-License-Identifier: GPL-2.0
3 * Driver for Marvell PPv2 network controller for Armada 375 SoC.
5 * Copyright (C) 2018 Marvell
8 #include <linux/kernel.h>
9 #include <linux/slab.h>
10 #include <linux/debugfs.h>
13 #include "mvpp2_prs.h"
14 #include "mvpp2_cls.h"
16 struct mvpp2_dbgfs_prs_entry {
21 struct mvpp2_dbgfs_flow_entry {
26 struct mvpp2_dbgfs_port_flow_entry {
27 struct mvpp2_port *port;
28 struct mvpp2_dbgfs_flow_entry *dbg_fe;
31 static int mvpp2_dbgfs_flow_flt_hits_show(struct seq_file *s, void *unused)
33 struct mvpp2_dbgfs_flow_entry *entry = s->private;
34 int id = MVPP2_FLOW_C2_ENTRY(entry->flow);
36 u32 hits = mvpp2_cls_flow_hits(entry->priv, id);
38 seq_printf(s, "%u\n", hits);
43 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_flow_flt_hits);
45 static int mvpp2_dbgfs_flow_dec_hits_show(struct seq_file *s, void *unused)
47 struct mvpp2_dbgfs_flow_entry *entry = s->private;
49 u32 hits = mvpp2_cls_lookup_hits(entry->priv, entry->flow);
51 seq_printf(s, "%u\n", hits);
56 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_flow_dec_hits);
58 static int mvpp2_dbgfs_flow_type_show(struct seq_file *s, void *unused)
60 struct mvpp2_dbgfs_flow_entry *entry = s->private;
61 struct mvpp2_cls_flow *f;
62 const char *flow_name;
64 f = mvpp2_cls_flow_get(entry->flow);
68 switch (f->flow_type) {
91 seq_printf(s, "%s\n", flow_name);
96 static int mvpp2_dbgfs_flow_type_open(struct inode *inode, struct file *file)
98 return single_open(file, mvpp2_dbgfs_flow_type_show, inode->i_private);
101 static int mvpp2_dbgfs_flow_type_release(struct inode *inode, struct file *file)
103 struct seq_file *seq = file->private_data;
104 struct mvpp2_dbgfs_flow_entry *flow_entry = seq->private;
107 return single_release(inode, file);
110 static const struct file_operations mvpp2_dbgfs_flow_type_fops = {
111 .open = mvpp2_dbgfs_flow_type_open,
113 .release = mvpp2_dbgfs_flow_type_release,
116 static int mvpp2_dbgfs_flow_id_show(struct seq_file *s, void *unused)
118 struct mvpp2_dbgfs_flow_entry *entry = s->private;
119 struct mvpp2_cls_flow *f;
121 f = mvpp2_cls_flow_get(entry->flow);
125 seq_printf(s, "%d\n", f->flow_id);
130 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_flow_id);
132 static int mvpp2_dbgfs_port_flow_hash_opt_show(struct seq_file *s, void *unused)
134 struct mvpp2_dbgfs_port_flow_entry *entry = s->private;
135 struct mvpp2_port *port = entry->port;
136 struct mvpp2_cls_flow_entry fe;
137 struct mvpp2_cls_flow *f;
141 f = mvpp2_cls_flow_get(entry->dbg_fe->flow);
145 flow_index = MVPP2_PORT_FLOW_HASH_ENTRY(entry->port->id, f->flow_id);
147 mvpp2_cls_flow_read(port->priv, flow_index, &fe);
149 hash_opts = mvpp2_flow_get_hek_fields(&fe);
151 seq_printf(s, "0x%04x\n", hash_opts);
156 static int mvpp2_dbgfs_port_flow_hash_opt_open(struct inode *inode,
159 return single_open(file, mvpp2_dbgfs_port_flow_hash_opt_show,
163 static int mvpp2_dbgfs_port_flow_hash_opt_release(struct inode *inode,
166 struct seq_file *seq = file->private_data;
167 struct mvpp2_dbgfs_port_flow_entry *flow_entry = seq->private;
170 return single_release(inode, file);
173 static const struct file_operations mvpp2_dbgfs_port_flow_hash_opt_fops = {
174 .open = mvpp2_dbgfs_port_flow_hash_opt_open,
176 .release = mvpp2_dbgfs_port_flow_hash_opt_release,
179 static int mvpp2_dbgfs_port_flow_engine_show(struct seq_file *s, void *unused)
181 struct mvpp2_dbgfs_port_flow_entry *entry = s->private;
182 struct mvpp2_port *port = entry->port;
183 struct mvpp2_cls_flow_entry fe;
184 struct mvpp2_cls_flow *f;
185 int flow_index, engine;
187 f = mvpp2_cls_flow_get(entry->dbg_fe->flow);
191 flow_index = MVPP2_PORT_FLOW_HASH_ENTRY(entry->port->id, f->flow_id);
193 mvpp2_cls_flow_read(port->priv, flow_index, &fe);
195 engine = mvpp2_cls_flow_eng_get(&fe);
197 seq_printf(s, "%d\n", engine);
202 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_port_flow_engine);
204 static int mvpp2_dbgfs_flow_c2_hits_show(struct seq_file *s, void *unused)
206 struct mvpp2_port *port = s->private;
209 hits = mvpp2_cls_c2_hit_count(port->priv,
210 MVPP22_CLS_C2_RSS_ENTRY(port->id));
212 seq_printf(s, "%u\n", hits);
217 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_flow_c2_hits);
219 static int mvpp2_dbgfs_flow_c2_rxq_show(struct seq_file *s, void *unused)
221 struct mvpp2_port *port = s->private;
222 struct mvpp2_cls_c2_entry c2;
225 mvpp2_cls_c2_read(port->priv, MVPP22_CLS_C2_RSS_ENTRY(port->id), &c2);
227 qh = (c2.attr[0] >> MVPP22_CLS_C2_ATTR0_QHIGH_OFFS) &
228 MVPP22_CLS_C2_ATTR0_QHIGH_MASK;
230 ql = (c2.attr[0] >> MVPP22_CLS_C2_ATTR0_QLOW_OFFS) &
231 MVPP22_CLS_C2_ATTR0_QLOW_MASK;
233 seq_printf(s, "%d\n", (qh << 3 | ql));
238 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_flow_c2_rxq);
240 static int mvpp2_dbgfs_flow_c2_enable_show(struct seq_file *s, void *unused)
242 struct mvpp2_port *port = s->private;
243 struct mvpp2_cls_c2_entry c2;
246 mvpp2_cls_c2_read(port->priv, MVPP22_CLS_C2_RSS_ENTRY(port->id), &c2);
248 enabled = !!(c2.attr[2] & MVPP22_CLS_C2_ATTR2_RSS_EN);
250 seq_printf(s, "%d\n", enabled);
255 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_flow_c2_enable);
257 static int mvpp2_dbgfs_port_vid_show(struct seq_file *s, void *unused)
259 struct mvpp2_port *port = s->private;
260 unsigned char byte[2], enable[2];
261 struct mvpp2 *priv = port->priv;
262 struct mvpp2_prs_entry pe;
267 for (tid = MVPP2_PRS_VID_PORT_FIRST(port->id);
268 tid <= MVPP2_PRS_VID_PORT_LAST(port->id); tid++) {
269 mvpp2_prs_init_from_hw(priv, &pe, tid);
271 pmap = mvpp2_prs_tcam_port_map_get(&pe);
273 if (!priv->prs_shadow[tid].valid)
276 if (!test_bit(port->id, &pmap))
279 mvpp2_prs_tcam_data_byte_get(&pe, 2, &byte[0], &enable[0]);
280 mvpp2_prs_tcam_data_byte_get(&pe, 3, &byte[1], &enable[1]);
282 rvid = ((byte[0] & 0xf) << 8) + byte[1];
284 seq_printf(s, "%u\n", rvid);
290 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_port_vid);
292 static int mvpp2_dbgfs_port_parser_show(struct seq_file *s, void *unused)
294 struct mvpp2_port *port = s->private;
295 struct mvpp2 *priv = port->priv;
296 struct mvpp2_prs_entry pe;
300 for (i = 0; i < MVPP2_PRS_TCAM_SRAM_SIZE; i++) {
301 mvpp2_prs_init_from_hw(port->priv, &pe, i);
303 pmap = mvpp2_prs_tcam_port_map_get(&pe);
304 if (priv->prs_shadow[i].valid && test_bit(port->id, &pmap))
305 seq_printf(s, "%03d\n", i);
311 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_port_parser);
313 static int mvpp2_dbgfs_filter_show(struct seq_file *s, void *unused)
315 struct mvpp2_port *port = s->private;
316 struct mvpp2 *priv = port->priv;
317 struct mvpp2_prs_entry pe;
321 for (tid = MVPP2_PE_MAC_RANGE_START;
322 tid <= MVPP2_PE_MAC_RANGE_END; tid++) {
323 unsigned char da[ETH_ALEN], da_mask[ETH_ALEN];
325 if (!priv->prs_shadow[tid].valid ||
326 priv->prs_shadow[tid].lu != MVPP2_PRS_LU_MAC ||
327 priv->prs_shadow[tid].udf != MVPP2_PRS_UDF_MAC_DEF)
330 mvpp2_prs_init_from_hw(priv, &pe, tid);
332 pmap = mvpp2_prs_tcam_port_map_get(&pe);
334 /* We only want entries active on this port */
335 if (!test_bit(port->id, &pmap))
338 /* Read mac addr from entry */
339 for (index = 0; index < ETH_ALEN; index++)
340 mvpp2_prs_tcam_data_byte_get(&pe, index, &da[index],
343 seq_printf(s, "%pM\n", da);
349 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_filter);
351 static int mvpp2_dbgfs_prs_lu_show(struct seq_file *s, void *unused)
353 struct mvpp2_dbgfs_prs_entry *entry = s->private;
354 struct mvpp2 *priv = entry->priv;
356 seq_printf(s, "%x\n", priv->prs_shadow[entry->tid].lu);
361 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_prs_lu);
363 static int mvpp2_dbgfs_prs_pmap_show(struct seq_file *s, void *unused)
365 struct mvpp2_dbgfs_prs_entry *entry = s->private;
366 struct mvpp2_prs_entry pe;
369 mvpp2_prs_init_from_hw(entry->priv, &pe, entry->tid);
371 pmap = mvpp2_prs_tcam_port_map_get(&pe);
372 pmap &= MVPP2_PRS_PORT_MASK;
374 seq_printf(s, "%02x\n", pmap);
379 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_prs_pmap);
381 static int mvpp2_dbgfs_prs_ai_show(struct seq_file *s, void *unused)
383 struct mvpp2_dbgfs_prs_entry *entry = s->private;
384 struct mvpp2_prs_entry pe;
385 unsigned char ai, ai_mask;
387 mvpp2_prs_init_from_hw(entry->priv, &pe, entry->tid);
389 ai = pe.tcam[MVPP2_PRS_TCAM_AI_WORD] & MVPP2_PRS_AI_MASK;
390 ai_mask = (pe.tcam[MVPP2_PRS_TCAM_AI_WORD] >> 16) & MVPP2_PRS_AI_MASK;
392 seq_printf(s, "%02x %02x\n", ai, ai_mask);
397 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_prs_ai);
399 static int mvpp2_dbgfs_prs_hdata_show(struct seq_file *s, void *unused)
401 struct mvpp2_dbgfs_prs_entry *entry = s->private;
402 struct mvpp2_prs_entry pe;
403 unsigned char data[8], mask[8];
406 mvpp2_prs_init_from_hw(entry->priv, &pe, entry->tid);
408 for (i = 0; i < 8; i++)
409 mvpp2_prs_tcam_data_byte_get(&pe, i, &data[i], &mask[i]);
411 seq_printf(s, "%*phN %*phN\n", 8, data, 8, mask);
416 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_prs_hdata);
418 static int mvpp2_dbgfs_prs_sram_show(struct seq_file *s, void *unused)
420 struct mvpp2_dbgfs_prs_entry *entry = s->private;
421 struct mvpp2_prs_entry pe;
423 mvpp2_prs_init_from_hw(entry->priv, &pe, entry->tid);
425 seq_printf(s, "%*phN\n", 14, pe.sram);
430 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_prs_sram);
432 static int mvpp2_dbgfs_prs_hits_show(struct seq_file *s, void *unused)
434 struct mvpp2_dbgfs_prs_entry *entry = s->private;
437 val = mvpp2_prs_hits(entry->priv, entry->tid);
441 seq_printf(s, "%d\n", val);
446 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_prs_hits);
448 static int mvpp2_dbgfs_prs_valid_show(struct seq_file *s, void *unused)
450 struct mvpp2_dbgfs_prs_entry *entry = s->private;
451 struct mvpp2 *priv = entry->priv;
452 int tid = entry->tid;
454 seq_printf(s, "%d\n", priv->prs_shadow[tid].valid ? 1 : 0);
459 static int mvpp2_dbgfs_prs_valid_open(struct inode *inode, struct file *file)
461 return single_open(file, mvpp2_dbgfs_prs_valid_show, inode->i_private);
464 static int mvpp2_dbgfs_prs_valid_release(struct inode *inode, struct file *file)
466 struct seq_file *seq = file->private_data;
467 struct mvpp2_dbgfs_prs_entry *entry = seq->private;
470 return single_release(inode, file);
473 static const struct file_operations mvpp2_dbgfs_prs_valid_fops = {
474 .open = mvpp2_dbgfs_prs_valid_open,
476 .release = mvpp2_dbgfs_prs_valid_release,
479 static int mvpp2_dbgfs_flow_port_init(struct dentry *parent,
480 struct mvpp2_port *port,
481 struct mvpp2_dbgfs_flow_entry *entry)
483 struct mvpp2_dbgfs_port_flow_entry *port_entry;
484 struct dentry *port_dir;
486 port_dir = debugfs_create_dir(port->dev->name, parent);
488 /* This will be freed by 'hash_opts' release op */
489 port_entry = kmalloc(sizeof(*port_entry), GFP_KERNEL);
493 port_entry->port = port;
494 port_entry->dbg_fe = entry;
496 debugfs_create_file("hash_opts", 0444, port_dir, port_entry,
497 &mvpp2_dbgfs_port_flow_hash_opt_fops);
499 debugfs_create_file("engine", 0444, port_dir, port_entry,
500 &mvpp2_dbgfs_port_flow_engine_fops);
505 static int mvpp2_dbgfs_flow_entry_init(struct dentry *parent,
506 struct mvpp2 *priv, int flow)
508 struct mvpp2_dbgfs_flow_entry *entry;
509 struct dentry *flow_entry_dir;
510 char flow_entry_name[10];
513 sprintf(flow_entry_name, "%02d", flow);
515 flow_entry_dir = debugfs_create_dir(flow_entry_name, parent);
517 /* This will be freed by 'type' release op */
518 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
525 debugfs_create_file("flow_hits", 0444, flow_entry_dir, entry,
526 &mvpp2_dbgfs_flow_flt_hits_fops);
528 debugfs_create_file("dec_hits", 0444, flow_entry_dir, entry,
529 &mvpp2_dbgfs_flow_dec_hits_fops);
531 debugfs_create_file("type", 0444, flow_entry_dir, entry,
532 &mvpp2_dbgfs_flow_type_fops);
534 debugfs_create_file("id", 0444, flow_entry_dir, entry,
535 &mvpp2_dbgfs_flow_id_fops);
537 /* Create entry for each port */
538 for (i = 0; i < priv->port_count; i++) {
539 ret = mvpp2_dbgfs_flow_port_init(flow_entry_dir,
540 priv->port_list[i], entry);
547 static int mvpp2_dbgfs_flow_init(struct dentry *parent, struct mvpp2 *priv)
549 struct dentry *flow_dir;
552 flow_dir = debugfs_create_dir("flows", parent);
554 for (i = 0; i < MVPP2_N_FLOWS; i++) {
555 ret = mvpp2_dbgfs_flow_entry_init(flow_dir, priv, i);
563 static int mvpp2_dbgfs_prs_entry_init(struct dentry *parent,
564 struct mvpp2 *priv, int tid)
566 struct mvpp2_dbgfs_prs_entry *entry;
567 struct dentry *prs_entry_dir;
568 char prs_entry_name[10];
570 if (tid >= MVPP2_PRS_TCAM_SRAM_SIZE)
573 sprintf(prs_entry_name, "%03d", tid);
575 prs_entry_dir = debugfs_create_dir(prs_entry_name, parent);
577 /* The 'valid' entry's ops will free that */
578 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
585 /* Create each attr */
586 debugfs_create_file("sram", 0444, prs_entry_dir, entry,
587 &mvpp2_dbgfs_prs_sram_fops);
589 debugfs_create_file("valid", 0644, prs_entry_dir, entry,
590 &mvpp2_dbgfs_prs_valid_fops);
592 debugfs_create_file("lookup_id", 0644, prs_entry_dir, entry,
593 &mvpp2_dbgfs_prs_lu_fops);
595 debugfs_create_file("ai", 0644, prs_entry_dir, entry,
596 &mvpp2_dbgfs_prs_ai_fops);
598 debugfs_create_file("header_data", 0644, prs_entry_dir, entry,
599 &mvpp2_dbgfs_prs_hdata_fops);
601 debugfs_create_file("hits", 0444, prs_entry_dir, entry,
602 &mvpp2_dbgfs_prs_hits_fops);
607 static int mvpp2_dbgfs_prs_init(struct dentry *parent, struct mvpp2 *priv)
609 struct dentry *prs_dir;
612 prs_dir = debugfs_create_dir("parser", parent);
614 for (i = 0; i < MVPP2_PRS_TCAM_SRAM_SIZE; i++) {
615 ret = mvpp2_dbgfs_prs_entry_init(prs_dir, priv, i);
623 static int mvpp2_dbgfs_port_init(struct dentry *parent,
624 struct mvpp2_port *port)
626 struct dentry *port_dir;
628 port_dir = debugfs_create_dir(port->dev->name, parent);
630 debugfs_create_file("parser_entries", 0444, port_dir, port,
631 &mvpp2_dbgfs_port_parser_fops);
633 debugfs_create_file("mac_filter", 0444, port_dir, port,
634 &mvpp2_dbgfs_filter_fops);
636 debugfs_create_file("vid_filter", 0444, port_dir, port,
637 &mvpp2_dbgfs_port_vid_fops);
639 debugfs_create_file("c2_hits", 0444, port_dir, port,
640 &mvpp2_dbgfs_flow_c2_hits_fops);
642 debugfs_create_file("default_rxq", 0444, port_dir, port,
643 &mvpp2_dbgfs_flow_c2_rxq_fops);
645 debugfs_create_file("rss_enable", 0444, port_dir, port,
646 &mvpp2_dbgfs_flow_c2_enable_fops);
651 static struct dentry *mvpp2_root;
653 void mvpp2_dbgfs_exit(void)
655 debugfs_remove(mvpp2_root);
658 void mvpp2_dbgfs_cleanup(struct mvpp2 *priv)
660 debugfs_remove_recursive(priv->dbgfs_dir);
663 void mvpp2_dbgfs_init(struct mvpp2 *priv, const char *name)
665 struct dentry *mvpp2_dir;
669 mvpp2_root = debugfs_create_dir(MVPP2_DRIVER_NAME, NULL);
671 mvpp2_dir = debugfs_create_dir(name, mvpp2_root);
673 priv->dbgfs_dir = mvpp2_dir;
675 ret = mvpp2_dbgfs_prs_init(mvpp2_dir, priv);
679 for (i = 0; i < priv->port_count; i++) {
680 ret = mvpp2_dbgfs_port_init(mvpp2_dir, priv->port_list[i]);
685 ret = mvpp2_dbgfs_flow_init(mvpp2_dir, priv);
691 mvpp2_dbgfs_cleanup(priv);