blob: 81cc24448164a980fd5ea9a085e18e62216aa999 [file] [log] [blame]
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001/*
2 * net/dsa/mv88e6123_61_65.c - Marvell 88e6123/6161/6165 switch chip support
Lennert Buytenheke84665c2009-03-20 09:52:09 +00003 * Copyright (c) 2008-2009 Marvell Semiconductor
Lennert Buytenhek91da11f2008-10-07 13:44:02 +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 Buytenhek91da11f2008-10-07 13:44:02 +000013#include <linux/list.h>
Paul Gortmaker2bbba272012-01-24 10:41:40 +000014#include <linux/module.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000015#include <linux/netdevice.h>
16#include <linux/phy.h>
Ben Hutchingsc8f0b862011-11-27 17:06:08 +000017#include <net/dsa.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000018#include "mv88e6xxx.h"
19
Alexander Duyckb4d23942014-09-15 13:00:27 -040020static char *mv88e6123_61_65_probe(struct device *host_dev, int sw_addr)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000021{
Alexander Duyckb4d23942014-09-15 13:00:27 -040022 struct mii_bus *bus = dsa_host_dev_to_mii_bus(host_dev);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000023 int ret;
24
Alexander Duyckb4d23942014-09-15 13:00:27 -040025 if (bus == NULL)
26 return NULL;
27
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000028 ret = __mv88e6xxx_reg_read(bus, sw_addr, REG_PORT(0), 0x03);
29 if (ret >= 0) {
Guenter Roeck14ef6ad2015-04-02 04:06:32 +020030 if (ret == ID_6123_A1)
Chris Healyedd664b2012-01-22 21:20:54 +000031 return "Marvell 88E6123 (A1)";
Guenter Roeck14ef6ad2015-04-02 04:06:32 +020032 if (ret == ID_6123_A2)
Chris Healyedd664b2012-01-22 21:20:54 +000033 return "Marvell 88E6123 (A2)";
Guenter Roeck14ef6ad2015-04-02 04:06:32 +020034 if ((ret & 0xfff0) == ID_6123)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000035 return "Marvell 88E6123";
Chris Healyedd664b2012-01-22 21:20:54 +000036
Guenter Roeck14ef6ad2015-04-02 04:06:32 +020037 if (ret == ID_6161_A1)
Chris Healyedd664b2012-01-22 21:20:54 +000038 return "Marvell 88E6161 (A1)";
Guenter Roeck14ef6ad2015-04-02 04:06:32 +020039 if (ret == ID_6161_A2)
Chris Healyedd664b2012-01-22 21:20:54 +000040 return "Marvell 88E6161 (A2)";
Guenter Roeck14ef6ad2015-04-02 04:06:32 +020041 if ((ret & 0xfff0) == ID_6161)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000042 return "Marvell 88E6161";
Chris Healyedd664b2012-01-22 21:20:54 +000043
Guenter Roeck14ef6ad2015-04-02 04:06:32 +020044 if (ret == ID_6165_A1)
Chris Healyedd664b2012-01-22 21:20:54 +000045 return "Marvell 88E6165 (A1)";
Guenter Roeck14ef6ad2015-04-02 04:06:32 +020046 if (ret == ID_6165_A2)
Chris Healyedd664b2012-01-22 21:20:54 +000047 return "Marvell 88e6165 (A2)";
Guenter Roeck14ef6ad2015-04-02 04:06:32 +020048 if ((ret & 0xfff0) == ID_6165)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000049 return "Marvell 88E6165";
50 }
51
52 return NULL;
53}
54
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000055static int mv88e6123_61_65_setup_global(struct dsa_switch *ds)
56{
57 int ret;
58 int i;
59
Barry Grussling3675c8d2013-01-08 16:05:53 +000060 /* Disable the PHY polling unit (since there won't be any
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000061 * external PHYs to poll), don't discard packets with
62 * excessive collisions, and mask all interrupt sources.
63 */
64 REG_WRITE(REG_GLOBAL, 0x04, 0x0000);
65
Barry Grussling3675c8d2013-01-08 16:05:53 +000066 /* Set the default address aging time to 5 minutes, and
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000067 * enable address learn messages to be sent to all message
68 * ports.
69 */
70 REG_WRITE(REG_GLOBAL, 0x0a, 0x0148);
71
Barry Grussling3675c8d2013-01-08 16:05:53 +000072 /* Configure the priority mapping registers. */
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000073 ret = mv88e6xxx_config_prio(ds);
74 if (ret < 0)
75 return ret;
76
Barry Grussling3675c8d2013-01-08 16:05:53 +000077 /* Configure the upstream port, and configure the upstream
Lennert Buytenheke84665c2009-03-20 09:52:09 +000078 * port as the port to which ingress and egress monitor frames
79 * are to be sent.
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000080 */
Lennert Buytenheke84665c2009-03-20 09:52:09 +000081 REG_WRITE(REG_GLOBAL, 0x1a, (dsa_upstream_port(ds) * 0x1110));
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000082
Barry Grussling3675c8d2013-01-08 16:05:53 +000083 /* Disable remote management for now, and set the switch's
Lennert Buytenheke84665c2009-03-20 09:52:09 +000084 * DSA device number.
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000085 */
Lennert Buytenheke84665c2009-03-20 09:52:09 +000086 REG_WRITE(REG_GLOBAL, 0x1c, ds->index & 0x1f);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000087
Barry Grussling3675c8d2013-01-08 16:05:53 +000088 /* Send all frames with destination addresses matching
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000089 * 01:80:c2:00:00:2x to the CPU port.
90 */
91 REG_WRITE(REG_GLOBAL2, 0x02, 0xffff);
92
Barry Grussling3675c8d2013-01-08 16:05:53 +000093 /* Send all frames with destination addresses matching
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000094 * 01:80:c2:00:00:0x to the CPU port.
95 */
96 REG_WRITE(REG_GLOBAL2, 0x03, 0xffff);
97
Barry Grussling3675c8d2013-01-08 16:05:53 +000098 /* Disable the loopback filter, disable flow control
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000099 * messages, disable flood broadcast override, disable
100 * removing of provider tags, disable ATU age violation
101 * interrupts, disable tag flow control, force flow
102 * control priority to the highest, and send all special
103 * multicast frames to the CPU at the highest priority.
104 */
105 REG_WRITE(REG_GLOBAL2, 0x05, 0x00ff);
106
Barry Grussling3675c8d2013-01-08 16:05:53 +0000107 /* Program the DSA routing table. */
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000108 for (i = 0; i < 32; i++) {
109 int nexthop;
110
111 nexthop = 0x1f;
112 if (i != ds->index && i < ds->dst->pd->nr_chips)
113 nexthop = ds->pd->rtable[i] & 0x1f;
114
115 REG_WRITE(REG_GLOBAL2, 0x06, 0x8000 | (i << 8) | nexthop);
116 }
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000117
Barry Grussling3675c8d2013-01-08 16:05:53 +0000118 /* Clear all trunk masks. */
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000119 for (i = 0; i < 8; i++)
120 REG_WRITE(REG_GLOBAL2, 0x07, 0x8000 | (i << 12) | 0xff);
121
Barry Grussling3675c8d2013-01-08 16:05:53 +0000122 /* Clear all trunk mappings. */
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000123 for (i = 0; i < 16; i++)
124 REG_WRITE(REG_GLOBAL2, 0x08, 0x8000 | (i << 11));
125
Barry Grussling3675c8d2013-01-08 16:05:53 +0000126 /* Disable ingress rate limiting by resetting all ingress
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000127 * rate limit registers to their initial state.
128 */
129 for (i = 0; i < 6; i++)
130 REG_WRITE(REG_GLOBAL2, 0x09, 0x9000 | (i << 8));
131
Barry Grussling3675c8d2013-01-08 16:05:53 +0000132 /* Initialise cross-chip port VLAN table to reset defaults. */
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000133 REG_WRITE(REG_GLOBAL2, 0x0b, 0x9000);
134
Barry Grussling3675c8d2013-01-08 16:05:53 +0000135 /* Clear the priority override table. */
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000136 for (i = 0; i < 16; i++)
137 REG_WRITE(REG_GLOBAL2, 0x0f, 0x8000 | (i << 8));
138
139 /* @@@ initialise AVB (22/23) watchdog (27) sdet (29) registers */
140
141 return 0;
142}
143
144static int mv88e6123_61_65_setup_port(struct dsa_switch *ds, int p)
145{
146 int addr = REG_PORT(p);
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000147 u16 val;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000148
Barry Grussling3675c8d2013-01-08 16:05:53 +0000149 /* MAC Forcing register: don't force link, speed, duplex
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000150 * or flow control state to any particular values on physical
151 * ports, but force the CPU port and all DSA ports to 1000 Mb/s
152 * full duplex.
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000153 */
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000154 if (dsa_is_cpu_port(ds, p) || ds->dsa_port_mask & (1 << p))
155 REG_WRITE(addr, 0x01, 0x003e);
156 else
157 REG_WRITE(addr, 0x01, 0x0003);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000158
Barry Grussling3675c8d2013-01-08 16:05:53 +0000159 /* Do not limit the period of time that this port can be
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000160 * paused for by the remote end or the period of time that
161 * this port can pause the remote end.
162 */
163 REG_WRITE(addr, 0x02, 0x0000);
164
Barry Grussling3675c8d2013-01-08 16:05:53 +0000165 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000166 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
167 * tunneling, determine priority by looking at 802.1p and IP
168 * priority fields (IP prio has precedence), and set STP state
169 * to Forwarding.
170 *
171 * If this is the CPU link, use DSA or EDSA tagging depending
172 * on which tagging mode was configured.
173 *
174 * If this is a link to another switch, use DSA tagging mode.
175 *
176 * If this is the upstream port for this switch, enable
177 * forwarding of unknown unicasts and multicasts.
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000178 */
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000179 val = 0x0433;
180 if (dsa_is_cpu_port(ds, p)) {
Florian Fainelliac7a04c2014-09-11 21:18:09 -0700181 if (ds->dst->tag_protocol == DSA_TAG_PROTO_EDSA)
Lennert Buytenheke84665c2009-03-20 09:52:09 +0000182 val |= 0x3300;
183 else
184 val |= 0x0100;
185 }
186 if (ds->dsa_port_mask & (1 << p))
187 val |= 0x0100;
188 if (p == dsa_upstream_port(ds))
189 val |= 0x000c;
190 REG_WRITE(addr, 0x04, val);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000191
Barry Grussling3675c8d2013-01-08 16:05:53 +0000192 /* Port Control 2: don't force a good FCS, set the maximum
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000193 * frame size to 10240 bytes, don't let the switch add or
194 * strip 802.1q tags, don't discard tagged or untagged frames
195 * on this port, do a destination address lookup on all
196 * received packets as usual, disable ARP mirroring and don't
197 * send a copy of all transmitted/received frames on this port
198 * to the CPU.
199 */
200 REG_WRITE(addr, 0x08, 0x2080);
201
Barry Grussling3675c8d2013-01-08 16:05:53 +0000202 /* Egress rate control: disable egress rate control. */
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000203 REG_WRITE(addr, 0x09, 0x0001);
204
Barry Grussling3675c8d2013-01-08 16:05:53 +0000205 /* Egress rate control 2: disable egress rate control. */
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000206 REG_WRITE(addr, 0x0a, 0x0000);
207
Barry Grussling3675c8d2013-01-08 16:05:53 +0000208 /* Port Association Vector: when learning source addresses
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000209 * of packets, add the address to the address database using
210 * a port bitmap that has only the bit for this port set and
211 * the other bits clear.
212 */
213 REG_WRITE(addr, 0x0b, 1 << p);
214
Barry Grussling3675c8d2013-01-08 16:05:53 +0000215 /* Port ATU control: disable limiting the number of address
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000216 * database entries that this port is allowed to use.
217 */
218 REG_WRITE(addr, 0x0c, 0x0000);
219
Barry Grussling3675c8d2013-01-08 16:05:53 +0000220 /* Priority Override: disable DA, SA and VTU priority override. */
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000221 REG_WRITE(addr, 0x0d, 0x0000);
222
Barry Grussling3675c8d2013-01-08 16:05:53 +0000223 /* Port Ethertype: use the Ethertype DSA Ethertype value. */
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000224 REG_WRITE(addr, 0x0f, ETH_P_EDSA);
225
Barry Grussling3675c8d2013-01-08 16:05:53 +0000226 /* Tag Remap: use an identity 802.1p prio -> switch prio
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000227 * mapping.
228 */
229 REG_WRITE(addr, 0x18, 0x3210);
230
Barry Grussling3675c8d2013-01-08 16:05:53 +0000231 /* Tag Remap 2: use an identity 802.1p prio -> switch prio
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000232 * mapping.
233 */
234 REG_WRITE(addr, 0x19, 0x7654);
235
Guenter Roeck54af0cf2015-03-26 18:36:33 -0700236 return mv88e6xxx_setup_port_common(ds, p);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000237}
238
239static int mv88e6123_61_65_setup(struct dsa_switch *ds)
240{
Guenter Roeck14ef6ad2015-04-02 04:06:32 +0200241 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000242 int i;
243 int ret;
244
Guenter Roeckacdaffc2015-03-26 18:36:28 -0700245 ret = mv88e6xxx_setup_common(ds);
246 if (ret < 0)
247 return ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000248
Guenter Roeck14ef6ad2015-04-02 04:06:32 +0200249 switch (ps->id) {
250 case ID_6123:
251 ps->num_ports = 3;
252 break;
253 case ID_6161:
254 case ID_6165:
255 ps->num_ports = 6;
256 break;
257 default:
258 return -ENODEV;
259 }
260
Andrew Lunn143a8302015-04-02 04:06:34 +0200261 ret = mv88e6xxx_switch_reset(ds, false);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000262 if (ret < 0)
263 return ret;
264
265 /* @@@ initialise vtu and atu */
266
267 ret = mv88e6123_61_65_setup_global(ds);
268 if (ret < 0)
269 return ret;
270
Guenter Roeck14ef6ad2015-04-02 04:06:32 +0200271 for (i = 0; i < ps->num_ports; i++) {
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000272 ret = mv88e6123_61_65_setup_port(ds, i);
273 if (ret < 0)
274 return ret;
275 }
276
277 return 0;
278}
279
Ben Hutchings98e67302011-11-25 14:36:19 +0000280struct dsa_switch_driver mv88e6123_61_65_switch_driver = {
Florian Fainelliac7a04c2014-09-11 21:18:09 -0700281 .tag_protocol = DSA_TAG_PROTO_EDSA,
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000282 .priv_size = sizeof(struct mv88e6xxx_priv_state),
283 .probe = mv88e6123_61_65_probe,
284 .setup = mv88e6123_61_65_setup,
285 .set_addr = mv88e6xxx_set_addr_indirect,
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +0200286 .phy_read = mv88e6xxx_phy_read,
287 .phy_write = mv88e6xxx_phy_write,
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000288 .poll_link = mv88e6xxx_poll_link,
Andrew Lunne413e7e2015-04-02 04:06:38 +0200289 .get_strings = mv88e6xxx_get_strings,
290 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
291 .get_sset_count = mv88e6xxx_get_sset_count,
Guenter Roeck87e5f662014-10-29 10:45:00 -0700292#ifdef CONFIG_NET_DSA_HWMON
Andrew Lunneaa23762014-11-15 22:24:51 +0100293 .get_temp = mv88e6xxx_get_temp,
Guenter Roeck87e5f662014-10-29 10:45:00 -0700294#endif
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700295 .get_regs_len = mv88e6xxx_get_regs_len,
296 .get_regs = mv88e6xxx_get_regs,
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000297};
Ben Hutchings3d825ed2011-11-25 14:37:16 +0000298
299MODULE_ALIAS("platform:mv88e6123");
300MODULE_ALIAS("platform:mv88e6161");
301MODULE_ALIAS("platform:mv88e6165");