kernel: add md5sum for 3.9 final
[oweals/openwrt.git] / target / linux / brcm63xx / patches-3.7 / 004-MIPS-BCM63XX-move-nvram-functions-into-their-own-fil.patch
1 From a4304adb62af528957ed8858c9eb4f2630abe6d7 Mon Sep 17 00:00:00 2001
2 From: Jonas Gorski <jonas.gorski@gmail.com>
3 Date: Sat, 12 May 2012 22:51:08 +0200
4 Subject: [PATCH] MIPS: BCM63XX: move nvram functions into their own file
5
6 Refactor nvram related functions into its own unit for easier expansion
7 and exposure of the values to other drivers.
8
9 Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
10 ---
11
12 This patch depends on the previous reset helper patch series or the
13 Makefile change needs to be merged manually. It has no real functional
14 dependencies.
15
16  arch/mips/bcm63xx/Makefile                         |    7 +-
17  arch/mips/bcm63xx/boards/board_bcm963xx.c          |   71 ++-----------
18  arch/mips/bcm63xx/nvram.c                          |  104 ++++++++++++++++++++
19  arch/mips/include/asm/mach-bcm63xx/bcm63xx_nvram.h |   35 +++++++
20  .../mips/include/asm/mach-bcm63xx/board_bcm963xx.h |   17 ---
21  5 files changed, 154 insertions(+), 80 deletions(-)
22  create mode 100644 arch/mips/bcm63xx/nvram.c
23  create mode 100644 arch/mips/include/asm/mach-bcm63xx/bcm63xx_nvram.h
24
25 --- a/arch/mips/bcm63xx/Makefile
26 +++ b/arch/mips/bcm63xx/Makefile
27 @@ -1,6 +1,7 @@
28 -obj-y          += clk.o cpu.o cs.o gpio.o irq.o prom.o reset.o setup.o \
29 -                  timer.o dev-dsp.o dev-enet.o dev-flash.o dev-pcmcia.o \
30 -                  dev-rng.o dev-spi.o dev-uart.o dev-wdt.o dev-usb-usbd.o
31 +obj-y          += clk.o cpu.o cs.o gpio.o irq.o nvram.o prom.o reset.o \
32 +                  setup.o timer.o dev-dsp.o dev-enet.o dev-flash.o \
33 +                  dev-pcmcia.o dev-rng.o dev-spi.o dev-uart.o dev-wdt.o \
34 +                  dev-usb-usbd.o
35  obj-$(CONFIG_EARLY_PRINTK)     += early_printk.o
36  
37  obj-y          += boards/
38 --- a/arch/mips/bcm63xx/boards/board_bcm963xx.c
39 +++ b/arch/mips/bcm63xx/boards/board_bcm963xx.c
40 @@ -18,6 +18,7 @@
41  #include <bcm63xx_dev_uart.h>
42  #include <bcm63xx_regs.h>
43  #include <bcm63xx_io.h>
44 +#include <bcm63xx_nvram.h>
45  #include <bcm63xx_dev_pci.h>
46  #include <bcm63xx_dev_enet.h>
47  #include <bcm63xx_dev_dsp.h>
48 @@ -29,8 +30,6 @@
49  
50  #define PFX    "board_bcm963xx: "
51  
52 -static struct bcm963xx_nvram nvram;
53 -static unsigned int mac_addr_used;
54  static struct board_info board;
55  
56  /*
57 @@ -716,50 +715,14 @@ const char *board_get_name(void)
58  }
59  
60  /*
61 - * register & return a new board mac address
62 - */
63 -static int board_get_mac_address(u8 *mac)
64 -{
65 -       u8 *oui;
66 -       int count;
67 -
68 -       if (mac_addr_used >= nvram.mac_addr_count) {
69 -               printk(KERN_ERR PFX "not enough mac address\n");
70 -               return -ENODEV;
71 -       }
72 -
73 -       memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
74 -       oui = mac + ETH_ALEN/2 - 1;
75 -       count = mac_addr_used;
76 -
77 -       while (count--) {
78 -               u8 *p = mac + ETH_ALEN - 1;
79 -
80 -               do {
81 -                       (*p)++;
82 -                       if (*p != 0)
83 -                               break;
84 -                       p--;
85 -               } while (p != oui);
86 -
87 -               if (p == oui) {
88 -                       printk(KERN_ERR PFX "unable to fetch mac address\n");
89 -                       return -ENODEV;
90 -               }
91 -       }
92 -
93 -       mac_addr_used++;
94 -       return 0;
95 -}
96 -
97 -/*
98   * early init callback, read nvram data from flash and checksum it
99   */
100  void __init board_prom_init(void)
101  {
102 -       unsigned int check_len, i;
103 -       u8 *boot_addr, *cfe, *p;
104 +       unsigned int i;
105 +       u8 *boot_addr, *cfe;
106         char cfe_version[32];
107 +       char *board_name;
108         u32 val;
109  
110         /* read base address of boot chip select (0)
111 @@ -782,27 +745,15 @@ void __init board_prom_init(void)
112                 strcpy(cfe_version, "unknown");
113         printk(KERN_INFO PFX "CFE version: %s\n", cfe_version);
114  
115 -       /* extract nvram data */
116 -       memcpy(&nvram, boot_addr + BCM963XX_NVRAM_OFFSET, sizeof(nvram));
117 -
118 -       /* check checksum before using data */
119 -       if (nvram.version <= 4)
120 -               check_len = offsetof(struct bcm963xx_nvram, checksum_old);
121 -       else
122 -               check_len = sizeof(nvram);
123 -       val = 0;
124 -       p = (u8 *)&nvram;
125 -       while (check_len--)
126 -               val += *p;
127 -       if (val) {
128 +       if (bcm63xx_nvram_init(boot_addr + BCM963XX_NVRAM_OFFSET)) {
129                 printk(KERN_ERR PFX "invalid nvram checksum\n");
130                 return;
131         }
132  
133 +       board_name = bcm63xx_nvram_get_name();
134         /* find board by name */
135         for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) {
136 -               if (strncmp(nvram.name, bcm963xx_boards[i]->name,
137 -                           sizeof(nvram.name)))
138 +               if (strncmp(board_name, bcm963xx_boards[i]->name, 16))
139                         continue;
140                 /* copy, board desc array is marked initdata */
141                 memcpy(&board, bcm963xx_boards[i], sizeof(board));
142 @@ -812,7 +763,7 @@ void __init board_prom_init(void)
143         /* bail out if board is not found, will complain later */
144         if (!board.name[0]) {
145                 char name[17];
146 -               memcpy(name, nvram.name, 16);
147 +               memcpy(name, board_name, 16);
148                 name[16] = 0;
149                 printk(KERN_ERR PFX "unknown bcm963xx board: %s\n",
150                        name);
151 @@ -890,11 +841,11 @@ int __init board_register_devices(void)
152                 bcm63xx_pcmcia_register();
153  
154         if (board.has_enet0 &&
155 -           !board_get_mac_address(board.enet0.mac_addr))
156 +           !bcm63xx_nvram_get_mac_address(board.enet0.mac_addr))
157                 bcm63xx_enet_register(0, &board.enet0);
158  
159         if (board.has_enet1 &&
160 -           !board_get_mac_address(board.enet1.mac_addr))
161 +           !bcm63xx_nvram_get_mac_address(board.enet1.mac_addr))
162                 bcm63xx_enet_register(1, &board.enet1);
163  
164         if (board.has_usbd)
165 @@ -907,7 +858,7 @@ int __init board_register_devices(void)
166          * do this after registering enet devices
167          */
168  #ifdef CONFIG_SSB_PCIHOST
169 -       if (!board_get_mac_address(bcm63xx_sprom.il0mac)) {
170 +       if (!bcm63xx_nvram_get_mac_address(bcm63xx_sprom.il0mac)) {
171                 memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN);
172                 memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN);
173                 if (ssb_arch_register_fallback_sprom(
174 --- /dev/null
175 +++ b/arch/mips/bcm63xx/nvram.c
176 @@ -0,0 +1,104 @@
177 +/*
178 + * This file is subject to the terms and conditions of the GNU General Public
179 + * License.  See the file "COPYING" in the main directory of this archive
180 + * for more details.
181 + *
182 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
183 + * Copyright (C) 2008 Florian Fainelli <florian@openwrt.org>
184 + * Copyright (C) 2012 Jonas Gorski <jonas.gorski@gmail.com>
185 + */
186 +
187 +#define pr_fmt(fmt) "bcm63xx_nvram: " fmt
188 +
189 +#include <linux/init.h>
190 +#include <linux/export.h>
191 +#include <linux/kernel.h>
192 +#include <linux/if_ether.h>
193 +
194 +#include <bcm63xx_nvram.h>
195 +
196 +/*
197 + * nvram structure
198 + */
199 +struct bcm963xx_nvram {
200 +       u32     version;
201 +       u8      reserved1[256];
202 +       u8      name[16];
203 +       u32     main_tp_number;
204 +       u32     psi_size;
205 +       u32     mac_addr_count;
206 +       u8      mac_addr_base[ETH_ALEN];
207 +       u8      reserved2[2];
208 +       u32     checksum_old;
209 +       u8      reserved3[720];
210 +       u32     checksum_high;
211 +};
212 +
213 +static struct bcm963xx_nvram nvram;
214 +static int mac_addr_used;
215 +
216 +int __init bcm63xx_nvram_init(void *addr)
217 +{
218 +       unsigned int check_len;
219 +       u8 *p;
220 +       u32 val;
221 +
222 +       /* extract nvram data */
223 +       memcpy(&nvram, addr, sizeof(nvram));
224 +
225 +       /* check checksum before using data */
226 +       if (nvram.version <= 4)
227 +               check_len = offsetof(struct bcm963xx_nvram, checksum_old);
228 +       else
229 +               check_len = sizeof(nvram);
230 +       val = 0;
231 +       p = (u8 *)&nvram;
232 +
233 +       while (check_len--)
234 +               val += *p;
235 +       if (val)
236 +               return -EINVAL;
237 +
238 +       return 0;
239 +}
240 +
241 +u8 *bcm63xx_nvram_get_name(void)
242 +{
243 +       return nvram.name;
244 +}
245 +EXPORT_SYMBOL(bcm63xx_nvram_get_name);
246 +
247 +int bcm63xx_nvram_get_mac_address(u8 *mac)
248 +{
249 +       u8 *oui;
250 +       int count;
251 +
252 +       if (mac_addr_used >= nvram.mac_addr_count) {
253 +               pr_err("not enough mac addresses\n");
254 +               return -ENODEV;
255 +       }
256 +
257 +       memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
258 +       oui = mac + ETH_ALEN/2 - 1;
259 +       count = mac_addr_used;
260 +
261 +       while (count--) {
262 +               u8 *p = mac + ETH_ALEN - 1;
263 +
264 +               do {
265 +                       (*p)++;
266 +                       if (*p != 0)
267 +                               break;
268 +                       p--;
269 +               } while (p != oui);
270 +
271 +               if (p == oui) {
272 +                       pr_err("unable to fetch mac address\n");
273 +                       return -ENODEV;
274 +               }
275 +       }
276 +
277 +       mac_addr_used++;
278 +       return 0;
279 +}
280 +EXPORT_SYMBOL(bcm63xx_nvram_get_mac_address);
281 --- /dev/null
282 +++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_nvram.h
283 @@ -0,0 +1,35 @@
284 +#ifndef BCM63XX_NVRAM_H
285 +#define BCM63XX_NVRAM_H
286 +
287 +#include <linux/types.h>
288 +
289 +/**
290 + * bcm63xx_nvram_init() - initializes nvram
291 + * @nvram:     address of the nvram data
292 + *
293 + * Initialized the local nvram copy from the target address and checks
294 + * its checksum.
295 + *
296 + * Returns 0 on success.
297 + */
298 +int __init bcm63xx_nvram_init(void *nvram);
299 +
300 +/**
301 + * bcm63xx_nvram_get_name() - returns the board name according to nvram
302 + *
303 + * Returns the board name field from nvram. Note that it might not be
304 + * null terminated if it is exactly 16 bytes long.
305 + */
306 +u8 *bcm63xx_nvram_get_name(void);
307 +
308 +/**
309 + * bcm63xx_nvram_get_mac_address() - register & return a new mac address
310 + * @mac:       pointer to array for allocated mac
311 + *
312 + * Registers and returns a mac address from the allocated macs from nvram.
313 + *
314 + * Returns 0 on success.
315 + */
316 +int bcm63xx_nvram_get_mac_address(u8 *mac);
317 +
318 +#endif /* BCM63XX_NVRAM_H */
319 --- a/arch/mips/include/asm/mach-bcm63xx/board_bcm963xx.h
320 +++ b/arch/mips/include/asm/mach-bcm63xx/board_bcm963xx.h
321 @@ -15,23 +15,6 @@
322  #define BCM963XX_NVRAM_OFFSET          0x580
323  
324  /*
325 - * nvram structure
326 - */
327 -struct bcm963xx_nvram {
328 -       u32     version;
329 -       u8      reserved1[256];
330 -       u8      name[16];
331 -       u32     main_tp_number;
332 -       u32     psi_size;
333 -       u32     mac_addr_count;
334 -       u8      mac_addr_base[6];
335 -       u8      reserved2[2];
336 -       u32     checksum_old;
337 -       u8      reserved3[720];
338 -       u32     checksum_high;
339 -};
340 -
341 -/*
342   * board definition
343   */
344  struct board_info {