From patchwork Wed Feb 22 17:22:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 60622 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp704279wrd; Wed, 22 Feb 2023 09:28:02 -0800 (PST) X-Google-Smtp-Source: AK7set+GEpj6n02S1UG/utCrEC9fzGaxPWvPrGp96d6rnPi4IQDmgF4yuQsaAeDmTc49yhx656q9 X-Received: by 2002:a17:906:f0c9:b0:8b1:3467:d71b with SMTP id dk9-20020a170906f0c900b008b13467d71bmr15730123ejb.48.1677086882134; Wed, 22 Feb 2023 09:28:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677086882; cv=none; d=google.com; s=arc-20160816; b=noiwuSZcnvaha+ygJ3K9ccdFFPCYzuBMSUWwlvqyRX6bdawbsBPRbmEvb703vnF7Vi rM1wy3yGtsCzBK+12fGN202U2AjUtspi2zgZDpfCLcjaussHcpiDartUy8bnMFW0gw2O gDNKd2R2AzWldwJjFkK0NZstQmZiX8K8cSJhrOboA3rVv9Q7LTVNIxjOpj6LJnmjFHBu nfWTnwgovp0EE2tjRbZJ6DliHwjNYu2qppcQ4Dmp/wmEOjf1hQj7SbXYFeGwW+flH+dC HjG/RamBpeRSD6d2JTVkZ4DfKrFNdaAuCUmO6dR1PNXEwawcoAnrkttJPNYZiscsIiUq dAiw== 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=n3duNGI0HfLu2PQ/Hpn1IXizpNMVGcpGhUax+XUrkwo=; b=Hl9KE0tMQJjKBeibCZ7oeEfjWe6NHA/CvWimPfcUBUwLIx3Da1NBVfTLNuyX3IOEGY OCburmged6O1B+k736vxPWHfExSG/NdbO46eLdUnmLdR28+WvBlYC1mqhU/sov2aXGid Xbzdm1O8rYxNZcDEP85FUtQQlDvvddpU8E94GMJNWHKquwFBHT5rFRj5bFi89zL/NsP6 BTo+RysQbg3T/RL5/U8HL1VtfK2UPUYGLO353kzajQg/Ehz1sRuPuU0iQl8ROPmjwGIQ MNy/383Xz7wEyZmFmRnuy5HvdLpFIAOqeISbmiHGn44uxCuw/t07WigvyumCR5iJDl5J Nj5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Qw2n8KB0; 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 eq4-20020a170907290400b008dc76bf3a69si5993202ejc.735.2023.02.22.09.27.39; Wed, 22 Feb 2023 09:28:02 -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=Qw2n8KB0; 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 S232718AbjBVRX2 (ORCPT + 99 others); Wed, 22 Feb 2023 12:23:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232635AbjBVRXS (ORCPT ); Wed, 22 Feb 2023 12:23:18 -0500 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5886093D4; Wed, 22 Feb 2023 09:23:17 -0800 (PST) Received: by mail-lj1-x22b.google.com with SMTP id y14so1477324ljq.4; Wed, 22 Feb 2023 09:23:17 -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=n3duNGI0HfLu2PQ/Hpn1IXizpNMVGcpGhUax+XUrkwo=; b=Qw2n8KB0aHET9DR0jdhZl6RxgAHDB/IFzEnlmka1iyJ+lBiFBGMzav4Wl5mEAX8NIu UQ5xSppwLtUR2UzSE/DmYGcX34P6FbWPz6IHe7hwRUllahOaNT8/mwk3QEhEfqloTKv+ tHFO0YztbXODEUPXySlJtGt5VAhR6JJmH3E7YfCqmRf/CsukcrBwnsLJxjAo9PI/lQP5 CQEQSh7/FVsKFR3vW/GiZwswpGADkDKDnVlQLTIMCjcTRKRf8pitHw8ErIcBp4O2ZW+z jTjtQGJkYhLWwyMGQrSn/G+x7UKhKtzU0QHnbI1MEBixoBaBICkXzJcL90KJWIGLc2te tUSg== 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=n3duNGI0HfLu2PQ/Hpn1IXizpNMVGcpGhUax+XUrkwo=; b=AWIgeozVkLvq0nwbRZI2SKay5izKHaku0yfN+pH9N6Ms6vQ8weYG9D+chVqtkWfORo hjHR/Pocsi57V0205nfEjajoW08QlAp4Q8iMjSSijIZElW4h5vx67JbtDe20WD6k4OGc 5IlQgPl5eBtF3HCAlOsc2VzA+gk5WTdAg/gy/ZkQTVPcheMjklaLSLd2nYYvZdRPNT05 b/wZQvtuUzFfVhZMynC5yD0j6Eq47infhFgvUZ2ZCJOqlhJXNbJtUBTLCRtkUMm+IE7h 6lznHZsf5pPWJqG8gPXQBBTBbvodMl0u0RLJFYV03iZgh4ZDi736mSxQJnRDaDKcNzcP 1HsQ== X-Gm-Message-State: AO0yUKVzbLtQXILEPehWZ+h9HrTfAlTwBnvBnQnSGPReUYjVJx1Ntm56 sERF8sqgHDWER0XceJU9tdU= X-Received: by 2002:a2e:b5ab:0:b0:294:7028:c672 with SMTP id f11-20020a2eb5ab000000b002947028c672mr3147761ljn.44.1677086595638; Wed, 22 Feb 2023 09:23:15 -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 p2-20020a2e93c2000000b0029477417d80sm721513ljh.85.2023.02.22.09.23.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 09:23:15 -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 , gregkh@linuxfoundation.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, u-boot@lists.denx.de Subject: [PATCH 1/4] nvmem: core: add per-cell post processing Date: Wed, 22 Feb 2023 18:22:42 +0100 Message-Id: <20230222172245.6313-2-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230222172245.6313-1-zajec5@gmail.com> References: <20230222172245.6313-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?1758553054536327017?= X-GMAIL-MSGID: =?utf-8?q?1758553054536327017?= From: Michael Walle Instead of relying on the name the consumer is using for the cell, like it is done for the nvmem .cell_post_process configuration parameter, provide a per-cell post processing hook. This can then be populated by the NVMEM provider (or the NVMEM layout) when adding the cell. Signed-off-by: Michael Walle Signed-off-by: Srinivas Kandagatla --- drivers/nvmem/core.c | 17 +++++++++++++++++ include/linux/nvmem-provider.h | 3 +++ 2 files changed, 20 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 6783cd8478d7..c5c9a4654241 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -52,6 +52,7 @@ struct nvmem_cell_entry { int bytes; int bit_offset; int nbits; + nvmem_cell_post_process_t read_post_process; struct device_node *np; struct nvmem_device *nvmem; struct list_head node; @@ -465,6 +466,7 @@ static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem, cell->offset = info->offset; cell->bytes = info->bytes; cell->name = info->name; + cell->read_post_process = info->read_post_process; cell->bit_offset = info->bit_offset; cell->nbits = info->nbits; @@ -1429,6 +1431,13 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem, if (cell->bit_offset || cell->nbits) nvmem_shift_read_buffer_in_place(cell, buf); + if (cell->read_post_process) { + rc = cell->read_post_process(nvmem->priv, id, index, + cell->offset, buf, cell->bytes); + if (rc) + return rc; + } + if (nvmem->cell_post_process) { rc = nvmem->cell_post_process(nvmem->priv, id, index, cell->offset, buf, cell->bytes); @@ -1537,6 +1546,14 @@ static int __nvmem_cell_entry_write(struct nvmem_cell_entry *cell, void *buf, si (cell->bit_offset == 0 && len != cell->bytes)) return -EINVAL; + /* + * Any cells which have a read_post_process hook are read-only because + * we cannot reverse the operation and it might affect other cells, + * too. + */ + if (cell->read_post_process) + return -EINVAL; + if (cell->bit_offset || cell->nbits) { buf = nvmem_cell_prepare_write_buffer(cell, buf, len); if (IS_ERR(buf)) diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index b3c14ce87a65..f87fd64eee8f 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -54,6 +54,8 @@ struct nvmem_keepout { * @bit_offset: Bit offset if cell is smaller than a byte. * @nbits: Number of bits. * @np: Optional device_node pointer. + * @read_post_process: Callback for optional post processing of cell data + * on reads. */ struct nvmem_cell_info { const char *name; @@ -62,6 +64,7 @@ struct nvmem_cell_info { unsigned int bit_offset; unsigned int nbits; struct device_node *np; + nvmem_cell_post_process_t read_post_process; }; /** From patchwork Wed Feb 22 17:22:43 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: 60625 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp705118wrd; Wed, 22 Feb 2023 09:29:26 -0800 (PST) X-Google-Smtp-Source: AK7set9wMz/ldS6yQ++CvEV75/N/hSL/5NCC1D4lE9l5cULM9bLrEcwmqjsw9iB98Gfo/R1zS376 X-Received: by 2002:aa7:c146:0:b0:4af:6227:39be with SMTP id r6-20020aa7c146000000b004af622739bemr2316842edp.32.1677086966627; Wed, 22 Feb 2023 09:29:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677086966; cv=none; d=google.com; s=arc-20160816; b=YfJktEdyFy60I7pTDnhfO5Vil0VuiMdGgXR9sglT9xAfUcf78avK0Ab/XVch2yBtog Ix8gyaaH5j1vBfptDe8APOAlWBy5sgaBGz+BRz/AJqI/AvAKc/bUxFdwqvxJYrpJm3Tn 0W5G4FzlfcMXjGqUXflWT62L2y1WWGqjNxXPgdVG0+VFLt62hseaHwmfpxKaBI4jST0w G4DWkehAu+Yo/X+95SZkHCqUf3M3SFShyslDkSbYz9zDLq0+DS1//jkm6cT9PXWXd/Z8 bukur/KxdAgl+uZi4pVnd/ojjhjidzkX8nsAFp3B0I8f9P/iYDMA1YcLWFn2mIbWQeBO gxwg== 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=VPXTaQZVL1HaoQxVYcZ7bgZixI9kr2H6DQ4AJLyVX08=; b=We5E781BstQHDF9o5u2cAnf0ZWhqzwnzISFipnFwY6KWE7z2dl6dKIo9fpwFOwwMD7 bfeOJpGvcoI7yvXnQkTB9TN36Ecrt/sKZRJiWuBkX2o/GV9NJodLH7Df7uBvr+GDe7sy wQIHCQ3MgnQdY7vzTTHXBJ7tSh0SONOoNJk1FNjw24degokGXTSZpC9n2XTc7cpQ0XhX LCDP9bTB/kcXpf8p4fVl0NNk6xpT04/K8RJVvRd+w9ZtMnxej1v+xdvyaZSEZ3VirQ6X i3S5okB88rEIMI40yeLe1Mk9401W+iRViUauPiRCAIyQMNFuLp0VsrpXYqxSC0iLYa1x OLMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=JVTkaMHZ; 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 x22-20020aa7dad6000000b004ab957caf1asi10673288eds.255.2023.02.22.09.29.03; Wed, 22 Feb 2023 09:29:26 -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=JVTkaMHZ; 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 S231679AbjBVRXc (ORCPT + 99 others); Wed, 22 Feb 2023 12:23:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232650AbjBVRXW (ORCPT ); Wed, 22 Feb 2023 12:23:22 -0500 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B978619F; Wed, 22 Feb 2023 09:23:19 -0800 (PST) Received: by mail-lj1-x232.google.com with SMTP id y14so1477443ljq.4; Wed, 22 Feb 2023 09:23:19 -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=VPXTaQZVL1HaoQxVYcZ7bgZixI9kr2H6DQ4AJLyVX08=; b=JVTkaMHZYEnCKdfREkIj6XRcyyViNk24I0n/UWNbyLNb2A7GtCYUtJSpVDxiQArYmi CG4e3yzPEfNfYp47Ma1bMw6mJ30JkEiZSIuaFfTK29X1cMqStblNJQxU+tx7gy+b2Uyn d/MtlK4o91g5oq9Tvv5nPp7+zmBUi/coznt6APtwb969s1OQTxRwOXTETGfi9MtvV7/R 7ZOIkkf+ubHto2YRcnk7rvriD9BQWOGwiB2K9A5xyM6oKXJCfrqDRUqGjByMBmbacnij t96xUlk5Z0k9bTUEsHI1VLaLzxGZ+FnS0Db+299mJZWcoSvO0kLBSurak0T2KWHjl1Ct xzbw== 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=VPXTaQZVL1HaoQxVYcZ7bgZixI9kr2H6DQ4AJLyVX08=; b=oRwDsHYJ64IapYjyPAT0RtlYFbLVIMTRQp4Px5aF/NTAYmzvO8uP1ScRYPdKPMo0wi sHFjTWTidblsSJh4uuWzQLQG5z+uxsvHVurDO4Ake4NhA752PcfN2pSVN9fmCBz+XYDl xNUoTzgDTGwVDQmNTTfsJUEQxNrvmdwdWjK4tuxLPd4ydVUayOBsKWQngGTbl+Np8uB3 9ReJemO1Ysw1KS4dPOX4AQ7nZlcn7d3n10/zJGrwFcWQ9X+vfElCkzr5FrO1leMdcpoL 076ESKcnTRsLa+UWvKMA3qxOCsarr4p/+fwfTW7yrOx1ac84mxJMFopuH2XlOOlZlPnS UuLQ== X-Gm-Message-State: AO0yUKW+R6ga9QGsmhzF6sScaxk75+TwYQ2cINxt4SZ/r0dZo/c2A5AW 9pZKoCEl0KPQhb9yQpeE2i0= X-Received: by 2002:a05:651c:b06:b0:295:733a:3463 with SMTP id b6-20020a05651c0b0600b00295733a3463mr4824738ljr.29.1677086597753; Wed, 22 Feb 2023 09:23:17 -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 p2-20020a2e93c2000000b0029477417d80sm721513ljh.85.2023.02.22.09.23.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 09:23:17 -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 , gregkh@linuxfoundation.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, u-boot@lists.denx.de, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH 2/4] nvmem: core: allow nvmem_cell_post_process_t callbacks to adjust buffer Date: Wed, 22 Feb 2023 18:22:43 +0100 Message-Id: <20230222172245.6313-3-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230222172245.6313-1-zajec5@gmail.com> References: <20230222172245.6313-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?1758553143246733833?= X-GMAIL-MSGID: =?utf-8?q?1758553143246733833?= From: Rafał Miłecki Sometimes reading NVMEM cell value involves some data reformatting. it may require resizing available buffer. 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 | 23 ++++++++++++++--------- drivers/nvmem/imx-ocotp.c | 8 ++++---- include/linux/nvmem-provider.h | 4 ++-- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index c5c9a4654241..18fbfbf61ec3 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -1418,35 +1418,36 @@ static void nvmem_shift_read_buffer_in_place(struct nvmem_cell_entry *cell, void static int __nvmem_cell_read(struct nvmem_device *nvmem, struct nvmem_cell_entry *cell, - void *buf, size_t *len, const char *id, int index) + 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); + rc = nvmem_reg_read(nvmem, cell->offset, *buf, bytes); if (rc) return rc; /* shift bits in-place */ if (cell->bit_offset || cell->nbits) - nvmem_shift_read_buffer_in_place(cell, buf); + nvmem_shift_read_buffer_in_place(cell, *buf); if (cell->read_post_process) { rc = cell->read_post_process(nvmem->priv, id, index, - cell->offset, buf, cell->bytes); + cell->offset, buf, &bytes); if (rc) return rc; } if (nvmem->cell_post_process) { rc = nvmem->cell_post_process(nvmem->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; } @@ -1464,7 +1465,7 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem, void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len) { struct nvmem_device *nvmem = cell->entry->nvmem; - u8 *buf; + void *buf; int rc; if (!nvmem) @@ -1474,7 +1475,7 @@ void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len) if (!buf) return ERR_PTR(-ENOMEM); - rc = __nvmem_cell_read(nvmem, cell->entry, buf, len, cell->id, cell->index); + rc = __nvmem_cell_read(nvmem, cell->entry, &buf, len, cell->id, cell->index); if (rc) { kfree(buf); return ERR_PTR(rc); @@ -1791,11 +1792,15 @@ ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, if (!nvmem) return -EINVAL; + /* Cells with read_post_process hook may realloc buffer we can't allow here */ + if (info->read_post_process) + return -EINVAL; + rc = nvmem_cell_info_to_nvmem_cell_entry_nodup(nvmem, info, &cell); if (rc) return rc; - rc = __nvmem_cell_read(nvmem, &cell, buf, &len, NULL, 0); + rc = __nvmem_cell_read(nvmem, &cell, &buf, &len, NULL, 0); if (rc) return rc; diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index e37a82f98ba6..0e0ab27cbfe3 100644 --- a/drivers/nvmem/imx-ocotp.c +++ b/drivers/nvmem/imx-ocotp.c @@ -223,18 +223,18 @@ 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) { struct ocotp_priv *priv = context; /* Deal with some post processing of nvmem cell data */ if (id && !strcmp(id, "mac-address")) { if (priv->params->reverse_mac_address) { - u8 *buf = data; + u8 *buf = *data; int i; - 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]); } } diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index f87fd64eee8f..9c212f7bb7d1 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -19,8 +19,8 @@ typedef int (*nvmem_reg_read_t)(void *priv, unsigned int offset, typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset, void *val, size_t bytes); /* 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); +typedef int (*nvmem_cell_post_process_t)(void *priv, const char *id, int index, unsigned int offset, + void **buf, size_t *bytes); enum nvmem_type { NVMEM_TYPE_UNKNOWN = 0, From patchwork Wed Feb 22 17:22:44 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: 60621 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp704171wrd; Wed, 22 Feb 2023 09:27:51 -0800 (PST) X-Google-Smtp-Source: AK7set+cAFu9/XaMheuvO/4iVE05VqVdevuDebwQQO9L4KcEnujKX7FzPeOuDfrSYgXvuSwlb1Vn X-Received: by 2002:a17:906:9452:b0:8af:2b57:b80f with SMTP id z18-20020a170906945200b008af2b57b80fmr16500803ejx.55.1677086870853; Wed, 22 Feb 2023 09:27:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677086870; cv=none; d=google.com; s=arc-20160816; b=jEII5aYKl05Ajq+AY+C7PH13h6fFGt2QYRxYWS1lBk5AHEMjVBRyclXeexNTcKA4iE iSxqurL8BA9sXKn9CBYwunJmSkj/DSg0bwyTSkJyFLAN88IBjMFA+3RjdA4HowVdhXHq r6BpXqcpqW79/phKNbv57PJdUunbtCKi+bPVG+hDxRE2JXm0XgbC1ZUC3WAaWaqemzlP sLG7mhksV8WzhHIXi9Z/F8/DVjVmDH7AWXzG2DnVvGY7ztersxtuOCxgD76/WzQirQOT uOygKSl5ASPUOxCGZikyKkj0Z+9eMDz3i6Zpmv+LfIJE+uZVyijIyzYFKvN76X6nIlP9 T7Gg== 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=T9PdNIUkyOijxkm8lOstlC8GwZtZ2lt8a9Evhp9jHyY=; b=LwjZrnr4Kw8UofYPRmpRCRloB6reVJJk8fjiSBAsTdsYUZfPt9YfoQ5l5I1SfvtmEe L0Tn5gXPj42cQboAWE8xe54KRQcodnE8y8cED/b9OepS8SjHhBqHJKEpkYbwDum9BJlQ Q4m635625pd4yj+T1DyxY8xMNrh80QUnzajv86MePnS07QQollevQdPXNiPazjkCRaeB mnMNqXjUYoBPGeMhQWUeYHNvkXzYjMaF8a7S4D6A618sKjjnrr66kkNI8kFRQ0r+cN0Q EnZOIrX9b746QtDHO+dKHLYVDvhQagV3jtYce21oKXzq8lUNLQCUeKbqPV1PVo5L2b2/ Q9/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=XkTDmNQd; 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 l7-20020a170907914700b008cb405fa59csi13227835ejs.73.2023.02.22.09.27.28; Wed, 22 Feb 2023 09:27:50 -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=XkTDmNQd; 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 S232746AbjBVRXf (ORCPT + 99 others); Wed, 22 Feb 2023 12:23:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232664AbjBVRXX (ORCPT ); Wed, 22 Feb 2023 12:23:23 -0500 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 679C930D9; Wed, 22 Feb 2023 09:23:22 -0800 (PST) Received: by mail-lf1-x135.google.com with SMTP id g8so7279671lfj.2; Wed, 22 Feb 2023 09:23:22 -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=T9PdNIUkyOijxkm8lOstlC8GwZtZ2lt8a9Evhp9jHyY=; b=XkTDmNQdujDorBXEGlYn8MmYJHDngP+r5qV8JFl16HU3Cd6o5Q+eT84Zatbghp/blU Jyf4jKMfzY3cOKgoH2V1oE7QHiDP2VUFMqnocY3mDzrmfnzrr99vMEeoGsGMfgcogfZX xAyU52u2dvL95BB4DEG5Hb3J4yn5/VakYa1GdlQiTqyFS91rs34V4h6FahlgeJvIuJBA FUgMvxvbhwSvWNXc3zKrgt491iMi4qM6eyubHCK5FmpLY2ntwt82j6GBtpVyShH/t9iy puKBoUcO4l4DR35P0EljAFLaSsqU45Qz3gIr3BSeIlIk4oFf/JYwLPtu7/j0F/DoeCie TwkA== 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=T9PdNIUkyOijxkm8lOstlC8GwZtZ2lt8a9Evhp9jHyY=; b=tMRU4eXwDfF04Ld5TL+SeBSteLPmYRwVffCLI+xD23PZB1o8+KqifxtQVVqwpqe0rv /3Y7h56YPE6m5rs9FVMltjwHqR/Appeic5bcRJjGNq54Z7FcTSJMmor1C3b76/TNB/oh C+RtGnTo6+DTMrI6gRPJcdX3svwZrWOix3xF/gcRNoKyJWtD7ddoIU9A7oeUNZsnj4/z DTo+rnXBhj7p8NR47avrtEI6BlLEDGQYfJNk1ObD4pJ3cBsEsr6jI0rpN2XDrIAjGaGF N1uw917hkzhog2O00wLsMeMKrt8ydXz/v9fkFlOm8rngqkB+Z8UcQKeAl9C0BDu+OqJ4 +IuA== X-Gm-Message-State: AO0yUKUwiUWy2wEICC7fUhsNlY8gSLCFUI7ZRF7szhVkZjgVG7ZaLEnh bsgYnVp36RiDesRRmA01jcw= X-Received: by 2002:a05:6512:218e:b0:4dd:9c16:ff7 with SMTP id b14-20020a056512218e00b004dd9c160ff7mr1161984lft.36.1677086600636; Wed, 22 Feb 2023 09:23:20 -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 p2-20020a2e93c2000000b0029477417d80sm721513ljh.85.2023.02.22.09.23.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 09:23:20 -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 , gregkh@linuxfoundation.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, u-boot@lists.denx.de, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Rob Herring Subject: [PATCH 3/4] dt-bindings: nvmem: u-boot,env: add MAC's #nvmem-cell-cells Date: Wed, 22 Feb 2023 18:22:44 +0100 Message-Id: <20230222172245.6313-4-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230222172245.6313-1-zajec5@gmail.com> References: <20230222172245.6313-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?1758553042765694831?= X-GMAIL-MSGID: =?utf-8?q?1758553042765694831?= 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 Reviewed-by: Rob Herring --- 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..36d97fb87865 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. + properties: + "#nvmem-cell-cells": + description: The first argument is a MAC address offset. + const: 1 additionalProperties: false @@ -72,6 +76,7 @@ examples: reg = <0x40000 0x10000>; mac: ethaddr { + #nvmem-cell-cells = <1>; }; }; }; From patchwork Wed Feb 22 17:22:45 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: 60624 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp704937wrd; Wed, 22 Feb 2023 09:29:08 -0800 (PST) X-Google-Smtp-Source: AK7set+cInosY1demYWASqyZ036di2+oPy5oYH142+fBuitAXuW4F37Bnol5uvnjzc1ob+N3k8Bo X-Received: by 2002:a17:906:e0ce:b0:881:a3ec:2b40 with SMTP id gl14-20020a170906e0ce00b00881a3ec2b40mr17018807ejb.59.1677086948691; Wed, 22 Feb 2023 09:29:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677086948; cv=none; d=google.com; s=arc-20160816; b=qtrNupp5z5uQJZnSFnNR+RBf6T/Y1RHPD45OvzvBrQGEf2T1j2O6i/3QAc9bprGw29 yuiiXFf47Two3YPWzkPUKuevdYp+eLG/NFBsoIsTRkfGNWLoLiWMhgTi4wsDRz+ZV5tn AUnji2HfMAHIvH+x855PoZzb25KmYkJf+tJpf3QEfq5pHSbidkVxLvc6fQX1E7W/pQzW 5JxkPpRgqxvmmV6sPaIwpXL5ykqJY1iWF59TG1XARs7QkBAiHsD1v3Vo5Veb6Auzto4r Ck4jG9XaZFui8PycxMj/PNzXXyYGBFVj1dxrQ8bWo4Q9hODxCs7a1zHx+8Xgz0HpFKci Zueg== 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=nSnsOpv8KS0rCS6ksY5VSkRcczl5vnYaXjWVVff7kGI=; b=xOzZXimCxFRjan2v4PKSLMzTYgnfWLvmL8+yfGuJDW2Q0Vj+Vmm23/sDHJpcBa7bdF gW0ERPjLblUCx0auRhbyUgnwBeatFlBv4IYb9fGiYDZM3dGYrNhBWFzJXfaZiWNfX3O1 piAQHmuKrhXVEv+7SYRvEmnmADUwCzbwzetaG1WyzUgNZxlMb/Dqo6eS9LQZSBB8bRCZ IapvbB9enHUBjjiy16JitIETMVxQVWfFCkWkYOwhU+kFHVUkbRHsazG9jnpphNnwh4JT IcMZ+E6G89mQML29wA10yLQHfLcoUn0fRyf9Ki8Cn/jt3pRWtYgD/wwCT3RLVJhsYsl+ nJaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=DEqh460B; 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 mf20-20020a1709071a5400b008ccca79f939si10644784ejc.293.2023.02.22.09.28.44; Wed, 22 Feb 2023 09:29:08 -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=DEqh460B; 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 S232750AbjBVRXg (ORCPT + 99 others); Wed, 22 Feb 2023 12:23:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230028AbjBVRXY (ORCPT ); Wed, 22 Feb 2023 12:23:24 -0500 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6982DBE4; Wed, 22 Feb 2023 09:23:22 -0800 (PST) Received: by mail-lj1-x229.google.com with SMTP id a10so8674568ljq.1; Wed, 22 Feb 2023 09:23:22 -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=nSnsOpv8KS0rCS6ksY5VSkRcczl5vnYaXjWVVff7kGI=; b=DEqh460Bb4lDxi7itAAchy/jrIh1Oa/jWaYu4Nx7cgDY96x8jDagi1unEus9USivCe hnkt0DAxuUro+wf1TVDiaPwef0RpD0ZP0ZUI8XqdpEPHbmWx56WXNhJwjrTSTcFh9L81 l9UdDjbAjJrPEQiIYw4C5tm5ibZkYM/+w/O51saS4ht8gDwJkU4o9D3Z6RpPtAhUnaWp XsuVGK3z0vNMtxihXuJ7DqtCo0g3x7kxtzvmUU74ztWEhfW5e7JLrAaE4tOs8EIf9lqf gOyOJeMDeRctrIJkNNsQLdgto+hJ4uQKSybCQG8NcK8wJBT3zd7HMfpr/tJ62VAC4HpK zZPw== 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=nSnsOpv8KS0rCS6ksY5VSkRcczl5vnYaXjWVVff7kGI=; b=dBOt0yK5WPfqIv02p8jVK7Qu42kaSEoeb5RcYf2nC+6MTd3RHypxnKkiAo+sxSnY8Q rOywXb494Plba72Ig2B9t4oKv28zNkGBsMzbz/sGAeTn4+UOg3K/bR+KpFrEwwZX95wM K3M0oQauhPMyrCxEEUSJsZT1tpZ6FA3mQc6mOMOl95qp2ZtFR19cUw8eW3YMDwzuU90+ I9v8fLxr3tqyovh7cHQCBruFSYRGVEM1Yx7W7Ngzie8z2eXuDYkjsAdF2OhbzH4Vt9TJ J3aVezXPdS8sPblhBgo8h3AeQ5m2vfGr7ZS2TMssDUawG4n/RJqgNcGDGqLhCo8eXfpA pIEQ== X-Gm-Message-State: AO0yUKXcd0N9PETdXBpHwO+uHUvi5+j4qcEOTwUXitzQH0ZyCW8yYTz7 xejy2ODH1Tqz2rjRf1AqJCqeidfGQ5ZZSw== X-Received: by 2002:a05:651c:50f:b0:293:4fff:422e with SMTP id o15-20020a05651c050f00b002934fff422emr4780096ljp.16.1677086602368; Wed, 22 Feb 2023 09:23:22 -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 p2-20020a2e93c2000000b0029477417d80sm721513ljh.85.2023.02.22.09.23.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 09:23:21 -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 , gregkh@linuxfoundation.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, u-boot@lists.denx.de, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH 4/4] nvmem: u-boot-env: post-process "ethaddr" env variable Date: Wed, 22 Feb 2023 18:22:45 +0100 Message-Id: <20230222172245.6313-5-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230222172245.6313-1-zajec5@gmail.com> References: <20230222172245.6313-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?1758553124370993104?= X-GMAIL-MSGID: =?utf-8?q?1758553124370993104?= 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/Kconfig | 1 + drivers/nvmem/u-boot-env.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index 189ea85bd67d..71322ea7cf53 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -346,6 +346,7 @@ config NVMEM_U_BOOT_ENV tristate "U-Boot environment variables support" depends on OF && MTD select CRC32 + select GENERIC_NET_UTILS help U-Boot stores its setup as environment variables. This driver adds support for verifying & exporting such data. It also exposes variables diff --git a/drivers/nvmem/u-boot-env.c b/drivers/nvmem/u-boot-env.c index 29b1d87a3c51..1f5d8aba98bf 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,27 @@ 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); + + /* We need *smaller* buffer so don't bother to krealloc() */ + 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 +124,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))