idt_gen2.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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. rio_mport_write_config_32(mport, destid, hopcount,
  76. LOCAL_RTE_CONF_DESTID_SEL, table);
  77. /*
  78. * Program destination port for the specified destID
  79. */
  80. rio_mport_write_config_32(mport, destid, hopcount,
  81. RIO_STD_RTE_CONF_DESTID_SEL_CSR,
  82. (u32)route_destid);
  83. rio_mport_write_config_32(mport, destid, hopcount,
  84. RIO_STD_RTE_CONF_PORT_SEL_CSR,
  85. (u32)route_port);
  86. udelay(10);
  87. return 0;
  88. }
  89. static int
  90. idtg2_route_get_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
  91. u16 table, u16 route_destid, u8 *route_port)
  92. {
  93. u32 result;
  94. /*
  95. * Select routing table to read
  96. */
  97. if (table == RIO_GLOBAL_TABLE)
  98. table = 0;
  99. else
  100. table++;
  101. rio_mport_write_config_32(mport, destid, hopcount,
  102. LOCAL_RTE_CONF_DESTID_SEL, table);
  103. rio_mport_write_config_32(mport, destid, hopcount,
  104. RIO_STD_RTE_CONF_DESTID_SEL_CSR,
  105. route_destid);
  106. rio_mport_read_config_32(mport, destid, hopcount,
  107. RIO_STD_RTE_CONF_PORT_SEL_CSR, &result);
  108. if (IDT_DEFAULT_ROUTE == (u8)result || IDT_NO_ROUTE == (u8)result)
  109. *route_port = RIO_INVALID_ROUTE;
  110. else
  111. *route_port = (u8)result;
  112. return 0;
  113. }
  114. static int
  115. idtg2_route_clr_table(struct rio_mport *mport, u16 destid, u8 hopcount,
  116. u16 table)
  117. {
  118. u32 i;
  119. /*
  120. * Select routing table to read
  121. */
  122. if (table == RIO_GLOBAL_TABLE)
  123. table = 0;
  124. else
  125. table++;
  126. rio_mport_write_config_32(mport, destid, hopcount,
  127. LOCAL_RTE_CONF_DESTID_SEL, table);
  128. for (i = RIO_STD_RTE_CONF_EXTCFGEN;
  129. i <= (RIO_STD_RTE_CONF_EXTCFGEN | 0xff);) {
  130. rio_mport_write_config_32(mport, destid, hopcount,
  131. RIO_STD_RTE_CONF_DESTID_SEL_CSR, i);
  132. rio_mport_write_config_32(mport, destid, hopcount,
  133. RIO_STD_RTE_CONF_PORT_SEL_CSR,
  134. (IDT_DEFAULT_ROUTE << 24) | (IDT_DEFAULT_ROUTE << 16) |
  135. (IDT_DEFAULT_ROUTE << 8) | IDT_DEFAULT_ROUTE);
  136. i += 4;
  137. }
  138. return 0;
  139. }
  140. static int
  141. idtg2_set_domain(struct rio_mport *mport, u16 destid, u8 hopcount,
  142. u8 sw_domain)
  143. {
  144. /*
  145. * Switch domain configuration operates only at global level
  146. */
  147. rio_mport_write_config_32(mport, destid, hopcount,
  148. IDT_RIO_DOMAIN, (u32)sw_domain);
  149. return 0;
  150. }
  151. static int
  152. idtg2_get_domain(struct rio_mport *mport, u16 destid, u8 hopcount,
  153. u8 *sw_domain)
  154. {
  155. u32 regval;
  156. /*
  157. * Switch domain configuration operates only at global level
  158. */
  159. rio_mport_read_config_32(mport, destid, hopcount,
  160. IDT_RIO_DOMAIN, &regval);
  161. *sw_domain = (u8)(regval & 0xff);
  162. return 0;
  163. }
  164. static int
  165. idtg2_em_init(struct rio_dev *rdev)
  166. {
  167. u32 regval;
  168. int i, tmp;
  169. /*
  170. * This routine performs device-specific initialization only.
  171. * All standard EM configuration should be performed at upper level.
  172. */
  173. pr_debug("RIO: %s [%d:%d]\n", __func__, rdev->destid, rdev->hopcount);
  174. /* Set Port-Write info CSR: PRIO=3 and CRF=1 */
  175. rio_write_config_32(rdev, IDT_PW_INFO_CSR, 0x0000e000);
  176. /*
  177. * Configure LT LAYER error reporting.
  178. */
  179. /* Enable standard (RIO.p8) error reporting */
  180. rio_write_config_32(rdev, IDT_LT_ERR_REPORT_EN,
  181. REM_LTL_ERR_ILLTRAN | REM_LTL_ERR_UNSOLR |
  182. REM_LTL_ERR_UNSUPTR);
  183. /* Use Port-Writes for LT layer error reporting.
  184. * Enable per-port reset
  185. */
  186. rio_read_config_32(rdev, IDT_DEV_CTRL_1, &regval);
  187. rio_write_config_32(rdev, IDT_DEV_CTRL_1,
  188. regval | IDT_DEV_CTRL_1_GENPW | IDT_DEV_CTRL_1_PRSTBEH);
  189. /*
  190. * Configure PORT error reporting.
  191. */
  192. /* Report all RIO.p8 errors supported by device */
  193. rio_write_config_32(rdev, IDT_PORT_ERR_REPORT_EN_BC, 0x807e8037);
  194. /* Configure reporting of implementation specific errors/events */
  195. rio_write_config_32(rdev, IDT_PORT_ISERR_REPORT_EN_BC,
  196. IDT_PORT_INIT_TX_ACQUIRED);
  197. /* Use Port-Writes for port error reporting and enable error logging */
  198. tmp = RIO_GET_TOTAL_PORTS(rdev->swpinfo);
  199. for (i = 0; i < tmp; i++) {
  200. rio_read_config_32(rdev, IDT_PORT_OPS(i), &regval);
  201. rio_write_config_32(rdev,
  202. IDT_PORT_OPS(i), regval | IDT_PORT_OPS_GENPW |
  203. IDT_PORT_OPS_PL_ELOG |
  204. IDT_PORT_OPS_LL_ELOG |
  205. IDT_PORT_OPS_LT_ELOG);
  206. }
  207. /* Overwrite error log if full */
  208. rio_write_config_32(rdev, IDT_ERR_CAP, IDT_ERR_CAP_LOG_OVERWR);
  209. /*
  210. * Configure LANE error reporting.
  211. */
  212. /* Disable line error reporting */
  213. rio_write_config_32(rdev, IDT_LANE_ERR_REPORT_EN_BC, 0);
  214. /* Use Port-Writes for lane error reporting (when enabled)
  215. * (do per-lane update because lanes may have different configuration)
  216. */
  217. tmp = (rdev->did == RIO_DID_IDTCPS1848) ? 48 : 16;
  218. for (i = 0; i < tmp; i++) {
  219. rio_read_config_32(rdev, IDT_LANE_CTRL(i), &regval);
  220. rio_write_config_32(rdev, IDT_LANE_CTRL(i),
  221. regval | IDT_LANE_CTRL_GENPW);
  222. }
  223. /*
  224. * Configure AUX error reporting.
  225. */
  226. /* Disable JTAG and I2C Error capture */
  227. rio_write_config_32(rdev, IDT_AUX_PORT_ERR_CAP_EN, 0);
  228. /* Disable JTAG and I2C Error reporting/logging */
  229. rio_write_config_32(rdev, IDT_AUX_ERR_REPORT_EN, 0);
  230. /* Disable Port-Write notification from JTAG */
  231. rio_write_config_32(rdev, IDT_JTAG_CTRL, 0);
  232. /* Disable Port-Write notification from I2C */
  233. rio_read_config_32(rdev, IDT_I2C_MCTRL, &regval);
  234. rio_write_config_32(rdev, IDT_I2C_MCTRL, regval & ~IDT_I2C_MCTRL_GENPW);
  235. /*
  236. * Configure CFG_BLK error reporting.
  237. */
  238. /* Disable Configuration Block error capture */
  239. rio_write_config_32(rdev, IDT_CFGBLK_ERR_CAPTURE_EN, 0);
  240. /* Disable Port-Writes for Configuration Block error reporting */
  241. rio_read_config_32(rdev, IDT_CFGBLK_ERR_REPORT, &regval);
  242. rio_write_config_32(rdev, IDT_CFGBLK_ERR_REPORT,
  243. regval & ~IDT_CFGBLK_ERR_REPORT_GENPW);
  244. /* set TVAL = ~50us */
  245. rio_write_config_32(rdev,
  246. rdev->phys_efptr + RIO_PORT_LINKTO_CTL_CSR, 0x8e << 8);
  247. return 0;
  248. }
  249. static int
  250. idtg2_em_handler(struct rio_dev *rdev, u8 portnum)
  251. {
  252. u32 regval, em_perrdet, em_ltlerrdet;
  253. rio_read_config_32(rdev,
  254. rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, &em_ltlerrdet);
  255. if (em_ltlerrdet) {
  256. /* Service Logical/Transport Layer Error(s) */
  257. if (em_ltlerrdet & REM_LTL_ERR_IMPSPEC) {
  258. /* Implementation specific error reported */
  259. rio_read_config_32(rdev,
  260. IDT_ISLTL_ADDRESS_CAP, &regval);
  261. pr_debug("RIO: %s Implementation Specific LTL errors" \
  262. " 0x%x @(0x%x)\n",
  263. rio_name(rdev), em_ltlerrdet, regval);
  264. /* Clear implementation specific address capture CSR */
  265. rio_write_config_32(rdev, IDT_ISLTL_ADDRESS_CAP, 0);
  266. }
  267. }
  268. rio_read_config_32(rdev,
  269. rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), &em_perrdet);
  270. if (em_perrdet) {
  271. /* Service Port-Level Error(s) */
  272. if (em_perrdet & REM_PED_IMPL_SPEC) {
  273. /* Implementation Specific port error reported */
  274. /* Get IS errors reported */
  275. rio_read_config_32(rdev,
  276. IDT_PORT_ISERR_DET(portnum), &regval);
  277. pr_debug("RIO: %s Implementation Specific Port" \
  278. " errors 0x%x\n", rio_name(rdev), regval);
  279. /* Clear all implementation specific events */
  280. rio_write_config_32(rdev,
  281. IDT_PORT_ISERR_DET(portnum), 0);
  282. }
  283. }
  284. return 0;
  285. }
  286. static ssize_t
  287. idtg2_show_errlog(struct device *dev, struct device_attribute *attr, char *buf)
  288. {
  289. struct rio_dev *rdev = to_rio_dev(dev);
  290. ssize_t len = 0;
  291. u32 regval;
  292. while (!rio_read_config_32(rdev, IDT_ERR_RD, &regval)) {
  293. if (!regval) /* 0 = end of log */
  294. break;
  295. len += snprintf(buf + len, PAGE_SIZE - len,
  296. "%08x\n", regval);
  297. if (len >= (PAGE_SIZE - 10))
  298. break;
  299. }
  300. return len;
  301. }
  302. static DEVICE_ATTR(errlog, S_IRUGO, idtg2_show_errlog, NULL);
  303. static int idtg2_sysfs(struct rio_dev *rdev, int create)
  304. {
  305. struct device *dev = &rdev->dev;
  306. int err = 0;
  307. if (create == RIO_SW_SYSFS_CREATE) {
  308. /* Initialize sysfs entries */
  309. err = device_create_file(dev, &dev_attr_errlog);
  310. if (err)
  311. dev_err(dev, "Unable create sysfs errlog file\n");
  312. } else
  313. device_remove_file(dev, &dev_attr_errlog);
  314. return err;
  315. }
  316. static int idtg2_switch_init(struct rio_dev *rdev, int do_enum)
  317. {
  318. pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
  319. rdev->rswitch->add_entry = idtg2_route_add_entry;
  320. rdev->rswitch->get_entry = idtg2_route_get_entry;
  321. rdev->rswitch->clr_table = idtg2_route_clr_table;
  322. rdev->rswitch->set_domain = idtg2_set_domain;
  323. rdev->rswitch->get_domain = idtg2_get_domain;
  324. rdev->rswitch->em_init = idtg2_em_init;
  325. rdev->rswitch->em_handle = idtg2_em_handler;
  326. rdev->rswitch->sw_sysfs = idtg2_sysfs;
  327. return 0;
  328. }
  329. DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS1848, idtg2_switch_init);
  330. DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS1616, idtg2_switch_init);
  331. DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTVPS1616, idtg2_switch_init);
  332. DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTSPS1616, idtg2_switch_init);