From patchwork Fri Apr 21 08:43:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 13219639 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 31E44C77B75 for ; Fri, 21 Apr 2023 08:44:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ujvmfYa1xutviENEnh5mtbcOCW0hbziWxTTrMYsbf30=; b=hPBHsyJiwSSR9M iPX69Xm3lOXud7wHXcafAPgdTFIkW2TWpMwFJ+Ip64PqEKXH8QaegoJ7o7BRH2TA05CEOpYjUC8RK RsGxqjH77FAiPi0WpaDcyIX42Fmsz254c4r1fDoo+iTSpVg9nlgAp2zahXujmhJOfKAqV0zoJPuPv 1KrbLNjxNwfGZgT/cisf18a7TGn4VFIsVbr6IbjB52G9vGri4BpRrV+jZDfDiGsjtolYJ1ZOJE1Cn D+GWG+OVHULPDRBHyZgIkjDCBUk/nmimoSNGUXd9wVLhtaSC80CC6j8oCFCZ2n6f7QFVE+mo3gCkr QJnLjH3HdIZ4xvwsCWAA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1ppmMd-00A86Q-3A; Fri, 21 Apr 2023 08:43:32 +0000 Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1ppmMW-00A83y-19 for linux-arm-kernel@lists.infradead.org; Fri, 21 Apr 2023 08:43:25 +0000 Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-4ec8399e963so1426127e87.1 for ; Fri, 21 Apr 2023 01:43:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682066602; x=1684658602; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wfYMOG8gPlyg4Z3cWn2F4o0SjxhHFN6Ihcum8cR5Xlk=; b=a+41VRsBYTq/V/MhxS4NncMUAaeaB+X7nipm5u7gcYrjjGhOf20sOA3+NqCjD7GWjS COQujy7krMnzNLKyYCGK8t5TfWwsCHzsucl05eZxHbpgLBCeg7b4+5K3bc8rfjgcI+Ne bs6ICN/bPGr1VRm8xsNBy/4/uUy40ITOsRLY97wBb1SO3V/zs5Sf9ZuTiN4H6fWTyt2o 8C0GoLdN8d3s0EDjpjU9/L0v54kLzSptqJJB51KWJX+grW2HyUgWIojifEerJsNRHsp1 kgD8iky9NeMRrq5E/HmvrILuhoZB5hmyXQ9A6nlB/6ZbNa0f400kcc3mr4TcVVa7i1Cj BOeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682066602; x=1684658602; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wfYMOG8gPlyg4Z3cWn2F4o0SjxhHFN6Ihcum8cR5Xlk=; b=gU7UPJXHowsQnVDI2xndzsV4VoeLo5CGtvMwo81/wuUgiwHY+/ZKi9h21Q/rDmI76s ngHodtsgvgwrVdwA8q62xZPOhrWf7UnmUWpvX4KYtaOmi9L2oTXYmKcozBCU8Zsn11rc BHUvV6fQK3zQ6UPPgwF0eJsnNDNvLVh7IIx+eby9CApfsao5ywnBsqSjAoSimRd539wy DUYvCBwN+Epc5XcAP9r6P9j2u0giYkxMYRkwg7hI8YFi5jLtH6kRuxHu7LorE78qU9gN 3dQEGt2gzPqF9ZcWt0k/QjtiT9UhkkBMcTKLpEK0K+nBJ05h8GzVkA9G5Xfn2/J2zaSL TExA== X-Gm-Message-State: AAQBX9ccMUoai7VtFXKWHyqss7OYpnKYhHQWPOTGUPaf0Q+u5609D5n+ tmjBtrcuO4kLLa9Fg5TsILw= X-Google-Smtp-Source: AKy350ah6s/GHGWSiKmHFzEyCAr9Dac0vpwQM2CEfN9P6MLOH0UyDwlWNTmr7FY3MEzznuGyXjpKXQ== X-Received: by 2002:ac2:4e52:0:b0:4ea:fac4:8ef2 with SMTP id f18-20020ac24e52000000b004eafac48ef2mr910330lfr.64.1682066601602; Fri, 21 Apr 2023 01:43:21 -0700 (PDT) Received: from localhost.lan (031011218106.poznan.vectranet.pl. [31.11.218.106]) by smtp.gmail.com with ESMTPSA id l16-20020ac25550000000b004edc16dbdfasm480721lfk.119.2023.04.21.01.43.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Apr 2023 01:43:21 -0700 (PDT) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Rob Herring , Krzysztof Kozlowski , Srinivas Kandagatla Cc: Florian Fainelli , Hauke Mehrtens , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, bcm-kernel-feedback-list@broadcom.com, linux-kernel@vger.kernel.org, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH V2 2/3] nvmem: brcm_nvram: add .read_post_process() for MACs Date: Fri, 21 Apr 2023 10:43:11 +0200 Message-Id: <20230421084312.27932-2-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230421084312.27932-1-zajec5@gmail.com> References: <20230421084312.27932-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230421_014324_393203_7E3ED469 X-CRM114-Status: GOOD ( 15.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Rafał Miłecki 1. Parse ASCII MAC format into byte based 2. Calculate relative addresses based on index argument Signed-off-by: Rafał Miłecki --- drivers/nvmem/Kconfig | 1 + drivers/nvmem/brcm_nvram.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index b291b27048c7..688b70ba4826 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -55,6 +55,7 @@ config NVMEM_BRCM_NVRAM tristate "Broadcom's NVRAM support" depends on ARCH_BCM_5301X || COMPILE_TEST depends on HAS_IOMEM + select GENERIC_NET_UTILS help This driver provides support for Broadcom's NVRAM that can be accessed using I/O mapping. diff --git a/drivers/nvmem/brcm_nvram.c b/drivers/nvmem/brcm_nvram.c index 39aa27942f28..4567c597c87f 100644 --- a/drivers/nvmem/brcm_nvram.c +++ b/drivers/nvmem/brcm_nvram.c @@ -4,6 +4,8 @@ */ #include +#include +#include #include #include #include @@ -42,6 +44,25 @@ static int brcm_nvram_read(void *context, unsigned int offset, void *val, return 0; } +static int brcm_nvram_read_post_process_macaddr(void *context, const char *id, int index, + unsigned int offset, void *buf, size_t bytes) +{ + u8 mac[ETH_ALEN]; + + if (bytes != 3 * ETH_ALEN - 1) + return -EINVAL; + + if (!mac_pton(buf, mac)) + return -EINVAL; + + if (index) + eth_addr_add(mac, index); + + ether_addr_copy(buf, mac); + + return 0; +} + static int brcm_nvram_add_cells(struct brcm_nvram *priv, uint8_t *data, size_t len) { @@ -75,6 +96,13 @@ static int brcm_nvram_add_cells(struct brcm_nvram *priv, uint8_t *data, priv->cells[idx].offset = value - (char *)data; priv->cells[idx].bytes = strlen(value); priv->cells[idx].np = of_get_child_by_name(dev->of_node, priv->cells[idx].name); + if (!strcmp(var, "et0macaddr") || + !strcmp(var, "et1macaddr") || + !strcmp(var, "et2macaddr")) { + priv->cells[idx].raw_len = strlen(value); + priv->cells[idx].bytes = ETH_ALEN; + priv->cells[idx].read_post_process = brcm_nvram_read_post_process_macaddr; + } } return 0;