virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Parav Pandit via Virtualization <virtualization@lists.linux-foundation.org>
To: <virtualization@lists.linux-foundation.org>
Cc: elic@nvidia.com, mst@redhat.com
Subject: [PATCH linux-next v4 5/8] vdpa_sim_net: Enable user to set mac address and mtu
Date: Thu, 21 Oct 2021 19:35:06 +0300	[thread overview]
Message-ID: <20211021163509.6978-6-parav@nvidia.com> (raw)
In-Reply-To: <20211021163509.6978-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

Signed-off-by: Parav Pandit <parav@nvidia.com>
Reviewed-by: Eli Cohen <elic@nvidia.com>
---
 drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 35 +++++++++++++++-------------
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c
index d681e423e64f..76dd24abc791 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c
@@ -16,6 +16,7 @@
 #include <linux/vringh.h>
 #include <linux/vdpa.h>
 #include <uapi/linux/virtio_net.h>
+#include <uapi/linux/vdpa.h>
 
 #include "vdpa_sim.h"
 
@@ -29,12 +30,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);
@@ -112,9 +107,21 @@ static void vdpasim_net_get_config(struct vdpasim *vdpasim, void *config)
 {
 	struct virtio_net_config *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_setup_config(struct vdpasim *vdpasim,
+				     const struct vdpa_dev_set_config *config)
+{
+	struct virtio_net_config *vio_config = vdpasim->config;
+
+	if (config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR))
+		memcpy(vio_config->mac, config->net.mac, ETH_ALEN);
+	if (config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MTU))
+		vio_config->mtu = cpu_to_vdpasim16(vdpasim, config->net.mtu);
+	else
+		/* Setup default MTU to be 1500 */
+		vio_config->mtu = cpu_to_vdpasim16(vdpasim, 1500);
 }
 
 static void vdpasim_net_mgmtdev_release(struct device *dev)
@@ -147,6 +154,8 @@ static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
 	if (IS_ERR(simdev))
 		return PTR_ERR(simdev);
 
+	vdpasim_net_setup_config(simdev, config);
+
 	ret = _vdpa_register_device(&simdev->vdpa, VDPASIM_NET_VQ_NUM);
 	if (ret)
 		goto reg_err;
@@ -180,20 +189,14 @@ static struct vdpa_mgmt_dev mgmt_dev = {
 	.device = &vdpasim_net_mgmtdev,
 	.id_table = id_table,
 	.ops = &vdpasim_net_mgmtdev_ops,
+	.config_attr_mask = (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR |
+			     1 << VDPA_ATTR_DEV_NET_CFG_MTU),
 };
 
 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.25.4

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

  parent reply	other threads:[~2021-10-21 16:35 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-21 16:35 [PATCH linux-next v4 0/8] vdpa: enable user to set mac, mtu Parav Pandit via Virtualization
2021-10-21 16:35 ` [PATCH linux-next v4 1/8] vdpa: Introduce and use vdpa device get, set config helpers Parav Pandit via Virtualization
2021-10-25  6:03   ` Jason Wang
2021-10-25 11:24     ` Parav Pandit via Virtualization
2021-10-21 16:35 ` [PATCH linux-next v4 2/8] vdpa: Introduce query of device config layout Parav Pandit via Virtualization
2021-10-25  6:05   ` Jason Wang
2021-10-25  6:59     ` Parav Pandit via Virtualization
2021-10-25  8:10       ` Michael S. Tsirkin
2021-10-26  2:45       ` Jason Wang
2021-10-25 11:43     ` Parav Pandit via Virtualization
2021-10-21 16:35 ` [PATCH linux-next v4 3/8] vdpa: Use kernel coding style for structure comments Parav Pandit via Virtualization
2021-10-25  6:06   ` Jason Wang
2021-10-21 16:35 ` [PATCH linux-next v4 4/8] vdpa: Enable user to set mac and mtu of vdpa device Parav Pandit via Virtualization
2021-10-25  7:01   ` Jason Wang
2021-10-25  7:06     ` Parav Pandit via Virtualization
2021-10-25  8:08       ` Michael S. Tsirkin
2021-10-25  8:26         ` Parav Pandit via Virtualization
2021-10-26  2:40       ` Jason Wang
2021-10-21 16:35 ` Parav Pandit via Virtualization [this message]
2021-10-25  7:02   ` [PATCH linux-next v4 5/8] vdpa_sim_net: Enable user to set mac address and mtu Jason Wang
2021-10-25  7:11     ` Parav Pandit via Virtualization
2021-10-25  8:09       ` Michael S. Tsirkin
2021-10-25  8:10         ` Parav Pandit via Virtualization
2021-10-25  8:16           ` Michael S. Tsirkin
2021-10-21 16:35 ` [PATCH linux-next v4 6/8] vdpa/mlx5: Fix clearing of VIRTIO_NET_F_MAC feature bit Parav Pandit via Virtualization
2021-10-25  7:05   ` Jason Wang
2021-10-25  7:08     ` Parav Pandit via Virtualization
2021-10-26  2:42       ` Jason Wang
2021-10-21 16:35 ` [PATCH linux-next v4 7/8] vdpa/mlx5: Support configuration of MAC Parav Pandit via Virtualization
2021-10-25  7:07   ` Jason Wang
2021-10-21 16:35 ` [PATCH linux-next v4 8/8] vdpa/mlx5: Forward only packets with allowed MAC address Parav Pandit via Virtualization
2021-10-22 10:41 ` [PATCH linux-next v4 0/8] vdpa: enable user to set mac, mtu Michael S. Tsirkin
2021-10-22 15:07   ` Parav Pandit via Virtualization
2021-10-23 20:03     ` Michael S. Tsirkin
2021-10-23 21:15       ` Michael S. Tsirkin
2021-10-25  3:43         ` Parav Pandit via Virtualization
2021-10-25  7:27           ` Parav Pandit via Virtualization

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=20211021163509.6978-6-parav@nvidia.com \
    --to=virtualization@lists.linux-foundation.org \
    --cc=elic@nvidia.com \
    --cc=mst@redhat.com \
    --cc=parav@nvidia.com \
    /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).