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