711ec28f52984d043a574ce2b4db6d7de00add2b
[openwrt/openwrt.git] / target / linux / generic / backport-5.10 / 800-v5.13-0001-firmware-bcm47xx_nvram-rename-finding-function-and-i.patch
1 From fb009cbdd0693bd633f11e99526617b3d392cfad Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Mon, 8 Mar 2021 10:03:16 +0100
4 Subject: [PATCH] firmware: bcm47xx_nvram: rename finding function and its
5 variables
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 1. Use "bcm47xx_" function name prefix for consistency
11 2. It takes flash start as argument so s/iobase/flash_start/
12 3. "off" was used for finding flash end so just call it "flash_size"
13
14 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
15 Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
16 ---
17 drivers/firmware/broadcom/bcm47xx_nvram.c | 24 ++++++++++++-----------
18 1 file changed, 13 insertions(+), 11 deletions(-)
19
20 diff --git a/drivers/firmware/broadcom/bcm47xx_nvram.c b/drivers/firmware/broadcom/bcm47xx_nvram.c
21 index 835ece9c00f1..b04007adc79f 100644
22 --- a/drivers/firmware/broadcom/bcm47xx_nvram.c
23 +++ b/drivers/firmware/broadcom/bcm47xx_nvram.c
24 @@ -48,11 +48,13 @@ static u32 find_nvram_size(void __iomem *end)
25 return 0;
26 }
27
28 -/* Probe for NVRAM header */
29 -static int nvram_find_and_copy(void __iomem *iobase, u32 lim)
30 +/**
31 + * bcm47xx_nvram_find_and_copy - find NVRAM on flash mapping & copy it
32 + */
33 +static int bcm47xx_nvram_find_and_copy(void __iomem *flash_start, size_t res_size)
34 {
35 struct nvram_header __iomem *header;
36 - u32 off;
37 + size_t flash_size;
38 u32 size;
39
40 if (nvram_len) {
41 @@ -61,25 +63,25 @@ static int nvram_find_and_copy(void __iomem *iobase, u32 lim)
42 }
43
44 /* TODO: when nvram is on nand flash check for bad blocks first. */
45 - off = FLASH_MIN;
46 - while (off <= lim) {
47 + flash_size = FLASH_MIN;
48 + while (flash_size <= res_size) {
49 /* Windowed flash access */
50 - size = find_nvram_size(iobase + off);
51 + size = find_nvram_size(flash_start + flash_size);
52 if (size) {
53 - header = (struct nvram_header *)(iobase + off - size);
54 + header = (struct nvram_header *)(flash_start + flash_size - size);
55 goto found;
56 }
57 - off <<= 1;
58 + flash_size <<= 1;
59 }
60
61 /* Try embedded NVRAM at 4 KB and 1 KB as last resorts */
62 - header = (struct nvram_header *)(iobase + 4096);
63 + header = (struct nvram_header *)(flash_start + 4096);
64 if (header->magic == NVRAM_MAGIC) {
65 size = NVRAM_SPACE;
66 goto found;
67 }
68
69 - header = (struct nvram_header *)(iobase + 1024);
70 + header = (struct nvram_header *)(flash_start + 1024);
71 if (header->magic == NVRAM_MAGIC) {
72 size = NVRAM_SPACE;
73 goto found;
74 @@ -124,7 +126,7 @@ int bcm47xx_nvram_init_from_mem(u32 base, u32 lim)
75 if (!iobase)
76 return -ENOMEM;
77
78 - err = nvram_find_and_copy(iobase, lim);
79 + err = bcm47xx_nvram_find_and_copy(iobase, lim);
80
81 iounmap(iobase);
82
83 --
84 2.26.2
85