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