idtcps.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 "../rio.h"
  16. #define CPS_DEFAULT_ROUTE 0xde
  17. #define CPS_NO_ROUTE 0xdf
  18. #define IDTCPS_RIO_DOMAIN 0xf20020
  19. static int
  20. idtcps_route_add_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
  21. u16 table, u16 route_destid, u8 route_port)
  22. {
  23. u32 result;
  24. if (route_port == RIO_INVALID_ROUTE)
  25. route_port = CPS_DEFAULT_ROUTE;
  26. if (table == RIO_GLOBAL_TABLE) {
  27. rio_mport_write_config_32(mport, destid, hopcount,
  28. RIO_STD_RTE_CONF_DESTID_SEL_CSR, route_destid);
  29. rio_mport_read_config_32(mport, destid, hopcount,
  30. RIO_STD_RTE_CONF_PORT_SEL_CSR, &result);
  31. result = (0xffffff00 & result) | (u32)route_port;
  32. rio_mport_write_config_32(mport, destid, hopcount,
  33. RIO_STD_RTE_CONF_PORT_SEL_CSR, result);
  34. }
  35. return 0;
  36. }
  37. static int
  38. idtcps_route_get_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
  39. u16 table, u16 route_destid, u8 *route_port)
  40. {
  41. u32 result;
  42. if (table == RIO_GLOBAL_TABLE) {
  43. rio_mport_write_config_32(mport, destid, hopcount,
  44. RIO_STD_RTE_CONF_DESTID_SEL_CSR, route_destid);
  45. rio_mport_read_config_32(mport, destid, hopcount,
  46. RIO_STD_RTE_CONF_PORT_SEL_CSR, &result);
  47. if (CPS_DEFAULT_ROUTE == (u8)result ||
  48. CPS_NO_ROUTE == (u8)result)
  49. *route_port = RIO_INVALID_ROUTE;
  50. else
  51. *route_port = (u8)result;
  52. }
  53. return 0;
  54. }
  55. static int
  56. idtcps_route_clr_table(struct rio_mport *mport, u16 destid, u8 hopcount,
  57. u16 table)
  58. {
  59. u32 i;
  60. if (table == RIO_GLOBAL_TABLE) {
  61. for (i = 0x80000000; i <= 0x800000ff;) {
  62. rio_mport_write_config_32(mport, destid, hopcount,
  63. RIO_STD_RTE_CONF_DESTID_SEL_CSR, i);
  64. rio_mport_write_config_32(mport, destid, hopcount,
  65. RIO_STD_RTE_CONF_PORT_SEL_CSR,
  66. (CPS_DEFAULT_ROUTE << 24) |
  67. (CPS_DEFAULT_ROUTE << 16) |
  68. (CPS_DEFAULT_ROUTE << 8) | CPS_DEFAULT_ROUTE);
  69. i += 4;
  70. }
  71. }
  72. return 0;
  73. }
  74. static int
  75. idtcps_set_domain(struct rio_mport *mport, u16 destid, u8 hopcount,
  76. u8 sw_domain)
  77. {
  78. /*
  79. * Switch domain configuration operates only at global level
  80. */
  81. rio_mport_write_config_32(mport, destid, hopcount,
  82. IDTCPS_RIO_DOMAIN, (u32)sw_domain);
  83. return 0;
  84. }
  85. static int
  86. idtcps_get_domain(struct rio_mport *mport, u16 destid, u8 hopcount,
  87. u8 *sw_domain)
  88. {
  89. u32 regval;
  90. /*
  91. * Switch domain configuration operates only at global level
  92. */
  93. rio_mport_read_config_32(mport, destid, hopcount,
  94. IDTCPS_RIO_DOMAIN, &regval);
  95. *sw_domain = (u8)(regval & 0xff);
  96. return 0;
  97. }
  98. static int idtcps_switch_init(struct rio_dev *rdev, int do_enum)
  99. {
  100. pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
  101. rdev->rswitch->add_entry = idtcps_route_add_entry;
  102. rdev->rswitch->get_entry = idtcps_route_get_entry;
  103. rdev->rswitch->clr_table = idtcps_route_clr_table;
  104. rdev->rswitch->set_domain = idtcps_set_domain;
  105. rdev->rswitch->get_domain = idtcps_get_domain;
  106. rdev->rswitch->em_init = NULL;
  107. rdev->rswitch->em_handle = NULL;
  108. if (do_enum) {
  109. /* set TVAL = ~50us */
  110. rio_write_config_32(rdev,
  111. rdev->phys_efptr + RIO_PORT_LINKTO_CTL_CSR, 0x8e << 8);
  112. /* Ensure that default routing is disabled on startup */
  113. rio_write_config_32(rdev,
  114. RIO_STD_RTE_DEFAULT_PORT, CPS_NO_ROUTE);
  115. }
  116. return 0;
  117. }
  118. DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS6Q, idtcps_switch_init);
  119. DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS8, idtcps_switch_init);
  120. DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS10Q, idtcps_switch_init);
  121. DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS12, idtcps_switch_init);
  122. DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS16, idtcps_switch_init);
  123. DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDT70K200, idtcps_switch_init);