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

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