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