tsi57x.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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. RIO_DEV_PORT_N_ERR_STS_CSR(rdev, portnum),
  150. &regval);
  151. rio_write_config_32(rdev,
  152. RIO_DEV_PORT_N_ERR_STS_CSR(rdev, portnum),
  153. regval & 0x07120214);
  154. rio_read_config_32(rdev,
  155. TSI578_SP_INT_STATUS(portnum), &regval);
  156. rio_write_config_32(rdev,
  157. TSI578_SP_INT_STATUS(portnum),
  158. regval & 0x000700bd);
  159. /* Enable all interrupts to allow ports to send a port-write */
  160. rio_read_config_32(rdev,
  161. TSI578_SP_CTL_INDEP(portnum), &regval);
  162. rio_write_config_32(rdev,
  163. TSI578_SP_CTL_INDEP(portnum),
  164. regval | 0x000b0000);
  165. /* Skip next (odd) port if the current port is in x4 mode */
  166. rio_read_config_32(rdev,
  167. RIO_DEV_PORT_N_CTL_CSR(rdev, portnum),
  168. &regval);
  169. if ((regval & RIO_PORT_N_CTL_PWIDTH) == RIO_PORT_N_CTL_PWIDTH_4)
  170. portnum++;
  171. }
  172. /* set TVAL = ~50us */
  173. rio_write_config_32(rdev,
  174. rdev->phys_efptr + RIO_PORT_LINKTO_CTL_CSR, 0x9a << 8);
  175. return 0;
  176. }
  177. static int
  178. tsi57x_em_handler(struct rio_dev *rdev, u8 portnum)
  179. {
  180. struct rio_mport *mport = rdev->net->hport;
  181. u32 intstat, err_status;
  182. int sendcount, checkcount;
  183. u8 route_port;
  184. u32 regval;
  185. rio_read_config_32(rdev,
  186. RIO_DEV_PORT_N_ERR_STS_CSR(rdev, portnum),
  187. &err_status);
  188. if ((err_status & RIO_PORT_N_ERR_STS_PORT_OK) &&
  189. (err_status & (RIO_PORT_N_ERR_STS_OUT_ES |
  190. RIO_PORT_N_ERR_STS_INP_ES))) {
  191. /* Remove any queued packets by locking/unlocking port */
  192. rio_read_config_32(rdev,
  193. RIO_DEV_PORT_N_CTL_CSR(rdev, portnum),
  194. &regval);
  195. if (!(regval & RIO_PORT_N_CTL_LOCKOUT)) {
  196. rio_write_config_32(rdev,
  197. RIO_DEV_PORT_N_CTL_CSR(rdev, portnum),
  198. regval | RIO_PORT_N_CTL_LOCKOUT);
  199. udelay(50);
  200. rio_write_config_32(rdev,
  201. RIO_DEV_PORT_N_CTL_CSR(rdev, portnum),
  202. regval);
  203. }
  204. /* Read from link maintenance response register to clear
  205. * valid bit
  206. */
  207. rio_read_config_32(rdev,
  208. RIO_DEV_PORT_N_MNT_RSP_CSR(rdev, portnum),
  209. &regval);
  210. /* Send a Packet-Not-Accepted/Link-Request-Input-Status control
  211. * symbol to recover from IES/OES
  212. */
  213. sendcount = 3;
  214. while (sendcount) {
  215. rio_write_config_32(rdev,
  216. TSI578_SP_CS_TX(portnum), 0x40fc8000);
  217. checkcount = 3;
  218. while (checkcount--) {
  219. udelay(50);
  220. rio_read_config_32(rdev,
  221. RIO_DEV_PORT_N_MNT_RSP_CSR(rdev,
  222. portnum),
  223. &regval);
  224. if (regval & RIO_PORT_N_MNT_RSP_RVAL)
  225. goto exit_es;
  226. }
  227. sendcount--;
  228. }
  229. }
  230. exit_es:
  231. /* Clear implementation specific error status bits */
  232. rio_read_config_32(rdev, TSI578_SP_INT_STATUS(portnum), &intstat);
  233. pr_debug("TSI578[%x:%x] SP%d_INT_STATUS=0x%08x\n",
  234. rdev->destid, rdev->hopcount, portnum, intstat);
  235. if (intstat & 0x10000) {
  236. rio_read_config_32(rdev,
  237. TSI578_SP_LUT_PEINF(portnum), &regval);
  238. regval = (mport->sys_size) ? (regval >> 16) : (regval >> 24);
  239. route_port = rdev->rswitch->route_table[regval];
  240. pr_debug("RIO: TSI578[%s] P%d LUT Parity Error (destID=%d)\n",
  241. rio_name(rdev), portnum, regval);
  242. tsi57x_route_add_entry(mport, rdev->destid, rdev->hopcount,
  243. RIO_GLOBAL_TABLE, regval, route_port);
  244. }
  245. rio_write_config_32(rdev, TSI578_SP_INT_STATUS(portnum),
  246. intstat & 0x000700bd);
  247. return 0;
  248. }
  249. static struct rio_switch_ops tsi57x_switch_ops = {
  250. .owner = THIS_MODULE,
  251. .add_entry = tsi57x_route_add_entry,
  252. .get_entry = tsi57x_route_get_entry,
  253. .clr_table = tsi57x_route_clr_table,
  254. .set_domain = tsi57x_set_domain,
  255. .get_domain = tsi57x_get_domain,
  256. .em_init = tsi57x_em_init,
  257. .em_handle = tsi57x_em_handler,
  258. };
  259. static int tsi57x_probe(struct rio_dev *rdev, const struct rio_device_id *id)
  260. {
  261. pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
  262. spin_lock(&rdev->rswitch->lock);
  263. if (rdev->rswitch->ops) {
  264. spin_unlock(&rdev->rswitch->lock);
  265. return -EINVAL;
  266. }
  267. rdev->rswitch->ops = &tsi57x_switch_ops;
  268. if (rdev->do_enum) {
  269. /* Ensure that default routing is disabled on startup */
  270. rio_write_config_32(rdev, RIO_STD_RTE_DEFAULT_PORT,
  271. RIO_INVALID_ROUTE);
  272. }
  273. spin_unlock(&rdev->rswitch->lock);
  274. return 0;
  275. }
  276. static void tsi57x_remove(struct rio_dev *rdev)
  277. {
  278. pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
  279. spin_lock(&rdev->rswitch->lock);
  280. if (rdev->rswitch->ops != &tsi57x_switch_ops) {
  281. spin_unlock(&rdev->rswitch->lock);
  282. return;
  283. }
  284. rdev->rswitch->ops = NULL;
  285. spin_unlock(&rdev->rswitch->lock);
  286. }
  287. static const struct rio_device_id tsi57x_id_table[] = {
  288. {RIO_DEVICE(RIO_DID_TSI572, RIO_VID_TUNDRA)},
  289. {RIO_DEVICE(RIO_DID_TSI574, RIO_VID_TUNDRA)},
  290. {RIO_DEVICE(RIO_DID_TSI577, RIO_VID_TUNDRA)},
  291. {RIO_DEVICE(RIO_DID_TSI578, RIO_VID_TUNDRA)},
  292. { 0, } /* terminate list */
  293. };
  294. static struct rio_driver tsi57x_driver = {
  295. .name = "tsi57x",
  296. .id_table = tsi57x_id_table,
  297. .probe = tsi57x_probe,
  298. .remove = tsi57x_remove,
  299. };
  300. static int __init tsi57x_init(void)
  301. {
  302. return rio_register_driver(&tsi57x_driver);
  303. }
  304. static void __exit tsi57x_exit(void)
  305. {
  306. rio_unregister_driver(&tsi57x_driver);
  307. }
  308. device_initcall(tsi57x_init);
  309. module_exit(tsi57x_exit);
  310. MODULE_DESCRIPTION("IDT Tsi57x Serial RapidIO switch family driver");
  311. MODULE_AUTHOR("Integrated Device Technology, Inc.");
  312. MODULE_LICENSE("GPL");