xref: /linux/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c (revision 3fd6c59042dbba50391e30862beac979491145fe)
1 // SPDX-License-Identifier: GPL-2.0
2 /* Marvell RVU Admin Function driver
3  *
4  * Copyright (C) 2019 Marvell.
5  *
6  */
7 
8 #ifdef CONFIG_DEBUG_FS
9 
10 #include <linux/fs.h>
11 #include <linux/debugfs.h>
12 #include <linux/module.h>
13 #include <linux/pci.h>
14 
15 #include "rvu_struct.h"
16 #include "rvu_reg.h"
17 #include "rvu.h"
18 #include "cgx.h"
19 #include "lmac_common.h"
20 #include "npc.h"
21 #include "rvu_npc_hash.h"
22 #include "mcs.h"
23 
24 #define DEBUGFS_DIR_NAME "octeontx2"
25 
26 enum {
27 	CGX_STAT0,
28 	CGX_STAT1,
29 	CGX_STAT2,
30 	CGX_STAT3,
31 	CGX_STAT4,
32 	CGX_STAT5,
33 	CGX_STAT6,
34 	CGX_STAT7,
35 	CGX_STAT8,
36 	CGX_STAT9,
37 	CGX_STAT10,
38 	CGX_STAT11,
39 	CGX_STAT12,
40 	CGX_STAT13,
41 	CGX_STAT14,
42 	CGX_STAT15,
43 	CGX_STAT16,
44 	CGX_STAT17,
45 	CGX_STAT18,
46 };
47 
48 static char *cgx_rx_stats_fields[] = {
49 	[CGX_STAT0]	= "Received packets",
50 	[CGX_STAT1]	= "Octets of received packets",
51 	[CGX_STAT2]	= "Received PAUSE packets",
52 	[CGX_STAT3]	= "Received PAUSE and control packets",
53 	[CGX_STAT4]	= "Filtered DMAC0 (NIX-bound) packets",
54 	[CGX_STAT5]	= "Filtered DMAC0 (NIX-bound) octets",
55 	[CGX_STAT6]	= "Packets dropped due to RX FIFO full",
56 	[CGX_STAT7]	= "Octets dropped due to RX FIFO full",
57 	[CGX_STAT8]	= "Error packets",
58 	[CGX_STAT9]	= "Filtered DMAC1 (NCSI-bound) packets",
59 	[CGX_STAT10]	= "Filtered DMAC1 (NCSI-bound) octets",
60 	[CGX_STAT11]	= "NCSI-bound packets dropped",
61 	[CGX_STAT12]	= "NCSI-bound octets dropped",
62 };
63 
64 static char *cgx_tx_stats_fields[] = {
65 	[CGX_STAT0]	= "Packets dropped due to excessive collisions",
66 	[CGX_STAT1]	= "Packets dropped due to excessive deferral",
67 	[CGX_STAT2]	= "Multiple collisions before successful transmission",
68 	[CGX_STAT3]	= "Single collisions before successful transmission",
69 	[CGX_STAT4]	= "Total octets sent on the interface",
70 	[CGX_STAT5]	= "Total frames sent on the interface",
71 	[CGX_STAT6]	= "Packets sent with an octet count < 64",
72 	[CGX_STAT7]	= "Packets sent with an octet count == 64",
73 	[CGX_STAT8]	= "Packets sent with an octet count of 65-127",
74 	[CGX_STAT9]	= "Packets sent with an octet count of 128-255",
75 	[CGX_STAT10]	= "Packets sent with an octet count of 256-511",
76 	[CGX_STAT11]	= "Packets sent with an octet count of 512-1023",
77 	[CGX_STAT12]	= "Packets sent with an octet count of 1024-1518",
78 	[CGX_STAT13]	= "Packets sent with an octet count of > 1518",
79 	[CGX_STAT14]	= "Packets sent to a broadcast DMAC",
80 	[CGX_STAT15]	= "Packets sent to the multicast DMAC",
81 	[CGX_STAT16]	= "Transmit underflow and were truncated",
82 	[CGX_STAT17]	= "Control/PAUSE packets sent",
83 };
84 
85 static char *rpm_rx_stats_fields[] = {
86 	"Octets of received packets",
87 	"Octets of received packets with out error",
88 	"Received packets with alignment errors",
89 	"Control/PAUSE packets received",
90 	"Packets received with Frame too long Errors",
91 	"Packets received with a1nrange length Errors",
92 	"Received packets",
93 	"Packets received with FrameCheckSequenceErrors",
94 	"Packets received with VLAN header",
95 	"Error packets",
96 	"Packets received with unicast DMAC",
97 	"Packets received with multicast DMAC",
98 	"Packets received with broadcast DMAC",
99 	"Dropped packets",
100 	"Total frames received on interface",
101 	"Packets received with an octet count < 64",
102 	"Packets received with an octet count == 64",
103 	"Packets received with an octet count of 65-127",
104 	"Packets received with an octet count of 128-255",
105 	"Packets received with an octet count of 256-511",
106 	"Packets received with an octet count of 512-1023",
107 	"Packets received with an octet count of 1024-1518",
108 	"Packets received with an octet count of > 1518",
109 	"Oversized Packets",
110 	"Jabber Packets",
111 	"Fragmented Packets",
112 	"CBFC(class based flow control) pause frames received for class 0",
113 	"CBFC pause frames received for class 1",
114 	"CBFC pause frames received for class 2",
115 	"CBFC pause frames received for class 3",
116 	"CBFC pause frames received for class 4",
117 	"CBFC pause frames received for class 5",
118 	"CBFC pause frames received for class 6",
119 	"CBFC pause frames received for class 7",
120 	"CBFC pause frames received for class 8",
121 	"CBFC pause frames received for class 9",
122 	"CBFC pause frames received for class 10",
123 	"CBFC pause frames received for class 11",
124 	"CBFC pause frames received for class 12",
125 	"CBFC pause frames received for class 13",
126 	"CBFC pause frames received for class 14",
127 	"CBFC pause frames received for class 15",
128 	"MAC control packets received",
129 };
130 
131 static char *rpm_tx_stats_fields[] = {
132 	"Total octets sent on the interface",
133 	"Total octets transmitted OK",
134 	"Control/Pause frames sent",
135 	"Total frames transmitted OK",
136 	"Total frames sent with VLAN header",
137 	"Error Packets",
138 	"Packets sent to unicast DMAC",
139 	"Packets sent to the multicast DMAC",
140 	"Packets sent to a broadcast DMAC",
141 	"Packets sent with an octet count == 64",
142 	"Packets sent with an octet count of 65-127",
143 	"Packets sent with an octet count of 128-255",
144 	"Packets sent with an octet count of 256-511",
145 	"Packets sent with an octet count of 512-1023",
146 	"Packets sent with an octet count of 1024-1518",
147 	"Packets sent with an octet count of > 1518",
148 	"CBFC(class based flow control) pause frames transmitted for class 0",
149 	"CBFC pause frames transmitted for class 1",
150 	"CBFC pause frames transmitted for class 2",
151 	"CBFC pause frames transmitted for class 3",
152 	"CBFC pause frames transmitted for class 4",
153 	"CBFC pause frames transmitted for class 5",
154 	"CBFC pause frames transmitted for class 6",
155 	"CBFC pause frames transmitted for class 7",
156 	"CBFC pause frames transmitted for class 8",
157 	"CBFC pause frames transmitted for class 9",
158 	"CBFC pause frames transmitted for class 10",
159 	"CBFC pause frames transmitted for class 11",
160 	"CBFC pause frames transmitted for class 12",
161 	"CBFC pause frames transmitted for class 13",
162 	"CBFC pause frames transmitted for class 14",
163 	"CBFC pause frames transmitted for class 15",
164 	"MAC control packets sent",
165 	"Total frames sent on the interface"
166 };
167 
168 enum cpt_eng_type {
169 	CPT_AE_TYPE = 1,
170 	CPT_SE_TYPE = 2,
171 	CPT_IE_TYPE = 3,
172 };
173 
174 #define rvu_dbg_NULL NULL
175 #define rvu_dbg_open_NULL NULL
176 
177 #define RVU_DEBUG_SEQ_FOPS(name, read_op, write_op)	\
178 static int rvu_dbg_open_##name(struct inode *inode, struct file *file) \
179 { \
180 	return single_open(file, rvu_dbg_##read_op, inode->i_private); \
181 } \
182 static const struct file_operations rvu_dbg_##name##_fops = { \
183 	.owner		= THIS_MODULE, \
184 	.open		= rvu_dbg_open_##name, \
185 	.read		= seq_read, \
186 	.write		= rvu_dbg_##write_op, \
187 	.llseek		= seq_lseek, \
188 	.release	= single_release, \
189 }
190 
191 #define RVU_DEBUG_FOPS(name, read_op, write_op) \
192 static const struct file_operations rvu_dbg_##name##_fops = { \
193 	.owner = THIS_MODULE, \
194 	.open = simple_open, \
195 	.read = rvu_dbg_##read_op, \
196 	.write = rvu_dbg_##write_op \
197 }
198 
199 static void print_nix_qsize(struct seq_file *filp, struct rvu_pfvf *pfvf);
200 
rvu_dbg_mcs_port_stats_display(struct seq_file * filp,void * unused,int dir)201 static int rvu_dbg_mcs_port_stats_display(struct seq_file *filp, void *unused, int dir)
202 {
203 	struct mcs *mcs = filp->private;
204 	struct mcs_port_stats stats;
205 	int lmac;
206 
207 	seq_puts(filp, "\n port stats\n");
208 	mutex_lock(&mcs->stats_lock);
209 	for_each_set_bit(lmac, &mcs->hw->lmac_bmap, mcs->hw->lmac_cnt) {
210 		mcs_get_port_stats(mcs, &stats, lmac, dir);
211 		seq_printf(filp, "port%d: Tcam Miss: %lld\n", lmac, stats.tcam_miss_cnt);
212 		seq_printf(filp, "port%d: Parser errors: %lld\n", lmac, stats.parser_err_cnt);
213 
214 		if (dir == MCS_RX && mcs->hw->mcs_blks > 1)
215 			seq_printf(filp, "port%d: Preempt error: %lld\n", lmac,
216 				   stats.preempt_err_cnt);
217 		if (dir == MCS_TX)
218 			seq_printf(filp, "port%d: Sectag insert error: %lld\n", lmac,
219 				   stats.sectag_insert_err_cnt);
220 	}
221 	mutex_unlock(&mcs->stats_lock);
222 	return 0;
223 }
224 
rvu_dbg_mcs_rx_port_stats_display(struct seq_file * filp,void * unused)225 static int rvu_dbg_mcs_rx_port_stats_display(struct seq_file *filp, void *unused)
226 {
227 	return rvu_dbg_mcs_port_stats_display(filp, unused, MCS_RX);
228 }
229 
230 RVU_DEBUG_SEQ_FOPS(mcs_rx_port_stats, mcs_rx_port_stats_display, NULL);
231 
rvu_dbg_mcs_tx_port_stats_display(struct seq_file * filp,void * unused)232 static int rvu_dbg_mcs_tx_port_stats_display(struct seq_file *filp, void *unused)
233 {
234 	return rvu_dbg_mcs_port_stats_display(filp, unused, MCS_TX);
235 }
236 
237 RVU_DEBUG_SEQ_FOPS(mcs_tx_port_stats, mcs_tx_port_stats_display, NULL);
238 
rvu_dbg_mcs_sa_stats_display(struct seq_file * filp,void * unused,int dir)239 static int rvu_dbg_mcs_sa_stats_display(struct seq_file *filp, void *unused, int dir)
240 {
241 	struct mcs *mcs = filp->private;
242 	struct mcs_sa_stats stats;
243 	struct rsrc_bmap *map;
244 	int sa_id;
245 
246 	if (dir == MCS_TX) {
247 		map = &mcs->tx.sa;
248 		mutex_lock(&mcs->stats_lock);
249 		for_each_set_bit(sa_id, map->bmap, mcs->hw->sa_entries) {
250 			seq_puts(filp, "\n TX SA stats\n");
251 			mcs_get_sa_stats(mcs, &stats, sa_id, MCS_TX);
252 			seq_printf(filp, "sa%d: Pkts encrypted: %lld\n", sa_id,
253 				   stats.pkt_encrypt_cnt);
254 
255 			seq_printf(filp, "sa%d: Pkts protected: %lld\n", sa_id,
256 				   stats.pkt_protected_cnt);
257 		}
258 		mutex_unlock(&mcs->stats_lock);
259 		return 0;
260 	}
261 
262 	/* RX stats */
263 	map = &mcs->rx.sa;
264 	mutex_lock(&mcs->stats_lock);
265 	for_each_set_bit(sa_id, map->bmap, mcs->hw->sa_entries) {
266 		seq_puts(filp, "\n RX SA stats\n");
267 		mcs_get_sa_stats(mcs, &stats, sa_id, MCS_RX);
268 		seq_printf(filp, "sa%d: Invalid pkts: %lld\n", sa_id, stats.pkt_invalid_cnt);
269 		seq_printf(filp, "sa%d: Pkts no sa error: %lld\n", sa_id, stats.pkt_nosaerror_cnt);
270 		seq_printf(filp, "sa%d: Pkts not valid: %lld\n", sa_id, stats.pkt_notvalid_cnt);
271 		seq_printf(filp, "sa%d: Pkts ok: %lld\n", sa_id, stats.pkt_ok_cnt);
272 		seq_printf(filp, "sa%d: Pkts no sa: %lld\n", sa_id, stats.pkt_nosa_cnt);
273 	}
274 	mutex_unlock(&mcs->stats_lock);
275 	return 0;
276 }
277 
rvu_dbg_mcs_rx_sa_stats_display(struct seq_file * filp,void * unused)278 static int rvu_dbg_mcs_rx_sa_stats_display(struct seq_file *filp, void *unused)
279 {
280 	return rvu_dbg_mcs_sa_stats_display(filp, unused, MCS_RX);
281 }
282 
283 RVU_DEBUG_SEQ_FOPS(mcs_rx_sa_stats, mcs_rx_sa_stats_display, NULL);
284 
rvu_dbg_mcs_tx_sa_stats_display(struct seq_file * filp,void * unused)285 static int rvu_dbg_mcs_tx_sa_stats_display(struct seq_file *filp, void *unused)
286 {
287 	return rvu_dbg_mcs_sa_stats_display(filp, unused, MCS_TX);
288 }
289 
290 RVU_DEBUG_SEQ_FOPS(mcs_tx_sa_stats, mcs_tx_sa_stats_display, NULL);
291 
rvu_dbg_mcs_tx_sc_stats_display(struct seq_file * filp,void * unused)292 static int rvu_dbg_mcs_tx_sc_stats_display(struct seq_file *filp, void *unused)
293 {
294 	struct mcs *mcs = filp->private;
295 	struct mcs_sc_stats stats;
296 	struct rsrc_bmap *map;
297 	int sc_id;
298 
299 	map = &mcs->tx.sc;
300 	seq_puts(filp, "\n SC stats\n");
301 
302 	mutex_lock(&mcs->stats_lock);
303 	for_each_set_bit(sc_id, map->bmap, mcs->hw->sc_entries) {
304 		mcs_get_sc_stats(mcs, &stats, sc_id, MCS_TX);
305 		seq_printf(filp, "\n=======sc%d======\n\n", sc_id);
306 		seq_printf(filp, "sc%d: Pkts encrypted: %lld\n", sc_id, stats.pkt_encrypt_cnt);
307 		seq_printf(filp, "sc%d: Pkts protected: %lld\n", sc_id, stats.pkt_protected_cnt);
308 
309 		if (mcs->hw->mcs_blks == 1) {
310 			seq_printf(filp, "sc%d: Octets encrypted: %lld\n", sc_id,
311 				   stats.octet_encrypt_cnt);
312 			seq_printf(filp, "sc%d: Octets protected: %lld\n", sc_id,
313 				   stats.octet_protected_cnt);
314 		}
315 	}
316 	mutex_unlock(&mcs->stats_lock);
317 	return 0;
318 }
319 
320 RVU_DEBUG_SEQ_FOPS(mcs_tx_sc_stats, mcs_tx_sc_stats_display, NULL);
321 
rvu_dbg_mcs_rx_sc_stats_display(struct seq_file * filp,void * unused)322 static int rvu_dbg_mcs_rx_sc_stats_display(struct seq_file *filp, void *unused)
323 {
324 	struct mcs *mcs = filp->private;
325 	struct mcs_sc_stats stats;
326 	struct rsrc_bmap *map;
327 	int sc_id;
328 
329 	map = &mcs->rx.sc;
330 	seq_puts(filp, "\n SC stats\n");
331 
332 	mutex_lock(&mcs->stats_lock);
333 	for_each_set_bit(sc_id, map->bmap, mcs->hw->sc_entries) {
334 		mcs_get_sc_stats(mcs, &stats, sc_id, MCS_RX);
335 		seq_printf(filp, "\n=======sc%d======\n\n", sc_id);
336 		seq_printf(filp, "sc%d: Cam hits: %lld\n", sc_id, stats.hit_cnt);
337 		seq_printf(filp, "sc%d: Invalid pkts: %lld\n", sc_id, stats.pkt_invalid_cnt);
338 		seq_printf(filp, "sc%d: Late pkts: %lld\n", sc_id, stats.pkt_late_cnt);
339 		seq_printf(filp, "sc%d: Notvalid pkts: %lld\n", sc_id, stats.pkt_notvalid_cnt);
340 		seq_printf(filp, "sc%d: Unchecked pkts: %lld\n", sc_id, stats.pkt_unchecked_cnt);
341 
342 		if (mcs->hw->mcs_blks > 1) {
343 			seq_printf(filp, "sc%d: Delay pkts: %lld\n", sc_id, stats.pkt_delay_cnt);
344 			seq_printf(filp, "sc%d: Pkts ok: %lld\n", sc_id, stats.pkt_ok_cnt);
345 		}
346 		if (mcs->hw->mcs_blks == 1) {
347 			seq_printf(filp, "sc%d: Octets decrypted: %lld\n", sc_id,
348 				   stats.octet_decrypt_cnt);
349 			seq_printf(filp, "sc%d: Octets validated: %lld\n", sc_id,
350 				   stats.octet_validate_cnt);
351 		}
352 	}
353 	mutex_unlock(&mcs->stats_lock);
354 	return 0;
355 }
356 
357 RVU_DEBUG_SEQ_FOPS(mcs_rx_sc_stats, mcs_rx_sc_stats_display, NULL);
358 
rvu_dbg_mcs_flowid_stats_display(struct seq_file * filp,void * unused,int dir)359 static int rvu_dbg_mcs_flowid_stats_display(struct seq_file *filp, void *unused, int dir)
360 {
361 	struct mcs *mcs = filp->private;
362 	struct mcs_flowid_stats stats;
363 	struct rsrc_bmap *map;
364 	int flow_id;
365 
366 	seq_puts(filp, "\n Flowid stats\n");
367 
368 	if (dir == MCS_RX)
369 		map = &mcs->rx.flow_ids;
370 	else
371 		map = &mcs->tx.flow_ids;
372 
373 	mutex_lock(&mcs->stats_lock);
374 	for_each_set_bit(flow_id, map->bmap, mcs->hw->tcam_entries) {
375 		mcs_get_flowid_stats(mcs, &stats, flow_id, dir);
376 		seq_printf(filp, "Flowid%d: Hit:%lld\n", flow_id, stats.tcam_hit_cnt);
377 	}
378 	mutex_unlock(&mcs->stats_lock);
379 	return 0;
380 }
381 
rvu_dbg_mcs_tx_flowid_stats_display(struct seq_file * filp,void * unused)382 static int rvu_dbg_mcs_tx_flowid_stats_display(struct seq_file *filp, void *unused)
383 {
384 	return rvu_dbg_mcs_flowid_stats_display(filp, unused, MCS_TX);
385 }
386 
387 RVU_DEBUG_SEQ_FOPS(mcs_tx_flowid_stats, mcs_tx_flowid_stats_display, NULL);
388 
rvu_dbg_mcs_rx_flowid_stats_display(struct seq_file * filp,void * unused)389 static int rvu_dbg_mcs_rx_flowid_stats_display(struct seq_file *filp, void *unused)
390 {
391 	return rvu_dbg_mcs_flowid_stats_display(filp, unused, MCS_RX);
392 }
393 
394 RVU_DEBUG_SEQ_FOPS(mcs_rx_flowid_stats, mcs_rx_flowid_stats_display, NULL);
395 
rvu_dbg_mcs_tx_secy_stats_display(struct seq_file * filp,void * unused)396 static int rvu_dbg_mcs_tx_secy_stats_display(struct seq_file *filp, void *unused)
397 {
398 	struct mcs *mcs = filp->private;
399 	struct mcs_secy_stats stats;
400 	struct rsrc_bmap *map;
401 	int secy_id;
402 
403 	map = &mcs->tx.secy;
404 	seq_puts(filp, "\n MCS TX secy stats\n");
405 
406 	mutex_lock(&mcs->stats_lock);
407 	for_each_set_bit(secy_id, map->bmap, mcs->hw->secy_entries) {
408 		mcs_get_tx_secy_stats(mcs, &stats, secy_id);
409 		seq_printf(filp, "\n=======Secy%d======\n\n", secy_id);
410 		seq_printf(filp, "secy%d: Ctrl bcast pkts: %lld\n", secy_id,
411 			   stats.ctl_pkt_bcast_cnt);
412 		seq_printf(filp, "secy%d: Ctrl Mcast pkts: %lld\n", secy_id,
413 			   stats.ctl_pkt_mcast_cnt);
414 		seq_printf(filp, "secy%d: Ctrl ucast pkts: %lld\n", secy_id,
415 			   stats.ctl_pkt_ucast_cnt);
416 		seq_printf(filp, "secy%d: Ctrl octets: %lld\n", secy_id, stats.ctl_octet_cnt);
417 		seq_printf(filp, "secy%d: Unctrl bcast cnt: %lld\n", secy_id,
418 			   stats.unctl_pkt_bcast_cnt);
419 		seq_printf(filp, "secy%d: Unctrl mcast pkts: %lld\n", secy_id,
420 			   stats.unctl_pkt_mcast_cnt);
421 		seq_printf(filp, "secy%d: Unctrl ucast pkts: %lld\n", secy_id,
422 			   stats.unctl_pkt_ucast_cnt);
423 		seq_printf(filp, "secy%d: Unctrl octets: %lld\n", secy_id, stats.unctl_octet_cnt);
424 		seq_printf(filp, "secy%d: Octet encrypted: %lld\n", secy_id,
425 			   stats.octet_encrypted_cnt);
426 		seq_printf(filp, "secy%d: octet protected: %lld\n", secy_id,
427 			   stats.octet_protected_cnt);
428 		seq_printf(filp, "secy%d: Pkts on active sa: %lld\n", secy_id,
429 			   stats.pkt_noactivesa_cnt);
430 		seq_printf(filp, "secy%d: Pkts too long: %lld\n", secy_id, stats.pkt_toolong_cnt);
431 		seq_printf(filp, "secy%d: Pkts untagged: %lld\n", secy_id, stats.pkt_untagged_cnt);
432 	}
433 	mutex_unlock(&mcs->stats_lock);
434 	return 0;
435 }
436 
437 RVU_DEBUG_SEQ_FOPS(mcs_tx_secy_stats, mcs_tx_secy_stats_display, NULL);
438 
rvu_dbg_mcs_rx_secy_stats_display(struct seq_file * filp,void * unused)439 static int rvu_dbg_mcs_rx_secy_stats_display(struct seq_file *filp, void *unused)
440 {
441 	struct mcs *mcs = filp->private;
442 	struct mcs_secy_stats stats;
443 	struct rsrc_bmap *map;
444 	int secy_id;
445 
446 	map = &mcs->rx.secy;
447 	seq_puts(filp, "\n MCS secy stats\n");
448 
449 	mutex_lock(&mcs->stats_lock);
450 	for_each_set_bit(secy_id, map->bmap, mcs->hw->secy_entries) {
451 		mcs_get_rx_secy_stats(mcs, &stats, secy_id);
452 		seq_printf(filp, "\n=======Secy%d======\n\n", secy_id);
453 		seq_printf(filp, "secy%d: Ctrl bcast pkts: %lld\n", secy_id,
454 			   stats.ctl_pkt_bcast_cnt);
455 		seq_printf(filp, "secy%d: Ctrl Mcast pkts: %lld\n", secy_id,
456 			   stats.ctl_pkt_mcast_cnt);
457 		seq_printf(filp, "secy%d: Ctrl ucast pkts: %lld\n", secy_id,
458 			   stats.ctl_pkt_ucast_cnt);
459 		seq_printf(filp, "secy%d: Ctrl octets: %lld\n", secy_id, stats.ctl_octet_cnt);
460 		seq_printf(filp, "secy%d: Unctrl bcast cnt: %lld\n", secy_id,
461 			   stats.unctl_pkt_bcast_cnt);
462 		seq_printf(filp, "secy%d: Unctrl mcast pkts: %lld\n", secy_id,
463 			   stats.unctl_pkt_mcast_cnt);
464 		seq_printf(filp, "secy%d: Unctrl ucast pkts: %lld\n", secy_id,
465 			   stats.unctl_pkt_ucast_cnt);
466 		seq_printf(filp, "secy%d: Unctrl octets: %lld\n", secy_id, stats.unctl_octet_cnt);
467 		seq_printf(filp, "secy%d: Octet decrypted: %lld\n", secy_id,
468 			   stats.octet_decrypted_cnt);
469 		seq_printf(filp, "secy%d: octet validated: %lld\n", secy_id,
470 			   stats.octet_validated_cnt);
471 		seq_printf(filp, "secy%d: Pkts on disable port: %lld\n", secy_id,
472 			   stats.pkt_port_disabled_cnt);
473 		seq_printf(filp, "secy%d: Pkts with badtag: %lld\n", secy_id, stats.pkt_badtag_cnt);
474 		seq_printf(filp, "secy%d: Pkts with no SA(sectag.tci.c=0): %lld\n", secy_id,
475 			   stats.pkt_nosa_cnt);
476 		seq_printf(filp, "secy%d: Pkts with nosaerror: %lld\n", secy_id,
477 			   stats.pkt_nosaerror_cnt);
478 		seq_printf(filp, "secy%d: Tagged ctrl pkts: %lld\n", secy_id,
479 			   stats.pkt_tagged_ctl_cnt);
480 		seq_printf(filp, "secy%d: Untaged pkts: %lld\n", secy_id, stats.pkt_untaged_cnt);
481 		seq_printf(filp, "secy%d: Ctrl pkts: %lld\n", secy_id, stats.pkt_ctl_cnt);
482 		if (mcs->hw->mcs_blks > 1)
483 			seq_printf(filp, "secy%d: pkts notag: %lld\n", secy_id,
484 				   stats.pkt_notag_cnt);
485 	}
486 	mutex_unlock(&mcs->stats_lock);
487 	return 0;
488 }
489 
490 RVU_DEBUG_SEQ_FOPS(mcs_rx_secy_stats, mcs_rx_secy_stats_display, NULL);
491 
rvu_dbg_mcs_init(struct rvu * rvu)492 static void rvu_dbg_mcs_init(struct rvu *rvu)
493 {
494 	struct mcs *mcs;
495 	char dname[10];
496 	int i;
497 
498 	if (!rvu->mcs_blk_cnt)
499 		return;
500 
501 	rvu->rvu_dbg.mcs_root = debugfs_create_dir("mcs", rvu->rvu_dbg.root);
502 
503 	for (i = 0; i < rvu->mcs_blk_cnt; i++) {
504 		mcs = mcs_get_pdata(i);
505 
506 		sprintf(dname, "mcs%d", i);
507 		rvu->rvu_dbg.mcs = debugfs_create_dir(dname,
508 						      rvu->rvu_dbg.mcs_root);
509 
510 		rvu->rvu_dbg.mcs_rx = debugfs_create_dir("rx_stats", rvu->rvu_dbg.mcs);
511 
512 		debugfs_create_file("flowid", 0600, rvu->rvu_dbg.mcs_rx, mcs,
513 				    &rvu_dbg_mcs_rx_flowid_stats_fops);
514 
515 		debugfs_create_file("secy", 0600, rvu->rvu_dbg.mcs_rx, mcs,
516 				    &rvu_dbg_mcs_rx_secy_stats_fops);
517 
518 		debugfs_create_file("sc", 0600, rvu->rvu_dbg.mcs_rx, mcs,
519 				    &rvu_dbg_mcs_rx_sc_stats_fops);
520 
521 		debugfs_create_file("sa", 0600, rvu->rvu_dbg.mcs_rx, mcs,
522 				    &rvu_dbg_mcs_rx_sa_stats_fops);
523 
524 		debugfs_create_file("port", 0600, rvu->rvu_dbg.mcs_rx, mcs,
525 				    &rvu_dbg_mcs_rx_port_stats_fops);
526 
527 		rvu->rvu_dbg.mcs_tx = debugfs_create_dir("tx_stats", rvu->rvu_dbg.mcs);
528 
529 		debugfs_create_file("flowid", 0600, rvu->rvu_dbg.mcs_tx, mcs,
530 				    &rvu_dbg_mcs_tx_flowid_stats_fops);
531 
532 		debugfs_create_file("secy", 0600, rvu->rvu_dbg.mcs_tx, mcs,
533 				    &rvu_dbg_mcs_tx_secy_stats_fops);
534 
535 		debugfs_create_file("sc", 0600, rvu->rvu_dbg.mcs_tx, mcs,
536 				    &rvu_dbg_mcs_tx_sc_stats_fops);
537 
538 		debugfs_create_file("sa", 0600, rvu->rvu_dbg.mcs_tx, mcs,
539 				    &rvu_dbg_mcs_tx_sa_stats_fops);
540 
541 		debugfs_create_file("port", 0600, rvu->rvu_dbg.mcs_tx, mcs,
542 				    &rvu_dbg_mcs_tx_port_stats_fops);
543 	}
544 }
545 
546 #define LMT_MAPTBL_ENTRY_SIZE 16
547 /* Dump LMTST map table */
rvu_dbg_lmtst_map_table_display(struct file * filp,char __user * buffer,size_t count,loff_t * ppos)548 static ssize_t rvu_dbg_lmtst_map_table_display(struct file *filp,
549 					       char __user *buffer,
550 					       size_t count, loff_t *ppos)
551 {
552 	struct rvu *rvu = filp->private_data;
553 	u64 lmt_addr, val, tbl_base;
554 	int pf, vf, num_vfs, hw_vfs;
555 	void __iomem *lmt_map_base;
556 	int buf_size = 10240;
557 	size_t off = 0;
558 	int index = 0;
559 	char *buf;
560 	int ret;
561 
562 	/* don't allow partial reads */
563 	if (*ppos != 0)
564 		return 0;
565 
566 	buf = kzalloc(buf_size, GFP_KERNEL);
567 	if (!buf)
568 		return -ENOMEM;
569 
570 	tbl_base = rvu_read64(rvu, BLKADDR_APR, APR_AF_LMT_MAP_BASE);
571 
572 	lmt_map_base = ioremap_wc(tbl_base, 128 * 1024);
573 	if (!lmt_map_base) {
574 		dev_err(rvu->dev, "Failed to setup lmt map table mapping!!\n");
575 		kfree(buf);
576 		return false;
577 	}
578 
579 	off +=	scnprintf(&buf[off], buf_size - 1 - off,
580 			  "\n\t\t\t\t\tLmtst Map Table Entries");
581 	off +=	scnprintf(&buf[off], buf_size - 1 - off,
582 			  "\n\t\t\t\t\t=======================");
583 	off +=	scnprintf(&buf[off], buf_size - 1 - off, "\nPcifunc\t\t\t");
584 	off +=	scnprintf(&buf[off], buf_size - 1 - off, "Table Index\t\t");
585 	off +=	scnprintf(&buf[off], buf_size - 1 - off,
586 			  "Lmtline Base (word 0)\t\t");
587 	off +=	scnprintf(&buf[off], buf_size - 1 - off,
588 			  "Lmt Map Entry (word 1)");
589 	off += scnprintf(&buf[off], buf_size - 1 - off, "\n");
590 	for (pf = 0; pf < rvu->hw->total_pfs; pf++) {
591 		off += scnprintf(&buf[off], buf_size - 1 - off, "PF%d  \t\t\t",
592 				    pf);
593 
594 		index = pf * rvu->hw->total_vfs * LMT_MAPTBL_ENTRY_SIZE;
595 		off += scnprintf(&buf[off], buf_size - 1 - off, " 0x%llx\t\t",
596 				 (tbl_base + index));
597 		lmt_addr = readq(lmt_map_base + index);
598 		off += scnprintf(&buf[off], buf_size - 1 - off,
599 				 " 0x%016llx\t\t", lmt_addr);
600 		index += 8;
601 		val = readq(lmt_map_base + index);
602 		off += scnprintf(&buf[off], buf_size - 1 - off, " 0x%016llx\n",
603 				 val);
604 		/* Reading num of VFs per PF */
605 		rvu_get_pf_numvfs(rvu, pf, &num_vfs, &hw_vfs);
606 		for (vf = 0; vf < num_vfs; vf++) {
607 			index = (pf * rvu->hw->total_vfs * 16) +
608 				((vf + 1)  * LMT_MAPTBL_ENTRY_SIZE);
609 			off += scnprintf(&buf[off], buf_size - 1 - off,
610 					    "PF%d:VF%d  \t\t", pf, vf);
611 			off += scnprintf(&buf[off], buf_size - 1 - off,
612 					 " 0x%llx\t\t", (tbl_base + index));
613 			lmt_addr = readq(lmt_map_base + index);
614 			off += scnprintf(&buf[off], buf_size - 1 - off,
615 					 " 0x%016llx\t\t", lmt_addr);
616 			index += 8;
617 			val = readq(lmt_map_base + index);
618 			off += scnprintf(&buf[off], buf_size - 1 - off,
619 					 " 0x%016llx\n", val);
620 		}
621 	}
622 	off +=	scnprintf(&buf[off], buf_size - 1 - off, "\n");
623 
624 	ret = min(off, count);
625 	if (copy_to_user(buffer, buf, ret))
626 		ret = -EFAULT;
627 	kfree(buf);
628 
629 	iounmap(lmt_map_base);
630 	if (ret < 0)
631 		return ret;
632 
633 	*ppos = ret;
634 	return ret;
635 }
636 
637 RVU_DEBUG_FOPS(lmtst_map_table, lmtst_map_table_display, NULL);
638 
get_lf_str_list(const struct rvu_block * block,int pcifunc,char * lfs)639 static void get_lf_str_list(const struct rvu_block *block, int pcifunc,
640 			    char *lfs)
641 {
642 	int lf = 0, seq = 0, len = 0, prev_lf = block->lf.max;
643 
644 	for_each_set_bit(lf, block->lf.bmap, block->lf.max) {
645 		if (lf >= block->lf.max)
646 			break;
647 
648 		if (block->fn_map[lf] != pcifunc)
649 			continue;
650 
651 		if (lf == prev_lf + 1) {
652 			prev_lf = lf;
653 			seq = 1;
654 			continue;
655 		}
656 
657 		if (seq)
658 			len += sprintf(lfs + len, "-%d,%d", prev_lf, lf);
659 		else
660 			len += (len ? sprintf(lfs + len, ",%d", lf) :
661 				      sprintf(lfs + len, "%d", lf));
662 
663 		prev_lf = lf;
664 		seq = 0;
665 	}
666 
667 	if (seq)
668 		len += sprintf(lfs + len, "-%d", prev_lf);
669 
670 	lfs[len] = '\0';
671 }
672 
get_max_column_width(struct rvu * rvu)673 static int get_max_column_width(struct rvu *rvu)
674 {
675 	int index, pf, vf, lf_str_size = 12, buf_size = 256;
676 	struct rvu_block block;
677 	u16 pcifunc;
678 	char *buf;
679 
680 	buf = kzalloc(buf_size, GFP_KERNEL);
681 	if (!buf)
682 		return -ENOMEM;
683 
684 	for (pf = 0; pf < rvu->hw->total_pfs; pf++) {
685 		for (vf = 0; vf <= rvu->hw->total_vfs; vf++) {
686 			pcifunc = pf << 10 | vf;
687 			if (!pcifunc)
688 				continue;
689 
690 			for (index = 0; index < BLK_COUNT; index++) {
691 				block = rvu->hw->block[index];
692 				if (!strlen(block.name))
693 					continue;
694 
695 				get_lf_str_list(&block, pcifunc, buf);
696 				if (lf_str_size <= strlen(buf))
697 					lf_str_size = strlen(buf) + 1;
698 			}
699 		}
700 	}
701 
702 	kfree(buf);
703 	return lf_str_size;
704 }
705 
706 /* Dumps current provisioning status of all RVU block LFs */
rvu_dbg_rsrc_attach_status(struct file * filp,char __user * buffer,size_t count,loff_t * ppos)707 static ssize_t rvu_dbg_rsrc_attach_status(struct file *filp,
708 					  char __user *buffer,
709 					  size_t count, loff_t *ppos)
710 {
711 	int index, off = 0, flag = 0, len = 0, i = 0;
712 	struct rvu *rvu = filp->private_data;
713 	int bytes_not_copied = 0;
714 	struct rvu_block block;
715 	int pf, vf, pcifunc;
716 	int buf_size = 2048;
717 	int lf_str_size;
718 	char *lfs;
719 	char *buf;
720 
721 	/* don't allow partial reads */
722 	if (*ppos != 0)
723 		return 0;
724 
725 	buf = kzalloc(buf_size, GFP_KERNEL);
726 	if (!buf)
727 		return -ENOMEM;
728 
729 	/* Get the maximum width of a column */
730 	lf_str_size = get_max_column_width(rvu);
731 
732 	lfs = kzalloc(lf_str_size, GFP_KERNEL);
733 	if (!lfs) {
734 		kfree(buf);
735 		return -ENOMEM;
736 	}
737 	off +=	scnprintf(&buf[off], buf_size - 1 - off, "%-*s", lf_str_size,
738 			  "pcifunc");
739 	for (index = 0; index < BLK_COUNT; index++)
740 		if (strlen(rvu->hw->block[index].name)) {
741 			off += scnprintf(&buf[off], buf_size - 1 - off,
742 					 "%-*s", lf_str_size,
743 					 rvu->hw->block[index].name);
744 		}
745 
746 	off += scnprintf(&buf[off], buf_size - 1 - off, "\n");
747 	bytes_not_copied = copy_to_user(buffer + (i * off), buf, off);
748 	if (bytes_not_copied)
749 		goto out;
750 
751 	i++;
752 	*ppos += off;
753 	for (pf = 0; pf < rvu->hw->total_pfs; pf++) {
754 		for (vf = 0; vf <= rvu->hw->total_vfs; vf++) {
755 			off = 0;
756 			flag = 0;
757 			pcifunc = pf << 10 | vf;
758 			if (!pcifunc)
759 				continue;
760 
761 			if (vf) {
762 				sprintf(lfs, "PF%d:VF%d", pf, vf - 1);
763 				off = scnprintf(&buf[off],
764 						buf_size - 1 - off,
765 						"%-*s", lf_str_size, lfs);
766 			} else {
767 				sprintf(lfs, "PF%d", pf);
768 				off = scnprintf(&buf[off],
769 						buf_size - 1 - off,
770 						"%-*s", lf_str_size, lfs);
771 			}
772 
773 			for (index = 0; index < BLK_COUNT; index++) {
774 				block = rvu->hw->block[index];
775 				if (!strlen(block.name))
776 					continue;
777 				len = 0;
778 				lfs[len] = '\0';
779 				get_lf_str_list(&block, pcifunc, lfs);
780 				if (strlen(lfs))
781 					flag = 1;
782 
783 				off += scnprintf(&buf[off], buf_size - 1 - off,
784 						 "%-*s", lf_str_size, lfs);
785 			}
786 			if (flag) {
787 				off +=	scnprintf(&buf[off],
788 						  buf_size - 1 - off, "\n");
789 				bytes_not_copied = copy_to_user(buffer +
790 								(i * off),
791 								buf, off);
792 				if (bytes_not_copied)
793 					goto out;
794 
795 				i++;
796 				*ppos += off;
797 			}
798 		}
799 	}
800 
801 out:
802 	kfree(lfs);
803 	kfree(buf);
804 	if (bytes_not_copied)
805 		return -EFAULT;
806 
807 	return *ppos;
808 }
809 
810 RVU_DEBUG_FOPS(rsrc_status, rsrc_attach_status, NULL);
811 
rvu_dbg_rvu_pf_cgx_map_display(struct seq_file * filp,void * unused)812 static int rvu_dbg_rvu_pf_cgx_map_display(struct seq_file *filp, void *unused)
813 {
814 	char cgx[10], lmac[10], chan[10];
815 	struct rvu *rvu = filp->private;
816 	struct pci_dev *pdev = NULL;
817 	struct mac_ops *mac_ops;
818 	struct rvu_pfvf *pfvf;
819 	int pf, domain, blkid;
820 	u8 cgx_id, lmac_id;
821 	u16 pcifunc;
822 
823 	domain = 2;
824 	mac_ops = get_mac_ops(rvu_first_cgx_pdata(rvu));
825 	/* There can be no CGX devices at all */
826 	if (!mac_ops)
827 		return 0;
828 	seq_printf(filp, "PCI dev\t\tRVU PF Func\tNIX block\t%s\tLMAC\tCHAN\n",
829 		   mac_ops->name);
830 	for (pf = 0; pf < rvu->hw->total_pfs; pf++) {
831 		if (!is_pf_cgxmapped(rvu, pf))
832 			continue;
833 
834 		pdev =  pci_get_domain_bus_and_slot(domain, pf + 1, 0);
835 		if (!pdev)
836 			continue;
837 
838 		cgx[0] = 0;
839 		lmac[0] = 0;
840 		pcifunc = pf << 10;
841 		pfvf = rvu_get_pfvf(rvu, pcifunc);
842 
843 		if (pfvf->nix_blkaddr == BLKADDR_NIX0)
844 			blkid = 0;
845 		else
846 			blkid = 1;
847 
848 		rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_id,
849 				    &lmac_id);
850 		sprintf(cgx, "%s%d", mac_ops->name, cgx_id);
851 		sprintf(lmac, "LMAC%d", lmac_id);
852 		sprintf(chan, "%d",
853 			rvu_nix_chan_cgx(rvu, cgx_id, lmac_id, 0));
854 		seq_printf(filp, "%s\t0x%x\t\tNIX%d\t\t%s\t%s\t%s\n",
855 			   dev_name(&pdev->dev), pcifunc, blkid, cgx, lmac,
856 			   chan);
857 
858 		pci_dev_put(pdev);
859 	}
860 	return 0;
861 }
862 
863 RVU_DEBUG_SEQ_FOPS(rvu_pf_cgx_map, rvu_pf_cgx_map_display, NULL);
864 
rvu_dbg_is_valid_lf(struct rvu * rvu,int blkaddr,int lf,u16 * pcifunc)865 static bool rvu_dbg_is_valid_lf(struct rvu *rvu, int blkaddr, int lf,
866 				u16 *pcifunc)
867 {
868 	struct rvu_block *block;
869 	struct rvu_hwinfo *hw;
870 
871 	hw = rvu->hw;
872 	block = &hw->block[blkaddr];
873 
874 	if (lf < 0 || lf >= block->lf.max) {
875 		dev_warn(rvu->dev, "Invalid LF: valid range: 0-%d\n",
876 			 block->lf.max - 1);
877 		return false;
878 	}
879 
880 	*pcifunc = block->fn_map[lf];
881 	if (!*pcifunc) {
882 		dev_warn(rvu->dev,
883 			 "This LF is not attached to any RVU PFFUNC\n");
884 		return false;
885 	}
886 	return true;
887 }
888 
print_npa_qsize(struct seq_file * m,struct rvu_pfvf * pfvf)889 static void print_npa_qsize(struct seq_file *m, struct rvu_pfvf *pfvf)
890 {
891 	char *buf;
892 
893 	buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
894 	if (!buf)
895 		return;
896 
897 	if (!pfvf->aura_ctx) {
898 		seq_puts(m, "Aura context is not initialized\n");
899 	} else {
900 		bitmap_print_to_pagebuf(false, buf, pfvf->aura_bmap,
901 					pfvf->aura_ctx->qsize);
902 		seq_printf(m, "Aura count : %d\n", pfvf->aura_ctx->qsize);
903 		seq_printf(m, "Aura context ena/dis bitmap : %s\n", buf);
904 	}
905 
906 	if (!pfvf->pool_ctx) {
907 		seq_puts(m, "Pool context is not initialized\n");
908 	} else {
909 		bitmap_print_to_pagebuf(false, buf, pfvf->pool_bmap,
910 					pfvf->pool_ctx->qsize);
911 		seq_printf(m, "Pool count : %d\n", pfvf->pool_ctx->qsize);
912 		seq_printf(m, "Pool context ena/dis bitmap : %s\n", buf);
913 	}
914 	kfree(buf);
915 }
916 
917 /* The 'qsize' entry dumps current Aura/Pool context Qsize
918  * and each context's current enable/disable status in a bitmap.
919  */
rvu_dbg_qsize_display(struct seq_file * filp,void * unsused,int blktype)920 static int rvu_dbg_qsize_display(struct seq_file *filp, void *unsused,
921 				 int blktype)
922 {
923 	void (*print_qsize)(struct seq_file *filp,
924 			    struct rvu_pfvf *pfvf) = NULL;
925 	struct dentry *current_dir;
926 	struct rvu_pfvf *pfvf;
927 	struct rvu *rvu;
928 	int qsize_id;
929 	u16 pcifunc;
930 	int blkaddr;
931 
932 	rvu = filp->private;
933 	switch (blktype) {
934 	case BLKTYPE_NPA:
935 		qsize_id = rvu->rvu_dbg.npa_qsize_id;
936 		print_qsize = print_npa_qsize;
937 		break;
938 
939 	case BLKTYPE_NIX:
940 		qsize_id = rvu->rvu_dbg.nix_qsize_id;
941 		print_qsize = print_nix_qsize;
942 		break;
943 
944 	default:
945 		return -EINVAL;
946 	}
947 
948 	if (blktype == BLKTYPE_NPA) {
949 		blkaddr = BLKADDR_NPA;
950 	} else {
951 		current_dir = filp->file->f_path.dentry->d_parent;
952 		blkaddr = (!strcmp(current_dir->d_name.name, "nix1") ?
953 				   BLKADDR_NIX1 : BLKADDR_NIX0);
954 	}
955 
956 	if (!rvu_dbg_is_valid_lf(rvu, blkaddr, qsize_id, &pcifunc))
957 		return -EINVAL;
958 
959 	pfvf = rvu_get_pfvf(rvu, pcifunc);
960 	print_qsize(filp, pfvf);
961 
962 	return 0;
963 }
964 
rvu_dbg_qsize_write(struct file * filp,const char __user * buffer,size_t count,loff_t * ppos,int blktype)965 static ssize_t rvu_dbg_qsize_write(struct file *filp,
966 				   const char __user *buffer, size_t count,
967 				   loff_t *ppos, int blktype)
968 {
969 	char *blk_string = (blktype == BLKTYPE_NPA) ? "npa" : "nix";
970 	struct seq_file *seqfile = filp->private_data;
971 	char *cmd_buf, *cmd_buf_tmp, *subtoken;
972 	struct rvu *rvu = seqfile->private;
973 	struct dentry *current_dir;
974 	int blkaddr;
975 	u16 pcifunc;
976 	int ret, lf;
977 
978 	cmd_buf = memdup_user_nul(buffer, count);
979 	if (IS_ERR(cmd_buf))
980 		return -ENOMEM;
981 
982 	cmd_buf_tmp = strchr(cmd_buf, '\n');
983 	if (cmd_buf_tmp) {
984 		*cmd_buf_tmp = '\0';
985 		count = cmd_buf_tmp - cmd_buf + 1;
986 	}
987 
988 	cmd_buf_tmp = cmd_buf;
989 	subtoken = strsep(&cmd_buf, " ");
990 	ret = subtoken ? kstrtoint(subtoken, 10, &lf) : -EINVAL;
991 	if (cmd_buf)
992 		ret = -EINVAL;
993 
994 	if (ret < 0 || !strncmp(subtoken, "help", 4)) {
995 		dev_info(rvu->dev, "Use echo <%s-lf > qsize\n", blk_string);
996 		goto qsize_write_done;
997 	}
998 
999 	if (blktype == BLKTYPE_NPA) {
1000 		blkaddr = BLKADDR_NPA;
1001 	} else {
1002 		current_dir = filp->f_path.dentry->d_parent;
1003 		blkaddr = (!strcmp(current_dir->d_name.name, "nix1") ?
1004 				   BLKADDR_NIX1 : BLKADDR_NIX0);
1005 	}
1006 
1007 	if (!rvu_dbg_is_valid_lf(rvu, blkaddr, lf, &pcifunc)) {
1008 		ret = -EINVAL;
1009 		goto qsize_write_done;
1010 	}
1011 	if (blktype  == BLKTYPE_NPA)
1012 		rvu->rvu_dbg.npa_qsize_id = lf;
1013 	else
1014 		rvu->rvu_dbg.nix_qsize_id = lf;
1015 
1016 qsize_write_done:
1017 	kfree(cmd_buf_tmp);
1018 	return ret ? ret : count;
1019 }
1020 
rvu_dbg_npa_qsize_write(struct file * filp,const char __user * buffer,size_t count,loff_t * ppos)1021 static ssize_t rvu_dbg_npa_qsize_write(struct file *filp,
1022 				       const char __user *buffer,
1023 				       size_t count, loff_t *ppos)
1024 {
1025 	return rvu_dbg_qsize_write(filp, buffer, count, ppos,
1026 					    BLKTYPE_NPA);
1027 }
1028 
rvu_dbg_npa_qsize_display(struct seq_file * filp,void * unused)1029 static int rvu_dbg_npa_qsize_display(struct seq_file *filp, void *unused)
1030 {
1031 	return rvu_dbg_qsize_display(filp, unused, BLKTYPE_NPA);
1032 }
1033 
1034 RVU_DEBUG_SEQ_FOPS(npa_qsize, npa_qsize_display, npa_qsize_write);
1035 
1036 /* Dumps given NPA Aura's context */
print_npa_aura_ctx(struct seq_file * m,struct npa_aq_enq_rsp * rsp)1037 static void print_npa_aura_ctx(struct seq_file *m, struct npa_aq_enq_rsp *rsp)
1038 {
1039 	struct npa_aura_s *aura = &rsp->aura;
1040 	struct rvu *rvu = m->private;
1041 
1042 	seq_printf(m, "W0: Pool addr\t\t%llx\n", aura->pool_addr);
1043 
1044 	seq_printf(m, "W1: ena\t\t\t%d\nW1: pool caching\t%d\n",
1045 		   aura->ena, aura->pool_caching);
1046 	seq_printf(m, "W1: pool way mask\t%d\nW1: avg con\t\t%d\n",
1047 		   aura->pool_way_mask, aura->avg_con);
1048 	seq_printf(m, "W1: pool drop ena\t%d\nW1: aura drop ena\t%d\n",
1049 		   aura->pool_drop_ena, aura->aura_drop_ena);
1050 	seq_printf(m, "W1: bp_ena\t\t%d\nW1: aura drop\t\t%d\n",
1051 		   aura->bp_ena, aura->aura_drop);
1052 	seq_printf(m, "W1: aura shift\t\t%d\nW1: avg_level\t\t%d\n",
1053 		   aura->shift, aura->avg_level);
1054 
1055 	seq_printf(m, "W2: count\t\t%llu\nW2: nix0_bpid\t\t%d\nW2: nix1_bpid\t\t%d\n",
1056 		   (u64)aura->count, aura->nix0_bpid, aura->nix1_bpid);
1057 
1058 	seq_printf(m, "W3: limit\t\t%llu\nW3: bp\t\t\t%d\nW3: fc_ena\t\t%d\n",
1059 		   (u64)aura->limit, aura->bp, aura->fc_ena);
1060 
1061 	if (!is_rvu_otx2(rvu))
1062 		seq_printf(m, "W3: fc_be\t\t%d\n", aura->fc_be);
1063 	seq_printf(m, "W3: fc_up_crossing\t%d\nW3: fc_stype\t\t%d\n",
1064 		   aura->fc_up_crossing, aura->fc_stype);
1065 	seq_printf(m, "W3: fc_hyst_bits\t%d\n", aura->fc_hyst_bits);
1066 
1067 	seq_printf(m, "W4: fc_addr\t\t%llx\n", aura->fc_addr);
1068 
1069 	seq_printf(m, "W5: pool_drop\t\t%d\nW5: update_time\t\t%d\n",
1070 		   aura->pool_drop, aura->update_time);
1071 	seq_printf(m, "W5: err_int \t\t%d\nW5: err_int_ena\t\t%d\n",
1072 		   aura->err_int, aura->err_int_ena);
1073 	seq_printf(m, "W5: thresh_int\t\t%d\nW5: thresh_int_ena \t%d\n",
1074 		   aura->thresh_int, aura->thresh_int_ena);
1075 	seq_printf(m, "W5: thresh_up\t\t%d\nW5: thresh_qint_idx\t%d\n",
1076 		   aura->thresh_up, aura->thresh_qint_idx);
1077 	seq_printf(m, "W5: err_qint_idx \t%d\n", aura->err_qint_idx);
1078 
1079 	seq_printf(m, "W6: thresh\t\t%llu\n", (u64)aura->thresh);
1080 	if (!is_rvu_otx2(rvu))
1081 		seq_printf(m, "W6: fc_msh_dst\t\t%d\n", aura->fc_msh_dst);
1082 }
1083 
1084 /* Dumps given NPA Pool's context */
print_npa_pool_ctx(struct seq_file * m,struct npa_aq_enq_rsp * rsp)1085 static void print_npa_pool_ctx(struct seq_file *m, struct npa_aq_enq_rsp *rsp)
1086 {
1087 	struct npa_pool_s *pool = &rsp->pool;
1088 	struct rvu *rvu = m->private;
1089 
1090 	seq_printf(m, "W0: Stack base\t\t%llx\n", pool->stack_base);
1091 
1092 	seq_printf(m, "W1: ena \t\t%d\nW1: nat_align \t\t%d\n",
1093 		   pool->ena, pool->nat_align);
1094 	seq_printf(m, "W1: stack_caching\t%d\nW1: stack_way_mask\t%d\n",
1095 		   pool->stack_caching, pool->stack_way_mask);
1096 	seq_printf(m, "W1: buf_offset\t\t%d\nW1: buf_size\t\t%d\n",
1097 		   pool->buf_offset, pool->buf_size);
1098 
1099 	seq_printf(m, "W2: stack_max_pages \t%d\nW2: stack_pages\t\t%d\n",
1100 		   pool->stack_max_pages, pool->stack_pages);
1101 
1102 	seq_printf(m, "W3: op_pc \t\t%llu\n", (u64)pool->op_pc);
1103 
1104 	seq_printf(m, "W4: stack_offset\t%d\nW4: shift\t\t%d\nW4: avg_level\t\t%d\n",
1105 		   pool->stack_offset, pool->shift, pool->avg_level);
1106 	seq_printf(m, "W4: avg_con \t\t%d\nW4: fc_ena\t\t%d\nW4: fc_stype\t\t%d\n",
1107 		   pool->avg_con, pool->fc_ena, pool->fc_stype);
1108 	seq_printf(m, "W4: fc_hyst_bits\t%d\nW4: fc_up_crossing\t%d\n",
1109 		   pool->fc_hyst_bits, pool->fc_up_crossing);
1110 	if (!is_rvu_otx2(rvu))
1111 		seq_printf(m, "W4: fc_be\t\t%d\n", pool->fc_be);
1112 	seq_printf(m, "W4: update_time\t\t%d\n", pool->update_time);
1113 
1114 	seq_printf(m, "W5: fc_addr\t\t%llx\n", pool->fc_addr);
1115 
1116 	seq_printf(m, "W6: ptr_start\t\t%llx\n", pool->ptr_start);
1117 
1118 	seq_printf(m, "W7: ptr_end\t\t%llx\n", pool->ptr_end);
1119 
1120 	seq_printf(m, "W8: err_int\t\t%d\nW8: err_int_ena\t\t%d\n",
1121 		   pool->err_int, pool->err_int_ena);
1122 	seq_printf(m, "W8: thresh_int\t\t%d\n", pool->thresh_int);
1123 	seq_printf(m, "W8: thresh_int_ena\t%d\nW8: thresh_up\t\t%d\n",
1124 		   pool->thresh_int_ena, pool->thresh_up);
1125 	seq_printf(m, "W8: thresh_qint_idx\t%d\nW8: err_qint_idx\t%d\n",
1126 		   pool->thresh_qint_idx, pool->err_qint_idx);
1127 	if (!is_rvu_otx2(rvu))
1128 		seq_printf(m, "W8: fc_msh_dst\t\t%d\n", pool->fc_msh_dst);
1129 }
1130 
1131 /* Reads aura/pool's ctx from admin queue */
rvu_dbg_npa_ctx_display(struct seq_file * m,void * unused,int ctype)1132 static int rvu_dbg_npa_ctx_display(struct seq_file *m, void *unused, int ctype)
1133 {
1134 	void (*print_npa_ctx)(struct seq_file *m, struct npa_aq_enq_rsp *rsp);
1135 	struct npa_aq_enq_req aq_req;
1136 	struct npa_aq_enq_rsp rsp;
1137 	struct rvu_pfvf *pfvf;
1138 	int aura, rc, max_id;
1139 	int npalf, id, all;
1140 	struct rvu *rvu;
1141 	u16 pcifunc;
1142 
1143 	rvu = m->private;
1144 
1145 	switch (ctype) {
1146 	case NPA_AQ_CTYPE_AURA:
1147 		npalf = rvu->rvu_dbg.npa_aura_ctx.lf;
1148 		id = rvu->rvu_dbg.npa_aura_ctx.id;
1149 		all = rvu->rvu_dbg.npa_aura_ctx.all;
1150 		break;
1151 
1152 	case NPA_AQ_CTYPE_POOL:
1153 		npalf = rvu->rvu_dbg.npa_pool_ctx.lf;
1154 		id = rvu->rvu_dbg.npa_pool_ctx.id;
1155 		all = rvu->rvu_dbg.npa_pool_ctx.all;
1156 		break;
1157 	default:
1158 		return -EINVAL;
1159 	}
1160 
1161 	if (!rvu_dbg_is_valid_lf(rvu, BLKADDR_NPA, npalf, &pcifunc))
1162 		return -EINVAL;
1163 
1164 	pfvf = rvu_get_pfvf(rvu, pcifunc);
1165 	if (ctype == NPA_AQ_CTYPE_AURA && !pfvf->aura_ctx) {
1166 		seq_puts(m, "Aura context is not initialized\n");
1167 		return -EINVAL;
1168 	} else if (ctype == NPA_AQ_CTYPE_POOL && !pfvf->pool_ctx) {
1169 		seq_puts(m, "Pool context is not initialized\n");
1170 		return -EINVAL;
1171 	}
1172 
1173 	memset(&aq_req, 0, sizeof(struct npa_aq_enq_req));
1174 	aq_req.hdr.pcifunc = pcifunc;
1175 	aq_req.ctype = ctype;
1176 	aq_req.op = NPA_AQ_INSTOP_READ;
1177 	if (ctype == NPA_AQ_CTYPE_AURA) {
1178 		max_id = pfvf->aura_ctx->qsize;
1179 		print_npa_ctx = print_npa_aura_ctx;
1180 	} else {
1181 		max_id = pfvf->pool_ctx->qsize;
1182 		print_npa_ctx = print_npa_pool_ctx;
1183 	}
1184 
1185 	if (id < 0 || id >= max_id) {
1186 		seq_printf(m, "Invalid %s, valid range is 0-%d\n",
1187 			   (ctype == NPA_AQ_CTYPE_AURA) ? "aura" : "pool",
1188 			max_id - 1);
1189 		return -EINVAL;
1190 	}
1191 
1192 	if (all)
1193 		id = 0;
1194 	else
1195 		max_id = id + 1;
1196 
1197 	for (aura = id; aura < max_id; aura++) {
1198 		aq_req.aura_id = aura;
1199 
1200 		/* Skip if queue is uninitialized */
1201 		if (ctype == NPA_AQ_CTYPE_POOL && !test_bit(aura, pfvf->pool_bmap))
1202 			continue;
1203 
1204 		seq_printf(m, "======%s : %d=======\n",
1205 			   (ctype == NPA_AQ_CTYPE_AURA) ? "AURA" : "POOL",
1206 			aq_req.aura_id);
1207 		rc = rvu_npa_aq_enq_inst(rvu, &aq_req, &rsp);
1208 		if (rc) {
1209 			seq_puts(m, "Failed to read context\n");
1210 			return -EINVAL;
1211 		}
1212 		print_npa_ctx(m, &rsp);
1213 	}
1214 	return 0;
1215 }
1216 
write_npa_ctx(struct rvu * rvu,bool all,int npalf,int id,int ctype)1217 static int write_npa_ctx(struct rvu *rvu, bool all,
1218 			 int npalf, int id, int ctype)
1219 {
1220 	struct rvu_pfvf *pfvf;
1221 	int max_id = 0;
1222 	u16 pcifunc;
1223 
1224 	if (!rvu_dbg_is_valid_lf(rvu, BLKADDR_NPA, npalf, &pcifunc))
1225 		return -EINVAL;
1226 
1227 	pfvf = rvu_get_pfvf(rvu, pcifunc);
1228 
1229 	if (ctype == NPA_AQ_CTYPE_AURA) {
1230 		if (!pfvf->aura_ctx) {
1231 			dev_warn(rvu->dev, "Aura context is not initialized\n");
1232 			return -EINVAL;
1233 		}
1234 		max_id = pfvf->aura_ctx->qsize;
1235 	} else if (ctype == NPA_AQ_CTYPE_POOL) {
1236 		if (!pfvf->pool_ctx) {
1237 			dev_warn(rvu->dev, "Pool context is not initialized\n");
1238 			return -EINVAL;
1239 		}
1240 		max_id = pfvf->pool_ctx->qsize;
1241 	}
1242 
1243 	if (id < 0 || id >= max_id) {
1244 		dev_warn(rvu->dev, "Invalid %s, valid range is 0-%d\n",
1245 			 (ctype == NPA_AQ_CTYPE_AURA) ? "aura" : "pool",
1246 			max_id - 1);
1247 		return -EINVAL;
1248 	}
1249 
1250 	switch (ctype) {
1251 	case NPA_AQ_CTYPE_AURA:
1252 		rvu->rvu_dbg.npa_aura_ctx.lf = npalf;
1253 		rvu->rvu_dbg.npa_aura_ctx.id = id;
1254 		rvu->rvu_dbg.npa_aura_ctx.all = all;
1255 		break;
1256 
1257 	case NPA_AQ_CTYPE_POOL:
1258 		rvu->rvu_dbg.npa_pool_ctx.lf = npalf;
1259 		rvu->rvu_dbg.npa_pool_ctx.id = id;
1260 		rvu->rvu_dbg.npa_pool_ctx.all = all;
1261 		break;
1262 	default:
1263 		return -EINVAL;
1264 	}
1265 	return 0;
1266 }
1267 
parse_cmd_buffer_ctx(char * cmd_buf,size_t * count,const char __user * buffer,int * npalf,int * id,bool * all)1268 static int parse_cmd_buffer_ctx(char *cmd_buf, size_t *count,
1269 				const char __user *buffer, int *npalf,
1270 				int *id, bool *all)
1271 {
1272 	int bytes_not_copied;
1273 	char *cmd_buf_tmp;
1274 	char *subtoken;
1275 	int ret;
1276 
1277 	bytes_not_copied = copy_from_user(cmd_buf, buffer, *count);
1278 	if (bytes_not_copied)
1279 		return -EFAULT;
1280 
1281 	cmd_buf[*count] = '\0';
1282 	cmd_buf_tmp = strchr(cmd_buf, '\n');
1283 
1284 	if (cmd_buf_tmp) {
1285 		*cmd_buf_tmp = '\0';
1286 		*count = cmd_buf_tmp - cmd_buf + 1;
1287 	}
1288 
1289 	subtoken = strsep(&cmd_buf, " ");
1290 	ret = subtoken ? kstrtoint(subtoken, 10, npalf) : -EINVAL;
1291 	if (ret < 0)
1292 		return ret;
1293 	subtoken = strsep(&cmd_buf, " ");
1294 	if (subtoken && strcmp(subtoken, "all") == 0) {
1295 		*all = true;
1296 	} else {
1297 		ret = subtoken ? kstrtoint(subtoken, 10, id) : -EINVAL;
1298 		if (ret < 0)
1299 			return ret;
1300 	}
1301 	if (cmd_buf)
1302 		return -EINVAL;
1303 	return ret;
1304 }
1305 
rvu_dbg_npa_ctx_write(struct file * filp,const char __user * buffer,size_t count,loff_t * ppos,int ctype)1306 static ssize_t rvu_dbg_npa_ctx_write(struct file *filp,
1307 				     const char __user *buffer,
1308 				     size_t count, loff_t *ppos, int ctype)
1309 {
1310 	char *cmd_buf, *ctype_string = (ctype == NPA_AQ_CTYPE_AURA) ?
1311 					"aura" : "pool";
1312 	struct seq_file *seqfp = filp->private_data;
1313 	struct rvu *rvu = seqfp->private;
1314 	int npalf, id = 0, ret;
1315 	bool all = false;
1316 
1317 	if ((*ppos != 0) || !count)
1318 		return -EINVAL;
1319 
1320 	cmd_buf = kzalloc(count + 1, GFP_KERNEL);
1321 	if (!cmd_buf)
1322 		return count;
1323 	ret = parse_cmd_buffer_ctx(cmd_buf, &count, buffer,
1324 				   &npalf, &id, &all);
1325 	if (ret < 0) {
1326 		dev_info(rvu->dev,
1327 			 "Usage: echo <npalf> [%s number/all] > %s_ctx\n",
1328 			 ctype_string, ctype_string);
1329 		goto done;
1330 	} else {
1331 		ret = write_npa_ctx(rvu, all, npalf, id, ctype);
1332 	}
1333 done:
1334 	kfree(cmd_buf);
1335 	return ret ? ret : count;
1336 }
1337 
rvu_dbg_npa_aura_ctx_write(struct file * filp,const char __user * buffer,size_t count,loff_t * ppos)1338 static ssize_t rvu_dbg_npa_aura_ctx_write(struct file *filp,
1339 					  const char __user *buffer,
1340 					  size_t count, loff_t *ppos)
1341 {
1342 	return rvu_dbg_npa_ctx_write(filp, buffer, count, ppos,
1343 				     NPA_AQ_CTYPE_AURA);
1344 }
1345 
rvu_dbg_npa_aura_ctx_display(struct seq_file * filp,void * unused)1346 static int rvu_dbg_npa_aura_ctx_display(struct seq_file *filp, void *unused)
1347 {
1348 	return rvu_dbg_npa_ctx_display(filp, unused, NPA_AQ_CTYPE_AURA);
1349 }
1350 
1351 RVU_DEBUG_SEQ_FOPS(npa_aura_ctx, npa_aura_ctx_display, npa_aura_ctx_write);
1352 
rvu_dbg_npa_pool_ctx_write(struct file * filp,const char __user * buffer,size_t count,loff_t * ppos)1353 static ssize_t rvu_dbg_npa_pool_ctx_write(struct file *filp,
1354 					  const char __user *buffer,
1355 					  size_t count, loff_t *ppos)
1356 {
1357 	return rvu_dbg_npa_ctx_write(filp, buffer, count, ppos,
1358 				     NPA_AQ_CTYPE_POOL);
1359 }
1360 
rvu_dbg_npa_pool_ctx_display(struct seq_file * filp,void * unused)1361 static int rvu_dbg_npa_pool_ctx_display(struct seq_file *filp, void *unused)
1362 {
1363 	return rvu_dbg_npa_ctx_display(filp, unused, NPA_AQ_CTYPE_POOL);
1364 }
1365 
1366 RVU_DEBUG_SEQ_FOPS(npa_pool_ctx, npa_pool_ctx_display, npa_pool_ctx_write);
1367 
ndc_cache_stats(struct seq_file * s,int blk_addr,int ctype,int transaction)1368 static void ndc_cache_stats(struct seq_file *s, int blk_addr,
1369 			    int ctype, int transaction)
1370 {
1371 	u64 req, out_req, lat, cant_alloc;
1372 	struct nix_hw *nix_hw;
1373 	struct rvu *rvu;
1374 	int port;
1375 
1376 	if (blk_addr == BLKADDR_NDC_NPA0) {
1377 		rvu = s->private;
1378 	} else {
1379 		nix_hw = s->private;
1380 		rvu = nix_hw->rvu;
1381 	}
1382 
1383 	for (port = 0; port < NDC_MAX_PORT; port++) {
1384 		req = rvu_read64(rvu, blk_addr, NDC_AF_PORTX_RTX_RWX_REQ_PC
1385 						(port, ctype, transaction));
1386 		lat = rvu_read64(rvu, blk_addr, NDC_AF_PORTX_RTX_RWX_LAT_PC
1387 						(port, ctype, transaction));
1388 		out_req = rvu_read64(rvu, blk_addr,
1389 				     NDC_AF_PORTX_RTX_RWX_OSTDN_PC
1390 				     (port, ctype, transaction));
1391 		cant_alloc = rvu_read64(rvu, blk_addr,
1392 					NDC_AF_PORTX_RTX_CANT_ALLOC_PC
1393 					(port, transaction));
1394 		seq_printf(s, "\nPort:%d\n", port);
1395 		seq_printf(s, "\tTotal Requests:\t\t%lld\n", req);
1396 		seq_printf(s, "\tTotal Time Taken:\t%lld cycles\n", lat);
1397 		seq_printf(s, "\tAvg Latency:\t\t%lld cycles\n", lat / req);
1398 		seq_printf(s, "\tOutstanding Requests:\t%lld\n", out_req);
1399 		seq_printf(s, "\tCant Alloc Requests:\t%lld\n", cant_alloc);
1400 	}
1401 }
1402 
ndc_blk_cache_stats(struct seq_file * s,int idx,int blk_addr)1403 static int ndc_blk_cache_stats(struct seq_file *s, int idx, int blk_addr)
1404 {
1405 	seq_puts(s, "\n***** CACHE mode read stats *****\n");
1406 	ndc_cache_stats(s, blk_addr, CACHING, NDC_READ_TRANS);
1407 	seq_puts(s, "\n***** CACHE mode write stats *****\n");
1408 	ndc_cache_stats(s, blk_addr, CACHING, NDC_WRITE_TRANS);
1409 	seq_puts(s, "\n***** BY-PASS mode read stats *****\n");
1410 	ndc_cache_stats(s, blk_addr, BYPASS, NDC_READ_TRANS);
1411 	seq_puts(s, "\n***** BY-PASS mode write stats *****\n");
1412 	ndc_cache_stats(s, blk_addr, BYPASS, NDC_WRITE_TRANS);
1413 	return 0;
1414 }
1415 
rvu_dbg_npa_ndc_cache_display(struct seq_file * filp,void * unused)1416 static int rvu_dbg_npa_ndc_cache_display(struct seq_file *filp, void *unused)
1417 {
1418 	return ndc_blk_cache_stats(filp, NPA0_U, BLKADDR_NDC_NPA0);
1419 }
1420 
1421 RVU_DEBUG_SEQ_FOPS(npa_ndc_cache, npa_ndc_cache_display, NULL);
1422 
ndc_blk_hits_miss_stats(struct seq_file * s,int idx,int blk_addr)1423 static int ndc_blk_hits_miss_stats(struct seq_file *s, int idx, int blk_addr)
1424 {
1425 	struct nix_hw *nix_hw;
1426 	struct rvu *rvu;
1427 	int bank, max_bank;
1428 	u64 ndc_af_const;
1429 
1430 	if (blk_addr == BLKADDR_NDC_NPA0) {
1431 		rvu = s->private;
1432 	} else {
1433 		nix_hw = s->private;
1434 		rvu = nix_hw->rvu;
1435 	}
1436 
1437 	ndc_af_const = rvu_read64(rvu, blk_addr, NDC_AF_CONST);
1438 	max_bank = FIELD_GET(NDC_AF_BANK_MASK, ndc_af_const);
1439 	for (bank = 0; bank < max_bank; bank++) {
1440 		seq_printf(s, "BANK:%d\n", bank);
1441 		seq_printf(s, "\tHits:\t%lld\n",
1442 			   (u64)rvu_read64(rvu, blk_addr,
1443 			   NDC_AF_BANKX_HIT_PC(bank)));
1444 		seq_printf(s, "\tMiss:\t%lld\n",
1445 			   (u64)rvu_read64(rvu, blk_addr,
1446 			    NDC_AF_BANKX_MISS_PC(bank)));
1447 	}
1448 	return 0;
1449 }
1450 
rvu_dbg_nix_ndc_rx_cache_display(struct seq_file * filp,void * unused)1451 static int rvu_dbg_nix_ndc_rx_cache_display(struct seq_file *filp, void *unused)
1452 {
1453 	struct nix_hw *nix_hw = filp->private;
1454 	int blkaddr = 0;
1455 	int ndc_idx = 0;
1456 
1457 	blkaddr = (nix_hw->blkaddr == BLKADDR_NIX1 ?
1458 		   BLKADDR_NDC_NIX1_RX : BLKADDR_NDC_NIX0_RX);
1459 	ndc_idx = (nix_hw->blkaddr == BLKADDR_NIX1 ? NIX1_RX : NIX0_RX);
1460 
1461 	return ndc_blk_cache_stats(filp, ndc_idx, blkaddr);
1462 }
1463 
1464 RVU_DEBUG_SEQ_FOPS(nix_ndc_rx_cache, nix_ndc_rx_cache_display, NULL);
1465 
rvu_dbg_nix_ndc_tx_cache_display(struct seq_file * filp,void * unused)1466 static int rvu_dbg_nix_ndc_tx_cache_display(struct seq_file *filp, void *unused)
1467 {
1468 	struct nix_hw *nix_hw = filp->private;
1469 	int blkaddr = 0;
1470 	int ndc_idx = 0;
1471 
1472 	blkaddr = (nix_hw->blkaddr == BLKADDR_NIX1 ?
1473 		   BLKADDR_NDC_NIX1_TX : BLKADDR_NDC_NIX0_TX);
1474 	ndc_idx = (nix_hw->blkaddr == BLKADDR_NIX1 ? NIX1_TX : NIX0_TX);
1475 
1476 	return ndc_blk_cache_stats(filp, ndc_idx, blkaddr);
1477 }
1478 
1479 RVU_DEBUG_SEQ_FOPS(nix_ndc_tx_cache, nix_ndc_tx_cache_display, NULL);
1480 
rvu_dbg_npa_ndc_hits_miss_display(struct seq_file * filp,void * unused)1481 static int rvu_dbg_npa_ndc_hits_miss_display(struct seq_file *filp,
1482 					     void *unused)
1483 {
1484 	return ndc_blk_hits_miss_stats(filp, NPA0_U, BLKADDR_NDC_NPA0);
1485 }
1486 
1487 RVU_DEBUG_SEQ_FOPS(npa_ndc_hits_miss, npa_ndc_hits_miss_display, NULL);
1488 
rvu_dbg_nix_ndc_rx_hits_miss_display(struct seq_file * filp,void * unused)1489 static int rvu_dbg_nix_ndc_rx_hits_miss_display(struct seq_file *filp,
1490 						void *unused)
1491 {
1492 	struct nix_hw *nix_hw = filp->private;
1493 	int ndc_idx = NPA0_U;
1494 	int blkaddr = 0;
1495 
1496 	blkaddr = (nix_hw->blkaddr == BLKADDR_NIX1 ?
1497 		   BLKADDR_NDC_NIX1_RX : BLKADDR_NDC_NIX0_RX);
1498 
1499 	return ndc_blk_hits_miss_stats(filp, ndc_idx, blkaddr);
1500 }
1501 
1502 RVU_DEBUG_SEQ_FOPS(nix_ndc_rx_hits_miss, nix_ndc_rx_hits_miss_display, NULL);
1503 
rvu_dbg_nix_ndc_tx_hits_miss_display(struct seq_file * filp,void * unused)1504 static int rvu_dbg_nix_ndc_tx_hits_miss_display(struct seq_file *filp,
1505 						void *unused)
1506 {
1507 	struct nix_hw *nix_hw = filp->private;
1508 	int ndc_idx = NPA0_U;
1509 	int blkaddr = 0;
1510 
1511 	blkaddr = (nix_hw->blkaddr == BLKADDR_NIX1 ?
1512 		   BLKADDR_NDC_NIX1_TX : BLKADDR_NDC_NIX0_TX);
1513 
1514 	return ndc_blk_hits_miss_stats(filp, ndc_idx, blkaddr);
1515 }
1516 
1517 RVU_DEBUG_SEQ_FOPS(nix_ndc_tx_hits_miss, nix_ndc_tx_hits_miss_display, NULL);
1518 
print_nix_cn10k_sq_ctx(struct seq_file * m,struct nix_cn10k_sq_ctx_s * sq_ctx)1519 static void print_nix_cn10k_sq_ctx(struct seq_file *m,
1520 				   struct nix_cn10k_sq_ctx_s *sq_ctx)
1521 {
1522 	seq_printf(m, "W0: ena \t\t\t%d\nW0: qint_idx \t\t\t%d\n",
1523 		   sq_ctx->ena, sq_ctx->qint_idx);
1524 	seq_printf(m, "W0: substream \t\t\t0x%03x\nW0: sdp_mcast \t\t\t%d\n",
1525 		   sq_ctx->substream, sq_ctx->sdp_mcast);
1526 	seq_printf(m, "W0: cq \t\t\t\t%d\nW0: sqe_way_mask \t\t%d\n\n",
1527 		   sq_ctx->cq, sq_ctx->sqe_way_mask);
1528 
1529 	seq_printf(m, "W1: smq \t\t\t%d\nW1: cq_ena \t\t\t%d\nW1: xoff\t\t\t%d\n",
1530 		   sq_ctx->smq, sq_ctx->cq_ena, sq_ctx->xoff);
1531 	seq_printf(m, "W1: sso_ena \t\t\t%d\nW1: smq_rr_weight\t\t%d\n",
1532 		   sq_ctx->sso_ena, sq_ctx->smq_rr_weight);
1533 	seq_printf(m, "W1: default_chan\t\t%d\nW1: sqb_count\t\t\t%d\n\n",
1534 		   sq_ctx->default_chan, sq_ctx->sqb_count);
1535 
1536 	seq_printf(m, "W2: smq_rr_count_lb \t\t%d\n", sq_ctx->smq_rr_count_lb);
1537 	seq_printf(m, "W2: smq_rr_count_ub \t\t%d\n", sq_ctx->smq_rr_count_ub);
1538 	seq_printf(m, "W2: sqb_aura \t\t\t%d\nW2: sq_int \t\t\t%d\n",
1539 		   sq_ctx->sqb_aura, sq_ctx->sq_int);
1540 	seq_printf(m, "W2: sq_int_ena \t\t\t%d\nW2: sqe_stype \t\t\t%d\n",
1541 		   sq_ctx->sq_int_ena, sq_ctx->sqe_stype);
1542 
1543 	seq_printf(m, "W3: max_sqe_size\t\t%d\nW3: cq_limit\t\t\t%d\n",
1544 		   sq_ctx->max_sqe_size, sq_ctx->cq_limit);
1545 	seq_printf(m, "W3: lmt_dis \t\t\t%d\nW3: mnq_dis \t\t\t%d\n",
1546 		   sq_ctx->mnq_dis, sq_ctx->lmt_dis);
1547 	seq_printf(m, "W3: smq_next_sq\t\t\t%d\nW3: smq_lso_segnum\t\t%d\n",
1548 		   sq_ctx->smq_next_sq, sq_ctx->smq_lso_segnum);
1549 	seq_printf(m, "W3: tail_offset \t\t%d\nW3: smenq_offset\t\t%d\n",
1550 		   sq_ctx->tail_offset, sq_ctx->smenq_offset);
1551 	seq_printf(m, "W3: head_offset\t\t\t%d\nW3: smenq_next_sqb_vld\t\t%d\n\n",
1552 		   sq_ctx->head_offset, sq_ctx->smenq_next_sqb_vld);
1553 
1554 	seq_printf(m, "W3: smq_next_sq_vld\t\t%d\nW3: smq_pend\t\t\t%d\n",
1555 		   sq_ctx->smq_next_sq_vld, sq_ctx->smq_pend);
1556 	seq_printf(m, "W4: next_sqb \t\t\t%llx\n\n", sq_ctx->next_sqb);
1557 	seq_printf(m, "W5: tail_sqb \t\t\t%llx\n\n", sq_ctx->tail_sqb);
1558 	seq_printf(m, "W6: smenq_sqb \t\t\t%llx\n\n", sq_ctx->smenq_sqb);
1559 	seq_printf(m, "W7: smenq_next_sqb \t\t%llx\n\n",
1560 		   sq_ctx->smenq_next_sqb);
1561 
1562 	seq_printf(m, "W8: head_sqb\t\t\t%llx\n\n", sq_ctx->head_sqb);
1563 
1564 	seq_printf(m, "W9: vfi_lso_total\t\t%d\n", sq_ctx->vfi_lso_total);
1565 	seq_printf(m, "W9: vfi_lso_sizem1\t\t%d\nW9: vfi_lso_sb\t\t\t%d\n",
1566 		   sq_ctx->vfi_lso_sizem1, sq_ctx->vfi_lso_sb);
1567 	seq_printf(m, "W9: vfi_lso_mps\t\t\t%d\nW9: vfi_lso_vlan0_ins_ena\t%d\n",
1568 		   sq_ctx->vfi_lso_mps, sq_ctx->vfi_lso_vlan0_ins_ena);
1569 	seq_printf(m, "W9: vfi_lso_vlan1_ins_ena\t%d\nW9: vfi_lso_vld \t\t%d\n\n",
1570 		   sq_ctx->vfi_lso_vld, sq_ctx->vfi_lso_vlan1_ins_ena);
1571 
1572 	seq_printf(m, "W10: scm_lso_rem \t\t%llu\n\n",
1573 		   (u64)sq_ctx->scm_lso_rem);
1574 	seq_printf(m, "W11: octs \t\t\t%llu\n\n", (u64)sq_ctx->octs);
1575 	seq_printf(m, "W12: pkts \t\t\t%llu\n\n", (u64)sq_ctx->pkts);
1576 	seq_printf(m, "W14: dropped_octs \t\t%llu\n\n",
1577 		   (u64)sq_ctx->dropped_octs);
1578 	seq_printf(m, "W15: dropped_pkts \t\t%llu\n\n",
1579 		   (u64)sq_ctx->dropped_pkts);
1580 }
1581 
print_tm_tree(struct seq_file * m,struct nix_aq_enq_rsp * rsp,u64 sq)1582 static void print_tm_tree(struct seq_file *m,
1583 			  struct nix_aq_enq_rsp *rsp, u64 sq)
1584 {
1585 	struct nix_sq_ctx_s *sq_ctx = &rsp->sq;
1586 	struct nix_hw *nix_hw = m->private;
1587 	struct rvu *rvu = nix_hw->rvu;
1588 	u16 p1, p2, p3, p4, schq;
1589 	int blkaddr;
1590 	u64 cfg;
1591 
1592 	blkaddr = nix_hw->blkaddr;
1593 	schq = sq_ctx->smq;
1594 
1595 	cfg = rvu_read64(rvu, blkaddr, NIX_AF_MDQX_PARENT(schq));
1596 	p1 = FIELD_GET(NIX_AF_MDQ_PARENT_MASK, cfg);
1597 
1598 	cfg = rvu_read64(rvu, blkaddr, NIX_AF_TL4X_PARENT(p1));
1599 	p2 = FIELD_GET(NIX_AF_TL4_PARENT_MASK, cfg);
1600 
1601 	cfg = rvu_read64(rvu, blkaddr, NIX_AF_TL3X_PARENT(p2));
1602 	p3 = FIELD_GET(NIX_AF_TL3_PARENT_MASK, cfg);
1603 
1604 	cfg = rvu_read64(rvu, blkaddr, NIX_AF_TL2X_PARENT(p3));
1605 	p4 = FIELD_GET(NIX_AF_TL2_PARENT_MASK, cfg);
1606 	seq_printf(m,
1607 		   "SQ(%llu) -> SMQ(%u) -> TL4(%u) -> TL3(%u) -> TL2(%u) -> TL1(%u)\n",
1608 		   sq, schq, p1, p2, p3, p4);
1609 }
1610 
1611 /*dumps given tm_tree registers*/
rvu_dbg_nix_tm_tree_display(struct seq_file * m,void * unused)1612 static int rvu_dbg_nix_tm_tree_display(struct seq_file *m, void *unused)
1613 {
1614 	int qidx, nixlf, rc, id, max_id = 0;
1615 	struct nix_hw *nix_hw = m->private;
1616 	struct rvu *rvu = nix_hw->rvu;
1617 	struct nix_aq_enq_req aq_req;
1618 	struct nix_aq_enq_rsp rsp;
1619 	struct rvu_pfvf *pfvf;
1620 	u16 pcifunc;
1621 
1622 	nixlf = rvu->rvu_dbg.nix_tm_ctx.lf;
1623 	id = rvu->rvu_dbg.nix_tm_ctx.id;
1624 
1625 	if (!rvu_dbg_is_valid_lf(rvu, nix_hw->blkaddr, nixlf, &pcifunc))
1626 		return -EINVAL;
1627 
1628 	pfvf = rvu_get_pfvf(rvu, pcifunc);
1629 	max_id = pfvf->sq_ctx->qsize;
1630 
1631 	memset(&aq_req, 0, sizeof(struct nix_aq_enq_req));
1632 	aq_req.hdr.pcifunc = pcifunc;
1633 	aq_req.ctype = NIX_AQ_CTYPE_SQ;
1634 	aq_req.op = NIX_AQ_INSTOP_READ;
1635 	seq_printf(m, "pcifunc is 0x%x\n", pcifunc);
1636 	for (qidx = id; qidx < max_id; qidx++) {
1637 		aq_req.qidx = qidx;
1638 
1639 		/* Skip SQ's if not initialized */
1640 		if (!test_bit(qidx, pfvf->sq_bmap))
1641 			continue;
1642 
1643 		rc = rvu_mbox_handler_nix_aq_enq(rvu, &aq_req, &rsp);
1644 
1645 		if (rc) {
1646 			seq_printf(m, "Failed to read SQ(%d) context\n",
1647 				   aq_req.qidx);
1648 			continue;
1649 		}
1650 		print_tm_tree(m, &rsp, aq_req.qidx);
1651 	}
1652 	return 0;
1653 }
1654 
rvu_dbg_nix_tm_tree_write(struct file * filp,const char __user * buffer,size_t count,loff_t * ppos)1655 static ssize_t rvu_dbg_nix_tm_tree_write(struct file *filp,
1656 					 const char __user *buffer,
1657 					 size_t count, loff_t *ppos)
1658 {
1659 	struct seq_file *m = filp->private_data;
1660 	struct nix_hw *nix_hw = m->private;
1661 	struct rvu *rvu = nix_hw->rvu;
1662 	struct rvu_pfvf *pfvf;
1663 	u16 pcifunc;
1664 	u64 nixlf;
1665 	int ret;
1666 
1667 	ret = kstrtoull_from_user(buffer, count, 10, &nixlf);
1668 	if (ret)
1669 		return ret;
1670 
1671 	if (!rvu_dbg_is_valid_lf(rvu, nix_hw->blkaddr, nixlf, &pcifunc))
1672 		return -EINVAL;
1673 
1674 	pfvf = rvu_get_pfvf(rvu, pcifunc);
1675 	if (!pfvf->sq_ctx) {
1676 		dev_warn(rvu->dev, "SQ context is not initialized\n");
1677 		return -EINVAL;
1678 	}
1679 
1680 	rvu->rvu_dbg.nix_tm_ctx.lf = nixlf;
1681 	return count;
1682 }
1683 
1684 RVU_DEBUG_SEQ_FOPS(nix_tm_tree, nix_tm_tree_display, nix_tm_tree_write);
1685 
print_tm_topo(struct seq_file * m,u64 schq,u32 lvl)1686 static void print_tm_topo(struct seq_file *m, u64 schq, u32 lvl)
1687 {
1688 	struct nix_hw *nix_hw = m->private;
1689 	struct rvu *rvu = nix_hw->rvu;
1690 	int blkaddr, link, link_level;
1691 	struct rvu_hwinfo *hw;
1692 
1693 	hw = rvu->hw;
1694 	blkaddr = nix_hw->blkaddr;
1695 	if (lvl == NIX_TXSCH_LVL_MDQ) {
1696 		seq_printf(m, "NIX_AF_SMQ[%llu]_CFG =0x%llx\n", schq,
1697 			   rvu_read64(rvu, blkaddr, NIX_AF_SMQX_CFG(schq)));
1698 		seq_printf(m, "NIX_AF_SMQ[%llu]_STATUS =0x%llx\n", schq,
1699 			   rvu_read64(rvu, blkaddr, NIX_AF_SMQX_STATUS(schq)));
1700 		seq_printf(m, "NIX_AF_MDQ[%llu]_OUT_MD_COUNT =0x%llx\n", schq,
1701 			   rvu_read64(rvu, blkaddr,
1702 				      NIX_AF_MDQX_OUT_MD_COUNT(schq)));
1703 		seq_printf(m, "NIX_AF_MDQ[%llu]_SCHEDULE =0x%llx\n", schq,
1704 			   rvu_read64(rvu, blkaddr,
1705 				      NIX_AF_MDQX_SCHEDULE(schq)));
1706 		seq_printf(m, "NIX_AF_MDQ[%llu]_SHAPE =0x%llx\n", schq,
1707 			   rvu_read64(rvu, blkaddr, NIX_AF_MDQX_SHAPE(schq)));
1708 		seq_printf(m, "NIX_AF_MDQ[%llu]_CIR =0x%llx\n", schq,
1709 			   rvu_read64(rvu, blkaddr, NIX_AF_MDQX_CIR(schq)));
1710 		seq_printf(m, "NIX_AF_MDQ[%llu]_PIR =0x%llx\n", schq,
1711 			   rvu_read64(rvu, blkaddr, NIX_AF_MDQX_PIR(schq)));
1712 		seq_printf(m, "NIX_AF_MDQ[%llu]_SW_XOFF =0x%llx\n", schq,
1713 			   rvu_read64(rvu, blkaddr, NIX_AF_MDQX_SW_XOFF(schq)));
1714 		seq_printf(m, "NIX_AF_MDQ[%llu]_PARENT =0x%llx\n", schq,
1715 			   rvu_read64(rvu, blkaddr, NIX_AF_MDQX_PARENT(schq)));
1716 		seq_puts(m, "\n");
1717 	}
1718 
1719 	if (lvl == NIX_TXSCH_LVL_TL4) {
1720 		seq_printf(m, "NIX_AF_TL4[%llu]_SDP_LINK_CFG =0x%llx\n", schq,
1721 			   rvu_read64(rvu, blkaddr,
1722 				      NIX_AF_TL4X_SDP_LINK_CFG(schq)));
1723 		seq_printf(m, "NIX_AF_TL4[%llu]_SCHEDULE =0x%llx\n", schq,
1724 			   rvu_read64(rvu, blkaddr,
1725 				      NIX_AF_TL4X_SCHEDULE(schq)));
1726 		seq_printf(m, "NIX_AF_TL4[%llu]_SHAPE =0x%llx\n", schq,
1727 			   rvu_read64(rvu, blkaddr, NIX_AF_TL4X_SHAPE(schq)));
1728 		seq_printf(m, "NIX_AF_TL4[%llu]_CIR =0x%llx\n", schq,
1729 			   rvu_read64(rvu, blkaddr, NIX_AF_TL4X_CIR(schq)));
1730 		seq_printf(m, "NIX_AF_TL4[%llu]_PIR =0x%llx\n", schq,
1731 			   rvu_read64(rvu, blkaddr, NIX_AF_TL4X_PIR(schq)));
1732 		seq_printf(m, "NIX_AF_TL4[%llu]_SW_XOFF =0x%llx\n", schq,
1733 			   rvu_read64(rvu, blkaddr, NIX_AF_TL4X_SW_XOFF(schq)));
1734 		seq_printf(m, "NIX_AF_TL4[%llu]_TOPOLOGY =0x%llx\n", schq,
1735 			   rvu_read64(rvu, blkaddr,
1736 				      NIX_AF_TL4X_TOPOLOGY(schq)));
1737 		seq_printf(m, "NIX_AF_TL4[%llu]_PARENT =0x%llx\n", schq,
1738 			   rvu_read64(rvu, blkaddr, NIX_AF_TL4X_PARENT(schq)));
1739 		seq_printf(m, "NIX_AF_TL4[%llu]_MD_DEBUG0 =0x%llx\n", schq,
1740 			   rvu_read64(rvu, blkaddr,
1741 				      NIX_AF_TL4X_MD_DEBUG0(schq)));
1742 		seq_printf(m, "NIX_AF_TL4[%llu]_MD_DEBUG1 =0x%llx\n", schq,
1743 			   rvu_read64(rvu, blkaddr,
1744 				      NIX_AF_TL4X_MD_DEBUG1(schq)));
1745 		seq_puts(m, "\n");
1746 	}
1747 
1748 	if (lvl == NIX_TXSCH_LVL_TL3) {
1749 		seq_printf(m, "NIX_AF_TL3[%llu]_SCHEDULE =0x%llx\n", schq,
1750 			   rvu_read64(rvu, blkaddr,
1751 				      NIX_AF_TL3X_SCHEDULE(schq)));
1752 		seq_printf(m, "NIX_AF_TL3[%llu]_SHAPE =0x%llx\n", schq,
1753 			   rvu_read64(rvu, blkaddr, NIX_AF_TL3X_SHAPE(schq)));
1754 		seq_printf(m, "NIX_AF_TL3[%llu]_CIR =0x%llx\n", schq,
1755 			   rvu_read64(rvu, blkaddr, NIX_AF_TL3X_CIR(schq)));
1756 		seq_printf(m, "NIX_AF_TL3[%llu]_PIR =0x%llx\n", schq,
1757 			   rvu_read64(rvu, blkaddr, NIX_AF_TL3X_PIR(schq)));
1758 		seq_printf(m, "NIX_AF_TL3[%llu]_SW_XOFF =0x%llx\n", schq,
1759 			   rvu_read64(rvu, blkaddr, NIX_AF_TL3X_SW_XOFF(schq)));
1760 		seq_printf(m, "NIX_AF_TL3[%llu]_TOPOLOGY =0x%llx\n", schq,
1761 			   rvu_read64(rvu, blkaddr,
1762 				      NIX_AF_TL3X_TOPOLOGY(schq)));
1763 		seq_printf(m, "NIX_AF_TL3[%llu]_PARENT =0x%llx\n", schq,
1764 			   rvu_read64(rvu, blkaddr, NIX_AF_TL3X_PARENT(schq)));
1765 		seq_printf(m, "NIX_AF_TL3[%llu]_MD_DEBUG0 =0x%llx\n", schq,
1766 			   rvu_read64(rvu, blkaddr,
1767 				      NIX_AF_TL3X_MD_DEBUG0(schq)));
1768 		seq_printf(m, "NIX_AF_TL3[%llu]_MD_DEBUG1 =0x%llx\n", schq,
1769 			   rvu_read64(rvu, blkaddr,
1770 				      NIX_AF_TL3X_MD_DEBUG1(schq)));
1771 
1772 		link_level = rvu_read64(rvu, blkaddr, NIX_AF_PSE_CHANNEL_LEVEL)
1773 				& 0x01 ? NIX_TXSCH_LVL_TL3 : NIX_TXSCH_LVL_TL2;
1774 		if (lvl == link_level) {
1775 			seq_printf(m,
1776 				   "NIX_AF_TL3_TL2[%llu]_BP_STATUS =0x%llx\n",
1777 				   schq, rvu_read64(rvu, blkaddr,
1778 				   NIX_AF_TL3_TL2X_BP_STATUS(schq)));
1779 			for (link = 0; link < hw->cgx_links; link++)
1780 				seq_printf(m,
1781 					   "NIX_AF_TL3_TL2[%llu]_LINK[%d]_CFG =0x%llx\n",
1782 					   schq, link,
1783 					   rvu_read64(rvu, blkaddr,
1784 						      NIX_AF_TL3_TL2X_LINKX_CFG(schq, link)));
1785 		}
1786 		seq_puts(m, "\n");
1787 	}
1788 
1789 	if (lvl == NIX_TXSCH_LVL_TL2) {
1790 		seq_printf(m, "NIX_AF_TL2[%llu]_SHAPE =0x%llx\n", schq,
1791 			   rvu_read64(rvu, blkaddr, NIX_AF_TL2X_SHAPE(schq)));
1792 		seq_printf(m, "NIX_AF_TL2[%llu]_CIR =0x%llx\n", schq,
1793 			   rvu_read64(rvu, blkaddr, NIX_AF_TL2X_CIR(schq)));
1794 		seq_printf(m, "NIX_AF_TL2[%llu]_PIR =0x%llx\n", schq,
1795 			   rvu_read64(rvu, blkaddr, NIX_AF_TL2X_PIR(schq)));
1796 		seq_printf(m, "NIX_AF_TL2[%llu]_SW_XOFF =0x%llx\n", schq,
1797 			   rvu_read64(rvu, blkaddr, NIX_AF_TL2X_SW_XOFF(schq)));
1798 		seq_printf(m, "NIX_AF_TL2[%llu]_TOPOLOGY =0x%llx\n", schq,
1799 			   rvu_read64(rvu, blkaddr,
1800 				      NIX_AF_TL2X_TOPOLOGY(schq)));
1801 		seq_printf(m, "NIX_AF_TL2[%llu]_PARENT =0x%llx\n", schq,
1802 			   rvu_read64(rvu, blkaddr, NIX_AF_TL2X_PARENT(schq)));
1803 		seq_printf(m, "NIX_AF_TL2[%llu]_MD_DEBUG0 =0x%llx\n", schq,
1804 			   rvu_read64(rvu, blkaddr,
1805 				      NIX_AF_TL2X_MD_DEBUG0(schq)));
1806 		seq_printf(m, "NIX_AF_TL2[%llu]_MD_DEBUG1 =0x%llx\n", schq,
1807 			   rvu_read64(rvu, blkaddr,
1808 				      NIX_AF_TL2X_MD_DEBUG1(schq)));
1809 
1810 		link_level = rvu_read64(rvu, blkaddr, NIX_AF_PSE_CHANNEL_LEVEL)
1811 				& 0x01 ? NIX_TXSCH_LVL_TL3 : NIX_TXSCH_LVL_TL2;
1812 		if (lvl == link_level) {
1813 			seq_printf(m,
1814 				   "NIX_AF_TL3_TL2[%llu]_BP_STATUS =0x%llx\n",
1815 				   schq, rvu_read64(rvu, blkaddr,
1816 				   NIX_AF_TL3_TL2X_BP_STATUS(schq)));
1817 			for (link = 0; link < hw->cgx_links; link++)
1818 				seq_printf(m,
1819 					   "NIX_AF_TL3_TL2[%llu]_LINK[%d]_CFG =0x%llx\n",
1820 					   schq, link, rvu_read64(rvu, blkaddr,
1821 					   NIX_AF_TL3_TL2X_LINKX_CFG(schq, link)));
1822 		}
1823 		seq_puts(m, "\n");
1824 	}
1825 
1826 	if (lvl == NIX_TXSCH_LVL_TL1) {
1827 		seq_printf(m, "NIX_AF_TX_LINK[%llu]_NORM_CREDIT =0x%llx\n",
1828 			   schq,
1829 			   rvu_read64(rvu, blkaddr,
1830 				      NIX_AF_TX_LINKX_NORM_CREDIT(schq)));
1831 		seq_printf(m, "NIX_AF_TX_LINK[%llu]_HW_XOFF =0x%llx\n", schq,
1832 			   rvu_read64(rvu, blkaddr,
1833 				      NIX_AF_TX_LINKX_HW_XOFF(schq)));
1834 		seq_printf(m, "NIX_AF_TL1[%llu]_SCHEDULE =0x%llx\n", schq,
1835 			   rvu_read64(rvu, blkaddr,
1836 				      NIX_AF_TL1X_SCHEDULE(schq)));
1837 		seq_printf(m, "NIX_AF_TL1[%llu]_SHAPE =0x%llx\n", schq,
1838 			   rvu_read64(rvu, blkaddr, NIX_AF_TL1X_SHAPE(schq)));
1839 		seq_printf(m, "NIX_AF_TL1[%llu]_CIR =0x%llx\n", schq,
1840 			   rvu_read64(rvu, blkaddr, NIX_AF_TL1X_CIR(schq)));
1841 		seq_printf(m, "NIX_AF_TL1[%llu]_SW_XOFF =0x%llx\n", schq,
1842 			   rvu_read64(rvu, blkaddr, NIX_AF_TL1X_SW_XOFF(schq)));
1843 		seq_printf(m, "NIX_AF_TL1[%llu]_TOPOLOGY =0x%llx\n", schq,
1844 			   rvu_read64(rvu, blkaddr,
1845 				      NIX_AF_TL1X_TOPOLOGY(schq)));
1846 		seq_printf(m, "NIX_AF_TL1[%llu]_MD_DEBUG0 =0x%llx\n", schq,
1847 			   rvu_read64(rvu, blkaddr,
1848 				      NIX_AF_TL1X_MD_DEBUG0(schq)));
1849 		seq_printf(m, "NIX_AF_TL1[%llu]_MD_DEBUG1 =0x%llx\n", schq,
1850 			   rvu_read64(rvu, blkaddr,
1851 				      NIX_AF_TL1X_MD_DEBUG1(schq)));
1852 		seq_printf(m, "NIX_AF_TL1[%llu]_DROPPED_PACKETS =0x%llx\n",
1853 			   schq,
1854 			   rvu_read64(rvu, blkaddr,
1855 				      NIX_AF_TL1X_DROPPED_PACKETS(schq)));
1856 		seq_printf(m, "NIX_AF_TL1[%llu]_DROPPED_BYTES =0x%llx\n", schq,
1857 			   rvu_read64(rvu, blkaddr,
1858 				      NIX_AF_TL1X_DROPPED_BYTES(schq)));
1859 		seq_printf(m, "NIX_AF_TL1[%llu]_RED_PACKETS =0x%llx\n", schq,
1860 			   rvu_read64(rvu, blkaddr,
1861 				      NIX_AF_TL1X_RED_PACKETS(schq)));
1862 		seq_printf(m, "NIX_AF_TL1[%llu]_RED_BYTES =0x%llx\n", schq,
1863 			   rvu_read64(rvu, blkaddr,
1864 				      NIX_AF_TL1X_RED_BYTES(schq)));
1865 		seq_printf(m, "NIX_AF_TL1[%llu]_YELLOW_PACKETS =0x%llx\n", schq,
1866 			   rvu_read64(rvu, blkaddr,
1867 				      NIX_AF_TL1X_YELLOW_PACKETS(schq)));
1868 		seq_printf(m, "NIX_AF_TL1[%llu]_YELLOW_BYTES =0x%llx\n", schq,
1869 			   rvu_read64(rvu, blkaddr,
1870 				      NIX_AF_TL1X_YELLOW_BYTES(schq)));
1871 		seq_printf(m, "NIX_AF_TL1[%llu]_GREEN_PACKETS =0x%llx\n", schq,
1872 			   rvu_read64(rvu, blkaddr,
1873 				      NIX_AF_TL1X_GREEN_PACKETS(schq)));
1874 		seq_printf(m, "NIX_AF_TL1[%llu]_GREEN_BYTES =0x%llx\n", schq,
1875 			   rvu_read64(rvu, blkaddr,
1876 				      NIX_AF_TL1X_GREEN_BYTES(schq)));
1877 		seq_puts(m, "\n");
1878 	}
1879 }
1880 
1881 /*dumps given tm_topo registers*/
rvu_dbg_nix_tm_topo_display(struct seq_file * m,void * unused)1882 static int rvu_dbg_nix_tm_topo_display(struct seq_file *m, void *unused)
1883 {
1884 	struct nix_hw *nix_hw = m->private;
1885 	struct rvu *rvu = nix_hw->rvu;
1886 	struct nix_aq_enq_req aq_req;
1887 	struct nix_txsch *txsch;
1888 	int nixlf, lvl, schq;
1889 	u16 pcifunc;
1890 
1891 	nixlf = rvu->rvu_dbg.nix_tm_ctx.lf;
1892 
1893 	if (!rvu_dbg_is_valid_lf(rvu, nix_hw->blkaddr, nixlf, &pcifunc))
1894 		return -EINVAL;
1895 
1896 	memset(&aq_req, 0, sizeof(struct nix_aq_enq_req));
1897 	aq_req.hdr.pcifunc = pcifunc;
1898 	aq_req.ctype = NIX_AQ_CTYPE_SQ;
1899 	aq_req.op = NIX_AQ_INSTOP_READ;
1900 	seq_printf(m, "pcifunc is 0x%x\n", pcifunc);
1901 
1902 	for (lvl = 0; lvl < NIX_TXSCH_LVL_CNT; lvl++) {
1903 		txsch = &nix_hw->txsch[lvl];
1904 		for (schq = 0; schq < txsch->schq.max; schq++) {
1905 			if (TXSCH_MAP_FUNC(txsch->pfvf_map[schq]) == pcifunc)
1906 				print_tm_topo(m, schq, lvl);
1907 		}
1908 	}
1909 	return 0;
1910 }
1911 
rvu_dbg_nix_tm_topo_write(struct file * filp,const char __user * buffer,size_t count,loff_t * ppos)1912 static ssize_t rvu_dbg_nix_tm_topo_write(struct file *filp,
1913 					 const char __user *buffer,
1914 					 size_t count, loff_t *ppos)
1915 {
1916 	struct seq_file *m = filp->private_data;
1917 	struct nix_hw *nix_hw = m->private;
1918 	struct rvu *rvu = nix_hw->rvu;
1919 	struct rvu_pfvf *pfvf;
1920 	u16 pcifunc;
1921 	u64 nixlf;
1922 	int ret;
1923 
1924 	ret = kstrtoull_from_user(buffer, count, 10, &nixlf);
1925 	if (ret)
1926 		return ret;
1927 
1928 	if (!rvu_dbg_is_valid_lf(rvu, nix_hw->blkaddr, nixlf, &pcifunc))
1929 		return -EINVAL;
1930 
1931 	pfvf = rvu_get_pfvf(rvu, pcifunc);
1932 	if (!pfvf->sq_ctx) {
1933 		dev_warn(rvu->dev, "SQ context is not initialized\n");
1934 		return -EINVAL;
1935 	}
1936 
1937 	rvu->rvu_dbg.nix_tm_ctx.lf = nixlf;
1938 	return count;
1939 }
1940 
1941 RVU_DEBUG_SEQ_FOPS(nix_tm_topo, nix_tm_topo_display, nix_tm_topo_write);
1942 
1943 /* Dumps given nix_sq's context */
print_nix_sq_ctx(struct seq_file * m,struct nix_aq_enq_rsp * rsp)1944 static void print_nix_sq_ctx(struct seq_file *m, struct nix_aq_enq_rsp *rsp)
1945 {
1946 	struct nix_sq_ctx_s *sq_ctx = &rsp->sq;
1947 	struct nix_hw *nix_hw = m->private;
1948 	struct rvu *rvu = nix_hw->rvu;
1949 
1950 	if (!is_rvu_otx2(rvu)) {
1951 		print_nix_cn10k_sq_ctx(m, (struct nix_cn10k_sq_ctx_s *)sq_ctx);
1952 		return;
1953 	}
1954 	seq_printf(m, "W0: sqe_way_mask \t\t%d\nW0: cq \t\t\t\t%d\n",
1955 		   sq_ctx->sqe_way_mask, sq_ctx->cq);
1956 	seq_printf(m, "W0: sdp_mcast \t\t\t%d\nW0: substream \t\t\t0x%03x\n",
1957 		   sq_ctx->sdp_mcast, sq_ctx->substream);
1958 	seq_printf(m, "W0: qint_idx \t\t\t%d\nW0: ena \t\t\t%d\n\n",
1959 		   sq_ctx->qint_idx, sq_ctx->ena);
1960 
1961 	seq_printf(m, "W1: sqb_count \t\t\t%d\nW1: default_chan \t\t%d\n",
1962 		   sq_ctx->sqb_count, sq_ctx->default_chan);
1963 	seq_printf(m, "W1: smq_rr_quantum \t\t%d\nW1: sso_ena \t\t\t%d\n",
1964 		   sq_ctx->smq_rr_quantum, sq_ctx->sso_ena);
1965 	seq_printf(m, "W1: xoff \t\t\t%d\nW1: cq_ena \t\t\t%d\nW1: smq\t\t\t\t%d\n\n",
1966 		   sq_ctx->xoff, sq_ctx->cq_ena, sq_ctx->smq);
1967 
1968 	seq_printf(m, "W2: sqe_stype \t\t\t%d\nW2: sq_int_ena \t\t\t%d\n",
1969 		   sq_ctx->sqe_stype, sq_ctx->sq_int_ena);
1970 	seq_printf(m, "W2: sq_int \t\t\t%d\nW2: sqb_aura \t\t\t%d\n",
1971 		   sq_ctx->sq_int, sq_ctx->sqb_aura);
1972 	seq_printf(m, "W2: smq_rr_count \t\t%d\n\n", sq_ctx->smq_rr_count);
1973 
1974 	seq_printf(m, "W3: smq_next_sq_vld\t\t%d\nW3: smq_pend\t\t\t%d\n",
1975 		   sq_ctx->smq_next_sq_vld, sq_ctx->smq_pend);
1976 	seq_printf(m, "W3: smenq_next_sqb_vld \t\t%d\nW3: head_offset\t\t\t%d\n",
1977 		   sq_ctx->smenq_next_sqb_vld, sq_ctx->head_offset);
1978 	seq_printf(m, "W3: smenq_offset\t\t%d\nW3: tail_offset\t\t\t%d\n",
1979 		   sq_ctx->smenq_offset, sq_ctx->tail_offset);
1980 	seq_printf(m, "W3: smq_lso_segnum \t\t%d\nW3: smq_next_sq\t\t\t%d\n",
1981 		   sq_ctx->smq_lso_segnum, sq_ctx->smq_next_sq);
1982 	seq_printf(m, "W3: mnq_dis \t\t\t%d\nW3: lmt_dis \t\t\t%d\n",
1983 		   sq_ctx->mnq_dis, sq_ctx->lmt_dis);
1984 	seq_printf(m, "W3: cq_limit\t\t\t%d\nW3: max_sqe_size\t\t%d\n\n",
1985 		   sq_ctx->cq_limit, sq_ctx->max_sqe_size);
1986 
1987 	seq_printf(m, "W4: next_sqb \t\t\t%llx\n\n", sq_ctx->next_sqb);
1988 	seq_printf(m, "W5: tail_sqb \t\t\t%llx\n\n", sq_ctx->tail_sqb);
1989 	seq_printf(m, "W6: smenq_sqb \t\t\t%llx\n\n", sq_ctx->smenq_sqb);
1990 	seq_printf(m, "W7: smenq_next_sqb \t\t%llx\n\n",
1991 		   sq_ctx->smenq_next_sqb);
1992 
1993 	seq_printf(m, "W8: head_sqb\t\t\t%llx\n\n", sq_ctx->head_sqb);
1994 
1995 	seq_printf(m, "W9: vfi_lso_vld\t\t\t%d\nW9: vfi_lso_vlan1_ins_ena\t%d\n",
1996 		   sq_ctx->vfi_lso_vld, sq_ctx->vfi_lso_vlan1_ins_ena);
1997 	seq_printf(m, "W9: vfi_lso_vlan0_ins_ena\t%d\nW9: vfi_lso_mps\t\t\t%d\n",
1998 		   sq_ctx->vfi_lso_vlan0_ins_ena, sq_ctx->vfi_lso_mps);
1999 	seq_printf(m, "W9: vfi_lso_sb\t\t\t%d\nW9: vfi_lso_sizem1\t\t%d\n",
2000 		   sq_ctx->vfi_lso_sb, sq_ctx->vfi_lso_sizem1);
2001 	seq_printf(m, "W9: vfi_lso_total\t\t%d\n\n", sq_ctx->vfi_lso_total);
2002 
2003 	seq_printf(m, "W10: scm_lso_rem \t\t%llu\n\n",
2004 		   (u64)sq_ctx->scm_lso_rem);
2005 	seq_printf(m, "W11: octs \t\t\t%llu\n\n", (u64)sq_ctx->octs);
2006 	seq_printf(m, "W12: pkts \t\t\t%llu\n\n", (u64)sq_ctx->pkts);
2007 	seq_printf(m, "W14: dropped_octs \t\t%llu\n\n",
2008 		   (u64)sq_ctx->dropped_octs);
2009 	seq_printf(m, "W15: dropped_pkts \t\t%llu\n\n",
2010 		   (u64)sq_ctx->dropped_pkts);
2011 }
2012 
print_nix_cn10k_rq_ctx(struct seq_file * m,struct nix_cn10k_rq_ctx_s * rq_ctx)2013 static void print_nix_cn10k_rq_ctx(struct seq_file *m,
2014 				   struct nix_cn10k_rq_ctx_s *rq_ctx)
2015 {
2016 	seq_printf(m, "W0: ena \t\t\t%d\nW0: sso_ena \t\t\t%d\n",
2017 		   rq_ctx->ena, rq_ctx->sso_ena);
2018 	seq_printf(m, "W0: ipsech_ena \t\t\t%d\nW0: ena_wqwd \t\t\t%d\n",
2019 		   rq_ctx->ipsech_ena, rq_ctx->ena_wqwd);
2020 	seq_printf(m, "W0: cq \t\t\t\t%d\nW0: lenerr_dis \t\t\t%d\n",
2021 		   rq_ctx->cq, rq_ctx->lenerr_dis);
2022 	seq_printf(m, "W0: csum_il4_dis \t\t%d\nW0: csum_ol4_dis \t\t%d\n",
2023 		   rq_ctx->csum_il4_dis, rq_ctx->csum_ol4_dis);
2024 	seq_printf(m, "W0: len_il4_dis \t\t%d\nW0: len_il3_dis \t\t%d\n",
2025 		   rq_ctx->len_il4_dis, rq_ctx->len_il3_dis);
2026 	seq_printf(m, "W0: len_ol4_dis \t\t%d\nW0: len_ol3_dis \t\t%d\n",
2027 		   rq_ctx->len_ol4_dis, rq_ctx->len_ol3_dis);
2028 	seq_printf(m, "W0: wqe_aura \t\t\t%d\n\n", rq_ctx->wqe_aura);
2029 
2030 	seq_printf(m, "W1: spb_aura \t\t\t%d\nW1: lpb_aura \t\t\t%d\n",
2031 		   rq_ctx->spb_aura, rq_ctx->lpb_aura);
2032 	seq_printf(m, "W1: spb_aura \t\t\t%d\n", rq_ctx->spb_aura);
2033 	seq_printf(m, "W1: sso_grp \t\t\t%d\nW1: sso_tt \t\t\t%d\n",
2034 		   rq_ctx->sso_grp, rq_ctx->sso_tt);
2035 	seq_printf(m, "W1: pb_caching \t\t\t%d\nW1: wqe_caching \t\t%d\n",
2036 		   rq_ctx->pb_caching, rq_ctx->wqe_caching);
2037 	seq_printf(m, "W1: xqe_drop_ena \t\t%d\nW1: spb_drop_ena \t\t%d\n",
2038 		   rq_ctx->xqe_drop_ena, rq_ctx->spb_drop_ena);
2039 	seq_printf(m, "W1: lpb_drop_ena \t\t%d\nW1: pb_stashing \t\t%d\n",
2040 		   rq_ctx->lpb_drop_ena, rq_ctx->pb_stashing);
2041 	seq_printf(m, "W1: ipsecd_drop_ena \t\t%d\nW1: chi_ena \t\t\t%d\n\n",
2042 		   rq_ctx->ipsecd_drop_ena, rq_ctx->chi_ena);
2043 
2044 	seq_printf(m, "W2: band_prof_id \t\t%d\n", rq_ctx->band_prof_id);
2045 	seq_printf(m, "W2: policer_ena \t\t%d\n", rq_ctx->policer_ena);
2046 	seq_printf(m, "W2: spb_sizem1 \t\t\t%d\n", rq_ctx->spb_sizem1);
2047 	seq_printf(m, "W2: wqe_skip \t\t\t%d\nW2: sqb_ena \t\t\t%d\n",
2048 		   rq_ctx->wqe_skip, rq_ctx->spb_ena);
2049 	seq_printf(m, "W2: lpb_size1 \t\t\t%d\nW2: first_skip \t\t\t%d\n",
2050 		   rq_ctx->lpb_sizem1, rq_ctx->first_skip);
2051 	seq_printf(m, "W2: later_skip\t\t\t%d\nW2: xqe_imm_size\t\t%d\n",
2052 		   rq_ctx->later_skip, rq_ctx->xqe_imm_size);
2053 	seq_printf(m, "W2: xqe_imm_copy \t\t%d\nW2: xqe_hdr_split \t\t%d\n\n",
2054 		   rq_ctx->xqe_imm_copy, rq_ctx->xqe_hdr_split);
2055 
2056 	seq_printf(m, "W3: xqe_drop \t\t\t%d\nW3: xqe_pass \t\t\t%d\n",
2057 		   rq_ctx->xqe_drop, rq_ctx->xqe_pass);
2058 	seq_printf(m, "W3: wqe_pool_drop \t\t%d\nW3: wqe_pool_pass \t\t%d\n",
2059 		   rq_ctx->wqe_pool_drop, rq_ctx->wqe_pool_pass);
2060 	seq_printf(m, "W3: spb_pool_drop \t\t%d\nW3: spb_pool_pass \t\t%d\n",
2061 		   rq_ctx->spb_pool_drop, rq_ctx->spb_pool_pass);
2062 	seq_printf(m, "W3: spb_aura_drop \t\t%d\nW3: spb_aura_pass \t\t%d\n\n",
2063 		   rq_ctx->spb_aura_pass, rq_ctx->spb_aura_drop);
2064 
2065 	seq_printf(m, "W4: lpb_aura_drop \t\t%d\nW3: lpb_aura_pass \t\t%d\n",
2066 		   rq_ctx->lpb_aura_pass, rq_ctx->lpb_aura_drop);
2067 	seq_printf(m, "W4: lpb_pool_drop \t\t%d\nW3: lpb_pool_pass \t\t%d\n",
2068 		   rq_ctx->lpb_pool_drop, rq_ctx->lpb_pool_pass);
2069 	seq_printf(m, "W4: rq_int \t\t\t%d\nW4: rq_int_ena\t\t\t%d\n",
2070 		   rq_ctx->rq_int, rq_ctx->rq_int_ena);
2071 	seq_printf(m, "W4: qint_idx \t\t\t%d\n\n", rq_ctx->qint_idx);
2072 
2073 	seq_printf(m, "W5: ltag \t\t\t%d\nW5: good_utag \t\t\t%d\n",
2074 		   rq_ctx->ltag, rq_ctx->good_utag);
2075 	seq_printf(m, "W5: bad_utag \t\t\t%d\nW5: flow_tagw \t\t\t%d\n",
2076 		   rq_ctx->bad_utag, rq_ctx->flow_tagw);
2077 	seq_printf(m, "W5: ipsec_vwqe \t\t\t%d\nW5: vwqe_ena \t\t\t%d\n",
2078 		   rq_ctx->ipsec_vwqe, rq_ctx->vwqe_ena);
2079 	seq_printf(m, "W5: vwqe_wait \t\t\t%d\nW5: max_vsize_exp\t\t%d\n",
2080 		   rq_ctx->vwqe_wait, rq_ctx->max_vsize_exp);
2081 	seq_printf(m, "W5: vwqe_skip \t\t\t%d\n\n", rq_ctx->vwqe_skip);
2082 
2083 	seq_printf(m, "W6: octs \t\t\t%llu\n\n", (u64)rq_ctx->octs);
2084 	seq_printf(m, "W7: pkts \t\t\t%llu\n\n", (u64)rq_ctx->pkts);
2085 	seq_printf(m, "W8: drop_octs \t\t\t%llu\n\n", (u64)rq_ctx->drop_octs);
2086 	seq_printf(m, "W9: drop_pkts \t\t\t%llu\n\n", (u64)rq_ctx->drop_pkts);
2087 	seq_printf(m, "W10: re_pkts \t\t\t%llu\n", (u64)rq_ctx->re_pkts);
2088 }
2089 
2090 /* Dumps given nix_rq's context */
print_nix_rq_ctx(struct seq_file * m,struct nix_aq_enq_rsp * rsp)2091 static void print_nix_rq_ctx(struct seq_file *m, struct nix_aq_enq_rsp *rsp)
2092 {
2093 	struct nix_rq_ctx_s *rq_ctx = &rsp->rq;
2094 	struct nix_hw *nix_hw = m->private;
2095 	struct rvu *rvu = nix_hw->rvu;
2096 
2097 	if (!is_rvu_otx2(rvu)) {
2098 		print_nix_cn10k_rq_ctx(m, (struct nix_cn10k_rq_ctx_s *)rq_ctx);
2099 		return;
2100 	}
2101 
2102 	seq_printf(m, "W0: wqe_aura \t\t\t%d\nW0: substream \t\t\t0x%03x\n",
2103 		   rq_ctx->wqe_aura, rq_ctx->substream);
2104 	seq_printf(m, "W0: cq \t\t\t\t%d\nW0: ena_wqwd \t\t\t%d\n",
2105 		   rq_ctx->cq, rq_ctx->ena_wqwd);
2106 	seq_printf(m, "W0: ipsech_ena \t\t\t%d\nW0: sso_ena \t\t\t%d\n",
2107 		   rq_ctx->ipsech_ena, rq_ctx->sso_ena);
2108 	seq_printf(m, "W0: ena \t\t\t%d\n\n", rq_ctx->ena);
2109 
2110 	seq_printf(m, "W1: lpb_drop_ena \t\t%d\nW1: spb_drop_ena \t\t%d\n",
2111 		   rq_ctx->lpb_drop_ena, rq_ctx->spb_drop_ena);
2112 	seq_printf(m, "W1: xqe_drop_ena \t\t%d\nW1: wqe_caching \t\t%d\n",
2113 		   rq_ctx->xqe_drop_ena, rq_ctx->wqe_caching);
2114 	seq_printf(m, "W1: pb_caching \t\t\t%d\nW1: sso_tt \t\t\t%d\n",
2115 		   rq_ctx->pb_caching, rq_ctx->sso_tt);
2116 	seq_printf(m, "W1: sso_grp \t\t\t%d\nW1: lpb_aura \t\t\t%d\n",
2117 		   rq_ctx->sso_grp, rq_ctx->lpb_aura);
2118 	seq_printf(m, "W1: spb_aura \t\t\t%d\n\n", rq_ctx->spb_aura);
2119 
2120 	seq_printf(m, "W2: xqe_hdr_split \t\t%d\nW2: xqe_imm_copy \t\t%d\n",
2121 		   rq_ctx->xqe_hdr_split, rq_ctx->xqe_imm_copy);
2122 	seq_printf(m, "W2: xqe_imm_size \t\t%d\nW2: later_skip \t\t\t%d\n",
2123 		   rq_ctx->xqe_imm_size, rq_ctx->later_skip);
2124 	seq_printf(m, "W2: first_skip \t\t\t%d\nW2: lpb_sizem1 \t\t\t%d\n",
2125 		   rq_ctx->first_skip, rq_ctx->lpb_sizem1);
2126 	seq_printf(m, "W2: spb_ena \t\t\t%d\nW2: wqe_skip \t\t\t%d\n",
2127 		   rq_ctx->spb_ena, rq_ctx->wqe_skip);
2128 	seq_printf(m, "W2: spb_sizem1 \t\t\t%d\n\n", rq_ctx->spb_sizem1);
2129 
2130 	seq_printf(m, "W3: spb_pool_pass \t\t%d\nW3: spb_pool_drop \t\t%d\n",
2131 		   rq_ctx->spb_pool_pass, rq_ctx->spb_pool_drop);
2132 	seq_printf(m, "W3: spb_aura_pass \t\t%d\nW3: spb_aura_drop \t\t%d\n",
2133 		   rq_ctx->spb_aura_pass, rq_ctx->spb_aura_drop);
2134 	seq_printf(m, "W3: wqe_pool_pass \t\t%d\nW3: wqe_pool_drop \t\t%d\n",
2135 		   rq_ctx->wqe_pool_pass, rq_ctx->wqe_pool_drop);
2136 	seq_printf(m, "W3: xqe_pass \t\t\t%d\nW3: xqe_drop \t\t\t%d\n\n",
2137 		   rq_ctx->xqe_pass, rq_ctx->xqe_drop);
2138 
2139 	seq_printf(m, "W4: qint_idx \t\t\t%d\nW4: rq_int_ena \t\t\t%d\n",
2140 		   rq_ctx->qint_idx, rq_ctx->rq_int_ena);
2141 	seq_printf(m, "W4: rq_int \t\t\t%d\nW4: lpb_pool_pass \t\t%d\n",
2142 		   rq_ctx->rq_int, rq_ctx->lpb_pool_pass);
2143 	seq_printf(m, "W4: lpb_pool_drop \t\t%d\nW4: lpb_aura_pass \t\t%d\n",
2144 		   rq_ctx->lpb_pool_drop, rq_ctx->lpb_aura_pass);
2145 	seq_printf(m, "W4: lpb_aura_drop \t\t%d\n\n", rq_ctx->lpb_aura_drop);
2146 
2147 	seq_printf(m, "W5: flow_tagw \t\t\t%d\nW5: bad_utag \t\t\t%d\n",
2148 		   rq_ctx->flow_tagw, rq_ctx->bad_utag);
2149 	seq_printf(m, "W5: good_utag \t\t\t%d\nW5: ltag \t\t\t%d\n\n",
2150 		   rq_ctx->good_utag, rq_ctx->ltag);
2151 
2152 	seq_printf(m, "W6: octs \t\t\t%llu\n\n", (u64)rq_ctx->octs);
2153 	seq_printf(m, "W7: pkts \t\t\t%llu\n\n", (u64)rq_ctx->pkts);
2154 	seq_printf(m, "W8: drop_octs \t\t\t%llu\n\n", (u64)rq_ctx->drop_octs);
2155 	seq_printf(m, "W9: drop_pkts \t\t\t%llu\n\n", (u64)rq_ctx->drop_pkts);
2156 	seq_printf(m, "W10: re_pkts \t\t\t%llu\n", (u64)rq_ctx->re_pkts);
2157 }
2158 
2159 /* Dumps given nix_cq's context */
print_nix_cq_ctx(struct seq_file * m,struct nix_aq_enq_rsp * rsp)2160 static void print_nix_cq_ctx(struct seq_file *m, struct nix_aq_enq_rsp *rsp)
2161 {
2162 	struct nix_cq_ctx_s *cq_ctx = &rsp->cq;
2163 	struct nix_hw *nix_hw = m->private;
2164 	struct rvu *rvu = nix_hw->rvu;
2165 
2166 	seq_printf(m, "W0: base \t\t\t%llx\n\n", cq_ctx->base);
2167 
2168 	seq_printf(m, "W1: wrptr \t\t\t%llx\n", (u64)cq_ctx->wrptr);
2169 	seq_printf(m, "W1: avg_con \t\t\t%d\nW1: cint_idx \t\t\t%d\n",
2170 		   cq_ctx->avg_con, cq_ctx->cint_idx);
2171 	seq_printf(m, "W1: cq_err \t\t\t%d\nW1: qint_idx \t\t\t%d\n",
2172 		   cq_ctx->cq_err, cq_ctx->qint_idx);
2173 	seq_printf(m, "W1: bpid \t\t\t%d\nW1: bp_ena \t\t\t%d\n\n",
2174 		   cq_ctx->bpid, cq_ctx->bp_ena);
2175 
2176 	if (!is_rvu_otx2(rvu)) {
2177 		seq_printf(m, "W1: lbpid_high \t\t\t0x%03x\n", cq_ctx->lbpid_high);
2178 		seq_printf(m, "W1: lbpid_med \t\t\t0x%03x\n", cq_ctx->lbpid_med);
2179 		seq_printf(m, "W1: lbpid_low \t\t\t0x%03x\n", cq_ctx->lbpid_low);
2180 		seq_printf(m, "(W1: lbpid) \t\t\t0x%03x\n",
2181 			   cq_ctx->lbpid_high << 6 | cq_ctx->lbpid_med << 3 |
2182 			   cq_ctx->lbpid_low);
2183 		seq_printf(m, "W1: lbp_ena \t\t\t\t%d\n\n", cq_ctx->lbp_ena);
2184 	}
2185 
2186 	seq_printf(m, "W2: update_time \t\t%d\nW2:avg_level \t\t\t%d\n",
2187 		   cq_ctx->update_time, cq_ctx->avg_level);
2188 	seq_printf(m, "W2: head \t\t\t%d\nW2:tail \t\t\t%d\n\n",
2189 		   cq_ctx->head, cq_ctx->tail);
2190 
2191 	seq_printf(m, "W3: cq_err_int_ena \t\t%d\nW3:cq_err_int \t\t\t%d\n",
2192 		   cq_ctx->cq_err_int_ena, cq_ctx->cq_err_int);
2193 	seq_printf(m, "W3: qsize \t\t\t%d\nW3:caching \t\t\t%d\n",
2194 		   cq_ctx->qsize, cq_ctx->caching);
2195 	seq_printf(m, "W3: substream \t\t\t0x%03x\nW3: ena \t\t\t%d\n",
2196 		   cq_ctx->substream, cq_ctx->ena);
2197 	if (!is_rvu_otx2(rvu)) {
2198 		seq_printf(m, "W3: lbp_frac \t\t\t%d\n", cq_ctx->lbp_frac);
2199 		seq_printf(m, "W3: cpt_drop_err_en \t\t\t%d\n",
2200 			   cq_ctx->cpt_drop_err_en);
2201 	}
2202 	seq_printf(m, "W3: drop_ena \t\t\t%d\nW3: drop \t\t\t%d\n",
2203 		   cq_ctx->drop_ena, cq_ctx->drop);
2204 	seq_printf(m, "W3: bp \t\t\t\t%d\n\n", cq_ctx->bp);
2205 }
2206 
rvu_dbg_nix_queue_ctx_display(struct seq_file * filp,void * unused,int ctype)2207 static int rvu_dbg_nix_queue_ctx_display(struct seq_file *filp,
2208 					 void *unused, int ctype)
2209 {
2210 	void (*print_nix_ctx)(struct seq_file *filp,
2211 			      struct nix_aq_enq_rsp *rsp) = NULL;
2212 	struct nix_hw *nix_hw = filp->private;
2213 	struct rvu *rvu = nix_hw->rvu;
2214 	struct nix_aq_enq_req aq_req;
2215 	struct nix_aq_enq_rsp rsp;
2216 	char *ctype_string = NULL;
2217 	int qidx, rc, max_id = 0;
2218 	struct rvu_pfvf *pfvf;
2219 	int nixlf, id, all;
2220 	u16 pcifunc;
2221 
2222 	switch (ctype) {
2223 	case NIX_AQ_CTYPE_CQ:
2224 		nixlf = rvu->rvu_dbg.nix_cq_ctx.lf;
2225 		id = rvu->rvu_dbg.nix_cq_ctx.id;
2226 		all = rvu->rvu_dbg.nix_cq_ctx.all;
2227 		break;
2228 
2229 	case NIX_AQ_CTYPE_SQ:
2230 		nixlf = rvu->rvu_dbg.nix_sq_ctx.lf;
2231 		id = rvu->rvu_dbg.nix_sq_ctx.id;
2232 		all = rvu->rvu_dbg.nix_sq_ctx.all;
2233 		break;
2234 
2235 	case NIX_AQ_CTYPE_RQ:
2236 		nixlf = rvu->rvu_dbg.nix_rq_ctx.lf;
2237 		id = rvu->rvu_dbg.nix_rq_ctx.id;
2238 		all = rvu->rvu_dbg.nix_rq_ctx.all;
2239 		break;
2240 
2241 	default:
2242 		return -EINVAL;
2243 	}
2244 
2245 	if (!rvu_dbg_is_valid_lf(rvu, nix_hw->blkaddr, nixlf, &pcifunc))
2246 		return -EINVAL;
2247 
2248 	pfvf = rvu_get_pfvf(rvu, pcifunc);
2249 	if (ctype == NIX_AQ_CTYPE_SQ && !pfvf->sq_ctx) {
2250 		seq_puts(filp, "SQ context is not initialized\n");
2251 		return -EINVAL;
2252 	} else if (ctype == NIX_AQ_CTYPE_RQ && !pfvf->rq_ctx) {
2253 		seq_puts(filp, "RQ context is not initialized\n");
2254 		return -EINVAL;
2255 	} else if (ctype == NIX_AQ_CTYPE_CQ && !pfvf->cq_ctx) {
2256 		seq_puts(filp, "CQ context is not initialized\n");
2257 		return -EINVAL;
2258 	}
2259 
2260 	if (ctype == NIX_AQ_CTYPE_SQ) {
2261 		max_id = pfvf->sq_ctx->qsize;
2262 		ctype_string = "sq";
2263 		print_nix_ctx = print_nix_sq_ctx;
2264 	} else if (ctype == NIX_AQ_CTYPE_RQ) {
2265 		max_id = pfvf->rq_ctx->qsize;
2266 		ctype_string = "rq";
2267 		print_nix_ctx = print_nix_rq_ctx;
2268 	} else if (ctype == NIX_AQ_CTYPE_CQ) {
2269 		max_id = pfvf->cq_ctx->qsize;
2270 		ctype_string = "cq";
2271 		print_nix_ctx = print_nix_cq_ctx;
2272 	}
2273 
2274 	memset(&aq_req, 0, sizeof(struct nix_aq_enq_req));
2275 	aq_req.hdr.pcifunc = pcifunc;
2276 	aq_req.ctype = ctype;
2277 	aq_req.op = NIX_AQ_INSTOP_READ;
2278 	if (all)
2279 		id = 0;
2280 	else
2281 		max_id = id + 1;
2282 	for (qidx = id; qidx < max_id; qidx++) {
2283 		aq_req.qidx = qidx;
2284 		seq_printf(filp, "=====%s_ctx for nixlf:%d and qidx:%d is=====\n",
2285 			   ctype_string, nixlf, aq_req.qidx);
2286 		rc = rvu_mbox_handler_nix_aq_enq(rvu, &aq_req, &rsp);
2287 		if (rc) {
2288 			seq_puts(filp, "Failed to read the context\n");
2289 			return -EINVAL;
2290 		}
2291 		print_nix_ctx(filp, &rsp);
2292 	}
2293 	return 0;
2294 }
2295 
write_nix_queue_ctx(struct rvu * rvu,bool all,int nixlf,int id,int ctype,char * ctype_string,struct seq_file * m)2296 static int write_nix_queue_ctx(struct rvu *rvu, bool all, int nixlf,
2297 			       int id, int ctype, char *ctype_string,
2298 			       struct seq_file *m)
2299 {
2300 	struct nix_hw *nix_hw = m->private;
2301 	struct rvu_pfvf *pfvf;
2302 	int max_id = 0;
2303 	u16 pcifunc;
2304 
2305 	if (!rvu_dbg_is_valid_lf(rvu, nix_hw->blkaddr, nixlf, &pcifunc))
2306 		return -EINVAL;
2307 
2308 	pfvf = rvu_get_pfvf(rvu, pcifunc);
2309 
2310 	if (ctype == NIX_AQ_CTYPE_SQ) {
2311 		if (!pfvf->sq_ctx) {
2312 			dev_warn(rvu->dev, "SQ context is not initialized\n");
2313 			return -EINVAL;
2314 		}
2315 		max_id = pfvf->sq_ctx->qsize;
2316 	} else if (ctype == NIX_AQ_CTYPE_RQ) {
2317 		if (!pfvf->rq_ctx) {
2318 			dev_warn(rvu->dev, "RQ context is not initialized\n");
2319 			return -EINVAL;
2320 		}
2321 		max_id = pfvf->rq_ctx->qsize;
2322 	} else if (ctype == NIX_AQ_CTYPE_CQ) {
2323 		if (!pfvf->cq_ctx) {
2324 			dev_warn(rvu->dev, "CQ context is not initialized\n");
2325 			return -EINVAL;
2326 		}
2327 		max_id = pfvf->cq_ctx->qsize;
2328 	}
2329 
2330 	if (id < 0 || id >= max_id) {
2331 		dev_warn(rvu->dev, "Invalid %s_ctx valid range 0-%d\n",
2332 			 ctype_string, max_id - 1);
2333 		return -EINVAL;
2334 	}
2335 	switch (ctype) {
2336 	case NIX_AQ_CTYPE_CQ:
2337 		rvu->rvu_dbg.nix_cq_ctx.lf = nixlf;
2338 		rvu->rvu_dbg.nix_cq_ctx.id = id;
2339 		rvu->rvu_dbg.nix_cq_ctx.all = all;
2340 		break;
2341 
2342 	case NIX_AQ_CTYPE_SQ:
2343 		rvu->rvu_dbg.nix_sq_ctx.lf = nixlf;
2344 		rvu->rvu_dbg.nix_sq_ctx.id = id;
2345 		rvu->rvu_dbg.nix_sq_ctx.all = all;
2346 		break;
2347 
2348 	case NIX_AQ_CTYPE_RQ:
2349 		rvu->rvu_dbg.nix_rq_ctx.lf = nixlf;
2350 		rvu->rvu_dbg.nix_rq_ctx.id = id;
2351 		rvu->rvu_dbg.nix_rq_ctx.all = all;
2352 		break;
2353 	default:
2354 		return -EINVAL;
2355 	}
2356 	return 0;
2357 }
2358 
rvu_dbg_nix_queue_ctx_write(struct file * filp,const char __user * buffer,size_t count,loff_t * ppos,int ctype)2359 static ssize_t rvu_dbg_nix_queue_ctx_write(struct file *filp,
2360 					   const char __user *buffer,
2361 					   size_t count, loff_t *ppos,
2362 					   int ctype)
2363 {
2364 	struct seq_file *m = filp->private_data;
2365 	struct nix_hw *nix_hw = m->private;
2366 	struct rvu *rvu = nix_hw->rvu;
2367 	char *cmd_buf, *ctype_string;
2368 	int nixlf, id = 0, ret;
2369 	bool all = false;
2370 
2371 	if ((*ppos != 0) || !count)
2372 		return -EINVAL;
2373 
2374 	switch (ctype) {
2375 	case NIX_AQ_CTYPE_SQ:
2376 		ctype_string = "sq";
2377 		break;
2378 	case NIX_AQ_CTYPE_RQ:
2379 		ctype_string = "rq";
2380 		break;
2381 	case NIX_AQ_CTYPE_CQ:
2382 		ctype_string = "cq";
2383 		break;
2384 	default:
2385 		return -EINVAL;
2386 	}
2387 
2388 	cmd_buf = kzalloc(count + 1, GFP_KERNEL);
2389 
2390 	if (!cmd_buf)
2391 		return count;
2392 
2393 	ret = parse_cmd_buffer_ctx(cmd_buf, &count, buffer,
2394 				   &nixlf, &id, &all);
2395 	if (ret < 0) {
2396 		dev_info(rvu->dev,
2397 			 "Usage: echo <nixlf> [%s number/all] > %s_ctx\n",
2398 			 ctype_string, ctype_string);
2399 		goto done;
2400 	} else {
2401 		ret = write_nix_queue_ctx(rvu, all, nixlf, id, ctype,
2402 					  ctype_string, m);
2403 	}
2404 done:
2405 	kfree(cmd_buf);
2406 	return ret ? ret : count;
2407 }
2408 
rvu_dbg_nix_sq_ctx_write(struct file * filp,const char __user * buffer,size_t count,loff_t * ppos)2409 static ssize_t rvu_dbg_nix_sq_ctx_write(struct file *filp,
2410 					const char __user *buffer,
2411 					size_t count, loff_t *ppos)
2412 {
2413 	return rvu_dbg_nix_queue_ctx_write(filp, buffer, count, ppos,
2414 					    NIX_AQ_CTYPE_SQ);
2415 }
2416 
rvu_dbg_nix_sq_ctx_display(struct seq_file * filp,void * unused)2417 static int rvu_dbg_nix_sq_ctx_display(struct seq_file *filp, void *unused)
2418 {
2419 	return rvu_dbg_nix_queue_ctx_display(filp, unused, NIX_AQ_CTYPE_SQ);
2420 }
2421 
2422 RVU_DEBUG_SEQ_FOPS(nix_sq_ctx, nix_sq_ctx_display, nix_sq_ctx_write);
2423 
rvu_dbg_nix_rq_ctx_write(struct file * filp,const char __user * buffer,size_t count,loff_t * ppos)2424 static ssize_t rvu_dbg_nix_rq_ctx_write(struct file *filp,
2425 					const char __user *buffer,
2426 					size_t count, loff_t *ppos)
2427 {
2428 	return rvu_dbg_nix_queue_ctx_write(filp, buffer, count, ppos,
2429 					    NIX_AQ_CTYPE_RQ);
2430 }
2431 
rvu_dbg_nix_rq_ctx_display(struct seq_file * filp,void * unused)2432 static int rvu_dbg_nix_rq_ctx_display(struct seq_file *filp, void  *unused)
2433 {
2434 	return rvu_dbg_nix_queue_ctx_display(filp, unused,  NIX_AQ_CTYPE_RQ);
2435 }
2436 
2437 RVU_DEBUG_SEQ_FOPS(nix_rq_ctx, nix_rq_ctx_display, nix_rq_ctx_write);
2438 
rvu_dbg_nix_cq_ctx_write(struct file * filp,const char __user * buffer,size_t count,loff_t * ppos)2439 static ssize_t rvu_dbg_nix_cq_ctx_write(struct file *filp,
2440 					const char __user *buffer,
2441 					size_t count, loff_t *ppos)
2442 {
2443 	return rvu_dbg_nix_queue_ctx_write(filp, buffer, count, ppos,
2444 					    NIX_AQ_CTYPE_CQ);
2445 }
2446 
rvu_dbg_nix_cq_ctx_display(struct seq_file * filp,void * unused)2447 static int rvu_dbg_nix_cq_ctx_display(struct seq_file *filp, void *unused)
2448 {
2449 	return rvu_dbg_nix_queue_ctx_display(filp, unused, NIX_AQ_CTYPE_CQ);
2450 }
2451 
2452 RVU_DEBUG_SEQ_FOPS(nix_cq_ctx, nix_cq_ctx_display, nix_cq_ctx_write);
2453 
print_nix_qctx_qsize(struct seq_file * filp,int qsize,unsigned long * bmap,char * qtype)2454 static void print_nix_qctx_qsize(struct seq_file *filp, int qsize,
2455 				 unsigned long *bmap, char *qtype)
2456 {
2457 	char *buf;
2458 
2459 	buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
2460 	if (!buf)
2461 		return;
2462 
2463 	bitmap_print_to_pagebuf(false, buf, bmap, qsize);
2464 	seq_printf(filp, "%s context count : %d\n", qtype, qsize);
2465 	seq_printf(filp, "%s context ena/dis bitmap : %s\n",
2466 		   qtype, buf);
2467 	kfree(buf);
2468 }
2469 
print_nix_qsize(struct seq_file * filp,struct rvu_pfvf * pfvf)2470 static void print_nix_qsize(struct seq_file *filp, struct rvu_pfvf *pfvf)
2471 {
2472 	if (!pfvf->cq_ctx)
2473 		seq_puts(filp, "cq context is not initialized\n");
2474 	else
2475 		print_nix_qctx_qsize(filp, pfvf->cq_ctx->qsize, pfvf->cq_bmap,
2476 				     "cq");
2477 
2478 	if (!pfvf->rq_ctx)
2479 		seq_puts(filp, "rq context is not initialized\n");
2480 	else
2481 		print_nix_qctx_qsize(filp, pfvf->rq_ctx->qsize, pfvf->rq_bmap,
2482 				     "rq");
2483 
2484 	if (!pfvf->sq_ctx)
2485 		seq_puts(filp, "sq context is not initialized\n");
2486 	else
2487 		print_nix_qctx_qsize(filp, pfvf->sq_ctx->qsize, pfvf->sq_bmap,
2488 				     "sq");
2489 }
2490 
rvu_dbg_nix_qsize_write(struct file * filp,const char __user * buffer,size_t count,loff_t * ppos)2491 static ssize_t rvu_dbg_nix_qsize_write(struct file *filp,
2492 				       const char __user *buffer,
2493 				       size_t count, loff_t *ppos)
2494 {
2495 	return rvu_dbg_qsize_write(filp, buffer, count, ppos,
2496 				   BLKTYPE_NIX);
2497 }
2498 
rvu_dbg_nix_qsize_display(struct seq_file * filp,void * unused)2499 static int rvu_dbg_nix_qsize_display(struct seq_file *filp, void *unused)
2500 {
2501 	return rvu_dbg_qsize_display(filp, unused, BLKTYPE_NIX);
2502 }
2503 
2504 RVU_DEBUG_SEQ_FOPS(nix_qsize, nix_qsize_display, nix_qsize_write);
2505 
print_band_prof_ctx(struct seq_file * m,struct nix_bandprof_s * prof)2506 static void print_band_prof_ctx(struct seq_file *m,
2507 				struct nix_bandprof_s *prof)
2508 {
2509 	char *str;
2510 
2511 	switch (prof->pc_mode) {
2512 	case NIX_RX_PC_MODE_VLAN:
2513 		str = "VLAN";
2514 		break;
2515 	case NIX_RX_PC_MODE_DSCP:
2516 		str = "DSCP";
2517 		break;
2518 	case NIX_RX_PC_MODE_GEN:
2519 		str = "Generic";
2520 		break;
2521 	case NIX_RX_PC_MODE_RSVD:
2522 		str = "Reserved";
2523 		break;
2524 	}
2525 	seq_printf(m, "W0: pc_mode\t\t%s\n", str);
2526 	str = (prof->icolor == 3) ? "Color blind" :
2527 		(prof->icolor == 0) ? "Green" :
2528 		(prof->icolor == 1) ? "Yellow" : "Red";
2529 	seq_printf(m, "W0: icolor\t\t%s\n", str);
2530 	seq_printf(m, "W0: tnl_ena\t\t%d\n", prof->tnl_ena);
2531 	seq_printf(m, "W0: peir_exponent\t%d\n", prof->peir_exponent);
2532 	seq_printf(m, "W0: pebs_exponent\t%d\n", prof->pebs_exponent);
2533 	seq_printf(m, "W0: cir_exponent\t%d\n", prof->cir_exponent);
2534 	seq_printf(m, "W0: cbs_exponent\t%d\n", prof->cbs_exponent);
2535 	seq_printf(m, "W0: peir_mantissa\t%d\n", prof->peir_mantissa);
2536 	seq_printf(m, "W0: pebs_mantissa\t%d\n", prof->pebs_mantissa);
2537 	seq_printf(m, "W0: cir_mantissa\t%d\n", prof->cir_mantissa);
2538 
2539 	seq_printf(m, "W1: cbs_mantissa\t%d\n", prof->cbs_mantissa);
2540 	str = (prof->lmode == 0) ? "byte" : "packet";
2541 	seq_printf(m, "W1: lmode\t\t%s\n", str);
2542 	seq_printf(m, "W1: l_select\t\t%d\n", prof->l_sellect);
2543 	seq_printf(m, "W1: rdiv\t\t%d\n", prof->rdiv);
2544 	seq_printf(m, "W1: adjust_exponent\t%d\n", prof->adjust_exponent);
2545 	seq_printf(m, "W1: adjust_mantissa\t%d\n", prof->adjust_mantissa);
2546 	str = (prof->gc_action == 0) ? "PASS" :
2547 		(prof->gc_action == 1) ? "DROP" : "RED";
2548 	seq_printf(m, "W1: gc_action\t\t%s\n", str);
2549 	str = (prof->yc_action == 0) ? "PASS" :
2550 		(prof->yc_action == 1) ? "DROP" : "RED";
2551 	seq_printf(m, "W1: yc_action\t\t%s\n", str);
2552 	str = (prof->rc_action == 0) ? "PASS" :
2553 		(prof->rc_action == 1) ? "DROP" : "RED";
2554 	seq_printf(m, "W1: rc_action\t\t%s\n", str);
2555 	seq_printf(m, "W1: meter_algo\t\t%d\n", prof->meter_algo);
2556 	seq_printf(m, "W1: band_prof_id\t%d\n", prof->band_prof_id);
2557 	seq_printf(m, "W1: hl_en\t\t%d\n", prof->hl_en);
2558 
2559 	seq_printf(m, "W2: ts\t\t\t%lld\n", (u64)prof->ts);
2560 	seq_printf(m, "W3: pe_accum\t\t%d\n", prof->pe_accum);
2561 	seq_printf(m, "W3: c_accum\t\t%d\n", prof->c_accum);
2562 	seq_printf(m, "W4: green_pkt_pass\t%lld\n",
2563 		   (u64)prof->green_pkt_pass);
2564 	seq_printf(m, "W5: yellow_pkt_pass\t%lld\n",
2565 		   (u64)prof->yellow_pkt_pass);
2566 	seq_printf(m, "W6: red_pkt_pass\t%lld\n", (u64)prof->red_pkt_pass);
2567 	seq_printf(m, "W7: green_octs_pass\t%lld\n",
2568 		   (u64)prof->green_octs_pass);
2569 	seq_printf(m, "W8: yellow_octs_pass\t%lld\n",
2570 		   (u64)prof->yellow_octs_pass);
2571 	seq_printf(m, "W9: red_octs_pass\t%lld\n", (u64)prof->red_octs_pass);
2572 	seq_printf(m, "W10: green_pkt_drop\t%lld\n",
2573 		   (u64)prof->green_pkt_drop);
2574 	seq_printf(m, "W11: yellow_pkt_drop\t%lld\n",
2575 		   (u64)prof->yellow_pkt_drop);
2576 	seq_printf(m, "W12: red_pkt_drop\t%lld\n", (u64)prof->red_pkt_drop);
2577 	seq_printf(m, "W13: green_octs_drop\t%lld\n",
2578 		   (u64)prof->green_octs_drop);
2579 	seq_printf(m, "W14: yellow_octs_drop\t%lld\n",
2580 		   (u64)prof->yellow_octs_drop);
2581 	seq_printf(m, "W15: red_octs_drop\t%lld\n", (u64)prof->red_octs_drop);
2582 	seq_puts(m, "==============================\n");
2583 }
2584 
rvu_dbg_nix_band_prof_ctx_display(struct seq_file * m,void * unused)2585 static int rvu_dbg_nix_band_prof_ctx_display(struct seq_file *m, void *unused)
2586 {
2587 	struct nix_hw *nix_hw = m->private;
2588 	struct nix_cn10k_aq_enq_req aq_req;
2589 	struct nix_cn10k_aq_enq_rsp aq_rsp;
2590 	struct rvu *rvu = nix_hw->rvu;
2591 	struct nix_ipolicer *ipolicer;
2592 	int layer, prof_idx, idx, rc;
2593 	u16 pcifunc;
2594 	char *str;
2595 
2596 	/* Ingress policers do not exist on all platforms */
2597 	if (!nix_hw->ipolicer)
2598 		return 0;
2599 
2600 	for (layer = 0; layer < BAND_PROF_NUM_LAYERS; layer++) {
2601 		if (layer == BAND_PROF_INVAL_LAYER)
2602 			continue;
2603 		str = (layer == BAND_PROF_LEAF_LAYER) ? "Leaf" :
2604 			(layer == BAND_PROF_MID_LAYER) ? "Mid" : "Top";
2605 
2606 		seq_printf(m, "\n%s bandwidth profiles\n", str);
2607 		seq_puts(m, "=======================\n");
2608 
2609 		ipolicer = &nix_hw->ipolicer[layer];
2610 
2611 		for (idx = 0; idx < ipolicer->band_prof.max; idx++) {
2612 			if (is_rsrc_free(&ipolicer->band_prof, idx))
2613 				continue;
2614 
2615 			prof_idx = (idx & 0x3FFF) | (layer << 14);
2616 			rc = nix_aq_context_read(rvu, nix_hw, &aq_req, &aq_rsp,
2617 						 0x00, NIX_AQ_CTYPE_BANDPROF,
2618 						 prof_idx);
2619 			if (rc) {
2620 				dev_err(rvu->dev,
2621 					"%s: Failed to fetch context of %s profile %d, err %d\n",
2622 					__func__, str, idx, rc);
2623 				return 0;
2624 			}
2625 			seq_printf(m, "\n%s bandwidth profile:: %d\n", str, idx);
2626 			pcifunc = ipolicer->pfvf_map[idx];
2627 			if (!(pcifunc & RVU_PFVF_FUNC_MASK))
2628 				seq_printf(m, "Allocated to :: PF %d\n",
2629 					   rvu_get_pf(pcifunc));
2630 			else
2631 				seq_printf(m, "Allocated to :: PF %d VF %d\n",
2632 					   rvu_get_pf(pcifunc),
2633 					   (pcifunc & RVU_PFVF_FUNC_MASK) - 1);
2634 			print_band_prof_ctx(m, &aq_rsp.prof);
2635 		}
2636 	}
2637 	return 0;
2638 }
2639 
2640 RVU_DEBUG_SEQ_FOPS(nix_band_prof_ctx, nix_band_prof_ctx_display, NULL);
2641 
rvu_dbg_nix_band_prof_rsrc_display(struct seq_file * m,void * unused)2642 static int rvu_dbg_nix_band_prof_rsrc_display(struct seq_file *m, void *unused)
2643 {
2644 	struct nix_hw *nix_hw = m->private;
2645 	struct nix_ipolicer *ipolicer;
2646 	int layer;
2647 	char *str;
2648 
2649 	/* Ingress policers do not exist on all platforms */
2650 	if (!nix_hw->ipolicer)
2651 		return 0;
2652 
2653 	seq_puts(m, "\nBandwidth profile resource free count\n");
2654 	seq_puts(m, "=====================================\n");
2655 	for (layer = 0; layer < BAND_PROF_NUM_LAYERS; layer++) {
2656 		if (layer == BAND_PROF_INVAL_LAYER)
2657 			continue;
2658 		str = (layer == BAND_PROF_LEAF_LAYER) ? "Leaf" :
2659 			(layer == BAND_PROF_MID_LAYER) ? "Mid " : "Top ";
2660 
2661 		ipolicer = &nix_hw->ipolicer[layer];
2662 		seq_printf(m, "%s :: Max: %4d  Free: %4d\n", str,
2663 			   ipolicer->band_prof.max,
2664 			   rvu_rsrc_free_count(&ipolicer->band_prof));
2665 	}
2666 	seq_puts(m, "=====================================\n");
2667 
2668 	return 0;
2669 }
2670 
2671 RVU_DEBUG_SEQ_FOPS(nix_band_prof_rsrc, nix_band_prof_rsrc_display, NULL);
2672 
rvu_dbg_nix_init(struct rvu * rvu,int blkaddr)2673 static void rvu_dbg_nix_init(struct rvu *rvu, int blkaddr)
2674 {
2675 	struct nix_hw *nix_hw;
2676 
2677 	if (!is_block_implemented(rvu->hw, blkaddr))
2678 		return;
2679 
2680 	if (blkaddr == BLKADDR_NIX0) {
2681 		rvu->rvu_dbg.nix = debugfs_create_dir("nix", rvu->rvu_dbg.root);
2682 		nix_hw = &rvu->hw->nix[0];
2683 	} else {
2684 		rvu->rvu_dbg.nix = debugfs_create_dir("nix1",
2685 						      rvu->rvu_dbg.root);
2686 		nix_hw = &rvu->hw->nix[1];
2687 	}
2688 
2689 	debugfs_create_file("tm_tree", 0600, rvu->rvu_dbg.nix, nix_hw,
2690 			    &rvu_dbg_nix_tm_tree_fops);
2691 	debugfs_create_file("tm_topo", 0600, rvu->rvu_dbg.nix, nix_hw,
2692 			    &rvu_dbg_nix_tm_topo_fops);
2693 	debugfs_create_file("sq_ctx", 0600, rvu->rvu_dbg.nix, nix_hw,
2694 			    &rvu_dbg_nix_sq_ctx_fops);
2695 	debugfs_create_file("rq_ctx", 0600, rvu->rvu_dbg.nix, nix_hw,
2696 			    &rvu_dbg_nix_rq_ctx_fops);
2697 	debugfs_create_file("cq_ctx", 0600, rvu->rvu_dbg.nix, nix_hw,
2698 			    &rvu_dbg_nix_cq_ctx_fops);
2699 	debugfs_create_file("ndc_tx_cache", 0600, rvu->rvu_dbg.nix, nix_hw,
2700 			    &rvu_dbg_nix_ndc_tx_cache_fops);
2701 	debugfs_create_file("ndc_rx_cache", 0600, rvu->rvu_dbg.nix, nix_hw,
2702 			    &rvu_dbg_nix_ndc_rx_cache_fops);
2703 	debugfs_create_file("ndc_tx_hits_miss", 0600, rvu->rvu_dbg.nix, nix_hw,
2704 			    &rvu_dbg_nix_ndc_tx_hits_miss_fops);
2705 	debugfs_create_file("ndc_rx_hits_miss", 0600, rvu->rvu_dbg.nix, nix_hw,
2706 			    &rvu_dbg_nix_ndc_rx_hits_miss_fops);
2707 	debugfs_create_file("qsize", 0600, rvu->rvu_dbg.nix, rvu,
2708 			    &rvu_dbg_nix_qsize_fops);
2709 	debugfs_create_file("ingress_policer_ctx", 0600, rvu->rvu_dbg.nix, nix_hw,
2710 			    &rvu_dbg_nix_band_prof_ctx_fops);
2711 	debugfs_create_file("ingress_policer_rsrc", 0600, rvu->rvu_dbg.nix, nix_hw,
2712 			    &rvu_dbg_nix_band_prof_rsrc_fops);
2713 }
2714 
rvu_dbg_npa_init(struct rvu * rvu)2715 static void rvu_dbg_npa_init(struct rvu *rvu)
2716 {
2717 	rvu->rvu_dbg.npa = debugfs_create_dir("npa", rvu->rvu_dbg.root);
2718 
2719 	debugfs_create_file("qsize", 0600, rvu->rvu_dbg.npa, rvu,
2720 			    &rvu_dbg_npa_qsize_fops);
2721 	debugfs_create_file("aura_ctx", 0600, rvu->rvu_dbg.npa, rvu,
2722 			    &rvu_dbg_npa_aura_ctx_fops);
2723 	debugfs_create_file("pool_ctx", 0600, rvu->rvu_dbg.npa, rvu,
2724 			    &rvu_dbg_npa_pool_ctx_fops);
2725 	debugfs_create_file("ndc_cache", 0600, rvu->rvu_dbg.npa, rvu,
2726 			    &rvu_dbg_npa_ndc_cache_fops);
2727 	debugfs_create_file("ndc_hits_miss", 0600, rvu->rvu_dbg.npa, rvu,
2728 			    &rvu_dbg_npa_ndc_hits_miss_fops);
2729 }
2730 
2731 #define PRINT_CGX_CUML_NIXRX_STATUS(idx, name)				\
2732 	({								\
2733 		u64 cnt;						\
2734 		err = rvu_cgx_nix_cuml_stats(rvu, cgxd, lmac_id, (idx),	\
2735 					     NIX_STATS_RX, &(cnt));	\
2736 		if (!err)						\
2737 			seq_printf(s, "%s: %llu\n", name, cnt);		\
2738 		cnt;							\
2739 	})
2740 
2741 #define PRINT_CGX_CUML_NIXTX_STATUS(idx, name)			\
2742 	({								\
2743 		u64 cnt;						\
2744 		err = rvu_cgx_nix_cuml_stats(rvu, cgxd, lmac_id, (idx),	\
2745 					  NIX_STATS_TX, &(cnt));	\
2746 		if (!err)						\
2747 			seq_printf(s, "%s: %llu\n", name, cnt);		\
2748 		cnt;							\
2749 	})
2750 
cgx_print_stats(struct seq_file * s,int lmac_id)2751 static int cgx_print_stats(struct seq_file *s, int lmac_id)
2752 {
2753 	struct cgx_link_user_info linfo;
2754 	struct mac_ops *mac_ops;
2755 	void *cgxd = s->private;
2756 	u64 ucast, mcast, bcast;
2757 	int stat = 0, err = 0;
2758 	u64 tx_stat, rx_stat;
2759 	struct rvu *rvu;
2760 
2761 	rvu = pci_get_drvdata(pci_get_device(PCI_VENDOR_ID_CAVIUM,
2762 					     PCI_DEVID_OCTEONTX2_RVU_AF, NULL));
2763 	if (!rvu)
2764 		return -ENODEV;
2765 
2766 	mac_ops = get_mac_ops(cgxd);
2767 	/* There can be no CGX devices at all */
2768 	if (!mac_ops)
2769 		return 0;
2770 
2771 	/* Link status */
2772 	seq_puts(s, "\n=======Link Status======\n\n");
2773 	err = cgx_get_link_info(cgxd, lmac_id, &linfo);
2774 	if (err)
2775 		seq_puts(s, "Failed to read link status\n");
2776 	seq_printf(s, "\nLink is %s %d Mbps\n\n",
2777 		   linfo.link_up ? "UP" : "DOWN", linfo.speed);
2778 
2779 	/* Rx stats */
2780 	seq_printf(s, "\n=======NIX RX_STATS(%s port level)======\n\n",
2781 		   mac_ops->name);
2782 	ucast = PRINT_CGX_CUML_NIXRX_STATUS(RX_UCAST, "rx_ucast_frames");
2783 	if (err)
2784 		return err;
2785 	mcast = PRINT_CGX_CUML_NIXRX_STATUS(RX_MCAST, "rx_mcast_frames");
2786 	if (err)
2787 		return err;
2788 	bcast = PRINT_CGX_CUML_NIXRX_STATUS(RX_BCAST, "rx_bcast_frames");
2789 	if (err)
2790 		return err;
2791 	seq_printf(s, "rx_frames: %llu\n", ucast + mcast + bcast);
2792 	PRINT_CGX_CUML_NIXRX_STATUS(RX_OCTS, "rx_bytes");
2793 	if (err)
2794 		return err;
2795 	PRINT_CGX_CUML_NIXRX_STATUS(RX_DROP, "rx_drops");
2796 	if (err)
2797 		return err;
2798 	PRINT_CGX_CUML_NIXRX_STATUS(RX_ERR, "rx_errors");
2799 	if (err)
2800 		return err;
2801 
2802 	/* Tx stats */
2803 	seq_printf(s, "\n=======NIX TX_STATS(%s port level)======\n\n",
2804 		   mac_ops->name);
2805 	ucast = PRINT_CGX_CUML_NIXTX_STATUS(TX_UCAST, "tx_ucast_frames");
2806 	if (err)
2807 		return err;
2808 	mcast = PRINT_CGX_CUML_NIXTX_STATUS(TX_MCAST, "tx_mcast_frames");
2809 	if (err)
2810 		return err;
2811 	bcast = PRINT_CGX_CUML_NIXTX_STATUS(TX_BCAST, "tx_bcast_frames");
2812 	if (err)
2813 		return err;
2814 	seq_printf(s, "tx_frames: %llu\n", ucast + mcast + bcast);
2815 	PRINT_CGX_CUML_NIXTX_STATUS(TX_OCTS, "tx_bytes");
2816 	if (err)
2817 		return err;
2818 	PRINT_CGX_CUML_NIXTX_STATUS(TX_DROP, "tx_drops");
2819 	if (err)
2820 		return err;
2821 
2822 	/* Rx stats */
2823 	seq_printf(s, "\n=======%s RX_STATS======\n\n", mac_ops->name);
2824 	while (stat < mac_ops->rx_stats_cnt) {
2825 		err = mac_ops->mac_get_rx_stats(cgxd, lmac_id, stat, &rx_stat);
2826 		if (err)
2827 			return err;
2828 		if (is_rvu_otx2(rvu))
2829 			seq_printf(s, "%s: %llu\n", cgx_rx_stats_fields[stat],
2830 				   rx_stat);
2831 		else
2832 			seq_printf(s, "%s: %llu\n", rpm_rx_stats_fields[stat],
2833 				   rx_stat);
2834 		stat++;
2835 	}
2836 
2837 	/* Tx stats */
2838 	stat = 0;
2839 	seq_printf(s, "\n=======%s TX_STATS======\n\n", mac_ops->name);
2840 	while (stat < mac_ops->tx_stats_cnt) {
2841 		err = mac_ops->mac_get_tx_stats(cgxd, lmac_id, stat, &tx_stat);
2842 		if (err)
2843 			return err;
2844 
2845 		if (is_rvu_otx2(rvu))
2846 			seq_printf(s, "%s: %llu\n", cgx_tx_stats_fields[stat],
2847 				   tx_stat);
2848 		else
2849 			seq_printf(s, "%s: %llu\n", rpm_tx_stats_fields[stat],
2850 				   tx_stat);
2851 		stat++;
2852 	}
2853 
2854 	return err;
2855 }
2856 
rvu_dbg_derive_lmacid(struct seq_file * filp,int * lmac_id)2857 static int rvu_dbg_derive_lmacid(struct seq_file *filp, int *lmac_id)
2858 {
2859 	struct dentry *current_dir;
2860 	char *buf;
2861 
2862 	current_dir = filp->file->f_path.dentry->d_parent;
2863 	buf = strrchr(current_dir->d_name.name, 'c');
2864 	if (!buf)
2865 		return -EINVAL;
2866 
2867 	return kstrtoint(buf + 1, 10, lmac_id);
2868 }
2869 
rvu_dbg_cgx_stat_display(struct seq_file * filp,void * unused)2870 static int rvu_dbg_cgx_stat_display(struct seq_file *filp, void *unused)
2871 {
2872 	int lmac_id, err;
2873 
2874 	err = rvu_dbg_derive_lmacid(filp, &lmac_id);
2875 	if (!err)
2876 		return cgx_print_stats(filp, lmac_id);
2877 
2878 	return err;
2879 }
2880 
2881 RVU_DEBUG_SEQ_FOPS(cgx_stat, cgx_stat_display, NULL);
2882 
cgx_print_dmac_flt(struct seq_file * s,int lmac_id)2883 static int cgx_print_dmac_flt(struct seq_file *s, int lmac_id)
2884 {
2885 	struct pci_dev *pdev = NULL;
2886 	void *cgxd = s->private;
2887 	char *bcast, *mcast;
2888 	u16 index, domain;
2889 	u8 dmac[ETH_ALEN];
2890 	struct rvu *rvu;
2891 	u64 cfg, mac;
2892 	int pf;
2893 
2894 	rvu = pci_get_drvdata(pci_get_device(PCI_VENDOR_ID_CAVIUM,
2895 					     PCI_DEVID_OCTEONTX2_RVU_AF, NULL));
2896 	if (!rvu)
2897 		return -ENODEV;
2898 
2899 	pf = cgxlmac_to_pf(rvu, cgx_get_cgxid(cgxd), lmac_id);
2900 	domain = 2;
2901 
2902 	pdev = pci_get_domain_bus_and_slot(domain, pf + 1, 0);
2903 	if (!pdev)
2904 		return 0;
2905 
2906 	cfg = cgx_read_dmac_ctrl(cgxd, lmac_id);
2907 	bcast = cfg & CGX_DMAC_BCAST_MODE ? "ACCEPT" : "REJECT";
2908 	mcast = cfg & CGX_DMAC_MCAST_MODE ? "ACCEPT" : "REJECT";
2909 
2910 	seq_puts(s,
2911 		 "PCI dev       RVUPF   BROADCAST  MULTICAST  FILTER-MODE\n");
2912 	seq_printf(s, "%s  PF%d  %9s  %9s",
2913 		   dev_name(&pdev->dev), pf, bcast, mcast);
2914 	if (cfg & CGX_DMAC_CAM_ACCEPT)
2915 		seq_printf(s, "%12s\n\n", "UNICAST");
2916 	else
2917 		seq_printf(s, "%16s\n\n", "PROMISCUOUS");
2918 
2919 	seq_puts(s, "\nDMAC-INDEX  ADDRESS\n");
2920 
2921 	for (index = 0 ; index < 32 ; index++) {
2922 		cfg = cgx_read_dmac_entry(cgxd, index);
2923 		/* Display enabled dmac entries associated with current lmac */
2924 		if (lmac_id == FIELD_GET(CGX_DMAC_CAM_ENTRY_LMACID, cfg) &&
2925 		    FIELD_GET(CGX_DMAC_CAM_ADDR_ENABLE, cfg)) {
2926 			mac = FIELD_GET(CGX_RX_DMAC_ADR_MASK, cfg);
2927 			u64_to_ether_addr(mac, dmac);
2928 			seq_printf(s, "%7d     %pM\n", index, dmac);
2929 		}
2930 	}
2931 
2932 	pci_dev_put(pdev);
2933 	return 0;
2934 }
2935 
rvu_dbg_cgx_dmac_flt_display(struct seq_file * filp,void * unused)2936 static int rvu_dbg_cgx_dmac_flt_display(struct seq_file *filp, void *unused)
2937 {
2938 	int err, lmac_id;
2939 
2940 	err = rvu_dbg_derive_lmacid(filp, &lmac_id);
2941 	if (!err)
2942 		return cgx_print_dmac_flt(filp, lmac_id);
2943 
2944 	return err;
2945 }
2946 
2947 RVU_DEBUG_SEQ_FOPS(cgx_dmac_flt, cgx_dmac_flt_display, NULL);
2948 
rvu_dbg_cgx_init(struct rvu * rvu)2949 static void rvu_dbg_cgx_init(struct rvu *rvu)
2950 {
2951 	struct mac_ops *mac_ops;
2952 	unsigned long lmac_bmap;
2953 	int i, lmac_id;
2954 	char dname[20];
2955 	void *cgx;
2956 
2957 	if (!cgx_get_cgxcnt_max())
2958 		return;
2959 
2960 	mac_ops = get_mac_ops(rvu_first_cgx_pdata(rvu));
2961 	if (!mac_ops)
2962 		return;
2963 
2964 	rvu->rvu_dbg.cgx_root = debugfs_create_dir(mac_ops->name,
2965 						   rvu->rvu_dbg.root);
2966 
2967 	for (i = 0; i < cgx_get_cgxcnt_max(); i++) {
2968 		cgx = rvu_cgx_pdata(i, rvu);
2969 		if (!cgx)
2970 			continue;
2971 		lmac_bmap = cgx_get_lmac_bmap(cgx);
2972 		/* cgx debugfs dir */
2973 		sprintf(dname, "%s%d", mac_ops->name, i);
2974 		rvu->rvu_dbg.cgx = debugfs_create_dir(dname,
2975 						      rvu->rvu_dbg.cgx_root);
2976 
2977 		for_each_set_bit(lmac_id, &lmac_bmap, rvu->hw->lmac_per_cgx) {
2978 			/* lmac debugfs dir */
2979 			sprintf(dname, "lmac%d", lmac_id);
2980 			rvu->rvu_dbg.lmac =
2981 				debugfs_create_dir(dname, rvu->rvu_dbg.cgx);
2982 
2983 			debugfs_create_file("stats", 0600, rvu->rvu_dbg.lmac,
2984 					    cgx, &rvu_dbg_cgx_stat_fops);
2985 			debugfs_create_file("mac_filter", 0600,
2986 					    rvu->rvu_dbg.lmac, cgx,
2987 					    &rvu_dbg_cgx_dmac_flt_fops);
2988 		}
2989 	}
2990 }
2991 
2992 /* NPC debugfs APIs */
rvu_print_npc_mcam_info(struct seq_file * s,u16 pcifunc,int blkaddr)2993 static void rvu_print_npc_mcam_info(struct seq_file *s,
2994 				    u16 pcifunc, int blkaddr)
2995 {
2996 	struct rvu *rvu = s->private;
2997 	int entry_acnt, entry_ecnt;
2998 	int cntr_acnt, cntr_ecnt;
2999 
3000 	rvu_npc_get_mcam_entry_alloc_info(rvu, pcifunc, blkaddr,
3001 					  &entry_acnt, &entry_ecnt);
3002 	rvu_npc_get_mcam_counter_alloc_info(rvu, pcifunc, blkaddr,
3003 					    &cntr_acnt, &cntr_ecnt);
3004 	if (!entry_acnt && !cntr_acnt)
3005 		return;
3006 
3007 	if (!(pcifunc & RVU_PFVF_FUNC_MASK))
3008 		seq_printf(s, "\n\t\t Device \t\t: PF%d\n",
3009 			   rvu_get_pf(pcifunc));
3010 	else
3011 		seq_printf(s, "\n\t\t Device \t\t: PF%d VF%d\n",
3012 			   rvu_get_pf(pcifunc),
3013 			   (pcifunc & RVU_PFVF_FUNC_MASK) - 1);
3014 
3015 	if (entry_acnt) {
3016 		seq_printf(s, "\t\t Entries allocated \t: %d\n", entry_acnt);
3017 		seq_printf(s, "\t\t Entries enabled \t: %d\n", entry_ecnt);
3018 	}
3019 	if (cntr_acnt) {
3020 		seq_printf(s, "\t\t Counters allocated \t: %d\n", cntr_acnt);
3021 		seq_printf(s, "\t\t Counters enabled \t: %d\n", cntr_ecnt);
3022 	}
3023 }
3024 
rvu_dbg_npc_mcam_info_display(struct seq_file * filp,void * unsued)3025 static int rvu_dbg_npc_mcam_info_display(struct seq_file *filp, void *unsued)
3026 {
3027 	struct rvu *rvu = filp->private;
3028 	int pf, vf, numvfs, blkaddr;
3029 	struct npc_mcam *mcam;
3030 	u16 pcifunc, counters;
3031 	u64 cfg;
3032 
3033 	blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
3034 	if (blkaddr < 0)
3035 		return -ENODEV;
3036 
3037 	mcam = &rvu->hw->mcam;
3038 	counters = rvu->hw->npc_counters;
3039 
3040 	seq_puts(filp, "\nNPC MCAM info:\n");
3041 	/* MCAM keywidth on receive and transmit sides */
3042 	cfg = rvu_read64(rvu, blkaddr, NPC_AF_INTFX_KEX_CFG(NIX_INTF_RX));
3043 	cfg = (cfg >> 32) & 0x07;
3044 	seq_printf(filp, "\t\t RX keywidth \t: %s\n", (cfg == NPC_MCAM_KEY_X1) ?
3045 		   "112bits" : ((cfg == NPC_MCAM_KEY_X2) ?
3046 		   "224bits" : "448bits"));
3047 	cfg = rvu_read64(rvu, blkaddr, NPC_AF_INTFX_KEX_CFG(NIX_INTF_TX));
3048 	cfg = (cfg >> 32) & 0x07;
3049 	seq_printf(filp, "\t\t TX keywidth \t: %s\n", (cfg == NPC_MCAM_KEY_X1) ?
3050 		   "112bits" : ((cfg == NPC_MCAM_KEY_X2) ?
3051 		   "224bits" : "448bits"));
3052 
3053 	mutex_lock(&mcam->lock);
3054 	/* MCAM entries */
3055 	seq_printf(filp, "\n\t\t MCAM entries \t: %d\n", mcam->total_entries);
3056 	seq_printf(filp, "\t\t Reserved \t: %d\n",
3057 		   mcam->total_entries - mcam->bmap_entries);
3058 	seq_printf(filp, "\t\t Available \t: %d\n", mcam->bmap_fcnt);
3059 
3060 	/* MCAM counters */
3061 	seq_printf(filp, "\n\t\t MCAM counters \t: %d\n", counters);
3062 	seq_printf(filp, "\t\t Reserved \t: %d\n",
3063 		   counters - mcam->counters.max);
3064 	seq_printf(filp, "\t\t Available \t: %d\n",
3065 		   rvu_rsrc_free_count(&mcam->counters));
3066 
3067 	if (mcam->bmap_entries == mcam->bmap_fcnt) {
3068 		mutex_unlock(&mcam->lock);
3069 		return 0;
3070 	}
3071 
3072 	seq_puts(filp, "\n\t\t Current allocation\n");
3073 	seq_puts(filp, "\t\t====================\n");
3074 	for (pf = 0; pf < rvu->hw->total_pfs; pf++) {
3075 		pcifunc = (pf << RVU_PFVF_PF_SHIFT);
3076 		rvu_print_npc_mcam_info(filp, pcifunc, blkaddr);
3077 
3078 		cfg = rvu_read64(rvu, BLKADDR_RVUM, RVU_PRIV_PFX_CFG(pf));
3079 		numvfs = (cfg >> 12) & 0xFF;
3080 		for (vf = 0; vf < numvfs; vf++) {
3081 			pcifunc = (pf << RVU_PFVF_PF_SHIFT) | (vf + 1);
3082 			rvu_print_npc_mcam_info(filp, pcifunc, blkaddr);
3083 		}
3084 	}
3085 
3086 	mutex_unlock(&mcam->lock);
3087 	return 0;
3088 }
3089 
3090 RVU_DEBUG_SEQ_FOPS(npc_mcam_info, npc_mcam_info_display, NULL);
3091 
rvu_dbg_npc_rx_miss_stats_display(struct seq_file * filp,void * unused)3092 static int rvu_dbg_npc_rx_miss_stats_display(struct seq_file *filp,
3093 					     void *unused)
3094 {
3095 	struct rvu *rvu = filp->private;
3096 	struct npc_mcam *mcam;
3097 	int blkaddr;
3098 
3099 	blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
3100 	if (blkaddr < 0)
3101 		return -ENODEV;
3102 
3103 	mcam = &rvu->hw->mcam;
3104 
3105 	seq_puts(filp, "\nNPC MCAM RX miss action stats\n");
3106 	seq_printf(filp, "\t\tStat %d: \t%lld\n", mcam->rx_miss_act_cntr,
3107 		   rvu_read64(rvu, blkaddr,
3108 			      NPC_AF_MATCH_STATX(mcam->rx_miss_act_cntr)));
3109 
3110 	return 0;
3111 }
3112 
3113 RVU_DEBUG_SEQ_FOPS(npc_rx_miss_act, npc_rx_miss_stats_display, NULL);
3114 
3115 #define RVU_DBG_PRINT_MPLS_TTL(pkt, mask)                                     \
3116 do {									      \
3117 	seq_printf(s, "%ld ", FIELD_GET(OTX2_FLOWER_MASK_MPLS_TTL, pkt));     \
3118 	seq_printf(s, "mask 0x%lx\n",                                         \
3119 		   FIELD_GET(OTX2_FLOWER_MASK_MPLS_TTL, mask));               \
3120 } while (0)                                                                   \
3121 
3122 #define RVU_DBG_PRINT_MPLS_LBTCBOS(_pkt, _mask)                               \
3123 do {									      \
3124 	typeof(_pkt) (pkt) = (_pkt);					      \
3125 	typeof(_mask) (mask) = (_mask);                                       \
3126 	seq_printf(s, "%ld %ld %ld\n",                                        \
3127 		   FIELD_GET(OTX2_FLOWER_MASK_MPLS_LB, pkt),                  \
3128 		   FIELD_GET(OTX2_FLOWER_MASK_MPLS_TC, pkt),                  \
3129 		   FIELD_GET(OTX2_FLOWER_MASK_MPLS_BOS, pkt));                \
3130 	seq_printf(s, "\tmask 0x%lx 0x%lx 0x%lx\n",                           \
3131 		   FIELD_GET(OTX2_FLOWER_MASK_MPLS_LB, mask),                 \
3132 		   FIELD_GET(OTX2_FLOWER_MASK_MPLS_TC, mask),                 \
3133 		   FIELD_GET(OTX2_FLOWER_MASK_MPLS_BOS, mask));               \
3134 } while (0)                                                                   \
3135 
rvu_dbg_npc_mcam_show_flows(struct seq_file * s,struct rvu_npc_mcam_rule * rule)3136 static void rvu_dbg_npc_mcam_show_flows(struct seq_file *s,
3137 					struct rvu_npc_mcam_rule *rule)
3138 {
3139 	u8 bit;
3140 
3141 	for_each_set_bit(bit, (unsigned long *)&rule->features, 64) {
3142 		seq_printf(s, "\t%s  ", npc_get_field_name(bit));
3143 		switch (bit) {
3144 		case NPC_LXMB:
3145 			if (rule->lxmb == 1)
3146 				seq_puts(s, "\tL2M nibble is set\n");
3147 			else
3148 				seq_puts(s, "\tL2B nibble is set\n");
3149 			break;
3150 		case NPC_DMAC:
3151 			seq_printf(s, "%pM ", rule->packet.dmac);
3152 			seq_printf(s, "mask %pM\n", rule->mask.dmac);
3153 			break;
3154 		case NPC_SMAC:
3155 			seq_printf(s, "%pM ", rule->packet.smac);
3156 			seq_printf(s, "mask %pM\n", rule->mask.smac);
3157 			break;
3158 		case NPC_ETYPE:
3159 			seq_printf(s, "0x%x ", ntohs(rule->packet.etype));
3160 			seq_printf(s, "mask 0x%x\n", ntohs(rule->mask.etype));
3161 			break;
3162 		case NPC_OUTER_VID:
3163 			seq_printf(s, "0x%x ", ntohs(rule->packet.vlan_tci));
3164 			seq_printf(s, "mask 0x%x\n",
3165 				   ntohs(rule->mask.vlan_tci));
3166 			break;
3167 		case NPC_INNER_VID:
3168 			seq_printf(s, "0x%x ", ntohs(rule->packet.vlan_itci));
3169 			seq_printf(s, "mask 0x%x\n",
3170 				   ntohs(rule->mask.vlan_itci));
3171 			break;
3172 		case NPC_TOS:
3173 			seq_printf(s, "%d ", rule->packet.tos);
3174 			seq_printf(s, "mask 0x%x\n", rule->mask.tos);
3175 			break;
3176 		case NPC_SIP_IPV4:
3177 			seq_printf(s, "%pI4 ", &rule->packet.ip4src);
3178 			seq_printf(s, "mask %pI4\n", &rule->mask.ip4src);
3179 			break;
3180 		case NPC_DIP_IPV4:
3181 			seq_printf(s, "%pI4 ", &rule->packet.ip4dst);
3182 			seq_printf(s, "mask %pI4\n", &rule->mask.ip4dst);
3183 			break;
3184 		case NPC_SIP_IPV6:
3185 			seq_printf(s, "%pI6 ", rule->packet.ip6src);
3186 			seq_printf(s, "mask %pI6\n", rule->mask.ip6src);
3187 			break;
3188 		case NPC_DIP_IPV6:
3189 			seq_printf(s, "%pI6 ", rule->packet.ip6dst);
3190 			seq_printf(s, "mask %pI6\n", rule->mask.ip6dst);
3191 			break;
3192 		case NPC_IPFRAG_IPV6:
3193 			seq_printf(s, "0x%x ", rule->packet.next_header);
3194 			seq_printf(s, "mask 0x%x\n", rule->mask.next_header);
3195 			break;
3196 		case NPC_IPFRAG_IPV4:
3197 			seq_printf(s, "0x%x ", rule->packet.ip_flag);
3198 			seq_printf(s, "mask 0x%x\n", rule->mask.ip_flag);
3199 			break;
3200 		case NPC_SPORT_TCP:
3201 		case NPC_SPORT_UDP:
3202 		case NPC_SPORT_SCTP:
3203 			seq_printf(s, "%d ", ntohs(rule->packet.sport));
3204 			seq_printf(s, "mask 0x%x\n", ntohs(rule->mask.sport));
3205 			break;
3206 		case NPC_DPORT_TCP:
3207 		case NPC_DPORT_UDP:
3208 		case NPC_DPORT_SCTP:
3209 			seq_printf(s, "%d ", ntohs(rule->packet.dport));
3210 			seq_printf(s, "mask 0x%x\n", ntohs(rule->mask.dport));
3211 			break;
3212 		case NPC_TCP_FLAGS:
3213 			seq_printf(s, "%d ", rule->packet.tcp_flags);
3214 			seq_printf(s, "mask 0x%x\n", rule->mask.tcp_flags);
3215 			break;
3216 		case NPC_IPSEC_SPI:
3217 			seq_printf(s, "0x%x ", ntohl(rule->packet.spi));
3218 			seq_printf(s, "mask 0x%x\n", ntohl(rule->mask.spi));
3219 			break;
3220 		case NPC_MPLS1_LBTCBOS:
3221 			RVU_DBG_PRINT_MPLS_LBTCBOS(rule->packet.mpls_lse[0],
3222 						   rule->mask.mpls_lse[0]);
3223 			break;
3224 		case NPC_MPLS1_TTL:
3225 			RVU_DBG_PRINT_MPLS_TTL(rule->packet.mpls_lse[0],
3226 					       rule->mask.mpls_lse[0]);
3227 			break;
3228 		case NPC_MPLS2_LBTCBOS:
3229 			RVU_DBG_PRINT_MPLS_LBTCBOS(rule->packet.mpls_lse[1],
3230 						   rule->mask.mpls_lse[1]);
3231 			break;
3232 		case NPC_MPLS2_TTL:
3233 			RVU_DBG_PRINT_MPLS_TTL(rule->packet.mpls_lse[1],
3234 					       rule->mask.mpls_lse[1]);
3235 			break;
3236 		case NPC_MPLS3_LBTCBOS:
3237 			RVU_DBG_PRINT_MPLS_LBTCBOS(rule->packet.mpls_lse[2],
3238 						   rule->mask.mpls_lse[2]);
3239 			break;
3240 		case NPC_MPLS3_TTL:
3241 			RVU_DBG_PRINT_MPLS_TTL(rule->packet.mpls_lse[2],
3242 					       rule->mask.mpls_lse[2]);
3243 			break;
3244 		case NPC_MPLS4_LBTCBOS:
3245 			RVU_DBG_PRINT_MPLS_LBTCBOS(rule->packet.mpls_lse[3],
3246 						   rule->mask.mpls_lse[3]);
3247 			break;
3248 		case NPC_MPLS4_TTL:
3249 			RVU_DBG_PRINT_MPLS_TTL(rule->packet.mpls_lse[3],
3250 					       rule->mask.mpls_lse[3]);
3251 			break;
3252 		case NPC_TYPE_ICMP:
3253 			seq_printf(s, "%d ", rule->packet.icmp_type);
3254 			seq_printf(s, "mask 0x%x\n", rule->mask.icmp_type);
3255 			break;
3256 		case NPC_CODE_ICMP:
3257 			seq_printf(s, "%d ", rule->packet.icmp_code);
3258 			seq_printf(s, "mask 0x%x\n", rule->mask.icmp_code);
3259 			break;
3260 		default:
3261 			seq_puts(s, "\n");
3262 			break;
3263 		}
3264 	}
3265 }
3266 
rvu_dbg_npc_mcam_show_action(struct seq_file * s,struct rvu_npc_mcam_rule * rule)3267 static void rvu_dbg_npc_mcam_show_action(struct seq_file *s,
3268 					 struct rvu_npc_mcam_rule *rule)
3269 {
3270 	if (is_npc_intf_tx(rule->intf)) {
3271 		switch (rule->tx_action.op) {
3272 		case NIX_TX_ACTIONOP_DROP:
3273 			seq_puts(s, "\taction: Drop\n");
3274 			break;
3275 		case NIX_TX_ACTIONOP_UCAST_DEFAULT:
3276 			seq_puts(s, "\taction: Unicast to default channel\n");
3277 			break;
3278 		case NIX_TX_ACTIONOP_UCAST_CHAN:
3279 			seq_printf(s, "\taction: Unicast to channel %d\n",
3280 				   rule->tx_action.index);
3281 			break;
3282 		case NIX_TX_ACTIONOP_MCAST:
3283 			seq_puts(s, "\taction: Multicast\n");
3284 			break;
3285 		case NIX_TX_ACTIONOP_DROP_VIOL:
3286 			seq_puts(s, "\taction: Lockdown Violation Drop\n");
3287 			break;
3288 		default:
3289 			break;
3290 		}
3291 	} else {
3292 		switch (rule->rx_action.op) {
3293 		case NIX_RX_ACTIONOP_DROP:
3294 			seq_puts(s, "\taction: Drop\n");
3295 			break;
3296 		case NIX_RX_ACTIONOP_UCAST:
3297 			seq_printf(s, "\taction: Direct to queue %d\n",
3298 				   rule->rx_action.index);
3299 			break;
3300 		case NIX_RX_ACTIONOP_RSS:
3301 			seq_puts(s, "\taction: RSS\n");
3302 			break;
3303 		case NIX_RX_ACTIONOP_UCAST_IPSEC:
3304 			seq_puts(s, "\taction: Unicast ipsec\n");
3305 			break;
3306 		case NIX_RX_ACTIONOP_MCAST:
3307 			seq_puts(s, "\taction: Multicast\n");
3308 			break;
3309 		default:
3310 			break;
3311 		}
3312 	}
3313 }
3314 
rvu_dbg_get_intf_name(int intf)3315 static const char *rvu_dbg_get_intf_name(int intf)
3316 {
3317 	switch (intf) {
3318 	case NIX_INTFX_RX(0):
3319 		return "NIX0_RX";
3320 	case NIX_INTFX_RX(1):
3321 		return "NIX1_RX";
3322 	case NIX_INTFX_TX(0):
3323 		return "NIX0_TX";
3324 	case NIX_INTFX_TX(1):
3325 		return "NIX1_TX";
3326 	default:
3327 		break;
3328 	}
3329 
3330 	return "unknown";
3331 }
3332 
rvu_dbg_npc_mcam_show_rules(struct seq_file * s,void * unused)3333 static int rvu_dbg_npc_mcam_show_rules(struct seq_file *s, void *unused)
3334 {
3335 	struct rvu_npc_mcam_rule *iter;
3336 	struct rvu *rvu = s->private;
3337 	struct npc_mcam *mcam;
3338 	int pf, vf = -1;
3339 	bool enabled;
3340 	int blkaddr;
3341 	u16 target;
3342 	u64 hits;
3343 
3344 	blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
3345 	if (blkaddr < 0)
3346 		return 0;
3347 
3348 	mcam = &rvu->hw->mcam;
3349 
3350 	mutex_lock(&mcam->lock);
3351 	list_for_each_entry(iter, &mcam->mcam_rules, list) {
3352 		pf = (iter->owner >> RVU_PFVF_PF_SHIFT) & RVU_PFVF_PF_MASK;
3353 		seq_printf(s, "\n\tInstalled by: PF%d ", pf);
3354 
3355 		if (iter->owner & RVU_PFVF_FUNC_MASK) {
3356 			vf = (iter->owner & RVU_PFVF_FUNC_MASK) - 1;
3357 			seq_printf(s, "VF%d", vf);
3358 		}
3359 		seq_puts(s, "\n");
3360 
3361 		seq_printf(s, "\tdirection: %s\n", is_npc_intf_rx(iter->intf) ?
3362 						    "RX" : "TX");
3363 		seq_printf(s, "\tinterface: %s\n",
3364 			   rvu_dbg_get_intf_name(iter->intf));
3365 		seq_printf(s, "\tmcam entry: %d\n", iter->entry);
3366 
3367 		rvu_dbg_npc_mcam_show_flows(s, iter);
3368 		if (is_npc_intf_rx(iter->intf)) {
3369 			target = iter->rx_action.pf_func;
3370 			pf = (target >> RVU_PFVF_PF_SHIFT) & RVU_PFVF_PF_MASK;
3371 			seq_printf(s, "\tForward to: PF%d ", pf);
3372 
3373 			if (target & RVU_PFVF_FUNC_MASK) {
3374 				vf = (target & RVU_PFVF_FUNC_MASK) - 1;
3375 				seq_printf(s, "VF%d", vf);
3376 			}
3377 			seq_puts(s, "\n");
3378 			seq_printf(s, "\tchannel: 0x%x\n", iter->chan);
3379 			seq_printf(s, "\tchannel_mask: 0x%x\n", iter->chan_mask);
3380 		}
3381 
3382 		rvu_dbg_npc_mcam_show_action(s, iter);
3383 
3384 		enabled = is_mcam_entry_enabled(rvu, mcam, blkaddr, iter->entry);
3385 		seq_printf(s, "\tenabled: %s\n", enabled ? "yes" : "no");
3386 
3387 		if (!iter->has_cntr)
3388 			continue;
3389 		seq_printf(s, "\tcounter: %d\n", iter->cntr);
3390 
3391 		hits = rvu_read64(rvu, blkaddr, NPC_AF_MATCH_STATX(iter->cntr));
3392 		seq_printf(s, "\thits: %lld\n", hits);
3393 	}
3394 	mutex_unlock(&mcam->lock);
3395 
3396 	return 0;
3397 }
3398 
3399 RVU_DEBUG_SEQ_FOPS(npc_mcam_rules, npc_mcam_show_rules, NULL);
3400 
rvu_dbg_npc_exact_show_entries(struct seq_file * s,void * unused)3401 static int rvu_dbg_npc_exact_show_entries(struct seq_file *s, void *unused)
3402 {
3403 	struct npc_exact_table_entry *mem_entry[NPC_EXACT_TBL_MAX_WAYS] = { 0 };
3404 	struct npc_exact_table_entry *cam_entry;
3405 	struct npc_exact_table *table;
3406 	struct rvu *rvu = s->private;
3407 	int i, j;
3408 
3409 	u8 bitmap = 0;
3410 
3411 	table = rvu->hw->table;
3412 
3413 	mutex_lock(&table->lock);
3414 
3415 	/* Check if there is at least one entry in mem table */
3416 	if (!table->mem_tbl_entry_cnt)
3417 		goto dump_cam_table;
3418 
3419 	/* Print table headers */
3420 	seq_puts(s, "\n\tExact Match MEM Table\n");
3421 	seq_puts(s, "Index\t");
3422 
3423 	for (i = 0; i < table->mem_table.ways; i++) {
3424 		mem_entry[i] = list_first_entry_or_null(&table->lhead_mem_tbl_entry[i],
3425 							struct npc_exact_table_entry, list);
3426 
3427 		seq_printf(s, "Way-%d\t\t\t\t\t", i);
3428 	}
3429 
3430 	seq_puts(s, "\n");
3431 	for (i = 0; i < table->mem_table.ways; i++)
3432 		seq_puts(s, "\tChan  MAC                     \t");
3433 
3434 	seq_puts(s, "\n\n");
3435 
3436 	/* Print mem table entries */
3437 	for (i = 0; i < table->mem_table.depth; i++) {
3438 		bitmap = 0;
3439 		for (j = 0; j < table->mem_table.ways; j++) {
3440 			if (!mem_entry[j])
3441 				continue;
3442 
3443 			if (mem_entry[j]->index != i)
3444 				continue;
3445 
3446 			bitmap |= BIT(j);
3447 		}
3448 
3449 		/* No valid entries */
3450 		if (!bitmap)
3451 			continue;
3452 
3453 		seq_printf(s, "%d\t", i);
3454 		for (j = 0; j < table->mem_table.ways; j++) {
3455 			if (!(bitmap & BIT(j))) {
3456 				seq_puts(s, "nil\t\t\t\t\t");
3457 				continue;
3458 			}
3459 
3460 			seq_printf(s, "0x%x %pM\t\t\t", mem_entry[j]->chan,
3461 				   mem_entry[j]->mac);
3462 			mem_entry[j] = list_next_entry(mem_entry[j], list);
3463 		}
3464 		seq_puts(s, "\n");
3465 	}
3466 
3467 dump_cam_table:
3468 
3469 	if (!table->cam_tbl_entry_cnt)
3470 		goto done;
3471 
3472 	seq_puts(s, "\n\tExact Match CAM Table\n");
3473 	seq_puts(s, "index\tchan\tMAC\n");
3474 
3475 	/* Traverse cam table entries */
3476 	list_for_each_entry(cam_entry, &table->lhead_cam_tbl_entry, list) {
3477 		seq_printf(s, "%d\t0x%x\t%pM\n", cam_entry->index, cam_entry->chan,
3478 			   cam_entry->mac);
3479 	}
3480 
3481 done:
3482 	mutex_unlock(&table->lock);
3483 	return 0;
3484 }
3485 
3486 RVU_DEBUG_SEQ_FOPS(npc_exact_entries, npc_exact_show_entries, NULL);
3487 
rvu_dbg_npc_exact_show_info(struct seq_file * s,void * unused)3488 static int rvu_dbg_npc_exact_show_info(struct seq_file *s, void *unused)
3489 {
3490 	struct npc_exact_table *table;
3491 	struct rvu *rvu = s->private;
3492 	int i;
3493 
3494 	table = rvu->hw->table;
3495 
3496 	seq_puts(s, "\n\tExact Table Info\n");
3497 	seq_printf(s, "Exact Match Feature : %s\n",
3498 		   rvu->hw->cap.npc_exact_match_enabled ? "enabled" : "disable");
3499 	if (!rvu->hw->cap.npc_exact_match_enabled)
3500 		return 0;
3501 
3502 	seq_puts(s, "\nMCAM Index\tMAC Filter Rules Count\n");
3503 	for (i = 0; i < table->num_drop_rules; i++)
3504 		seq_printf(s, "%d\t\t%d\n", i, table->cnt_cmd_rules[i]);
3505 
3506 	seq_puts(s, "\nMcam Index\tPromisc Mode Status\n");
3507 	for (i = 0; i < table->num_drop_rules; i++)
3508 		seq_printf(s, "%d\t\t%s\n", i, table->promisc_mode[i] ? "on" : "off");
3509 
3510 	seq_puts(s, "\n\tMEM Table Info\n");
3511 	seq_printf(s, "Ways : %d\n", table->mem_table.ways);
3512 	seq_printf(s, "Depth : %d\n", table->mem_table.depth);
3513 	seq_printf(s, "Mask : 0x%llx\n", table->mem_table.mask);
3514 	seq_printf(s, "Hash Mask : 0x%x\n", table->mem_table.hash_mask);
3515 	seq_printf(s, "Hash Offset : 0x%x\n", table->mem_table.hash_offset);
3516 
3517 	seq_puts(s, "\n\tCAM Table Info\n");
3518 	seq_printf(s, "Depth : %d\n", table->cam_table.depth);
3519 
3520 	return 0;
3521 }
3522 
3523 RVU_DEBUG_SEQ_FOPS(npc_exact_info, npc_exact_show_info, NULL);
3524 
rvu_dbg_npc_exact_drop_cnt(struct seq_file * s,void * unused)3525 static int rvu_dbg_npc_exact_drop_cnt(struct seq_file *s, void *unused)
3526 {
3527 	struct npc_exact_table *table;
3528 	struct rvu *rvu = s->private;
3529 	struct npc_key_field *field;
3530 	u16 chan, pcifunc;
3531 	int blkaddr, i;
3532 	u64 cfg, cam1;
3533 	char *str;
3534 
3535 	blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
3536 	table = rvu->hw->table;
3537 
3538 	field = &rvu->hw->mcam.rx_key_fields[NPC_CHAN];
3539 
3540 	seq_puts(s, "\n\t Exact Hit on drop status\n");
3541 	seq_puts(s, "\npcifunc\tmcam_idx\tHits\tchan\tstatus\n");
3542 
3543 	for (i = 0; i < table->num_drop_rules; i++) {
3544 		pcifunc = rvu_npc_exact_drop_rule_to_pcifunc(rvu, i);
3545 		cfg = rvu_read64(rvu, blkaddr, NPC_AF_MCAMEX_BANKX_CFG(i, 0));
3546 
3547 		/* channel will be always in keyword 0 */
3548 		cam1 = rvu_read64(rvu, blkaddr,
3549 				  NPC_AF_MCAMEX_BANKX_CAMX_W0(i, 0, 1));
3550 		chan = field->kw_mask[0] & cam1;
3551 
3552 		str = (cfg & 1) ? "enabled" : "disabled";
3553 
3554 		seq_printf(s, "0x%x\t%d\t\t%llu\t0x%x\t%s\n", pcifunc, i,
3555 			   rvu_read64(rvu, blkaddr,
3556 				      NPC_AF_MATCH_STATX(table->counter_idx[i])),
3557 			   chan, str);
3558 	}
3559 
3560 	return 0;
3561 }
3562 
3563 RVU_DEBUG_SEQ_FOPS(npc_exact_drop_cnt, npc_exact_drop_cnt, NULL);
3564 
rvu_dbg_npc_init(struct rvu * rvu)3565 static void rvu_dbg_npc_init(struct rvu *rvu)
3566 {
3567 	rvu->rvu_dbg.npc = debugfs_create_dir("npc", rvu->rvu_dbg.root);
3568 
3569 	debugfs_create_file("mcam_info", 0444, rvu->rvu_dbg.npc, rvu,
3570 			    &rvu_dbg_npc_mcam_info_fops);
3571 	debugfs_create_file("mcam_rules", 0444, rvu->rvu_dbg.npc, rvu,
3572 			    &rvu_dbg_npc_mcam_rules_fops);
3573 
3574 	debugfs_create_file("rx_miss_act_stats", 0444, rvu->rvu_dbg.npc, rvu,
3575 			    &rvu_dbg_npc_rx_miss_act_fops);
3576 
3577 	if (!rvu->hw->cap.npc_exact_match_enabled)
3578 		return;
3579 
3580 	debugfs_create_file("exact_entries", 0444, rvu->rvu_dbg.npc, rvu,
3581 			    &rvu_dbg_npc_exact_entries_fops);
3582 
3583 	debugfs_create_file("exact_info", 0444, rvu->rvu_dbg.npc, rvu,
3584 			    &rvu_dbg_npc_exact_info_fops);
3585 
3586 	debugfs_create_file("exact_drop_cnt", 0444, rvu->rvu_dbg.npc, rvu,
3587 			    &rvu_dbg_npc_exact_drop_cnt_fops);
3588 
3589 }
3590 
cpt_eng_sts_display(struct seq_file * filp,u8 eng_type)3591 static int cpt_eng_sts_display(struct seq_file *filp, u8 eng_type)
3592 {
3593 	struct cpt_ctx *ctx = filp->private;
3594 	u64 busy_sts = 0, free_sts = 0;
3595 	u32 e_min = 0, e_max = 0, e, i;
3596 	u16 max_ses, max_ies, max_aes;
3597 	struct rvu *rvu = ctx->rvu;
3598 	int blkaddr = ctx->blkaddr;
3599 	u64 reg;
3600 
3601 	reg = rvu_read64(rvu, blkaddr, CPT_AF_CONSTANTS1);
3602 	max_ses = reg & 0xffff;
3603 	max_ies = (reg >> 16) & 0xffff;
3604 	max_aes = (reg >> 32) & 0xffff;
3605 
3606 	switch (eng_type) {
3607 	case CPT_AE_TYPE:
3608 		e_min = max_ses + max_ies;
3609 		e_max = max_ses + max_ies + max_aes;
3610 		break;
3611 	case CPT_SE_TYPE:
3612 		e_min = 0;
3613 		e_max = max_ses;
3614 		break;
3615 	case CPT_IE_TYPE:
3616 		e_min = max_ses;
3617 		e_max = max_ses + max_ies;
3618 		break;
3619 	default:
3620 		return -EINVAL;
3621 	}
3622 
3623 	for (e = e_min, i = 0; e < e_max; e++, i++) {
3624 		reg = rvu_read64(rvu, blkaddr, CPT_AF_EXEX_STS(e));
3625 		if (reg & 0x1)
3626 			busy_sts |= 1ULL << i;
3627 
3628 		if (reg & 0x2)
3629 			free_sts |= 1ULL << i;
3630 	}
3631 	seq_printf(filp, "FREE STS : 0x%016llx\n", free_sts);
3632 	seq_printf(filp, "BUSY STS : 0x%016llx\n", busy_sts);
3633 
3634 	return 0;
3635 }
3636 
rvu_dbg_cpt_ae_sts_display(struct seq_file * filp,void * unused)3637 static int rvu_dbg_cpt_ae_sts_display(struct seq_file *filp, void *unused)
3638 {
3639 	return cpt_eng_sts_display(filp, CPT_AE_TYPE);
3640 }
3641 
3642 RVU_DEBUG_SEQ_FOPS(cpt_ae_sts, cpt_ae_sts_display, NULL);
3643 
rvu_dbg_cpt_se_sts_display(struct seq_file * filp,void * unused)3644 static int rvu_dbg_cpt_se_sts_display(struct seq_file *filp, void *unused)
3645 {
3646 	return cpt_eng_sts_display(filp, CPT_SE_TYPE);
3647 }
3648 
3649 RVU_DEBUG_SEQ_FOPS(cpt_se_sts, cpt_se_sts_display, NULL);
3650 
rvu_dbg_cpt_ie_sts_display(struct seq_file * filp,void * unused)3651 static int rvu_dbg_cpt_ie_sts_display(struct seq_file *filp, void *unused)
3652 {
3653 	return cpt_eng_sts_display(filp, CPT_IE_TYPE);
3654 }
3655 
3656 RVU_DEBUG_SEQ_FOPS(cpt_ie_sts, cpt_ie_sts_display, NULL);
3657 
rvu_dbg_cpt_engines_info_display(struct seq_file * filp,void * unused)3658 static int rvu_dbg_cpt_engines_info_display(struct seq_file *filp, void *unused)
3659 {
3660 	struct cpt_ctx *ctx = filp->private;
3661 	u16 max_ses, max_ies, max_aes;
3662 	struct rvu *rvu = ctx->rvu;
3663 	int blkaddr = ctx->blkaddr;
3664 	u32 e_max, e;
3665 	u64 reg;
3666 
3667 	reg = rvu_read64(rvu, blkaddr, CPT_AF_CONSTANTS1);
3668 	max_ses = reg & 0xffff;
3669 	max_ies = (reg >> 16) & 0xffff;
3670 	max_aes = (reg >> 32) & 0xffff;
3671 
3672 	e_max = max_ses + max_ies + max_aes;
3673 
3674 	seq_puts(filp, "===========================================\n");
3675 	for (e = 0; e < e_max; e++) {
3676 		reg = rvu_read64(rvu, blkaddr, CPT_AF_EXEX_CTL2(e));
3677 		seq_printf(filp, "CPT Engine[%u] Group Enable   0x%02llx\n", e,
3678 			   reg & 0xff);
3679 		reg = rvu_read64(rvu, blkaddr, CPT_AF_EXEX_ACTIVE(e));
3680 		seq_printf(filp, "CPT Engine[%u] Active Info    0x%llx\n", e,
3681 			   reg);
3682 		reg = rvu_read64(rvu, blkaddr, CPT_AF_EXEX_CTL(e));
3683 		seq_printf(filp, "CPT Engine[%u] Control        0x%llx\n", e,
3684 			   reg);
3685 		seq_puts(filp, "===========================================\n");
3686 	}
3687 	return 0;
3688 }
3689 
3690 RVU_DEBUG_SEQ_FOPS(cpt_engines_info, cpt_engines_info_display, NULL);
3691 
rvu_dbg_cpt_lfs_info_display(struct seq_file * filp,void * unused)3692 static int rvu_dbg_cpt_lfs_info_display(struct seq_file *filp, void *unused)
3693 {
3694 	struct cpt_ctx *ctx = filp->private;
3695 	int blkaddr = ctx->blkaddr;
3696 	struct rvu *rvu = ctx->rvu;
3697 	struct rvu_block *block;
3698 	struct rvu_hwinfo *hw;
3699 	u64 reg;
3700 	u32 lf;
3701 
3702 	hw = rvu->hw;
3703 	block = &hw->block[blkaddr];
3704 	if (!block->lf.bmap)
3705 		return -ENODEV;
3706 
3707 	seq_puts(filp, "===========================================\n");
3708 	for (lf = 0; lf < block->lf.max; lf++) {
3709 		reg = rvu_read64(rvu, blkaddr, CPT_AF_LFX_CTL(lf));
3710 		seq_printf(filp, "CPT Lf[%u] CTL          0x%llx\n", lf, reg);
3711 		reg = rvu_read64(rvu, blkaddr, CPT_AF_LFX_CTL2(lf));
3712 		seq_printf(filp, "CPT Lf[%u] CTL2         0x%llx\n", lf, reg);
3713 		reg = rvu_read64(rvu, blkaddr, CPT_AF_LFX_PTR_CTL(lf));
3714 		seq_printf(filp, "CPT Lf[%u] PTR_CTL      0x%llx\n", lf, reg);
3715 		reg = rvu_read64(rvu, blkaddr, block->lfcfg_reg |
3716 				(lf << block->lfshift));
3717 		seq_printf(filp, "CPT Lf[%u] CFG          0x%llx\n", lf, reg);
3718 		seq_puts(filp, "===========================================\n");
3719 	}
3720 	return 0;
3721 }
3722 
3723 RVU_DEBUG_SEQ_FOPS(cpt_lfs_info, cpt_lfs_info_display, NULL);
3724 
rvu_dbg_cpt_err_info_display(struct seq_file * filp,void * unused)3725 static int rvu_dbg_cpt_err_info_display(struct seq_file *filp, void *unused)
3726 {
3727 	struct cpt_ctx *ctx = filp->private;
3728 	struct rvu *rvu = ctx->rvu;
3729 	int blkaddr = ctx->blkaddr;
3730 	u64 reg0, reg1;
3731 
3732 	reg0 = rvu_read64(rvu, blkaddr, CPT_AF_FLTX_INT(0));
3733 	reg1 = rvu_read64(rvu, blkaddr, CPT_AF_FLTX_INT(1));
3734 	seq_printf(filp, "CPT_AF_FLTX_INT:       0x%llx 0x%llx\n", reg0, reg1);
3735 	reg0 = rvu_read64(rvu, blkaddr, CPT_AF_PSNX_EXE(0));
3736 	reg1 = rvu_read64(rvu, blkaddr, CPT_AF_PSNX_EXE(1));
3737 	seq_printf(filp, "CPT_AF_PSNX_EXE:       0x%llx 0x%llx\n", reg0, reg1);
3738 	reg0 = rvu_read64(rvu, blkaddr, CPT_AF_PSNX_LF(0));
3739 	seq_printf(filp, "CPT_AF_PSNX_LF:        0x%llx\n", reg0);
3740 	reg0 = rvu_read64(rvu, blkaddr, CPT_AF_RVU_INT);
3741 	seq_printf(filp, "CPT_AF_RVU_INT:        0x%llx\n", reg0);
3742 	reg0 = rvu_read64(rvu, blkaddr, CPT_AF_RAS_INT);
3743 	seq_printf(filp, "CPT_AF_RAS_INT:        0x%llx\n", reg0);
3744 	reg0 = rvu_read64(rvu, blkaddr, CPT_AF_EXE_ERR_INFO);
3745 	seq_printf(filp, "CPT_AF_EXE_ERR_INFO:   0x%llx\n", reg0);
3746 
3747 	return 0;
3748 }
3749 
3750 RVU_DEBUG_SEQ_FOPS(cpt_err_info, cpt_err_info_display, NULL);
3751 
rvu_dbg_cpt_pc_display(struct seq_file * filp,void * unused)3752 static int rvu_dbg_cpt_pc_display(struct seq_file *filp, void *unused)
3753 {
3754 	struct cpt_ctx *ctx = filp->private;
3755 	struct rvu *rvu = ctx->rvu;
3756 	int blkaddr = ctx->blkaddr;
3757 	u64 reg;
3758 
3759 	reg = rvu_read64(rvu, blkaddr, CPT_AF_INST_REQ_PC);
3760 	seq_printf(filp, "CPT instruction requests   %llu\n", reg);
3761 	reg = rvu_read64(rvu, blkaddr, CPT_AF_INST_LATENCY_PC);
3762 	seq_printf(filp, "CPT instruction latency    %llu\n", reg);
3763 	reg = rvu_read64(rvu, blkaddr, CPT_AF_RD_REQ_PC);
3764 	seq_printf(filp, "CPT NCB read requests      %llu\n", reg);
3765 	reg = rvu_read64(rvu, blkaddr, CPT_AF_RD_LATENCY_PC);
3766 	seq_printf(filp, "CPT NCB read latency       %llu\n", reg);
3767 	reg = rvu_read64(rvu, blkaddr, CPT_AF_RD_UC_PC);
3768 	seq_printf(filp, "CPT read requests caused by UC fills   %llu\n", reg);
3769 	reg = rvu_read64(rvu, blkaddr, CPT_AF_ACTIVE_CYCLES_PC);
3770 	seq_printf(filp, "CPT active cycles pc       %llu\n", reg);
3771 	reg = rvu_read64(rvu, blkaddr, CPT_AF_CPTCLK_CNT);
3772 	seq_printf(filp, "CPT clock count pc         %llu\n", reg);
3773 
3774 	return 0;
3775 }
3776 
3777 RVU_DEBUG_SEQ_FOPS(cpt_pc, cpt_pc_display, NULL);
3778 
rvu_dbg_cpt_init(struct rvu * rvu,int blkaddr)3779 static void rvu_dbg_cpt_init(struct rvu *rvu, int blkaddr)
3780 {
3781 	struct cpt_ctx *ctx;
3782 
3783 	if (!is_block_implemented(rvu->hw, blkaddr))
3784 		return;
3785 
3786 	if (blkaddr == BLKADDR_CPT0) {
3787 		rvu->rvu_dbg.cpt = debugfs_create_dir("cpt", rvu->rvu_dbg.root);
3788 		ctx = &rvu->rvu_dbg.cpt_ctx[0];
3789 		ctx->blkaddr = BLKADDR_CPT0;
3790 		ctx->rvu = rvu;
3791 	} else {
3792 		rvu->rvu_dbg.cpt = debugfs_create_dir("cpt1",
3793 						      rvu->rvu_dbg.root);
3794 		ctx = &rvu->rvu_dbg.cpt_ctx[1];
3795 		ctx->blkaddr = BLKADDR_CPT1;
3796 		ctx->rvu = rvu;
3797 	}
3798 
3799 	debugfs_create_file("cpt_pc", 0600, rvu->rvu_dbg.cpt, ctx,
3800 			    &rvu_dbg_cpt_pc_fops);
3801 	debugfs_create_file("cpt_ae_sts", 0600, rvu->rvu_dbg.cpt, ctx,
3802 			    &rvu_dbg_cpt_ae_sts_fops);
3803 	debugfs_create_file("cpt_se_sts", 0600, rvu->rvu_dbg.cpt, ctx,
3804 			    &rvu_dbg_cpt_se_sts_fops);
3805 	debugfs_create_file("cpt_ie_sts", 0600, rvu->rvu_dbg.cpt, ctx,
3806 			    &rvu_dbg_cpt_ie_sts_fops);
3807 	debugfs_create_file("cpt_engines_info", 0600, rvu->rvu_dbg.cpt, ctx,
3808 			    &rvu_dbg_cpt_engines_info_fops);
3809 	debugfs_create_file("cpt_lfs_info", 0600, rvu->rvu_dbg.cpt, ctx,
3810 			    &rvu_dbg_cpt_lfs_info_fops);
3811 	debugfs_create_file("cpt_err_info", 0600, rvu->rvu_dbg.cpt, ctx,
3812 			    &rvu_dbg_cpt_err_info_fops);
3813 }
3814 
rvu_get_dbg_dir_name(struct rvu * rvu)3815 static const char *rvu_get_dbg_dir_name(struct rvu *rvu)
3816 {
3817 	if (!is_rvu_otx2(rvu))
3818 		return "cn10k";
3819 	else
3820 		return "octeontx2";
3821 }
3822 
rvu_dbg_init(struct rvu * rvu)3823 void rvu_dbg_init(struct rvu *rvu)
3824 {
3825 	rvu->rvu_dbg.root = debugfs_create_dir(rvu_get_dbg_dir_name(rvu), NULL);
3826 
3827 	debugfs_create_file("rsrc_alloc", 0444, rvu->rvu_dbg.root, rvu,
3828 			    &rvu_dbg_rsrc_status_fops);
3829 
3830 	if (!is_rvu_otx2(rvu))
3831 		debugfs_create_file("lmtst_map_table", 0444, rvu->rvu_dbg.root,
3832 				    rvu, &rvu_dbg_lmtst_map_table_fops);
3833 
3834 	if (!cgx_get_cgxcnt_max())
3835 		goto create;
3836 
3837 	if (is_rvu_otx2(rvu))
3838 		debugfs_create_file("rvu_pf_cgx_map", 0444, rvu->rvu_dbg.root,
3839 				    rvu, &rvu_dbg_rvu_pf_cgx_map_fops);
3840 	else
3841 		debugfs_create_file("rvu_pf_rpm_map", 0444, rvu->rvu_dbg.root,
3842 				    rvu, &rvu_dbg_rvu_pf_cgx_map_fops);
3843 
3844 create:
3845 	rvu_dbg_npa_init(rvu);
3846 	rvu_dbg_nix_init(rvu, BLKADDR_NIX0);
3847 
3848 	rvu_dbg_nix_init(rvu, BLKADDR_NIX1);
3849 	rvu_dbg_cgx_init(rvu);
3850 	rvu_dbg_npc_init(rvu);
3851 	rvu_dbg_cpt_init(rvu, BLKADDR_CPT0);
3852 	rvu_dbg_cpt_init(rvu, BLKADDR_CPT1);
3853 	rvu_dbg_mcs_init(rvu);
3854 }
3855 
rvu_dbg_exit(struct rvu * rvu)3856 void rvu_dbg_exit(struct rvu *rvu)
3857 {
3858 	debugfs_remove_recursive(rvu->rvu_dbg.root);
3859 }
3860 
3861 #endif /* CONFIG_DEBUG_FS */
3862