From patchwork Sat Mar 18 17:13:54 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: 71638 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp390257wrt; Sat, 18 Mar 2023 10:37:03 -0700 (PDT) X-Google-Smtp-Source: AK7set/k3XCK0BB/LM1YFYT6MTnSxY2LTdi7tc/dkNCphYVGHX7i9sNH38djzLa56hmUY/r4owu3 X-Received: by 2002:a05:6a21:78a7:b0:cc:5f27:d003 with SMTP id bf39-20020a056a2178a700b000cc5f27d003mr12851371pzc.56.1679161023321; Sat, 18 Mar 2023 10:37:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679161023; cv=none; d=google.com; s=arc-20160816; b=UEq8dTwqB+WZ/n81/efDlrJY94fgUv+Pjkgv3N3aB1+ybvNxHsPmlCqjGR/2ytSAxo XtVM7SGj9cKTJJU1pxMnFByycCGWQMLuWD6FTDkMQtHSsipJ9a9MOOU/I87YHKvd0KCw q14augodDgzChoBmaW5IJ8iLc14bNhcP/tGJaBbTty89fepPh/qn9WvyLdh69iS97jIB QhQEPQvV5Uocd81NyPO7b0yu5xxmNPSvqyaSuBNrcxl/Mo/mh4aXzZv89yTE5MWQF2WX qAFKJBvALK0fkCojwZrcUBYAEnRGrDqS92qm9CE8pAXIhbOjg2lZA4ftp0c+bk+fJsil s0HQ== 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=pp9igBJ08r0VD7UzKGc4hwKsqI+qS7B8wD3c5+JhpEunhdgTbyPkP12T7MWoYNdwbk 6Hfsa2G/G9IFUcMkhVnlNy+c6pvRxKfrP1Hg832oHzyEY/2sShW4d9m3YeYfPcbZVwCx gSxy0n7RfFuV0hvtXHUFe4oPVlLk5UWmrQ5He6cfXDnM6A0LUdi8sHW9bIqb8m7Lscag oqB+TytxyFNfnJ0CMSZHW1zhab/5mQjvzsVsnp9laKUmdER33aeI99Zg67pz2v/Im6+v x9FcVZtfd58vJmgPBd09FzrRy04JIyVQeLZ7j2v2/7Qq33lJHiImOBg6P62yaZg9XGNm m96A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dpH5VunW; 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 a6-20020a631a46000000b004fae7b9ed23si5459501pgm.791.2023.03.18.10.36.47; Sat, 18 Mar 2023 10:37:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dpH5VunW; 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 S229938AbjCRROX (ORCPT + 99 others); Sat, 18 Mar 2023 13:14:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229925AbjCRROV (ORCPT ); Sat, 18 Mar 2023 13:14:21 -0400 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 1829C1B314; Sat, 18 Mar 2023 10:14:19 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id s20so927857ljp.1; Sat, 18 Mar 2023 10:14:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679159657; 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=dpH5VunWjpCn63iFcoDNWtxgyMVveYmI8v67tXbKoiIa/DfhM/on2j2ky4/cKk8HPC lAxYE8b0J+wAUWmLrOLJ4D0o56TnkTaw2zmM5Zeo3yLTFsfEaHZf6SKrQiiODJC+wRYm SJm+h8DnEODr34Lqtfm94BvIv6GInLXFhl/VOqtKma2Z9361PKm7w+eFQ2v5yWxP8YaQ nAmSaedWvl5bF05m66BqHK6fEk2+V/gG39qJc01ZcleezpD3JWf278ZimIJ11TxUB2B1 KK7Ya9FOf6BtUg/I7Z6psaYiNnZ3wQp/6lHL0NFtAM/abAYtpjVXL2lscepAhz5a+6dO 5vFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679159657; 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=hhWs9YFZtm2/gVV4hXLeeK/SapVnxb4HazHI0p3IPi5MNEnOl9SgrOrtklHBlOxMg/ ZusrCYcV2KKCxNtXw/FkOrSC1TG8LCddDIyLe5tc+J4ieZ+EFB8RCedCNeZMPVpPud3M NrNKownFrSJhxm3k6WXx8kOSGcu0GqggBqwiASFzUdq5iXjN8UBDju2xmOANTKJIA4IP qNLEVLMLpX/V2OOUj4qvKFuWQNpI4PctKuiT6+DMIt+LjgfgqXb9e1EoHrcVNcayPu42 TJlyl3k34jt59jQJ7FNnOM14tQeCQAD5R3dvpjC92YJczxjBDPleSYnf6tQEEKUob5eb m1Dg== X-Gm-Message-State: AO0yUKWtXxSCDw8HCPxzi0AfNPQmyktD9EroDufNS0w42OPwqGZenmf/ 5I6HYPwhFnnh13pw/vXYNMA= X-Received: by 2002:a05:651c:511:b0:295:93eb:e795 with SMTP id o17-20020a05651c051100b0029593ebe795mr6313453ljp.41.1679159656632; Sat, 18 Mar 2023 10:14:16 -0700 (PDT) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id r9-20020a2e80c9000000b0029573844d03sm929221ljg.109.2023.03.18.10.14.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 10:14:16 -0700 (PDT) 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 V2 1/3] dt-bindings: nvmem: u-boot,env: add MAC's #nvmem-cell-cells Date: Sat, 18 Mar 2023 18:13:54 +0100 Message-Id: <20230318171356.29515-2-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230318171356.29515-1-zajec5@gmail.com> References: <20230318171356.29515-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?1760727949015729513?= X-GMAIL-MSGID: =?utf-8?q?1760727949015729513?= 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 Sat Mar 18 17:13:55 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: 71640 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp391002wrt; Sat, 18 Mar 2023 10:39:02 -0700 (PDT) X-Google-Smtp-Source: AK7set+o6fNEX8djRvNZUXvXRjHOWFK/5YpV+2ps/of6eWhgwyQnr3lW9Irz44IUyjxYciHyl2DJ X-Received: by 2002:a62:1d52:0:b0:625:e8ec:4f5b with SMTP id d79-20020a621d52000000b00625e8ec4f5bmr8853034pfd.6.1679161142486; Sat, 18 Mar 2023 10:39:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679161142; cv=none; d=google.com; s=arc-20160816; b=BhyBZGY29VnbtvZCiSUoBkP9izrNjM6l9Fylm+jcciec7IbJ47Uqxa673d5OX4Txnk 3dA2PUWmBcwJmaMpjal2oDEf2MQ3YXh/C4/+mAUhZaC1GRKayZpfQ23Hj5Yapcmufyf7 F/EiALIvQHZVDX8VEuE1MDgoqKPIPK3FUgGX4HyV7cOdC7GgnAAAaBWC88DBJa6epm+m VvghpmX03YvGRcfLPGtbzzKTokTtJKIv+HeO99bEcaQKqKPeH42dJrO4bYY5PS/EL71O /MgDglKcN4dYyKV0T7pybvJcxDZSSw/99sG2QFptZl5/jvQgTn9s1T7IEORfgJ7MpqrE gALw== 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=OHNZ4cJK3nDs1ydwUCLlZnjoqV5tGqCoWiDTUvwcqRM=; b=Tan4pp6JBD4pnhyCpSFrgMlyUh0mIJeN75AGYVlKDjAFg3RkLgPCrql63W3On/WSTq ly+TMJBx5502lrug7fGHzfi3LT1UDd61fCYWz4ZDEwj4dHOCtaC2Kpwi4GQZlr68HOfB +WPx79JpTbszFTMbFZlHyFNAV2zL+DTXK0fkvrJDg0eXDFJpulcAg6nw6ff39Ow/Viqg Gmp5LR+bVdaeVVjD8EonOzR/82iFnXijMNiEWsDPDpWpQr4m+vK7rT+dqwk+3hKQkJjD jhV+cXXHeuPcbmtwEcsPDsE6fvSbnZFqhsmc9UawMKn3gyAgcAzuKtZskz7djPxHy055 RGgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=WkZKmx6k; 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 a6-20020a631a46000000b004fae7b9ed23si5459501pgm.791.2023.03.18.10.38.46; Sat, 18 Mar 2023 10:39:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=WkZKmx6k; 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 S229972AbjCRRO0 (ORCPT + 99 others); Sat, 18 Mar 2023 13:14:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229926AbjCRROV (ORCPT ); Sat, 18 Mar 2023 13:14:21 -0400 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 1AD98149AA; Sat, 18 Mar 2023 10:14:20 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id 20so999521lju.0; Sat, 18 Mar 2023 10:14:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679159658; 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=OHNZ4cJK3nDs1ydwUCLlZnjoqV5tGqCoWiDTUvwcqRM=; b=WkZKmx6klWxMG9Yhh6CNKVShzb8jM9M8AVTmW4QGOw49tN/DI+rUgtiFzLe4A4ARq5 je81EJy0/oXIQFj6lsrgco/A1NyrlwXB0mW4VIoVKIEc2i+WGn6ZPTnpk4DJY7qDkaGj kYpFndkBxTGgLvXoAQkp1LhU8Vi4tdyg+Xxnc3R+D1TB/rAbLImqZcSIKBNnzOuFaneR KqeIRdkKye4gxP3tyUJlKxYDhpkyJE0yrZ4iSEy+bS/cFYK8oO5BDrL1RqUWrkTdqHO9 2iWrSRbGtitCmfIIPsUWFwAeqg8/5rh1lVXqDGHVjuHOAE/9SBJtKFltr+mjTajbz1U8 Xn2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679159658; 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=OHNZ4cJK3nDs1ydwUCLlZnjoqV5tGqCoWiDTUvwcqRM=; b=Ad4oW3JKLuZBf7wDl20g5h87BN2vNCJEHb4dzzg2qq1kA/ATZDZd1dmqsnKuy0WRmm hR1SCsc5Y0RXoa55Nu8Yf6hxDqG1lc2z0P9JeIobMLXGTdA1Re+sIPnRrQxy0b+Xpb4K WLqgM39P3WTiXQNrzrOCXsgk6nbNf6lUrmot+Vi0koXX7lFcx0NoInmggnOtgdpYkyJE KUkX9JrJh/EggKYPAE8qkLB3KZIKC7hKnQ05RFTUkUI218CSndNRoRbM2U03lFBZSY6H Fgs1b1aDR1K18vp6PaYYEkLj9n6fgTwdXSrXI6v+qHixSExfjKDRVWMbKnRwF1WJjOsh 2IQA== X-Gm-Message-State: AO0yUKXr2bbpyUBtU4m+VdhMkavtzfxRYAVRzbn3dcAgUB+DZZDSpi0I z5Jm6P4NazFw2ItHv+w7DMo= X-Received: by 2002:a2e:b895:0:b0:295:a958:2bca with SMTP id r21-20020a2eb895000000b00295a9582bcamr5373412ljp.6.1679159658495; Sat, 18 Mar 2023 10:14:18 -0700 (PDT) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id r9-20020a2e80c9000000b0029573844d03sm929221ljg.109.2023.03.18.10.14.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 10:14:18 -0700 (PDT) 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 V2 2/3] nvmem: core: support specifying both: cell raw data & post read lengths Date: Sat, 18 Mar 2023 18:13:55 +0100 Message-Id: <20230318171356.29515-3-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230318171356.29515-1-zajec5@gmail.com> References: <20230318171356.29515-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?1760728074074639791?= X-GMAIL-MSGID: =?utf-8?q?1760728074074639791?= From: Rafał Miłecki Callback .read_post_process() is designed to modify raw cell content before providing it to the consumer. So far we were dealing with modifications that didn't affect cell size (length). In some cases however cell content needs to be reformatted and resized. 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). There were few discussions how to optimally handle that. Following possible solutions were considered: 1. Allow .read_post_process() to realloc (resize) content buffer 2. Allow .read_post_process() to adjust (decrease) just buffer length 3. Register NVMEM cells using post-read sizes The preferred solution was the last one. The problem is that simply adjusting "bytes" in NVMEM providers would result in core code NOT passing whole raw data to .read_post_process() callbacks. It means callback functions couldn't do their job without somehow manually reading original cell content on their own. This patch deals with that by registering NVMEM cells with both lengths: raw content one and post read one. It allows: 1. Core code to read whole raw cell content 2. Callbacks to return content they want Signed-off-by: Rafał Miłecki --- drivers/nvmem/core.c | 11 +++++++---- include/linux/nvmem-provider.h | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 212c5ba5789f..a62973d010ff 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -50,6 +50,7 @@ struct nvmem_device { struct nvmem_cell_entry { const char *name; int offset; + size_t raw_len; int bytes; int bit_offset; int nbits; @@ -469,6 +470,7 @@ static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem, { cell->nvmem = nvmem; cell->offset = info->offset; + cell->raw_len = info->raw_len ?: info->bytes; cell->bytes = info->bytes; cell->name = info->name; cell->read_post_process = info->read_post_process; @@ -1560,7 +1562,7 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem, { int rc; - rc = nvmem_reg_read(nvmem, cell->offset, buf, cell->bytes); + rc = nvmem_reg_read(nvmem, cell->offset, buf, cell->raw_len); if (rc) return rc; @@ -1571,7 +1573,7 @@ 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, cell->raw_len); if (rc) return rc; } @@ -1594,14 +1596,15 @@ 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; + struct nvmem_cell_entry *entry = cell->entry; + struct nvmem_device *nvmem = entry->nvmem; u8 *buf; int rc; if (!nvmem) return ERR_PTR(-EINVAL); - buf = kzalloc(cell->entry->bytes, GFP_KERNEL); + buf = kzalloc(max_t(size_t, entry->raw_len, entry->bytes), GFP_KERNEL); if (!buf) return ERR_PTR(-ENOMEM); diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 0cf9f9490514..8ffb42ba0f62 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -51,6 +51,7 @@ struct nvmem_keepout { * struct nvmem_cell_info - NVMEM cell description * @name: Name. * @offset: Offset within the NVMEM device. + * @raw_len: Length of raw data (without post processing). * @bytes: Length of the cell. * @bit_offset: Bit offset if cell is smaller than a byte. * @nbits: Number of bits. @@ -62,6 +63,7 @@ struct nvmem_keepout { struct nvmem_cell_info { const char *name; unsigned int offset; + size_t raw_len; unsigned int bytes; unsigned int bit_offset; unsigned int nbits; From patchwork Sat Mar 18 17:13:56 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: 71639 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp390980wrt; Sat, 18 Mar 2023 10:38:59 -0700 (PDT) X-Google-Smtp-Source: AK7set+qgRRBuJnope0V3rre6/ms84VwGSByzdUZf2e/QfF6PF0e1P8oTP8cUrwqME80K/rYtJzu X-Received: by 2002:a62:f252:0:b0:627:e677:bc70 with SMTP id y18-20020a62f252000000b00627e677bc70mr1645135pfl.14.1679161139301; Sat, 18 Mar 2023 10:38:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679161139; cv=none; d=google.com; s=arc-20160816; b=jJhC8dZxelASFQAuulC3Zzocu04kemRPpL5dNUDFwLishihFG5ZXvq0oZ7w1vjikh7 j/6haRQA7Ycag7Dv+bnkXcHTNZIx4hvaZpBaP5oCRfMLmpYnB7i+TpdVcOnDBYq+Zn9K vC2udwsOJLWBqDtHsjA5FWVLaDkg3yql7YztujE8xTmhhVr6e36WFb6J5HnFGSallCci brL+9G6RU0L2QeCbZmwaCcWmZEZ7iGnE/pjsVDToRbvoGuu6vUmdKnjZ8fwbw/vntXf6 pviOcnQIUcft8bP/bJJ+GSyCNYOTxGPlJkCW9tT2EE+KHjACfJC5IoLhlak7hoC2nv1Z pfzA== 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=o6gVXR7MyV0dGeKTkzI0XUj6QXrFR6902YeCKHs1ZQM=; b=lhM7gjlSqVZkeIcaRlCDtj/LQK0StZZmYQZYGVlbKFkE2aydFXj/NdX6jkR4NdYhg1 P0vmVVOUGrdunobuqCH9TssR0xGQUs7oMkLM9b6aodEYPF0w2R6KqpW1DZ/Dwb+yCvvL OIO2QHGkJJsMvAoEc0kluKsnLH29/Ql84mlV271UC2IMJveMucwEm1Ctqv+hPsGJHQ24 iVKmGyWRiHwO9MUyEkffUPmJafANuf9eSWKW3rQPcm9XeXlnHfMPWE2diK9PR6nMYGdt kvlAlR8WOf3R24tKyT8nQVcynKpekhIWEVcWPRTmrOowOmN2YmZix/OnQHH361XIAQgX bO4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=mdenNH8N; 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 n24-20020a635918000000b00502f3d1a058si5608479pgb.479.2023.03.18.10.38.44; Sat, 18 Mar 2023 10:38:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=mdenNH8N; 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 S229970AbjCRRO3 (ORCPT + 99 others); Sat, 18 Mar 2023 13:14:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229940AbjCRROX (ORCPT ); Sat, 18 Mar 2023 13:14:23 -0400 Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 567AB149AA; Sat, 18 Mar 2023 10:14:22 -0700 (PDT) Received: by mail-lj1-x234.google.com with SMTP id a32so8135833ljr.9; Sat, 18 Mar 2023 10:14:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679159660; 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=o6gVXR7MyV0dGeKTkzI0XUj6QXrFR6902YeCKHs1ZQM=; b=mdenNH8Nyexs6YyB62R/BZLhJHWiUS4++a1cZgCzO3QzqQ13iScjbNS8+W9Nxo9Z9o nScggbnS6OkYgx2/QfjKc9S82cp+l+kNMyaGGh0C1QAyLO0d8SUZcgcMTIEaNmChWl6v u1Hs51u4M9GmZ+BAZRYB+F5sYcp6/ZoiDnI07OOR1QmpifluKrnBqpFdiLZbjQnpnaU4 de2By0/MmkKVHh0Wjm45cKM6/zOGETPSD4zkBo/LghjDi4FI6Hq1r+g+K93M57C/YAFT JaoT2+1axMz5zCIHevO/igMIB7A+U4i3J4UBjIojSr1foZN5eFiLKDU4VO6jrPi7amJg f1Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679159660; 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=o6gVXR7MyV0dGeKTkzI0XUj6QXrFR6902YeCKHs1ZQM=; b=Qwbj0opkqzxaFimEAWluWj9UjWU8nd/uhbKmCdrKIK62jeASoDoFUN/Zr3mv8meusD HkTmCfYz7vzyykDstFhGlvUmqPbrIjjfWGVFjzyEEzMMuIAig9T2e62ZWHmwKYH7/KSU 79w/OIWy+2+spgN0hedtpl5iw1ZIr+rS9Tw1DBoj+C8zy4oiEZIvOzuGnubUBIU11TVk YOOpxjowkiWe1Pfn9UDa5JHkDaMfwGODfRraY08J1W/aRkEEg4O9T1nX2U+sTWq0W6Tk Eh1Bwk7ttxbFMjjw+lKyQQQhbq/RrdRM4gPT70HQgWaR8jHUqVOC3BTC63lXBl51jRjB wkug== X-Gm-Message-State: AO0yUKU75/te4mKybJn00AX6gkTtwmbdjgzx7ti0G/BCdCT5yTHJVKw1 pJsOVg0K1+um+Ceb9aG4sdA= X-Received: by 2002:a2e:7d15:0:b0:298:b065:c29b with SMTP id y21-20020a2e7d15000000b00298b065c29bmr4403516ljc.38.1679159660245; Sat, 18 Mar 2023 10:14:20 -0700 (PDT) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id r9-20020a2e80c9000000b0029573844d03sm929221ljg.109.2023.03.18.10.14.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 10:14:19 -0700 (PDT) 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 V2 3/3] nvmem: u-boot-env: post-process "ethaddr" env variable Date: Sat, 18 Mar 2023 18:13:56 +0100 Message-Id: <20230318171356.29515-4-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230318171356.29515-1-zajec5@gmail.com> References: <20230318171356.29515-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?1760728070976590981?= X-GMAIL-MSGID: =?utf-8?q?1760728070976590981?= 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 | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index a2afba11c890..b291b27048c7 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -340,6 +340,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..ee9fd9989b6e 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,25 @@ 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 *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 u_boot_env_add_cells(struct u_boot_env *priv, uint8_t *buf, size_t data_offset, size_t data_len) { @@ -101,6 +122,11 @@ 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].raw_len = strlen(value); + priv->cells[idx].bytes = ETH_ALEN; + priv->cells[idx].read_post_process = u_boot_env_read_post_process_ethaddr; + } } if (WARN_ON(idx != priv->ncells))