tsi57x.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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. struct rio_mport *mport = rdev->net->hport;
  136. u16 destid = rdev->rswitch->destid;
  137. u8 hopcount = rdev->rswitch->hopcount;
  138. u32 regval;
  139. int portnum;
  140. pr_debug("TSI578 %s [%d:%d]\n", __func__, destid, hopcount);
  141. for (portnum = 0;
  142. portnum < RIO_GET_TOTAL_PORTS(rdev->swpinfo); portnum++) {
  143. /* Make sure that Port-Writes are enabled (for all ports) */
  144. rio_mport_read_config_32(mport, destid, hopcount,
  145. TSI578_SP_MODE(portnum), &regval);
  146. rio_mport_write_config_32(mport, destid, hopcount,
  147. TSI578_SP_MODE(portnum),
  148. regval & ~TSI578_SP_MODE_PW_DIS);
  149. /* Clear all pending interrupts */
  150. rio_mport_read_config_32(mport, destid, hopcount,
  151. rdev->phys_efptr +
  152. RIO_PORT_N_ERR_STS_CSR(portnum),
  153. &regval);
  154. rio_mport_write_config_32(mport, destid, hopcount,
  155. rdev->phys_efptr +
  156. RIO_PORT_N_ERR_STS_CSR(portnum),
  157. regval & 0x07120214);
  158. rio_mport_read_config_32(mport, destid, hopcount,
  159. TSI578_SP_INT_STATUS(portnum), &regval);
  160. rio_mport_write_config_32(mport, destid, hopcount,
  161. TSI578_SP_INT_STATUS(portnum),
  162. regval & 0x000700bd);
  163. /* Enable all interrupts to allow ports to send a port-write */
  164. rio_mport_read_config_32(mport, destid, hopcount,
  165. TSI578_SP_CTL_INDEP(portnum), &regval);
  166. rio_mport_write_config_32(mport, destid, hopcount,
  167. TSI578_SP_CTL_INDEP(portnum),
  168. regval | 0x000b0000);
  169. /* Skip next (odd) port if the current port is in x4 mode */
  170. rio_mport_read_config_32(mport, destid, hopcount,
  171. rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum),
  172. &regval);
  173. if ((regval & RIO_PORT_N_CTL_PWIDTH) == RIO_PORT_N_CTL_PWIDTH_4)
  174. portnum++;
  175. }
  176. /* set TVAL = ~50us */
  177. rio_mport_write_config_32(mport, destid, hopcount,
  178. rdev->phys_efptr + RIO_PORT_LINKTO_CTL_CSR, 0x9a << 8);
  179. return 0;
  180. }
  181. static int
  182. tsi57x_em_handler(struct rio_dev *rdev, u8 portnum)
  183. {
  184. struct rio_mport *mport = rdev->net->hport;
  185. u16 destid = rdev->rswitch->destid;
  186. u8 hopcount = rdev->rswitch->hopcount;
  187. u32 intstat, err_status;
  188. int sendcount, checkcount;
  189. u8 route_port;
  190. u32 regval;
  191. rio_mport_read_config_32(mport, destid, hopcount,
  192. rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum),
  193. &err_status);
  194. if ((err_status & RIO_PORT_N_ERR_STS_PORT_OK) &&
  195. (err_status & (RIO_PORT_N_ERR_STS_PW_OUT_ES |
  196. RIO_PORT_N_ERR_STS_PW_INP_ES))) {
  197. /* Remove any queued packets by locking/unlocking port */
  198. rio_mport_read_config_32(mport, destid, hopcount,
  199. rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum),
  200. &regval);
  201. if (!(regval & RIO_PORT_N_CTL_LOCKOUT)) {
  202. rio_mport_write_config_32(mport, destid, hopcount,
  203. rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum),
  204. regval | RIO_PORT_N_CTL_LOCKOUT);
  205. udelay(50);
  206. rio_mport_write_config_32(mport, destid, hopcount,
  207. rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum),
  208. regval);
  209. }
  210. /* Read from link maintenance response register to clear
  211. * valid bit
  212. */
  213. rio_mport_read_config_32(mport, destid, hopcount,
  214. rdev->phys_efptr + RIO_PORT_N_MNT_RSP_CSR(portnum),
  215. &regval);
  216. /* Send a Packet-Not-Accepted/Link-Request-Input-Status control
  217. * symbol to recover from IES/OES
  218. */
  219. sendcount = 3;
  220. while (sendcount) {
  221. rio_mport_write_config_32(mport, destid, hopcount,
  222. TSI578_SP_CS_TX(portnum), 0x40fc8000);
  223. checkcount = 3;
  224. while (checkcount--) {
  225. udelay(50);
  226. rio_mport_read_config_32(
  227. mport, destid, hopcount,
  228. rdev->phys_efptr +
  229. RIO_PORT_N_MNT_RSP_CSR(portnum),
  230. &regval);
  231. if (regval & RIO_PORT_N_MNT_RSP_RVAL)
  232. goto exit_es;
  233. }
  234. sendcount--;
  235. }
  236. }
  237. exit_es:
  238. /* Clear implementation specific error status bits */
  239. rio_mport_read_config_32(mport, destid, hopcount,
  240. TSI578_SP_INT_STATUS(portnum), &intstat);
  241. pr_debug("TSI578[%x:%x] SP%d_INT_STATUS=0x%08x\n",
  242. destid, hopcount, portnum, intstat);
  243. if (intstat & 0x10000) {
  244. rio_mport_read_config_32(mport, destid, hopcount,
  245. TSI578_SP_LUT_PEINF(portnum), &regval);
  246. regval = (mport->sys_size) ? (regval >> 16) : (regval >> 24);
  247. route_port = rdev->rswitch->route_table[regval];
  248. pr_debug("RIO: TSI578[%s] P%d LUT Parity Error (destID=%d)\n",
  249. rio_name(rdev), portnum, regval);
  250. tsi57x_route_add_entry(mport, destid, hopcount,
  251. RIO_GLOBAL_TABLE, regval, route_port);
  252. }
  253. rio_mport_write_config_32(mport, destid, hopcount,
  254. TSI578_SP_INT_STATUS(portnum),
  255. intstat & 0x000700bd);
  256. return 0;
  257. }
  258. static int tsi57x_switch_init(struct rio_dev *rdev, int do_enum)
  259. {
  260. pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
  261. rdev->rswitch->add_entry = tsi57x_route_add_entry;
  262. rdev->rswitch->get_entry = tsi57x_route_get_entry;
  263. rdev->rswitch->clr_table = tsi57x_route_clr_table;
  264. rdev->rswitch->set_domain = tsi57x_set_domain;
  265. rdev->rswitch->get_domain = tsi57x_get_domain;
  266. rdev->rswitch->em_init = tsi57x_em_init;
  267. rdev->rswitch->em_handle = tsi57x_em_handler;
  268. return 0;
  269. }
  270. DECLARE_RIO_SWITCH_INIT(RIO_VID_TUNDRA, RIO_DID_TSI572, tsi57x_switch_init);
  271. DECLARE_RIO_SWITCH_INIT(RIO_VID_TUNDRA, RIO_DID_TSI574, tsi57x_switch_init);
  272. DECLARE_RIO_SWITCH_INIT(RIO_VID_TUNDRA, RIO_DID_TSI577, tsi57x_switch_init);
  273. DECLARE_RIO_SWITCH_INIT(RIO_VID_TUNDRA, RIO_DID_TSI578, tsi57x_switch_init);