2 * RapidIO Tsi57x switch family support
4 * Copyright 2009-2010 Integrated Device Technology, Inc.
5 * Alexandre Bounine <alexandre.bounine@idt.com>
7 * - Modified switch operations initialization.
9 * Copyright 2005 MontaVista Software, Inc.
10 * Matt Porter <mporter@kernel.crashing.org>
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
18 #include <linux/rio.h>
19 #include <linux/rio_drv.h>
20 #include <linux/rio_ids.h>
21 #include <linux/delay.h>
22 #include <linux/module.h>
25 /* Global (broadcast) route registers */
26 #define SPBC_ROUTE_CFG_DESTID 0x10070
27 #define SPBC_ROUTE_CFG_PORT 0x10074
29 /* Per port route registers */
30 #define SPP_ROUTE_CFG_DESTID(n) (0x11070 + 0x100*n)
31 #define SPP_ROUTE_CFG_PORT(n) (0x11074 + 0x100*n)
33 #define TSI578_SP_MODE(n) (0x11004 + n*0x100)
34 #define TSI578_SP_MODE_GLBL 0x10004
35 #define TSI578_SP_MODE_PW_DIS 0x08000000
36 #define TSI578_SP_MODE_LUT_512 0x01000000
38 #define TSI578_SP_CTL_INDEP(n) (0x13004 + n*0x100)
39 #define TSI578_SP_LUT_PEINF(n) (0x13010 + n*0x100)
40 #define TSI578_SP_CS_TX(n) (0x13014 + n*0x100)
41 #define TSI578_SP_INT_STATUS(n) (0x13018 + n*0x100)
43 #define TSI578_GLBL_ROUTE_BASE 0x10078
46 tsi57x_route_add_entry(struct rio_mport
*mport
, u16 destid
, u8 hopcount
,
47 u16 table
, u16 route_destid
, u8 route_port
)
49 if (table
== RIO_GLOBAL_TABLE
) {
50 rio_mport_write_config_32(mport
, destid
, hopcount
,
51 SPBC_ROUTE_CFG_DESTID
, route_destid
);
52 rio_mport_write_config_32(mport
, destid
, hopcount
,
53 SPBC_ROUTE_CFG_PORT
, route_port
);
55 rio_mport_write_config_32(mport
, destid
, hopcount
,
56 SPP_ROUTE_CFG_DESTID(table
), route_destid
);
57 rio_mport_write_config_32(mport
, destid
, hopcount
,
58 SPP_ROUTE_CFG_PORT(table
), route_port
);
67 tsi57x_route_get_entry(struct rio_mport
*mport
, u16 destid
, u8 hopcount
,
68 u16 table
, u16 route_destid
, u8
*route_port
)
73 if (table
== RIO_GLOBAL_TABLE
) {
74 /* Use local RT of the ingress port to avoid possible
76 rio_mport_read_config_32(mport
, destid
, hopcount
,
77 RIO_SWP_INFO_CAR
, &result
);
78 table
= (result
& RIO_SWP_INFO_PORT_NUM_MASK
);
81 rio_mport_write_config_32(mport
, destid
, hopcount
,
82 SPP_ROUTE_CFG_DESTID(table
), route_destid
);
83 rio_mport_read_config_32(mport
, destid
, hopcount
,
84 SPP_ROUTE_CFG_PORT(table
), &result
);
86 *route_port
= (u8
)result
;
94 tsi57x_route_clr_table(struct rio_mport
*mport
, u16 destid
, u8 hopcount
,
100 lut_size
= (mport
->sys_size
) ? 0x1ff : 0xff;
102 if (table
== RIO_GLOBAL_TABLE
) {
103 rio_mport_write_config_32(mport
, destid
, hopcount
,
104 SPBC_ROUTE_CFG_DESTID
, 0x80000000);
105 for (route_idx
= 0; route_idx
<= lut_size
; route_idx
++)
106 rio_mport_write_config_32(mport
, destid
, hopcount
,
110 rio_mport_write_config_32(mport
, destid
, hopcount
,
111 SPP_ROUTE_CFG_DESTID(table
), 0x80000000);
112 for (route_idx
= 0; route_idx
<= lut_size
; route_idx
++)
113 rio_mport_write_config_32(mport
, destid
, hopcount
,
114 SPP_ROUTE_CFG_PORT(table
) , RIO_INVALID_ROUTE
);
121 tsi57x_set_domain(struct rio_mport
*mport
, u16 destid
, u8 hopcount
,
127 * Switch domain configuration operates only at global level
130 /* Turn off flat (LUT_512) mode */
131 rio_mport_read_config_32(mport
, destid
, hopcount
,
132 TSI578_SP_MODE_GLBL
, ®val
);
133 rio_mport_write_config_32(mport
, destid
, hopcount
, TSI578_SP_MODE_GLBL
,
134 regval
& ~TSI578_SP_MODE_LUT_512
);
135 /* Set switch domain base */
136 rio_mport_write_config_32(mport
, destid
, hopcount
,
137 TSI578_GLBL_ROUTE_BASE
,
138 (u32
)(sw_domain
<< 24));
143 tsi57x_get_domain(struct rio_mport
*mport
, u16 destid
, u8 hopcount
,
149 * Switch domain configuration operates only at global level
151 rio_mport_read_config_32(mport
, destid
, hopcount
,
152 TSI578_GLBL_ROUTE_BASE
, ®val
);
154 *sw_domain
= (u8
)(regval
>> 24);
160 tsi57x_em_init(struct rio_dev
*rdev
)
165 pr_debug("TSI578 %s [%d:%d]\n", __func__
, rdev
->destid
, rdev
->hopcount
);
168 portnum
< RIO_GET_TOTAL_PORTS(rdev
->swpinfo
); portnum
++) {
169 /* Make sure that Port-Writes are enabled (for all ports) */
170 rio_read_config_32(rdev
,
171 TSI578_SP_MODE(portnum
), ®val
);
172 rio_write_config_32(rdev
,
173 TSI578_SP_MODE(portnum
),
174 regval
& ~TSI578_SP_MODE_PW_DIS
);
176 /* Clear all pending interrupts */
177 rio_read_config_32(rdev
,
178 RIO_DEV_PORT_N_ERR_STS_CSR(rdev
, portnum
),
180 rio_write_config_32(rdev
,
181 RIO_DEV_PORT_N_ERR_STS_CSR(rdev
, portnum
),
182 regval
& 0x07120214);
184 rio_read_config_32(rdev
,
185 TSI578_SP_INT_STATUS(portnum
), ®val
);
186 rio_write_config_32(rdev
,
187 TSI578_SP_INT_STATUS(portnum
),
188 regval
& 0x000700bd);
190 /* Enable all interrupts to allow ports to send a port-write */
191 rio_read_config_32(rdev
,
192 TSI578_SP_CTL_INDEP(portnum
), ®val
);
193 rio_write_config_32(rdev
,
194 TSI578_SP_CTL_INDEP(portnum
),
195 regval
| 0x000b0000);
197 /* Skip next (odd) port if the current port is in x4 mode */
198 rio_read_config_32(rdev
,
199 RIO_DEV_PORT_N_CTL_CSR(rdev
, portnum
),
201 if ((regval
& RIO_PORT_N_CTL_PWIDTH
) == RIO_PORT_N_CTL_PWIDTH_4
)
205 /* set TVAL = ~50us */
206 rio_write_config_32(rdev
,
207 rdev
->phys_efptr
+ RIO_PORT_LINKTO_CTL_CSR
, 0x9a << 8);
213 tsi57x_em_handler(struct rio_dev
*rdev
, u8 portnum
)
215 struct rio_mport
*mport
= rdev
->net
->hport
;
216 u32 intstat
, err_status
;
217 int sendcount
, checkcount
;
221 rio_read_config_32(rdev
,
222 RIO_DEV_PORT_N_ERR_STS_CSR(rdev
, portnum
),
225 if ((err_status
& RIO_PORT_N_ERR_STS_PORT_OK
) &&
226 (err_status
& (RIO_PORT_N_ERR_STS_OUT_ES
|
227 RIO_PORT_N_ERR_STS_INP_ES
))) {
228 /* Remove any queued packets by locking/unlocking port */
229 rio_read_config_32(rdev
,
230 RIO_DEV_PORT_N_CTL_CSR(rdev
, portnum
),
232 if (!(regval
& RIO_PORT_N_CTL_LOCKOUT
)) {
233 rio_write_config_32(rdev
,
234 RIO_DEV_PORT_N_CTL_CSR(rdev
, portnum
),
235 regval
| RIO_PORT_N_CTL_LOCKOUT
);
237 rio_write_config_32(rdev
,
238 RIO_DEV_PORT_N_CTL_CSR(rdev
, portnum
),
242 /* Read from link maintenance response register to clear
245 rio_read_config_32(rdev
,
246 RIO_DEV_PORT_N_MNT_RSP_CSR(rdev
, portnum
),
249 /* Send a Packet-Not-Accepted/Link-Request-Input-Status control
250 * symbol to recover from IES/OES
254 rio_write_config_32(rdev
,
255 TSI578_SP_CS_TX(portnum
), 0x40fc8000);
257 while (checkcount
--) {
259 rio_read_config_32(rdev
,
260 RIO_DEV_PORT_N_MNT_RSP_CSR(rdev
,
263 if (regval
& RIO_PORT_N_MNT_RSP_RVAL
)
272 /* Clear implementation specific error status bits */
273 rio_read_config_32(rdev
, TSI578_SP_INT_STATUS(portnum
), &intstat
);
274 pr_debug("TSI578[%x:%x] SP%d_INT_STATUS=0x%08x\n",
275 rdev
->destid
, rdev
->hopcount
, portnum
, intstat
);
277 if (intstat
& 0x10000) {
278 rio_read_config_32(rdev
,
279 TSI578_SP_LUT_PEINF(portnum
), ®val
);
280 regval
= (mport
->sys_size
) ? (regval
>> 16) : (regval
>> 24);
281 route_port
= rdev
->rswitch
->route_table
[regval
];
282 pr_debug("RIO: TSI578[%s] P%d LUT Parity Error (destID=%d)\n",
283 rio_name(rdev
), portnum
, regval
);
284 tsi57x_route_add_entry(mport
, rdev
->destid
, rdev
->hopcount
,
285 RIO_GLOBAL_TABLE
, regval
, route_port
);
288 rio_write_config_32(rdev
, TSI578_SP_INT_STATUS(portnum
),
289 intstat
& 0x000700bd);
294 static struct rio_switch_ops tsi57x_switch_ops
= {
295 .owner
= THIS_MODULE
,
296 .add_entry
= tsi57x_route_add_entry
,
297 .get_entry
= tsi57x_route_get_entry
,
298 .clr_table
= tsi57x_route_clr_table
,
299 .set_domain
= tsi57x_set_domain
,
300 .get_domain
= tsi57x_get_domain
,
301 .em_init
= tsi57x_em_init
,
302 .em_handle
= tsi57x_em_handler
,
305 static int tsi57x_probe(struct rio_dev
*rdev
, const struct rio_device_id
*id
)
307 pr_debug("RIO: %s for %s\n", __func__
, rio_name(rdev
));
309 spin_lock(&rdev
->rswitch
->lock
);
311 if (rdev
->rswitch
->ops
) {
312 spin_unlock(&rdev
->rswitch
->lock
);
315 rdev
->rswitch
->ops
= &tsi57x_switch_ops
;
318 /* Ensure that default routing is disabled on startup */
319 rio_write_config_32(rdev
, RIO_STD_RTE_DEFAULT_PORT
,
323 spin_unlock(&rdev
->rswitch
->lock
);
327 static void tsi57x_remove(struct rio_dev
*rdev
)
329 pr_debug("RIO: %s for %s\n", __func__
, rio_name(rdev
));
330 spin_lock(&rdev
->rswitch
->lock
);
331 if (rdev
->rswitch
->ops
!= &tsi57x_switch_ops
) {
332 spin_unlock(&rdev
->rswitch
->lock
);
335 rdev
->rswitch
->ops
= NULL
;
336 spin_unlock(&rdev
->rswitch
->lock
);
339 static struct rio_device_id tsi57x_id_table
[] = {
340 {RIO_DEVICE(RIO_DID_TSI572
, RIO_VID_TUNDRA
)},
341 {RIO_DEVICE(RIO_DID_TSI574
, RIO_VID_TUNDRA
)},
342 {RIO_DEVICE(RIO_DID_TSI577
, RIO_VID_TUNDRA
)},
343 {RIO_DEVICE(RIO_DID_TSI578
, RIO_VID_TUNDRA
)},
344 { 0, } /* terminate list */
347 static struct rio_driver tsi57x_driver
= {
349 .id_table
= tsi57x_id_table
,
350 .probe
= tsi57x_probe
,
351 .remove
= tsi57x_remove
,
354 static int __init
tsi57x_init(void)
356 return rio_register_driver(&tsi57x_driver
);
359 static void __exit
tsi57x_exit(void)
361 rio_unregister_driver(&tsi57x_driver
);
364 device_initcall(tsi57x_init
);
365 module_exit(tsi57x_exit
);
367 MODULE_DESCRIPTION("IDT Tsi57x Serial RapidIO switch family driver");
368 MODULE_AUTHOR("Integrated Device Technology, Inc.");
369 MODULE_LICENSE("GPL");