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: 13203169 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 DEC73C7618D for ; Thu, 6 Apr 2023 11:09:55 +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=LyLu2e15cyml2H hNPLrNSogfNvO5qqFJnglbkLUITEII4w+QCFKRcZM2/C/5/7vbVlPaa0pEmehkpl2DFenwKFveLcZ 9XT6+o5rvTusvQ1FaRSBqlGvHzjuafoA342KZIr7WRrKP9pcTOcbnxsIrlGZu3BEUlwr0ey+a8NJP 7llS8gcpOosj+g+1+2Y0UqJ+rGefFPrvVPwP1SDWXHdWW7DvwBi2rY4KQq598J4Lzzdb0SO+xb/u/ fFpwFBVmk9TRixD/D8OVHI3ldcvrIajz/3YDdbnbIrfgoKKpos/O4bNLTU6wPbU0F1g73YmhqTSNI bNBYGhZArgOImAs5DRxA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pkNUH-0077V9-0C; Thu, 06 Apr 2023 11:09:05 +0000 Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pkNUC-0077Sa-0d for linux-arm-kernel@lists.infradead.org; Thu, 06 Apr 2023 11:09:01 +0000 Received: by mail-lf1-x131.google.com with SMTP id h25so50329213lfv.6 for ; 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=lDwHb/ig9bNc/y31cVXI/GKrNWVWw7ENUzTMyFpypciPPy18xx6lz5M3X1tcDd1gMJ jIM9PhMjN3FCp1pTQeCnEbGQ/em6s7nvfFVE5f/ohjmmzxt1ZI/BhP0A+SJ8ynOGMqIt JYyCq6kOLX4of6g/ZSwT98v216bsCc45WdBdk71etyGVlWKl3hewmyJNvYE4TMW7PKG7 lV7R6ipI6mTZBB2ssQ/oCApdBuatHmEcau8B22iDTbj8xPzO9s5Vf85qiBOlHfxRa8ZI RM556UywXQCgpvuAUpwy1/zkLxKBBK12f0J9swihPTSppQ3BoWBg1tCnD5L0m9Fepura K3+Q== X-Gm-Message-State: AAQBX9cqZf/QONMpZ83Z7iGLB2KEzUUmFOkz/T5r/VFru6HF2GRbhNcZ ffj18Zqy1X+JPhUlL6vhkrQ= X-Google-Smtp-Source: AKy350bEbAhBNNx9rxCddQ6y4IbOjg+2Hy5K6Gk/hqrMHBDrixOMNKnmkaniICT90Ogxfil+NedGuA== 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230406_040900_233219_A4A588D4 X-CRM114-Status: GOOD ( 15.19 ) 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;