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