DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] net/mlx5: set VF MAC address from host
@ 2019-11-07 16:03 Raslan Darawsheh
  2019-11-11 11:40 ` [dpdk-dev] [PATCH v2] " Raslan Darawsheh
  0 siblings, 1 reply; 4+ messages in thread
From: Raslan Darawsheh @ 2019-11-07 16:03 UTC (permalink / raw)
  To: Slava Ovsiienko; +Cc: Thomas Monjalon, dev, Asaf Penso

Allow to configure the default MAC address of a VF
via its representor port in the host.

An API was proposed to specify explicitly the VF as a
target: https://patches.dpdk.org/patch/62176/

It has been rejected by the technical board in order to
keep compatibility with behavior in Intel PMDs.
http://mails.dpdk.org/archives/dev/2019-November/150588.html

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Signed-off-by: Raslan Darawsheh <rasland@mellanox.com>
---
 drivers/net/mlx5/mlx5.h     |  2 +
 drivers/net/mlx5/mlx5_mac.c | 20 +++++++++
 drivers/net/mlx5/mlx5_nl.c  | 98 ++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 119 insertions(+), 1 deletion(-)

diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index b56dae1..75e20a9 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -938,6 +938,8 @@ int mlx5_nl_promisc(struct rte_eth_dev *dev, int enable);
 int mlx5_nl_allmulti(struct rte_eth_dev *dev, int enable);
 unsigned int mlx5_nl_portnum(int nl, const char *name);
 unsigned int mlx5_nl_ifindex(int nl, const char *name, uint32_t pindex);
+int mlx5_nl_vf_mac_addr_modify(struct rte_eth_dev *dev,
+			       struct rte_ether_addr *mac, int vf_index);
 int mlx5_nl_switch_info(int nl, unsigned int ifindex,
 			struct mlx5_switch_info *info);
 
diff --git a/drivers/net/mlx5/mlx5_mac.c b/drivers/net/mlx5/mlx5_mac.c
index 0ffef5c..ca95bd2 100644
--- a/drivers/net/mlx5/mlx5_mac.c
+++ b/drivers/net/mlx5/mlx5_mac.c
@@ -197,6 +197,26 @@ mlx5_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac,
 int
 mlx5_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
 {
+	uint16_t port_id;
+	struct mlx5_priv *priv = dev->data->dev_private;
+
+	/* Configuring the VF instead of its representor. */
+	if (priv->representor_id != -1) {
+		DRV_LOG(DEBUG, "VF represented by port %u setting primary MAC address",
+			dev->data->port_id);
+		RTE_ETH_FOREACH_DEV_SIBLING(port_id, dev->data->port_id) {
+			priv = rte_eth_devices[port_id].data->dev_private;
+			if (priv->master == 1) {
+				priv = dev->data->dev_private;
+				return mlx5_nl_vf_mac_addr_modify
+					(&rte_eth_devices[port_id],
+					 mac_addr, priv->representor_id);
+			}
+		}
+		rte_errno = -ENOTSUP;
+		return rte_errno;
+	}
+
 	DRV_LOG(DEBUG, "port %u setting primary MAC address",
 		dev->data->port_id);
 	return mlx5_mac_addr_add(dev, mac_addr, 0, 0);
diff --git a/drivers/net/mlx5/mlx5_nl.c b/drivers/net/mlx5/mlx5_nl.c
index 3e073c6..1eff575 100644
--- a/drivers/net/mlx5/mlx5_nl.c
+++ b/drivers/net/mlx5/mlx5_nl.c
@@ -42,7 +42,15 @@
 #define MLX5_NDA_RTA(r) \
 	((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct ndmsg))))
 #endif
-
+/*
+ * Define NLMSG_TAIL as defined in iproute2 sources.
+ *
+ * see in iproute2 sources file include/libnetlink.h
+ */
+#ifndef NLMSG_TAIL
+#define NLMSG_TAIL(nmsg) \
+	((struct rtattr *)(((char *)(nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
+#endif
 /*
  * The following definitions are normally found in rdma/rdma_netlink.h,
  * however they are so recent that most systems do not expose them yet.
@@ -494,6 +502,94 @@ mlx5_nl_mac_addr_modify(struct rte_eth_dev *dev, struct rte_ether_addr *mac,
 }
 
 /**
+ * Modify the VF MAC address neighbour table with Netlink.
+ *
+ * @param dev
+ *    Pointer to Ethernet device.
+ * @param mac
+ *    MAC address to consider.
+ * @param vf_index
+ *    VF index.
+ *
+ * @return
+ *    0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+int
+mlx5_nl_vf_mac_addr_modify(struct rte_eth_dev *dev,
+			   struct rte_ether_addr *mac, int vf_index)
+{
+	int fd, ret;
+	struct mlx5_priv *priv = dev->data->dev_private;
+	unsigned int iface_idx = mlx5_ifindex(dev);
+	struct {
+		struct nlmsghdr hdr;
+		struct ifinfomsg ifm;
+		struct rtattr vf_list_rta;
+		struct rtattr vf_info_rta;
+		struct rtattr vf_mac_rta;
+		struct ifla_vf_mac ivm;
+	} req = {
+		.hdr = {
+			.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
+			.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK,
+			.nlmsg_type = RTM_BASE,
+		},
+		.ifm = {
+			.ifi_index = iface_idx,
+		},
+		.vf_list_rta = {
+			.rta_type = IFLA_VFINFO_LIST,
+			.rta_len = RTA_ALIGN(RTA_LENGTH(0)),
+		},
+		.vf_info_rta = {
+			.rta_type = IFLA_VF_INFO,
+			.rta_len = RTA_ALIGN(RTA_LENGTH(0)),
+		},
+		.vf_mac_rta = {
+			.rta_type = IFLA_VF_MAC,
+		},
+	};
+	uint32_t sn = priv->nl_sn++;
+	struct ifla_vf_mac ivm = {
+		.vf = vf_index,
+	};
+
+	memcpy(&ivm.mac, mac, RTE_ETHER_ADDR_LEN);
+	memcpy(RTA_DATA(&req.vf_mac_rta), &ivm, sizeof(ivm));
+
+	req.vf_mac_rta.rta_len = RTA_LENGTH(sizeof(ivm));
+	req.hdr.nlmsg_len = NLMSG_ALIGN(req.hdr.nlmsg_len) +
+		RTA_ALIGN(req.vf_list_rta.rta_len) +
+		RTA_ALIGN(req.vf_info_rta.rta_len) +
+		RTA_ALIGN(req.vf_mac_rta.rta_len);
+	req.vf_list_rta.rta_len = (char *)NLMSG_TAIL(&req.hdr) -
+		(char *)&req.vf_list_rta;
+	req.vf_info_rta.rta_len = (char *)NLMSG_TAIL(&req.hdr) -
+		(char *)&req.vf_info_rta;
+
+	fd = priv->nl_socket_route;
+	if (fd < 0)
+		return -1;
+	ret = mlx5_nl_send(fd, &req.hdr, sn);
+	if (ret < 0)
+		goto error;
+	ret = mlx5_nl_recv(fd, sn, NULL, NULL);
+	if (ret < 0)
+		goto error;
+	return 0;
+error:
+	DRV_LOG(ERR,
+		"representor %u cannot set VF MAC address "
+		"%02X:%02X:%02X:%02X:%02X:%02X : %s",
+		vf_index,
+		mac->addr_bytes[0], mac->addr_bytes[1],
+		mac->addr_bytes[2], mac->addr_bytes[3],
+		mac->addr_bytes[4], mac->addr_bytes[5],
+		strerror(rte_errno));
+	return -rte_errno;
+}
+
+/**
  * Add a MAC address.
  *
  * @param dev
-- 
2.7.4


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [dpdk-dev] [PATCH v2] net/mlx5: set VF MAC address from host
  2019-11-07 16:03 [dpdk-dev] [PATCH] net/mlx5: set VF MAC address from host Raslan Darawsheh
@ 2019-11-11 11:40 ` Raslan Darawsheh
  2019-11-11 11:49   ` Slava Ovsiienko
  2019-11-11 14:03   ` Raslan Darawsheh
  0 siblings, 2 replies; 4+ messages in thread
From: Raslan Darawsheh @ 2019-11-11 11:40 UTC (permalink / raw)
  To: Slava Ovsiienko; +Cc: Thomas Monjalon, dev

Allow to configure the default MAC address of a VF
via its representor port in the host.

An API was proposed to specify explicitly the VF as a
target: https://patches.dpdk.org/patch/62176/

It has been rejected by the technical board in order to
keep compatibility with behavior in Intel PMDs.
http://mails.dpdk.org/archives/dev/2019-November/150588.html

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Signed-off-by: Raslan Darawsheh <rasland@mellanox.com>
---
v2: use RTE_PTR_DIFF, and change the use of representor id to representor bit
---
 drivers/net/mlx5/mlx5.h     |  2 +
 drivers/net/mlx5/mlx5_mac.c | 20 +++++++++
 drivers/net/mlx5/mlx5_nl.c  | 98 ++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 119 insertions(+), 1 deletion(-)

diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 3296f10..969bfd7 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -997,6 +997,8 @@ int mlx5_nl_promisc(struct rte_eth_dev *dev, int enable);
 int mlx5_nl_allmulti(struct rte_eth_dev *dev, int enable);
 unsigned int mlx5_nl_portnum(int nl, const char *name);
 unsigned int mlx5_nl_ifindex(int nl, const char *name, uint32_t pindex);
+int mlx5_nl_vf_mac_addr_modify(struct rte_eth_dev *dev,
+			       struct rte_ether_addr *mac, int vf_index);
 int mlx5_nl_switch_info(int nl, unsigned int ifindex,
 			struct mlx5_switch_info *info);
 
diff --git a/drivers/net/mlx5/mlx5_mac.c b/drivers/net/mlx5/mlx5_mac.c
index 0ffef5c..7bdaa2a 100644
--- a/drivers/net/mlx5/mlx5_mac.c
+++ b/drivers/net/mlx5/mlx5_mac.c
@@ -197,6 +197,26 @@ mlx5_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac,
 int
 mlx5_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
 {
+	uint16_t port_id;
+	struct mlx5_priv *priv = dev->data->dev_private;
+
+	/* Configuring the VF instead of its representor. */
+	if (priv->representor) {
+		DRV_LOG(DEBUG, "VF represented by port %u setting primary MAC address",
+			dev->data->port_id);
+		RTE_ETH_FOREACH_DEV_SIBLING(port_id, dev->data->port_id) {
+			priv = rte_eth_devices[port_id].data->dev_private;
+			if (priv->master == 1) {
+				priv = dev->data->dev_private;
+				return mlx5_nl_vf_mac_addr_modify
+					(&rte_eth_devices[port_id],
+					 mac_addr, priv->representor_id);
+			}
+		}
+		rte_errno = -ENOTSUP;
+		return rte_errno;
+	}
+
 	DRV_LOG(DEBUG, "port %u setting primary MAC address",
 		dev->data->port_id);
 	return mlx5_mac_addr_add(dev, mac_addr, 0, 0);
diff --git a/drivers/net/mlx5/mlx5_nl.c b/drivers/net/mlx5/mlx5_nl.c
index 3e073c6..e7ba034 100644
--- a/drivers/net/mlx5/mlx5_nl.c
+++ b/drivers/net/mlx5/mlx5_nl.c
@@ -42,7 +42,15 @@
 #define MLX5_NDA_RTA(r) \
 	((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct ndmsg))))
 #endif
-
+/*
+ * Define NLMSG_TAIL as defined in iproute2 sources.
+ *
+ * see in iproute2 sources file include/libnetlink.h
+ */
+#ifndef NLMSG_TAIL
+#define NLMSG_TAIL(nmsg) \
+	((struct rtattr *)(((char *)(nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
+#endif
 /*
  * The following definitions are normally found in rdma/rdma_netlink.h,
  * however they are so recent that most systems do not expose them yet.
@@ -494,6 +502,94 @@ mlx5_nl_mac_addr_modify(struct rte_eth_dev *dev, struct rte_ether_addr *mac,
 }
 
 /**
+ * Modify the VF MAC address neighbour table with Netlink.
+ *
+ * @param dev
+ *    Pointer to Ethernet device.
+ * @param mac
+ *    MAC address to consider.
+ * @param vf_index
+ *    VF index.
+ *
+ * @return
+ *    0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+int
+mlx5_nl_vf_mac_addr_modify(struct rte_eth_dev *dev,
+			   struct rte_ether_addr *mac, int vf_index)
+{
+	int fd, ret;
+	struct mlx5_priv *priv = dev->data->dev_private;
+	unsigned int iface_idx = mlx5_ifindex(dev);
+	struct {
+		struct nlmsghdr hdr;
+		struct ifinfomsg ifm;
+		struct rtattr vf_list_rta;
+		struct rtattr vf_info_rta;
+		struct rtattr vf_mac_rta;
+		struct ifla_vf_mac ivm;
+	} req = {
+		.hdr = {
+			.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
+			.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK,
+			.nlmsg_type = RTM_BASE,
+		},
+		.ifm = {
+			.ifi_index = iface_idx,
+		},
+		.vf_list_rta = {
+			.rta_type = IFLA_VFINFO_LIST,
+			.rta_len = RTA_ALIGN(RTA_LENGTH(0)),
+		},
+		.vf_info_rta = {
+			.rta_type = IFLA_VF_INFO,
+			.rta_len = RTA_ALIGN(RTA_LENGTH(0)),
+		},
+		.vf_mac_rta = {
+			.rta_type = IFLA_VF_MAC,
+		},
+	};
+	uint32_t sn = priv->nl_sn++;
+	struct ifla_vf_mac ivm = {
+		.vf = vf_index,
+	};
+
+	memcpy(&ivm.mac, mac, RTE_ETHER_ADDR_LEN);
+	memcpy(RTA_DATA(&req.vf_mac_rta), &ivm, sizeof(ivm));
+
+	req.vf_mac_rta.rta_len = RTA_LENGTH(sizeof(ivm));
+	req.hdr.nlmsg_len = NLMSG_ALIGN(req.hdr.nlmsg_len) +
+		RTA_ALIGN(req.vf_list_rta.rta_len) +
+		RTA_ALIGN(req.vf_info_rta.rta_len) +
+		RTA_ALIGN(req.vf_mac_rta.rta_len);
+	req.vf_list_rta.rta_len = RTE_PTR_DIFF(NLMSG_TAIL(&req.hdr),
+					       &req.vf_list_rta);
+	req.vf_info_rta.rta_len = RTE_PTR_DIFF(NLMSG_TAIL(&req.hdr),
+					       &req.vf_info_rta);
+
+	fd = priv->nl_socket_route;
+	if (fd < 0)
+		return -1;
+	ret = mlx5_nl_send(fd, &req.hdr, sn);
+	if (ret < 0)
+		goto error;
+	ret = mlx5_nl_recv(fd, sn, NULL, NULL);
+	if (ret < 0)
+		goto error;
+	return 0;
+error:
+	DRV_LOG(ERR,
+		"representor %u cannot set VF MAC address "
+		"%02X:%02X:%02X:%02X:%02X:%02X : %s",
+		vf_index,
+		mac->addr_bytes[0], mac->addr_bytes[1],
+		mac->addr_bytes[2], mac->addr_bytes[3],
+		mac->addr_bytes[4], mac->addr_bytes[5],
+		strerror(rte_errno));
+	return -rte_errno;
+}
+
+/**
  * Add a MAC address.
  *
  * @param dev
-- 
2.7.4


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [dpdk-dev] [PATCH v2] net/mlx5: set VF MAC address from host
  2019-11-11 11:40 ` [dpdk-dev] [PATCH v2] " Raslan Darawsheh
@ 2019-11-11 11:49   ` Slava Ovsiienko
  2019-11-11 14:03   ` Raslan Darawsheh
  1 sibling, 0 replies; 4+ messages in thread
From: Slava Ovsiienko @ 2019-11-11 11:49 UTC (permalink / raw)
  To: Raslan Darawsheh; +Cc: Thomas Monjalon, dev

> -----Original Message-----
> From: Raslan Darawsheh <rasland@mellanox.com>
> Sent: Monday, November 11, 2019 13:40
> To: Slava Ovsiienko <viacheslavo@mellanox.com>
> Cc: Thomas Monjalon <thomas@monjalon.net>; dev@dpdk.org
> Subject: [PATCH v2] net/mlx5: set VF MAC address from host
> 
> Allow to configure the default MAC address of a VF via its representor port in
> the host.
> 
> An API was proposed to specify explicitly the VF as a
> target: https://patches.dpdk.org/patch/62176/
> 
> It has been rejected by the technical board in order to keep compatibility
> with behavior in Intel PMDs.
> http://mails.dpdk.org/archives/dev/2019-November/150588.html
> 
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> Signed-off-by: Raslan Darawsheh <rasland@mellanox.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [dpdk-dev] [PATCH v2] net/mlx5: set VF MAC address from host
  2019-11-11 11:40 ` [dpdk-dev] [PATCH v2] " Raslan Darawsheh
  2019-11-11 11:49   ` Slava Ovsiienko
@ 2019-11-11 14:03   ` Raslan Darawsheh
  1 sibling, 0 replies; 4+ messages in thread
From: Raslan Darawsheh @ 2019-11-11 14:03 UTC (permalink / raw)
  To: Raslan Darawsheh, Slava Ovsiienko; +Cc: Thomas Monjalon, dev

Hi,

> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Raslan Darawsheh
> Sent: Monday, November 11, 2019 1:40 PM
> To: Slava Ovsiienko <viacheslavo@mellanox.com>
> Cc: Thomas Monjalon <thomas@monjalon.net>; dev@dpdk.org
> Subject: [dpdk-dev] [PATCH v2] net/mlx5: set VF MAC address from host
> 
> Allow to configure the default MAC address of a VF
> via its representor port in the host.
> 
> An API was proposed to specify explicitly the VF as a
> target:
> https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatch
> es.dpdk.org%2Fpatch%2F62176%2F&amp;data=02%7C01%7Crasland%40mell
> anox.com%7Ceae200f7fe9a4dfd9f4a08d7669bf317%7Ca652971c7d2e4d9ba6a
> 4d149256f461b%7C0%7C0%7C637090692316231424&amp;sdata=r%2Faxjgak6
> wG8192hP8iXGmM9i67ZwcxGRcNYhgirl5Y%3D&amp;reserved=0
> 
> It has been rejected by the technical board in order to
> keep compatibility with behavior in Intel PMDs.
> https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmails.
> dpdk.org%2Farchives%2Fdev%2F2019-
> November%2F150588.html&amp;data=02%7C01%7Crasland%40mellanox.co
> m%7Ceae200f7fe9a4dfd9f4a08d7669bf317%7Ca652971c7d2e4d9ba6a4d1492
> 56f461b%7C0%7C0%7C637090692316231424&amp;sdata=5ST1D5mGMze5IGa
> LSm%2FjwbQuB4bs0UJ1HsaVqEoxfzo%3D&amp;reserved=0
> 
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> Signed-off-by: Raslan Darawsheh <rasland@mellanox.com>
> ---
> v2: use RTE_PTR_DIFF, and change the use of representor id to representor
> bit
> ---
>  drivers/net/mlx5/mlx5.h     |  2 +
>  drivers/net/mlx5/mlx5_mac.c | 20 +++++++++
>  drivers/net/mlx5/mlx5_nl.c  | 98
> ++++++++++++++++++++++++++++++++++++++++++++-
>  3 files changed, 119 insertions(+), 1 deletion(-)
> 


Patch applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-11-11 14:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-07 16:03 [dpdk-dev] [PATCH] net/mlx5: set VF MAC address from host Raslan Darawsheh
2019-11-11 11:40 ` [dpdk-dev] [PATCH v2] " Raslan Darawsheh
2019-11-11 11:49   ` Slava Ovsiienko
2019-11-11 14:03   ` Raslan Darawsheh

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).