~ubuntu-branches/debian/wheezy/linux-2.6/wheezy

« back to all changes in this revision

Viewing changes to arch/powerpc/sysdev/fsl_rio.c

  • Committer: Bazaar Package Importer
  • Author(s): Ben Hutchings, Ben Hutchings, Aurelien Jarno, Martin Michlmayr
  • Date: 2011-04-06 13:53:30 UTC
  • mfrom: (43.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110406135330-wjufxhd0tvn3zx4z
Tags: 2.6.38-3
[ Ben Hutchings ]
* [ppc64] Add to linux-tools package architectures (Closes: #620124)
* [amd64] Save cr4 to mmu_cr4_features at boot time (Closes: #620284)
* appletalk: Fix bugs introduced when removing use of BKL
* ALSA: Fix yet another race in disconnection
* cciss: Fix lost command issue
* ath9k: Fix kernel panic in AR2427
* ses: Avoid kernel panic when lun 0 is not mapped
* PCI/ACPI: Report ASPM support to BIOS if not disabled from command line

[ Aurelien Jarno ]
* rtlwifi: fix build when PCI is not enabled.

[ Martin Michlmayr ]
* rtlwifi: Eliminate udelay calls with too large values (Closes: #620204)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Freescale MPC85xx/MPC86xx RapidIO support
3
3
 *
 
4
 * Copyright 2009 Sysgo AG
 
5
 * Thomas Moll <thomas.moll@sysgo.com>
 
6
 * - fixed maintenance access routines, check for aligned access
 
7
 *
 
8
 * Copyright 2009 Integrated Device Technology, Inc.
 
9
 * Alex Bounine <alexandre.bounine@idt.com>
 
10
 * - Added Port-Write message handling
 
11
 * - Added Machine Check exception handling
 
12
 *
4
13
 * Copyright (C) 2007, 2008 Freescale Semiconductor, Inc.
5
14
 * Zhang Wei <wei.zhang@freescale.com>
6
15
 *
23
32
#include <linux/rio_drv.h>
24
33
#include <linux/of_platform.h>
25
34
#include <linux/delay.h>
 
35
#include <linux/slab.h>
 
36
#include <linux/kfifo.h>
26
37
 
27
38
#include <asm/io.h>
 
39
#include <asm/machdep.h>
 
40
#include <asm/uaccess.h>
 
41
 
 
42
#undef DEBUG_PW /* Port-Write debugging */
28
43
 
29
44
/* RapidIO definition irq, which read from OF-tree */
30
45
#define IRQ_RIO_BELL(m)         (((struct rio_priv *)(m->priv))->bellirq)
31
46
#define IRQ_RIO_TX(m)           (((struct rio_priv *)(m->priv))->txirq)
32
47
#define IRQ_RIO_RX(m)           (((struct rio_priv *)(m->priv))->rxirq)
 
48
#define IRQ_RIO_PW(m)           (((struct rio_priv *)(m->priv))->pwirq)
33
49
 
34
50
#define RIO_ATMU_REGS_OFFSET    0x10c00
35
51
#define RIO_P_MSG_REGS_OFFSET   0x11000
36
52
#define RIO_S_MSG_REGS_OFFSET   0x13000
 
53
#define RIO_GCCSR               0x13c
37
54
#define RIO_ESCSR               0x158
38
55
#define RIO_CCSR                0x15c
 
56
#define RIO_LTLEDCSR            0x0608
 
57
#define  RIO_LTLEDCSR_IER       0x80000000
 
58
#define  RIO_LTLEDCSR_PRT       0x01000000
 
59
#define RIO_LTLEECSR            0x060c
 
60
#define RIO_EPWISR              0x10010
39
61
#define RIO_ISR_AACR            0x10120
40
62
#define RIO_ISR_AACR_AA         0x1     /* Accept All ID */
41
63
#define RIO_MAINT_WIN_SIZE      0x400000
54
76
#define RIO_MSG_ISR_QFI         0x00000010
55
77
#define RIO_MSG_ISR_DIQI        0x00000001
56
78
 
 
79
#define RIO_IPWMR_SEN           0x00100000
 
80
#define RIO_IPWMR_QFIE          0x00000100
 
81
#define RIO_IPWMR_EIE           0x00000020
 
82
#define RIO_IPWMR_CQ            0x00000002
 
83
#define RIO_IPWMR_PWE           0x00000001
 
84
 
 
85
#define RIO_IPWSR_QF            0x00100000
 
86
#define RIO_IPWSR_TE            0x00000080
 
87
#define RIO_IPWSR_QFI           0x00000010
 
88
#define RIO_IPWSR_PWD           0x00000008
 
89
#define RIO_IPWSR_PWB           0x00000004
 
90
 
 
91
#define RIO_EPWISR_PINT         0x80000000
 
92
#define RIO_EPWISR_PW           0x00000001
 
93
 
57
94
#define RIO_MSG_DESC_SIZE       32
58
95
#define RIO_MSG_BUFFER_SIZE     4096
59
96
#define RIO_MIN_TX_RING_SIZE    2
84
121
};
85
122
 
86
123
struct rio_msg_regs {
87
 
        u32 omr;
88
 
        u32 osr;
 
124
        u32 omr;        /* 0xD_3000 - Outbound message 0 mode register */
 
125
        u32 osr;        /* 0xD_3004 - Outbound message 0 status register */
89
126
        u32 pad1;
90
 
        u32 odqdpar;
 
127
        u32 odqdpar;    /* 0xD_300C - Outbound message 0 descriptor queue
 
128
                           dequeue pointer address register */
91
129
        u32 pad2;
92
 
        u32 osar;
93
 
        u32 odpr;
94
 
        u32 odatr;
95
 
        u32 odcr;
 
130
        u32 osar;       /* 0xD_3014 - Outbound message 0 source address
 
131
                           register */
 
132
        u32 odpr;       /* 0xD_3018 - Outbound message 0 destination port
 
133
                           register */
 
134
        u32 odatr;      /* 0xD_301C - Outbound message 0 destination attributes
 
135
                           Register*/
 
136
        u32 odcr;       /* 0xD_3020 - Outbound message 0 double-word count
 
137
                           register */
96
138
        u32 pad3;
97
 
        u32 odqepar;
 
139
        u32 odqepar;    /* 0xD_3028 - Outbound message 0 descriptor queue
 
140
                           enqueue pointer address register */
98
141
        u32 pad4[13];
99
 
        u32 imr;
100
 
        u32 isr;
 
142
        u32 imr;        /* 0xD_3060 - Inbound message 0 mode register */
 
143
        u32 isr;        /* 0xD_3064 - Inbound message 0 status register */
101
144
        u32 pad5;
102
 
        u32 ifqdpar;
 
145
        u32 ifqdpar;    /* 0xD_306C - Inbound message 0 frame queue dequeue
 
146
                           pointer address register*/
103
147
        u32 pad6;
104
 
        u32 ifqepar;
 
148
        u32 ifqepar;    /* 0xD_3074 - Inbound message 0 frame queue enqueue
 
149
                           pointer address register */
105
150
        u32 pad7[226];
106
 
        u32 odmr;
107
 
        u32 odsr;
 
151
        u32 odmr;       /* 0xD_3400 - Outbound doorbell mode register */
 
152
        u32 odsr;       /* 0xD_3404 - Outbound doorbell status register */
108
153
        u32 res0[4];
109
 
        u32 oddpr;
110
 
        u32 oddatr;
 
154
        u32 oddpr;      /* 0xD_3418 - Outbound doorbell destination port
 
155
                           register */
 
156
        u32 oddatr;     /* 0xD_341c - Outbound doorbell destination attributes
 
157
                           register */
111
158
        u32 res1[3];
112
 
        u32 odretcr;
 
159
        u32 odretcr;    /* 0xD_342C - Outbound doorbell retry error threshold
 
160
                           configuration register */
113
161
        u32 res2[12];
114
 
        u32 dmr;
115
 
        u32 dsr;
 
162
        u32 dmr;        /* 0xD_3460 - Inbound doorbell mode register */
 
163
        u32 dsr;        /* 0xD_3464 - Inbound doorbell status register */
116
164
        u32 pad8;
117
 
        u32 dqdpar;
 
165
        u32 dqdpar;     /* 0xD_346C - Inbound doorbell queue dequeue Pointer
 
166
                           address register */
118
167
        u32 pad9;
119
 
        u32 dqepar;
 
168
        u32 dqepar;     /* 0xD_3474 - Inbound doorbell Queue enqueue pointer
 
169
                           address register */
120
170
        u32 pad10[26];
121
 
        u32 pwmr;
122
 
        u32 pwsr;
123
 
        u32 pad11;
124
 
        u32 pwqbar;
 
171
        u32 pwmr;       /* 0xD_34E0 - Inbound port-write mode register */
 
172
        u32 pwsr;       /* 0xD_34E4 - Inbound port-write status register */
 
173
        u32 epwqbar;    /* 0xD_34E8 - Extended Port-Write Queue Base Address
 
174
                           register */
 
175
        u32 pwqbar;     /* 0xD_34EC - Inbound port-write queue base address
 
176
                           register */
125
177
};
126
178
 
127
179
struct rio_tx_desc {
159
211
        void *dev_id;
160
212
};
161
213
 
 
214
struct rio_port_write_msg {
 
215
        void *virt;
 
216
        dma_addr_t phys;
 
217
        u32 msg_count;
 
218
        u32 err_count;
 
219
        u32 discard_count;
 
220
};
 
221
 
162
222
struct rio_priv {
163
223
        struct device *dev;
164
224
        void __iomem *regs_win;
171
231
        struct rio_dbell_ring dbell_ring;
172
232
        struct rio_msg_tx_ring msg_tx_ring;
173
233
        struct rio_msg_rx_ring msg_rx_ring;
 
234
        struct rio_port_write_msg port_write_msg;
174
235
        int bellirq;
175
236
        int txirq;
176
237
        int rxirq;
 
238
        int pwirq;
 
239
        struct work_struct pw_work;
 
240
        struct kfifo pw_fifo;
 
241
        spinlock_t pw_fifo_lock;
177
242
};
178
243
 
 
244
#define __fsl_read_rio_config(x, addr, err, op)         \
 
245
        __asm__ __volatile__(                           \
 
246
                "1:     "op" %1,0(%2)\n"                \
 
247
                "       eieio\n"                        \
 
248
                "2:\n"                                  \
 
249
                ".section .fixup,\"ax\"\n"              \
 
250
                "3:     li %1,-1\n"                     \
 
251
                "       li %0,%3\n"                     \
 
252
                "       b 2b\n"                         \
 
253
                ".section __ex_table,\"a\"\n"           \
 
254
                "       .align 2\n"                     \
 
255
                "       .long 1b,3b\n"                  \
 
256
                ".text"                                 \
 
257
                : "=r" (err), "=r" (x)                  \
 
258
                : "b" (addr), "i" (-EFAULT), "0" (err))
 
259
 
 
260
static void __iomem *rio_regs_win;
 
261
 
 
262
#ifdef CONFIG_E500
 
263
static int (*saved_mcheck_exception)(struct pt_regs *regs);
 
264
 
 
265
static int fsl_rio_mcheck_exception(struct pt_regs *regs)
 
266
{
 
267
        const struct exception_table_entry *entry = NULL;
 
268
        unsigned long reason = mfspr(SPRN_MCSR);
 
269
 
 
270
        if (reason & MCSR_BUS_RBERR) {
 
271
                reason = in_be32((u32 *)(rio_regs_win + RIO_LTLEDCSR));
 
272
                if (reason & (RIO_LTLEDCSR_IER | RIO_LTLEDCSR_PRT)) {
 
273
                        /* Check if we are prepared to handle this fault */
 
274
                        entry = search_exception_tables(regs->nip);
 
275
                        if (entry) {
 
276
                                pr_debug("RIO: %s - MC Exception handled\n",
 
277
                                         __func__);
 
278
                                out_be32((u32 *)(rio_regs_win + RIO_LTLEDCSR),
 
279
                                         0);
 
280
                                regs->msr |= MSR_RI;
 
281
                                regs->nip = entry->fixup;
 
282
                                return 1;
 
283
                        }
 
284
                }
 
285
        }
 
286
 
 
287
        if (saved_mcheck_exception)
 
288
                return saved_mcheck_exception(regs);
 
289
        else
 
290
                return cur_cpu_spec->machine_check(regs);
 
291
}
 
292
#endif
 
293
 
179
294
/**
180
295
 * fsl_rio_doorbell_send - Send a MPC85xx doorbell message
181
296
 * @mport: RapidIO master port info
276
391
{
277
392
        struct rio_priv *priv = mport->priv;
278
393
        u8 *data;
 
394
        u32 rval, err = 0;
279
395
 
280
396
        pr_debug
281
397
            ("fsl_rio_config_read: index %d destid %d hopcount %d offset %8.8x len %d\n",
282
398
             index, destid, hopcount, offset, len);
 
399
 
 
400
        /* 16MB maintenance window possible */
 
401
        /* allow only aligned access to maintenance registers */
 
402
        if (offset > (0x1000000 - len) || !IS_ALIGNED(offset, len))
 
403
                return -EINVAL;
 
404
 
283
405
        out_be32(&priv->maint_atmu_regs->rowtar,
284
 
                 (destid << 22) | (hopcount << 12) | ((offset & ~0x3) >> 9));
 
406
                 (destid << 22) | (hopcount << 12) | (offset >> 12));
 
407
        out_be32(&priv->maint_atmu_regs->rowtear,  (destid >> 10));
285
408
 
286
 
        data = (u8 *) priv->maint_win + offset;
 
409
        data = (u8 *) priv->maint_win + (offset & (RIO_MAINT_WIN_SIZE - 1));
287
410
        switch (len) {
288
411
        case 1:
289
 
                *val = in_8((u8 *) data);
 
412
                __fsl_read_rio_config(rval, data, err, "lbz");
290
413
                break;
291
414
        case 2:
292
 
                *val = in_be16((u16 *) data);
 
415
                __fsl_read_rio_config(rval, data, err, "lhz");
 
416
                break;
 
417
        case 4:
 
418
                __fsl_read_rio_config(rval, data, err, "lwz");
293
419
                break;
294
420
        default:
295
 
                *val = in_be32((u32 *) data);
296
 
                break;
297
 
        }
298
 
 
299
 
        return 0;
 
421
                return -EINVAL;
 
422
        }
 
423
 
 
424
        if (err) {
 
425
                pr_debug("RIO: cfg_read error %d for %x:%x:%x\n",
 
426
                         err, destid, hopcount, offset);
 
427
        }
 
428
 
 
429
        *val = rval;
 
430
 
 
431
        return err;
300
432
}
301
433
 
302
434
/**
321
453
        pr_debug
322
454
            ("fsl_rio_config_write: index %d destid %d hopcount %d offset %8.8x len %d val %8.8x\n",
323
455
             index, destid, hopcount, offset, len, val);
 
456
 
 
457
        /* 16MB maintenance windows possible */
 
458
        /* allow only aligned access to maintenance registers */
 
459
        if (offset > (0x1000000 - len) || !IS_ALIGNED(offset, len))
 
460
                return -EINVAL;
 
461
 
324
462
        out_be32(&priv->maint_atmu_regs->rowtar,
325
 
                 (destid << 22) | (hopcount << 12) | ((offset & ~0x3) >> 9));
 
463
                 (destid << 22) | (hopcount << 12) | (offset >> 12));
 
464
        out_be32(&priv->maint_atmu_regs->rowtear,  (destid >> 10));
326
465
 
327
 
        data = (u8 *) priv->maint_win + offset;
 
466
        data = (u8 *) priv->maint_win + (offset & (RIO_MAINT_WIN_SIZE - 1));
328
467
        switch (len) {
329
468
        case 1:
330
469
                out_8((u8 *) data, val);
332
471
        case 2:
333
472
                out_be16((u16 *) data, val);
334
473
                break;
335
 
        default:
 
474
        case 4:
336
475
                out_be32((u32 *) data, val);
337
476
                break;
 
477
        default:
 
478
                return -EINVAL;
338
479
        }
339
480
 
340
481
        return 0;
832
973
        if (dsr & DOORBELL_DSR_QFI) {
833
974
                pr_info("RIO: doorbell queue full\n");
834
975
                out_be32(&priv->msg_regs->dsr, DOORBELL_DSR_QFI);
835
 
                goto out;
836
976
        }
837
977
 
838
978
        /* XXX Need to check/dispatch until queue empty */
929
1069
        return rc;
930
1070
}
931
1071
 
 
1072
/**
 
1073
 * fsl_rio_port_write_handler - MPC85xx port write interrupt handler
 
1074
 * @irq: Linux interrupt number
 
1075
 * @dev_instance: Pointer to interrupt-specific data
 
1076
 *
 
1077
 * Handles port write interrupts. Parses a list of registered
 
1078
 * port write event handlers and executes a matching event handler.
 
1079
 */
 
1080
static irqreturn_t
 
1081
fsl_rio_port_write_handler(int irq, void *dev_instance)
 
1082
{
 
1083
        u32 ipwmr, ipwsr;
 
1084
        struct rio_mport *port = (struct rio_mport *)dev_instance;
 
1085
        struct rio_priv *priv = port->priv;
 
1086
        u32 epwisr, tmp;
 
1087
 
 
1088
        epwisr = in_be32(priv->regs_win + RIO_EPWISR);
 
1089
        if (!(epwisr & RIO_EPWISR_PW))
 
1090
                goto pw_done;
 
1091
 
 
1092
        ipwmr = in_be32(&priv->msg_regs->pwmr);
 
1093
        ipwsr = in_be32(&priv->msg_regs->pwsr);
 
1094
 
 
1095
#ifdef DEBUG_PW
 
1096
        pr_debug("PW Int->IPWMR: 0x%08x IPWSR: 0x%08x (", ipwmr, ipwsr);
 
1097
        if (ipwsr & RIO_IPWSR_QF)
 
1098
                pr_debug(" QF");
 
1099
        if (ipwsr & RIO_IPWSR_TE)
 
1100
                pr_debug(" TE");
 
1101
        if (ipwsr & RIO_IPWSR_QFI)
 
1102
                pr_debug(" QFI");
 
1103
        if (ipwsr & RIO_IPWSR_PWD)
 
1104
                pr_debug(" PWD");
 
1105
        if (ipwsr & RIO_IPWSR_PWB)
 
1106
                pr_debug(" PWB");
 
1107
        pr_debug(" )\n");
 
1108
#endif
 
1109
        /* Schedule deferred processing if PW was received */
 
1110
        if (ipwsr & RIO_IPWSR_QFI) {
 
1111
                /* Save PW message (if there is room in FIFO),
 
1112
                 * otherwise discard it.
 
1113
                 */
 
1114
                if (kfifo_avail(&priv->pw_fifo) >= RIO_PW_MSG_SIZE) {
 
1115
                        priv->port_write_msg.msg_count++;
 
1116
                        kfifo_in(&priv->pw_fifo, priv->port_write_msg.virt,
 
1117
                                 RIO_PW_MSG_SIZE);
 
1118
                } else {
 
1119
                        priv->port_write_msg.discard_count++;
 
1120
                        pr_debug("RIO: ISR Discarded Port-Write Msg(s) (%d)\n",
 
1121
                                 priv->port_write_msg.discard_count);
 
1122
                }
 
1123
                /* Clear interrupt and issue Clear Queue command. This allows
 
1124
                 * another port-write to be received.
 
1125
                 */
 
1126
                out_be32(&priv->msg_regs->pwsr, RIO_IPWSR_QFI);
 
1127
                out_be32(&priv->msg_regs->pwmr, ipwmr | RIO_IPWMR_CQ);
 
1128
 
 
1129
                schedule_work(&priv->pw_work);
 
1130
        }
 
1131
 
 
1132
        if ((ipwmr & RIO_IPWMR_EIE) && (ipwsr & RIO_IPWSR_TE)) {
 
1133
                priv->port_write_msg.err_count++;
 
1134
                pr_debug("RIO: Port-Write Transaction Err (%d)\n",
 
1135
                         priv->port_write_msg.err_count);
 
1136
                /* Clear Transaction Error: port-write controller should be
 
1137
                 * disabled when clearing this error
 
1138
                 */
 
1139
                out_be32(&priv->msg_regs->pwmr, ipwmr & ~RIO_IPWMR_PWE);
 
1140
                out_be32(&priv->msg_regs->pwsr, RIO_IPWSR_TE);
 
1141
                out_be32(&priv->msg_regs->pwmr, ipwmr);
 
1142
        }
 
1143
 
 
1144
        if (ipwsr & RIO_IPWSR_PWD) {
 
1145
                priv->port_write_msg.discard_count++;
 
1146
                pr_debug("RIO: Port Discarded Port-Write Msg(s) (%d)\n",
 
1147
                         priv->port_write_msg.discard_count);
 
1148
                out_be32(&priv->msg_regs->pwsr, RIO_IPWSR_PWD);
 
1149
        }
 
1150
 
 
1151
pw_done:
 
1152
        if (epwisr & RIO_EPWISR_PINT) {
 
1153
                tmp = in_be32(priv->regs_win + RIO_LTLEDCSR);
 
1154
                pr_debug("RIO_LTLEDCSR = 0x%x\n", tmp);
 
1155
                out_be32(priv->regs_win + RIO_LTLEDCSR, 0);
 
1156
        }
 
1157
 
 
1158
        return IRQ_HANDLED;
 
1159
}
 
1160
 
 
1161
static void fsl_pw_dpc(struct work_struct *work)
 
1162
{
 
1163
        struct rio_priv *priv = container_of(work, struct rio_priv, pw_work);
 
1164
        unsigned long flags;
 
1165
        u32 msg_buffer[RIO_PW_MSG_SIZE/sizeof(u32)];
 
1166
 
 
1167
        /*
 
1168
         * Process port-write messages
 
1169
         */
 
1170
        spin_lock_irqsave(&priv->pw_fifo_lock, flags);
 
1171
        while (kfifo_out(&priv->pw_fifo, (unsigned char *)msg_buffer,
 
1172
                         RIO_PW_MSG_SIZE)) {
 
1173
                /* Process one message */
 
1174
                spin_unlock_irqrestore(&priv->pw_fifo_lock, flags);
 
1175
#ifdef DEBUG_PW
 
1176
                {
 
1177
                u32 i;
 
1178
                pr_debug("%s : Port-Write Message:", __func__);
 
1179
                for (i = 0; i < RIO_PW_MSG_SIZE/sizeof(u32); i++) {
 
1180
                        if ((i%4) == 0)
 
1181
                                pr_debug("\n0x%02x: 0x%08x", i*4,
 
1182
                                         msg_buffer[i]);
 
1183
                        else
 
1184
                                pr_debug(" 0x%08x", msg_buffer[i]);
 
1185
                }
 
1186
                pr_debug("\n");
 
1187
                }
 
1188
#endif
 
1189
                /* Pass the port-write message to RIO core for processing */
 
1190
                rio_inb_pwrite_handler((union rio_pw_msg *)msg_buffer);
 
1191
                spin_lock_irqsave(&priv->pw_fifo_lock, flags);
 
1192
        }
 
1193
        spin_unlock_irqrestore(&priv->pw_fifo_lock, flags);
 
1194
}
 
1195
 
 
1196
/**
 
1197
 * fsl_rio_pw_enable - enable/disable port-write interface init
 
1198
 * @mport: Master port implementing the port write unit
 
1199
 * @enable:    1=enable; 0=disable port-write message handling
 
1200
 */
 
1201
static int fsl_rio_pw_enable(struct rio_mport *mport, int enable)
 
1202
{
 
1203
        struct rio_priv *priv = mport->priv;
 
1204
        u32 rval;
 
1205
 
 
1206
        rval = in_be32(&priv->msg_regs->pwmr);
 
1207
 
 
1208
        if (enable)
 
1209
                rval |= RIO_IPWMR_PWE;
 
1210
        else
 
1211
                rval &= ~RIO_IPWMR_PWE;
 
1212
 
 
1213
        out_be32(&priv->msg_regs->pwmr, rval);
 
1214
 
 
1215
        return 0;
 
1216
}
 
1217
 
 
1218
/**
 
1219
 * fsl_rio_port_write_init - MPC85xx port write interface init
 
1220
 * @mport: Master port implementing the port write unit
 
1221
 *
 
1222
 * Initializes port write unit hardware and DMA buffer
 
1223
 * ring. Called from fsl_rio_setup(). Returns %0 on success
 
1224
 * or %-ENOMEM on failure.
 
1225
 */
 
1226
static int fsl_rio_port_write_init(struct rio_mport *mport)
 
1227
{
 
1228
        struct rio_priv *priv = mport->priv;
 
1229
        int rc = 0;
 
1230
 
 
1231
        /* Following configurations require a disabled port write controller */
 
1232
        out_be32(&priv->msg_regs->pwmr,
 
1233
                 in_be32(&priv->msg_regs->pwmr) & ~RIO_IPWMR_PWE);
 
1234
 
 
1235
        /* Initialize port write */
 
1236
        priv->port_write_msg.virt = dma_alloc_coherent(priv->dev,
 
1237
                                        RIO_PW_MSG_SIZE,
 
1238
                                        &priv->port_write_msg.phys, GFP_KERNEL);
 
1239
        if (!priv->port_write_msg.virt) {
 
1240
                pr_err("RIO: unable allocate port write queue\n");
 
1241
                return -ENOMEM;
 
1242
        }
 
1243
 
 
1244
        priv->port_write_msg.err_count = 0;
 
1245
        priv->port_write_msg.discard_count = 0;
 
1246
 
 
1247
        /* Point dequeue/enqueue pointers at first entry */
 
1248
        out_be32(&priv->msg_regs->epwqbar, 0);
 
1249
        out_be32(&priv->msg_regs->pwqbar, (u32) priv->port_write_msg.phys);
 
1250
 
 
1251
        pr_debug("EIPWQBAR: 0x%08x IPWQBAR: 0x%08x\n",
 
1252
                 in_be32(&priv->msg_regs->epwqbar),
 
1253
                 in_be32(&priv->msg_regs->pwqbar));
 
1254
 
 
1255
        /* Clear interrupt status IPWSR */
 
1256
        out_be32(&priv->msg_regs->pwsr,
 
1257
                 (RIO_IPWSR_TE | RIO_IPWSR_QFI | RIO_IPWSR_PWD));
 
1258
 
 
1259
        /* Configure port write contoller for snooping enable all reporting,
 
1260
           clear queue full */
 
1261
        out_be32(&priv->msg_regs->pwmr,
 
1262
                 RIO_IPWMR_SEN | RIO_IPWMR_QFIE | RIO_IPWMR_EIE | RIO_IPWMR_CQ);
 
1263
 
 
1264
 
 
1265
        /* Hook up port-write handler */
 
1266
        rc = request_irq(IRQ_RIO_PW(mport), fsl_rio_port_write_handler, 0,
 
1267
                         "port-write", (void *)mport);
 
1268
        if (rc < 0) {
 
1269
                pr_err("MPC85xx RIO: unable to request inbound doorbell irq");
 
1270
                goto err_out;
 
1271
        }
 
1272
 
 
1273
        INIT_WORK(&priv->pw_work, fsl_pw_dpc);
 
1274
        spin_lock_init(&priv->pw_fifo_lock);
 
1275
        if (kfifo_alloc(&priv->pw_fifo, RIO_PW_MSG_SIZE * 32, GFP_KERNEL)) {
 
1276
                pr_err("FIFO allocation failed\n");
 
1277
                rc = -ENOMEM;
 
1278
                goto err_out_irq;
 
1279
        }
 
1280
 
 
1281
        pr_debug("IPWMR: 0x%08x IPWSR: 0x%08x\n",
 
1282
                 in_be32(&priv->msg_regs->pwmr),
 
1283
                 in_be32(&priv->msg_regs->pwsr));
 
1284
 
 
1285
        return rc;
 
1286
 
 
1287
err_out_irq:
 
1288
        free_irq(IRQ_RIO_PW(mport), (void *)mport);
 
1289
err_out:
 
1290
        dma_free_coherent(priv->dev, RIO_PW_MSG_SIZE,
 
1291
                          priv->port_write_msg.virt,
 
1292
                          priv->port_write_msg.phys);
 
1293
        return rc;
 
1294
}
 
1295
 
932
1296
static char *cmdline = NULL;
933
1297
 
934
1298
static int fsl_rio_get_hdid(int index)
995
1359
 
996
1360
/**
997
1361
 * fsl_rio_setup - Setup Freescale PowerPC RapidIO interface
998
 
 * @dev: of_device pointer
 
1362
 * @dev: platform_device pointer
999
1363
 *
1000
1364
 * Initializes MPC85xx RapidIO hardware interface, configures
1001
1365
 * master port with system-specific info, and registers the
1002
1366
 * master port with the RapidIO subsystem.
1003
1367
 */
1004
 
int fsl_rio_setup(struct of_device *dev)
 
1368
int fsl_rio_setup(struct platform_device *dev)
1005
1369
{
1006
1370
        struct rio_ops *ops;
1007
1371
        struct rio_mport *port;
1014
1378
        u64 law_start, law_size;
1015
1379
        int paw, aw, sw;
1016
1380
 
1017
 
        if (!dev->node) {
 
1381
        if (!dev->dev.of_node) {
1018
1382
                dev_err(&dev->dev, "Device OF-Node is NULL");
1019
1383
                return -EFAULT;
1020
1384
        }
1021
1385
 
1022
 
        rc = of_address_to_resource(dev->node, 0, &regs);
 
1386
        rc = of_address_to_resource(dev->dev.of_node, 0, &regs);
1023
1387
        if (rc) {
1024
1388
                dev_err(&dev->dev, "Can't get %s property 'reg'\n",
1025
 
                                dev->node->full_name);
 
1389
                                dev->dev.of_node->full_name);
1026
1390
                return -EFAULT;
1027
1391
        }
1028
 
        dev_info(&dev->dev, "Of-device full name %s\n", dev->node->full_name);
 
1392
        dev_info(&dev->dev, "Of-device full name %s\n", dev->dev.of_node->full_name);
1029
1393
        dev_info(&dev->dev, "Regs: %pR\n", &regs);
1030
1394
 
1031
 
        dt_range = of_get_property(dev->node, "ranges", &rlen);
 
1395
        dt_range = of_get_property(dev->dev.of_node, "ranges", &rlen);
1032
1396
        if (!dt_range) {
1033
1397
                dev_err(&dev->dev, "Can't get %s property 'ranges'\n",
1034
 
                                dev->node->full_name);
 
1398
                                dev->dev.of_node->full_name);
1035
1399
                return -EFAULT;
1036
1400
        }
1037
1401
 
1038
1402
        /* Get node address wide */
1039
 
        cell = of_get_property(dev->node, "#address-cells", NULL);
 
1403
        cell = of_get_property(dev->dev.of_node, "#address-cells", NULL);
1040
1404
        if (cell)
1041
1405
                aw = *cell;
1042
1406
        else
1043
 
                aw = of_n_addr_cells(dev->node);
 
1407
                aw = of_n_addr_cells(dev->dev.of_node);
1044
1408
        /* Get node size wide */
1045
 
        cell = of_get_property(dev->node, "#size-cells", NULL);
 
1409
        cell = of_get_property(dev->dev.of_node, "#size-cells", NULL);
1046
1410
        if (cell)
1047
1411
                sw = *cell;
1048
1412
        else
1049
 
                sw = of_n_size_cells(dev->node);
 
1413
                sw = of_n_size_cells(dev->dev.of_node);
1050
1414
        /* Get parent address wide wide */
1051
 
        paw = of_n_addr_cells(dev->node);
 
1415
        paw = of_n_addr_cells(dev->dev.of_node);
1052
1416
 
1053
1417
        law_start = of_read_number(dt_range + aw, paw);
1054
1418
        law_size = of_read_number(dt_range + aw + paw, sw);
1056
1420
        dev_info(&dev->dev, "LAW start 0x%016llx, size 0x%016llx.\n",
1057
1421
                        law_start, law_size);
1058
1422
 
1059
 
        ops = kmalloc(sizeof(struct rio_ops), GFP_KERNEL);
 
1423
        ops = kzalloc(sizeof(struct rio_ops), GFP_KERNEL);
1060
1424
        if (!ops) {
1061
1425
                rc = -ENOMEM;
1062
1426
                goto err_ops;
1066
1430
        ops->cread = fsl_rio_config_read;
1067
1431
        ops->cwrite = fsl_rio_config_write;
1068
1432
        ops->dsend = fsl_rio_doorbell_send;
 
1433
        ops->pwenable = fsl_rio_pw_enable;
1069
1434
 
1070
1435
        port = kzalloc(sizeof(struct rio_mport), GFP_KERNEL);
1071
1436
        if (!port) {
1088
1453
        port->iores.flags = IORESOURCE_MEM;
1089
1454
        port->iores.name = "rio_io_win";
1090
1455
 
1091
 
        priv->bellirq = irq_of_parse_and_map(dev->node, 2);
1092
 
        priv->txirq = irq_of_parse_and_map(dev->node, 3);
1093
 
        priv->rxirq = irq_of_parse_and_map(dev->node, 4);
1094
 
        dev_info(&dev->dev, "bellirq: %d, txirq: %d, rxirq %d\n", priv->bellirq,
1095
 
                                priv->txirq, priv->rxirq);
 
1456
        priv->pwirq   = irq_of_parse_and_map(dev->dev.of_node, 0);
 
1457
        priv->bellirq = irq_of_parse_and_map(dev->dev.of_node, 2);
 
1458
        priv->txirq = irq_of_parse_and_map(dev->dev.of_node, 3);
 
1459
        priv->rxirq = irq_of_parse_and_map(dev->dev.of_node, 4);
 
1460
        dev_info(&dev->dev, "pwirq: %d, bellirq: %d, txirq: %d, rxirq %d\n",
 
1461
                 priv->pwirq, priv->bellirq, priv->txirq, priv->rxirq);
1096
1462
 
1097
1463
        rio_init_dbell_res(&port->riores[RIO_DOORBELL_RESOURCE], 0, 0xffff);
1098
1464
        rio_init_mbox_res(&port->riores[RIO_INB_MBOX_RESOURCE], 0, 0);
1105
1471
        port->host_deviceid = fsl_rio_get_hdid(port->id);
1106
1472
 
1107
1473
        port->priv = priv;
 
1474
        port->phys_efptr = 0x100;
1108
1475
        rio_register_mport(port);
1109
1476
 
1110
1477
        priv->regs_win = ioremap(regs.start, regs.end - regs.start + 1);
 
1478
        rio_regs_win = priv->regs_win;
1111
1479
 
1112
1480
        /* Probe the master port phy type */
1113
1481
        ccsr = in_be32(priv->regs_win + RIO_CCSR);
1151
1519
        dev_info(&dev->dev, "RapidIO Common Transport System size: %d\n",
1152
1520
                        port->sys_size ? 65536 : 256);
1153
1521
 
 
1522
        if (port->host_deviceid >= 0)
 
1523
                out_be32(priv->regs_win + RIO_GCCSR, RIO_PORT_GEN_HOST |
 
1524
                        RIO_PORT_GEN_MASTER | RIO_PORT_GEN_DISCOVERED);
 
1525
        else
 
1526
                out_be32(priv->regs_win + RIO_GCCSR, 0x00000000);
 
1527
 
1154
1528
        priv->atmu_regs = (struct rio_atmu_regs *)(priv->regs_win
1155
1529
                                        + RIO_ATMU_REGS_OFFSET);
1156
1530
        priv->maint_atmu_regs = priv->atmu_regs + 1;
1165
1539
 
1166
1540
        /* Configure maintenance transaction window */
1167
1541
        out_be32(&priv->maint_atmu_regs->rowbar, law_start >> 12);
1168
 
        out_be32(&priv->maint_atmu_regs->rowar, 0x80077015);    /* 4M */
 
1542
        out_be32(&priv->maint_atmu_regs->rowar,
 
1543
                 0x80077000 | (ilog2(RIO_MAINT_WIN_SIZE) - 1));
1169
1544
 
1170
1545
        priv->maint_win = ioremap(law_start, RIO_MAINT_WIN_SIZE);
1171
1546
 
1174
1549
                        (law_start + RIO_MAINT_WIN_SIZE) >> 12);
1175
1550
        out_be32(&priv->dbell_atmu_regs->rowar, 0x8004200b);    /* 4k */
1176
1551
        fsl_rio_doorbell_init(port);
 
1552
        fsl_rio_port_write_init(port);
 
1553
 
 
1554
#ifdef CONFIG_E500
 
1555
        saved_mcheck_exception = ppc_md.machine_check_exception;
 
1556
        ppc_md.machine_check_exception = fsl_rio_mcheck_exception;
 
1557
#endif
1177
1558
 
1178
1559
        return 0;
1179
1560
err:
1189
1570
 
1190
1571
/* The probe function for RapidIO peer-to-peer network.
1191
1572
 */
1192
 
static int __devinit fsl_of_rio_rpn_probe(struct of_device *dev,
 
1573
static int __devinit fsl_of_rio_rpn_probe(struct platform_device *dev,
1193
1574
                                     const struct of_device_id *match)
1194
1575
{
1195
1576
        int rc;
1196
1577
        printk(KERN_INFO "Setting up RapidIO peer-to-peer network %s\n",
1197
 
                        dev->node->full_name);
 
1578
                        dev->dev.of_node->full_name);
1198
1579
 
1199
1580
        rc = fsl_rio_setup(dev);
1200
1581
        if (rc)
1214
1595
};
1215
1596
 
1216
1597
static struct of_platform_driver fsl_of_rio_rpn_driver = {
1217
 
        .name = "fsl-of-rio",
1218
 
        .match_table = fsl_of_rio_rpn_ids,
 
1598
        .driver = {
 
1599
                .name = "fsl-of-rio",
 
1600
                .owner = THIS_MODULE,
 
1601
                .of_match_table = fsl_of_rio_rpn_ids,
 
1602
        },
1219
1603
        .probe = fsl_of_rio_rpn_probe,
1220
1604
};
1221
1605