From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF435CA9EAE for ; Wed, 23 Oct 2019 06:22:16 +0000 (UTC) Received: from dpdk.org (dpdk.org [92.243.14.124]) by mail.kernel.org (Postfix) with ESMTP id 4ABDE2173B for ; Wed, 23 Oct 2019 06:22:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4ABDE2173B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nxp.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=dev-bounces@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 044731BF97; Wed, 23 Oct 2019 08:22:07 +0200 (CEST) Received: from inva021.nxp.com (inva021.nxp.com [92.121.34.21]) by dpdk.org (Postfix) with ESMTP id 929221BF87 for ; Wed, 23 Oct 2019 08:22:00 +0200 (CEST) Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 58C1F20081E; Wed, 23 Oct 2019 08:22:00 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 8A1DB200054; Wed, 23 Oct 2019 08:21:58 +0200 (CEST) Received: from GDB1.ap.freescale.net (GDB1.ap.freescale.net [10.232.132.179]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 68D10402F3; Wed, 23 Oct 2019 14:21:55 +0800 (SGT) From: Gagandeep Singh To: dev@dpdk.org, ferruh.yigit@intel.com Cc: Gagandeep Singh Date: Wed, 23 Oct 2019 11:36:00 +0530 Message-Id: <20191023060602.32456-3-g.singh@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191023060602.32456-1-g.singh@nxp.com> References: <20191021105027.14792-1-g.singh@nxp.com> <20191023060602.32456-1-g.singh@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Subject: [dpdk-dev] [PATCH v5 2/4] net/enetc: set random MAC in case no MAC for SI 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" for SGMII interfaces, there can be 0 value written on MAC registers. This patch set the random MAC address for those interfaces. Signed-off-by: Gagandeep Singh --- drivers/net/enetc/Makefile | 2 +- drivers/net/enetc/enetc_ethdev.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/drivers/net/enetc/Makefile b/drivers/net/enetc/Makefile index 9895501db..312b37245 100644 --- a/drivers/net/enetc/Makefile +++ b/drivers/net/enetc/Makefile @@ -17,7 +17,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_ENETC_PMD) += enetc_ethdev.c SRCS-$(CONFIG_RTE_LIBRTE_ENETC_PMD) += enetc_rxtx.c LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -LDLIBS += -lrte_ethdev +LDLIBS += -lrte_ethdev -lrte_net LDLIBS += -lrte_bus_pci include $(RTE_SDK)/mk/rte.lib.mk diff --git a/drivers/net/enetc/enetc_ethdev.c b/drivers/net/enetc/enetc_ethdev.c index 4e978348c..d07e61c3f 100644 --- a/drivers/net/enetc/enetc_ethdev.c +++ b/drivers/net/enetc/enetc_ethdev.c @@ -4,6 +4,7 @@ #include #include +#include #include "enetc_logs.h" #include "enetc.h" @@ -123,11 +124,22 @@ enetc_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused) return rte_eth_linkstatus_set(dev, &link); } +static void +print_ethaddr(const char *name, const struct rte_ether_addr *eth_addr) +{ + char buf[RTE_ETHER_ADDR_FMT_SIZE]; + + rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr); + ENETC_PMD_INFO("%s%s\n", name, buf); +} + static int enetc_hardware_init(struct enetc_eth_hw *hw) { struct enetc_hw *enetc_hw = &hw->hw; uint32_t *mac = (uint32_t *)hw->mac.addr; + uint32_t high_mac = 0; + uint16_t low_mac = 0; PMD_INIT_FUNC_TRACE(); /* Calculating and storing the base HW addresses */ @@ -138,8 +150,27 @@ enetc_hardware_init(struct enetc_eth_hw *hw) enetc_wr(enetc_hw, ENETC_SIMR, ENETC_SIMR_EN); *mac = (uint32_t)enetc_port_rd(enetc_hw, ENETC_PSIPMAR0(0)); + high_mac = (uint32_t)*mac; mac++; *mac = (uint16_t)enetc_port_rd(enetc_hw, ENETC_PSIPMAR1(0)); + low_mac = (uint16_t)*mac; + + if ((high_mac | low_mac) == 0) { + char *first_byte; + + mac = (uint32_t *)hw->mac.addr; + *mac = (uint32_t)rte_rand(); + first_byte = (char *)mac; + *first_byte &= 0xfe; /* clear multicast bit */ + *first_byte |= 0x02; /* set local assignment bit (IEEE802) */ + + enetc_port_wr(enetc_hw, ENETC_PSIPMAR0(0), *mac); + mac++; + *mac = (uint16_t)rte_rand(); + enetc_port_wr(enetc_hw, ENETC_PSIPMAR1(0), *mac); + print_ethaddr("New address: ", + (const struct rte_ether_addr *)hw->mac.addr); + } return 0; } -- 2.17.1