Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 1 | /* |
Lennert Buytenhek | 076d3e1 | 2009-03-20 09:50:39 +0000 | [diff] [blame] | 2 | * net/dsa/mv88e6131.c - Marvell 88e6095/6095f/6131 switch chip support |
| 3 | * Copyright (c) 2008-2009 Marvell Semiconductor |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 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 | |
Barry Grussling | 19b2f97 | 2013-01-08 16:05:54 +0000 | [diff] [blame] | 11 | #include <linux/delay.h> |
| 12 | #include <linux/jiffies.h> |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 13 | #include <linux/list.h> |
Paul Gortmaker | 2bbba27 | 2012-01-24 10:41:40 +0000 | [diff] [blame] | 14 | #include <linux/module.h> |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 15 | #include <linux/netdevice.h> |
| 16 | #include <linux/phy.h> |
Ben Hutchings | c8f0b86 | 2011-11-27 17:06:08 +0000 | [diff] [blame] | 17 | #include <net/dsa.h> |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 18 | #include "mv88e6xxx.h" |
| 19 | |
Alexander Duyck | b4d2394 | 2014-09-15 13:00:27 -0400 | [diff] [blame] | 20 | static char *mv88e6131_probe(struct device *host_dev, int sw_addr) |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 21 | { |
Alexander Duyck | b4d2394 | 2014-09-15 13:00:27 -0400 | [diff] [blame] | 22 | struct mii_bus *bus = dsa_host_dev_to_mii_bus(host_dev); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 23 | int ret; |
| 24 | |
Alexander Duyck | b4d2394 | 2014-09-15 13:00:27 -0400 | [diff] [blame] | 25 | if (bus == NULL) |
| 26 | return NULL; |
| 27 | |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 28 | ret = __mv88e6xxx_reg_read(bus, sw_addr, REG_PORT(0), PORT_SWITCH_ID); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 29 | if (ret >= 0) { |
Guenter Roeck | a93e464 | 2014-10-29 10:44:55 -0700 | [diff] [blame] | 30 | int ret_masked = ret & 0xfff0; |
| 31 | |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 32 | if (ret_masked == PORT_SWITCH_ID_6085) |
Peter Korsgaard | ec80bfc | 2011-04-05 03:03:56 +0000 | [diff] [blame] | 33 | return "Marvell 88E6085"; |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 34 | if (ret_masked == PORT_SWITCH_ID_6095) |
Lennert Buytenhek | 076d3e1 | 2009-03-20 09:50:39 +0000 | [diff] [blame] | 35 | return "Marvell 88E6095/88E6095F"; |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 36 | if (ret == PORT_SWITCH_ID_6131_B2) |
Guenter Roeck | a93e464 | 2014-10-29 10:44:55 -0700 | [diff] [blame] | 37 | return "Marvell 88E6131 (B2)"; |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 38 | if (ret_masked == PORT_SWITCH_ID_6131) |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 39 | return "Marvell 88E6131"; |
Andrew Lunn | 1441f4e | 2015-05-06 01:09:52 +0200 | [diff] [blame^] | 40 | if (ret_masked == PORT_SWITCH_ID_6185) |
| 41 | return "Marvell 88E6185"; |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | return NULL; |
| 45 | } |
| 46 | |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 47 | static int mv88e6131_setup_global(struct dsa_switch *ds) |
| 48 | { |
Andrew Lunn | 15966a2 | 2015-05-06 01:09:49 +0200 | [diff] [blame] | 49 | u32 upstream_port = dsa_upstream_port(ds); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 50 | int ret; |
Andrew Lunn | 15966a2 | 2015-05-06 01:09:49 +0200 | [diff] [blame] | 51 | u32 reg; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 52 | |
| 53 | ret = mv88e6xxx_setup_global(ds); |
| 54 | if (ret) |
| 55 | return ret; |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 56 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 57 | /* Enable the PHY polling unit, don't discard packets with |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 58 | * excessive collisions, use a weighted fair queueing scheme |
| 59 | * to arbitrate between packet queues, set the maximum frame |
| 60 | * size to 1632, and mask all interrupt sources. |
| 61 | */ |
Andrew Lunn | 15966a2 | 2015-05-06 01:09:49 +0200 | [diff] [blame] | 62 | REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL, |
| 63 | GLOBAL_CONTROL_PPU_ENABLE | GLOBAL_CONTROL_MAX_FRAME_1632); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 64 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 65 | /* Set the VLAN ethertype to 0x8100. */ |
Andrew Lunn | 15966a2 | 2015-05-06 01:09:49 +0200 | [diff] [blame] | 66 | REG_WRITE(REG_GLOBAL, GLOBAL_CORE_TAG_TYPE, 0x8100); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 67 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 68 | /* Disable ARP mirroring, and configure the upstream port as |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 69 | * the port to which ingress and egress monitor frames are to |
| 70 | * be sent. |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 71 | */ |
Andrew Lunn | 15966a2 | 2015-05-06 01:09:49 +0200 | [diff] [blame] | 72 | reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT | |
| 73 | upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT | |
| 74 | GLOBAL_MONITOR_CONTROL_ARP_DISABLED; |
| 75 | REG_WRITE(REG_GLOBAL, GLOBAL_MONITOR_CONTROL, reg); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 76 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 77 | /* Disable cascade port functionality unless this device |
Barry Grussling | 81399ec | 2011-06-24 19:53:51 +0000 | [diff] [blame] | 78 | * is used in a cascade configuration, and set the switch's |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 79 | * DSA device number. |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 80 | */ |
Barry Grussling | 81399ec | 2011-06-24 19:53:51 +0000 | [diff] [blame] | 81 | if (ds->dst->pd->nr_chips > 1) |
Andrew Lunn | 15966a2 | 2015-05-06 01:09:49 +0200 | [diff] [blame] | 82 | REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL_2, |
| 83 | GLOBAL_CONTROL_2_MULTIPLE_CASCADE | |
| 84 | (ds->index & 0x1f)); |
Barry Grussling | 81399ec | 2011-06-24 19:53:51 +0000 | [diff] [blame] | 85 | else |
Andrew Lunn | 15966a2 | 2015-05-06 01:09:49 +0200 | [diff] [blame] | 86 | REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL_2, |
| 87 | GLOBAL_CONTROL_2_NO_CASCADE | |
| 88 | (ds->index & 0x1f)); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 89 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 90 | /* Force the priority of IGMP/MLD snoop frames and ARP frames |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 91 | * to the highest setting. |
| 92 | */ |
Andrew Lunn | 15966a2 | 2015-05-06 01:09:49 +0200 | [diff] [blame] | 93 | REG_WRITE(REG_GLOBAL2, GLOBAL2_PRIO_OVERRIDE, |
| 94 | GLOBAL2_PRIO_OVERRIDE_FORCE_SNOOP | |
| 95 | 7 << GLOBAL2_PRIO_OVERRIDE_SNOOP_SHIFT | |
| 96 | GLOBAL2_PRIO_OVERRIDE_FORCE_ARP | |
| 97 | 7 << GLOBAL2_PRIO_OVERRIDE_ARP_SHIFT); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 102 | static int mv88e6131_setup(struct dsa_switch *ds) |
| 103 | { |
Guenter Roeck | d198893 | 2015-04-02 04:06:31 +0200 | [diff] [blame] | 104 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 105 | int ret; |
| 106 | |
Guenter Roeck | 0d65da4 | 2015-04-02 04:06:29 +0200 | [diff] [blame] | 107 | ret = mv88e6xxx_setup_common(ds); |
| 108 | if (ret < 0) |
| 109 | return ret; |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 110 | |
Guenter Roeck | 0d65da4 | 2015-04-02 04:06:29 +0200 | [diff] [blame] | 111 | mv88e6xxx_ppu_state_init(ds); |
Peter Korsgaard | ec80bfc | 2011-04-05 03:03:56 +0000 | [diff] [blame] | 112 | |
Guenter Roeck | d198893 | 2015-04-02 04:06:31 +0200 | [diff] [blame] | 113 | switch (ps->id) { |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 114 | case PORT_SWITCH_ID_6085: |
Andrew Lunn | 1441f4e | 2015-05-06 01:09:52 +0200 | [diff] [blame^] | 115 | case PORT_SWITCH_ID_6185: |
Guenter Roeck | d198893 | 2015-04-02 04:06:31 +0200 | [diff] [blame] | 116 | ps->num_ports = 10; |
| 117 | break; |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 118 | case PORT_SWITCH_ID_6095: |
Guenter Roeck | d198893 | 2015-04-02 04:06:31 +0200 | [diff] [blame] | 119 | ps->num_ports = 11; |
| 120 | break; |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 121 | case PORT_SWITCH_ID_6131: |
| 122 | case PORT_SWITCH_ID_6131_B2: |
Guenter Roeck | d198893 | 2015-04-02 04:06:31 +0200 | [diff] [blame] | 123 | ps->num_ports = 8; |
| 124 | break; |
| 125 | default: |
| 126 | return -ENODEV; |
| 127 | } |
| 128 | |
Andrew Lunn | 143a830 | 2015-04-02 04:06:34 +0200 | [diff] [blame] | 129 | ret = mv88e6xxx_switch_reset(ds, false); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 130 | if (ret < 0) |
| 131 | return ret; |
| 132 | |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 133 | ret = mv88e6131_setup_global(ds); |
| 134 | if (ret < 0) |
| 135 | return ret; |
| 136 | |
Andrew Lunn | dbde9e6 | 2015-05-06 01:09:48 +0200 | [diff] [blame] | 137 | return mv88e6xxx_setup_ports(ds); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 138 | } |
| 139 | |
Guenter Roeck | d198893 | 2015-04-02 04:06:31 +0200 | [diff] [blame] | 140 | static int mv88e6131_port_to_phy_addr(struct dsa_switch *ds, int port) |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 141 | { |
Guenter Roeck | d198893 | 2015-04-02 04:06:31 +0200 | [diff] [blame] | 142 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 143 | |
| 144 | if (port >= 0 && port < ps->num_ports) |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 145 | return port; |
Guenter Roeck | d198893 | 2015-04-02 04:06:31 +0200 | [diff] [blame] | 146 | |
| 147 | return -EINVAL; |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | static int |
| 151 | mv88e6131_phy_read(struct dsa_switch *ds, int port, int regnum) |
| 152 | { |
Guenter Roeck | d198893 | 2015-04-02 04:06:31 +0200 | [diff] [blame] | 153 | int addr = mv88e6131_port_to_phy_addr(ds, port); |
| 154 | |
| 155 | if (addr < 0) |
| 156 | return addr; |
| 157 | |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 158 | return mv88e6xxx_phy_read_ppu(ds, addr, regnum); |
| 159 | } |
| 160 | |
| 161 | static int |
| 162 | mv88e6131_phy_write(struct dsa_switch *ds, |
| 163 | int port, int regnum, u16 val) |
| 164 | { |
Guenter Roeck | d198893 | 2015-04-02 04:06:31 +0200 | [diff] [blame] | 165 | int addr = mv88e6131_port_to_phy_addr(ds, port); |
| 166 | |
| 167 | if (addr < 0) |
| 168 | return addr; |
| 169 | |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 170 | return mv88e6xxx_phy_write_ppu(ds, addr, regnum, val); |
| 171 | } |
| 172 | |
Ben Hutchings | 98e6730 | 2011-11-25 14:36:19 +0000 | [diff] [blame] | 173 | struct dsa_switch_driver mv88e6131_switch_driver = { |
Florian Fainelli | ac7a04c | 2014-09-11 21:18:09 -0700 | [diff] [blame] | 174 | .tag_protocol = DSA_TAG_PROTO_DSA, |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 175 | .priv_size = sizeof(struct mv88e6xxx_priv_state), |
| 176 | .probe = mv88e6131_probe, |
| 177 | .setup = mv88e6131_setup, |
| 178 | .set_addr = mv88e6xxx_set_addr_direct, |
| 179 | .phy_read = mv88e6131_phy_read, |
| 180 | .phy_write = mv88e6131_phy_write, |
| 181 | .poll_link = mv88e6xxx_poll_link, |
Andrew Lunn | e413e7e | 2015-04-02 04:06:38 +0200 | [diff] [blame] | 182 | .get_strings = mv88e6xxx_get_strings, |
| 183 | .get_ethtool_stats = mv88e6xxx_get_ethtool_stats, |
| 184 | .get_sset_count = mv88e6xxx_get_sset_count, |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 185 | }; |
Ben Hutchings | 3d825ed | 2011-11-25 14:37:16 +0000 | [diff] [blame] | 186 | |
| 187 | MODULE_ALIAS("platform:mv88e6085"); |
| 188 | MODULE_ALIAS("platform:mv88e6095"); |
| 189 | MODULE_ALIAS("platform:mv88e6095f"); |
| 190 | MODULE_ALIAS("platform:mv88e6131"); |