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