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>
24 /* Global (broadcast) route registers */
25 #define SPBC_ROUTE_CFG_DESTID 0x10070
26 #define SPBC_ROUTE_CFG_PORT 0x10074
28 /* Per port route registers */
29 #define SPP_ROUTE_CFG_DESTID(n) (0x11070 + 0x100*n)
30 #define SPP_ROUTE_CFG_PORT(n) (0x11074 + 0x100*n)
32 #define TSI578_SP_MODE(n) (0x11004 + n*0x100)
33 #define TSI578_SP_MODE_GLBL 0x10004
34 #define TSI578_SP_MODE_PW_DIS 0x08000000
35 #define TSI578_SP_MODE_LUT_512 0x01000000
37 #define TSI578_SP_CTL_INDEP(n) (0x13004 + n*0x100)
38 #define TSI578_SP_LUT_PEINF(n) (0x13010 + n*0x100)
39 #define TSI578_SP_CS_TX(n) (0x13014 + n*0x100)
40 #define TSI578_SP_INT_STATUS(n) (0x13018 + n*0x100)
42 #define TSI578_GLBL_ROUTE_BASE 0x10078
45 tsi57x_route_add_entry(struct rio_mport
*mport
, u16 destid
, u8 hopcount
,
46 u16 table
, u16 route_destid
, u8 route_port
)
48 if (table
== RIO_GLOBAL_TABLE
) {
49 rio_mport_write_config_32(mport
, destid
, hopcount
,
50 SPBC_ROUTE_CFG_DESTID
, route_destid
);
51 rio_mport_write_config_32(mport
, destid
, hopcount
,
52 SPBC_ROUTE_CFG_PORT
, route_port
);
54 rio_mport_write_config_32(mport
, destid
, hopcount
,
55 SPP_ROUTE_CFG_DESTID(table
), route_destid
);
56 rio_mport_write_config_32(mport
, destid
, hopcount
,
57 SPP_ROUTE_CFG_PORT(table
), route_port
);
66 tsi57x_route_get_entry(struct rio_mport
*mport
, u16 destid
, u8 hopcount
,
67 u16 table
, u16 route_destid
, u8
*route_port
)
72 if (table
== RIO_GLOBAL_TABLE
) {
73 /* Use local RT of the ingress port to avoid possible
75 rio_mport_read_config_32(mport
, destid
, hopcount
,
76 RIO_SWP_INFO_CAR
, &result
);
77 table
= (result
& RIO_SWP_INFO_PORT_NUM_MASK
);
80 rio_mport_write_config_32(mport
, destid
, hopcount
,
81 SPP_ROUTE_CFG_DESTID(table
), route_destid
);
82 rio_mport_read_config_32(mport
, destid
, hopcount
,
83 SPP_ROUTE_CFG_PORT(table
), &result
);
85 *route_port
= (u8
)result
;
93 tsi57x_route_clr_table(struct rio_mport
*mport
, u16 destid
, u8 hopcount
,
99 lut_size
= (mport
->sys_size
) ? 0x1ff : 0xff;
101 if (table
== RIO_GLOBAL_TABLE
) {
102 rio_mport_write_config_32(mport
, destid
, hopcount
,
103 SPBC_ROUTE_CFG_DESTID
, 0x80000000);
104 for (route_idx
= 0; route_idx
<= lut_size
; route_idx
++)
105 rio_mport_write_config_32(mport
, destid
, hopcount
,
109 rio_mport_write_config_32(mport
, destid
, hopcount
,
110 SPP_ROUTE_CFG_DESTID(table
), 0x80000000);
111 for (route_idx
= 0; route_idx
<= lut_size
; route_idx
++)
112 rio_mport_write_config_32(mport
, destid
, hopcount
,
113 SPP_ROUTE_CFG_PORT(table
) , RIO_INVALID_ROUTE
);
120 tsi57x_set_domain(struct rio_mport
*mport
, u16 destid
, u8 hopcount
,
126 * Switch domain configuration operates only at global level
129 /* Turn off flat (LUT_512) mode */
130 rio_mport_read_config_32(mport
, destid
, hopcount
,
131 TSI578_SP_MODE_GLBL
, ®val
);
132 rio_mport_write_config_32(mport
, destid
, hopcount
, TSI578_SP_MODE_GLBL
,
133 regval
& ~TSI578_SP_MODE_LUT_512
);
134 /* Set switch domain base */
135 rio_mport_write_config_32(mport
, destid
, hopcount
,
136 TSI578_GLBL_ROUTE_BASE
,
137 (u32
)(sw_domain
<< 24));
142 tsi57x_get_domain(struct rio_mport
*mport
, u16 destid
, u8 hopcount
,
148 * Switch domain configuration operates only at global level
150 rio_mport_read_config_32(mport
, destid
, hopcount
,
151 TSI578_GLBL_ROUTE_BASE
, ®val
);
153 *sw_domain
= (u8
)(regval
>> 24);
159 tsi57x_em_init(struct rio_dev
*rdev
)
161 struct rio_mport
*mport
= rdev
->net
->hport
;
162 u16 destid
= rdev
->rswitch
->destid
;
163 u8 hopcount
= rdev
->rswitch
->hopcount
;
167 pr_debug("TSI578 %s [%d:%d]\n", __func__
, destid
, hopcount
);
170 portnum
< RIO_GET_TOTAL_PORTS(rdev
->swpinfo
); portnum
++) {
171 /* Make sure that Port-Writes are enabled (for all ports) */
172 rio_mport_read_config_32(mport
, destid
, hopcount
,
173 TSI578_SP_MODE(portnum
), ®val
);
174 rio_mport_write_config_32(mport
, destid
, hopcount
,
175 TSI578_SP_MODE(portnum
),
176 regval
& ~TSI578_SP_MODE_PW_DIS
);
178 /* Clear all pending interrupts */
179 rio_mport_read_config_32(mport
, destid
, hopcount
,
181 RIO_PORT_N_ERR_STS_CSR(portnum
),
183 rio_mport_write_config_32(mport
, destid
, hopcount
,
185 RIO_PORT_N_ERR_STS_CSR(portnum
),
186 regval
& 0x07120214);
188 rio_mport_read_config_32(mport
, destid
, hopcount
,
189 TSI578_SP_INT_STATUS(portnum
), ®val
);
190 rio_mport_write_config_32(mport
, destid
, hopcount
,
191 TSI578_SP_INT_STATUS(portnum
),
192 regval
& 0x000700bd);
194 /* Enable all interrupts to allow ports to send a port-write */
195 rio_mport_read_config_32(mport
, destid
, hopcount
,
196 TSI578_SP_CTL_INDEP(portnum
), ®val
);
197 rio_mport_write_config_32(mport
, destid
, hopcount
,
198 TSI578_SP_CTL_INDEP(portnum
),
199 regval
| 0x000b0000);
201 /* Skip next (odd) port if the current port is in x4 mode */
202 rio_mport_read_config_32(mport
, destid
, hopcount
,
203 rdev
->phys_efptr
+ RIO_PORT_N_CTL_CSR(portnum
),
205 if ((regval
& RIO_PORT_N_CTL_PWIDTH
) == RIO_PORT_N_CTL_PWIDTH_4
)
209 /* set TVAL = ~50us */
210 rio_mport_write_config_32(mport
, destid
, hopcount
,
211 rdev
->phys_efptr
+ RIO_PORT_LINKTO_CTL_CSR
, 0x9a << 8);
217 tsi57x_em_handler(struct rio_dev
*rdev
, u8 portnum
)
219 struct rio_mport
*mport
= rdev
->net
->hport
;
220 u16 destid
= rdev
->rswitch
->destid
;
221 u8 hopcount
= rdev
->rswitch
->hopcount
;
222 u32 intstat
, err_status
;
223 int sendcount
, checkcount
;
227 rio_mport_read_config_32(mport
, destid
, hopcount
,
228 rdev
->phys_efptr
+ RIO_PORT_N_ERR_STS_CSR(portnum
),
231 if ((err_status
& RIO_PORT_N_ERR_STS_PORT_OK
) &&
232 (err_status
& (RIO_PORT_N_ERR_STS_PW_OUT_ES
|
233 RIO_PORT_N_ERR_STS_PW_INP_ES
))) {
234 /* Remove any queued packets by locking/unlocking port */
235 rio_mport_read_config_32(mport
, destid
, hopcount
,
236 rdev
->phys_efptr
+ RIO_PORT_N_CTL_CSR(portnum
),
238 if (!(regval
& RIO_PORT_N_CTL_LOCKOUT
)) {
239 rio_mport_write_config_32(mport
, destid
, hopcount
,
240 rdev
->phys_efptr
+ RIO_PORT_N_CTL_CSR(portnum
),
241 regval
| RIO_PORT_N_CTL_LOCKOUT
);
243 rio_mport_write_config_32(mport
, destid
, hopcount
,
244 rdev
->phys_efptr
+ RIO_PORT_N_CTL_CSR(portnum
),
248 /* Read from link maintenance response register to clear
251 rio_mport_read_config_32(mport
, destid
, hopcount
,
252 rdev
->phys_efptr
+ RIO_PORT_N_MNT_RSP_CSR(portnum
),
255 /* Send a Packet-Not-Accepted/Link-Request-Input-Status control
256 * symbol to recover from IES/OES
260 rio_mport_write_config_32(mport
, destid
, hopcount
,
261 TSI578_SP_CS_TX(portnum
), 0x40fc8000);
263 while (checkcount
--) {
265 rio_mport_read_config_32(
266 mport
, destid
, hopcount
,
268 RIO_PORT_N_MNT_RSP_CSR(portnum
),
270 if (regval
& RIO_PORT_N_MNT_RSP_RVAL
)
279 /* Clear implementation specific error status bits */
280 rio_mport_read_config_32(mport
, destid
, hopcount
,
281 TSI578_SP_INT_STATUS(portnum
), &intstat
);
282 pr_debug("TSI578[%x:%x] SP%d_INT_STATUS=0x%08x\n",
283 destid
, hopcount
, portnum
, intstat
);
285 if (intstat
& 0x10000) {
286 rio_mport_read_config_32(mport
, destid
, hopcount
,
287 TSI578_SP_LUT_PEINF(portnum
), ®val
);
288 regval
= (mport
->sys_size
) ? (regval
>> 16) : (regval
>> 24);
289 route_port
= rdev
->rswitch
->route_table
[regval
];
290 pr_debug("RIO: TSI578[%s] P%d LUT Parity Error (destID=%d)\n",
291 rio_name(rdev
), portnum
, regval
);
292 tsi57x_route_add_entry(mport
, destid
, hopcount
,
293 RIO_GLOBAL_TABLE
, regval
, route_port
);
296 rio_mport_write_config_32(mport
, destid
, hopcount
,
297 TSI578_SP_INT_STATUS(portnum
),
298 intstat
& 0x000700bd);
303 static int tsi57x_switch_init(struct rio_dev
*rdev
, int do_enum
)
305 pr_debug("RIO: %s for %s\n", __func__
, rio_name(rdev
));
306 rdev
->rswitch
->add_entry
= tsi57x_route_add_entry
;
307 rdev
->rswitch
->get_entry
= tsi57x_route_get_entry
;
308 rdev
->rswitch
->clr_table
= tsi57x_route_clr_table
;
309 rdev
->rswitch
->set_domain
= tsi57x_set_domain
;
310 rdev
->rswitch
->get_domain
= tsi57x_get_domain
;
311 rdev
->rswitch
->em_init
= tsi57x_em_init
;
312 rdev
->rswitch
->em_handle
= tsi57x_em_handler
;
317 DECLARE_RIO_SWITCH_INIT(RIO_VID_TUNDRA
, RIO_DID_TSI572
, tsi57x_switch_init
);
318 DECLARE_RIO_SWITCH_INIT(RIO_VID_TUNDRA
, RIO_DID_TSI574
, tsi57x_switch_init
);
319 DECLARE_RIO_SWITCH_INIT(RIO_VID_TUNDRA
, RIO_DID_TSI577
, tsi57x_switch_init
);
320 DECLARE_RIO_SWITCH_INIT(RIO_VID_TUNDRA
, RIO_DID_TSI578
, tsi57x_switch_init
);