From: Parav Pandit <parav@nvidia.com>
To: <virtualization@lists.linux-foundation.org>
Cc: elic@nvidia.com, mst@redhat.com
Subject: [PATCH linux-next v2 06/14] vdpa_sim_net: Enable user to set mac address and mtu
Date: Tue, 6 Apr 2021 20:04:49 +0300 [thread overview]
Message-ID: <20210406170457.98481-7-parav@nvidia.com> (raw)
In-Reply-To: <20210406170457.98481-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>
---
changelog:
v1->v2:
- using updated interface and callbacks for get/set config
---
drivers/vdpa/vdpa_sim/vdpa_sim.c | 26 +++++++++++++++++++
drivers/vdpa/vdpa_sim/vdpa_sim.h | 4 +++
drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 39 +++++++++++++++++-----------
3 files changed, 54 insertions(+), 15 deletions(-)
diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index 5b6b2f87d40c..5d59e06ab224 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -467,6 +467,28 @@ static void vdpasim_set_config(struct vdpa_device *vdpa, unsigned int offset,
vdpasim->dev_attr.set_config(vdpasim, vdpasim->config);
}
+static void vdpasim_get_ce_config(struct vdpa_device *vdpa,
+ struct vdpa_dev_config *config)
+{
+ struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
+
+ if (!vdpasim->dev_attr.get_ce_config)
+ return;
+
+ vdpasim->dev_attr.get_ce_config(vdpasim, config);
+}
+
+static int vdpasim_set_ce_config(struct vdpa_device *vdpa,
+ const struct vdpa_dev_set_config *config)
+{
+ struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
+
+ if (!vdpasim->dev_attr.set_ce_config)
+ return -EOPNOTSUPP;
+
+ return vdpasim->dev_attr.set_ce_config(vdpasim, config);
+}
+
static u32 vdpasim_get_generation(struct vdpa_device *vdpa)
{
struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
@@ -568,6 +590,8 @@ static const struct vdpa_config_ops vdpasim_config_ops = {
.set_status = vdpasim_set_status,
.get_config = vdpasim_get_config,
.set_config = vdpasim_set_config,
+ .get_ce_config = vdpasim_get_ce_config,
+ .set_ce_config = vdpasim_set_ce_config,
.get_generation = vdpasim_get_generation,
.get_iova_range = vdpasim_get_iova_range,
.dma_map = vdpasim_dma_map,
@@ -595,6 +619,8 @@ static const struct vdpa_config_ops vdpasim_batch_config_ops = {
.set_status = vdpasim_set_status,
.get_config = vdpasim_get_config,
.set_config = vdpasim_set_config,
+ .get_ce_config = vdpasim_get_ce_config,
+ .set_ce_config = vdpasim_set_ce_config,
.get_generation = vdpasim_get_generation,
.get_iova_range = vdpasim_get_iova_range,
.set_map = vdpasim_set_map,
diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.h b/drivers/vdpa/vdpa_sim/vdpa_sim.h
index 6d75444f9948..62a21a4567cf 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.h
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.h
@@ -44,6 +44,10 @@ struct vdpasim_dev_attr {
work_func_t work_fn;
void (*get_config)(struct vdpasim *vdpasim, void *config);
void (*set_config)(struct vdpasim *vdpasim, const void *config);
+ void (*get_ce_config)(struct vdpasim *vdpasim,
+ struct vdpa_dev_config *config);
+ int (*set_ce_config)(struct vdpasim *vdpasim,
+ const struct vdpa_dev_set_config *config);
};
/* State of each vdpasim device */
diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c
index a1ab6163f7d1..bdc70e9bf3a2 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);
@@ -114,7 +108,28 @@ static void vdpasim_net_get_config(struct vdpasim *vdpasim, void *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_get_ce_config(struct vdpasim *vdpasim,
+ struct vdpa_dev_config *config)
+{
+ struct virtio_net_config *vio_config = vdpasim->config;
+
+ memcpy(config->net.mac, vio_config->mac, ETH_ALEN);
+ config->net.mtu = vdpasim16_to_cpu(vdpasim, vio_config->mtu);
+ config->net.status = VIRTIO_NET_S_LINK_UP;
+}
+
+static int vdpasim_net_set_ce_config(struct vdpasim *vdpasim,
+ const struct vdpa_dev_set_config *config)
+{
+ struct virtio_net_config *vio_config = vdpasim->config;
+
+ if (config->net_mask.mac_valid)
+ memcpy(vio_config->mac, config->net.mac, ETH_ALEN);
+ if (config->net_mask.mtu_valid)
+ vio_config->mtu = cpu_to_vdpasim16(vdpasim, config->net.mtu);
+ return 0;
}
static void vdpasim_net_mgmtdev_release(struct device *dev)
@@ -139,6 +154,8 @@ static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name)
dev_attr.nvqs = VDPASIM_NET_VQ_NUM;
dev_attr.config_size = sizeof(struct virtio_net_config);
dev_attr.get_config = vdpasim_net_get_config;
+ dev_attr.get_ce_config = vdpasim_net_get_ce_config;
+ dev_attr.set_ce_config = vdpasim_net_set_ce_config;
dev_attr.work_fn = vdpasim_net_work;
dev_attr.buffer_size = PAGE_SIZE;
@@ -185,14 +202,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-04-06 17:05 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-06 17:04 [PATCH linux-next v2 00/14] vdpa: Enable user to set mac address, mtu Parav Pandit
2021-04-06 17:04 ` [PATCH linux-next v2 01/14] vdpa: Follow kdoc comment style Parav Pandit
2021-04-07 3:08 ` Jason Wang
2021-04-06 17:04 ` [PATCH linux-next v2 02/14] " Parav Pandit
2021-04-07 3:09 ` Jason Wang
2021-04-06 17:04 ` [PATCH linux-next v2 03/14] vdpa: Introduce and use vdpa device get, set config, features helpers Parav Pandit
2021-04-07 3:18 ` [PATCH linux-next v2 03/14] vdpa: Introduce and use vdpa device get,set " Jason Wang
2021-04-07 3:52 ` Parav Pandit
2021-04-06 17:04 ` [PATCH linux-next v2 04/14] vdpa: Introduce query of device config layout Parav Pandit
2021-04-07 3:56 ` Jason Wang
2021-04-07 5:10 ` Parav Pandit
2021-04-07 7:12 ` Jason Wang
2021-04-08 6:23 ` Parav Pandit
2021-04-06 17:04 ` [PATCH linux-next v2 05/14] vdpa: Enable user to set mac and mtu of vdpa device Parav Pandit
2021-04-07 3:59 ` Jason Wang
2021-04-06 17:04 ` Parav Pandit [this message]
2021-04-06 17:04 ` [PATCH linux-next v2 07/14] vdpa/mlx5: Use the correct dma device when registering memory Parav Pandit
2021-04-07 4:00 ` Jason Wang
2021-04-06 17:04 ` [PATCH linux-next v2 08/14] vdpa/mlx5: Retrieve BAR address suitable any function Parav Pandit
2021-04-07 5:32 ` Jason Wang
2021-04-06 17:04 ` [PATCH linux-next v2 09/14] vdpa/mlx5: Enable user to add/delete vdpa device Parav Pandit
2021-04-06 17:04 ` [PATCH linux-next v2 10/14] vdpa/mlx5: Support configuration of MAC Parav Pandit
2021-04-07 7:21 ` Jason Wang
2021-04-06 17:04 ` [PATCH linux-next v2 11/14] vdpa/mlx5: Forward only packets with allowed MAC address Parav Pandit
2021-04-06 17:04 ` [PATCH linux-next v2 12/14] vdpa/mlx5: should exclude header length and fcs from mtu Parav Pandit
2021-04-06 17:04 ` [PATCH linux-next v2 13/14] vdpa/mlx5: Fix suspend/resume index restoration Parav Pandit
2021-04-07 7:25 ` Jason Wang
[not found] ` <20210407101612.GB207753@mtl-vdi-166.wap.labs.mlnx>
2021-04-07 13:38 ` Michael S. Tsirkin
2021-04-06 17:04 ` [PATCH linux-next v2 14/14] vdpa/mlx5: Fix wrong use of bit numbers Parav Pandit
2021-04-07 7:25 ` Jason Wang
2021-04-07 7:28 ` Parav Pandit
2021-04-07 7:28 ` [PATCH linux-next v2 00/14] vdpa: Enable user to set mac address, mtu Jason Wang
2021-04-08 3:45 ` 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=20210406170457.98481-7-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.