From: Parav Pandit <parav@nvidia.com>
To: <virtualization@lists.linux-foundation.org>
Cc: Eli Cohen <elic@nvidia.com>, mst@redhat.com
Subject: [PATCH linux-next 4/9] vdpa_sim_net: Enable user to set mac address and mtu
Date: Wed, 24 Feb 2021 08:18:39 +0200 [thread overview]
Message-ID: <20210224061844.137776-5-parav@nvidia.com> (raw)
In-Reply-To: <20210224061844.137776-1-parav@nvidia.com>
Enable user to set the mac address and mtu so that each vdpa device
can have its own user specified mac address and mtu.
This is done by implementing the management device's configuration
layout fields setting callback routine.
Now that user is enabled to set the mac address, remove the module
parameter for same.
And example of setting mac addr and mtu:
$ vdpa mgmtdev show
$ vdpa dev add name bar mgmtdev vdpasim_net
$ vdpa dev config set bar mac 00:11:22:33:44:55 mtu 9000
View the config after setting:
$ vdpa dev config show
bar: mac 00:11:22:33:44:55 link up link_announce false mtu 9000 speed 0 duplex 0
Signed-off-by: Parav Pandit <parav@nvidia.com>
Reviewed-by: Eli Cohen <elic@nvidia.com>
---
drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 39 ++++++++++++++++------------
1 file changed, 22 insertions(+), 17 deletions(-)
diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c
index 240a5f1306b5..6e941b0e7935 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c
@@ -29,12 +29,6 @@
#define VDPASIM_NET_VQ_NUM 2
-static char *macaddr;
-module_param(macaddr, charp, 0);
-MODULE_PARM_DESC(macaddr, "Ethernet MAC address");
-
-static u8 macaddr_buf[ETH_ALEN];
-
static void vdpasim_net_work(struct work_struct *work)
{
struct vdpasim *vdpasim = container_of(work, struct vdpasim, work);
@@ -113,9 +107,7 @@ static void vdpasim_net_get_config(struct vdpasim *vdpasim, void *config)
struct virtio_net_config *net_config =
(struct virtio_net_config *)config;
- net_config->mtu = cpu_to_vdpasim16(vdpasim, 1500);
net_config->status = cpu_to_vdpasim16(vdpasim, VIRTIO_NET_S_LINK_UP);
- memcpy(net_config->mac, macaddr_buf, ETH_ALEN);
}
static void vdpasim_net_mgmtdev_release(struct device *dev)
@@ -134,6 +126,7 @@ static struct device vdpasim_net_mgmtdev_dummy = {
static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name)
{
+ struct virtio_net_config *cfg;
struct vdpasim_dev_attr dev_attr = {};
struct vdpasim *simdev;
int ret;
@@ -152,6 +145,10 @@ static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name)
if (IS_ERR(simdev))
return PTR_ERR(simdev);
+ cfg = simdev->config;
+ eth_random_addr(cfg->mac);
+ cfg->mtu = cpu_to_vdpasim16(simdev, 1500);
+
ret = _vdpa_register_device(&simdev->vdpa);
if (ret)
goto reg_err;
@@ -171,9 +168,25 @@ static void vdpasim_net_dev_del(struct vdpa_mgmt_dev *mdev,
_vdpa_unregister_device(&simdev->vdpa);
}
+static int
+vdpasim_net_dev_config_set(struct vdpa_mgmt_dev *mdev,
+ struct vdpa_device *dev,
+ const struct vdpa_dev_config_set_attr *attrs)
+{
+ struct vdpasim *simdev = container_of(dev, struct vdpasim, vdpa);
+ struct virtio_net_config *dev_cfg = simdev->config;
+
+ if (attrs->mask.mac_valid)
+ memcpy(dev_cfg->mac, attrs->cfg.mac, sizeof(dev_cfg->mac));
+ if (attrs->mask.mtu_valid)
+ dev_cfg->mtu = cpu_to_vdpasim16(simdev, attrs->cfg.mtu);
+ return 0;
+}
+
static const struct vdpa_mgmtdev_ops vdpasim_net_mgmtdev_ops = {
.dev_add = vdpasim_net_dev_add,
- .dev_del = vdpasim_net_dev_del
+ .dev_del = vdpasim_net_dev_del,
+ .dev_config_set = vdpasim_net_dev_config_set,
};
static struct virtio_device_id id_table[] = {
@@ -198,14 +211,6 @@ static int __init vdpasim_net_init(void)
{
int ret;
- if (macaddr) {
- mac_pton(macaddr, macaddr_buf);
- if (!is_valid_ether_addr(macaddr_buf))
- return -EADDRNOTAVAIL;
- } else {
- eth_random_addr(macaddr_buf);
- }
-
ret = device_register(&vdpasim_net_mgmtdev);
if (ret)
return ret;
--
2.26.2
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
next prev parent reply other threads:[~2021-02-24 6:19 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-24 6:18 [PATCH linux-next 0/9] vdpa: Enable user to set mac address, Parav Pandit
2021-02-24 6:18 ` [PATCH linux-next 1/9] vdpa_sim: Consider read only supported features instead of current Parav Pandit
2021-02-24 7:10 ` Michael S. Tsirkin
2021-02-26 7:36 ` Parav Pandit
2021-02-26 8:33 ` Jason Wang
2021-02-24 6:18 ` [PATCH linux-next 2/9] vdpa: Introduce query of device config layout Parav Pandit
2021-02-24 7:02 ` Michael S. Tsirkin
2021-02-24 11:18 ` Parav Pandit
2021-02-24 8:47 ` Jason Wang
2021-02-26 5:32 ` Parav Pandit
2021-02-26 8:26 ` Jason Wang
2021-02-26 8:50 ` Parav Pandit
2021-03-01 3:59 ` Jason Wang
2021-03-01 7:29 ` Parav Pandit
2021-03-01 7:50 ` Jason Wang
2021-03-01 10:28 ` Adrian Moreno
[not found] ` <abc1d3d7cd321620f6ae7f9ac0bb92fcce30a474.camel@redhat.com>
2021-03-02 4:25 ` Jason Wang
2021-03-03 9:24 ` Adrian Moreno
2021-02-24 6:18 ` [PATCH linux-next 3/9] vdpa: Enable user to set mac and mtu of vdpa device Parav Pandit
2021-02-24 6:18 ` Parav Pandit [this message]
2021-02-24 6:56 ` [PATCH linux-next 4/9] vdpa_sim_net: Enable user to set mac address and mtu Michael S. Tsirkin
2021-02-26 5:26 ` Parav Pandit
2021-02-24 6:18 ` [PATCH linux-next 5/9] vdpa_sim_net: Remove redundant get_config callback Parav Pandit
2021-02-24 6:18 ` [PATCH linux-next 6/9] vdpa/mlx5: Enable user to add/delete vdpa device Parav Pandit
2021-02-24 6:18 ` [PATCH linux-next 7/9] vdpa/mlx5: Provide device generated random MAC address Parav Pandit
2021-02-24 9:11 ` Jason Wang
[not found] ` <20210301070828.GA184680@mtl-vdi-166.wap.labs.mlnx>
2021-03-01 13:09 ` Michael S. Tsirkin
[not found] ` <20210301131951.GA196924@mtl-vdi-166.wap.labs.mlnx>
2021-03-01 16:12 ` Michael S. Tsirkin
2021-03-02 4:10 ` Jason Wang
[not found] ` <20210302053919.GB227464@mtl-vdi-166.wap.labs.mlnx>
2021-03-03 3:59 ` Parav Pandit
[not found] ` <20210303063350.GA29123@mtl-vdi-166.wap.labs.mlnx>
2021-03-03 9:29 ` Michael S. Tsirkin
2021-03-03 10:01 ` Parav Pandit
2021-03-03 9:35 ` Michael S. Tsirkin
2021-02-24 6:18 ` [PATCH linux-next 8/9] vdpa/mlx5: Support configuration of MAC Parav Pandit
2021-02-24 9:12 ` Jason Wang
2021-02-24 6:18 ` [PATCH linux-next 9/9] vdpa/mlx5: Forward only packets with allowed MAC address Parav Pandit
2021-02-24 9:14 ` Jason Wang
2021-02-24 6:51 ` [PATCH linux-next 0/9] vdpa: Enable user to set mac address, Michael S. Tsirkin
2021-02-24 8:02 ` Parav Pandit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210224061844.137776-5-parav@nvidia.com \
--to=parav@nvidia.com \
--cc=elic@nvidia.com \
--cc=mst@redhat.com \
--cc=virtualization@lists.linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).