summaryrefslogtreecommitdiff
path: root/usr/src/cmd/mdb/common/modules/i40e/i40e.c
blob: 6d1f900b430fbe2860a0358df3b58e70736582d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
 * This file and its contents are supplied under the terms of the
 * Common Development and Distribution License ("CDDL"), version 1.0.
 * You may only use this file in accordance with the terms of version
 * 1.0 of the CDDL.
 *
 * A full copy of the text of the CDDL should have accompanied this
 * source.  A copy of the CDDL is also available via the Internet at
 * http://www.illumos.org/license/CDDL.
 */

/*
 * Copyright 2016 Joyent, Inc.
 */

#include <sys/mdb_modapi.h>
#include "i40e_sw.h"

#define	RSRC_MAX	0x13
static const char *i40e_switch_rsrc_names[] = {
	"VEBs",
	"VSIs",
	"Perfect Match MAC Addresses",
	"S-Tags",
	"Reserved",
	"Multicast Hash Entries",
	"Reserved",
	"VLANs",
	"VSI Lists",
	"Reserved",
	"VLAN Stat pools",
	"Mirror rules",
	"Queue sets",
	"Inner VLAN Forwarding",
	"Reserved",
	"Inner MACs",
	"IPs",
	"GRE/VN1 Keys",
	"VN2 Keys",
	"Tunnelling Ports"
};

/*
 * i40e mdb dcmds
 */
/* ARGSUSED */
static int
i40e_switch_rsrcs_dcmd(uintptr_t addr, uint_t flags, int argc,
    const mdb_arg_t *argv)
{
	i40e_t i40e;
	int i;

	if (!(flags & DCMD_ADDRSPEC)) {
		mdb_warn("::i40e_switch_rsrcs does not operate globally\n");
		return (DCMD_USAGE);
	}

	if (mdb_vread(&i40e, sizeof (i40e_t), addr) != sizeof (i40e_t)) {
		mdb_warn("failed to read i40e_t at %p", addr);
		return (DCMD_ERR);
	}

	mdb_printf("%-28s %-12s %-8s %-8s %s\n", "TYPE", "GUARANTEE",
	    "TOTAL", "USED", "UNALLOCED");

	for (i = 0; i < i40e.i40e_switch_rsrc_actual; i++) {
		i40e_switch_rsrc_t rsrc;
		uintptr_t raddr = (uintptr_t)i40e.i40e_switch_rsrcs +
		    i * sizeof (i40e_switch_rsrc_t);
		const char *name;

		if (mdb_vread(&rsrc, sizeof (i40e_switch_rsrc_t), raddr) !=
		    sizeof (i40e_switch_rsrc_t)) {
			mdb_warn("failed to read i40e_switch_rsrc_t %d at %p",
			    i, raddr);
			return (DCMD_ERR);
		}

		if (rsrc.resource_type <= RSRC_MAX) {
			name = i40e_switch_rsrc_names[rsrc.resource_type];
		} else {
			char *buf;
			size_t s = mdb_snprintf(NULL, 0, "Unknown type (%d)",
			    rsrc.resource_type);
			buf = mdb_alloc(s + 1, UM_GC | UM_SLEEP);
			(void) mdb_snprintf(buf, s + 1, "Unknown type (%d)",
			    rsrc.resource_type);
			name = buf;
		}

		mdb_printf("%-28s %-12d %-8d %-8d %d\n", name,
		    LE_16(rsrc.guaranteed), LE_16(rsrc.total), LE_16(rsrc.used),
		    LE_16(rsrc.total_unalloced));
	}

	return (DCMD_OK);
}

static const mdb_dcmd_t i40e_dcmds[] = {
	{ "i40e_switch_rsrcs", NULL, "print switch resources",
	    i40e_switch_rsrcs_dcmd, NULL },
	{ NULL }
};

static const mdb_modinfo_t i40e_modinfo = {
	MDB_API_VERSION, i40e_dcmds, NULL
};

const mdb_modinfo_t *
_mdb_init(void)
{
	return (&i40e_modinfo);
}