421-MIPS-BCM63XX-move-nvram-related-functions-into-their.patch 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. From 5b753c1d01c6af23d7d37d37d9de30da8a971084 Mon Sep 17 00:00:00 2001
  2. From: Jonas Gorski <[email protected]>
  3. Date: Sat, 12 May 2012 22:51:08 +0200
  4. Subject: [PATCH 60/79] MIPS: BCM63XX: move nvram related functions into their
  5. own file
  6. Signed-off-by: Jonas Gorski <[email protected]>
  7. ---
  8. arch/mips/bcm63xx/Makefile | 6 +-
  9. arch/mips/bcm63xx/boards/board_bcm963xx.c | 74 +++--------------
  10. arch/mips/bcm63xx/nvram.c | 84 ++++++++++++++++++++
  11. arch/mips/include/asm/mach-bcm63xx/bcm63xx_nvram.h | 34 ++++++++
  12. .../mips/include/asm/mach-bcm63xx/board_bcm963xx.h | 17 ----
  13. 5 files changed, 134 insertions(+), 81 deletions(-)
  14. create mode 100644 arch/mips/bcm63xx/nvram.c
  15. create mode 100644 arch/mips/include/asm/mach-bcm63xx/bcm63xx_nvram.h
  16. --- a/arch/mips/bcm63xx/Makefile
  17. +++ b/arch/mips/bcm63xx/Makefile
  18. @@ -1,6 +1,6 @@
  19. -obj-y += clk.o cpu.o cs.o gpio.o irq.o prom.o setup.o timer.o \
  20. - dev-dsp.o dev-enet.o dev-flash.o dev-hsspi.o dev-pcmcia.o \
  21. - dev-spi.o dev-trng.o dev-uart.o dev-usb-ehci.o \
  22. +obj-y += clk.o cpu.o cs.o gpio.o irq.o nvram.o prom.o setup.o \
  23. + timer.o dev-dsp.o dev-enet.o dev-flash.o dev-hsspi.o \
  24. + dev-pcmcia.o dev-spi.o dev-trng.o dev-uart.o dev-usb-ehci.o \
  25. dev-usb-ohci.o dev-wdt.o
  26. obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
  27. --- a/arch/mips/bcm63xx/boards/board_bcm963xx.c
  28. +++ b/arch/mips/bcm63xx/boards/board_bcm963xx.c
  29. @@ -21,6 +21,7 @@
  30. #include <bcm63xx_dev_uart.h>
  31. #include <bcm63xx_regs.h>
  32. #include <bcm63xx_io.h>
  33. +#include <bcm63xx_nvram.h>
  34. #include <bcm63xx_dev_pci.h>
  35. #include <bcm63xx_dev_enet.h>
  36. #include <bcm63xx_dev_dsp.h>
  37. @@ -41,8 +42,6 @@
  38. #define CFE_OFFSET_64K 0x10000
  39. #define CFE_OFFSET_128K 0x20000
  40. -static struct bcm963xx_nvram nvram;
  41. -static unsigned int mac_addr_used;
  42. static struct board_info board;
  43. /*
  44. @@ -696,50 +695,16 @@ const char *board_get_name(void)
  45. return board.name;
  46. }
  47. -/*
  48. - * register & return a new board mac address
  49. - */
  50. -static int board_get_mac_address(u8 *mac)
  51. -{
  52. - u8 *p;
  53. - int count;
  54. -
  55. - if (mac_addr_used >= nvram.mac_addr_count) {
  56. - printk(KERN_ERR PFX "not enough mac address\n");
  57. - return -ENODEV;
  58. - }
  59. -
  60. - memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
  61. - p = mac + ETH_ALEN - 1;
  62. - count = mac_addr_used;
  63. -
  64. - while (count--) {
  65. - do {
  66. - (*p)++;
  67. - if (*p != 0)
  68. - break;
  69. - p--;
  70. - } while (p != mac);
  71. - }
  72. -
  73. - if (p == mac) {
  74. - printk(KERN_ERR PFX "unable to fetch mac address\n");
  75. - return -ENODEV;
  76. - }
  77. -
  78. - mac_addr_used++;
  79. - return 0;
  80. -}
  81. -
  82. static void __init boardid_fixup(u8 *boot_addr)
  83. {
  84. struct bcm_tag *tag = (struct bcm_tag *)(boot_addr + CFE_OFFSET_64K);
  85. + char *board_name = (char *)bcm63xx_nvram_get_name();
  86. /* check if bcm_tag is at 64k offset */
  87. - if (strncmp(nvram.name, tag->boardid, BOARDID_LEN) != 0) {
  88. + if (strncmp(board_name, tag->boardid, BOARDID_LEN) != 0) {
  89. /* else try 128k */
  90. tag = (struct bcm_tag *)(boot_addr + CFE_OFFSET_128K);
  91. - if (strncmp(nvram.name, tag->boardid, BOARDID_LEN) != 0) {
  92. + if (strncmp(board_name, tag->boardid, BOARDID_LEN) != 0) {
  93. /* No tag found */
  94. printk(KERN_DEBUG "No bcm_tag found!\n");
  95. return;
  96. @@ -749,9 +714,9 @@ static void __init boardid_fixup(u8 *boo
  97. if (tag->information1[0] != '+')
  98. return;
  99. - strncpy(nvram.name, &tag->information1[1], BOARDID_LEN);
  100. + strncpy(board_name, &tag->information1[1], BOARDID_LEN);
  101. - printk(KERN_INFO "Overriding boardid with '%s'\n", nvram.name);
  102. + printk(KERN_INFO "Overriding boardid with '%s'\n", board_name);
  103. }
  104. /*
  105. @@ -759,9 +724,10 @@ static void __init boardid_fixup(u8 *boo
  106. */
  107. void __init board_prom_init(void)
  108. {
  109. - unsigned int check_len, i;
  110. - u8 *boot_addr, *cfe, *p;
  111. + unsigned int i;
  112. + u8 *boot_addr, *cfe;
  113. char cfe_version[32];
  114. + char *board_name;
  115. u32 val;
  116. /* read base address of boot chip select (0)
  117. @@ -783,32 +749,19 @@ void __init board_prom_init(void)
  118. strcpy(cfe_version, "unknown");
  119. printk(KERN_INFO PFX "CFE version: %s\n", cfe_version);
  120. - /* extract nvram data */
  121. - memcpy(&nvram, boot_addr + BCM963XX_NVRAM_OFFSET, sizeof(nvram));
  122. -
  123. - /* check checksum before using data */
  124. - if (nvram.version <= 4)
  125. - check_len = offsetof(struct bcm963xx_nvram, checksum_old);
  126. - else
  127. - check_len = sizeof(nvram);
  128. - val = 0;
  129. - p = (u8 *)&nvram;
  130. - while (check_len--)
  131. - val += *p;
  132. - if (val) {
  133. - printk(KERN_ERR PFX "invalid nvram checksum\n");
  134. + if (bcm63xx_nvram_init(boot_addr + BCM963XX_NVRAM_OFFSET))
  135. return;
  136. - }
  137. if (strcmp(cfe_version, "unknown") != 0) {
  138. /* cfe present */
  139. boardid_fixup(boot_addr);
  140. }
  141. + board_name = bcm63xx_nvram_get_name();
  142. /* find board by name */
  143. for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) {
  144. - if (strncmp(nvram.name, bcm963xx_boards[i]->name,
  145. - sizeof(nvram.name)))
  146. + if (strncmp(board_name, bcm963xx_boards[i]->name,
  147. + BCM63XX_NVRAM_NAMELEN))
  148. continue;
  149. /* copy, board desc array is marked initdata */
  150. memcpy(&board, bcm963xx_boards[i], sizeof(board));
  151. @@ -818,7 +771,7 @@ void __init board_prom_init(void)
  152. /* bail out if board is not found, will complain later */
  153. if (!board.name[0]) {
  154. char name[17];
  155. - memcpy(name, nvram.name, 16);
  156. + memcpy(name, board_name, 16);
  157. name[16] = 0;
  158. printk(KERN_ERR PFX "unknown bcm963xx board: %s\n",
  159. name);
  160. @@ -910,15 +863,15 @@ int __init board_register_devices(void)
  161. bcm63xx_pcmcia_register();
  162. if (board.has_enet0 &&
  163. - !board_get_mac_address(board.enet0.mac_addr))
  164. + !bcm63xx_nvram_get_mac_address(board.enet0.mac_addr))
  165. bcm63xx_enet_register(0, &board.enet0);
  166. if (board.has_enet1 &&
  167. - !board_get_mac_address(board.enet1.mac_addr))
  168. + !bcm63xx_nvram_get_mac_address(board.enet1.mac_addr))
  169. bcm63xx_enet_register(1, &board.enet1);
  170. if (board.has_enetsw &&
  171. - !board_get_mac_address(board.enetsw.mac_addr))
  172. + !bcm63xx_nvram_get_mac_address(board.enetsw.mac_addr))
  173. bcm63xx_enetsw_register(&board.enetsw);
  174. if (board.has_ehci0)
  175. @@ -934,7 +887,7 @@ int __init board_register_devices(void)
  176. * do this after registering enet devices
  177. */
  178. #ifdef CONFIG_SSB_PCIHOST
  179. - if (!board_get_mac_address(bcm63xx_sprom.il0mac)) {
  180. + if (!bcm63xx_nvram_get_mac_address(bcm63xx_sprom.il0mac)) {
  181. memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN);
  182. memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN);
  183. if (ssb_arch_register_fallback_sprom(
  184. --- /dev/null
  185. +++ b/arch/mips/bcm63xx/nvram.c
  186. @@ -0,0 +1,84 @@
  187. +/*
  188. + * This file is subject to the terms and conditions of the GNU General Public
  189. + * License. See the file "COPYING" in the main directory of this archive
  190. + * for more details.
  191. + *
  192. + * Copyright (C) 2012 Jonas Gorski <[email protected]>
  193. + */
  194. +
  195. +#define pr_fmt(fmt) "bcm63xx_nvram: " fmt
  196. +
  197. +#include <linux/init.h>
  198. +#include <linux/export.h>
  199. +#include <linux/kernel.h>
  200. +
  201. +#include <bcm63xx_nvram.h>
  202. +
  203. +static struct bcm963xx_nvram nvram;
  204. +static int mac_addr_used;
  205. +
  206. +int __init bcm63xx_nvram_init(void *addr)
  207. +{
  208. + unsigned int check_len;
  209. + u8 *p;
  210. + u32 val;
  211. +
  212. + /* extract nvram data */
  213. + memcpy(&nvram, addr, sizeof(nvram));
  214. +
  215. + /* check checksum before using data */
  216. + if (nvram.version <= 4)
  217. + check_len = offsetof(struct bcm963xx_nvram, checksum_old);
  218. + else
  219. + check_len = sizeof(nvram);
  220. + val = 0;
  221. + p = (u8 *)&nvram;
  222. +
  223. + while (check_len--)
  224. + val += *p;
  225. + if (val) {
  226. + pr_err("invalid nvram checksum\n");
  227. + return -EINVAL;
  228. + }
  229. +
  230. + return 0;
  231. +}
  232. +
  233. +u8 *bcm63xx_nvram_get_name(void)
  234. +{
  235. + return nvram.name;
  236. +}
  237. +EXPORT_SYMBOL(bcm63xx_nvram_get_name);
  238. +
  239. +int bcm63xx_nvram_get_mac_address(u8 *mac)
  240. +{
  241. + u8 *p;
  242. + int count;
  243. +
  244. + if (mac_addr_used >= nvram.mac_addr_count) {
  245. + pr_err("not enough mac address\n");
  246. + return -ENODEV;
  247. + }
  248. +
  249. + memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
  250. + p = mac + ETH_ALEN - 1;
  251. + count = mac_addr_used;
  252. +
  253. + while (count--) {
  254. + do {
  255. + (*p)++;
  256. + if (*p != 0)
  257. + break;
  258. + p--;
  259. + } while (p != mac);
  260. + }
  261. +
  262. + if (p == mac) {
  263. + pr_err("unable to fetch mac address\n");
  264. + return -ENODEV;
  265. + }
  266. +
  267. + mac_addr_used++;
  268. + return 0;
  269. +}
  270. +EXPORT_SYMBOL(bcm63xx_nvram_get_mac_address);
  271. --- /dev/null
  272. +++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_nvram.h
  273. @@ -0,0 +1,34 @@
  274. +#ifndef BCM63XX_NVRAM_H
  275. +#define BCM63XX_NVRAM_H
  276. +
  277. +#include <linux/if_ether.h>
  278. +
  279. +#define BCM63XX_NVRAM_NAMELEN 16
  280. +
  281. +/*
  282. + * nvram structure
  283. + */
  284. +struct bcm963xx_nvram {
  285. + u32 version;
  286. + u8 reserved1[256];
  287. + u8 name[BCM63XX_NVRAM_NAMELEN];
  288. + u32 main_tp_number;
  289. + u32 psi_size;
  290. + u32 mac_addr_count;
  291. + u8 mac_addr_base[ETH_ALEN];
  292. + u8 reserved2[2];
  293. + u32 checksum_old;
  294. + u8 reserved3[720];
  295. + u32 checksum_high;
  296. +};
  297. +
  298. +int __init bcm63xx_nvram_init(void *);
  299. +
  300. +u8 *bcm63xx_nvram_get_name(void);
  301. +
  302. +/*
  303. + * register & return a new board mac address
  304. + */
  305. +int bcm63xx_nvram_get_mac_address(u8 *mac);
  306. +
  307. +#endif /* BCM63XX_NVRAM_H */
  308. --- a/arch/mips/include/asm/mach-bcm63xx/board_bcm963xx.h
  309. +++ b/arch/mips/include/asm/mach-bcm63xx/board_bcm963xx.h
  310. @@ -15,23 +15,6 @@
  311. #define BCM963XX_NVRAM_OFFSET 0x580
  312. /*
  313. - * nvram structure
  314. - */
  315. -struct bcm963xx_nvram {
  316. - u32 version;
  317. - u8 reserved1[256];
  318. - u8 name[16];
  319. - u32 main_tp_number;
  320. - u32 psi_size;
  321. - u32 mac_addr_count;
  322. - u8 mac_addr_base[6];
  323. - u8 reserved2[2];
  324. - u32 checksum_old;
  325. - u8 reserved3[720];
  326. - u32 checksum_high;
  327. -};
  328. -
  329. -/*
  330. * board definition
  331. */
  332. struct board_info {