xref: /openbmc/linux/drivers/net/dsa/b53/b53_common.c (revision 2c32a3d3c233b855943677609fe388f82b1f0975)
1967dd82fSFlorian Fainelli /*
2967dd82fSFlorian Fainelli  * B53 switch driver main logic
3967dd82fSFlorian Fainelli  *
4967dd82fSFlorian Fainelli  * Copyright (C) 2011-2013 Jonas Gorski <jogo@openwrt.org>
5967dd82fSFlorian Fainelli  * Copyright (C) 2016 Florian Fainelli <f.fainelli@gmail.com>
6967dd82fSFlorian Fainelli  *
7967dd82fSFlorian Fainelli  * Permission to use, copy, modify, and/or distribute this software for any
8967dd82fSFlorian Fainelli  * purpose with or without fee is hereby granted, provided that the above
9967dd82fSFlorian Fainelli  * copyright notice and this permission notice appear in all copies.
10967dd82fSFlorian Fainelli  *
11967dd82fSFlorian Fainelli  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12967dd82fSFlorian Fainelli  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13967dd82fSFlorian Fainelli  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14967dd82fSFlorian Fainelli  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15967dd82fSFlorian Fainelli  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16967dd82fSFlorian Fainelli  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17967dd82fSFlorian Fainelli  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18967dd82fSFlorian Fainelli  */
19967dd82fSFlorian Fainelli 
20967dd82fSFlorian Fainelli #include <linux/delay.h>
21967dd82fSFlorian Fainelli #include <linux/export.h>
22967dd82fSFlorian Fainelli #include <linux/gpio.h>
23967dd82fSFlorian Fainelli #include <linux/kernel.h>
24967dd82fSFlorian Fainelli #include <linux/module.h>
25967dd82fSFlorian Fainelli #include <linux/platform_data/b53.h>
26967dd82fSFlorian Fainelli #include <linux/phy.h>
275e004460SFlorian Fainelli #include <linux/phylink.h>
281da6df85SFlorian Fainelli #include <linux/etherdevice.h>
29ff39c2d6SFlorian Fainelli #include <linux/if_bridge.h>
30967dd82fSFlorian Fainelli #include <net/dsa.h>
31967dd82fSFlorian Fainelli 
32967dd82fSFlorian Fainelli #include "b53_regs.h"
33967dd82fSFlorian Fainelli #include "b53_priv.h"
34967dd82fSFlorian Fainelli 
35967dd82fSFlorian Fainelli struct b53_mib_desc {
36967dd82fSFlorian Fainelli 	u8 size;
37967dd82fSFlorian Fainelli 	u8 offset;
38967dd82fSFlorian Fainelli 	const char *name;
39967dd82fSFlorian Fainelli };
40967dd82fSFlorian Fainelli 
41967dd82fSFlorian Fainelli /* BCM5365 MIB counters */
42967dd82fSFlorian Fainelli static const struct b53_mib_desc b53_mibs_65[] = {
43967dd82fSFlorian Fainelli 	{ 8, 0x00, "TxOctets" },
44967dd82fSFlorian Fainelli 	{ 4, 0x08, "TxDropPkts" },
45967dd82fSFlorian Fainelli 	{ 4, 0x10, "TxBroadcastPkts" },
46967dd82fSFlorian Fainelli 	{ 4, 0x14, "TxMulticastPkts" },
47967dd82fSFlorian Fainelli 	{ 4, 0x18, "TxUnicastPkts" },
48967dd82fSFlorian Fainelli 	{ 4, 0x1c, "TxCollisions" },
49967dd82fSFlorian Fainelli 	{ 4, 0x20, "TxSingleCollision" },
50967dd82fSFlorian Fainelli 	{ 4, 0x24, "TxMultipleCollision" },
51967dd82fSFlorian Fainelli 	{ 4, 0x28, "TxDeferredTransmit" },
52967dd82fSFlorian Fainelli 	{ 4, 0x2c, "TxLateCollision" },
53967dd82fSFlorian Fainelli 	{ 4, 0x30, "TxExcessiveCollision" },
54967dd82fSFlorian Fainelli 	{ 4, 0x38, "TxPausePkts" },
55967dd82fSFlorian Fainelli 	{ 8, 0x44, "RxOctets" },
56967dd82fSFlorian Fainelli 	{ 4, 0x4c, "RxUndersizePkts" },
57967dd82fSFlorian Fainelli 	{ 4, 0x50, "RxPausePkts" },
58967dd82fSFlorian Fainelli 	{ 4, 0x54, "Pkts64Octets" },
59967dd82fSFlorian Fainelli 	{ 4, 0x58, "Pkts65to127Octets" },
60967dd82fSFlorian Fainelli 	{ 4, 0x5c, "Pkts128to255Octets" },
61967dd82fSFlorian Fainelli 	{ 4, 0x60, "Pkts256to511Octets" },
62967dd82fSFlorian Fainelli 	{ 4, 0x64, "Pkts512to1023Octets" },
63967dd82fSFlorian Fainelli 	{ 4, 0x68, "Pkts1024to1522Octets" },
64967dd82fSFlorian Fainelli 	{ 4, 0x6c, "RxOversizePkts" },
65967dd82fSFlorian Fainelli 	{ 4, 0x70, "RxJabbers" },
66967dd82fSFlorian Fainelli 	{ 4, 0x74, "RxAlignmentErrors" },
67967dd82fSFlorian Fainelli 	{ 4, 0x78, "RxFCSErrors" },
68967dd82fSFlorian Fainelli 	{ 8, 0x7c, "RxGoodOctets" },
69967dd82fSFlorian Fainelli 	{ 4, 0x84, "RxDropPkts" },
70967dd82fSFlorian Fainelli 	{ 4, 0x88, "RxUnicastPkts" },
71967dd82fSFlorian Fainelli 	{ 4, 0x8c, "RxMulticastPkts" },
72967dd82fSFlorian Fainelli 	{ 4, 0x90, "RxBroadcastPkts" },
73967dd82fSFlorian Fainelli 	{ 4, 0x94, "RxSAChanges" },
74967dd82fSFlorian Fainelli 	{ 4, 0x98, "RxFragments" },
75967dd82fSFlorian Fainelli };
76967dd82fSFlorian Fainelli 
77967dd82fSFlorian Fainelli #define B53_MIBS_65_SIZE	ARRAY_SIZE(b53_mibs_65)
78967dd82fSFlorian Fainelli 
79967dd82fSFlorian Fainelli /* BCM63xx MIB counters */
80967dd82fSFlorian Fainelli static const struct b53_mib_desc b53_mibs_63xx[] = {
81967dd82fSFlorian Fainelli 	{ 8, 0x00, "TxOctets" },
82967dd82fSFlorian Fainelli 	{ 4, 0x08, "TxDropPkts" },
83967dd82fSFlorian Fainelli 	{ 4, 0x0c, "TxQoSPkts" },
84967dd82fSFlorian Fainelli 	{ 4, 0x10, "TxBroadcastPkts" },
85967dd82fSFlorian Fainelli 	{ 4, 0x14, "TxMulticastPkts" },
86967dd82fSFlorian Fainelli 	{ 4, 0x18, "TxUnicastPkts" },
87967dd82fSFlorian Fainelli 	{ 4, 0x1c, "TxCollisions" },
88967dd82fSFlorian Fainelli 	{ 4, 0x20, "TxSingleCollision" },
89967dd82fSFlorian Fainelli 	{ 4, 0x24, "TxMultipleCollision" },
90967dd82fSFlorian Fainelli 	{ 4, 0x28, "TxDeferredTransmit" },
91967dd82fSFlorian Fainelli 	{ 4, 0x2c, "TxLateCollision" },
92967dd82fSFlorian Fainelli 	{ 4, 0x30, "TxExcessiveCollision" },
93967dd82fSFlorian Fainelli 	{ 4, 0x38, "TxPausePkts" },
94967dd82fSFlorian Fainelli 	{ 8, 0x3c, "TxQoSOctets" },
95967dd82fSFlorian Fainelli 	{ 8, 0x44, "RxOctets" },
96967dd82fSFlorian Fainelli 	{ 4, 0x4c, "RxUndersizePkts" },
97967dd82fSFlorian Fainelli 	{ 4, 0x50, "RxPausePkts" },
98967dd82fSFlorian Fainelli 	{ 4, 0x54, "Pkts64Octets" },
99967dd82fSFlorian Fainelli 	{ 4, 0x58, "Pkts65to127Octets" },
100967dd82fSFlorian Fainelli 	{ 4, 0x5c, "Pkts128to255Octets" },
101967dd82fSFlorian Fainelli 	{ 4, 0x60, "Pkts256to511Octets" },
102967dd82fSFlorian Fainelli 	{ 4, 0x64, "Pkts512to1023Octets" },
103967dd82fSFlorian Fainelli 	{ 4, 0x68, "Pkts1024to1522Octets" },
104967dd82fSFlorian Fainelli 	{ 4, 0x6c, "RxOversizePkts" },
105967dd82fSFlorian Fainelli 	{ 4, 0x70, "RxJabbers" },
106967dd82fSFlorian Fainelli 	{ 4, 0x74, "RxAlignmentErrors" },
107967dd82fSFlorian Fainelli 	{ 4, 0x78, "RxFCSErrors" },
108967dd82fSFlorian Fainelli 	{ 8, 0x7c, "RxGoodOctets" },
109967dd82fSFlorian Fainelli 	{ 4, 0x84, "RxDropPkts" },
110967dd82fSFlorian Fainelli 	{ 4, 0x88, "RxUnicastPkts" },
111967dd82fSFlorian Fainelli 	{ 4, 0x8c, "RxMulticastPkts" },
112967dd82fSFlorian Fainelli 	{ 4, 0x90, "RxBroadcastPkts" },
113967dd82fSFlorian Fainelli 	{ 4, 0x94, "RxSAChanges" },
114967dd82fSFlorian Fainelli 	{ 4, 0x98, "RxFragments" },
115967dd82fSFlorian Fainelli 	{ 4, 0xa0, "RxSymbolErrors" },
116967dd82fSFlorian Fainelli 	{ 4, 0xa4, "RxQoSPkts" },
117967dd82fSFlorian Fainelli 	{ 8, 0xa8, "RxQoSOctets" },
118967dd82fSFlorian Fainelli 	{ 4, 0xb0, "Pkts1523to2047Octets" },
119967dd82fSFlorian Fainelli 	{ 4, 0xb4, "Pkts2048to4095Octets" },
120967dd82fSFlorian Fainelli 	{ 4, 0xb8, "Pkts4096to8191Octets" },
121967dd82fSFlorian Fainelli 	{ 4, 0xbc, "Pkts8192to9728Octets" },
122967dd82fSFlorian Fainelli 	{ 4, 0xc0, "RxDiscarded" },
123967dd82fSFlorian Fainelli };
124967dd82fSFlorian Fainelli 
125967dd82fSFlorian Fainelli #define B53_MIBS_63XX_SIZE	ARRAY_SIZE(b53_mibs_63xx)
126967dd82fSFlorian Fainelli 
127967dd82fSFlorian Fainelli /* MIB counters */
128967dd82fSFlorian Fainelli static const struct b53_mib_desc b53_mibs[] = {
129967dd82fSFlorian Fainelli 	{ 8, 0x00, "TxOctets" },
130967dd82fSFlorian Fainelli 	{ 4, 0x08, "TxDropPkts" },
131967dd82fSFlorian Fainelli 	{ 4, 0x10, "TxBroadcastPkts" },
132967dd82fSFlorian Fainelli 	{ 4, 0x14, "TxMulticastPkts" },
133967dd82fSFlorian Fainelli 	{ 4, 0x18, "TxUnicastPkts" },
134967dd82fSFlorian Fainelli 	{ 4, 0x1c, "TxCollisions" },
135967dd82fSFlorian Fainelli 	{ 4, 0x20, "TxSingleCollision" },
136967dd82fSFlorian Fainelli 	{ 4, 0x24, "TxMultipleCollision" },
137967dd82fSFlorian Fainelli 	{ 4, 0x28, "TxDeferredTransmit" },
138967dd82fSFlorian Fainelli 	{ 4, 0x2c, "TxLateCollision" },
139967dd82fSFlorian Fainelli 	{ 4, 0x30, "TxExcessiveCollision" },
140967dd82fSFlorian Fainelli 	{ 4, 0x38, "TxPausePkts" },
141967dd82fSFlorian Fainelli 	{ 8, 0x50, "RxOctets" },
142967dd82fSFlorian Fainelli 	{ 4, 0x58, "RxUndersizePkts" },
143967dd82fSFlorian Fainelli 	{ 4, 0x5c, "RxPausePkts" },
144967dd82fSFlorian Fainelli 	{ 4, 0x60, "Pkts64Octets" },
145967dd82fSFlorian Fainelli 	{ 4, 0x64, "Pkts65to127Octets" },
146967dd82fSFlorian Fainelli 	{ 4, 0x68, "Pkts128to255Octets" },
147967dd82fSFlorian Fainelli 	{ 4, 0x6c, "Pkts256to511Octets" },
148967dd82fSFlorian Fainelli 	{ 4, 0x70, "Pkts512to1023Octets" },
149967dd82fSFlorian Fainelli 	{ 4, 0x74, "Pkts1024to1522Octets" },
150967dd82fSFlorian Fainelli 	{ 4, 0x78, "RxOversizePkts" },
151967dd82fSFlorian Fainelli 	{ 4, 0x7c, "RxJabbers" },
152967dd82fSFlorian Fainelli 	{ 4, 0x80, "RxAlignmentErrors" },
153967dd82fSFlorian Fainelli 	{ 4, 0x84, "RxFCSErrors" },
154967dd82fSFlorian Fainelli 	{ 8, 0x88, "RxGoodOctets" },
155967dd82fSFlorian Fainelli 	{ 4, 0x90, "RxDropPkts" },
156967dd82fSFlorian Fainelli 	{ 4, 0x94, "RxUnicastPkts" },
157967dd82fSFlorian Fainelli 	{ 4, 0x98, "RxMulticastPkts" },
158967dd82fSFlorian Fainelli 	{ 4, 0x9c, "RxBroadcastPkts" },
159967dd82fSFlorian Fainelli 	{ 4, 0xa0, "RxSAChanges" },
160967dd82fSFlorian Fainelli 	{ 4, 0xa4, "RxFragments" },
161967dd82fSFlorian Fainelli 	{ 4, 0xa8, "RxJumboPkts" },
162967dd82fSFlorian Fainelli 	{ 4, 0xac, "RxSymbolErrors" },
163967dd82fSFlorian Fainelli 	{ 4, 0xc0, "RxDiscarded" },
164967dd82fSFlorian Fainelli };
165967dd82fSFlorian Fainelli 
166967dd82fSFlorian Fainelli #define B53_MIBS_SIZE	ARRAY_SIZE(b53_mibs)
167967dd82fSFlorian Fainelli 
168bde5d132SFlorian Fainelli static const struct b53_mib_desc b53_mibs_58xx[] = {
169bde5d132SFlorian Fainelli 	{ 8, 0x00, "TxOctets" },
170bde5d132SFlorian Fainelli 	{ 4, 0x08, "TxDropPkts" },
171bde5d132SFlorian Fainelli 	{ 4, 0x0c, "TxQPKTQ0" },
172bde5d132SFlorian Fainelli 	{ 4, 0x10, "TxBroadcastPkts" },
173bde5d132SFlorian Fainelli 	{ 4, 0x14, "TxMulticastPkts" },
174bde5d132SFlorian Fainelli 	{ 4, 0x18, "TxUnicastPKts" },
175bde5d132SFlorian Fainelli 	{ 4, 0x1c, "TxCollisions" },
176bde5d132SFlorian Fainelli 	{ 4, 0x20, "TxSingleCollision" },
177bde5d132SFlorian Fainelli 	{ 4, 0x24, "TxMultipleCollision" },
178bde5d132SFlorian Fainelli 	{ 4, 0x28, "TxDeferredCollision" },
179bde5d132SFlorian Fainelli 	{ 4, 0x2c, "TxLateCollision" },
180bde5d132SFlorian Fainelli 	{ 4, 0x30, "TxExcessiveCollision" },
181bde5d132SFlorian Fainelli 	{ 4, 0x34, "TxFrameInDisc" },
182bde5d132SFlorian Fainelli 	{ 4, 0x38, "TxPausePkts" },
183bde5d132SFlorian Fainelli 	{ 4, 0x3c, "TxQPKTQ1" },
184bde5d132SFlorian Fainelli 	{ 4, 0x40, "TxQPKTQ2" },
185bde5d132SFlorian Fainelli 	{ 4, 0x44, "TxQPKTQ3" },
186bde5d132SFlorian Fainelli 	{ 4, 0x48, "TxQPKTQ4" },
187bde5d132SFlorian Fainelli 	{ 4, 0x4c, "TxQPKTQ5" },
188bde5d132SFlorian Fainelli 	{ 8, 0x50, "RxOctets" },
189bde5d132SFlorian Fainelli 	{ 4, 0x58, "RxUndersizePkts" },
190bde5d132SFlorian Fainelli 	{ 4, 0x5c, "RxPausePkts" },
191bde5d132SFlorian Fainelli 	{ 4, 0x60, "RxPkts64Octets" },
192bde5d132SFlorian Fainelli 	{ 4, 0x64, "RxPkts65to127Octets" },
193bde5d132SFlorian Fainelli 	{ 4, 0x68, "RxPkts128to255Octets" },
194bde5d132SFlorian Fainelli 	{ 4, 0x6c, "RxPkts256to511Octets" },
195bde5d132SFlorian Fainelli 	{ 4, 0x70, "RxPkts512to1023Octets" },
196bde5d132SFlorian Fainelli 	{ 4, 0x74, "RxPkts1024toMaxPktsOctets" },
197bde5d132SFlorian Fainelli 	{ 4, 0x78, "RxOversizePkts" },
198bde5d132SFlorian Fainelli 	{ 4, 0x7c, "RxJabbers" },
199bde5d132SFlorian Fainelli 	{ 4, 0x80, "RxAlignmentErrors" },
200bde5d132SFlorian Fainelli 	{ 4, 0x84, "RxFCSErrors" },
201bde5d132SFlorian Fainelli 	{ 8, 0x88, "RxGoodOctets" },
202bde5d132SFlorian Fainelli 	{ 4, 0x90, "RxDropPkts" },
203bde5d132SFlorian Fainelli 	{ 4, 0x94, "RxUnicastPkts" },
204bde5d132SFlorian Fainelli 	{ 4, 0x98, "RxMulticastPkts" },
205bde5d132SFlorian Fainelli 	{ 4, 0x9c, "RxBroadcastPkts" },
206bde5d132SFlorian Fainelli 	{ 4, 0xa0, "RxSAChanges" },
207bde5d132SFlorian Fainelli 	{ 4, 0xa4, "RxFragments" },
208bde5d132SFlorian Fainelli 	{ 4, 0xa8, "RxJumboPkt" },
209bde5d132SFlorian Fainelli 	{ 4, 0xac, "RxSymblErr" },
210bde5d132SFlorian Fainelli 	{ 4, 0xb0, "InRangeErrCount" },
211bde5d132SFlorian Fainelli 	{ 4, 0xb4, "OutRangeErrCount" },
212bde5d132SFlorian Fainelli 	{ 4, 0xb8, "EEELpiEvent" },
213bde5d132SFlorian Fainelli 	{ 4, 0xbc, "EEELpiDuration" },
214bde5d132SFlorian Fainelli 	{ 4, 0xc0, "RxDiscard" },
215bde5d132SFlorian Fainelli 	{ 4, 0xc8, "TxQPKTQ6" },
216bde5d132SFlorian Fainelli 	{ 4, 0xcc, "TxQPKTQ7" },
217bde5d132SFlorian Fainelli 	{ 4, 0xd0, "TxPkts64Octets" },
218bde5d132SFlorian Fainelli 	{ 4, 0xd4, "TxPkts65to127Octets" },
219bde5d132SFlorian Fainelli 	{ 4, 0xd8, "TxPkts128to255Octets" },
220bde5d132SFlorian Fainelli 	{ 4, 0xdc, "TxPkts256to511Ocets" },
221bde5d132SFlorian Fainelli 	{ 4, 0xe0, "TxPkts512to1023Ocets" },
222bde5d132SFlorian Fainelli 	{ 4, 0xe4, "TxPkts1024toMaxPktOcets" },
223bde5d132SFlorian Fainelli };
224bde5d132SFlorian Fainelli 
225bde5d132SFlorian Fainelli #define B53_MIBS_58XX_SIZE	ARRAY_SIZE(b53_mibs_58xx)
226bde5d132SFlorian Fainelli 
227967dd82fSFlorian Fainelli static int b53_do_vlan_op(struct b53_device *dev, u8 op)
228967dd82fSFlorian Fainelli {
229967dd82fSFlorian Fainelli 	unsigned int i;
230967dd82fSFlorian Fainelli 
231967dd82fSFlorian Fainelli 	b53_write8(dev, B53_ARLIO_PAGE, dev->vta_regs[0], VTA_START_CMD | op);
232967dd82fSFlorian Fainelli 
233967dd82fSFlorian Fainelli 	for (i = 0; i < 10; i++) {
234967dd82fSFlorian Fainelli 		u8 vta;
235967dd82fSFlorian Fainelli 
236967dd82fSFlorian Fainelli 		b53_read8(dev, B53_ARLIO_PAGE, dev->vta_regs[0], &vta);
237967dd82fSFlorian Fainelli 		if (!(vta & VTA_START_CMD))
238967dd82fSFlorian Fainelli 			return 0;
239967dd82fSFlorian Fainelli 
240967dd82fSFlorian Fainelli 		usleep_range(100, 200);
241967dd82fSFlorian Fainelli 	}
242967dd82fSFlorian Fainelli 
243967dd82fSFlorian Fainelli 	return -EIO;
244967dd82fSFlorian Fainelli }
245967dd82fSFlorian Fainelli 
246a2482d2cSFlorian Fainelli static void b53_set_vlan_entry(struct b53_device *dev, u16 vid,
247a2482d2cSFlorian Fainelli 			       struct b53_vlan *vlan)
248967dd82fSFlorian Fainelli {
249967dd82fSFlorian Fainelli 	if (is5325(dev)) {
250967dd82fSFlorian Fainelli 		u32 entry = 0;
251967dd82fSFlorian Fainelli 
252a2482d2cSFlorian Fainelli 		if (vlan->members) {
253a2482d2cSFlorian Fainelli 			entry = ((vlan->untag & VA_UNTAG_MASK_25) <<
254a2482d2cSFlorian Fainelli 				 VA_UNTAG_S_25) | vlan->members;
255967dd82fSFlorian Fainelli 			if (dev->core_rev >= 3)
256967dd82fSFlorian Fainelli 				entry |= VA_VALID_25_R4 | vid << VA_VID_HIGH_S;
257967dd82fSFlorian Fainelli 			else
258967dd82fSFlorian Fainelli 				entry |= VA_VALID_25;
259967dd82fSFlorian Fainelli 		}
260967dd82fSFlorian Fainelli 
261967dd82fSFlorian Fainelli 		b53_write32(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_25, entry);
262967dd82fSFlorian Fainelli 		b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, vid |
263967dd82fSFlorian Fainelli 			    VTA_RW_STATE_WR | VTA_RW_OP_EN);
264967dd82fSFlorian Fainelli 	} else if (is5365(dev)) {
265967dd82fSFlorian Fainelli 		u16 entry = 0;
266967dd82fSFlorian Fainelli 
267a2482d2cSFlorian Fainelli 		if (vlan->members)
268a2482d2cSFlorian Fainelli 			entry = ((vlan->untag & VA_UNTAG_MASK_65) <<
269a2482d2cSFlorian Fainelli 				 VA_UNTAG_S_65) | vlan->members | VA_VALID_65;
270967dd82fSFlorian Fainelli 
271967dd82fSFlorian Fainelli 		b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_65, entry);
272967dd82fSFlorian Fainelli 		b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_65, vid |
273967dd82fSFlorian Fainelli 			    VTA_RW_STATE_WR | VTA_RW_OP_EN);
274967dd82fSFlorian Fainelli 	} else {
275967dd82fSFlorian Fainelli 		b53_write16(dev, B53_ARLIO_PAGE, dev->vta_regs[1], vid);
276967dd82fSFlorian Fainelli 		b53_write32(dev, B53_ARLIO_PAGE, dev->vta_regs[2],
277a2482d2cSFlorian Fainelli 			    (vlan->untag << VTE_UNTAG_S) | vlan->members);
278967dd82fSFlorian Fainelli 
279967dd82fSFlorian Fainelli 		b53_do_vlan_op(dev, VTA_CMD_WRITE);
280967dd82fSFlorian Fainelli 	}
281a2482d2cSFlorian Fainelli 
282a2482d2cSFlorian Fainelli 	dev_dbg(dev->ds->dev, "VID: %d, members: 0x%04x, untag: 0x%04x\n",
283a2482d2cSFlorian Fainelli 		vid, vlan->members, vlan->untag);
284967dd82fSFlorian Fainelli }
285967dd82fSFlorian Fainelli 
286a2482d2cSFlorian Fainelli static void b53_get_vlan_entry(struct b53_device *dev, u16 vid,
287a2482d2cSFlorian Fainelli 			       struct b53_vlan *vlan)
288a2482d2cSFlorian Fainelli {
289a2482d2cSFlorian Fainelli 	if (is5325(dev)) {
290a2482d2cSFlorian Fainelli 		u32 entry = 0;
291a2482d2cSFlorian Fainelli 
292a2482d2cSFlorian Fainelli 		b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, vid |
293a2482d2cSFlorian Fainelli 			    VTA_RW_STATE_RD | VTA_RW_OP_EN);
294a2482d2cSFlorian Fainelli 		b53_read32(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_25, &entry);
295a2482d2cSFlorian Fainelli 
296a2482d2cSFlorian Fainelli 		if (dev->core_rev >= 3)
297a2482d2cSFlorian Fainelli 			vlan->valid = !!(entry & VA_VALID_25_R4);
298a2482d2cSFlorian Fainelli 		else
299a2482d2cSFlorian Fainelli 			vlan->valid = !!(entry & VA_VALID_25);
300a2482d2cSFlorian Fainelli 		vlan->members = entry & VA_MEMBER_MASK;
301a2482d2cSFlorian Fainelli 		vlan->untag = (entry >> VA_UNTAG_S_25) & VA_UNTAG_MASK_25;
302a2482d2cSFlorian Fainelli 
303a2482d2cSFlorian Fainelli 	} else if (is5365(dev)) {
304a2482d2cSFlorian Fainelli 		u16 entry = 0;
305a2482d2cSFlorian Fainelli 
306a2482d2cSFlorian Fainelli 		b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_65, vid |
307a2482d2cSFlorian Fainelli 			    VTA_RW_STATE_WR | VTA_RW_OP_EN);
308a2482d2cSFlorian Fainelli 		b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_65, &entry);
309a2482d2cSFlorian Fainelli 
310a2482d2cSFlorian Fainelli 		vlan->valid = !!(entry & VA_VALID_65);
311a2482d2cSFlorian Fainelli 		vlan->members = entry & VA_MEMBER_MASK;
312a2482d2cSFlorian Fainelli 		vlan->untag = (entry >> VA_UNTAG_S_65) & VA_UNTAG_MASK_65;
313a2482d2cSFlorian Fainelli 	} else {
314a2482d2cSFlorian Fainelli 		u32 entry = 0;
315a2482d2cSFlorian Fainelli 
316a2482d2cSFlorian Fainelli 		b53_write16(dev, B53_ARLIO_PAGE, dev->vta_regs[1], vid);
317a2482d2cSFlorian Fainelli 		b53_do_vlan_op(dev, VTA_CMD_READ);
318a2482d2cSFlorian Fainelli 		b53_read32(dev, B53_ARLIO_PAGE, dev->vta_regs[2], &entry);
319a2482d2cSFlorian Fainelli 		vlan->members = entry & VTE_MEMBERS;
320a2482d2cSFlorian Fainelli 		vlan->untag = (entry >> VTE_UNTAG_S) & VTE_MEMBERS;
321a2482d2cSFlorian Fainelli 		vlan->valid = true;
322a2482d2cSFlorian Fainelli 	}
323a2482d2cSFlorian Fainelli }
324a2482d2cSFlorian Fainelli 
325a2482d2cSFlorian Fainelli static void b53_set_forwarding(struct b53_device *dev, int enable)
326967dd82fSFlorian Fainelli {
327967dd82fSFlorian Fainelli 	u8 mgmt;
328967dd82fSFlorian Fainelli 
329967dd82fSFlorian Fainelli 	b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt);
330967dd82fSFlorian Fainelli 
331967dd82fSFlorian Fainelli 	if (enable)
332967dd82fSFlorian Fainelli 		mgmt |= SM_SW_FWD_EN;
333967dd82fSFlorian Fainelli 	else
334967dd82fSFlorian Fainelli 		mgmt &= ~SM_SW_FWD_EN;
335967dd82fSFlorian Fainelli 
336967dd82fSFlorian Fainelli 	b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt);
337a424f0deSFlorian Fainelli 
3387edc58d6SFlorian Fainelli 	/* Include IMP port in dumb forwarding mode
339a424f0deSFlorian Fainelli 	 */
340a424f0deSFlorian Fainelli 	b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_CTRL, &mgmt);
341a424f0deSFlorian Fainelli 	mgmt |= B53_MII_DUMB_FWDG_EN;
342a424f0deSFlorian Fainelli 	b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_CTRL, mgmt);
34353568438SFlorian Fainelli 
34453568438SFlorian Fainelli 	/* Look at B53_UC_FWD_EN and B53_MC_FWD_EN to decide whether
34553568438SFlorian Fainelli 	 * frames should be flooded or not.
34653568438SFlorian Fainelli 	 */
34753568438SFlorian Fainelli 	b53_read8(dev, B53_CTRL_PAGE, B53_IP_MULTICAST_CTRL, &mgmt);
34863cc54a6SFlorian Fainelli 	mgmt |= B53_UC_FWD_EN | B53_MC_FWD_EN | B53_IPMC_FWD_EN;
34953568438SFlorian Fainelli 	b53_write8(dev, B53_CTRL_PAGE, B53_IP_MULTICAST_CTRL, mgmt);
350a424f0deSFlorian Fainelli }
351967dd82fSFlorian Fainelli 
352ee47ed08SFlorian Fainelli static void b53_enable_vlan(struct b53_device *dev, int port, bool enable,
353dad8d7c6SFlorian Fainelli 			    bool enable_filtering)
354967dd82fSFlorian Fainelli {
355967dd82fSFlorian Fainelli 	u8 mgmt, vc0, vc1, vc4 = 0, vc5;
356967dd82fSFlorian Fainelli 
357967dd82fSFlorian Fainelli 	b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt);
358967dd82fSFlorian Fainelli 	b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL0, &vc0);
359967dd82fSFlorian Fainelli 	b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL1, &vc1);
360967dd82fSFlorian Fainelli 
361967dd82fSFlorian Fainelli 	if (is5325(dev) || is5365(dev)) {
362967dd82fSFlorian Fainelli 		b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, &vc4);
363967dd82fSFlorian Fainelli 		b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_25, &vc5);
364967dd82fSFlorian Fainelli 	} else if (is63xx(dev)) {
365967dd82fSFlorian Fainelli 		b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_63XX, &vc4);
366967dd82fSFlorian Fainelli 		b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_63XX, &vc5);
367967dd82fSFlorian Fainelli 	} else {
368967dd82fSFlorian Fainelli 		b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4, &vc4);
369967dd82fSFlorian Fainelli 		b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5, &vc5);
370967dd82fSFlorian Fainelli 	}
371967dd82fSFlorian Fainelli 
372967dd82fSFlorian Fainelli 	if (enable) {
373967dd82fSFlorian Fainelli 		vc0 |= VC0_VLAN_EN | VC0_VID_CHK_EN | VC0_VID_HASH_VID;
374967dd82fSFlorian Fainelli 		vc1 |= VC1_RX_MCST_UNTAG_EN | VC1_RX_MCST_FWD_EN;
375967dd82fSFlorian Fainelli 		vc4 &= ~VC4_ING_VID_CHECK_MASK;
376dad8d7c6SFlorian Fainelli 		if (enable_filtering) {
377967dd82fSFlorian Fainelli 			vc4 |= VC4_ING_VID_VIO_DROP << VC4_ING_VID_CHECK_S;
378967dd82fSFlorian Fainelli 			vc5 |= VC5_DROP_VTABLE_MISS;
379dad8d7c6SFlorian Fainelli 		} else {
380dad8d7c6SFlorian Fainelli 			vc4 |= VC4_ING_VID_VIO_FWD << VC4_ING_VID_CHECK_S;
381dad8d7c6SFlorian Fainelli 			vc5 &= ~VC5_DROP_VTABLE_MISS;
382dad8d7c6SFlorian Fainelli 		}
383967dd82fSFlorian Fainelli 
384967dd82fSFlorian Fainelli 		if (is5325(dev))
385967dd82fSFlorian Fainelli 			vc0 &= ~VC0_RESERVED_1;
386967dd82fSFlorian Fainelli 
387967dd82fSFlorian Fainelli 		if (is5325(dev) || is5365(dev))
388967dd82fSFlorian Fainelli 			vc1 |= VC1_RX_MCST_TAG_EN;
389967dd82fSFlorian Fainelli 
390967dd82fSFlorian Fainelli 	} else {
391967dd82fSFlorian Fainelli 		vc0 &= ~(VC0_VLAN_EN | VC0_VID_CHK_EN | VC0_VID_HASH_VID);
392967dd82fSFlorian Fainelli 		vc1 &= ~(VC1_RX_MCST_UNTAG_EN | VC1_RX_MCST_FWD_EN);
393967dd82fSFlorian Fainelli 		vc4 &= ~VC4_ING_VID_CHECK_MASK;
394967dd82fSFlorian Fainelli 		vc5 &= ~VC5_DROP_VTABLE_MISS;
395967dd82fSFlorian Fainelli 
396967dd82fSFlorian Fainelli 		if (is5325(dev) || is5365(dev))
397967dd82fSFlorian Fainelli 			vc4 |= VC4_ING_VID_VIO_FWD << VC4_ING_VID_CHECK_S;
398967dd82fSFlorian Fainelli 		else
399967dd82fSFlorian Fainelli 			vc4 |= VC4_ING_VID_VIO_TO_IMP << VC4_ING_VID_CHECK_S;
400967dd82fSFlorian Fainelli 
401967dd82fSFlorian Fainelli 		if (is5325(dev) || is5365(dev))
402967dd82fSFlorian Fainelli 			vc1 &= ~VC1_RX_MCST_TAG_EN;
403a2482d2cSFlorian Fainelli 	}
404967dd82fSFlorian Fainelli 
405967dd82fSFlorian Fainelli 	if (!is5325(dev) && !is5365(dev))
406967dd82fSFlorian Fainelli 		vc5 &= ~VC5_VID_FFF_EN;
407967dd82fSFlorian Fainelli 
408967dd82fSFlorian Fainelli 	b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL0, vc0);
409967dd82fSFlorian Fainelli 	b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL1, vc1);
410967dd82fSFlorian Fainelli 
411967dd82fSFlorian Fainelli 	if (is5325(dev) || is5365(dev)) {
412967dd82fSFlorian Fainelli 		/* enable the high 8 bit vid check on 5325 */
413967dd82fSFlorian Fainelli 		if (is5325(dev) && enable)
414967dd82fSFlorian Fainelli 			b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3,
415967dd82fSFlorian Fainelli 				   VC3_HIGH_8BIT_EN);
416967dd82fSFlorian Fainelli 		else
417967dd82fSFlorian Fainelli 			b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3, 0);
418967dd82fSFlorian Fainelli 
419967dd82fSFlorian Fainelli 		b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, vc4);
420967dd82fSFlorian Fainelli 		b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_25, vc5);
421967dd82fSFlorian Fainelli 	} else if (is63xx(dev)) {
422967dd82fSFlorian Fainelli 		b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3_63XX, 0);
423967dd82fSFlorian Fainelli 		b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_63XX, vc4);
424967dd82fSFlorian Fainelli 		b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_63XX, vc5);
425967dd82fSFlorian Fainelli 	} else {
426967dd82fSFlorian Fainelli 		b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3, 0);
427967dd82fSFlorian Fainelli 		b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4, vc4);
428967dd82fSFlorian Fainelli 		b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5, vc5);
429967dd82fSFlorian Fainelli 	}
430967dd82fSFlorian Fainelli 
431967dd82fSFlorian Fainelli 	b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt);
432dad8d7c6SFlorian Fainelli 
433dad8d7c6SFlorian Fainelli 	dev->vlan_enabled = enable;
434ee47ed08SFlorian Fainelli 
435ee47ed08SFlorian Fainelli 	dev_dbg(dev->dev, "Port %d VLAN enabled: %d, filtering: %d\n",
436ee47ed08SFlorian Fainelli 		port, enable, enable_filtering);
437967dd82fSFlorian Fainelli }
438967dd82fSFlorian Fainelli 
439967dd82fSFlorian Fainelli static int b53_set_jumbo(struct b53_device *dev, bool enable, bool allow_10_100)
440967dd82fSFlorian Fainelli {
441967dd82fSFlorian Fainelli 	u32 port_mask = 0;
442967dd82fSFlorian Fainelli 	u16 max_size = JMS_MIN_SIZE;
443967dd82fSFlorian Fainelli 
444967dd82fSFlorian Fainelli 	if (is5325(dev) || is5365(dev))
445967dd82fSFlorian Fainelli 		return -EINVAL;
446967dd82fSFlorian Fainelli 
447967dd82fSFlorian Fainelli 	if (enable) {
448967dd82fSFlorian Fainelli 		port_mask = dev->enabled_ports;
449967dd82fSFlorian Fainelli 		max_size = JMS_MAX_SIZE;
450967dd82fSFlorian Fainelli 		if (allow_10_100)
451967dd82fSFlorian Fainelli 			port_mask |= JPM_10_100_JUMBO_EN;
452967dd82fSFlorian Fainelli 	}
453967dd82fSFlorian Fainelli 
454967dd82fSFlorian Fainelli 	b53_write32(dev, B53_JUMBO_PAGE, dev->jumbo_pm_reg, port_mask);
455967dd82fSFlorian Fainelli 	return b53_write16(dev, B53_JUMBO_PAGE, dev->jumbo_size_reg, max_size);
456967dd82fSFlorian Fainelli }
457967dd82fSFlorian Fainelli 
458ff39c2d6SFlorian Fainelli static int b53_flush_arl(struct b53_device *dev, u8 mask)
459967dd82fSFlorian Fainelli {
460967dd82fSFlorian Fainelli 	unsigned int i;
461967dd82fSFlorian Fainelli 
462967dd82fSFlorian Fainelli 	b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL,
463ff39c2d6SFlorian Fainelli 		   FAST_AGE_DONE | FAST_AGE_DYNAMIC | mask);
464967dd82fSFlorian Fainelli 
465967dd82fSFlorian Fainelli 	for (i = 0; i < 10; i++) {
466967dd82fSFlorian Fainelli 		u8 fast_age_ctrl;
467967dd82fSFlorian Fainelli 
468967dd82fSFlorian Fainelli 		b53_read8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL,
469967dd82fSFlorian Fainelli 			  &fast_age_ctrl);
470967dd82fSFlorian Fainelli 
471967dd82fSFlorian Fainelli 		if (!(fast_age_ctrl & FAST_AGE_DONE))
472967dd82fSFlorian Fainelli 			goto out;
473967dd82fSFlorian Fainelli 
474967dd82fSFlorian Fainelli 		msleep(1);
475967dd82fSFlorian Fainelli 	}
476967dd82fSFlorian Fainelli 
477967dd82fSFlorian Fainelli 	return -ETIMEDOUT;
478967dd82fSFlorian Fainelli out:
479967dd82fSFlorian Fainelli 	/* Only age dynamic entries (default behavior) */
480967dd82fSFlorian Fainelli 	b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL, FAST_AGE_DYNAMIC);
481967dd82fSFlorian Fainelli 	return 0;
482967dd82fSFlorian Fainelli }
483967dd82fSFlorian Fainelli 
484ff39c2d6SFlorian Fainelli static int b53_fast_age_port(struct b53_device *dev, int port)
485ff39c2d6SFlorian Fainelli {
486ff39c2d6SFlorian Fainelli 	b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_PORT_CTRL, port);
487ff39c2d6SFlorian Fainelli 
488ff39c2d6SFlorian Fainelli 	return b53_flush_arl(dev, FAST_AGE_PORT);
489ff39c2d6SFlorian Fainelli }
490ff39c2d6SFlorian Fainelli 
491a2482d2cSFlorian Fainelli static int b53_fast_age_vlan(struct b53_device *dev, u16 vid)
492a2482d2cSFlorian Fainelli {
493a2482d2cSFlorian Fainelli 	b53_write16(dev, B53_CTRL_PAGE, B53_FAST_AGE_VID_CTRL, vid);
494a2482d2cSFlorian Fainelli 
495a2482d2cSFlorian Fainelli 	return b53_flush_arl(dev, FAST_AGE_VLAN);
496a2482d2cSFlorian Fainelli }
497a2482d2cSFlorian Fainelli 
498aac02867SFlorian Fainelli void b53_imp_vlan_setup(struct dsa_switch *ds, int cpu_port)
499ff39c2d6SFlorian Fainelli {
50004bed143SVivien Didelot 	struct b53_device *dev = ds->priv;
501ff39c2d6SFlorian Fainelli 	unsigned int i;
502ff39c2d6SFlorian Fainelli 	u16 pvlan;
503ff39c2d6SFlorian Fainelli 
504ff39c2d6SFlorian Fainelli 	/* Enable the IMP port to be in the same VLAN as the other ports
505ff39c2d6SFlorian Fainelli 	 * on a per-port basis such that we only have Port i and IMP in
506ff39c2d6SFlorian Fainelli 	 * the same VLAN.
507ff39c2d6SFlorian Fainelli 	 */
508ff39c2d6SFlorian Fainelli 	b53_for_each_port(dev, i) {
509ff39c2d6SFlorian Fainelli 		b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), &pvlan);
510ff39c2d6SFlorian Fainelli 		pvlan |= BIT(cpu_port);
511ff39c2d6SFlorian Fainelli 		b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), pvlan);
512ff39c2d6SFlorian Fainelli 	}
513ff39c2d6SFlorian Fainelli }
514aac02867SFlorian Fainelli EXPORT_SYMBOL(b53_imp_vlan_setup);
515ff39c2d6SFlorian Fainelli 
516a8b659e7SVladimir Oltean static void b53_port_set_ucast_flood(struct b53_device *dev, int port,
517a8b659e7SVladimir Oltean 				     bool unicast)
518a8b659e7SVladimir Oltean {
519a8b659e7SVladimir Oltean 	u16 uc;
520a8b659e7SVladimir Oltean 
521a8b659e7SVladimir Oltean 	b53_read16(dev, B53_CTRL_PAGE, B53_UC_FLOOD_MASK, &uc);
522a8b659e7SVladimir Oltean 	if (unicast)
523a8b659e7SVladimir Oltean 		uc |= BIT(port);
524a8b659e7SVladimir Oltean 	else
525a8b659e7SVladimir Oltean 		uc &= ~BIT(port);
526a8b659e7SVladimir Oltean 	b53_write16(dev, B53_CTRL_PAGE, B53_UC_FLOOD_MASK, uc);
527a8b659e7SVladimir Oltean }
528a8b659e7SVladimir Oltean 
529a8b659e7SVladimir Oltean static void b53_port_set_mcast_flood(struct b53_device *dev, int port,
530a8b659e7SVladimir Oltean 				     bool multicast)
531a8b659e7SVladimir Oltean {
532a8b659e7SVladimir Oltean 	u16 mc;
533a8b659e7SVladimir Oltean 
534a8b659e7SVladimir Oltean 	b53_read16(dev, B53_CTRL_PAGE, B53_MC_FLOOD_MASK, &mc);
535a8b659e7SVladimir Oltean 	if (multicast)
536a8b659e7SVladimir Oltean 		mc |= BIT(port);
537a8b659e7SVladimir Oltean 	else
538a8b659e7SVladimir Oltean 		mc &= ~BIT(port);
539a8b659e7SVladimir Oltean 	b53_write16(dev, B53_CTRL_PAGE, B53_MC_FLOOD_MASK, mc);
540a8b659e7SVladimir Oltean 
541a8b659e7SVladimir Oltean 	b53_read16(dev, B53_CTRL_PAGE, B53_IPMC_FLOOD_MASK, &mc);
542a8b659e7SVladimir Oltean 	if (multicast)
543a8b659e7SVladimir Oltean 		mc |= BIT(port);
544a8b659e7SVladimir Oltean 	else
545a8b659e7SVladimir Oltean 		mc &= ~BIT(port);
546a8b659e7SVladimir Oltean 	b53_write16(dev, B53_CTRL_PAGE, B53_IPMC_FLOOD_MASK, mc);
547a8b659e7SVladimir Oltean }
548a8b659e7SVladimir Oltean 
549f9b3827eSFlorian Fainelli static void b53_port_set_learning(struct b53_device *dev, int port,
550f9b3827eSFlorian Fainelli 				  bool learning)
551f9b3827eSFlorian Fainelli {
552f9b3827eSFlorian Fainelli 	u16 reg;
553f9b3827eSFlorian Fainelli 
554f9b3827eSFlorian Fainelli 	b53_read16(dev, B53_CTRL_PAGE, B53_DIS_LEARNING, &reg);
555f9b3827eSFlorian Fainelli 	if (learning)
556f9b3827eSFlorian Fainelli 		reg &= ~BIT(port);
557f9b3827eSFlorian Fainelli 	else
558f9b3827eSFlorian Fainelli 		reg |= BIT(port);
559f9b3827eSFlorian Fainelli 	b53_write16(dev, B53_CTRL_PAGE, B53_DIS_LEARNING, reg);
560f9b3827eSFlorian Fainelli }
561f9b3827eSFlorian Fainelli 
562f86ad77fSFlorian Fainelli int b53_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy)
563967dd82fSFlorian Fainelli {
56404bed143SVivien Didelot 	struct b53_device *dev = ds->priv;
56574be4babSVivien Didelot 	unsigned int cpu_port;
5668ca7c160SFlorian Fainelli 	int ret = 0;
567ff39c2d6SFlorian Fainelli 	u16 pvlan;
568967dd82fSFlorian Fainelli 
56974be4babSVivien Didelot 	if (!dsa_is_user_port(ds, port))
57074be4babSVivien Didelot 		return 0;
57174be4babSVivien Didelot 
57268bb8ea8SVivien Didelot 	cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
57374be4babSVivien Didelot 
574a8b659e7SVladimir Oltean 	b53_port_set_ucast_flood(dev, port, true);
575a8b659e7SVladimir Oltean 	b53_port_set_mcast_flood(dev, port, true);
576f9b3827eSFlorian Fainelli 	b53_port_set_learning(dev, port, false);
57763cc54a6SFlorian Fainelli 
5788ca7c160SFlorian Fainelli 	if (dev->ops->irq_enable)
5798ca7c160SFlorian Fainelli 		ret = dev->ops->irq_enable(dev, port);
5808ca7c160SFlorian Fainelli 	if (ret)
5818ca7c160SFlorian Fainelli 		return ret;
5828ca7c160SFlorian Fainelli 
583967dd82fSFlorian Fainelli 	/* Clear the Rx and Tx disable bits and set to no spanning tree */
584967dd82fSFlorian Fainelli 	b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), 0);
585967dd82fSFlorian Fainelli 
586ff39c2d6SFlorian Fainelli 	/* Set this port, and only this one to be in the default VLAN,
587ff39c2d6SFlorian Fainelli 	 * if member of a bridge, restore its membership prior to
588ff39c2d6SFlorian Fainelli 	 * bringing down this port.
589ff39c2d6SFlorian Fainelli 	 */
590ff39c2d6SFlorian Fainelli 	b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan);
591ff39c2d6SFlorian Fainelli 	pvlan &= ~0x1ff;
592ff39c2d6SFlorian Fainelli 	pvlan |= BIT(port);
593ff39c2d6SFlorian Fainelli 	pvlan |= dev->ports[port].vlan_ctl_mask;
594ff39c2d6SFlorian Fainelli 	b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan);
595ff39c2d6SFlorian Fainelli 
596ff39c2d6SFlorian Fainelli 	b53_imp_vlan_setup(ds, cpu_port);
597ff39c2d6SFlorian Fainelli 
598f43a2dbeSFlorian Fainelli 	/* If EEE was enabled, restore it */
599f43a2dbeSFlorian Fainelli 	if (dev->ports[port].eee.eee_enabled)
600f43a2dbeSFlorian Fainelli 		b53_eee_enable_set(ds, port, true);
601f43a2dbeSFlorian Fainelli 
602967dd82fSFlorian Fainelli 	return 0;
603967dd82fSFlorian Fainelli }
604f86ad77fSFlorian Fainelli EXPORT_SYMBOL(b53_enable_port);
605967dd82fSFlorian Fainelli 
60675104db0SAndrew Lunn void b53_disable_port(struct dsa_switch *ds, int port)
607967dd82fSFlorian Fainelli {
60804bed143SVivien Didelot 	struct b53_device *dev = ds->priv;
609967dd82fSFlorian Fainelli 	u8 reg;
610967dd82fSFlorian Fainelli 
611967dd82fSFlorian Fainelli 	/* Disable Tx/Rx for the port */
612967dd82fSFlorian Fainelli 	b53_read8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), &reg);
613967dd82fSFlorian Fainelli 	reg |= PORT_CTRL_RX_DISABLE | PORT_CTRL_TX_DISABLE;
614967dd82fSFlorian Fainelli 	b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), reg);
6158ca7c160SFlorian Fainelli 
6168ca7c160SFlorian Fainelli 	if (dev->ops->irq_disable)
6178ca7c160SFlorian Fainelli 		dev->ops->irq_disable(dev, port);
618967dd82fSFlorian Fainelli }
619f86ad77fSFlorian Fainelli EXPORT_SYMBOL(b53_disable_port);
620967dd82fSFlorian Fainelli 
621b409a9efSFlorian Fainelli void b53_brcm_hdr_setup(struct dsa_switch *ds, int port)
622b409a9efSFlorian Fainelli {
623b409a9efSFlorian Fainelli 	struct b53_device *dev = ds->priv;
6244d776482SFlorian Fainelli 	bool tag_en = !(dev->tag_protocol == DSA_TAG_PROTO_NONE);
625b409a9efSFlorian Fainelli 	u8 hdr_ctl, val;
626b409a9efSFlorian Fainelli 	u16 reg;
627b409a9efSFlorian Fainelli 
628b409a9efSFlorian Fainelli 	/* Resolve which bit controls the Broadcom tag */
629b409a9efSFlorian Fainelli 	switch (port) {
630b409a9efSFlorian Fainelli 	case 8:
631b409a9efSFlorian Fainelli 		val = BRCM_HDR_P8_EN;
632b409a9efSFlorian Fainelli 		break;
633b409a9efSFlorian Fainelli 	case 7:
634b409a9efSFlorian Fainelli 		val = BRCM_HDR_P7_EN;
635b409a9efSFlorian Fainelli 		break;
636b409a9efSFlorian Fainelli 	case 5:
637b409a9efSFlorian Fainelli 		val = BRCM_HDR_P5_EN;
638b409a9efSFlorian Fainelli 		break;
639b409a9efSFlorian Fainelli 	default:
640b409a9efSFlorian Fainelli 		val = 0;
641b409a9efSFlorian Fainelli 		break;
642b409a9efSFlorian Fainelli 	}
643b409a9efSFlorian Fainelli 
6448fab459eSFlorian Fainelli 	/* Enable management mode if tagging is requested */
6458fab459eSFlorian Fainelli 	b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &hdr_ctl);
6468fab459eSFlorian Fainelli 	if (tag_en)
6478fab459eSFlorian Fainelli 		hdr_ctl |= SM_SW_FWD_MODE;
6488fab459eSFlorian Fainelli 	else
6498fab459eSFlorian Fainelli 		hdr_ctl &= ~SM_SW_FWD_MODE;
6508fab459eSFlorian Fainelli 	b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, hdr_ctl);
6518fab459eSFlorian Fainelli 
6528fab459eSFlorian Fainelli 	/* Configure the appropriate IMP port */
6538fab459eSFlorian Fainelli 	b53_read8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &hdr_ctl);
6548fab459eSFlorian Fainelli 	if (port == 8)
6558fab459eSFlorian Fainelli 		hdr_ctl |= GC_FRM_MGMT_PORT_MII;
6568fab459eSFlorian Fainelli 	else if (port == 5)
6578fab459eSFlorian Fainelli 		hdr_ctl |= GC_FRM_MGMT_PORT_M;
6588fab459eSFlorian Fainelli 	b53_write8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, hdr_ctl);
6598fab459eSFlorian Fainelli 
660b409a9efSFlorian Fainelli 	/* Enable Broadcom tags for IMP port */
661b409a9efSFlorian Fainelli 	b53_read8(dev, B53_MGMT_PAGE, B53_BRCM_HDR, &hdr_ctl);
662cdb583cfSFlorian Fainelli 	if (tag_en)
663b409a9efSFlorian Fainelli 		hdr_ctl |= val;
664cdb583cfSFlorian Fainelli 	else
665cdb583cfSFlorian Fainelli 		hdr_ctl &= ~val;
666b409a9efSFlorian Fainelli 	b53_write8(dev, B53_MGMT_PAGE, B53_BRCM_HDR, hdr_ctl);
667b409a9efSFlorian Fainelli 
668b409a9efSFlorian Fainelli 	/* Registers below are only accessible on newer devices */
669b409a9efSFlorian Fainelli 	if (!is58xx(dev))
670b409a9efSFlorian Fainelli 		return;
671b409a9efSFlorian Fainelli 
672b409a9efSFlorian Fainelli 	/* Enable reception Broadcom tag for CPU TX (switch RX) to
673b409a9efSFlorian Fainelli 	 * allow us to tag outgoing frames
674b409a9efSFlorian Fainelli 	 */
675b409a9efSFlorian Fainelli 	b53_read16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_RX_DIS, &reg);
676cdb583cfSFlorian Fainelli 	if (tag_en)
677b409a9efSFlorian Fainelli 		reg &= ~BIT(port);
678cdb583cfSFlorian Fainelli 	else
679cdb583cfSFlorian Fainelli 		reg |= BIT(port);
680b409a9efSFlorian Fainelli 	b53_write16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_RX_DIS, reg);
681b409a9efSFlorian Fainelli 
682b409a9efSFlorian Fainelli 	/* Enable transmission of Broadcom tags from the switch (CPU RX) to
683b409a9efSFlorian Fainelli 	 * allow delivering frames to the per-port net_devices
684b409a9efSFlorian Fainelli 	 */
685b409a9efSFlorian Fainelli 	b53_read16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_TX_DIS, &reg);
686cdb583cfSFlorian Fainelli 	if (tag_en)
687b409a9efSFlorian Fainelli 		reg &= ~BIT(port);
688cdb583cfSFlorian Fainelli 	else
689cdb583cfSFlorian Fainelli 		reg |= BIT(port);
690b409a9efSFlorian Fainelli 	b53_write16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_TX_DIS, reg);
691b409a9efSFlorian Fainelli }
692b409a9efSFlorian Fainelli EXPORT_SYMBOL(b53_brcm_hdr_setup);
693b409a9efSFlorian Fainelli 
694299752a7SFlorian Fainelli static void b53_enable_cpu_port(struct b53_device *dev, int port)
695967dd82fSFlorian Fainelli {
696967dd82fSFlorian Fainelli 	u8 port_ctrl;
697967dd82fSFlorian Fainelli 
698967dd82fSFlorian Fainelli 	/* BCM5325 CPU port is at 8 */
699299752a7SFlorian Fainelli 	if ((is5325(dev) || is5365(dev)) && port == B53_CPU_PORT_25)
700299752a7SFlorian Fainelli 		port = B53_CPU_PORT;
701967dd82fSFlorian Fainelli 
702967dd82fSFlorian Fainelli 	port_ctrl = PORT_CTRL_RX_BCST_EN |
703967dd82fSFlorian Fainelli 		    PORT_CTRL_RX_MCST_EN |
704967dd82fSFlorian Fainelli 		    PORT_CTRL_RX_UCST_EN;
705299752a7SFlorian Fainelli 	b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), port_ctrl);
7067edc58d6SFlorian Fainelli 
7077edc58d6SFlorian Fainelli 	b53_brcm_hdr_setup(dev->ds, port);
70863cc54a6SFlorian Fainelli 
709a8b659e7SVladimir Oltean 	b53_port_set_ucast_flood(dev, port, true);
710a8b659e7SVladimir Oltean 	b53_port_set_mcast_flood(dev, port, true);
711f9b3827eSFlorian Fainelli 	b53_port_set_learning(dev, port, false);
712967dd82fSFlorian Fainelli }
713967dd82fSFlorian Fainelli 
714967dd82fSFlorian Fainelli static void b53_enable_mib(struct b53_device *dev)
715967dd82fSFlorian Fainelli {
716967dd82fSFlorian Fainelli 	u8 gc;
717967dd82fSFlorian Fainelli 
718967dd82fSFlorian Fainelli 	b53_read8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &gc);
719967dd82fSFlorian Fainelli 	gc &= ~(GC_RESET_MIB | GC_MIB_AC_EN);
720967dd82fSFlorian Fainelli 	b53_write8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc);
721967dd82fSFlorian Fainelli }
722967dd82fSFlorian Fainelli 
723fea83353SFlorian Fainelli static u16 b53_default_pvid(struct b53_device *dev)
724fea83353SFlorian Fainelli {
725fea83353SFlorian Fainelli 	if (is5325(dev) || is5365(dev))
726fea83353SFlorian Fainelli 		return 1;
727fea83353SFlorian Fainelli 	else
728fea83353SFlorian Fainelli 		return 0;
729fea83353SFlorian Fainelli }
730fea83353SFlorian Fainelli 
7315c1a6eafSFlorian Fainelli int b53_configure_vlan(struct dsa_switch *ds)
732967dd82fSFlorian Fainelli {
7335c1a6eafSFlorian Fainelli 	struct b53_device *dev = ds->priv;
734a2482d2cSFlorian Fainelli 	struct b53_vlan vl = { 0 };
735d7a0b1f7SFlorian Fainelli 	struct b53_vlan *v;
736fea83353SFlorian Fainelli 	int i, def_vid;
737d7a0b1f7SFlorian Fainelli 	u16 vid;
738fea83353SFlorian Fainelli 
739fea83353SFlorian Fainelli 	def_vid = b53_default_pvid(dev);
740967dd82fSFlorian Fainelli 
741967dd82fSFlorian Fainelli 	/* clear all vlan entries */
742967dd82fSFlorian Fainelli 	if (is5325(dev) || is5365(dev)) {
743fea83353SFlorian Fainelli 		for (i = def_vid; i < dev->num_vlans; i++)
744a2482d2cSFlorian Fainelli 			b53_set_vlan_entry(dev, i, &vl);
745967dd82fSFlorian Fainelli 	} else {
746967dd82fSFlorian Fainelli 		b53_do_vlan_op(dev, VTA_CMD_CLEAR);
747967dd82fSFlorian Fainelli 	}
748967dd82fSFlorian Fainelli 
749ee47ed08SFlorian Fainelli 	b53_enable_vlan(dev, -1, dev->vlan_enabled, ds->vlan_filtering);
750967dd82fSFlorian Fainelli 
751967dd82fSFlorian Fainelli 	b53_for_each_port(dev, i)
752967dd82fSFlorian Fainelli 		b53_write16(dev, B53_VLAN_PAGE,
753fea83353SFlorian Fainelli 			    B53_VLAN_PORT_DEF_TAG(i), def_vid);
754967dd82fSFlorian Fainelli 
755d7a0b1f7SFlorian Fainelli 	/* Upon initial call we have not set-up any VLANs, but upon
756d7a0b1f7SFlorian Fainelli 	 * system resume, we need to restore all VLAN entries.
757d7a0b1f7SFlorian Fainelli 	 */
758d7a0b1f7SFlorian Fainelli 	for (vid = def_vid; vid < dev->num_vlans; vid++) {
759d7a0b1f7SFlorian Fainelli 		v = &dev->vlans[vid];
760d7a0b1f7SFlorian Fainelli 
761d7a0b1f7SFlorian Fainelli 		if (!v->members)
762d7a0b1f7SFlorian Fainelli 			continue;
763d7a0b1f7SFlorian Fainelli 
764d7a0b1f7SFlorian Fainelli 		b53_set_vlan_entry(dev, vid, v);
765d7a0b1f7SFlorian Fainelli 		b53_fast_age_vlan(dev, vid);
766d7a0b1f7SFlorian Fainelli 	}
767d7a0b1f7SFlorian Fainelli 
768967dd82fSFlorian Fainelli 	return 0;
769967dd82fSFlorian Fainelli }
7705c1a6eafSFlorian Fainelli EXPORT_SYMBOL(b53_configure_vlan);
771967dd82fSFlorian Fainelli 
772967dd82fSFlorian Fainelli static void b53_switch_reset_gpio(struct b53_device *dev)
773967dd82fSFlorian Fainelli {
774967dd82fSFlorian Fainelli 	int gpio = dev->reset_gpio;
775967dd82fSFlorian Fainelli 
776967dd82fSFlorian Fainelli 	if (gpio < 0)
777967dd82fSFlorian Fainelli 		return;
778967dd82fSFlorian Fainelli 
779967dd82fSFlorian Fainelli 	/* Reset sequence: RESET low(50ms)->high(20ms)
780967dd82fSFlorian Fainelli 	 */
781967dd82fSFlorian Fainelli 	gpio_set_value(gpio, 0);
782967dd82fSFlorian Fainelli 	mdelay(50);
783967dd82fSFlorian Fainelli 
784967dd82fSFlorian Fainelli 	gpio_set_value(gpio, 1);
785967dd82fSFlorian Fainelli 	mdelay(20);
786967dd82fSFlorian Fainelli 
787967dd82fSFlorian Fainelli 	dev->current_page = 0xff;
788967dd82fSFlorian Fainelli }
789967dd82fSFlorian Fainelli 
790967dd82fSFlorian Fainelli static int b53_switch_reset(struct b53_device *dev)
791967dd82fSFlorian Fainelli {
7923fb22b05SFlorian Fainelli 	unsigned int timeout = 1000;
7933fb22b05SFlorian Fainelli 	u8 mgmt, reg;
794967dd82fSFlorian Fainelli 
795967dd82fSFlorian Fainelli 	b53_switch_reset_gpio(dev);
796967dd82fSFlorian Fainelli 
797967dd82fSFlorian Fainelli 	if (is539x(dev)) {
798967dd82fSFlorian Fainelli 		b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x83);
799967dd82fSFlorian Fainelli 		b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x00);
800967dd82fSFlorian Fainelli 	}
801967dd82fSFlorian Fainelli 
8023fb22b05SFlorian Fainelli 	/* This is specific to 58xx devices here, do not use is58xx() which
8033fb22b05SFlorian Fainelli 	 * covers the larger Starfigther 2 family, including 7445/7278 which
8043fb22b05SFlorian Fainelli 	 * still use this driver as a library and need to perform the reset
8053fb22b05SFlorian Fainelli 	 * earlier.
8063fb22b05SFlorian Fainelli 	 */
8075040cc99SArun Parameswaran 	if (dev->chip_id == BCM58XX_DEVICE_ID ||
8085040cc99SArun Parameswaran 	    dev->chip_id == BCM583XX_DEVICE_ID) {
8093fb22b05SFlorian Fainelli 		b53_read8(dev, B53_CTRL_PAGE, B53_SOFTRESET, &reg);
8103fb22b05SFlorian Fainelli 		reg |= SW_RST | EN_SW_RST | EN_CH_RST;
8113fb22b05SFlorian Fainelli 		b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, reg);
8123fb22b05SFlorian Fainelli 
8133fb22b05SFlorian Fainelli 		do {
8143fb22b05SFlorian Fainelli 			b53_read8(dev, B53_CTRL_PAGE, B53_SOFTRESET, &reg);
8153fb22b05SFlorian Fainelli 			if (!(reg & SW_RST))
8163fb22b05SFlorian Fainelli 				break;
8173fb22b05SFlorian Fainelli 
8183fb22b05SFlorian Fainelli 			usleep_range(1000, 2000);
8193fb22b05SFlorian Fainelli 		} while (timeout-- > 0);
8203fb22b05SFlorian Fainelli 
821434d2312SPaul Barker 		if (timeout == 0) {
822434d2312SPaul Barker 			dev_err(dev->dev,
823434d2312SPaul Barker 				"Timeout waiting for SW_RST to clear!\n");
8243fb22b05SFlorian Fainelli 			return -ETIMEDOUT;
8253fb22b05SFlorian Fainelli 		}
826434d2312SPaul Barker 	}
8273fb22b05SFlorian Fainelli 
828967dd82fSFlorian Fainelli 	b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt);
829967dd82fSFlorian Fainelli 
830967dd82fSFlorian Fainelli 	if (!(mgmt & SM_SW_FWD_EN)) {
831967dd82fSFlorian Fainelli 		mgmt &= ~SM_SW_FWD_MODE;
832967dd82fSFlorian Fainelli 		mgmt |= SM_SW_FWD_EN;
833967dd82fSFlorian Fainelli 
834967dd82fSFlorian Fainelli 		b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt);
835967dd82fSFlorian Fainelli 		b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt);
836967dd82fSFlorian Fainelli 
837967dd82fSFlorian Fainelli 		if (!(mgmt & SM_SW_FWD_EN)) {
838967dd82fSFlorian Fainelli 			dev_err(dev->dev, "Failed to enable switch!\n");
839967dd82fSFlorian Fainelli 			return -EINVAL;
840967dd82fSFlorian Fainelli 		}
841967dd82fSFlorian Fainelli 	}
842967dd82fSFlorian Fainelli 
843967dd82fSFlorian Fainelli 	b53_enable_mib(dev);
844967dd82fSFlorian Fainelli 
845ff39c2d6SFlorian Fainelli 	return b53_flush_arl(dev, FAST_AGE_STATIC);
846967dd82fSFlorian Fainelli }
847967dd82fSFlorian Fainelli 
848967dd82fSFlorian Fainelli static int b53_phy_read16(struct dsa_switch *ds, int addr, int reg)
849967dd82fSFlorian Fainelli {
85004bed143SVivien Didelot 	struct b53_device *priv = ds->priv;
851967dd82fSFlorian Fainelli 	u16 value = 0;
852967dd82fSFlorian Fainelli 	int ret;
853967dd82fSFlorian Fainelli 
854967dd82fSFlorian Fainelli 	if (priv->ops->phy_read16)
855967dd82fSFlorian Fainelli 		ret = priv->ops->phy_read16(priv, addr, reg, &value);
856967dd82fSFlorian Fainelli 	else
857967dd82fSFlorian Fainelli 		ret = b53_read16(priv, B53_PORT_MII_PAGE(addr),
858967dd82fSFlorian Fainelli 				 reg * 2, &value);
859967dd82fSFlorian Fainelli 
860967dd82fSFlorian Fainelli 	return ret ? ret : value;
861967dd82fSFlorian Fainelli }
862967dd82fSFlorian Fainelli 
863967dd82fSFlorian Fainelli static int b53_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val)
864967dd82fSFlorian Fainelli {
86504bed143SVivien Didelot 	struct b53_device *priv = ds->priv;
866967dd82fSFlorian Fainelli 
867967dd82fSFlorian Fainelli 	if (priv->ops->phy_write16)
868967dd82fSFlorian Fainelli 		return priv->ops->phy_write16(priv, addr, reg, val);
869967dd82fSFlorian Fainelli 
870967dd82fSFlorian Fainelli 	return b53_write16(priv, B53_PORT_MII_PAGE(addr), reg * 2, val);
871967dd82fSFlorian Fainelli }
872967dd82fSFlorian Fainelli 
873967dd82fSFlorian Fainelli static int b53_reset_switch(struct b53_device *priv)
874967dd82fSFlorian Fainelli {
875967dd82fSFlorian Fainelli 	/* reset vlans */
876a2482d2cSFlorian Fainelli 	memset(priv->vlans, 0, sizeof(*priv->vlans) * priv->num_vlans);
877967dd82fSFlorian Fainelli 	memset(priv->ports, 0, sizeof(*priv->ports) * priv->num_ports);
878967dd82fSFlorian Fainelli 
8790e01491dSFlorian Fainelli 	priv->serdes_lane = B53_INVALID_LANE;
8800e01491dSFlorian Fainelli 
881967dd82fSFlorian Fainelli 	return b53_switch_reset(priv);
882967dd82fSFlorian Fainelli }
883967dd82fSFlorian Fainelli 
884967dd82fSFlorian Fainelli static int b53_apply_config(struct b53_device *priv)
885967dd82fSFlorian Fainelli {
886967dd82fSFlorian Fainelli 	/* disable switching */
887967dd82fSFlorian Fainelli 	b53_set_forwarding(priv, 0);
888967dd82fSFlorian Fainelli 
8895c1a6eafSFlorian Fainelli 	b53_configure_vlan(priv->ds);
890967dd82fSFlorian Fainelli 
891967dd82fSFlorian Fainelli 	/* enable switching */
892967dd82fSFlorian Fainelli 	b53_set_forwarding(priv, 1);
893967dd82fSFlorian Fainelli 
894967dd82fSFlorian Fainelli 	return 0;
895967dd82fSFlorian Fainelli }
896967dd82fSFlorian Fainelli 
897967dd82fSFlorian Fainelli static void b53_reset_mib(struct b53_device *priv)
898967dd82fSFlorian Fainelli {
899967dd82fSFlorian Fainelli 	u8 gc;
900967dd82fSFlorian Fainelli 
901967dd82fSFlorian Fainelli 	b53_read8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &gc);
902967dd82fSFlorian Fainelli 
903967dd82fSFlorian Fainelli 	b53_write8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc | GC_RESET_MIB);
904967dd82fSFlorian Fainelli 	msleep(1);
905967dd82fSFlorian Fainelli 	b53_write8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc & ~GC_RESET_MIB);
906967dd82fSFlorian Fainelli 	msleep(1);
907967dd82fSFlorian Fainelli }
908967dd82fSFlorian Fainelli 
909967dd82fSFlorian Fainelli static const struct b53_mib_desc *b53_get_mib(struct b53_device *dev)
910967dd82fSFlorian Fainelli {
911967dd82fSFlorian Fainelli 	if (is5365(dev))
912967dd82fSFlorian Fainelli 		return b53_mibs_65;
913967dd82fSFlorian Fainelli 	else if (is63xx(dev))
914967dd82fSFlorian Fainelli 		return b53_mibs_63xx;
915bde5d132SFlorian Fainelli 	else if (is58xx(dev))
916bde5d132SFlorian Fainelli 		return b53_mibs_58xx;
917967dd82fSFlorian Fainelli 	else
918967dd82fSFlorian Fainelli 		return b53_mibs;
919967dd82fSFlorian Fainelli }
920967dd82fSFlorian Fainelli 
921967dd82fSFlorian Fainelli static unsigned int b53_get_mib_size(struct b53_device *dev)
922967dd82fSFlorian Fainelli {
923967dd82fSFlorian Fainelli 	if (is5365(dev))
924967dd82fSFlorian Fainelli 		return B53_MIBS_65_SIZE;
925967dd82fSFlorian Fainelli 	else if (is63xx(dev))
926967dd82fSFlorian Fainelli 		return B53_MIBS_63XX_SIZE;
927bde5d132SFlorian Fainelli 	else if (is58xx(dev))
928bde5d132SFlorian Fainelli 		return B53_MIBS_58XX_SIZE;
929967dd82fSFlorian Fainelli 	else
930967dd82fSFlorian Fainelli 		return B53_MIBS_SIZE;
931967dd82fSFlorian Fainelli }
932967dd82fSFlorian Fainelli 
933c7d28c9dSFlorian Fainelli static struct phy_device *b53_get_phy_device(struct dsa_switch *ds, int port)
934c7d28c9dSFlorian Fainelli {
935c7d28c9dSFlorian Fainelli 	/* These ports typically do not have built-in PHYs */
936c7d28c9dSFlorian Fainelli 	switch (port) {
937c7d28c9dSFlorian Fainelli 	case B53_CPU_PORT_25:
938c7d28c9dSFlorian Fainelli 	case 7:
939c7d28c9dSFlorian Fainelli 	case B53_CPU_PORT:
940c7d28c9dSFlorian Fainelli 		return NULL;
941c7d28c9dSFlorian Fainelli 	}
942c7d28c9dSFlorian Fainelli 
943c7d28c9dSFlorian Fainelli 	return mdiobus_get_phy(ds->slave_mii_bus, port);
944c7d28c9dSFlorian Fainelli }
945c7d28c9dSFlorian Fainelli 
94689f09048SFlorian Fainelli void b53_get_strings(struct dsa_switch *ds, int port, u32 stringset,
94789f09048SFlorian Fainelli 		     uint8_t *data)
948967dd82fSFlorian Fainelli {
94904bed143SVivien Didelot 	struct b53_device *dev = ds->priv;
950967dd82fSFlorian Fainelli 	const struct b53_mib_desc *mibs = b53_get_mib(dev);
951967dd82fSFlorian Fainelli 	unsigned int mib_size = b53_get_mib_size(dev);
952c7d28c9dSFlorian Fainelli 	struct phy_device *phydev;
953967dd82fSFlorian Fainelli 	unsigned int i;
954967dd82fSFlorian Fainelli 
955c7d28c9dSFlorian Fainelli 	if (stringset == ETH_SS_STATS) {
956967dd82fSFlorian Fainelli 		for (i = 0; i < mib_size; i++)
957cd526676SFlorian Fainelli 			strlcpy(data + i * ETH_GSTRING_LEN,
958967dd82fSFlorian Fainelli 				mibs[i].name, ETH_GSTRING_LEN);
959c7d28c9dSFlorian Fainelli 	} else if (stringset == ETH_SS_PHY_STATS) {
960c7d28c9dSFlorian Fainelli 		phydev = b53_get_phy_device(ds, port);
961c7d28c9dSFlorian Fainelli 		if (!phydev)
962c7d28c9dSFlorian Fainelli 			return;
963c7d28c9dSFlorian Fainelli 
964c7d28c9dSFlorian Fainelli 		phy_ethtool_get_strings(phydev, data);
965c7d28c9dSFlorian Fainelli 	}
966967dd82fSFlorian Fainelli }
9673117455dSFlorian Fainelli EXPORT_SYMBOL(b53_get_strings);
968967dd82fSFlorian Fainelli 
9693117455dSFlorian Fainelli void b53_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data)
970967dd82fSFlorian Fainelli {
97104bed143SVivien Didelot 	struct b53_device *dev = ds->priv;
972967dd82fSFlorian Fainelli 	const struct b53_mib_desc *mibs = b53_get_mib(dev);
973967dd82fSFlorian Fainelli 	unsigned int mib_size = b53_get_mib_size(dev);
974967dd82fSFlorian Fainelli 	const struct b53_mib_desc *s;
975967dd82fSFlorian Fainelli 	unsigned int i;
976967dd82fSFlorian Fainelli 	u64 val = 0;
977967dd82fSFlorian Fainelli 
978967dd82fSFlorian Fainelli 	if (is5365(dev) && port == 5)
979967dd82fSFlorian Fainelli 		port = 8;
980967dd82fSFlorian Fainelli 
981967dd82fSFlorian Fainelli 	mutex_lock(&dev->stats_mutex);
982967dd82fSFlorian Fainelli 
983967dd82fSFlorian Fainelli 	for (i = 0; i < mib_size; i++) {
984967dd82fSFlorian Fainelli 		s = &mibs[i];
985967dd82fSFlorian Fainelli 
98651dca8a1SFlorian Fainelli 		if (s->size == 8) {
987967dd82fSFlorian Fainelli 			b53_read64(dev, B53_MIB_PAGE(port), s->offset, &val);
988967dd82fSFlorian Fainelli 		} else {
989967dd82fSFlorian Fainelli 			u32 val32;
990967dd82fSFlorian Fainelli 
991967dd82fSFlorian Fainelli 			b53_read32(dev, B53_MIB_PAGE(port), s->offset,
992967dd82fSFlorian Fainelli 				   &val32);
993967dd82fSFlorian Fainelli 			val = val32;
994967dd82fSFlorian Fainelli 		}
995967dd82fSFlorian Fainelli 		data[i] = (u64)val;
996967dd82fSFlorian Fainelli 	}
997967dd82fSFlorian Fainelli 
998967dd82fSFlorian Fainelli 	mutex_unlock(&dev->stats_mutex);
999967dd82fSFlorian Fainelli }
10003117455dSFlorian Fainelli EXPORT_SYMBOL(b53_get_ethtool_stats);
1001967dd82fSFlorian Fainelli 
1002c7d28c9dSFlorian Fainelli void b53_get_ethtool_phy_stats(struct dsa_switch *ds, int port, uint64_t *data)
1003c7d28c9dSFlorian Fainelli {
1004c7d28c9dSFlorian Fainelli 	struct phy_device *phydev;
1005c7d28c9dSFlorian Fainelli 
1006c7d28c9dSFlorian Fainelli 	phydev = b53_get_phy_device(ds, port);
1007c7d28c9dSFlorian Fainelli 	if (!phydev)
1008c7d28c9dSFlorian Fainelli 		return;
1009c7d28c9dSFlorian Fainelli 
1010c7d28c9dSFlorian Fainelli 	phy_ethtool_get_stats(phydev, NULL, data);
1011c7d28c9dSFlorian Fainelli }
1012c7d28c9dSFlorian Fainelli EXPORT_SYMBOL(b53_get_ethtool_phy_stats);
1013c7d28c9dSFlorian Fainelli 
101489f09048SFlorian Fainelli int b53_get_sset_count(struct dsa_switch *ds, int port, int sset)
1015967dd82fSFlorian Fainelli {
101604bed143SVivien Didelot 	struct b53_device *dev = ds->priv;
1017c7d28c9dSFlorian Fainelli 	struct phy_device *phydev;
1018967dd82fSFlorian Fainelli 
1019c7d28c9dSFlorian Fainelli 	if (sset == ETH_SS_STATS) {
1020c7d28c9dSFlorian Fainelli 		return b53_get_mib_size(dev);
1021c7d28c9dSFlorian Fainelli 	} else if (sset == ETH_SS_PHY_STATS) {
1022c7d28c9dSFlorian Fainelli 		phydev = b53_get_phy_device(ds, port);
1023c7d28c9dSFlorian Fainelli 		if (!phydev)
102489f09048SFlorian Fainelli 			return 0;
102589f09048SFlorian Fainelli 
1026c7d28c9dSFlorian Fainelli 		return phy_ethtool_get_sset_count(phydev);
1027c7d28c9dSFlorian Fainelli 	}
1028c7d28c9dSFlorian Fainelli 
1029c7d28c9dSFlorian Fainelli 	return 0;
1030967dd82fSFlorian Fainelli }
10313117455dSFlorian Fainelli EXPORT_SYMBOL(b53_get_sset_count);
1032967dd82fSFlorian Fainelli 
10334f6a5cafSFlorian Fainelli enum b53_devlink_resource_id {
10344f6a5cafSFlorian Fainelli 	B53_DEVLINK_PARAM_ID_VLAN_TABLE,
10354f6a5cafSFlorian Fainelli };
10364f6a5cafSFlorian Fainelli 
10374f6a5cafSFlorian Fainelli static u64 b53_devlink_vlan_table_get(void *priv)
10384f6a5cafSFlorian Fainelli {
10394f6a5cafSFlorian Fainelli 	struct b53_device *dev = priv;
10404f6a5cafSFlorian Fainelli 	struct b53_vlan *vl;
10414f6a5cafSFlorian Fainelli 	unsigned int i;
10424f6a5cafSFlorian Fainelli 	u64 count = 0;
10434f6a5cafSFlorian Fainelli 
10444f6a5cafSFlorian Fainelli 	for (i = 0; i < dev->num_vlans; i++) {
10454f6a5cafSFlorian Fainelli 		vl = &dev->vlans[i];
10464f6a5cafSFlorian Fainelli 		if (vl->members)
10474f6a5cafSFlorian Fainelli 			count++;
10484f6a5cafSFlorian Fainelli 	}
10494f6a5cafSFlorian Fainelli 
10504f6a5cafSFlorian Fainelli 	return count;
10514f6a5cafSFlorian Fainelli }
10524f6a5cafSFlorian Fainelli 
10534f6a5cafSFlorian Fainelli int b53_setup_devlink_resources(struct dsa_switch *ds)
10544f6a5cafSFlorian Fainelli {
10554f6a5cafSFlorian Fainelli 	struct devlink_resource_size_params size_params;
10564f6a5cafSFlorian Fainelli 	struct b53_device *dev = ds->priv;
10574f6a5cafSFlorian Fainelli 	int err;
10584f6a5cafSFlorian Fainelli 
10594f6a5cafSFlorian Fainelli 	devlink_resource_size_params_init(&size_params, dev->num_vlans,
10604f6a5cafSFlorian Fainelli 					  dev->num_vlans,
10614f6a5cafSFlorian Fainelli 					  1, DEVLINK_RESOURCE_UNIT_ENTRY);
10624f6a5cafSFlorian Fainelli 
10634f6a5cafSFlorian Fainelli 	err = dsa_devlink_resource_register(ds, "VLAN", dev->num_vlans,
10644f6a5cafSFlorian Fainelli 					    B53_DEVLINK_PARAM_ID_VLAN_TABLE,
10654f6a5cafSFlorian Fainelli 					    DEVLINK_RESOURCE_ID_PARENT_TOP,
10664f6a5cafSFlorian Fainelli 					    &size_params);
10674f6a5cafSFlorian Fainelli 	if (err)
10684f6a5cafSFlorian Fainelli 		goto out;
10694f6a5cafSFlorian Fainelli 
10704f6a5cafSFlorian Fainelli 	dsa_devlink_resource_occ_get_register(ds,
10714f6a5cafSFlorian Fainelli 					      B53_DEVLINK_PARAM_ID_VLAN_TABLE,
10724f6a5cafSFlorian Fainelli 					      b53_devlink_vlan_table_get, dev);
10734f6a5cafSFlorian Fainelli 
10744f6a5cafSFlorian Fainelli 	return 0;
10754f6a5cafSFlorian Fainelli out:
10764f6a5cafSFlorian Fainelli 	dsa_devlink_resources_unregister(ds);
10774f6a5cafSFlorian Fainelli 	return err;
10784f6a5cafSFlorian Fainelli }
10794f6a5cafSFlorian Fainelli EXPORT_SYMBOL(b53_setup_devlink_resources);
10804f6a5cafSFlorian Fainelli 
1081967dd82fSFlorian Fainelli static int b53_setup(struct dsa_switch *ds)
1082967dd82fSFlorian Fainelli {
108304bed143SVivien Didelot 	struct b53_device *dev = ds->priv;
1084967dd82fSFlorian Fainelli 	unsigned int port;
1085967dd82fSFlorian Fainelli 	int ret;
1086967dd82fSFlorian Fainelli 
1087*2c32a3d3SFlorian Fainelli 	/* Request bridge PVID untagged when DSA_TAG_PROTO_NONE is set
1088*2c32a3d3SFlorian Fainelli 	 * which forces the CPU port to be tagged in all VLANs.
1089*2c32a3d3SFlorian Fainelli 	 */
1090*2c32a3d3SFlorian Fainelli 	ds->untag_bridge_pvid = dev->tag_protocol == DSA_TAG_PROTO_NONE;
1091*2c32a3d3SFlorian Fainelli 
1092967dd82fSFlorian Fainelli 	ret = b53_reset_switch(dev);
1093967dd82fSFlorian Fainelli 	if (ret) {
1094967dd82fSFlorian Fainelli 		dev_err(ds->dev, "failed to reset switch\n");
1095967dd82fSFlorian Fainelli 		return ret;
1096967dd82fSFlorian Fainelli 	}
1097967dd82fSFlorian Fainelli 
1098967dd82fSFlorian Fainelli 	b53_reset_mib(dev);
1099967dd82fSFlorian Fainelli 
1100967dd82fSFlorian Fainelli 	ret = b53_apply_config(dev);
11014f6a5cafSFlorian Fainelli 	if (ret) {
1102967dd82fSFlorian Fainelli 		dev_err(ds->dev, "failed to apply configuration\n");
11034f6a5cafSFlorian Fainelli 		return ret;
11044f6a5cafSFlorian Fainelli 	}
1105967dd82fSFlorian Fainelli 
110675dad252SBenedikt Spranger 	/* Configure IMP/CPU port, disable all other ports. Enabled
110734c8befdSFlorian Fainelli 	 * ports will be configured with .port_enable
110834c8befdSFlorian Fainelli 	 */
1109967dd82fSFlorian Fainelli 	for (port = 0; port < dev->num_ports; port++) {
111034c8befdSFlorian Fainelli 		if (dsa_is_cpu_port(ds, port))
1111299752a7SFlorian Fainelli 			b53_enable_cpu_port(dev, port);
111275dad252SBenedikt Spranger 		else
111375104db0SAndrew Lunn 			b53_disable_port(ds, port);
1114967dd82fSFlorian Fainelli 	}
1115967dd82fSFlorian Fainelli 
11164f6a5cafSFlorian Fainelli 	return b53_setup_devlink_resources(ds);
11174f6a5cafSFlorian Fainelli }
11184f6a5cafSFlorian Fainelli 
11194f6a5cafSFlorian Fainelli static void b53_teardown(struct dsa_switch *ds)
11204f6a5cafSFlorian Fainelli {
11214f6a5cafSFlorian Fainelli 	dsa_devlink_resources_unregister(ds);
1122967dd82fSFlorian Fainelli }
1123967dd82fSFlorian Fainelli 
11245e004460SFlorian Fainelli static void b53_force_link(struct b53_device *dev, int port, int link)
1125967dd82fSFlorian Fainelli {
11265e004460SFlorian Fainelli 	u8 reg, val, off;
1127967dd82fSFlorian Fainelli 
1128967dd82fSFlorian Fainelli 	/* Override the port settings */
1129967dd82fSFlorian Fainelli 	if (port == dev->cpu_port) {
1130967dd82fSFlorian Fainelli 		off = B53_PORT_OVERRIDE_CTRL;
11315e004460SFlorian Fainelli 		val = PORT_OVERRIDE_EN;
1132967dd82fSFlorian Fainelli 	} else {
1133967dd82fSFlorian Fainelli 		off = B53_GMII_PORT_OVERRIDE_CTRL(port);
11345e004460SFlorian Fainelli 		val = GMII_PO_EN;
1135967dd82fSFlorian Fainelli 	}
1136967dd82fSFlorian Fainelli 
11375e004460SFlorian Fainelli 	b53_read8(dev, B53_CTRL_PAGE, off, &reg);
11385e004460SFlorian Fainelli 	reg |= val;
11395e004460SFlorian Fainelli 	if (link)
1140967dd82fSFlorian Fainelli 		reg |= PORT_OVERRIDE_LINK;
11415e004460SFlorian Fainelli 	else
11425e004460SFlorian Fainelli 		reg &= ~PORT_OVERRIDE_LINK;
11435e004460SFlorian Fainelli 	b53_write8(dev, B53_CTRL_PAGE, off, reg);
11445e004460SFlorian Fainelli }
1145967dd82fSFlorian Fainelli 
11465e004460SFlorian Fainelli static void b53_force_port_config(struct b53_device *dev, int port,
11473cad1c8bSRussell King 				  int speed, int duplex,
11483cad1c8bSRussell King 				  bool tx_pause, bool rx_pause)
11495e004460SFlorian Fainelli {
11505e004460SFlorian Fainelli 	u8 reg, val, off;
11515e004460SFlorian Fainelli 
11525e004460SFlorian Fainelli 	/* Override the port settings */
11535e004460SFlorian Fainelli 	if (port == dev->cpu_port) {
11545e004460SFlorian Fainelli 		off = B53_PORT_OVERRIDE_CTRL;
11555e004460SFlorian Fainelli 		val = PORT_OVERRIDE_EN;
11565e004460SFlorian Fainelli 	} else {
11575e004460SFlorian Fainelli 		off = B53_GMII_PORT_OVERRIDE_CTRL(port);
11585e004460SFlorian Fainelli 		val = GMII_PO_EN;
11595e004460SFlorian Fainelli 	}
11605e004460SFlorian Fainelli 
11615e004460SFlorian Fainelli 	b53_read8(dev, B53_CTRL_PAGE, off, &reg);
11625e004460SFlorian Fainelli 	reg |= val;
11635e004460SFlorian Fainelli 	if (duplex == DUPLEX_FULL)
1164967dd82fSFlorian Fainelli 		reg |= PORT_OVERRIDE_FULL_DUPLEX;
11655e004460SFlorian Fainelli 	else
11665e004460SFlorian Fainelli 		reg &= ~PORT_OVERRIDE_FULL_DUPLEX;
1167967dd82fSFlorian Fainelli 
11685e004460SFlorian Fainelli 	switch (speed) {
1169967dd82fSFlorian Fainelli 	case 2000:
1170967dd82fSFlorian Fainelli 		reg |= PORT_OVERRIDE_SPEED_2000M;
1171df561f66SGustavo A. R. Silva 		fallthrough;
1172967dd82fSFlorian Fainelli 	case SPEED_1000:
1173967dd82fSFlorian Fainelli 		reg |= PORT_OVERRIDE_SPEED_1000M;
1174967dd82fSFlorian Fainelli 		break;
1175967dd82fSFlorian Fainelli 	case SPEED_100:
1176967dd82fSFlorian Fainelli 		reg |= PORT_OVERRIDE_SPEED_100M;
1177967dd82fSFlorian Fainelli 		break;
1178967dd82fSFlorian Fainelli 	case SPEED_10:
1179967dd82fSFlorian Fainelli 		reg |= PORT_OVERRIDE_SPEED_10M;
1180967dd82fSFlorian Fainelli 		break;
1181967dd82fSFlorian Fainelli 	default:
11825e004460SFlorian Fainelli 		dev_err(dev->dev, "unknown speed: %d\n", speed);
1183967dd82fSFlorian Fainelli 		return;
1184967dd82fSFlorian Fainelli 	}
1185967dd82fSFlorian Fainelli 
11863cad1c8bSRussell King 	if (rx_pause)
11875e004460SFlorian Fainelli 		reg |= PORT_OVERRIDE_RX_FLOW;
11883cad1c8bSRussell King 	if (tx_pause)
11895e004460SFlorian Fainelli 		reg |= PORT_OVERRIDE_TX_FLOW;
11905e004460SFlorian Fainelli 
11915e004460SFlorian Fainelli 	b53_write8(dev, B53_CTRL_PAGE, off, reg);
11925e004460SFlorian Fainelli }
11935e004460SFlorian Fainelli 
11945e004460SFlorian Fainelli static void b53_adjust_link(struct dsa_switch *ds, int port,
11955e004460SFlorian Fainelli 			    struct phy_device *phydev)
11965e004460SFlorian Fainelli {
11975e004460SFlorian Fainelli 	struct b53_device *dev = ds->priv;
11985e004460SFlorian Fainelli 	struct ethtool_eee *p = &dev->ports[port].eee;
11995e004460SFlorian Fainelli 	u8 rgmii_ctrl = 0, reg = 0, off;
12003cad1c8bSRussell King 	bool tx_pause = false;
12013cad1c8bSRussell King 	bool rx_pause = false;
12025e004460SFlorian Fainelli 
12035e004460SFlorian Fainelli 	if (!phy_is_pseudo_fixed_link(phydev))
12045e004460SFlorian Fainelli 		return;
12055e004460SFlorian Fainelli 
1206967dd82fSFlorian Fainelli 	/* Enable flow control on BCM5301x's CPU port */
1207967dd82fSFlorian Fainelli 	if (is5301x(dev) && port == dev->cpu_port)
12083cad1c8bSRussell King 		tx_pause = rx_pause = true;
1209967dd82fSFlorian Fainelli 
1210967dd82fSFlorian Fainelli 	if (phydev->pause) {
1211967dd82fSFlorian Fainelli 		if (phydev->asym_pause)
12123cad1c8bSRussell King 			tx_pause = true;
12133cad1c8bSRussell King 		rx_pause = true;
1214967dd82fSFlorian Fainelli 	}
1215967dd82fSFlorian Fainelli 
12163cad1c8bSRussell King 	b53_force_port_config(dev, port, phydev->speed, phydev->duplex,
12173cad1c8bSRussell King 			      tx_pause, rx_pause);
12185e004460SFlorian Fainelli 	b53_force_link(dev, port, phydev->link);
1219967dd82fSFlorian Fainelli 
1220967dd82fSFlorian Fainelli 	if (is531x5(dev) && phy_interface_is_rgmii(phydev)) {
1221967dd82fSFlorian Fainelli 		if (port == 8)
1222967dd82fSFlorian Fainelli 			off = B53_RGMII_CTRL_IMP;
1223967dd82fSFlorian Fainelli 		else
1224967dd82fSFlorian Fainelli 			off = B53_RGMII_CTRL_P(port);
1225967dd82fSFlorian Fainelli 
1226967dd82fSFlorian Fainelli 		/* Configure the port RGMII clock delay by DLL disabled and
1227967dd82fSFlorian Fainelli 		 * tx_clk aligned timing (restoring to reset defaults)
1228967dd82fSFlorian Fainelli 		 */
1229967dd82fSFlorian Fainelli 		b53_read8(dev, B53_CTRL_PAGE, off, &rgmii_ctrl);
1230967dd82fSFlorian Fainelli 		rgmii_ctrl &= ~(RGMII_CTRL_DLL_RXC | RGMII_CTRL_DLL_TXC |
1231967dd82fSFlorian Fainelli 				RGMII_CTRL_TIMING_SEL);
1232967dd82fSFlorian Fainelli 
1233967dd82fSFlorian Fainelli 		/* PHY_INTERFACE_MODE_RGMII_TXID means TX internal delay, make
1234967dd82fSFlorian Fainelli 		 * sure that we enable the port TX clock internal delay to
1235967dd82fSFlorian Fainelli 		 * account for this internal delay that is inserted, otherwise
1236967dd82fSFlorian Fainelli 		 * the switch won't be able to receive correctly.
1237967dd82fSFlorian Fainelli 		 *
1238967dd82fSFlorian Fainelli 		 * PHY_INTERFACE_MODE_RGMII means that we are not introducing
1239967dd82fSFlorian Fainelli 		 * any delay neither on transmission nor reception, so the
1240967dd82fSFlorian Fainelli 		 * BCM53125 must also be configured accordingly to account for
1241967dd82fSFlorian Fainelli 		 * the lack of delay and introduce
1242967dd82fSFlorian Fainelli 		 *
1243967dd82fSFlorian Fainelli 		 * The BCM53125 switch has its RX clock and TX clock control
1244967dd82fSFlorian Fainelli 		 * swapped, hence the reason why we modify the TX clock path in
1245967dd82fSFlorian Fainelli 		 * the "RGMII" case
1246967dd82fSFlorian Fainelli 		 */
1247967dd82fSFlorian Fainelli 		if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
1248967dd82fSFlorian Fainelli 			rgmii_ctrl |= RGMII_CTRL_DLL_TXC;
1249967dd82fSFlorian Fainelli 		if (phydev->interface == PHY_INTERFACE_MODE_RGMII)
1250967dd82fSFlorian Fainelli 			rgmii_ctrl |= RGMII_CTRL_DLL_TXC | RGMII_CTRL_DLL_RXC;
1251967dd82fSFlorian Fainelli 		rgmii_ctrl |= RGMII_CTRL_TIMING_SEL;
1252967dd82fSFlorian Fainelli 		b53_write8(dev, B53_CTRL_PAGE, off, rgmii_ctrl);
1253967dd82fSFlorian Fainelli 
1254967dd82fSFlorian Fainelli 		dev_info(ds->dev, "Configured port %d for %s\n", port,
1255967dd82fSFlorian Fainelli 			 phy_modes(phydev->interface));
1256967dd82fSFlorian Fainelli 	}
1257967dd82fSFlorian Fainelli 
1258967dd82fSFlorian Fainelli 	/* configure MII port if necessary */
1259967dd82fSFlorian Fainelli 	if (is5325(dev)) {
1260967dd82fSFlorian Fainelli 		b53_read8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL,
1261967dd82fSFlorian Fainelli 			  &reg);
1262967dd82fSFlorian Fainelli 
1263967dd82fSFlorian Fainelli 		/* reverse mii needs to be enabled */
1264967dd82fSFlorian Fainelli 		if (!(reg & PORT_OVERRIDE_RV_MII_25)) {
1265967dd82fSFlorian Fainelli 			b53_write8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL,
1266967dd82fSFlorian Fainelli 				   reg | PORT_OVERRIDE_RV_MII_25);
1267967dd82fSFlorian Fainelli 			b53_read8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL,
1268967dd82fSFlorian Fainelli 				  &reg);
1269967dd82fSFlorian Fainelli 
1270967dd82fSFlorian Fainelli 			if (!(reg & PORT_OVERRIDE_RV_MII_25)) {
1271967dd82fSFlorian Fainelli 				dev_err(ds->dev,
1272967dd82fSFlorian Fainelli 					"Failed to enable reverse MII mode\n");
1273967dd82fSFlorian Fainelli 				return;
1274967dd82fSFlorian Fainelli 			}
1275967dd82fSFlorian Fainelli 		}
1276967dd82fSFlorian Fainelli 	} else if (is5301x(dev)) {
1277967dd82fSFlorian Fainelli 		if (port != dev->cpu_port) {
12785e004460SFlorian Fainelli 			b53_force_port_config(dev, dev->cpu_port, 2000,
12793cad1c8bSRussell King 					      DUPLEX_FULL, true, true);
12805e004460SFlorian Fainelli 			b53_force_link(dev, dev->cpu_port, 1);
1281967dd82fSFlorian Fainelli 		}
1282967dd82fSFlorian Fainelli 	}
1283f43a2dbeSFlorian Fainelli 
1284f43a2dbeSFlorian Fainelli 	/* Re-negotiate EEE if it was enabled already */
1285f43a2dbeSFlorian Fainelli 	p->eee_enabled = b53_eee_init(ds, port, phydev);
1286967dd82fSFlorian Fainelli }
1287967dd82fSFlorian Fainelli 
1288a8e8b985SFlorian Fainelli void b53_port_event(struct dsa_switch *ds, int port)
1289a8e8b985SFlorian Fainelli {
1290a8e8b985SFlorian Fainelli 	struct b53_device *dev = ds->priv;
1291a8e8b985SFlorian Fainelli 	bool link;
1292a8e8b985SFlorian Fainelli 	u16 sts;
1293a8e8b985SFlorian Fainelli 
1294a8e8b985SFlorian Fainelli 	b53_read16(dev, B53_STAT_PAGE, B53_LINK_STAT, &sts);
1295a8e8b985SFlorian Fainelli 	link = !!(sts & BIT(port));
1296a8e8b985SFlorian Fainelli 	dsa_port_phylink_mac_change(ds, port, link);
1297a8e8b985SFlorian Fainelli }
1298a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_port_event);
1299a8e8b985SFlorian Fainelli 
1300a8e8b985SFlorian Fainelli void b53_phylink_validate(struct dsa_switch *ds, int port,
1301a8e8b985SFlorian Fainelli 			  unsigned long *supported,
1302a8e8b985SFlorian Fainelli 			  struct phylink_link_state *state)
1303a8e8b985SFlorian Fainelli {
1304a8e8b985SFlorian Fainelli 	struct b53_device *dev = ds->priv;
1305a8e8b985SFlorian Fainelli 	__ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
1306a8e8b985SFlorian Fainelli 
13070e01491dSFlorian Fainelli 	if (dev->ops->serdes_phylink_validate)
13080e01491dSFlorian Fainelli 		dev->ops->serdes_phylink_validate(dev, port, mask, state);
13090e01491dSFlorian Fainelli 
1310a8e8b985SFlorian Fainelli 	/* Allow all the expected bits */
1311a8e8b985SFlorian Fainelli 	phylink_set(mask, Autoneg);
1312a8e8b985SFlorian Fainelli 	phylink_set_port_modes(mask);
1313a8e8b985SFlorian Fainelli 	phylink_set(mask, Pause);
1314a8e8b985SFlorian Fainelli 	phylink_set(mask, Asym_Pause);
1315a8e8b985SFlorian Fainelli 
1316a8e8b985SFlorian Fainelli 	/* With the exclusion of 5325/5365, MII, Reverse MII and 802.3z, we
1317a8e8b985SFlorian Fainelli 	 * support Gigabit, including Half duplex.
1318a8e8b985SFlorian Fainelli 	 */
1319a8e8b985SFlorian Fainelli 	if (state->interface != PHY_INTERFACE_MODE_MII &&
1320a8e8b985SFlorian Fainelli 	    state->interface != PHY_INTERFACE_MODE_REVMII &&
1321a8e8b985SFlorian Fainelli 	    !phy_interface_mode_is_8023z(state->interface) &&
1322a8e8b985SFlorian Fainelli 	    !(is5325(dev) || is5365(dev))) {
1323a8e8b985SFlorian Fainelli 		phylink_set(mask, 1000baseT_Full);
1324a8e8b985SFlorian Fainelli 		phylink_set(mask, 1000baseT_Half);
1325a8e8b985SFlorian Fainelli 	}
1326a8e8b985SFlorian Fainelli 
1327a8e8b985SFlorian Fainelli 	if (!phy_interface_mode_is_8023z(state->interface)) {
1328a8e8b985SFlorian Fainelli 		phylink_set(mask, 10baseT_Half);
1329a8e8b985SFlorian Fainelli 		phylink_set(mask, 10baseT_Full);
1330a8e8b985SFlorian Fainelli 		phylink_set(mask, 100baseT_Half);
1331a8e8b985SFlorian Fainelli 		phylink_set(mask, 100baseT_Full);
1332a8e8b985SFlorian Fainelli 	}
1333a8e8b985SFlorian Fainelli 
1334a8e8b985SFlorian Fainelli 	bitmap_and(supported, supported, mask,
1335a8e8b985SFlorian Fainelli 		   __ETHTOOL_LINK_MODE_MASK_NBITS);
1336a8e8b985SFlorian Fainelli 	bitmap_and(state->advertising, state->advertising, mask,
1337a8e8b985SFlorian Fainelli 		   __ETHTOOL_LINK_MODE_MASK_NBITS);
1338a8e8b985SFlorian Fainelli 
1339a8e8b985SFlorian Fainelli 	phylink_helper_basex_speed(state);
1340a8e8b985SFlorian Fainelli }
1341a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_validate);
1342a8e8b985SFlorian Fainelli 
1343a8e8b985SFlorian Fainelli int b53_phylink_mac_link_state(struct dsa_switch *ds, int port,
1344a8e8b985SFlorian Fainelli 			       struct phylink_link_state *state)
1345a8e8b985SFlorian Fainelli {
13460e01491dSFlorian Fainelli 	struct b53_device *dev = ds->priv;
1347a8e8b985SFlorian Fainelli 	int ret = -EOPNOTSUPP;
1348a8e8b985SFlorian Fainelli 
134955a4d2eaSFlorian Fainelli 	if ((phy_interface_mode_is_8023z(state->interface) ||
135055a4d2eaSFlorian Fainelli 	     state->interface == PHY_INTERFACE_MODE_SGMII) &&
13510e01491dSFlorian Fainelli 	     dev->ops->serdes_link_state)
13520e01491dSFlorian Fainelli 		ret = dev->ops->serdes_link_state(dev, port, state);
13530e01491dSFlorian Fainelli 
1354a8e8b985SFlorian Fainelli 	return ret;
1355a8e8b985SFlorian Fainelli }
1356a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_link_state);
1357a8e8b985SFlorian Fainelli 
1358a8e8b985SFlorian Fainelli void b53_phylink_mac_config(struct dsa_switch *ds, int port,
1359a8e8b985SFlorian Fainelli 			    unsigned int mode,
1360a8e8b985SFlorian Fainelli 			    const struct phylink_link_state *state)
1361a8e8b985SFlorian Fainelli {
1362a8e8b985SFlorian Fainelli 	struct b53_device *dev = ds->priv;
1363a8e8b985SFlorian Fainelli 
1364ab017b79SRussell King 	if (mode == MLO_AN_PHY || mode == MLO_AN_FIXED)
1365a8e8b985SFlorian Fainelli 		return;
1366a8e8b985SFlorian Fainelli 
136755a4d2eaSFlorian Fainelli 	if ((phy_interface_mode_is_8023z(state->interface) ||
136855a4d2eaSFlorian Fainelli 	     state->interface == PHY_INTERFACE_MODE_SGMII) &&
13690e01491dSFlorian Fainelli 	     dev->ops->serdes_config)
13700e01491dSFlorian Fainelli 		dev->ops->serdes_config(dev, port, mode, state);
1371a8e8b985SFlorian Fainelli }
1372a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_config);
1373a8e8b985SFlorian Fainelli 
1374a8e8b985SFlorian Fainelli void b53_phylink_mac_an_restart(struct dsa_switch *ds, int port)
1375a8e8b985SFlorian Fainelli {
13760e01491dSFlorian Fainelli 	struct b53_device *dev = ds->priv;
13770e01491dSFlorian Fainelli 
13780e01491dSFlorian Fainelli 	if (dev->ops->serdes_an_restart)
13790e01491dSFlorian Fainelli 		dev->ops->serdes_an_restart(dev, port);
1380a8e8b985SFlorian Fainelli }
1381a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_an_restart);
1382a8e8b985SFlorian Fainelli 
1383a8e8b985SFlorian Fainelli void b53_phylink_mac_link_down(struct dsa_switch *ds, int port,
1384a8e8b985SFlorian Fainelli 			       unsigned int mode,
1385a8e8b985SFlorian Fainelli 			       phy_interface_t interface)
1386a8e8b985SFlorian Fainelli {
1387a8e8b985SFlorian Fainelli 	struct b53_device *dev = ds->priv;
1388a8e8b985SFlorian Fainelli 
1389a8e8b985SFlorian Fainelli 	if (mode == MLO_AN_PHY)
1390a8e8b985SFlorian Fainelli 		return;
1391a8e8b985SFlorian Fainelli 
1392a8e8b985SFlorian Fainelli 	if (mode == MLO_AN_FIXED) {
1393a8e8b985SFlorian Fainelli 		b53_force_link(dev, port, false);
1394a8e8b985SFlorian Fainelli 		return;
1395a8e8b985SFlorian Fainelli 	}
13960e01491dSFlorian Fainelli 
13970e01491dSFlorian Fainelli 	if (phy_interface_mode_is_8023z(interface) &&
13980e01491dSFlorian Fainelli 	    dev->ops->serdes_link_set)
13990e01491dSFlorian Fainelli 		dev->ops->serdes_link_set(dev, port, mode, interface, false);
1400a8e8b985SFlorian Fainelli }
1401a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_link_down);
1402a8e8b985SFlorian Fainelli 
1403a8e8b985SFlorian Fainelli void b53_phylink_mac_link_up(struct dsa_switch *ds, int port,
1404a8e8b985SFlorian Fainelli 			     unsigned int mode,
1405a8e8b985SFlorian Fainelli 			     phy_interface_t interface,
14065b502a7bSRussell King 			     struct phy_device *phydev,
14075b502a7bSRussell King 			     int speed, int duplex,
14085b502a7bSRussell King 			     bool tx_pause, bool rx_pause)
1409a8e8b985SFlorian Fainelli {
1410a8e8b985SFlorian Fainelli 	struct b53_device *dev = ds->priv;
1411a8e8b985SFlorian Fainelli 
1412a8e8b985SFlorian Fainelli 	if (mode == MLO_AN_PHY)
1413a8e8b985SFlorian Fainelli 		return;
1414a8e8b985SFlorian Fainelli 
1415a8e8b985SFlorian Fainelli 	if (mode == MLO_AN_FIXED) {
1416ab017b79SRussell King 		b53_force_port_config(dev, port, speed, duplex,
1417ab017b79SRussell King 				      tx_pause, rx_pause);
1418a8e8b985SFlorian Fainelli 		b53_force_link(dev, port, true);
1419a8e8b985SFlorian Fainelli 		return;
1420a8e8b985SFlorian Fainelli 	}
14210e01491dSFlorian Fainelli 
14220e01491dSFlorian Fainelli 	if (phy_interface_mode_is_8023z(interface) &&
14230e01491dSFlorian Fainelli 	    dev->ops->serdes_link_set)
14240e01491dSFlorian Fainelli 		dev->ops->serdes_link_set(dev, port, mode, interface, true);
1425a8e8b985SFlorian Fainelli }
1426a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_link_up);
1427a8e8b985SFlorian Fainelli 
142889153ed6SVladimir Oltean int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering,
142989153ed6SVladimir Oltean 		       struct netlink_ext_ack *extack)
1430a2482d2cSFlorian Fainelli {
1431dad8d7c6SFlorian Fainelli 	struct b53_device *dev = ds->priv;
1432dad8d7c6SFlorian Fainelli 
1433ee47ed08SFlorian Fainelli 	b53_enable_vlan(dev, port, dev->vlan_enabled, vlan_filtering);
1434dad8d7c6SFlorian Fainelli 
1435a2482d2cSFlorian Fainelli 	return 0;
1436a2482d2cSFlorian Fainelli }
14373117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_filtering);
1438a2482d2cSFlorian Fainelli 
14391958d581SVladimir Oltean static int b53_vlan_prepare(struct dsa_switch *ds, int port,
144080e02360SVivien Didelot 			    const struct switchdev_obj_port_vlan *vlan)
1441a2482d2cSFlorian Fainelli {
144204bed143SVivien Didelot 	struct b53_device *dev = ds->priv;
1443a2482d2cSFlorian Fainelli 
1444b7a9e0daSVladimir Oltean 	if ((is5325(dev) || is5365(dev)) && vlan->vid == 0)
1445a2482d2cSFlorian Fainelli 		return -EOPNOTSUPP;
1446a2482d2cSFlorian Fainelli 
144788631864SFlorian Fainelli 	/* Port 7 on 7278 connects to the ASP's UniMAC which is not capable of
144888631864SFlorian Fainelli 	 * receiving VLAN tagged frames at all, we can still allow the port to
144988631864SFlorian Fainelli 	 * be configured for egress untagged.
145088631864SFlorian Fainelli 	 */
145188631864SFlorian Fainelli 	if (dev->chip_id == BCM7278_DEVICE_ID && port == 7 &&
145288631864SFlorian Fainelli 	    !(vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED))
145388631864SFlorian Fainelli 		return -EINVAL;
145488631864SFlorian Fainelli 
14550fe2f273SJakub Kicinski 	if (vlan->vid >= dev->num_vlans)
1456a2482d2cSFlorian Fainelli 		return -ERANGE;
1457a2482d2cSFlorian Fainelli 
1458ee47ed08SFlorian Fainelli 	b53_enable_vlan(dev, port, true, ds->vlan_filtering);
1459a2482d2cSFlorian Fainelli 
1460a2482d2cSFlorian Fainelli 	return 0;
1461a2482d2cSFlorian Fainelli }
1462a2482d2cSFlorian Fainelli 
1463*2c32a3d3SFlorian Fainelli static bool b53_vlan_port_needs_forced_tagged(struct dsa_switch *ds, int port)
1464*2c32a3d3SFlorian Fainelli {
1465*2c32a3d3SFlorian Fainelli 	struct b53_device *dev = ds->priv;
1466*2c32a3d3SFlorian Fainelli 
1467*2c32a3d3SFlorian Fainelli 	return dev->tag_protocol == DSA_TAG_PROTO_NONE && dsa_is_cpu_port(ds, port);
1468*2c32a3d3SFlorian Fainelli }
1469*2c32a3d3SFlorian Fainelli 
14701958d581SVladimir Oltean int b53_vlan_add(struct dsa_switch *ds, int port,
147131046a5fSVladimir Oltean 		 const struct switchdev_obj_port_vlan *vlan,
147231046a5fSVladimir Oltean 		 struct netlink_ext_ack *extack)
1473a2482d2cSFlorian Fainelli {
147404bed143SVivien Didelot 	struct b53_device *dev = ds->priv;
1475a2482d2cSFlorian Fainelli 	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1476a2482d2cSFlorian Fainelli 	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1477a2482d2cSFlorian Fainelli 	struct b53_vlan *vl;
14781958d581SVladimir Oltean 	int err;
14791958d581SVladimir Oltean 
14801958d581SVladimir Oltean 	err = b53_vlan_prepare(ds, port, vlan);
14811958d581SVladimir Oltean 	if (err)
14821958d581SVladimir Oltean 		return err;
1483a2482d2cSFlorian Fainelli 
1484b7a9e0daSVladimir Oltean 	vl = &dev->vlans[vlan->vid];
1485a2482d2cSFlorian Fainelli 
1486b7a9e0daSVladimir Oltean 	b53_get_vlan_entry(dev, vlan->vid, vl);
1487a2482d2cSFlorian Fainelli 
1488b7a9e0daSVladimir Oltean 	if (vlan->vid == 0 && vlan->vid == b53_default_pvid(dev))
1489d965a543SFlorian Fainelli 		untagged = true;
1490d965a543SFlorian Fainelli 
1491c499696eSFlorian Fainelli 	vl->members |= BIT(port);
1492*2c32a3d3SFlorian Fainelli 	if (untagged && !b53_vlan_port_needs_forced_tagged(ds, port))
1493e47112d9SFlorian Fainelli 		vl->untag |= BIT(port);
1494a2482d2cSFlorian Fainelli 	else
1495e47112d9SFlorian Fainelli 		vl->untag &= ~BIT(port);
1496a2482d2cSFlorian Fainelli 
1497b7a9e0daSVladimir Oltean 	b53_set_vlan_entry(dev, vlan->vid, vl);
1498b7a9e0daSVladimir Oltean 	b53_fast_age_vlan(dev, vlan->vid);
1499a2482d2cSFlorian Fainelli 
150010163aaeSFlorian Fainelli 	if (pvid && !dsa_is_cpu_port(ds, port)) {
1501a2482d2cSFlorian Fainelli 		b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port),
1502b7a9e0daSVladimir Oltean 			    vlan->vid);
1503b7a9e0daSVladimir Oltean 		b53_fast_age_vlan(dev, vlan->vid);
1504a2482d2cSFlorian Fainelli 	}
15051958d581SVladimir Oltean 
15061958d581SVladimir Oltean 	return 0;
1507a2482d2cSFlorian Fainelli }
15083117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_add);
1509a2482d2cSFlorian Fainelli 
15103117455dSFlorian Fainelli int b53_vlan_del(struct dsa_switch *ds, int port,
1511a2482d2cSFlorian Fainelli 		 const struct switchdev_obj_port_vlan *vlan)
1512a2482d2cSFlorian Fainelli {
151304bed143SVivien Didelot 	struct b53_device *dev = ds->priv;
1514a2482d2cSFlorian Fainelli 	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1515a2482d2cSFlorian Fainelli 	struct b53_vlan *vl;
1516a2482d2cSFlorian Fainelli 	u16 pvid;
1517a2482d2cSFlorian Fainelli 
1518a2482d2cSFlorian Fainelli 	b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &pvid);
1519a2482d2cSFlorian Fainelli 
1520b7a9e0daSVladimir Oltean 	vl = &dev->vlans[vlan->vid];
1521a2482d2cSFlorian Fainelli 
1522b7a9e0daSVladimir Oltean 	b53_get_vlan_entry(dev, vlan->vid, vl);
1523a2482d2cSFlorian Fainelli 
1524a2482d2cSFlorian Fainelli 	vl->members &= ~BIT(port);
1525a2482d2cSFlorian Fainelli 
1526b7a9e0daSVladimir Oltean 	if (pvid == vlan->vid)
1527fea83353SFlorian Fainelli 		pvid = b53_default_pvid(dev);
1528a2482d2cSFlorian Fainelli 
1529*2c32a3d3SFlorian Fainelli 	if (untagged && !b53_vlan_port_needs_forced_tagged(ds, port))
1530a2482d2cSFlorian Fainelli 		vl->untag &= ~(BIT(port));
1531a2482d2cSFlorian Fainelli 
1532b7a9e0daSVladimir Oltean 	b53_set_vlan_entry(dev, vlan->vid, vl);
1533b7a9e0daSVladimir Oltean 	b53_fast_age_vlan(dev, vlan->vid);
1534a2482d2cSFlorian Fainelli 
1535a2482d2cSFlorian Fainelli 	b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), pvid);
1536a2482d2cSFlorian Fainelli 	b53_fast_age_vlan(dev, pvid);
1537a2482d2cSFlorian Fainelli 
1538a2482d2cSFlorian Fainelli 	return 0;
1539a2482d2cSFlorian Fainelli }
15403117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_del);
1541a2482d2cSFlorian Fainelli 
15421da6df85SFlorian Fainelli /* Address Resolution Logic routines */
15431da6df85SFlorian Fainelli static int b53_arl_op_wait(struct b53_device *dev)
15441da6df85SFlorian Fainelli {
15451da6df85SFlorian Fainelli 	unsigned int timeout = 10;
15461da6df85SFlorian Fainelli 	u8 reg;
15471da6df85SFlorian Fainelli 
15481da6df85SFlorian Fainelli 	do {
15491da6df85SFlorian Fainelli 		b53_read8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, &reg);
15501da6df85SFlorian Fainelli 		if (!(reg & ARLTBL_START_DONE))
15511da6df85SFlorian Fainelli 			return 0;
15521da6df85SFlorian Fainelli 
15531da6df85SFlorian Fainelli 		usleep_range(1000, 2000);
15541da6df85SFlorian Fainelli 	} while (timeout--);
15551da6df85SFlorian Fainelli 
15561da6df85SFlorian Fainelli 	dev_warn(dev->dev, "timeout waiting for ARL to finish: 0x%02x\n", reg);
15571da6df85SFlorian Fainelli 
15581da6df85SFlorian Fainelli 	return -ETIMEDOUT;
15591da6df85SFlorian Fainelli }
15601da6df85SFlorian Fainelli 
15611da6df85SFlorian Fainelli static int b53_arl_rw_op(struct b53_device *dev, unsigned int op)
15621da6df85SFlorian Fainelli {
15631da6df85SFlorian Fainelli 	u8 reg;
15641da6df85SFlorian Fainelli 
15651da6df85SFlorian Fainelli 	if (op > ARLTBL_RW)
15661da6df85SFlorian Fainelli 		return -EINVAL;
15671da6df85SFlorian Fainelli 
15681da6df85SFlorian Fainelli 	b53_read8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, &reg);
15691da6df85SFlorian Fainelli 	reg |= ARLTBL_START_DONE;
15701da6df85SFlorian Fainelli 	if (op)
15711da6df85SFlorian Fainelli 		reg |= ARLTBL_RW;
15721da6df85SFlorian Fainelli 	else
15731da6df85SFlorian Fainelli 		reg &= ~ARLTBL_RW;
157464fec949SFlorian Fainelli 	if (dev->vlan_enabled)
157564fec949SFlorian Fainelli 		reg &= ~ARLTBL_IVL_SVL_SELECT;
157664fec949SFlorian Fainelli 	else
157764fec949SFlorian Fainelli 		reg |= ARLTBL_IVL_SVL_SELECT;
15781da6df85SFlorian Fainelli 	b53_write8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, reg);
15791da6df85SFlorian Fainelli 
15801da6df85SFlorian Fainelli 	return b53_arl_op_wait(dev);
15811da6df85SFlorian Fainelli }
15821da6df85SFlorian Fainelli 
15831da6df85SFlorian Fainelli static int b53_arl_read(struct b53_device *dev, u64 mac,
1584ef2a0bd9SFlorian Fainelli 			u16 vid, struct b53_arl_entry *ent, u8 *idx)
15851da6df85SFlorian Fainelli {
15866344dbdeSFlorian Fainelli 	DECLARE_BITMAP(free_bins, B53_ARLTBL_MAX_BIN_ENTRIES);
15871da6df85SFlorian Fainelli 	unsigned int i;
15881da6df85SFlorian Fainelli 	int ret;
15891da6df85SFlorian Fainelli 
15901da6df85SFlorian Fainelli 	ret = b53_arl_op_wait(dev);
15911da6df85SFlorian Fainelli 	if (ret)
15921da6df85SFlorian Fainelli 		return ret;
15931da6df85SFlorian Fainelli 
1594673e69a6SFlorian Fainelli 	bitmap_zero(free_bins, dev->num_arl_bins);
15956344dbdeSFlorian Fainelli 
15961da6df85SFlorian Fainelli 	/* Read the bins */
1597673e69a6SFlorian Fainelli 	for (i = 0; i < dev->num_arl_bins; i++) {
15981da6df85SFlorian Fainelli 		u64 mac_vid;
15991da6df85SFlorian Fainelli 		u32 fwd_entry;
16001da6df85SFlorian Fainelli 
16011da6df85SFlorian Fainelli 		b53_read64(dev, B53_ARLIO_PAGE,
16021da6df85SFlorian Fainelli 			   B53_ARLTBL_MAC_VID_ENTRY(i), &mac_vid);
16031da6df85SFlorian Fainelli 		b53_read32(dev, B53_ARLIO_PAGE,
16041da6df85SFlorian Fainelli 			   B53_ARLTBL_DATA_ENTRY(i), &fwd_entry);
16051da6df85SFlorian Fainelli 		b53_arl_to_entry(ent, mac_vid, fwd_entry);
16061da6df85SFlorian Fainelli 
16076344dbdeSFlorian Fainelli 		if (!(fwd_entry & ARLTBL_VALID)) {
16086344dbdeSFlorian Fainelli 			set_bit(i, free_bins);
16091da6df85SFlorian Fainelli 			continue;
16106344dbdeSFlorian Fainelli 		}
16111da6df85SFlorian Fainelli 		if ((mac_vid & ARLTBL_MAC_MASK) != mac)
16121da6df85SFlorian Fainelli 			continue;
16132e97b0cdSFlorian Fainelli 		if (dev->vlan_enabled &&
16142e97b0cdSFlorian Fainelli 		    ((mac_vid >> ARLTBL_VID_S) & ARLTBL_VID_MASK) != vid)
16152e97b0cdSFlorian Fainelli 			continue;
16161da6df85SFlorian Fainelli 		*idx = i;
16176344dbdeSFlorian Fainelli 		return 0;
16181da6df85SFlorian Fainelli 	}
16191da6df85SFlorian Fainelli 
1620673e69a6SFlorian Fainelli 	if (bitmap_weight(free_bins, dev->num_arl_bins) == 0)
16216344dbdeSFlorian Fainelli 		return -ENOSPC;
16226344dbdeSFlorian Fainelli 
1623673e69a6SFlorian Fainelli 	*idx = find_first_bit(free_bins, dev->num_arl_bins);
16246344dbdeSFlorian Fainelli 
16251da6df85SFlorian Fainelli 	return -ENOENT;
16261da6df85SFlorian Fainelli }
16271da6df85SFlorian Fainelli 
16281da6df85SFlorian Fainelli static int b53_arl_op(struct b53_device *dev, int op, int port,
16291da6df85SFlorian Fainelli 		      const unsigned char *addr, u16 vid, bool is_valid)
16301da6df85SFlorian Fainelli {
16311da6df85SFlorian Fainelli 	struct b53_arl_entry ent;
16321da6df85SFlorian Fainelli 	u32 fwd_entry;
16331da6df85SFlorian Fainelli 	u64 mac, mac_vid = 0;
16341da6df85SFlorian Fainelli 	u8 idx = 0;
16351da6df85SFlorian Fainelli 	int ret;
16361da6df85SFlorian Fainelli 
16371da6df85SFlorian Fainelli 	/* Convert the array into a 64-bit MAC */
16384b92ea81SFlorian Fainelli 	mac = ether_addr_to_u64(addr);
16391da6df85SFlorian Fainelli 
16401da6df85SFlorian Fainelli 	/* Perform a read for the given MAC and VID */
16411da6df85SFlorian Fainelli 	b53_write48(dev, B53_ARLIO_PAGE, B53_MAC_ADDR_IDX, mac);
16421da6df85SFlorian Fainelli 	b53_write16(dev, B53_ARLIO_PAGE, B53_VLAN_ID_IDX, vid);
16431da6df85SFlorian Fainelli 
16441da6df85SFlorian Fainelli 	/* Issue a read operation for this MAC */
16451da6df85SFlorian Fainelli 	ret = b53_arl_rw_op(dev, 1);
16461da6df85SFlorian Fainelli 	if (ret)
16471da6df85SFlorian Fainelli 		return ret;
16481da6df85SFlorian Fainelli 
1649ef2a0bd9SFlorian Fainelli 	ret = b53_arl_read(dev, mac, vid, &ent, &idx);
1650ef2a0bd9SFlorian Fainelli 
16511da6df85SFlorian Fainelli 	/* If this is a read, just finish now */
16521da6df85SFlorian Fainelli 	if (op)
16531da6df85SFlorian Fainelli 		return ret;
16541da6df85SFlorian Fainelli 
16556344dbdeSFlorian Fainelli 	switch (ret) {
1656774d977aSTom Rix 	case -ETIMEDOUT:
1657774d977aSTom Rix 		return ret;
16586344dbdeSFlorian Fainelli 	case -ENOSPC:
16596344dbdeSFlorian Fainelli 		dev_dbg(dev->dev, "{%pM,%.4d} no space left in ARL\n",
16606344dbdeSFlorian Fainelli 			addr, vid);
16616344dbdeSFlorian Fainelli 		return is_valid ? ret : 0;
16626344dbdeSFlorian Fainelli 	case -ENOENT:
16631da6df85SFlorian Fainelli 		/* We could not find a matching MAC, so reset to a new entry */
16646344dbdeSFlorian Fainelli 		dev_dbg(dev->dev, "{%pM,%.4d} not found, using idx: %d\n",
16656344dbdeSFlorian Fainelli 			addr, vid, idx);
16661da6df85SFlorian Fainelli 		fwd_entry = 0;
16676344dbdeSFlorian Fainelli 		break;
16686344dbdeSFlorian Fainelli 	default:
16696344dbdeSFlorian Fainelli 		dev_dbg(dev->dev, "{%pM,%.4d} found, using idx: %d\n",
16706344dbdeSFlorian Fainelli 			addr, vid, idx);
16716344dbdeSFlorian Fainelli 		break;
16721da6df85SFlorian Fainelli 	}
16731da6df85SFlorian Fainelli 
16745d65b64aSFlorian Fainelli 	/* For multicast address, the port is a bitmask and the validity
16755d65b64aSFlorian Fainelli 	 * is determined by having at least one port being still active
16765d65b64aSFlorian Fainelli 	 */
16775d65b64aSFlorian Fainelli 	if (!is_multicast_ether_addr(addr)) {
16781da6df85SFlorian Fainelli 		ent.port = port;
16791da6df85SFlorian Fainelli 		ent.is_valid = is_valid;
16805d65b64aSFlorian Fainelli 	} else {
16815d65b64aSFlorian Fainelli 		if (is_valid)
16825d65b64aSFlorian Fainelli 			ent.port |= BIT(port);
16835d65b64aSFlorian Fainelli 		else
16845d65b64aSFlorian Fainelli 			ent.port &= ~BIT(port);
16855d65b64aSFlorian Fainelli 
16865d65b64aSFlorian Fainelli 		ent.is_valid = !!(ent.port);
16875d65b64aSFlorian Fainelli 	}
16885d65b64aSFlorian Fainelli 
16891da6df85SFlorian Fainelli 	ent.vid = vid;
16901da6df85SFlorian Fainelli 	ent.is_static = true;
16915d65b64aSFlorian Fainelli 	ent.is_age = false;
16921da6df85SFlorian Fainelli 	memcpy(ent.mac, addr, ETH_ALEN);
16931da6df85SFlorian Fainelli 	b53_arl_from_entry(&mac_vid, &fwd_entry, &ent);
16941da6df85SFlorian Fainelli 
16951da6df85SFlorian Fainelli 	b53_write64(dev, B53_ARLIO_PAGE,
16961da6df85SFlorian Fainelli 		    B53_ARLTBL_MAC_VID_ENTRY(idx), mac_vid);
16971da6df85SFlorian Fainelli 	b53_write32(dev, B53_ARLIO_PAGE,
16981da6df85SFlorian Fainelli 		    B53_ARLTBL_DATA_ENTRY(idx), fwd_entry);
16991da6df85SFlorian Fainelli 
17001da6df85SFlorian Fainelli 	return b53_arl_rw_op(dev, 0);
17011da6df85SFlorian Fainelli }
17021da6df85SFlorian Fainelli 
17031b6dd556SArkadi Sharshevsky int b53_fdb_add(struct dsa_switch *ds, int port,
17046c2c1dcbSArkadi Sharshevsky 		const unsigned char *addr, u16 vid)
17051da6df85SFlorian Fainelli {
170604bed143SVivien Didelot 	struct b53_device *priv = ds->priv;
17071da6df85SFlorian Fainelli 
17081da6df85SFlorian Fainelli 	/* 5325 and 5365 require some more massaging, but could
17091da6df85SFlorian Fainelli 	 * be supported eventually
17101da6df85SFlorian Fainelli 	 */
17111da6df85SFlorian Fainelli 	if (is5325(priv) || is5365(priv))
17121da6df85SFlorian Fainelli 		return -EOPNOTSUPP;
17131da6df85SFlorian Fainelli 
17141b6dd556SArkadi Sharshevsky 	return b53_arl_op(priv, 0, port, addr, vid, true);
17151da6df85SFlorian Fainelli }
17163117455dSFlorian Fainelli EXPORT_SYMBOL(b53_fdb_add);
17171da6df85SFlorian Fainelli 
17183117455dSFlorian Fainelli int b53_fdb_del(struct dsa_switch *ds, int port,
17196c2c1dcbSArkadi Sharshevsky 		const unsigned char *addr, u16 vid)
17201da6df85SFlorian Fainelli {
172104bed143SVivien Didelot 	struct b53_device *priv = ds->priv;
17221da6df85SFlorian Fainelli 
17236c2c1dcbSArkadi Sharshevsky 	return b53_arl_op(priv, 0, port, addr, vid, false);
17241da6df85SFlorian Fainelli }
17253117455dSFlorian Fainelli EXPORT_SYMBOL(b53_fdb_del);
17261da6df85SFlorian Fainelli 
17271da6df85SFlorian Fainelli static int b53_arl_search_wait(struct b53_device *dev)
17281da6df85SFlorian Fainelli {
17291da6df85SFlorian Fainelli 	unsigned int timeout = 1000;
17301da6df85SFlorian Fainelli 	u8 reg;
17311da6df85SFlorian Fainelli 
17321da6df85SFlorian Fainelli 	do {
17331da6df85SFlorian Fainelli 		b53_read8(dev, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, &reg);
17341da6df85SFlorian Fainelli 		if (!(reg & ARL_SRCH_STDN))
17351da6df85SFlorian Fainelli 			return 0;
17361da6df85SFlorian Fainelli 
17371da6df85SFlorian Fainelli 		if (reg & ARL_SRCH_VLID)
17381da6df85SFlorian Fainelli 			return 0;
17391da6df85SFlorian Fainelli 
17401da6df85SFlorian Fainelli 		usleep_range(1000, 2000);
17411da6df85SFlorian Fainelli 	} while (timeout--);
17421da6df85SFlorian Fainelli 
17431da6df85SFlorian Fainelli 	return -ETIMEDOUT;
17441da6df85SFlorian Fainelli }
17451da6df85SFlorian Fainelli 
17461da6df85SFlorian Fainelli static void b53_arl_search_rd(struct b53_device *dev, u8 idx,
17471da6df85SFlorian Fainelli 			      struct b53_arl_entry *ent)
17481da6df85SFlorian Fainelli {
17491da6df85SFlorian Fainelli 	u64 mac_vid;
17501da6df85SFlorian Fainelli 	u32 fwd_entry;
17511da6df85SFlorian Fainelli 
17521da6df85SFlorian Fainelli 	b53_read64(dev, B53_ARLIO_PAGE,
17531da6df85SFlorian Fainelli 		   B53_ARL_SRCH_RSTL_MACVID(idx), &mac_vid);
17541da6df85SFlorian Fainelli 	b53_read32(dev, B53_ARLIO_PAGE,
17551da6df85SFlorian Fainelli 		   B53_ARL_SRCH_RSTL(idx), &fwd_entry);
17561da6df85SFlorian Fainelli 	b53_arl_to_entry(ent, mac_vid, fwd_entry);
17571da6df85SFlorian Fainelli }
17581da6df85SFlorian Fainelli 
1759e6cbef0cSVivien Didelot static int b53_fdb_copy(int port, const struct b53_arl_entry *ent,
17602bedde1aSArkadi Sharshevsky 			dsa_fdb_dump_cb_t *cb, void *data)
17611da6df85SFlorian Fainelli {
17621da6df85SFlorian Fainelli 	if (!ent->is_valid)
17631da6df85SFlorian Fainelli 		return 0;
17641da6df85SFlorian Fainelli 
17651da6df85SFlorian Fainelli 	if (port != ent->port)
17661da6df85SFlorian Fainelli 		return 0;
17671da6df85SFlorian Fainelli 
17682bedde1aSArkadi Sharshevsky 	return cb(ent->mac, ent->vid, ent->is_static, data);
17691da6df85SFlorian Fainelli }
17701da6df85SFlorian Fainelli 
17713117455dSFlorian Fainelli int b53_fdb_dump(struct dsa_switch *ds, int port,
17722bedde1aSArkadi Sharshevsky 		 dsa_fdb_dump_cb_t *cb, void *data)
17731da6df85SFlorian Fainelli {
177404bed143SVivien Didelot 	struct b53_device *priv = ds->priv;
17751da6df85SFlorian Fainelli 	struct b53_arl_entry results[2];
17761da6df85SFlorian Fainelli 	unsigned int count = 0;
17771da6df85SFlorian Fainelli 	int ret;
17781da6df85SFlorian Fainelli 	u8 reg;
17791da6df85SFlorian Fainelli 
17801da6df85SFlorian Fainelli 	/* Start search operation */
17811da6df85SFlorian Fainelli 	reg = ARL_SRCH_STDN;
17821da6df85SFlorian Fainelli 	b53_write8(priv, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, reg);
17831da6df85SFlorian Fainelli 
17841da6df85SFlorian Fainelli 	do {
17851da6df85SFlorian Fainelli 		ret = b53_arl_search_wait(priv);
17861da6df85SFlorian Fainelli 		if (ret)
17871da6df85SFlorian Fainelli 			return ret;
17881da6df85SFlorian Fainelli 
17891da6df85SFlorian Fainelli 		b53_arl_search_rd(priv, 0, &results[0]);
17902bedde1aSArkadi Sharshevsky 		ret = b53_fdb_copy(port, &results[0], cb, data);
17911da6df85SFlorian Fainelli 		if (ret)
17921da6df85SFlorian Fainelli 			return ret;
17931da6df85SFlorian Fainelli 
1794673e69a6SFlorian Fainelli 		if (priv->num_arl_bins > 2) {
17951da6df85SFlorian Fainelli 			b53_arl_search_rd(priv, 1, &results[1]);
17962bedde1aSArkadi Sharshevsky 			ret = b53_fdb_copy(port, &results[1], cb, data);
17971da6df85SFlorian Fainelli 			if (ret)
17981da6df85SFlorian Fainelli 				return ret;
17991da6df85SFlorian Fainelli 
18001da6df85SFlorian Fainelli 			if (!results[0].is_valid && !results[1].is_valid)
18011da6df85SFlorian Fainelli 				break;
18021da6df85SFlorian Fainelli 		}
18031da6df85SFlorian Fainelli 
1804cd169d79SFlorian Fainelli 	} while (count++ < b53_max_arl_entries(priv) / 2);
18051da6df85SFlorian Fainelli 
18061da6df85SFlorian Fainelli 	return 0;
18071da6df85SFlorian Fainelli }
18083117455dSFlorian Fainelli EXPORT_SYMBOL(b53_fdb_dump);
18091da6df85SFlorian Fainelli 
1810a52b2da7SVladimir Oltean int b53_mdb_add(struct dsa_switch *ds, int port,
18115d65b64aSFlorian Fainelli 		const struct switchdev_obj_port_mdb *mdb)
18125d65b64aSFlorian Fainelli {
18135d65b64aSFlorian Fainelli 	struct b53_device *priv = ds->priv;
18145d65b64aSFlorian Fainelli 
18155d65b64aSFlorian Fainelli 	/* 5325 and 5365 require some more massaging, but could
18165d65b64aSFlorian Fainelli 	 * be supported eventually
18175d65b64aSFlorian Fainelli 	 */
18185d65b64aSFlorian Fainelli 	if (is5325(priv) || is5365(priv))
18195d65b64aSFlorian Fainelli 		return -EOPNOTSUPP;
18205d65b64aSFlorian Fainelli 
1821a52b2da7SVladimir Oltean 	return b53_arl_op(priv, 0, port, mdb->addr, mdb->vid, true);
18225d65b64aSFlorian Fainelli }
18235d65b64aSFlorian Fainelli EXPORT_SYMBOL(b53_mdb_add);
18245d65b64aSFlorian Fainelli 
18255d65b64aSFlorian Fainelli int b53_mdb_del(struct dsa_switch *ds, int port,
18265d65b64aSFlorian Fainelli 		const struct switchdev_obj_port_mdb *mdb)
18275d65b64aSFlorian Fainelli {
18285d65b64aSFlorian Fainelli 	struct b53_device *priv = ds->priv;
18295d65b64aSFlorian Fainelli 	int ret;
18305d65b64aSFlorian Fainelli 
18315d65b64aSFlorian Fainelli 	ret = b53_arl_op(priv, 0, port, mdb->addr, mdb->vid, false);
18325d65b64aSFlorian Fainelli 	if (ret)
18335d65b64aSFlorian Fainelli 		dev_err(ds->dev, "failed to delete MDB entry\n");
18345d65b64aSFlorian Fainelli 
18355d65b64aSFlorian Fainelli 	return ret;
18365d65b64aSFlorian Fainelli }
18375d65b64aSFlorian Fainelli EXPORT_SYMBOL(b53_mdb_del);
18385d65b64aSFlorian Fainelli 
1839ddd3a0c8SVivien Didelot int b53_br_join(struct dsa_switch *ds, int port, struct net_device *br)
1840ff39c2d6SFlorian Fainelli {
184104bed143SVivien Didelot 	struct b53_device *dev = ds->priv;
184268bb8ea8SVivien Didelot 	s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
1843ff39c2d6SFlorian Fainelli 	u16 pvlan, reg;
1844ff39c2d6SFlorian Fainelli 	unsigned int i;
1845ff39c2d6SFlorian Fainelli 
184631bfc2d4SFlorian Fainelli 	/* On 7278, port 7 which connects to the ASP should only receive
184731bfc2d4SFlorian Fainelli 	 * traffic from matching CFP rules.
184831bfc2d4SFlorian Fainelli 	 */
184931bfc2d4SFlorian Fainelli 	if (dev->chip_id == BCM7278_DEVICE_ID && port == 7)
185031bfc2d4SFlorian Fainelli 		return -EINVAL;
185131bfc2d4SFlorian Fainelli 
185248aea33aSFlorian Fainelli 	/* Make this port leave the all VLANs join since we will have proper
185348aea33aSFlorian Fainelli 	 * VLAN entries from now on
185448aea33aSFlorian Fainelli 	 */
185548aea33aSFlorian Fainelli 	if (is58xx(dev)) {
185648aea33aSFlorian Fainelli 		b53_read16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, &reg);
185748aea33aSFlorian Fainelli 		reg &= ~BIT(port);
185848aea33aSFlorian Fainelli 		if ((reg & BIT(cpu_port)) == BIT(cpu_port))
185948aea33aSFlorian Fainelli 			reg &= ~BIT(cpu_port);
186048aea33aSFlorian Fainelli 		b53_write16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, reg);
186148aea33aSFlorian Fainelli 	}
186248aea33aSFlorian Fainelli 
1863ff39c2d6SFlorian Fainelli 	b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan);
1864ff39c2d6SFlorian Fainelli 
1865ff39c2d6SFlorian Fainelli 	b53_for_each_port(dev, i) {
1866c8652c83SVivien Didelot 		if (dsa_to_port(ds, i)->bridge_dev != br)
1867ff39c2d6SFlorian Fainelli 			continue;
1868ff39c2d6SFlorian Fainelli 
1869ff39c2d6SFlorian Fainelli 		/* Add this local port to the remote port VLAN control
1870ff39c2d6SFlorian Fainelli 		 * membership and update the remote port bitmask
1871ff39c2d6SFlorian Fainelli 		 */
1872ff39c2d6SFlorian Fainelli 		b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), &reg);
1873ff39c2d6SFlorian Fainelli 		reg |= BIT(port);
1874ff39c2d6SFlorian Fainelli 		b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), reg);
1875ff39c2d6SFlorian Fainelli 		dev->ports[i].vlan_ctl_mask = reg;
1876ff39c2d6SFlorian Fainelli 
1877ff39c2d6SFlorian Fainelli 		pvlan |= BIT(i);
1878ff39c2d6SFlorian Fainelli 	}
1879ff39c2d6SFlorian Fainelli 
1880ff39c2d6SFlorian Fainelli 	/* Configure the local port VLAN control membership to include
1881ff39c2d6SFlorian Fainelli 	 * remote ports and update the local port bitmask
1882ff39c2d6SFlorian Fainelli 	 */
1883ff39c2d6SFlorian Fainelli 	b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan);
1884ff39c2d6SFlorian Fainelli 	dev->ports[port].vlan_ctl_mask = pvlan;
1885ff39c2d6SFlorian Fainelli 
1886ff39c2d6SFlorian Fainelli 	return 0;
1887ff39c2d6SFlorian Fainelli }
18883117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_join);
1889ff39c2d6SFlorian Fainelli 
1890f123f2fbSVivien Didelot void b53_br_leave(struct dsa_switch *ds, int port, struct net_device *br)
1891ff39c2d6SFlorian Fainelli {
189204bed143SVivien Didelot 	struct b53_device *dev = ds->priv;
1893a2482d2cSFlorian Fainelli 	struct b53_vlan *vl = &dev->vlans[0];
189468bb8ea8SVivien Didelot 	s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
1895ff39c2d6SFlorian Fainelli 	unsigned int i;
1896a2482d2cSFlorian Fainelli 	u16 pvlan, reg, pvid;
1897ff39c2d6SFlorian Fainelli 
1898ff39c2d6SFlorian Fainelli 	b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan);
1899ff39c2d6SFlorian Fainelli 
1900ff39c2d6SFlorian Fainelli 	b53_for_each_port(dev, i) {
1901ff39c2d6SFlorian Fainelli 		/* Don't touch the remaining ports */
1902c8652c83SVivien Didelot 		if (dsa_to_port(ds, i)->bridge_dev != br)
1903ff39c2d6SFlorian Fainelli 			continue;
1904ff39c2d6SFlorian Fainelli 
1905ff39c2d6SFlorian Fainelli 		b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), &reg);
1906ff39c2d6SFlorian Fainelli 		reg &= ~BIT(port);
1907ff39c2d6SFlorian Fainelli 		b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), reg);
1908ff39c2d6SFlorian Fainelli 		dev->ports[port].vlan_ctl_mask = reg;
1909ff39c2d6SFlorian Fainelli 
1910ff39c2d6SFlorian Fainelli 		/* Prevent self removal to preserve isolation */
1911ff39c2d6SFlorian Fainelli 		if (port != i)
1912ff39c2d6SFlorian Fainelli 			pvlan &= ~BIT(i);
1913ff39c2d6SFlorian Fainelli 	}
1914ff39c2d6SFlorian Fainelli 
1915ff39c2d6SFlorian Fainelli 	b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan);
1916ff39c2d6SFlorian Fainelli 	dev->ports[port].vlan_ctl_mask = pvlan;
1917a2482d2cSFlorian Fainelli 
1918fea83353SFlorian Fainelli 	pvid = b53_default_pvid(dev);
1919a2482d2cSFlorian Fainelli 
192048aea33aSFlorian Fainelli 	/* Make this port join all VLANs without VLAN entries */
192148aea33aSFlorian Fainelli 	if (is58xx(dev)) {
192248aea33aSFlorian Fainelli 		b53_read16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, &reg);
192348aea33aSFlorian Fainelli 		reg |= BIT(port);
192448aea33aSFlorian Fainelli 		if (!(reg & BIT(cpu_port)))
192548aea33aSFlorian Fainelli 			reg |= BIT(cpu_port);
192648aea33aSFlorian Fainelli 		b53_write16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, reg);
192748aea33aSFlorian Fainelli 	} else {
1928a2482d2cSFlorian Fainelli 		b53_get_vlan_entry(dev, pvid, vl);
1929c499696eSFlorian Fainelli 		vl->members |= BIT(port) | BIT(cpu_port);
1930c499696eSFlorian Fainelli 		vl->untag |= BIT(port) | BIT(cpu_port);
1931a2482d2cSFlorian Fainelli 		b53_set_vlan_entry(dev, pvid, vl);
1932ff39c2d6SFlorian Fainelli 	}
193348aea33aSFlorian Fainelli }
19343117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_leave);
1935ff39c2d6SFlorian Fainelli 
19363117455dSFlorian Fainelli void b53_br_set_stp_state(struct dsa_switch *ds, int port, u8 state)
1937ff39c2d6SFlorian Fainelli {
193804bed143SVivien Didelot 	struct b53_device *dev = ds->priv;
1939597698f1SVivien Didelot 	u8 hw_state;
1940ff39c2d6SFlorian Fainelli 	u8 reg;
1941ff39c2d6SFlorian Fainelli 
1942ff39c2d6SFlorian Fainelli 	switch (state) {
1943ff39c2d6SFlorian Fainelli 	case BR_STATE_DISABLED:
1944ff39c2d6SFlorian Fainelli 		hw_state = PORT_CTRL_DIS_STATE;
1945ff39c2d6SFlorian Fainelli 		break;
1946ff39c2d6SFlorian Fainelli 	case BR_STATE_LISTENING:
1947ff39c2d6SFlorian Fainelli 		hw_state = PORT_CTRL_LISTEN_STATE;
1948ff39c2d6SFlorian Fainelli 		break;
1949ff39c2d6SFlorian Fainelli 	case BR_STATE_LEARNING:
1950ff39c2d6SFlorian Fainelli 		hw_state = PORT_CTRL_LEARN_STATE;
1951ff39c2d6SFlorian Fainelli 		break;
1952ff39c2d6SFlorian Fainelli 	case BR_STATE_FORWARDING:
1953ff39c2d6SFlorian Fainelli 		hw_state = PORT_CTRL_FWD_STATE;
1954ff39c2d6SFlorian Fainelli 		break;
1955ff39c2d6SFlorian Fainelli 	case BR_STATE_BLOCKING:
1956ff39c2d6SFlorian Fainelli 		hw_state = PORT_CTRL_BLOCK_STATE;
1957ff39c2d6SFlorian Fainelli 		break;
1958ff39c2d6SFlorian Fainelli 	default:
1959ff39c2d6SFlorian Fainelli 		dev_err(ds->dev, "invalid STP state: %d\n", state);
1960ff39c2d6SFlorian Fainelli 		return;
1961ff39c2d6SFlorian Fainelli 	}
1962ff39c2d6SFlorian Fainelli 
1963ff39c2d6SFlorian Fainelli 	b53_read8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), &reg);
1964ff39c2d6SFlorian Fainelli 	reg &= ~PORT_CTRL_STP_STATE_MASK;
1965ff39c2d6SFlorian Fainelli 	reg |= hw_state;
1966ff39c2d6SFlorian Fainelli 	b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), reg);
1967ff39c2d6SFlorian Fainelli }
19683117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_set_stp_state);
1969ff39c2d6SFlorian Fainelli 
19703117455dSFlorian Fainelli void b53_br_fast_age(struct dsa_switch *ds, int port)
1971597698f1SVivien Didelot {
1972597698f1SVivien Didelot 	struct b53_device *dev = ds->priv;
1973597698f1SVivien Didelot 
1974597698f1SVivien Didelot 	if (b53_fast_age_port(dev, port))
1975597698f1SVivien Didelot 		dev_err(ds->dev, "fast ageing failed\n");
1976597698f1SVivien Didelot }
19773117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_fast_age);
1978597698f1SVivien Didelot 
1979e6dd86edSFlorian Fainelli int b53_br_flags_pre(struct dsa_switch *ds, int port,
1980a8b659e7SVladimir Oltean 		     struct switchdev_brport_flags flags,
1981a8b659e7SVladimir Oltean 		     struct netlink_ext_ack *extack)
198253568438SFlorian Fainelli {
1983f9b3827eSFlorian Fainelli 	if (flags.mask & ~(BR_FLOOD | BR_MCAST_FLOOD | BR_LEARNING))
1984a8b659e7SVladimir Oltean 		return -EINVAL;
198553568438SFlorian Fainelli 
198653568438SFlorian Fainelli 	return 0;
198753568438SFlorian Fainelli }
1988e6dd86edSFlorian Fainelli EXPORT_SYMBOL(b53_br_flags_pre);
1989a8b659e7SVladimir Oltean 
1990e6dd86edSFlorian Fainelli int b53_br_flags(struct dsa_switch *ds, int port,
1991a8b659e7SVladimir Oltean 		 struct switchdev_brport_flags flags,
1992a8b659e7SVladimir Oltean 		 struct netlink_ext_ack *extack)
1993a8b659e7SVladimir Oltean {
1994a8b659e7SVladimir Oltean 	if (flags.mask & BR_FLOOD)
1995a8b659e7SVladimir Oltean 		b53_port_set_ucast_flood(ds->priv, port,
1996a8b659e7SVladimir Oltean 					 !!(flags.val & BR_FLOOD));
1997a8b659e7SVladimir Oltean 	if (flags.mask & BR_MCAST_FLOOD)
1998a8b659e7SVladimir Oltean 		b53_port_set_mcast_flood(ds->priv, port,
1999a8b659e7SVladimir Oltean 					 !!(flags.val & BR_MCAST_FLOOD));
2000f9b3827eSFlorian Fainelli 	if (flags.mask & BR_LEARNING)
2001f9b3827eSFlorian Fainelli 		b53_port_set_learning(ds->priv, port,
2002f9b3827eSFlorian Fainelli 				      !!(flags.val & BR_LEARNING));
2003a8b659e7SVladimir Oltean 
2004a8b659e7SVladimir Oltean 	return 0;
2005a8b659e7SVladimir Oltean }
2006e6dd86edSFlorian Fainelli EXPORT_SYMBOL(b53_br_flags);
2007a8b659e7SVladimir Oltean 
2008e6dd86edSFlorian Fainelli int b53_set_mrouter(struct dsa_switch *ds, int port, bool mrouter,
2009a8b659e7SVladimir Oltean 		    struct netlink_ext_ack *extack)
2010a8b659e7SVladimir Oltean {
2011a8b659e7SVladimir Oltean 	b53_port_set_mcast_flood(ds->priv, port, mrouter);
2012a8b659e7SVladimir Oltean 
2013a8b659e7SVladimir Oltean 	return 0;
2014a8b659e7SVladimir Oltean }
2015e6dd86edSFlorian Fainelli EXPORT_SYMBOL(b53_set_mrouter);
201653568438SFlorian Fainelli 
2017c7d28c9dSFlorian Fainelli static bool b53_possible_cpu_port(struct dsa_switch *ds, int port)
20187edc58d6SFlorian Fainelli {
20197edc58d6SFlorian Fainelli 	/* Broadcom switches will accept enabling Broadcom tags on the
20207edc58d6SFlorian Fainelli 	 * following ports: 5, 7 and 8, any other port is not supported
20217edc58d6SFlorian Fainelli 	 */
20225ed4e3ebSFlorian Fainelli 	switch (port) {
20235ed4e3ebSFlorian Fainelli 	case B53_CPU_PORT_25:
20245ed4e3ebSFlorian Fainelli 	case 7:
20255ed4e3ebSFlorian Fainelli 	case B53_CPU_PORT:
20267edc58d6SFlorian Fainelli 		return true;
20277edc58d6SFlorian Fainelli 	}
20287edc58d6SFlorian Fainelli 
20295ed4e3ebSFlorian Fainelli 	return false;
20305ed4e3ebSFlorian Fainelli }
20315ed4e3ebSFlorian Fainelli 
20328fab459eSFlorian Fainelli static bool b53_can_enable_brcm_tags(struct dsa_switch *ds, int port,
20338fab459eSFlorian Fainelli 				     enum dsa_tag_protocol tag_protocol)
2034c7d28c9dSFlorian Fainelli {
2035c7d28c9dSFlorian Fainelli 	bool ret = b53_possible_cpu_port(ds, port);
2036c7d28c9dSFlorian Fainelli 
20378fab459eSFlorian Fainelli 	if (!ret) {
2038c7d28c9dSFlorian Fainelli 		dev_warn(ds->dev, "Port %d is not Broadcom tag capable\n",
2039c7d28c9dSFlorian Fainelli 			 port);
2040c7d28c9dSFlorian Fainelli 		return ret;
2041c7d28c9dSFlorian Fainelli 	}
2042c7d28c9dSFlorian Fainelli 
20438fab459eSFlorian Fainelli 	switch (tag_protocol) {
20448fab459eSFlorian Fainelli 	case DSA_TAG_PROTO_BRCM:
20458fab459eSFlorian Fainelli 	case DSA_TAG_PROTO_BRCM_PREPEND:
20468fab459eSFlorian Fainelli 		dev_warn(ds->dev,
20478fab459eSFlorian Fainelli 			 "Port %d is stacked to Broadcom tag switch\n", port);
20488fab459eSFlorian Fainelli 		ret = false;
20498fab459eSFlorian Fainelli 		break;
20508fab459eSFlorian Fainelli 	default:
20518fab459eSFlorian Fainelli 		ret = true;
20528fab459eSFlorian Fainelli 		break;
20538fab459eSFlorian Fainelli 	}
20548fab459eSFlorian Fainelli 
20558fab459eSFlorian Fainelli 	return ret;
20568fab459eSFlorian Fainelli }
20578fab459eSFlorian Fainelli 
20584d776482SFlorian Fainelli enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds, int port,
20594d776482SFlorian Fainelli 					   enum dsa_tag_protocol mprot)
20607b314362SAndrew Lunn {
20617edc58d6SFlorian Fainelli 	struct b53_device *dev = ds->priv;
20627edc58d6SFlorian Fainelli 
206346c5176cSÁlvaro Fernández Rojas 	if (!b53_can_enable_brcm_tags(ds, port, mprot)) {
20644d776482SFlorian Fainelli 		dev->tag_protocol = DSA_TAG_PROTO_NONE;
20654d776482SFlorian Fainelli 		goto out;
20664d776482SFlorian Fainelli 	}
206711606039SFlorian Fainelli 
206846c5176cSÁlvaro Fernández Rojas 	/* Older models require a different 6 byte tag */
206946c5176cSÁlvaro Fernández Rojas 	if (is5325(dev) || is5365(dev) || is63xx(dev)) {
207046c5176cSÁlvaro Fernández Rojas 		dev->tag_protocol = DSA_TAG_PROTO_BRCM_LEGACY;
207146c5176cSÁlvaro Fernández Rojas 		goto out;
207246c5176cSÁlvaro Fernández Rojas 	}
207346c5176cSÁlvaro Fernández Rojas 
207411606039SFlorian Fainelli 	/* Broadcom BCM58xx chips have a flow accelerator on Port 8
207511606039SFlorian Fainelli 	 * which requires us to use the prepended Broadcom tag type
207611606039SFlorian Fainelli 	 */
20774d776482SFlorian Fainelli 	if (dev->chip_id == BCM58XX_DEVICE_ID && port == B53_CPU_PORT) {
20784d776482SFlorian Fainelli 		dev->tag_protocol = DSA_TAG_PROTO_BRCM_PREPEND;
20794d776482SFlorian Fainelli 		goto out;
20804d776482SFlorian Fainelli 	}
208111606039SFlorian Fainelli 
20824d776482SFlorian Fainelli 	dev->tag_protocol = DSA_TAG_PROTO_BRCM;
20834d776482SFlorian Fainelli out:
20844d776482SFlorian Fainelli 	return dev->tag_protocol;
20857b314362SAndrew Lunn }
20869f66816aSFlorian Fainelli EXPORT_SYMBOL(b53_get_tag_protocol);
20877b314362SAndrew Lunn 
2088ed3af5fdSFlorian Fainelli int b53_mirror_add(struct dsa_switch *ds, int port,
2089ed3af5fdSFlorian Fainelli 		   struct dsa_mall_mirror_tc_entry *mirror, bool ingress)
2090ed3af5fdSFlorian Fainelli {
2091ed3af5fdSFlorian Fainelli 	struct b53_device *dev = ds->priv;
2092ed3af5fdSFlorian Fainelli 	u16 reg, loc;
2093ed3af5fdSFlorian Fainelli 
2094ed3af5fdSFlorian Fainelli 	if (ingress)
2095ed3af5fdSFlorian Fainelli 		loc = B53_IG_MIR_CTL;
2096ed3af5fdSFlorian Fainelli 	else
2097ed3af5fdSFlorian Fainelli 		loc = B53_EG_MIR_CTL;
2098ed3af5fdSFlorian Fainelli 
2099ed3af5fdSFlorian Fainelli 	b53_read16(dev, B53_MGMT_PAGE, loc, &reg);
2100ed3af5fdSFlorian Fainelli 	reg |= BIT(port);
2101ed3af5fdSFlorian Fainelli 	b53_write16(dev, B53_MGMT_PAGE, loc, reg);
2102ed3af5fdSFlorian Fainelli 
2103ed3af5fdSFlorian Fainelli 	b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, &reg);
2104ed3af5fdSFlorian Fainelli 	reg &= ~CAP_PORT_MASK;
2105ed3af5fdSFlorian Fainelli 	reg |= mirror->to_local_port;
2106ed3af5fdSFlorian Fainelli 	reg |= MIRROR_EN;
2107ed3af5fdSFlorian Fainelli 	b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg);
2108ed3af5fdSFlorian Fainelli 
2109ed3af5fdSFlorian Fainelli 	return 0;
2110ed3af5fdSFlorian Fainelli }
2111ed3af5fdSFlorian Fainelli EXPORT_SYMBOL(b53_mirror_add);
2112ed3af5fdSFlorian Fainelli 
2113ed3af5fdSFlorian Fainelli void b53_mirror_del(struct dsa_switch *ds, int port,
2114ed3af5fdSFlorian Fainelli 		    struct dsa_mall_mirror_tc_entry *mirror)
2115ed3af5fdSFlorian Fainelli {
2116ed3af5fdSFlorian Fainelli 	struct b53_device *dev = ds->priv;
2117ed3af5fdSFlorian Fainelli 	bool loc_disable = false, other_loc_disable = false;
2118ed3af5fdSFlorian Fainelli 	u16 reg, loc;
2119ed3af5fdSFlorian Fainelli 
2120ed3af5fdSFlorian Fainelli 	if (mirror->ingress)
2121ed3af5fdSFlorian Fainelli 		loc = B53_IG_MIR_CTL;
2122ed3af5fdSFlorian Fainelli 	else
2123ed3af5fdSFlorian Fainelli 		loc = B53_EG_MIR_CTL;
2124ed3af5fdSFlorian Fainelli 
2125ed3af5fdSFlorian Fainelli 	/* Update the desired ingress/egress register */
2126ed3af5fdSFlorian Fainelli 	b53_read16(dev, B53_MGMT_PAGE, loc, &reg);
2127ed3af5fdSFlorian Fainelli 	reg &= ~BIT(port);
2128ed3af5fdSFlorian Fainelli 	if (!(reg & MIRROR_MASK))
2129ed3af5fdSFlorian Fainelli 		loc_disable = true;
2130ed3af5fdSFlorian Fainelli 	b53_write16(dev, B53_MGMT_PAGE, loc, reg);
2131ed3af5fdSFlorian Fainelli 
2132ed3af5fdSFlorian Fainelli 	/* Now look at the other one to know if we can disable mirroring
2133ed3af5fdSFlorian Fainelli 	 * entirely
2134ed3af5fdSFlorian Fainelli 	 */
2135ed3af5fdSFlorian Fainelli 	if (mirror->ingress)
2136ed3af5fdSFlorian Fainelli 		b53_read16(dev, B53_MGMT_PAGE, B53_EG_MIR_CTL, &reg);
2137ed3af5fdSFlorian Fainelli 	else
2138ed3af5fdSFlorian Fainelli 		b53_read16(dev, B53_MGMT_PAGE, B53_IG_MIR_CTL, &reg);
2139ed3af5fdSFlorian Fainelli 	if (!(reg & MIRROR_MASK))
2140ed3af5fdSFlorian Fainelli 		other_loc_disable = true;
2141ed3af5fdSFlorian Fainelli 
2142ed3af5fdSFlorian Fainelli 	b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, &reg);
2143ed3af5fdSFlorian Fainelli 	/* Both no longer have ports, let's disable mirroring */
2144ed3af5fdSFlorian Fainelli 	if (loc_disable && other_loc_disable) {
2145ed3af5fdSFlorian Fainelli 		reg &= ~MIRROR_EN;
2146ed3af5fdSFlorian Fainelli 		reg &= ~mirror->to_local_port;
2147ed3af5fdSFlorian Fainelli 	}
2148ed3af5fdSFlorian Fainelli 	b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg);
2149ed3af5fdSFlorian Fainelli }
2150ed3af5fdSFlorian Fainelli EXPORT_SYMBOL(b53_mirror_del);
2151ed3af5fdSFlorian Fainelli 
215222256b0aSFlorian Fainelli void b53_eee_enable_set(struct dsa_switch *ds, int port, bool enable)
215322256b0aSFlorian Fainelli {
215422256b0aSFlorian Fainelli 	struct b53_device *dev = ds->priv;
215522256b0aSFlorian Fainelli 	u16 reg;
215622256b0aSFlorian Fainelli 
215722256b0aSFlorian Fainelli 	b53_read16(dev, B53_EEE_PAGE, B53_EEE_EN_CTRL, &reg);
215822256b0aSFlorian Fainelli 	if (enable)
215922256b0aSFlorian Fainelli 		reg |= BIT(port);
216022256b0aSFlorian Fainelli 	else
216122256b0aSFlorian Fainelli 		reg &= ~BIT(port);
216222256b0aSFlorian Fainelli 	b53_write16(dev, B53_EEE_PAGE, B53_EEE_EN_CTRL, reg);
216322256b0aSFlorian Fainelli }
216422256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_eee_enable_set);
216522256b0aSFlorian Fainelli 
216622256b0aSFlorian Fainelli 
216722256b0aSFlorian Fainelli /* Returns 0 if EEE was not enabled, or 1 otherwise
216822256b0aSFlorian Fainelli  */
216922256b0aSFlorian Fainelli int b53_eee_init(struct dsa_switch *ds, int port, struct phy_device *phy)
217022256b0aSFlorian Fainelli {
217122256b0aSFlorian Fainelli 	int ret;
217222256b0aSFlorian Fainelli 
217322256b0aSFlorian Fainelli 	ret = phy_init_eee(phy, 0);
217422256b0aSFlorian Fainelli 	if (ret)
217522256b0aSFlorian Fainelli 		return 0;
217622256b0aSFlorian Fainelli 
217722256b0aSFlorian Fainelli 	b53_eee_enable_set(ds, port, true);
217822256b0aSFlorian Fainelli 
217922256b0aSFlorian Fainelli 	return 1;
218022256b0aSFlorian Fainelli }
218122256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_eee_init);
218222256b0aSFlorian Fainelli 
218322256b0aSFlorian Fainelli int b53_get_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e)
218422256b0aSFlorian Fainelli {
218522256b0aSFlorian Fainelli 	struct b53_device *dev = ds->priv;
218622256b0aSFlorian Fainelli 	struct ethtool_eee *p = &dev->ports[port].eee;
218722256b0aSFlorian Fainelli 	u16 reg;
218822256b0aSFlorian Fainelli 
218922256b0aSFlorian Fainelli 	if (is5325(dev) || is5365(dev))
219022256b0aSFlorian Fainelli 		return -EOPNOTSUPP;
219122256b0aSFlorian Fainelli 
219222256b0aSFlorian Fainelli 	b53_read16(dev, B53_EEE_PAGE, B53_EEE_LPI_INDICATE, &reg);
219322256b0aSFlorian Fainelli 	e->eee_enabled = p->eee_enabled;
219422256b0aSFlorian Fainelli 	e->eee_active = !!(reg & BIT(port));
219522256b0aSFlorian Fainelli 
219622256b0aSFlorian Fainelli 	return 0;
219722256b0aSFlorian Fainelli }
219822256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_get_mac_eee);
219922256b0aSFlorian Fainelli 
220022256b0aSFlorian Fainelli int b53_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e)
220122256b0aSFlorian Fainelli {
220222256b0aSFlorian Fainelli 	struct b53_device *dev = ds->priv;
220322256b0aSFlorian Fainelli 	struct ethtool_eee *p = &dev->ports[port].eee;
220422256b0aSFlorian Fainelli 
220522256b0aSFlorian Fainelli 	if (is5325(dev) || is5365(dev))
220622256b0aSFlorian Fainelli 		return -EOPNOTSUPP;
220722256b0aSFlorian Fainelli 
220822256b0aSFlorian Fainelli 	p->eee_enabled = e->eee_enabled;
220922256b0aSFlorian Fainelli 	b53_eee_enable_set(ds, port, e->eee_enabled);
221022256b0aSFlorian Fainelli 
221122256b0aSFlorian Fainelli 	return 0;
221222256b0aSFlorian Fainelli }
221322256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_set_mac_eee);
221422256b0aSFlorian Fainelli 
22156ae5834bSMurali Krishna Policharla static int b53_change_mtu(struct dsa_switch *ds, int port, int mtu)
22166ae5834bSMurali Krishna Policharla {
22176ae5834bSMurali Krishna Policharla 	struct b53_device *dev = ds->priv;
22186ae5834bSMurali Krishna Policharla 	bool enable_jumbo;
22196ae5834bSMurali Krishna Policharla 	bool allow_10_100;
22206ae5834bSMurali Krishna Policharla 
22216ae5834bSMurali Krishna Policharla 	if (is5325(dev) || is5365(dev))
22226ae5834bSMurali Krishna Policharla 		return -EOPNOTSUPP;
22236ae5834bSMurali Krishna Policharla 
22246ae5834bSMurali Krishna Policharla 	enable_jumbo = (mtu >= JMS_MIN_SIZE);
22256ae5834bSMurali Krishna Policharla 	allow_10_100 = (dev->chip_id == BCM583XX_DEVICE_ID);
22266ae5834bSMurali Krishna Policharla 
22276ae5834bSMurali Krishna Policharla 	return b53_set_jumbo(dev, enable_jumbo, allow_10_100);
22286ae5834bSMurali Krishna Policharla }
22296ae5834bSMurali Krishna Policharla 
22306ae5834bSMurali Krishna Policharla static int b53_get_max_mtu(struct dsa_switch *ds, int port)
22316ae5834bSMurali Krishna Policharla {
22326ae5834bSMurali Krishna Policharla 	return JMS_MAX_SIZE;
22336ae5834bSMurali Krishna Policharla }
22346ae5834bSMurali Krishna Policharla 
2235a82f67afSFlorian Fainelli static const struct dsa_switch_ops b53_switch_ops = {
22367b314362SAndrew Lunn 	.get_tag_protocol	= b53_get_tag_protocol,
2237967dd82fSFlorian Fainelli 	.setup			= b53_setup,
22384f6a5cafSFlorian Fainelli 	.teardown		= b53_teardown,
2239967dd82fSFlorian Fainelli 	.get_strings		= b53_get_strings,
2240967dd82fSFlorian Fainelli 	.get_ethtool_stats	= b53_get_ethtool_stats,
2241967dd82fSFlorian Fainelli 	.get_sset_count		= b53_get_sset_count,
2242c7d28c9dSFlorian Fainelli 	.get_ethtool_phy_stats	= b53_get_ethtool_phy_stats,
2243967dd82fSFlorian Fainelli 	.phy_read		= b53_phy_read16,
2244967dd82fSFlorian Fainelli 	.phy_write		= b53_phy_write16,
2245967dd82fSFlorian Fainelli 	.adjust_link		= b53_adjust_link,
2246a8e8b985SFlorian Fainelli 	.phylink_validate	= b53_phylink_validate,
2247a8e8b985SFlorian Fainelli 	.phylink_mac_link_state	= b53_phylink_mac_link_state,
2248a8e8b985SFlorian Fainelli 	.phylink_mac_config	= b53_phylink_mac_config,
2249a8e8b985SFlorian Fainelli 	.phylink_mac_an_restart	= b53_phylink_mac_an_restart,
2250a8e8b985SFlorian Fainelli 	.phylink_mac_link_down	= b53_phylink_mac_link_down,
2251a8e8b985SFlorian Fainelli 	.phylink_mac_link_up	= b53_phylink_mac_link_up,
2252967dd82fSFlorian Fainelli 	.port_enable		= b53_enable_port,
2253967dd82fSFlorian Fainelli 	.port_disable		= b53_disable_port,
2254f43a2dbeSFlorian Fainelli 	.get_mac_eee		= b53_get_mac_eee,
2255f43a2dbeSFlorian Fainelli 	.set_mac_eee		= b53_set_mac_eee,
2256ff39c2d6SFlorian Fainelli 	.port_bridge_join	= b53_br_join,
2257ff39c2d6SFlorian Fainelli 	.port_bridge_leave	= b53_br_leave,
2258a8b659e7SVladimir Oltean 	.port_pre_bridge_flags	= b53_br_flags_pre,
2259a8b659e7SVladimir Oltean 	.port_bridge_flags	= b53_br_flags,
2260a8b659e7SVladimir Oltean 	.port_set_mrouter	= b53_set_mrouter,
2261ff39c2d6SFlorian Fainelli 	.port_stp_state_set	= b53_br_set_stp_state,
2262597698f1SVivien Didelot 	.port_fast_age		= b53_br_fast_age,
2263a2482d2cSFlorian Fainelli 	.port_vlan_filtering	= b53_vlan_filtering,
2264a2482d2cSFlorian Fainelli 	.port_vlan_add		= b53_vlan_add,
2265a2482d2cSFlorian Fainelli 	.port_vlan_del		= b53_vlan_del,
22661da6df85SFlorian Fainelli 	.port_fdb_dump		= b53_fdb_dump,
22671da6df85SFlorian Fainelli 	.port_fdb_add		= b53_fdb_add,
22681da6df85SFlorian Fainelli 	.port_fdb_del		= b53_fdb_del,
2269ed3af5fdSFlorian Fainelli 	.port_mirror_add	= b53_mirror_add,
2270ed3af5fdSFlorian Fainelli 	.port_mirror_del	= b53_mirror_del,
22715d65b64aSFlorian Fainelli 	.port_mdb_add		= b53_mdb_add,
22725d65b64aSFlorian Fainelli 	.port_mdb_del		= b53_mdb_del,
22736ae5834bSMurali Krishna Policharla 	.port_max_mtu		= b53_get_max_mtu,
22746ae5834bSMurali Krishna Policharla 	.port_change_mtu	= b53_change_mtu,
2275967dd82fSFlorian Fainelli };
2276967dd82fSFlorian Fainelli 
2277967dd82fSFlorian Fainelli struct b53_chip_data {
2278967dd82fSFlorian Fainelli 	u32 chip_id;
2279967dd82fSFlorian Fainelli 	const char *dev_name;
2280967dd82fSFlorian Fainelli 	u16 vlans;
2281967dd82fSFlorian Fainelli 	u16 enabled_ports;
2282967dd82fSFlorian Fainelli 	u8 cpu_port;
2283967dd82fSFlorian Fainelli 	u8 vta_regs[3];
2284673e69a6SFlorian Fainelli 	u8 arl_bins;
2285e3da4038SFlorian Fainelli 	u16 arl_buckets;
2286967dd82fSFlorian Fainelli 	u8 duplex_reg;
2287967dd82fSFlorian Fainelli 	u8 jumbo_pm_reg;
2288967dd82fSFlorian Fainelli 	u8 jumbo_size_reg;
2289967dd82fSFlorian Fainelli };
2290967dd82fSFlorian Fainelli 
2291967dd82fSFlorian Fainelli #define B53_VTA_REGS	\
2292967dd82fSFlorian Fainelli 	{ B53_VT_ACCESS, B53_VT_INDEX, B53_VT_ENTRY }
2293967dd82fSFlorian Fainelli #define B53_VTA_REGS_9798 \
2294967dd82fSFlorian Fainelli 	{ B53_VT_ACCESS_9798, B53_VT_INDEX_9798, B53_VT_ENTRY_9798 }
2295967dd82fSFlorian Fainelli #define B53_VTA_REGS_63XX \
2296967dd82fSFlorian Fainelli 	{ B53_VT_ACCESS_63XX, B53_VT_INDEX_63XX, B53_VT_ENTRY_63XX }
2297967dd82fSFlorian Fainelli 
2298967dd82fSFlorian Fainelli static const struct b53_chip_data b53_switch_chips[] = {
2299967dd82fSFlorian Fainelli 	{
2300967dd82fSFlorian Fainelli 		.chip_id = BCM5325_DEVICE_ID,
2301967dd82fSFlorian Fainelli 		.dev_name = "BCM5325",
2302967dd82fSFlorian Fainelli 		.vlans = 16,
2303967dd82fSFlorian Fainelli 		.enabled_ports = 0x1f,
2304673e69a6SFlorian Fainelli 		.arl_bins = 2,
2305e3da4038SFlorian Fainelli 		.arl_buckets = 1024,
2306967dd82fSFlorian Fainelli 		.cpu_port = B53_CPU_PORT_25,
2307967dd82fSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_FE,
2308967dd82fSFlorian Fainelli 	},
2309967dd82fSFlorian Fainelli 	{
2310967dd82fSFlorian Fainelli 		.chip_id = BCM5365_DEVICE_ID,
2311967dd82fSFlorian Fainelli 		.dev_name = "BCM5365",
2312967dd82fSFlorian Fainelli 		.vlans = 256,
2313967dd82fSFlorian Fainelli 		.enabled_ports = 0x1f,
2314673e69a6SFlorian Fainelli 		.arl_bins = 2,
2315e3da4038SFlorian Fainelli 		.arl_buckets = 1024,
2316967dd82fSFlorian Fainelli 		.cpu_port = B53_CPU_PORT_25,
2317967dd82fSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_FE,
2318967dd82fSFlorian Fainelli 	},
2319967dd82fSFlorian Fainelli 	{
2320a95691bcSDamien Thébault 		.chip_id = BCM5389_DEVICE_ID,
2321a95691bcSDamien Thébault 		.dev_name = "BCM5389",
2322a95691bcSDamien Thébault 		.vlans = 4096,
2323a95691bcSDamien Thébault 		.enabled_ports = 0x1f,
2324673e69a6SFlorian Fainelli 		.arl_bins = 4,
2325e3da4038SFlorian Fainelli 		.arl_buckets = 1024,
2326a95691bcSDamien Thébault 		.cpu_port = B53_CPU_PORT,
2327a95691bcSDamien Thébault 		.vta_regs = B53_VTA_REGS,
2328a95691bcSDamien Thébault 		.duplex_reg = B53_DUPLEX_STAT_GE,
2329a95691bcSDamien Thébault 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2330a95691bcSDamien Thébault 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2331a95691bcSDamien Thébault 	},
2332a95691bcSDamien Thébault 	{
2333967dd82fSFlorian Fainelli 		.chip_id = BCM5395_DEVICE_ID,
2334967dd82fSFlorian Fainelli 		.dev_name = "BCM5395",
2335967dd82fSFlorian Fainelli 		.vlans = 4096,
2336967dd82fSFlorian Fainelli 		.enabled_ports = 0x1f,
2337673e69a6SFlorian Fainelli 		.arl_bins = 4,
2338e3da4038SFlorian Fainelli 		.arl_buckets = 1024,
2339967dd82fSFlorian Fainelli 		.cpu_port = B53_CPU_PORT,
2340967dd82fSFlorian Fainelli 		.vta_regs = B53_VTA_REGS,
2341967dd82fSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_GE,
2342967dd82fSFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2343967dd82fSFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2344967dd82fSFlorian Fainelli 	},
2345967dd82fSFlorian Fainelli 	{
2346967dd82fSFlorian Fainelli 		.chip_id = BCM5397_DEVICE_ID,
2347967dd82fSFlorian Fainelli 		.dev_name = "BCM5397",
2348967dd82fSFlorian Fainelli 		.vlans = 4096,
2349967dd82fSFlorian Fainelli 		.enabled_ports = 0x1f,
2350673e69a6SFlorian Fainelli 		.arl_bins = 4,
2351e3da4038SFlorian Fainelli 		.arl_buckets = 1024,
2352967dd82fSFlorian Fainelli 		.cpu_port = B53_CPU_PORT,
2353967dd82fSFlorian Fainelli 		.vta_regs = B53_VTA_REGS_9798,
2354967dd82fSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_GE,
2355967dd82fSFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2356967dd82fSFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2357967dd82fSFlorian Fainelli 	},
2358967dd82fSFlorian Fainelli 	{
2359967dd82fSFlorian Fainelli 		.chip_id = BCM5398_DEVICE_ID,
2360967dd82fSFlorian Fainelli 		.dev_name = "BCM5398",
2361967dd82fSFlorian Fainelli 		.vlans = 4096,
2362967dd82fSFlorian Fainelli 		.enabled_ports = 0x7f,
2363673e69a6SFlorian Fainelli 		.arl_bins = 4,
2364e3da4038SFlorian Fainelli 		.arl_buckets = 1024,
2365967dd82fSFlorian Fainelli 		.cpu_port = B53_CPU_PORT,
2366967dd82fSFlorian Fainelli 		.vta_regs = B53_VTA_REGS_9798,
2367967dd82fSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_GE,
2368967dd82fSFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2369967dd82fSFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2370967dd82fSFlorian Fainelli 	},
2371967dd82fSFlorian Fainelli 	{
2372967dd82fSFlorian Fainelli 		.chip_id = BCM53115_DEVICE_ID,
2373967dd82fSFlorian Fainelli 		.dev_name = "BCM53115",
2374967dd82fSFlorian Fainelli 		.vlans = 4096,
2375967dd82fSFlorian Fainelli 		.enabled_ports = 0x1f,
2376673e69a6SFlorian Fainelli 		.arl_bins = 4,
2377e3da4038SFlorian Fainelli 		.arl_buckets = 1024,
2378967dd82fSFlorian Fainelli 		.vta_regs = B53_VTA_REGS,
2379967dd82fSFlorian Fainelli 		.cpu_port = B53_CPU_PORT,
2380967dd82fSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_GE,
2381967dd82fSFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2382967dd82fSFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2383967dd82fSFlorian Fainelli 	},
2384967dd82fSFlorian Fainelli 	{
2385967dd82fSFlorian Fainelli 		.chip_id = BCM53125_DEVICE_ID,
2386967dd82fSFlorian Fainelli 		.dev_name = "BCM53125",
2387967dd82fSFlorian Fainelli 		.vlans = 4096,
2388967dd82fSFlorian Fainelli 		.enabled_ports = 0xff,
2389673e69a6SFlorian Fainelli 		.arl_bins = 4,
2390e3da4038SFlorian Fainelli 		.arl_buckets = 1024,
2391967dd82fSFlorian Fainelli 		.cpu_port = B53_CPU_PORT,
2392967dd82fSFlorian Fainelli 		.vta_regs = B53_VTA_REGS,
2393967dd82fSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_GE,
2394967dd82fSFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2395967dd82fSFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2396967dd82fSFlorian Fainelli 	},
2397967dd82fSFlorian Fainelli 	{
2398967dd82fSFlorian Fainelli 		.chip_id = BCM53128_DEVICE_ID,
2399967dd82fSFlorian Fainelli 		.dev_name = "BCM53128",
2400967dd82fSFlorian Fainelli 		.vlans = 4096,
2401967dd82fSFlorian Fainelli 		.enabled_ports = 0x1ff,
2402673e69a6SFlorian Fainelli 		.arl_bins = 4,
2403e3da4038SFlorian Fainelli 		.arl_buckets = 1024,
2404967dd82fSFlorian Fainelli 		.cpu_port = B53_CPU_PORT,
2405967dd82fSFlorian Fainelli 		.vta_regs = B53_VTA_REGS,
2406967dd82fSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_GE,
2407967dd82fSFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2408967dd82fSFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2409967dd82fSFlorian Fainelli 	},
2410967dd82fSFlorian Fainelli 	{
2411967dd82fSFlorian Fainelli 		.chip_id = BCM63XX_DEVICE_ID,
2412967dd82fSFlorian Fainelli 		.dev_name = "BCM63xx",
2413967dd82fSFlorian Fainelli 		.vlans = 4096,
2414967dd82fSFlorian Fainelli 		.enabled_ports = 0, /* pdata must provide them */
2415673e69a6SFlorian Fainelli 		.arl_bins = 4,
2416e3da4038SFlorian Fainelli 		.arl_buckets = 1024,
2417967dd82fSFlorian Fainelli 		.cpu_port = B53_CPU_PORT,
2418967dd82fSFlorian Fainelli 		.vta_regs = B53_VTA_REGS_63XX,
2419967dd82fSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_63XX,
2420967dd82fSFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK_63XX,
2421967dd82fSFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE_63XX,
2422967dd82fSFlorian Fainelli 	},
2423967dd82fSFlorian Fainelli 	{
2424967dd82fSFlorian Fainelli 		.chip_id = BCM53010_DEVICE_ID,
2425967dd82fSFlorian Fainelli 		.dev_name = "BCM53010",
2426967dd82fSFlorian Fainelli 		.vlans = 4096,
2427967dd82fSFlorian Fainelli 		.enabled_ports = 0x1f,
2428673e69a6SFlorian Fainelli 		.arl_bins = 4,
2429e3da4038SFlorian Fainelli 		.arl_buckets = 1024,
2430967dd82fSFlorian Fainelli 		.cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
2431967dd82fSFlorian Fainelli 		.vta_regs = B53_VTA_REGS,
2432967dd82fSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_GE,
2433967dd82fSFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2434967dd82fSFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2435967dd82fSFlorian Fainelli 	},
2436967dd82fSFlorian Fainelli 	{
2437967dd82fSFlorian Fainelli 		.chip_id = BCM53011_DEVICE_ID,
2438967dd82fSFlorian Fainelli 		.dev_name = "BCM53011",
2439967dd82fSFlorian Fainelli 		.vlans = 4096,
2440967dd82fSFlorian Fainelli 		.enabled_ports = 0x1bf,
2441673e69a6SFlorian Fainelli 		.arl_bins = 4,
2442e3da4038SFlorian Fainelli 		.arl_buckets = 1024,
2443967dd82fSFlorian Fainelli 		.cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
2444967dd82fSFlorian Fainelli 		.vta_regs = B53_VTA_REGS,
2445967dd82fSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_GE,
2446967dd82fSFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2447967dd82fSFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2448967dd82fSFlorian Fainelli 	},
2449967dd82fSFlorian Fainelli 	{
2450967dd82fSFlorian Fainelli 		.chip_id = BCM53012_DEVICE_ID,
2451967dd82fSFlorian Fainelli 		.dev_name = "BCM53012",
2452967dd82fSFlorian Fainelli 		.vlans = 4096,
2453967dd82fSFlorian Fainelli 		.enabled_ports = 0x1bf,
2454673e69a6SFlorian Fainelli 		.arl_bins = 4,
2455e3da4038SFlorian Fainelli 		.arl_buckets = 1024,
2456967dd82fSFlorian Fainelli 		.cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
2457967dd82fSFlorian Fainelli 		.vta_regs = B53_VTA_REGS,
2458967dd82fSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_GE,
2459967dd82fSFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2460967dd82fSFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2461967dd82fSFlorian Fainelli 	},
2462967dd82fSFlorian Fainelli 	{
2463967dd82fSFlorian Fainelli 		.chip_id = BCM53018_DEVICE_ID,
2464967dd82fSFlorian Fainelli 		.dev_name = "BCM53018",
2465967dd82fSFlorian Fainelli 		.vlans = 4096,
2466967dd82fSFlorian Fainelli 		.enabled_ports = 0x1f,
2467673e69a6SFlorian Fainelli 		.arl_bins = 4,
2468e3da4038SFlorian Fainelli 		.arl_buckets = 1024,
2469967dd82fSFlorian Fainelli 		.cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
2470967dd82fSFlorian Fainelli 		.vta_regs = B53_VTA_REGS,
2471967dd82fSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_GE,
2472967dd82fSFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2473967dd82fSFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2474967dd82fSFlorian Fainelli 	},
2475967dd82fSFlorian Fainelli 	{
2476967dd82fSFlorian Fainelli 		.chip_id = BCM53019_DEVICE_ID,
2477967dd82fSFlorian Fainelli 		.dev_name = "BCM53019",
2478967dd82fSFlorian Fainelli 		.vlans = 4096,
2479967dd82fSFlorian Fainelli 		.enabled_ports = 0x1f,
2480673e69a6SFlorian Fainelli 		.arl_bins = 4,
2481e3da4038SFlorian Fainelli 		.arl_buckets = 1024,
2482967dd82fSFlorian Fainelli 		.cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
2483967dd82fSFlorian Fainelli 		.vta_regs = B53_VTA_REGS,
2484967dd82fSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_GE,
2485967dd82fSFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2486967dd82fSFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2487967dd82fSFlorian Fainelli 	},
2488991a36bbSFlorian Fainelli 	{
2489991a36bbSFlorian Fainelli 		.chip_id = BCM58XX_DEVICE_ID,
2490991a36bbSFlorian Fainelli 		.dev_name = "BCM585xx/586xx/88312",
2491991a36bbSFlorian Fainelli 		.vlans	= 4096,
2492991a36bbSFlorian Fainelli 		.enabled_ports = 0x1ff,
2493673e69a6SFlorian Fainelli 		.arl_bins = 4,
2494e3da4038SFlorian Fainelli 		.arl_buckets = 1024,
2495bfcda65cSFlorian Fainelli 		.cpu_port = B53_CPU_PORT,
2496991a36bbSFlorian Fainelli 		.vta_regs = B53_VTA_REGS,
2497991a36bbSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_GE,
2498991a36bbSFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2499991a36bbSFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2500991a36bbSFlorian Fainelli 	},
2501130401d9SFlorian Fainelli 	{
25025040cc99SArun Parameswaran 		.chip_id = BCM583XX_DEVICE_ID,
25035040cc99SArun Parameswaran 		.dev_name = "BCM583xx/11360",
25045040cc99SArun Parameswaran 		.vlans = 4096,
25055040cc99SArun Parameswaran 		.enabled_ports = 0x103,
2506673e69a6SFlorian Fainelli 		.arl_bins = 4,
2507e3da4038SFlorian Fainelli 		.arl_buckets = 1024,
25085040cc99SArun Parameswaran 		.cpu_port = B53_CPU_PORT,
25095040cc99SArun Parameswaran 		.vta_regs = B53_VTA_REGS,
25105040cc99SArun Parameswaran 		.duplex_reg = B53_DUPLEX_STAT_GE,
25115040cc99SArun Parameswaran 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
25125040cc99SArun Parameswaran 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
25135040cc99SArun Parameswaran 	},
251473b7a604SRafał Miłecki 	/* Starfighter 2 */
251573b7a604SRafał Miłecki 	{
251673b7a604SRafał Miłecki 		.chip_id = BCM4908_DEVICE_ID,
251773b7a604SRafał Miłecki 		.dev_name = "BCM4908",
251873b7a604SRafał Miłecki 		.vlans = 4096,
251973b7a604SRafał Miłecki 		.enabled_ports = 0x1bf,
252073b7a604SRafał Miłecki 		.arl_bins = 4,
252173b7a604SRafał Miłecki 		.arl_buckets = 256,
252273b7a604SRafał Miłecki 		.cpu_port = 8, /* TODO: ports 4, 5, 8 */
252373b7a604SRafał Miłecki 		.vta_regs = B53_VTA_REGS,
252473b7a604SRafał Miłecki 		.duplex_reg = B53_DUPLEX_STAT_GE,
252573b7a604SRafał Miłecki 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
252673b7a604SRafał Miłecki 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
252773b7a604SRafał Miłecki 	},
25285040cc99SArun Parameswaran 	{
2529130401d9SFlorian Fainelli 		.chip_id = BCM7445_DEVICE_ID,
2530130401d9SFlorian Fainelli 		.dev_name = "BCM7445",
2531130401d9SFlorian Fainelli 		.vlans	= 4096,
2532130401d9SFlorian Fainelli 		.enabled_ports = 0x1ff,
2533673e69a6SFlorian Fainelli 		.arl_bins = 4,
2534e3da4038SFlorian Fainelli 		.arl_buckets = 1024,
2535130401d9SFlorian Fainelli 		.cpu_port = B53_CPU_PORT,
2536130401d9SFlorian Fainelli 		.vta_regs = B53_VTA_REGS,
2537130401d9SFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_GE,
2538130401d9SFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2539130401d9SFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2540130401d9SFlorian Fainelli 	},
25410fe99338SFlorian Fainelli 	{
25420fe99338SFlorian Fainelli 		.chip_id = BCM7278_DEVICE_ID,
25430fe99338SFlorian Fainelli 		.dev_name = "BCM7278",
25440fe99338SFlorian Fainelli 		.vlans = 4096,
25450fe99338SFlorian Fainelli 		.enabled_ports = 0x1ff,
2546673e69a6SFlorian Fainelli 		.arl_bins = 4,
2547e3da4038SFlorian Fainelli 		.arl_buckets = 256,
25480fe99338SFlorian Fainelli 		.cpu_port = B53_CPU_PORT,
25490fe99338SFlorian Fainelli 		.vta_regs = B53_VTA_REGS,
25500fe99338SFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_GE,
25510fe99338SFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
25520fe99338SFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
25530fe99338SFlorian Fainelli 	},
2554967dd82fSFlorian Fainelli };
2555967dd82fSFlorian Fainelli 
2556967dd82fSFlorian Fainelli static int b53_switch_init(struct b53_device *dev)
2557967dd82fSFlorian Fainelli {
2558967dd82fSFlorian Fainelli 	unsigned int i;
2559967dd82fSFlorian Fainelli 	int ret;
2560967dd82fSFlorian Fainelli 
2561967dd82fSFlorian Fainelli 	for (i = 0; i < ARRAY_SIZE(b53_switch_chips); i++) {
2562967dd82fSFlorian Fainelli 		const struct b53_chip_data *chip = &b53_switch_chips[i];
2563967dd82fSFlorian Fainelli 
2564967dd82fSFlorian Fainelli 		if (chip->chip_id == dev->chip_id) {
2565967dd82fSFlorian Fainelli 			if (!dev->enabled_ports)
2566967dd82fSFlorian Fainelli 				dev->enabled_ports = chip->enabled_ports;
2567967dd82fSFlorian Fainelli 			dev->name = chip->dev_name;
2568967dd82fSFlorian Fainelli 			dev->duplex_reg = chip->duplex_reg;
2569967dd82fSFlorian Fainelli 			dev->vta_regs[0] = chip->vta_regs[0];
2570967dd82fSFlorian Fainelli 			dev->vta_regs[1] = chip->vta_regs[1];
2571967dd82fSFlorian Fainelli 			dev->vta_regs[2] = chip->vta_regs[2];
2572967dd82fSFlorian Fainelli 			dev->jumbo_pm_reg = chip->jumbo_pm_reg;
2573967dd82fSFlorian Fainelli 			dev->cpu_port = chip->cpu_port;
2574967dd82fSFlorian Fainelli 			dev->num_vlans = chip->vlans;
2575673e69a6SFlorian Fainelli 			dev->num_arl_bins = chip->arl_bins;
2576e3da4038SFlorian Fainelli 			dev->num_arl_buckets = chip->arl_buckets;
2577967dd82fSFlorian Fainelli 			break;
2578967dd82fSFlorian Fainelli 		}
2579967dd82fSFlorian Fainelli 	}
2580967dd82fSFlorian Fainelli 
2581967dd82fSFlorian Fainelli 	/* check which BCM5325x version we have */
2582967dd82fSFlorian Fainelli 	if (is5325(dev)) {
2583967dd82fSFlorian Fainelli 		u8 vc4;
2584967dd82fSFlorian Fainelli 
2585967dd82fSFlorian Fainelli 		b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, &vc4);
2586967dd82fSFlorian Fainelli 
2587967dd82fSFlorian Fainelli 		/* check reserved bits */
2588967dd82fSFlorian Fainelli 		switch (vc4 & 3) {
2589967dd82fSFlorian Fainelli 		case 1:
2590967dd82fSFlorian Fainelli 			/* BCM5325E */
2591967dd82fSFlorian Fainelli 			break;
2592967dd82fSFlorian Fainelli 		case 3:
2593967dd82fSFlorian Fainelli 			/* BCM5325F - do not use port 4 */
2594967dd82fSFlorian Fainelli 			dev->enabled_ports &= ~BIT(4);
2595967dd82fSFlorian Fainelli 			break;
2596967dd82fSFlorian Fainelli 		default:
2597967dd82fSFlorian Fainelli /* On the BCM47XX SoCs this is the supported internal switch.*/
2598967dd82fSFlorian Fainelli #ifndef CONFIG_BCM47XX
2599967dd82fSFlorian Fainelli 			/* BCM5325M */
2600967dd82fSFlorian Fainelli 			return -EINVAL;
2601967dd82fSFlorian Fainelli #else
2602967dd82fSFlorian Fainelli 			break;
2603967dd82fSFlorian Fainelli #endif
2604967dd82fSFlorian Fainelli 		}
2605967dd82fSFlorian Fainelli 	} else if (dev->chip_id == BCM53115_DEVICE_ID) {
2606967dd82fSFlorian Fainelli 		u64 strap_value;
2607967dd82fSFlorian Fainelli 
2608967dd82fSFlorian Fainelli 		b53_read48(dev, B53_STAT_PAGE, B53_STRAP_VALUE, &strap_value);
2609967dd82fSFlorian Fainelli 		/* use second IMP port if GMII is enabled */
2610967dd82fSFlorian Fainelli 		if (strap_value & SV_GMII_CTRL_115)
2611967dd82fSFlorian Fainelli 			dev->cpu_port = 5;
2612967dd82fSFlorian Fainelli 	}
2613967dd82fSFlorian Fainelli 
2614967dd82fSFlorian Fainelli 	/* cpu port is always last */
2615967dd82fSFlorian Fainelli 	dev->num_ports = dev->cpu_port + 1;
2616967dd82fSFlorian Fainelli 	dev->enabled_ports |= BIT(dev->cpu_port);
2617967dd82fSFlorian Fainelli 
2618c7d28c9dSFlorian Fainelli 	/* Include non standard CPU port built-in PHYs to be probed */
2619c7d28c9dSFlorian Fainelli 	if (is539x(dev) || is531x5(dev)) {
2620c7d28c9dSFlorian Fainelli 		for (i = 0; i < dev->num_ports; i++) {
2621c7d28c9dSFlorian Fainelli 			if (!(dev->ds->phys_mii_mask & BIT(i)) &&
2622c7d28c9dSFlorian Fainelli 			    !b53_possible_cpu_port(dev->ds, i))
2623c7d28c9dSFlorian Fainelli 				dev->ds->phys_mii_mask |= BIT(i);
2624c7d28c9dSFlorian Fainelli 		}
2625c7d28c9dSFlorian Fainelli 	}
2626c7d28c9dSFlorian Fainelli 
2627a86854d0SKees Cook 	dev->ports = devm_kcalloc(dev->dev,
2628a86854d0SKees Cook 				  dev->num_ports, sizeof(struct b53_port),
2629967dd82fSFlorian Fainelli 				  GFP_KERNEL);
2630967dd82fSFlorian Fainelli 	if (!dev->ports)
2631967dd82fSFlorian Fainelli 		return -ENOMEM;
2632967dd82fSFlorian Fainelli 
2633a86854d0SKees Cook 	dev->vlans = devm_kcalloc(dev->dev,
2634a86854d0SKees Cook 				  dev->num_vlans, sizeof(struct b53_vlan),
2635a2482d2cSFlorian Fainelli 				  GFP_KERNEL);
2636a2482d2cSFlorian Fainelli 	if (!dev->vlans)
2637a2482d2cSFlorian Fainelli 		return -ENOMEM;
2638a2482d2cSFlorian Fainelli 
2639967dd82fSFlorian Fainelli 	dev->reset_gpio = b53_switch_get_reset_gpio(dev);
2640967dd82fSFlorian Fainelli 	if (dev->reset_gpio >= 0) {
2641967dd82fSFlorian Fainelli 		ret = devm_gpio_request_one(dev->dev, dev->reset_gpio,
2642967dd82fSFlorian Fainelli 					    GPIOF_OUT_INIT_HIGH, "robo_reset");
2643967dd82fSFlorian Fainelli 		if (ret)
2644967dd82fSFlorian Fainelli 			return ret;
2645967dd82fSFlorian Fainelli 	}
2646967dd82fSFlorian Fainelli 
2647967dd82fSFlorian Fainelli 	return 0;
2648967dd82fSFlorian Fainelli }
2649967dd82fSFlorian Fainelli 
26500dff88d3SJulia Lawall struct b53_device *b53_switch_alloc(struct device *base,
26510dff88d3SJulia Lawall 				    const struct b53_io_ops *ops,
2652967dd82fSFlorian Fainelli 				    void *priv)
2653967dd82fSFlorian Fainelli {
2654967dd82fSFlorian Fainelli 	struct dsa_switch *ds;
2655967dd82fSFlorian Fainelli 	struct b53_device *dev;
2656967dd82fSFlorian Fainelli 
26577e99e347SVivien Didelot 	ds = devm_kzalloc(base, sizeof(*ds), GFP_KERNEL);
2658967dd82fSFlorian Fainelli 	if (!ds)
2659967dd82fSFlorian Fainelli 		return NULL;
2660967dd82fSFlorian Fainelli 
26617e99e347SVivien Didelot 	ds->dev = base;
26627e99e347SVivien Didelot 	ds->num_ports = DSA_MAX_PORTS;
26637e99e347SVivien Didelot 
2664a0c02161SVivien Didelot 	dev = devm_kzalloc(base, sizeof(*dev), GFP_KERNEL);
2665a0c02161SVivien Didelot 	if (!dev)
2666a0c02161SVivien Didelot 		return NULL;
2667967dd82fSFlorian Fainelli 
2668967dd82fSFlorian Fainelli 	ds->priv = dev;
2669967dd82fSFlorian Fainelli 	dev->dev = base;
2670967dd82fSFlorian Fainelli 
2671967dd82fSFlorian Fainelli 	dev->ds = ds;
2672967dd82fSFlorian Fainelli 	dev->priv = priv;
2673967dd82fSFlorian Fainelli 	dev->ops = ops;
2674485ebd61SFlorian Fainelli 	ds->ops = &b53_switch_ops;
26750ee2af4eSVladimir Oltean 	dev->vlan_enabled = true;
2676d45c36baSFlorian Fainelli 	/* Let DSA handle the case were multiple bridges span the same switch
2677d45c36baSFlorian Fainelli 	 * device and different VLAN awareness settings are requested, which
2678d45c36baSFlorian Fainelli 	 * would be breaking filtering semantics for any of the other bridge
2679d45c36baSFlorian Fainelli 	 * devices. (not hardware supported)
2680d45c36baSFlorian Fainelli 	 */
2681d45c36baSFlorian Fainelli 	ds->vlan_filtering_is_global = true;
2682d45c36baSFlorian Fainelli 
2683967dd82fSFlorian Fainelli 	mutex_init(&dev->reg_mutex);
2684967dd82fSFlorian Fainelli 	mutex_init(&dev->stats_mutex);
2685967dd82fSFlorian Fainelli 
2686967dd82fSFlorian Fainelli 	return dev;
2687967dd82fSFlorian Fainelli }
2688967dd82fSFlorian Fainelli EXPORT_SYMBOL(b53_switch_alloc);
2689967dd82fSFlorian Fainelli 
2690967dd82fSFlorian Fainelli int b53_switch_detect(struct b53_device *dev)
2691967dd82fSFlorian Fainelli {
2692967dd82fSFlorian Fainelli 	u32 id32;
2693967dd82fSFlorian Fainelli 	u16 tmp;
2694967dd82fSFlorian Fainelli 	u8 id8;
2695967dd82fSFlorian Fainelli 	int ret;
2696967dd82fSFlorian Fainelli 
2697967dd82fSFlorian Fainelli 	ret = b53_read8(dev, B53_MGMT_PAGE, B53_DEVICE_ID, &id8);
2698967dd82fSFlorian Fainelli 	if (ret)
2699967dd82fSFlorian Fainelli 		return ret;
2700967dd82fSFlorian Fainelli 
2701967dd82fSFlorian Fainelli 	switch (id8) {
2702967dd82fSFlorian Fainelli 	case 0:
2703967dd82fSFlorian Fainelli 		/* BCM5325 and BCM5365 do not have this register so reads
2704967dd82fSFlorian Fainelli 		 * return 0. But the read operation did succeed, so assume this
2705967dd82fSFlorian Fainelli 		 * is one of them.
2706967dd82fSFlorian Fainelli 		 *
2707967dd82fSFlorian Fainelli 		 * Next check if we can write to the 5325's VTA register; for
2708967dd82fSFlorian Fainelli 		 * 5365 it is read only.
2709967dd82fSFlorian Fainelli 		 */
2710967dd82fSFlorian Fainelli 		b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, 0xf);
2711967dd82fSFlorian Fainelli 		b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, &tmp);
2712967dd82fSFlorian Fainelli 
2713967dd82fSFlorian Fainelli 		if (tmp == 0xf)
2714967dd82fSFlorian Fainelli 			dev->chip_id = BCM5325_DEVICE_ID;
2715967dd82fSFlorian Fainelli 		else
2716967dd82fSFlorian Fainelli 			dev->chip_id = BCM5365_DEVICE_ID;
2717967dd82fSFlorian Fainelli 		break;
2718a95691bcSDamien Thébault 	case BCM5389_DEVICE_ID:
2719967dd82fSFlorian Fainelli 	case BCM5395_DEVICE_ID:
2720967dd82fSFlorian Fainelli 	case BCM5397_DEVICE_ID:
2721967dd82fSFlorian Fainelli 	case BCM5398_DEVICE_ID:
2722967dd82fSFlorian Fainelli 		dev->chip_id = id8;
2723967dd82fSFlorian Fainelli 		break;
2724967dd82fSFlorian Fainelli 	default:
2725967dd82fSFlorian Fainelli 		ret = b53_read32(dev, B53_MGMT_PAGE, B53_DEVICE_ID, &id32);
2726967dd82fSFlorian Fainelli 		if (ret)
2727967dd82fSFlorian Fainelli 			return ret;
2728967dd82fSFlorian Fainelli 
2729967dd82fSFlorian Fainelli 		switch (id32) {
2730967dd82fSFlorian Fainelli 		case BCM53115_DEVICE_ID:
2731967dd82fSFlorian Fainelli 		case BCM53125_DEVICE_ID:
2732967dd82fSFlorian Fainelli 		case BCM53128_DEVICE_ID:
2733967dd82fSFlorian Fainelli 		case BCM53010_DEVICE_ID:
2734967dd82fSFlorian Fainelli 		case BCM53011_DEVICE_ID:
2735967dd82fSFlorian Fainelli 		case BCM53012_DEVICE_ID:
2736967dd82fSFlorian Fainelli 		case BCM53018_DEVICE_ID:
2737967dd82fSFlorian Fainelli 		case BCM53019_DEVICE_ID:
2738967dd82fSFlorian Fainelli 			dev->chip_id = id32;
2739967dd82fSFlorian Fainelli 			break;
2740967dd82fSFlorian Fainelli 		default:
27413b33438cSPaul Barker 			dev_err(dev->dev,
27423b33438cSPaul Barker 				"unsupported switch detected (BCM53%02x/BCM%x)\n",
2743967dd82fSFlorian Fainelli 				id8, id32);
2744967dd82fSFlorian Fainelli 			return -ENODEV;
2745967dd82fSFlorian Fainelli 		}
2746967dd82fSFlorian Fainelli 	}
2747967dd82fSFlorian Fainelli 
2748967dd82fSFlorian Fainelli 	if (dev->chip_id == BCM5325_DEVICE_ID)
2749967dd82fSFlorian Fainelli 		return b53_read8(dev, B53_STAT_PAGE, B53_REV_ID_25,
2750967dd82fSFlorian Fainelli 				 &dev->core_rev);
2751967dd82fSFlorian Fainelli 	else
2752967dd82fSFlorian Fainelli 		return b53_read8(dev, B53_MGMT_PAGE, B53_REV_ID,
2753967dd82fSFlorian Fainelli 				 &dev->core_rev);
2754967dd82fSFlorian Fainelli }
2755967dd82fSFlorian Fainelli EXPORT_SYMBOL(b53_switch_detect);
2756967dd82fSFlorian Fainelli 
2757967dd82fSFlorian Fainelli int b53_switch_register(struct b53_device *dev)
2758967dd82fSFlorian Fainelli {
2759967dd82fSFlorian Fainelli 	int ret;
2760967dd82fSFlorian Fainelli 
2761967dd82fSFlorian Fainelli 	if (dev->pdata) {
2762967dd82fSFlorian Fainelli 		dev->chip_id = dev->pdata->chip_id;
2763967dd82fSFlorian Fainelli 		dev->enabled_ports = dev->pdata->enabled_ports;
2764967dd82fSFlorian Fainelli 	}
2765967dd82fSFlorian Fainelli 
2766967dd82fSFlorian Fainelli 	if (!dev->chip_id && b53_switch_detect(dev))
2767967dd82fSFlorian Fainelli 		return -EINVAL;
2768967dd82fSFlorian Fainelli 
2769967dd82fSFlorian Fainelli 	ret = b53_switch_init(dev);
2770967dd82fSFlorian Fainelli 	if (ret)
2771967dd82fSFlorian Fainelli 		return ret;
2772967dd82fSFlorian Fainelli 
27733b33438cSPaul Barker 	dev_info(dev->dev, "found switch: %s, rev %i\n",
27743b33438cSPaul Barker 		 dev->name, dev->core_rev);
2775967dd82fSFlorian Fainelli 
277623c9ee49SVivien Didelot 	return dsa_register_switch(dev->ds);
2777967dd82fSFlorian Fainelli }
2778967dd82fSFlorian Fainelli EXPORT_SYMBOL(b53_switch_register);
2779967dd82fSFlorian Fainelli 
2780967dd82fSFlorian Fainelli MODULE_AUTHOR("Jonas Gorski <jogo@openwrt.org>");
2781967dd82fSFlorian Fainelli MODULE_DESCRIPTION("B53 switch library");
2782967dd82fSFlorian Fainelli MODULE_LICENSE("Dual BSD/GPL");
2783