2 * Intel IXP4xx Network Processor Engine driver for Linux
4 * Copyright (C) 2007 Krzysztof Halasa <khc@pm.waw.pl>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License
8 * as published by the Free Software Foundation.
10 * The code is based on publicly available information:
11 * - Intel IXP4xx Developer's Manual and other e-papers
12 * - Intel IXP400 Access Library Software (BSD license)
13 * - previous works by Christian Hohnstaedt <chohnstaedt@innominate.com>
17 #include <linux/delay.h>
18 #include <linux/dma-mapping.h>
19 #include <linux/firmware.h>
21 #include <linux/kernel.h>
22 #include <linux/module.h>
29 #define MAX_RETRIES 1000 /* microseconds */
30 #define NPE_42X_DATA_SIZE 0x800 /* in dwords */
31 #define NPE_46X_DATA_SIZE 0x1000
32 #define NPE_A_42X_INSTR_SIZE 0x1000
33 #define NPE_B_AND_C_42X_INSTR_SIZE 0x800
34 #define NPE_46X_INSTR_SIZE 0x1000
35 #define REGS_SIZE 0x1000
37 #define NPE_PHYS_REG 32
39 #define FW_MAGIC 0xFEEDF00D
40 #define FW_BLOCK_TYPE_INSTR 0x0
41 #define FW_BLOCK_TYPE_DATA 0x1
42 #define FW_BLOCK_TYPE_EOF 0xF
44 /* NPE exec status (read) and command (write) */
45 #define CMD_NPE_STEP 0x01
46 #define CMD_NPE_START 0x02
47 #define CMD_NPE_STOP 0x03
48 #define CMD_NPE_CLR_PIPE 0x04
49 #define CMD_CLR_PROFILE_CNT 0x0C
50 #define CMD_RD_INS_MEM 0x10 /* instruction memory */
51 #define CMD_WR_INS_MEM 0x11
52 #define CMD_RD_DATA_MEM 0x12 /* data memory */
53 #define CMD_WR_DATA_MEM 0x13
54 #define CMD_RD_ECS_REG 0x14 /* exec access register */
55 #define CMD_WR_ECS_REG 0x15
57 #define STAT_RUN 0x80000000
58 #define STAT_STOP 0x40000000
59 #define STAT_CLEAR 0x20000000
60 #define STAT_ECS_K 0x00800000 /* pipeline clean */
62 #define NPE_STEVT 0x1B
63 #define NPE_STARTPC 0x1C
64 #define NPE_REGMAP 0x1E
65 #define NPE_CINDEX 0x1F
67 #define INSTR_WR_REG_SHORT 0x0000C000
68 #define INSTR_WR_REG_BYTE 0x00004000
69 #define INSTR_RD_FIFO 0x0F888220
70 #define INSTR_RESET_MBOX 0x0FAC8210
72 #define ECS_BG_CTXT_REG_0 0x00 /* Background Executing Context */
73 #define ECS_BG_CTXT_REG_1 0x01 /* Stack level */
74 #define ECS_BG_CTXT_REG_2 0x02
75 #define ECS_PRI_1_CTXT_REG_0 0x04 /* Priority 1 Executing Context */
76 #define ECS_PRI_1_CTXT_REG_1 0x05 /* Stack level */
77 #define ECS_PRI_1_CTXT_REG_2 0x06
78 #define ECS_PRI_2_CTXT_REG_0 0x08 /* Priority 2 Executing Context */
79 #define ECS_PRI_2_CTXT_REG_1 0x09 /* Stack level */
80 #define ECS_PRI_2_CTXT_REG_2 0x0A
81 #define ECS_DBG_CTXT_REG_0 0x0C /* Debug Executing Context */
82 #define ECS_DBG_CTXT_REG_1 0x0D /* Stack level */
83 #define ECS_DBG_CTXT_REG_2 0x0E
84 #define ECS_INSTRUCT_REG 0x11 /* NPE Instruction Register */
86 #define ECS_REG_0_ACTIVE 0x80000000 /* all levels */
87 #define ECS_REG_0_NEXTPC_MASK 0x1FFF0000 /* BG/PRI1/PRI2 levels */
88 #define ECS_REG_0_LDUR_BITS 8
89 #define ECS_REG_0_LDUR_MASK 0x00000700 /* all levels */
90 #define ECS_REG_1_CCTXT_BITS 16
91 #define ECS_REG_1_CCTXT_MASK 0x000F0000 /* all levels */
92 #define ECS_REG_1_SELCTXT_BITS 0
93 #define ECS_REG_1_SELCTXT_MASK 0x0000000F /* all levels */
94 #define ECS_DBG_REG_2_IF 0x00100000 /* debug level */
95 #define ECS_DBG_REG_2_IE 0x00080000 /* debug level */
97 /* NPE watchpoint_fifo register bit */
98 #define WFIFO_VALID 0x80000000
100 /* NPE messaging_status register bit definitions */
101 #define MSGSTAT_OFNE 0x00010000 /* OutFifoNotEmpty */
102 #define MSGSTAT_IFNF 0x00020000 /* InFifoNotFull */
103 #define MSGSTAT_OFNF 0x00040000 /* OutFifoNotFull */
104 #define MSGSTAT_IFNE 0x00080000 /* InFifoNotEmpty */
105 #define MSGSTAT_MBINT 0x00100000 /* Mailbox interrupt */
106 #define MSGSTAT_IFINT 0x00200000 /* InFifo interrupt */
107 #define MSGSTAT_OFINT 0x00400000 /* OutFifo interrupt */
108 #define MSGSTAT_WFINT 0x00800000 /* WatchFifo interrupt */
110 /* NPE messaging_control register bit definitions */
111 #define MSGCTL_OUT_FIFO 0x00010000 /* enable output FIFO */
112 #define MSGCTL_IN_FIFO 0x00020000 /* enable input FIFO */
113 #define MSGCTL_OUT_FIFO_WRITE 0x01000000 /* enable FIFO + WRITE */
114 #define MSGCTL_IN_FIFO_WRITE 0x02000000
116 /* NPE mailbox_status value for reset */
117 #define RESET_MBOX_STAT 0x0000F0F0
119 const char *npe_names
[] = { "NPE-A", "NPE-B", "NPE-C" };
121 #define print_npe(pri, npe, fmt, ...) \
122 printk(pri "%s: " fmt, npe_name(npe), ## __VA_ARGS__)
125 #define debug_msg(npe, fmt, ...) \
126 print_npe(KERN_DEBUG, npe, fmt, ## __VA_ARGS__)
128 #define debug_msg(npe, fmt, ...)
134 { ECS_BG_CTXT_REG_0
, 0xA0000000 },
135 { ECS_BG_CTXT_REG_1
, 0x01000000 },
136 { ECS_BG_CTXT_REG_2
, 0x00008000 },
137 { ECS_PRI_1_CTXT_REG_0
, 0x20000080 },
138 { ECS_PRI_1_CTXT_REG_1
, 0x01000000 },
139 { ECS_PRI_1_CTXT_REG_2
, 0x00008000 },
140 { ECS_PRI_2_CTXT_REG_0
, 0x20000080 },
141 { ECS_PRI_2_CTXT_REG_1
, 0x01000000 },
142 { ECS_PRI_2_CTXT_REG_2
, 0x00008000 },
143 { ECS_DBG_CTXT_REG_0
, 0x20000000 },
144 { ECS_DBG_CTXT_REG_1
, 0x00000000 },
145 { ECS_DBG_CTXT_REG_2
, 0x001E0000 },
146 { ECS_INSTRUCT_REG
, 0x1003C00F },
149 static struct npe npe_tab
[NPE_COUNT
] = {
152 .regs
= (struct npe_regs __iomem
*)IXP4XX_NPEA_BASE_VIRT
,
153 .regs_phys
= IXP4XX_NPEA_BASE_PHYS
,
156 .regs
= (struct npe_regs __iomem
*)IXP4XX_NPEB_BASE_VIRT
,
157 .regs_phys
= IXP4XX_NPEB_BASE_PHYS
,
160 .regs
= (struct npe_regs __iomem
*)IXP4XX_NPEC_BASE_VIRT
,
161 .regs_phys
= IXP4XX_NPEC_BASE_PHYS
,
165 int npe_running(struct npe
*npe
)
167 return (__raw_readl(&npe
->regs
->exec_status_cmd
) & STAT_RUN
) != 0;
170 static void npe_cmd_write(struct npe
*npe
, u32 addr
, int cmd
, u32 data
)
172 __raw_writel(data
, &npe
->regs
->exec_data
);
173 __raw_writel(addr
, &npe
->regs
->exec_addr
);
174 __raw_writel(cmd
, &npe
->regs
->exec_status_cmd
);
177 static u32
npe_cmd_read(struct npe
*npe
, u32 addr
, int cmd
)
179 __raw_writel(addr
, &npe
->regs
->exec_addr
);
180 __raw_writel(cmd
, &npe
->regs
->exec_status_cmd
);
181 /* Iintroduce extra read cycles after issuing read command to NPE
182 so that we read the register after the NPE has updated it.
183 This is to overcome race condition between XScale and NPE */
184 __raw_readl(&npe
->regs
->exec_data
);
185 __raw_readl(&npe
->regs
->exec_data
);
186 return __raw_readl(&npe
->regs
->exec_data
);
189 static void npe_clear_active(struct npe
*npe
, u32 reg
)
191 u32 val
= npe_cmd_read(npe
, reg
, CMD_RD_ECS_REG
);
192 npe_cmd_write(npe
, reg
, CMD_WR_ECS_REG
, val
& ~ECS_REG_0_ACTIVE
);
195 static void npe_start(struct npe
*npe
)
197 /* ensure only Background Context Stack Level is active */
198 npe_clear_active(npe
, ECS_PRI_1_CTXT_REG_0
);
199 npe_clear_active(npe
, ECS_PRI_2_CTXT_REG_0
);
200 npe_clear_active(npe
, ECS_DBG_CTXT_REG_0
);
202 __raw_writel(CMD_NPE_CLR_PIPE
, &npe
->regs
->exec_status_cmd
);
203 __raw_writel(CMD_NPE_START
, &npe
->regs
->exec_status_cmd
);
206 static void npe_stop(struct npe
*npe
)
208 __raw_writel(CMD_NPE_STOP
, &npe
->regs
->exec_status_cmd
);
209 __raw_writel(CMD_NPE_CLR_PIPE
, &npe
->regs
->exec_status_cmd
); /*FIXME?*/
212 static int __must_check
npe_debug_instr(struct npe
*npe
, u32 instr
, u32 ctx
,
218 /* set the Active bit, and the LDUR, in the debug level */
219 npe_cmd_write(npe
, ECS_DBG_CTXT_REG_0
, CMD_WR_ECS_REG
,
220 ECS_REG_0_ACTIVE
| (ldur
<< ECS_REG_0_LDUR_BITS
));
222 /* set CCTXT at ECS DEBUG L3 to specify in which context to execute
223 the instruction, and set SELCTXT at ECS DEBUG Level to specify
224 which context store to access.
225 Debug ECS Level Reg 1 has form 0x000n000n, where n = context number
227 npe_cmd_write(npe
, ECS_DBG_CTXT_REG_1
, CMD_WR_ECS_REG
,
228 (ctx
<< ECS_REG_1_CCTXT_BITS
) |
229 (ctx
<< ECS_REG_1_SELCTXT_BITS
));
231 /* clear the pipeline */
232 __raw_writel(CMD_NPE_CLR_PIPE
, &npe
->regs
->exec_status_cmd
);
234 /* load NPE instruction into the instruction register */
235 npe_cmd_write(npe
, ECS_INSTRUCT_REG
, CMD_WR_ECS_REG
, instr
);
237 /* we need this value later to wait for completion of NPE execution
239 wc
= __raw_readl(&npe
->regs
->watch_count
);
241 /* issue a Step One command via the Execution Control register */
242 __raw_writel(CMD_NPE_STEP
, &npe
->regs
->exec_status_cmd
);
244 /* Watch Count register increments when NPE completes an instruction */
245 for (i
= 0; i
< MAX_RETRIES
; i
++) {
246 if (wc
!= __raw_readl(&npe
->regs
->watch_count
))
251 print_npe(KERN_ERR
, npe
, "reset: npe_debug_instr(): timeout\n");
255 static int __must_check
npe_logical_reg_write8(struct npe
*npe
, u32 addr
,
258 /* here we build the NPE assembler instruction: mov8 d0, #0 */
259 u32 instr
= INSTR_WR_REG_BYTE
| /* OpCode */
260 addr
<< 9 | /* base Operand */
261 (val
& 0x1F) << 4 | /* lower 5 bits to immediate data */
262 (val
& ~0x1F) << (18 - 5);/* higher 3 bits to CoProc instr. */
263 return npe_debug_instr(npe
, instr
, ctx
, 1); /* execute it */
266 static int __must_check
npe_logical_reg_write16(struct npe
*npe
, u32 addr
,
269 /* here we build the NPE assembler instruction: mov16 d0, #0 */
270 u32 instr
= INSTR_WR_REG_SHORT
| /* OpCode */
271 addr
<< 9 | /* base Operand */
272 (val
& 0x1F) << 4 | /* lower 5 bits to immediate data */
273 (val
& ~0x1F) << (18 - 5);/* higher 11 bits to CoProc instr. */
274 return npe_debug_instr(npe
, instr
, ctx
, 1); /* execute it */
277 static int __must_check
npe_logical_reg_write32(struct npe
*npe
, u32 addr
,
280 /* write in 16 bit steps first the high and then the low value */
281 if (npe_logical_reg_write16(npe
, addr
, val
>> 16, ctx
))
283 return npe_logical_reg_write16(npe
, addr
+ 2, val
& 0xFFFF, ctx
);
286 static int npe_reset(struct npe
*npe
)
288 u32 val
, ctl
, exec_count
, ctx_reg2
;
291 ctl
= (__raw_readl(&npe
->regs
->messaging_control
) | 0x3F000000) &
294 /* disable parity interrupt */
295 __raw_writel(ctl
& 0x3F00FFFF, &npe
->regs
->messaging_control
);
297 /* pre exec - debug instruction */
298 /* turn off the halt bit by clearing Execution Count register. */
299 exec_count
= __raw_readl(&npe
->regs
->exec_count
);
300 __raw_writel(0, &npe
->regs
->exec_count
);
301 /* ensure that IF and IE are on (temporarily), so that we don't end up
303 ctx_reg2
= npe_cmd_read(npe
, ECS_DBG_CTXT_REG_2
, CMD_RD_ECS_REG
);
304 npe_cmd_write(npe
, ECS_DBG_CTXT_REG_2
, CMD_WR_ECS_REG
, ctx_reg2
|
305 ECS_DBG_REG_2_IF
| ECS_DBG_REG_2_IE
);
307 /* clear the FIFOs */
308 while (__raw_readl(&npe
->regs
->watchpoint_fifo
) & WFIFO_VALID
)
310 while (__raw_readl(&npe
->regs
->messaging_status
) & MSGSTAT_OFNE
)
311 /* read from the outFIFO until empty */
312 print_npe(KERN_DEBUG
, npe
, "npe_reset: read FIFO = 0x%X\n",
313 __raw_readl(&npe
->regs
->in_out_fifo
));
315 while (__raw_readl(&npe
->regs
->messaging_status
) & MSGSTAT_IFNE
)
316 /* step execution of the NPE intruction to read inFIFO using
317 the Debug Executing Context stack */
318 if (npe_debug_instr(npe
, INSTR_RD_FIFO
, 0, 0))
321 /* reset the mailbox reg from the XScale side */
322 __raw_writel(RESET_MBOX_STAT
, &npe
->regs
->mailbox_status
);
324 if (npe_debug_instr(npe
, INSTR_RESET_MBOX
, 0, 0))
327 /* Reset the physical registers in the NPE register file */
328 for (val
= 0; val
< NPE_PHYS_REG
; val
++) {
329 if (npe_logical_reg_write16(npe
, NPE_REGMAP
, val
>> 1, 0))
331 /* address is either 0 or 4 */
332 if (npe_logical_reg_write32(npe
, (val
& 1) * 4, 0, 0))
336 /* Reset the context store = each context's Context Store registers */
338 /* Context 0 has no STARTPC. Instead, this value is used to set NextPC
339 for Background ECS, to set where NPE starts executing code */
340 val
= npe_cmd_read(npe
, ECS_BG_CTXT_REG_0
, CMD_RD_ECS_REG
);
341 val
&= ~ECS_REG_0_NEXTPC_MASK
;
342 val
|= (0 /* NextPC */ << 16) & ECS_REG_0_NEXTPC_MASK
;
343 npe_cmd_write(npe
, ECS_BG_CTXT_REG_0
, CMD_WR_ECS_REG
, val
);
345 for (i
= 0; i
< 16; i
++) {
346 if (i
) { /* Context 0 has no STEVT nor STARTPC */
347 /* STEVT = off, 0x80 */
348 if (npe_logical_reg_write8(npe
, NPE_STEVT
, 0x80, i
))
350 if (npe_logical_reg_write16(npe
, NPE_STARTPC
, 0, i
))
353 /* REGMAP = d0->p0, d8->p2, d16->p4 */
354 if (npe_logical_reg_write16(npe
, NPE_REGMAP
, 0x820, i
))
356 if (npe_logical_reg_write8(npe
, NPE_CINDEX
, 0, i
))
361 /* clear active bit in debug level */
362 npe_cmd_write(npe
, ECS_DBG_CTXT_REG_0
, CMD_WR_ECS_REG
, 0);
363 /* clear the pipeline */
364 __raw_writel(CMD_NPE_CLR_PIPE
, &npe
->regs
->exec_status_cmd
);
365 /* restore previous values */
366 __raw_writel(exec_count
, &npe
->regs
->exec_count
);
367 npe_cmd_write(npe
, ECS_DBG_CTXT_REG_2
, CMD_WR_ECS_REG
, ctx_reg2
);
369 /* write reset values to Execution Context Stack registers */
370 for (val
= 0; val
< ARRAY_SIZE(ecs_reset
); val
++)
371 npe_cmd_write(npe
, ecs_reset
[val
].reg
, CMD_WR_ECS_REG
,
374 /* clear the profile counter */
375 __raw_writel(CMD_CLR_PROFILE_CNT
, &npe
->regs
->exec_status_cmd
);
377 __raw_writel(0, &npe
->regs
->exec_count
);
378 __raw_writel(0, &npe
->regs
->action_points
[0]);
379 __raw_writel(0, &npe
->regs
->action_points
[1]);
380 __raw_writel(0, &npe
->regs
->action_points
[2]);
381 __raw_writel(0, &npe
->regs
->action_points
[3]);
382 __raw_writel(0, &npe
->regs
->watch_count
);
384 val
= ixp4xx_read_feature_bits();
386 ixp4xx_write_feature_bits(val
&
387 ~(IXP4XX_FEATURE_RESET_NPEA
<< npe
->id
));
389 ixp4xx_write_feature_bits(val
|
390 (IXP4XX_FEATURE_RESET_NPEA
<< npe
->id
));
391 for (i
= 0; i
< MAX_RETRIES
; i
++) {
392 if (ixp4xx_read_feature_bits() &
393 (IXP4XX_FEATURE_RESET_NPEA
<< npe
->id
))
394 break; /* NPE is back alive */
397 if (i
== MAX_RETRIES
)
402 /* restore NPE configuration bus Control Register - parity settings */
403 __raw_writel(ctl
, &npe
->regs
->messaging_control
);
408 int npe_send_message(struct npe
*npe
, const void *msg
, const char *what
)
410 const u32
*send
= msg
;
413 debug_msg(npe
, "Trying to send message %s [%08X:%08X]\n",
414 what
, send
[0], send
[1]);
416 if (__raw_readl(&npe
->regs
->messaging_status
) & MSGSTAT_IFNE
) {
417 debug_msg(npe
, "NPE input FIFO not empty\n");
421 __raw_writel(send
[0], &npe
->regs
->in_out_fifo
);
423 if (!(__raw_readl(&npe
->regs
->messaging_status
) & MSGSTAT_IFNF
)) {
424 debug_msg(npe
, "NPE input FIFO full\n");
428 __raw_writel(send
[1], &npe
->regs
->in_out_fifo
);
430 while ((cycles
< MAX_RETRIES
) &&
431 (__raw_readl(&npe
->regs
->messaging_status
) & MSGSTAT_IFNE
)) {
436 if (cycles
== MAX_RETRIES
) {
437 debug_msg(npe
, "Timeout sending message\n");
442 debug_msg(npe
, "Sending a message took %i cycles\n", cycles
);
447 int npe_recv_message(struct npe
*npe
, void *msg
, const char *what
)
450 int cycles
= 0, cnt
= 0;
452 debug_msg(npe
, "Trying to receive message %s\n", what
);
454 while (cycles
< MAX_RETRIES
) {
455 if (__raw_readl(&npe
->regs
->messaging_status
) & MSGSTAT_OFNE
) {
456 recv
[cnt
++] = __raw_readl(&npe
->regs
->in_out_fifo
);
467 debug_msg(npe
, "Received [%08X]\n", recv
[0]);
470 debug_msg(npe
, "Received [%08X:%08X]\n", recv
[0], recv
[1]);
474 if (cycles
== MAX_RETRIES
) {
475 debug_msg(npe
, "Timeout waiting for message\n");
480 debug_msg(npe
, "Receiving a message took %i cycles\n", cycles
);
485 int npe_send_recv_message(struct npe
*npe
, void *msg
, const char *what
)
488 u32
*send
= msg
, recv
[2];
490 if ((result
= npe_send_message(npe
, msg
, what
)) != 0)
492 if ((result
= npe_recv_message(npe
, recv
, what
)) != 0)
495 if ((recv
[0] != send
[0]) || (recv
[1] != send
[1])) {
496 debug_msg(npe
, "Message %s: unexpected message received\n",
504 int npe_load_firmware(struct npe
*npe
, const char *name
, struct device
*dev
)
506 const struct firmware
*fw_entry
;
519 struct dl_block blocks
[0];
523 struct dl_codeblock
{
529 int i
, j
, err
, data_size
, instr_size
, blocks
, table_end
;
532 if ((err
= request_firmware(&fw_entry
, name
, dev
)) != 0)
536 if (fw_entry
->size
< sizeof(struct dl_image
)) {
537 print_npe(KERN_ERR
, npe
, "incomplete firmware file\n");
540 image
= (struct dl_image
*)fw_entry
->data
;
543 print_npe(KERN_DEBUG
, npe
, "firmware: %08X %08X %08X (0x%X bytes)\n",
544 image
->magic
, image
->id
, image
->size
, image
->size
* 4);
547 if (image
->magic
== swab32(FW_MAGIC
)) { /* swapped file */
548 image
->id
= swab32(image
->id
);
549 image
->size
= swab32(image
->size
);
550 } else if (image
->magic
!= FW_MAGIC
) {
551 print_npe(KERN_ERR
, npe
, "bad firmware file magic: 0x%X\n",
555 if ((image
->size
* 4 + sizeof(struct dl_image
)) != fw_entry
->size
) {
556 print_npe(KERN_ERR
, npe
,
557 "inconsistent size of firmware file\n");
560 if (((image
->id
>> 24) & 0xF /* NPE ID */) != npe
->id
) {
561 print_npe(KERN_ERR
, npe
, "firmware file NPE ID mismatch\n");
564 if (image
->magic
== swab32(FW_MAGIC
))
565 for (i
= 0; i
< image
->size
; i
++)
566 image
->data
[i
] = swab32(image
->data
[i
]);
568 if (cpu_is_ixp42x() && ((image
->id
>> 28) & 0xF /* device ID */)) {
569 print_npe(KERN_INFO
, npe
, "IXP43x/IXP46x firmware ignored on "
574 if (npe_running(npe
)) {
575 print_npe(KERN_INFO
, npe
, "unable to load firmware, NPE is "
576 "already running\n");
585 print_npe(KERN_INFO
, npe
, "firmware functionality 0x%X, "
586 "revision 0x%X:%X\n", (image
->id
>> 16) & 0xFF,
587 (image
->id
>> 8) & 0xFF, image
->id
& 0xFF);
589 if (cpu_is_ixp42x()) {
591 instr_size
= NPE_A_42X_INSTR_SIZE
;
593 instr_size
= NPE_B_AND_C_42X_INSTR_SIZE
;
594 data_size
= NPE_42X_DATA_SIZE
;
596 instr_size
= NPE_46X_INSTR_SIZE
;
597 data_size
= NPE_46X_DATA_SIZE
;
600 for (blocks
= 0; blocks
* sizeof(struct dl_block
) / 4 < image
->size
;
602 if (image
->blocks
[blocks
].type
== FW_BLOCK_TYPE_EOF
)
604 if (blocks
* sizeof(struct dl_block
) / 4 >= image
->size
) {
605 print_npe(KERN_INFO
, npe
, "firmware EOF block marker not "
611 print_npe(KERN_DEBUG
, npe
, "%i firmware blocks found\n", blocks
);
614 table_end
= blocks
* sizeof(struct dl_block
) / 4 + 1 /* EOF marker */;
615 for (i
= 0, blk
= image
->blocks
; i
< blocks
; i
++, blk
++) {
616 if (blk
->offset
> image
->size
- sizeof(struct dl_codeblock
) / 4
617 || blk
->offset
< table_end
) {
618 print_npe(KERN_INFO
, npe
, "invalid offset 0x%X of "
619 "firmware block #%i\n", blk
->offset
, i
);
623 cb
= (struct dl_codeblock
*)&image
->data
[blk
->offset
];
624 if (blk
->type
== FW_BLOCK_TYPE_INSTR
) {
625 if (cb
->npe_addr
+ cb
->size
> instr_size
)
627 cmd
= CMD_WR_INS_MEM
;
628 } else if (blk
->type
== FW_BLOCK_TYPE_DATA
) {
629 if (cb
->npe_addr
+ cb
->size
> data_size
)
631 cmd
= CMD_WR_DATA_MEM
;
633 print_npe(KERN_INFO
, npe
, "invalid firmware block #%i "
634 "type 0x%X\n", i
, blk
->type
);
637 if (blk
->offset
+ sizeof(*cb
) / 4 + cb
->size
> image
->size
) {
638 print_npe(KERN_INFO
, npe
, "firmware block #%i doesn't "
639 "fit in firmware image: type %c, start 0x%X,"
641 blk
->type
== FW_BLOCK_TYPE_INSTR
? 'I' : 'D',
642 cb
->npe_addr
, cb
->size
);
646 for (j
= 0; j
< cb
->size
; j
++)
647 npe_cmd_write(npe
, cb
->npe_addr
+ j
, cmd
, cb
->data
[j
]);
651 if (!npe_running(npe
))
652 print_npe(KERN_ERR
, npe
, "unable to start\n");
653 release_firmware(fw_entry
);
657 print_npe(KERN_INFO
, npe
, "firmware block #%i doesn't fit in NPE "
658 "memory: type %c, start 0x%X, length 0x%X\n", i
,
659 blk
->type
== FW_BLOCK_TYPE_INSTR
? 'I' : 'D',
660 cb
->npe_addr
, cb
->size
);
662 release_firmware(fw_entry
);
667 struct npe
*npe_request(unsigned id
)
670 if (npe_tab
[id
].valid
)
671 if (try_module_get(THIS_MODULE
))
676 void npe_release(struct npe
*npe
)
678 module_put(THIS_MODULE
);
682 static int __init
npe_init_module(void)
687 for (i
= 0; i
< NPE_COUNT
; i
++) {
688 struct npe
*npe
= &npe_tab
[i
];
689 if (!(ixp4xx_read_feature_bits() &
690 (IXP4XX_FEATURE_RESET_NPEA
<< i
)))
691 continue; /* NPE already disabled or not present */
692 if (!(npe
->mem_res
= request_mem_region(npe
->regs_phys
,
695 print_npe(KERN_ERR
, npe
,
696 "failed to request memory region\n");
711 static void __exit
npe_cleanup_module(void)
715 for (i
= 0; i
< NPE_COUNT
; i
++)
716 if (npe_tab
[i
].mem_res
) {
717 npe_reset(&npe_tab
[i
]);
718 release_resource(npe_tab
[i
].mem_res
);
722 module_init(npe_init_module
);
723 module_exit(npe_cleanup_module
);
725 MODULE_AUTHOR("Krzysztof Halasa");
726 MODULE_LICENSE("GPL v2");
728 EXPORT_SYMBOL(npe_names
);
729 EXPORT_SYMBOL(npe_running
);
730 EXPORT_SYMBOL(npe_request
);
731 EXPORT_SYMBOL(npe_release
);
732 EXPORT_SYMBOL(npe_load_firmware
);
733 EXPORT_SYMBOL(npe_send_message
);
734 EXPORT_SYMBOL(npe_recv_message
);
735 EXPORT_SYMBOL(npe_send_recv_message
);