tsi57x.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. /*
  2. * RapidIO Tsi57x switch family support
  3. *
  4. * Copyright 2009-2010 Integrated Device Technology, Inc.
  5. * Alexandre Bounine <alexandre.bounine@idt.com>
  6. * - Added EM support
  7. * - Modified switch operations initialization.
  8. *
  9. * Copyright 2005 MontaVista Software, Inc.
  10. * Matt Porter <mporter@kernel.crashing.org>
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the
  14. * Free Software Foundation; either version 2 of the License, or (at your
  15. * option) any later version.
  16. */
  17. #include <linux/rio.h>
  18. #include <linux/rio_drv.h>
  19. #include <linux/rio_ids.h>
  20. #include <linux/delay.h>
  21. #include <linux/module.h>
  22. #include "../rio.h"
  23. /* Global (broadcast) route registers */
  24. #define SPBC_ROUTE_CFG_DESTID 0x10070
  25. #define SPBC_ROUTE_CFG_PORT 0x10074
  26. /* Per port route registers */
  27. #define SPP_ROUTE_CFG_DESTID(n) (0x11070 + 0x100*n)
  28. #define SPP_ROUTE_CFG_PORT(n) (0x11074 + 0x100*n)
  29. #define TSI578_SP_MODE(n) (0x11004 + n*0x100)
  30. #define TSI578_SP_MODE_GLBL 0x10004
  31. #define TSI578_SP_MODE_PW_DIS 0x08000000
  32. #define TSI578_SP_MODE_LUT_512 0x01000000
  33. #define TSI578_SP_CTL_INDEP(n) (0x13004 + n*0x100)
  34. #define TSI578_SP_LUT_PEINF(n) (0x13010 + n*0x100)
  35. #define TSI578_SP_CS_TX(n) (0x13014 + n*0x100)
  36. #define TSI578_SP_INT_STATUS(n) (0x13018 + n*0x100)
  37. #define TSI578_GLBL_ROUTE_BASE 0x10078
  38. static int
  39. tsi57x_route_add_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
  40. u16 table, u16 route_destid, u8 route_port)
  41. {
  42. if (table == RIO_GLOBAL_TABLE) {
  43. rio_mport_write_config_32(mport, destid, hopcount,
  44. SPBC_ROUTE_CFG_DESTID, route_destid);
  45. rio_mport_write_config_32(mport, destid, hopcount,
  46. SPBC_ROUTE_CFG_PORT, route_port);
  47. } else {
  48. rio_mport_write_config_32(mport, destid, hopcount,
  49. SPP_ROUTE_CFG_DESTID(table), route_destid);
  50. rio_mport_write_config_32(mport, destid, hopcount,
  51. SPP_ROUTE_CFG_PORT(table), route_port);
  52. }
  53. udelay(10);
  54. return 0;
  55. }
  56. static int
  57. tsi57x_route_get_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
  58. u16 table, u16 route_destid, u8 *route_port)
  59. {
  60. int ret = 0;
  61. u32 result;
  62. if (table == RIO_GLOBAL_TABLE) {
  63. /* Use local RT of the ingress port to avoid possible
  64. race condition */
  65. rio_mport_read_config_32(mport, destid, hopcount,
  66. RIO_SWP_INFO_CAR, &result);
  67. table = (result & RIO_SWP_INFO_PORT_NUM_MASK);
  68. }
  69. rio_mport_write_config_32(mport, destid, hopcount,
  70. SPP_ROUTE_CFG_DESTID(table), route_destid);
  71. rio_mport_read_config_32(mport, destid, hopcount,
  72. SPP_ROUTE_CFG_PORT(table), &result);
  73. *route_port = (u8)result;
  74. if (*route_port > 15)
  75. ret = -1;
  76. return ret;
  77. }
  78. static int
  79. tsi57x_route_clr_table(struct rio_mport *mport, u16 destid, u8 hopcount,
  80. u16 table)
  81. {
  82. u32 route_idx;
  83. u32 lut_size;
  84. lut_size = (mport->sys_size) ? 0x1ff : 0xff;
  85. if (table == RIO_GLOBAL_TABLE) {
  86. rio_mport_write_config_32(mport, destid, hopcount,
  87. SPBC_ROUTE_CFG_DESTID, 0x80000000);
  88. for (route_idx = 0; route_idx <= lut_size; route_idx++)
  89. rio_mport_write_config_32(mport, destid, hopcount,
  90. SPBC_ROUTE_CFG_PORT,
  91. RIO_INVALID_ROUTE);
  92. } else {
  93. rio_mport_write_config_32(mport, destid, hopcount,
  94. SPP_ROUTE_CFG_DESTID(table), 0x80000000);
  95. for (route_idx = 0; route_idx <= lut_size; route_idx++)
  96. rio_mport_write_config_32(mport, destid, hopcount,
  97. SPP_ROUTE_CFG_PORT(table) , RIO_INVALID_ROUTE);
  98. }
  99. return 0;
  100. }
  101. static int
  102. tsi57x_set_domain(struct rio_mport *mport, u16 destid, u8 hopcount,
  103. u8 sw_domain)
  104. {
  105. u32 regval;
  106. /*
  107. * Switch domain configuration operates only at global level
  108. */
  109. /* Turn off flat (LUT_512) mode */
  110. rio_mport_read_config_32(mport, destid, hopcount,
  111. TSI578_SP_MODE_GLBL, &regval);
  112. rio_mport_write_config_32(mport, destid, hopcount, TSI578_SP_MODE_GLBL,
  113. regval & ~TSI578_SP_MODE_LUT_512);
  114. /* Set switch domain base */
  115. rio_mport_write_config_32(mport, destid, hopcount,
  116. TSI578_GLBL_ROUTE_BASE,
  117. (u32)(sw_domain << 24));
  118. return 0;
  119. }
  120. static int
  121. tsi57x_get_domain(struct rio_mport *mport, u16 destid, u8 hopcount,
  122. u8 *sw_domain)
  123. {
  124. u32 regval;
  125. /*
  126. * Switch domain configuration operates only at global level
  127. */
  128. rio_mport_read_config_32(mport, destid, hopcount,
  129. TSI578_GLBL_ROUTE_BASE, &regval);
  130. *sw_domain = (u8)(regval >> 24);
  131. return 0;
  132. }
  133. static int
  134. tsi57x_em_init(struct rio_dev *rdev)
  135. {
  136. u32 regval;
  137. int portnum;
  138. pr_debug("TSI578 %s [%d:%d]\n", __func__, rdev->destid, rdev->hopcount);
  139. for (portnum = 0;
  140. portnum < RIO_GET_TOTAL_PORTS(rdev->swpinfo); portnum++) {
  141. /* Make sure that Port-Writes are enabled (for all ports) */
  142. rio_read_config_32(rdev,
  143. TSI578_SP_MODE(portnum), &regval);
  144. rio_write_config_32(rdev,
  145. TSI578_SP_MODE(portnum),
  146. regval & ~TSI578_SP_MODE_PW_DIS);
  147. /* Clear all pending interrupts */
  148. rio_read_config_32(rdev,
  149. rdev->phys_efptr +
  150. RIO_PORT_N_ERR_STS_CSR(portnum),
  151. &regval);
  152. rio_write_config_32(rdev,
  153. rdev->phys_efptr +
  154. RIO_PORT_N_ERR_STS_CSR(portnum),
  155. regval & 0x07120214);
  156. rio_read_config_32(rdev,
  157. TSI578_SP_INT_STATUS(portnum), &regval);
  158. rio_write_config_32(rdev,
  159. TSI578_SP_INT_STATUS(portnum),
  160. regval & 0x000700bd);
  161. /* Enable all interrupts to allow ports to send a port-write */
  162. rio_read_config_32(rdev,
  163. TSI578_SP_CTL_INDEP(portnum), &regval);
  164. rio_write_config_32(rdev,
  165. TSI578_SP_CTL_INDEP(portnum),
  166. regval | 0x000b0000);
  167. /* Skip next (odd) port if the current port is in x4 mode */
  168. rio_read_config_32(rdev,
  169. rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum),
  170. &regval);
  171. if ((regval & RIO_PORT_N_CTL_PWIDTH) == RIO_PORT_N_CTL_PWIDTH_4)
  172. portnum++;
  173. }
  174. /* set TVAL = ~50us */
  175. rio_write_config_32(rdev,
  176. rdev->phys_efptr + RIO_PORT_LINKTO_CTL_CSR, 0x9a << 8);
  177. return 0;
  178. }
  179. static int
  180. tsi57x_em_handler(struct rio_dev *rdev, u8 portnum)
  181. {
  182. struct rio_mport *mport = rdev->net->hport;
  183. u32 intstat, err_status;
  184. int sendcount, checkcount;
  185. u8 route_port;
  186. u32 regval;
  187. rio_read_config_32(rdev,
  188. rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum),
  189. &err_status);
  190. if ((err_status & RIO_PORT_N_ERR_STS_PORT_OK) &&
  191. (err_status & (RIO_PORT_N_ERR_STS_PW_OUT_ES |
  192. RIO_PORT_N_ERR_STS_PW_INP_ES))) {
  193. /* Remove any queued packets by locking/unlocking port */
  194. rio_read_config_32(rdev,
  195. rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum),
  196. &regval);
  197. if (!(regval & RIO_PORT_N_CTL_LOCKOUT)) {
  198. rio_write_config_32(rdev,
  199. rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum),
  200. regval | RIO_PORT_N_CTL_LOCKOUT);
  201. udelay(50);
  202. rio_write_config_32(rdev,
  203. rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum),
  204. regval);
  205. }
  206. /* Read from link maintenance response register to clear
  207. * valid bit
  208. */
  209. rio_read_config_32(rdev,
  210. rdev->phys_efptr + RIO_PORT_N_MNT_RSP_CSR(portnum),
  211. &regval);
  212. /* Send a Packet-Not-Accepted/Link-Request-Input-Status control
  213. * symbol to recover from IES/OES
  214. */
  215. sendcount = 3;
  216. while (sendcount) {
  217. rio_write_config_32(rdev,
  218. TSI578_SP_CS_TX(portnum), 0x40fc8000);
  219. checkcount = 3;
  220. while (checkcount--) {
  221. udelay(50);
  222. rio_read_config_32(rdev,
  223. rdev->phys_efptr +
  224. RIO_PORT_N_MNT_RSP_CSR(portnum),
  225. &regval);
  226. if (regval & RIO_PORT_N_MNT_RSP_RVAL)
  227. goto exit_es;
  228. }
  229. sendcount--;
  230. }
  231. }
  232. exit_es:
  233. /* Clear implementation specific error status bits */
  234. rio_read_config_32(rdev, TSI578_SP_INT_STATUS(portnum), &intstat);
  235. pr_debug("TSI578[%x:%x] SP%d_INT_STATUS=0x%08x\n",
  236. rdev->destid, rdev->hopcount, portnum, intstat);
  237. if (intstat & 0x10000) {
  238. rio_read_config_32(rdev,
  239. TSI578_SP_LUT_PEINF(portnum), &regval);
  240. regval = (mport->sys_size) ? (regval >> 16) : (regval >> 24);
  241. route_port = rdev->rswitch->route_table[regval];
  242. pr_debug("RIO: TSI578[%s] P%d LUT Parity Error (destID=%d)\n",
  243. rio_name(rdev), portnum, regval);
  244. tsi57x_route_add_entry(mport, rdev->destid, rdev->hopcount,
  245. RIO_GLOBAL_TABLE, regval, route_port);
  246. }
  247. rio_write_config_32(rdev, TSI578_SP_INT_STATUS(portnum),
  248. intstat & 0x000700bd);
  249. return 0;
  250. }
  251. static struct rio_switch_ops tsi57x_switch_ops = {
  252. .owner = THIS_MODULE,
  253. .add_entry = tsi57x_route_add_entry,
  254. .get_entry = tsi57x_route_get_entry,
  255. .clr_table = tsi57x_route_clr_table,
  256. .set_domain = tsi57x_set_domain,
  257. .get_domain = tsi57x_get_domain,
  258. .em_init = tsi57x_em_init,
  259. .em_handle = tsi57x_em_handler,
  260. };
  261. static int tsi57x_probe(struct rio_dev *rdev, const struct rio_device_id *id)
  262. {
  263. pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
  264. spin_lock(&rdev->rswitch->lock);
  265. if (rdev->rswitch->ops) {
  266. spin_unlock(&rdev->rswitch->lock);
  267. return -EINVAL;
  268. }
  269. rdev->rswitch->ops = &tsi57x_switch_ops;
  270. if (rdev->do_enum) {
  271. /* Ensure that default routing is disabled on startup */
  272. rio_write_config_32(rdev, RIO_STD_RTE_DEFAULT_PORT,
  273. RIO_INVALID_ROUTE);
  274. }
  275. spin_unlock(&rdev->rswitch->lock);
  276. return 0;
  277. }
  278. static void tsi57x_remove(struct rio_dev *rdev)
  279. {
  280. pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
  281. spin_lock(&rdev->rswitch->lock);
  282. if (rdev->rswitch->ops != &tsi57x_switch_ops) {
  283. spin_unlock(&rdev->rswitch->lock);
  284. return;
  285. }
  286. rdev->rswitch->ops = NULL;
  287. spin_unlock(&rdev->rswitch->lock);
  288. }
  289. static struct rio_device_id tsi57x_id_table[] = {
  290. {RIO_DEVICE(RIO_DID_TSI572, RIO_VID_TUNDRA)},
  291. {RIO_DEVICE(RIO_DID_TSI574, RIO_VID_TUNDRA)},
  292. {RIO_DEVICE(RIO_DID_TSI577, RIO_VID_TUNDRA)},
  293. {RIO_DEVICE(RIO_DID_TSI578, RIO_VID_TUNDRA)},
  294. { 0, } /* terminate list */
  295. };
  296. static struct rio_driver tsi57x_driver = {
  297. .name = "tsi57x",
  298. .id_table = tsi57x_id_table,
  299. .probe = tsi57x_probe,
  300. .remove = tsi57x_remove,
  301. };
  302. static int __init tsi57x_init(void)
  303. {
  304. return rio_register_driver(&tsi57x_driver);
  305. }
  306. static void __exit tsi57x_exit(void)
  307. {
  308. rio_unregister_driver(&tsi57x_driver);
  309. }
  310. device_initcall(tsi57x_init);
  311. module_exit(tsi57x_exit);
  312. MODULE_DESCRIPTION("IDT Tsi57x Serial RapidIO switch family driver");
  313. MODULE_AUTHOR("Integrated Device Technology, Inc.");
  314. MODULE_LICENSE("GPL");