From patchwork Thu Jan 5 17:10:36 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: 39718 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp411401wrt; Thu, 5 Jan 2023 09:26:20 -0800 (PST) X-Google-Smtp-Source: AMrXdXsjSlWjmq6V5b9fXomrowUQEJ0tq1IAACgTMx7fhdkeLzN5VENjwnzozv3VL2wyHSPDOO+L X-Received: by 2002:aa7:c398:0:b0:47f:14a6:a24b with SMTP id k24-20020aa7c398000000b0047f14a6a24bmr43491353edq.21.1672939580803; Thu, 05 Jan 2023 09:26:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672939580; cv=none; d=google.com; s=arc-20160816; b=tazgO2UutfGlZGOlM1RhPkT0ehJMGP+KmwekUH5TuiNZkb3C2zgoWRE/KOssN0bYEs KTdrrWuIZKM34CjzsqfftYMyAlebsfBkeI9PjFsfNc1VtDgCZBx9HrLOuaNCKuK12tpO Isk7T1bhmpYqx5j/hGxm2X5JOe9qq+TWKCrkzwzpy6Amcaj9/DBTf5czs5II1V6EuZaH b2c3yV82JChRHjrQrjQUeZOclyGFY4UnKlFWWy1EmfyivYr3/gCQNO5KDY8Kb4Ay6Kmn cf1Iu+UJLXnvf4XWgoFAPPxfKlb6+4WUG95vqK2Ya05L+jGedLs7IBTMJR7ezGpBs/B4 H14Q== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=0/YbCUbiIk7jw/h/JX9JQTuGXWp0ew1oCAgQXwBuda4=; b=zfwp3cjXvcqzSf2rYIyNIu4umQzhy2rmpCPC242tOq7ycjo9waQ8CvkD4USDjlVK8F deQDnmlOzrBus1/EfGCs+XYZGR7Aaq/c2NODiSqprlGVrkzum1upbOxQGaXPcBezjWza sRJLHxvmYTjSsrXz7p1j8k0uzAJRukg4psxYyFPywyXW4vPv05XPr0uYb+bT+8GMX7TE +oggCfbzQxXEVuketwV7eUbr3HGJQbBEe83619sRncThDiLqmaYDoPuSwtR73oXsc9QF QG/iImfDc1/EDGQtmFjXFcHtI8JAKc7GeI/9pFeoK8gMBkY1FnL25ctj/PZ+nM27zG8b IcGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=IojnGYDP; 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 da9-20020a056402176900b00482efc40d58si27583353edb.400.2023.01.05.09.25.57; Thu, 05 Jan 2023 09:26:20 -0800 (PST) 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=IojnGYDP; 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 S234740AbjAERTW (ORCPT + 99 others); Thu, 5 Jan 2023 12:19:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235080AbjAERSQ (ORCPT ); Thu, 5 Jan 2023 12:18:16 -0500 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 595C9F5E; Thu, 5 Jan 2023 09:11:03 -0800 (PST) Received: by mail-ed1-x52a.google.com with SMTP id b88so46369343edf.6; Thu, 05 Jan 2023 09:11:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=0/YbCUbiIk7jw/h/JX9JQTuGXWp0ew1oCAgQXwBuda4=; b=IojnGYDPn9/9kUDImAM4/qPxH1tqs8AraceRSrGaPrIA4K0BRlCAPDmiBwZEg9QXQT jG8NZZpy9XBTTB43h/Qh4IRnJJWSC1XKZFUXqJrg3vMkW8c92mN+vnhLuFR1nQ1BIhpo C1pjPh0QmKFQRehd6MyFU3oCS9Fq17hTATXQEUmkS7Id1y7ILI2vLVlRmx+Tt8fd6CW1 lL3h034rSuNYg3bQyHofC94WE0CP3oQ9Z8ft8R+bp1ZoV9tgvJFCzrPN8TW6uAe2mAXV dlaDaK8cFh/IDl0oDiS8AI1iqgB5m/AwFXYw0MOCg9nqHal+h1VGqkNHDhR6+wFf9Ezi Wm5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0/YbCUbiIk7jw/h/JX9JQTuGXWp0ew1oCAgQXwBuda4=; b=JVOgqsTBdzD5tT3BhIalR6q5ptyDwgl8g0ZWqvyik6ty5yUdy3sOsyoUHbxqjFJAIs KN1Bb+MuYoWGTaJG6tzqhZfa3qbEGa+Ehc9Dks6qu4ATPetJ+3AZFTjz2jw/3j4qRxjq rpEgPWai9EExOVsFNwsfnvMci6Q8qZG/ql5OCVWM50Ps+J8dDZ4CXABpO8DPdcbFPLpW YJ6CDq5HgroOR7aACzkcWCbJX/vzxKyuO9l7lH7rO0Bwv/x93c+/lnqwG1Fl/vc+wrYt Q+35WfseelWvJ40gkLCjhqm4HwzM+VWaYVOnB38unJfajZi6i044FfhBLGlDNDaYjVAU qOyQ== X-Gm-Message-State: AFqh2koyRwgyXHUF+HfVQoaXBLbnh+PEV/mQouyf1TbZ0L4C3qemVrqx EIwwAm5Jwai4YrqByunx8WI= X-Received: by 2002:a05:6402:3909:b0:492:846d:e86d with SMTP id fe9-20020a056402390900b00492846de86dmr2651833edb.23.1672938661792; Thu, 05 Jan 2023 09:11:01 -0800 (PST) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id cn9-20020a0564020ca900b0048fdf37c441sm1714829edb.3.2023.01.05.09.11.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 09:11:01 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Srinivas Kandagatla , Rob Herring , Krzysztof Kozlowski Cc: Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Miquel Raynal , Michael Walle , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, u-boot@lists.denx.de, =?utf-8?b?UmFmYcWCIE1p?= =?utf-8?b?xYJlY2tp?= Subject: [PATCH 1/3] dt-bindings: nvmem: u-boot,env: add MAC's #nvmem-cell-cells Date: Thu, 5 Jan 2023 18:10:36 +0100 Message-Id: <20230105171038.13649-1-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,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=ham 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?1754204293995311233?= X-GMAIL-MSGID: =?utf-8?q?1754204293995311233?= From: Rafał Miłecki U-Boot's "ethaddr" environment variable is very often used to store *base* MAC address. It's used as a base for calculating addresses for multiple interfaces. It's done by adding proper values. Actual offsets are picked by manufacturers and vary across devices. Signed-off-by: Rafał Miłecki --- Documentation/devicetree/bindings/nvmem/u-boot,env.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/nvmem/u-boot,env.yaml b/Documentation/devicetree/bindings/nvmem/u-boot,env.yaml index cbc5c69fd405..1c139bd689ea 100644 --- a/Documentation/devicetree/bindings/nvmem/u-boot,env.yaml +++ b/Documentation/devicetree/bindings/nvmem/u-boot,env.yaml @@ -50,7 +50,11 @@ properties: ethaddr: type: object - description: Ethernet interface's MAC address + description: + Ethernet interfaces base MAC address. The first argument is an offset. + properties: + "#nvmem-cell-cells": + const: 1 additionalProperties: false @@ -72,6 +76,7 @@ examples: reg = <0x40000 0x10000>; mac: ethaddr { + #nvmem-cell-cells = <1>; }; }; }; From patchwork Thu Jan 5 17:10:37 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: 39716 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp411398wrt; Thu, 5 Jan 2023 09:26:20 -0800 (PST) X-Google-Smtp-Source: AMrXdXsI4oey2dLilz2429VH+o3V6+tVzXzTUBpiKFWTCat0nyVbaQ+X1IpijH+w5RjyuipZSVDD X-Received: by 2002:a17:907:8b12:b0:78d:f457:1062 with SMTP id sz18-20020a1709078b1200b0078df4571062mr44955368ejc.31.1672939580548; Thu, 05 Jan 2023 09:26:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672939580; cv=none; d=google.com; s=arc-20160816; b=iB5bePXFc5fiifp1NQzOLnvSlXa6hXVGR3RIDFb3z8aUgCZTEjyWp63wriNVdDgE0H k1xCdLjpMC+TbfXqBfJxakQNVYGMA2kwACizxiPdRrUMqWqJowpqBFv8ccho3BohX6or GXs/9WgVgDfxrgYIV3tY24F4mfMzNa6DwtSRXXuiG7dccKyugfjaLsbOyB6fKCAla1e6 NNbVMSMYG1IneKo+lzsNy1JkIFbn/qbRn/f9EHlXji/Po3dCiG+DlqF/gOLWaERX1owh nXsUv5ma481Hwjmw5sfdpywpHwowCLbrz4fKRRygWmQXhkPvuCUGxu7Y7b2NT0u+Fu6i uglQ== 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=7Rha6d9hLLk+vltlf40Zf83zL1DAznh3btmFm0dmpPc=; b=i/VGjUKXGnKXunAikp9rwiaQKKa9rgZnQdPDXoh9fJM7TKLrR2NAvVSg3b2cNMzpB7 EDIn60Cg6BrTusrFuwp0Py3H4mGPlTKkmjJDp/E7HYhDBdRlt6aDeGZCHJ4cYK89p01+ kFb4xcDk2DndOUAsH6PK9JlDbPUH6CMXN5Ja1d3iaE7SJvPoPjYC+Vmdb8biqmrMPa09 9oIHMH5wkWLb+7O/18HsgC22gErJcZxEOe1+fEHZsjoZg4eeWy2c0YBgc3m2E/0+wDg8 Hzzqrq5AeXKxb83ljq7+/iXqjHrOf3K6YAEElBby640sFDNjhWbU3IQHXVRsqlwioIyB Ox4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OPcdb4OP; 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 cs19-20020a170906dc9300b007c4f76c4e81si34711687ejc.319.2023.01.05.09.25.57; Thu, 05 Jan 2023 09:26:20 -0800 (PST) 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=OPcdb4OP; 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 S235080AbjAERT0 (ORCPT + 99 others); Thu, 5 Jan 2023 12:19:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234793AbjAERSR (ORCPT ); Thu, 5 Jan 2023 12:18:17 -0500 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C687E5C1E4; Thu, 5 Jan 2023 09:11:06 -0800 (PST) Received: by mail-ed1-x52e.google.com with SMTP id g1so39418512edj.8; Thu, 05 Jan 2023 09:11:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=7Rha6d9hLLk+vltlf40Zf83zL1DAznh3btmFm0dmpPc=; b=OPcdb4OPK2QbdDbj7B8kKYxmQ0+r6GZLYmG8jBXT93j75CoBCwssxZc1nZJwLH12tC mXC7QfbDKU6uBBoVE5DNquE+gInwQ0sxfALkM1oRm9vWj+HDxLpIfz2bTWV3c8bLtl50 7lzf5tilIguW8pqZnJD9y3l90pduLM9+Z1q7hubWHj6sqnHTem/z7EX/Muv3VKvRgdFD 4HTHDnjYkU2Rev1hxp/xL92Hb0zahH6B/qJIp5tE1CoN+5gss2JU/hgJsqaoxllEiZNk NYgi+tHNr7RMDVWLwtfP+/EFE4c0OBBYQ8ibOpUEvSuU6hd/cHS8i8CPYImu+/HgVOwJ Onpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=7Rha6d9hLLk+vltlf40Zf83zL1DAznh3btmFm0dmpPc=; b=AJ6IKpL22C5BOaXYrlnihEVnpOnakXW+MPyE4xncnt78a5SW05w0ZII1Z1eBaAreio 3ZNQdYmp1m4MvUehPmtO3znvjef4JKPeoK/bOSQ+dlhqY6VenKKHn/a5L1R58bWi6XXW bKmz6JJ0ZZu5EPk/+0HywXvLkJI42MSjX//P7/OcAZ5Q0XCtEMj5LsPq3toK5vN0Hq4l fQdp4JUWcwIICYtPb+06CND4Mu7AvXw7US4XCa4YmYGDc8hXlqQeNHOsqH0UeX1DBLaK mK1bblhRumBjJIdefrXfgEdh9+rh6OGuvzhIgM5jsEZPKv1ut+TmgCTzYZswOXlZjhzR uPBw== X-Gm-Message-State: AFqh2kqI0+sT1NfomftCRTLtQ6Di9OZRddJ+5q0k4ARTjSXJkGyl96Lp n+4pVOcVxn0KjVuKoV1c/O4= X-Received: by 2002:a05:6402:1654:b0:474:a583:2e25 with SMTP id s20-20020a056402165400b00474a5832e25mr46531093edx.5.1672938665304; Thu, 05 Jan 2023 09:11:05 -0800 (PST) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id cn9-20020a0564020ca900b0048fdf37c441sm1714829edb.3.2023.01.05.09.11.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 09:11:04 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Srinivas Kandagatla , Rob Herring , Krzysztof Kozlowski Cc: Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Miquel Raynal , Michael Walle , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, u-boot@lists.denx.de, =?utf-8?b?UmFmYcWCIE1p?= =?utf-8?b?xYJlY2tp?= Subject: [PATCH 2/3] nvmem: core: allow .read_post_process() callbacks to adjust data length Date: Thu, 5 Jan 2023 18:10:37 +0100 Message-Id: <20230105171038.13649-2-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230105171038.13649-1-zajec5@gmail.com> References: <20230105171038.13649-1-zajec5@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,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=ham 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?1754204293889960629?= X-GMAIL-MSGID: =?utf-8?q?1754204293889960629?= From: Rafał Miłecki Sometimes reading NVMEM cell value involves some data reformatting. It requires passing updated size value to the caller. Support that. It's required e.g. to provide properly formatted MAC address in case it's stored in a non-binary format (e.g. using ASCII). Signed-off-by: Rafał Miłecki --- drivers/nvmem/core.c | 5 +++-- drivers/nvmem/imx-ocotp.c | 6 +++--- drivers/nvmem/layouts/onie-tlv.c | 2 +- drivers/nvmem/layouts/sl28vpd.c | 4 ++-- include/linux/nvmem-provider.h | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 1b61c8bf0de4..1daf5a1d3ec7 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -1537,6 +1537,7 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem, struct nvmem_cell_entry *cell, void *buf, size_t *len, const char *id, int index) { + size_t bytes = cell->bytes; int rc; rc = nvmem_reg_read(nvmem, cell->offset, buf, cell->bytes); @@ -1550,13 +1551,13 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem, if (cell->read_post_process) { rc = cell->read_post_process(cell->priv, id, index, - cell->offset, buf, cell->bytes); + cell->offset, buf, &bytes); if (rc) return rc; } if (len) - *len = cell->bytes; + *len = bytes; return 0; } diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index ac0edb6398f1..ebd0e9e0314e 100644 --- a/drivers/nvmem/imx-ocotp.c +++ b/drivers/nvmem/imx-ocotp.c @@ -223,15 +223,15 @@ static int imx_ocotp_read(void *context, unsigned int offset, } static int imx_ocotp_cell_pp(void *context, const char *id, int index, - unsigned int offset, void *data, size_t bytes) + unsigned int offset, void *data, size_t *bytes) { u8 *buf = data; int i; /* Deal with some post processing of nvmem cell data */ if (id && !strcmp(id, "mac-address")) - for (i = 0; i < bytes / 2; i++) - swap(buf[i], buf[bytes - i - 1]); + for (i = 0; i < *bytes / 2; i++) + swap(buf[i], buf[*bytes - i - 1]); return 0; } diff --git a/drivers/nvmem/layouts/onie-tlv.c b/drivers/nvmem/layouts/onie-tlv.c index 074c7c700845..2cb7112229ba 100644 --- a/drivers/nvmem/layouts/onie-tlv.c +++ b/drivers/nvmem/layouts/onie-tlv.c @@ -76,7 +76,7 @@ static const char *onie_tlv_cell_name(u8 type) static int onie_tlv_mac_read_cb(void *priv, const char *id, int index, unsigned int offset, void *buf, - size_t bytes) + size_t *bytes) { eth_addr_add(buf, index); diff --git a/drivers/nvmem/layouts/sl28vpd.c b/drivers/nvmem/layouts/sl28vpd.c index a36800f201a3..63c0da58ad60 100644 --- a/drivers/nvmem/layouts/sl28vpd.c +++ b/drivers/nvmem/layouts/sl28vpd.c @@ -23,9 +23,9 @@ struct sl28vpd_v1 { static int sl28vpd_mac_address_pp(void *priv, const char *id, int index, unsigned int offset, void *buf, - size_t bytes) + size_t *bytes) { - if (bytes != ETH_ALEN) + if (*bytes != ETH_ALEN) return -EINVAL; if (index < 0) diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 0cf9f9490514..5d896eec2f1c 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -21,7 +21,7 @@ typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset, /* used for vendor specific post processing of cell data */ typedef int (*nvmem_cell_post_process_t)(void *priv, const char *id, int index, unsigned int offset, void *buf, - size_t bytes); + size_t *bytes); enum nvmem_type { NVMEM_TYPE_UNKNOWN = 0, From patchwork Thu Jan 5 17:10:38 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: 39717 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp411399wrt; Thu, 5 Jan 2023 09:26:20 -0800 (PST) X-Google-Smtp-Source: AMrXdXtBty3IQrCVbscq2nV1Wk6LAiQ4kpclTTmKGYZhTeWeW3P89fDP7ItQs2b0dq8I2KFNhO90 X-Received: by 2002:a05:6402:528d:b0:48e:f679:e733 with SMTP id en13-20020a056402528d00b0048ef679e733mr6762171edb.36.1672939580563; Thu, 05 Jan 2023 09:26:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672939580; cv=none; d=google.com; s=arc-20160816; b=pIUsZDFWBBxWbeHy5oowpUrjUxTckEt5+wcutJQscak8So+aicwEKRXXCEk8k4+2sC if1puiZwHdOK31xbE2qLBF3r3AjJ0otup3J4uh89ovEwQMIXJGeb79P6jY0kzxxwIX6n c+FyEYqhtxVCQGc552/MFuE78tz65gBl3lprrQvin6Q5W6SXVI85z9I2TgJ2UVHa1KQh M7z9AToup1ZSk7DC1W92XNIApo4ambNx3Q13Dz3agwD9CxEGzsP4HXV/aS9a4ie0D4av PdMQl0im84c9ey6jdYnZRkSmnvfU3wrpUxvzFVjObluBcFlZjDG1trCsncqVUbR7AMOB Gedw== 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=MaNtjFyAXugDAWX/bR32Dva5wigb85ST8Ayk+tDoGms=; b=m1zkNCi44eDwATqy1cyK94ih6ocR7AnYM9RPnYqVnb+5OxZ5FdxlZFDZm8hgqKEvDS wnhu9IJGV9bXyNOs/DjTmpKBHPEZCibj30YEUaTacdDUoiwNitDw7bIh1PGi8Ma89DAv uUi1ZEUBRor5Usr7oR9kOshnmIUqqn38SNEdLfaB5c/Ulb2g87VaIOEChuAgjSysF520 xt62GHn7FSdSpNGa808i25BiK3AzEI6oL/qL5+TRBNJ/Iqw+oyHAnJ9Kb2xyfvu9mvqd TG3XK/irORt4yH0LGy05meKj9IOKTcG6tKddjIYDOvhJtxFl/9kbtv40eVl1APhsXW8h TPuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="Jc/IGmb5"; 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 k6-20020aa7c386000000b0048a48f92a6csi16995446edq.439.2023.01.05.09.25.57; Thu, 05 Jan 2023 09:26:20 -0800 (PST) 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="Jc/IGmb5"; 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 S233840AbjAERTd (ORCPT + 99 others); Thu, 5 Jan 2023 12:19:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234158AbjAERSR (ORCPT ); Thu, 5 Jan 2023 12:18:17 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD6F35C90D; Thu, 5 Jan 2023 09:11:08 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id i9so53629905edj.4; Thu, 05 Jan 2023 09:11:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=MaNtjFyAXugDAWX/bR32Dva5wigb85ST8Ayk+tDoGms=; b=Jc/IGmb5ZhCXE5QR+3vxXRLGLCxIDNy2+fy0f2wmt8y0c9AMwje0Uo+hYkNeWMSZMR DxiFw3QRh2bqGnGySwQK2GRJHcvJ6kcg4eJzLbRmcpyP5WSiY71zRV8A8aRv9fUN1hZu gdhDQKZSNSoa05nkLCVrvZLUoxG+0Gf/Y48w/QhMqbA09GTpYUUhki0MN/CRE6vNYTMR /ykxnHm9vtwZqAzTTuFU1kAmAHysvdf97xqQdGDZXWBTYF4mz8BKIQVrX3dnc1G73RC/ zLdR2FQK3JxOZo74xaVXkzq91PzMowGeYVWhuSJqlrvTRYRnSctpYjxogelIlyCXbXpa NaiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=MaNtjFyAXugDAWX/bR32Dva5wigb85ST8Ayk+tDoGms=; b=CThrm4Qg6CCq18ID+lqb0AFwnT55HWmOox+roUc0ipEsPtS7GtCOGBA7cpTrnfznTC EHFGvhdBI5waPon+DJVWlESWJeu94sJWPfAiPUtuggvYWXogNidEEGKGIjKb1foqnQoR BculdsgiJ8XMXa8cZvH3M5RkSJTge4qwi6Do7DemV2rydEj7XBgCSGQw2kpV/qKf0Nt4 ibXcnWqXdR0LNwO8dD6JVHpMsZtqxCnIN0mEIC7zsJoY79qvAyVDChmV2+O5M6A4xogW Cc9Zw9X+sgvXqQ8w3LeINS2gUJJRhl05MaNYJ/dw4FbcGawNXuMKrExK4v6EeCC64ytZ N1SQ== X-Gm-Message-State: AFqh2ko8hJISE/BlPW7u/+wF9dUKMVaSlnv9K4YqaGC4pXsMwKgzvDtK lS2+kcuMa3iD9M2Jk+M26vc= X-Received: by 2002:a05:6402:2072:b0:487:6d4a:444c with SMTP id bd18-20020a056402207200b004876d4a444cmr26202520edb.28.1672938667401; Thu, 05 Jan 2023 09:11:07 -0800 (PST) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id cn9-20020a0564020ca900b0048fdf37c441sm1714829edb.3.2023.01.05.09.11.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 09:11:06 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Srinivas Kandagatla , Rob Herring , Krzysztof Kozlowski Cc: Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Miquel Raynal , Michael Walle , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, u-boot@lists.denx.de, =?utf-8?b?UmFmYcWCIE1p?= =?utf-8?b?xYJlY2tp?= Subject: [PATCH 3/3] nvmem: u-boot-env: post process "ethaddr" env variable Date: Thu, 5 Jan 2023 18:10:38 +0100 Message-Id: <20230105171038.13649-3-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230105171038.13649-1-zajec5@gmail.com> References: <20230105171038.13649-1-zajec5@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,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=ham 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?1754204293797126011?= X-GMAIL-MSGID: =?utf-8?q?1754204293797126011?= From: Rafał Miłecki U-Boot environment variables are stored in ASCII format so "ethaddr" requires parsing into binary to make it work with Ethernet interfaces. This includes support for indexes to support #nvmem-cell-cells = <1>. Signed-off-by: Rafał Miłecki --- drivers/nvmem/u-boot-env.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/nvmem/u-boot-env.c b/drivers/nvmem/u-boot-env.c index 2a87dda45188..54283f8061b0 100644 --- a/drivers/nvmem/u-boot-env.c +++ b/drivers/nvmem/u-boot-env.c @@ -4,6 +4,8 @@ */ #include +#include +#include #include #include #include @@ -70,6 +72,26 @@ static int u_boot_env_read(void *context, unsigned int offset, void *val, return 0; } +static int u_boot_env_read_post_process_ethaddr(void *context, const char *id, int index, + unsigned int offset, void *data, size_t *bytes) +{ + u8 mac[ETH_ALEN]; + + if (*bytes != 3 * ETH_ALEN - 1) + return -EINVAL; + + if (!mac_pton(data, mac)) + return -EINVAL; + + if (index) + eth_addr_add(mac, index); + + ether_addr_copy(data, mac); + *bytes = ETH_ALEN; + + return 0; +} + static int u_boot_env_add_cells(struct u_boot_env *priv, uint8_t *buf, size_t data_offset, size_t data_len) { @@ -101,6 +123,8 @@ static int u_boot_env_add_cells(struct u_boot_env *priv, uint8_t *buf, priv->cells[idx].offset = data_offset + value - 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, "ethaddr")) + priv->cells[idx].read_post_process = u_boot_env_read_post_process_ethaddr; } if (WARN_ON(idx != priv->ncells))