From patchwork Thu Apr 6 11:08:03 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: 80202 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp946804vqo; Thu, 6 Apr 2023 04:26:22 -0700 (PDT) X-Google-Smtp-Source: AKy350YEv43OhY0hcqITLsCZg3XjYWD2qbjh9SZ2c4kD7jk1l8EqgmHjUM7qMcnHRGAtLnnCcMjO X-Received: by 2002:a17:907:8b95:b0:92b:eefb:b966 with SMTP id tb21-20020a1709078b9500b0092beefbb966mr7359567ejc.0.1680780382446; Thu, 06 Apr 2023 04:26:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680780382; cv=none; d=google.com; s=arc-20160816; b=sCKGEC3nuak41Cchx87EjnSzXTylHO2pKA6TV3f5P2+qvPrcbN5iOpfO13QHBCd6NA mO2kiJ6mlqOFOa189mM0DFiNsxnMLzeJWeGF+9t/62huLdETLiDFgB5ylI2Y1CFLhpqb pD0K1hI5jybO7DPdOUL3awkiijCM5LYAsjxnDOtcBvtd2Imj4qiCssdanZQ3DH2IQE9q 0gLUWcrsI06kc4tGW3ETXmh6U8hG3n6ZutrJCkND14R+1DacGkqJ8nE0xxiASrdOqlam B7Urkk0elg7FUbf4P0W87XuWAma+DDO4bZ1q9sKtAwY1kBZxWGQkfQwYW2GtoaHIoZXU Dr8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wfYMOG8gPlyg4Z3cWn2F4o0SjxhHFN6Ihcum8cR5Xlk=; b=XJSTPE2unhtMmzt4NPBr86nHlI/xSN4frWqtzbHbh3WFbY8Rvuh5HFwTwse9Zl6b40 k0cyTYNLFngEjJMl/3RTX7w/vYfP9Oy4tNAWDBSqI/s/M1ykSHt8XRvh9kv35W/CBS4F p3G50zj9A8817ogUYcBWuYjiB20Z9WgJnZya1WQntgXCwRbUYe6/dGXt+bXoLPePJes4 lRqkvluYYS2irbuIaON1Q+AsUbZqf29tA2l8+XAtmnEByqwFpxe/PkmBRhacA6WSr/K6 YTFHWtWfmX8EAAMrufsfl4sgkAayhbKQbYK9Dc+zCZKp9i4MHuCtdxBGC/AsWjpW6kAW 3cgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=p6OqGU8g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l26-20020a17090615da00b0093d4ca392a1si895979ejd.409.2023.04.06.04.25.58; Thu, 06 Apr 2023 04:26:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=p6OqGU8g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237261AbjDFLJB (ORCPT + 99 others); Thu, 6 Apr 2023 07:09:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236833AbjDFLI6 (ORCPT ); Thu, 6 Apr 2023 07:08:58 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7065972A0; Thu, 6 Apr 2023 04:08:57 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id q16so50299830lfe.10; Thu, 06 Apr 2023 04:08:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680779336; 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=p6OqGU8gW0fCJlDL00V8f51dUiscXEsiSaD5vmQO1isPXkmvIh9KT8CDihdJexXbVQ q3tgHgG4DpF06psRjl2A0IwVsn7JX5nomaufOSyqRqwv5ek93yeBNotwx9a7jv2Hx3jX huraJ/iQLlQk0axSQbJnfik5t4ssW1sNuwAp2CLylhKbUT1vphXZg7hswQOtf6gru7og GYKjDGlUc94LMNNxr2vHX0t+Yyy/c0JvLlFUDELjqewTug0YBn0HwusAej3sAMJBsd0/ dSR0LlkVSh/BpSwUfX0PVU1Q562PEQvh67dmT7x5Sp4gYIPmyP5w/qIVOiReOYL5Wmcq sa8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680779336; 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=THv+dHDKSfSCDa7U0gg4XWKkMSG9ZRwx4UvabVKHgStwonZ3Ztf/OqSkD8yJsr/wnL GLdeVu3txYMuu5hKUD50tDAcv36mF6JMCcZ8r6CQAuUhLAnlrYaeJPeuDHTxUnIrAVzk k0ITwsksPt/OfNG+rw1efED+7IAOQiErKR7IqsaJPvp8OxDOL7Uqkl0fKD8DDyHpVvtJ UNhMxgxPKtO5l1cHkY7EMAWD0PgzkOCL9dk4MXJ0aQrsiPM5yBZBPeCzYDf4dT+E87MN xdkHh1zZkvxXgA9HSYg2IZDgmXDQ9Qnxt6Fu+jx8k66paPZg1K5dQA1+p3/Ok1PVpLOY CCtA== X-Gm-Message-State: AAQBX9c85SoSruYp+UX1DNjHPywCUwTNMsfG1SwJCx6uFuLnUE78AzNV snee8pYm59HBuMiF9UMbfYw= X-Received: by 2002:ac2:4a63:0:b0:4ea:e262:e551 with SMTP id q3-20020ac24a63000000b004eae262e551mr2417608lfp.31.1680779335666; Thu, 06 Apr 2023 04:08:55 -0700 (PDT) Received: from localhost.lan (031011218106.poznan.vectranet.pl. [31.11.218.106]) by smtp.gmail.com with ESMTPSA id r26-20020ac252ba000000b004e048852377sm218667lfm.263.2023.04.06.04.08.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Apr 2023 04:08:55 -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 2/3] nvmem: brcm_nvram: add .read_post_process() for MACs Date: Thu, 6 Apr 2023 13:08:03 +0200 Message-Id: <20230406110804.12024-2-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230406110804.12024-1-zajec5@gmail.com> References: <20230406110804.12024-1-zajec5@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762425970318391198?= X-GMAIL-MSGID: =?utf-8?q?1762425970318391198?= 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;