blob: b9f9b009f65a26897bfd479724cd42e001114880 [file] [log] [blame]
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +00001/*
Lennert Buytenhek076d3e12009-03-20 09:50:39 +00002 * net/dsa/mv88e6131.c - Marvell 88e6095/6095f/6131 switch chip support
3 * Copyright (c) 2008-2009 Marvell Semiconductor
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +00004 *
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 Grussling19b2f972013-01-08 16:05:54 +000011#include <linux/delay.h>
12#include <linux/jiffies.h>
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000013#include <linux/list.h>
Paul Gortmaker2bbba272012-01-24 10:41:40 +000014#include <linux/module.h>
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000015#include <linux/netdevice.h>
16#include <linux/phy.h>
Ben Hutchingsc8f0b862011-11-27 17:06:08 +000017#include <net/dsa.h>
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000018#include "mv88e6xxx.h"
19
Vivien Didelotb9b37712015-10-30 19:39:48 -040020static const struct mv88e6xxx_switch_id mv88e6131_table[] = {
21 { PORT_SWITCH_ID_6085, "Marvell 88E6085" },
22 { PORT_SWITCH_ID_6095, "Marvell 88E6095/88E6095F" },
23 { PORT_SWITCH_ID_6131, "Marvell 88E6131" },
24 { PORT_SWITCH_ID_6131_B2, "Marvell 88E6131 (B2)" },
25 { PORT_SWITCH_ID_6185, "Marvell 88E6185" },
26};
27
Andrew Lunnbbb8d792016-04-13 02:40:39 +020028static char *mv88e6131_probe(struct device *dsa_dev, struct device *host_dev,
Andrew Lunn7543a6d2016-04-13 02:40:40 +020029 int sw_addr, void **priv)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000030{
Andrew Lunn7543a6d2016-04-13 02:40:40 +020031 struct mv88e6xxx_priv_state *ps;
32 char *name;
33
34 name = mv88e6xxx_lookup_name(host_dev, sw_addr, mv88e6131_table,
Vivien Didelotb9b37712015-10-30 19:39:48 -040035 ARRAY_SIZE(mv88e6131_table));
Andrew Lunn7543a6d2016-04-13 02:40:40 +020036 if (name) {
37 ps = devm_kzalloc(dsa_dev, sizeof(*ps), GFP_KERNEL);
38 if (!ps)
39 return NULL;
40 *priv = ps;
41 }
42 return name;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000043}
44
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000045static int mv88e6131_setup_global(struct dsa_switch *ds)
46{
Andrew Lunn15966a22015-05-06 01:09:49 +020047 u32 upstream_port = dsa_upstream_port(ds);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000048 int ret;
Andrew Lunn15966a22015-05-06 01:09:49 +020049 u32 reg;
Andrew Lunn54d792f2015-05-06 01:09:47 +020050
51 ret = mv88e6xxx_setup_global(ds);
52 if (ret)
53 return ret;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000054
Barry Grussling3675c8d2013-01-08 16:05:53 +000055 /* Enable the PHY polling unit, don't discard packets with
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000056 * excessive collisions, use a weighted fair queueing scheme
57 * to arbitrate between packet queues, set the maximum frame
58 * size to 1632, and mask all interrupt sources.
59 */
Andrew Lunn15966a22015-05-06 01:09:49 +020060 REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL,
61 GLOBAL_CONTROL_PPU_ENABLE | GLOBAL_CONTROL_MAX_FRAME_1632);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000062
Barry Grussling3675c8d2013-01-08 16:05:53 +000063 /* Set the VLAN ethertype to 0x8100. */
Andrew Lunn15966a22015-05-06 01:09:49 +020064 REG_WRITE(REG_GLOBAL, GLOBAL_CORE_TAG_TYPE, 0x8100);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000065
Barry Grussling3675c8d2013-01-08 16:05:53 +000066 /* Disable ARP mirroring, and configure the upstream port as
Lennert Buytenheke84665c2009-03-20 09:52:09 +000067 * the port to which ingress and egress monitor frames are to
68 * be sent.
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000069 */
Andrew Lunn15966a22015-05-06 01:09:49 +020070 reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT |
71 upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT |
72 GLOBAL_MONITOR_CONTROL_ARP_DISABLED;
73 REG_WRITE(REG_GLOBAL, GLOBAL_MONITOR_CONTROL, reg);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000074
Barry Grussling3675c8d2013-01-08 16:05:53 +000075 /* Disable cascade port functionality unless this device
Barry Grussling81399ec2011-06-24 19:53:51 +000076 * is used in a cascade configuration, and set the switch's
Lennert Buytenheke84665c2009-03-20 09:52:09 +000077 * DSA device number.
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000078 */
Barry Grussling81399ec2011-06-24 19:53:51 +000079 if (ds->dst->pd->nr_chips > 1)
Andrew Lunn15966a22015-05-06 01:09:49 +020080 REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL_2,
81 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
82 (ds->index & 0x1f));
Barry Grussling81399ec2011-06-24 19:53:51 +000083 else
Andrew Lunn15966a22015-05-06 01:09:49 +020084 REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL_2,
85 GLOBAL_CONTROL_2_NO_CASCADE |
86 (ds->index & 0x1f));
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000087
Barry Grussling3675c8d2013-01-08 16:05:53 +000088 /* Force the priority of IGMP/MLD snoop frames and ARP frames
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000089 * to the highest setting.
90 */
Andrew Lunn15966a22015-05-06 01:09:49 +020091 REG_WRITE(REG_GLOBAL2, GLOBAL2_PRIO_OVERRIDE,
92 GLOBAL2_PRIO_OVERRIDE_FORCE_SNOOP |
93 7 << GLOBAL2_PRIO_OVERRIDE_SNOOP_SHIFT |
94 GLOBAL2_PRIO_OVERRIDE_FORCE_ARP |
95 7 << GLOBAL2_PRIO_OVERRIDE_ARP_SHIFT);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000096
97 return 0;
98}
99
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000100static int mv88e6131_setup(struct dsa_switch *ds)
101{
Guenter Roeckd1988932015-04-02 04:06:31 +0200102 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000103 int ret;
104
Andrew Lunn7543a6d2016-04-13 02:40:40 +0200105 ps->ds = ds;
106
Guenter Roeck0d65da42015-04-02 04:06:29 +0200107 ret = mv88e6xxx_setup_common(ds);
108 if (ret < 0)
109 return ret;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000110
Guenter Roeck0d65da42015-04-02 04:06:29 +0200111 mv88e6xxx_ppu_state_init(ds);
Peter Korsgaardec80bfc2011-04-05 03:03:56 +0000112
Guenter Roeckd1988932015-04-02 04:06:31 +0200113 switch (ps->id) {
Andrew Lunncca8b132015-04-02 04:06:39 +0200114 case PORT_SWITCH_ID_6085:
Andrew Lunn1441f4e2015-05-06 01:09:52 +0200115 case PORT_SWITCH_ID_6185:
Guenter Roeckd1988932015-04-02 04:06:31 +0200116 ps->num_ports = 10;
117 break;
Andrew Lunncca8b132015-04-02 04:06:39 +0200118 case PORT_SWITCH_ID_6095:
Guenter Roeckd1988932015-04-02 04:06:31 +0200119 ps->num_ports = 11;
120 break;
Andrew Lunncca8b132015-04-02 04:06:39 +0200121 case PORT_SWITCH_ID_6131:
122 case PORT_SWITCH_ID_6131_B2:
Guenter Roeckd1988932015-04-02 04:06:31 +0200123 ps->num_ports = 8;
124 break;
125 default:
126 return -ENODEV;
127 }
128
Andrew Lunn143a8302015-04-02 04:06:34 +0200129 ret = mv88e6xxx_switch_reset(ds, false);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000130 if (ret < 0)
131 return ret;
132
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000133 ret = mv88e6131_setup_global(ds);
134 if (ret < 0)
135 return ret;
136
Andrew Lunndbde9e62015-05-06 01:09:48 +0200137 return mv88e6xxx_setup_ports(ds);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000138}
139
Guenter Roeckd1988932015-04-02 04:06:31 +0200140static int mv88e6131_port_to_phy_addr(struct dsa_switch *ds, int port)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000141{
Guenter Roeckd1988932015-04-02 04:06:31 +0200142 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
143
144 if (port >= 0 && port < ps->num_ports)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000145 return port;
Guenter Roeckd1988932015-04-02 04:06:31 +0200146
147 return -EINVAL;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000148}
149
150static int
151mv88e6131_phy_read(struct dsa_switch *ds, int port, int regnum)
152{
Guenter Roeckd1988932015-04-02 04:06:31 +0200153 int addr = mv88e6131_port_to_phy_addr(ds, port);
154
155 if (addr < 0)
156 return addr;
157
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000158 return mv88e6xxx_phy_read_ppu(ds, addr, regnum);
159}
160
161static int
162mv88e6131_phy_write(struct dsa_switch *ds,
163 int port, int regnum, u16 val)
164{
Guenter Roeckd1988932015-04-02 04:06:31 +0200165 int addr = mv88e6131_port_to_phy_addr(ds, port);
166
167 if (addr < 0)
168 return addr;
169
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000170 return mv88e6xxx_phy_write_ppu(ds, addr, regnum, val);
171}
172
Ben Hutchings98e67302011-11-25 14:36:19 +0000173struct dsa_switch_driver mv88e6131_switch_driver = {
Florian Fainelliac7a04c2014-09-11 21:18:09 -0700174 .tag_protocol = DSA_TAG_PROTO_DSA,
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000175 .probe = mv88e6131_probe,
176 .setup = mv88e6131_setup,
177 .set_addr = mv88e6xxx_set_addr_direct,
178 .phy_read = mv88e6131_phy_read,
179 .phy_write = mv88e6131_phy_write,
Andrew Lunne413e7e2015-04-02 04:06:38 +0200180 .get_strings = mv88e6xxx_get_strings,
181 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
182 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunndea87022015-08-31 15:56:47 +0200183 .adjust_link = mv88e6xxx_adjust_link,
Vivien Didelot26892ff2016-03-31 16:53:46 -0400184 .port_bridge_join = mv88e6xxx_port_bridge_join,
185 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
186 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
187 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
188 .port_vlan_add = mv88e6xxx_port_vlan_add,
189 .port_vlan_del = mv88e6xxx_port_vlan_del,
190 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
191 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
192 .port_fdb_add = mv88e6xxx_port_fdb_add,
193 .port_fdb_del = mv88e6xxx_port_fdb_del,
194 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000195};
Ben Hutchings3d825ed2011-11-25 14:37:16 +0000196
197MODULE_ALIAS("platform:mv88e6085");
198MODULE_ALIAS("platform:mv88e6095");
199MODULE_ALIAS("platform:mv88e6095f");
200MODULE_ALIAS("platform:mv88e6131");