idt_gen2.c 11 KB

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