From patchwork Tue Mar 14 13:04:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 95297 Delivered-To: patch@linaro.org Received: by 10.140.89.134 with SMTP id v6csp250620qgd; Tue, 14 Mar 2017 06:05:26 -0700 (PDT) X-Received: by 10.28.180.135 with SMTP id d129mr14162136wmf.135.1489496726097; Tue, 14 Mar 2017 06:05:26 -0700 (PDT) Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id z20si15276795wmc.68.2017.03.14.06.05.25; Tue, 14 Mar 2017 06:05:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@ti.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ti.com Received: by lists.denx.de (Postfix, from userid 105) id A48CAC21C56; Tue, 14 Mar 2017 13:05:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 90099C21C29; Tue, 14 Mar 2017 13:05:20 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id E27A5C21C29; Tue, 14 Mar 2017 13:05:18 +0000 (UTC) Received: from lelnx194.ext.ti.com (lelnx194.ext.ti.com [198.47.27.80]) by lists.denx.de (Postfix) with ESMTPS id 43558C21C26 for ; Tue, 14 Mar 2017 13:05:18 +0000 (UTC) Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by lelnx194.ext.ti.com (8.15.1/8.15.1) with ESMTP id v2ED4MdD019906; Tue, 14 Mar 2017 08:04:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1489496662; bh=qfAUsY/E+bjnvTmYs8Qu8RHkBWcrpV5L//4uk8q8Iv4=; h=Subject:To:References:CC:From:Date:In-Reply-To; b=n+26udk/2muTi6G06/yk7YoXGMLKnjaRxaUeum3ql0Ix13uubejmYTCU2vliMcxqK 0hEhZpcjhJY3SGYVqNcSHbXqkhYl0WsxLh2vjGzgu9jDQ7rZT6bAY6iYJ/v6NNmmAl D/5noFfhWu83xkfwoFB8uRofVfrJoYdF7nmL9MTw= Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id v2ED4MNK016963; Tue, 14 Mar 2017 08:04:22 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.294.0; Tue, 14 Mar 2017 08:04:21 -0500 Received: from [192.168.2.6] (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id v2ED4JHU003922; Tue, 14 Mar 2017 08:04:20 -0500 To: References: <1489410273-10159-1-git-send-email-rogerq@ti.com> <1489410273-10159-5-git-send-email-rogerq@ti.com> From: Roger Quadros Message-ID: Date: Tue, 14 Mar 2017 15:04:19 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: <1489410273-10159-5-git-send-email-rogerq@ti.com> Cc: Felipe Balbi , u-boot@lists.denx.de Subject: [U-Boot] [u-boot PATCH v5 04/10] ti: common: board_detect: commodify ethaddr environment setting code X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" Keystone and OMAP platforms will need this to set ethernet MAC addresses from board EEPROM. Signed-off-by: Roger Quadros Reviewed-by: Lokesh Vutla Reviewed-by: Tom Rini --- v5: - Set upto 50 MAC addresses if more than 50 are provided in board EEPROM. board/ti/common/board_detect.c | 62 ++++++++++++++++++++++++++++++++++++++++++ board/ti/common/board_detect.h | 12 ++++++++ 2 files changed, 74 insertions(+) diff --git a/board/ti/common/board_detect.c b/board/ti/common/board_detect.c index a5dba94..c55e24e 100644 --- a/board/ti/common/board_detect.c +++ b/board/ti/common/board_detect.c @@ -314,3 +314,65 @@ void __maybe_unused set_board_info_env(char *name) else setenv("board_serial", unknown); } + +static u64 mac_to_u64(u8 mac[6]) +{ + int i; + u64 addr = 0; + + for (i = 0; i < 6; i++) { + addr <<= 8; + addr |= mac[i]; + } + + return addr; +} + +static void u64_to_mac(u64 addr, u8 mac[6]) +{ + mac[5] = addr; + mac[4] = addr >> 8; + mac[3] = addr >> 16; + mac[2] = addr >> 24; + mac[1] = addr >> 32; + mac[0] = addr >> 40; +} + +void board_ti_set_ethaddr(int index) +{ + uint8_t mac_addr[6]; + int i; + u64 mac1, mac2; + u8 mac_addr1[6], mac_addr2[6]; + int num_macs; + /* + * Export any Ethernet MAC addresses from EEPROM. + * The 2 MAC addresses in EEPROM define the address range. + */ + board_ti_get_eth_mac_addr(0, mac_addr1); + board_ti_get_eth_mac_addr(1, mac_addr2); + + if (is_valid_ethaddr(mac_addr1) && is_valid_ethaddr(mac_addr2)) { + mac1 = mac_to_u64(mac_addr1); + mac2 = mac_to_u64(mac_addr2); + + /* must contain an address range */ + num_macs = mac2 - mac1 + 1; + if (num_macs <= 0) + return; + + if (num_macs > 50) { + printf("%s: Too many MAC addresses: %d. Limiting to 50\n", + __func__, num_macs); + num_macs = 50; + } + + for (i = 0; i < num_macs; i++) { + u64_to_mac(mac1 + i, mac_addr); + if (is_valid_ethaddr(mac_addr)) { + eth_setenv_enetaddr_by_index("eth", i + index, + mac_addr); + } + } + } +} diff --git a/board/ti/common/board_detect.h b/board/ti/common/board_detect.h index 52b0075..88b0a59 100644 --- a/board/ti/common/board_detect.h +++ b/board/ti/common/board_detect.h @@ -193,4 +193,16 @@ u64 board_ti_get_emif2_size(void); */ void set_board_info_env(char *name); +/** + * board_ti_set_ethaddr- Sets the ethaddr environment from EEPROM + * @index: The first ethaddr environment variable to set + * + * EEPROM should be already read before calling this function. + * The EEPROM contains 2 MAC addresses which define the MAC address + * range (i.e. first and last MAC address). + * This function sets the ethaddr environment variable for all + * the available MAC addresses starting from ethaddr. + */ +void board_ti_set_ethaddr(int index); + #endif /* __BOARD_DETECT_H */