xref: /openbmc/linux/drivers/net/dsa/b53/b53_common.c (revision 53568438e381d680bc84f1fe1d3ed2ac8d7ae85c)
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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21967dd82fSFlorian Fainelli 
22967dd82fSFlorian Fainelli #include <linux/delay.h>
23967dd82fSFlorian Fainelli #include <linux/export.h>
24967dd82fSFlorian Fainelli #include <linux/gpio.h>
25967dd82fSFlorian Fainelli #include <linux/kernel.h>
26967dd82fSFlorian Fainelli #include <linux/module.h>
27967dd82fSFlorian Fainelli #include <linux/platform_data/b53.h>
28967dd82fSFlorian Fainelli #include <linux/phy.h>
295e004460SFlorian Fainelli #include <linux/phylink.h>
301da6df85SFlorian Fainelli #include <linux/etherdevice.h>
31ff39c2d6SFlorian Fainelli #include <linux/if_bridge.h>
32967dd82fSFlorian Fainelli #include <net/dsa.h>
33967dd82fSFlorian Fainelli 
34967dd82fSFlorian Fainelli #include "b53_regs.h"
35967dd82fSFlorian Fainelli #include "b53_priv.h"
36967dd82fSFlorian Fainelli 
37967dd82fSFlorian Fainelli struct b53_mib_desc {
38967dd82fSFlorian Fainelli 	u8 size;
39967dd82fSFlorian Fainelli 	u8 offset;
40967dd82fSFlorian Fainelli 	const char *name;
41967dd82fSFlorian Fainelli };
42967dd82fSFlorian Fainelli 
43967dd82fSFlorian Fainelli /* BCM5365 MIB counters */
44967dd82fSFlorian Fainelli static const struct b53_mib_desc b53_mibs_65[] = {
45967dd82fSFlorian Fainelli 	{ 8, 0x00, "TxOctets" },
46967dd82fSFlorian Fainelli 	{ 4, 0x08, "TxDropPkts" },
47967dd82fSFlorian Fainelli 	{ 4, 0x10, "TxBroadcastPkts" },
48967dd82fSFlorian Fainelli 	{ 4, 0x14, "TxMulticastPkts" },
49967dd82fSFlorian Fainelli 	{ 4, 0x18, "TxUnicastPkts" },
50967dd82fSFlorian Fainelli 	{ 4, 0x1c, "TxCollisions" },
51967dd82fSFlorian Fainelli 	{ 4, 0x20, "TxSingleCollision" },
52967dd82fSFlorian Fainelli 	{ 4, 0x24, "TxMultipleCollision" },
53967dd82fSFlorian Fainelli 	{ 4, 0x28, "TxDeferredTransmit" },
54967dd82fSFlorian Fainelli 	{ 4, 0x2c, "TxLateCollision" },
55967dd82fSFlorian Fainelli 	{ 4, 0x30, "TxExcessiveCollision" },
56967dd82fSFlorian Fainelli 	{ 4, 0x38, "TxPausePkts" },
57967dd82fSFlorian Fainelli 	{ 8, 0x44, "RxOctets" },
58967dd82fSFlorian Fainelli 	{ 4, 0x4c, "RxUndersizePkts" },
59967dd82fSFlorian Fainelli 	{ 4, 0x50, "RxPausePkts" },
60967dd82fSFlorian Fainelli 	{ 4, 0x54, "Pkts64Octets" },
61967dd82fSFlorian Fainelli 	{ 4, 0x58, "Pkts65to127Octets" },
62967dd82fSFlorian Fainelli 	{ 4, 0x5c, "Pkts128to255Octets" },
63967dd82fSFlorian Fainelli 	{ 4, 0x60, "Pkts256to511Octets" },
64967dd82fSFlorian Fainelli 	{ 4, 0x64, "Pkts512to1023Octets" },
65967dd82fSFlorian Fainelli 	{ 4, 0x68, "Pkts1024to1522Octets" },
66967dd82fSFlorian Fainelli 	{ 4, 0x6c, "RxOversizePkts" },
67967dd82fSFlorian Fainelli 	{ 4, 0x70, "RxJabbers" },
68967dd82fSFlorian Fainelli 	{ 4, 0x74, "RxAlignmentErrors" },
69967dd82fSFlorian Fainelli 	{ 4, 0x78, "RxFCSErrors" },
70967dd82fSFlorian Fainelli 	{ 8, 0x7c, "RxGoodOctets" },
71967dd82fSFlorian Fainelli 	{ 4, 0x84, "RxDropPkts" },
72967dd82fSFlorian Fainelli 	{ 4, 0x88, "RxUnicastPkts" },
73967dd82fSFlorian Fainelli 	{ 4, 0x8c, "RxMulticastPkts" },
74967dd82fSFlorian Fainelli 	{ 4, 0x90, "RxBroadcastPkts" },
75967dd82fSFlorian Fainelli 	{ 4, 0x94, "RxSAChanges" },
76967dd82fSFlorian Fainelli 	{ 4, 0x98, "RxFragments" },
77967dd82fSFlorian Fainelli };
78967dd82fSFlorian Fainelli 
79967dd82fSFlorian Fainelli #define B53_MIBS_65_SIZE	ARRAY_SIZE(b53_mibs_65)
80967dd82fSFlorian Fainelli 
81967dd82fSFlorian Fainelli /* BCM63xx MIB counters */
82967dd82fSFlorian Fainelli static const struct b53_mib_desc b53_mibs_63xx[] = {
83967dd82fSFlorian Fainelli 	{ 8, 0x00, "TxOctets" },
84967dd82fSFlorian Fainelli 	{ 4, 0x08, "TxDropPkts" },
85967dd82fSFlorian Fainelli 	{ 4, 0x0c, "TxQoSPkts" },
86967dd82fSFlorian Fainelli 	{ 4, 0x10, "TxBroadcastPkts" },
87967dd82fSFlorian Fainelli 	{ 4, 0x14, "TxMulticastPkts" },
88967dd82fSFlorian Fainelli 	{ 4, 0x18, "TxUnicastPkts" },
89967dd82fSFlorian Fainelli 	{ 4, 0x1c, "TxCollisions" },
90967dd82fSFlorian Fainelli 	{ 4, 0x20, "TxSingleCollision" },
91967dd82fSFlorian Fainelli 	{ 4, 0x24, "TxMultipleCollision" },
92967dd82fSFlorian Fainelli 	{ 4, 0x28, "TxDeferredTransmit" },
93967dd82fSFlorian Fainelli 	{ 4, 0x2c, "TxLateCollision" },
94967dd82fSFlorian Fainelli 	{ 4, 0x30, "TxExcessiveCollision" },
95967dd82fSFlorian Fainelli 	{ 4, 0x38, "TxPausePkts" },
96967dd82fSFlorian Fainelli 	{ 8, 0x3c, "TxQoSOctets" },
97967dd82fSFlorian Fainelli 	{ 8, 0x44, "RxOctets" },
98967dd82fSFlorian Fainelli 	{ 4, 0x4c, "RxUndersizePkts" },
99967dd82fSFlorian Fainelli 	{ 4, 0x50, "RxPausePkts" },
100967dd82fSFlorian Fainelli 	{ 4, 0x54, "Pkts64Octets" },
101967dd82fSFlorian Fainelli 	{ 4, 0x58, "Pkts65to127Octets" },
102967dd82fSFlorian Fainelli 	{ 4, 0x5c, "Pkts128to255Octets" },
103967dd82fSFlorian Fainelli 	{ 4, 0x60, "Pkts256to511Octets" },
104967dd82fSFlorian Fainelli 	{ 4, 0x64, "Pkts512to1023Octets" },
105967dd82fSFlorian Fainelli 	{ 4, 0x68, "Pkts1024to1522Octets" },
106967dd82fSFlorian Fainelli 	{ 4, 0x6c, "RxOversizePkts" },
107967dd82fSFlorian Fainelli 	{ 4, 0x70, "RxJabbers" },
108967dd82fSFlorian Fainelli 	{ 4, 0x74, "RxAlignmentErrors" },
109967dd82fSFlorian Fainelli 	{ 4, 0x78, "RxFCSErrors" },
110967dd82fSFlorian Fainelli 	{ 8, 0x7c, "RxGoodOctets" },
111967dd82fSFlorian Fainelli 	{ 4, 0x84, "RxDropPkts" },
112967dd82fSFlorian Fainelli 	{ 4, 0x88, "RxUnicastPkts" },
113967dd82fSFlorian Fainelli 	{ 4, 0x8c, "RxMulticastPkts" },
114967dd82fSFlorian Fainelli 	{ 4, 0x90, "RxBroadcastPkts" },
115967dd82fSFlorian Fainelli 	{ 4, 0x94, "RxSAChanges" },
116967dd82fSFlorian Fainelli 	{ 4, 0x98, "RxFragments" },
117967dd82fSFlorian Fainelli 	{ 4, 0xa0, "RxSymbolErrors" },
118967dd82fSFlorian Fainelli 	{ 4, 0xa4, "RxQoSPkts" },
119967dd82fSFlorian Fainelli 	{ 8, 0xa8, "RxQoSOctets" },
120967dd82fSFlorian Fainelli 	{ 4, 0xb0, "Pkts1523to2047Octets" },
121967dd82fSFlorian Fainelli 	{ 4, 0xb4, "Pkts2048to4095Octets" },
122967dd82fSFlorian Fainelli 	{ 4, 0xb8, "Pkts4096to8191Octets" },
123967dd82fSFlorian Fainelli 	{ 4, 0xbc, "Pkts8192to9728Octets" },
124967dd82fSFlorian Fainelli 	{ 4, 0xc0, "RxDiscarded" },
125967dd82fSFlorian Fainelli };
126967dd82fSFlorian Fainelli 
127967dd82fSFlorian Fainelli #define B53_MIBS_63XX_SIZE	ARRAY_SIZE(b53_mibs_63xx)
128967dd82fSFlorian Fainelli 
129967dd82fSFlorian Fainelli /* MIB counters */
130967dd82fSFlorian Fainelli static const struct b53_mib_desc b53_mibs[] = {
131967dd82fSFlorian Fainelli 	{ 8, 0x00, "TxOctets" },
132967dd82fSFlorian Fainelli 	{ 4, 0x08, "TxDropPkts" },
133967dd82fSFlorian Fainelli 	{ 4, 0x10, "TxBroadcastPkts" },
134967dd82fSFlorian Fainelli 	{ 4, 0x14, "TxMulticastPkts" },
135967dd82fSFlorian Fainelli 	{ 4, 0x18, "TxUnicastPkts" },
136967dd82fSFlorian Fainelli 	{ 4, 0x1c, "TxCollisions" },
137967dd82fSFlorian Fainelli 	{ 4, 0x20, "TxSingleCollision" },
138967dd82fSFlorian Fainelli 	{ 4, 0x24, "TxMultipleCollision" },
139967dd82fSFlorian Fainelli 	{ 4, 0x28, "TxDeferredTransmit" },
140967dd82fSFlorian Fainelli 	{ 4, 0x2c, "TxLateCollision" },
141967dd82fSFlorian Fainelli 	{ 4, 0x30, "TxExcessiveCollision" },
142967dd82fSFlorian Fainelli 	{ 4, 0x38, "TxPausePkts" },
143967dd82fSFlorian Fainelli 	{ 8, 0x50, "RxOctets" },
144967dd82fSFlorian Fainelli 	{ 4, 0x58, "RxUndersizePkts" },
145967dd82fSFlorian Fainelli 	{ 4, 0x5c, "RxPausePkts" },
146967dd82fSFlorian Fainelli 	{ 4, 0x60, "Pkts64Octets" },
147967dd82fSFlorian Fainelli 	{ 4, 0x64, "Pkts65to127Octets" },
148967dd82fSFlorian Fainelli 	{ 4, 0x68, "Pkts128to255Octets" },
149967dd82fSFlorian Fainelli 	{ 4, 0x6c, "Pkts256to511Octets" },
150967dd82fSFlorian Fainelli 	{ 4, 0x70, "Pkts512to1023Octets" },
151967dd82fSFlorian Fainelli 	{ 4, 0x74, "Pkts1024to1522Octets" },
152967dd82fSFlorian Fainelli 	{ 4, 0x78, "RxOversizePkts" },
153967dd82fSFlorian Fainelli 	{ 4, 0x7c, "RxJabbers" },
154967dd82fSFlorian Fainelli 	{ 4, 0x80, "RxAlignmentErrors" },
155967dd82fSFlorian Fainelli 	{ 4, 0x84, "RxFCSErrors" },
156967dd82fSFlorian Fainelli 	{ 8, 0x88, "RxGoodOctets" },
157967dd82fSFlorian Fainelli 	{ 4, 0x90, "RxDropPkts" },
158967dd82fSFlorian Fainelli 	{ 4, 0x94, "RxUnicastPkts" },
159967dd82fSFlorian Fainelli 	{ 4, 0x98, "RxMulticastPkts" },
160967dd82fSFlorian Fainelli 	{ 4, 0x9c, "RxBroadcastPkts" },
161967dd82fSFlorian Fainelli 	{ 4, 0xa0, "RxSAChanges" },
162967dd82fSFlorian Fainelli 	{ 4, 0xa4, "RxFragments" },
163967dd82fSFlorian Fainelli 	{ 4, 0xa8, "RxJumboPkts" },
164967dd82fSFlorian Fainelli 	{ 4, 0xac, "RxSymbolErrors" },
165967dd82fSFlorian Fainelli 	{ 4, 0xc0, "RxDiscarded" },
166967dd82fSFlorian Fainelli };
167967dd82fSFlorian Fainelli 
168967dd82fSFlorian Fainelli #define B53_MIBS_SIZE	ARRAY_SIZE(b53_mibs)
169967dd82fSFlorian Fainelli 
170bde5d132SFlorian Fainelli static const struct b53_mib_desc b53_mibs_58xx[] = {
171bde5d132SFlorian Fainelli 	{ 8, 0x00, "TxOctets" },
172bde5d132SFlorian Fainelli 	{ 4, 0x08, "TxDropPkts" },
173bde5d132SFlorian Fainelli 	{ 4, 0x0c, "TxQPKTQ0" },
174bde5d132SFlorian Fainelli 	{ 4, 0x10, "TxBroadcastPkts" },
175bde5d132SFlorian Fainelli 	{ 4, 0x14, "TxMulticastPkts" },
176bde5d132SFlorian Fainelli 	{ 4, 0x18, "TxUnicastPKts" },
177bde5d132SFlorian Fainelli 	{ 4, 0x1c, "TxCollisions" },
178bde5d132SFlorian Fainelli 	{ 4, 0x20, "TxSingleCollision" },
179bde5d132SFlorian Fainelli 	{ 4, 0x24, "TxMultipleCollision" },
180bde5d132SFlorian Fainelli 	{ 4, 0x28, "TxDeferredCollision" },
181bde5d132SFlorian Fainelli 	{ 4, 0x2c, "TxLateCollision" },
182bde5d132SFlorian Fainelli 	{ 4, 0x30, "TxExcessiveCollision" },
183bde5d132SFlorian Fainelli 	{ 4, 0x34, "TxFrameInDisc" },
184bde5d132SFlorian Fainelli 	{ 4, 0x38, "TxPausePkts" },
185bde5d132SFlorian Fainelli 	{ 4, 0x3c, "TxQPKTQ1" },
186bde5d132SFlorian Fainelli 	{ 4, 0x40, "TxQPKTQ2" },
187bde5d132SFlorian Fainelli 	{ 4, 0x44, "TxQPKTQ3" },
188bde5d132SFlorian Fainelli 	{ 4, 0x48, "TxQPKTQ4" },
189bde5d132SFlorian Fainelli 	{ 4, 0x4c, "TxQPKTQ5" },
190bde5d132SFlorian Fainelli 	{ 8, 0x50, "RxOctets" },
191bde5d132SFlorian Fainelli 	{ 4, 0x58, "RxUndersizePkts" },
192bde5d132SFlorian Fainelli 	{ 4, 0x5c, "RxPausePkts" },
193bde5d132SFlorian Fainelli 	{ 4, 0x60, "RxPkts64Octets" },
194bde5d132SFlorian Fainelli 	{ 4, 0x64, "RxPkts65to127Octets" },
195bde5d132SFlorian Fainelli 	{ 4, 0x68, "RxPkts128to255Octets" },
196bde5d132SFlorian Fainelli 	{ 4, 0x6c, "RxPkts256to511Octets" },
197bde5d132SFlorian Fainelli 	{ 4, 0x70, "RxPkts512to1023Octets" },
198bde5d132SFlorian Fainelli 	{ 4, 0x74, "RxPkts1024toMaxPktsOctets" },
199bde5d132SFlorian Fainelli 	{ 4, 0x78, "RxOversizePkts" },
200bde5d132SFlorian Fainelli 	{ 4, 0x7c, "RxJabbers" },
201bde5d132SFlorian Fainelli 	{ 4, 0x80, "RxAlignmentErrors" },
202bde5d132SFlorian Fainelli 	{ 4, 0x84, "RxFCSErrors" },
203bde5d132SFlorian Fainelli 	{ 8, 0x88, "RxGoodOctets" },
204bde5d132SFlorian Fainelli 	{ 4, 0x90, "RxDropPkts" },
205bde5d132SFlorian Fainelli 	{ 4, 0x94, "RxUnicastPkts" },
206bde5d132SFlorian Fainelli 	{ 4, 0x98, "RxMulticastPkts" },
207bde5d132SFlorian Fainelli 	{ 4, 0x9c, "RxBroadcastPkts" },
208bde5d132SFlorian Fainelli 	{ 4, 0xa0, "RxSAChanges" },
209bde5d132SFlorian Fainelli 	{ 4, 0xa4, "RxFragments" },
210bde5d132SFlorian Fainelli 	{ 4, 0xa8, "RxJumboPkt" },
211bde5d132SFlorian Fainelli 	{ 4, 0xac, "RxSymblErr" },
212bde5d132SFlorian Fainelli 	{ 4, 0xb0, "InRangeErrCount" },
213bde5d132SFlorian Fainelli 	{ 4, 0xb4, "OutRangeErrCount" },
214bde5d132SFlorian Fainelli 	{ 4, 0xb8, "EEELpiEvent" },
215bde5d132SFlorian Fainelli 	{ 4, 0xbc, "EEELpiDuration" },
216bde5d132SFlorian Fainelli 	{ 4, 0xc0, "RxDiscard" },
217bde5d132SFlorian Fainelli 	{ 4, 0xc8, "TxQPKTQ6" },
218bde5d132SFlorian Fainelli 	{ 4, 0xcc, "TxQPKTQ7" },
219bde5d132SFlorian Fainelli 	{ 4, 0xd0, "TxPkts64Octets" },
220bde5d132SFlorian Fainelli 	{ 4, 0xd4, "TxPkts65to127Octets" },
221bde5d132SFlorian Fainelli 	{ 4, 0xd8, "TxPkts128to255Octets" },
222bde5d132SFlorian Fainelli 	{ 4, 0xdc, "TxPkts256to511Ocets" },
223bde5d132SFlorian Fainelli 	{ 4, 0xe0, "TxPkts512to1023Ocets" },
224bde5d132SFlorian Fainelli 	{ 4, 0xe4, "TxPkts1024toMaxPktOcets" },
225bde5d132SFlorian Fainelli };
226bde5d132SFlorian Fainelli 
227bde5d132SFlorian Fainelli #define B53_MIBS_58XX_SIZE	ARRAY_SIZE(b53_mibs_58xx)
228bde5d132SFlorian Fainelli 
229967dd82fSFlorian Fainelli static int b53_do_vlan_op(struct b53_device *dev, u8 op)
230967dd82fSFlorian Fainelli {
231967dd82fSFlorian Fainelli 	unsigned int i;
232967dd82fSFlorian Fainelli 
233967dd82fSFlorian Fainelli 	b53_write8(dev, B53_ARLIO_PAGE, dev->vta_regs[0], VTA_START_CMD | op);
234967dd82fSFlorian Fainelli 
235967dd82fSFlorian Fainelli 	for (i = 0; i < 10; i++) {
236967dd82fSFlorian Fainelli 		u8 vta;
237967dd82fSFlorian Fainelli 
238967dd82fSFlorian Fainelli 		b53_read8(dev, B53_ARLIO_PAGE, dev->vta_regs[0], &vta);
239967dd82fSFlorian Fainelli 		if (!(vta & VTA_START_CMD))
240967dd82fSFlorian Fainelli 			return 0;
241967dd82fSFlorian Fainelli 
242967dd82fSFlorian Fainelli 		usleep_range(100, 200);
243967dd82fSFlorian Fainelli 	}
244967dd82fSFlorian Fainelli 
245967dd82fSFlorian Fainelli 	return -EIO;
246967dd82fSFlorian Fainelli }
247967dd82fSFlorian Fainelli 
248a2482d2cSFlorian Fainelli static void b53_set_vlan_entry(struct b53_device *dev, u16 vid,
249a2482d2cSFlorian Fainelli 			       struct b53_vlan *vlan)
250967dd82fSFlorian Fainelli {
251967dd82fSFlorian Fainelli 	if (is5325(dev)) {
252967dd82fSFlorian Fainelli 		u32 entry = 0;
253967dd82fSFlorian Fainelli 
254a2482d2cSFlorian Fainelli 		if (vlan->members) {
255a2482d2cSFlorian Fainelli 			entry = ((vlan->untag & VA_UNTAG_MASK_25) <<
256a2482d2cSFlorian Fainelli 				 VA_UNTAG_S_25) | vlan->members;
257967dd82fSFlorian Fainelli 			if (dev->core_rev >= 3)
258967dd82fSFlorian Fainelli 				entry |= VA_VALID_25_R4 | vid << VA_VID_HIGH_S;
259967dd82fSFlorian Fainelli 			else
260967dd82fSFlorian Fainelli 				entry |= VA_VALID_25;
261967dd82fSFlorian Fainelli 		}
262967dd82fSFlorian Fainelli 
263967dd82fSFlorian Fainelli 		b53_write32(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_25, entry);
264967dd82fSFlorian Fainelli 		b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, vid |
265967dd82fSFlorian Fainelli 			    VTA_RW_STATE_WR | VTA_RW_OP_EN);
266967dd82fSFlorian Fainelli 	} else if (is5365(dev)) {
267967dd82fSFlorian Fainelli 		u16 entry = 0;
268967dd82fSFlorian Fainelli 
269a2482d2cSFlorian Fainelli 		if (vlan->members)
270a2482d2cSFlorian Fainelli 			entry = ((vlan->untag & VA_UNTAG_MASK_65) <<
271a2482d2cSFlorian Fainelli 				 VA_UNTAG_S_65) | vlan->members | VA_VALID_65;
272967dd82fSFlorian Fainelli 
273967dd82fSFlorian Fainelli 		b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_65, entry);
274967dd82fSFlorian Fainelli 		b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_65, vid |
275967dd82fSFlorian Fainelli 			    VTA_RW_STATE_WR | VTA_RW_OP_EN);
276967dd82fSFlorian Fainelli 	} else {
277967dd82fSFlorian Fainelli 		b53_write16(dev, B53_ARLIO_PAGE, dev->vta_regs[1], vid);
278967dd82fSFlorian Fainelli 		b53_write32(dev, B53_ARLIO_PAGE, dev->vta_regs[2],
279a2482d2cSFlorian Fainelli 			    (vlan->untag << VTE_UNTAG_S) | vlan->members);
280967dd82fSFlorian Fainelli 
281967dd82fSFlorian Fainelli 		b53_do_vlan_op(dev, VTA_CMD_WRITE);
282967dd82fSFlorian Fainelli 	}
283a2482d2cSFlorian Fainelli 
284a2482d2cSFlorian Fainelli 	dev_dbg(dev->ds->dev, "VID: %d, members: 0x%04x, untag: 0x%04x\n",
285a2482d2cSFlorian Fainelli 		vid, vlan->members, vlan->untag);
286967dd82fSFlorian Fainelli }
287967dd82fSFlorian Fainelli 
288a2482d2cSFlorian Fainelli static void b53_get_vlan_entry(struct b53_device *dev, u16 vid,
289a2482d2cSFlorian Fainelli 			       struct b53_vlan *vlan)
290a2482d2cSFlorian Fainelli {
291a2482d2cSFlorian Fainelli 	if (is5325(dev)) {
292a2482d2cSFlorian Fainelli 		u32 entry = 0;
293a2482d2cSFlorian Fainelli 
294a2482d2cSFlorian Fainelli 		b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, vid |
295a2482d2cSFlorian Fainelli 			    VTA_RW_STATE_RD | VTA_RW_OP_EN);
296a2482d2cSFlorian Fainelli 		b53_read32(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_25, &entry);
297a2482d2cSFlorian Fainelli 
298a2482d2cSFlorian Fainelli 		if (dev->core_rev >= 3)
299a2482d2cSFlorian Fainelli 			vlan->valid = !!(entry & VA_VALID_25_R4);
300a2482d2cSFlorian Fainelli 		else
301a2482d2cSFlorian Fainelli 			vlan->valid = !!(entry & VA_VALID_25);
302a2482d2cSFlorian Fainelli 		vlan->members = entry & VA_MEMBER_MASK;
303a2482d2cSFlorian Fainelli 		vlan->untag = (entry >> VA_UNTAG_S_25) & VA_UNTAG_MASK_25;
304a2482d2cSFlorian Fainelli 
305a2482d2cSFlorian Fainelli 	} else if (is5365(dev)) {
306a2482d2cSFlorian Fainelli 		u16 entry = 0;
307a2482d2cSFlorian Fainelli 
308a2482d2cSFlorian Fainelli 		b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_65, vid |
309a2482d2cSFlorian Fainelli 			    VTA_RW_STATE_WR | VTA_RW_OP_EN);
310a2482d2cSFlorian Fainelli 		b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_65, &entry);
311a2482d2cSFlorian Fainelli 
312a2482d2cSFlorian Fainelli 		vlan->valid = !!(entry & VA_VALID_65);
313a2482d2cSFlorian Fainelli 		vlan->members = entry & VA_MEMBER_MASK;
314a2482d2cSFlorian Fainelli 		vlan->untag = (entry >> VA_UNTAG_S_65) & VA_UNTAG_MASK_65;
315a2482d2cSFlorian Fainelli 	} else {
316a2482d2cSFlorian Fainelli 		u32 entry = 0;
317a2482d2cSFlorian Fainelli 
318a2482d2cSFlorian Fainelli 		b53_write16(dev, B53_ARLIO_PAGE, dev->vta_regs[1], vid);
319a2482d2cSFlorian Fainelli 		b53_do_vlan_op(dev, VTA_CMD_READ);
320a2482d2cSFlorian Fainelli 		b53_read32(dev, B53_ARLIO_PAGE, dev->vta_regs[2], &entry);
321a2482d2cSFlorian Fainelli 		vlan->members = entry & VTE_MEMBERS;
322a2482d2cSFlorian Fainelli 		vlan->untag = (entry >> VTE_UNTAG_S) & VTE_MEMBERS;
323a2482d2cSFlorian Fainelli 		vlan->valid = true;
324a2482d2cSFlorian Fainelli 	}
325a2482d2cSFlorian Fainelli }
326a2482d2cSFlorian Fainelli 
327a2482d2cSFlorian Fainelli static void b53_set_forwarding(struct b53_device *dev, int enable)
328967dd82fSFlorian Fainelli {
329967dd82fSFlorian Fainelli 	u8 mgmt;
330967dd82fSFlorian Fainelli 
331967dd82fSFlorian Fainelli 	b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt);
332967dd82fSFlorian Fainelli 
333967dd82fSFlorian Fainelli 	if (enable)
334967dd82fSFlorian Fainelli 		mgmt |= SM_SW_FWD_EN;
335967dd82fSFlorian Fainelli 	else
336967dd82fSFlorian Fainelli 		mgmt &= ~SM_SW_FWD_EN;
337967dd82fSFlorian Fainelli 
338967dd82fSFlorian Fainelli 	b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt);
339a424f0deSFlorian Fainelli 
3407edc58d6SFlorian Fainelli 	/* Include IMP port in dumb forwarding mode
341a424f0deSFlorian Fainelli 	 */
342a424f0deSFlorian Fainelli 	b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_CTRL, &mgmt);
343a424f0deSFlorian Fainelli 	mgmt |= B53_MII_DUMB_FWDG_EN;
344a424f0deSFlorian Fainelli 	b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_CTRL, mgmt);
345*53568438SFlorian Fainelli 
346*53568438SFlorian Fainelli 	/* Look at B53_UC_FWD_EN and B53_MC_FWD_EN to decide whether
347*53568438SFlorian Fainelli 	 * frames should be flooded or not.
348*53568438SFlorian Fainelli 	 */
349*53568438SFlorian Fainelli 	b53_read8(dev, B53_CTRL_PAGE, B53_IP_MULTICAST_CTRL, &mgmt);
350*53568438SFlorian Fainelli 	mgmt |= B53_UC_FWD_EN | B53_MC_FWD_EN;
351*53568438SFlorian Fainelli 	b53_write8(dev, B53_CTRL_PAGE, B53_IP_MULTICAST_CTRL, mgmt);
352a424f0deSFlorian Fainelli }
353967dd82fSFlorian Fainelli 
354dad8d7c6SFlorian Fainelli static void b53_enable_vlan(struct b53_device *dev, bool enable,
355dad8d7c6SFlorian Fainelli 			    bool enable_filtering)
356967dd82fSFlorian Fainelli {
357967dd82fSFlorian Fainelli 	u8 mgmt, vc0, vc1, vc4 = 0, vc5;
358967dd82fSFlorian Fainelli 
359967dd82fSFlorian Fainelli 	b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt);
360967dd82fSFlorian Fainelli 	b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL0, &vc0);
361967dd82fSFlorian Fainelli 	b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL1, &vc1);
362967dd82fSFlorian Fainelli 
363967dd82fSFlorian Fainelli 	if (is5325(dev) || is5365(dev)) {
364967dd82fSFlorian Fainelli 		b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, &vc4);
365967dd82fSFlorian Fainelli 		b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_25, &vc5);
366967dd82fSFlorian Fainelli 	} else if (is63xx(dev)) {
367967dd82fSFlorian Fainelli 		b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_63XX, &vc4);
368967dd82fSFlorian Fainelli 		b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_63XX, &vc5);
369967dd82fSFlorian Fainelli 	} else {
370967dd82fSFlorian Fainelli 		b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4, &vc4);
371967dd82fSFlorian Fainelli 		b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5, &vc5);
372967dd82fSFlorian Fainelli 	}
373967dd82fSFlorian Fainelli 
374967dd82fSFlorian Fainelli 	mgmt &= ~SM_SW_FWD_MODE;
375967dd82fSFlorian Fainelli 
376967dd82fSFlorian Fainelli 	if (enable) {
377967dd82fSFlorian Fainelli 		vc0 |= VC0_VLAN_EN | VC0_VID_CHK_EN | VC0_VID_HASH_VID;
378967dd82fSFlorian Fainelli 		vc1 |= VC1_RX_MCST_UNTAG_EN | VC1_RX_MCST_FWD_EN;
379967dd82fSFlorian Fainelli 		vc4 &= ~VC4_ING_VID_CHECK_MASK;
380dad8d7c6SFlorian Fainelli 		if (enable_filtering) {
381967dd82fSFlorian Fainelli 			vc4 |= VC4_ING_VID_VIO_DROP << VC4_ING_VID_CHECK_S;
382967dd82fSFlorian Fainelli 			vc5 |= VC5_DROP_VTABLE_MISS;
383dad8d7c6SFlorian Fainelli 		} else {
384dad8d7c6SFlorian Fainelli 			vc4 |= VC4_ING_VID_VIO_FWD << VC4_ING_VID_CHECK_S;
385dad8d7c6SFlorian Fainelli 			vc5 &= ~VC5_DROP_VTABLE_MISS;
386dad8d7c6SFlorian Fainelli 		}
387967dd82fSFlorian Fainelli 
388967dd82fSFlorian Fainelli 		if (is5325(dev))
389967dd82fSFlorian Fainelli 			vc0 &= ~VC0_RESERVED_1;
390967dd82fSFlorian Fainelli 
391967dd82fSFlorian Fainelli 		if (is5325(dev) || is5365(dev))
392967dd82fSFlorian Fainelli 			vc1 |= VC1_RX_MCST_TAG_EN;
393967dd82fSFlorian Fainelli 
394967dd82fSFlorian Fainelli 	} else {
395967dd82fSFlorian Fainelli 		vc0 &= ~(VC0_VLAN_EN | VC0_VID_CHK_EN | VC0_VID_HASH_VID);
396967dd82fSFlorian Fainelli 		vc1 &= ~(VC1_RX_MCST_UNTAG_EN | VC1_RX_MCST_FWD_EN);
397967dd82fSFlorian Fainelli 		vc4 &= ~VC4_ING_VID_CHECK_MASK;
398967dd82fSFlorian Fainelli 		vc5 &= ~VC5_DROP_VTABLE_MISS;
399967dd82fSFlorian Fainelli 
400967dd82fSFlorian Fainelli 		if (is5325(dev) || is5365(dev))
401967dd82fSFlorian Fainelli 			vc4 |= VC4_ING_VID_VIO_FWD << VC4_ING_VID_CHECK_S;
402967dd82fSFlorian Fainelli 		else
403967dd82fSFlorian Fainelli 			vc4 |= VC4_ING_VID_VIO_TO_IMP << VC4_ING_VID_CHECK_S;
404967dd82fSFlorian Fainelli 
405967dd82fSFlorian Fainelli 		if (is5325(dev) || is5365(dev))
406967dd82fSFlorian Fainelli 			vc1 &= ~VC1_RX_MCST_TAG_EN;
407a2482d2cSFlorian Fainelli 	}
408967dd82fSFlorian Fainelli 
409967dd82fSFlorian Fainelli 	if (!is5325(dev) && !is5365(dev))
410967dd82fSFlorian Fainelli 		vc5 &= ~VC5_VID_FFF_EN;
411967dd82fSFlorian Fainelli 
412967dd82fSFlorian Fainelli 	b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL0, vc0);
413967dd82fSFlorian Fainelli 	b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL1, vc1);
414967dd82fSFlorian Fainelli 
415967dd82fSFlorian Fainelli 	if (is5325(dev) || is5365(dev)) {
416967dd82fSFlorian Fainelli 		/* enable the high 8 bit vid check on 5325 */
417967dd82fSFlorian Fainelli 		if (is5325(dev) && enable)
418967dd82fSFlorian Fainelli 			b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3,
419967dd82fSFlorian Fainelli 				   VC3_HIGH_8BIT_EN);
420967dd82fSFlorian Fainelli 		else
421967dd82fSFlorian Fainelli 			b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3, 0);
422967dd82fSFlorian Fainelli 
423967dd82fSFlorian Fainelli 		b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, vc4);
424967dd82fSFlorian Fainelli 		b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_25, vc5);
425967dd82fSFlorian Fainelli 	} else if (is63xx(dev)) {
426967dd82fSFlorian Fainelli 		b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3_63XX, 0);
427967dd82fSFlorian Fainelli 		b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_63XX, vc4);
428967dd82fSFlorian Fainelli 		b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_63XX, vc5);
429967dd82fSFlorian Fainelli 	} else {
430967dd82fSFlorian Fainelli 		b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3, 0);
431967dd82fSFlorian Fainelli 		b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4, vc4);
432967dd82fSFlorian Fainelli 		b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5, vc5);
433967dd82fSFlorian Fainelli 	}
434967dd82fSFlorian Fainelli 
435967dd82fSFlorian Fainelli 	b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt);
436dad8d7c6SFlorian Fainelli 
437dad8d7c6SFlorian Fainelli 	dev->vlan_enabled = enable;
438967dd82fSFlorian Fainelli }
439967dd82fSFlorian Fainelli 
440967dd82fSFlorian Fainelli static int b53_set_jumbo(struct b53_device *dev, bool enable, bool allow_10_100)
441967dd82fSFlorian Fainelli {
442967dd82fSFlorian Fainelli 	u32 port_mask = 0;
443967dd82fSFlorian Fainelli 	u16 max_size = JMS_MIN_SIZE;
444967dd82fSFlorian Fainelli 
445967dd82fSFlorian Fainelli 	if (is5325(dev) || is5365(dev))
446967dd82fSFlorian Fainelli 		return -EINVAL;
447967dd82fSFlorian Fainelli 
448967dd82fSFlorian Fainelli 	if (enable) {
449967dd82fSFlorian Fainelli 		port_mask = dev->enabled_ports;
450967dd82fSFlorian Fainelli 		max_size = JMS_MAX_SIZE;
451967dd82fSFlorian Fainelli 		if (allow_10_100)
452967dd82fSFlorian Fainelli 			port_mask |= JPM_10_100_JUMBO_EN;
453967dd82fSFlorian Fainelli 	}
454967dd82fSFlorian Fainelli 
455967dd82fSFlorian Fainelli 	b53_write32(dev, B53_JUMBO_PAGE, dev->jumbo_pm_reg, port_mask);
456967dd82fSFlorian Fainelli 	return b53_write16(dev, B53_JUMBO_PAGE, dev->jumbo_size_reg, max_size);
457967dd82fSFlorian Fainelli }
458967dd82fSFlorian Fainelli 
459ff39c2d6SFlorian Fainelli static int b53_flush_arl(struct b53_device *dev, u8 mask)
460967dd82fSFlorian Fainelli {
461967dd82fSFlorian Fainelli 	unsigned int i;
462967dd82fSFlorian Fainelli 
463967dd82fSFlorian Fainelli 	b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL,
464ff39c2d6SFlorian Fainelli 		   FAST_AGE_DONE | FAST_AGE_DYNAMIC | mask);
465967dd82fSFlorian Fainelli 
466967dd82fSFlorian Fainelli 	for (i = 0; i < 10; i++) {
467967dd82fSFlorian Fainelli 		u8 fast_age_ctrl;
468967dd82fSFlorian Fainelli 
469967dd82fSFlorian Fainelli 		b53_read8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL,
470967dd82fSFlorian Fainelli 			  &fast_age_ctrl);
471967dd82fSFlorian Fainelli 
472967dd82fSFlorian Fainelli 		if (!(fast_age_ctrl & FAST_AGE_DONE))
473967dd82fSFlorian Fainelli 			goto out;
474967dd82fSFlorian Fainelli 
475967dd82fSFlorian Fainelli 		msleep(1);
476967dd82fSFlorian Fainelli 	}
477967dd82fSFlorian Fainelli 
478967dd82fSFlorian Fainelli 	return -ETIMEDOUT;
479967dd82fSFlorian Fainelli out:
480967dd82fSFlorian Fainelli 	/* Only age dynamic entries (default behavior) */
481967dd82fSFlorian Fainelli 	b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL, FAST_AGE_DYNAMIC);
482967dd82fSFlorian Fainelli 	return 0;
483967dd82fSFlorian Fainelli }
484967dd82fSFlorian Fainelli 
485ff39c2d6SFlorian Fainelli static int b53_fast_age_port(struct b53_device *dev, int port)
486ff39c2d6SFlorian Fainelli {
487ff39c2d6SFlorian Fainelli 	b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_PORT_CTRL, port);
488ff39c2d6SFlorian Fainelli 
489ff39c2d6SFlorian Fainelli 	return b53_flush_arl(dev, FAST_AGE_PORT);
490ff39c2d6SFlorian Fainelli }
491ff39c2d6SFlorian Fainelli 
492a2482d2cSFlorian Fainelli static int b53_fast_age_vlan(struct b53_device *dev, u16 vid)
493a2482d2cSFlorian Fainelli {
494a2482d2cSFlorian Fainelli 	b53_write16(dev, B53_CTRL_PAGE, B53_FAST_AGE_VID_CTRL, vid);
495a2482d2cSFlorian Fainelli 
496a2482d2cSFlorian Fainelli 	return b53_flush_arl(dev, FAST_AGE_VLAN);
497a2482d2cSFlorian Fainelli }
498a2482d2cSFlorian Fainelli 
499aac02867SFlorian Fainelli void b53_imp_vlan_setup(struct dsa_switch *ds, int cpu_port)
500ff39c2d6SFlorian Fainelli {
50104bed143SVivien Didelot 	struct b53_device *dev = ds->priv;
502ff39c2d6SFlorian Fainelli 	unsigned int i;
503ff39c2d6SFlorian Fainelli 	u16 pvlan;
504ff39c2d6SFlorian Fainelli 
505ff39c2d6SFlorian Fainelli 	/* Enable the IMP port to be in the same VLAN as the other ports
506ff39c2d6SFlorian Fainelli 	 * on a per-port basis such that we only have Port i and IMP in
507ff39c2d6SFlorian Fainelli 	 * the same VLAN.
508ff39c2d6SFlorian Fainelli 	 */
509ff39c2d6SFlorian Fainelli 	b53_for_each_port(dev, i) {
510ff39c2d6SFlorian Fainelli 		b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), &pvlan);
511ff39c2d6SFlorian Fainelli 		pvlan |= BIT(cpu_port);
512ff39c2d6SFlorian Fainelli 		b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), pvlan);
513ff39c2d6SFlorian Fainelli 	}
514ff39c2d6SFlorian Fainelli }
515aac02867SFlorian Fainelli EXPORT_SYMBOL(b53_imp_vlan_setup);
516ff39c2d6SFlorian Fainelli 
517f86ad77fSFlorian Fainelli int b53_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy)
518967dd82fSFlorian Fainelli {
51904bed143SVivien Didelot 	struct b53_device *dev = ds->priv;
52074be4babSVivien Didelot 	unsigned int cpu_port;
5218ca7c160SFlorian Fainelli 	int ret = 0;
522ff39c2d6SFlorian Fainelli 	u16 pvlan;
523967dd82fSFlorian Fainelli 
52474be4babSVivien Didelot 	if (!dsa_is_user_port(ds, port))
52574be4babSVivien Didelot 		return 0;
52674be4babSVivien Didelot 
52774be4babSVivien Didelot 	cpu_port = ds->ports[port].cpu_dp->index;
52874be4babSVivien Didelot 
5298ca7c160SFlorian Fainelli 	if (dev->ops->irq_enable)
5308ca7c160SFlorian Fainelli 		ret = dev->ops->irq_enable(dev, port);
5318ca7c160SFlorian Fainelli 	if (ret)
5328ca7c160SFlorian Fainelli 		return ret;
5338ca7c160SFlorian Fainelli 
534967dd82fSFlorian Fainelli 	/* Clear the Rx and Tx disable bits and set to no spanning tree */
535967dd82fSFlorian Fainelli 	b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), 0);
536967dd82fSFlorian Fainelli 
537ff39c2d6SFlorian Fainelli 	/* Set this port, and only this one to be in the default VLAN,
538ff39c2d6SFlorian Fainelli 	 * if member of a bridge, restore its membership prior to
539ff39c2d6SFlorian Fainelli 	 * bringing down this port.
540ff39c2d6SFlorian Fainelli 	 */
541ff39c2d6SFlorian Fainelli 	b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan);
542ff39c2d6SFlorian Fainelli 	pvlan &= ~0x1ff;
543ff39c2d6SFlorian Fainelli 	pvlan |= BIT(port);
544ff39c2d6SFlorian Fainelli 	pvlan |= dev->ports[port].vlan_ctl_mask;
545ff39c2d6SFlorian Fainelli 	b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan);
546ff39c2d6SFlorian Fainelli 
547ff39c2d6SFlorian Fainelli 	b53_imp_vlan_setup(ds, cpu_port);
548ff39c2d6SFlorian Fainelli 
549f43a2dbeSFlorian Fainelli 	/* If EEE was enabled, restore it */
550f43a2dbeSFlorian Fainelli 	if (dev->ports[port].eee.eee_enabled)
551f43a2dbeSFlorian Fainelli 		b53_eee_enable_set(ds, port, true);
552f43a2dbeSFlorian Fainelli 
553967dd82fSFlorian Fainelli 	return 0;
554967dd82fSFlorian Fainelli }
555f86ad77fSFlorian Fainelli EXPORT_SYMBOL(b53_enable_port);
556967dd82fSFlorian Fainelli 
55775104db0SAndrew Lunn void b53_disable_port(struct dsa_switch *ds, int port)
558967dd82fSFlorian Fainelli {
55904bed143SVivien Didelot 	struct b53_device *dev = ds->priv;
560967dd82fSFlorian Fainelli 	u8 reg;
561967dd82fSFlorian Fainelli 
562967dd82fSFlorian Fainelli 	/* Disable Tx/Rx for the port */
563967dd82fSFlorian Fainelli 	b53_read8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), &reg);
564967dd82fSFlorian Fainelli 	reg |= PORT_CTRL_RX_DISABLE | PORT_CTRL_TX_DISABLE;
565967dd82fSFlorian Fainelli 	b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), reg);
5668ca7c160SFlorian Fainelli 
5678ca7c160SFlorian Fainelli 	if (dev->ops->irq_disable)
5688ca7c160SFlorian Fainelli 		dev->ops->irq_disable(dev, port);
569967dd82fSFlorian Fainelli }
570f86ad77fSFlorian Fainelli EXPORT_SYMBOL(b53_disable_port);
571967dd82fSFlorian Fainelli 
572b409a9efSFlorian Fainelli void b53_brcm_hdr_setup(struct dsa_switch *ds, int port)
573b409a9efSFlorian Fainelli {
57411606039SFlorian Fainelli 	bool tag_en = !(ds->ops->get_tag_protocol(ds, port) ==
57511606039SFlorian Fainelli 			 DSA_TAG_PROTO_NONE);
576b409a9efSFlorian Fainelli 	struct b53_device *dev = ds->priv;
577b409a9efSFlorian Fainelli 	u8 hdr_ctl, val;
578b409a9efSFlorian Fainelli 	u16 reg;
579b409a9efSFlorian Fainelli 
580b409a9efSFlorian Fainelli 	/* Resolve which bit controls the Broadcom tag */
581b409a9efSFlorian Fainelli 	switch (port) {
582b409a9efSFlorian Fainelli 	case 8:
583b409a9efSFlorian Fainelli 		val = BRCM_HDR_P8_EN;
584b409a9efSFlorian Fainelli 		break;
585b409a9efSFlorian Fainelli 	case 7:
586b409a9efSFlorian Fainelli 		val = BRCM_HDR_P7_EN;
587b409a9efSFlorian Fainelli 		break;
588b409a9efSFlorian Fainelli 	case 5:
589b409a9efSFlorian Fainelli 		val = BRCM_HDR_P5_EN;
590b409a9efSFlorian Fainelli 		break;
591b409a9efSFlorian Fainelli 	default:
592b409a9efSFlorian Fainelli 		val = 0;
593b409a9efSFlorian Fainelli 		break;
594b409a9efSFlorian Fainelli 	}
595b409a9efSFlorian Fainelli 
596b409a9efSFlorian Fainelli 	/* Enable Broadcom tags for IMP port */
597b409a9efSFlorian Fainelli 	b53_read8(dev, B53_MGMT_PAGE, B53_BRCM_HDR, &hdr_ctl);
598cdb583cfSFlorian Fainelli 	if (tag_en)
599b409a9efSFlorian Fainelli 		hdr_ctl |= val;
600cdb583cfSFlorian Fainelli 	else
601cdb583cfSFlorian Fainelli 		hdr_ctl &= ~val;
602b409a9efSFlorian Fainelli 	b53_write8(dev, B53_MGMT_PAGE, B53_BRCM_HDR, hdr_ctl);
603b409a9efSFlorian Fainelli 
604b409a9efSFlorian Fainelli 	/* Registers below are only accessible on newer devices */
605b409a9efSFlorian Fainelli 	if (!is58xx(dev))
606b409a9efSFlorian Fainelli 		return;
607b409a9efSFlorian Fainelli 
608b409a9efSFlorian Fainelli 	/* Enable reception Broadcom tag for CPU TX (switch RX) to
609b409a9efSFlorian Fainelli 	 * allow us to tag outgoing frames
610b409a9efSFlorian Fainelli 	 */
611b409a9efSFlorian Fainelli 	b53_read16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_RX_DIS, &reg);
612cdb583cfSFlorian Fainelli 	if (tag_en)
613b409a9efSFlorian Fainelli 		reg &= ~BIT(port);
614cdb583cfSFlorian Fainelli 	else
615cdb583cfSFlorian Fainelli 		reg |= BIT(port);
616b409a9efSFlorian Fainelli 	b53_write16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_RX_DIS, reg);
617b409a9efSFlorian Fainelli 
618b409a9efSFlorian Fainelli 	/* Enable transmission of Broadcom tags from the switch (CPU RX) to
619b409a9efSFlorian Fainelli 	 * allow delivering frames to the per-port net_devices
620b409a9efSFlorian Fainelli 	 */
621b409a9efSFlorian Fainelli 	b53_read16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_TX_DIS, &reg);
622cdb583cfSFlorian Fainelli 	if (tag_en)
623b409a9efSFlorian Fainelli 		reg &= ~BIT(port);
624cdb583cfSFlorian Fainelli 	else
625cdb583cfSFlorian Fainelli 		reg |= BIT(port);
626b409a9efSFlorian Fainelli 	b53_write16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_TX_DIS, reg);
627b409a9efSFlorian Fainelli }
628b409a9efSFlorian Fainelli EXPORT_SYMBOL(b53_brcm_hdr_setup);
629b409a9efSFlorian Fainelli 
630299752a7SFlorian Fainelli static void b53_enable_cpu_port(struct b53_device *dev, int port)
631967dd82fSFlorian Fainelli {
632967dd82fSFlorian Fainelli 	u8 port_ctrl;
633967dd82fSFlorian Fainelli 
634967dd82fSFlorian Fainelli 	/* BCM5325 CPU port is at 8 */
635299752a7SFlorian Fainelli 	if ((is5325(dev) || is5365(dev)) && port == B53_CPU_PORT_25)
636299752a7SFlorian Fainelli 		port = B53_CPU_PORT;
637967dd82fSFlorian Fainelli 
638967dd82fSFlorian Fainelli 	port_ctrl = PORT_CTRL_RX_BCST_EN |
639967dd82fSFlorian Fainelli 		    PORT_CTRL_RX_MCST_EN |
640967dd82fSFlorian Fainelli 		    PORT_CTRL_RX_UCST_EN;
641299752a7SFlorian Fainelli 	b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), port_ctrl);
6427edc58d6SFlorian Fainelli 
6437edc58d6SFlorian Fainelli 	b53_brcm_hdr_setup(dev->ds, port);
644967dd82fSFlorian Fainelli }
645967dd82fSFlorian Fainelli 
646967dd82fSFlorian Fainelli static void b53_enable_mib(struct b53_device *dev)
647967dd82fSFlorian Fainelli {
648967dd82fSFlorian Fainelli 	u8 gc;
649967dd82fSFlorian Fainelli 
650967dd82fSFlorian Fainelli 	b53_read8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &gc);
651967dd82fSFlorian Fainelli 	gc &= ~(GC_RESET_MIB | GC_MIB_AC_EN);
652967dd82fSFlorian Fainelli 	b53_write8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc);
653967dd82fSFlorian Fainelli }
654967dd82fSFlorian Fainelli 
655fea83353SFlorian Fainelli static u16 b53_default_pvid(struct b53_device *dev)
656fea83353SFlorian Fainelli {
657fea83353SFlorian Fainelli 	if (is5325(dev) || is5365(dev))
658fea83353SFlorian Fainelli 		return 1;
659fea83353SFlorian Fainelli 	else
660fea83353SFlorian Fainelli 		return 0;
661fea83353SFlorian Fainelli }
662fea83353SFlorian Fainelli 
6635c1a6eafSFlorian Fainelli int b53_configure_vlan(struct dsa_switch *ds)
664967dd82fSFlorian Fainelli {
6655c1a6eafSFlorian Fainelli 	struct b53_device *dev = ds->priv;
666a2482d2cSFlorian Fainelli 	struct b53_vlan vl = { 0 };
667fea83353SFlorian Fainelli 	int i, def_vid;
668fea83353SFlorian Fainelli 
669fea83353SFlorian Fainelli 	def_vid = b53_default_pvid(dev);
670967dd82fSFlorian Fainelli 
671967dd82fSFlorian Fainelli 	/* clear all vlan entries */
672967dd82fSFlorian Fainelli 	if (is5325(dev) || is5365(dev)) {
673fea83353SFlorian Fainelli 		for (i = def_vid; i < dev->num_vlans; i++)
674a2482d2cSFlorian Fainelli 			b53_set_vlan_entry(dev, i, &vl);
675967dd82fSFlorian Fainelli 	} else {
676967dd82fSFlorian Fainelli 		b53_do_vlan_op(dev, VTA_CMD_CLEAR);
677967dd82fSFlorian Fainelli 	}
678967dd82fSFlorian Fainelli 
679e74f014eSVladimir Oltean 	b53_enable_vlan(dev, false, ds->vlan_filtering);
680967dd82fSFlorian Fainelli 
681967dd82fSFlorian Fainelli 	b53_for_each_port(dev, i)
682967dd82fSFlorian Fainelli 		b53_write16(dev, B53_VLAN_PAGE,
683fea83353SFlorian Fainelli 			    B53_VLAN_PORT_DEF_TAG(i), def_vid);
684967dd82fSFlorian Fainelli 
685967dd82fSFlorian Fainelli 	if (!is5325(dev) && !is5365(dev))
686967dd82fSFlorian Fainelli 		b53_set_jumbo(dev, dev->enable_jumbo, false);
687967dd82fSFlorian Fainelli 
688967dd82fSFlorian Fainelli 	return 0;
689967dd82fSFlorian Fainelli }
6905c1a6eafSFlorian Fainelli EXPORT_SYMBOL(b53_configure_vlan);
691967dd82fSFlorian Fainelli 
692967dd82fSFlorian Fainelli static void b53_switch_reset_gpio(struct b53_device *dev)
693967dd82fSFlorian Fainelli {
694967dd82fSFlorian Fainelli 	int gpio = dev->reset_gpio;
695967dd82fSFlorian Fainelli 
696967dd82fSFlorian Fainelli 	if (gpio < 0)
697967dd82fSFlorian Fainelli 		return;
698967dd82fSFlorian Fainelli 
699967dd82fSFlorian Fainelli 	/* Reset sequence: RESET low(50ms)->high(20ms)
700967dd82fSFlorian Fainelli 	 */
701967dd82fSFlorian Fainelli 	gpio_set_value(gpio, 0);
702967dd82fSFlorian Fainelli 	mdelay(50);
703967dd82fSFlorian Fainelli 
704967dd82fSFlorian Fainelli 	gpio_set_value(gpio, 1);
705967dd82fSFlorian Fainelli 	mdelay(20);
706967dd82fSFlorian Fainelli 
707967dd82fSFlorian Fainelli 	dev->current_page = 0xff;
708967dd82fSFlorian Fainelli }
709967dd82fSFlorian Fainelli 
710967dd82fSFlorian Fainelli static int b53_switch_reset(struct b53_device *dev)
711967dd82fSFlorian Fainelli {
7123fb22b05SFlorian Fainelli 	unsigned int timeout = 1000;
7133fb22b05SFlorian Fainelli 	u8 mgmt, reg;
714967dd82fSFlorian Fainelli 
715967dd82fSFlorian Fainelli 	b53_switch_reset_gpio(dev);
716967dd82fSFlorian Fainelli 
717967dd82fSFlorian Fainelli 	if (is539x(dev)) {
718967dd82fSFlorian Fainelli 		b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x83);
719967dd82fSFlorian Fainelli 		b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x00);
720967dd82fSFlorian Fainelli 	}
721967dd82fSFlorian Fainelli 
7223fb22b05SFlorian Fainelli 	/* This is specific to 58xx devices here, do not use is58xx() which
7233fb22b05SFlorian Fainelli 	 * covers the larger Starfigther 2 family, including 7445/7278 which
7243fb22b05SFlorian Fainelli 	 * still use this driver as a library and need to perform the reset
7253fb22b05SFlorian Fainelli 	 * earlier.
7263fb22b05SFlorian Fainelli 	 */
7275040cc99SArun Parameswaran 	if (dev->chip_id == BCM58XX_DEVICE_ID ||
7285040cc99SArun Parameswaran 	    dev->chip_id == BCM583XX_DEVICE_ID) {
7293fb22b05SFlorian Fainelli 		b53_read8(dev, B53_CTRL_PAGE, B53_SOFTRESET, &reg);
7303fb22b05SFlorian Fainelli 		reg |= SW_RST | EN_SW_RST | EN_CH_RST;
7313fb22b05SFlorian Fainelli 		b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, reg);
7323fb22b05SFlorian Fainelli 
7333fb22b05SFlorian Fainelli 		do {
7343fb22b05SFlorian Fainelli 			b53_read8(dev, B53_CTRL_PAGE, B53_SOFTRESET, &reg);
7353fb22b05SFlorian Fainelli 			if (!(reg & SW_RST))
7363fb22b05SFlorian Fainelli 				break;
7373fb22b05SFlorian Fainelli 
7383fb22b05SFlorian Fainelli 			usleep_range(1000, 2000);
7393fb22b05SFlorian Fainelli 		} while (timeout-- > 0);
7403fb22b05SFlorian Fainelli 
7413fb22b05SFlorian Fainelli 		if (timeout == 0)
7423fb22b05SFlorian Fainelli 			return -ETIMEDOUT;
7433fb22b05SFlorian Fainelli 	}
7443fb22b05SFlorian Fainelli 
745967dd82fSFlorian Fainelli 	b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt);
746967dd82fSFlorian Fainelli 
747967dd82fSFlorian Fainelli 	if (!(mgmt & SM_SW_FWD_EN)) {
748967dd82fSFlorian Fainelli 		mgmt &= ~SM_SW_FWD_MODE;
749967dd82fSFlorian Fainelli 		mgmt |= SM_SW_FWD_EN;
750967dd82fSFlorian Fainelli 
751967dd82fSFlorian Fainelli 		b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt);
752967dd82fSFlorian Fainelli 		b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt);
753967dd82fSFlorian Fainelli 
754967dd82fSFlorian Fainelli 		if (!(mgmt & SM_SW_FWD_EN)) {
755967dd82fSFlorian Fainelli 			dev_err(dev->dev, "Failed to enable switch!\n");
756967dd82fSFlorian Fainelli 			return -EINVAL;
757967dd82fSFlorian Fainelli 		}
758967dd82fSFlorian Fainelli 	}
759967dd82fSFlorian Fainelli 
760967dd82fSFlorian Fainelli 	b53_enable_mib(dev);
761967dd82fSFlorian Fainelli 
762ff39c2d6SFlorian Fainelli 	return b53_flush_arl(dev, FAST_AGE_STATIC);
763967dd82fSFlorian Fainelli }
764967dd82fSFlorian Fainelli 
765967dd82fSFlorian Fainelli static int b53_phy_read16(struct dsa_switch *ds, int addr, int reg)
766967dd82fSFlorian Fainelli {
76704bed143SVivien Didelot 	struct b53_device *priv = ds->priv;
768967dd82fSFlorian Fainelli 	u16 value = 0;
769967dd82fSFlorian Fainelli 	int ret;
770967dd82fSFlorian Fainelli 
771967dd82fSFlorian Fainelli 	if (priv->ops->phy_read16)
772967dd82fSFlorian Fainelli 		ret = priv->ops->phy_read16(priv, addr, reg, &value);
773967dd82fSFlorian Fainelli 	else
774967dd82fSFlorian Fainelli 		ret = b53_read16(priv, B53_PORT_MII_PAGE(addr),
775967dd82fSFlorian Fainelli 				 reg * 2, &value);
776967dd82fSFlorian Fainelli 
777967dd82fSFlorian Fainelli 	return ret ? ret : value;
778967dd82fSFlorian Fainelli }
779967dd82fSFlorian Fainelli 
780967dd82fSFlorian Fainelli static int b53_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val)
781967dd82fSFlorian Fainelli {
78204bed143SVivien Didelot 	struct b53_device *priv = ds->priv;
783967dd82fSFlorian Fainelli 
784967dd82fSFlorian Fainelli 	if (priv->ops->phy_write16)
785967dd82fSFlorian Fainelli 		return priv->ops->phy_write16(priv, addr, reg, val);
786967dd82fSFlorian Fainelli 
787967dd82fSFlorian Fainelli 	return b53_write16(priv, B53_PORT_MII_PAGE(addr), reg * 2, val);
788967dd82fSFlorian Fainelli }
789967dd82fSFlorian Fainelli 
790967dd82fSFlorian Fainelli static int b53_reset_switch(struct b53_device *priv)
791967dd82fSFlorian Fainelli {
792967dd82fSFlorian Fainelli 	/* reset vlans */
793967dd82fSFlorian Fainelli 	priv->enable_jumbo = false;
794967dd82fSFlorian Fainelli 
795a2482d2cSFlorian Fainelli 	memset(priv->vlans, 0, sizeof(*priv->vlans) * priv->num_vlans);
796967dd82fSFlorian Fainelli 	memset(priv->ports, 0, sizeof(*priv->ports) * priv->num_ports);
797967dd82fSFlorian Fainelli 
7980e01491dSFlorian Fainelli 	priv->serdes_lane = B53_INVALID_LANE;
7990e01491dSFlorian Fainelli 
800967dd82fSFlorian Fainelli 	return b53_switch_reset(priv);
801967dd82fSFlorian Fainelli }
802967dd82fSFlorian Fainelli 
803967dd82fSFlorian Fainelli static int b53_apply_config(struct b53_device *priv)
804967dd82fSFlorian Fainelli {
805967dd82fSFlorian Fainelli 	/* disable switching */
806967dd82fSFlorian Fainelli 	b53_set_forwarding(priv, 0);
807967dd82fSFlorian Fainelli 
8085c1a6eafSFlorian Fainelli 	b53_configure_vlan(priv->ds);
809967dd82fSFlorian Fainelli 
810967dd82fSFlorian Fainelli 	/* enable switching */
811967dd82fSFlorian Fainelli 	b53_set_forwarding(priv, 1);
812967dd82fSFlorian Fainelli 
813967dd82fSFlorian Fainelli 	return 0;
814967dd82fSFlorian Fainelli }
815967dd82fSFlorian Fainelli 
816967dd82fSFlorian Fainelli static void b53_reset_mib(struct b53_device *priv)
817967dd82fSFlorian Fainelli {
818967dd82fSFlorian Fainelli 	u8 gc;
819967dd82fSFlorian Fainelli 
820967dd82fSFlorian Fainelli 	b53_read8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &gc);
821967dd82fSFlorian Fainelli 
822967dd82fSFlorian Fainelli 	b53_write8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc | GC_RESET_MIB);
823967dd82fSFlorian Fainelli 	msleep(1);
824967dd82fSFlorian Fainelli 	b53_write8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc & ~GC_RESET_MIB);
825967dd82fSFlorian Fainelli 	msleep(1);
826967dd82fSFlorian Fainelli }
827967dd82fSFlorian Fainelli 
828967dd82fSFlorian Fainelli static const struct b53_mib_desc *b53_get_mib(struct b53_device *dev)
829967dd82fSFlorian Fainelli {
830967dd82fSFlorian Fainelli 	if (is5365(dev))
831967dd82fSFlorian Fainelli 		return b53_mibs_65;
832967dd82fSFlorian Fainelli 	else if (is63xx(dev))
833967dd82fSFlorian Fainelli 		return b53_mibs_63xx;
834bde5d132SFlorian Fainelli 	else if (is58xx(dev))
835bde5d132SFlorian Fainelli 		return b53_mibs_58xx;
836967dd82fSFlorian Fainelli 	else
837967dd82fSFlorian Fainelli 		return b53_mibs;
838967dd82fSFlorian Fainelli }
839967dd82fSFlorian Fainelli 
840967dd82fSFlorian Fainelli static unsigned int b53_get_mib_size(struct b53_device *dev)
841967dd82fSFlorian Fainelli {
842967dd82fSFlorian Fainelli 	if (is5365(dev))
843967dd82fSFlorian Fainelli 		return B53_MIBS_65_SIZE;
844967dd82fSFlorian Fainelli 	else if (is63xx(dev))
845967dd82fSFlorian Fainelli 		return B53_MIBS_63XX_SIZE;
846bde5d132SFlorian Fainelli 	else if (is58xx(dev))
847bde5d132SFlorian Fainelli 		return B53_MIBS_58XX_SIZE;
848967dd82fSFlorian Fainelli 	else
849967dd82fSFlorian Fainelli 		return B53_MIBS_SIZE;
850967dd82fSFlorian Fainelli }
851967dd82fSFlorian Fainelli 
852c7d28c9dSFlorian Fainelli static struct phy_device *b53_get_phy_device(struct dsa_switch *ds, int port)
853c7d28c9dSFlorian Fainelli {
854c7d28c9dSFlorian Fainelli 	/* These ports typically do not have built-in PHYs */
855c7d28c9dSFlorian Fainelli 	switch (port) {
856c7d28c9dSFlorian Fainelli 	case B53_CPU_PORT_25:
857c7d28c9dSFlorian Fainelli 	case 7:
858c7d28c9dSFlorian Fainelli 	case B53_CPU_PORT:
859c7d28c9dSFlorian Fainelli 		return NULL;
860c7d28c9dSFlorian Fainelli 	}
861c7d28c9dSFlorian Fainelli 
862c7d28c9dSFlorian Fainelli 	return mdiobus_get_phy(ds->slave_mii_bus, port);
863c7d28c9dSFlorian Fainelli }
864c7d28c9dSFlorian Fainelli 
86589f09048SFlorian Fainelli void b53_get_strings(struct dsa_switch *ds, int port, u32 stringset,
86689f09048SFlorian Fainelli 		     uint8_t *data)
867967dd82fSFlorian Fainelli {
86804bed143SVivien Didelot 	struct b53_device *dev = ds->priv;
869967dd82fSFlorian Fainelli 	const struct b53_mib_desc *mibs = b53_get_mib(dev);
870967dd82fSFlorian Fainelli 	unsigned int mib_size = b53_get_mib_size(dev);
871c7d28c9dSFlorian Fainelli 	struct phy_device *phydev;
872967dd82fSFlorian Fainelli 	unsigned int i;
873967dd82fSFlorian Fainelli 
874c7d28c9dSFlorian Fainelli 	if (stringset == ETH_SS_STATS) {
875967dd82fSFlorian Fainelli 		for (i = 0; i < mib_size; i++)
876cd526676SFlorian Fainelli 			strlcpy(data + i * ETH_GSTRING_LEN,
877967dd82fSFlorian Fainelli 				mibs[i].name, ETH_GSTRING_LEN);
878c7d28c9dSFlorian Fainelli 	} else if (stringset == ETH_SS_PHY_STATS) {
879c7d28c9dSFlorian Fainelli 		phydev = b53_get_phy_device(ds, port);
880c7d28c9dSFlorian Fainelli 		if (!phydev)
881c7d28c9dSFlorian Fainelli 			return;
882c7d28c9dSFlorian Fainelli 
883c7d28c9dSFlorian Fainelli 		phy_ethtool_get_strings(phydev, data);
884c7d28c9dSFlorian Fainelli 	}
885967dd82fSFlorian Fainelli }
8863117455dSFlorian Fainelli EXPORT_SYMBOL(b53_get_strings);
887967dd82fSFlorian Fainelli 
8883117455dSFlorian Fainelli void b53_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data)
889967dd82fSFlorian Fainelli {
89004bed143SVivien Didelot 	struct b53_device *dev = ds->priv;
891967dd82fSFlorian Fainelli 	const struct b53_mib_desc *mibs = b53_get_mib(dev);
892967dd82fSFlorian Fainelli 	unsigned int mib_size = b53_get_mib_size(dev);
893967dd82fSFlorian Fainelli 	const struct b53_mib_desc *s;
894967dd82fSFlorian Fainelli 	unsigned int i;
895967dd82fSFlorian Fainelli 	u64 val = 0;
896967dd82fSFlorian Fainelli 
897967dd82fSFlorian Fainelli 	if (is5365(dev) && port == 5)
898967dd82fSFlorian Fainelli 		port = 8;
899967dd82fSFlorian Fainelli 
900967dd82fSFlorian Fainelli 	mutex_lock(&dev->stats_mutex);
901967dd82fSFlorian Fainelli 
902967dd82fSFlorian Fainelli 	for (i = 0; i < mib_size; i++) {
903967dd82fSFlorian Fainelli 		s = &mibs[i];
904967dd82fSFlorian Fainelli 
90551dca8a1SFlorian Fainelli 		if (s->size == 8) {
906967dd82fSFlorian Fainelli 			b53_read64(dev, B53_MIB_PAGE(port), s->offset, &val);
907967dd82fSFlorian Fainelli 		} else {
908967dd82fSFlorian Fainelli 			u32 val32;
909967dd82fSFlorian Fainelli 
910967dd82fSFlorian Fainelli 			b53_read32(dev, B53_MIB_PAGE(port), s->offset,
911967dd82fSFlorian Fainelli 				   &val32);
912967dd82fSFlorian Fainelli 			val = val32;
913967dd82fSFlorian Fainelli 		}
914967dd82fSFlorian Fainelli 		data[i] = (u64)val;
915967dd82fSFlorian Fainelli 	}
916967dd82fSFlorian Fainelli 
917967dd82fSFlorian Fainelli 	mutex_unlock(&dev->stats_mutex);
918967dd82fSFlorian Fainelli }
9193117455dSFlorian Fainelli EXPORT_SYMBOL(b53_get_ethtool_stats);
920967dd82fSFlorian Fainelli 
921c7d28c9dSFlorian Fainelli void b53_get_ethtool_phy_stats(struct dsa_switch *ds, int port, uint64_t *data)
922c7d28c9dSFlorian Fainelli {
923c7d28c9dSFlorian Fainelli 	struct phy_device *phydev;
924c7d28c9dSFlorian Fainelli 
925c7d28c9dSFlorian Fainelli 	phydev = b53_get_phy_device(ds, port);
926c7d28c9dSFlorian Fainelli 	if (!phydev)
927c7d28c9dSFlorian Fainelli 		return;
928c7d28c9dSFlorian Fainelli 
929c7d28c9dSFlorian Fainelli 	phy_ethtool_get_stats(phydev, NULL, data);
930c7d28c9dSFlorian Fainelli }
931c7d28c9dSFlorian Fainelli EXPORT_SYMBOL(b53_get_ethtool_phy_stats);
932c7d28c9dSFlorian Fainelli 
93389f09048SFlorian Fainelli int b53_get_sset_count(struct dsa_switch *ds, int port, int sset)
934967dd82fSFlorian Fainelli {
93504bed143SVivien Didelot 	struct b53_device *dev = ds->priv;
936c7d28c9dSFlorian Fainelli 	struct phy_device *phydev;
937967dd82fSFlorian Fainelli 
938c7d28c9dSFlorian Fainelli 	if (sset == ETH_SS_STATS) {
939c7d28c9dSFlorian Fainelli 		return b53_get_mib_size(dev);
940c7d28c9dSFlorian Fainelli 	} else if (sset == ETH_SS_PHY_STATS) {
941c7d28c9dSFlorian Fainelli 		phydev = b53_get_phy_device(ds, port);
942c7d28c9dSFlorian Fainelli 		if (!phydev)
94389f09048SFlorian Fainelli 			return 0;
94489f09048SFlorian Fainelli 
945c7d28c9dSFlorian Fainelli 		return phy_ethtool_get_sset_count(phydev);
946c7d28c9dSFlorian Fainelli 	}
947c7d28c9dSFlorian Fainelli 
948c7d28c9dSFlorian Fainelli 	return 0;
949967dd82fSFlorian Fainelli }
9503117455dSFlorian Fainelli EXPORT_SYMBOL(b53_get_sset_count);
951967dd82fSFlorian Fainelli 
952967dd82fSFlorian Fainelli static int b53_setup(struct dsa_switch *ds)
953967dd82fSFlorian Fainelli {
95404bed143SVivien Didelot 	struct b53_device *dev = ds->priv;
955967dd82fSFlorian Fainelli 	unsigned int port;
956967dd82fSFlorian Fainelli 	int ret;
957967dd82fSFlorian Fainelli 
958967dd82fSFlorian Fainelli 	ret = b53_reset_switch(dev);
959967dd82fSFlorian Fainelli 	if (ret) {
960967dd82fSFlorian Fainelli 		dev_err(ds->dev, "failed to reset switch\n");
961967dd82fSFlorian Fainelli 		return ret;
962967dd82fSFlorian Fainelli 	}
963967dd82fSFlorian Fainelli 
964967dd82fSFlorian Fainelli 	b53_reset_mib(dev);
965967dd82fSFlorian Fainelli 
966967dd82fSFlorian Fainelli 	ret = b53_apply_config(dev);
967967dd82fSFlorian Fainelli 	if (ret)
968967dd82fSFlorian Fainelli 		dev_err(ds->dev, "failed to apply configuration\n");
969967dd82fSFlorian Fainelli 
97075dad252SBenedikt Spranger 	/* Configure IMP/CPU port, disable all other ports. Enabled
97134c8befdSFlorian Fainelli 	 * ports will be configured with .port_enable
97234c8befdSFlorian Fainelli 	 */
973967dd82fSFlorian Fainelli 	for (port = 0; port < dev->num_ports; port++) {
97434c8befdSFlorian Fainelli 		if (dsa_is_cpu_port(ds, port))
975299752a7SFlorian Fainelli 			b53_enable_cpu_port(dev, port);
97675dad252SBenedikt Spranger 		else
97775104db0SAndrew Lunn 			b53_disable_port(ds, port);
978967dd82fSFlorian Fainelli 	}
979967dd82fSFlorian Fainelli 
9807228b23eSVladimir Oltean 	/* Let DSA handle the case were multiple bridges span the same switch
9817228b23eSVladimir Oltean 	 * device and different VLAN awareness settings are requested, which
9827228b23eSVladimir Oltean 	 * would be breaking filtering semantics for any of the other bridge
9837228b23eSVladimir Oltean 	 * devices. (not hardware supported)
9847228b23eSVladimir Oltean 	 */
9857228b23eSVladimir Oltean 	ds->vlan_filtering_is_global = true;
9867228b23eSVladimir Oltean 
987967dd82fSFlorian Fainelli 	return ret;
988967dd82fSFlorian Fainelli }
989967dd82fSFlorian Fainelli 
9905e004460SFlorian Fainelli static void b53_force_link(struct b53_device *dev, int port, int link)
991967dd82fSFlorian Fainelli {
9925e004460SFlorian Fainelli 	u8 reg, val, off;
993967dd82fSFlorian Fainelli 
994967dd82fSFlorian Fainelli 	/* Override the port settings */
995967dd82fSFlorian Fainelli 	if (port == dev->cpu_port) {
996967dd82fSFlorian Fainelli 		off = B53_PORT_OVERRIDE_CTRL;
9975e004460SFlorian Fainelli 		val = PORT_OVERRIDE_EN;
998967dd82fSFlorian Fainelli 	} else {
999967dd82fSFlorian Fainelli 		off = B53_GMII_PORT_OVERRIDE_CTRL(port);
10005e004460SFlorian Fainelli 		val = GMII_PO_EN;
1001967dd82fSFlorian Fainelli 	}
1002967dd82fSFlorian Fainelli 
10035e004460SFlorian Fainelli 	b53_read8(dev, B53_CTRL_PAGE, off, &reg);
10045e004460SFlorian Fainelli 	reg |= val;
10055e004460SFlorian Fainelli 	if (link)
1006967dd82fSFlorian Fainelli 		reg |= PORT_OVERRIDE_LINK;
10075e004460SFlorian Fainelli 	else
10085e004460SFlorian Fainelli 		reg &= ~PORT_OVERRIDE_LINK;
10095e004460SFlorian Fainelli 	b53_write8(dev, B53_CTRL_PAGE, off, reg);
10105e004460SFlorian Fainelli }
1011967dd82fSFlorian Fainelli 
10125e004460SFlorian Fainelli static void b53_force_port_config(struct b53_device *dev, int port,
10135e004460SFlorian Fainelli 				  int speed, int duplex, int pause)
10145e004460SFlorian Fainelli {
10155e004460SFlorian Fainelli 	u8 reg, val, off;
10165e004460SFlorian Fainelli 
10175e004460SFlorian Fainelli 	/* Override the port settings */
10185e004460SFlorian Fainelli 	if (port == dev->cpu_port) {
10195e004460SFlorian Fainelli 		off = B53_PORT_OVERRIDE_CTRL;
10205e004460SFlorian Fainelli 		val = PORT_OVERRIDE_EN;
10215e004460SFlorian Fainelli 	} else {
10225e004460SFlorian Fainelli 		off = B53_GMII_PORT_OVERRIDE_CTRL(port);
10235e004460SFlorian Fainelli 		val = GMII_PO_EN;
10245e004460SFlorian Fainelli 	}
10255e004460SFlorian Fainelli 
10265e004460SFlorian Fainelli 	b53_read8(dev, B53_CTRL_PAGE, off, &reg);
10275e004460SFlorian Fainelli 	reg |= val;
10285e004460SFlorian Fainelli 	if (duplex == DUPLEX_FULL)
1029967dd82fSFlorian Fainelli 		reg |= PORT_OVERRIDE_FULL_DUPLEX;
10305e004460SFlorian Fainelli 	else
10315e004460SFlorian Fainelli 		reg &= ~PORT_OVERRIDE_FULL_DUPLEX;
1032967dd82fSFlorian Fainelli 
10335e004460SFlorian Fainelli 	switch (speed) {
1034967dd82fSFlorian Fainelli 	case 2000:
1035967dd82fSFlorian Fainelli 		reg |= PORT_OVERRIDE_SPEED_2000M;
1036967dd82fSFlorian Fainelli 		/* fallthrough */
1037967dd82fSFlorian Fainelli 	case SPEED_1000:
1038967dd82fSFlorian Fainelli 		reg |= PORT_OVERRIDE_SPEED_1000M;
1039967dd82fSFlorian Fainelli 		break;
1040967dd82fSFlorian Fainelli 	case SPEED_100:
1041967dd82fSFlorian Fainelli 		reg |= PORT_OVERRIDE_SPEED_100M;
1042967dd82fSFlorian Fainelli 		break;
1043967dd82fSFlorian Fainelli 	case SPEED_10:
1044967dd82fSFlorian Fainelli 		reg |= PORT_OVERRIDE_SPEED_10M;
1045967dd82fSFlorian Fainelli 		break;
1046967dd82fSFlorian Fainelli 	default:
10475e004460SFlorian Fainelli 		dev_err(dev->dev, "unknown speed: %d\n", speed);
1048967dd82fSFlorian Fainelli 		return;
1049967dd82fSFlorian Fainelli 	}
1050967dd82fSFlorian Fainelli 
10515e004460SFlorian Fainelli 	if (pause & MLO_PAUSE_RX)
10525e004460SFlorian Fainelli 		reg |= PORT_OVERRIDE_RX_FLOW;
10535e004460SFlorian Fainelli 	if (pause & MLO_PAUSE_TX)
10545e004460SFlorian Fainelli 		reg |= PORT_OVERRIDE_TX_FLOW;
10555e004460SFlorian Fainelli 
10565e004460SFlorian Fainelli 	b53_write8(dev, B53_CTRL_PAGE, off, reg);
10575e004460SFlorian Fainelli }
10585e004460SFlorian Fainelli 
10595e004460SFlorian Fainelli static void b53_adjust_link(struct dsa_switch *ds, int port,
10605e004460SFlorian Fainelli 			    struct phy_device *phydev)
10615e004460SFlorian Fainelli {
10625e004460SFlorian Fainelli 	struct b53_device *dev = ds->priv;
10635e004460SFlorian Fainelli 	struct ethtool_eee *p = &dev->ports[port].eee;
10645e004460SFlorian Fainelli 	u8 rgmii_ctrl = 0, reg = 0, off;
1065f973b768SDan Carpenter 	int pause = 0;
10665e004460SFlorian Fainelli 
10675e004460SFlorian Fainelli 	if (!phy_is_pseudo_fixed_link(phydev))
10685e004460SFlorian Fainelli 		return;
10695e004460SFlorian Fainelli 
1070967dd82fSFlorian Fainelli 	/* Enable flow control on BCM5301x's CPU port */
1071967dd82fSFlorian Fainelli 	if (is5301x(dev) && port == dev->cpu_port)
10725e004460SFlorian Fainelli 		pause = MLO_PAUSE_TXRX_MASK;
1073967dd82fSFlorian Fainelli 
1074967dd82fSFlorian Fainelli 	if (phydev->pause) {
1075967dd82fSFlorian Fainelli 		if (phydev->asym_pause)
10765e004460SFlorian Fainelli 			pause |= MLO_PAUSE_TX;
10775e004460SFlorian Fainelli 		pause |= MLO_PAUSE_RX;
1078967dd82fSFlorian Fainelli 	}
1079967dd82fSFlorian Fainelli 
10805e004460SFlorian Fainelli 	b53_force_port_config(dev, port, phydev->speed, phydev->duplex, pause);
10815e004460SFlorian Fainelli 	b53_force_link(dev, port, phydev->link);
1082967dd82fSFlorian Fainelli 
1083967dd82fSFlorian Fainelli 	if (is531x5(dev) && phy_interface_is_rgmii(phydev)) {
1084967dd82fSFlorian Fainelli 		if (port == 8)
1085967dd82fSFlorian Fainelli 			off = B53_RGMII_CTRL_IMP;
1086967dd82fSFlorian Fainelli 		else
1087967dd82fSFlorian Fainelli 			off = B53_RGMII_CTRL_P(port);
1088967dd82fSFlorian Fainelli 
1089967dd82fSFlorian Fainelli 		/* Configure the port RGMII clock delay by DLL disabled and
1090967dd82fSFlorian Fainelli 		 * tx_clk aligned timing (restoring to reset defaults)
1091967dd82fSFlorian Fainelli 		 */
1092967dd82fSFlorian Fainelli 		b53_read8(dev, B53_CTRL_PAGE, off, &rgmii_ctrl);
1093967dd82fSFlorian Fainelli 		rgmii_ctrl &= ~(RGMII_CTRL_DLL_RXC | RGMII_CTRL_DLL_TXC |
1094967dd82fSFlorian Fainelli 				RGMII_CTRL_TIMING_SEL);
1095967dd82fSFlorian Fainelli 
1096967dd82fSFlorian Fainelli 		/* PHY_INTERFACE_MODE_RGMII_TXID means TX internal delay, make
1097967dd82fSFlorian Fainelli 		 * sure that we enable the port TX clock internal delay to
1098967dd82fSFlorian Fainelli 		 * account for this internal delay that is inserted, otherwise
1099967dd82fSFlorian Fainelli 		 * the switch won't be able to receive correctly.
1100967dd82fSFlorian Fainelli 		 *
1101967dd82fSFlorian Fainelli 		 * PHY_INTERFACE_MODE_RGMII means that we are not introducing
1102967dd82fSFlorian Fainelli 		 * any delay neither on transmission nor reception, so the
1103967dd82fSFlorian Fainelli 		 * BCM53125 must also be configured accordingly to account for
1104967dd82fSFlorian Fainelli 		 * the lack of delay and introduce
1105967dd82fSFlorian Fainelli 		 *
1106967dd82fSFlorian Fainelli 		 * The BCM53125 switch has its RX clock and TX clock control
1107967dd82fSFlorian Fainelli 		 * swapped, hence the reason why we modify the TX clock path in
1108967dd82fSFlorian Fainelli 		 * the "RGMII" case
1109967dd82fSFlorian Fainelli 		 */
1110967dd82fSFlorian Fainelli 		if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
1111967dd82fSFlorian Fainelli 			rgmii_ctrl |= RGMII_CTRL_DLL_TXC;
1112967dd82fSFlorian Fainelli 		if (phydev->interface == PHY_INTERFACE_MODE_RGMII)
1113967dd82fSFlorian Fainelli 			rgmii_ctrl |= RGMII_CTRL_DLL_TXC | RGMII_CTRL_DLL_RXC;
1114967dd82fSFlorian Fainelli 		rgmii_ctrl |= RGMII_CTRL_TIMING_SEL;
1115967dd82fSFlorian Fainelli 		b53_write8(dev, B53_CTRL_PAGE, off, rgmii_ctrl);
1116967dd82fSFlorian Fainelli 
1117967dd82fSFlorian Fainelli 		dev_info(ds->dev, "Configured port %d for %s\n", port,
1118967dd82fSFlorian Fainelli 			 phy_modes(phydev->interface));
1119967dd82fSFlorian Fainelli 	}
1120967dd82fSFlorian Fainelli 
1121967dd82fSFlorian Fainelli 	/* configure MII port if necessary */
1122967dd82fSFlorian Fainelli 	if (is5325(dev)) {
1123967dd82fSFlorian Fainelli 		b53_read8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL,
1124967dd82fSFlorian Fainelli 			  &reg);
1125967dd82fSFlorian Fainelli 
1126967dd82fSFlorian Fainelli 		/* reverse mii needs to be enabled */
1127967dd82fSFlorian Fainelli 		if (!(reg & PORT_OVERRIDE_RV_MII_25)) {
1128967dd82fSFlorian Fainelli 			b53_write8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL,
1129967dd82fSFlorian Fainelli 				   reg | PORT_OVERRIDE_RV_MII_25);
1130967dd82fSFlorian Fainelli 			b53_read8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL,
1131967dd82fSFlorian Fainelli 				  &reg);
1132967dd82fSFlorian Fainelli 
1133967dd82fSFlorian Fainelli 			if (!(reg & PORT_OVERRIDE_RV_MII_25)) {
1134967dd82fSFlorian Fainelli 				dev_err(ds->dev,
1135967dd82fSFlorian Fainelli 					"Failed to enable reverse MII mode\n");
1136967dd82fSFlorian Fainelli 				return;
1137967dd82fSFlorian Fainelli 			}
1138967dd82fSFlorian Fainelli 		}
1139967dd82fSFlorian Fainelli 	} else if (is5301x(dev)) {
1140967dd82fSFlorian Fainelli 		if (port != dev->cpu_port) {
11415e004460SFlorian Fainelli 			b53_force_port_config(dev, dev->cpu_port, 2000,
11425e004460SFlorian Fainelli 					      DUPLEX_FULL, MLO_PAUSE_TXRX_MASK);
11435e004460SFlorian Fainelli 			b53_force_link(dev, dev->cpu_port, 1);
1144967dd82fSFlorian Fainelli 		}
1145967dd82fSFlorian Fainelli 	}
1146f43a2dbeSFlorian Fainelli 
1147f43a2dbeSFlorian Fainelli 	/* Re-negotiate EEE if it was enabled already */
1148f43a2dbeSFlorian Fainelli 	p->eee_enabled = b53_eee_init(ds, port, phydev);
1149967dd82fSFlorian Fainelli }
1150967dd82fSFlorian Fainelli 
1151a8e8b985SFlorian Fainelli void b53_port_event(struct dsa_switch *ds, int port)
1152a8e8b985SFlorian Fainelli {
1153a8e8b985SFlorian Fainelli 	struct b53_device *dev = ds->priv;
1154a8e8b985SFlorian Fainelli 	bool link;
1155a8e8b985SFlorian Fainelli 	u16 sts;
1156a8e8b985SFlorian Fainelli 
1157a8e8b985SFlorian Fainelli 	b53_read16(dev, B53_STAT_PAGE, B53_LINK_STAT, &sts);
1158a8e8b985SFlorian Fainelli 	link = !!(sts & BIT(port));
1159a8e8b985SFlorian Fainelli 	dsa_port_phylink_mac_change(ds, port, link);
1160a8e8b985SFlorian Fainelli }
1161a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_port_event);
1162a8e8b985SFlorian Fainelli 
1163a8e8b985SFlorian Fainelli void b53_phylink_validate(struct dsa_switch *ds, int port,
1164a8e8b985SFlorian Fainelli 			  unsigned long *supported,
1165a8e8b985SFlorian Fainelli 			  struct phylink_link_state *state)
1166a8e8b985SFlorian Fainelli {
1167a8e8b985SFlorian Fainelli 	struct b53_device *dev = ds->priv;
1168a8e8b985SFlorian Fainelli 	__ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
1169a8e8b985SFlorian Fainelli 
11700e01491dSFlorian Fainelli 	if (dev->ops->serdes_phylink_validate)
11710e01491dSFlorian Fainelli 		dev->ops->serdes_phylink_validate(dev, port, mask, state);
11720e01491dSFlorian Fainelli 
1173a8e8b985SFlorian Fainelli 	/* Allow all the expected bits */
1174a8e8b985SFlorian Fainelli 	phylink_set(mask, Autoneg);
1175a8e8b985SFlorian Fainelli 	phylink_set_port_modes(mask);
1176a8e8b985SFlorian Fainelli 	phylink_set(mask, Pause);
1177a8e8b985SFlorian Fainelli 	phylink_set(mask, Asym_Pause);
1178a8e8b985SFlorian Fainelli 
1179a8e8b985SFlorian Fainelli 	/* With the exclusion of 5325/5365, MII, Reverse MII and 802.3z, we
1180a8e8b985SFlorian Fainelli 	 * support Gigabit, including Half duplex.
1181a8e8b985SFlorian Fainelli 	 */
1182a8e8b985SFlorian Fainelli 	if (state->interface != PHY_INTERFACE_MODE_MII &&
1183a8e8b985SFlorian Fainelli 	    state->interface != PHY_INTERFACE_MODE_REVMII &&
1184a8e8b985SFlorian Fainelli 	    !phy_interface_mode_is_8023z(state->interface) &&
1185a8e8b985SFlorian Fainelli 	    !(is5325(dev) || is5365(dev))) {
1186a8e8b985SFlorian Fainelli 		phylink_set(mask, 1000baseT_Full);
1187a8e8b985SFlorian Fainelli 		phylink_set(mask, 1000baseT_Half);
1188a8e8b985SFlorian Fainelli 	}
1189a8e8b985SFlorian Fainelli 
1190a8e8b985SFlorian Fainelli 	if (!phy_interface_mode_is_8023z(state->interface)) {
1191a8e8b985SFlorian Fainelli 		phylink_set(mask, 10baseT_Half);
1192a8e8b985SFlorian Fainelli 		phylink_set(mask, 10baseT_Full);
1193a8e8b985SFlorian Fainelli 		phylink_set(mask, 100baseT_Half);
1194a8e8b985SFlorian Fainelli 		phylink_set(mask, 100baseT_Full);
1195a8e8b985SFlorian Fainelli 	}
1196a8e8b985SFlorian Fainelli 
1197a8e8b985SFlorian Fainelli 	bitmap_and(supported, supported, mask,
1198a8e8b985SFlorian Fainelli 		   __ETHTOOL_LINK_MODE_MASK_NBITS);
1199a8e8b985SFlorian Fainelli 	bitmap_and(state->advertising, state->advertising, mask,
1200a8e8b985SFlorian Fainelli 		   __ETHTOOL_LINK_MODE_MASK_NBITS);
1201a8e8b985SFlorian Fainelli 
1202a8e8b985SFlorian Fainelli 	phylink_helper_basex_speed(state);
1203a8e8b985SFlorian Fainelli }
1204a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_validate);
1205a8e8b985SFlorian Fainelli 
1206a8e8b985SFlorian Fainelli int b53_phylink_mac_link_state(struct dsa_switch *ds, int port,
1207a8e8b985SFlorian Fainelli 			       struct phylink_link_state *state)
1208a8e8b985SFlorian Fainelli {
12090e01491dSFlorian Fainelli 	struct b53_device *dev = ds->priv;
1210a8e8b985SFlorian Fainelli 	int ret = -EOPNOTSUPP;
1211a8e8b985SFlorian Fainelli 
121255a4d2eaSFlorian Fainelli 	if ((phy_interface_mode_is_8023z(state->interface) ||
121355a4d2eaSFlorian Fainelli 	     state->interface == PHY_INTERFACE_MODE_SGMII) &&
12140e01491dSFlorian Fainelli 	     dev->ops->serdes_link_state)
12150e01491dSFlorian Fainelli 		ret = dev->ops->serdes_link_state(dev, port, state);
12160e01491dSFlorian Fainelli 
1217a8e8b985SFlorian Fainelli 	return ret;
1218a8e8b985SFlorian Fainelli }
1219a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_link_state);
1220a8e8b985SFlorian Fainelli 
1221a8e8b985SFlorian Fainelli void b53_phylink_mac_config(struct dsa_switch *ds, int port,
1222a8e8b985SFlorian Fainelli 			    unsigned int mode,
1223a8e8b985SFlorian Fainelli 			    const struct phylink_link_state *state)
1224a8e8b985SFlorian Fainelli {
1225a8e8b985SFlorian Fainelli 	struct b53_device *dev = ds->priv;
1226a8e8b985SFlorian Fainelli 
1227a8e8b985SFlorian Fainelli 	if (mode == MLO_AN_PHY)
1228a8e8b985SFlorian Fainelli 		return;
1229a8e8b985SFlorian Fainelli 
1230a8e8b985SFlorian Fainelli 	if (mode == MLO_AN_FIXED) {
1231a8e8b985SFlorian Fainelli 		b53_force_port_config(dev, port, state->speed,
1232a8e8b985SFlorian Fainelli 				      state->duplex, state->pause);
1233a8e8b985SFlorian Fainelli 		return;
1234a8e8b985SFlorian Fainelli 	}
12350e01491dSFlorian Fainelli 
123655a4d2eaSFlorian Fainelli 	if ((phy_interface_mode_is_8023z(state->interface) ||
123755a4d2eaSFlorian Fainelli 	     state->interface == PHY_INTERFACE_MODE_SGMII) &&
12380e01491dSFlorian Fainelli 	     dev->ops->serdes_config)
12390e01491dSFlorian Fainelli 		dev->ops->serdes_config(dev, port, mode, state);
1240a8e8b985SFlorian Fainelli }
1241a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_config);
1242a8e8b985SFlorian Fainelli 
1243a8e8b985SFlorian Fainelli void b53_phylink_mac_an_restart(struct dsa_switch *ds, int port)
1244a8e8b985SFlorian Fainelli {
12450e01491dSFlorian Fainelli 	struct b53_device *dev = ds->priv;
12460e01491dSFlorian Fainelli 
12470e01491dSFlorian Fainelli 	if (dev->ops->serdes_an_restart)
12480e01491dSFlorian Fainelli 		dev->ops->serdes_an_restart(dev, port);
1249a8e8b985SFlorian Fainelli }
1250a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_an_restart);
1251a8e8b985SFlorian Fainelli 
1252a8e8b985SFlorian Fainelli void b53_phylink_mac_link_down(struct dsa_switch *ds, int port,
1253a8e8b985SFlorian Fainelli 			       unsigned int mode,
1254a8e8b985SFlorian Fainelli 			       phy_interface_t interface)
1255a8e8b985SFlorian Fainelli {
1256a8e8b985SFlorian Fainelli 	struct b53_device *dev = ds->priv;
1257a8e8b985SFlorian Fainelli 
1258a8e8b985SFlorian Fainelli 	if (mode == MLO_AN_PHY)
1259a8e8b985SFlorian Fainelli 		return;
1260a8e8b985SFlorian Fainelli 
1261a8e8b985SFlorian Fainelli 	if (mode == MLO_AN_FIXED) {
1262a8e8b985SFlorian Fainelli 		b53_force_link(dev, port, false);
1263a8e8b985SFlorian Fainelli 		return;
1264a8e8b985SFlorian Fainelli 	}
12650e01491dSFlorian Fainelli 
12660e01491dSFlorian Fainelli 	if (phy_interface_mode_is_8023z(interface) &&
12670e01491dSFlorian Fainelli 	    dev->ops->serdes_link_set)
12680e01491dSFlorian Fainelli 		dev->ops->serdes_link_set(dev, port, mode, interface, false);
1269a8e8b985SFlorian Fainelli }
1270a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_link_down);
1271a8e8b985SFlorian Fainelli 
1272a8e8b985SFlorian Fainelli void b53_phylink_mac_link_up(struct dsa_switch *ds, int port,
1273a8e8b985SFlorian Fainelli 			     unsigned int mode,
1274a8e8b985SFlorian Fainelli 			     phy_interface_t interface,
1275a8e8b985SFlorian Fainelli 			     struct phy_device *phydev)
1276a8e8b985SFlorian Fainelli {
1277a8e8b985SFlorian Fainelli 	struct b53_device *dev = ds->priv;
1278a8e8b985SFlorian Fainelli 
1279a8e8b985SFlorian Fainelli 	if (mode == MLO_AN_PHY)
1280a8e8b985SFlorian Fainelli 		return;
1281a8e8b985SFlorian Fainelli 
1282a8e8b985SFlorian Fainelli 	if (mode == MLO_AN_FIXED) {
1283a8e8b985SFlorian Fainelli 		b53_force_link(dev, port, true);
1284a8e8b985SFlorian Fainelli 		return;
1285a8e8b985SFlorian Fainelli 	}
12860e01491dSFlorian Fainelli 
12870e01491dSFlorian Fainelli 	if (phy_interface_mode_is_8023z(interface) &&
12880e01491dSFlorian Fainelli 	    dev->ops->serdes_link_set)
12890e01491dSFlorian Fainelli 		dev->ops->serdes_link_set(dev, port, mode, interface, true);
1290a8e8b985SFlorian Fainelli }
1291a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_link_up);
1292a8e8b985SFlorian Fainelli 
12933117455dSFlorian Fainelli int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering)
1294a2482d2cSFlorian Fainelli {
1295dad8d7c6SFlorian Fainelli 	struct b53_device *dev = ds->priv;
1296dad8d7c6SFlorian Fainelli 	u16 pvid, new_pvid;
1297dad8d7c6SFlorian Fainelli 
1298dad8d7c6SFlorian Fainelli 	b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &pvid);
1299dad8d7c6SFlorian Fainelli 	new_pvid = pvid;
1300864cd7b0SVladimir Oltean 	if (!vlan_filtering) {
1301dad8d7c6SFlorian Fainelli 		/* Filtering is currently enabled, use the default PVID since
1302dad8d7c6SFlorian Fainelli 		 * the bridge does not expect tagging anymore
1303dad8d7c6SFlorian Fainelli 		 */
1304dad8d7c6SFlorian Fainelli 		dev->ports[port].pvid = pvid;
1305dad8d7c6SFlorian Fainelli 		new_pvid = b53_default_pvid(dev);
1306864cd7b0SVladimir Oltean 	} else {
1307dad8d7c6SFlorian Fainelli 		/* Filtering is currently disabled, restore the previous PVID */
1308dad8d7c6SFlorian Fainelli 		new_pvid = dev->ports[port].pvid;
1309dad8d7c6SFlorian Fainelli 	}
1310dad8d7c6SFlorian Fainelli 
1311dad8d7c6SFlorian Fainelli 	if (pvid != new_pvid)
1312dad8d7c6SFlorian Fainelli 		b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port),
1313dad8d7c6SFlorian Fainelli 			    new_pvid);
1314dad8d7c6SFlorian Fainelli 
1315dad8d7c6SFlorian Fainelli 	b53_enable_vlan(dev, dev->vlan_enabled, vlan_filtering);
1316dad8d7c6SFlorian Fainelli 
1317a2482d2cSFlorian Fainelli 	return 0;
1318a2482d2cSFlorian Fainelli }
13193117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_filtering);
1320a2482d2cSFlorian Fainelli 
13213117455dSFlorian Fainelli int b53_vlan_prepare(struct dsa_switch *ds, int port,
132280e02360SVivien Didelot 		     const struct switchdev_obj_port_vlan *vlan)
1323a2482d2cSFlorian Fainelli {
132404bed143SVivien Didelot 	struct b53_device *dev = ds->priv;
1325a2482d2cSFlorian Fainelli 
1326a2482d2cSFlorian Fainelli 	if ((is5325(dev) || is5365(dev)) && vlan->vid_begin == 0)
1327a2482d2cSFlorian Fainelli 		return -EOPNOTSUPP;
1328a2482d2cSFlorian Fainelli 
1329a2482d2cSFlorian Fainelli 	if (vlan->vid_end > dev->num_vlans)
1330a2482d2cSFlorian Fainelli 		return -ERANGE;
1331a2482d2cSFlorian Fainelli 
1332e74f014eSVladimir Oltean 	b53_enable_vlan(dev, true, ds->vlan_filtering);
1333a2482d2cSFlorian Fainelli 
1334a2482d2cSFlorian Fainelli 	return 0;
1335a2482d2cSFlorian Fainelli }
13363117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_prepare);
1337a2482d2cSFlorian Fainelli 
13383117455dSFlorian Fainelli void b53_vlan_add(struct dsa_switch *ds, int port,
133980e02360SVivien Didelot 		  const struct switchdev_obj_port_vlan *vlan)
1340a2482d2cSFlorian Fainelli {
134104bed143SVivien Didelot 	struct b53_device *dev = ds->priv;
1342a2482d2cSFlorian Fainelli 	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1343a2482d2cSFlorian Fainelli 	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1344a2482d2cSFlorian Fainelli 	struct b53_vlan *vl;
1345a2482d2cSFlorian Fainelli 	u16 vid;
1346a2482d2cSFlorian Fainelli 
1347a2482d2cSFlorian Fainelli 	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1348a2482d2cSFlorian Fainelli 		vl = &dev->vlans[vid];
1349a2482d2cSFlorian Fainelli 
1350a2482d2cSFlorian Fainelli 		b53_get_vlan_entry(dev, vid, vl);
1351a2482d2cSFlorian Fainelli 
1352c499696eSFlorian Fainelli 		vl->members |= BIT(port);
1353ca893194SFlorian Fainelli 		if (untagged && !dsa_is_cpu_port(ds, port))
1354e47112d9SFlorian Fainelli 			vl->untag |= BIT(port);
1355a2482d2cSFlorian Fainelli 		else
1356e47112d9SFlorian Fainelli 			vl->untag &= ~BIT(port);
1357a2482d2cSFlorian Fainelli 
1358a2482d2cSFlorian Fainelli 		b53_set_vlan_entry(dev, vid, vl);
1359a2482d2cSFlorian Fainelli 		b53_fast_age_vlan(dev, vid);
1360a2482d2cSFlorian Fainelli 	}
1361a2482d2cSFlorian Fainelli 
136210163aaeSFlorian Fainelli 	if (pvid && !dsa_is_cpu_port(ds, port)) {
1363a2482d2cSFlorian Fainelli 		b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port),
1364a2482d2cSFlorian Fainelli 			    vlan->vid_end);
1365a2482d2cSFlorian Fainelli 		b53_fast_age_vlan(dev, vid);
1366a2482d2cSFlorian Fainelli 	}
1367a2482d2cSFlorian Fainelli }
13683117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_add);
1369a2482d2cSFlorian Fainelli 
13703117455dSFlorian Fainelli int b53_vlan_del(struct dsa_switch *ds, int port,
1371a2482d2cSFlorian Fainelli 		 const struct switchdev_obj_port_vlan *vlan)
1372a2482d2cSFlorian Fainelli {
137304bed143SVivien Didelot 	struct b53_device *dev = ds->priv;
1374a2482d2cSFlorian Fainelli 	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1375a2482d2cSFlorian Fainelli 	struct b53_vlan *vl;
1376a2482d2cSFlorian Fainelli 	u16 vid;
1377a2482d2cSFlorian Fainelli 	u16 pvid;
1378a2482d2cSFlorian Fainelli 
1379a2482d2cSFlorian Fainelli 	b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &pvid);
1380a2482d2cSFlorian Fainelli 
1381a2482d2cSFlorian Fainelli 	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1382a2482d2cSFlorian Fainelli 		vl = &dev->vlans[vid];
1383a2482d2cSFlorian Fainelli 
1384a2482d2cSFlorian Fainelli 		b53_get_vlan_entry(dev, vid, vl);
1385a2482d2cSFlorian Fainelli 
1386a2482d2cSFlorian Fainelli 		vl->members &= ~BIT(port);
1387a2482d2cSFlorian Fainelli 
1388fea83353SFlorian Fainelli 		if (pvid == vid)
1389fea83353SFlorian Fainelli 			pvid = b53_default_pvid(dev);
1390a2482d2cSFlorian Fainelli 
1391ca893194SFlorian Fainelli 		if (untagged && !dsa_is_cpu_port(ds, port))
1392a2482d2cSFlorian Fainelli 			vl->untag &= ~(BIT(port));
1393a2482d2cSFlorian Fainelli 
1394a2482d2cSFlorian Fainelli 		b53_set_vlan_entry(dev, vid, vl);
1395a2482d2cSFlorian Fainelli 		b53_fast_age_vlan(dev, vid);
1396a2482d2cSFlorian Fainelli 	}
1397a2482d2cSFlorian Fainelli 
1398a2482d2cSFlorian Fainelli 	b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), pvid);
1399a2482d2cSFlorian Fainelli 	b53_fast_age_vlan(dev, pvid);
1400a2482d2cSFlorian Fainelli 
1401a2482d2cSFlorian Fainelli 	return 0;
1402a2482d2cSFlorian Fainelli }
14033117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_del);
1404a2482d2cSFlorian Fainelli 
14051da6df85SFlorian Fainelli /* Address Resolution Logic routines */
14061da6df85SFlorian Fainelli static int b53_arl_op_wait(struct b53_device *dev)
14071da6df85SFlorian Fainelli {
14081da6df85SFlorian Fainelli 	unsigned int timeout = 10;
14091da6df85SFlorian Fainelli 	u8 reg;
14101da6df85SFlorian Fainelli 
14111da6df85SFlorian Fainelli 	do {
14121da6df85SFlorian Fainelli 		b53_read8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, &reg);
14131da6df85SFlorian Fainelli 		if (!(reg & ARLTBL_START_DONE))
14141da6df85SFlorian Fainelli 			return 0;
14151da6df85SFlorian Fainelli 
14161da6df85SFlorian Fainelli 		usleep_range(1000, 2000);
14171da6df85SFlorian Fainelli 	} while (timeout--);
14181da6df85SFlorian Fainelli 
14191da6df85SFlorian Fainelli 	dev_warn(dev->dev, "timeout waiting for ARL to finish: 0x%02x\n", reg);
14201da6df85SFlorian Fainelli 
14211da6df85SFlorian Fainelli 	return -ETIMEDOUT;
14221da6df85SFlorian Fainelli }
14231da6df85SFlorian Fainelli 
14241da6df85SFlorian Fainelli static int b53_arl_rw_op(struct b53_device *dev, unsigned int op)
14251da6df85SFlorian Fainelli {
14261da6df85SFlorian Fainelli 	u8 reg;
14271da6df85SFlorian Fainelli 
14281da6df85SFlorian Fainelli 	if (op > ARLTBL_RW)
14291da6df85SFlorian Fainelli 		return -EINVAL;
14301da6df85SFlorian Fainelli 
14311da6df85SFlorian Fainelli 	b53_read8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, &reg);
14321da6df85SFlorian Fainelli 	reg |= ARLTBL_START_DONE;
14331da6df85SFlorian Fainelli 	if (op)
14341da6df85SFlorian Fainelli 		reg |= ARLTBL_RW;
14351da6df85SFlorian Fainelli 	else
14361da6df85SFlorian Fainelli 		reg &= ~ARLTBL_RW;
14371da6df85SFlorian Fainelli 	b53_write8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, reg);
14381da6df85SFlorian Fainelli 
14391da6df85SFlorian Fainelli 	return b53_arl_op_wait(dev);
14401da6df85SFlorian Fainelli }
14411da6df85SFlorian Fainelli 
14421da6df85SFlorian Fainelli static int b53_arl_read(struct b53_device *dev, u64 mac,
14431da6df85SFlorian Fainelli 			u16 vid, struct b53_arl_entry *ent, u8 *idx,
14441da6df85SFlorian Fainelli 			bool is_valid)
14451da6df85SFlorian Fainelli {
14461da6df85SFlorian Fainelli 	unsigned int i;
14471da6df85SFlorian Fainelli 	int ret;
14481da6df85SFlorian Fainelli 
14491da6df85SFlorian Fainelli 	ret = b53_arl_op_wait(dev);
14501da6df85SFlorian Fainelli 	if (ret)
14511da6df85SFlorian Fainelli 		return ret;
14521da6df85SFlorian Fainelli 
14531da6df85SFlorian Fainelli 	/* Read the bins */
14541da6df85SFlorian Fainelli 	for (i = 0; i < dev->num_arl_entries; i++) {
14551da6df85SFlorian Fainelli 		u64 mac_vid;
14561da6df85SFlorian Fainelli 		u32 fwd_entry;
14571da6df85SFlorian Fainelli 
14581da6df85SFlorian Fainelli 		b53_read64(dev, B53_ARLIO_PAGE,
14591da6df85SFlorian Fainelli 			   B53_ARLTBL_MAC_VID_ENTRY(i), &mac_vid);
14601da6df85SFlorian Fainelli 		b53_read32(dev, B53_ARLIO_PAGE,
14611da6df85SFlorian Fainelli 			   B53_ARLTBL_DATA_ENTRY(i), &fwd_entry);
14621da6df85SFlorian Fainelli 		b53_arl_to_entry(ent, mac_vid, fwd_entry);
14631da6df85SFlorian Fainelli 
14641da6df85SFlorian Fainelli 		if (!(fwd_entry & ARLTBL_VALID))
14651da6df85SFlorian Fainelli 			continue;
14661da6df85SFlorian Fainelli 		if ((mac_vid & ARLTBL_MAC_MASK) != mac)
14671da6df85SFlorian Fainelli 			continue;
14681da6df85SFlorian Fainelli 		*idx = i;
14691da6df85SFlorian Fainelli 	}
14701da6df85SFlorian Fainelli 
14711da6df85SFlorian Fainelli 	return -ENOENT;
14721da6df85SFlorian Fainelli }
14731da6df85SFlorian Fainelli 
14741da6df85SFlorian Fainelli static int b53_arl_op(struct b53_device *dev, int op, int port,
14751da6df85SFlorian Fainelli 		      const unsigned char *addr, u16 vid, bool is_valid)
14761da6df85SFlorian Fainelli {
14771da6df85SFlorian Fainelli 	struct b53_arl_entry ent;
14781da6df85SFlorian Fainelli 	u32 fwd_entry;
14791da6df85SFlorian Fainelli 	u64 mac, mac_vid = 0;
14801da6df85SFlorian Fainelli 	u8 idx = 0;
14811da6df85SFlorian Fainelli 	int ret;
14821da6df85SFlorian Fainelli 
14831da6df85SFlorian Fainelli 	/* Convert the array into a 64-bit MAC */
14844b92ea81SFlorian Fainelli 	mac = ether_addr_to_u64(addr);
14851da6df85SFlorian Fainelli 
14861da6df85SFlorian Fainelli 	/* Perform a read for the given MAC and VID */
14871da6df85SFlorian Fainelli 	b53_write48(dev, B53_ARLIO_PAGE, B53_MAC_ADDR_IDX, mac);
14881da6df85SFlorian Fainelli 	b53_write16(dev, B53_ARLIO_PAGE, B53_VLAN_ID_IDX, vid);
14891da6df85SFlorian Fainelli 
14901da6df85SFlorian Fainelli 	/* Issue a read operation for this MAC */
14911da6df85SFlorian Fainelli 	ret = b53_arl_rw_op(dev, 1);
14921da6df85SFlorian Fainelli 	if (ret)
14931da6df85SFlorian Fainelli 		return ret;
14941da6df85SFlorian Fainelli 
14951da6df85SFlorian Fainelli 	ret = b53_arl_read(dev, mac, vid, &ent, &idx, is_valid);
14961da6df85SFlorian Fainelli 	/* If this is a read, just finish now */
14971da6df85SFlorian Fainelli 	if (op)
14981da6df85SFlorian Fainelli 		return ret;
14991da6df85SFlorian Fainelli 
15001da6df85SFlorian Fainelli 	/* We could not find a matching MAC, so reset to a new entry */
15011da6df85SFlorian Fainelli 	if (ret) {
15021da6df85SFlorian Fainelli 		fwd_entry = 0;
15031da6df85SFlorian Fainelli 		idx = 1;
15041da6df85SFlorian Fainelli 	}
15051da6df85SFlorian Fainelli 
15061da6df85SFlorian Fainelli 	memset(&ent, 0, sizeof(ent));
15071da6df85SFlorian Fainelli 	ent.port = port;
15081da6df85SFlorian Fainelli 	ent.is_valid = is_valid;
15091da6df85SFlorian Fainelli 	ent.vid = vid;
15101da6df85SFlorian Fainelli 	ent.is_static = true;
15111da6df85SFlorian Fainelli 	memcpy(ent.mac, addr, ETH_ALEN);
15121da6df85SFlorian Fainelli 	b53_arl_from_entry(&mac_vid, &fwd_entry, &ent);
15131da6df85SFlorian Fainelli 
15141da6df85SFlorian Fainelli 	b53_write64(dev, B53_ARLIO_PAGE,
15151da6df85SFlorian Fainelli 		    B53_ARLTBL_MAC_VID_ENTRY(idx), mac_vid);
15161da6df85SFlorian Fainelli 	b53_write32(dev, B53_ARLIO_PAGE,
15171da6df85SFlorian Fainelli 		    B53_ARLTBL_DATA_ENTRY(idx), fwd_entry);
15181da6df85SFlorian Fainelli 
15191da6df85SFlorian Fainelli 	return b53_arl_rw_op(dev, 0);
15201da6df85SFlorian Fainelli }
15211da6df85SFlorian Fainelli 
15221b6dd556SArkadi Sharshevsky int b53_fdb_add(struct dsa_switch *ds, int port,
15236c2c1dcbSArkadi Sharshevsky 		const unsigned char *addr, u16 vid)
15241da6df85SFlorian Fainelli {
152504bed143SVivien Didelot 	struct b53_device *priv = ds->priv;
15261da6df85SFlorian Fainelli 
15271da6df85SFlorian Fainelli 	/* 5325 and 5365 require some more massaging, but could
15281da6df85SFlorian Fainelli 	 * be supported eventually
15291da6df85SFlorian Fainelli 	 */
15301da6df85SFlorian Fainelli 	if (is5325(priv) || is5365(priv))
15311da6df85SFlorian Fainelli 		return -EOPNOTSUPP;
15321da6df85SFlorian Fainelli 
15331b6dd556SArkadi Sharshevsky 	return b53_arl_op(priv, 0, port, addr, vid, true);
15341da6df85SFlorian Fainelli }
15353117455dSFlorian Fainelli EXPORT_SYMBOL(b53_fdb_add);
15361da6df85SFlorian Fainelli 
15373117455dSFlorian Fainelli int b53_fdb_del(struct dsa_switch *ds, int port,
15386c2c1dcbSArkadi Sharshevsky 		const unsigned char *addr, u16 vid)
15391da6df85SFlorian Fainelli {
154004bed143SVivien Didelot 	struct b53_device *priv = ds->priv;
15411da6df85SFlorian Fainelli 
15426c2c1dcbSArkadi Sharshevsky 	return b53_arl_op(priv, 0, port, addr, vid, false);
15431da6df85SFlorian Fainelli }
15443117455dSFlorian Fainelli EXPORT_SYMBOL(b53_fdb_del);
15451da6df85SFlorian Fainelli 
15461da6df85SFlorian Fainelli static int b53_arl_search_wait(struct b53_device *dev)
15471da6df85SFlorian Fainelli {
15481da6df85SFlorian Fainelli 	unsigned int timeout = 1000;
15491da6df85SFlorian Fainelli 	u8 reg;
15501da6df85SFlorian Fainelli 
15511da6df85SFlorian Fainelli 	do {
15521da6df85SFlorian Fainelli 		b53_read8(dev, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, &reg);
15531da6df85SFlorian Fainelli 		if (!(reg & ARL_SRCH_STDN))
15541da6df85SFlorian Fainelli 			return 0;
15551da6df85SFlorian Fainelli 
15561da6df85SFlorian Fainelli 		if (reg & ARL_SRCH_VLID)
15571da6df85SFlorian Fainelli 			return 0;
15581da6df85SFlorian Fainelli 
15591da6df85SFlorian Fainelli 		usleep_range(1000, 2000);
15601da6df85SFlorian Fainelli 	} while (timeout--);
15611da6df85SFlorian Fainelli 
15621da6df85SFlorian Fainelli 	return -ETIMEDOUT;
15631da6df85SFlorian Fainelli }
15641da6df85SFlorian Fainelli 
15651da6df85SFlorian Fainelli static void b53_arl_search_rd(struct b53_device *dev, u8 idx,
15661da6df85SFlorian Fainelli 			      struct b53_arl_entry *ent)
15671da6df85SFlorian Fainelli {
15681da6df85SFlorian Fainelli 	u64 mac_vid;
15691da6df85SFlorian Fainelli 	u32 fwd_entry;
15701da6df85SFlorian Fainelli 
15711da6df85SFlorian Fainelli 	b53_read64(dev, B53_ARLIO_PAGE,
15721da6df85SFlorian Fainelli 		   B53_ARL_SRCH_RSTL_MACVID(idx), &mac_vid);
15731da6df85SFlorian Fainelli 	b53_read32(dev, B53_ARLIO_PAGE,
15741da6df85SFlorian Fainelli 		   B53_ARL_SRCH_RSTL(idx), &fwd_entry);
15751da6df85SFlorian Fainelli 	b53_arl_to_entry(ent, mac_vid, fwd_entry);
15761da6df85SFlorian Fainelli }
15771da6df85SFlorian Fainelli 
1578e6cbef0cSVivien Didelot static int b53_fdb_copy(int port, const struct b53_arl_entry *ent,
15792bedde1aSArkadi Sharshevsky 			dsa_fdb_dump_cb_t *cb, void *data)
15801da6df85SFlorian Fainelli {
15811da6df85SFlorian Fainelli 	if (!ent->is_valid)
15821da6df85SFlorian Fainelli 		return 0;
15831da6df85SFlorian Fainelli 
15841da6df85SFlorian Fainelli 	if (port != ent->port)
15851da6df85SFlorian Fainelli 		return 0;
15861da6df85SFlorian Fainelli 
15872bedde1aSArkadi Sharshevsky 	return cb(ent->mac, ent->vid, ent->is_static, data);
15881da6df85SFlorian Fainelli }
15891da6df85SFlorian Fainelli 
15903117455dSFlorian Fainelli int b53_fdb_dump(struct dsa_switch *ds, int port,
15912bedde1aSArkadi Sharshevsky 		 dsa_fdb_dump_cb_t *cb, void *data)
15921da6df85SFlorian Fainelli {
159304bed143SVivien Didelot 	struct b53_device *priv = ds->priv;
15941da6df85SFlorian Fainelli 	struct b53_arl_entry results[2];
15951da6df85SFlorian Fainelli 	unsigned int count = 0;
15961da6df85SFlorian Fainelli 	int ret;
15971da6df85SFlorian Fainelli 	u8 reg;
15981da6df85SFlorian Fainelli 
15991da6df85SFlorian Fainelli 	/* Start search operation */
16001da6df85SFlorian Fainelli 	reg = ARL_SRCH_STDN;
16011da6df85SFlorian Fainelli 	b53_write8(priv, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, reg);
16021da6df85SFlorian Fainelli 
16031da6df85SFlorian Fainelli 	do {
16041da6df85SFlorian Fainelli 		ret = b53_arl_search_wait(priv);
16051da6df85SFlorian Fainelli 		if (ret)
16061da6df85SFlorian Fainelli 			return ret;
16071da6df85SFlorian Fainelli 
16081da6df85SFlorian Fainelli 		b53_arl_search_rd(priv, 0, &results[0]);
16092bedde1aSArkadi Sharshevsky 		ret = b53_fdb_copy(port, &results[0], cb, data);
16101da6df85SFlorian Fainelli 		if (ret)
16111da6df85SFlorian Fainelli 			return ret;
16121da6df85SFlorian Fainelli 
16131da6df85SFlorian Fainelli 		if (priv->num_arl_entries > 2) {
16141da6df85SFlorian Fainelli 			b53_arl_search_rd(priv, 1, &results[1]);
16152bedde1aSArkadi Sharshevsky 			ret = b53_fdb_copy(port, &results[1], cb, data);
16161da6df85SFlorian Fainelli 			if (ret)
16171da6df85SFlorian Fainelli 				return ret;
16181da6df85SFlorian Fainelli 
16191da6df85SFlorian Fainelli 			if (!results[0].is_valid && !results[1].is_valid)
16201da6df85SFlorian Fainelli 				break;
16211da6df85SFlorian Fainelli 		}
16221da6df85SFlorian Fainelli 
16231da6df85SFlorian Fainelli 	} while (count++ < 1024);
16241da6df85SFlorian Fainelli 
16251da6df85SFlorian Fainelli 	return 0;
16261da6df85SFlorian Fainelli }
16273117455dSFlorian Fainelli EXPORT_SYMBOL(b53_fdb_dump);
16281da6df85SFlorian Fainelli 
1629ddd3a0c8SVivien Didelot int b53_br_join(struct dsa_switch *ds, int port, struct net_device *br)
1630ff39c2d6SFlorian Fainelli {
163104bed143SVivien Didelot 	struct b53_device *dev = ds->priv;
16320abfd494SVivien Didelot 	s8 cpu_port = ds->ports[port].cpu_dp->index;
1633ff39c2d6SFlorian Fainelli 	u16 pvlan, reg;
1634ff39c2d6SFlorian Fainelli 	unsigned int i;
1635ff39c2d6SFlorian Fainelli 
163648aea33aSFlorian Fainelli 	/* Make this port leave the all VLANs join since we will have proper
163748aea33aSFlorian Fainelli 	 * VLAN entries from now on
163848aea33aSFlorian Fainelli 	 */
163948aea33aSFlorian Fainelli 	if (is58xx(dev)) {
164048aea33aSFlorian Fainelli 		b53_read16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, &reg);
164148aea33aSFlorian Fainelli 		reg &= ~BIT(port);
164248aea33aSFlorian Fainelli 		if ((reg & BIT(cpu_port)) == BIT(cpu_port))
164348aea33aSFlorian Fainelli 			reg &= ~BIT(cpu_port);
164448aea33aSFlorian Fainelli 		b53_write16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, reg);
164548aea33aSFlorian Fainelli 	}
164648aea33aSFlorian Fainelli 
1647ff39c2d6SFlorian Fainelli 	b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan);
1648ff39c2d6SFlorian Fainelli 
1649ff39c2d6SFlorian Fainelli 	b53_for_each_port(dev, i) {
1650c8652c83SVivien Didelot 		if (dsa_to_port(ds, i)->bridge_dev != br)
1651ff39c2d6SFlorian Fainelli 			continue;
1652ff39c2d6SFlorian Fainelli 
1653ff39c2d6SFlorian Fainelli 		/* Add this local port to the remote port VLAN control
1654ff39c2d6SFlorian Fainelli 		 * membership and update the remote port bitmask
1655ff39c2d6SFlorian Fainelli 		 */
1656ff39c2d6SFlorian Fainelli 		b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), &reg);
1657ff39c2d6SFlorian Fainelli 		reg |= BIT(port);
1658ff39c2d6SFlorian Fainelli 		b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), reg);
1659ff39c2d6SFlorian Fainelli 		dev->ports[i].vlan_ctl_mask = reg;
1660ff39c2d6SFlorian Fainelli 
1661ff39c2d6SFlorian Fainelli 		pvlan |= BIT(i);
1662ff39c2d6SFlorian Fainelli 	}
1663ff39c2d6SFlorian Fainelli 
1664ff39c2d6SFlorian Fainelli 	/* Configure the local port VLAN control membership to include
1665ff39c2d6SFlorian Fainelli 	 * remote ports and update the local port bitmask
1666ff39c2d6SFlorian Fainelli 	 */
1667ff39c2d6SFlorian Fainelli 	b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan);
1668ff39c2d6SFlorian Fainelli 	dev->ports[port].vlan_ctl_mask = pvlan;
1669ff39c2d6SFlorian Fainelli 
1670ff39c2d6SFlorian Fainelli 	return 0;
1671ff39c2d6SFlorian Fainelli }
16723117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_join);
1673ff39c2d6SFlorian Fainelli 
1674f123f2fbSVivien Didelot void b53_br_leave(struct dsa_switch *ds, int port, struct net_device *br)
1675ff39c2d6SFlorian Fainelli {
167604bed143SVivien Didelot 	struct b53_device *dev = ds->priv;
1677a2482d2cSFlorian Fainelli 	struct b53_vlan *vl = &dev->vlans[0];
16780abfd494SVivien Didelot 	s8 cpu_port = ds->ports[port].cpu_dp->index;
1679ff39c2d6SFlorian Fainelli 	unsigned int i;
1680a2482d2cSFlorian Fainelli 	u16 pvlan, reg, pvid;
1681ff39c2d6SFlorian Fainelli 
1682ff39c2d6SFlorian Fainelli 	b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan);
1683ff39c2d6SFlorian Fainelli 
1684ff39c2d6SFlorian Fainelli 	b53_for_each_port(dev, i) {
1685ff39c2d6SFlorian Fainelli 		/* Don't touch the remaining ports */
1686c8652c83SVivien Didelot 		if (dsa_to_port(ds, i)->bridge_dev != br)
1687ff39c2d6SFlorian Fainelli 			continue;
1688ff39c2d6SFlorian Fainelli 
1689ff39c2d6SFlorian Fainelli 		b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), &reg);
1690ff39c2d6SFlorian Fainelli 		reg &= ~BIT(port);
1691ff39c2d6SFlorian Fainelli 		b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), reg);
1692ff39c2d6SFlorian Fainelli 		dev->ports[port].vlan_ctl_mask = reg;
1693ff39c2d6SFlorian Fainelli 
1694ff39c2d6SFlorian Fainelli 		/* Prevent self removal to preserve isolation */
1695ff39c2d6SFlorian Fainelli 		if (port != i)
1696ff39c2d6SFlorian Fainelli 			pvlan &= ~BIT(i);
1697ff39c2d6SFlorian Fainelli 	}
1698ff39c2d6SFlorian Fainelli 
1699ff39c2d6SFlorian Fainelli 	b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan);
1700ff39c2d6SFlorian Fainelli 	dev->ports[port].vlan_ctl_mask = pvlan;
1701a2482d2cSFlorian Fainelli 
1702fea83353SFlorian Fainelli 	pvid = b53_default_pvid(dev);
1703a2482d2cSFlorian Fainelli 
170448aea33aSFlorian Fainelli 	/* Make this port join all VLANs without VLAN entries */
170548aea33aSFlorian Fainelli 	if (is58xx(dev)) {
170648aea33aSFlorian Fainelli 		b53_read16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, &reg);
170748aea33aSFlorian Fainelli 		reg |= BIT(port);
170848aea33aSFlorian Fainelli 		if (!(reg & BIT(cpu_port)))
170948aea33aSFlorian Fainelli 			reg |= BIT(cpu_port);
171048aea33aSFlorian Fainelli 		b53_write16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, reg);
171148aea33aSFlorian Fainelli 	} else {
1712a2482d2cSFlorian Fainelli 		b53_get_vlan_entry(dev, pvid, vl);
1713c499696eSFlorian Fainelli 		vl->members |= BIT(port) | BIT(cpu_port);
1714c499696eSFlorian Fainelli 		vl->untag |= BIT(port) | BIT(cpu_port);
1715a2482d2cSFlorian Fainelli 		b53_set_vlan_entry(dev, pvid, vl);
1716ff39c2d6SFlorian Fainelli 	}
171748aea33aSFlorian Fainelli }
17183117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_leave);
1719ff39c2d6SFlorian Fainelli 
17203117455dSFlorian Fainelli void b53_br_set_stp_state(struct dsa_switch *ds, int port, u8 state)
1721ff39c2d6SFlorian Fainelli {
172204bed143SVivien Didelot 	struct b53_device *dev = ds->priv;
1723597698f1SVivien Didelot 	u8 hw_state;
1724ff39c2d6SFlorian Fainelli 	u8 reg;
1725ff39c2d6SFlorian Fainelli 
1726ff39c2d6SFlorian Fainelli 	switch (state) {
1727ff39c2d6SFlorian Fainelli 	case BR_STATE_DISABLED:
1728ff39c2d6SFlorian Fainelli 		hw_state = PORT_CTRL_DIS_STATE;
1729ff39c2d6SFlorian Fainelli 		break;
1730ff39c2d6SFlorian Fainelli 	case BR_STATE_LISTENING:
1731ff39c2d6SFlorian Fainelli 		hw_state = PORT_CTRL_LISTEN_STATE;
1732ff39c2d6SFlorian Fainelli 		break;
1733ff39c2d6SFlorian Fainelli 	case BR_STATE_LEARNING:
1734ff39c2d6SFlorian Fainelli 		hw_state = PORT_CTRL_LEARN_STATE;
1735ff39c2d6SFlorian Fainelli 		break;
1736ff39c2d6SFlorian Fainelli 	case BR_STATE_FORWARDING:
1737ff39c2d6SFlorian Fainelli 		hw_state = PORT_CTRL_FWD_STATE;
1738ff39c2d6SFlorian Fainelli 		break;
1739ff39c2d6SFlorian Fainelli 	case BR_STATE_BLOCKING:
1740ff39c2d6SFlorian Fainelli 		hw_state = PORT_CTRL_BLOCK_STATE;
1741ff39c2d6SFlorian Fainelli 		break;
1742ff39c2d6SFlorian Fainelli 	default:
1743ff39c2d6SFlorian Fainelli 		dev_err(ds->dev, "invalid STP state: %d\n", state);
1744ff39c2d6SFlorian Fainelli 		return;
1745ff39c2d6SFlorian Fainelli 	}
1746ff39c2d6SFlorian Fainelli 
1747ff39c2d6SFlorian Fainelli 	b53_read8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), &reg);
1748ff39c2d6SFlorian Fainelli 	reg &= ~PORT_CTRL_STP_STATE_MASK;
1749ff39c2d6SFlorian Fainelli 	reg |= hw_state;
1750ff39c2d6SFlorian Fainelli 	b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), reg);
1751ff39c2d6SFlorian Fainelli }
17523117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_set_stp_state);
1753ff39c2d6SFlorian Fainelli 
17543117455dSFlorian Fainelli void b53_br_fast_age(struct dsa_switch *ds, int port)
1755597698f1SVivien Didelot {
1756597698f1SVivien Didelot 	struct b53_device *dev = ds->priv;
1757597698f1SVivien Didelot 
1758597698f1SVivien Didelot 	if (b53_fast_age_port(dev, port))
1759597698f1SVivien Didelot 		dev_err(ds->dev, "fast ageing failed\n");
1760597698f1SVivien Didelot }
17613117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_fast_age);
1762597698f1SVivien Didelot 
1763*53568438SFlorian Fainelli int b53_br_egress_floods(struct dsa_switch *ds, int port,
1764*53568438SFlorian Fainelli 			 bool unicast, bool multicast)
1765*53568438SFlorian Fainelli {
1766*53568438SFlorian Fainelli 	struct b53_device *dev = ds->priv;
1767*53568438SFlorian Fainelli 	u16 uc, mc;
1768*53568438SFlorian Fainelli 
1769*53568438SFlorian Fainelli 	b53_read16(dev, B53_CTRL_PAGE, B53_UC_FWD_EN, &uc);
1770*53568438SFlorian Fainelli 	if (unicast)
1771*53568438SFlorian Fainelli 		uc |= BIT(port);
1772*53568438SFlorian Fainelli 	else
1773*53568438SFlorian Fainelli 		uc &= ~BIT(port);
1774*53568438SFlorian Fainelli 	b53_write16(dev, B53_CTRL_PAGE, B53_UC_FWD_EN, uc);
1775*53568438SFlorian Fainelli 
1776*53568438SFlorian Fainelli 	b53_read16(dev, B53_CTRL_PAGE, B53_MC_FWD_EN, &mc);
1777*53568438SFlorian Fainelli 	if (multicast)
1778*53568438SFlorian Fainelli 		mc |= BIT(port);
1779*53568438SFlorian Fainelli 	else
1780*53568438SFlorian Fainelli 		mc &= ~BIT(port);
1781*53568438SFlorian Fainelli 	b53_write16(dev, B53_CTRL_PAGE, B53_MC_FWD_EN, mc);
1782*53568438SFlorian Fainelli 
1783*53568438SFlorian Fainelli 	return 0;
1784*53568438SFlorian Fainelli 
1785*53568438SFlorian Fainelli }
1786*53568438SFlorian Fainelli EXPORT_SYMBOL(b53_br_egress_floods);
1787*53568438SFlorian Fainelli 
1788c7d28c9dSFlorian Fainelli static bool b53_possible_cpu_port(struct dsa_switch *ds, int port)
17897edc58d6SFlorian Fainelli {
17907edc58d6SFlorian Fainelli 	/* Broadcom switches will accept enabling Broadcom tags on the
17917edc58d6SFlorian Fainelli 	 * following ports: 5, 7 and 8, any other port is not supported
17927edc58d6SFlorian Fainelli 	 */
17935ed4e3ebSFlorian Fainelli 	switch (port) {
17945ed4e3ebSFlorian Fainelli 	case B53_CPU_PORT_25:
17955ed4e3ebSFlorian Fainelli 	case 7:
17965ed4e3ebSFlorian Fainelli 	case B53_CPU_PORT:
17977edc58d6SFlorian Fainelli 		return true;
17987edc58d6SFlorian Fainelli 	}
17997edc58d6SFlorian Fainelli 
18005ed4e3ebSFlorian Fainelli 	return false;
18015ed4e3ebSFlorian Fainelli }
18025ed4e3ebSFlorian Fainelli 
1803c7d28c9dSFlorian Fainelli static bool b53_can_enable_brcm_tags(struct dsa_switch *ds, int port)
1804c7d28c9dSFlorian Fainelli {
1805c7d28c9dSFlorian Fainelli 	bool ret = b53_possible_cpu_port(ds, port);
1806c7d28c9dSFlorian Fainelli 
1807c7d28c9dSFlorian Fainelli 	if (!ret)
1808c7d28c9dSFlorian Fainelli 		dev_warn(ds->dev, "Port %d is not Broadcom tag capable\n",
1809c7d28c9dSFlorian Fainelli 			 port);
1810c7d28c9dSFlorian Fainelli 	return ret;
1811c7d28c9dSFlorian Fainelli }
1812c7d28c9dSFlorian Fainelli 
18139f66816aSFlorian Fainelli enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds, int port)
18147b314362SAndrew Lunn {
18157edc58d6SFlorian Fainelli 	struct b53_device *dev = ds->priv;
18167edc58d6SFlorian Fainelli 
181754e98b5dSFlorian Fainelli 	/* Older models (5325, 5365) support a different tag format that we do
181854e98b5dSFlorian Fainelli 	 * not support in net/dsa/tag_brcm.c yet. 539x and 531x5 require managed
181954e98b5dSFlorian Fainelli 	 * mode to be turned on which means we need to specifically manage ARL
182054e98b5dSFlorian Fainelli 	 * misses on multicast addresses (TBD).
18217edc58d6SFlorian Fainelli 	 */
182254e98b5dSFlorian Fainelli 	if (is5325(dev) || is5365(dev) || is539x(dev) || is531x5(dev) ||
182354e98b5dSFlorian Fainelli 	    !b53_can_enable_brcm_tags(ds, port))
18247b314362SAndrew Lunn 		return DSA_TAG_PROTO_NONE;
182511606039SFlorian Fainelli 
182611606039SFlorian Fainelli 	/* Broadcom BCM58xx chips have a flow accelerator on Port 8
182711606039SFlorian Fainelli 	 * which requires us to use the prepended Broadcom tag type
182811606039SFlorian Fainelli 	 */
182911606039SFlorian Fainelli 	if (dev->chip_id == BCM58XX_DEVICE_ID && port == B53_CPU_PORT)
183011606039SFlorian Fainelli 		return DSA_TAG_PROTO_BRCM_PREPEND;
183111606039SFlorian Fainelli 
18327edc58d6SFlorian Fainelli 	return DSA_TAG_PROTO_BRCM;
18337b314362SAndrew Lunn }
18349f66816aSFlorian Fainelli EXPORT_SYMBOL(b53_get_tag_protocol);
18357b314362SAndrew Lunn 
1836ed3af5fdSFlorian Fainelli int b53_mirror_add(struct dsa_switch *ds, int port,
1837ed3af5fdSFlorian Fainelli 		   struct dsa_mall_mirror_tc_entry *mirror, bool ingress)
1838ed3af5fdSFlorian Fainelli {
1839ed3af5fdSFlorian Fainelli 	struct b53_device *dev = ds->priv;
1840ed3af5fdSFlorian Fainelli 	u16 reg, loc;
1841ed3af5fdSFlorian Fainelli 
1842ed3af5fdSFlorian Fainelli 	if (ingress)
1843ed3af5fdSFlorian Fainelli 		loc = B53_IG_MIR_CTL;
1844ed3af5fdSFlorian Fainelli 	else
1845ed3af5fdSFlorian Fainelli 		loc = B53_EG_MIR_CTL;
1846ed3af5fdSFlorian Fainelli 
1847ed3af5fdSFlorian Fainelli 	b53_read16(dev, B53_MGMT_PAGE, loc, &reg);
1848ed3af5fdSFlorian Fainelli 	reg &= ~MIRROR_MASK;
1849ed3af5fdSFlorian Fainelli 	reg |= BIT(port);
1850ed3af5fdSFlorian Fainelli 	b53_write16(dev, B53_MGMT_PAGE, loc, reg);
1851ed3af5fdSFlorian Fainelli 
1852ed3af5fdSFlorian Fainelli 	b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, &reg);
1853ed3af5fdSFlorian Fainelli 	reg &= ~CAP_PORT_MASK;
1854ed3af5fdSFlorian Fainelli 	reg |= mirror->to_local_port;
1855ed3af5fdSFlorian Fainelli 	reg |= MIRROR_EN;
1856ed3af5fdSFlorian Fainelli 	b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg);
1857ed3af5fdSFlorian Fainelli 
1858ed3af5fdSFlorian Fainelli 	return 0;
1859ed3af5fdSFlorian Fainelli }
1860ed3af5fdSFlorian Fainelli EXPORT_SYMBOL(b53_mirror_add);
1861ed3af5fdSFlorian Fainelli 
1862ed3af5fdSFlorian Fainelli void b53_mirror_del(struct dsa_switch *ds, int port,
1863ed3af5fdSFlorian Fainelli 		    struct dsa_mall_mirror_tc_entry *mirror)
1864ed3af5fdSFlorian Fainelli {
1865ed3af5fdSFlorian Fainelli 	struct b53_device *dev = ds->priv;
1866ed3af5fdSFlorian Fainelli 	bool loc_disable = false, other_loc_disable = false;
1867ed3af5fdSFlorian Fainelli 	u16 reg, loc;
1868ed3af5fdSFlorian Fainelli 
1869ed3af5fdSFlorian Fainelli 	if (mirror->ingress)
1870ed3af5fdSFlorian Fainelli 		loc = B53_IG_MIR_CTL;
1871ed3af5fdSFlorian Fainelli 	else
1872ed3af5fdSFlorian Fainelli 		loc = B53_EG_MIR_CTL;
1873ed3af5fdSFlorian Fainelli 
1874ed3af5fdSFlorian Fainelli 	/* Update the desired ingress/egress register */
1875ed3af5fdSFlorian Fainelli 	b53_read16(dev, B53_MGMT_PAGE, loc, &reg);
1876ed3af5fdSFlorian Fainelli 	reg &= ~BIT(port);
1877ed3af5fdSFlorian Fainelli 	if (!(reg & MIRROR_MASK))
1878ed3af5fdSFlorian Fainelli 		loc_disable = true;
1879ed3af5fdSFlorian Fainelli 	b53_write16(dev, B53_MGMT_PAGE, loc, reg);
1880ed3af5fdSFlorian Fainelli 
1881ed3af5fdSFlorian Fainelli 	/* Now look at the other one to know if we can disable mirroring
1882ed3af5fdSFlorian Fainelli 	 * entirely
1883ed3af5fdSFlorian Fainelli 	 */
1884ed3af5fdSFlorian Fainelli 	if (mirror->ingress)
1885ed3af5fdSFlorian Fainelli 		b53_read16(dev, B53_MGMT_PAGE, B53_EG_MIR_CTL, &reg);
1886ed3af5fdSFlorian Fainelli 	else
1887ed3af5fdSFlorian Fainelli 		b53_read16(dev, B53_MGMT_PAGE, B53_IG_MIR_CTL, &reg);
1888ed3af5fdSFlorian Fainelli 	if (!(reg & MIRROR_MASK))
1889ed3af5fdSFlorian Fainelli 		other_loc_disable = true;
1890ed3af5fdSFlorian Fainelli 
1891ed3af5fdSFlorian Fainelli 	b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, &reg);
1892ed3af5fdSFlorian Fainelli 	/* Both no longer have ports, let's disable mirroring */
1893ed3af5fdSFlorian Fainelli 	if (loc_disable && other_loc_disable) {
1894ed3af5fdSFlorian Fainelli 		reg &= ~MIRROR_EN;
1895ed3af5fdSFlorian Fainelli 		reg &= ~mirror->to_local_port;
1896ed3af5fdSFlorian Fainelli 	}
1897ed3af5fdSFlorian Fainelli 	b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg);
1898ed3af5fdSFlorian Fainelli }
1899ed3af5fdSFlorian Fainelli EXPORT_SYMBOL(b53_mirror_del);
1900ed3af5fdSFlorian Fainelli 
190122256b0aSFlorian Fainelli void b53_eee_enable_set(struct dsa_switch *ds, int port, bool enable)
190222256b0aSFlorian Fainelli {
190322256b0aSFlorian Fainelli 	struct b53_device *dev = ds->priv;
190422256b0aSFlorian Fainelli 	u16 reg;
190522256b0aSFlorian Fainelli 
190622256b0aSFlorian Fainelli 	b53_read16(dev, B53_EEE_PAGE, B53_EEE_EN_CTRL, &reg);
190722256b0aSFlorian Fainelli 	if (enable)
190822256b0aSFlorian Fainelli 		reg |= BIT(port);
190922256b0aSFlorian Fainelli 	else
191022256b0aSFlorian Fainelli 		reg &= ~BIT(port);
191122256b0aSFlorian Fainelli 	b53_write16(dev, B53_EEE_PAGE, B53_EEE_EN_CTRL, reg);
191222256b0aSFlorian Fainelli }
191322256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_eee_enable_set);
191422256b0aSFlorian Fainelli 
191522256b0aSFlorian Fainelli 
191622256b0aSFlorian Fainelli /* Returns 0 if EEE was not enabled, or 1 otherwise
191722256b0aSFlorian Fainelli  */
191822256b0aSFlorian Fainelli int b53_eee_init(struct dsa_switch *ds, int port, struct phy_device *phy)
191922256b0aSFlorian Fainelli {
192022256b0aSFlorian Fainelli 	int ret;
192122256b0aSFlorian Fainelli 
192222256b0aSFlorian Fainelli 	ret = phy_init_eee(phy, 0);
192322256b0aSFlorian Fainelli 	if (ret)
192422256b0aSFlorian Fainelli 		return 0;
192522256b0aSFlorian Fainelli 
192622256b0aSFlorian Fainelli 	b53_eee_enable_set(ds, port, true);
192722256b0aSFlorian Fainelli 
192822256b0aSFlorian Fainelli 	return 1;
192922256b0aSFlorian Fainelli }
193022256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_eee_init);
193122256b0aSFlorian Fainelli 
193222256b0aSFlorian Fainelli int b53_get_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e)
193322256b0aSFlorian Fainelli {
193422256b0aSFlorian Fainelli 	struct b53_device *dev = ds->priv;
193522256b0aSFlorian Fainelli 	struct ethtool_eee *p = &dev->ports[port].eee;
193622256b0aSFlorian Fainelli 	u16 reg;
193722256b0aSFlorian Fainelli 
193822256b0aSFlorian Fainelli 	if (is5325(dev) || is5365(dev))
193922256b0aSFlorian Fainelli 		return -EOPNOTSUPP;
194022256b0aSFlorian Fainelli 
194122256b0aSFlorian Fainelli 	b53_read16(dev, B53_EEE_PAGE, B53_EEE_LPI_INDICATE, &reg);
194222256b0aSFlorian Fainelli 	e->eee_enabled = p->eee_enabled;
194322256b0aSFlorian Fainelli 	e->eee_active = !!(reg & BIT(port));
194422256b0aSFlorian Fainelli 
194522256b0aSFlorian Fainelli 	return 0;
194622256b0aSFlorian Fainelli }
194722256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_get_mac_eee);
194822256b0aSFlorian Fainelli 
194922256b0aSFlorian Fainelli int b53_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e)
195022256b0aSFlorian Fainelli {
195122256b0aSFlorian Fainelli 	struct b53_device *dev = ds->priv;
195222256b0aSFlorian Fainelli 	struct ethtool_eee *p = &dev->ports[port].eee;
195322256b0aSFlorian Fainelli 
195422256b0aSFlorian Fainelli 	if (is5325(dev) || is5365(dev))
195522256b0aSFlorian Fainelli 		return -EOPNOTSUPP;
195622256b0aSFlorian Fainelli 
195722256b0aSFlorian Fainelli 	p->eee_enabled = e->eee_enabled;
195822256b0aSFlorian Fainelli 	b53_eee_enable_set(ds, port, e->eee_enabled);
195922256b0aSFlorian Fainelli 
196022256b0aSFlorian Fainelli 	return 0;
196122256b0aSFlorian Fainelli }
196222256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_set_mac_eee);
196322256b0aSFlorian Fainelli 
1964a82f67afSFlorian Fainelli static const struct dsa_switch_ops b53_switch_ops = {
19657b314362SAndrew Lunn 	.get_tag_protocol	= b53_get_tag_protocol,
1966967dd82fSFlorian Fainelli 	.setup			= b53_setup,
1967967dd82fSFlorian Fainelli 	.get_strings		= b53_get_strings,
1968967dd82fSFlorian Fainelli 	.get_ethtool_stats	= b53_get_ethtool_stats,
1969967dd82fSFlorian Fainelli 	.get_sset_count		= b53_get_sset_count,
1970c7d28c9dSFlorian Fainelli 	.get_ethtool_phy_stats	= b53_get_ethtool_phy_stats,
1971967dd82fSFlorian Fainelli 	.phy_read		= b53_phy_read16,
1972967dd82fSFlorian Fainelli 	.phy_write		= b53_phy_write16,
1973967dd82fSFlorian Fainelli 	.adjust_link		= b53_adjust_link,
1974a8e8b985SFlorian Fainelli 	.phylink_validate	= b53_phylink_validate,
1975a8e8b985SFlorian Fainelli 	.phylink_mac_link_state	= b53_phylink_mac_link_state,
1976a8e8b985SFlorian Fainelli 	.phylink_mac_config	= b53_phylink_mac_config,
1977a8e8b985SFlorian Fainelli 	.phylink_mac_an_restart	= b53_phylink_mac_an_restart,
1978a8e8b985SFlorian Fainelli 	.phylink_mac_link_down	= b53_phylink_mac_link_down,
1979a8e8b985SFlorian Fainelli 	.phylink_mac_link_up	= b53_phylink_mac_link_up,
1980967dd82fSFlorian Fainelli 	.port_enable		= b53_enable_port,
1981967dd82fSFlorian Fainelli 	.port_disable		= b53_disable_port,
1982f43a2dbeSFlorian Fainelli 	.get_mac_eee		= b53_get_mac_eee,
1983f43a2dbeSFlorian Fainelli 	.set_mac_eee		= b53_set_mac_eee,
1984ff39c2d6SFlorian Fainelli 	.port_bridge_join	= b53_br_join,
1985ff39c2d6SFlorian Fainelli 	.port_bridge_leave	= b53_br_leave,
1986ff39c2d6SFlorian Fainelli 	.port_stp_state_set	= b53_br_set_stp_state,
1987597698f1SVivien Didelot 	.port_fast_age		= b53_br_fast_age,
1988*53568438SFlorian Fainelli 	.port_egress_floods	= b53_br_egress_floods,
1989a2482d2cSFlorian Fainelli 	.port_vlan_filtering	= b53_vlan_filtering,
1990a2482d2cSFlorian Fainelli 	.port_vlan_prepare	= b53_vlan_prepare,
1991a2482d2cSFlorian Fainelli 	.port_vlan_add		= b53_vlan_add,
1992a2482d2cSFlorian Fainelli 	.port_vlan_del		= b53_vlan_del,
19931da6df85SFlorian Fainelli 	.port_fdb_dump		= b53_fdb_dump,
19941da6df85SFlorian Fainelli 	.port_fdb_add		= b53_fdb_add,
19951da6df85SFlorian Fainelli 	.port_fdb_del		= b53_fdb_del,
1996ed3af5fdSFlorian Fainelli 	.port_mirror_add	= b53_mirror_add,
1997ed3af5fdSFlorian Fainelli 	.port_mirror_del	= b53_mirror_del,
1998967dd82fSFlorian Fainelli };
1999967dd82fSFlorian Fainelli 
2000967dd82fSFlorian Fainelli struct b53_chip_data {
2001967dd82fSFlorian Fainelli 	u32 chip_id;
2002967dd82fSFlorian Fainelli 	const char *dev_name;
2003967dd82fSFlorian Fainelli 	u16 vlans;
2004967dd82fSFlorian Fainelli 	u16 enabled_ports;
2005967dd82fSFlorian Fainelli 	u8 cpu_port;
2006967dd82fSFlorian Fainelli 	u8 vta_regs[3];
20071da6df85SFlorian Fainelli 	u8 arl_entries;
2008967dd82fSFlorian Fainelli 	u8 duplex_reg;
2009967dd82fSFlorian Fainelli 	u8 jumbo_pm_reg;
2010967dd82fSFlorian Fainelli 	u8 jumbo_size_reg;
2011967dd82fSFlorian Fainelli };
2012967dd82fSFlorian Fainelli 
2013967dd82fSFlorian Fainelli #define B53_VTA_REGS	\
2014967dd82fSFlorian Fainelli 	{ B53_VT_ACCESS, B53_VT_INDEX, B53_VT_ENTRY }
2015967dd82fSFlorian Fainelli #define B53_VTA_REGS_9798 \
2016967dd82fSFlorian Fainelli 	{ B53_VT_ACCESS_9798, B53_VT_INDEX_9798, B53_VT_ENTRY_9798 }
2017967dd82fSFlorian Fainelli #define B53_VTA_REGS_63XX \
2018967dd82fSFlorian Fainelli 	{ B53_VT_ACCESS_63XX, B53_VT_INDEX_63XX, B53_VT_ENTRY_63XX }
2019967dd82fSFlorian Fainelli 
2020967dd82fSFlorian Fainelli static const struct b53_chip_data b53_switch_chips[] = {
2021967dd82fSFlorian Fainelli 	{
2022967dd82fSFlorian Fainelli 		.chip_id = BCM5325_DEVICE_ID,
2023967dd82fSFlorian Fainelli 		.dev_name = "BCM5325",
2024967dd82fSFlorian Fainelli 		.vlans = 16,
2025967dd82fSFlorian Fainelli 		.enabled_ports = 0x1f,
20261da6df85SFlorian Fainelli 		.arl_entries = 2,
2027967dd82fSFlorian Fainelli 		.cpu_port = B53_CPU_PORT_25,
2028967dd82fSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_FE,
2029967dd82fSFlorian Fainelli 	},
2030967dd82fSFlorian Fainelli 	{
2031967dd82fSFlorian Fainelli 		.chip_id = BCM5365_DEVICE_ID,
2032967dd82fSFlorian Fainelli 		.dev_name = "BCM5365",
2033967dd82fSFlorian Fainelli 		.vlans = 256,
2034967dd82fSFlorian Fainelli 		.enabled_ports = 0x1f,
20351da6df85SFlorian Fainelli 		.arl_entries = 2,
2036967dd82fSFlorian Fainelli 		.cpu_port = B53_CPU_PORT_25,
2037967dd82fSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_FE,
2038967dd82fSFlorian Fainelli 	},
2039967dd82fSFlorian Fainelli 	{
2040a95691bcSDamien Thébault 		.chip_id = BCM5389_DEVICE_ID,
2041a95691bcSDamien Thébault 		.dev_name = "BCM5389",
2042a95691bcSDamien Thébault 		.vlans = 4096,
2043a95691bcSDamien Thébault 		.enabled_ports = 0x1f,
2044a95691bcSDamien Thébault 		.arl_entries = 4,
2045a95691bcSDamien Thébault 		.cpu_port = B53_CPU_PORT,
2046a95691bcSDamien Thébault 		.vta_regs = B53_VTA_REGS,
2047a95691bcSDamien Thébault 		.duplex_reg = B53_DUPLEX_STAT_GE,
2048a95691bcSDamien Thébault 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2049a95691bcSDamien Thébault 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2050a95691bcSDamien Thébault 	},
2051a95691bcSDamien Thébault 	{
2052967dd82fSFlorian Fainelli 		.chip_id = BCM5395_DEVICE_ID,
2053967dd82fSFlorian Fainelli 		.dev_name = "BCM5395",
2054967dd82fSFlorian Fainelli 		.vlans = 4096,
2055967dd82fSFlorian Fainelli 		.enabled_ports = 0x1f,
20561da6df85SFlorian Fainelli 		.arl_entries = 4,
2057967dd82fSFlorian Fainelli 		.cpu_port = B53_CPU_PORT,
2058967dd82fSFlorian Fainelli 		.vta_regs = B53_VTA_REGS,
2059967dd82fSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_GE,
2060967dd82fSFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2061967dd82fSFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2062967dd82fSFlorian Fainelli 	},
2063967dd82fSFlorian Fainelli 	{
2064967dd82fSFlorian Fainelli 		.chip_id = BCM5397_DEVICE_ID,
2065967dd82fSFlorian Fainelli 		.dev_name = "BCM5397",
2066967dd82fSFlorian Fainelli 		.vlans = 4096,
2067967dd82fSFlorian Fainelli 		.enabled_ports = 0x1f,
20681da6df85SFlorian Fainelli 		.arl_entries = 4,
2069967dd82fSFlorian Fainelli 		.cpu_port = B53_CPU_PORT,
2070967dd82fSFlorian Fainelli 		.vta_regs = B53_VTA_REGS_9798,
2071967dd82fSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_GE,
2072967dd82fSFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2073967dd82fSFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2074967dd82fSFlorian Fainelli 	},
2075967dd82fSFlorian Fainelli 	{
2076967dd82fSFlorian Fainelli 		.chip_id = BCM5398_DEVICE_ID,
2077967dd82fSFlorian Fainelli 		.dev_name = "BCM5398",
2078967dd82fSFlorian Fainelli 		.vlans = 4096,
2079967dd82fSFlorian Fainelli 		.enabled_ports = 0x7f,
20801da6df85SFlorian Fainelli 		.arl_entries = 4,
2081967dd82fSFlorian Fainelli 		.cpu_port = B53_CPU_PORT,
2082967dd82fSFlorian Fainelli 		.vta_regs = B53_VTA_REGS_9798,
2083967dd82fSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_GE,
2084967dd82fSFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2085967dd82fSFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2086967dd82fSFlorian Fainelli 	},
2087967dd82fSFlorian Fainelli 	{
2088967dd82fSFlorian Fainelli 		.chip_id = BCM53115_DEVICE_ID,
2089967dd82fSFlorian Fainelli 		.dev_name = "BCM53115",
2090967dd82fSFlorian Fainelli 		.vlans = 4096,
2091967dd82fSFlorian Fainelli 		.enabled_ports = 0x1f,
20921da6df85SFlorian Fainelli 		.arl_entries = 4,
2093967dd82fSFlorian Fainelli 		.vta_regs = B53_VTA_REGS,
2094967dd82fSFlorian Fainelli 		.cpu_port = B53_CPU_PORT,
2095967dd82fSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_GE,
2096967dd82fSFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2097967dd82fSFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2098967dd82fSFlorian Fainelli 	},
2099967dd82fSFlorian Fainelli 	{
2100967dd82fSFlorian Fainelli 		.chip_id = BCM53125_DEVICE_ID,
2101967dd82fSFlorian Fainelli 		.dev_name = "BCM53125",
2102967dd82fSFlorian Fainelli 		.vlans = 4096,
2103967dd82fSFlorian Fainelli 		.enabled_ports = 0xff,
2104be35e8c5SFlorian Fainelli 		.arl_entries = 4,
2105967dd82fSFlorian Fainelli 		.cpu_port = B53_CPU_PORT,
2106967dd82fSFlorian Fainelli 		.vta_regs = B53_VTA_REGS,
2107967dd82fSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_GE,
2108967dd82fSFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2109967dd82fSFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2110967dd82fSFlorian Fainelli 	},
2111967dd82fSFlorian Fainelli 	{
2112967dd82fSFlorian Fainelli 		.chip_id = BCM53128_DEVICE_ID,
2113967dd82fSFlorian Fainelli 		.dev_name = "BCM53128",
2114967dd82fSFlorian Fainelli 		.vlans = 4096,
2115967dd82fSFlorian Fainelli 		.enabled_ports = 0x1ff,
21161da6df85SFlorian Fainelli 		.arl_entries = 4,
2117967dd82fSFlorian Fainelli 		.cpu_port = B53_CPU_PORT,
2118967dd82fSFlorian Fainelli 		.vta_regs = B53_VTA_REGS,
2119967dd82fSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_GE,
2120967dd82fSFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2121967dd82fSFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2122967dd82fSFlorian Fainelli 	},
2123967dd82fSFlorian Fainelli 	{
2124967dd82fSFlorian Fainelli 		.chip_id = BCM63XX_DEVICE_ID,
2125967dd82fSFlorian Fainelli 		.dev_name = "BCM63xx",
2126967dd82fSFlorian Fainelli 		.vlans = 4096,
2127967dd82fSFlorian Fainelli 		.enabled_ports = 0, /* pdata must provide them */
21281da6df85SFlorian Fainelli 		.arl_entries = 4,
2129967dd82fSFlorian Fainelli 		.cpu_port = B53_CPU_PORT,
2130967dd82fSFlorian Fainelli 		.vta_regs = B53_VTA_REGS_63XX,
2131967dd82fSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_63XX,
2132967dd82fSFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK_63XX,
2133967dd82fSFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE_63XX,
2134967dd82fSFlorian Fainelli 	},
2135967dd82fSFlorian Fainelli 	{
2136967dd82fSFlorian Fainelli 		.chip_id = BCM53010_DEVICE_ID,
2137967dd82fSFlorian Fainelli 		.dev_name = "BCM53010",
2138967dd82fSFlorian Fainelli 		.vlans = 4096,
2139967dd82fSFlorian Fainelli 		.enabled_ports = 0x1f,
21401da6df85SFlorian Fainelli 		.arl_entries = 4,
2141967dd82fSFlorian Fainelli 		.cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
2142967dd82fSFlorian Fainelli 		.vta_regs = B53_VTA_REGS,
2143967dd82fSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_GE,
2144967dd82fSFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2145967dd82fSFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2146967dd82fSFlorian Fainelli 	},
2147967dd82fSFlorian Fainelli 	{
2148967dd82fSFlorian Fainelli 		.chip_id = BCM53011_DEVICE_ID,
2149967dd82fSFlorian Fainelli 		.dev_name = "BCM53011",
2150967dd82fSFlorian Fainelli 		.vlans = 4096,
2151967dd82fSFlorian Fainelli 		.enabled_ports = 0x1bf,
21521da6df85SFlorian Fainelli 		.arl_entries = 4,
2153967dd82fSFlorian Fainelli 		.cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
2154967dd82fSFlorian Fainelli 		.vta_regs = B53_VTA_REGS,
2155967dd82fSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_GE,
2156967dd82fSFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2157967dd82fSFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2158967dd82fSFlorian Fainelli 	},
2159967dd82fSFlorian Fainelli 	{
2160967dd82fSFlorian Fainelli 		.chip_id = BCM53012_DEVICE_ID,
2161967dd82fSFlorian Fainelli 		.dev_name = "BCM53012",
2162967dd82fSFlorian Fainelli 		.vlans = 4096,
2163967dd82fSFlorian Fainelli 		.enabled_ports = 0x1bf,
21641da6df85SFlorian Fainelli 		.arl_entries = 4,
2165967dd82fSFlorian Fainelli 		.cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
2166967dd82fSFlorian Fainelli 		.vta_regs = B53_VTA_REGS,
2167967dd82fSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_GE,
2168967dd82fSFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2169967dd82fSFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2170967dd82fSFlorian Fainelli 	},
2171967dd82fSFlorian Fainelli 	{
2172967dd82fSFlorian Fainelli 		.chip_id = BCM53018_DEVICE_ID,
2173967dd82fSFlorian Fainelli 		.dev_name = "BCM53018",
2174967dd82fSFlorian Fainelli 		.vlans = 4096,
2175967dd82fSFlorian Fainelli 		.enabled_ports = 0x1f,
21761da6df85SFlorian Fainelli 		.arl_entries = 4,
2177967dd82fSFlorian Fainelli 		.cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
2178967dd82fSFlorian Fainelli 		.vta_regs = B53_VTA_REGS,
2179967dd82fSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_GE,
2180967dd82fSFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2181967dd82fSFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2182967dd82fSFlorian Fainelli 	},
2183967dd82fSFlorian Fainelli 	{
2184967dd82fSFlorian Fainelli 		.chip_id = BCM53019_DEVICE_ID,
2185967dd82fSFlorian Fainelli 		.dev_name = "BCM53019",
2186967dd82fSFlorian Fainelli 		.vlans = 4096,
2187967dd82fSFlorian Fainelli 		.enabled_ports = 0x1f,
21881da6df85SFlorian Fainelli 		.arl_entries = 4,
2189967dd82fSFlorian Fainelli 		.cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
2190967dd82fSFlorian Fainelli 		.vta_regs = B53_VTA_REGS,
2191967dd82fSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_GE,
2192967dd82fSFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2193967dd82fSFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2194967dd82fSFlorian Fainelli 	},
2195991a36bbSFlorian Fainelli 	{
2196991a36bbSFlorian Fainelli 		.chip_id = BCM58XX_DEVICE_ID,
2197991a36bbSFlorian Fainelli 		.dev_name = "BCM585xx/586xx/88312",
2198991a36bbSFlorian Fainelli 		.vlans	= 4096,
2199991a36bbSFlorian Fainelli 		.enabled_ports = 0x1ff,
2200991a36bbSFlorian Fainelli 		.arl_entries = 4,
2201bfcda65cSFlorian Fainelli 		.cpu_port = B53_CPU_PORT,
2202991a36bbSFlorian Fainelli 		.vta_regs = B53_VTA_REGS,
2203991a36bbSFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_GE,
2204991a36bbSFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2205991a36bbSFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2206991a36bbSFlorian Fainelli 	},
2207130401d9SFlorian Fainelli 	{
22085040cc99SArun Parameswaran 		.chip_id = BCM583XX_DEVICE_ID,
22095040cc99SArun Parameswaran 		.dev_name = "BCM583xx/11360",
22105040cc99SArun Parameswaran 		.vlans = 4096,
22115040cc99SArun Parameswaran 		.enabled_ports = 0x103,
22125040cc99SArun Parameswaran 		.arl_entries = 4,
22135040cc99SArun Parameswaran 		.cpu_port = B53_CPU_PORT,
22145040cc99SArun Parameswaran 		.vta_regs = B53_VTA_REGS,
22155040cc99SArun Parameswaran 		.duplex_reg = B53_DUPLEX_STAT_GE,
22165040cc99SArun Parameswaran 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
22175040cc99SArun Parameswaran 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
22185040cc99SArun Parameswaran 	},
22195040cc99SArun Parameswaran 	{
2220130401d9SFlorian Fainelli 		.chip_id = BCM7445_DEVICE_ID,
2221130401d9SFlorian Fainelli 		.dev_name = "BCM7445",
2222130401d9SFlorian Fainelli 		.vlans	= 4096,
2223130401d9SFlorian Fainelli 		.enabled_ports = 0x1ff,
2224130401d9SFlorian Fainelli 		.arl_entries = 4,
2225130401d9SFlorian Fainelli 		.cpu_port = B53_CPU_PORT,
2226130401d9SFlorian Fainelli 		.vta_regs = B53_VTA_REGS,
2227130401d9SFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_GE,
2228130401d9SFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2229130401d9SFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2230130401d9SFlorian Fainelli 	},
22310fe99338SFlorian Fainelli 	{
22320fe99338SFlorian Fainelli 		.chip_id = BCM7278_DEVICE_ID,
22330fe99338SFlorian Fainelli 		.dev_name = "BCM7278",
22340fe99338SFlorian Fainelli 		.vlans = 4096,
22350fe99338SFlorian Fainelli 		.enabled_ports = 0x1ff,
22360fe99338SFlorian Fainelli 		.arl_entries= 4,
22370fe99338SFlorian Fainelli 		.cpu_port = B53_CPU_PORT,
22380fe99338SFlorian Fainelli 		.vta_regs = B53_VTA_REGS,
22390fe99338SFlorian Fainelli 		.duplex_reg = B53_DUPLEX_STAT_GE,
22400fe99338SFlorian Fainelli 		.jumbo_pm_reg = B53_JUMBO_PORT_MASK,
22410fe99338SFlorian Fainelli 		.jumbo_size_reg = B53_JUMBO_MAX_SIZE,
22420fe99338SFlorian Fainelli 	},
2243967dd82fSFlorian Fainelli };
2244967dd82fSFlorian Fainelli 
2245967dd82fSFlorian Fainelli static int b53_switch_init(struct b53_device *dev)
2246967dd82fSFlorian Fainelli {
2247967dd82fSFlorian Fainelli 	unsigned int i;
2248967dd82fSFlorian Fainelli 	int ret;
2249967dd82fSFlorian Fainelli 
2250967dd82fSFlorian Fainelli 	for (i = 0; i < ARRAY_SIZE(b53_switch_chips); i++) {
2251967dd82fSFlorian Fainelli 		const struct b53_chip_data *chip = &b53_switch_chips[i];
2252967dd82fSFlorian Fainelli 
2253967dd82fSFlorian Fainelli 		if (chip->chip_id == dev->chip_id) {
2254967dd82fSFlorian Fainelli 			if (!dev->enabled_ports)
2255967dd82fSFlorian Fainelli 				dev->enabled_ports = chip->enabled_ports;
2256967dd82fSFlorian Fainelli 			dev->name = chip->dev_name;
2257967dd82fSFlorian Fainelli 			dev->duplex_reg = chip->duplex_reg;
2258967dd82fSFlorian Fainelli 			dev->vta_regs[0] = chip->vta_regs[0];
2259967dd82fSFlorian Fainelli 			dev->vta_regs[1] = chip->vta_regs[1];
2260967dd82fSFlorian Fainelli 			dev->vta_regs[2] = chip->vta_regs[2];
2261967dd82fSFlorian Fainelli 			dev->jumbo_pm_reg = chip->jumbo_pm_reg;
2262967dd82fSFlorian Fainelli 			dev->cpu_port = chip->cpu_port;
2263967dd82fSFlorian Fainelli 			dev->num_vlans = chip->vlans;
22641da6df85SFlorian Fainelli 			dev->num_arl_entries = chip->arl_entries;
2265967dd82fSFlorian Fainelli 			break;
2266967dd82fSFlorian Fainelli 		}
2267967dd82fSFlorian Fainelli 	}
2268967dd82fSFlorian Fainelli 
2269967dd82fSFlorian Fainelli 	/* check which BCM5325x version we have */
2270967dd82fSFlorian Fainelli 	if (is5325(dev)) {
2271967dd82fSFlorian Fainelli 		u8 vc4;
2272967dd82fSFlorian Fainelli 
2273967dd82fSFlorian Fainelli 		b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, &vc4);
2274967dd82fSFlorian Fainelli 
2275967dd82fSFlorian Fainelli 		/* check reserved bits */
2276967dd82fSFlorian Fainelli 		switch (vc4 & 3) {
2277967dd82fSFlorian Fainelli 		case 1:
2278967dd82fSFlorian Fainelli 			/* BCM5325E */
2279967dd82fSFlorian Fainelli 			break;
2280967dd82fSFlorian Fainelli 		case 3:
2281967dd82fSFlorian Fainelli 			/* BCM5325F - do not use port 4 */
2282967dd82fSFlorian Fainelli 			dev->enabled_ports &= ~BIT(4);
2283967dd82fSFlorian Fainelli 			break;
2284967dd82fSFlorian Fainelli 		default:
2285967dd82fSFlorian Fainelli /* On the BCM47XX SoCs this is the supported internal switch.*/
2286967dd82fSFlorian Fainelli #ifndef CONFIG_BCM47XX
2287967dd82fSFlorian Fainelli 			/* BCM5325M */
2288967dd82fSFlorian Fainelli 			return -EINVAL;
2289967dd82fSFlorian Fainelli #else
2290967dd82fSFlorian Fainelli 			break;
2291967dd82fSFlorian Fainelli #endif
2292967dd82fSFlorian Fainelli 		}
2293967dd82fSFlorian Fainelli 	} else if (dev->chip_id == BCM53115_DEVICE_ID) {
2294967dd82fSFlorian Fainelli 		u64 strap_value;
2295967dd82fSFlorian Fainelli 
2296967dd82fSFlorian Fainelli 		b53_read48(dev, B53_STAT_PAGE, B53_STRAP_VALUE, &strap_value);
2297967dd82fSFlorian Fainelli 		/* use second IMP port if GMII is enabled */
2298967dd82fSFlorian Fainelli 		if (strap_value & SV_GMII_CTRL_115)
2299967dd82fSFlorian Fainelli 			dev->cpu_port = 5;
2300967dd82fSFlorian Fainelli 	}
2301967dd82fSFlorian Fainelli 
2302967dd82fSFlorian Fainelli 	/* cpu port is always last */
2303967dd82fSFlorian Fainelli 	dev->num_ports = dev->cpu_port + 1;
2304967dd82fSFlorian Fainelli 	dev->enabled_ports |= BIT(dev->cpu_port);
2305967dd82fSFlorian Fainelli 
2306c7d28c9dSFlorian Fainelli 	/* Include non standard CPU port built-in PHYs to be probed */
2307c7d28c9dSFlorian Fainelli 	if (is539x(dev) || is531x5(dev)) {
2308c7d28c9dSFlorian Fainelli 		for (i = 0; i < dev->num_ports; i++) {
2309c7d28c9dSFlorian Fainelli 			if (!(dev->ds->phys_mii_mask & BIT(i)) &&
2310c7d28c9dSFlorian Fainelli 			    !b53_possible_cpu_port(dev->ds, i))
2311c7d28c9dSFlorian Fainelli 				dev->ds->phys_mii_mask |= BIT(i);
2312c7d28c9dSFlorian Fainelli 		}
2313c7d28c9dSFlorian Fainelli 	}
2314c7d28c9dSFlorian Fainelli 
2315a86854d0SKees Cook 	dev->ports = devm_kcalloc(dev->dev,
2316a86854d0SKees Cook 				  dev->num_ports, sizeof(struct b53_port),
2317967dd82fSFlorian Fainelli 				  GFP_KERNEL);
2318967dd82fSFlorian Fainelli 	if (!dev->ports)
2319967dd82fSFlorian Fainelli 		return -ENOMEM;
2320967dd82fSFlorian Fainelli 
2321a86854d0SKees Cook 	dev->vlans = devm_kcalloc(dev->dev,
2322a86854d0SKees Cook 				  dev->num_vlans, sizeof(struct b53_vlan),
2323a2482d2cSFlorian Fainelli 				  GFP_KERNEL);
2324a2482d2cSFlorian Fainelli 	if (!dev->vlans)
2325a2482d2cSFlorian Fainelli 		return -ENOMEM;
2326a2482d2cSFlorian Fainelli 
2327967dd82fSFlorian Fainelli 	dev->reset_gpio = b53_switch_get_reset_gpio(dev);
2328967dd82fSFlorian Fainelli 	if (dev->reset_gpio >= 0) {
2329967dd82fSFlorian Fainelli 		ret = devm_gpio_request_one(dev->dev, dev->reset_gpio,
2330967dd82fSFlorian Fainelli 					    GPIOF_OUT_INIT_HIGH, "robo_reset");
2331967dd82fSFlorian Fainelli 		if (ret)
2332967dd82fSFlorian Fainelli 			return ret;
2333967dd82fSFlorian Fainelli 	}
2334967dd82fSFlorian Fainelli 
2335967dd82fSFlorian Fainelli 	return 0;
2336967dd82fSFlorian Fainelli }
2337967dd82fSFlorian Fainelli 
23380dff88d3SJulia Lawall struct b53_device *b53_switch_alloc(struct device *base,
23390dff88d3SJulia Lawall 				    const struct b53_io_ops *ops,
2340967dd82fSFlorian Fainelli 				    void *priv)
2341967dd82fSFlorian Fainelli {
2342967dd82fSFlorian Fainelli 	struct dsa_switch *ds;
2343967dd82fSFlorian Fainelli 	struct b53_device *dev;
2344967dd82fSFlorian Fainelli 
2345a0c02161SVivien Didelot 	ds = dsa_switch_alloc(base, DSA_MAX_PORTS);
2346967dd82fSFlorian Fainelli 	if (!ds)
2347967dd82fSFlorian Fainelli 		return NULL;
2348967dd82fSFlorian Fainelli 
2349a0c02161SVivien Didelot 	dev = devm_kzalloc(base, sizeof(*dev), GFP_KERNEL);
2350a0c02161SVivien Didelot 	if (!dev)
2351a0c02161SVivien Didelot 		return NULL;
2352967dd82fSFlorian Fainelli 
2353967dd82fSFlorian Fainelli 	ds->priv = dev;
2354967dd82fSFlorian Fainelli 	dev->dev = base;
2355967dd82fSFlorian Fainelli 
2356967dd82fSFlorian Fainelli 	dev->ds = ds;
2357967dd82fSFlorian Fainelli 	dev->priv = priv;
2358967dd82fSFlorian Fainelli 	dev->ops = ops;
2359485ebd61SFlorian Fainelli 	ds->ops = &b53_switch_ops;
2360967dd82fSFlorian Fainelli 	mutex_init(&dev->reg_mutex);
2361967dd82fSFlorian Fainelli 	mutex_init(&dev->stats_mutex);
2362967dd82fSFlorian Fainelli 
2363967dd82fSFlorian Fainelli 	return dev;
2364967dd82fSFlorian Fainelli }
2365967dd82fSFlorian Fainelli EXPORT_SYMBOL(b53_switch_alloc);
2366967dd82fSFlorian Fainelli 
2367967dd82fSFlorian Fainelli int b53_switch_detect(struct b53_device *dev)
2368967dd82fSFlorian Fainelli {
2369967dd82fSFlorian Fainelli 	u32 id32;
2370967dd82fSFlorian Fainelli 	u16 tmp;
2371967dd82fSFlorian Fainelli 	u8 id8;
2372967dd82fSFlorian Fainelli 	int ret;
2373967dd82fSFlorian Fainelli 
2374967dd82fSFlorian Fainelli 	ret = b53_read8(dev, B53_MGMT_PAGE, B53_DEVICE_ID, &id8);
2375967dd82fSFlorian Fainelli 	if (ret)
2376967dd82fSFlorian Fainelli 		return ret;
2377967dd82fSFlorian Fainelli 
2378967dd82fSFlorian Fainelli 	switch (id8) {
2379967dd82fSFlorian Fainelli 	case 0:
2380967dd82fSFlorian Fainelli 		/* BCM5325 and BCM5365 do not have this register so reads
2381967dd82fSFlorian Fainelli 		 * return 0. But the read operation did succeed, so assume this
2382967dd82fSFlorian Fainelli 		 * is one of them.
2383967dd82fSFlorian Fainelli 		 *
2384967dd82fSFlorian Fainelli 		 * Next check if we can write to the 5325's VTA register; for
2385967dd82fSFlorian Fainelli 		 * 5365 it is read only.
2386967dd82fSFlorian Fainelli 		 */
2387967dd82fSFlorian Fainelli 		b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, 0xf);
2388967dd82fSFlorian Fainelli 		b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, &tmp);
2389967dd82fSFlorian Fainelli 
2390967dd82fSFlorian Fainelli 		if (tmp == 0xf)
2391967dd82fSFlorian Fainelli 			dev->chip_id = BCM5325_DEVICE_ID;
2392967dd82fSFlorian Fainelli 		else
2393967dd82fSFlorian Fainelli 			dev->chip_id = BCM5365_DEVICE_ID;
2394967dd82fSFlorian Fainelli 		break;
2395a95691bcSDamien Thébault 	case BCM5389_DEVICE_ID:
2396967dd82fSFlorian Fainelli 	case BCM5395_DEVICE_ID:
2397967dd82fSFlorian Fainelli 	case BCM5397_DEVICE_ID:
2398967dd82fSFlorian Fainelli 	case BCM5398_DEVICE_ID:
2399967dd82fSFlorian Fainelli 		dev->chip_id = id8;
2400967dd82fSFlorian Fainelli 		break;
2401967dd82fSFlorian Fainelli 	default:
2402967dd82fSFlorian Fainelli 		ret = b53_read32(dev, B53_MGMT_PAGE, B53_DEVICE_ID, &id32);
2403967dd82fSFlorian Fainelli 		if (ret)
2404967dd82fSFlorian Fainelli 			return ret;
2405967dd82fSFlorian Fainelli 
2406967dd82fSFlorian Fainelli 		switch (id32) {
2407967dd82fSFlorian Fainelli 		case BCM53115_DEVICE_ID:
2408967dd82fSFlorian Fainelli 		case BCM53125_DEVICE_ID:
2409967dd82fSFlorian Fainelli 		case BCM53128_DEVICE_ID:
2410967dd82fSFlorian Fainelli 		case BCM53010_DEVICE_ID:
2411967dd82fSFlorian Fainelli 		case BCM53011_DEVICE_ID:
2412967dd82fSFlorian Fainelli 		case BCM53012_DEVICE_ID:
2413967dd82fSFlorian Fainelli 		case BCM53018_DEVICE_ID:
2414967dd82fSFlorian Fainelli 		case BCM53019_DEVICE_ID:
2415967dd82fSFlorian Fainelli 			dev->chip_id = id32;
2416967dd82fSFlorian Fainelli 			break;
2417967dd82fSFlorian Fainelli 		default:
2418967dd82fSFlorian Fainelli 			pr_err("unsupported switch detected (BCM53%02x/BCM%x)\n",
2419967dd82fSFlorian Fainelli 			       id8, id32);
2420967dd82fSFlorian Fainelli 			return -ENODEV;
2421967dd82fSFlorian Fainelli 		}
2422967dd82fSFlorian Fainelli 	}
2423967dd82fSFlorian Fainelli 
2424967dd82fSFlorian Fainelli 	if (dev->chip_id == BCM5325_DEVICE_ID)
2425967dd82fSFlorian Fainelli 		return b53_read8(dev, B53_STAT_PAGE, B53_REV_ID_25,
2426967dd82fSFlorian Fainelli 				 &dev->core_rev);
2427967dd82fSFlorian Fainelli 	else
2428967dd82fSFlorian Fainelli 		return b53_read8(dev, B53_MGMT_PAGE, B53_REV_ID,
2429967dd82fSFlorian Fainelli 				 &dev->core_rev);
2430967dd82fSFlorian Fainelli }
2431967dd82fSFlorian Fainelli EXPORT_SYMBOL(b53_switch_detect);
2432967dd82fSFlorian Fainelli 
2433967dd82fSFlorian Fainelli int b53_switch_register(struct b53_device *dev)
2434967dd82fSFlorian Fainelli {
2435967dd82fSFlorian Fainelli 	int ret;
2436967dd82fSFlorian Fainelli 
2437967dd82fSFlorian Fainelli 	if (dev->pdata) {
2438967dd82fSFlorian Fainelli 		dev->chip_id = dev->pdata->chip_id;
2439967dd82fSFlorian Fainelli 		dev->enabled_ports = dev->pdata->enabled_ports;
2440967dd82fSFlorian Fainelli 	}
2441967dd82fSFlorian Fainelli 
2442967dd82fSFlorian Fainelli 	if (!dev->chip_id && b53_switch_detect(dev))
2443967dd82fSFlorian Fainelli 		return -EINVAL;
2444967dd82fSFlorian Fainelli 
2445967dd82fSFlorian Fainelli 	ret = b53_switch_init(dev);
2446967dd82fSFlorian Fainelli 	if (ret)
2447967dd82fSFlorian Fainelli 		return ret;
2448967dd82fSFlorian Fainelli 
2449967dd82fSFlorian Fainelli 	pr_info("found switch: %s, rev %i\n", dev->name, dev->core_rev);
2450967dd82fSFlorian Fainelli 
245123c9ee49SVivien Didelot 	return dsa_register_switch(dev->ds);
2452967dd82fSFlorian Fainelli }
2453967dd82fSFlorian Fainelli EXPORT_SYMBOL(b53_switch_register);
2454967dd82fSFlorian Fainelli 
2455967dd82fSFlorian Fainelli MODULE_AUTHOR("Jonas Gorski <jogo@openwrt.org>");
2456967dd82fSFlorian Fainelli MODULE_DESCRIPTION("B53 switch library");
2457967dd82fSFlorian Fainelli MODULE_LICENSE("Dual BSD/GPL");
2458