1 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
2 Date: Thu, 6 Apr 2023 12:46:16 +0200
3 Subject: [PATCH] nvmem: brcm_nvram: add .read_post_process() for MACs
5 Content-Type: text/plain; charset=UTF-8
6 Content-Transfer-Encoding: 8bit
8 1. Parse ASCII MAC format into byte based
9 2. Calculate relative addresses based on index argument
11 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
13 drivers/nvmem/Kconfig | 1 +
14 drivers/nvmem/brcm_nvram.c | 28 ++++++++++++++++++++++++++++
15 2 files changed, 29 insertions(+)
17 --- a/drivers/nvmem/Kconfig
18 +++ b/drivers/nvmem/Kconfig
19 @@ -55,6 +55,7 @@ config NVMEM_BRCM_NVRAM
20 tristate "Broadcom's NVRAM support"
21 depends on ARCH_BCM_5301X || COMPILE_TEST
23 + select GENERIC_NET_UTILS
25 This driver provides support for Broadcom's NVRAM that can be accessed
27 --- a/drivers/nvmem/brcm_nvram.c
28 +++ b/drivers/nvmem/brcm_nvram.c
32 #include <linux/bcm47xx_nvram.h>
33 +#include <linux/etherdevice.h>
34 +#include <linux/if_ether.h>
36 #include <linux/mod_devicetable.h>
37 #include <linux/module.h>
38 @@ -42,6 +44,25 @@ static int brcm_nvram_read(void *context
42 +static int brcm_nvram_read_post_process_macaddr(void *context, const char *id, int index,
43 + unsigned int offset, void *buf, size_t bytes)
47 + if (bytes != 3 * ETH_ALEN - 1)
50 + if (!mac_pton(buf, mac))
54 + eth_addr_add(mac, index);
56 + ether_addr_copy(buf, mac);
61 static int brcm_nvram_add_cells(struct brcm_nvram *priv, uint8_t *data,
64 @@ -75,6 +96,13 @@ static int brcm_nvram_add_cells(struct b
65 priv->cells[idx].offset = value - (char *)data;
66 priv->cells[idx].bytes = strlen(value);
67 priv->cells[idx].np = of_get_child_by_name(dev->of_node, priv->cells[idx].name);
68 + if (!strcmp(var, "et0macaddr") ||
69 + !strcmp(var, "et1macaddr") ||
70 + !strcmp(var, "et2macaddr")) {
71 + priv->cells[idx].raw_len = strlen(value);
72 + priv->cells[idx].bytes = ETH_ALEN;
73 + priv->cells[idx].read_post_process = brcm_nvram_read_post_process_macaddr;