2 * Freescale MPC85xx/MPC86xx RapidIO support
4 * Copyright 2009 Integrated Device Technology, Inc.
5 * Alex Bounine <alexandre.bounine@idt.com>
6 * - Added Port-Write message handling
7 * - Added Machine Check exception handling
9 * Copyright (C) 2007, 2008 Freescale Semiconductor, Inc.
10 * Zhang Wei <wei.zhang@freescale.com>
12 * Copyright 2005 MontaVista Software, Inc.
13 * Matt Porter <mporter@kernel.crashing.org>
15 * This program is free software; you can redistribute it and/or modify it
16 * under the terms of the GNU General Public License as published by the
17 * Free Software Foundation; either version 2 of the License, or (at your
18 * option) any later version.
21 #include <linux/init.h>
22 #include <linux/module.h>
23 #include <linux/types.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/interrupt.h>
26 #include <linux/device.h>
27 #include <linux/rio.h>
28 #include <linux/rio_drv.h>
29 #include <linux/of_platform.h>
30 #include <linux/delay.h>
31 #include <linux/slab.h>
32 #include <linux/kfifo.h>
35 #include <asm/machdep.h>
36 #include <asm/uaccess.h>
38 #undef DEBUG_PW /* Port-Write debugging */
40 /* RapidIO definition irq, which read from OF-tree */
41 #define IRQ_RIO_BELL(m) (((struct rio_priv *)(m->priv))->bellirq)
42 #define IRQ_RIO_TX(m) (((struct rio_priv *)(m->priv))->txirq)
43 #define IRQ_RIO_RX(m) (((struct rio_priv *)(m->priv))->rxirq)
44 #define IRQ_RIO_PW(m) (((struct rio_priv *)(m->priv))->pwirq)
46 #define RIO_ATMU_REGS_OFFSET 0x10c00
47 #define RIO_P_MSG_REGS_OFFSET 0x11000
48 #define RIO_S_MSG_REGS_OFFSET 0x13000
49 #define RIO_ESCSR 0x158
50 #define RIO_CCSR 0x15c
51 #define RIO_LTLEDCSR 0x0608
52 #define RIO_LTLEDCSR_IER 0x80000000
53 #define RIO_LTLEDCSR_PRT 0x01000000
54 #define RIO_LTLEECSR 0x060c
55 #define RIO_EPWISR 0x10010
56 #define RIO_ISR_AACR 0x10120
57 #define RIO_ISR_AACR_AA 0x1 /* Accept All ID */
58 #define RIO_MAINT_WIN_SIZE 0x400000
59 #define RIO_DBELL_WIN_SIZE 0x1000
61 #define RIO_MSG_OMR_MUI 0x00000002
62 #define RIO_MSG_OSR_TE 0x00000080
63 #define RIO_MSG_OSR_QOI 0x00000020
64 #define RIO_MSG_OSR_QFI 0x00000010
65 #define RIO_MSG_OSR_MUB 0x00000004
66 #define RIO_MSG_OSR_EOMI 0x00000002
67 #define RIO_MSG_OSR_QEI 0x00000001
69 #define RIO_MSG_IMR_MI 0x00000002
70 #define RIO_MSG_ISR_TE 0x00000080
71 #define RIO_MSG_ISR_QFI 0x00000010
72 #define RIO_MSG_ISR_DIQI 0x00000001
74 #define RIO_IPWMR_SEN 0x00100000
75 #define RIO_IPWMR_QFIE 0x00000100
76 #define RIO_IPWMR_EIE 0x00000020
77 #define RIO_IPWMR_CQ 0x00000002
78 #define RIO_IPWMR_PWE 0x00000001
80 #define RIO_IPWSR_QF 0x00100000
81 #define RIO_IPWSR_TE 0x00000080
82 #define RIO_IPWSR_QFI 0x00000010
83 #define RIO_IPWSR_PWD 0x00000008
84 #define RIO_IPWSR_PWB 0x00000004
86 #define RIO_MSG_DESC_SIZE 32
87 #define RIO_MSG_BUFFER_SIZE 4096
88 #define RIO_MIN_TX_RING_SIZE 2
89 #define RIO_MAX_TX_RING_SIZE 2048
90 #define RIO_MIN_RX_RING_SIZE 2
91 #define RIO_MAX_RX_RING_SIZE 2048
93 #define DOORBELL_DMR_DI 0x00000002
94 #define DOORBELL_DSR_TE 0x00000080
95 #define DOORBELL_DSR_QFI 0x00000010
96 #define DOORBELL_DSR_DIQI 0x00000001
97 #define DOORBELL_TID_OFFSET 0x02
98 #define DOORBELL_SID_OFFSET 0x04
99 #define DOORBELL_INFO_OFFSET 0x06
101 #define DOORBELL_MESSAGE_SIZE 0x08
102 #define DBELL_SID(x) (*(u16 *)(x + DOORBELL_SID_OFFSET))
103 #define DBELL_TID(x) (*(u16 *)(x + DOORBELL_TID_OFFSET))
104 #define DBELL_INF(x) (*(u16 *)(x + DOORBELL_INFO_OFFSET))
106 struct rio_atmu_regs
{
115 struct rio_msg_regs
{
167 struct rio_dbell_ring
{
172 struct rio_msg_tx_ring
{
175 void *virt_buffer
[RIO_MAX_TX_RING_SIZE
];
176 dma_addr_t phys_buffer
[RIO_MAX_TX_RING_SIZE
];
182 struct rio_msg_rx_ring
{
185 void *virt_buffer
[RIO_MAX_RX_RING_SIZE
];
191 struct rio_port_write_msg
{
201 void __iomem
*regs_win
;
202 struct rio_atmu_regs __iomem
*atmu_regs
;
203 struct rio_atmu_regs __iomem
*maint_atmu_regs
;
204 struct rio_atmu_regs __iomem
*dbell_atmu_regs
;
205 void __iomem
*dbell_win
;
206 void __iomem
*maint_win
;
207 struct rio_msg_regs __iomem
*msg_regs
;
208 struct rio_dbell_ring dbell_ring
;
209 struct rio_msg_tx_ring msg_tx_ring
;
210 struct rio_msg_rx_ring msg_rx_ring
;
211 struct rio_port_write_msg port_write_msg
;
216 struct work_struct pw_work
;
217 struct kfifo pw_fifo
;
218 spinlock_t pw_fifo_lock
;
221 #define __fsl_read_rio_config(x, addr, err, op) \
222 __asm__ __volatile__( \
223 "1: "op" %1,0(%2)\n" \
226 ".section .fixup,\"ax\"\n" \
230 ".section __ex_table,\"a\"\n" \
234 : "=r" (err), "=r" (x) \
235 : "b" (addr), "i" (-EFAULT), "0" (err))
237 static void __iomem
*rio_regs_win
;
239 static int (*saved_mcheck_exception
)(struct pt_regs
*regs
);
241 static int fsl_rio_mcheck_exception(struct pt_regs
*regs
)
243 const struct exception_table_entry
*entry
= NULL
;
244 unsigned long reason
= (mfspr(SPRN_MCSR
) & MCSR_MASK
);
246 if (reason
& MCSR_BUS_RBERR
) {
247 reason
= in_be32((u32
*)(rio_regs_win
+ RIO_LTLEDCSR
));
248 if (reason
& (RIO_LTLEDCSR_IER
| RIO_LTLEDCSR_PRT
)) {
249 /* Check if we are prepared to handle this fault */
250 entry
= search_exception_tables(regs
->nip
);
252 pr_debug("RIO: %s - MC Exception handled\n",
254 out_be32((u32
*)(rio_regs_win
+ RIO_LTLEDCSR
),
257 regs
->nip
= entry
->fixup
;
263 if (saved_mcheck_exception
)
264 return saved_mcheck_exception(regs
);
266 return cur_cpu_spec
->machine_check(regs
);
270 * fsl_rio_doorbell_send - Send a MPC85xx doorbell message
271 * @mport: RapidIO master port info
272 * @index: ID of RapidIO interface
273 * @destid: Destination ID of target device
274 * @data: 16-bit info field of RapidIO doorbell message
276 * Sends a MPC85xx doorbell message. Returns %0 on success or
277 * %-EINVAL on failure.
279 static int fsl_rio_doorbell_send(struct rio_mport
*mport
,
280 int index
, u16 destid
, u16 data
)
282 struct rio_priv
*priv
= mport
->priv
;
283 pr_debug("fsl_doorbell_send: index %d destid %4.4x data %4.4x\n",
284 index
, destid
, data
);
285 switch (mport
->phy_type
) {
286 case RIO_PHY_PARALLEL
:
287 out_be32(&priv
->dbell_atmu_regs
->rowtar
, destid
<< 22);
288 out_be16(priv
->dbell_win
, data
);
291 /* In the serial version silicons, such as MPC8548, MPC8641,
292 * below operations is must be.
294 out_be32(&priv
->msg_regs
->odmr
, 0x00000000);
295 out_be32(&priv
->msg_regs
->odretcr
, 0x00000004);
296 out_be32(&priv
->msg_regs
->oddpr
, destid
<< 16);
297 out_be32(&priv
->msg_regs
->oddatr
, data
);
298 out_be32(&priv
->msg_regs
->odmr
, 0x00000001);
306 * fsl_local_config_read - Generate a MPC85xx local config space read
307 * @mport: RapidIO master port info
308 * @index: ID of RapdiIO interface
309 * @offset: Offset into configuration space
310 * @len: Length (in bytes) of the maintenance transaction
311 * @data: Value to be read into
313 * Generates a MPC85xx local configuration space read. Returns %0 on
314 * success or %-EINVAL on failure.
316 static int fsl_local_config_read(struct rio_mport
*mport
,
317 int index
, u32 offset
, int len
, u32
*data
)
319 struct rio_priv
*priv
= mport
->priv
;
320 pr_debug("fsl_local_config_read: index %d offset %8.8x\n", index
,
322 *data
= in_be32(priv
->regs_win
+ offset
);
328 * fsl_local_config_write - Generate a MPC85xx local config space write
329 * @mport: RapidIO master port info
330 * @index: ID of RapdiIO interface
331 * @offset: Offset into configuration space
332 * @len: Length (in bytes) of the maintenance transaction
333 * @data: Value to be written
335 * Generates a MPC85xx local configuration space write. Returns %0 on
336 * success or %-EINVAL on failure.
338 static int fsl_local_config_write(struct rio_mport
*mport
,
339 int index
, u32 offset
, int len
, u32 data
)
341 struct rio_priv
*priv
= mport
->priv
;
343 ("fsl_local_config_write: index %d offset %8.8x data %8.8x\n",
344 index
, offset
, data
);
345 out_be32(priv
->regs_win
+ offset
, data
);
351 * fsl_rio_config_read - Generate a MPC85xx read maintenance transaction
352 * @mport: RapidIO master port info
353 * @index: ID of RapdiIO interface
354 * @destid: Destination ID of transaction
355 * @hopcount: Number of hops to target device
356 * @offset: Offset into configuration space
357 * @len: Length (in bytes) of the maintenance transaction
358 * @val: Location to be read into
360 * Generates a MPC85xx read maintenance transaction. Returns %0 on
361 * success or %-EINVAL on failure.
364 fsl_rio_config_read(struct rio_mport
*mport
, int index
, u16 destid
,
365 u8 hopcount
, u32 offset
, int len
, u32
*val
)
367 struct rio_priv
*priv
= mport
->priv
;
372 ("fsl_rio_config_read: index %d destid %d hopcount %d offset %8.8x len %d\n",
373 index
, destid
, hopcount
, offset
, len
);
374 out_be32(&priv
->maint_atmu_regs
->rowtar
,
375 (destid
<< 22) | (hopcount
<< 12) | ((offset
& ~0x3) >> 9));
377 data
= (u8
*) priv
->maint_win
+ offset
;
380 __fsl_read_rio_config(rval
, data
, err
, "lbz");
383 __fsl_read_rio_config(rval
, data
, err
, "lhz");
386 __fsl_read_rio_config(rval
, data
, err
, "lwz");
391 pr_debug("RIO: cfg_read error %d for %x:%x:%x\n",
392 err
, destid
, hopcount
, offset
);
401 * fsl_rio_config_write - Generate a MPC85xx write maintenance transaction
402 * @mport: RapidIO master port info
403 * @index: ID of RapdiIO interface
404 * @destid: Destination ID of transaction
405 * @hopcount: Number of hops to target device
406 * @offset: Offset into configuration space
407 * @len: Length (in bytes) of the maintenance transaction
408 * @val: Value to be written
410 * Generates an MPC85xx write maintenance transaction. Returns %0 on
411 * success or %-EINVAL on failure.
414 fsl_rio_config_write(struct rio_mport
*mport
, int index
, u16 destid
,
415 u8 hopcount
, u32 offset
, int len
, u32 val
)
417 struct rio_priv
*priv
= mport
->priv
;
420 ("fsl_rio_config_write: index %d destid %d hopcount %d offset %8.8x len %d val %8.8x\n",
421 index
, destid
, hopcount
, offset
, len
, val
);
422 out_be32(&priv
->maint_atmu_regs
->rowtar
,
423 (destid
<< 22) | (hopcount
<< 12) | ((offset
& ~0x3) >> 9));
425 data
= (u8
*) priv
->maint_win
+ offset
;
428 out_8((u8
*) data
, val
);
431 out_be16((u16
*) data
, val
);
434 out_be32((u32
*) data
, val
);
442 * rio_hw_add_outb_message - Add message to the MPC85xx outbound message queue
443 * @mport: Master port with outbound message queue
444 * @rdev: Target of outbound message
445 * @mbox: Outbound mailbox
446 * @buffer: Message to add to outbound queue
447 * @len: Length of message
449 * Adds the @buffer message to the MPC85xx outbound message queue. Returns
450 * %0 on success or %-EINVAL on failure.
453 rio_hw_add_outb_message(struct rio_mport
*mport
, struct rio_dev
*rdev
, int mbox
,
454 void *buffer
, size_t len
)
456 struct rio_priv
*priv
= mport
->priv
;
458 struct rio_tx_desc
*desc
= (struct rio_tx_desc
*)priv
->msg_tx_ring
.virt
459 + priv
->msg_tx_ring
.tx_slot
;
463 ("RIO: rio_hw_add_outb_message(): destid %4.4x mbox %d buffer %8.8x len %8.8x\n",
464 rdev
->destid
, mbox
, (int)buffer
, len
);
466 if ((len
< 8) || (len
> RIO_MAX_MSG_SIZE
)) {
471 /* Copy and clear rest of buffer */
472 memcpy(priv
->msg_tx_ring
.virt_buffer
[priv
->msg_tx_ring
.tx_slot
], buffer
,
474 if (len
< (RIO_MAX_MSG_SIZE
- 4))
475 memset(priv
->msg_tx_ring
.virt_buffer
[priv
->msg_tx_ring
.tx_slot
]
476 + len
, 0, RIO_MAX_MSG_SIZE
- len
);
478 switch (mport
->phy_type
) {
479 case RIO_PHY_PARALLEL
:
480 /* Set mbox field for message */
481 desc
->dport
= mbox
& 0x3;
483 /* Enable EOMI interrupt, set priority, and set destid */
484 desc
->dattr
= 0x28000000 | (rdev
->destid
<< 2);
487 /* Set mbox field for message, and set destid */
488 desc
->dport
= (rdev
->destid
<< 16) | (mbox
& 0x3);
490 /* Enable EOMI interrupt and priority */
491 desc
->dattr
= 0x28000000;
495 /* Set transfer size aligned to next power of 2 (in double words) */
496 desc
->dwcnt
= is_power_of_2(len
) ? len
: 1 << get_bitmask_order(len
);
498 /* Set snooping and source buffer address */
499 desc
->saddr
= 0x00000004
500 | priv
->msg_tx_ring
.phys_buffer
[priv
->msg_tx_ring
.tx_slot
];
502 /* Increment enqueue pointer */
503 omr
= in_be32(&priv
->msg_regs
->omr
);
504 out_be32(&priv
->msg_regs
->omr
, omr
| RIO_MSG_OMR_MUI
);
506 /* Go to next descriptor */
507 if (++priv
->msg_tx_ring
.tx_slot
== priv
->msg_tx_ring
.size
)
508 priv
->msg_tx_ring
.tx_slot
= 0;
514 EXPORT_SYMBOL_GPL(rio_hw_add_outb_message
);
517 * fsl_rio_tx_handler - MPC85xx outbound message interrupt handler
518 * @irq: Linux interrupt number
519 * @dev_instance: Pointer to interrupt-specific data
521 * Handles outbound message interrupts. Executes a register outbound
522 * mailbox event handler and acks the interrupt occurrence.
525 fsl_rio_tx_handler(int irq
, void *dev_instance
)
528 struct rio_mport
*port
= (struct rio_mport
*)dev_instance
;
529 struct rio_priv
*priv
= port
->priv
;
531 osr
= in_be32(&priv
->msg_regs
->osr
);
533 if (osr
& RIO_MSG_OSR_TE
) {
534 pr_info("RIO: outbound message transmission error\n");
535 out_be32(&priv
->msg_regs
->osr
, RIO_MSG_OSR_TE
);
539 if (osr
& RIO_MSG_OSR_QOI
) {
540 pr_info("RIO: outbound message queue overflow\n");
541 out_be32(&priv
->msg_regs
->osr
, RIO_MSG_OSR_QOI
);
545 if (osr
& RIO_MSG_OSR_EOMI
) {
546 u32 dqp
= in_be32(&priv
->msg_regs
->odqdpar
);
547 int slot
= (dqp
- priv
->msg_tx_ring
.phys
) >> 5;
548 port
->outb_msg
[0].mcback(port
, priv
->msg_tx_ring
.dev_id
, -1,
551 /* Ack the end-of-message interrupt */
552 out_be32(&priv
->msg_regs
->osr
, RIO_MSG_OSR_EOMI
);
560 * rio_open_outb_mbox - Initialize MPC85xx outbound mailbox
561 * @mport: Master port implementing the outbound message unit
562 * @dev_id: Device specific pointer to pass on event
563 * @mbox: Mailbox to open
564 * @entries: Number of entries in the outbound mailbox ring
566 * Initializes buffer ring, request the outbound message interrupt,
567 * and enables the outbound message unit. Returns %0 on success and
568 * %-EINVAL or %-ENOMEM on failure.
570 int rio_open_outb_mbox(struct rio_mport
*mport
, void *dev_id
, int mbox
, int entries
)
573 struct rio_priv
*priv
= mport
->priv
;
575 if ((entries
< RIO_MIN_TX_RING_SIZE
) ||
576 (entries
> RIO_MAX_TX_RING_SIZE
) || (!is_power_of_2(entries
))) {
581 /* Initialize shadow copy ring */
582 priv
->msg_tx_ring
.dev_id
= dev_id
;
583 priv
->msg_tx_ring
.size
= entries
;
585 for (i
= 0; i
< priv
->msg_tx_ring
.size
; i
++) {
586 priv
->msg_tx_ring
.virt_buffer
[i
] =
587 dma_alloc_coherent(priv
->dev
, RIO_MSG_BUFFER_SIZE
,
588 &priv
->msg_tx_ring
.phys_buffer
[i
], GFP_KERNEL
);
589 if (!priv
->msg_tx_ring
.virt_buffer
[i
]) {
591 for (j
= 0; j
< priv
->msg_tx_ring
.size
; j
++)
592 if (priv
->msg_tx_ring
.virt_buffer
[j
])
593 dma_free_coherent(priv
->dev
,
603 /* Initialize outbound message descriptor ring */
604 priv
->msg_tx_ring
.virt
= dma_alloc_coherent(priv
->dev
,
605 priv
->msg_tx_ring
.size
* RIO_MSG_DESC_SIZE
,
606 &priv
->msg_tx_ring
.phys
, GFP_KERNEL
);
607 if (!priv
->msg_tx_ring
.virt
) {
611 memset(priv
->msg_tx_ring
.virt
, 0,
612 priv
->msg_tx_ring
.size
* RIO_MSG_DESC_SIZE
);
613 priv
->msg_tx_ring
.tx_slot
= 0;
615 /* Point dequeue/enqueue pointers at first entry in ring */
616 out_be32(&priv
->msg_regs
->odqdpar
, priv
->msg_tx_ring
.phys
);
617 out_be32(&priv
->msg_regs
->odqepar
, priv
->msg_tx_ring
.phys
);
619 /* Configure for snooping */
620 out_be32(&priv
->msg_regs
->osar
, 0x00000004);
622 /* Clear interrupt status */
623 out_be32(&priv
->msg_regs
->osr
, 0x000000b3);
625 /* Hook up outbound message handler */
626 rc
= request_irq(IRQ_RIO_TX(mport
), fsl_rio_tx_handler
, 0,
627 "msg_tx", (void *)mport
);
632 * Configure outbound message unit
634 * Interrupts (all enabled, except QEIE)
638 out_be32(&priv
->msg_regs
->omr
, 0x00100220);
640 /* Set number of entries */
641 out_be32(&priv
->msg_regs
->omr
,
642 in_be32(&priv
->msg_regs
->omr
) |
643 ((get_bitmask_order(entries
) - 2) << 12));
645 /* Now enable the unit */
646 out_be32(&priv
->msg_regs
->omr
, in_be32(&priv
->msg_regs
->omr
) | 0x1);
652 dma_free_coherent(priv
->dev
,
653 priv
->msg_tx_ring
.size
* RIO_MSG_DESC_SIZE
,
654 priv
->msg_tx_ring
.virt
, priv
->msg_tx_ring
.phys
);
657 for (i
= 0; i
< priv
->msg_tx_ring
.size
; i
++)
658 dma_free_coherent(priv
->dev
, RIO_MSG_BUFFER_SIZE
,
659 priv
->msg_tx_ring
.virt_buffer
[i
],
660 priv
->msg_tx_ring
.phys_buffer
[i
]);
666 * rio_close_outb_mbox - Shut down MPC85xx outbound mailbox
667 * @mport: Master port implementing the outbound message unit
668 * @mbox: Mailbox to close
670 * Disables the outbound message unit, free all buffers, and
671 * frees the outbound message interrupt.
673 void rio_close_outb_mbox(struct rio_mport
*mport
, int mbox
)
675 struct rio_priv
*priv
= mport
->priv
;
676 /* Disable inbound message unit */
677 out_be32(&priv
->msg_regs
->omr
, 0);
680 dma_free_coherent(priv
->dev
,
681 priv
->msg_tx_ring
.size
* RIO_MSG_DESC_SIZE
,
682 priv
->msg_tx_ring
.virt
, priv
->msg_tx_ring
.phys
);
685 free_irq(IRQ_RIO_TX(mport
), (void *)mport
);
689 * fsl_rio_rx_handler - MPC85xx inbound message interrupt handler
690 * @irq: Linux interrupt number
691 * @dev_instance: Pointer to interrupt-specific data
693 * Handles inbound message interrupts. Executes a registered inbound
694 * mailbox event handler and acks the interrupt occurrence.
697 fsl_rio_rx_handler(int irq
, void *dev_instance
)
700 struct rio_mport
*port
= (struct rio_mport
*)dev_instance
;
701 struct rio_priv
*priv
= port
->priv
;
703 isr
= in_be32(&priv
->msg_regs
->isr
);
705 if (isr
& RIO_MSG_ISR_TE
) {
706 pr_info("RIO: inbound message reception error\n");
707 out_be32((void *)&priv
->msg_regs
->isr
, RIO_MSG_ISR_TE
);
711 /* XXX Need to check/dispatch until queue empty */
712 if (isr
& RIO_MSG_ISR_DIQI
) {
714 * We implement *only* mailbox 0, but can receive messages
715 * for any mailbox/letter to that mailbox destination. So,
716 * make the callback with an unknown/invalid mailbox number
719 port
->inb_msg
[0].mcback(port
, priv
->msg_rx_ring
.dev_id
, -1, -1);
721 /* Ack the queueing interrupt */
722 out_be32(&priv
->msg_regs
->isr
, RIO_MSG_ISR_DIQI
);
730 * rio_open_inb_mbox - Initialize MPC85xx inbound mailbox
731 * @mport: Master port implementing the inbound message unit
732 * @dev_id: Device specific pointer to pass on event
733 * @mbox: Mailbox to open
734 * @entries: Number of entries in the inbound mailbox ring
736 * Initializes buffer ring, request the inbound message interrupt,
737 * and enables the inbound message unit. Returns %0 on success
738 * and %-EINVAL or %-ENOMEM on failure.
740 int rio_open_inb_mbox(struct rio_mport
*mport
, void *dev_id
, int mbox
, int entries
)
743 struct rio_priv
*priv
= mport
->priv
;
745 if ((entries
< RIO_MIN_RX_RING_SIZE
) ||
746 (entries
> RIO_MAX_RX_RING_SIZE
) || (!is_power_of_2(entries
))) {
751 /* Initialize client buffer ring */
752 priv
->msg_rx_ring
.dev_id
= dev_id
;
753 priv
->msg_rx_ring
.size
= entries
;
754 priv
->msg_rx_ring
.rx_slot
= 0;
755 for (i
= 0; i
< priv
->msg_rx_ring
.size
; i
++)
756 priv
->msg_rx_ring
.virt_buffer
[i
] = NULL
;
758 /* Initialize inbound message ring */
759 priv
->msg_rx_ring
.virt
= dma_alloc_coherent(priv
->dev
,
760 priv
->msg_rx_ring
.size
* RIO_MAX_MSG_SIZE
,
761 &priv
->msg_rx_ring
.phys
, GFP_KERNEL
);
762 if (!priv
->msg_rx_ring
.virt
) {
767 /* Point dequeue/enqueue pointers at first entry in ring */
768 out_be32(&priv
->msg_regs
->ifqdpar
, (u32
) priv
->msg_rx_ring
.phys
);
769 out_be32(&priv
->msg_regs
->ifqepar
, (u32
) priv
->msg_rx_ring
.phys
);
771 /* Clear interrupt status */
772 out_be32(&priv
->msg_regs
->isr
, 0x00000091);
774 /* Hook up inbound message handler */
775 rc
= request_irq(IRQ_RIO_RX(mport
), fsl_rio_rx_handler
, 0,
776 "msg_rx", (void *)mport
);
778 dma_free_coherent(priv
->dev
, RIO_MSG_BUFFER_SIZE
,
779 priv
->msg_tx_ring
.virt_buffer
[i
],
780 priv
->msg_tx_ring
.phys_buffer
[i
]);
785 * Configure inbound message unit:
787 * 4KB max message size
788 * Unmask all interrupt sources
791 out_be32(&priv
->msg_regs
->imr
, 0x001b0060);
793 /* Set number of queue entries */
794 setbits32(&priv
->msg_regs
->imr
, (get_bitmask_order(entries
) - 2) << 12);
796 /* Now enable the unit */
797 setbits32(&priv
->msg_regs
->imr
, 0x1);
804 * rio_close_inb_mbox - Shut down MPC85xx inbound mailbox
805 * @mport: Master port implementing the inbound message unit
806 * @mbox: Mailbox to close
808 * Disables the inbound message unit, free all buffers, and
809 * frees the inbound message interrupt.
811 void rio_close_inb_mbox(struct rio_mport
*mport
, int mbox
)
813 struct rio_priv
*priv
= mport
->priv
;
814 /* Disable inbound message unit */
815 out_be32(&priv
->msg_regs
->imr
, 0);
818 dma_free_coherent(priv
->dev
, priv
->msg_rx_ring
.size
* RIO_MAX_MSG_SIZE
,
819 priv
->msg_rx_ring
.virt
, priv
->msg_rx_ring
.phys
);
822 free_irq(IRQ_RIO_RX(mport
), (void *)mport
);
826 * rio_hw_add_inb_buffer - Add buffer to the MPC85xx inbound message queue
827 * @mport: Master port implementing the inbound message unit
828 * @mbox: Inbound mailbox number
829 * @buf: Buffer to add to inbound queue
831 * Adds the @buf buffer to the MPC85xx inbound message queue. Returns
832 * %0 on success or %-EINVAL on failure.
834 int rio_hw_add_inb_buffer(struct rio_mport
*mport
, int mbox
, void *buf
)
837 struct rio_priv
*priv
= mport
->priv
;
839 pr_debug("RIO: rio_hw_add_inb_buffer(), msg_rx_ring.rx_slot %d\n",
840 priv
->msg_rx_ring
.rx_slot
);
842 if (priv
->msg_rx_ring
.virt_buffer
[priv
->msg_rx_ring
.rx_slot
]) {
844 "RIO: error adding inbound buffer %d, buffer exists\n",
845 priv
->msg_rx_ring
.rx_slot
);
850 priv
->msg_rx_ring
.virt_buffer
[priv
->msg_rx_ring
.rx_slot
] = buf
;
851 if (++priv
->msg_rx_ring
.rx_slot
== priv
->msg_rx_ring
.size
)
852 priv
->msg_rx_ring
.rx_slot
= 0;
858 EXPORT_SYMBOL_GPL(rio_hw_add_inb_buffer
);
861 * rio_hw_get_inb_message - Fetch inbound message from the MPC85xx message unit
862 * @mport: Master port implementing the inbound message unit
863 * @mbox: Inbound mailbox number
865 * Gets the next available inbound message from the inbound message queue.
866 * A pointer to the message is returned on success or NULL on failure.
868 void *rio_hw_get_inb_message(struct rio_mport
*mport
, int mbox
)
870 struct rio_priv
*priv
= mport
->priv
;
871 u32 phys_buf
, virt_buf
;
875 phys_buf
= in_be32(&priv
->msg_regs
->ifqdpar
);
877 /* If no more messages, then bail out */
878 if (phys_buf
== in_be32(&priv
->msg_regs
->ifqepar
))
881 virt_buf
= (u32
) priv
->msg_rx_ring
.virt
+ (phys_buf
882 - priv
->msg_rx_ring
.phys
);
883 buf_idx
= (phys_buf
- priv
->msg_rx_ring
.phys
) / RIO_MAX_MSG_SIZE
;
884 buf
= priv
->msg_rx_ring
.virt_buffer
[buf_idx
];
888 "RIO: inbound message copy failed, no buffers\n");
892 /* Copy max message size, caller is expected to allocate that big */
893 memcpy(buf
, (void *)virt_buf
, RIO_MAX_MSG_SIZE
);
895 /* Clear the available buffer */
896 priv
->msg_rx_ring
.virt_buffer
[buf_idx
] = NULL
;
899 setbits32(&priv
->msg_regs
->imr
, RIO_MSG_IMR_MI
);
905 EXPORT_SYMBOL_GPL(rio_hw_get_inb_message
);
908 * fsl_rio_dbell_handler - MPC85xx doorbell interrupt handler
909 * @irq: Linux interrupt number
910 * @dev_instance: Pointer to interrupt-specific data
912 * Handles doorbell interrupts. Parses a list of registered
913 * doorbell event handlers and executes a matching event handler.
916 fsl_rio_dbell_handler(int irq
, void *dev_instance
)
919 struct rio_mport
*port
= (struct rio_mport
*)dev_instance
;
920 struct rio_priv
*priv
= port
->priv
;
922 dsr
= in_be32(&priv
->msg_regs
->dsr
);
924 if (dsr
& DOORBELL_DSR_TE
) {
925 pr_info("RIO: doorbell reception error\n");
926 out_be32(&priv
->msg_regs
->dsr
, DOORBELL_DSR_TE
);
930 if (dsr
& DOORBELL_DSR_QFI
) {
931 pr_info("RIO: doorbell queue full\n");
932 out_be32(&priv
->msg_regs
->dsr
, DOORBELL_DSR_QFI
);
936 /* XXX Need to check/dispatch until queue empty */
937 if (dsr
& DOORBELL_DSR_DIQI
) {
939 (u32
) priv
->dbell_ring
.virt
+
940 (in_be32(&priv
->msg_regs
->dqdpar
) & 0xfff);
941 struct rio_dbell
*dbell
;
945 ("RIO: processing doorbell, sid %2.2x tid %2.2x info %4.4x\n",
946 DBELL_SID(dmsg
), DBELL_TID(dmsg
), DBELL_INF(dmsg
));
948 list_for_each_entry(dbell
, &port
->dbells
, node
) {
949 if ((dbell
->res
->start
<= DBELL_INF(dmsg
)) &&
950 (dbell
->res
->end
>= DBELL_INF(dmsg
))) {
956 dbell
->dinb(port
, dbell
->dev_id
, DBELL_SID(dmsg
), DBELL_TID(dmsg
),
960 ("RIO: spurious doorbell, sid %2.2x tid %2.2x info %4.4x\n",
961 DBELL_SID(dmsg
), DBELL_TID(dmsg
), DBELL_INF(dmsg
));
963 setbits32(&priv
->msg_regs
->dmr
, DOORBELL_DMR_DI
);
964 out_be32(&priv
->msg_regs
->dsr
, DOORBELL_DSR_DIQI
);
972 * fsl_rio_doorbell_init - MPC85xx doorbell interface init
973 * @mport: Master port implementing the inbound doorbell unit
975 * Initializes doorbell unit hardware and inbound DMA buffer
976 * ring. Called from fsl_rio_setup(). Returns %0 on success
977 * or %-ENOMEM on failure.
979 static int fsl_rio_doorbell_init(struct rio_mport
*mport
)
981 struct rio_priv
*priv
= mport
->priv
;
984 /* Map outbound doorbell window immediately after maintenance window */
985 priv
->dbell_win
= ioremap(mport
->iores
.start
+ RIO_MAINT_WIN_SIZE
,
987 if (!priv
->dbell_win
) {
989 "RIO: unable to map outbound doorbell window\n");
994 /* Initialize inbound doorbells */
995 priv
->dbell_ring
.virt
= dma_alloc_coherent(priv
->dev
, 512 *
996 DOORBELL_MESSAGE_SIZE
, &priv
->dbell_ring
.phys
, GFP_KERNEL
);
997 if (!priv
->dbell_ring
.virt
) {
998 printk(KERN_ERR
"RIO: unable allocate inbound doorbell ring\n");
1000 iounmap(priv
->dbell_win
);
1004 /* Point dequeue/enqueue pointers at first entry in ring */
1005 out_be32(&priv
->msg_regs
->dqdpar
, (u32
) priv
->dbell_ring
.phys
);
1006 out_be32(&priv
->msg_regs
->dqepar
, (u32
) priv
->dbell_ring
.phys
);
1008 /* Clear interrupt status */
1009 out_be32(&priv
->msg_regs
->dsr
, 0x00000091);
1011 /* Hook up doorbell handler */
1012 rc
= request_irq(IRQ_RIO_BELL(mport
), fsl_rio_dbell_handler
, 0,
1013 "dbell_rx", (void *)mport
);
1015 iounmap(priv
->dbell_win
);
1016 dma_free_coherent(priv
->dev
, 512 * DOORBELL_MESSAGE_SIZE
,
1017 priv
->dbell_ring
.virt
, priv
->dbell_ring
.phys
);
1019 "MPC85xx RIO: unable to request inbound doorbell irq");
1023 /* Configure doorbells for snooping, 512 entries, and enable */
1024 out_be32(&priv
->msg_regs
->dmr
, 0x00108161);
1031 * fsl_rio_port_write_handler - MPC85xx port write interrupt handler
1032 * @irq: Linux interrupt number
1033 * @dev_instance: Pointer to interrupt-specific data
1035 * Handles port write interrupts. Parses a list of registered
1036 * port write event handlers and executes a matching event handler.
1039 fsl_rio_port_write_handler(int irq
, void *dev_instance
)
1042 struct rio_mport
*port
= (struct rio_mport
*)dev_instance
;
1043 struct rio_priv
*priv
= port
->priv
;
1046 ipwmr
= in_be32(&priv
->msg_regs
->pwmr
);
1047 ipwsr
= in_be32(&priv
->msg_regs
->pwsr
);
1049 epwisr
= in_be32(priv
->regs_win
+ RIO_EPWISR
);
1050 if (epwisr
& 0x80000000) {
1051 tmp
= in_be32(priv
->regs_win
+ RIO_LTLEDCSR
);
1052 pr_info("RIO_LTLEDCSR = 0x%x\n", tmp
);
1053 out_be32(priv
->regs_win
+ RIO_LTLEDCSR
, 0);
1056 if (!(epwisr
& 0x00000001))
1060 pr_debug("PW Int->IPWMR: 0x%08x IPWSR: 0x%08x (", ipwmr
, ipwsr
);
1061 if (ipwsr
& RIO_IPWSR_QF
)
1063 if (ipwsr
& RIO_IPWSR_TE
)
1065 if (ipwsr
& RIO_IPWSR_QFI
)
1067 if (ipwsr
& RIO_IPWSR_PWD
)
1069 if (ipwsr
& RIO_IPWSR_PWB
)
1073 out_be32(&priv
->msg_regs
->pwsr
,
1074 ipwsr
& (RIO_IPWSR_TE
| RIO_IPWSR_QFI
| RIO_IPWSR_PWD
));
1076 if ((ipwmr
& RIO_IPWMR_EIE
) && (ipwsr
& RIO_IPWSR_TE
)) {
1077 priv
->port_write_msg
.err_count
++;
1078 pr_info("RIO: Port-Write Transaction Err (%d)\n",
1079 priv
->port_write_msg
.err_count
);
1081 if (ipwsr
& RIO_IPWSR_PWD
) {
1082 priv
->port_write_msg
.discard_count
++;
1083 pr_info("RIO: Port Discarded Port-Write Msg(s) (%d)\n",
1084 priv
->port_write_msg
.discard_count
);
1087 /* Schedule deferred processing if PW was received */
1088 if (ipwsr
& RIO_IPWSR_QFI
) {
1089 /* Save PW message (if there is room in FIFO),
1090 * otherwise discard it.
1092 if (kfifo_avail(&priv
->pw_fifo
) >= RIO_PW_MSG_SIZE
) {
1093 priv
->port_write_msg
.msg_count
++;
1094 kfifo_in(&priv
->pw_fifo
, priv
->port_write_msg
.virt
,
1097 priv
->port_write_msg
.discard_count
++;
1098 pr_info("RIO: ISR Discarded Port-Write Msg(s) (%d)\n",
1099 priv
->port_write_msg
.discard_count
);
1101 schedule_work(&priv
->pw_work
);
1104 /* Issue Clear Queue command. This allows another
1105 * port-write to be received.
1107 out_be32(&priv
->msg_regs
->pwmr
, ipwmr
| RIO_IPWMR_CQ
);
1112 static void fsl_pw_dpc(struct work_struct
*work
)
1114 struct rio_priv
*priv
= container_of(work
, struct rio_priv
, pw_work
);
1115 unsigned long flags
;
1116 u32 msg_buffer
[RIO_PW_MSG_SIZE
/sizeof(u32
)];
1119 * Process port-write messages
1121 spin_lock_irqsave(&priv
->pw_fifo_lock
, flags
);
1122 while (kfifo_out(&priv
->pw_fifo
, (unsigned char *)msg_buffer
,
1124 /* Process one message */
1125 spin_unlock_irqrestore(&priv
->pw_fifo_lock
, flags
);
1129 pr_debug("%s : Port-Write Message:", __func__
);
1130 for (i
= 0; i
< RIO_PW_MSG_SIZE
/sizeof(u32
); i
++) {
1132 pr_debug("\n0x%02x: 0x%08x", i
*4,
1135 pr_debug(" 0x%08x", msg_buffer
[i
]);
1140 /* Pass the port-write message to RIO core for processing */
1141 rio_inb_pwrite_handler((union rio_pw_msg
*)msg_buffer
);
1142 spin_lock_irqsave(&priv
->pw_fifo_lock
, flags
);
1144 spin_unlock_irqrestore(&priv
->pw_fifo_lock
, flags
);
1148 * fsl_rio_pw_enable - enable/disable port-write interface init
1149 * @mport: Master port implementing the port write unit
1150 * @enable: 1=enable; 0=disable port-write message handling
1152 static int fsl_rio_pw_enable(struct rio_mport
*mport
, int enable
)
1154 struct rio_priv
*priv
= mport
->priv
;
1157 rval
= in_be32(&priv
->msg_regs
->pwmr
);
1160 rval
|= RIO_IPWMR_PWE
;
1162 rval
&= ~RIO_IPWMR_PWE
;
1164 out_be32(&priv
->msg_regs
->pwmr
, rval
);
1170 * fsl_rio_port_write_init - MPC85xx port write interface init
1171 * @mport: Master port implementing the port write unit
1173 * Initializes port write unit hardware and DMA buffer
1174 * ring. Called from fsl_rio_setup(). Returns %0 on success
1175 * or %-ENOMEM on failure.
1177 static int fsl_rio_port_write_init(struct rio_mport
*mport
)
1179 struct rio_priv
*priv
= mport
->priv
;
1182 /* Following configurations require a disabled port write controller */
1183 out_be32(&priv
->msg_regs
->pwmr
,
1184 in_be32(&priv
->msg_regs
->pwmr
) & ~RIO_IPWMR_PWE
);
1186 /* Initialize port write */
1187 priv
->port_write_msg
.virt
= dma_alloc_coherent(priv
->dev
,
1189 &priv
->port_write_msg
.phys
, GFP_KERNEL
);
1190 if (!priv
->port_write_msg
.virt
) {
1191 pr_err("RIO: unable allocate port write queue\n");
1195 priv
->port_write_msg
.err_count
= 0;
1196 priv
->port_write_msg
.discard_count
= 0;
1198 /* Point dequeue/enqueue pointers at first entry */
1199 out_be32(&priv
->msg_regs
->epwqbar
, 0);
1200 out_be32(&priv
->msg_regs
->pwqbar
, (u32
) priv
->port_write_msg
.phys
);
1202 pr_debug("EIPWQBAR: 0x%08x IPWQBAR: 0x%08x\n",
1203 in_be32(&priv
->msg_regs
->epwqbar
),
1204 in_be32(&priv
->msg_regs
->pwqbar
));
1206 /* Clear interrupt status IPWSR */
1207 out_be32(&priv
->msg_regs
->pwsr
,
1208 (RIO_IPWSR_TE
| RIO_IPWSR_QFI
| RIO_IPWSR_PWD
));
1210 /* Configure port write contoller for snooping enable all reporting,
1212 out_be32(&priv
->msg_regs
->pwmr
,
1213 RIO_IPWMR_SEN
| RIO_IPWMR_QFIE
| RIO_IPWMR_EIE
| RIO_IPWMR_CQ
);
1216 /* Hook up port-write handler */
1217 rc
= request_irq(IRQ_RIO_PW(mport
), fsl_rio_port_write_handler
, 0,
1218 "port-write", (void *)mport
);
1220 pr_err("MPC85xx RIO: unable to request inbound doorbell irq");
1224 INIT_WORK(&priv
->pw_work
, fsl_pw_dpc
);
1225 spin_lock_init(&priv
->pw_fifo_lock
);
1226 if (kfifo_alloc(&priv
->pw_fifo
, RIO_PW_MSG_SIZE
* 32, GFP_KERNEL
)) {
1227 pr_err("FIFO allocation failed\n");
1232 pr_debug("IPWMR: 0x%08x IPWSR: 0x%08x\n",
1233 in_be32(&priv
->msg_regs
->pwmr
),
1234 in_be32(&priv
->msg_regs
->pwsr
));
1239 free_irq(IRQ_RIO_PW(mport
), (void *)mport
);
1241 dma_free_coherent(priv
->dev
, RIO_PW_MSG_SIZE
,
1242 priv
->port_write_msg
.virt
,
1243 priv
->port_write_msg
.phys
);
1247 static char *cmdline
= NULL
;
1249 static int fsl_rio_get_hdid(int index
)
1251 /* XXX Need to parse multiple entries in some format */
1255 return simple_strtol(cmdline
, NULL
, 0);
1258 static int fsl_rio_get_cmdline(char *s
)
1267 __setup("riohdid=", fsl_rio_get_cmdline
);
1269 static inline void fsl_rio_info(struct device
*dev
, u32 ccsr
)
1274 switch (ccsr
>> 30) {
1285 dev_info(dev
, "Hardware port width: %s\n", str
);
1287 switch ((ccsr
>> 27) & 7) {
1289 str
= "Single-lane 0";
1292 str
= "Single-lane 2";
1301 dev_info(dev
, "Training connection status: %s\n", str
);
1304 if (!(ccsr
& 0x80000000))
1305 dev_info(dev
, "Output port operating in 8-bit mode\n");
1306 if (!(ccsr
& 0x08000000))
1307 dev_info(dev
, "Input port operating in 8-bit mode\n");
1312 * fsl_rio_setup - Setup Freescale PowerPC RapidIO interface
1313 * @dev: of_device pointer
1315 * Initializes MPC85xx RapidIO hardware interface, configures
1316 * master port with system-specific info, and registers the
1317 * master port with the RapidIO subsystem.
1319 int fsl_rio_setup(struct of_device
*dev
)
1321 struct rio_ops
*ops
;
1322 struct rio_mport
*port
;
1323 struct rio_priv
*priv
;
1325 const u32
*dt_range
, *cell
;
1326 struct resource regs
;
1329 u64 law_start
, law_size
;
1332 if (!dev
->dev
.of_node
) {
1333 dev_err(&dev
->dev
, "Device OF-Node is NULL");
1337 rc
= of_address_to_resource(dev
->dev
.of_node
, 0, ®s
);
1339 dev_err(&dev
->dev
, "Can't get %s property 'reg'\n",
1340 dev
->dev
.of_node
->full_name
);
1343 dev_info(&dev
->dev
, "Of-device full name %s\n", dev
->dev
.of_node
->full_name
);
1344 dev_info(&dev
->dev
, "Regs: %pR\n", ®s
);
1346 dt_range
= of_get_property(dev
->dev
.of_node
, "ranges", &rlen
);
1348 dev_err(&dev
->dev
, "Can't get %s property 'ranges'\n",
1349 dev
->dev
.of_node
->full_name
);
1353 /* Get node address wide */
1354 cell
= of_get_property(dev
->dev
.of_node
, "#address-cells", NULL
);
1358 aw
= of_n_addr_cells(dev
->dev
.of_node
);
1359 /* Get node size wide */
1360 cell
= of_get_property(dev
->dev
.of_node
, "#size-cells", NULL
);
1364 sw
= of_n_size_cells(dev
->dev
.of_node
);
1365 /* Get parent address wide wide */
1366 paw
= of_n_addr_cells(dev
->dev
.of_node
);
1368 law_start
= of_read_number(dt_range
+ aw
, paw
);
1369 law_size
= of_read_number(dt_range
+ aw
+ paw
, sw
);
1371 dev_info(&dev
->dev
, "LAW start 0x%016llx, size 0x%016llx.\n",
1372 law_start
, law_size
);
1374 ops
= kzalloc(sizeof(struct rio_ops
), GFP_KERNEL
);
1379 ops
->lcread
= fsl_local_config_read
;
1380 ops
->lcwrite
= fsl_local_config_write
;
1381 ops
->cread
= fsl_rio_config_read
;
1382 ops
->cwrite
= fsl_rio_config_write
;
1383 ops
->dsend
= fsl_rio_doorbell_send
;
1384 ops
->pwenable
= fsl_rio_pw_enable
;
1386 port
= kzalloc(sizeof(struct rio_mport
), GFP_KERNEL
);
1394 priv
= kzalloc(sizeof(struct rio_priv
), GFP_KERNEL
);
1396 printk(KERN_ERR
"Can't alloc memory for 'priv'\n");
1401 INIT_LIST_HEAD(&port
->dbells
);
1402 port
->iores
.start
= law_start
;
1403 port
->iores
.end
= law_start
+ law_size
- 1;
1404 port
->iores
.flags
= IORESOURCE_MEM
;
1405 port
->iores
.name
= "rio_io_win";
1407 priv
->pwirq
= irq_of_parse_and_map(dev
->node
, 0);
1408 priv
->bellirq
= irq_of_parse_and_map(dev
->dev
.of_node
, 2);
1409 priv
->txirq
= irq_of_parse_and_map(dev
->dev
.of_node
, 3);
1410 priv
->rxirq
= irq_of_parse_and_map(dev
->dev
.of_node
, 4);
1411 dev_info(&dev
->dev
, "pwirq: %d, bellirq: %d, txirq: %d, rxirq %d\n",
1412 priv
->pwirq
, priv
->bellirq
, priv
->txirq
, priv
->rxirq
);
1414 rio_init_dbell_res(&port
->riores
[RIO_DOORBELL_RESOURCE
], 0, 0xffff);
1415 rio_init_mbox_res(&port
->riores
[RIO_INB_MBOX_RESOURCE
], 0, 0);
1416 rio_init_mbox_res(&port
->riores
[RIO_OUTB_MBOX_RESOURCE
], 0, 0);
1417 strcpy(port
->name
, "RIO0 mport");
1419 priv
->dev
= &dev
->dev
;
1422 port
->host_deviceid
= fsl_rio_get_hdid(port
->id
);
1425 rio_register_mport(port
);
1427 priv
->regs_win
= ioremap(regs
.start
, regs
.end
- regs
.start
+ 1);
1428 rio_regs_win
= priv
->regs_win
;
1430 /* Probe the master port phy type */
1431 ccsr
= in_be32(priv
->regs_win
+ RIO_CCSR
);
1432 port
->phy_type
= (ccsr
& 1) ? RIO_PHY_SERIAL
: RIO_PHY_PARALLEL
;
1433 dev_info(&dev
->dev
, "RapidIO PHY type: %s\n",
1434 (port
->phy_type
== RIO_PHY_PARALLEL
) ? "parallel" :
1435 ((port
->phy_type
== RIO_PHY_SERIAL
) ? "serial" :
1437 /* Checking the port training status */
1438 if (in_be32((priv
->regs_win
+ RIO_ESCSR
)) & 1) {
1439 dev_err(&dev
->dev
, "Port is not ready. "
1440 "Try to restart connection...\n");
1441 switch (port
->phy_type
) {
1442 case RIO_PHY_SERIAL
:
1444 out_be32(priv
->regs_win
+ RIO_CCSR
, 0);
1446 setbits32(priv
->regs_win
+ RIO_CCSR
, 0x02000000);
1448 setbits32(priv
->regs_win
+ RIO_CCSR
, 0x00600000);
1450 case RIO_PHY_PARALLEL
:
1452 out_be32(priv
->regs_win
+ RIO_CCSR
, 0x22000000);
1454 out_be32(priv
->regs_win
+ RIO_CCSR
, 0x44000000);
1458 if (in_be32((priv
->regs_win
+ RIO_ESCSR
)) & 1) {
1459 dev_err(&dev
->dev
, "Port restart failed.\n");
1463 dev_info(&dev
->dev
, "Port restart success!\n");
1465 fsl_rio_info(&dev
->dev
, ccsr
);
1467 port
->sys_size
= (in_be32((priv
->regs_win
+ RIO_PEF_CAR
))
1468 & RIO_PEF_CTLS
) >> 4;
1469 dev_info(&dev
->dev
, "RapidIO Common Transport System size: %d\n",
1470 port
->sys_size
? 65536 : 256);
1472 priv
->atmu_regs
= (struct rio_atmu_regs
*)(priv
->regs_win
1473 + RIO_ATMU_REGS_OFFSET
);
1474 priv
->maint_atmu_regs
= priv
->atmu_regs
+ 1;
1475 priv
->dbell_atmu_regs
= priv
->atmu_regs
+ 2;
1476 priv
->msg_regs
= (struct rio_msg_regs
*)(priv
->regs_win
+
1477 ((port
->phy_type
== RIO_PHY_SERIAL
) ?
1478 RIO_S_MSG_REGS_OFFSET
: RIO_P_MSG_REGS_OFFSET
));
1480 /* Set to receive any dist ID for serial RapidIO controller. */
1481 if (port
->phy_type
== RIO_PHY_SERIAL
)
1482 out_be32((priv
->regs_win
+ RIO_ISR_AACR
), RIO_ISR_AACR_AA
);
1484 /* Configure maintenance transaction window */
1485 out_be32(&priv
->maint_atmu_regs
->rowbar
, law_start
>> 12);
1486 out_be32(&priv
->maint_atmu_regs
->rowar
, 0x80077015); /* 4M */
1488 priv
->maint_win
= ioremap(law_start
, RIO_MAINT_WIN_SIZE
);
1490 /* Configure outbound doorbell window */
1491 out_be32(&priv
->dbell_atmu_regs
->rowbar
,
1492 (law_start
+ RIO_MAINT_WIN_SIZE
) >> 12);
1493 out_be32(&priv
->dbell_atmu_regs
->rowar
, 0x8004200b); /* 4k */
1494 fsl_rio_doorbell_init(port
);
1495 fsl_rio_port_write_init(port
);
1497 saved_mcheck_exception
= ppc_md
.machine_check_exception
;
1498 ppc_md
.machine_check_exception
= fsl_rio_mcheck_exception
;
1499 /* Ensure that RFXE is set */
1500 mtspr(SPRN_HID1
, (mfspr(SPRN_HID1
) | 0x20000));
1504 iounmap(priv
->regs_win
);
1514 /* The probe function for RapidIO peer-to-peer network.
1516 static int __devinit
fsl_of_rio_rpn_probe(struct of_device
*dev
,
1517 const struct of_device_id
*match
)
1520 printk(KERN_INFO
"Setting up RapidIO peer-to-peer network %s\n",
1521 dev
->dev
.of_node
->full_name
);
1523 rc
= fsl_rio_setup(dev
);
1527 /* Enumerate all registered ports */
1528 rc
= rio_init_mports();
1533 static const struct of_device_id fsl_of_rio_rpn_ids
[] = {
1535 .compatible
= "fsl,rapidio-delta",
1540 static struct of_platform_driver fsl_of_rio_rpn_driver
= {
1542 .name
= "fsl-of-rio",
1543 .owner
= THIS_MODULE
,
1544 .of_match_table
= fsl_of_rio_rpn_ids
,
1546 .probe
= fsl_of_rio_rpn_probe
,
1549 static __init
int fsl_of_rio_rpn_init(void)
1551 return of_register_platform_driver(&fsl_of_rio_rpn_driver
);
1554 subsys_initcall(fsl_of_rio_rpn_init
);