[dpdk-dev] [PATCH v2 12/32] net/i40e: set VF MAC from PF support

Wenzhuo Lu wenzhuo.lu at intel.com
Wed Dec 7 04:31:55 CET 2016


Support setting VF MAC address from PF.
User can call the API on PF to set a specific
VF's MAC address.

This will reset the VF.

Signed-off-by: Ferruh Yigit <ferruh.yigit at intel.com>
---
 app/test/Makefile                         |  8 +++
 app/test/test_pmd_i40e.c                  | 96 +++++++++++++++++++++++++++++++
 drivers/net/i40e/i40e_ethdev.c            | 42 ++++++++++++++
 drivers/net/i40e/rte_pmd_i40e.h           | 19 ++++++
 drivers/net/i40e/rte_pmd_i40e_version.map |  2 +
 5 files changed, 167 insertions(+)
 create mode 100644 app/test/test_pmd_i40e.c

diff --git a/app/test/Makefile b/app/test/Makefile
index 5be023a..b3f6ecb 100644
--- a/app/test/Makefile
+++ b/app/test/Makefile
@@ -199,6 +199,8 @@ SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev.c
 
 SRCS-$(CONFIG_RTE_LIBRTE_KVARGS) += test_kvargs.c
 
+SRCS-$(CONFIG_RTE_LIBRTE_I40E_PMD) += test_pmd_i40e.c
+
 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
 
@@ -228,6 +230,12 @@ endif
 endif
 endif
 
+ifeq ($(CONFIG_RTE_BUILD_SHARED_LIB),y)
+ifeq ($(CONFIG_RTE_LIBRTE_I40E_PMD),y)
+LDLIBS += -lrte_pmd_i40e
+endif
+endif
+
 ifeq ($(CONFIG_RTE_APP_TEST_RESOURCE_TAR),y)
 LDLIBS += -larchive
 endif
diff --git a/app/test/test_pmd_i40e.c b/app/test/test_pmd_i40e.c
new file mode 100644
index 0000000..c901e89
--- /dev/null
+++ b/app/test/test_pmd_i40e.c
@@ -0,0 +1,96 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2016 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <inttypes.h>
+
+#include <rte_pmd_i40e.h>
+#include <rte_ethdev.h>
+
+#include "test.h"
+
+#define I40E_DRV_NAME "net_i40e"
+
+static struct ether_addr mac_addr = {
+	{ 0xAA, 0xBB, 0xCC, 0xDD, 0x00, 0x00 }
+};
+
+static const int max_vfs = 3;
+
+static int
+test_i40e(void)
+{
+	struct rte_eth_dev_info dev_info;
+	struct ether_addr current_mac_addr;
+	uint8_t nb_ports;
+	uint8_t port;
+	int ret = 0;
+	int i;
+
+	nb_ports = rte_eth_dev_count();
+	printf("nb_ports=%d\n", nb_ports);
+
+	for (port = 0; port < nb_ports; port++) {
+		rte_eth_dev_info_get(port, &dev_info);
+
+		printf("%d: %s\n", port, dev_info.driver_name);
+
+		if (strcmp(dev_info.driver_name, I40E_DRV_NAME))
+			continue;
+
+		rte_eth_macaddr_get(port, &current_mac_addr);
+
+		printf("%d: mac address:", port);
+		for (i = 0; i < ETHER_ADDR_LEN - 1; i++)
+			printf("%x:", current_mac_addr.addr_bytes[i]);
+		printf("%x\n", current_mac_addr.addr_bytes[ETHER_ADDR_LEN - 1]);
+
+		for (i = 0; i < max_vfs; i++) {
+			if (i >= dev_info.max_vfs)
+				break;
+
+			mac_addr.addr_bytes[ETHER_ADDR_LEN - 2] = port + 1;
+			mac_addr.addr_bytes[ETHER_ADDR_LEN - 1] = i + 1;
+
+			ret = rte_pmd_i40e_set_vf_mac_addr(port, i, &mac_addr);
+			printf("port:%d vf:%d set mac %s\n",
+					port, i, ret ? "failed" : "succeed");
+		}
+	}
+
+	return 0;
+}
+
+REGISTER_TEST_COMMAND(i40e_autotest, test_i40e);
diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index 5c9d6d1..832995a 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -10293,3 +10293,45 @@ static void i40e_set_default_mac_addr(struct rte_eth_dev *dev,
 
 	return ret;
 }
+
+int
+rte_pmd_i40e_set_vf_mac_addr(uint8_t port, uint16_t vf_id,
+			     struct ether_addr *mac_addr)
+{
+	struct rte_eth_dev_info dev_info;
+	struct i40e_mac_filter *f;
+	struct rte_eth_dev *dev;
+	struct i40e_pf_vf *vf;
+	struct i40e_vsi *vsi;
+	struct i40e_pf *pf;
+	void *temp;
+
+	if (i40e_validate_mac_addr((u8 *)mac_addr) != I40E_SUCCESS)
+		return -EINVAL;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
+
+	dev = &rte_eth_devices[port];
+	rte_eth_dev_info_get(port, &dev_info);
+
+	if (vf_id >= dev_info.max_vfs)
+		return -EINVAL;
+
+	pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
+
+	if (vf_id > pf->vf_num - 1 || !pf->vfs)
+		return -EINVAL;
+
+	vf = &pf->vfs[vf_id];
+	vsi = vf->vsi;
+
+	ether_addr_copy(mac_addr, &vf->mac_addr);
+
+	/* Remove all existing mac */
+	TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp)
+		i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr);
+
+	i40e_pf_host_vf_reset(vf, 1);
+
+	return 0;
+}
diff --git a/drivers/net/i40e/rte_pmd_i40e.h b/drivers/net/i40e/rte_pmd_i40e.h
index 9091520..ca5e05a 100644
--- a/drivers/net/i40e/rte_pmd_i40e.h
+++ b/drivers/net/i40e/rte_pmd_i40e.h
@@ -168,4 +168,23 @@ int rte_pmd_i40e_set_vf_multicast_promisc(uint8_t port,
 					  uint16_t vf_id,
 					  uint8_t on);
 
+/**
+ * Set the VF MAC address.
+ *
+ * This will reset the vf.
+ *
+ * @param port
+ *   The port identifier of the Ethernet device.
+ * @param vf_id
+ *   VF id.
+ * @param mac_addr
+ *   VF MAC address.
+ * @return
+ *   - (0) if successful.
+ *   - (-ENODEV) if *port* invalid.
+ *   - (-EINVAL) if *vf* or *mac_addr* is invalid.
+ */
+int rte_pmd_i40e_set_vf_mac_addr(uint8_t port, uint16_t vf_id,
+				 struct ether_addr *mac_addr);
+
 #endif /* _PMD_I40E_H_ */
diff --git a/drivers/net/i40e/rte_pmd_i40e_version.map b/drivers/net/i40e/rte_pmd_i40e_version.map
index 08d3028..64ba93a 100644
--- a/drivers/net/i40e/rte_pmd_i40e_version.map
+++ b/drivers/net/i40e/rte_pmd_i40e_version.map
@@ -12,4 +12,6 @@ DPDK_17.02 {
 	rte_pmd_i40e_set_tx_loopback;
 	rte_pmd_i40e_set_vf_unicast_promisc;
 	rte_pmd_i40e_set_vf_multicast_promisc;
+	rte_pmd_i40e_set_vf_mac_addr;
+
 } DPDK_2.0;
-- 
1.9.3



More information about the dev mailing list