2 * IDT RXS Gen.3 Serial RapidIO switch family support
4 * Copyright 2016 Integrated Device Technology, Inc.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
12 #include <linux/stat.h>
13 #include <linux/module.h>
14 #include <linux/rio.h>
15 #include <linux/rio_drv.h>
16 #include <linux/rio_ids.h>
17 #include <linux/delay.h>
22 #define RIO_EM_PW_STAT 0x40020
23 #define RIO_PW_CTL 0x40204
24 #define RIO_PW_CTL_PW_TMR 0xffffff00
25 #define RIO_PW_ROUTE 0x40208
27 #define RIO_EM_DEV_INT_EN 0x40030
29 #define RIO_PLM_SPx_IMP_SPEC_CTL(x) (0x10100 + (x)*0x100)
30 #define RIO_PLM_SPx_IMP_SPEC_CTL_SOFT_RST 0x02000000
32 #define RIO_PLM_SPx_PW_EN(x) (0x10118 + (x)*0x100)
33 #define RIO_PLM_SPx_PW_EN_OK2U 0x40000000
34 #define RIO_PLM_SPx_PW_EN_LINIT 0x10000000
36 #define RIO_BC_L2_Gn_ENTRYx_CSR(n, x) (0x31000 + (n)*0x400 + (x)*0x4)
37 #define RIO_SPx_L2_Gn_ENTRYy_CSR(x, n, y) \
38 (0x51000 + (x)*0x2000 + (n)*0x400 + (y)*0x4)
41 idtg3_route_add_entry(struct rio_mport
*mport
, u16 destid
, u8 hopcount
,
42 u16 table
, u16 route_destid
, u8 route_port
)
45 u32 entry
= route_port
;
48 pr_debug("RIO: %s t=0x%x did_%x to p_%x\n",
49 __func__
, table
, route_destid
, entry
);
51 if (route_destid
> 0xFF)
54 if (route_port
== RIO_INVALID_ROUTE
)
55 entry
= RIO_RT_ENTRY_DROP_PKT
;
57 if (table
== RIO_GLOBAL_TABLE
) {
58 /* Use broadcast register to update all per-port tables */
59 err
= rio_mport_write_config_32(mport
, destid
, hopcount
,
60 RIO_BC_L2_Gn_ENTRYx_CSR(0, route_destid
),
66 * Verify that specified port/table number is valid
68 err
= rio_mport_read_config_32(mport
, destid
, hopcount
,
69 RIO_SWP_INFO_CAR
, &rval
);
73 if (table
>= RIO_GET_TOTAL_PORTS(rval
))
76 err
= rio_mport_write_config_32(mport
, destid
, hopcount
,
77 RIO_SPx_L2_Gn_ENTRYy_CSR(table
, 0, route_destid
),
83 idtg3_route_get_entry(struct rio_mport
*mport
, u16 destid
, u8 hopcount
,
84 u16 table
, u16 route_destid
, u8
*route_port
)
89 if (route_destid
> 0xFF)
92 err
= rio_mport_read_config_32(mport
, destid
, hopcount
,
93 RIO_SWP_INFO_CAR
, &rval
);
98 * This switch device does not have the dedicated global routing table.
99 * It is substituted by reading routing table of the ingress port of
100 * maintenance read requests.
102 if (table
== RIO_GLOBAL_TABLE
)
103 table
= RIO_GET_PORT_NUM(rval
);
104 else if (table
>= RIO_GET_TOTAL_PORTS(rval
))
107 err
= rio_mport_read_config_32(mport
, destid
, hopcount
,
108 RIO_SPx_L2_Gn_ENTRYy_CSR(table
, 0, route_destid
),
113 if (rval
== RIO_RT_ENTRY_DROP_PKT
)
114 *route_port
= RIO_INVALID_ROUTE
;
116 *route_port
= (u8
)rval
;
122 idtg3_route_clr_table(struct rio_mport
*mport
, u16 destid
, u8 hopcount
,
129 if (table
== RIO_GLOBAL_TABLE
) {
130 for (i
= 0; i
<= 0xff; i
++) {
131 err
= rio_mport_write_config_32(mport
, destid
, hopcount
,
132 RIO_BC_L2_Gn_ENTRYx_CSR(0, i
),
133 RIO_RT_ENTRY_DROP_PKT
);
141 err
= rio_mport_read_config_32(mport
, destid
, hopcount
,
142 RIO_SWP_INFO_CAR
, &rval
);
146 if (table
>= RIO_GET_TOTAL_PORTS(rval
))
149 for (i
= 0; i
<= 0xff; i
++) {
150 err
= rio_mport_write_config_32(mport
, destid
, hopcount
,
151 RIO_SPx_L2_Gn_ENTRYy_CSR(table
, 0, i
),
152 RIO_RT_ENTRY_DROP_PKT
);
161 * This routine performs device-specific initialization only.
162 * All standard EM configuration should be performed at upper level.
165 idtg3_em_init(struct rio_dev
*rdev
)
170 pr_debug("RIO: %s [%d:%d]\n", __func__
, rdev
->destid
, rdev
->hopcount
);
172 /* Disable assertion of interrupt signal */
173 rio_write_config_32(rdev
, RIO_EM_DEV_INT_EN
, 0);
175 /* Disable port-write event notifications during initialization */
176 rio_write_config_32(rdev
, rdev
->em_efptr
+ RIO_EM_PW_TX_CTRL
,
177 RIO_EM_PW_TX_CTRL_PW_DIS
);
179 /* Configure Port-Write notifications for hot-swap events */
180 tmp
= RIO_GET_TOTAL_PORTS(rdev
->swpinfo
);
181 for (i
= 0; i
< tmp
; i
++) {
183 rio_read_config_32(rdev
,
184 RIO_DEV_PORT_N_ERR_STS_CSR(rdev
, i
),
186 if (rval
& RIO_PORT_N_ERR_STS_PORT_UA
)
189 /* Clear events signaled before enabling notification */
190 rio_write_config_32(rdev
,
191 rdev
->em_efptr
+ RIO_EM_PN_ERR_DETECT(i
), 0);
193 /* Enable event notifications */
194 rio_write_config_32(rdev
,
195 rdev
->em_efptr
+ RIO_EM_PN_ERRRATE_EN(i
),
196 RIO_EM_PN_ERRRATE_EN_OK2U
| RIO_EM_PN_ERRRATE_EN_U2OK
);
197 /* Enable port-write generation on events */
198 rio_write_config_32(rdev
, RIO_PLM_SPx_PW_EN(i
),
199 RIO_PLM_SPx_PW_EN_OK2U
| RIO_PLM_SPx_PW_EN_LINIT
);
203 /* Set Port-Write destination port */
204 tmp
= RIO_GET_PORT_NUM(rdev
->swpinfo
);
205 rio_write_config_32(rdev
, RIO_PW_ROUTE
, 1 << tmp
);
208 /* Enable sending port-write event notifications */
209 rio_write_config_32(rdev
, rdev
->em_efptr
+ RIO_EM_PW_TX_CTRL
, 0);
211 /* set TVAL = ~50us */
212 rio_write_config_32(rdev
,
213 rdev
->phys_efptr
+ RIO_PORT_LINKTO_CTL_CSR
, 0x8e << 8);
219 * idtg3_em_handler - device-specific error handler
221 * If the link is down (PORT_UNINIT) does nothing - this is considered
222 * as link partner removal from the port.
224 * If the link is up (PORT_OK) - situation is handled as *new* device insertion.
225 * In this case ERR_STOP bits are cleared by issuing soft reset command to the
226 * reporting port. Inbound and outbound ackIDs are cleared by the reset as well.
227 * This way the port is synchronized with freshly inserted device (assuming it
228 * was reset/powered-up on insertion).
230 * TODO: This is not sufficient in a situation when a link between two devices
231 * was down and up again (e.g. cable disconnect). For that situation full ackID
232 * realignment process has to be implemented.
235 idtg3_em_handler(struct rio_dev
*rdev
, u8 pnum
)
240 rio_read_config_32(rdev
,
241 RIO_DEV_PORT_N_ERR_STS_CSR(rdev
, pnum
),
244 /* Do nothing for device/link removal */
245 if (err_status
& RIO_PORT_N_ERR_STS_PORT_UNINIT
)
248 /* When link is OK we have a device insertion.
249 * Request port soft reset to clear errors if they present.
250 * Inbound and outbound ackIDs will be 0 after reset.
252 if (err_status
& (RIO_PORT_N_ERR_STS_OUT_ES
|
253 RIO_PORT_N_ERR_STS_INP_ES
)) {
254 rio_read_config_32(rdev
, RIO_PLM_SPx_IMP_SPEC_CTL(pnum
), &rval
);
255 rio_write_config_32(rdev
, RIO_PLM_SPx_IMP_SPEC_CTL(pnum
),
256 rval
| RIO_PLM_SPx_IMP_SPEC_CTL_SOFT_RST
);
258 rio_write_config_32(rdev
, RIO_PLM_SPx_IMP_SPEC_CTL(pnum
), rval
);
265 static struct rio_switch_ops idtg3_switch_ops
= {
266 .owner
= THIS_MODULE
,
267 .add_entry
= idtg3_route_add_entry
,
268 .get_entry
= idtg3_route_get_entry
,
269 .clr_table
= idtg3_route_clr_table
,
270 .em_init
= idtg3_em_init
,
271 .em_handle
= idtg3_em_handler
,
274 static int idtg3_probe(struct rio_dev
*rdev
, const struct rio_device_id
*id
)
276 pr_debug("RIO: %s for %s\n", __func__
, rio_name(rdev
));
278 spin_lock(&rdev
->rswitch
->lock
);
280 if (rdev
->rswitch
->ops
) {
281 spin_unlock(&rdev
->rswitch
->lock
);
285 rdev
->rswitch
->ops
= &idtg3_switch_ops
;
288 /* Disable hierarchical routing support: Existing fabric
289 * enumeration/discovery process (see rio-scan.c) uses 8-bit
290 * flat destination ID routing only.
292 rio_write_config_32(rdev
, 0x5000 + RIO_BC_RT_CTL_CSR
, 0);
295 spin_unlock(&rdev
->rswitch
->lock
);
300 static void idtg3_remove(struct rio_dev
*rdev
)
302 pr_debug("RIO: %s for %s\n", __func__
, rio_name(rdev
));
303 spin_lock(&rdev
->rswitch
->lock
);
304 if (rdev
->rswitch
->ops
== &idtg3_switch_ops
)
305 rdev
->rswitch
->ops
= NULL
;
306 spin_unlock(&rdev
->rswitch
->lock
);
310 * Gen3 switches repeat sending PW messages until a corresponding event flag
311 * is cleared. Use shutdown notification to disable generation of port-write
312 * messages if their destination node is shut down.
314 static void idtg3_shutdown(struct rio_dev
*rdev
)
320 /* Currently the enumerator node acts also as PW handler */
324 pr_debug("RIO: %s(%s)\n", __func__
, rio_name(rdev
));
326 rio_read_config_32(rdev
, RIO_PW_ROUTE
, &rval
);
327 i
= RIO_GET_PORT_NUM(rdev
->swpinfo
);
329 /* Check port-write destination port */
330 if (!((1 << i
) & rval
))
333 /* Disable sending port-write event notifications if PW destID
334 * matches to one of the enumerator node
336 rio_read_config_32(rdev
, rdev
->em_efptr
+ RIO_EM_PW_TGT_DEVID
, &rval
);
338 if (rval
& RIO_EM_PW_TGT_DEVID_DEV16
)
341 destid
= ((rval
& RIO_EM_PW_TGT_DEVID_D8
) >> 16);
343 if (rdev
->net
->hport
->host_deviceid
== destid
) {
344 rio_write_config_32(rdev
,
345 rdev
->em_efptr
+ RIO_EM_PW_TX_CTRL
, 0);
346 pr_debug("RIO: %s(%s) PW transmission disabled\n",
347 __func__
, rio_name(rdev
));
351 static struct rio_device_id idtg3_id_table
[] = {
352 {RIO_DEVICE(RIO_DID_IDTRXS1632
, RIO_VID_IDT
)},
353 {RIO_DEVICE(RIO_DID_IDTRXS2448
, RIO_VID_IDT
)},
354 { 0, } /* terminate list */
357 static struct rio_driver idtg3_driver
= {
359 .id_table
= idtg3_id_table
,
360 .probe
= idtg3_probe
,
361 .remove
= idtg3_remove
,
362 .shutdown
= idtg3_shutdown
,
365 static int __init
idtg3_init(void)
367 return rio_register_driver(&idtg3_driver
);
370 static void __exit
idtg3_exit(void)
372 pr_debug("RIO: %s\n", __func__
);
373 rio_unregister_driver(&idtg3_driver
);
374 pr_debug("RIO: %s done\n", __func__
);
377 device_initcall(idtg3_init
);
378 module_exit(idtg3_exit
);
380 MODULE_DESCRIPTION("IDT RXS Gen.3 Serial RapidIO switch family driver");
381 MODULE_AUTHOR("Integrated Device Technology, Inc.");
382 MODULE_LICENSE("GPL");