xref: /illumos-gate/usr/src/cmd/mdb/intel/modules/i40e/i40e.c (revision 3cb4cf2c471d8987abb34ec86fda3a6224b5add7)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2016 Joyent, Inc.
14  */
15 
16 #include <sys/mdb_modapi.h>
17 #include "i40e_sw.h"
18 
19 #define	RSRC_MAX	0x13
20 static const char *i40e_switch_rsrc_names[] = {
21 	"VEBs",
22 	"VSIs",
23 	"Perfect Match MAC Addresses",
24 	"S-Tags",
25 	"Reserved",
26 	"Multicast Hash Entries",
27 	"Reserved",
28 	"VLANs",
29 	"VSI Lists",
30 	"Reserved",
31 	"VLAN Stat pools",
32 	"Mirror rules",
33 	"Queue sets",
34 	"Inner VLAN Forwarding",
35 	"Reserved",
36 	"Inner MACs",
37 	"IPs",
38 	"GRE/VN1 Keys",
39 	"VN2 Keys",
40 	"Tunnelling Ports"
41 };
42 
43 /*
44  * i40e mdb dcmds
45  */
46 /* ARGSUSED */
47 static int
48 i40e_switch_rsrcs_dcmd(uintptr_t addr, uint_t flags, int argc,
49     const mdb_arg_t *argv)
50 {
51 	i40e_t i40e;
52 	int i;
53 
54 	if (!(flags & DCMD_ADDRSPEC)) {
55 		mdb_warn("::i40e_switch_rsrcs does not operate globally\n");
56 		return (DCMD_USAGE);
57 	}
58 
59 	if (mdb_vread(&i40e, sizeof (i40e_t), addr) != sizeof (i40e_t)) {
60 		mdb_warn("failed to read i40e_t at %p", addr);
61 		return (DCMD_ERR);
62 	}
63 
64 	mdb_printf("%-28s %-12s %-8s %-8s %s\n", "TYPE", "GUARANTEE",
65 	    "TOTAL", "USED", "UNALLOCED");
66 
67 	for (i = 0; i < i40e.i40e_switch_rsrc_actual; i++) {
68 		i40e_switch_rsrc_t rsrc;
69 		uintptr_t raddr = (uintptr_t)i40e.i40e_switch_rsrcs +
70 		    i * sizeof (i40e_switch_rsrc_t);
71 		const char *name;
72 
73 		if (mdb_vread(&rsrc, sizeof (i40e_switch_rsrc_t), raddr) !=
74 		    sizeof (i40e_switch_rsrc_t)) {
75 			mdb_warn("failed to read i40e_switch_rsrc_t %d at %p",
76 			    i, raddr);
77 			return (DCMD_ERR);
78 		}
79 
80 		if (rsrc.resource_type <= RSRC_MAX) {
81 			name = i40e_switch_rsrc_names[rsrc.resource_type];
82 		} else {
83 			char *buf;
84 			size_t s = mdb_snprintf(NULL, 0, "Unknown type (%d)",
85 			    rsrc.resource_type);
86 			buf = mdb_alloc(s + 1, UM_GC | UM_SLEEP);
87 			(void) mdb_snprintf(buf, s + 1, "Unknown type (%d)",
88 			    rsrc.resource_type);
89 			name = buf;
90 		}
91 
92 		mdb_printf("%-28s %-12d %-8d %-8d %d\n", name,
93 		    LE_16(rsrc.guaranteed), LE_16(rsrc.total), LE_16(rsrc.used),
94 		    LE_16(rsrc.total_unalloced));
95 	}
96 
97 	return (DCMD_OK);
98 }
99 
100 static const mdb_dcmd_t i40e_dcmds[] = {
101 	{ "i40e_switch_rsrcs", NULL, "print switch resources",
102 	    i40e_switch_rsrcs_dcmd, NULL },
103 	{ NULL }
104 };
105 
106 static const mdb_modinfo_t i40e_modinfo = {
107 	MDB_API_VERSION, i40e_dcmds, NULL
108 };
109 
110 const mdb_modinfo_t *
111 _mdb_init(void)
112 {
113 	return (&i40e_modinfo);
114 }
115