From patchwork Sat Sep 19 22:30:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 1367744 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=cb+cKG1I; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Bv55C1cynz9sRR for ; Sun, 20 Sep 2020 08:30:55 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726808AbgISWav (ORCPT ); Sat, 19 Sep 2020 18:30:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726626AbgISWau (ORCPT ); Sat, 19 Sep 2020 18:30:50 -0400 Received: from mail-qv1-xf43.google.com (mail-qv1-xf43.google.com [IPv6:2607:f8b0:4864:20::f43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B50BC0613CE; Sat, 19 Sep 2020 15:30:50 -0700 (PDT) Received: by mail-qv1-xf43.google.com with SMTP id h1so5207634qvo.9; Sat, 19 Sep 2020 15:30:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1Cp6wGeZB6SS98LJtexBivyXrwvaD2ffDaajHaSACWY=; b=cb+cKG1I8bwsm48NEpp4t1JXK45eRJlANrsLdFS6bpoo0AsOub4t4AuMMf+XVSNwxZ tyZCcj0lUMNSqqQRpWy4jII5t40ALeYPmirmrzPed4rpGGRLkNMMaJeaGLAIWoXV8oFX 6nHR3drHjrv5V5XfEhnp5FkZjeRAEFG518Vn611y4+qznw3D879rCK0/XUQoiwT59OmU +RNWB/g+Uf3c2SY6SX0jACnJo8UP0Mn0b5ZLa0Rfz0En7iz4xRPXKy9clD+5U+J0e4lL H7CjOXXAyq1djZHDcf1z883o4iLm23jg+4ISG6+6T7B+nO++gmGIZEKo77vxmwoH+RPH q3PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1Cp6wGeZB6SS98LJtexBivyXrwvaD2ffDaajHaSACWY=; b=GrBvxEouCNSVM04IeS/4wXimTEhsp/yJIzcAte7thdxCySJKYsLlPSCp1tOqwAdiMq FRTa5ePVNzIqbj9yWdNskoxQetqZddAaD4i7kt0sIK+8P2MwrwXnZAQOFVpS5ttbxImm DIoP98Cm/EJiWXRBscL0yyNUm6r1EE2QUNkbK4nVHI2W6BgXB74yiExfETdRv8f6+I90 HF4HsyE+f8CnOBt4fH6iFu7HfwALvxvtL2pMKI370133jLQGYh47A28Zcv9SdL4Glv6p qzi9er8/luFpO2rmKfq1DF0DGOzcwDlEUgudnB43yatMhi4h4VwL83OA/wgMoJsPpKCz ZZaQ== X-Gm-Message-State: AOAM530CBHSddhlK7eSt8lYWBKusGdvGRuTpAF32/E+y7IWxUyFg3hEN WlAaywoedMQbWo8dPNpm1us= X-Google-Smtp-Source: ABdhPJycBYegZeDbUTMjcO7/HmBDoNX4rCni/FQqn9RIFmTJbrpMXtH1bw4JeAWdpgXYt0a5FTLRGQ== X-Received: by 2002:a05:6214:929:: with SMTP id dk9mr23719833qvb.60.1600554649519; Sat, 19 Sep 2020 15:30:49 -0700 (PDT) Received: from Ansuel-XPS.localdomain (93-39-149-95.ip76.fastwebnet.it. [93.39.149.95]) by smtp.googlemail.com with ESMTPSA id f24sm2581139qkk.136.2020.09.19.15.30.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 15:30:48 -0700 (PDT) From: Ansuel Smith To: Miquel Raynal Cc: Ansuel Smith , Richard Weinberger , Vignesh Raghavendra , Rob Herring , "David S. Miller" , Jakub Kicinski , Andrew Lunn , Heiner Kallweit , Russell King , Frank Rowand , Boris Brezillon , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v2 1/4] mtd: Add nvmem support for mtd nvmem-providers Date: Sun, 20 Sep 2020 00:30:20 +0200 Message-Id: <20200919223026.20803-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200919223026.20803-1-ansuelsmth@gmail.com> References: <20200919223026.20803-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Introduce 2 new bindings for the mtd structure. Mtd partitions can be set as 'nvmem-provider' and any subpartition defined with the tag 'nvmem-cell' are skipped by the 'fixed-partitions' parser and registred as a nvmem cell by the nvmem api. Signed-off-by: Ansuel Smith --- drivers/mtd/mtdcore.c | 3 ++- drivers/mtd/parsers/ofpart.c | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 7d930569a7df..ba5236db8318 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -551,6 +551,7 @@ static int mtd_nvmem_reg_read(void *priv, unsigned int offset, static int mtd_nvmem_add(struct mtd_info *mtd) { + struct device_node *mtd_node = mtd_get_of_node(mtd); struct nvmem_config config = {}; config.id = -1; @@ -563,7 +564,7 @@ static int mtd_nvmem_add(struct mtd_info *mtd) config.stride = 1; config.read_only = true; config.root_only = true; - config.no_of_node = true; + config.no_of_node = !of_property_read_bool(mtd_node, "nvmem-provider"); config.priv = mtd; mtd->nvmem = nvmem_register(&config); diff --git a/drivers/mtd/parsers/ofpart.c b/drivers/mtd/parsers/ofpart.c index daf507c123e6..442e039214bc 100644 --- a/drivers/mtd/parsers/ofpart.c +++ b/drivers/mtd/parsers/ofpart.c @@ -61,6 +61,10 @@ static int parse_fixed_partitions(struct mtd_info *master, if (!dedicated && node_has_compatible(pp)) continue; + /* skip adding if a nvmem-cell is detected */ + if (of_property_read_bool(pp, "nvmem-cell")) + continue; + nr_parts++; } @@ -80,6 +84,10 @@ static int parse_fixed_partitions(struct mtd_info *master, if (!dedicated && node_has_compatible(pp)) continue; + /* skip adding if a nvmem-cell is detected */ + if (of_property_read_bool(pp, "nvmem-cell")) + continue; + reg = of_get_property(pp, "reg", &len); if (!reg) { if (dedicated) { From patchwork Sat Sep 19 22:30:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 1367746 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=UxRNRXL0; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Bv55L1841z9ryj for ; Sun, 20 Sep 2020 08:31:02 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726828AbgISWa5 (ORCPT ); Sat, 19 Sep 2020 18:30:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726626AbgISWa4 (ORCPT ); Sat, 19 Sep 2020 18:30:56 -0400 Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B43BC0613CE; Sat, 19 Sep 2020 15:30:56 -0700 (PDT) Received: by mail-qk1-x744.google.com with SMTP id q63so10862510qkf.3; Sat, 19 Sep 2020 15:30:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=64xYu3WDX6vWiceRdxZMl2E+VlBih2IULY9GL5lmn0U=; b=UxRNRXL0c3gmNCGQcB1OpKvz1kVKOF1b6fhmhznYWuSPaq0zBOPUzR4GXaxYyxhtVh KA2XN1xdaeI8D3KOVfSQJzhfxO8/vNWxgGrWKDBTL8O+bM9mBnWQsjtd2cv7TXgg4BhQ umUwu8vdEiPwOxkAzZ95wSY8ISXfwyk27YyA4uAlIbSclw0sZXXfiBjKk4heoITRoAYW 5TpYU9sk6nADmvAXa6UculR0ocf0MA6ow39ut3k+BfdFcrET2/q4MuqRnI6cZwanTByI iFznGYxY2HVjGYgygKAEBTYPpjTOxMKMrsCidaD1M7TuEOmaMyLYqsT4fQQmBwXZtkI3 As4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=64xYu3WDX6vWiceRdxZMl2E+VlBih2IULY9GL5lmn0U=; b=pID1Sy2oZX6wBqt34mvWSRydV0G2VeaKiBl9pIY4s3OcHBimlx6QB4u01cnvGEfaWl FOIxHhKPL1vV+x+KQdnebYG9SkmzmMzUjJZyRLRvZY1sNB9vkxon/SQPylS14DputNL5 XteZyJksRHK1vgdIZhHL3HDYI1TwrE/g9pSdQyJFvf6cxgcSkNbz0RrzxRYndBpjdx+T dIswAT8K2SYiRfdCLQtq+Qu2YZKtbbSV1qF80iMZuiP7bBy+JdXcPqyU3vyrwFPPA8Gh 0GfnlV3GzBQdNl4IgOxkCla1IgMqzzomIn0IEZ5yPG4J/4rTDQbNw5u3+wp+u+fpfYAo M8PA== X-Gm-Message-State: AOAM532zE/8lK1cbMIPUbjM1ptOeoXB6+v0sE+wUcJEhf4F65ShtG+GG e53p4kdA8IPhyIrEgq5UmOMdhCb3q7mU7A== X-Google-Smtp-Source: ABdhPJyPapxawX3mTmskaO/Mu+FnvoeGud/hPaQVcm1zqD4t4YwDsmGHKQ5y1cB5vQjbXhvvKKdU3g== X-Received: by 2002:a05:620a:20db:: with SMTP id f27mr41427656qka.11.1600554655774; Sat, 19 Sep 2020 15:30:55 -0700 (PDT) Received: from Ansuel-XPS.localdomain (93-39-149-95.ip76.fastwebnet.it. [93.39.149.95]) by smtp.googlemail.com with ESMTPSA id f24sm2581139qkk.136.2020.09.19.15.30.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 15:30:55 -0700 (PDT) From: Ansuel Smith To: Miquel Raynal Cc: Ansuel Smith , Richard Weinberger , Vignesh Raghavendra , Rob Herring , "David S. Miller" , Jakub Kicinski , Andrew Lunn , Heiner Kallweit , Russell King , Frank Rowand , Boris Brezillon , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v2 2/4] dt-bindings: mtd: partition: Document use of nvmem-provider Date: Sun, 20 Sep 2020 00:30:21 +0200 Message-Id: <20200919223026.20803-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200919223026.20803-1-ansuelsmth@gmail.com> References: <20200919223026.20803-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Document the use of this 2 new bindings, nvmem-provider and nvmem-cell, used to describe the nvmem cell that the subpartition provide to the nvmem api and the system. Nvmem cell are direct subnode of the subpartition and are skipped by the 'fixed-partitions' parser if they contain the 'nvmem-cell' tag. The subpartition must have the 'nvmem-provider' tag or the subpartition will not register the cell to the nvmem api. Signed-off-by: Ansuel Smith --- .../devicetree/bindings/mtd/partition.txt | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/Documentation/devicetree/bindings/mtd/partition.txt b/Documentation/devicetree/bindings/mtd/partition.txt index 4a39698221a2..66d3a3f0a021 100644 --- a/Documentation/devicetree/bindings/mtd/partition.txt +++ b/Documentation/devicetree/bindings/mtd/partition.txt @@ -64,6 +64,16 @@ Optional properties: - slc-mode: This parameter, if present, allows one to emulate SLC mode on a partition attached to an MLC NAND thus making this partition immune to paired-pages corruptions +- nvmem-provider : Optionally a subpartition can be set as a nvmem-provider. This can + be very useful if some data like the mac-address is stored in a special partition + at a specific offset. Subpartition that describe nvmem-cell must have set the + 'nvmem-cell' of they will be treated as a subpartition and not skipped and registred + as nvmem cells. In this specific case '#address-cells' and '#size-cells' must be + provided. +- nvmem-cell : A direct subnode of a subpartition can be described as a nvmem-cell and + skipped by the fixed-partition parser and registred as a nvmem-cell of the registred + nvmem subpartition IF it does contain the 'nvmem-provider tag. If the subpartition + lacks of such tag the subnode will be skipped and the nvmem api won't register them. Examples: @@ -158,3 +168,52 @@ flash@3 { }; }; }; + +flash@0 { + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + partition@0 { + label = "u-boot"; + reg = <0x0000000 0x100000>; + read-only; + }; + + art: art@1200000 { + label = "art"; + reg = <0x1200000 0x0140000>; + read-only; + nvmem-provider; + + #address-cells = <1>; + #size-cells = <1>; + + macaddr_gmac1: macaddr_gmac1@0 { + nvmem-cell; + reg = <0x0 0x6>; + }; + + macaddr_gmac2: macaddr_gmac2@6 { + nvmem-cell; + reg = <0x6 0x6>; + }; + + macaddr_wifi: macaddr_wifi@6 { + nvmem-cell; + reg = <0x6 0x6>; + }; + + pre_cal_24g: pre_cal_24g@1000 { + nvmem-cell; + reg = <0x1000 0x2f20>; + }; + + pre_cal_5g: pre_cal_5g@5000{ + nvmem-cell; + reg = <0x5000 0x2f20>; + }; + }; + }; +}; \ No newline at end of file From patchwork Sat Sep 19 22:30:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 1367747 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=oZQRGbmZ; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Bv55R5jFFz9sSn for ; Sun, 20 Sep 2020 08:31:07 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726847AbgISWbD (ORCPT ); Sat, 19 Sep 2020 18:31:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726626AbgISWbD (ORCPT ); Sat, 19 Sep 2020 18:31:03 -0400 Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 269E4C0613CE; Sat, 19 Sep 2020 15:31:03 -0700 (PDT) Received: by mail-qk1-x742.google.com with SMTP id t138so10908428qka.0; Sat, 19 Sep 2020 15:31:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=k1VC0bLlr113eP4lGbVnwgieBOJkCTeFf8AM/n1gCow=; b=oZQRGbmZNIP8xDhXxJXwaTHJ6TcfISf9HwgXXIBR6DVh+PJJWuz4+zS3vF+mv09p/k dWXDWjyj8OxpIkMTs4q7d/u4ChjoMpK0IQItLzWJLPJUW4GacQh3+CBqoAlY+XRHEKXM Hg8TMPy0//QJk2KfPPfYOXW9ZPyjOiJG767+7rddNrhGhiL33hu8d0mivBq8bAgrX4DA FiLr3BI0b+xLGdqp1g4VJTamg1PmqcHORbHWFAlYd8CHz/vieWUhVS54/SiT2ZYC+54T OWCP2WTWZKJ5n4fbhNqTMXzVDQQld2zosW5/MO3Cjj6GL1HmHrRt2W0XZpVXSrXPd54v bAlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=k1VC0bLlr113eP4lGbVnwgieBOJkCTeFf8AM/n1gCow=; b=iX09ZC1X5t8/CISR2Y4G5JNhRX2bomuj7bUNUQtQOQoTA4YN5J7Bf92uNy6dhWbXsr CZRF7r7pFD6VIrDNwjYRDCUUWA2yYobJjDUtS1IhFRiXpfzTjq0lRavuYDuB1gp8nSHB PaRKTKQ0W/A69eGVmGMR/3VahYmkRTNzqH9lfqHdtRnUND7yFM5mCbJyRpub+BsIpzgM LFeHD3b2dicuVO3SBSmyInaBrCOlMzr9t4Wgh3VtrF5Nb25fRa7zZPUdzFXlpSxei0Gy XE5SVKFits2MsTyF+wrQvul1V3THcGbUdyYDS/nCdCSwSgzURJV11vR0HY5hXtogRFsU vOcw== X-Gm-Message-State: AOAM531VVvGvCOOAaGQ+6z8ZUBBzrvR7mLyRcXnwTxtYEYv75HI77oJ+ aZwG6ZILKMfQFFcuAHojtrM= X-Google-Smtp-Source: ABdhPJxJXbn9HdM+MNqZCyPh8BZb9Hy6VajZ2BR5r+QbZYC7YHCD81iTR8ZRs+LEUGggk18nm5j/Wg== X-Received: by 2002:a37:51d5:: with SMTP id f204mr38304587qkb.145.1600554662256; Sat, 19 Sep 2020 15:31:02 -0700 (PDT) Received: from Ansuel-XPS.localdomain (93-39-149-95.ip76.fastwebnet.it. [93.39.149.95]) by smtp.googlemail.com with ESMTPSA id f24sm2581139qkk.136.2020.09.19.15.30.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 15:31:01 -0700 (PDT) From: Ansuel Smith To: Miquel Raynal Cc: Ansuel Smith , Richard Weinberger , Vignesh Raghavendra , Rob Herring , "David S. Miller" , Jakub Kicinski , Andrew Lunn , Heiner Kallweit , Russell King , Frank Rowand , Boris Brezillon , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v2 3/4] of_net: add mac-address-increment support Date: Sun, 20 Sep 2020 00:30:22 +0200 Message-Id: <20200919223026.20803-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200919223026.20803-1-ansuelsmth@gmail.com> References: <20200919223026.20803-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Lots of embedded devices use the mac-address of other interface extracted from nvmem cells and increments it by one or two. Add two bindings to integrate this and directly use the right mac-address for the interface. Some example are some routers that use the gmac mac-address stored in the art partition and increments it by one for the wifi. mac-address-increment-byte bindings is used to tell what byte of the mac-address has to be increased (if not defined the last byte is increased) and mac-address-increment tells how much the byte decided early has to be increased. Signed-off-by: Ansuel Smith --- drivers/of/of_net.c | 53 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c index 6e411821583e..171f5ea6f371 100644 --- a/drivers/of/of_net.c +++ b/drivers/of/of_net.c @@ -45,7 +45,7 @@ int of_get_phy_mode(struct device_node *np, phy_interface_t *interface) } EXPORT_SYMBOL_GPL(of_get_phy_mode); -static const void *of_get_mac_addr(struct device_node *np, const char *name) +static void *of_get_mac_addr(struct device_node *np, const char *name) { struct property *pp = of_find_property(np, name, NULL); @@ -54,26 +54,31 @@ static const void *of_get_mac_addr(struct device_node *np, const char *name) return NULL; } -static const void *of_get_mac_addr_nvmem(struct device_node *np) +static void *of_get_mac_addr_nvmem(struct device_node *np, int *err) { int ret; const void *mac; u8 nvmem_mac[ETH_ALEN]; struct platform_device *pdev = of_find_device_by_node(np); - if (!pdev) - return ERR_PTR(-ENODEV); + if (!pdev) { + *err = -ENODEV; + return NULL; + } ret = nvmem_get_mac_address(&pdev->dev, &nvmem_mac); if (ret) { put_device(&pdev->dev); - return ERR_PTR(ret); + *err = ret; + return NULL; } mac = devm_kmemdup(&pdev->dev, nvmem_mac, ETH_ALEN, GFP_KERNEL); put_device(&pdev->dev); - if (!mac) - return ERR_PTR(-ENOMEM); + if (!mac) { + *err = -ENOMEM; + return NULL; + } return mac; } @@ -98,24 +103,48 @@ static const void *of_get_mac_addr_nvmem(struct device_node *np) * this case, the real MAC is in 'local-mac-address', and 'mac-address' exists * but is all zeros. * + * DT can tell the system to increment the mac-address after is extracted by + * using: + * - mac-address-increment-byte to decide what byte to increase + * (if not defined is increased the last byte) + * - mac-address-increment to decide how much to increase + * * Return: Will be a valid pointer on success and ERR_PTR in case of error. */ const void *of_get_mac_address(struct device_node *np) { - const void *addr; + u32 inc_idx, mac_inc; + int ret = 0; + u8 *addr; + + /* Check first if the increment byte is present and valid. + * If not set assume to increment the last byte if found. + */ + if (of_property_read_u32(np, "mac-address-increment-byte", &inc_idx)) + inc_idx = 5; + if (inc_idx > 5) + return ERR_PTR(-EINVAL); addr = of_get_mac_addr(np, "mac-address"); if (addr) - return addr; + goto found; addr = of_get_mac_addr(np, "local-mac-address"); if (addr) - return addr; + goto found; addr = of_get_mac_addr(np, "address"); if (addr) - return addr; + goto found; + + addr = of_get_mac_addr_nvmem(np, &ret); + if (ret) + return ERR_PTR(ret); + +found: + if (!of_property_read_u32(np, "mac-address-increment", &mac_inc)) + addr[inc_idx] += mac_inc; - return of_get_mac_addr_nvmem(np); + return addr; } EXPORT_SYMBOL(of_get_mac_address); From patchwork Sat Sep 19 22:30:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 1367749 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Kq1HpGi/; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Bv55b1ZGcz9sRR for ; Sun, 20 Sep 2020 08:31:14 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726865AbgISWbL (ORCPT ); Sat, 19 Sep 2020 18:31:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726626AbgISWbJ (ORCPT ); Sat, 19 Sep 2020 18:31:09 -0400 Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [IPv6:2607:f8b0:4864:20::736]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91F99C0613CE; Sat, 19 Sep 2020 15:31:09 -0700 (PDT) Received: by mail-qk1-x736.google.com with SMTP id w16so10866678qkj.7; Sat, 19 Sep 2020 15:31:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FuUvgB8iMkHgcxvxhIPaKesqPeUDTnfXOpNMPbDpmVY=; b=Kq1HpGi/RYvFJutzgEITb+4XKoQsYcQaiw+JEkrWbrHSNHzflhnewbfX+OA/ayuomc x3AwuO3t6ZN/vhnJYTiArWB+c8Pu0QJUMS+brIYBidpJNVGEz9z7sTUTkkkivAKtsgGU RGezSP7qEpItLVMgIEcxuxHKBWu3MIDWlAM9tqgm57ObEzYKGqa9JVYmkTrGUo2mfwzS ZxY6ejgJBoT5TwyAYgFIDcg+QaX4gXcG4FmbOK2w1IA4Ubx7QgTojiH/B/H1cDuKif55 Y92TBtPpPRCIIrht7fIqeMgQx1pNYJw+mSfl6uw8QaKuMUI0/0a+UTtuhH46eDnZwOVW 01Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FuUvgB8iMkHgcxvxhIPaKesqPeUDTnfXOpNMPbDpmVY=; b=N8UnoZd9YzYjClP8pLLdHKWvuoc3+AFc/gzIyte9Il49DmctXxyBeinGMZL4JIvZEN /gPOn/2G1IiF8AKts4D2ziujnPlRUyMTiLllIpwGSUxCGYfqeLkz3mhR4s4ij3ooHwIs LxvpGSnaMVHAugsbfPX8lpSZVRwdjC/hHw9nsXVTZ8HWR/kVaYOOjqP8HUQTxe8ToLpt JaGSnRZvAC+fMeuw878P69FqZp3ytuLhAemcqL09ZYIpZQgKNPs6q+7gTdOTxHkg4+1T +58Rjf3X5pxXNK98U7N7fVHuX/1cG5dmPBlPqeOuyLXDlqPNCFtk+eV0/wf5rjUSBmKx hi2g== X-Gm-Message-State: AOAM532BsGVgEY6dgBM/wau8KqcYYcba3IVTZYW0sYxuq9yxxetZ0zYG 5layRWw557DyAa0oBNo+13c= X-Google-Smtp-Source: ABdhPJwMQqLUYfruyEYwvtNhOG0DwZqLC/uJ2hsFUBlKE0cn+xgwFxVAVeYLm/LOL9qALxmfXyYNrA== X-Received: by 2002:a37:76c2:: with SMTP id r185mr38929715qkc.122.1600554668713; Sat, 19 Sep 2020 15:31:08 -0700 (PDT) Received: from Ansuel-XPS.localdomain (93-39-149-95.ip76.fastwebnet.it. [93.39.149.95]) by smtp.googlemail.com with ESMTPSA id f24sm2581139qkk.136.2020.09.19.15.31.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 15:31:08 -0700 (PDT) From: Ansuel Smith To: Miquel Raynal Cc: Ansuel Smith , Richard Weinberger , Vignesh Raghavendra , Rob Herring , "David S. Miller" , Jakub Kicinski , Andrew Lunn , Heiner Kallweit , Russell King , Frank Rowand , Boris Brezillon , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v2 4/4] dt-bindings: net: Document use of mac-address-increment Date: Sun, 20 Sep 2020 00:30:23 +0200 Message-Id: <20200919223026.20803-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200919223026.20803-1-ansuelsmth@gmail.com> References: <20200919223026.20803-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Two new bindings are now supported by the of_net driver to increase (or decrease) a mac-address. This can be very useful in case where the system extract the mac-address for the device from a dedicated partition and have a generic mac-address that needs to be incremented based on the device number. - mac-address-increment-byte is used to tell what byte must be incremented (if not set the last byte is increased) - mac-address-increment is used to tell how much to increment of the extracted mac-address decided byte. Signed-off-by: Ansuel Smith --- .../bindings/net/ethernet-controller.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Documentation/devicetree/bindings/net/ethernet-controller.yaml b/Documentation/devicetree/bindings/net/ethernet-controller.yaml index fa2baca8c726..43f2f21faf41 100644 --- a/Documentation/devicetree/bindings/net/ethernet-controller.yaml +++ b/Documentation/devicetree/bindings/net/ethernet-controller.yaml @@ -32,6 +32,25 @@ properties: - minItems: 6 maxItems: 6 + mac-address-increment: + description: + The MAC address can optionally be increased (or decreased using + negative values) from the original value readed (from a nvmem cell + for example). This can be used if the mac is readed from a dedicated + partition and must be increased based on the number of device + present in the system. + minimum: -255 + maximum: 255 + + mac-address-increment-byte: + description: + If 'mac-address-increment' is defined, this will tell what byte of + the mac-address will be increased. If 'mac-address-increment' is + not defined, this option will do nothing. + default: 5 + minimum: 0 + maximum: 5 + max-frame-size: $ref: /schemas/types.yaml#definitions/uint32 description: