xref: /openbmc/linux/drivers/net/dsa/mv88e6xxx/chip.c (revision 5d331b7f)
1 /*
2  * Marvell 88e6xxx Ethernet switch single-chip support
3  *
4  * Copyright (c) 2008 Marvell Semiconductor
5  *
6  * Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch>
7  *
8  * Copyright (c) 2016-2017 Savoir-faire Linux Inc.
9  *	Vivien Didelot <vivien.didelot@savoirfairelinux.com>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  */
16 
17 #include <linux/delay.h>
18 #include <linux/etherdevice.h>
19 #include <linux/ethtool.h>
20 #include <linux/if_bridge.h>
21 #include <linux/interrupt.h>
22 #include <linux/irq.h>
23 #include <linux/irqdomain.h>
24 #include <linux/jiffies.h>
25 #include <linux/list.h>
26 #include <linux/mdio.h>
27 #include <linux/module.h>
28 #include <linux/of_device.h>
29 #include <linux/of_irq.h>
30 #include <linux/of_mdio.h>
31 #include <linux/platform_data/mv88e6xxx.h>
32 #include <linux/netdevice.h>
33 #include <linux/gpio/consumer.h>
34 #include <linux/phy.h>
35 #include <linux/phylink.h>
36 #include <net/dsa.h>
37 
38 #include "chip.h"
39 #include "global1.h"
40 #include "global2.h"
41 #include "hwtstamp.h"
42 #include "phy.h"
43 #include "port.h"
44 #include "ptp.h"
45 #include "serdes.h"
46 
47 static void assert_reg_lock(struct mv88e6xxx_chip *chip)
48 {
49 	if (unlikely(!mutex_is_locked(&chip->reg_lock))) {
50 		dev_err(chip->dev, "Switch registers lock not held!\n");
51 		dump_stack();
52 	}
53 }
54 
55 /* The switch ADDR[4:1] configuration pins define the chip SMI device address
56  * (ADDR[0] is always zero, thus only even SMI addresses can be strapped).
57  *
58  * When ADDR is all zero, the chip uses Single-chip Addressing Mode, assuming it
59  * is the only device connected to the SMI master. In this mode it responds to
60  * all 32 possible SMI addresses, and thus maps directly the internal devices.
61  *
62  * When ADDR is non-zero, the chip uses Multi-chip Addressing Mode, allowing
63  * multiple devices to share the SMI interface. In this mode it responds to only
64  * 2 registers, used to indirectly access the internal SMI devices.
65  */
66 
67 static int mv88e6xxx_smi_read(struct mv88e6xxx_chip *chip,
68 			      int addr, int reg, u16 *val)
69 {
70 	if (!chip->smi_ops)
71 		return -EOPNOTSUPP;
72 
73 	return chip->smi_ops->read(chip, addr, reg, val);
74 }
75 
76 static int mv88e6xxx_smi_write(struct mv88e6xxx_chip *chip,
77 			       int addr, int reg, u16 val)
78 {
79 	if (!chip->smi_ops)
80 		return -EOPNOTSUPP;
81 
82 	return chip->smi_ops->write(chip, addr, reg, val);
83 }
84 
85 static int mv88e6xxx_smi_single_chip_read(struct mv88e6xxx_chip *chip,
86 					  int addr, int reg, u16 *val)
87 {
88 	int ret;
89 
90 	ret = mdiobus_read_nested(chip->bus, addr, reg);
91 	if (ret < 0)
92 		return ret;
93 
94 	*val = ret & 0xffff;
95 
96 	return 0;
97 }
98 
99 static int mv88e6xxx_smi_single_chip_write(struct mv88e6xxx_chip *chip,
100 					   int addr, int reg, u16 val)
101 {
102 	int ret;
103 
104 	ret = mdiobus_write_nested(chip->bus, addr, reg, val);
105 	if (ret < 0)
106 		return ret;
107 
108 	return 0;
109 }
110 
111 static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_single_chip_ops = {
112 	.read = mv88e6xxx_smi_single_chip_read,
113 	.write = mv88e6xxx_smi_single_chip_write,
114 };
115 
116 static int mv88e6xxx_smi_multi_chip_wait(struct mv88e6xxx_chip *chip)
117 {
118 	int ret;
119 	int i;
120 
121 	for (i = 0; i < 16; i++) {
122 		ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_CMD);
123 		if (ret < 0)
124 			return ret;
125 
126 		if ((ret & SMI_CMD_BUSY) == 0)
127 			return 0;
128 	}
129 
130 	return -ETIMEDOUT;
131 }
132 
133 static int mv88e6xxx_smi_multi_chip_read(struct mv88e6xxx_chip *chip,
134 					 int addr, int reg, u16 *val)
135 {
136 	int ret;
137 
138 	/* Wait for the bus to become free. */
139 	ret = mv88e6xxx_smi_multi_chip_wait(chip);
140 	if (ret < 0)
141 		return ret;
142 
143 	/* Transmit the read command. */
144 	ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
145 				   SMI_CMD_OP_22_READ | (addr << 5) | reg);
146 	if (ret < 0)
147 		return ret;
148 
149 	/* Wait for the read command to complete. */
150 	ret = mv88e6xxx_smi_multi_chip_wait(chip);
151 	if (ret < 0)
152 		return ret;
153 
154 	/* Read the data. */
155 	ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_DATA);
156 	if (ret < 0)
157 		return ret;
158 
159 	*val = ret & 0xffff;
160 
161 	return 0;
162 }
163 
164 static int mv88e6xxx_smi_multi_chip_write(struct mv88e6xxx_chip *chip,
165 					  int addr, int reg, u16 val)
166 {
167 	int ret;
168 
169 	/* Wait for the bus to become free. */
170 	ret = mv88e6xxx_smi_multi_chip_wait(chip);
171 	if (ret < 0)
172 		return ret;
173 
174 	/* Transmit the data to write. */
175 	ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_DATA, val);
176 	if (ret < 0)
177 		return ret;
178 
179 	/* Transmit the write command. */
180 	ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
181 				   SMI_CMD_OP_22_WRITE | (addr << 5) | reg);
182 	if (ret < 0)
183 		return ret;
184 
185 	/* Wait for the write command to complete. */
186 	ret = mv88e6xxx_smi_multi_chip_wait(chip);
187 	if (ret < 0)
188 		return ret;
189 
190 	return 0;
191 }
192 
193 static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_multi_chip_ops = {
194 	.read = mv88e6xxx_smi_multi_chip_read,
195 	.write = mv88e6xxx_smi_multi_chip_write,
196 };
197 
198 int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val)
199 {
200 	int err;
201 
202 	assert_reg_lock(chip);
203 
204 	err = mv88e6xxx_smi_read(chip, addr, reg, val);
205 	if (err)
206 		return err;
207 
208 	dev_dbg(chip->dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
209 		addr, reg, *val);
210 
211 	return 0;
212 }
213 
214 int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val)
215 {
216 	int err;
217 
218 	assert_reg_lock(chip);
219 
220 	err = mv88e6xxx_smi_write(chip, addr, reg, val);
221 	if (err)
222 		return err;
223 
224 	dev_dbg(chip->dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
225 		addr, reg, val);
226 
227 	return 0;
228 }
229 
230 struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
231 {
232 	struct mv88e6xxx_mdio_bus *mdio_bus;
233 
234 	mdio_bus = list_first_entry(&chip->mdios, struct mv88e6xxx_mdio_bus,
235 				    list);
236 	if (!mdio_bus)
237 		return NULL;
238 
239 	return mdio_bus->bus;
240 }
241 
242 static void mv88e6xxx_g1_irq_mask(struct irq_data *d)
243 {
244 	struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
245 	unsigned int n = d->hwirq;
246 
247 	chip->g1_irq.masked |= (1 << n);
248 }
249 
250 static void mv88e6xxx_g1_irq_unmask(struct irq_data *d)
251 {
252 	struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
253 	unsigned int n = d->hwirq;
254 
255 	chip->g1_irq.masked &= ~(1 << n);
256 }
257 
258 static irqreturn_t mv88e6xxx_g1_irq_thread_work(struct mv88e6xxx_chip *chip)
259 {
260 	unsigned int nhandled = 0;
261 	unsigned int sub_irq;
262 	unsigned int n;
263 	u16 reg;
264 	int err;
265 
266 	mutex_lock(&chip->reg_lock);
267 	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
268 	mutex_unlock(&chip->reg_lock);
269 
270 	if (err)
271 		goto out;
272 
273 	for (n = 0; n < chip->g1_irq.nirqs; ++n) {
274 		if (reg & (1 << n)) {
275 			sub_irq = irq_find_mapping(chip->g1_irq.domain, n);
276 			handle_nested_irq(sub_irq);
277 			++nhandled;
278 		}
279 	}
280 out:
281 	return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
282 }
283 
284 static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id)
285 {
286 	struct mv88e6xxx_chip *chip = dev_id;
287 
288 	return mv88e6xxx_g1_irq_thread_work(chip);
289 }
290 
291 static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
292 {
293 	struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
294 
295 	mutex_lock(&chip->reg_lock);
296 }
297 
298 static void mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data *d)
299 {
300 	struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
301 	u16 mask = GENMASK(chip->g1_irq.nirqs, 0);
302 	u16 reg;
303 	int err;
304 
305 	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &reg);
306 	if (err)
307 		goto out;
308 
309 	reg &= ~mask;
310 	reg |= (~chip->g1_irq.masked & mask);
311 
312 	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, reg);
313 	if (err)
314 		goto out;
315 
316 out:
317 	mutex_unlock(&chip->reg_lock);
318 }
319 
320 static const struct irq_chip mv88e6xxx_g1_irq_chip = {
321 	.name			= "mv88e6xxx-g1",
322 	.irq_mask		= mv88e6xxx_g1_irq_mask,
323 	.irq_unmask		= mv88e6xxx_g1_irq_unmask,
324 	.irq_bus_lock		= mv88e6xxx_g1_irq_bus_lock,
325 	.irq_bus_sync_unlock	= mv88e6xxx_g1_irq_bus_sync_unlock,
326 };
327 
328 static int mv88e6xxx_g1_irq_domain_map(struct irq_domain *d,
329 				       unsigned int irq,
330 				       irq_hw_number_t hwirq)
331 {
332 	struct mv88e6xxx_chip *chip = d->host_data;
333 
334 	irq_set_chip_data(irq, d->host_data);
335 	irq_set_chip_and_handler(irq, &chip->g1_irq.chip, handle_level_irq);
336 	irq_set_noprobe(irq);
337 
338 	return 0;
339 }
340 
341 static const struct irq_domain_ops mv88e6xxx_g1_irq_domain_ops = {
342 	.map	= mv88e6xxx_g1_irq_domain_map,
343 	.xlate	= irq_domain_xlate_twocell,
344 };
345 
346 /* To be called with reg_lock held */
347 static void mv88e6xxx_g1_irq_free_common(struct mv88e6xxx_chip *chip)
348 {
349 	int irq, virq;
350 	u16 mask;
351 
352 	mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
353 	mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
354 	mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
355 
356 	for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
357 		virq = irq_find_mapping(chip->g1_irq.domain, irq);
358 		irq_dispose_mapping(virq);
359 	}
360 
361 	irq_domain_remove(chip->g1_irq.domain);
362 }
363 
364 static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
365 {
366 	/*
367 	 * free_irq must be called without reg_lock taken because the irq
368 	 * handler takes this lock, too.
369 	 */
370 	free_irq(chip->irq, chip);
371 
372 	mutex_lock(&chip->reg_lock);
373 	mv88e6xxx_g1_irq_free_common(chip);
374 	mutex_unlock(&chip->reg_lock);
375 }
376 
377 static int mv88e6xxx_g1_irq_setup_common(struct mv88e6xxx_chip *chip)
378 {
379 	int err, irq, virq;
380 	u16 reg, mask;
381 
382 	chip->g1_irq.nirqs = chip->info->g1_irqs;
383 	chip->g1_irq.domain = irq_domain_add_simple(
384 		NULL, chip->g1_irq.nirqs, 0,
385 		&mv88e6xxx_g1_irq_domain_ops, chip);
386 	if (!chip->g1_irq.domain)
387 		return -ENOMEM;
388 
389 	for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
390 		irq_create_mapping(chip->g1_irq.domain, irq);
391 
392 	chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
393 	chip->g1_irq.masked = ~0;
394 
395 	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
396 	if (err)
397 		goto out_mapping;
398 
399 	mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
400 
401 	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
402 	if (err)
403 		goto out_disable;
404 
405 	/* Reading the interrupt status clears (most of) them */
406 	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
407 	if (err)
408 		goto out_disable;
409 
410 	return 0;
411 
412 out_disable:
413 	mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
414 	mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
415 
416 out_mapping:
417 	for (irq = 0; irq < 16; irq++) {
418 		virq = irq_find_mapping(chip->g1_irq.domain, irq);
419 		irq_dispose_mapping(virq);
420 	}
421 
422 	irq_domain_remove(chip->g1_irq.domain);
423 
424 	return err;
425 }
426 
427 static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
428 {
429 	int err;
430 
431 	err = mv88e6xxx_g1_irq_setup_common(chip);
432 	if (err)
433 		return err;
434 
435 	err = request_threaded_irq(chip->irq, NULL,
436 				   mv88e6xxx_g1_irq_thread_fn,
437 				   IRQF_ONESHOT | IRQF_SHARED,
438 				   dev_name(chip->dev), chip);
439 	if (err)
440 		mv88e6xxx_g1_irq_free_common(chip);
441 
442 	return err;
443 }
444 
445 static void mv88e6xxx_irq_poll(struct kthread_work *work)
446 {
447 	struct mv88e6xxx_chip *chip = container_of(work,
448 						   struct mv88e6xxx_chip,
449 						   irq_poll_work.work);
450 	mv88e6xxx_g1_irq_thread_work(chip);
451 
452 	kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work,
453 				   msecs_to_jiffies(100));
454 }
455 
456 static int mv88e6xxx_irq_poll_setup(struct mv88e6xxx_chip *chip)
457 {
458 	int err;
459 
460 	err = mv88e6xxx_g1_irq_setup_common(chip);
461 	if (err)
462 		return err;
463 
464 	kthread_init_delayed_work(&chip->irq_poll_work,
465 				  mv88e6xxx_irq_poll);
466 
467 	chip->kworker = kthread_create_worker(0, dev_name(chip->dev));
468 	if (IS_ERR(chip->kworker))
469 		return PTR_ERR(chip->kworker);
470 
471 	kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work,
472 				   msecs_to_jiffies(100));
473 
474 	return 0;
475 }
476 
477 static void mv88e6xxx_irq_poll_free(struct mv88e6xxx_chip *chip)
478 {
479 	kthread_cancel_delayed_work_sync(&chip->irq_poll_work);
480 	kthread_destroy_worker(chip->kworker);
481 
482 	mutex_lock(&chip->reg_lock);
483 	mv88e6xxx_g1_irq_free_common(chip);
484 	mutex_unlock(&chip->reg_lock);
485 }
486 
487 int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask)
488 {
489 	int i;
490 
491 	for (i = 0; i < 16; i++) {
492 		u16 val;
493 		int err;
494 
495 		err = mv88e6xxx_read(chip, addr, reg, &val);
496 		if (err)
497 			return err;
498 
499 		if (!(val & mask))
500 			return 0;
501 
502 		usleep_range(1000, 2000);
503 	}
504 
505 	dev_err(chip->dev, "Timeout while waiting for switch\n");
506 	return -ETIMEDOUT;
507 }
508 
509 /* Indirect write to single pointer-data register with an Update bit */
510 int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
511 {
512 	u16 val;
513 	int err;
514 
515 	/* Wait until the previous operation is completed */
516 	err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
517 	if (err)
518 		return err;
519 
520 	/* Set the Update bit to trigger a write operation */
521 	val = BIT(15) | update;
522 
523 	return mv88e6xxx_write(chip, addr, reg, val);
524 }
525 
526 static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
527 				    int link, int speed, int duplex, int pause,
528 				    phy_interface_t mode)
529 {
530 	int err;
531 
532 	if (!chip->info->ops->port_set_link)
533 		return 0;
534 
535 	/* Port's MAC control must not be changed unless the link is down */
536 	err = chip->info->ops->port_set_link(chip, port, 0);
537 	if (err)
538 		return err;
539 
540 	if (chip->info->ops->port_set_speed) {
541 		err = chip->info->ops->port_set_speed(chip, port, speed);
542 		if (err && err != -EOPNOTSUPP)
543 			goto restore_link;
544 	}
545 
546 	if (chip->info->ops->port_set_pause) {
547 		err = chip->info->ops->port_set_pause(chip, port, pause);
548 		if (err)
549 			goto restore_link;
550 	}
551 
552 	if (chip->info->ops->port_set_duplex) {
553 		err = chip->info->ops->port_set_duplex(chip, port, duplex);
554 		if (err && err != -EOPNOTSUPP)
555 			goto restore_link;
556 	}
557 
558 	if (chip->info->ops->port_set_rgmii_delay) {
559 		err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
560 		if (err && err != -EOPNOTSUPP)
561 			goto restore_link;
562 	}
563 
564 	if (chip->info->ops->port_set_cmode) {
565 		err = chip->info->ops->port_set_cmode(chip, port, mode);
566 		if (err && err != -EOPNOTSUPP)
567 			goto restore_link;
568 	}
569 
570 	err = 0;
571 restore_link:
572 	if (chip->info->ops->port_set_link(chip, port, link))
573 		dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
574 
575 	return err;
576 }
577 
578 static int mv88e6xxx_phy_is_internal(struct dsa_switch *ds, int port)
579 {
580 	struct mv88e6xxx_chip *chip = ds->priv;
581 
582 	return port < chip->info->num_internal_phys;
583 }
584 
585 /* We expect the switch to perform auto negotiation if there is a real
586  * phy. However, in the case of a fixed link phy, we force the port
587  * settings from the fixed link settings.
588  */
589 static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
590 				  struct phy_device *phydev)
591 {
592 	struct mv88e6xxx_chip *chip = ds->priv;
593 	int err;
594 
595 	if (!phy_is_pseudo_fixed_link(phydev) &&
596 	    mv88e6xxx_phy_is_internal(ds, port))
597 		return;
598 
599 	mutex_lock(&chip->reg_lock);
600 	err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
601 				       phydev->duplex, phydev->pause,
602 				       phydev->interface);
603 	mutex_unlock(&chip->reg_lock);
604 
605 	if (err && err != -EOPNOTSUPP)
606 		dev_err(ds->dev, "p%d: failed to configure MAC\n", port);
607 }
608 
609 static void mv88e6065_phylink_validate(struct mv88e6xxx_chip *chip, int port,
610 				       unsigned long *mask,
611 				       struct phylink_link_state *state)
612 {
613 	if (!phy_interface_mode_is_8023z(state->interface)) {
614 		/* 10M and 100M are only supported in non-802.3z mode */
615 		phylink_set(mask, 10baseT_Half);
616 		phylink_set(mask, 10baseT_Full);
617 		phylink_set(mask, 100baseT_Half);
618 		phylink_set(mask, 100baseT_Full);
619 	}
620 }
621 
622 static void mv88e6185_phylink_validate(struct mv88e6xxx_chip *chip, int port,
623 				       unsigned long *mask,
624 				       struct phylink_link_state *state)
625 {
626 	/* FIXME: if the port is in 1000Base-X mode, then it only supports
627 	 * 1000M FD speeds.  In this case, CMODE will indicate 5.
628 	 */
629 	phylink_set(mask, 1000baseT_Full);
630 	phylink_set(mask, 1000baseX_Full);
631 
632 	mv88e6065_phylink_validate(chip, port, mask, state);
633 }
634 
635 static void mv88e6352_phylink_validate(struct mv88e6xxx_chip *chip, int port,
636 				       unsigned long *mask,
637 				       struct phylink_link_state *state)
638 {
639 	/* No ethtool bits for 200Mbps */
640 	phylink_set(mask, 1000baseT_Full);
641 	phylink_set(mask, 1000baseX_Full);
642 
643 	mv88e6065_phylink_validate(chip, port, mask, state);
644 }
645 
646 static void mv88e6390_phylink_validate(struct mv88e6xxx_chip *chip, int port,
647 				       unsigned long *mask,
648 				       struct phylink_link_state *state)
649 {
650 	if (port >= 9)
651 		phylink_set(mask, 2500baseX_Full);
652 
653 	/* No ethtool bits for 200Mbps */
654 	phylink_set(mask, 1000baseT_Full);
655 	phylink_set(mask, 1000baseX_Full);
656 
657 	mv88e6065_phylink_validate(chip, port, mask, state);
658 }
659 
660 static void mv88e6390x_phylink_validate(struct mv88e6xxx_chip *chip, int port,
661 					unsigned long *mask,
662 					struct phylink_link_state *state)
663 {
664 	if (port >= 9) {
665 		phylink_set(mask, 10000baseT_Full);
666 		phylink_set(mask, 10000baseKR_Full);
667 	}
668 
669 	mv88e6390_phylink_validate(chip, port, mask, state);
670 }
671 
672 static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
673 			       unsigned long *supported,
674 			       struct phylink_link_state *state)
675 {
676 	__ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
677 	struct mv88e6xxx_chip *chip = ds->priv;
678 
679 	/* Allow all the expected bits */
680 	phylink_set(mask, Autoneg);
681 	phylink_set(mask, Pause);
682 	phylink_set_port_modes(mask);
683 
684 	if (chip->info->ops->phylink_validate)
685 		chip->info->ops->phylink_validate(chip, port, mask, state);
686 
687 	bitmap_and(supported, supported, mask, __ETHTOOL_LINK_MODE_MASK_NBITS);
688 	bitmap_and(state->advertising, state->advertising, mask,
689 		   __ETHTOOL_LINK_MODE_MASK_NBITS);
690 
691 	/* We can only operate at 2500BaseX or 1000BaseX.  If requested
692 	 * to advertise both, only report advertising at 2500BaseX.
693 	 */
694 	phylink_helper_basex_speed(state);
695 }
696 
697 static int mv88e6xxx_link_state(struct dsa_switch *ds, int port,
698 				struct phylink_link_state *state)
699 {
700 	struct mv88e6xxx_chip *chip = ds->priv;
701 	int err;
702 
703 	mutex_lock(&chip->reg_lock);
704 	if (chip->info->ops->port_link_state)
705 		err = chip->info->ops->port_link_state(chip, port, state);
706 	else
707 		err = -EOPNOTSUPP;
708 	mutex_unlock(&chip->reg_lock);
709 
710 	return err;
711 }
712 
713 static void mv88e6xxx_mac_config(struct dsa_switch *ds, int port,
714 				 unsigned int mode,
715 				 const struct phylink_link_state *state)
716 {
717 	struct mv88e6xxx_chip *chip = ds->priv;
718 	int speed, duplex, link, pause, err;
719 
720 	if ((mode == MLO_AN_PHY) && mv88e6xxx_phy_is_internal(ds, port))
721 		return;
722 
723 	if (mode == MLO_AN_FIXED) {
724 		link = LINK_FORCED_UP;
725 		speed = state->speed;
726 		duplex = state->duplex;
727 	} else if (!mv88e6xxx_phy_is_internal(ds, port)) {
728 		link = state->link;
729 		speed = state->speed;
730 		duplex = state->duplex;
731 	} else {
732 		speed = SPEED_UNFORCED;
733 		duplex = DUPLEX_UNFORCED;
734 		link = LINK_UNFORCED;
735 	}
736 	pause = !!phylink_test(state->advertising, Pause);
737 
738 	mutex_lock(&chip->reg_lock);
739 	err = mv88e6xxx_port_setup_mac(chip, port, link, speed, duplex, pause,
740 				       state->interface);
741 	mutex_unlock(&chip->reg_lock);
742 
743 	if (err && err != -EOPNOTSUPP)
744 		dev_err(ds->dev, "p%d: failed to configure MAC\n", port);
745 }
746 
747 static void mv88e6xxx_mac_link_force(struct dsa_switch *ds, int port, int link)
748 {
749 	struct mv88e6xxx_chip *chip = ds->priv;
750 	int err;
751 
752 	mutex_lock(&chip->reg_lock);
753 	err = chip->info->ops->port_set_link(chip, port, link);
754 	mutex_unlock(&chip->reg_lock);
755 
756 	if (err)
757 		dev_err(chip->dev, "p%d: failed to force MAC link\n", port);
758 }
759 
760 static void mv88e6xxx_mac_link_down(struct dsa_switch *ds, int port,
761 				    unsigned int mode,
762 				    phy_interface_t interface)
763 {
764 	if (mode == MLO_AN_FIXED)
765 		mv88e6xxx_mac_link_force(ds, port, LINK_FORCED_DOWN);
766 }
767 
768 static void mv88e6xxx_mac_link_up(struct dsa_switch *ds, int port,
769 				  unsigned int mode, phy_interface_t interface,
770 				  struct phy_device *phydev)
771 {
772 	if (mode == MLO_AN_FIXED)
773 		mv88e6xxx_mac_link_force(ds, port, LINK_FORCED_UP);
774 }
775 
776 static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
777 {
778 	if (!chip->info->ops->stats_snapshot)
779 		return -EOPNOTSUPP;
780 
781 	return chip->info->ops->stats_snapshot(chip, port);
782 }
783 
784 static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
785 	{ "in_good_octets",		8, 0x00, STATS_TYPE_BANK0, },
786 	{ "in_bad_octets",		4, 0x02, STATS_TYPE_BANK0, },
787 	{ "in_unicast",			4, 0x04, STATS_TYPE_BANK0, },
788 	{ "in_broadcasts",		4, 0x06, STATS_TYPE_BANK0, },
789 	{ "in_multicasts",		4, 0x07, STATS_TYPE_BANK0, },
790 	{ "in_pause",			4, 0x16, STATS_TYPE_BANK0, },
791 	{ "in_undersize",		4, 0x18, STATS_TYPE_BANK0, },
792 	{ "in_fragments",		4, 0x19, STATS_TYPE_BANK0, },
793 	{ "in_oversize",		4, 0x1a, STATS_TYPE_BANK0, },
794 	{ "in_jabber",			4, 0x1b, STATS_TYPE_BANK0, },
795 	{ "in_rx_error",		4, 0x1c, STATS_TYPE_BANK0, },
796 	{ "in_fcs_error",		4, 0x1d, STATS_TYPE_BANK0, },
797 	{ "out_octets",			8, 0x0e, STATS_TYPE_BANK0, },
798 	{ "out_unicast",		4, 0x10, STATS_TYPE_BANK0, },
799 	{ "out_broadcasts",		4, 0x13, STATS_TYPE_BANK0, },
800 	{ "out_multicasts",		4, 0x12, STATS_TYPE_BANK0, },
801 	{ "out_pause",			4, 0x15, STATS_TYPE_BANK0, },
802 	{ "excessive",			4, 0x11, STATS_TYPE_BANK0, },
803 	{ "collisions",			4, 0x1e, STATS_TYPE_BANK0, },
804 	{ "deferred",			4, 0x05, STATS_TYPE_BANK0, },
805 	{ "single",			4, 0x14, STATS_TYPE_BANK0, },
806 	{ "multiple",			4, 0x17, STATS_TYPE_BANK0, },
807 	{ "out_fcs_error",		4, 0x03, STATS_TYPE_BANK0, },
808 	{ "late",			4, 0x1f, STATS_TYPE_BANK0, },
809 	{ "hist_64bytes",		4, 0x08, STATS_TYPE_BANK0, },
810 	{ "hist_65_127bytes",		4, 0x09, STATS_TYPE_BANK0, },
811 	{ "hist_128_255bytes",		4, 0x0a, STATS_TYPE_BANK0, },
812 	{ "hist_256_511bytes",		4, 0x0b, STATS_TYPE_BANK0, },
813 	{ "hist_512_1023bytes",		4, 0x0c, STATS_TYPE_BANK0, },
814 	{ "hist_1024_max_bytes",	4, 0x0d, STATS_TYPE_BANK0, },
815 	{ "sw_in_discards",		4, 0x10, STATS_TYPE_PORT, },
816 	{ "sw_in_filtered",		2, 0x12, STATS_TYPE_PORT, },
817 	{ "sw_out_filtered",		2, 0x13, STATS_TYPE_PORT, },
818 	{ "in_discards",		4, 0x00, STATS_TYPE_BANK1, },
819 	{ "in_filtered",		4, 0x01, STATS_TYPE_BANK1, },
820 	{ "in_accepted",		4, 0x02, STATS_TYPE_BANK1, },
821 	{ "in_bad_accepted",		4, 0x03, STATS_TYPE_BANK1, },
822 	{ "in_good_avb_class_a",	4, 0x04, STATS_TYPE_BANK1, },
823 	{ "in_good_avb_class_b",	4, 0x05, STATS_TYPE_BANK1, },
824 	{ "in_bad_avb_class_a",		4, 0x06, STATS_TYPE_BANK1, },
825 	{ "in_bad_avb_class_b",		4, 0x07, STATS_TYPE_BANK1, },
826 	{ "tcam_counter_0",		4, 0x08, STATS_TYPE_BANK1, },
827 	{ "tcam_counter_1",		4, 0x09, STATS_TYPE_BANK1, },
828 	{ "tcam_counter_2",		4, 0x0a, STATS_TYPE_BANK1, },
829 	{ "tcam_counter_3",		4, 0x0b, STATS_TYPE_BANK1, },
830 	{ "in_da_unknown",		4, 0x0e, STATS_TYPE_BANK1, },
831 	{ "in_management",		4, 0x0f, STATS_TYPE_BANK1, },
832 	{ "out_queue_0",		4, 0x10, STATS_TYPE_BANK1, },
833 	{ "out_queue_1",		4, 0x11, STATS_TYPE_BANK1, },
834 	{ "out_queue_2",		4, 0x12, STATS_TYPE_BANK1, },
835 	{ "out_queue_3",		4, 0x13, STATS_TYPE_BANK1, },
836 	{ "out_queue_4",		4, 0x14, STATS_TYPE_BANK1, },
837 	{ "out_queue_5",		4, 0x15, STATS_TYPE_BANK1, },
838 	{ "out_queue_6",		4, 0x16, STATS_TYPE_BANK1, },
839 	{ "out_queue_7",		4, 0x17, STATS_TYPE_BANK1, },
840 	{ "out_cut_through",		4, 0x18, STATS_TYPE_BANK1, },
841 	{ "out_octets_a",		4, 0x1a, STATS_TYPE_BANK1, },
842 	{ "out_octets_b",		4, 0x1b, STATS_TYPE_BANK1, },
843 	{ "out_management",		4, 0x1f, STATS_TYPE_BANK1, },
844 };
845 
846 static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
847 					    struct mv88e6xxx_hw_stat *s,
848 					    int port, u16 bank1_select,
849 					    u16 histogram)
850 {
851 	u32 low;
852 	u32 high = 0;
853 	u16 reg = 0;
854 	int err;
855 	u64 value;
856 
857 	switch (s->type) {
858 	case STATS_TYPE_PORT:
859 		err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
860 		if (err)
861 			return U64_MAX;
862 
863 		low = reg;
864 		if (s->size == 4) {
865 			err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
866 			if (err)
867 				return U64_MAX;
868 			high = reg;
869 		}
870 		break;
871 	case STATS_TYPE_BANK1:
872 		reg = bank1_select;
873 		/* fall through */
874 	case STATS_TYPE_BANK0:
875 		reg |= s->reg | histogram;
876 		mv88e6xxx_g1_stats_read(chip, reg, &low);
877 		if (s->size == 8)
878 			mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
879 		break;
880 	default:
881 		return U64_MAX;
882 	}
883 	value = (((u64)high) << 16) | low;
884 	return value;
885 }
886 
887 static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
888 				       uint8_t *data, int types)
889 {
890 	struct mv88e6xxx_hw_stat *stat;
891 	int i, j;
892 
893 	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
894 		stat = &mv88e6xxx_hw_stats[i];
895 		if (stat->type & types) {
896 			memcpy(data + j * ETH_GSTRING_LEN, stat->string,
897 			       ETH_GSTRING_LEN);
898 			j++;
899 		}
900 	}
901 
902 	return j;
903 }
904 
905 static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
906 				       uint8_t *data)
907 {
908 	return mv88e6xxx_stats_get_strings(chip, data,
909 					   STATS_TYPE_BANK0 | STATS_TYPE_PORT);
910 }
911 
912 static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
913 				       uint8_t *data)
914 {
915 	return mv88e6xxx_stats_get_strings(chip, data,
916 					   STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
917 }
918 
919 static const uint8_t *mv88e6xxx_atu_vtu_stats_strings[] = {
920 	"atu_member_violation",
921 	"atu_miss_violation",
922 	"atu_full_violation",
923 	"vtu_member_violation",
924 	"vtu_miss_violation",
925 };
926 
927 static void mv88e6xxx_atu_vtu_get_strings(uint8_t *data)
928 {
929 	unsigned int i;
930 
931 	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings); i++)
932 		strlcpy(data + i * ETH_GSTRING_LEN,
933 			mv88e6xxx_atu_vtu_stats_strings[i],
934 			ETH_GSTRING_LEN);
935 }
936 
937 static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
938 				  u32 stringset, uint8_t *data)
939 {
940 	struct mv88e6xxx_chip *chip = ds->priv;
941 	int count = 0;
942 
943 	if (stringset != ETH_SS_STATS)
944 		return;
945 
946 	mutex_lock(&chip->reg_lock);
947 
948 	if (chip->info->ops->stats_get_strings)
949 		count = chip->info->ops->stats_get_strings(chip, data);
950 
951 	if (chip->info->ops->serdes_get_strings) {
952 		data += count * ETH_GSTRING_LEN;
953 		count = chip->info->ops->serdes_get_strings(chip, port, data);
954 	}
955 
956 	data += count * ETH_GSTRING_LEN;
957 	mv88e6xxx_atu_vtu_get_strings(data);
958 
959 	mutex_unlock(&chip->reg_lock);
960 }
961 
962 static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
963 					  int types)
964 {
965 	struct mv88e6xxx_hw_stat *stat;
966 	int i, j;
967 
968 	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
969 		stat = &mv88e6xxx_hw_stats[i];
970 		if (stat->type & types)
971 			j++;
972 	}
973 	return j;
974 }
975 
976 static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
977 {
978 	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
979 					      STATS_TYPE_PORT);
980 }
981 
982 static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
983 {
984 	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
985 					      STATS_TYPE_BANK1);
986 }
987 
988 static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
989 {
990 	struct mv88e6xxx_chip *chip = ds->priv;
991 	int serdes_count = 0;
992 	int count = 0;
993 
994 	if (sset != ETH_SS_STATS)
995 		return 0;
996 
997 	mutex_lock(&chip->reg_lock);
998 	if (chip->info->ops->stats_get_sset_count)
999 		count = chip->info->ops->stats_get_sset_count(chip);
1000 	if (count < 0)
1001 		goto out;
1002 
1003 	if (chip->info->ops->serdes_get_sset_count)
1004 		serdes_count = chip->info->ops->serdes_get_sset_count(chip,
1005 								      port);
1006 	if (serdes_count < 0) {
1007 		count = serdes_count;
1008 		goto out;
1009 	}
1010 	count += serdes_count;
1011 	count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);
1012 
1013 out:
1014 	mutex_unlock(&chip->reg_lock);
1015 
1016 	return count;
1017 }
1018 
1019 static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1020 				     uint64_t *data, int types,
1021 				     u16 bank1_select, u16 histogram)
1022 {
1023 	struct mv88e6xxx_hw_stat *stat;
1024 	int i, j;
1025 
1026 	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
1027 		stat = &mv88e6xxx_hw_stats[i];
1028 		if (stat->type & types) {
1029 			mutex_lock(&chip->reg_lock);
1030 			data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
1031 							      bank1_select,
1032 							      histogram);
1033 			mutex_unlock(&chip->reg_lock);
1034 
1035 			j++;
1036 		}
1037 	}
1038 	return j;
1039 }
1040 
1041 static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1042 				     uint64_t *data)
1043 {
1044 	return mv88e6xxx_stats_get_stats(chip, port, data,
1045 					 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
1046 					 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1047 }
1048 
1049 static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1050 				     uint64_t *data)
1051 {
1052 	return mv88e6xxx_stats_get_stats(chip, port, data,
1053 					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1054 					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
1055 					 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1056 }
1057 
1058 static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1059 				     uint64_t *data)
1060 {
1061 	return mv88e6xxx_stats_get_stats(chip, port, data,
1062 					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1063 					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
1064 					 0);
1065 }
1066 
1067 static void mv88e6xxx_atu_vtu_get_stats(struct mv88e6xxx_chip *chip, int port,
1068 					uint64_t *data)
1069 {
1070 	*data++ = chip->ports[port].atu_member_violation;
1071 	*data++ = chip->ports[port].atu_miss_violation;
1072 	*data++ = chip->ports[port].atu_full_violation;
1073 	*data++ = chip->ports[port].vtu_member_violation;
1074 	*data++ = chip->ports[port].vtu_miss_violation;
1075 }
1076 
1077 static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
1078 				uint64_t *data)
1079 {
1080 	int count = 0;
1081 
1082 	if (chip->info->ops->stats_get_stats)
1083 		count = chip->info->ops->stats_get_stats(chip, port, data);
1084 
1085 	mutex_lock(&chip->reg_lock);
1086 	if (chip->info->ops->serdes_get_stats) {
1087 		data += count;
1088 		count = chip->info->ops->serdes_get_stats(chip, port, data);
1089 	}
1090 	data += count;
1091 	mv88e6xxx_atu_vtu_get_stats(chip, port, data);
1092 	mutex_unlock(&chip->reg_lock);
1093 }
1094 
1095 static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
1096 					uint64_t *data)
1097 {
1098 	struct mv88e6xxx_chip *chip = ds->priv;
1099 	int ret;
1100 
1101 	mutex_lock(&chip->reg_lock);
1102 
1103 	ret = mv88e6xxx_stats_snapshot(chip, port);
1104 	mutex_unlock(&chip->reg_lock);
1105 
1106 	if (ret < 0)
1107 		return;
1108 
1109 	mv88e6xxx_get_stats(chip, port, data);
1110 
1111 }
1112 
1113 static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
1114 {
1115 	return 32 * sizeof(u16);
1116 }
1117 
1118 static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1119 			       struct ethtool_regs *regs, void *_p)
1120 {
1121 	struct mv88e6xxx_chip *chip = ds->priv;
1122 	int err;
1123 	u16 reg;
1124 	u16 *p = _p;
1125 	int i;
1126 
1127 	regs->version = 0;
1128 
1129 	memset(p, 0xff, 32 * sizeof(u16));
1130 
1131 	mutex_lock(&chip->reg_lock);
1132 
1133 	for (i = 0; i < 32; i++) {
1134 
1135 		err = mv88e6xxx_port_read(chip, port, i, &reg);
1136 		if (!err)
1137 			p[i] = reg;
1138 	}
1139 
1140 	mutex_unlock(&chip->reg_lock);
1141 }
1142 
1143 static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
1144 				 struct ethtool_eee *e)
1145 {
1146 	/* Nothing to do on the port's MAC */
1147 	return 0;
1148 }
1149 
1150 static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
1151 				 struct ethtool_eee *e)
1152 {
1153 	/* Nothing to do on the port's MAC */
1154 	return 0;
1155 }
1156 
1157 static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
1158 {
1159 	struct dsa_switch *ds = NULL;
1160 	struct net_device *br;
1161 	u16 pvlan;
1162 	int i;
1163 
1164 	if (dev < DSA_MAX_SWITCHES)
1165 		ds = chip->ds->dst->ds[dev];
1166 
1167 	/* Prevent frames from unknown switch or port */
1168 	if (!ds || port >= ds->num_ports)
1169 		return 0;
1170 
1171 	/* Frames from DSA links and CPU ports can egress any local port */
1172 	if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
1173 		return mv88e6xxx_port_mask(chip);
1174 
1175 	br = ds->ports[port].bridge_dev;
1176 	pvlan = 0;
1177 
1178 	/* Frames from user ports can egress any local DSA links and CPU ports,
1179 	 * as well as any local member of their bridge group.
1180 	 */
1181 	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1182 		if (dsa_is_cpu_port(chip->ds, i) ||
1183 		    dsa_is_dsa_port(chip->ds, i) ||
1184 		    (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
1185 			pvlan |= BIT(i);
1186 
1187 	return pvlan;
1188 }
1189 
1190 static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
1191 {
1192 	u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
1193 
1194 	/* prevent frames from going back out of the port they came in on */
1195 	output_ports &= ~BIT(port);
1196 
1197 	return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
1198 }
1199 
1200 static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1201 					 u8 state)
1202 {
1203 	struct mv88e6xxx_chip *chip = ds->priv;
1204 	int err;
1205 
1206 	mutex_lock(&chip->reg_lock);
1207 	err = mv88e6xxx_port_set_state(chip, port, state);
1208 	mutex_unlock(&chip->reg_lock);
1209 
1210 	if (err)
1211 		dev_err(ds->dev, "p%d: failed to update state\n", port);
1212 }
1213 
1214 static int mv88e6xxx_pri_setup(struct mv88e6xxx_chip *chip)
1215 {
1216 	int err;
1217 
1218 	if (chip->info->ops->ieee_pri_map) {
1219 		err = chip->info->ops->ieee_pri_map(chip);
1220 		if (err)
1221 			return err;
1222 	}
1223 
1224 	if (chip->info->ops->ip_pri_map) {
1225 		err = chip->info->ops->ip_pri_map(chip);
1226 		if (err)
1227 			return err;
1228 	}
1229 
1230 	return 0;
1231 }
1232 
1233 static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
1234 {
1235 	int target, port;
1236 	int err;
1237 
1238 	if (!chip->info->global2_addr)
1239 		return 0;
1240 
1241 	/* Initialize the routing port to the 32 possible target devices */
1242 	for (target = 0; target < 32; target++) {
1243 		port = 0x1f;
1244 		if (target < DSA_MAX_SWITCHES)
1245 			if (chip->ds->rtable[target] != DSA_RTABLE_NONE)
1246 				port = chip->ds->rtable[target];
1247 
1248 		err = mv88e6xxx_g2_device_mapping_write(chip, target, port);
1249 		if (err)
1250 			return err;
1251 	}
1252 
1253 	if (chip->info->ops->set_cascade_port) {
1254 		port = MV88E6XXX_CASCADE_PORT_MULTIPLE;
1255 		err = chip->info->ops->set_cascade_port(chip, port);
1256 		if (err)
1257 			return err;
1258 	}
1259 
1260 	err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
1261 	if (err)
1262 		return err;
1263 
1264 	return 0;
1265 }
1266 
1267 static int mv88e6xxx_trunk_setup(struct mv88e6xxx_chip *chip)
1268 {
1269 	/* Clear all trunk masks and mapping */
1270 	if (chip->info->global2_addr)
1271 		return mv88e6xxx_g2_trunk_clear(chip);
1272 
1273 	return 0;
1274 }
1275 
1276 static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
1277 {
1278 	if (chip->info->ops->rmu_disable)
1279 		return chip->info->ops->rmu_disable(chip);
1280 
1281 	return 0;
1282 }
1283 
1284 static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
1285 {
1286 	if (chip->info->ops->pot_clear)
1287 		return chip->info->ops->pot_clear(chip);
1288 
1289 	return 0;
1290 }
1291 
1292 static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
1293 {
1294 	if (chip->info->ops->mgmt_rsvd2cpu)
1295 		return chip->info->ops->mgmt_rsvd2cpu(chip);
1296 
1297 	return 0;
1298 }
1299 
1300 static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1301 {
1302 	int err;
1303 
1304 	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1305 	if (err)
1306 		return err;
1307 
1308 	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1309 	if (err)
1310 		return err;
1311 
1312 	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1313 }
1314 
1315 static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
1316 {
1317 	int port;
1318 	int err;
1319 
1320 	if (!chip->info->ops->irl_init_all)
1321 		return 0;
1322 
1323 	for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1324 		/* Disable ingress rate limiting by resetting all per port
1325 		 * ingress rate limit resources to their initial state.
1326 		 */
1327 		err = chip->info->ops->irl_init_all(chip, port);
1328 		if (err)
1329 			return err;
1330 	}
1331 
1332 	return 0;
1333 }
1334 
1335 static int mv88e6xxx_mac_setup(struct mv88e6xxx_chip *chip)
1336 {
1337 	if (chip->info->ops->set_switch_mac) {
1338 		u8 addr[ETH_ALEN];
1339 
1340 		eth_random_addr(addr);
1341 
1342 		return chip->info->ops->set_switch_mac(chip, addr);
1343 	}
1344 
1345 	return 0;
1346 }
1347 
1348 static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1349 {
1350 	u16 pvlan = 0;
1351 
1352 	if (!mv88e6xxx_has_pvt(chip))
1353 		return -EOPNOTSUPP;
1354 
1355 	/* Skip the local source device, which uses in-chip port VLAN */
1356 	if (dev != chip->ds->index)
1357 		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1358 
1359 	return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1360 }
1361 
1362 static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1363 {
1364 	int dev, port;
1365 	int err;
1366 
1367 	if (!mv88e6xxx_has_pvt(chip))
1368 		return 0;
1369 
1370 	/* Clear 5 Bit Port for usage with Marvell Link Street devices:
1371 	 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1372 	 */
1373 	err = mv88e6xxx_g2_misc_4_bit_port(chip);
1374 	if (err)
1375 		return err;
1376 
1377 	for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1378 		for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1379 			err = mv88e6xxx_pvt_map(chip, dev, port);
1380 			if (err)
1381 				return err;
1382 		}
1383 	}
1384 
1385 	return 0;
1386 }
1387 
1388 static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1389 {
1390 	struct mv88e6xxx_chip *chip = ds->priv;
1391 	int err;
1392 
1393 	mutex_lock(&chip->reg_lock);
1394 	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1395 	mutex_unlock(&chip->reg_lock);
1396 
1397 	if (err)
1398 		dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
1399 }
1400 
1401 static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1402 {
1403 	if (!chip->info->max_vid)
1404 		return 0;
1405 
1406 	return mv88e6xxx_g1_vtu_flush(chip);
1407 }
1408 
1409 static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
1410 				 struct mv88e6xxx_vtu_entry *entry)
1411 {
1412 	if (!chip->info->ops->vtu_getnext)
1413 		return -EOPNOTSUPP;
1414 
1415 	return chip->info->ops->vtu_getnext(chip, entry);
1416 }
1417 
1418 static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1419 				   struct mv88e6xxx_vtu_entry *entry)
1420 {
1421 	if (!chip->info->ops->vtu_loadpurge)
1422 		return -EOPNOTSUPP;
1423 
1424 	return chip->info->ops->vtu_loadpurge(chip, entry);
1425 }
1426 
1427 static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1428 {
1429 	DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1430 	struct mv88e6xxx_vtu_entry vlan = {
1431 		.vid = chip->info->max_vid,
1432 	};
1433 	int i, err;
1434 
1435 	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1436 
1437 	/* Set every FID bit used by the (un)bridged ports */
1438 	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1439 		err = mv88e6xxx_port_get_fid(chip, i, fid);
1440 		if (err)
1441 			return err;
1442 
1443 		set_bit(*fid, fid_bitmap);
1444 	}
1445 
1446 	/* Set every FID bit used by the VLAN entries */
1447 	do {
1448 		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1449 		if (err)
1450 			return err;
1451 
1452 		if (!vlan.valid)
1453 			break;
1454 
1455 		set_bit(vlan.fid, fid_bitmap);
1456 	} while (vlan.vid < chip->info->max_vid);
1457 
1458 	/* The reset value 0x000 is used to indicate that multiple address
1459 	 * databases are not needed. Return the next positive available.
1460 	 */
1461 	*fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
1462 	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1463 		return -ENOSPC;
1464 
1465 	/* Clear the database */
1466 	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1467 }
1468 
1469 static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
1470 			     struct mv88e6xxx_vtu_entry *entry, bool new)
1471 {
1472 	int err;
1473 
1474 	if (!vid)
1475 		return -EINVAL;
1476 
1477 	entry->vid = vid - 1;
1478 	entry->valid = false;
1479 
1480 	err = mv88e6xxx_vtu_getnext(chip, entry);
1481 	if (err)
1482 		return err;
1483 
1484 	if (entry->vid == vid && entry->valid)
1485 		return 0;
1486 
1487 	if (new) {
1488 		int i;
1489 
1490 		/* Initialize a fresh VLAN entry */
1491 		memset(entry, 0, sizeof(*entry));
1492 		entry->valid = true;
1493 		entry->vid = vid;
1494 
1495 		/* Exclude all ports */
1496 		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1497 			entry->member[i] =
1498 				MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1499 
1500 		return mv88e6xxx_atu_new(chip, &entry->fid);
1501 	}
1502 
1503 	/* switchdev expects -EOPNOTSUPP to honor software VLANs */
1504 	return -EOPNOTSUPP;
1505 }
1506 
1507 static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1508 					u16 vid_begin, u16 vid_end)
1509 {
1510 	struct mv88e6xxx_chip *chip = ds->priv;
1511 	struct mv88e6xxx_vtu_entry vlan = {
1512 		.vid = vid_begin - 1,
1513 	};
1514 	int i, err;
1515 
1516 	/* DSA and CPU ports have to be members of multiple vlans */
1517 	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1518 		return 0;
1519 
1520 	if (!vid_begin)
1521 		return -EOPNOTSUPP;
1522 
1523 	mutex_lock(&chip->reg_lock);
1524 
1525 	do {
1526 		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1527 		if (err)
1528 			goto unlock;
1529 
1530 		if (!vlan.valid)
1531 			break;
1532 
1533 		if (vlan.vid > vid_end)
1534 			break;
1535 
1536 		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1537 			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1538 				continue;
1539 
1540 			if (!ds->ports[i].slave)
1541 				continue;
1542 
1543 			if (vlan.member[i] ==
1544 			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1545 				continue;
1546 
1547 			if (dsa_to_port(ds, i)->bridge_dev ==
1548 			    ds->ports[port].bridge_dev)
1549 				break; /* same bridge, check next VLAN */
1550 
1551 			if (!dsa_to_port(ds, i)->bridge_dev)
1552 				continue;
1553 
1554 			dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
1555 				port, vlan.vid, i,
1556 				netdev_name(dsa_to_port(ds, i)->bridge_dev));
1557 			err = -EOPNOTSUPP;
1558 			goto unlock;
1559 		}
1560 	} while (vlan.vid < vid_end);
1561 
1562 unlock:
1563 	mutex_unlock(&chip->reg_lock);
1564 
1565 	return err;
1566 }
1567 
1568 static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1569 					 bool vlan_filtering)
1570 {
1571 	struct mv88e6xxx_chip *chip = ds->priv;
1572 	u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
1573 		MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
1574 	int err;
1575 
1576 	if (!chip->info->max_vid)
1577 		return -EOPNOTSUPP;
1578 
1579 	mutex_lock(&chip->reg_lock);
1580 	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1581 	mutex_unlock(&chip->reg_lock);
1582 
1583 	return err;
1584 }
1585 
1586 static int
1587 mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1588 			    const struct switchdev_obj_port_vlan *vlan)
1589 {
1590 	struct mv88e6xxx_chip *chip = ds->priv;
1591 	int err;
1592 
1593 	if (!chip->info->max_vid)
1594 		return -EOPNOTSUPP;
1595 
1596 	/* If the requested port doesn't belong to the same bridge as the VLAN
1597 	 * members, do not support it (yet) and fallback to software VLAN.
1598 	 */
1599 	err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1600 					   vlan->vid_end);
1601 	if (err)
1602 		return err;
1603 
1604 	/* We don't need any dynamic resource from the kernel (yet),
1605 	 * so skip the prepare phase.
1606 	 */
1607 	return 0;
1608 }
1609 
1610 static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1611 					const unsigned char *addr, u16 vid,
1612 					u8 state)
1613 {
1614 	struct mv88e6xxx_vtu_entry vlan;
1615 	struct mv88e6xxx_atu_entry entry;
1616 	int err;
1617 
1618 	/* Null VLAN ID corresponds to the port private database */
1619 	if (vid == 0)
1620 		err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
1621 	else
1622 		err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1623 	if (err)
1624 		return err;
1625 
1626 	entry.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1627 	ether_addr_copy(entry.mac, addr);
1628 	eth_addr_dec(entry.mac);
1629 
1630 	err = mv88e6xxx_g1_atu_getnext(chip, vlan.fid, &entry);
1631 	if (err)
1632 		return err;
1633 
1634 	/* Initialize a fresh ATU entry if it isn't found */
1635 	if (entry.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED ||
1636 	    !ether_addr_equal(entry.mac, addr)) {
1637 		memset(&entry, 0, sizeof(entry));
1638 		ether_addr_copy(entry.mac, addr);
1639 	}
1640 
1641 	/* Purge the ATU entry only if no port is using it anymore */
1642 	if (state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED) {
1643 		entry.portvec &= ~BIT(port);
1644 		if (!entry.portvec)
1645 			entry.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1646 	} else {
1647 		entry.portvec |= BIT(port);
1648 		entry.state = state;
1649 	}
1650 
1651 	return mv88e6xxx_g1_atu_loadpurge(chip, vlan.fid, &entry);
1652 }
1653 
1654 static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
1655 					u16 vid)
1656 {
1657 	const char broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1658 	u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
1659 
1660 	return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state);
1661 }
1662 
1663 static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid)
1664 {
1665 	int port;
1666 	int err;
1667 
1668 	for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1669 		err = mv88e6xxx_port_add_broadcast(chip, port, vid);
1670 		if (err)
1671 			return err;
1672 	}
1673 
1674 	return 0;
1675 }
1676 
1677 static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
1678 				    u16 vid, u8 member)
1679 {
1680 	struct mv88e6xxx_vtu_entry vlan;
1681 	int err;
1682 
1683 	err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
1684 	if (err)
1685 		return err;
1686 
1687 	vlan.member[port] = member;
1688 
1689 	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1690 	if (err)
1691 		return err;
1692 
1693 	return mv88e6xxx_broadcast_setup(chip, vid);
1694 }
1695 
1696 static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1697 				    const struct switchdev_obj_port_vlan *vlan)
1698 {
1699 	struct mv88e6xxx_chip *chip = ds->priv;
1700 	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1701 	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1702 	u8 member;
1703 	u16 vid;
1704 
1705 	if (!chip->info->max_vid)
1706 		return;
1707 
1708 	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1709 		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1710 	else if (untagged)
1711 		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
1712 	else
1713 		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
1714 
1715 	mutex_lock(&chip->reg_lock);
1716 
1717 	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
1718 		if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
1719 			dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
1720 				vid, untagged ? 'u' : 't');
1721 
1722 	if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1723 		dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
1724 			vlan->vid_end);
1725 
1726 	mutex_unlock(&chip->reg_lock);
1727 }
1728 
1729 static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
1730 				    int port, u16 vid)
1731 {
1732 	struct mv88e6xxx_vtu_entry vlan;
1733 	int i, err;
1734 
1735 	err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1736 	if (err)
1737 		return err;
1738 
1739 	/* Tell switchdev if this VLAN is handled in software */
1740 	if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1741 		return -EOPNOTSUPP;
1742 
1743 	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1744 
1745 	/* keep the VLAN unless all ports are excluded */
1746 	vlan.valid = false;
1747 	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1748 		if (vlan.member[i] !=
1749 		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
1750 			vlan.valid = true;
1751 			break;
1752 		}
1753 	}
1754 
1755 	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1756 	if (err)
1757 		return err;
1758 
1759 	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
1760 }
1761 
1762 static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1763 				   const struct switchdev_obj_port_vlan *vlan)
1764 {
1765 	struct mv88e6xxx_chip *chip = ds->priv;
1766 	u16 pvid, vid;
1767 	int err = 0;
1768 
1769 	if (!chip->info->max_vid)
1770 		return -EOPNOTSUPP;
1771 
1772 	mutex_lock(&chip->reg_lock);
1773 
1774 	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
1775 	if (err)
1776 		goto unlock;
1777 
1778 	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1779 		err = _mv88e6xxx_port_vlan_del(chip, port, vid);
1780 		if (err)
1781 			goto unlock;
1782 
1783 		if (vid == pvid) {
1784 			err = mv88e6xxx_port_set_pvid(chip, port, 0);
1785 			if (err)
1786 				goto unlock;
1787 		}
1788 	}
1789 
1790 unlock:
1791 	mutex_unlock(&chip->reg_lock);
1792 
1793 	return err;
1794 }
1795 
1796 static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1797 				  const unsigned char *addr, u16 vid)
1798 {
1799 	struct mv88e6xxx_chip *chip = ds->priv;
1800 	int err;
1801 
1802 	mutex_lock(&chip->reg_lock);
1803 	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1804 					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1805 	mutex_unlock(&chip->reg_lock);
1806 
1807 	return err;
1808 }
1809 
1810 static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1811 				  const unsigned char *addr, u16 vid)
1812 {
1813 	struct mv88e6xxx_chip *chip = ds->priv;
1814 	int err;
1815 
1816 	mutex_lock(&chip->reg_lock);
1817 	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1818 					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
1819 	mutex_unlock(&chip->reg_lock);
1820 
1821 	return err;
1822 }
1823 
1824 static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
1825 				      u16 fid, u16 vid, int port,
1826 				      dsa_fdb_dump_cb_t *cb, void *data)
1827 {
1828 	struct mv88e6xxx_atu_entry addr;
1829 	bool is_static;
1830 	int err;
1831 
1832 	addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1833 	eth_broadcast_addr(addr.mac);
1834 
1835 	do {
1836 		mutex_lock(&chip->reg_lock);
1837 		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
1838 		mutex_unlock(&chip->reg_lock);
1839 		if (err)
1840 			return err;
1841 
1842 		if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
1843 			break;
1844 
1845 		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
1846 			continue;
1847 
1848 		if (!is_unicast_ether_addr(addr.mac))
1849 			continue;
1850 
1851 		is_static = (addr.state ==
1852 			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1853 		err = cb(addr.mac, vid, is_static, data);
1854 		if (err)
1855 			return err;
1856 	} while (!is_broadcast_ether_addr(addr.mac));
1857 
1858 	return err;
1859 }
1860 
1861 static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1862 				  dsa_fdb_dump_cb_t *cb, void *data)
1863 {
1864 	struct mv88e6xxx_vtu_entry vlan = {
1865 		.vid = chip->info->max_vid,
1866 	};
1867 	u16 fid;
1868 	int err;
1869 
1870 	/* Dump port's default Filtering Information Database (VLAN ID 0) */
1871 	mutex_lock(&chip->reg_lock);
1872 	err = mv88e6xxx_port_get_fid(chip, port, &fid);
1873 	mutex_unlock(&chip->reg_lock);
1874 
1875 	if (err)
1876 		return err;
1877 
1878 	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
1879 	if (err)
1880 		return err;
1881 
1882 	/* Dump VLANs' Filtering Information Databases */
1883 	do {
1884 		mutex_lock(&chip->reg_lock);
1885 		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1886 		mutex_unlock(&chip->reg_lock);
1887 		if (err)
1888 			return err;
1889 
1890 		if (!vlan.valid)
1891 			break;
1892 
1893 		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1894 						 cb, data);
1895 		if (err)
1896 			return err;
1897 	} while (vlan.vid < chip->info->max_vid);
1898 
1899 	return err;
1900 }
1901 
1902 static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1903 				   dsa_fdb_dump_cb_t *cb, void *data)
1904 {
1905 	struct mv88e6xxx_chip *chip = ds->priv;
1906 
1907 	return mv88e6xxx_port_db_dump(chip, port, cb, data);
1908 }
1909 
1910 static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
1911 				struct net_device *br)
1912 {
1913 	struct dsa_switch *ds;
1914 	int port;
1915 	int dev;
1916 	int err;
1917 
1918 	/* Remap the Port VLAN of each local bridge group member */
1919 	for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) {
1920 		if (chip->ds->ports[port].bridge_dev == br) {
1921 			err = mv88e6xxx_port_vlan_map(chip, port);
1922 			if (err)
1923 				return err;
1924 		}
1925 	}
1926 
1927 	if (!mv88e6xxx_has_pvt(chip))
1928 		return 0;
1929 
1930 	/* Remap the Port VLAN of each cross-chip bridge group member */
1931 	for (dev = 0; dev < DSA_MAX_SWITCHES; ++dev) {
1932 		ds = chip->ds->dst->ds[dev];
1933 		if (!ds)
1934 			break;
1935 
1936 		for (port = 0; port < ds->num_ports; ++port) {
1937 			if (ds->ports[port].bridge_dev == br) {
1938 				err = mv88e6xxx_pvt_map(chip, dev, port);
1939 				if (err)
1940 					return err;
1941 			}
1942 		}
1943 	}
1944 
1945 	return 0;
1946 }
1947 
1948 static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
1949 				      struct net_device *br)
1950 {
1951 	struct mv88e6xxx_chip *chip = ds->priv;
1952 	int err;
1953 
1954 	mutex_lock(&chip->reg_lock);
1955 	err = mv88e6xxx_bridge_map(chip, br);
1956 	mutex_unlock(&chip->reg_lock);
1957 
1958 	return err;
1959 }
1960 
1961 static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
1962 					struct net_device *br)
1963 {
1964 	struct mv88e6xxx_chip *chip = ds->priv;
1965 
1966 	mutex_lock(&chip->reg_lock);
1967 	if (mv88e6xxx_bridge_map(chip, br) ||
1968 	    mv88e6xxx_port_vlan_map(chip, port))
1969 		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
1970 	mutex_unlock(&chip->reg_lock);
1971 }
1972 
1973 static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, int dev,
1974 					   int port, struct net_device *br)
1975 {
1976 	struct mv88e6xxx_chip *chip = ds->priv;
1977 	int err;
1978 
1979 	if (!mv88e6xxx_has_pvt(chip))
1980 		return 0;
1981 
1982 	mutex_lock(&chip->reg_lock);
1983 	err = mv88e6xxx_pvt_map(chip, dev, port);
1984 	mutex_unlock(&chip->reg_lock);
1985 
1986 	return err;
1987 }
1988 
1989 static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, int dev,
1990 					     int port, struct net_device *br)
1991 {
1992 	struct mv88e6xxx_chip *chip = ds->priv;
1993 
1994 	if (!mv88e6xxx_has_pvt(chip))
1995 		return;
1996 
1997 	mutex_lock(&chip->reg_lock);
1998 	if (mv88e6xxx_pvt_map(chip, dev, port))
1999 		dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
2000 	mutex_unlock(&chip->reg_lock);
2001 }
2002 
2003 static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2004 {
2005 	if (chip->info->ops->reset)
2006 		return chip->info->ops->reset(chip);
2007 
2008 	return 0;
2009 }
2010 
2011 static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2012 {
2013 	struct gpio_desc *gpiod = chip->reset;
2014 
2015 	/* If there is a GPIO connected to the reset pin, toggle it */
2016 	if (gpiod) {
2017 		gpiod_set_value_cansleep(gpiod, 1);
2018 		usleep_range(10000, 20000);
2019 		gpiod_set_value_cansleep(gpiod, 0);
2020 		usleep_range(10000, 20000);
2021 	}
2022 }
2023 
2024 static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2025 {
2026 	int i, err;
2027 
2028 	/* Set all ports to the Disabled state */
2029 	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2030 		err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
2031 		if (err)
2032 			return err;
2033 	}
2034 
2035 	/* Wait for transmit queues to drain,
2036 	 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2037 	 */
2038 	usleep_range(2000, 4000);
2039 
2040 	return 0;
2041 }
2042 
2043 static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
2044 {
2045 	int err;
2046 
2047 	err = mv88e6xxx_disable_ports(chip);
2048 	if (err)
2049 		return err;
2050 
2051 	mv88e6xxx_hardware_reset(chip);
2052 
2053 	return mv88e6xxx_software_reset(chip);
2054 }
2055 
2056 static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
2057 				   enum mv88e6xxx_frame_mode frame,
2058 				   enum mv88e6xxx_egress_mode egress, u16 etype)
2059 {
2060 	int err;
2061 
2062 	if (!chip->info->ops->port_set_frame_mode)
2063 		return -EOPNOTSUPP;
2064 
2065 	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
2066 	if (err)
2067 		return err;
2068 
2069 	err = chip->info->ops->port_set_frame_mode(chip, port, frame);
2070 	if (err)
2071 		return err;
2072 
2073 	if (chip->info->ops->port_set_ether_type)
2074 		return chip->info->ops->port_set_ether_type(chip, port, etype);
2075 
2076 	return 0;
2077 }
2078 
2079 static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2080 {
2081 	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
2082 				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2083 				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2084 }
2085 
2086 static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
2087 {
2088 	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
2089 				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2090 				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2091 }
2092 
2093 static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
2094 {
2095 	return mv88e6xxx_set_port_mode(chip, port,
2096 				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
2097 				       MV88E6XXX_EGRESS_MODE_ETHERTYPE,
2098 				       ETH_P_EDSA);
2099 }
2100 
2101 static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
2102 {
2103 	if (dsa_is_dsa_port(chip->ds, port))
2104 		return mv88e6xxx_set_port_mode_dsa(chip, port);
2105 
2106 	if (dsa_is_user_port(chip->ds, port))
2107 		return mv88e6xxx_set_port_mode_normal(chip, port);
2108 
2109 	/* Setup CPU port mode depending on its supported tag format */
2110 	if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
2111 		return mv88e6xxx_set_port_mode_dsa(chip, port);
2112 
2113 	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
2114 		return mv88e6xxx_set_port_mode_edsa(chip, port);
2115 
2116 	return -EINVAL;
2117 }
2118 
2119 static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2120 {
2121 	bool message = dsa_is_dsa_port(chip->ds, port);
2122 
2123 	return mv88e6xxx_port_set_message_port(chip, port, message);
2124 }
2125 
2126 static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2127 {
2128 	struct dsa_switch *ds = chip->ds;
2129 	bool flood;
2130 
2131 	/* Upstream ports flood frames with unknown unicast or multicast DA */
2132 	flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
2133 	if (chip->info->ops->port_set_egress_floods)
2134 		return chip->info->ops->port_set_egress_floods(chip, port,
2135 							       flood, flood);
2136 
2137 	return 0;
2138 }
2139 
2140 static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
2141 				  bool on)
2142 {
2143 	if (chip->info->ops->serdes_power)
2144 		return chip->info->ops->serdes_power(chip, port, on);
2145 
2146 	return 0;
2147 }
2148 
2149 static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
2150 {
2151 	struct dsa_switch *ds = chip->ds;
2152 	int upstream_port;
2153 	int err;
2154 
2155 	upstream_port = dsa_upstream_port(ds, port);
2156 	if (chip->info->ops->port_set_upstream_port) {
2157 		err = chip->info->ops->port_set_upstream_port(chip, port,
2158 							      upstream_port);
2159 		if (err)
2160 			return err;
2161 	}
2162 
2163 	if (port == upstream_port) {
2164 		if (chip->info->ops->set_cpu_port) {
2165 			err = chip->info->ops->set_cpu_port(chip,
2166 							    upstream_port);
2167 			if (err)
2168 				return err;
2169 		}
2170 
2171 		if (chip->info->ops->set_egress_port) {
2172 			err = chip->info->ops->set_egress_port(chip,
2173 							       upstream_port);
2174 			if (err)
2175 				return err;
2176 		}
2177 	}
2178 
2179 	return 0;
2180 }
2181 
2182 static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
2183 {
2184 	struct dsa_switch *ds = chip->ds;
2185 	int err;
2186 	u16 reg;
2187 
2188 	chip->ports[port].chip = chip;
2189 	chip->ports[port].port = port;
2190 
2191 	/* MAC Forcing register: don't force link, speed, duplex or flow control
2192 	 * state to any particular values on physical ports, but force the CPU
2193 	 * port and all DSA ports to their maximum bandwidth and full duplex.
2194 	 */
2195 	if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2196 		err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2197 					       SPEED_MAX, DUPLEX_FULL,
2198 					       PAUSE_OFF,
2199 					       PHY_INTERFACE_MODE_NA);
2200 	else
2201 		err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2202 					       SPEED_UNFORCED, DUPLEX_UNFORCED,
2203 					       PAUSE_ON,
2204 					       PHY_INTERFACE_MODE_NA);
2205 	if (err)
2206 		return err;
2207 
2208 	/* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2209 	 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2210 	 * tunneling, determine priority by looking at 802.1p and IP
2211 	 * priority fields (IP prio has precedence), and set STP state
2212 	 * to Forwarding.
2213 	 *
2214 	 * If this is the CPU link, use DSA or EDSA tagging depending
2215 	 * on which tagging mode was configured.
2216 	 *
2217 	 * If this is a link to another switch, use DSA tagging mode.
2218 	 *
2219 	 * If this is the upstream port for this switch, enable
2220 	 * forwarding of unknown unicasts and multicasts.
2221 	 */
2222 	reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
2223 		MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
2224 		MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
2225 	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
2226 	if (err)
2227 		return err;
2228 
2229 	err = mv88e6xxx_setup_port_mode(chip, port);
2230 	if (err)
2231 		return err;
2232 
2233 	err = mv88e6xxx_setup_egress_floods(chip, port);
2234 	if (err)
2235 		return err;
2236 
2237 	/* Enable the SERDES interface for DSA and CPU ports. Normal
2238 	 * ports SERDES are enabled when the port is enabled, thus
2239 	 * saving a bit of power.
2240 	 */
2241 	if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
2242 		err = mv88e6xxx_serdes_power(chip, port, true);
2243 		if (err)
2244 			return err;
2245 	}
2246 
2247 	/* Port Control 2: don't force a good FCS, set the maximum frame size to
2248 	 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
2249 	 * untagged frames on this port, do a destination address lookup on all
2250 	 * received packets as usual, disable ARP mirroring and don't send a
2251 	 * copy of all transmitted/received frames on this port to the CPU.
2252 	 */
2253 	err = mv88e6xxx_port_set_map_da(chip, port);
2254 	if (err)
2255 		return err;
2256 
2257 	err = mv88e6xxx_setup_upstream_port(chip, port);
2258 	if (err)
2259 		return err;
2260 
2261 	err = mv88e6xxx_port_set_8021q_mode(chip, port,
2262 				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
2263 	if (err)
2264 		return err;
2265 
2266 	if (chip->info->ops->port_set_jumbo_size) {
2267 		err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
2268 		if (err)
2269 			return err;
2270 	}
2271 
2272 	/* Port Association Vector: when learning source addresses
2273 	 * of packets, add the address to the address database using
2274 	 * a port bitmap that has only the bit for this port set and
2275 	 * the other bits clear.
2276 	 */
2277 	reg = 1 << port;
2278 	/* Disable learning for CPU port */
2279 	if (dsa_is_cpu_port(ds, port))
2280 		reg = 0;
2281 
2282 	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
2283 				   reg);
2284 	if (err)
2285 		return err;
2286 
2287 	/* Egress rate control 2: disable egress rate control. */
2288 	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
2289 				   0x0000);
2290 	if (err)
2291 		return err;
2292 
2293 	if (chip->info->ops->port_pause_limit) {
2294 		err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
2295 		if (err)
2296 			return err;
2297 	}
2298 
2299 	if (chip->info->ops->port_disable_learn_limit) {
2300 		err = chip->info->ops->port_disable_learn_limit(chip, port);
2301 		if (err)
2302 			return err;
2303 	}
2304 
2305 	if (chip->info->ops->port_disable_pri_override) {
2306 		err = chip->info->ops->port_disable_pri_override(chip, port);
2307 		if (err)
2308 			return err;
2309 	}
2310 
2311 	if (chip->info->ops->port_tag_remap) {
2312 		err = chip->info->ops->port_tag_remap(chip, port);
2313 		if (err)
2314 			return err;
2315 	}
2316 
2317 	if (chip->info->ops->port_egress_rate_limiting) {
2318 		err = chip->info->ops->port_egress_rate_limiting(chip, port);
2319 		if (err)
2320 			return err;
2321 	}
2322 
2323 	err = mv88e6xxx_setup_message_port(chip, port);
2324 	if (err)
2325 		return err;
2326 
2327 	/* Port based VLAN map: give each port the same default address
2328 	 * database, and allow bidirectional communication between the
2329 	 * CPU and DSA port(s), and the other ports.
2330 	 */
2331 	err = mv88e6xxx_port_set_fid(chip, port, 0);
2332 	if (err)
2333 		return err;
2334 
2335 	err = mv88e6xxx_port_vlan_map(chip, port);
2336 	if (err)
2337 		return err;
2338 
2339 	/* Default VLAN ID and priority: don't set a default VLAN
2340 	 * ID, and set the default packet priority to zero.
2341 	 */
2342 	return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
2343 }
2344 
2345 static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
2346 				 struct phy_device *phydev)
2347 {
2348 	struct mv88e6xxx_chip *chip = ds->priv;
2349 	int err;
2350 
2351 	mutex_lock(&chip->reg_lock);
2352 
2353 	err = mv88e6xxx_serdes_power(chip, port, true);
2354 
2355 	if (!err && chip->info->ops->serdes_irq_setup)
2356 		err = chip->info->ops->serdes_irq_setup(chip, port);
2357 
2358 	mutex_unlock(&chip->reg_lock);
2359 
2360 	return err;
2361 }
2362 
2363 static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port,
2364 				   struct phy_device *phydev)
2365 {
2366 	struct mv88e6xxx_chip *chip = ds->priv;
2367 
2368 	mutex_lock(&chip->reg_lock);
2369 
2370 	if (chip->info->ops->serdes_irq_free)
2371 		chip->info->ops->serdes_irq_free(chip, port);
2372 
2373 	if (mv88e6xxx_serdes_power(chip, port, false))
2374 		dev_err(chip->dev, "failed to power off SERDES\n");
2375 
2376 	mutex_unlock(&chip->reg_lock);
2377 }
2378 
2379 static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2380 				     unsigned int ageing_time)
2381 {
2382 	struct mv88e6xxx_chip *chip = ds->priv;
2383 	int err;
2384 
2385 	mutex_lock(&chip->reg_lock);
2386 	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2387 	mutex_unlock(&chip->reg_lock);
2388 
2389 	return err;
2390 }
2391 
2392 static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
2393 {
2394 	int err;
2395 
2396 	/* Initialize the statistics unit */
2397 	if (chip->info->ops->stats_set_histogram) {
2398 		err = chip->info->ops->stats_set_histogram(chip);
2399 		if (err)
2400 			return err;
2401 	}
2402 
2403 	return mv88e6xxx_g1_stats_clear(chip);
2404 }
2405 
2406 static int mv88e6xxx_setup(struct dsa_switch *ds)
2407 {
2408 	struct mv88e6xxx_chip *chip = ds->priv;
2409 	u8 cmode;
2410 	int err;
2411 	int i;
2412 
2413 	chip->ds = ds;
2414 	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
2415 
2416 	mutex_lock(&chip->reg_lock);
2417 
2418 	/* Cache the cmode of each port. */
2419 	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2420 		if (chip->info->ops->port_get_cmode) {
2421 			err = chip->info->ops->port_get_cmode(chip, i, &cmode);
2422 			if (err)
2423 				goto unlock;
2424 
2425 			chip->ports[i].cmode = cmode;
2426 		}
2427 	}
2428 
2429 	/* Setup Switch Port Registers */
2430 	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2431 		if (dsa_is_unused_port(ds, i))
2432 			continue;
2433 
2434 		err = mv88e6xxx_setup_port(chip, i);
2435 		if (err)
2436 			goto unlock;
2437 	}
2438 
2439 	err = mv88e6xxx_irl_setup(chip);
2440 	if (err)
2441 		goto unlock;
2442 
2443 	err = mv88e6xxx_mac_setup(chip);
2444 	if (err)
2445 		goto unlock;
2446 
2447 	err = mv88e6xxx_phy_setup(chip);
2448 	if (err)
2449 		goto unlock;
2450 
2451 	err = mv88e6xxx_vtu_setup(chip);
2452 	if (err)
2453 		goto unlock;
2454 
2455 	err = mv88e6xxx_pvt_setup(chip);
2456 	if (err)
2457 		goto unlock;
2458 
2459 	err = mv88e6xxx_atu_setup(chip);
2460 	if (err)
2461 		goto unlock;
2462 
2463 	err = mv88e6xxx_broadcast_setup(chip, 0);
2464 	if (err)
2465 		goto unlock;
2466 
2467 	err = mv88e6xxx_pot_setup(chip);
2468 	if (err)
2469 		goto unlock;
2470 
2471 	err = mv88e6xxx_rmu_setup(chip);
2472 	if (err)
2473 		goto unlock;
2474 
2475 	err = mv88e6xxx_rsvd2cpu_setup(chip);
2476 	if (err)
2477 		goto unlock;
2478 
2479 	err = mv88e6xxx_trunk_setup(chip);
2480 	if (err)
2481 		goto unlock;
2482 
2483 	err = mv88e6xxx_devmap_setup(chip);
2484 	if (err)
2485 		goto unlock;
2486 
2487 	err = mv88e6xxx_pri_setup(chip);
2488 	if (err)
2489 		goto unlock;
2490 
2491 	/* Setup PTP Hardware Clock and timestamping */
2492 	if (chip->info->ptp_support) {
2493 		err = mv88e6xxx_ptp_setup(chip);
2494 		if (err)
2495 			goto unlock;
2496 
2497 		err = mv88e6xxx_hwtstamp_setup(chip);
2498 		if (err)
2499 			goto unlock;
2500 	}
2501 
2502 	err = mv88e6xxx_stats_setup(chip);
2503 	if (err)
2504 		goto unlock;
2505 
2506 unlock:
2507 	mutex_unlock(&chip->reg_lock);
2508 
2509 	return err;
2510 }
2511 
2512 static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
2513 {
2514 	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2515 	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2516 	u16 val;
2517 	int err;
2518 
2519 	if (!chip->info->ops->phy_read)
2520 		return -EOPNOTSUPP;
2521 
2522 	mutex_lock(&chip->reg_lock);
2523 	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
2524 	mutex_unlock(&chip->reg_lock);
2525 
2526 	if (reg == MII_PHYSID2) {
2527 		/* Some internal PHYS don't have a model number.  Use
2528 		 * the mv88e6390 family model number instead.
2529 		 */
2530 		if (!(val & 0x3f0))
2531 			val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
2532 	}
2533 
2534 	return err ? err : val;
2535 }
2536 
2537 static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
2538 {
2539 	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2540 	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2541 	int err;
2542 
2543 	if (!chip->info->ops->phy_write)
2544 		return -EOPNOTSUPP;
2545 
2546 	mutex_lock(&chip->reg_lock);
2547 	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
2548 	mutex_unlock(&chip->reg_lock);
2549 
2550 	return err;
2551 }
2552 
2553 static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
2554 				   struct device_node *np,
2555 				   bool external)
2556 {
2557 	static int index;
2558 	struct mv88e6xxx_mdio_bus *mdio_bus;
2559 	struct mii_bus *bus;
2560 	int err;
2561 
2562 	if (external) {
2563 		mutex_lock(&chip->reg_lock);
2564 		err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
2565 		mutex_unlock(&chip->reg_lock);
2566 
2567 		if (err)
2568 			return err;
2569 	}
2570 
2571 	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
2572 	if (!bus)
2573 		return -ENOMEM;
2574 
2575 	mdio_bus = bus->priv;
2576 	mdio_bus->bus = bus;
2577 	mdio_bus->chip = chip;
2578 	INIT_LIST_HEAD(&mdio_bus->list);
2579 	mdio_bus->external = external;
2580 
2581 	if (np) {
2582 		bus->name = np->full_name;
2583 		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
2584 	} else {
2585 		bus->name = "mv88e6xxx SMI";
2586 		snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2587 	}
2588 
2589 	bus->read = mv88e6xxx_mdio_read;
2590 	bus->write = mv88e6xxx_mdio_write;
2591 	bus->parent = chip->dev;
2592 
2593 	if (!external) {
2594 		err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
2595 		if (err)
2596 			return err;
2597 	}
2598 
2599 	err = of_mdiobus_register(bus, np);
2600 	if (err) {
2601 		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
2602 		mv88e6xxx_g2_irq_mdio_free(chip, bus);
2603 		return err;
2604 	}
2605 
2606 	if (external)
2607 		list_add_tail(&mdio_bus->list, &chip->mdios);
2608 	else
2609 		list_add(&mdio_bus->list, &chip->mdios);
2610 
2611 	return 0;
2612 }
2613 
2614 static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
2615 	{ .compatible = "marvell,mv88e6xxx-mdio-external",
2616 	  .data = (void *)true },
2617 	{ },
2618 };
2619 
2620 static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
2621 
2622 {
2623 	struct mv88e6xxx_mdio_bus *mdio_bus;
2624 	struct mii_bus *bus;
2625 
2626 	list_for_each_entry(mdio_bus, &chip->mdios, list) {
2627 		bus = mdio_bus->bus;
2628 
2629 		if (!mdio_bus->external)
2630 			mv88e6xxx_g2_irq_mdio_free(chip, bus);
2631 
2632 		mdiobus_unregister(bus);
2633 	}
2634 }
2635 
2636 static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
2637 				    struct device_node *np)
2638 {
2639 	const struct of_device_id *match;
2640 	struct device_node *child;
2641 	int err;
2642 
2643 	/* Always register one mdio bus for the internal/default mdio
2644 	 * bus. This maybe represented in the device tree, but is
2645 	 * optional.
2646 	 */
2647 	child = of_get_child_by_name(np, "mdio");
2648 	err = mv88e6xxx_mdio_register(chip, child, false);
2649 	if (err)
2650 		return err;
2651 
2652 	/* Walk the device tree, and see if there are any other nodes
2653 	 * which say they are compatible with the external mdio
2654 	 * bus.
2655 	 */
2656 	for_each_available_child_of_node(np, child) {
2657 		match = of_match_node(mv88e6xxx_mdio_external_match, child);
2658 		if (match) {
2659 			err = mv88e6xxx_mdio_register(chip, child, true);
2660 			if (err) {
2661 				mv88e6xxx_mdios_unregister(chip);
2662 				return err;
2663 			}
2664 		}
2665 	}
2666 
2667 	return 0;
2668 }
2669 
2670 static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
2671 {
2672 	struct mv88e6xxx_chip *chip = ds->priv;
2673 
2674 	return chip->eeprom_len;
2675 }
2676 
2677 static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
2678 				struct ethtool_eeprom *eeprom, u8 *data)
2679 {
2680 	struct mv88e6xxx_chip *chip = ds->priv;
2681 	int err;
2682 
2683 	if (!chip->info->ops->get_eeprom)
2684 		return -EOPNOTSUPP;
2685 
2686 	mutex_lock(&chip->reg_lock);
2687 	err = chip->info->ops->get_eeprom(chip, eeprom, data);
2688 	mutex_unlock(&chip->reg_lock);
2689 
2690 	if (err)
2691 		return err;
2692 
2693 	eeprom->magic = 0xc3ec4951;
2694 
2695 	return 0;
2696 }
2697 
2698 static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
2699 				struct ethtool_eeprom *eeprom, u8 *data)
2700 {
2701 	struct mv88e6xxx_chip *chip = ds->priv;
2702 	int err;
2703 
2704 	if (!chip->info->ops->set_eeprom)
2705 		return -EOPNOTSUPP;
2706 
2707 	if (eeprom->magic != 0xc3ec4951)
2708 		return -EINVAL;
2709 
2710 	mutex_lock(&chip->reg_lock);
2711 	err = chip->info->ops->set_eeprom(chip, eeprom, data);
2712 	mutex_unlock(&chip->reg_lock);
2713 
2714 	return err;
2715 }
2716 
2717 static const struct mv88e6xxx_ops mv88e6085_ops = {
2718 	/* MV88E6XXX_FAMILY_6097 */
2719 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2720 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2721 	.irl_init_all = mv88e6352_g2_irl_init_all,
2722 	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2723 	.phy_read = mv88e6185_phy_ppu_read,
2724 	.phy_write = mv88e6185_phy_ppu_write,
2725 	.port_set_link = mv88e6xxx_port_set_link,
2726 	.port_set_duplex = mv88e6xxx_port_set_duplex,
2727 	.port_set_speed = mv88e6185_port_set_speed,
2728 	.port_tag_remap = mv88e6095_port_tag_remap,
2729 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2730 	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2731 	.port_set_ether_type = mv88e6351_port_set_ether_type,
2732 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2733 	.port_pause_limit = mv88e6097_port_pause_limit,
2734 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2735 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2736 	.port_link_state = mv88e6352_port_link_state,
2737 	.port_get_cmode = mv88e6185_port_get_cmode,
2738 	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2739 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2740 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
2741 	.stats_get_strings = mv88e6095_stats_get_strings,
2742 	.stats_get_stats = mv88e6095_stats_get_stats,
2743 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
2744 	.set_egress_port = mv88e6095_g1_set_egress_port,
2745 	.watchdog_ops = &mv88e6097_watchdog_ops,
2746 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2747 	.pot_clear = mv88e6xxx_g2_pot_clear,
2748 	.ppu_enable = mv88e6185_g1_ppu_enable,
2749 	.ppu_disable = mv88e6185_g1_ppu_disable,
2750 	.reset = mv88e6185_g1_reset,
2751 	.rmu_disable = mv88e6085_g1_rmu_disable,
2752 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2753 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2754 	.phylink_validate = mv88e6185_phylink_validate,
2755 };
2756 
2757 static const struct mv88e6xxx_ops mv88e6095_ops = {
2758 	/* MV88E6XXX_FAMILY_6095 */
2759 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2760 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2761 	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2762 	.phy_read = mv88e6185_phy_ppu_read,
2763 	.phy_write = mv88e6185_phy_ppu_write,
2764 	.port_set_link = mv88e6xxx_port_set_link,
2765 	.port_set_duplex = mv88e6xxx_port_set_duplex,
2766 	.port_set_speed = mv88e6185_port_set_speed,
2767 	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2768 	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2769 	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2770 	.port_link_state = mv88e6185_port_link_state,
2771 	.port_get_cmode = mv88e6185_port_get_cmode,
2772 	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2773 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2774 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
2775 	.stats_get_strings = mv88e6095_stats_get_strings,
2776 	.stats_get_stats = mv88e6095_stats_get_stats,
2777 	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2778 	.ppu_enable = mv88e6185_g1_ppu_enable,
2779 	.ppu_disable = mv88e6185_g1_ppu_disable,
2780 	.reset = mv88e6185_g1_reset,
2781 	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2782 	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2783 	.phylink_validate = mv88e6185_phylink_validate,
2784 };
2785 
2786 static const struct mv88e6xxx_ops mv88e6097_ops = {
2787 	/* MV88E6XXX_FAMILY_6097 */
2788 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2789 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2790 	.irl_init_all = mv88e6352_g2_irl_init_all,
2791 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2792 	.phy_read = mv88e6xxx_g2_smi_phy_read,
2793 	.phy_write = mv88e6xxx_g2_smi_phy_write,
2794 	.port_set_link = mv88e6xxx_port_set_link,
2795 	.port_set_duplex = mv88e6xxx_port_set_duplex,
2796 	.port_set_speed = mv88e6185_port_set_speed,
2797 	.port_tag_remap = mv88e6095_port_tag_remap,
2798 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2799 	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2800 	.port_set_ether_type = mv88e6351_port_set_ether_type,
2801 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2802 	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
2803 	.port_pause_limit = mv88e6097_port_pause_limit,
2804 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2805 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2806 	.port_link_state = mv88e6352_port_link_state,
2807 	.port_get_cmode = mv88e6185_port_get_cmode,
2808 	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2809 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2810 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
2811 	.stats_get_strings = mv88e6095_stats_get_strings,
2812 	.stats_get_stats = mv88e6095_stats_get_stats,
2813 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
2814 	.set_egress_port = mv88e6095_g1_set_egress_port,
2815 	.watchdog_ops = &mv88e6097_watchdog_ops,
2816 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2817 	.pot_clear = mv88e6xxx_g2_pot_clear,
2818 	.reset = mv88e6352_g1_reset,
2819 	.rmu_disable = mv88e6085_g1_rmu_disable,
2820 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2821 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2822 	.phylink_validate = mv88e6185_phylink_validate,
2823 };
2824 
2825 static const struct mv88e6xxx_ops mv88e6123_ops = {
2826 	/* MV88E6XXX_FAMILY_6165 */
2827 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2828 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2829 	.irl_init_all = mv88e6352_g2_irl_init_all,
2830 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2831 	.phy_read = mv88e6xxx_g2_smi_phy_read,
2832 	.phy_write = mv88e6xxx_g2_smi_phy_write,
2833 	.port_set_link = mv88e6xxx_port_set_link,
2834 	.port_set_duplex = mv88e6xxx_port_set_duplex,
2835 	.port_set_speed = mv88e6185_port_set_speed,
2836 	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2837 	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2838 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2839 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2840 	.port_link_state = mv88e6352_port_link_state,
2841 	.port_get_cmode = mv88e6185_port_get_cmode,
2842 	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2843 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2844 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
2845 	.stats_get_strings = mv88e6095_stats_get_strings,
2846 	.stats_get_stats = mv88e6095_stats_get_stats,
2847 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
2848 	.set_egress_port = mv88e6095_g1_set_egress_port,
2849 	.watchdog_ops = &mv88e6097_watchdog_ops,
2850 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2851 	.pot_clear = mv88e6xxx_g2_pot_clear,
2852 	.reset = mv88e6352_g1_reset,
2853 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2854 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2855 	.phylink_validate = mv88e6185_phylink_validate,
2856 };
2857 
2858 static const struct mv88e6xxx_ops mv88e6131_ops = {
2859 	/* MV88E6XXX_FAMILY_6185 */
2860 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2861 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2862 	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2863 	.phy_read = mv88e6185_phy_ppu_read,
2864 	.phy_write = mv88e6185_phy_ppu_write,
2865 	.port_set_link = mv88e6xxx_port_set_link,
2866 	.port_set_duplex = mv88e6xxx_port_set_duplex,
2867 	.port_set_speed = mv88e6185_port_set_speed,
2868 	.port_tag_remap = mv88e6095_port_tag_remap,
2869 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2870 	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2871 	.port_set_ether_type = mv88e6351_port_set_ether_type,
2872 	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2873 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2874 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2875 	.port_pause_limit = mv88e6097_port_pause_limit,
2876 	.port_set_pause = mv88e6185_port_set_pause,
2877 	.port_link_state = mv88e6352_port_link_state,
2878 	.port_get_cmode = mv88e6185_port_get_cmode,
2879 	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2880 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2881 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
2882 	.stats_get_strings = mv88e6095_stats_get_strings,
2883 	.stats_get_stats = mv88e6095_stats_get_stats,
2884 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
2885 	.set_egress_port = mv88e6095_g1_set_egress_port,
2886 	.watchdog_ops = &mv88e6097_watchdog_ops,
2887 	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2888 	.ppu_enable = mv88e6185_g1_ppu_enable,
2889 	.set_cascade_port = mv88e6185_g1_set_cascade_port,
2890 	.ppu_disable = mv88e6185_g1_ppu_disable,
2891 	.reset = mv88e6185_g1_reset,
2892 	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2893 	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2894 	.phylink_validate = mv88e6185_phylink_validate,
2895 };
2896 
2897 static const struct mv88e6xxx_ops mv88e6141_ops = {
2898 	/* MV88E6XXX_FAMILY_6341 */
2899 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2900 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2901 	.irl_init_all = mv88e6352_g2_irl_init_all,
2902 	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
2903 	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
2904 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2905 	.phy_read = mv88e6xxx_g2_smi_phy_read,
2906 	.phy_write = mv88e6xxx_g2_smi_phy_write,
2907 	.port_set_link = mv88e6xxx_port_set_link,
2908 	.port_set_duplex = mv88e6xxx_port_set_duplex,
2909 	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2910 	.port_set_speed = mv88e6341_port_set_speed,
2911 	.port_tag_remap = mv88e6095_port_tag_remap,
2912 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2913 	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2914 	.port_set_ether_type = mv88e6351_port_set_ether_type,
2915 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2916 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2917 	.port_pause_limit = mv88e6097_port_pause_limit,
2918 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2919 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2920 	.port_link_state = mv88e6352_port_link_state,
2921 	.port_get_cmode = mv88e6352_port_get_cmode,
2922 	.stats_snapshot = mv88e6390_g1_stats_snapshot,
2923 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2924 	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
2925 	.stats_get_strings = mv88e6320_stats_get_strings,
2926 	.stats_get_stats = mv88e6390_stats_get_stats,
2927 	.set_cpu_port = mv88e6390_g1_set_cpu_port,
2928 	.set_egress_port = mv88e6390_g1_set_egress_port,
2929 	.watchdog_ops = &mv88e6390_watchdog_ops,
2930 	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
2931 	.pot_clear = mv88e6xxx_g2_pot_clear,
2932 	.reset = mv88e6352_g1_reset,
2933 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2934 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2935 	.serdes_power = mv88e6341_serdes_power,
2936 	.gpio_ops = &mv88e6352_gpio_ops,
2937 	.phylink_validate = mv88e6390_phylink_validate,
2938 };
2939 
2940 static const struct mv88e6xxx_ops mv88e6161_ops = {
2941 	/* MV88E6XXX_FAMILY_6165 */
2942 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2943 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2944 	.irl_init_all = mv88e6352_g2_irl_init_all,
2945 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2946 	.phy_read = mv88e6xxx_g2_smi_phy_read,
2947 	.phy_write = mv88e6xxx_g2_smi_phy_write,
2948 	.port_set_link = mv88e6xxx_port_set_link,
2949 	.port_set_duplex = mv88e6xxx_port_set_duplex,
2950 	.port_set_speed = mv88e6185_port_set_speed,
2951 	.port_tag_remap = mv88e6095_port_tag_remap,
2952 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2953 	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2954 	.port_set_ether_type = mv88e6351_port_set_ether_type,
2955 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2956 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2957 	.port_pause_limit = mv88e6097_port_pause_limit,
2958 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2959 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2960 	.port_link_state = mv88e6352_port_link_state,
2961 	.port_get_cmode = mv88e6185_port_get_cmode,
2962 	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2963 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2964 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
2965 	.stats_get_strings = mv88e6095_stats_get_strings,
2966 	.stats_get_stats = mv88e6095_stats_get_stats,
2967 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
2968 	.set_egress_port = mv88e6095_g1_set_egress_port,
2969 	.watchdog_ops = &mv88e6097_watchdog_ops,
2970 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2971 	.pot_clear = mv88e6xxx_g2_pot_clear,
2972 	.reset = mv88e6352_g1_reset,
2973 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2974 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2975 	.avb_ops = &mv88e6165_avb_ops,
2976 	.ptp_ops = &mv88e6165_ptp_ops,
2977 	.phylink_validate = mv88e6185_phylink_validate,
2978 };
2979 
2980 static const struct mv88e6xxx_ops mv88e6165_ops = {
2981 	/* MV88E6XXX_FAMILY_6165 */
2982 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2983 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2984 	.irl_init_all = mv88e6352_g2_irl_init_all,
2985 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2986 	.phy_read = mv88e6165_phy_read,
2987 	.phy_write = mv88e6165_phy_write,
2988 	.port_set_link = mv88e6xxx_port_set_link,
2989 	.port_set_duplex = mv88e6xxx_port_set_duplex,
2990 	.port_set_speed = mv88e6185_port_set_speed,
2991 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2992 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2993 	.port_link_state = mv88e6352_port_link_state,
2994 	.port_get_cmode = mv88e6185_port_get_cmode,
2995 	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2996 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2997 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
2998 	.stats_get_strings = mv88e6095_stats_get_strings,
2999 	.stats_get_stats = mv88e6095_stats_get_stats,
3000 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
3001 	.set_egress_port = mv88e6095_g1_set_egress_port,
3002 	.watchdog_ops = &mv88e6097_watchdog_ops,
3003 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3004 	.pot_clear = mv88e6xxx_g2_pot_clear,
3005 	.reset = mv88e6352_g1_reset,
3006 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3007 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3008 	.avb_ops = &mv88e6165_avb_ops,
3009 	.ptp_ops = &mv88e6165_ptp_ops,
3010 	.phylink_validate = mv88e6185_phylink_validate,
3011 };
3012 
3013 static const struct mv88e6xxx_ops mv88e6171_ops = {
3014 	/* MV88E6XXX_FAMILY_6351 */
3015 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3016 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3017 	.irl_init_all = mv88e6352_g2_irl_init_all,
3018 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3019 	.phy_read = mv88e6xxx_g2_smi_phy_read,
3020 	.phy_write = mv88e6xxx_g2_smi_phy_write,
3021 	.port_set_link = mv88e6xxx_port_set_link,
3022 	.port_set_duplex = mv88e6xxx_port_set_duplex,
3023 	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3024 	.port_set_speed = mv88e6185_port_set_speed,
3025 	.port_tag_remap = mv88e6095_port_tag_remap,
3026 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3027 	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3028 	.port_set_ether_type = mv88e6351_port_set_ether_type,
3029 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3030 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3031 	.port_pause_limit = mv88e6097_port_pause_limit,
3032 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3033 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3034 	.port_link_state = mv88e6352_port_link_state,
3035 	.port_get_cmode = mv88e6352_port_get_cmode,
3036 	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3037 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3038 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
3039 	.stats_get_strings = mv88e6095_stats_get_strings,
3040 	.stats_get_stats = mv88e6095_stats_get_stats,
3041 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
3042 	.set_egress_port = mv88e6095_g1_set_egress_port,
3043 	.watchdog_ops = &mv88e6097_watchdog_ops,
3044 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3045 	.pot_clear = mv88e6xxx_g2_pot_clear,
3046 	.reset = mv88e6352_g1_reset,
3047 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3048 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3049 	.phylink_validate = mv88e6185_phylink_validate,
3050 };
3051 
3052 static const struct mv88e6xxx_ops mv88e6172_ops = {
3053 	/* MV88E6XXX_FAMILY_6352 */
3054 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3055 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3056 	.irl_init_all = mv88e6352_g2_irl_init_all,
3057 	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
3058 	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3059 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3060 	.phy_read = mv88e6xxx_g2_smi_phy_read,
3061 	.phy_write = mv88e6xxx_g2_smi_phy_write,
3062 	.port_set_link = mv88e6xxx_port_set_link,
3063 	.port_set_duplex = mv88e6xxx_port_set_duplex,
3064 	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3065 	.port_set_speed = mv88e6352_port_set_speed,
3066 	.port_tag_remap = mv88e6095_port_tag_remap,
3067 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3068 	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3069 	.port_set_ether_type = mv88e6351_port_set_ether_type,
3070 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3071 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3072 	.port_pause_limit = mv88e6097_port_pause_limit,
3073 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3074 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3075 	.port_link_state = mv88e6352_port_link_state,
3076 	.port_get_cmode = mv88e6352_port_get_cmode,
3077 	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3078 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3079 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
3080 	.stats_get_strings = mv88e6095_stats_get_strings,
3081 	.stats_get_stats = mv88e6095_stats_get_stats,
3082 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
3083 	.set_egress_port = mv88e6095_g1_set_egress_port,
3084 	.watchdog_ops = &mv88e6097_watchdog_ops,
3085 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3086 	.pot_clear = mv88e6xxx_g2_pot_clear,
3087 	.reset = mv88e6352_g1_reset,
3088 	.rmu_disable = mv88e6352_g1_rmu_disable,
3089 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3090 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3091 	.serdes_power = mv88e6352_serdes_power,
3092 	.gpio_ops = &mv88e6352_gpio_ops,
3093 	.phylink_validate = mv88e6352_phylink_validate,
3094 };
3095 
3096 static const struct mv88e6xxx_ops mv88e6175_ops = {
3097 	/* MV88E6XXX_FAMILY_6351 */
3098 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3099 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3100 	.irl_init_all = mv88e6352_g2_irl_init_all,
3101 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3102 	.phy_read = mv88e6xxx_g2_smi_phy_read,
3103 	.phy_write = mv88e6xxx_g2_smi_phy_write,
3104 	.port_set_link = mv88e6xxx_port_set_link,
3105 	.port_set_duplex = mv88e6xxx_port_set_duplex,
3106 	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3107 	.port_set_speed = mv88e6185_port_set_speed,
3108 	.port_tag_remap = mv88e6095_port_tag_remap,
3109 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3110 	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3111 	.port_set_ether_type = mv88e6351_port_set_ether_type,
3112 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3113 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3114 	.port_pause_limit = mv88e6097_port_pause_limit,
3115 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3116 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3117 	.port_link_state = mv88e6352_port_link_state,
3118 	.port_get_cmode = mv88e6352_port_get_cmode,
3119 	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3120 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3121 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
3122 	.stats_get_strings = mv88e6095_stats_get_strings,
3123 	.stats_get_stats = mv88e6095_stats_get_stats,
3124 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
3125 	.set_egress_port = mv88e6095_g1_set_egress_port,
3126 	.watchdog_ops = &mv88e6097_watchdog_ops,
3127 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3128 	.pot_clear = mv88e6xxx_g2_pot_clear,
3129 	.reset = mv88e6352_g1_reset,
3130 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3131 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3132 	.phylink_validate = mv88e6185_phylink_validate,
3133 };
3134 
3135 static const struct mv88e6xxx_ops mv88e6176_ops = {
3136 	/* MV88E6XXX_FAMILY_6352 */
3137 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3138 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3139 	.irl_init_all = mv88e6352_g2_irl_init_all,
3140 	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
3141 	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3142 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3143 	.phy_read = mv88e6xxx_g2_smi_phy_read,
3144 	.phy_write = mv88e6xxx_g2_smi_phy_write,
3145 	.port_set_link = mv88e6xxx_port_set_link,
3146 	.port_set_duplex = mv88e6xxx_port_set_duplex,
3147 	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3148 	.port_set_speed = mv88e6352_port_set_speed,
3149 	.port_tag_remap = mv88e6095_port_tag_remap,
3150 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3151 	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3152 	.port_set_ether_type = mv88e6351_port_set_ether_type,
3153 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3154 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3155 	.port_pause_limit = mv88e6097_port_pause_limit,
3156 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3157 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3158 	.port_link_state = mv88e6352_port_link_state,
3159 	.port_get_cmode = mv88e6352_port_get_cmode,
3160 	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3161 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3162 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
3163 	.stats_get_strings = mv88e6095_stats_get_strings,
3164 	.stats_get_stats = mv88e6095_stats_get_stats,
3165 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
3166 	.set_egress_port = mv88e6095_g1_set_egress_port,
3167 	.watchdog_ops = &mv88e6097_watchdog_ops,
3168 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3169 	.pot_clear = mv88e6xxx_g2_pot_clear,
3170 	.reset = mv88e6352_g1_reset,
3171 	.rmu_disable = mv88e6352_g1_rmu_disable,
3172 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3173 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3174 	.serdes_power = mv88e6352_serdes_power,
3175 	.serdes_irq_setup = mv88e6352_serdes_irq_setup,
3176 	.serdes_irq_free = mv88e6352_serdes_irq_free,
3177 	.gpio_ops = &mv88e6352_gpio_ops,
3178 	.phylink_validate = mv88e6352_phylink_validate,
3179 };
3180 
3181 static const struct mv88e6xxx_ops mv88e6185_ops = {
3182 	/* MV88E6XXX_FAMILY_6185 */
3183 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3184 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3185 	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3186 	.phy_read = mv88e6185_phy_ppu_read,
3187 	.phy_write = mv88e6185_phy_ppu_write,
3188 	.port_set_link = mv88e6xxx_port_set_link,
3189 	.port_set_duplex = mv88e6xxx_port_set_duplex,
3190 	.port_set_speed = mv88e6185_port_set_speed,
3191 	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
3192 	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
3193 	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
3194 	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
3195 	.port_set_pause = mv88e6185_port_set_pause,
3196 	.port_link_state = mv88e6185_port_link_state,
3197 	.port_get_cmode = mv88e6185_port_get_cmode,
3198 	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3199 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3200 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
3201 	.stats_get_strings = mv88e6095_stats_get_strings,
3202 	.stats_get_stats = mv88e6095_stats_get_stats,
3203 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
3204 	.set_egress_port = mv88e6095_g1_set_egress_port,
3205 	.watchdog_ops = &mv88e6097_watchdog_ops,
3206 	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3207 	.set_cascade_port = mv88e6185_g1_set_cascade_port,
3208 	.ppu_enable = mv88e6185_g1_ppu_enable,
3209 	.ppu_disable = mv88e6185_g1_ppu_disable,
3210 	.reset = mv88e6185_g1_reset,
3211 	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3212 	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3213 	.phylink_validate = mv88e6185_phylink_validate,
3214 };
3215 
3216 static const struct mv88e6xxx_ops mv88e6190_ops = {
3217 	/* MV88E6XXX_FAMILY_6390 */
3218 	.irl_init_all = mv88e6390_g2_irl_init_all,
3219 	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
3220 	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3221 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3222 	.phy_read = mv88e6xxx_g2_smi_phy_read,
3223 	.phy_write = mv88e6xxx_g2_smi_phy_write,
3224 	.port_set_link = mv88e6xxx_port_set_link,
3225 	.port_set_duplex = mv88e6xxx_port_set_duplex,
3226 	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3227 	.port_set_speed = mv88e6390_port_set_speed,
3228 	.port_tag_remap = mv88e6390_port_tag_remap,
3229 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3230 	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3231 	.port_set_ether_type = mv88e6351_port_set_ether_type,
3232 	.port_pause_limit = mv88e6390_port_pause_limit,
3233 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3234 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3235 	.port_link_state = mv88e6352_port_link_state,
3236 	.port_get_cmode = mv88e6352_port_get_cmode,
3237 	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3238 	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3239 	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
3240 	.stats_get_strings = mv88e6320_stats_get_strings,
3241 	.stats_get_stats = mv88e6390_stats_get_stats,
3242 	.set_cpu_port = mv88e6390_g1_set_cpu_port,
3243 	.set_egress_port = mv88e6390_g1_set_egress_port,
3244 	.watchdog_ops = &mv88e6390_watchdog_ops,
3245 	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3246 	.pot_clear = mv88e6xxx_g2_pot_clear,
3247 	.reset = mv88e6352_g1_reset,
3248 	.rmu_disable = mv88e6390_g1_rmu_disable,
3249 	.vtu_getnext = mv88e6390_g1_vtu_getnext,
3250 	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3251 	.serdes_power = mv88e6390_serdes_power,
3252 	.serdes_irq_setup = mv88e6390_serdes_irq_setup,
3253 	.serdes_irq_free = mv88e6390_serdes_irq_free,
3254 	.gpio_ops = &mv88e6352_gpio_ops,
3255 	.phylink_validate = mv88e6390_phylink_validate,
3256 };
3257 
3258 static const struct mv88e6xxx_ops mv88e6190x_ops = {
3259 	/* MV88E6XXX_FAMILY_6390 */
3260 	.irl_init_all = mv88e6390_g2_irl_init_all,
3261 	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
3262 	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3263 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3264 	.phy_read = mv88e6xxx_g2_smi_phy_read,
3265 	.phy_write = mv88e6xxx_g2_smi_phy_write,
3266 	.port_set_link = mv88e6xxx_port_set_link,
3267 	.port_set_duplex = mv88e6xxx_port_set_duplex,
3268 	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3269 	.port_set_speed = mv88e6390x_port_set_speed,
3270 	.port_tag_remap = mv88e6390_port_tag_remap,
3271 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3272 	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3273 	.port_set_ether_type = mv88e6351_port_set_ether_type,
3274 	.port_pause_limit = mv88e6390_port_pause_limit,
3275 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3276 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3277 	.port_link_state = mv88e6352_port_link_state,
3278 	.port_get_cmode = mv88e6352_port_get_cmode,
3279 	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3280 	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3281 	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
3282 	.stats_get_strings = mv88e6320_stats_get_strings,
3283 	.stats_get_stats = mv88e6390_stats_get_stats,
3284 	.set_cpu_port = mv88e6390_g1_set_cpu_port,
3285 	.set_egress_port = mv88e6390_g1_set_egress_port,
3286 	.watchdog_ops = &mv88e6390_watchdog_ops,
3287 	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3288 	.pot_clear = mv88e6xxx_g2_pot_clear,
3289 	.reset = mv88e6352_g1_reset,
3290 	.rmu_disable = mv88e6390_g1_rmu_disable,
3291 	.vtu_getnext = mv88e6390_g1_vtu_getnext,
3292 	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3293 	.serdes_power = mv88e6390x_serdes_power,
3294 	.serdes_irq_setup = mv88e6390_serdes_irq_setup,
3295 	.serdes_irq_free = mv88e6390_serdes_irq_free,
3296 	.gpio_ops = &mv88e6352_gpio_ops,
3297 	.phylink_validate = mv88e6390x_phylink_validate,
3298 };
3299 
3300 static const struct mv88e6xxx_ops mv88e6191_ops = {
3301 	/* MV88E6XXX_FAMILY_6390 */
3302 	.irl_init_all = mv88e6390_g2_irl_init_all,
3303 	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
3304 	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3305 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3306 	.phy_read = mv88e6xxx_g2_smi_phy_read,
3307 	.phy_write = mv88e6xxx_g2_smi_phy_write,
3308 	.port_set_link = mv88e6xxx_port_set_link,
3309 	.port_set_duplex = mv88e6xxx_port_set_duplex,
3310 	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3311 	.port_set_speed = mv88e6390_port_set_speed,
3312 	.port_tag_remap = mv88e6390_port_tag_remap,
3313 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3314 	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3315 	.port_set_ether_type = mv88e6351_port_set_ether_type,
3316 	.port_pause_limit = mv88e6390_port_pause_limit,
3317 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3318 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3319 	.port_link_state = mv88e6352_port_link_state,
3320 	.port_get_cmode = mv88e6352_port_get_cmode,
3321 	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3322 	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3323 	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
3324 	.stats_get_strings = mv88e6320_stats_get_strings,
3325 	.stats_get_stats = mv88e6390_stats_get_stats,
3326 	.set_cpu_port = mv88e6390_g1_set_cpu_port,
3327 	.set_egress_port = mv88e6390_g1_set_egress_port,
3328 	.watchdog_ops = &mv88e6390_watchdog_ops,
3329 	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3330 	.pot_clear = mv88e6xxx_g2_pot_clear,
3331 	.reset = mv88e6352_g1_reset,
3332 	.rmu_disable = mv88e6390_g1_rmu_disable,
3333 	.vtu_getnext = mv88e6390_g1_vtu_getnext,
3334 	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3335 	.serdes_power = mv88e6390_serdes_power,
3336 	.serdes_irq_setup = mv88e6390_serdes_irq_setup,
3337 	.serdes_irq_free = mv88e6390_serdes_irq_free,
3338 	.avb_ops = &mv88e6390_avb_ops,
3339 	.ptp_ops = &mv88e6352_ptp_ops,
3340 	.phylink_validate = mv88e6390_phylink_validate,
3341 };
3342 
3343 static const struct mv88e6xxx_ops mv88e6240_ops = {
3344 	/* MV88E6XXX_FAMILY_6352 */
3345 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3346 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3347 	.irl_init_all = mv88e6352_g2_irl_init_all,
3348 	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
3349 	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3350 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3351 	.phy_read = mv88e6xxx_g2_smi_phy_read,
3352 	.phy_write = mv88e6xxx_g2_smi_phy_write,
3353 	.port_set_link = mv88e6xxx_port_set_link,
3354 	.port_set_duplex = mv88e6xxx_port_set_duplex,
3355 	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3356 	.port_set_speed = mv88e6352_port_set_speed,
3357 	.port_tag_remap = mv88e6095_port_tag_remap,
3358 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3359 	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3360 	.port_set_ether_type = mv88e6351_port_set_ether_type,
3361 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3362 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3363 	.port_pause_limit = mv88e6097_port_pause_limit,
3364 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3365 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3366 	.port_link_state = mv88e6352_port_link_state,
3367 	.port_get_cmode = mv88e6352_port_get_cmode,
3368 	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3369 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3370 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
3371 	.stats_get_strings = mv88e6095_stats_get_strings,
3372 	.stats_get_stats = mv88e6095_stats_get_stats,
3373 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
3374 	.set_egress_port = mv88e6095_g1_set_egress_port,
3375 	.watchdog_ops = &mv88e6097_watchdog_ops,
3376 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3377 	.pot_clear = mv88e6xxx_g2_pot_clear,
3378 	.reset = mv88e6352_g1_reset,
3379 	.rmu_disable = mv88e6352_g1_rmu_disable,
3380 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3381 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3382 	.serdes_power = mv88e6352_serdes_power,
3383 	.serdes_irq_setup = mv88e6352_serdes_irq_setup,
3384 	.serdes_irq_free = mv88e6352_serdes_irq_free,
3385 	.gpio_ops = &mv88e6352_gpio_ops,
3386 	.avb_ops = &mv88e6352_avb_ops,
3387 	.ptp_ops = &mv88e6352_ptp_ops,
3388 	.phylink_validate = mv88e6352_phylink_validate,
3389 };
3390 
3391 static const struct mv88e6xxx_ops mv88e6290_ops = {
3392 	/* MV88E6XXX_FAMILY_6390 */
3393 	.irl_init_all = mv88e6390_g2_irl_init_all,
3394 	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
3395 	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3396 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3397 	.phy_read = mv88e6xxx_g2_smi_phy_read,
3398 	.phy_write = mv88e6xxx_g2_smi_phy_write,
3399 	.port_set_link = mv88e6xxx_port_set_link,
3400 	.port_set_duplex = mv88e6xxx_port_set_duplex,
3401 	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3402 	.port_set_speed = mv88e6390_port_set_speed,
3403 	.port_tag_remap = mv88e6390_port_tag_remap,
3404 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3405 	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3406 	.port_set_ether_type = mv88e6351_port_set_ether_type,
3407 	.port_pause_limit = mv88e6390_port_pause_limit,
3408 	.port_set_cmode = mv88e6390x_port_set_cmode,
3409 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3410 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3411 	.port_link_state = mv88e6352_port_link_state,
3412 	.port_get_cmode = mv88e6352_port_get_cmode,
3413 	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3414 	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3415 	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
3416 	.stats_get_strings = mv88e6320_stats_get_strings,
3417 	.stats_get_stats = mv88e6390_stats_get_stats,
3418 	.set_cpu_port = mv88e6390_g1_set_cpu_port,
3419 	.set_egress_port = mv88e6390_g1_set_egress_port,
3420 	.watchdog_ops = &mv88e6390_watchdog_ops,
3421 	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3422 	.pot_clear = mv88e6xxx_g2_pot_clear,
3423 	.reset = mv88e6352_g1_reset,
3424 	.rmu_disable = mv88e6390_g1_rmu_disable,
3425 	.vtu_getnext = mv88e6390_g1_vtu_getnext,
3426 	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3427 	.serdes_power = mv88e6390_serdes_power,
3428 	.serdes_irq_setup = mv88e6390_serdes_irq_setup,
3429 	.serdes_irq_free = mv88e6390_serdes_irq_free,
3430 	.gpio_ops = &mv88e6352_gpio_ops,
3431 	.avb_ops = &mv88e6390_avb_ops,
3432 	.ptp_ops = &mv88e6352_ptp_ops,
3433 	.phylink_validate = mv88e6390_phylink_validate,
3434 };
3435 
3436 static const struct mv88e6xxx_ops mv88e6320_ops = {
3437 	/* MV88E6XXX_FAMILY_6320 */
3438 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3439 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3440 	.irl_init_all = mv88e6352_g2_irl_init_all,
3441 	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
3442 	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3443 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3444 	.phy_read = mv88e6xxx_g2_smi_phy_read,
3445 	.phy_write = mv88e6xxx_g2_smi_phy_write,
3446 	.port_set_link = mv88e6xxx_port_set_link,
3447 	.port_set_duplex = mv88e6xxx_port_set_duplex,
3448 	.port_set_speed = mv88e6185_port_set_speed,
3449 	.port_tag_remap = mv88e6095_port_tag_remap,
3450 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3451 	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3452 	.port_set_ether_type = mv88e6351_port_set_ether_type,
3453 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3454 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3455 	.port_pause_limit = mv88e6097_port_pause_limit,
3456 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3457 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3458 	.port_link_state = mv88e6352_port_link_state,
3459 	.port_get_cmode = mv88e6352_port_get_cmode,
3460 	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3461 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3462 	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
3463 	.stats_get_strings = mv88e6320_stats_get_strings,
3464 	.stats_get_stats = mv88e6320_stats_get_stats,
3465 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
3466 	.set_egress_port = mv88e6095_g1_set_egress_port,
3467 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3468 	.pot_clear = mv88e6xxx_g2_pot_clear,
3469 	.reset = mv88e6352_g1_reset,
3470 	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3471 	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3472 	.gpio_ops = &mv88e6352_gpio_ops,
3473 	.avb_ops = &mv88e6352_avb_ops,
3474 	.ptp_ops = &mv88e6352_ptp_ops,
3475 	.phylink_validate = mv88e6185_phylink_validate,
3476 };
3477 
3478 static const struct mv88e6xxx_ops mv88e6321_ops = {
3479 	/* MV88E6XXX_FAMILY_6320 */
3480 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3481 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3482 	.irl_init_all = mv88e6352_g2_irl_init_all,
3483 	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
3484 	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3485 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3486 	.phy_read = mv88e6xxx_g2_smi_phy_read,
3487 	.phy_write = mv88e6xxx_g2_smi_phy_write,
3488 	.port_set_link = mv88e6xxx_port_set_link,
3489 	.port_set_duplex = mv88e6xxx_port_set_duplex,
3490 	.port_set_speed = mv88e6185_port_set_speed,
3491 	.port_tag_remap = mv88e6095_port_tag_remap,
3492 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3493 	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3494 	.port_set_ether_type = mv88e6351_port_set_ether_type,
3495 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3496 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3497 	.port_pause_limit = mv88e6097_port_pause_limit,
3498 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3499 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3500 	.port_link_state = mv88e6352_port_link_state,
3501 	.port_get_cmode = mv88e6352_port_get_cmode,
3502 	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3503 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3504 	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
3505 	.stats_get_strings = mv88e6320_stats_get_strings,
3506 	.stats_get_stats = mv88e6320_stats_get_stats,
3507 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
3508 	.set_egress_port = mv88e6095_g1_set_egress_port,
3509 	.reset = mv88e6352_g1_reset,
3510 	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3511 	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3512 	.gpio_ops = &mv88e6352_gpio_ops,
3513 	.avb_ops = &mv88e6352_avb_ops,
3514 	.ptp_ops = &mv88e6352_ptp_ops,
3515 	.phylink_validate = mv88e6185_phylink_validate,
3516 };
3517 
3518 static const struct mv88e6xxx_ops mv88e6341_ops = {
3519 	/* MV88E6XXX_FAMILY_6341 */
3520 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3521 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3522 	.irl_init_all = mv88e6352_g2_irl_init_all,
3523 	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
3524 	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3525 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3526 	.phy_read = mv88e6xxx_g2_smi_phy_read,
3527 	.phy_write = mv88e6xxx_g2_smi_phy_write,
3528 	.port_set_link = mv88e6xxx_port_set_link,
3529 	.port_set_duplex = mv88e6xxx_port_set_duplex,
3530 	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3531 	.port_set_speed = mv88e6341_port_set_speed,
3532 	.port_tag_remap = mv88e6095_port_tag_remap,
3533 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3534 	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3535 	.port_set_ether_type = mv88e6351_port_set_ether_type,
3536 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3537 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3538 	.port_pause_limit = mv88e6097_port_pause_limit,
3539 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3540 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3541 	.port_link_state = mv88e6352_port_link_state,
3542 	.port_get_cmode = mv88e6352_port_get_cmode,
3543 	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3544 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3545 	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
3546 	.stats_get_strings = mv88e6320_stats_get_strings,
3547 	.stats_get_stats = mv88e6390_stats_get_stats,
3548 	.set_cpu_port = mv88e6390_g1_set_cpu_port,
3549 	.set_egress_port = mv88e6390_g1_set_egress_port,
3550 	.watchdog_ops = &mv88e6390_watchdog_ops,
3551 	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
3552 	.pot_clear = mv88e6xxx_g2_pot_clear,
3553 	.reset = mv88e6352_g1_reset,
3554 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3555 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3556 	.serdes_power = mv88e6341_serdes_power,
3557 	.gpio_ops = &mv88e6352_gpio_ops,
3558 	.avb_ops = &mv88e6390_avb_ops,
3559 	.ptp_ops = &mv88e6352_ptp_ops,
3560 	.phylink_validate = mv88e6390_phylink_validate,
3561 };
3562 
3563 static const struct mv88e6xxx_ops mv88e6350_ops = {
3564 	/* MV88E6XXX_FAMILY_6351 */
3565 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3566 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3567 	.irl_init_all = mv88e6352_g2_irl_init_all,
3568 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3569 	.phy_read = mv88e6xxx_g2_smi_phy_read,
3570 	.phy_write = mv88e6xxx_g2_smi_phy_write,
3571 	.port_set_link = mv88e6xxx_port_set_link,
3572 	.port_set_duplex = mv88e6xxx_port_set_duplex,
3573 	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3574 	.port_set_speed = mv88e6185_port_set_speed,
3575 	.port_tag_remap = mv88e6095_port_tag_remap,
3576 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3577 	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3578 	.port_set_ether_type = mv88e6351_port_set_ether_type,
3579 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3580 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3581 	.port_pause_limit = mv88e6097_port_pause_limit,
3582 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3583 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3584 	.port_link_state = mv88e6352_port_link_state,
3585 	.port_get_cmode = mv88e6352_port_get_cmode,
3586 	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3587 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3588 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
3589 	.stats_get_strings = mv88e6095_stats_get_strings,
3590 	.stats_get_stats = mv88e6095_stats_get_stats,
3591 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
3592 	.set_egress_port = mv88e6095_g1_set_egress_port,
3593 	.watchdog_ops = &mv88e6097_watchdog_ops,
3594 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3595 	.pot_clear = mv88e6xxx_g2_pot_clear,
3596 	.reset = mv88e6352_g1_reset,
3597 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3598 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3599 	.phylink_validate = mv88e6185_phylink_validate,
3600 };
3601 
3602 static const struct mv88e6xxx_ops mv88e6351_ops = {
3603 	/* MV88E6XXX_FAMILY_6351 */
3604 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3605 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3606 	.irl_init_all = mv88e6352_g2_irl_init_all,
3607 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3608 	.phy_read = mv88e6xxx_g2_smi_phy_read,
3609 	.phy_write = mv88e6xxx_g2_smi_phy_write,
3610 	.port_set_link = mv88e6xxx_port_set_link,
3611 	.port_set_duplex = mv88e6xxx_port_set_duplex,
3612 	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3613 	.port_set_speed = mv88e6185_port_set_speed,
3614 	.port_tag_remap = mv88e6095_port_tag_remap,
3615 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3616 	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3617 	.port_set_ether_type = mv88e6351_port_set_ether_type,
3618 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3619 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3620 	.port_pause_limit = mv88e6097_port_pause_limit,
3621 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3622 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3623 	.port_link_state = mv88e6352_port_link_state,
3624 	.port_get_cmode = mv88e6352_port_get_cmode,
3625 	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3626 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3627 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
3628 	.stats_get_strings = mv88e6095_stats_get_strings,
3629 	.stats_get_stats = mv88e6095_stats_get_stats,
3630 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
3631 	.set_egress_port = mv88e6095_g1_set_egress_port,
3632 	.watchdog_ops = &mv88e6097_watchdog_ops,
3633 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3634 	.pot_clear = mv88e6xxx_g2_pot_clear,
3635 	.reset = mv88e6352_g1_reset,
3636 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3637 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3638 	.avb_ops = &mv88e6352_avb_ops,
3639 	.ptp_ops = &mv88e6352_ptp_ops,
3640 	.phylink_validate = mv88e6185_phylink_validate,
3641 };
3642 
3643 static const struct mv88e6xxx_ops mv88e6352_ops = {
3644 	/* MV88E6XXX_FAMILY_6352 */
3645 	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3646 	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3647 	.irl_init_all = mv88e6352_g2_irl_init_all,
3648 	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
3649 	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3650 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3651 	.phy_read = mv88e6xxx_g2_smi_phy_read,
3652 	.phy_write = mv88e6xxx_g2_smi_phy_write,
3653 	.port_set_link = mv88e6xxx_port_set_link,
3654 	.port_set_duplex = mv88e6xxx_port_set_duplex,
3655 	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3656 	.port_set_speed = mv88e6352_port_set_speed,
3657 	.port_tag_remap = mv88e6095_port_tag_remap,
3658 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3659 	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3660 	.port_set_ether_type = mv88e6351_port_set_ether_type,
3661 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3662 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3663 	.port_pause_limit = mv88e6097_port_pause_limit,
3664 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3665 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3666 	.port_link_state = mv88e6352_port_link_state,
3667 	.port_get_cmode = mv88e6352_port_get_cmode,
3668 	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3669 	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3670 	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
3671 	.stats_get_strings = mv88e6095_stats_get_strings,
3672 	.stats_get_stats = mv88e6095_stats_get_stats,
3673 	.set_cpu_port = mv88e6095_g1_set_cpu_port,
3674 	.set_egress_port = mv88e6095_g1_set_egress_port,
3675 	.watchdog_ops = &mv88e6097_watchdog_ops,
3676 	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3677 	.pot_clear = mv88e6xxx_g2_pot_clear,
3678 	.reset = mv88e6352_g1_reset,
3679 	.rmu_disable = mv88e6352_g1_rmu_disable,
3680 	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3681 	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3682 	.serdes_power = mv88e6352_serdes_power,
3683 	.serdes_irq_setup = mv88e6352_serdes_irq_setup,
3684 	.serdes_irq_free = mv88e6352_serdes_irq_free,
3685 	.gpio_ops = &mv88e6352_gpio_ops,
3686 	.avb_ops = &mv88e6352_avb_ops,
3687 	.ptp_ops = &mv88e6352_ptp_ops,
3688 	.serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
3689 	.serdes_get_strings = mv88e6352_serdes_get_strings,
3690 	.serdes_get_stats = mv88e6352_serdes_get_stats,
3691 	.phylink_validate = mv88e6352_phylink_validate,
3692 };
3693 
3694 static const struct mv88e6xxx_ops mv88e6390_ops = {
3695 	/* MV88E6XXX_FAMILY_6390 */
3696 	.irl_init_all = mv88e6390_g2_irl_init_all,
3697 	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
3698 	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3699 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3700 	.phy_read = mv88e6xxx_g2_smi_phy_read,
3701 	.phy_write = mv88e6xxx_g2_smi_phy_write,
3702 	.port_set_link = mv88e6xxx_port_set_link,
3703 	.port_set_duplex = mv88e6xxx_port_set_duplex,
3704 	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3705 	.port_set_speed = mv88e6390_port_set_speed,
3706 	.port_tag_remap = mv88e6390_port_tag_remap,
3707 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3708 	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3709 	.port_set_ether_type = mv88e6351_port_set_ether_type,
3710 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3711 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3712 	.port_pause_limit = mv88e6390_port_pause_limit,
3713 	.port_set_cmode = mv88e6390x_port_set_cmode,
3714 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3715 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3716 	.port_link_state = mv88e6352_port_link_state,
3717 	.port_get_cmode = mv88e6352_port_get_cmode,
3718 	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3719 	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3720 	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
3721 	.stats_get_strings = mv88e6320_stats_get_strings,
3722 	.stats_get_stats = mv88e6390_stats_get_stats,
3723 	.set_cpu_port = mv88e6390_g1_set_cpu_port,
3724 	.set_egress_port = mv88e6390_g1_set_egress_port,
3725 	.watchdog_ops = &mv88e6390_watchdog_ops,
3726 	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3727 	.pot_clear = mv88e6xxx_g2_pot_clear,
3728 	.reset = mv88e6352_g1_reset,
3729 	.rmu_disable = mv88e6390_g1_rmu_disable,
3730 	.vtu_getnext = mv88e6390_g1_vtu_getnext,
3731 	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3732 	.serdes_power = mv88e6390_serdes_power,
3733 	.serdes_irq_setup = mv88e6390_serdes_irq_setup,
3734 	.serdes_irq_free = mv88e6390_serdes_irq_free,
3735 	.gpio_ops = &mv88e6352_gpio_ops,
3736 	.avb_ops = &mv88e6390_avb_ops,
3737 	.ptp_ops = &mv88e6352_ptp_ops,
3738 	.phylink_validate = mv88e6390_phylink_validate,
3739 };
3740 
3741 static const struct mv88e6xxx_ops mv88e6390x_ops = {
3742 	/* MV88E6XXX_FAMILY_6390 */
3743 	.irl_init_all = mv88e6390_g2_irl_init_all,
3744 	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
3745 	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3746 	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3747 	.phy_read = mv88e6xxx_g2_smi_phy_read,
3748 	.phy_write = mv88e6xxx_g2_smi_phy_write,
3749 	.port_set_link = mv88e6xxx_port_set_link,
3750 	.port_set_duplex = mv88e6xxx_port_set_duplex,
3751 	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3752 	.port_set_speed = mv88e6390x_port_set_speed,
3753 	.port_tag_remap = mv88e6390_port_tag_remap,
3754 	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3755 	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3756 	.port_set_ether_type = mv88e6351_port_set_ether_type,
3757 	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3758 	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3759 	.port_pause_limit = mv88e6390_port_pause_limit,
3760 	.port_set_cmode = mv88e6390x_port_set_cmode,
3761 	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3762 	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3763 	.port_link_state = mv88e6352_port_link_state,
3764 	.port_get_cmode = mv88e6352_port_get_cmode,
3765 	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3766 	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3767 	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
3768 	.stats_get_strings = mv88e6320_stats_get_strings,
3769 	.stats_get_stats = mv88e6390_stats_get_stats,
3770 	.set_cpu_port = mv88e6390_g1_set_cpu_port,
3771 	.set_egress_port = mv88e6390_g1_set_egress_port,
3772 	.watchdog_ops = &mv88e6390_watchdog_ops,
3773 	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3774 	.pot_clear = mv88e6xxx_g2_pot_clear,
3775 	.reset = mv88e6352_g1_reset,
3776 	.rmu_disable = mv88e6390_g1_rmu_disable,
3777 	.vtu_getnext = mv88e6390_g1_vtu_getnext,
3778 	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3779 	.serdes_power = mv88e6390x_serdes_power,
3780 	.serdes_irq_setup = mv88e6390_serdes_irq_setup,
3781 	.serdes_irq_free = mv88e6390_serdes_irq_free,
3782 	.gpio_ops = &mv88e6352_gpio_ops,
3783 	.avb_ops = &mv88e6390_avb_ops,
3784 	.ptp_ops = &mv88e6352_ptp_ops,
3785 	.phylink_validate = mv88e6390x_phylink_validate,
3786 };
3787 
3788 static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3789 	[MV88E6085] = {
3790 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
3791 		.family = MV88E6XXX_FAMILY_6097,
3792 		.name = "Marvell 88E6085",
3793 		.num_databases = 4096,
3794 		.num_ports = 10,
3795 		.num_internal_phys = 5,
3796 		.max_vid = 4095,
3797 		.port_base_addr = 0x10,
3798 		.phy_base_addr = 0x0,
3799 		.global1_addr = 0x1b,
3800 		.global2_addr = 0x1c,
3801 		.age_time_coeff = 15000,
3802 		.g1_irqs = 8,
3803 		.g2_irqs = 10,
3804 		.atu_move_port_mask = 0xf,
3805 		.pvt = true,
3806 		.multi_chip = true,
3807 		.tag_protocol = DSA_TAG_PROTO_DSA,
3808 		.ops = &mv88e6085_ops,
3809 	},
3810 
3811 	[MV88E6095] = {
3812 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
3813 		.family = MV88E6XXX_FAMILY_6095,
3814 		.name = "Marvell 88E6095/88E6095F",
3815 		.num_databases = 256,
3816 		.num_ports = 11,
3817 		.num_internal_phys = 0,
3818 		.max_vid = 4095,
3819 		.port_base_addr = 0x10,
3820 		.phy_base_addr = 0x0,
3821 		.global1_addr = 0x1b,
3822 		.global2_addr = 0x1c,
3823 		.age_time_coeff = 15000,
3824 		.g1_irqs = 8,
3825 		.atu_move_port_mask = 0xf,
3826 		.multi_chip = true,
3827 		.tag_protocol = DSA_TAG_PROTO_DSA,
3828 		.ops = &mv88e6095_ops,
3829 	},
3830 
3831 	[MV88E6097] = {
3832 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
3833 		.family = MV88E6XXX_FAMILY_6097,
3834 		.name = "Marvell 88E6097/88E6097F",
3835 		.num_databases = 4096,
3836 		.num_ports = 11,
3837 		.num_internal_phys = 8,
3838 		.max_vid = 4095,
3839 		.port_base_addr = 0x10,
3840 		.phy_base_addr = 0x0,
3841 		.global1_addr = 0x1b,
3842 		.global2_addr = 0x1c,
3843 		.age_time_coeff = 15000,
3844 		.g1_irqs = 8,
3845 		.g2_irqs = 10,
3846 		.atu_move_port_mask = 0xf,
3847 		.pvt = true,
3848 		.multi_chip = true,
3849 		.tag_protocol = DSA_TAG_PROTO_EDSA,
3850 		.ops = &mv88e6097_ops,
3851 	},
3852 
3853 	[MV88E6123] = {
3854 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
3855 		.family = MV88E6XXX_FAMILY_6165,
3856 		.name = "Marvell 88E6123",
3857 		.num_databases = 4096,
3858 		.num_ports = 3,
3859 		.num_internal_phys = 5,
3860 		.max_vid = 4095,
3861 		.port_base_addr = 0x10,
3862 		.phy_base_addr = 0x0,
3863 		.global1_addr = 0x1b,
3864 		.global2_addr = 0x1c,
3865 		.age_time_coeff = 15000,
3866 		.g1_irqs = 9,
3867 		.g2_irqs = 10,
3868 		.atu_move_port_mask = 0xf,
3869 		.pvt = true,
3870 		.multi_chip = true,
3871 		.tag_protocol = DSA_TAG_PROTO_EDSA,
3872 		.ops = &mv88e6123_ops,
3873 	},
3874 
3875 	[MV88E6131] = {
3876 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
3877 		.family = MV88E6XXX_FAMILY_6185,
3878 		.name = "Marvell 88E6131",
3879 		.num_databases = 256,
3880 		.num_ports = 8,
3881 		.num_internal_phys = 0,
3882 		.max_vid = 4095,
3883 		.port_base_addr = 0x10,
3884 		.phy_base_addr = 0x0,
3885 		.global1_addr = 0x1b,
3886 		.global2_addr = 0x1c,
3887 		.age_time_coeff = 15000,
3888 		.g1_irqs = 9,
3889 		.atu_move_port_mask = 0xf,
3890 		.multi_chip = true,
3891 		.tag_protocol = DSA_TAG_PROTO_DSA,
3892 		.ops = &mv88e6131_ops,
3893 	},
3894 
3895 	[MV88E6141] = {
3896 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
3897 		.family = MV88E6XXX_FAMILY_6341,
3898 		.name = "Marvell 88E6141",
3899 		.num_databases = 4096,
3900 		.num_ports = 6,
3901 		.num_internal_phys = 5,
3902 		.num_gpio = 11,
3903 		.max_vid = 4095,
3904 		.port_base_addr = 0x10,
3905 		.phy_base_addr = 0x10,
3906 		.global1_addr = 0x1b,
3907 		.global2_addr = 0x1c,
3908 		.age_time_coeff = 3750,
3909 		.atu_move_port_mask = 0x1f,
3910 		.g1_irqs = 9,
3911 		.g2_irqs = 10,
3912 		.pvt = true,
3913 		.multi_chip = true,
3914 		.tag_protocol = DSA_TAG_PROTO_EDSA,
3915 		.ops = &mv88e6141_ops,
3916 	},
3917 
3918 	[MV88E6161] = {
3919 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
3920 		.family = MV88E6XXX_FAMILY_6165,
3921 		.name = "Marvell 88E6161",
3922 		.num_databases = 4096,
3923 		.num_ports = 6,
3924 		.num_internal_phys = 5,
3925 		.max_vid = 4095,
3926 		.port_base_addr = 0x10,
3927 		.phy_base_addr = 0x0,
3928 		.global1_addr = 0x1b,
3929 		.global2_addr = 0x1c,
3930 		.age_time_coeff = 15000,
3931 		.g1_irqs = 9,
3932 		.g2_irqs = 10,
3933 		.atu_move_port_mask = 0xf,
3934 		.pvt = true,
3935 		.multi_chip = true,
3936 		.tag_protocol = DSA_TAG_PROTO_EDSA,
3937 		.ptp_support = true,
3938 		.ops = &mv88e6161_ops,
3939 	},
3940 
3941 	[MV88E6165] = {
3942 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
3943 		.family = MV88E6XXX_FAMILY_6165,
3944 		.name = "Marvell 88E6165",
3945 		.num_databases = 4096,
3946 		.num_ports = 6,
3947 		.num_internal_phys = 0,
3948 		.max_vid = 4095,
3949 		.port_base_addr = 0x10,
3950 		.phy_base_addr = 0x0,
3951 		.global1_addr = 0x1b,
3952 		.global2_addr = 0x1c,
3953 		.age_time_coeff = 15000,
3954 		.g1_irqs = 9,
3955 		.g2_irqs = 10,
3956 		.atu_move_port_mask = 0xf,
3957 		.pvt = true,
3958 		.multi_chip = true,
3959 		.tag_protocol = DSA_TAG_PROTO_DSA,
3960 		.ptp_support = true,
3961 		.ops = &mv88e6165_ops,
3962 	},
3963 
3964 	[MV88E6171] = {
3965 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
3966 		.family = MV88E6XXX_FAMILY_6351,
3967 		.name = "Marvell 88E6171",
3968 		.num_databases = 4096,
3969 		.num_ports = 7,
3970 		.num_internal_phys = 5,
3971 		.max_vid = 4095,
3972 		.port_base_addr = 0x10,
3973 		.phy_base_addr = 0x0,
3974 		.global1_addr = 0x1b,
3975 		.global2_addr = 0x1c,
3976 		.age_time_coeff = 15000,
3977 		.g1_irqs = 9,
3978 		.g2_irqs = 10,
3979 		.atu_move_port_mask = 0xf,
3980 		.pvt = true,
3981 		.multi_chip = true,
3982 		.tag_protocol = DSA_TAG_PROTO_EDSA,
3983 		.ops = &mv88e6171_ops,
3984 	},
3985 
3986 	[MV88E6172] = {
3987 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
3988 		.family = MV88E6XXX_FAMILY_6352,
3989 		.name = "Marvell 88E6172",
3990 		.num_databases = 4096,
3991 		.num_ports = 7,
3992 		.num_internal_phys = 5,
3993 		.num_gpio = 15,
3994 		.max_vid = 4095,
3995 		.port_base_addr = 0x10,
3996 		.phy_base_addr = 0x0,
3997 		.global1_addr = 0x1b,
3998 		.global2_addr = 0x1c,
3999 		.age_time_coeff = 15000,
4000 		.g1_irqs = 9,
4001 		.g2_irqs = 10,
4002 		.atu_move_port_mask = 0xf,
4003 		.pvt = true,
4004 		.multi_chip = true,
4005 		.tag_protocol = DSA_TAG_PROTO_EDSA,
4006 		.ops = &mv88e6172_ops,
4007 	},
4008 
4009 	[MV88E6175] = {
4010 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
4011 		.family = MV88E6XXX_FAMILY_6351,
4012 		.name = "Marvell 88E6175",
4013 		.num_databases = 4096,
4014 		.num_ports = 7,
4015 		.num_internal_phys = 5,
4016 		.max_vid = 4095,
4017 		.port_base_addr = 0x10,
4018 		.phy_base_addr = 0x0,
4019 		.global1_addr = 0x1b,
4020 		.global2_addr = 0x1c,
4021 		.age_time_coeff = 15000,
4022 		.g1_irqs = 9,
4023 		.g2_irqs = 10,
4024 		.atu_move_port_mask = 0xf,
4025 		.pvt = true,
4026 		.multi_chip = true,
4027 		.tag_protocol = DSA_TAG_PROTO_EDSA,
4028 		.ops = &mv88e6175_ops,
4029 	},
4030 
4031 	[MV88E6176] = {
4032 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
4033 		.family = MV88E6XXX_FAMILY_6352,
4034 		.name = "Marvell 88E6176",
4035 		.num_databases = 4096,
4036 		.num_ports = 7,
4037 		.num_internal_phys = 5,
4038 		.num_gpio = 15,
4039 		.max_vid = 4095,
4040 		.port_base_addr = 0x10,
4041 		.phy_base_addr = 0x0,
4042 		.global1_addr = 0x1b,
4043 		.global2_addr = 0x1c,
4044 		.age_time_coeff = 15000,
4045 		.g1_irqs = 9,
4046 		.g2_irqs = 10,
4047 		.atu_move_port_mask = 0xf,
4048 		.pvt = true,
4049 		.multi_chip = true,
4050 		.tag_protocol = DSA_TAG_PROTO_EDSA,
4051 		.ops = &mv88e6176_ops,
4052 	},
4053 
4054 	[MV88E6185] = {
4055 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
4056 		.family = MV88E6XXX_FAMILY_6185,
4057 		.name = "Marvell 88E6185",
4058 		.num_databases = 256,
4059 		.num_ports = 10,
4060 		.num_internal_phys = 0,
4061 		.max_vid = 4095,
4062 		.port_base_addr = 0x10,
4063 		.phy_base_addr = 0x0,
4064 		.global1_addr = 0x1b,
4065 		.global2_addr = 0x1c,
4066 		.age_time_coeff = 15000,
4067 		.g1_irqs = 8,
4068 		.atu_move_port_mask = 0xf,
4069 		.multi_chip = true,
4070 		.tag_protocol = DSA_TAG_PROTO_EDSA,
4071 		.ops = &mv88e6185_ops,
4072 	},
4073 
4074 	[MV88E6190] = {
4075 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
4076 		.family = MV88E6XXX_FAMILY_6390,
4077 		.name = "Marvell 88E6190",
4078 		.num_databases = 4096,
4079 		.num_ports = 11,	/* 10 + Z80 */
4080 		.num_internal_phys = 11,
4081 		.num_gpio = 16,
4082 		.max_vid = 8191,
4083 		.port_base_addr = 0x0,
4084 		.phy_base_addr = 0x0,
4085 		.global1_addr = 0x1b,
4086 		.global2_addr = 0x1c,
4087 		.tag_protocol = DSA_TAG_PROTO_DSA,
4088 		.age_time_coeff = 3750,
4089 		.g1_irqs = 9,
4090 		.g2_irqs = 14,
4091 		.pvt = true,
4092 		.multi_chip = true,
4093 		.atu_move_port_mask = 0x1f,
4094 		.ops = &mv88e6190_ops,
4095 	},
4096 
4097 	[MV88E6190X] = {
4098 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
4099 		.family = MV88E6XXX_FAMILY_6390,
4100 		.name = "Marvell 88E6190X",
4101 		.num_databases = 4096,
4102 		.num_ports = 11,	/* 10 + Z80 */
4103 		.num_internal_phys = 11,
4104 		.num_gpio = 16,
4105 		.max_vid = 8191,
4106 		.port_base_addr = 0x0,
4107 		.phy_base_addr = 0x0,
4108 		.global1_addr = 0x1b,
4109 		.global2_addr = 0x1c,
4110 		.age_time_coeff = 3750,
4111 		.g1_irqs = 9,
4112 		.g2_irqs = 14,
4113 		.atu_move_port_mask = 0x1f,
4114 		.pvt = true,
4115 		.multi_chip = true,
4116 		.tag_protocol = DSA_TAG_PROTO_DSA,
4117 		.ops = &mv88e6190x_ops,
4118 	},
4119 
4120 	[MV88E6191] = {
4121 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
4122 		.family = MV88E6XXX_FAMILY_6390,
4123 		.name = "Marvell 88E6191",
4124 		.num_databases = 4096,
4125 		.num_ports = 11,	/* 10 + Z80 */
4126 		.num_internal_phys = 11,
4127 		.max_vid = 8191,
4128 		.port_base_addr = 0x0,
4129 		.phy_base_addr = 0x0,
4130 		.global1_addr = 0x1b,
4131 		.global2_addr = 0x1c,
4132 		.age_time_coeff = 3750,
4133 		.g1_irqs = 9,
4134 		.g2_irqs = 14,
4135 		.atu_move_port_mask = 0x1f,
4136 		.pvt = true,
4137 		.multi_chip = true,
4138 		.tag_protocol = DSA_TAG_PROTO_DSA,
4139 		.ptp_support = true,
4140 		.ops = &mv88e6191_ops,
4141 	},
4142 
4143 	[MV88E6240] = {
4144 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
4145 		.family = MV88E6XXX_FAMILY_6352,
4146 		.name = "Marvell 88E6240",
4147 		.num_databases = 4096,
4148 		.num_ports = 7,
4149 		.num_internal_phys = 5,
4150 		.num_gpio = 15,
4151 		.max_vid = 4095,
4152 		.port_base_addr = 0x10,
4153 		.phy_base_addr = 0x0,
4154 		.global1_addr = 0x1b,
4155 		.global2_addr = 0x1c,
4156 		.age_time_coeff = 15000,
4157 		.g1_irqs = 9,
4158 		.g2_irqs = 10,
4159 		.atu_move_port_mask = 0xf,
4160 		.pvt = true,
4161 		.multi_chip = true,
4162 		.tag_protocol = DSA_TAG_PROTO_EDSA,
4163 		.ptp_support = true,
4164 		.ops = &mv88e6240_ops,
4165 	},
4166 
4167 	[MV88E6290] = {
4168 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
4169 		.family = MV88E6XXX_FAMILY_6390,
4170 		.name = "Marvell 88E6290",
4171 		.num_databases = 4096,
4172 		.num_ports = 11,	/* 10 + Z80 */
4173 		.num_internal_phys = 11,
4174 		.num_gpio = 16,
4175 		.max_vid = 8191,
4176 		.port_base_addr = 0x0,
4177 		.phy_base_addr = 0x0,
4178 		.global1_addr = 0x1b,
4179 		.global2_addr = 0x1c,
4180 		.age_time_coeff = 3750,
4181 		.g1_irqs = 9,
4182 		.g2_irqs = 14,
4183 		.atu_move_port_mask = 0x1f,
4184 		.pvt = true,
4185 		.multi_chip = true,
4186 		.tag_protocol = DSA_TAG_PROTO_DSA,
4187 		.ptp_support = true,
4188 		.ops = &mv88e6290_ops,
4189 	},
4190 
4191 	[MV88E6320] = {
4192 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
4193 		.family = MV88E6XXX_FAMILY_6320,
4194 		.name = "Marvell 88E6320",
4195 		.num_databases = 4096,
4196 		.num_ports = 7,
4197 		.num_internal_phys = 5,
4198 		.num_gpio = 15,
4199 		.max_vid = 4095,
4200 		.port_base_addr = 0x10,
4201 		.phy_base_addr = 0x0,
4202 		.global1_addr = 0x1b,
4203 		.global2_addr = 0x1c,
4204 		.age_time_coeff = 15000,
4205 		.g1_irqs = 8,
4206 		.g2_irqs = 10,
4207 		.atu_move_port_mask = 0xf,
4208 		.pvt = true,
4209 		.multi_chip = true,
4210 		.tag_protocol = DSA_TAG_PROTO_EDSA,
4211 		.ptp_support = true,
4212 		.ops = &mv88e6320_ops,
4213 	},
4214 
4215 	[MV88E6321] = {
4216 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
4217 		.family = MV88E6XXX_FAMILY_6320,
4218 		.name = "Marvell 88E6321",
4219 		.num_databases = 4096,
4220 		.num_ports = 7,
4221 		.num_internal_phys = 5,
4222 		.num_gpio = 15,
4223 		.max_vid = 4095,
4224 		.port_base_addr = 0x10,
4225 		.phy_base_addr = 0x0,
4226 		.global1_addr = 0x1b,
4227 		.global2_addr = 0x1c,
4228 		.age_time_coeff = 15000,
4229 		.g1_irqs = 8,
4230 		.g2_irqs = 10,
4231 		.atu_move_port_mask = 0xf,
4232 		.multi_chip = true,
4233 		.tag_protocol = DSA_TAG_PROTO_EDSA,
4234 		.ptp_support = true,
4235 		.ops = &mv88e6321_ops,
4236 	},
4237 
4238 	[MV88E6341] = {
4239 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
4240 		.family = MV88E6XXX_FAMILY_6341,
4241 		.name = "Marvell 88E6341",
4242 		.num_databases = 4096,
4243 		.num_internal_phys = 5,
4244 		.num_ports = 6,
4245 		.num_gpio = 11,
4246 		.max_vid = 4095,
4247 		.port_base_addr = 0x10,
4248 		.phy_base_addr = 0x10,
4249 		.global1_addr = 0x1b,
4250 		.global2_addr = 0x1c,
4251 		.age_time_coeff = 3750,
4252 		.atu_move_port_mask = 0x1f,
4253 		.g1_irqs = 9,
4254 		.g2_irqs = 10,
4255 		.pvt = true,
4256 		.multi_chip = true,
4257 		.tag_protocol = DSA_TAG_PROTO_EDSA,
4258 		.ptp_support = true,
4259 		.ops = &mv88e6341_ops,
4260 	},
4261 
4262 	[MV88E6350] = {
4263 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
4264 		.family = MV88E6XXX_FAMILY_6351,
4265 		.name = "Marvell 88E6350",
4266 		.num_databases = 4096,
4267 		.num_ports = 7,
4268 		.num_internal_phys = 5,
4269 		.max_vid = 4095,
4270 		.port_base_addr = 0x10,
4271 		.phy_base_addr = 0x0,
4272 		.global1_addr = 0x1b,
4273 		.global2_addr = 0x1c,
4274 		.age_time_coeff = 15000,
4275 		.g1_irqs = 9,
4276 		.g2_irqs = 10,
4277 		.atu_move_port_mask = 0xf,
4278 		.pvt = true,
4279 		.multi_chip = true,
4280 		.tag_protocol = DSA_TAG_PROTO_EDSA,
4281 		.ops = &mv88e6350_ops,
4282 	},
4283 
4284 	[MV88E6351] = {
4285 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
4286 		.family = MV88E6XXX_FAMILY_6351,
4287 		.name = "Marvell 88E6351",
4288 		.num_databases = 4096,
4289 		.num_ports = 7,
4290 		.num_internal_phys = 5,
4291 		.max_vid = 4095,
4292 		.port_base_addr = 0x10,
4293 		.phy_base_addr = 0x0,
4294 		.global1_addr = 0x1b,
4295 		.global2_addr = 0x1c,
4296 		.age_time_coeff = 15000,
4297 		.g1_irqs = 9,
4298 		.g2_irqs = 10,
4299 		.atu_move_port_mask = 0xf,
4300 		.pvt = true,
4301 		.multi_chip = true,
4302 		.tag_protocol = DSA_TAG_PROTO_EDSA,
4303 		.ops = &mv88e6351_ops,
4304 	},
4305 
4306 	[MV88E6352] = {
4307 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
4308 		.family = MV88E6XXX_FAMILY_6352,
4309 		.name = "Marvell 88E6352",
4310 		.num_databases = 4096,
4311 		.num_ports = 7,
4312 		.num_internal_phys = 5,
4313 		.num_gpio = 15,
4314 		.max_vid = 4095,
4315 		.port_base_addr = 0x10,
4316 		.phy_base_addr = 0x0,
4317 		.global1_addr = 0x1b,
4318 		.global2_addr = 0x1c,
4319 		.age_time_coeff = 15000,
4320 		.g1_irqs = 9,
4321 		.g2_irqs = 10,
4322 		.atu_move_port_mask = 0xf,
4323 		.pvt = true,
4324 		.multi_chip = true,
4325 		.tag_protocol = DSA_TAG_PROTO_EDSA,
4326 		.ptp_support = true,
4327 		.ops = &mv88e6352_ops,
4328 	},
4329 	[MV88E6390] = {
4330 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
4331 		.family = MV88E6XXX_FAMILY_6390,
4332 		.name = "Marvell 88E6390",
4333 		.num_databases = 4096,
4334 		.num_ports = 11,	/* 10 + Z80 */
4335 		.num_internal_phys = 11,
4336 		.num_gpio = 16,
4337 		.max_vid = 8191,
4338 		.port_base_addr = 0x0,
4339 		.phy_base_addr = 0x0,
4340 		.global1_addr = 0x1b,
4341 		.global2_addr = 0x1c,
4342 		.age_time_coeff = 3750,
4343 		.g1_irqs = 9,
4344 		.g2_irqs = 14,
4345 		.atu_move_port_mask = 0x1f,
4346 		.pvt = true,
4347 		.multi_chip = true,
4348 		.tag_protocol = DSA_TAG_PROTO_DSA,
4349 		.ptp_support = true,
4350 		.ops = &mv88e6390_ops,
4351 	},
4352 	[MV88E6390X] = {
4353 		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
4354 		.family = MV88E6XXX_FAMILY_6390,
4355 		.name = "Marvell 88E6390X",
4356 		.num_databases = 4096,
4357 		.num_ports = 11,	/* 10 + Z80 */
4358 		.num_internal_phys = 11,
4359 		.num_gpio = 16,
4360 		.max_vid = 8191,
4361 		.port_base_addr = 0x0,
4362 		.phy_base_addr = 0x0,
4363 		.global1_addr = 0x1b,
4364 		.global2_addr = 0x1c,
4365 		.age_time_coeff = 3750,
4366 		.g1_irqs = 9,
4367 		.g2_irqs = 14,
4368 		.atu_move_port_mask = 0x1f,
4369 		.pvt = true,
4370 		.multi_chip = true,
4371 		.tag_protocol = DSA_TAG_PROTO_DSA,
4372 		.ptp_support = true,
4373 		.ops = &mv88e6390x_ops,
4374 	},
4375 };
4376 
4377 static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
4378 {
4379 	int i;
4380 
4381 	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
4382 		if (mv88e6xxx_table[i].prod_num == prod_num)
4383 			return &mv88e6xxx_table[i];
4384 
4385 	return NULL;
4386 }
4387 
4388 static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
4389 {
4390 	const struct mv88e6xxx_info *info;
4391 	unsigned int prod_num, rev;
4392 	u16 id;
4393 	int err;
4394 
4395 	mutex_lock(&chip->reg_lock);
4396 	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
4397 	mutex_unlock(&chip->reg_lock);
4398 	if (err)
4399 		return err;
4400 
4401 	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
4402 	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
4403 
4404 	info = mv88e6xxx_lookup_info(prod_num);
4405 	if (!info)
4406 		return -ENODEV;
4407 
4408 	/* Update the compatible info with the probed one */
4409 	chip->info = info;
4410 
4411 	err = mv88e6xxx_g2_require(chip);
4412 	if (err)
4413 		return err;
4414 
4415 	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
4416 		 chip->info->prod_num, chip->info->name, rev);
4417 
4418 	return 0;
4419 }
4420 
4421 static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
4422 {
4423 	struct mv88e6xxx_chip *chip;
4424 
4425 	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
4426 	if (!chip)
4427 		return NULL;
4428 
4429 	chip->dev = dev;
4430 
4431 	mutex_init(&chip->reg_lock);
4432 	INIT_LIST_HEAD(&chip->mdios);
4433 
4434 	return chip;
4435 }
4436 
4437 static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
4438 			      struct mii_bus *bus, int sw_addr)
4439 {
4440 	if (sw_addr == 0)
4441 		chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
4442 	else if (chip->info->multi_chip)
4443 		chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
4444 	else
4445 		return -EINVAL;
4446 
4447 	chip->bus = bus;
4448 	chip->sw_addr = sw_addr;
4449 
4450 	return 0;
4451 }
4452 
4453 static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
4454 							int port)
4455 {
4456 	struct mv88e6xxx_chip *chip = ds->priv;
4457 
4458 	return chip->info->tag_protocol;
4459 }
4460 
4461 #if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
4462 static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
4463 				       struct device *host_dev, int sw_addr,
4464 				       void **priv)
4465 {
4466 	struct mv88e6xxx_chip *chip;
4467 	struct mii_bus *bus;
4468 	int err;
4469 
4470 	bus = dsa_host_dev_to_mii_bus(host_dev);
4471 	if (!bus)
4472 		return NULL;
4473 
4474 	chip = mv88e6xxx_alloc_chip(dsa_dev);
4475 	if (!chip)
4476 		return NULL;
4477 
4478 	/* Legacy SMI probing will only support chips similar to 88E6085 */
4479 	chip->info = &mv88e6xxx_table[MV88E6085];
4480 
4481 	err = mv88e6xxx_smi_init(chip, bus, sw_addr);
4482 	if (err)
4483 		goto free;
4484 
4485 	err = mv88e6xxx_detect(chip);
4486 	if (err)
4487 		goto free;
4488 
4489 	mutex_lock(&chip->reg_lock);
4490 	err = mv88e6xxx_switch_reset(chip);
4491 	mutex_unlock(&chip->reg_lock);
4492 	if (err)
4493 		goto free;
4494 
4495 	mv88e6xxx_phy_init(chip);
4496 
4497 	err = mv88e6xxx_mdios_register(chip, NULL);
4498 	if (err)
4499 		goto free;
4500 
4501 	*priv = chip;
4502 
4503 	return chip->info->name;
4504 free:
4505 	devm_kfree(dsa_dev, chip);
4506 
4507 	return NULL;
4508 }
4509 #endif
4510 
4511 static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4512 				      const struct switchdev_obj_port_mdb *mdb)
4513 {
4514 	/* We don't need any dynamic resource from the kernel (yet),
4515 	 * so skip the prepare phase.
4516 	 */
4517 
4518 	return 0;
4519 }
4520 
4521 static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
4522 				   const struct switchdev_obj_port_mdb *mdb)
4523 {
4524 	struct mv88e6xxx_chip *chip = ds->priv;
4525 
4526 	mutex_lock(&chip->reg_lock);
4527 	if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4528 					 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
4529 		dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
4530 			port);
4531 	mutex_unlock(&chip->reg_lock);
4532 }
4533 
4534 static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4535 				  const struct switchdev_obj_port_mdb *mdb)
4536 {
4537 	struct mv88e6xxx_chip *chip = ds->priv;
4538 	int err;
4539 
4540 	mutex_lock(&chip->reg_lock);
4541 	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4542 					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
4543 	mutex_unlock(&chip->reg_lock);
4544 
4545 	return err;
4546 }
4547 
4548 static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
4549 #if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
4550 	.probe			= mv88e6xxx_drv_probe,
4551 #endif
4552 	.get_tag_protocol	= mv88e6xxx_get_tag_protocol,
4553 	.setup			= mv88e6xxx_setup,
4554 	.adjust_link		= mv88e6xxx_adjust_link,
4555 	.phylink_validate	= mv88e6xxx_validate,
4556 	.phylink_mac_link_state	= mv88e6xxx_link_state,
4557 	.phylink_mac_config	= mv88e6xxx_mac_config,
4558 	.phylink_mac_link_down	= mv88e6xxx_mac_link_down,
4559 	.phylink_mac_link_up	= mv88e6xxx_mac_link_up,
4560 	.get_strings		= mv88e6xxx_get_strings,
4561 	.get_ethtool_stats	= mv88e6xxx_get_ethtool_stats,
4562 	.get_sset_count		= mv88e6xxx_get_sset_count,
4563 	.port_enable		= mv88e6xxx_port_enable,
4564 	.port_disable		= mv88e6xxx_port_disable,
4565 	.get_mac_eee		= mv88e6xxx_get_mac_eee,
4566 	.set_mac_eee		= mv88e6xxx_set_mac_eee,
4567 	.get_eeprom_len		= mv88e6xxx_get_eeprom_len,
4568 	.get_eeprom		= mv88e6xxx_get_eeprom,
4569 	.set_eeprom		= mv88e6xxx_set_eeprom,
4570 	.get_regs_len		= mv88e6xxx_get_regs_len,
4571 	.get_regs		= mv88e6xxx_get_regs,
4572 	.set_ageing_time	= mv88e6xxx_set_ageing_time,
4573 	.port_bridge_join	= mv88e6xxx_port_bridge_join,
4574 	.port_bridge_leave	= mv88e6xxx_port_bridge_leave,
4575 	.port_stp_state_set	= mv88e6xxx_port_stp_state_set,
4576 	.port_fast_age		= mv88e6xxx_port_fast_age,
4577 	.port_vlan_filtering	= mv88e6xxx_port_vlan_filtering,
4578 	.port_vlan_prepare	= mv88e6xxx_port_vlan_prepare,
4579 	.port_vlan_add		= mv88e6xxx_port_vlan_add,
4580 	.port_vlan_del		= mv88e6xxx_port_vlan_del,
4581 	.port_fdb_add           = mv88e6xxx_port_fdb_add,
4582 	.port_fdb_del           = mv88e6xxx_port_fdb_del,
4583 	.port_fdb_dump          = mv88e6xxx_port_fdb_dump,
4584 	.port_mdb_prepare       = mv88e6xxx_port_mdb_prepare,
4585 	.port_mdb_add           = mv88e6xxx_port_mdb_add,
4586 	.port_mdb_del           = mv88e6xxx_port_mdb_del,
4587 	.crosschip_bridge_join	= mv88e6xxx_crosschip_bridge_join,
4588 	.crosschip_bridge_leave	= mv88e6xxx_crosschip_bridge_leave,
4589 	.port_hwtstamp_set	= mv88e6xxx_port_hwtstamp_set,
4590 	.port_hwtstamp_get	= mv88e6xxx_port_hwtstamp_get,
4591 	.port_txtstamp		= mv88e6xxx_port_txtstamp,
4592 	.port_rxtstamp		= mv88e6xxx_port_rxtstamp,
4593 	.get_ts_info		= mv88e6xxx_get_ts_info,
4594 };
4595 
4596 static struct dsa_switch_driver mv88e6xxx_switch_drv = {
4597 	.ops			= &mv88e6xxx_switch_ops,
4598 };
4599 
4600 static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
4601 {
4602 	struct device *dev = chip->dev;
4603 	struct dsa_switch *ds;
4604 
4605 	ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
4606 	if (!ds)
4607 		return -ENOMEM;
4608 
4609 	ds->priv = chip;
4610 	ds->dev = dev;
4611 	ds->ops = &mv88e6xxx_switch_ops;
4612 	ds->ageing_time_min = chip->info->age_time_coeff;
4613 	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
4614 
4615 	dev_set_drvdata(dev, ds);
4616 
4617 	return dsa_register_switch(ds);
4618 }
4619 
4620 static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
4621 {
4622 	dsa_unregister_switch(chip->ds);
4623 }
4624 
4625 static const void *pdata_device_get_match_data(struct device *dev)
4626 {
4627 	const struct of_device_id *matches = dev->driver->of_match_table;
4628 	const struct dsa_mv88e6xxx_pdata *pdata = dev->platform_data;
4629 
4630 	for (; matches->name[0] || matches->type[0] || matches->compatible[0];
4631 	     matches++) {
4632 		if (!strcmp(pdata->compatible, matches->compatible))
4633 			return matches->data;
4634 	}
4635 	return NULL;
4636 }
4637 
4638 static int mv88e6xxx_probe(struct mdio_device *mdiodev)
4639 {
4640 	struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
4641 	const struct mv88e6xxx_info *compat_info = NULL;
4642 	struct device *dev = &mdiodev->dev;
4643 	struct device_node *np = dev->of_node;
4644 	struct mv88e6xxx_chip *chip;
4645 	int port;
4646 	int err;
4647 
4648 	if (!np && !pdata)
4649 		return -EINVAL;
4650 
4651 	if (np)
4652 		compat_info = of_device_get_match_data(dev);
4653 
4654 	if (pdata) {
4655 		compat_info = pdata_device_get_match_data(dev);
4656 
4657 		if (!pdata->netdev)
4658 			return -EINVAL;
4659 
4660 		for (port = 0; port < DSA_MAX_PORTS; port++) {
4661 			if (!(pdata->enabled_ports & (1 << port)))
4662 				continue;
4663 			if (strcmp(pdata->cd.port_names[port], "cpu"))
4664 				continue;
4665 			pdata->cd.netdev[port] = &pdata->netdev->dev;
4666 			break;
4667 		}
4668 	}
4669 
4670 	if (!compat_info)
4671 		return -EINVAL;
4672 
4673 	chip = mv88e6xxx_alloc_chip(dev);
4674 	if (!chip) {
4675 		err = -ENOMEM;
4676 		goto out;
4677 	}
4678 
4679 	chip->info = compat_info;
4680 
4681 	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
4682 	if (err)
4683 		goto out;
4684 
4685 	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4686 	if (IS_ERR(chip->reset)) {
4687 		err = PTR_ERR(chip->reset);
4688 		goto out;
4689 	}
4690 
4691 	err = mv88e6xxx_detect(chip);
4692 	if (err)
4693 		goto out;
4694 
4695 	mv88e6xxx_phy_init(chip);
4696 
4697 	if (chip->info->ops->get_eeprom) {
4698 		if (np)
4699 			of_property_read_u32(np, "eeprom-length",
4700 					     &chip->eeprom_len);
4701 		else
4702 			chip->eeprom_len = pdata->eeprom_len;
4703 	}
4704 
4705 	mutex_lock(&chip->reg_lock);
4706 	err = mv88e6xxx_switch_reset(chip);
4707 	mutex_unlock(&chip->reg_lock);
4708 	if (err)
4709 		goto out;
4710 
4711 	chip->irq = of_irq_get(np, 0);
4712 	if (chip->irq == -EPROBE_DEFER) {
4713 		err = chip->irq;
4714 		goto out;
4715 	}
4716 
4717 	/* Has to be performed before the MDIO bus is created, because
4718 	 * the PHYs will link their interrupts to these interrupt
4719 	 * controllers
4720 	 */
4721 	mutex_lock(&chip->reg_lock);
4722 	if (chip->irq > 0)
4723 		err = mv88e6xxx_g1_irq_setup(chip);
4724 	else
4725 		err = mv88e6xxx_irq_poll_setup(chip);
4726 	mutex_unlock(&chip->reg_lock);
4727 
4728 	if (err)
4729 		goto out;
4730 
4731 	if (chip->info->g2_irqs > 0) {
4732 		err = mv88e6xxx_g2_irq_setup(chip);
4733 		if (err)
4734 			goto out_g1_irq;
4735 	}
4736 
4737 	err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
4738 	if (err)
4739 		goto out_g2_irq;
4740 
4741 	err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
4742 	if (err)
4743 		goto out_g1_atu_prob_irq;
4744 
4745 	err = mv88e6xxx_mdios_register(chip, np);
4746 	if (err)
4747 		goto out_g1_vtu_prob_irq;
4748 
4749 	err = mv88e6xxx_register_switch(chip);
4750 	if (err)
4751 		goto out_mdio;
4752 
4753 	return 0;
4754 
4755 out_mdio:
4756 	mv88e6xxx_mdios_unregister(chip);
4757 out_g1_vtu_prob_irq:
4758 	mv88e6xxx_g1_vtu_prob_irq_free(chip);
4759 out_g1_atu_prob_irq:
4760 	mv88e6xxx_g1_atu_prob_irq_free(chip);
4761 out_g2_irq:
4762 	if (chip->info->g2_irqs > 0)
4763 		mv88e6xxx_g2_irq_free(chip);
4764 out_g1_irq:
4765 	if (chip->irq > 0)
4766 		mv88e6xxx_g1_irq_free(chip);
4767 	else
4768 		mv88e6xxx_irq_poll_free(chip);
4769 out:
4770 	if (pdata)
4771 		dev_put(pdata->netdev);
4772 
4773 	return err;
4774 }
4775 
4776 static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4777 {
4778 	struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
4779 	struct mv88e6xxx_chip *chip = ds->priv;
4780 
4781 	if (chip->info->ptp_support) {
4782 		mv88e6xxx_hwtstamp_free(chip);
4783 		mv88e6xxx_ptp_free(chip);
4784 	}
4785 
4786 	mv88e6xxx_phy_destroy(chip);
4787 	mv88e6xxx_unregister_switch(chip);
4788 	mv88e6xxx_mdios_unregister(chip);
4789 
4790 	mv88e6xxx_g1_vtu_prob_irq_free(chip);
4791 	mv88e6xxx_g1_atu_prob_irq_free(chip);
4792 
4793 	if (chip->info->g2_irqs > 0)
4794 		mv88e6xxx_g2_irq_free(chip);
4795 
4796 	if (chip->irq > 0)
4797 		mv88e6xxx_g1_irq_free(chip);
4798 	else
4799 		mv88e6xxx_irq_poll_free(chip);
4800 }
4801 
4802 static const struct of_device_id mv88e6xxx_of_match[] = {
4803 	{
4804 		.compatible = "marvell,mv88e6085",
4805 		.data = &mv88e6xxx_table[MV88E6085],
4806 	},
4807 	{
4808 		.compatible = "marvell,mv88e6190",
4809 		.data = &mv88e6xxx_table[MV88E6190],
4810 	},
4811 	{ /* sentinel */ },
4812 };
4813 
4814 MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4815 
4816 static struct mdio_driver mv88e6xxx_driver = {
4817 	.probe	= mv88e6xxx_probe,
4818 	.remove = mv88e6xxx_remove,
4819 	.mdiodrv.driver = {
4820 		.name = "mv88e6085",
4821 		.of_match_table = mv88e6xxx_of_match,
4822 	},
4823 };
4824 
4825 static int __init mv88e6xxx_init(void)
4826 {
4827 	register_switch_driver(&mv88e6xxx_switch_drv);
4828 	return mdio_driver_register(&mv88e6xxx_driver);
4829 }
4830 module_init(mv88e6xxx_init);
4831 
4832 static void __exit mv88e6xxx_cleanup(void)
4833 {
4834 	mdio_driver_unregister(&mv88e6xxx_driver);
4835 	unregister_switch_driver(&mv88e6xxx_switch_drv);
4836 }
4837 module_exit(mv88e6xxx_cleanup);
4838 
4839 MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4840 MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4841 MODULE_LICENSE("GPL");
4842