fb4d346a95add1eb21066000a7470fb8b3f0bc70
[openwrt/staging/thess.git] /
1 From 73bcd133c910bff3b6d3b3834d0d14be9444e90a Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Sun, 11 Jun 2023 15:03:08 +0100
4 Subject: [PATCH] nvmem: brcm_nvram: add .read_post_process() for MACs
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 1. Parse ASCII MAC format into byte based
10 2. Calculate relative addresses based on index argument
11
12 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
13 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
14 Message-ID: <20230611140330.154222-5-srinivas.kandagatla@linaro.org>
15 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
16 ---
17 drivers/nvmem/Kconfig | 1 +
18 drivers/nvmem/brcm_nvram.c | 28 ++++++++++++++++++++++++++++
19 2 files changed, 29 insertions(+)
20
21 --- a/drivers/nvmem/Kconfig
22 +++ b/drivers/nvmem/Kconfig
23 @@ -55,6 +55,7 @@ config NVMEM_BRCM_NVRAM
24 tristate "Broadcom's NVRAM support"
25 depends on ARCH_BCM_5301X || COMPILE_TEST
26 depends on HAS_IOMEM
27 + select GENERIC_NET_UTILS
28 help
29 This driver provides support for Broadcom's NVRAM that can be accessed
30 using I/O mapping.
31 --- a/drivers/nvmem/brcm_nvram.c
32 +++ b/drivers/nvmem/brcm_nvram.c
33 @@ -4,6 +4,8 @@
34 */
35
36 #include <linux/bcm47xx_nvram.h>
37 +#include <linux/etherdevice.h>
38 +#include <linux/if_ether.h>
39 #include <linux/io.h>
40 #include <linux/mod_devicetable.h>
41 #include <linux/module.h>
42 @@ -42,6 +44,25 @@ static int brcm_nvram_read(void *context
43 return 0;
44 }
45
46 +static int brcm_nvram_read_post_process_macaddr(void *context, const char *id, int index,
47 + unsigned int offset, void *buf, size_t bytes)
48 +{
49 + u8 mac[ETH_ALEN];
50 +
51 + if (bytes != 3 * ETH_ALEN - 1)
52 + return -EINVAL;
53 +
54 + if (!mac_pton(buf, mac))
55 + return -EINVAL;
56 +
57 + if (index)
58 + eth_addr_add(mac, index);
59 +
60 + ether_addr_copy(buf, mac);
61 +
62 + return 0;
63 +}
64 +
65 static int brcm_nvram_add_cells(struct brcm_nvram *priv, uint8_t *data,
66 size_t len)
67 {
68 @@ -75,6 +96,13 @@ static int brcm_nvram_add_cells(struct b
69 priv->cells[idx].offset = value - (char *)data;
70 priv->cells[idx].bytes = strlen(value);
71 priv->cells[idx].np = of_get_child_by_name(dev->of_node, priv->cells[idx].name);
72 + if (!strcmp(var, "et0macaddr") ||
73 + !strcmp(var, "et1macaddr") ||
74 + !strcmp(var, "et2macaddr")) {
75 + priv->cells[idx].raw_len = strlen(value);
76 + priv->cells[idx].bytes = ETH_ALEN;
77 + priv->cells[idx].read_post_process = brcm_nvram_read_post_process_macaddr;
78 + }
79 }
80
81 return 0;