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

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