From nobody Mon Jun 17 09:54:58 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4W2lc24YWxz5NYVw; Mon, 17 Jun 2024 09:54:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4W2lc23hDqz4SFD; Mon, 17 Jun 2024 09:54:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1718618098; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4R0gQSgtKZXD9wL2wDXUgNZFTCmPH3Wie+gvnY36Xj0=; b=inVt/r9lHmRcQFU/b/TcpNF7VYK7s2PMcSaxexc4YXScc/u3uoxHYyJPfflhM4Gkq+TDu+ T8MUUXr01j3UfCU9au693WZ97P8xmXMv3mIkBEZUZztl/h3NaLKniL7qBxYh1mhqMxccZM 26WfROlYGNwJ+FnaVLW3rvbT4WZL57j7c9P8OIXAmKH3F3wpiEOanOaaf938GDnoGrnA+I /AomBshp4mI/+RQ3LolR2YBgtmvvpXkDGgY0owd4N8LTjctOxRmhLEh9WKtgCqnwiAhNPY peD2fQkaOIbMVMJ9Yktl86ANL+LeHFp+UqVEa+i6p3C0dbOEZbU0Elk762qSOA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1718618098; a=rsa-sha256; cv=none; b=Q1Xxw2UIfRCC6xjtc7J1falMWYyYQWsCetlF8y/WzMNWbzjhMALLV2qJ6/KtK8wPwiGWx2 uBo3PEP7qvjSz+wigZa8pdxs59lEU5iGYMzckTlrvziVnIgPgDWguVHLreDLQPX69i1OUm rxIuWSXET+9GraZaccNbh9ejnV7kb1YhC5wwYIrLc2gd39ixryBc9VYuvQtPGAE9jc8Frn BeaueOdi5pPUpMwjqzzVGsgsndazuys0idZ8isvIj+lZz8s0nDSo6JyReKJVKYgAfwYVa0 /IeY9YtComCgaJdAWkm4Ndap8gj7JKlTnMyLV6UEcUL8ldSX2KdwGtj/VYbtSw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1718618098; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4R0gQSgtKZXD9wL2wDXUgNZFTCmPH3Wie+gvnY36Xj0=; b=iji1lb4Z5lPW2S+SNDkAV5CF8fgjjahB4u1fPB1kF2l+Brw+LoGjl5C+xpJYCh8p06pzUa lWt2MYnBQVglddRHFWFlw2HPpUIYiIQcrHCIUco7Z4Q25h2ybCLIZ9p28V/3vH40hMgqMg 2Q4dNqJ3pCYV0qui6P+D9PwLxLi0tn31/JWRVQBz2NAhbSaPG6vCU3YvCppE74CazyiTKK fL6VqBj1Md0JMJQ5VvqKv/aJo0MXlhSmhLfkgQros1JRQ/z2HqW07T2M9viGQi/k5ThIiA hb/GK73gJGY/jw+6G64e5znJnKhNbVOieMP3y4w2iXyLf93zFbdYc64oNO0AVw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4W2lc238sLz1Q6B; Mon, 17 Jun 2024 09:54:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 45H9swXr030905; Mon, 17 Jun 2024 09:54:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 45H9swjT030902; Mon, 17 Jun 2024 09:54:58 GMT (envelope-from git) Date: Mon, 17 Jun 2024 09:54:58 GMT Message-Id: <202406170954.45H9swjT030902@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: c57c26179033 - main - iovctl: allow vlan restrictions to be passed to the driver List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c57c26179033f64c2011a2d2a904ee3fa62e826a Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=c57c26179033f64c2011a2d2a904ee3fa62e826a commit c57c26179033f64c2011a2d2a904ee3fa62e826a Author: Kristof Provost AuthorDate: 2024-05-29 17:29:35 +0000 Commit: Kristof Provost CommitDate: 2024-06-17 08:50:15 +0000 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 --- sys/dev/pci/pci_iov_schema.c | 61 +++++++++++++++++++++++++++++++++++++++++++ sys/sys/iov.h | 2 ++ sys/sys/iov_schema.h | 3 ++- usr.sbin/iovctl/iovctl.c | 6 +++++ usr.sbin/iovctl/iovctl.conf.5 | 5 +++- usr.sbin/iovctl/parse.c | 25 ++++++++++++++++++ 6 files changed, 100 insertions(+), 2 deletions(-) diff --git a/sys/dev/pci/pci_iov_schema.c b/sys/dev/pci/pci_iov_schema.c index 3cec329d77a1..804a8b1c0a8f 100644 --- a/sys/dev/pci/pci_iov_schema.c +++ b/sys/dev/pci/pci_iov_schema.c @@ -54,11 +54,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; @@ -107,6 +109,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 * @@ -261,6 +268,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) @@ -320,6 +347,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) @@ -400,6 +445,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) { diff --git a/sys/sys/iov.h b/sys/sys/iov.h index 0171fc5a98cf..2ae7e5ac6767 100644 --- a/sys/sys/iov.h +++ b/sys/sys/iov.h @@ -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 diff --git a/sys/sys/iov_schema.h b/sys/sys/iov_schema.h index cb50f7796d30..66c883540563 100644 --- a/sys/sys/iov_schema.h +++ b/sys/sys/iov_schema.h @@ -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 diff --git a/usr.sbin/iovctl/iovctl.c b/usr.sbin/iovctl/iovctl.c index 0110751082ec..28d2e0a93504 100644 --- a/usr.sbin/iovctl/iovctl.c +++ b/usr.sbin/iovctl/iovctl.c @@ -345,6 +345,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); } diff --git a/usr.sbin/iovctl/iovctl.conf.5 b/usr.sbin/iovctl/iovctl.conf.5 index a7eb6c2077ee..1bae96e150ba 100644 --- a/usr.sbin/iovctl/iovctl.conf.5 +++ b/usr.sbin/iovctl/iovctl.conf.5 @@ -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 diff --git a/usr.sbin/iovctl/parse.c b/usr.sbin/iovctl/parse.c index b1aad7d7ddd6..6b7645f341cc 100644 --- a/usr.sbin/iovctl/parse.c +++ b/usr.sbin/iovctl/parse.c @@ -160,6 +160,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. @@ -186,6 +209,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); }