DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ivan Malov <ivan.malov@oktetlabs.ru>
To: dev@dpdk.org
Cc: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>,
	Andy Moreton <amoreton@xilinx.com>
Subject: [PATCH 3/3] net/sfc: allow to control the represented entity MAC address
Date: Thu, 26 May 2022 11:45:50 +0300	[thread overview]
Message-ID: <20220526084550.243121-3-ivan.malov@oktetlabs.ru> (raw)
In-Reply-To: <20220526084550.243121-1-ivan.malov@oktetlabs.ru>

The MAC address is accessed via the representor ethdev's one.

Signed-off-by: Ivan Malov <ivan.malov@oktetlabs.ru>
Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Reviewed-by: Andy Moreton <amoreton@xilinx.com>
---
 drivers/net/sfc/sfc_port.c           |  1 +
 drivers/net/sfc/sfc_repr.c           | 29 ++++++++++++++++--
 drivers/net/sfc/sfc_repr_proxy.c     | 45 +++++++++++++++++++++++++++-
 drivers/net/sfc/sfc_repr_proxy.h     |  1 +
 drivers/net/sfc/sfc_repr_proxy_api.h |  7 ++++-
 5 files changed, 78 insertions(+), 5 deletions(-)

diff --git a/drivers/net/sfc/sfc_port.c b/drivers/net/sfc/sfc_port.c
index 91139375ea..5f312ab1ba 100644
--- a/drivers/net/sfc/sfc_port.c
+++ b/drivers/net/sfc/sfc_port.c
@@ -8,6 +8,7 @@
  */
 
 #include <rte_bitmap.h>
+#include <rte_ether.h>
 
 #include "efx.h"
 
diff --git a/drivers/net/sfc/sfc_repr.c b/drivers/net/sfc/sfc_repr.c
index 9d88d554c1..d0e5385889 100644
--- a/drivers/net/sfc/sfc_repr.c
+++ b/drivers/net/sfc/sfc_repr.c
@@ -853,6 +853,17 @@ sfc_repr_dev_close(struct rte_eth_dev *dev)
 	return 0;
 }
 
+static int
+sfc_repr_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
+{
+	struct sfc_repr_shared *srs = sfc_repr_shared_by_eth_dev(dev);
+	int ret;
+
+	ret = sfc_repr_proxy_repr_entity_mac_addr_set(srs->pf_port_id,
+						      srs->repr_id, mac_addr);
+	return -ret;
+}
+
 static int
 sfc_repr_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
 {
@@ -889,6 +900,7 @@ static const struct eth_dev_ops sfc_repr_dev_ops = {
 	.dev_close			= sfc_repr_dev_close,
 	.dev_infos_get			= sfc_repr_dev_infos_get,
 	.link_update			= sfc_repr_dev_link_update,
+	.mac_addr_set			= sfc_repr_mac_addr_set,
 	.stats_get			= sfc_repr_stats_get,
 	.rx_queue_setup			= sfc_repr_rx_queue_setup,
 	.rx_queue_release		= sfc_repr_rx_queue_release,
@@ -956,9 +968,9 @@ sfc_repr_eth_dev_init(struct rte_eth_dev *dev, void *init_params)
 	}
 
 	ret = sfc_repr_proxy_add_port(repr_data->pf_port_id,
-				      srs->switch_port_id,
-				      dev->data->port_id,
-				      &repr_data->mport_sel);
+				      srs->switch_port_id, dev->data->port_id,
+				      &repr_data->mport_sel, repr_data->intf,
+				      repr_data->pf, repr_data->vf);
 	if (ret != 0) {
 		SFC_GENERIC_LOG(ERR, "%s() failed to add repr proxy port",
 				__func__);
@@ -996,6 +1008,16 @@ sfc_repr_eth_dev_init(struct rte_eth_dev *dev, void *init_params)
 		goto fail_mac_addrs;
 	}
 
+	rte_eth_random_addr(dev->data->mac_addrs[0].addr_bytes);
+
+	ret = sfc_repr_proxy_repr_entity_mac_addr_set(repr_data->pf_port_id,
+						      srs->repr_id,
+						      &dev->data->mac_addrs[0]);
+	if (ret != 0) {
+		ret = -ret;
+		goto fail_mac_addr_set;
+	}
+
 	dev->rx_pkt_burst = sfc_repr_rx_burst;
 	dev->tx_pkt_burst = sfc_repr_tx_burst;
 	dev->dev_ops = &sfc_repr_dev_ops;
@@ -1005,6 +1027,7 @@ sfc_repr_eth_dev_init(struct rte_eth_dev *dev, void *init_params)
 
 	return 0;
 
+fail_mac_addr_set:
 fail_mac_addrs:
 	sfc_repr_unlock(sr);
 	free(sr);
diff --git a/drivers/net/sfc/sfc_repr_proxy.c b/drivers/net/sfc/sfc_repr_proxy.c
index 8660d419a3..4b958ced61 100644
--- a/drivers/net/sfc/sfc_repr_proxy.c
+++ b/drivers/net/sfc/sfc_repr_proxy.c
@@ -1280,7 +1280,8 @@ sfc_repr_proxy_stop(struct sfc_adapter *sa)
 
 int
 sfc_repr_proxy_add_port(uint16_t pf_port_id, uint16_t repr_id,
-			uint16_t rte_port_id, const efx_mport_sel_t *mport_sel)
+			uint16_t rte_port_id, const efx_mport_sel_t *mport_sel,
+			efx_pcie_interface_t intf, uint16_t pf, uint16_t vf)
 {
 	struct sfc_repr_proxy_port *port;
 	struct sfc_repr_proxy *rp;
@@ -1319,6 +1320,14 @@ sfc_repr_proxy_add_port(uint16_t pf_port_id, uint16_t repr_id,
 	port->rte_port_id = rte_port_id;
 	port->repr_id = repr_id;
 
+	rc = efx_mcdi_get_client_handle(sa->nic, intf, pf, vf,
+					&port->remote_vnic_mcdi_client_handle);
+	if (rc != 0) {
+		sfc_err(sa, "failed to get the represented VNIC's MCDI handle (repr_id=%u): %s",
+			repr_id, rte_strerror(rc));
+		goto fail_client_handle;
+	}
+
 	if (rp->started) {
 		rc = sfc_repr_proxy_mbox_send(&rp->mbox, port,
 					      SFC_REPR_PROXY_MBOX_ADD_PORT);
@@ -1337,6 +1346,7 @@ sfc_repr_proxy_add_port(uint16_t pf_port_id, uint16_t repr_id,
 	return 0;
 
 fail_port_add:
+fail_client_handle:
 fail_mport_id:
 	rte_free(port);
 fail_alloc_port:
@@ -1664,3 +1674,36 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id)
 
 	return 0;
 }
+
+int
+sfc_repr_proxy_repr_entity_mac_addr_set(uint16_t pf_port_id, uint16_t repr_id,
+					const struct rte_ether_addr *mac_addr)
+{
+	struct sfc_repr_proxy_port *port;
+	struct sfc_repr_proxy *rp;
+	struct sfc_adapter *sa;
+	int rc;
+
+	sa = sfc_get_adapter_by_pf_port_id(pf_port_id);
+	rp = sfc_repr_proxy_by_adapter(sa);
+
+	port = sfc_repr_proxy_find_port(rp, repr_id);
+	if (port == NULL) {
+		sfc_err(sa, "%s() failed: no such port (repr_id=%u)",
+			__func__, repr_id);
+		sfc_put_adapter(sa);
+		return ENOENT;
+	}
+
+	rc = efx_mcdi_client_mac_addr_set(sa->nic,
+					  port->remote_vnic_mcdi_client_handle,
+					  mac_addr->addr_bytes);
+	if (rc != 0) {
+		sfc_err(sa, "%s() failed: cannot set MAC address (repr_id=%u): %s",
+			__func__, repr_id, rte_strerror(rc));
+	}
+
+	sfc_put_adapter(sa);
+
+	return rc;
+}
diff --git a/drivers/net/sfc/sfc_repr_proxy.h b/drivers/net/sfc/sfc_repr_proxy.h
index b49b1a2a96..260e2cab30 100644
--- a/drivers/net/sfc/sfc_repr_proxy.h
+++ b/drivers/net/sfc/sfc_repr_proxy.h
@@ -64,6 +64,7 @@ struct sfc_repr_proxy_port {
 	uint16_t				repr_id;
 	uint16_t				rte_port_id;
 	efx_mport_id_t				egress_mport;
+	uint32_t				remote_vnic_mcdi_client_handle;
 	struct sfc_repr_proxy_rxq		rxq[SFC_REPR_RXQ_MAX];
 	struct sfc_repr_proxy_txq		txq[SFC_REPR_TXQ_MAX];
 	struct sfc_mae_rule			*mae_rule;
diff --git a/drivers/net/sfc/sfc_repr_proxy_api.h b/drivers/net/sfc/sfc_repr_proxy_api.h
index 95b065801d..1d38ab2451 100644
--- a/drivers/net/sfc/sfc_repr_proxy_api.h
+++ b/drivers/net/sfc/sfc_repr_proxy_api.h
@@ -23,7 +23,9 @@ extern "C" {
 
 int sfc_repr_proxy_add_port(uint16_t pf_port_id, uint16_t repr_id,
 			    uint16_t rte_port_id,
-			    const efx_mport_sel_t *mport_set);
+			    const efx_mport_sel_t *mport_sel,
+			    efx_pcie_interface_t intf, uint16_t pf,
+			    uint16_t vf);
 int sfc_repr_proxy_del_port(uint16_t pf_port_id, uint16_t repr_id);
 
 int sfc_repr_proxy_add_rxq(uint16_t pf_port_id, uint16_t repr_id,
@@ -41,6 +43,9 @@ void sfc_repr_proxy_del_txq(uint16_t pf_port_id, uint16_t repr_id,
 int sfc_repr_proxy_start_repr(uint16_t pf_port_id, uint16_t repr_id);
 int sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id);
 
+int sfc_repr_proxy_repr_entity_mac_addr_set(uint16_t pf_port_id,
+		uint16_t repr_id, const struct rte_ether_addr *mac_addr);
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.30.2


  parent reply	other threads:[~2022-05-26  8:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-26  8:45 [PATCH 1/3] common/sfc_efx/base: convert EFX PCIe INTF to MCDI value Ivan Malov
2022-05-26  8:45 ` [PATCH 2/3] common/sfc_efx/base: manage VNIC MAC address by MCDI handle Ivan Malov
2022-05-26  9:54   ` Ray Kinsella
2022-05-26  8:45 ` Ivan Malov [this message]
2022-05-31 16:57 ` [PATCH 1/3] common/sfc_efx/base: convert EFX PCIe INTF to MCDI value Andrew Rybchenko

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=20220526084550.243121-3-ivan.malov@oktetlabs.ru \
    --to=ivan.malov@oktetlabs.ru \
    --cc=amoreton@xilinx.com \
    --cc=andrew.rybchenko@oktetlabs.ru \
    --cc=dev@dpdk.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).