tsi568.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * RapidIO Tsi568 switch 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 TSI568_SP_MODE(n) (0x11004 + 0x100*n)
  29. #define TSI568_SP_MODE_PW_DIS 0x08000000
  30. static int
  31. tsi568_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),
  42. route_destid);
  43. rio_mport_write_config_32(mport, destid, hopcount,
  44. SPP_ROUTE_CFG_PORT(table), route_port);
  45. }
  46. udelay(10);
  47. return 0;
  48. }
  49. static int
  50. tsi568_route_get_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
  51. u16 table, u16 route_destid, u8 *route_port)
  52. {
  53. int ret = 0;
  54. u32 result;
  55. if (table == RIO_GLOBAL_TABLE) {
  56. rio_mport_write_config_32(mport, destid, hopcount,
  57. SPBC_ROUTE_CFG_DESTID, route_destid);
  58. rio_mport_read_config_32(mport, destid, hopcount,
  59. SPBC_ROUTE_CFG_PORT, &result);
  60. } else {
  61. rio_mport_write_config_32(mport, destid, hopcount,
  62. SPP_ROUTE_CFG_DESTID(table),
  63. route_destid);
  64. rio_mport_read_config_32(mport, destid, hopcount,
  65. SPP_ROUTE_CFG_PORT(table), &result);
  66. }
  67. *route_port = result;
  68. if (*route_port > 15)
  69. ret = -1;
  70. return ret;
  71. }
  72. static int
  73. tsi568_route_clr_table(struct rio_mport *mport, u16 destid, u8 hopcount,
  74. u16 table)
  75. {
  76. u32 route_idx;
  77. u32 lut_size;
  78. lut_size = (mport->sys_size) ? 0x1ff : 0xff;
  79. if (table == RIO_GLOBAL_TABLE) {
  80. rio_mport_write_config_32(mport, destid, hopcount,
  81. SPBC_ROUTE_CFG_DESTID, 0x80000000);
  82. for (route_idx = 0; route_idx <= lut_size; route_idx++)
  83. rio_mport_write_config_32(mport, destid, hopcount,
  84. SPBC_ROUTE_CFG_PORT,
  85. RIO_INVALID_ROUTE);
  86. } else {
  87. rio_mport_write_config_32(mport, destid, hopcount,
  88. SPP_ROUTE_CFG_DESTID(table),
  89. 0x80000000);
  90. for (route_idx = 0; route_idx <= lut_size; route_idx++)
  91. rio_mport_write_config_32(mport, destid, hopcount,
  92. SPP_ROUTE_CFG_PORT(table),
  93. RIO_INVALID_ROUTE);
  94. }
  95. return 0;
  96. }
  97. static int
  98. tsi568_em_init(struct rio_dev *rdev)
  99. {
  100. u32 regval;
  101. int portnum;
  102. pr_debug("TSI568 %s [%d:%d]\n", __func__, rdev->destid, rdev->hopcount);
  103. /* Make sure that Port-Writes are disabled (for all ports) */
  104. for (portnum = 0;
  105. portnum < RIO_GET_TOTAL_PORTS(rdev->swpinfo); portnum++) {
  106. rio_read_config_32(rdev, TSI568_SP_MODE(portnum), &regval);
  107. rio_write_config_32(rdev, TSI568_SP_MODE(portnum),
  108. regval | TSI568_SP_MODE_PW_DIS);
  109. }
  110. return 0;
  111. }
  112. static int tsi568_switch_init(struct rio_dev *rdev, int do_enum)
  113. {
  114. pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
  115. rdev->rswitch->add_entry = tsi568_route_add_entry;
  116. rdev->rswitch->get_entry = tsi568_route_get_entry;
  117. rdev->rswitch->clr_table = tsi568_route_clr_table;
  118. rdev->rswitch->set_domain = NULL;
  119. rdev->rswitch->get_domain = NULL;
  120. rdev->rswitch->em_init = tsi568_em_init;
  121. rdev->rswitch->em_handle = NULL;
  122. return 0;
  123. }
  124. DECLARE_RIO_SWITCH_INIT(RIO_VID_TUNDRA, RIO_DID_TSI568, tsi568_switch_init);