mv88e6171.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* net/dsa/mv88e6171.c - Marvell 88e6171 switch chip support
  2. * Copyright (c) 2008-2009 Marvell Semiconductor
  3. * Copyright (c) 2014 Claudio Leite <leitec@staticky.com>
  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 char *mv88e6171_probe(struct device *host_dev, int sw_addr)
  19. {
  20. struct mii_bus *bus = dsa_host_dev_to_mii_bus(host_dev);
  21. int ret;
  22. if (bus == NULL)
  23. return NULL;
  24. ret = __mv88e6xxx_reg_read(bus, sw_addr, REG_PORT(0), PORT_SWITCH_ID);
  25. if (ret >= 0) {
  26. if ((ret & 0xfff0) == PORT_SWITCH_ID_6171)
  27. return "Marvell 88E6171";
  28. if ((ret & 0xfff0) == PORT_SWITCH_ID_6175)
  29. return "Marvell 88E6175";
  30. if ((ret & 0xfff0) == PORT_SWITCH_ID_6350)
  31. return "Marvell 88E6350";
  32. if ((ret & 0xfff0) == PORT_SWITCH_ID_6351)
  33. return "Marvell 88E6351";
  34. }
  35. return NULL;
  36. }
  37. static int mv88e6171_setup_global(struct dsa_switch *ds)
  38. {
  39. u32 upstream_port = dsa_upstream_port(ds);
  40. int ret;
  41. u32 reg;
  42. ret = mv88e6xxx_setup_global(ds);
  43. if (ret)
  44. return ret;
  45. /* Discard packets with excessive collisions, mask all
  46. * interrupt sources, enable PPU.
  47. */
  48. REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL,
  49. GLOBAL_CONTROL_PPU_ENABLE | GLOBAL_CONTROL_DISCARD_EXCESS);
  50. /* Configure the upstream port, and configure the upstream
  51. * port as the port to which ingress and egress monitor frames
  52. * are to be sent.
  53. */
  54. reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT |
  55. upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT |
  56. upstream_port << GLOBAL_MONITOR_CONTROL_ARP_SHIFT |
  57. upstream_port << GLOBAL_MONITOR_CONTROL_MIRROR_SHIFT;
  58. REG_WRITE(REG_GLOBAL, GLOBAL_MONITOR_CONTROL, reg);
  59. /* Disable remote management for now, and set the switch's
  60. * DSA device number.
  61. */
  62. REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL_2, ds->index & 0x1f);
  63. return 0;
  64. }
  65. static int mv88e6171_setup(struct dsa_switch *ds)
  66. {
  67. struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
  68. int ret;
  69. ret = mv88e6xxx_setup_common(ds);
  70. if (ret < 0)
  71. return ret;
  72. ps->num_ports = 7;
  73. ret = mv88e6xxx_switch_reset(ds, true);
  74. if (ret < 0)
  75. return ret;
  76. ret = mv88e6171_setup_global(ds);
  77. if (ret < 0)
  78. return ret;
  79. return mv88e6xxx_setup_ports(ds);
  80. }
  81. struct dsa_switch_driver mv88e6171_switch_driver = {
  82. .tag_protocol = DSA_TAG_PROTO_EDSA,
  83. .priv_size = sizeof(struct mv88e6xxx_priv_state),
  84. .probe = mv88e6171_probe,
  85. .setup = mv88e6171_setup,
  86. .set_addr = mv88e6xxx_set_addr_indirect,
  87. .phy_read = mv88e6xxx_phy_read_indirect,
  88. .phy_write = mv88e6xxx_phy_write_indirect,
  89. .poll_link = mv88e6xxx_poll_link,
  90. .get_strings = mv88e6xxx_get_strings,
  91. .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
  92. .get_sset_count = mv88e6xxx_get_sset_count,
  93. .adjust_link = mv88e6xxx_adjust_link,
  94. #ifdef CONFIG_NET_DSA_HWMON
  95. .get_temp = mv88e6xxx_get_temp,
  96. #endif
  97. .get_regs_len = mv88e6xxx_get_regs_len,
  98. .get_regs = mv88e6xxx_get_regs,
  99. .port_join_bridge = mv88e6xxx_join_bridge,
  100. .port_leave_bridge = mv88e6xxx_leave_bridge,
  101. .port_stp_update = mv88e6xxx_port_stp_update,
  102. .port_pvid_get = mv88e6xxx_port_pvid_get,
  103. .port_pvid_set = mv88e6xxx_port_pvid_set,
  104. .port_vlan_add = mv88e6xxx_port_vlan_add,
  105. .port_vlan_del = mv88e6xxx_port_vlan_del,
  106. .vlan_getnext = mv88e6xxx_vlan_getnext,
  107. .port_fdb_add = mv88e6xxx_port_fdb_add,
  108. .port_fdb_del = mv88e6xxx_port_fdb_del,
  109. .port_fdb_getnext = mv88e6xxx_port_fdb_getnext,
  110. };
  111. MODULE_ALIAS("platform:mv88e6171");
  112. MODULE_ALIAS("platform:mv88e6175");
  113. MODULE_ALIAS("platform:mv88e6350");
  114. MODULE_ALIAS("platform:mv88e6351");