From patchwork Thu Dec 15 21:05:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zhang X-Patchwork-Id: 18015 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id F08A168BD; Fri, 16 Dec 2016 05:09:48 +0100 (CET) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id BE86A2C0A for ; Fri, 16 Dec 2016 05:08:48 +0100 (CET) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP; 15 Dec 2016 20:08:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,355,1477983600"; d="scan'208";a="43201968" Received: from unknown (HELO localhost.localdomain.sh.intel.com) ([10.239.129.189]) by fmsmga006.fm.intel.com with ESMTP; 15 Dec 2016 20:08:47 -0800 From: Qi Zhang To: jingjing.wu@intel.com, helin.zhang@intel.com Cc: dev@dpdk.org, Ferruh Yigit Date: Thu, 15 Dec 2016 16:05:00 -0500 Message-Id: <1481835919-36488-11-git-send-email-qi.z.zhang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1481835919-36488-1-git-send-email-qi.z.zhang@intel.com> References: <1481835919-36488-1-git-send-email-qi.z.zhang@intel.com> Subject: [dpdk-dev] [PATCH v3 10/29] net/i40e: set VF MAC from PF support X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Ferruh Yigit Support setting VF MAC address from PF. User can call the API on PF to set a specific VF's MAC address. This will remove all existing MAC filters. Signed-off-by: Ferruh Yigit --- app/test-pmd/cmdline.c | 18 ++++++++++++-- drivers/net/i40e/i40e_ethdev.c | 40 +++++++++++++++++++++++++++++++ drivers/net/i40e/rte_pmd_i40e.h | 19 +++++++++++++++ drivers/net/i40e/rte_pmd_i40e_version.map | 2 ++ 4 files changed, 77 insertions(+), 2 deletions(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 3b45c32..2028173 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -90,6 +90,9 @@ #ifdef RTE_LIBRTE_IXGBE_PMD #include #endif +#ifdef RTE_LIBRTE_I40E_PMD +#include +#endif #include "testpmd.h" static struct cmdline *testpmd_cl; @@ -11453,13 +11456,24 @@ cmd_set_vf_mac_addr_parsed( __attribute__((unused)) void *data) { struct cmd_set_vf_mac_addr_result *res = parsed_result; + struct rte_eth_dev_info dev_info; int ret; if (port_id_is_invalid(res->port_id, ENABLED_WARN)) return; - ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id, - &res->mac_addr); + memset(&dev_info, 0, sizeof(dev_info)); + rte_eth_dev_info_get(res->port_id, &dev_info); + + if (strstr(dev_info.driver_name, "ixgbe") != NULL) + ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id, + &res->mac_addr); + else if (strstr(dev_info.driver_name, "i40e") != NULL) + ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id, + &res->mac_addr); + else + return; + switch (ret) { case 0: break; diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c index e2214bd..e9bd95b 100644 --- a/drivers/net/i40e/i40e_ethdev.c +++ b/drivers/net/i40e/i40e_ethdev.c @@ -10189,3 +10189,43 @@ rte_pmd_i40e_set_vf_multicast_promisc(uint8_t port, uint16_t vf_id, uint8_t on) 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); + + return 0; +} diff --git a/drivers/net/i40e/rte_pmd_i40e.h b/drivers/net/i40e/rte_pmd_i40e.h index 9091520..faacbb9 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 remove all existing MAC filters. + * + * @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;