blob: b613818875872dd08e63b8ace31ecb88ca2a278a [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
11#include <linux/list.h>
Paul Gortmaker2bbba272012-01-24 10:41:40 +000012#include <linux/module.h>
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000013#include <linux/netdevice.h>
14#include <linux/phy.h>
Ben Hutchingsc8f0b862011-11-27 17:06:08 +000015#include <net/dsa.h>
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000016#include "mv88e6xxx.h"
17
Barry Grussling3675c8d2013-01-08 16:05:53 +000018/* Switch product IDs */
Peter Korsgaardec80bfc2011-04-05 03:03:56 +000019#define ID_6085 0x04a0
20#define ID_6095 0x0950
21#define ID_6131 0x1060
22
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000023static char *mv88e6131_probe(struct mii_bus *bus, int sw_addr)
24{
25 int ret;
26
27 ret = __mv88e6xxx_reg_read(bus, sw_addr, REG_PORT(0), 0x03);
28 if (ret >= 0) {
29 ret &= 0xfff0;
Peter Korsgaardec80bfc2011-04-05 03:03:56 +000030 if (ret == ID_6085)
31 return "Marvell 88E6085";
32 if (ret == ID_6095)
Lennert Buytenhek076d3e12009-03-20 09:50:39 +000033 return "Marvell 88E6095/88E6095F";
Peter Korsgaardec80bfc2011-04-05 03:03:56 +000034 if (ret == ID_6131)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000035 return "Marvell 88E6131";
36 }
37
38 return NULL;
39}
40
41static int mv88e6131_switch_reset(struct dsa_switch *ds)
42{
43 int i;
44 int ret;
45
Barry Grussling3675c8d2013-01-08 16:05:53 +000046 /* Set all ports to the disabled state. */
Lennert Buytenhek076d3e12009-03-20 09:50:39 +000047 for (i = 0; i < 11; i++) {
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000048 ret = REG_READ(REG_PORT(i), 0x04);
49 REG_WRITE(REG_PORT(i), 0x04, ret & 0xfffc);
50 }
51
Barry Grussling3675c8d2013-01-08 16:05:53 +000052 /* Wait for transmit queues to drain. */
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000053 msleep(2);
54
Barry Grussling3675c8d2013-01-08 16:05:53 +000055 /* Reset the switch. */
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000056 REG_WRITE(REG_GLOBAL, 0x04, 0xc400);
57
Barry Grussling3675c8d2013-01-08 16:05:53 +000058 /* Wait up to one second for reset to complete. */
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000059 for (i = 0; i < 1000; i++) {
60 ret = REG_READ(REG_GLOBAL, 0x00);
61 if ((ret & 0xc800) == 0xc800)
62 break;
63
64 msleep(1);
65 }
66 if (i == 1000)
67 return -ETIMEDOUT;
68
69 return 0;
70}
71
72static int mv88e6131_setup_global(struct dsa_switch *ds)
73{
74 int ret;
75 int i;
76
Barry Grussling3675c8d2013-01-08 16:05:53 +000077 /* Enable the PHY polling unit, don't discard packets with
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000078 * excessive collisions, use a weighted fair queueing scheme
79 * to arbitrate between packet queues, set the maximum frame
80 * size to 1632, and mask all interrupt sources.
81 */
82 REG_WRITE(REG_GLOBAL, 0x04, 0x4400);
83
Barry Grussling3675c8d2013-01-08 16:05:53 +000084 /* Set the default address aging time to 5 minutes, and
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000085 * enable address learn messages to be sent to all message
86 * ports.
87 */
88 REG_WRITE(REG_GLOBAL, 0x0a, 0x0148);
89
Barry Grussling3675c8d2013-01-08 16:05:53 +000090 /* Configure the priority mapping registers. */
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000091 ret = mv88e6xxx_config_prio(ds);
92 if (ret < 0)
93 return ret;
94
Barry Grussling3675c8d2013-01-08 16:05:53 +000095 /* Set the VLAN ethertype to 0x8100. */
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000096 REG_WRITE(REG_GLOBAL, 0x19, 0x8100);
97
Barry Grussling3675c8d2013-01-08 16:05:53 +000098 /* Disable ARP mirroring, and configure the upstream port as
Lennert Buytenheke84665c2009-03-20 09:52:09 +000099 * the port to which ingress and egress monitor frames are to
100 * be sent.
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000101 */
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000102 REG_WRITE(REG_GLOBAL, 0x1a, (dsa_upstream_port(ds) * 0x1100) | 0x00f0);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000103
Barry Grussling3675c8d2013-01-08 16:05:53 +0000104 /* Disable cascade port functionality unless this device
Barry Grussling81399ec2011-06-24 19:53:51 +0000105 * is used in a cascade configuration, and set the switch's
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000106 * DSA device number.
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000107 */
Barry Grussling81399ec2011-06-24 19:53:51 +0000108 if (ds->dst->pd->nr_chips > 1)
109 REG_WRITE(REG_GLOBAL, 0x1c, 0xf000 | (ds->index & 0x1f));
110 else
111 REG_WRITE(REG_GLOBAL, 0x1c, 0xe000 | (ds->index & 0x1f));
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000112
Barry Grussling3675c8d2013-01-08 16:05:53 +0000113 /* Send all frames with destination addresses matching
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000114 * 01:80:c2:00:00:0x to the CPU port.
115 */
116 REG_WRITE(REG_GLOBAL2, 0x03, 0xffff);
117
Barry Grussling3675c8d2013-01-08 16:05:53 +0000118 /* Ignore removed tag data on doubly tagged packets, disable
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000119 * flow control messages, force flow control priority to the
120 * highest, and send all special multicast frames to the CPU
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300121 * port at the highest priority.
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000122 */
123 REG_WRITE(REG_GLOBAL2, 0x05, 0x00ff);
124
Barry Grussling3675c8d2013-01-08 16:05:53 +0000125 /* Program the DSA routing table. */
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000126 for (i = 0; i < 32; i++) {
127 int nexthop;
128
129 nexthop = 0x1f;
130 if (i != ds->index && i < ds->dst->pd->nr_chips)
131 nexthop = ds->pd->rtable[i] & 0x1f;
132
133 REG_WRITE(REG_GLOBAL2, 0x06, 0x8000 | (i << 8) | nexthop);
134 }
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000135
Barry Grussling3675c8d2013-01-08 16:05:53 +0000136 /* Clear all trunk masks. */
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000137 for (i = 0; i < 8; i++)
Lennert Buytenhek076d3e12009-03-20 09:50:39 +0000138 REG_WRITE(REG_GLOBAL2, 0x07, 0x8000 | (i << 12) | 0x7ff);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000139
Barry Grussling3675c8d2013-01-08 16:05:53 +0000140 /* Clear all trunk mappings. */
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000141 for (i = 0; i < 16; i++)
142 REG_WRITE(REG_GLOBAL2, 0x08, 0x8000 | (i << 11));
143
Barry Grussling3675c8d2013-01-08 16:05:53 +0000144 /* Force the priority of IGMP/MLD snoop frames and ARP frames
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000145 * to the highest setting.
146 */
147 REG_WRITE(REG_GLOBAL2, 0x0f, 0x00ff);
148
149 return 0;
150}
151
152static int mv88e6131_setup_port(struct dsa_switch *ds, int p)
153{
Peter Korsgaardec80bfc2011-04-05 03:03:56 +0000154 struct mv88e6xxx_priv_state *ps = (void *)(ds + 1);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000155 int addr = REG_PORT(p);
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000156 u16 val;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000157
Barry Grussling3675c8d2013-01-08 16:05:53 +0000158 /* MAC Forcing register: don't force link, speed, duplex
Lennert Buytenhek076d3e12009-03-20 09:50:39 +0000159 * or flow control state to any particular values on physical
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000160 * ports, but force the CPU port and all DSA ports to 1000 Mb/s
Peter Korsgaardec80bfc2011-04-05 03:03:56 +0000161 * (100 Mb/s on 6085) full duplex.
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000162 */
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000163 if (dsa_is_cpu_port(ds, p) || ds->dsa_port_mask & (1 << p))
Peter Korsgaardec80bfc2011-04-05 03:03:56 +0000164 if (ps->id == ID_6085)
165 REG_WRITE(addr, 0x01, 0x003d); /* 100 Mb/s */
166 else
167 REG_WRITE(addr, 0x01, 0x003e); /* 1000 Mb/s */
Lennert Buytenhek076d3e12009-03-20 09:50:39 +0000168 else
169 REG_WRITE(addr, 0x01, 0x0003);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000170
Barry Grussling3675c8d2013-01-08 16:05:53 +0000171 /* Port Control: disable Core Tag, disable Drop-on-Lock,
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000172 * transmit frames unmodified, disable Header mode,
173 * enable IGMP/MLD snoop, disable DoubleTag, disable VLAN
174 * tunneling, determine priority by looking at 802.1p and
175 * IP priority fields (IP prio has precedence), and set STP
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000176 * state to Forwarding.
177 *
178 * If this is the upstream port for this switch, enable
179 * forwarding of unknown unicasts, and enable DSA tagging
180 * mode.
181 *
182 * If this is the link to another switch, use DSA tagging
183 * mode, but do not enable forwarding of unknown unicasts.
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000184 */
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000185 val = 0x0433;
Peter Korsgaardb3b27002011-04-26 01:45:41 +0000186 if (p == dsa_upstream_port(ds)) {
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000187 val |= 0x0104;
Barry Grussling3675c8d2013-01-08 16:05:53 +0000188 /* On 6085, unknown multicast forward is controlled
Peter Korsgaardb3b27002011-04-26 01:45:41 +0000189 * here rather than in Port Control 2 register.
190 */
191 if (ps->id == ID_6085)
192 val |= 0x0008;
193 }
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000194 if (ds->dsa_port_mask & (1 << p))
195 val |= 0x0100;
196 REG_WRITE(addr, 0x04, val);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000197
Barry Grussling3675c8d2013-01-08 16:05:53 +0000198 /* Port Control 1: disable trunking. Also, if this is the
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000199 * CPU port, enable learn messages to be sent to this port.
200 */
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000201 REG_WRITE(addr, 0x05, dsa_is_cpu_port(ds, p) ? 0x8000 : 0x0000);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000202
Barry Grussling3675c8d2013-01-08 16:05:53 +0000203 /* Port based VLAN map: give each port its own address
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000204 * database, allow the CPU port to talk to each of the 'real'
205 * ports, and allow each of the 'real' ports to only talk to
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000206 * the upstream port.
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000207 */
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000208 val = (p & 0xf) << 12;
209 if (dsa_is_cpu_port(ds, p))
210 val |= ds->phys_port_mask;
211 else
212 val |= 1 << dsa_upstream_port(ds);
213 REG_WRITE(addr, 0x06, val);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000214
Barry Grussling3675c8d2013-01-08 16:05:53 +0000215 /* Default VLAN ID and priority: don't set a default VLAN
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000216 * ID, and set the default packet priority to zero.
217 */
218 REG_WRITE(addr, 0x07, 0x0000);
219
Barry Grussling3675c8d2013-01-08 16:05:53 +0000220 /* Port Control 2: don't force a good FCS, don't use
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000221 * VLAN-based, source address-based or destination
222 * address-based priority overrides, don't let the switch
223 * add or strip 802.1q tags, don't discard tagged or
224 * untagged frames on this port, do a destination address
225 * lookup on received packets as usual, don't send a copy
226 * of all transmitted/received frames on this port to the
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000227 * CPU, and configure the upstream port number.
228 *
229 * If this is the upstream port for this switch, enable
230 * forwarding of unknown multicast addresses.
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000231 */
Peter Korsgaardb3b27002011-04-26 01:45:41 +0000232 if (ps->id == ID_6085)
Barry Grussling3675c8d2013-01-08 16:05:53 +0000233 /* on 6085, bits 3:0 are reserved, bit 6 control ARP
Peter Korsgaardb3b27002011-04-26 01:45:41 +0000234 * mirroring, and multicast forward is handled in
235 * Port Control register.
236 */
237 REG_WRITE(addr, 0x08, 0x0080);
238 else {
239 val = 0x0080 | dsa_upstream_port(ds);
240 if (p == dsa_upstream_port(ds))
241 val |= 0x0040;
242 REG_WRITE(addr, 0x08, val);
243 }
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000244
Barry Grussling3675c8d2013-01-08 16:05:53 +0000245 /* Rate Control: disable ingress rate limiting. */
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000246 REG_WRITE(addr, 0x09, 0x0000);
247
Barry Grussling3675c8d2013-01-08 16:05:53 +0000248 /* Rate Control 2: disable egress rate limiting. */
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000249 REG_WRITE(addr, 0x0a, 0x0000);
250
Barry Grussling3675c8d2013-01-08 16:05:53 +0000251 /* Port Association Vector: when learning source addresses
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000252 * of packets, add the address to the address database using
253 * a port bitmap that has only the bit for this port set and
254 * the other bits clear.
255 */
256 REG_WRITE(addr, 0x0b, 1 << p);
257
Barry Grussling3675c8d2013-01-08 16:05:53 +0000258 /* Tag Remap: use an identity 802.1p prio -> switch prio
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000259 * mapping.
260 */
261 REG_WRITE(addr, 0x18, 0x3210);
262
Barry Grussling3675c8d2013-01-08 16:05:53 +0000263 /* Tag Remap 2: use an identity 802.1p prio -> switch prio
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000264 * mapping.
265 */
266 REG_WRITE(addr, 0x19, 0x7654);
267
268 return 0;
269}
270
271static int mv88e6131_setup(struct dsa_switch *ds)
272{
273 struct mv88e6xxx_priv_state *ps = (void *)(ds + 1);
274 int i;
275 int ret;
276
277 mutex_init(&ps->smi_mutex);
278 mv88e6xxx_ppu_state_init(ds);
279 mutex_init(&ps->stats_mutex);
280
Peter Korsgaardec80bfc2011-04-05 03:03:56 +0000281 ps->id = REG_READ(REG_PORT(0), 0x03) & 0xfff0;
282
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000283 ret = mv88e6131_switch_reset(ds);
284 if (ret < 0)
285 return ret;
286
287 /* @@@ initialise vtu and atu */
288
289 ret = mv88e6131_setup_global(ds);
290 if (ret < 0)
291 return ret;
292
Lennert Buytenhek076d3e12009-03-20 09:50:39 +0000293 for (i = 0; i < 11; i++) {
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000294 ret = mv88e6131_setup_port(ds, i);
295 if (ret < 0)
296 return ret;
297 }
298
299 return 0;
300}
301
302static int mv88e6131_port_to_phy_addr(int port)
303{
Lennert Buytenhek076d3e12009-03-20 09:50:39 +0000304 if (port >= 0 && port <= 11)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000305 return port;
306 return -1;
307}
308
309static int
310mv88e6131_phy_read(struct dsa_switch *ds, int port, int regnum)
311{
312 int addr = mv88e6131_port_to_phy_addr(port);
313 return mv88e6xxx_phy_read_ppu(ds, addr, regnum);
314}
315
316static int
317mv88e6131_phy_write(struct dsa_switch *ds,
318 int port, int regnum, u16 val)
319{
320 int addr = mv88e6131_port_to_phy_addr(port);
321 return mv88e6xxx_phy_write_ppu(ds, addr, regnum, val);
322}
323
324static struct mv88e6xxx_hw_stat mv88e6131_hw_stats[] = {
325 { "in_good_octets", 8, 0x00, },
326 { "in_bad_octets", 4, 0x02, },
327 { "in_unicast", 4, 0x04, },
328 { "in_broadcasts", 4, 0x06, },
329 { "in_multicasts", 4, 0x07, },
330 { "in_pause", 4, 0x16, },
331 { "in_undersize", 4, 0x18, },
332 { "in_fragments", 4, 0x19, },
333 { "in_oversize", 4, 0x1a, },
334 { "in_jabber", 4, 0x1b, },
335 { "in_rx_error", 4, 0x1c, },
336 { "in_fcs_error", 4, 0x1d, },
337 { "out_octets", 8, 0x0e, },
338 { "out_unicast", 4, 0x10, },
339 { "out_broadcasts", 4, 0x13, },
340 { "out_multicasts", 4, 0x12, },
341 { "out_pause", 4, 0x15, },
342 { "excessive", 4, 0x11, },
343 { "collisions", 4, 0x1e, },
344 { "deferred", 4, 0x05, },
345 { "single", 4, 0x14, },
346 { "multiple", 4, 0x17, },
347 { "out_fcs_error", 4, 0x03, },
348 { "late", 4, 0x1f, },
349 { "hist_64bytes", 4, 0x08, },
350 { "hist_65_127bytes", 4, 0x09, },
351 { "hist_128_255bytes", 4, 0x0a, },
352 { "hist_256_511bytes", 4, 0x0b, },
353 { "hist_512_1023bytes", 4, 0x0c, },
354 { "hist_1024_max_bytes", 4, 0x0d, },
355};
356
357static void
358mv88e6131_get_strings(struct dsa_switch *ds, int port, uint8_t *data)
359{
360 mv88e6xxx_get_strings(ds, ARRAY_SIZE(mv88e6131_hw_stats),
361 mv88e6131_hw_stats, port, data);
362}
363
364static void
365mv88e6131_get_ethtool_stats(struct dsa_switch *ds,
366 int port, uint64_t *data)
367{
368 mv88e6xxx_get_ethtool_stats(ds, ARRAY_SIZE(mv88e6131_hw_stats),
369 mv88e6131_hw_stats, port, data);
370}
371
372static int mv88e6131_get_sset_count(struct dsa_switch *ds)
373{
374 return ARRAY_SIZE(mv88e6131_hw_stats);
375}
376
Ben Hutchings98e67302011-11-25 14:36:19 +0000377struct dsa_switch_driver mv88e6131_switch_driver = {
Harvey Harrison09640e62009-02-01 00:45:17 -0800378 .tag_protocol = cpu_to_be16(ETH_P_DSA),
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000379 .priv_size = sizeof(struct mv88e6xxx_priv_state),
380 .probe = mv88e6131_probe,
381 .setup = mv88e6131_setup,
382 .set_addr = mv88e6xxx_set_addr_direct,
383 .phy_read = mv88e6131_phy_read,
384 .phy_write = mv88e6131_phy_write,
385 .poll_link = mv88e6xxx_poll_link,
386 .get_strings = mv88e6131_get_strings,
387 .get_ethtool_stats = mv88e6131_get_ethtool_stats,
388 .get_sset_count = mv88e6131_get_sset_count,
389};
Ben Hutchings3d825ed2011-11-25 14:37:16 +0000390
391MODULE_ALIAS("platform:mv88e6085");
392MODULE_ALIAS("platform:mv88e6095");
393MODULE_ALIAS("platform:mv88e6095f");
394MODULE_ALIAS("platform:mv88e6131");