1 // 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 #include "mvpp2_cls.h"
15 
16 struct mvpp2_dbgfs_prs_entry {
17 	int tid;
18 	struct mvpp2 *priv;
19 };
20 
21 struct mvpp2_dbgfs_flow_entry {
22 	int flow;
23 	struct mvpp2 *priv;
24 };
25 
26 struct mvpp2_dbgfs_port_flow_entry {
27 	struct mvpp2_port *port;
28 	struct mvpp2_dbgfs_flow_entry *dbg_fe;
29 };
30 
31 static int mvpp2_dbgfs_flow_flt_hits_show(struct seq_file *s, void *unused)
32 {
33 	struct mvpp2_dbgfs_flow_entry *entry = s->private;
34 	int id = MVPP2_FLOW_C2_ENTRY(entry->flow);
35 
36 	u32 hits = mvpp2_cls_flow_hits(entry->priv, id);
37 
38 	seq_printf(s, "%u\n", hits);
39 
40 	return 0;
41 }
42 
43 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_flow_flt_hits);
44 
45 static int mvpp2_dbgfs_flow_dec_hits_show(struct seq_file *s, void *unused)
46 {
47 	struct mvpp2_dbgfs_flow_entry *entry = s->private;
48 
49 	u32 hits = mvpp2_cls_lookup_hits(entry->priv, entry->flow);
50 
51 	seq_printf(s, "%u\n", hits);
52 
53 	return 0;
54 }
55 
56 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_flow_dec_hits);
57 
58 static int mvpp2_dbgfs_flow_type_show(struct seq_file *s, void *unused)
59 {
60 	struct mvpp2_dbgfs_flow_entry *entry = s->private;
61 	struct mvpp2_cls_flow *f;
62 	const char *flow_name;
63 
64 	f = mvpp2_cls_flow_get(entry->flow);
65 	if (!f)
66 		return -EINVAL;
67 
68 	switch (f->flow_type) {
69 	case IPV4_FLOW:
70 		flow_name = "ipv4";
71 		break;
72 	case IPV6_FLOW:
73 		flow_name = "ipv6";
74 		break;
75 	case TCP_V4_FLOW:
76 		flow_name = "tcp4";
77 		break;
78 	case TCP_V6_FLOW:
79 		flow_name = "tcp6";
80 		break;
81 	case UDP_V4_FLOW:
82 		flow_name = "udp4";
83 		break;
84 	case UDP_V6_FLOW:
85 		flow_name = "udp6";
86 		break;
87 	default:
88 		flow_name = "other";
89 	}
90 
91 	seq_printf(s, "%s\n", flow_name);
92 
93 	return 0;
94 }
95 
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 };
115 
116 static int mvpp2_dbgfs_flow_id_show(struct seq_file *s, void *unused)
117 {
118 	struct mvpp2_dbgfs_flow_entry *entry = s->private;
119 	struct mvpp2_cls_flow *f;
120 
121 	f = mvpp2_cls_flow_get(entry->flow);
122 	if (!f)
123 		return -EINVAL;
124 
125 	seq_printf(s, "%d\n", f->flow_id);
126 
127 	return 0;
128 }
129 
130 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_flow_id);
131 
132 static int mvpp2_dbgfs_port_flow_hash_opt_show(struct seq_file *s, void *unused)
133 {
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;
138 	int flow_index;
139 	u16 hash_opts;
140 
141 	f = mvpp2_cls_flow_get(entry->dbg_fe->flow);
142 	if (!f)
143 		return -EINVAL;
144 
145 	flow_index = MVPP2_PORT_FLOW_HASH_ENTRY(entry->port->id, f->flow_id);
146 
147 	mvpp2_cls_flow_read(port->priv, flow_index, &fe);
148 
149 	hash_opts = mvpp2_flow_get_hek_fields(&fe);
150 
151 	seq_printf(s, "0x%04x\n", hash_opts);
152 
153 	return 0;
154 }
155 
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 };
178 
179 static int mvpp2_dbgfs_port_flow_engine_show(struct seq_file *s, void *unused)
180 {
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;
186 
187 	f = mvpp2_cls_flow_get(entry->dbg_fe->flow);
188 	if (!f)
189 		return -EINVAL;
190 
191 	flow_index = MVPP2_PORT_FLOW_HASH_ENTRY(entry->port->id, f->flow_id);
192 
193 	mvpp2_cls_flow_read(port->priv, flow_index, &fe);
194 
195 	engine = mvpp2_cls_flow_eng_get(&fe);
196 
197 	seq_printf(s, "%d\n", engine);
198 
199 	return 0;
200 }
201 
202 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_port_flow_engine);
203 
204 static int mvpp2_dbgfs_flow_c2_hits_show(struct seq_file *s, void *unused)
205 {
206 	struct mvpp2_port *port = s->private;
207 	u32 hits;
208 
209 	hits = mvpp2_cls_c2_hit_count(port->priv,
210 				      MVPP22_CLS_C2_RSS_ENTRY(port->id));
211 
212 	seq_printf(s, "%u\n", hits);
213 
214 	return 0;
215 }
216 
217 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_flow_c2_hits);
218 
219 static int mvpp2_dbgfs_flow_c2_rxq_show(struct seq_file *s, void *unused)
220 {
221 	struct mvpp2_port *port = s->private;
222 	struct mvpp2_cls_c2_entry c2;
223 	u8 qh, ql;
224 
225 	mvpp2_cls_c2_read(port->priv, MVPP22_CLS_C2_RSS_ENTRY(port->id), &c2);
226 
227 	qh = (c2.attr[0] >> MVPP22_CLS_C2_ATTR0_QHIGH_OFFS) &
228 	     MVPP22_CLS_C2_ATTR0_QHIGH_MASK;
229 
230 	ql = (c2.attr[0] >> MVPP22_CLS_C2_ATTR0_QLOW_OFFS) &
231 	     MVPP22_CLS_C2_ATTR0_QLOW_MASK;
232 
233 	seq_printf(s, "%d\n", (qh << 3 | ql));
234 
235 	return 0;
236 }
237 
238 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_flow_c2_rxq);
239 
240 static int mvpp2_dbgfs_flow_c2_enable_show(struct seq_file *s, void *unused)
241 {
242 	struct mvpp2_port *port = s->private;
243 	struct mvpp2_cls_c2_entry c2;
244 	int enabled;
245 
246 	mvpp2_cls_c2_read(port->priv, MVPP22_CLS_C2_RSS_ENTRY(port->id), &c2);
247 
248 	enabled = !!(c2.attr[2] & MVPP22_CLS_C2_ATTR2_RSS_EN);
249 
250 	seq_printf(s, "%d\n", enabled);
251 
252 	return 0;
253 }
254 
255 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_flow_c2_enable);
256 
257 static int mvpp2_dbgfs_port_vid_show(struct seq_file *s, void *unused)
258 {
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;
263 	unsigned long pmap;
264 	u16 rvid;
265 	int tid;
266 
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);
270 
271 		pmap = mvpp2_prs_tcam_port_map_get(&pe);
272 
273 		if (!priv->prs_shadow[tid].valid)
274 			continue;
275 
276 		if (!test_bit(port->id, &pmap))
277 			continue;
278 
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]);
281 
282 		rvid = ((byte[0] & 0xf) << 8) + byte[1];
283 
284 		seq_printf(s, "%u\n", rvid);
285 	}
286 
287 	return 0;
288 }
289 
290 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_port_vid);
291 
292 static int mvpp2_dbgfs_port_parser_show(struct seq_file *s, void *unused)
293 {
294 	struct mvpp2_port *port = s->private;
295 	struct mvpp2 *priv = port->priv;
296 	struct mvpp2_prs_entry pe;
297 	unsigned long pmap;
298 	int i;
299 
300 	for (i = 0; i < MVPP2_PRS_TCAM_SRAM_SIZE; i++) {
301 		mvpp2_prs_init_from_hw(port->priv, &pe, i);
302 
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);
306 	}
307 
308 	return 0;
309 }
310 
311 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_port_parser);
312 
313 static int mvpp2_dbgfs_filter_show(struct seq_file *s, void *unused)
314 {
315 	struct mvpp2_port *port = s->private;
316 	struct mvpp2 *priv = port->priv;
317 	struct mvpp2_prs_entry pe;
318 	unsigned long pmap;
319 	int index, tid;
320 
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];
324 
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)
328 			continue;
329 
330 		mvpp2_prs_init_from_hw(priv, &pe, tid);
331 
332 		pmap = mvpp2_prs_tcam_port_map_get(&pe);
333 
334 		/* We only want entries active on this port */
335 		if (!test_bit(port->id, &pmap))
336 			continue;
337 
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],
341 						     &da_mask[index]);
342 
343 		seq_printf(s, "%pM\n", da);
344 	}
345 
346 	return 0;
347 }
348 
349 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_filter);
350 
351 static int mvpp2_dbgfs_prs_lu_show(struct seq_file *s, void *unused)
352 {
353 	struct mvpp2_dbgfs_prs_entry *entry = s->private;
354 	struct mvpp2 *priv = entry->priv;
355 
356 	seq_printf(s, "%x\n", priv->prs_shadow[entry->tid].lu);
357 
358 	return 0;
359 }
360 
361 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_prs_lu);
362 
363 static int mvpp2_dbgfs_prs_pmap_show(struct seq_file *s, void *unused)
364 {
365 	struct mvpp2_dbgfs_prs_entry *entry = s->private;
366 	struct mvpp2_prs_entry pe;
367 	unsigned int pmap;
368 
369 	mvpp2_prs_init_from_hw(entry->priv, &pe, entry->tid);
370 
371 	pmap = mvpp2_prs_tcam_port_map_get(&pe);
372 	pmap &= MVPP2_PRS_PORT_MASK;
373 
374 	seq_printf(s, "%02x\n", pmap);
375 
376 	return 0;
377 }
378 
379 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_prs_pmap);
380 
381 static int mvpp2_dbgfs_prs_ai_show(struct seq_file *s, void *unused)
382 {
383 	struct mvpp2_dbgfs_prs_entry *entry = s->private;
384 	struct mvpp2_prs_entry pe;
385 	unsigned char ai, ai_mask;
386 
387 	mvpp2_prs_init_from_hw(entry->priv, &pe, entry->tid);
388 
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;
391 
392 	seq_printf(s, "%02x %02x\n", ai, ai_mask);
393 
394 	return 0;
395 }
396 
397 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_prs_ai);
398 
399 static int mvpp2_dbgfs_prs_hdata_show(struct seq_file *s, void *unused)
400 {
401 	struct mvpp2_dbgfs_prs_entry *entry = s->private;
402 	struct mvpp2_prs_entry pe;
403 	unsigned char data[8], mask[8];
404 	int i;
405 
406 	mvpp2_prs_init_from_hw(entry->priv, &pe, entry->tid);
407 
408 	for (i = 0; i < 8; i++)
409 		mvpp2_prs_tcam_data_byte_get(&pe, i, &data[i], &mask[i]);
410 
411 	seq_printf(s, "%*phN %*phN\n", 8, data, 8, mask);
412 
413 	return 0;
414 }
415 
416 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_prs_hdata);
417 
418 static int mvpp2_dbgfs_prs_sram_show(struct seq_file *s, void *unused)
419 {
420 	struct mvpp2_dbgfs_prs_entry *entry = s->private;
421 	struct mvpp2_prs_entry pe;
422 
423 	mvpp2_prs_init_from_hw(entry->priv, &pe, entry->tid);
424 
425 	seq_printf(s, "%*phN\n", 14, pe.sram);
426 
427 	return 0;
428 }
429 
430 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_prs_sram);
431 
432 static int mvpp2_dbgfs_prs_hits_show(struct seq_file *s, void *unused)
433 {
434 	struct mvpp2_dbgfs_prs_entry *entry = s->private;
435 	int val;
436 
437 	val = mvpp2_prs_hits(entry->priv, entry->tid);
438 	if (val < 0)
439 		return val;
440 
441 	seq_printf(s, "%d\n", val);
442 
443 	return 0;
444 }
445 
446 DEFINE_SHOW_ATTRIBUTE(mvpp2_dbgfs_prs_hits);
447 
448 static int mvpp2_dbgfs_prs_valid_show(struct seq_file *s, void *unused)
449 {
450 	struct mvpp2_dbgfs_prs_entry *entry = s->private;
451 	struct mvpp2 *priv = entry->priv;
452 	int tid = entry->tid;
453 
454 	seq_printf(s, "%d\n", priv->prs_shadow[tid].valid ? 1 : 0);
455 
456 	return 0;
457 }
458 
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 };
478 
479 static int mvpp2_dbgfs_flow_port_init(struct dentry *parent,
480 				      struct mvpp2_port *port,
481 				      struct mvpp2_dbgfs_flow_entry *entry)
482 {
483 	struct mvpp2_dbgfs_port_flow_entry *port_entry;
484 	struct dentry *port_dir;
485 
486 	port_dir = debugfs_create_dir(port->dev->name, parent);
487 	if (IS_ERR(port_dir))
488 		return PTR_ERR(port_dir);
489 
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;
494 
495 	port_entry->port = port;
496 	port_entry->dbg_fe = entry;
497 
498 	debugfs_create_file("hash_opts", 0444, port_dir, port_entry,
499 			    &mvpp2_dbgfs_port_flow_hash_opt_fops);
500 
501 	debugfs_create_file("engine", 0444, port_dir, port_entry,
502 			    &mvpp2_dbgfs_port_flow_engine_fops);
503 
504 	return 0;
505 }
506 
507 static int mvpp2_dbgfs_flow_entry_init(struct dentry *parent,
508 				       struct mvpp2 *priv, int flow)
509 {
510 	struct mvpp2_dbgfs_flow_entry *entry;
511 	struct dentry *flow_entry_dir;
512 	char flow_entry_name[10];
513 	int i, ret;
514 
515 	sprintf(flow_entry_name, "%02d", flow);
516 
517 	flow_entry_dir = debugfs_create_dir(flow_entry_name, parent);
518 	if (!flow_entry_dir)
519 		return -ENOMEM;
520 
521 	/* This will be freed by 'type' release op */
522 	entry = kmalloc(sizeof(*entry), GFP_KERNEL);
523 	if (!entry)
524 		return -ENOMEM;
525 
526 	entry->flow = flow;
527 	entry->priv = priv;
528 
529 	debugfs_create_file("flow_hits", 0444, flow_entry_dir, entry,
530 			    &mvpp2_dbgfs_flow_flt_hits_fops);
531 
532 	debugfs_create_file("dec_hits", 0444, flow_entry_dir, entry,
533 			    &mvpp2_dbgfs_flow_dec_hits_fops);
534 
535 	debugfs_create_file("type", 0444, flow_entry_dir, entry,
536 			    &mvpp2_dbgfs_flow_type_fops);
537 
538 	debugfs_create_file("id", 0444, flow_entry_dir, entry,
539 			    &mvpp2_dbgfs_flow_id_fops);
540 
541 	/* Create entry for each port */
542 	for (i = 0; i < priv->port_count; i++) {
543 		ret = mvpp2_dbgfs_flow_port_init(flow_entry_dir,
544 						 priv->port_list[i], entry);
545 		if (ret)
546 			return ret;
547 	}
548 	return 0;
549 }
550 
551 static int mvpp2_dbgfs_flow_init(struct dentry *parent, struct mvpp2 *priv)
552 {
553 	struct dentry *flow_dir;
554 	int i, ret;
555 
556 	flow_dir = debugfs_create_dir("flows", parent);
557 	if (!flow_dir)
558 		return -ENOMEM;
559 
560 	for (i = 0; i < MVPP2_N_FLOWS; i++) {
561 		ret = mvpp2_dbgfs_flow_entry_init(flow_dir, priv, i);
562 		if (ret)
563 			return ret;
564 	}
565 
566 	return 0;
567 }
568 
569 static int mvpp2_dbgfs_prs_entry_init(struct dentry *parent,
570 				      struct mvpp2 *priv, int tid)
571 {
572 	struct mvpp2_dbgfs_prs_entry *entry;
573 	struct dentry *prs_entry_dir;
574 	char prs_entry_name[10];
575 
576 	if (tid >= MVPP2_PRS_TCAM_SRAM_SIZE)
577 		return -EINVAL;
578 
579 	sprintf(prs_entry_name, "%03d", tid);
580 
581 	prs_entry_dir = debugfs_create_dir(prs_entry_name, parent);
582 	if (!prs_entry_dir)
583 		return -ENOMEM;
584 
585 	/* The 'valid' entry's ops will free that */
586 	entry = kmalloc(sizeof(*entry), GFP_KERNEL);
587 	if (!entry)
588 		return -ENOMEM;
589 
590 	entry->tid = tid;
591 	entry->priv = priv;
592 
593 	/* Create each attr */
594 	debugfs_create_file("sram", 0444, prs_entry_dir, entry,
595 			    &mvpp2_dbgfs_prs_sram_fops);
596 
597 	debugfs_create_file("valid", 0644, prs_entry_dir, entry,
598 			    &mvpp2_dbgfs_prs_valid_fops);
599 
600 	debugfs_create_file("lookup_id", 0644, prs_entry_dir, entry,
601 			    &mvpp2_dbgfs_prs_lu_fops);
602 
603 	debugfs_create_file("ai", 0644, prs_entry_dir, entry,
604 			    &mvpp2_dbgfs_prs_ai_fops);
605 
606 	debugfs_create_file("header_data", 0644, prs_entry_dir, entry,
607 			    &mvpp2_dbgfs_prs_hdata_fops);
608 
609 	debugfs_create_file("hits", 0444, prs_entry_dir, entry,
610 			    &mvpp2_dbgfs_prs_hits_fops);
611 
612 	return 0;
613 }
614 
615 static int mvpp2_dbgfs_prs_init(struct dentry *parent, struct mvpp2 *priv)
616 {
617 	struct dentry *prs_dir;
618 	int i, ret;
619 
620 	prs_dir = debugfs_create_dir("parser", parent);
621 	if (!prs_dir)
622 		return -ENOMEM;
623 
624 	for (i = 0; i < MVPP2_PRS_TCAM_SRAM_SIZE; i++) {
625 		ret = mvpp2_dbgfs_prs_entry_init(prs_dir, priv, i);
626 		if (ret)
627 			return ret;
628 	}
629 
630 	return 0;
631 }
632 
633 static int mvpp2_dbgfs_port_init(struct dentry *parent,
634 				 struct mvpp2_port *port)
635 {
636 	struct dentry *port_dir;
637 
638 	port_dir = debugfs_create_dir(port->dev->name, parent);
639 	if (IS_ERR(port_dir))
640 		return PTR_ERR(port_dir);
641 
642 	debugfs_create_file("parser_entries", 0444, port_dir, port,
643 			    &mvpp2_dbgfs_port_parser_fops);
644 
645 	debugfs_create_file("mac_filter", 0444, port_dir, port,
646 			    &mvpp2_dbgfs_filter_fops);
647 
648 	debugfs_create_file("vid_filter", 0444, port_dir, port,
649 			    &mvpp2_dbgfs_port_vid_fops);
650 
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 
660 	return 0;
661 }
662 
663 void mvpp2_dbgfs_cleanup(struct mvpp2 *priv)
664 {
665 	debugfs_remove_recursive(priv->dbgfs_dir);
666 }
667 
668 void mvpp2_dbgfs_init(struct mvpp2 *priv, const char *name)
669 {
670 	struct dentry *mvpp2_dir, *mvpp2_root;
671 	int ret, i;
672 
673 	mvpp2_root = debugfs_lookup(MVPP2_DRIVER_NAME, NULL);
674 	if (!mvpp2_root) {
675 		mvpp2_root = debugfs_create_dir(MVPP2_DRIVER_NAME, NULL);
676 		if (IS_ERR(mvpp2_root))
677 			return;
678 	}
679 
680 	mvpp2_dir = debugfs_create_dir(name, mvpp2_root);
681 	if (IS_ERR(mvpp2_dir))
682 		return;
683 
684 	priv->dbgfs_dir = mvpp2_dir;
685 
686 	ret = mvpp2_dbgfs_prs_init(mvpp2_dir, priv);
687 	if (ret)
688 		goto err;
689 
690 	for (i = 0; i < priv->port_count; i++) {
691 		ret = mvpp2_dbgfs_port_init(mvpp2_dir, priv->port_list[i]);
692 		if (ret)
693 			goto err;
694 	}
695 
696 	ret = mvpp2_dbgfs_flow_init(mvpp2_dir, priv);
697 	if (ret)
698 		goto err;
699 
700 	return;
701 err:
702 	mvpp2_dbgfs_cleanup(priv);
703 }
704