|
|
b6425b |
From f5af49ce12667a6331d1a866d52e67fc27308f5d Mon Sep 17 00:00:00 2001
|
|
|
b6425b |
Message-Id: <f5af49ce12667a6331d1a866d52e67fc27308f5d.1647984433.git.aclaudi@redhat.com>
|
|
|
b6425b |
In-Reply-To: <cef782ca658d695c5ca2d174ba1f89cba6bd84e5.1647984433.git.aclaudi@redhat.com>
|
|
|
b6425b |
References: <cef782ca658d695c5ca2d174ba1f89cba6bd84e5.1647984433.git.aclaudi@redhat.com>
|
|
|
b6425b |
From: Andrea Claudi <aclaudi@redhat.com>
|
|
|
b6425b |
Date: Mon, 21 Mar 2022 16:35:15 +0100
|
|
|
b6425b |
Subject: [PATCH] vdpa: Enable user to set mac address of vdpa device
|
|
|
b6425b |
|
|
|
b6425b |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2059427
|
|
|
b6425b |
Upstream Status: iproute2-next.git commit 384938f9
|
|
|
b6425b |
|
|
|
b6425b |
commit 384938f9b00f2d203603e0919f23ae6857a14d96
|
|
|
b6425b |
Author: Parav Pandit <parav@nvidia.com>
|
|
|
b6425b |
Date: Fri Dec 17 10:08:26 2021 +0200
|
|
|
b6425b |
|
|
|
b6425b |
vdpa: Enable user to set mac address of vdpa device
|
|
|
b6425b |
|
|
|
b6425b |
vdpa: Enable user to set mtu of the vdpa device
|
|
|
b6425b |
|
|
|
b6425b |
Implement mtu setting for vdpa device.
|
|
|
b6425b |
|
|
|
b6425b |
$ vdpa mgmtdev show
|
|
|
b6425b |
vdpasim_net:
|
|
|
b6425b |
supported_classes net
|
|
|
b6425b |
|
|
|
b6425b |
Add the device with specified mac address:
|
|
|
b6425b |
$ vdpa dev add name bar mgmtdev vdpasim_net mac 00:11:22:33:44:55
|
|
|
b6425b |
|
|
|
b6425b |
View the config after setting:
|
|
|
b6425b |
$ vdpa dev config show
|
|
|
b6425b |
bar: mac 00:11:22:33:44:55 link up link_announce false mtu 1500
|
|
|
b6425b |
|
|
|
b6425b |
Signed-off-by: Parav Pandit <parav@nvidia.com>
|
|
|
b6425b |
Signed-off-by: David Ahern <dsahern@kernel.org>
|
|
|
b6425b |
---
|
|
|
b6425b |
man/man8/vdpa-dev.8 | 11 ++++++++++
|
|
|
b6425b |
vdpa/vdpa.c | 52 ++++++++++++++++++++++++++++++++++++---------
|
|
|
b6425b |
2 files changed, 53 insertions(+), 10 deletions(-)
|
|
|
b6425b |
|
|
|
b6425b |
diff --git a/man/man8/vdpa-dev.8 b/man/man8/vdpa-dev.8
|
|
|
b6425b |
index 5d3a3f26..5c5ac469 100644
|
|
|
b6425b |
--- a/man/man8/vdpa-dev.8
|
|
|
b6425b |
+++ b/man/man8/vdpa-dev.8
|
|
|
b6425b |
@@ -31,6 +31,7 @@ vdpa-dev \- vdpa device configuration
|
|
|
b6425b |
.I NAME
|
|
|
b6425b |
.B mgmtdev
|
|
|
b6425b |
.I MGMTDEV
|
|
|
b6425b |
+.RI "[ mac " MACADDR " ]"
|
|
|
b6425b |
|
|
|
b6425b |
.ti -8
|
|
|
b6425b |
.B vdpa dev del
|
|
|
b6425b |
@@ -63,6 +64,11 @@ Name of the new vdpa device to add.
|
|
|
b6425b |
.BI mgmtdev " MGMTDEV"
|
|
|
b6425b |
Name of the management device to use for device addition.
|
|
|
b6425b |
|
|
|
b6425b |
+.PP
|
|
|
b6425b |
+.BI mac " MACADDR"
|
|
|
b6425b |
+- specifies the mac address for the new vdpa device.
|
|
|
b6425b |
+This is applicable only for the network type of vdpa device. This is optional.
|
|
|
b6425b |
+
|
|
|
b6425b |
.SS vdpa dev del - Delete the vdpa device.
|
|
|
b6425b |
|
|
|
b6425b |
.PP
|
|
|
b6425b |
@@ -98,6 +104,11 @@ vdpa dev add name foo mgmtdev vdpa_sim_net
|
|
|
b6425b |
Add the vdpa device named foo on the management device vdpa_sim_net.
|
|
|
b6425b |
.RE
|
|
|
b6425b |
.PP
|
|
|
b6425b |
+vdpa dev add name foo mgmtdev vdpa_sim_net mac 00:11:22:33:44:55
|
|
|
b6425b |
+.RS 4
|
|
|
b6425b |
+Add the vdpa device named foo on the management device vdpa_sim_net with mac address of 00:11:22:33:44:55.
|
|
|
b6425b |
+.RE
|
|
|
b6425b |
+.PP
|
|
|
b6425b |
vdpa dev del foo
|
|
|
b6425b |
.RS 4
|
|
|
b6425b |
Delete the vdpa device named foo which was previously created.
|
|
|
b6425b |
diff --git a/vdpa/vdpa.c b/vdpa/vdpa.c
|
|
|
b6425b |
index ba704254..63d464d1 100644
|
|
|
b6425b |
--- a/vdpa/vdpa.c
|
|
|
b6425b |
+++ b/vdpa/vdpa.c
|
|
|
b6425b |
@@ -4,6 +4,7 @@
|
|
|
b6425b |
#include <getopt.h>
|
|
|
b6425b |
#include <errno.h>
|
|
|
b6425b |
#include <linux/genetlink.h>
|
|
|
b6425b |
+#include <linux/if_ether.h>
|
|
|
b6425b |
#include <linux/vdpa.h>
|
|
|
b6425b |
#include <linux/virtio_ids.h>
|
|
|
b6425b |
#include <linux/virtio_net.h>
|
|
|
b6425b |
@@ -20,6 +21,7 @@
|
|
|
b6425b |
#define VDPA_OPT_VDEV_MGMTDEV_HANDLE BIT(1)
|
|
|
b6425b |
#define VDPA_OPT_VDEV_NAME BIT(2)
|
|
|
b6425b |
#define VDPA_OPT_VDEV_HANDLE BIT(3)
|
|
|
b6425b |
+#define VDPA_OPT_VDEV_MAC BIT(4)
|
|
|
b6425b |
|
|
|
b6425b |
struct vdpa_opts {
|
|
|
b6425b |
uint64_t present; /* flags of present items */
|
|
|
b6425b |
@@ -27,6 +29,7 @@ struct vdpa_opts {
|
|
|
b6425b |
char *mdev_name;
|
|
|
b6425b |
const char *vdev_name;
|
|
|
b6425b |
unsigned int device_id;
|
|
|
b6425b |
+ char mac[ETH_ALEN];
|
|
|
b6425b |
};
|
|
|
b6425b |
|
|
|
b6425b |
struct vdpa {
|
|
|
b6425b |
@@ -136,6 +139,21 @@ static int vdpa_argv_str(struct vdpa *vdpa, int argc, char **argv,
|
|
|
b6425b |
return 0;
|
|
|
b6425b |
}
|
|
|
b6425b |
|
|
|
b6425b |
+static int vdpa_argv_mac(struct vdpa *vdpa, int argc, char **argv, char *mac)
|
|
|
b6425b |
+{
|
|
|
b6425b |
+ int alen;
|
|
|
b6425b |
+
|
|
|
b6425b |
+ if (argc <= 0 || *argv == NULL) {
|
|
|
b6425b |
+ fprintf(stderr, "String parameter expected\n");
|
|
|
b6425b |
+ return -EINVAL;
|
|
|
b6425b |
+ }
|
|
|
b6425b |
+
|
|
|
b6425b |
+ alen = ll_addr_a2n(mac, ETH_ALEN, *argv);
|
|
|
b6425b |
+ if (alen < 0)
|
|
|
b6425b |
+ return -EINVAL;
|
|
|
b6425b |
+ return 0;
|
|
|
b6425b |
+}
|
|
|
b6425b |
+
|
|
|
b6425b |
struct vdpa_args_metadata {
|
|
|
b6425b |
uint64_t o_flag;
|
|
|
b6425b |
const char *err_msg;
|
|
|
b6425b |
@@ -183,13 +201,16 @@ static void vdpa_opts_put(struct nlmsghdr *nlh, struct vdpa *vdpa)
|
|
|
b6425b |
if ((opts->present & VDPA_OPT_VDEV_NAME) ||
|
|
|
b6425b |
(opts->present & VDPA_OPT_VDEV_HANDLE))
|
|
|
b6425b |
mnl_attr_put_strz(nlh, VDPA_ATTR_DEV_NAME, opts->vdev_name);
|
|
|
b6425b |
+ if (opts->present & VDPA_OPT_VDEV_MAC)
|
|
|
b6425b |
+ mnl_attr_put(nlh, VDPA_ATTR_DEV_NET_CFG_MACADDR,
|
|
|
b6425b |
+ sizeof(opts->mac), opts->mac);
|
|
|
b6425b |
}
|
|
|
b6425b |
|
|
|
b6425b |
static int vdpa_argv_parse(struct vdpa *vdpa, int argc, char **argv,
|
|
|
b6425b |
- uint64_t o_required)
|
|
|
b6425b |
+ uint64_t o_required, uint64_t o_optional)
|
|
|
b6425b |
{
|
|
|
b6425b |
+ uint64_t o_all = o_required | o_optional;
|
|
|
b6425b |
struct vdpa_opts *opts = &vdpa->opts;
|
|
|
b6425b |
- uint64_t o_all = o_required;
|
|
|
b6425b |
uint64_t o_found = 0;
|
|
|
b6425b |
int err;
|
|
|
b6425b |
|
|
|
b6425b |
@@ -233,6 +254,15 @@ static int vdpa_argv_parse(struct vdpa *vdpa, int argc, char **argv,
|
|
|
b6425b |
|
|
|
b6425b |
NEXT_ARG_FWD();
|
|
|
b6425b |
o_found |= VDPA_OPT_VDEV_MGMTDEV_HANDLE;
|
|
|
b6425b |
+ } else if ((strcmp(*argv, "mac") == 0) &&
|
|
|
b6425b |
+ (o_all & VDPA_OPT_VDEV_MAC)) {
|
|
|
b6425b |
+ NEXT_ARG_FWD();
|
|
|
b6425b |
+ err = vdpa_argv_mac(vdpa, argc, argv, opts->mac);
|
|
|
b6425b |
+ if (err)
|
|
|
b6425b |
+ return err;
|
|
|
b6425b |
+
|
|
|
b6425b |
+ NEXT_ARG_FWD();
|
|
|
b6425b |
+ o_found |= VDPA_OPT_VDEV_MAC;
|
|
|
b6425b |
} else {
|
|
|
b6425b |
fprintf(stderr, "Unknown option \"%s\"\n", *argv);
|
|
|
b6425b |
return -EINVAL;
|
|
|
b6425b |
@@ -246,11 +276,11 @@ static int vdpa_argv_parse(struct vdpa *vdpa, int argc, char **argv,
|
|
|
b6425b |
|
|
|
b6425b |
static int vdpa_argv_parse_put(struct nlmsghdr *nlh, struct vdpa *vdpa,
|
|
|
b6425b |
int argc, char **argv,
|
|
|
b6425b |
- uint64_t o_required)
|
|
|
b6425b |
+ uint64_t o_required, uint64_t o_optional)
|
|
|
b6425b |
{
|
|
|
b6425b |
int err;
|
|
|
b6425b |
|
|
|
b6425b |
- err = vdpa_argv_parse(vdpa, argc, argv, o_required);
|
|
|
b6425b |
+ err = vdpa_argv_parse(vdpa, argc, argv, o_required, o_optional);
|
|
|
b6425b |
if (err)
|
|
|
b6425b |
return err;
|
|
|
b6425b |
vdpa_opts_put(nlh, vdpa);
|
|
|
b6425b |
@@ -386,7 +416,7 @@ static int cmd_mgmtdev_show(struct vdpa *vdpa, int argc, char **argv)
|
|
|
b6425b |
flags);
|
|
|
b6425b |
if (argc > 0) {
|
|
|
b6425b |
err = vdpa_argv_parse_put(nlh, vdpa, argc, argv,
|
|
|
b6425b |
- VDPA_OPT_MGMTDEV_HANDLE);
|
|
|
b6425b |
+ VDPA_OPT_MGMTDEV_HANDLE, 0);
|
|
|
b6425b |
if (err)
|
|
|
b6425b |
return err;
|
|
|
b6425b |
}
|
|
|
b6425b |
@@ -413,7 +443,7 @@ static int cmd_mgmtdev(struct vdpa *vdpa, int argc, char **argv)
|
|
|
b6425b |
static void cmd_dev_help(void)
|
|
|
b6425b |
{
|
|
|
b6425b |
fprintf(stderr, "Usage: vdpa dev show [ DEV ]\n");
|
|
|
b6425b |
- fprintf(stderr, " vdpa dev add name NAME mgmtdev MANAGEMENTDEV\n");
|
|
|
b6425b |
+ fprintf(stderr, " vdpa dev add name NAME mgmtdev MANAGEMENTDEV [ mac MACADDR ]\n");
|
|
|
b6425b |
fprintf(stderr, " vdpa dev del DEV\n");
|
|
|
b6425b |
fprintf(stderr, "Usage: vdpa dev config COMMAND [ OPTIONS ]\n");
|
|
|
b6425b |
}
|
|
|
b6425b |
@@ -483,7 +513,7 @@ static int cmd_dev_show(struct vdpa *vdpa, int argc, char **argv)
|
|
|
b6425b |
nlh = mnlu_gen_socket_cmd_prepare(&vdpa->nlg, VDPA_CMD_DEV_GET, flags);
|
|
|
b6425b |
if (argc > 0) {
|
|
|
b6425b |
err = vdpa_argv_parse_put(nlh, vdpa, argc, argv,
|
|
|
b6425b |
- VDPA_OPT_VDEV_HANDLE);
|
|
|
b6425b |
+ VDPA_OPT_VDEV_HANDLE, 0);
|
|
|
b6425b |
if (err)
|
|
|
b6425b |
return err;
|
|
|
b6425b |
}
|
|
|
b6425b |
@@ -502,7 +532,8 @@ static int cmd_dev_add(struct vdpa *vdpa, int argc, char **argv)
|
|
|
b6425b |
nlh = mnlu_gen_socket_cmd_prepare(&vdpa->nlg, VDPA_CMD_DEV_NEW,
|
|
|
b6425b |
NLM_F_REQUEST | NLM_F_ACK);
|
|
|
b6425b |
err = vdpa_argv_parse_put(nlh, vdpa, argc, argv,
|
|
|
b6425b |
- VDPA_OPT_VDEV_MGMTDEV_HANDLE | VDPA_OPT_VDEV_NAME);
|
|
|
b6425b |
+ VDPA_OPT_VDEV_MGMTDEV_HANDLE | VDPA_OPT_VDEV_NAME,
|
|
|
b6425b |
+ VDPA_OPT_VDEV_MAC);
|
|
|
b6425b |
if (err)
|
|
|
b6425b |
return err;
|
|
|
b6425b |
|
|
|
b6425b |
@@ -516,7 +547,8 @@ static int cmd_dev_del(struct vdpa *vdpa, int argc, char **argv)
|
|
|
b6425b |
|
|
|
b6425b |
nlh = mnlu_gen_socket_cmd_prepare(&vdpa->nlg, VDPA_CMD_DEV_DEL,
|
|
|
b6425b |
NLM_F_REQUEST | NLM_F_ACK);
|
|
|
b6425b |
- err = vdpa_argv_parse_put(nlh, vdpa, argc, argv, VDPA_OPT_VDEV_HANDLE);
|
|
|
b6425b |
+ err = vdpa_argv_parse_put(nlh, vdpa, argc, argv, VDPA_OPT_VDEV_HANDLE,
|
|
|
b6425b |
+ 0);
|
|
|
b6425b |
if (err)
|
|
|
b6425b |
return err;
|
|
|
b6425b |
|
|
|
b6425b |
@@ -597,7 +629,7 @@ static int cmd_dev_config_show(struct vdpa *vdpa, int argc, char **argv)
|
|
|
b6425b |
flags);
|
|
|
b6425b |
if (argc > 0) {
|
|
|
b6425b |
err = vdpa_argv_parse_put(nlh, vdpa, argc, argv,
|
|
|
b6425b |
- VDPA_OPT_VDEV_HANDLE);
|
|
|
b6425b |
+ VDPA_OPT_VDEV_HANDLE, 0);
|
|
|
b6425b |
if (err)
|
|
|
b6425b |
return err;
|
|
|
b6425b |
}
|
|
|
b6425b |
--
|
|
|
b6425b |
2.35.1
|
|
|
b6425b |
|