naccyde / rpms / iproute

Forked from rpms/iproute 7 months ago
Clone

Blame SOURCES/0011-vdpa-Enable-user-to-set-mtu-of-the-vdpa-device.patch

6548d8
From 6af0b1f5f1848689ee3c4cd00af224309185c644 Mon Sep 17 00:00:00 2001
6548d8
Message-Id: <6af0b1f5f1848689ee3c4cd00af224309185c644.1643220552.git.aclaudi@redhat.com>
6548d8
In-Reply-To: <b30268eda844bdebbb8e5e4f5735e3b1bb666368.1643220552.git.aclaudi@redhat.com>
6548d8
References: <b30268eda844bdebbb8e5e4f5735e3b1bb666368.1643220552.git.aclaudi@redhat.com>
6548d8
From: Andrea Claudi <aclaudi@redhat.com>
6548d8
Date: Wed, 26 Jan 2022 10:39:38 +0100
6548d8
Subject: [PATCH] vdpa: Enable user to set mtu of the vdpa device
6548d8
6548d8
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2036880
6548d8
Upstream Status: iproute2.git commit 167e33f3
6548d8
6548d8
commit 167e33f3be88c0fbe206df25145b850ddf3897a2
6548d8
Author: Parav Pandit <parav@nvidia.com>
6548d8
Date:   Fri Dec 17 10:08:27 2021 +0200
6548d8
6548d8
    vdpa: Enable user to set mtu of the vdpa device
6548d8
6548d8
    Implement mtu setting for vdpa device.
6548d8
6548d8
    $ vdpa mgmtdev show
6548d8
    vdpasim_net:
6548d8
      supported_classes net
6548d8
6548d8
    Add the device with mac address and mtu:
6548d8
    $ vdpa dev add name bar mgmtdev vdpasim_net mac 00:11:22:33:44:55 mtu 9000
6548d8
6548d8
    In above command only mac address or only mtu can also be set.
6548d8
6548d8
    View the config after setting:
6548d8
    $ vdpa dev config show
6548d8
    bar: mac 00:11:22:33:44:55 link up link_announce false mtu 9000
6548d8
6548d8
    Signed-off-by: Parav Pandit <parav@nvidia.com>
6548d8
    Signed-off-by: David Ahern <dsahern@kernel.org>
6548d8
---
6548d8
 man/man8/vdpa-dev.8 | 10 ++++++++++
6548d8
 vdpa/vdpa.c         | 28 ++++++++++++++++++++++++++--
6548d8
 2 files changed, 36 insertions(+), 2 deletions(-)
6548d8
6548d8
diff --git a/man/man8/vdpa-dev.8 b/man/man8/vdpa-dev.8
6548d8
index 5c5ac469..aa21ae3a 100644
6548d8
--- a/man/man8/vdpa-dev.8
6548d8
+++ b/man/man8/vdpa-dev.8
6548d8
@@ -32,6 +32,7 @@ vdpa-dev \- vdpa device configuration
6548d8
 .B mgmtdev
6548d8
 .I MGMTDEV
6548d8
 .RI "[ mac " MACADDR " ]"
6548d8
+.RI "[ mtu " MTU " ]"
6548d8
 
6548d8
 .ti -8
6548d8
 .B vdpa dev del
6548d8
@@ -69,6 +70,10 @@ Name of the management device to use for device addition.
6548d8
 - specifies the mac address for the new vdpa device.
6548d8
 This is applicable only for the network type of vdpa device. This is optional.
6548d8
 
6548d8
+.BI mtu " MTU"
6548d8
+- specifies the mtu for the new vdpa device.
6548d8
+This is applicable only for the network type of vdpa device. This is optional.
6548d8
+
6548d8
 .SS vdpa dev del - Delete the vdpa device.
6548d8
 
6548d8
 .PP
6548d8
@@ -109,6 +114,11 @@ vdpa dev add name foo mgmtdev vdpa_sim_net mac 00:11:22:33:44:55
6548d8
 Add the vdpa device named foo on the management device vdpa_sim_net with mac address of 00:11:22:33:44:55.
6548d8
 .RE
6548d8
 .PP
6548d8
+vdpa dev add name foo mgmtdev vdpa_sim_net mac 00:11:22:33:44:55 mtu 9000
6548d8
+.RS 4
6548d8
+Add the vdpa device named foo on the management device vdpa_sim_net with mac address of 00:11:22:33:44:55 and mtu of 9000 bytes.
6548d8
+.RE
6548d8
+.PP
6548d8
 vdpa dev del foo
6548d8
 .RS 4
6548d8
 Delete the vdpa device named foo which was previously created.
6548d8
diff --git a/vdpa/vdpa.c b/vdpa/vdpa.c
6548d8
index 63d464d1..f048e470 100644
6548d8
--- a/vdpa/vdpa.c
6548d8
+++ b/vdpa/vdpa.c
6548d8
@@ -22,6 +22,7 @@
6548d8
 #define VDPA_OPT_VDEV_NAME		BIT(2)
6548d8
 #define VDPA_OPT_VDEV_HANDLE		BIT(3)
6548d8
 #define VDPA_OPT_VDEV_MAC		BIT(4)
6548d8
+#define VDPA_OPT_VDEV_MTU		BIT(5)
6548d8
 
6548d8
 struct vdpa_opts {
6548d8
 	uint64_t present; /* flags of present items */
6548d8
@@ -30,6 +31,7 @@ struct vdpa_opts {
6548d8
 	const char *vdev_name;
6548d8
 	unsigned int device_id;
6548d8
 	char mac[ETH_ALEN];
6548d8
+	uint16_t mtu;
6548d8
 };
6548d8
 
6548d8
 struct vdpa {
6548d8
@@ -154,6 +156,17 @@ static int vdpa_argv_mac(struct vdpa *vdpa, int argc, char **argv, char *mac)
6548d8
 	return 0;
6548d8
 }
6548d8
 
6548d8
+static int vdpa_argv_u16(struct vdpa *vdpa, int argc, char **argv,
6548d8
+			 uint16_t *result)
6548d8
+{
6548d8
+	if (argc <= 0 || *argv == NULL) {
6548d8
+		fprintf(stderr, "number expected\n");
6548d8
+		return -EINVAL;
6548d8
+	}
6548d8
+
6548d8
+	return get_u16(result, *argv, 10);
6548d8
+}
6548d8
+
6548d8
 struct vdpa_args_metadata {
6548d8
 	uint64_t o_flag;
6548d8
 	const char *err_msg;
6548d8
@@ -204,6 +217,8 @@ static void vdpa_opts_put(struct nlmsghdr *nlh, struct vdpa *vdpa)
6548d8
 	if (opts->present & VDPA_OPT_VDEV_MAC)
6548d8
 		mnl_attr_put(nlh, VDPA_ATTR_DEV_NET_CFG_MACADDR,
6548d8
 			     sizeof(opts->mac), opts->mac);
6548d8
+	if (opts->present & VDPA_OPT_VDEV_MTU)
6548d8
+		mnl_attr_put_u16(nlh, VDPA_ATTR_DEV_NET_CFG_MTU, opts->mtu);
6548d8
 }
6548d8
 
6548d8
 static int vdpa_argv_parse(struct vdpa *vdpa, int argc, char **argv,
6548d8
@@ -263,6 +278,15 @@ static int vdpa_argv_parse(struct vdpa *vdpa, int argc, char **argv,
6548d8
 
6548d8
 			NEXT_ARG_FWD();
6548d8
 			o_found |= VDPA_OPT_VDEV_MAC;
6548d8
+		} else if ((strcmp(*argv, "mtu") == 0) &&
6548d8
+			   (o_all & VDPA_OPT_VDEV_MTU)) {
6548d8
+			NEXT_ARG_FWD();
6548d8
+			err = vdpa_argv_u16(vdpa, argc, argv, &opts->mtu);
6548d8
+			if (err)
6548d8
+				return err;
6548d8
+
6548d8
+			NEXT_ARG_FWD();
6548d8
+			o_found |= VDPA_OPT_VDEV_MTU;
6548d8
 		} else {
6548d8
 			fprintf(stderr, "Unknown option \"%s\"\n", *argv);
6548d8
 			return -EINVAL;
6548d8
@@ -443,7 +467,7 @@ static int cmd_mgmtdev(struct vdpa *vdpa, int argc, char **argv)
6548d8
 static void cmd_dev_help(void)
6548d8
 {
6548d8
 	fprintf(stderr, "Usage: vdpa dev show [ DEV ]\n");
6548d8
-	fprintf(stderr, "       vdpa dev add name NAME mgmtdev MANAGEMENTDEV [ mac MACADDR ]\n");
6548d8
+	fprintf(stderr, "       vdpa dev add name NAME mgmtdev MANAGEMENTDEV [ mac MACADDR ] [ mtu MTU ]\n");
6548d8
 	fprintf(stderr, "       vdpa dev del DEV\n");
6548d8
 	fprintf(stderr, "Usage: vdpa dev config COMMAND [ OPTIONS ]\n");
6548d8
 }
6548d8
@@ -533,7 +557,7 @@ static int cmd_dev_add(struct vdpa *vdpa, int argc, char **argv)
6548d8
 					  NLM_F_REQUEST | NLM_F_ACK);
6548d8
 	err = vdpa_argv_parse_put(nlh, vdpa, argc, argv,
6548d8
 				  VDPA_OPT_VDEV_MGMTDEV_HANDLE | VDPA_OPT_VDEV_NAME,
6548d8
-				  VDPA_OPT_VDEV_MAC);
6548d8
+				  VDPA_OPT_VDEV_MAC | VDPA_OPT_VDEV_MTU);
6548d8
 	if (err)
6548d8
 		return err;
6548d8
 
6548d8
-- 
6548d8
2.34.1
6548d8