tsi57x.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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 "../rio.h"
  22. /* Global (broadcast) route registers */
  23. #define SPBC_ROUTE_CFG_DESTID 0x10070
  24. #define SPBC_ROUTE_CFG_PORT 0x10074
  25. /* Per port route registers */
  26. #define SPP_ROUTE_CFG_DESTID(n) (0x11070 + 0x100*n)
  27. #define SPP_ROUTE_CFG_PORT(n) (0x11074 + 0x100*n)
  28. #define TSI578_SP_MODE(n) (0x11004 + n*0x100)
  29. #define TSI578_SP_MODE_GLBL 0x10004
  30. #define TSI578_SP_MODE_PW_DIS 0x08000000
  31. #define TSI578_SP_MODE_LUT_512 0x01000000
  32. #define TSI578_SP_CTL_INDEP(n) (0x13004 + n*0x100)
  33. #define TSI578_SP_LUT_PEINF(n) (0x13010 + n*0x100)
  34. #define TSI578_SP_CS_TX(n) (0x13014 + n*0x100)
  35. #define TSI578_SP_INT_STATUS(n) (0x13018 + n*0x100)
  36. #define TSI578_GLBL_ROUTE_BASE 0x10078
  37. static int
  38. tsi57x_route_add_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
  39. u16 table, u16 route_destid, u8 route_port)
  40. {
  41. if (table == RIO_GLOBAL_TABLE) {
  42. rio_mport_write_config_32(mport, destid, hopcount,
  43. SPBC_ROUTE_CFG_DESTID, route_destid);
  44. rio_mport_write_config_32(mport, destid, hopcount,
  45. SPBC_ROUTE_CFG_PORT, route_port);
  46. } else {
  47. rio_mport_write_config_32(mport, destid, hopcount,
  48. SPP_ROUTE_CFG_DESTID(table), route_destid);
  49. rio_mport_write_config_32(mport, destid, hopcount,
  50. SPP_ROUTE_CFG_PORT(table), route_port);
  51. }
  52. udelay(10);
  53. return 0;
  54. }
  55. static int
  56. tsi57x_route_get_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
  57. u16 table, u16 route_destid, u8 *route_port)
  58. {
  59. int ret = 0;
  60. u32 result;
  61. if (table == RIO_GLOBAL_TABLE) {
  62. /* Use local RT of the ingress port to avoid possible
  63. race condition */
  64. rio_mport_read_config_32(mport, destid, hopcount,
  65. RIO_SWP_INFO_CAR, &result);
  66. table = (result & RIO_SWP_INFO_PORT_NUM_MASK);
  67. }
  68. rio_mport_write_config_32(mport, destid, hopcount,
  69. SPP_ROUTE_CFG_DESTID(table), route_destid);
  70. rio_mport_read_config_32(mport, destid, hopcount,
  71. SPP_ROUTE_CFG_PORT(table), &result);
  72. *route_port = (u8)result;
  73. if (*route_port > 15)
  74. ret = -1;
  75. return ret;
  76. }
  77. static int
  78. tsi57x_route_clr_table(struct rio_mport *mport, u16 destid, u8 hopcount,
  79. u16 table)
  80. {
  81. u32 route_idx;
  82. u32 lut_size;
  83. lut_size = (mport->sys_size) ? 0x1ff : 0xff;
  84. if (table == RIO_GLOBAL_TABLE) {
  85. rio_mport_write_config_32(mport, destid, hopcount,
  86. SPBC_ROUTE_CFG_DESTID, 0x80000000);
  87. for (route_idx = 0; route_idx <= lut_size; route_idx++)
  88. rio_mport_write_config_32(mport, destid, hopcount,
  89. SPBC_ROUTE_CFG_PORT,
  90. RIO_INVALID_ROUTE);
  91. } else {
  92. rio_mport_write_config_32(mport, destid, hopcount,
  93. SPP_ROUTE_CFG_DESTID(table), 0x80000000);
  94. for (route_idx = 0; route_idx <= lut_size; route_idx++)
  95. rio_mport_write_config_32(mport, destid, hopcount,
  96. SPP_ROUTE_CFG_PORT(table) , RIO_INVALID_ROUTE);
  97. }
  98. return 0;
  99. }
  100. static int
  101. tsi57x_set_domain(struct rio_mport *mport, u16 destid, u8 hopcount,
  102. u8 sw_domain)
  103. {
  104. u32 regval;
  105. /*
  106. * Switch domain configuration operates only at global level
  107. */
  108. /* Turn off flat (LUT_512) mode */
  109. rio_mport_read_config_32(mport, destid, hopcount,
  110. TSI578_SP_MODE_GLBL, &regval);
  111. rio_mport_write_config_32(mport, destid, hopcount, TSI578_SP_MODE_GLBL,
  112. regval & ~TSI578_SP_MODE_LUT_512);
  113. /* Set switch domain base */
  114. rio_mport_write_config_32(mport, destid, hopcount,
  115. TSI578_GLBL_ROUTE_BASE,
  116. (u32)(sw_domain << 24));
  117. return 0;
  118. }
  119. static int
  120. tsi57x_get_domain(struct rio_mport *mport, u16 destid, u8 hopcount,
  121. u8 *sw_domain)
  122. {
  123. u32 regval;
  124. /*
  125. * Switch domain configuration operates only at global level
  126. */
  127. rio_mport_read_config_32(mport, destid, hopcount,
  128. TSI578_GLBL_ROUTE_BASE, &regval);
  129. *sw_domain = (u8)(regval >> 24);
  130. return 0;
  131. }
  132. static int
  133. tsi57x_em_init(struct rio_dev *rdev)
  134. {
  135. u32 regval;
  136. int portnum;
  137. pr_debug("TSI578 %s [%d:%d]\n", __func__, rdev->destid, rdev->hopcount);
  138. for (portnum = 0;
  139. portnum < RIO_GET_TOTAL_PORTS(rdev->swpinfo); portnum++) {
  140. /* Make sure that Port-Writes are enabled (for all ports) */
  141. rio_read_config_32(rdev,
  142. TSI578_SP_MODE(portnum), &regval);
  143. rio_write_config_32(rdev,
  144. TSI578_SP_MODE(portnum),
  145. regval & ~TSI578_SP_MODE_PW_DIS);
  146. /* Clear all pending interrupts */
  147. rio_read_config_32(rdev,
  148. rdev->phys_efptr +
  149. RIO_PORT_N_ERR_STS_CSR(portnum),
  150. &regval);
  151. rio_write_config_32(rdev,
  152. rdev->phys_efptr +
  153. RIO_PORT_N_ERR_STS_CSR(portnum),
  154. regval & 0x07120214);
  155. rio_read_config_32(rdev,
  156. TSI578_SP_INT_STATUS(portnum), &regval);
  157. rio_write_config_32(rdev,
  158. TSI578_SP_INT_STATUS(portnum),
  159. regval & 0x000700bd);
  160. /* Enable all interrupts to allow ports to send a port-write */
  161. rio_read_config_32(rdev,
  162. TSI578_SP_CTL_INDEP(portnum), &regval);
  163. rio_write_config_32(rdev,
  164. TSI578_SP_CTL_INDEP(portnum),
  165. regval | 0x000b0000);
  166. /* Skip next (odd) port if the current port is in x4 mode */
  167. rio_read_config_32(rdev,
  168. rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum),
  169. &regval);
  170. if ((regval & RIO_PORT_N_CTL_PWIDTH) == RIO_PORT_N_CTL_PWIDTH_4)
  171. portnum++;
  172. }
  173. /* set TVAL = ~50us */
  174. rio_write_config_32(rdev,
  175. rdev->phys_efptr + RIO_PORT_LINKTO_CTL_CSR, 0x9a << 8);
  176. return 0;
  177. }
  178. static int
  179. tsi57x_em_handler(struct rio_dev *rdev, u8 portnum)
  180. {
  181. struct rio_mport *mport = rdev->net->hport;
  182. u32 intstat, err_status;
  183. int sendcount, checkcount;
  184. u8 route_port;
  185. u32 regval;
  186. rio_read_config_32(rdev,
  187. rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum),
  188. &err_status);
  189. if ((err_status & RIO_PORT_N_ERR_STS_PORT_OK) &&
  190. (err_status & (RIO_PORT_N_ERR_STS_PW_OUT_ES |
  191. RIO_PORT_N_ERR_STS_PW_INP_ES))) {
  192. /* Remove any queued packets by locking/unlocking port */
  193. rio_read_config_32(rdev,
  194. rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum),
  195. &regval);
  196. if (!(regval & RIO_PORT_N_CTL_LOCKOUT)) {
  197. rio_write_config_32(rdev,
  198. rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum),
  199. regval | RIO_PORT_N_CTL_LOCKOUT);
  200. udelay(50);
  201. rio_write_config_32(rdev,
  202. rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum),
  203. regval);
  204. }
  205. /* Read from link maintenance response register to clear
  206. * valid bit
  207. */
  208. rio_read_config_32(rdev,
  209. rdev->phys_efptr + RIO_PORT_N_MNT_RSP_CSR(portnum),
  210. &regval);
  211. /* Send a Packet-Not-Accepted/Link-Request-Input-Status control
  212. * symbol to recover from IES/OES
  213. */
  214. sendcount = 3;
  215. while (sendcount) {
  216. rio_write_config_32(rdev,
  217. TSI578_SP_CS_TX(portnum), 0x40fc8000);
  218. checkcount = 3;
  219. while (checkcount--) {
  220. udelay(50);
  221. rio_read_config_32(rdev,
  222. rdev->phys_efptr +
  223. RIO_PORT_N_MNT_RSP_CSR(portnum),
  224. &regval);
  225. if (regval & RIO_PORT_N_MNT_RSP_RVAL)
  226. goto exit_es;
  227. }
  228. sendcount--;
  229. }
  230. }
  231. exit_es:
  232. /* Clear implementation specific error status bits */
  233. rio_read_config_32(rdev, TSI578_SP_INT_STATUS(portnum), &intstat);
  234. pr_debug("TSI578[%x:%x] SP%d_INT_STATUS=0x%08x\n",
  235. rdev->destid, rdev->hopcount, portnum, intstat);
  236. if (intstat & 0x10000) {
  237. rio_read_config_32(rdev,
  238. TSI578_SP_LUT_PEINF(portnum), &regval);
  239. regval = (mport->sys_size) ? (regval >> 16) : (regval >> 24);
  240. route_port = rdev->rswitch->route_table[regval];
  241. pr_debug("RIO: TSI578[%s] P%d LUT Parity Error (destID=%d)\n",
  242. rio_name(rdev), portnum, regval);
  243. tsi57x_route_add_entry(mport, rdev->destid, rdev->hopcount,
  244. RIO_GLOBAL_TABLE, regval, route_port);
  245. }
  246. rio_write_config_32(rdev, TSI578_SP_INT_STATUS(portnum),
  247. intstat & 0x000700bd);
  248. return 0;
  249. }
  250. static int tsi57x_switch_init(struct rio_dev *rdev, int do_enum)
  251. {
  252. pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
  253. rdev->rswitch->add_entry = tsi57x_route_add_entry;
  254. rdev->rswitch->get_entry = tsi57x_route_get_entry;
  255. rdev->rswitch->clr_table = tsi57x_route_clr_table;
  256. rdev->rswitch->set_domain = tsi57x_set_domain;
  257. rdev->rswitch->get_domain = tsi57x_get_domain;
  258. rdev->rswitch->em_init = tsi57x_em_init;
  259. rdev->rswitch->em_handle = tsi57x_em_handler;
  260. if (do_enum) {
  261. /* Ensure that default routing is disabled on startup */
  262. rio_write_config_32(rdev, RIO_STD_RTE_DEFAULT_PORT,
  263. RIO_INVALID_ROUTE);
  264. }
  265. return 0;
  266. }
  267. DECLARE_RIO_SWITCH_INIT(RIO_VID_TUNDRA, RIO_DID_TSI572, tsi57x_switch_init);
  268. DECLARE_RIO_SWITCH_INIT(RIO_VID_TUNDRA, RIO_DID_TSI574, tsi57x_switch_init);
  269. DECLARE_RIO_SWITCH_INIT(RIO_VID_TUNDRA, RIO_DID_TSI577, tsi57x_switch_init);
  270. DECLARE_RIO_SWITCH_INIT(RIO_VID_TUNDRA, RIO_DID_TSI578, tsi57x_switch_init);