1 diff -Naupr a/drivers/net/ixp4xx/Kconfig b/drivers/net/ixp4xx/Kconfig
2 --- a/drivers/net/ixp4xx/Kconfig 2007-01-12 21:54:40.000000000 -0700
3 +++ b/drivers/net/ixp4xx/Kconfig 2007-01-12 23:28:50.000000000 -0700
4 @@ -11,6 +11,7 @@ config IXP4XX_NPE
5 tristate "IXP4xx NPE support"
7 depends on NET_ETHERNET
10 The IXP4XX NPE driver supports the 3 CPU co-processors called
11 "Network Processing Engines" (NPE). It adds support fo downloading
12 @@ -18,7 +19,7 @@ config IXP4XX_NPE
13 More about this at: Documentation/networking/ixp4xx/README.
14 You can either use this OR the Intel Access Library (IAL)
16 -config IXP4XX_FW_LOAD
17 +config IXP4XX_NPE_FW_LOAD
18 bool "Use Firmware hotplug for Microcode download"
21 @@ -28,6 +29,13 @@ config IXP4XX_FW_LOAD
22 /usr/lib/hotplug/firmware/NPE-[ABC]
23 see Documentation/firmware_class/hotplug-script
25 +config IXP4XX_NPE_FW_MTD
26 + bool "Load firmware from an mtd partition"
27 + depends on IXP4XX_NPE && MTD_IXP4XX
29 + With this option, the driver will search for
30 + the firmware into an MTD partition.
33 tristate "IXP4xx MAC support"
35 diff -Naupr a/drivers/net/ixp4xx/Makefile b/drivers/net/ixp4xx/Makefile
36 --- a/drivers/net/ixp4xx/Makefile 2007-01-12 21:54:40.000000000 -0700
37 +++ b/drivers/net/ixp4xx/Makefile 2007-01-12 23:28:50.000000000 -0700
39 obj-$(CONFIG_IXP4XX_QMGR) += ixp4xx_qmgr.o
40 obj-$(CONFIG_IXP4XX_NPE) += ixp4xx_npe.o
41 +obj-$(CONFIG_IXP4XX_NPE_FW_MTD) += npe_ucode.o
42 obj-$(CONFIG_IXP4XX_MAC) += ixp4xx_mac.o
43 obj-$(CONFIG_IXP4XX_CRYPTO) += ixp4xx_crypto.o
45 diff -Naupr a/drivers/net/ixp4xx/npe_ucode.c b/drivers/net/ixp4xx/npe_ucode.c
46 --- a/drivers/net/ixp4xx/npe_ucode.c 1969-12-31 17:00:00.000000000 -0700
47 +++ b/drivers/net/ixp4xx/npe_ucode.c 2007-01-12 23:28:50.000000000 -0700
50 + * Provide an NPE platform device for microcode handling
52 + * Copyright (C) 2006 Christian Hohnstaedt <chohnstaedt@innominate.com>
54 + * This file is released under the GPLv2
57 +#include <linux/kernel.h>
58 +#include <linux/platform_device.h>
59 +#include <linux/init.h>
60 +#include <linux/slab.h>
61 +#include <linux/firmware.h>
62 +#include <linux/mtd/mtd.h>
64 +#include <linux/ixp_npe.h>
66 +#define DL_MAGIC 0xfeedf00d
67 +#define DL_MAGIC_SWAP 0x0df0edfe
69 +#define IMG_SIZE(image) (((image)->size * sizeof(u32)) + \
70 + sizeof(struct dl_image))
72 +#define IMG_REV_MAJOR(id) (((id) >> 8) & 0x0f)
73 +#define IMG_REV_MINOR(id) ((id) & 0x0f)
74 +#define IMG_FUNC(id) (((id) >> 16) & 0xff)
75 +#define IMG_NPE(id) (((id) >> 24) & 0x0f)
76 +#define IMG_IXP(id) (((id) >> 28) & 0x0f)
78 +static struct platform_driver ixp4xx_npe_ucode_driver;
79 +static unsigned char *partition_name = NULL;
81 +static void print_image_info(u32 id, u32 offset, u32 size)
84 + const char *names[] = { "IXP425", "IXP465", "unknown" };
86 + idx = IMG_IXP(id) < 2 ? IMG_IXP(id) : 2;
88 + printk(KERN_INFO "npe: found at 0x%x, %s/NPE-%c func: %02x, rev: %x.%x, "
89 + "size: %5d, id: %08x\n", offset, names[idx], IMG_NPE(id) + 'A',
90 + IMG_FUNC(id), IMG_REV_MAJOR(id), IMG_REV_MINOR(id), size, id);
93 +void npe_swap_image(struct dl_image *image)
97 + image->magic = swab32(image->magic);
98 + image->id = swab32(image->id);
99 + image->size = swab32(image->size);
101 + for (i = 0; i < image->size; i++)
102 + image->u.data[i] = swab32(image->u.data[i]);
105 +static void npe_find_microcode(struct mtd_info *mtd)
108 + u32 magic = htonl(DL_MAGIC);
112 + unsigned int offset = 0;
114 + printk("npe: searching for firmware...\n");
116 + while (offset < mtd->size) {
118 + err = mtd->read(mtd, offset, 4, &retlen, (u_char *) &buf);
124 + err = mtd->read(mtd, offset, 4, &retlen, (u_char *) &id);
132 + err = mtd->read(mtd, offset, 4, &retlen, (u_char *) &size);
135 + size = (ntohl(size) * 4) + 12;
137 + print_image_info(id, offset - 12, size);
139 + if (size < 24000 && ( IMG_FUNC(id) == 0x01 || IMG_FUNC(id) == 0x00) ) { // XXX fix size/detection
141 + struct dl_image *image = kmalloc(size, GFP_KERNEL);
143 + /* we are going to load it, rewind offset */
147 + err = mtd->read(mtd, offset, size, &retlen, (u_char *) image);
149 + if (err == 0 && retlen == size) {
150 + if (image->magic == DL_MAGIC_SWAP)
151 + npe_swap_image(image);
153 + store_npe_image(image, NULL);
155 + printk(KERN_ERR "unable to read firmware\n");
166 +static void npe_flash_add(struct mtd_info *mtd)
168 + if (partition_name == NULL)
171 + if (strcmp(mtd->name, partition_name) == 0) {
172 + npe_find_microcode(mtd);
176 +static void npe_flash_remove(struct mtd_info *mtd) {
179 +static struct mtd_notifier npe_flash_notifier = {
180 + .add = npe_flash_add,
181 + .remove = npe_flash_remove,
184 +static int npe_ucode_probe(struct platform_device *pdev)
186 + struct npe_ucode_platform_data *data = pdev->dev.platform_data;
188 + if (partition_name)
191 + if (data && data->mtd_partition) {
192 + partition_name = data->mtd_partition;
199 +static int npe_ucode_remove(struct platform_device *pdev)
204 +static struct platform_driver ixp4xx_npe_ucode_driver = {
206 + .name = "ixp4xx_npe_ucode",
207 + .owner = THIS_MODULE,
209 + .probe = npe_ucode_probe,
210 + .remove = npe_ucode_remove,
213 +static int __init npe_ucode_init(void)
217 + ret = platform_driver_register(&ixp4xx_npe_ucode_driver);
218 + register_mtd_user(&npe_flash_notifier);
223 +static void __exit npe_ucode_exit(void)
225 + unregister_mtd_user(&npe_flash_notifier);
226 + platform_driver_unregister(&ixp4xx_npe_ucode_driver);
229 +module_init(npe_ucode_init);
230 +module_exit(npe_ucode_exit);
232 +MODULE_LICENSE("GPL");
233 +MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
234 diff -Naupr a/drivers/net/ixp4xx/ucode_dl.c b/drivers/net/ixp4xx/ucode_dl.c
235 --- a/drivers/net/ixp4xx/ucode_dl.c 2007-01-12 21:54:40.000000000 -0700
236 +++ b/drivers/net/ixp4xx/ucode_dl.c 2007-01-12 23:28:50.000000000 -0700
238 #include <linux/firmware.h>
239 #include <linux/dma-mapping.h>
240 #include <linux/byteorder/swab.h>
241 +#include <linux/crc16.h>
242 #include <asm/uaccess.h>
246 #define DL_MAGIC 0xfeedf00d
247 #define DL_MAGIC_SWAP 0x0df0edfe
249 +#define IMG_REV_MAJOR(id) (((id) >> 8) & 0x0f)
250 +#define IMG_REV_MINOR(id) ((id) & 0x0f)
251 +#define IMG_FUNC(id) (((id) >> 16) & 0xff)
252 +#define IMG_NPE(id) (((id) >> 24) & 0x0f)
253 +#define IMG_IXP(id) (((id) >> 28) & 0x0f)
255 #define EOF_BLOCK 0xf
256 #define IMG_SIZE(image) (((image)->size * sizeof(u32)) + \
257 sizeof(struct dl_image))
258 @@ -38,21 +45,6 @@ enum blk_type {
273 - struct dl_block block[0];
277 struct dl_codeblock {
280 @@ -127,20 +119,33 @@ download_block(struct npe_info *npe, str
284 -static int store_npe_image(struct dl_image *image, struct device *dev)
285 +int store_npe_image(struct dl_image *image, struct device *dev)
287 struct dl_block *blk;
288 struct dl_codeblock *cb;
289 struct npe_info *npe;
294 - dev = get_npe_by_id( (image->id >> 24) & 0xf);
295 + dev = get_npe_by_id(IMG_NPE(image->id));
301 + if (image->size > 24000) { // XXX fix max size
302 + printk(KERN_ERR "npe: firmware too large\n");
306 + if (IMG_REV_MAJOR(image->id) != 2) {
307 + printk(KERN_ERR "npe: only revision 2 is supported at this time\n");
311 + crc = crc16(0, (u8 *) image, IMG_SIZE(image));
313 npe = dev_get_drvdata(dev);
314 if (npe->loaded && (npe->usage > 0)) {
315 printk(KERN_INFO "Cowardly refusing to reload an Image "
316 @@ -267,8 +272,7 @@ static ssize_t ucode_write(struct file *
318 static void npe_firmware_probe(struct device *dev)
320 -#if (defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE)) \
322 +#ifdef CONFIG_IXP4XX_NPE_FW_LOADER
323 const struct firmware *fw_entry;
324 struct npe_info *npe = dev_get_drvdata(dev);
325 struct dl_image *image;
326 @@ -477,3 +481,4 @@ MODULE_AUTHOR("Christian Hohnstaedt <cho
328 EXPORT_SYMBOL(get_npe_by_id);
329 EXPORT_SYMBOL(return_npe_dev);
330 +EXPORT_SYMBOL(store_npe_image);
331 diff -Naupr a/include/asm-arm/arch-ixp4xx/platform.h b/include/asm-arm/arch-ixp4xx/platform.h
332 --- a/include/asm-arm/arch-ixp4xx/platform.h 2007-01-12 21:54:40.000000000 -0700
333 +++ b/include/asm-arm/arch-ixp4xx/platform.h 2007-01-12 23:28:50.000000000 -0700
334 @@ -89,6 +89,21 @@ struct ixp4xx_i2c_pins {
349 + struct dl_block block[0];
353 struct npe_plat_data {
356 @@ -108,6 +123,10 @@ struct mac_plat_info {
360 +struct npe_ucode_platform_data {
361 + unsigned char *mtd_partition;
365 * Frequency of clock used for primary clocksource
367 diff -Naupr a/include/linux/ixp_npe.h b/include/linux/ixp_npe.h
368 --- a/include/linux/ixp_npe.h 2007-01-12 21:54:40.000000000 -0700
369 +++ b/include/linux/ixp_npe.h 2007-01-12 23:28:50.000000000 -0700
370 @@ -99,6 +99,7 @@ extern void npe_reset(struct npe_info *n
372 extern struct device *get_npe_by_id(int id);
373 extern void return_npe_dev(struct device *dev);
374 +extern int store_npe_image(struct dl_image *image, struct device *dev);