idt_gen2.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. /*
  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. #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>
  18. #include <asm/page.h>
  19. #include "../rio.h"
  20. #define LOCAL_RTE_CONF_DESTID_SEL 0x010070
  21. #define LOCAL_RTE_CONF_DESTID_SEL_PSEL 0x0000001f
  22. #define IDT_LT_ERR_REPORT_EN 0x03100c
  23. #define IDT_PORT_ERR_REPORT_EN(n) (0x031044 + (n)*0x40)
  24. #define IDT_PORT_ERR_REPORT_EN_BC 0x03ff04
  25. #define IDT_PORT_ISERR_REPORT_EN(n) (0x03104C + (n)*0x40)
  26. #define IDT_PORT_ISERR_REPORT_EN_BC 0x03ff0c
  27. #define IDT_PORT_INIT_TX_ACQUIRED 0x00000020
  28. #define IDT_LANE_ERR_REPORT_EN(n) (0x038010 + (n)*0x100)
  29. #define IDT_LANE_ERR_REPORT_EN_BC 0x03ff10
  30. #define IDT_DEV_CTRL_1 0xf2000c
  31. #define IDT_DEV_CTRL_1_GENPW 0x02000000
  32. #define IDT_DEV_CTRL_1_PRSTBEH 0x00000001
  33. #define IDT_CFGBLK_ERR_CAPTURE_EN 0x020008
  34. #define IDT_CFGBLK_ERR_REPORT 0xf20014
  35. #define IDT_CFGBLK_ERR_REPORT_GENPW 0x00000002
  36. #define IDT_AUX_PORT_ERR_CAP_EN 0x020000
  37. #define IDT_AUX_ERR_REPORT_EN 0xf20018
  38. #define IDT_AUX_PORT_ERR_LOG_I2C 0x00000002
  39. #define IDT_AUX_PORT_ERR_LOG_JTAG 0x00000001
  40. #define IDT_ISLTL_ADDRESS_CAP 0x021014
  41. #define IDT_RIO_DOMAIN 0xf20020
  42. #define IDT_RIO_DOMAIN_MASK 0x000000ff
  43. #define IDT_PW_INFO_CSR 0xf20024
  44. #define IDT_SOFT_RESET 0xf20040
  45. #define IDT_SOFT_RESET_REQ 0x00030097
  46. #define IDT_I2C_MCTRL 0xf20050
  47. #define IDT_I2C_MCTRL_GENPW 0x04000000
  48. #define IDT_JTAG_CTRL 0xf2005c
  49. #define IDT_JTAG_CTRL_GENPW 0x00000002
  50. #define IDT_LANE_CTRL(n) (0xff8000 + (n)*0x100)
  51. #define IDT_LANE_CTRL_BC 0xffff00
  52. #define IDT_LANE_CTRL_GENPW 0x00200000
  53. #define IDT_LANE_DFE_1_BC 0xffff18
  54. #define IDT_LANE_DFE_2_BC 0xffff1c
  55. #define IDT_PORT_OPS(n) (0xf40004 + (n)*0x100)
  56. #define IDT_PORT_OPS_GENPW 0x08000000
  57. #define IDT_PORT_OPS_PL_ELOG 0x00000040
  58. #define IDT_PORT_OPS_LL_ELOG 0x00000020
  59. #define IDT_PORT_OPS_LT_ELOG 0x00000010
  60. #define IDT_PORT_OPS_BC 0xf4ff04
  61. #define IDT_PORT_ISERR_DET(n) (0xf40008 + (n)*0x100)
  62. #define IDT_ERR_CAP 0xfd0000
  63. #define IDT_ERR_CAP_LOG_OVERWR 0x00000004
  64. #define IDT_ERR_RD 0xfd0004
  65. #define IDT_DEFAULT_ROUTE 0xde
  66. #define IDT_NO_ROUTE 0xdf
  67. static int
  68. idtg2_route_add_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
  69. u16 table, u16 route_destid, u8 route_port)
  70. {
  71. /*
  72. * Select routing table to update
  73. */
  74. if (table == RIO_GLOBAL_TABLE)
  75. table = 0;
  76. else
  77. table++;
  78. if (route_port == RIO_INVALID_ROUTE)
  79. route_port = IDT_DEFAULT_ROUTE;
  80. rio_mport_write_config_32(mport, destid, hopcount,
  81. LOCAL_RTE_CONF_DESTID_SEL, table);
  82. /*
  83. * Program destination port for the specified destID
  84. */
  85. rio_mport_write_config_32(mport, destid, hopcount,
  86. RIO_STD_RTE_CONF_DESTID_SEL_CSR,
  87. (u32)route_destid);
  88. rio_mport_write_config_32(mport, destid, hopcount,
  89. RIO_STD_RTE_CONF_PORT_SEL_CSR,
  90. (u32)route_port);
  91. udelay(10);
  92. return 0;
  93. }
  94. static int
  95. idtg2_route_get_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
  96. u16 table, u16 route_destid, u8 *route_port)
  97. {
  98. u32 result;
  99. /*
  100. * Select routing table to read
  101. */
  102. if (table == RIO_GLOBAL_TABLE)
  103. table = 0;
  104. else
  105. table++;
  106. rio_mport_write_config_32(mport, destid, hopcount,
  107. LOCAL_RTE_CONF_DESTID_SEL, table);
  108. rio_mport_write_config_32(mport, destid, hopcount,
  109. RIO_STD_RTE_CONF_DESTID_SEL_CSR,
  110. route_destid);
  111. rio_mport_read_config_32(mport, destid, hopcount,
  112. RIO_STD_RTE_CONF_PORT_SEL_CSR, &result);
  113. if (IDT_DEFAULT_ROUTE == (u8)result || IDT_NO_ROUTE == (u8)result)
  114. *route_port = RIO_INVALID_ROUTE;
  115. else
  116. *route_port = (u8)result;
  117. return 0;
  118. }
  119. static int
  120. idtg2_route_clr_table(struct rio_mport *mport, u16 destid, u8 hopcount,
  121. u16 table)
  122. {
  123. u32 i;
  124. /*
  125. * Select routing table to read
  126. */
  127. if (table == RIO_GLOBAL_TABLE)
  128. table = 0;
  129. else
  130. table++;
  131. rio_mport_write_config_32(mport, destid, hopcount,
  132. LOCAL_RTE_CONF_DESTID_SEL, table);
  133. for (i = RIO_STD_RTE_CONF_EXTCFGEN;
  134. i <= (RIO_STD_RTE_CONF_EXTCFGEN | 0xff);) {
  135. rio_mport_write_config_32(mport, destid, hopcount,
  136. RIO_STD_RTE_CONF_DESTID_SEL_CSR, i);
  137. rio_mport_write_config_32(mport, destid, hopcount,
  138. RIO_STD_RTE_CONF_PORT_SEL_CSR,
  139. (IDT_DEFAULT_ROUTE << 24) | (IDT_DEFAULT_ROUTE << 16) |
  140. (IDT_DEFAULT_ROUTE << 8) | IDT_DEFAULT_ROUTE);
  141. i += 4;
  142. }
  143. return 0;
  144. }
  145. static int
  146. idtg2_set_domain(struct rio_mport *mport, u16 destid, u8 hopcount,
  147. u8 sw_domain)
  148. {
  149. /*
  150. * Switch domain configuration operates only at global level
  151. */
  152. rio_mport_write_config_32(mport, destid, hopcount,
  153. IDT_RIO_DOMAIN, (u32)sw_domain);
  154. return 0;
  155. }
  156. static int
  157. idtg2_get_domain(struct rio_mport *mport, u16 destid, u8 hopcount,
  158. u8 *sw_domain)
  159. {
  160. u32 regval;
  161. /*
  162. * Switch domain configuration operates only at global level
  163. */
  164. rio_mport_read_config_32(mport, destid, hopcount,
  165. IDT_RIO_DOMAIN, &regval);
  166. *sw_domain = (u8)(regval & 0xff);
  167. return 0;
  168. }
  169. static int
  170. idtg2_em_init(struct rio_dev *rdev)
  171. {
  172. u32 regval;
  173. int i, tmp;
  174. /*
  175. * This routine performs device-specific initialization only.
  176. * All standard EM configuration should be performed at upper level.
  177. */
  178. pr_debug("RIO: %s [%d:%d]\n", __func__, rdev->destid, rdev->hopcount);
  179. /* Set Port-Write info CSR: PRIO=3 and CRF=1 */
  180. rio_write_config_32(rdev, IDT_PW_INFO_CSR, 0x0000e000);
  181. /*
  182. * Configure LT LAYER error reporting.
  183. */
  184. /* Enable standard (RIO.p8) error reporting */
  185. rio_write_config_32(rdev, IDT_LT_ERR_REPORT_EN,
  186. REM_LTL_ERR_ILLTRAN | REM_LTL_ERR_UNSOLR |
  187. REM_LTL_ERR_UNSUPTR);
  188. /* Use Port-Writes for LT layer error reporting.
  189. * Enable per-port reset
  190. */
  191. rio_read_config_32(rdev, IDT_DEV_CTRL_1, &regval);
  192. rio_write_config_32(rdev, IDT_DEV_CTRL_1,
  193. regval | IDT_DEV_CTRL_1_GENPW | IDT_DEV_CTRL_1_PRSTBEH);
  194. /*
  195. * Configure PORT error reporting.
  196. */
  197. /* Report all RIO.p8 errors supported by device */
  198. rio_write_config_32(rdev, IDT_PORT_ERR_REPORT_EN_BC, 0x807e8037);
  199. /* Configure reporting of implementation specific errors/events */
  200. rio_write_config_32(rdev, IDT_PORT_ISERR_REPORT_EN_BC,
  201. IDT_PORT_INIT_TX_ACQUIRED);
  202. /* Use Port-Writes for port error reporting and enable error logging */
  203. tmp = RIO_GET_TOTAL_PORTS(rdev->swpinfo);
  204. for (i = 0; i < tmp; i++) {
  205. rio_read_config_32(rdev, IDT_PORT_OPS(i), &regval);
  206. rio_write_config_32(rdev,
  207. IDT_PORT_OPS(i), regval | IDT_PORT_OPS_GENPW |
  208. IDT_PORT_OPS_PL_ELOG |
  209. IDT_PORT_OPS_LL_ELOG |
  210. IDT_PORT_OPS_LT_ELOG);
  211. }
  212. /* Overwrite error log if full */
  213. rio_write_config_32(rdev, IDT_ERR_CAP, IDT_ERR_CAP_LOG_OVERWR);
  214. /*
  215. * Configure LANE error reporting.
  216. */
  217. /* Disable line error reporting */
  218. rio_write_config_32(rdev, IDT_LANE_ERR_REPORT_EN_BC, 0);
  219. /* Use Port-Writes for lane error reporting (when enabled)
  220. * (do per-lane update because lanes may have different configuration)
  221. */
  222. tmp = (rdev->did == RIO_DID_IDTCPS1848) ? 48 : 16;
  223. for (i = 0; i < tmp; i++) {
  224. rio_read_config_32(rdev, IDT_LANE_CTRL(i), &regval);
  225. rio_write_config_32(rdev, IDT_LANE_CTRL(i),
  226. regval | IDT_LANE_CTRL_GENPW);
  227. }
  228. /*
  229. * Configure AUX error reporting.
  230. */
  231. /* Disable JTAG and I2C Error capture */
  232. rio_write_config_32(rdev, IDT_AUX_PORT_ERR_CAP_EN, 0);
  233. /* Disable JTAG and I2C Error reporting/logging */
  234. rio_write_config_32(rdev, IDT_AUX_ERR_REPORT_EN, 0);
  235. /* Disable Port-Write notification from JTAG */
  236. rio_write_config_32(rdev, IDT_JTAG_CTRL, 0);
  237. /* Disable Port-Write notification from I2C */
  238. rio_read_config_32(rdev, IDT_I2C_MCTRL, &regval);
  239. rio_write_config_32(rdev, IDT_I2C_MCTRL, regval & ~IDT_I2C_MCTRL_GENPW);
  240. /*
  241. * Configure CFG_BLK error reporting.
  242. */
  243. /* Disable Configuration Block error capture */
  244. rio_write_config_32(rdev, IDT_CFGBLK_ERR_CAPTURE_EN, 0);
  245. /* Disable Port-Writes for Configuration Block error reporting */
  246. rio_read_config_32(rdev, IDT_CFGBLK_ERR_REPORT, &regval);
  247. rio_write_config_32(rdev, IDT_CFGBLK_ERR_REPORT,
  248. regval & ~IDT_CFGBLK_ERR_REPORT_GENPW);
  249. /* set TVAL = ~50us */
  250. rio_write_config_32(rdev,
  251. rdev->phys_efptr + RIO_PORT_LINKTO_CTL_CSR, 0x8e << 8);
  252. return 0;
  253. }
  254. static int
  255. idtg2_em_handler(struct rio_dev *rdev, u8 portnum)
  256. {
  257. u32 regval, em_perrdet, em_ltlerrdet;
  258. rio_read_config_32(rdev,
  259. rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, &em_ltlerrdet);
  260. if (em_ltlerrdet) {
  261. /* Service Logical/Transport Layer Error(s) */
  262. if (em_ltlerrdet & REM_LTL_ERR_IMPSPEC) {
  263. /* Implementation specific error reported */
  264. rio_read_config_32(rdev,
  265. IDT_ISLTL_ADDRESS_CAP, &regval);
  266. pr_debug("RIO: %s Implementation Specific LTL errors" \
  267. " 0x%x @(0x%x)\n",
  268. rio_name(rdev), em_ltlerrdet, regval);
  269. /* Clear implementation specific address capture CSR */
  270. rio_write_config_32(rdev, IDT_ISLTL_ADDRESS_CAP, 0);
  271. }
  272. }
  273. rio_read_config_32(rdev,
  274. rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), &em_perrdet);
  275. if (em_perrdet) {
  276. /* Service Port-Level Error(s) */
  277. if (em_perrdet & REM_PED_IMPL_SPEC) {
  278. /* Implementation Specific port error reported */
  279. /* Get IS errors reported */
  280. rio_read_config_32(rdev,
  281. IDT_PORT_ISERR_DET(portnum), &regval);
  282. pr_debug("RIO: %s Implementation Specific Port" \
  283. " errors 0x%x\n", rio_name(rdev), regval);
  284. /* Clear all implementation specific events */
  285. rio_write_config_32(rdev,
  286. IDT_PORT_ISERR_DET(portnum), 0);
  287. }
  288. }
  289. return 0;
  290. }
  291. static ssize_t
  292. idtg2_show_errlog(struct device *dev, struct device_attribute *attr, char *buf)
  293. {
  294. struct rio_dev *rdev = to_rio_dev(dev);
  295. ssize_t len = 0;
  296. u32 regval;
  297. while (!rio_read_config_32(rdev, IDT_ERR_RD, &regval)) {
  298. if (!regval) /* 0 = end of log */
  299. break;
  300. len += snprintf(buf + len, PAGE_SIZE - len,
  301. "%08x\n", regval);
  302. if (len >= (PAGE_SIZE - 10))
  303. break;
  304. }
  305. return len;
  306. }
  307. static DEVICE_ATTR(errlog, S_IRUGO, idtg2_show_errlog, NULL);
  308. static int idtg2_sysfs(struct rio_dev *rdev, bool create)
  309. {
  310. struct device *dev = &rdev->dev;
  311. int err = 0;
  312. if (create) {
  313. /* Initialize sysfs entries */
  314. err = device_create_file(dev, &dev_attr_errlog);
  315. if (err)
  316. dev_err(dev, "Unable create sysfs errlog file\n");
  317. } else
  318. device_remove_file(dev, &dev_attr_errlog);
  319. return err;
  320. }
  321. static struct rio_switch_ops idtg2_switch_ops = {
  322. .owner = THIS_MODULE,
  323. .add_entry = idtg2_route_add_entry,
  324. .get_entry = idtg2_route_get_entry,
  325. .clr_table = idtg2_route_clr_table,
  326. .set_domain = idtg2_set_domain,
  327. .get_domain = idtg2_get_domain,
  328. .em_init = idtg2_em_init,
  329. .em_handle = idtg2_em_handler,
  330. };
  331. static int idtg2_probe(struct rio_dev *rdev, const struct rio_device_id *id)
  332. {
  333. pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
  334. spin_lock(&rdev->rswitch->lock);
  335. if (rdev->rswitch->ops) {
  336. spin_unlock(&rdev->rswitch->lock);
  337. return -EINVAL;
  338. }
  339. rdev->rswitch->ops = &idtg2_switch_ops;
  340. if (rdev->do_enum) {
  341. /* Ensure that default routing is disabled on startup */
  342. rio_write_config_32(rdev,
  343. RIO_STD_RTE_DEFAULT_PORT, IDT_NO_ROUTE);
  344. }
  345. /* Create device-specific sysfs attributes */
  346. idtg2_sysfs(rdev, true);
  347. spin_unlock(&rdev->rswitch->lock);
  348. return 0;
  349. }
  350. static void idtg2_remove(struct rio_dev *rdev)
  351. {
  352. pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
  353. spin_lock(&rdev->rswitch->lock);
  354. if (rdev->rswitch->ops != &idtg2_switch_ops) {
  355. spin_unlock(&rdev->rswitch->lock);
  356. return;
  357. }
  358. rdev->rswitch->ops = NULL;
  359. /* Remove device-specific sysfs attributes */
  360. idtg2_sysfs(rdev, false);
  361. spin_unlock(&rdev->rswitch->lock);
  362. }
  363. static struct rio_device_id idtg2_id_table[] = {
  364. {RIO_DEVICE(RIO_DID_IDTCPS1848, RIO_VID_IDT)},
  365. {RIO_DEVICE(RIO_DID_IDTCPS1616, RIO_VID_IDT)},
  366. {RIO_DEVICE(RIO_DID_IDTVPS1616, RIO_VID_IDT)},
  367. {RIO_DEVICE(RIO_DID_IDTSPS1616, RIO_VID_IDT)},
  368. {RIO_DEVICE(RIO_DID_IDTCPS1432, RIO_VID_IDT)},
  369. { 0, } /* terminate list */
  370. };
  371. static struct rio_driver idtg2_driver = {
  372. .name = "idt_gen2",
  373. .id_table = idtg2_id_table,
  374. .probe = idtg2_probe,
  375. .remove = idtg2_remove,
  376. };
  377. static int __init idtg2_init(void)
  378. {
  379. return rio_register_driver(&idtg2_driver);
  380. }
  381. static void __exit idtg2_exit(void)
  382. {
  383. pr_debug("RIO: %s\n", __func__);
  384. rio_unregister_driver(&idtg2_driver);
  385. pr_debug("RIO: %s done\n", __func__);
  386. }
  387. device_initcall(idtg2_init);
  388. module_exit(idtg2_exit);
  389. MODULE_DESCRIPTION("IDT CPS Gen.2 Serial RapidIO switch family driver");
  390. MODULE_AUTHOR("Integrated Device Technology, Inc.");
  391. MODULE_LICENSE("GPL");