idtcps.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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_NO_ROUTE 0xdf
  17. static int
  18. idtcps_route_add_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
  19. u16 table, u16 route_destid, u8 route_port)
  20. {
  21. u32 result;
  22. if (table == RIO_GLOBAL_TABLE) {
  23. rio_mport_write_config_32(mport, destid, hopcount,
  24. RIO_STD_RTE_CONF_DESTID_SEL_CSR, route_destid);
  25. rio_mport_read_config_32(mport, destid, hopcount,
  26. RIO_STD_RTE_CONF_PORT_SEL_CSR, &result);
  27. result = (0xffffff00 & result) | (u32)route_port;
  28. rio_mport_write_config_32(mport, destid, hopcount,
  29. RIO_STD_RTE_CONF_PORT_SEL_CSR, result);
  30. }
  31. return 0;
  32. }
  33. static int
  34. idtcps_route_get_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
  35. u16 table, u16 route_destid, u8 *route_port)
  36. {
  37. u32 result;
  38. if (table == RIO_GLOBAL_TABLE) {
  39. rio_mport_write_config_32(mport, destid, hopcount,
  40. RIO_STD_RTE_CONF_DESTID_SEL_CSR, route_destid);
  41. rio_mport_read_config_32(mport, destid, hopcount,
  42. RIO_STD_RTE_CONF_PORT_SEL_CSR, &result);
  43. if (CPS_NO_ROUTE == (u8)result)
  44. result = RIO_INVALID_ROUTE;
  45. *route_port = (u8)result;
  46. }
  47. return 0;
  48. }
  49. static int
  50. idtcps_route_clr_table(struct rio_mport *mport, u16 destid, u8 hopcount,
  51. u16 table)
  52. {
  53. u32 i;
  54. if (table == RIO_GLOBAL_TABLE) {
  55. for (i = 0x80000000; i <= 0x800000ff;) {
  56. rio_mport_write_config_32(mport, destid, hopcount,
  57. RIO_STD_RTE_CONF_DESTID_SEL_CSR, i);
  58. rio_mport_write_config_32(mport, destid, hopcount,
  59. RIO_STD_RTE_CONF_PORT_SEL_CSR,
  60. (RIO_INVALID_ROUTE << 24) |
  61. (RIO_INVALID_ROUTE << 16) |
  62. (RIO_INVALID_ROUTE << 8) | RIO_INVALID_ROUTE);
  63. i += 4;
  64. }
  65. }
  66. return 0;
  67. }
  68. static int idtcps_switch_init(struct rio_dev *rdev, int do_enum)
  69. {
  70. pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
  71. rdev->rswitch->add_entry = idtcps_route_add_entry;
  72. rdev->rswitch->get_entry = idtcps_route_get_entry;
  73. rdev->rswitch->clr_table = idtcps_route_clr_table;
  74. rdev->rswitch->em_init = NULL;
  75. rdev->rswitch->em_handle = NULL;
  76. return 0;
  77. }
  78. DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS6Q, idtcps_switch_init);
  79. DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS8, idtcps_switch_init);
  80. DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS10Q, idtcps_switch_init);
  81. DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS12, idtcps_switch_init);
  82. DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS16, idtcps_switch_init);
  83. DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDT70K200, idtcps_switch_init);