From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id B98481BC8D for ; Tue, 18 Dec 2018 09:42:23 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2018 00:42:23 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,367,1539673200"; d="scan'208";a="111449589" Received: from dpdk26.sh.intel.com ([10.67.110.164]) by orsmga003.jf.intel.com with ESMTP; 18 Dec 2018 00:42:22 -0800 From: Wenzhuo Lu To: dev@dpdk.org Cc: Wenzhuo Lu , Qiming Yang , Xiaoyun Li , Jingjing Wu Date: Tue, 18 Dec 2018 16:46:32 +0800 Message-Id: <1545122800-57293-24-git-send-email-wenzhuo.lu@intel.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1545122800-57293-1-git-send-email-wenzhuo.lu@intel.com> References: <1542956179-80951-1-git-send-email-wenzhuo.lu@intel.com> <1545122800-57293-1-git-send-email-wenzhuo.lu@intel.com> Subject: [dpdk-dev] [PATCH v6 23/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: , X-List-Received-Date: Tue, 18 Dec 2018 08:42:24 -0000 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 | 235 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 237 insertions(+) diff --git a/doc/guides/nics/features/ice.ini b/doc/guides/nics/features/ice.ini index 7a87de3..ff4749f 100644 --- a/doc/guides/nics/features/ice.ini +++ b/doc/guides/nics/features/ice.ini @@ -11,6 +11,8 @@ Queue start/stop = Y MTU update = Y Jumbo frame = Y TSO = Y +Unicast MAC filter = Y +Multicast MAC filter = Y CRC offload = Y L3 checksum offload = Y L4 checksum offload = Y diff --git a/drivers/net/ice/ice_ethdev.c b/drivers/net/ice/ice_ethdev.c index f7c0b36..a124c9c 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, .rxq_info_get = ice_rxq_info_get, .txq_info_get = ice_txq_info_get, .rx_queue_count = ice_rx_queue_count, @@ -339,6 +349,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) @@ -547,6 +681,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; @@ -632,6 +769,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. @@ -1260,6 +1412,89 @@ 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) -- 1.9.3