idtcps.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. * IDT CPS RapidIO switches support
  3. *
  4. * Copyright 2009-2010 Integrated Device Technology, Inc.
  5. * Alexandre Bounine <alexandre.bounine@idt.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. */
  12. #include <linux/rio.h>
  13. #include <linux/rio_drv.h>
  14. #include <linux/rio_ids.h>
  15. #include <linux/module.h>
  16. #include "../rio.h"
  17. #define CPS_DEFAULT_ROUTE 0xde
  18. #define CPS_NO_ROUTE 0xdf
  19. #define IDTCPS_RIO_DOMAIN 0xf20020
  20. static int
  21. idtcps_route_add_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
  22. u16 table, u16 route_destid, u8 route_port)
  23. {
  24. u32 result;
  25. if (route_port == RIO_INVALID_ROUTE)
  26. route_port = CPS_DEFAULT_ROUTE;
  27. if (table == RIO_GLOBAL_TABLE) {
  28. rio_mport_write_config_32(mport, destid, hopcount,
  29. RIO_STD_RTE_CONF_DESTID_SEL_CSR, route_destid);
  30. rio_mport_read_config_32(mport, destid, hopcount,
  31. RIO_STD_RTE_CONF_PORT_SEL_CSR, &result);
  32. result = (0xffffff00 & result) | (u32)route_port;
  33. rio_mport_write_config_32(mport, destid, hopcount,
  34. RIO_STD_RTE_CONF_PORT_SEL_CSR, result);
  35. }
  36. return 0;
  37. }
  38. static int
  39. idtcps_route_get_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
  40. u16 table, u16 route_destid, u8 *route_port)
  41. {
  42. u32 result;
  43. if (table == RIO_GLOBAL_TABLE) {
  44. rio_mport_write_config_32(mport, destid, hopcount,
  45. RIO_STD_RTE_CONF_DESTID_SEL_CSR, route_destid);
  46. rio_mport_read_config_32(mport, destid, hopcount,
  47. RIO_STD_RTE_CONF_PORT_SEL_CSR, &result);
  48. if (CPS_DEFAULT_ROUTE == (u8)result ||
  49. CPS_NO_ROUTE == (u8)result)
  50. *route_port = RIO_INVALID_ROUTE;
  51. else
  52. *route_port = (u8)result;
  53. }
  54. return 0;
  55. }
  56. static int
  57. idtcps_route_clr_table(struct rio_mport *mport, u16 destid, u8 hopcount,
  58. u16 table)
  59. {
  60. u32 i;
  61. if (table == RIO_GLOBAL_TABLE) {
  62. for (i = 0x80000000; i <= 0x800000ff;) {
  63. rio_mport_write_config_32(mport, destid, hopcount,
  64. RIO_STD_RTE_CONF_DESTID_SEL_CSR, i);
  65. rio_mport_write_config_32(mport, destid, hopcount,
  66. RIO_STD_RTE_CONF_PORT_SEL_CSR,
  67. (CPS_DEFAULT_ROUTE << 24) |
  68. (CPS_DEFAULT_ROUTE << 16) |
  69. (CPS_DEFAULT_ROUTE << 8) | CPS_DEFAULT_ROUTE);
  70. i += 4;
  71. }
  72. }
  73. return 0;
  74. }
  75. static int
  76. idtcps_set_domain(struct rio_mport *mport, u16 destid, u8 hopcount,
  77. u8 sw_domain)
  78. {
  79. /*
  80. * Switch domain configuration operates only at global level
  81. */
  82. rio_mport_write_config_32(mport, destid, hopcount,
  83. IDTCPS_RIO_DOMAIN, (u32)sw_domain);
  84. return 0;
  85. }
  86. static int
  87. idtcps_get_domain(struct rio_mport *mport, u16 destid, u8 hopcount,
  88. u8 *sw_domain)
  89. {
  90. u32 regval;
  91. /*
  92. * Switch domain configuration operates only at global level
  93. */
  94. rio_mport_read_config_32(mport, destid, hopcount,
  95. IDTCPS_RIO_DOMAIN, &regval);
  96. *sw_domain = (u8)(regval & 0xff);
  97. return 0;
  98. }
  99. static struct rio_switch_ops idtcps_switch_ops = {
  100. .owner = THIS_MODULE,
  101. .add_entry = idtcps_route_add_entry,
  102. .get_entry = idtcps_route_get_entry,
  103. .clr_table = idtcps_route_clr_table,
  104. .set_domain = idtcps_set_domain,
  105. .get_domain = idtcps_get_domain,
  106. .em_init = NULL,
  107. .em_handle = NULL,
  108. };
  109. static int idtcps_probe(struct rio_dev *rdev, const struct rio_device_id *id)
  110. {
  111. pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
  112. spin_lock(&rdev->rswitch->lock);
  113. if (rdev->rswitch->ops) {
  114. spin_unlock(&rdev->rswitch->lock);
  115. return -EINVAL;
  116. }
  117. rdev->rswitch->ops = &idtcps_switch_ops;
  118. if (rdev->do_enum) {
  119. /* set TVAL = ~50us */
  120. rio_write_config_32(rdev,
  121. rdev->phys_efptr + RIO_PORT_LINKTO_CTL_CSR, 0x8e << 8);
  122. /* Ensure that default routing is disabled on startup */
  123. rio_write_config_32(rdev,
  124. RIO_STD_RTE_DEFAULT_PORT, CPS_NO_ROUTE);
  125. }
  126. spin_unlock(&rdev->rswitch->lock);
  127. return 0;
  128. }
  129. static void idtcps_remove(struct rio_dev *rdev)
  130. {
  131. pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
  132. spin_lock(&rdev->rswitch->lock);
  133. if (rdev->rswitch->ops != &idtcps_switch_ops) {
  134. spin_unlock(&rdev->rswitch->lock);
  135. return;
  136. }
  137. rdev->rswitch->ops = NULL;
  138. spin_unlock(&rdev->rswitch->lock);
  139. }
  140. static struct rio_device_id idtcps_id_table[] = {
  141. {RIO_DEVICE(RIO_DID_IDTCPS6Q, RIO_VID_IDT)},
  142. {RIO_DEVICE(RIO_DID_IDTCPS8, RIO_VID_IDT)},
  143. {RIO_DEVICE(RIO_DID_IDTCPS10Q, RIO_VID_IDT)},
  144. {RIO_DEVICE(RIO_DID_IDTCPS12, RIO_VID_IDT)},
  145. {RIO_DEVICE(RIO_DID_IDTCPS16, RIO_VID_IDT)},
  146. {RIO_DEVICE(RIO_DID_IDT70K200, RIO_VID_IDT)},
  147. { 0, } /* terminate list */
  148. };
  149. static struct rio_driver idtcps_driver = {
  150. .name = "idtcps",
  151. .id_table = idtcps_id_table,
  152. .probe = idtcps_probe,
  153. .remove = idtcps_remove,
  154. };
  155. static int __init idtcps_init(void)
  156. {
  157. return rio_register_driver(&idtcps_driver);
  158. }
  159. static void __exit idtcps_exit(void)
  160. {
  161. rio_unregister_driver(&idtcps_driver);
  162. }
  163. device_initcall(idtcps_init);
  164. module_exit(idtcps_exit);
  165. MODULE_DESCRIPTION("IDT CPS Gen.1 Serial RapidIO switch family driver");
  166. MODULE_AUTHOR("Integrated Device Technology, Inc.");
  167. MODULE_LICENSE("GPL");