hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/drivers/net/ethernet/marvell/mvpp2/mvpp2_debugfs.c
....@@ -18,8 +18,18 @@
1818 struct mvpp2 *priv;
1919 };
2020
21
+struct mvpp2_dbgfs_c2_entry {
22
+ int id;
23
+ struct mvpp2 *priv;
24
+};
25
+
2126 struct mvpp2_dbgfs_flow_entry {
2227 int flow;
28
+ struct mvpp2 *priv;
29
+};
30
+
31
+struct mvpp2_dbgfs_flow_tbl_entry {
32
+ int id;
2333 struct mvpp2 *priv;
2434 };
2535
....@@ -28,12 +38,28 @@
2838 struct mvpp2_dbgfs_flow_entry *dbg_fe;
2939 };
3040
41
+struct mvpp2_dbgfs_entries {
42
+ /* Entries for Header Parser debug info */
43
+ struct mvpp2_dbgfs_prs_entry prs_entries[MVPP2_PRS_TCAM_SRAM_SIZE];
44
+
45
+ /* Entries for Classifier C2 engine debug info */
46
+ struct mvpp2_dbgfs_c2_entry c2_entries[MVPP22_CLS_C2_N_ENTRIES];
47
+
48
+ /* Entries for Classifier Flow Table debug info */
49
+ struct mvpp2_dbgfs_flow_tbl_entry flt_entries[MVPP2_CLS_FLOWS_TBL_SIZE];
50
+
51
+ /* Entries for Classifier flows debug info */
52
+ struct mvpp2_dbgfs_flow_entry flow_entries[MVPP2_N_PRS_FLOWS];
53
+
54
+ /* Entries for per-port flows debug info */
55
+ struct mvpp2_dbgfs_port_flow_entry port_flow_entries[MVPP2_MAX_PORTS];
56
+};
57
+
3158 static int mvpp2_dbgfs_flow_flt_hits_show(struct seq_file *s, void *unused)
3259 {
33
- struct mvpp2_dbgfs_flow_entry *entry = s->private;
34
- int id = MVPP2_FLOW_C2_ENTRY(entry->flow);
60
+ struct mvpp2_dbgfs_flow_tbl_entry *entry = s->private;
3561
36
- u32 hits = mvpp2_cls_flow_hits(entry->priv, id);
62
+ u32 hits = mvpp2_cls_flow_hits(entry->priv, entry->id);
3763
3864 seq_printf(s, "%u\n", hits);
3965
....@@ -58,7 +84,7 @@
5884 static int mvpp2_dbgfs_flow_type_show(struct seq_file *s, void *unused)
5985 {
6086 struct mvpp2_dbgfs_flow_entry *entry = s->private;
61
- struct mvpp2_cls_flow *f;
87
+ const struct mvpp2_cls_flow *f;
6288 const char *flow_name;
6389
6490 f = mvpp2_cls_flow_get(entry->flow);
....@@ -93,30 +119,12 @@
93119 return 0;
94120 }
95121
96
-static int mvpp2_dbgfs_flow_type_open(struct inode *inode, struct file *file)
97
-{
98
- return single_open(file, mvpp2_dbgfs_flow_type_show, inode->i_private);
99
-}
100
-
101
-static int mvpp2_dbgfs_flow_type_release(struct inode *inode, struct file *file)
102
-{
103
- struct seq_file *seq = file->private_data;
104
- struct mvpp2_dbgfs_flow_entry *flow_entry = seq->private;
105
-
106
- kfree(flow_entry);
107
- return single_release(inode, file);
108
-}
109
-
110
-static const struct file_operations mvpp2_dbgfs_flow_type_fops = {
111
- .open = mvpp2_dbgfs_flow_type_open,
112
- .read = seq_read,
113
- .release = mvpp2_dbgfs_flow_type_release,
114
-};
122
+DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_flow_type);
115123
116124 static int mvpp2_dbgfs_flow_id_show(struct seq_file *s, void *unused)
117125 {
118
- struct mvpp2_dbgfs_flow_entry *entry = s->private;
119
- struct mvpp2_cls_flow *f;
126
+ const struct mvpp2_dbgfs_flow_entry *entry = s->private;
127
+ const struct mvpp2_cls_flow *f;
120128
121129 f = mvpp2_cls_flow_get(entry->flow);
122130 if (!f)
....@@ -134,7 +142,7 @@
134142 struct mvpp2_dbgfs_port_flow_entry *entry = s->private;
135143 struct mvpp2_port *port = entry->port;
136144 struct mvpp2_cls_flow_entry fe;
137
- struct mvpp2_cls_flow *f;
145
+ const struct mvpp2_cls_flow *f;
138146 int flow_index;
139147 u16 hash_opts;
140148
....@@ -142,7 +150,7 @@
142150 if (!f)
143151 return -EINVAL;
144152
145
- flow_index = MVPP2_PORT_FLOW_HASH_ENTRY(entry->port->id, f->flow_id);
153
+ flow_index = MVPP2_CLS_FLT_HASH_ENTRY(entry->port->id, f->flow_id);
146154
147155 mvpp2_cls_flow_read(port->priv, flow_index, &fe);
148156
....@@ -153,42 +161,21 @@
153161 return 0;
154162 }
155163
156
-static int mvpp2_dbgfs_port_flow_hash_opt_open(struct inode *inode,
157
- struct file *file)
158
-{
159
- return single_open(file, mvpp2_dbgfs_port_flow_hash_opt_show,
160
- inode->i_private);
161
-}
162
-
163
-static int mvpp2_dbgfs_port_flow_hash_opt_release(struct inode *inode,
164
- struct file *file)
165
-{
166
- struct seq_file *seq = file->private_data;
167
- struct mvpp2_dbgfs_port_flow_entry *flow_entry = seq->private;
168
-
169
- kfree(flow_entry);
170
- return single_release(inode, file);
171
-}
172
-
173
-static const struct file_operations mvpp2_dbgfs_port_flow_hash_opt_fops = {
174
- .open = mvpp2_dbgfs_port_flow_hash_opt_open,
175
- .read = seq_read,
176
- .release = mvpp2_dbgfs_port_flow_hash_opt_release,
177
-};
164
+DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_port_flow_hash_opt);
178165
179166 static int mvpp2_dbgfs_port_flow_engine_show(struct seq_file *s, void *unused)
180167 {
181168 struct mvpp2_dbgfs_port_flow_entry *entry = s->private;
182169 struct mvpp2_port *port = entry->port;
183170 struct mvpp2_cls_flow_entry fe;
184
- struct mvpp2_cls_flow *f;
171
+ const struct mvpp2_cls_flow *f;
185172 int flow_index, engine;
186173
187174 f = mvpp2_cls_flow_get(entry->dbg_fe->flow);
188175 if (!f)
189176 return -EINVAL;
190177
191
- flow_index = MVPP2_PORT_FLOW_HASH_ENTRY(entry->port->id, f->flow_id);
178
+ flow_index = MVPP2_CLS_FLT_HASH_ENTRY(entry->port->id, f->flow_id);
192179
193180 mvpp2_cls_flow_read(port->priv, flow_index, &fe);
194181
....@@ -203,11 +190,10 @@
203190
204191 static int mvpp2_dbgfs_flow_c2_hits_show(struct seq_file *s, void *unused)
205192 {
206
- struct mvpp2_port *port = s->private;
193
+ struct mvpp2_dbgfs_c2_entry *entry = s->private;
207194 u32 hits;
208195
209
- hits = mvpp2_cls_c2_hit_count(port->priv,
210
- MVPP22_CLS_C2_RSS_ENTRY(port->id));
196
+ hits = mvpp2_cls_c2_hit_count(entry->priv, entry->id);
211197
212198 seq_printf(s, "%u\n", hits);
213199
....@@ -218,11 +204,11 @@
218204
219205 static int mvpp2_dbgfs_flow_c2_rxq_show(struct seq_file *s, void *unused)
220206 {
221
- struct mvpp2_port *port = s->private;
207
+ struct mvpp2_dbgfs_c2_entry *entry = s->private;
222208 struct mvpp2_cls_c2_entry c2;
223209 u8 qh, ql;
224210
225
- mvpp2_cls_c2_read(port->priv, MVPP22_CLS_C2_RSS_ENTRY(port->id), &c2);
211
+ mvpp2_cls_c2_read(entry->priv, entry->id, &c2);
226212
227213 qh = (c2.attr[0] >> MVPP22_CLS_C2_ATTR0_QHIGH_OFFS) &
228214 MVPP22_CLS_C2_ATTR0_QHIGH_MASK;
....@@ -239,11 +225,11 @@
239225
240226 static int mvpp2_dbgfs_flow_c2_enable_show(struct seq_file *s, void *unused)
241227 {
242
- struct mvpp2_port *port = s->private;
228
+ struct mvpp2_dbgfs_c2_entry *entry = s->private;
243229 struct mvpp2_cls_c2_entry c2;
244230 int enabled;
245231
246
- mvpp2_cls_c2_read(port->priv, MVPP22_CLS_C2_RSS_ENTRY(port->id), &c2);
232
+ mvpp2_cls_c2_read(entry->priv, entry->id, &c2);
247233
248234 enabled = !!(c2.attr[2] & MVPP22_CLS_C2_ATTR2_RSS_EN);
249235
....@@ -456,25 +442,7 @@
456442 return 0;
457443 }
458444
459
-static int mvpp2_dbgfs_prs_valid_open(struct inode *inode, struct file *file)
460
-{
461
- return single_open(file, mvpp2_dbgfs_prs_valid_show, inode->i_private);
462
-}
463
-
464
-static int mvpp2_dbgfs_prs_valid_release(struct inode *inode, struct file *file)
465
-{
466
- struct seq_file *seq = file->private_data;
467
- struct mvpp2_dbgfs_prs_entry *entry = seq->private;
468
-
469
- kfree(entry);
470
- return single_release(inode, file);
471
-}
472
-
473
-static const struct file_operations mvpp2_dbgfs_prs_valid_fops = {
474
- .open = mvpp2_dbgfs_prs_valid_open,
475
- .read = seq_read,
476
- .release = mvpp2_dbgfs_prs_valid_release,
477
-};
445
+DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_prs_valid);
478446
479447 static int mvpp2_dbgfs_flow_port_init(struct dentry *parent,
480448 struct mvpp2_port *port,
....@@ -484,13 +452,8 @@
484452 struct dentry *port_dir;
485453
486454 port_dir = debugfs_create_dir(port->dev->name, parent);
487
- if (IS_ERR(port_dir))
488
- return PTR_ERR(port_dir);
489455
490
- /* This will be freed by 'hash_opts' release op */
491
- port_entry = kmalloc(sizeof(*port_entry), GFP_KERNEL);
492
- if (!port_entry)
493
- return -ENOMEM;
456
+ port_entry = &port->priv->dbgfs_entries->port_flow_entries[port->id];
494457
495458 port_entry->port = port;
496459 port_entry->dbg_fe = entry;
....@@ -515,19 +478,11 @@
515478 sprintf(flow_entry_name, "%02d", flow);
516479
517480 flow_entry_dir = debugfs_create_dir(flow_entry_name, parent);
518
- if (!flow_entry_dir)
519
- return -ENOMEM;
520481
521
- /* This will be freed by 'type' release op */
522
- entry = kmalloc(sizeof(*entry), GFP_KERNEL);
523
- if (!entry)
524
- return -ENOMEM;
482
+ entry = &priv->dbgfs_entries->flow_entries[flow];
525483
526484 entry->flow = flow;
527485 entry->priv = priv;
528
-
529
- debugfs_create_file("flow_hits", 0444, flow_entry_dir, entry,
530
- &mvpp2_dbgfs_flow_flt_hits_fops);
531486
532487 debugfs_create_file("dec_hits", 0444, flow_entry_dir, entry,
533488 &mvpp2_dbgfs_flow_dec_hits_fops);
....@@ -545,6 +500,7 @@
545500 if (ret)
546501 return ret;
547502 }
503
+
548504 return 0;
549505 }
550506
....@@ -554,10 +510,8 @@
554510 int i, ret;
555511
556512 flow_dir = debugfs_create_dir("flows", parent);
557
- if (!flow_dir)
558
- return -ENOMEM;
559513
560
- for (i = 0; i < MVPP2_N_FLOWS; i++) {
514
+ for (i = 0; i < MVPP2_N_PRS_FLOWS; i++) {
561515 ret = mvpp2_dbgfs_flow_entry_init(flow_dir, priv, i);
562516 if (ret)
563517 return ret;
....@@ -579,13 +533,8 @@
579533 sprintf(prs_entry_name, "%03d", tid);
580534
581535 prs_entry_dir = debugfs_create_dir(prs_entry_name, parent);
582
- if (!prs_entry_dir)
583
- return -ENOMEM;
584536
585
- /* The 'valid' entry's ops will free that */
586
- entry = kmalloc(sizeof(*entry), GFP_KERNEL);
587
- if (!entry)
588
- return -ENOMEM;
537
+ entry = &priv->dbgfs_entries->prs_entries[tid];
589538
590539 entry->tid = tid;
591540 entry->priv = priv;
....@@ -609,6 +558,9 @@
609558 debugfs_create_file("hits", 0444, prs_entry_dir, entry,
610559 &mvpp2_dbgfs_prs_hits_fops);
611560
561
+ debugfs_create_file("pmap", 0444, prs_entry_dir, entry,
562
+ &mvpp2_dbgfs_prs_pmap_fops);
563
+
612564 return 0;
613565 }
614566
....@@ -618,11 +570,101 @@
618570 int i, ret;
619571
620572 prs_dir = debugfs_create_dir("parser", parent);
621
- if (!prs_dir)
622
- return -ENOMEM;
623573
624574 for (i = 0; i < MVPP2_PRS_TCAM_SRAM_SIZE; i++) {
625575 ret = mvpp2_dbgfs_prs_entry_init(prs_dir, priv, i);
576
+ if (ret)
577
+ return ret;
578
+ }
579
+
580
+ return 0;
581
+}
582
+
583
+static int mvpp2_dbgfs_c2_entry_init(struct dentry *parent,
584
+ struct mvpp2 *priv, int id)
585
+{
586
+ struct mvpp2_dbgfs_c2_entry *entry;
587
+ struct dentry *c2_entry_dir;
588
+ char c2_entry_name[10];
589
+
590
+ if (id >= MVPP22_CLS_C2_N_ENTRIES)
591
+ return -EINVAL;
592
+
593
+ sprintf(c2_entry_name, "%03d", id);
594
+
595
+ c2_entry_dir = debugfs_create_dir(c2_entry_name, parent);
596
+ if (!c2_entry_dir)
597
+ return -ENOMEM;
598
+
599
+ entry = &priv->dbgfs_entries->c2_entries[id];
600
+
601
+ entry->id = id;
602
+ entry->priv = priv;
603
+
604
+ debugfs_create_file("hits", 0444, c2_entry_dir, entry,
605
+ &mvpp2_dbgfs_flow_c2_hits_fops);
606
+
607
+ debugfs_create_file("default_rxq", 0444, c2_entry_dir, entry,
608
+ &mvpp2_dbgfs_flow_c2_rxq_fops);
609
+
610
+ debugfs_create_file("rss_enable", 0444, c2_entry_dir, entry,
611
+ &mvpp2_dbgfs_flow_c2_enable_fops);
612
+
613
+ return 0;
614
+}
615
+
616
+static int mvpp2_dbgfs_flow_tbl_entry_init(struct dentry *parent,
617
+ struct mvpp2 *priv, int id)
618
+{
619
+ struct mvpp2_dbgfs_flow_tbl_entry *entry;
620
+ struct dentry *flow_tbl_entry_dir;
621
+ char flow_tbl_entry_name[10];
622
+
623
+ if (id >= MVPP2_CLS_FLOWS_TBL_SIZE)
624
+ return -EINVAL;
625
+
626
+ sprintf(flow_tbl_entry_name, "%03d", id);
627
+
628
+ flow_tbl_entry_dir = debugfs_create_dir(flow_tbl_entry_name, parent);
629
+ if (!flow_tbl_entry_dir)
630
+ return -ENOMEM;
631
+
632
+ entry = &priv->dbgfs_entries->flt_entries[id];
633
+
634
+ entry->id = id;
635
+ entry->priv = priv;
636
+
637
+ debugfs_create_file("hits", 0444, flow_tbl_entry_dir, entry,
638
+ &mvpp2_dbgfs_flow_flt_hits_fops);
639
+
640
+ return 0;
641
+}
642
+
643
+static int mvpp2_dbgfs_cls_init(struct dentry *parent, struct mvpp2 *priv)
644
+{
645
+ struct dentry *cls_dir, *c2_dir, *flow_tbl_dir;
646
+ int i, ret;
647
+
648
+ cls_dir = debugfs_create_dir("classifier", parent);
649
+ if (!cls_dir)
650
+ return -ENOMEM;
651
+
652
+ c2_dir = debugfs_create_dir("c2", cls_dir);
653
+ if (!c2_dir)
654
+ return -ENOMEM;
655
+
656
+ for (i = 0; i < MVPP22_CLS_C2_N_ENTRIES; i++) {
657
+ ret = mvpp2_dbgfs_c2_entry_init(c2_dir, priv, i);
658
+ if (ret)
659
+ return ret;
660
+ }
661
+
662
+ flow_tbl_dir = debugfs_create_dir("flow_table", cls_dir);
663
+ if (!flow_tbl_dir)
664
+ return -ENOMEM;
665
+
666
+ for (i = 0; i < MVPP2_CLS_FLOWS_TBL_SIZE; i++) {
667
+ ret = mvpp2_dbgfs_flow_tbl_entry_init(flow_tbl_dir, priv, i);
626668 if (ret)
627669 return ret;
628670 }
....@@ -636,8 +678,6 @@
636678 struct dentry *port_dir;
637679
638680 port_dir = debugfs_create_dir(port->dev->name, parent);
639
- if (IS_ERR(port_dir))
640
- return PTR_ERR(port_dir);
641681
642682 debugfs_create_file("parser_entries", 0444, port_dir, port,
643683 &mvpp2_dbgfs_port_parser_fops);
....@@ -648,45 +688,46 @@
648688 debugfs_create_file("vid_filter", 0444, port_dir, port,
649689 &mvpp2_dbgfs_port_vid_fops);
650690
651
- debugfs_create_file("c2_hits", 0444, port_dir, port,
652
- &mvpp2_dbgfs_flow_c2_hits_fops);
653
-
654
- debugfs_create_file("default_rxq", 0444, port_dir, port,
655
- &mvpp2_dbgfs_flow_c2_rxq_fops);
656
-
657
- debugfs_create_file("rss_enable", 0444, port_dir, port,
658
- &mvpp2_dbgfs_flow_c2_enable_fops);
659
-
660691 return 0;
692
+}
693
+
694
+static struct dentry *mvpp2_root;
695
+
696
+void mvpp2_dbgfs_exit(void)
697
+{
698
+ debugfs_remove(mvpp2_root);
661699 }
662700
663701 void mvpp2_dbgfs_cleanup(struct mvpp2 *priv)
664702 {
665703 debugfs_remove_recursive(priv->dbgfs_dir);
704
+
705
+ kfree(priv->dbgfs_entries);
666706 }
667707
668708 void mvpp2_dbgfs_init(struct mvpp2 *priv, const char *name)
669709 {
670
- struct dentry *mvpp2_dir, *mvpp2_root;
710
+ struct dentry *mvpp2_dir;
671711 int ret, i;
672712
673
- mvpp2_root = debugfs_lookup(MVPP2_DRIVER_NAME, NULL);
674
- if (!mvpp2_root) {
713
+ if (!mvpp2_root)
675714 mvpp2_root = debugfs_create_dir(MVPP2_DRIVER_NAME, NULL);
676
- if (IS_ERR(mvpp2_root))
677
- return;
678
- }
679715
680716 mvpp2_dir = debugfs_create_dir(name, mvpp2_root);
681
- if (IS_ERR(mvpp2_dir))
682
- return;
683717
684718 priv->dbgfs_dir = mvpp2_dir;
719
+ priv->dbgfs_entries = kzalloc(sizeof(*priv->dbgfs_entries), GFP_KERNEL);
720
+ if (!priv->dbgfs_entries)
721
+ goto err;
685722
686723 ret = mvpp2_dbgfs_prs_init(mvpp2_dir, priv);
687724 if (ret)
688725 goto err;
689726
727
+ ret = mvpp2_dbgfs_cls_init(mvpp2_dir, priv);
728
+ if (ret)
729
+ goto err;
730
+
690731 for (i = 0; i < priv->port_count; i++) {
691732 ret = mvpp2_dbgfs_port_init(mvpp2_dir, priv->port_list[i]);
692733 if (ret)