mv88e6131.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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_info mv88e6131_table[] = {
  19. {
  20. .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
  21. .family = MV88E6XXX_FAMILY_6095,
  22. .name = "Marvell 88E6095/88E6095F",
  23. .num_databases = 256,
  24. .num_ports = 11,
  25. }, {
  26. .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
  27. .family = MV88E6XXX_FAMILY_6097,
  28. .name = "Marvell 88E6085",
  29. .num_databases = 4096,
  30. .num_ports = 10,
  31. }, {
  32. .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
  33. .family = MV88E6XXX_FAMILY_6185,
  34. .name = "Marvell 88E6131",
  35. .num_databases = 256,
  36. .num_ports = 8,
  37. }, {
  38. .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
  39. .family = MV88E6XXX_FAMILY_6185,
  40. .name = "Marvell 88E6185",
  41. .num_databases = 256,
  42. .num_ports = 10,
  43. }
  44. };
  45. static const char *mv88e6131_drv_probe(struct device *dsa_dev,
  46. struct device *host_dev, int sw_addr,
  47. void **priv)
  48. {
  49. return mv88e6xxx_drv_probe(dsa_dev, host_dev, sw_addr, priv,
  50. mv88e6131_table,
  51. ARRAY_SIZE(mv88e6131_table));
  52. }
  53. static int mv88e6131_setup_global(struct dsa_switch *ds)
  54. {
  55. u32 upstream_port = dsa_upstream_port(ds);
  56. int ret;
  57. u32 reg;
  58. ret = mv88e6xxx_setup_global(ds);
  59. if (ret)
  60. return ret;
  61. /* Enable the PHY polling unit, don't discard packets with
  62. * excessive collisions, use a weighted fair queueing scheme
  63. * to arbitrate between packet queues, set the maximum frame
  64. * size to 1632, and mask all interrupt sources.
  65. */
  66. ret = mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_CONTROL,
  67. GLOBAL_CONTROL_PPU_ENABLE |
  68. GLOBAL_CONTROL_MAX_FRAME_1632);
  69. if (ret)
  70. return ret;
  71. /* Set the VLAN ethertype to 0x8100. */
  72. ret = mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_CORE_TAG_TYPE, 0x8100);
  73. if (ret)
  74. return ret;
  75. /* Disable ARP mirroring, and configure the upstream port as
  76. * the port to which ingress and egress monitor frames are to
  77. * be sent.
  78. */
  79. reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT |
  80. upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT |
  81. GLOBAL_MONITOR_CONTROL_ARP_DISABLED;
  82. ret = mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_MONITOR_CONTROL, reg);
  83. if (ret)
  84. return ret;
  85. /* Disable cascade port functionality unless this device
  86. * is used in a cascade configuration, and set the switch's
  87. * DSA device number.
  88. */
  89. if (ds->dst->pd->nr_chips > 1)
  90. ret = mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_CONTROL_2,
  91. GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
  92. (ds->index & 0x1f));
  93. else
  94. ret = mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_CONTROL_2,
  95. GLOBAL_CONTROL_2_NO_CASCADE |
  96. (ds->index & 0x1f));
  97. if (ret)
  98. return ret;
  99. /* Force the priority of IGMP/MLD snoop frames and ARP frames
  100. * to the highest setting.
  101. */
  102. return mv88e6xxx_reg_write(ds, REG_GLOBAL2, GLOBAL2_PRIO_OVERRIDE,
  103. GLOBAL2_PRIO_OVERRIDE_FORCE_SNOOP |
  104. 7 << GLOBAL2_PRIO_OVERRIDE_SNOOP_SHIFT |
  105. GLOBAL2_PRIO_OVERRIDE_FORCE_ARP |
  106. 7 << GLOBAL2_PRIO_OVERRIDE_ARP_SHIFT);
  107. }
  108. static int mv88e6131_setup(struct dsa_switch *ds)
  109. {
  110. int ret;
  111. ret = mv88e6xxx_setup_common(ds);
  112. if (ret < 0)
  113. return ret;
  114. mv88e6xxx_ppu_state_init(ds);
  115. ret = mv88e6xxx_switch_reset(ds, false);
  116. if (ret < 0)
  117. return ret;
  118. ret = mv88e6131_setup_global(ds);
  119. if (ret < 0)
  120. return ret;
  121. return mv88e6xxx_setup_ports(ds);
  122. }
  123. static int mv88e6131_port_to_phy_addr(struct dsa_switch *ds, int port)
  124. {
  125. struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
  126. if (port >= 0 && port < ps->info->num_ports)
  127. return port;
  128. return -EINVAL;
  129. }
  130. static int
  131. mv88e6131_phy_read(struct dsa_switch *ds, int port, int regnum)
  132. {
  133. int addr = mv88e6131_port_to_phy_addr(ds, port);
  134. if (addr < 0)
  135. return addr;
  136. return mv88e6xxx_phy_read_ppu(ds, addr, regnum);
  137. }
  138. static int
  139. mv88e6131_phy_write(struct dsa_switch *ds,
  140. int port, int regnum, u16 val)
  141. {
  142. int addr = mv88e6131_port_to_phy_addr(ds, port);
  143. if (addr < 0)
  144. return addr;
  145. return mv88e6xxx_phy_write_ppu(ds, addr, regnum, val);
  146. }
  147. struct dsa_switch_driver mv88e6131_switch_driver = {
  148. .tag_protocol = DSA_TAG_PROTO_DSA,
  149. .probe = mv88e6131_drv_probe,
  150. .setup = mv88e6131_setup,
  151. .set_addr = mv88e6xxx_set_addr_direct,
  152. .phy_read = mv88e6131_phy_read,
  153. .phy_write = mv88e6131_phy_write,
  154. .get_strings = mv88e6xxx_get_strings,
  155. .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
  156. .get_sset_count = mv88e6xxx_get_sset_count,
  157. .adjust_link = mv88e6xxx_adjust_link,
  158. .port_bridge_join = mv88e6xxx_port_bridge_join,
  159. .port_bridge_leave = mv88e6xxx_port_bridge_leave,
  160. .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
  161. .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
  162. .port_vlan_add = mv88e6xxx_port_vlan_add,
  163. .port_vlan_del = mv88e6xxx_port_vlan_del,
  164. .port_vlan_dump = mv88e6xxx_port_vlan_dump,
  165. .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
  166. .port_fdb_add = mv88e6xxx_port_fdb_add,
  167. .port_fdb_del = mv88e6xxx_port_fdb_del,
  168. .port_fdb_dump = mv88e6xxx_port_fdb_dump,
  169. };
  170. MODULE_ALIAS("platform:mv88e6085");
  171. MODULE_ALIAS("platform:mv88e6095");
  172. MODULE_ALIAS("platform:mv88e6095f");
  173. MODULE_ALIAS("platform:mv88e6131");