blob: 5bec7a60b476e321b6769add0851ff27fc929501 [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
Alexander Duyckb4d23942014-09-15 13:00:27 -040020static char *mv88e6131_probe(struct device *host_dev, int sw_addr)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000021{
Alexander Duyckb4d23942014-09-15 13:00:27 -040022 struct mii_bus *bus = dsa_host_dev_to_mii_bus(host_dev);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000023 int ret;
24
Alexander Duyckb4d23942014-09-15 13:00:27 -040025 if (bus == NULL)
26 return NULL;
27
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000028 ret = __mv88e6xxx_reg_read(bus, sw_addr, REG_PORT(0), 0x03);
29 if (ret >= 0) {
Guenter Roecka93e4642014-10-29 10:44:55 -070030 int ret_masked = ret & 0xfff0;
31
32 if (ret_masked == ID_6085)
Peter Korsgaardec80bfc2011-04-05 03:03:56 +000033 return "Marvell 88E6085";
Guenter Roecka93e4642014-10-29 10:44:55 -070034 if (ret_masked == ID_6095)
Lennert Buytenhek076d3e12009-03-20 09:50:39 +000035 return "Marvell 88E6095/88E6095F";
Guenter Roecka93e4642014-10-29 10:44:55 -070036 if (ret == ID_6131_B2)
37 return "Marvell 88E6131 (B2)";
38 if (ret_masked == ID_6131)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000039 return "Marvell 88E6131";
40 }
41
42 return NULL;
43}
44
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000045static int mv88e6131_setup_global(struct dsa_switch *ds)
46{
47 int ret;
48 int i;
49
Barry Grussling3675c8d2013-01-08 16:05:53 +000050 /* Enable the PHY polling unit, don't discard packets with
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000051 * excessive collisions, use a weighted fair queueing scheme
52 * to arbitrate between packet queues, set the maximum frame
53 * size to 1632, and mask all interrupt sources.
54 */
55 REG_WRITE(REG_GLOBAL, 0x04, 0x4400);
56
Barry Grussling3675c8d2013-01-08 16:05:53 +000057 /* Set the default address aging time to 5 minutes, and
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000058 * enable address learn messages to be sent to all message
59 * ports.
60 */
61 REG_WRITE(REG_GLOBAL, 0x0a, 0x0148);
62
Barry Grussling3675c8d2013-01-08 16:05:53 +000063 /* Configure the priority mapping registers. */
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000064 ret = mv88e6xxx_config_prio(ds);
65 if (ret < 0)
66 return ret;
67
Barry Grussling3675c8d2013-01-08 16:05:53 +000068 /* Set the VLAN ethertype to 0x8100. */
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000069 REG_WRITE(REG_GLOBAL, 0x19, 0x8100);
70
Barry Grussling3675c8d2013-01-08 16:05:53 +000071 /* Disable ARP mirroring, and configure the upstream port as
Lennert Buytenheke84665c2009-03-20 09:52:09 +000072 * the port to which ingress and egress monitor frames are to
73 * be sent.
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000074 */
Lennert Buytenheke84665c2009-03-20 09:52:09 +000075 REG_WRITE(REG_GLOBAL, 0x1a, (dsa_upstream_port(ds) * 0x1100) | 0x00f0);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000076
Barry Grussling3675c8d2013-01-08 16:05:53 +000077 /* Disable cascade port functionality unless this device
Barry Grussling81399ec2011-06-24 19:53:51 +000078 * is used in a cascade configuration, and set the switch's
Lennert Buytenheke84665c2009-03-20 09:52:09 +000079 * DSA device number.
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000080 */
Barry Grussling81399ec2011-06-24 19:53:51 +000081 if (ds->dst->pd->nr_chips > 1)
82 REG_WRITE(REG_GLOBAL, 0x1c, 0xf000 | (ds->index & 0x1f));
83 else
84 REG_WRITE(REG_GLOBAL, 0x1c, 0xe000 | (ds->index & 0x1f));
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000085
Barry Grussling3675c8d2013-01-08 16:05:53 +000086 /* Send all frames with destination addresses matching
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000087 * 01:80:c2:00:00:0x to the CPU port.
88 */
89 REG_WRITE(REG_GLOBAL2, 0x03, 0xffff);
90
Barry Grussling3675c8d2013-01-08 16:05:53 +000091 /* Ignore removed tag data on doubly tagged packets, disable
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000092 * flow control messages, force flow control priority to the
93 * highest, and send all special multicast frames to the CPU
Lucas De Marchi25985ed2011-03-30 22:57:33 -030094 * port at the highest priority.
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000095 */
96 REG_WRITE(REG_GLOBAL2, 0x05, 0x00ff);
97
Barry Grussling3675c8d2013-01-08 16:05:53 +000098 /* Program the DSA routing table. */
Lennert Buytenheke84665c2009-03-20 09:52:09 +000099 for (i = 0; i < 32; i++) {
100 int nexthop;
101
102 nexthop = 0x1f;
Tobias Waldekranz6e0ba472015-02-05 14:52:06 +0100103 if (ds->pd->rtable &&
104 i != ds->index && i < ds->dst->pd->nr_chips)
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000105 nexthop = ds->pd->rtable[i] & 0x1f;
106
107 REG_WRITE(REG_GLOBAL2, 0x06, 0x8000 | (i << 8) | nexthop);
108 }
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000109
Barry Grussling3675c8d2013-01-08 16:05:53 +0000110 /* Clear all trunk masks. */
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000111 for (i = 0; i < 8; i++)
Lennert Buytenhek076d3e12009-03-20 09:50:39 +0000112 REG_WRITE(REG_GLOBAL2, 0x07, 0x8000 | (i << 12) | 0x7ff);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000113
Barry Grussling3675c8d2013-01-08 16:05:53 +0000114 /* Clear all trunk mappings. */
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000115 for (i = 0; i < 16; i++)
116 REG_WRITE(REG_GLOBAL2, 0x08, 0x8000 | (i << 11));
117
Barry Grussling3675c8d2013-01-08 16:05:53 +0000118 /* Force the priority of IGMP/MLD snoop frames and ARP frames
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000119 * to the highest setting.
120 */
121 REG_WRITE(REG_GLOBAL2, 0x0f, 0x00ff);
122
123 return 0;
124}
125
126static int mv88e6131_setup_port(struct dsa_switch *ds, int p)
127{
Florian Fainellia22adce2014-04-28 11:14:28 -0700128 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000129 int addr = REG_PORT(p);
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000130 u16 val;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000131
Barry Grussling3675c8d2013-01-08 16:05:53 +0000132 /* MAC Forcing register: don't force link, speed, duplex
Lennert Buytenhek076d3e12009-03-20 09:50:39 +0000133 * or flow control state to any particular values on physical
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000134 * ports, but force the CPU port and all DSA ports to 1000 Mb/s
Peter Korsgaardec80bfc2011-04-05 03:03:56 +0000135 * (100 Mb/s on 6085) full duplex.
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000136 */
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000137 if (dsa_is_cpu_port(ds, p) || ds->dsa_port_mask & (1 << p))
Peter Korsgaardec80bfc2011-04-05 03:03:56 +0000138 if (ps->id == ID_6085)
139 REG_WRITE(addr, 0x01, 0x003d); /* 100 Mb/s */
140 else
141 REG_WRITE(addr, 0x01, 0x003e); /* 1000 Mb/s */
Lennert Buytenhek076d3e12009-03-20 09:50:39 +0000142 else
143 REG_WRITE(addr, 0x01, 0x0003);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000144
Barry Grussling3675c8d2013-01-08 16:05:53 +0000145 /* Port Control: disable Core Tag, disable Drop-on-Lock,
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000146 * transmit frames unmodified, disable Header mode,
147 * enable IGMP/MLD snoop, disable DoubleTag, disable VLAN
148 * tunneling, determine priority by looking at 802.1p and
149 * IP priority fields (IP prio has precedence), and set STP
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000150 * state to Forwarding.
151 *
152 * If this is the upstream port for this switch, enable
153 * forwarding of unknown unicasts, and enable DSA tagging
154 * mode.
155 *
156 * If this is the link to another switch, use DSA tagging
157 * mode, but do not enable forwarding of unknown unicasts.
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000158 */
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000159 val = 0x0433;
Peter Korsgaardb3b27002011-04-26 01:45:41 +0000160 if (p == dsa_upstream_port(ds)) {
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000161 val |= 0x0104;
Barry Grussling3675c8d2013-01-08 16:05:53 +0000162 /* On 6085, unknown multicast forward is controlled
Peter Korsgaardb3b27002011-04-26 01:45:41 +0000163 * here rather than in Port Control 2 register.
164 */
165 if (ps->id == ID_6085)
166 val |= 0x0008;
167 }
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000168 if (ds->dsa_port_mask & (1 << p))
169 val |= 0x0100;
170 REG_WRITE(addr, 0x04, val);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000171
Barry Grussling3675c8d2013-01-08 16:05:53 +0000172 /* Port Control 2: don't force a good FCS, don't use
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000173 * VLAN-based, source address-based or destination
174 * address-based priority overrides, don't let the switch
175 * add or strip 802.1q tags, don't discard tagged or
176 * untagged frames on this port, do a destination address
177 * lookup on received packets as usual, don't send a copy
178 * of all transmitted/received frames on this port to the
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000179 * CPU, and configure the upstream port number.
180 *
181 * If this is the upstream port for this switch, enable
182 * forwarding of unknown multicast addresses.
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000183 */
Peter Korsgaardb3b27002011-04-26 01:45:41 +0000184 if (ps->id == ID_6085)
Barry Grussling3675c8d2013-01-08 16:05:53 +0000185 /* on 6085, bits 3:0 are reserved, bit 6 control ARP
Peter Korsgaardb3b27002011-04-26 01:45:41 +0000186 * mirroring, and multicast forward is handled in
187 * Port Control register.
188 */
189 REG_WRITE(addr, 0x08, 0x0080);
190 else {
191 val = 0x0080 | dsa_upstream_port(ds);
192 if (p == dsa_upstream_port(ds))
193 val |= 0x0040;
194 REG_WRITE(addr, 0x08, val);
195 }
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000196
Barry Grussling3675c8d2013-01-08 16:05:53 +0000197 /* Rate Control: disable ingress rate limiting. */
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000198 REG_WRITE(addr, 0x09, 0x0000);
199
Barry Grussling3675c8d2013-01-08 16:05:53 +0000200 /* Rate Control 2: disable egress rate limiting. */
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000201 REG_WRITE(addr, 0x0a, 0x0000);
202
Barry Grussling3675c8d2013-01-08 16:05:53 +0000203 /* Port Association Vector: when learning source addresses
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000204 * of packets, add the address to the address database using
205 * a port bitmap that has only the bit for this port set and
206 * the other bits clear.
207 */
208 REG_WRITE(addr, 0x0b, 1 << p);
209
Barry Grussling3675c8d2013-01-08 16:05:53 +0000210 /* Tag Remap: use an identity 802.1p prio -> switch prio
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000211 * mapping.
212 */
213 REG_WRITE(addr, 0x18, 0x3210);
214
Barry Grussling3675c8d2013-01-08 16:05:53 +0000215 /* Tag Remap 2: use an identity 802.1p prio -> switch prio
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000216 * mapping.
217 */
218 REG_WRITE(addr, 0x19, 0x7654);
219
Guenter Roeck0d65da42015-04-02 04:06:29 +0200220 return mv88e6xxx_setup_port_common(ds, p);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000221}
222
223static int mv88e6131_setup(struct dsa_switch *ds)
224{
Guenter Roeckd1988932015-04-02 04:06:31 +0200225 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000226 int i;
227 int ret;
228
Guenter Roeck0d65da42015-04-02 04:06:29 +0200229 ret = mv88e6xxx_setup_common(ds);
230 if (ret < 0)
231 return ret;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000232
Guenter Roeck0d65da42015-04-02 04:06:29 +0200233 mv88e6xxx_ppu_state_init(ds);
Peter Korsgaardec80bfc2011-04-05 03:03:56 +0000234
Guenter Roeckd1988932015-04-02 04:06:31 +0200235 switch (ps->id) {
236 case ID_6085:
237 ps->num_ports = 10;
238 break;
239 case ID_6095:
240 ps->num_ports = 11;
241 break;
242 case ID_6131:
243 case ID_6131_B2:
244 ps->num_ports = 8;
245 break;
246 default:
247 return -ENODEV;
248 }
249
Andrew Lunn143a8302015-04-02 04:06:34 +0200250 ret = mv88e6xxx_switch_reset(ds, false);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000251 if (ret < 0)
252 return ret;
253
254 /* @@@ initialise vtu and atu */
255
256 ret = mv88e6131_setup_global(ds);
257 if (ret < 0)
258 return ret;
259
Guenter Roeckd1988932015-04-02 04:06:31 +0200260 for (i = 0; i < ps->num_ports; i++) {
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000261 ret = mv88e6131_setup_port(ds, i);
262 if (ret < 0)
263 return ret;
264 }
265
266 return 0;
267}
268
Guenter Roeckd1988932015-04-02 04:06:31 +0200269static int mv88e6131_port_to_phy_addr(struct dsa_switch *ds, int port)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000270{
Guenter Roeckd1988932015-04-02 04:06:31 +0200271 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
272
273 if (port >= 0 && port < ps->num_ports)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000274 return port;
Guenter Roeckd1988932015-04-02 04:06:31 +0200275
276 return -EINVAL;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000277}
278
279static int
280mv88e6131_phy_read(struct dsa_switch *ds, int port, int regnum)
281{
Guenter Roeckd1988932015-04-02 04:06:31 +0200282 int addr = mv88e6131_port_to_phy_addr(ds, port);
283
284 if (addr < 0)
285 return addr;
286
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000287 return mv88e6xxx_phy_read_ppu(ds, addr, regnum);
288}
289
290static int
291mv88e6131_phy_write(struct dsa_switch *ds,
292 int port, int regnum, u16 val)
293{
Guenter Roeckd1988932015-04-02 04:06:31 +0200294 int addr = mv88e6131_port_to_phy_addr(ds, port);
295
296 if (addr < 0)
297 return addr;
298
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000299 return mv88e6xxx_phy_write_ppu(ds, addr, regnum, val);
300}
301
Ben Hutchings98e67302011-11-25 14:36:19 +0000302struct dsa_switch_driver mv88e6131_switch_driver = {
Florian Fainelliac7a04c2014-09-11 21:18:09 -0700303 .tag_protocol = DSA_TAG_PROTO_DSA,
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000304 .priv_size = sizeof(struct mv88e6xxx_priv_state),
305 .probe = mv88e6131_probe,
306 .setup = mv88e6131_setup,
307 .set_addr = mv88e6xxx_set_addr_direct,
308 .phy_read = mv88e6131_phy_read,
309 .phy_write = mv88e6131_phy_write,
310 .poll_link = mv88e6xxx_poll_link,
Andrew Lunne413e7e2015-04-02 04:06:38 +0200311 .get_strings = mv88e6xxx_get_strings,
312 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
313 .get_sset_count = mv88e6xxx_get_sset_count,
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000314};
Ben Hutchings3d825ed2011-11-25 14:37:16 +0000315
316MODULE_ALIAS("platform:mv88e6085");
317MODULE_ALIAS("platform:mv88e6095");
318MODULE_ALIAS("platform:mv88e6095f");
319MODULE_ALIAS("platform:mv88e6131");