From patchwork Mon Dec 17 07:37:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenzhuo Lu X-Patchwork-Id: 48992 X-Patchwork-Delegate: qi.z.zhang@intel.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7A4FF1BA59; Mon, 17 Dec 2018 08:33:34 +0100 (CET) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id B38891B8B5 for ; Mon, 17 Dec 2018 08:33:20 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Dec 2018 23:33:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,364,1539673200"; d="scan'208";a="118899294" Received: from dpdk26.sh.intel.com ([10.67.110.164]) by orsmga002.jf.intel.com with ESMTP; 16 Dec 2018 23:33:19 -0800 From: Wenzhuo Lu To: dev@dpdk.org Cc: Wenzhuo Lu , Qiming Yang , Xiaoyun Li , Jingjing Wu Date: Mon, 17 Dec 2018 15:37:29 +0800 Message-Id: <1545032259-77179-22-git-send-email-wenzhuo.lu@intel.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1545032259-77179-1-git-send-email-wenzhuo.lu@intel.com> References: <1542956179-80951-1-git-send-email-wenzhuo.lu@intel.com> <1545032259-77179-1-git-send-email-wenzhuo.lu@intel.com> Subject: [dpdk-dev] [PATCH v5 21/31] net/ice: support MAC ops 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" Add below ops, mac_addr_set mac_addr_add mac_addr_remove Signed-off-by: Wenzhuo Lu Signed-off-by: Qiming Yang Signed-off-by: Xiaoyun Li Signed-off-by: Jingjing Wu --- doc/guides/nics/features/ice.ini | 2 + drivers/net/ice/ice_ethdev.c | 236 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 238 insertions(+) diff --git a/doc/guides/nics/features/ice.ini b/doc/guides/nics/features/ice.ini index fab6442..759a036 100644 --- a/doc/guides/nics/features/ice.ini +++ b/doc/guides/nics/features/ice.ini @@ -10,6 +10,8 @@ Link status event = Y Queue start/stop = Y MTU update = Y Jumbo frame = Y +Unicast MAC filter = Y +Multicast MAC filter = Y BSD nic_uio = Y Linux UIO = Y Linux VFIO = Y diff --git a/drivers/net/ice/ice_ethdev.c b/drivers/net/ice/ice_ethdev.c index 0c0efce..29840fd 100644 --- a/drivers/net/ice/ice_ethdev.c +++ b/drivers/net/ice/ice_ethdev.c @@ -24,6 +24,13 @@ static void ice_dev_info_get(struct rte_eth_dev *dev, static int ice_link_update(struct rte_eth_dev *dev, int wait_to_complete); static int ice_mtu_set(struct rte_eth_dev *dev, uint16_t mtu); +static int ice_macaddr_set(struct rte_eth_dev *dev, + struct ether_addr *mac_addr); +static int ice_macaddr_add(struct rte_eth_dev *dev, + struct ether_addr *mac_addr, + __rte_unused uint32_t index, + uint32_t pool); +static void ice_macaddr_remove(struct rte_eth_dev *dev, uint32_t index); static const struct rte_pci_id pci_id_ice_map[] = { { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E810C_BACKPLANE) }, @@ -50,6 +57,9 @@ static int ice_link_update(struct rte_eth_dev *dev, .dev_supported_ptypes_get = ice_dev_supported_ptypes_get, .link_update = ice_link_update, .mtu_set = ice_mtu_set, + .mac_addr_set = ice_macaddr_set, + .mac_addr_add = ice_macaddr_add, + .mac_addr_remove = ice_macaddr_remove, }; static void @@ -336,6 +346,130 @@ static int ice_link_update(struct rte_eth_dev *dev, return 0; } +/* Find out specific MAC filter */ +static struct ice_mac_filter * +ice_find_mac_filter(struct ice_vsi *vsi, struct ether_addr *macaddr) +{ + struct ice_mac_filter *f; + + TAILQ_FOREACH(f, &vsi->mac_list, next) { + if (is_same_ether_addr(macaddr, &f->mac_info.mac_addr)) + return f; + } + + return NULL; +} + +static int +ice_add_mac_filter(struct ice_vsi *vsi, struct ether_addr *mac_addr) +{ + struct ice_fltr_list_entry *m_list_itr = NULL; + struct ice_mac_filter *f; + struct LIST_HEAD_TYPE list_head; + struct ice_hw *hw = ICE_VSI_TO_HW(vsi); + int ret = 0; + + /* If it's added and configured, return */ + f = ice_find_mac_filter(vsi, mac_addr); + if (f) { + PMD_DRV_LOG(INFO, "This MAC filter already exists."); + return 0; + } + + INIT_LIST_HEAD(&list_head); + + m_list_itr = (struct ice_fltr_list_entry *) + ice_malloc(hw, sizeof(*m_list_itr)); + if (!m_list_itr) { + ret = -ENOMEM; + goto DONE; + } + ice_memcpy(m_list_itr->fltr_info.l_data.mac.mac_addr, + mac_addr, ETH_ALEN, ICE_NONDMA_TO_NONDMA); + m_list_itr->fltr_info.src_id = ICE_SRC_ID_VSI; + m_list_itr->fltr_info.fltr_act = ICE_FWD_TO_VSI; + m_list_itr->fltr_info.lkup_type = ICE_SW_LKUP_MAC; + m_list_itr->fltr_info.flag = ICE_FLTR_TX; + m_list_itr->fltr_info.vsi_handle = vsi->idx; + + LIST_ADD(&m_list_itr->list_entry, &list_head); + + /* Add the mac */ + ret = ice_add_mac(hw, &list_head); + if (ret != ICE_SUCCESS) { + PMD_DRV_LOG(ERR, "Failed to add MAC filter"); + ret = -EINVAL; + goto DONE; + } + /* Add the mac addr into mac list */ + f = rte_zmalloc(NULL, sizeof(*f), 0); + if (!f) { + PMD_DRV_LOG(ERR, "failed to allocate memory"); + ret = -ENOMEM; + goto DONE; + } + rte_memcpy(&f->mac_info.mac_addr, mac_addr, ETH_ADDR_LEN); + TAILQ_INSERT_TAIL(&vsi->mac_list, f, next); + vsi->mac_num++; + + ret = 0; + +DONE: + rte_free(m_list_itr); + return ret; +} + +static int +ice_remove_mac_filter(struct ice_vsi *vsi, struct ether_addr *mac_addr) +{ + struct ice_fltr_list_entry *m_list_itr = NULL; + struct ice_mac_filter *f; + struct LIST_HEAD_TYPE list_head; + struct ice_hw *hw = ICE_VSI_TO_HW(vsi); + int ret = 0; + + /* Can't find it, return an error */ + f = ice_find_mac_filter(vsi, mac_addr); + if (!f) + return -EINVAL; + + INIT_LIST_HEAD(&list_head); + + m_list_itr = (struct ice_fltr_list_entry *) + ice_malloc(hw, sizeof(*m_list_itr)); + if (!m_list_itr) { + ret = -ENOMEM; + goto DONE; + } + ice_memcpy(m_list_itr->fltr_info.l_data.mac.mac_addr, + mac_addr, ETH_ALEN, ICE_NONDMA_TO_NONDMA); + m_list_itr->fltr_info.src_id = ICE_SRC_ID_VSI; + m_list_itr->fltr_info.fltr_act = ICE_FWD_TO_VSI; + m_list_itr->fltr_info.lkup_type = ICE_SW_LKUP_MAC; + m_list_itr->fltr_info.flag = ICE_FLTR_TX; + m_list_itr->fltr_info.vsi_handle = vsi->idx; + + LIST_ADD(&m_list_itr->list_entry, &list_head); + + /* remove the mac filter */ + ret = ice_remove_mac(hw, &list_head); + if (ret != ICE_SUCCESS) { + PMD_DRV_LOG(ERR, "Failed to remove MAC filter"); + ret = -EINVAL; + goto DONE; + } + + /* Remove the mac addr from mac list */ + TAILQ_REMOVE(&vsi->mac_list, f, next); + rte_free(f); + vsi->mac_num--; + + ret = 0; +DONE: + rte_free(m_list_itr); + return ret; +} + /* Enable IRQ0 */ static void ice_pf_enable_irq0(struct ice_hw *hw) @@ -544,6 +678,9 @@ static int ice_link_update(struct rte_eth_dev *dev, struct ice_vsi *vsi = NULL; struct ice_vsi_ctx vsi_ctx; int ret; + struct ether_addr broadcast = { + .addr_bytes = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff} }; + struct ether_addr mac_addr; uint16_t max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 }; uint8_t tc_bitmap = 0x1; @@ -629,6 +766,21 @@ static int ice_link_update(struct rte_eth_dev *dev, pf->vsis_allocated = vsi_ctx.vsis_allocd; pf->vsis_unallocated = vsi_ctx.vsis_unallocated; + /* MAC configuration */ + rte_memcpy(pf->dev_addr.addr_bytes, + hw->port_info->mac.perm_addr, + ETH_ADDR_LEN); + + rte_memcpy(&mac_addr, &pf->dev_addr, ETHER_ADDR_LEN); + ret = ice_add_mac_filter(vsi, &mac_addr); + if (ret != ICE_SUCCESS) + PMD_INIT_LOG(ERR, "Failed to add dflt MAC filter"); + + rte_memcpy(&mac_addr, &broadcast, ETHER_ADDR_LEN); + ret = ice_add_mac_filter(vsi, &mac_addr); + if (ret != ICE_SUCCESS) + PMD_INIT_LOG(ERR, "Failed to add MAC filter"); + /* At the beginning, only TC0. */ /* What we need here is the maximam number of the TX queues. * Currently vsi->nb_qps means it. @@ -1261,6 +1413,90 @@ static int ice_init_rss(struct ice_pf *pf) return 0; } +static int ice_macaddr_set(struct rte_eth_dev *dev, + struct ether_addr *mac_addr) +{ + struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private); + struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private); + struct ice_vsi *vsi = pf->main_vsi; + struct ice_mac_filter *f; + uint8_t flags = 0; + int ret; + + if (!is_valid_assigned_ether_addr(mac_addr)) { + PMD_DRV_LOG(ERR, "Tried to set invalid MAC address."); + return -EINVAL; + } + + TAILQ_FOREACH(f, &vsi->mac_list, next) { + if (is_same_ether_addr(&pf->dev_addr, &f->mac_info.mac_addr)) + break; + } + + if (!f) { + PMD_DRV_LOG(ERR, "Failed to find filter for default mac"); + return -EIO; + } + + ret = ice_remove_mac_filter(vsi, &f->mac_info.mac_addr); + if (ret != ICE_SUCCESS) { + PMD_DRV_LOG(ERR, "Failed to delete mac filter"); + return -EIO; + } + ret = ice_add_mac_filter(vsi, mac_addr); + if (ret != ICE_SUCCESS) { + PMD_DRV_LOG(ERR, "Failed to add mac filter"); + return -EIO; + } + memcpy(&pf->dev_addr, mac_addr, ETH_ADDR_LEN); + + flags = ICE_AQC_MAN_MAC_UPDATE_LAA_WOL; + ret = ice_aq_manage_mac_write(hw, mac_addr->addr_bytes, flags, NULL); + if (ret != ICE_SUCCESS) { + PMD_DRV_LOG(ERR, "Failed to set manage mac"); + } + + return 0; +} + +/* Add a MAC address, and update filters */ +static int +ice_macaddr_add(struct rte_eth_dev *dev, + struct ether_addr *mac_addr, + __rte_unused uint32_t index, + __rte_unused uint32_t pool) +{ + struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private); + struct ice_vsi *vsi = pf->main_vsi; + int ret; + + ret = ice_add_mac_filter(vsi, mac_addr); + if (ret != ICE_SUCCESS) { + PMD_DRV_LOG(ERR, "Failed to add MAC filter"); + return -EINVAL; + } + + return ICE_SUCCESS; +} + +/* Remove a MAC address, and update filters */ +static void +ice_macaddr_remove(struct rte_eth_dev *dev, uint32_t index) +{ + struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private); + struct ice_vsi *vsi = pf->main_vsi; + struct rte_eth_dev_data *data = dev->data; + struct ether_addr *macaddr; + int ret; + + macaddr = &data->mac_addrs[index]; + ret = ice_remove_mac_filter(vsi, macaddr); + if (ret) { + PMD_DRV_LOG(ERR, "Failed to remove MAC filter"); + return; + } +} + static int ice_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, struct rte_pci_device *pci_dev)