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: 13090608 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 8EA4CC3DA7A for ; Thu, 5 Jan 2023 22:21:12 +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: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:In-Reply-To:References: List-Owner; bh=9Je2TeHcCsIJUuhR2UMnfMOvCFRtajZrdWQGnJIWISw=; b=3ioabOP7pcSJEc KPHulNx0hdiMqs7gqWvxAzEntMrbAD6v0utHz6CVt9yFlJxo9/9g56NniOuSOxY+BYLcBl/fPvLkn vZ8WrftspNjw/8ewaZFpU4wSPKXUNYMrfguN/ZM/Gy2XC8gd5wz1a61xgqav2FM8klDEjoib/MdLj AHhGDQWn3z7mTgUie8JC4svrA1SkkQE6/7z23y2DNsy6wBGyYL1w7n0Niw7SqI3dI5eiRhBw9e6fH OxLf1kPZ4yl9AFDaRoIpWGvvZW1hwacStE6k6hgJoGFitnWhotWRwZbxSBoQbEJ9ZkqsWZ530qFv0 RdgNOHOCphS1ZRg7WqMA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDYal-00FWj9-RZ; Thu, 05 Jan 2023 22:20:08 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDVEW-00Dn0G-1t for linux-arm-kernel@bombadil.infradead.org; Thu, 05 Jan 2023 18:44:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type :MIME-Version:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:In-Reply-To:References; bh=0/YbCUbiIk7jw/h/JX9JQTuGXWp0ew1oCAgQXwBuda4=; b=j8ZNZw6Vh6KEi8qu6dBYKKnG6k QUgsVp0aq3aDz8ezv+EEwtfHv6WIVit+xUbjDN1cF1E7YZznsGJtY2dLHnIuRJ4lgppGNb7jktHE4 SiaRXaXsGYwm6hqeK3tjFWvfvEs/wkRk2x/2SOzNJMdV4luvjPaXX+KQXmzPTmpN3iqigdjHjwnz3 X55pDg9R5H6o/bnauGNVz4uGA+ctTa32y+2nk6nVgegiC/WfxXLlvDIIdUnVZp+5KqsGYcFtSaoT5 CF1qmCP8cNDz4T1F5eHPbZaxJJRdDAljSYpZjMo7/c6Fz2TqKwTfrggyBE182xz7rgHB0yebSdxYj RvtKh79g==; Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pDTlc-001Vnq-2J for linux-arm-kernel@lists.infradead.org; Thu, 05 Jan 2023 17:11:03 +0000 Received: by mail-ed1-x534.google.com with SMTP id z11so37822839ede.1 for ; Thu, 05 Jan 2023 09:11:05 -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=KzytypfC84hqMuu4bp1zbRbQZ7i2Qx70KT4PPZRiPBmgMdSBAHLnyX5pDMPUXRwRz/ ptU6dpFhV7XVt6nHJvZ7SEI+sJ7gCTYo+7srjGcVKET61yKgHNqRt+T5ehLDKoqPhmYh bhWczN/k8l2HadwN7UkzEvHYKFXQ6Kf3/416oLWoJx3qBxyIGiwqoZ+RjN/lu3JoMxxE SxKNvmxcTLNBEHGTTESNL/i5gBm4DAIzIamdzQD4V/PTN5XCqD1zzk2yc61sL14vtuet mQ5F8IPiDuz2oJ94op13eTv6YQw+Z94ZdbuF0Ay4fo4Eiy1r0smAqba+F2c4XuNYhxXG ATWw== X-Gm-Message-State: AFqh2kquj+2DpkZEqafLYFyLSA28HoqWGTiJL9SEGllbHDn69xs7wZUg 0+D7Zg57sCp9aZ0oDDR08hA= X-Google-Smtp-Source: AMrXdXsnbZYzuSv0TqR8hfYnHxxX2Xd5kBkoqfcQ9arljmolLSRX2rKW22FQCZ/5qyGNKYpvruiI5Q== 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230105_171100_935300_FDB6CE7B X-CRM114-Status: GOOD ( 12.39 ) 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 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: 13090610 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 125DCC3DA7A for ; Thu, 5 Jan 2023 22:24:42 +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=IuaPYWrfJ1OcE8cY1gyQbO/jAiNIi3/rizPQClECWWE=; b=ybJbrzkoUznbhu qINxabkhBE7bgAA2fRGxd0wSYA9PlKiWmT0uWTgIe9kLKQbU+VpGJzzLHHKcKQRqE/fy2bdTgTJQm r/5NREZFbFVr1+Vopg2d+aIWqopY+iSuzfRedu/daKtHz+28ubv37Q0uLONMCYoGzOmVwvkKdpvLY +TDCrVvB+ejFVzMOMoSADegIetigYzYKEiEMtRyQqTEoKrFGFHTZwKtEbvHBLK7g3vODzBdU6gTOx nYV2tONpUSa0NJ5KZ85vLvGRmYqo2D2nWRSSCCmFcDxNuVABWape/dceFJcjSIN5k9/0QDMTrOv64 Ga6DdP6fstnYZ6Dson6w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDYeD-00FYWU-Le; Thu, 05 Jan 2023 22:23:42 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDVFH-00DnQt-E5 for linux-arm-kernel@bombadil.infradead.org; Thu, 05 Jan 2023 18:45:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type :MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=7Rha6d9hLLk+vltlf40Zf83zL1DAznh3btmFm0dmpPc=; b=eQIpQx8pfOX3wyIjb/pj4qnhKP STDMtfiq8zEwjV/cOzkx895OjTCUlj7oE1FQhU/uztx4qIiK/RAhpB60E8xi11wL0mv1svu/AYhR3 dBeP4K0KkB8wDDvhh3pLN6l2STQRimf6sJSipyXnnC5VvkR0rVXF1yUclXn1nQFwzH+8vjpQw9ga9 sdiyAq0wIVf1GVOSW96z/xiefFxCLenY02YeLujSDjpvrdufKZtOVuBwoHEFTuwSsk/ZWdIV7v0G7 5XAJJ4nEG/0TxvoVEPOrXcpnz/rvPoITk2nfiZ7S27gRA9qbpqjeALnOV4ewW2E7Jf89cZmJAgkod p4/Nf/7w==; Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pDTld-001Vns-0a for linux-arm-kernel@lists.infradead.org; Thu, 05 Jan 2023 17:11:03 +0000 Received: by mail-ed1-x532.google.com with SMTP id c17so53580662edj.13 for ; 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=odE+jCXDB/d7YCPot1rzpnNiJWCAbtJduzlvTdZl2aaAGZA2hj/SrfSbE2Kg/RDu1D 96Lh2VsFSNL8mQod2cIE0KdMdQ2oknUnHMI4FKGgql/4fVlQGuseMUWWrsQWSR+GVKII GyTYQGycTh281xLdccWRou1g+o9UZ3VsLyE+J16P7GFvCcsQLkRTv4YOH15b0XiqlDnU vh09Ylqa+5SE2W3FZOW6uPONozx+kjQvVK3aGvi+ldISLlC50x3Xy4wTXmRZjloJCcf7 DCyCrto9UY8Nf9G41TkMxeEkz8t3eWanKlkNmoMNoQEG68ciwJZag4CSNkfpDF+Mxy0x MrzQ== X-Gm-Message-State: AFqh2kpGFHPIF82gvZya0EnEOZrkfBSLKcq31ayStBAOtbqOHFdN+gWk yr+suca+oq4cRw5ykWKw52g= X-Google-Smtp-Source: AMrXdXt7rrdKfh+/K7o3yJL8MQzXVPDGlQayf/5oiuaD1PKk0PY3KvshJfQSqYpsOiDPZRCovanbtw== 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230105_171101_351836_E078123C X-CRM114-Status: GOOD ( 18.87 ) 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 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: 13090501 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 72008C3DA7D for ; Thu, 5 Jan 2023 21:29:00 +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=KpAkhz6yBz9qnpSW3qqfhDnVPHVKnup3osNtatRO0+g=; b=FT0Bj9BWu6MuNM jYhTlL4ssJ/l7rxTBzF5UdySesGe6psgcCdryjx0TBw/gcwIlPpBBLGbkmj7h9J7BtAFpdDqSAdDn idSTCwXC3IIx4QB9jaoD3x8ykMPgJUdy9PZhXS4gy1upR7hGOuIcofLBVOHQb5UT+mzXuRkmzZ8+K lmjjuYa5aQjSOyVCqL89EdLrbHii8q0VQIBD2gjI5wlVsHE/RkjkfN2sPVXaWlr4KYiIHapJg3Zst fa20vXW9PDZLJbiXrFeWt5LXNowE1WXfO43V3JJIzD1O092Ew2ceAoNaHAVcfDcPQK9XP9p58xnse yApTaQojJOsIZry/eNSw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDXmH-00F644-FC; Thu, 05 Jan 2023 21:27:58 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDUwU-00DZ8S-4E for linux-arm-kernel@bombadil.infradead.org; Thu, 05 Jan 2023 18:26:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type :MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=MaNtjFyAXugDAWX/bR32Dva5wigb85ST8Ayk+tDoGms=; b=luqMevrqbJ51UsqzjFcTLZajOZ X2qgxCNPunM7hvx7cfihs+/f728+lUapyk59N0vyVpWTBM6TfH1T4aK8SAAsTYNDM7HpgbejEgeDg px87JYglfNz8xMOiq3+Cdd/YX2XtUdcmuhF342oPBqHD9K0OeXSTZXzf1lG8jGWfCBZzt4VcPvAEo IuKBzbRdAxEWdTLrYw39bmk0/usulykm9Y1Ky+2hEVzyrsN0ZvH07acMR9OR+Uu34ShBSHhkUQZmj Bu9V8jXRl6ulySr3ba22VgVAhd3RUxqa/LDCacGG70KdogyTRwGAmAFL6/ekRcj6Uv4Ehe7aatjFA 7ki85elg==; Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pDTlf-001VoL-03 for linux-arm-kernel@lists.infradead.org; Thu, 05 Jan 2023 17:11:05 +0000 Received: by mail-ed1-x52a.google.com with SMTP id v30so2305371edb.9 for ; 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=eWBPO4sikrdMfPQnPJMFS2goSplLcjVXrfRKOq5Q2xGjIuuwjgzWKRNeDXUyARcwxK qs3EkLBmq2W0fiY4pHM2vqczF0RWIb5tO327LTJj3uZCkZ4R8EhgT1CbNn5QHRn/VhxZ attYbvQ0ldeUb1OakVtCM5h8qaFJKawv++I0UCh6x4esDgae/PvnpYmfJwtyoxrL6uKK nEz2N5U6n40TyTyFpHtPmt86ZPWjla7eWAZGwGeJ0DxQ3/zc9r6bbDV7bt2RZXuSrhZo Y9WSD6aBgfgCPmm7XXPuWjWDoJYVTSUzzPrgxsk3xnMpyq9M9OWVfPMb2FiAj+hnZfLq d/yA== X-Gm-Message-State: AFqh2koqHgh9mECwFX55CwleBK9fVqaXM2KT+FZHocSGM0nqP0v4qPno 6dtYln0FO1rhtGE8QsxleEY= X-Google-Smtp-Source: AMrXdXv5zDOsStIlsnwT9M02nEHELn4C8qBhZMwS49BaMy0TTTD9iNc3SDUbaUdl9yMz/XOGOycK+w== 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230105_171103_368728_07B916B2 X-CRM114-Status: GOOD ( 13.57 ) 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 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))