1 // SPDX-License-Identifier: GPL-2.0-only
3 * Intel IXP4xx Network Processor Engine driver for Linux
5 * Copyright (C) 2007 Krzysztof Halasa <khc@pm.waw.pl>
7 * The code is based on publicly available information:
8 * - Intel IXP4xx Developer's Manual and other e-papers
9 * - Intel IXP400 Access Library Software (BSD license)
10 * - previous works by Christian Hohnstaedt <chohnstaedt@innominate.com>
14 #include <linux/delay.h>
15 #include <linux/dma-mapping.h>
16 #include <linux/firmware.h>
18 #include <linux/kernel.h>
19 #include <linux/module.h>
21 #include <linux/platform_device.h>
22 #include <linux/soc/ixp4xx/npe.h>
28 #define MAX_RETRIES 1000 /* microseconds */
29 #define NPE_42X_DATA_SIZE 0x800 /* in dwords */
30 #define NPE_46X_DATA_SIZE 0x1000
31 #define NPE_A_42X_INSTR_SIZE 0x1000
32 #define NPE_B_AND_C_42X_INSTR_SIZE 0x800
33 #define NPE_46X_INSTR_SIZE 0x1000
34 #define REGS_SIZE 0x1000
36 #define NPE_PHYS_REG 32
38 #define FW_MAGIC 0xFEEDF00D
39 #define FW_BLOCK_TYPE_INSTR 0x0
40 #define FW_BLOCK_TYPE_DATA 0x1
41 #define FW_BLOCK_TYPE_EOF 0xF
43 /* NPE exec status (read) and command (write) */
44 #define CMD_NPE_STEP 0x01
45 #define CMD_NPE_START 0x02
46 #define CMD_NPE_STOP 0x03
47 #define CMD_NPE_CLR_PIPE 0x04
48 #define CMD_CLR_PROFILE_CNT 0x0C
49 #define CMD_RD_INS_MEM 0x10 /* instruction memory */
50 #define CMD_WR_INS_MEM 0x11
51 #define CMD_RD_DATA_MEM 0x12 /* data memory */
52 #define CMD_WR_DATA_MEM 0x13
53 #define CMD_RD_ECS_REG 0x14 /* exec access register */
54 #define CMD_WR_ECS_REG 0x15
56 #define STAT_RUN 0x80000000
57 #define STAT_STOP 0x40000000
58 #define STAT_CLEAR 0x20000000
59 #define STAT_ECS_K 0x00800000 /* pipeline clean */
61 #define NPE_STEVT 0x1B
62 #define NPE_STARTPC 0x1C
63 #define NPE_REGMAP 0x1E
64 #define NPE_CINDEX 0x1F
66 #define INSTR_WR_REG_SHORT 0x0000C000
67 #define INSTR_WR_REG_BYTE 0x00004000
68 #define INSTR_RD_FIFO 0x0F888220
69 #define INSTR_RESET_MBOX 0x0FAC8210
71 #define ECS_BG_CTXT_REG_0 0x00 /* Background Executing Context */
72 #define ECS_BG_CTXT_REG_1 0x01 /* Stack level */
73 #define ECS_BG_CTXT_REG_2 0x02
74 #define ECS_PRI_1_CTXT_REG_0 0x04 /* Priority 1 Executing Context */
75 #define ECS_PRI_1_CTXT_REG_1 0x05 /* Stack level */
76 #define ECS_PRI_1_CTXT_REG_2 0x06
77 #define ECS_PRI_2_CTXT_REG_0 0x08 /* Priority 2 Executing Context */
78 #define ECS_PRI_2_CTXT_REG_1 0x09 /* Stack level */
79 #define ECS_PRI_2_CTXT_REG_2 0x0A
80 #define ECS_DBG_CTXT_REG_0 0x0C /* Debug Executing Context */
81 #define ECS_DBG_CTXT_REG_1 0x0D /* Stack level */
82 #define ECS_DBG_CTXT_REG_2 0x0E
83 #define ECS_INSTRUCT_REG 0x11 /* NPE Instruction Register */
85 #define ECS_REG_0_ACTIVE 0x80000000 /* all levels */
86 #define ECS_REG_0_NEXTPC_MASK 0x1FFF0000 /* BG/PRI1/PRI2 levels */
87 #define ECS_REG_0_LDUR_BITS 8
88 #define ECS_REG_0_LDUR_MASK 0x00000700 /* all levels */
89 #define ECS_REG_1_CCTXT_BITS 16
90 #define ECS_REG_1_CCTXT_MASK 0x000F0000 /* all levels */
91 #define ECS_REG_1_SELCTXT_BITS 0
92 #define ECS_REG_1_SELCTXT_MASK 0x0000000F /* all levels */
93 #define ECS_DBG_REG_2_IF 0x00100000 /* debug level */
94 #define ECS_DBG_REG_2_IE 0x00080000 /* debug level */
96 /* NPE watchpoint_fifo register bit */
97 #define WFIFO_VALID 0x80000000
99 /* NPE messaging_status register bit definitions */
100 #define MSGSTAT_OFNE 0x00010000 /* OutFifoNotEmpty */
101 #define MSGSTAT_IFNF 0x00020000 /* InFifoNotFull */
102 #define MSGSTAT_OFNF 0x00040000 /* OutFifoNotFull */
103 #define MSGSTAT_IFNE 0x00080000 /* InFifoNotEmpty */
104 #define MSGSTAT_MBINT 0x00100000 /* Mailbox interrupt */
105 #define MSGSTAT_IFINT 0x00200000 /* InFifo interrupt */
106 #define MSGSTAT_OFINT 0x00400000 /* OutFifo interrupt */
107 #define MSGSTAT_WFINT 0x00800000 /* WatchFifo interrupt */
109 /* NPE messaging_control register bit definitions */
110 #define MSGCTL_OUT_FIFO 0x00010000 /* enable output FIFO */
111 #define MSGCTL_IN_FIFO 0x00020000 /* enable input FIFO */
112 #define MSGCTL_OUT_FIFO_WRITE 0x01000000 /* enable FIFO + WRITE */
113 #define MSGCTL_IN_FIFO_WRITE 0x02000000
115 /* NPE mailbox_status value for reset */
116 #define RESET_MBOX_STAT 0x0000F0F0
118 #define NPE_A_FIRMWARE "NPE-A"
119 #define NPE_B_FIRMWARE "NPE-B"
120 #define NPE_C_FIRMWARE "NPE-C"
122 const char *npe_names[] = { NPE_A_FIRMWARE, NPE_B_FIRMWARE, NPE_C_FIRMWARE };
124 #define print_npe(pri, npe, fmt, ...) \
125 printk(pri "%s: " fmt, npe_name(npe), ## __VA_ARGS__)
128 #define debug_msg(npe, fmt, ...) \
129 print_npe(KERN_DEBUG, npe, fmt, ## __VA_ARGS__)
131 #define debug_msg(npe, fmt, ...)
137 { ECS_BG_CTXT_REG_0, 0xA0000000 },
138 { ECS_BG_CTXT_REG_1, 0x01000000 },
139 { ECS_BG_CTXT_REG_2, 0x00008000 },
140 { ECS_PRI_1_CTXT_REG_0, 0x20000080 },
141 { ECS_PRI_1_CTXT_REG_1, 0x01000000 },
142 { ECS_PRI_1_CTXT_REG_2, 0x00008000 },
143 { ECS_PRI_2_CTXT_REG_0, 0x20000080 },
144 { ECS_PRI_2_CTXT_REG_1, 0x01000000 },
145 { ECS_PRI_2_CTXT_REG_2, 0x00008000 },
146 { ECS_DBG_CTXT_REG_0, 0x20000000 },
147 { ECS_DBG_CTXT_REG_1, 0x00000000 },
148 { ECS_DBG_CTXT_REG_2, 0x001E0000 },
149 { ECS_INSTRUCT_REG, 0x1003C00F },
152 static struct npe npe_tab[NPE_COUNT] = {
162 int npe_running(struct npe *npe)
164 return (__raw_readl(&npe->regs->exec_status_cmd) & STAT_RUN) != 0;
167 static void npe_cmd_write(struct npe *npe, u32 addr, int cmd, u32 data)
169 __raw_writel(data, &npe->regs->exec_data);
170 __raw_writel(addr, &npe->regs->exec_addr);
171 __raw_writel(cmd, &npe->regs->exec_status_cmd);
174 static u32 npe_cmd_read(struct npe *npe, u32 addr, int cmd)
176 __raw_writel(addr, &npe->regs->exec_addr);
177 __raw_writel(cmd, &npe->regs->exec_status_cmd);
178 /* Iintroduce extra read cycles after issuing read command to NPE
179 so that we read the register after the NPE has updated it.
180 This is to overcome race condition between XScale and NPE */
181 __raw_readl(&npe->regs->exec_data);
182 __raw_readl(&npe->regs->exec_data);
183 return __raw_readl(&npe->regs->exec_data);
186 static void npe_clear_active(struct npe *npe, u32 reg)
188 u32 val = npe_cmd_read(npe, reg, CMD_RD_ECS_REG);
189 npe_cmd_write(npe, reg, CMD_WR_ECS_REG, val & ~ECS_REG_0_ACTIVE);
192 static void npe_start(struct npe *npe)
194 /* ensure only Background Context Stack Level is active */
195 npe_clear_active(npe, ECS_PRI_1_CTXT_REG_0);
196 npe_clear_active(npe, ECS_PRI_2_CTXT_REG_0);
197 npe_clear_active(npe, ECS_DBG_CTXT_REG_0);
199 __raw_writel(CMD_NPE_CLR_PIPE, &npe->regs->exec_status_cmd);
200 __raw_writel(CMD_NPE_START, &npe->regs->exec_status_cmd);
203 static void npe_stop(struct npe *npe)
205 __raw_writel(CMD_NPE_STOP, &npe->regs->exec_status_cmd);
206 __raw_writel(CMD_NPE_CLR_PIPE, &npe->regs->exec_status_cmd); /*FIXME?*/
209 static int __must_check npe_debug_instr(struct npe *npe, u32 instr, u32 ctx,
215 /* set the Active bit, and the LDUR, in the debug level */
216 npe_cmd_write(npe, ECS_DBG_CTXT_REG_0, CMD_WR_ECS_REG,
217 ECS_REG_0_ACTIVE | (ldur << ECS_REG_0_LDUR_BITS));
219 /* set CCTXT at ECS DEBUG L3 to specify in which context to execute
220 the instruction, and set SELCTXT at ECS DEBUG Level to specify
221 which context store to access.
222 Debug ECS Level Reg 1 has form 0x000n000n, where n = context number
224 npe_cmd_write(npe, ECS_DBG_CTXT_REG_1, CMD_WR_ECS_REG,
225 (ctx << ECS_REG_1_CCTXT_BITS) |
226 (ctx << ECS_REG_1_SELCTXT_BITS));
228 /* clear the pipeline */
229 __raw_writel(CMD_NPE_CLR_PIPE, &npe->regs->exec_status_cmd);
231 /* load NPE instruction into the instruction register */
232 npe_cmd_write(npe, ECS_INSTRUCT_REG, CMD_WR_ECS_REG, instr);
234 /* we need this value later to wait for completion of NPE execution
236 wc = __raw_readl(&npe->regs->watch_count);
238 /* issue a Step One command via the Execution Control register */
239 __raw_writel(CMD_NPE_STEP, &npe->regs->exec_status_cmd);
241 /* Watch Count register increments when NPE completes an instruction */
242 for (i = 0; i < MAX_RETRIES; i++) {
243 if (wc != __raw_readl(&npe->regs->watch_count))
248 print_npe(KERN_ERR, npe, "reset: npe_debug_instr(): timeout\n");
252 static int __must_check npe_logical_reg_write8(struct npe *npe, u32 addr,
255 /* here we build the NPE assembler instruction: mov8 d0, #0 */
256 u32 instr = INSTR_WR_REG_BYTE | /* OpCode */
257 addr << 9 | /* base Operand */
258 (val & 0x1F) << 4 | /* lower 5 bits to immediate data */
259 (val & ~0x1F) << (18 - 5);/* higher 3 bits to CoProc instr. */
260 return npe_debug_instr(npe, instr, ctx, 1); /* execute it */
263 static int __must_check npe_logical_reg_write16(struct npe *npe, u32 addr,
266 /* here we build the NPE assembler instruction: mov16 d0, #0 */
267 u32 instr = INSTR_WR_REG_SHORT | /* OpCode */
268 addr << 9 | /* base Operand */
269 (val & 0x1F) << 4 | /* lower 5 bits to immediate data */
270 (val & ~0x1F) << (18 - 5);/* higher 11 bits to CoProc instr. */
271 return npe_debug_instr(npe, instr, ctx, 1); /* execute it */
274 static int __must_check npe_logical_reg_write32(struct npe *npe, u32 addr,
277 /* write in 16 bit steps first the high and then the low value */
278 if (npe_logical_reg_write16(npe, addr, val >> 16, ctx))
280 return npe_logical_reg_write16(npe, addr + 2, val & 0xFFFF, ctx);
283 static int npe_reset(struct npe *npe)
285 u32 val, ctl, exec_count, ctx_reg2;
288 ctl = (__raw_readl(&npe->regs->messaging_control) | 0x3F000000) &
291 /* disable parity interrupt */
292 __raw_writel(ctl & 0x3F00FFFF, &npe->regs->messaging_control);
294 /* pre exec - debug instruction */
295 /* turn off the halt bit by clearing Execution Count register. */
296 exec_count = __raw_readl(&npe->regs->exec_count);
297 __raw_writel(0, &npe->regs->exec_count);
298 /* ensure that IF and IE are on (temporarily), so that we don't end up
300 ctx_reg2 = npe_cmd_read(npe, ECS_DBG_CTXT_REG_2, CMD_RD_ECS_REG);
301 npe_cmd_write(npe, ECS_DBG_CTXT_REG_2, CMD_WR_ECS_REG, ctx_reg2 |
302 ECS_DBG_REG_2_IF | ECS_DBG_REG_2_IE);
304 /* clear the FIFOs */
305 while (__raw_readl(&npe->regs->watchpoint_fifo) & WFIFO_VALID)
307 while (__raw_readl(&npe->regs->messaging_status) & MSGSTAT_OFNE)
308 /* read from the outFIFO until empty */
309 print_npe(KERN_DEBUG, npe, "npe_reset: read FIFO = 0x%X\n",
310 __raw_readl(&npe->regs->in_out_fifo));
312 while (__raw_readl(&npe->regs->messaging_status) & MSGSTAT_IFNE)
313 /* step execution of the NPE intruction to read inFIFO using
314 the Debug Executing Context stack */
315 if (npe_debug_instr(npe, INSTR_RD_FIFO, 0, 0))
318 /* reset the mailbox reg from the XScale side */
319 __raw_writel(RESET_MBOX_STAT, &npe->regs->mailbox_status);
321 if (npe_debug_instr(npe, INSTR_RESET_MBOX, 0, 0))
324 /* Reset the physical registers in the NPE register file */
325 for (val = 0; val < NPE_PHYS_REG; val++) {
326 if (npe_logical_reg_write16(npe, NPE_REGMAP, val >> 1, 0))
328 /* address is either 0 or 4 */
329 if (npe_logical_reg_write32(npe, (val & 1) * 4, 0, 0))
333 /* Reset the context store = each context's Context Store registers */
335 /* Context 0 has no STARTPC. Instead, this value is used to set NextPC
336 for Background ECS, to set where NPE starts executing code */
337 val = npe_cmd_read(npe, ECS_BG_CTXT_REG_0, CMD_RD_ECS_REG);
338 val &= ~ECS_REG_0_NEXTPC_MASK;
339 val |= (0 /* NextPC */ << 16) & ECS_REG_0_NEXTPC_MASK;
340 npe_cmd_write(npe, ECS_BG_CTXT_REG_0, CMD_WR_ECS_REG, val);
342 for (i = 0; i < 16; i++) {
343 if (i) { /* Context 0 has no STEVT nor STARTPC */
344 /* STEVT = off, 0x80 */
345 if (npe_logical_reg_write8(npe, NPE_STEVT, 0x80, i))
347 if (npe_logical_reg_write16(npe, NPE_STARTPC, 0, i))
350 /* REGMAP = d0->p0, d8->p2, d16->p4 */
351 if (npe_logical_reg_write16(npe, NPE_REGMAP, 0x820, i))
353 if (npe_logical_reg_write8(npe, NPE_CINDEX, 0, i))
358 /* clear active bit in debug level */
359 npe_cmd_write(npe, ECS_DBG_CTXT_REG_0, CMD_WR_ECS_REG, 0);
360 /* clear the pipeline */
361 __raw_writel(CMD_NPE_CLR_PIPE, &npe->regs->exec_status_cmd);
362 /* restore previous values */
363 __raw_writel(exec_count, &npe->regs->exec_count);
364 npe_cmd_write(npe, ECS_DBG_CTXT_REG_2, CMD_WR_ECS_REG, ctx_reg2);
366 /* write reset values to Execution Context Stack registers */
367 for (val = 0; val < ARRAY_SIZE(ecs_reset); val++)
368 npe_cmd_write(npe, ecs_reset[val].reg, CMD_WR_ECS_REG,
371 /* clear the profile counter */
372 __raw_writel(CMD_CLR_PROFILE_CNT, &npe->regs->exec_status_cmd);
374 __raw_writel(0, &npe->regs->exec_count);
375 __raw_writel(0, &npe->regs->action_points[0]);
376 __raw_writel(0, &npe->regs->action_points[1]);
377 __raw_writel(0, &npe->regs->action_points[2]);
378 __raw_writel(0, &npe->regs->action_points[3]);
379 __raw_writel(0, &npe->regs->watch_count);
381 val = ixp4xx_read_feature_bits();
383 ixp4xx_write_feature_bits(val &
384 ~(IXP4XX_FEATURE_RESET_NPEA << npe->id));
386 ixp4xx_write_feature_bits(val |
387 (IXP4XX_FEATURE_RESET_NPEA << npe->id));
388 for (i = 0; i < MAX_RETRIES; i++) {
389 if (ixp4xx_read_feature_bits() &
390 (IXP4XX_FEATURE_RESET_NPEA << npe->id))
391 break; /* NPE is back alive */
394 if (i == MAX_RETRIES)
399 /* restore NPE configuration bus Control Register - parity settings */
400 __raw_writel(ctl, &npe->regs->messaging_control);
405 int npe_send_message(struct npe *npe, const void *msg, const char *what)
407 const u32 *send = msg;
410 debug_msg(npe, "Trying to send message %s [%08X:%08X]\n",
411 what, send[0], send[1]);
413 if (__raw_readl(&npe->regs->messaging_status) & MSGSTAT_IFNE) {
414 debug_msg(npe, "NPE input FIFO not empty\n");
418 __raw_writel(send[0], &npe->regs->in_out_fifo);
420 if (!(__raw_readl(&npe->regs->messaging_status) & MSGSTAT_IFNF)) {
421 debug_msg(npe, "NPE input FIFO full\n");
425 __raw_writel(send[1], &npe->regs->in_out_fifo);
427 while ((cycles < MAX_RETRIES) &&
428 (__raw_readl(&npe->regs->messaging_status) & MSGSTAT_IFNE)) {
433 if (cycles == MAX_RETRIES) {
434 debug_msg(npe, "Timeout sending message\n");
439 debug_msg(npe, "Sending a message took %i cycles\n", cycles);
444 int npe_recv_message(struct npe *npe, void *msg, const char *what)
447 int cycles = 0, cnt = 0;
449 debug_msg(npe, "Trying to receive message %s\n", what);
451 while (cycles < MAX_RETRIES) {
452 if (__raw_readl(&npe->regs->messaging_status) & MSGSTAT_OFNE) {
453 recv[cnt++] = __raw_readl(&npe->regs->in_out_fifo);
464 debug_msg(npe, "Received [%08X]\n", recv[0]);
467 debug_msg(npe, "Received [%08X:%08X]\n", recv[0], recv[1]);
471 if (cycles == MAX_RETRIES) {
472 debug_msg(npe, "Timeout waiting for message\n");
477 debug_msg(npe, "Receiving a message took %i cycles\n", cycles);
482 int npe_send_recv_message(struct npe *npe, void *msg, const char *what)
485 u32 *send = msg, recv[2];
487 if ((result = npe_send_message(npe, msg, what)) != 0)
489 if ((result = npe_recv_message(npe, recv, what)) != 0)
492 if ((recv[0] != send[0]) || (recv[1] != send[1])) {
493 debug_msg(npe, "Message %s: unexpected message received\n",
501 int npe_load_firmware(struct npe *npe, const char *name, struct device *dev)
503 const struct firmware *fw_entry;
516 struct dl_block blocks[0];
520 struct dl_codeblock {
526 int i, j, err, data_size, instr_size, blocks, table_end;
529 if ((err = reject_firmware(&fw_entry, name, dev)) != 0)
533 if (fw_entry->size < sizeof(struct dl_image)) {
534 print_npe(KERN_ERR, npe, "incomplete firmware file\n");
537 image = (struct dl_image*)fw_entry->data;
540 print_npe(KERN_DEBUG, npe, "firmware: %08X %08X %08X (0x%X bytes)\n",
541 image->magic, image->id, image->size, image->size * 4);
544 if (image->magic == swab32(FW_MAGIC)) { /* swapped file */
545 image->id = swab32(image->id);
546 image->size = swab32(image->size);
547 } else if (image->magic != FW_MAGIC) {
548 print_npe(KERN_ERR, npe, "bad firmware file magic: 0x%X\n",
552 if ((image->size * 4 + sizeof(struct dl_image)) != fw_entry->size) {
553 print_npe(KERN_ERR, npe,
554 "inconsistent size of firmware file\n");
557 if (((image->id >> 24) & 0xF /* NPE ID */) != npe->id) {
558 print_npe(KERN_ERR, npe, "firmware file NPE ID mismatch\n");
561 if (image->magic == swab32(FW_MAGIC))
562 for (i = 0; i < image->size; i++)
563 image->data[i] = swab32(image->data[i]);
565 if (cpu_is_ixp42x() && ((image->id >> 28) & 0xF /* device ID */)) {
566 print_npe(KERN_INFO, npe, "IXP43x/IXP46x firmware ignored on "
571 if (npe_running(npe)) {
572 print_npe(KERN_INFO, npe, "unable to load firmware, NPE is "
573 "already running\n");
582 print_npe(KERN_INFO, npe, "firmware functionality 0x%X, "
583 "revision 0x%X:%X\n", (image->id >> 16) & 0xFF,
584 (image->id >> 8) & 0xFF, image->id & 0xFF);
586 if (cpu_is_ixp42x()) {
588 instr_size = NPE_A_42X_INSTR_SIZE;
590 instr_size = NPE_B_AND_C_42X_INSTR_SIZE;
591 data_size = NPE_42X_DATA_SIZE;
593 instr_size = NPE_46X_INSTR_SIZE;
594 data_size = NPE_46X_DATA_SIZE;
597 for (blocks = 0; blocks * sizeof(struct dl_block) / 4 < image->size;
599 if (image->blocks[blocks].type == FW_BLOCK_TYPE_EOF)
601 if (blocks * sizeof(struct dl_block) / 4 >= image->size) {
602 print_npe(KERN_INFO, npe, "firmware EOF block marker not "
608 print_npe(KERN_DEBUG, npe, "%i firmware blocks found\n", blocks);
611 table_end = blocks * sizeof(struct dl_block) / 4 + 1 /* EOF marker */;
612 for (i = 0, blk = image->blocks; i < blocks; i++, blk++) {
613 if (blk->offset > image->size - sizeof(struct dl_codeblock) / 4
614 || blk->offset < table_end) {
615 print_npe(KERN_INFO, npe, "invalid offset 0x%X of "
616 "firmware block #%i\n", blk->offset, i);
620 cb = (struct dl_codeblock*)&image->data[blk->offset];
621 if (blk->type == FW_BLOCK_TYPE_INSTR) {
622 if (cb->npe_addr + cb->size > instr_size)
624 cmd = CMD_WR_INS_MEM;
625 } else if (blk->type == FW_BLOCK_TYPE_DATA) {
626 if (cb->npe_addr + cb->size > data_size)
628 cmd = CMD_WR_DATA_MEM;
630 print_npe(KERN_INFO, npe, "invalid firmware block #%i "
631 "type 0x%X\n", i, blk->type);
634 if (blk->offset + sizeof(*cb) / 4 + cb->size > image->size) {
635 print_npe(KERN_INFO, npe, "firmware block #%i doesn't "
636 "fit in firmware image: type %c, start 0x%X,"
638 blk->type == FW_BLOCK_TYPE_INSTR ? 'I' : 'D',
639 cb->npe_addr, cb->size);
643 for (j = 0; j < cb->size; j++)
644 npe_cmd_write(npe, cb->npe_addr + j, cmd, cb->data[j]);
648 if (!npe_running(npe))
649 print_npe(KERN_ERR, npe, "unable to start\n");
650 release_firmware(fw_entry);
654 print_npe(KERN_INFO, npe, "firmware block #%i doesn't fit in NPE "
655 "memory: type %c, start 0x%X, length 0x%X\n", i,
656 blk->type == FW_BLOCK_TYPE_INSTR ? 'I' : 'D',
657 cb->npe_addr, cb->size);
659 release_firmware(fw_entry);
664 struct npe *npe_request(unsigned id)
667 if (npe_tab[id].valid)
668 if (try_module_get(THIS_MODULE))
673 void npe_release(struct npe *npe)
675 module_put(THIS_MODULE);
678 static int ixp4xx_npe_probe(struct platform_device *pdev)
681 struct device *dev = &pdev->dev;
682 struct resource *res;
684 for (i = 0; i < NPE_COUNT; i++) {
685 struct npe *npe = &npe_tab[i];
687 res = platform_get_resource(pdev, IORESOURCE_MEM, i);
691 if (!(ixp4xx_read_feature_bits() &
692 (IXP4XX_FEATURE_RESET_NPEA << i))) {
693 dev_info(dev, "NPE%d at %pR not available\n",
695 continue; /* NPE already disabled or not present */
697 npe->regs = devm_ioremap_resource(dev, res);
698 if (IS_ERR(npe->regs))
699 return PTR_ERR(npe->regs);
701 if (npe_reset(npe)) {
702 dev_info(dev, "NPE%d at %pR does not reset\n",
707 dev_info(dev, "NPE%d at %pR registered\n", i, res);
716 static int ixp4xx_npe_remove(struct platform_device *pdev)
720 for (i = 0; i < NPE_COUNT; i++)
721 if (npe_tab[i].regs) {
722 npe_reset(&npe_tab[i]);
728 static const struct of_device_id ixp4xx_npe_of_match[] = {
730 .compatible = "intel,ixp4xx-network-processing-engine",
735 static struct platform_driver ixp4xx_npe_driver = {
737 .name = "ixp4xx-npe",
738 .of_match_table = ixp4xx_npe_of_match,
740 .probe = ixp4xx_npe_probe,
741 .remove = ixp4xx_npe_remove,
743 module_platform_driver(ixp4xx_npe_driver);
745 MODULE_AUTHOR("Krzysztof Halasa");
746 MODULE_LICENSE("GPL v2");
749 EXPORT_SYMBOL(npe_names);
750 EXPORT_SYMBOL(npe_running);
751 EXPORT_SYMBOL(npe_request);
752 EXPORT_SYMBOL(npe_release);
753 EXPORT_SYMBOL(npe_load_firmware);
754 EXPORT_SYMBOL(npe_send_message);
755 EXPORT_SYMBOL(npe_recv_message);
756 EXPORT_SYMBOL(npe_send_recv_message);