From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 52921A04B1; Tue, 25 Aug 2020 13:55:08 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8BD261C2A3; Tue, 25 Aug 2020 13:53:51 +0200 (CEST) Received: from mail.chinasoftinc.com (unknown [114.113.233.8]) by dpdk.org (Postfix) with ESMTP id 2568D1C296 for ; Tue, 25 Aug 2020 13:53:48 +0200 (CEST) Received: from localhost.localdomain (65.49.108.226) by INCCAS002.ito.icss (10.168.0.60) with Microsoft SMTP Server id 14.3.487.0; Tue, 25 Aug 2020 19:53:39 +0800 From: "Wei Hu (Xavier)" To: CC: , Date: Tue, 25 Aug 2020 19:53:03 +0800 Message-ID: <20200825115305.58490-10-huwei013@chinasoftinc.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200825115305.58490-1-huwei013@chinasoftinc.com> References: <20200825115305.58490-1-huwei013@chinasoftinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [65.49.108.226] Subject: [dpdk-dev] [PATCH 09/11] net/hns3: fix default MAC addr from firmware 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: Huisong Li Currently, default MAC address obtained from firmware in hns3 PF PMD driver is directly used by .mac_addr_set ops implementation function when the rte_eth_dev_start API function is executed. At this moment, if the default MAC addr isn't an unicast address, it will fail to set default MAC addr to hardware. So this patch adds the validity check of default MAC addr in hns3 PF PMD driver. We will use a random unicast address, if the default MAC address obtained from firmware is not a vailid unicast address. In addition, this patch also adjusts the location of processing default MAC addr in hns3 VF PMD driver so as to increase relevance and readability of the code. Fixes: eab21776717 ("net/hns3: support setting VF MAC address by PF driver") Fixes: d51867db65c ("net/hns3: add initialization") Cc: stable@dpdk.org Signed-off-by: Huisong Li Signed-off-by: Wei Hu (Xavier) Signed-off-by: Chengchang Tang --- drivers/net/hns3/hns3_ethdev.c | 11 +++++++++++ drivers/net/hns3/hns3_ethdev_vf.c | 29 ++++++++++++++--------------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c index 3827d3277..14e4b9e35 100644 --- a/drivers/net/hns3/hns3_ethdev.c +++ b/drivers/net/hns3/hns3_ethdev.c @@ -5574,6 +5574,8 @@ static int hns3_dev_init(struct rte_eth_dev *eth_dev) { struct hns3_adapter *hns = eth_dev->data->dev_private; + char mac_str[RTE_ETHER_ADDR_FMT_SIZE]; + struct rte_ether_addr *eth_addr; struct hns3_hw *hw = &hns->hw; int ret; @@ -5646,6 +5648,15 @@ hns3_dev_init(struct rte_eth_dev *eth_dev) goto err_rte_zmalloc; } + eth_addr = (struct rte_ether_addr *)hw->mac.mac_addr; + if (!rte_is_valid_assigned_ether_addr(eth_addr)) { + rte_eth_random_addr(hw->mac.mac_addr); + rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE, + (struct rte_ether_addr *)hw->mac.mac_addr); + hns3_warn(hw, "default mac_addr from firmware is an invalid " + "unicast address, using random MAC address %s", + mac_str); + } rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.mac_addr, ð_dev->data->mac_addrs[0]); diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c index 3b2ba69bb..7fd0e6a43 100644 --- a/drivers/net/hns3/hns3_ethdev_vf.c +++ b/drivers/net/hns3/hns3_ethdev_vf.c @@ -1748,21 +1748,6 @@ hns3vf_init_vf(struct rte_eth_dev *eth_dev) goto err_get_config; } - /* - * The hns3 PF ethdev driver in kernel support setting VF MAC address - * on the host by "ip link set ..." command. To avoid some incorrect - * scenes, for example, hns3 VF PMD driver fails to receive and send - * packets after user configure the MAC address by using the - * "ip link set ..." command, hns3 VF PMD driver keep the same MAC - * address strategy as the hns3 kernel ethdev driver in the - * initialization. If user configure a MAC address by the ip command - * for VF device, then hns3 VF PMD driver will start with it, otherwise - * start with a random MAC address in the initialization. - */ - ret = rte_is_zero_ether_addr((struct rte_ether_addr *)hw->mac.mac_addr); - if (ret) - rte_eth_random_addr(hw->mac.mac_addr); - ret = hns3vf_clear_vport_list(hw); if (ret) { PMD_INIT_LOG(ERR, "Failed to clear tbl list: %d", ret); @@ -2644,8 +2629,22 @@ hns3vf_dev_init(struct rte_eth_dev *eth_dev) goto err_rte_zmalloc; } + /* + * The hns3 PF ethdev driver in kernel support setting VF MAC address + * on the host by "ip link set ..." command. To avoid some incorrect + * scenes, for example, hns3 VF PMD driver fails to receive and send + * packets after user configure the MAC address by using the + * "ip link set ..." command, hns3 VF PMD driver keep the same MAC + * address strategy as the hns3 kernel ethdev driver in the + * initialization. If user configure a MAC address by the ip command + * for VF device, then hns3 VF PMD driver will start with it, otherwise + * start with a random MAC address in the initialization. + */ + if (rte_is_zero_ether_addr((struct rte_ether_addr *)hw->mac.mac_addr)) + rte_eth_random_addr(hw->mac.mac_addr); rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.mac_addr, ð_dev->data->mac_addrs[0]); + hw->adapter_state = HNS3_NIC_INITIALIZED; /* * Pass the information to the rte_eth_dev_close() that it should also -- 2.27.0