From patchwork Wed Aug 5 12:30:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 1341217 X-Patchwork-Delegate: eugen.hristev@microchip.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=microchip.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=microchip.com header.i=@microchip.com header.a=rsa-sha256 header.s=mchp header.b=mYyfLOLz; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BM9wL6fmRz9sRK for ; Wed, 5 Aug 2020 22:31:30 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6DA2F81B65; Wed, 5 Aug 2020 14:31:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=quarantine dis=none) header.from=microchip.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=microchip.com header.i=@microchip.com header.b="mYyfLOLz"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 17D9B81E39; Wed, 5 Aug 2020 14:31:17 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from esa1.microchip.iphmx.com (esa1.microchip.iphmx.com [68.232.147.91]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E9B2B81B5E for ; Wed, 5 Aug 2020 14:31:08 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=microchip.com Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=Eugen.Hristev@microchip.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1596630668; x=1628166668; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=6mto94vzif0R7B6rr1kuk3MD4I674QnistFmUL20cJA=; b=mYyfLOLzrqpdjSTjt43pc/bbSpgtCRbV2LZ07gZ0UB0PPgnDMAgJA3Kf iIgrmybMRjqgcSq5R55uIW70hX8XNF8OBOs2YbJah97ICjZSuVEEMHnFE Z8I5Ujl0Bo5by2KwyLoEfBJfrtteIizANvf4citisOaeE54jPCcWzpjAU RstKowqM9RncJAdE7zCBy1P3uMKWRB/T/b3lejvQ0qIq9f45O3w7t7STN 1dTVLCVuQUZPE/4lZ0Msn7AZrQu1Mr1rAFksLVYPeSyWAvCY9EAgoPcAv H+tIpvNQYkbR/s9YCshArfVY80vliuCLpJehy5dyLq0SUuMoCjF8KbuGa A==; IronPort-SDR: TELMckJzKUDHMwfPQxfGTADexqMgSzHqJyrtewlFuRpmjnpiXOLv0ty+OTI6t1VcvNs3wyzcXO TuA2Be44fdL2JyYxFz+LcvcVUhzB8Yu4twic4RZCupi6nugXZw+bvfbFaMP1z8Fa2T+t5AknNq j3sgJmaA9v9a3E27ZQq6NNDTsaFVF1tpGk+WSC49M1JeG0bhnDTooqZkszwVI7rNtC1QVA+byD iJMDn+BmqfbR+DFMjnhdRKX2bTIkgCdvkX1pY6DnZArMx9AdhDoLPp6UW1ueMBC8n2vLd72zEM U4Q= X-IronPort-AV: E=Sophos;i="5.75,436,1589266800"; d="scan'208";a="90549189" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa1.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 05 Aug 2020 05:30:56 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 5 Aug 2020 05:30:54 -0700 Received: from ROB-ULT-M18282.microchip.com (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.1979.3 via Frontend Transport; Wed, 5 Aug 2020 05:30:39 -0700 From: Eugen Hristev To: CC: Eugen Hristev Subject: [PATCH] board: atmel: common: introduce at91_set_eth1addr for second interface Date: Wed, 5 Aug 2020 15:30:34 +0300 Message-ID: <20200805123034.176792-1-eugen.hristev@microchip.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean We already have a function to retrieve the mac address from one EEPROM. For boards with a second Ethernet interface, however, we would require another EEPROM with a second unique MAC address. Introduce at91_set_eth1addr which will look for a second EEPROM and set the 'eth1addr' variable with the obtained MAC address. Signed-off-by: Eugen Hristev --- arch/arm/mach-at91/include/mach/at91_common.h | 1 + board/atmel/common/mac_eeprom.c | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/arch/arm/mach-at91/include/mach/at91_common.h b/arch/arm/mach-at91/include/mach/at91_common.h index 01e00c508a..f7b411cf7d 100644 --- a/arch/arm/mach-at91/include/mach/at91_common.h +++ b/arch/arm/mach-at91/include/mach/at91_common.h @@ -40,6 +40,7 @@ void configure_ddrcfg_input_buffers(bool open); #endif int at91_set_ethaddr(int offset); +int at91_set_eth1addr(int offset); void at91_spi_nor_set_ethaddr(void); int at91_video_show_board_info(void); diff --git a/board/atmel/common/mac_eeprom.c b/board/atmel/common/mac_eeprom.c index 050aa51ee1..0f038beee6 100644 --- a/board/atmel/common/mac_eeprom.c +++ b/board/atmel/common/mac_eeprom.c @@ -35,3 +35,36 @@ int at91_set_ethaddr(int offset) return 0; } + +/* this function will set eth1addr from a second eeprom, if available */ +int at91_set_eth1addr(int offset) +{ + const int ETH_ADDR_LEN = 6; + unsigned char ethaddr[ETH_ADDR_LEN]; + /* configure eth1addr for second interface */ + const char *ETHADDR_NAME = "eth1addr"; + struct udevice *dev; + int ret; + + if (env_get(ETHADDR_NAME)) + return 0; + + /* first eeprom is retrieved, this is for the first interface */ + ret = uclass_first_device_err(UCLASS_I2C_EEPROM, &dev); + if (ret) + return ret; + + /* attempt to obtain a second eeprom device */ + ret = uclass_next_device(&dev); + if (ret) + return ret; + + ret = i2c_eeprom_read(dev, offset, ethaddr, 6); + if (ret) + return ret; + + if (is_valid_ethaddr(ethaddr)) + eth_env_set_enetaddr(ETHADDR_NAME, ethaddr); + + return 0; +}