blob: 5b206a2fe17c47653632e516051984746ad2d587 [file] [log] [blame]
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001/*
Zhang Weid02443a2008-04-18 13:33:38 -07002 * Freescale MPC85xx/MPC86xx RapidIO support
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08003 *
Thomas Mollbd4fb652010-05-26 14:44:05 -07004 * Copyright 2009 Sysgo AG
5 * Thomas Moll <thomas.moll@sysgo.com>
6 * - fixed maintenance access routines, check for aligned access
7 *
Alexandre Bounine5b2074a2010-05-26 14:44:00 -07008 * 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 *
Shaohui Xie6ff31452010-11-18 14:57:53 +080013 * Copyright (C) 2007, 2008, 2010 Freescale Semiconductor, Inc.
Zhang Weiad1e9382008-04-18 13:33:41 -070014 * Zhang Wei <wei.zhang@freescale.com>
15 *
Matt Porter2b0c28d7f2005-11-07 01:00:19 -080016 * Copyright 2005 MontaVista Software, Inc.
17 * Matt Porter <mporter@kernel.crashing.org>
18 *
19 * This program is free software; you can redistribute it and/or modify it
20 * under the terms of the GNU General Public License as published by the
21 * Free Software Foundation; either version 2 of the License, or (at your
22 * option) any later version.
23 */
24
Matt Porter2b0c28d7f2005-11-07 01:00:19 -080025#include <linux/init.h>
26#include <linux/module.h>
27#include <linux/types.h>
28#include <linux/dma-mapping.h>
29#include <linux/interrupt.h>
Anton Vorontsov0dbbbf12009-04-18 21:48:52 +040030#include <linux/device.h>
Matt Porter2b0c28d7f2005-11-07 01:00:19 -080031#include <linux/rio.h>
32#include <linux/rio_drv.h>
Zhang Weicc2bb692008-04-18 13:33:41 -070033#include <linux/of_platform.h>
Zhang Wei61b26912008-04-18 13:33:44 -070034#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090035#include <linux/slab.h>
Alexandre Bounine5b2074a2010-05-26 14:44:00 -070036#include <linux/kfifo.h>
Matt Porter2b0c28d7f2005-11-07 01:00:19 -080037
38#include <asm/io.h>
Alexandre Bouninea52c8f52010-05-26 14:44:00 -070039#include <asm/machdep.h>
40#include <asm/uaccess.h>
Matt Porter2b0c28d7f2005-11-07 01:00:19 -080041
Alexandre Bounine5b2074a2010-05-26 14:44:00 -070042#undef DEBUG_PW /* Port-Write debugging */
43
Zhang Weiad1e9382008-04-18 13:33:41 -070044/* RapidIO definition irq, which read from OF-tree */
45#define IRQ_RIO_BELL(m) (((struct rio_priv *)(m->priv))->bellirq)
46#define IRQ_RIO_TX(m) (((struct rio_priv *)(m->priv))->txirq)
47#define IRQ_RIO_RX(m) (((struct rio_priv *)(m->priv))->rxirq)
Alexandre Bounine5b2074a2010-05-26 14:44:00 -070048#define IRQ_RIO_PW(m) (((struct rio_priv *)(m->priv))->pwirq)
Zhang Weiad1e9382008-04-18 13:33:41 -070049
Shaohui Xie6ff31452010-11-18 14:57:53 +080050#define IPWSR_CLEAR 0x98
51#define OMSR_CLEAR 0x1cb3
52#define IMSR_CLEAR 0x491
53#define IDSR_CLEAR 0x91
54#define ODSR_CLEAR 0x1c00
55#define LTLEECSR_ENABLE_ALL 0xFFC000FC
56#define ESCSR_CLEAR 0x07120204
57
58#define RIO_PORT1_EDCSR 0x0640
59#define RIO_PORT2_EDCSR 0x0680
60#define RIO_PORT1_IECSR 0x10130
61#define RIO_PORT2_IECSR 0x101B0
62#define RIO_IM0SR 0x13064
63#define RIO_IM1SR 0x13164
64#define RIO_OM0SR 0x13004
65#define RIO_OM1SR 0x13104
66
Matt Porter2b0c28d7f2005-11-07 01:00:19 -080067#define RIO_ATMU_REGS_OFFSET 0x10c00
Zhang Wei61b26912008-04-18 13:33:44 -070068#define RIO_P_MSG_REGS_OFFSET 0x11000
69#define RIO_S_MSG_REGS_OFFSET 0x13000
Alexandre Bounineaf84ca382010-10-27 15:34:34 -070070#define RIO_GCCSR 0x13c
Zhang Wei61b26912008-04-18 13:33:44 -070071#define RIO_ESCSR 0x158
Shaohui Xie6ff31452010-11-18 14:57:53 +080072#define RIO_PORT2_ESCSR 0x178
Zhang Wei61b26912008-04-18 13:33:44 -070073#define RIO_CCSR 0x15c
Alexandre Bounine5b2074a2010-05-26 14:44:00 -070074#define RIO_LTLEDCSR 0x0608
Shaohui Xie6ff31452010-11-18 14:57:53 +080075#define RIO_LTLEDCSR_IER 0x80000000
76#define RIO_LTLEDCSR_PRT 0x01000000
Alexandre Bounine5b2074a2010-05-26 14:44:00 -070077#define RIO_LTLEECSR 0x060c
78#define RIO_EPWISR 0x10010
Zhang Wei61b26912008-04-18 13:33:44 -070079#define RIO_ISR_AACR 0x10120
80#define RIO_ISR_AACR_AA 0x1 /* Accept All ID */
Matt Porter2b0c28d7f2005-11-07 01:00:19 -080081#define RIO_MAINT_WIN_SIZE 0x400000
82#define RIO_DBELL_WIN_SIZE 0x1000
83
84#define RIO_MSG_OMR_MUI 0x00000002
85#define RIO_MSG_OSR_TE 0x00000080
86#define RIO_MSG_OSR_QOI 0x00000020
87#define RIO_MSG_OSR_QFI 0x00000010
88#define RIO_MSG_OSR_MUB 0x00000004
89#define RIO_MSG_OSR_EOMI 0x00000002
90#define RIO_MSG_OSR_QEI 0x00000001
91
92#define RIO_MSG_IMR_MI 0x00000002
93#define RIO_MSG_ISR_TE 0x00000080
94#define RIO_MSG_ISR_QFI 0x00000010
95#define RIO_MSG_ISR_DIQI 0x00000001
96
Alexandre Bounine5b2074a2010-05-26 14:44:00 -070097#define RIO_IPWMR_SEN 0x00100000
98#define RIO_IPWMR_QFIE 0x00000100
99#define RIO_IPWMR_EIE 0x00000020
100#define RIO_IPWMR_CQ 0x00000002
101#define RIO_IPWMR_PWE 0x00000001
102
103#define RIO_IPWSR_QF 0x00100000
104#define RIO_IPWSR_TE 0x00000080
105#define RIO_IPWSR_QFI 0x00000010
106#define RIO_IPWSR_PWD 0x00000008
107#define RIO_IPWSR_PWB 0x00000004
108
Shaohui Xie6ff31452010-11-18 14:57:53 +0800109/* EPWISR Error match value */
110#define RIO_EPWISR_PINT1 0x80000000
111#define RIO_EPWISR_PINT2 0x40000000
112#define RIO_EPWISR_MU 0x00000002
Alexandre Bounine93e2cbd2010-10-27 15:34:28 -0700113#define RIO_EPWISR_PW 0x00000001
114
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800115#define RIO_MSG_DESC_SIZE 32
116#define RIO_MSG_BUFFER_SIZE 4096
117#define RIO_MIN_TX_RING_SIZE 2
118#define RIO_MAX_TX_RING_SIZE 2048
119#define RIO_MIN_RX_RING_SIZE 2
120#define RIO_MAX_RX_RING_SIZE 2048
121
122#define DOORBELL_DMR_DI 0x00000002
123#define DOORBELL_DSR_TE 0x00000080
124#define DOORBELL_DSR_QFI 0x00000010
125#define DOORBELL_DSR_DIQI 0x00000001
Zhang Wei6c391032008-04-18 13:33:48 -0700126#define DOORBELL_TID_OFFSET 0x02
127#define DOORBELL_SID_OFFSET 0x04
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800128#define DOORBELL_INFO_OFFSET 0x06
129
130#define DOORBELL_MESSAGE_SIZE 0x08
Zhang Wei6c391032008-04-18 13:33:48 -0700131#define DBELL_SID(x) (*(u16 *)(x + DOORBELL_SID_OFFSET))
132#define DBELL_TID(x) (*(u16 *)(x + DOORBELL_TID_OFFSET))
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800133#define DBELL_INF(x) (*(u16 *)(x + DOORBELL_INFO_OFFSET))
134
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800135struct rio_atmu_regs {
136 u32 rowtar;
Zhang Wei61b26912008-04-18 13:33:44 -0700137 u32 rowtear;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800138 u32 rowbar;
139 u32 pad2;
140 u32 rowar;
141 u32 pad3[3];
142};
143
144struct rio_msg_regs {
Shaohui Xieabd12fe2010-10-14 10:04:02 +0800145 u32 omr; /* 0xD_3000 - Outbound message 0 mode register */
146 u32 osr; /* 0xD_3004 - Outbound message 0 status register */
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800147 u32 pad1;
Shaohui Xieabd12fe2010-10-14 10:04:02 +0800148 u32 odqdpar; /* 0xD_300C - Outbound message 0 descriptor queue
149 dequeue pointer address register */
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800150 u32 pad2;
Shaohui Xieabd12fe2010-10-14 10:04:02 +0800151 u32 osar; /* 0xD_3014 - Outbound message 0 source address
152 register */
153 u32 odpr; /* 0xD_3018 - Outbound message 0 destination port
154 register */
155 u32 odatr; /* 0xD_301C - Outbound message 0 destination attributes
156 Register*/
157 u32 odcr; /* 0xD_3020 - Outbound message 0 double-word count
158 register */
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800159 u32 pad3;
Shaohui Xieabd12fe2010-10-14 10:04:02 +0800160 u32 odqepar; /* 0xD_3028 - Outbound message 0 descriptor queue
161 enqueue pointer address register */
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800162 u32 pad4[13];
Shaohui Xieabd12fe2010-10-14 10:04:02 +0800163 u32 imr; /* 0xD_3060 - Inbound message 0 mode register */
164 u32 isr; /* 0xD_3064 - Inbound message 0 status register */
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800165 u32 pad5;
Shaohui Xieabd12fe2010-10-14 10:04:02 +0800166 u32 ifqdpar; /* 0xD_306C - Inbound message 0 frame queue dequeue
167 pointer address register*/
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800168 u32 pad6;
Shaohui Xieabd12fe2010-10-14 10:04:02 +0800169 u32 ifqepar; /* 0xD_3074 - Inbound message 0 frame queue enqueue
170 pointer address register */
Zhang Wei61b26912008-04-18 13:33:44 -0700171 u32 pad7[226];
Shaohui Xieabd12fe2010-10-14 10:04:02 +0800172 u32 odmr; /* 0xD_3400 - Outbound doorbell mode register */
173 u32 odsr; /* 0xD_3404 - Outbound doorbell status register */
Zhang Wei61b26912008-04-18 13:33:44 -0700174 u32 res0[4];
Shaohui Xieabd12fe2010-10-14 10:04:02 +0800175 u32 oddpr; /* 0xD_3418 - Outbound doorbell destination port
176 register */
177 u32 oddatr; /* 0xD_341c - Outbound doorbell destination attributes
178 register */
Zhang Wei61b26912008-04-18 13:33:44 -0700179 u32 res1[3];
Shaohui Xieabd12fe2010-10-14 10:04:02 +0800180 u32 odretcr; /* 0xD_342C - Outbound doorbell retry error threshold
181 configuration register */
Zhang Wei61b26912008-04-18 13:33:44 -0700182 u32 res2[12];
Shaohui Xieabd12fe2010-10-14 10:04:02 +0800183 u32 dmr; /* 0xD_3460 - Inbound doorbell mode register */
184 u32 dsr; /* 0xD_3464 - Inbound doorbell status register */
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800185 u32 pad8;
Shaohui Xieabd12fe2010-10-14 10:04:02 +0800186 u32 dqdpar; /* 0xD_346C - Inbound doorbell queue dequeue Pointer
187 address register */
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800188 u32 pad9;
Shaohui Xieabd12fe2010-10-14 10:04:02 +0800189 u32 dqepar; /* 0xD_3474 - Inbound doorbell Queue enqueue pointer
190 address register */
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800191 u32 pad10[26];
Shaohui Xieabd12fe2010-10-14 10:04:02 +0800192 u32 pwmr; /* 0xD_34E0 - Inbound port-write mode register */
193 u32 pwsr; /* 0xD_34E4 - Inbound port-write status register */
194 u32 epwqbar; /* 0xD_34E8 - Extended Port-Write Queue Base Address
195 register */
196 u32 pwqbar; /* 0xD_34EC - Inbound port-write queue base address
197 register */
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800198};
199
200struct rio_tx_desc {
201 u32 res1;
202 u32 saddr;
203 u32 dport;
204 u32 dattr;
205 u32 res2;
206 u32 res3;
207 u32 dwcnt;
208 u32 res4;
209};
210
Zhang Weiad1e9382008-04-18 13:33:41 -0700211struct rio_dbell_ring {
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800212 void *virt;
213 dma_addr_t phys;
Zhang Weiad1e9382008-04-18 13:33:41 -0700214};
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800215
Zhang Weiad1e9382008-04-18 13:33:41 -0700216struct rio_msg_tx_ring {
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800217 void *virt;
218 dma_addr_t phys;
219 void *virt_buffer[RIO_MAX_TX_RING_SIZE];
220 dma_addr_t phys_buffer[RIO_MAX_TX_RING_SIZE];
221 int tx_slot;
222 int size;
Matt Porter6978bbc2005-11-07 01:00:20 -0800223 void *dev_id;
Zhang Weiad1e9382008-04-18 13:33:41 -0700224};
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800225
Zhang Weiad1e9382008-04-18 13:33:41 -0700226struct rio_msg_rx_ring {
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800227 void *virt;
228 dma_addr_t phys;
229 void *virt_buffer[RIO_MAX_RX_RING_SIZE];
230 int rx_slot;
231 int size;
Matt Porter6978bbc2005-11-07 01:00:20 -0800232 void *dev_id;
Zhang Weiad1e9382008-04-18 13:33:41 -0700233};
234
Alexandre Bounine5b2074a2010-05-26 14:44:00 -0700235struct rio_port_write_msg {
236 void *virt;
237 dma_addr_t phys;
238 u32 msg_count;
239 u32 err_count;
240 u32 discard_count;
241};
242
Zhang Weiad1e9382008-04-18 13:33:41 -0700243struct rio_priv {
Anton Vorontsov0dbbbf12009-04-18 21:48:52 +0400244 struct device *dev;
Zhang Weiad1e9382008-04-18 13:33:41 -0700245 void __iomem *regs_win;
246 struct rio_atmu_regs __iomem *atmu_regs;
247 struct rio_atmu_regs __iomem *maint_atmu_regs;
248 struct rio_atmu_regs __iomem *dbell_atmu_regs;
249 void __iomem *dbell_win;
250 void __iomem *maint_win;
251 struct rio_msg_regs __iomem *msg_regs;
252 struct rio_dbell_ring dbell_ring;
253 struct rio_msg_tx_ring msg_tx_ring;
254 struct rio_msg_rx_ring msg_rx_ring;
Alexandre Bounine5b2074a2010-05-26 14:44:00 -0700255 struct rio_port_write_msg port_write_msg;
Zhang Weiad1e9382008-04-18 13:33:41 -0700256 int bellirq;
257 int txirq;
258 int rxirq;
Alexandre Bounine5b2074a2010-05-26 14:44:00 -0700259 int pwirq;
260 struct work_struct pw_work;
261 struct kfifo pw_fifo;
262 spinlock_t pw_fifo_lock;
Zhang Weiad1e9382008-04-18 13:33:41 -0700263};
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800264
Alexandre Bouninea52c8f52010-05-26 14:44:00 -0700265#define __fsl_read_rio_config(x, addr, err, op) \
266 __asm__ __volatile__( \
267 "1: "op" %1,0(%2)\n" \
268 " eieio\n" \
269 "2:\n" \
270 ".section .fixup,\"ax\"\n" \
271 "3: li %1,-1\n" \
272 " li %0,%3\n" \
273 " b 2b\n" \
274 ".section __ex_table,\"a\"\n" \
275 " .align 2\n" \
276 " .long 1b,3b\n" \
277 ".text" \
278 : "=r" (err), "=r" (x) \
279 : "b" (addr), "i" (-EFAULT), "0" (err))
280
281static void __iomem *rio_regs_win;
282
Li Yangff33f182010-06-18 14:24:20 +0800283#ifdef CONFIG_E500
Shaohui Xiecce1f102010-11-18 14:57:32 +0800284int fsl_rio_mcheck_exception(struct pt_regs *regs)
Alexandre Bouninea52c8f52010-05-26 14:44:00 -0700285{
286 const struct exception_table_entry *entry = NULL;
Li Yangff33f182010-06-18 14:24:20 +0800287 unsigned long reason = mfspr(SPRN_MCSR);
Alexandre Bouninea52c8f52010-05-26 14:44:00 -0700288
289 if (reason & MCSR_BUS_RBERR) {
290 reason = in_be32((u32 *)(rio_regs_win + RIO_LTLEDCSR));
291 if (reason & (RIO_LTLEDCSR_IER | RIO_LTLEDCSR_PRT)) {
292 /* Check if we are prepared to handle this fault */
293 entry = search_exception_tables(regs->nip);
294 if (entry) {
295 pr_debug("RIO: %s - MC Exception handled\n",
296 __func__);
297 out_be32((u32 *)(rio_regs_win + RIO_LTLEDCSR),
298 0);
299 regs->msr |= MSR_RI;
300 regs->nip = entry->fixup;
301 return 1;
302 }
303 }
304 }
305
Shaohui Xiecce1f102010-11-18 14:57:32 +0800306 return 0;
Alexandre Bouninea52c8f52010-05-26 14:44:00 -0700307}
Shaohui Xiecce1f102010-11-18 14:57:32 +0800308EXPORT_SYMBOL_GPL(fsl_rio_mcheck_exception);
Li Yangff33f182010-06-18 14:24:20 +0800309#endif
Alexandre Bouninea52c8f52010-05-26 14:44:00 -0700310
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800311/**
Zhang Weid02443a2008-04-18 13:33:38 -0700312 * fsl_rio_doorbell_send - Send a MPC85xx doorbell message
Randy Dunlap9941d942008-04-30 16:45:58 -0700313 * @mport: RapidIO master port info
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800314 * @index: ID of RapidIO interface
315 * @destid: Destination ID of target device
316 * @data: 16-bit info field of RapidIO doorbell message
317 *
318 * Sends a MPC85xx doorbell message. Returns %0 on success or
319 * %-EINVAL on failure.
320 */
Zhang Weiad1e9382008-04-18 13:33:41 -0700321static int fsl_rio_doorbell_send(struct rio_mport *mport,
322 int index, u16 destid, u16 data)
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800323{
Zhang Weiad1e9382008-04-18 13:33:41 -0700324 struct rio_priv *priv = mport->priv;
Zhang Weid02443a2008-04-18 13:33:38 -0700325 pr_debug("fsl_doorbell_send: index %d destid %4.4x data %4.4x\n",
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800326 index, destid, data);
Zhang Wei61b26912008-04-18 13:33:44 -0700327 switch (mport->phy_type) {
328 case RIO_PHY_PARALLEL:
329 out_be32(&priv->dbell_atmu_regs->rowtar, destid << 22);
330 out_be16(priv->dbell_win, data);
331 break;
332 case RIO_PHY_SERIAL:
333 /* In the serial version silicons, such as MPC8548, MPC8641,
334 * below operations is must be.
335 */
336 out_be32(&priv->msg_regs->odmr, 0x00000000);
337 out_be32(&priv->msg_regs->odretcr, 0x00000004);
338 out_be32(&priv->msg_regs->oddpr, destid << 16);
339 out_be32(&priv->msg_regs->oddatr, data);
340 out_be32(&priv->msg_regs->odmr, 0x00000001);
341 break;
342 }
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800343
344 return 0;
345}
346
347/**
Zhang Weid02443a2008-04-18 13:33:38 -0700348 * fsl_local_config_read - Generate a MPC85xx local config space read
Randy Dunlap9941d942008-04-30 16:45:58 -0700349 * @mport: RapidIO master port info
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800350 * @index: ID of RapdiIO interface
351 * @offset: Offset into configuration space
352 * @len: Length (in bytes) of the maintenance transaction
353 * @data: Value to be read into
354 *
355 * Generates a MPC85xx local configuration space read. Returns %0 on
356 * success or %-EINVAL on failure.
357 */
Zhang Weiad1e9382008-04-18 13:33:41 -0700358static int fsl_local_config_read(struct rio_mport *mport,
359 int index, u32 offset, int len, u32 *data)
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800360{
Zhang Weiad1e9382008-04-18 13:33:41 -0700361 struct rio_priv *priv = mport->priv;
Zhang Weid02443a2008-04-18 13:33:38 -0700362 pr_debug("fsl_local_config_read: index %d offset %8.8x\n", index,
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800363 offset);
Zhang Weiad1e9382008-04-18 13:33:41 -0700364 *data = in_be32(priv->regs_win + offset);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800365
366 return 0;
367}
368
369/**
Zhang Weid02443a2008-04-18 13:33:38 -0700370 * fsl_local_config_write - Generate a MPC85xx local config space write
Randy Dunlap9941d942008-04-30 16:45:58 -0700371 * @mport: RapidIO master port info
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800372 * @index: ID of RapdiIO interface
373 * @offset: Offset into configuration space
374 * @len: Length (in bytes) of the maintenance transaction
375 * @data: Value to be written
376 *
377 * Generates a MPC85xx local configuration space write. Returns %0 on
378 * success or %-EINVAL on failure.
379 */
Zhang Weiad1e9382008-04-18 13:33:41 -0700380static int fsl_local_config_write(struct rio_mport *mport,
381 int index, u32 offset, int len, u32 data)
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800382{
Zhang Weiad1e9382008-04-18 13:33:41 -0700383 struct rio_priv *priv = mport->priv;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800384 pr_debug
Zhang Weid02443a2008-04-18 13:33:38 -0700385 ("fsl_local_config_write: index %d offset %8.8x data %8.8x\n",
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800386 index, offset, data);
Zhang Weiad1e9382008-04-18 13:33:41 -0700387 out_be32(priv->regs_win + offset, data);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800388
389 return 0;
390}
391
392/**
Zhang Weid02443a2008-04-18 13:33:38 -0700393 * fsl_rio_config_read - Generate a MPC85xx read maintenance transaction
Randy Dunlap9941d942008-04-30 16:45:58 -0700394 * @mport: RapidIO master port info
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800395 * @index: ID of RapdiIO interface
396 * @destid: Destination ID of transaction
397 * @hopcount: Number of hops to target device
398 * @offset: Offset into configuration space
399 * @len: Length (in bytes) of the maintenance transaction
400 * @val: Location to be read into
401 *
402 * Generates a MPC85xx read maintenance transaction. Returns %0 on
403 * success or %-EINVAL on failure.
404 */
405static int
Zhang Weiad1e9382008-04-18 13:33:41 -0700406fsl_rio_config_read(struct rio_mport *mport, int index, u16 destid,
407 u8 hopcount, u32 offset, int len, u32 *val)
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800408{
Zhang Weiad1e9382008-04-18 13:33:41 -0700409 struct rio_priv *priv = mport->priv;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800410 u8 *data;
Alexandre Bouninea52c8f52010-05-26 14:44:00 -0700411 u32 rval, err = 0;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800412
413 pr_debug
Zhang Weid02443a2008-04-18 13:33:38 -0700414 ("fsl_rio_config_read: index %d destid %d hopcount %d offset %8.8x len %d\n",
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800415 index, destid, hopcount, offset, len);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800416
Thomas Mollbd4fb652010-05-26 14:44:05 -0700417 /* 16MB maintenance window possible */
418 /* allow only aligned access to maintenance registers */
419 if (offset > (0x1000000 - len) || !IS_ALIGNED(offset, len))
420 return -EINVAL;
421
422 out_be32(&priv->maint_atmu_regs->rowtar,
423 (destid << 22) | (hopcount << 12) | (offset >> 12));
424 out_be32(&priv->maint_atmu_regs->rowtear, (destid >> 10));
425
426 data = (u8 *) priv->maint_win + (offset & (RIO_MAINT_WIN_SIZE - 1));
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800427 switch (len) {
428 case 1:
Alexandre Bouninea52c8f52010-05-26 14:44:00 -0700429 __fsl_read_rio_config(rval, data, err, "lbz");
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800430 break;
431 case 2:
Alexandre Bouninea52c8f52010-05-26 14:44:00 -0700432 __fsl_read_rio_config(rval, data, err, "lhz");
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800433 break;
Thomas Mollbd4fb652010-05-26 14:44:05 -0700434 case 4:
Alexandre Bouninea52c8f52010-05-26 14:44:00 -0700435 __fsl_read_rio_config(rval, data, err, "lwz");
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800436 break;
Thomas Mollbd4fb652010-05-26 14:44:05 -0700437 default:
438 return -EINVAL;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800439 }
440
Alexandre Bouninea52c8f52010-05-26 14:44:00 -0700441 if (err) {
442 pr_debug("RIO: cfg_read error %d for %x:%x:%x\n",
443 err, destid, hopcount, offset);
444 }
445
446 *val = rval;
447
448 return err;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800449}
450
451/**
Zhang Weid02443a2008-04-18 13:33:38 -0700452 * fsl_rio_config_write - Generate a MPC85xx write maintenance transaction
Randy Dunlap9941d942008-04-30 16:45:58 -0700453 * @mport: RapidIO master port info
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800454 * @index: ID of RapdiIO interface
455 * @destid: Destination ID of transaction
456 * @hopcount: Number of hops to target device
457 * @offset: Offset into configuration space
458 * @len: Length (in bytes) of the maintenance transaction
459 * @val: Value to be written
460 *
461 * Generates an MPC85xx write maintenance transaction. Returns %0 on
462 * success or %-EINVAL on failure.
463 */
464static int
Zhang Weiad1e9382008-04-18 13:33:41 -0700465fsl_rio_config_write(struct rio_mport *mport, int index, u16 destid,
466 u8 hopcount, u32 offset, int len, u32 val)
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800467{
Zhang Weiad1e9382008-04-18 13:33:41 -0700468 struct rio_priv *priv = mport->priv;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800469 u8 *data;
470 pr_debug
Zhang Weid02443a2008-04-18 13:33:38 -0700471 ("fsl_rio_config_write: index %d destid %d hopcount %d offset %8.8x len %d val %8.8x\n",
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800472 index, destid, hopcount, offset, len, val);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800473
Thomas Mollbd4fb652010-05-26 14:44:05 -0700474 /* 16MB maintenance windows possible */
475 /* allow only aligned access to maintenance registers */
476 if (offset > (0x1000000 - len) || !IS_ALIGNED(offset, len))
477 return -EINVAL;
478
479 out_be32(&priv->maint_atmu_regs->rowtar,
480 (destid << 22) | (hopcount << 12) | (offset >> 12));
481 out_be32(&priv->maint_atmu_regs->rowtear, (destid >> 10));
482
483 data = (u8 *) priv->maint_win + (offset & (RIO_MAINT_WIN_SIZE - 1));
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800484 switch (len) {
485 case 1:
486 out_8((u8 *) data, val);
487 break;
488 case 2:
489 out_be16((u16 *) data, val);
490 break;
Thomas Mollbd4fb652010-05-26 14:44:05 -0700491 case 4:
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800492 out_be32((u32 *) data, val);
493 break;
Thomas Mollbd4fb652010-05-26 14:44:05 -0700494 default:
495 return -EINVAL;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800496 }
497
498 return 0;
499}
500
501/**
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700502 * fsl_add_outb_message - Add message to the MPC85xx outbound message queue
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800503 * @mport: Master port with outbound message queue
504 * @rdev: Target of outbound message
505 * @mbox: Outbound mailbox
506 * @buffer: Message to add to outbound queue
507 * @len: Length of message
508 *
509 * Adds the @buffer message to the MPC85xx outbound message queue. Returns
510 * %0 on success or %-EINVAL on failure.
511 */
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700512static int
513fsl_add_outb_message(struct rio_mport *mport, struct rio_dev *rdev, int mbox,
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800514 void *buffer, size_t len)
515{
Zhang Weiad1e9382008-04-18 13:33:41 -0700516 struct rio_priv *priv = mport->priv;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800517 u32 omr;
Zhang Weiad1e9382008-04-18 13:33:41 -0700518 struct rio_tx_desc *desc = (struct rio_tx_desc *)priv->msg_tx_ring.virt
519 + priv->msg_tx_ring.tx_slot;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800520 int ret = 0;
521
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700522 pr_debug("RIO: fsl_add_outb_message(): destid %4.4x mbox %d buffer " \
523 "%8.8x len %8.8x\n", rdev->destid, mbox, (int)buffer, len);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800524
525 if ((len < 8) || (len > RIO_MAX_MSG_SIZE)) {
526 ret = -EINVAL;
527 goto out;
528 }
529
530 /* Copy and clear rest of buffer */
Zhang Weiad1e9382008-04-18 13:33:41 -0700531 memcpy(priv->msg_tx_ring.virt_buffer[priv->msg_tx_ring.tx_slot], buffer,
532 len);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800533 if (len < (RIO_MAX_MSG_SIZE - 4))
Zhang Weiad1e9382008-04-18 13:33:41 -0700534 memset(priv->msg_tx_ring.virt_buffer[priv->msg_tx_ring.tx_slot]
535 + len, 0, RIO_MAX_MSG_SIZE - len);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800536
Zhang Wei61b26912008-04-18 13:33:44 -0700537 switch (mport->phy_type) {
538 case RIO_PHY_PARALLEL:
539 /* Set mbox field for message */
540 desc->dport = mbox & 0x3;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800541
Zhang Wei61b26912008-04-18 13:33:44 -0700542 /* Enable EOMI interrupt, set priority, and set destid */
543 desc->dattr = 0x28000000 | (rdev->destid << 2);
544 break;
545 case RIO_PHY_SERIAL:
546 /* Set mbox field for message, and set destid */
547 desc->dport = (rdev->destid << 16) | (mbox & 0x3);
548
549 /* Enable EOMI interrupt and priority */
550 desc->dattr = 0x28000000;
551 break;
552 }
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800553
554 /* Set transfer size aligned to next power of 2 (in double words) */
555 desc->dwcnt = is_power_of_2(len) ? len : 1 << get_bitmask_order(len);
556
557 /* Set snooping and source buffer address */
Zhang Weiad1e9382008-04-18 13:33:41 -0700558 desc->saddr = 0x00000004
559 | priv->msg_tx_ring.phys_buffer[priv->msg_tx_ring.tx_slot];
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800560
561 /* Increment enqueue pointer */
Zhang Weiad1e9382008-04-18 13:33:41 -0700562 omr = in_be32(&priv->msg_regs->omr);
563 out_be32(&priv->msg_regs->omr, omr | RIO_MSG_OMR_MUI);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800564
565 /* Go to next descriptor */
Zhang Weiad1e9382008-04-18 13:33:41 -0700566 if (++priv->msg_tx_ring.tx_slot == priv->msg_tx_ring.size)
567 priv->msg_tx_ring.tx_slot = 0;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800568
569 out:
570 return ret;
571}
572
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800573/**
Zhang Weid02443a2008-04-18 13:33:38 -0700574 * fsl_rio_tx_handler - MPC85xx outbound message interrupt handler
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800575 * @irq: Linux interrupt number
576 * @dev_instance: Pointer to interrupt-specific data
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800577 *
578 * Handles outbound message interrupts. Executes a register outbound
Simon Arlotta8de5ce2007-05-12 05:42:54 +1000579 * mailbox event handler and acks the interrupt occurrence.
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800580 */
581static irqreturn_t
Zhang Weid02443a2008-04-18 13:33:38 -0700582fsl_rio_tx_handler(int irq, void *dev_instance)
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800583{
584 int osr;
585 struct rio_mport *port = (struct rio_mport *)dev_instance;
Zhang Weiad1e9382008-04-18 13:33:41 -0700586 struct rio_priv *priv = port->priv;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800587
Zhang Weiad1e9382008-04-18 13:33:41 -0700588 osr = in_be32(&priv->msg_regs->osr);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800589
590 if (osr & RIO_MSG_OSR_TE) {
591 pr_info("RIO: outbound message transmission error\n");
Zhang Weiad1e9382008-04-18 13:33:41 -0700592 out_be32(&priv->msg_regs->osr, RIO_MSG_OSR_TE);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800593 goto out;
594 }
595
596 if (osr & RIO_MSG_OSR_QOI) {
597 pr_info("RIO: outbound message queue overflow\n");
Zhang Weiad1e9382008-04-18 13:33:41 -0700598 out_be32(&priv->msg_regs->osr, RIO_MSG_OSR_QOI);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800599 goto out;
600 }
601
602 if (osr & RIO_MSG_OSR_EOMI) {
Zhang Weiad1e9382008-04-18 13:33:41 -0700603 u32 dqp = in_be32(&priv->msg_regs->odqdpar);
604 int slot = (dqp - priv->msg_tx_ring.phys) >> 5;
605 port->outb_msg[0].mcback(port, priv->msg_tx_ring.dev_id, -1,
606 slot);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800607
608 /* Ack the end-of-message interrupt */
Zhang Weiad1e9382008-04-18 13:33:41 -0700609 out_be32(&priv->msg_regs->osr, RIO_MSG_OSR_EOMI);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800610 }
611
612 out:
613 return IRQ_HANDLED;
614}
615
616/**
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700617 * fsl_open_outb_mbox - Initialize MPC85xx outbound mailbox
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800618 * @mport: Master port implementing the outbound message unit
Matt Porter6978bbc2005-11-07 01:00:20 -0800619 * @dev_id: Device specific pointer to pass on event
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800620 * @mbox: Mailbox to open
621 * @entries: Number of entries in the outbound mailbox ring
622 *
623 * Initializes buffer ring, request the outbound message interrupt,
624 * and enables the outbound message unit. Returns %0 on success and
625 * %-EINVAL or %-ENOMEM on failure.
626 */
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700627static int
628fsl_open_outb_mbox(struct rio_mport *mport, void *dev_id, int mbox, int entries)
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800629{
630 int i, j, rc = 0;
Zhang Weiad1e9382008-04-18 13:33:41 -0700631 struct rio_priv *priv = mport->priv;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800632
633 if ((entries < RIO_MIN_TX_RING_SIZE) ||
634 (entries > RIO_MAX_TX_RING_SIZE) || (!is_power_of_2(entries))) {
635 rc = -EINVAL;
636 goto out;
637 }
638
639 /* Initialize shadow copy ring */
Zhang Weiad1e9382008-04-18 13:33:41 -0700640 priv->msg_tx_ring.dev_id = dev_id;
641 priv->msg_tx_ring.size = entries;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800642
Zhang Weiad1e9382008-04-18 13:33:41 -0700643 for (i = 0; i < priv->msg_tx_ring.size; i++) {
644 priv->msg_tx_ring.virt_buffer[i] =
Anton Vorontsov0dbbbf12009-04-18 21:48:52 +0400645 dma_alloc_coherent(priv->dev, RIO_MSG_BUFFER_SIZE,
Zhang Weiad1e9382008-04-18 13:33:41 -0700646 &priv->msg_tx_ring.phys_buffer[i], GFP_KERNEL);
647 if (!priv->msg_tx_ring.virt_buffer[i]) {
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800648 rc = -ENOMEM;
Zhang Weiad1e9382008-04-18 13:33:41 -0700649 for (j = 0; j < priv->msg_tx_ring.size; j++)
650 if (priv->msg_tx_ring.virt_buffer[j])
Anton Vorontsov0dbbbf12009-04-18 21:48:52 +0400651 dma_free_coherent(priv->dev,
Zhang Weiad1e9382008-04-18 13:33:41 -0700652 RIO_MSG_BUFFER_SIZE,
653 priv->msg_tx_ring.
654 virt_buffer[j],
655 priv->msg_tx_ring.
656 phys_buffer[j]);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800657 goto out;
658 }
659 }
660
661 /* Initialize outbound message descriptor ring */
Anton Vorontsov0dbbbf12009-04-18 21:48:52 +0400662 priv->msg_tx_ring.virt = dma_alloc_coherent(priv->dev,
Zhang Weiad1e9382008-04-18 13:33:41 -0700663 priv->msg_tx_ring.size * RIO_MSG_DESC_SIZE,
664 &priv->msg_tx_ring.phys, GFP_KERNEL);
665 if (!priv->msg_tx_ring.virt) {
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800666 rc = -ENOMEM;
667 goto out_dma;
668 }
Zhang Weiad1e9382008-04-18 13:33:41 -0700669 memset(priv->msg_tx_ring.virt, 0,
670 priv->msg_tx_ring.size * RIO_MSG_DESC_SIZE);
671 priv->msg_tx_ring.tx_slot = 0;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800672
673 /* Point dequeue/enqueue pointers at first entry in ring */
Zhang Weiad1e9382008-04-18 13:33:41 -0700674 out_be32(&priv->msg_regs->odqdpar, priv->msg_tx_ring.phys);
675 out_be32(&priv->msg_regs->odqepar, priv->msg_tx_ring.phys);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800676
677 /* Configure for snooping */
Zhang Weiad1e9382008-04-18 13:33:41 -0700678 out_be32(&priv->msg_regs->osar, 0x00000004);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800679
680 /* Clear interrupt status */
Zhang Weiad1e9382008-04-18 13:33:41 -0700681 out_be32(&priv->msg_regs->osr, 0x000000b3);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800682
683 /* Hook up outbound message handler */
Zhang Weiad1e9382008-04-18 13:33:41 -0700684 rc = request_irq(IRQ_RIO_TX(mport), fsl_rio_tx_handler, 0,
685 "msg_tx", (void *)mport);
686 if (rc < 0)
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800687 goto out_irq;
688
689 /*
690 * Configure outbound message unit
691 * Snooping
692 * Interrupts (all enabled, except QEIE)
693 * Chaining mode
694 * Disable
695 */
Zhang Weiad1e9382008-04-18 13:33:41 -0700696 out_be32(&priv->msg_regs->omr, 0x00100220);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800697
698 /* Set number of entries */
Zhang Weiad1e9382008-04-18 13:33:41 -0700699 out_be32(&priv->msg_regs->omr,
700 in_be32(&priv->msg_regs->omr) |
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800701 ((get_bitmask_order(entries) - 2) << 12));
702
703 /* Now enable the unit */
Zhang Weiad1e9382008-04-18 13:33:41 -0700704 out_be32(&priv->msg_regs->omr, in_be32(&priv->msg_regs->omr) | 0x1);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800705
706 out:
707 return rc;
708
709 out_irq:
Anton Vorontsov0dbbbf12009-04-18 21:48:52 +0400710 dma_free_coherent(priv->dev,
711 priv->msg_tx_ring.size * RIO_MSG_DESC_SIZE,
Zhang Weiad1e9382008-04-18 13:33:41 -0700712 priv->msg_tx_ring.virt, priv->msg_tx_ring.phys);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800713
714 out_dma:
Zhang Weiad1e9382008-04-18 13:33:41 -0700715 for (i = 0; i < priv->msg_tx_ring.size; i++)
Anton Vorontsov0dbbbf12009-04-18 21:48:52 +0400716 dma_free_coherent(priv->dev, RIO_MSG_BUFFER_SIZE,
Zhang Weiad1e9382008-04-18 13:33:41 -0700717 priv->msg_tx_ring.virt_buffer[i],
718 priv->msg_tx_ring.phys_buffer[i]);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800719
720 return rc;
721}
722
723/**
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700724 * fsl_close_outb_mbox - Shut down MPC85xx outbound mailbox
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800725 * @mport: Master port implementing the outbound message unit
726 * @mbox: Mailbox to close
727 *
728 * Disables the outbound message unit, free all buffers, and
729 * frees the outbound message interrupt.
730 */
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700731static void fsl_close_outb_mbox(struct rio_mport *mport, int mbox)
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800732{
Zhang Weiad1e9382008-04-18 13:33:41 -0700733 struct rio_priv *priv = mport->priv;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800734 /* Disable inbound message unit */
Zhang Weiad1e9382008-04-18 13:33:41 -0700735 out_be32(&priv->msg_regs->omr, 0);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800736
737 /* Free ring */
Anton Vorontsov0dbbbf12009-04-18 21:48:52 +0400738 dma_free_coherent(priv->dev,
739 priv->msg_tx_ring.size * RIO_MSG_DESC_SIZE,
Zhang Weiad1e9382008-04-18 13:33:41 -0700740 priv->msg_tx_ring.virt, priv->msg_tx_ring.phys);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800741
742 /* Free interrupt */
Zhang Weiad1e9382008-04-18 13:33:41 -0700743 free_irq(IRQ_RIO_TX(mport), (void *)mport);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800744}
745
746/**
Zhang Weid02443a2008-04-18 13:33:38 -0700747 * fsl_rio_rx_handler - MPC85xx inbound message interrupt handler
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800748 * @irq: Linux interrupt number
749 * @dev_instance: Pointer to interrupt-specific data
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800750 *
751 * Handles inbound message interrupts. Executes a registered inbound
Simon Arlotta8de5ce2007-05-12 05:42:54 +1000752 * mailbox event handler and acks the interrupt occurrence.
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800753 */
754static irqreturn_t
Zhang Weid02443a2008-04-18 13:33:38 -0700755fsl_rio_rx_handler(int irq, void *dev_instance)
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800756{
757 int isr;
758 struct rio_mport *port = (struct rio_mport *)dev_instance;
Zhang Weiad1e9382008-04-18 13:33:41 -0700759 struct rio_priv *priv = port->priv;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800760
Zhang Weiad1e9382008-04-18 13:33:41 -0700761 isr = in_be32(&priv->msg_regs->isr);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800762
763 if (isr & RIO_MSG_ISR_TE) {
764 pr_info("RIO: inbound message reception error\n");
Zhang Weiad1e9382008-04-18 13:33:41 -0700765 out_be32((void *)&priv->msg_regs->isr, RIO_MSG_ISR_TE);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800766 goto out;
767 }
768
769 /* XXX Need to check/dispatch until queue empty */
770 if (isr & RIO_MSG_ISR_DIQI) {
771 /*
772 * We implement *only* mailbox 0, but can receive messages
773 * for any mailbox/letter to that mailbox destination. So,
774 * make the callback with an unknown/invalid mailbox number
775 * argument.
776 */
Zhang Weiad1e9382008-04-18 13:33:41 -0700777 port->inb_msg[0].mcback(port, priv->msg_rx_ring.dev_id, -1, -1);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800778
779 /* Ack the queueing interrupt */
Zhang Weiad1e9382008-04-18 13:33:41 -0700780 out_be32(&priv->msg_regs->isr, RIO_MSG_ISR_DIQI);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800781 }
782
783 out:
784 return IRQ_HANDLED;
785}
786
787/**
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700788 * fsl_open_inb_mbox - Initialize MPC85xx inbound mailbox
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800789 * @mport: Master port implementing the inbound message unit
Matt Porter6978bbc2005-11-07 01:00:20 -0800790 * @dev_id: Device specific pointer to pass on event
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800791 * @mbox: Mailbox to open
792 * @entries: Number of entries in the inbound mailbox ring
793 *
794 * Initializes buffer ring, request the inbound message interrupt,
795 * and enables the inbound message unit. Returns %0 on success
796 * and %-EINVAL or %-ENOMEM on failure.
797 */
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700798static int
799fsl_open_inb_mbox(struct rio_mport *mport, void *dev_id, int mbox, int entries)
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800800{
801 int i, rc = 0;
Zhang Weiad1e9382008-04-18 13:33:41 -0700802 struct rio_priv *priv = mport->priv;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800803
804 if ((entries < RIO_MIN_RX_RING_SIZE) ||
805 (entries > RIO_MAX_RX_RING_SIZE) || (!is_power_of_2(entries))) {
806 rc = -EINVAL;
807 goto out;
808 }
809
810 /* Initialize client buffer ring */
Zhang Weiad1e9382008-04-18 13:33:41 -0700811 priv->msg_rx_ring.dev_id = dev_id;
812 priv->msg_rx_ring.size = entries;
813 priv->msg_rx_ring.rx_slot = 0;
814 for (i = 0; i < priv->msg_rx_ring.size; i++)
815 priv->msg_rx_ring.virt_buffer[i] = NULL;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800816
817 /* Initialize inbound message ring */
Anton Vorontsov0dbbbf12009-04-18 21:48:52 +0400818 priv->msg_rx_ring.virt = dma_alloc_coherent(priv->dev,
Zhang Weiad1e9382008-04-18 13:33:41 -0700819 priv->msg_rx_ring.size * RIO_MAX_MSG_SIZE,
820 &priv->msg_rx_ring.phys, GFP_KERNEL);
821 if (!priv->msg_rx_ring.virt) {
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800822 rc = -ENOMEM;
823 goto out;
824 }
825
826 /* Point dequeue/enqueue pointers at first entry in ring */
Zhang Weiad1e9382008-04-18 13:33:41 -0700827 out_be32(&priv->msg_regs->ifqdpar, (u32) priv->msg_rx_ring.phys);
828 out_be32(&priv->msg_regs->ifqepar, (u32) priv->msg_rx_ring.phys);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800829
830 /* Clear interrupt status */
Zhang Weiad1e9382008-04-18 13:33:41 -0700831 out_be32(&priv->msg_regs->isr, 0x00000091);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800832
833 /* Hook up inbound message handler */
Zhang Weiad1e9382008-04-18 13:33:41 -0700834 rc = request_irq(IRQ_RIO_RX(mport), fsl_rio_rx_handler, 0,
835 "msg_rx", (void *)mport);
836 if (rc < 0) {
Anton Vorontsov0dbbbf12009-04-18 21:48:52 +0400837 dma_free_coherent(priv->dev, RIO_MSG_BUFFER_SIZE,
Zhang Weiad1e9382008-04-18 13:33:41 -0700838 priv->msg_tx_ring.virt_buffer[i],
839 priv->msg_tx_ring.phys_buffer[i]);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800840 goto out;
841 }
842
843 /*
844 * Configure inbound message unit:
845 * Snooping
846 * 4KB max message size
847 * Unmask all interrupt sources
848 * Disable
849 */
Zhang Weiad1e9382008-04-18 13:33:41 -0700850 out_be32(&priv->msg_regs->imr, 0x001b0060);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800851
852 /* Set number of queue entries */
Zhang Weiad1e9382008-04-18 13:33:41 -0700853 setbits32(&priv->msg_regs->imr, (get_bitmask_order(entries) - 2) << 12);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800854
855 /* Now enable the unit */
Zhang Weiad1e9382008-04-18 13:33:41 -0700856 setbits32(&priv->msg_regs->imr, 0x1);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800857
858 out:
859 return rc;
860}
861
862/**
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700863 * fsl_close_inb_mbox - Shut down MPC85xx inbound mailbox
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800864 * @mport: Master port implementing the inbound message unit
865 * @mbox: Mailbox to close
866 *
867 * Disables the inbound message unit, free all buffers, and
868 * frees the inbound message interrupt.
869 */
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700870static void fsl_close_inb_mbox(struct rio_mport *mport, int mbox)
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800871{
Zhang Weiad1e9382008-04-18 13:33:41 -0700872 struct rio_priv *priv = mport->priv;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800873 /* Disable inbound message unit */
Zhang Weiad1e9382008-04-18 13:33:41 -0700874 out_be32(&priv->msg_regs->imr, 0);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800875
876 /* Free ring */
Anton Vorontsov0dbbbf12009-04-18 21:48:52 +0400877 dma_free_coherent(priv->dev, priv->msg_rx_ring.size * RIO_MAX_MSG_SIZE,
Zhang Weiad1e9382008-04-18 13:33:41 -0700878 priv->msg_rx_ring.virt, priv->msg_rx_ring.phys);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800879
880 /* Free interrupt */
Zhang Weiad1e9382008-04-18 13:33:41 -0700881 free_irq(IRQ_RIO_RX(mport), (void *)mport);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800882}
883
884/**
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700885 * fsl_add_inb_buffer - Add buffer to the MPC85xx inbound message queue
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800886 * @mport: Master port implementing the inbound message unit
887 * @mbox: Inbound mailbox number
888 * @buf: Buffer to add to inbound queue
889 *
890 * Adds the @buf buffer to the MPC85xx inbound message queue. Returns
891 * %0 on success or %-EINVAL on failure.
892 */
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700893static int fsl_add_inb_buffer(struct rio_mport *mport, int mbox, void *buf)
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800894{
895 int rc = 0;
Zhang Weiad1e9382008-04-18 13:33:41 -0700896 struct rio_priv *priv = mport->priv;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800897
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700898 pr_debug("RIO: fsl_add_inb_buffer(), msg_rx_ring.rx_slot %d\n",
Zhang Weiad1e9382008-04-18 13:33:41 -0700899 priv->msg_rx_ring.rx_slot);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800900
Zhang Weiad1e9382008-04-18 13:33:41 -0700901 if (priv->msg_rx_ring.virt_buffer[priv->msg_rx_ring.rx_slot]) {
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800902 printk(KERN_ERR
903 "RIO: error adding inbound buffer %d, buffer exists\n",
Zhang Weiad1e9382008-04-18 13:33:41 -0700904 priv->msg_rx_ring.rx_slot);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800905 rc = -EINVAL;
906 goto out;
907 }
908
Zhang Weiad1e9382008-04-18 13:33:41 -0700909 priv->msg_rx_ring.virt_buffer[priv->msg_rx_ring.rx_slot] = buf;
910 if (++priv->msg_rx_ring.rx_slot == priv->msg_rx_ring.size)
911 priv->msg_rx_ring.rx_slot = 0;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800912
913 out:
914 return rc;
915}
916
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800917/**
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700918 * fsl_get_inb_message - Fetch inbound message from the MPC85xx message unit
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800919 * @mport: Master port implementing the inbound message unit
920 * @mbox: Inbound mailbox number
921 *
922 * Gets the next available inbound message from the inbound message queue.
923 * A pointer to the message is returned on success or NULL on failure.
924 */
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700925static void *fsl_get_inb_message(struct rio_mport *mport, int mbox)
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800926{
Zhang Weiad1e9382008-04-18 13:33:41 -0700927 struct rio_priv *priv = mport->priv;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800928 u32 phys_buf, virt_buf;
929 void *buf = NULL;
930 int buf_idx;
931
Zhang Weiad1e9382008-04-18 13:33:41 -0700932 phys_buf = in_be32(&priv->msg_regs->ifqdpar);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800933
934 /* If no more messages, then bail out */
Zhang Weiad1e9382008-04-18 13:33:41 -0700935 if (phys_buf == in_be32(&priv->msg_regs->ifqepar))
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800936 goto out2;
937
Zhang Weiad1e9382008-04-18 13:33:41 -0700938 virt_buf = (u32) priv->msg_rx_ring.virt + (phys_buf
939 - priv->msg_rx_ring.phys);
940 buf_idx = (phys_buf - priv->msg_rx_ring.phys) / RIO_MAX_MSG_SIZE;
941 buf = priv->msg_rx_ring.virt_buffer[buf_idx];
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800942
943 if (!buf) {
944 printk(KERN_ERR
945 "RIO: inbound message copy failed, no buffers\n");
946 goto out1;
947 }
948
949 /* Copy max message size, caller is expected to allocate that big */
950 memcpy(buf, (void *)virt_buf, RIO_MAX_MSG_SIZE);
951
952 /* Clear the available buffer */
Zhang Weiad1e9382008-04-18 13:33:41 -0700953 priv->msg_rx_ring.virt_buffer[buf_idx] = NULL;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800954
955 out1:
Zhang Weiad1e9382008-04-18 13:33:41 -0700956 setbits32(&priv->msg_regs->imr, RIO_MSG_IMR_MI);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800957
958 out2:
959 return buf;
960}
961
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800962/**
Zhang Weid02443a2008-04-18 13:33:38 -0700963 * fsl_rio_dbell_handler - MPC85xx doorbell interrupt handler
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800964 * @irq: Linux interrupt number
965 * @dev_instance: Pointer to interrupt-specific data
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800966 *
967 * Handles doorbell interrupts. Parses a list of registered
968 * doorbell event handlers and executes a matching event handler.
969 */
970static irqreturn_t
Zhang Weid02443a2008-04-18 13:33:38 -0700971fsl_rio_dbell_handler(int irq, void *dev_instance)
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800972{
973 int dsr;
974 struct rio_mport *port = (struct rio_mport *)dev_instance;
Zhang Weiad1e9382008-04-18 13:33:41 -0700975 struct rio_priv *priv = port->priv;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800976
Zhang Weiad1e9382008-04-18 13:33:41 -0700977 dsr = in_be32(&priv->msg_regs->dsr);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800978
979 if (dsr & DOORBELL_DSR_TE) {
980 pr_info("RIO: doorbell reception error\n");
Zhang Weiad1e9382008-04-18 13:33:41 -0700981 out_be32(&priv->msg_regs->dsr, DOORBELL_DSR_TE);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800982 goto out;
983 }
984
985 if (dsr & DOORBELL_DSR_QFI) {
986 pr_info("RIO: doorbell queue full\n");
Zhang Weiad1e9382008-04-18 13:33:41 -0700987 out_be32(&priv->msg_regs->dsr, DOORBELL_DSR_QFI);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800988 }
989
990 /* XXX Need to check/dispatch until queue empty */
991 if (dsr & DOORBELL_DSR_DIQI) {
992 u32 dmsg =
Zhang Weiad1e9382008-04-18 13:33:41 -0700993 (u32) priv->dbell_ring.virt +
994 (in_be32(&priv->msg_regs->dqdpar) & 0xfff);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -0800995 struct rio_dbell *dbell;
996 int found = 0;
997
998 pr_debug
999 ("RIO: processing doorbell, sid %2.2x tid %2.2x info %4.4x\n",
1000 DBELL_SID(dmsg), DBELL_TID(dmsg), DBELL_INF(dmsg));
1001
1002 list_for_each_entry(dbell, &port->dbells, node) {
1003 if ((dbell->res->start <= DBELL_INF(dmsg)) &&
1004 (dbell->res->end >= DBELL_INF(dmsg))) {
1005 found = 1;
1006 break;
1007 }
1008 }
1009 if (found) {
Matt Porter6978bbc2005-11-07 01:00:20 -08001010 dbell->dinb(port, dbell->dev_id, DBELL_SID(dmsg), DBELL_TID(dmsg),
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001011 DBELL_INF(dmsg));
1012 } else {
1013 pr_debug
1014 ("RIO: spurious doorbell, sid %2.2x tid %2.2x info %4.4x\n",
1015 DBELL_SID(dmsg), DBELL_TID(dmsg), DBELL_INF(dmsg));
1016 }
Zhang Weiad1e9382008-04-18 13:33:41 -07001017 setbits32(&priv->msg_regs->dmr, DOORBELL_DMR_DI);
1018 out_be32(&priv->msg_regs->dsr, DOORBELL_DSR_DIQI);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001019 }
1020
1021 out:
1022 return IRQ_HANDLED;
1023}
1024
1025/**
Zhang Weid02443a2008-04-18 13:33:38 -07001026 * fsl_rio_doorbell_init - MPC85xx doorbell interface init
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001027 * @mport: Master port implementing the inbound doorbell unit
1028 *
1029 * Initializes doorbell unit hardware and inbound DMA buffer
Zhang Weid02443a2008-04-18 13:33:38 -07001030 * ring. Called from fsl_rio_setup(). Returns %0 on success
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001031 * or %-ENOMEM on failure.
1032 */
Zhang Weid02443a2008-04-18 13:33:38 -07001033static int fsl_rio_doorbell_init(struct rio_mport *mport)
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001034{
Zhang Weiad1e9382008-04-18 13:33:41 -07001035 struct rio_priv *priv = mport->priv;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001036 int rc = 0;
1037
1038 /* Map outbound doorbell window immediately after maintenance window */
Zhang Weiad1e9382008-04-18 13:33:41 -07001039 priv->dbell_win = ioremap(mport->iores.start + RIO_MAINT_WIN_SIZE,
1040 RIO_DBELL_WIN_SIZE);
1041 if (!priv->dbell_win) {
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001042 printk(KERN_ERR
1043 "RIO: unable to map outbound doorbell window\n");
1044 rc = -ENOMEM;
1045 goto out;
1046 }
1047
1048 /* Initialize inbound doorbells */
Anton Vorontsov0dbbbf12009-04-18 21:48:52 +04001049 priv->dbell_ring.virt = dma_alloc_coherent(priv->dev, 512 *
Zhang Weiad1e9382008-04-18 13:33:41 -07001050 DOORBELL_MESSAGE_SIZE, &priv->dbell_ring.phys, GFP_KERNEL);
1051 if (!priv->dbell_ring.virt) {
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001052 printk(KERN_ERR "RIO: unable allocate inbound doorbell ring\n");
1053 rc = -ENOMEM;
Zhang Weiad1e9382008-04-18 13:33:41 -07001054 iounmap(priv->dbell_win);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001055 goto out;
1056 }
1057
1058 /* Point dequeue/enqueue pointers at first entry in ring */
Zhang Weiad1e9382008-04-18 13:33:41 -07001059 out_be32(&priv->msg_regs->dqdpar, (u32) priv->dbell_ring.phys);
1060 out_be32(&priv->msg_regs->dqepar, (u32) priv->dbell_ring.phys);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001061
1062 /* Clear interrupt status */
Zhang Weiad1e9382008-04-18 13:33:41 -07001063 out_be32(&priv->msg_regs->dsr, 0x00000091);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001064
1065 /* Hook up doorbell handler */
Zhang Weiad1e9382008-04-18 13:33:41 -07001066 rc = request_irq(IRQ_RIO_BELL(mport), fsl_rio_dbell_handler, 0,
1067 "dbell_rx", (void *)mport);
1068 if (rc < 0) {
1069 iounmap(priv->dbell_win);
Anton Vorontsov0dbbbf12009-04-18 21:48:52 +04001070 dma_free_coherent(priv->dev, 512 * DOORBELL_MESSAGE_SIZE,
Zhang Weiad1e9382008-04-18 13:33:41 -07001071 priv->dbell_ring.virt, priv->dbell_ring.phys);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001072 printk(KERN_ERR
1073 "MPC85xx RIO: unable to request inbound doorbell irq");
1074 goto out;
1075 }
1076
1077 /* Configure doorbells for snooping, 512 entries, and enable */
Zhang Weiad1e9382008-04-18 13:33:41 -07001078 out_be32(&priv->msg_regs->dmr, 0x00108161);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001079
1080 out:
1081 return rc;
1082}
1083
Shaohui Xie6ff31452010-11-18 14:57:53 +08001084static void port_error_handler(struct rio_mport *port, int offset)
1085{
1086 /*XXX: Error recovery is not implemented, we just clear errors */
1087 out_be32((u32 *)(rio_regs_win + RIO_LTLEDCSR), 0);
1088
1089 if (offset == 0) {
1090 out_be32((u32 *)(rio_regs_win + RIO_PORT1_EDCSR), 0);
1091 out_be32((u32 *)(rio_regs_win + RIO_PORT1_IECSR), 0);
1092 out_be32((u32 *)(rio_regs_win + RIO_ESCSR), ESCSR_CLEAR);
1093 } else {
1094 out_be32((u32 *)(rio_regs_win + RIO_PORT2_EDCSR), 0);
1095 out_be32((u32 *)(rio_regs_win + RIO_PORT2_IECSR), 0);
1096 out_be32((u32 *)(rio_regs_win + RIO_PORT2_ESCSR), ESCSR_CLEAR);
1097 }
1098}
1099
1100static void msg_unit_error_handler(struct rio_mport *port)
1101{
1102 struct rio_priv *priv = port->priv;
1103
1104 /*XXX: Error recovery is not implemented, we just clear errors */
1105 out_be32((u32 *)(rio_regs_win + RIO_LTLEDCSR), 0);
1106
1107 out_be32((u32 *)(rio_regs_win + RIO_IM0SR), IMSR_CLEAR);
1108 out_be32((u32 *)(rio_regs_win + RIO_IM1SR), IMSR_CLEAR);
1109 out_be32((u32 *)(rio_regs_win + RIO_OM0SR), OMSR_CLEAR);
1110 out_be32((u32 *)(rio_regs_win + RIO_OM1SR), OMSR_CLEAR);
1111
1112 out_be32(&priv->msg_regs->odsr, ODSR_CLEAR);
1113 out_be32(&priv->msg_regs->dsr, IDSR_CLEAR);
1114
1115 out_be32(&priv->msg_regs->pwsr, IPWSR_CLEAR);
1116}
1117
Alexandre Bounine5b2074a2010-05-26 14:44:00 -07001118/**
1119 * fsl_rio_port_write_handler - MPC85xx port write interrupt handler
1120 * @irq: Linux interrupt number
1121 * @dev_instance: Pointer to interrupt-specific data
1122 *
1123 * Handles port write interrupts. Parses a list of registered
1124 * port write event handlers and executes a matching event handler.
1125 */
1126static irqreturn_t
1127fsl_rio_port_write_handler(int irq, void *dev_instance)
1128{
1129 u32 ipwmr, ipwsr;
1130 struct rio_mport *port = (struct rio_mport *)dev_instance;
1131 struct rio_priv *priv = port->priv;
1132 u32 epwisr, tmp;
1133
Alexandre Bounine93e2cbd2010-10-27 15:34:28 -07001134 epwisr = in_be32(priv->regs_win + RIO_EPWISR);
1135 if (!(epwisr & RIO_EPWISR_PW))
1136 goto pw_done;
1137
Alexandre Bounine5b2074a2010-05-26 14:44:00 -07001138 ipwmr = in_be32(&priv->msg_regs->pwmr);
1139 ipwsr = in_be32(&priv->msg_regs->pwsr);
1140
Alexandre Bounine5b2074a2010-05-26 14:44:00 -07001141#ifdef DEBUG_PW
1142 pr_debug("PW Int->IPWMR: 0x%08x IPWSR: 0x%08x (", ipwmr, ipwsr);
1143 if (ipwsr & RIO_IPWSR_QF)
1144 pr_debug(" QF");
1145 if (ipwsr & RIO_IPWSR_TE)
1146 pr_debug(" TE");
1147 if (ipwsr & RIO_IPWSR_QFI)
1148 pr_debug(" QFI");
1149 if (ipwsr & RIO_IPWSR_PWD)
1150 pr_debug(" PWD");
1151 if (ipwsr & RIO_IPWSR_PWB)
1152 pr_debug(" PWB");
1153 pr_debug(" )\n");
1154#endif
Alexandre Bounine5b2074a2010-05-26 14:44:00 -07001155 /* Schedule deferred processing if PW was received */
1156 if (ipwsr & RIO_IPWSR_QFI) {
1157 /* Save PW message (if there is room in FIFO),
1158 * otherwise discard it.
1159 */
1160 if (kfifo_avail(&priv->pw_fifo) >= RIO_PW_MSG_SIZE) {
1161 priv->port_write_msg.msg_count++;
1162 kfifo_in(&priv->pw_fifo, priv->port_write_msg.virt,
1163 RIO_PW_MSG_SIZE);
1164 } else {
1165 priv->port_write_msg.discard_count++;
Alexandre Bounine93e2cbd2010-10-27 15:34:28 -07001166 pr_debug("RIO: ISR Discarded Port-Write Msg(s) (%d)\n",
Alexandre Bounine5b2074a2010-05-26 14:44:00 -07001167 priv->port_write_msg.discard_count);
1168 }
Alexandre Bounine93e2cbd2010-10-27 15:34:28 -07001169 /* Clear interrupt and issue Clear Queue command. This allows
1170 * another port-write to be received.
1171 */
1172 out_be32(&priv->msg_regs->pwsr, RIO_IPWSR_QFI);
1173 out_be32(&priv->msg_regs->pwmr, ipwmr | RIO_IPWMR_CQ);
1174
Alexandre Bounine5b2074a2010-05-26 14:44:00 -07001175 schedule_work(&priv->pw_work);
1176 }
1177
Alexandre Bounine93e2cbd2010-10-27 15:34:28 -07001178 if ((ipwmr & RIO_IPWMR_EIE) && (ipwsr & RIO_IPWSR_TE)) {
1179 priv->port_write_msg.err_count++;
1180 pr_debug("RIO: Port-Write Transaction Err (%d)\n",
1181 priv->port_write_msg.err_count);
1182 /* Clear Transaction Error: port-write controller should be
1183 * disabled when clearing this error
1184 */
1185 out_be32(&priv->msg_regs->pwmr, ipwmr & ~RIO_IPWMR_PWE);
1186 out_be32(&priv->msg_regs->pwsr, RIO_IPWSR_TE);
1187 out_be32(&priv->msg_regs->pwmr, ipwmr);
1188 }
1189
1190 if (ipwsr & RIO_IPWSR_PWD) {
1191 priv->port_write_msg.discard_count++;
1192 pr_debug("RIO: Port Discarded Port-Write Msg(s) (%d)\n",
1193 priv->port_write_msg.discard_count);
1194 out_be32(&priv->msg_regs->pwsr, RIO_IPWSR_PWD);
1195 }
1196
1197pw_done:
Shaohui Xie6ff31452010-11-18 14:57:53 +08001198 if (epwisr & RIO_EPWISR_PINT1) {
Alexandre Bounine93e2cbd2010-10-27 15:34:28 -07001199 tmp = in_be32(priv->regs_win + RIO_LTLEDCSR);
1200 pr_debug("RIO_LTLEDCSR = 0x%x\n", tmp);
Shaohui Xie6ff31452010-11-18 14:57:53 +08001201 port_error_handler(port, 0);
1202 }
1203
1204 if (epwisr & RIO_EPWISR_PINT2) {
1205 tmp = in_be32(priv->regs_win + RIO_LTLEDCSR);
1206 pr_debug("RIO_LTLEDCSR = 0x%x\n", tmp);
1207 port_error_handler(port, 1);
1208 }
1209
1210 if (epwisr & RIO_EPWISR_MU) {
1211 tmp = in_be32(priv->regs_win + RIO_LTLEDCSR);
1212 pr_debug("RIO_LTLEDCSR = 0x%x\n", tmp);
1213 msg_unit_error_handler(port);
Alexandre Bounine93e2cbd2010-10-27 15:34:28 -07001214 }
Alexandre Bounine5b2074a2010-05-26 14:44:00 -07001215
1216 return IRQ_HANDLED;
1217}
1218
1219static void fsl_pw_dpc(struct work_struct *work)
1220{
1221 struct rio_priv *priv = container_of(work, struct rio_priv, pw_work);
1222 unsigned long flags;
1223 u32 msg_buffer[RIO_PW_MSG_SIZE/sizeof(u32)];
1224
1225 /*
1226 * Process port-write messages
1227 */
1228 spin_lock_irqsave(&priv->pw_fifo_lock, flags);
1229 while (kfifo_out(&priv->pw_fifo, (unsigned char *)msg_buffer,
1230 RIO_PW_MSG_SIZE)) {
1231 /* Process one message */
1232 spin_unlock_irqrestore(&priv->pw_fifo_lock, flags);
1233#ifdef DEBUG_PW
1234 {
1235 u32 i;
1236 pr_debug("%s : Port-Write Message:", __func__);
1237 for (i = 0; i < RIO_PW_MSG_SIZE/sizeof(u32); i++) {
1238 if ((i%4) == 0)
1239 pr_debug("\n0x%02x: 0x%08x", i*4,
1240 msg_buffer[i]);
1241 else
1242 pr_debug(" 0x%08x", msg_buffer[i]);
1243 }
1244 pr_debug("\n");
1245 }
1246#endif
1247 /* Pass the port-write message to RIO core for processing */
1248 rio_inb_pwrite_handler((union rio_pw_msg *)msg_buffer);
1249 spin_lock_irqsave(&priv->pw_fifo_lock, flags);
1250 }
1251 spin_unlock_irqrestore(&priv->pw_fifo_lock, flags);
1252}
1253
1254/**
1255 * fsl_rio_pw_enable - enable/disable port-write interface init
1256 * @mport: Master port implementing the port write unit
1257 * @enable: 1=enable; 0=disable port-write message handling
1258 */
1259static int fsl_rio_pw_enable(struct rio_mport *mport, int enable)
1260{
1261 struct rio_priv *priv = mport->priv;
1262 u32 rval;
1263
1264 rval = in_be32(&priv->msg_regs->pwmr);
1265
1266 if (enable)
1267 rval |= RIO_IPWMR_PWE;
1268 else
1269 rval &= ~RIO_IPWMR_PWE;
1270
1271 out_be32(&priv->msg_regs->pwmr, rval);
1272
1273 return 0;
1274}
1275
1276/**
1277 * fsl_rio_port_write_init - MPC85xx port write interface init
1278 * @mport: Master port implementing the port write unit
1279 *
1280 * Initializes port write unit hardware and DMA buffer
1281 * ring. Called from fsl_rio_setup(). Returns %0 on success
1282 * or %-ENOMEM on failure.
1283 */
1284static int fsl_rio_port_write_init(struct rio_mport *mport)
1285{
1286 struct rio_priv *priv = mport->priv;
1287 int rc = 0;
1288
1289 /* Following configurations require a disabled port write controller */
1290 out_be32(&priv->msg_regs->pwmr,
1291 in_be32(&priv->msg_regs->pwmr) & ~RIO_IPWMR_PWE);
1292
1293 /* Initialize port write */
1294 priv->port_write_msg.virt = dma_alloc_coherent(priv->dev,
1295 RIO_PW_MSG_SIZE,
1296 &priv->port_write_msg.phys, GFP_KERNEL);
1297 if (!priv->port_write_msg.virt) {
1298 pr_err("RIO: unable allocate port write queue\n");
1299 return -ENOMEM;
1300 }
1301
1302 priv->port_write_msg.err_count = 0;
1303 priv->port_write_msg.discard_count = 0;
1304
1305 /* Point dequeue/enqueue pointers at first entry */
1306 out_be32(&priv->msg_regs->epwqbar, 0);
1307 out_be32(&priv->msg_regs->pwqbar, (u32) priv->port_write_msg.phys);
1308
1309 pr_debug("EIPWQBAR: 0x%08x IPWQBAR: 0x%08x\n",
1310 in_be32(&priv->msg_regs->epwqbar),
1311 in_be32(&priv->msg_regs->pwqbar));
1312
1313 /* Clear interrupt status IPWSR */
1314 out_be32(&priv->msg_regs->pwsr,
1315 (RIO_IPWSR_TE | RIO_IPWSR_QFI | RIO_IPWSR_PWD));
1316
1317 /* Configure port write contoller for snooping enable all reporting,
1318 clear queue full */
1319 out_be32(&priv->msg_regs->pwmr,
1320 RIO_IPWMR_SEN | RIO_IPWMR_QFIE | RIO_IPWMR_EIE | RIO_IPWMR_CQ);
1321
1322
1323 /* Hook up port-write handler */
Shaohui Xie6ff31452010-11-18 14:57:53 +08001324 rc = request_irq(IRQ_RIO_PW(mport), fsl_rio_port_write_handler,
1325 IRQF_SHARED, "port-write", (void *)mport);
Alexandre Bounine5b2074a2010-05-26 14:44:00 -07001326 if (rc < 0) {
1327 pr_err("MPC85xx RIO: unable to request inbound doorbell irq");
1328 goto err_out;
1329 }
Shaohui Xie6ff31452010-11-18 14:57:53 +08001330 /* Enable Error Interrupt */
1331 out_be32((u32 *)(rio_regs_win + RIO_LTLEECSR), LTLEECSR_ENABLE_ALL);
Alexandre Bounine5b2074a2010-05-26 14:44:00 -07001332
1333 INIT_WORK(&priv->pw_work, fsl_pw_dpc);
1334 spin_lock_init(&priv->pw_fifo_lock);
1335 if (kfifo_alloc(&priv->pw_fifo, RIO_PW_MSG_SIZE * 32, GFP_KERNEL)) {
1336 pr_err("FIFO allocation failed\n");
1337 rc = -ENOMEM;
1338 goto err_out_irq;
1339 }
1340
1341 pr_debug("IPWMR: 0x%08x IPWSR: 0x%08x\n",
1342 in_be32(&priv->msg_regs->pwmr),
1343 in_be32(&priv->msg_regs->pwsr));
1344
1345 return rc;
1346
1347err_out_irq:
1348 free_irq(IRQ_RIO_PW(mport), (void *)mport);
1349err_out:
1350 dma_free_coherent(priv->dev, RIO_PW_MSG_SIZE,
1351 priv->port_write_msg.virt,
1352 priv->port_write_msg.phys);
1353 return rc;
1354}
1355
Zhang Wei7f620df2008-04-18 13:33:44 -07001356static inline void fsl_rio_info(struct device *dev, u32 ccsr)
1357{
1358 const char *str;
1359 if (ccsr & 1) {
1360 /* Serial phy */
1361 switch (ccsr >> 30) {
1362 case 0:
1363 str = "1";
1364 break;
1365 case 1:
1366 str = "4";
1367 break;
1368 default:
1369 str = "Unknown";
Joe Perchesd258e642009-06-28 06:26:10 +00001370 break;
Zhang Wei7f620df2008-04-18 13:33:44 -07001371 }
1372 dev_info(dev, "Hardware port width: %s\n", str);
1373
1374 switch ((ccsr >> 27) & 7) {
1375 case 0:
1376 str = "Single-lane 0";
1377 break;
1378 case 1:
1379 str = "Single-lane 2";
1380 break;
1381 case 2:
1382 str = "Four-lane";
1383 break;
1384 default:
1385 str = "Unknown";
1386 break;
1387 }
1388 dev_info(dev, "Training connection status: %s\n", str);
1389 } else {
1390 /* Parallel phy */
1391 if (!(ccsr & 0x80000000))
1392 dev_info(dev, "Output port operating in 8-bit mode\n");
1393 if (!(ccsr & 0x08000000))
1394 dev_info(dev, "Input port operating in 8-bit mode\n");
1395 }
1396}
1397
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001398/**
Randy Dunlap9941d942008-04-30 16:45:58 -07001399 * fsl_rio_setup - Setup Freescale PowerPC RapidIO interface
Grant Likely2dc11582010-08-06 09:25:50 -06001400 * @dev: platform_device pointer
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001401 *
1402 * Initializes MPC85xx RapidIO hardware interface, configures
1403 * master port with system-specific info, and registers the
1404 * master port with the RapidIO subsystem.
1405 */
Grant Likelya454dc52010-07-22 15:52:34 -06001406int fsl_rio_setup(struct platform_device *dev)
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001407{
1408 struct rio_ops *ops;
1409 struct rio_mport *port;
Zhang Weicc2bb692008-04-18 13:33:41 -07001410 struct rio_priv *priv;
1411 int rc = 0;
1412 const u32 *dt_range, *cell;
1413 struct resource regs;
1414 int rlen;
Zhang Wei61b26912008-04-18 13:33:44 -07001415 u32 ccsr;
Zhang Weicc2bb692008-04-18 13:33:41 -07001416 u64 law_start, law_size;
1417 int paw, aw, sw;
1418
Grant Likely61c7a082010-04-13 16:12:29 -07001419 if (!dev->dev.of_node) {
Zhang Weicc2bb692008-04-18 13:33:41 -07001420 dev_err(&dev->dev, "Device OF-Node is NULL");
1421 return -EFAULT;
1422 }
1423
Grant Likely61c7a082010-04-13 16:12:29 -07001424 rc = of_address_to_resource(dev->dev.of_node, 0, &regs);
Zhang Weicc2bb692008-04-18 13:33:41 -07001425 if (rc) {
1426 dev_err(&dev->dev, "Can't get %s property 'reg'\n",
Grant Likely61c7a082010-04-13 16:12:29 -07001427 dev->dev.of_node->full_name);
Zhang Weicc2bb692008-04-18 13:33:41 -07001428 return -EFAULT;
1429 }
Grant Likely61c7a082010-04-13 16:12:29 -07001430 dev_info(&dev->dev, "Of-device full name %s\n", dev->dev.of_node->full_name);
Kumar Galafc274a12009-05-13 17:02:24 -05001431 dev_info(&dev->dev, "Regs: %pR\n", &regs);
Zhang Weicc2bb692008-04-18 13:33:41 -07001432
Grant Likely61c7a082010-04-13 16:12:29 -07001433 dt_range = of_get_property(dev->dev.of_node, "ranges", &rlen);
Zhang Weicc2bb692008-04-18 13:33:41 -07001434 if (!dt_range) {
1435 dev_err(&dev->dev, "Can't get %s property 'ranges'\n",
Grant Likely61c7a082010-04-13 16:12:29 -07001436 dev->dev.of_node->full_name);
Zhang Weicc2bb692008-04-18 13:33:41 -07001437 return -EFAULT;
1438 }
1439
1440 /* Get node address wide */
Grant Likely61c7a082010-04-13 16:12:29 -07001441 cell = of_get_property(dev->dev.of_node, "#address-cells", NULL);
Zhang Weicc2bb692008-04-18 13:33:41 -07001442 if (cell)
1443 aw = *cell;
1444 else
Grant Likely61c7a082010-04-13 16:12:29 -07001445 aw = of_n_addr_cells(dev->dev.of_node);
Zhang Weicc2bb692008-04-18 13:33:41 -07001446 /* Get node size wide */
Grant Likely61c7a082010-04-13 16:12:29 -07001447 cell = of_get_property(dev->dev.of_node, "#size-cells", NULL);
Zhang Weicc2bb692008-04-18 13:33:41 -07001448 if (cell)
1449 sw = *cell;
1450 else
Grant Likely61c7a082010-04-13 16:12:29 -07001451 sw = of_n_size_cells(dev->dev.of_node);
Zhang Weicc2bb692008-04-18 13:33:41 -07001452 /* Get parent address wide wide */
Grant Likely61c7a082010-04-13 16:12:29 -07001453 paw = of_n_addr_cells(dev->dev.of_node);
Zhang Weicc2bb692008-04-18 13:33:41 -07001454
1455 law_start = of_read_number(dt_range + aw, paw);
1456 law_size = of_read_number(dt_range + aw + paw, sw);
1457
1458 dev_info(&dev->dev, "LAW start 0x%016llx, size 0x%016llx.\n",
1459 law_start, law_size);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001460
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -07001461 ops = kzalloc(sizeof(struct rio_ops), GFP_KERNEL);
Julia Lawall6c759332009-08-07 09:00:34 +02001462 if (!ops) {
1463 rc = -ENOMEM;
1464 goto err_ops;
1465 }
Zhang Weid02443a2008-04-18 13:33:38 -07001466 ops->lcread = fsl_local_config_read;
1467 ops->lcwrite = fsl_local_config_write;
1468 ops->cread = fsl_rio_config_read;
1469 ops->cwrite = fsl_rio_config_write;
1470 ops->dsend = fsl_rio_doorbell_send;
Alexandre Bounine5b2074a2010-05-26 14:44:00 -07001471 ops->pwenable = fsl_rio_pw_enable;
Alexandre Bouninef8f06262011-03-23 16:43:02 -07001472 ops->open_outb_mbox = fsl_open_outb_mbox;
1473 ops->open_inb_mbox = fsl_open_inb_mbox;
1474 ops->close_outb_mbox = fsl_close_outb_mbox;
1475 ops->close_inb_mbox = fsl_close_inb_mbox;
1476 ops->add_outb_message = fsl_add_outb_message;
1477 ops->add_inb_buffer = fsl_add_inb_buffer;
1478 ops->get_inb_message = fsl_get_inb_message;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001479
Zhang Weiad1e9382008-04-18 13:33:41 -07001480 port = kzalloc(sizeof(struct rio_mport), GFP_KERNEL);
Julia Lawall6c759332009-08-07 09:00:34 +02001481 if (!port) {
1482 rc = -ENOMEM;
1483 goto err_port;
1484 }
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001485 port->index = 0;
Zhang Weiad1e9382008-04-18 13:33:41 -07001486
1487 priv = kzalloc(sizeof(struct rio_priv), GFP_KERNEL);
1488 if (!priv) {
1489 printk(KERN_ERR "Can't alloc memory for 'priv'\n");
1490 rc = -ENOMEM;
Julia Lawall6c759332009-08-07 09:00:34 +02001491 goto err_priv;
Zhang Weiad1e9382008-04-18 13:33:41 -07001492 }
1493
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001494 INIT_LIST_HEAD(&port->dbells);
1495 port->iores.start = law_start;
Li Yang186e74b2009-05-12 16:35:59 +08001496 port->iores.end = law_start + law_size - 1;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001497 port->iores.flags = IORESOURCE_MEM;
Li Yang186e74b2009-05-12 16:35:59 +08001498 port->iores.name = "rio_io_win";
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001499
Alexandre Bouninec1256eb2011-03-23 16:43:06 -07001500 if (request_resource(&iomem_resource, &port->iores) < 0) {
1501 dev_err(&dev->dev, "RIO: Error requesting master port region"
1502 " 0x%016llx-0x%016llx\n",
1503 (u64)port->iores.start, (u64)port->iores.end);
1504 rc = -ENOMEM;
1505 goto err_res;
1506 }
1507
Alexandre Bounine45fdf002010-05-28 13:56:17 -04001508 priv->pwirq = irq_of_parse_and_map(dev->dev.of_node, 0);
Grant Likely61c7a082010-04-13 16:12:29 -07001509 priv->bellirq = irq_of_parse_and_map(dev->dev.of_node, 2);
1510 priv->txirq = irq_of_parse_and_map(dev->dev.of_node, 3);
1511 priv->rxirq = irq_of_parse_and_map(dev->dev.of_node, 4);
Alexandre Bounine5b2074a2010-05-26 14:44:00 -07001512 dev_info(&dev->dev, "pwirq: %d, bellirq: %d, txirq: %d, rxirq %d\n",
1513 priv->pwirq, priv->bellirq, priv->txirq, priv->rxirq);
Zhang Weicc2bb692008-04-18 13:33:41 -07001514
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001515 rio_init_dbell_res(&port->riores[RIO_DOORBELL_RESOURCE], 0, 0xffff);
1516 rio_init_mbox_res(&port->riores[RIO_INB_MBOX_RESOURCE], 0, 0);
1517 rio_init_mbox_res(&port->riores[RIO_OUTB_MBOX_RESOURCE], 0, 0);
1518 strcpy(port->name, "RIO0 mport");
1519
Anton Vorontsov0dbbbf12009-04-18 21:48:52 +04001520 priv->dev = &dev->dev;
1521
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001522 port->ops = ops;
Zhang Weiad1e9382008-04-18 13:33:41 -07001523 port->priv = priv;
Alexandre Bounineaf84ca382010-10-27 15:34:34 -07001524 port->phys_efptr = 0x100;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001525
Zhang Weicc2bb692008-04-18 13:33:41 -07001526 priv->regs_win = ioremap(regs.start, regs.end - regs.start + 1);
Alexandre Bouninea52c8f52010-05-26 14:44:00 -07001527 rio_regs_win = priv->regs_win;
Zhang Weie0423232008-04-18 13:33:42 -07001528
Zhang Wei61b26912008-04-18 13:33:44 -07001529 /* Probe the master port phy type */
1530 ccsr = in_be32(priv->regs_win + RIO_CCSR);
1531 port->phy_type = (ccsr & 1) ? RIO_PHY_SERIAL : RIO_PHY_PARALLEL;
1532 dev_info(&dev->dev, "RapidIO PHY type: %s\n",
1533 (port->phy_type == RIO_PHY_PARALLEL) ? "parallel" :
1534 ((port->phy_type == RIO_PHY_SERIAL) ? "serial" :
1535 "unknown"));
Zhang Wei7f620df2008-04-18 13:33:44 -07001536 /* Checking the port training status */
1537 if (in_be32((priv->regs_win + RIO_ESCSR)) & 1) {
1538 dev_err(&dev->dev, "Port is not ready. "
1539 "Try to restart connection...\n");
1540 switch (port->phy_type) {
1541 case RIO_PHY_SERIAL:
1542 /* Disable ports */
1543 out_be32(priv->regs_win + RIO_CCSR, 0);
1544 /* Set 1x lane */
1545 setbits32(priv->regs_win + RIO_CCSR, 0x02000000);
1546 /* Enable ports */
1547 setbits32(priv->regs_win + RIO_CCSR, 0x00600000);
1548 break;
1549 case RIO_PHY_PARALLEL:
1550 /* Disable ports */
1551 out_be32(priv->regs_win + RIO_CCSR, 0x22000000);
1552 /* Enable ports */
1553 out_be32(priv->regs_win + RIO_CCSR, 0x44000000);
1554 break;
1555 }
1556 msleep(100);
1557 if (in_be32((priv->regs_win + RIO_ESCSR)) & 1) {
1558 dev_err(&dev->dev, "Port restart failed.\n");
1559 rc = -ENOLINK;
1560 goto err;
1561 }
1562 dev_info(&dev->dev, "Port restart success!\n");
1563 }
1564 fsl_rio_info(&dev->dev, ccsr);
Zhang Wei61b26912008-04-18 13:33:44 -07001565
Zhang Weie0423232008-04-18 13:33:42 -07001566 port->sys_size = (in_be32((priv->regs_win + RIO_PEF_CAR))
1567 & RIO_PEF_CTLS) >> 4;
1568 dev_info(&dev->dev, "RapidIO Common Transport System size: %d\n",
1569 port->sys_size ? 65536 : 256);
1570
Alexandre Bounine59f99962011-04-14 15:22:14 -07001571 if (rio_register_mport(port))
1572 goto err;
1573
Alexandre Bounineaf84ca382010-10-27 15:34:34 -07001574 if (port->host_deviceid >= 0)
1575 out_be32(priv->regs_win + RIO_GCCSR, RIO_PORT_GEN_HOST |
1576 RIO_PORT_GEN_MASTER | RIO_PORT_GEN_DISCOVERED);
1577 else
1578 out_be32(priv->regs_win + RIO_GCCSR, 0x00000000);
1579
Zhang Weiad1e9382008-04-18 13:33:41 -07001580 priv->atmu_regs = (struct rio_atmu_regs *)(priv->regs_win
1581 + RIO_ATMU_REGS_OFFSET);
1582 priv->maint_atmu_regs = priv->atmu_regs + 1;
1583 priv->dbell_atmu_regs = priv->atmu_regs + 2;
Zhang Wei61b26912008-04-18 13:33:44 -07001584 priv->msg_regs = (struct rio_msg_regs *)(priv->regs_win +
1585 ((port->phy_type == RIO_PHY_SERIAL) ?
1586 RIO_S_MSG_REGS_OFFSET : RIO_P_MSG_REGS_OFFSET));
1587
1588 /* Set to receive any dist ID for serial RapidIO controller. */
1589 if (port->phy_type == RIO_PHY_SERIAL)
1590 out_be32((priv->regs_win + RIO_ISR_AACR), RIO_ISR_AACR_AA);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001591
1592 /* Configure maintenance transaction window */
Li Yang186e74b2009-05-12 16:35:59 +08001593 out_be32(&priv->maint_atmu_regs->rowbar, law_start >> 12);
Thomas Mollbd4fb652010-05-26 14:44:05 -07001594 out_be32(&priv->maint_atmu_regs->rowar,
1595 0x80077000 | (ilog2(RIO_MAINT_WIN_SIZE) - 1));
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001596
Zhang Weiad1e9382008-04-18 13:33:41 -07001597 priv->maint_win = ioremap(law_start, RIO_MAINT_WIN_SIZE);
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001598
1599 /* Configure outbound doorbell window */
Li Yang186e74b2009-05-12 16:35:59 +08001600 out_be32(&priv->dbell_atmu_regs->rowbar,
1601 (law_start + RIO_MAINT_WIN_SIZE) >> 12);
1602 out_be32(&priv->dbell_atmu_regs->rowar, 0x8004200b); /* 4k */
Zhang Weid02443a2008-04-18 13:33:38 -07001603 fsl_rio_doorbell_init(port);
Alexandre Bounine5b2074a2010-05-26 14:44:00 -07001604 fsl_rio_port_write_init(port);
Zhang Weiad1e9382008-04-18 13:33:41 -07001605
Zhang Weicc2bb692008-04-18 13:33:41 -07001606 return 0;
Zhang Weiad1e9382008-04-18 13:33:41 -07001607err:
Julia Lawall6c759332009-08-07 09:00:34 +02001608 iounmap(priv->regs_win);
Alexandre Bouninec1256eb2011-03-23 16:43:06 -07001609err_res:
Zhang Weiad1e9382008-04-18 13:33:41 -07001610 kfree(priv);
Julia Lawall6c759332009-08-07 09:00:34 +02001611err_priv:
Zhang Weiad1e9382008-04-18 13:33:41 -07001612 kfree(port);
Julia Lawall6c759332009-08-07 09:00:34 +02001613err_port:
1614 kfree(ops);
1615err_ops:
Zhang Weicc2bb692008-04-18 13:33:41 -07001616 return rc;
Matt Porter2b0c28d7f2005-11-07 01:00:19 -08001617}
Zhang Weicc2bb692008-04-18 13:33:41 -07001618
1619/* The probe function for RapidIO peer-to-peer network.
1620 */
Grant Likely00006122011-02-22 19:59:54 -07001621static int __devinit fsl_of_rio_rpn_probe(struct platform_device *dev)
Zhang Weicc2bb692008-04-18 13:33:41 -07001622{
Zhang Weicc2bb692008-04-18 13:33:41 -07001623 printk(KERN_INFO "Setting up RapidIO peer-to-peer network %s\n",
Grant Likely61c7a082010-04-13 16:12:29 -07001624 dev->dev.of_node->full_name);
Zhang Weicc2bb692008-04-18 13:33:41 -07001625
Alexandre Bounine2f809982011-03-23 16:43:04 -07001626 return fsl_rio_setup(dev);
Zhang Weicc2bb692008-04-18 13:33:41 -07001627};
1628
1629static const struct of_device_id fsl_of_rio_rpn_ids[] = {
1630 {
1631 .compatible = "fsl,rapidio-delta",
1632 },
1633 {},
1634};
1635
Grant Likely00006122011-02-22 19:59:54 -07001636static struct platform_driver fsl_of_rio_rpn_driver = {
Grant Likely40182942010-04-13 16:13:02 -07001637 .driver = {
1638 .name = "fsl-of-rio",
1639 .owner = THIS_MODULE,
1640 .of_match_table = fsl_of_rio_rpn_ids,
1641 },
Zhang Weicc2bb692008-04-18 13:33:41 -07001642 .probe = fsl_of_rio_rpn_probe,
1643};
1644
1645static __init int fsl_of_rio_rpn_init(void)
1646{
Grant Likely00006122011-02-22 19:59:54 -07001647 return platform_driver_register(&fsl_of_rio_rpn_driver);
Zhang Weicc2bb692008-04-18 13:33:41 -07001648}
1649
1650subsys_initcall(fsl_of_rio_rpn_init);