iovctl: allow vlan restrictions to be passed to the driver
Allow iovctl to create VFs that are restricted to specific VLAN IDs.
Reviewed by: kib, np
MFC after: 2 weeks
Sponsored by: Orange Business Services
Differential Revision: https://reviews.freebsd.org/D45402
(cherry picked from commit c57c261790)
This commit is contained in:
parent
d56a912f2f
commit
6bba78e6e9
6 changed files with 100 additions and 2 deletions
|
|
@ -55,11 +55,13 @@ static validate_func pci_iov_schema_validate_bool;
|
|||
static validate_func pci_iov_schema_validate_string;
|
||||
static validate_func pci_iov_schema_validate_uint;
|
||||
static validate_func pci_iov_schema_validate_unicast_mac;
|
||||
static validate_func pci_iov_schema_validate_vlan;
|
||||
|
||||
static default_validate_t pci_iov_validate_bool_default;
|
||||
static default_validate_t pci_iov_validate_string_default;
|
||||
static default_validate_t pci_iov_validate_uint_default;
|
||||
static default_validate_t pci_iov_validate_unicast_mac_default;
|
||||
static default_validate_t pci_iov_validate_vlan_default;
|
||||
|
||||
struct config_type_validator {
|
||||
const char *type_name;
|
||||
|
|
@ -108,6 +110,11 @@ static struct config_type_validator pci_iov_schema_validators[] = {
|
|||
.validate = pci_iov_schema_validate_unicast_mac,
|
||||
.default_validate = pci_iov_validate_unicast_mac_default,
|
||||
},
|
||||
{
|
||||
.type_name = "vlan",
|
||||
.validate = pci_iov_schema_validate_vlan,
|
||||
.default_validate = pci_iov_validate_vlan_default,
|
||||
},
|
||||
};
|
||||
|
||||
static const struct config_type_validator *
|
||||
|
|
@ -262,6 +269,26 @@ pci_iov_schema_add_unicast_mac(nvlist_t *schema, const char *name,
|
|||
nvlist_move_nvlist(schema, name, entry);
|
||||
}
|
||||
|
||||
void
|
||||
pci_iov_schema_add_vlan(nvlist_t *schema, const char *name,
|
||||
uint32_t flags, const uint16_t defaultVal)
|
||||
{
|
||||
nvlist_t *entry;
|
||||
|
||||
entry = nvlist_create(NV_FLAG_IGNORE_CASE);
|
||||
if (entry == NULL) {
|
||||
nvlist_set_error(schema, ENOMEM);
|
||||
return;
|
||||
}
|
||||
|
||||
pci_iov_schema_add_type(entry, "vlan");
|
||||
if (flags & IOV_SCHEMA_HASDEFAULT)
|
||||
nvlist_add_number(entry, "default", defaultVal);
|
||||
pci_iov_schema_add_required(entry, flags);
|
||||
|
||||
nvlist_move_nvlist(schema, name, entry);
|
||||
}
|
||||
|
||||
static int
|
||||
pci_iov_schema_validate_bool(const struct config_type_validator * validator,
|
||||
const nvlist_t *config, const char *name)
|
||||
|
|
@ -321,6 +348,24 @@ pci_iov_schema_validate_unicast_mac(
|
|||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
pci_iov_schema_validate_vlan(
|
||||
const struct config_type_validator * validator,
|
||||
const nvlist_t *config, const char *name)
|
||||
{
|
||||
uint16_t vlan;
|
||||
|
||||
if (!nvlist_exists_number(config, name))
|
||||
return (EINVAL);
|
||||
|
||||
vlan = nvlist_get_number(config, name);
|
||||
|
||||
if (vlan > 4095 && vlan != VF_VLAN_TRUNK)
|
||||
return (EINVAL);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
pci_iov_config_add_default(const nvlist_t *param_schema, const char *name,
|
||||
nvlist_t *config)
|
||||
|
|
@ -401,6 +446,22 @@ pci_iov_validate_unicast_mac_default(
|
|||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
pci_iov_validate_vlan_default(
|
||||
const struct config_type_validator * validator, const nvlist_t *param)
|
||||
{
|
||||
uint16_t vlan;
|
||||
|
||||
if (! nvlist_exists_number(param, DEFAULT_SCHEMA_NAME))
|
||||
return (EINVAL);
|
||||
|
||||
vlan = nvlist_get_number(param, DEFAULT_SCHEMA_NAME);
|
||||
if (vlan > 4095 && vlan != VF_VLAN_TRUNK)
|
||||
return (EINVAL);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
pci_iov_validate_param_schema(const nvlist_t *schema)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -46,6 +46,8 @@
|
|||
#define DEFAULT_SCHEMA_NAME "DEFAULT"
|
||||
#define REQUIRED_SCHEMA_NAME "REQUIRED"
|
||||
|
||||
#define VF_VLAN_TRUNK 4096
|
||||
|
||||
/*
|
||||
* Because each PF device is expected to expose a unique set of possible
|
||||
* configurations, the SR-IOV infrastructure dynamically queries the PF
|
||||
|
|
|
|||
|
|
@ -48,5 +48,6 @@ void pci_iov_schema_add_uint64(nvlist_t *schema, const char *name,
|
|||
uint32_t flags, uint64_t defaultVal);
|
||||
void pci_iov_schema_add_unicast_mac(nvlist_t *schema, const char *name,
|
||||
uint32_t flags, const uint8_t * defaultVal);
|
||||
|
||||
void pci_iov_schema_add_vlan(nvlist_t *schema, const char *name,
|
||||
uint32_t flags, const uint16_t defaultVal);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -346,6 +346,12 @@ print_default_value(const nvlist_t *parameter, const char *type)
|
|||
mac = nvlist_get_binary(parameter, DEFAULT_SCHEMA_NAME, &size);
|
||||
printf(" (default = %02x:%02x:%02x:%02x:%02x:%02x)", mac[0],
|
||||
mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
} else if (strcasecmp(type, "vlan") == 0) {
|
||||
uint16_t vlan = nvlist_get_number(parameter, DEFAULT_SCHEMA_NAME);
|
||||
if (vlan == VF_VLAN_TRUNK)
|
||||
printf(" (default = trunk)");
|
||||
else
|
||||
printf(" (default = %d)", vlan);
|
||||
} else
|
||||
errx(1, "Unexpected type in schema: '%s'", type);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd May 29, 2020
|
||||
.Dd May 30, 2024
|
||||
.Dt IOVCTL.CONF 5
|
||||
.Os
|
||||
.Sh NAME
|
||||
|
|
@ -95,6 +95,8 @@ The following option types are supported:
|
|||
.Bl -tag -width indent
|
||||
.It boolean
|
||||
Accepts a boolean value of true or false.
|
||||
.It vlan
|
||||
Accepts a VLAN ID, or "trunk" to allow any VLAN ID.
|
||||
.It mac-addr
|
||||
Accepts a unicast MAC address specified as a string of the form
|
||||
xx:xx:xx:xx:xx:xx, where xx is one or two hexadecimal digits.
|
||||
|
|
@ -159,6 +161,7 @@ DEFAULT {
|
|||
VF-0 {
|
||||
mac-addr : "02:56:48:7e:d9:f7";
|
||||
passthrough : false;
|
||||
vlan: 1;
|
||||
}
|
||||
.Ed
|
||||
.Sh SEE ALSO
|
||||
|
|
|
|||
|
|
@ -161,6 +161,29 @@ add_unicast_mac_config(const char *key, const ucl_object_t *obj, nvlist_t *confi
|
|||
nvlist_add_binary(config, key, mac, ETHER_ADDR_LEN);
|
||||
}
|
||||
|
||||
static void
|
||||
add_vlan_config(const char *key, const ucl_object_t *obj, nvlist_t *config)
|
||||
{
|
||||
int64_t val;
|
||||
const char *strVal = "";
|
||||
|
||||
if(ucl_object_tostring_safe(obj, &strVal)) {
|
||||
if (strcasecmp(strVal, "trunk") == 0) {
|
||||
nvlist_add_number(config, key, VF_VLAN_TRUNK);
|
||||
return;
|
||||
}
|
||||
report_config_error(key, obj, "vlan");
|
||||
}
|
||||
|
||||
if (!ucl_object_toint_safe(obj, &val))
|
||||
report_config_error(key, obj, "vlan");
|
||||
|
||||
if (val < 0 || val > 4095)
|
||||
report_config_error(key, obj, "vlan");
|
||||
|
||||
nvlist_add_number(config, key, val);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validates that the given configuration value has the right type as specified
|
||||
* in the schema, and then adds the value to the configuration node.
|
||||
|
|
@ -187,6 +210,8 @@ add_config(const char *key, const ucl_object_t *obj, nvlist_t *config,
|
|||
add_uint_config(key, obj, config, type, UINT64_MAX);
|
||||
else if (strcasecmp(type, "unicast-mac") == 0)
|
||||
add_unicast_mac_config(key, obj, config);
|
||||
else if (strcasecmp(type, "vlan") == 0)
|
||||
add_vlan_config(key, obj, config);
|
||||
else
|
||||
errx(1, "Unexpected type '%s' in schema", type);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue