1967dd82fSFlorian Fainelli /*
2967dd82fSFlorian Fainelli * B53 switch driver main logic
3967dd82fSFlorian Fainelli *
4967dd82fSFlorian Fainelli * Copyright (C) 2011-2013 Jonas Gorski <jogo@openwrt.org>
5967dd82fSFlorian Fainelli * Copyright (C) 2016 Florian Fainelli <f.fainelli@gmail.com>
6967dd82fSFlorian Fainelli *
7967dd82fSFlorian Fainelli * Permission to use, copy, modify, and/or distribute this software for any
8967dd82fSFlorian Fainelli * purpose with or without fee is hereby granted, provided that the above
9967dd82fSFlorian Fainelli * copyright notice and this permission notice appear in all copies.
10967dd82fSFlorian Fainelli *
11967dd82fSFlorian Fainelli * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12967dd82fSFlorian Fainelli * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13967dd82fSFlorian Fainelli * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14967dd82fSFlorian Fainelli * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15967dd82fSFlorian Fainelli * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16967dd82fSFlorian Fainelli * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17967dd82fSFlorian Fainelli * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18967dd82fSFlorian Fainelli */
19967dd82fSFlorian Fainelli
20967dd82fSFlorian Fainelli #include <linux/delay.h>
21967dd82fSFlorian Fainelli #include <linux/export.h>
22967dd82fSFlorian Fainelli #include <linux/gpio.h>
23967dd82fSFlorian Fainelli #include <linux/kernel.h>
24967dd82fSFlorian Fainelli #include <linux/module.h>
25967dd82fSFlorian Fainelli #include <linux/platform_data/b53.h>
26967dd82fSFlorian Fainelli #include <linux/phy.h>
275e004460SFlorian Fainelli #include <linux/phylink.h>
281da6df85SFlorian Fainelli #include <linux/etherdevice.h>
29ff39c2d6SFlorian Fainelli #include <linux/if_bridge.h>
30bd1f41c3SJonas Gorski #include <linux/if_vlan.h>
31967dd82fSFlorian Fainelli #include <net/dsa.h>
32967dd82fSFlorian Fainelli
33967dd82fSFlorian Fainelli #include "b53_regs.h"
34967dd82fSFlorian Fainelli #include "b53_priv.h"
35967dd82fSFlorian Fainelli
36967dd82fSFlorian Fainelli struct b53_mib_desc {
37967dd82fSFlorian Fainelli u8 size;
38967dd82fSFlorian Fainelli u8 offset;
39967dd82fSFlorian Fainelli const char *name;
40967dd82fSFlorian Fainelli };
41967dd82fSFlorian Fainelli
42967dd82fSFlorian Fainelli /* BCM5365 MIB counters */
43967dd82fSFlorian Fainelli static const struct b53_mib_desc b53_mibs_65[] = {
44967dd82fSFlorian Fainelli { 8, 0x00, "TxOctets" },
45967dd82fSFlorian Fainelli { 4, 0x08, "TxDropPkts" },
46967dd82fSFlorian Fainelli { 4, 0x10, "TxBroadcastPkts" },
47967dd82fSFlorian Fainelli { 4, 0x14, "TxMulticastPkts" },
48967dd82fSFlorian Fainelli { 4, 0x18, "TxUnicastPkts" },
49967dd82fSFlorian Fainelli { 4, 0x1c, "TxCollisions" },
50967dd82fSFlorian Fainelli { 4, 0x20, "TxSingleCollision" },
51967dd82fSFlorian Fainelli { 4, 0x24, "TxMultipleCollision" },
52967dd82fSFlorian Fainelli { 4, 0x28, "TxDeferredTransmit" },
53967dd82fSFlorian Fainelli { 4, 0x2c, "TxLateCollision" },
54967dd82fSFlorian Fainelli { 4, 0x30, "TxExcessiveCollision" },
55967dd82fSFlorian Fainelli { 4, 0x38, "TxPausePkts" },
56967dd82fSFlorian Fainelli { 8, 0x44, "RxOctets" },
57967dd82fSFlorian Fainelli { 4, 0x4c, "RxUndersizePkts" },
58967dd82fSFlorian Fainelli { 4, 0x50, "RxPausePkts" },
59967dd82fSFlorian Fainelli { 4, 0x54, "Pkts64Octets" },
60967dd82fSFlorian Fainelli { 4, 0x58, "Pkts65to127Octets" },
61967dd82fSFlorian Fainelli { 4, 0x5c, "Pkts128to255Octets" },
62967dd82fSFlorian Fainelli { 4, 0x60, "Pkts256to511Octets" },
63967dd82fSFlorian Fainelli { 4, 0x64, "Pkts512to1023Octets" },
64967dd82fSFlorian Fainelli { 4, 0x68, "Pkts1024to1522Octets" },
65967dd82fSFlorian Fainelli { 4, 0x6c, "RxOversizePkts" },
66967dd82fSFlorian Fainelli { 4, 0x70, "RxJabbers" },
67967dd82fSFlorian Fainelli { 4, 0x74, "RxAlignmentErrors" },
68967dd82fSFlorian Fainelli { 4, 0x78, "RxFCSErrors" },
69967dd82fSFlorian Fainelli { 8, 0x7c, "RxGoodOctets" },
70967dd82fSFlorian Fainelli { 4, 0x84, "RxDropPkts" },
71967dd82fSFlorian Fainelli { 4, 0x88, "RxUnicastPkts" },
72967dd82fSFlorian Fainelli { 4, 0x8c, "RxMulticastPkts" },
73967dd82fSFlorian Fainelli { 4, 0x90, "RxBroadcastPkts" },
74967dd82fSFlorian Fainelli { 4, 0x94, "RxSAChanges" },
75967dd82fSFlorian Fainelli { 4, 0x98, "RxFragments" },
76967dd82fSFlorian Fainelli };
77967dd82fSFlorian Fainelli
78967dd82fSFlorian Fainelli #define B53_MIBS_65_SIZE ARRAY_SIZE(b53_mibs_65)
79967dd82fSFlorian Fainelli
80967dd82fSFlorian Fainelli /* BCM63xx MIB counters */
81967dd82fSFlorian Fainelli static const struct b53_mib_desc b53_mibs_63xx[] = {
82967dd82fSFlorian Fainelli { 8, 0x00, "TxOctets" },
83967dd82fSFlorian Fainelli { 4, 0x08, "TxDropPkts" },
84967dd82fSFlorian Fainelli { 4, 0x0c, "TxQoSPkts" },
85967dd82fSFlorian Fainelli { 4, 0x10, "TxBroadcastPkts" },
86967dd82fSFlorian Fainelli { 4, 0x14, "TxMulticastPkts" },
87967dd82fSFlorian Fainelli { 4, 0x18, "TxUnicastPkts" },
88967dd82fSFlorian Fainelli { 4, 0x1c, "TxCollisions" },
89967dd82fSFlorian Fainelli { 4, 0x20, "TxSingleCollision" },
90967dd82fSFlorian Fainelli { 4, 0x24, "TxMultipleCollision" },
91967dd82fSFlorian Fainelli { 4, 0x28, "TxDeferredTransmit" },
92967dd82fSFlorian Fainelli { 4, 0x2c, "TxLateCollision" },
93967dd82fSFlorian Fainelli { 4, 0x30, "TxExcessiveCollision" },
94967dd82fSFlorian Fainelli { 4, 0x38, "TxPausePkts" },
95967dd82fSFlorian Fainelli { 8, 0x3c, "TxQoSOctets" },
96967dd82fSFlorian Fainelli { 8, 0x44, "RxOctets" },
97967dd82fSFlorian Fainelli { 4, 0x4c, "RxUndersizePkts" },
98967dd82fSFlorian Fainelli { 4, 0x50, "RxPausePkts" },
99967dd82fSFlorian Fainelli { 4, 0x54, "Pkts64Octets" },
100967dd82fSFlorian Fainelli { 4, 0x58, "Pkts65to127Octets" },
101967dd82fSFlorian Fainelli { 4, 0x5c, "Pkts128to255Octets" },
102967dd82fSFlorian Fainelli { 4, 0x60, "Pkts256to511Octets" },
103967dd82fSFlorian Fainelli { 4, 0x64, "Pkts512to1023Octets" },
104967dd82fSFlorian Fainelli { 4, 0x68, "Pkts1024to1522Octets" },
105967dd82fSFlorian Fainelli { 4, 0x6c, "RxOversizePkts" },
106967dd82fSFlorian Fainelli { 4, 0x70, "RxJabbers" },
107967dd82fSFlorian Fainelli { 4, 0x74, "RxAlignmentErrors" },
108967dd82fSFlorian Fainelli { 4, 0x78, "RxFCSErrors" },
109967dd82fSFlorian Fainelli { 8, 0x7c, "RxGoodOctets" },
110967dd82fSFlorian Fainelli { 4, 0x84, "RxDropPkts" },
111967dd82fSFlorian Fainelli { 4, 0x88, "RxUnicastPkts" },
112967dd82fSFlorian Fainelli { 4, 0x8c, "RxMulticastPkts" },
113967dd82fSFlorian Fainelli { 4, 0x90, "RxBroadcastPkts" },
114967dd82fSFlorian Fainelli { 4, 0x94, "RxSAChanges" },
115967dd82fSFlorian Fainelli { 4, 0x98, "RxFragments" },
116967dd82fSFlorian Fainelli { 4, 0xa0, "RxSymbolErrors" },
117967dd82fSFlorian Fainelli { 4, 0xa4, "RxQoSPkts" },
118967dd82fSFlorian Fainelli { 8, 0xa8, "RxQoSOctets" },
119967dd82fSFlorian Fainelli { 4, 0xb0, "Pkts1523to2047Octets" },
120967dd82fSFlorian Fainelli { 4, 0xb4, "Pkts2048to4095Octets" },
121967dd82fSFlorian Fainelli { 4, 0xb8, "Pkts4096to8191Octets" },
122967dd82fSFlorian Fainelli { 4, 0xbc, "Pkts8192to9728Octets" },
123967dd82fSFlorian Fainelli { 4, 0xc0, "RxDiscarded" },
124967dd82fSFlorian Fainelli };
125967dd82fSFlorian Fainelli
126967dd82fSFlorian Fainelli #define B53_MIBS_63XX_SIZE ARRAY_SIZE(b53_mibs_63xx)
127967dd82fSFlorian Fainelli
128967dd82fSFlorian Fainelli /* MIB counters */
129967dd82fSFlorian Fainelli static const struct b53_mib_desc b53_mibs[] = {
130967dd82fSFlorian Fainelli { 8, 0x00, "TxOctets" },
131967dd82fSFlorian Fainelli { 4, 0x08, "TxDropPkts" },
132967dd82fSFlorian Fainelli { 4, 0x10, "TxBroadcastPkts" },
133967dd82fSFlorian Fainelli { 4, 0x14, "TxMulticastPkts" },
134967dd82fSFlorian Fainelli { 4, 0x18, "TxUnicastPkts" },
135967dd82fSFlorian Fainelli { 4, 0x1c, "TxCollisions" },
136967dd82fSFlorian Fainelli { 4, 0x20, "TxSingleCollision" },
137967dd82fSFlorian Fainelli { 4, 0x24, "TxMultipleCollision" },
138967dd82fSFlorian Fainelli { 4, 0x28, "TxDeferredTransmit" },
139967dd82fSFlorian Fainelli { 4, 0x2c, "TxLateCollision" },
140967dd82fSFlorian Fainelli { 4, 0x30, "TxExcessiveCollision" },
141967dd82fSFlorian Fainelli { 4, 0x38, "TxPausePkts" },
142967dd82fSFlorian Fainelli { 8, 0x50, "RxOctets" },
143967dd82fSFlorian Fainelli { 4, 0x58, "RxUndersizePkts" },
144967dd82fSFlorian Fainelli { 4, 0x5c, "RxPausePkts" },
145967dd82fSFlorian Fainelli { 4, 0x60, "Pkts64Octets" },
146967dd82fSFlorian Fainelli { 4, 0x64, "Pkts65to127Octets" },
147967dd82fSFlorian Fainelli { 4, 0x68, "Pkts128to255Octets" },
148967dd82fSFlorian Fainelli { 4, 0x6c, "Pkts256to511Octets" },
149967dd82fSFlorian Fainelli { 4, 0x70, "Pkts512to1023Octets" },
150967dd82fSFlorian Fainelli { 4, 0x74, "Pkts1024to1522Octets" },
151967dd82fSFlorian Fainelli { 4, 0x78, "RxOversizePkts" },
152967dd82fSFlorian Fainelli { 4, 0x7c, "RxJabbers" },
153967dd82fSFlorian Fainelli { 4, 0x80, "RxAlignmentErrors" },
154967dd82fSFlorian Fainelli { 4, 0x84, "RxFCSErrors" },
155967dd82fSFlorian Fainelli { 8, 0x88, "RxGoodOctets" },
156967dd82fSFlorian Fainelli { 4, 0x90, "RxDropPkts" },
157967dd82fSFlorian Fainelli { 4, 0x94, "RxUnicastPkts" },
158967dd82fSFlorian Fainelli { 4, 0x98, "RxMulticastPkts" },
159967dd82fSFlorian Fainelli { 4, 0x9c, "RxBroadcastPkts" },
160967dd82fSFlorian Fainelli { 4, 0xa0, "RxSAChanges" },
161967dd82fSFlorian Fainelli { 4, 0xa4, "RxFragments" },
162967dd82fSFlorian Fainelli { 4, 0xa8, "RxJumboPkts" },
163967dd82fSFlorian Fainelli { 4, 0xac, "RxSymbolErrors" },
164967dd82fSFlorian Fainelli { 4, 0xc0, "RxDiscarded" },
165967dd82fSFlorian Fainelli };
166967dd82fSFlorian Fainelli
167967dd82fSFlorian Fainelli #define B53_MIBS_SIZE ARRAY_SIZE(b53_mibs)
168967dd82fSFlorian Fainelli
169bde5d132SFlorian Fainelli static const struct b53_mib_desc b53_mibs_58xx[] = {
170bde5d132SFlorian Fainelli { 8, 0x00, "TxOctets" },
171bde5d132SFlorian Fainelli { 4, 0x08, "TxDropPkts" },
172bde5d132SFlorian Fainelli { 4, 0x0c, "TxQPKTQ0" },
173bde5d132SFlorian Fainelli { 4, 0x10, "TxBroadcastPkts" },
174bde5d132SFlorian Fainelli { 4, 0x14, "TxMulticastPkts" },
175bde5d132SFlorian Fainelli { 4, 0x18, "TxUnicastPKts" },
176bde5d132SFlorian Fainelli { 4, 0x1c, "TxCollisions" },
177bde5d132SFlorian Fainelli { 4, 0x20, "TxSingleCollision" },
178bde5d132SFlorian Fainelli { 4, 0x24, "TxMultipleCollision" },
179bde5d132SFlorian Fainelli { 4, 0x28, "TxDeferredCollision" },
180bde5d132SFlorian Fainelli { 4, 0x2c, "TxLateCollision" },
181bde5d132SFlorian Fainelli { 4, 0x30, "TxExcessiveCollision" },
182bde5d132SFlorian Fainelli { 4, 0x34, "TxFrameInDisc" },
183bde5d132SFlorian Fainelli { 4, 0x38, "TxPausePkts" },
184bde5d132SFlorian Fainelli { 4, 0x3c, "TxQPKTQ1" },
185bde5d132SFlorian Fainelli { 4, 0x40, "TxQPKTQ2" },
186bde5d132SFlorian Fainelli { 4, 0x44, "TxQPKTQ3" },
187bde5d132SFlorian Fainelli { 4, 0x48, "TxQPKTQ4" },
188bde5d132SFlorian Fainelli { 4, 0x4c, "TxQPKTQ5" },
189bde5d132SFlorian Fainelli { 8, 0x50, "RxOctets" },
190bde5d132SFlorian Fainelli { 4, 0x58, "RxUndersizePkts" },
191bde5d132SFlorian Fainelli { 4, 0x5c, "RxPausePkts" },
192bde5d132SFlorian Fainelli { 4, 0x60, "RxPkts64Octets" },
193bde5d132SFlorian Fainelli { 4, 0x64, "RxPkts65to127Octets" },
194bde5d132SFlorian Fainelli { 4, 0x68, "RxPkts128to255Octets" },
195bde5d132SFlorian Fainelli { 4, 0x6c, "RxPkts256to511Octets" },
196bde5d132SFlorian Fainelli { 4, 0x70, "RxPkts512to1023Octets" },
197bde5d132SFlorian Fainelli { 4, 0x74, "RxPkts1024toMaxPktsOctets" },
198bde5d132SFlorian Fainelli { 4, 0x78, "RxOversizePkts" },
199bde5d132SFlorian Fainelli { 4, 0x7c, "RxJabbers" },
200bde5d132SFlorian Fainelli { 4, 0x80, "RxAlignmentErrors" },
201bde5d132SFlorian Fainelli { 4, 0x84, "RxFCSErrors" },
202bde5d132SFlorian Fainelli { 8, 0x88, "RxGoodOctets" },
203bde5d132SFlorian Fainelli { 4, 0x90, "RxDropPkts" },
204bde5d132SFlorian Fainelli { 4, 0x94, "RxUnicastPkts" },
205bde5d132SFlorian Fainelli { 4, 0x98, "RxMulticastPkts" },
206bde5d132SFlorian Fainelli { 4, 0x9c, "RxBroadcastPkts" },
207bde5d132SFlorian Fainelli { 4, 0xa0, "RxSAChanges" },
208bde5d132SFlorian Fainelli { 4, 0xa4, "RxFragments" },
209bde5d132SFlorian Fainelli { 4, 0xa8, "RxJumboPkt" },
210bde5d132SFlorian Fainelli { 4, 0xac, "RxSymblErr" },
211bde5d132SFlorian Fainelli { 4, 0xb0, "InRangeErrCount" },
212bde5d132SFlorian Fainelli { 4, 0xb4, "OutRangeErrCount" },
213bde5d132SFlorian Fainelli { 4, 0xb8, "EEELpiEvent" },
214bde5d132SFlorian Fainelli { 4, 0xbc, "EEELpiDuration" },
215bde5d132SFlorian Fainelli { 4, 0xc0, "RxDiscard" },
216bde5d132SFlorian Fainelli { 4, 0xc8, "TxQPKTQ6" },
217bde5d132SFlorian Fainelli { 4, 0xcc, "TxQPKTQ7" },
218bde5d132SFlorian Fainelli { 4, 0xd0, "TxPkts64Octets" },
219bde5d132SFlorian Fainelli { 4, 0xd4, "TxPkts65to127Octets" },
220bde5d132SFlorian Fainelli { 4, 0xd8, "TxPkts128to255Octets" },
221bde5d132SFlorian Fainelli { 4, 0xdc, "TxPkts256to511Ocets" },
222bde5d132SFlorian Fainelli { 4, 0xe0, "TxPkts512to1023Ocets" },
223bde5d132SFlorian Fainelli { 4, 0xe4, "TxPkts1024toMaxPktOcets" },
224bde5d132SFlorian Fainelli };
225bde5d132SFlorian Fainelli
226bde5d132SFlorian Fainelli #define B53_MIBS_58XX_SIZE ARRAY_SIZE(b53_mibs_58xx)
227bde5d132SFlorian Fainelli
22894c4cb9bSJonas Gorski #define B53_MAX_MTU_25 (1536 - ETH_HLEN - VLAN_HLEN - ETH_FCS_LEN)
229bd1f41c3SJonas Gorski #define B53_MAX_MTU (9720 - ETH_HLEN - VLAN_HLEN - ETH_FCS_LEN)
230bd1f41c3SJonas Gorski
b53_do_vlan_op(struct b53_device * dev,u8 op)231967dd82fSFlorian Fainelli static int b53_do_vlan_op(struct b53_device *dev, u8 op)
232967dd82fSFlorian Fainelli {
233967dd82fSFlorian Fainelli unsigned int i;
234967dd82fSFlorian Fainelli
235967dd82fSFlorian Fainelli b53_write8(dev, B53_ARLIO_PAGE, dev->vta_regs[0], VTA_START_CMD | op);
236967dd82fSFlorian Fainelli
237967dd82fSFlorian Fainelli for (i = 0; i < 10; i++) {
238967dd82fSFlorian Fainelli u8 vta;
239967dd82fSFlorian Fainelli
240967dd82fSFlorian Fainelli b53_read8(dev, B53_ARLIO_PAGE, dev->vta_regs[0], &vta);
241967dd82fSFlorian Fainelli if (!(vta & VTA_START_CMD))
242967dd82fSFlorian Fainelli return 0;
243967dd82fSFlorian Fainelli
244967dd82fSFlorian Fainelli usleep_range(100, 200);
245967dd82fSFlorian Fainelli }
246967dd82fSFlorian Fainelli
247967dd82fSFlorian Fainelli return -EIO;
248967dd82fSFlorian Fainelli }
249967dd82fSFlorian Fainelli
b53_set_vlan_entry(struct b53_device * dev,u16 vid,struct b53_vlan * vlan)250a2482d2cSFlorian Fainelli static void b53_set_vlan_entry(struct b53_device *dev, u16 vid,
251a2482d2cSFlorian Fainelli struct b53_vlan *vlan)
252967dd82fSFlorian Fainelli {
253967dd82fSFlorian Fainelli if (is5325(dev)) {
254967dd82fSFlorian Fainelli u32 entry = 0;
255967dd82fSFlorian Fainelli
256a2482d2cSFlorian Fainelli if (vlan->members) {
257a2482d2cSFlorian Fainelli entry = ((vlan->untag & VA_UNTAG_MASK_25) <<
258a2482d2cSFlorian Fainelli VA_UNTAG_S_25) | vlan->members;
259967dd82fSFlorian Fainelli if (dev->core_rev >= 3)
260967dd82fSFlorian Fainelli entry |= VA_VALID_25_R4 | vid << VA_VID_HIGH_S;
261967dd82fSFlorian Fainelli else
262967dd82fSFlorian Fainelli entry |= VA_VALID_25;
263967dd82fSFlorian Fainelli }
264967dd82fSFlorian Fainelli
265967dd82fSFlorian Fainelli b53_write32(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_25, entry);
266967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, vid |
267967dd82fSFlorian Fainelli VTA_RW_STATE_WR | VTA_RW_OP_EN);
268967dd82fSFlorian Fainelli } else if (is5365(dev)) {
269967dd82fSFlorian Fainelli u16 entry = 0;
270967dd82fSFlorian Fainelli
271a2482d2cSFlorian Fainelli if (vlan->members)
272a2482d2cSFlorian Fainelli entry = ((vlan->untag & VA_UNTAG_MASK_65) <<
273a2482d2cSFlorian Fainelli VA_UNTAG_S_65) | vlan->members | VA_VALID_65;
274967dd82fSFlorian Fainelli
275967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_65, entry);
276967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_65, vid |
277967dd82fSFlorian Fainelli VTA_RW_STATE_WR | VTA_RW_OP_EN);
278967dd82fSFlorian Fainelli } else {
279967dd82fSFlorian Fainelli b53_write16(dev, B53_ARLIO_PAGE, dev->vta_regs[1], vid);
280967dd82fSFlorian Fainelli b53_write32(dev, B53_ARLIO_PAGE, dev->vta_regs[2],
281a2482d2cSFlorian Fainelli (vlan->untag << VTE_UNTAG_S) | vlan->members);
282967dd82fSFlorian Fainelli
283967dd82fSFlorian Fainelli b53_do_vlan_op(dev, VTA_CMD_WRITE);
284967dd82fSFlorian Fainelli }
285a2482d2cSFlorian Fainelli
286a2482d2cSFlorian Fainelli dev_dbg(dev->ds->dev, "VID: %d, members: 0x%04x, untag: 0x%04x\n",
287a2482d2cSFlorian Fainelli vid, vlan->members, vlan->untag);
288967dd82fSFlorian Fainelli }
289967dd82fSFlorian Fainelli
b53_get_vlan_entry(struct b53_device * dev,u16 vid,struct b53_vlan * vlan)290a2482d2cSFlorian Fainelli static void b53_get_vlan_entry(struct b53_device *dev, u16 vid,
291a2482d2cSFlorian Fainelli struct b53_vlan *vlan)
292a2482d2cSFlorian Fainelli {
293a2482d2cSFlorian Fainelli if (is5325(dev)) {
294a2482d2cSFlorian Fainelli u32 entry = 0;
295a2482d2cSFlorian Fainelli
296a2482d2cSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, vid |
297a2482d2cSFlorian Fainelli VTA_RW_STATE_RD | VTA_RW_OP_EN);
298a2482d2cSFlorian Fainelli b53_read32(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_25, &entry);
299a2482d2cSFlorian Fainelli
300a2482d2cSFlorian Fainelli if (dev->core_rev >= 3)
301a2482d2cSFlorian Fainelli vlan->valid = !!(entry & VA_VALID_25_R4);
302a2482d2cSFlorian Fainelli else
303a2482d2cSFlorian Fainelli vlan->valid = !!(entry & VA_VALID_25);
304a2482d2cSFlorian Fainelli vlan->members = entry & VA_MEMBER_MASK;
305a2482d2cSFlorian Fainelli vlan->untag = (entry >> VA_UNTAG_S_25) & VA_UNTAG_MASK_25;
306a2482d2cSFlorian Fainelli
307a2482d2cSFlorian Fainelli } else if (is5365(dev)) {
308a2482d2cSFlorian Fainelli u16 entry = 0;
309a2482d2cSFlorian Fainelli
310a2482d2cSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_65, vid |
311a2482d2cSFlorian Fainelli VTA_RW_STATE_WR | VTA_RW_OP_EN);
312a2482d2cSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_65, &entry);
313a2482d2cSFlorian Fainelli
314a2482d2cSFlorian Fainelli vlan->valid = !!(entry & VA_VALID_65);
315a2482d2cSFlorian Fainelli vlan->members = entry & VA_MEMBER_MASK;
316a2482d2cSFlorian Fainelli vlan->untag = (entry >> VA_UNTAG_S_65) & VA_UNTAG_MASK_65;
317a2482d2cSFlorian Fainelli } else {
318a2482d2cSFlorian Fainelli u32 entry = 0;
319a2482d2cSFlorian Fainelli
320a2482d2cSFlorian Fainelli b53_write16(dev, B53_ARLIO_PAGE, dev->vta_regs[1], vid);
321a2482d2cSFlorian Fainelli b53_do_vlan_op(dev, VTA_CMD_READ);
322a2482d2cSFlorian Fainelli b53_read32(dev, B53_ARLIO_PAGE, dev->vta_regs[2], &entry);
323a2482d2cSFlorian Fainelli vlan->members = entry & VTE_MEMBERS;
324a2482d2cSFlorian Fainelli vlan->untag = (entry >> VTE_UNTAG_S) & VTE_MEMBERS;
325a2482d2cSFlorian Fainelli vlan->valid = true;
326a2482d2cSFlorian Fainelli }
327a2482d2cSFlorian Fainelli }
328a2482d2cSFlorian Fainelli
b53_set_forwarding(struct b53_device * dev,int enable)329a2482d2cSFlorian Fainelli static void b53_set_forwarding(struct b53_device *dev, int enable)
330967dd82fSFlorian Fainelli {
331967dd82fSFlorian Fainelli u8 mgmt;
332967dd82fSFlorian Fainelli
333967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt);
334967dd82fSFlorian Fainelli
335967dd82fSFlorian Fainelli if (enable)
336967dd82fSFlorian Fainelli mgmt |= SM_SW_FWD_EN;
337967dd82fSFlorian Fainelli else
338967dd82fSFlorian Fainelli mgmt &= ~SM_SW_FWD_EN;
339967dd82fSFlorian Fainelli
340967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt);
341a424f0deSFlorian Fainelli
3427edc58d6SFlorian Fainelli /* Include IMP port in dumb forwarding mode
343a424f0deSFlorian Fainelli */
344a424f0deSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_CTRL, &mgmt);
345a424f0deSFlorian Fainelli mgmt |= B53_MII_DUMB_FWDG_EN;
346a424f0deSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_CTRL, mgmt);
34753568438SFlorian Fainelli
34853568438SFlorian Fainelli /* Look at B53_UC_FWD_EN and B53_MC_FWD_EN to decide whether
34953568438SFlorian Fainelli * frames should be flooded or not.
35053568438SFlorian Fainelli */
35153568438SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_IP_MULTICAST_CTRL, &mgmt);
35263cc54a6SFlorian Fainelli mgmt |= B53_UC_FWD_EN | B53_MC_FWD_EN | B53_IPMC_FWD_EN;
35353568438SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_IP_MULTICAST_CTRL, mgmt);
354a424f0deSFlorian Fainelli }
355967dd82fSFlorian Fainelli
b53_enable_vlan(struct b53_device * dev,int port,bool enable,bool enable_filtering)356ee47ed08SFlorian Fainelli static void b53_enable_vlan(struct b53_device *dev, int port, bool enable,
357dad8d7c6SFlorian Fainelli bool enable_filtering)
358967dd82fSFlorian Fainelli {
359967dd82fSFlorian Fainelli u8 mgmt, vc0, vc1, vc4 = 0, vc5;
360967dd82fSFlorian Fainelli
361967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt);
362967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL0, &vc0);
363967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL1, &vc1);
364967dd82fSFlorian Fainelli
365967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) {
366967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, &vc4);
367967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_25, &vc5);
368967dd82fSFlorian Fainelli } else if (is63xx(dev)) {
369967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_63XX, &vc4);
370967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_63XX, &vc5);
371967dd82fSFlorian Fainelli } else {
372967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4, &vc4);
373967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5, &vc5);
374967dd82fSFlorian Fainelli }
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;
438ee47ed08SFlorian Fainelli
439ee47ed08SFlorian Fainelli dev_dbg(dev->dev, "Port %d VLAN enabled: %d, filtering: %d\n",
440ee47ed08SFlorian Fainelli port, enable, enable_filtering);
441967dd82fSFlorian Fainelli }
442967dd82fSFlorian Fainelli
b53_set_jumbo(struct b53_device * dev,bool enable,bool allow_10_100)443967dd82fSFlorian Fainelli static int b53_set_jumbo(struct b53_device *dev, bool enable, bool allow_10_100)
444967dd82fSFlorian Fainelli {
445967dd82fSFlorian Fainelli u32 port_mask = 0;
446967dd82fSFlorian Fainelli u16 max_size = JMS_MIN_SIZE;
447967dd82fSFlorian Fainelli
448967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev))
449967dd82fSFlorian Fainelli return -EINVAL;
450967dd82fSFlorian Fainelli
451967dd82fSFlorian Fainelli if (enable) {
452967dd82fSFlorian Fainelli port_mask = dev->enabled_ports;
453967dd82fSFlorian Fainelli max_size = JMS_MAX_SIZE;
454967dd82fSFlorian Fainelli if (allow_10_100)
455967dd82fSFlorian Fainelli port_mask |= JPM_10_100_JUMBO_EN;
456967dd82fSFlorian Fainelli }
457967dd82fSFlorian Fainelli
458967dd82fSFlorian Fainelli b53_write32(dev, B53_JUMBO_PAGE, dev->jumbo_pm_reg, port_mask);
459967dd82fSFlorian Fainelli return b53_write16(dev, B53_JUMBO_PAGE, dev->jumbo_size_reg, max_size);
460967dd82fSFlorian Fainelli }
461967dd82fSFlorian Fainelli
b53_flush_arl(struct b53_device * dev,u8 mask)462ff39c2d6SFlorian Fainelli static int b53_flush_arl(struct b53_device *dev, u8 mask)
463967dd82fSFlorian Fainelli {
464967dd82fSFlorian Fainelli unsigned int i;
465967dd82fSFlorian Fainelli
466967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL,
467ff39c2d6SFlorian Fainelli FAST_AGE_DONE | FAST_AGE_DYNAMIC | mask);
468967dd82fSFlorian Fainelli
469967dd82fSFlorian Fainelli for (i = 0; i < 10; i++) {
470967dd82fSFlorian Fainelli u8 fast_age_ctrl;
471967dd82fSFlorian Fainelli
472967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL,
473967dd82fSFlorian Fainelli &fast_age_ctrl);
474967dd82fSFlorian Fainelli
475967dd82fSFlorian Fainelli if (!(fast_age_ctrl & FAST_AGE_DONE))
476967dd82fSFlorian Fainelli goto out;
477967dd82fSFlorian Fainelli
478967dd82fSFlorian Fainelli msleep(1);
479967dd82fSFlorian Fainelli }
480967dd82fSFlorian Fainelli
481967dd82fSFlorian Fainelli return -ETIMEDOUT;
482967dd82fSFlorian Fainelli out:
483967dd82fSFlorian Fainelli /* Only age dynamic entries (default behavior) */
484967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL, FAST_AGE_DYNAMIC);
485967dd82fSFlorian Fainelli return 0;
486967dd82fSFlorian Fainelli }
487967dd82fSFlorian Fainelli
b53_fast_age_port(struct b53_device * dev,int port)488ff39c2d6SFlorian Fainelli static int b53_fast_age_port(struct b53_device *dev, int port)
489ff39c2d6SFlorian Fainelli {
490ff39c2d6SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_PORT_CTRL, port);
491ff39c2d6SFlorian Fainelli
492ff39c2d6SFlorian Fainelli return b53_flush_arl(dev, FAST_AGE_PORT);
493ff39c2d6SFlorian Fainelli }
494ff39c2d6SFlorian Fainelli
b53_fast_age_vlan(struct b53_device * dev,u16 vid)495a2482d2cSFlorian Fainelli static int b53_fast_age_vlan(struct b53_device *dev, u16 vid)
496a2482d2cSFlorian Fainelli {
497a2482d2cSFlorian Fainelli b53_write16(dev, B53_CTRL_PAGE, B53_FAST_AGE_VID_CTRL, vid);
498a2482d2cSFlorian Fainelli
499a2482d2cSFlorian Fainelli return b53_flush_arl(dev, FAST_AGE_VLAN);
500a2482d2cSFlorian Fainelli }
501a2482d2cSFlorian Fainelli
b53_imp_vlan_setup(struct dsa_switch * ds,int cpu_port)502aac02867SFlorian Fainelli void b53_imp_vlan_setup(struct dsa_switch *ds, int cpu_port)
503ff39c2d6SFlorian Fainelli {
50404bed143SVivien Didelot struct b53_device *dev = ds->priv;
505ff39c2d6SFlorian Fainelli unsigned int i;
506ff39c2d6SFlorian Fainelli u16 pvlan;
507ff39c2d6SFlorian Fainelli
508ff39c2d6SFlorian Fainelli /* Enable the IMP port to be in the same VLAN as the other ports
509ff39c2d6SFlorian Fainelli * on a per-port basis such that we only have Port i and IMP in
510ff39c2d6SFlorian Fainelli * the same VLAN.
511ff39c2d6SFlorian Fainelli */
512ff39c2d6SFlorian Fainelli b53_for_each_port(dev, i) {
513ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), &pvlan);
514ff39c2d6SFlorian Fainelli pvlan |= BIT(cpu_port);
515ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), pvlan);
516ff39c2d6SFlorian Fainelli }
517ff39c2d6SFlorian Fainelli }
518aac02867SFlorian Fainelli EXPORT_SYMBOL(b53_imp_vlan_setup);
519ff39c2d6SFlorian Fainelli
b53_port_set_ucast_flood(struct b53_device * dev,int port,bool unicast)520a8b659e7SVladimir Oltean static void b53_port_set_ucast_flood(struct b53_device *dev, int port,
521a8b659e7SVladimir Oltean bool unicast)
522a8b659e7SVladimir Oltean {
523a8b659e7SVladimir Oltean u16 uc;
524a8b659e7SVladimir Oltean
525a8b659e7SVladimir Oltean b53_read16(dev, B53_CTRL_PAGE, B53_UC_FLOOD_MASK, &uc);
526a8b659e7SVladimir Oltean if (unicast)
527a8b659e7SVladimir Oltean uc |= BIT(port);
528a8b659e7SVladimir Oltean else
529a8b659e7SVladimir Oltean uc &= ~BIT(port);
530a8b659e7SVladimir Oltean b53_write16(dev, B53_CTRL_PAGE, B53_UC_FLOOD_MASK, uc);
531a8b659e7SVladimir Oltean }
532a8b659e7SVladimir Oltean
b53_port_set_mcast_flood(struct b53_device * dev,int port,bool multicast)533a8b659e7SVladimir Oltean static void b53_port_set_mcast_flood(struct b53_device *dev, int port,
534a8b659e7SVladimir Oltean bool multicast)
535a8b659e7SVladimir Oltean {
536a8b659e7SVladimir Oltean u16 mc;
537a8b659e7SVladimir Oltean
538a8b659e7SVladimir Oltean b53_read16(dev, B53_CTRL_PAGE, B53_MC_FLOOD_MASK, &mc);
539a8b659e7SVladimir Oltean if (multicast)
540a8b659e7SVladimir Oltean mc |= BIT(port);
541a8b659e7SVladimir Oltean else
542a8b659e7SVladimir Oltean mc &= ~BIT(port);
543a8b659e7SVladimir Oltean b53_write16(dev, B53_CTRL_PAGE, B53_MC_FLOOD_MASK, mc);
544a8b659e7SVladimir Oltean
545a8b659e7SVladimir Oltean b53_read16(dev, B53_CTRL_PAGE, B53_IPMC_FLOOD_MASK, &mc);
546a8b659e7SVladimir Oltean if (multicast)
547a8b659e7SVladimir Oltean mc |= BIT(port);
548a8b659e7SVladimir Oltean else
549a8b659e7SVladimir Oltean mc &= ~BIT(port);
550a8b659e7SVladimir Oltean b53_write16(dev, B53_CTRL_PAGE, B53_IPMC_FLOOD_MASK, mc);
551a8b659e7SVladimir Oltean }
552a8b659e7SVladimir Oltean
b53_port_set_learning(struct b53_device * dev,int port,bool learning)553f9b3827eSFlorian Fainelli static void b53_port_set_learning(struct b53_device *dev, int port,
554f9b3827eSFlorian Fainelli bool learning)
555f9b3827eSFlorian Fainelli {
556f9b3827eSFlorian Fainelli u16 reg;
557f9b3827eSFlorian Fainelli
558f9b3827eSFlorian Fainelli b53_read16(dev, B53_CTRL_PAGE, B53_DIS_LEARNING, ®);
559f9b3827eSFlorian Fainelli if (learning)
560f9b3827eSFlorian Fainelli reg &= ~BIT(port);
561f9b3827eSFlorian Fainelli else
562f9b3827eSFlorian Fainelli reg |= BIT(port);
563f9b3827eSFlorian Fainelli b53_write16(dev, B53_CTRL_PAGE, B53_DIS_LEARNING, reg);
564f9b3827eSFlorian Fainelli }
565f9b3827eSFlorian Fainelli
b53_enable_port(struct dsa_switch * ds,int port,struct phy_device * phy)566f86ad77fSFlorian Fainelli int b53_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy)
567967dd82fSFlorian Fainelli {
56804bed143SVivien Didelot struct b53_device *dev = ds->priv;
56974be4babSVivien Didelot unsigned int cpu_port;
5708ca7c160SFlorian Fainelli int ret = 0;
571ff39c2d6SFlorian Fainelli u16 pvlan;
572967dd82fSFlorian Fainelli
57374be4babSVivien Didelot if (!dsa_is_user_port(ds, port))
57474be4babSVivien Didelot return 0;
57574be4babSVivien Didelot
57668bb8ea8SVivien Didelot cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
57774be4babSVivien Didelot
578a8b659e7SVladimir Oltean b53_port_set_ucast_flood(dev, port, true);
579a8b659e7SVladimir Oltean b53_port_set_mcast_flood(dev, port, true);
580f9b3827eSFlorian Fainelli b53_port_set_learning(dev, port, false);
58163cc54a6SFlorian Fainelli
5828ca7c160SFlorian Fainelli if (dev->ops->irq_enable)
5838ca7c160SFlorian Fainelli ret = dev->ops->irq_enable(dev, port);
5848ca7c160SFlorian Fainelli if (ret)
5858ca7c160SFlorian Fainelli return ret;
5868ca7c160SFlorian Fainelli
587967dd82fSFlorian Fainelli /* Clear the Rx and Tx disable bits and set to no spanning tree */
588967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), 0);
589967dd82fSFlorian Fainelli
590ff39c2d6SFlorian Fainelli /* Set this port, and only this one to be in the default VLAN,
591ff39c2d6SFlorian Fainelli * if member of a bridge, restore its membership prior to
592ff39c2d6SFlorian Fainelli * bringing down this port.
593ff39c2d6SFlorian Fainelli */
594ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan);
595ff39c2d6SFlorian Fainelli pvlan &= ~0x1ff;
596ff39c2d6SFlorian Fainelli pvlan |= BIT(port);
597ff39c2d6SFlorian Fainelli pvlan |= dev->ports[port].vlan_ctl_mask;
598ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan);
599ff39c2d6SFlorian Fainelli
600ff39c2d6SFlorian Fainelli b53_imp_vlan_setup(ds, cpu_port);
601ff39c2d6SFlorian Fainelli
602f43a2dbeSFlorian Fainelli /* If EEE was enabled, restore it */
603f43a2dbeSFlorian Fainelli if (dev->ports[port].eee.eee_enabled)
604f43a2dbeSFlorian Fainelli b53_eee_enable_set(ds, port, true);
605f43a2dbeSFlorian Fainelli
606967dd82fSFlorian Fainelli return 0;
607967dd82fSFlorian Fainelli }
608f86ad77fSFlorian Fainelli EXPORT_SYMBOL(b53_enable_port);
609967dd82fSFlorian Fainelli
b53_disable_port(struct dsa_switch * ds,int port)61075104db0SAndrew Lunn void b53_disable_port(struct dsa_switch *ds, int port)
611967dd82fSFlorian Fainelli {
61204bed143SVivien Didelot struct b53_device *dev = ds->priv;
613967dd82fSFlorian Fainelli u8 reg;
614967dd82fSFlorian Fainelli
615967dd82fSFlorian Fainelli /* Disable Tx/Rx for the port */
616967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), ®);
617967dd82fSFlorian Fainelli reg |= PORT_CTRL_RX_DISABLE | PORT_CTRL_TX_DISABLE;
618967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), reg);
6198ca7c160SFlorian Fainelli
6208ca7c160SFlorian Fainelli if (dev->ops->irq_disable)
6218ca7c160SFlorian Fainelli dev->ops->irq_disable(dev, port);
622967dd82fSFlorian Fainelli }
623f86ad77fSFlorian Fainelli EXPORT_SYMBOL(b53_disable_port);
624967dd82fSFlorian Fainelli
b53_brcm_hdr_setup(struct dsa_switch * ds,int port)625b409a9efSFlorian Fainelli void b53_brcm_hdr_setup(struct dsa_switch *ds, int port)
626b409a9efSFlorian Fainelli {
627b409a9efSFlorian Fainelli struct b53_device *dev = ds->priv;
6284d776482SFlorian Fainelli bool tag_en = !(dev->tag_protocol == DSA_TAG_PROTO_NONE);
629b409a9efSFlorian Fainelli u8 hdr_ctl, val;
630b409a9efSFlorian Fainelli u16 reg;
631b409a9efSFlorian Fainelli
632b409a9efSFlorian Fainelli /* Resolve which bit controls the Broadcom tag */
633b409a9efSFlorian Fainelli switch (port) {
634b409a9efSFlorian Fainelli case 8:
635b409a9efSFlorian Fainelli val = BRCM_HDR_P8_EN;
636b409a9efSFlorian Fainelli break;
637b409a9efSFlorian Fainelli case 7:
638b409a9efSFlorian Fainelli val = BRCM_HDR_P7_EN;
639b409a9efSFlorian Fainelli break;
640b409a9efSFlorian Fainelli case 5:
641b409a9efSFlorian Fainelli val = BRCM_HDR_P5_EN;
642b409a9efSFlorian Fainelli break;
643b409a9efSFlorian Fainelli default:
644b409a9efSFlorian Fainelli val = 0;
645b409a9efSFlorian Fainelli break;
646b409a9efSFlorian Fainelli }
647b409a9efSFlorian Fainelli
6488fab459eSFlorian Fainelli /* Enable management mode if tagging is requested */
6498fab459eSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &hdr_ctl);
6508fab459eSFlorian Fainelli if (tag_en)
6518fab459eSFlorian Fainelli hdr_ctl |= SM_SW_FWD_MODE;
6528fab459eSFlorian Fainelli else
6538fab459eSFlorian Fainelli hdr_ctl &= ~SM_SW_FWD_MODE;
6548fab459eSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, hdr_ctl);
6558fab459eSFlorian Fainelli
6568fab459eSFlorian Fainelli /* Configure the appropriate IMP port */
6578fab459eSFlorian Fainelli b53_read8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &hdr_ctl);
6588fab459eSFlorian Fainelli if (port == 8)
6598fab459eSFlorian Fainelli hdr_ctl |= GC_FRM_MGMT_PORT_MII;
6608fab459eSFlorian Fainelli else if (port == 5)
6618fab459eSFlorian Fainelli hdr_ctl |= GC_FRM_MGMT_PORT_M;
6628fab459eSFlorian Fainelli b53_write8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, hdr_ctl);
6638fab459eSFlorian Fainelli
664b409a9efSFlorian Fainelli /* Enable Broadcom tags for IMP port */
665b409a9efSFlorian Fainelli b53_read8(dev, B53_MGMT_PAGE, B53_BRCM_HDR, &hdr_ctl);
666cdb583cfSFlorian Fainelli if (tag_en)
667b409a9efSFlorian Fainelli hdr_ctl |= val;
668cdb583cfSFlorian Fainelli else
669cdb583cfSFlorian Fainelli hdr_ctl &= ~val;
670b409a9efSFlorian Fainelli b53_write8(dev, B53_MGMT_PAGE, B53_BRCM_HDR, hdr_ctl);
671b409a9efSFlorian Fainelli
672b409a9efSFlorian Fainelli /* Registers below are only accessible on newer devices */
673b409a9efSFlorian Fainelli if (!is58xx(dev))
674b409a9efSFlorian Fainelli return;
675b409a9efSFlorian Fainelli
676b409a9efSFlorian Fainelli /* Enable reception Broadcom tag for CPU TX (switch RX) to
677b409a9efSFlorian Fainelli * allow us to tag outgoing frames
678b409a9efSFlorian Fainelli */
679b409a9efSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_RX_DIS, ®);
680cdb583cfSFlorian Fainelli if (tag_en)
681b409a9efSFlorian Fainelli reg &= ~BIT(port);
682cdb583cfSFlorian Fainelli else
683cdb583cfSFlorian Fainelli reg |= BIT(port);
684b409a9efSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_RX_DIS, reg);
685b409a9efSFlorian Fainelli
686b409a9efSFlorian Fainelli /* Enable transmission of Broadcom tags from the switch (CPU RX) to
687b409a9efSFlorian Fainelli * allow delivering frames to the per-port net_devices
688b409a9efSFlorian Fainelli */
689b409a9efSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_TX_DIS, ®);
690cdb583cfSFlorian Fainelli if (tag_en)
691b409a9efSFlorian Fainelli reg &= ~BIT(port);
692cdb583cfSFlorian Fainelli else
693cdb583cfSFlorian Fainelli reg |= BIT(port);
694b409a9efSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_TX_DIS, reg);
695b409a9efSFlorian Fainelli }
696b409a9efSFlorian Fainelli EXPORT_SYMBOL(b53_brcm_hdr_setup);
697b409a9efSFlorian Fainelli
b53_enable_cpu_port(struct b53_device * dev,int port)698299752a7SFlorian Fainelli static void b53_enable_cpu_port(struct b53_device *dev, int port)
699967dd82fSFlorian Fainelli {
700967dd82fSFlorian Fainelli u8 port_ctrl;
701967dd82fSFlorian Fainelli
702967dd82fSFlorian Fainelli /* BCM5325 CPU port is at 8 */
703299752a7SFlorian Fainelli if ((is5325(dev) || is5365(dev)) && port == B53_CPU_PORT_25)
704299752a7SFlorian Fainelli port = B53_CPU_PORT;
705967dd82fSFlorian Fainelli
706967dd82fSFlorian Fainelli port_ctrl = PORT_CTRL_RX_BCST_EN |
707967dd82fSFlorian Fainelli PORT_CTRL_RX_MCST_EN |
708967dd82fSFlorian Fainelli PORT_CTRL_RX_UCST_EN;
709299752a7SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), port_ctrl);
7107edc58d6SFlorian Fainelli
7117edc58d6SFlorian Fainelli b53_brcm_hdr_setup(dev->ds, port);
71263cc54a6SFlorian Fainelli
713a8b659e7SVladimir Oltean b53_port_set_ucast_flood(dev, port, true);
714a8b659e7SVladimir Oltean b53_port_set_mcast_flood(dev, port, true);
715f9b3827eSFlorian Fainelli b53_port_set_learning(dev, port, false);
716967dd82fSFlorian Fainelli }
717967dd82fSFlorian Fainelli
b53_enable_mib(struct b53_device * dev)718967dd82fSFlorian Fainelli static void b53_enable_mib(struct b53_device *dev)
719967dd82fSFlorian Fainelli {
720967dd82fSFlorian Fainelli u8 gc;
721967dd82fSFlorian Fainelli
722967dd82fSFlorian Fainelli b53_read8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &gc);
723967dd82fSFlorian Fainelli gc &= ~(GC_RESET_MIB | GC_MIB_AC_EN);
724967dd82fSFlorian Fainelli b53_write8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc);
725967dd82fSFlorian Fainelli }
726967dd82fSFlorian Fainelli
b53_default_pvid(struct b53_device * dev)727fea83353SFlorian Fainelli static u16 b53_default_pvid(struct b53_device *dev)
728fea83353SFlorian Fainelli {
729fea83353SFlorian Fainelli if (is5325(dev) || is5365(dev))
730fea83353SFlorian Fainelli return 1;
731fea83353SFlorian Fainelli else
732fea83353SFlorian Fainelli return 0;
733fea83353SFlorian Fainelli }
734fea83353SFlorian Fainelli
b53_vlan_port_needs_forced_tagged(struct dsa_switch * ds,int port)73564a81b24SFlorian Fainelli static bool b53_vlan_port_needs_forced_tagged(struct dsa_switch *ds, int port)
73664a81b24SFlorian Fainelli {
73764a81b24SFlorian Fainelli struct b53_device *dev = ds->priv;
73864a81b24SFlorian Fainelli
73964a81b24SFlorian Fainelli return dev->tag_protocol == DSA_TAG_PROTO_NONE && dsa_is_cpu_port(ds, port);
74064a81b24SFlorian Fainelli }
74164a81b24SFlorian Fainelli
b53_configure_vlan(struct dsa_switch * ds)7425c1a6eafSFlorian Fainelli int b53_configure_vlan(struct dsa_switch *ds)
743967dd82fSFlorian Fainelli {
7445c1a6eafSFlorian Fainelli struct b53_device *dev = ds->priv;
745a2482d2cSFlorian Fainelli struct b53_vlan vl = { 0 };
746d7a0b1f7SFlorian Fainelli struct b53_vlan *v;
747fea83353SFlorian Fainelli int i, def_vid;
748d7a0b1f7SFlorian Fainelli u16 vid;
749fea83353SFlorian Fainelli
750fea83353SFlorian Fainelli def_vid = b53_default_pvid(dev);
751967dd82fSFlorian Fainelli
752967dd82fSFlorian Fainelli /* clear all vlan entries */
753967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) {
754fea83353SFlorian Fainelli for (i = def_vid; i < dev->num_vlans; i++)
755a2482d2cSFlorian Fainelli b53_set_vlan_entry(dev, i, &vl);
756967dd82fSFlorian Fainelli } else {
757967dd82fSFlorian Fainelli b53_do_vlan_op(dev, VTA_CMD_CLEAR);
758967dd82fSFlorian Fainelli }
759967dd82fSFlorian Fainelli
760ee47ed08SFlorian Fainelli b53_enable_vlan(dev, -1, dev->vlan_enabled, ds->vlan_filtering);
761967dd82fSFlorian Fainelli
76264a81b24SFlorian Fainelli /* Create an untagged VLAN entry for the default PVID in case
76364a81b24SFlorian Fainelli * CONFIG_VLAN_8021Q is disabled and there are no calls to
76464a81b24SFlorian Fainelli * dsa_slave_vlan_rx_add_vid() to create the default VLAN
76564a81b24SFlorian Fainelli * entry. Do this only when the tagging protocol is not
76664a81b24SFlorian Fainelli * DSA_TAG_PROTO_NONE
76764a81b24SFlorian Fainelli */
76864a81b24SFlorian Fainelli b53_for_each_port(dev, i) {
76964a81b24SFlorian Fainelli v = &dev->vlans[def_vid];
77064a81b24SFlorian Fainelli v->members |= BIT(i);
77164a81b24SFlorian Fainelli if (!b53_vlan_port_needs_forced_tagged(ds, i))
77264a81b24SFlorian Fainelli v->untag = v->members;
773967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE,
774fea83353SFlorian Fainelli B53_VLAN_PORT_DEF_TAG(i), def_vid);
77564a81b24SFlorian Fainelli }
776967dd82fSFlorian Fainelli
777d7a0b1f7SFlorian Fainelli /* Upon initial call we have not set-up any VLANs, but upon
778d7a0b1f7SFlorian Fainelli * system resume, we need to restore all VLAN entries.
779d7a0b1f7SFlorian Fainelli */
780d7a0b1f7SFlorian Fainelli for (vid = def_vid; vid < dev->num_vlans; vid++) {
781d7a0b1f7SFlorian Fainelli v = &dev->vlans[vid];
782d7a0b1f7SFlorian Fainelli
783d7a0b1f7SFlorian Fainelli if (!v->members)
784d7a0b1f7SFlorian Fainelli continue;
785d7a0b1f7SFlorian Fainelli
786d7a0b1f7SFlorian Fainelli b53_set_vlan_entry(dev, vid, v);
787d7a0b1f7SFlorian Fainelli b53_fast_age_vlan(dev, vid);
788d7a0b1f7SFlorian Fainelli }
789d7a0b1f7SFlorian Fainelli
790967dd82fSFlorian Fainelli return 0;
791967dd82fSFlorian Fainelli }
7925c1a6eafSFlorian Fainelli EXPORT_SYMBOL(b53_configure_vlan);
793967dd82fSFlorian Fainelli
b53_switch_reset_gpio(struct b53_device * dev)794967dd82fSFlorian Fainelli static void b53_switch_reset_gpio(struct b53_device *dev)
795967dd82fSFlorian Fainelli {
796967dd82fSFlorian Fainelli int gpio = dev->reset_gpio;
797967dd82fSFlorian Fainelli
798967dd82fSFlorian Fainelli if (gpio < 0)
799967dd82fSFlorian Fainelli return;
800967dd82fSFlorian Fainelli
801967dd82fSFlorian Fainelli /* Reset sequence: RESET low(50ms)->high(20ms)
802967dd82fSFlorian Fainelli */
803967dd82fSFlorian Fainelli gpio_set_value(gpio, 0);
804967dd82fSFlorian Fainelli mdelay(50);
805967dd82fSFlorian Fainelli
806967dd82fSFlorian Fainelli gpio_set_value(gpio, 1);
807967dd82fSFlorian Fainelli mdelay(20);
808967dd82fSFlorian Fainelli
809967dd82fSFlorian Fainelli dev->current_page = 0xff;
810967dd82fSFlorian Fainelli }
811967dd82fSFlorian Fainelli
b53_switch_reset(struct b53_device * dev)812967dd82fSFlorian Fainelli static int b53_switch_reset(struct b53_device *dev)
813967dd82fSFlorian Fainelli {
8143fb22b05SFlorian Fainelli unsigned int timeout = 1000;
8153fb22b05SFlorian Fainelli u8 mgmt, reg;
816967dd82fSFlorian Fainelli
817967dd82fSFlorian Fainelli b53_switch_reset_gpio(dev);
818967dd82fSFlorian Fainelli
819967dd82fSFlorian Fainelli if (is539x(dev)) {
820967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x83);
821967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x00);
822967dd82fSFlorian Fainelli }
823967dd82fSFlorian Fainelli
8243fb22b05SFlorian Fainelli /* This is specific to 58xx devices here, do not use is58xx() which
8253fb22b05SFlorian Fainelli * covers the larger Starfigther 2 family, including 7445/7278 which
8263fb22b05SFlorian Fainelli * still use this driver as a library and need to perform the reset
8273fb22b05SFlorian Fainelli * earlier.
8283fb22b05SFlorian Fainelli */
8295040cc99SArun Parameswaran if (dev->chip_id == BCM58XX_DEVICE_ID ||
8305040cc99SArun Parameswaran dev->chip_id == BCM583XX_DEVICE_ID) {
8313fb22b05SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SOFTRESET, ®);
8323fb22b05SFlorian Fainelli reg |= SW_RST | EN_SW_RST | EN_CH_RST;
8333fb22b05SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, reg);
8343fb22b05SFlorian Fainelli
8353fb22b05SFlorian Fainelli do {
8363fb22b05SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SOFTRESET, ®);
8373fb22b05SFlorian Fainelli if (!(reg & SW_RST))
8383fb22b05SFlorian Fainelli break;
8393fb22b05SFlorian Fainelli
8403fb22b05SFlorian Fainelli usleep_range(1000, 2000);
8413fb22b05SFlorian Fainelli } while (timeout-- > 0);
8423fb22b05SFlorian Fainelli
843434d2312SPaul Barker if (timeout == 0) {
844434d2312SPaul Barker dev_err(dev->dev,
845434d2312SPaul Barker "Timeout waiting for SW_RST to clear!\n");
8463fb22b05SFlorian Fainelli return -ETIMEDOUT;
8473fb22b05SFlorian Fainelli }
848434d2312SPaul Barker }
8493fb22b05SFlorian Fainelli
850967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt);
851967dd82fSFlorian Fainelli
852967dd82fSFlorian Fainelli if (!(mgmt & SM_SW_FWD_EN)) {
853967dd82fSFlorian Fainelli mgmt &= ~SM_SW_FWD_MODE;
854967dd82fSFlorian Fainelli mgmt |= SM_SW_FWD_EN;
855967dd82fSFlorian Fainelli
856967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt);
857967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt);
858967dd82fSFlorian Fainelli
859967dd82fSFlorian Fainelli if (!(mgmt & SM_SW_FWD_EN)) {
860967dd82fSFlorian Fainelli dev_err(dev->dev, "Failed to enable switch!\n");
861967dd82fSFlorian Fainelli return -EINVAL;
862967dd82fSFlorian Fainelli }
863967dd82fSFlorian Fainelli }
864967dd82fSFlorian Fainelli
865967dd82fSFlorian Fainelli b53_enable_mib(dev);
866967dd82fSFlorian Fainelli
867ff39c2d6SFlorian Fainelli return b53_flush_arl(dev, FAST_AGE_STATIC);
868967dd82fSFlorian Fainelli }
869967dd82fSFlorian Fainelli
b53_phy_read16(struct dsa_switch * ds,int addr,int reg)870967dd82fSFlorian Fainelli static int b53_phy_read16(struct dsa_switch *ds, int addr, int reg)
871967dd82fSFlorian Fainelli {
87204bed143SVivien Didelot struct b53_device *priv = ds->priv;
873967dd82fSFlorian Fainelli u16 value = 0;
874967dd82fSFlorian Fainelli int ret;
875967dd82fSFlorian Fainelli
876967dd82fSFlorian Fainelli if (priv->ops->phy_read16)
877967dd82fSFlorian Fainelli ret = priv->ops->phy_read16(priv, addr, reg, &value);
878967dd82fSFlorian Fainelli else
879967dd82fSFlorian Fainelli ret = b53_read16(priv, B53_PORT_MII_PAGE(addr),
880967dd82fSFlorian Fainelli reg * 2, &value);
881967dd82fSFlorian Fainelli
882967dd82fSFlorian Fainelli return ret ? ret : value;
883967dd82fSFlorian Fainelli }
884967dd82fSFlorian Fainelli
b53_phy_write16(struct dsa_switch * ds,int addr,int reg,u16 val)885967dd82fSFlorian Fainelli static int b53_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val)
886967dd82fSFlorian Fainelli {
88704bed143SVivien Didelot struct b53_device *priv = ds->priv;
888967dd82fSFlorian Fainelli
889967dd82fSFlorian Fainelli if (priv->ops->phy_write16)
890967dd82fSFlorian Fainelli return priv->ops->phy_write16(priv, addr, reg, val);
891967dd82fSFlorian Fainelli
892967dd82fSFlorian Fainelli return b53_write16(priv, B53_PORT_MII_PAGE(addr), reg * 2, val);
893967dd82fSFlorian Fainelli }
894967dd82fSFlorian Fainelli
b53_reset_switch(struct b53_device * priv)895967dd82fSFlorian Fainelli static int b53_reset_switch(struct b53_device *priv)
896967dd82fSFlorian Fainelli {
897967dd82fSFlorian Fainelli /* reset vlans */
898a2482d2cSFlorian Fainelli memset(priv->vlans, 0, sizeof(*priv->vlans) * priv->num_vlans);
899967dd82fSFlorian Fainelli memset(priv->ports, 0, sizeof(*priv->ports) * priv->num_ports);
900967dd82fSFlorian Fainelli
9010e01491dSFlorian Fainelli priv->serdes_lane = B53_INVALID_LANE;
9020e01491dSFlorian Fainelli
903967dd82fSFlorian Fainelli return b53_switch_reset(priv);
904967dd82fSFlorian Fainelli }
905967dd82fSFlorian Fainelli
b53_apply_config(struct b53_device * priv)906967dd82fSFlorian Fainelli static int b53_apply_config(struct b53_device *priv)
907967dd82fSFlorian Fainelli {
908967dd82fSFlorian Fainelli /* disable switching */
909967dd82fSFlorian Fainelli b53_set_forwarding(priv, 0);
910967dd82fSFlorian Fainelli
9115c1a6eafSFlorian Fainelli b53_configure_vlan(priv->ds);
912967dd82fSFlorian Fainelli
913967dd82fSFlorian Fainelli /* enable switching */
914967dd82fSFlorian Fainelli b53_set_forwarding(priv, 1);
915967dd82fSFlorian Fainelli
916967dd82fSFlorian Fainelli return 0;
917967dd82fSFlorian Fainelli }
918967dd82fSFlorian Fainelli
b53_reset_mib(struct b53_device * priv)919967dd82fSFlorian Fainelli static void b53_reset_mib(struct b53_device *priv)
920967dd82fSFlorian Fainelli {
921967dd82fSFlorian Fainelli u8 gc;
922967dd82fSFlorian Fainelli
923967dd82fSFlorian Fainelli b53_read8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &gc);
924967dd82fSFlorian Fainelli
925967dd82fSFlorian Fainelli b53_write8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc | GC_RESET_MIB);
926967dd82fSFlorian Fainelli msleep(1);
927967dd82fSFlorian Fainelli b53_write8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc & ~GC_RESET_MIB);
928967dd82fSFlorian Fainelli msleep(1);
929967dd82fSFlorian Fainelli }
930967dd82fSFlorian Fainelli
b53_get_mib(struct b53_device * dev)931967dd82fSFlorian Fainelli static const struct b53_mib_desc *b53_get_mib(struct b53_device *dev)
932967dd82fSFlorian Fainelli {
933967dd82fSFlorian Fainelli if (is5365(dev))
934967dd82fSFlorian Fainelli return b53_mibs_65;
935967dd82fSFlorian Fainelli else if (is63xx(dev))
936967dd82fSFlorian Fainelli return b53_mibs_63xx;
937bde5d132SFlorian Fainelli else if (is58xx(dev))
938bde5d132SFlorian Fainelli return b53_mibs_58xx;
939967dd82fSFlorian Fainelli else
940967dd82fSFlorian Fainelli return b53_mibs;
941967dd82fSFlorian Fainelli }
942967dd82fSFlorian Fainelli
b53_get_mib_size(struct b53_device * dev)943967dd82fSFlorian Fainelli static unsigned int b53_get_mib_size(struct b53_device *dev)
944967dd82fSFlorian Fainelli {
945967dd82fSFlorian Fainelli if (is5365(dev))
946967dd82fSFlorian Fainelli return B53_MIBS_65_SIZE;
947967dd82fSFlorian Fainelli else if (is63xx(dev))
948967dd82fSFlorian Fainelli return B53_MIBS_63XX_SIZE;
949bde5d132SFlorian Fainelli else if (is58xx(dev))
950bde5d132SFlorian Fainelli return B53_MIBS_58XX_SIZE;
951967dd82fSFlorian Fainelli else
952967dd82fSFlorian Fainelli return B53_MIBS_SIZE;
953967dd82fSFlorian Fainelli }
954967dd82fSFlorian Fainelli
b53_get_phy_device(struct dsa_switch * ds,int port)955c7d28c9dSFlorian Fainelli static struct phy_device *b53_get_phy_device(struct dsa_switch *ds, int port)
956c7d28c9dSFlorian Fainelli {
957c7d28c9dSFlorian Fainelli /* These ports typically do not have built-in PHYs */
958c7d28c9dSFlorian Fainelli switch (port) {
959c7d28c9dSFlorian Fainelli case B53_CPU_PORT_25:
960c7d28c9dSFlorian Fainelli case 7:
961c7d28c9dSFlorian Fainelli case B53_CPU_PORT:
962c7d28c9dSFlorian Fainelli return NULL;
963c7d28c9dSFlorian Fainelli }
964c7d28c9dSFlorian Fainelli
965c7d28c9dSFlorian Fainelli return mdiobus_get_phy(ds->slave_mii_bus, port);
966c7d28c9dSFlorian Fainelli }
967c7d28c9dSFlorian Fainelli
b53_get_strings(struct dsa_switch * ds,int port,u32 stringset,uint8_t * data)96889f09048SFlorian Fainelli void b53_get_strings(struct dsa_switch *ds, int port, u32 stringset,
96989f09048SFlorian Fainelli uint8_t *data)
970967dd82fSFlorian Fainelli {
97104bed143SVivien Didelot struct b53_device *dev = ds->priv;
972967dd82fSFlorian Fainelli const struct b53_mib_desc *mibs = b53_get_mib(dev);
973967dd82fSFlorian Fainelli unsigned int mib_size = b53_get_mib_size(dev);
974c7d28c9dSFlorian Fainelli struct phy_device *phydev;
975967dd82fSFlorian Fainelli unsigned int i;
976967dd82fSFlorian Fainelli
977c7d28c9dSFlorian Fainelli if (stringset == ETH_SS_STATS) {
978967dd82fSFlorian Fainelli for (i = 0; i < mib_size; i++)
979fb3ceec1SWolfram Sang strscpy(data + i * ETH_GSTRING_LEN,
980967dd82fSFlorian Fainelli mibs[i].name, ETH_GSTRING_LEN);
981c7d28c9dSFlorian Fainelli } else if (stringset == ETH_SS_PHY_STATS) {
982c7d28c9dSFlorian Fainelli phydev = b53_get_phy_device(ds, port);
983c7d28c9dSFlorian Fainelli if (!phydev)
984c7d28c9dSFlorian Fainelli return;
985c7d28c9dSFlorian Fainelli
986c7d28c9dSFlorian Fainelli phy_ethtool_get_strings(phydev, data);
987c7d28c9dSFlorian Fainelli }
988967dd82fSFlorian Fainelli }
9893117455dSFlorian Fainelli EXPORT_SYMBOL(b53_get_strings);
990967dd82fSFlorian Fainelli
b53_get_ethtool_stats(struct dsa_switch * ds,int port,uint64_t * data)9913117455dSFlorian Fainelli void b53_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data)
992967dd82fSFlorian Fainelli {
99304bed143SVivien Didelot struct b53_device *dev = ds->priv;
994967dd82fSFlorian Fainelli const struct b53_mib_desc *mibs = b53_get_mib(dev);
995967dd82fSFlorian Fainelli unsigned int mib_size = b53_get_mib_size(dev);
996967dd82fSFlorian Fainelli const struct b53_mib_desc *s;
997967dd82fSFlorian Fainelli unsigned int i;
998967dd82fSFlorian Fainelli u64 val = 0;
999967dd82fSFlorian Fainelli
1000967dd82fSFlorian Fainelli if (is5365(dev) && port == 5)
1001967dd82fSFlorian Fainelli port = 8;
1002967dd82fSFlorian Fainelli
1003967dd82fSFlorian Fainelli mutex_lock(&dev->stats_mutex);
1004967dd82fSFlorian Fainelli
1005967dd82fSFlorian Fainelli for (i = 0; i < mib_size; i++) {
1006967dd82fSFlorian Fainelli s = &mibs[i];
1007967dd82fSFlorian Fainelli
100851dca8a1SFlorian Fainelli if (s->size == 8) {
1009967dd82fSFlorian Fainelli b53_read64(dev, B53_MIB_PAGE(port), s->offset, &val);
1010967dd82fSFlorian Fainelli } else {
1011967dd82fSFlorian Fainelli u32 val32;
1012967dd82fSFlorian Fainelli
1013967dd82fSFlorian Fainelli b53_read32(dev, B53_MIB_PAGE(port), s->offset,
1014967dd82fSFlorian Fainelli &val32);
1015967dd82fSFlorian Fainelli val = val32;
1016967dd82fSFlorian Fainelli }
1017967dd82fSFlorian Fainelli data[i] = (u64)val;
1018967dd82fSFlorian Fainelli }
1019967dd82fSFlorian Fainelli
1020967dd82fSFlorian Fainelli mutex_unlock(&dev->stats_mutex);
1021967dd82fSFlorian Fainelli }
10223117455dSFlorian Fainelli EXPORT_SYMBOL(b53_get_ethtool_stats);
1023967dd82fSFlorian Fainelli
b53_get_ethtool_phy_stats(struct dsa_switch * ds,int port,uint64_t * data)1024c7d28c9dSFlorian Fainelli void b53_get_ethtool_phy_stats(struct dsa_switch *ds, int port, uint64_t *data)
1025c7d28c9dSFlorian Fainelli {
1026c7d28c9dSFlorian Fainelli struct phy_device *phydev;
1027c7d28c9dSFlorian Fainelli
1028c7d28c9dSFlorian Fainelli phydev = b53_get_phy_device(ds, port);
1029c7d28c9dSFlorian Fainelli if (!phydev)
1030c7d28c9dSFlorian Fainelli return;
1031c7d28c9dSFlorian Fainelli
1032c7d28c9dSFlorian Fainelli phy_ethtool_get_stats(phydev, NULL, data);
1033c7d28c9dSFlorian Fainelli }
1034c7d28c9dSFlorian Fainelli EXPORT_SYMBOL(b53_get_ethtool_phy_stats);
1035c7d28c9dSFlorian Fainelli
b53_get_sset_count(struct dsa_switch * ds,int port,int sset)103689f09048SFlorian Fainelli int b53_get_sset_count(struct dsa_switch *ds, int port, int sset)
1037967dd82fSFlorian Fainelli {
103804bed143SVivien Didelot struct b53_device *dev = ds->priv;
1039c7d28c9dSFlorian Fainelli struct phy_device *phydev;
1040967dd82fSFlorian Fainelli
1041c7d28c9dSFlorian Fainelli if (sset == ETH_SS_STATS) {
1042c7d28c9dSFlorian Fainelli return b53_get_mib_size(dev);
1043c7d28c9dSFlorian Fainelli } else if (sset == ETH_SS_PHY_STATS) {
1044c7d28c9dSFlorian Fainelli phydev = b53_get_phy_device(ds, port);
1045c7d28c9dSFlorian Fainelli if (!phydev)
104689f09048SFlorian Fainelli return 0;
104789f09048SFlorian Fainelli
1048c7d28c9dSFlorian Fainelli return phy_ethtool_get_sset_count(phydev);
1049c7d28c9dSFlorian Fainelli }
1050c7d28c9dSFlorian Fainelli
1051c7d28c9dSFlorian Fainelli return 0;
1052967dd82fSFlorian Fainelli }
10533117455dSFlorian Fainelli EXPORT_SYMBOL(b53_get_sset_count);
1054967dd82fSFlorian Fainelli
10554f6a5cafSFlorian Fainelli enum b53_devlink_resource_id {
10564f6a5cafSFlorian Fainelli B53_DEVLINK_PARAM_ID_VLAN_TABLE,
10574f6a5cafSFlorian Fainelli };
10584f6a5cafSFlorian Fainelli
b53_devlink_vlan_table_get(void * priv)10594f6a5cafSFlorian Fainelli static u64 b53_devlink_vlan_table_get(void *priv)
10604f6a5cafSFlorian Fainelli {
10614f6a5cafSFlorian Fainelli struct b53_device *dev = priv;
10624f6a5cafSFlorian Fainelli struct b53_vlan *vl;
10634f6a5cafSFlorian Fainelli unsigned int i;
10644f6a5cafSFlorian Fainelli u64 count = 0;
10654f6a5cafSFlorian Fainelli
10664f6a5cafSFlorian Fainelli for (i = 0; i < dev->num_vlans; i++) {
10674f6a5cafSFlorian Fainelli vl = &dev->vlans[i];
10684f6a5cafSFlorian Fainelli if (vl->members)
10694f6a5cafSFlorian Fainelli count++;
10704f6a5cafSFlorian Fainelli }
10714f6a5cafSFlorian Fainelli
10724f6a5cafSFlorian Fainelli return count;
10734f6a5cafSFlorian Fainelli }
10744f6a5cafSFlorian Fainelli
b53_setup_devlink_resources(struct dsa_switch * ds)10754f6a5cafSFlorian Fainelli int b53_setup_devlink_resources(struct dsa_switch *ds)
10764f6a5cafSFlorian Fainelli {
10774f6a5cafSFlorian Fainelli struct devlink_resource_size_params size_params;
10784f6a5cafSFlorian Fainelli struct b53_device *dev = ds->priv;
10794f6a5cafSFlorian Fainelli int err;
10804f6a5cafSFlorian Fainelli
10814f6a5cafSFlorian Fainelli devlink_resource_size_params_init(&size_params, dev->num_vlans,
10824f6a5cafSFlorian Fainelli dev->num_vlans,
10834f6a5cafSFlorian Fainelli 1, DEVLINK_RESOURCE_UNIT_ENTRY);
10844f6a5cafSFlorian Fainelli
10854f6a5cafSFlorian Fainelli err = dsa_devlink_resource_register(ds, "VLAN", dev->num_vlans,
10864f6a5cafSFlorian Fainelli B53_DEVLINK_PARAM_ID_VLAN_TABLE,
10874f6a5cafSFlorian Fainelli DEVLINK_RESOURCE_ID_PARENT_TOP,
10884f6a5cafSFlorian Fainelli &size_params);
10894f6a5cafSFlorian Fainelli if (err)
10904f6a5cafSFlorian Fainelli goto out;
10914f6a5cafSFlorian Fainelli
10924f6a5cafSFlorian Fainelli dsa_devlink_resource_occ_get_register(ds,
10934f6a5cafSFlorian Fainelli B53_DEVLINK_PARAM_ID_VLAN_TABLE,
10944f6a5cafSFlorian Fainelli b53_devlink_vlan_table_get, dev);
10954f6a5cafSFlorian Fainelli
10964f6a5cafSFlorian Fainelli return 0;
10974f6a5cafSFlorian Fainelli out:
10984f6a5cafSFlorian Fainelli dsa_devlink_resources_unregister(ds);
10994f6a5cafSFlorian Fainelli return err;
11004f6a5cafSFlorian Fainelli }
11014f6a5cafSFlorian Fainelli EXPORT_SYMBOL(b53_setup_devlink_resources);
11024f6a5cafSFlorian Fainelli
b53_setup(struct dsa_switch * ds)1103967dd82fSFlorian Fainelli static int b53_setup(struct dsa_switch *ds)
1104967dd82fSFlorian Fainelli {
110504bed143SVivien Didelot struct b53_device *dev = ds->priv;
1106967dd82fSFlorian Fainelli unsigned int port;
1107967dd82fSFlorian Fainelli int ret;
1108967dd82fSFlorian Fainelli
11092c32a3d3SFlorian Fainelli /* Request bridge PVID untagged when DSA_TAG_PROTO_NONE is set
11102c32a3d3SFlorian Fainelli * which forces the CPU port to be tagged in all VLANs.
11112c32a3d3SFlorian Fainelli */
11122c32a3d3SFlorian Fainelli ds->untag_bridge_pvid = dev->tag_protocol == DSA_TAG_PROTO_NONE;
11132c32a3d3SFlorian Fainelli
1114967dd82fSFlorian Fainelli ret = b53_reset_switch(dev);
1115967dd82fSFlorian Fainelli if (ret) {
1116967dd82fSFlorian Fainelli dev_err(ds->dev, "failed to reset switch\n");
1117967dd82fSFlorian Fainelli return ret;
1118967dd82fSFlorian Fainelli }
1119967dd82fSFlorian Fainelli
1120967dd82fSFlorian Fainelli b53_reset_mib(dev);
1121967dd82fSFlorian Fainelli
1122967dd82fSFlorian Fainelli ret = b53_apply_config(dev);
11234f6a5cafSFlorian Fainelli if (ret) {
1124967dd82fSFlorian Fainelli dev_err(ds->dev, "failed to apply configuration\n");
11254f6a5cafSFlorian Fainelli return ret;
11264f6a5cafSFlorian Fainelli }
1127967dd82fSFlorian Fainelli
112875dad252SBenedikt Spranger /* Configure IMP/CPU port, disable all other ports. Enabled
112934c8befdSFlorian Fainelli * ports will be configured with .port_enable
113034c8befdSFlorian Fainelli */
1131967dd82fSFlorian Fainelli for (port = 0; port < dev->num_ports; port++) {
113234c8befdSFlorian Fainelli if (dsa_is_cpu_port(ds, port))
1133299752a7SFlorian Fainelli b53_enable_cpu_port(dev, port);
113475dad252SBenedikt Spranger else
113575104db0SAndrew Lunn b53_disable_port(ds, port);
1136967dd82fSFlorian Fainelli }
1137967dd82fSFlorian Fainelli
11384f6a5cafSFlorian Fainelli return b53_setup_devlink_resources(ds);
11394f6a5cafSFlorian Fainelli }
11404f6a5cafSFlorian Fainelli
b53_teardown(struct dsa_switch * ds)11414f6a5cafSFlorian Fainelli static void b53_teardown(struct dsa_switch *ds)
11424f6a5cafSFlorian Fainelli {
11434f6a5cafSFlorian Fainelli dsa_devlink_resources_unregister(ds);
1144967dd82fSFlorian Fainelli }
1145967dd82fSFlorian Fainelli
b53_force_link(struct b53_device * dev,int port,int link)11465e004460SFlorian Fainelli static void b53_force_link(struct b53_device *dev, int port, int link)
1147967dd82fSFlorian Fainelli {
11485e004460SFlorian Fainelli u8 reg, val, off;
1149967dd82fSFlorian Fainelli
1150967dd82fSFlorian Fainelli /* Override the port settings */
115163f8428bSRafał Miłecki if (port == dev->imp_port) {
1152967dd82fSFlorian Fainelli off = B53_PORT_OVERRIDE_CTRL;
11535e004460SFlorian Fainelli val = PORT_OVERRIDE_EN;
1154967dd82fSFlorian Fainelli } else {
1155967dd82fSFlorian Fainelli off = B53_GMII_PORT_OVERRIDE_CTRL(port);
11565e004460SFlorian Fainelli val = GMII_PO_EN;
1157967dd82fSFlorian Fainelli }
1158967dd82fSFlorian Fainelli
11595e004460SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, off, ®);
11605e004460SFlorian Fainelli reg |= val;
11615e004460SFlorian Fainelli if (link)
1162967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_LINK;
11635e004460SFlorian Fainelli else
11645e004460SFlorian Fainelli reg &= ~PORT_OVERRIDE_LINK;
11655e004460SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, off, reg);
11665e004460SFlorian Fainelli }
1167967dd82fSFlorian Fainelli
b53_force_port_config(struct b53_device * dev,int port,int speed,int duplex,bool tx_pause,bool rx_pause)11685e004460SFlorian Fainelli static void b53_force_port_config(struct b53_device *dev, int port,
11693cad1c8bSRussell King int speed, int duplex,
11703cad1c8bSRussell King bool tx_pause, bool rx_pause)
11715e004460SFlorian Fainelli {
11725e004460SFlorian Fainelli u8 reg, val, off;
11735e004460SFlorian Fainelli
11745e004460SFlorian Fainelli /* Override the port settings */
117563f8428bSRafał Miłecki if (port == dev->imp_port) {
11765e004460SFlorian Fainelli off = B53_PORT_OVERRIDE_CTRL;
11775e004460SFlorian Fainelli val = PORT_OVERRIDE_EN;
11785e004460SFlorian Fainelli } else {
11795e004460SFlorian Fainelli off = B53_GMII_PORT_OVERRIDE_CTRL(port);
11805e004460SFlorian Fainelli val = GMII_PO_EN;
11815e004460SFlorian Fainelli }
11825e004460SFlorian Fainelli
11835e004460SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, off, ®);
11845e004460SFlorian Fainelli reg |= val;
11855e004460SFlorian Fainelli if (duplex == DUPLEX_FULL)
1186967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_FULL_DUPLEX;
11875e004460SFlorian Fainelli else
11885e004460SFlorian Fainelli reg &= ~PORT_OVERRIDE_FULL_DUPLEX;
1189967dd82fSFlorian Fainelli
11905e004460SFlorian Fainelli switch (speed) {
1191967dd82fSFlorian Fainelli case 2000:
1192967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_SPEED_2000M;
1193df561f66SGustavo A. R. Silva fallthrough;
1194967dd82fSFlorian Fainelli case SPEED_1000:
1195967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_SPEED_1000M;
1196967dd82fSFlorian Fainelli break;
1197967dd82fSFlorian Fainelli case SPEED_100:
1198967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_SPEED_100M;
1199967dd82fSFlorian Fainelli break;
1200967dd82fSFlorian Fainelli case SPEED_10:
1201967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_SPEED_10M;
1202967dd82fSFlorian Fainelli break;
1203967dd82fSFlorian Fainelli default:
12045e004460SFlorian Fainelli dev_err(dev->dev, "unknown speed: %d\n", speed);
1205967dd82fSFlorian Fainelli return;
1206967dd82fSFlorian Fainelli }
1207967dd82fSFlorian Fainelli
12083cad1c8bSRussell King if (rx_pause)
12095e004460SFlorian Fainelli reg |= PORT_OVERRIDE_RX_FLOW;
12103cad1c8bSRussell King if (tx_pause)
12115e004460SFlorian Fainelli reg |= PORT_OVERRIDE_TX_FLOW;
12125e004460SFlorian Fainelli
12135e004460SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, off, reg);
12145e004460SFlorian Fainelli }
12155e004460SFlorian Fainelli
b53_adjust_63xx_rgmii(struct dsa_switch * ds,int port,phy_interface_t interface)1216ce3bf948SÁlvaro Fernández Rojas static void b53_adjust_63xx_rgmii(struct dsa_switch *ds, int port,
1217ce3bf948SÁlvaro Fernández Rojas phy_interface_t interface)
1218ce3bf948SÁlvaro Fernández Rojas {
1219ce3bf948SÁlvaro Fernández Rojas struct b53_device *dev = ds->priv;
1220ce3bf948SÁlvaro Fernández Rojas u8 rgmii_ctrl = 0, off;
1221ce3bf948SÁlvaro Fernández Rojas
1222ce3bf948SÁlvaro Fernández Rojas if (port == dev->imp_port)
1223ce3bf948SÁlvaro Fernández Rojas off = B53_RGMII_CTRL_IMP;
1224ce3bf948SÁlvaro Fernández Rojas else
1225ce3bf948SÁlvaro Fernández Rojas off = B53_RGMII_CTRL_P(port);
1226ce3bf948SÁlvaro Fernández Rojas
1227ce3bf948SÁlvaro Fernández Rojas b53_read8(dev, B53_CTRL_PAGE, off, &rgmii_ctrl);
1228ce3bf948SÁlvaro Fernández Rojas
1229ce3bf948SÁlvaro Fernández Rojas switch (interface) {
1230ce3bf948SÁlvaro Fernández Rojas case PHY_INTERFACE_MODE_RGMII_ID:
1231ce3bf948SÁlvaro Fernández Rojas rgmii_ctrl |= (RGMII_CTRL_DLL_RXC | RGMII_CTRL_DLL_TXC);
1232ce3bf948SÁlvaro Fernández Rojas break;
1233ce3bf948SÁlvaro Fernández Rojas case PHY_INTERFACE_MODE_RGMII_RXID:
1234ce3bf948SÁlvaro Fernández Rojas rgmii_ctrl &= ~(RGMII_CTRL_DLL_TXC);
1235ce3bf948SÁlvaro Fernández Rojas rgmii_ctrl |= RGMII_CTRL_DLL_RXC;
1236ce3bf948SÁlvaro Fernández Rojas break;
1237ce3bf948SÁlvaro Fernández Rojas case PHY_INTERFACE_MODE_RGMII_TXID:
1238ce3bf948SÁlvaro Fernández Rojas rgmii_ctrl &= ~(RGMII_CTRL_DLL_RXC);
1239ce3bf948SÁlvaro Fernández Rojas rgmii_ctrl |= RGMII_CTRL_DLL_TXC;
1240ce3bf948SÁlvaro Fernández Rojas break;
1241ce3bf948SÁlvaro Fernández Rojas case PHY_INTERFACE_MODE_RGMII:
1242ce3bf948SÁlvaro Fernández Rojas default:
1243ce3bf948SÁlvaro Fernández Rojas rgmii_ctrl &= ~(RGMII_CTRL_DLL_RXC | RGMII_CTRL_DLL_TXC);
1244ce3bf948SÁlvaro Fernández Rojas break;
1245ce3bf948SÁlvaro Fernández Rojas }
1246ce3bf948SÁlvaro Fernández Rojas
1247594c6c2eSÁlvaro Fernández Rojas if (port != dev->imp_port) {
1248594c6c2eSÁlvaro Fernández Rojas if (is63268(dev))
1249594c6c2eSÁlvaro Fernández Rojas rgmii_ctrl |= RGMII_CTRL_MII_OVERRIDE;
1250594c6c2eSÁlvaro Fernández Rojas
1251ce3bf948SÁlvaro Fernández Rojas rgmii_ctrl |= RGMII_CTRL_ENABLE_GMII;
1252594c6c2eSÁlvaro Fernández Rojas }
1253ce3bf948SÁlvaro Fernández Rojas
1254ce3bf948SÁlvaro Fernández Rojas b53_write8(dev, B53_CTRL_PAGE, off, rgmii_ctrl);
1255ce3bf948SÁlvaro Fernández Rojas
1256ce3bf948SÁlvaro Fernández Rojas dev_dbg(ds->dev, "Configured port %d for %s\n", port,
1257ce3bf948SÁlvaro Fernández Rojas phy_modes(interface));
1258ce3bf948SÁlvaro Fernández Rojas }
1259ce3bf948SÁlvaro Fernández Rojas
b53_adjust_link(struct dsa_switch * ds,int port,struct phy_device * phydev)12605e004460SFlorian Fainelli static void b53_adjust_link(struct dsa_switch *ds, int port,
12615e004460SFlorian Fainelli struct phy_device *phydev)
12625e004460SFlorian Fainelli {
12635e004460SFlorian Fainelli struct b53_device *dev = ds->priv;
12645e004460SFlorian Fainelli struct ethtool_eee *p = &dev->ports[port].eee;
12655e004460SFlorian Fainelli u8 rgmii_ctrl = 0, reg = 0, off;
12663cad1c8bSRussell King bool tx_pause = false;
12673cad1c8bSRussell King bool rx_pause = false;
12685e004460SFlorian Fainelli
12695e004460SFlorian Fainelli if (!phy_is_pseudo_fixed_link(phydev))
12705e004460SFlorian Fainelli return;
12715e004460SFlorian Fainelli
1272967dd82fSFlorian Fainelli /* Enable flow control on BCM5301x's CPU port */
12733ff26b29SRafał Miłecki if (is5301x(dev) && dsa_is_cpu_port(ds, port))
12743cad1c8bSRussell King tx_pause = rx_pause = true;
1275967dd82fSFlorian Fainelli
1276967dd82fSFlorian Fainelli if (phydev->pause) {
1277967dd82fSFlorian Fainelli if (phydev->asym_pause)
12783cad1c8bSRussell King tx_pause = true;
12793cad1c8bSRussell King rx_pause = true;
1280967dd82fSFlorian Fainelli }
1281967dd82fSFlorian Fainelli
12823cad1c8bSRussell King b53_force_port_config(dev, port, phydev->speed, phydev->duplex,
12833cad1c8bSRussell King tx_pause, rx_pause);
12845e004460SFlorian Fainelli b53_force_link(dev, port, phydev->link);
1285967dd82fSFlorian Fainelli
1286ce3bf948SÁlvaro Fernández Rojas if (is63xx(dev) && port >= B53_63XX_RGMII0)
1287ce3bf948SÁlvaro Fernández Rojas b53_adjust_63xx_rgmii(ds, port, phydev->interface);
1288ce3bf948SÁlvaro Fernández Rojas
1289967dd82fSFlorian Fainelli if (is531x5(dev) && phy_interface_is_rgmii(phydev)) {
129063f8428bSRafał Miłecki if (port == dev->imp_port)
1291967dd82fSFlorian Fainelli off = B53_RGMII_CTRL_IMP;
1292967dd82fSFlorian Fainelli else
1293967dd82fSFlorian Fainelli off = B53_RGMII_CTRL_P(port);
1294967dd82fSFlorian Fainelli
1295967dd82fSFlorian Fainelli /* Configure the port RGMII clock delay by DLL disabled and
1296967dd82fSFlorian Fainelli * tx_clk aligned timing (restoring to reset defaults)
1297967dd82fSFlorian Fainelli */
1298967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, off, &rgmii_ctrl);
1299967dd82fSFlorian Fainelli rgmii_ctrl &= ~(RGMII_CTRL_DLL_RXC | RGMII_CTRL_DLL_TXC |
1300967dd82fSFlorian Fainelli RGMII_CTRL_TIMING_SEL);
1301967dd82fSFlorian Fainelli
1302967dd82fSFlorian Fainelli /* PHY_INTERFACE_MODE_RGMII_TXID means TX internal delay, make
1303967dd82fSFlorian Fainelli * sure that we enable the port TX clock internal delay to
1304967dd82fSFlorian Fainelli * account for this internal delay that is inserted, otherwise
1305967dd82fSFlorian Fainelli * the switch won't be able to receive correctly.
1306967dd82fSFlorian Fainelli *
1307967dd82fSFlorian Fainelli * PHY_INTERFACE_MODE_RGMII means that we are not introducing
1308967dd82fSFlorian Fainelli * any delay neither on transmission nor reception, so the
1309967dd82fSFlorian Fainelli * BCM53125 must also be configured accordingly to account for
1310967dd82fSFlorian Fainelli * the lack of delay and introduce
1311967dd82fSFlorian Fainelli *
1312967dd82fSFlorian Fainelli * The BCM53125 switch has its RX clock and TX clock control
1313967dd82fSFlorian Fainelli * swapped, hence the reason why we modify the TX clock path in
1314967dd82fSFlorian Fainelli * the "RGMII" case
1315967dd82fSFlorian Fainelli */
1316967dd82fSFlorian Fainelli if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
1317967dd82fSFlorian Fainelli rgmii_ctrl |= RGMII_CTRL_DLL_TXC;
1318967dd82fSFlorian Fainelli if (phydev->interface == PHY_INTERFACE_MODE_RGMII)
1319967dd82fSFlorian Fainelli rgmii_ctrl |= RGMII_CTRL_DLL_TXC | RGMII_CTRL_DLL_RXC;
1320967dd82fSFlorian Fainelli rgmii_ctrl |= RGMII_CTRL_TIMING_SEL;
1321967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, off, rgmii_ctrl);
1322967dd82fSFlorian Fainelli
1323967dd82fSFlorian Fainelli dev_info(ds->dev, "Configured port %d for %s\n", port,
1324967dd82fSFlorian Fainelli phy_modes(phydev->interface));
1325967dd82fSFlorian Fainelli }
1326967dd82fSFlorian Fainelli
1327967dd82fSFlorian Fainelli /* configure MII port if necessary */
1328967dd82fSFlorian Fainelli if (is5325(dev)) {
1329967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL,
1330967dd82fSFlorian Fainelli ®);
1331967dd82fSFlorian Fainelli
1332967dd82fSFlorian Fainelli /* reverse mii needs to be enabled */
1333967dd82fSFlorian Fainelli if (!(reg & PORT_OVERRIDE_RV_MII_25)) {
1334967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL,
1335967dd82fSFlorian Fainelli reg | PORT_OVERRIDE_RV_MII_25);
1336967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL,
1337967dd82fSFlorian Fainelli ®);
1338967dd82fSFlorian Fainelli
1339967dd82fSFlorian Fainelli if (!(reg & PORT_OVERRIDE_RV_MII_25)) {
1340967dd82fSFlorian Fainelli dev_err(ds->dev,
1341967dd82fSFlorian Fainelli "Failed to enable reverse MII mode\n");
1342967dd82fSFlorian Fainelli return;
1343967dd82fSFlorian Fainelli }
1344967dd82fSFlorian Fainelli }
1345967dd82fSFlorian Fainelli }
1346f43a2dbeSFlorian Fainelli
1347f43a2dbeSFlorian Fainelli /* Re-negotiate EEE if it was enabled already */
1348f43a2dbeSFlorian Fainelli p->eee_enabled = b53_eee_init(ds, port, phydev);
1349967dd82fSFlorian Fainelli }
1350967dd82fSFlorian Fainelli
b53_port_event(struct dsa_switch * ds,int port)1351a8e8b985SFlorian Fainelli void b53_port_event(struct dsa_switch *ds, int port)
1352a8e8b985SFlorian Fainelli {
1353a8e8b985SFlorian Fainelli struct b53_device *dev = ds->priv;
1354a8e8b985SFlorian Fainelli bool link;
1355a8e8b985SFlorian Fainelli u16 sts;
1356a8e8b985SFlorian Fainelli
1357a8e8b985SFlorian Fainelli b53_read16(dev, B53_STAT_PAGE, B53_LINK_STAT, &sts);
1358a8e8b985SFlorian Fainelli link = !!(sts & BIT(port));
1359a8e8b985SFlorian Fainelli dsa_port_phylink_mac_change(ds, port, link);
1360a8e8b985SFlorian Fainelli }
1361a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_port_event);
1362a8e8b985SFlorian Fainelli
b53_phylink_get_caps(struct dsa_switch * ds,int port,struct phylink_config * config)1363dda1c257SRussell King (Oracle) static void b53_phylink_get_caps(struct dsa_switch *ds, int port,
1364dda1c257SRussell King (Oracle) struct phylink_config *config)
1365dda1c257SRussell King (Oracle) {
1366dda1c257SRussell King (Oracle) struct b53_device *dev = ds->priv;
1367dda1c257SRussell King (Oracle)
1368dda1c257SRussell King (Oracle) /* Internal ports need GMII for PHYLIB */
1369dda1c257SRussell King (Oracle) __set_bit(PHY_INTERFACE_MODE_GMII, config->supported_interfaces);
1370dda1c257SRussell King (Oracle)
1371dda1c257SRussell King (Oracle) /* These switches appear to support MII and RevMII too, but beyond
1372dda1c257SRussell King (Oracle) * this, the code gives very few clues. FIXME: We probably need more
1373dda1c257SRussell King (Oracle) * interface modes here.
137425179f8fSRussell King (Oracle) *
137525179f8fSRussell King (Oracle) * According to b53_srab_mux_init(), ports 3..5 can support:
137625179f8fSRussell King (Oracle) * SGMII, MII, GMII, RGMII or INTERNAL depending on the MUX setting.
137725179f8fSRussell King (Oracle) * However, the interface mode read from the MUX configuration is
137825179f8fSRussell King (Oracle) * not passed back to DSA, so phylink uses NA.
137925179f8fSRussell King (Oracle) * DT can specify RGMII for ports 0, 1.
138025179f8fSRussell King (Oracle) * For MDIO, port 8 can be RGMII_TXID.
1381dda1c257SRussell King (Oracle) */
1382dda1c257SRussell King (Oracle) __set_bit(PHY_INTERFACE_MODE_MII, config->supported_interfaces);
1383dda1c257SRussell King (Oracle) __set_bit(PHY_INTERFACE_MODE_REVMII, config->supported_interfaces);
1384dda1c257SRussell King (Oracle)
1385dda1c257SRussell King (Oracle) config->mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE |
1386dda1c257SRussell King (Oracle) MAC_10 | MAC_100;
1387dda1c257SRussell King (Oracle)
138825179f8fSRussell King (Oracle) /* 5325/5365 are not capable of gigabit speeds, everything else is.
138925179f8fSRussell King (Oracle) * Note: the original code also exclulded Gigagbit for MII, RevMII
139025179f8fSRussell King (Oracle) * and 802.3z modes. MII and RevMII are not able to work above 100M,
139125179f8fSRussell King (Oracle) * so will be excluded by the generic validator implementation.
139225179f8fSRussell King (Oracle) * However, the exclusion of Gigabit for 802.3z just seems wrong.
139325179f8fSRussell King (Oracle) */
1394dda1c257SRussell King (Oracle) if (!(is5325(dev) || is5365(dev)))
1395dda1c257SRussell King (Oracle) config->mac_capabilities |= MAC_1000;
1396dda1c257SRussell King (Oracle)
1397dda1c257SRussell King (Oracle) /* Get the implementation specific capabilities */
1398dda1c257SRussell King (Oracle) if (dev->ops->phylink_get_caps)
1399dda1c257SRussell King (Oracle) dev->ops->phylink_get_caps(dev, port, config);
1400dda1c257SRussell King (Oracle) }
1401dda1c257SRussell King (Oracle)
b53_phylink_mac_select_pcs(struct dsa_switch * ds,int port,phy_interface_t interface)140279396934SRussell King (Oracle) static struct phylink_pcs *b53_phylink_mac_select_pcs(struct dsa_switch *ds,
140379396934SRussell King (Oracle) int port,
140479396934SRussell King (Oracle) phy_interface_t interface)
1405a8e8b985SFlorian Fainelli {
14060e01491dSFlorian Fainelli struct b53_device *dev = ds->priv;
1407a8e8b985SFlorian Fainelli
140879396934SRussell King (Oracle) if (!dev->ops->phylink_mac_select_pcs)
140979396934SRussell King (Oracle) return NULL;
14100e01491dSFlorian Fainelli
141179396934SRussell King (Oracle) return dev->ops->phylink_mac_select_pcs(dev, port, interface);
1412a8e8b985SFlorian Fainelli }
1413a8e8b985SFlorian Fainelli
b53_phylink_mac_config(struct dsa_switch * ds,int port,unsigned int mode,const struct phylink_link_state * state)1414a8e8b985SFlorian Fainelli void b53_phylink_mac_config(struct dsa_switch *ds, int port,
1415a8e8b985SFlorian Fainelli unsigned int mode,
1416a8e8b985SFlorian Fainelli const struct phylink_link_state *state)
1417a8e8b985SFlorian Fainelli {
1418a8e8b985SFlorian Fainelli }
1419a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_config);
1420a8e8b985SFlorian Fainelli
b53_phylink_mac_link_down(struct dsa_switch * ds,int port,unsigned int mode,phy_interface_t interface)1421a8e8b985SFlorian Fainelli void b53_phylink_mac_link_down(struct dsa_switch *ds, int port,
1422a8e8b985SFlorian Fainelli unsigned int mode,
1423a8e8b985SFlorian Fainelli phy_interface_t interface)
1424a8e8b985SFlorian Fainelli {
1425a8e8b985SFlorian Fainelli struct b53_device *dev = ds->priv;
1426a8e8b985SFlorian Fainelli
1427a8e8b985SFlorian Fainelli if (mode == MLO_AN_PHY)
1428a8e8b985SFlorian Fainelli return;
1429a8e8b985SFlorian Fainelli
1430a8e8b985SFlorian Fainelli if (mode == MLO_AN_FIXED) {
1431a8e8b985SFlorian Fainelli b53_force_link(dev, port, false);
1432a8e8b985SFlorian Fainelli return;
1433a8e8b985SFlorian Fainelli }
14340e01491dSFlorian Fainelli
14350e01491dSFlorian Fainelli if (phy_interface_mode_is_8023z(interface) &&
14360e01491dSFlorian Fainelli dev->ops->serdes_link_set)
14370e01491dSFlorian Fainelli dev->ops->serdes_link_set(dev, port, mode, interface, false);
1438a8e8b985SFlorian Fainelli }
1439a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_link_down);
1440a8e8b985SFlorian Fainelli
b53_phylink_mac_link_up(struct dsa_switch * ds,int port,unsigned int mode,phy_interface_t interface,struct phy_device * phydev,int speed,int duplex,bool tx_pause,bool rx_pause)1441a8e8b985SFlorian Fainelli void b53_phylink_mac_link_up(struct dsa_switch *ds, int port,
1442a8e8b985SFlorian Fainelli unsigned int mode,
1443a8e8b985SFlorian Fainelli phy_interface_t interface,
14445b502a7bSRussell King struct phy_device *phydev,
14455b502a7bSRussell King int speed, int duplex,
14465b502a7bSRussell King bool tx_pause, bool rx_pause)
1447a8e8b985SFlorian Fainelli {
1448a8e8b985SFlorian Fainelli struct b53_device *dev = ds->priv;
1449a8e8b985SFlorian Fainelli
1450ce3bf948SÁlvaro Fernández Rojas if (is63xx(dev) && port >= B53_63XX_RGMII0)
1451ce3bf948SÁlvaro Fernández Rojas b53_adjust_63xx_rgmii(ds, port, interface);
1452ce3bf948SÁlvaro Fernández Rojas
1453a8e8b985SFlorian Fainelli if (mode == MLO_AN_PHY)
1454a8e8b985SFlorian Fainelli return;
1455a8e8b985SFlorian Fainelli
1456a8e8b985SFlorian Fainelli if (mode == MLO_AN_FIXED) {
1457ab017b79SRussell King b53_force_port_config(dev, port, speed, duplex,
1458ab017b79SRussell King tx_pause, rx_pause);
1459a8e8b985SFlorian Fainelli b53_force_link(dev, port, true);
1460a8e8b985SFlorian Fainelli return;
1461a8e8b985SFlorian Fainelli }
14620e01491dSFlorian Fainelli
14630e01491dSFlorian Fainelli if (phy_interface_mode_is_8023z(interface) &&
14640e01491dSFlorian Fainelli dev->ops->serdes_link_set)
14650e01491dSFlorian Fainelli dev->ops->serdes_link_set(dev, port, mode, interface, true);
1466a8e8b985SFlorian Fainelli }
1467a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_link_up);
1468a8e8b985SFlorian Fainelli
b53_vlan_filtering(struct dsa_switch * ds,int port,bool vlan_filtering,struct netlink_ext_ack * extack)146989153ed6SVladimir Oltean int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering,
147089153ed6SVladimir Oltean struct netlink_ext_ack *extack)
1471a2482d2cSFlorian Fainelli {
1472dad8d7c6SFlorian Fainelli struct b53_device *dev = ds->priv;
1473dad8d7c6SFlorian Fainelli
1474ee47ed08SFlorian Fainelli b53_enable_vlan(dev, port, dev->vlan_enabled, vlan_filtering);
1475dad8d7c6SFlorian Fainelli
1476a2482d2cSFlorian Fainelli return 0;
1477a2482d2cSFlorian Fainelli }
14783117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_filtering);
1479a2482d2cSFlorian Fainelli
b53_vlan_prepare(struct dsa_switch * ds,int port,const struct switchdev_obj_port_vlan * vlan)14801958d581SVladimir Oltean static int b53_vlan_prepare(struct dsa_switch *ds, int port,
148180e02360SVivien Didelot const struct switchdev_obj_port_vlan *vlan)
1482a2482d2cSFlorian Fainelli {
148304bed143SVivien Didelot struct b53_device *dev = ds->priv;
1484a2482d2cSFlorian Fainelli
1485b7a9e0daSVladimir Oltean if ((is5325(dev) || is5365(dev)) && vlan->vid == 0)
1486a2482d2cSFlorian Fainelli return -EOPNOTSUPP;
1487a2482d2cSFlorian Fainelli
148888631864SFlorian Fainelli /* Port 7 on 7278 connects to the ASP's UniMAC which is not capable of
148988631864SFlorian Fainelli * receiving VLAN tagged frames at all, we can still allow the port to
149088631864SFlorian Fainelli * be configured for egress untagged.
149188631864SFlorian Fainelli */
149288631864SFlorian Fainelli if (dev->chip_id == BCM7278_DEVICE_ID && port == 7 &&
149388631864SFlorian Fainelli !(vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED))
149488631864SFlorian Fainelli return -EINVAL;
149588631864SFlorian Fainelli
14960fe2f273SJakub Kicinski if (vlan->vid >= dev->num_vlans)
1497a2482d2cSFlorian Fainelli return -ERANGE;
1498a2482d2cSFlorian Fainelli
1499ee47ed08SFlorian Fainelli b53_enable_vlan(dev, port, true, ds->vlan_filtering);
1500a2482d2cSFlorian Fainelli
1501a2482d2cSFlorian Fainelli return 0;
1502a2482d2cSFlorian Fainelli }
1503a2482d2cSFlorian Fainelli
b53_vlan_add(struct dsa_switch * ds,int port,const struct switchdev_obj_port_vlan * vlan,struct netlink_ext_ack * extack)15041958d581SVladimir Oltean int b53_vlan_add(struct dsa_switch *ds, int port,
150531046a5fSVladimir Oltean const struct switchdev_obj_port_vlan *vlan,
150631046a5fSVladimir Oltean struct netlink_ext_ack *extack)
1507a2482d2cSFlorian Fainelli {
150804bed143SVivien Didelot struct b53_device *dev = ds->priv;
1509a2482d2cSFlorian Fainelli bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1510a2482d2cSFlorian Fainelli bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1511a2482d2cSFlorian Fainelli struct b53_vlan *vl;
15121958d581SVladimir Oltean int err;
15131958d581SVladimir Oltean
15141958d581SVladimir Oltean err = b53_vlan_prepare(ds, port, vlan);
15151958d581SVladimir Oltean if (err)
15161958d581SVladimir Oltean return err;
1517a2482d2cSFlorian Fainelli
1518b7a9e0daSVladimir Oltean vl = &dev->vlans[vlan->vid];
1519a2482d2cSFlorian Fainelli
1520b7a9e0daSVladimir Oltean b53_get_vlan_entry(dev, vlan->vid, vl);
1521a2482d2cSFlorian Fainelli
1522b7a9e0daSVladimir Oltean if (vlan->vid == 0 && vlan->vid == b53_default_pvid(dev))
1523d965a543SFlorian Fainelli untagged = true;
1524d965a543SFlorian Fainelli
1525c499696eSFlorian Fainelli vl->members |= BIT(port);
15262c32a3d3SFlorian Fainelli if (untagged && !b53_vlan_port_needs_forced_tagged(ds, port))
1527e47112d9SFlorian Fainelli vl->untag |= BIT(port);
1528a2482d2cSFlorian Fainelli else
1529e47112d9SFlorian Fainelli vl->untag &= ~BIT(port);
1530a2482d2cSFlorian Fainelli
1531b7a9e0daSVladimir Oltean b53_set_vlan_entry(dev, vlan->vid, vl);
1532b7a9e0daSVladimir Oltean b53_fast_age_vlan(dev, vlan->vid);
1533a2482d2cSFlorian Fainelli
153410163aaeSFlorian Fainelli if (pvid && !dsa_is_cpu_port(ds, port)) {
1535a2482d2cSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port),
1536b7a9e0daSVladimir Oltean vlan->vid);
1537b7a9e0daSVladimir Oltean b53_fast_age_vlan(dev, vlan->vid);
1538a2482d2cSFlorian Fainelli }
15391958d581SVladimir Oltean
15401958d581SVladimir Oltean return 0;
1541a2482d2cSFlorian Fainelli }
15423117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_add);
1543a2482d2cSFlorian Fainelli
b53_vlan_del(struct dsa_switch * ds,int port,const struct switchdev_obj_port_vlan * vlan)15443117455dSFlorian Fainelli int b53_vlan_del(struct dsa_switch *ds, int port,
1545a2482d2cSFlorian Fainelli const struct switchdev_obj_port_vlan *vlan)
1546a2482d2cSFlorian Fainelli {
154704bed143SVivien Didelot struct b53_device *dev = ds->priv;
1548a2482d2cSFlorian Fainelli bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1549a2482d2cSFlorian Fainelli struct b53_vlan *vl;
1550a2482d2cSFlorian Fainelli u16 pvid;
1551a2482d2cSFlorian Fainelli
1552a2482d2cSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &pvid);
1553a2482d2cSFlorian Fainelli
1554b7a9e0daSVladimir Oltean vl = &dev->vlans[vlan->vid];
1555a2482d2cSFlorian Fainelli
1556b7a9e0daSVladimir Oltean b53_get_vlan_entry(dev, vlan->vid, vl);
1557a2482d2cSFlorian Fainelli
1558a2482d2cSFlorian Fainelli vl->members &= ~BIT(port);
1559a2482d2cSFlorian Fainelli
1560b7a9e0daSVladimir Oltean if (pvid == vlan->vid)
1561fea83353SFlorian Fainelli pvid = b53_default_pvid(dev);
1562a2482d2cSFlorian Fainelli
15632c32a3d3SFlorian Fainelli if (untagged && !b53_vlan_port_needs_forced_tagged(ds, port))
1564a2482d2cSFlorian Fainelli vl->untag &= ~(BIT(port));
1565a2482d2cSFlorian Fainelli
1566b7a9e0daSVladimir Oltean b53_set_vlan_entry(dev, vlan->vid, vl);
1567b7a9e0daSVladimir Oltean b53_fast_age_vlan(dev, vlan->vid);
1568a2482d2cSFlorian Fainelli
1569a2482d2cSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), pvid);
1570a2482d2cSFlorian Fainelli b53_fast_age_vlan(dev, pvid);
1571a2482d2cSFlorian Fainelli
1572a2482d2cSFlorian Fainelli return 0;
1573a2482d2cSFlorian Fainelli }
15743117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_del);
1575a2482d2cSFlorian Fainelli
1576f7eb4a1cSVladimir Oltean /* Address Resolution Logic routines. Caller must hold &dev->arl_mutex. */
b53_arl_op_wait(struct b53_device * dev)15771da6df85SFlorian Fainelli static int b53_arl_op_wait(struct b53_device *dev)
15781da6df85SFlorian Fainelli {
15791da6df85SFlorian Fainelli unsigned int timeout = 10;
15801da6df85SFlorian Fainelli u8 reg;
15811da6df85SFlorian Fainelli
15821da6df85SFlorian Fainelli do {
15831da6df85SFlorian Fainelli b53_read8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, ®);
15841da6df85SFlorian Fainelli if (!(reg & ARLTBL_START_DONE))
15851da6df85SFlorian Fainelli return 0;
15861da6df85SFlorian Fainelli
15871da6df85SFlorian Fainelli usleep_range(1000, 2000);
15881da6df85SFlorian Fainelli } while (timeout--);
15891da6df85SFlorian Fainelli
15901da6df85SFlorian Fainelli dev_warn(dev->dev, "timeout waiting for ARL to finish: 0x%02x\n", reg);
15911da6df85SFlorian Fainelli
15921da6df85SFlorian Fainelli return -ETIMEDOUT;
15931da6df85SFlorian Fainelli }
15941da6df85SFlorian Fainelli
b53_arl_rw_op(struct b53_device * dev,unsigned int op)15951da6df85SFlorian Fainelli static int b53_arl_rw_op(struct b53_device *dev, unsigned int op)
15961da6df85SFlorian Fainelli {
15971da6df85SFlorian Fainelli u8 reg;
15981da6df85SFlorian Fainelli
15991da6df85SFlorian Fainelli if (op > ARLTBL_RW)
16001da6df85SFlorian Fainelli return -EINVAL;
16011da6df85SFlorian Fainelli
16021da6df85SFlorian Fainelli b53_read8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, ®);
16031da6df85SFlorian Fainelli reg |= ARLTBL_START_DONE;
16041da6df85SFlorian Fainelli if (op)
16051da6df85SFlorian Fainelli reg |= ARLTBL_RW;
16061da6df85SFlorian Fainelli else
16071da6df85SFlorian Fainelli reg &= ~ARLTBL_RW;
160864fec949SFlorian Fainelli if (dev->vlan_enabled)
160964fec949SFlorian Fainelli reg &= ~ARLTBL_IVL_SVL_SELECT;
161064fec949SFlorian Fainelli else
161164fec949SFlorian Fainelli reg |= ARLTBL_IVL_SVL_SELECT;
16121da6df85SFlorian Fainelli b53_write8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, reg);
16131da6df85SFlorian Fainelli
16141da6df85SFlorian Fainelli return b53_arl_op_wait(dev);
16151da6df85SFlorian Fainelli }
16161da6df85SFlorian Fainelli
b53_arl_read(struct b53_device * dev,u64 mac,u16 vid,struct b53_arl_entry * ent,u8 * idx)16171da6df85SFlorian Fainelli static int b53_arl_read(struct b53_device *dev, u64 mac,
1618ef2a0bd9SFlorian Fainelli u16 vid, struct b53_arl_entry *ent, u8 *idx)
16191da6df85SFlorian Fainelli {
16206344dbdeSFlorian Fainelli DECLARE_BITMAP(free_bins, B53_ARLTBL_MAX_BIN_ENTRIES);
16211da6df85SFlorian Fainelli unsigned int i;
16221da6df85SFlorian Fainelli int ret;
16231da6df85SFlorian Fainelli
16241da6df85SFlorian Fainelli ret = b53_arl_op_wait(dev);
16251da6df85SFlorian Fainelli if (ret)
16261da6df85SFlorian Fainelli return ret;
16271da6df85SFlorian Fainelli
1628673e69a6SFlorian Fainelli bitmap_zero(free_bins, dev->num_arl_bins);
16296344dbdeSFlorian Fainelli
16301da6df85SFlorian Fainelli /* Read the bins */
1631673e69a6SFlorian Fainelli for (i = 0; i < dev->num_arl_bins; i++) {
16321da6df85SFlorian Fainelli u64 mac_vid;
16331da6df85SFlorian Fainelli u32 fwd_entry;
16341da6df85SFlorian Fainelli
16351da6df85SFlorian Fainelli b53_read64(dev, B53_ARLIO_PAGE,
16361da6df85SFlorian Fainelli B53_ARLTBL_MAC_VID_ENTRY(i), &mac_vid);
16371da6df85SFlorian Fainelli b53_read32(dev, B53_ARLIO_PAGE,
16381da6df85SFlorian Fainelli B53_ARLTBL_DATA_ENTRY(i), &fwd_entry);
16391da6df85SFlorian Fainelli b53_arl_to_entry(ent, mac_vid, fwd_entry);
16401da6df85SFlorian Fainelli
16416344dbdeSFlorian Fainelli if (!(fwd_entry & ARLTBL_VALID)) {
16426344dbdeSFlorian Fainelli set_bit(i, free_bins);
16431da6df85SFlorian Fainelli continue;
16446344dbdeSFlorian Fainelli }
16451da6df85SFlorian Fainelli if ((mac_vid & ARLTBL_MAC_MASK) != mac)
16461da6df85SFlorian Fainelli continue;
16472e97b0cdSFlorian Fainelli if (dev->vlan_enabled &&
16482e97b0cdSFlorian Fainelli ((mac_vid >> ARLTBL_VID_S) & ARLTBL_VID_MASK) != vid)
16492e97b0cdSFlorian Fainelli continue;
16501da6df85SFlorian Fainelli *idx = i;
16516344dbdeSFlorian Fainelli return 0;
16521da6df85SFlorian Fainelli }
16531da6df85SFlorian Fainelli
1654673e69a6SFlorian Fainelli *idx = find_first_bit(free_bins, dev->num_arl_bins);
1655e18e5cbcSYury Norov return *idx >= dev->num_arl_bins ? -ENOSPC : -ENOENT;
16561da6df85SFlorian Fainelli }
16571da6df85SFlorian Fainelli
b53_arl_op(struct b53_device * dev,int op,int port,const unsigned char * addr,u16 vid,bool is_valid)16581da6df85SFlorian Fainelli static int b53_arl_op(struct b53_device *dev, int op, int port,
16591da6df85SFlorian Fainelli const unsigned char *addr, u16 vid, bool is_valid)
16601da6df85SFlorian Fainelli {
16611da6df85SFlorian Fainelli struct b53_arl_entry ent;
16621da6df85SFlorian Fainelli u32 fwd_entry;
16631da6df85SFlorian Fainelli u64 mac, mac_vid = 0;
16641da6df85SFlorian Fainelli u8 idx = 0;
16651da6df85SFlorian Fainelli int ret;
16661da6df85SFlorian Fainelli
16671da6df85SFlorian Fainelli /* Convert the array into a 64-bit MAC */
16684b92ea81SFlorian Fainelli mac = ether_addr_to_u64(addr);
16691da6df85SFlorian Fainelli
16701da6df85SFlorian Fainelli /* Perform a read for the given MAC and VID */
16711da6df85SFlorian Fainelli b53_write48(dev, B53_ARLIO_PAGE, B53_MAC_ADDR_IDX, mac);
16721da6df85SFlorian Fainelli b53_write16(dev, B53_ARLIO_PAGE, B53_VLAN_ID_IDX, vid);
16731da6df85SFlorian Fainelli
16741da6df85SFlorian Fainelli /* Issue a read operation for this MAC */
16751da6df85SFlorian Fainelli ret = b53_arl_rw_op(dev, 1);
16761da6df85SFlorian Fainelli if (ret)
16771da6df85SFlorian Fainelli return ret;
16781da6df85SFlorian Fainelli
1679ef2a0bd9SFlorian Fainelli ret = b53_arl_read(dev, mac, vid, &ent, &idx);
1680ef2a0bd9SFlorian Fainelli
16811da6df85SFlorian Fainelli /* If this is a read, just finish now */
16821da6df85SFlorian Fainelli if (op)
16831da6df85SFlorian Fainelli return ret;
16841da6df85SFlorian Fainelli
16856344dbdeSFlorian Fainelli switch (ret) {
1686774d977aSTom Rix case -ETIMEDOUT:
1687774d977aSTom Rix return ret;
16886344dbdeSFlorian Fainelli case -ENOSPC:
16896344dbdeSFlorian Fainelli dev_dbg(dev->dev, "{%pM,%.4d} no space left in ARL\n",
16906344dbdeSFlorian Fainelli addr, vid);
16916344dbdeSFlorian Fainelli return is_valid ? ret : 0;
16926344dbdeSFlorian Fainelli case -ENOENT:
16931da6df85SFlorian Fainelli /* We could not find a matching MAC, so reset to a new entry */
16946344dbdeSFlorian Fainelli dev_dbg(dev->dev, "{%pM,%.4d} not found, using idx: %d\n",
16956344dbdeSFlorian Fainelli addr, vid, idx);
16961da6df85SFlorian Fainelli fwd_entry = 0;
16976344dbdeSFlorian Fainelli break;
16986344dbdeSFlorian Fainelli default:
16996344dbdeSFlorian Fainelli dev_dbg(dev->dev, "{%pM,%.4d} found, using idx: %d\n",
17006344dbdeSFlorian Fainelli addr, vid, idx);
17016344dbdeSFlorian Fainelli break;
17021da6df85SFlorian Fainelli }
17031da6df85SFlorian Fainelli
17045d65b64aSFlorian Fainelli /* For multicast address, the port is a bitmask and the validity
17055d65b64aSFlorian Fainelli * is determined by having at least one port being still active
17065d65b64aSFlorian Fainelli */
17075d65b64aSFlorian Fainelli if (!is_multicast_ether_addr(addr)) {
17081da6df85SFlorian Fainelli ent.port = port;
17091da6df85SFlorian Fainelli ent.is_valid = is_valid;
17105d65b64aSFlorian Fainelli } else {
17115d65b64aSFlorian Fainelli if (is_valid)
17125d65b64aSFlorian Fainelli ent.port |= BIT(port);
17135d65b64aSFlorian Fainelli else
17145d65b64aSFlorian Fainelli ent.port &= ~BIT(port);
17155d65b64aSFlorian Fainelli
17165d65b64aSFlorian Fainelli ent.is_valid = !!(ent.port);
17175d65b64aSFlorian Fainelli }
17185d65b64aSFlorian Fainelli
17191da6df85SFlorian Fainelli ent.vid = vid;
17201da6df85SFlorian Fainelli ent.is_static = true;
17215d65b64aSFlorian Fainelli ent.is_age = false;
17221da6df85SFlorian Fainelli memcpy(ent.mac, addr, ETH_ALEN);
17231da6df85SFlorian Fainelli b53_arl_from_entry(&mac_vid, &fwd_entry, &ent);
17241da6df85SFlorian Fainelli
17251da6df85SFlorian Fainelli b53_write64(dev, B53_ARLIO_PAGE,
17261da6df85SFlorian Fainelli B53_ARLTBL_MAC_VID_ENTRY(idx), mac_vid);
17271da6df85SFlorian Fainelli b53_write32(dev, B53_ARLIO_PAGE,
17281da6df85SFlorian Fainelli B53_ARLTBL_DATA_ENTRY(idx), fwd_entry);
17291da6df85SFlorian Fainelli
17301da6df85SFlorian Fainelli return b53_arl_rw_op(dev, 0);
17311da6df85SFlorian Fainelli }
17321da6df85SFlorian Fainelli
b53_fdb_add(struct dsa_switch * ds,int port,const unsigned char * addr,u16 vid,struct dsa_db db)17331b6dd556SArkadi Sharshevsky int b53_fdb_add(struct dsa_switch *ds, int port,
1734c2693363SVladimir Oltean const unsigned char *addr, u16 vid,
1735c2693363SVladimir Oltean struct dsa_db db)
17361da6df85SFlorian Fainelli {
173704bed143SVivien Didelot struct b53_device *priv = ds->priv;
1738f7eb4a1cSVladimir Oltean int ret;
17391da6df85SFlorian Fainelli
17401da6df85SFlorian Fainelli /* 5325 and 5365 require some more massaging, but could
17411da6df85SFlorian Fainelli * be supported eventually
17421da6df85SFlorian Fainelli */
17431da6df85SFlorian Fainelli if (is5325(priv) || is5365(priv))
17441da6df85SFlorian Fainelli return -EOPNOTSUPP;
17451da6df85SFlorian Fainelli
1746f7eb4a1cSVladimir Oltean mutex_lock(&priv->arl_mutex);
1747f7eb4a1cSVladimir Oltean ret = b53_arl_op(priv, 0, port, addr, vid, true);
1748f7eb4a1cSVladimir Oltean mutex_unlock(&priv->arl_mutex);
1749f7eb4a1cSVladimir Oltean
1750f7eb4a1cSVladimir Oltean return ret;
17511da6df85SFlorian Fainelli }
17523117455dSFlorian Fainelli EXPORT_SYMBOL(b53_fdb_add);
17531da6df85SFlorian Fainelli
b53_fdb_del(struct dsa_switch * ds,int port,const unsigned char * addr,u16 vid,struct dsa_db db)17543117455dSFlorian Fainelli int b53_fdb_del(struct dsa_switch *ds, int port,
1755c2693363SVladimir Oltean const unsigned char *addr, u16 vid,
1756c2693363SVladimir Oltean struct dsa_db db)
17571da6df85SFlorian Fainelli {
175804bed143SVivien Didelot struct b53_device *priv = ds->priv;
1759f7eb4a1cSVladimir Oltean int ret;
17601da6df85SFlorian Fainelli
1761f7eb4a1cSVladimir Oltean mutex_lock(&priv->arl_mutex);
1762f7eb4a1cSVladimir Oltean ret = b53_arl_op(priv, 0, port, addr, vid, false);
1763f7eb4a1cSVladimir Oltean mutex_unlock(&priv->arl_mutex);
1764f7eb4a1cSVladimir Oltean
1765f7eb4a1cSVladimir Oltean return ret;
17661da6df85SFlorian Fainelli }
17673117455dSFlorian Fainelli EXPORT_SYMBOL(b53_fdb_del);
17681da6df85SFlorian Fainelli
b53_arl_search_wait(struct b53_device * dev)17691da6df85SFlorian Fainelli static int b53_arl_search_wait(struct b53_device *dev)
17701da6df85SFlorian Fainelli {
17711da6df85SFlorian Fainelli unsigned int timeout = 1000;
17721da6df85SFlorian Fainelli u8 reg;
17731da6df85SFlorian Fainelli
17741da6df85SFlorian Fainelli do {
17751da6df85SFlorian Fainelli b53_read8(dev, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, ®);
17761da6df85SFlorian Fainelli if (!(reg & ARL_SRCH_STDN))
17771da6df85SFlorian Fainelli return 0;
17781da6df85SFlorian Fainelli
17791da6df85SFlorian Fainelli if (reg & ARL_SRCH_VLID)
17801da6df85SFlorian Fainelli return 0;
17811da6df85SFlorian Fainelli
17821da6df85SFlorian Fainelli usleep_range(1000, 2000);
17831da6df85SFlorian Fainelli } while (timeout--);
17841da6df85SFlorian Fainelli
17851da6df85SFlorian Fainelli return -ETIMEDOUT;
17861da6df85SFlorian Fainelli }
17871da6df85SFlorian Fainelli
b53_arl_search_rd(struct b53_device * dev,u8 idx,struct b53_arl_entry * ent)17881da6df85SFlorian Fainelli static void b53_arl_search_rd(struct b53_device *dev, u8 idx,
17891da6df85SFlorian Fainelli struct b53_arl_entry *ent)
17901da6df85SFlorian Fainelli {
17911da6df85SFlorian Fainelli u64 mac_vid;
17921da6df85SFlorian Fainelli u32 fwd_entry;
17931da6df85SFlorian Fainelli
17941da6df85SFlorian Fainelli b53_read64(dev, B53_ARLIO_PAGE,
17951da6df85SFlorian Fainelli B53_ARL_SRCH_RSTL_MACVID(idx), &mac_vid);
17961da6df85SFlorian Fainelli b53_read32(dev, B53_ARLIO_PAGE,
17971da6df85SFlorian Fainelli B53_ARL_SRCH_RSTL(idx), &fwd_entry);
17981da6df85SFlorian Fainelli b53_arl_to_entry(ent, mac_vid, fwd_entry);
17991da6df85SFlorian Fainelli }
18001da6df85SFlorian Fainelli
b53_fdb_copy(int port,const struct b53_arl_entry * ent,dsa_fdb_dump_cb_t * cb,void * data)1801e6cbef0cSVivien Didelot static int b53_fdb_copy(int port, const struct b53_arl_entry *ent,
18022bedde1aSArkadi Sharshevsky dsa_fdb_dump_cb_t *cb, void *data)
18031da6df85SFlorian Fainelli {
18041da6df85SFlorian Fainelli if (!ent->is_valid)
18051da6df85SFlorian Fainelli return 0;
18061da6df85SFlorian Fainelli
18071da6df85SFlorian Fainelli if (port != ent->port)
18081da6df85SFlorian Fainelli return 0;
18091da6df85SFlorian Fainelli
18102bedde1aSArkadi Sharshevsky return cb(ent->mac, ent->vid, ent->is_static, data);
18111da6df85SFlorian Fainelli }
18121da6df85SFlorian Fainelli
b53_fdb_dump(struct dsa_switch * ds,int port,dsa_fdb_dump_cb_t * cb,void * data)18133117455dSFlorian Fainelli int b53_fdb_dump(struct dsa_switch *ds, int port,
18142bedde1aSArkadi Sharshevsky dsa_fdb_dump_cb_t *cb, void *data)
18151da6df85SFlorian Fainelli {
181604bed143SVivien Didelot struct b53_device *priv = ds->priv;
18171da6df85SFlorian Fainelli struct b53_arl_entry results[2];
18181da6df85SFlorian Fainelli unsigned int count = 0;
18191da6df85SFlorian Fainelli int ret;
18201da6df85SFlorian Fainelli u8 reg;
18211da6df85SFlorian Fainelli
1822f7eb4a1cSVladimir Oltean mutex_lock(&priv->arl_mutex);
1823f7eb4a1cSVladimir Oltean
18241da6df85SFlorian Fainelli /* Start search operation */
18251da6df85SFlorian Fainelli reg = ARL_SRCH_STDN;
18261da6df85SFlorian Fainelli b53_write8(priv, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, reg);
18271da6df85SFlorian Fainelli
18281da6df85SFlorian Fainelli do {
18291da6df85SFlorian Fainelli ret = b53_arl_search_wait(priv);
18301da6df85SFlorian Fainelli if (ret)
1831f7eb4a1cSVladimir Oltean break;
18321da6df85SFlorian Fainelli
18331da6df85SFlorian Fainelli b53_arl_search_rd(priv, 0, &results[0]);
18342bedde1aSArkadi Sharshevsky ret = b53_fdb_copy(port, &results[0], cb, data);
18351da6df85SFlorian Fainelli if (ret)
1836f7eb4a1cSVladimir Oltean break;
18371da6df85SFlorian Fainelli
1838673e69a6SFlorian Fainelli if (priv->num_arl_bins > 2) {
18391da6df85SFlorian Fainelli b53_arl_search_rd(priv, 1, &results[1]);
18402bedde1aSArkadi Sharshevsky ret = b53_fdb_copy(port, &results[1], cb, data);
18411da6df85SFlorian Fainelli if (ret)
1842f7eb4a1cSVladimir Oltean break;
18431da6df85SFlorian Fainelli
18441da6df85SFlorian Fainelli if (!results[0].is_valid && !results[1].is_valid)
18451da6df85SFlorian Fainelli break;
18461da6df85SFlorian Fainelli }
18471da6df85SFlorian Fainelli
1848cd169d79SFlorian Fainelli } while (count++ < b53_max_arl_entries(priv) / 2);
18491da6df85SFlorian Fainelli
1850f7eb4a1cSVladimir Oltean mutex_unlock(&priv->arl_mutex);
1851f7eb4a1cSVladimir Oltean
18521da6df85SFlorian Fainelli return 0;
18531da6df85SFlorian Fainelli }
18543117455dSFlorian Fainelli EXPORT_SYMBOL(b53_fdb_dump);
18551da6df85SFlorian Fainelli
b53_mdb_add(struct dsa_switch * ds,int port,const struct switchdev_obj_port_mdb * mdb,struct dsa_db db)1856a52b2da7SVladimir Oltean int b53_mdb_add(struct dsa_switch *ds, int port,
1857c2693363SVladimir Oltean const struct switchdev_obj_port_mdb *mdb,
1858c2693363SVladimir Oltean struct dsa_db db)
18595d65b64aSFlorian Fainelli {
18605d65b64aSFlorian Fainelli struct b53_device *priv = ds->priv;
1861f7eb4a1cSVladimir Oltean int ret;
18625d65b64aSFlorian Fainelli
18635d65b64aSFlorian Fainelli /* 5325 and 5365 require some more massaging, but could
18645d65b64aSFlorian Fainelli * be supported eventually
18655d65b64aSFlorian Fainelli */
18665d65b64aSFlorian Fainelli if (is5325(priv) || is5365(priv))
18675d65b64aSFlorian Fainelli return -EOPNOTSUPP;
18685d65b64aSFlorian Fainelli
1869f7eb4a1cSVladimir Oltean mutex_lock(&priv->arl_mutex);
1870f7eb4a1cSVladimir Oltean ret = b53_arl_op(priv, 0, port, mdb->addr, mdb->vid, true);
1871f7eb4a1cSVladimir Oltean mutex_unlock(&priv->arl_mutex);
1872f7eb4a1cSVladimir Oltean
1873f7eb4a1cSVladimir Oltean return ret;
18745d65b64aSFlorian Fainelli }
18755d65b64aSFlorian Fainelli EXPORT_SYMBOL(b53_mdb_add);
18765d65b64aSFlorian Fainelli
b53_mdb_del(struct dsa_switch * ds,int port,const struct switchdev_obj_port_mdb * mdb,struct dsa_db db)18775d65b64aSFlorian Fainelli int b53_mdb_del(struct dsa_switch *ds, int port,
1878c2693363SVladimir Oltean const struct switchdev_obj_port_mdb *mdb,
1879c2693363SVladimir Oltean struct dsa_db db)
18805d65b64aSFlorian Fainelli {
18815d65b64aSFlorian Fainelli struct b53_device *priv = ds->priv;
18825d65b64aSFlorian Fainelli int ret;
18835d65b64aSFlorian Fainelli
1884f7eb4a1cSVladimir Oltean mutex_lock(&priv->arl_mutex);
18855d65b64aSFlorian Fainelli ret = b53_arl_op(priv, 0, port, mdb->addr, mdb->vid, false);
1886f7eb4a1cSVladimir Oltean mutex_unlock(&priv->arl_mutex);
18875d65b64aSFlorian Fainelli if (ret)
18885d65b64aSFlorian Fainelli dev_err(ds->dev, "failed to delete MDB entry\n");
18895d65b64aSFlorian Fainelli
18905d65b64aSFlorian Fainelli return ret;
18915d65b64aSFlorian Fainelli }
18925d65b64aSFlorian Fainelli EXPORT_SYMBOL(b53_mdb_del);
18935d65b64aSFlorian Fainelli
b53_br_join(struct dsa_switch * ds,int port,struct dsa_bridge bridge,bool * tx_fwd_offload,struct netlink_ext_ack * extack)1894b079922bSVladimir Oltean int b53_br_join(struct dsa_switch *ds, int port, struct dsa_bridge bridge,
189506b9cce4SVladimir Oltean bool *tx_fwd_offload, struct netlink_ext_ack *extack)
1896ff39c2d6SFlorian Fainelli {
189704bed143SVivien Didelot struct b53_device *dev = ds->priv;
189868bb8ea8SVivien Didelot s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
1899ff39c2d6SFlorian Fainelli u16 pvlan, reg;
1900ff39c2d6SFlorian Fainelli unsigned int i;
1901ff39c2d6SFlorian Fainelli
190231bfc2d4SFlorian Fainelli /* On 7278, port 7 which connects to the ASP should only receive
190331bfc2d4SFlorian Fainelli * traffic from matching CFP rules.
190431bfc2d4SFlorian Fainelli */
190531bfc2d4SFlorian Fainelli if (dev->chip_id == BCM7278_DEVICE_ID && port == 7)
190631bfc2d4SFlorian Fainelli return -EINVAL;
190731bfc2d4SFlorian Fainelli
190848aea33aSFlorian Fainelli /* Make this port leave the all VLANs join since we will have proper
190948aea33aSFlorian Fainelli * VLAN entries from now on
191048aea33aSFlorian Fainelli */
191148aea33aSFlorian Fainelli if (is58xx(dev)) {
191248aea33aSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, ®);
191348aea33aSFlorian Fainelli reg &= ~BIT(port);
191448aea33aSFlorian Fainelli if ((reg & BIT(cpu_port)) == BIT(cpu_port))
191548aea33aSFlorian Fainelli reg &= ~BIT(cpu_port);
191648aea33aSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, reg);
191748aea33aSFlorian Fainelli }
191848aea33aSFlorian Fainelli
1919ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan);
1920ff39c2d6SFlorian Fainelli
1921ff39c2d6SFlorian Fainelli b53_for_each_port(dev, i) {
1922d3eed0e5SVladimir Oltean if (!dsa_port_offloads_bridge(dsa_to_port(ds, i), &bridge))
1923ff39c2d6SFlorian Fainelli continue;
1924ff39c2d6SFlorian Fainelli
1925ff39c2d6SFlorian Fainelli /* Add this local port to the remote port VLAN control
1926ff39c2d6SFlorian Fainelli * membership and update the remote port bitmask
1927ff39c2d6SFlorian Fainelli */
1928ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), ®);
1929ff39c2d6SFlorian Fainelli reg |= BIT(port);
1930ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), reg);
1931ff39c2d6SFlorian Fainelli dev->ports[i].vlan_ctl_mask = reg;
1932ff39c2d6SFlorian Fainelli
1933ff39c2d6SFlorian Fainelli pvlan |= BIT(i);
1934ff39c2d6SFlorian Fainelli }
1935ff39c2d6SFlorian Fainelli
1936ff39c2d6SFlorian Fainelli /* Configure the local port VLAN control membership to include
1937ff39c2d6SFlorian Fainelli * remote ports and update the local port bitmask
1938ff39c2d6SFlorian Fainelli */
1939ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan);
1940ff39c2d6SFlorian Fainelli dev->ports[port].vlan_ctl_mask = pvlan;
1941ff39c2d6SFlorian Fainelli
1942ff39c2d6SFlorian Fainelli return 0;
1943ff39c2d6SFlorian Fainelli }
19443117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_join);
1945ff39c2d6SFlorian Fainelli
b53_br_leave(struct dsa_switch * ds,int port,struct dsa_bridge bridge)1946d3eed0e5SVladimir Oltean void b53_br_leave(struct dsa_switch *ds, int port, struct dsa_bridge bridge)
1947ff39c2d6SFlorian Fainelli {
194804bed143SVivien Didelot struct b53_device *dev = ds->priv;
1949a2482d2cSFlorian Fainelli struct b53_vlan *vl = &dev->vlans[0];
195068bb8ea8SVivien Didelot s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
1951ff39c2d6SFlorian Fainelli unsigned int i;
1952a2482d2cSFlorian Fainelli u16 pvlan, reg, pvid;
1953ff39c2d6SFlorian Fainelli
1954ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan);
1955ff39c2d6SFlorian Fainelli
1956ff39c2d6SFlorian Fainelli b53_for_each_port(dev, i) {
1957ff39c2d6SFlorian Fainelli /* Don't touch the remaining ports */
1958d3eed0e5SVladimir Oltean if (!dsa_port_offloads_bridge(dsa_to_port(ds, i), &bridge))
1959ff39c2d6SFlorian Fainelli continue;
1960ff39c2d6SFlorian Fainelli
1961ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), ®);
1962ff39c2d6SFlorian Fainelli reg &= ~BIT(port);
1963ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), reg);
1964ff39c2d6SFlorian Fainelli dev->ports[port].vlan_ctl_mask = reg;
1965ff39c2d6SFlorian Fainelli
1966ff39c2d6SFlorian Fainelli /* Prevent self removal to preserve isolation */
1967ff39c2d6SFlorian Fainelli if (port != i)
1968ff39c2d6SFlorian Fainelli pvlan &= ~BIT(i);
1969ff39c2d6SFlorian Fainelli }
1970ff39c2d6SFlorian Fainelli
1971ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan);
1972ff39c2d6SFlorian Fainelli dev->ports[port].vlan_ctl_mask = pvlan;
1973a2482d2cSFlorian Fainelli
1974fea83353SFlorian Fainelli pvid = b53_default_pvid(dev);
1975a2482d2cSFlorian Fainelli
197648aea33aSFlorian Fainelli /* Make this port join all VLANs without VLAN entries */
197748aea33aSFlorian Fainelli if (is58xx(dev)) {
197848aea33aSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, ®);
197948aea33aSFlorian Fainelli reg |= BIT(port);
198048aea33aSFlorian Fainelli if (!(reg & BIT(cpu_port)))
198148aea33aSFlorian Fainelli reg |= BIT(cpu_port);
198248aea33aSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, reg);
198348aea33aSFlorian Fainelli } else {
1984a2482d2cSFlorian Fainelli b53_get_vlan_entry(dev, pvid, vl);
1985c499696eSFlorian Fainelli vl->members |= BIT(port) | BIT(cpu_port);
1986c499696eSFlorian Fainelli vl->untag |= BIT(port) | BIT(cpu_port);
1987a2482d2cSFlorian Fainelli b53_set_vlan_entry(dev, pvid, vl);
1988ff39c2d6SFlorian Fainelli }
198948aea33aSFlorian Fainelli }
19903117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_leave);
1991ff39c2d6SFlorian Fainelli
b53_br_set_stp_state(struct dsa_switch * ds,int port,u8 state)19923117455dSFlorian Fainelli void b53_br_set_stp_state(struct dsa_switch *ds, int port, u8 state)
1993ff39c2d6SFlorian Fainelli {
199404bed143SVivien Didelot struct b53_device *dev = ds->priv;
1995597698f1SVivien Didelot u8 hw_state;
1996ff39c2d6SFlorian Fainelli u8 reg;
1997ff39c2d6SFlorian Fainelli
1998ff39c2d6SFlorian Fainelli switch (state) {
1999ff39c2d6SFlorian Fainelli case BR_STATE_DISABLED:
2000ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_DIS_STATE;
2001ff39c2d6SFlorian Fainelli break;
2002ff39c2d6SFlorian Fainelli case BR_STATE_LISTENING:
2003ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_LISTEN_STATE;
2004ff39c2d6SFlorian Fainelli break;
2005ff39c2d6SFlorian Fainelli case BR_STATE_LEARNING:
2006ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_LEARN_STATE;
2007ff39c2d6SFlorian Fainelli break;
2008ff39c2d6SFlorian Fainelli case BR_STATE_FORWARDING:
2009ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_FWD_STATE;
2010ff39c2d6SFlorian Fainelli break;
2011ff39c2d6SFlorian Fainelli case BR_STATE_BLOCKING:
2012ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_BLOCK_STATE;
2013ff39c2d6SFlorian Fainelli break;
2014ff39c2d6SFlorian Fainelli default:
2015ff39c2d6SFlorian Fainelli dev_err(ds->dev, "invalid STP state: %d\n", state);
2016ff39c2d6SFlorian Fainelli return;
2017ff39c2d6SFlorian Fainelli }
2018ff39c2d6SFlorian Fainelli
2019ff39c2d6SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), ®);
2020ff39c2d6SFlorian Fainelli reg &= ~PORT_CTRL_STP_STATE_MASK;
2021ff39c2d6SFlorian Fainelli reg |= hw_state;
2022ff39c2d6SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), reg);
2023ff39c2d6SFlorian Fainelli }
20243117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_set_stp_state);
2025ff39c2d6SFlorian Fainelli
b53_br_fast_age(struct dsa_switch * ds,int port)20263117455dSFlorian Fainelli void b53_br_fast_age(struct dsa_switch *ds, int port)
2027597698f1SVivien Didelot {
2028597698f1SVivien Didelot struct b53_device *dev = ds->priv;
2029597698f1SVivien Didelot
2030597698f1SVivien Didelot if (b53_fast_age_port(dev, port))
2031597698f1SVivien Didelot dev_err(ds->dev, "fast ageing failed\n");
2032597698f1SVivien Didelot }
20333117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_fast_age);
2034597698f1SVivien Didelot
b53_br_flags_pre(struct dsa_switch * ds,int port,struct switchdev_brport_flags flags,struct netlink_ext_ack * extack)2035e6dd86edSFlorian Fainelli int b53_br_flags_pre(struct dsa_switch *ds, int port,
2036a8b659e7SVladimir Oltean struct switchdev_brport_flags flags,
2037a8b659e7SVladimir Oltean struct netlink_ext_ack *extack)
203853568438SFlorian Fainelli {
2039f9b3827eSFlorian Fainelli if (flags.mask & ~(BR_FLOOD | BR_MCAST_FLOOD | BR_LEARNING))
2040a8b659e7SVladimir Oltean return -EINVAL;
204153568438SFlorian Fainelli
204253568438SFlorian Fainelli return 0;
204353568438SFlorian Fainelli }
2044e6dd86edSFlorian Fainelli EXPORT_SYMBOL(b53_br_flags_pre);
2045a8b659e7SVladimir Oltean
b53_br_flags(struct dsa_switch * ds,int port,struct switchdev_brport_flags flags,struct netlink_ext_ack * extack)2046e6dd86edSFlorian Fainelli int b53_br_flags(struct dsa_switch *ds, int port,
2047a8b659e7SVladimir Oltean struct switchdev_brport_flags flags,
2048a8b659e7SVladimir Oltean struct netlink_ext_ack *extack)
2049a8b659e7SVladimir Oltean {
2050a8b659e7SVladimir Oltean if (flags.mask & BR_FLOOD)
2051a8b659e7SVladimir Oltean b53_port_set_ucast_flood(ds->priv, port,
2052a8b659e7SVladimir Oltean !!(flags.val & BR_FLOOD));
2053a8b659e7SVladimir Oltean if (flags.mask & BR_MCAST_FLOOD)
2054a8b659e7SVladimir Oltean b53_port_set_mcast_flood(ds->priv, port,
2055a8b659e7SVladimir Oltean !!(flags.val & BR_MCAST_FLOOD));
2056f9b3827eSFlorian Fainelli if (flags.mask & BR_LEARNING)
2057f9b3827eSFlorian Fainelli b53_port_set_learning(ds->priv, port,
2058f9b3827eSFlorian Fainelli !!(flags.val & BR_LEARNING));
2059a8b659e7SVladimir Oltean
2060a8b659e7SVladimir Oltean return 0;
2061a8b659e7SVladimir Oltean }
2062e6dd86edSFlorian Fainelli EXPORT_SYMBOL(b53_br_flags);
2063a8b659e7SVladimir Oltean
b53_possible_cpu_port(struct dsa_switch * ds,int port)2064c7d28c9dSFlorian Fainelli static bool b53_possible_cpu_port(struct dsa_switch *ds, int port)
20657edc58d6SFlorian Fainelli {
20667edc58d6SFlorian Fainelli /* Broadcom switches will accept enabling Broadcom tags on the
20677edc58d6SFlorian Fainelli * following ports: 5, 7 and 8, any other port is not supported
20687edc58d6SFlorian Fainelli */
20695ed4e3ebSFlorian Fainelli switch (port) {
20705ed4e3ebSFlorian Fainelli case B53_CPU_PORT_25:
20715ed4e3ebSFlorian Fainelli case 7:
20725ed4e3ebSFlorian Fainelli case B53_CPU_PORT:
20737edc58d6SFlorian Fainelli return true;
20747edc58d6SFlorian Fainelli }
20757edc58d6SFlorian Fainelli
20765ed4e3ebSFlorian Fainelli return false;
20775ed4e3ebSFlorian Fainelli }
20785ed4e3ebSFlorian Fainelli
b53_can_enable_brcm_tags(struct dsa_switch * ds,int port,enum dsa_tag_protocol tag_protocol)20798fab459eSFlorian Fainelli static bool b53_can_enable_brcm_tags(struct dsa_switch *ds, int port,
20808fab459eSFlorian Fainelli enum dsa_tag_protocol tag_protocol)
2081c7d28c9dSFlorian Fainelli {
2082c7d28c9dSFlorian Fainelli bool ret = b53_possible_cpu_port(ds, port);
2083c7d28c9dSFlorian Fainelli
20848fab459eSFlorian Fainelli if (!ret) {
2085c7d28c9dSFlorian Fainelli dev_warn(ds->dev, "Port %d is not Broadcom tag capable\n",
2086c7d28c9dSFlorian Fainelli port);
2087c7d28c9dSFlorian Fainelli return ret;
2088c7d28c9dSFlorian Fainelli }
2089c7d28c9dSFlorian Fainelli
20908fab459eSFlorian Fainelli switch (tag_protocol) {
20918fab459eSFlorian Fainelli case DSA_TAG_PROTO_BRCM:
20928fab459eSFlorian Fainelli case DSA_TAG_PROTO_BRCM_PREPEND:
20938fab459eSFlorian Fainelli dev_warn(ds->dev,
20948fab459eSFlorian Fainelli "Port %d is stacked to Broadcom tag switch\n", port);
20958fab459eSFlorian Fainelli ret = false;
20968fab459eSFlorian Fainelli break;
20978fab459eSFlorian Fainelli default:
20988fab459eSFlorian Fainelli ret = true;
20998fab459eSFlorian Fainelli break;
21008fab459eSFlorian Fainelli }
21018fab459eSFlorian Fainelli
21028fab459eSFlorian Fainelli return ret;
21038fab459eSFlorian Fainelli }
21048fab459eSFlorian Fainelli
b53_get_tag_protocol(struct dsa_switch * ds,int port,enum dsa_tag_protocol mprot)21054d776482SFlorian Fainelli enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds, int port,
21064d776482SFlorian Fainelli enum dsa_tag_protocol mprot)
21077b314362SAndrew Lunn {
21087edc58d6SFlorian Fainelli struct b53_device *dev = ds->priv;
21097edc58d6SFlorian Fainelli
211046c5176cSÁlvaro Fernández Rojas if (!b53_can_enable_brcm_tags(ds, port, mprot)) {
21114d776482SFlorian Fainelli dev->tag_protocol = DSA_TAG_PROTO_NONE;
21124d776482SFlorian Fainelli goto out;
21134d776482SFlorian Fainelli }
211411606039SFlorian Fainelli
211546c5176cSÁlvaro Fernández Rojas /* Older models require a different 6 byte tag */
211646c5176cSÁlvaro Fernández Rojas if (is5325(dev) || is5365(dev) || is63xx(dev)) {
211746c5176cSÁlvaro Fernández Rojas dev->tag_protocol = DSA_TAG_PROTO_BRCM_LEGACY;
211846c5176cSÁlvaro Fernández Rojas goto out;
211946c5176cSÁlvaro Fernández Rojas }
212046c5176cSÁlvaro Fernández Rojas
212111606039SFlorian Fainelli /* Broadcom BCM58xx chips have a flow accelerator on Port 8
212211606039SFlorian Fainelli * which requires us to use the prepended Broadcom tag type
212311606039SFlorian Fainelli */
21244d776482SFlorian Fainelli if (dev->chip_id == BCM58XX_DEVICE_ID && port == B53_CPU_PORT) {
21254d776482SFlorian Fainelli dev->tag_protocol = DSA_TAG_PROTO_BRCM_PREPEND;
21264d776482SFlorian Fainelli goto out;
21274d776482SFlorian Fainelli }
212811606039SFlorian Fainelli
21294d776482SFlorian Fainelli dev->tag_protocol = DSA_TAG_PROTO_BRCM;
21304d776482SFlorian Fainelli out:
21314d776482SFlorian Fainelli return dev->tag_protocol;
21327b314362SAndrew Lunn }
21339f66816aSFlorian Fainelli EXPORT_SYMBOL(b53_get_tag_protocol);
21347b314362SAndrew Lunn
b53_mirror_add(struct dsa_switch * ds,int port,struct dsa_mall_mirror_tc_entry * mirror,bool ingress,struct netlink_ext_ack * extack)2135ed3af5fdSFlorian Fainelli int b53_mirror_add(struct dsa_switch *ds, int port,
21360148bb50SVladimir Oltean struct dsa_mall_mirror_tc_entry *mirror, bool ingress,
21370148bb50SVladimir Oltean struct netlink_ext_ack *extack)
2138ed3af5fdSFlorian Fainelli {
2139ed3af5fdSFlorian Fainelli struct b53_device *dev = ds->priv;
2140ed3af5fdSFlorian Fainelli u16 reg, loc;
2141ed3af5fdSFlorian Fainelli
2142ed3af5fdSFlorian Fainelli if (ingress)
2143ed3af5fdSFlorian Fainelli loc = B53_IG_MIR_CTL;
2144ed3af5fdSFlorian Fainelli else
2145ed3af5fdSFlorian Fainelli loc = B53_EG_MIR_CTL;
2146ed3af5fdSFlorian Fainelli
2147ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, loc, ®);
2148ed3af5fdSFlorian Fainelli reg |= BIT(port);
2149ed3af5fdSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, loc, reg);
2150ed3af5fdSFlorian Fainelli
2151ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, ®);
2152ed3af5fdSFlorian Fainelli reg &= ~CAP_PORT_MASK;
2153ed3af5fdSFlorian Fainelli reg |= mirror->to_local_port;
2154ed3af5fdSFlorian Fainelli reg |= MIRROR_EN;
2155ed3af5fdSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg);
2156ed3af5fdSFlorian Fainelli
2157ed3af5fdSFlorian Fainelli return 0;
2158ed3af5fdSFlorian Fainelli }
2159ed3af5fdSFlorian Fainelli EXPORT_SYMBOL(b53_mirror_add);
2160ed3af5fdSFlorian Fainelli
b53_mirror_del(struct dsa_switch * ds,int port,struct dsa_mall_mirror_tc_entry * mirror)2161ed3af5fdSFlorian Fainelli void b53_mirror_del(struct dsa_switch *ds, int port,
2162ed3af5fdSFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror)
2163ed3af5fdSFlorian Fainelli {
2164ed3af5fdSFlorian Fainelli struct b53_device *dev = ds->priv;
2165ed3af5fdSFlorian Fainelli bool loc_disable = false, other_loc_disable = false;
2166ed3af5fdSFlorian Fainelli u16 reg, loc;
2167ed3af5fdSFlorian Fainelli
2168ed3af5fdSFlorian Fainelli if (mirror->ingress)
2169ed3af5fdSFlorian Fainelli loc = B53_IG_MIR_CTL;
2170ed3af5fdSFlorian Fainelli else
2171ed3af5fdSFlorian Fainelli loc = B53_EG_MIR_CTL;
2172ed3af5fdSFlorian Fainelli
2173ed3af5fdSFlorian Fainelli /* Update the desired ingress/egress register */
2174ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, loc, ®);
2175ed3af5fdSFlorian Fainelli reg &= ~BIT(port);
2176ed3af5fdSFlorian Fainelli if (!(reg & MIRROR_MASK))
2177ed3af5fdSFlorian Fainelli loc_disable = true;
2178ed3af5fdSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, loc, reg);
2179ed3af5fdSFlorian Fainelli
2180ed3af5fdSFlorian Fainelli /* Now look at the other one to know if we can disable mirroring
2181ed3af5fdSFlorian Fainelli * entirely
2182ed3af5fdSFlorian Fainelli */
2183ed3af5fdSFlorian Fainelli if (mirror->ingress)
2184ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_EG_MIR_CTL, ®);
2185ed3af5fdSFlorian Fainelli else
2186ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_IG_MIR_CTL, ®);
2187ed3af5fdSFlorian Fainelli if (!(reg & MIRROR_MASK))
2188ed3af5fdSFlorian Fainelli other_loc_disable = true;
2189ed3af5fdSFlorian Fainelli
2190ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, ®);
2191ed3af5fdSFlorian Fainelli /* Both no longer have ports, let's disable mirroring */
2192ed3af5fdSFlorian Fainelli if (loc_disable && other_loc_disable) {
2193ed3af5fdSFlorian Fainelli reg &= ~MIRROR_EN;
2194ed3af5fdSFlorian Fainelli reg &= ~mirror->to_local_port;
2195ed3af5fdSFlorian Fainelli }
2196ed3af5fdSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg);
2197ed3af5fdSFlorian Fainelli }
2198ed3af5fdSFlorian Fainelli EXPORT_SYMBOL(b53_mirror_del);
2199ed3af5fdSFlorian Fainelli
b53_eee_enable_set(struct dsa_switch * ds,int port,bool enable)220022256b0aSFlorian Fainelli void b53_eee_enable_set(struct dsa_switch *ds, int port, bool enable)
220122256b0aSFlorian Fainelli {
220222256b0aSFlorian Fainelli struct b53_device *dev = ds->priv;
220322256b0aSFlorian Fainelli u16 reg;
220422256b0aSFlorian Fainelli
220522256b0aSFlorian Fainelli b53_read16(dev, B53_EEE_PAGE, B53_EEE_EN_CTRL, ®);
220622256b0aSFlorian Fainelli if (enable)
220722256b0aSFlorian Fainelli reg |= BIT(port);
220822256b0aSFlorian Fainelli else
220922256b0aSFlorian Fainelli reg &= ~BIT(port);
221022256b0aSFlorian Fainelli b53_write16(dev, B53_EEE_PAGE, B53_EEE_EN_CTRL, reg);
221122256b0aSFlorian Fainelli }
221222256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_eee_enable_set);
221322256b0aSFlorian Fainelli
221422256b0aSFlorian Fainelli
221522256b0aSFlorian Fainelli /* Returns 0 if EEE was not enabled, or 1 otherwise
221622256b0aSFlorian Fainelli */
b53_eee_init(struct dsa_switch * ds,int port,struct phy_device * phy)221722256b0aSFlorian Fainelli int b53_eee_init(struct dsa_switch *ds, int port, struct phy_device *phy)
221822256b0aSFlorian Fainelli {
221922256b0aSFlorian Fainelli int ret;
222022256b0aSFlorian Fainelli
222153243d41SJisheng Zhang ret = phy_init_eee(phy, false);
222222256b0aSFlorian Fainelli if (ret)
222322256b0aSFlorian Fainelli return 0;
222422256b0aSFlorian Fainelli
222522256b0aSFlorian Fainelli b53_eee_enable_set(ds, port, true);
222622256b0aSFlorian Fainelli
222722256b0aSFlorian Fainelli return 1;
222822256b0aSFlorian Fainelli }
222922256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_eee_init);
223022256b0aSFlorian Fainelli
b53_get_mac_eee(struct dsa_switch * ds,int port,struct ethtool_eee * e)223122256b0aSFlorian Fainelli int b53_get_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e)
223222256b0aSFlorian Fainelli {
223322256b0aSFlorian Fainelli struct b53_device *dev = ds->priv;
223422256b0aSFlorian Fainelli struct ethtool_eee *p = &dev->ports[port].eee;
223522256b0aSFlorian Fainelli u16 reg;
223622256b0aSFlorian Fainelli
223722256b0aSFlorian Fainelli if (is5325(dev) || is5365(dev))
223822256b0aSFlorian Fainelli return -EOPNOTSUPP;
223922256b0aSFlorian Fainelli
224022256b0aSFlorian Fainelli b53_read16(dev, B53_EEE_PAGE, B53_EEE_LPI_INDICATE, ®);
224122256b0aSFlorian Fainelli e->eee_enabled = p->eee_enabled;
224222256b0aSFlorian Fainelli e->eee_active = !!(reg & BIT(port));
224322256b0aSFlorian Fainelli
224422256b0aSFlorian Fainelli return 0;
224522256b0aSFlorian Fainelli }
224622256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_get_mac_eee);
224722256b0aSFlorian Fainelli
b53_set_mac_eee(struct dsa_switch * ds,int port,struct ethtool_eee * e)224822256b0aSFlorian Fainelli int b53_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e)
224922256b0aSFlorian Fainelli {
225022256b0aSFlorian Fainelli struct b53_device *dev = ds->priv;
225122256b0aSFlorian Fainelli struct ethtool_eee *p = &dev->ports[port].eee;
225222256b0aSFlorian Fainelli
225322256b0aSFlorian Fainelli if (is5325(dev) || is5365(dev))
225422256b0aSFlorian Fainelli return -EOPNOTSUPP;
225522256b0aSFlorian Fainelli
225622256b0aSFlorian Fainelli p->eee_enabled = e->eee_enabled;
225722256b0aSFlorian Fainelli b53_eee_enable_set(ds, port, e->eee_enabled);
225822256b0aSFlorian Fainelli
225922256b0aSFlorian Fainelli return 0;
226022256b0aSFlorian Fainelli }
226122256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_set_mac_eee);
226222256b0aSFlorian Fainelli
b53_change_mtu(struct dsa_switch * ds,int port,int mtu)22636ae5834bSMurali Krishna Policharla static int b53_change_mtu(struct dsa_switch *ds, int port, int mtu)
22646ae5834bSMurali Krishna Policharla {
22656ae5834bSMurali Krishna Policharla struct b53_device *dev = ds->priv;
22666ae5834bSMurali Krishna Policharla bool enable_jumbo;
22676ae5834bSMurali Krishna Policharla bool allow_10_100;
22686ae5834bSMurali Krishna Policharla
22696ae5834bSMurali Krishna Policharla if (is5325(dev) || is5365(dev))
2270dd5b3a83SJonas Gorski return 0;
22716ae5834bSMurali Krishna Policharla
227296787989SMartin Willi if (!dsa_is_cpu_port(ds, port))
227396787989SMartin Willi return 0;
227496787989SMartin Willi
2275f9a966afSJonas Gorski enable_jumbo = (mtu > ETH_DATA_LEN);
2276*ca57186fSJonas Gorski allow_10_100 = !is63xx(dev);
22776ae5834bSMurali Krishna Policharla
22786ae5834bSMurali Krishna Policharla return b53_set_jumbo(dev, enable_jumbo, allow_10_100);
22796ae5834bSMurali Krishna Policharla }
22806ae5834bSMurali Krishna Policharla
b53_get_max_mtu(struct dsa_switch * ds,int port)22816ae5834bSMurali Krishna Policharla static int b53_get_max_mtu(struct dsa_switch *ds, int port)
22826ae5834bSMurali Krishna Policharla {
228394c4cb9bSJonas Gorski struct b53_device *dev = ds->priv;
228494c4cb9bSJonas Gorski
228594c4cb9bSJonas Gorski if (is5325(dev) || is5365(dev))
228694c4cb9bSJonas Gorski return B53_MAX_MTU_25;
228794c4cb9bSJonas Gorski
2288bd1f41c3SJonas Gorski return B53_MAX_MTU;
22896ae5834bSMurali Krishna Policharla }
22906ae5834bSMurali Krishna Policharla
2291a82f67afSFlorian Fainelli static const struct dsa_switch_ops b53_switch_ops = {
22927b314362SAndrew Lunn .get_tag_protocol = b53_get_tag_protocol,
2293967dd82fSFlorian Fainelli .setup = b53_setup,
22944f6a5cafSFlorian Fainelli .teardown = b53_teardown,
2295967dd82fSFlorian Fainelli .get_strings = b53_get_strings,
2296967dd82fSFlorian Fainelli .get_ethtool_stats = b53_get_ethtool_stats,
2297967dd82fSFlorian Fainelli .get_sset_count = b53_get_sset_count,
2298c7d28c9dSFlorian Fainelli .get_ethtool_phy_stats = b53_get_ethtool_phy_stats,
2299967dd82fSFlorian Fainelli .phy_read = b53_phy_read16,
2300967dd82fSFlorian Fainelli .phy_write = b53_phy_write16,
2301967dd82fSFlorian Fainelli .adjust_link = b53_adjust_link,
2302dda1c257SRussell King (Oracle) .phylink_get_caps = b53_phylink_get_caps,
230379396934SRussell King (Oracle) .phylink_mac_select_pcs = b53_phylink_mac_select_pcs,
2304a8e8b985SFlorian Fainelli .phylink_mac_config = b53_phylink_mac_config,
2305a8e8b985SFlorian Fainelli .phylink_mac_link_down = b53_phylink_mac_link_down,
2306a8e8b985SFlorian Fainelli .phylink_mac_link_up = b53_phylink_mac_link_up,
2307967dd82fSFlorian Fainelli .port_enable = b53_enable_port,
2308967dd82fSFlorian Fainelli .port_disable = b53_disable_port,
2309f43a2dbeSFlorian Fainelli .get_mac_eee = b53_get_mac_eee,
2310f43a2dbeSFlorian Fainelli .set_mac_eee = b53_set_mac_eee,
2311ff39c2d6SFlorian Fainelli .port_bridge_join = b53_br_join,
2312ff39c2d6SFlorian Fainelli .port_bridge_leave = b53_br_leave,
2313a8b659e7SVladimir Oltean .port_pre_bridge_flags = b53_br_flags_pre,
2314a8b659e7SVladimir Oltean .port_bridge_flags = b53_br_flags,
2315ff39c2d6SFlorian Fainelli .port_stp_state_set = b53_br_set_stp_state,
2316597698f1SVivien Didelot .port_fast_age = b53_br_fast_age,
2317a2482d2cSFlorian Fainelli .port_vlan_filtering = b53_vlan_filtering,
2318a2482d2cSFlorian Fainelli .port_vlan_add = b53_vlan_add,
2319a2482d2cSFlorian Fainelli .port_vlan_del = b53_vlan_del,
23201da6df85SFlorian Fainelli .port_fdb_dump = b53_fdb_dump,
23211da6df85SFlorian Fainelli .port_fdb_add = b53_fdb_add,
23221da6df85SFlorian Fainelli .port_fdb_del = b53_fdb_del,
2323ed3af5fdSFlorian Fainelli .port_mirror_add = b53_mirror_add,
2324ed3af5fdSFlorian Fainelli .port_mirror_del = b53_mirror_del,
23255d65b64aSFlorian Fainelli .port_mdb_add = b53_mdb_add,
23265d65b64aSFlorian Fainelli .port_mdb_del = b53_mdb_del,
23276ae5834bSMurali Krishna Policharla .port_max_mtu = b53_get_max_mtu,
23286ae5834bSMurali Krishna Policharla .port_change_mtu = b53_change_mtu,
2329967dd82fSFlorian Fainelli };
2330967dd82fSFlorian Fainelli
2331967dd82fSFlorian Fainelli struct b53_chip_data {
2332967dd82fSFlorian Fainelli u32 chip_id;
2333967dd82fSFlorian Fainelli const char *dev_name;
2334967dd82fSFlorian Fainelli u16 vlans;
2335967dd82fSFlorian Fainelli u16 enabled_ports;
233663f8428bSRafał Miłecki u8 imp_port;
2337967dd82fSFlorian Fainelli u8 cpu_port;
2338967dd82fSFlorian Fainelli u8 vta_regs[3];
2339673e69a6SFlorian Fainelli u8 arl_bins;
2340e3da4038SFlorian Fainelli u16 arl_buckets;
2341967dd82fSFlorian Fainelli u8 duplex_reg;
2342967dd82fSFlorian Fainelli u8 jumbo_pm_reg;
2343967dd82fSFlorian Fainelli u8 jumbo_size_reg;
2344967dd82fSFlorian Fainelli };
2345967dd82fSFlorian Fainelli
2346967dd82fSFlorian Fainelli #define B53_VTA_REGS \
2347967dd82fSFlorian Fainelli { B53_VT_ACCESS, B53_VT_INDEX, B53_VT_ENTRY }
2348967dd82fSFlorian Fainelli #define B53_VTA_REGS_9798 \
2349967dd82fSFlorian Fainelli { B53_VT_ACCESS_9798, B53_VT_INDEX_9798, B53_VT_ENTRY_9798 }
2350967dd82fSFlorian Fainelli #define B53_VTA_REGS_63XX \
2351967dd82fSFlorian Fainelli { B53_VT_ACCESS_63XX, B53_VT_INDEX_63XX, B53_VT_ENTRY_63XX }
2352967dd82fSFlorian Fainelli
2353967dd82fSFlorian Fainelli static const struct b53_chip_data b53_switch_chips[] = {
2354967dd82fSFlorian Fainelli {
2355967dd82fSFlorian Fainelli .chip_id = BCM5325_DEVICE_ID,
2356967dd82fSFlorian Fainelli .dev_name = "BCM5325",
2357967dd82fSFlorian Fainelli .vlans = 16,
2358983d96a9SRafał Miłecki .enabled_ports = 0x3f,
2359673e69a6SFlorian Fainelli .arl_bins = 2,
2360e3da4038SFlorian Fainelli .arl_buckets = 1024,
236163f8428bSRafał Miłecki .imp_port = 5,
2362967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_FE,
2363967dd82fSFlorian Fainelli },
2364967dd82fSFlorian Fainelli {
2365967dd82fSFlorian Fainelli .chip_id = BCM5365_DEVICE_ID,
2366967dd82fSFlorian Fainelli .dev_name = "BCM5365",
2367967dd82fSFlorian Fainelli .vlans = 256,
2368983d96a9SRafał Miłecki .enabled_ports = 0x3f,
2369673e69a6SFlorian Fainelli .arl_bins = 2,
2370e3da4038SFlorian Fainelli .arl_buckets = 1024,
237163f8428bSRafał Miłecki .imp_port = 5,
2372967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_FE,
2373967dd82fSFlorian Fainelli },
2374967dd82fSFlorian Fainelli {
2375a95691bcSDamien Thébault .chip_id = BCM5389_DEVICE_ID,
2376a95691bcSDamien Thébault .dev_name = "BCM5389",
2377a95691bcSDamien Thébault .vlans = 4096,
2378983d96a9SRafał Miłecki .enabled_ports = 0x11f,
2379673e69a6SFlorian Fainelli .arl_bins = 4,
2380e3da4038SFlorian Fainelli .arl_buckets = 1024,
238163f8428bSRafał Miłecki .imp_port = 8,
2382a95691bcSDamien Thébault .vta_regs = B53_VTA_REGS,
2383a95691bcSDamien Thébault .duplex_reg = B53_DUPLEX_STAT_GE,
2384a95691bcSDamien Thébault .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2385a95691bcSDamien Thébault .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2386a95691bcSDamien Thébault },
2387a95691bcSDamien Thébault {
2388967dd82fSFlorian Fainelli .chip_id = BCM5395_DEVICE_ID,
2389967dd82fSFlorian Fainelli .dev_name = "BCM5395",
2390967dd82fSFlorian Fainelli .vlans = 4096,
2391983d96a9SRafał Miłecki .enabled_ports = 0x11f,
2392673e69a6SFlorian Fainelli .arl_bins = 4,
2393e3da4038SFlorian Fainelli .arl_buckets = 1024,
239463f8428bSRafał Miłecki .imp_port = 8,
2395967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS,
2396967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE,
2397967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2398967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2399967dd82fSFlorian Fainelli },
2400967dd82fSFlorian Fainelli {
2401967dd82fSFlorian Fainelli .chip_id = BCM5397_DEVICE_ID,
2402967dd82fSFlorian Fainelli .dev_name = "BCM5397",
2403967dd82fSFlorian Fainelli .vlans = 4096,
2404983d96a9SRafał Miłecki .enabled_ports = 0x11f,
2405673e69a6SFlorian Fainelli .arl_bins = 4,
2406e3da4038SFlorian Fainelli .arl_buckets = 1024,
240763f8428bSRafał Miłecki .imp_port = 8,
2408967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS_9798,
2409967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE,
2410967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2411967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2412967dd82fSFlorian Fainelli },
2413967dd82fSFlorian Fainelli {
2414967dd82fSFlorian Fainelli .chip_id = BCM5398_DEVICE_ID,
2415967dd82fSFlorian Fainelli .dev_name = "BCM5398",
2416967dd82fSFlorian Fainelli .vlans = 4096,
2417983d96a9SRafał Miłecki .enabled_ports = 0x17f,
2418673e69a6SFlorian Fainelli .arl_bins = 4,
2419e3da4038SFlorian Fainelli .arl_buckets = 1024,
242063f8428bSRafał Miłecki .imp_port = 8,
2421967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS_9798,
2422967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE,
2423967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2424967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2425967dd82fSFlorian Fainelli },
2426967dd82fSFlorian Fainelli {
2427967dd82fSFlorian Fainelli .chip_id = BCM53115_DEVICE_ID,
2428967dd82fSFlorian Fainelli .dev_name = "BCM53115",
2429967dd82fSFlorian Fainelli .vlans = 4096,
2430983d96a9SRafał Miłecki .enabled_ports = 0x11f,
2431673e69a6SFlorian Fainelli .arl_bins = 4,
2432e3da4038SFlorian Fainelli .arl_buckets = 1024,
2433967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS,
243463f8428bSRafał Miłecki .imp_port = 8,
2435967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE,
2436967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2437967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2438967dd82fSFlorian Fainelli },
2439967dd82fSFlorian Fainelli {
2440967dd82fSFlorian Fainelli .chip_id = BCM53125_DEVICE_ID,
2441967dd82fSFlorian Fainelli .dev_name = "BCM53125",
2442967dd82fSFlorian Fainelli .vlans = 4096,
2443983d96a9SRafał Miłecki .enabled_ports = 0x1ff,
2444673e69a6SFlorian Fainelli .arl_bins = 4,
2445e3da4038SFlorian Fainelli .arl_buckets = 1024,
244663f8428bSRafał Miłecki .imp_port = 8,
2447967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS,
2448967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE,
2449967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2450967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2451967dd82fSFlorian Fainelli },
2452967dd82fSFlorian Fainelli {
2453967dd82fSFlorian Fainelli .chip_id = BCM53128_DEVICE_ID,
2454967dd82fSFlorian Fainelli .dev_name = "BCM53128",
2455967dd82fSFlorian Fainelli .vlans = 4096,
2456967dd82fSFlorian Fainelli .enabled_ports = 0x1ff,
2457673e69a6SFlorian Fainelli .arl_bins = 4,
2458e3da4038SFlorian Fainelli .arl_buckets = 1024,
245963f8428bSRafał Miłecki .imp_port = 8,
2460967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS,
2461967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE,
2462967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2463967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2464967dd82fSFlorian Fainelli },
2465967dd82fSFlorian Fainelli {
2466967dd82fSFlorian Fainelli .chip_id = BCM63XX_DEVICE_ID,
2467967dd82fSFlorian Fainelli .dev_name = "BCM63xx",
2468967dd82fSFlorian Fainelli .vlans = 4096,
2469967dd82fSFlorian Fainelli .enabled_ports = 0, /* pdata must provide them */
2470673e69a6SFlorian Fainelli .arl_bins = 4,
2471e3da4038SFlorian Fainelli .arl_buckets = 1024,
247263f8428bSRafał Miłecki .imp_port = 8,
2473967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS_63XX,
2474967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_63XX,
2475967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK_63XX,
2476967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE_63XX,
2477967dd82fSFlorian Fainelli },
2478967dd82fSFlorian Fainelli {
2479260887c7SÁlvaro Fernández Rojas .chip_id = BCM63268_DEVICE_ID,
2480260887c7SÁlvaro Fernández Rojas .dev_name = "BCM63268",
2481260887c7SÁlvaro Fernández Rojas .vlans = 4096,
2482260887c7SÁlvaro Fernández Rojas .enabled_ports = 0, /* pdata must provide them */
2483260887c7SÁlvaro Fernández Rojas .arl_bins = 4,
2484260887c7SÁlvaro Fernández Rojas .arl_buckets = 1024,
2485260887c7SÁlvaro Fernández Rojas .imp_port = 8,
2486260887c7SÁlvaro Fernández Rojas .vta_regs = B53_VTA_REGS_63XX,
2487260887c7SÁlvaro Fernández Rojas .duplex_reg = B53_DUPLEX_STAT_63XX,
2488260887c7SÁlvaro Fernández Rojas .jumbo_pm_reg = B53_JUMBO_PORT_MASK_63XX,
2489260887c7SÁlvaro Fernández Rojas .jumbo_size_reg = B53_JUMBO_MAX_SIZE_63XX,
2490260887c7SÁlvaro Fernández Rojas },
2491260887c7SÁlvaro Fernández Rojas {
2492967dd82fSFlorian Fainelli .chip_id = BCM53010_DEVICE_ID,
2493967dd82fSFlorian Fainelli .dev_name = "BCM53010",
2494967dd82fSFlorian Fainelli .vlans = 4096,
2495983d96a9SRafał Miłecki .enabled_ports = 0x1bf,
2496673e69a6SFlorian Fainelli .arl_bins = 4,
2497e3da4038SFlorian Fainelli .arl_buckets = 1024,
249863f8428bSRafał Miłecki .imp_port = 8,
2499967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS,
2500967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE,
2501967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2502967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2503967dd82fSFlorian Fainelli },
2504967dd82fSFlorian Fainelli {
2505967dd82fSFlorian Fainelli .chip_id = BCM53011_DEVICE_ID,
2506967dd82fSFlorian Fainelli .dev_name = "BCM53011",
2507967dd82fSFlorian Fainelli .vlans = 4096,
2508967dd82fSFlorian Fainelli .enabled_ports = 0x1bf,
2509673e69a6SFlorian Fainelli .arl_bins = 4,
2510e3da4038SFlorian Fainelli .arl_buckets = 1024,
251163f8428bSRafał Miłecki .imp_port = 8,
2512967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS,
2513967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE,
2514967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2515967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2516967dd82fSFlorian Fainelli },
2517967dd82fSFlorian Fainelli {
2518967dd82fSFlorian Fainelli .chip_id = BCM53012_DEVICE_ID,
2519967dd82fSFlorian Fainelli .dev_name = "BCM53012",
2520967dd82fSFlorian Fainelli .vlans = 4096,
2521967dd82fSFlorian Fainelli .enabled_ports = 0x1bf,
2522673e69a6SFlorian Fainelli .arl_bins = 4,
2523e3da4038SFlorian Fainelli .arl_buckets = 1024,
252463f8428bSRafał Miłecki .imp_port = 8,
2525967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS,
2526967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE,
2527967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2528967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2529967dd82fSFlorian Fainelli },
2530967dd82fSFlorian Fainelli {
2531967dd82fSFlorian Fainelli .chip_id = BCM53018_DEVICE_ID,
2532967dd82fSFlorian Fainelli .dev_name = "BCM53018",
2533967dd82fSFlorian Fainelli .vlans = 4096,
2534983d96a9SRafał Miłecki .enabled_ports = 0x1bf,
2535673e69a6SFlorian Fainelli .arl_bins = 4,
2536e3da4038SFlorian Fainelli .arl_buckets = 1024,
253763f8428bSRafał Miłecki .imp_port = 8,
2538967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS,
2539967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE,
2540967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2541967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2542967dd82fSFlorian Fainelli },
2543967dd82fSFlorian Fainelli {
2544967dd82fSFlorian Fainelli .chip_id = BCM53019_DEVICE_ID,
2545967dd82fSFlorian Fainelli .dev_name = "BCM53019",
2546967dd82fSFlorian Fainelli .vlans = 4096,
2547983d96a9SRafał Miłecki .enabled_ports = 0x1bf,
2548673e69a6SFlorian Fainelli .arl_bins = 4,
2549e3da4038SFlorian Fainelli .arl_buckets = 1024,
255063f8428bSRafał Miłecki .imp_port = 8,
2551967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS,
2552967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE,
2553967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2554967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2555967dd82fSFlorian Fainelli },
2556991a36bbSFlorian Fainelli {
2557991a36bbSFlorian Fainelli .chip_id = BCM58XX_DEVICE_ID,
2558991a36bbSFlorian Fainelli .dev_name = "BCM585xx/586xx/88312",
2559991a36bbSFlorian Fainelli .vlans = 4096,
2560991a36bbSFlorian Fainelli .enabled_ports = 0x1ff,
2561673e69a6SFlorian Fainelli .arl_bins = 4,
2562e3da4038SFlorian Fainelli .arl_buckets = 1024,
256363f8428bSRafał Miłecki .imp_port = 8,
2564991a36bbSFlorian Fainelli .vta_regs = B53_VTA_REGS,
2565991a36bbSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE,
2566991a36bbSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2567991a36bbSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2568991a36bbSFlorian Fainelli },
2569130401d9SFlorian Fainelli {
25705040cc99SArun Parameswaran .chip_id = BCM583XX_DEVICE_ID,
25715040cc99SArun Parameswaran .dev_name = "BCM583xx/11360",
25725040cc99SArun Parameswaran .vlans = 4096,
25735040cc99SArun Parameswaran .enabled_ports = 0x103,
2574673e69a6SFlorian Fainelli .arl_bins = 4,
2575e3da4038SFlorian Fainelli .arl_buckets = 1024,
257663f8428bSRafał Miłecki .imp_port = 8,
25775040cc99SArun Parameswaran .vta_regs = B53_VTA_REGS,
25785040cc99SArun Parameswaran .duplex_reg = B53_DUPLEX_STAT_GE,
25795040cc99SArun Parameswaran .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
25805040cc99SArun Parameswaran .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
25815040cc99SArun Parameswaran },
258273b7a604SRafał Miłecki /* Starfighter 2 */
258373b7a604SRafał Miłecki {
258473b7a604SRafał Miłecki .chip_id = BCM4908_DEVICE_ID,
258573b7a604SRafał Miłecki .dev_name = "BCM4908",
258673b7a604SRafał Miłecki .vlans = 4096,
258773b7a604SRafał Miłecki .enabled_ports = 0x1bf,
258873b7a604SRafał Miłecki .arl_bins = 4,
258973b7a604SRafał Miłecki .arl_buckets = 256,
259063f8428bSRafał Miłecki .imp_port = 8,
259173b7a604SRafał Miłecki .vta_regs = B53_VTA_REGS,
259273b7a604SRafał Miłecki .duplex_reg = B53_DUPLEX_STAT_GE,
259373b7a604SRafał Miłecki .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
259473b7a604SRafał Miłecki .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
259573b7a604SRafał Miłecki },
25965040cc99SArun Parameswaran {
2597130401d9SFlorian Fainelli .chip_id = BCM7445_DEVICE_ID,
2598130401d9SFlorian Fainelli .dev_name = "BCM7445",
2599130401d9SFlorian Fainelli .vlans = 4096,
2600130401d9SFlorian Fainelli .enabled_ports = 0x1ff,
2601673e69a6SFlorian Fainelli .arl_bins = 4,
2602e3da4038SFlorian Fainelli .arl_buckets = 1024,
260363f8428bSRafał Miłecki .imp_port = 8,
2604130401d9SFlorian Fainelli .vta_regs = B53_VTA_REGS,
2605130401d9SFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE,
2606130401d9SFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2607130401d9SFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2608130401d9SFlorian Fainelli },
26090fe99338SFlorian Fainelli {
26100fe99338SFlorian Fainelli .chip_id = BCM7278_DEVICE_ID,
26110fe99338SFlorian Fainelli .dev_name = "BCM7278",
26120fe99338SFlorian Fainelli .vlans = 4096,
26130fe99338SFlorian Fainelli .enabled_ports = 0x1ff,
2614673e69a6SFlorian Fainelli .arl_bins = 4,
2615e3da4038SFlorian Fainelli .arl_buckets = 256,
261663f8428bSRafał Miłecki .imp_port = 8,
26170fe99338SFlorian Fainelli .vta_regs = B53_VTA_REGS,
26180fe99338SFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE,
26190fe99338SFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
26200fe99338SFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
26210fe99338SFlorian Fainelli },
2622f927e8efSPaul Geurts {
2623f927e8efSPaul Geurts .chip_id = BCM53134_DEVICE_ID,
2624f927e8efSPaul Geurts .dev_name = "BCM53134",
2625f927e8efSPaul Geurts .vlans = 4096,
2626f927e8efSPaul Geurts .enabled_ports = 0x12f,
2627f927e8efSPaul Geurts .imp_port = 8,
2628f927e8efSPaul Geurts .cpu_port = B53_CPU_PORT,
2629f927e8efSPaul Geurts .vta_regs = B53_VTA_REGS,
2630f927e8efSPaul Geurts .arl_bins = 4,
2631f927e8efSPaul Geurts .arl_buckets = 1024,
2632f927e8efSPaul Geurts .duplex_reg = B53_DUPLEX_STAT_GE,
2633f927e8efSPaul Geurts .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
2634f927e8efSPaul Geurts .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
2635f927e8efSPaul Geurts },
2636967dd82fSFlorian Fainelli };
2637967dd82fSFlorian Fainelli
b53_switch_init(struct b53_device * dev)2638967dd82fSFlorian Fainelli static int b53_switch_init(struct b53_device *dev)
2639967dd82fSFlorian Fainelli {
2640967dd82fSFlorian Fainelli unsigned int i;
2641967dd82fSFlorian Fainelli int ret;
2642967dd82fSFlorian Fainelli
2643967dd82fSFlorian Fainelli for (i = 0; i < ARRAY_SIZE(b53_switch_chips); i++) {
2644967dd82fSFlorian Fainelli const struct b53_chip_data *chip = &b53_switch_chips[i];
2645967dd82fSFlorian Fainelli
2646967dd82fSFlorian Fainelli if (chip->chip_id == dev->chip_id) {
2647967dd82fSFlorian Fainelli if (!dev->enabled_ports)
2648967dd82fSFlorian Fainelli dev->enabled_ports = chip->enabled_ports;
2649967dd82fSFlorian Fainelli dev->name = chip->dev_name;
2650967dd82fSFlorian Fainelli dev->duplex_reg = chip->duplex_reg;
2651967dd82fSFlorian Fainelli dev->vta_regs[0] = chip->vta_regs[0];
2652967dd82fSFlorian Fainelli dev->vta_regs[1] = chip->vta_regs[1];
2653967dd82fSFlorian Fainelli dev->vta_regs[2] = chip->vta_regs[2];
2654967dd82fSFlorian Fainelli dev->jumbo_pm_reg = chip->jumbo_pm_reg;
265563f8428bSRafał Miłecki dev->imp_port = chip->imp_port;
2656967dd82fSFlorian Fainelli dev->num_vlans = chip->vlans;
2657673e69a6SFlorian Fainelli dev->num_arl_bins = chip->arl_bins;
2658e3da4038SFlorian Fainelli dev->num_arl_buckets = chip->arl_buckets;
2659967dd82fSFlorian Fainelli break;
2660967dd82fSFlorian Fainelli }
2661967dd82fSFlorian Fainelli }
2662967dd82fSFlorian Fainelli
2663967dd82fSFlorian Fainelli /* check which BCM5325x version we have */
2664967dd82fSFlorian Fainelli if (is5325(dev)) {
2665967dd82fSFlorian Fainelli u8 vc4;
2666967dd82fSFlorian Fainelli
2667967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, &vc4);
2668967dd82fSFlorian Fainelli
2669967dd82fSFlorian Fainelli /* check reserved bits */
2670967dd82fSFlorian Fainelli switch (vc4 & 3) {
2671967dd82fSFlorian Fainelli case 1:
2672967dd82fSFlorian Fainelli /* BCM5325E */
2673967dd82fSFlorian Fainelli break;
2674967dd82fSFlorian Fainelli case 3:
2675967dd82fSFlorian Fainelli /* BCM5325F - do not use port 4 */
2676967dd82fSFlorian Fainelli dev->enabled_ports &= ~BIT(4);
2677967dd82fSFlorian Fainelli break;
2678967dd82fSFlorian Fainelli default:
2679967dd82fSFlorian Fainelli /* On the BCM47XX SoCs this is the supported internal switch.*/
2680967dd82fSFlorian Fainelli #ifndef CONFIG_BCM47XX
2681967dd82fSFlorian Fainelli /* BCM5325M */
2682967dd82fSFlorian Fainelli return -EINVAL;
2683967dd82fSFlorian Fainelli #else
2684967dd82fSFlorian Fainelli break;
2685967dd82fSFlorian Fainelli #endif
2686967dd82fSFlorian Fainelli }
2687967dd82fSFlorian Fainelli }
2688967dd82fSFlorian Fainelli
2689cdb067d3SRafał Miłecki dev->num_ports = fls(dev->enabled_ports);
2690967dd82fSFlorian Fainelli
2691d12e1c46SRafał Miłecki dev->ds->num_ports = min_t(unsigned int, dev->num_ports, DSA_MAX_PORTS);
2692d12e1c46SRafał Miłecki
2693c7d28c9dSFlorian Fainelli /* Include non standard CPU port built-in PHYs to be probed */
2694c7d28c9dSFlorian Fainelli if (is539x(dev) || is531x5(dev)) {
2695c7d28c9dSFlorian Fainelli for (i = 0; i < dev->num_ports; i++) {
2696c7d28c9dSFlorian Fainelli if (!(dev->ds->phys_mii_mask & BIT(i)) &&
2697c7d28c9dSFlorian Fainelli !b53_possible_cpu_port(dev->ds, i))
2698c7d28c9dSFlorian Fainelli dev->ds->phys_mii_mask |= BIT(i);
2699c7d28c9dSFlorian Fainelli }
2700c7d28c9dSFlorian Fainelli }
2701c7d28c9dSFlorian Fainelli
2702a86854d0SKees Cook dev->ports = devm_kcalloc(dev->dev,
2703a86854d0SKees Cook dev->num_ports, sizeof(struct b53_port),
2704967dd82fSFlorian Fainelli GFP_KERNEL);
2705967dd82fSFlorian Fainelli if (!dev->ports)
2706967dd82fSFlorian Fainelli return -ENOMEM;
2707967dd82fSFlorian Fainelli
2708a86854d0SKees Cook dev->vlans = devm_kcalloc(dev->dev,
2709a86854d0SKees Cook dev->num_vlans, sizeof(struct b53_vlan),
2710a2482d2cSFlorian Fainelli GFP_KERNEL);
2711a2482d2cSFlorian Fainelli if (!dev->vlans)
2712a2482d2cSFlorian Fainelli return -ENOMEM;
2713a2482d2cSFlorian Fainelli
2714967dd82fSFlorian Fainelli dev->reset_gpio = b53_switch_get_reset_gpio(dev);
2715967dd82fSFlorian Fainelli if (dev->reset_gpio >= 0) {
2716967dd82fSFlorian Fainelli ret = devm_gpio_request_one(dev->dev, dev->reset_gpio,
2717967dd82fSFlorian Fainelli GPIOF_OUT_INIT_HIGH, "robo_reset");
2718967dd82fSFlorian Fainelli if (ret)
2719967dd82fSFlorian Fainelli return ret;
2720967dd82fSFlorian Fainelli }
2721967dd82fSFlorian Fainelli
2722967dd82fSFlorian Fainelli return 0;
2723967dd82fSFlorian Fainelli }
2724967dd82fSFlorian Fainelli
b53_switch_alloc(struct device * base,const struct b53_io_ops * ops,void * priv)27250dff88d3SJulia Lawall struct b53_device *b53_switch_alloc(struct device *base,
27260dff88d3SJulia Lawall const struct b53_io_ops *ops,
2727967dd82fSFlorian Fainelli void *priv)
2728967dd82fSFlorian Fainelli {
2729967dd82fSFlorian Fainelli struct dsa_switch *ds;
2730967dd82fSFlorian Fainelli struct b53_device *dev;
2731967dd82fSFlorian Fainelli
27327e99e347SVivien Didelot ds = devm_kzalloc(base, sizeof(*ds), GFP_KERNEL);
2733967dd82fSFlorian Fainelli if (!ds)
2734967dd82fSFlorian Fainelli return NULL;
2735967dd82fSFlorian Fainelli
27367e99e347SVivien Didelot ds->dev = base;
27377e99e347SVivien Didelot
2738a0c02161SVivien Didelot dev = devm_kzalloc(base, sizeof(*dev), GFP_KERNEL);
2739a0c02161SVivien Didelot if (!dev)
2740a0c02161SVivien Didelot return NULL;
2741967dd82fSFlorian Fainelli
2742967dd82fSFlorian Fainelli ds->priv = dev;
2743967dd82fSFlorian Fainelli dev->dev = base;
2744967dd82fSFlorian Fainelli
2745967dd82fSFlorian Fainelli dev->ds = ds;
2746967dd82fSFlorian Fainelli dev->priv = priv;
2747967dd82fSFlorian Fainelli dev->ops = ops;
2748485ebd61SFlorian Fainelli ds->ops = &b53_switch_ops;
27490ee2af4eSVladimir Oltean dev->vlan_enabled = true;
2750d45c36baSFlorian Fainelli /* Let DSA handle the case were multiple bridges span the same switch
2751d45c36baSFlorian Fainelli * device and different VLAN awareness settings are requested, which
2752d45c36baSFlorian Fainelli * would be breaking filtering semantics for any of the other bridge
2753d45c36baSFlorian Fainelli * devices. (not hardware supported)
2754d45c36baSFlorian Fainelli */
2755d45c36baSFlorian Fainelli ds->vlan_filtering_is_global = true;
2756d45c36baSFlorian Fainelli
2757967dd82fSFlorian Fainelli mutex_init(&dev->reg_mutex);
2758967dd82fSFlorian Fainelli mutex_init(&dev->stats_mutex);
2759f7eb4a1cSVladimir Oltean mutex_init(&dev->arl_mutex);
2760967dd82fSFlorian Fainelli
2761967dd82fSFlorian Fainelli return dev;
2762967dd82fSFlorian Fainelli }
2763967dd82fSFlorian Fainelli EXPORT_SYMBOL(b53_switch_alloc);
2764967dd82fSFlorian Fainelli
b53_switch_detect(struct b53_device * dev)2765967dd82fSFlorian Fainelli int b53_switch_detect(struct b53_device *dev)
2766967dd82fSFlorian Fainelli {
2767967dd82fSFlorian Fainelli u32 id32;
2768967dd82fSFlorian Fainelli u16 tmp;
2769967dd82fSFlorian Fainelli u8 id8;
2770967dd82fSFlorian Fainelli int ret;
2771967dd82fSFlorian Fainelli
2772967dd82fSFlorian Fainelli ret = b53_read8(dev, B53_MGMT_PAGE, B53_DEVICE_ID, &id8);
2773967dd82fSFlorian Fainelli if (ret)
2774967dd82fSFlorian Fainelli return ret;
2775967dd82fSFlorian Fainelli
2776967dd82fSFlorian Fainelli switch (id8) {
2777967dd82fSFlorian Fainelli case 0:
2778967dd82fSFlorian Fainelli /* BCM5325 and BCM5365 do not have this register so reads
2779967dd82fSFlorian Fainelli * return 0. But the read operation did succeed, so assume this
2780967dd82fSFlorian Fainelli * is one of them.
2781967dd82fSFlorian Fainelli *
2782967dd82fSFlorian Fainelli * Next check if we can write to the 5325's VTA register; for
2783967dd82fSFlorian Fainelli * 5365 it is read only.
2784967dd82fSFlorian Fainelli */
2785967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, 0xf);
2786967dd82fSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, &tmp);
2787967dd82fSFlorian Fainelli
2788967dd82fSFlorian Fainelli if (tmp == 0xf)
2789967dd82fSFlorian Fainelli dev->chip_id = BCM5325_DEVICE_ID;
2790967dd82fSFlorian Fainelli else
2791967dd82fSFlorian Fainelli dev->chip_id = BCM5365_DEVICE_ID;
2792967dd82fSFlorian Fainelli break;
2793a95691bcSDamien Thébault case BCM5389_DEVICE_ID:
2794967dd82fSFlorian Fainelli case BCM5395_DEVICE_ID:
2795967dd82fSFlorian Fainelli case BCM5397_DEVICE_ID:
2796967dd82fSFlorian Fainelli case BCM5398_DEVICE_ID:
2797967dd82fSFlorian Fainelli dev->chip_id = id8;
2798967dd82fSFlorian Fainelli break;
2799967dd82fSFlorian Fainelli default:
2800967dd82fSFlorian Fainelli ret = b53_read32(dev, B53_MGMT_PAGE, B53_DEVICE_ID, &id32);
2801967dd82fSFlorian Fainelli if (ret)
2802967dd82fSFlorian Fainelli return ret;
2803967dd82fSFlorian Fainelli
2804967dd82fSFlorian Fainelli switch (id32) {
2805967dd82fSFlorian Fainelli case BCM53115_DEVICE_ID:
2806967dd82fSFlorian Fainelli case BCM53125_DEVICE_ID:
2807967dd82fSFlorian Fainelli case BCM53128_DEVICE_ID:
2808967dd82fSFlorian Fainelli case BCM53010_DEVICE_ID:
2809967dd82fSFlorian Fainelli case BCM53011_DEVICE_ID:
2810967dd82fSFlorian Fainelli case BCM53012_DEVICE_ID:
2811967dd82fSFlorian Fainelli case BCM53018_DEVICE_ID:
2812967dd82fSFlorian Fainelli case BCM53019_DEVICE_ID:
2813f927e8efSPaul Geurts case BCM53134_DEVICE_ID:
2814967dd82fSFlorian Fainelli dev->chip_id = id32;
2815967dd82fSFlorian Fainelli break;
2816967dd82fSFlorian Fainelli default:
28173b33438cSPaul Barker dev_err(dev->dev,
28183b33438cSPaul Barker "unsupported switch detected (BCM53%02x/BCM%x)\n",
2819967dd82fSFlorian Fainelli id8, id32);
2820967dd82fSFlorian Fainelli return -ENODEV;
2821967dd82fSFlorian Fainelli }
2822967dd82fSFlorian Fainelli }
2823967dd82fSFlorian Fainelli
2824967dd82fSFlorian Fainelli if (dev->chip_id == BCM5325_DEVICE_ID)
2825967dd82fSFlorian Fainelli return b53_read8(dev, B53_STAT_PAGE, B53_REV_ID_25,
2826967dd82fSFlorian Fainelli &dev->core_rev);
2827967dd82fSFlorian Fainelli else
2828967dd82fSFlorian Fainelli return b53_read8(dev, B53_MGMT_PAGE, B53_REV_ID,
2829967dd82fSFlorian Fainelli &dev->core_rev);
2830967dd82fSFlorian Fainelli }
2831967dd82fSFlorian Fainelli EXPORT_SYMBOL(b53_switch_detect);
2832967dd82fSFlorian Fainelli
b53_switch_register(struct b53_device * dev)2833967dd82fSFlorian Fainelli int b53_switch_register(struct b53_device *dev)
2834967dd82fSFlorian Fainelli {
2835967dd82fSFlorian Fainelli int ret;
2836967dd82fSFlorian Fainelli
2837967dd82fSFlorian Fainelli if (dev->pdata) {
2838967dd82fSFlorian Fainelli dev->chip_id = dev->pdata->chip_id;
2839967dd82fSFlorian Fainelli dev->enabled_ports = dev->pdata->enabled_ports;
2840967dd82fSFlorian Fainelli }
2841967dd82fSFlorian Fainelli
2842967dd82fSFlorian Fainelli if (!dev->chip_id && b53_switch_detect(dev))
2843967dd82fSFlorian Fainelli return -EINVAL;
2844967dd82fSFlorian Fainelli
2845967dd82fSFlorian Fainelli ret = b53_switch_init(dev);
2846967dd82fSFlorian Fainelli if (ret)
2847967dd82fSFlorian Fainelli return ret;
2848967dd82fSFlorian Fainelli
28493b33438cSPaul Barker dev_info(dev->dev, "found switch: %s, rev %i\n",
28503b33438cSPaul Barker dev->name, dev->core_rev);
2851967dd82fSFlorian Fainelli
285223c9ee49SVivien Didelot return dsa_register_switch(dev->ds);
2853967dd82fSFlorian Fainelli }
2854967dd82fSFlorian Fainelli EXPORT_SYMBOL(b53_switch_register);
2855967dd82fSFlorian Fainelli
2856967dd82fSFlorian Fainelli MODULE_AUTHOR("Jonas Gorski <jogo@openwrt.org>");
2857967dd82fSFlorian Fainelli MODULE_DESCRIPTION("B53 switch library");
2858967dd82fSFlorian Fainelli MODULE_LICENSE("Dual BSD/GPL");
2859