idt_gen2.c 11 KB

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