1 Index: linux-2.6.23.17/arch/arm/kernel/setup.c
2 ===================================================================
3 --- linux-2.6.23.17.orig/arch/arm/kernel/setup.c
4 +++ linux-2.6.23.17/arch/arm/kernel/setup.c
5 @@ -62,6 +62,7 @@ extern int root_mountflags;
6 extern void _stext, _text, _etext, __data_start, _edata, _end;
8 unsigned int processor_id;
9 +EXPORT_SYMBOL(processor_id);
10 unsigned int __machine_arch_type;
11 EXPORT_SYMBOL(__machine_arch_type);
13 Index: linux-2.6.23.17/arch/arm/mach-ixp4xx/Kconfig
14 ===================================================================
15 --- linux-2.6.23.17.orig/arch/arm/mach-ixp4xx/Kconfig
16 +++ linux-2.6.23.17/arch/arm/mach-ixp4xx/Kconfig
17 @@ -246,6 +246,20 @@ config IXP4XX_INDIRECT_PCI
18 need to use the indirect method instead. If you don't know
19 what you need, leave this option unselected.
22 + tristate "IXP4xx Queue Manager support"
24 + This driver supports IXP4xx built-in hardware queue manager
25 + and is automatically selected by Ethernet and HSS drivers.
28 + tristate "IXP4xx Network Processor Engine support"
32 + This driver supports IXP4xx built-in network coprocessors
33 + and is automatically selected by Ethernet and HSS drivers.
38 Index: linux-2.6.23.17/arch/arm/mach-ixp4xx/Makefile
39 ===================================================================
40 --- linux-2.6.23.17.orig/arch/arm/mach-ixp4xx/Makefile
41 +++ linux-2.6.23.17/arch/arm/mach-ixp4xx/Makefile
42 @@ -44,3 +44,5 @@ obj-$(CONFIG_MACH_SIDEWINDER) += sidewin
43 obj-$(CONFIG_MACH_AP1000) += ap1000-setup.o
45 obj-$(CONFIG_PCI) += $(obj-pci-$(CONFIG_PCI)) common-pci.o
46 +obj-$(CONFIG_IXP4XX_QMGR) += ixp4xx_qmgr.o
47 +obj-$(CONFIG_IXP4XX_NPE) += ixp4xx_npe.o
48 Index: linux-2.6.23.17/arch/arm/mach-ixp4xx/ixdp425-setup.c
49 ===================================================================
50 --- linux-2.6.23.17.orig/arch/arm/mach-ixp4xx/ixdp425-setup.c
51 +++ linux-2.6.23.17/arch/arm/mach-ixp4xx/ixdp425-setup.c
52 @@ -177,6 +177,31 @@ static struct platform_device ixdp425_ua
53 .resource = ixdp425_uart_resources
56 +/* Built-in 10/100 Ethernet MAC interfaces */
57 +static struct eth_plat_info ixdp425_plat_eth[] = {
69 +static struct platform_device ixdp425_eth[] = {
71 + .name = "ixp4xx_eth",
72 + .id = IXP4XX_ETH_NPEB,
73 + .dev.platform_data = ixdp425_plat_eth,
75 + .name = "ixp4xx_eth",
76 + .id = IXP4XX_ETH_NPEC,
77 + .dev.platform_data = ixdp425_plat_eth + 1,
81 static struct platform_device *ixdp425_devices[] __initdata = {
84 @@ -184,7 +209,9 @@ static struct platform_device *ixdp425_d
85 defined(CONFIG_MTD_NAND_PLATFORM_MODULE)
94 static void __init ixdp425_init(void)
95 Index: linux-2.6.23.17/arch/arm/mach-ixp4xx/ixp4xx_npe.c
96 ===================================================================
98 +++ linux-2.6.23.17/arch/arm/mach-ixp4xx/ixp4xx_npe.c
101 + * Intel IXP4xx Network Processor Engine driver for Linux
103 + * Copyright (C) 2007 Krzysztof Halasa <khc@pm.waw.pl>
105 + * This program is free software; you can redistribute it and/or modify it
106 + * under the terms of version 2 of the GNU General Public License
107 + * as published by the Free Software Foundation.
109 + * The code is based on publicly available information:
110 + * - Intel IXP4xx Developer's Manual and other e-papers
111 + * - Intel IXP400 Access Library Software (BSD license)
112 + * - previous works by Christian Hohnstaedt <chohnstaedt@innominate.com>
113 + * Thanks, Christian.
116 +#include <linux/delay.h>
117 +#include <linux/dma-mapping.h>
118 +#include <linux/firmware.h>
119 +#include <linux/io.h>
120 +#include <linux/kernel.h>
121 +#include <linux/module.h>
122 +#include <linux/slab.h>
123 +#include <asm/arch/npe.h>
129 +#define MAX_RETRIES 1000 /* microseconds */
130 +#define NPE_42X_DATA_SIZE 0x800 /* in dwords */
131 +#define NPE_46X_DATA_SIZE 0x1000
132 +#define NPE_A_42X_INSTR_SIZE 0x1000
133 +#define NPE_B_AND_C_42X_INSTR_SIZE 0x800
134 +#define NPE_46X_INSTR_SIZE 0x1000
135 +#define REGS_SIZE 0x1000
137 +#define NPE_PHYS_REG 32
139 +#define FW_MAGIC 0xFEEDF00D
140 +#define FW_BLOCK_TYPE_INSTR 0x0
141 +#define FW_BLOCK_TYPE_DATA 0x1
142 +#define FW_BLOCK_TYPE_EOF 0xF
144 +/* NPE exec status (read) and command (write) */
145 +#define CMD_NPE_STEP 0x01
146 +#define CMD_NPE_START 0x02
147 +#define CMD_NPE_STOP 0x03
148 +#define CMD_NPE_CLR_PIPE 0x04
149 +#define CMD_CLR_PROFILE_CNT 0x0C
150 +#define CMD_RD_INS_MEM 0x10 /* instruction memory */
151 +#define CMD_WR_INS_MEM 0x11
152 +#define CMD_RD_DATA_MEM 0x12 /* data memory */
153 +#define CMD_WR_DATA_MEM 0x13
154 +#define CMD_RD_ECS_REG 0x14 /* exec access register */
155 +#define CMD_WR_ECS_REG 0x15
157 +#define STAT_RUN 0x80000000
158 +#define STAT_STOP 0x40000000
159 +#define STAT_CLEAR 0x20000000
160 +#define STAT_ECS_K 0x00800000 /* pipeline clean */
162 +#define NPE_STEVT 0x1B
163 +#define NPE_STARTPC 0x1C
164 +#define NPE_REGMAP 0x1E
165 +#define NPE_CINDEX 0x1F
167 +#define INSTR_WR_REG_SHORT 0x0000C000
168 +#define INSTR_WR_REG_BYTE 0x00004000
169 +#define INSTR_RD_FIFO 0x0F888220
170 +#define INSTR_RESET_MBOX 0x0FAC8210
172 +#define ECS_BG_CTXT_REG_0 0x00 /* Background Executing Context */
173 +#define ECS_BG_CTXT_REG_1 0x01 /* Stack level */
174 +#define ECS_BG_CTXT_REG_2 0x02
175 +#define ECS_PRI_1_CTXT_REG_0 0x04 /* Priority 1 Executing Context */
176 +#define ECS_PRI_1_CTXT_REG_1 0x05 /* Stack level */
177 +#define ECS_PRI_1_CTXT_REG_2 0x06
178 +#define ECS_PRI_2_CTXT_REG_0 0x08 /* Priority 2 Executing Context */
179 +#define ECS_PRI_2_CTXT_REG_1 0x09 /* Stack level */
180 +#define ECS_PRI_2_CTXT_REG_2 0x0A
181 +#define ECS_DBG_CTXT_REG_0 0x0C /* Debug Executing Context */
182 +#define ECS_DBG_CTXT_REG_1 0x0D /* Stack level */
183 +#define ECS_DBG_CTXT_REG_2 0x0E
184 +#define ECS_INSTRUCT_REG 0x11 /* NPE Instruction Register */
186 +#define ECS_REG_0_ACTIVE 0x80000000 /* all levels */
187 +#define ECS_REG_0_NEXTPC_MASK 0x1FFF0000 /* BG/PRI1/PRI2 levels */
188 +#define ECS_REG_0_LDUR_BITS 8
189 +#define ECS_REG_0_LDUR_MASK 0x00000700 /* all levels */
190 +#define ECS_REG_1_CCTXT_BITS 16
191 +#define ECS_REG_1_CCTXT_MASK 0x000F0000 /* all levels */
192 +#define ECS_REG_1_SELCTXT_BITS 0
193 +#define ECS_REG_1_SELCTXT_MASK 0x0000000F /* all levels */
194 +#define ECS_DBG_REG_2_IF 0x00100000 /* debug level */
195 +#define ECS_DBG_REG_2_IE 0x00080000 /* debug level */
197 +/* NPE watchpoint_fifo register bit */
198 +#define WFIFO_VALID 0x80000000
200 +/* NPE messaging_status register bit definitions */
201 +#define MSGSTAT_OFNE 0x00010000 /* OutFifoNotEmpty */
202 +#define MSGSTAT_IFNF 0x00020000 /* InFifoNotFull */
203 +#define MSGSTAT_OFNF 0x00040000 /* OutFifoNotFull */
204 +#define MSGSTAT_IFNE 0x00080000 /* InFifoNotEmpty */
205 +#define MSGSTAT_MBINT 0x00100000 /* Mailbox interrupt */
206 +#define MSGSTAT_IFINT 0x00200000 /* InFifo interrupt */
207 +#define MSGSTAT_OFINT 0x00400000 /* OutFifo interrupt */
208 +#define MSGSTAT_WFINT 0x00800000 /* WatchFifo interrupt */
210 +/* NPE messaging_control register bit definitions */
211 +#define MSGCTL_OUT_FIFO 0x00010000 /* enable output FIFO */
212 +#define MSGCTL_IN_FIFO 0x00020000 /* enable input FIFO */
213 +#define MSGCTL_OUT_FIFO_WRITE 0x01000000 /* enable FIFO + WRITE */
214 +#define MSGCTL_IN_FIFO_WRITE 0x02000000
216 +/* NPE mailbox_status value for reset */
217 +#define RESET_MBOX_STAT 0x0000F0F0
219 +const char *npe_names[] = { "NPE-A", "NPE-B", "NPE-C" };
221 +#define print_npe(pri, npe, fmt, ...) \
222 + printk(pri "%s: " fmt, npe_name(npe), ## __VA_ARGS__)
225 +#define debug_msg(npe, fmt, ...) \
226 + print_npe(KERN_DEBUG, npe, fmt, ## __VA_ARGS__)
228 +#define debug_msg(npe, fmt, ...)
234 + { ECS_BG_CTXT_REG_0, 0xA0000000 },
235 + { ECS_BG_CTXT_REG_1, 0x01000000 },
236 + { ECS_BG_CTXT_REG_2, 0x00008000 },
237 + { ECS_PRI_1_CTXT_REG_0, 0x20000080 },
238 + { ECS_PRI_1_CTXT_REG_1, 0x01000000 },
239 + { ECS_PRI_1_CTXT_REG_2, 0x00008000 },
240 + { ECS_PRI_2_CTXT_REG_0, 0x20000080 },
241 + { ECS_PRI_2_CTXT_REG_1, 0x01000000 },
242 + { ECS_PRI_2_CTXT_REG_2, 0x00008000 },
243 + { ECS_DBG_CTXT_REG_0, 0x20000000 },
244 + { ECS_DBG_CTXT_REG_1, 0x00000000 },
245 + { ECS_DBG_CTXT_REG_2, 0x001E0000 },
246 + { ECS_INSTRUCT_REG, 0x1003C00F },
249 +static struct npe npe_tab[NPE_COUNT] = {
252 + .regs = (struct npe_regs __iomem *)IXP4XX_NPEA_BASE_VIRT,
253 + .regs_phys = IXP4XX_NPEA_BASE_PHYS,
256 + .regs = (struct npe_regs __iomem *)IXP4XX_NPEB_BASE_VIRT,
257 + .regs_phys = IXP4XX_NPEB_BASE_PHYS,
260 + .regs = (struct npe_regs __iomem *)IXP4XX_NPEC_BASE_VIRT,
261 + .regs_phys = IXP4XX_NPEC_BASE_PHYS,
265 +int npe_running(struct npe *npe)
267 + return (__raw_readl(&npe->regs->exec_status_cmd) & STAT_RUN) != 0;
270 +static void npe_cmd_write(struct npe *npe, u32 addr, int cmd, u32 data)
272 + __raw_writel(data, &npe->regs->exec_data);
273 + __raw_writel(addr, &npe->regs->exec_addr);
274 + __raw_writel(cmd, &npe->regs->exec_status_cmd);
277 +static u32 npe_cmd_read(struct npe *npe, u32 addr, int cmd)
279 + __raw_writel(addr, &npe->regs->exec_addr);
280 + __raw_writel(cmd, &npe->regs->exec_status_cmd);
281 + /* Iintroduce extra read cycles after issuing read command to NPE
282 + so that we read the register after the NPE has updated it.
283 + This is to overcome race condition between XScale and NPE */
284 + __raw_readl(&npe->regs->exec_data);
285 + __raw_readl(&npe->regs->exec_data);
286 + return __raw_readl(&npe->regs->exec_data);
289 +static void npe_clear_active(struct npe *npe, u32 reg)
291 + u32 val = npe_cmd_read(npe, reg, CMD_RD_ECS_REG);
292 + npe_cmd_write(npe, reg, CMD_WR_ECS_REG, val & ~ECS_REG_0_ACTIVE);
295 +static void npe_start(struct npe *npe)
297 + /* ensure only Background Context Stack Level is active */
298 + npe_clear_active(npe, ECS_PRI_1_CTXT_REG_0);
299 + npe_clear_active(npe, ECS_PRI_2_CTXT_REG_0);
300 + npe_clear_active(npe, ECS_DBG_CTXT_REG_0);
302 + __raw_writel(CMD_NPE_CLR_PIPE, &npe->regs->exec_status_cmd);
303 + __raw_writel(CMD_NPE_START, &npe->regs->exec_status_cmd);
306 +static void npe_stop(struct npe *npe)
308 + __raw_writel(CMD_NPE_STOP, &npe->regs->exec_status_cmd);
309 + __raw_writel(CMD_NPE_CLR_PIPE, &npe->regs->exec_status_cmd); /*FIXME?*/
312 +static int __must_check npe_debug_instr(struct npe *npe, u32 instr, u32 ctx,
318 + /* set the Active bit, and the LDUR, in the debug level */
319 + npe_cmd_write(npe, ECS_DBG_CTXT_REG_0, CMD_WR_ECS_REG,
320 + ECS_REG_0_ACTIVE | (ldur << ECS_REG_0_LDUR_BITS));
322 + /* set CCTXT at ECS DEBUG L3 to specify in which context to execute
323 + the instruction, and set SELCTXT at ECS DEBUG Level to specify
324 + which context store to access.
325 + Debug ECS Level Reg 1 has form 0x000n000n, where n = context number
327 + npe_cmd_write(npe, ECS_DBG_CTXT_REG_1, CMD_WR_ECS_REG,
328 + (ctx << ECS_REG_1_CCTXT_BITS) |
329 + (ctx << ECS_REG_1_SELCTXT_BITS));
331 + /* clear the pipeline */
332 + __raw_writel(CMD_NPE_CLR_PIPE, &npe->regs->exec_status_cmd);
334 + /* load NPE instruction into the instruction register */
335 + npe_cmd_write(npe, ECS_INSTRUCT_REG, CMD_WR_ECS_REG, instr);
337 + /* we need this value later to wait for completion of NPE execution
339 + wc = __raw_readl(&npe->regs->watch_count);
341 + /* issue a Step One command via the Execution Control register */
342 + __raw_writel(CMD_NPE_STEP, &npe->regs->exec_status_cmd);
344 + /* Watch Count register increments when NPE completes an instruction */
345 + for (i = 0; i < MAX_RETRIES; i++) {
346 + if (wc != __raw_readl(&npe->regs->watch_count))
351 + print_npe(KERN_ERR, npe, "reset: npe_debug_instr(): timeout\n");
355 +static int __must_check npe_logical_reg_write8(struct npe *npe, u32 addr,
358 + /* here we build the NPE assembler instruction: mov8 d0, #0 */
359 + u32 instr = INSTR_WR_REG_BYTE | /* OpCode */
360 + addr << 9 | /* base Operand */
361 + (val & 0x1F) << 4 | /* lower 5 bits to immediate data */
362 + (val & ~0x1F) << (18 - 5);/* higher 3 bits to CoProc instr. */
363 + return npe_debug_instr(npe, instr, ctx, 1); /* execute it */
366 +static int __must_check npe_logical_reg_write16(struct npe *npe, u32 addr,
369 + /* here we build the NPE assembler instruction: mov16 d0, #0 */
370 + u32 instr = INSTR_WR_REG_SHORT | /* OpCode */
371 + addr << 9 | /* base Operand */
372 + (val & 0x1F) << 4 | /* lower 5 bits to immediate data */
373 + (val & ~0x1F) << (18 - 5);/* higher 11 bits to CoProc instr. */
374 + return npe_debug_instr(npe, instr, ctx, 1); /* execute it */
377 +static int __must_check npe_logical_reg_write32(struct npe *npe, u32 addr,
380 + /* write in 16 bit steps first the high and then the low value */
381 + if (npe_logical_reg_write16(npe, addr, val >> 16, ctx))
383 + return npe_logical_reg_write16(npe, addr + 2, val & 0xFFFF, ctx);
386 +static int npe_reset(struct npe *npe)
388 + u32 val, ctl, exec_count, ctx_reg2;
391 + ctl = (__raw_readl(&npe->regs->messaging_control) | 0x3F000000) &
394 + /* disable parity interrupt */
395 + __raw_writel(ctl & 0x3F00FFFF, &npe->regs->messaging_control);
397 + /* pre exec - debug instruction */
398 + /* turn off the halt bit by clearing Execution Count register. */
399 + exec_count = __raw_readl(&npe->regs->exec_count);
400 + __raw_writel(0, &npe->regs->exec_count);
401 + /* ensure that IF and IE are on (temporarily), so that we don't end up
402 + stepping forever */
403 + ctx_reg2 = npe_cmd_read(npe, ECS_DBG_CTXT_REG_2, CMD_RD_ECS_REG);
404 + npe_cmd_write(npe, ECS_DBG_CTXT_REG_2, CMD_WR_ECS_REG, ctx_reg2 |
405 + ECS_DBG_REG_2_IF | ECS_DBG_REG_2_IE);
407 + /* clear the FIFOs */
408 + while (__raw_readl(&npe->regs->watchpoint_fifo) & WFIFO_VALID)
410 + while (__raw_readl(&npe->regs->messaging_status) & MSGSTAT_OFNE)
411 + /* read from the outFIFO until empty */
412 + print_npe(KERN_DEBUG, npe, "npe_reset: read FIFO = 0x%X\n",
413 + __raw_readl(&npe->regs->in_out_fifo));
415 + while (__raw_readl(&npe->regs->messaging_status) & MSGSTAT_IFNE)
416 + /* step execution of the NPE intruction to read inFIFO using
417 + the Debug Executing Context stack */
418 + if (npe_debug_instr(npe, INSTR_RD_FIFO, 0, 0))
421 + /* reset the mailbox reg from the XScale side */
422 + __raw_writel(RESET_MBOX_STAT, &npe->regs->mailbox_status);
423 + /* from NPE side */
424 + if (npe_debug_instr(npe, INSTR_RESET_MBOX, 0, 0))
427 + /* Reset the physical registers in the NPE register file */
428 + for (val = 0; val < NPE_PHYS_REG; val++) {
429 + if (npe_logical_reg_write16(npe, NPE_REGMAP, val >> 1, 0))
431 + /* address is either 0 or 4 */
432 + if (npe_logical_reg_write32(npe, (val & 1) * 4, 0, 0))
436 + /* Reset the context store = each context's Context Store registers */
438 + /* Context 0 has no STARTPC. Instead, this value is used to set NextPC
439 + for Background ECS, to set where NPE starts executing code */
440 + val = npe_cmd_read(npe, ECS_BG_CTXT_REG_0, CMD_RD_ECS_REG);
441 + val &= ~ECS_REG_0_NEXTPC_MASK;
442 + val |= (0 /* NextPC */ << 16) & ECS_REG_0_NEXTPC_MASK;
443 + npe_cmd_write(npe, ECS_BG_CTXT_REG_0, CMD_WR_ECS_REG, val);
445 + for (i = 0; i < 16; i++) {
446 + if (i) { /* Context 0 has no STEVT nor STARTPC */
447 + /* STEVT = off, 0x80 */
448 + if (npe_logical_reg_write8(npe, NPE_STEVT, 0x80, i))
450 + if (npe_logical_reg_write16(npe, NPE_STARTPC, 0, i))
453 + /* REGMAP = d0->p0, d8->p2, d16->p4 */
454 + if (npe_logical_reg_write16(npe, NPE_REGMAP, 0x820, i))
456 + if (npe_logical_reg_write8(npe, NPE_CINDEX, 0, i))
461 + /* clear active bit in debug level */
462 + npe_cmd_write(npe, ECS_DBG_CTXT_REG_0, CMD_WR_ECS_REG, 0);
463 + /* clear the pipeline */
464 + __raw_writel(CMD_NPE_CLR_PIPE, &npe->regs->exec_status_cmd);
465 + /* restore previous values */
466 + __raw_writel(exec_count, &npe->regs->exec_count);
467 + npe_cmd_write(npe, ECS_DBG_CTXT_REG_2, CMD_WR_ECS_REG, ctx_reg2);
469 + /* write reset values to Execution Context Stack registers */
470 + for (val = 0; val < ARRAY_SIZE(ecs_reset); val++)
471 + npe_cmd_write(npe, ecs_reset[val].reg, CMD_WR_ECS_REG,
472 + ecs_reset[val].val);
474 + /* clear the profile counter */
475 + __raw_writel(CMD_CLR_PROFILE_CNT, &npe->regs->exec_status_cmd);
477 + __raw_writel(0, &npe->regs->exec_count);
478 + __raw_writel(0, &npe->regs->action_points[0]);
479 + __raw_writel(0, &npe->regs->action_points[1]);
480 + __raw_writel(0, &npe->regs->action_points[2]);
481 + __raw_writel(0, &npe->regs->action_points[3]);
482 + __raw_writel(0, &npe->regs->watch_count);
484 + val = ixp4xx_read_feature_bits();
485 + /* reset the NPE */
486 + ixp4xx_write_feature_bits(val &
487 + ~(IXP4XX_FEATURE_RESET_NPEA << npe->id));
488 + for (i = 0; i < MAX_RETRIES; i++) {
489 + if (!(ixp4xx_read_feature_bits() &
490 + (IXP4XX_FEATURE_RESET_NPEA << npe->id)))
491 + break; /* reset completed */
494 + if (i == MAX_RETRIES)
497 + /* deassert reset */
498 + ixp4xx_write_feature_bits(val |
499 + (IXP4XX_FEATURE_RESET_NPEA << npe->id));
500 + for (i = 0; i < MAX_RETRIES; i++) {
501 + if (ixp4xx_read_feature_bits() &
502 + (IXP4XX_FEATURE_RESET_NPEA << npe->id))
503 + break; /* NPE is back alive */
506 + if (i == MAX_RETRIES)
511 + /* restore NPE configuration bus Control Register - parity settings */
512 + __raw_writel(ctl, &npe->regs->messaging_control);
517 +int npe_send_message(struct npe *npe, const void *msg, const char *what)
519 + const u32 *send = msg;
522 + debug_msg(npe, "Trying to send message %s [%08X:%08X]\n",
523 + what, send[0], send[1]);
525 + if (__raw_readl(&npe->regs->messaging_status) & MSGSTAT_IFNE) {
526 + debug_msg(npe, "NPE input FIFO not empty\n");
530 + __raw_writel(send[0], &npe->regs->in_out_fifo);
532 + if (!(__raw_readl(&npe->regs->messaging_status) & MSGSTAT_IFNF)) {
533 + debug_msg(npe, "NPE input FIFO full\n");
537 + __raw_writel(send[1], &npe->regs->in_out_fifo);
539 + while ((cycles < MAX_RETRIES) &&
540 + (__raw_readl(&npe->regs->messaging_status) & MSGSTAT_IFNE)) {
545 + if (cycles == MAX_RETRIES) {
546 + debug_msg(npe, "Timeout sending message\n");
550 + debug_msg(npe, "Sending a message took %i cycles\n", cycles);
554 +int npe_recv_message(struct npe *npe, void *msg, const char *what)
557 + int cycles = 0, cnt = 0;
559 + debug_msg(npe, "Trying to receive message %s\n", what);
561 + while (cycles < MAX_RETRIES) {
562 + if (__raw_readl(&npe->regs->messaging_status) & MSGSTAT_OFNE) {
563 + recv[cnt++] = __raw_readl(&npe->regs->in_out_fifo);
574 + debug_msg(npe, "Received [%08X]\n", recv[0]);
577 + debug_msg(npe, "Received [%08X:%08X]\n", recv[0], recv[1]);
581 + if (cycles == MAX_RETRIES) {
582 + debug_msg(npe, "Timeout waiting for message\n");
586 + debug_msg(npe, "Receiving a message took %i cycles\n", cycles);
590 +int npe_send_recv_message(struct npe *npe, void *msg, const char *what)
593 + u32 *send = msg, recv[2];
595 + if ((result = npe_send_message(npe, msg, what)) != 0)
597 + if ((result = npe_recv_message(npe, recv, what)) != 0)
600 + if ((recv[0] != send[0]) || (recv[1] != send[1])) {
601 + debug_msg(npe, "Message %s: unexpected message received\n",
609 +int npe_load_firmware(struct npe *npe, const char *name, struct device *dev)
611 + const struct firmware *fw_entry;
624 + struct dl_block blocks[0];
628 + struct dl_codeblock {
634 + int i, j, err, data_size, instr_size, blocks, table_end;
637 + if ((err = request_firmware(&fw_entry, name, dev)) != 0)
641 + if (fw_entry->size < sizeof(struct dl_image)) {
642 + print_npe(KERN_ERR, npe, "incomplete firmware file\n");
645 + image = (struct dl_image*)fw_entry->data;
648 + print_npe(KERN_DEBUG, npe, "firmware: %08X %08X %08X (0x%X bytes)\n",
649 + image->magic, image->id, image->size, image->size * 4);
652 + if (image->magic == swab32(FW_MAGIC)) { /* swapped file */
653 + image->id = swab32(image->id);
654 + image->size = swab32(image->size);
655 + } else if (image->magic != FW_MAGIC) {
656 + print_npe(KERN_ERR, npe, "bad firmware file magic: 0x%X\n",
660 + if ((image->size * 4 + sizeof(struct dl_image)) != fw_entry->size) {
661 + print_npe(KERN_ERR, npe,
662 + "inconsistent size of firmware file\n");
665 + if (((image->id >> 24) & 0xF /* NPE ID */) != npe->id) {
666 + print_npe(KERN_ERR, npe, "firmware file NPE ID mismatch\n");
669 + if (image->magic == swab32(FW_MAGIC))
670 + for (i = 0; i < image->size; i++)
671 + image->data[i] = swab32(image->data[i]);
673 + if (!cpu_is_ixp46x() && ((image->id >> 28) & 0xF /* device ID */)) {
674 + print_npe(KERN_INFO, npe, "IXP46x firmware ignored on "
679 + if (npe_running(npe)) {
680 + print_npe(KERN_INFO, npe, "unable to load firmware, NPE is "
681 + "already running\n");
690 + print_npe(KERN_INFO, npe, "firmware functionality 0x%X, "
691 + "revision 0x%X:%X\n", (image->id >> 16) & 0xFF,
692 + (image->id >> 8) & 0xFF, image->id & 0xFF);
694 + if (!cpu_is_ixp46x()) {
696 + instr_size = NPE_A_42X_INSTR_SIZE;
698 + instr_size = NPE_B_AND_C_42X_INSTR_SIZE;
699 + data_size = NPE_42X_DATA_SIZE;
701 + instr_size = NPE_46X_INSTR_SIZE;
702 + data_size = NPE_46X_DATA_SIZE;
705 + for (blocks = 0; blocks * sizeof(struct dl_block) / 4 < image->size;
707 + if (image->blocks[blocks].type == FW_BLOCK_TYPE_EOF)
709 + if (blocks * sizeof(struct dl_block) / 4 >= image->size) {
710 + print_npe(KERN_INFO, npe, "firmware EOF block marker not "
716 + print_npe(KERN_DEBUG, npe, "%i firmware blocks found\n", blocks);
719 + table_end = blocks * sizeof(struct dl_block) / 4 + 1 /* EOF marker */;
720 + for (i = 0, blk = image->blocks; i < blocks; i++, blk++) {
721 + if (blk->offset > image->size - sizeof(struct dl_codeblock) / 4
722 + || blk->offset < table_end) {
723 + print_npe(KERN_INFO, npe, "invalid offset 0x%X of "
724 + "firmware block #%i\n", blk->offset, i);
728 + cb = (struct dl_codeblock*)&image->data[blk->offset];
729 + if (blk->type == FW_BLOCK_TYPE_INSTR) {
730 + if (cb->npe_addr + cb->size > instr_size)
732 + cmd = CMD_WR_INS_MEM;
733 + } else if (blk->type == FW_BLOCK_TYPE_DATA) {
734 + if (cb->npe_addr + cb->size > data_size)
736 + cmd = CMD_WR_DATA_MEM;
738 + print_npe(KERN_INFO, npe, "invalid firmware block #%i "
739 + "type 0x%X\n", i, blk->type);
742 + if (blk->offset + sizeof(*cb) / 4 + cb->size > image->size) {
743 + print_npe(KERN_INFO, npe, "firmware block #%i doesn't "
744 + "fit in firmware image: type %c, start 0x%X,"
745 + " length 0x%X\n", i,
746 + blk->type == FW_BLOCK_TYPE_INSTR ? 'I' : 'D',
747 + cb->npe_addr, cb->size);
751 + for (j = 0; j < cb->size; j++)
752 + npe_cmd_write(npe, cb->npe_addr + j, cmd, cb->data[j]);
756 + if (!npe_running(npe))
757 + print_npe(KERN_ERR, npe, "unable to start\n");
758 + release_firmware(fw_entry);
762 + print_npe(KERN_INFO, npe, "firmware block #%i doesn't fit in NPE "
763 + "memory: type %c, start 0x%X, length 0x%X\n", i,
764 + blk->type == FW_BLOCK_TYPE_INSTR ? 'I' : 'D',
765 + cb->npe_addr, cb->size);
767 + release_firmware(fw_entry);
772 +struct npe *npe_request(int id)
774 + if (id < NPE_COUNT)
775 + if (npe_tab[id].valid)
776 + if (try_module_get(THIS_MODULE))
777 + return &npe_tab[id];
781 +void npe_release(struct npe *npe)
783 + module_put(THIS_MODULE);
787 +static int __init npe_init_module(void)
792 + for (i = 0; i < NPE_COUNT; i++) {
793 + struct npe *npe = &npe_tab[i];
794 + if (!(ixp4xx_read_feature_bits() &
795 + (IXP4XX_FEATURE_RESET_NPEA << i)))
796 + continue; /* NPE already disabled or not present */
797 + if (!(npe->mem_res = request_mem_region(npe->regs_phys,
800 + print_npe(KERN_ERR, npe,
801 + "failed to request memory region\n");
805 + if (npe_reset(npe))
816 +static void __exit npe_cleanup_module(void)
820 + for (i = 0; i < NPE_COUNT; i++)
821 + if (npe_tab[i].mem_res) {
822 + npe_reset(&npe_tab[i]);
823 + release_resource(npe_tab[i].mem_res);
827 +module_init(npe_init_module);
828 +module_exit(npe_cleanup_module);
830 +MODULE_AUTHOR("Krzysztof Halasa");
831 +MODULE_LICENSE("GPL v2");
833 +EXPORT_SYMBOL(npe_names);
834 +EXPORT_SYMBOL(npe_running);
835 +EXPORT_SYMBOL(npe_request);
836 +EXPORT_SYMBOL(npe_release);
837 +EXPORT_SYMBOL(npe_load_firmware);
838 +EXPORT_SYMBOL(npe_send_message);
839 +EXPORT_SYMBOL(npe_recv_message);
840 +EXPORT_SYMBOL(npe_send_recv_message);
841 Index: linux-2.6.23.17/arch/arm/mach-ixp4xx/ixp4xx_qmgr.c
842 ===================================================================
844 +++ linux-2.6.23.17/arch/arm/mach-ixp4xx/ixp4xx_qmgr.c
847 + * Intel IXP4xx Queue Manager driver for Linux
849 + * Copyright (C) 2007 Krzysztof Halasa <khc@pm.waw.pl>
851 + * This program is free software; you can redistribute it and/or modify it
852 + * under the terms of version 2 of the GNU General Public License
853 + * as published by the Free Software Foundation.
856 +#include <linux/ioport.h>
857 +#include <linux/interrupt.h>
858 +#include <linux/kernel.h>
859 +#include <linux/module.h>
860 +#include <asm/arch/qmgr.h>
864 +struct qmgr_regs __iomem *qmgr_regs;
865 +static struct resource *mem_res;
866 +static spinlock_t qmgr_lock;
867 +static u32 used_sram_bitmap[4]; /* 128 16-dword pages */
868 +static void (*irq_handlers[HALF_QUEUES])(void *pdev);
869 +static void *irq_pdevs[HALF_QUEUES];
871 +void qmgr_set_irq(unsigned int queue, int src,
872 + void (*handler)(void *pdev), void *pdev)
874 + u32 __iomem *reg = &qmgr_regs->irqsrc[queue / 8]; /* 8 queues / u32 */
875 + int bit = (queue % 8) * 4; /* 3 bits + 1 reserved bit per queue */
876 + unsigned long flags;
879 + spin_lock_irqsave(&qmgr_lock, flags);
880 + __raw_writel((__raw_readl(reg) & ~(7 << bit)) | (src << bit), reg);
881 + irq_handlers[queue] = handler;
882 + irq_pdevs[queue] = pdev;
883 + spin_unlock_irqrestore(&qmgr_lock, flags);
887 +static irqreturn_t qmgr_irq1(int irq, void *pdev)
890 + u32 val = __raw_readl(&qmgr_regs->irqstat[0]);
891 + __raw_writel(val, &qmgr_regs->irqstat[0]); /* ACK */
893 + for (i = 0; i < HALF_QUEUES; i++)
894 + if (val & (1 << i))
895 + irq_handlers[i](irq_pdevs[i]);
897 + return val ? IRQ_HANDLED : 0;
901 +void qmgr_enable_irq(unsigned int queue)
903 + unsigned long flags;
905 + spin_lock_irqsave(&qmgr_lock, flags);
906 + __raw_writel(__raw_readl(&qmgr_regs->irqen[0]) | (1 << queue),
907 + &qmgr_regs->irqen[0]);
908 + spin_unlock_irqrestore(&qmgr_lock, flags);
911 +void qmgr_disable_irq(unsigned int queue)
913 + unsigned long flags;
915 + spin_lock_irqsave(&qmgr_lock, flags);
916 + __raw_writel(__raw_readl(&qmgr_regs->irqen[0]) & ~(1 << queue),
917 + &qmgr_regs->irqen[0]);
918 + spin_unlock_irqrestore(&qmgr_lock, flags);
921 +static inline void shift_mask(u32 *mask)
923 + mask[3] = mask[3] << 1 | mask[2] >> 31;
924 + mask[2] = mask[2] << 1 | mask[1] >> 31;
925 + mask[1] = mask[1] << 1 | mask[0] >> 31;
929 +int qmgr_request_queue(unsigned int queue, unsigned int len /* dwords */,
930 + unsigned int nearly_empty_watermark,
931 + unsigned int nearly_full_watermark)
933 + u32 cfg, addr = 0, mask[4]; /* in 16-dwords */
936 + if (queue >= HALF_QUEUES)
939 + if ((nearly_empty_watermark | nearly_full_watermark) & ~7)
963 + cfg |= nearly_empty_watermark << 26;
964 + cfg |= nearly_full_watermark << 29;
965 + len /= 16; /* in 16-dwords: 1, 2, 4 or 8 */
966 + mask[1] = mask[2] = mask[3] = 0;
968 + if (!try_module_get(THIS_MODULE))
971 + spin_lock_irq(&qmgr_lock);
972 + if (__raw_readl(&qmgr_regs->sram[queue])) {
978 + if (!(used_sram_bitmap[0] & mask[0]) &&
979 + !(used_sram_bitmap[1] & mask[1]) &&
980 + !(used_sram_bitmap[2] & mask[2]) &&
981 + !(used_sram_bitmap[3] & mask[3]))
982 + break; /* found free space */
986 + if (addr + len > ARRAY_SIZE(qmgr_regs->sram)) {
987 + printk(KERN_ERR "qmgr: no free SRAM space for"
988 + " queue %i\n", queue);
994 + used_sram_bitmap[0] |= mask[0];
995 + used_sram_bitmap[1] |= mask[1];
996 + used_sram_bitmap[2] |= mask[2];
997 + used_sram_bitmap[3] |= mask[3];
998 + __raw_writel(cfg | (addr << 14), &qmgr_regs->sram[queue]);
999 + spin_unlock_irq(&qmgr_lock);
1002 + printk(KERN_DEBUG "qmgr: requested queue %i, addr = 0x%02X\n",
1008 + spin_unlock_irq(&qmgr_lock);
1009 + module_put(THIS_MODULE);
1013 +void qmgr_release_queue(unsigned int queue)
1015 + u32 cfg, addr, mask[4];
1017 + BUG_ON(queue >= HALF_QUEUES); /* not in valid range */
1019 + spin_lock_irq(&qmgr_lock);
1020 + cfg = __raw_readl(&qmgr_regs->sram[queue]);
1021 + addr = (cfg >> 14) & 0xFF;
1023 + BUG_ON(!addr); /* not requested */
1025 + switch ((cfg >> 24) & 3) {
1026 + case 0: mask[0] = 0x1; break;
1027 + case 1: mask[0] = 0x3; break;
1028 + case 2: mask[0] = 0xF; break;
1029 + case 3: mask[0] = 0xFF; break;
1035 + __raw_writel(0, &qmgr_regs->sram[queue]);
1037 + used_sram_bitmap[0] &= ~mask[0];
1038 + used_sram_bitmap[1] &= ~mask[1];
1039 + used_sram_bitmap[2] &= ~mask[2];
1040 + used_sram_bitmap[3] &= ~mask[3];
1041 + irq_handlers[queue] = NULL; /* catch IRQ bugs */
1042 + spin_unlock_irq(&qmgr_lock);
1044 + module_put(THIS_MODULE);
1046 + printk(KERN_DEBUG "qmgr: released queue %i\n", queue);
1050 +static int qmgr_init(void)
1053 + mem_res = request_mem_region(IXP4XX_QMGR_BASE_PHYS,
1054 + IXP4XX_QMGR_REGION_SIZE,
1055 + "IXP4xx Queue Manager");
1056 + if (mem_res == NULL)
1059 + qmgr_regs = ioremap(IXP4XX_QMGR_BASE_PHYS, IXP4XX_QMGR_REGION_SIZE);
1060 + if (qmgr_regs == NULL) {
1065 + /* reset qmgr registers */
1066 + for (i = 0; i < 4; i++) {
1067 + __raw_writel(0x33333333, &qmgr_regs->stat1[i]);
1068 + __raw_writel(0, &qmgr_regs->irqsrc[i]);
1070 + for (i = 0; i < 2; i++) {
1071 + __raw_writel(0, &qmgr_regs->stat2[i]);
1072 + __raw_writel(0xFFFFFFFF, &qmgr_regs->irqstat[i]); /* clear */
1073 + __raw_writel(0, &qmgr_regs->irqen[i]);
1076 + for (i = 0; i < QUEUES; i++)
1077 + __raw_writel(0, &qmgr_regs->sram[i]);
1079 + err = request_irq(IRQ_IXP4XX_QM1, qmgr_irq1, 0,
1080 + "IXP4xx Queue Manager", NULL);
1082 + printk(KERN_ERR "qmgr: failed to request IRQ%i\n",
1087 + used_sram_bitmap[0] = 0xF; /* 4 first pages reserved for config */
1088 + spin_lock_init(&qmgr_lock);
1090 + printk(KERN_INFO "IXP4xx Queue Manager initialized.\n");
1094 + iounmap(qmgr_regs);
1096 + release_mem_region(IXP4XX_QMGR_BASE_PHYS, IXP4XX_QMGR_REGION_SIZE);
1100 +static void qmgr_remove(void)
1102 + free_irq(IRQ_IXP4XX_QM1, NULL);
1103 + synchronize_irq(IRQ_IXP4XX_QM1);
1104 + iounmap(qmgr_regs);
1105 + release_mem_region(IXP4XX_QMGR_BASE_PHYS, IXP4XX_QMGR_REGION_SIZE);
1108 +module_init(qmgr_init);
1109 +module_exit(qmgr_remove);
1111 +MODULE_LICENSE("GPL v2");
1112 +MODULE_AUTHOR("Krzysztof Halasa");
1114 +EXPORT_SYMBOL(qmgr_regs);
1115 +EXPORT_SYMBOL(qmgr_set_irq);
1116 +EXPORT_SYMBOL(qmgr_enable_irq);
1117 +EXPORT_SYMBOL(qmgr_disable_irq);
1118 +EXPORT_SYMBOL(qmgr_request_queue);
1119 +EXPORT_SYMBOL(qmgr_release_queue);
1120 Index: linux-2.6.23.17/drivers/net/arm/Kconfig
1121 ===================================================================
1122 --- linux-2.6.23.17.orig/drivers/net/arm/Kconfig
1123 +++ linux-2.6.23.17/drivers/net/arm/Kconfig
1124 @@ -47,3 +47,13 @@ config EP93XX_ETH
1126 This is a driver for the ethernet hardware included in EP93xx CPUs.
1127 Say Y if you are building a kernel for EP93xx based devices.
1130 + tristate "IXP4xx Ethernet support"
1131 + depends on NET_ETHERNET && ARM && ARCH_IXP4XX
1133 + select IXP4XX_QMGR
1136 + Say Y here if you want to use built-in Ethernet ports
1137 + on IXP4xx processor.
1138 Index: linux-2.6.23.17/drivers/net/arm/Makefile
1139 ===================================================================
1140 --- linux-2.6.23.17.orig/drivers/net/arm/Makefile
1141 +++ linux-2.6.23.17/drivers/net/arm/Makefile
1142 @@ -9,3 +9,4 @@ obj-$(CONFIG_ARM_ETHER3) += ether3.o
1143 obj-$(CONFIG_ARM_ETHER1) += ether1.o
1144 obj-$(CONFIG_ARM_AT91_ETHER) += at91_ether.o
1145 obj-$(CONFIG_EP93XX_ETH) += ep93xx_eth.o
1146 +obj-$(CONFIG_IXP4XX_ETH) += ixp4xx_eth.o
1147 Index: linux-2.6.23.17/drivers/net/arm/ixp4xx_eth.c
1148 ===================================================================
1150 +++ linux-2.6.23.17/drivers/net/arm/ixp4xx_eth.c
1153 + * Intel IXP4xx Ethernet driver for Linux
1155 + * Copyright (C) 2007 Krzysztof Halasa <khc@pm.waw.pl>
1157 + * This program is free software; you can redistribute it and/or modify it
1158 + * under the terms of version 2 of the GNU General Public License
1159 + * as published by the Free Software Foundation.
1161 + * Ethernet port config (0x00 is not present on IXP42X):
1163 + * logical port 0x00 0x10 0x20
1164 + * NPE 0 (NPE-A) 1 (NPE-B) 2 (NPE-C)
1165 + * physical PortId 2 0 1
1166 + * TX queue 23 24 25
1167 + * RX-free queue 26 27 28
1168 + * TX-done queue is always 31, per-port RX and TX-ready queues are configurable
1172 + * bits 0 -> 1 - NPE ID (RX and TX-done)
1173 + * bits 0 -> 2 - priority (TX, per 802.1D)
1174 + * bits 3 -> 4 - port ID (user-set?)
1175 + * bits 5 -> 31 - physical descriptor address
1178 +#include <linux/delay.h>
1179 +#include <linux/dma-mapping.h>
1180 +#include <linux/dmapool.h>
1181 +#include <linux/etherdevice.h>
1182 +#include <linux/io.h>
1183 +#include <linux/kernel.h>
1184 +#include <linux/mii.h>
1185 +#include <linux/platform_device.h>
1186 +#include <asm/arch/npe.h>
1187 +#include <asm/arch/qmgr.h>
1189 +#define DEBUG_QUEUES 0
1190 +#define DEBUG_DESC 0
1193 +#define DEBUG_PKT_BYTES 0
1194 +#define DEBUG_MDIO 0
1195 +#define DEBUG_CLOSE 0
1197 +#define DRV_NAME "ixp4xx_eth"
1201 +#define RX_DESCS 64 /* also length of all RX queues */
1202 +#define TX_DESCS 16 /* also length of all TX queues */
1203 +#define TXDONE_QUEUE_LEN 64 /* dwords */
1205 +#define POOL_ALLOC_SIZE (sizeof(struct desc) * (RX_DESCS + TX_DESCS))
1206 +#define REGS_SIZE 0x1000
1207 +#define MAX_MRU 1536 /* 0x600 */
1209 +#define MDIO_INTERVAL (3 * HZ)
1210 +#define MAX_MDIO_RETRIES 100 /* microseconds, typically 30 cycles */
1211 +#define MAX_MII_RESET_RETRIES 100 /* mdio_read() cycles, typically 4 */
1212 +#define MAX_CLOSE_WAIT 1000 /* microseconds, typically 2-3 cycles */
1214 +#define NPE_ID(port_id) ((port_id) >> 4)
1215 +#define PHYSICAL_ID(port_id) ((NPE_ID(port_id) + 2) % 3)
1216 +#define TX_QUEUE(port_id) (NPE_ID(port_id) + 23)
1217 +#define RXFREE_QUEUE(port_id) (NPE_ID(port_id) + 26)
1218 +#define TXDONE_QUEUE 31
1220 +/* TX Control Registers */
1221 +#define TX_CNTRL0_TX_EN 0x01
1222 +#define TX_CNTRL0_HALFDUPLEX 0x02
1223 +#define TX_CNTRL0_RETRY 0x04
1224 +#define TX_CNTRL0_PAD_EN 0x08
1225 +#define TX_CNTRL0_APPEND_FCS 0x10
1226 +#define TX_CNTRL0_2DEFER 0x20
1227 +#define TX_CNTRL0_RMII 0x40 /* reduced MII */
1228 +#define TX_CNTRL1_RETRIES 0x0F /* 4 bits */
1230 +/* RX Control Registers */
1231 +#define RX_CNTRL0_RX_EN 0x01
1232 +#define RX_CNTRL0_PADSTRIP_EN 0x02
1233 +#define RX_CNTRL0_SEND_FCS 0x04
1234 +#define RX_CNTRL0_PAUSE_EN 0x08
1235 +#define RX_CNTRL0_LOOP_EN 0x10
1236 +#define RX_CNTRL0_ADDR_FLTR_EN 0x20
1237 +#define RX_CNTRL0_RX_RUNT_EN 0x40
1238 +#define RX_CNTRL0_BCAST_DIS 0x80
1239 +#define RX_CNTRL1_DEFER_EN 0x01
1241 +/* Core Control Register */
1242 +#define CORE_RESET 0x01
1243 +#define CORE_RX_FIFO_FLUSH 0x02
1244 +#define CORE_TX_FIFO_FLUSH 0x04
1245 +#define CORE_SEND_JAM 0x08
1246 +#define CORE_MDC_EN 0x10 /* MDIO using NPE-B ETH-0 only */
1248 +#define DEFAULT_TX_CNTRL0 (TX_CNTRL0_TX_EN | TX_CNTRL0_RETRY | \
1249 + TX_CNTRL0_PAD_EN | TX_CNTRL0_APPEND_FCS | \
1251 +#define DEFAULT_RX_CNTRL0 RX_CNTRL0_RX_EN
1252 +#define DEFAULT_CORE_CNTRL CORE_MDC_EN
1255 +/* NPE message codes */
1256 +#define NPE_GETSTATUS 0x00
1257 +#define NPE_EDB_SETPORTADDRESS 0x01
1258 +#define NPE_EDB_GETMACADDRESSDATABASE 0x02
1259 +#define NPE_EDB_SETMACADDRESSSDATABASE 0x03
1260 +#define NPE_GETSTATS 0x04
1261 +#define NPE_RESETSTATS 0x05
1262 +#define NPE_SETMAXFRAMELENGTHS 0x06
1263 +#define NPE_VLAN_SETRXTAGMODE 0x07
1264 +#define NPE_VLAN_SETDEFAULTRXVID 0x08
1265 +#define NPE_VLAN_SETPORTVLANTABLEENTRY 0x09
1266 +#define NPE_VLAN_SETPORTVLANTABLERANGE 0x0A
1267 +#define NPE_VLAN_SETRXQOSENTRY 0x0B
1268 +#define NPE_VLAN_SETPORTIDEXTRACTIONMODE 0x0C
1269 +#define NPE_STP_SETBLOCKINGSTATE 0x0D
1270 +#define NPE_FW_SETFIREWALLMODE 0x0E
1271 +#define NPE_PC_SETFRAMECONTROLDURATIONID 0x0F
1272 +#define NPE_PC_SETAPMACTABLE 0x11
1273 +#define NPE_SETLOOPBACK_MODE 0x12
1274 +#define NPE_PC_SETBSSIDTABLE 0x13
1275 +#define NPE_ADDRESS_FILTER_CONFIG 0x14
1276 +#define NPE_APPENDFCSCONFIG 0x15
1277 +#define NPE_NOTIFY_MAC_RECOVERY_DONE 0x16
1278 +#define NPE_MAC_RECOVERY_START 0x17
1282 +typedef struct sk_buff buffer_t;
1283 +#define free_buffer dev_kfree_skb
1284 +#define free_buffer_irq dev_kfree_skb_irq
1286 +typedef void buffer_t;
1287 +#define free_buffer kfree
1288 +#define free_buffer_irq kfree
1292 + u32 tx_control[2], __res1[2]; /* 000 */
1293 + u32 rx_control[2], __res2[2]; /* 010 */
1294 + u32 random_seed, __res3[3]; /* 020 */
1295 + u32 partial_empty_threshold, __res4; /* 030 */
1296 + u32 partial_full_threshold, __res5; /* 038 */
1297 + u32 tx_start_bytes, __res6[3]; /* 040 */
1298 + u32 tx_deferral, rx_deferral,__res7[2]; /* 050 */
1299 + u32 tx_2part_deferral[2], __res8[2]; /* 060 */
1300 + u32 slot_time, __res9[3]; /* 070 */
1301 + u32 mdio_command[4]; /* 080 */
1302 + u32 mdio_status[4]; /* 090 */
1303 + u32 mcast_mask[6], __res10[2]; /* 0A0 */
1304 + u32 mcast_addr[6], __res11[2]; /* 0C0 */
1305 + u32 int_clock_threshold, __res12[3]; /* 0E0 */
1306 + u32 hw_addr[6], __res13[61]; /* 0F0 */
1307 + u32 core_control; /* 1FC */
1311 + struct resource *mem_res;
1312 + struct eth_regs __iomem *regs;
1314 + struct net_device *netdev;
1315 + struct net_device_stats stat;
1316 + struct mii_if_info mii;
1317 + struct delayed_work mdio_thread;
1318 + struct eth_plat_info *plat;
1319 + buffer_t *rx_buff_tab[RX_DESCS], *tx_buff_tab[TX_DESCS];
1320 + struct desc *desc_tab; /* coherent */
1321 + u32 desc_tab_phys;
1322 + int id; /* logical port ID */
1326 +/* NPE message structure */
1329 + u8 cmd, eth_id, byte2, byte3;
1330 + u8 byte4, byte5, byte6, byte7;
1332 + u8 byte3, byte2, eth_id, cmd;
1333 + u8 byte7, byte6, byte5, byte4;
1337 +/* Ethernet packet descriptor */
1339 + u32 next; /* pointer to next buffer, unused */
1342 + u16 buf_len; /* buffer length */
1343 + u16 pkt_len; /* packet length */
1344 + u32 data; /* pointer to data buffer in RAM */
1352 + u16 pkt_len; /* packet length */
1353 + u16 buf_len; /* buffer length */
1354 + u32 data; /* pointer to data buffer in RAM */
1364 + u8 dst_mac_0, dst_mac_1, dst_mac_2, dst_mac_3;
1365 + u8 dst_mac_4, dst_mac_5, src_mac_0, src_mac_1;
1366 + u8 src_mac_2, src_mac_3, src_mac_4, src_mac_5;
1368 + u8 dst_mac_3, dst_mac_2, dst_mac_1, dst_mac_0;
1369 + u8 src_mac_1, src_mac_0, dst_mac_5, dst_mac_4;
1370 + u8 src_mac_5, src_mac_4, src_mac_3, src_mac_2;
1375 +#define rx_desc_phys(port, n) ((port)->desc_tab_phys + \
1376 + (n) * sizeof(struct desc))
1377 +#define rx_desc_ptr(port, n) (&(port)->desc_tab[n])
1379 +#define tx_desc_phys(port, n) ((port)->desc_tab_phys + \
1380 + ((n) + RX_DESCS) * sizeof(struct desc))
1381 +#define tx_desc_ptr(port, n) (&(port)->desc_tab[(n) + RX_DESCS])
1384 +static inline void memcpy_swab32(u32 *dest, u32 *src, int cnt)
1387 + for (i = 0; i < cnt; i++)
1388 + dest[i] = swab32(src[i]);
1392 +static spinlock_t mdio_lock;
1393 +static struct eth_regs __iomem *mdio_regs; /* mdio command and status only */
1394 +static int ports_open;
1395 +static struct port *npe_port_tab[MAX_NPES];
1396 +static struct dma_pool *dma_pool;
1399 +static u16 mdio_cmd(struct net_device *dev, int phy_id, int location,
1400 + int write, u16 cmd)
1404 + if (__raw_readl(&mdio_regs->mdio_command[3]) & 0x80) {
1405 + printk(KERN_ERR "%s: MII not ready to transmit\n", dev->name);
1410 + __raw_writel(cmd & 0xFF, &mdio_regs->mdio_command[0]);
1411 + __raw_writel(cmd >> 8, &mdio_regs->mdio_command[1]);
1413 + __raw_writel(((phy_id << 5) | location) & 0xFF,
1414 + &mdio_regs->mdio_command[2]);
1415 + __raw_writel((phy_id >> 3) | (write << 2) | 0x80 /* GO */,
1416 + &mdio_regs->mdio_command[3]);
1418 + while ((cycles < MAX_MDIO_RETRIES) &&
1419 + (__raw_readl(&mdio_regs->mdio_command[3]) & 0x80)) {
1424 + if (cycles == MAX_MDIO_RETRIES) {
1425 + printk(KERN_ERR "%s: MII write failed\n", dev->name);
1430 + printk(KERN_DEBUG "%s: mdio_cmd() took %i cycles\n", dev->name,
1437 + if (__raw_readl(&mdio_regs->mdio_status[3]) & 0x80) {
1438 + printk(KERN_ERR "%s: MII read failed\n", dev->name);
1442 + return (__raw_readl(&mdio_regs->mdio_status[0]) & 0xFF) |
1443 + (__raw_readl(&mdio_regs->mdio_status[1]) << 8);
1446 +static int mdio_read(struct net_device *dev, int phy_id, int location)
1448 + unsigned long flags;
1451 + spin_lock_irqsave(&mdio_lock, flags);
1452 + val = mdio_cmd(dev, phy_id, location, 0, 0);
1453 + spin_unlock_irqrestore(&mdio_lock, flags);
1457 +static void mdio_write(struct net_device *dev, int phy_id, int location,
1460 + unsigned long flags;
1462 + spin_lock_irqsave(&mdio_lock, flags);
1463 + mdio_cmd(dev, phy_id, location, 1, val);
1464 + spin_unlock_irqrestore(&mdio_lock, flags);
1467 +static void phy_reset(struct net_device *dev, int phy_id)
1469 + struct port *port = netdev_priv(dev);
1472 + mdio_write(dev, phy_id, MII_BMCR, port->mii_bmcr | BMCR_RESET);
1474 + while (cycles < MAX_MII_RESET_RETRIES) {
1475 + if (!(mdio_read(dev, phy_id, MII_BMCR) & BMCR_RESET)) {
1477 + printk(KERN_DEBUG "%s: phy_reset() took %i cycles\n",
1478 + dev->name, cycles);
1486 + printk(KERN_ERR "%s: MII reset failed\n", dev->name);
1489 +static void eth_set_duplex(struct port *port)
1491 + if (port->mii.full_duplex)
1492 + __raw_writel(DEFAULT_TX_CNTRL0 & ~TX_CNTRL0_HALFDUPLEX,
1493 + &port->regs->tx_control[0]);
1495 + __raw_writel(DEFAULT_TX_CNTRL0 | TX_CNTRL0_HALFDUPLEX,
1496 + &port->regs->tx_control[0]);
1500 +static void phy_check_media(struct port *port, int init)
1502 + if (mii_check_media(&port->mii, 1, init))
1503 + eth_set_duplex(port);
1504 + if (port->mii.force_media) { /* mii_check_media() doesn't work */
1505 + struct net_device *dev = port->netdev;
1506 + int cur_link = mii_link_ok(&port->mii);
1507 + int prev_link = netif_carrier_ok(dev);
1509 + if (!prev_link && cur_link) {
1510 + printk(KERN_INFO "%s: link up\n", dev->name);
1511 + netif_carrier_on(dev);
1512 + } else if (prev_link && !cur_link) {
1513 + printk(KERN_INFO "%s: link down\n", dev->name);
1514 + netif_carrier_off(dev);
1520 +static void mdio_thread(struct work_struct *work)
1522 + struct port *port = container_of(work, struct port, mdio_thread.work);
1524 + phy_check_media(port, 0);
1525 + schedule_delayed_work(&port->mdio_thread, MDIO_INTERVAL);
1529 +static inline void debug_pkt(struct net_device *dev, const char *func,
1530 + u8 *data, int len)
1532 +#if DEBUG_PKT_BYTES
1535 + printk(KERN_DEBUG "%s: %s(%i) ", dev->name, func, len);
1536 + for (i = 0; i < len; i++) {
1537 + if (i >= DEBUG_PKT_BYTES)
1540 + ((i == 6) || (i == 12) || (i >= 14)) ? " " : "",
1548 +static inline void debug_desc(u32 phys, struct desc *desc)
1551 + printk(KERN_DEBUG "%X: %X %3X %3X %08X %2X < %2X %4X %X"
1552 + " %X %X %02X%02X%02X%02X%02X%02X < %02X%02X%02X%02X%02X%02X\n",
1553 + phys, desc->next, desc->buf_len, desc->pkt_len,
1554 + desc->data, desc->dest_id, desc->src_id, desc->flags,
1555 + desc->qos, desc->padlen, desc->vlan_tci,
1556 + desc->dst_mac_0, desc->dst_mac_1, desc->dst_mac_2,
1557 + desc->dst_mac_3, desc->dst_mac_4, desc->dst_mac_5,
1558 + desc->src_mac_0, desc->src_mac_1, desc->src_mac_2,
1559 + desc->src_mac_3, desc->src_mac_4, desc->src_mac_5);
1563 +static inline void debug_queue(unsigned int queue, int is_get, u32 phys)
1570 + { TX_QUEUE(0x10), "TX#0 " },
1571 + { TX_QUEUE(0x20), "TX#1 " },
1572 + { TX_QUEUE(0x00), "TX#2 " },
1573 + { RXFREE_QUEUE(0x10), "RX-free#0 " },
1574 + { RXFREE_QUEUE(0x20), "RX-free#1 " },
1575 + { RXFREE_QUEUE(0x00), "RX-free#2 " },
1576 + { TXDONE_QUEUE, "TX-done " },
1580 + for (i = 0; i < ARRAY_SIZE(names); i++)
1581 + if (names[i].queue == queue)
1584 + printk(KERN_DEBUG "Queue %i %s%s %X\n", queue,
1585 + i < ARRAY_SIZE(names) ? names[i].name : "",
1586 + is_get ? "->" : "<-", phys);
1590 +static inline u32 queue_get_entry(unsigned int queue)
1592 + u32 phys = qmgr_get_entry(queue);
1593 + debug_queue(queue, 1, phys);
1597 +static inline int queue_get_desc(unsigned int queue, struct port *port,
1600 + u32 phys, tab_phys, n_desc;
1603 + if (!(phys = queue_get_entry(queue)))
1606 + phys &= ~0x1F; /* mask out non-address bits */
1607 + tab_phys = is_tx ? tx_desc_phys(port, 0) : rx_desc_phys(port, 0);
1608 + tab = is_tx ? tx_desc_ptr(port, 0) : rx_desc_ptr(port, 0);
1609 + n_desc = (phys - tab_phys) / sizeof(struct desc);
1610 + BUG_ON(n_desc >= (is_tx ? TX_DESCS : RX_DESCS));
1611 + debug_desc(phys, &tab[n_desc]);
1612 + BUG_ON(tab[n_desc].next);
1616 +static inline void queue_put_desc(unsigned int queue, u32 phys,
1617 + struct desc *desc)
1619 + debug_queue(queue, 0, phys);
1620 + debug_desc(phys, desc);
1621 + BUG_ON(phys & 0x1F);
1622 + qmgr_put_entry(queue, phys);
1623 + BUG_ON(qmgr_stat_overflow(queue));
1627 +static inline void dma_unmap_tx(struct port *port, struct desc *desc)
1630 + dma_unmap_single(&port->netdev->dev, desc->data,
1631 + desc->buf_len, DMA_TO_DEVICE);
1633 + dma_unmap_single(&port->netdev->dev, desc->data & ~3,
1634 + ALIGN((desc->data & 3) + desc->buf_len, 4),
1640 +static void eth_rx_irq(void *pdev)
1642 + struct net_device *dev = pdev;
1643 + struct port *port = netdev_priv(dev);
1646 + printk(KERN_DEBUG "%s: eth_rx_irq\n", dev->name);
1648 + qmgr_disable_irq(port->plat->rxq);
1649 + netif_rx_schedule(dev);
1652 +static int eth_poll(struct net_device *dev, int *budget)
1654 + struct port *port = netdev_priv(dev);
1655 + unsigned int rxq = port->plat->rxq, rxfreeq = RXFREE_QUEUE(port->id);
1656 + int quota = dev->quota, received = 0;
1659 + printk(KERN_DEBUG "%s: eth_poll\n", dev->name);
1663 + struct sk_buff *skb;
1664 + struct desc *desc;
1667 + struct sk_buff *temp;
1671 + if ((n = queue_get_desc(rxq, port, 0)) < 0) {
1672 + dev->quota -= received; /* No packet received */
1673 + *budget -= received;
1676 + printk(KERN_DEBUG "%s: eth_poll netif_rx_complete\n",
1679 + netif_rx_complete(dev);
1680 + qmgr_enable_irq(rxq);
1681 + if (!qmgr_stat_empty(rxq) &&
1682 + netif_rx_reschedule(dev, 0)) {
1684 + printk(KERN_DEBUG "%s: eth_poll"
1685 + " netif_rx_reschedule successed\n",
1688 + qmgr_disable_irq(rxq);
1692 + printk(KERN_DEBUG "%s: eth_poll all done\n",
1695 + return 0; /* all work done */
1698 + desc = rx_desc_ptr(port, n);
1701 + if ((skb = netdev_alloc_skb(dev, MAX_MRU)) != NULL) {
1702 + phys = dma_map_single(&dev->dev, skb->data,
1703 + MAX_MRU, DMA_FROM_DEVICE);
1704 + if (dma_mapping_error(phys)) {
1705 + dev_kfree_skb(skb);
1710 + skb = netdev_alloc_skb(dev, desc->pkt_len);
1714 + port->stat.rx_dropped++;
1715 + /* put the desc back on RX-ready queue */
1716 + desc->buf_len = MAX_MRU;
1717 + desc->pkt_len = 0;
1718 + queue_put_desc(rxfreeq, rx_desc_phys(port, n), desc);
1722 + /* process received frame */
1725 + skb = port->rx_buff_tab[n];
1726 + dma_unmap_single(&dev->dev, desc->data,
1727 + MAX_MRU, DMA_FROM_DEVICE);
1729 + dma_sync_single(&dev->dev, desc->data,
1730 + MAX_MRU, DMA_FROM_DEVICE);
1731 + memcpy_swab32((u32 *)skb->data, (u32 *)port->rx_buff_tab[n],
1732 + ALIGN(desc->pkt_len, 4) / 4);
1734 + skb_put(skb, desc->pkt_len);
1736 + debug_pkt(dev, "eth_poll", skb->data, skb->len);
1738 + skb->protocol = eth_type_trans(skb, dev);
1739 + dev->last_rx = jiffies;
1740 + port->stat.rx_packets++;
1741 + port->stat.rx_bytes += skb->len;
1742 + netif_receive_skb(skb);
1744 + /* put the new buffer on RX-free queue */
1746 + port->rx_buff_tab[n] = temp;
1747 + desc->data = phys;
1749 + desc->buf_len = MAX_MRU;
1750 + desc->pkt_len = 0;
1751 + queue_put_desc(rxfreeq, rx_desc_phys(port, n), desc);
1755 + dev->quota -= received;
1756 + *budget -= received;
1758 + printk(KERN_DEBUG "eth_poll(): end, not all work done\n");
1760 + return 1; /* not all work done */
1764 +static void eth_txdone_irq(void *unused)
1769 + printk(KERN_DEBUG DRV_NAME ": eth_txdone_irq\n");
1771 + while ((phys = queue_get_entry(TXDONE_QUEUE)) != 0) {
1772 + u32 npe_id, n_desc;
1773 + struct port *port;
1774 + struct desc *desc;
1777 + npe_id = phys & 3;
1778 + BUG_ON(npe_id >= MAX_NPES);
1779 + port = npe_port_tab[npe_id];
1781 + phys &= ~0x1F; /* mask out non-address bits */
1782 + n_desc = (phys - tx_desc_phys(port, 0)) / sizeof(struct desc);
1783 + BUG_ON(n_desc >= TX_DESCS);
1784 + desc = tx_desc_ptr(port, n_desc);
1785 + debug_desc(phys, desc);
1787 + if (port->tx_buff_tab[n_desc]) { /* not the draining packet */
1788 + port->stat.tx_packets++;
1789 + port->stat.tx_bytes += desc->pkt_len;
1791 + dma_unmap_tx(port, desc);
1793 + printk(KERN_DEBUG "%s: eth_txdone_irq free %p\n",
1794 + port->netdev->name, port->tx_buff_tab[n_desc]);
1796 + free_buffer_irq(port->tx_buff_tab[n_desc]);
1797 + port->tx_buff_tab[n_desc] = NULL;
1800 + start = qmgr_stat_empty(port->plat->txreadyq);
1801 + queue_put_desc(port->plat->txreadyq, phys, desc);
1804 + printk(KERN_DEBUG "%s: eth_txdone_irq xmit ready\n",
1805 + port->netdev->name);
1807 + netif_wake_queue(port->netdev);
1812 +static int eth_xmit(struct sk_buff *skb, struct net_device *dev)
1814 + struct port *port = netdev_priv(dev);
1815 + unsigned int txreadyq = port->plat->txreadyq;
1816 + int len, offset, bytes, n;
1819 + struct desc *desc;
1822 + printk(KERN_DEBUG "%s: eth_xmit\n", dev->name);
1825 + if (unlikely(skb->len > MAX_MRU)) {
1826 + dev_kfree_skb(skb);
1827 + port->stat.tx_errors++;
1828 + return NETDEV_TX_OK;
1831 + debug_pkt(dev, "eth_xmit", skb->data, skb->len);
1835 + offset = 0; /* no need to keep alignment */
1839 + offset = (int)skb->data & 3; /* keep 32-bit alignment */
1840 + bytes = ALIGN(offset + len, 4);
1841 + if (!(mem = kmalloc(bytes, GFP_ATOMIC))) {
1842 + dev_kfree_skb(skb);
1843 + port->stat.tx_dropped++;
1844 + return NETDEV_TX_OK;
1846 + memcpy_swab32(mem, (u32 *)((int)skb->data & ~3), bytes / 4);
1847 + dev_kfree_skb(skb);
1850 + phys = dma_map_single(&dev->dev, mem, bytes, DMA_TO_DEVICE);
1851 + if (dma_mapping_error(phys)) {
1853 + dev_kfree_skb(skb);
1857 + port->stat.tx_dropped++;
1858 + return NETDEV_TX_OK;
1861 + n = queue_get_desc(txreadyq, port, 1);
1863 + desc = tx_desc_ptr(port, n);
1866 + port->tx_buff_tab[n] = skb;
1868 + port->tx_buff_tab[n] = mem;
1870 + desc->data = phys + offset;
1871 + desc->buf_len = desc->pkt_len = len;
1873 + /* NPE firmware pads short frames with zeros internally */
1875 + queue_put_desc(TX_QUEUE(port->id), tx_desc_phys(port, n), desc);
1876 + dev->trans_start = jiffies;
1878 + if (qmgr_stat_empty(txreadyq)) {
1880 + printk(KERN_DEBUG "%s: eth_xmit queue full\n", dev->name);
1882 + netif_stop_queue(dev);
1883 + /* we could miss TX ready interrupt */
1884 + if (!qmgr_stat_empty(txreadyq)) {
1886 + printk(KERN_DEBUG "%s: eth_xmit ready again\n",
1889 + netif_wake_queue(dev);
1894 + printk(KERN_DEBUG "%s: eth_xmit end\n", dev->name);
1896 + return NETDEV_TX_OK;
1900 +static struct net_device_stats *eth_stats(struct net_device *dev)
1902 + struct port *port = netdev_priv(dev);
1903 + return &port->stat;
1906 +static void eth_set_mcast_list(struct net_device *dev)
1908 + struct port *port = netdev_priv(dev);
1909 + struct dev_mc_list *mclist = dev->mc_list;
1910 + u8 diffs[ETH_ALEN], *addr;
1911 + int cnt = dev->mc_count, i;
1913 + if ((dev->flags & IFF_PROMISC) || !mclist || !cnt) {
1914 + __raw_writel(DEFAULT_RX_CNTRL0 & ~RX_CNTRL0_ADDR_FLTR_EN,
1915 + &port->regs->rx_control[0]);
1919 + memset(diffs, 0, ETH_ALEN);
1920 + addr = mclist->dmi_addr; /* first MAC address */
1922 + while (--cnt && (mclist = mclist->next))
1923 + for (i = 0; i < ETH_ALEN; i++)
1924 + diffs[i] |= addr[i] ^ mclist->dmi_addr[i];
1926 + for (i = 0; i < ETH_ALEN; i++) {
1927 + __raw_writel(addr[i], &port->regs->mcast_addr[i]);
1928 + __raw_writel(~diffs[i], &port->regs->mcast_mask[i]);
1931 + __raw_writel(DEFAULT_RX_CNTRL0 | RX_CNTRL0_ADDR_FLTR_EN,
1932 + &port->regs->rx_control[0]);
1936 +static int eth_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
1938 + struct port *port = netdev_priv(dev);
1939 + unsigned int duplex_chg;
1942 + if (!netif_running(dev))
1944 + err = generic_mii_ioctl(&port->mii, if_mii(req), cmd, &duplex_chg);
1946 + eth_set_duplex(port);
1951 +static int request_queues(struct port *port)
1955 + err = qmgr_request_queue(RXFREE_QUEUE(port->id), RX_DESCS, 0, 0);
1959 + err = qmgr_request_queue(port->plat->rxq, RX_DESCS, 0, 0);
1963 + err = qmgr_request_queue(TX_QUEUE(port->id), TX_DESCS, 0, 0);
1967 + err = qmgr_request_queue(port->plat->txreadyq, TX_DESCS, 0, 0);
1971 + /* TX-done queue handles skbs sent out by the NPEs */
1972 + if (!ports_open) {
1973 + err = qmgr_request_queue(TXDONE_QUEUE, TXDONE_QUEUE_LEN, 0, 0);
1980 + qmgr_release_queue(port->plat->txreadyq);
1982 + qmgr_release_queue(TX_QUEUE(port->id));
1984 + qmgr_release_queue(port->plat->rxq);
1986 + qmgr_release_queue(RXFREE_QUEUE(port->id));
1987 + printk(KERN_DEBUG "%s: unable to request hardware queues\n",
1988 + port->netdev->name);
1992 +static void release_queues(struct port *port)
1994 + qmgr_release_queue(RXFREE_QUEUE(port->id));
1995 + qmgr_release_queue(port->plat->rxq);
1996 + qmgr_release_queue(TX_QUEUE(port->id));
1997 + qmgr_release_queue(port->plat->txreadyq);
2000 + qmgr_release_queue(TXDONE_QUEUE);
2003 +static int init_queues(struct port *port)
2008 + if (!(dma_pool = dma_pool_create(DRV_NAME, NULL,
2009 + POOL_ALLOC_SIZE, 32, 0)))
2012 + if (!(port->desc_tab = dma_pool_alloc(dma_pool, GFP_KERNEL,
2013 + &port->desc_tab_phys)))
2015 + memset(port->desc_tab, 0, POOL_ALLOC_SIZE);
2016 + memset(port->rx_buff_tab, 0, sizeof(port->rx_buff_tab)); /* tables */
2017 + memset(port->tx_buff_tab, 0, sizeof(port->tx_buff_tab));
2019 + /* Setup RX buffers */
2020 + for (i = 0; i < RX_DESCS; i++) {
2021 + struct desc *desc = rx_desc_ptr(port, i);
2025 + if (!(buff = netdev_alloc_skb(port->netdev, MAX_MRU)))
2027 + data = buff->data;
2029 + if (!(buff = kmalloc(MAX_MRU, GFP_KERNEL)))
2033 + desc->buf_len = MAX_MRU;
2034 + desc->data = dma_map_single(&port->netdev->dev, data,
2035 + MAX_MRU, DMA_FROM_DEVICE);
2036 + if (dma_mapping_error(desc->data)) {
2037 + free_buffer(buff);
2040 + port->rx_buff_tab[i] = buff;
2046 +static void destroy_queues(struct port *port)
2050 + if (port->desc_tab) {
2051 + for (i = 0; i < RX_DESCS; i++) {
2052 + struct desc *desc = rx_desc_ptr(port, i);
2053 + buffer_t *buff = port->rx_buff_tab[i];
2055 + dma_unmap_single(&port->netdev->dev,
2056 + desc->data, MAX_MRU,
2058 + free_buffer(buff);
2061 + for (i = 0; i < TX_DESCS; i++) {
2062 + struct desc *desc = tx_desc_ptr(port, i);
2063 + buffer_t *buff = port->tx_buff_tab[i];
2065 + dma_unmap_tx(port, desc);
2066 + free_buffer(buff);
2069 + dma_pool_free(dma_pool, port->desc_tab, port->desc_tab_phys);
2070 + port->desc_tab = NULL;
2073 + if (!ports_open && dma_pool) {
2074 + dma_pool_destroy(dma_pool);
2079 +static int eth_open(struct net_device *dev)
2081 + struct port *port = netdev_priv(dev);
2082 + struct npe *npe = port->npe;
2086 + if (!npe_running(npe)) {
2087 + err = npe_load_firmware(npe, npe_name(npe), &dev->dev);
2091 + if (npe_recv_message(npe, &msg, "ETH_GET_STATUS")) {
2092 + printk(KERN_ERR "%s: %s not responding\n", dev->name,
2098 + mdio_write(dev, port->plat->phy, MII_BMCR, port->mii_bmcr);
2100 + memset(&msg, 0, sizeof(msg));
2101 + msg.cmd = NPE_VLAN_SETRXQOSENTRY;
2102 + msg.eth_id = port->id;
2103 + msg.byte5 = port->plat->rxq | 0x80;
2104 + msg.byte7 = port->plat->rxq << 4;
2105 + for (i = 0; i < 8; i++) {
2107 + if (npe_send_recv_message(port->npe, &msg, "ETH_SET_RXQ"))
2111 + msg.cmd = NPE_EDB_SETPORTADDRESS;
2112 + msg.eth_id = PHYSICAL_ID(port->id);
2113 + msg.byte2 = dev->dev_addr[0];
2114 + msg.byte3 = dev->dev_addr[1];
2115 + msg.byte4 = dev->dev_addr[2];
2116 + msg.byte5 = dev->dev_addr[3];
2117 + msg.byte6 = dev->dev_addr[4];
2118 + msg.byte7 = dev->dev_addr[5];
2119 + if (npe_send_recv_message(port->npe, &msg, "ETH_SET_MAC"))
2122 + memset(&msg, 0, sizeof(msg));
2123 + msg.cmd = NPE_FW_SETFIREWALLMODE;
2124 + msg.eth_id = port->id;
2125 + if (npe_send_recv_message(port->npe, &msg, "ETH_SET_FIREWALL_MODE"))
2128 + if ((err = request_queues(port)) != 0)
2131 + if ((err = init_queues(port)) != 0) {
2132 + destroy_queues(port);
2133 + release_queues(port);
2137 + for (i = 0; i < ETH_ALEN; i++)
2138 + __raw_writel(dev->dev_addr[i], &port->regs->hw_addr[i]);
2139 + __raw_writel(0x08, &port->regs->random_seed);
2140 + __raw_writel(0x12, &port->regs->partial_empty_threshold);
2141 + __raw_writel(0x30, &port->regs->partial_full_threshold);
2142 + __raw_writel(0x08, &port->regs->tx_start_bytes);
2143 + __raw_writel(0x15, &port->regs->tx_deferral);
2144 + __raw_writel(0x08, &port->regs->tx_2part_deferral[0]);
2145 + __raw_writel(0x07, &port->regs->tx_2part_deferral[1]);
2146 + __raw_writel(0x80, &port->regs->slot_time);
2147 + __raw_writel(0x01, &port->regs->int_clock_threshold);
2149 + /* Populate queues with buffers, no failure after this point */
2150 + for (i = 0; i < TX_DESCS; i++)
2151 + queue_put_desc(port->plat->txreadyq,
2152 + tx_desc_phys(port, i), tx_desc_ptr(port, i));
2154 + for (i = 0; i < RX_DESCS; i++)
2155 + queue_put_desc(RXFREE_QUEUE(port->id),
2156 + rx_desc_phys(port, i), rx_desc_ptr(port, i));
2158 + __raw_writel(TX_CNTRL1_RETRIES, &port->regs->tx_control[1]);
2159 + __raw_writel(DEFAULT_TX_CNTRL0, &port->regs->tx_control[0]);
2160 + __raw_writel(0, &port->regs->rx_control[1]);
2161 + __raw_writel(DEFAULT_RX_CNTRL0, &port->regs->rx_control[0]);
2163 + phy_check_media(port, 1);
2164 + eth_set_mcast_list(dev);
2165 + netif_start_queue(dev);
2166 + schedule_delayed_work(&port->mdio_thread, MDIO_INTERVAL);
2168 + qmgr_set_irq(port->plat->rxq, QUEUE_IRQ_SRC_NOT_EMPTY,
2170 + if (!ports_open) {
2171 + qmgr_set_irq(TXDONE_QUEUE, QUEUE_IRQ_SRC_NOT_EMPTY,
2172 + eth_txdone_irq, NULL);
2173 + qmgr_enable_irq(TXDONE_QUEUE);
2176 + netif_rx_schedule(dev); /* we may already have RX data, enables IRQ */
2180 +static int eth_close(struct net_device *dev)
2182 + struct port *port = netdev_priv(dev);
2184 + int buffs = RX_DESCS; /* allocated RX buffers */
2188 + qmgr_disable_irq(port->plat->rxq);
2189 + netif_stop_queue(dev);
2191 + while (queue_get_desc(RXFREE_QUEUE(port->id), port, 0) >= 0)
2194 + memset(&msg, 0, sizeof(msg));
2195 + msg.cmd = NPE_SETLOOPBACK_MODE;
2196 + msg.eth_id = port->id;
2198 + if (npe_send_recv_message(port->npe, &msg, "ETH_ENABLE_LOOPBACK"))
2199 + printk(KERN_CRIT "%s: unable to enable loopback\n", dev->name);
2202 + do { /* drain RX buffers */
2203 + while (queue_get_desc(port->plat->rxq, port, 0) >= 0)
2207 + if (qmgr_stat_empty(TX_QUEUE(port->id))) {
2208 + /* we have to inject some packet */
2209 + struct desc *desc;
2211 + int n = queue_get_desc(port->plat->txreadyq, port, 1);
2213 + desc = tx_desc_ptr(port, n);
2214 + phys = tx_desc_phys(port, n);
2215 + desc->buf_len = desc->pkt_len = 1;
2217 + queue_put_desc(TX_QUEUE(port->id), phys, desc);
2220 + } while (++i < MAX_CLOSE_WAIT);
2223 + printk(KERN_CRIT "%s: unable to drain RX queue, %i buffer(s)"
2224 + " left in NPE\n", dev->name, buffs);
2227 + printk(KERN_DEBUG "Draining RX queue took %i cycles\n", i);
2231 + while (queue_get_desc(TX_QUEUE(port->id), port, 1) >= 0)
2232 + buffs--; /* cancel TX */
2236 + while (queue_get_desc(port->plat->txreadyq, port, 1) >= 0)
2240 + } while (++i < MAX_CLOSE_WAIT);
2243 + printk(KERN_CRIT "%s: unable to drain TX queue, %i buffer(s) "
2244 + "left in NPE\n", dev->name, buffs);
2247 + printk(KERN_DEBUG "Draining TX queues took %i cycles\n", i);
2251 + if (npe_send_recv_message(port->npe, &msg, "ETH_DISABLE_LOOPBACK"))
2252 + printk(KERN_CRIT "%s: unable to disable loopback\n",
2255 + port->mii_bmcr = mdio_read(dev, port->plat->phy, MII_BMCR) &
2256 + ~(BMCR_RESET | BMCR_PDOWN); /* may have been altered */
2257 + mdio_write(dev, port->plat->phy, MII_BMCR,
2258 + port->mii_bmcr | BMCR_PDOWN);
2261 + qmgr_disable_irq(TXDONE_QUEUE);
2262 + cancel_rearming_delayed_work(&port->mdio_thread);
2263 + destroy_queues(port);
2264 + release_queues(port);
2268 +static int __devinit eth_init_one(struct platform_device *pdev)
2270 + struct port *port;
2271 + struct net_device *dev;
2272 + struct eth_plat_info *plat = pdev->dev.platform_data;
2276 + if (!(dev = alloc_etherdev(sizeof(struct port))))
2279 + SET_MODULE_OWNER(dev);
2280 + SET_NETDEV_DEV(dev, &pdev->dev);
2281 + port = netdev_priv(dev);
2282 + port->netdev = dev;
2283 + port->id = pdev->id;
2285 + switch (port->id) {
2286 + case IXP4XX_ETH_NPEA:
2287 + port->regs = (struct eth_regs __iomem *)IXP4XX_EthA_BASE_VIRT;
2288 + regs_phys = IXP4XX_EthA_BASE_PHYS;
2290 + case IXP4XX_ETH_NPEB:
2291 + port->regs = (struct eth_regs __iomem *)IXP4XX_EthB_BASE_VIRT;
2292 + regs_phys = IXP4XX_EthB_BASE_PHYS;
2294 + case IXP4XX_ETH_NPEC:
2295 + port->regs = (struct eth_regs __iomem *)IXP4XX_EthC_BASE_VIRT;
2296 + regs_phys = IXP4XX_EthC_BASE_PHYS;
2303 + dev->open = eth_open;
2304 + dev->hard_start_xmit = eth_xmit;
2305 + dev->poll = eth_poll;
2306 + dev->stop = eth_close;
2307 + dev->get_stats = eth_stats;
2308 + dev->do_ioctl = eth_ioctl;
2309 + dev->set_multicast_list = eth_set_mcast_list;
2311 + dev->tx_queue_len = 100;
2313 + if (!(port->npe = npe_request(NPE_ID(port->id)))) {
2318 + if (register_netdev(dev)) {
2323 + port->mem_res = request_mem_region(regs_phys, REGS_SIZE, dev->name);
2324 + if (!port->mem_res) {
2329 + port->plat = plat;
2330 + npe_port_tab[NPE_ID(port->id)] = port;
2331 + memcpy(dev->dev_addr, plat->hwaddr, ETH_ALEN);
2333 + platform_set_drvdata(pdev, dev);
2335 + __raw_writel(DEFAULT_CORE_CNTRL | CORE_RESET,
2336 + &port->regs->core_control);
2338 + __raw_writel(DEFAULT_CORE_CNTRL, &port->regs->core_control);
2341 + port->mii.dev = dev;
2342 + port->mii.mdio_read = mdio_read;
2343 + port->mii.mdio_write = mdio_write;
2344 + port->mii.phy_id = plat->phy;
2345 + port->mii.phy_id_mask = 0x1F;
2346 + port->mii.reg_num_mask = 0x1F;
2348 + printk(KERN_INFO "%s: MII PHY %i on %s\n", dev->name, plat->phy,
2349 + npe_name(port->npe));
2351 + phy_reset(dev, plat->phy);
2352 + port->mii_bmcr = mdio_read(dev, plat->phy, MII_BMCR) &
2353 + ~(BMCR_RESET | BMCR_PDOWN);
2354 + mdio_write(dev, plat->phy, MII_BMCR, port->mii_bmcr | BMCR_PDOWN);
2356 + INIT_DELAYED_WORK(&port->mdio_thread, mdio_thread);
2360 + unregister_netdev(dev);
2362 + npe_release(port->npe);
2368 +static int __devexit eth_remove_one(struct platform_device *pdev)
2370 + struct net_device *dev = platform_get_drvdata(pdev);
2371 + struct port *port = netdev_priv(dev);
2373 + unregister_netdev(dev);
2374 + npe_port_tab[NPE_ID(port->id)] = NULL;
2375 + platform_set_drvdata(pdev, NULL);
2376 + npe_release(port->npe);
2377 + release_resource(port->mem_res);
2382 +static struct platform_driver drv = {
2383 + .driver.name = DRV_NAME,
2384 + .probe = eth_init_one,
2385 + .remove = eth_remove_one,
2388 +static int __init eth_init_module(void)
2390 + if (!(ixp4xx_read_feature_bits() & IXP4XX_FEATURE_NPEB_ETH0))
2393 + /* All MII PHY accesses use NPE-B Ethernet registers */
2394 + spin_lock_init(&mdio_lock);
2395 + mdio_regs = (struct eth_regs __iomem *)IXP4XX_EthB_BASE_VIRT;
2396 + __raw_writel(DEFAULT_CORE_CNTRL, &mdio_regs->core_control);
2398 + return platform_driver_register(&drv);
2401 +static void __exit eth_cleanup_module(void)
2403 + platform_driver_unregister(&drv);
2406 +MODULE_AUTHOR("Krzysztof Halasa");
2407 +MODULE_DESCRIPTION("Intel IXP4xx Ethernet driver");
2408 +MODULE_LICENSE("GPL v2");
2409 +module_init(eth_init_module);
2410 +module_exit(eth_cleanup_module);
2411 Index: linux-2.6.23.17/drivers/net/wan/Kconfig
2412 ===================================================================
2413 --- linux-2.6.23.17.orig/drivers/net/wan/Kconfig
2414 +++ linux-2.6.23.17/drivers/net/wan/Kconfig
2415 @@ -334,6 +334,15 @@ config DSCC4_PCI_RST
2417 Say Y if your card supports this feature.
2420 + tristate "IXP4xx HSS (synchronous serial port) support"
2421 + depends on HDLC && ARM && ARCH_IXP4XX
2423 + select IXP4XX_QMGR
2425 + Say Y here if you want to use built-in HSS ports
2426 + on IXP4xx processor.
2429 tristate "Frame Relay DLCI support"
2431 Index: linux-2.6.23.17/drivers/net/wan/Makefile
2432 ===================================================================
2433 --- linux-2.6.23.17.orig/drivers/net/wan/Makefile
2434 +++ linux-2.6.23.17/drivers/net/wan/Makefile
2435 @@ -42,6 +42,7 @@ obj-$(CONFIG_C101) += c101.o
2436 obj-$(CONFIG_WANXL) += wanxl.o
2437 obj-$(CONFIG_PCI200SYN) += pci200syn.o
2438 obj-$(CONFIG_PC300TOO) += pc300too.o
2439 +obj-$(CONFIG_IXP4XX_HSS) += ixp4xx_hss.o
2441 clean-files := wanxlfw.inc
2442 $(obj)/wanxl.o: $(obj)/wanxlfw.inc
2443 Index: linux-2.6.23.17/drivers/net/wan/ixp4xx_hss.c
2444 ===================================================================
2446 +++ linux-2.6.23.17/drivers/net/wan/ixp4xx_hss.c
2449 + * Intel IXP4xx HSS (synchronous serial port) driver for Linux
2451 + * Copyright (C) 2007 Krzysztof Halasa <khc@pm.waw.pl>
2453 + * This program is free software; you can redistribute it and/or modify it
2454 + * under the terms of version 2 of the GNU General Public License
2455 + * as published by the Free Software Foundation.
2458 +#include <linux/dma-mapping.h>
2459 +#include <linux/dmapool.h>
2460 +#include <linux/io.h>
2461 +#include <linux/kernel.h>
2462 +#include <linux/hdlc.h>
2463 +#include <linux/platform_device.h>
2464 +#include <asm/arch/npe.h>
2465 +#include <asm/arch/qmgr.h>
2467 +#define DEBUG_QUEUES 0
2468 +#define DEBUG_DESC 0
2471 +#define DEBUG_PKT_BYTES 0
2472 +#define DEBUG_CLOSE 0
2474 +#define DRV_NAME "ixp4xx_hss"
2476 +#define PKT_EXTRA_FLAGS 0 /* orig 1 */
2477 +#define FRAME_SYNC_OFFSET 0 /* unused, channelized only */
2478 +#define FRAME_SYNC_SIZE 1024
2479 +#define PKT_NUM_PIPES 1 /* 1, 2 or 4 */
2480 +#define PKT_PIPE_FIFO_SIZEW 4 /* total 4 dwords per HSS */
2482 +#define RX_DESCS 16 /* also length of all RX queues */
2483 +#define TX_DESCS 16 /* also length of all TX queues */
2485 +#define POOL_ALLOC_SIZE (sizeof(struct desc) * (RX_DESCS + TX_DESCS))
2486 +#define RX_SIZE (HDLC_MAX_MRU + 4) /* NPE needs more space */
2487 +#define MAX_CLOSE_WAIT 1000 /* microseconds */
2490 +#define HSS0_CHL_RXTRIG_QUEUE 12 /* orig size = 32 dwords */
2491 +#define HSS0_PKT_RX_QUEUE 13 /* orig size = 32 dwords */
2492 +#define HSS0_PKT_TX0_QUEUE 14 /* orig size = 16 dwords */
2493 +#define HSS0_PKT_TX1_QUEUE 15
2494 +#define HSS0_PKT_TX2_QUEUE 16
2495 +#define HSS0_PKT_TX3_QUEUE 17
2496 +#define HSS0_PKT_RXFREE0_QUEUE 18 /* orig size = 16 dwords */
2497 +#define HSS0_PKT_RXFREE1_QUEUE 19
2498 +#define HSS0_PKT_RXFREE2_QUEUE 20
2499 +#define HSS0_PKT_RXFREE3_QUEUE 21
2500 +#define HSS0_PKT_TXDONE_QUEUE 22 /* orig size = 64 dwords */
2502 +#define HSS1_CHL_RXTRIG_QUEUE 10
2503 +#define HSS1_PKT_RX_QUEUE 0
2504 +#define HSS1_PKT_TX0_QUEUE 5
2505 +#define HSS1_PKT_TX1_QUEUE 6
2506 +#define HSS1_PKT_TX2_QUEUE 7
2507 +#define HSS1_PKT_TX3_QUEUE 8
2508 +#define HSS1_PKT_RXFREE0_QUEUE 1
2509 +#define HSS1_PKT_RXFREE1_QUEUE 2
2510 +#define HSS1_PKT_RXFREE2_QUEUE 3
2511 +#define HSS1_PKT_RXFREE3_QUEUE 4
2512 +#define HSS1_PKT_TXDONE_QUEUE 9
2514 +#define NPE_PKT_MODE_HDLC 0
2515 +#define NPE_PKT_MODE_RAW 1
2516 +#define NPE_PKT_MODE_56KMODE 2
2517 +#define NPE_PKT_MODE_56KENDIAN_MSB 4
2519 +/* PKT_PIPE_HDLC_CFG_WRITE flags */
2520 +#define PKT_HDLC_IDLE_ONES 0x1 /* default = flags */
2521 +#define PKT_HDLC_CRC_32 0x2 /* default = CRC-16 */
2522 +#define PKT_HDLC_MSB_ENDIAN 0x4 /* default = LE */
2525 +/* hss_config, PCRs */
2526 +/* Frame sync sampling, default = active low */
2527 +#define PCR_FRM_SYNC_ACTIVE_HIGH 0x40000000
2528 +#define PCR_FRM_SYNC_FALLINGEDGE 0x80000000
2529 +#define PCR_FRM_SYNC_RISINGEDGE 0xC0000000
2531 +/* Frame sync pin: input (default) or output generated off a given clk edge */
2532 +#define PCR_FRM_SYNC_OUTPUT_FALLING 0x20000000
2533 +#define PCR_FRM_SYNC_OUTPUT_RISING 0x30000000
2535 +/* Frame and data clock sampling on edge, default = falling */
2536 +#define PCR_FCLK_EDGE_RISING 0x08000000
2537 +#define PCR_DCLK_EDGE_RISING 0x04000000
2539 +/* Clock direction, default = input */
2540 +#define PCR_SYNC_CLK_DIR_OUTPUT 0x02000000
2542 +/* Generate/Receive frame pulses, default = enabled */
2543 +#define PCR_FRM_PULSE_DISABLED 0x01000000
2545 + /* Data rate is full (default) or half the configured clk speed */
2546 +#define PCR_HALF_CLK_RATE 0x00200000
2548 +/* Invert data between NPE and HSS FIFOs? (default = no) */
2549 +#define PCR_DATA_POLARITY_INVERT 0x00100000
2551 +/* TX/RX endianness, default = LSB */
2552 +#define PCR_MSB_ENDIAN 0x00080000
2554 +/* Normal (default) / open drain mode (TX only) */
2555 +#define PCR_TX_PINS_OPEN_DRAIN 0x00040000
2557 +/* No framing bit transmitted and expected on RX? (default = framing bit) */
2558 +#define PCR_SOF_NO_FBIT 0x00020000
2560 +/* Drive data pins? */
2561 +#define PCR_TX_DATA_ENABLE 0x00010000
2563 +/* Voice 56k type: drive the data pins low (default), high, high Z */
2564 +#define PCR_TX_V56K_HIGH 0x00002000
2565 +#define PCR_TX_V56K_HIGH_IMP 0x00004000
2567 +/* Unassigned type: drive the data pins low (default), high, high Z */
2568 +#define PCR_TX_UNASS_HIGH 0x00000800
2569 +#define PCR_TX_UNASS_HIGH_IMP 0x00001000
2571 +/* T1 @ 1.544MHz only: Fbit dictated in FIFO (default) or high Z */
2572 +#define PCR_TX_FB_HIGH_IMP 0x00000400
2574 +/* 56k data endiannes - which bit unused: high (default) or low */
2575 +#define PCR_TX_56KE_BIT_0_UNUSED 0x00000200
2577 +/* 56k data transmission type: 32/8 bit data (default) or 56K data */
2578 +#define PCR_TX_56KS_56K_DATA 0x00000100
2580 +/* hss_config, cCR */
2581 +/* Number of packetized clients, default = 1 */
2582 +#define CCR_NPE_HFIFO_2_HDLC 0x04000000
2583 +#define CCR_NPE_HFIFO_3_OR_4HDLC 0x08000000
2585 +/* default = no loopback */
2586 +#define CCR_LOOPBACK 0x02000000
2588 +/* HSS number, default = 0 (first) */
2589 +#define CCR_SECOND_HSS 0x01000000
2592 +/* hss_config, clkCR: main:10, num:10, denom:12 */
2593 +#define CLK42X_SPEED_EXP ((0x3FF << 22) | ( 2 << 12) | 15) /*65 KHz*/
2595 +#define CLK42X_SPEED_512KHZ (( 130 << 22) | ( 2 << 12) | 15)
2596 +#define CLK42X_SPEED_1536KHZ (( 43 << 22) | ( 18 << 12) | 47)
2597 +#define CLK42X_SPEED_1544KHZ (( 43 << 22) | ( 33 << 12) | 192)
2598 +#define CLK42X_SPEED_2048KHZ (( 32 << 22) | ( 34 << 12) | 63)
2599 +#define CLK42X_SPEED_4096KHZ (( 16 << 22) | ( 34 << 12) | 127)
2600 +#define CLK42X_SPEED_8192KHZ (( 8 << 22) | ( 34 << 12) | 255)
2602 +#define CLK46X_SPEED_512KHZ (( 130 << 22) | ( 24 << 12) | 127)
2603 +#define CLK46X_SPEED_1536KHZ (( 43 << 22) | (152 << 12) | 383)
2604 +#define CLK46X_SPEED_1544KHZ (( 43 << 22) | ( 66 << 12) | 385)
2605 +#define CLK46X_SPEED_2048KHZ (( 32 << 22) | (280 << 12) | 511)
2606 +#define CLK46X_SPEED_4096KHZ (( 16 << 22) | (280 << 12) | 1023)
2607 +#define CLK46X_SPEED_8192KHZ (( 8 << 22) | (280 << 12) | 2047)
2610 +/* hss_config, LUT entries */
2611 +#define TDMMAP_UNASSIGNED 0
2612 +#define TDMMAP_HDLC 1 /* HDLC - packetized */
2613 +#define TDMMAP_VOICE56K 2 /* Voice56K - 7-bit channelized */
2614 +#define TDMMAP_VOICE64K 3 /* Voice64K - 8-bit channelized */
2616 +#define TIMESLOTS 128
2619 +/* offsets into HSS config */
2620 +#define HSS_CONFIG_TX_PCR 0x00
2621 +#define HSS_CONFIG_RX_PCR 0x04
2622 +#define HSS_CONFIG_CORE_CR 0x08
2623 +#define HSS_CONFIG_CLOCK_CR 0x0C
2624 +#define HSS_CONFIG_TX_FCR 0x10
2625 +#define HSS_CONFIG_RX_FCR 0x14
2626 +#define HSS_CONFIG_TX_LUT 0x18
2627 +#define HSS_CONFIG_RX_LUT 0x38
2630 +/* NPE command codes */
2631 +/* writes the ConfigWord value to the location specified by offset */
2632 +#define PORT_CONFIG_WRITE 0x40
2634 +/* triggers the NPE to load the contents of the configuration table */
2635 +#define PORT_CONFIG_LOAD 0x41
2637 +/* triggers the NPE to return an HssErrorReadResponse message */
2638 +#define PORT_ERROR_READ 0x42
2640 +/* reset NPE internal status and enable the HssChannelized operation */
2641 +#define CHAN_FLOW_ENABLE 0x43
2642 +#define CHAN_FLOW_DISABLE 0x44
2643 +#define CHAN_IDLE_PATTERN_WRITE 0x45
2644 +#define CHAN_NUM_CHANS_WRITE 0x46
2645 +#define CHAN_RX_BUF_ADDR_WRITE 0x47
2646 +#define CHAN_RX_BUF_CFG_WRITE 0x48
2647 +#define CHAN_TX_BLK_CFG_WRITE 0x49
2648 +#define CHAN_TX_BUF_ADDR_WRITE 0x4A
2649 +#define CHAN_TX_BUF_SIZE_WRITE 0x4B
2650 +#define CHAN_TSLOTSWITCH_ENABLE 0x4C
2651 +#define CHAN_TSLOTSWITCH_DISABLE 0x4D
2653 +/* downloads the gainWord value for a timeslot switching channel associated
2655 +#define CHAN_TSLOTSWITCH_GCT_DOWNLOAD 0x4E
2657 +/* triggers the NPE to reset internal status and enable the HssPacketized
2658 + operation for the flow specified by pPipe */
2659 +#define PKT_PIPE_FLOW_ENABLE 0x50
2660 +#define PKT_PIPE_FLOW_DISABLE 0x51
2661 +#define PKT_NUM_PIPES_WRITE 0x52
2662 +#define PKT_PIPE_FIFO_SIZEW_WRITE 0x53
2663 +#define PKT_PIPE_HDLC_CFG_WRITE 0x54
2664 +#define PKT_PIPE_IDLE_PATTERN_WRITE 0x55
2665 +#define PKT_PIPE_RX_SIZE_WRITE 0x56
2666 +#define PKT_PIPE_MODE_WRITE 0x57
2668 +/* HDLC packet status values - desc->status */
2669 +#define ERR_SHUTDOWN 1 /* stop or shutdown occurrance */
2670 +#define ERR_HDLC_ALIGN 2 /* HDLC alignment error */
2671 +#define ERR_HDLC_FCS 3 /* HDLC Frame Check Sum error */
2672 +#define ERR_RXFREE_Q_EMPTY 4 /* RX-free queue became empty while receiving
2673 + this packet (if buf_len < pkt_len) */
2674 +#define ERR_HDLC_TOO_LONG 5 /* HDLC frame size too long */
2675 +#define ERR_HDLC_ABORT 6 /* abort sequence received */
2676 +#define ERR_DISCONNECTING 7 /* disconnect is in progress */
2680 +typedef struct sk_buff buffer_t;
2681 +#define free_buffer dev_kfree_skb
2682 +#define free_buffer_irq dev_kfree_skb_irq
2684 +typedef void buffer_t;
2685 +#define free_buffer kfree
2686 +#define free_buffer_irq kfree
2691 + struct net_device *netdev;
2692 + struct hss_plat_info *plat;
2693 + buffer_t *rx_buff_tab[RX_DESCS], *tx_buff_tab[TX_DESCS];
2694 + struct desc *desc_tab; /* coherent */
2695 + u32 desc_tab_phys;
2697 + unsigned int clock_type, clock_rate, loopback;
2701 +/* NPE message structure */
2704 + u8 cmd, unused, hss_port, index;
2706 + struct { u8 data8a, data8b, data8c, data8d; };
2707 + struct { u16 data16a, data16b; };
2708 + struct { u32 data32; };
2711 + u8 index, hss_port, unused, cmd;
2713 + struct { u8 data8d, data8c, data8b, data8a; };
2714 + struct { u16 data16b, data16a; };
2715 + struct { u32 data32; };
2720 +/* HDLC packet descriptor */
2722 + u32 next; /* pointer to next buffer, unused */
2725 + u16 buf_len; /* buffer length */
2726 + u16 pkt_len; /* packet length */
2727 + u32 data; /* pointer to data buffer in RAM */
2732 + u16 pkt_len; /* packet length */
2733 + u16 buf_len; /* buffer length */
2734 + u32 data; /* pointer to data buffer in RAM */
2739 + u32 __reserved1[4];
2743 +#define rx_desc_phys(port, n) ((port)->desc_tab_phys + \
2744 + (n) * sizeof(struct desc))
2745 +#define rx_desc_ptr(port, n) (&(port)->desc_tab[n])
2747 +#define tx_desc_phys(port, n) ((port)->desc_tab_phys + \
2748 + ((n) + RX_DESCS) * sizeof(struct desc))
2749 +#define tx_desc_ptr(port, n) (&(port)->desc_tab[(n) + RX_DESCS])
2751 +/*****************************************************************************
2752 + * global variables
2753 + ****************************************************************************/
2755 +static int ports_open;
2756 +static struct dma_pool *dma_pool;
2758 +static const struct {
2759 + int tx, txdone, rx, rxfree;
2760 +}queue_ids[2] = {{ HSS0_PKT_TX0_QUEUE, HSS0_PKT_TXDONE_QUEUE,
2761 + HSS0_PKT_RX_QUEUE, HSS0_PKT_RXFREE0_QUEUE },
2762 + { HSS1_PKT_TX0_QUEUE, HSS1_PKT_TXDONE_QUEUE,
2763 + HSS1_PKT_RX_QUEUE, HSS1_PKT_RXFREE0_QUEUE },
2766 +/*****************************************************************************
2767 + * utility functions
2768 + ****************************************************************************/
2770 +static inline struct port* dev_to_port(struct net_device *dev)
2772 + return dev_to_hdlc(dev)->priv;
2776 +static inline void memcpy_swab32(u32 *dest, u32 *src, int cnt)
2779 + for (i = 0; i < cnt; i++)
2780 + dest[i] = swab32(src[i]);
2784 +static inline void debug_pkt(struct net_device *dev, const char *func,
2785 + u8 *data, int len)
2787 +#if DEBUG_PKT_BYTES
2790 + printk(KERN_DEBUG "%s: %s(%i) ", dev->name, func, len);
2791 + for (i = 0; i < len; i++) {
2792 + if (i >= DEBUG_PKT_BYTES)
2794 + printk("%s%02X", !(i % 4) ? " " : "", data[i]);
2801 +static inline void debug_desc(u32 phys, struct desc *desc)
2804 + printk(KERN_DEBUG "%X: %X %3X %3X %08X %X %X\n",
2805 + phys, desc->next, desc->buf_len, desc->pkt_len,
2806 + desc->data, desc->status, desc->error_count);
2810 +static inline void debug_queue(unsigned int queue, int is_get, u32 phys)
2817 + { HSS0_PKT_TX0_QUEUE, "TX#0 " },
2818 + { HSS0_PKT_TXDONE_QUEUE, "TX-done#0 " },
2819 + { HSS0_PKT_RX_QUEUE, "RX#0 " },
2820 + { HSS0_PKT_RXFREE0_QUEUE, "RX-free#0 " },
2821 + { HSS1_PKT_TX0_QUEUE, "TX#1 " },
2822 + { HSS1_PKT_TXDONE_QUEUE, "TX-done#1 " },
2823 + { HSS1_PKT_RX_QUEUE, "RX#1 " },
2824 + { HSS1_PKT_RXFREE0_QUEUE, "RX-free#1 " },
2828 + for (i = 0; i < ARRAY_SIZE(names); i++)
2829 + if (names[i].queue == queue)
2832 + printk(KERN_DEBUG "Queue %i %s%s %X\n", queue,
2833 + i < ARRAY_SIZE(names) ? names[i].name : "",
2834 + is_get ? "->" : "<-", phys);
2838 +static inline u32 queue_get_entry(unsigned int queue)
2840 + u32 phys = qmgr_get_entry(queue);
2841 + debug_queue(queue, 1, phys);
2845 +static inline int queue_get_desc(unsigned int queue, struct port *port,
2848 + u32 phys, tab_phys, n_desc;
2851 + if (!(phys = queue_get_entry(queue)))
2854 + BUG_ON(phys & 0x1F);
2855 + tab_phys = is_tx ? tx_desc_phys(port, 0) : rx_desc_phys(port, 0);
2856 + tab = is_tx ? tx_desc_ptr(port, 0) : rx_desc_ptr(port, 0);
2857 + n_desc = (phys - tab_phys) / sizeof(struct desc);
2858 + BUG_ON(n_desc >= (is_tx ? TX_DESCS : RX_DESCS));
2859 + debug_desc(phys, &tab[n_desc]);
2860 + BUG_ON(tab[n_desc].next);
2864 +static inline void queue_put_desc(unsigned int queue, u32 phys,
2865 + struct desc *desc)
2867 + debug_queue(queue, 0, phys);
2868 + debug_desc(phys, desc);
2869 + BUG_ON(phys & 0x1F);
2870 + qmgr_put_entry(queue, phys);
2871 + BUG_ON(qmgr_stat_overflow(queue));
2875 +static inline void dma_unmap_tx(struct port *port, struct desc *desc)
2878 + dma_unmap_single(&port->netdev->dev, desc->data,
2879 + desc->buf_len, DMA_TO_DEVICE);
2881 + dma_unmap_single(&port->netdev->dev, desc->data & ~3,
2882 + ALIGN((desc->data & 3) + desc->buf_len, 4),
2888 +static void hss_hdlc_set_carrier(void *pdev, int carrier)
2890 + struct net_device *dev = pdev;
2892 + netif_carrier_on(dev);
2894 + netif_carrier_off(dev);
2897 +static void hss_hdlc_rx_irq(void *pdev)
2899 + struct net_device *dev = pdev;
2900 + struct port *port = dev_to_port(dev);
2903 + printk(KERN_DEBUG "%s: hss_hdlc_rx_irq\n", dev->name);
2905 + qmgr_disable_irq(queue_ids[port->id].rx);
2906 + netif_rx_schedule(dev);
2909 +static int hss_hdlc_poll(struct net_device *dev, int *budget)
2911 + struct port *port = dev_to_port(dev);
2912 + unsigned int rxq = queue_ids[port->id].rx;
2913 + unsigned int rxfreeq = queue_ids[port->id].rxfree;
2914 + struct net_device_stats *stats = hdlc_stats(dev);
2915 + int quota = dev->quota, received = 0;
2918 + printk(KERN_DEBUG "%s: hss_hdlc_poll\n", dev->name);
2922 + struct sk_buff *skb;
2923 + struct desc *desc;
2926 + struct sk_buff *temp;
2930 + if ((n = queue_get_desc(rxq, port, 0)) < 0) {
2931 + dev->quota -= received; /* No packet received */
2932 + *budget -= received;
2935 + printk(KERN_DEBUG "%s: hss_hdlc_poll"
2936 + " netif_rx_complete\n", dev->name);
2938 + netif_rx_complete(dev);
2939 + qmgr_enable_irq(rxq);
2940 + if (!qmgr_stat_empty(rxq) &&
2941 + netif_rx_reschedule(dev, 0)) {
2943 + printk(KERN_DEBUG "%s: hss_hdlc_poll"
2944 + " netif_rx_reschedule successed\n",
2947 + qmgr_disable_irq(rxq);
2951 + printk(KERN_DEBUG "%s: hss_hdlc_poll all done\n",
2954 + return 0; /* all work done */
2957 + desc = rx_desc_ptr(port, n);
2959 + if (desc->error_count) /* FIXME - remove printk */
2960 + printk(KERN_DEBUG "%s: hss_hdlc_poll status 0x%02X"
2961 + " errors %u\n", dev->name, desc->status,
2962 + desc->error_count);
2965 + switch (desc->status) {
2968 + if ((skb = netdev_alloc_skb(dev, RX_SIZE)) != NULL) {
2969 + phys = dma_map_single(&dev->dev, skb->data,
2972 + if (dma_mapping_error(phys)) {
2973 + dev_kfree_skb(skb);
2978 + skb = netdev_alloc_skb(dev, desc->pkt_len);
2981 + stats->rx_dropped++;
2983 + case ERR_HDLC_ALIGN:
2984 + case ERR_HDLC_ABORT:
2985 + stats->rx_frame_errors++;
2986 + stats->rx_errors++;
2988 + case ERR_HDLC_FCS:
2989 + stats->rx_crc_errors++;
2990 + stats->rx_errors++;
2992 + case ERR_HDLC_TOO_LONG:
2993 + stats->rx_length_errors++;
2994 + stats->rx_errors++;
2996 + default: /* FIXME - remove printk */
2997 + printk(KERN_ERR "%s: hss_hdlc_poll: status 0x%02X"
2998 + " errors %u\n", dev->name, desc->status,
2999 + desc->error_count);
3000 + stats->rx_errors++;
3004 + /* put the desc back on RX-ready queue */
3005 + desc->buf_len = RX_SIZE;
3006 + desc->pkt_len = desc->status = 0;
3007 + queue_put_desc(rxfreeq, rx_desc_phys(port, n), desc);
3011 + /* process received frame */
3014 + skb = port->rx_buff_tab[n];
3015 + dma_unmap_single(&dev->dev, desc->data,
3016 + RX_SIZE, DMA_FROM_DEVICE);
3018 + dma_sync_single(&dev->dev, desc->data,
3019 + RX_SIZE, DMA_FROM_DEVICE);
3020 + memcpy_swab32((u32 *)skb->data, (u32 *)port->rx_buff_tab[n],
3021 + ALIGN(desc->pkt_len, 4) / 4);
3023 + skb_put(skb, desc->pkt_len);
3025 + debug_pkt(dev, "hss_hdlc_poll", skb->data, skb->len);
3027 + skb->protocol = hdlc_type_trans(skb, dev);
3028 + dev->last_rx = jiffies;
3029 + stats->rx_packets++;
3030 + stats->rx_bytes += skb->len;
3031 + netif_receive_skb(skb);
3033 + /* put the new buffer on RX-free queue */
3035 + port->rx_buff_tab[n] = temp;
3036 + desc->data = phys;
3038 + desc->buf_len = RX_SIZE;
3039 + desc->pkt_len = 0;
3040 + queue_put_desc(rxfreeq, rx_desc_phys(port, n), desc);
3044 + dev->quota -= received;
3045 + *budget -= received;
3047 + printk(KERN_DEBUG "hss_hdlc_poll: end, not all work done\n");
3049 + return 1; /* not all work done */
3053 +static void hss_hdlc_txdone_irq(void *pdev)
3055 + struct net_device *dev = pdev;
3056 + struct port *port = dev_to_port(dev);
3057 + struct net_device_stats *stats = hdlc_stats(dev);
3061 + printk(KERN_DEBUG DRV_NAME ": hss_hdlc_txdone_irq\n");
3063 + while ((n_desc = queue_get_desc(queue_ids[port->id].txdone,
3065 + struct desc *desc;
3068 + desc = tx_desc_ptr(port, n_desc);
3070 + stats->tx_packets++;
3071 + stats->tx_bytes += desc->pkt_len;
3073 + dma_unmap_tx(port, desc);
3075 + printk(KERN_DEBUG "%s: hss_hdlc_txdone_irq free %p\n",
3076 + port->netdev->name, port->tx_buff_tab[n_desc]);
3078 + free_buffer_irq(port->tx_buff_tab[n_desc]);
3079 + port->tx_buff_tab[n_desc] = NULL;
3081 + start = qmgr_stat_empty(port->plat->txreadyq);
3082 + queue_put_desc(port->plat->txreadyq,
3083 + tx_desc_phys(port, n_desc), desc);
3086 + printk(KERN_DEBUG "%s: hss_hdlc_txdone_irq xmit"
3087 + " ready\n", port->netdev->name);
3089 + netif_wake_queue(port->netdev);
3094 +static int hss_hdlc_xmit(struct sk_buff *skb, struct net_device *dev)
3096 + struct port *port = dev_to_port(dev);
3097 + struct net_device_stats *stats = hdlc_stats(dev);
3098 + unsigned int txreadyq = port->plat->txreadyq;
3099 + int len, offset, bytes, n;
3102 + struct desc *desc;
3105 + printk(KERN_DEBUG "%s: hss_hdlc_xmit\n", dev->name);
3108 + if (unlikely(skb->len > HDLC_MAX_MRU)) {
3109 + dev_kfree_skb(skb);
3110 + stats->tx_errors++;
3111 + return NETDEV_TX_OK;
3114 + debug_pkt(dev, "hss_hdlc_xmit", skb->data, skb->len);
3118 + offset = 0; /* no need to keep alignment */
3122 + offset = (int)skb->data & 3; /* keep 32-bit alignment */
3123 + bytes = ALIGN(offset + len, 4);
3124 + if (!(mem = kmalloc(bytes, GFP_ATOMIC))) {
3125 + dev_kfree_skb(skb);
3126 + stats->tx_dropped++;
3127 + return NETDEV_TX_OK;
3129 + memcpy_swab32(mem, (u32 *)((int)skb->data & ~3), bytes / 4);
3130 + dev_kfree_skb(skb);
3133 + phys = dma_map_single(&dev->dev, mem, bytes, DMA_TO_DEVICE);
3134 + if (dma_mapping_error(phys)) {
3136 + dev_kfree_skb(skb);
3140 + stats->tx_dropped++;
3141 + return NETDEV_TX_OK;
3144 + n = queue_get_desc(txreadyq, port, 1);
3146 + desc = tx_desc_ptr(port, n);
3149 + port->tx_buff_tab[n] = skb;
3151 + port->tx_buff_tab[n] = mem;
3153 + desc->data = phys + offset;
3154 + desc->buf_len = desc->pkt_len = len;
3157 + queue_put_desc(queue_ids[port->id].tx, tx_desc_phys(port, n), desc);
3158 + dev->trans_start = jiffies;
3160 + if (qmgr_stat_empty(txreadyq)) {
3162 + printk(KERN_DEBUG "%s: hss_hdlc_xmit queue full\n", dev->name);
3164 + netif_stop_queue(dev);
3165 + /* we could miss TX ready interrupt */
3166 + if (!qmgr_stat_empty(txreadyq)) {
3168 + printk(KERN_DEBUG "%s: hss_hdlc_xmit ready again\n",
3171 + netif_wake_queue(dev);
3176 + printk(KERN_DEBUG "%s: hss_hdlc_xmit end\n", dev->name);
3178 + return NETDEV_TX_OK;
3182 +static int request_hdlc_queues(struct port *port)
3186 + err = qmgr_request_queue(queue_ids[port->id].rxfree, RX_DESCS, 0, 0);
3190 + err = qmgr_request_queue(queue_ids[port->id].rx, RX_DESCS, 0, 0);
3194 + err = qmgr_request_queue(queue_ids[port->id].tx, TX_DESCS, 0, 0);
3198 + err = qmgr_request_queue(port->plat->txreadyq, TX_DESCS, 0, 0);
3202 + err = qmgr_request_queue(queue_ids[port->id].txdone, TX_DESCS, 0, 0);
3208 + qmgr_release_queue(port->plat->txreadyq);
3210 + qmgr_release_queue(queue_ids[port->id].tx);
3212 + qmgr_release_queue(queue_ids[port->id].rx);
3214 + qmgr_release_queue(queue_ids[port->id].rxfree);
3215 + printk(KERN_DEBUG "%s: unable to request hardware queues\n",
3216 + port->netdev->name);
3220 +static void release_hdlc_queues(struct port *port)
3222 + qmgr_release_queue(queue_ids[port->id].rxfree);
3223 + qmgr_release_queue(queue_ids[port->id].rx);
3224 + qmgr_release_queue(queue_ids[port->id].txdone);
3225 + qmgr_release_queue(queue_ids[port->id].tx);
3226 + qmgr_release_queue(port->plat->txreadyq);
3229 +static int init_hdlc_queues(struct port *port)
3234 + if (!(dma_pool = dma_pool_create(DRV_NAME, NULL,
3235 + POOL_ALLOC_SIZE, 32, 0)))
3238 + if (!(port->desc_tab = dma_pool_alloc(dma_pool, GFP_KERNEL,
3239 + &port->desc_tab_phys)))
3241 + memset(port->desc_tab, 0, POOL_ALLOC_SIZE);
3242 + memset(port->rx_buff_tab, 0, sizeof(port->rx_buff_tab)); /* tables */
3243 + memset(port->tx_buff_tab, 0, sizeof(port->tx_buff_tab));
3245 + /* Setup RX buffers */
3246 + for (i = 0; i < RX_DESCS; i++) {
3247 + struct desc *desc = rx_desc_ptr(port, i);
3251 + if (!(buff = netdev_alloc_skb(port->netdev, RX_SIZE)))
3253 + data = buff->data;
3255 + if (!(buff = kmalloc(RX_SIZE, GFP_KERNEL)))
3259 + desc->buf_len = RX_SIZE;
3260 + desc->data = dma_map_single(&port->netdev->dev, data,
3261 + RX_SIZE, DMA_FROM_DEVICE);
3262 + if (dma_mapping_error(desc->data)) {
3263 + free_buffer(buff);
3266 + port->rx_buff_tab[i] = buff;
3272 +static void destroy_hdlc_queues(struct port *port)
3276 + if (port->desc_tab) {
3277 + for (i = 0; i < RX_DESCS; i++) {
3278 + struct desc *desc = rx_desc_ptr(port, i);
3279 + buffer_t *buff = port->rx_buff_tab[i];
3281 + dma_unmap_single(&port->netdev->dev,
3282 + desc->data, RX_SIZE,
3284 + free_buffer(buff);
3287 + for (i = 0; i < TX_DESCS; i++) {
3288 + struct desc *desc = tx_desc_ptr(port, i);
3289 + buffer_t *buff = port->tx_buff_tab[i];
3291 + dma_unmap_tx(port, desc);
3292 + free_buffer(buff);
3295 + dma_pool_free(dma_pool, port->desc_tab, port->desc_tab_phys);
3296 + port->desc_tab = NULL;
3299 + if (!ports_open && dma_pool) {
3300 + dma_pool_destroy(dma_pool);
3305 +static int hss_hdlc_open(struct net_device *dev)
3307 + struct port *port = dev_to_port(dev);
3308 + struct npe *npe = port->npe;
3312 + if (!npe_running(npe)) {
3313 + err = npe_load_firmware(npe, npe_name(npe), &dev->dev);
3318 + if ((err = hdlc_open(dev)) != 0)
3321 + if (port->plat->open)
3322 + if ((err = port->plat->open(port->id, port->netdev,
3323 + hss_hdlc_set_carrier)) != 0)
3324 + goto err_hdlc_close;
3326 + /* HSS main configuration */
3327 + memset(&msg, 0, sizeof(msg));
3328 + msg.cmd = PORT_CONFIG_WRITE;
3329 + msg.hss_port = port->id;
3330 + msg.index = 0; /* offset in HSS config */
3332 + msg.data32 = PCR_FRM_PULSE_DISABLED |
3335 + PCR_TX_DATA_ENABLE;
3337 + if (port->clock_type == CLOCK_INT)
3338 + msg.data32 |= PCR_SYNC_CLK_DIR_OUTPUT;
3340 + if ((err = npe_send_message(npe, &msg, "HSS_SET_TX_PCR") != 0))
3341 + goto err_plat_close; /* 0: TX PCR */
3344 + msg.data32 ^= PCR_TX_DATA_ENABLE | PCR_DCLK_EDGE_RISING;
3345 + if ((err = npe_send_message(npe, &msg, "HSS_SET_RX_PCR") != 0))
3346 + goto err_plat_close; /* 4: RX PCR */
3349 + msg.data32 = (port->loopback ? CCR_LOOPBACK : 0) |
3350 + (port->id ? CCR_SECOND_HSS : 0);
3351 + if ((err = npe_send_message(npe, &msg, "HSS_SET_CORE_CR") != 0))
3352 + goto err_plat_close; /* 8: Core CR */
3355 + msg.data32 = CLK42X_SPEED_2048KHZ /* FIXME */;
3356 + if ((err = npe_send_message(npe, &msg, "HSS_SET_CLK_CR") != 0))
3357 + goto err_plat_close; /* 12: CLK CR */
3359 + msg.data32 = (FRAME_SYNC_OFFSET << 16) | (FRAME_SYNC_SIZE - 1);
3361 + if ((err = npe_send_message(npe, &msg, "HSS_SET_TX_FCR") != 0))
3362 + goto err_plat_close; /* 16: TX FCR */
3365 + if ((err = npe_send_message(npe, &msg, "HSS_SET_RX_FCR") != 0))
3366 + goto err_plat_close; /* 20: RX FCR */
3368 + msg.data32 = 0; /* Fill LUT with HDLC timeslots */
3369 + for (i = 0; i < 32 / LUT_BITS; i++)
3370 + msg.data32 |= TDMMAP_HDLC << (LUT_BITS * i);
3372 + for (i = 0; i < 2 /* TX and RX */ * TIMESLOTS * LUT_BITS / 8; i += 4) {
3373 + msg.index = 24 + i; /* 24 - 55: TX LUT, 56 - 87: RX LUT */
3374 + if ((err = npe_send_message(npe, &msg, "HSS_SET_LUT") != 0))
3375 + goto err_plat_close;
3378 + /* HDLC mode configuration */
3379 + memset(&msg, 0, sizeof(msg));
3380 + msg.cmd = PKT_NUM_PIPES_WRITE;
3381 + msg.hss_port = port->id;
3382 + msg.data8a = PKT_NUM_PIPES;
3383 + if ((err = npe_send_message(npe, &msg, "HSS_SET_PKT_PIPES") != 0))
3384 + goto err_plat_close;
3386 + memset(&msg, 0, sizeof(msg));
3387 + msg.cmd = PKT_PIPE_FIFO_SIZEW_WRITE;
3388 + msg.hss_port = port->id;
3389 + msg.data8a = PKT_PIPE_FIFO_SIZEW;
3390 + if ((err = npe_send_message(npe, &msg, "HSS_SET_PKT_FIFO") != 0))
3391 + goto err_plat_close;
3393 + memset(&msg, 0, sizeof(msg));
3394 + msg.cmd = PKT_PIPE_IDLE_PATTERN_WRITE;
3395 + msg.hss_port = port->id;
3396 + msg.data32 = 0x7F7F7F7F;
3397 + if ((err = npe_send_message(npe, &msg, "HSS_SET_PKT_IDLE") != 0))
3398 + goto err_plat_close;
3400 + memset(&msg, 0, sizeof(msg));
3401 + msg.cmd = PORT_CONFIG_LOAD;
3402 + msg.hss_port = port->id;
3403 + if ((err = npe_send_message(npe, &msg, "HSS_LOAD_CONFIG") != 0))
3404 + goto err_plat_close;
3405 + if ((err = npe_recv_message(npe, &msg, "HSS_LOAD_CONFIG") != 0))
3406 + goto err_plat_close;
3408 + /* HSS_LOAD_CONFIG for port #1 returns port_id = #4 */
3409 + if (msg.cmd != PORT_CONFIG_LOAD || msg.data32) {
3410 + printk(KERN_DEBUG "%s: unexpected message received in"
3411 + " response to HSS_LOAD_CONFIG\n", npe_name(npe));
3413 + goto err_plat_close;
3416 + memset(&msg, 0, sizeof(msg));
3417 + msg.cmd = PKT_PIPE_HDLC_CFG_WRITE;
3418 + msg.hss_port = port->id;
3419 + msg.data8a = port->hdlc_cfg; /* rx_cfg */
3420 + msg.data8b = port->hdlc_cfg | (PKT_EXTRA_FLAGS << 3); /* tx_cfg */
3421 + if ((err = npe_send_message(npe, &msg, "HSS_SET_HDLC_CFG") != 0))
3422 + goto err_plat_close;
3424 + memset(&msg, 0, sizeof(msg));
3425 + msg.cmd = PKT_PIPE_MODE_WRITE;
3426 + msg.hss_port = port->id;
3427 + msg.data8a = NPE_PKT_MODE_HDLC;
3428 + /* msg.data8b = inv_mask */
3429 + /* msg.data8c = or_mask */
3430 + if ((err = npe_send_message(npe, &msg, "HSS_SET_PKT_MODE") != 0))
3431 + goto err_plat_close;
3433 + memset(&msg, 0, sizeof(msg));
3434 + msg.cmd = PKT_PIPE_RX_SIZE_WRITE;
3435 + msg.hss_port = port->id;
3436 + msg.data16a = HDLC_MAX_MRU;
3437 + if ((err = npe_send_message(npe, &msg, "HSS_SET_PKT_RX_SIZE") != 0))
3438 + goto err_plat_close;
3440 + if ((err = request_hdlc_queues(port)) != 0)
3441 + goto err_plat_close;
3443 + if ((err = init_hdlc_queues(port)) != 0)
3444 + goto err_destroy_queues;
3446 + memset(&msg, 0, sizeof(msg));
3447 + msg.cmd = PKT_PIPE_FLOW_ENABLE;
3448 + msg.hss_port = port->id;
3449 + if ((err = npe_send_message(npe, &msg, "HSS_ENABLE_PKT_PIPE") != 0))
3450 + goto err_destroy_queues;
3452 + /* Populate queues with buffers, no failure after this point */
3453 + for (i = 0; i < TX_DESCS; i++)
3454 + queue_put_desc(port->plat->txreadyq,
3455 + tx_desc_phys(port, i), tx_desc_ptr(port, i));
3457 + for (i = 0; i < RX_DESCS; i++)
3458 + queue_put_desc(queue_ids[port->id].rxfree,
3459 + rx_desc_phys(port, i), rx_desc_ptr(port, i));
3461 + netif_start_queue(dev);
3463 + qmgr_set_irq(queue_ids[port->id].rx, QUEUE_IRQ_SRC_NOT_EMPTY,
3464 + hss_hdlc_rx_irq, dev);
3466 + qmgr_set_irq(queue_ids[port->id].txdone, QUEUE_IRQ_SRC_NOT_EMPTY,
3467 + hss_hdlc_txdone_irq, dev);
3468 + qmgr_enable_irq(queue_ids[port->id].txdone);
3471 + netif_rx_schedule(dev); /* we may already have RX data, enables IRQ */
3474 +err_destroy_queues:
3475 + destroy_hdlc_queues(port);
3476 + release_hdlc_queues(port);
3478 + if (port->plat->close)
3479 + port->plat->close(port->id, port->netdev);
3485 +static int hss_hdlc_close(struct net_device *dev)
3487 + struct port *port = dev_to_port(dev);
3488 + struct npe *npe = port->npe;
3490 + int buffs = RX_DESCS; /* allocated RX buffers */
3494 + qmgr_disable_irq(queue_ids[port->id].rx);
3495 + netif_stop_queue(dev);
3497 + memset(&msg, 0, sizeof(msg));
3498 + msg.cmd = PKT_PIPE_FLOW_DISABLE;
3499 + msg.hss_port = port->id;
3500 + if (npe_send_message(npe, &msg, "HSS_DISABLE_PKT_PIPE")) {
3501 + printk(KERN_CRIT "HSS-%i: unable to stop HDLC flow\n",
3503 + /* The upper level would ignore the error anyway */
3506 + while (queue_get_desc(queue_ids[port->id].rxfree, port, 0) >= 0)
3508 + while (queue_get_desc(queue_ids[port->id].rx, port, 0) >= 0)
3512 + printk(KERN_CRIT "%s: unable to drain RX queue, %i buffer(s)"
3513 + " left in NPE\n", dev->name, buffs);
3516 + while (queue_get_desc(queue_ids[port->id].tx, port, 1) >= 0)
3517 + buffs--; /* cancel TX */
3521 + while (queue_get_desc(port->plat->txreadyq, port, 1) >= 0)
3525 + } while (++i < MAX_CLOSE_WAIT);
3528 + printk(KERN_CRIT "%s: unable to drain TX queue, %i buffer(s) "
3529 + "left in NPE\n", dev->name, buffs);
3532 + printk(KERN_DEBUG "Draining TX queues took %i cycles\n", i);
3534 + qmgr_disable_irq(queue_ids[port->id].txdone);
3535 + destroy_hdlc_queues(port);
3536 + release_hdlc_queues(port);
3538 + if (port->plat->close)
3539 + port->plat->close(port->id, port->netdev);
3545 +static int hss_hdlc_attach(struct net_device *dev, unsigned short encoding,
3546 + unsigned short parity)
3548 + struct port *port = dev_to_port(dev);
3550 + if (encoding != ENCODING_NRZ)
3554 + case PARITY_CRC16_PR1_CCITT:
3555 + port->hdlc_cfg = 0;
3558 + case PARITY_CRC32_PR1_CCITT:
3559 + port->hdlc_cfg = PKT_HDLC_CRC_32;
3568 +static int hss_hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
3570 + const size_t size = sizeof(sync_serial_settings);
3571 + sync_serial_settings new_line;
3573 + sync_serial_settings __user *line = ifr->ifr_settings.ifs_ifsu.sync;
3574 + struct port *port = dev_to_port(dev);
3576 + if (cmd != SIOCWANDEV)
3577 + return hdlc_ioctl(dev, ifr, cmd);
3579 + switch(ifr->ifr_settings.type) {
3580 + case IF_GET_IFACE:
3581 + ifr->ifr_settings.type = IF_IFACE_V35;
3582 + if (ifr->ifr_settings.size < size) {
3583 + ifr->ifr_settings.size = size; /* data size wanted */
3586 + memset(&new_line, 0, sizeof(new_line));
3587 + new_line.clock_type = port->clock_type;
3588 + new_line.clock_rate = port->clock_rate;
3589 + new_line.loopback = port->loopback;
3590 + if (copy_to_user(line, &new_line, size))
3594 + case IF_IFACE_SYNC_SERIAL:
3595 + case IF_IFACE_V35:
3596 + if(!capable(CAP_NET_ADMIN))
3598 + if (dev->flags & IFF_UP)
3599 + return -EBUSY; /* Cannot change parameters when open */
3601 + if (copy_from_user(&new_line, line, size))
3604 + clk = new_line.clock_type;
3605 + if (port->plat->set_clock)
3606 + clk = port->plat->set_clock(port->id, clk);
3608 + if (clk != CLOCK_EXT && clk != CLOCK_INT)
3609 + return -EINVAL; /* No such clock setting */
3611 + if (new_line.loopback != 0 && new_line.loopback != 1)
3614 + port->clock_type = clk; /* Update settings */
3615 + port->clock_rate = new_line.clock_rate;
3616 + port->loopback = new_line.loopback;
3620 + return hdlc_ioctl(dev, ifr, cmd);
3625 +static int __devinit hss_init_one(struct platform_device *pdev)
3627 + struct port *port;
3628 + struct net_device *dev;
3629 + hdlc_device *hdlc;
3632 + if ((port = kzalloc(sizeof(*port), GFP_KERNEL)) == NULL)
3634 + platform_set_drvdata(pdev, port);
3635 + port->id = pdev->id;
3637 + if ((port->npe = npe_request(0)) == NULL) {
3642 + port->plat = pdev->dev.platform_data;
3643 + if ((port->netdev = dev = alloc_hdlcdev(port)) == NULL) {
3648 + SET_MODULE_OWNER(net);
3649 + SET_NETDEV_DEV(dev, &pdev->dev);
3650 + hdlc = dev_to_hdlc(dev);
3651 + hdlc->attach = hss_hdlc_attach;
3652 + hdlc->xmit = hss_hdlc_xmit;
3653 + dev->open = hss_hdlc_open;
3654 + dev->poll = hss_hdlc_poll;
3655 + dev->stop = hss_hdlc_close;
3656 + dev->do_ioctl = hss_hdlc_ioctl;
3658 + dev->tx_queue_len = 100;
3659 + port->clock_type = CLOCK_EXT;
3660 + port->clock_rate = 2048000;
3662 + if (register_hdlc_device(dev)) {
3663 + printk(KERN_ERR "HSS-%i: unable to register HDLC device\n",
3666 + goto err_free_netdev;
3668 + printk(KERN_INFO "%s: HSS-%i\n", dev->name, port->id);
3674 + npe_release(port->npe);
3675 + platform_set_drvdata(pdev, NULL);
3681 +static int __devexit hss_remove_one(struct platform_device *pdev)
3683 + struct port *port = platform_get_drvdata(pdev);
3685 + unregister_hdlc_device(port->netdev);
3686 + free_netdev(port->netdev);
3687 + npe_release(port->npe);
3688 + platform_set_drvdata(pdev, NULL);
3693 +static struct platform_driver drv = {
3694 + .driver.name = DRV_NAME,
3695 + .probe = hss_init_one,
3696 + .remove = hss_remove_one,
3699 +static int __init hss_init_module(void)
3701 + if ((ixp4xx_read_feature_bits() &
3702 + (IXP4XX_FEATURE_HDLC | IXP4XX_FEATURE_HSS)) !=
3703 + (IXP4XX_FEATURE_HDLC | IXP4XX_FEATURE_HSS))
3705 + return platform_driver_register(&drv);
3708 +static void __exit hss_cleanup_module(void)
3710 + platform_driver_unregister(&drv);
3713 +MODULE_AUTHOR("Krzysztof Halasa");
3714 +MODULE_DESCRIPTION("Intel IXP4xx HSS driver");
3715 +MODULE_LICENSE("GPL v2");
3716 +module_init(hss_init_module);
3717 +module_exit(hss_cleanup_module);
3718 Index: linux-2.6.23.17/include/asm-arm/arch-ixp4xx/cpu.h
3719 ===================================================================
3720 --- linux-2.6.23.17.orig/include/asm-arm/arch-ixp4xx/cpu.h
3721 +++ linux-2.6.23.17/include/asm-arm/arch-ixp4xx/cpu.h
3722 @@ -28,4 +28,19 @@ extern unsigned int processor_id;
3723 #define cpu_is_ixp46x() ((processor_id & IXP4XX_PROCESSOR_ID_MASK) == \
3724 IXP465_PROCESSOR_ID_VALUE)
3726 +static inline u32 ixp4xx_read_feature_bits(void)
3728 + unsigned int val = ~*IXP4XX_EXP_CFG2;
3729 + val &= ~IXP4XX_FEATURE_RESERVED;
3730 + if (!cpu_is_ixp46x())
3731 + val &= ~IXP4XX_FEATURE_IXP46X_ONLY;
3736 +static inline void ixp4xx_write_feature_bits(u32 value)
3738 + *IXP4XX_EXP_CFG2 = ~value;
3741 #endif /* _ASM_ARCH_CPU_H */
3742 Index: linux-2.6.23.17/include/asm-arm/arch-ixp4xx/hardware.h
3743 ===================================================================
3744 --- linux-2.6.23.17.orig/include/asm-arm/arch-ixp4xx/hardware.h
3745 +++ linux-2.6.23.17/include/asm-arm/arch-ixp4xx/hardware.h
3748 #define pcibios_assign_all_busses() 1
3750 +/* Register locations and bits */
3751 +#include "ixp4xx-regs.h"
3753 #ifndef __ASSEMBLER__
3754 #include <asm/arch/cpu.h>
3757 -/* Register locations and bits */
3758 -#include "ixp4xx-regs.h"
3760 /* Platform helper functions and definitions */
3761 #include "platform.h"
3763 Index: linux-2.6.23.17/include/asm-arm/arch-ixp4xx/ixp4xx-regs.h
3764 ===================================================================
3765 --- linux-2.6.23.17.orig/include/asm-arm/arch-ixp4xx/ixp4xx-regs.h
3766 +++ linux-2.6.23.17/include/asm-arm/arch-ixp4xx/ixp4xx-regs.h
3771 -#ifndef __ASM_ARCH_HARDWARE_H__
3772 -#error "Do not include this directly, instead #include <asm/hardware.h>"
3775 #ifndef _ASM_ARM_IXP4XX_H_
3776 #define _ASM_ARM_IXP4XX_H_
3778 @@ -607,4 +603,36 @@
3780 #define DCMD_LENGTH 0x01fff /* length mask (max = 8K - 1) */
3782 +/* "fuse" bits of IXP_EXP_CFG2 */
3783 +#define IXP4XX_FEATURE_RCOMP (1 << 0)
3784 +#define IXP4XX_FEATURE_USB_DEVICE (1 << 1)
3785 +#define IXP4XX_FEATURE_HASH (1 << 2)
3786 +#define IXP4XX_FEATURE_AES (1 << 3)
3787 +#define IXP4XX_FEATURE_DES (1 << 4)
3788 +#define IXP4XX_FEATURE_HDLC (1 << 5)
3789 +#define IXP4XX_FEATURE_AAL (1 << 6)
3790 +#define IXP4XX_FEATURE_HSS (1 << 7)
3791 +#define IXP4XX_FEATURE_UTOPIA (1 << 8)
3792 +#define IXP4XX_FEATURE_NPEB_ETH0 (1 << 9)
3793 +#define IXP4XX_FEATURE_NPEC_ETH (1 << 10)
3794 +#define IXP4XX_FEATURE_RESET_NPEA (1 << 11)
3795 +#define IXP4XX_FEATURE_RESET_NPEB (1 << 12)
3796 +#define IXP4XX_FEATURE_RESET_NPEC (1 << 13)
3797 +#define IXP4XX_FEATURE_PCI (1 << 14)
3798 +#define IXP4XX_FEATURE_ECC_TIMESYNC (1 << 15)
3799 +#define IXP4XX_FEATURE_UTOPIA_PHY_LIMIT (3 << 16)
3800 +#define IXP4XX_FEATURE_USB_HOST (1 << 18)
3801 +#define IXP4XX_FEATURE_NPEA_ETH (1 << 19)
3802 +#define IXP4XX_FEATURE_NPEB_ETH_1_TO_3 (1 << 20)
3803 +#define IXP4XX_FEATURE_RSA (1 << 21)
3804 +#define IXP4XX_FEATURE_XSCALE_MAX_FREQ (3 << 22)
3805 +#define IXP4XX_FEATURE_RESERVED (0xFF << 24)
3807 +#define IXP4XX_FEATURE_IXP46X_ONLY (IXP4XX_FEATURE_ECC_TIMESYNC | \
3808 + IXP4XX_FEATURE_USB_HOST | \
3809 + IXP4XX_FEATURE_NPEA_ETH | \
3810 + IXP4XX_FEATURE_NPEB_ETH_1_TO_3 | \
3811 + IXP4XX_FEATURE_RSA | \
3812 + IXP4XX_FEATURE_XSCALE_MAX_FREQ)
3815 Index: linux-2.6.23.17/include/asm-arm/arch-ixp4xx/npe.h
3816 ===================================================================
3818 +++ linux-2.6.23.17/include/asm-arm/arch-ixp4xx/npe.h
3820 +#ifndef __IXP4XX_NPE_H
3821 +#define __IXP4XX_NPE_H
3823 +#include <linux/kernel.h>
3825 +extern const char *npe_names[];
3828 + u32 exec_addr, exec_data, exec_status_cmd, exec_count;
3829 + u32 action_points[4];
3830 + u32 watchpoint_fifo, watch_count;
3831 + u32 profile_count;
3832 + u32 messaging_status, messaging_control;
3833 + u32 mailbox_status, /*messaging_*/ in_out_fifo;
3837 + struct resource *mem_res;
3838 + struct npe_regs __iomem *regs;
3845 +static inline const char *npe_name(struct npe *npe)
3847 + return npe_names[npe->id];
3850 +int npe_running(struct npe *npe);
3851 +int npe_send_message(struct npe *npe, const void *msg, const char *what);
3852 +int npe_recv_message(struct npe *npe, void *msg, const char *what);
3853 +int npe_send_recv_message(struct npe *npe, void *msg, const char *what);
3854 +int npe_load_firmware(struct npe *npe, const char *name, struct device *dev);
3855 +struct npe *npe_request(int id);
3856 +void npe_release(struct npe *npe);
3858 +#endif /* __IXP4XX_NPE_H */
3859 Index: linux-2.6.23.17/include/asm-arm/arch-ixp4xx/platform.h
3860 ===================================================================
3861 --- linux-2.6.23.17.orig/include/asm-arm/arch-ixp4xx/platform.h
3862 +++ linux-2.6.23.17/include/asm-arm/arch-ixp4xx/platform.h
3863 @@ -77,8 +77,7 @@ extern unsigned long ixp4xx_exp_bus_size
3866 * The IXP4xx chips do not have an I2C unit, so GPIO lines are just
3868 - * Used as platform_data to provide GPIO pin information to the ixp42x
3869 + * used as platform_data to provide GPIO pin information to the ixp42x
3872 struct ixp4xx_i2c_pins {
3873 @@ -86,6 +85,27 @@ struct ixp4xx_i2c_pins {
3874 unsigned long scl_pin;
3877 +#define IXP4XX_ETH_NPEA 0x00
3878 +#define IXP4XX_ETH_NPEB 0x10
3879 +#define IXP4XX_ETH_NPEC 0x20
3881 +/* Information about built-in Ethernet MAC interfaces */
3882 +struct eth_plat_info {
3883 + u8 phy; /* MII PHY ID, 0 - 31 */
3884 + u8 rxq; /* configurable, currently 0 - 31 only */
3889 +/* Information about built-in HSS (synchronous serial) interfaces */
3890 +struct hss_plat_info {
3891 + int (*set_clock)(int port, unsigned int clock_type);
3892 + int (*open)(int port, void *pdev,
3893 + void (*set_carrier_cb)(void *pdev, int carrier));
3894 + void (*close)(int port, void *pdev);
3899 * This structure provide a means for the board setup code
3900 * to give information to th pata_ixp4xx driver. It is
3901 Index: linux-2.6.23.17/include/asm-arm/arch-ixp4xx/qmgr.h
3902 ===================================================================
3904 +++ linux-2.6.23.17/include/asm-arm/arch-ixp4xx/qmgr.h
3907 + * Copyright (C) 2007 Krzysztof Halasa <khc@pm.waw.pl>
3909 + * This program is free software; you can redistribute it and/or modify it
3910 + * under the terms of version 2 of the GNU General Public License
3911 + * as published by the Free Software Foundation.
3914 +#ifndef IXP4XX_QMGR_H
3915 +#define IXP4XX_QMGR_H
3917 +#include <linux/io.h>
3918 +#include <linux/kernel.h>
3920 +#define HALF_QUEUES 32
3921 +#define QUEUES 64 /* only 32 lower queues currently supported */
3922 +#define MAX_QUEUE_LENGTH 4 /* in dwords */
3924 +#define QUEUE_STAT1_EMPTY 1 /* queue status bits */
3925 +#define QUEUE_STAT1_NEARLY_EMPTY 2
3926 +#define QUEUE_STAT1_NEARLY_FULL 4
3927 +#define QUEUE_STAT1_FULL 8
3928 +#define QUEUE_STAT2_UNDERFLOW 1
3929 +#define QUEUE_STAT2_OVERFLOW 2
3931 +#define QUEUE_WATERMARK_0_ENTRIES 0
3932 +#define QUEUE_WATERMARK_1_ENTRY 1
3933 +#define QUEUE_WATERMARK_2_ENTRIES 2
3934 +#define QUEUE_WATERMARK_4_ENTRIES 3
3935 +#define QUEUE_WATERMARK_8_ENTRIES 4
3936 +#define QUEUE_WATERMARK_16_ENTRIES 5
3937 +#define QUEUE_WATERMARK_32_ENTRIES 6
3938 +#define QUEUE_WATERMARK_64_ENTRIES 7
3940 +/* queue interrupt request conditions */
3941 +#define QUEUE_IRQ_SRC_EMPTY 0
3942 +#define QUEUE_IRQ_SRC_NEARLY_EMPTY 1
3943 +#define QUEUE_IRQ_SRC_NEARLY_FULL 2
3944 +#define QUEUE_IRQ_SRC_FULL 3
3945 +#define QUEUE_IRQ_SRC_NOT_EMPTY 4
3946 +#define QUEUE_IRQ_SRC_NOT_NEARLY_EMPTY 5
3947 +#define QUEUE_IRQ_SRC_NOT_NEARLY_FULL 6
3948 +#define QUEUE_IRQ_SRC_NOT_FULL 7
3951 + u32 acc[QUEUES][MAX_QUEUE_LENGTH]; /* 0x000 - 0x3FF */
3952 + u32 stat1[4]; /* 0x400 - 0x40F */
3953 + u32 stat2[2]; /* 0x410 - 0x417 */
3954 + u32 statne_h; /* 0x418 - queue nearly empty */
3955 + u32 statf_h; /* 0x41C - queue full */
3956 + u32 irqsrc[4]; /* 0x420 - 0x42F IRC source */
3957 + u32 irqen[2]; /* 0x430 - 0x437 IRQ enabled */
3958 + u32 irqstat[2]; /* 0x438 - 0x43F - IRQ access only */
3959 + u32 reserved[1776];
3960 + u32 sram[2048]; /* 0x2000 - 0x3FFF - config and buffer */
3963 +void qmgr_set_irq(unsigned int queue, int src,
3964 + void (*handler)(void *pdev), void *pdev);
3965 +void qmgr_enable_irq(unsigned int queue);
3966 +void qmgr_disable_irq(unsigned int queue);
3968 +/* request_ and release_queue() must be called from non-IRQ context */
3969 +int qmgr_request_queue(unsigned int queue, unsigned int len /* dwords */,
3970 + unsigned int nearly_empty_watermark,
3971 + unsigned int nearly_full_watermark);
3972 +void qmgr_release_queue(unsigned int queue);
3975 +static inline void qmgr_put_entry(unsigned int queue, u32 val)
3977 + extern struct qmgr_regs __iomem *qmgr_regs;
3978 + __raw_writel(val, &qmgr_regs->acc[queue][0]);
3981 +static inline u32 qmgr_get_entry(unsigned int queue)
3983 + extern struct qmgr_regs __iomem *qmgr_regs;
3984 + return __raw_readl(&qmgr_regs->acc[queue][0]);
3987 +static inline int qmgr_get_stat1(unsigned int queue)
3989 + extern struct qmgr_regs __iomem *qmgr_regs;
3990 + return (__raw_readl(&qmgr_regs->stat1[queue >> 3])
3991 + >> ((queue & 7) << 2)) & 0xF;
3994 +static inline int qmgr_get_stat2(unsigned int queue)
3996 + extern struct qmgr_regs __iomem *qmgr_regs;
3997 + return (__raw_readl(&qmgr_regs->stat2[queue >> 4])
3998 + >> ((queue & 0xF) << 1)) & 0x3;
4001 +static inline int qmgr_stat_empty(unsigned int queue)
4003 + return !!(qmgr_get_stat1(queue) & QUEUE_STAT1_EMPTY);
4006 +static inline int qmgr_stat_nearly_empty(unsigned int queue)
4008 + return !!(qmgr_get_stat1(queue) & QUEUE_STAT1_NEARLY_EMPTY);
4011 +static inline int qmgr_stat_nearly_full(unsigned int queue)
4013 + return !!(qmgr_get_stat1(queue) & QUEUE_STAT1_NEARLY_FULL);
4016 +static inline int qmgr_stat_full(unsigned int queue)
4018 + return !!(qmgr_get_stat1(queue) & QUEUE_STAT1_FULL);
4021 +static inline int qmgr_stat_underflow(unsigned int queue)
4023 + return !!(qmgr_get_stat2(queue) & QUEUE_STAT2_UNDERFLOW);
4026 +static inline int qmgr_stat_overflow(unsigned int queue)
4028 + return !!(qmgr_get_stat2(queue) & QUEUE_STAT2_OVERFLOW);
4032 Index: linux-2.6.23.17/include/asm-arm/arch-ixp4xx/uncompress.h
4033 ===================================================================
4034 --- linux-2.6.23.17.orig/include/asm-arm/arch-ixp4xx/uncompress.h
4035 +++ linux-2.6.23.17/include/asm-arm/arch-ixp4xx/uncompress.h
4037 #ifndef _ARCH_UNCOMPRESS_H_
4038 #define _ARCH_UNCOMPRESS_H_
4040 -#include <asm/hardware.h>
4041 +#include "ixp4xx-regs.h"
4042 #include <asm/mach-types.h>
4043 #include <linux/serial_reg.h>