From patchwork Fri Dec 20 19:17:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13917269 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2840225414 for ; Fri, 20 Dec 2024 19:17:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734722240; cv=none; b=Ct4HpSoESEag5R6TnO+nIPyS7P8no6Qlf5MrqwNIierqrYVcBTO8L/bPRd3JJPrvxiv2U+uDNhp/+++ddUg8kR5KyQJYtbSoEt3AITbhsYRpihdvPnRipBkVNfLQwk1+FTRu2nPgFcCgd3QvFw6tKSIUPO477tK0mynWrGwinZU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734722240; c=relaxed/simple; bh=3owT/KMCvF5XwxfrBAfaiky6eGpIYrzcz95ija8sMWg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mgIwIzZHMoYfIQ4toM+Qf8Y1g9fTHVtbdc/tUUxzH1Ygm1Rqj20xiCRDRj2fm/GZL/9u3BvglijFJQgubPQj7hDDYzZXGFcqvxp71XAFm9Tpmhh5Pree9OX1Zq6OzUc9QptQj94pVid6ecAaPG6TUCGSOCoQVOXfErmZCghv16Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=h49gztQW; arc=none smtp.client-ip=209.85.208.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="h49gztQW" Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-5d3d479b1e6so2913520a12.2 for ; Fri, 20 Dec 2024 11:17:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1734722236; x=1735327036; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=vBR/gsOu5StkcyNL8p43Oyx52bSqF/t8CsaHctvuxX4=; b=h49gztQWoAh9Ae5RpDe/nkxfQDL6oPqjeFZeN+RXRSt6QaoT2Yr01PYZPb6/auh6Qy e3uok0CXIVUUT4NJPk+ElAy1DKAOQgycNX9Pc4HeWTpNPPAGNJOHHtBoY7ui40AmZ1Mv 0HLHj8rXK4j4knGt6iGZEPjhgtFFu0EZ9DFBLCoquSYjZdqh6ZkUbwIn14PXajKPF4B8 0kTmX6zy56OJ/8V/ZVrbPq22BAT/ss6AAURC/J1gt273iYMhg9nYynEkgTpBRjq78Aa1 5EgsBAQUwtbIBHGzZ6NstFn5Xxh2pcALzMAxlmZxB6FncbjV54a60Ut8hd57K2o1g/mg Ciug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734722236; x=1735327036; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vBR/gsOu5StkcyNL8p43Oyx52bSqF/t8CsaHctvuxX4=; b=NJDp02AX29gAsaQRKjVnxzOhrUwd3kvCZi1UB/h5onZ9lSZPuqtTcIOdNpPr9tdyAP gZnAsiVqlrqsVKlZGd+Lk8ssu2iC2/eykhthGPplnXwOOPF0B3l8misWJwfwXwMFugsA eNWaRNwE4QrpIbrDpf0juZOAzADekWVNwljqLpK1VmAn81IdQbcFrlJwceFHcRHPoMj1 xs4rL+ZSatZaGg0G+uzlybD7gursG40fEuVoi7TQR8ExiZouyq1APIfOsKwbpPXYwP7v XfcdUvKSwyh0pdYgPk8SLgz3+WpmvHYKo7625/ymJDN6VmN3PF5XAdMpY5GVKMUsuQNY 16CQ== X-Gm-Message-State: AOJu0YzLgtzRPWgLg9JqzsUEwO2tO1PeDCo4f7VvqRAvW3Ljmb83+RH3 4Q8s5VX5nClUFaEUkAtj3Cq6DIT5RKe0ehd93EQjZ/v33chrachL1n3o26UKhqc= X-Gm-Gg: ASbGncup66KjEVusEGBCtoujxGs3azHXSpnyt4BdDZaC0q8zYBXkRy4Cn2dBC9sMNY8 XXoj2lXq14e44L9cnHXSJhTJgMvPB8ADPPYF6Y8kuwDwPUEmVdRGRAZuc9s1aWQkDSFzk+68jyc e/HvV5L2CB4nvlortjXol6/dWiiy5mqbj0aaFCBGOkCsTUR5UJxDMyYeZV4GcmhSdeMQjklL+qB 9hREm4dZUTBtlczixPkgil+cr64VE3Ko3n1lvxeso3L/kWFcMHzR7iq8tXxWUWsUBI= X-Google-Smtp-Source: AGHT+IFmLyPE9OMUVuB/6IZRMr2eptvA+ua1OuRWCkVTNnTDUTn6N/1kmxMoQ8Owur8tJ0XN93MY3g== X-Received: by 2002:a05:6402:1d53:b0:5d0:bf5e:eb8 with SMTP id 4fb4d7f45d1cf-5d81de06611mr7849152a12.23.1734722236189; Fri, 20 Dec 2024 11:17:16 -0800 (PST) Received: from [192.168.1.140] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d80679f11dsm1988727a12.46.2024.12.20.11.17.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2024 11:17:15 -0800 (PST) From: Linus Walleij Date: Fri, 20 Dec 2024 20:17:06 +0100 Subject: [PATCH 1/2] dt-bindings: net: ethernet-controller: Add mac offset option Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241220-net-mac-nvmem-offset-v1-1-e9d1da2c1681@linaro.org> References: <20241220-net-mac-nvmem-offset-v1-0-e9d1da2c1681@linaro.org> In-Reply-To: <20241220-net-mac-nvmem-offset-v1-0-e9d1da2c1681@linaro.org> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andrew Lunn , Heiner Kallweit , Russell King , Simon Horman Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.2 X-Patchwork-Delegate: kuba@kernel.org In practice (as found in the OpenWrt project) many devices with multiple ethernet interfaces just store a base MAC address in NVMEM and increase the lowermost byte with one for each interface, so as to occupy less NVMEM. Support this with a per-interface offset so we can encode this in a predictable way for each interface sharing the same NVMEM cell. Signed-off-by: Linus Walleij --- .../devicetree/bindings/net/ethernet-controller.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Documentation/devicetree/bindings/net/ethernet-controller.yaml b/Documentation/devicetree/bindings/net/ethernet-controller.yaml index 45819b2358002bc75e876eddb4b2ca18017c04bd..608f89359ca844e5325e3cc81bd2677b0eccb08a 100644 --- a/Documentation/devicetree/bindings/net/ethernet-controller.yaml +++ b/Documentation/devicetree/bindings/net/ethernet-controller.yaml @@ -53,6 +53,18 @@ properties: nvmem-cell-names: const: mac-address + nvmem-mac-minor-offset: + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 1 + maximum: 255 + description: + When a MAC address for a device with multiple ethernet interface + is stored in non-volatile memory, the address is often offsetted + for different interfaces by increasing the lowermost byte for each + interface subsequent to the first in order to save space in NVMEM. + This property can be used to add that offset when several + interfaces refer to the same NVMEM cell. + phy-connection-type: description: Specifies interface type between the Ethernet device and a physical From patchwork Fri Dec 20 19:17:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13917270 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8ADC3225A5A for ; Fri, 20 Dec 2024 19:17:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734722242; cv=none; b=qW2799NCI200QG+BMxH8NweoS4yIBs+nmO8DGy2FDvQfz4H6NV3Jh6IpuZRtPH1KW0ZVi1K0m3gHr9uz90NdjbdtE4qTCjkix9pgMBH2iVY2MaDQ00w2A/ZJSwKs6/Ic6duftg4J0+HdKyiKjrUQv8WecebvHv9TOJXsXUknpe8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734722242; c=relaxed/simple; bh=mGhlxfT6eF+jcZlW7jmmh2wdkJ3HDICoSvZsMZwFbd0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TekSYLUCnwUKjwHtBfnJtr94ShrpsBEsEyB9GLVoemPQZka2n25ha5Dqo2Y7Imu1m1RWgS8WS4bOXM4sUpFbnbAxnqRJFU/kFxHKJcuRp4M5i72GAK+G7ZIjgjM5iw41A6NzGYcHcAd2Zx1hwsjkTOhFjxMA7uSRWZT5QNFrUWA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=cKkSBBs8; arc=none smtp.client-ip=209.85.208.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="cKkSBBs8" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-5d414b8af7bso4141538a12.0 for ; Fri, 20 Dec 2024 11:17:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1734722238; x=1735327038; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Yb2OFBg5699Qjzh1WbbstXrxCP9eQxyz8l9GfCLKz0E=; b=cKkSBBs8fD6LoZVHsUE1MXMQyp8M6hjeJhlJiJ5Zm6/eYs7CLl4fK1LCkm0yZm6Fqd /s2fNQ4+caNBJlaQzS8TYel0yCm43CiV/qpcYgw/VwwIbtFG0Fa17iFlXPXICLlnrwSM xnah4zpGzWBE45YDn9p8Z+hr7EAmp4HyVTJHLthE/MM0a8DGonXnIO3eImnHot61FzOn N3d3j6gYXfGQO0/0FtnFARDgfHP7YZVEpfGPWsBBploN1dwk6b0oYaQ9MZXeQ3U1uPSj LFxGWNWGDs4A6oq2jSyq2GAEQUKTQyVqGnVGUTuIZchx181ERzkPwFeOb/HZArUYdiCA vn8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734722238; x=1735327038; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Yb2OFBg5699Qjzh1WbbstXrxCP9eQxyz8l9GfCLKz0E=; b=ghYLnjpZYGkruVAVv+1Bji11BfiTnKqq77wyYSmsLBwLvpjmgMZkdAx5CDoj0yaj4A FCLr3wrvJ7XHJ0bY9f/lnYvrz5Mo8MYNKHk/+APBWR5b6pfzZwB1qahbgNelOaNwxJhq VPFo9MQD8idZ33stRK5G59OhzdaHwxkfzeDKY0HA5/GA2WtZss3pqsl2m4w0WunStHJV euADN4ISU+rUsycV92glH1lOKaBfToa6f+79MvS3FnSmbYr8n1017vT3IS3zXzZRQsH0 XVumH0fIalF+SXsIVxb3PCFeMWtNTxJtWK9GRNfxokmC1zwkqncbCSZLugEhQ2YmnuX/ B9Vw== X-Gm-Message-State: AOJu0Yy9Lw2/fyzPux7cSdHW1ViKYoE2gFH9wLEQmCkagTB/4r9ClQhH TcjujLQvVVqjMsSVUizWGIDXsI0VWSHEXzb2z/VsAVPiy2ihYD+IeEETZa+3t8Q= X-Gm-Gg: ASbGncvd6Vok1RdkQmodFtZmG6vMbWz05Z26gBZJKL6WCehtzPUj4jVboihMd836hRZ gyExjSXrJmHw6FjRMpqgk+d07Rc5vLrPqv/VN+NDI9/MLxoj3JXbsczkbSW2/Pq3Kvl6SiHWRDA 0972PePdx9qgnEQbbMFUoEF+YGNu1Wp1DY8cKH3SVteP9+Vgiq8WLrMxsD5q1Xwg6jt7+lt/YOL Q+DUumD4r1SL4s1oBEMLcn0Z0DsE2zAzEJcdxoueQnP2yHlHd8jU5OzjYostCYZmGc= X-Google-Smtp-Source: AGHT+IFAISrFUYFuhFqTWUFjIqqCBrlHPHO2EfxocbLtuEGjlne/qNFOwZx94YXCbT5K77LTeZrxpA== X-Received: by 2002:a05:6402:4402:b0:5d2:60d9:a2a0 with SMTP id 4fb4d7f45d1cf-5d81de5d896mr3637217a12.33.1734722237695; Fri, 20 Dec 2024 11:17:17 -0800 (PST) Received: from [192.168.1.140] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d80679f11dsm1988727a12.46.2024.12.20.11.17.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2024 11:17:16 -0800 (PST) From: Linus Walleij Date: Fri, 20 Dec 2024 20:17:07 +0100 Subject: [PATCH 2/2] net: of: Support adding offset to nvmem MAC addresses Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241220-net-mac-nvmem-offset-v1-2-e9d1da2c1681@linaro.org> References: <20241220-net-mac-nvmem-offset-v1-0-e9d1da2c1681@linaro.org> In-Reply-To: <20241220-net-mac-nvmem-offset-v1-0-e9d1da2c1681@linaro.org> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andrew Lunn , Heiner Kallweit , Russell King , Simon Horman Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.2 X-Patchwork-Delegate: kuba@kernel.org If a lower-byte MAC address offset is encoded into the device tree, make sure to add this to the returned address when looking up a MAC address from NVMEM. Signed-off-by: Linus Walleij --- net/core/of_net.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/net/core/of_net.c b/net/core/of_net.c index 93ea425b9248a23f4f95a336e9cdbf0053248e32..c98000ec13377ea4b541e182a66be8b1010edc40 100644 --- a/net/core/of_net.c +++ b/net/core/of_net.c @@ -64,6 +64,7 @@ int of_get_mac_address_nvmem(struct device_node *np, u8 *addr) struct nvmem_cell *cell; const void *mac; size_t len; + u32 offset; int ret; /* Try lookup by device first, there might be a nvmem_cell_lookup @@ -72,7 +73,7 @@ int of_get_mac_address_nvmem(struct device_node *np, u8 *addr) if (pdev) { ret = nvmem_get_mac_address(&pdev->dev, addr); put_device(&pdev->dev); - return ret; + goto add_offset_exit; } cell = of_nvmem_cell_get(np, "mac-address"); @@ -92,8 +93,13 @@ int of_get_mac_address_nvmem(struct device_node *np, u8 *addr) memcpy(addr, mac, ETH_ALEN); kfree(mac); + ret = 0; - return 0; +add_offset_exit: + if (!ret && !of_property_read_u32(np, "nvmem-mac-minor-offset", &offset)) + addr[ETH_ALEN - 1] += offset; + + return ret; } EXPORT_SYMBOL(of_get_mac_address_nvmem);