diff mbox series

[3/3] net/sfc: allow to control the represented entity MAC address

Message ID 20220526084550.243121-3-ivan.malov@oktetlabs.ru (mailing list archive)
State Accepted
Delegated to: Andrew Rybchenko
Headers show
Series [1/3] common/sfc_efx/base: convert EFX PCIe INTF to MCDI value | expand

Checks

Context Check Description
ci/iol-abi-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing fail Testing issues
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/intel-Testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/checkpatch warning coding style issues

Commit Message

Ivan Malov May 26, 2022, 8:45 a.m. UTC
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 mbox series

Patch

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