mv88e6131.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * net/dsa/mv88e6131.c - Marvell 88e6095/6095f/6131 switch chip support
  3. * Copyright (c) 2008-2009 Marvell Semiconductor
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. */
  10. #include <linux/delay.h>
  11. #include <linux/jiffies.h>
  12. #include <linux/list.h>
  13. #include <linux/module.h>
  14. #include <linux/netdevice.h>
  15. #include <linux/phy.h>
  16. #include <net/dsa.h>
  17. #include "mv88e6xxx.h"
  18. static const struct mv88e6xxx_switch_id mv88e6131_table[] = {
  19. { PORT_SWITCH_ID_6085, "Marvell 88E6085" },
  20. { PORT_SWITCH_ID_6095, "Marvell 88E6095/88E6095F" },
  21. { PORT_SWITCH_ID_6131, "Marvell 88E6131" },
  22. { PORT_SWITCH_ID_6131_B2, "Marvell 88E6131 (B2)" },
  23. { PORT_SWITCH_ID_6185, "Marvell 88E6185" },
  24. };
  25. static char *mv88e6131_probe(struct device *host_dev, int sw_addr)
  26. {
  27. return mv88e6xxx_lookup_name(host_dev, sw_addr, mv88e6131_table,
  28. ARRAY_SIZE(mv88e6131_table));
  29. }
  30. static int mv88e6131_setup_global(struct dsa_switch *ds)
  31. {
  32. u32 upstream_port = dsa_upstream_port(ds);
  33. int ret;
  34. u32 reg;
  35. ret = mv88e6xxx_setup_global(ds);
  36. if (ret)
  37. return ret;
  38. /* Enable the PHY polling unit, don't discard packets with
  39. * excessive collisions, use a weighted fair queueing scheme
  40. * to arbitrate between packet queues, set the maximum frame
  41. * size to 1632, and mask all interrupt sources.
  42. */
  43. REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL,
  44. GLOBAL_CONTROL_PPU_ENABLE | GLOBAL_CONTROL_MAX_FRAME_1632);
  45. /* Set the VLAN ethertype to 0x8100. */
  46. REG_WRITE(REG_GLOBAL, GLOBAL_CORE_TAG_TYPE, 0x8100);
  47. /* Disable ARP mirroring, and configure the upstream port as
  48. * the port to which ingress and egress monitor frames are to
  49. * be sent.
  50. */
  51. reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT |
  52. upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT |
  53. GLOBAL_MONITOR_CONTROL_ARP_DISABLED;
  54. REG_WRITE(REG_GLOBAL, GLOBAL_MONITOR_CONTROL, reg);
  55. /* Disable cascade port functionality unless this device
  56. * is used in a cascade configuration, and set the switch's
  57. * DSA device number.
  58. */
  59. if (ds->dst->pd->nr_chips > 1)
  60. REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL_2,
  61. GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
  62. (ds->index & 0x1f));
  63. else
  64. REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL_2,
  65. GLOBAL_CONTROL_2_NO_CASCADE |
  66. (ds->index & 0x1f));
  67. /* Force the priority of IGMP/MLD snoop frames and ARP frames
  68. * to the highest setting.
  69. */
  70. REG_WRITE(REG_GLOBAL2, GLOBAL2_PRIO_OVERRIDE,
  71. GLOBAL2_PRIO_OVERRIDE_FORCE_SNOOP |
  72. 7 << GLOBAL2_PRIO_OVERRIDE_SNOOP_SHIFT |
  73. GLOBAL2_PRIO_OVERRIDE_FORCE_ARP |
  74. 7 << GLOBAL2_PRIO_OVERRIDE_ARP_SHIFT);
  75. return 0;
  76. }
  77. static int mv88e6131_setup(struct dsa_switch *ds)
  78. {
  79. struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
  80. int ret;
  81. ret = mv88e6xxx_setup_common(ds);
  82. if (ret < 0)
  83. return ret;
  84. mv88e6xxx_ppu_state_init(ds);
  85. switch (ps->id) {
  86. case PORT_SWITCH_ID_6085:
  87. case PORT_SWITCH_ID_6185:
  88. ps->num_ports = 10;
  89. break;
  90. case PORT_SWITCH_ID_6095:
  91. ps->num_ports = 11;
  92. break;
  93. case PORT_SWITCH_ID_6131:
  94. case PORT_SWITCH_ID_6131_B2:
  95. ps->num_ports = 8;
  96. break;
  97. default:
  98. return -ENODEV;
  99. }
  100. ret = mv88e6xxx_switch_reset(ds, false);
  101. if (ret < 0)
  102. return ret;
  103. ret = mv88e6131_setup_global(ds);
  104. if (ret < 0)
  105. return ret;
  106. return mv88e6xxx_setup_ports(ds);
  107. }
  108. static int mv88e6131_port_to_phy_addr(struct dsa_switch *ds, int port)
  109. {
  110. struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
  111. if (port >= 0 && port < ps->num_ports)
  112. return port;
  113. return -EINVAL;
  114. }
  115. static int
  116. mv88e6131_phy_read(struct dsa_switch *ds, int port, int regnum)
  117. {
  118. int addr = mv88e6131_port_to_phy_addr(ds, port);
  119. if (addr < 0)
  120. return addr;
  121. return mv88e6xxx_phy_read_ppu(ds, addr, regnum);
  122. }
  123. static int
  124. mv88e6131_phy_write(struct dsa_switch *ds,
  125. int port, int regnum, u16 val)
  126. {
  127. int addr = mv88e6131_port_to_phy_addr(ds, port);
  128. if (addr < 0)
  129. return addr;
  130. return mv88e6xxx_phy_write_ppu(ds, addr, regnum, val);
  131. }
  132. struct dsa_switch_driver mv88e6131_switch_driver = {
  133. .tag_protocol = DSA_TAG_PROTO_DSA,
  134. .priv_size = sizeof(struct mv88e6xxx_priv_state),
  135. .probe = mv88e6131_probe,
  136. .setup = mv88e6131_setup,
  137. .set_addr = mv88e6xxx_set_addr_direct,
  138. .phy_read = mv88e6131_phy_read,
  139. .phy_write = mv88e6131_phy_write,
  140. .get_strings = mv88e6xxx_get_strings,
  141. .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
  142. .get_sset_count = mv88e6xxx_get_sset_count,
  143. .adjust_link = mv88e6xxx_adjust_link,
  144. };
  145. MODULE_ALIAS("platform:mv88e6085");
  146. MODULE_ALIAS("platform:mv88e6095");
  147. MODULE_ALIAS("platform:mv88e6095f");
  148. MODULE_ALIAS("platform:mv88e6131");