1 /* 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2026 Kevin Bowling <kbowling@FreeBSD.org> 5 */ 6 7 #ifndef _NET_IF_VF_STATUS_H_ 8 #define _NET_IF_VF_STATUS_H_ 9 10 #include <sys/types.h> 11 #ifndef _KERNEL 12 #include <stdbool.h> 13 #endif 14 15 #include <net/ethernet.h> 16 17 /* 18 * Kernel-only snapshot of SR-IOV VF state. The fields member is a bit mask 19 * identifying which other members contain valid data. This distinguishes a 20 * missing value from a value of false or zero. Drivers set bits only for 21 * information they can report, and each transport converts the snapshot to 22 * its own ABI. VLAN PCP and protocol describe the PF-administered access 23 * VLAN, not the VF's trunk filters. Transmit rates describe an aggregate VF 24 * policy. When both are present and the maximum is nonzero, the minimum must 25 * not exceed it. A successful snapshot may contain zero VFs, allowing a 26 * provider to report that SR-IOV is available but is not currently configured. 27 */ 28 #define IFVF_MAX_VFS UINT16_MAX 29 #define IFVF_MAX_EXTENSIONS 16 30 #define IFVF_MAX_EXTENSION_FIELDS 64 31 32 enum if_vf_field { 33 IFVF_F_CONFIGURED = 1ULL << 0, 34 IFVF_F_INITIALIZED = 1ULL << 1, 35 IFVF_F_MAC = 1ULL << 2, 36 IFVF_F_VLAN_MODE = 1ULL << 3, 37 IFVF_F_VLAN = 1ULL << 4, 38 IFVF_F_VLAN_PCP = 1ULL << 5, 39 IFVF_F_VLAN_PROTO = 1ULL << 6, 40 IFVF_F_VLAN_COUNT = 1ULL << 7, 41 IFVF_F_VLAN_LIMIT = 1ULL << 8, 42 IFVF_F_NUM_TX_QUEUES = 1ULL << 9, 43 IFVF_F_NUM_RX_QUEUES = 1ULL << 10, 44 IFVF_F_MIN_TX_RATE = 1ULL << 11, 45 IFVF_F_MAX_TX_RATE = 1ULL << 12, 46 IFVF_F_ALLOW_SET_MAC = 1ULL << 13, 47 IFVF_F_ALLOW_SET_VLAN = 1ULL << 14, 48 IFVF_F_MAC_ANTI_SPOOF = 1ULL << 15, 49 IFVF_F_ALLOW_PROMISC = 1ULL << 16, 50 IFVF_F_TRAFFIC_ALLOWED = 1ULL << 17, 51 IFVF_F_FAULT_BLOCKED = 1ULL << 18, 52 IFVF_F_QUARANTINED = 1ULL << 19, 53 IFVF_F_API_VERSION = 1ULL << 20, 54 IFVF_F_LINK_STATE_POLICY = 1ULL << 21, 55 }; 56 57 enum if_vf_vlan_mode { 58 IFVF_VLAN_UNKNOWN = 0, 59 IFVF_VLAN_ACCESS, 60 IFVF_VLAN_TRUNK, 61 }; 62 63 enum if_vf_link_state { 64 IFVF_LINK_UNKNOWN = 0, 65 IFVF_LINK_DOWN, 66 IFVF_LINK_UP, 67 IFVF_LINK_AUTO, 68 }; 69 70 /* 71 * Drivers may add fields under a stable, versioned namespace. The named, 72 * typed representation lets transports and generic consumers carry and 73 * display fields whose driver-specific schema they do not know. The driver 74 * owns the field names and meanings; common code does not interpret them. 75 * Namespace and field names must remain valid until the snapshot is freed. 76 */ 77 enum if_vf_ext_type { 78 IFVF_EXT_BOOL = 1, 79 IFVF_EXT_NUMBER, 80 IFVF_EXT_STRING, 81 IFVF_EXT_BINARY, 82 }; 83 84 struct if_vf_ext_field { 85 const char *name; 86 enum if_vf_ext_type type; 87 union { 88 bool boolean; 89 uint64_t number; 90 char *string; 91 struct { 92 void *data; 93 uint32_t length; 94 } binary; 95 } value; 96 }; 97 98 struct if_vf_extension { 99 const char *name; 100 uint32_t version; 101 uint32_t num_fields; 102 struct if_vf_ext_field *fields; 103 }; 104 105 #define IFVF_API_VERSION_MAX 16 106 107 struct if_vf_info { 108 uint64_t fields; 109 uint64_t min_tx_rate_bps; /* Zero means no guaranteed allocation. */ 110 uint64_t max_tx_rate_bps; /* Zero means unlimited. */ 111 uint32_t index; 112 uint32_t vlan_count; 113 uint32_t vlan_limit; 114 uint16_t tx_queue_count; 115 uint16_t rx_queue_count; 116 uint16_t vlan; 117 uint16_t vlan_proto; /* Host-order Ethernet type. */ 118 uint8_t vlan_pcp; 119 uint8_t mac[ETHER_ADDR_LEN]; 120 enum if_vf_vlan_mode vlan_mode; 121 enum if_vf_link_state link_state_policy; 122 bool configured:1; 123 bool initialized:1; 124 bool allow_set_mac:1; 125 bool allow_set_vlan:1; 126 bool mac_anti_spoof:1; 127 bool allow_promisc:1; 128 bool traffic_allowed:1; 129 bool fault_blocked:1; 130 bool quarantined:1; 131 /* Negotiated PF/VF mailbox API, not a version of this structure. */ 132 char api_version[IFVF_API_VERSION_MAX]; 133 uint32_t num_extensions; 134 struct if_vf_extension *extensions; 135 }; 136 137 struct if_vf_status { 138 uint32_t num_vfs; 139 struct if_vf_info vfs[]; 140 }; 141 142 #ifdef _KERNEL 143 struct if_vf_status *if_vf_status_alloc(uint32_t); 144 void if_vf_status_free(struct if_vf_status *); 145 struct if_vf_extension *if_vf_status_add_extension(struct if_vf_info *, 146 const char *, uint32_t, uint32_t); 147 void if_vf_extension_set_bool(struct if_vf_extension *, uint32_t, 148 const char *, bool); 149 void if_vf_extension_set_number(struct if_vf_extension *, uint32_t, 150 const char *, uint64_t); 151 void if_vf_extension_set_string(struct if_vf_extension *, uint32_t, 152 const char *, const char *); 153 void if_vf_extension_set_binary(struct if_vf_extension *, uint32_t, 154 const char *, const void *, uint32_t); 155 #endif 156 157 #endif /* _NET_IF_VF_STATUS_H_ */ 158