1 Index: linux-2.6.19/drivers/net/ixp4xx/Kconfig
2 ===================================================================
3 --- linux-2.6.19.orig/drivers/net/ixp4xx/Kconfig
4 +++ linux-2.6.19/drivers/net/ixp4xx/Kconfig
5 @@ -11,6 +11,7 @@ config IXP4XX_NPE
6 tristate "IXP4xx NPE support"
8 depends on NET_ETHERNET
11 The IXP4XX NPE driver supports the 3 CPU co-processors called
12 "Network Processing Engines" (NPE). It adds support fo downloading
13 @@ -18,7 +19,7 @@ config IXP4XX_NPE
14 More about this at: Documentation/networking/ixp4xx/README.
15 You can either use this OR the Intel Access Library (IAL)
17 -config IXP4XX_FW_LOAD
18 +config IXP4XX_NPE_FW_LOAD
19 bool "Use Firmware hotplug for Microcode download"
22 @@ -28,6 +29,13 @@ config IXP4XX_FW_LOAD
23 /usr/lib/hotplug/firmware/NPE-[ABC]
24 see Documentation/firmware_class/hotplug-script
26 +config IXP4XX_NPE_FW_MTD
27 + bool "Load firmware from an mtd partition"
28 + depends on IXP4XX_NPE && MTD_IXP4XX
30 + With this option, the driver will search for
31 + the firmware into an MTD partition.
34 tristate "IXP4xx MAC support"
36 Index: linux-2.6.19/drivers/net/ixp4xx/Makefile
37 ===================================================================
38 --- linux-2.6.19.orig/drivers/net/ixp4xx/Makefile
39 +++ linux-2.6.19/drivers/net/ixp4xx/Makefile
41 obj-$(CONFIG_IXP4XX_QMGR) += ixp4xx_qmgr.o
42 obj-$(CONFIG_IXP4XX_NPE) += ixp4xx_npe.o
43 obj-$(CONFIG_IXP4XX_MAC) += ixp4xx_mac.o
44 +obj-$(CONFIG_IXP4XX_NPE_FW_MTD) += npe_ucode.o
46 ixp4xx_npe-objs := ucode_dl.o npe_mh.o
47 ixp4xx_mac-objs := mac_driver.o qmgr_eth.o phy.o
48 Index: linux-2.6.19/drivers/net/ixp4xx/npe_ucode.c
49 ===================================================================
51 +++ linux-2.6.19/drivers/net/ixp4xx/npe_ucode.c
54 + * Provide an NPE platform device for microcode handling
56 + * Copyright (C) 2006 Christian Hohnstaedt <chohnstaedt@innominate.com>
58 + * This file is released under the GPLv2
61 +#include <linux/kernel.h>
62 +#include <linux/platform_device.h>
63 +#include <linux/init.h>
64 +#include <linux/slab.h>
65 +#include <linux/firmware.h>
66 +#include <linux/mtd/mtd.h>
68 +#include <linux/ixp_npe.h>
70 +#define DL_MAGIC 0xfeedf00d
71 +#define DL_MAGIC_SWAP 0x0df0edfe
73 +#define IMG_SIZE(image) (((image)->size * sizeof(u32)) + \
74 + sizeof(struct dl_image))
76 +#define IMG_REV_MAJOR(id) (((id) >> 8) & 0x0f)
77 +#define IMG_REV_MINOR(id) ((id) & 0x0f)
78 +#define IMG_FUNC(id) (((id) >> 16) & 0xff)
79 +#define IMG_NPE(id) (((id) >> 24) & 0x0f)
80 +#define IMG_IXP(id) (((id) >> 28) & 0x0f)
82 +static struct platform_driver ixp4xx_npe_ucode_driver;
83 +static unsigned char *partition_name = NULL;
85 +static void print_image_info(u32 id, u32 offset, u32 size)
88 + const char *names[] = { "IXP425", "IXP465", "unknown" };
90 + idx = IMG_IXP(id) < 2 ? IMG_IXP(id) : 2;
92 + printk(KERN_INFO "npe: found at 0x%x, %s/NPE-%c func: %02x, rev: %x.%x, "
93 + "size: %5d, id: %08x\n", offset, names[idx], IMG_NPE(id) + 'A',
94 + IMG_FUNC(id), IMG_REV_MAJOR(id), IMG_REV_MINOR(id), size, id);
97 +void npe_swap_image(struct dl_image *image)
101 + image->magic = swab32(image->magic);
102 + image->id = swab32(image->id);
103 + image->size = swab32(image->size);
105 + for (i = 0; i < image->size; i++)
106 + image->u.data[i] = swab32(image->u.data[i]);
109 +static void npe_find_microcode(struct mtd_info *mtd)
112 + u32 magic = htonl(DL_MAGIC);
116 + unsigned int offset = 0;
118 + printk("npe: searching for firmware...\n");
120 + while (offset < mtd->size) {
122 + err = mtd->read(mtd, offset, 4, &retlen, (u_char *) &buf);
128 + err = mtd->read(mtd, offset, 4, &retlen, (u_char *) &id);
136 + err = mtd->read(mtd, offset, 4, &retlen, (u_char *) &size);
139 + size = (ntohl(size) * 4) + 12;
141 + print_image_info(id, offset - 12, size);
143 + if (size < 24000 && ( IMG_FUNC(id) == 0x01 || IMG_FUNC(id) == 0x00) ) { // XXX fix size/detection
145 + struct dl_image *image = kmalloc(size, GFP_KERNEL);
147 + /* we are going to load it, rewind offset */
151 + err = mtd->read(mtd, offset, size, &retlen, (u_char *) image);
153 + if (err == 0 && retlen == size) {
154 + if (image->magic == DL_MAGIC_SWAP)
155 + npe_swap_image(image);
157 + store_npe_image(image, NULL);
159 + printk(KERN_ERR "unable to read firmware\n");
170 +static void npe_flash_add(struct mtd_info *mtd)
172 + if (partition_name == NULL)
175 + if (strcmp(mtd->name, partition_name) == 0) {
176 + npe_find_microcode(mtd);
180 +static void npe_flash_remove(struct mtd_info *mtd) {
183 +static struct mtd_notifier npe_flash_notifier = {
184 + .add = npe_flash_add,
185 + .remove = npe_flash_remove,
188 +static int npe_ucode_probe(struct platform_device *pdev)
190 + struct npe_ucode_platform_data *data = pdev->dev.platform_data;
192 + if (partition_name)
195 + if (data && data->mtd_partition) {
196 + partition_name = data->mtd_partition;
203 +static int npe_ucode_remove(struct platform_device *pdev)
208 +static struct platform_driver ixp4xx_npe_ucode_driver = {
210 + .name = "ixp4xx_npe_ucode",
211 + .owner = THIS_MODULE,
213 + .probe = npe_ucode_probe,
214 + .remove = npe_ucode_remove,
217 +static int __init npe_ucode_init(void)
221 + ret = platform_driver_register(&ixp4xx_npe_ucode_driver);
222 + register_mtd_user(&npe_flash_notifier);
227 +static void __exit npe_ucode_exit(void)
229 + unregister_mtd_user(&npe_flash_notifier);
230 + platform_driver_unregister(&ixp4xx_npe_ucode_driver);
233 +module_init(npe_ucode_init);
234 +module_exit(npe_ucode_exit);
236 +MODULE_LICENSE("GPL");
237 +MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
238 Index: linux-2.6.19/drivers/net/ixp4xx/ucode_dl.c
239 ===================================================================
240 --- linux-2.6.19.orig/drivers/net/ixp4xx/ucode_dl.c
241 +++ linux-2.6.19/drivers/net/ixp4xx/ucode_dl.c
243 #include <linux/firmware.h>
244 #include <linux/dma-mapping.h>
245 #include <linux/byteorder/swab.h>
246 +#include <linux/crc16.h>
247 #include <asm/uaccess.h>
251 #define IMG_SIZE(image) (((image)->size * sizeof(u32)) + \
252 sizeof(struct dl_image))
254 +#define IMG_REV_MAJOR(id) (((id) >> 8) & 0x0f)
255 +#define IMG_REV_MINOR(id) ((id) & 0x0f)
256 +#define IMG_FUNC(id) (((id) >> 16) & 0xff)
257 +#define IMG_NPE(id) (((id) >> 24) & 0x0f)
258 +#define IMG_IXP(id) (((id) >> 28) & 0x0f)
263 @@ -38,21 +45,6 @@ enum blk_type {
278 - struct dl_block block[0];
282 struct dl_codeblock {
285 @@ -134,23 +126,41 @@ struct device *get_npe_by_id(int id)
286 &id, match_by_npeid);
289 -static int store_npe_image(struct dl_image *image, struct device *dev)
290 +int store_npe_image(struct dl_image *image, struct device *dev)
292 struct dl_block *blk;
293 struct dl_codeblock *cb;
294 struct npe_info *npe;
300 - dev = get_npe_by_id( (image->id >> 24) & 0xf);
302 + dev = get_npe_by_id(IMG_NPE(image->id));
305 + // XXX shouldn't this put_device be outside if(!dev) ?
307 + printk(KERN_ERR "npe: cannot find npe for image %x\n", IMG_NPE(image->id));
313 + if (image->size > 24000) { // XXX fix max size
314 + printk(KERN_ERR "npe: firmware too large\n");
318 + if (IMG_REV_MAJOR(image->id) != 2) {
319 + printk(KERN_ERR "npe: only revision 2 is supported at this time\n");
323 + crc = crc16(0, (u8 *) image, IMG_SIZE(image));
325 npe = dev_get_drvdata(dev);
327 - if ( npe_status(npe) & IX_NPEDL_EXCTL_STATUS_RUN) {
328 + if (npe_status(npe) & IX_NPEDL_EXCTL_STATUS_RUN) {
329 printk(KERN_INFO "Cowardly refusing to reload an Image "
330 "into the running %s\n", npe->plat->name);
331 return 0; /* indicate success anyway... */
332 @@ -173,9 +183,9 @@ static int store_npe_image(struct dl_ima
333 *(u32*)npe->img_info = cpu_to_be32(image->id);
336 - printk(KERN_INFO "Image loaded to %s Func:%x, Rel: %x:%x, Status: %x\n",
337 + printk(KERN_INFO "npe: firmware loaded to %s, func: %02x, rev: %x.%x, status: %x, crc: %x\n",
338 npe->plat->name, npe->img_info[1], npe->img_info[2],
339 - npe->img_info[3], npe_status(npe));
340 + npe->img_info[3], npe_status(npe), crc);
344 @@ -265,8 +275,7 @@ static ssize_t ucode_write(struct file *
346 static void npe_firmware_probe(struct device *dev)
348 -#if (defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE)) \
350 +#ifdef CONFIG_IXP4XX_NPE_FW_LOADER
351 const struct firmware *fw_entry;
352 struct npe_info *npe = dev_get_drvdata(dev);
353 struct dl_image *image;
354 @@ -388,7 +397,7 @@ static int npe_probe(struct platform_dev
357 disable_npe_irq(npe);
358 - if (! (npe_status(npe) & IX_NPEDL_EXCTL_STATUS_RUN))
359 + if (!(npe_status(npe) & IX_NPEDL_EXCTL_STATUS_RUN))
360 npe_firmware_probe(&pdev->dev);
363 @@ -464,3 +473,4 @@ MODULE_LICENSE("GPL");
364 MODULE_AUTHOR("Christian Hohnstaedt <chohnstaedt@innominate.com>");
366 EXPORT_SYMBOL(get_npe_by_id);
367 +EXPORT_SYMBOL(store_npe_image);
368 Index: linux-2.6.19/include/asm-arm/arch-ixp4xx/platform.h
369 ===================================================================
370 --- linux-2.6.19.orig/include/asm-arm/arch-ixp4xx/platform.h
371 +++ linux-2.6.19/include/asm-arm/arch-ixp4xx/platform.h
372 @@ -86,6 +86,20 @@ struct ixp4xx_i2c_pins {
373 unsigned long scl_pin;
387 + struct dl_block block[0];
390 struct npe_plat_data {
393 @@ -103,6 +117,9 @@ struct mac_plat_info {
394 unsigned char hwaddr[6]; /* Desired hardware address */
397 +struct npe_ucode_platform_data {
398 + unsigned char *mtd_partition;
403 Index: linux-2.6.19/include/linux/ixp_npe.h
404 ===================================================================
405 --- linux-2.6.19.orig/include/linux/ixp_npe.h
406 +++ linux-2.6.19/include/linux/ixp_npe.h
407 @@ -71,6 +71,7 @@ static inline u32 npe_read_ecs_reg(struc
410 extern struct device *get_npe_by_id(int id);
411 +extern int store_npe_image(struct dl_image *image, struct device *dev);