kernel: bump 5.15 to 5.15.116
[openwrt/openwrt.git] / target / linux / generic / backport-5.15 / 813-v6.5-nvmem-brcm_nvram-add-.read_post_process-for-MACs.patch
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
4 MIME-Version: 1.0
5 Content-Type: text/plain; charset=UTF-8
6 Content-Transfer-Encoding: 8bit
7
8 1. Parse ASCII MAC format into byte based
9 2. Calculate relative addresses based on index argument
10
11 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
12 ---
13 drivers/nvmem/Kconfig | 1 +
14 drivers/nvmem/brcm_nvram.c | 28 ++++++++++++++++++++++++++++
15 2 files changed, 29 insertions(+)
16
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
22 depends on HAS_IOMEM
23 + select GENERIC_NET_UTILS
24 help
25 This driver provides support for Broadcom's NVRAM that can be accessed
26 using I/O mapping.
27 --- a/drivers/nvmem/brcm_nvram.c
28 +++ b/drivers/nvmem/brcm_nvram.c
29 @@ -4,6 +4,8 @@
30 */
31
32 #include <linux/bcm47xx_nvram.h>
33 +#include <linux/etherdevice.h>
34 +#include <linux/if_ether.h>
35 #include <linux/io.h>
36 #include <linux/mod_devicetable.h>
37 #include <linux/module.h>
38 @@ -42,6 +44,25 @@ static int brcm_nvram_read(void *context
39 return 0;
40 }
41
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)
44 +{
45 + u8 mac[ETH_ALEN];
46 +
47 + if (bytes != 3 * ETH_ALEN - 1)
48 + return -EINVAL;
49 +
50 + if (!mac_pton(buf, mac))
51 + return -EINVAL;
52 +
53 + if (index)
54 + eth_addr_add(mac, index);
55 +
56 + ether_addr_copy(buf, mac);
57 +
58 + return 0;
59 +}
60 +
61 static int brcm_nvram_add_cells(struct brcm_nvram *priv, uint8_t *data,
62 size_t len)
63 {
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;
74 + }
75 }
76
77 return 0;