blob: 00a71ebb5cac2f3b4a7b11248d32139db67a772c [file] [log] [blame]
Alexandre Bouninea3725c42010-10-27 15:34:33 -07001/*
2 * IDT CPS Gen.2 Serial RapidIO switch family support
3 *
4 * Copyright 2010 Integrated Device Technology, Inc.
5 * Alexandre Bounine <alexandre.bounine@idt.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
Paul Gortmaker0a422f22011-07-15 16:48:24 -040013#include <linux/stat.h>
Alexandre Bounine2ec3ba62013-07-03 15:08:50 -070014#include <linux/module.h>
Alexandre Bouninea3725c42010-10-27 15:34:33 -070015#include <linux/rio.h>
16#include <linux/rio_drv.h>
17#include <linux/rio_ids.h>
18#include <linux/delay.h>
19#include "../rio.h"
20
21#define LOCAL_RTE_CONF_DESTID_SEL 0x010070
22#define LOCAL_RTE_CONF_DESTID_SEL_PSEL 0x0000001f
23
24#define IDT_LT_ERR_REPORT_EN 0x03100c
25
26#define IDT_PORT_ERR_REPORT_EN(n) (0x031044 + (n)*0x40)
27#define IDT_PORT_ERR_REPORT_EN_BC 0x03ff04
28
29#define IDT_PORT_ISERR_REPORT_EN(n) (0x03104C + (n)*0x40)
30#define IDT_PORT_ISERR_REPORT_EN_BC 0x03ff0c
31#define IDT_PORT_INIT_TX_ACQUIRED 0x00000020
32
33#define IDT_LANE_ERR_REPORT_EN(n) (0x038010 + (n)*0x100)
34#define IDT_LANE_ERR_REPORT_EN_BC 0x03ff10
35
36#define IDT_DEV_CTRL_1 0xf2000c
37#define IDT_DEV_CTRL_1_GENPW 0x02000000
38#define IDT_DEV_CTRL_1_PRSTBEH 0x00000001
39
40#define IDT_CFGBLK_ERR_CAPTURE_EN 0x020008
41#define IDT_CFGBLK_ERR_REPORT 0xf20014
42#define IDT_CFGBLK_ERR_REPORT_GENPW 0x00000002
43
44#define IDT_AUX_PORT_ERR_CAP_EN 0x020000
45#define IDT_AUX_ERR_REPORT_EN 0xf20018
46#define IDT_AUX_PORT_ERR_LOG_I2C 0x00000002
47#define IDT_AUX_PORT_ERR_LOG_JTAG 0x00000001
48
49#define IDT_ISLTL_ADDRESS_CAP 0x021014
50
51#define IDT_RIO_DOMAIN 0xf20020
52#define IDT_RIO_DOMAIN_MASK 0x000000ff
53
54#define IDT_PW_INFO_CSR 0xf20024
55
56#define IDT_SOFT_RESET 0xf20040
57#define IDT_SOFT_RESET_REQ 0x00030097
58
59#define IDT_I2C_MCTRL 0xf20050
60#define IDT_I2C_MCTRL_GENPW 0x04000000
61
62#define IDT_JTAG_CTRL 0xf2005c
63#define IDT_JTAG_CTRL_GENPW 0x00000002
64
65#define IDT_LANE_CTRL(n) (0xff8000 + (n)*0x100)
66#define IDT_LANE_CTRL_BC 0xffff00
67#define IDT_LANE_CTRL_GENPW 0x00200000
68#define IDT_LANE_DFE_1_BC 0xffff18
69#define IDT_LANE_DFE_2_BC 0xffff1c
70
71#define IDT_PORT_OPS(n) (0xf40004 + (n)*0x100)
72#define IDT_PORT_OPS_GENPW 0x08000000
73#define IDT_PORT_OPS_PL_ELOG 0x00000040
74#define IDT_PORT_OPS_LL_ELOG 0x00000020
75#define IDT_PORT_OPS_LT_ELOG 0x00000010
76#define IDT_PORT_OPS_BC 0xf4ff04
77
78#define IDT_PORT_ISERR_DET(n) (0xf40008 + (n)*0x100)
79
80#define IDT_ERR_CAP 0xfd0000
81#define IDT_ERR_CAP_LOG_OVERWR 0x00000004
82
83#define IDT_ERR_RD 0xfd0004
84
85#define IDT_DEFAULT_ROUTE 0xde
86#define IDT_NO_ROUTE 0xdf
87
88static int
89idtg2_route_add_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
90 u16 table, u16 route_destid, u8 route_port)
91{
92 /*
93 * Select routing table to update
94 */
95 if (table == RIO_GLOBAL_TABLE)
96 table = 0;
97 else
98 table++;
99
Alexandre Bounine0bf24612011-05-17 15:44:08 -0700100 if (route_port == RIO_INVALID_ROUTE)
101 route_port = IDT_DEFAULT_ROUTE;
102
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700103 rio_mport_write_config_32(mport, destid, hopcount,
104 LOCAL_RTE_CONF_DESTID_SEL, table);
105
106 /*
107 * Program destination port for the specified destID
108 */
109 rio_mport_write_config_32(mport, destid, hopcount,
110 RIO_STD_RTE_CONF_DESTID_SEL_CSR,
111 (u32)route_destid);
112
113 rio_mport_write_config_32(mport, destid, hopcount,
114 RIO_STD_RTE_CONF_PORT_SEL_CSR,
115 (u32)route_port);
116 udelay(10);
117
118 return 0;
119}
120
121static int
122idtg2_route_get_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
123 u16 table, u16 route_destid, u8 *route_port)
124{
125 u32 result;
126
127 /*
128 * Select routing table to read
129 */
130 if (table == RIO_GLOBAL_TABLE)
131 table = 0;
132 else
133 table++;
134
135 rio_mport_write_config_32(mport, destid, hopcount,
136 LOCAL_RTE_CONF_DESTID_SEL, table);
137
138 rio_mport_write_config_32(mport, destid, hopcount,
139 RIO_STD_RTE_CONF_DESTID_SEL_CSR,
140 route_destid);
141
142 rio_mport_read_config_32(mport, destid, hopcount,
143 RIO_STD_RTE_CONF_PORT_SEL_CSR, &result);
144
145 if (IDT_DEFAULT_ROUTE == (u8)result || IDT_NO_ROUTE == (u8)result)
146 *route_port = RIO_INVALID_ROUTE;
147 else
148 *route_port = (u8)result;
149
150 return 0;
151}
152
153static int
154idtg2_route_clr_table(struct rio_mport *mport, u16 destid, u8 hopcount,
155 u16 table)
156{
157 u32 i;
158
159 /*
160 * Select routing table to read
161 */
162 if (table == RIO_GLOBAL_TABLE)
163 table = 0;
164 else
165 table++;
166
167 rio_mport_write_config_32(mport, destid, hopcount,
168 LOCAL_RTE_CONF_DESTID_SEL, table);
169
170 for (i = RIO_STD_RTE_CONF_EXTCFGEN;
171 i <= (RIO_STD_RTE_CONF_EXTCFGEN | 0xff);) {
172 rio_mport_write_config_32(mport, destid, hopcount,
173 RIO_STD_RTE_CONF_DESTID_SEL_CSR, i);
174 rio_mport_write_config_32(mport, destid, hopcount,
175 RIO_STD_RTE_CONF_PORT_SEL_CSR,
176 (IDT_DEFAULT_ROUTE << 24) | (IDT_DEFAULT_ROUTE << 16) |
177 (IDT_DEFAULT_ROUTE << 8) | IDT_DEFAULT_ROUTE);
178 i += 4;
179 }
180
181 return 0;
182}
183
184
185static int
186idtg2_set_domain(struct rio_mport *mport, u16 destid, u8 hopcount,
187 u8 sw_domain)
188{
189 /*
190 * Switch domain configuration operates only at global level
191 */
192 rio_mport_write_config_32(mport, destid, hopcount,
193 IDT_RIO_DOMAIN, (u32)sw_domain);
194 return 0;
195}
196
197static int
198idtg2_get_domain(struct rio_mport *mport, u16 destid, u8 hopcount,
199 u8 *sw_domain)
200{
201 u32 regval;
202
203 /*
204 * Switch domain configuration operates only at global level
205 */
206 rio_mport_read_config_32(mport, destid, hopcount,
207 IDT_RIO_DOMAIN, &regval);
208
209 *sw_domain = (u8)(regval & 0xff);
210
211 return 0;
212}
213
214static int
215idtg2_em_init(struct rio_dev *rdev)
216{
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700217 u32 regval;
218 int i, tmp;
219
220 /*
221 * This routine performs device-specific initialization only.
222 * All standard EM configuration should be performed at upper level.
223 */
224
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800225 pr_debug("RIO: %s [%d:%d]\n", __func__, rdev->destid, rdev->hopcount);
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700226
227 /* Set Port-Write info CSR: PRIO=3 and CRF=1 */
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800228 rio_write_config_32(rdev, IDT_PW_INFO_CSR, 0x0000e000);
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700229
230 /*
231 * Configure LT LAYER error reporting.
232 */
233
234 /* Enable standard (RIO.p8) error reporting */
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800235 rio_write_config_32(rdev, IDT_LT_ERR_REPORT_EN,
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700236 REM_LTL_ERR_ILLTRAN | REM_LTL_ERR_UNSOLR |
237 REM_LTL_ERR_UNSUPTR);
238
239 /* Use Port-Writes for LT layer error reporting.
240 * Enable per-port reset
241 */
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800242 rio_read_config_32(rdev, IDT_DEV_CTRL_1, &regval);
243 rio_write_config_32(rdev, IDT_DEV_CTRL_1,
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700244 regval | IDT_DEV_CTRL_1_GENPW | IDT_DEV_CTRL_1_PRSTBEH);
245
246 /*
247 * Configure PORT error reporting.
248 */
249
250 /* Report all RIO.p8 errors supported by device */
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800251 rio_write_config_32(rdev, IDT_PORT_ERR_REPORT_EN_BC, 0x807e8037);
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700252
253 /* Configure reporting of implementation specific errors/events */
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800254 rio_write_config_32(rdev, IDT_PORT_ISERR_REPORT_EN_BC,
255 IDT_PORT_INIT_TX_ACQUIRED);
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700256
257 /* Use Port-Writes for port error reporting and enable error logging */
258 tmp = RIO_GET_TOTAL_PORTS(rdev->swpinfo);
259 for (i = 0; i < tmp; i++) {
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800260 rio_read_config_32(rdev, IDT_PORT_OPS(i), &regval);
261 rio_write_config_32(rdev,
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700262 IDT_PORT_OPS(i), regval | IDT_PORT_OPS_GENPW |
263 IDT_PORT_OPS_PL_ELOG |
264 IDT_PORT_OPS_LL_ELOG |
265 IDT_PORT_OPS_LT_ELOG);
266 }
267 /* Overwrite error log if full */
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800268 rio_write_config_32(rdev, IDT_ERR_CAP, IDT_ERR_CAP_LOG_OVERWR);
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700269
270 /*
271 * Configure LANE error reporting.
272 */
273
274 /* Disable line error reporting */
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800275 rio_write_config_32(rdev, IDT_LANE_ERR_REPORT_EN_BC, 0);
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700276
277 /* Use Port-Writes for lane error reporting (when enabled)
278 * (do per-lane update because lanes may have different configuration)
279 */
280 tmp = (rdev->did == RIO_DID_IDTCPS1848) ? 48 : 16;
281 for (i = 0; i < tmp; i++) {
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800282 rio_read_config_32(rdev, IDT_LANE_CTRL(i), &regval);
283 rio_write_config_32(rdev, IDT_LANE_CTRL(i),
284 regval | IDT_LANE_CTRL_GENPW);
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700285 }
286
287 /*
288 * Configure AUX error reporting.
289 */
290
291 /* Disable JTAG and I2C Error capture */
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800292 rio_write_config_32(rdev, IDT_AUX_PORT_ERR_CAP_EN, 0);
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700293
294 /* Disable JTAG and I2C Error reporting/logging */
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800295 rio_write_config_32(rdev, IDT_AUX_ERR_REPORT_EN, 0);
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700296
297 /* Disable Port-Write notification from JTAG */
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800298 rio_write_config_32(rdev, IDT_JTAG_CTRL, 0);
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700299
300 /* Disable Port-Write notification from I2C */
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800301 rio_read_config_32(rdev, IDT_I2C_MCTRL, &regval);
302 rio_write_config_32(rdev, IDT_I2C_MCTRL, regval & ~IDT_I2C_MCTRL_GENPW);
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700303
304 /*
305 * Configure CFG_BLK error reporting.
306 */
307
308 /* Disable Configuration Block error capture */
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800309 rio_write_config_32(rdev, IDT_CFGBLK_ERR_CAPTURE_EN, 0);
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700310
311 /* Disable Port-Writes for Configuration Block error reporting */
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800312 rio_read_config_32(rdev, IDT_CFGBLK_ERR_REPORT, &regval);
313 rio_write_config_32(rdev, IDT_CFGBLK_ERR_REPORT,
314 regval & ~IDT_CFGBLK_ERR_REPORT_GENPW);
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700315
316 /* set TVAL = ~50us */
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800317 rio_write_config_32(rdev,
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700318 rdev->phys_efptr + RIO_PORT_LINKTO_CTL_CSR, 0x8e << 8);
319
320 return 0;
321}
322
323static int
324idtg2_em_handler(struct rio_dev *rdev, u8 portnum)
325{
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700326 u32 regval, em_perrdet, em_ltlerrdet;
327
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800328 rio_read_config_32(rdev,
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700329 rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, &em_ltlerrdet);
330 if (em_ltlerrdet) {
331 /* Service Logical/Transport Layer Error(s) */
332 if (em_ltlerrdet & REM_LTL_ERR_IMPSPEC) {
333 /* Implementation specific error reported */
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800334 rio_read_config_32(rdev,
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700335 IDT_ISLTL_ADDRESS_CAP, &regval);
336
337 pr_debug("RIO: %s Implementation Specific LTL errors" \
338 " 0x%x @(0x%x)\n",
339 rio_name(rdev), em_ltlerrdet, regval);
340
341 /* Clear implementation specific address capture CSR */
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800342 rio_write_config_32(rdev, IDT_ISLTL_ADDRESS_CAP, 0);
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700343
344 }
345 }
346
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800347 rio_read_config_32(rdev,
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700348 rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), &em_perrdet);
349 if (em_perrdet) {
350 /* Service Port-Level Error(s) */
351 if (em_perrdet & REM_PED_IMPL_SPEC) {
352 /* Implementation Specific port error reported */
353
354 /* Get IS errors reported */
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800355 rio_read_config_32(rdev,
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700356 IDT_PORT_ISERR_DET(portnum), &regval);
357
358 pr_debug("RIO: %s Implementation Specific Port" \
359 " errors 0x%x\n", rio_name(rdev), regval);
360
361 /* Clear all implementation specific events */
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800362 rio_write_config_32(rdev,
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700363 IDT_PORT_ISERR_DET(portnum), 0);
364 }
365 }
366
367 return 0;
368}
369
370static ssize_t
371idtg2_show_errlog(struct device *dev, struct device_attribute *attr, char *buf)
372{
373 struct rio_dev *rdev = to_rio_dev(dev);
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700374 ssize_t len = 0;
375 u32 regval;
376
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800377 while (!rio_read_config_32(rdev, IDT_ERR_RD, &regval)) {
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700378 if (!regval) /* 0 = end of log */
379 break;
380 len += snprintf(buf + len, PAGE_SIZE - len,
381 "%08x\n", regval);
382 if (len >= (PAGE_SIZE - 10))
383 break;
384 }
385
386 return len;
387}
388
389static DEVICE_ATTR(errlog, S_IRUGO, idtg2_show_errlog, NULL);
390
Alexandre Bounine2ec3ba62013-07-03 15:08:50 -0700391static int idtg2_sysfs(struct rio_dev *rdev, bool create)
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700392{
393 struct device *dev = &rdev->dev;
394 int err = 0;
395
Alexandre Bounine2ec3ba62013-07-03 15:08:50 -0700396 if (create) {
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700397 /* Initialize sysfs entries */
398 err = device_create_file(dev, &dev_attr_errlog);
399 if (err)
400 dev_err(dev, "Unable create sysfs errlog file\n");
401 } else
402 device_remove_file(dev, &dev_attr_errlog);
403
404 return err;
405}
406
Alexandre Bounine2ec3ba62013-07-03 15:08:50 -0700407static struct rio_switch_ops idtg2_switch_ops = {
408 .owner = THIS_MODULE,
409 .add_entry = idtg2_route_add_entry,
410 .get_entry = idtg2_route_get_entry,
411 .clr_table = idtg2_route_clr_table,
412 .set_domain = idtg2_set_domain,
413 .get_domain = idtg2_get_domain,
414 .em_init = idtg2_em_init,
415 .em_handle = idtg2_em_handler,
416};
417
418static int idtg2_probe(struct rio_dev *rdev, const struct rio_device_id *id)
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700419{
420 pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700421
Alexandre Bounine2ec3ba62013-07-03 15:08:50 -0700422 spin_lock(&rdev->rswitch->lock);
423
424 if (rdev->rswitch->ops) {
425 spin_unlock(&rdev->rswitch->lock);
426 return -EINVAL;
427 }
428
429 rdev->rswitch->ops = &idtg2_switch_ops;
430
431 if (rdev->do_enum) {
Alexandre Bounine0bf24612011-05-17 15:44:08 -0700432 /* Ensure that default routing is disabled on startup */
433 rio_write_config_32(rdev,
434 RIO_STD_RTE_DEFAULT_PORT, IDT_NO_ROUTE);
435 }
436
Alexandre Bounine2ec3ba62013-07-03 15:08:50 -0700437 /* Create device-specific sysfs attributes */
438 idtg2_sysfs(rdev, true);
439
440 spin_unlock(&rdev->rswitch->lock);
Alexandre Bouninea3725c42010-10-27 15:34:33 -0700441 return 0;
442}
443
Alexandre Bounine2ec3ba62013-07-03 15:08:50 -0700444static void idtg2_remove(struct rio_dev *rdev)
445{
446 pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
447 spin_lock(&rdev->rswitch->lock);
448 if (rdev->rswitch->ops != &idtg2_switch_ops) {
449 spin_unlock(&rdev->rswitch->lock);
450 return;
451 }
452 rdev->rswitch->ops = NULL;
453
454 /* Remove device-specific sysfs attributes */
455 idtg2_sysfs(rdev, false);
456
457 spin_unlock(&rdev->rswitch->lock);
458}
459
460static struct rio_device_id idtg2_id_table[] = {
461 {RIO_DEVICE(RIO_DID_IDTCPS1848, RIO_VID_IDT)},
462 {RIO_DEVICE(RIO_DID_IDTCPS1616, RIO_VID_IDT)},
463 {RIO_DEVICE(RIO_DID_IDTVPS1616, RIO_VID_IDT)},
464 {RIO_DEVICE(RIO_DID_IDTSPS1616, RIO_VID_IDT)},
465 {RIO_DEVICE(RIO_DID_IDTCPS1432, RIO_VID_IDT)},
466 { 0, } /* terminate list */
467};
468
469static struct rio_driver idtg2_driver = {
470 .name = "idt_gen2",
471 .id_table = idtg2_id_table,
472 .probe = idtg2_probe,
473 .remove = idtg2_remove,
474};
475
476static int __init idtg2_init(void)
477{
478 return rio_register_driver(&idtg2_driver);
479}
480
481static void __exit idtg2_exit(void)
482{
483 pr_debug("RIO: %s\n", __func__);
484 rio_unregister_driver(&idtg2_driver);
485 pr_debug("RIO: %s done\n", __func__);
486}
487
488device_initcall(idtg2_init);
489module_exit(idtg2_exit);
490
491MODULE_DESCRIPTION("IDT CPS Gen.2 Serial RapidIO switch family driver");
492MODULE_AUTHOR("Integrated Device Technology, Inc.");
493MODULE_LICENSE("GPL");