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: 13179925 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 0EFD1C7618B for ; Sat, 18 Mar 2023 17:15:22 +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=fCfrPZa5koob4pe3VhNKi1Spn+94J+FfjeeQld5WPwQ=; b=ZFNYEFWxDBXd/T M+RQXlpZrYKvopvryVMlZ3RSLZl+rkMBlMyYTZPNUhD6R0PBJ8VDXdh1dEakusxisE0tDWwFn3WvR zNojJmuCwAl4sUdnMDrYQYEjzxV5lWWSh0FDPYcBvUKUlyMcn7XZu2SE0gKdJd42gXFZakNNRHroj UTKxdhv6AbQWRzGsgfJJgwBqDkrM5plKEHwDjpqS6XKmaJ+5qAyXuTOZedJBAUukj2NHyZjYRrgsk rkdbBEwOjHzEgRwc68SlkV0iFYxd9IQyfHIZGw4zI+8/78rrvZihPDWCCxmS+6wFmySt5uxADxlqc NEkA15XAWFfwfJTAZ6qQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pda8U-00530E-04; Sat, 18 Mar 2023 17:14:30 +0000 Received: from mail-lj1-x22c.google.com ([2a00:1450:4864:20::22c]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pda8K-0052wt-2L for linux-arm-kernel@lists.infradead.org; Sat, 18 Mar 2023 17:14:21 +0000 Received: by mail-lj1-x22c.google.com with SMTP id l22so8122275ljc.11 for ; Sat, 18 Mar 2023 10:14:18 -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=AbC5DlWCUzqvKiJr8lMDXzLgpZn2FKkV980RoyAO4vNCOxPkL9NVwwY8ZjPrdAK9cF scGoLAqUiHq7Fuh4Jx8VE08xAdgfP5XDLJVnxFzk5WotMlEWXvBCYIJAx9ErouqQwj5o 5N5NtCOkJ/j0i9j8ZZyn3kRqa7atfwwvvhobX5ehdgVpyO2XiZALvhzZTnih9DxsgiFI B9+cTIioQwj15t61TxDeKd73xAVIPyS5CqhqHOVmXD57UpnS/qRP8dcYxGqBIucnXZ6J DGfiCNRSlK/AtMogdf0AgyQ4JyMbPHlg50wS3l5q8gQioKi4+45Xv9sN+BSq7jfHrtkc dTkw== X-Gm-Message-State: AO0yUKU+r/iIlEgaISgO5U41V0G7XKHo/c3YF6Pwm1KBXLuB3K9c/zNs GYKnugqlFMXM7ZQuzZ/fmTg= X-Google-Smtp-Source: AK7set+ubWVjoJl1oeOHI9nP6gLMYPK66IIBurwMgzxnfjH97r8QI+YZvhy4zjtezMa0TBMw3nWSTQ== 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230318_101420_763413_93E5852D X-CRM114-Status: GOOD ( 12.00 ) 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 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: 13179924 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 33D0FC74A5B for ; Sat, 18 Mar 2023 17:15:20 +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=o3X/b6s0Ep+El7tgnlofO2AvXFSUiI1dd7yhOEZ7tRw=; b=K6ymXMAA0eEpHw trHGdmjqhAsGgBXxznyQxJPY2h8cAp3ugEGtCd1YRbSFz/TFGD/dbhBTy+xiHcvjeSAy8XxpnWY4k wzjdsiVh9z6uogLvtWP1w50cXrRKtSfGoQ/a+IahoiuA8a7MocHzqA5FmwaLABtsgp6CqBamWRRPt 3xuBo88MHn+CZgFJlIhur11wtLLo4C2kNnik1bCDAsR61vBRWODD8u+JsUCj9Nipo1N8t+U/fnlSo 8o1ACm1LQDRGUOhhLMbDbU/zL/XXezVclWRFL8028eSqOeTrueBnl0gQ6yWmqhEGTW7S2OAVqdqV5 +cSHW86GrA6GFHIyoaXg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pda8T-0052zu-02; Sat, 18 Mar 2023 17:14:29 +0000 Received: from mail-lj1-x235.google.com ([2a00:1450:4864:20::235]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pda8J-0052xB-2g for linux-arm-kernel@lists.infradead.org; Sat, 18 Mar 2023 17:14:21 +0000 Received: by mail-lj1-x235.google.com with SMTP id f16so8123837ljq.10 for ; 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=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=WZVLiTLIdZfVcdtS0B9JZugKO2gkg96YexyZu1sVlEEH41nzuAdvwdBmvIWjErdMpG 1zf+b3rzzC8xHwwAyxUVPKbNNTUc9z0Wyg5iVizcwmwwjxNggz7c5Rm7oZlMC5Y0IZX6 zi+IhBdAKqxJCUucNoGQlzl/FsoJ/W50hAKBZF/qjRVLTIuHkAtLTKrC2mgxoezojW51 oIwlEdgwuDIKh4MCDcgIrUG4Dj/UESZJa9kb1YSk/ZQtFd+gAq9a3F23GHE7xns7UAUn VGOLohnkEMfJR36p8mM16Lw9bwz9UcYd49ozv1owZIs6XBTPi43xj2uKSlU48+JNEt5i Urkw== X-Gm-Message-State: AO0yUKWFr720nWyW3uPAElouGUETQsyMW1RpKJnK0k/tcpiDQ2cNA6vq +33QoA21xH8iPCpKxPyjXcmkKfAIwQQ= X-Google-Smtp-Source: AK7set/Al0LN4OHWbI9yra477vbTqV3Ei5RvLaohUdA4IP6+DO1j48nhcE19Pco6txBWopNJt4iN+w== 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230318_101419_892062_20170F4B X-CRM114-Status: GOOD ( 16.61 ) 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 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: 13179923 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 EAAB4C7618B for ; Sat, 18 Mar 2023 17:15:17 +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=wASja4R3xQ7VAmJzp1LsPSoCBytu0gcnseiH2AJ49N8=; b=OoPTdWGsB3qMqW aDTGVIEdwMFWru8DGX2AvvbvUl9LBRaomokmSxxHPJKNuFhtAdx6la1ZfL31h50SgJTG45fOHx6Lf isqfMbuc7ovVrFlrgHNN1wiLIPxCNTHROlNSyHJ+Xqjkxc2lj58LCHotF4JlPhh33XzfmSuNbu8// hzYP6qS/QreKTFha8RNeyN9EGVRcujieeSPcxcws2G5Dq0hEvX/v6doM7TUmdiiHy0kO0Pq4RyjuU M6+aIRuhvNfnZgFvJnuDJKRfMhQA4EmLVvl/WhlqgKtQvAggU95ZMFp/3Q4CvbxTiI6bHzQhKGMou R+5t2z5apNVwWr4ego5A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pda8V-00531C-0u; Sat, 18 Mar 2023 17:14:31 +0000 Received: from mail-lj1-x22a.google.com ([2a00:1450:4864:20::22a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pda8N-0052xj-0o for linux-arm-kernel@lists.infradead.org; Sat, 18 Mar 2023 17:14:24 +0000 Received: by mail-lj1-x22a.google.com with SMTP id by8so6937616ljb.12 for ; Sat, 18 Mar 2023 10:14:21 -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=DLIe/8D9jlcvLtCSgQ923pqFFIBbf0pDBNzi/skEXctADMnS89QLngu2HfspOm9Rc8 krJ8+nboWqtv3Ul06tm2YEUXwyEUQWi1vYgjoXdzxKhfZCQwG4OzedT6Ta9XkiA5QQcQ 3ZQfc8YkXz+2ZTTA+Ph71Ul1GAM8AvN9SFRe97Ka6KvgG8EMGfY6xEEneFaqhkPbUvXH NIeadqJQf/BYfvAz6HiDlvkCqKFhSzducYpwL4HAsy7QBjUKRgou+YXCGsRuUpg3BnJC oCyOZZ+jQEGORcNt11ZhaOy3PcagW0L4If5O048mQScWNvvzY8dOPLTddNSkvKaOuB40 kJ7Q== X-Gm-Message-State: AO0yUKWapucRx+HE2Df/ZzyW8R2mSzB9reSBQ4BS4F6xkzR5p7sV+Kcn fHwwr5tk6vI6EksYf0OH6GU= X-Google-Smtp-Source: AK7set8khjgdJDLOjsL60JsKr969nfrsBSBbcfsEBMv6ZZISnKH1yfHmoQD7kzYtX9KchAV/GxaTnA== 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230318_101423_289688_68F6D4AB X-CRM114-Status: GOOD ( 15.90 ) 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/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))