]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
vdpa: Enable user to set mtu of the vdpa device
authorParav Pandit <parav@nvidia.com>
Fri, 17 Dec 2021 08:08:27 +0000 (10:08 +0200)
committerDavid Ahern <dsahern@kernel.org>
Sat, 18 Dec 2021 21:04:14 +0000 (14:04 -0700)
Implement mtu setting for vdpa device.

$ vdpa mgmtdev show
vdpasim_net:
  supported_classes net

Add the device with mac address and mtu:
$ vdpa dev add name bar mgmtdev vdpasim_net mac 00:11:22:33:44:55 mtu 9000

In above command only mac address or only mtu can also be set.

View the config after setting:
$ vdpa dev config show
bar: mac 00:11:22:33:44:55 link up link_announce false mtu 9000

Signed-off-by: Parav Pandit <parav@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
man/man8/vdpa-dev.8
vdpa/vdpa.c

index 5c5ac469f3df01031d0460b011cb24be04edd48d..aa21ae3acbd86a9a5704bdde57577fd5a459321b 100644 (file)
@@ -32,6 +32,7 @@ vdpa-dev \- vdpa device configuration
 .B mgmtdev
 .I MGMTDEV
 .RI "[ mac " MACADDR " ]"
+.RI "[ mtu " MTU " ]"
 
 .ti -8
 .B vdpa dev del
@@ -69,6 +70,10 @@ Name of the management device to use for device addition.
 - specifies the mac address for the new vdpa device.
 This is applicable only for the network type of vdpa device. This is optional.
 
+.BI mtu " MTU"
+- specifies the mtu for the new vdpa device.
+This is applicable only for the network type of vdpa device. This is optional.
+
 .SS vdpa dev del - Delete the vdpa device.
 
 .PP
@@ -109,6 +114,11 @@ vdpa dev add name foo mgmtdev vdpa_sim_net mac 00:11:22:33:44:55
 Add the vdpa device named foo on the management device vdpa_sim_net with mac address of 00:11:22:33:44:55.
 .RE
 .PP
+vdpa dev add name foo mgmtdev vdpa_sim_net mac 00:11:22:33:44:55 mtu 9000
+.RS 4
+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.
+.RE
+.PP
 vdpa dev del foo
 .RS 4
 Delete the vdpa device named foo which was previously created.
index 63d464d17a49fc108a4998fbd97e64a54078b228..f048e470c929b8504a925a521388a376aae87847 100644 (file)
@@ -22,6 +22,7 @@
 #define VDPA_OPT_VDEV_NAME             BIT(2)
 #define VDPA_OPT_VDEV_HANDLE           BIT(3)
 #define VDPA_OPT_VDEV_MAC              BIT(4)
+#define VDPA_OPT_VDEV_MTU              BIT(5)
 
 struct vdpa_opts {
        uint64_t present; /* flags of present items */
@@ -30,6 +31,7 @@ struct vdpa_opts {
        const char *vdev_name;
        unsigned int device_id;
        char mac[ETH_ALEN];
+       uint16_t mtu;
 };
 
 struct vdpa {
@@ -154,6 +156,17 @@ static int vdpa_argv_mac(struct vdpa *vdpa, int argc, char **argv, char *mac)
        return 0;
 }
 
+static int vdpa_argv_u16(struct vdpa *vdpa, int argc, char **argv,
+                        uint16_t *result)
+{
+       if (argc <= 0 || *argv == NULL) {
+               fprintf(stderr, "number expected\n");
+               return -EINVAL;
+       }
+
+       return get_u16(result, *argv, 10);
+}
+
 struct vdpa_args_metadata {
        uint64_t o_flag;
        const char *err_msg;
@@ -204,6 +217,8 @@ static void vdpa_opts_put(struct nlmsghdr *nlh, struct vdpa *vdpa)
        if (opts->present & VDPA_OPT_VDEV_MAC)
                mnl_attr_put(nlh, VDPA_ATTR_DEV_NET_CFG_MACADDR,
                             sizeof(opts->mac), opts->mac);
+       if (opts->present & VDPA_OPT_VDEV_MTU)
+               mnl_attr_put_u16(nlh, VDPA_ATTR_DEV_NET_CFG_MTU, opts->mtu);
 }
 
 static int vdpa_argv_parse(struct vdpa *vdpa, int argc, char **argv,
@@ -263,6 +278,15 @@ static int vdpa_argv_parse(struct vdpa *vdpa, int argc, char **argv,
 
                        NEXT_ARG_FWD();
                        o_found |= VDPA_OPT_VDEV_MAC;
+               } else if ((strcmp(*argv, "mtu") == 0) &&
+                          (o_all & VDPA_OPT_VDEV_MTU)) {
+                       NEXT_ARG_FWD();
+                       err = vdpa_argv_u16(vdpa, argc, argv, &opts->mtu);
+                       if (err)
+                               return err;
+
+                       NEXT_ARG_FWD();
+                       o_found |= VDPA_OPT_VDEV_MTU;
                } else {
                        fprintf(stderr, "Unknown option \"%s\"\n", *argv);
                        return -EINVAL;
@@ -443,7 +467,7 @@ static int cmd_mgmtdev(struct vdpa *vdpa, int argc, char **argv)
 static void cmd_dev_help(void)
 {
        fprintf(stderr, "Usage: vdpa dev show [ DEV ]\n");
-       fprintf(stderr, "       vdpa dev add name NAME mgmtdev MANAGEMENTDEV [ mac MACADDR ]\n");
+       fprintf(stderr, "       vdpa dev add name NAME mgmtdev MANAGEMENTDEV [ mac MACADDR ] [ mtu MTU ]\n");
        fprintf(stderr, "       vdpa dev del DEV\n");
        fprintf(stderr, "Usage: vdpa dev config COMMAND [ OPTIONS ]\n");
 }
@@ -533,7 +557,7 @@ static int cmd_dev_add(struct vdpa *vdpa, int argc, char **argv)
                                          NLM_F_REQUEST | NLM_F_ACK);
        err = vdpa_argv_parse_put(nlh, vdpa, argc, argv,
                                  VDPA_OPT_VDEV_MGMTDEV_HANDLE | VDPA_OPT_VDEV_NAME,
-                                 VDPA_OPT_VDEV_MAC);
+                                 VDPA_OPT_VDEV_MAC | VDPA_OPT_VDEV_MTU);
        if (err)
                return err;