idt_gen2.c 12 KB

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