aboutsummaryrefslogtreecommitdiff
path: root/sys/net/if_vf_status.h
blob: 4c24a4a8b615a16a1763a9b3f5248afca5572074 (plain) (blame)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
 * SPDX-License-Identifier: BSD-2-Clause
 *
 * Copyright (c) 2026 Kevin Bowling <kbowling@FreeBSD.org>
 */

#ifndef _NET_IF_VF_STATUS_H_
#define	_NET_IF_VF_STATUS_H_

#include <sys/types.h>
#ifndef _KERNEL
#include <stdbool.h>
#endif

#include <net/ethernet.h>

/*
 * Kernel-only snapshot of SR-IOV VF state.  The fields member is a bit mask
 * identifying which other members contain valid data.  This distinguishes a
 * missing value from a value of false or zero.  Drivers set bits only for
 * information they can report, and each transport converts the snapshot to
 * its own ABI.  VLAN identifier and protocol describe the PF-administered
 * access VLAN.  VLAN PCP describes PF-administered priority in access or
 * trunk mode, including priority-only tagging with VID 0.  These fields do
 * not describe individual trunk filters or VF-selected priorities.
 * Transmit rates describe an aggregate VF policy.  When both are present and
 * the maximum is nonzero, the minimum must not exceed it.  A successful
 * snapshot may contain zero VFs, allowing a provider to report that SR-IOV is
 * available but is not currently configured.
 */
#define	IFVF_MAX_VFS			UINT16_MAX
#define	IFVF_MAX_EXTENSIONS		16
#define	IFVF_MAX_EXTENSION_FIELDS	64

enum if_vf_field {
	IFVF_F_CONFIGURED		= 1ULL << 0,
	IFVF_F_INITIALIZED		= 1ULL << 1,
	IFVF_F_MAC			= 1ULL << 2,
	IFVF_F_VLAN_MODE		= 1ULL << 3,
	IFVF_F_VLAN			= 1ULL << 4,
	IFVF_F_VLAN_PCP			= 1ULL << 5,
	IFVF_F_VLAN_PROTO		= 1ULL << 6,
	IFVF_F_VLAN_COUNT		= 1ULL << 7,
	IFVF_F_VLAN_LIMIT		= 1ULL << 8,
	IFVF_F_NUM_TX_QUEUES		= 1ULL << 9,
	IFVF_F_NUM_RX_QUEUES		= 1ULL << 10,
	IFVF_F_MIN_TX_RATE		= 1ULL << 11,
	IFVF_F_MAX_TX_RATE		= 1ULL << 12,
	IFVF_F_ALLOW_SET_MAC		= 1ULL << 13,
	IFVF_F_ALLOW_SET_VLAN		= 1ULL << 14,
	IFVF_F_MAC_ANTI_SPOOF		= 1ULL << 15,
	IFVF_F_ALLOW_PROMISC		= 1ULL << 16,
	IFVF_F_TRAFFIC_ALLOWED		= 1ULL << 17,
	IFVF_F_FAULT_BLOCKED		= 1ULL << 18,
	IFVF_F_QUARANTINED		= 1ULL << 19,
	IFVF_F_API_VERSION		= 1ULL << 20,
	IFVF_F_LINK_STATE_POLICY	= 1ULL << 21,
};

enum if_vf_vlan_mode {
	IFVF_VLAN_UNKNOWN = 0,
	IFVF_VLAN_ACCESS,
	IFVF_VLAN_TRUNK,
};

enum if_vf_link_state {
	IFVF_LINK_UNKNOWN = 0,
	IFVF_LINK_DOWN,
	IFVF_LINK_UP,
	IFVF_LINK_AUTO,
};

/*
 * Drivers may add fields under a stable, versioned namespace.  The named,
 * typed representation lets transports and generic consumers carry and
 * display fields whose driver-specific schema they do not know.  The driver
 * owns the field names and meanings; common code does not interpret them.
 * Namespace and field names must remain valid until the snapshot is freed.
 */
enum if_vf_ext_type {
	IFVF_EXT_BOOL = 1,
	IFVF_EXT_NUMBER,
	IFVF_EXT_STRING,
	IFVF_EXT_BINARY,
};

struct if_vf_ext_field {
	const char *name;
	enum if_vf_ext_type type;
	union {
		bool boolean;
		uint64_t number;
		char *string;
		struct {
			void *data;
			uint32_t length;
		} binary;
	} value;
};

struct if_vf_extension {
	const char *name;
	uint32_t version;
	uint32_t num_fields;
	struct if_vf_ext_field *fields;
};

#define	IFVF_API_VERSION_MAX	16

struct if_vf_info {
	uint64_t fields;
	uint64_t min_tx_rate_bps;	/* Zero means no guaranteed allocation. */
	uint64_t max_tx_rate_bps;	/* Zero means unlimited. */
	uint32_t index;
	uint32_t vlan_count;
	uint32_t vlan_limit;
	uint16_t tx_queue_count;
	uint16_t rx_queue_count;
	uint16_t vlan;
	uint16_t vlan_proto;		/* Host-order Ethernet type. */
	uint8_t vlan_pcp;
	uint8_t mac[ETHER_ADDR_LEN];
	enum if_vf_vlan_mode vlan_mode;
	enum if_vf_link_state link_state_policy;
	bool configured:1;
	bool initialized:1;
	bool allow_set_mac:1;
	bool allow_set_vlan:1;
	bool mac_anti_spoof:1;
	bool allow_promisc:1;
	bool traffic_allowed:1;
	bool fault_blocked:1;
	bool quarantined:1;
	/* Negotiated PF/VF mailbox API, not a version of this structure. */
	char api_version[IFVF_API_VERSION_MAX];
	uint32_t num_extensions;
	struct if_vf_extension *extensions;
};

struct if_vf_status {
	uint32_t num_vfs;
	struct if_vf_info vfs[];
};

#ifdef _KERNEL
struct if_vf_status *if_vf_status_alloc(uint32_t);
void if_vf_status_free(struct if_vf_status *);
struct if_vf_extension *if_vf_status_add_extension(struct if_vf_info *,
    const char *, uint32_t, uint32_t);
void if_vf_extension_set_bool(struct if_vf_extension *, uint32_t,
    const char *, bool);
void if_vf_extension_set_number(struct if_vf_extension *, uint32_t,
    const char *, uint64_t);
void if_vf_extension_set_string(struct if_vf_extension *, uint32_t,
    const char *, const char *);
void if_vf_extension_set_binary(struct if_vf_extension *, uint32_t,
    const char *, const void *, uint32_t);
#endif

#endif /* _NET_IF_VF_STATUS_H_ */