1 /* net/dsa/mv88e6171.c - Marvell 88e6171/8826172 switch chip support
2 * Copyright (c) 2008-2009 Marvell Semiconductor
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.
11 #include <linux/delay.h>
12 #include <linux/jiffies.h>
13 #include <linux/list.h>
14 #include <linux/module.h>
15 #include <linux/netdevice.h>
16 #include <linux/phy.h>
18 #include "mv88e6xxx.h"
20 static char *mv88e6171_probe(struct device *host_dev, int sw_addr)
22 struct mii_bus *bus = dsa_host_dev_to_mii_bus(host_dev);
28 ret = __mv88e6xxx_reg_read(bus, sw_addr, REG_PORT(0), 0x03);
30 if ((ret & 0xfff0) == 0x1710)
31 return "Marvell 88E6171";
32 if ((ret & 0xfff0) == 0x1720)
33 return "Marvell 88E6172";
39 static int mv88e6171_switch_reset(struct dsa_switch *ds)
43 unsigned long timeout;
45 /* Set all ports to the disabled state. */
46 for (i = 0; i < 8; i++) {
47 ret = REG_READ(REG_PORT(i), 0x04);
48 REG_WRITE(REG_PORT(i), 0x04, ret & 0xfffc);
51 /* Wait for transmit queues to drain. */
52 usleep_range(2000, 4000);
54 /* Reset the switch. */
55 REG_WRITE(REG_GLOBAL, 0x04, 0xc400);
57 /* Wait up to one second for reset to complete. */
58 timeout = jiffies + 1 * HZ;
59 while (time_before(jiffies, timeout)) {
60 ret = REG_READ(REG_GLOBAL, 0x00);
61 if ((ret & 0xc800) == 0xc800)
64 usleep_range(1000, 2000);
66 if (time_after(jiffies, timeout))
69 /* Enable ports not under DSA, e.g. WAN port */
70 for (i = 0; i < 8; i++) {
71 if (dsa_is_cpu_port(ds, i) || ds->phys_port_mask & (1 << i))
74 ret = REG_READ(REG_PORT(i), 0x04);
75 REG_WRITE(REG_PORT(i), 0x04, ret | 0x03);
81 static int mv88e6171_setup_global(struct dsa_switch *ds)
86 /* Disable the PHY polling unit (since there won't be any
87 * external PHYs to poll), don't discard packets with
88 * excessive collisions, and mask all interrupt sources.
90 REG_WRITE(REG_GLOBAL, 0x04, 0x0000);
92 /* Set the default address aging time to 5 minutes, and
93 * enable address learn messages to be sent to all message
96 REG_WRITE(REG_GLOBAL, 0x0a, 0x0148);
98 /* Configure the priority mapping registers. */
99 ret = mv88e6xxx_config_prio(ds);
103 /* Configure the upstream port, and configure the upstream
104 * port as the port to which ingress and egress monitor frames
107 if (REG_READ(REG_PORT(0), 0x03) == 0x1710)
108 REG_WRITE(REG_GLOBAL, 0x1a, (dsa_upstream_port(ds) * 0x1111));
110 REG_WRITE(REG_GLOBAL, 0x1a, (dsa_upstream_port(ds) * 0x1110));
112 /* Disable remote management for now, and set the switch's
115 REG_WRITE(REG_GLOBAL, 0x1c, ds->index & 0x1f);
117 /* Send all frames with destination addresses matching
118 * 01:80:c2:00:00:2x to the CPU port.
120 REG_WRITE(REG_GLOBAL2, 0x02, 0xffff);
122 /* Send all frames with destination addresses matching
123 * 01:80:c2:00:00:0x to the CPU port.
125 REG_WRITE(REG_GLOBAL2, 0x03, 0xffff);
127 /* Disable the loopback filter, disable flow control
128 * messages, disable flood broadcast override, disable
129 * removing of provider tags, disable ATU age violation
130 * interrupts, disable tag flow control, force flow
131 * control priority to the highest, and send all special
132 * multicast frames to the CPU at the highest priority.
134 REG_WRITE(REG_GLOBAL2, 0x05, 0x00ff);
136 /* Program the DSA routing table. */
137 for (i = 0; i < 32; i++) {
141 if (i != ds->index && i < ds->dst->pd->nr_chips)
142 nexthop = ds->pd->rtable[i] & 0x1f;
144 REG_WRITE(REG_GLOBAL2, 0x06, 0x8000 | (i << 8) | nexthop);
147 /* Clear all trunk masks. */
148 for (i = 0; i < 8; i++)
149 REG_WRITE(REG_GLOBAL2, 0x07, 0x8000 | (i << 12) | 0xff);
151 /* Clear all trunk mappings. */
152 for (i = 0; i < 16; i++)
153 REG_WRITE(REG_GLOBAL2, 0x08, 0x8000 | (i << 11));
155 /* Disable ingress rate limiting by resetting all ingress
156 * rate limit registers to their initial state.
158 for (i = 0; i < 6; i++)
159 REG_WRITE(REG_GLOBAL2, 0x09, 0x9000 | (i << 8));
161 /* Initialise cross-chip port VLAN table to reset defaults. */
162 REG_WRITE(REG_GLOBAL2, 0x0b, 0x9000);
164 /* Clear the priority override table. */
165 for (i = 0; i < 16; i++)
166 REG_WRITE(REG_GLOBAL2, 0x0f, 0x8000 | (i << 8));
168 /* @@@ initialise AVB (22/23) watchdog (27) sdet (29) registers */
173 static int mv88e6171_setup_port(struct dsa_switch *ds, int p)
175 int addr = REG_PORT(p);
178 /* MAC Forcing register: don't force link, speed, duplex
179 * or flow control state to any particular values on physical
180 * ports, but force the CPU port and all DSA ports to 1000 Mb/s
183 val = REG_READ(addr, 0x01);
184 if (dsa_is_cpu_port(ds, p) || ds->dsa_port_mask & (1 << p))
185 REG_WRITE(addr, 0x01, val | 0x003e);
187 REG_WRITE(addr, 0x01, val | 0x0003);
189 /* Do not limit the period of time that this port can be
190 * paused for by the remote end or the period of time that
191 * this port can pause the remote end.
193 REG_WRITE(addr, 0x02, 0x0000);
195 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
196 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
197 * tunneling, determine priority by looking at 802.1p and IP
198 * priority fields (IP prio has precedence), and set STP state
201 * If this is the CPU link, use DSA or EDSA tagging depending
202 * on which tagging mode was configured.
204 * If this is a link to another switch, use DSA tagging mode.
206 * If this is the upstream port for this switch, enable
207 * forwarding of unknown unicasts and multicasts.
210 if (dsa_is_cpu_port(ds, p)) {
211 if (ds->dst->tag_protocol == DSA_TAG_PROTO_EDSA)
216 if (ds->dsa_port_mask & (1 << p))
218 if (p == dsa_upstream_port(ds))
220 REG_WRITE(addr, 0x04, val);
222 /* Port Control 1: disable trunking. Also, if this is the
223 * CPU port, enable learn messages to be sent to this port.
225 REG_WRITE(addr, 0x05, dsa_is_cpu_port(ds, p) ? 0x8000 : 0x0000);
227 /* Port based VLAN map: give each port its own address
228 * database, allow the CPU port to talk to each of the 'real'
229 * ports, and allow each of the 'real' ports to only talk to
232 val = (p & 0xf) << 12;
233 if (dsa_is_cpu_port(ds, p))
234 val |= ds->phys_port_mask;
236 val |= 1 << dsa_upstream_port(ds);
237 REG_WRITE(addr, 0x06, val);
239 /* Default VLAN ID and priority: don't set a default VLAN
240 * ID, and set the default packet priority to zero.
242 REG_WRITE(addr, 0x07, 0x0000);
244 /* Port Control 2: don't force a good FCS, set the maximum
245 * frame size to 10240 bytes, don't let the switch add or
246 * strip 802.1q tags, don't discard tagged or untagged frames
247 * on this port, do a destination address lookup on all
248 * received packets as usual, disable ARP mirroring and don't
249 * send a copy of all transmitted/received frames on this port
252 REG_WRITE(addr, 0x08, 0x2080);
254 /* Egress rate control: disable egress rate control. */
255 REG_WRITE(addr, 0x09, 0x0001);
257 /* Egress rate control 2: disable egress rate control. */
258 REG_WRITE(addr, 0x0a, 0x0000);
260 /* Port Association Vector: when learning source addresses
261 * of packets, add the address to the address database using
262 * a port bitmap that has only the bit for this port set and
263 * the other bits clear.
265 REG_WRITE(addr, 0x0b, 1 << p);
267 /* Port ATU control: disable limiting the number of address
268 * database entries that this port is allowed to use.
270 REG_WRITE(addr, 0x0c, 0x0000);
272 /* Priority Override: disable DA, SA and VTU priority override. */
273 REG_WRITE(addr, 0x0d, 0x0000);
275 /* Port Ethertype: use the Ethertype DSA Ethertype value. */
276 REG_WRITE(addr, 0x0f, ETH_P_EDSA);
278 /* Tag Remap: use an identity 802.1p prio -> switch prio
281 REG_WRITE(addr, 0x18, 0x3210);
283 /* Tag Remap 2: use an identity 802.1p prio -> switch prio
286 REG_WRITE(addr, 0x19, 0x7654);
291 static int mv88e6171_setup(struct dsa_switch *ds)
293 struct mv88e6xxx_priv_state *ps = (void *)(ds + 1);
297 mutex_init(&ps->smi_mutex);
298 mutex_init(&ps->stats_mutex);
300 ret = mv88e6171_switch_reset(ds);
304 /* @@@ initialise vtu and atu */
306 ret = mv88e6171_setup_global(ds);
310 for (i = 0; i < 8; i++) {
311 if (!(dsa_is_cpu_port(ds, i) || ds->phys_port_mask & (1 << i)))
314 ret = mv88e6171_setup_port(ds, i);
319 mutex_init(&ps->phy_mutex);
324 static int mv88e6171_port_to_phy_addr(int port)
326 if (port >= 0 && port <= 4)
332 mv88e6171_phy_read(struct dsa_switch *ds, int port, int regnum)
334 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
335 int addr = mv88e6171_port_to_phy_addr(port);
338 mutex_lock(&ps->phy_mutex);
339 ret = mv88e6xxx_phy_read(ds, addr, regnum);
340 mutex_unlock(&ps->phy_mutex);
345 mv88e6171_phy_write(struct dsa_switch *ds,
346 int port, int regnum, u16 val)
348 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
349 int addr = mv88e6171_port_to_phy_addr(port);
352 mutex_lock(&ps->phy_mutex);
353 ret = mv88e6xxx_phy_write(ds, addr, regnum, val);
354 mutex_unlock(&ps->phy_mutex);
358 static struct mv88e6xxx_hw_stat mv88e6171_hw_stats[] = {
359 { "in_good_octets", 8, 0x00, },
360 { "in_bad_octets", 4, 0x02, },
361 { "in_unicast", 4, 0x04, },
362 { "in_broadcasts", 4, 0x06, },
363 { "in_multicasts", 4, 0x07, },
364 { "in_pause", 4, 0x16, },
365 { "in_undersize", 4, 0x18, },
366 { "in_fragments", 4, 0x19, },
367 { "in_oversize", 4, 0x1a, },
368 { "in_jabber", 4, 0x1b, },
369 { "in_rx_error", 4, 0x1c, },
370 { "in_fcs_error", 4, 0x1d, },
371 { "out_octets", 8, 0x0e, },
372 { "out_unicast", 4, 0x10, },
373 { "out_broadcasts", 4, 0x13, },
374 { "out_multicasts", 4, 0x12, },
375 { "out_pause", 4, 0x15, },
376 { "excessive", 4, 0x11, },
377 { "collisions", 4, 0x1e, },
378 { "deferred", 4, 0x05, },
379 { "single", 4, 0x14, },
380 { "multiple", 4, 0x17, },
381 { "out_fcs_error", 4, 0x03, },
382 { "late", 4, 0x1f, },
383 { "hist_64bytes", 4, 0x08, },
384 { "hist_65_127bytes", 4, 0x09, },
385 { "hist_128_255bytes", 4, 0x0a, },
386 { "hist_256_511bytes", 4, 0x0b, },
387 { "hist_512_1023bytes", 4, 0x0c, },
388 { "hist_1024_max_bytes", 4, 0x0d, },
392 mv88e6171_get_strings(struct dsa_switch *ds, int port, uint8_t *data)
394 mv88e6xxx_get_strings(ds, ARRAY_SIZE(mv88e6171_hw_stats),
395 mv88e6171_hw_stats, port, data);
399 mv88e6171_get_ethtool_stats(struct dsa_switch *ds,
400 int port, uint64_t *data)
402 mv88e6xxx_get_ethtool_stats(ds, ARRAY_SIZE(mv88e6171_hw_stats),
403 mv88e6171_hw_stats, port, data);
406 static int mv88e6171_get_sset_count(struct dsa_switch *ds)
408 return ARRAY_SIZE(mv88e6171_hw_stats);
411 struct dsa_switch_driver mv88e6171_switch_driver = {
412 .tag_protocol = DSA_TAG_PROTO_EDSA,
413 .priv_size = sizeof(struct mv88e6xxx_priv_state),
414 .probe = mv88e6171_probe,
415 .setup = mv88e6171_setup,
416 .set_addr = mv88e6xxx_set_addr_indirect,
417 .phy_read = mv88e6171_phy_read,
418 .phy_write = mv88e6171_phy_write,
419 .poll_link = mv88e6xxx_poll_link,
420 .get_strings = mv88e6171_get_strings,
421 .get_ethtool_stats = mv88e6171_get_ethtool_stats,
422 .get_sset_count = mv88e6171_get_sset_count,
423 #ifdef CONFIG_NET_DSA_HWMON
424 .get_temp = mv88e6xxx_get_temp,
426 .get_regs_len = mv88e6xxx_get_regs_len,
427 .get_regs = mv88e6xxx_get_regs,
430 MODULE_ALIAS("platform:mv88e6171");
431 MODULE_ALIAS("platform:mv88e6172");