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"; |
| 40 | } |
| 41 | |
| 42 | return NULL; |
| 43 | } |
| 44 | |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 45 | static int mv88e6131_setup_global(struct dsa_switch *ds) |
| 46 | { |
| 47 | int ret; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame^] | 48 | |
| 49 | ret = mv88e6xxx_setup_global(ds); |
| 50 | if (ret) |
| 51 | return ret; |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 52 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 53 | /* Enable the PHY polling unit, don't discard packets with |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 54 | * excessive collisions, use a weighted fair queueing scheme |
| 55 | * to arbitrate between packet queues, set the maximum frame |
| 56 | * size to 1632, and mask all interrupt sources. |
| 57 | */ |
| 58 | REG_WRITE(REG_GLOBAL, 0x04, 0x4400); |
| 59 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 60 | /* Set the VLAN ethertype to 0x8100. */ |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 61 | REG_WRITE(REG_GLOBAL, 0x19, 0x8100); |
| 62 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 63 | /* Disable ARP mirroring, and configure the upstream port as |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 64 | * the port to which ingress and egress monitor frames are to |
| 65 | * be sent. |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 66 | */ |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 67 | REG_WRITE(REG_GLOBAL, 0x1a, (dsa_upstream_port(ds) * 0x1100) | 0x00f0); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 68 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 69 | /* Disable cascade port functionality unless this device |
Barry Grussling | 81399ec | 2011-06-24 19:53:51 +0000 | [diff] [blame] | 70 | * is used in a cascade configuration, and set the switch's |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 71 | * DSA device number. |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 72 | */ |
Barry Grussling | 81399ec | 2011-06-24 19:53:51 +0000 | [diff] [blame] | 73 | if (ds->dst->pd->nr_chips > 1) |
| 74 | REG_WRITE(REG_GLOBAL, 0x1c, 0xf000 | (ds->index & 0x1f)); |
| 75 | else |
| 76 | REG_WRITE(REG_GLOBAL, 0x1c, 0xe000 | (ds->index & 0x1f)); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 77 | |
Barry Grussling | 3675c8d | 2013-01-08 16:05:53 +0000 | [diff] [blame] | 78 | /* Force the priority of IGMP/MLD snoop frames and ARP frames |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 79 | * to the highest setting. |
| 80 | */ |
| 81 | REG_WRITE(REG_GLOBAL2, 0x0f, 0x00ff); |
| 82 | |
| 83 | return 0; |
| 84 | } |
| 85 | |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 86 | static int mv88e6131_setup(struct dsa_switch *ds) |
| 87 | { |
Guenter Roeck | d198893 | 2015-04-02 04:06:31 +0200 | [diff] [blame] | 88 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 89 | int i; |
| 90 | int ret; |
| 91 | |
Guenter Roeck | 0d65da4 | 2015-04-02 04:06:29 +0200 | [diff] [blame] | 92 | ret = mv88e6xxx_setup_common(ds); |
| 93 | if (ret < 0) |
| 94 | return ret; |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 95 | |
Guenter Roeck | 0d65da4 | 2015-04-02 04:06:29 +0200 | [diff] [blame] | 96 | mv88e6xxx_ppu_state_init(ds); |
Peter Korsgaard | ec80bfc | 2011-04-05 03:03:56 +0000 | [diff] [blame] | 97 | |
Guenter Roeck | d198893 | 2015-04-02 04:06:31 +0200 | [diff] [blame] | 98 | switch (ps->id) { |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 99 | case PORT_SWITCH_ID_6085: |
Guenter Roeck | d198893 | 2015-04-02 04:06:31 +0200 | [diff] [blame] | 100 | ps->num_ports = 10; |
| 101 | break; |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 102 | case PORT_SWITCH_ID_6095: |
Guenter Roeck | d198893 | 2015-04-02 04:06:31 +0200 | [diff] [blame] | 103 | ps->num_ports = 11; |
| 104 | break; |
Andrew Lunn | cca8b13 | 2015-04-02 04:06:39 +0200 | [diff] [blame] | 105 | case PORT_SWITCH_ID_6131: |
| 106 | case PORT_SWITCH_ID_6131_B2: |
Guenter Roeck | d198893 | 2015-04-02 04:06:31 +0200 | [diff] [blame] | 107 | ps->num_ports = 8; |
| 108 | break; |
| 109 | default: |
| 110 | return -ENODEV; |
| 111 | } |
| 112 | |
Andrew Lunn | 143a830 | 2015-04-02 04:06:34 +0200 | [diff] [blame] | 113 | ret = mv88e6xxx_switch_reset(ds, false); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 114 | if (ret < 0) |
| 115 | return ret; |
| 116 | |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 117 | ret = mv88e6131_setup_global(ds); |
| 118 | if (ret < 0) |
| 119 | return ret; |
| 120 | |
Guenter Roeck | d198893 | 2015-04-02 04:06:31 +0200 | [diff] [blame] | 121 | for (i = 0; i < ps->num_ports; i++) { |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame^] | 122 | ret = mv88e6xxx_setup_port(ds, i); |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 123 | if (ret < 0) |
| 124 | return ret; |
| 125 | } |
| 126 | |
| 127 | return 0; |
| 128 | } |
| 129 | |
Guenter Roeck | d198893 | 2015-04-02 04:06:31 +0200 | [diff] [blame] | 130 | 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] | 131 | { |
Guenter Roeck | d198893 | 2015-04-02 04:06:31 +0200 | [diff] [blame] | 132 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 133 | |
| 134 | if (port >= 0 && port < ps->num_ports) |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 135 | return port; |
Guenter Roeck | d198893 | 2015-04-02 04:06:31 +0200 | [diff] [blame] | 136 | |
| 137 | return -EINVAL; |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | static int |
| 141 | mv88e6131_phy_read(struct dsa_switch *ds, int port, int regnum) |
| 142 | { |
Guenter Roeck | d198893 | 2015-04-02 04:06:31 +0200 | [diff] [blame] | 143 | int addr = mv88e6131_port_to_phy_addr(ds, port); |
| 144 | |
| 145 | if (addr < 0) |
| 146 | return addr; |
| 147 | |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 148 | return mv88e6xxx_phy_read_ppu(ds, addr, regnum); |
| 149 | } |
| 150 | |
| 151 | static int |
| 152 | mv88e6131_phy_write(struct dsa_switch *ds, |
| 153 | int port, int regnum, u16 val) |
| 154 | { |
Guenter Roeck | d198893 | 2015-04-02 04:06:31 +0200 | [diff] [blame] | 155 | int addr = mv88e6131_port_to_phy_addr(ds, port); |
| 156 | |
| 157 | if (addr < 0) |
| 158 | return addr; |
| 159 | |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 160 | return mv88e6xxx_phy_write_ppu(ds, addr, regnum, val); |
| 161 | } |
| 162 | |
Ben Hutchings | 98e6730 | 2011-11-25 14:36:19 +0000 | [diff] [blame] | 163 | struct dsa_switch_driver mv88e6131_switch_driver = { |
Florian Fainelli | ac7a04c | 2014-09-11 21:18:09 -0700 | [diff] [blame] | 164 | .tag_protocol = DSA_TAG_PROTO_DSA, |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 165 | .priv_size = sizeof(struct mv88e6xxx_priv_state), |
| 166 | .probe = mv88e6131_probe, |
| 167 | .setup = mv88e6131_setup, |
| 168 | .set_addr = mv88e6xxx_set_addr_direct, |
| 169 | .phy_read = mv88e6131_phy_read, |
| 170 | .phy_write = mv88e6131_phy_write, |
| 171 | .poll_link = mv88e6xxx_poll_link, |
Andrew Lunn | e413e7e | 2015-04-02 04:06:38 +0200 | [diff] [blame] | 172 | .get_strings = mv88e6xxx_get_strings, |
| 173 | .get_ethtool_stats = mv88e6xxx_get_ethtool_stats, |
| 174 | .get_sset_count = mv88e6xxx_get_sset_count, |
Lennert Buytenhek | 2e5f032 | 2008-10-07 13:45:18 +0000 | [diff] [blame] | 175 | }; |
Ben Hutchings | 3d825ed | 2011-11-25 14:37:16 +0000 | [diff] [blame] | 176 | |
| 177 | MODULE_ALIAS("platform:mv88e6085"); |
| 178 | MODULE_ALIAS("platform:mv88e6095"); |
| 179 | MODULE_ALIAS("platform:mv88e6095f"); |
| 180 | MODULE_ALIAS("platform:mv88e6131"); |