tsi57x.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*
  2. * RapidIO Tsi57x switch family support
  3. *
  4. * Copyright 2009 Integrated Device Technology, Inc.
  5. * Copyright 2005 MontaVista Software, Inc.
  6. * Matt Porter <mporter@kernel.crashing.org>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. */
  13. #include <linux/rio.h>
  14. #include <linux/rio_drv.h>
  15. #include <linux/rio_ids.h>
  16. #include <linux/delay.h>
  17. #include "../rio.h"
  18. /* Global (broadcast) route registers */
  19. #define SPBC_ROUTE_CFG_DESTID 0x10070
  20. #define SPBC_ROUTE_CFG_PORT 0x10074
  21. /* Per port route registers */
  22. #define SPP_ROUTE_CFG_DESTID(n) (0x11070 + 0x100*n)
  23. #define SPP_ROUTE_CFG_PORT(n) (0x11074 + 0x100*n)
  24. #define TSI578_SP_MODE(n) (0x11004 + n*0x100)
  25. #define TSI578_SP_MODE_PW_DIS 0x08000000
  26. #define TSI578_SP_CTL_INDEP(n) (0x13004 + n*0x100)
  27. #define TSI578_SP_LUT_PEINF(n) (0x13010 + n*0x100)
  28. #define TSI578_SP_CS_TX(n) (0x13014 + n*0x100)
  29. #define TSI578_SP_INT_STATUS(n) (0x13018 + n*0x100)
  30. static int
  31. tsi57x_route_add_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
  32. u16 table, u16 route_destid, u8 route_port)
  33. {
  34. if (table == RIO_GLOBAL_TABLE) {
  35. rio_mport_write_config_32(mport, destid, hopcount,
  36. SPBC_ROUTE_CFG_DESTID, route_destid);
  37. rio_mport_write_config_32(mport, destid, hopcount,
  38. SPBC_ROUTE_CFG_PORT, route_port);
  39. } else {
  40. rio_mport_write_config_32(mport, destid, hopcount,
  41. SPP_ROUTE_CFG_DESTID(table), route_destid);
  42. rio_mport_write_config_32(mport, destid, hopcount,
  43. SPP_ROUTE_CFG_PORT(table), route_port);
  44. }
  45. udelay(10);
  46. return 0;
  47. }
  48. static int
  49. tsi57x_route_get_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
  50. u16 table, u16 route_destid, u8 *route_port)
  51. {
  52. int ret = 0;
  53. u32 result;
  54. if (table == RIO_GLOBAL_TABLE) {
  55. /* Use local RT of the ingress port to avoid possible
  56. race condition */
  57. rio_mport_read_config_32(mport, destid, hopcount,
  58. RIO_SWP_INFO_CAR, &result);
  59. table = (result & RIO_SWP_INFO_PORT_NUM_MASK);
  60. }
  61. rio_mport_write_config_32(mport, destid, hopcount,
  62. SPP_ROUTE_CFG_DESTID(table), route_destid);
  63. rio_mport_read_config_32(mport, destid, hopcount,
  64. SPP_ROUTE_CFG_PORT(table), &result);
  65. *route_port = (u8)result;
  66. if (*route_port > 15)
  67. ret = -1;
  68. return ret;
  69. }
  70. static int
  71. tsi57x_route_clr_table(struct rio_mport *mport, u16 destid, u8 hopcount,
  72. u16 table)
  73. {
  74. u32 route_idx;
  75. u32 lut_size;
  76. lut_size = (mport->sys_size) ? 0x1ff : 0xff;
  77. if (table == RIO_GLOBAL_TABLE) {
  78. rio_mport_write_config_32(mport, destid, hopcount,
  79. SPBC_ROUTE_CFG_DESTID, 0x80000000);
  80. for (route_idx = 0; route_idx <= lut_size; route_idx++)
  81. rio_mport_write_config_32(mport, destid, hopcount,
  82. SPBC_ROUTE_CFG_PORT,
  83. RIO_INVALID_ROUTE);
  84. } else {
  85. rio_mport_write_config_32(mport, destid, hopcount,
  86. SPP_ROUTE_CFG_DESTID(table), 0x80000000);
  87. for (route_idx = 0; route_idx <= lut_size; route_idx++)
  88. rio_mport_write_config_32(mport, destid, hopcount,
  89. SPP_ROUTE_CFG_PORT(table) , RIO_INVALID_ROUTE);
  90. }
  91. return 0;
  92. }
  93. DECLARE_RIO_ROUTE_OPS(RIO_VID_TUNDRA, RIO_DID_TSI572, tsi57x_route_add_entry, tsi57x_route_get_entry, tsi57x_route_clr_table);
  94. DECLARE_RIO_ROUTE_OPS(RIO_VID_TUNDRA, RIO_DID_TSI574, tsi57x_route_add_entry, tsi57x_route_get_entry, tsi57x_route_clr_table);
  95. DECLARE_RIO_ROUTE_OPS(RIO_VID_TUNDRA, RIO_DID_TSI577, tsi57x_route_add_entry, tsi57x_route_get_entry, tsi57x_route_clr_table);
  96. DECLARE_RIO_ROUTE_OPS(RIO_VID_TUNDRA, RIO_DID_TSI578, tsi57x_route_add_entry, tsi57x_route_get_entry, tsi57x_route_clr_table);
  97. static int
  98. tsi57x_em_init(struct rio_dev *rdev)
  99. {
  100. struct rio_mport *mport = rdev->net->hport;
  101. u16 destid = rdev->rswitch->destid;
  102. u8 hopcount = rdev->rswitch->hopcount;
  103. u32 regval;
  104. int portnum;
  105. pr_debug("TSI578 %s [%d:%d]\n", __func__, destid, hopcount);
  106. for (portnum = 0; portnum < 16; portnum++) {
  107. /* Make sure that Port-Writes are enabled (for all ports) */
  108. rio_mport_read_config_32(mport, destid, hopcount,
  109. TSI578_SP_MODE(portnum), &regval);
  110. rio_mport_write_config_32(mport, destid, hopcount,
  111. TSI578_SP_MODE(portnum),
  112. regval & ~TSI578_SP_MODE_PW_DIS);
  113. /* Clear all pending interrupts */
  114. rio_mport_read_config_32(mport, destid, hopcount,
  115. rdev->phys_efptr +
  116. RIO_PORT_N_ERR_STS_CSR(portnum),
  117. &regval);
  118. rio_mport_write_config_32(mport, destid, hopcount,
  119. rdev->phys_efptr +
  120. RIO_PORT_N_ERR_STS_CSR(portnum),
  121. regval & 0x07120214);
  122. rio_mport_read_config_32(mport, destid, hopcount,
  123. TSI578_SP_INT_STATUS(portnum), &regval);
  124. rio_mport_write_config_32(mport, destid, hopcount,
  125. TSI578_SP_INT_STATUS(portnum),
  126. regval & 0x000700bd);
  127. /* Enable all interrupts to allow ports to send a port-write */
  128. rio_mport_read_config_32(mport, destid, hopcount,
  129. TSI578_SP_CTL_INDEP(portnum), &regval);
  130. rio_mport_write_config_32(mport, destid, hopcount,
  131. TSI578_SP_CTL_INDEP(portnum),
  132. regval | 0x000b0000);
  133. /* Skip next (odd) port if the current port is in x4 mode */
  134. rio_mport_read_config_32(mport, destid, hopcount,
  135. rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum),
  136. &regval);
  137. if ((regval & RIO_PORT_N_CTL_PWIDTH) == RIO_PORT_N_CTL_PWIDTH_4)
  138. portnum++;
  139. }
  140. return 0;
  141. }
  142. static int
  143. tsi57x_em_handler(struct rio_dev *rdev, u8 portnum)
  144. {
  145. struct rio_mport *mport = rdev->net->hport;
  146. u16 destid = rdev->rswitch->destid;
  147. u8 hopcount = rdev->rswitch->hopcount;
  148. u32 intstat, err_status;
  149. int sendcount, checkcount;
  150. u8 route_port;
  151. u32 regval;
  152. rio_mport_read_config_32(mport, destid, hopcount,
  153. rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum),
  154. &err_status);
  155. if ((err_status & RIO_PORT_N_ERR_STS_PORT_OK) &&
  156. (err_status & (RIO_PORT_N_ERR_STS_PW_OUT_ES |
  157. RIO_PORT_N_ERR_STS_PW_INP_ES))) {
  158. /* Remove any queued packets by locking/unlocking port */
  159. rio_mport_read_config_32(mport, destid, hopcount,
  160. rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum),
  161. &regval);
  162. if (!(regval & RIO_PORT_N_CTL_LOCKOUT)) {
  163. rio_mport_write_config_32(mport, destid, hopcount,
  164. rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum),
  165. regval | RIO_PORT_N_CTL_LOCKOUT);
  166. udelay(50);
  167. rio_mport_write_config_32(mport, destid, hopcount,
  168. rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum),
  169. regval);
  170. }
  171. /* Read from link maintenance response register to clear
  172. * valid bit
  173. */
  174. rio_mport_read_config_32(mport, destid, hopcount,
  175. rdev->phys_efptr + RIO_PORT_N_MNT_RSP_CSR(portnum),
  176. &regval);
  177. /* Send a Packet-Not-Accepted/Link-Request-Input-Status control
  178. * symbol to recover from IES/OES
  179. */
  180. sendcount = 3;
  181. while (sendcount) {
  182. rio_mport_write_config_32(mport, destid, hopcount,
  183. TSI578_SP_CS_TX(portnum), 0x40fc8000);
  184. checkcount = 3;
  185. while (checkcount--) {
  186. udelay(50);
  187. rio_mport_read_config_32(
  188. mport, destid, hopcount,
  189. rdev->phys_efptr +
  190. RIO_PORT_N_MNT_RSP_CSR(portnum),
  191. &regval);
  192. if (regval & RIO_PORT_N_MNT_RSP_RVAL)
  193. goto exit_es;
  194. }
  195. sendcount--;
  196. }
  197. }
  198. exit_es:
  199. /* Clear implementation specific error status bits */
  200. rio_mport_read_config_32(mport, destid, hopcount,
  201. TSI578_SP_INT_STATUS(portnum), &intstat);
  202. pr_debug("TSI578[%x:%x] SP%d_INT_STATUS=0x%08x\n",
  203. destid, hopcount, portnum, intstat);
  204. if (intstat & 0x10000) {
  205. rio_mport_read_config_32(mport, destid, hopcount,
  206. TSI578_SP_LUT_PEINF(portnum), &regval);
  207. regval = (mport->sys_size) ? (regval >> 16) : (regval >> 24);
  208. route_port = rdev->rswitch->route_table[regval];
  209. pr_debug("RIO: TSI578[%s] P%d LUT Parity Error (destID=%d)\n",
  210. rio_name(rdev), portnum, regval);
  211. tsi57x_route_add_entry(mport, destid, hopcount,
  212. RIO_GLOBAL_TABLE, regval, route_port);
  213. }
  214. rio_mport_write_config_32(mport, destid, hopcount,
  215. TSI578_SP_INT_STATUS(portnum),
  216. intstat & 0x000700bd);
  217. return 0;
  218. }
  219. DECLARE_RIO_EM_OPS(RIO_VID_TUNDRA, RIO_DID_TSI572, tsi57x_em_init, tsi57x_em_handler);
  220. DECLARE_RIO_EM_OPS(RIO_VID_TUNDRA, RIO_DID_TSI574, tsi57x_em_init, tsi57x_em_handler);
  221. DECLARE_RIO_EM_OPS(RIO_VID_TUNDRA, RIO_DID_TSI577, tsi57x_em_init, tsi57x_em_handler);
  222. DECLARE_RIO_EM_OPS(RIO_VID_TUNDRA, RIO_DID_TSI578, tsi57x_em_init, tsi57x_em_handler);