1 /* net/dsa/mv88e6171.c - Marvell 88e6171/8826172 switch chip support
2 * Copyright (c) 2008-2009 Marvell Semiconductor
3 * Copyright (c) 2014 Claudio Leite <leitec@staticky.com>
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), PORT_SWITCH_ID
);
30 if ((ret
& 0xfff0) == PORT_SWITCH_ID_6171
)
31 return "Marvell 88E6171";
32 if ((ret
& 0xfff0) == PORT_SWITCH_ID_6172
)
33 return "Marvell 88E6172";
39 static int mv88e6171_setup_global(struct dsa_switch
*ds
)
41 struct mv88e6xxx_priv_state
*ps
= ds_to_priv(ds
);
45 /* Discard packets with excessive collisions, mask all
46 * interrupt sources, enable PPU.
48 REG_WRITE(REG_GLOBAL
, 0x04, 0x6000);
50 /* Set the default address aging time to 5 minutes, and
51 * enable address learn messages to be sent to all message
54 REG_WRITE(REG_GLOBAL
, 0x0a, 0x0148);
56 /* Configure the priority mapping registers. */
57 ret
= mv88e6xxx_config_prio(ds
);
61 /* Configure the upstream port, and configure the upstream
62 * port as the port to which ingress and egress monitor frames
65 if (REG_READ(REG_PORT(0), 0x03) == 0x1710)
66 REG_WRITE(REG_GLOBAL
, 0x1a, (dsa_upstream_port(ds
) * 0x1111));
68 REG_WRITE(REG_GLOBAL
, 0x1a, (dsa_upstream_port(ds
) * 0x1110));
70 /* Disable remote management for now, and set the switch's
73 REG_WRITE(REG_GLOBAL
, 0x1c, ds
->index
& 0x1f);
75 /* Send all frames with destination addresses matching
76 * 01:80:c2:00:00:2x to the CPU port.
78 REG_WRITE(REG_GLOBAL2
, 0x02, 0xffff);
80 /* Send all frames with destination addresses matching
81 * 01:80:c2:00:00:0x to the CPU port.
83 REG_WRITE(REG_GLOBAL2
, 0x03, 0xffff);
85 /* Disable the loopback filter, disable flow control
86 * messages, disable flood broadcast override, disable
87 * removing of provider tags, disable ATU age violation
88 * interrupts, disable tag flow control, force flow
89 * control priority to the highest, and send all special
90 * multicast frames to the CPU at the highest priority.
92 REG_WRITE(REG_GLOBAL2
, 0x05, 0x00ff);
94 /* Program the DSA routing table. */
95 for (i
= 0; i
< 32; i
++) {
99 if (i
!= ds
->index
&& i
< ds
->dst
->pd
->nr_chips
)
100 nexthop
= ds
->pd
->rtable
[i
] & 0x1f;
102 REG_WRITE(REG_GLOBAL2
, 0x06, 0x8000 | (i
<< 8) | nexthop
);
105 /* Clear all trunk masks. */
106 for (i
= 0; i
< ps
->num_ports
; i
++)
107 REG_WRITE(REG_GLOBAL2
, 0x07, 0x8000 | (i
<< 12) | 0xff);
109 /* Clear all trunk mappings. */
110 for (i
= 0; i
< 16; i
++)
111 REG_WRITE(REG_GLOBAL2
, 0x08, 0x8000 | (i
<< 11));
113 /* Disable ingress rate limiting by resetting all ingress
114 * rate limit registers to their initial state.
116 for (i
= 0; i
< 6; i
++)
117 REG_WRITE(REG_GLOBAL2
, 0x09, 0x9000 | (i
<< 8));
119 /* Initialise cross-chip port VLAN table to reset defaults. */
120 REG_WRITE(REG_GLOBAL2
, 0x0b, 0x9000);
122 /* Clear the priority override table. */
123 for (i
= 0; i
< 16; i
++)
124 REG_WRITE(REG_GLOBAL2
, 0x0f, 0x8000 | (i
<< 8));
126 /* @@@ initialise AVB (22/23) watchdog (27) sdet (29) registers */
131 static int mv88e6171_setup_port(struct dsa_switch
*ds
, int p
)
133 int addr
= REG_PORT(p
);
136 /* MAC Forcing register: don't force link, speed, duplex
137 * or flow control state to any particular values on physical
138 * ports, but force the CPU port and all DSA ports to 1000 Mb/s
141 val
= REG_READ(addr
, 0x01);
142 if (dsa_is_cpu_port(ds
, p
) || ds
->dsa_port_mask
& (1 << p
))
143 REG_WRITE(addr
, 0x01, val
| 0x003e);
145 REG_WRITE(addr
, 0x01, val
| 0x0003);
147 /* Do not limit the period of time that this port can be
148 * paused for by the remote end or the period of time that
149 * this port can pause the remote end.
151 REG_WRITE(addr
, 0x02, 0x0000);
153 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
154 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
155 * tunneling, determine priority by looking at 802.1p and IP
156 * priority fields (IP prio has precedence), and set STP state
159 * If this is the CPU link, use DSA or EDSA tagging depending
160 * on which tagging mode was configured.
162 * If this is a link to another switch, use DSA tagging mode.
164 * If this is the upstream port for this switch, enable
165 * forwarding of unknown unicasts and multicasts.
168 if (dsa_is_cpu_port(ds
, p
)) {
169 if (ds
->dst
->tag_protocol
== DSA_TAG_PROTO_EDSA
)
174 if (ds
->dsa_port_mask
& (1 << p
))
176 if (p
== dsa_upstream_port(ds
))
178 REG_WRITE(addr
, 0x04, val
);
180 /* Port Control 2: don't force a good FCS, set the maximum
181 * frame size to 10240 bytes, don't let the switch add or
182 * strip 802.1q tags, don't discard tagged or untagged frames
183 * on this port, do a destination address lookup on all
184 * received packets as usual, disable ARP mirroring and don't
185 * send a copy of all transmitted/received frames on this port
188 REG_WRITE(addr
, 0x08, 0x2080);
190 /* Egress rate control: disable egress rate control. */
191 REG_WRITE(addr
, 0x09, 0x0001);
193 /* Egress rate control 2: disable egress rate control. */
194 REG_WRITE(addr
, 0x0a, 0x0000);
196 /* Port Association Vector: when learning source addresses
197 * of packets, add the address to the address database using
198 * a port bitmap that has only the bit for this port set and
199 * the other bits clear.
201 REG_WRITE(addr
, 0x0b, 1 << p
);
203 /* Port ATU control: disable limiting the number of address
204 * database entries that this port is allowed to use.
206 REG_WRITE(addr
, 0x0c, 0x0000);
208 /* Priority Override: disable DA, SA and VTU priority override. */
209 REG_WRITE(addr
, 0x0d, 0x0000);
211 /* Port Ethertype: use the Ethertype DSA Ethertype value. */
212 REG_WRITE(addr
, 0x0f, ETH_P_EDSA
);
214 /* Tag Remap: use an identity 802.1p prio -> switch prio
217 REG_WRITE(addr
, 0x18, 0x3210);
219 /* Tag Remap 2: use an identity 802.1p prio -> switch prio
222 REG_WRITE(addr
, 0x19, 0x7654);
224 return mv88e6xxx_setup_port_common(ds
, p
);
227 static int mv88e6171_setup(struct dsa_switch
*ds
)
229 struct mv88e6xxx_priv_state
*ps
= ds_to_priv(ds
);
233 ret
= mv88e6xxx_setup_common(ds
);
239 ret
= mv88e6xxx_switch_reset(ds
, true);
243 /* @@@ initialise vtu and atu */
245 ret
= mv88e6171_setup_global(ds
);
249 for (i
= 0; i
< ps
->num_ports
; i
++) {
250 if (!(dsa_is_cpu_port(ds
, i
) || ds
->phys_port_mask
& (1 << i
)))
253 ret
= mv88e6171_setup_port(ds
, i
);
261 static int mv88e6171_get_eee(struct dsa_switch
*ds
, int port
,
262 struct ethtool_eee
*e
)
264 struct mv88e6xxx_priv_state
*ps
= ds_to_priv(ds
);
266 if (ps
->id
== PORT_SWITCH_ID_6172
)
267 return mv88e6xxx_get_eee(ds
, port
, e
);
272 static int mv88e6171_set_eee(struct dsa_switch
*ds
, int port
,
273 struct phy_device
*phydev
, struct ethtool_eee
*e
)
275 struct mv88e6xxx_priv_state
*ps
= ds_to_priv(ds
);
277 if (ps
->id
== PORT_SWITCH_ID_6172
)
278 return mv88e6xxx_set_eee(ds
, port
, phydev
, e
);
283 struct dsa_switch_driver mv88e6171_switch_driver
= {
284 .tag_protocol
= DSA_TAG_PROTO_EDSA
,
285 .priv_size
= sizeof(struct mv88e6xxx_priv_state
),
286 .probe
= mv88e6171_probe
,
287 .setup
= mv88e6171_setup
,
288 .set_addr
= mv88e6xxx_set_addr_indirect
,
289 .phy_read
= mv88e6xxx_phy_read_indirect
,
290 .phy_write
= mv88e6xxx_phy_write_indirect
,
291 .poll_link
= mv88e6xxx_poll_link
,
292 .get_strings
= mv88e6xxx_get_strings
,
293 .get_ethtool_stats
= mv88e6xxx_get_ethtool_stats
,
294 .get_sset_count
= mv88e6xxx_get_sset_count
,
295 .set_eee
= mv88e6171_set_eee
,
296 .get_eee
= mv88e6171_get_eee
,
297 #ifdef CONFIG_NET_DSA_HWMON
298 .get_temp
= mv88e6xxx_get_temp
,
300 .get_regs_len
= mv88e6xxx_get_regs_len
,
301 .get_regs
= mv88e6xxx_get_regs
,
302 .port_join_bridge
= mv88e6xxx_join_bridge
,
303 .port_leave_bridge
= mv88e6xxx_leave_bridge
,
304 .port_stp_update
= mv88e6xxx_port_stp_update
,
305 .fdb_add
= mv88e6xxx_port_fdb_add
,
306 .fdb_del
= mv88e6xxx_port_fdb_del
,
307 .fdb_getnext
= mv88e6xxx_port_fdb_getnext
,
310 MODULE_ALIAS("platform:mv88e6171");
311 MODULE_ALIAS("platform:mv88e6172");