* [PATCH 1/3] dt-bindings: nvmem: brcm,nvram: add #nvmem-cell-cells for MACs
@ 2023-04-06 11:08 Rafał Miłecki
2023-04-06 11:08 ` [PATCH 2/3] nvmem: brcm_nvram: add .read_post_process() " Rafał Miłecki
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Rafał Miłecki @ 2023-04-06 11:08 UTC (permalink / raw)
To: Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla
Cc: Florian Fainelli, Hauke Mehrtens, devicetree, linux-arm-kernel,
bcm-kernel-feedback-list, linux-kernel, Rafał Miłecki
From: Rafał Miłecki <rafal@milecki.pl>
Broadcom's NVRAM contains MACs for Ethernet interfaces. Those MACs are
usually base addresses that are also used for calculating other MACs.
For example if a router vendor decided to use gmac0 it most likely
programmed NVRAM of each unit with a proper "et0macaddr" value. That is
a base.
Ethernet interface is usually connected to switch port. Switch usually
includes few LAN ports and a WAN port. MAC of WAN port gets calculated
as relative address to the interface one. Offset varies depending on
device model.
Wireless MACs may also need to be calculated using relevant offsets.
To support all those scenarios let MAC NVMEM cells be referenced with an
index specifying MAC offset.
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
.../devicetree/bindings/nvmem/brcm,nvram.yaml | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
index 36def7128fca..a921e05cc544 100644
--- a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
+++ b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
@@ -36,14 +36,26 @@ properties:
et0macaddr:
type: object
description: First Ethernet interface's MAC address
+ properties:
+ "#nvmem-cell-cells":
+ description: The first argument is a MAC address offset.
+ const: 1
et1macaddr:
type: object
description: Second Ethernet interface's MAC address
+ properties:
+ "#nvmem-cell-cells":
+ description: The first argument is a MAC address offset.
+ const: 1
et2macaddr:
type: object
description: Third Ethernet interface's MAC address
+ properties:
+ "#nvmem-cell-cells":
+ description: The first argument is a MAC address offset.
+ const: 1
unevaluatedProperties: false
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] nvmem: brcm_nvram: add .read_post_process() for MACs
2023-04-06 11:08 [PATCH 1/3] dt-bindings: nvmem: brcm,nvram: add #nvmem-cell-cells for MACs Rafał Miłecki
@ 2023-04-06 11:08 ` Rafał Miłecki
2023-04-06 11:08 ` [PATCH 3/3] ARM: dts: BCM5301X: Specify WAN port MAC address for Luxul XWR-3150 Rafał Miłecki
2023-04-20 16:01 ` [PATCH 1/3] dt-bindings: nvmem: brcm,nvram: add #nvmem-cell-cells for MACs Rob Herring
2 siblings, 0 replies; 4+ messages in thread
From: Rafał Miłecki @ 2023-04-06 11:08 UTC (permalink / raw)
To: Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla
Cc: Florian Fainelli, Hauke Mehrtens, devicetree, linux-arm-kernel,
bcm-kernel-feedback-list, linux-kernel, Rafał Miłecki
From: Rafał Miłecki <rafal@milecki.pl>
1. Parse ASCII MAC format into byte based
2. Calculate relative addresses based on index argument
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
drivers/nvmem/Kconfig | 1 +
drivers/nvmem/brcm_nvram.c | 28 ++++++++++++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
index b291b27048c7..688b70ba4826 100644
--- a/drivers/nvmem/Kconfig
+++ b/drivers/nvmem/Kconfig
@@ -55,6 +55,7 @@ config NVMEM_BRCM_NVRAM
tristate "Broadcom's NVRAM support"
depends on ARCH_BCM_5301X || COMPILE_TEST
depends on HAS_IOMEM
+ select GENERIC_NET_UTILS
help
This driver provides support for Broadcom's NVRAM that can be accessed
using I/O mapping.
diff --git a/drivers/nvmem/brcm_nvram.c b/drivers/nvmem/brcm_nvram.c
index 39aa27942f28..4567c597c87f 100644
--- a/drivers/nvmem/brcm_nvram.c
+++ b/drivers/nvmem/brcm_nvram.c
@@ -4,6 +4,8 @@
*/
#include <linux/bcm47xx_nvram.h>
+#include <linux/etherdevice.h>
+#include <linux/if_ether.h>
#include <linux/io.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
@@ -42,6 +44,25 @@ static int brcm_nvram_read(void *context, unsigned int offset, void *val,
return 0;
}
+static int brcm_nvram_read_post_process_macaddr(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 brcm_nvram_add_cells(struct brcm_nvram *priv, uint8_t *data,
size_t len)
{
@@ -75,6 +96,13 @@ static int brcm_nvram_add_cells(struct brcm_nvram *priv, uint8_t *data,
priv->cells[idx].offset = value - (char *)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, "et0macaddr") ||
+ !strcmp(var, "et1macaddr") ||
+ !strcmp(var, "et2macaddr")) {
+ priv->cells[idx].raw_len = strlen(value);
+ priv->cells[idx].bytes = ETH_ALEN;
+ priv->cells[idx].read_post_process = brcm_nvram_read_post_process_macaddr;
+ }
}
return 0;
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] ARM: dts: BCM5301X: Specify WAN port MAC address for Luxul XWR-3150
2023-04-06 11:08 [PATCH 1/3] dt-bindings: nvmem: brcm,nvram: add #nvmem-cell-cells for MACs Rafał Miłecki
2023-04-06 11:08 ` [PATCH 2/3] nvmem: brcm_nvram: add .read_post_process() " Rafał Miłecki
@ 2023-04-06 11:08 ` Rafał Miłecki
2023-04-20 16:01 ` [PATCH 1/3] dt-bindings: nvmem: brcm,nvram: add #nvmem-cell-cells for MACs Rob Herring
2 siblings, 0 replies; 4+ messages in thread
From: Rafał Miłecki @ 2023-04-06 11:08 UTC (permalink / raw)
To: Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla
Cc: Florian Fainelli, Hauke Mehrtens, devicetree, linux-arm-kernel,
bcm-kernel-feedback-list, linux-kernel, Rafał Miłecki
From: Rafał Miłecki <rafal@milecki.pl>
It needs to be calculated based on the base Ethernet interface one.
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
This PATCH is a proof of concept that can go separately through the ARM
DT tree. I'd actually suggest that. There are more .dts files I'll want
to update.
Srini: can you just take the first 2 patches from this series?
---
arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts b/arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts
index 60a2c441d5bd..2dd05f4dce92 100644
--- a/arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts
+++ b/arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts
@@ -27,6 +27,7 @@ nvram@1eff0000 {
reg = <0x1eff0000 0x10000>;
et0macaddr: et0macaddr {
+ #nvmem-cell-cells = <1>;
};
};
@@ -76,7 +77,7 @@ button-restart {
};
&gmac0 {
- nvmem-cells = <&et0macaddr>;
+ nvmem-cells = <&et0macaddr 0>;
nvmem-cell-names = "mac-address";
};
@@ -119,6 +120,8 @@ port@3 {
port@4 {
reg = <4>;
label = "wan";
+ nvmem-cells = <&et0macaddr 5>;
+ nvmem-cell-names = "mac-address";
};
port@5 {
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/3] dt-bindings: nvmem: brcm,nvram: add #nvmem-cell-cells for MACs
2023-04-06 11:08 [PATCH 1/3] dt-bindings: nvmem: brcm,nvram: add #nvmem-cell-cells for MACs Rafał Miłecki
2023-04-06 11:08 ` [PATCH 2/3] nvmem: brcm_nvram: add .read_post_process() " Rafał Miłecki
2023-04-06 11:08 ` [PATCH 3/3] ARM: dts: BCM5301X: Specify WAN port MAC address for Luxul XWR-3150 Rafał Miłecki
@ 2023-04-20 16:01 ` Rob Herring
2 siblings, 0 replies; 4+ messages in thread
From: Rob Herring @ 2023-04-20 16:01 UTC (permalink / raw)
To: Rafał Miłecki
Cc: Krzysztof Kozlowski, Srinivas Kandagatla, Florian Fainelli,
Hauke Mehrtens, devicetree, linux-arm-kernel,
bcm-kernel-feedback-list, linux-kernel, Rafał Miłecki
On Thu, Apr 06, 2023 at 01:08:02PM +0200, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
>
> Broadcom's NVRAM contains MACs for Ethernet interfaces. Those MACs are
> usually base addresses that are also used for calculating other MACs.
>
> For example if a router vendor decided to use gmac0 it most likely
> programmed NVRAM of each unit with a proper "et0macaddr" value. That is
> a base.
>
> Ethernet interface is usually connected to switch port. Switch usually
> includes few LAN ports and a WAN port. MAC of WAN port gets calculated
> as relative address to the interface one. Offset varies depending on
> device model.
>
> Wireless MACs may also need to be calculated using relevant offsets.
>
> To support all those scenarios let MAC NVMEM cells be referenced with an
> index specifying MAC offset.
>
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
> ---
> .../devicetree/bindings/nvmem/brcm,nvram.yaml | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
> index 36def7128fca..a921e05cc544 100644
> --- a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
> +++ b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
> @@ -36,14 +36,26 @@ properties:
> et0macaddr:
> type: object
> description: First Ethernet interface's MAC address
> + properties:
> + "#nvmem-cell-cells":
> + description: The first argument is a MAC address offset.
> + const: 1
Not a new issue, but these nodes are missing 'additionalProperties:
false'. Can you add that. With that,
Reviewed-by: Rob Herring <robh@kernel.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-04-20 16:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-06 11:08 [PATCH 1/3] dt-bindings: nvmem: brcm,nvram: add #nvmem-cell-cells for MACs Rafał Miłecki
2023-04-06 11:08 ` [PATCH 2/3] nvmem: brcm_nvram: add .read_post_process() " Rafał Miłecki
2023-04-06 11:08 ` [PATCH 3/3] ARM: dts: BCM5301X: Specify WAN port MAC address for Luxul XWR-3150 Rafał Miłecki
2023-04-20 16:01 ` [PATCH 1/3] dt-bindings: nvmem: brcm,nvram: add #nvmem-cell-cells for MACs Rob Herring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).