1 Index: linux-2.6.21.7/Documentation/networking/ixp4xx/IxNpeMicrocode.h
2 ===================================================================
4 +++ linux-2.6.21.7/Documentation/networking/ixp4xx/IxNpeMicrocode.h
7 + * IxNpeMicrocode.h - Headerfile for compiling the Intel microcode C file
9 + * Copyright (C) 2006 Christian Hohnstaedt <chohnstaedt@innominate.com>
11 + * This file is released under the GPLv2
16 + * gcc -Wall IxNpeMicrocode.c -o IxNpeMicrocode
18 + * Executing the resulting binary on your build-host creates the
19 + * "NPE-[ABC].xxxxxxxx" files containing the selected microcode
21 + * fetch the IxNpeMicrocode.c from the Intel Access Library.
22 + * It will include this header.
24 + * select Images for every NPE from the following
25 + * (used C++ comments for easy uncommenting ....)
28 +// #define IX_NPEDL_NPEIMAGE_NPEA_ETH_SPAN_MASK_FIREWALL_VLAN_QOS_HDR_CONV_EXTMIB
29 +// #define IX_NPEDL_NPEIMAGE_NPEA_ETH_SPAN_VLAN_QOS_HDR_CONV_EXTMIB
30 +// #define IX_NPEDL_NPEIMAGE_NPEA_ETH_LEARN_FILTER_SPAN_MASK_FIREWALL_VLAN_QOS_EXTMIB
31 +// #define IX_NPEDL_NPEIMAGE_NPEA_HSS_TSLOT_SWITCH
32 +// #define IX_NPEDL_NPEIMAGE_NPEA_ETH_SPAN_FIREWALL_VLAN_QOS_HDR_CONV
33 +// #define IX_NPEDL_NPEIMAGE_NPEA_ETH_LEARN_FILTER_SPAN_FIREWALL_VLAN_QOS
34 +// #define IX_NPEDL_NPEIMAGE_NPEA_ETH_LEARN_FILTER_SPAN_FIREWALL
35 +// #define IX_NPEDL_NPEIMAGE_NPEA_HSS_2_PORT
36 +// #define IX_NPEDL_NPEIMAGE_NPEA_DMA
37 +// #define IX_NPEDL_NPEIMAGE_NPEA_ATM_MPHY_12_PORT
38 +// #define IX_NPEDL_NPEIMAGE_NPEA_HSS0_ATM_MPHY_1_PORT
39 +// #define IX_NPEDL_NPEIMAGE_NPEA_HSS0_ATM_SPHY_1_PORT
40 +// #define IX_NPEDL_NPEIMAGE_NPEA_HSS0
41 +// #define IX_NPEDL_NPEIMAGE_NPEA_WEP
44 +// #define IX_NPEDL_NPEIMAGE_NPEB_ETH_SPAN_MASK_FIREWALL_VLAN_QOS_HDR_CONV_EXTMIB
45 +//#define IX_NPEDL_NPEIMAGE_NPEB_ETH_SPAN_VLAN_QOS_HDR_CONV_EXTMIB
46 +// #define IX_NPEDL_NPEIMAGE_NPEB_ETH_LEARN_FILTER_SPAN_MASK_FIREWALL_VLAN_QOS_EXTMIB
47 +// #define IX_NPEDL_NPEIMAGE_NPEB_DMA
48 +// #define IX_NPEDL_NPEIMAGE_NPEB_ETH_SPAN_FIREWALL_VLAN_QOS_HDR_CONV
49 +// #define IX_NPEDL_NPEIMAGE_NPEB_ETH_LEARN_FILTER_SPAN_FIREWALL_VLAN_QOS
50 + #define IX_NPEDL_NPEIMAGE_NPEB_ETH_LEARN_FILTER_SPAN_FIREWALL
53 +// #define IX_NPEDL_NPEIMAGE_NPEC_ETH_SPAN_MASK_FIREWALL_VLAN_QOS_HDR_CONV_EXTMIB
54 +// #define IX_NPEDL_NPEIMAGE_NPEC_ETH_SPAN_VLAN_QOS_HDR_CONV_EXTMIB
55 +// #define IX_NPEDL_NPEIMAGE_NPEC_ETH_LEARN_FILTER_SPAN_MASK_FIREWALL_VLAN_QOS_EXTMIB
56 +// #define IX_NPEDL_NPEIMAGE_NPEC_DMA
57 +// #define IX_NPEDL_NPEIMAGE_NPEC_CRYPTO_AES_ETH_LEARN_FILTER_SPAN
58 +// #define IX_NPEDL_NPEIMAGE_NPEC_CRYPTO_AES_ETH_LEARN_FILTER_FIREWALL
59 + #define IX_NPEDL_NPEIMAGE_NPEC_CRYPTO_AES_CCM_ETH
60 +// #define IX_NPEDL_NPEIMAGE_NPEC_CRYPTO_ETH_LEARN_FILTER_SPAN_FIREWALL
61 +// #define IX_NPEDL_NPEIMAGE_NPEC_ETH_SPAN_FIREWALL_VLAN_QOS_HDR_CONV
62 +// #define IX_NPEDL_NPEIMAGE_NPEC_ETH_LEARN_FILTER_SPAN_FIREWALL_VLAN_QOS
63 +// #define IX_NPEDL_NPEIMAGE_NPEC_ETH_LEARN_FILTER_SPAN_FIREWALL
69 +#include <netinet/in.h>
70 +#include <sys/types.h>
71 +#include <sys/stat.h>
75 +#include <byteswap.h>
78 +#if __BYTE_ORDER == __LITTLE_ENDIAN
79 +#define to_le32(x) (x)
80 +#define to_be32(x) bswap_32(x)
82 +#define to_be32(x) (x)
83 +#define to_le32(x) bswap_32(x)
93 +const unsigned IxNpeMicrocode_array[];
95 +int main(int argc, char *argv[])
97 + struct dl_image *image = (struct dl_image *)IxNpeMicrocode_array;
98 + int imgsiz, i, fd, cnt;
99 + const unsigned *arrayptr = IxNpeMicrocode_array;
100 + const char *names[] = { "IXP425", "IXP465", "unknown" };
104 + if (!strcmp(argv[1], "-le"))
106 + else if (!strcmp(argv[1], "-be"))
109 + printf("Usage: %s <-le|-be>\n", argv[0]);
110 + return EXIT_FAILURE;
114 + for (image = (struct dl_image *)arrayptr, cnt=0;
115 + (image->id != 0xfeedf00d) && (image->magic == 0xfeedf00d);
116 + image = (struct dl_image *)(arrayptr), cnt++)
118 + unsigned char field[4];
119 + imgsiz = image->size + 3;
120 + *(unsigned*)field = to_be32(image->id);
121 + char filename[40], slnk[10];
123 + sprintf(filename, "NPE-%c.%08x", (field[0] & 0xf) + 'A',
125 + sprintf(slnk, "NPE-%c", (field[0] & 0xf) + 'A');
126 + printf("Writing image: %s.NPE_%c Func: %2x Rev: %02x.%02x "
127 + "Size: %5d to: '%s'\n",
128 + names[field[0] >> 4], (field[0] & 0xf) + 'A',
129 + field[1], field[2], field[3], imgsiz*4, filename);
130 + fd = open(filename, O_CREAT | O_RDWR | O_TRUNC, 0644);
132 + for (i=0; i<imgsiz; i++) {
133 + *(unsigned*)field = bigendian ?
134 + to_be32(arrayptr[i]) :
135 + to_le32(arrayptr[i]);
136 + write(fd, field, sizeof(field));
140 + symlink(filename, slnk);
144 + arrayptr += imgsiz;
149 Index: linux-2.6.21.7/Documentation/networking/ixp4xx/README
150 ===================================================================
152 +++ linux-2.6.21.7/Documentation/networking/ixp4xx/README
154 +Informations about the Networking Driver using the IXP4XX CPU internal NPEs
157 +If this driver is used, the IAL (Intel Access Library) must not be loaded.
158 +However, the IAL may be loaded, if this Modules are unloaded:
159 + ixp4xx_npe.ko, ixp4xx_qmgr.ko ixp4xx_mac.ko
161 +This also means that HW crypto accelleration does NOT work when using this
162 +driver, unless I have finished my crypto driver for NPE-C
165 +Adoption to your custom board:
166 +------------------------------
167 +use "arch/arm/mach-ixp4xx/ixdp425-setup.c" as template:
169 +in "static struct mac_plat_info" adopt the entry "phy_id" to your needs
170 +(Ask your hardware designer about the PHY id)
172 +The order of "&mac0" and "&mac1" in the "struct platform_device"
173 +determines which of them becomes eth0 and eth1
179 + Configure "CONFIG_HOTPLUG" and "CONFIG_FW_LOADER" and configure
180 + IXP4XX_NPE as module.
181 + The default hotplug script will load the Firmware from
182 + /usr/lib/hotplug/firmware/NPE-[ABC]
183 + see Documentation/firmware_class/hotplug-script
185 + You should take care, that $ACTION is "add" and $SUBSYSTEM is "firmware"
186 + to avoid unnessecary calls:
187 + test $ACTION = "remove" -o $SUBSYSTEM != "firmware" && exit
190 + create a char-dev: "mknod /dev/misc/npe c 10 184"
191 + cat the Microcode into it:
192 + cat /usr/lib/hotplug/firmware/NPE-* > /dev/misc/npe
193 + This also works if the driver is linked to the kernel
195 + Having a mix of both (e.g. solution 1 for NPE-B and solution 2 for NPE-C)
196 + is perfectly ok and works.
198 + The state of the NPEs can be seen and changed at:
199 + /sys/bus/platform/devices/ixp4xx_npe.X/state
202 +Obtaining the Microcode:
203 +------------------------
204 +1) IxNpeMicrocode.h in this directory:
205 + Download IPL_IXP400NPELIBRARYWITHCRYPTO-2_1.ZIP from Intel
206 + It unpacks the Microcode IxNpeMicrocode.c
208 + Compile it with "gcc -Wall IxNpeMicrocode.c -o IxNpeMicrocode" on your host.
209 + The resulting images can be moved to "/usr/lib/hotplug/firmware"
211 +2) mc_grab.c in this directory:
212 + Compile and execute it either on the host or on the target
213 + to grab the microcode from a binary image like the RedBoot bootloader.
216 Index: linux-2.6.21.7/Documentation/networking/ixp4xx/mc_grab.c
217 ===================================================================
219 +++ linux-2.6.21.7/Documentation/networking/ixp4xx/mc_grab.c
222 + * mc_grab.c - grabs IXP4XX microcode from a binary datastream
223 + * e.g. The redboot bootloader....
225 + * usage: mc_grab 1010200 2010200 < /dev/mtd/0 > /dev/misc/npe
227 + * Copyright (C) 2006 Christian Hohnstaedt <chohnstaedt@innominate.com>
229 + * This file is released under the GPLv2
236 +#include <netinet/in.h>
237 +#include <sys/types.h>
238 +#include <sys/stat.h>
245 +static void print_mc_info(unsigned id, int siz)
247 + unsigned char buf[sizeof(unsigned)];
248 + *(unsigned*)buf = id;
250 + const char *names[] = { "IXP425", "IXP465", "unknown" };
252 + idx = (buf[0] >> 4) < 2 ? (buf[0] >> 4) : 2;
254 + fprintf(stderr, "Device: %s:NPE_%c Func: %2x Rev: %02x.%02x "
255 + "Size: %5d bytes ID:%08x\n", names[idx], (buf[0] & 0xf)+'A',
256 + buf[1], buf[2], buf[3], siz*4, ntohl(id));
259 +int main(int argc, char *argv[])
262 + unsigned char buf[sizeof(unsigned)];
263 + unsigned magic = htonl(0xfeedf00d);
264 + unsigned id, my_ids[MAX_IMG+1], siz, sizbe;
265 + int ret=1, verbose=0;
267 + for (i=0, j=0; i<argc-1 && j<MAX_IMG; i++) {
268 + if (!strcmp(argv[i+1], "-v"))
271 + my_ids[j++] = htonl(strtoul(argv[i+1], NULL, 16));
274 + if (my_ids[0] == 0 && !verbose) {
275 + fprintf(stderr, "Usage: %s <-v> [ID1] [ID2] [IDn]\n", argv[0]);
279 + while ((ret=read(0, buf, sizeof(unsigned))) == sizeof(unsigned)) {
280 + if (*(unsigned*)buf != magic)
282 + if ((ret=read(0, buf, sizeof(unsigned))) != sizeof(unsigned) )
284 + id = *(unsigned*)buf;
286 + if (read(0, buf, sizeof(siz)) != sizeof(siz) )
288 + sizbe = *(unsigned*)buf;
289 + siz = ntohl(sizbe);
292 + print_mc_info(id, siz);
294 + for(i=0; my_ids[i]; i++)
295 + if (id == my_ids[i])
301 + print_mc_info(id, siz);
303 + write(1, &magic, sizeof(magic));
304 + write(1, &id, sizeof(id));
305 + write(1, &sizbe, sizeof(sizbe));
306 + for (i=0; i<siz; i++) {
307 + if (read(0, buf, sizeof(unsigned)) != sizeof(unsigned))
309 + write(1, buf, sizeof(unsigned));
315 + fprintf(stderr, "Error reading Microcode\n");
318 Index: linux-2.6.21.7/arch/arm/mach-ixp4xx/common.c
319 ===================================================================
320 --- linux-2.6.21.7.orig/arch/arm/mach-ixp4xx/common.c
321 +++ linux-2.6.21.7/arch/arm/mach-ixp4xx/common.c
322 @@ -357,6 +357,90 @@ static struct platform_device *ixp46x_de
323 &ixp46x_i2c_controller
326 +static struct npe_plat_data npea = {
328 + .data_size = 0x800,
329 + .inst_size = 0x1000,
333 +static struct npe_plat_data npeb = {
335 + .data_size = 0x800,
336 + .inst_size = 0x800,
340 +static struct npe_plat_data npec = {
342 + .data_size = 0x800,
343 + .inst_size = 0x800,
347 +static struct resource res_npea = {
348 + .start = IXP4XX_NPEA_BASE_PHYS,
349 + .end = IXP4XX_NPEA_BASE_PHYS + 0xfff,
350 + .flags = IORESOURCE_MEM,
353 +static struct resource res_npeb = {
354 + .start = IXP4XX_NPEB_BASE_PHYS,
355 + .end = IXP4XX_NPEB_BASE_PHYS + 0xfff,
356 + .flags = IORESOURCE_MEM,
359 +static struct resource res_npec = {
360 + .start = IXP4XX_NPEC_BASE_PHYS,
361 + .end = IXP4XX_NPEC_BASE_PHYS + 0xfff,
362 + .flags = IORESOURCE_MEM,
365 +static struct platform_device dev_npea = {
366 + .name = "ixp4xx_npe",
368 + .dev.platform_data = &npea,
369 + .num_resources = 1,
370 + .resource = &res_npea,
373 +static struct platform_device dev_npeb = {
374 + .name = "ixp4xx_npe",
376 + .dev.platform_data = &npeb,
377 + .num_resources = 1,
378 + .resource = &res_npeb,
381 +static struct platform_device dev_npec = {
382 + .name = "ixp4xx_npe",
384 + .dev.platform_data = &npec,
385 + .num_resources = 1,
386 + .resource = &res_npec,
390 +static struct resource res_qmgr[] = {
392 + .start = IXP4XX_QMGR_BASE_PHYS,
393 + .end = IXP4XX_QMGR_BASE_PHYS + IXP4XX_QMGR_REGION_SIZE -1,
394 + .flags = IORESOURCE_MEM,
396 + .start = IRQ_IXP4XX_QM1,
397 + .flags = IORESOURCE_IRQ,
400 +static struct platform_device qmgr = {
401 + .name = "ixp4xx_qmgr",
404 + .coherent_dma_mask = DMA_32BIT_MASK,
406 + .num_resources = ARRAY_SIZE(res_qmgr),
407 + .resource = res_qmgr,
410 unsigned long ixp4xx_exp_bus_size;
411 EXPORT_SYMBOL(ixp4xx_exp_bus_size);
413 @@ -378,8 +462,19 @@ void __init ixp4xx_sys_init(void)
417 + npeb.inst_size = 0x1000;
418 + npec.inst_size = 0x1000;
421 + platform_device_register(&qmgr);
423 + if (ix_fuse() & IX_FUSE_NPEA)
424 + platform_device_register(&dev_npea);
425 + if (ix_fuse() & IX_FUSE_NPEB)
426 + platform_device_register(&dev_npeb);
427 + if (ix_fuse() & IX_FUSE_NPEC)
428 + platform_device_register(&dev_npec);
430 printk("IXP4xx: Using %luMiB expansion bus window size\n",
431 ixp4xx_exp_bus_size >> 20);
433 Index: linux-2.6.21.7/arch/arm/mach-ixp4xx/ixdp425-setup.c
434 ===================================================================
435 --- linux-2.6.21.7.orig/arch/arm/mach-ixp4xx/ixdp425-setup.c
436 +++ linux-2.6.21.7/arch/arm/mach-ixp4xx/ixdp425-setup.c
437 @@ -101,10 +101,59 @@ static struct platform_device ixdp425_ua
438 .resource = ixdp425_uart_resources
442 +static struct resource res_mac0 = {
443 + .start = IXP4XX_EthB_BASE_PHYS,
444 + .end = IXP4XX_EthB_BASE_PHYS + 0x1ff,
445 + .flags = IORESOURCE_MEM,
448 +static struct resource res_mac1 = {
449 + .start = IXP4XX_EthC_BASE_PHYS,
450 + .end = IXP4XX_EthC_BASE_PHYS + 0x1ff,
451 + .flags = IORESOURCE_MEM,
454 +static struct mac_plat_info plat_mac0 = {
463 +static struct mac_plat_info plat_mac1 = {
472 +static struct platform_device mac0 = {
473 + .name = "ixp4xx_mac",
475 + .dev.platform_data = &plat_mac0,
476 + .num_resources = 1,
477 + .resource = &res_mac0,
480 +static struct platform_device mac1 = {
481 + .name = "ixp4xx_mac",
483 + .dev.platform_data = &plat_mac1,
484 + .num_resources = 1,
485 + .resource = &res_mac1,
488 static struct platform_device *ixdp425_devices[] __initdata = {
489 &ixdp425_i2c_controller,
497 static void __init ixdp425_init(void)
498 Index: linux-2.6.21.7/drivers/net/Kconfig
499 ===================================================================
500 --- linux-2.6.21.7.orig/drivers/net/Kconfig
501 +++ linux-2.6.21.7/drivers/net/Kconfig
502 @@ -324,6 +324,8 @@ config MACB
504 source "drivers/net/arm/Kconfig"
506 +source "drivers/net/ixp4xx/Kconfig"
509 tristate "MACE (Power Mac ethernet) support"
510 depends on NET_ETHERNET && PPC_PMAC && PPC32
511 Index: linux-2.6.21.7/drivers/net/Makefile
512 ===================================================================
513 --- linux-2.6.21.7.orig/drivers/net/Makefile
514 +++ linux-2.6.21.7/drivers/net/Makefile
515 @@ -213,6 +213,7 @@ obj-$(CONFIG_HAMRADIO) += hamradio/
516 obj-$(CONFIG_IRDA) += irda/
517 obj-$(CONFIG_ETRAX_ETHERNET) += cris/
518 obj-$(CONFIG_ENP2611_MSF_NET) += ixp2000/
519 +obj-$(CONFIG_IXP4XX_NPE) += ixp4xx/
521 obj-$(CONFIG_NETCONSOLE) += netconsole.o
523 Index: linux-2.6.21.7/drivers/net/ixp4xx/Kconfig
524 ===================================================================
526 +++ linux-2.6.21.7/drivers/net/ixp4xx/Kconfig
529 + tristate "IXP4xx Queue Manager support"
530 + depends on ARCH_IXP4XX
531 + depends on NET_ETHERNET
533 + The IXP4XX Queue manager is a configurable hardware ringbuffer.
534 + It is used by the NPEs to exchange data from and to the CPU.
535 + You can either use this OR the Intel Access Library (IAL)
538 + tristate "IXP4xx NPE support"
539 + depends on ARCH_IXP4XX
540 + depends on NET_ETHERNET
542 + The IXP4XX NPE driver supports the 3 CPU co-processors called
543 + "Network Processing Engines" (NPE). It adds support fo downloading
544 + the Microcode (firmware) via Hotplug or character-special-device.
545 + More about this at: Documentation/networking/ixp4xx/README.
546 + You can either use this OR the Intel Access Library (IAL)
548 +config IXP4XX_FW_LOAD
549 + bool "Use Firmware hotplug for Microcode download"
550 + depends on IXP4XX_NPE
554 + The default hotplug script will load the Firmware from
555 + /usr/lib/hotplug/firmware/NPE-[ABC]
556 + see Documentation/firmware_class/hotplug-script
559 + tristate "IXP4xx MAC support"
560 + depends on IXP4XX_NPE
561 + depends on IXP4XX_QMGR
562 + depends on NET_ETHERNET
565 + The IXP4XX MAC driver supports the MACs on the IXP4XX CPUs.
566 + There are 2 on ixp425 and up to 5 on ixdp465.
567 + You can either use this OR the Intel Access Library (IAL)
569 +config IXP4XX_CRYPTO
570 + tristate "IXP4xx crypto support"
571 + depends on IXP4XX_NPE
572 + depends on IXP4XX_QMGR
574 + This driver is a generic NPE-crypto access layer.
575 + You need additional code in OCF for example.
576 Index: linux-2.6.21.7/drivers/net/ixp4xx/Makefile
577 ===================================================================
579 +++ linux-2.6.21.7/drivers/net/ixp4xx/Makefile
581 +obj-$(CONFIG_IXP4XX_QMGR) += ixp4xx_qmgr.o
582 +obj-$(CONFIG_IXP4XX_NPE) += ixp4xx_npe.o
583 +obj-$(CONFIG_IXP4XX_MAC) += ixp4xx_mac.o
584 +obj-$(CONFIG_IXP4XX_CRYPTO) += ixp4xx_crypto.o
586 +ixp4xx_npe-objs := ucode_dl.o npe_mh.o npe.o
587 +ixp4xx_mac-objs := mac_driver.o phy.o
588 Index: linux-2.6.21.7/drivers/net/ixp4xx/ixp4xx_crypto.c
589 ===================================================================
591 +++ linux-2.6.21.7/drivers/net/ixp4xx/ixp4xx_crypto.c
594 + * ixp4xx_crypto.c - interface to the HW crypto
596 + * Copyright (C) 2006 Christian Hohnstaedt <chohnstaedt@innominate.com>
598 + * This file is released under the GPLv2
601 +#include <linux/ixp_qmgr.h>
602 +#include <linux/ixp_npe.h>
603 +#include <linux/dma-mapping.h>
604 +#include <linux/dmapool.h>
605 +#include <linux/device.h>
606 +#include <linux/delay.h>
607 +#include <linux/slab.h>
608 +#include <linux/kernel.h>
609 +#include <linux/ixp_crypto.h>
614 +#define NPE_ID 2 /* NPE C */
616 +#define QUEUE_SIZE 64
617 +#define MY_VERSION "0.0.1"
619 +/* local head for all sa_ctx */
620 +static struct ix_sa_master sa_master;
622 +static const struct ix_hash_algo _hash_algos[] = {
625 + .cfgword = 0xAA010004,
627 + .icv = "\x01\x23\x45\x67\x89\xAB\xCD\xEF"
628 + "\xFE\xDC\xBA\x98\x76\x54\x32\x10",
629 + .type = HASH_TYPE_MD5,
632 + .cfgword = 0x00000005,
634 + .icv = "\x67\x45\x23\x01\xEF\xCD\xAB\x89\x98\xBA"
635 + "\xDC\xFE\x10\x32\x54\x76\xC3\xD2\xE1\xF0",
636 + .type = HASH_TYPE_SHA1,
642 + .type = HASH_TYPE_CBCMAC,
646 +static const struct ix_cipher_algo _cipher_algos[] = {
649 + .cfgword_enc = CIPH_ENCR | MOD_DES | MOD_ECB | KEYLEN_192,
650 + .cfgword_dec = CIPH_DECR | MOD_DES | MOD_ECB | KEYLEN_192,
652 + .type = CIPHER_TYPE_DES,
653 + .mode = CIPHER_MODE_ECB,
656 + .cfgword_enc = CIPH_ENCR | MOD_DES | MOD_CBC_ENC | KEYLEN_192,
657 + .cfgword_dec = CIPH_DECR | MOD_DES | MOD_CBC_DEC | KEYLEN_192,
660 + .type = CIPHER_TYPE_DES,
661 + .mode = CIPHER_MODE_CBC,
663 + .name = "3DES ECB",
664 + .cfgword_enc = CIPH_ENCR | MOD_TDEA3 | MOD_ECB | KEYLEN_192,
665 + .cfgword_dec = CIPH_DECR | MOD_TDEA3 | MOD_ECB | KEYLEN_192,
667 + .type = CIPHER_TYPE_3DES,
668 + .mode = CIPHER_MODE_ECB,
670 + .name = "3DES CBC",
671 + .cfgword_enc = CIPH_ENCR | MOD_TDEA3 | MOD_CBC_ENC | KEYLEN_192,
672 + .cfgword_dec = CIPH_DECR | MOD_TDEA3 | MOD_CBC_DEC | KEYLEN_192,
675 + .type = CIPHER_TYPE_3DES,
676 + .mode = CIPHER_MODE_CBC,
679 + .cfgword_enc = CIPH_ENCR | ALGO_AES | MOD_ECB,
680 + .cfgword_dec = CIPH_DECR | ALGO_AES | MOD_ECB,
682 + .type = CIPHER_TYPE_AES,
683 + .mode = CIPHER_MODE_ECB,
686 + .cfgword_enc = CIPH_ENCR | ALGO_AES | MOD_CBC_ENC,
687 + .cfgword_dec = CIPH_DECR | ALGO_AES | MOD_CBC_DEC,
690 + .type = CIPHER_TYPE_AES,
691 + .mode = CIPHER_MODE_CBC,
694 + .cfgword_enc = CIPH_ENCR | ALGO_AES | MOD_CTR,
695 + .cfgword_dec = CIPH_ENCR | ALGO_AES | MOD_CTR,
698 + .type = CIPHER_TYPE_AES,
699 + .mode = CIPHER_MODE_CTR,
703 + .cfgword_enc = CIPH_ENCR | ALGO_AES | MOD_CCM_ENC,
704 + .cfgword_dec = CIPH_ENCR | ALGO_AES | MOD_CCM_DEC,
707 + .type = CIPHER_TYPE_AES,
708 + .mode = CIPHER_MODE_CCM,
712 +const struct ix_hash_algo *ix_hash_by_id(int type)
716 + for(i=0; i<ARRAY_SIZE(_hash_algos); i++) {
717 + if (_hash_algos[i].type == type)
718 + return _hash_algos + i;
723 +const struct ix_cipher_algo *ix_cipher_by_id(int type, int mode)
727 + for(i=0; i<ARRAY_SIZE(_cipher_algos); i++) {
728 + if (_cipher_algos[i].type==type && _cipher_algos[i].mode==mode)
729 + return _cipher_algos + i;
734 +static void irqcb_recv(struct qm_queue *queue);
736 +static int init_sa_master(struct ix_sa_master *master)
738 + struct npe_info *npe;
741 + if (! (ix_fuse() & (IX_FUSE_HASH | IX_FUSE_AES | IX_FUSE_DES))) {
742 + printk(KERN_ERR "ixp_crypto: No HW crypto available\n");
745 + memset(master, 0, sizeof(struct ix_sa_master));
746 + master->npe_dev = get_npe_by_id(NPE_ID);
747 + if (! master->npe_dev)
750 + npe = dev_get_drvdata(master->npe_dev);
752 + if (npe_status(npe) & IX_NPEDL_EXCTL_STATUS_RUN) {
753 + switch (npe->img_info[1]) {
755 + printk(KERN_INFO "Crypto AES avaialable\n");
758 + printk(KERN_INFO "Crypto AES and CCM avaialable\n");
761 + printk(KERN_WARNING "Current microcode for %s has no"
762 + " crypto capabilities\n", npe->plat->name);
766 + rwlock_init(&master->lock);
767 + master->dmapool = dma_pool_create("ixp4xx_crypto", master->npe_dev,
768 + sizeof(struct npe_crypt_cont), 32, 0);
769 + if (!master->dmapool) {
773 + master->sendq = request_queue(SEND_QID, QUEUE_SIZE);
774 + if (IS_ERR(master->sendq)) {
775 + printk(KERN_ERR "ixp4xx_crypto: Error requesting Q: %d\n",
777 + ret = PTR_ERR(master->sendq);
780 + master->recvq = request_queue(RECV_QID, QUEUE_SIZE);
781 + if (IS_ERR(master->recvq)) {
782 + printk(KERN_ERR "ixp4xx_crypto: Error requesting Q: %d\n",
784 + ret = PTR_ERR(master->recvq);
785 + release_queue(master->sendq);
789 + master->recvq->irq_cb = irqcb_recv;
790 + queue_set_watermarks(master->recvq, 0, 0);
791 + queue_set_irq_src(master->recvq, Q_IRQ_ID_NOT_E);
792 + queue_enable_irq(master->recvq);
793 + printk(KERN_INFO "ixp4xx_crypto " MY_VERSION " registered successfully\n");
797 + if (master->dmapool)
798 + dma_pool_destroy(master->dmapool);
799 + if (! master->npe_dev)
800 + put_device(master->npe_dev);
805 +static void release_sa_master(struct ix_sa_master *master)
807 + struct npe_crypt_cont *cont;
808 + unsigned long flags;
810 + write_lock_irqsave(&master->lock, flags);
811 + while (master->pool) {
812 + cont = master->pool;
813 + master->pool = cont->next;
814 + dma_pool_free(master->dmapool, cont, cont->phys);
815 + master->pool_size--;
817 + write_unlock_irqrestore(&master->lock, flags);
818 + if (master->pool_size) {
819 + printk(KERN_ERR "ixp4xx_crypto: %d items lost from DMA pool\n",
820 + master->pool_size);
823 + dma_pool_destroy(master->dmapool);
824 + release_queue(master->sendq);
825 + release_queue(master->recvq);
826 + return_npe_dev(master->npe_dev);
829 +static struct npe_crypt_cont *ix_sa_get_cont(struct ix_sa_master *master)
831 + unsigned long flags;
832 + struct npe_crypt_cont *cont;
835 + write_lock_irqsave(&master->lock, flags);
836 + if (!master->pool) {
837 + cont = dma_pool_alloc(master->dmapool, GFP_ATOMIC, &handle);
839 + master->pool_size++;
840 + cont->phys = handle;
844 + cont = master->pool;
845 + master->pool = cont->next;
847 + write_unlock_irqrestore(&master->lock, flags);
852 +ix_sa_return_cont(struct ix_sa_master *master,struct npe_crypt_cont *cont)
854 + unsigned long flags;
856 + write_lock_irqsave(&master->lock, flags);
857 + cont->next = master->pool;
858 + master->pool = cont;
859 + write_unlock_irqrestore(&master->lock, flags);
862 +static void free_sa_dir(struct ix_sa_ctx *sa_ctx, struct ix_sa_dir *dir)
864 + memset(dir->npe_ctx, 0, NPE_CTX_LEN);
865 + dma_pool_free(sa_ctx->master->dmapool, dir->npe_ctx,
866 + dir->npe_ctx_phys);
869 +static void ix_sa_ctx_destroy(struct ix_sa_ctx *sa_ctx)
871 + BUG_ON(sa_ctx->state != STATE_UNLOADING);
872 + free_sa_dir(sa_ctx, &sa_ctx->encrypt);
873 + free_sa_dir(sa_ctx, &sa_ctx->decrypt);
875 + module_put(THIS_MODULE);
878 +static void recv_pack(struct qm_queue *queue, u32 phys)
880 + struct ix_sa_ctx *sa_ctx;
881 + struct npe_crypt_cont *cr_cont;
882 + struct npe_cont *cont;
885 + failed = phys & 0x1;
888 + cr_cont = dma_to_virt(queue->dev, phys);
889 + cr_cont = cr_cont->virt;
890 + sa_ctx = cr_cont->ctl.crypt.sa_ctx;
892 + phys = npe_to_cpu32(cr_cont->ctl.crypt.src_buf);
894 + cont = dma_to_virt(queue->dev, phys);
899 + if (cr_cont->ctl.crypt.oper_type == OP_PERFORM) {
900 + dma_unmap_single(sa_ctx->master->npe_dev,
901 + cont->eth.phys_addr,
903 + DMA_BIDIRECTIONAL);
904 + if (sa_ctx->perf_cb)
905 + sa_ctx->perf_cb(sa_ctx, cont->data, failed);
906 + qmgr_return_cont(dev_get_drvdata(queue->dev), cont);
907 + ix_sa_return_cont(sa_ctx->master, cr_cont);
908 + if (atomic_dec_and_test(&sa_ctx->use_cnt))
909 + ix_sa_ctx_destroy(sa_ctx);
913 + /* We are registering */
914 + switch (cr_cont->ctl.crypt.mode) {
915 + case NPE_OP_HASH_GEN_ICV:
916 + /* 1 out of 2 HMAC preparation operations completed */
917 + dma_unmap_single(sa_ctx->master->npe_dev,
918 + cont->eth.phys_addr,
922 + qmgr_return_cont(dev_get_drvdata(queue->dev), cont);
924 + case NPE_OP_ENC_GEN_KEY:
925 + memcpy(sa_ctx->decrypt.npe_ctx + sizeof(u32),
926 + sa_ctx->rev_aes->ctl.rev_aes_key + sizeof(u32),
927 + sa_ctx->c_key.len);
928 + /* REV AES data not needed anymore, free it */
929 + ix_sa_return_cont(sa_ctx->master, sa_ctx->rev_aes);
930 + sa_ctx->rev_aes = NULL;
933 + printk(KERN_ERR "Unknown crypt-register mode: %x\n",
934 + cr_cont->ctl.crypt.mode);
937 + if (cr_cont->ctl.crypt.oper_type == OP_REG_DONE) {
938 + if (sa_ctx->state == STATE_UNREGISTERED)
939 + sa_ctx->state = STATE_REGISTERED;
940 + if (sa_ctx->reg_cb)
941 + sa_ctx->reg_cb(sa_ctx, failed);
943 + ix_sa_return_cont(sa_ctx->master, cr_cont);
944 + if (atomic_dec_and_test(&sa_ctx->use_cnt))
945 + ix_sa_ctx_destroy(sa_ctx);
948 +static void irqcb_recv(struct qm_queue *queue)
952 + queue_ack_irq(queue);
953 + while ((phys = queue_get_entry(queue)))
954 + recv_pack(queue, phys);
957 +static int init_sa_dir(struct ix_sa_ctx *sa_ctx, struct ix_sa_dir *dir)
959 + dir->npe_ctx = dma_pool_alloc(sa_ctx->master->dmapool,
960 + sa_ctx->gfp_flags, &dir->npe_ctx_phys);
961 + if (!dir->npe_ctx) {
964 + memset(dir->npe_ctx, 0, NPE_CTX_LEN);
968 +struct ix_sa_ctx *ix_sa_ctx_new(int priv_len, gfp_t flags)
970 + struct ix_sa_ctx *sa_ctx;
971 + struct ix_sa_master *master = &sa_master;
972 + struct npe_info *npe = dev_get_drvdata(master->npe_dev);
974 + /* first check if Microcode was downloaded into this NPE */
975 + if (!( npe_status(npe) & IX_NPEDL_EXCTL_STATUS_RUN)) {
976 + printk(KERN_ERR "%s not running\n", npe->plat->name);
979 + switch (npe->img_info[1]) {
984 + /* No crypto Microcode */
987 + if (!try_module_get(THIS_MODULE)) {
991 + sa_ctx = kzalloc(sizeof(struct ix_sa_ctx) + priv_len, flags);
996 + sa_ctx->master = master;
997 + sa_ctx->gfp_flags = flags;
999 + if (init_sa_dir(sa_ctx, &sa_ctx->encrypt))
1001 + if (init_sa_dir(sa_ctx, &sa_ctx->decrypt)) {
1002 + free_sa_dir(sa_ctx, &sa_ctx->encrypt);
1006 + sa_ctx->priv = sa_ctx + 1;
1008 + atomic_set(&sa_ctx->use_cnt, 1);
1014 + module_put(THIS_MODULE);
1018 +void ix_sa_ctx_free(struct ix_sa_ctx *sa_ctx)
1020 + sa_ctx->state = STATE_UNLOADING;
1021 + if (atomic_dec_and_test(&sa_ctx->use_cnt))
1022 + ix_sa_ctx_destroy(sa_ctx);
1024 + printk("ix_sa_ctx_free -> delayed: %p %d\n",
1025 + sa_ctx, atomic_read(&sa_ctx->use_cnt));
1028 +/* http://www.ietf.org/rfc/rfc2104.txt */
1029 +#define HMAC_IPAD_VALUE 0x36
1030 +#define HMAC_OPAD_VALUE 0x5C
1031 +#define PAD_BLOCKLEN 64
1033 +static int register_chain_var(struct ix_sa_ctx *sa_ctx,
1034 + unsigned char *pad, u32 target, int init_len, u32 ctx_addr, int oper)
1036 + struct npe_crypt_cont *cr_cont;
1037 + struct npe_cont *cont;
1039 + cr_cont = ix_sa_get_cont(sa_ctx->master);
1043 + cr_cont->ctl.crypt.sa_ctx = sa_ctx;
1044 + cr_cont->ctl.crypt.auth_offs = 0;
1045 + cr_cont->ctl.crypt.auth_len =cpu_to_npe16(PAD_BLOCKLEN);
1046 + cr_cont->ctl.crypt.crypto_ctx = cpu_to_npe32(ctx_addr);
1048 + cont = qmgr_get_cont(dev_get_drvdata(sa_ctx->master->sendq->dev));
1050 + ix_sa_return_cont(sa_ctx->master, cr_cont);
1055 + cont->eth.next = 0;
1056 + cont->eth.buf_len = cpu_to_npe16(PAD_BLOCKLEN);
1057 + cont->eth.pkt_len = 0;
1059 + cont->eth.phys_addr = cpu_to_npe32(dma_map_single(
1060 + sa_ctx->master->npe_dev, pad, PAD_BLOCKLEN, DMA_TO_DEVICE));
1062 + cr_cont->ctl.crypt.src_buf = cpu_to_npe32(cont->phys);
1063 + cr_cont->ctl.crypt.oper_type = oper;
1065 + cr_cont->ctl.crypt.addr.icv = cpu_to_npe32(target);
1066 + cr_cont->ctl.crypt.mode = NPE_OP_HASH_GEN_ICV;
1067 + cr_cont->ctl.crypt.init_len = init_len;
1069 + atomic_inc(&sa_ctx->use_cnt);
1070 + queue_put_entry(sa_ctx->master->sendq, cr_cont->phys);
1071 + if (queue_stat(sa_ctx->master->sendq) == 2) { /* overflow */
1072 + atomic_dec(&sa_ctx->use_cnt);
1073 + qmgr_return_cont(dev_get_drvdata(sa_ctx->master->sendq->dev),
1075 + ix_sa_return_cont(sa_ctx->master, cr_cont);
1082 + * 0 if nothing registered,
1083 + * 1 if something registered and
1086 +static int ix_sa_ctx_setup_auth(struct ix_sa_ctx *sa_ctx,
1087 + const struct ix_hash_algo *algo, int len, int oper, int encrypt)
1089 + unsigned char *ipad, *opad;
1090 + u32 itarget, otarget, ctx_addr;
1091 + unsigned char *cinfo;
1092 + int init_len, i, ret = 0;
1093 + struct qm_qmgr *qmgr;
1094 + struct ix_sa_dir *dir;
1097 + dir = encrypt ? &sa_ctx->encrypt : &sa_ctx->decrypt;
1098 + cinfo = dir->npe_ctx + dir->npe_ctx_idx;
1100 + qmgr = dev_get_drvdata(sa_ctx->master->sendq->dev);
1102 + cinfo = dir->npe_ctx + dir->npe_ctx_idx;
1103 + sa_ctx->h_algo = algo;
1106 + dir->npe_mode |= NPE_OP_HMAC_DISABLE;
1109 + if (algo->type == HASH_TYPE_CBCMAC) {
1110 + dir->npe_mode |= NPE_OP_CCM_ENABLE | NPE_OP_HMAC_DISABLE;
1113 + if (sa_ctx->h_key.len > 64 || sa_ctx->h_key.len < algo->digest_len)
1115 + if (len > algo->digest_len || (len % 4))
1118 + len = algo->digest_len;
1120 + sa_ctx->digest_len = len;
1122 + /* write cfg word to cryptinfo */
1123 + cfgword = algo->cfgword | ((len/4) << 8);
1124 + *(u32*)cinfo = cpu_to_be32(cfgword);
1125 + cinfo += sizeof(cfgword);
1127 + /* write ICV to cryptinfo */
1128 + memcpy(cinfo, algo->icv, algo->digest_len);
1129 + cinfo += algo->digest_len;
1131 + itarget = dir->npe_ctx_phys + dir->npe_ctx_idx
1132 + + sizeof(algo->cfgword);
1133 + otarget = itarget + algo->digest_len;
1135 + opad = kzalloc(PAD_BLOCKLEN, sa_ctx->gfp_flags | GFP_DMA);
1139 + ipad = kzalloc(PAD_BLOCKLEN, sa_ctx->gfp_flags | GFP_DMA);
1144 + memcpy(ipad, sa_ctx->h_key.key, sa_ctx->h_key.len);
1145 + memcpy(opad, sa_ctx->h_key.key, sa_ctx->h_key.len);
1146 + for (i = 0; i < PAD_BLOCKLEN; i++) {
1147 + ipad[i] ^= HMAC_IPAD_VALUE;
1148 + opad[i] ^= HMAC_OPAD_VALUE;
1150 + init_len = cinfo - (dir->npe_ctx + dir->npe_ctx_idx);
1151 + ctx_addr = dir->npe_ctx_phys + dir->npe_ctx_idx;
1153 + dir->npe_ctx_idx += init_len;
1154 + dir->npe_mode |= NPE_OP_HASH_ENABLE;
1157 + dir->npe_mode |= NPE_OP_HASH_VERIFY;
1159 + /* register first chainvar */
1160 + ret = register_chain_var(sa_ctx, opad, otarget,
1161 + init_len, ctx_addr, OP_REGISTER);
1168 + /* register second chainvar */
1169 + ret = register_chain_var(sa_ctx, ipad, itarget,
1170 + init_len, ctx_addr, oper);
1179 +static int gen_rev_aes_key(struct ix_sa_ctx *sa_ctx,
1180 + u32 keylen_cfg, int cipher_op)
1182 + unsigned char *cinfo;
1183 + struct npe_crypt_cont *cr_cont;
1185 + keylen_cfg |= CIPH_ENCR | ALGO_AES | MOD_ECB;
1186 + sa_ctx->rev_aes = ix_sa_get_cont(sa_ctx->master);
1187 + if (!sa_ctx->rev_aes)
1190 + cinfo = sa_ctx->rev_aes->ctl.rev_aes_key;
1191 + *(u32*)cinfo = cpu_to_be32(keylen_cfg);
1192 + cinfo += sizeof(keylen_cfg);
1194 + memcpy(cinfo, sa_ctx->c_key.key, sa_ctx->c_key.len);
1196 + cr_cont = ix_sa_get_cont(sa_ctx->master);
1198 + ix_sa_return_cont(sa_ctx->master, sa_ctx->rev_aes);
1199 + sa_ctx->rev_aes = NULL;
1202 + cr_cont->ctl.crypt.sa_ctx = sa_ctx;
1203 + cr_cont->ctl.crypt.oper_type = cipher_op;
1205 + cr_cont->ctl.crypt.crypt_offs = 0;
1206 + cr_cont->ctl.crypt.crypt_len = cpu_to_npe16(AES_BLOCK128);
1207 + cr_cont->ctl.crypt.addr.rev_aes = cpu_to_npe32(
1208 + sa_ctx->rev_aes->phys + sizeof(keylen_cfg));
1210 + cr_cont->ctl.crypt.src_buf = 0;
1211 + cr_cont->ctl.crypt.crypto_ctx = cpu_to_npe32(sa_ctx->rev_aes->phys);
1212 + cr_cont->ctl.crypt.mode = NPE_OP_ENC_GEN_KEY;
1213 + cr_cont->ctl.crypt.init_len = sa_ctx->decrypt.npe_ctx_idx;
1215 + atomic_inc(&sa_ctx->use_cnt);
1216 + queue_put_entry(sa_ctx->master->sendq, cr_cont->phys);
1217 + if (queue_stat(sa_ctx->master->sendq) == 2) { /* overflow */
1218 + atomic_dec(&sa_ctx->use_cnt);
1219 + ix_sa_return_cont(sa_ctx->master, cr_cont);
1220 + ix_sa_return_cont(sa_ctx->master, sa_ctx->rev_aes);
1221 + sa_ctx->rev_aes = NULL;
1229 + * 0 if nothing registered,
1230 + * 1 if something registered and
1233 +static int ix_sa_ctx_setup_cipher(struct ix_sa_ctx *sa_ctx,
1234 + const struct ix_cipher_algo *algo, int cipher_op, int encrypt)
1236 + unsigned char *cinfo;
1237 + int keylen, init_len;
1239 + u32 keylen_cfg = 0;
1240 + struct ix_sa_dir *dir;
1242 + dir = encrypt ? &sa_ctx->encrypt : &sa_ctx->decrypt;
1243 + cinfo = dir->npe_ctx + dir->npe_ctx_idx;
1245 + sa_ctx->c_algo = algo;
1250 + if (algo->type == CIPHER_TYPE_DES && sa_ctx->c_key.len != 8)
1253 + if (algo->type == CIPHER_TYPE_3DES && sa_ctx->c_key.len != 24)
1259 + cipher_cfg = algo->cfgword_enc;
1260 + dir->npe_mode |= NPE_OP_CRYPT_ENCRYPT;
1262 + cipher_cfg = algo->cfgword_dec;
1264 + if (algo->type == CIPHER_TYPE_AES) {
1265 + switch (sa_ctx->c_key.len) {
1266 + case 16: keylen_cfg = MOD_AES128 | KEYLEN_128; break;
1267 + case 24: keylen_cfg = MOD_AES192 | KEYLEN_192; break;
1268 + case 32: keylen_cfg = MOD_AES256 | KEYLEN_256; break;
1269 + default: return -EINVAL;
1271 + keylen = sa_ctx->c_key.len;
1272 + cipher_cfg |= keylen_cfg;
1275 + /* write cfg word to cryptinfo */
1276 + *(u32*)cinfo = cpu_to_be32(cipher_cfg);
1277 + cinfo += sizeof(cipher_cfg);
1279 + /* write cipher key to cryptinfo */
1280 + memcpy(cinfo, sa_ctx->c_key.key, sa_ctx->c_key.len);
1283 + init_len = cinfo - (dir->npe_ctx + dir->npe_ctx_idx);
1284 + dir->npe_ctx_idx += init_len;
1286 + dir->npe_mode |= NPE_OP_CRYPT_ENABLE;
1288 + if (algo->type == CIPHER_TYPE_AES && !encrypt) {
1289 + return gen_rev_aes_key(sa_ctx, keylen_cfg, cipher_op);
1295 +/* returns 0 on OK, <0 on error and 1 on overflow */
1296 +int ix_sa_crypto_perform(struct ix_sa_ctx *sa_ctx, u8 *data, void *ptr,
1297 + int datalen, int c_offs, int c_len, int a_offs, int a_len,
1298 + int hmac, char *iv, int encrypt)
1300 + struct npe_crypt_cont *cr_cont;
1301 + struct npe_cont *cont;
1303 + int ret = -ENOMEM;
1304 + struct ix_sa_dir *dir;
1306 + dir = encrypt ? &sa_ctx->encrypt : &sa_ctx->decrypt;
1308 + if (sa_ctx->state != STATE_REGISTERED)
1311 + cr_cont = ix_sa_get_cont(sa_ctx->master);
1315 + cr_cont->ctl.crypt.sa_ctx = sa_ctx;
1316 + cr_cont->ctl.crypt.crypto_ctx = cpu_to_npe32(dir->npe_ctx_phys);
1317 + cr_cont->ctl.crypt.oper_type = OP_PERFORM;
1318 + cr_cont->ctl.crypt.mode = dir->npe_mode;
1319 + cr_cont->ctl.crypt.init_len = dir->npe_ctx_idx;
1321 + if (sa_ctx->c_algo) {
1322 + cr_cont->ctl.crypt.crypt_offs = cpu_to_npe16(c_offs);
1323 + cr_cont->ctl.crypt.crypt_len = cpu_to_npe16(c_len);
1324 + if (sa_ctx->c_algo->iv_len) {
1329 + memcpy(cr_cont->ctl.crypt.iv, iv,
1330 + sa_ctx->c_algo->iv_len);
1334 + if (sa_ctx->h_algo) {
1335 + /* prepare hashing */
1336 + cr_cont->ctl.crypt.auth_offs = cpu_to_npe16(a_offs);
1337 + cr_cont->ctl.crypt.auth_len = cpu_to_npe16(a_len);
1340 + data_phys = dma_map_single(sa_ctx->master->npe_dev,
1341 + data, datalen, DMA_BIDIRECTIONAL);
1343 + cr_cont->ctl.crypt.addr.icv = cpu_to_npe32(data_phys + hmac);
1345 + /* Prepare the data ptr */
1346 + cont = qmgr_get_cont(dev_get_drvdata(sa_ctx->master->sendq->dev));
1352 + cont->eth.next = 0;
1353 + cont->eth.buf_len = cpu_to_npe16(datalen);
1354 + cont->eth.pkt_len = 0;
1356 + cont->eth.phys_addr = cpu_to_npe32(data_phys);
1357 + cr_cont->ctl.crypt.src_buf = cpu_to_npe32(cont->phys);
1359 + atomic_inc(&sa_ctx->use_cnt);
1360 + queue_put_entry(sa_ctx->master->sendq, cr_cont->phys);
1361 + if (queue_stat(sa_ctx->master->sendq) != 2) {
1366 + printk("%s: Overflow\n", __FUNCTION__);
1368 + atomic_dec(&sa_ctx->use_cnt);
1369 + qmgr_return_cont(dev_get_drvdata(sa_ctx->master->sendq->dev), cont);
1372 + dma_unmap_single(sa_ctx->master->npe_dev, data_phys, datalen,
1373 + DMA_BIDIRECTIONAL);
1375 + ix_sa_return_cont(sa_ctx->master, cr_cont);
1380 +int ix_sa_ctx_setup_cipher_auth(struct ix_sa_ctx *sa_ctx,
1381 + const struct ix_cipher_algo *cipher,
1382 + const struct ix_hash_algo *auth, int len)
1384 + int ret = 0, sum = 0;
1387 + if (sa_ctx->state != STATE_UNREGISTERED)
1390 + atomic_inc(&sa_ctx->use_cnt);
1392 + cipher_op = auth ? OP_REGISTER : OP_REG_DONE;
1393 + if ((ret = ix_sa_ctx_setup_cipher(sa_ctx, cipher, OP_REGISTER, 1)) < 0)
1396 + if ((ret = ix_sa_ctx_setup_cipher(sa_ctx, cipher, cipher_op, 0)) < 0)
1399 + if ((ret = ix_sa_ctx_setup_auth(sa_ctx, auth, len, OP_REGISTER, 1)) < 0)
1402 + if ((ret = ix_sa_ctx_setup_auth(sa_ctx, auth, len, OP_REG_DONE, 0)) < 0)
1406 + /* Nothing registered ?
1407 + * Ok, then we are done and call the callback here.
1410 + if (sa_ctx->state == STATE_UNREGISTERED)
1411 + sa_ctx->state = STATE_REGISTERED;
1412 + if (sa_ctx->reg_cb)
1413 + sa_ctx->reg_cb(sa_ctx, 0);
1416 + atomic_dec(&sa_ctx->use_cnt);
1420 +static int __init init_crypto(void)
1422 + return init_sa_master(&sa_master);
1425 +static void __exit finish_crypto(void)
1427 + release_sa_master(&sa_master);
1430 +MODULE_LICENSE("GPL");
1431 +MODULE_AUTHOR("Christian Hohnstaedt <chohnstaedt@innominate.com>");
1433 +EXPORT_SYMBOL(ix_hash_by_id);
1434 +EXPORT_SYMBOL(ix_cipher_by_id);
1436 +EXPORT_SYMBOL(ix_sa_ctx_new);
1437 +EXPORT_SYMBOL(ix_sa_ctx_free);
1438 +EXPORT_SYMBOL(ix_sa_ctx_setup_cipher_auth);
1439 +EXPORT_SYMBOL(ix_sa_crypto_perform);
1441 +module_init(init_crypto);
1442 +module_exit(finish_crypto);
1444 Index: linux-2.6.21.7/drivers/net/ixp4xx/ixp4xx_qmgr.c
1445 ===================================================================
1447 +++ linux-2.6.21.7/drivers/net/ixp4xx/ixp4xx_qmgr.c
1450 + * qmgr.c - reimplementation of the queue configuration interface.
1452 + * Copyright (C) 2006 Christian Hohnstaedt <chohnstaedt@innominate.com>
1454 + * This file is released under the GPLv2
1457 +#include <linux/kernel.h>
1458 +#include <linux/module.h>
1459 +#include <linux/platform_device.h>
1460 +#include <linux/fs.h>
1461 +#include <linux/init.h>
1462 +#include <linux/slab.h>
1463 +#include <linux/dmapool.h>
1464 +#include <linux/interrupt.h>
1465 +#include <linux/err.h>
1466 +#include <linux/delay.h>
1467 +#include <asm/uaccess.h>
1468 +#include <asm/io.h>
1470 +#include <linux/ixp_qmgr.h>
1471 +#include <linux/ixp_npe.h>
1473 +#define IXQMGR_VERSION "IXP4XX Q Manager 0.2.1"
1475 +static struct device *qmgr_dev = NULL;
1477 +static int poll_freq = 4000;
1478 +static int poll_enable = 0;
1479 +static u32 timer_countup_ticks;
1481 +module_param(poll_freq, int, 0644);
1482 +module_param(poll_enable, int, 0644);
1484 +int queue_len(struct qm_queue *queue)
1486 + struct qm_qmgr *qmgr = dev_get_drvdata(queue->dev);
1490 + offs = queue->id/8 + QUE_LOW_STAT0;
1491 + val = *(qmgr->addr + IX_QMGR_QCFG_BASE + queue->id);
1493 + diff = (val - (val >> 7)) & 0x7f;
1495 + /* diff == 0 means either empty or full, must look at STAT0 */
1496 + if ((*(qmgr->addr + offs) >> ((queue->id % 8)*4)) & 0x04)
1497 + diff = queue->len;
1502 +static int request_pool(struct device *dev, int count)
1505 + struct npe_cont *cont;
1506 + struct qm_qmgr *qmgr = dev_get_drvdata(dev);
1507 + dma_addr_t handle;
1509 + for (i=0; i<count; i++) {
1510 + cont = dma_pool_alloc(qmgr->dmapool, GFP_KERNEL, &handle);
1514 + cont->phys = handle;
1515 + cont->virt = cont;
1516 + write_lock(&qmgr->lock);
1517 + cont->next = qmgr->pool;
1518 + qmgr->pool = cont;
1519 + write_unlock(&qmgr->lock);
1524 +static int free_pool(struct device *dev, int count)
1527 + struct npe_cont *cont;
1528 + struct qm_qmgr *qmgr = dev_get_drvdata(dev);
1530 + for (i=0; i<count; i++) {
1531 + write_lock(&qmgr->lock);
1532 + cont = qmgr->pool;
1534 + write_unlock(&qmgr->lock);
1537 + qmgr->pool = cont->next;
1538 + write_unlock(&qmgr->lock);
1539 + dma_pool_free(qmgr->dmapool, cont, cont->phys);
1544 +static int get_free_qspace(struct qm_qmgr *qmgr, int len)
1546 + int words = (qmgr->res->end - qmgr->res->start + 1) / 4 -
1547 + IX_QMGR_SRAM_SPACE;
1550 + for (i=0; i<words; i+=len) {
1551 + for (q=0; q<MAX_QUEUES; q++) {
1552 + struct qm_queue *qu = qmgr->queues[q];
1555 + if ((qu->addr + qu->len > i) && (qu->addr < i + len))
1558 + if (q == MAX_QUEUES) {
1559 + /* we have a free address */
1566 +static inline int _log2(int x)
1575 + * 32bit Config registers at IX_QMGR_QUECONFIG_BASE_OFFSET[Qid]
1576 + * 0 - 6 WRPTR Word offset to baseaddr (index 0 .. BSIZE-1)
1578 + * 14 -21 BADDR baseaddr = (offset to IX_QMGR_QUEBUFFER_SPACE_OFFSET) >> 6
1579 + * 22 -23 ESIZE entrySizeInWords (always 00 because entrySizeInWords==1)
1580 + * 24 -25 BSIZE qSizeInWords 00=16,01=32,10=64,11=128
1581 + * 26 -28 NE nearly empty
1582 + * 29 -31 NF nearly full
1584 +static int conf_q_regs(struct qm_queue *queue)
1586 + int bsize = _log2(queue->len/16);
1587 + int baddr = queue->addr + IX_QMGR_QCFG_SIZE;
1589 + /* +2, because baddr is in words and not in bytes */
1590 + queue_write_cfg_reg(queue, (bsize << 24) | (baddr<<(14-6+2)) );
1595 +static void pmu_timer_restart(void)
1597 + unsigned long flags;
1599 + local_irq_save(flags);
1601 + __asm__(" mcr p14,0,%0,c1,c1,0\n" /* write current counter */
1602 + : : "r" (timer_countup_ticks));
1604 + __asm__(" mrc p14,0,r1,c4,c1,0; " /* get int enable register */
1606 + " mcr p14,0,r1,c5,c1,0; " /* clear overflow */
1607 + " mcr p14,0,r1,c4,c1,0\n" /* enable interrupts */
1610 + local_irq_restore(flags);
1613 +static void pmu_timer_init(void)
1615 + u32 controlRegisterMask =
1616 + BIT(0) | /* enable counters */
1617 + BIT(2); /* reset clock counter; */
1620 + * Compute the number of xscale cycles needed between each
1621 + * PMU IRQ. This is done from the result of an OS calibration loop.
1623 + * For 533MHz CPU, 533000000 tick/s / 4000 times/sec = 138250
1624 + * 4000 times/sec = 37 mbufs/interrupt at line rate
1625 + * The pmu timer is reset to -138250 = 0xfffde3f6, to trigger an IRQ
1626 + * when this up counter overflows.
1628 + * The multiplication gives a number of instructions per second.
1629 + * which is close to the processor frequency, and then close to the
1632 + * 2 is the number of instructions per loop
1636 + timer_countup_ticks = - ((loops_per_jiffy * HZ * 2) / poll_freq);
1638 + /* enable the CCNT (clock count) timer from the PMU */
1639 + __asm__(" mcr p14,0,%0,c0,c1,0\n"
1640 + : : "r" (controlRegisterMask));
1643 +static void pmu_timer_disable(void)
1645 + unsigned long flags;
1647 + local_irq_save(flags);
1649 + __asm__(" mrc p14,0,r1,c4,c1,0; " /* get int enable register */
1650 + " and r1,r1,#0x1e; "
1651 + " mcr p14,0,r1,c4,c1,0\n" /* disable interrupts */
1653 + local_irq_restore(flags);
1656 +void queue_set_watermarks(struct qm_queue *queue, unsigned ne, unsigned nf)
1659 + /* calculate the register values
1660 + * 0->0, 1->1, 2->2, 4->3, 8->4 16->5...*/
1661 + ne = _log2(ne<<1) & 0x7;
1662 + nf = _log2(nf<<1) & 0x7;
1664 + /* Mask out old watermarks */
1665 + val = queue_read_cfg_reg(queue) & ~0xfc000000;
1666 + queue_write_cfg_reg(queue, val | (ne << 26) | (nf << 29));
1669 +int queue_set_irq_src(struct qm_queue *queue, int flag)
1671 + struct qm_qmgr *qmgr = dev_get_drvdata(queue->dev);
1673 + int offs, bitoffs;
1675 + /* Q 0-7 are in REG0, 8-15 are in REG1, etc. They occupy 4 bits/Q */
1676 + offs = queue->id/8 + INT0_SRC_SELREG0;
1677 + bitoffs = (queue->id % 8)*4;
1679 + reg = *(qmgr->addr + offs) & ~(0xf << bitoffs);
1680 + *(qmgr->addr + offs) = reg | (flag << bitoffs);
1685 +static irqreturn_t irq_qm1(int irq, void *dev_id)
1687 + struct qm_qmgr *qmgr = dev_id;
1689 + struct qm_queue *queue;
1692 + pmu_timer_restart();
1694 + reg = *(qmgr->addr + QUE_INT_REG0);
1697 + * count leading zeros. "offs" gets
1698 + * the amount of leading 0 in "reg"
1700 + asm ("clz %0, %1;" : "=r"(offs) : "r"(reg));
1702 + reg &= ~(1 << offs);
1703 + queue = qmgr->queues[offs];
1704 + if (likely(queue)) {
1705 + if (likely(queue->irq_cb)) {
1706 + queue->irq_cb(queue);
1708 + printk(KERN_ERR "Missing callback for Q %d\n",
1712 + printk(KERN_ERR "IRQ for unregistered Q %d\n", offs);
1715 + return IRQ_HANDLED;
1718 +struct qm_queue *request_queue(int qid, int len)
1721 + struct qm_qmgr *qmgr;
1722 + struct qm_queue *queue;
1725 + return ERR_PTR(-ENODEV);
1727 + if ((qid < 0) || (qid > MAX_QUEUES))
1728 + return ERR_PTR(-ERANGE);
1735 + default : return ERR_PTR(-EINVAL);
1738 + qmgr = dev_get_drvdata(qmgr_dev);
1740 + if (qmgr->queues[qid]) {
1741 + /* not an error, just in use already */
1744 + if ((ram = get_free_qspace(qmgr, len)) < 0) {
1745 + printk(KERN_ERR "No free SRAM space for this queue\n");
1746 + return ERR_PTR(-ENOMEM);
1748 + if (!(queue = kzalloc(sizeof(struct qm_queue), GFP_KERNEL)))
1749 + return ERR_PTR(-ENOMEM);
1751 + if (!try_module_get(THIS_MODULE)) {
1753 + return ERR_PTR(-ENODEV);
1756 + queue->addr = ram;
1759 + queue->dev = get_device(qmgr_dev);
1760 + queue->acc_reg = qmgr->addr + (4 * qid);
1761 + qmgr->queues[qid] = queue;
1762 + if (request_pool(qmgr_dev, len)) {
1763 + printk(KERN_ERR "Failed to request DMA pool of Q %d\n", qid);
1766 + conf_q_regs(queue);
1770 +void release_queue(struct qm_queue *queue)
1772 + struct qm_qmgr *qmgr = dev_get_drvdata(queue->dev);
1774 + BUG_ON(qmgr->queues[queue->id] != queue);
1775 + qmgr->queues[queue->id] = NULL;
1777 + if (free_pool(queue->dev, queue->len)) {
1778 + printk(KERN_ERR "Failed to release DMA pool of Q %d\n",
1781 + queue_disable_irq(queue);
1782 + queue_write_cfg_reg(queue, 0);
1784 + module_put(THIS_MODULE);
1785 + put_device(queue->dev);
1792 +static int qmgr_probe(struct platform_device *pdev)
1794 + struct resource *res;
1795 + struct qm_qmgr *qmgr;
1796 + int size, ret=0, i;
1798 + if (!(res = platform_get_resource(pdev, IORESOURCE_MEM, 0)))
1801 + if ((i = platform_get_irq(pdev, 0)) < 0)
1804 + if (!(qmgr = kzalloc(sizeof(struct qm_qmgr), GFP_KERNEL)))
1808 + size = res->end - res->start +1;
1809 + qmgr->res = request_mem_region(res->start, size, "ixp_qmgr");
1815 + qmgr->addr = ioremap(res->start, size);
1816 + if (!qmgr->addr) {
1821 + /* Reset Q registers */
1822 + for (i=0; i<4; i++)
1823 + *(qmgr->addr + QUE_LOW_STAT0 +i) = 0x33333333;
1824 + for (i=0; i<10; i++)
1825 + *(qmgr->addr + QUE_UO_STAT0 +i) = 0x0;
1826 + for (i=0; i<4; i++)
1827 + *(qmgr->addr + INT0_SRC_SELREG0 +i) = 0x0;
1828 + for (i=0; i<2; i++) {
1829 + *(qmgr->addr + QUE_IE_REG0 +i) = 0x00;
1830 + *(qmgr->addr + QUE_INT_REG0 +i) = 0xffffffff;
1832 + for (i=0; i<64; i++) {
1833 + *(qmgr->addr + IX_QMGR_QCFG_BASE + i) = 0x0;
1836 + if (poll_enable) {
1838 + qmgr->irq = IRQ_IXP4XX_XSCALE_PMU;
1840 + ret = request_irq(qmgr->irq, irq_qm1, SA_SHIRQ | SA_INTERRUPT,
1843 + printk(KERN_ERR "Failed to request IRQ(%d)\n", qmgr->irq);
1848 + pmu_timer_restart();
1850 + rwlock_init(&qmgr->lock);
1851 + qmgr->dmapool = dma_pool_create("qmgr", &pdev->dev,
1852 + sizeof(struct npe_cont), 32, 0);
1853 + platform_set_drvdata(pdev, qmgr);
1855 + qmgr_dev = &pdev->dev;
1857 + printk(KERN_INFO IXQMGR_VERSION " initialized.\n");
1862 + release_resource(qmgr->res);
1868 +static int qmgr_remove(struct platform_device *pdev)
1870 + struct qm_qmgr *qmgr = platform_get_drvdata(pdev);
1873 + for (i=0; i<MAX_QUEUES; i++) {
1874 + if (qmgr->queues[i]) {
1875 + printk(KERN_ERR "WARNING Unreleased Q: %d\n", i);
1876 + release_queue(qmgr->queues[i]);
1881 + pmu_timer_disable();
1883 + synchronize_irq (qmgr->irq);
1884 + free_irq(qmgr->irq, qmgr);
1886 + dma_pool_destroy(qmgr->dmapool);
1887 + iounmap(qmgr->addr);
1888 + release_resource(qmgr->res);
1889 + platform_set_drvdata(pdev, NULL);
1895 +static struct platform_driver ixp4xx_qmgr = {
1896 + .driver.name = "ixp4xx_qmgr",
1897 + .probe = qmgr_probe,
1898 + .remove = qmgr_remove,
1902 +static int __init init_qmgr(void)
1904 + return platform_driver_register(&ixp4xx_qmgr);
1907 +static void __exit finish_qmgr(void)
1909 + platform_driver_unregister(&ixp4xx_qmgr);
1912 +module_init(init_qmgr);
1913 +module_exit(finish_qmgr);
1915 +MODULE_LICENSE("GPL");
1916 +MODULE_AUTHOR("Christian Hohnstaedt <chohnstaedt@innominate.com>");
1918 +EXPORT_SYMBOL(request_queue);
1919 +EXPORT_SYMBOL(release_queue);
1920 +EXPORT_SYMBOL(queue_set_irq_src);
1921 +EXPORT_SYMBOL(queue_set_watermarks);
1922 +EXPORT_SYMBOL(queue_len);
1923 Index: linux-2.6.21.7/drivers/net/ixp4xx/mac.h
1924 ===================================================================
1926 +++ linux-2.6.21.7/drivers/net/ixp4xx/mac.h
1929 + * Copyright (C) 2002-2006 Christian Hohnstaedt <chohnstaedt@innominate.com>
1931 + * This file is released under the GPLv2
1934 +#include <linux/resource.h>
1935 +#include <linux/netdevice.h>
1936 +#include <linux/io.h>
1937 +#include <linux/mii.h>
1938 +#include <linux/workqueue.h>
1939 +#include <asm/hardware.h>
1940 +#include <linux/ixp_qmgr.h>
1942 +/* 32 bit offsets to be added to u32 *pointers */
1943 +#define MAC_TX_CNTRL1 0x00 // 0x000
1944 +#define MAC_TX_CNTRL2 0x01 // 0x004
1945 +#define MAC_RX_CNTRL1 0x04 // 0x010
1946 +#define MAC_RX_CNTRL2 0x05 // 0x014
1947 +#define MAC_RANDOM_SEED 0x08 // 0x020
1948 +#define MAC_THRESH_P_EMPTY 0x0c // 0x030
1949 +#define MAC_THRESH_P_FULL 0x0e // 0x038
1950 +#define MAC_BUF_SIZE_TX 0x10 // 0x040
1951 +#define MAC_TX_DEFER 0x14 // 0x050
1952 +#define MAC_RX_DEFER 0x15 // 0x054
1953 +#define MAC_TX_TWO_DEFER_1 0x18 // 0x060
1954 +#define MAC_TX_TWO_DEFER_2 0x19 // 0x064
1955 +#define MAC_SLOT_TIME 0x1c // 0x070
1956 +#define MAC_MDIO_CMD 0x20 // 0x080 4 registers 0x20 - 0x23
1957 +#define MAC_MDIO_STS 0x24 // 0x090 4 registers 0x24 - 0x27
1958 +#define MAC_ADDR_MASK 0x28 // 0x0A0 6 registers 0x28 - 0x2d
1959 +#define MAC_ADDR 0x30 // 0x0C0 6 registers 0x30 - 0x35
1960 +#define MAC_INT_CLK_THRESH 0x38 // 0x0E0 1 register
1961 +#define MAC_UNI_ADDR 0x3c // 0x0F0 6 registers 0x3c - 0x41
1962 +#define MAC_CORE_CNTRL 0x7f // 0x1fC
1964 +/* TX Control Register 1*/
1966 +#define TX_CNTRL1_TX_EN BIT(0)
1967 +#define TX_CNTRL1_DUPLEX BIT(1)
1968 +#define TX_CNTRL1_RETRY BIT(2)
1969 +#define TX_CNTRL1_PAD_EN BIT(3)
1970 +#define TX_CNTRL1_FCS_EN BIT(4)
1971 +#define TX_CNTRL1_2DEFER BIT(5)
1972 +#define TX_CNTRL1_RMII BIT(6)
1974 +/* TX Control Register 2 */
1975 +#define TX_CNTRL2_RETRIES_MASK 0xf
1977 +/* RX Control Register 1 */
1978 +#define RX_CNTRL1_RX_EN BIT(0)
1979 +#define RX_CNTRL1_PADSTRIP_EN BIT(1)
1980 +#define RX_CNTRL1_CRC_EN BIT(2)
1981 +#define RX_CNTRL1_PAUSE_EN BIT(3)
1982 +#define RX_CNTRL1_LOOP_EN BIT(4)
1983 +#define RX_CNTRL1_ADDR_FLTR_EN BIT(5)
1984 +#define RX_CNTRL1_RX_RUNT_EN BIT(6)
1985 +#define RX_CNTRL1_BCAST_DIS BIT(7)
1987 +/* RX Control Register 2 */
1988 +#define RX_CNTRL2_DEFER_EN BIT(0)
1990 +/* Core Control Register */
1991 +#define CORE_RESET BIT(0)
1992 +#define CORE_RX_FIFO_FLUSH BIT(1)
1993 +#define CORE_TX_FIFO_FLUSH BIT(2)
1994 +#define CORE_SEND_JAM BIT(3)
1995 +#define CORE_MDC_EN BIT(4)
1997 +/* Definitions for MII access routines*/
1999 +#define MII_REG_SHL 16
2000 +#define MII_ADDR_SHL 21
2002 +#define MII_GO BIT(31)
2003 +#define MII_WRITE BIT(26)
2004 +#define MII_READ_FAIL BIT(31)
2006 +#define MII_TIMEOUT_10TH_SECS 5
2007 +#define MII_10TH_SEC_IN_MILLIS 100
2015 +#define MAC_DEF_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
2017 +#define MAC_TX_CNTRL1_DEFAULT (\
2018 + TX_CNTRL1_TX_EN | \
2019 + TX_CNTRL1_RETRY | \
2020 + TX_CNTRL1_FCS_EN | \
2021 + TX_CNTRL1_2DEFER | \
2022 + TX_CNTRL1_PAD_EN )
2024 +#define MAC_TX_MAX_RETRIES_DEFAULT 0x0f
2026 +#define MAC_RX_CNTRL1_DEFAULT ( \
2027 + RX_CNTRL1_PADSTRIP_EN | \
2028 + RX_CNTRL1_CRC_EN | \
2031 +#define MAC_RX_CNTRL2_DEFAULT 0x0
2032 +#define MAC_TX_CNTRL2_DEFAULT TX_CNTRL2_RETRIES_MASK
2034 +/* Thresholds determined by NPE firmware FS */
2035 +#define MAC_THRESH_P_EMPTY_DEFAULT 0x12
2036 +#define MAC_THRESH_P_FULL_DEFAULT 0x30
2038 +/* Number of bytes that must be in the tx fifo before
2039 + * transmission commences */
2040 +#define MAC_BUF_SIZE_TX_DEFAULT 0x8
2042 +/* One-part deferral values */
2043 +#define MAC_TX_DEFER_DEFAULT 0x15
2044 +#define MAC_RX_DEFER_DEFAULT 0x16
2046 +/* Two-part deferral values... */
2047 +#define MAC_TX_TWO_DEFER_1_DEFAULT 0x08
2048 +#define MAC_TX_TWO_DEFER_2_DEFAULT 0x07
2050 +/* This value applies to MII */
2051 +#define MAC_SLOT_TIME_DEFAULT 0x80
2053 +/* This value applies to RMII */
2054 +#define MAC_SLOT_TIME_RMII_DEFAULT 0xFF
2056 +#define MAC_ADDR_MASK_DEFAULT 0xFF
2058 +#define MAC_INT_CLK_THRESH_DEFAULT 0x1
2059 +/* The following is a value chosen at random */
2060 +#define MAC_RANDOM_SEED_DEFAULT 0x8
2062 +/* By default we must configure the MAC to generate the MDC clock*/
2063 +#define CORE_DEFAULT (CORE_MDC_EN)
2065 +/* End of Intel provided register information */
2068 +mdio_read_register(struct net_device *dev, int phy_addr, int phy_reg);
2070 +mdio_write_register(struct net_device *dev, int phy_addr, int phy_reg, int val);
2071 +extern void init_mdio(struct net_device *dev, int phy_id);
2074 + u32 __iomem *addr;
2075 + struct resource *res;
2076 + struct device *npe_dev;
2077 + struct net_device *netdev;
2078 + struct qm_qmgr *qmgr;
2079 + struct qm_queue *rxq;
2080 + struct qm_queue *txq;
2081 + struct qm_queue *rxdoneq;
2083 + struct net_device_stats stat;
2084 + struct mii_if_info mii;
2085 + struct delayed_work mdio_thread;
2089 + struct mac_plat_info *plat;
2091 + spinlock_t rx_lock;
2095 +static inline void mac_write_reg(struct mac_info *mac, int offset, u32 val)
2097 + *(mac->addr + offset) = val;
2099 +static inline u32 mac_read_reg(struct mac_info *mac, int offset)
2101 + return *(mac->addr + offset);
2103 +static inline void mac_set_regbit(struct mac_info *mac, int offset, u32 bit)
2105 + mac_write_reg(mac, offset, mac_read_reg(mac, offset) | bit);
2107 +static inline void mac_reset_regbit(struct mac_info *mac, int offset, u32 bit)
2109 + mac_write_reg(mac, offset, mac_read_reg(mac, offset) & ~bit);
2112 +static inline void mac_mdio_cmd_write(struct mac_info *mac, u32 cmd)
2115 + for(i=0; i<4; i++) {
2116 + mac_write_reg(mac, MAC_MDIO_CMD + i, cmd & 0xff);
2121 +#define mac_mdio_cmd_read(mac) mac_mdio_read((mac), MAC_MDIO_CMD)
2122 +#define mac_mdio_status_read(mac) mac_mdio_read((mac), MAC_MDIO_STS)
2123 +static inline u32 mac_mdio_read(struct mac_info *mac, int offset)
2127 + for(i=0; i<4; i++) {
2128 + data |= (mac_read_reg(mac, offset + i) & 0xff) << (i*8);
2133 +static inline u32 mdio_cmd(int phy_addr, int phy_reg)
2135 + return phy_addr << MII_ADDR_SHL |
2136 + phy_reg << MII_REG_SHL |
2140 +#define MAC_REG_LIST { \
2141 + MAC_TX_CNTRL1, MAC_TX_CNTRL2, \
2142 + MAC_RX_CNTRL1, MAC_RX_CNTRL2, \
2143 + MAC_RANDOM_SEED, MAC_THRESH_P_EMPTY, MAC_THRESH_P_FULL, \
2144 + MAC_BUF_SIZE_TX, MAC_TX_DEFER, MAC_RX_DEFER, \
2145 + MAC_TX_TWO_DEFER_1, MAC_TX_TWO_DEFER_2, MAC_SLOT_TIME, \
2146 + MAC_ADDR_MASK +0, MAC_ADDR_MASK +1, MAC_ADDR_MASK +2, \
2147 + MAC_ADDR_MASK +3, MAC_ADDR_MASK +4, MAC_ADDR_MASK +5, \
2148 + MAC_ADDR +0, MAC_ADDR +1, MAC_ADDR +2, \
2149 + MAC_ADDR +3, MAC_ADDR +4, MAC_ADDR +5, \
2150 + MAC_INT_CLK_THRESH, \
2151 + MAC_UNI_ADDR +0, MAC_UNI_ADDR +1, MAC_UNI_ADDR +2, \
2152 + MAC_UNI_ADDR +3, MAC_UNI_ADDR +4, MAC_UNI_ADDR +5, \
2156 +#define NPE_STAT_NUM 34
2157 +#define NPE_STAT_NUM_BASE 22
2158 +#define NPE_Q_STAT_NUM 4
2160 +#define NPE_Q_STAT_STRINGS \
2161 + {"RX ready to use queue len "}, \
2162 + {"RX received queue len "}, \
2163 + {"TX to be send queue len "}, \
2164 + {"TX done queue len "},
2166 +#define NPE_STAT_STRINGS \
2167 + {"StatsAlignmentErrors "}, \
2168 + {"StatsFCSErrors "}, \
2169 + {"StatsInternalMacReceiveErrors "}, \
2170 + {"RxOverrunDiscards "}, \
2171 + {"RxLearnedEntryDiscards "}, \
2172 + {"RxLargeFramesDiscards "}, \
2173 + {"RxSTPBlockedDiscards "}, \
2174 + {"RxVLANTypeFilterDiscards "}, \
2175 + {"RxVLANIdFilterDiscards "}, \
2176 + {"RxInvalidSourceDiscards "}, \
2177 + {"RxBlackListDiscards "}, \
2178 + {"RxWhiteListDiscards "}, \
2179 + {"RxUnderflowEntryDiscards "}, \
2180 + {"StatsSingleCollisionFrames "}, \
2181 + {"StatsMultipleCollisionFrames "}, \
2182 + {"StatsDeferredTransmissions "}, \
2183 + {"StatsLateCollisions "}, \
2184 + {"StatsExcessiveCollsions "}, \
2185 + {"StatsInternalMacTransmitErrors"}, \
2186 + {"StatsCarrierSenseErrors "}, \
2187 + {"TxLargeFrameDiscards "}, \
2188 + {"TxVLANIdFilterDiscards "}, \
2190 + {"RxValidFramesTotalOctets "}, \
2191 + {"RxUcastPkts "}, \
2192 + {"RxBcastPkts "}, \
2193 + {"RxMcastPkts "}, \
2194 + {"RxPkts64Octets "}, \
2195 + {"RxPkts65to127Octets "}, \
2196 + {"RxPkts128to255Octets "}, \
2197 + {"RxPkts256to511Octets "}, \
2198 + {"RxPkts512to1023Octets "}, \
2199 + {"RxPkts1024to1518Octets "}, \
2200 + {"RxInternalNPEReceiveErrors "}, \
2201 + {"TxInternalNPETransmitErrors "}
2203 Index: linux-2.6.21.7/drivers/net/ixp4xx/mac_driver.c
2204 ===================================================================
2206 +++ linux-2.6.21.7/drivers/net/ixp4xx/mac_driver.c
2209 + * mac_driver.c - provide a network interface for each MAC
2211 + * Copyright (C) 2006 Christian Hohnstaedt <chohnstaedt@innominate.com>
2213 + * This file is released under the GPLv2
2216 +#include <linux/kernel.h>
2217 +#include <linux/module.h>
2218 +#include <linux/platform_device.h>
2219 +#include <linux/netdevice.h>
2220 +#include <linux/etherdevice.h>
2221 +#include <linux/ethtool.h>
2222 +#include <linux/slab.h>
2223 +#include <linux/delay.h>
2224 +#include <linux/err.h>
2225 +#include <linux/dma-mapping.h>
2226 +#include <linux/workqueue.h>
2227 +#include <asm/io.h>
2228 +#include <asm/irq.h>
2231 +#include <linux/ixp_qmgr.h>
2232 +#include <linux/ixp_npe.h>
2235 +#define MDIO_INTERVAL (3*HZ)
2236 +#define RX_QUEUE_PREFILL 64
2237 +#define TX_QUEUE_PREFILL 16
2239 +#define IXMAC_NAME "ixp4xx_mac"
2240 +#define IXMAC_VERSION "0.3.1"
2242 +#define MAC_DEFAULT_REG(mac, name) \
2243 + mac_write_reg(mac, MAC_ ## name, MAC_ ## name ## _DEFAULT)
2245 +#define TX_DONE_QID 31
2247 +#define DMA_ALLOC_SIZE 2048
2248 +#define DMA_HDR_SIZE (sizeof(struct npe_cont))
2249 +#define DMA_BUF_SIZE (DMA_ALLOC_SIZE - DMA_HDR_SIZE)
2251 +/* Since the NPEs use 1 Return Q for sent frames, we need a device
2252 + * independent return Q. We call it tx_doneq.
2253 + * It will be initialized during module load and uninitialized
2254 + * during module unload. Evil hack, but there is no choice :-(
2257 +static struct qm_queue *tx_doneq = NULL;
2258 +static int debug = -1;
2259 +module_param(debug, int, 0);
2261 +static int init_buffer(struct qm_queue *queue, int count)
2264 + struct npe_cont *cont;
2266 + for (i=0; i<count; i++) {
2267 + cont = kmalloc(DMA_ALLOC_SIZE, GFP_KERNEL | GFP_DMA);
2271 + cont->phys = dma_map_single(queue->dev, cont, DMA_ALLOC_SIZE,
2272 + DMA_BIDIRECTIONAL);
2273 + if (dma_mapping_error(cont->phys))
2276 + cont->data = cont+1;
2277 + /* now the buffer is on a 32 bit boundary.
2278 + * we add 2 bytes for good alignment to SKB */
2280 + cont->eth.next = 0;
2281 + cont->eth.buf_len = cpu_to_npe16(DMA_BUF_SIZE);
2282 + cont->eth.pkt_len = 0;
2283 + /* also add 2 alignment bytes from cont->data*/
2284 + cont->eth.phys_addr = cpu_to_npe32(cont->phys+ DMA_HDR_SIZE+ 2);
2286 + dma_sync_single(queue->dev, cont->phys, DMA_HDR_SIZE,
2289 + queue_put_entry(queue, cont->phys);
2290 + if (queue_stat(queue) == 2) { /* overflow */
2291 + dma_unmap_single(queue->dev, cont->phys, DMA_ALLOC_SIZE,
2292 + DMA_BIDIRECTIONAL);
2303 +static int destroy_buffer(struct qm_queue *queue, int count)
2307 + struct npe_cont *cont;
2309 + for (i=0; i<count; i++) {
2310 + phys = queue_get_entry(queue) & ~0xf;
2313 + dma_unmap_single(queue->dev, phys, DMA_ALLOC_SIZE,
2314 + DMA_BIDIRECTIONAL);
2315 + cont = dma_to_virt(queue->dev, phys);
2321 +static void mac_init(struct mac_info *mac)
2323 + MAC_DEFAULT_REG(mac, TX_CNTRL2);
2324 + MAC_DEFAULT_REG(mac, RANDOM_SEED);
2325 + MAC_DEFAULT_REG(mac, THRESH_P_EMPTY);
2326 + MAC_DEFAULT_REG(mac, THRESH_P_FULL);
2327 + MAC_DEFAULT_REG(mac, TX_DEFER);
2328 + MAC_DEFAULT_REG(mac, TX_TWO_DEFER_1);
2329 + MAC_DEFAULT_REG(mac, TX_TWO_DEFER_2);
2330 + MAC_DEFAULT_REG(mac, SLOT_TIME);
2331 + MAC_DEFAULT_REG(mac, INT_CLK_THRESH);
2332 + MAC_DEFAULT_REG(mac, BUF_SIZE_TX);
2333 + MAC_DEFAULT_REG(mac, TX_CNTRL1);
2334 + MAC_DEFAULT_REG(mac, RX_CNTRL1);
2337 +static void mac_set_uniaddr(struct net_device *dev)
2340 + struct mac_info *mac = netdev_priv(dev);
2341 + struct npe_info *npe = dev_get_drvdata(mac->npe_dev);
2343 + /* check for multicast */
2344 + if (dev->dev_addr[0] & 1)
2347 + npe_mh_setportaddr(npe, mac->plat, dev->dev_addr);
2348 + npe_mh_disable_firewall(npe, mac->plat);
2349 + for (i=0; i<dev->addr_len; i++)
2350 + mac_write_reg(mac, MAC_UNI_ADDR + i, dev->dev_addr[i]);
2353 +static void update_duplex_mode(struct net_device *dev)
2355 + struct mac_info *mac = netdev_priv(dev);
2356 + if (netif_msg_link(mac)) {
2357 + printk(KERN_DEBUG "Link of %s is %s-duplex\n", dev->name,
2358 + mac->mii.full_duplex ? "full" : "half");
2360 + if (mac->mii.full_duplex) {
2361 + mac_reset_regbit(mac, MAC_TX_CNTRL1, TX_CNTRL1_DUPLEX);
2363 + mac_set_regbit(mac, MAC_TX_CNTRL1, TX_CNTRL1_DUPLEX);
2367 +static int media_check(struct net_device *dev, int init)
2369 + struct mac_info *mac = netdev_priv(dev);
2371 + if (mii_check_media(&mac->mii, netif_msg_link(mac), init)) {
2372 + update_duplex_mode(dev);
2378 +static void get_npe_stats(struct mac_info *mac, u32 *buf, int len, int reset)
2380 + struct npe_info *npe = dev_get_drvdata(mac->npe_dev);
2383 + memset(buf, len, 0);
2384 + phys = dma_map_single(mac->npe_dev, buf, len, DMA_BIDIRECTIONAL);
2385 + npe_mh_get_stats(npe, mac->plat, phys, reset);
2386 + dma_unmap_single(mac->npe_dev, phys, len, DMA_BIDIRECTIONAL);
2389 +static void irqcb_recv(struct qm_queue *queue)
2391 + struct net_device *dev = queue->cb_data;
2393 + queue_ack_irq(queue);
2394 + queue_disable_irq(queue);
2395 + if (netif_running(dev))
2396 + netif_rx_schedule(dev);
2399 +int ix_recv(struct net_device *dev, int *budget, struct qm_queue *queue)
2401 + struct mac_info *mac = netdev_priv(dev);
2402 + struct sk_buff *skb;
2404 + struct npe_cont *cont;
2406 + while (*budget > 0 && netif_running(dev) ) {
2408 + phys = queue_get_entry(queue) & ~0xf;
2411 + dma_sync_single(queue->dev, phys, DMA_HDR_SIZE,
2413 + cont = dma_to_virt(queue->dev, phys);
2414 + len = npe_to_cpu16(cont->eth.pkt_len) -4; /* strip FCS */
2416 + if (unlikely(netif_msg_rx_status(mac))) {
2417 + printk(KERN_DEBUG "%s: RX packet size: %u\n",
2419 + queue_state(mac->rxq);
2420 + queue_state(mac->rxdoneq);
2422 + skb = dev_alloc_skb(len + 2);
2423 + if (likely(skb)) {
2425 + skb_reserve(skb, 2);
2426 + dma_sync_single(queue->dev, cont->eth.phys_addr, len,
2428 +#ifdef CONFIG_NPE_ADDRESS_COHERENT
2429 + /* swap the payload of the SKB */
2431 + u32 *t = (u32*)(skb->data-2);
2432 + u32 *s = (u32*)(cont->data-2);
2433 + int i, j = (len+5)/4;
2434 + for (i=0; i<j; i++)
2435 + t[i] = cpu_to_be32(s[i]);
2438 + eth_copy_and_sum(skb, cont->data, len, 0);
2440 + skb_put(skb, len);
2441 + skb->protocol = eth_type_trans(skb, dev);
2442 + dev->last_rx = jiffies;
2443 + netif_receive_skb(skb);
2444 + mac->stat.rx_packets++;
2445 + mac->stat.rx_bytes += skb->len;
2447 + mac->stat.rx_dropped++;
2449 + cont->eth.buf_len = cpu_to_npe16(DMA_BUF_SIZE);
2450 + cont->eth.pkt_len = 0;
2451 + dma_sync_single(queue->dev, phys, DMA_HDR_SIZE, DMA_TO_DEVICE);
2452 + queue_put_entry(mac->rxq, phys);
2460 +static int ix_poll(struct net_device *dev, int *budget)
2462 + struct mac_info *mac = netdev_priv(dev);
2463 + struct qm_queue *queue = mac->rxdoneq;
2466 + if (ix_recv(dev, budget, queue))
2468 + netif_rx_complete(dev);
2469 + queue_enable_irq(queue);
2470 + if (!queue_len(queue))
2472 + queue_disable_irq(queue);
2473 + if (netif_rx_reschedule(dev, 0))
2479 +static void ixmac_set_rx_mode (struct net_device *dev)
2481 + struct mac_info *mac = netdev_priv(dev);
2482 + struct dev_mc_list *mclist;
2483 + u8 aset[dev->addr_len], aclear[dev->addr_len];
2486 + if (dev->flags & IFF_PROMISC) {
2487 + mac_reset_regbit(mac, MAC_RX_CNTRL1, RX_CNTRL1_ADDR_FLTR_EN);
2489 + mac_set_regbit(mac, MAC_RX_CNTRL1, RX_CNTRL1_ADDR_FLTR_EN);
2491 + mclist = dev->mc_list;
2492 + memset(aset, 0xff, dev->addr_len);
2493 + memset(aclear, 0x00, dev->addr_len);
2494 + for (i = 0; mclist && i < dev->mc_count; i++) {
2495 + for (j=0; j< dev->addr_len; j++) {
2496 + aset[j] &= mclist->dmi_addr[j];
2497 + aclear[j] |= mclist->dmi_addr[j];
2499 + mclist = mclist->next;
2501 + for (j=0; j< dev->addr_len; j++) {
2502 + aclear[j] = aset[j] | ~aclear[j];
2504 + for (i=0; i<dev->addr_len; i++) {
2505 + mac_write_reg(mac, MAC_ADDR + i, aset[i]);
2506 + mac_write_reg(mac, MAC_ADDR_MASK + i, aclear[i]);
2511 +static int ixmac_open (struct net_device *dev)
2513 + struct mac_info *mac = netdev_priv(dev);
2514 + struct npe_info *npe = dev_get_drvdata(mac->npe_dev);
2515 + u32 buf[NPE_STAT_NUM];
2519 + /* first check if the NPE is up and running */
2520 + if (!( npe_status(npe) & IX_NPEDL_EXCTL_STATUS_RUN)) {
2521 + printk(KERN_ERR "%s: %s not running\n", dev->name,
2525 + if (npe_mh_status(npe)) {
2526 + printk(KERN_ERR "%s: %s not responding\n", dev->name,
2530 + mac->txq_pkt += init_buffer(mac->txq, TX_QUEUE_PREFILL - mac->txq_pkt);
2531 + mac->rxq_pkt += init_buffer(mac->rxq, RX_QUEUE_PREFILL - mac->rxq_pkt);
2533 + queue_enable_irq(mac->rxdoneq);
2535 + /* drain all buffers from then RX-done-q to make the IRQ happen */
2536 + while ((phys = queue_get_entry(mac->rxdoneq) & ~0xf)) {
2537 + struct npe_cont *cont;
2538 + cont = dma_to_virt(mac->rxdoneq->dev, phys);
2539 + cont->eth.buf_len = cpu_to_npe16(DMA_BUF_SIZE);
2540 + cont->eth.pkt_len = 0;
2541 + dma_sync_single(mac->rxdoneq->dev, phys, DMA_HDR_SIZE,
2543 + queue_put_entry(mac->rxq, phys);
2546 + npe_mh_set_rxqid(npe, mac->plat, mac->plat->rxdoneq_id);
2547 + get_npe_stats(mac, buf, sizeof(buf), 1); /* reset stats */
2548 + get_npe_stats(mac, buf, sizeof(buf), 0);
2550 + * if the extended stats contain random values
2551 + * the NPE image lacks extendet statistic counters
2553 + for (i=NPE_STAT_NUM_BASE; i<NPE_STAT_NUM; i++) {
2554 + if (buf[i] >10000)
2557 + mac->npe_stat_num = i<NPE_STAT_NUM ? NPE_STAT_NUM_BASE : NPE_STAT_NUM;
2558 + mac->npe_stat_num += NPE_Q_STAT_NUM;
2560 + mac_set_uniaddr(dev);
2561 + media_check(dev, 1);
2562 + ixmac_set_rx_mode(dev);
2563 + netif_start_queue(dev);
2564 + schedule_delayed_work(&mac->mdio_thread, MDIO_INTERVAL);
2565 + if (netif_msg_ifup(mac)) {
2566 + printk(KERN_DEBUG "%s: open " IXMAC_NAME
2567 + " RX queue %d bufs, TX queue %d bufs\n",
2568 + dev->name, mac->rxq_pkt, mac->txq_pkt);
2573 +static int ixmac_start_xmit (struct sk_buff *skb, struct net_device *dev)
2575 + struct mac_info *mac = netdev_priv(dev);
2576 + struct npe_cont *cont;
2578 + struct qm_queue *queue = mac->txq;
2580 + if (unlikely(skb->len > DMA_BUF_SIZE)) {
2581 + dev_kfree_skb(skb);
2582 + mac->stat.tx_errors++;
2583 + return NETDEV_TX_OK;
2585 + phys = queue_get_entry(tx_doneq) & ~0xf;
2588 + cont = dma_to_virt(queue->dev, phys);
2589 +#ifdef CONFIG_NPE_ADDRESS_COHERENT
2590 + /* swap the payload of the SKB */
2592 + u32 *s = (u32*)(skb->data-2);
2593 + u32 *t = (u32*)(cont->data-2);
2594 + int i,j = (skb->len+5) / 4;
2595 + for (i=0; i<j; i++)
2596 + t[i] = cpu_to_be32(s[i]);
2599 + //skb_copy_and_csum_dev(skb, cont->data);
2600 + memcpy(cont->data, skb->data, skb->len);
2602 + cont->eth.buf_len = cpu_to_npe16(DMA_BUF_SIZE);
2603 + cont->eth.pkt_len = cpu_to_npe16(skb->len);
2604 + /* disable VLAN functions in NPE image for now */
2605 + cont->eth.flags = 0;
2606 + dma_sync_single(queue->dev, phys, skb->len + DMA_HDR_SIZE,
2608 + queue_put_entry(queue, phys);
2609 + if (queue_stat(queue) == 2) { /* overflow */
2610 + queue_put_entry(tx_doneq, phys);
2613 + dev_kfree_skb(skb);
2615 + mac->stat.tx_packets++;
2616 + mac->stat.tx_bytes += skb->len;
2617 + dev->trans_start = jiffies;
2618 + if (netif_msg_tx_queued(mac)) {
2619 + printk(KERN_DEBUG "%s: TX packet size %u\n",
2620 + dev->name, skb->len);
2621 + queue_state(mac->txq);
2622 + queue_state(tx_doneq);
2624 + return NETDEV_TX_OK;
2626 + return NETDEV_TX_BUSY;
2629 +static int ixmac_close (struct net_device *dev)
2631 + struct mac_info *mac = netdev_priv(dev);
2633 + netif_stop_queue (dev);
2634 + queue_disable_irq(mac->rxdoneq);
2636 + mac->txq_pkt -= destroy_buffer(tx_doneq, mac->txq_pkt);
2637 + mac->rxq_pkt -= destroy_buffer(mac->rxq, mac->rxq_pkt);
2639 + cancel_rearming_delayed_work(&(mac->mdio_thread));
2641 + if (netif_msg_ifdown(mac)) {
2642 + printk(KERN_DEBUG "%s: close " IXMAC_NAME
2643 + " RX queue %d bufs, TX queue %d bufs\n",
2644 + dev->name, mac->rxq_pkt, mac->txq_pkt);
2649 +static int ixmac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2651 + struct mac_info *mac = netdev_priv(dev);
2652 + int rc, duplex_changed;
2654 + if (!netif_running(dev))
2656 + if (!try_module_get(THIS_MODULE))
2658 + rc = generic_mii_ioctl(&mac->mii, if_mii(rq), cmd, &duplex_changed);
2659 + module_put(THIS_MODULE);
2660 + if (duplex_changed)
2661 + update_duplex_mode(dev);
2665 +static struct net_device_stats *ixmac_stats (struct net_device *dev)
2667 + struct mac_info *mac = netdev_priv(dev);
2668 + return &mac->stat;
2671 +static void ixmac_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
2673 + struct mac_info *mac = netdev_priv(dev);
2674 + struct npe_info *npe = dev_get_drvdata(mac->npe_dev);
2676 + strcpy(info->driver, IXMAC_NAME);
2677 + strcpy(info->version, IXMAC_VERSION);
2678 + if (npe_status(npe) & IX_NPEDL_EXCTL_STATUS_RUN) {
2679 + snprintf(info->fw_version, 32, "%d.%d func [%d]",
2680 + npe->img_info[2], npe->img_info[3], npe->img_info[1]);
2682 + strncpy(info->bus_info, npe->plat->name, ETHTOOL_BUSINFO_LEN);
2685 +static int ixmac_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
2687 + struct mac_info *mac = netdev_priv(dev);
2688 + mii_ethtool_gset(&mac->mii, cmd);
2692 +static int ixmac_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
2694 + struct mac_info *mac = netdev_priv(dev);
2696 + rc = mii_ethtool_sset(&mac->mii, cmd);
2700 +static int ixmac_nway_reset(struct net_device *dev)
2702 + struct mac_info *mac = netdev_priv(dev);
2703 + return mii_nway_restart(&mac->mii);
2706 +static u32 ixmac_get_link(struct net_device *dev)
2708 + struct mac_info *mac = netdev_priv(dev);
2709 + return mii_link_ok(&mac->mii);
2712 +static const int mac_reg_list[] = MAC_REG_LIST;
2714 +static int ixmac_get_regs_len(struct net_device *dev)
2716 + return ARRAY_SIZE(mac_reg_list);
2720 +ixmac_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *regbuf)
2723 + struct mac_info *mac = netdev_priv(dev);
2726 + for (i=0; i<regs->len; i++) {
2727 + buf[i] = mac_read_reg(mac, mac_reg_list[i]);
2732 + const char str[ETH_GSTRING_LEN];
2733 +} ethtool_stats_keys[NPE_STAT_NUM + NPE_Q_STAT_NUM] = {
2734 + NPE_Q_STAT_STRINGS
2738 +static void ixmac_get_strings(struct net_device *dev, u32 stringset, u8 *data)
2740 + struct mac_info *mac = netdev_priv(dev);
2741 + memcpy(data, ethtool_stats_keys, mac->npe_stat_num * ETH_GSTRING_LEN);
2744 +static int ixmac_get_stats_count(struct net_device *dev)
2746 + struct mac_info *mac = netdev_priv(dev);
2747 + return mac->npe_stat_num;
2750 +static u32 ixmac_get_msglevel(struct net_device *dev)
2752 + struct mac_info *mac = netdev_priv(dev);
2753 + return mac->msg_enable;
2756 +static void ixmac_set_msglevel(struct net_device *dev, u32 datum)
2758 + struct mac_info *mac = netdev_priv(dev);
2759 + mac->msg_enable = datum;
2762 +static void ixmac_get_ethtool_stats(struct net_device *dev,
2763 + struct ethtool_stats *stats, u64 *data)
2766 + struct mac_info *mac = netdev_priv(dev);
2767 + u32 buf[NPE_STAT_NUM];
2769 + data[0] = queue_len(mac->rxq);
2770 + data[1] = queue_len(mac->rxdoneq);
2771 + data[2] = queue_len(mac->txq);
2772 + data[3] = queue_len(tx_doneq);
2774 + get_npe_stats(mac, buf, sizeof(buf), 0);
2776 + for (i=0; i<stats->n_stats-4; i++) {
2777 + data[i+4] = npe_to_cpu32(buf[i]);
2781 +static struct ethtool_ops ixmac_ethtool_ops = {
2782 + .get_drvinfo = ixmac_get_drvinfo,
2783 + .get_settings = ixmac_get_settings,
2784 + .set_settings = ixmac_set_settings,
2785 + .nway_reset = ixmac_nway_reset,
2786 + .get_link = ixmac_get_link,
2787 + .get_msglevel = ixmac_get_msglevel,
2788 + .set_msglevel = ixmac_set_msglevel,
2789 + .get_regs_len = ixmac_get_regs_len,
2790 + .get_regs = ixmac_get_regs,
2791 + .get_perm_addr = ethtool_op_get_perm_addr,
2792 + .get_strings = ixmac_get_strings,
2793 + .get_stats_count = ixmac_get_stats_count,
2794 + .get_ethtool_stats = ixmac_get_ethtool_stats,
2797 +static void mac_mdio_thread(struct work_struct *work)
2799 + struct mac_info *mac = container_of(work, struct mac_info,
2800 + mdio_thread.work);
2801 + struct net_device *dev = mac->netdev;
2803 + media_check(dev, 0);
2804 + schedule_delayed_work(&mac->mdio_thread, MDIO_INTERVAL);
2807 +static int mac_probe(struct platform_device *pdev)
2809 + struct resource *res;
2810 + struct mac_info *mac;
2811 + struct net_device *dev;
2812 + struct npe_info *npe;
2813 + struct mac_plat_info *plat = pdev->dev.platform_data;
2816 + if (!(res = platform_get_resource(pdev, IORESOURCE_MEM, 0))) {
2819 + if (!(dev = alloc_etherdev (sizeof(struct mac_info)))) {
2822 + SET_MODULE_OWNER(dev);
2823 + SET_NETDEV_DEV(dev, &pdev->dev);
2824 + mac = netdev_priv(dev);
2825 + mac->netdev = dev;
2827 + size = res->end - res->start +1;
2828 + mac->res = request_mem_region(res->start, size, IXMAC_NAME);
2834 + mac->addr = ioremap(res->start, size);
2840 + dev->open = ixmac_open;
2841 + dev->hard_start_xmit = ixmac_start_xmit;
2842 + dev->poll = ix_poll;
2843 + dev->stop = ixmac_close;
2844 + dev->get_stats = ixmac_stats;
2845 + dev->do_ioctl = ixmac_ioctl;
2846 + dev->set_multicast_list = ixmac_set_rx_mode;
2847 + dev->ethtool_ops = &ixmac_ethtool_ops;
2850 + dev->tx_queue_len = 100;
2852 + mac->npe_dev = get_npe_by_id(plat->npe_id);
2853 + if (!mac->npe_dev) {
2857 + npe = dev_get_drvdata(mac->npe_dev);
2859 + mac->rxq = request_queue(plat->rxq_id, 128);
2860 + if (IS_ERR(mac->rxq)) {
2861 + printk(KERN_ERR "Error requesting Q: %d\n", plat->rxq_id);
2865 + mac->txq = request_queue(plat->txq_id, 128);
2866 + if (IS_ERR(mac->txq)) {
2867 + printk(KERN_ERR "Error requesting Q: %d\n", plat->txq_id);
2871 + mac->rxdoneq = request_queue(plat->rxdoneq_id, 128);
2872 + if (IS_ERR(mac->rxdoneq)) {
2873 + printk(KERN_ERR "Error requesting Q: %d\n", plat->rxdoneq_id);
2877 + mac->rxdoneq->irq_cb = irqcb_recv;
2878 + mac->rxdoneq->cb_data = dev;
2879 + queue_set_watermarks(mac->rxdoneq, 0, 0);
2880 + queue_set_irq_src(mac->rxdoneq, Q_IRQ_ID_NOT_E);
2882 + mac->qmgr = dev_get_drvdata(mac->rxq->dev);
2883 + if (register_netdev (dev)) {
2889 + mac->npe_stat_num = NPE_STAT_NUM_BASE;
2890 + mac->msg_enable = netif_msg_init(debug, MAC_DEF_MSG_ENABLE);
2892 + platform_set_drvdata(pdev, dev);
2894 + mac_write_reg(mac, MAC_CORE_CNTRL, CORE_RESET);
2896 + mac_write_reg(mac, MAC_CORE_CNTRL, CORE_MDC_EN);
2898 + init_mdio(dev, plat->phy_id);
2900 + INIT_DELAYED_WORK(&mac->mdio_thread, mac_mdio_thread);
2902 + /* The place of the MAC address is very system dependent.
2903 + * Here we use a random one to be replaced by one of the
2904 + * following commands:
2905 + * "ip link set address 02:03:04:04:04:01 dev eth0"
2906 + * "ifconfig eth0 hw ether 02:03:04:04:04:07"
2909 + if (is_zero_ether_addr(plat->hwaddr)) {
2910 + random_ether_addr(dev->dev_addr);
2911 + dev->dev_addr[5] = plat->phy_id;
2914 + memcpy(dev->dev_addr, plat->hwaddr, 6);
2916 + printk(KERN_INFO IXMAC_NAME " driver " IXMAC_VERSION
2917 + ": %s on %s with PHY[%d] initialized\n",
2918 + dev->name, npe->plat->name, plat->phy_id);
2924 + release_queue(mac->rxq);
2926 + release_queue(mac->txq);
2928 + release_queue(mac->rxdoneq);
2929 + module_put(mac->npe_dev->driver->owner);
2931 + iounmap(mac->addr);
2933 + release_resource(mac->res);
2939 +static void drain_npe(struct mac_info *mac)
2941 + struct npe_info *npe = dev_get_drvdata(mac->npe_dev);
2942 + struct npe_cont *cont;
2946 + /* Now there are some skb hold by the NPE.
2947 + * We switch the MAC in loopback mode and send a pseudo packet
2948 + * that will be returned by the NPE in its last SKB.
2949 + * We will also try to isolate the PHY to keep the packets internal.
2952 + if (mac->txq_pkt <2)
2953 + mac->txq_pkt += init_buffer(tx_doneq, 5);
2955 + if (npe_status(npe) & IX_NPEDL_EXCTL_STATUS_RUN) {
2956 + mac_reset_regbit(mac, MAC_CORE_CNTRL, CORE_MDC_EN);
2957 + mac_set_regbit(mac, MAC_RX_CNTRL1, RX_CNTRL1_LOOP_EN);
2959 + npe_mh_npe_loopback_mode(npe, mac->plat, 1);
2962 + while (mac->rxq_pkt && loop++ < 2000 ) {
2963 + phys = queue_get_entry(tx_doneq) & ~0xf;
2966 + cont = dma_to_virt(queue->dev, phys);
2967 + /* actually the packets should never leave the system,
2968 + * but if they do, they shall contain 0s instead of
2969 + * intresting random data....
2971 + memset(cont->data, 0, 64);
2972 + cont->eth.pkt_len = 64;
2973 + dma_sync_single(mac->txq->dev, phys, 64 + DMA_HDR_SIZE,
2975 + queue_put_entry(mac->txq, phys);
2976 + if (queue_stat(mac->txq) == 2) { /* overflow */
2977 + queue_put_entry(tx_doneq, phys);
2981 + mac->rxq_pkt -= destroy_buffer(mac->rxdoneq,
2984 + npe_mh_npe_loopback_mode(npe, mac->plat, 0);
2986 + /* Flush MAC TX fifo to drain the bogus packages */
2987 + mac_set_regbit(mac, MAC_CORE_CNTRL, CORE_TX_FIFO_FLUSH);
2988 + mac_reset_regbit(mac, MAC_RX_CNTRL1, RX_CNTRL1_RX_EN);
2989 + mac_reset_regbit(mac, MAC_TX_CNTRL1, TX_CNTRL1_TX_EN);
2990 + mac_reset_regbit(mac, MAC_RX_CNTRL1, RX_CNTRL1_LOOP_EN);
2991 + mac_reset_regbit(mac, MAC_CORE_CNTRL, CORE_TX_FIFO_FLUSH);
2992 + mac_reset_regbit(mac, MAC_CORE_CNTRL, CORE_TX_FIFO_FLUSH);
2995 +static int mac_remove(struct platform_device *pdev)
2997 + struct net_device* dev = platform_get_drvdata(pdev);
2998 + struct mac_info *mac = netdev_priv(dev);
3000 + unregister_netdev(dev);
3002 + mac->rxq_pkt -= destroy_buffer(mac->rxq, mac->rxq_pkt);
3006 + mac->txq_pkt -= destroy_buffer(mac->txq, mac->txq_pkt);
3007 + mac->txq_pkt -= destroy_buffer(tx_doneq, mac->txq_pkt);
3009 + if (mac->rxq_pkt || mac->txq_pkt)
3010 + printk("Buffers lost in NPE: RX:%d, TX:%d\n",
3011 + mac->rxq_pkt, mac->txq_pkt);
3013 + release_queue(mac->txq);
3014 + release_queue(mac->rxq);
3015 + release_queue(mac->rxdoneq);
3017 + flush_scheduled_work();
3018 + return_npe_dev(mac->npe_dev);
3020 + iounmap(mac->addr);
3021 + release_resource(mac->res);
3022 + platform_set_drvdata(pdev, NULL);
3027 +static struct platform_driver ixp4xx_mac = {
3028 + .driver.name = IXMAC_NAME,
3029 + .probe = mac_probe,
3030 + .remove = mac_remove,
3033 +static int __init init_mac(void)
3035 + /* The TX done Queue handles skbs sent out by the NPE */
3036 + tx_doneq = request_queue(TX_DONE_QID, 128);
3037 + if (IS_ERR(tx_doneq)) {
3038 + printk(KERN_ERR "Error requesting Q: %d\n", TX_DONE_QID);
3041 + return platform_driver_register(&ixp4xx_mac);
3044 +static void __exit finish_mac(void)
3046 + platform_driver_unregister(&ixp4xx_mac);
3048 + release_queue(tx_doneq);
3052 +module_init(init_mac);
3053 +module_exit(finish_mac);
3055 +MODULE_LICENSE("GPL");
3056 +MODULE_AUTHOR("Christian Hohnstaedt <chohnstaedt@innominate.com>");
3058 Index: linux-2.6.21.7/drivers/net/ixp4xx/npe.c
3059 ===================================================================
3061 +++ linux-2.6.21.7/drivers/net/ixp4xx/npe.c
3064 +#include <linux/ixp_npe.h>
3065 +#include <asm/hardware.h>
3067 +#define RESET_NPE_PARITY 0x0800
3068 +#define PARITY_BIT_MASK 0x3F00FFFF
3069 +#define CONFIG_CTRL_REG_MASK 0x3F3FFFFF
3070 +#define MAX_RETRIES 1000000
3071 +#define NPE_PHYS_REG 32
3072 +#define RESET_MBST_VAL 0x0000F0F0
3073 +#define NPE_REGMAP 0x0000001E
3074 +#define INSTR_WR_REG_SHORT 0x0000C000
3075 +#define INSTR_WR_REG_BYTE 0x00004000
3076 +#define MASK_ECS_REG_0_NEXTPC 0x1FFF0000
3078 +#define INSTR_RD_FIFO 0x0F888220
3079 +#define INSTR_RESET_MBOX 0x0FAC8210
3081 +#define ECS_REG_0_LDUR 8
3082 +#define ECS_REG_1_CCTXT 16
3083 +#define ECS_REG_1_SELCTXT 0
3085 +#define ECS_BG_CTXT_REG_0 0x00
3086 +#define ECS_BG_CTXT_REG_1 0x01
3087 +#define ECS_BG_CTXT_REG_2 0x02
3088 +#define ECS_PRI_1_CTXT_REG_0 0x04
3089 +#define ECS_PRI_1_CTXT_REG_1 0x05
3090 +#define ECS_PRI_1_CTXT_REG_2 0x06
3091 +#define ECS_PRI_2_CTXT_REG_0 0x08
3092 +#define ECS_PRI_2_CTXT_REG_1 0x09
3093 +#define ECS_PRI_2_CTXT_REG_2 0x0A
3094 +#define ECS_DBG_CTXT_REG_0 0x0C
3095 +#define ECS_DBG_CTXT_REG_1 0x0D
3096 +#define ECS_DBG_CTXT_REG_2 0x0E
3097 +#define ECS_INSTRUCT_REG 0x11
3099 +#define ECS_BG_CTXT_REG_0_RESET 0xA0000000
3100 +#define ECS_BG_CTXT_REG_1_RESET 0x01000000
3101 +#define ECS_BG_CTXT_REG_2_RESET 0x00008000
3102 +#define ECS_PRI_1_CTXT_REG_0_RESET 0x20000080
3103 +#define ECS_PRI_1_CTXT_REG_1_RESET 0x01000000
3104 +#define ECS_PRI_1_CTXT_REG_2_RESET 0x00008000
3105 +#define ECS_PRI_2_CTXT_REG_0_RESET 0x20000080
3106 +#define ECS_PRI_2_CTXT_REG_1_RESET 0x01000000
3107 +#define ECS_PRI_2_CTXT_REG_2_RESET 0x00008000
3108 +#define ECS_DBG_CTXT_REG_0_RESET 0x20000000
3109 +#define ECS_DBG_CTXT_REG_1_RESET 0x00000000
3110 +#define ECS_DBG_CTXT_REG_2_RESET 0x001E0000
3111 +#define ECS_INSTRUCT_REG_RESET 0x1003C00F
3113 +static struct { u32 reg; u32 val; } ecs_reset[] =
3115 + { ECS_BG_CTXT_REG_0, ECS_BG_CTXT_REG_0_RESET },
3116 + { ECS_BG_CTXT_REG_1, ECS_BG_CTXT_REG_1_RESET },
3117 + { ECS_BG_CTXT_REG_2, ECS_BG_CTXT_REG_2_RESET },
3118 + { ECS_PRI_1_CTXT_REG_0, ECS_PRI_1_CTXT_REG_0_RESET },
3119 + { ECS_PRI_1_CTXT_REG_1, ECS_PRI_1_CTXT_REG_1_RESET },
3120 + { ECS_PRI_1_CTXT_REG_2, ECS_PRI_1_CTXT_REG_2_RESET },
3121 + { ECS_PRI_2_CTXT_REG_0, ECS_PRI_2_CTXT_REG_0_RESET },
3122 + { ECS_PRI_2_CTXT_REG_1, ECS_PRI_2_CTXT_REG_1_RESET },
3123 + { ECS_PRI_2_CTXT_REG_2, ECS_PRI_2_CTXT_REG_2_RESET },
3124 + { ECS_DBG_CTXT_REG_0, ECS_DBG_CTXT_REG_0_RESET },
3125 + { ECS_DBG_CTXT_REG_1, ECS_DBG_CTXT_REG_1_RESET },
3126 + { ECS_DBG_CTXT_REG_2, ECS_DBG_CTXT_REG_2_RESET },
3127 + { ECS_INSTRUCT_REG, ECS_INSTRUCT_REG_RESET }
3130 +/* actually I have no idea what I'm doing here !!
3131 + * I only rewrite the "reset" sequence the way Intel does it.
3134 +static void npe_debg_preexec(struct npe_info *npe)
3136 + u32 r = IX_NPEDL_MASK_ECS_DBG_REG_2_IF | IX_NPEDL_MASK_ECS_DBG_REG_2_IE;
3138 + npe->exec_count = npe_reg_read(npe, IX_NPEDL_REG_OFFSET_EXCT);
3139 + npe_reg_write(npe, IX_NPEDL_REG_OFFSET_EXCT, 0);
3140 + npe->ctx_reg2 = npe_read_ecs_reg(npe, ECS_DBG_CTXT_REG_2);
3141 + npe_write_ecs_reg(npe, ECS_DBG_CTXT_REG_2, npe->ctx_reg2 | r);
3144 +static void npe_debg_postexec(struct npe_info *npe)
3146 + npe_write_ecs_reg(npe, ECS_DBG_CTXT_REG_0, 0);
3147 + npe_write_exctl(npe, IX_NPEDL_EXCTL_CMD_NPE_CLR_PIPE);
3148 + npe_reg_write(npe, IX_NPEDL_REG_OFFSET_EXCT, npe->exec_count);
3149 + npe_write_ecs_reg(npe, ECS_DBG_CTXT_REG_2, npe->ctx_reg2);
3153 +npe_debg_inst_exec(struct npe_info *npe, u32 instr, u32 ctx, u32 ldur)
3158 + regval = IX_NPEDL_MASK_ECS_REG_0_ACTIVE |
3159 + (ldur << ECS_REG_0_LDUR);
3160 + npe_write_ecs_reg(npe, ECS_DBG_CTXT_REG_0 , regval);
3161 + /* set CCTXT at ECS DEBUG L3 to specify in which context
3162 + * to execute the instruction
3164 + regval = (ctx << ECS_REG_1_CCTXT) |
3165 + (ctx << ECS_REG_1_SELCTXT);
3166 + npe_write_ecs_reg(npe, ECS_DBG_CTXT_REG_1, regval);
3168 + /* clear the pipeline */
3169 + npe_write_exctl(npe, IX_NPEDL_EXCTL_CMD_NPE_CLR_PIPE);
3171 + /* load NPE instruction into the instruction register */
3172 + npe_write_ecs_reg(npe, ECS_INSTRUCT_REG, instr);
3173 + /* we need this value later to wait for
3174 + * completion of NPE execution step
3176 + wc = npe_reg_read(npe, IX_NPEDL_REG_OFFSET_WC);
3177 + npe_write_exctl(npe, IX_NPEDL_EXCTL_CMD_NPE_STEP);
3179 + /* Watch Count register increments when NPE completes an instruction */
3180 + while (wc == npe_reg_read(npe, IX_NPEDL_REG_OFFSET_WC) &&
3181 + ++c < MAX_RETRIES);
3183 + if (c >= MAX_RETRIES) {
3184 + printk(KERN_ERR "%s reset:npe_debg_inst_exec(): Timeout\n",
3191 +static int npe_logical_reg_write8(struct npe_info *npe, u32 addr, u32 val)
3195 + /* here we build the NPE assembler instruction:
3197 + instr = INSTR_WR_REG_BYTE | /* OpCode */
3198 + addr << 9 | /* base Operand */
3199 + (val & 0x1f) << 4 | /* lower 5 bits to immediate data */
3200 + (val & ~0x1f) << (18-5);/* higher 3 bits to CoProc instr. */
3201 + /* and execute it */
3202 + return npe_debg_inst_exec(npe, instr, 0, 1);
3205 +static int npe_logical_reg_write16(struct npe_info *npe, u32 addr, u32 val)
3208 + /* here we build the NPE assembler instruction:
3211 + instr = INSTR_WR_REG_SHORT | /* OpCode */
3212 + addr << 9 | /* base Operand */
3213 + (val & 0x1f) << 4 | /* lower 5 bits to immediate data */
3214 + (val & ~0x1f) << (18-5);/* higher 11 bits to CoProc instr. */
3215 + /* and execute it */
3216 + return npe_debg_inst_exec(npe, instr, 0, 1);
3219 +static int npe_logical_reg_write32(struct npe_info *npe, u32 addr, u32 val)
3221 + /* write in 16 bit steps first the high and then the low value */
3222 + npe_logical_reg_write16(npe, addr, val >> 16);
3223 + return npe_logical_reg_write16(npe, addr+2, val & 0xffff);
3226 +void npe_reset(struct npe_info *npe)
3228 + u32 reg, cfg_ctrl;
3230 + struct { u32 reset; int addr; int size; } ctx_reg[] = {
3231 + { 0x80, 0x1b, 8 },
3233 + { 0x820, 0x1e, 16 },
3237 + cfg_ctrl = npe_reg_read(npe, IX_NPEDL_REG_OFFSET_CTL);
3238 + cfg_ctrl |= 0x3F000000;
3239 + /* disable the parity interrupt */
3240 + npe_reg_write(npe, IX_NPEDL_REG_OFFSET_CTL, cfg_ctrl & PARITY_BIT_MASK);
3242 + npe_debg_preexec(npe);
3244 + /* clear the FIFOs */
3245 + while (npe_reg_read(npe, IX_NPEDL_REG_OFFSET_WFIFO) ==
3246 + IX_NPEDL_MASK_WFIFO_VALID);
3247 + while (npe_reg_read(npe, IX_NPEDL_REG_OFFSET_STAT) ==
3248 + IX_NPEDL_MASK_STAT_OFNE)
3251 + reg = npe_reg_read(npe, IX_NPEDL_REG_OFFSET_FIFO);
3252 + printk("%s reset: Read FIFO:=%x\n", npe->plat->name, reg);
3254 + while (npe_reg_read(npe, IX_NPEDL_REG_OFFSET_STAT) ==
3255 + IX_NPEDL_MASK_STAT_IFNE) {
3256 + npe_debg_inst_exec(npe, INSTR_RD_FIFO, 0, 0);
3259 + /* Reset the mailbox reg */
3260 + npe_reg_write(npe, IX_NPEDL_REG_OFFSET_MBST, RESET_MBST_VAL);
3261 + npe_debg_inst_exec(npe, INSTR_RESET_MBOX, 0, 0);
3263 + /* Reset the physical registers in the NPE register file */
3264 + for (i=0; i<NPE_PHYS_REG; i++) {
3265 + npe_logical_reg_write16(npe, NPE_REGMAP, i >> 1);
3266 + npe_logical_reg_write32(npe, (i&1) *4, 0);
3269 + /* Reset the context store. Iterate over the 16 ctx s */
3270 + for(i=0; i<16; i++) {
3271 + for (reg=0; reg<4; reg++) {
3272 + /* There is no (STEVT) register for Context 0.
3273 + * ignore if register=0 and ctx=0 */
3276 + /* Context 0 has no STARTPC. Instead, this value is
3277 + * used to set NextPC for Background ECS,
3278 + * to set where NPE starts executing code
3280 + if (!i && reg==1) {
3282 + r = npe_read_ecs_reg(npe, ECS_BG_CTXT_REG_0);
3283 + r &= ~MASK_ECS_REG_0_NEXTPC;
3284 + r |= (cr->reset << 16) & MASK_ECS_REG_0_NEXTPC;
3287 + cr = ctx_reg + reg;
3288 + switch (cr->size) {
3290 + npe_logical_reg_write8(npe, cr->addr,
3294 + npe_logical_reg_write16(npe, cr->addr,
3299 + npe_debg_postexec(npe);
3301 + for (i=0; i< ARRAY_SIZE(ecs_reset); i++) {
3302 + npe_write_ecs_reg(npe, ecs_reset[i].reg, ecs_reset[i].val);
3304 + npe_write_exctl(npe, IX_NPEDL_EXCTL_CMD_CLR_PROFILE_CNT);
3306 + for (i=IX_NPEDL_REG_OFFSET_EXCT; i<=IX_NPEDL_REG_OFFSET_AP3; i+=4) {
3307 + npe_reg_write(npe, i, 0);
3310 + npe_reg_write(npe, IX_NPEDL_REG_OFFSET_WC, 0);
3312 + reg = *IXP4XX_EXP_CFG2;
3313 + reg |= 0x800 << npe->plat->id; /* IX_FUSE_NPE[ABC] */
3314 + *IXP4XX_EXP_CFG2 = reg;
3315 + reg &= ~(0x800 << npe->plat->id); /* IX_FUSE_NPE[ABC] */
3316 + *IXP4XX_EXP_CFG2 = reg;
3320 + npe_reg_write(npe, IX_NPEDL_REG_OFFSET_CTL,
3321 + cfg_ctrl & CONFIG_CTRL_REG_MASK);
3326 +void npe_stop(struct npe_info *npe)
3328 + npe_write_exctl(npe, IX_NPEDL_EXCTL_CMD_NPE_STOP);
3329 + npe_write_exctl(npe, IX_NPEDL_EXCTL_CMD_NPE_CLR_PIPE);
3332 +static void npe_reset_active(struct npe_info *npe, u32 reg)
3336 + regval = npe_read_ecs_reg(npe, reg);
3337 + regval &= ~IX_NPEDL_MASK_ECS_REG_0_ACTIVE;
3338 + npe_write_ecs_reg(npe, reg, regval);
3341 +void npe_start(struct npe_info *npe)
3343 + npe_reset_active(npe, IX_NPEDL_ECS_PRI_1_CTXT_REG_0);
3344 + npe_reset_active(npe, IX_NPEDL_ECS_PRI_2_CTXT_REG_0);
3345 + npe_reset_active(npe, IX_NPEDL_ECS_DBG_CTXT_REG_0);
3347 + npe_write_exctl(npe, IX_NPEDL_EXCTL_CMD_NPE_CLR_PIPE);
3348 + npe_write_exctl(npe, IX_NPEDL_EXCTL_CMD_NPE_START);
3351 +EXPORT_SYMBOL(npe_stop);
3352 +EXPORT_SYMBOL(npe_start);
3353 +EXPORT_SYMBOL(npe_reset);
3354 Index: linux-2.6.21.7/drivers/net/ixp4xx/npe_mh.c
3355 ===================================================================
3357 +++ linux-2.6.21.7/drivers/net/ixp4xx/npe_mh.c
3360 + * npe_mh.c - NPE message handler.
3362 + * Copyright (C) 2006 Christian Hohnstaedt <chohnstaedt@innominate.com>
3364 + * This file is released under the GPLv2
3367 +#include <linux/ixp_npe.h>
3368 +#include <linux/slab.h>
3370 +#define MAX_RETRY 200
3372 +struct npe_mh_msg {
3374 + u8 byte[8]; /* Very desciptive name, I know ... */
3380 + * The whole code in this function must be reworked.
3381 + * It is in a state that works but is not rock solid
3383 +static int send_message(struct npe_info *npe, struct npe_mh_msg *msg)
3386 + u32 send[2], recv[2];
3388 + for (i=0; i<2; i++)
3389 + send[i] = be32_to_cpu(msg->u.data[i]);
3391 + if ((npe_reg_read(npe, IX_NPEDL_REG_OFFSET_STAT) &
3392 + IX_NPEMH_NPE_STAT_IFNE))
3395 + npe_reg_write(npe, IX_NPEDL_REG_OFFSET_FIFO, send[0]);
3396 + for(i=0; i<MAX_RETRY; i++) {
3397 + /* if the IFNF status bit is unset then the inFIFO is full */
3398 + if (npe_reg_read(npe, IX_NPEDL_REG_OFFSET_STAT) &
3399 + IX_NPEMH_NPE_STAT_IFNF)
3404 + npe_reg_write(npe, IX_NPEDL_REG_OFFSET_FIFO, send[1]);
3406 + while (!(npe_reg_read(npe, IX_NPEDL_REG_OFFSET_STAT) &
3407 + IX_NPEMH_NPE_STAT_OFNE)) {
3408 + if (i++>MAX_RETRY) {
3409 + printk("Waiting for Output FIFO NotEmpty failed\n");
3413 + //printk("Output FIFO Not Empty. Loops: %d\n", i);
3415 + while (npe_reg_read(npe, IX_NPEDL_REG_OFFSET_STAT) &
3416 + IX_NPEMH_NPE_STAT_OFNE) {
3417 + recv[j&1] = npe_reg_read(npe,IX_NPEDL_REG_OFFSET_FIFO);
3420 + if ((recv[0] != send[0]) || (recv[1] != send[1])) {
3421 + if (send[0] || send[1]) {
3422 + /* all CMDs return the complete message as answer,
3423 + * only GETSTATUS returns the ImageID of the NPE
3425 + printk("Unexpected answer: "
3426 + "Send %08x:%08x Ret %08x:%08x\n",
3427 + send[0], send[1], recv[0], recv[1]);
3437 +#define IX_ETHNPE_NPE_GETSTATUS 0x00
3438 +#define IX_ETHNPE_EDB_SETPORTADDRESS 0x01
3439 +#define IX_ETHNPE_GETSTATS 0x04
3440 +#define IX_ETHNPE_RESETSTATS 0x05
3441 +#define IX_ETHNPE_FW_SETFIREWALLMODE 0x0E
3442 +#define IX_ETHNPE_VLAN_SETRXQOSENTRY 0x0B
3443 +#define IX_ETHNPE_SETLOOPBACK_MODE 0x12
3445 +#define logical_id(mp) (((mp)->npe_id << 4) | ((mp)->port_id & 0xf))
3447 +int npe_mh_status(struct npe_info *npe)
3449 + struct npe_mh_msg msg;
3451 + memset(&msg, 0, sizeof(msg));
3452 + msg.u.byte[CMD] = IX_ETHNPE_NPE_GETSTATUS;
3453 + return send_message(npe, &msg);
3456 +int npe_mh_setportaddr(struct npe_info *npe, struct mac_plat_info *mp,
3459 + struct npe_mh_msg msg;
3461 + msg.u.byte[CMD] = IX_ETHNPE_EDB_SETPORTADDRESS;
3462 + msg.u.byte[PORT] = mp->eth_id;
3463 + memcpy(msg.u.byte + MAC, macaddr, 6);
3465 + return send_message(npe, &msg);
3468 +int npe_mh_disable_firewall(struct npe_info *npe, struct mac_plat_info *mp)
3470 + struct npe_mh_msg msg;
3472 + memset(&msg, 0, sizeof(msg));
3473 + msg.u.byte[CMD] = IX_ETHNPE_FW_SETFIREWALLMODE;
3474 + msg.u.byte[PORT] = logical_id(mp);
3476 + return send_message(npe, &msg);
3479 +int npe_mh_npe_loopback_mode(struct npe_info *npe, struct mac_plat_info *mp,
3482 + struct npe_mh_msg msg;
3484 + memset(&msg, 0, sizeof(msg));
3485 + msg.u.byte[CMD] = IX_ETHNPE_SETLOOPBACK_MODE;
3486 + msg.u.byte[PORT] = logical_id(mp);
3487 + msg.u.byte[3] = enable ? 1 : 0;
3489 + return send_message(npe, &msg);
3492 +int npe_mh_set_rxqid(struct npe_info *npe, struct mac_plat_info *mp, int qid)
3494 + struct npe_mh_msg msg;
3497 + memset(&msg, 0, sizeof(msg));
3498 + msg.u.byte[CMD] = IX_ETHNPE_VLAN_SETRXQOSENTRY;
3499 + msg.u.byte[PORT] = logical_id(mp);
3500 + msg.u.byte[5] = qid | 0x80;
3501 + msg.u.byte[7] = qid<<4;
3502 + for(i=0; i<8; i++) {
3503 + msg.u.byte[3] = i;
3504 + if ((ret = send_message(npe, &msg)))
3510 +int npe_mh_get_stats(struct npe_info *npe, struct mac_plat_info *mp, u32 phys,
3513 + struct npe_mh_msg msg;
3514 + memset(&msg, 0, sizeof(msg));
3515 + msg.u.byte[CMD] = reset ? IX_ETHNPE_RESETSTATS : IX_ETHNPE_GETSTATS;
3516 + msg.u.byte[PORT] = logical_id(mp);
3517 + msg.u.data[1] = cpu_to_npe32(cpu_to_be32(phys));
3519 + return send_message(npe, &msg);
3523 +EXPORT_SYMBOL(npe_mh_status);
3524 +EXPORT_SYMBOL(npe_mh_setportaddr);
3525 +EXPORT_SYMBOL(npe_mh_disable_firewall);
3526 +EXPORT_SYMBOL(npe_mh_set_rxqid);
3527 +EXPORT_SYMBOL(npe_mh_npe_loopback_mode);
3528 +EXPORT_SYMBOL(npe_mh_get_stats);
3529 Index: linux-2.6.21.7/drivers/net/ixp4xx/phy.c
3530 ===================================================================
3532 +++ linux-2.6.21.7/drivers/net/ixp4xx/phy.c
3535 + * phy.c - MDIO functions and mii initialisation
3537 + * Copyright (C) 2006 Christian Hohnstaedt <chohnstaedt@innominate.com>
3539 + * This file is released under the GPLv2
3543 +#include <linux/mutex.h>
3546 +#define MAX_PHYS (1<<5)
3549 + * We must always use the same MAC for acessing the MDIO
3550 + * We may not use each MAC for its PHY :-(
3553 +static struct net_device *phy_dev = NULL;
3554 +static struct mutex mtx;
3556 +/* here we remember if the PHY is alive, to avoid log dumping */
3557 +static int phy_works[MAX_PHYS];
3559 +int mdio_read_register(struct net_device *dev, int phy_addr, int phy_reg)
3561 + struct mac_info *mac;
3568 + mac = netdev_priv(phy_dev);
3569 + cmd = mdio_cmd(phy_addr, phy_reg);
3570 + mutex_lock_interruptible(&mtx);
3571 + mac_mdio_cmd_write(mac, cmd);
3572 + while((cmd = mac_mdio_cmd_read(mac)) & MII_GO) {
3573 + if (++cnt >= 100) {
3574 + printk("%s: PHY[%d] access failed\n",
3575 + dev->name, phy_addr);
3580 + reg = mac_mdio_status_read(mac);
3581 + mutex_unlock(&mtx);
3582 + if (reg & MII_READ_FAIL) {
3583 + if (phy_works[phy_addr]) {
3584 + printk("%s: PHY[%d] unresponsive\n",
3585 + dev->name, phy_addr);
3588 + phy_works[phy_addr] = 0;
3590 + if ( !phy_works[phy_addr]) {
3591 + printk("%s: PHY[%d] responsive again\n",
3592 + dev->name, phy_addr);
3594 + phy_works[phy_addr] = 1;
3596 + return reg & 0xffff;
3600 +mdio_write_register(struct net_device *dev, int phy_addr, int phy_reg, int val)
3602 + struct mac_info *mac;
3609 + mac = netdev_priv(phy_dev);
3610 + cmd = mdio_cmd(phy_addr, phy_reg) | MII_WRITE | val;
3612 + mutex_lock_interruptible(&mtx);
3613 + mac_mdio_cmd_write(mac, cmd);
3614 + while((cmd = mac_mdio_cmd_read(mac)) & MII_GO) {
3615 + if (++cnt >= 100) {
3616 + printk("%s: PHY[%d] access failed\n",
3617 + dev->name, phy_addr);
3622 + mutex_unlock(&mtx);
3625 +void init_mdio(struct net_device *dev, int phy_id)
3627 + struct mac_info *mac = netdev_priv(dev);
3630 + /* All phy operations should use the same MAC
3633 + if (mac->plat->eth_id == 0) {
3636 + for (i=0; i<MAX_PHYS; i++)
3639 + mac->mii.dev = dev;
3640 + mac->mii.phy_id = phy_id;
3641 + mac->mii.phy_id_mask = MAX_PHYS - 1;
3642 + mac->mii.reg_num_mask = 0x1f;
3643 + mac->mii.mdio_read = mdio_read_register;
3644 + mac->mii.mdio_write = mdio_write_register;
3647 Index: linux-2.6.21.7/drivers/net/ixp4xx/ucode_dl.c
3648 ===================================================================
3650 +++ linux-2.6.21.7/drivers/net/ixp4xx/ucode_dl.c
3653 + * ucode_dl.c - provide an NPE device and a char-dev for microcode download
3655 + * Copyright (C) 2006 Christian Hohnstaedt <chohnstaedt@innominate.com>
3657 + * This file is released under the GPLv2
3660 +#include <linux/kernel.h>
3661 +#include <linux/module.h>
3662 +#include <linux/miscdevice.h>
3663 +#include <linux/platform_device.h>
3664 +#include <linux/fs.h>
3665 +#include <linux/init.h>
3666 +#include <linux/slab.h>
3667 +#include <linux/firmware.h>
3668 +#include <linux/dma-mapping.h>
3669 +#include <linux/byteorder/swab.h>
3670 +#include <asm/uaccess.h>
3671 +#include <asm/io.h>
3673 +#include <linux/ixp_npe.h>
3675 +#define IXNPE_VERSION "IXP4XX NPE driver Version 0.3.0"
3677 +#define DL_MAGIC 0xfeedf00d
3678 +#define DL_MAGIC_SWAP 0x0df0edfe
3680 +#define EOF_BLOCK 0xf
3681 +#define IMG_SIZE(image) (((image)->size * sizeof(u32)) + \
3682 + sizeof(struct dl_image))
3703 + struct dl_block block[0];
3707 +struct dl_codeblock {
3713 +static struct platform_driver ixp4xx_npe_driver;
3715 +static int match_by_npeid(struct device *dev, void *id)
3717 + struct npe_info *npe = dev_get_drvdata(dev);
3720 + return (npe->plat->id == *(int*)id);
3723 +struct device *get_npe_by_id(int id)
3725 + struct device *dev = driver_find_device(&ixp4xx_npe_driver.driver,
3726 + NULL, &id, match_by_npeid);
3728 + struct npe_info *npe = dev_get_drvdata(dev);
3729 + if (!try_module_get(THIS_MODULE)) {
3738 +void return_npe_dev(struct device *dev)
3740 + struct npe_info *npe = dev_get_drvdata(dev);
3742 + module_put(THIS_MODULE);
3747 +download_block(struct npe_info *npe, struct dl_codeblock *cb, unsigned type)
3754 + cmd = IX_NPEDL_EXCTL_CMD_WR_DATA_MEM;
3755 + if (cb->npe_addr + cb->size > npe->plat->data_size) {
3756 + printk(KERN_INFO "Data size too large: %d+%d > %d\n",
3757 + cb->npe_addr, cb->size, npe->plat->data_size);
3762 + cmd = IX_NPEDL_EXCTL_CMD_WR_INS_MEM;
3763 + if (cb->npe_addr + cb->size > npe->plat->inst_size) {
3764 + printk(KERN_INFO "Instr size too large: %d+%d > %d\n",
3765 + cb->npe_addr, cb->size, npe->plat->inst_size);
3770 + printk(KERN_INFO "Unknown CMD: %d\n", type);
3774 + for (i=0; i < cb->size; i++) {
3775 + npe_write_cmd(npe, cb->npe_addr + i, cb->data[i], cmd);
3781 +static int store_npe_image(struct dl_image *image, struct device *dev)
3783 + struct dl_block *blk;
3784 + struct dl_codeblock *cb;
3785 + struct npe_info *npe;
3789 + dev = get_npe_by_id( (image->id >> 24) & 0xf);
3790 + return_npe_dev(dev);
3795 + npe = dev_get_drvdata(dev);
3796 + if (npe->loaded && (npe->usage > 0)) {
3797 + printk(KERN_INFO "Cowardly refusing to reload an Image "
3798 + "into the used and running %s\n", npe->plat->name);
3799 + return 0; /* indicate success anyway... */
3801 + if (!cpu_is_ixp46x() && ((image->id >> 28) & 0xf)) {
3802 + printk(KERN_INFO "IXP46x NPE image ignored on IXP42x\n");
3809 + for (blk = image->u.block; blk->type != EOF_BLOCK; blk++) {
3810 + if (blk->offset > image->size) {
3811 + printk(KERN_INFO "Block offset out of range\n");
3814 + cb = (struct dl_codeblock*)&image->u.data[blk->offset];
3815 + if (blk->offset + cb->size + 2 > image->size) {
3816 + printk(KERN_INFO "Codeblock size out of range\n");
3819 + if ((ret = download_block(npe, cb, blk->type)))
3822 + *(u32*)npe->img_info = cpu_to_be32(image->id);
3825 + printk(KERN_INFO "Image loaded to %s Func:%x, Rel: %x:%x, Status: %x\n",
3826 + npe->plat->name, npe->img_info[1], npe->img_info[2],
3827 + npe->img_info[3], npe_status(npe));
3828 + if (npe_mh_status(npe)) {
3829 + printk(KERN_ERR "%s not responding\n", npe->plat->name);
3835 +static int ucode_open(struct inode *inode, struct file *file)
3837 + file->private_data = kmalloc(sizeof(struct dl_image), GFP_KERNEL);
3838 + if (!file->private_data)
3843 +static int ucode_close(struct inode *inode, struct file *file)
3845 + kfree(file->private_data);
3849 +static ssize_t ucode_write(struct file *file, const char __user *buf,
3850 + size_t count, loff_t *ppos)
3854 + struct dl_image *image;
3856 + const char __user *cbuf = buf;
3858 + u.data = file->private_data;
3862 + if (*ppos < sizeof(struct dl_image)) {
3863 + len = sizeof(struct dl_image) - *ppos;
3864 + len = len > count ? count : len;
3865 + if (copy_from_user(u.data + *ppos, cbuf, len))
3871 + } else if (*ppos == sizeof(struct dl_image)) {
3873 + if (u.image->magic == DL_MAGIC_SWAP) {
3874 + printk(KERN_INFO "swapped image found\n");
3875 + u.image->id = swab32(u.image->id);
3876 + u.image->size = swab32(u.image->size);
3877 + } else if (u.image->magic != DL_MAGIC) {
3878 + printk(KERN_INFO "Bad magic:%x\n",
3882 + len = IMG_SIZE(u.image);
3883 + data = kmalloc(len, GFP_KERNEL);
3886 + memcpy(data, u.data, *ppos);
3888 + u.data = (char*)data;
3889 + file->private_data = data;
3891 + len = IMG_SIZE(u.image) - *ppos;
3892 + len = len > count ? count : len;
3893 + if (copy_from_user(u.data + *ppos, cbuf, len))
3898 + if (*ppos == IMG_SIZE(u.image)) {
3901 + if (u.image->magic == DL_MAGIC_SWAP) {
3902 + for (i=0; i<u.image->size; i++) {
3903 + u.image->u.data[i] =
3904 + swab32(u.image->u.data[i]);
3906 + u.image->magic = swab32(u.image->magic);
3908 + ret = store_npe_image(u.image, NULL);
3910 + printk(KERN_INFO "Error in NPE image: %x\n",
3916 + return (cbuf-buf);
3919 +static void npe_firmware_probe(struct device *dev)
3921 +#if (defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE)) \
3922 + && defined(MODULE)
3923 + const struct firmware *fw_entry;
3924 + struct npe_info *npe = dev_get_drvdata(dev);
3925 + struct dl_image *image;
3928 + if (request_firmware(&fw_entry, npe->plat->name, dev) != 0) {
3931 + image = (struct dl_image*)fw_entry->data;
3932 + /* Sanity checks */
3933 + if (fw_entry->size < sizeof(struct dl_image)) {
3934 + printk(KERN_ERR "Firmware error: too small\n");
3937 + if (image->magic == DL_MAGIC_SWAP) {
3938 + printk(KERN_INFO "swapped image found\n");
3939 + image->id = swab32(image->id);
3940 + image->size = swab32(image->size);
3941 + } else if (image->magic != DL_MAGIC) {
3942 + printk(KERN_ERR "Bad magic:%x\n", image->magic);
3945 + if (IMG_SIZE(image) != fw_entry->size) {
3946 + printk(KERN_ERR "Firmware error: bad size\n");
3949 + if (((image->id >> 24) & 0xf) != npe->plat->id) {
3950 + printk(KERN_ERR "NPE id missmatch\n");
3953 + if (image->magic == DL_MAGIC_SWAP) {
3954 + for (i=0; i<image->size; i++) {
3955 + image->u.data[i] = swab32(image->u.data[i]);
3957 + image->magic = swab32(image->magic);
3960 + ret = store_npe_image(image, dev);
3963 + printk(KERN_ERR "Error downloading Firmware for %s\n",
3966 + release_firmware(fw_entry);
3970 +static void disable_npe_irq(struct npe_info *npe)
3973 + reg = npe_reg_read(npe, IX_NPEDL_REG_OFFSET_CTL);
3974 + reg &= ~(IX_NPEMH_NPE_CTL_OFE | IX_NPEMH_NPE_CTL_IFE);
3975 + reg |= IX_NPEMH_NPE_CTL_OFEWE | IX_NPEMH_NPE_CTL_IFEWE;
3976 + npe_reg_write(npe, IX_NPEDL_REG_OFFSET_CTL, reg);
3979 +static ssize_t show_npe_state(struct device *dev, struct device_attribute *attr,
3982 + struct npe_info *npe = dev_get_drvdata(dev);
3984 + strcpy(buf, npe_status(npe) & IX_NPEDL_EXCTL_STATUS_RUN ?
3985 + "start\n" : "stop\n");
3986 + return strlen(buf);
3989 +static ssize_t set_npe_state(struct device *dev, struct device_attribute *attr,
3990 + const char *buf, size_t count)
3992 + struct npe_info *npe = dev_get_drvdata(dev);
3995 + printk("%s in use: read-only\n", npe->plat->name);
3998 + if (!strncmp(buf, "start", 5)) {
4001 + if (!strncmp(buf, "stop", 4)) {
4004 + if (!strncmp(buf, "reset", 5)) {
4011 +static DEVICE_ATTR(state, S_IRUGO | S_IWUSR, show_npe_state, set_npe_state);
4013 +static int npe_probe(struct platform_device *pdev)
4015 + struct resource *res;
4016 + struct npe_info *npe;
4017 + struct npe_plat_data *plat = pdev->dev.platform_data;
4018 + int err, size, ret=0;
4020 + if (!(res = platform_get_resource(pdev, IORESOURCE_MEM, 0)))
4023 + if (!(npe = kzalloc(sizeof(struct npe_info), GFP_KERNEL)))
4026 + size = res->end - res->start +1;
4027 + npe->res = request_mem_region(res->start, size, plat->name);
4030 + printk(KERN_ERR "Failed to get memregion(%x, %x)\n",
4031 + res->start, size);
4035 + npe->addr = ioremap(res->start, size);
4038 + printk(KERN_ERR "Failed to ioremap(%x, %x)\n",
4039 + res->start, size);
4043 + pdev->dev.coherent_dma_mask = DMA_32BIT_MASK;
4045 + platform_set_drvdata(pdev, npe);
4047 + err = device_create_file(&pdev->dev, &dev_attr_state);
4052 + disable_npe_irq(npe);
4055 + npe_firmware_probe(&pdev->dev);
4060 + release_resource(npe->res);
4066 +static struct file_operations ucode_dl_fops = {
4067 + .owner = THIS_MODULE,
4068 + .write = ucode_write,
4069 + .open = ucode_open,
4070 + .release = ucode_close,
4073 +static struct miscdevice ucode_dl_dev = {
4074 + .minor = MICROCODE_MINOR,
4075 + .name = "ixp4xx_ucode",
4076 + .fops = &ucode_dl_fops,
4079 +static int npe_remove(struct platform_device *pdev)
4081 + struct npe_info *npe = platform_get_drvdata(pdev);
4083 + device_remove_file(&pdev->dev, &dev_attr_state);
4085 + iounmap(npe->addr);
4086 + release_resource(npe->res);
4091 +static struct platform_driver ixp4xx_npe_driver = {
4093 + .name = "ixp4xx_npe",
4094 + .owner = THIS_MODULE,
4096 + .probe = npe_probe,
4097 + .remove = npe_remove,
4100 +static int __init init_npedriver(void)
4103 + if ((ret = misc_register(&ucode_dl_dev))){
4104 + printk(KERN_ERR "Failed to register misc device %d\n",
4108 + if ((ret = platform_driver_register(&ixp4xx_npe_driver)))
4109 + misc_deregister(&ucode_dl_dev);
4111 + printk(KERN_INFO IXNPE_VERSION " initialized\n");
4117 +static void __exit finish_npedriver(void)
4119 + misc_deregister(&ucode_dl_dev);
4120 + platform_driver_unregister(&ixp4xx_npe_driver);
4123 +module_init(init_npedriver);
4124 +module_exit(finish_npedriver);
4126 +MODULE_LICENSE("GPL");
4127 +MODULE_AUTHOR("Christian Hohnstaedt <chohnstaedt@innominate.com>");
4129 +EXPORT_SYMBOL(get_npe_by_id);
4130 +EXPORT_SYMBOL(return_npe_dev);
4131 Index: linux-2.6.21.7/include/asm-arm/arch-ixp4xx/ixp4xx-regs.h
4132 ===================================================================
4133 --- linux-2.6.21.7.orig/include/asm-arm/arch-ixp4xx/ixp4xx-regs.h
4134 +++ linux-2.6.21.7/include/asm-arm/arch-ixp4xx/ixp4xx-regs.h
4136 #ifndef _ASM_ARM_IXP4XX_H_
4137 #define _ASM_ARM_IXP4XX_H_
4139 +#include "npe_regs.h"
4142 * IXP4xx Linux Memory Map:
4148 + * PCI Memory Space
4150 +#define IXP4XX_PCIMEM_BASE_PHYS (0x48000000)
4151 +#define IXP4XX_PCIMEM_REGION_SIZE (0x04000000)
4152 +#define IXP4XX_PCIMEM_BAR_SIZE (0x01000000)
4156 #define IXP4XX_QMGR_BASE_PHYS (0x60000000)
4157 @@ -322,7 +330,13 @@
4158 #define PCI_ATPDMA0_LENADDR_OFFSET 0x48
4159 #define PCI_ATPDMA1_AHBADDR_OFFSET 0x4C
4160 #define PCI_ATPDMA1_PCIADDR_OFFSET 0x50
4161 -#define PCI_ATPDMA1_LENADDR_OFFSET 0x54
4162 +#define PCI_ATPDMA1_LENADDR_OFFSET 0x54
4163 +#define PCI_PTADMA0_AHBADDR_OFFSET 0x58
4164 +#define PCI_PTADMA0_PCIADDR_OFFSET 0x5c
4165 +#define PCI_PTADMA0_LENADDR_OFFSET 0x60
4166 +#define PCI_PTADMA1_AHBADDR_OFFSET 0x64
4167 +#define PCI_PTADMA1_PCIADDR_OFFSET 0x68
4168 +#define PCI_PTADMA1_LENADDR_OFFSET 0x6c
4171 * PCI Control/Status Registers
4172 @@ -351,6 +365,12 @@
4173 #define PCI_ATPDMA1_AHBADDR IXP4XX_PCI_CSR(PCI_ATPDMA1_AHBADDR_OFFSET)
4174 #define PCI_ATPDMA1_PCIADDR IXP4XX_PCI_CSR(PCI_ATPDMA1_PCIADDR_OFFSET)
4175 #define PCI_ATPDMA1_LENADDR IXP4XX_PCI_CSR(PCI_ATPDMA1_LENADDR_OFFSET)
4176 +#define PCI_PTADMA0_AHBADDR IXP4XX_PCI_CSR(PCI_PTADMA0_AHBADDR_OFFSET)
4177 +#define PCI_PTADMA0_PCIADDR IXP4XX_PCI_CSR(PCI_PTADMA0_PCIADDR_OFFSET)
4178 +#define PCI_PTADMA0_LENADDR IXP4XX_PCI_CSR(PCI_PTADMA0_LENADDR_OFFSET)
4179 +#define PCI_PTADMA1_AHBADDR IXP4XX_PCI_CSR(PCI_PTADMA1_AHBADDR_OFFSET)
4180 +#define PCI_PTADMA1_PCIADDR IXP4XX_PCI_CSR(PCI_PTADMA1_PCIADDR_OFFSET)
4181 +#define PCI_PTADMA1_LENADDR IXP4XX_PCI_CSR(PCI_PTADMA1_LENADDR_OFFSET)
4184 * PCI register values and bit definitions
4185 @@ -607,6 +627,34 @@
4187 #define DCMD_LENGTH 0x01fff /* length mask (max = 8K - 1) */
4190 +/* Fuse Bits of IXP_EXP_CFG2 */
4191 +#define IX_FUSE_RCOMP (1 << 0)
4192 +#define IX_FUSE_USB (1 << 1)
4193 +#define IX_FUSE_HASH (1 << 2)
4194 +#define IX_FUSE_AES (1 << 3)
4195 +#define IX_FUSE_DES (1 << 4)
4196 +#define IX_FUSE_HDLC (1 << 5)
4197 +#define IX_FUSE_AAL (1 << 6)
4198 +#define IX_FUSE_HSS (1 << 7)
4199 +#define IX_FUSE_UTOPIA (1 << 8)
4200 +#define IX_FUSE_ETH0 (1 << 9)
4201 +#define IX_FUSE_ETH1 (1 << 10)
4202 +#define IX_FUSE_NPEA (1 << 11)
4203 +#define IX_FUSE_NPEB (1 << 12)
4204 +#define IX_FUSE_NPEC (1 << 13)
4205 +#define IX_FUSE_PCI (1 << 14)
4206 +#define IX_FUSE_ECC (1 << 15)
4207 +#define IX_FUSE_UTOPIA_PHY_LIMIT (3 << 16)
4208 +#define IX_FUSE_USB_HOST (1 << 18)
4209 +#define IX_FUSE_NPEA_ETH (1 << 19)
4210 +#define IX_FUSE_NPEB_ETH (1 << 20)
4211 +#define IX_FUSE_RSA (1 << 21)
4212 +#define IX_FUSE_XSCALE_MAX_FREQ (3 << 22)
4214 +#define IX_FUSE_IXP46X_ONLY IX_FUSE_XSCALE_MAX_FREQ | IX_FUSE_RSA | \
4215 + IX_FUSE_NPEB_ETH | IX_FUSE_NPEA_ETH | IX_FUSE_USB_HOST | IX_FUSE_ECC
4217 #ifndef __ASSEMBLY__
4218 static inline int cpu_is_ixp46x(void)
4220 @@ -620,6 +668,15 @@ static inline int cpu_is_ixp46x(void)
4225 +static inline u32 ix_fuse(void)
4227 + unsigned int fuses = ~(*IXP4XX_EXP_CFG2);
4228 + if (!cpu_is_ixp46x())
4229 + fuses &= ~IX_FUSE_IXP46X_ONLY;
4236 Index: linux-2.6.21.7/include/asm-arm/arch-ixp4xx/npe_regs.h
4237 ===================================================================
4239 +++ linux-2.6.21.7/include/asm-arm/arch-ixp4xx/npe_regs.h
4244 +/* Execution Address */
4245 +#define IX_NPEDL_REG_OFFSET_EXAD 0x00
4246 +/* Execution Data */
4247 +#define IX_NPEDL_REG_OFFSET_EXDATA 0x04
4248 +/* Execution Control */
4249 +#define IX_NPEDL_REG_OFFSET_EXCTL 0x08
4250 +/* Execution Count */
4251 +#define IX_NPEDL_REG_OFFSET_EXCT 0x0C
4252 +/* Action Point 0 */
4253 +#define IX_NPEDL_REG_OFFSET_AP0 0x10
4254 +/* Action Point 1 */
4255 +#define IX_NPEDL_REG_OFFSET_AP1 0x14
4256 +/* Action Point 2 */
4257 +#define IX_NPEDL_REG_OFFSET_AP2 0x18
4258 +/* Action Point 3 */
4259 +#define IX_NPEDL_REG_OFFSET_AP3 0x1C
4260 +/* Watchpoint FIFO */
4261 +#define IX_NPEDL_REG_OFFSET_WFIFO 0x20
4263 +#define IX_NPEDL_REG_OFFSET_WC 0x24
4264 +/* Profile Count */
4265 +#define IX_NPEDL_REG_OFFSET_PROFCT 0x28
4267 +/* Messaging Status */
4268 +#define IX_NPEDL_REG_OFFSET_STAT 0x2C
4269 +/* Messaging Control */
4270 +#define IX_NPEDL_REG_OFFSET_CTL 0x30
4271 +/* Mailbox Status */
4272 +#define IX_NPEDL_REG_OFFSET_MBST 0x34
4273 +/* messaging in/out FIFO */
4274 +#define IX_NPEDL_REG_OFFSET_FIFO 0x38
4277 +#define IX_NPEDL_MASK_ECS_DBG_REG_2_IF 0x00100000
4278 +#define IX_NPEDL_MASK_ECS_DBG_REG_2_IE 0x00080000
4279 +#define IX_NPEDL_MASK_ECS_REG_0_ACTIVE 0x80000000
4281 +#define IX_NPEDL_EXCTL_CMD_NPE_STEP 0x01
4282 +#define IX_NPEDL_EXCTL_CMD_NPE_START 0x02
4283 +#define IX_NPEDL_EXCTL_CMD_NPE_STOP 0x03
4284 +#define IX_NPEDL_EXCTL_CMD_NPE_CLR_PIPE 0x04
4285 +#define IX_NPEDL_EXCTL_CMD_CLR_PROFILE_CNT 0x0C
4286 +#define IX_NPEDL_EXCTL_CMD_RD_INS_MEM 0x10
4287 +#define IX_NPEDL_EXCTL_CMD_WR_INS_MEM 0x11
4288 +#define IX_NPEDL_EXCTL_CMD_RD_DATA_MEM 0x12
4289 +#define IX_NPEDL_EXCTL_CMD_WR_DATA_MEM 0x13
4290 +#define IX_NPEDL_EXCTL_CMD_RD_ECS_REG 0x14
4291 +#define IX_NPEDL_EXCTL_CMD_WR_ECS_REG 0x15
4293 +#define IX_NPEDL_EXCTL_STATUS_RUN 0x80000000
4294 +#define IX_NPEDL_EXCTL_STATUS_STOP 0x40000000
4295 +#define IX_NPEDL_EXCTL_STATUS_CLEAR 0x20000000
4297 +#define IX_NPEDL_MASK_WFIFO_VALID 0x80000000
4298 +#define IX_NPEDL_MASK_STAT_OFNE 0x00010000
4299 +#define IX_NPEDL_MASK_STAT_IFNE 0x00080000
4301 +#define IX_NPEDL_ECS_DBG_CTXT_REG_0 0x0C
4302 +#define IX_NPEDL_ECS_PRI_1_CTXT_REG_0 0x04
4303 +#define IX_NPEDL_ECS_PRI_2_CTXT_REG_0 0x08
4305 +/* NPE control register bit definitions */
4306 +#define IX_NPEMH_NPE_CTL_OFE (1 << 16) /**< OutFifoEnable */
4307 +#define IX_NPEMH_NPE_CTL_IFE (1 << 17) /**< InFifoEnable */
4308 +#define IX_NPEMH_NPE_CTL_OFEWE (1 << 24) /**< OutFifoEnableWriteEnable */
4309 +#define IX_NPEMH_NPE_CTL_IFEWE (1 << 25) /**< InFifoEnableWriteEnable */
4311 +/* NPE status register bit definitions */
4312 +#define IX_NPEMH_NPE_STAT_OFNE (1 << 16) /**< OutFifoNotEmpty */
4313 +#define IX_NPEMH_NPE_STAT_IFNF (1 << 17) /**< InFifoNotFull */
4314 +#define IX_NPEMH_NPE_STAT_OFNF (1 << 18) /**< OutFifoNotFull */
4315 +#define IX_NPEMH_NPE_STAT_IFNE (1 << 19) /**< InFifoNotEmpty */
4316 +#define IX_NPEMH_NPE_STAT_MBINT (1 << 20) /**< Mailbox interrupt */
4317 +#define IX_NPEMH_NPE_STAT_IFINT (1 << 21) /**< InFifo interrupt */
4318 +#define IX_NPEMH_NPE_STAT_OFINT (1 << 22) /**< OutFifo interrupt */
4319 +#define IX_NPEMH_NPE_STAT_WFINT (1 << 23) /**< WatchFifo interrupt */
4323 Index: linux-2.6.21.7/include/asm-arm/arch-ixp4xx/platform.h
4324 ===================================================================
4325 --- linux-2.6.21.7.orig/include/asm-arm/arch-ixp4xx/platform.h
4326 +++ linux-2.6.21.7/include/asm-arm/arch-ixp4xx/platform.h
4327 @@ -86,6 +86,25 @@ struct ixp4xx_i2c_pins {
4328 unsigned long scl_pin;
4331 +struct npe_plat_data {
4335 + int id; /* Node ID */
4338 +struct mac_plat_info {
4339 + int npe_id; /* Node ID of the NPE for this port */
4340 + int port_id; /* Port ID for NPE-B @ ixp465 */
4341 + int eth_id; /* Physical ID */
4342 + int phy_id; /* ID of the connected PHY (PCB/platform dependent) */
4343 + int rxq_id; /* Queue ID of the RX-free q */
4344 + int rxdoneq_id; /* where incoming packets are returned */
4345 + int txq_id; /* Where to push the outgoing packets */
4346 + unsigned char hwaddr[6]; /* Desired hardware address */
4351 * This structure provide a means for the board setup code
4352 * to give information to th pata_ixp4xx driver. It is
4353 Index: linux-2.6.21.7/include/linux/ixp_crypto.h
4354 ===================================================================
4356 +++ linux-2.6.21.7/include/linux/ixp_crypto.h
4359 +#ifndef IX_CRYPTO_H
4360 +#define IX_CRYPTO_H
4362 +#define MAX_KEYLEN 64
4363 +#define NPE_CTX_LEN 80
4364 +#define AES_BLOCK128 16
4366 +#define NPE_OP_HASH_GEN_ICV 0x50
4367 +#define NPE_OP_ENC_GEN_KEY 0xc9
4370 +#define NPE_OP_HASH_VERIFY 0x01
4371 +#define NPE_OP_CCM_ENABLE 0x04
4372 +#define NPE_OP_CRYPT_ENABLE 0x08
4373 +#define NPE_OP_HASH_ENABLE 0x10
4374 +#define NPE_OP_NOT_IN_PLACE 0x20
4375 +#define NPE_OP_HMAC_DISABLE 0x40
4376 +#define NPE_OP_CRYPT_ENCRYPT 0x80
4378 +#define MOD_ECB 0x0000
4379 +#define MOD_CTR 0x1000
4380 +#define MOD_CBC_ENC 0x2000
4381 +#define MOD_CBC_DEC 0x3000
4382 +#define MOD_CCM_ENC 0x4000
4383 +#define MOD_CCM_DEC 0x5000
4385 +#define ALGO_AES 0x0800
4386 +#define CIPH_DECR 0x0000
4387 +#define CIPH_ENCR 0x0400
4389 +#define MOD_DES 0x0000
4390 +#define MOD_TDEA2 0x0100
4391 +#define MOD_TDEA3 0x0200
4392 +#define MOD_AES128 0x0000
4393 +#define MOD_AES192 0x0100
4394 +#define MOD_AES256 0x0200
4396 +#define KEYLEN_128 4
4397 +#define KEYLEN_192 6
4398 +#define KEYLEN_256 8
4400 +#define CIPHER_TYPE_NULL 0
4401 +#define CIPHER_TYPE_DES 1
4402 +#define CIPHER_TYPE_3DES 2
4403 +#define CIPHER_TYPE_AES 3
4405 +#define CIPHER_MODE_ECB 1
4406 +#define CIPHER_MODE_CTR 2
4407 +#define CIPHER_MODE_CBC 3
4408 +#define CIPHER_MODE_CCM 4
4410 +#define HASH_TYPE_NULL 0
4411 +#define HASH_TYPE_MD5 1
4412 +#define HASH_TYPE_SHA1 2
4413 +#define HASH_TYPE_CBCMAC 3
4415 +#define OP_REG_DONE 1
4416 +#define OP_REGISTER 2
4417 +#define OP_PERFORM 3
4419 +#define STATE_UNREGISTERED 0
4420 +#define STATE_REGISTERED 1
4421 +#define STATE_UNLOADING 2
4424 +#ifndef CONFIG_NPE_ADDRESS_COHERENT
4425 + u8 mode; /* NPE operation */
4431 + u8 mode; /* NPE operation */
4433 + u8 iv[16]; /* IV for CBC mode or CTR IV for CTR mode */
4440 +#ifndef CONFIG_NPE_ADDRESS_COHERENT
4441 + u16 auth_offs; /* Authentication start offset */
4442 + u16 auth_len; /* Authentication data length */
4443 + u16 crypt_offs; /* Cryption start offset */
4444 + u16 crypt_len; /* Cryption data length */
4446 + u16 auth_len; /* Authentication data length */
4447 + u16 auth_offs; /* Authentication start offset */
4448 + u16 crypt_len; /* Cryption data length */
4449 + u16 crypt_offs; /* Cryption start offset */
4451 + u32 aadAddr; /* Additional Auth Data Addr for CCM mode */
4452 + u32 crypto_ctx; /* NPE Crypto Param structure address */
4454 + /* Used by Host */
4455 + struct ix_sa_ctx *sa_ctx;
4459 +struct npe_crypt_cont {
4461 + struct crypt_ctl crypt;
4462 + u8 rev_aes_key[NPE_CTX_LEN];
4464 + struct npe_crypt_cont *next;
4465 + struct npe_crypt_cont *virt;
4469 +struct ix_hash_algo {
4474 + unsigned char *icv;
4478 +struct ix_cipher_algo {
4489 + u8 key[MAX_KEYLEN];
4493 +struct ix_sa_master {
4494 + struct device *npe_dev;
4495 + struct qm_queue *sendq;
4496 + struct qm_queue *recvq;
4497 + struct dma_pool *dmapool;
4498 + struct npe_crypt_cont *pool;
4504 + unsigned char *npe_ctx;
4505 + dma_addr_t npe_ctx_phys;
4511 + struct list_head list;
4512 + struct ix_sa_master *master;
4514 + const struct ix_hash_algo *h_algo;
4515 + const struct ix_cipher_algo *c_algo;
4516 + struct ix_key c_key;
4517 + struct ix_key h_key;
4521 + struct ix_sa_dir encrypt;
4522 + struct ix_sa_dir decrypt;
4524 + struct npe_crypt_cont *rev_aes;
4530 + void(*reg_cb)(struct ix_sa_ctx*, int);
4531 + void(*perf_cb)(struct ix_sa_ctx*, void*, int);
4535 +const struct ix_hash_algo *ix_hash_by_id(int type);
4536 +const struct ix_cipher_algo *ix_cipher_by_id(int type, int mode);
4538 +struct ix_sa_ctx *ix_sa_ctx_new(int priv_len, gfp_t flags);
4539 +void ix_sa_ctx_free(struct ix_sa_ctx *sa_ctx);
4541 +int ix_sa_crypto_perform(struct ix_sa_ctx *sa_ctx, u8 *data, void *ptr,
4542 + int datalen, int c_offs, int c_len, int a_offs, int a_len,
4543 + int hmac, char *iv, int encrypt);
4545 +int ix_sa_ctx_setup_cipher_auth(struct ix_sa_ctx *sa_ctx,
4546 + const struct ix_cipher_algo *cipher,
4547 + const struct ix_hash_algo *auth, int len);
4550 Index: linux-2.6.21.7/include/linux/ixp_npe.h
4551 ===================================================================
4553 +++ linux-2.6.21.7/include/linux/ixp_npe.h
4556 + * Copyright (C) 2006 Christian Hohnstaedt <chohnstaedt@innominate.com>
4558 + * This file is released under the GPLv2
4561 +#ifndef NPE_DEVICE_H
4562 +#define NPE_DEVICE_H
4564 +#include <linux/miscdevice.h>
4565 +#include <asm/hardware.h>
4568 +#undef CONFIG_NPE_ADDRESS_COHERENT
4570 +#define CONFIG_NPE_ADDRESS_COHERENT
4573 +#if defined(__ARMEB__) || defined (CONFIG_NPE_ADDRESS_COHERENT)
4574 +#define npe_to_cpu32(x) (x)
4575 +#define npe_to_cpu16(x) (x)
4576 +#define cpu_to_npe32(x) (x)
4577 +#define cpu_to_npe16(x) (x)
4579 +#error NPE_DATA_COHERENT
4580 +#define NPE_DATA_COHERENT
4581 +#define npe_to_cpu32(x) be32_to_cpu(x)
4582 +#define npe_to_cpu16(x) be16_to_cpu(x)
4583 +#define cpu_to_npe32(x) cpu_to_be32(x)
4584 +#define cpu_to_npe16(x) cpu_to_be16(x)
4589 + struct resource *res;
4590 + void __iomem *addr;
4591 + struct npe_plat_data *plat;
4600 +static inline void npe_reg_write(struct npe_info *npe, u32 reg, u32 val)
4602 + *(volatile u32*)((u8*)(npe->addr) + reg) = val;
4605 +static inline u32 npe_reg_read(struct npe_info *npe, u32 reg)
4607 + return *(volatile u32*)((u8*)(npe->addr) + reg);
4610 +static inline u32 npe_status(struct npe_info *npe)
4612 + return npe_reg_read(npe, IX_NPEDL_REG_OFFSET_EXCTL);
4615 +/* ixNpeDlNpeMgrCommandIssue */
4616 +static inline void npe_write_exctl(struct npe_info *npe, u32 cmd)
4618 + npe_reg_write(npe, IX_NPEDL_REG_OFFSET_EXCTL, cmd);
4620 +/* ixNpeDlNpeMgrWriteCommandIssue */
4622 +npe_write_cmd(struct npe_info *npe, u32 addr, u32 data, int cmd)
4624 + npe_reg_write(npe, IX_NPEDL_REG_OFFSET_EXDATA, data);
4625 + npe_reg_write(npe, IX_NPEDL_REG_OFFSET_EXAD, addr);
4626 + npe_reg_write(npe, IX_NPEDL_REG_OFFSET_EXCTL, cmd);
4628 +/* ixNpeDlNpeMgrReadCommandIssue */
4630 +npe_read_cmd(struct npe_info *npe, u32 addr, int cmd)
4632 + npe_reg_write(npe, IX_NPEDL_REG_OFFSET_EXAD, addr);
4633 + npe_reg_write(npe, IX_NPEDL_REG_OFFSET_EXCTL, cmd);
4634 + /* Intel reads the data twice - so do we... */
4635 + npe_reg_read(npe, IX_NPEDL_REG_OFFSET_EXDATA);
4636 + return npe_reg_read(npe, IX_NPEDL_REG_OFFSET_EXDATA);
4639 +/* ixNpeDlNpeMgrExecAccRegWrite */
4640 +static inline void npe_write_ecs_reg(struct npe_info *npe, u32 addr, u32 data)
4642 + npe_write_cmd(npe, addr, data, IX_NPEDL_EXCTL_CMD_WR_ECS_REG);
4644 +/* ixNpeDlNpeMgrExecAccRegRead */
4645 +static inline u32 npe_read_ecs_reg(struct npe_info *npe, u32 addr)
4647 + return npe_read_cmd(npe, addr, IX_NPEDL_EXCTL_CMD_RD_ECS_REG);
4650 +extern void npe_stop(struct npe_info *npe);
4651 +extern void npe_start(struct npe_info *npe);
4652 +extern void npe_reset(struct npe_info *npe);
4654 +extern struct device *get_npe_by_id(int id);
4655 +extern void return_npe_dev(struct device *dev);
4659 +npe_mh_status(struct npe_info *npe);
4661 +npe_mh_setportaddr(struct npe_info *npe, struct mac_plat_info *mp, u8 *macaddr);
4663 +npe_mh_disable_firewall(struct npe_info *npe, struct mac_plat_info *mp);
4665 +npe_mh_set_rxqid(struct npe_info *npe, struct mac_plat_info *mp, int qid);
4667 +npe_mh_npe_loopback_mode(struct npe_info *npe, struct mac_plat_info *mp, int enable);
4669 +npe_mh_get_stats(struct npe_info *npe, struct mac_plat_info *mp, u32 phys, int reset);
4672 Index: linux-2.6.21.7/include/linux/ixp_qmgr.h
4673 ===================================================================
4675 +++ linux-2.6.21.7/include/linux/ixp_qmgr.h
4678 + * Copyright (C) 2006 Christian Hohnstaedt <chohnstaedt@innominate.com>
4680 + * This file is released under the GPLv2
4686 +#include <linux/skbuff.h>
4687 +#include <linux/list.h>
4688 +#include <linux/if_ether.h>
4689 +#include <linux/spinlock.h>
4690 +#include <linux/platform_device.h>
4691 +#include <linux/ixp_npe.h>
4692 +#include <asm/atomic.h>
4694 +/* All offsets are in 32bit words */
4695 +#define QUE_LOW_STAT0 0x100 /* 4x Status of the 32 lower queues 0-31 */
4696 +#define QUE_UO_STAT0 0x104 /* 2x Underflow/Overflow status bits*/
4697 +#define QUE_UPP_STAT0 0x106 /* 2x Status of thew 32 upper queues 32-63 */
4698 +#define INT0_SRC_SELREG0 0x108 /* 4x */
4699 +#define QUE_IE_REG0 0x10c /* 2x */
4700 +#define QUE_INT_REG0 0x10e /* 2x IRQ reg, write 1 to reset IRQ */
4702 +#define IX_QMGR_QCFG_BASE 0x800
4703 +#define IX_QMGR_QCFG_SIZE 0x40
4704 +#define IX_QMGR_SRAM_SPACE (IX_QMGR_QCFG_BASE + IX_QMGR_QCFG_SIZE)
4706 +#define MAX_QUEUES 32 /* first, we only support the lower 32 queues */
4710 + Q_IRQ_ID_E = 0, /* Queue Empty due to last read */
4711 + Q_IRQ_ID_NE, /* Queue Nearly Empty due to last read */
4712 + Q_IRQ_ID_NF, /* Queue Nearly Full due to last write */
4713 + Q_IRQ_ID_F, /* Queue Full due to last write */
4714 + Q_IRQ_ID_NOT_E, /* Queue Not Empty due to last write */
4715 + Q_IRQ_ID_NOT_NE, /* Queue Not Nearly Empty due to last write */
4716 + Q_IRQ_ID_NOT_NF, /* Queue Not Nearly Full due to last read */
4717 + Q_IRQ_ID_NOT_F /* Queue Not Full due to last read */
4720 +extern struct qm_queue *request_queue(int qid, int len);
4721 +extern void release_queue(struct qm_queue *queue);
4722 +extern int queue_set_irq_src(struct qm_queue *queue, int flag);
4723 +extern void queue_set_watermarks(struct qm_queue *, unsigned ne, unsigned nf);
4724 +extern int queue_len(struct qm_queue *queue);
4729 +typedef void(*queue_cb)(struct qm_queue *);
4732 + int addr; /* word offset from IX_QMGR_SRAM_SPACE */
4733 + int len; /* size in words */
4734 + int id; /* Q Id */
4735 + u32 __iomem *acc_reg;
4736 + struct device *dev;
4742 +#ifndef CONFIG_NPE_ADDRESS_COHERENT
4754 + u8 dest_mac[ETH_ALEN];
4755 + u8 src_mac[ETH_ALEN];
4770 + u8 dest_mac[ETH_ALEN];
4771 + u8 src_mac[ETH_ALEN];
4776 + struct eth_ctl eth;
4778 + struct npe_cont *next;
4779 + struct npe_cont *virt;
4784 + u32 __iomem *addr;
4785 + struct resource *res;
4786 + struct qm_queue *queues[MAX_QUEUES];
4788 + struct npe_cont *pool;
4789 + struct dma_pool *dmapool;
4793 +static inline void queue_write_cfg_reg(struct qm_queue *queue, u32 val)
4795 + struct qm_qmgr *qmgr = dev_get_drvdata(queue->dev);
4796 + *(qmgr->addr + IX_QMGR_QCFG_BASE + queue->id) = val;
4798 +static inline u32 queue_read_cfg_reg(struct qm_queue *queue)
4800 + struct qm_qmgr *qmgr = dev_get_drvdata(queue->dev);
4801 + return *(qmgr->addr + IX_QMGR_QCFG_BASE + queue->id);
4804 +static inline void queue_ack_irq(struct qm_queue *queue)
4806 + struct qm_qmgr *qmgr = dev_get_drvdata(queue->dev);
4807 + *(qmgr->addr + QUE_INT_REG0) = 1 << queue->id;
4810 +static inline void queue_enable_irq(struct qm_queue *queue)
4812 + struct qm_qmgr *qmgr = dev_get_drvdata(queue->dev);
4813 + *(qmgr->addr + QUE_IE_REG0) |= 1 << queue->id;
4816 +static inline void queue_disable_irq(struct qm_queue *queue)
4818 + struct qm_qmgr *qmgr = dev_get_drvdata(queue->dev);
4819 + *(qmgr->addr + QUE_IE_REG0) &= ~(1 << queue->id);
4822 +static inline void queue_put_entry(struct qm_queue *queue, u32 entry)
4824 + *(queue->acc_reg) = npe_to_cpu32(entry);
4827 +static inline u32 queue_get_entry(struct qm_queue *queue)
4829 + return cpu_to_npe32(*queue->acc_reg);
4832 +static inline struct npe_cont *qmgr_get_cont(struct qm_qmgr *qmgr)
4834 + unsigned long flags;
4835 + struct npe_cont *cont;
4839 + write_lock_irqsave(&qmgr->lock, flags);
4840 + cont = qmgr->pool;
4841 + qmgr->pool = cont->next;
4842 + write_unlock_irqrestore(&qmgr->lock, flags);
4846 +static inline void qmgr_return_cont(struct qm_qmgr *qmgr,struct npe_cont *cont)
4848 + unsigned long flags;
4850 + write_lock_irqsave(&qmgr->lock, flags);
4851 + cont->next = qmgr->pool;
4852 + qmgr->pool = cont;
4853 + write_unlock_irqrestore(&qmgr->lock, flags);
4856 +static inline int queue_stat(struct qm_queue *queue)
4858 + struct qm_qmgr *qmgr = dev_get_drvdata(queue->dev);
4859 + u32 reg = *(qmgr->addr + QUE_UO_STAT0 + (queue->id >> 4));
4860 + return (reg >> (queue->id & 0xf) << 1) & 3;
4863 +/* Prints the queue state, which is very, very helpfull for debugging */
4864 +static inline void queue_state(struct qm_queue *queue)
4866 + u32 val=0, lstat=0;
4868 + struct qm_qmgr *qmgr = dev_get_drvdata(queue->dev);
4870 + offs = queue->id/8 + QUE_LOW_STAT0;
4871 + val = *(qmgr->addr + IX_QMGR_QCFG_BASE + queue->id);
4872 + lstat = (*(qmgr->addr + offs) >> ((queue->id % 8)*4)) & 0x0f;
4874 + printk("Qid[%02d]: Wptr=%4x, Rptr=%4x, diff=%4x, Stat:%x\n", queue->id,
4875 + val&0x7f, (val>>7) &0x7f, (val - (val >> 7)) & 0x7f, lstat);