xref: /linux/drivers/net/dsa/mv88e6xxx/chip.c (revision c5288cda69ee2d8607f5026bd599a5cebf0ee783)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Marvell 88e6xxx Ethernet switch single-chip support
4  *
5  * Copyright (c) 2008 Marvell Semiconductor
6  *
7  * Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch>
8  *
9  * Copyright (c) 2016-2017 Savoir-faire Linux Inc.
10  *	Vivien Didelot <vivien.didelot@savoirfairelinux.com>
11  */
12 
13 #include <linux/bitfield.h>
14 #include <linux/delay.h>
15 #include <linux/dsa/mv88e6xxx.h>
16 #include <linux/etherdevice.h>
17 #include <linux/ethtool.h>
18 #include <linux/if_bridge.h>
19 #include <linux/interrupt.h>
20 #include <linux/irq.h>
21 #include <linux/irqdomain.h>
22 #include <linux/jiffies.h>
23 #include <linux/list.h>
24 #include <linux/mdio.h>
25 #include <linux/module.h>
26 #include <linux/of.h>
27 #include <linux/of_irq.h>
28 #include <linux/of_mdio.h>
29 #include <linux/platform_data/mv88e6xxx.h>
30 #include <linux/netdevice.h>
31 #include <linux/gpio/consumer.h>
32 #include <linux/phylink.h>
33 #include <net/dsa.h>
34 
35 #include "chip.h"
36 #include "devlink.h"
37 #include "global1.h"
38 #include "global2.h"
39 #include "hwtstamp.h"
40 #include "phy.h"
41 #include "port.h"
42 #include "ptp.h"
43 #include "serdes.h"
44 #include "smi.h"
45 
46 static void assert_reg_lock(struct mv88e6xxx_chip *chip)
47 {
48 	if (unlikely(!mutex_is_locked(&chip->reg_lock))) {
49 		dev_err(chip->dev, "Switch registers lock not held!\n");
50 		dump_stack();
51 	}
52 }
53 
54 int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val)
55 {
56 	int err;
57 
58 	assert_reg_lock(chip);
59 
60 	err = mv88e6xxx_smi_read(chip, addr, reg, val);
61 	if (err)
62 		return err;
63 
64 	dev_dbg(chip->dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
65 		addr, reg, *val);
66 
67 	return 0;
68 }
69 
70 int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val)
71 {
72 	int err;
73 
74 	assert_reg_lock(chip);
75 
76 	err = mv88e6xxx_smi_write(chip, addr, reg, val);
77 	if (err)
78 		return err;
79 
80 	dev_dbg(chip->dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
81 		addr, reg, val);
82 
83 	return 0;
84 }
85 
86 int mv88e6xxx_wait_mask(struct mv88e6xxx_chip *chip, int addr, int reg,
87 			u16 mask, u16 val)
88 {
89 	const unsigned long timeout = jiffies + msecs_to_jiffies(50);
90 	u16 data;
91 	int err;
92 	int i;
93 
94 	/* There's no bus specific operation to wait for a mask. Even
95 	 * if the initial poll takes longer than 50ms, always do at
96 	 * least one more attempt.
97 	 */
98 	for (i = 0; time_before(jiffies, timeout) || (i < 2); i++) {
99 		err = mv88e6xxx_read(chip, addr, reg, &data);
100 		if (err)
101 			return err;
102 
103 		if ((data & mask) == val)
104 			return 0;
105 
106 		if (i < 2)
107 			cpu_relax();
108 		else
109 			usleep_range(1000, 2000);
110 	}
111 
112 	err = mv88e6xxx_read(chip, addr, reg, &data);
113 	if (err)
114 		return err;
115 
116 	if ((data & mask) == val)
117 		return 0;
118 
119 	dev_err(chip->dev, "Timeout while waiting for switch\n");
120 	return -ETIMEDOUT;
121 }
122 
123 int mv88e6xxx_wait_bit(struct mv88e6xxx_chip *chip, int addr, int reg,
124 		       int bit, int val)
125 {
126 	return mv88e6xxx_wait_mask(chip, addr, reg, BIT(bit),
127 				   val ? BIT(bit) : 0x0000);
128 }
129 
130 struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
131 {
132 	struct mv88e6xxx_mdio_bus *mdio_bus;
133 
134 	mdio_bus = list_first_entry_or_null(&chip->mdios,
135 					    struct mv88e6xxx_mdio_bus, list);
136 	if (!mdio_bus)
137 		return NULL;
138 
139 	return mdio_bus->bus;
140 }
141 
142 static void mv88e6xxx_g1_irq_mask(struct irq_data *d)
143 {
144 	struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
145 	unsigned int n = d->hwirq;
146 
147 	chip->g1_irq.masked |= (1 << n);
148 }
149 
150 static void mv88e6xxx_g1_irq_unmask(struct irq_data *d)
151 {
152 	struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
153 	unsigned int n = d->hwirq;
154 
155 	chip->g1_irq.masked &= ~(1 << n);
156 }
157 
158 static irqreturn_t mv88e6xxx_g1_irq_thread_work(struct mv88e6xxx_chip *chip)
159 {
160 	unsigned int nhandled = 0;
161 	unsigned int sub_irq;
162 	unsigned int n;
163 	u16 reg;
164 	u16 ctl1;
165 	int err;
166 
167 	mv88e6xxx_reg_lock(chip);
168 	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
169 	mv88e6xxx_reg_unlock(chip);
170 
171 	if (err)
172 		goto out;
173 
174 	do {
175 		for (n = 0; n < chip->g1_irq.nirqs; ++n) {
176 			if (reg & (1 << n)) {
177 				sub_irq = irq_find_mapping(chip->g1_irq.domain,
178 							   n);
179 				handle_nested_irq(sub_irq);
180 				++nhandled;
181 			}
182 		}
183 
184 		mv88e6xxx_reg_lock(chip);
185 		err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &ctl1);
186 		if (err)
187 			goto unlock;
188 		err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
189 unlock:
190 		mv88e6xxx_reg_unlock(chip);
191 		if (err)
192 			goto out;
193 		ctl1 &= GENMASK(chip->g1_irq.nirqs, 0);
194 	} while (reg & ctl1);
195 
196 out:
197 	return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
198 }
199 
200 static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id)
201 {
202 	struct mv88e6xxx_chip *chip = dev_id;
203 
204 	return mv88e6xxx_g1_irq_thread_work(chip);
205 }
206 
207 static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
208 {
209 	struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
210 
211 	mv88e6xxx_reg_lock(chip);
212 }
213 
214 static void mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data *d)
215 {
216 	struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
217 	u16 mask = GENMASK(chip->g1_irq.nirqs, 0);
218 	u16 reg;
219 	int err;
220 
221 	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &reg);
222 	if (err)
223 		goto out;
224 
225 	reg &= ~mask;
226 	reg |= (~chip->g1_irq.masked & mask);
227 
228 	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, reg);
229 	if (err)
230 		goto out;
231 
232 out:
233 	mv88e6xxx_reg_unlock(chip);
234 }
235 
236 static const struct irq_chip mv88e6xxx_g1_irq_chip = {
237 	.name			= "mv88e6xxx-g1",
238 	.irq_mask		= mv88e6xxx_g1_irq_mask,
239 	.irq_unmask		= mv88e6xxx_g1_irq_unmask,
240 	.irq_bus_lock		= mv88e6xxx_g1_irq_bus_lock,
241 	.irq_bus_sync_unlock	= mv88e6xxx_g1_irq_bus_sync_unlock,
242 };
243 
244 static int mv88e6xxx_g1_irq_domain_map(struct irq_domain *d,
245 				       unsigned int irq,
246 				       irq_hw_number_t hwirq)
247 {
248 	struct mv88e6xxx_chip *chip = d->host_data;
249 
250 	irq_set_chip_data(irq, d->host_data);
251 	irq_set_chip_and_handler(irq, &chip->g1_irq.chip, handle_level_irq);
252 	irq_set_noprobe(irq);
253 
254 	return 0;
255 }
256 
257 static const struct irq_domain_ops mv88e6xxx_g1_irq_domain_ops = {
258 	.map	= mv88e6xxx_g1_irq_domain_map,
259 	.xlate	= irq_domain_xlate_twocell,
260 };
261 
262 /* To be called with reg_lock held */
263 static void mv88e6xxx_g1_irq_free_common(struct mv88e6xxx_chip *chip)
264 {
265 	int irq, virq;
266 	u16 mask;
267 
268 	mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
269 	mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
270 	mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
271 
272 	for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
273 		virq = irq_find_mapping(chip->g1_irq.domain, irq);
274 		irq_dispose_mapping(virq);
275 	}
276 
277 	irq_domain_remove(chip->g1_irq.domain);
278 }
279 
280 static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
281 {
282 	/*
283 	 * free_irq must be called without reg_lock taken because the irq
284 	 * handler takes this lock, too.
285 	 */
286 	free_irq(chip->irq, chip);
287 
288 	mv88e6xxx_reg_lock(chip);
289 	mv88e6xxx_g1_irq_free_common(chip);
290 	mv88e6xxx_reg_unlock(chip);
291 }
292 
293 static int mv88e6xxx_g1_irq_setup_common(struct mv88e6xxx_chip *chip)
294 {
295 	int err, irq, virq;
296 	u16 reg, mask;
297 
298 	chip->g1_irq.nirqs = chip->info->g1_irqs;
299 	chip->g1_irq.domain = irq_domain_add_simple(
300 		NULL, chip->g1_irq.nirqs, 0,
301 		&mv88e6xxx_g1_irq_domain_ops, chip);
302 	if (!chip->g1_irq.domain)
303 		return -ENOMEM;
304 
305 	for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
306 		irq_create_mapping(chip->g1_irq.domain, irq);
307 
308 	chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
309 	chip->g1_irq.masked = ~0;
310 
311 	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
312 	if (err)
313 		goto out_mapping;
314 
315 	mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
316 
317 	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
318 	if (err)
319 		goto out_disable;
320 
321 	/* Reading the interrupt status clears (most of) them */
322 	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
323 	if (err)
324 		goto out_disable;
325 
326 	return 0;
327 
328 out_disable:
329 	mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
330 	mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
331 
332 out_mapping:
333 	for (irq = 0; irq < 16; irq++) {
334 		virq = irq_find_mapping(chip->g1_irq.domain, irq);
335 		irq_dispose_mapping(virq);
336 	}
337 
338 	irq_domain_remove(chip->g1_irq.domain);
339 
340 	return err;
341 }
342 
343 static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
344 {
345 	static struct lock_class_key lock_key;
346 	static struct lock_class_key request_key;
347 	int err;
348 
349 	err = mv88e6xxx_g1_irq_setup_common(chip);
350 	if (err)
351 		return err;
352 
353 	/* These lock classes tells lockdep that global 1 irqs are in
354 	 * a different category than their parent GPIO, so it won't
355 	 * report false recursion.
356 	 */
357 	irq_set_lockdep_class(chip->irq, &lock_key, &request_key);
358 
359 	snprintf(chip->irq_name, sizeof(chip->irq_name),
360 		 "mv88e6xxx-%s", dev_name(chip->dev));
361 
362 	mv88e6xxx_reg_unlock(chip);
363 	err = request_threaded_irq(chip->irq, NULL,
364 				   mv88e6xxx_g1_irq_thread_fn,
365 				   IRQF_ONESHOT | IRQF_SHARED,
366 				   chip->irq_name, chip);
367 	mv88e6xxx_reg_lock(chip);
368 	if (err)
369 		mv88e6xxx_g1_irq_free_common(chip);
370 
371 	return err;
372 }
373 
374 static void mv88e6xxx_irq_poll(struct kthread_work *work)
375 {
376 	struct mv88e6xxx_chip *chip = container_of(work,
377 						   struct mv88e6xxx_chip,
378 						   irq_poll_work.work);
379 	mv88e6xxx_g1_irq_thread_work(chip);
380 
381 	kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work,
382 				   msecs_to_jiffies(100));
383 }
384 
385 static int mv88e6xxx_irq_poll_setup(struct mv88e6xxx_chip *chip)
386 {
387 	int err;
388 
389 	err = mv88e6xxx_g1_irq_setup_common(chip);
390 	if (err)
391 		return err;
392 
393 	kthread_init_delayed_work(&chip->irq_poll_work,
394 				  mv88e6xxx_irq_poll);
395 
396 	chip->kworker = kthread_create_worker(0, "%s", dev_name(chip->dev));
397 	if (IS_ERR(chip->kworker))
398 		return PTR_ERR(chip->kworker);
399 
400 	kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work,
401 				   msecs_to_jiffies(100));
402 
403 	return 0;
404 }
405 
406 static void mv88e6xxx_irq_poll_free(struct mv88e6xxx_chip *chip)
407 {
408 	kthread_cancel_delayed_work_sync(&chip->irq_poll_work);
409 	kthread_destroy_worker(chip->kworker);
410 
411 	mv88e6xxx_reg_lock(chip);
412 	mv88e6xxx_g1_irq_free_common(chip);
413 	mv88e6xxx_reg_unlock(chip);
414 }
415 
416 static int mv88e6xxx_port_config_interface(struct mv88e6xxx_chip *chip,
417 					   int port, phy_interface_t interface)
418 {
419 	int err;
420 
421 	if (chip->info->ops->port_set_rgmii_delay) {
422 		err = chip->info->ops->port_set_rgmii_delay(chip, port,
423 							    interface);
424 		if (err && err != -EOPNOTSUPP)
425 			return err;
426 	}
427 
428 	if (chip->info->ops->port_set_cmode) {
429 		err = chip->info->ops->port_set_cmode(chip, port,
430 						      interface);
431 		if (err && err != -EOPNOTSUPP)
432 			return err;
433 	}
434 
435 	return 0;
436 }
437 
438 static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
439 				    int link, int speed, int duplex, int pause,
440 				    phy_interface_t mode)
441 {
442 	int err;
443 
444 	if (!chip->info->ops->port_set_link)
445 		return 0;
446 
447 	/* Port's MAC control must not be changed unless the link is down */
448 	err = chip->info->ops->port_set_link(chip, port, LINK_FORCED_DOWN);
449 	if (err)
450 		return err;
451 
452 	if (chip->info->ops->port_set_speed_duplex) {
453 		err = chip->info->ops->port_set_speed_duplex(chip, port,
454 							     speed, duplex);
455 		if (err && err != -EOPNOTSUPP)
456 			goto restore_link;
457 	}
458 
459 	if (chip->info->ops->port_set_pause) {
460 		err = chip->info->ops->port_set_pause(chip, port, pause);
461 		if (err)
462 			goto restore_link;
463 	}
464 
465 	err = mv88e6xxx_port_config_interface(chip, port, mode);
466 restore_link:
467 	if (chip->info->ops->port_set_link(chip, port, link))
468 		dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
469 
470 	return err;
471 }
472 
473 static int mv88e6xxx_phy_is_internal(struct mv88e6xxx_chip *chip, int port)
474 {
475 	return port >= chip->info->internal_phys_offset &&
476 		port < chip->info->num_internal_phys +
477 			chip->info->internal_phys_offset;
478 }
479 
480 static int mv88e6xxx_port_ppu_updates(struct mv88e6xxx_chip *chip, int port)
481 {
482 	u16 reg;
483 	int err;
484 
485 	/* The 88e6250 family does not have the PHY detect bit. Instead,
486 	 * report whether the port is internal.
487 	 */
488 	if (chip->info->family == MV88E6XXX_FAMILY_6250)
489 		return mv88e6xxx_phy_is_internal(chip, port);
490 
491 	err = mv88e6xxx_port_read(chip, port, MV88E6XXX_PORT_STS, &reg);
492 	if (err) {
493 		dev_err(chip->dev,
494 			"p%d: %s: failed to read port status\n",
495 			port, __func__);
496 		return err;
497 	}
498 
499 	return !!(reg & MV88E6XXX_PORT_STS_PHY_DETECT);
500 }
501 
502 static const u8 mv88e6185_phy_interface_modes[] = {
503 	[MV88E6185_PORT_STS_CMODE_GMII_FD]	 = PHY_INTERFACE_MODE_GMII,
504 	[MV88E6185_PORT_STS_CMODE_MII_100_FD_PS] = PHY_INTERFACE_MODE_MII,
505 	[MV88E6185_PORT_STS_CMODE_MII_100]	 = PHY_INTERFACE_MODE_MII,
506 	[MV88E6185_PORT_STS_CMODE_MII_10]	 = PHY_INTERFACE_MODE_MII,
507 	[MV88E6185_PORT_STS_CMODE_SERDES]	 = PHY_INTERFACE_MODE_1000BASEX,
508 	[MV88E6185_PORT_STS_CMODE_1000BASE_X]	 = PHY_INTERFACE_MODE_1000BASEX,
509 	[MV88E6185_PORT_STS_CMODE_PHY]		 = PHY_INTERFACE_MODE_SGMII,
510 };
511 
512 static void mv88e6095_phylink_get_caps(struct mv88e6xxx_chip *chip, int port,
513 				       struct phylink_config *config)
514 {
515 	u8 cmode = chip->ports[port].cmode;
516 
517 	config->mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100;
518 
519 	if (mv88e6xxx_phy_is_internal(chip, port)) {
520 		__set_bit(PHY_INTERFACE_MODE_MII, config->supported_interfaces);
521 	} else {
522 		if (cmode < ARRAY_SIZE(mv88e6185_phy_interface_modes) &&
523 		    mv88e6185_phy_interface_modes[cmode])
524 			__set_bit(mv88e6185_phy_interface_modes[cmode],
525 				  config->supported_interfaces);
526 
527 		config->mac_capabilities |= MAC_1000FD;
528 	}
529 }
530 
531 static void mv88e6185_phylink_get_caps(struct mv88e6xxx_chip *chip, int port,
532 				       struct phylink_config *config)
533 {
534 	u8 cmode = chip->ports[port].cmode;
535 
536 	if (cmode < ARRAY_SIZE(mv88e6185_phy_interface_modes) &&
537 	    mv88e6185_phy_interface_modes[cmode])
538 		__set_bit(mv88e6185_phy_interface_modes[cmode],
539 			  config->supported_interfaces);
540 
541 	config->mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100 |
542 				   MAC_1000FD;
543 }
544 
545 static const u8 mv88e6xxx_phy_interface_modes[] = {
546 	[MV88E6XXX_PORT_STS_CMODE_MII_PHY]	= PHY_INTERFACE_MODE_REVMII,
547 	[MV88E6XXX_PORT_STS_CMODE_MII]		= PHY_INTERFACE_MODE_MII,
548 	[MV88E6XXX_PORT_STS_CMODE_GMII]		= PHY_INTERFACE_MODE_GMII,
549 	[MV88E6XXX_PORT_STS_CMODE_RMII_PHY]	= PHY_INTERFACE_MODE_REVRMII,
550 	[MV88E6XXX_PORT_STS_CMODE_RMII]		= PHY_INTERFACE_MODE_RMII,
551 	[MV88E6XXX_PORT_STS_CMODE_100BASEX]	= PHY_INTERFACE_MODE_100BASEX,
552 	[MV88E6XXX_PORT_STS_CMODE_1000BASEX]	= PHY_INTERFACE_MODE_1000BASEX,
553 	[MV88E6XXX_PORT_STS_CMODE_SGMII]	= PHY_INTERFACE_MODE_SGMII,
554 	/* higher interface modes are not needed here, since ports supporting
555 	 * them are writable, and so the supported interfaces are filled in the
556 	 * corresponding .phylink_set_interfaces() implementation below
557 	 */
558 };
559 
560 static void mv88e6xxx_translate_cmode(u8 cmode, unsigned long *supported)
561 {
562 	if (cmode < ARRAY_SIZE(mv88e6xxx_phy_interface_modes) &&
563 	    mv88e6xxx_phy_interface_modes[cmode])
564 		__set_bit(mv88e6xxx_phy_interface_modes[cmode], supported);
565 	else if (cmode == MV88E6XXX_PORT_STS_CMODE_RGMII)
566 		phy_interface_set_rgmii(supported);
567 }
568 
569 static void
570 mv88e6250_setup_supported_interfaces(struct mv88e6xxx_chip *chip, int port,
571 				     struct phylink_config *config)
572 {
573 	unsigned long *supported = config->supported_interfaces;
574 	int err;
575 	u16 reg;
576 
577 	err = mv88e6xxx_port_read(chip, port, MV88E6XXX_PORT_STS, &reg);
578 	if (err) {
579 		dev_err(chip->dev, "p%d: failed to read port status\n", port);
580 		return;
581 	}
582 
583 	switch (reg & MV88E6250_PORT_STS_PORTMODE_MASK) {
584 	case MV88E6250_PORT_STS_PORTMODE_MII_10_HALF_PHY:
585 	case MV88E6250_PORT_STS_PORTMODE_MII_100_HALF_PHY:
586 	case MV88E6250_PORT_STS_PORTMODE_MII_10_FULL_PHY:
587 	case MV88E6250_PORT_STS_PORTMODE_MII_100_FULL_PHY:
588 		__set_bit(PHY_INTERFACE_MODE_REVMII, supported);
589 		break;
590 
591 	case MV88E6250_PORT_STS_PORTMODE_MII_HALF:
592 	case MV88E6250_PORT_STS_PORTMODE_MII_FULL:
593 		__set_bit(PHY_INTERFACE_MODE_MII, supported);
594 		break;
595 
596 	case MV88E6250_PORT_STS_PORTMODE_MII_DUAL_100_RMII_FULL_PHY:
597 	case MV88E6250_PORT_STS_PORTMODE_MII_200_RMII_FULL_PHY:
598 	case MV88E6250_PORT_STS_PORTMODE_MII_10_100_RMII_HALF_PHY:
599 	case MV88E6250_PORT_STS_PORTMODE_MII_10_100_RMII_FULL_PHY:
600 		__set_bit(PHY_INTERFACE_MODE_REVRMII, supported);
601 		break;
602 
603 	case MV88E6250_PORT_STS_PORTMODE_MII_DUAL_100_RMII_FULL:
604 	case MV88E6250_PORT_STS_PORTMODE_MII_10_100_RMII_FULL:
605 		__set_bit(PHY_INTERFACE_MODE_RMII, supported);
606 		break;
607 
608 	case MV88E6250_PORT_STS_PORTMODE_MII_100_RGMII:
609 		__set_bit(PHY_INTERFACE_MODE_RGMII, supported);
610 		break;
611 
612 	default:
613 		dev_err(chip->dev,
614 			"p%d: invalid port mode in status register: %04x\n",
615 			port, reg);
616 	}
617 }
618 
619 static void mv88e6250_phylink_get_caps(struct mv88e6xxx_chip *chip, int port,
620 				       struct phylink_config *config)
621 {
622 	if (!mv88e6xxx_phy_is_internal(chip, port))
623 		mv88e6250_setup_supported_interfaces(chip, port, config);
624 
625 	config->mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100;
626 }
627 
628 static void mv88e6351_phylink_get_caps(struct mv88e6xxx_chip *chip, int port,
629 				       struct phylink_config *config)
630 {
631 	unsigned long *supported = config->supported_interfaces;
632 
633 	/* Translate the default cmode */
634 	mv88e6xxx_translate_cmode(chip->ports[port].cmode, supported);
635 
636 	config->mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100 |
637 				   MAC_1000FD;
638 }
639 
640 static int mv88e63xx_get_port_serdes_cmode(struct mv88e6xxx_chip *chip, int port)
641 {
642 	u16 reg, val;
643 	int err;
644 
645 	err = mv88e6xxx_port_read(chip, port, MV88E6XXX_PORT_STS, &reg);
646 	if (err)
647 		return err;
648 
649 	/* If PHY_DETECT is zero, then we are not in auto-media mode */
650 	if (!(reg & MV88E6XXX_PORT_STS_PHY_DETECT))
651 		return 0xf;
652 
653 	val = reg & ~MV88E6XXX_PORT_STS_PHY_DETECT;
654 	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_STS, val);
655 	if (err)
656 		return err;
657 
658 	err = mv88e6xxx_port_read(chip, port, MV88E6XXX_PORT_STS, &val);
659 	if (err)
660 		return err;
661 
662 	/* Restore PHY_DETECT value */
663 	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_STS, reg);
664 	if (err)
665 		return err;
666 
667 	return val & MV88E6XXX_PORT_STS_CMODE_MASK;
668 }
669 
670 static void mv88e6352_phylink_get_caps(struct mv88e6xxx_chip *chip, int port,
671 				       struct phylink_config *config)
672 {
673 	unsigned long *supported = config->supported_interfaces;
674 	int err, cmode;
675 
676 	/* Translate the default cmode */
677 	mv88e6xxx_translate_cmode(chip->ports[port].cmode, supported);
678 
679 	config->mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100 |
680 				   MAC_1000FD;
681 
682 	/* Port 4 supports automedia if the serdes is associated with it. */
683 	if (port == 4) {
684 		err = mv88e6352_g2_scratch_port_has_serdes(chip, port);
685 		if (err < 0)
686 			dev_err(chip->dev, "p%d: failed to read scratch\n",
687 				port);
688 		if (err <= 0)
689 			return;
690 
691 		cmode = mv88e63xx_get_port_serdes_cmode(chip, port);
692 		if (cmode < 0)
693 			dev_err(chip->dev, "p%d: failed to read serdes cmode\n",
694 				port);
695 		else
696 			mv88e6xxx_translate_cmode(cmode, supported);
697 	}
698 }
699 
700 static void mv88e632x_phylink_get_caps(struct mv88e6xxx_chip *chip, int port,
701 				       struct phylink_config *config)
702 {
703 	unsigned long *supported = config->supported_interfaces;
704 	int cmode;
705 
706 	/* Translate the default cmode */
707 	mv88e6xxx_translate_cmode(chip->ports[port].cmode, supported);
708 
709 	config->mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100 |
710 				   MAC_1000FD;
711 
712 	/* Port 0/1 are serdes only ports */
713 	if (port == 0 || port == 1) {
714 		cmode = mv88e63xx_get_port_serdes_cmode(chip, port);
715 		if (cmode < 0)
716 			dev_err(chip->dev, "p%d: failed to read serdes cmode\n",
717 				port);
718 		else
719 			mv88e6xxx_translate_cmode(cmode, supported);
720 	}
721 }
722 
723 static void mv88e6341_phylink_get_caps(struct mv88e6xxx_chip *chip, int port,
724 				       struct phylink_config *config)
725 {
726 	unsigned long *supported = config->supported_interfaces;
727 
728 	/* Translate the default cmode */
729 	mv88e6xxx_translate_cmode(chip->ports[port].cmode, supported);
730 
731 	/* No ethtool bits for 200Mbps */
732 	config->mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100 |
733 				   MAC_1000FD;
734 
735 	/* The C_Mode field is programmable on port 5 */
736 	if (port == 5) {
737 		__set_bit(PHY_INTERFACE_MODE_SGMII, supported);
738 		__set_bit(PHY_INTERFACE_MODE_1000BASEX, supported);
739 		__set_bit(PHY_INTERFACE_MODE_2500BASEX, supported);
740 
741 		config->mac_capabilities |= MAC_2500FD;
742 	}
743 }
744 
745 static void mv88e6390_phylink_get_caps(struct mv88e6xxx_chip *chip, int port,
746 				       struct phylink_config *config)
747 {
748 	unsigned long *supported = config->supported_interfaces;
749 
750 	/* Translate the default cmode */
751 	mv88e6xxx_translate_cmode(chip->ports[port].cmode, supported);
752 
753 	/* No ethtool bits for 200Mbps */
754 	config->mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100 |
755 				   MAC_1000FD;
756 
757 	/* The C_Mode field is programmable on ports 9 and 10 */
758 	if (port == 9 || port == 10) {
759 		__set_bit(PHY_INTERFACE_MODE_SGMII, supported);
760 		__set_bit(PHY_INTERFACE_MODE_1000BASEX, supported);
761 		__set_bit(PHY_INTERFACE_MODE_2500BASEX, supported);
762 
763 		config->mac_capabilities |= MAC_2500FD;
764 	}
765 }
766 
767 static void mv88e6390x_phylink_get_caps(struct mv88e6xxx_chip *chip, int port,
768 					struct phylink_config *config)
769 {
770 	unsigned long *supported = config->supported_interfaces;
771 
772 	mv88e6390_phylink_get_caps(chip, port, config);
773 
774 	/* For the 6x90X, ports 2-7 can be in automedia mode.
775 	 * (Note that 6x90 doesn't support RXAUI nor XAUI).
776 	 *
777 	 * Port 2 can also support 1000BASE-X in automedia mode if port 9 is
778 	 * configured for 1000BASE-X, SGMII or 2500BASE-X.
779 	 * Port 3-4 can also support 1000BASE-X in automedia mode if port 9 is
780 	 * configured for RXAUI, 1000BASE-X, SGMII or 2500BASE-X.
781 	 *
782 	 * Port 5 can also support 1000BASE-X in automedia mode if port 10 is
783 	 * configured for 1000BASE-X, SGMII or 2500BASE-X.
784 	 * Port 6-7 can also support 1000BASE-X in automedia mode if port 10 is
785 	 * configured for RXAUI, 1000BASE-X, SGMII or 2500BASE-X.
786 	 *
787 	 * For now, be permissive (as the old code was) and allow 1000BASE-X
788 	 * on ports 2..7.
789 	 */
790 	if (port >= 2 && port <= 7)
791 		__set_bit(PHY_INTERFACE_MODE_1000BASEX, supported);
792 
793 	/* The C_Mode field can also be programmed for 10G speeds */
794 	if (port == 9 || port == 10) {
795 		__set_bit(PHY_INTERFACE_MODE_XAUI, supported);
796 		__set_bit(PHY_INTERFACE_MODE_RXAUI, supported);
797 
798 		config->mac_capabilities |= MAC_10000FD;
799 	}
800 }
801 
802 static void mv88e6393x_phylink_get_caps(struct mv88e6xxx_chip *chip, int port,
803 					struct phylink_config *config)
804 {
805 	unsigned long *supported = config->supported_interfaces;
806 	bool is_6191x =
807 		chip->info->prod_num == MV88E6XXX_PORT_SWITCH_ID_PROD_6191X;
808 	bool is_6361 =
809 		chip->info->prod_num == MV88E6XXX_PORT_SWITCH_ID_PROD_6361;
810 
811 	mv88e6xxx_translate_cmode(chip->ports[port].cmode, supported);
812 
813 	config->mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100 |
814 				   MAC_1000FD;
815 
816 	/* The C_Mode field can be programmed for ports 0, 9 and 10 */
817 	if (port == 0 || port == 9 || port == 10) {
818 		__set_bit(PHY_INTERFACE_MODE_SGMII, supported);
819 		__set_bit(PHY_INTERFACE_MODE_1000BASEX, supported);
820 
821 		/* 6191X supports >1G modes only on port 10 */
822 		if (!is_6191x || port == 10) {
823 			__set_bit(PHY_INTERFACE_MODE_2500BASEX, supported);
824 			config->mac_capabilities |= MAC_2500FD;
825 
826 			/* 6361 only supports up to 2500BaseX */
827 			if (!is_6361) {
828 				__set_bit(PHY_INTERFACE_MODE_5GBASER, supported);
829 				__set_bit(PHY_INTERFACE_MODE_10GBASER, supported);
830 				__set_bit(PHY_INTERFACE_MODE_USXGMII, supported);
831 				config->mac_capabilities |= MAC_5000FD |
832 					MAC_10000FD;
833 			}
834 		}
835 	}
836 
837 	if (port == 0) {
838 		__set_bit(PHY_INTERFACE_MODE_RMII, supported);
839 		__set_bit(PHY_INTERFACE_MODE_RGMII, supported);
840 		__set_bit(PHY_INTERFACE_MODE_RGMII_ID, supported);
841 		__set_bit(PHY_INTERFACE_MODE_RGMII_RXID, supported);
842 		__set_bit(PHY_INTERFACE_MODE_RGMII_TXID, supported);
843 	}
844 }
845 
846 static void mv88e6xxx_get_caps(struct dsa_switch *ds, int port,
847 			       struct phylink_config *config)
848 {
849 	struct mv88e6xxx_chip *chip = ds->priv;
850 
851 	mv88e6xxx_reg_lock(chip);
852 	chip->info->ops->phylink_get_caps(chip, port, config);
853 	mv88e6xxx_reg_unlock(chip);
854 
855 	if (mv88e6xxx_phy_is_internal(chip, port)) {
856 		__set_bit(PHY_INTERFACE_MODE_INTERNAL,
857 			  config->supported_interfaces);
858 		/* Internal ports with no phy-mode need GMII for PHYLIB */
859 		__set_bit(PHY_INTERFACE_MODE_GMII,
860 			  config->supported_interfaces);
861 	}
862 }
863 
864 static struct phylink_pcs *
865 mv88e6xxx_mac_select_pcs(struct phylink_config *config,
866 			 phy_interface_t interface)
867 {
868 	struct dsa_port *dp = dsa_phylink_to_port(config);
869 	struct mv88e6xxx_chip *chip = dp->ds->priv;
870 	struct phylink_pcs *pcs = ERR_PTR(-EOPNOTSUPP);
871 
872 	if (chip->info->ops->pcs_ops)
873 		pcs = chip->info->ops->pcs_ops->pcs_select(chip, dp->index,
874 							   interface);
875 
876 	return pcs;
877 }
878 
879 static int mv88e6xxx_mac_prepare(struct phylink_config *config,
880 				 unsigned int mode, phy_interface_t interface)
881 {
882 	struct dsa_port *dp = dsa_phylink_to_port(config);
883 	struct mv88e6xxx_chip *chip = dp->ds->priv;
884 	int port = dp->index;
885 	int err = 0;
886 
887 	/* In inband mode, the link may come up at any time while the link
888 	 * is not forced down. Force the link down while we reconfigure the
889 	 * interface mode.
890 	 */
891 	if (mode == MLO_AN_INBAND &&
892 	    chip->ports[port].interface != interface &&
893 	    chip->info->ops->port_set_link) {
894 		mv88e6xxx_reg_lock(chip);
895 		err = chip->info->ops->port_set_link(chip, port,
896 						     LINK_FORCED_DOWN);
897 		mv88e6xxx_reg_unlock(chip);
898 	}
899 
900 	return err;
901 }
902 
903 static void mv88e6xxx_mac_config(struct phylink_config *config,
904 				 unsigned int mode,
905 				 const struct phylink_link_state *state)
906 {
907 	struct dsa_port *dp = dsa_phylink_to_port(config);
908 	struct mv88e6xxx_chip *chip = dp->ds->priv;
909 	int port = dp->index;
910 	int err = 0;
911 
912 	mv88e6xxx_reg_lock(chip);
913 
914 	if (mode != MLO_AN_PHY || !mv88e6xxx_phy_is_internal(chip, port)) {
915 		err = mv88e6xxx_port_config_interface(chip, port,
916 						      state->interface);
917 		if (err && err != -EOPNOTSUPP)
918 			goto err_unlock;
919 	}
920 
921 err_unlock:
922 	mv88e6xxx_reg_unlock(chip);
923 
924 	if (err && err != -EOPNOTSUPP)
925 		dev_err(chip->dev, "p%d: failed to configure MAC/PCS\n", port);
926 }
927 
928 static int mv88e6xxx_mac_finish(struct phylink_config *config,
929 				unsigned int mode, phy_interface_t interface)
930 {
931 	struct dsa_port *dp = dsa_phylink_to_port(config);
932 	struct mv88e6xxx_chip *chip = dp->ds->priv;
933 	int port = dp->index;
934 	int err = 0;
935 
936 	/* Undo the forced down state above after completing configuration
937 	 * irrespective of its state on entry, which allows the link to come
938 	 * up in the in-band case where there is no separate SERDES. Also
939 	 * ensure that the link can come up if the PPU is in use and we are
940 	 * in PHY mode (we treat the PPU as an effective in-band mechanism.)
941 	 */
942 	mv88e6xxx_reg_lock(chip);
943 
944 	if (chip->info->ops->port_set_link &&
945 	    ((mode == MLO_AN_INBAND &&
946 	      chip->ports[port].interface != interface) ||
947 	     (mode == MLO_AN_PHY && mv88e6xxx_port_ppu_updates(chip, port))))
948 		err = chip->info->ops->port_set_link(chip, port, LINK_UNFORCED);
949 
950 	mv88e6xxx_reg_unlock(chip);
951 
952 	chip->ports[port].interface = interface;
953 
954 	return err;
955 }
956 
957 static void mv88e6xxx_mac_link_down(struct phylink_config *config,
958 				    unsigned int mode,
959 				    phy_interface_t interface)
960 {
961 	struct dsa_port *dp = dsa_phylink_to_port(config);
962 	struct mv88e6xxx_chip *chip = dp->ds->priv;
963 	const struct mv88e6xxx_ops *ops;
964 	int port = dp->index;
965 	int err = 0;
966 
967 	ops = chip->info->ops;
968 
969 	mv88e6xxx_reg_lock(chip);
970 	/* Force the link down if we know the port may not be automatically
971 	 * updated by the switch or if we are using fixed-link mode.
972 	 */
973 	if ((!mv88e6xxx_port_ppu_updates(chip, port) ||
974 	     mode == MLO_AN_FIXED) && ops->port_sync_link)
975 		err = ops->port_sync_link(chip, port, mode, false);
976 
977 	if (!err && ops->port_set_speed_duplex)
978 		err = ops->port_set_speed_duplex(chip, port, SPEED_UNFORCED,
979 						 DUPLEX_UNFORCED);
980 	mv88e6xxx_reg_unlock(chip);
981 
982 	if (err)
983 		dev_err(chip->dev,
984 			"p%d: failed to force MAC link down\n", port);
985 }
986 
987 static void mv88e6xxx_mac_link_up(struct phylink_config *config,
988 				  struct phy_device *phydev,
989 				  unsigned int mode, phy_interface_t interface,
990 				  int speed, int duplex,
991 				  bool tx_pause, bool rx_pause)
992 {
993 	struct dsa_port *dp = dsa_phylink_to_port(config);
994 	struct mv88e6xxx_chip *chip = dp->ds->priv;
995 	const struct mv88e6xxx_ops *ops;
996 	int port = dp->index;
997 	int err = 0;
998 
999 	ops = chip->info->ops;
1000 
1001 	mv88e6xxx_reg_lock(chip);
1002 	/* Configure and force the link up if we know that the port may not
1003 	 * automatically updated by the switch or if we are using fixed-link
1004 	 * mode.
1005 	 */
1006 	if (!mv88e6xxx_port_ppu_updates(chip, port) ||
1007 	    mode == MLO_AN_FIXED) {
1008 		if (ops->port_set_speed_duplex) {
1009 			err = ops->port_set_speed_duplex(chip, port,
1010 							 speed, duplex);
1011 			if (err && err != -EOPNOTSUPP)
1012 				goto error;
1013 		}
1014 
1015 		if (ops->port_sync_link)
1016 			err = ops->port_sync_link(chip, port, mode, true);
1017 	}
1018 error:
1019 	mv88e6xxx_reg_unlock(chip);
1020 
1021 	if (err && err != -EOPNOTSUPP)
1022 		dev_err(chip->dev,
1023 			"p%d: failed to configure MAC link up\n", port);
1024 }
1025 
1026 static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
1027 {
1028 	int err;
1029 
1030 	if (!chip->info->ops->stats_snapshot)
1031 		return -EOPNOTSUPP;
1032 
1033 	mv88e6xxx_reg_lock(chip);
1034 	err = chip->info->ops->stats_snapshot(chip, port);
1035 	mv88e6xxx_reg_unlock(chip);
1036 
1037 	return err;
1038 }
1039 
1040 #define MV88E6XXX_HW_STAT_MAPPER(_fn)				    \
1041 	_fn(in_good_octets,		8, 0x00, STATS_TYPE_BANK0), \
1042 	_fn(in_bad_octets,		4, 0x02, STATS_TYPE_BANK0), \
1043 	_fn(in_unicast,			4, 0x04, STATS_TYPE_BANK0), \
1044 	_fn(in_broadcasts,		4, 0x06, STATS_TYPE_BANK0), \
1045 	_fn(in_multicasts,		4, 0x07, STATS_TYPE_BANK0), \
1046 	_fn(in_pause,			4, 0x16, STATS_TYPE_BANK0), \
1047 	_fn(in_undersize,		4, 0x18, STATS_TYPE_BANK0), \
1048 	_fn(in_fragments,		4, 0x19, STATS_TYPE_BANK0), \
1049 	_fn(in_oversize,		4, 0x1a, STATS_TYPE_BANK0), \
1050 	_fn(in_jabber,			4, 0x1b, STATS_TYPE_BANK0), \
1051 	_fn(in_rx_error,		4, 0x1c, STATS_TYPE_BANK0), \
1052 	_fn(in_fcs_error,		4, 0x1d, STATS_TYPE_BANK0), \
1053 	_fn(out_octets,			8, 0x0e, STATS_TYPE_BANK0), \
1054 	_fn(out_unicast,		4, 0x10, STATS_TYPE_BANK0), \
1055 	_fn(out_broadcasts,		4, 0x13, STATS_TYPE_BANK0), \
1056 	_fn(out_multicasts,		4, 0x12, STATS_TYPE_BANK0), \
1057 	_fn(out_pause,			4, 0x15, STATS_TYPE_BANK0), \
1058 	_fn(excessive,			4, 0x11, STATS_TYPE_BANK0), \
1059 	_fn(collisions,			4, 0x1e, STATS_TYPE_BANK0), \
1060 	_fn(deferred,			4, 0x05, STATS_TYPE_BANK0), \
1061 	_fn(single,			4, 0x14, STATS_TYPE_BANK0), \
1062 	_fn(multiple,			4, 0x17, STATS_TYPE_BANK0), \
1063 	_fn(out_fcs_error,		4, 0x03, STATS_TYPE_BANK0), \
1064 	_fn(late,			4, 0x1f, STATS_TYPE_BANK0), \
1065 	_fn(hist_64bytes,		4, 0x08, STATS_TYPE_BANK0), \
1066 	_fn(hist_65_127bytes,		4, 0x09, STATS_TYPE_BANK0), \
1067 	_fn(hist_128_255bytes,		4, 0x0a, STATS_TYPE_BANK0), \
1068 	_fn(hist_256_511bytes,		4, 0x0b, STATS_TYPE_BANK0), \
1069 	_fn(hist_512_1023bytes,		4, 0x0c, STATS_TYPE_BANK0), \
1070 	_fn(hist_1024_max_bytes,	4, 0x0d, STATS_TYPE_BANK0), \
1071 	_fn(sw_in_discards,		4, 0x10, STATS_TYPE_PORT), \
1072 	_fn(sw_in_filtered,		2, 0x12, STATS_TYPE_PORT), \
1073 	_fn(sw_out_filtered,		2, 0x13, STATS_TYPE_PORT), \
1074 	_fn(in_discards,		4, 0x00, STATS_TYPE_BANK1), \
1075 	_fn(in_filtered,		4, 0x01, STATS_TYPE_BANK1), \
1076 	_fn(in_accepted,		4, 0x02, STATS_TYPE_BANK1), \
1077 	_fn(in_bad_accepted,		4, 0x03, STATS_TYPE_BANK1), \
1078 	_fn(in_good_avb_class_a,	4, 0x04, STATS_TYPE_BANK1), \
1079 	_fn(in_good_avb_class_b,	4, 0x05, STATS_TYPE_BANK1), \
1080 	_fn(in_bad_avb_class_a,		4, 0x06, STATS_TYPE_BANK1), \
1081 	_fn(in_bad_avb_class_b,		4, 0x07, STATS_TYPE_BANK1), \
1082 	_fn(tcam_counter_0,		4, 0x08, STATS_TYPE_BANK1), \
1083 	_fn(tcam_counter_1,		4, 0x09, STATS_TYPE_BANK1), \
1084 	_fn(tcam_counter_2,		4, 0x0a, STATS_TYPE_BANK1), \
1085 	_fn(tcam_counter_3,		4, 0x0b, STATS_TYPE_BANK1), \
1086 	_fn(in_da_unknown,		4, 0x0e, STATS_TYPE_BANK1), \
1087 	_fn(in_management,		4, 0x0f, STATS_TYPE_BANK1), \
1088 	_fn(out_queue_0,		4, 0x10, STATS_TYPE_BANK1), \
1089 	_fn(out_queue_1,		4, 0x11, STATS_TYPE_BANK1), \
1090 	_fn(out_queue_2,		4, 0x12, STATS_TYPE_BANK1), \
1091 	_fn(out_queue_3,		4, 0x13, STATS_TYPE_BANK1), \
1092 	_fn(out_queue_4,		4, 0x14, STATS_TYPE_BANK1), \
1093 	_fn(out_queue_5,		4, 0x15, STATS_TYPE_BANK1), \
1094 	_fn(out_queue_6,		4, 0x16, STATS_TYPE_BANK1), \
1095 	_fn(out_queue_7,		4, 0x17, STATS_TYPE_BANK1), \
1096 	_fn(out_cut_through,		4, 0x18, STATS_TYPE_BANK1), \
1097 	_fn(out_octets_a,		4, 0x1a, STATS_TYPE_BANK1), \
1098 	_fn(out_octets_b,		4, 0x1b, STATS_TYPE_BANK1), \
1099 	_fn(out_management,		4, 0x1f, STATS_TYPE_BANK1), \
1100 	/*  */
1101 
1102 #define MV88E6XXX_HW_STAT_ENTRY(_string, _size, _reg, _type) \
1103 	{ #_string, _size, _reg, _type }
1104 static const struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
1105 	MV88E6XXX_HW_STAT_MAPPER(MV88E6XXX_HW_STAT_ENTRY)
1106 };
1107 
1108 #define MV88E6XXX_HW_STAT_ENUM(_string, _size, _reg, _type) \
1109 	MV88E6XXX_HW_STAT_ID_ ## _string
1110 enum mv88e6xxx_hw_stat_id {
1111 	MV88E6XXX_HW_STAT_MAPPER(MV88E6XXX_HW_STAT_ENUM)
1112 };
1113 
1114 static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
1115 					    const struct mv88e6xxx_hw_stat *s,
1116 					    int port, u16 bank1_select,
1117 					    u16 histogram)
1118 {
1119 	u32 low;
1120 	u32 high = 0;
1121 	u16 reg = 0;
1122 	int err;
1123 	u64 value;
1124 
1125 	switch (s->type) {
1126 	case STATS_TYPE_PORT:
1127 		err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
1128 		if (err)
1129 			return U64_MAX;
1130 
1131 		low = reg;
1132 		if (s->size == 4) {
1133 			err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
1134 			if (err)
1135 				return U64_MAX;
1136 			low |= ((u32)reg) << 16;
1137 		}
1138 		break;
1139 	case STATS_TYPE_BANK1:
1140 		reg = bank1_select;
1141 		fallthrough;
1142 	case STATS_TYPE_BANK0:
1143 		reg |= s->reg | histogram;
1144 		mv88e6xxx_g1_stats_read(chip, reg, &low);
1145 		if (s->size == 8)
1146 			mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
1147 		break;
1148 	default:
1149 		return U64_MAX;
1150 	}
1151 	value = (((u64)high) << 32) | low;
1152 	return value;
1153 }
1154 
1155 static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
1156 				       uint8_t *data, int types)
1157 {
1158 	const struct mv88e6xxx_hw_stat *stat;
1159 	int i, j;
1160 
1161 	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
1162 		stat = &mv88e6xxx_hw_stats[i];
1163 		if (stat->type & types) {
1164 			memcpy(data + j * ETH_GSTRING_LEN, stat->string,
1165 			       ETH_GSTRING_LEN);
1166 			j++;
1167 		}
1168 	}
1169 
1170 	return j;
1171 }
1172 
1173 static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
1174 				       uint8_t *data)
1175 {
1176 	return mv88e6xxx_stats_get_strings(chip, data,
1177 					   STATS_TYPE_BANK0 | STATS_TYPE_PORT);
1178 }
1179 
1180 static int mv88e6250_stats_get_strings(struct mv88e6xxx_chip *chip,
1181 				       uint8_t *data)
1182 {
1183 	return mv88e6xxx_stats_get_strings(chip, data, STATS_TYPE_BANK0);
1184 }
1185 
1186 static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
1187 				       uint8_t *data)
1188 {
1189 	return mv88e6xxx_stats_get_strings(chip, data,
1190 					   STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
1191 }
1192 
1193 static const uint8_t *mv88e6xxx_atu_vtu_stats_strings[] = {
1194 	"atu_member_violation",
1195 	"atu_miss_violation",
1196 	"atu_full_violation",
1197 	"vtu_member_violation",
1198 	"vtu_miss_violation",
1199 };
1200 
1201 static void mv88e6xxx_atu_vtu_get_strings(uint8_t *data)
1202 {
1203 	unsigned int i;
1204 
1205 	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings); i++)
1206 		strscpy(data + i * ETH_GSTRING_LEN,
1207 			mv88e6xxx_atu_vtu_stats_strings[i],
1208 			ETH_GSTRING_LEN);
1209 }
1210 
1211 static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
1212 				  u32 stringset, uint8_t *data)
1213 {
1214 	struct mv88e6xxx_chip *chip = ds->priv;
1215 	int count = 0;
1216 
1217 	if (stringset != ETH_SS_STATS)
1218 		return;
1219 
1220 	mv88e6xxx_reg_lock(chip);
1221 
1222 	if (chip->info->ops->stats_get_strings)
1223 		count = chip->info->ops->stats_get_strings(chip, data);
1224 
1225 	if (chip->info->ops->serdes_get_strings) {
1226 		data += count * ETH_GSTRING_LEN;
1227 		count = chip->info->ops->serdes_get_strings(chip, port, data);
1228 	}
1229 
1230 	data += count * ETH_GSTRING_LEN;
1231 	mv88e6xxx_atu_vtu_get_strings(data);
1232 
1233 	mv88e6xxx_reg_unlock(chip);
1234 }
1235 
1236 static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
1237 					  int types)
1238 {
1239 	const struct mv88e6xxx_hw_stat *stat;
1240 	int i, j;
1241 
1242 	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
1243 		stat = &mv88e6xxx_hw_stats[i];
1244 		if (stat->type & types)
1245 			j++;
1246 	}
1247 	return j;
1248 }
1249 
1250 static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
1251 {
1252 	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
1253 					      STATS_TYPE_PORT);
1254 }
1255 
1256 static int mv88e6250_stats_get_sset_count(struct mv88e6xxx_chip *chip)
1257 {
1258 	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0);
1259 }
1260 
1261 static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
1262 {
1263 	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
1264 					      STATS_TYPE_BANK1);
1265 }
1266 
1267 static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
1268 {
1269 	struct mv88e6xxx_chip *chip = ds->priv;
1270 	int serdes_count = 0;
1271 	int count = 0;
1272 
1273 	if (sset != ETH_SS_STATS)
1274 		return 0;
1275 
1276 	mv88e6xxx_reg_lock(chip);
1277 	if (chip->info->ops->stats_get_sset_count)
1278 		count = chip->info->ops->stats_get_sset_count(chip);
1279 	if (count < 0)
1280 		goto out;
1281 
1282 	if (chip->info->ops->serdes_get_sset_count)
1283 		serdes_count = chip->info->ops->serdes_get_sset_count(chip,
1284 								      port);
1285 	if (serdes_count < 0) {
1286 		count = serdes_count;
1287 		goto out;
1288 	}
1289 	count += serdes_count;
1290 	count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);
1291 
1292 out:
1293 	mv88e6xxx_reg_unlock(chip);
1294 
1295 	return count;
1296 }
1297 
1298 static size_t mv88e6095_stats_get_stat(struct mv88e6xxx_chip *chip, int port,
1299 				       const struct mv88e6xxx_hw_stat *stat,
1300 				       uint64_t *data)
1301 {
1302 	if (!(stat->type & (STATS_TYPE_BANK0 | STATS_TYPE_PORT)))
1303 		return 0;
1304 
1305 	*data = _mv88e6xxx_get_ethtool_stat(chip, stat, port, 0,
1306 					    MV88E6XXX_G1_STATS_OP_HIST_RX);
1307 	return 1;
1308 }
1309 
1310 static size_t mv88e6250_stats_get_stat(struct mv88e6xxx_chip *chip, int port,
1311 				       const struct mv88e6xxx_hw_stat *stat,
1312 				       uint64_t *data)
1313 {
1314 	if (!(stat->type & STATS_TYPE_BANK0))
1315 		return 0;
1316 
1317 	*data = _mv88e6xxx_get_ethtool_stat(chip, stat, port, 0,
1318 					    MV88E6XXX_G1_STATS_OP_HIST_RX);
1319 	return 1;
1320 }
1321 
1322 static size_t mv88e6320_stats_get_stat(struct mv88e6xxx_chip *chip, int port,
1323 				       const struct mv88e6xxx_hw_stat *stat,
1324 				       uint64_t *data)
1325 {
1326 	if (!(stat->type & (STATS_TYPE_BANK0 | STATS_TYPE_BANK1)))
1327 		return 0;
1328 
1329 	*data = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
1330 					    MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
1331 					    MV88E6XXX_G1_STATS_OP_HIST_RX);
1332 	return 1;
1333 }
1334 
1335 static size_t mv88e6390_stats_get_stat(struct mv88e6xxx_chip *chip, int port,
1336 				       const struct mv88e6xxx_hw_stat *stat,
1337 				       uint64_t *data)
1338 {
1339 	if (!(stat->type & (STATS_TYPE_BANK0 | STATS_TYPE_BANK1)))
1340 		return 0;
1341 
1342 	*data = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
1343 					    MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
1344 					    0);
1345 	return 1;
1346 }
1347 
1348 static size_t mv88e6xxx_stats_get_stat(struct mv88e6xxx_chip *chip, int port,
1349 				       const struct mv88e6xxx_hw_stat *stat,
1350 				       uint64_t *data)
1351 {
1352 	int ret = 0;
1353 
1354 	if (chip->info->ops->stats_get_stat) {
1355 		mv88e6xxx_reg_lock(chip);
1356 		ret = chip->info->ops->stats_get_stat(chip, port, stat, data);
1357 		mv88e6xxx_reg_unlock(chip);
1358 	}
1359 
1360 	return ret;
1361 }
1362 
1363 static size_t mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1364 					uint64_t *data)
1365 {
1366 	const struct mv88e6xxx_hw_stat *stat;
1367 	size_t i, j;
1368 
1369 	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
1370 		stat = &mv88e6xxx_hw_stats[i];
1371 		j += mv88e6xxx_stats_get_stat(chip, port, stat, &data[j]);
1372 	}
1373 	return j;
1374 }
1375 
1376 static void mv88e6xxx_atu_vtu_get_stats(struct mv88e6xxx_chip *chip, int port,
1377 					uint64_t *data)
1378 {
1379 	*data++ = chip->ports[port].atu_member_violation;
1380 	*data++ = chip->ports[port].atu_miss_violation;
1381 	*data++ = chip->ports[port].atu_full_violation;
1382 	*data++ = chip->ports[port].vtu_member_violation;
1383 	*data++ = chip->ports[port].vtu_miss_violation;
1384 }
1385 
1386 static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
1387 				uint64_t *data)
1388 {
1389 	size_t count;
1390 
1391 	count = mv88e6xxx_stats_get_stats(chip, port, data);
1392 
1393 	mv88e6xxx_reg_lock(chip);
1394 	if (chip->info->ops->serdes_get_stats) {
1395 		data += count;
1396 		count = chip->info->ops->serdes_get_stats(chip, port, data);
1397 	}
1398 	data += count;
1399 	mv88e6xxx_atu_vtu_get_stats(chip, port, data);
1400 	mv88e6xxx_reg_unlock(chip);
1401 }
1402 
1403 static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
1404 					uint64_t *data)
1405 {
1406 	struct mv88e6xxx_chip *chip = ds->priv;
1407 	int ret;
1408 
1409 	ret = mv88e6xxx_stats_snapshot(chip, port);
1410 	if (ret < 0)
1411 		return;
1412 
1413 	mv88e6xxx_get_stats(chip, port, data);
1414 }
1415 
1416 static void mv88e6xxx_get_eth_mac_stats(struct dsa_switch *ds, int port,
1417 					struct ethtool_eth_mac_stats *mac_stats)
1418 {
1419 	struct mv88e6xxx_chip *chip = ds->priv;
1420 	int ret;
1421 
1422 	ret = mv88e6xxx_stats_snapshot(chip, port);
1423 	if (ret < 0)
1424 		return;
1425 
1426 #define MV88E6XXX_ETH_MAC_STAT_MAP(_id, _member)			\
1427 	mv88e6xxx_stats_get_stat(chip, port,				\
1428 				 &mv88e6xxx_hw_stats[MV88E6XXX_HW_STAT_ID_ ## _id], \
1429 				 &mac_stats->stats._member)
1430 
1431 	MV88E6XXX_ETH_MAC_STAT_MAP(out_unicast, FramesTransmittedOK);
1432 	MV88E6XXX_ETH_MAC_STAT_MAP(single, SingleCollisionFrames);
1433 	MV88E6XXX_ETH_MAC_STAT_MAP(multiple, MultipleCollisionFrames);
1434 	MV88E6XXX_ETH_MAC_STAT_MAP(in_unicast, FramesReceivedOK);
1435 	MV88E6XXX_ETH_MAC_STAT_MAP(in_fcs_error, FrameCheckSequenceErrors);
1436 	MV88E6XXX_ETH_MAC_STAT_MAP(out_octets, OctetsTransmittedOK);
1437 	MV88E6XXX_ETH_MAC_STAT_MAP(deferred, FramesWithDeferredXmissions);
1438 	MV88E6XXX_ETH_MAC_STAT_MAP(late, LateCollisions);
1439 	MV88E6XXX_ETH_MAC_STAT_MAP(in_good_octets, OctetsReceivedOK);
1440 	MV88E6XXX_ETH_MAC_STAT_MAP(out_multicasts, MulticastFramesXmittedOK);
1441 	MV88E6XXX_ETH_MAC_STAT_MAP(out_broadcasts, BroadcastFramesXmittedOK);
1442 	MV88E6XXX_ETH_MAC_STAT_MAP(excessive, FramesWithExcessiveDeferral);
1443 	MV88E6XXX_ETH_MAC_STAT_MAP(in_multicasts, MulticastFramesReceivedOK);
1444 	MV88E6XXX_ETH_MAC_STAT_MAP(in_broadcasts, BroadcastFramesReceivedOK);
1445 
1446 #undef MV88E6XXX_ETH_MAC_STAT_MAP
1447 
1448 	mac_stats->stats.FramesTransmittedOK += mac_stats->stats.MulticastFramesXmittedOK;
1449 	mac_stats->stats.FramesTransmittedOK += mac_stats->stats.BroadcastFramesXmittedOK;
1450 	mac_stats->stats.FramesReceivedOK += mac_stats->stats.MulticastFramesReceivedOK;
1451 	mac_stats->stats.FramesReceivedOK += mac_stats->stats.BroadcastFramesReceivedOK;
1452 }
1453 
1454 static void mv88e6xxx_get_rmon_stats(struct dsa_switch *ds, int port,
1455 				     struct ethtool_rmon_stats *rmon_stats,
1456 				     const struct ethtool_rmon_hist_range **ranges)
1457 {
1458 	static const struct ethtool_rmon_hist_range rmon_ranges[] = {
1459 		{   64,    64 },
1460 		{   65,   127 },
1461 		{  128,   255 },
1462 		{  256,   511 },
1463 		{  512,  1023 },
1464 		{ 1024, 65535 },
1465 		{}
1466 	};
1467 	struct mv88e6xxx_chip *chip = ds->priv;
1468 	int ret;
1469 
1470 	ret = mv88e6xxx_stats_snapshot(chip, port);
1471 	if (ret < 0)
1472 		return;
1473 
1474 #define MV88E6XXX_RMON_STAT_MAP(_id, _member)				\
1475 	mv88e6xxx_stats_get_stat(chip, port,				\
1476 				 &mv88e6xxx_hw_stats[MV88E6XXX_HW_STAT_ID_ ## _id], \
1477 				 &rmon_stats->stats._member)
1478 
1479 	MV88E6XXX_RMON_STAT_MAP(in_undersize, undersize_pkts);
1480 	MV88E6XXX_RMON_STAT_MAP(in_oversize, oversize_pkts);
1481 	MV88E6XXX_RMON_STAT_MAP(in_fragments, fragments);
1482 	MV88E6XXX_RMON_STAT_MAP(in_jabber, jabbers);
1483 	MV88E6XXX_RMON_STAT_MAP(hist_64bytes, hist[0]);
1484 	MV88E6XXX_RMON_STAT_MAP(hist_65_127bytes, hist[1]);
1485 	MV88E6XXX_RMON_STAT_MAP(hist_128_255bytes, hist[2]);
1486 	MV88E6XXX_RMON_STAT_MAP(hist_256_511bytes, hist[3]);
1487 	MV88E6XXX_RMON_STAT_MAP(hist_512_1023bytes, hist[4]);
1488 	MV88E6XXX_RMON_STAT_MAP(hist_1024_max_bytes, hist[5]);
1489 
1490 #undef MV88E6XXX_RMON_STAT_MAP
1491 
1492 	*ranges = rmon_ranges;
1493 }
1494 
1495 static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
1496 {
1497 	struct mv88e6xxx_chip *chip = ds->priv;
1498 	int len;
1499 
1500 	len = 32 * sizeof(u16);
1501 	if (chip->info->ops->serdes_get_regs_len)
1502 		len += chip->info->ops->serdes_get_regs_len(chip, port);
1503 
1504 	return len;
1505 }
1506 
1507 static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1508 			       struct ethtool_regs *regs, void *_p)
1509 {
1510 	struct mv88e6xxx_chip *chip = ds->priv;
1511 	int err;
1512 	u16 reg;
1513 	u16 *p = _p;
1514 	int i;
1515 
1516 	regs->version = chip->info->prod_num;
1517 
1518 	memset(p, 0xff, 32 * sizeof(u16));
1519 
1520 	mv88e6xxx_reg_lock(chip);
1521 
1522 	for (i = 0; i < 32; i++) {
1523 
1524 		err = mv88e6xxx_port_read(chip, port, i, &reg);
1525 		if (!err)
1526 			p[i] = reg;
1527 	}
1528 
1529 	if (chip->info->ops->serdes_get_regs)
1530 		chip->info->ops->serdes_get_regs(chip, port, &p[i]);
1531 
1532 	mv88e6xxx_reg_unlock(chip);
1533 }
1534 
1535 static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
1536 				 struct ethtool_keee *e)
1537 {
1538 	/* Nothing to do on the port's MAC */
1539 	return 0;
1540 }
1541 
1542 static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
1543 				 struct ethtool_keee *e)
1544 {
1545 	/* Nothing to do on the port's MAC */
1546 	return 0;
1547 }
1548 
1549 /* Mask of the local ports allowed to receive frames from a given fabric port */
1550 static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
1551 {
1552 	struct dsa_switch *ds = chip->ds;
1553 	struct dsa_switch_tree *dst = ds->dst;
1554 	struct dsa_port *dp, *other_dp;
1555 	bool found = false;
1556 	u16 pvlan;
1557 
1558 	/* dev is a physical switch */
1559 	if (dev <= dst->last_switch) {
1560 		list_for_each_entry(dp, &dst->ports, list) {
1561 			if (dp->ds->index == dev && dp->index == port) {
1562 				/* dp might be a DSA link or a user port, so it
1563 				 * might or might not have a bridge.
1564 				 * Use the "found" variable for both cases.
1565 				 */
1566 				found = true;
1567 				break;
1568 			}
1569 		}
1570 	/* dev is a virtual bridge */
1571 	} else {
1572 		list_for_each_entry(dp, &dst->ports, list) {
1573 			unsigned int bridge_num = dsa_port_bridge_num_get(dp);
1574 
1575 			if (!bridge_num)
1576 				continue;
1577 
1578 			if (bridge_num + dst->last_switch != dev)
1579 				continue;
1580 
1581 			found = true;
1582 			break;
1583 		}
1584 	}
1585 
1586 	/* Prevent frames from unknown switch or virtual bridge */
1587 	if (!found)
1588 		return 0;
1589 
1590 	/* Frames from DSA links and CPU ports can egress any local port */
1591 	if (dp->type == DSA_PORT_TYPE_CPU || dp->type == DSA_PORT_TYPE_DSA)
1592 		return mv88e6xxx_port_mask(chip);
1593 
1594 	pvlan = 0;
1595 
1596 	/* Frames from standalone user ports can only egress on the
1597 	 * upstream port.
1598 	 */
1599 	if (!dsa_port_bridge_dev_get(dp))
1600 		return BIT(dsa_switch_upstream_port(ds));
1601 
1602 	/* Frames from bridged user ports can egress any local DSA
1603 	 * links and CPU ports, as well as any local member of their
1604 	 * bridge group.
1605 	 */
1606 	dsa_switch_for_each_port(other_dp, ds)
1607 		if (other_dp->type == DSA_PORT_TYPE_CPU ||
1608 		    other_dp->type == DSA_PORT_TYPE_DSA ||
1609 		    dsa_port_bridge_same(dp, other_dp))
1610 			pvlan |= BIT(other_dp->index);
1611 
1612 	return pvlan;
1613 }
1614 
1615 static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
1616 {
1617 	u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
1618 
1619 	/* prevent frames from going back out of the port they came in on */
1620 	output_ports &= ~BIT(port);
1621 
1622 	return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
1623 }
1624 
1625 static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1626 					 u8 state)
1627 {
1628 	struct mv88e6xxx_chip *chip = ds->priv;
1629 	int err;
1630 
1631 	mv88e6xxx_reg_lock(chip);
1632 	err = mv88e6xxx_port_set_state(chip, port, state);
1633 	mv88e6xxx_reg_unlock(chip);
1634 
1635 	if (err)
1636 		dev_err(ds->dev, "p%d: failed to update state\n", port);
1637 }
1638 
1639 static int mv88e6xxx_pri_setup(struct mv88e6xxx_chip *chip)
1640 {
1641 	int err;
1642 
1643 	if (chip->info->ops->ieee_pri_map) {
1644 		err = chip->info->ops->ieee_pri_map(chip);
1645 		if (err)
1646 			return err;
1647 	}
1648 
1649 	if (chip->info->ops->ip_pri_map) {
1650 		err = chip->info->ops->ip_pri_map(chip);
1651 		if (err)
1652 			return err;
1653 	}
1654 
1655 	return 0;
1656 }
1657 
1658 static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
1659 {
1660 	struct dsa_switch *ds = chip->ds;
1661 	int target, port;
1662 	int err;
1663 
1664 	if (!chip->info->global2_addr)
1665 		return 0;
1666 
1667 	/* Initialize the routing port to the 32 possible target devices */
1668 	for (target = 0; target < 32; target++) {
1669 		port = dsa_routing_port(ds, target);
1670 		if (port == ds->num_ports)
1671 			port = 0x1f;
1672 
1673 		err = mv88e6xxx_g2_device_mapping_write(chip, target, port);
1674 		if (err)
1675 			return err;
1676 	}
1677 
1678 	if (chip->info->ops->set_cascade_port) {
1679 		port = MV88E6XXX_CASCADE_PORT_MULTIPLE;
1680 		err = chip->info->ops->set_cascade_port(chip, port);
1681 		if (err)
1682 			return err;
1683 	}
1684 
1685 	err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
1686 	if (err)
1687 		return err;
1688 
1689 	return 0;
1690 }
1691 
1692 static int mv88e6xxx_trunk_setup(struct mv88e6xxx_chip *chip)
1693 {
1694 	/* Clear all trunk masks and mapping */
1695 	if (chip->info->global2_addr)
1696 		return mv88e6xxx_g2_trunk_clear(chip);
1697 
1698 	return 0;
1699 }
1700 
1701 static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
1702 {
1703 	if (chip->info->ops->rmu_disable)
1704 		return chip->info->ops->rmu_disable(chip);
1705 
1706 	return 0;
1707 }
1708 
1709 static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
1710 {
1711 	if (chip->info->ops->pot_clear)
1712 		return chip->info->ops->pot_clear(chip);
1713 
1714 	return 0;
1715 }
1716 
1717 static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
1718 {
1719 	if (chip->info->ops->mgmt_rsvd2cpu)
1720 		return chip->info->ops->mgmt_rsvd2cpu(chip);
1721 
1722 	return 0;
1723 }
1724 
1725 static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1726 {
1727 	int err;
1728 
1729 	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1730 	if (err)
1731 		return err;
1732 
1733 	/* The chips that have a "learn2all" bit in Global1, ATU
1734 	 * Control are precisely those whose port registers have a
1735 	 * Message Port bit in Port Control 1 and hence implement
1736 	 * ->port_setup_message_port.
1737 	 */
1738 	if (chip->info->ops->port_setup_message_port) {
1739 		err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1740 		if (err)
1741 			return err;
1742 	}
1743 
1744 	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1745 }
1746 
1747 static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
1748 {
1749 	int port;
1750 	int err;
1751 
1752 	if (!chip->info->ops->irl_init_all)
1753 		return 0;
1754 
1755 	for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1756 		/* Disable ingress rate limiting by resetting all per port
1757 		 * ingress rate limit resources to their initial state.
1758 		 */
1759 		err = chip->info->ops->irl_init_all(chip, port);
1760 		if (err)
1761 			return err;
1762 	}
1763 
1764 	return 0;
1765 }
1766 
1767 static int mv88e6xxx_mac_setup(struct mv88e6xxx_chip *chip)
1768 {
1769 	if (chip->info->ops->set_switch_mac) {
1770 		u8 addr[ETH_ALEN];
1771 
1772 		eth_random_addr(addr);
1773 
1774 		return chip->info->ops->set_switch_mac(chip, addr);
1775 	}
1776 
1777 	return 0;
1778 }
1779 
1780 static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1781 {
1782 	struct dsa_switch_tree *dst = chip->ds->dst;
1783 	struct dsa_switch *ds;
1784 	struct dsa_port *dp;
1785 	u16 pvlan = 0;
1786 
1787 	if (!mv88e6xxx_has_pvt(chip))
1788 		return 0;
1789 
1790 	/* Skip the local source device, which uses in-chip port VLAN */
1791 	if (dev != chip->ds->index) {
1792 		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1793 
1794 		ds = dsa_switch_find(dst->index, dev);
1795 		dp = ds ? dsa_to_port(ds, port) : NULL;
1796 		if (dp && dp->lag) {
1797 			/* As the PVT is used to limit flooding of
1798 			 * FORWARD frames, which use the LAG ID as the
1799 			 * source port, we must translate dev/port to
1800 			 * the special "LAG device" in the PVT, using
1801 			 * the LAG ID (one-based) as the port number
1802 			 * (zero-based).
1803 			 */
1804 			dev = MV88E6XXX_G2_PVT_ADDR_DEV_TRUNK;
1805 			port = dsa_port_lag_id_get(dp) - 1;
1806 		}
1807 	}
1808 
1809 	return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1810 }
1811 
1812 static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1813 {
1814 	int dev, port;
1815 	int err;
1816 
1817 	if (!mv88e6xxx_has_pvt(chip))
1818 		return 0;
1819 
1820 	/* Clear 5 Bit Port for usage with Marvell Link Street devices:
1821 	 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1822 	 */
1823 	err = mv88e6xxx_g2_misc_4_bit_port(chip);
1824 	if (err)
1825 		return err;
1826 
1827 	for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1828 		for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1829 			err = mv88e6xxx_pvt_map(chip, dev, port);
1830 			if (err)
1831 				return err;
1832 		}
1833 	}
1834 
1835 	return 0;
1836 }
1837 
1838 static int mv88e6xxx_port_fast_age_fid(struct mv88e6xxx_chip *chip, int port,
1839 				       u16 fid)
1840 {
1841 	if (dsa_to_port(chip->ds, port)->lag)
1842 		/* Hardware is incapable of fast-aging a LAG through a
1843 		 * regular ATU move operation. Until we have something
1844 		 * more fancy in place this is a no-op.
1845 		 */
1846 		return -EOPNOTSUPP;
1847 
1848 	return mv88e6xxx_g1_atu_remove(chip, fid, port, false);
1849 }
1850 
1851 static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1852 {
1853 	struct mv88e6xxx_chip *chip = ds->priv;
1854 	int err;
1855 
1856 	mv88e6xxx_reg_lock(chip);
1857 	err = mv88e6xxx_port_fast_age_fid(chip, port, 0);
1858 	mv88e6xxx_reg_unlock(chip);
1859 
1860 	if (err)
1861 		dev_err(chip->ds->dev, "p%d: failed to flush ATU: %d\n",
1862 			port, err);
1863 }
1864 
1865 static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1866 {
1867 	if (!mv88e6xxx_max_vid(chip))
1868 		return 0;
1869 
1870 	return mv88e6xxx_g1_vtu_flush(chip);
1871 }
1872 
1873 static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
1874 			     struct mv88e6xxx_vtu_entry *entry)
1875 {
1876 	int err;
1877 
1878 	if (!chip->info->ops->vtu_getnext)
1879 		return -EOPNOTSUPP;
1880 
1881 	entry->vid = vid ? vid - 1 : mv88e6xxx_max_vid(chip);
1882 	entry->valid = false;
1883 
1884 	err = chip->info->ops->vtu_getnext(chip, entry);
1885 
1886 	if (entry->vid != vid)
1887 		entry->valid = false;
1888 
1889 	return err;
1890 }
1891 
1892 int mv88e6xxx_vtu_walk(struct mv88e6xxx_chip *chip,
1893 		       int (*cb)(struct mv88e6xxx_chip *chip,
1894 				 const struct mv88e6xxx_vtu_entry *entry,
1895 				 void *priv),
1896 		       void *priv)
1897 {
1898 	struct mv88e6xxx_vtu_entry entry = {
1899 		.vid = mv88e6xxx_max_vid(chip),
1900 		.valid = false,
1901 	};
1902 	int err;
1903 
1904 	if (!chip->info->ops->vtu_getnext)
1905 		return -EOPNOTSUPP;
1906 
1907 	do {
1908 		err = chip->info->ops->vtu_getnext(chip, &entry);
1909 		if (err)
1910 			return err;
1911 
1912 		if (!entry.valid)
1913 			break;
1914 
1915 		err = cb(chip, &entry, priv);
1916 		if (err)
1917 			return err;
1918 	} while (entry.vid < mv88e6xxx_max_vid(chip));
1919 
1920 	return 0;
1921 }
1922 
1923 static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1924 				   struct mv88e6xxx_vtu_entry *entry)
1925 {
1926 	if (!chip->info->ops->vtu_loadpurge)
1927 		return -EOPNOTSUPP;
1928 
1929 	return chip->info->ops->vtu_loadpurge(chip, entry);
1930 }
1931 
1932 static int mv88e6xxx_fid_map_vlan(struct mv88e6xxx_chip *chip,
1933 				  const struct mv88e6xxx_vtu_entry *entry,
1934 				  void *_fid_bitmap)
1935 {
1936 	unsigned long *fid_bitmap = _fid_bitmap;
1937 
1938 	set_bit(entry->fid, fid_bitmap);
1939 	return 0;
1940 }
1941 
1942 int mv88e6xxx_fid_map(struct mv88e6xxx_chip *chip, unsigned long *fid_bitmap)
1943 {
1944 	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1945 
1946 	/* Every FID has an associated VID, so walking the VTU
1947 	 * will discover the full set of FIDs in use.
1948 	 */
1949 	return mv88e6xxx_vtu_walk(chip, mv88e6xxx_fid_map_vlan, fid_bitmap);
1950 }
1951 
1952 static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1953 {
1954 	DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1955 	int err;
1956 
1957 	err = mv88e6xxx_fid_map(chip, fid_bitmap);
1958 	if (err)
1959 		return err;
1960 
1961 	*fid = find_first_zero_bit(fid_bitmap, MV88E6XXX_N_FID);
1962 	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1963 		return -ENOSPC;
1964 
1965 	/* Clear the database */
1966 	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1967 }
1968 
1969 static int mv88e6xxx_stu_loadpurge(struct mv88e6xxx_chip *chip,
1970 				   struct mv88e6xxx_stu_entry *entry)
1971 {
1972 	if (!chip->info->ops->stu_loadpurge)
1973 		return -EOPNOTSUPP;
1974 
1975 	return chip->info->ops->stu_loadpurge(chip, entry);
1976 }
1977 
1978 static int mv88e6xxx_stu_setup(struct mv88e6xxx_chip *chip)
1979 {
1980 	struct mv88e6xxx_stu_entry stu = {
1981 		.valid = true,
1982 		.sid = 0
1983 	};
1984 
1985 	if (!mv88e6xxx_has_stu(chip))
1986 		return 0;
1987 
1988 	/* Make sure that SID 0 is always valid. This is used by VTU
1989 	 * entries that do not make use of the STU, e.g. when creating
1990 	 * a VLAN upper on a port that is also part of a VLAN
1991 	 * filtering bridge.
1992 	 */
1993 	return mv88e6xxx_stu_loadpurge(chip, &stu);
1994 }
1995 
1996 static int mv88e6xxx_sid_get(struct mv88e6xxx_chip *chip, u8 *sid)
1997 {
1998 	DECLARE_BITMAP(busy, MV88E6XXX_N_SID) = { 0 };
1999 	struct mv88e6xxx_mst *mst;
2000 
2001 	__set_bit(0, busy);
2002 
2003 	list_for_each_entry(mst, &chip->msts, node)
2004 		__set_bit(mst->stu.sid, busy);
2005 
2006 	*sid = find_first_zero_bit(busy, MV88E6XXX_N_SID);
2007 
2008 	return (*sid >= mv88e6xxx_max_sid(chip)) ? -ENOSPC : 0;
2009 }
2010 
2011 static int mv88e6xxx_mst_put(struct mv88e6xxx_chip *chip, u8 sid)
2012 {
2013 	struct mv88e6xxx_mst *mst, *tmp;
2014 	int err;
2015 
2016 	if (!sid)
2017 		return 0;
2018 
2019 	list_for_each_entry_safe(mst, tmp, &chip->msts, node) {
2020 		if (mst->stu.sid != sid)
2021 			continue;
2022 
2023 		if (!refcount_dec_and_test(&mst->refcnt))
2024 			return 0;
2025 
2026 		mst->stu.valid = false;
2027 		err = mv88e6xxx_stu_loadpurge(chip, &mst->stu);
2028 		if (err) {
2029 			refcount_set(&mst->refcnt, 1);
2030 			return err;
2031 		}
2032 
2033 		list_del(&mst->node);
2034 		kfree(mst);
2035 		return 0;
2036 	}
2037 
2038 	return -ENOENT;
2039 }
2040 
2041 static int mv88e6xxx_mst_get(struct mv88e6xxx_chip *chip, struct net_device *br,
2042 			     u16 msti, u8 *sid)
2043 {
2044 	struct mv88e6xxx_mst *mst;
2045 	int err, i;
2046 
2047 	if (!mv88e6xxx_has_stu(chip)) {
2048 		err = -EOPNOTSUPP;
2049 		goto err;
2050 	}
2051 
2052 	if (!msti) {
2053 		*sid = 0;
2054 		return 0;
2055 	}
2056 
2057 	list_for_each_entry(mst, &chip->msts, node) {
2058 		if (mst->br == br && mst->msti == msti) {
2059 			refcount_inc(&mst->refcnt);
2060 			*sid = mst->stu.sid;
2061 			return 0;
2062 		}
2063 	}
2064 
2065 	err = mv88e6xxx_sid_get(chip, sid);
2066 	if (err)
2067 		goto err;
2068 
2069 	mst = kzalloc(sizeof(*mst), GFP_KERNEL);
2070 	if (!mst) {
2071 		err = -ENOMEM;
2072 		goto err;
2073 	}
2074 
2075 	INIT_LIST_HEAD(&mst->node);
2076 	refcount_set(&mst->refcnt, 1);
2077 	mst->br = br;
2078 	mst->msti = msti;
2079 	mst->stu.valid = true;
2080 	mst->stu.sid = *sid;
2081 
2082 	/* The bridge starts out all ports in the disabled state. But
2083 	 * a STU state of disabled means to go by the port-global
2084 	 * state. So we set all user port's initial state to blocking,
2085 	 * to match the bridge's behavior.
2086 	 */
2087 	for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
2088 		mst->stu.state[i] = dsa_is_user_port(chip->ds, i) ?
2089 			MV88E6XXX_PORT_CTL0_STATE_BLOCKING :
2090 			MV88E6XXX_PORT_CTL0_STATE_DISABLED;
2091 
2092 	err = mv88e6xxx_stu_loadpurge(chip, &mst->stu);
2093 	if (err)
2094 		goto err_free;
2095 
2096 	list_add_tail(&mst->node, &chip->msts);
2097 	return 0;
2098 
2099 err_free:
2100 	kfree(mst);
2101 err:
2102 	return err;
2103 }
2104 
2105 static int mv88e6xxx_port_mst_state_set(struct dsa_switch *ds, int port,
2106 					const struct switchdev_mst_state *st)
2107 {
2108 	struct dsa_port *dp = dsa_to_port(ds, port);
2109 	struct mv88e6xxx_chip *chip = ds->priv;
2110 	struct mv88e6xxx_mst *mst;
2111 	u8 state;
2112 	int err;
2113 
2114 	if (!mv88e6xxx_has_stu(chip))
2115 		return -EOPNOTSUPP;
2116 
2117 	switch (st->state) {
2118 	case BR_STATE_DISABLED:
2119 	case BR_STATE_BLOCKING:
2120 	case BR_STATE_LISTENING:
2121 		state = MV88E6XXX_PORT_CTL0_STATE_BLOCKING;
2122 		break;
2123 	case BR_STATE_LEARNING:
2124 		state = MV88E6XXX_PORT_CTL0_STATE_LEARNING;
2125 		break;
2126 	case BR_STATE_FORWARDING:
2127 		state = MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
2128 		break;
2129 	default:
2130 		return -EINVAL;
2131 	}
2132 
2133 	list_for_each_entry(mst, &chip->msts, node) {
2134 		if (mst->br == dsa_port_bridge_dev_get(dp) &&
2135 		    mst->msti == st->msti) {
2136 			if (mst->stu.state[port] == state)
2137 				return 0;
2138 
2139 			mst->stu.state[port] = state;
2140 			mv88e6xxx_reg_lock(chip);
2141 			err = mv88e6xxx_stu_loadpurge(chip, &mst->stu);
2142 			mv88e6xxx_reg_unlock(chip);
2143 			return err;
2144 		}
2145 	}
2146 
2147 	return -ENOENT;
2148 }
2149 
2150 static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
2151 					u16 vid)
2152 {
2153 	struct dsa_port *dp = dsa_to_port(ds, port), *other_dp;
2154 	struct mv88e6xxx_chip *chip = ds->priv;
2155 	struct mv88e6xxx_vtu_entry vlan;
2156 	int err;
2157 
2158 	/* DSA and CPU ports have to be members of multiple vlans */
2159 	if (dsa_port_is_dsa(dp) || dsa_port_is_cpu(dp))
2160 		return 0;
2161 
2162 	err = mv88e6xxx_vtu_get(chip, vid, &vlan);
2163 	if (err)
2164 		return err;
2165 
2166 	if (!vlan.valid)
2167 		return 0;
2168 
2169 	dsa_switch_for_each_user_port(other_dp, ds) {
2170 		struct net_device *other_br;
2171 
2172 		if (vlan.member[other_dp->index] ==
2173 		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
2174 			continue;
2175 
2176 		if (dsa_port_bridge_same(dp, other_dp))
2177 			break; /* same bridge, check next VLAN */
2178 
2179 		other_br = dsa_port_bridge_dev_get(other_dp);
2180 		if (!other_br)
2181 			continue;
2182 
2183 		dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
2184 			port, vlan.vid, other_dp->index, netdev_name(other_br));
2185 		return -EOPNOTSUPP;
2186 	}
2187 
2188 	return 0;
2189 }
2190 
2191 static int mv88e6xxx_port_commit_pvid(struct mv88e6xxx_chip *chip, int port)
2192 {
2193 	struct dsa_port *dp = dsa_to_port(chip->ds, port);
2194 	struct net_device *br = dsa_port_bridge_dev_get(dp);
2195 	struct mv88e6xxx_port *p = &chip->ports[port];
2196 	u16 pvid = MV88E6XXX_VID_STANDALONE;
2197 	bool drop_untagged = false;
2198 	int err;
2199 
2200 	if (br) {
2201 		if (br_vlan_enabled(br)) {
2202 			pvid = p->bridge_pvid.vid;
2203 			drop_untagged = !p->bridge_pvid.valid;
2204 		} else {
2205 			pvid = MV88E6XXX_VID_BRIDGED;
2206 		}
2207 	}
2208 
2209 	err = mv88e6xxx_port_set_pvid(chip, port, pvid);
2210 	if (err)
2211 		return err;
2212 
2213 	return mv88e6xxx_port_drop_untagged(chip, port, drop_untagged);
2214 }
2215 
2216 static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
2217 					 bool vlan_filtering,
2218 					 struct netlink_ext_ack *extack)
2219 {
2220 	struct mv88e6xxx_chip *chip = ds->priv;
2221 	u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
2222 		MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
2223 	int err;
2224 
2225 	if (!mv88e6xxx_max_vid(chip))
2226 		return -EOPNOTSUPP;
2227 
2228 	mv88e6xxx_reg_lock(chip);
2229 
2230 	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
2231 	if (err)
2232 		goto unlock;
2233 
2234 	err = mv88e6xxx_port_commit_pvid(chip, port);
2235 	if (err)
2236 		goto unlock;
2237 
2238 unlock:
2239 	mv88e6xxx_reg_unlock(chip);
2240 
2241 	return err;
2242 }
2243 
2244 static int
2245 mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
2246 			    const struct switchdev_obj_port_vlan *vlan)
2247 {
2248 	struct mv88e6xxx_chip *chip = ds->priv;
2249 	int err;
2250 
2251 	if (!mv88e6xxx_max_vid(chip))
2252 		return -EOPNOTSUPP;
2253 
2254 	/* If the requested port doesn't belong to the same bridge as the VLAN
2255 	 * members, do not support it (yet) and fallback to software VLAN.
2256 	 */
2257 	mv88e6xxx_reg_lock(chip);
2258 	err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid);
2259 	mv88e6xxx_reg_unlock(chip);
2260 
2261 	return err;
2262 }
2263 
2264 static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
2265 					const unsigned char *addr, u16 vid,
2266 					u8 state)
2267 {
2268 	struct mv88e6xxx_atu_entry entry;
2269 	struct mv88e6xxx_vtu_entry vlan;
2270 	u16 fid;
2271 	int err;
2272 
2273 	/* Ports have two private address databases: one for when the port is
2274 	 * standalone and one for when the port is under a bridge and the
2275 	 * 802.1Q mode is disabled. When the port is standalone, DSA wants its
2276 	 * address database to remain 100% empty, so we never load an ATU entry
2277 	 * into a standalone port's database. Therefore, translate the null
2278 	 * VLAN ID into the port's database used for VLAN-unaware bridging.
2279 	 */
2280 	if (vid == 0) {
2281 		fid = MV88E6XXX_FID_BRIDGED;
2282 	} else {
2283 		err = mv88e6xxx_vtu_get(chip, vid, &vlan);
2284 		if (err)
2285 			return err;
2286 
2287 		/* switchdev expects -EOPNOTSUPP to honor software VLANs */
2288 		if (!vlan.valid)
2289 			return -EOPNOTSUPP;
2290 
2291 		fid = vlan.fid;
2292 	}
2293 
2294 	entry.state = 0;
2295 	ether_addr_copy(entry.mac, addr);
2296 	eth_addr_dec(entry.mac);
2297 
2298 	err = mv88e6xxx_g1_atu_getnext(chip, fid, &entry);
2299 	if (err)
2300 		return err;
2301 
2302 	/* Initialize a fresh ATU entry if it isn't found */
2303 	if (!entry.state || !ether_addr_equal(entry.mac, addr)) {
2304 		memset(&entry, 0, sizeof(entry));
2305 		ether_addr_copy(entry.mac, addr);
2306 	}
2307 
2308 	/* Purge the ATU entry only if no port is using it anymore */
2309 	if (!state) {
2310 		entry.portvec &= ~BIT(port);
2311 		if (!entry.portvec)
2312 			entry.state = 0;
2313 	} else {
2314 		if (state == MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC)
2315 			entry.portvec = BIT(port);
2316 		else
2317 			entry.portvec |= BIT(port);
2318 
2319 		entry.state = state;
2320 	}
2321 
2322 	return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry);
2323 }
2324 
2325 static int mv88e6xxx_policy_apply(struct mv88e6xxx_chip *chip, int port,
2326 				  const struct mv88e6xxx_policy *policy)
2327 {
2328 	enum mv88e6xxx_policy_mapping mapping = policy->mapping;
2329 	enum mv88e6xxx_policy_action action = policy->action;
2330 	const u8 *addr = policy->addr;
2331 	u16 vid = policy->vid;
2332 	u8 state;
2333 	int err;
2334 	int id;
2335 
2336 	if (!chip->info->ops->port_set_policy)
2337 		return -EOPNOTSUPP;
2338 
2339 	switch (mapping) {
2340 	case MV88E6XXX_POLICY_MAPPING_DA:
2341 	case MV88E6XXX_POLICY_MAPPING_SA:
2342 		if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
2343 			state = 0; /* Dissociate the port and address */
2344 		else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
2345 			 is_multicast_ether_addr(addr))
2346 			state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC_POLICY;
2347 		else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
2348 			 is_unicast_ether_addr(addr))
2349 			state = MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC_POLICY;
2350 		else
2351 			return -EOPNOTSUPP;
2352 
2353 		err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
2354 						   state);
2355 		if (err)
2356 			return err;
2357 		break;
2358 	default:
2359 		return -EOPNOTSUPP;
2360 	}
2361 
2362 	/* Skip the port's policy clearing if the mapping is still in use */
2363 	if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
2364 		idr_for_each_entry(&chip->policies, policy, id)
2365 			if (policy->port == port &&
2366 			    policy->mapping == mapping &&
2367 			    policy->action != action)
2368 				return 0;
2369 
2370 	return chip->info->ops->port_set_policy(chip, port, mapping, action);
2371 }
2372 
2373 static int mv88e6xxx_policy_insert(struct mv88e6xxx_chip *chip, int port,
2374 				   struct ethtool_rx_flow_spec *fs)
2375 {
2376 	struct ethhdr *mac_entry = &fs->h_u.ether_spec;
2377 	struct ethhdr *mac_mask = &fs->m_u.ether_spec;
2378 	enum mv88e6xxx_policy_mapping mapping;
2379 	enum mv88e6xxx_policy_action action;
2380 	struct mv88e6xxx_policy *policy;
2381 	u16 vid = 0;
2382 	u8 *addr;
2383 	int err;
2384 	int id;
2385 
2386 	if (fs->location != RX_CLS_LOC_ANY)
2387 		return -EINVAL;
2388 
2389 	if (fs->ring_cookie == RX_CLS_FLOW_DISC)
2390 		action = MV88E6XXX_POLICY_ACTION_DISCARD;
2391 	else
2392 		return -EOPNOTSUPP;
2393 
2394 	switch (fs->flow_type & ~FLOW_EXT) {
2395 	case ETHER_FLOW:
2396 		if (!is_zero_ether_addr(mac_mask->h_dest) &&
2397 		    is_zero_ether_addr(mac_mask->h_source)) {
2398 			mapping = MV88E6XXX_POLICY_MAPPING_DA;
2399 			addr = mac_entry->h_dest;
2400 		} else if (is_zero_ether_addr(mac_mask->h_dest) &&
2401 		    !is_zero_ether_addr(mac_mask->h_source)) {
2402 			mapping = MV88E6XXX_POLICY_MAPPING_SA;
2403 			addr = mac_entry->h_source;
2404 		} else {
2405 			/* Cannot support DA and SA mapping in the same rule */
2406 			return -EOPNOTSUPP;
2407 		}
2408 		break;
2409 	default:
2410 		return -EOPNOTSUPP;
2411 	}
2412 
2413 	if ((fs->flow_type & FLOW_EXT) && fs->m_ext.vlan_tci) {
2414 		if (fs->m_ext.vlan_tci != htons(0xffff))
2415 			return -EOPNOTSUPP;
2416 		vid = be16_to_cpu(fs->h_ext.vlan_tci) & VLAN_VID_MASK;
2417 	}
2418 
2419 	idr_for_each_entry(&chip->policies, policy, id) {
2420 		if (policy->port == port && policy->mapping == mapping &&
2421 		    policy->action == action && policy->vid == vid &&
2422 		    ether_addr_equal(policy->addr, addr))
2423 			return -EEXIST;
2424 	}
2425 
2426 	policy = devm_kzalloc(chip->dev, sizeof(*policy), GFP_KERNEL);
2427 	if (!policy)
2428 		return -ENOMEM;
2429 
2430 	fs->location = 0;
2431 	err = idr_alloc_u32(&chip->policies, policy, &fs->location, 0xffffffff,
2432 			    GFP_KERNEL);
2433 	if (err) {
2434 		devm_kfree(chip->dev, policy);
2435 		return err;
2436 	}
2437 
2438 	memcpy(&policy->fs, fs, sizeof(*fs));
2439 	ether_addr_copy(policy->addr, addr);
2440 	policy->mapping = mapping;
2441 	policy->action = action;
2442 	policy->port = port;
2443 	policy->vid = vid;
2444 
2445 	err = mv88e6xxx_policy_apply(chip, port, policy);
2446 	if (err) {
2447 		idr_remove(&chip->policies, fs->location);
2448 		devm_kfree(chip->dev, policy);
2449 		return err;
2450 	}
2451 
2452 	return 0;
2453 }
2454 
2455 static int mv88e6xxx_get_rxnfc(struct dsa_switch *ds, int port,
2456 			       struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
2457 {
2458 	struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
2459 	struct mv88e6xxx_chip *chip = ds->priv;
2460 	struct mv88e6xxx_policy *policy;
2461 	int err;
2462 	int id;
2463 
2464 	mv88e6xxx_reg_lock(chip);
2465 
2466 	switch (rxnfc->cmd) {
2467 	case ETHTOOL_GRXCLSRLCNT:
2468 		rxnfc->data = 0;
2469 		rxnfc->data |= RX_CLS_LOC_SPECIAL;
2470 		rxnfc->rule_cnt = 0;
2471 		idr_for_each_entry(&chip->policies, policy, id)
2472 			if (policy->port == port)
2473 				rxnfc->rule_cnt++;
2474 		err = 0;
2475 		break;
2476 	case ETHTOOL_GRXCLSRULE:
2477 		err = -ENOENT;
2478 		policy = idr_find(&chip->policies, fs->location);
2479 		if (policy) {
2480 			memcpy(fs, &policy->fs, sizeof(*fs));
2481 			err = 0;
2482 		}
2483 		break;
2484 	case ETHTOOL_GRXCLSRLALL:
2485 		rxnfc->data = 0;
2486 		rxnfc->rule_cnt = 0;
2487 		idr_for_each_entry(&chip->policies, policy, id)
2488 			if (policy->port == port)
2489 				rule_locs[rxnfc->rule_cnt++] = id;
2490 		err = 0;
2491 		break;
2492 	default:
2493 		err = -EOPNOTSUPP;
2494 		break;
2495 	}
2496 
2497 	mv88e6xxx_reg_unlock(chip);
2498 
2499 	return err;
2500 }
2501 
2502 static int mv88e6xxx_set_rxnfc(struct dsa_switch *ds, int port,
2503 			       struct ethtool_rxnfc *rxnfc)
2504 {
2505 	struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
2506 	struct mv88e6xxx_chip *chip = ds->priv;
2507 	struct mv88e6xxx_policy *policy;
2508 	int err;
2509 
2510 	mv88e6xxx_reg_lock(chip);
2511 
2512 	switch (rxnfc->cmd) {
2513 	case ETHTOOL_SRXCLSRLINS:
2514 		err = mv88e6xxx_policy_insert(chip, port, fs);
2515 		break;
2516 	case ETHTOOL_SRXCLSRLDEL:
2517 		err = -ENOENT;
2518 		policy = idr_remove(&chip->policies, fs->location);
2519 		if (policy) {
2520 			policy->action = MV88E6XXX_POLICY_ACTION_NORMAL;
2521 			err = mv88e6xxx_policy_apply(chip, port, policy);
2522 			devm_kfree(chip->dev, policy);
2523 		}
2524 		break;
2525 	default:
2526 		err = -EOPNOTSUPP;
2527 		break;
2528 	}
2529 
2530 	mv88e6xxx_reg_unlock(chip);
2531 
2532 	return err;
2533 }
2534 
2535 static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
2536 					u16 vid)
2537 {
2538 	u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
2539 	u8 broadcast[ETH_ALEN];
2540 
2541 	eth_broadcast_addr(broadcast);
2542 
2543 	return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state);
2544 }
2545 
2546 static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid)
2547 {
2548 	int port;
2549 	int err;
2550 
2551 	for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
2552 		struct dsa_port *dp = dsa_to_port(chip->ds, port);
2553 		struct net_device *brport;
2554 
2555 		if (dsa_is_unused_port(chip->ds, port))
2556 			continue;
2557 
2558 		brport = dsa_port_to_bridge_port(dp);
2559 		if (brport && !br_port_flag_is_set(brport, BR_BCAST_FLOOD))
2560 			/* Skip bridged user ports where broadcast
2561 			 * flooding is disabled.
2562 			 */
2563 			continue;
2564 
2565 		err = mv88e6xxx_port_add_broadcast(chip, port, vid);
2566 		if (err)
2567 			return err;
2568 	}
2569 
2570 	return 0;
2571 }
2572 
2573 struct mv88e6xxx_port_broadcast_sync_ctx {
2574 	int port;
2575 	bool flood;
2576 };
2577 
2578 static int
2579 mv88e6xxx_port_broadcast_sync_vlan(struct mv88e6xxx_chip *chip,
2580 				   const struct mv88e6xxx_vtu_entry *vlan,
2581 				   void *_ctx)
2582 {
2583 	struct mv88e6xxx_port_broadcast_sync_ctx *ctx = _ctx;
2584 	u8 broadcast[ETH_ALEN];
2585 	u8 state;
2586 
2587 	if (ctx->flood)
2588 		state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
2589 	else
2590 		state = MV88E6XXX_G1_ATU_DATA_STATE_MC_UNUSED;
2591 
2592 	eth_broadcast_addr(broadcast);
2593 
2594 	return mv88e6xxx_port_db_load_purge(chip, ctx->port, broadcast,
2595 					    vlan->vid, state);
2596 }
2597 
2598 static int mv88e6xxx_port_broadcast_sync(struct mv88e6xxx_chip *chip, int port,
2599 					 bool flood)
2600 {
2601 	struct mv88e6xxx_port_broadcast_sync_ctx ctx = {
2602 		.port = port,
2603 		.flood = flood,
2604 	};
2605 	struct mv88e6xxx_vtu_entry vid0 = {
2606 		.vid = 0,
2607 	};
2608 	int err;
2609 
2610 	/* Update the port's private database... */
2611 	err = mv88e6xxx_port_broadcast_sync_vlan(chip, &vid0, &ctx);
2612 	if (err)
2613 		return err;
2614 
2615 	/* ...and the database for all VLANs. */
2616 	return mv88e6xxx_vtu_walk(chip, mv88e6xxx_port_broadcast_sync_vlan,
2617 				  &ctx);
2618 }
2619 
2620 static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port,
2621 				    u16 vid, u8 member, bool warn)
2622 {
2623 	const u8 non_member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
2624 	struct mv88e6xxx_vtu_entry vlan;
2625 	int i, err;
2626 
2627 	err = mv88e6xxx_vtu_get(chip, vid, &vlan);
2628 	if (err)
2629 		return err;
2630 
2631 	if (!vlan.valid) {
2632 		memset(&vlan, 0, sizeof(vlan));
2633 
2634 		if (vid == MV88E6XXX_VID_STANDALONE)
2635 			vlan.policy = true;
2636 
2637 		err = mv88e6xxx_atu_new(chip, &vlan.fid);
2638 		if (err)
2639 			return err;
2640 
2641 		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
2642 			if (i == port)
2643 				vlan.member[i] = member;
2644 			else
2645 				vlan.member[i] = non_member;
2646 
2647 		vlan.vid = vid;
2648 		vlan.valid = true;
2649 
2650 		err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
2651 		if (err)
2652 			return err;
2653 
2654 		err = mv88e6xxx_broadcast_setup(chip, vlan.vid);
2655 		if (err)
2656 			return err;
2657 	} else if (vlan.member[port] != member) {
2658 		vlan.member[port] = member;
2659 
2660 		err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
2661 		if (err)
2662 			return err;
2663 	} else if (warn) {
2664 		dev_info(chip->dev, "p%d: already a member of VLAN %d\n",
2665 			 port, vid);
2666 	}
2667 
2668 	return 0;
2669 }
2670 
2671 static int mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
2672 				   const struct switchdev_obj_port_vlan *vlan,
2673 				   struct netlink_ext_ack *extack)
2674 {
2675 	struct mv88e6xxx_chip *chip = ds->priv;
2676 	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
2677 	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
2678 	struct mv88e6xxx_port *p = &chip->ports[port];
2679 	bool warn;
2680 	u8 member;
2681 	int err;
2682 
2683 	if (!vlan->vid)
2684 		return 0;
2685 
2686 	err = mv88e6xxx_port_vlan_prepare(ds, port, vlan);
2687 	if (err)
2688 		return err;
2689 
2690 	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
2691 		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
2692 	else if (untagged)
2693 		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
2694 	else
2695 		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
2696 
2697 	/* net/dsa/user.c will call dsa_port_vlan_add() for the affected port
2698 	 * and then the CPU port. Do not warn for duplicates for the CPU port.
2699 	 */
2700 	warn = !dsa_is_cpu_port(ds, port) && !dsa_is_dsa_port(ds, port);
2701 
2702 	mv88e6xxx_reg_lock(chip);
2703 
2704 	err = mv88e6xxx_port_vlan_join(chip, port, vlan->vid, member, warn);
2705 	if (err) {
2706 		dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
2707 			vlan->vid, untagged ? 'u' : 't');
2708 		goto out;
2709 	}
2710 
2711 	if (pvid) {
2712 		p->bridge_pvid.vid = vlan->vid;
2713 		p->bridge_pvid.valid = true;
2714 
2715 		err = mv88e6xxx_port_commit_pvid(chip, port);
2716 		if (err)
2717 			goto out;
2718 	} else if (vlan->vid && p->bridge_pvid.vid == vlan->vid) {
2719 		/* The old pvid was reinstalled as a non-pvid VLAN */
2720 		p->bridge_pvid.valid = false;
2721 
2722 		err = mv88e6xxx_port_commit_pvid(chip, port);
2723 		if (err)
2724 			goto out;
2725 	}
2726 
2727 out:
2728 	mv88e6xxx_reg_unlock(chip);
2729 
2730 	return err;
2731 }
2732 
2733 static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,
2734 				     int port, u16 vid)
2735 {
2736 	struct mv88e6xxx_vtu_entry vlan;
2737 	int i, err;
2738 
2739 	if (!vid)
2740 		return 0;
2741 
2742 	err = mv88e6xxx_vtu_get(chip, vid, &vlan);
2743 	if (err)
2744 		return err;
2745 
2746 	/* If the VLAN doesn't exist in hardware or the port isn't a member,
2747 	 * tell switchdev that this VLAN is likely handled in software.
2748 	 */
2749 	if (!vlan.valid ||
2750 	    vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
2751 		return -EOPNOTSUPP;
2752 
2753 	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
2754 
2755 	/* keep the VLAN unless all ports are excluded */
2756 	vlan.valid = false;
2757 	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
2758 		if (vlan.member[i] !=
2759 		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
2760 			vlan.valid = true;
2761 			break;
2762 		}
2763 	}
2764 
2765 	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
2766 	if (err)
2767 		return err;
2768 
2769 	if (!vlan.valid) {
2770 		err = mv88e6xxx_mst_put(chip, vlan.sid);
2771 		if (err)
2772 			return err;
2773 	}
2774 
2775 	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
2776 }
2777 
2778 static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
2779 				   const struct switchdev_obj_port_vlan *vlan)
2780 {
2781 	struct mv88e6xxx_chip *chip = ds->priv;
2782 	struct mv88e6xxx_port *p = &chip->ports[port];
2783 	int err = 0;
2784 	u16 pvid;
2785 
2786 	if (!mv88e6xxx_max_vid(chip))
2787 		return -EOPNOTSUPP;
2788 
2789 	/* The ATU removal procedure needs the FID to be mapped in the VTU,
2790 	 * but FDB deletion runs concurrently with VLAN deletion. Flush the DSA
2791 	 * switchdev workqueue to ensure that all FDB entries are deleted
2792 	 * before we remove the VLAN.
2793 	 */
2794 	dsa_flush_workqueue();
2795 
2796 	mv88e6xxx_reg_lock(chip);
2797 
2798 	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
2799 	if (err)
2800 		goto unlock;
2801 
2802 	err = mv88e6xxx_port_vlan_leave(chip, port, vlan->vid);
2803 	if (err)
2804 		goto unlock;
2805 
2806 	if (vlan->vid == pvid) {
2807 		p->bridge_pvid.valid = false;
2808 
2809 		err = mv88e6xxx_port_commit_pvid(chip, port);
2810 		if (err)
2811 			goto unlock;
2812 	}
2813 
2814 unlock:
2815 	mv88e6xxx_reg_unlock(chip);
2816 
2817 	return err;
2818 }
2819 
2820 static int mv88e6xxx_port_vlan_fast_age(struct dsa_switch *ds, int port, u16 vid)
2821 {
2822 	struct mv88e6xxx_chip *chip = ds->priv;
2823 	struct mv88e6xxx_vtu_entry vlan;
2824 	int err;
2825 
2826 	mv88e6xxx_reg_lock(chip);
2827 
2828 	err = mv88e6xxx_vtu_get(chip, vid, &vlan);
2829 	if (err)
2830 		goto unlock;
2831 
2832 	err = mv88e6xxx_port_fast_age_fid(chip, port, vlan.fid);
2833 
2834 unlock:
2835 	mv88e6xxx_reg_unlock(chip);
2836 
2837 	return err;
2838 }
2839 
2840 static int mv88e6xxx_vlan_msti_set(struct dsa_switch *ds,
2841 				   struct dsa_bridge bridge,
2842 				   const struct switchdev_vlan_msti *msti)
2843 {
2844 	struct mv88e6xxx_chip *chip = ds->priv;
2845 	struct mv88e6xxx_vtu_entry vlan;
2846 	u8 old_sid, new_sid;
2847 	int err;
2848 
2849 	if (!mv88e6xxx_has_stu(chip))
2850 		return -EOPNOTSUPP;
2851 
2852 	mv88e6xxx_reg_lock(chip);
2853 
2854 	err = mv88e6xxx_vtu_get(chip, msti->vid, &vlan);
2855 	if (err)
2856 		goto unlock;
2857 
2858 	if (!vlan.valid) {
2859 		err = -EINVAL;
2860 		goto unlock;
2861 	}
2862 
2863 	old_sid = vlan.sid;
2864 
2865 	err = mv88e6xxx_mst_get(chip, bridge.dev, msti->msti, &new_sid);
2866 	if (err)
2867 		goto unlock;
2868 
2869 	if (new_sid != old_sid) {
2870 		vlan.sid = new_sid;
2871 
2872 		err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
2873 		if (err) {
2874 			mv88e6xxx_mst_put(chip, new_sid);
2875 			goto unlock;
2876 		}
2877 	}
2878 
2879 	err = mv88e6xxx_mst_put(chip, old_sid);
2880 
2881 unlock:
2882 	mv88e6xxx_reg_unlock(chip);
2883 	return err;
2884 }
2885 
2886 static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2887 				  const unsigned char *addr, u16 vid,
2888 				  struct dsa_db db)
2889 {
2890 	struct mv88e6xxx_chip *chip = ds->priv;
2891 	int err;
2892 
2893 	mv88e6xxx_reg_lock(chip);
2894 	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
2895 					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
2896 	mv88e6xxx_reg_unlock(chip);
2897 
2898 	return err;
2899 }
2900 
2901 static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
2902 				  const unsigned char *addr, u16 vid,
2903 				  struct dsa_db db)
2904 {
2905 	struct mv88e6xxx_chip *chip = ds->priv;
2906 	int err;
2907 
2908 	mv88e6xxx_reg_lock(chip);
2909 	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid, 0);
2910 	mv88e6xxx_reg_unlock(chip);
2911 
2912 	return err;
2913 }
2914 
2915 static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2916 				      u16 fid, u16 vid, int port,
2917 				      dsa_fdb_dump_cb_t *cb, void *data)
2918 {
2919 	struct mv88e6xxx_atu_entry addr;
2920 	bool is_static;
2921 	int err;
2922 
2923 	addr.state = 0;
2924 	eth_broadcast_addr(addr.mac);
2925 
2926 	do {
2927 		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
2928 		if (err)
2929 			return err;
2930 
2931 		if (!addr.state)
2932 			break;
2933 
2934 		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
2935 			continue;
2936 
2937 		if (!is_unicast_ether_addr(addr.mac))
2938 			continue;
2939 
2940 		is_static = (addr.state ==
2941 			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
2942 		err = cb(addr.mac, vid, is_static, data);
2943 		if (err)
2944 			return err;
2945 	} while (!is_broadcast_ether_addr(addr.mac));
2946 
2947 	return err;
2948 }
2949 
2950 struct mv88e6xxx_port_db_dump_vlan_ctx {
2951 	int port;
2952 	dsa_fdb_dump_cb_t *cb;
2953 	void *data;
2954 };
2955 
2956 static int mv88e6xxx_port_db_dump_vlan(struct mv88e6xxx_chip *chip,
2957 				       const struct mv88e6xxx_vtu_entry *entry,
2958 				       void *_data)
2959 {
2960 	struct mv88e6xxx_port_db_dump_vlan_ctx *ctx = _data;
2961 
2962 	return mv88e6xxx_port_db_dump_fid(chip, entry->fid, entry->vid,
2963 					  ctx->port, ctx->cb, ctx->data);
2964 }
2965 
2966 static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2967 				  dsa_fdb_dump_cb_t *cb, void *data)
2968 {
2969 	struct mv88e6xxx_port_db_dump_vlan_ctx ctx = {
2970 		.port = port,
2971 		.cb = cb,
2972 		.data = data,
2973 	};
2974 	u16 fid;
2975 	int err;
2976 
2977 	/* Dump port's default Filtering Information Database (VLAN ID 0) */
2978 	err = mv88e6xxx_port_get_fid(chip, port, &fid);
2979 	if (err)
2980 		return err;
2981 
2982 	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
2983 	if (err)
2984 		return err;
2985 
2986 	return mv88e6xxx_vtu_walk(chip, mv88e6xxx_port_db_dump_vlan, &ctx);
2987 }
2988 
2989 static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2990 				   dsa_fdb_dump_cb_t *cb, void *data)
2991 {
2992 	struct mv88e6xxx_chip *chip = ds->priv;
2993 	int err;
2994 
2995 	mv88e6xxx_reg_lock(chip);
2996 	err = mv88e6xxx_port_db_dump(chip, port, cb, data);
2997 	mv88e6xxx_reg_unlock(chip);
2998 
2999 	return err;
3000 }
3001 
3002 static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
3003 				struct dsa_bridge bridge)
3004 {
3005 	struct dsa_switch *ds = chip->ds;
3006 	struct dsa_switch_tree *dst = ds->dst;
3007 	struct dsa_port *dp;
3008 	int err;
3009 
3010 	list_for_each_entry(dp, &dst->ports, list) {
3011 		if (dsa_port_offloads_bridge(dp, &bridge)) {
3012 			if (dp->ds == ds) {
3013 				/* This is a local bridge group member,
3014 				 * remap its Port VLAN Map.
3015 				 */
3016 				err = mv88e6xxx_port_vlan_map(chip, dp->index);
3017 				if (err)
3018 					return err;
3019 			} else {
3020 				/* This is an external bridge group member,
3021 				 * remap its cross-chip Port VLAN Table entry.
3022 				 */
3023 				err = mv88e6xxx_pvt_map(chip, dp->ds->index,
3024 							dp->index);
3025 				if (err)
3026 					return err;
3027 			}
3028 		}
3029 	}
3030 
3031 	return 0;
3032 }
3033 
3034 /* Treat the software bridge as a virtual single-port switch behind the
3035  * CPU and map in the PVT. First dst->last_switch elements are taken by
3036  * physical switches, so start from beyond that range.
3037  */
3038 static int mv88e6xxx_map_virtual_bridge_to_pvt(struct dsa_switch *ds,
3039 					       unsigned int bridge_num)
3040 {
3041 	u8 dev = bridge_num + ds->dst->last_switch;
3042 	struct mv88e6xxx_chip *chip = ds->priv;
3043 
3044 	return mv88e6xxx_pvt_map(chip, dev, 0);
3045 }
3046 
3047 static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
3048 				      struct dsa_bridge bridge,
3049 				      bool *tx_fwd_offload,
3050 				      struct netlink_ext_ack *extack)
3051 {
3052 	struct mv88e6xxx_chip *chip = ds->priv;
3053 	int err;
3054 
3055 	mv88e6xxx_reg_lock(chip);
3056 
3057 	err = mv88e6xxx_bridge_map(chip, bridge);
3058 	if (err)
3059 		goto unlock;
3060 
3061 	err = mv88e6xxx_port_set_map_da(chip, port, true);
3062 	if (err)
3063 		goto unlock;
3064 
3065 	err = mv88e6xxx_port_commit_pvid(chip, port);
3066 	if (err)
3067 		goto unlock;
3068 
3069 	if (mv88e6xxx_has_pvt(chip)) {
3070 		err = mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge.num);
3071 		if (err)
3072 			goto unlock;
3073 
3074 		*tx_fwd_offload = true;
3075 	}
3076 
3077 unlock:
3078 	mv88e6xxx_reg_unlock(chip);
3079 
3080 	return err;
3081 }
3082 
3083 static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
3084 					struct dsa_bridge bridge)
3085 {
3086 	struct mv88e6xxx_chip *chip = ds->priv;
3087 	int err;
3088 
3089 	mv88e6xxx_reg_lock(chip);
3090 
3091 	if (bridge.tx_fwd_offload &&
3092 	    mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge.num))
3093 		dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
3094 
3095 	if (mv88e6xxx_bridge_map(chip, bridge) ||
3096 	    mv88e6xxx_port_vlan_map(chip, port))
3097 		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
3098 
3099 	err = mv88e6xxx_port_set_map_da(chip, port, false);
3100 	if (err)
3101 		dev_err(ds->dev,
3102 			"port %d failed to restore map-DA: %pe\n",
3103 			port, ERR_PTR(err));
3104 
3105 	err = mv88e6xxx_port_commit_pvid(chip, port);
3106 	if (err)
3107 		dev_err(ds->dev,
3108 			"port %d failed to restore standalone pvid: %pe\n",
3109 			port, ERR_PTR(err));
3110 
3111 	mv88e6xxx_reg_unlock(chip);
3112 }
3113 
3114 static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds,
3115 					   int tree_index, int sw_index,
3116 					   int port, struct dsa_bridge bridge,
3117 					   struct netlink_ext_ack *extack)
3118 {
3119 	struct mv88e6xxx_chip *chip = ds->priv;
3120 	int err;
3121 
3122 	if (tree_index != ds->dst->index)
3123 		return 0;
3124 
3125 	mv88e6xxx_reg_lock(chip);
3126 	err = mv88e6xxx_pvt_map(chip, sw_index, port);
3127 	err = err ? : mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge.num);
3128 	mv88e6xxx_reg_unlock(chip);
3129 
3130 	return err;
3131 }
3132 
3133 static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds,
3134 					     int tree_index, int sw_index,
3135 					     int port, struct dsa_bridge bridge)
3136 {
3137 	struct mv88e6xxx_chip *chip = ds->priv;
3138 
3139 	if (tree_index != ds->dst->index)
3140 		return;
3141 
3142 	mv88e6xxx_reg_lock(chip);
3143 	if (mv88e6xxx_pvt_map(chip, sw_index, port) ||
3144 	    mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge.num))
3145 		dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
3146 	mv88e6xxx_reg_unlock(chip);
3147 }
3148 
3149 static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
3150 {
3151 	if (chip->info->ops->reset)
3152 		return chip->info->ops->reset(chip);
3153 
3154 	return 0;
3155 }
3156 
3157 static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
3158 {
3159 	struct gpio_desc *gpiod = chip->reset;
3160 	int err;
3161 
3162 	/* If there is a GPIO connected to the reset pin, toggle it */
3163 	if (gpiod) {
3164 		/* If the switch has just been reset and not yet completed
3165 		 * loading EEPROM, the reset may interrupt the I2C transaction
3166 		 * mid-byte, causing the first EEPROM read after the reset
3167 		 * from the wrong location resulting in the switch booting
3168 		 * to wrong mode and inoperable.
3169 		 * For this reason, switch families with EEPROM support
3170 		 * generally wait for EEPROM loads to complete as their pre-
3171 		 * and post-reset handlers.
3172 		 */
3173 		if (chip->info->ops->hardware_reset_pre) {
3174 			err = chip->info->ops->hardware_reset_pre(chip);
3175 			if (err)
3176 				dev_err(chip->dev, "pre-reset error: %d\n", err);
3177 		}
3178 
3179 		gpiod_set_value_cansleep(gpiod, 1);
3180 		usleep_range(10000, 20000);
3181 		gpiod_set_value_cansleep(gpiod, 0);
3182 		usleep_range(10000, 20000);
3183 
3184 		if (chip->info->ops->hardware_reset_post) {
3185 			err = chip->info->ops->hardware_reset_post(chip);
3186 			if (err)
3187 				dev_err(chip->dev, "post-reset error: %d\n", err);
3188 		}
3189 	}
3190 }
3191 
3192 static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
3193 {
3194 	int i, err;
3195 
3196 	/* Set all ports to the Disabled state */
3197 	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
3198 		err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
3199 		if (err)
3200 			return err;
3201 	}
3202 
3203 	/* Wait for transmit queues to drain,
3204 	 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
3205 	 */
3206 	usleep_range(2000, 4000);
3207 
3208 	return 0;
3209 }
3210 
3211 static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
3212 {
3213 	int err;
3214 
3215 	err = mv88e6xxx_disable_ports(chip);
3216 	if (err)
3217 		return err;
3218 
3219 	mv88e6xxx_hardware_reset(chip);
3220 
3221 	return mv88e6xxx_software_reset(chip);
3222 }
3223 
3224 static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
3225 				   enum mv88e6xxx_frame_mode frame,
3226 				   enum mv88e6xxx_egress_mode egress, u16 etype)
3227 {
3228 	int err;
3229 
3230 	if (!chip->info->ops->port_set_frame_mode)
3231 		return -EOPNOTSUPP;
3232 
3233 	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
3234 	if (err)
3235 		return err;
3236 
3237 	err = chip->info->ops->port_set_frame_mode(chip, port, frame);
3238 	if (err)
3239 		return err;
3240 
3241 	if (chip->info->ops->port_set_ether_type)
3242 		return chip->info->ops->port_set_ether_type(chip, port, etype);
3243 
3244 	return 0;
3245 }
3246 
3247 static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
3248 {
3249 	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
3250 				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
3251 				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
3252 }
3253 
3254 static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
3255 {
3256 	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
3257 				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
3258 				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
3259 }
3260 
3261 static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
3262 {
3263 	return mv88e6xxx_set_port_mode(chip, port,
3264 				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
3265 				       MV88E6XXX_EGRESS_MODE_ETHERTYPE,
3266 				       ETH_P_EDSA);
3267 }
3268 
3269 static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
3270 {
3271 	if (dsa_is_dsa_port(chip->ds, port))
3272 		return mv88e6xxx_set_port_mode_dsa(chip, port);
3273 
3274 	if (dsa_is_user_port(chip->ds, port))
3275 		return mv88e6xxx_set_port_mode_normal(chip, port);
3276 
3277 	/* Setup CPU port mode depending on its supported tag format */
3278 	if (chip->tag_protocol == DSA_TAG_PROTO_DSA)
3279 		return mv88e6xxx_set_port_mode_dsa(chip, port);
3280 
3281 	if (chip->tag_protocol == DSA_TAG_PROTO_EDSA)
3282 		return mv88e6xxx_set_port_mode_edsa(chip, port);
3283 
3284 	return -EINVAL;
3285 }
3286 
3287 static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
3288 {
3289 	bool message = dsa_is_dsa_port(chip->ds, port);
3290 
3291 	return mv88e6xxx_port_set_message_port(chip, port, message);
3292 }
3293 
3294 static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
3295 {
3296 	int err;
3297 
3298 	if (chip->info->ops->port_set_ucast_flood) {
3299 		err = chip->info->ops->port_set_ucast_flood(chip, port, true);
3300 		if (err)
3301 			return err;
3302 	}
3303 	if (chip->info->ops->port_set_mcast_flood) {
3304 		err = chip->info->ops->port_set_mcast_flood(chip, port, true);
3305 		if (err)
3306 			return err;
3307 	}
3308 
3309 	return 0;
3310 }
3311 
3312 static int mv88e6xxx_set_egress_port(struct mv88e6xxx_chip *chip,
3313 				     enum mv88e6xxx_egress_direction direction,
3314 				     int port)
3315 {
3316 	int err;
3317 
3318 	if (!chip->info->ops->set_egress_port)
3319 		return -EOPNOTSUPP;
3320 
3321 	err = chip->info->ops->set_egress_port(chip, direction, port);
3322 	if (err)
3323 		return err;
3324 
3325 	if (direction == MV88E6XXX_EGRESS_DIR_INGRESS)
3326 		chip->ingress_dest_port = port;
3327 	else
3328 		chip->egress_dest_port = port;
3329 
3330 	return 0;
3331 }
3332 
3333 static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
3334 {
3335 	struct dsa_switch *ds = chip->ds;
3336 	int upstream_port;
3337 	int err;
3338 
3339 	upstream_port = dsa_upstream_port(ds, port);
3340 	if (chip->info->ops->port_set_upstream_port) {
3341 		err = chip->info->ops->port_set_upstream_port(chip, port,
3342 							      upstream_port);
3343 		if (err)
3344 			return err;
3345 	}
3346 
3347 	if (port == upstream_port) {
3348 		if (chip->info->ops->set_cpu_port) {
3349 			err = chip->info->ops->set_cpu_port(chip,
3350 							    upstream_port);
3351 			if (err)
3352 				return err;
3353 		}
3354 
3355 		err = mv88e6xxx_set_egress_port(chip,
3356 						MV88E6XXX_EGRESS_DIR_INGRESS,
3357 						upstream_port);
3358 		if (err && err != -EOPNOTSUPP)
3359 			return err;
3360 
3361 		err = mv88e6xxx_set_egress_port(chip,
3362 						MV88E6XXX_EGRESS_DIR_EGRESS,
3363 						upstream_port);
3364 		if (err && err != -EOPNOTSUPP)
3365 			return err;
3366 	}
3367 
3368 	return 0;
3369 }
3370 
3371 static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
3372 {
3373 	struct device_node *phy_handle = NULL;
3374 	struct dsa_switch *ds = chip->ds;
3375 	struct dsa_port *dp;
3376 	int tx_amp;
3377 	int err;
3378 	u16 reg;
3379 
3380 	chip->ports[port].chip = chip;
3381 	chip->ports[port].port = port;
3382 
3383 	err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
3384 				       SPEED_UNFORCED, DUPLEX_UNFORCED,
3385 				       PAUSE_ON, PHY_INTERFACE_MODE_NA);
3386 	if (err)
3387 		return err;
3388 
3389 	/* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
3390 	 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
3391 	 * tunneling, determine priority by looking at 802.1p and IP
3392 	 * priority fields (IP prio has precedence), and set STP state
3393 	 * to Forwarding.
3394 	 *
3395 	 * If this is the CPU link, use DSA or EDSA tagging depending
3396 	 * on which tagging mode was configured.
3397 	 *
3398 	 * If this is a link to another switch, use DSA tagging mode.
3399 	 *
3400 	 * If this is the upstream port for this switch, enable
3401 	 * forwarding of unknown unicasts and multicasts.
3402 	 */
3403 	reg = MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
3404 		MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
3405 	/* Forward any IPv4 IGMP or IPv6 MLD frames received
3406 	 * by a USER port to the CPU port to allow snooping.
3407 	 */
3408 	if (dsa_is_user_port(ds, port))
3409 		reg |= MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP;
3410 
3411 	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
3412 	if (err)
3413 		return err;
3414 
3415 	err = mv88e6xxx_setup_port_mode(chip, port);
3416 	if (err)
3417 		return err;
3418 
3419 	err = mv88e6xxx_setup_egress_floods(chip, port);
3420 	if (err)
3421 		return err;
3422 
3423 	/* Port Control 2: don't force a good FCS, set the MTU size to
3424 	 * 10222 bytes, disable 802.1q tags checking, don't discard
3425 	 * tagged or untagged frames on this port, skip destination
3426 	 * address lookup on user ports, disable ARP mirroring and don't
3427 	 * send a copy of all transmitted/received frames on this port
3428 	 * to the CPU.
3429 	 */
3430 	err = mv88e6xxx_port_set_map_da(chip, port, !dsa_is_user_port(ds, port));
3431 	if (err)
3432 		return err;
3433 
3434 	err = mv88e6xxx_setup_upstream_port(chip, port);
3435 	if (err)
3436 		return err;
3437 
3438 	/* On chips that support it, set all downstream DSA ports'
3439 	 * VLAN policy to TRAP. In combination with loading
3440 	 * MV88E6XXX_VID_STANDALONE as a policy entry in the VTU, this
3441 	 * provides a better isolation barrier between standalone
3442 	 * ports, as the ATU is bypassed on any intermediate switches
3443 	 * between the incoming port and the CPU.
3444 	 */
3445 	if (dsa_is_downstream_port(ds, port) &&
3446 	    chip->info->ops->port_set_policy) {
3447 		err = chip->info->ops->port_set_policy(chip, port,
3448 						MV88E6XXX_POLICY_MAPPING_VTU,
3449 						MV88E6XXX_POLICY_ACTION_TRAP);
3450 		if (err)
3451 			return err;
3452 	}
3453 
3454 	/* User ports start out in standalone mode and 802.1Q is
3455 	 * therefore disabled. On DSA ports, all valid VIDs are always
3456 	 * loaded in the VTU - therefore, enable 802.1Q in order to take
3457 	 * advantage of VLAN policy on chips that supports it.
3458 	 */
3459 	err = mv88e6xxx_port_set_8021q_mode(chip, port,
3460 				dsa_is_user_port(ds, port) ?
3461 				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED :
3462 				MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE);
3463 	if (err)
3464 		return err;
3465 
3466 	/* Bind MV88E6XXX_VID_STANDALONE to MV88E6XXX_FID_STANDALONE by
3467 	 * virtue of the fact that mv88e6xxx_atu_new() will pick it as
3468 	 * the first free FID. This will be used as the private PVID for
3469 	 * unbridged ports. Shared (DSA and CPU) ports must also be
3470 	 * members of this VID, in order to trap all frames assigned to
3471 	 * it to the CPU.
3472 	 */
3473 	err = mv88e6xxx_port_vlan_join(chip, port, MV88E6XXX_VID_STANDALONE,
3474 				       MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED,
3475 				       false);
3476 	if (err)
3477 		return err;
3478 
3479 	/* Associate MV88E6XXX_VID_BRIDGED with MV88E6XXX_FID_BRIDGED in the
3480 	 * ATU by virtue of the fact that mv88e6xxx_atu_new() will pick it as
3481 	 * the first free FID after MV88E6XXX_FID_STANDALONE. This will be used
3482 	 * as the private PVID on ports under a VLAN-unaware bridge.
3483 	 * Shared (DSA and CPU) ports must also be members of it, to translate
3484 	 * the VID from the DSA tag into MV88E6XXX_FID_BRIDGED, instead of
3485 	 * relying on their port default FID.
3486 	 */
3487 	err = mv88e6xxx_port_vlan_join(chip, port, MV88E6XXX_VID_BRIDGED,
3488 				       MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED,
3489 				       false);
3490 	if (err)
3491 		return err;
3492 
3493 	if (chip->info->ops->port_set_jumbo_size) {
3494 		err = chip->info->ops->port_set_jumbo_size(chip, port, 10218);
3495 		if (err)
3496 			return err;
3497 	}
3498 
3499 	/* Port Association Vector: disable automatic address learning
3500 	 * on all user ports since they start out in standalone
3501 	 * mode. When joining a bridge, learning will be configured to
3502 	 * match the bridge port settings. Enable learning on all
3503 	 * DSA/CPU ports. NOTE: FROM_CPU frames always bypass the
3504 	 * learning process.
3505 	 *
3506 	 * Disable HoldAt1, IntOnAgeOut, LockedPort, IgnoreWrongData,
3507 	 * and RefreshLocked. I.e. setup standard automatic learning.
3508 	 */
3509 	if (dsa_is_user_port(ds, port))
3510 		reg = 0;
3511 	else
3512 		reg = 1 << port;
3513 
3514 	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
3515 				   reg);
3516 	if (err)
3517 		return err;
3518 
3519 	/* Egress rate control 2: disable egress rate control. */
3520 	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
3521 				   0x0000);
3522 	if (err)
3523 		return err;
3524 
3525 	if (chip->info->ops->port_pause_limit) {
3526 		err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
3527 		if (err)
3528 			return err;
3529 	}
3530 
3531 	if (chip->info->ops->port_disable_learn_limit) {
3532 		err = chip->info->ops->port_disable_learn_limit(chip, port);
3533 		if (err)
3534 			return err;
3535 	}
3536 
3537 	if (chip->info->ops->port_disable_pri_override) {
3538 		err = chip->info->ops->port_disable_pri_override(chip, port);
3539 		if (err)
3540 			return err;
3541 	}
3542 
3543 	if (chip->info->ops->port_tag_remap) {
3544 		err = chip->info->ops->port_tag_remap(chip, port);
3545 		if (err)
3546 			return err;
3547 	}
3548 
3549 	if (chip->info->ops->port_egress_rate_limiting) {
3550 		err = chip->info->ops->port_egress_rate_limiting(chip, port);
3551 		if (err)
3552 			return err;
3553 	}
3554 
3555 	if (chip->info->ops->port_setup_message_port) {
3556 		err = chip->info->ops->port_setup_message_port(chip, port);
3557 		if (err)
3558 			return err;
3559 	}
3560 
3561 	if (chip->info->ops->serdes_set_tx_amplitude) {
3562 		dp = dsa_to_port(ds, port);
3563 		if (dp)
3564 			phy_handle = of_parse_phandle(dp->dn, "phy-handle", 0);
3565 
3566 		if (phy_handle && !of_property_read_u32(phy_handle,
3567 							"tx-p2p-microvolt",
3568 							&tx_amp))
3569 			err = chip->info->ops->serdes_set_tx_amplitude(chip,
3570 								port, tx_amp);
3571 		if (phy_handle) {
3572 			of_node_put(phy_handle);
3573 			if (err)
3574 				return err;
3575 		}
3576 	}
3577 
3578 	/* Port based VLAN map: give each port the same default address
3579 	 * database, and allow bidirectional communication between the
3580 	 * CPU and DSA port(s), and the other ports.
3581 	 */
3582 	err = mv88e6xxx_port_set_fid(chip, port, MV88E6XXX_FID_STANDALONE);
3583 	if (err)
3584 		return err;
3585 
3586 	err = mv88e6xxx_port_vlan_map(chip, port);
3587 	if (err)
3588 		return err;
3589 
3590 	/* Default VLAN ID and priority: don't set a default VLAN
3591 	 * ID, and set the default packet priority to zero.
3592 	 */
3593 	return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
3594 }
3595 
3596 static int mv88e6xxx_get_max_mtu(struct dsa_switch *ds, int port)
3597 {
3598 	struct mv88e6xxx_chip *chip = ds->priv;
3599 
3600 	if (chip->info->ops->port_set_jumbo_size)
3601 		return 10240 - VLAN_ETH_HLEN - EDSA_HLEN - ETH_FCS_LEN;
3602 	else if (chip->info->ops->set_max_frame_size)
3603 		return 1632 - VLAN_ETH_HLEN - EDSA_HLEN - ETH_FCS_LEN;
3604 	return ETH_DATA_LEN;
3605 }
3606 
3607 static int mv88e6xxx_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
3608 {
3609 	struct mv88e6xxx_chip *chip = ds->priv;
3610 	int ret = 0;
3611 
3612 	/* For families where we don't know how to alter the MTU,
3613 	 * just accept any value up to ETH_DATA_LEN
3614 	 */
3615 	if (!chip->info->ops->port_set_jumbo_size &&
3616 	    !chip->info->ops->set_max_frame_size) {
3617 		if (new_mtu > ETH_DATA_LEN)
3618 			return -EINVAL;
3619 
3620 		return 0;
3621 	}
3622 
3623 	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
3624 		new_mtu += EDSA_HLEN;
3625 
3626 	mv88e6xxx_reg_lock(chip);
3627 	if (chip->info->ops->port_set_jumbo_size)
3628 		ret = chip->info->ops->port_set_jumbo_size(chip, port, new_mtu);
3629 	else if (chip->info->ops->set_max_frame_size)
3630 		ret = chip->info->ops->set_max_frame_size(chip, new_mtu);
3631 	mv88e6xxx_reg_unlock(chip);
3632 
3633 	return ret;
3634 }
3635 
3636 static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
3637 				     unsigned int ageing_time)
3638 {
3639 	struct mv88e6xxx_chip *chip = ds->priv;
3640 	int err;
3641 
3642 	mv88e6xxx_reg_lock(chip);
3643 	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
3644 	mv88e6xxx_reg_unlock(chip);
3645 
3646 	return err;
3647 }
3648 
3649 static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
3650 {
3651 	int err;
3652 
3653 	/* Initialize the statistics unit */
3654 	if (chip->info->ops->stats_set_histogram) {
3655 		err = chip->info->ops->stats_set_histogram(chip);
3656 		if (err)
3657 			return err;
3658 	}
3659 
3660 	return mv88e6xxx_g1_stats_clear(chip);
3661 }
3662 
3663 /* Check if the errata has already been applied. */
3664 static bool mv88e6390_setup_errata_applied(struct mv88e6xxx_chip *chip)
3665 {
3666 	int port;
3667 	int err;
3668 	u16 val;
3669 
3670 	for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
3671 		err = mv88e6xxx_port_hidden_read(chip, 0xf, port, 0, &val);
3672 		if (err) {
3673 			dev_err(chip->dev,
3674 				"Error reading hidden register: %d\n", err);
3675 			return false;
3676 		}
3677 		if (val != 0x01c0)
3678 			return false;
3679 	}
3680 
3681 	return true;
3682 }
3683 
3684 /* The 6390 copper ports have an errata which require poking magic
3685  * values into undocumented hidden registers and then performing a
3686  * software reset.
3687  */
3688 static int mv88e6390_setup_errata(struct mv88e6xxx_chip *chip)
3689 {
3690 	int port;
3691 	int err;
3692 
3693 	if (mv88e6390_setup_errata_applied(chip))
3694 		return 0;
3695 
3696 	/* Set the ports into blocking mode */
3697 	for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
3698 		err = mv88e6xxx_port_set_state(chip, port, BR_STATE_DISABLED);
3699 		if (err)
3700 			return err;
3701 	}
3702 
3703 	for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
3704 		err = mv88e6xxx_port_hidden_write(chip, 0xf, port, 0, 0x01c0);
3705 		if (err)
3706 			return err;
3707 	}
3708 
3709 	return mv88e6xxx_software_reset(chip);
3710 }
3711 
3712 /* prod_id for switch families which do not have a PHY model number */
3713 static const u16 family_prod_id_table[] = {
3714 	[MV88E6XXX_FAMILY_6341] = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
3715 	[MV88E6XXX_FAMILY_6390] = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
3716 	[MV88E6XXX_FAMILY_6393] = MV88E6XXX_PORT_SWITCH_ID_PROD_6393X,
3717 };
3718 
3719 static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
3720 {
3721 	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3722 	struct mv88e6xxx_chip *chip = mdio_bus->chip;
3723 	u16 prod_id;
3724 	u16 val;
3725 	int err;
3726 
3727 	if (!chip->info->ops->phy_read)
3728 		return -EOPNOTSUPP;
3729 
3730 	mv88e6xxx_reg_lock(chip);
3731 	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
3732 	mv88e6xxx_reg_unlock(chip);
3733 
3734 	/* Some internal PHYs don't have a model number. */
3735 	if (reg == MII_PHYSID2 && !(val & 0x3f0) &&
3736 	    chip->info->family < ARRAY_SIZE(family_prod_id_table)) {
3737 		prod_id = family_prod_id_table[chip->info->family];
3738 		if (prod_id)
3739 			val |= prod_id >> 4;
3740 	}
3741 
3742 	return err ? err : val;
3743 }
3744 
3745 static int mv88e6xxx_mdio_read_c45(struct mii_bus *bus, int phy, int devad,
3746 				   int reg)
3747 {
3748 	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3749 	struct mv88e6xxx_chip *chip = mdio_bus->chip;
3750 	u16 val;
3751 	int err;
3752 
3753 	if (!chip->info->ops->phy_read_c45)
3754 		return -ENODEV;
3755 
3756 	mv88e6xxx_reg_lock(chip);
3757 	err = chip->info->ops->phy_read_c45(chip, bus, phy, devad, reg, &val);
3758 	mv88e6xxx_reg_unlock(chip);
3759 
3760 	return err ? err : val;
3761 }
3762 
3763 static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
3764 {
3765 	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3766 	struct mv88e6xxx_chip *chip = mdio_bus->chip;
3767 	int err;
3768 
3769 	if (!chip->info->ops->phy_write)
3770 		return -EOPNOTSUPP;
3771 
3772 	mv88e6xxx_reg_lock(chip);
3773 	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
3774 	mv88e6xxx_reg_unlock(chip);
3775 
3776 	return err;
3777 }
3778 
3779 static int mv88e6xxx_mdio_write_c45(struct mii_bus *bus, int phy, int devad,
3780 				    int reg, u16 val)
3781 {
3782 	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3783 	struct mv88e6xxx_chip *chip = mdio_bus->chip;
3784 	int err;
3785 
3786 	if (!chip->info->ops->phy_write_c45)
3787 		return -EOPNOTSUPP;
3788 
3789 	mv88e6xxx_reg_lock(chip);
3790 	err = chip->info->ops->phy_write_c45(chip, bus, phy, devad, reg, val);
3791 	mv88e6xxx_reg_unlock(chip);
3792 
3793 	return err;
3794 }
3795 
3796 static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
3797 				   struct device_node *np,
3798 				   bool external)
3799 {
3800 	static int index;
3801 	struct mv88e6xxx_mdio_bus *mdio_bus;
3802 	struct mii_bus *bus;
3803 	int err;
3804 
3805 	if (external) {
3806 		mv88e6xxx_reg_lock(chip);
3807 		if (chip->info->family == MV88E6XXX_FAMILY_6393)
3808 			err = mv88e6393x_g2_scratch_gpio_set_smi(chip, true);
3809 		else
3810 			err = mv88e6390_g2_scratch_gpio_set_smi(chip, true);
3811 		mv88e6xxx_reg_unlock(chip);
3812 
3813 		if (err)
3814 			return err;
3815 	}
3816 
3817 	bus = mdiobus_alloc_size(sizeof(*mdio_bus));
3818 	if (!bus)
3819 		return -ENOMEM;
3820 
3821 	mdio_bus = bus->priv;
3822 	mdio_bus->bus = bus;
3823 	mdio_bus->chip = chip;
3824 	INIT_LIST_HEAD(&mdio_bus->list);
3825 	mdio_bus->external = external;
3826 
3827 	if (np) {
3828 		bus->name = np->full_name;
3829 		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
3830 	} else {
3831 		bus->name = "mv88e6xxx SMI";
3832 		snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
3833 	}
3834 
3835 	bus->read = mv88e6xxx_mdio_read;
3836 	bus->write = mv88e6xxx_mdio_write;
3837 	bus->read_c45 = mv88e6xxx_mdio_read_c45;
3838 	bus->write_c45 = mv88e6xxx_mdio_write_c45;
3839 	bus->parent = chip->dev;
3840 	bus->phy_mask = ~GENMASK(chip->info->phy_base_addr +
3841 				 mv88e6xxx_num_ports(chip) - 1,
3842 				 chip->info->phy_base_addr);
3843 
3844 	if (!external) {
3845 		err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
3846 		if (err)
3847 			goto out;
3848 	}
3849 
3850 	err = of_mdiobus_register(bus, np);
3851 	if (err) {
3852 		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
3853 		mv88e6xxx_g2_irq_mdio_free(chip, bus);
3854 		goto out;
3855 	}
3856 
3857 	if (external)
3858 		list_add_tail(&mdio_bus->list, &chip->mdios);
3859 	else
3860 		list_add(&mdio_bus->list, &chip->mdios);
3861 
3862 	return 0;
3863 
3864 out:
3865 	mdiobus_free(bus);
3866 	return err;
3867 }
3868 
3869 static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
3870 
3871 {
3872 	struct mv88e6xxx_mdio_bus *mdio_bus, *p;
3873 	struct mii_bus *bus;
3874 
3875 	list_for_each_entry_safe(mdio_bus, p, &chip->mdios, list) {
3876 		bus = mdio_bus->bus;
3877 
3878 		if (!mdio_bus->external)
3879 			mv88e6xxx_g2_irq_mdio_free(chip, bus);
3880 
3881 		mdiobus_unregister(bus);
3882 		mdiobus_free(bus);
3883 	}
3884 }
3885 
3886 static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip)
3887 {
3888 	struct device_node *np = chip->dev->of_node;
3889 	struct device_node *child;
3890 	int err;
3891 
3892 	/* Always register one mdio bus for the internal/default mdio
3893 	 * bus. This maybe represented in the device tree, but is
3894 	 * optional.
3895 	 */
3896 	child = of_get_child_by_name(np, "mdio");
3897 	err = mv88e6xxx_mdio_register(chip, child, false);
3898 	of_node_put(child);
3899 	if (err)
3900 		return err;
3901 
3902 	/* Walk the device tree, and see if there are any other nodes
3903 	 * which say they are compatible with the external mdio
3904 	 * bus.
3905 	 */
3906 	for_each_available_child_of_node(np, child) {
3907 		if (of_device_is_compatible(
3908 			    child, "marvell,mv88e6xxx-mdio-external")) {
3909 			err = mv88e6xxx_mdio_register(chip, child, true);
3910 			if (err) {
3911 				mv88e6xxx_mdios_unregister(chip);
3912 				of_node_put(child);
3913 				return err;
3914 			}
3915 		}
3916 	}
3917 
3918 	return 0;
3919 }
3920 
3921 static void mv88e6xxx_teardown(struct dsa_switch *ds)
3922 {
3923 	struct mv88e6xxx_chip *chip = ds->priv;
3924 
3925 	mv88e6xxx_teardown_devlink_params(ds);
3926 	dsa_devlink_resources_unregister(ds);
3927 	mv88e6xxx_teardown_devlink_regions_global(ds);
3928 	mv88e6xxx_mdios_unregister(chip);
3929 }
3930 
3931 static int mv88e6xxx_setup(struct dsa_switch *ds)
3932 {
3933 	struct mv88e6xxx_chip *chip = ds->priv;
3934 	u8 cmode;
3935 	int err;
3936 	int i;
3937 
3938 	err = mv88e6xxx_mdios_register(chip);
3939 	if (err)
3940 		return err;
3941 
3942 	chip->ds = ds;
3943 	ds->user_mii_bus = mv88e6xxx_default_mdio_bus(chip);
3944 
3945 	/* Since virtual bridges are mapped in the PVT, the number we support
3946 	 * depends on the physical switch topology. We need to let DSA figure
3947 	 * that out and therefore we cannot set this at dsa_register_switch()
3948 	 * time.
3949 	 */
3950 	if (mv88e6xxx_has_pvt(chip))
3951 		ds->max_num_bridges = MV88E6XXX_MAX_PVT_SWITCHES -
3952 				      ds->dst->last_switch - 1;
3953 
3954 	mv88e6xxx_reg_lock(chip);
3955 
3956 	if (chip->info->ops->setup_errata) {
3957 		err = chip->info->ops->setup_errata(chip);
3958 		if (err)
3959 			goto unlock;
3960 	}
3961 
3962 	/* Cache the cmode of each port. */
3963 	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
3964 		if (chip->info->ops->port_get_cmode) {
3965 			err = chip->info->ops->port_get_cmode(chip, i, &cmode);
3966 			if (err)
3967 				goto unlock;
3968 
3969 			chip->ports[i].cmode = cmode;
3970 		}
3971 	}
3972 
3973 	err = mv88e6xxx_vtu_setup(chip);
3974 	if (err)
3975 		goto unlock;
3976 
3977 	/* Must be called after mv88e6xxx_vtu_setup (which flushes the
3978 	 * VTU, thereby also flushing the STU).
3979 	 */
3980 	err = mv88e6xxx_stu_setup(chip);
3981 	if (err)
3982 		goto unlock;
3983 
3984 	/* Setup Switch Port Registers */
3985 	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
3986 		if (dsa_is_unused_port(ds, i))
3987 			continue;
3988 
3989 		/* Prevent the use of an invalid port. */
3990 		if (mv88e6xxx_is_invalid_port(chip, i)) {
3991 			dev_err(chip->dev, "port %d is invalid\n", i);
3992 			err = -EINVAL;
3993 			goto unlock;
3994 		}
3995 
3996 		err = mv88e6xxx_setup_port(chip, i);
3997 		if (err)
3998 			goto unlock;
3999 	}
4000 
4001 	err = mv88e6xxx_irl_setup(chip);
4002 	if (err)
4003 		goto unlock;
4004 
4005 	err = mv88e6xxx_mac_setup(chip);
4006 	if (err)
4007 		goto unlock;
4008 
4009 	err = mv88e6xxx_phy_setup(chip);
4010 	if (err)
4011 		goto unlock;
4012 
4013 	err = mv88e6xxx_pvt_setup(chip);
4014 	if (err)
4015 		goto unlock;
4016 
4017 	err = mv88e6xxx_atu_setup(chip);
4018 	if (err)
4019 		goto unlock;
4020 
4021 	err = mv88e6xxx_broadcast_setup(chip, 0);
4022 	if (err)
4023 		goto unlock;
4024 
4025 	err = mv88e6xxx_pot_setup(chip);
4026 	if (err)
4027 		goto unlock;
4028 
4029 	err = mv88e6xxx_rmu_setup(chip);
4030 	if (err)
4031 		goto unlock;
4032 
4033 	err = mv88e6xxx_rsvd2cpu_setup(chip);
4034 	if (err)
4035 		goto unlock;
4036 
4037 	err = mv88e6xxx_trunk_setup(chip);
4038 	if (err)
4039 		goto unlock;
4040 
4041 	err = mv88e6xxx_devmap_setup(chip);
4042 	if (err)
4043 		goto unlock;
4044 
4045 	err = mv88e6xxx_pri_setup(chip);
4046 	if (err)
4047 		goto unlock;
4048 
4049 	/* Setup PTP Hardware Clock and timestamping */
4050 	if (chip->info->ptp_support) {
4051 		err = mv88e6xxx_ptp_setup(chip);
4052 		if (err)
4053 			goto unlock;
4054 
4055 		err = mv88e6xxx_hwtstamp_setup(chip);
4056 		if (err)
4057 			goto unlock;
4058 	}
4059 
4060 	err = mv88e6xxx_stats_setup(chip);
4061 	if (err)
4062 		goto unlock;
4063 
4064 unlock:
4065 	mv88e6xxx_reg_unlock(chip);
4066 
4067 	if (err)
4068 		goto out_mdios;
4069 
4070 	/* Have to be called without holding the register lock, since
4071 	 * they take the devlink lock, and we later take the locks in
4072 	 * the reverse order when getting/setting parameters or
4073 	 * resource occupancy.
4074 	 */
4075 	err = mv88e6xxx_setup_devlink_resources(ds);
4076 	if (err)
4077 		goto out_mdios;
4078 
4079 	err = mv88e6xxx_setup_devlink_params(ds);
4080 	if (err)
4081 		goto out_resources;
4082 
4083 	err = mv88e6xxx_setup_devlink_regions_global(ds);
4084 	if (err)
4085 		goto out_params;
4086 
4087 	return 0;
4088 
4089 out_params:
4090 	mv88e6xxx_teardown_devlink_params(ds);
4091 out_resources:
4092 	dsa_devlink_resources_unregister(ds);
4093 out_mdios:
4094 	mv88e6xxx_mdios_unregister(chip);
4095 
4096 	return err;
4097 }
4098 
4099 static int mv88e6xxx_port_setup(struct dsa_switch *ds, int port)
4100 {
4101 	struct mv88e6xxx_chip *chip = ds->priv;
4102 	int err;
4103 
4104 	if (chip->info->ops->pcs_ops &&
4105 	    chip->info->ops->pcs_ops->pcs_init) {
4106 		err = chip->info->ops->pcs_ops->pcs_init(chip, port);
4107 		if (err)
4108 			return err;
4109 	}
4110 
4111 	return mv88e6xxx_setup_devlink_regions_port(ds, port);
4112 }
4113 
4114 static void mv88e6xxx_port_teardown(struct dsa_switch *ds, int port)
4115 {
4116 	struct mv88e6xxx_chip *chip = ds->priv;
4117 
4118 	mv88e6xxx_teardown_devlink_regions_port(ds, port);
4119 
4120 	if (chip->info->ops->pcs_ops &&
4121 	    chip->info->ops->pcs_ops->pcs_teardown)
4122 		chip->info->ops->pcs_ops->pcs_teardown(chip, port);
4123 }
4124 
4125 static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
4126 {
4127 	struct mv88e6xxx_chip *chip = ds->priv;
4128 
4129 	return chip->eeprom_len;
4130 }
4131 
4132 static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
4133 				struct ethtool_eeprom *eeprom, u8 *data)
4134 {
4135 	struct mv88e6xxx_chip *chip = ds->priv;
4136 	int err;
4137 
4138 	if (!chip->info->ops->get_eeprom)
4139 		return -EOPNOTSUPP;
4140 
4141 	mv88e6xxx_reg_lock(chip);
4142 	err = chip->info->ops->get_eeprom(chip, eeprom, data);
4143 	mv88e6xxx_reg_unlock(chip);
4144 
4145 	if (err)
4146 		return err;
4147 
4148 	eeprom->magic = 0xc3ec4951;
4149 
4150 	return 0;
4151 }
4152 
4153 static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
4154 				struct ethtool_eeprom *eeprom, u8 *data)
4155 {
4156 	struct mv88e6xxx_chip *chip = ds->priv;
4157 	int err;
4158 
4159 	if (!chip->info->ops->set_eeprom)
4160 		return -EOPNOTSUPP;
4161 
4162 	if (eeprom->magic != 0xc3ec4951)
4163 		return -EINVAL;
4164 
4165 	mv88e6xxx_reg_lock(chip);
4166 	err = chip->info->ops->set_eeprom(chip, eeprom, data);
4167 	mv88e6xxx_reg_unlock(chip);
4168 
4169 	return err;
4170 }
4171 
4172 static const struct mv88e6xxx_ops mv88e6085_ops = {
4173 	/* MV88E6XXX_FAMILY_6097 */
4174 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4175 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4176 	.irl_init_all = mv88e6352_g2_irl_init_all,
4177 	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
4178 	.phy_read = mv88e6185_phy_ppu_read,
4179 	.phy_write = mv88e6185_phy_ppu_write,
4180 	.port_set_link = mv88e6xxx_port_set_link,
4181 	.port_sync_link = mv88e6xxx_port_sync_link,
4182 	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4183 	.port_tag_remap = mv88e6095_port_tag_remap,
4184 	.port_set_policy = mv88e6352_port_set_policy,
4185 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4186 	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4187 	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4188 	.port_set_ether_type = mv88e6351_port_set_ether_type,
4189 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4190 	.port_pause_limit = mv88e6097_port_pause_limit,
4191 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4192 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4193 	.port_get_cmode = mv88e6185_port_get_cmode,
4194 	.port_setup_message_port = mv88e6xxx_setup_message_port,
4195 	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
4196 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4197 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
4198 	.stats_get_strings = mv88e6095_stats_get_strings,
4199 	.stats_get_stat = mv88e6095_stats_get_stat,
4200 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
4201 	.set_egress_port = mv88e6095_g1_set_egress_port,
4202 	.watchdog_ops = &mv88e6097_watchdog_ops,
4203 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4204 	.pot_clear = mv88e6xxx_g2_pot_clear,
4205 	.ppu_enable = mv88e6185_g1_ppu_enable,
4206 	.ppu_disable = mv88e6185_g1_ppu_disable,
4207 	.reset = mv88e6185_g1_reset,
4208 	.rmu_disable = mv88e6085_g1_rmu_disable,
4209 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4210 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4211 	.stu_getnext = mv88e6352_g1_stu_getnext,
4212 	.stu_loadpurge = mv88e6352_g1_stu_loadpurge,
4213 	.phylink_get_caps = mv88e6185_phylink_get_caps,
4214 	.set_max_frame_size = mv88e6185_g1_set_max_frame_size,
4215 };
4216 
4217 static const struct mv88e6xxx_ops mv88e6095_ops = {
4218 	/* MV88E6XXX_FAMILY_6095 */
4219 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4220 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4221 	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
4222 	.phy_read = mv88e6185_phy_ppu_read,
4223 	.phy_write = mv88e6185_phy_ppu_write,
4224 	.port_set_link = mv88e6xxx_port_set_link,
4225 	.port_sync_link = mv88e6185_port_sync_link,
4226 	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4227 	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
4228 	.port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
4229 	.port_set_mcast_flood = mv88e6185_port_set_default_forward,
4230 	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
4231 	.port_get_cmode = mv88e6185_port_get_cmode,
4232 	.port_setup_message_port = mv88e6xxx_setup_message_port,
4233 	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
4234 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4235 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
4236 	.stats_get_strings = mv88e6095_stats_get_strings,
4237 	.stats_get_stat = mv88e6095_stats_get_stat,
4238 	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
4239 	.ppu_enable = mv88e6185_g1_ppu_enable,
4240 	.ppu_disable = mv88e6185_g1_ppu_disable,
4241 	.reset = mv88e6185_g1_reset,
4242 	.vtu_getnext = mv88e6185_g1_vtu_getnext,
4243 	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
4244 	.phylink_get_caps = mv88e6095_phylink_get_caps,
4245 	.pcs_ops = &mv88e6185_pcs_ops,
4246 	.set_max_frame_size = mv88e6185_g1_set_max_frame_size,
4247 };
4248 
4249 static const struct mv88e6xxx_ops mv88e6097_ops = {
4250 	/* MV88E6XXX_FAMILY_6097 */
4251 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4252 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4253 	.irl_init_all = mv88e6352_g2_irl_init_all,
4254 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4255 	.phy_read = mv88e6xxx_g2_smi_phy_read_c22,
4256 	.phy_write = mv88e6xxx_g2_smi_phy_write_c22,
4257 	.phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45,
4258 	.phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45,
4259 	.port_set_link = mv88e6xxx_port_set_link,
4260 	.port_sync_link = mv88e6185_port_sync_link,
4261 	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4262 	.port_tag_remap = mv88e6095_port_tag_remap,
4263 	.port_set_policy = mv88e6352_port_set_policy,
4264 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4265 	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4266 	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4267 	.port_set_ether_type = mv88e6351_port_set_ether_type,
4268 	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
4269 	.port_pause_limit = mv88e6097_port_pause_limit,
4270 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4271 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4272 	.port_get_cmode = mv88e6185_port_get_cmode,
4273 	.port_setup_message_port = mv88e6xxx_setup_message_port,
4274 	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
4275 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4276 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
4277 	.stats_get_strings = mv88e6095_stats_get_strings,
4278 	.stats_get_stat = mv88e6095_stats_get_stat,
4279 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
4280 	.set_egress_port = mv88e6095_g1_set_egress_port,
4281 	.watchdog_ops = &mv88e6097_watchdog_ops,
4282 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4283 	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4284 	.pot_clear = mv88e6xxx_g2_pot_clear,
4285 	.reset = mv88e6352_g1_reset,
4286 	.rmu_disable = mv88e6085_g1_rmu_disable,
4287 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4288 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4289 	.phylink_get_caps = mv88e6095_phylink_get_caps,
4290 	.pcs_ops = &mv88e6185_pcs_ops,
4291 	.stu_getnext = mv88e6352_g1_stu_getnext,
4292 	.stu_loadpurge = mv88e6352_g1_stu_loadpurge,
4293 	.set_max_frame_size = mv88e6185_g1_set_max_frame_size,
4294 };
4295 
4296 static const struct mv88e6xxx_ops mv88e6123_ops = {
4297 	/* MV88E6XXX_FAMILY_6165 */
4298 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4299 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4300 	.irl_init_all = mv88e6352_g2_irl_init_all,
4301 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4302 	.phy_read = mv88e6xxx_g2_smi_phy_read_c22,
4303 	.phy_write = mv88e6xxx_g2_smi_phy_write_c22,
4304 	.phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45,
4305 	.phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45,
4306 	.port_set_link = mv88e6xxx_port_set_link,
4307 	.port_sync_link = mv88e6xxx_port_sync_link,
4308 	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4309 	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
4310 	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4311 	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4312 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4313 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4314 	.port_get_cmode = mv88e6185_port_get_cmode,
4315 	.port_setup_message_port = mv88e6xxx_setup_message_port,
4316 	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4317 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4318 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
4319 	.stats_get_strings = mv88e6095_stats_get_strings,
4320 	.stats_get_stat = mv88e6095_stats_get_stat,
4321 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
4322 	.set_egress_port = mv88e6095_g1_set_egress_port,
4323 	.watchdog_ops = &mv88e6097_watchdog_ops,
4324 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4325 	.pot_clear = mv88e6xxx_g2_pot_clear,
4326 	.reset = mv88e6352_g1_reset,
4327 	.atu_get_hash = mv88e6165_g1_atu_get_hash,
4328 	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4329 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4330 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4331 	.stu_getnext = mv88e6352_g1_stu_getnext,
4332 	.stu_loadpurge = mv88e6352_g1_stu_loadpurge,
4333 	.phylink_get_caps = mv88e6185_phylink_get_caps,
4334 	.set_max_frame_size = mv88e6185_g1_set_max_frame_size,
4335 };
4336 
4337 static const struct mv88e6xxx_ops mv88e6131_ops = {
4338 	/* MV88E6XXX_FAMILY_6185 */
4339 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4340 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4341 	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
4342 	.phy_read = mv88e6185_phy_ppu_read,
4343 	.phy_write = mv88e6185_phy_ppu_write,
4344 	.port_set_link = mv88e6xxx_port_set_link,
4345 	.port_sync_link = mv88e6xxx_port_sync_link,
4346 	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4347 	.port_tag_remap = mv88e6095_port_tag_remap,
4348 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4349 	.port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
4350 	.port_set_mcast_flood = mv88e6185_port_set_default_forward,
4351 	.port_set_ether_type = mv88e6351_port_set_ether_type,
4352 	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
4353 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4354 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4355 	.port_pause_limit = mv88e6097_port_pause_limit,
4356 	.port_set_pause = mv88e6185_port_set_pause,
4357 	.port_get_cmode = mv88e6185_port_get_cmode,
4358 	.port_setup_message_port = mv88e6xxx_setup_message_port,
4359 	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
4360 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4361 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
4362 	.stats_get_strings = mv88e6095_stats_get_strings,
4363 	.stats_get_stat = mv88e6095_stats_get_stat,
4364 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
4365 	.set_egress_port = mv88e6095_g1_set_egress_port,
4366 	.watchdog_ops = &mv88e6097_watchdog_ops,
4367 	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
4368 	.ppu_enable = mv88e6185_g1_ppu_enable,
4369 	.set_cascade_port = mv88e6185_g1_set_cascade_port,
4370 	.ppu_disable = mv88e6185_g1_ppu_disable,
4371 	.reset = mv88e6185_g1_reset,
4372 	.vtu_getnext = mv88e6185_g1_vtu_getnext,
4373 	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
4374 	.phylink_get_caps = mv88e6185_phylink_get_caps,
4375 };
4376 
4377 static const struct mv88e6xxx_ops mv88e6141_ops = {
4378 	/* MV88E6XXX_FAMILY_6341 */
4379 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4380 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4381 	.irl_init_all = mv88e6352_g2_irl_init_all,
4382 	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
4383 	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4384 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4385 	.phy_read = mv88e6xxx_g2_smi_phy_read_c22,
4386 	.phy_write = mv88e6xxx_g2_smi_phy_write_c22,
4387 	.phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45,
4388 	.phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45,
4389 	.port_set_link = mv88e6xxx_port_set_link,
4390 	.port_sync_link = mv88e6xxx_port_sync_link,
4391 	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4392 	.port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
4393 	.port_max_speed_mode = mv88e6341_port_max_speed_mode,
4394 	.port_tag_remap = mv88e6095_port_tag_remap,
4395 	.port_set_policy = mv88e6352_port_set_policy,
4396 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4397 	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4398 	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4399 	.port_set_ether_type = mv88e6351_port_set_ether_type,
4400 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4401 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4402 	.port_pause_limit = mv88e6097_port_pause_limit,
4403 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4404 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4405 	.port_get_cmode = mv88e6352_port_get_cmode,
4406 	.port_set_cmode = mv88e6341_port_set_cmode,
4407 	.port_setup_message_port = mv88e6xxx_setup_message_port,
4408 	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4409 	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4410 	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
4411 	.stats_get_strings = mv88e6320_stats_get_strings,
4412 	.stats_get_stat = mv88e6390_stats_get_stat,
4413 	.set_cpu_port = mv88e6390_g1_set_cpu_port,
4414 	.set_egress_port = mv88e6390_g1_set_egress_port,
4415 	.watchdog_ops = &mv88e6390_watchdog_ops,
4416 	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
4417 	.pot_clear = mv88e6xxx_g2_pot_clear,
4418 	.hardware_reset_pre = mv88e6xxx_g2_eeprom_wait,
4419 	.hardware_reset_post = mv88e6xxx_g2_eeprom_wait,
4420 	.reset = mv88e6352_g1_reset,
4421 	.rmu_disable = mv88e6390_g1_rmu_disable,
4422 	.atu_get_hash = mv88e6165_g1_atu_get_hash,
4423 	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4424 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4425 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4426 	.stu_getnext = mv88e6352_g1_stu_getnext,
4427 	.stu_loadpurge = mv88e6352_g1_stu_loadpurge,
4428 	.serdes_get_lane = mv88e6341_serdes_get_lane,
4429 	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4430 	.gpio_ops = &mv88e6352_gpio_ops,
4431 	.serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4432 	.serdes_get_strings = mv88e6390_serdes_get_strings,
4433 	.serdes_get_stats = mv88e6390_serdes_get_stats,
4434 	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4435 	.serdes_get_regs = mv88e6390_serdes_get_regs,
4436 	.phylink_get_caps = mv88e6341_phylink_get_caps,
4437 	.pcs_ops = &mv88e6390_pcs_ops,
4438 };
4439 
4440 static const struct mv88e6xxx_ops mv88e6161_ops = {
4441 	/* MV88E6XXX_FAMILY_6165 */
4442 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4443 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4444 	.irl_init_all = mv88e6352_g2_irl_init_all,
4445 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4446 	.phy_read = mv88e6xxx_g2_smi_phy_read_c22,
4447 	.phy_write = mv88e6xxx_g2_smi_phy_write_c22,
4448 	.phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45,
4449 	.phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45,
4450 	.port_set_link = mv88e6xxx_port_set_link,
4451 	.port_sync_link = mv88e6xxx_port_sync_link,
4452 	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4453 	.port_tag_remap = mv88e6095_port_tag_remap,
4454 	.port_set_policy = mv88e6352_port_set_policy,
4455 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4456 	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4457 	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4458 	.port_set_ether_type = mv88e6351_port_set_ether_type,
4459 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4460 	.port_pause_limit = mv88e6097_port_pause_limit,
4461 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4462 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4463 	.port_get_cmode = mv88e6185_port_get_cmode,
4464 	.port_setup_message_port = mv88e6xxx_setup_message_port,
4465 	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
4466 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4467 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
4468 	.stats_get_strings = mv88e6095_stats_get_strings,
4469 	.stats_get_stat = mv88e6095_stats_get_stat,
4470 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
4471 	.set_egress_port = mv88e6095_g1_set_egress_port,
4472 	.watchdog_ops = &mv88e6097_watchdog_ops,
4473 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4474 	.pot_clear = mv88e6xxx_g2_pot_clear,
4475 	.reset = mv88e6352_g1_reset,
4476 	.atu_get_hash = mv88e6165_g1_atu_get_hash,
4477 	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4478 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4479 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4480 	.stu_getnext = mv88e6352_g1_stu_getnext,
4481 	.stu_loadpurge = mv88e6352_g1_stu_loadpurge,
4482 	.avb_ops = &mv88e6165_avb_ops,
4483 	.ptp_ops = &mv88e6165_ptp_ops,
4484 	.phylink_get_caps = mv88e6185_phylink_get_caps,
4485 	.set_max_frame_size = mv88e6185_g1_set_max_frame_size,
4486 };
4487 
4488 static const struct mv88e6xxx_ops mv88e6165_ops = {
4489 	/* MV88E6XXX_FAMILY_6165 */
4490 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4491 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4492 	.irl_init_all = mv88e6352_g2_irl_init_all,
4493 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4494 	.phy_read = mv88e6165_phy_read,
4495 	.phy_write = mv88e6165_phy_write,
4496 	.port_set_link = mv88e6xxx_port_set_link,
4497 	.port_sync_link = mv88e6xxx_port_sync_link,
4498 	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4499 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4500 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4501 	.port_get_cmode = mv88e6185_port_get_cmode,
4502 	.port_setup_message_port = mv88e6xxx_setup_message_port,
4503 	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
4504 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4505 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
4506 	.stats_get_strings = mv88e6095_stats_get_strings,
4507 	.stats_get_stat = mv88e6095_stats_get_stat,
4508 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
4509 	.set_egress_port = mv88e6095_g1_set_egress_port,
4510 	.watchdog_ops = &mv88e6097_watchdog_ops,
4511 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4512 	.pot_clear = mv88e6xxx_g2_pot_clear,
4513 	.reset = mv88e6352_g1_reset,
4514 	.atu_get_hash = mv88e6165_g1_atu_get_hash,
4515 	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4516 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4517 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4518 	.stu_getnext = mv88e6352_g1_stu_getnext,
4519 	.stu_loadpurge = mv88e6352_g1_stu_loadpurge,
4520 	.avb_ops = &mv88e6165_avb_ops,
4521 	.ptp_ops = &mv88e6165_ptp_ops,
4522 	.phylink_get_caps = mv88e6185_phylink_get_caps,
4523 };
4524 
4525 static const struct mv88e6xxx_ops mv88e6171_ops = {
4526 	/* MV88E6XXX_FAMILY_6351 */
4527 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4528 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4529 	.irl_init_all = mv88e6352_g2_irl_init_all,
4530 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4531 	.phy_read = mv88e6xxx_g2_smi_phy_read_c22,
4532 	.phy_write = mv88e6xxx_g2_smi_phy_write_c22,
4533 	.phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45,
4534 	.phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45,
4535 	.port_set_link = mv88e6xxx_port_set_link,
4536 	.port_sync_link = mv88e6xxx_port_sync_link,
4537 	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4538 	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4539 	.port_tag_remap = mv88e6095_port_tag_remap,
4540 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4541 	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4542 	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4543 	.port_set_ether_type = mv88e6351_port_set_ether_type,
4544 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4545 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4546 	.port_pause_limit = mv88e6097_port_pause_limit,
4547 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4548 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4549 	.port_get_cmode = mv88e6352_port_get_cmode,
4550 	.port_setup_message_port = mv88e6xxx_setup_message_port,
4551 	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4552 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4553 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
4554 	.stats_get_strings = mv88e6095_stats_get_strings,
4555 	.stats_get_stat = mv88e6095_stats_get_stat,
4556 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
4557 	.set_egress_port = mv88e6095_g1_set_egress_port,
4558 	.watchdog_ops = &mv88e6097_watchdog_ops,
4559 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4560 	.pot_clear = mv88e6xxx_g2_pot_clear,
4561 	.reset = mv88e6352_g1_reset,
4562 	.atu_get_hash = mv88e6165_g1_atu_get_hash,
4563 	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4564 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4565 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4566 	.stu_getnext = mv88e6352_g1_stu_getnext,
4567 	.stu_loadpurge = mv88e6352_g1_stu_loadpurge,
4568 	.phylink_get_caps = mv88e6351_phylink_get_caps,
4569 };
4570 
4571 static const struct mv88e6xxx_ops mv88e6172_ops = {
4572 	/* MV88E6XXX_FAMILY_6352 */
4573 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4574 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4575 	.irl_init_all = mv88e6352_g2_irl_init_all,
4576 	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
4577 	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
4578 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4579 	.phy_read = mv88e6xxx_g2_smi_phy_read_c22,
4580 	.phy_write = mv88e6xxx_g2_smi_phy_write_c22,
4581 	.phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45,
4582 	.phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45,
4583 	.port_set_link = mv88e6xxx_port_set_link,
4584 	.port_sync_link = mv88e6xxx_port_sync_link,
4585 	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4586 	.port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
4587 	.port_tag_remap = mv88e6095_port_tag_remap,
4588 	.port_set_policy = mv88e6352_port_set_policy,
4589 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4590 	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4591 	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4592 	.port_set_ether_type = mv88e6351_port_set_ether_type,
4593 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4594 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4595 	.port_pause_limit = mv88e6097_port_pause_limit,
4596 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4597 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4598 	.port_get_cmode = mv88e6352_port_get_cmode,
4599 	.port_setup_message_port = mv88e6xxx_setup_message_port,
4600 	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4601 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4602 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
4603 	.stats_get_strings = mv88e6095_stats_get_strings,
4604 	.stats_get_stat = mv88e6095_stats_get_stat,
4605 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
4606 	.set_egress_port = mv88e6095_g1_set_egress_port,
4607 	.watchdog_ops = &mv88e6097_watchdog_ops,
4608 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4609 	.pot_clear = mv88e6xxx_g2_pot_clear,
4610 	.hardware_reset_pre = mv88e6xxx_g2_eeprom_wait,
4611 	.hardware_reset_post = mv88e6xxx_g2_eeprom_wait,
4612 	.reset = mv88e6352_g1_reset,
4613 	.rmu_disable = mv88e6352_g1_rmu_disable,
4614 	.atu_get_hash = mv88e6165_g1_atu_get_hash,
4615 	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4616 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4617 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4618 	.stu_getnext = mv88e6352_g1_stu_getnext,
4619 	.stu_loadpurge = mv88e6352_g1_stu_loadpurge,
4620 	.serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4621 	.serdes_get_regs = mv88e6352_serdes_get_regs,
4622 	.gpio_ops = &mv88e6352_gpio_ops,
4623 	.phylink_get_caps = mv88e6352_phylink_get_caps,
4624 	.pcs_ops = &mv88e6352_pcs_ops,
4625 };
4626 
4627 static const struct mv88e6xxx_ops mv88e6175_ops = {
4628 	/* MV88E6XXX_FAMILY_6351 */
4629 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4630 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4631 	.irl_init_all = mv88e6352_g2_irl_init_all,
4632 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4633 	.phy_read = mv88e6xxx_g2_smi_phy_read_c22,
4634 	.phy_write = mv88e6xxx_g2_smi_phy_write_c22,
4635 	.phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45,
4636 	.phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45,
4637 	.port_set_link = mv88e6xxx_port_set_link,
4638 	.port_sync_link = mv88e6xxx_port_sync_link,
4639 	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4640 	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4641 	.port_tag_remap = mv88e6095_port_tag_remap,
4642 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4643 	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4644 	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4645 	.port_set_ether_type = mv88e6351_port_set_ether_type,
4646 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4647 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4648 	.port_pause_limit = mv88e6097_port_pause_limit,
4649 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4650 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4651 	.port_get_cmode = mv88e6352_port_get_cmode,
4652 	.port_setup_message_port = mv88e6xxx_setup_message_port,
4653 	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4654 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4655 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
4656 	.stats_get_strings = mv88e6095_stats_get_strings,
4657 	.stats_get_stat = mv88e6095_stats_get_stat,
4658 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
4659 	.set_egress_port = mv88e6095_g1_set_egress_port,
4660 	.watchdog_ops = &mv88e6097_watchdog_ops,
4661 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4662 	.pot_clear = mv88e6xxx_g2_pot_clear,
4663 	.reset = mv88e6352_g1_reset,
4664 	.atu_get_hash = mv88e6165_g1_atu_get_hash,
4665 	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4666 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4667 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4668 	.stu_getnext = mv88e6352_g1_stu_getnext,
4669 	.stu_loadpurge = mv88e6352_g1_stu_loadpurge,
4670 	.phylink_get_caps = mv88e6351_phylink_get_caps,
4671 };
4672 
4673 static const struct mv88e6xxx_ops mv88e6176_ops = {
4674 	/* MV88E6XXX_FAMILY_6352 */
4675 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4676 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4677 	.irl_init_all = mv88e6352_g2_irl_init_all,
4678 	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
4679 	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
4680 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4681 	.phy_read = mv88e6xxx_g2_smi_phy_read_c22,
4682 	.phy_write = mv88e6xxx_g2_smi_phy_write_c22,
4683 	.phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45,
4684 	.phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45,
4685 	.port_set_link = mv88e6xxx_port_set_link,
4686 	.port_sync_link = mv88e6xxx_port_sync_link,
4687 	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4688 	.port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
4689 	.port_tag_remap = mv88e6095_port_tag_remap,
4690 	.port_set_policy = mv88e6352_port_set_policy,
4691 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4692 	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4693 	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4694 	.port_set_ether_type = mv88e6351_port_set_ether_type,
4695 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4696 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4697 	.port_pause_limit = mv88e6097_port_pause_limit,
4698 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4699 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4700 	.port_get_cmode = mv88e6352_port_get_cmode,
4701 	.port_setup_message_port = mv88e6xxx_setup_message_port,
4702 	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4703 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4704 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
4705 	.stats_get_strings = mv88e6095_stats_get_strings,
4706 	.stats_get_stat = mv88e6095_stats_get_stat,
4707 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
4708 	.set_egress_port = mv88e6095_g1_set_egress_port,
4709 	.watchdog_ops = &mv88e6097_watchdog_ops,
4710 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4711 	.pot_clear = mv88e6xxx_g2_pot_clear,
4712 	.hardware_reset_pre = mv88e6xxx_g2_eeprom_wait,
4713 	.hardware_reset_post = mv88e6xxx_g2_eeprom_wait,
4714 	.reset = mv88e6352_g1_reset,
4715 	.rmu_disable = mv88e6352_g1_rmu_disable,
4716 	.atu_get_hash = mv88e6165_g1_atu_get_hash,
4717 	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4718 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4719 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4720 	.stu_getnext = mv88e6352_g1_stu_getnext,
4721 	.stu_loadpurge = mv88e6352_g1_stu_loadpurge,
4722 	.serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
4723 	.serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4724 	.serdes_get_regs = mv88e6352_serdes_get_regs,
4725 	.serdes_set_tx_amplitude = mv88e6352_serdes_set_tx_amplitude,
4726 	.gpio_ops = &mv88e6352_gpio_ops,
4727 	.phylink_get_caps = mv88e6352_phylink_get_caps,
4728 	.pcs_ops = &mv88e6352_pcs_ops,
4729 };
4730 
4731 static const struct mv88e6xxx_ops mv88e6185_ops = {
4732 	/* MV88E6XXX_FAMILY_6185 */
4733 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4734 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4735 	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
4736 	.phy_read = mv88e6185_phy_ppu_read,
4737 	.phy_write = mv88e6185_phy_ppu_write,
4738 	.port_set_link = mv88e6xxx_port_set_link,
4739 	.port_sync_link = mv88e6185_port_sync_link,
4740 	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4741 	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
4742 	.port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
4743 	.port_set_mcast_flood = mv88e6185_port_set_default_forward,
4744 	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
4745 	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
4746 	.port_set_pause = mv88e6185_port_set_pause,
4747 	.port_get_cmode = mv88e6185_port_get_cmode,
4748 	.port_setup_message_port = mv88e6xxx_setup_message_port,
4749 	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
4750 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4751 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
4752 	.stats_get_strings = mv88e6095_stats_get_strings,
4753 	.stats_get_stat = mv88e6095_stats_get_stat,
4754 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
4755 	.set_egress_port = mv88e6095_g1_set_egress_port,
4756 	.watchdog_ops = &mv88e6097_watchdog_ops,
4757 	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
4758 	.set_cascade_port = mv88e6185_g1_set_cascade_port,
4759 	.ppu_enable = mv88e6185_g1_ppu_enable,
4760 	.ppu_disable = mv88e6185_g1_ppu_disable,
4761 	.reset = mv88e6185_g1_reset,
4762 	.vtu_getnext = mv88e6185_g1_vtu_getnext,
4763 	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
4764 	.phylink_get_caps = mv88e6185_phylink_get_caps,
4765 	.pcs_ops = &mv88e6185_pcs_ops,
4766 	.set_max_frame_size = mv88e6185_g1_set_max_frame_size,
4767 };
4768 
4769 static const struct mv88e6xxx_ops mv88e6190_ops = {
4770 	/* MV88E6XXX_FAMILY_6390 */
4771 	.setup_errata = mv88e6390_setup_errata,
4772 	.irl_init_all = mv88e6390_g2_irl_init_all,
4773 	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
4774 	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4775 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4776 	.phy_read = mv88e6xxx_g2_smi_phy_read_c22,
4777 	.phy_write = mv88e6xxx_g2_smi_phy_write_c22,
4778 	.phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45,
4779 	.phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45,
4780 	.port_set_link = mv88e6xxx_port_set_link,
4781 	.port_sync_link = mv88e6xxx_port_sync_link,
4782 	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4783 	.port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
4784 	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
4785 	.port_tag_remap = mv88e6390_port_tag_remap,
4786 	.port_set_policy = mv88e6352_port_set_policy,
4787 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4788 	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4789 	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4790 	.port_set_ether_type = mv88e6351_port_set_ether_type,
4791 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4792 	.port_pause_limit = mv88e6390_port_pause_limit,
4793 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4794 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4795 	.port_get_cmode = mv88e6352_port_get_cmode,
4796 	.port_set_cmode = mv88e6390_port_set_cmode,
4797 	.port_setup_message_port = mv88e6xxx_setup_message_port,
4798 	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4799 	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4800 	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
4801 	.stats_get_strings = mv88e6320_stats_get_strings,
4802 	.stats_get_stat = mv88e6390_stats_get_stat,
4803 	.set_cpu_port = mv88e6390_g1_set_cpu_port,
4804 	.set_egress_port = mv88e6390_g1_set_egress_port,
4805 	.watchdog_ops = &mv88e6390_watchdog_ops,
4806 	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4807 	.pot_clear = mv88e6xxx_g2_pot_clear,
4808 	.hardware_reset_pre = mv88e6xxx_g2_eeprom_wait,
4809 	.hardware_reset_post = mv88e6xxx_g2_eeprom_wait,
4810 	.reset = mv88e6352_g1_reset,
4811 	.rmu_disable = mv88e6390_g1_rmu_disable,
4812 	.atu_get_hash = mv88e6165_g1_atu_get_hash,
4813 	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4814 	.vtu_getnext = mv88e6390_g1_vtu_getnext,
4815 	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4816 	.stu_getnext = mv88e6390_g1_stu_getnext,
4817 	.stu_loadpurge = mv88e6390_g1_stu_loadpurge,
4818 	.serdes_get_lane = mv88e6390_serdes_get_lane,
4819 	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4820 	.serdes_get_strings = mv88e6390_serdes_get_strings,
4821 	.serdes_get_stats = mv88e6390_serdes_get_stats,
4822 	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4823 	.serdes_get_regs = mv88e6390_serdes_get_regs,
4824 	.gpio_ops = &mv88e6352_gpio_ops,
4825 	.phylink_get_caps = mv88e6390_phylink_get_caps,
4826 	.pcs_ops = &mv88e6390_pcs_ops,
4827 };
4828 
4829 static const struct mv88e6xxx_ops mv88e6190x_ops = {
4830 	/* MV88E6XXX_FAMILY_6390 */
4831 	.setup_errata = mv88e6390_setup_errata,
4832 	.irl_init_all = mv88e6390_g2_irl_init_all,
4833 	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
4834 	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4835 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4836 	.phy_read = mv88e6xxx_g2_smi_phy_read_c22,
4837 	.phy_write = mv88e6xxx_g2_smi_phy_write_c22,
4838 	.phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45,
4839 	.phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45,
4840 	.port_set_link = mv88e6xxx_port_set_link,
4841 	.port_sync_link = mv88e6xxx_port_sync_link,
4842 	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4843 	.port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
4844 	.port_max_speed_mode = mv88e6390x_port_max_speed_mode,
4845 	.port_tag_remap = mv88e6390_port_tag_remap,
4846 	.port_set_policy = mv88e6352_port_set_policy,
4847 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4848 	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4849 	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4850 	.port_set_ether_type = mv88e6351_port_set_ether_type,
4851 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4852 	.port_pause_limit = mv88e6390_port_pause_limit,
4853 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4854 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4855 	.port_get_cmode = mv88e6352_port_get_cmode,
4856 	.port_set_cmode = mv88e6390x_port_set_cmode,
4857 	.port_setup_message_port = mv88e6xxx_setup_message_port,
4858 	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4859 	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4860 	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
4861 	.stats_get_strings = mv88e6320_stats_get_strings,
4862 	.stats_get_stat = mv88e6390_stats_get_stat,
4863 	.set_cpu_port = mv88e6390_g1_set_cpu_port,
4864 	.set_egress_port = mv88e6390_g1_set_egress_port,
4865 	.watchdog_ops = &mv88e6390_watchdog_ops,
4866 	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4867 	.pot_clear = mv88e6xxx_g2_pot_clear,
4868 	.hardware_reset_pre = mv88e6xxx_g2_eeprom_wait,
4869 	.hardware_reset_post = mv88e6xxx_g2_eeprom_wait,
4870 	.reset = mv88e6352_g1_reset,
4871 	.rmu_disable = mv88e6390_g1_rmu_disable,
4872 	.atu_get_hash = mv88e6165_g1_atu_get_hash,
4873 	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4874 	.vtu_getnext = mv88e6390_g1_vtu_getnext,
4875 	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4876 	.stu_getnext = mv88e6390_g1_stu_getnext,
4877 	.stu_loadpurge = mv88e6390_g1_stu_loadpurge,
4878 	.serdes_get_lane = mv88e6390x_serdes_get_lane,
4879 	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4880 	.serdes_get_strings = mv88e6390_serdes_get_strings,
4881 	.serdes_get_stats = mv88e6390_serdes_get_stats,
4882 	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4883 	.serdes_get_regs = mv88e6390_serdes_get_regs,
4884 	.gpio_ops = &mv88e6352_gpio_ops,
4885 	.phylink_get_caps = mv88e6390x_phylink_get_caps,
4886 	.pcs_ops = &mv88e6390_pcs_ops,
4887 };
4888 
4889 static const struct mv88e6xxx_ops mv88e6191_ops = {
4890 	/* MV88E6XXX_FAMILY_6390 */
4891 	.setup_errata = mv88e6390_setup_errata,
4892 	.irl_init_all = mv88e6390_g2_irl_init_all,
4893 	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
4894 	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4895 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4896 	.phy_read = mv88e6xxx_g2_smi_phy_read_c22,
4897 	.phy_write = mv88e6xxx_g2_smi_phy_write_c22,
4898 	.phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45,
4899 	.phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45,
4900 	.port_set_link = mv88e6xxx_port_set_link,
4901 	.port_sync_link = mv88e6xxx_port_sync_link,
4902 	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4903 	.port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
4904 	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
4905 	.port_tag_remap = mv88e6390_port_tag_remap,
4906 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4907 	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4908 	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4909 	.port_set_ether_type = mv88e6351_port_set_ether_type,
4910 	.port_pause_limit = mv88e6390_port_pause_limit,
4911 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4912 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4913 	.port_get_cmode = mv88e6352_port_get_cmode,
4914 	.port_set_cmode = mv88e6390_port_set_cmode,
4915 	.port_setup_message_port = mv88e6xxx_setup_message_port,
4916 	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4917 	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4918 	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
4919 	.stats_get_strings = mv88e6320_stats_get_strings,
4920 	.stats_get_stat = mv88e6390_stats_get_stat,
4921 	.set_cpu_port = mv88e6390_g1_set_cpu_port,
4922 	.set_egress_port = mv88e6390_g1_set_egress_port,
4923 	.watchdog_ops = &mv88e6390_watchdog_ops,
4924 	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4925 	.pot_clear = mv88e6xxx_g2_pot_clear,
4926 	.hardware_reset_pre = mv88e6xxx_g2_eeprom_wait,
4927 	.hardware_reset_post = mv88e6xxx_g2_eeprom_wait,
4928 	.reset = mv88e6352_g1_reset,
4929 	.rmu_disable = mv88e6390_g1_rmu_disable,
4930 	.atu_get_hash = mv88e6165_g1_atu_get_hash,
4931 	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4932 	.vtu_getnext = mv88e6390_g1_vtu_getnext,
4933 	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4934 	.stu_getnext = mv88e6390_g1_stu_getnext,
4935 	.stu_loadpurge = mv88e6390_g1_stu_loadpurge,
4936 	.serdes_get_lane = mv88e6390_serdes_get_lane,
4937 	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4938 	.serdes_get_strings = mv88e6390_serdes_get_strings,
4939 	.serdes_get_stats = mv88e6390_serdes_get_stats,
4940 	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4941 	.serdes_get_regs = mv88e6390_serdes_get_regs,
4942 	.avb_ops = &mv88e6390_avb_ops,
4943 	.ptp_ops = &mv88e6352_ptp_ops,
4944 	.phylink_get_caps = mv88e6390_phylink_get_caps,
4945 	.pcs_ops = &mv88e6390_pcs_ops,
4946 };
4947 
4948 static const struct mv88e6xxx_ops mv88e6240_ops = {
4949 	/* MV88E6XXX_FAMILY_6352 */
4950 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4951 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4952 	.irl_init_all = mv88e6352_g2_irl_init_all,
4953 	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
4954 	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
4955 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4956 	.phy_read = mv88e6xxx_g2_smi_phy_read_c22,
4957 	.phy_write = mv88e6xxx_g2_smi_phy_write_c22,
4958 	.phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45,
4959 	.phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45,
4960 	.port_set_link = mv88e6xxx_port_set_link,
4961 	.port_sync_link = mv88e6xxx_port_sync_link,
4962 	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4963 	.port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
4964 	.port_tag_remap = mv88e6095_port_tag_remap,
4965 	.port_set_policy = mv88e6352_port_set_policy,
4966 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4967 	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4968 	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4969 	.port_set_ether_type = mv88e6351_port_set_ether_type,
4970 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4971 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4972 	.port_pause_limit = mv88e6097_port_pause_limit,
4973 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4974 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4975 	.port_get_cmode = mv88e6352_port_get_cmode,
4976 	.port_setup_message_port = mv88e6xxx_setup_message_port,
4977 	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4978 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4979 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
4980 	.stats_get_strings = mv88e6095_stats_get_strings,
4981 	.stats_get_stat = mv88e6095_stats_get_stat,
4982 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
4983 	.set_egress_port = mv88e6095_g1_set_egress_port,
4984 	.watchdog_ops = &mv88e6097_watchdog_ops,
4985 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4986 	.pot_clear = mv88e6xxx_g2_pot_clear,
4987 	.hardware_reset_pre = mv88e6xxx_g2_eeprom_wait,
4988 	.hardware_reset_post = mv88e6xxx_g2_eeprom_wait,
4989 	.reset = mv88e6352_g1_reset,
4990 	.rmu_disable = mv88e6352_g1_rmu_disable,
4991 	.atu_get_hash = mv88e6165_g1_atu_get_hash,
4992 	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4993 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4994 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4995 	.stu_getnext = mv88e6352_g1_stu_getnext,
4996 	.stu_loadpurge = mv88e6352_g1_stu_loadpurge,
4997 	.serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
4998 	.serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4999 	.serdes_get_regs = mv88e6352_serdes_get_regs,
5000 	.serdes_set_tx_amplitude = mv88e6352_serdes_set_tx_amplitude,
5001 	.gpio_ops = &mv88e6352_gpio_ops,
5002 	.avb_ops = &mv88e6352_avb_ops,
5003 	.ptp_ops = &mv88e6352_ptp_ops,
5004 	.phylink_get_caps = mv88e6352_phylink_get_caps,
5005 	.pcs_ops = &mv88e6352_pcs_ops,
5006 };
5007 
5008 static const struct mv88e6xxx_ops mv88e6250_ops = {
5009 	/* MV88E6XXX_FAMILY_6250 */
5010 	.ieee_pri_map = mv88e6250_g1_ieee_pri_map,
5011 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
5012 	.irl_init_all = mv88e6352_g2_irl_init_all,
5013 	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
5014 	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
5015 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
5016 	.phy_read = mv88e6xxx_g2_smi_phy_read_c22,
5017 	.phy_write = mv88e6xxx_g2_smi_phy_write_c22,
5018 	.phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45,
5019 	.phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45,
5020 	.port_set_link = mv88e6xxx_port_set_link,
5021 	.port_sync_link = mv88e6xxx_port_sync_link,
5022 	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
5023 	.port_set_speed_duplex = mv88e6250_port_set_speed_duplex,
5024 	.port_tag_remap = mv88e6095_port_tag_remap,
5025 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
5026 	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
5027 	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
5028 	.port_set_ether_type = mv88e6351_port_set_ether_type,
5029 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
5030 	.port_pause_limit = mv88e6097_port_pause_limit,
5031 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
5032 	.stats_snapshot = mv88e6320_g1_stats_snapshot,
5033 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
5034 	.stats_get_sset_count = mv88e6250_stats_get_sset_count,
5035 	.stats_get_strings = mv88e6250_stats_get_strings,
5036 	.stats_get_stat = mv88e6250_stats_get_stat,
5037 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
5038 	.set_egress_port = mv88e6095_g1_set_egress_port,
5039 	.watchdog_ops = &mv88e6250_watchdog_ops,
5040 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
5041 	.pot_clear = mv88e6xxx_g2_pot_clear,
5042 	.hardware_reset_pre = mv88e6250_g1_wait_eeprom_done_prereset,
5043 	.hardware_reset_post = mv88e6xxx_g1_wait_eeprom_done,
5044 	.reset = mv88e6250_g1_reset,
5045 	.vtu_getnext = mv88e6185_g1_vtu_getnext,
5046 	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
5047 	.avb_ops = &mv88e6352_avb_ops,
5048 	.ptp_ops = &mv88e6250_ptp_ops,
5049 	.phylink_get_caps = mv88e6250_phylink_get_caps,
5050 	.set_max_frame_size = mv88e6185_g1_set_max_frame_size,
5051 };
5052 
5053 static const struct mv88e6xxx_ops mv88e6290_ops = {
5054 	/* MV88E6XXX_FAMILY_6390 */
5055 	.setup_errata = mv88e6390_setup_errata,
5056 	.irl_init_all = mv88e6390_g2_irl_init_all,
5057 	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
5058 	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
5059 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
5060 	.phy_read = mv88e6xxx_g2_smi_phy_read_c22,
5061 	.phy_write = mv88e6xxx_g2_smi_phy_write_c22,
5062 	.phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45,
5063 	.phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45,
5064 	.port_set_link = mv88e6xxx_port_set_link,
5065 	.port_sync_link = mv88e6xxx_port_sync_link,
5066 	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
5067 	.port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
5068 	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
5069 	.port_tag_remap = mv88e6390_port_tag_remap,
5070 	.port_set_policy = mv88e6352_port_set_policy,
5071 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
5072 	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
5073 	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
5074 	.port_set_ether_type = mv88e6351_port_set_ether_type,
5075 	.port_pause_limit = mv88e6390_port_pause_limit,
5076 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
5077 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
5078 	.port_get_cmode = mv88e6352_port_get_cmode,
5079 	.port_set_cmode = mv88e6390_port_set_cmode,
5080 	.port_setup_message_port = mv88e6xxx_setup_message_port,
5081 	.stats_snapshot = mv88e6390_g1_stats_snapshot,
5082 	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
5083 	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
5084 	.stats_get_strings = mv88e6320_stats_get_strings,
5085 	.stats_get_stat = mv88e6390_stats_get_stat,
5086 	.set_cpu_port = mv88e6390_g1_set_cpu_port,
5087 	.set_egress_port = mv88e6390_g1_set_egress_port,
5088 	.watchdog_ops = &mv88e6390_watchdog_ops,
5089 	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
5090 	.pot_clear = mv88e6xxx_g2_pot_clear,
5091 	.hardware_reset_pre = mv88e6xxx_g2_eeprom_wait,
5092 	.hardware_reset_post = mv88e6xxx_g2_eeprom_wait,
5093 	.reset = mv88e6352_g1_reset,
5094 	.rmu_disable = mv88e6390_g1_rmu_disable,
5095 	.atu_get_hash = mv88e6165_g1_atu_get_hash,
5096 	.atu_set_hash = mv88e6165_g1_atu_set_hash,
5097 	.vtu_getnext = mv88e6390_g1_vtu_getnext,
5098 	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
5099 	.stu_getnext = mv88e6390_g1_stu_getnext,
5100 	.stu_loadpurge = mv88e6390_g1_stu_loadpurge,
5101 	.serdes_get_lane = mv88e6390_serdes_get_lane,
5102 	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
5103 	.serdes_get_strings = mv88e6390_serdes_get_strings,
5104 	.serdes_get_stats = mv88e6390_serdes_get_stats,
5105 	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
5106 	.serdes_get_regs = mv88e6390_serdes_get_regs,
5107 	.gpio_ops = &mv88e6352_gpio_ops,
5108 	.avb_ops = &mv88e6390_avb_ops,
5109 	.ptp_ops = &mv88e6390_ptp_ops,
5110 	.phylink_get_caps = mv88e6390_phylink_get_caps,
5111 	.pcs_ops = &mv88e6390_pcs_ops,
5112 };
5113 
5114 static const struct mv88e6xxx_ops mv88e6320_ops = {
5115 	/* MV88E6XXX_FAMILY_6320 */
5116 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
5117 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
5118 	.irl_init_all = mv88e6352_g2_irl_init_all,
5119 	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
5120 	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
5121 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
5122 	.phy_read = mv88e6xxx_g2_smi_phy_read_c22,
5123 	.phy_write = mv88e6xxx_g2_smi_phy_write_c22,
5124 	.phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45,
5125 	.phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45,
5126 	.port_set_link = mv88e6xxx_port_set_link,
5127 	.port_sync_link = mv88e6xxx_port_sync_link,
5128 	.port_set_rgmii_delay = mv88e6320_port_set_rgmii_delay,
5129 	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
5130 	.port_tag_remap = mv88e6095_port_tag_remap,
5131 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
5132 	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
5133 	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
5134 	.port_set_ether_type = mv88e6351_port_set_ether_type,
5135 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
5136 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
5137 	.port_pause_limit = mv88e6097_port_pause_limit,
5138 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
5139 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
5140 	.port_get_cmode = mv88e6352_port_get_cmode,
5141 	.port_setup_message_port = mv88e6xxx_setup_message_port,
5142 	.stats_snapshot = mv88e6320_g1_stats_snapshot,
5143 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
5144 	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
5145 	.stats_get_strings = mv88e6320_stats_get_strings,
5146 	.stats_get_stat = mv88e6320_stats_get_stat,
5147 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
5148 	.set_egress_port = mv88e6095_g1_set_egress_port,
5149 	.watchdog_ops = &mv88e6390_watchdog_ops,
5150 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
5151 	.pot_clear = mv88e6xxx_g2_pot_clear,
5152 	.hardware_reset_pre = mv88e6xxx_g2_eeprom_wait,
5153 	.hardware_reset_post = mv88e6xxx_g2_eeprom_wait,
5154 	.reset = mv88e6352_g1_reset,
5155 	.vtu_getnext = mv88e6185_g1_vtu_getnext,
5156 	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
5157 	.gpio_ops = &mv88e6352_gpio_ops,
5158 	.avb_ops = &mv88e6352_avb_ops,
5159 	.ptp_ops = &mv88e6352_ptp_ops,
5160 	.phylink_get_caps = mv88e632x_phylink_get_caps,
5161 };
5162 
5163 static const struct mv88e6xxx_ops mv88e6321_ops = {
5164 	/* MV88E6XXX_FAMILY_6320 */
5165 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
5166 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
5167 	.irl_init_all = mv88e6352_g2_irl_init_all,
5168 	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
5169 	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
5170 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
5171 	.phy_read = mv88e6xxx_g2_smi_phy_read_c22,
5172 	.phy_write = mv88e6xxx_g2_smi_phy_write_c22,
5173 	.phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45,
5174 	.phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45,
5175 	.port_set_link = mv88e6xxx_port_set_link,
5176 	.port_sync_link = mv88e6xxx_port_sync_link,
5177 	.port_set_rgmii_delay = mv88e6320_port_set_rgmii_delay,
5178 	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
5179 	.port_tag_remap = mv88e6095_port_tag_remap,
5180 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
5181 	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
5182 	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
5183 	.port_set_ether_type = mv88e6351_port_set_ether_type,
5184 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
5185 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
5186 	.port_pause_limit = mv88e6097_port_pause_limit,
5187 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
5188 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
5189 	.port_get_cmode = mv88e6352_port_get_cmode,
5190 	.port_setup_message_port = mv88e6xxx_setup_message_port,
5191 	.stats_snapshot = mv88e6320_g1_stats_snapshot,
5192 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
5193 	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
5194 	.stats_get_strings = mv88e6320_stats_get_strings,
5195 	.stats_get_stat = mv88e6320_stats_get_stat,
5196 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
5197 	.set_egress_port = mv88e6095_g1_set_egress_port,
5198 	.watchdog_ops = &mv88e6390_watchdog_ops,
5199 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
5200 	.hardware_reset_pre = mv88e6xxx_g2_eeprom_wait,
5201 	.hardware_reset_post = mv88e6xxx_g2_eeprom_wait,
5202 	.reset = mv88e6352_g1_reset,
5203 	.vtu_getnext = mv88e6185_g1_vtu_getnext,
5204 	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
5205 	.gpio_ops = &mv88e6352_gpio_ops,
5206 	.avb_ops = &mv88e6352_avb_ops,
5207 	.ptp_ops = &mv88e6352_ptp_ops,
5208 	.phylink_get_caps = mv88e632x_phylink_get_caps,
5209 };
5210 
5211 static const struct mv88e6xxx_ops mv88e6341_ops = {
5212 	/* MV88E6XXX_FAMILY_6341 */
5213 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
5214 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
5215 	.irl_init_all = mv88e6352_g2_irl_init_all,
5216 	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
5217 	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
5218 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
5219 	.phy_read = mv88e6xxx_g2_smi_phy_read_c22,
5220 	.phy_write = mv88e6xxx_g2_smi_phy_write_c22,
5221 	.phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45,
5222 	.phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45,
5223 	.port_set_link = mv88e6xxx_port_set_link,
5224 	.port_sync_link = mv88e6xxx_port_sync_link,
5225 	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
5226 	.port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
5227 	.port_max_speed_mode = mv88e6341_port_max_speed_mode,
5228 	.port_tag_remap = mv88e6095_port_tag_remap,
5229 	.port_set_policy = mv88e6352_port_set_policy,
5230 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
5231 	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
5232 	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
5233 	.port_set_ether_type = mv88e6351_port_set_ether_type,
5234 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
5235 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
5236 	.port_pause_limit = mv88e6097_port_pause_limit,
5237 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
5238 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
5239 	.port_get_cmode = mv88e6352_port_get_cmode,
5240 	.port_set_cmode = mv88e6341_port_set_cmode,
5241 	.port_setup_message_port = mv88e6xxx_setup_message_port,
5242 	.stats_snapshot = mv88e6390_g1_stats_snapshot,
5243 	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
5244 	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
5245 	.stats_get_strings = mv88e6320_stats_get_strings,
5246 	.stats_get_stat = mv88e6390_stats_get_stat,
5247 	.set_cpu_port = mv88e6390_g1_set_cpu_port,
5248 	.set_egress_port = mv88e6390_g1_set_egress_port,
5249 	.watchdog_ops = &mv88e6390_watchdog_ops,
5250 	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
5251 	.pot_clear = mv88e6xxx_g2_pot_clear,
5252 	.hardware_reset_pre = mv88e6xxx_g2_eeprom_wait,
5253 	.hardware_reset_post = mv88e6xxx_g2_eeprom_wait,
5254 	.reset = mv88e6352_g1_reset,
5255 	.rmu_disable = mv88e6390_g1_rmu_disable,
5256 	.atu_get_hash = mv88e6165_g1_atu_get_hash,
5257 	.atu_set_hash = mv88e6165_g1_atu_set_hash,
5258 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
5259 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
5260 	.stu_getnext = mv88e6352_g1_stu_getnext,
5261 	.stu_loadpurge = mv88e6352_g1_stu_loadpurge,
5262 	.serdes_get_lane = mv88e6341_serdes_get_lane,
5263 	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
5264 	.gpio_ops = &mv88e6352_gpio_ops,
5265 	.avb_ops = &mv88e6390_avb_ops,
5266 	.ptp_ops = &mv88e6352_ptp_ops,
5267 	.serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
5268 	.serdes_get_strings = mv88e6390_serdes_get_strings,
5269 	.serdes_get_stats = mv88e6390_serdes_get_stats,
5270 	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
5271 	.serdes_get_regs = mv88e6390_serdes_get_regs,
5272 	.phylink_get_caps = mv88e6341_phylink_get_caps,
5273 	.pcs_ops = &mv88e6390_pcs_ops,
5274 };
5275 
5276 static const struct mv88e6xxx_ops mv88e6350_ops = {
5277 	/* MV88E6XXX_FAMILY_6351 */
5278 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
5279 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
5280 	.irl_init_all = mv88e6352_g2_irl_init_all,
5281 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
5282 	.phy_read = mv88e6xxx_g2_smi_phy_read_c22,
5283 	.phy_write = mv88e6xxx_g2_smi_phy_write_c22,
5284 	.phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45,
5285 	.phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45,
5286 	.port_set_link = mv88e6xxx_port_set_link,
5287 	.port_sync_link = mv88e6xxx_port_sync_link,
5288 	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
5289 	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
5290 	.port_tag_remap = mv88e6095_port_tag_remap,
5291 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
5292 	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
5293 	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
5294 	.port_set_ether_type = mv88e6351_port_set_ether_type,
5295 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
5296 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
5297 	.port_pause_limit = mv88e6097_port_pause_limit,
5298 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
5299 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
5300 	.port_get_cmode = mv88e6352_port_get_cmode,
5301 	.port_setup_message_port = mv88e6xxx_setup_message_port,
5302 	.stats_snapshot = mv88e6320_g1_stats_snapshot,
5303 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
5304 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
5305 	.stats_get_strings = mv88e6095_stats_get_strings,
5306 	.stats_get_stat = mv88e6095_stats_get_stat,
5307 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
5308 	.set_egress_port = mv88e6095_g1_set_egress_port,
5309 	.watchdog_ops = &mv88e6097_watchdog_ops,
5310 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
5311 	.pot_clear = mv88e6xxx_g2_pot_clear,
5312 	.reset = mv88e6352_g1_reset,
5313 	.atu_get_hash = mv88e6165_g1_atu_get_hash,
5314 	.atu_set_hash = mv88e6165_g1_atu_set_hash,
5315 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
5316 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
5317 	.stu_getnext = mv88e6352_g1_stu_getnext,
5318 	.stu_loadpurge = mv88e6352_g1_stu_loadpurge,
5319 	.phylink_get_caps = mv88e6351_phylink_get_caps,
5320 };
5321 
5322 static const struct mv88e6xxx_ops mv88e6351_ops = {
5323 	/* MV88E6XXX_FAMILY_6351 */
5324 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
5325 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
5326 	.irl_init_all = mv88e6352_g2_irl_init_all,
5327 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
5328 	.phy_read = mv88e6xxx_g2_smi_phy_read_c22,
5329 	.phy_write = mv88e6xxx_g2_smi_phy_write_c22,
5330 	.phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45,
5331 	.phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45,
5332 	.port_set_link = mv88e6xxx_port_set_link,
5333 	.port_sync_link = mv88e6xxx_port_sync_link,
5334 	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
5335 	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
5336 	.port_tag_remap = mv88e6095_port_tag_remap,
5337 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
5338 	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
5339 	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
5340 	.port_set_ether_type = mv88e6351_port_set_ether_type,
5341 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
5342 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
5343 	.port_pause_limit = mv88e6097_port_pause_limit,
5344 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
5345 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
5346 	.port_get_cmode = mv88e6352_port_get_cmode,
5347 	.port_setup_message_port = mv88e6xxx_setup_message_port,
5348 	.stats_snapshot = mv88e6320_g1_stats_snapshot,
5349 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
5350 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
5351 	.stats_get_strings = mv88e6095_stats_get_strings,
5352 	.stats_get_stat = mv88e6095_stats_get_stat,
5353 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
5354 	.set_egress_port = mv88e6095_g1_set_egress_port,
5355 	.watchdog_ops = &mv88e6097_watchdog_ops,
5356 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
5357 	.pot_clear = mv88e6xxx_g2_pot_clear,
5358 	.reset = mv88e6352_g1_reset,
5359 	.atu_get_hash = mv88e6165_g1_atu_get_hash,
5360 	.atu_set_hash = mv88e6165_g1_atu_set_hash,
5361 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
5362 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
5363 	.stu_getnext = mv88e6352_g1_stu_getnext,
5364 	.stu_loadpurge = mv88e6352_g1_stu_loadpurge,
5365 	.avb_ops = &mv88e6352_avb_ops,
5366 	.ptp_ops = &mv88e6352_ptp_ops,
5367 	.phylink_get_caps = mv88e6351_phylink_get_caps,
5368 };
5369 
5370 static const struct mv88e6xxx_ops mv88e6352_ops = {
5371 	/* MV88E6XXX_FAMILY_6352 */
5372 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
5373 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
5374 	.irl_init_all = mv88e6352_g2_irl_init_all,
5375 	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
5376 	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
5377 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
5378 	.phy_read = mv88e6xxx_g2_smi_phy_read_c22,
5379 	.phy_write = mv88e6xxx_g2_smi_phy_write_c22,
5380 	.phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45,
5381 	.phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45,
5382 	.port_set_link = mv88e6xxx_port_set_link,
5383 	.port_sync_link = mv88e6xxx_port_sync_link,
5384 	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
5385 	.port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
5386 	.port_tag_remap = mv88e6095_port_tag_remap,
5387 	.port_set_policy = mv88e6352_port_set_policy,
5388 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
5389 	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
5390 	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
5391 	.port_set_ether_type = mv88e6351_port_set_ether_type,
5392 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
5393 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
5394 	.port_pause_limit = mv88e6097_port_pause_limit,
5395 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
5396 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
5397 	.port_get_cmode = mv88e6352_port_get_cmode,
5398 	.port_setup_message_port = mv88e6xxx_setup_message_port,
5399 	.stats_snapshot = mv88e6320_g1_stats_snapshot,
5400 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
5401 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
5402 	.stats_get_strings = mv88e6095_stats_get_strings,
5403 	.stats_get_stat = mv88e6095_stats_get_stat,
5404 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
5405 	.set_egress_port = mv88e6095_g1_set_egress_port,
5406 	.watchdog_ops = &mv88e6097_watchdog_ops,
5407 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
5408 	.pot_clear = mv88e6xxx_g2_pot_clear,
5409 	.hardware_reset_pre = mv88e6xxx_g2_eeprom_wait,
5410 	.hardware_reset_post = mv88e6xxx_g2_eeprom_wait,
5411 	.reset = mv88e6352_g1_reset,
5412 	.rmu_disable = mv88e6352_g1_rmu_disable,
5413 	.atu_get_hash = mv88e6165_g1_atu_get_hash,
5414 	.atu_set_hash = mv88e6165_g1_atu_set_hash,
5415 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
5416 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
5417 	.stu_getnext = mv88e6352_g1_stu_getnext,
5418 	.stu_loadpurge = mv88e6352_g1_stu_loadpurge,
5419 	.serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
5420 	.gpio_ops = &mv88e6352_gpio_ops,
5421 	.avb_ops = &mv88e6352_avb_ops,
5422 	.ptp_ops = &mv88e6352_ptp_ops,
5423 	.serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
5424 	.serdes_get_strings = mv88e6352_serdes_get_strings,
5425 	.serdes_get_stats = mv88e6352_serdes_get_stats,
5426 	.serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
5427 	.serdes_get_regs = mv88e6352_serdes_get_regs,
5428 	.serdes_set_tx_amplitude = mv88e6352_serdes_set_tx_amplitude,
5429 	.phylink_get_caps = mv88e6352_phylink_get_caps,
5430 	.pcs_ops = &mv88e6352_pcs_ops,
5431 };
5432 
5433 static const struct mv88e6xxx_ops mv88e6390_ops = {
5434 	/* MV88E6XXX_FAMILY_6390 */
5435 	.setup_errata = mv88e6390_setup_errata,
5436 	.irl_init_all = mv88e6390_g2_irl_init_all,
5437 	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
5438 	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
5439 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
5440 	.phy_read = mv88e6xxx_g2_smi_phy_read_c22,
5441 	.phy_write = mv88e6xxx_g2_smi_phy_write_c22,
5442 	.phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45,
5443 	.phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45,
5444 	.port_set_link = mv88e6xxx_port_set_link,
5445 	.port_sync_link = mv88e6xxx_port_sync_link,
5446 	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
5447 	.port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
5448 	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
5449 	.port_tag_remap = mv88e6390_port_tag_remap,
5450 	.port_set_policy = mv88e6352_port_set_policy,
5451 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
5452 	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
5453 	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
5454 	.port_set_ether_type = mv88e6351_port_set_ether_type,
5455 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
5456 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
5457 	.port_pause_limit = mv88e6390_port_pause_limit,
5458 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
5459 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
5460 	.port_get_cmode = mv88e6352_port_get_cmode,
5461 	.port_set_cmode = mv88e6390_port_set_cmode,
5462 	.port_setup_message_port = mv88e6xxx_setup_message_port,
5463 	.stats_snapshot = mv88e6390_g1_stats_snapshot,
5464 	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
5465 	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
5466 	.stats_get_strings = mv88e6320_stats_get_strings,
5467 	.stats_get_stat = mv88e6390_stats_get_stat,
5468 	.set_cpu_port = mv88e6390_g1_set_cpu_port,
5469 	.set_egress_port = mv88e6390_g1_set_egress_port,
5470 	.watchdog_ops = &mv88e6390_watchdog_ops,
5471 	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
5472 	.pot_clear = mv88e6xxx_g2_pot_clear,
5473 	.hardware_reset_pre = mv88e6xxx_g2_eeprom_wait,
5474 	.hardware_reset_post = mv88e6xxx_g2_eeprom_wait,
5475 	.reset = mv88e6352_g1_reset,
5476 	.rmu_disable = mv88e6390_g1_rmu_disable,
5477 	.atu_get_hash = mv88e6165_g1_atu_get_hash,
5478 	.atu_set_hash = mv88e6165_g1_atu_set_hash,
5479 	.vtu_getnext = mv88e6390_g1_vtu_getnext,
5480 	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
5481 	.stu_getnext = mv88e6390_g1_stu_getnext,
5482 	.stu_loadpurge = mv88e6390_g1_stu_loadpurge,
5483 	.serdes_get_lane = mv88e6390_serdes_get_lane,
5484 	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
5485 	.gpio_ops = &mv88e6352_gpio_ops,
5486 	.avb_ops = &mv88e6390_avb_ops,
5487 	.ptp_ops = &mv88e6390_ptp_ops,
5488 	.serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
5489 	.serdes_get_strings = mv88e6390_serdes_get_strings,
5490 	.serdes_get_stats = mv88e6390_serdes_get_stats,
5491 	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
5492 	.serdes_get_regs = mv88e6390_serdes_get_regs,
5493 	.phylink_get_caps = mv88e6390_phylink_get_caps,
5494 	.pcs_ops = &mv88e6390_pcs_ops,
5495 };
5496 
5497 static const struct mv88e6xxx_ops mv88e6390x_ops = {
5498 	/* MV88E6XXX_FAMILY_6390 */
5499 	.setup_errata = mv88e6390_setup_errata,
5500 	.irl_init_all = mv88e6390_g2_irl_init_all,
5501 	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
5502 	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
5503 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
5504 	.phy_read = mv88e6xxx_g2_smi_phy_read_c22,
5505 	.phy_write = mv88e6xxx_g2_smi_phy_write_c22,
5506 	.phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45,
5507 	.phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45,
5508 	.port_set_link = mv88e6xxx_port_set_link,
5509 	.port_sync_link = mv88e6xxx_port_sync_link,
5510 	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
5511 	.port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
5512 	.port_max_speed_mode = mv88e6390x_port_max_speed_mode,
5513 	.port_tag_remap = mv88e6390_port_tag_remap,
5514 	.port_set_policy = mv88e6352_port_set_policy,
5515 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
5516 	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
5517 	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
5518 	.port_set_ether_type = mv88e6351_port_set_ether_type,
5519 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
5520 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
5521 	.port_pause_limit = mv88e6390_port_pause_limit,
5522 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
5523 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
5524 	.port_get_cmode = mv88e6352_port_get_cmode,
5525 	.port_set_cmode = mv88e6390x_port_set_cmode,
5526 	.port_setup_message_port = mv88e6xxx_setup_message_port,
5527 	.stats_snapshot = mv88e6390_g1_stats_snapshot,
5528 	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
5529 	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
5530 	.stats_get_strings = mv88e6320_stats_get_strings,
5531 	.stats_get_stat = mv88e6390_stats_get_stat,
5532 	.set_cpu_port = mv88e6390_g1_set_cpu_port,
5533 	.set_egress_port = mv88e6390_g1_set_egress_port,
5534 	.watchdog_ops = &mv88e6390_watchdog_ops,
5535 	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
5536 	.pot_clear = mv88e6xxx_g2_pot_clear,
5537 	.hardware_reset_pre = mv88e6xxx_g2_eeprom_wait,
5538 	.hardware_reset_post = mv88e6xxx_g2_eeprom_wait,
5539 	.reset = mv88e6352_g1_reset,
5540 	.rmu_disable = mv88e6390_g1_rmu_disable,
5541 	.atu_get_hash = mv88e6165_g1_atu_get_hash,
5542 	.atu_set_hash = mv88e6165_g1_atu_set_hash,
5543 	.vtu_getnext = mv88e6390_g1_vtu_getnext,
5544 	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
5545 	.stu_getnext = mv88e6390_g1_stu_getnext,
5546 	.stu_loadpurge = mv88e6390_g1_stu_loadpurge,
5547 	.serdes_get_lane = mv88e6390x_serdes_get_lane,
5548 	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
5549 	.serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
5550 	.serdes_get_strings = mv88e6390_serdes_get_strings,
5551 	.serdes_get_stats = mv88e6390_serdes_get_stats,
5552 	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
5553 	.serdes_get_regs = mv88e6390_serdes_get_regs,
5554 	.gpio_ops = &mv88e6352_gpio_ops,
5555 	.avb_ops = &mv88e6390_avb_ops,
5556 	.ptp_ops = &mv88e6390_ptp_ops,
5557 	.phylink_get_caps = mv88e6390x_phylink_get_caps,
5558 	.pcs_ops = &mv88e6390_pcs_ops,
5559 };
5560 
5561 static const struct mv88e6xxx_ops mv88e6393x_ops = {
5562 	/* MV88E6XXX_FAMILY_6393 */
5563 	.irl_init_all = mv88e6390_g2_irl_init_all,
5564 	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
5565 	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
5566 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
5567 	.phy_read = mv88e6xxx_g2_smi_phy_read_c22,
5568 	.phy_write = mv88e6xxx_g2_smi_phy_write_c22,
5569 	.phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45,
5570 	.phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45,
5571 	.port_set_link = mv88e6xxx_port_set_link,
5572 	.port_sync_link = mv88e6xxx_port_sync_link,
5573 	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
5574 	.port_set_speed_duplex = mv88e6393x_port_set_speed_duplex,
5575 	.port_max_speed_mode = mv88e6393x_port_max_speed_mode,
5576 	.port_tag_remap = mv88e6390_port_tag_remap,
5577 	.port_set_policy = mv88e6393x_port_set_policy,
5578 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
5579 	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
5580 	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
5581 	.port_set_ether_type = mv88e6393x_port_set_ether_type,
5582 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
5583 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
5584 	.port_pause_limit = mv88e6390_port_pause_limit,
5585 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
5586 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
5587 	.port_get_cmode = mv88e6352_port_get_cmode,
5588 	.port_set_cmode = mv88e6393x_port_set_cmode,
5589 	.port_setup_message_port = mv88e6xxx_setup_message_port,
5590 	.port_set_upstream_port = mv88e6393x_port_set_upstream_port,
5591 	.stats_snapshot = mv88e6390_g1_stats_snapshot,
5592 	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
5593 	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
5594 	.stats_get_strings = mv88e6320_stats_get_strings,
5595 	.stats_get_stat = mv88e6390_stats_get_stat,
5596 	/* .set_cpu_port is missing because this family does not support a global
5597 	 * CPU port, only per port CPU port which is set via
5598 	 * .port_set_upstream_port method.
5599 	 */
5600 	.set_egress_port = mv88e6393x_set_egress_port,
5601 	.watchdog_ops = &mv88e6393x_watchdog_ops,
5602 	.mgmt_rsvd2cpu = mv88e6393x_port_mgmt_rsvd2cpu,
5603 	.pot_clear = mv88e6xxx_g2_pot_clear,
5604 	.hardware_reset_pre = mv88e6xxx_g2_eeprom_wait,
5605 	.hardware_reset_post = mv88e6xxx_g2_eeprom_wait,
5606 	.reset = mv88e6352_g1_reset,
5607 	.rmu_disable = mv88e6390_g1_rmu_disable,
5608 	.atu_get_hash = mv88e6165_g1_atu_get_hash,
5609 	.atu_set_hash = mv88e6165_g1_atu_set_hash,
5610 	.vtu_getnext = mv88e6390_g1_vtu_getnext,
5611 	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
5612 	.stu_getnext = mv88e6390_g1_stu_getnext,
5613 	.stu_loadpurge = mv88e6390_g1_stu_loadpurge,
5614 	.serdes_get_lane = mv88e6393x_serdes_get_lane,
5615 	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
5616 	/* TODO: serdes stats */
5617 	.gpio_ops = &mv88e6352_gpio_ops,
5618 	.avb_ops = &mv88e6390_avb_ops,
5619 	.ptp_ops = &mv88e6352_ptp_ops,
5620 	.phylink_get_caps = mv88e6393x_phylink_get_caps,
5621 	.pcs_ops = &mv88e6393x_pcs_ops,
5622 };
5623 
5624 static const struct mv88e6xxx_info mv88e6xxx_table[] = {
5625 	[MV88E6020] = {
5626 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6020,
5627 		.family = MV88E6XXX_FAMILY_6250,
5628 		.name = "Marvell 88E6020",
5629 		.num_databases = 64,
5630 		/* Ports 2-4 are not routed to pins
5631 		 * => usable ports 0, 1, 5, 6
5632 		 */
5633 		.num_ports = 7,
5634 		.num_internal_phys = 2,
5635 		.invalid_port_mask = BIT(2) | BIT(3) | BIT(4),
5636 		.max_vid = 4095,
5637 		.port_base_addr = 0x8,
5638 		.phy_base_addr = 0x0,
5639 		.global1_addr = 0xf,
5640 		.global2_addr = 0x7,
5641 		.age_time_coeff = 15000,
5642 		.g1_irqs = 9,
5643 		.g2_irqs = 5,
5644 		.atu_move_port_mask = 0xf,
5645 		.dual_chip = true,
5646 		.ops = &mv88e6250_ops,
5647 	},
5648 
5649 	[MV88E6071] = {
5650 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6071,
5651 		.family = MV88E6XXX_FAMILY_6250,
5652 		.name = "Marvell 88E6071",
5653 		.num_databases = 64,
5654 		.num_ports = 7,
5655 		.num_internal_phys = 5,
5656 		.max_vid = 4095,
5657 		.port_base_addr = 0x08,
5658 		.phy_base_addr = 0x00,
5659 		.global1_addr = 0x0f,
5660 		.global2_addr = 0x07,
5661 		.age_time_coeff = 15000,
5662 		.g1_irqs = 9,
5663 		.g2_irqs = 5,
5664 		.atu_move_port_mask = 0xf,
5665 		.dual_chip = true,
5666 		.ops = &mv88e6250_ops,
5667 	},
5668 
5669 	[MV88E6085] = {
5670 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
5671 		.family = MV88E6XXX_FAMILY_6097,
5672 		.name = "Marvell 88E6085",
5673 		.num_databases = 4096,
5674 		.num_macs = 8192,
5675 		.num_ports = 10,
5676 		.num_internal_phys = 5,
5677 		.max_vid = 4095,
5678 		.max_sid = 63,
5679 		.port_base_addr = 0x10,
5680 		.phy_base_addr = 0x0,
5681 		.global1_addr = 0x1b,
5682 		.global2_addr = 0x1c,
5683 		.age_time_coeff = 15000,
5684 		.g1_irqs = 8,
5685 		.g2_irqs = 10,
5686 		.atu_move_port_mask = 0xf,
5687 		.pvt = true,
5688 		.multi_chip = true,
5689 		.ops = &mv88e6085_ops,
5690 	},
5691 
5692 	[MV88E6095] = {
5693 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
5694 		.family = MV88E6XXX_FAMILY_6095,
5695 		.name = "Marvell 88E6095/88E6095F",
5696 		.num_databases = 256,
5697 		.num_macs = 8192,
5698 		.num_ports = 11,
5699 		.num_internal_phys = 0,
5700 		.max_vid = 4095,
5701 		.port_base_addr = 0x10,
5702 		.phy_base_addr = 0x0,
5703 		.global1_addr = 0x1b,
5704 		.global2_addr = 0x1c,
5705 		.age_time_coeff = 15000,
5706 		.g1_irqs = 8,
5707 		.atu_move_port_mask = 0xf,
5708 		.multi_chip = true,
5709 		.ops = &mv88e6095_ops,
5710 	},
5711 
5712 	[MV88E6097] = {
5713 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
5714 		.family = MV88E6XXX_FAMILY_6097,
5715 		.name = "Marvell 88E6097/88E6097F",
5716 		.num_databases = 4096,
5717 		.num_macs = 8192,
5718 		.num_ports = 11,
5719 		.num_internal_phys = 8,
5720 		.max_vid = 4095,
5721 		.max_sid = 63,
5722 		.port_base_addr = 0x10,
5723 		.phy_base_addr = 0x0,
5724 		.global1_addr = 0x1b,
5725 		.global2_addr = 0x1c,
5726 		.age_time_coeff = 15000,
5727 		.g1_irqs = 8,
5728 		.g2_irqs = 10,
5729 		.atu_move_port_mask = 0xf,
5730 		.pvt = true,
5731 		.multi_chip = true,
5732 		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5733 		.ops = &mv88e6097_ops,
5734 	},
5735 
5736 	[MV88E6123] = {
5737 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
5738 		.family = MV88E6XXX_FAMILY_6165,
5739 		.name = "Marvell 88E6123",
5740 		.num_databases = 4096,
5741 		.num_macs = 1024,
5742 		.num_ports = 3,
5743 		.num_internal_phys = 5,
5744 		.max_vid = 4095,
5745 		.max_sid = 63,
5746 		.port_base_addr = 0x10,
5747 		.phy_base_addr = 0x0,
5748 		.global1_addr = 0x1b,
5749 		.global2_addr = 0x1c,
5750 		.age_time_coeff = 15000,
5751 		.g1_irqs = 9,
5752 		.g2_irqs = 10,
5753 		.atu_move_port_mask = 0xf,
5754 		.pvt = true,
5755 		.multi_chip = true,
5756 		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5757 		.ops = &mv88e6123_ops,
5758 	},
5759 
5760 	[MV88E6131] = {
5761 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
5762 		.family = MV88E6XXX_FAMILY_6185,
5763 		.name = "Marvell 88E6131",
5764 		.num_databases = 256,
5765 		.num_macs = 8192,
5766 		.num_ports = 8,
5767 		.num_internal_phys = 0,
5768 		.max_vid = 4095,
5769 		.port_base_addr = 0x10,
5770 		.phy_base_addr = 0x0,
5771 		.global1_addr = 0x1b,
5772 		.global2_addr = 0x1c,
5773 		.age_time_coeff = 15000,
5774 		.g1_irqs = 9,
5775 		.atu_move_port_mask = 0xf,
5776 		.multi_chip = true,
5777 		.ops = &mv88e6131_ops,
5778 	},
5779 
5780 	[MV88E6141] = {
5781 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
5782 		.family = MV88E6XXX_FAMILY_6341,
5783 		.name = "Marvell 88E6141",
5784 		.num_databases = 256,
5785 		.num_macs = 2048,
5786 		.num_ports = 6,
5787 		.num_internal_phys = 5,
5788 		.num_gpio = 11,
5789 		.max_vid = 4095,
5790 		.max_sid = 63,
5791 		.port_base_addr = 0x10,
5792 		.phy_base_addr = 0x10,
5793 		.global1_addr = 0x1b,
5794 		.global2_addr = 0x1c,
5795 		.age_time_coeff = 3750,
5796 		.atu_move_port_mask = 0x1f,
5797 		.g1_irqs = 9,
5798 		.g2_irqs = 10,
5799 		.pvt = true,
5800 		.multi_chip = true,
5801 		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5802 		.ops = &mv88e6141_ops,
5803 	},
5804 
5805 	[MV88E6161] = {
5806 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
5807 		.family = MV88E6XXX_FAMILY_6165,
5808 		.name = "Marvell 88E6161",
5809 		.num_databases = 4096,
5810 		.num_macs = 1024,
5811 		.num_ports = 6,
5812 		.num_internal_phys = 5,
5813 		.max_vid = 4095,
5814 		.max_sid = 63,
5815 		.port_base_addr = 0x10,
5816 		.phy_base_addr = 0x0,
5817 		.global1_addr = 0x1b,
5818 		.global2_addr = 0x1c,
5819 		.age_time_coeff = 15000,
5820 		.g1_irqs = 9,
5821 		.g2_irqs = 10,
5822 		.atu_move_port_mask = 0xf,
5823 		.pvt = true,
5824 		.multi_chip = true,
5825 		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5826 		.ptp_support = true,
5827 		.ops = &mv88e6161_ops,
5828 	},
5829 
5830 	[MV88E6165] = {
5831 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
5832 		.family = MV88E6XXX_FAMILY_6165,
5833 		.name = "Marvell 88E6165",
5834 		.num_databases = 4096,
5835 		.num_macs = 8192,
5836 		.num_ports = 6,
5837 		.num_internal_phys = 0,
5838 		.max_vid = 4095,
5839 		.max_sid = 63,
5840 		.port_base_addr = 0x10,
5841 		.phy_base_addr = 0x0,
5842 		.global1_addr = 0x1b,
5843 		.global2_addr = 0x1c,
5844 		.age_time_coeff = 15000,
5845 		.g1_irqs = 9,
5846 		.g2_irqs = 10,
5847 		.atu_move_port_mask = 0xf,
5848 		.pvt = true,
5849 		.multi_chip = true,
5850 		.ptp_support = true,
5851 		.ops = &mv88e6165_ops,
5852 	},
5853 
5854 	[MV88E6171] = {
5855 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
5856 		.family = MV88E6XXX_FAMILY_6351,
5857 		.name = "Marvell 88E6171",
5858 		.num_databases = 4096,
5859 		.num_macs = 8192,
5860 		.num_ports = 7,
5861 		.num_internal_phys = 5,
5862 		.max_vid = 4095,
5863 		.max_sid = 63,
5864 		.port_base_addr = 0x10,
5865 		.phy_base_addr = 0x0,
5866 		.global1_addr = 0x1b,
5867 		.global2_addr = 0x1c,
5868 		.age_time_coeff = 15000,
5869 		.g1_irqs = 9,
5870 		.g2_irqs = 10,
5871 		.atu_move_port_mask = 0xf,
5872 		.pvt = true,
5873 		.multi_chip = true,
5874 		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5875 		.ops = &mv88e6171_ops,
5876 	},
5877 
5878 	[MV88E6172] = {
5879 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
5880 		.family = MV88E6XXX_FAMILY_6352,
5881 		.name = "Marvell 88E6172",
5882 		.num_databases = 4096,
5883 		.num_macs = 8192,
5884 		.num_ports = 7,
5885 		.num_internal_phys = 5,
5886 		.num_gpio = 15,
5887 		.max_vid = 4095,
5888 		.max_sid = 63,
5889 		.port_base_addr = 0x10,
5890 		.phy_base_addr = 0x0,
5891 		.global1_addr = 0x1b,
5892 		.global2_addr = 0x1c,
5893 		.age_time_coeff = 15000,
5894 		.g1_irqs = 9,
5895 		.g2_irqs = 10,
5896 		.atu_move_port_mask = 0xf,
5897 		.pvt = true,
5898 		.multi_chip = true,
5899 		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5900 		.ops = &mv88e6172_ops,
5901 	},
5902 
5903 	[MV88E6175] = {
5904 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
5905 		.family = MV88E6XXX_FAMILY_6351,
5906 		.name = "Marvell 88E6175",
5907 		.num_databases = 4096,
5908 		.num_macs = 8192,
5909 		.num_ports = 7,
5910 		.num_internal_phys = 5,
5911 		.max_vid = 4095,
5912 		.max_sid = 63,
5913 		.port_base_addr = 0x10,
5914 		.phy_base_addr = 0x0,
5915 		.global1_addr = 0x1b,
5916 		.global2_addr = 0x1c,
5917 		.age_time_coeff = 15000,
5918 		.g1_irqs = 9,
5919 		.g2_irqs = 10,
5920 		.atu_move_port_mask = 0xf,
5921 		.pvt = true,
5922 		.multi_chip = true,
5923 		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5924 		.ops = &mv88e6175_ops,
5925 	},
5926 
5927 	[MV88E6176] = {
5928 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
5929 		.family = MV88E6XXX_FAMILY_6352,
5930 		.name = "Marvell 88E6176",
5931 		.num_databases = 4096,
5932 		.num_macs = 8192,
5933 		.num_ports = 7,
5934 		.num_internal_phys = 5,
5935 		.num_gpio = 15,
5936 		.max_vid = 4095,
5937 		.max_sid = 63,
5938 		.port_base_addr = 0x10,
5939 		.phy_base_addr = 0x0,
5940 		.global1_addr = 0x1b,
5941 		.global2_addr = 0x1c,
5942 		.age_time_coeff = 15000,
5943 		.g1_irqs = 9,
5944 		.g2_irqs = 10,
5945 		.atu_move_port_mask = 0xf,
5946 		.pvt = true,
5947 		.multi_chip = true,
5948 		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5949 		.ops = &mv88e6176_ops,
5950 	},
5951 
5952 	[MV88E6185] = {
5953 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
5954 		.family = MV88E6XXX_FAMILY_6185,
5955 		.name = "Marvell 88E6185",
5956 		.num_databases = 256,
5957 		.num_macs = 8192,
5958 		.num_ports = 10,
5959 		.num_internal_phys = 0,
5960 		.max_vid = 4095,
5961 		.port_base_addr = 0x10,
5962 		.phy_base_addr = 0x0,
5963 		.global1_addr = 0x1b,
5964 		.global2_addr = 0x1c,
5965 		.age_time_coeff = 15000,
5966 		.g1_irqs = 8,
5967 		.atu_move_port_mask = 0xf,
5968 		.multi_chip = true,
5969 		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5970 		.ops = &mv88e6185_ops,
5971 	},
5972 
5973 	[MV88E6190] = {
5974 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
5975 		.family = MV88E6XXX_FAMILY_6390,
5976 		.name = "Marvell 88E6190",
5977 		.num_databases = 4096,
5978 		.num_macs = 16384,
5979 		.num_ports = 11,	/* 10 + Z80 */
5980 		.num_internal_phys = 9,
5981 		.num_gpio = 16,
5982 		.max_vid = 8191,
5983 		.max_sid = 63,
5984 		.port_base_addr = 0x0,
5985 		.phy_base_addr = 0x0,
5986 		.global1_addr = 0x1b,
5987 		.global2_addr = 0x1c,
5988 		.age_time_coeff = 3750,
5989 		.g1_irqs = 9,
5990 		.g2_irqs = 14,
5991 		.pvt = true,
5992 		.multi_chip = true,
5993 		.atu_move_port_mask = 0x1f,
5994 		.ops = &mv88e6190_ops,
5995 	},
5996 
5997 	[MV88E6190X] = {
5998 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
5999 		.family = MV88E6XXX_FAMILY_6390,
6000 		.name = "Marvell 88E6190X",
6001 		.num_databases = 4096,
6002 		.num_macs = 16384,
6003 		.num_ports = 11,	/* 10 + Z80 */
6004 		.num_internal_phys = 9,
6005 		.num_gpio = 16,
6006 		.max_vid = 8191,
6007 		.max_sid = 63,
6008 		.port_base_addr = 0x0,
6009 		.phy_base_addr = 0x0,
6010 		.global1_addr = 0x1b,
6011 		.global2_addr = 0x1c,
6012 		.age_time_coeff = 3750,
6013 		.g1_irqs = 9,
6014 		.g2_irqs = 14,
6015 		.atu_move_port_mask = 0x1f,
6016 		.pvt = true,
6017 		.multi_chip = true,
6018 		.ops = &mv88e6190x_ops,
6019 	},
6020 
6021 	[MV88E6191] = {
6022 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
6023 		.family = MV88E6XXX_FAMILY_6390,
6024 		.name = "Marvell 88E6191",
6025 		.num_databases = 4096,
6026 		.num_macs = 16384,
6027 		.num_ports = 11,	/* 10 + Z80 */
6028 		.num_internal_phys = 9,
6029 		.max_vid = 8191,
6030 		.max_sid = 63,
6031 		.port_base_addr = 0x0,
6032 		.phy_base_addr = 0x0,
6033 		.global1_addr = 0x1b,
6034 		.global2_addr = 0x1c,
6035 		.age_time_coeff = 3750,
6036 		.g1_irqs = 9,
6037 		.g2_irqs = 14,
6038 		.atu_move_port_mask = 0x1f,
6039 		.pvt = true,
6040 		.multi_chip = true,
6041 		.ptp_support = true,
6042 		.ops = &mv88e6191_ops,
6043 	},
6044 
6045 	[MV88E6191X] = {
6046 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191X,
6047 		.family = MV88E6XXX_FAMILY_6393,
6048 		.name = "Marvell 88E6191X",
6049 		.num_databases = 4096,
6050 		.num_ports = 11,	/* 10 + Z80 */
6051 		.num_internal_phys = 8,
6052 		.internal_phys_offset = 1,
6053 		.max_vid = 8191,
6054 		.max_sid = 63,
6055 		.port_base_addr = 0x0,
6056 		.phy_base_addr = 0x0,
6057 		.global1_addr = 0x1b,
6058 		.global2_addr = 0x1c,
6059 		.age_time_coeff = 3750,
6060 		.g1_irqs = 10,
6061 		.g2_irqs = 14,
6062 		.atu_move_port_mask = 0x1f,
6063 		.pvt = true,
6064 		.multi_chip = true,
6065 		.ptp_support = true,
6066 		.ops = &mv88e6393x_ops,
6067 	},
6068 
6069 	[MV88E6193X] = {
6070 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6193X,
6071 		.family = MV88E6XXX_FAMILY_6393,
6072 		.name = "Marvell 88E6193X",
6073 		.num_databases = 4096,
6074 		.num_ports = 11,	/* 10 + Z80 */
6075 		.num_internal_phys = 8,
6076 		.internal_phys_offset = 1,
6077 		.max_vid = 8191,
6078 		.max_sid = 63,
6079 		.port_base_addr = 0x0,
6080 		.phy_base_addr = 0x0,
6081 		.global1_addr = 0x1b,
6082 		.global2_addr = 0x1c,
6083 		.age_time_coeff = 3750,
6084 		.g1_irqs = 10,
6085 		.g2_irqs = 14,
6086 		.atu_move_port_mask = 0x1f,
6087 		.pvt = true,
6088 		.multi_chip = true,
6089 		.ptp_support = true,
6090 		.ops = &mv88e6393x_ops,
6091 	},
6092 
6093 	[MV88E6220] = {
6094 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6220,
6095 		.family = MV88E6XXX_FAMILY_6250,
6096 		.name = "Marvell 88E6220",
6097 		.num_databases = 64,
6098 
6099 		/* Ports 2-4 are not routed to pins
6100 		 * => usable ports 0, 1, 5, 6
6101 		 */
6102 		.num_ports = 7,
6103 		.num_internal_phys = 2,
6104 		.invalid_port_mask = BIT(2) | BIT(3) | BIT(4),
6105 		.max_vid = 4095,
6106 		.port_base_addr = 0x08,
6107 		.phy_base_addr = 0x00,
6108 		.global1_addr = 0x0f,
6109 		.global2_addr = 0x07,
6110 		.age_time_coeff = 15000,
6111 		.g1_irqs = 9,
6112 		.g2_irqs = 10,
6113 		.atu_move_port_mask = 0xf,
6114 		.dual_chip = true,
6115 		.ptp_support = true,
6116 		.ops = &mv88e6250_ops,
6117 	},
6118 
6119 	[MV88E6240] = {
6120 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
6121 		.family = MV88E6XXX_FAMILY_6352,
6122 		.name = "Marvell 88E6240",
6123 		.num_databases = 4096,
6124 		.num_macs = 8192,
6125 		.num_ports = 7,
6126 		.num_internal_phys = 5,
6127 		.num_gpio = 15,
6128 		.max_vid = 4095,
6129 		.max_sid = 63,
6130 		.port_base_addr = 0x10,
6131 		.phy_base_addr = 0x0,
6132 		.global1_addr = 0x1b,
6133 		.global2_addr = 0x1c,
6134 		.age_time_coeff = 15000,
6135 		.g1_irqs = 9,
6136 		.g2_irqs = 10,
6137 		.atu_move_port_mask = 0xf,
6138 		.pvt = true,
6139 		.multi_chip = true,
6140 		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
6141 		.ptp_support = true,
6142 		.ops = &mv88e6240_ops,
6143 	},
6144 
6145 	[MV88E6250] = {
6146 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6250,
6147 		.family = MV88E6XXX_FAMILY_6250,
6148 		.name = "Marvell 88E6250",
6149 		.num_databases = 64,
6150 		.num_ports = 7,
6151 		.num_internal_phys = 5,
6152 		.max_vid = 4095,
6153 		.port_base_addr = 0x08,
6154 		.phy_base_addr = 0x00,
6155 		.global1_addr = 0x0f,
6156 		.global2_addr = 0x07,
6157 		.age_time_coeff = 15000,
6158 		.g1_irqs = 9,
6159 		.g2_irqs = 10,
6160 		.atu_move_port_mask = 0xf,
6161 		.dual_chip = true,
6162 		.ptp_support = true,
6163 		.ops = &mv88e6250_ops,
6164 	},
6165 
6166 	[MV88E6290] = {
6167 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
6168 		.family = MV88E6XXX_FAMILY_6390,
6169 		.name = "Marvell 88E6290",
6170 		.num_databases = 4096,
6171 		.num_ports = 11,	/* 10 + Z80 */
6172 		.num_internal_phys = 9,
6173 		.num_gpio = 16,
6174 		.max_vid = 8191,
6175 		.max_sid = 63,
6176 		.port_base_addr = 0x0,
6177 		.phy_base_addr = 0x0,
6178 		.global1_addr = 0x1b,
6179 		.global2_addr = 0x1c,
6180 		.age_time_coeff = 3750,
6181 		.g1_irqs = 9,
6182 		.g2_irqs = 14,
6183 		.atu_move_port_mask = 0x1f,
6184 		.pvt = true,
6185 		.multi_chip = true,
6186 		.ptp_support = true,
6187 		.ops = &mv88e6290_ops,
6188 	},
6189 
6190 	[MV88E6320] = {
6191 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
6192 		.family = MV88E6XXX_FAMILY_6320,
6193 		.name = "Marvell 88E6320",
6194 		.num_databases = 4096,
6195 		.num_macs = 8192,
6196 		.num_ports = 7,
6197 		.num_internal_phys = 5,
6198 		.num_gpio = 15,
6199 		.max_vid = 4095,
6200 		.port_base_addr = 0x10,
6201 		.phy_base_addr = 0x0,
6202 		.global1_addr = 0x1b,
6203 		.global2_addr = 0x1c,
6204 		.age_time_coeff = 15000,
6205 		.g1_irqs = 8,
6206 		.g2_irqs = 10,
6207 		.atu_move_port_mask = 0xf,
6208 		.pvt = true,
6209 		.multi_chip = true,
6210 		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
6211 		.ptp_support = true,
6212 		.ops = &mv88e6320_ops,
6213 	},
6214 
6215 	[MV88E6321] = {
6216 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
6217 		.family = MV88E6XXX_FAMILY_6320,
6218 		.name = "Marvell 88E6321",
6219 		.num_databases = 4096,
6220 		.num_macs = 8192,
6221 		.num_ports = 7,
6222 		.num_internal_phys = 5,
6223 		.num_gpio = 15,
6224 		.max_vid = 4095,
6225 		.port_base_addr = 0x10,
6226 		.phy_base_addr = 0x0,
6227 		.global1_addr = 0x1b,
6228 		.global2_addr = 0x1c,
6229 		.age_time_coeff = 15000,
6230 		.g1_irqs = 8,
6231 		.g2_irqs = 10,
6232 		.atu_move_port_mask = 0xf,
6233 		.multi_chip = true,
6234 		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
6235 		.ptp_support = true,
6236 		.ops = &mv88e6321_ops,
6237 	},
6238 
6239 	[MV88E6341] = {
6240 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
6241 		.family = MV88E6XXX_FAMILY_6341,
6242 		.name = "Marvell 88E6341",
6243 		.num_databases = 256,
6244 		.num_macs = 2048,
6245 		.num_internal_phys = 5,
6246 		.num_ports = 6,
6247 		.num_gpio = 11,
6248 		.max_vid = 4095,
6249 		.max_sid = 63,
6250 		.port_base_addr = 0x10,
6251 		.phy_base_addr = 0x10,
6252 		.global1_addr = 0x1b,
6253 		.global2_addr = 0x1c,
6254 		.age_time_coeff = 3750,
6255 		.atu_move_port_mask = 0x1f,
6256 		.g1_irqs = 9,
6257 		.g2_irqs = 10,
6258 		.pvt = true,
6259 		.multi_chip = true,
6260 		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
6261 		.ptp_support = true,
6262 		.ops = &mv88e6341_ops,
6263 	},
6264 
6265 	[MV88E6350] = {
6266 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
6267 		.family = MV88E6XXX_FAMILY_6351,
6268 		.name = "Marvell 88E6350",
6269 		.num_databases = 4096,
6270 		.num_macs = 8192,
6271 		.num_ports = 7,
6272 		.num_internal_phys = 5,
6273 		.max_vid = 4095,
6274 		.max_sid = 63,
6275 		.port_base_addr = 0x10,
6276 		.phy_base_addr = 0x0,
6277 		.global1_addr = 0x1b,
6278 		.global2_addr = 0x1c,
6279 		.age_time_coeff = 15000,
6280 		.g1_irqs = 9,
6281 		.g2_irqs = 10,
6282 		.atu_move_port_mask = 0xf,
6283 		.pvt = true,
6284 		.multi_chip = true,
6285 		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
6286 		.ops = &mv88e6350_ops,
6287 	},
6288 
6289 	[MV88E6351] = {
6290 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
6291 		.family = MV88E6XXX_FAMILY_6351,
6292 		.name = "Marvell 88E6351",
6293 		.num_databases = 4096,
6294 		.num_macs = 8192,
6295 		.num_ports = 7,
6296 		.num_internal_phys = 5,
6297 		.max_vid = 4095,
6298 		.max_sid = 63,
6299 		.port_base_addr = 0x10,
6300 		.phy_base_addr = 0x0,
6301 		.global1_addr = 0x1b,
6302 		.global2_addr = 0x1c,
6303 		.age_time_coeff = 15000,
6304 		.g1_irqs = 9,
6305 		.g2_irqs = 10,
6306 		.atu_move_port_mask = 0xf,
6307 		.pvt = true,
6308 		.multi_chip = true,
6309 		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
6310 		.ops = &mv88e6351_ops,
6311 	},
6312 
6313 	[MV88E6352] = {
6314 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
6315 		.family = MV88E6XXX_FAMILY_6352,
6316 		.name = "Marvell 88E6352",
6317 		.num_databases = 4096,
6318 		.num_macs = 8192,
6319 		.num_ports = 7,
6320 		.num_internal_phys = 5,
6321 		.num_gpio = 15,
6322 		.max_vid = 4095,
6323 		.max_sid = 63,
6324 		.port_base_addr = 0x10,
6325 		.phy_base_addr = 0x0,
6326 		.global1_addr = 0x1b,
6327 		.global2_addr = 0x1c,
6328 		.age_time_coeff = 15000,
6329 		.g1_irqs = 9,
6330 		.g2_irqs = 10,
6331 		.atu_move_port_mask = 0xf,
6332 		.pvt = true,
6333 		.multi_chip = true,
6334 		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
6335 		.ptp_support = true,
6336 		.ops = &mv88e6352_ops,
6337 	},
6338 	[MV88E6361] = {
6339 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6361,
6340 		.family = MV88E6XXX_FAMILY_6393,
6341 		.name = "Marvell 88E6361",
6342 		.num_databases = 4096,
6343 		.num_macs = 16384,
6344 		.num_ports = 11,
6345 		/* Ports 1, 2 and 8 are not routed */
6346 		.invalid_port_mask = BIT(1) | BIT(2) | BIT(8),
6347 		.num_internal_phys = 5,
6348 		.internal_phys_offset = 3,
6349 		.max_vid = 4095,
6350 		.max_sid = 63,
6351 		.port_base_addr = 0x0,
6352 		.phy_base_addr = 0x0,
6353 		.global1_addr = 0x1b,
6354 		.global2_addr = 0x1c,
6355 		.age_time_coeff = 3750,
6356 		.g1_irqs = 10,
6357 		.g2_irqs = 14,
6358 		.atu_move_port_mask = 0x1f,
6359 		.pvt = true,
6360 		.multi_chip = true,
6361 		.ptp_support = true,
6362 		.ops = &mv88e6393x_ops,
6363 	},
6364 	[MV88E6390] = {
6365 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
6366 		.family = MV88E6XXX_FAMILY_6390,
6367 		.name = "Marvell 88E6390",
6368 		.num_databases = 4096,
6369 		.num_macs = 16384,
6370 		.num_ports = 11,	/* 10 + Z80 */
6371 		.num_internal_phys = 9,
6372 		.num_gpio = 16,
6373 		.max_vid = 8191,
6374 		.max_sid = 63,
6375 		.port_base_addr = 0x0,
6376 		.phy_base_addr = 0x0,
6377 		.global1_addr = 0x1b,
6378 		.global2_addr = 0x1c,
6379 		.age_time_coeff = 3750,
6380 		.g1_irqs = 9,
6381 		.g2_irqs = 14,
6382 		.atu_move_port_mask = 0x1f,
6383 		.pvt = true,
6384 		.multi_chip = true,
6385 		.edsa_support = MV88E6XXX_EDSA_UNDOCUMENTED,
6386 		.ptp_support = true,
6387 		.ops = &mv88e6390_ops,
6388 	},
6389 	[MV88E6390X] = {
6390 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
6391 		.family = MV88E6XXX_FAMILY_6390,
6392 		.name = "Marvell 88E6390X",
6393 		.num_databases = 4096,
6394 		.num_macs = 16384,
6395 		.num_ports = 11,	/* 10 + Z80 */
6396 		.num_internal_phys = 9,
6397 		.num_gpio = 16,
6398 		.max_vid = 8191,
6399 		.max_sid = 63,
6400 		.port_base_addr = 0x0,
6401 		.phy_base_addr = 0x0,
6402 		.global1_addr = 0x1b,
6403 		.global2_addr = 0x1c,
6404 		.age_time_coeff = 3750,
6405 		.g1_irqs = 9,
6406 		.g2_irqs = 14,
6407 		.atu_move_port_mask = 0x1f,
6408 		.pvt = true,
6409 		.multi_chip = true,
6410 		.edsa_support = MV88E6XXX_EDSA_UNDOCUMENTED,
6411 		.ptp_support = true,
6412 		.ops = &mv88e6390x_ops,
6413 	},
6414 
6415 	[MV88E6393X] = {
6416 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6393X,
6417 		.family = MV88E6XXX_FAMILY_6393,
6418 		.name = "Marvell 88E6393X",
6419 		.num_databases = 4096,
6420 		.num_ports = 11,	/* 10 + Z80 */
6421 		.num_internal_phys = 8,
6422 		.internal_phys_offset = 1,
6423 		.max_vid = 8191,
6424 		.max_sid = 63,
6425 		.port_base_addr = 0x0,
6426 		.phy_base_addr = 0x0,
6427 		.global1_addr = 0x1b,
6428 		.global2_addr = 0x1c,
6429 		.age_time_coeff = 3750,
6430 		.g1_irqs = 10,
6431 		.g2_irqs = 14,
6432 		.atu_move_port_mask = 0x1f,
6433 		.pvt = true,
6434 		.multi_chip = true,
6435 		.ptp_support = true,
6436 		.ops = &mv88e6393x_ops,
6437 	},
6438 };
6439 
6440 static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
6441 {
6442 	int i;
6443 
6444 	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
6445 		if (mv88e6xxx_table[i].prod_num == prod_num)
6446 			return &mv88e6xxx_table[i];
6447 
6448 	return NULL;
6449 }
6450 
6451 static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
6452 {
6453 	const struct mv88e6xxx_info *info;
6454 	unsigned int prod_num, rev;
6455 	u16 id;
6456 	int err;
6457 
6458 	mv88e6xxx_reg_lock(chip);
6459 	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
6460 	mv88e6xxx_reg_unlock(chip);
6461 	if (err)
6462 		return err;
6463 
6464 	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
6465 	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
6466 
6467 	info = mv88e6xxx_lookup_info(prod_num);
6468 	if (!info)
6469 		return -ENODEV;
6470 
6471 	/* Update the compatible info with the probed one */
6472 	chip->info = info;
6473 
6474 	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
6475 		 chip->info->prod_num, chip->info->name, rev);
6476 
6477 	return 0;
6478 }
6479 
6480 static int mv88e6xxx_single_chip_detect(struct mv88e6xxx_chip *chip,
6481 					struct mdio_device *mdiodev)
6482 {
6483 	int err;
6484 
6485 	/* dual_chip takes precedence over single/multi-chip modes */
6486 	if (chip->info->dual_chip)
6487 		return -EINVAL;
6488 
6489 	/* If the mdio addr is 16 indicating the first port address of a switch
6490 	 * (e.g. mv88e6*41) in single chip addressing mode the device may be
6491 	 * configured in single chip addressing mode. Setup the smi access as
6492 	 * single chip addressing mode and attempt to detect the model of the
6493 	 * switch, if this fails the device is not configured in single chip
6494 	 * addressing mode.
6495 	 */
6496 	if (mdiodev->addr != 16)
6497 		return -EINVAL;
6498 
6499 	err = mv88e6xxx_smi_init(chip, mdiodev->bus, 0);
6500 	if (err)
6501 		return err;
6502 
6503 	return mv88e6xxx_detect(chip);
6504 }
6505 
6506 static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
6507 {
6508 	struct mv88e6xxx_chip *chip;
6509 
6510 	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
6511 	if (!chip)
6512 		return NULL;
6513 
6514 	chip->dev = dev;
6515 
6516 	mutex_init(&chip->reg_lock);
6517 	INIT_LIST_HEAD(&chip->mdios);
6518 	idr_init(&chip->policies);
6519 	INIT_LIST_HEAD(&chip->msts);
6520 
6521 	return chip;
6522 }
6523 
6524 static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
6525 							int port,
6526 							enum dsa_tag_protocol m)
6527 {
6528 	struct mv88e6xxx_chip *chip = ds->priv;
6529 
6530 	return chip->tag_protocol;
6531 }
6532 
6533 static int mv88e6xxx_change_tag_protocol(struct dsa_switch *ds,
6534 					 enum dsa_tag_protocol proto)
6535 {
6536 	struct mv88e6xxx_chip *chip = ds->priv;
6537 	enum dsa_tag_protocol old_protocol;
6538 	struct dsa_port *cpu_dp;
6539 	int err;
6540 
6541 	switch (proto) {
6542 	case DSA_TAG_PROTO_EDSA:
6543 		switch (chip->info->edsa_support) {
6544 		case MV88E6XXX_EDSA_UNSUPPORTED:
6545 			return -EPROTONOSUPPORT;
6546 		case MV88E6XXX_EDSA_UNDOCUMENTED:
6547 			dev_warn(chip->dev, "Relying on undocumented EDSA tagging behavior\n");
6548 			fallthrough;
6549 		case MV88E6XXX_EDSA_SUPPORTED:
6550 			break;
6551 		}
6552 		break;
6553 	case DSA_TAG_PROTO_DSA:
6554 		break;
6555 	default:
6556 		return -EPROTONOSUPPORT;
6557 	}
6558 
6559 	old_protocol = chip->tag_protocol;
6560 	chip->tag_protocol = proto;
6561 
6562 	mv88e6xxx_reg_lock(chip);
6563 	dsa_switch_for_each_cpu_port(cpu_dp, ds) {
6564 		err = mv88e6xxx_setup_port_mode(chip, cpu_dp->index);
6565 		if (err) {
6566 			mv88e6xxx_reg_unlock(chip);
6567 			goto unwind;
6568 		}
6569 	}
6570 	mv88e6xxx_reg_unlock(chip);
6571 
6572 	return 0;
6573 
6574 unwind:
6575 	chip->tag_protocol = old_protocol;
6576 
6577 	mv88e6xxx_reg_lock(chip);
6578 	dsa_switch_for_each_cpu_port_continue_reverse(cpu_dp, ds)
6579 		mv88e6xxx_setup_port_mode(chip, cpu_dp->index);
6580 	mv88e6xxx_reg_unlock(chip);
6581 
6582 	return err;
6583 }
6584 
6585 static int mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
6586 				  const struct switchdev_obj_port_mdb *mdb,
6587 				  struct dsa_db db)
6588 {
6589 	struct mv88e6xxx_chip *chip = ds->priv;
6590 	int err;
6591 
6592 	mv88e6xxx_reg_lock(chip);
6593 	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
6594 					   MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC);
6595 	mv88e6xxx_reg_unlock(chip);
6596 
6597 	return err;
6598 }
6599 
6600 static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
6601 				  const struct switchdev_obj_port_mdb *mdb,
6602 				  struct dsa_db db)
6603 {
6604 	struct mv88e6xxx_chip *chip = ds->priv;
6605 	int err;
6606 
6607 	mv88e6xxx_reg_lock(chip);
6608 	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 0);
6609 	mv88e6xxx_reg_unlock(chip);
6610 
6611 	return err;
6612 }
6613 
6614 static int mv88e6xxx_port_mirror_add(struct dsa_switch *ds, int port,
6615 				     struct dsa_mall_mirror_tc_entry *mirror,
6616 				     bool ingress,
6617 				     struct netlink_ext_ack *extack)
6618 {
6619 	enum mv88e6xxx_egress_direction direction = ingress ?
6620 						MV88E6XXX_EGRESS_DIR_INGRESS :
6621 						MV88E6XXX_EGRESS_DIR_EGRESS;
6622 	struct mv88e6xxx_chip *chip = ds->priv;
6623 	bool other_mirrors = false;
6624 	int i;
6625 	int err;
6626 
6627 	mutex_lock(&chip->reg_lock);
6628 	if ((ingress ? chip->ingress_dest_port : chip->egress_dest_port) !=
6629 	    mirror->to_local_port) {
6630 		for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
6631 			other_mirrors |= ingress ?
6632 					 chip->ports[i].mirror_ingress :
6633 					 chip->ports[i].mirror_egress;
6634 
6635 		/* Can't change egress port when other mirror is active */
6636 		if (other_mirrors) {
6637 			err = -EBUSY;
6638 			goto out;
6639 		}
6640 
6641 		err = mv88e6xxx_set_egress_port(chip, direction,
6642 						mirror->to_local_port);
6643 		if (err)
6644 			goto out;
6645 	}
6646 
6647 	err = mv88e6xxx_port_set_mirror(chip, port, direction, true);
6648 out:
6649 	mutex_unlock(&chip->reg_lock);
6650 
6651 	return err;
6652 }
6653 
6654 static void mv88e6xxx_port_mirror_del(struct dsa_switch *ds, int port,
6655 				      struct dsa_mall_mirror_tc_entry *mirror)
6656 {
6657 	enum mv88e6xxx_egress_direction direction = mirror->ingress ?
6658 						MV88E6XXX_EGRESS_DIR_INGRESS :
6659 						MV88E6XXX_EGRESS_DIR_EGRESS;
6660 	struct mv88e6xxx_chip *chip = ds->priv;
6661 	bool other_mirrors = false;
6662 	int i;
6663 
6664 	mutex_lock(&chip->reg_lock);
6665 	if (mv88e6xxx_port_set_mirror(chip, port, direction, false))
6666 		dev_err(ds->dev, "p%d: failed to disable mirroring\n", port);
6667 
6668 	for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
6669 		other_mirrors |= mirror->ingress ?
6670 				 chip->ports[i].mirror_ingress :
6671 				 chip->ports[i].mirror_egress;
6672 
6673 	/* Reset egress port when no other mirror is active */
6674 	if (!other_mirrors) {
6675 		if (mv88e6xxx_set_egress_port(chip, direction,
6676 					      dsa_upstream_port(ds, port)))
6677 			dev_err(ds->dev, "failed to set egress port\n");
6678 	}
6679 
6680 	mutex_unlock(&chip->reg_lock);
6681 }
6682 
6683 static int mv88e6xxx_port_pre_bridge_flags(struct dsa_switch *ds, int port,
6684 					   struct switchdev_brport_flags flags,
6685 					   struct netlink_ext_ack *extack)
6686 {
6687 	struct mv88e6xxx_chip *chip = ds->priv;
6688 	const struct mv88e6xxx_ops *ops;
6689 
6690 	if (flags.mask & ~(BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD |
6691 			   BR_BCAST_FLOOD | BR_PORT_LOCKED | BR_PORT_MAB))
6692 		return -EINVAL;
6693 
6694 	ops = chip->info->ops;
6695 
6696 	if ((flags.mask & BR_FLOOD) && !ops->port_set_ucast_flood)
6697 		return -EINVAL;
6698 
6699 	if ((flags.mask & BR_MCAST_FLOOD) && !ops->port_set_mcast_flood)
6700 		return -EINVAL;
6701 
6702 	return 0;
6703 }
6704 
6705 static int mv88e6xxx_port_bridge_flags(struct dsa_switch *ds, int port,
6706 				       struct switchdev_brport_flags flags,
6707 				       struct netlink_ext_ack *extack)
6708 {
6709 	struct mv88e6xxx_chip *chip = ds->priv;
6710 	int err = 0;
6711 
6712 	mv88e6xxx_reg_lock(chip);
6713 
6714 	if (flags.mask & BR_LEARNING) {
6715 		bool learning = !!(flags.val & BR_LEARNING);
6716 		u16 pav = learning ? (1 << port) : 0;
6717 
6718 		err = mv88e6xxx_port_set_assoc_vector(chip, port, pav);
6719 		if (err)
6720 			goto out;
6721 	}
6722 
6723 	if (flags.mask & BR_FLOOD) {
6724 		bool unicast = !!(flags.val & BR_FLOOD);
6725 
6726 		err = chip->info->ops->port_set_ucast_flood(chip, port,
6727 							    unicast);
6728 		if (err)
6729 			goto out;
6730 	}
6731 
6732 	if (flags.mask & BR_MCAST_FLOOD) {
6733 		bool multicast = !!(flags.val & BR_MCAST_FLOOD);
6734 
6735 		err = chip->info->ops->port_set_mcast_flood(chip, port,
6736 							    multicast);
6737 		if (err)
6738 			goto out;
6739 	}
6740 
6741 	if (flags.mask & BR_BCAST_FLOOD) {
6742 		bool broadcast = !!(flags.val & BR_BCAST_FLOOD);
6743 
6744 		err = mv88e6xxx_port_broadcast_sync(chip, port, broadcast);
6745 		if (err)
6746 			goto out;
6747 	}
6748 
6749 	if (flags.mask & BR_PORT_MAB) {
6750 		bool mab = !!(flags.val & BR_PORT_MAB);
6751 
6752 		mv88e6xxx_port_set_mab(chip, port, mab);
6753 	}
6754 
6755 	if (flags.mask & BR_PORT_LOCKED) {
6756 		bool locked = !!(flags.val & BR_PORT_LOCKED);
6757 
6758 		err = mv88e6xxx_port_set_lock(chip, port, locked);
6759 		if (err)
6760 			goto out;
6761 	}
6762 out:
6763 	mv88e6xxx_reg_unlock(chip);
6764 
6765 	return err;
6766 }
6767 
6768 static bool mv88e6xxx_lag_can_offload(struct dsa_switch *ds,
6769 				      struct dsa_lag lag,
6770 				      struct netdev_lag_upper_info *info,
6771 				      struct netlink_ext_ack *extack)
6772 {
6773 	struct mv88e6xxx_chip *chip = ds->priv;
6774 	struct dsa_port *dp;
6775 	int members = 0;
6776 
6777 	if (!mv88e6xxx_has_lag(chip)) {
6778 		NL_SET_ERR_MSG_MOD(extack, "Chip does not support LAG offload");
6779 		return false;
6780 	}
6781 
6782 	if (!lag.id)
6783 		return false;
6784 
6785 	dsa_lag_foreach_port(dp, ds->dst, &lag)
6786 		/* Includes the port joining the LAG */
6787 		members++;
6788 
6789 	if (members > 8) {
6790 		NL_SET_ERR_MSG_MOD(extack,
6791 				   "Cannot offload more than 8 LAG ports");
6792 		return false;
6793 	}
6794 
6795 	/* We could potentially relax this to include active
6796 	 * backup in the future.
6797 	 */
6798 	if (info->tx_type != NETDEV_LAG_TX_TYPE_HASH) {
6799 		NL_SET_ERR_MSG_MOD(extack,
6800 				   "Can only offload LAG using hash TX type");
6801 		return false;
6802 	}
6803 
6804 	/* Ideally we would also validate that the hash type matches
6805 	 * the hardware. Alas, this is always set to unknown on team
6806 	 * interfaces.
6807 	 */
6808 	return true;
6809 }
6810 
6811 static int mv88e6xxx_lag_sync_map(struct dsa_switch *ds, struct dsa_lag lag)
6812 {
6813 	struct mv88e6xxx_chip *chip = ds->priv;
6814 	struct dsa_port *dp;
6815 	u16 map = 0;
6816 	int id;
6817 
6818 	/* DSA LAG IDs are one-based, hardware is zero-based */
6819 	id = lag.id - 1;
6820 
6821 	/* Build the map of all ports to distribute flows destined for
6822 	 * this LAG. This can be either a local user port, or a DSA
6823 	 * port if the LAG port is on a remote chip.
6824 	 */
6825 	dsa_lag_foreach_port(dp, ds->dst, &lag)
6826 		map |= BIT(dsa_towards_port(ds, dp->ds->index, dp->index));
6827 
6828 	return mv88e6xxx_g2_trunk_mapping_write(chip, id, map);
6829 }
6830 
6831 static const u8 mv88e6xxx_lag_mask_table[8][8] = {
6832 	/* Row number corresponds to the number of active members in a
6833 	 * LAG. Each column states which of the eight hash buckets are
6834 	 * mapped to the column:th port in the LAG.
6835 	 *
6836 	 * Example: In a LAG with three active ports, the second port
6837 	 * ([2][1]) would be selected for traffic mapped to buckets
6838 	 * 3,4,5 (0x38).
6839 	 */
6840 	{ 0xff,    0,    0,    0,    0,    0,    0,    0 },
6841 	{ 0x0f, 0xf0,    0,    0,    0,    0,    0,    0 },
6842 	{ 0x07, 0x38, 0xc0,    0,    0,    0,    0,    0 },
6843 	{ 0x03, 0x0c, 0x30, 0xc0,    0,    0,    0,    0 },
6844 	{ 0x03, 0x0c, 0x30, 0x40, 0x80,    0,    0,    0 },
6845 	{ 0x03, 0x0c, 0x10, 0x20, 0x40, 0x80,    0,    0 },
6846 	{ 0x03, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,    0 },
6847 	{ 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 },
6848 };
6849 
6850 static void mv88e6xxx_lag_set_port_mask(u16 *mask, int port,
6851 					int num_tx, int nth)
6852 {
6853 	u8 active = 0;
6854 	int i;
6855 
6856 	num_tx = num_tx <= 8 ? num_tx : 8;
6857 	if (nth < num_tx)
6858 		active = mv88e6xxx_lag_mask_table[num_tx - 1][nth];
6859 
6860 	for (i = 0; i < 8; i++) {
6861 		if (BIT(i) & active)
6862 			mask[i] |= BIT(port);
6863 	}
6864 }
6865 
6866 static int mv88e6xxx_lag_sync_masks(struct dsa_switch *ds)
6867 {
6868 	struct mv88e6xxx_chip *chip = ds->priv;
6869 	unsigned int id, num_tx;
6870 	struct dsa_port *dp;
6871 	struct dsa_lag *lag;
6872 	int i, err, nth;
6873 	u16 mask[8];
6874 	u16 ivec;
6875 
6876 	/* Assume no port is a member of any LAG. */
6877 	ivec = BIT(mv88e6xxx_num_ports(chip)) - 1;
6878 
6879 	/* Disable all masks for ports that _are_ members of a LAG. */
6880 	dsa_switch_for_each_port(dp, ds) {
6881 		if (!dp->lag)
6882 			continue;
6883 
6884 		ivec &= ~BIT(dp->index);
6885 	}
6886 
6887 	for (i = 0; i < 8; i++)
6888 		mask[i] = ivec;
6889 
6890 	/* Enable the correct subset of masks for all LAG ports that
6891 	 * are in the Tx set.
6892 	 */
6893 	dsa_lags_foreach_id(id, ds->dst) {
6894 		lag = dsa_lag_by_id(ds->dst, id);
6895 		if (!lag)
6896 			continue;
6897 
6898 		num_tx = 0;
6899 		dsa_lag_foreach_port(dp, ds->dst, lag) {
6900 			if (dp->lag_tx_enabled)
6901 				num_tx++;
6902 		}
6903 
6904 		if (!num_tx)
6905 			continue;
6906 
6907 		nth = 0;
6908 		dsa_lag_foreach_port(dp, ds->dst, lag) {
6909 			if (!dp->lag_tx_enabled)
6910 				continue;
6911 
6912 			if (dp->ds == ds)
6913 				mv88e6xxx_lag_set_port_mask(mask, dp->index,
6914 							    num_tx, nth);
6915 
6916 			nth++;
6917 		}
6918 	}
6919 
6920 	for (i = 0; i < 8; i++) {
6921 		err = mv88e6xxx_g2_trunk_mask_write(chip, i, true, mask[i]);
6922 		if (err)
6923 			return err;
6924 	}
6925 
6926 	return 0;
6927 }
6928 
6929 static int mv88e6xxx_lag_sync_masks_map(struct dsa_switch *ds,
6930 					struct dsa_lag lag)
6931 {
6932 	int err;
6933 
6934 	err = mv88e6xxx_lag_sync_masks(ds);
6935 
6936 	if (!err)
6937 		err = mv88e6xxx_lag_sync_map(ds, lag);
6938 
6939 	return err;
6940 }
6941 
6942 static int mv88e6xxx_port_lag_change(struct dsa_switch *ds, int port)
6943 {
6944 	struct mv88e6xxx_chip *chip = ds->priv;
6945 	int err;
6946 
6947 	mv88e6xxx_reg_lock(chip);
6948 	err = mv88e6xxx_lag_sync_masks(ds);
6949 	mv88e6xxx_reg_unlock(chip);
6950 	return err;
6951 }
6952 
6953 static int mv88e6xxx_port_lag_join(struct dsa_switch *ds, int port,
6954 				   struct dsa_lag lag,
6955 				   struct netdev_lag_upper_info *info,
6956 				   struct netlink_ext_ack *extack)
6957 {
6958 	struct mv88e6xxx_chip *chip = ds->priv;
6959 	int err, id;
6960 
6961 	if (!mv88e6xxx_lag_can_offload(ds, lag, info, extack))
6962 		return -EOPNOTSUPP;
6963 
6964 	/* DSA LAG IDs are one-based */
6965 	id = lag.id - 1;
6966 
6967 	mv88e6xxx_reg_lock(chip);
6968 
6969 	err = mv88e6xxx_port_set_trunk(chip, port, true, id);
6970 	if (err)
6971 		goto err_unlock;
6972 
6973 	err = mv88e6xxx_lag_sync_masks_map(ds, lag);
6974 	if (err)
6975 		goto err_clear_trunk;
6976 
6977 	mv88e6xxx_reg_unlock(chip);
6978 	return 0;
6979 
6980 err_clear_trunk:
6981 	mv88e6xxx_port_set_trunk(chip, port, false, 0);
6982 err_unlock:
6983 	mv88e6xxx_reg_unlock(chip);
6984 	return err;
6985 }
6986 
6987 static int mv88e6xxx_port_lag_leave(struct dsa_switch *ds, int port,
6988 				    struct dsa_lag lag)
6989 {
6990 	struct mv88e6xxx_chip *chip = ds->priv;
6991 	int err_sync, err_trunk;
6992 
6993 	mv88e6xxx_reg_lock(chip);
6994 	err_sync = mv88e6xxx_lag_sync_masks_map(ds, lag);
6995 	err_trunk = mv88e6xxx_port_set_trunk(chip, port, false, 0);
6996 	mv88e6xxx_reg_unlock(chip);
6997 	return err_sync ? : err_trunk;
6998 }
6999 
7000 static int mv88e6xxx_crosschip_lag_change(struct dsa_switch *ds, int sw_index,
7001 					  int port)
7002 {
7003 	struct mv88e6xxx_chip *chip = ds->priv;
7004 	int err;
7005 
7006 	mv88e6xxx_reg_lock(chip);
7007 	err = mv88e6xxx_lag_sync_masks(ds);
7008 	mv88e6xxx_reg_unlock(chip);
7009 	return err;
7010 }
7011 
7012 static int mv88e6xxx_crosschip_lag_join(struct dsa_switch *ds, int sw_index,
7013 					int port, struct dsa_lag lag,
7014 					struct netdev_lag_upper_info *info,
7015 					struct netlink_ext_ack *extack)
7016 {
7017 	struct mv88e6xxx_chip *chip = ds->priv;
7018 	int err;
7019 
7020 	if (!mv88e6xxx_lag_can_offload(ds, lag, info, extack))
7021 		return -EOPNOTSUPP;
7022 
7023 	mv88e6xxx_reg_lock(chip);
7024 
7025 	err = mv88e6xxx_lag_sync_masks_map(ds, lag);
7026 	if (err)
7027 		goto unlock;
7028 
7029 	err = mv88e6xxx_pvt_map(chip, sw_index, port);
7030 
7031 unlock:
7032 	mv88e6xxx_reg_unlock(chip);
7033 	return err;
7034 }
7035 
7036 static int mv88e6xxx_crosschip_lag_leave(struct dsa_switch *ds, int sw_index,
7037 					 int port, struct dsa_lag lag)
7038 {
7039 	struct mv88e6xxx_chip *chip = ds->priv;
7040 	int err_sync, err_pvt;
7041 
7042 	mv88e6xxx_reg_lock(chip);
7043 	err_sync = mv88e6xxx_lag_sync_masks_map(ds, lag);
7044 	err_pvt = mv88e6xxx_pvt_map(chip, sw_index, port);
7045 	mv88e6xxx_reg_unlock(chip);
7046 	return err_sync ? : err_pvt;
7047 }
7048 
7049 static const struct phylink_mac_ops mv88e6xxx_phylink_mac_ops = {
7050 	.mac_select_pcs		= mv88e6xxx_mac_select_pcs,
7051 	.mac_prepare		= mv88e6xxx_mac_prepare,
7052 	.mac_config		= mv88e6xxx_mac_config,
7053 	.mac_finish		= mv88e6xxx_mac_finish,
7054 	.mac_link_down		= mv88e6xxx_mac_link_down,
7055 	.mac_link_up		= mv88e6xxx_mac_link_up,
7056 };
7057 
7058 static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
7059 	.get_tag_protocol	= mv88e6xxx_get_tag_protocol,
7060 	.change_tag_protocol	= mv88e6xxx_change_tag_protocol,
7061 	.setup			= mv88e6xxx_setup,
7062 	.teardown		= mv88e6xxx_teardown,
7063 	.port_setup		= mv88e6xxx_port_setup,
7064 	.port_teardown		= mv88e6xxx_port_teardown,
7065 	.phylink_get_caps	= mv88e6xxx_get_caps,
7066 	.get_strings		= mv88e6xxx_get_strings,
7067 	.get_ethtool_stats	= mv88e6xxx_get_ethtool_stats,
7068 	.get_eth_mac_stats	= mv88e6xxx_get_eth_mac_stats,
7069 	.get_rmon_stats		= mv88e6xxx_get_rmon_stats,
7070 	.get_sset_count		= mv88e6xxx_get_sset_count,
7071 	.port_max_mtu		= mv88e6xxx_get_max_mtu,
7072 	.port_change_mtu	= mv88e6xxx_change_mtu,
7073 	.get_mac_eee		= mv88e6xxx_get_mac_eee,
7074 	.set_mac_eee		= mv88e6xxx_set_mac_eee,
7075 	.get_eeprom_len		= mv88e6xxx_get_eeprom_len,
7076 	.get_eeprom		= mv88e6xxx_get_eeprom,
7077 	.set_eeprom		= mv88e6xxx_set_eeprom,
7078 	.get_regs_len		= mv88e6xxx_get_regs_len,
7079 	.get_regs		= mv88e6xxx_get_regs,
7080 	.get_rxnfc		= mv88e6xxx_get_rxnfc,
7081 	.set_rxnfc		= mv88e6xxx_set_rxnfc,
7082 	.set_ageing_time	= mv88e6xxx_set_ageing_time,
7083 	.port_bridge_join	= mv88e6xxx_port_bridge_join,
7084 	.port_bridge_leave	= mv88e6xxx_port_bridge_leave,
7085 	.port_pre_bridge_flags	= mv88e6xxx_port_pre_bridge_flags,
7086 	.port_bridge_flags	= mv88e6xxx_port_bridge_flags,
7087 	.port_stp_state_set	= mv88e6xxx_port_stp_state_set,
7088 	.port_mst_state_set	= mv88e6xxx_port_mst_state_set,
7089 	.port_fast_age		= mv88e6xxx_port_fast_age,
7090 	.port_vlan_fast_age	= mv88e6xxx_port_vlan_fast_age,
7091 	.port_vlan_filtering	= mv88e6xxx_port_vlan_filtering,
7092 	.port_vlan_add		= mv88e6xxx_port_vlan_add,
7093 	.port_vlan_del		= mv88e6xxx_port_vlan_del,
7094 	.vlan_msti_set		= mv88e6xxx_vlan_msti_set,
7095 	.port_fdb_add		= mv88e6xxx_port_fdb_add,
7096 	.port_fdb_del		= mv88e6xxx_port_fdb_del,
7097 	.port_fdb_dump		= mv88e6xxx_port_fdb_dump,
7098 	.port_mdb_add		= mv88e6xxx_port_mdb_add,
7099 	.port_mdb_del		= mv88e6xxx_port_mdb_del,
7100 	.port_mirror_add	= mv88e6xxx_port_mirror_add,
7101 	.port_mirror_del	= mv88e6xxx_port_mirror_del,
7102 	.crosschip_bridge_join	= mv88e6xxx_crosschip_bridge_join,
7103 	.crosschip_bridge_leave	= mv88e6xxx_crosschip_bridge_leave,
7104 	.port_hwtstamp_set	= mv88e6xxx_port_hwtstamp_set,
7105 	.port_hwtstamp_get	= mv88e6xxx_port_hwtstamp_get,
7106 	.port_txtstamp		= mv88e6xxx_port_txtstamp,
7107 	.port_rxtstamp		= mv88e6xxx_port_rxtstamp,
7108 	.get_ts_info		= mv88e6xxx_get_ts_info,
7109 	.devlink_param_get	= mv88e6xxx_devlink_param_get,
7110 	.devlink_param_set	= mv88e6xxx_devlink_param_set,
7111 	.devlink_info_get	= mv88e6xxx_devlink_info_get,
7112 	.port_lag_change	= mv88e6xxx_port_lag_change,
7113 	.port_lag_join		= mv88e6xxx_port_lag_join,
7114 	.port_lag_leave		= mv88e6xxx_port_lag_leave,
7115 	.crosschip_lag_change	= mv88e6xxx_crosschip_lag_change,
7116 	.crosschip_lag_join	= mv88e6xxx_crosschip_lag_join,
7117 	.crosschip_lag_leave	= mv88e6xxx_crosschip_lag_leave,
7118 };
7119 
7120 static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
7121 {
7122 	struct device *dev = chip->dev;
7123 	struct dsa_switch *ds;
7124 
7125 	ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
7126 	if (!ds)
7127 		return -ENOMEM;
7128 
7129 	ds->dev = dev;
7130 	ds->num_ports = mv88e6xxx_num_ports(chip);
7131 	ds->priv = chip;
7132 	ds->dev = dev;
7133 	ds->ops = &mv88e6xxx_switch_ops;
7134 	ds->phylink_mac_ops = &mv88e6xxx_phylink_mac_ops;
7135 	ds->ageing_time_min = chip->info->age_time_coeff;
7136 	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
7137 
7138 	/* Some chips support up to 32, but that requires enabling the
7139 	 * 5-bit port mode, which we do not support. 640k^W16 ought to
7140 	 * be enough for anyone.
7141 	 */
7142 	ds->num_lag_ids = mv88e6xxx_has_lag(chip) ? 16 : 0;
7143 
7144 	dev_set_drvdata(dev, ds);
7145 
7146 	return dsa_register_switch(ds);
7147 }
7148 
7149 static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
7150 {
7151 	dsa_unregister_switch(chip->ds);
7152 }
7153 
7154 static const void *pdata_device_get_match_data(struct device *dev)
7155 {
7156 	const struct of_device_id *matches = dev->driver->of_match_table;
7157 	const struct dsa_mv88e6xxx_pdata *pdata = dev->platform_data;
7158 
7159 	for (; matches->name[0] || matches->type[0] || matches->compatible[0];
7160 	     matches++) {
7161 		if (!strcmp(pdata->compatible, matches->compatible))
7162 			return matches->data;
7163 	}
7164 	return NULL;
7165 }
7166 
7167 /* There is no suspend to RAM support at DSA level yet, the switch configuration
7168  * would be lost after a power cycle so prevent it to be suspended.
7169  */
7170 static int __maybe_unused mv88e6xxx_suspend(struct device *dev)
7171 {
7172 	return -EOPNOTSUPP;
7173 }
7174 
7175 static int __maybe_unused mv88e6xxx_resume(struct device *dev)
7176 {
7177 	return 0;
7178 }
7179 
7180 static SIMPLE_DEV_PM_OPS(mv88e6xxx_pm_ops, mv88e6xxx_suspend, mv88e6xxx_resume);
7181 
7182 static int mv88e6xxx_probe(struct mdio_device *mdiodev)
7183 {
7184 	struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
7185 	const struct mv88e6xxx_info *compat_info = NULL;
7186 	struct device *dev = &mdiodev->dev;
7187 	struct device_node *np = dev->of_node;
7188 	struct mv88e6xxx_chip *chip;
7189 	int port;
7190 	int err;
7191 
7192 	if (!np && !pdata)
7193 		return -EINVAL;
7194 
7195 	if (np)
7196 		compat_info = of_device_get_match_data(dev);
7197 
7198 	if (pdata) {
7199 		compat_info = pdata_device_get_match_data(dev);
7200 
7201 		if (!pdata->netdev)
7202 			return -EINVAL;
7203 
7204 		for (port = 0; port < DSA_MAX_PORTS; port++) {
7205 			if (!(pdata->enabled_ports & (1 << port)))
7206 				continue;
7207 			if (strcmp(pdata->cd.port_names[port], "cpu"))
7208 				continue;
7209 			pdata->cd.netdev[port] = &pdata->netdev->dev;
7210 			break;
7211 		}
7212 	}
7213 
7214 	if (!compat_info)
7215 		return -EINVAL;
7216 
7217 	chip = mv88e6xxx_alloc_chip(dev);
7218 	if (!chip) {
7219 		err = -ENOMEM;
7220 		goto out;
7221 	}
7222 
7223 	chip->info = compat_info;
7224 
7225 	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
7226 	if (IS_ERR(chip->reset)) {
7227 		err = PTR_ERR(chip->reset);
7228 		goto out;
7229 	}
7230 	if (chip->reset)
7231 		usleep_range(10000, 20000);
7232 
7233 	/* Detect if the device is configured in single chip addressing mode,
7234 	 * otherwise continue with address specific smi init/detection.
7235 	 */
7236 	err = mv88e6xxx_single_chip_detect(chip, mdiodev);
7237 	if (err) {
7238 		err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
7239 		if (err)
7240 			goto out;
7241 
7242 		err = mv88e6xxx_detect(chip);
7243 		if (err)
7244 			goto out;
7245 	}
7246 
7247 	if (chip->info->edsa_support == MV88E6XXX_EDSA_SUPPORTED)
7248 		chip->tag_protocol = DSA_TAG_PROTO_EDSA;
7249 	else
7250 		chip->tag_protocol = DSA_TAG_PROTO_DSA;
7251 
7252 	mv88e6xxx_phy_init(chip);
7253 
7254 	if (chip->info->ops->get_eeprom) {
7255 		if (np)
7256 			of_property_read_u32(np, "eeprom-length",
7257 					     &chip->eeprom_len);
7258 		else
7259 			chip->eeprom_len = pdata->eeprom_len;
7260 	}
7261 
7262 	mv88e6xxx_reg_lock(chip);
7263 	err = mv88e6xxx_switch_reset(chip);
7264 	mv88e6xxx_reg_unlock(chip);
7265 	if (err)
7266 		goto out;
7267 
7268 	if (np) {
7269 		chip->irq = of_irq_get(np, 0);
7270 		if (chip->irq == -EPROBE_DEFER) {
7271 			err = chip->irq;
7272 			goto out;
7273 		}
7274 	}
7275 
7276 	if (pdata)
7277 		chip->irq = pdata->irq;
7278 
7279 	/* Has to be performed before the MDIO bus is created, because
7280 	 * the PHYs will link their interrupts to these interrupt
7281 	 * controllers
7282 	 */
7283 	mv88e6xxx_reg_lock(chip);
7284 	if (chip->irq > 0)
7285 		err = mv88e6xxx_g1_irq_setup(chip);
7286 	else
7287 		err = mv88e6xxx_irq_poll_setup(chip);
7288 	mv88e6xxx_reg_unlock(chip);
7289 
7290 	if (err)
7291 		goto out;
7292 
7293 	if (chip->info->g2_irqs > 0) {
7294 		err = mv88e6xxx_g2_irq_setup(chip);
7295 		if (err)
7296 			goto out_g1_irq;
7297 	}
7298 
7299 	err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
7300 	if (err)
7301 		goto out_g2_irq;
7302 
7303 	err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
7304 	if (err)
7305 		goto out_g1_atu_prob_irq;
7306 
7307 	err = mv88e6xxx_register_switch(chip);
7308 	if (err)
7309 		goto out_g1_vtu_prob_irq;
7310 
7311 	return 0;
7312 
7313 out_g1_vtu_prob_irq:
7314 	mv88e6xxx_g1_vtu_prob_irq_free(chip);
7315 out_g1_atu_prob_irq:
7316 	mv88e6xxx_g1_atu_prob_irq_free(chip);
7317 out_g2_irq:
7318 	if (chip->info->g2_irqs > 0)
7319 		mv88e6xxx_g2_irq_free(chip);
7320 out_g1_irq:
7321 	if (chip->irq > 0)
7322 		mv88e6xxx_g1_irq_free(chip);
7323 	else
7324 		mv88e6xxx_irq_poll_free(chip);
7325 out:
7326 	if (pdata)
7327 		dev_put(pdata->netdev);
7328 
7329 	return err;
7330 }
7331 
7332 static void mv88e6xxx_remove(struct mdio_device *mdiodev)
7333 {
7334 	struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
7335 	struct mv88e6xxx_chip *chip;
7336 
7337 	if (!ds)
7338 		return;
7339 
7340 	chip = ds->priv;
7341 
7342 	if (chip->info->ptp_support) {
7343 		mv88e6xxx_hwtstamp_free(chip);
7344 		mv88e6xxx_ptp_free(chip);
7345 	}
7346 
7347 	mv88e6xxx_phy_destroy(chip);
7348 	mv88e6xxx_unregister_switch(chip);
7349 
7350 	mv88e6xxx_g1_vtu_prob_irq_free(chip);
7351 	mv88e6xxx_g1_atu_prob_irq_free(chip);
7352 
7353 	if (chip->info->g2_irqs > 0)
7354 		mv88e6xxx_g2_irq_free(chip);
7355 
7356 	if (chip->irq > 0)
7357 		mv88e6xxx_g1_irq_free(chip);
7358 	else
7359 		mv88e6xxx_irq_poll_free(chip);
7360 }
7361 
7362 static void mv88e6xxx_shutdown(struct mdio_device *mdiodev)
7363 {
7364 	struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
7365 
7366 	if (!ds)
7367 		return;
7368 
7369 	dsa_switch_shutdown(ds);
7370 
7371 	dev_set_drvdata(&mdiodev->dev, NULL);
7372 }
7373 
7374 static const struct of_device_id mv88e6xxx_of_match[] = {
7375 	{
7376 		.compatible = "marvell,mv88e6085",
7377 		.data = &mv88e6xxx_table[MV88E6085],
7378 	},
7379 	{
7380 		.compatible = "marvell,mv88e6190",
7381 		.data = &mv88e6xxx_table[MV88E6190],
7382 	},
7383 	{
7384 		.compatible = "marvell,mv88e6250",
7385 		.data = &mv88e6xxx_table[MV88E6250],
7386 	},
7387 	{ /* sentinel */ },
7388 };
7389 
7390 MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
7391 
7392 static struct mdio_driver mv88e6xxx_driver = {
7393 	.probe	= mv88e6xxx_probe,
7394 	.remove = mv88e6xxx_remove,
7395 	.shutdown = mv88e6xxx_shutdown,
7396 	.mdiodrv.driver = {
7397 		.name = "mv88e6085",
7398 		.of_match_table = mv88e6xxx_of_match,
7399 		.pm = &mv88e6xxx_pm_ops,
7400 	},
7401 };
7402 
7403 mdio_module_driver(mv88e6xxx_driver);
7404 
7405 MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
7406 MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
7407 MODULE_LICENSE("GPL");
7408