26 #include <linux/module.h>
27 #include <linux/types.h>
30 #include <linux/device.h>
33 #include <linux/slab.h>
37 #include <asm/machdep.h>
43 #define RIO_PORT1_EDCSR 0x0640
44 #define RIO_PORT2_EDCSR 0x0680
45 #define RIO_PORT1_IECSR 0x10130
46 #define RIO_PORT2_IECSR 0x101B0
48 #define RIO_GCCSR 0x13c
49 #define RIO_ESCSR 0x158
50 #define ESCSR_CLEAR 0x07120204
51 #define RIO_PORT2_ESCSR 0x178
52 #define RIO_CCSR 0x15c
53 #define RIO_LTLEDCSR_IER 0x80000000
54 #define RIO_LTLEDCSR_PRT 0x01000000
55 #define IECSR_CLEAR 0x80000000
56 #define RIO_ISR_AACR 0x10120
57 #define RIO_ISR_AACR_AA 0x1
59 #define __fsl_read_rio_config(x, addr, err, op) \
60 __asm__ __volatile__( \
61 "1: "op" %1,0(%2)\n" \
64 ".section .fixup,\"ax\"\n" \
68 ".section __ex_table,\"a\"\n" \
72 : "=r" (err), "=r" (x) \
73 : "b" (addr), "i" (-EFAULT), "0" (err))
96 pr_debug(
"RIO: %s - MC Exception handled\n",
122 static int fsl_local_config_read(
struct rio_mport *mport,
126 pr_debug(
"fsl_local_config_read: index %d offset %8.8x\n", index,
144 static int fsl_local_config_write(
struct rio_mport *mport,
149 (
"fsl_local_config_write: index %d offset %8.8x data %8.8x\n",
150 index, offset, data);
178 (
"fsl_rio_config_read:"
179 " index %d destid %d hopcount %d offset %8.8x len %d\n",
180 index, destid, hopcount, offset, len);
184 if (offset > (0x1000000 - len) || !
IS_ALIGNED(offset, len))
188 (destid << 22) | (hopcount << 12) | (offset >> 12));
207 pr_debug(
"RIO: cfg_read error %d for %x:%x:%x\n",
208 err, destid, hopcount, offset);
230 fsl_rio_config_write(
struct rio_mport *mport,
int index,
u16 destid,
231 u8 hopcount,
u32 offset,
int len,
u32 val)
236 (
"fsl_rio_config_write:"
237 " index %d destid %d hopcount %d offset %8.8x len %d val %8.8x\n",
238 index, destid, hopcount, offset, len, val);
242 if (offset > (0x1000000 - len) || !
IS_ALIGNED(offset, len))
246 (destid << 22) | (hopcount << 12) | (offset >> 12));
282 static inline void fsl_rio_info(
struct device *
dev,
u32 ccsr)
287 switch (ccsr >> 30) {
298 dev_info(dev,
"Hardware port width: %s\n", str);
300 switch ((ccsr >> 27) & 7) {
302 str =
"Single-lane 0";
305 str =
"Single-lane 2";
314 dev_info(dev,
"Training connection status: %s\n", str);
317 if (!(ccsr & 0x80000000))
318 dev_info(dev,
"Output port operating in 8-bit mode\n");
319 if (!(ccsr & 0x08000000))
320 dev_info(dev,
"Input port operating in 8-bit mode\n");
338 const u32 *dt_range, *cell, *port_index;
339 u32 active_ports = 0;
350 if (!dev->
dev.of_node) {
357 dev_err(&dev->
dev,
"Can't get %s property 'reg'\n",
358 dev->
dev.of_node->full_name);
362 dev->
dev.of_node->full_name);
367 dev_err(&dev->
dev,
"Unable to map rio register window\n");
377 ops->
lcread = fsl_local_config_read;
378 ops->
lcwrite = fsl_local_config_write;
379 ops->
cread = fsl_rio_config_read;
380 ops->
cwrite = fsl_rio_config_write;
396 dev_err(&dev->
dev,
"Can't get %s property 'reg'\n",
402 dev_err(&dev->
dev,
"Unable to map rmu register window\n");
406 for_each_compatible_node(np,
NULL,
"fsl,srio-msg-unit") {
419 dev_err(&dev->
dev,
"Can't alloc memory for 'fsl_rio_dbell'\n");
430 pr_err(
"%s: unable to find 'reg' property\n",
435 range_start = of_read_number(dt_range, aw);
447 dev_err(&dev->
dev,
"Can't alloc memory for 'fsl_rio_pw'\n");
457 pr_err(
"%s: unable to find 'reg' property\n",
462 range_start = of_read_number(dt_range, aw);
469 dev_err(&dev->
dev,
"Can't get %s property 'cell-index'\n",
476 dev_err(&dev->
dev,
"Can't get %s property 'ranges'\n",
495 range_start = of_read_number(dt_range + aw, paw);
496 range_size = of_read_number(dt_range + aw + paw, sw);
498 dev_info(&dev->
dev,
"%s: LAW start 0x%016llx, size 0x%016llx.\n",
510 dev_err(&dev->
dev,
"Can't alloc memory for 'priv'\n");
515 INIT_LIST_HEAD(&port->
dbells);
517 port->
iores.end = port->
iores.start + range_size - 1;
519 port->
iores.name =
"rio_io_win";
522 dev_err(&dev->
dev,
"RIO: Error requesting master port region"
523 " 0x%016llx-0x%016llx\n",
541 dev_err(&dev->
dev,
"RIO: Parallel PHY type, unsupported port type!\n");
551 "Try to restart connection...\n", i);
565 "Port %d restart failed.\n", i);
571 dev_info(&dev->
dev,
"Port %d restart success!\n", i);
573 fsl_rio_info(&dev->
dev, ccsr);
577 dev_info(&dev->
dev,
"RapidIO Common Transport System size: %d\n",
606 port->
iores.start >> 12);
650 dev->
dev.of_node->full_name);
655 static const struct of_device_id fsl_of_rio_rpn_ids[] = {
657 .compatible =
"fsl,srio",
664 .name =
"fsl-of-rio",
666 .of_match_table = fsl_of_rio_rpn_ids,
668 .probe = fsl_of_rio_rpn_probe,
671 static __init int fsl_of_rio_rpn_init(
void)