chip.c 161.6 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0-or-later
2
/*
3 4
 * Marvell 88e6xxx Ethernet switch single-chip support
 *
5 6
 * Copyright (c) 2008 Marvell Semiconductor
 *
7 8
 * Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch>
 *
V
Vivien Didelot 已提交
9 10
 * Copyright (c) 2016-2017 Savoir-faire Linux Inc.
 *	Vivien Didelot <vivien.didelot@savoirfairelinux.com>
11 12
 */

13
#include <linux/bitfield.h>
14
#include <linux/delay.h>
15
#include <linux/etherdevice.h>
16
#include <linux/ethtool.h>
17
#include <linux/if_bridge.h>
18 19 20
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/irqdomain.h>
21
#include <linux/jiffies.h>
22
#include <linux/list.h>
23
#include <linux/mdio.h>
24
#include <linux/module.h>
25
#include <linux/of_device.h>
26
#include <linux/of_irq.h>
27
#include <linux/of_mdio.h>
28
#include <linux/platform_data/mv88e6xxx.h>
29
#include <linux/netdevice.h>
30
#include <linux/gpio/consumer.h>
31
#include <linux/phylink.h>
32
#include <net/dsa.h>
33

34
#include "chip.h"
35
#include "global1.h"
36
#include "global2.h"
37
#include "hwtstamp.h"
38
#include "phy.h"
39
#include "port.h"
40
#include "ptp.h"
41
#include "serdes.h"
42
#include "smi.h"
43

44
static void assert_reg_lock(struct mv88e6xxx_chip *chip)
45
{
46 47
	if (unlikely(!mutex_is_locked(&chip->reg_lock))) {
		dev_err(chip->dev, "Switch registers lock not held!\n");
48 49 50 51
		dump_stack();
	}
}

52
int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val)
53 54 55
{
	int err;

56
	assert_reg_lock(chip);
57

58
	err = mv88e6xxx_smi_read(chip, addr, reg, val);
59 60 61
	if (err)
		return err;

62
	dev_dbg(chip->dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
63 64 65 66 67
		addr, reg, *val);

	return 0;
}

68
int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val)
69
{
70 71
	int err;

72
	assert_reg_lock(chip);
73

74
	err = mv88e6xxx_smi_write(chip, addr, reg, val);
75 76 77
	if (err)
		return err;

78
	dev_dbg(chip->dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
79 80
		addr, reg, val);

81 82 83
	return 0;
}

84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
int mv88e6xxx_wait_mask(struct mv88e6xxx_chip *chip, int addr, int reg,
			u16 mask, u16 val)
{
	u16 data;
	int err;
	int i;

	/* There's no bus specific operation to wait for a mask */
	for (i = 0; i < 16; i++) {
		err = mv88e6xxx_read(chip, addr, reg, &data);
		if (err)
			return err;

		if ((data & mask) == val)
			return 0;

		usleep_range(1000, 2000);
	}

	dev_err(chip->dev, "Timeout while waiting for switch\n");
	return -ETIMEDOUT;
}

107 108 109 110 111 112 113
int mv88e6xxx_wait_bit(struct mv88e6xxx_chip *chip, int addr, int reg,
		       int bit, int val)
{
	return mv88e6xxx_wait_mask(chip, addr, reg, BIT(bit),
				   val ? BIT(bit) : 0x0000);
}

114
struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
115 116 117 118 119 120 121 122 123 124 125
{
	struct mv88e6xxx_mdio_bus *mdio_bus;

	mdio_bus = list_first_entry(&chip->mdios, struct mv88e6xxx_mdio_bus,
				    list);
	if (!mdio_bus)
		return NULL;

	return mdio_bus->bus;
}

126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
static void mv88e6xxx_g1_irq_mask(struct irq_data *d)
{
	struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
	unsigned int n = d->hwirq;

	chip->g1_irq.masked |= (1 << n);
}

static void mv88e6xxx_g1_irq_unmask(struct irq_data *d)
{
	struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
	unsigned int n = d->hwirq;

	chip->g1_irq.masked &= ~(1 << n);
}

142
static irqreturn_t mv88e6xxx_g1_irq_thread_work(struct mv88e6xxx_chip *chip)
143 144 145 146 147
{
	unsigned int nhandled = 0;
	unsigned int sub_irq;
	unsigned int n;
	u16 reg;
148
	u16 ctl1;
149 150
	int err;

151
	mv88e6xxx_reg_lock(chip);
152
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
153
	mv88e6xxx_reg_unlock(chip);
154 155 156 157

	if (err)
		goto out;

158 159 160 161 162 163 164 165
	do {
		for (n = 0; n < chip->g1_irq.nirqs; ++n) {
			if (reg & (1 << n)) {
				sub_irq = irq_find_mapping(chip->g1_irq.domain,
							   n);
				handle_nested_irq(sub_irq);
				++nhandled;
			}
166
		}
167

168
		mv88e6xxx_reg_lock(chip);
169 170 171 172 173
		err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &ctl1);
		if (err)
			goto unlock;
		err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
unlock:
174
		mv88e6xxx_reg_unlock(chip);
175 176 177 178 179
		if (err)
			goto out;
		ctl1 &= GENMASK(chip->g1_irq.nirqs, 0);
	} while (reg & ctl1);

180 181 182 183
out:
	return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
}

184 185 186 187 188 189 190
static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id)
{
	struct mv88e6xxx_chip *chip = dev_id;

	return mv88e6xxx_g1_irq_thread_work(chip);
}

191 192 193 194
static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
{
	struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);

195
	mv88e6xxx_reg_lock(chip);
196 197 198 199 200 201 202 203 204
}

static void mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data *d)
{
	struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
	u16 mask = GENMASK(chip->g1_irq.nirqs, 0);
	u16 reg;
	int err;

205
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &reg);
206 207 208 209 210 211
	if (err)
		goto out;

	reg &= ~mask;
	reg |= (~chip->g1_irq.masked & mask);

212
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, reg);
213 214 215 216
	if (err)
		goto out;

out:
217
	mv88e6xxx_reg_unlock(chip);
218 219
}

220
static const struct irq_chip mv88e6xxx_g1_irq_chip = {
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
	.name			= "mv88e6xxx-g1",
	.irq_mask		= mv88e6xxx_g1_irq_mask,
	.irq_unmask		= mv88e6xxx_g1_irq_unmask,
	.irq_bus_lock		= mv88e6xxx_g1_irq_bus_lock,
	.irq_bus_sync_unlock	= mv88e6xxx_g1_irq_bus_sync_unlock,
};

static int mv88e6xxx_g1_irq_domain_map(struct irq_domain *d,
				       unsigned int irq,
				       irq_hw_number_t hwirq)
{
	struct mv88e6xxx_chip *chip = d->host_data;

	irq_set_chip_data(irq, d->host_data);
	irq_set_chip_and_handler(irq, &chip->g1_irq.chip, handle_level_irq);
	irq_set_noprobe(irq);

	return 0;
}

static const struct irq_domain_ops mv88e6xxx_g1_irq_domain_ops = {
	.map	= mv88e6xxx_g1_irq_domain_map,
	.xlate	= irq_domain_xlate_twocell,
};

246
/* To be called with reg_lock held */
247
static void mv88e6xxx_g1_irq_free_common(struct mv88e6xxx_chip *chip)
248 249
{
	int irq, virq;
250 251
	u16 mask;

252
	mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
253
	mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
254
	mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
255

256
	for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
257
		virq = irq_find_mapping(chip->g1_irq.domain, irq);
258 259 260
		irq_dispose_mapping(virq);
	}

261
	irq_domain_remove(chip->g1_irq.domain);
262 263
}

264 265
static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
{
266 267 268 269
	/*
	 * free_irq must be called without reg_lock taken because the irq
	 * handler takes this lock, too.
	 */
270
	free_irq(chip->irq, chip);
271

272
	mv88e6xxx_reg_lock(chip);
273
	mv88e6xxx_g1_irq_free_common(chip);
274
	mv88e6xxx_reg_unlock(chip);
275 276 277
}

static int mv88e6xxx_g1_irq_setup_common(struct mv88e6xxx_chip *chip)
278
{
279 280
	int err, irq, virq;
	u16 reg, mask;
281 282 283 284 285 286 287 288 289 290 291 292 293 294

	chip->g1_irq.nirqs = chip->info->g1_irqs;
	chip->g1_irq.domain = irq_domain_add_simple(
		NULL, chip->g1_irq.nirqs, 0,
		&mv88e6xxx_g1_irq_domain_ops, chip);
	if (!chip->g1_irq.domain)
		return -ENOMEM;

	for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
		irq_create_mapping(chip->g1_irq.domain, irq);

	chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
	chip->g1_irq.masked = ~0;

295
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
296
	if (err)
297
		goto out_mapping;
298

299
	mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
300

301
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
302
	if (err)
303
		goto out_disable;
304 305

	/* Reading the interrupt status clears (most of) them */
306
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
307
	if (err)
308
		goto out_disable;
309 310 311

	return 0;

312
out_disable:
313
	mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
314
	mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
315 316 317 318 319 320 321 322

out_mapping:
	for (irq = 0; irq < 16; irq++) {
		virq = irq_find_mapping(chip->g1_irq.domain, irq);
		irq_dispose_mapping(virq);
	}

	irq_domain_remove(chip->g1_irq.domain);
323 324 325 326

	return err;
}

327 328
static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
{
329 330
	static struct lock_class_key lock_key;
	static struct lock_class_key request_key;
331 332 333 334 335 336
	int err;

	err = mv88e6xxx_g1_irq_setup_common(chip);
	if (err)
		return err;

337 338 339 340 341 342
	/* These lock classes tells lockdep that global 1 irqs are in
	 * a different category than their parent GPIO, so it won't
	 * report false recursion.
	 */
	irq_set_lockdep_class(chip->irq, &lock_key, &request_key);

343 344 345
	snprintf(chip->irq_name, sizeof(chip->irq_name),
		 "mv88e6xxx-%s", dev_name(chip->dev));

346
	mv88e6xxx_reg_unlock(chip);
347 348
	err = request_threaded_irq(chip->irq, NULL,
				   mv88e6xxx_g1_irq_thread_fn,
349
				   IRQF_ONESHOT | IRQF_SHARED,
350
				   chip->irq_name, chip);
351
	mv88e6xxx_reg_lock(chip);
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
	if (err)
		mv88e6xxx_g1_irq_free_common(chip);

	return err;
}

static void mv88e6xxx_irq_poll(struct kthread_work *work)
{
	struct mv88e6xxx_chip *chip = container_of(work,
						   struct mv88e6xxx_chip,
						   irq_poll_work.work);
	mv88e6xxx_g1_irq_thread_work(chip);

	kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work,
				   msecs_to_jiffies(100));
}

static int mv88e6xxx_irq_poll_setup(struct mv88e6xxx_chip *chip)
{
	int err;

	err = mv88e6xxx_g1_irq_setup_common(chip);
	if (err)
		return err;

	kthread_init_delayed_work(&chip->irq_poll_work,
				  mv88e6xxx_irq_poll);

380
	chip->kworker = kthread_create_worker(0, "%s", dev_name(chip->dev));
381 382 383 384 385 386 387 388 389 390 391 392 393
	if (IS_ERR(chip->kworker))
		return PTR_ERR(chip->kworker);

	kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work,
				   msecs_to_jiffies(100));

	return 0;
}

static void mv88e6xxx_irq_poll_free(struct mv88e6xxx_chip *chip)
{
	kthread_cancel_delayed_work_sync(&chip->irq_poll_work);
	kthread_destroy_worker(chip->kworker);
394

395
	mv88e6xxx_reg_lock(chip);
396
	mv88e6xxx_g1_irq_free_common(chip);
397
	mv88e6xxx_reg_unlock(chip);
398 399
}

400 401 402
int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port, int link,
			     int speed, int duplex, int pause,
			     phy_interface_t mode)
403
{
404
	struct phylink_link_state state;
405 406 407 408 409
	int err;

	if (!chip->info->ops->port_set_link)
		return 0;

410 411 412 413 414 415 416 417 418 419 420 421 422
	if (!chip->info->ops->port_link_state)
		return 0;

	err = chip->info->ops->port_link_state(chip, port, &state);
	if (err)
		return err;

	/* Has anything actually changed? We don't expect the
	 * interface mode to change without one of the other
	 * parameters also changing
	 */
	if (state.link == link &&
	    state.speed == speed &&
423 424 425
	    state.duplex == duplex &&
	    (state.interface == mode ||
	     state.interface == PHY_INTERFACE_MODE_NA))
426 427
		return 0;

428
	/* Port's MAC control must not be changed unless the link is down */
429
	err = chip->info->ops->port_set_link(chip, port, LINK_FORCED_DOWN);
430 431 432 433 434 435 436 437 438
	if (err)
		return err;

	if (chip->info->ops->port_set_speed) {
		err = chip->info->ops->port_set_speed(chip, port, speed);
		if (err && err != -EOPNOTSUPP)
			goto restore_link;
	}

439 440 441
	if (speed == SPEED_MAX && chip->info->ops->port_max_speed_mode)
		mode = chip->info->ops->port_max_speed_mode(port);

442 443 444 445 446 447
	if (chip->info->ops->port_set_pause) {
		err = chip->info->ops->port_set_pause(chip, port, pause);
		if (err)
			goto restore_link;
	}

448 449 450 451 452 453 454 455 456 457 458 459
	if (chip->info->ops->port_set_duplex) {
		err = chip->info->ops->port_set_duplex(chip, port, duplex);
		if (err && err != -EOPNOTSUPP)
			goto restore_link;
	}

	if (chip->info->ops->port_set_rgmii_delay) {
		err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
		if (err && err != -EOPNOTSUPP)
			goto restore_link;
	}

460 461 462 463 464 465
	if (chip->info->ops->port_set_cmode) {
		err = chip->info->ops->port_set_cmode(chip, port, mode);
		if (err && err != -EOPNOTSUPP)
			goto restore_link;
	}

466 467 468
	err = 0;
restore_link:
	if (chip->info->ops->port_set_link(chip, port, link))
469
		dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
470 471 472 473

	return err;
}

474 475 476 477 478 479 480
static int mv88e6xxx_phy_is_internal(struct dsa_switch *ds, int port)
{
	struct mv88e6xxx_chip *chip = ds->priv;

	return port < chip->info->num_internal_phys;
}

481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
static void mv88e6065_phylink_validate(struct mv88e6xxx_chip *chip, int port,
				       unsigned long *mask,
				       struct phylink_link_state *state)
{
	if (!phy_interface_mode_is_8023z(state->interface)) {
		/* 10M and 100M are only supported in non-802.3z mode */
		phylink_set(mask, 10baseT_Half);
		phylink_set(mask, 10baseT_Full);
		phylink_set(mask, 100baseT_Half);
		phylink_set(mask, 100baseT_Full);
	}
}

static void mv88e6185_phylink_validate(struct mv88e6xxx_chip *chip, int port,
				       unsigned long *mask,
				       struct phylink_link_state *state)
{
	/* FIXME: if the port is in 1000Base-X mode, then it only supports
	 * 1000M FD speeds.  In this case, CMODE will indicate 5.
	 */
	phylink_set(mask, 1000baseT_Full);
	phylink_set(mask, 1000baseX_Full);

	mv88e6065_phylink_validate(chip, port, mask, state);
}

507 508 509 510 511 512 513 514 515 516 517 518 519 520
static void mv88e6341_phylink_validate(struct mv88e6xxx_chip *chip, int port,
				       unsigned long *mask,
				       struct phylink_link_state *state)
{
	if (port >= 5)
		phylink_set(mask, 2500baseX_Full);

	/* No ethtool bits for 200Mbps */
	phylink_set(mask, 1000baseT_Full);
	phylink_set(mask, 1000baseX_Full);

	mv88e6065_phylink_validate(chip, port, mask, state);
}

521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
static void mv88e6352_phylink_validate(struct mv88e6xxx_chip *chip, int port,
				       unsigned long *mask,
				       struct phylink_link_state *state)
{
	/* No ethtool bits for 200Mbps */
	phylink_set(mask, 1000baseT_Full);
	phylink_set(mask, 1000baseX_Full);

	mv88e6065_phylink_validate(chip, port, mask, state);
}

static void mv88e6390_phylink_validate(struct mv88e6xxx_chip *chip, int port,
				       unsigned long *mask,
				       struct phylink_link_state *state)
{
536
	if (port >= 9) {
537
		phylink_set(mask, 2500baseX_Full);
538 539
		phylink_set(mask, 2500baseT_Full);
	}
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559

	/* No ethtool bits for 200Mbps */
	phylink_set(mask, 1000baseT_Full);
	phylink_set(mask, 1000baseX_Full);

	mv88e6065_phylink_validate(chip, port, mask, state);
}

static void mv88e6390x_phylink_validate(struct mv88e6xxx_chip *chip, int port,
					unsigned long *mask,
					struct phylink_link_state *state)
{
	if (port >= 9) {
		phylink_set(mask, 10000baseT_Full);
		phylink_set(mask, 10000baseKR_Full);
	}

	mv88e6390_phylink_validate(chip, port, mask, state);
}

560 561 562 563
static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
			       unsigned long *supported,
			       struct phylink_link_state *state)
{
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582
	__ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
	struct mv88e6xxx_chip *chip = ds->priv;

	/* Allow all the expected bits */
	phylink_set(mask, Autoneg);
	phylink_set(mask, Pause);
	phylink_set_port_modes(mask);

	if (chip->info->ops->phylink_validate)
		chip->info->ops->phylink_validate(chip, port, mask, state);

	bitmap_and(supported, supported, mask, __ETHTOOL_LINK_MODE_MASK_NBITS);
	bitmap_and(state->advertising, state->advertising, mask,
		   __ETHTOOL_LINK_MODE_MASK_NBITS);

	/* We can only operate at 2500BaseX or 1000BaseX.  If requested
	 * to advertise both, only report advertising at 2500BaseX.
	 */
	phylink_helper_basex_speed(state);
583 584 585 586 587 588 589 590
}

static int mv88e6xxx_link_state(struct dsa_switch *ds, int port,
				struct phylink_link_state *state)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

591
	mv88e6xxx_reg_lock(chip);
592 593 594 595
	if (chip->info->ops->port_link_state)
		err = chip->info->ops->port_link_state(chip, port, state);
	else
		err = -EOPNOTSUPP;
596
	mv88e6xxx_reg_unlock(chip);
597 598 599 600 601 602 603 604 605

	return err;
}

static void mv88e6xxx_mac_config(struct dsa_switch *ds, int port,
				 unsigned int mode,
				 const struct phylink_link_state *state)
{
	struct mv88e6xxx_chip *chip = ds->priv;
606
	int speed, duplex, link, pause, err;
607

608
	if ((mode == MLO_AN_PHY) && mv88e6xxx_phy_is_internal(ds, port))
609 610 611 612 613 614
		return;

	if (mode == MLO_AN_FIXED) {
		link = LINK_FORCED_UP;
		speed = state->speed;
		duplex = state->duplex;
615 616 617 618
	} else if (!mv88e6xxx_phy_is_internal(ds, port)) {
		link = state->link;
		speed = state->speed;
		duplex = state->duplex;
619 620 621 622 623
	} else {
		speed = SPEED_UNFORCED;
		duplex = DUPLEX_UNFORCED;
		link = LINK_UNFORCED;
	}
624
	pause = !!phylink_test(state->advertising, Pause);
625

626
	mv88e6xxx_reg_lock(chip);
627
	err = mv88e6xxx_port_setup_mac(chip, port, link, speed, duplex, pause,
628
				       state->interface);
629
	mv88e6xxx_reg_unlock(chip);
630 631 632 633 634 635 636 637 638 639

	if (err && err != -EOPNOTSUPP)
		dev_err(ds->dev, "p%d: failed to configure MAC\n", port);
}

static void mv88e6xxx_mac_link_force(struct dsa_switch *ds, int port, int link)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

640
	mv88e6xxx_reg_lock(chip);
641
	err = chip->info->ops->port_set_link(chip, port, link);
642
	mv88e6xxx_reg_unlock(chip);
643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663

	if (err)
		dev_err(chip->dev, "p%d: failed to force MAC link\n", port);
}

static void mv88e6xxx_mac_link_down(struct dsa_switch *ds, int port,
				    unsigned int mode,
				    phy_interface_t interface)
{
	if (mode == MLO_AN_FIXED)
		mv88e6xxx_mac_link_force(ds, port, LINK_FORCED_DOWN);
}

static void mv88e6xxx_mac_link_up(struct dsa_switch *ds, int port,
				  unsigned int mode, phy_interface_t interface,
				  struct phy_device *phydev)
{
	if (mode == MLO_AN_FIXED)
		mv88e6xxx_mac_link_force(ds, port, LINK_FORCED_UP);
}

664
static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
665
{
666 667
	if (!chip->info->ops->stats_snapshot)
		return -EOPNOTSUPP;
668

669
	return chip->info->ops->stats_snapshot(chip, port);
670 671
}

672
static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731
	{ "in_good_octets",		8, 0x00, STATS_TYPE_BANK0, },
	{ "in_bad_octets",		4, 0x02, STATS_TYPE_BANK0, },
	{ "in_unicast",			4, 0x04, STATS_TYPE_BANK0, },
	{ "in_broadcasts",		4, 0x06, STATS_TYPE_BANK0, },
	{ "in_multicasts",		4, 0x07, STATS_TYPE_BANK0, },
	{ "in_pause",			4, 0x16, STATS_TYPE_BANK0, },
	{ "in_undersize",		4, 0x18, STATS_TYPE_BANK0, },
	{ "in_fragments",		4, 0x19, STATS_TYPE_BANK0, },
	{ "in_oversize",		4, 0x1a, STATS_TYPE_BANK0, },
	{ "in_jabber",			4, 0x1b, STATS_TYPE_BANK0, },
	{ "in_rx_error",		4, 0x1c, STATS_TYPE_BANK0, },
	{ "in_fcs_error",		4, 0x1d, STATS_TYPE_BANK0, },
	{ "out_octets",			8, 0x0e, STATS_TYPE_BANK0, },
	{ "out_unicast",		4, 0x10, STATS_TYPE_BANK0, },
	{ "out_broadcasts",		4, 0x13, STATS_TYPE_BANK0, },
	{ "out_multicasts",		4, 0x12, STATS_TYPE_BANK0, },
	{ "out_pause",			4, 0x15, STATS_TYPE_BANK0, },
	{ "excessive",			4, 0x11, STATS_TYPE_BANK0, },
	{ "collisions",			4, 0x1e, STATS_TYPE_BANK0, },
	{ "deferred",			4, 0x05, STATS_TYPE_BANK0, },
	{ "single",			4, 0x14, STATS_TYPE_BANK0, },
	{ "multiple",			4, 0x17, STATS_TYPE_BANK0, },
	{ "out_fcs_error",		4, 0x03, STATS_TYPE_BANK0, },
	{ "late",			4, 0x1f, STATS_TYPE_BANK0, },
	{ "hist_64bytes",		4, 0x08, STATS_TYPE_BANK0, },
	{ "hist_65_127bytes",		4, 0x09, STATS_TYPE_BANK0, },
	{ "hist_128_255bytes",		4, 0x0a, STATS_TYPE_BANK0, },
	{ "hist_256_511bytes",		4, 0x0b, STATS_TYPE_BANK0, },
	{ "hist_512_1023bytes",		4, 0x0c, STATS_TYPE_BANK0, },
	{ "hist_1024_max_bytes",	4, 0x0d, STATS_TYPE_BANK0, },
	{ "sw_in_discards",		4, 0x10, STATS_TYPE_PORT, },
	{ "sw_in_filtered",		2, 0x12, STATS_TYPE_PORT, },
	{ "sw_out_filtered",		2, 0x13, STATS_TYPE_PORT, },
	{ "in_discards",		4, 0x00, STATS_TYPE_BANK1, },
	{ "in_filtered",		4, 0x01, STATS_TYPE_BANK1, },
	{ "in_accepted",		4, 0x02, STATS_TYPE_BANK1, },
	{ "in_bad_accepted",		4, 0x03, STATS_TYPE_BANK1, },
	{ "in_good_avb_class_a",	4, 0x04, STATS_TYPE_BANK1, },
	{ "in_good_avb_class_b",	4, 0x05, STATS_TYPE_BANK1, },
	{ "in_bad_avb_class_a",		4, 0x06, STATS_TYPE_BANK1, },
	{ "in_bad_avb_class_b",		4, 0x07, STATS_TYPE_BANK1, },
	{ "tcam_counter_0",		4, 0x08, STATS_TYPE_BANK1, },
	{ "tcam_counter_1",		4, 0x09, STATS_TYPE_BANK1, },
	{ "tcam_counter_2",		4, 0x0a, STATS_TYPE_BANK1, },
	{ "tcam_counter_3",		4, 0x0b, STATS_TYPE_BANK1, },
	{ "in_da_unknown",		4, 0x0e, STATS_TYPE_BANK1, },
	{ "in_management",		4, 0x0f, STATS_TYPE_BANK1, },
	{ "out_queue_0",		4, 0x10, STATS_TYPE_BANK1, },
	{ "out_queue_1",		4, 0x11, STATS_TYPE_BANK1, },
	{ "out_queue_2",		4, 0x12, STATS_TYPE_BANK1, },
	{ "out_queue_3",		4, 0x13, STATS_TYPE_BANK1, },
	{ "out_queue_4",		4, 0x14, STATS_TYPE_BANK1, },
	{ "out_queue_5",		4, 0x15, STATS_TYPE_BANK1, },
	{ "out_queue_6",		4, 0x16, STATS_TYPE_BANK1, },
	{ "out_queue_7",		4, 0x17, STATS_TYPE_BANK1, },
	{ "out_cut_through",		4, 0x18, STATS_TYPE_BANK1, },
	{ "out_octets_a",		4, 0x1a, STATS_TYPE_BANK1, },
	{ "out_octets_b",		4, 0x1b, STATS_TYPE_BANK1, },
	{ "out_management",		4, 0x1f, STATS_TYPE_BANK1, },
732 733
};

734
static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
735
					    struct mv88e6xxx_hw_stat *s,
736 737
					    int port, u16 bank1_select,
					    u16 histogram)
738 739 740
{
	u32 low;
	u32 high = 0;
741
	u16 reg = 0;
742
	int err;
743 744
	u64 value;

745
	switch (s->type) {
746
	case STATS_TYPE_PORT:
747 748
		err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
		if (err)
749
			return U64_MAX;
750

751
		low = reg;
752
		if (s->size == 4) {
753 754
			err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
			if (err)
755
				return U64_MAX;
756
			low |= ((u32)reg) << 16;
757
		}
758
		break;
759
	case STATS_TYPE_BANK1:
760
		reg = bank1_select;
761 762
		/* fall through */
	case STATS_TYPE_BANK0:
763
		reg |= s->reg | histogram;
764
		mv88e6xxx_g1_stats_read(chip, reg, &low);
765
		if (s->size == 8)
766
			mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
767 768
		break;
	default:
769
		return U64_MAX;
770
	}
771
	value = (((u64)high) << 32) | low;
772 773 774
	return value;
}

775 776
static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data, int types)
777
{
778 779
	struct mv88e6xxx_hw_stat *stat;
	int i, j;
780

781 782
	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
		stat = &mv88e6xxx_hw_stats[i];
783
		if (stat->type & types) {
784 785 786 787
			memcpy(data + j * ETH_GSTRING_LEN, stat->string,
			       ETH_GSTRING_LEN);
			j++;
		}
788
	}
789 790

	return j;
791 792
}

793 794
static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
795
{
796 797
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_PORT);
798 799
}

800 801 802 803 804 805
static int mv88e6250_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
{
	return mv88e6xxx_stats_get_strings(chip, data, STATS_TYPE_BANK0);
}

806 807
static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
808
{
809 810
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
811 812
}

813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830
static const uint8_t *mv88e6xxx_atu_vtu_stats_strings[] = {
	"atu_member_violation",
	"atu_miss_violation",
	"atu_full_violation",
	"vtu_member_violation",
	"vtu_miss_violation",
};

static void mv88e6xxx_atu_vtu_get_strings(uint8_t *data)
{
	unsigned int i;

	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings); i++)
		strlcpy(data + i * ETH_GSTRING_LEN,
			mv88e6xxx_atu_vtu_stats_strings[i],
			ETH_GSTRING_LEN);
}

831
static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
832
				  u32 stringset, uint8_t *data)
833
{
V
Vivien Didelot 已提交
834
	struct mv88e6xxx_chip *chip = ds->priv;
835
	int count = 0;
836

837 838 839
	if (stringset != ETH_SS_STATS)
		return;

840
	mv88e6xxx_reg_lock(chip);
841

842
	if (chip->info->ops->stats_get_strings)
843 844 845 846
		count = chip->info->ops->stats_get_strings(chip, data);

	if (chip->info->ops->serdes_get_strings) {
		data += count * ETH_GSTRING_LEN;
847
		count = chip->info->ops->serdes_get_strings(chip, port, data);
848
	}
849

850 851 852
	data += count * ETH_GSTRING_LEN;
	mv88e6xxx_atu_vtu_get_strings(data);

853
	mv88e6xxx_reg_unlock(chip);
854 855 856 857 858
}

static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
					  int types)
{
859 860 861 862 863
	struct mv88e6xxx_hw_stat *stat;
	int i, j;

	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
		stat = &mv88e6xxx_hw_stats[i];
864
		if (stat->type & types)
865 866 867
			j++;
	}
	return j;
868 869
}

870 871 872 873 874 875
static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
{
	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
					      STATS_TYPE_PORT);
}

876 877 878 879 880
static int mv88e6250_stats_get_sset_count(struct mv88e6xxx_chip *chip)
{
	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0);
}

881 882 883 884 885 886
static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
{
	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
					      STATS_TYPE_BANK1);
}

887
static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
888 889
{
	struct mv88e6xxx_chip *chip = ds->priv;
890 891
	int serdes_count = 0;
	int count = 0;
892

893 894 895
	if (sset != ETH_SS_STATS)
		return 0;

896
	mv88e6xxx_reg_lock(chip);
897
	if (chip->info->ops->stats_get_sset_count)
898 899 900 901 902 903 904
		count = chip->info->ops->stats_get_sset_count(chip);
	if (count < 0)
		goto out;

	if (chip->info->ops->serdes_get_sset_count)
		serdes_count = chip->info->ops->serdes_get_sset_count(chip,
								      port);
905
	if (serdes_count < 0) {
906
		count = serdes_count;
907 908 909 910 911
		goto out;
	}
	count += serdes_count;
	count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);

912
out:
913
	mv88e6xxx_reg_unlock(chip);
914

915
	return count;
916 917
}

918 919 920
static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data, int types,
				     u16 bank1_select, u16 histogram)
921 922 923 924 925 926 927
{
	struct mv88e6xxx_hw_stat *stat;
	int i, j;

	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
		stat = &mv88e6xxx_hw_stats[i];
		if (stat->type & types) {
928
			mv88e6xxx_reg_lock(chip);
929 930 931
			data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
							      bank1_select,
							      histogram);
932
			mv88e6xxx_reg_unlock(chip);
933

934 935 936
			j++;
		}
	}
937
	return j;
938 939
}

940 941
static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
942 943
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
944
					 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
945
					 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
946 947
}

948 949 950 951 952 953 954
static int mv88e6250_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
{
	return mv88e6xxx_stats_get_stats(chip, port, data, STATS_TYPE_BANK0,
					 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
}

955 956
static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
957 958
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
959
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
960 961
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
					 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
962 963
}

964 965
static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
966 967 968
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
969 970
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
					 0);
971 972
}

973 974 975 976 977 978 979 980 981 982
static void mv88e6xxx_atu_vtu_get_stats(struct mv88e6xxx_chip *chip, int port,
					uint64_t *data)
{
	*data++ = chip->ports[port].atu_member_violation;
	*data++ = chip->ports[port].atu_miss_violation;
	*data++ = chip->ports[port].atu_full_violation;
	*data++ = chip->ports[port].vtu_member_violation;
	*data++ = chip->ports[port].vtu_miss_violation;
}

983 984 985
static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
				uint64_t *data)
{
986 987
	int count = 0;

988
	if (chip->info->ops->stats_get_stats)
989 990
		count = chip->info->ops->stats_get_stats(chip, port, data);

991
	mv88e6xxx_reg_lock(chip);
992 993
	if (chip->info->ops->serdes_get_stats) {
		data += count;
994
		count = chip->info->ops->serdes_get_stats(chip, port, data);
995
	}
996 997
	data += count;
	mv88e6xxx_atu_vtu_get_stats(chip, port, data);
998
	mv88e6xxx_reg_unlock(chip);
999 1000
}

1001 1002
static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
					uint64_t *data)
1003
{
V
Vivien Didelot 已提交
1004
	struct mv88e6xxx_chip *chip = ds->priv;
1005 1006
	int ret;

1007
	mv88e6xxx_reg_lock(chip);
1008

1009
	ret = mv88e6xxx_stats_snapshot(chip, port);
1010
	mv88e6xxx_reg_unlock(chip);
1011 1012

	if (ret < 0)
1013
		return;
1014 1015

	mv88e6xxx_get_stats(chip, port, data);
1016

1017 1018
}

1019
static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
1020
{
1021 1022 1023 1024 1025 1026 1027 1028
	struct mv88e6xxx_chip *chip = ds->priv;
	int len;

	len = 32 * sizeof(u16);
	if (chip->info->ops->serdes_get_regs_len)
		len += chip->info->ops->serdes_get_regs_len(chip, port);

	return len;
1029 1030
}

1031 1032
static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
			       struct ethtool_regs *regs, void *_p)
1033
{
V
Vivien Didelot 已提交
1034
	struct mv88e6xxx_chip *chip = ds->priv;
1035 1036
	int err;
	u16 reg;
1037 1038 1039
	u16 *p = _p;
	int i;

1040
	regs->version = chip->info->prod_num;
1041 1042 1043

	memset(p, 0xff, 32 * sizeof(u16));

1044
	mv88e6xxx_reg_lock(chip);
1045

1046 1047
	for (i = 0; i < 32; i++) {

1048 1049 1050
		err = mv88e6xxx_port_read(chip, port, i, &reg);
		if (!err)
			p[i] = reg;
1051
	}
1052

1053 1054 1055
	if (chip->info->ops->serdes_get_regs)
		chip->info->ops->serdes_get_regs(chip, port, &p[i]);

1056
	mv88e6xxx_reg_unlock(chip);
1057 1058
}

V
Vivien Didelot 已提交
1059 1060
static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
1061
{
1062 1063
	/* Nothing to do on the port's MAC */
	return 0;
1064 1065
}

V
Vivien Didelot 已提交
1066 1067
static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
1068
{
1069 1070
	/* Nothing to do on the port's MAC */
	return 0;
1071 1072
}

1073
/* Mask of the local ports allowed to receive frames from a given fabric port */
1074
static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
1075
{
1076 1077
	struct dsa_switch *ds = chip->ds;
	struct dsa_switch_tree *dst = ds->dst;
1078
	struct net_device *br;
1079 1080
	struct dsa_port *dp;
	bool found = false;
1081
	u16 pvlan;
1082

1083 1084 1085 1086 1087 1088
	list_for_each_entry(dp, &dst->ports, list) {
		if (dp->ds->index == dev && dp->index == port) {
			found = true;
			break;
		}
	}
1089 1090

	/* Prevent frames from unknown switch or port */
1091
	if (!found)
1092 1093 1094
		return 0;

	/* Frames from DSA links and CPU ports can egress any local port */
1095
	if (dp->type == DSA_PORT_TYPE_CPU || dp->type == DSA_PORT_TYPE_DSA)
1096 1097
		return mv88e6xxx_port_mask(chip);

1098
	br = dp->bridge_dev;
1099 1100 1101 1102 1103
	pvlan = 0;

	/* Frames from user ports can egress any local DSA links and CPU ports,
	 * as well as any local member of their bridge group.
	 */
1104 1105 1106 1107 1108 1109
	list_for_each_entry(dp, &dst->ports, list)
		if (dp->ds == ds &&
		    (dp->type == DSA_PORT_TYPE_CPU ||
		     dp->type == DSA_PORT_TYPE_DSA ||
		     (br && dp->bridge_dev == br)))
			pvlan |= BIT(dp->index);
1110 1111 1112 1113

	return pvlan;
}

1114
static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
1115 1116
{
	u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
1117 1118 1119

	/* prevent frames from going back out of the port they came in on */
	output_ports &= ~BIT(port);
1120

1121
	return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
1122 1123
}

1124 1125
static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
					 u8 state)
1126
{
V
Vivien Didelot 已提交
1127
	struct mv88e6xxx_chip *chip = ds->priv;
1128
	int err;
1129

1130
	mv88e6xxx_reg_lock(chip);
1131
	err = mv88e6xxx_port_set_state(chip, port, state);
1132
	mv88e6xxx_reg_unlock(chip);
1133 1134

	if (err)
1135
		dev_err(ds->dev, "p%d: failed to update state\n", port);
1136 1137
}

1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156
static int mv88e6xxx_pri_setup(struct mv88e6xxx_chip *chip)
{
	int err;

	if (chip->info->ops->ieee_pri_map) {
		err = chip->info->ops->ieee_pri_map(chip);
		if (err)
			return err;
	}

	if (chip->info->ops->ip_pri_map) {
		err = chip->info->ops->ip_pri_map(chip);
		if (err)
			return err;
	}

	return 0;
}

1157 1158
static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
{
1159
	struct dsa_switch *ds = chip->ds;
1160 1161 1162 1163 1164 1165 1166 1167
	int target, port;
	int err;

	if (!chip->info->global2_addr)
		return 0;

	/* Initialize the routing port to the 32 possible target devices */
	for (target = 0; target < 32; target++) {
1168 1169 1170
		port = dsa_routing_port(ds, target);
		if (port == ds->num_ports)
			port = 0x1f;
1171 1172 1173 1174 1175 1176

		err = mv88e6xxx_g2_device_mapping_write(chip, target, port);
		if (err)
			return err;
	}

1177 1178 1179 1180 1181 1182 1183
	if (chip->info->ops->set_cascade_port) {
		port = MV88E6XXX_CASCADE_PORT_MULTIPLE;
		err = chip->info->ops->set_cascade_port(chip, port);
		if (err)
			return err;
	}

1184 1185 1186 1187
	err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
	if (err)
		return err;

1188 1189 1190
	return 0;
}

1191 1192 1193 1194 1195 1196 1197 1198 1199
static int mv88e6xxx_trunk_setup(struct mv88e6xxx_chip *chip)
{
	/* Clear all trunk masks and mapping */
	if (chip->info->global2_addr)
		return mv88e6xxx_g2_trunk_clear(chip);

	return 0;
}

1200 1201 1202 1203 1204 1205 1206 1207
static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->rmu_disable)
		return chip->info->ops->rmu_disable(chip);

	return 0;
}

1208 1209 1210 1211 1212 1213 1214 1215
static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->pot_clear)
		return chip->info->ops->pot_clear(chip);

	return 0;
}

1216 1217 1218 1219 1220 1221 1222 1223
static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->mgmt_rsvd2cpu)
		return chip->info->ops->mgmt_rsvd2cpu(chip);

	return 0;
}

1224 1225
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
1226 1227
	int err;

1228 1229 1230 1231
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

1232 1233 1234 1235
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

1236 1237 1238
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258
static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
{
	int port;
	int err;

	if (!chip->info->ops->irl_init_all)
		return 0;

	for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
		/* Disable ingress rate limiting by resetting all per port
		 * ingress rate limit resources to their initial state.
		 */
		err = chip->info->ops->irl_init_all(chip, port);
		if (err)
			return err;
	}

	return 0;
}

1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271
static int mv88e6xxx_mac_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->set_switch_mac) {
		u8 addr[ETH_ALEN];

		eth_random_addr(addr);

		return chip->info->ops->set_switch_mac(chip, addr);
	}

	return 0;
}

1272 1273 1274 1275 1276
static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
{
	u16 pvlan = 0;

	if (!mv88e6xxx_has_pvt(chip))
1277
		return 0;
1278 1279 1280

	/* Skip the local source device, which uses in-chip port VLAN */
	if (dev != chip->ds->index)
1281
		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1282 1283 1284 1285

	return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
}

1286 1287
static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
{
1288 1289 1290
	int dev, port;
	int err;

1291 1292 1293 1294 1295 1296
	if (!mv88e6xxx_has_pvt(chip))
		return 0;

	/* Clear 5 Bit Port for usage with Marvell Link Street devices:
	 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
	 */
1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309
	err = mv88e6xxx_g2_misc_4_bit_port(chip);
	if (err)
		return err;

	for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
		for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
			err = mv88e6xxx_pvt_map(chip, dev, port);
			if (err)
				return err;
		}
	}

	return 0;
1310 1311
}

1312 1313 1314 1315 1316
static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

1317
	mv88e6xxx_reg_lock(chip);
1318
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1319
	mv88e6xxx_reg_unlock(chip);
1320 1321

	if (err)
1322
		dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
1323 1324
}

1325 1326 1327 1328 1329 1330 1331 1332
static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
{
	if (!chip->info->max_vid)
		return 0;

	return mv88e6xxx_g1_vtu_flush(chip);
}

1333 1334 1335 1336 1337 1338 1339 1340 1341
static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
				 struct mv88e6xxx_vtu_entry *entry)
{
	if (!chip->info->ops->vtu_getnext)
		return -EOPNOTSUPP;

	return chip->info->ops->vtu_getnext(chip, entry);
}

1342 1343 1344 1345 1346 1347 1348 1349 1350
static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
				   struct mv88e6xxx_vtu_entry *entry)
{
	if (!chip->info->ops->vtu_loadpurge)
		return -EOPNOTSUPP;

	return chip->info->ops->vtu_loadpurge(chip, entry);
}

1351
static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1352 1353
{
	DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1354
	struct mv88e6xxx_vtu_entry vlan;
1355
	int i, err;
1356 1357 1358

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

1359
	/* Set every FID bit used by the (un)bridged ports */
1360
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1361
		err = mv88e6xxx_port_get_fid(chip, i, fid);
1362 1363 1364 1365 1366 1367
		if (err)
			return err;

		set_bit(*fid, fid_bitmap);
	}

1368
	/* Set every FID bit used by the VLAN entries */
1369 1370 1371
	vlan.vid = chip->info->max_vid;
	vlan.valid = false;

1372
	do {
1373
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1374 1375 1376 1377 1378 1379 1380
		if (err)
			return err;

		if (!vlan.valid)
			break;

		set_bit(vlan.fid, fid_bitmap);
1381
	} while (vlan.vid < chip->info->max_vid);
1382 1383 1384 1385 1386

	/* The reset value 0x000 is used to indicate that multiple address
	 * databases are not needed. Return the next positive available.
	 */
	*fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
1387
	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1388 1389 1390
		return -ENOSPC;

	/* Clear the database */
1391
	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1392 1393
}

1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409
static int mv88e6xxx_atu_get_hash(struct mv88e6xxx_chip *chip, u8 *hash)
{
	if (chip->info->ops->atu_get_hash)
		return chip->info->ops->atu_get_hash(chip, hash);

	return -EOPNOTSUPP;
}

static int mv88e6xxx_atu_set_hash(struct mv88e6xxx_chip *chip, u8 hash)
{
	if (chip->info->ops->atu_set_hash)
		return chip->info->ops->atu_set_hash(chip, hash);

	return -EOPNOTSUPP;
}

1410 1411 1412
static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
					u16 vid_begin, u16 vid_end)
{
V
Vivien Didelot 已提交
1413
	struct mv88e6xxx_chip *chip = ds->priv;
1414
	struct mv88e6xxx_vtu_entry vlan;
1415 1416
	int i, err;

1417 1418 1419 1420
	/* DSA and CPU ports have to be members of multiple vlans */
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
		return 0;

1421 1422 1423
	if (!vid_begin)
		return -EOPNOTSUPP;

1424 1425 1426
	vlan.vid = vid_begin - 1;
	vlan.valid = false;

1427
	do {
1428
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1429
		if (err)
1430
			return err;
1431 1432 1433 1434 1435 1436 1437

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

1438
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1439 1440 1441
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

1442
			if (!dsa_to_port(ds, i)->slave)
1443 1444
				continue;

1445
			if (vlan.member[i] ==
1446
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1447 1448
				continue;

V
Vivien Didelot 已提交
1449
			if (dsa_to_port(ds, i)->bridge_dev ==
1450
			    dsa_to_port(ds, port)->bridge_dev)
1451 1452
				break; /* same bridge, check next VLAN */

V
Vivien Didelot 已提交
1453
			if (!dsa_to_port(ds, i)->bridge_dev)
1454 1455
				continue;

1456 1457
			dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
				port, vlan.vid, i,
V
Vivien Didelot 已提交
1458
				netdev_name(dsa_to_port(ds, i)->bridge_dev));
1459
			return -EOPNOTSUPP;
1460 1461 1462
		}
	} while (vlan.vid < vid_end);

1463
	return 0;
1464 1465
}

1466 1467
static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
					 bool vlan_filtering)
1468
{
V
Vivien Didelot 已提交
1469
	struct mv88e6xxx_chip *chip = ds->priv;
1470 1471
	u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
		MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
1472
	int err;
1473

1474
	if (!chip->info->max_vid)
1475 1476
		return -EOPNOTSUPP;

1477
	mv88e6xxx_reg_lock(chip);
1478
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1479
	mv88e6xxx_reg_unlock(chip);
1480

1481
	return err;
1482 1483
}

1484 1485
static int
mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1486
			    const struct switchdev_obj_port_vlan *vlan)
1487
{
V
Vivien Didelot 已提交
1488
	struct mv88e6xxx_chip *chip = ds->priv;
1489 1490
	int err;

1491
	if (!chip->info->max_vid)
1492 1493
		return -EOPNOTSUPP;

1494 1495 1496
	/* If the requested port doesn't belong to the same bridge as the VLAN
	 * members, do not support it (yet) and fallback to software VLAN.
	 */
1497
	mv88e6xxx_reg_lock(chip);
1498 1499
	err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
					   vlan->vid_end);
1500
	mv88e6xxx_reg_unlock(chip);
1501

1502 1503 1504
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */
1505
	return err;
1506 1507
}

1508 1509 1510 1511 1512
static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
					const unsigned char *addr, u16 vid,
					u8 state)
{
	struct mv88e6xxx_atu_entry entry;
1513 1514
	struct mv88e6xxx_vtu_entry vlan;
	u16 fid;
1515 1516 1517
	int err;

	/* Null VLAN ID corresponds to the port private database */
1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535
	if (vid == 0) {
		err = mv88e6xxx_port_get_fid(chip, port, &fid);
		if (err)
			return err;
	} else {
		vlan.vid = vid - 1;
		vlan.valid = false;

		err = mv88e6xxx_vtu_getnext(chip, &vlan);
		if (err)
			return err;

		/* switchdev expects -EOPNOTSUPP to honor software VLANs */
		if (vlan.vid != vid || !vlan.valid)
			return -EOPNOTSUPP;

		fid = vlan.fid;
	}
1536

1537
	entry.state = 0;
1538 1539 1540
	ether_addr_copy(entry.mac, addr);
	eth_addr_dec(entry.mac);

1541
	err = mv88e6xxx_g1_atu_getnext(chip, fid, &entry);
1542 1543 1544 1545
	if (err)
		return err;

	/* Initialize a fresh ATU entry if it isn't found */
1546
	if (!entry.state || !ether_addr_equal(entry.mac, addr)) {
1547 1548 1549 1550 1551
		memset(&entry, 0, sizeof(entry));
		ether_addr_copy(entry.mac, addr);
	}

	/* Purge the ATU entry only if no port is using it anymore */
1552
	if (!state) {
1553 1554
		entry.portvec &= ~BIT(port);
		if (!entry.portvec)
1555
			entry.state = 0;
1556 1557 1558 1559 1560
	} else {
		entry.portvec |= BIT(port);
		entry.state = state;
	}

1561
	return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry);
1562 1563
}

1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773
static int mv88e6xxx_policy_apply(struct mv88e6xxx_chip *chip, int port,
				  const struct mv88e6xxx_policy *policy)
{
	enum mv88e6xxx_policy_mapping mapping = policy->mapping;
	enum mv88e6xxx_policy_action action = policy->action;
	const u8 *addr = policy->addr;
	u16 vid = policy->vid;
	u8 state;
	int err;
	int id;

	if (!chip->info->ops->port_set_policy)
		return -EOPNOTSUPP;

	switch (mapping) {
	case MV88E6XXX_POLICY_MAPPING_DA:
	case MV88E6XXX_POLICY_MAPPING_SA:
		if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
			state = 0; /* Dissociate the port and address */
		else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
			 is_multicast_ether_addr(addr))
			state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC_POLICY;
		else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
			 is_unicast_ether_addr(addr))
			state = MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC_POLICY;
		else
			return -EOPNOTSUPP;

		err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
						   state);
		if (err)
			return err;
		break;
	default:
		return -EOPNOTSUPP;
	}

	/* Skip the port's policy clearing if the mapping is still in use */
	if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
		idr_for_each_entry(&chip->policies, policy, id)
			if (policy->port == port &&
			    policy->mapping == mapping &&
			    policy->action != action)
				return 0;

	return chip->info->ops->port_set_policy(chip, port, mapping, action);
}

static int mv88e6xxx_policy_insert(struct mv88e6xxx_chip *chip, int port,
				   struct ethtool_rx_flow_spec *fs)
{
	struct ethhdr *mac_entry = &fs->h_u.ether_spec;
	struct ethhdr *mac_mask = &fs->m_u.ether_spec;
	enum mv88e6xxx_policy_mapping mapping;
	enum mv88e6xxx_policy_action action;
	struct mv88e6xxx_policy *policy;
	u16 vid = 0;
	u8 *addr;
	int err;
	int id;

	if (fs->location != RX_CLS_LOC_ANY)
		return -EINVAL;

	if (fs->ring_cookie == RX_CLS_FLOW_DISC)
		action = MV88E6XXX_POLICY_ACTION_DISCARD;
	else
		return -EOPNOTSUPP;

	switch (fs->flow_type & ~FLOW_EXT) {
	case ETHER_FLOW:
		if (!is_zero_ether_addr(mac_mask->h_dest) &&
		    is_zero_ether_addr(mac_mask->h_source)) {
			mapping = MV88E6XXX_POLICY_MAPPING_DA;
			addr = mac_entry->h_dest;
		} else if (is_zero_ether_addr(mac_mask->h_dest) &&
		    !is_zero_ether_addr(mac_mask->h_source)) {
			mapping = MV88E6XXX_POLICY_MAPPING_SA;
			addr = mac_entry->h_source;
		} else {
			/* Cannot support DA and SA mapping in the same rule */
			return -EOPNOTSUPP;
		}
		break;
	default:
		return -EOPNOTSUPP;
	}

	if ((fs->flow_type & FLOW_EXT) && fs->m_ext.vlan_tci) {
		if (fs->m_ext.vlan_tci != 0xffff)
			return -EOPNOTSUPP;
		vid = be16_to_cpu(fs->h_ext.vlan_tci) & VLAN_VID_MASK;
	}

	idr_for_each_entry(&chip->policies, policy, id) {
		if (policy->port == port && policy->mapping == mapping &&
		    policy->action == action && policy->vid == vid &&
		    ether_addr_equal(policy->addr, addr))
			return -EEXIST;
	}

	policy = devm_kzalloc(chip->dev, sizeof(*policy), GFP_KERNEL);
	if (!policy)
		return -ENOMEM;

	fs->location = 0;
	err = idr_alloc_u32(&chip->policies, policy, &fs->location, 0xffffffff,
			    GFP_KERNEL);
	if (err) {
		devm_kfree(chip->dev, policy);
		return err;
	}

	memcpy(&policy->fs, fs, sizeof(*fs));
	ether_addr_copy(policy->addr, addr);
	policy->mapping = mapping;
	policy->action = action;
	policy->port = port;
	policy->vid = vid;

	err = mv88e6xxx_policy_apply(chip, port, policy);
	if (err) {
		idr_remove(&chip->policies, fs->location);
		devm_kfree(chip->dev, policy);
		return err;
	}

	return 0;
}

static int mv88e6xxx_get_rxnfc(struct dsa_switch *ds, int port,
			       struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
{
	struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
	struct mv88e6xxx_chip *chip = ds->priv;
	struct mv88e6xxx_policy *policy;
	int err;
	int id;

	mv88e6xxx_reg_lock(chip);

	switch (rxnfc->cmd) {
	case ETHTOOL_GRXCLSRLCNT:
		rxnfc->data = 0;
		rxnfc->data |= RX_CLS_LOC_SPECIAL;
		rxnfc->rule_cnt = 0;
		idr_for_each_entry(&chip->policies, policy, id)
			if (policy->port == port)
				rxnfc->rule_cnt++;
		err = 0;
		break;
	case ETHTOOL_GRXCLSRULE:
		err = -ENOENT;
		policy = idr_find(&chip->policies, fs->location);
		if (policy) {
			memcpy(fs, &policy->fs, sizeof(*fs));
			err = 0;
		}
		break;
	case ETHTOOL_GRXCLSRLALL:
		rxnfc->data = 0;
		rxnfc->rule_cnt = 0;
		idr_for_each_entry(&chip->policies, policy, id)
			if (policy->port == port)
				rule_locs[rxnfc->rule_cnt++] = id;
		err = 0;
		break;
	default:
		err = -EOPNOTSUPP;
		break;
	}

	mv88e6xxx_reg_unlock(chip);

	return err;
}

static int mv88e6xxx_set_rxnfc(struct dsa_switch *ds, int port,
			       struct ethtool_rxnfc *rxnfc)
{
	struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
	struct mv88e6xxx_chip *chip = ds->priv;
	struct mv88e6xxx_policy *policy;
	int err;

	mv88e6xxx_reg_lock(chip);

	switch (rxnfc->cmd) {
	case ETHTOOL_SRXCLSRLINS:
		err = mv88e6xxx_policy_insert(chip, port, fs);
		break;
	case ETHTOOL_SRXCLSRLDEL:
		err = -ENOENT;
		policy = idr_remove(&chip->policies, fs->location);
		if (policy) {
			policy->action = MV88E6XXX_POLICY_ACTION_NORMAL;
			err = mv88e6xxx_policy_apply(chip, port, policy);
			devm_kfree(chip->dev, policy);
		}
		break;
	default:
		err = -EOPNOTSUPP;
		break;
	}

	mv88e6xxx_reg_unlock(chip);

	return err;
}

1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796
static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
					u16 vid)
{
	const char broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
	u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;

	return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state);
}

static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid)
{
	int port;
	int err;

	for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
		err = mv88e6xxx_port_add_broadcast(chip, port, vid);
		if (err)
			return err;
	}

	return 0;
}

1797
static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port,
1798
				    u16 vid, u8 member)
1799
{
1800
	const u8 non_member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1801
	struct mv88e6xxx_vtu_entry vlan;
1802
	int i, err;
1803

1804 1805
	if (!vid)
		return -EOPNOTSUPP;
1806

1807 1808
	vlan.vid = vid - 1;
	vlan.valid = false;
1809

1810
	err = mv88e6xxx_vtu_getnext(chip, &vlan);
1811 1812 1813
	if (err)
		return err;

1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848
	if (vlan.vid != vid || !vlan.valid) {
		memset(&vlan, 0, sizeof(vlan));

		err = mv88e6xxx_atu_new(chip, &vlan.fid);
		if (err)
			return err;

		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
			if (i == port)
				vlan.member[i] = member;
			else
				vlan.member[i] = non_member;

		vlan.vid = vid;
		vlan.valid = true;

		err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
		if (err)
			return err;

		err = mv88e6xxx_broadcast_setup(chip, vlan.vid);
		if (err)
			return err;
	} else if (vlan.member[port] != member) {
		vlan.member[port] = member;

		err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
		if (err)
			return err;
	} else {
		dev_info(chip->dev, "p%d: already a member of VLAN %d\n",
			 port, vid);
	}

	return 0;
1849 1850
}

1851
static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1852
				    const struct switchdev_obj_port_vlan *vlan)
1853
{
V
Vivien Didelot 已提交
1854
	struct mv88e6xxx_chip *chip = ds->priv;
1855 1856
	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1857
	u8 member;
1858 1859
	u16 vid;

1860
	if (!chip->info->max_vid)
1861 1862
		return;

1863
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1864
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1865
	else if (untagged)
1866
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
1867
	else
1868
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
1869

1870
	mv88e6xxx_reg_lock(chip);
1871

1872
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
1873
		if (mv88e6xxx_port_vlan_join(chip, port, vid, member))
1874 1875
			dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
				vid, untagged ? 'u' : 't');
1876

1877
	if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1878 1879
		dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
			vlan->vid_end);
1880

1881
	mv88e6xxx_reg_unlock(chip);
1882 1883
}

1884 1885
static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,
				     int port, u16 vid)
1886
{
1887
	struct mv88e6xxx_vtu_entry vlan;
1888 1889
	int i, err;

1890 1891 1892 1893 1894 1895 1896
	if (!vid)
		return -EOPNOTSUPP;

	vlan.vid = vid - 1;
	vlan.valid = false;

	err = mv88e6xxx_vtu_getnext(chip, &vlan);
1897
	if (err)
1898
		return err;
1899

1900 1901 1902 1903 1904
	/* If the VLAN doesn't exist in hardware or the port isn't a member,
	 * tell switchdev that this VLAN is likely handled in software.
	 */
	if (vlan.vid != vid || !vlan.valid ||
	    vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1905
		return -EOPNOTSUPP;
1906

1907
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1908 1909

	/* keep the VLAN unless all ports are excluded */
1910
	vlan.valid = false;
1911
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1912 1913
		if (vlan.member[i] !=
		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
1914
			vlan.valid = true;
1915 1916 1917 1918
			break;
		}
	}

1919
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1920 1921 1922
	if (err)
		return err;

1923
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
1924 1925
}

1926 1927
static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
				   const struct switchdev_obj_port_vlan *vlan)
1928
{
V
Vivien Didelot 已提交
1929
	struct mv88e6xxx_chip *chip = ds->priv;
1930 1931 1932
	u16 pvid, vid;
	int err = 0;

1933
	if (!chip->info->max_vid)
1934 1935
		return -EOPNOTSUPP;

1936
	mv88e6xxx_reg_lock(chip);
1937

1938
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
1939 1940 1941
	if (err)
		goto unlock;

1942
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1943
		err = mv88e6xxx_port_vlan_leave(chip, port, vid);
1944 1945 1946 1947
		if (err)
			goto unlock;

		if (vid == pvid) {
1948
			err = mv88e6xxx_port_set_pvid(chip, port, 0);
1949 1950 1951 1952 1953
			if (err)
				goto unlock;
		}
	}

1954
unlock:
1955
	mv88e6xxx_reg_unlock(chip);
1956 1957 1958 1959

	return err;
}

1960 1961
static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
				  const unsigned char *addr, u16 vid)
1962
{
V
Vivien Didelot 已提交
1963
	struct mv88e6xxx_chip *chip = ds->priv;
1964
	int err;
1965

1966
	mv88e6xxx_reg_lock(chip);
1967 1968
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1969
	mv88e6xxx_reg_unlock(chip);
1970 1971

	return err;
1972 1973
}

1974
static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1975
				  const unsigned char *addr, u16 vid)
1976
{
V
Vivien Didelot 已提交
1977
	struct mv88e6xxx_chip *chip = ds->priv;
1978
	int err;
1979

1980
	mv88e6xxx_reg_lock(chip);
1981
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid, 0);
1982
	mv88e6xxx_reg_unlock(chip);
1983

1984
	return err;
1985 1986
}

1987 1988
static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
				      u16 fid, u16 vid, int port,
1989
				      dsa_fdb_dump_cb_t *cb, void *data)
1990
{
1991
	struct mv88e6xxx_atu_entry addr;
1992
	bool is_static;
1993 1994
	int err;

1995
	addr.state = 0;
1996
	eth_broadcast_addr(addr.mac);
1997 1998

	do {
1999
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
2000
		if (err)
2001
			return err;
2002

2003
		if (!addr.state)
2004 2005
			break;

2006
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
2007 2008
			continue;

2009 2010
		if (!is_unicast_ether_addr(addr.mac))
			continue;
2011

2012 2013 2014
		is_static = (addr.state ==
			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
		err = cb(addr.mac, vid, is_static, data);
2015 2016
		if (err)
			return err;
2017 2018 2019 2020 2021
	} while (!is_broadcast_ether_addr(addr.mac));

	return err;
}

2022
static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2023
				  dsa_fdb_dump_cb_t *cb, void *data)
2024
{
2025
	struct mv88e6xxx_vtu_entry vlan;
2026
	u16 fid;
2027 2028
	int err;

2029
	/* Dump port's default Filtering Information Database (VLAN ID 0) */
2030
	err = mv88e6xxx_port_get_fid(chip, port, &fid);
2031
	if (err)
2032
		return err;
2033

2034
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
2035
	if (err)
2036
		return err;
2037

2038
	/* Dump VLANs' Filtering Information Databases */
2039 2040 2041
	vlan.vid = chip->info->max_vid;
	vlan.valid = false;

2042
	do {
2043
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
2044
		if (err)
2045
			return err;
2046 2047 2048 2049

		if (!vlan.valid)
			break;

2050
		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
2051
						 cb, data);
2052
		if (err)
2053
			return err;
2054
	} while (vlan.vid < chip->info->max_vid);
2055

2056 2057 2058 2059
	return err;
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2060
				   dsa_fdb_dump_cb_t *cb, void *data)
2061
{
V
Vivien Didelot 已提交
2062
	struct mv88e6xxx_chip *chip = ds->priv;
2063 2064
	int err;

2065
	mv88e6xxx_reg_lock(chip);
2066
	err = mv88e6xxx_port_db_dump(chip, port, cb, data);
2067
	mv88e6xxx_reg_unlock(chip);
2068

2069
	return err;
2070 2071
}

2072 2073
static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
				struct net_device *br)
2074
{
2075 2076 2077
	struct dsa_switch *ds = chip->ds;
	struct dsa_switch_tree *dst = ds->dst;
	struct dsa_port *dp;
2078
	int err;
2079

2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094
	list_for_each_entry(dp, &dst->ports, list) {
		if (dp->bridge_dev == br) {
			if (dp->ds == ds) {
				/* This is a local bridge group member,
				 * remap its Port VLAN Map.
				 */
				err = mv88e6xxx_port_vlan_map(chip, dp->index);
				if (err)
					return err;
			} else {
				/* This is an external bridge group member,
				 * remap its cross-chip Port VLAN Table entry.
				 */
				err = mv88e6xxx_pvt_map(chip, dp->ds->index,
							dp->index);
2095 2096 2097 2098 2099 2100
				if (err)
					return err;
			}
		}
	}

2101 2102 2103 2104 2105 2106 2107 2108 2109
	return 0;
}

static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
				      struct net_device *br)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

2110
	mv88e6xxx_reg_lock(chip);
2111
	err = mv88e6xxx_bridge_map(chip, br);
2112
	mv88e6xxx_reg_unlock(chip);
2113

2114
	return err;
2115 2116
}

2117 2118
static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
					struct net_device *br)
2119
{
V
Vivien Didelot 已提交
2120
	struct mv88e6xxx_chip *chip = ds->priv;
2121

2122
	mv88e6xxx_reg_lock(chip);
2123 2124 2125
	if (mv88e6xxx_bridge_map(chip, br) ||
	    mv88e6xxx_port_vlan_map(chip, port))
		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
2126
	mv88e6xxx_reg_unlock(chip);
2127 2128
}

2129 2130 2131 2132 2133 2134
static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, int dev,
					   int port, struct net_device *br)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

2135
	mv88e6xxx_reg_lock(chip);
2136
	err = mv88e6xxx_pvt_map(chip, dev, port);
2137
	mv88e6xxx_reg_unlock(chip);
2138 2139 2140 2141 2142 2143 2144 2145 2146

	return err;
}

static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, int dev,
					     int port, struct net_device *br)
{
	struct mv88e6xxx_chip *chip = ds->priv;

2147
	mv88e6xxx_reg_lock(chip);
2148 2149
	if (mv88e6xxx_pvt_map(chip, dev, port))
		dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
2150
	mv88e6xxx_reg_unlock(chip);
2151 2152
}

2153 2154 2155 2156 2157 2158 2159 2160
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->reset)
		return chip->info->ops->reset(chip);

	return 0;
}

2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173
static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
{
	struct gpio_desc *gpiod = chip->reset;

	/* If there is a GPIO connected to the reset pin, toggle it */
	if (gpiod) {
		gpiod_set_value_cansleep(gpiod, 1);
		usleep_range(10000, 20000);
		gpiod_set_value_cansleep(gpiod, 0);
		usleep_range(10000, 20000);
	}
}

2174
static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2175
{
2176
	int i, err;
2177

2178
	/* Set all ports to the Disabled state */
2179
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2180
		err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
2181 2182
		if (err)
			return err;
2183 2184
	}

2185 2186 2187
	/* Wait for transmit queues to drain,
	 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
	 */
2188 2189
	usleep_range(2000, 4000);

2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200
	return 0;
}

static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
{
	int err;

	err = mv88e6xxx_disable_ports(chip);
	if (err)
		return err;

2201
	mv88e6xxx_hardware_reset(chip);
2202

2203
	return mv88e6xxx_software_reset(chip);
2204 2205
}

2206
static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
2207 2208
				   enum mv88e6xxx_frame_mode frame,
				   enum mv88e6xxx_egress_mode egress, u16 etype)
2209 2210 2211
{
	int err;

2212 2213 2214 2215
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
2216 2217 2218
	if (err)
		return err;

2219 2220 2221 2222 2223 2224 2225 2226
	err = chip->info->ops->port_set_frame_mode(chip, port, frame);
	if (err)
		return err;

	if (chip->info->ops->port_set_ether_type)
		return chip->info->ops->port_set_ether_type(chip, port, etype);

	return 0;
2227 2228
}

2229
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2230
{
2231
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
2232
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2233
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2234
}
2235

2236 2237 2238
static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
2239
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2240
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2241
}
2242

2243 2244 2245 2246
static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port,
				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
2247 2248
				       MV88E6XXX_EGRESS_MODE_ETHERTYPE,
				       ETH_P_EDSA);
2249
}
2250

2251 2252 2253 2254
static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
{
	if (dsa_is_dsa_port(chip->ds, port))
		return mv88e6xxx_set_port_mode_dsa(chip, port);
2255

2256
	if (dsa_is_user_port(chip->ds, port))
2257
		return mv88e6xxx_set_port_mode_normal(chip, port);
2258

2259 2260 2261
	/* Setup CPU port mode depending on its supported tag format */
	if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
		return mv88e6xxx_set_port_mode_dsa(chip, port);
2262

2263 2264
	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
		return mv88e6xxx_set_port_mode_edsa(chip, port);
2265

2266
	return -EINVAL;
2267 2268
}

2269
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2270
{
2271
	bool message = dsa_is_dsa_port(chip->ds, port);
2272

2273
	return mv88e6xxx_port_set_message_port(chip, port, message);
2274
}
2275

2276
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2277
{
2278
	struct dsa_switch *ds = chip->ds;
2279
	bool flood;
2280

2281 2282 2283 2284 2285
	/* Upstream ports flood frames with unknown unicast or multicast DA */
	flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
	if (chip->info->ops->port_set_egress_floods)
		return chip->info->ops->port_set_egress_floods(chip, port,
							       flood, flood);
2286

2287
	return 0;
2288 2289
}

2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318
static irqreturn_t mv88e6xxx_serdes_irq_thread_fn(int irq, void *dev_id)
{
	struct mv88e6xxx_port *mvp = dev_id;
	struct mv88e6xxx_chip *chip = mvp->chip;
	irqreturn_t ret = IRQ_NONE;
	int port = mvp->port;
	u8 lane;

	mv88e6xxx_reg_lock(chip);
	lane = mv88e6xxx_serdes_get_lane(chip, port);
	if (lane)
		ret = mv88e6xxx_serdes_irq_status(chip, port, lane);
	mv88e6xxx_reg_unlock(chip);

	return ret;
}

static int mv88e6xxx_serdes_irq_request(struct mv88e6xxx_chip *chip, int port,
					u8 lane)
{
	struct mv88e6xxx_port *dev_id = &chip->ports[port];
	unsigned int irq;
	int err;

	/* Nothing to request if this SERDES port has no IRQ */
	irq = mv88e6xxx_serdes_irq_mapping(chip, port);
	if (!irq)
		return 0;

2319 2320 2321
	snprintf(dev_id->serdes_irq_name, sizeof(dev_id->serdes_irq_name),
		 "mv88e6xxx-%s-serdes-%d", dev_name(chip->dev), port);

2322 2323 2324
	/* Requesting the IRQ will trigger IRQ callbacks, so release the lock */
	mv88e6xxx_reg_unlock(chip);
	err = request_threaded_irq(irq, NULL, mv88e6xxx_serdes_irq_thread_fn,
2325 2326
				   IRQF_ONESHOT, dev_id->serdes_irq_name,
				   dev_id);
2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358
	mv88e6xxx_reg_lock(chip);
	if (err)
		return err;

	dev_id->serdes_irq = irq;

	return mv88e6xxx_serdes_irq_enable(chip, port, lane);
}

static int mv88e6xxx_serdes_irq_free(struct mv88e6xxx_chip *chip, int port,
				     u8 lane)
{
	struct mv88e6xxx_port *dev_id = &chip->ports[port];
	unsigned int irq = dev_id->serdes_irq;
	int err;

	/* Nothing to free if no IRQ has been requested */
	if (!irq)
		return 0;

	err = mv88e6xxx_serdes_irq_disable(chip, port, lane);

	/* Freeing the IRQ will trigger IRQ callbacks, so release the lock */
	mv88e6xxx_reg_unlock(chip);
	free_irq(irq, dev_id);
	mv88e6xxx_reg_lock(chip);

	dev_id->serdes_irq = 0;

	return err;
}

2359 2360 2361
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
2362
	u8 lane;
2363
	int err;
2364

2365 2366
	lane = mv88e6xxx_serdes_get_lane(chip, port);
	if (!lane)
2367 2368 2369
		return 0;

	if (on) {
2370
		err = mv88e6xxx_serdes_power_up(chip, port, lane);
2371 2372 2373
		if (err)
			return err;

2374
		err = mv88e6xxx_serdes_irq_request(chip, port, lane);
2375
	} else {
2376 2377 2378
		err = mv88e6xxx_serdes_irq_free(chip, port, lane);
		if (err)
			return err;
2379

2380
		err = mv88e6xxx_serdes_power_down(chip, port, lane);
2381 2382 2383
	}

	return err;
2384 2385
}

2386 2387 2388 2389 2390 2391
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

2392
	upstream_port = dsa_upstream_port(ds, port);
2393 2394 2395 2396 2397 2398 2399
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

2400 2401 2402 2403 2404 2405 2406 2407 2408 2409
	if (port == upstream_port) {
		if (chip->info->ops->set_cpu_port) {
			err = chip->info->ops->set_cpu_port(chip,
							    upstream_port);
			if (err)
				return err;
		}

		if (chip->info->ops->set_egress_port) {
			err = chip->info->ops->set_egress_port(chip,
2410 2411 2412 2413 2414 2415 2416 2417
						MV88E6XXX_EGRESS_DIR_INGRESS,
						upstream_port);
			if (err)
				return err;

			err = chip->info->ops->set_egress_port(chip,
						MV88E6XXX_EGRESS_DIR_EGRESS,
						upstream_port);
2418 2419 2420 2421 2422
			if (err)
				return err;
		}
	}

2423 2424 2425
	return 0;
}

2426
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
2427
{
2428
	struct dsa_switch *ds = chip->ds;
2429
	int err;
2430
	u16 reg;
2431

2432 2433 2434
	chip->ports[port].chip = chip;
	chip->ports[port].port = port;

2435 2436 2437 2438 2439 2440 2441
	/* MAC Forcing register: don't force link, speed, duplex or flow control
	 * state to any particular values on physical ports, but force the CPU
	 * port and all DSA ports to their maximum bandwidth and full duplex.
	 */
	if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
		err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
					       SPEED_MAX, DUPLEX_FULL,
2442
					       PAUSE_OFF,
2443 2444 2445 2446
					       PHY_INTERFACE_MODE_NA);
	else
		err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
					       SPEED_UNFORCED, DUPLEX_UNFORCED,
2447
					       PAUSE_ON,
2448 2449 2450
					       PHY_INTERFACE_MODE_NA);
	if (err)
		return err;
2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465

	/* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
	 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
	 * tunneling, determine priority by looking at 802.1p and IP
	 * priority fields (IP prio has precedence), and set STP state
	 * to Forwarding.
	 *
	 * If this is the CPU link, use DSA or EDSA tagging depending
	 * on which tagging mode was configured.
	 *
	 * If this is a link to another switch, use DSA tagging mode.
	 *
	 * If this is the upstream port for this switch, enable
	 * forwarding of unknown unicasts and multicasts.
	 */
2466 2467 2468 2469
	reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
		MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
		MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
2470 2471
	if (err)
		return err;
2472

2473
	err = mv88e6xxx_setup_port_mode(chip, port);
2474 2475
	if (err)
		return err;
2476

2477
	err = mv88e6xxx_setup_egress_floods(chip, port);
2478 2479 2480
	if (err)
		return err;

2481
	/* Port Control 2: don't force a good FCS, set the maximum frame size to
2482
	 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
2483 2484 2485
	 * untagged frames on this port, do a destination address lookup on all
	 * received packets as usual, disable ARP mirroring and don't send a
	 * copy of all transmitted/received frames on this port to the CPU.
2486
	 */
2487 2488 2489
	err = mv88e6xxx_port_set_map_da(chip, port);
	if (err)
		return err;
2490

2491 2492 2493
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
2494

2495
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
2496
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
2497 2498 2499
	if (err)
		return err;

2500 2501
	if (chip->info->ops->port_set_jumbo_size) {
		err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
2502 2503 2504 2505
		if (err)
			return err;
	}

2506 2507 2508 2509 2510
	/* Port Association Vector: when learning source addresses
	 * of packets, add the address to the address database using
	 * a port bitmap that has only the bit for this port set and
	 * the other bits clear.
	 */
2511
	reg = 1 << port;
2512 2513
	/* Disable learning for CPU port */
	if (dsa_is_cpu_port(ds, port))
2514
		reg = 0;
2515

2516 2517
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
2518 2519
	if (err)
		return err;
2520 2521

	/* Egress rate control 2: disable egress rate control. */
2522 2523
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
				   0x0000);
2524 2525
	if (err)
		return err;
2526

2527 2528
	if (chip->info->ops->port_pause_limit) {
		err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
2529 2530
		if (err)
			return err;
2531
	}
2532

2533 2534 2535 2536 2537 2538
	if (chip->info->ops->port_disable_learn_limit) {
		err = chip->info->ops->port_disable_learn_limit(chip, port);
		if (err)
			return err;
	}

2539 2540
	if (chip->info->ops->port_disable_pri_override) {
		err = chip->info->ops->port_disable_pri_override(chip, port);
2541 2542
		if (err)
			return err;
2543
	}
2544

2545 2546
	if (chip->info->ops->port_tag_remap) {
		err = chip->info->ops->port_tag_remap(chip, port);
2547 2548
		if (err)
			return err;
2549 2550
	}

2551 2552
	if (chip->info->ops->port_egress_rate_limiting) {
		err = chip->info->ops->port_egress_rate_limiting(chip, port);
2553 2554
		if (err)
			return err;
2555 2556
	}

2557 2558 2559 2560 2561
	if (chip->info->ops->port_setup_message_port) {
		err = chip->info->ops->port_setup_message_port(chip, port);
		if (err)
			return err;
	}
2562

2563
	/* Port based VLAN map: give each port the same default address
2564 2565
	 * database, and allow bidirectional communication between the
	 * CPU and DSA port(s), and the other ports.
2566
	 */
2567
	err = mv88e6xxx_port_set_fid(chip, port, 0);
2568 2569
	if (err)
		return err;
2570

2571
	err = mv88e6xxx_port_vlan_map(chip, port);
2572 2573
	if (err)
		return err;
2574 2575 2576 2577

	/* Default VLAN ID and priority: don't set a default VLAN
	 * ID, and set the default packet priority to zero.
	 */
2578
	return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
2579 2580
}

2581 2582 2583 2584
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
2585
	int err;
2586

2587
	mv88e6xxx_reg_lock(chip);
2588
	err = mv88e6xxx_serdes_power(chip, port, true);
2589
	mv88e6xxx_reg_unlock(chip);
2590 2591 2592 2593

	return err;
}

2594
static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port)
2595 2596 2597
{
	struct mv88e6xxx_chip *chip = ds->priv;

2598
	mv88e6xxx_reg_lock(chip);
2599 2600
	if (mv88e6xxx_serdes_power(chip, port, false))
		dev_err(chip->dev, "failed to power off SERDES\n");
2601
	mv88e6xxx_reg_unlock(chip);
2602 2603
}

2604 2605 2606
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
2607
	struct mv88e6xxx_chip *chip = ds->priv;
2608 2609
	int err;

2610
	mv88e6xxx_reg_lock(chip);
2611
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2612
	mv88e6xxx_reg_unlock(chip);
2613 2614 2615 2616

	return err;
}

2617
static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
2618
{
2619
	int err;
2620

2621
	/* Initialize the statistics unit */
2622 2623 2624 2625 2626
	if (chip->info->ops->stats_set_histogram) {
		err = chip->info->ops->stats_set_histogram(chip);
		if (err)
			return err;
	}
2627

2628
	return mv88e6xxx_g1_stats_clear(chip);
2629 2630
}

2631 2632 2633 2634 2635 2636 2637 2638
/* Check if the errata has already been applied. */
static bool mv88e6390_setup_errata_applied(struct mv88e6xxx_chip *chip)
{
	int port;
	int err;
	u16 val;

	for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
2639
		err = mv88e6xxx_port_hidden_read(chip, 0xf, port, 0, &val);
2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671
		if (err) {
			dev_err(chip->dev,
				"Error reading hidden register: %d\n", err);
			return false;
		}
		if (val != 0x01c0)
			return false;
	}

	return true;
}

/* The 6390 copper ports have an errata which require poking magic
 * values into undocumented hidden registers and then performing a
 * software reset.
 */
static int mv88e6390_setup_errata(struct mv88e6xxx_chip *chip)
{
	int port;
	int err;

	if (mv88e6390_setup_errata_applied(chip))
		return 0;

	/* Set the ports into blocking mode */
	for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
		err = mv88e6xxx_port_set_state(chip, port, BR_STATE_DISABLED);
		if (err)
			return err;
	}

	for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
2672
		err = mv88e6xxx_port_hidden_write(chip, 0xf, port, 0, 0x01c0);
2673 2674 2675 2676 2677 2678 2679
		if (err)
			return err;
	}

	return mv88e6xxx_software_reset(chip);
}

2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746
enum mv88e6xxx_devlink_param_id {
	MV88E6XXX_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,
	MV88E6XXX_DEVLINK_PARAM_ID_ATU_HASH,
};

static int mv88e6xxx_devlink_param_get(struct dsa_switch *ds, u32 id,
				       struct devlink_param_gset_ctx *ctx)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

	mv88e6xxx_reg_lock(chip);

	switch (id) {
	case MV88E6XXX_DEVLINK_PARAM_ID_ATU_HASH:
		err = mv88e6xxx_atu_get_hash(chip, &ctx->val.vu8);
		break;
	default:
		err = -EOPNOTSUPP;
		break;
	}

	mv88e6xxx_reg_unlock(chip);

	return err;
}

static int mv88e6xxx_devlink_param_set(struct dsa_switch *ds, u32 id,
				       struct devlink_param_gset_ctx *ctx)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

	mv88e6xxx_reg_lock(chip);

	switch (id) {
	case MV88E6XXX_DEVLINK_PARAM_ID_ATU_HASH:
		err = mv88e6xxx_atu_set_hash(chip, ctx->val.vu8);
		break;
	default:
		err = -EOPNOTSUPP;
		break;
	}

	mv88e6xxx_reg_unlock(chip);

	return err;
}

static const struct devlink_param mv88e6xxx_devlink_params[] = {
	DSA_DEVLINK_PARAM_DRIVER(MV88E6XXX_DEVLINK_PARAM_ID_ATU_HASH,
				 "ATU_hash", DEVLINK_PARAM_TYPE_U8,
				 BIT(DEVLINK_PARAM_CMODE_RUNTIME)),
};

static int mv88e6xxx_setup_devlink_params(struct dsa_switch *ds)
{
	return dsa_devlink_params_register(ds, mv88e6xxx_devlink_params,
					   ARRAY_SIZE(mv88e6xxx_devlink_params));
}

static void mv88e6xxx_teardown_devlink_params(struct dsa_switch *ds)
{
	dsa_devlink_params_unregister(ds, mv88e6xxx_devlink_params,
				      ARRAY_SIZE(mv88e6xxx_devlink_params));
}

2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915
enum mv88e6xxx_devlink_resource_id {
	MV88E6XXX_RESOURCE_ID_ATU,
	MV88E6XXX_RESOURCE_ID_ATU_BIN_0,
	MV88E6XXX_RESOURCE_ID_ATU_BIN_1,
	MV88E6XXX_RESOURCE_ID_ATU_BIN_2,
	MV88E6XXX_RESOURCE_ID_ATU_BIN_3,
};

static u64 mv88e6xxx_devlink_atu_bin_get(struct mv88e6xxx_chip *chip,
					 u16 bin)
{
	u16 occupancy = 0;
	int err;

	mv88e6xxx_reg_lock(chip);

	err = mv88e6xxx_g2_atu_stats_set(chip, MV88E6XXX_G2_ATU_STATS_MODE_ALL,
					 bin);
	if (err) {
		dev_err(chip->dev, "failed to set ATU stats kind/bin\n");
		goto unlock;
	}

	err = mv88e6xxx_g1_atu_get_next(chip, 0);
	if (err) {
		dev_err(chip->dev, "failed to perform ATU get next\n");
		goto unlock;
	}

	err = mv88e6xxx_g2_atu_stats_get(chip, &occupancy);
	if (err) {
		dev_err(chip->dev, "failed to get ATU stats\n");
		goto unlock;
	}

unlock:
	mv88e6xxx_reg_unlock(chip);

	return occupancy;
}

static u64 mv88e6xxx_devlink_atu_bin_0_get(void *priv)
{
	struct mv88e6xxx_chip *chip = priv;

	return mv88e6xxx_devlink_atu_bin_get(chip,
					     MV88E6XXX_G2_ATU_STATS_BIN_0);
}

static u64 mv88e6xxx_devlink_atu_bin_1_get(void *priv)
{
	struct mv88e6xxx_chip *chip = priv;

	return mv88e6xxx_devlink_atu_bin_get(chip,
					     MV88E6XXX_G2_ATU_STATS_BIN_1);
}

static u64 mv88e6xxx_devlink_atu_bin_2_get(void *priv)
{
	struct mv88e6xxx_chip *chip = priv;

	return mv88e6xxx_devlink_atu_bin_get(chip,
					     MV88E6XXX_G2_ATU_STATS_BIN_2);
}

static u64 mv88e6xxx_devlink_atu_bin_3_get(void *priv)
{
	struct mv88e6xxx_chip *chip = priv;

	return mv88e6xxx_devlink_atu_bin_get(chip,
					     MV88E6XXX_G2_ATU_STATS_BIN_3);
}

static u64 mv88e6xxx_devlink_atu_get(void *priv)
{
	return mv88e6xxx_devlink_atu_bin_0_get(priv) +
		mv88e6xxx_devlink_atu_bin_1_get(priv) +
		mv88e6xxx_devlink_atu_bin_2_get(priv) +
		mv88e6xxx_devlink_atu_bin_3_get(priv);
}

static int mv88e6xxx_setup_devlink_resources(struct dsa_switch *ds)
{
	struct devlink_resource_size_params size_params;
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

	devlink_resource_size_params_init(&size_params,
					  mv88e6xxx_num_macs(chip),
					  mv88e6xxx_num_macs(chip),
					  1, DEVLINK_RESOURCE_UNIT_ENTRY);

	err = dsa_devlink_resource_register(ds, "ATU",
					    mv88e6xxx_num_macs(chip),
					    MV88E6XXX_RESOURCE_ID_ATU,
					    DEVLINK_RESOURCE_ID_PARENT_TOP,
					    &size_params);
	if (err)
		goto out;

	devlink_resource_size_params_init(&size_params,
					  mv88e6xxx_num_macs(chip) / 4,
					  mv88e6xxx_num_macs(chip) / 4,
					  1, DEVLINK_RESOURCE_UNIT_ENTRY);

	err = dsa_devlink_resource_register(ds, "ATU_bin_0",
					    mv88e6xxx_num_macs(chip) / 4,
					    MV88E6XXX_RESOURCE_ID_ATU_BIN_0,
					    MV88E6XXX_RESOURCE_ID_ATU,
					    &size_params);
	if (err)
		goto out;

	err = dsa_devlink_resource_register(ds, "ATU_bin_1",
					    mv88e6xxx_num_macs(chip) / 4,
					    MV88E6XXX_RESOURCE_ID_ATU_BIN_1,
					    MV88E6XXX_RESOURCE_ID_ATU,
					    &size_params);
	if (err)
		goto out;

	err = dsa_devlink_resource_register(ds, "ATU_bin_2",
					    mv88e6xxx_num_macs(chip) / 4,
					    MV88E6XXX_RESOURCE_ID_ATU_BIN_2,
					    MV88E6XXX_RESOURCE_ID_ATU,
					    &size_params);
	if (err)
		goto out;

	err = dsa_devlink_resource_register(ds, "ATU_bin_3",
					    mv88e6xxx_num_macs(chip) / 4,
					    MV88E6XXX_RESOURCE_ID_ATU_BIN_3,
					    MV88E6XXX_RESOURCE_ID_ATU,
					    &size_params);
	if (err)
		goto out;

	dsa_devlink_resource_occ_get_register(ds,
					      MV88E6XXX_RESOURCE_ID_ATU,
					      mv88e6xxx_devlink_atu_get,
					      chip);

	dsa_devlink_resource_occ_get_register(ds,
					      MV88E6XXX_RESOURCE_ID_ATU_BIN_0,
					      mv88e6xxx_devlink_atu_bin_0_get,
					      chip);

	dsa_devlink_resource_occ_get_register(ds,
					      MV88E6XXX_RESOURCE_ID_ATU_BIN_1,
					      mv88e6xxx_devlink_atu_bin_1_get,
					      chip);

	dsa_devlink_resource_occ_get_register(ds,
					      MV88E6XXX_RESOURCE_ID_ATU_BIN_2,
					      mv88e6xxx_devlink_atu_bin_2_get,
					      chip);

	dsa_devlink_resource_occ_get_register(ds,
					      MV88E6XXX_RESOURCE_ID_ATU_BIN_3,
					      mv88e6xxx_devlink_atu_bin_3_get,
					      chip);

	return 0;

out:
	dsa_devlink_resources_unregister(ds);
	return err;
}

2916 2917 2918
static void mv88e6xxx_teardown(struct dsa_switch *ds)
{
	mv88e6xxx_teardown_devlink_params(ds);
2919
	dsa_devlink_resources_unregister(ds);
2920 2921
}

2922
static int mv88e6xxx_setup(struct dsa_switch *ds)
2923
{
V
Vivien Didelot 已提交
2924
	struct mv88e6xxx_chip *chip = ds->priv;
2925
	u8 cmode;
2926
	int err;
2927 2928
	int i;

2929
	chip->ds = ds;
2930
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
2931

2932
	mv88e6xxx_reg_lock(chip);
2933

2934 2935 2936 2937 2938 2939
	if (chip->info->ops->setup_errata) {
		err = chip->info->ops->setup_errata(chip);
		if (err)
			goto unlock;
	}

2940 2941 2942 2943 2944
	/* Cache the cmode of each port. */
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
		if (chip->info->ops->port_get_cmode) {
			err = chip->info->ops->port_get_cmode(chip, i, &cmode);
			if (err)
2945
				goto unlock;
2946 2947 2948 2949 2950

			chip->ports[i].cmode = cmode;
		}
	}

2951
	/* Setup Switch Port Registers */
2952
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2953 2954 2955
		if (dsa_is_unused_port(ds, i))
			continue;

2956
		/* Prevent the use of an invalid port. */
2957
		if (mv88e6xxx_is_invalid_port(chip, i)) {
2958 2959 2960 2961 2962
			dev_err(chip->dev, "port %d is invalid\n", i);
			err = -EINVAL;
			goto unlock;
		}

2963 2964 2965 2966 2967
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

2968 2969 2970 2971
	err = mv88e6xxx_irl_setup(chip);
	if (err)
		goto unlock;

2972 2973 2974 2975
	err = mv88e6xxx_mac_setup(chip);
	if (err)
		goto unlock;

2976 2977 2978 2979
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

2980 2981 2982 2983
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

2984 2985 2986 2987
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

2988 2989 2990 2991
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

2992 2993 2994 2995
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

2996 2997 2998 2999
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

3000 3001 3002 3003
	err = mv88e6xxx_rmu_setup(chip);
	if (err)
		goto unlock;

3004 3005 3006
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
3007

3008 3009 3010 3011
	err = mv88e6xxx_trunk_setup(chip);
	if (err)
		goto unlock;

3012 3013 3014 3015
	err = mv88e6xxx_devmap_setup(chip);
	if (err)
		goto unlock;

3016 3017 3018 3019
	err = mv88e6xxx_pri_setup(chip);
	if (err)
		goto unlock;

3020
	/* Setup PTP Hardware Clock and timestamping */
3021 3022 3023 3024
	if (chip->info->ptp_support) {
		err = mv88e6xxx_ptp_setup(chip);
		if (err)
			goto unlock;
3025 3026 3027 3028

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
3029 3030
	}

3031 3032 3033 3034
	err = mv88e6xxx_stats_setup(chip);
	if (err)
		goto unlock;

3035
unlock:
3036
	mv88e6xxx_reg_unlock(chip);
3037

3038 3039 3040 3041 3042 3043 3044
	if (err)
		return err;

	/* Have to be called without holding the register lock, since
	 * they take the devlink lock, and we later take the locks in
	 * the reverse order when getting/setting parameters or
	 * resource occupancy.
3045
	 */
3046 3047 3048 3049 3050 3051 3052 3053 3054
	err = mv88e6xxx_setup_devlink_resources(ds);
	if (err)
		return err;

	err = mv88e6xxx_setup_devlink_params(ds);
	if (err)
		dsa_devlink_resources_unregister(ds);

	return err;
3055 3056
}

3057
static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
3058
{
3059 3060
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
3061 3062
	u16 val;
	int err;
3063

3064 3065 3066
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

3067
	mv88e6xxx_reg_lock(chip);
3068
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
3069
	mv88e6xxx_reg_unlock(chip);
3070

3071
	if (reg == MII_PHYSID2) {
3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087
		/* Some internal PHYs don't have a model number. */
		if (chip->info->family != MV88E6XXX_FAMILY_6165)
			/* Then there is the 6165 family. It gets is
			 * PHYs correct. But it can also have two
			 * SERDES interfaces in the PHY address
			 * space. And these don't have a model
			 * number. But they are not PHYs, so we don't
			 * want to give them something a PHY driver
			 * will recognise.
			 *
			 * Use the mv88e6390 family model number
			 * instead, for anything which really could be
			 * a PHY,
			 */
			if (!(val & 0x3f0))
				val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
3088 3089
	}

3090
	return err ? err : val;
3091 3092
}

3093
static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
3094
{
3095 3096
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
3097
	int err;
3098

3099 3100 3101
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

3102
	mv88e6xxx_reg_lock(chip);
3103
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
3104
	mv88e6xxx_reg_unlock(chip);
3105 3106

	return err;
3107 3108
}

3109
static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
3110 3111
				   struct device_node *np,
				   bool external)
3112 3113
{
	static int index;
3114
	struct mv88e6xxx_mdio_bus *mdio_bus;
3115 3116 3117
	struct mii_bus *bus;
	int err;

3118
	if (external) {
3119
		mv88e6xxx_reg_lock(chip);
3120
		err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
3121
		mv88e6xxx_reg_unlock(chip);
3122 3123 3124 3125 3126

		if (err)
			return err;
	}

3127
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
3128 3129 3130
	if (!bus)
		return -ENOMEM;

3131
	mdio_bus = bus->priv;
3132
	mdio_bus->bus = bus;
3133
	mdio_bus->chip = chip;
3134 3135
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
3136

3137 3138
	if (np) {
		bus->name = np->full_name;
3139
		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
3140 3141 3142 3143 3144 3145 3146
	} else {
		bus->name = "mv88e6xxx SMI";
		snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
	}

	bus->read = mv88e6xxx_mdio_read;
	bus->write = mv88e6xxx_mdio_write;
3147
	bus->parent = chip->dev;
3148

3149 3150 3151 3152 3153 3154
	if (!external) {
		err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
		if (err)
			return err;
	}

3155
	err = of_mdiobus_register(bus, np);
3156
	if (err) {
3157
		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
3158
		mv88e6xxx_g2_irq_mdio_free(chip, bus);
3159
		return err;
3160
	}
3161 3162 3163 3164 3165

	if (external)
		list_add_tail(&mdio_bus->list, &chip->mdios);
	else
		list_add(&mdio_bus->list, &chip->mdios);
3166 3167

	return 0;
3168
}
3169

3170 3171 3172 3173 3174
static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
	{ .compatible = "marvell,mv88e6xxx-mdio-external",
	  .data = (void *)true },
	{ },
};
3175

3176 3177 3178 3179 3180 3181 3182 3183 3184
static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)

{
	struct mv88e6xxx_mdio_bus *mdio_bus;
	struct mii_bus *bus;

	list_for_each_entry(mdio_bus, &chip->mdios, list) {
		bus = mdio_bus->bus;

3185 3186 3187
		if (!mdio_bus->external)
			mv88e6xxx_g2_irq_mdio_free(chip, bus);

3188 3189 3190 3191
		mdiobus_unregister(bus);
	}
}

3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215
static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
				    struct device_node *np)
{
	const struct of_device_id *match;
	struct device_node *child;
	int err;

	/* Always register one mdio bus for the internal/default mdio
	 * bus. This maybe represented in the device tree, but is
	 * optional.
	 */
	child = of_get_child_by_name(np, "mdio");
	err = mv88e6xxx_mdio_register(chip, child, false);
	if (err)
		return err;

	/* Walk the device tree, and see if there are any other nodes
	 * which say they are compatible with the external mdio
	 * bus.
	 */
	for_each_available_child_of_node(np, child) {
		match = of_match_node(mv88e6xxx_mdio_external_match, child);
		if (match) {
			err = mv88e6xxx_mdio_register(chip, child, true);
3216 3217
			if (err) {
				mv88e6xxx_mdios_unregister(chip);
3218
				of_node_put(child);
3219
				return err;
3220
			}
3221 3222 3223 3224
		}
	}

	return 0;
3225 3226
}

3227 3228
static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
3229
	struct mv88e6xxx_chip *chip = ds->priv;
3230 3231 3232 3233 3234 3235 3236

	return chip->eeprom_len;
}

static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
				struct ethtool_eeprom *eeprom, u8 *data)
{
V
Vivien Didelot 已提交
3237
	struct mv88e6xxx_chip *chip = ds->priv;
3238 3239
	int err;

3240 3241
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
3242

3243
	mv88e6xxx_reg_lock(chip);
3244
	err = chip->info->ops->get_eeprom(chip, eeprom, data);
3245
	mv88e6xxx_reg_unlock(chip);
3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257

	if (err)
		return err;

	eeprom->magic = 0xc3ec4951;

	return 0;
}

static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
				struct ethtool_eeprom *eeprom, u8 *data)
{
V
Vivien Didelot 已提交
3258
	struct mv88e6xxx_chip *chip = ds->priv;
3259 3260
	int err;

3261 3262 3263
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

3264 3265 3266
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

3267
	mv88e6xxx_reg_lock(chip);
3268
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
3269
	mv88e6xxx_reg_unlock(chip);
3270 3271 3272 3273

	return err;
}

3274
static const struct mv88e6xxx_ops mv88e6085_ops = {
3275
	/* MV88E6XXX_FAMILY_6097 */
3276 3277
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3278
	.irl_init_all = mv88e6352_g2_irl_init_all,
3279
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3280 3281
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3282
	.port_set_link = mv88e6xxx_port_set_link,
3283
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3284
	.port_set_speed = mv88e6185_port_set_speed,
3285
	.port_tag_remap = mv88e6095_port_tag_remap,
3286
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3287
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3288
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3289
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3290
	.port_pause_limit = mv88e6097_port_pause_limit,
3291
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3292
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3293
	.port_link_state = mv88e6352_port_link_state,
3294
	.port_get_cmode = mv88e6185_port_get_cmode,
3295
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3296
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3297
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3298 3299
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3300
	.stats_get_stats = mv88e6095_stats_get_stats,
3301 3302
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3303
	.watchdog_ops = &mv88e6097_watchdog_ops,
3304
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3305
	.pot_clear = mv88e6xxx_g2_pot_clear,
3306 3307
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
3308
	.reset = mv88e6185_g1_reset,
3309
	.rmu_disable = mv88e6085_g1_rmu_disable,
3310
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3311
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3312
	.phylink_validate = mv88e6185_phylink_validate,
3313 3314 3315
};

static const struct mv88e6xxx_ops mv88e6095_ops = {
3316
	/* MV88E6XXX_FAMILY_6095 */
3317 3318
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3319
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3320 3321
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3322
	.port_set_link = mv88e6xxx_port_set_link,
3323
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3324
	.port_set_speed = mv88e6185_port_set_speed,
3325
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
3326
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
3327
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
3328
	.port_link_state = mv88e6185_port_link_state,
3329
	.port_get_cmode = mv88e6185_port_get_cmode,
3330
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3331
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3332
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3333 3334
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3335
	.stats_get_stats = mv88e6095_stats_get_stats,
3336
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3337 3338
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
3339
	.reset = mv88e6185_g1_reset,
3340
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3341
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3342
	.phylink_validate = mv88e6185_phylink_validate,
3343 3344
};

3345
static const struct mv88e6xxx_ops mv88e6097_ops = {
3346
	/* MV88E6XXX_FAMILY_6097 */
3347 3348
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3349
	.irl_init_all = mv88e6352_g2_irl_init_all,
3350 3351 3352 3353 3354 3355
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_speed = mv88e6185_port_set_speed,
3356
	.port_tag_remap = mv88e6095_port_tag_remap,
3357
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3358
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3359
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3360
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3361
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
3362
	.port_pause_limit = mv88e6097_port_pause_limit,
3363
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3364
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3365
	.port_link_state = mv88e6352_port_link_state,
3366
	.port_get_cmode = mv88e6185_port_get_cmode,
3367
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3368
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3369
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3370 3371 3372
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
	.stats_get_stats = mv88e6095_stats_get_stats,
3373 3374
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3375
	.watchdog_ops = &mv88e6097_watchdog_ops,
3376
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3377
	.pot_clear = mv88e6xxx_g2_pot_clear,
3378
	.reset = mv88e6352_g1_reset,
3379
	.rmu_disable = mv88e6085_g1_rmu_disable,
3380
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3381
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3382
	.phylink_validate = mv88e6185_phylink_validate,
3383 3384
};

3385
static const struct mv88e6xxx_ops mv88e6123_ops = {
3386
	/* MV88E6XXX_FAMILY_6165 */
3387 3388
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3389
	.irl_init_all = mv88e6352_g2_irl_init_all,
3390
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3391 3392
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3393
	.port_set_link = mv88e6xxx_port_set_link,
3394
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3395
	.port_set_speed = mv88e6185_port_set_speed,
3396
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
3397
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3398
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3399
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3400
	.port_link_state = mv88e6352_port_link_state,
3401
	.port_get_cmode = mv88e6185_port_get_cmode,
3402
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3403
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3404
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3405 3406
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3407
	.stats_get_stats = mv88e6095_stats_get_stats,
3408 3409
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3410
	.watchdog_ops = &mv88e6097_watchdog_ops,
3411
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3412
	.pot_clear = mv88e6xxx_g2_pot_clear,
3413
	.reset = mv88e6352_g1_reset,
3414 3415
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3416
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3417
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3418
	.phylink_validate = mv88e6185_phylink_validate,
3419 3420 3421
};

static const struct mv88e6xxx_ops mv88e6131_ops = {
3422
	/* MV88E6XXX_FAMILY_6185 */
3423 3424
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3425
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3426 3427
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3428
	.port_set_link = mv88e6xxx_port_set_link,
3429
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3430
	.port_set_speed = mv88e6185_port_set_speed,
3431
	.port_tag_remap = mv88e6095_port_tag_remap,
3432
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3433
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
3434
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3435
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
3436
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3437
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3438
	.port_pause_limit = mv88e6097_port_pause_limit,
3439
	.port_set_pause = mv88e6185_port_set_pause,
3440
	.port_link_state = mv88e6352_port_link_state,
3441
	.port_get_cmode = mv88e6185_port_get_cmode,
3442
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3443
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3444
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3445 3446
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3447
	.stats_get_stats = mv88e6095_stats_get_stats,
3448 3449
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3450
	.watchdog_ops = &mv88e6097_watchdog_ops,
3451
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3452
	.ppu_enable = mv88e6185_g1_ppu_enable,
3453
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
3454
	.ppu_disable = mv88e6185_g1_ppu_disable,
3455
	.reset = mv88e6185_g1_reset,
3456
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3457
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3458
	.phylink_validate = mv88e6185_phylink_validate,
3459 3460
};

3461 3462
static const struct mv88e6xxx_ops mv88e6141_ops = {
	/* MV88E6XXX_FAMILY_6341 */
3463 3464
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3465
	.irl_init_all = mv88e6352_g2_irl_init_all,
3466 3467 3468 3469 3470 3471 3472 3473
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3474
	.port_set_speed = mv88e6341_port_set_speed,
3475
	.port_max_speed_mode = mv88e6341_port_max_speed_mode,
3476 3477 3478 3479
	.port_tag_remap = mv88e6095_port_tag_remap,
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3480
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3481
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3482
	.port_pause_limit = mv88e6097_port_pause_limit,
3483 3484
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3485
	.port_link_state = mv88e6352_port_link_state,
3486
	.port_get_cmode = mv88e6352_port_get_cmode,
3487
	.port_set_cmode = mv88e6341_port_set_cmode,
3488
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3489
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3490
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3491 3492 3493
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
3494 3495
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3496 3497
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
3498
	.pot_clear = mv88e6xxx_g2_pot_clear,
3499
	.reset = mv88e6352_g1_reset,
3500
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3501
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3502 3503
	.serdes_power = mv88e6390_serdes_power,
	.serdes_get_lane = mv88e6341_serdes_get_lane,
3504
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3505
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
3506
	.serdes_irq_status = mv88e6390_serdes_irq_status,
3507
	.gpio_ops = &mv88e6352_gpio_ops,
3508
	.phylink_validate = mv88e6341_phylink_validate,
3509 3510
};

3511
static const struct mv88e6xxx_ops mv88e6161_ops = {
3512
	/* MV88E6XXX_FAMILY_6165 */
3513 3514
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3515
	.irl_init_all = mv88e6352_g2_irl_init_all,
3516
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3517 3518
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3519
	.port_set_link = mv88e6xxx_port_set_link,
3520
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3521
	.port_set_speed = mv88e6185_port_set_speed,
3522
	.port_tag_remap = mv88e6095_port_tag_remap,
3523
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3524
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3525
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3526
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3527
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3528
	.port_pause_limit = mv88e6097_port_pause_limit,
3529
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3530
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3531
	.port_link_state = mv88e6352_port_link_state,
3532
	.port_get_cmode = mv88e6185_port_get_cmode,
3533
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3534
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3535
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3536 3537
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3538
	.stats_get_stats = mv88e6095_stats_get_stats,
3539 3540
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3541
	.watchdog_ops = &mv88e6097_watchdog_ops,
3542
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3543
	.pot_clear = mv88e6xxx_g2_pot_clear,
3544
	.reset = mv88e6352_g1_reset,
3545 3546
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3547
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3548
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3549
	.avb_ops = &mv88e6165_avb_ops,
3550
	.ptp_ops = &mv88e6165_ptp_ops,
3551
	.phylink_validate = mv88e6185_phylink_validate,
3552 3553 3554
};

static const struct mv88e6xxx_ops mv88e6165_ops = {
3555
	/* MV88E6XXX_FAMILY_6165 */
3556 3557
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3558
	.irl_init_all = mv88e6352_g2_irl_init_all,
3559
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3560 3561
	.phy_read = mv88e6165_phy_read,
	.phy_write = mv88e6165_phy_write,
3562
	.port_set_link = mv88e6xxx_port_set_link,
3563
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3564
	.port_set_speed = mv88e6185_port_set_speed,
3565
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3566
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3567
	.port_link_state = mv88e6352_port_link_state,
3568
	.port_get_cmode = mv88e6185_port_get_cmode,
3569
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3570
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3571
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3572 3573
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3574
	.stats_get_stats = mv88e6095_stats_get_stats,
3575 3576
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3577
	.watchdog_ops = &mv88e6097_watchdog_ops,
3578
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3579
	.pot_clear = mv88e6xxx_g2_pot_clear,
3580
	.reset = mv88e6352_g1_reset,
3581 3582
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3583
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3584
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3585
	.avb_ops = &mv88e6165_avb_ops,
3586
	.ptp_ops = &mv88e6165_ptp_ops,
3587
	.phylink_validate = mv88e6185_phylink_validate,
3588 3589 3590
};

static const struct mv88e6xxx_ops mv88e6171_ops = {
3591
	/* MV88E6XXX_FAMILY_6351 */
3592 3593
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3594
	.irl_init_all = mv88e6352_g2_irl_init_all,
3595
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3596 3597
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3598
	.port_set_link = mv88e6xxx_port_set_link,
3599
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3600
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3601
	.port_set_speed = mv88e6185_port_set_speed,
3602
	.port_tag_remap = mv88e6095_port_tag_remap,
3603
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3604
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3605
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3606
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3607
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3608
	.port_pause_limit = mv88e6097_port_pause_limit,
3609
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3610
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3611
	.port_link_state = mv88e6352_port_link_state,
3612
	.port_get_cmode = mv88e6352_port_get_cmode,
3613
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3614
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3615
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3616 3617
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3618
	.stats_get_stats = mv88e6095_stats_get_stats,
3619 3620
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3621
	.watchdog_ops = &mv88e6097_watchdog_ops,
3622
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3623
	.pot_clear = mv88e6xxx_g2_pot_clear,
3624
	.reset = mv88e6352_g1_reset,
3625 3626
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3627
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3628
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3629
	.phylink_validate = mv88e6185_phylink_validate,
3630 3631 3632
};

static const struct mv88e6xxx_ops mv88e6172_ops = {
3633
	/* MV88E6XXX_FAMILY_6352 */
3634 3635
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3636
	.irl_init_all = mv88e6352_g2_irl_init_all,
3637 3638
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3639
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3640 3641
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3642
	.port_set_link = mv88e6xxx_port_set_link,
3643
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3644
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3645
	.port_set_speed = mv88e6352_port_set_speed,
3646
	.port_tag_remap = mv88e6095_port_tag_remap,
3647
	.port_set_policy = mv88e6352_port_set_policy,
3648
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3649
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3650
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3651
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3652
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3653
	.port_pause_limit = mv88e6097_port_pause_limit,
3654
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3655
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3656
	.port_link_state = mv88e6352_port_link_state,
3657
	.port_get_cmode = mv88e6352_port_get_cmode,
3658
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3659
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3660
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3661 3662
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3663
	.stats_get_stats = mv88e6095_stats_get_stats,
3664 3665
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3666
	.watchdog_ops = &mv88e6097_watchdog_ops,
3667
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3668
	.pot_clear = mv88e6xxx_g2_pot_clear,
3669
	.reset = mv88e6352_g1_reset,
3670
	.rmu_disable = mv88e6352_g1_rmu_disable,
3671 3672
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3673
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3674
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3675
	.serdes_get_lane = mv88e6352_serdes_get_lane,
3676
	.serdes_power = mv88e6352_serdes_power,
3677 3678
	.serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
	.serdes_get_regs = mv88e6352_serdes_get_regs,
3679
	.gpio_ops = &mv88e6352_gpio_ops,
3680
	.phylink_validate = mv88e6352_phylink_validate,
3681 3682 3683
};

static const struct mv88e6xxx_ops mv88e6175_ops = {
3684
	/* MV88E6XXX_FAMILY_6351 */
3685 3686
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3687
	.irl_init_all = mv88e6352_g2_irl_init_all,
3688
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3689 3690
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3691
	.port_set_link = mv88e6xxx_port_set_link,
3692
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3693
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3694
	.port_set_speed = mv88e6185_port_set_speed,
3695
	.port_tag_remap = mv88e6095_port_tag_remap,
3696
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3697
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3698
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3699
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3700
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3701
	.port_pause_limit = mv88e6097_port_pause_limit,
3702
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3703
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3704
	.port_link_state = mv88e6352_port_link_state,
3705
	.port_get_cmode = mv88e6352_port_get_cmode,
3706
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3707
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3708
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3709 3710
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3711
	.stats_get_stats = mv88e6095_stats_get_stats,
3712 3713
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3714
	.watchdog_ops = &mv88e6097_watchdog_ops,
3715
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3716
	.pot_clear = mv88e6xxx_g2_pot_clear,
3717
	.reset = mv88e6352_g1_reset,
3718 3719
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3720
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3721
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3722
	.phylink_validate = mv88e6185_phylink_validate,
3723 3724 3725
};

static const struct mv88e6xxx_ops mv88e6176_ops = {
3726
	/* MV88E6XXX_FAMILY_6352 */
3727 3728
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3729
	.irl_init_all = mv88e6352_g2_irl_init_all,
3730 3731
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3732
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3733 3734
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3735
	.port_set_link = mv88e6xxx_port_set_link,
3736
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3737
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3738
	.port_set_speed = mv88e6352_port_set_speed,
3739
	.port_tag_remap = mv88e6095_port_tag_remap,
3740
	.port_set_policy = mv88e6352_port_set_policy,
3741
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3742
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3743
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3744
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3745
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3746
	.port_pause_limit = mv88e6097_port_pause_limit,
3747
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3748
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3749
	.port_link_state = mv88e6352_port_link_state,
3750
	.port_get_cmode = mv88e6352_port_get_cmode,
3751
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3752
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3753
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3754 3755
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3756
	.stats_get_stats = mv88e6095_stats_get_stats,
3757 3758
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3759
	.watchdog_ops = &mv88e6097_watchdog_ops,
3760
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3761
	.pot_clear = mv88e6xxx_g2_pot_clear,
3762
	.reset = mv88e6352_g1_reset,
3763
	.rmu_disable = mv88e6352_g1_rmu_disable,
3764 3765
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3766
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3767
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3768
	.serdes_get_lane = mv88e6352_serdes_get_lane,
3769
	.serdes_power = mv88e6352_serdes_power,
3770
	.serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
3771
	.serdes_irq_enable = mv88e6352_serdes_irq_enable,
3772
	.serdes_irq_status = mv88e6352_serdes_irq_status,
3773 3774
	.serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
	.serdes_get_regs = mv88e6352_serdes_get_regs,
3775
	.gpio_ops = &mv88e6352_gpio_ops,
3776
	.phylink_validate = mv88e6352_phylink_validate,
3777 3778 3779
};

static const struct mv88e6xxx_ops mv88e6185_ops = {
3780
	/* MV88E6XXX_FAMILY_6185 */
3781 3782
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3783
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3784 3785
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3786
	.port_set_link = mv88e6xxx_port_set_link,
3787
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3788
	.port_set_speed = mv88e6185_port_set_speed,
3789
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
3790
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
3791
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
3792
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
3793
	.port_set_pause = mv88e6185_port_set_pause,
3794
	.port_link_state = mv88e6185_port_link_state,
3795
	.port_get_cmode = mv88e6185_port_get_cmode,
3796
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3797
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3798
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3799 3800
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3801
	.stats_get_stats = mv88e6095_stats_get_stats,
3802 3803
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3804
	.watchdog_ops = &mv88e6097_watchdog_ops,
3805
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3806
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
3807 3808
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
3809
	.reset = mv88e6185_g1_reset,
3810
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3811
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3812
	.phylink_validate = mv88e6185_phylink_validate,
3813 3814
};

3815
static const struct mv88e6xxx_ops mv88e6190_ops = {
3816
	/* MV88E6XXX_FAMILY_6390 */
3817
	.setup_errata = mv88e6390_setup_errata,
3818
	.irl_init_all = mv88e6390_g2_irl_init_all,
3819 3820
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3821 3822 3823 3824 3825 3826 3827
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
	.port_set_speed = mv88e6390_port_set_speed,
3828
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
3829
	.port_tag_remap = mv88e6390_port_tag_remap,
3830
	.port_set_policy = mv88e6352_port_set_policy,
3831
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3832
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3833
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3834
	.port_pause_limit = mv88e6390_port_pause_limit,
3835
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3836
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3837
	.port_link_state = mv88e6352_port_link_state,
3838
	.port_get_cmode = mv88e6352_port_get_cmode,
3839
	.port_set_cmode = mv88e6390_port_set_cmode,
3840
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3841
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3842
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3843 3844
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3845
	.stats_get_stats = mv88e6390_stats_get_stats,
3846 3847
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3848
	.watchdog_ops = &mv88e6390_watchdog_ops,
3849
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3850
	.pot_clear = mv88e6xxx_g2_pot_clear,
3851
	.reset = mv88e6352_g1_reset,
3852
	.rmu_disable = mv88e6390_g1_rmu_disable,
3853 3854
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3855 3856
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3857
	.serdes_power = mv88e6390_serdes_power,
3858
	.serdes_get_lane = mv88e6390_serdes_get_lane,
3859
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3860
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
3861
	.serdes_irq_status = mv88e6390_serdes_irq_status,
3862 3863
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
3864 3865
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
3866
	.phylink_validate = mv88e6390_phylink_validate,
3867
	.gpio_ops = &mv88e6352_gpio_ops,
3868
	.phylink_validate = mv88e6390_phylink_validate,
3869 3870 3871
};

static const struct mv88e6xxx_ops mv88e6190x_ops = {
3872
	/* MV88E6XXX_FAMILY_6390 */
3873
	.setup_errata = mv88e6390_setup_errata,
3874
	.irl_init_all = mv88e6390_g2_irl_init_all,
3875 3876
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3877 3878 3879 3880 3881 3882 3883
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
	.port_set_speed = mv88e6390x_port_set_speed,
3884
	.port_max_speed_mode = mv88e6390x_port_max_speed_mode,
3885
	.port_tag_remap = mv88e6390_port_tag_remap,
3886
	.port_set_policy = mv88e6352_port_set_policy,
3887
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3888
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3889
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3890
	.port_pause_limit = mv88e6390_port_pause_limit,
3891
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3892
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3893
	.port_link_state = mv88e6352_port_link_state,
3894
	.port_get_cmode = mv88e6352_port_get_cmode,
3895
	.port_set_cmode = mv88e6390x_port_set_cmode,
3896
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3897
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3898
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3899 3900
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3901
	.stats_get_stats = mv88e6390_stats_get_stats,
3902 3903
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3904
	.watchdog_ops = &mv88e6390_watchdog_ops,
3905
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3906
	.pot_clear = mv88e6xxx_g2_pot_clear,
3907
	.reset = mv88e6352_g1_reset,
3908
	.rmu_disable = mv88e6390_g1_rmu_disable,
3909 3910
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3911 3912
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3913
	.serdes_power = mv88e6390_serdes_power,
3914
	.serdes_get_lane = mv88e6390x_serdes_get_lane,
3915
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3916
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
3917
	.serdes_irq_status = mv88e6390_serdes_irq_status,
3918 3919
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
3920 3921
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
3922
	.phylink_validate = mv88e6390_phylink_validate,
3923
	.gpio_ops = &mv88e6352_gpio_ops,
3924
	.phylink_validate = mv88e6390x_phylink_validate,
3925 3926 3927
};

static const struct mv88e6xxx_ops mv88e6191_ops = {
3928
	/* MV88E6XXX_FAMILY_6390 */
3929
	.setup_errata = mv88e6390_setup_errata,
3930
	.irl_init_all = mv88e6390_g2_irl_init_all,
3931 3932
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3933 3934 3935 3936 3937 3938 3939
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
	.port_set_speed = mv88e6390_port_set_speed,
3940
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
3941
	.port_tag_remap = mv88e6390_port_tag_remap,
3942
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3943
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3944
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3945
	.port_pause_limit = mv88e6390_port_pause_limit,
3946
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3947
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3948
	.port_link_state = mv88e6352_port_link_state,
3949
	.port_get_cmode = mv88e6352_port_get_cmode,
3950
	.port_set_cmode = mv88e6390_port_set_cmode,
3951
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3952
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3953
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3954 3955
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3956
	.stats_get_stats = mv88e6390_stats_get_stats,
3957 3958
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3959
	.watchdog_ops = &mv88e6390_watchdog_ops,
3960
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3961
	.pot_clear = mv88e6xxx_g2_pot_clear,
3962
	.reset = mv88e6352_g1_reset,
3963
	.rmu_disable = mv88e6390_g1_rmu_disable,
3964 3965
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3966 3967
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3968
	.serdes_power = mv88e6390_serdes_power,
3969
	.serdes_get_lane = mv88e6390_serdes_get_lane,
3970
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3971
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
3972
	.serdes_irq_status = mv88e6390_serdes_irq_status,
3973 3974
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
3975 3976
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
3977
	.phylink_validate = mv88e6390_phylink_validate,
3978 3979
	.avb_ops = &mv88e6390_avb_ops,
	.ptp_ops = &mv88e6352_ptp_ops,
3980
	.phylink_validate = mv88e6390_phylink_validate,
3981 3982
};

3983
static const struct mv88e6xxx_ops mv88e6240_ops = {
3984
	/* MV88E6XXX_FAMILY_6352 */
3985 3986
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3987
	.irl_init_all = mv88e6352_g2_irl_init_all,
3988 3989
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3990
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3991 3992
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3993
	.port_set_link = mv88e6xxx_port_set_link,
3994
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3995
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3996
	.port_set_speed = mv88e6352_port_set_speed,
3997
	.port_tag_remap = mv88e6095_port_tag_remap,
3998
	.port_set_policy = mv88e6352_port_set_policy,
3999
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4000
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4001
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4002
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4003
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4004
	.port_pause_limit = mv88e6097_port_pause_limit,
4005
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4006
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4007
	.port_link_state = mv88e6352_port_link_state,
4008
	.port_get_cmode = mv88e6352_port_get_cmode,
4009
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4010
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4011
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4012 4013
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
4014
	.stats_get_stats = mv88e6095_stats_get_stats,
4015 4016
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4017
	.watchdog_ops = &mv88e6097_watchdog_ops,
4018
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4019
	.pot_clear = mv88e6xxx_g2_pot_clear,
4020
	.reset = mv88e6352_g1_reset,
4021
	.rmu_disable = mv88e6352_g1_rmu_disable,
4022 4023
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4024
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4025
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4026
	.serdes_get_lane = mv88e6352_serdes_get_lane,
4027
	.serdes_power = mv88e6352_serdes_power,
4028
	.serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
4029
	.serdes_irq_enable = mv88e6352_serdes_irq_enable,
4030
	.serdes_irq_status = mv88e6352_serdes_irq_status,
4031 4032
	.serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
	.serdes_get_regs = mv88e6352_serdes_get_regs,
4033
	.gpio_ops = &mv88e6352_gpio_ops,
4034
	.avb_ops = &mv88e6352_avb_ops,
4035
	.ptp_ops = &mv88e6352_ptp_ops,
4036
	.phylink_validate = mv88e6352_phylink_validate,
4037 4038
};

4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073
static const struct mv88e6xxx_ops mv88e6250_ops = {
	/* MV88E6XXX_FAMILY_6250 */
	.ieee_pri_map = mv88e6250_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
	.irl_init_all = mv88e6352_g2_irl_init_all,
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
	.port_set_speed = mv88e6250_port_set_speed,
	.port_tag_remap = mv88e6095_port_tag_remap,
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
	.port_set_ether_type = mv88e6351_port_set_ether_type,
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
	.port_pause_limit = mv88e6097_port_pause_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
	.port_link_state = mv88e6250_port_link_state,
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
	.stats_get_sset_count = mv88e6250_stats_get_sset_count,
	.stats_get_strings = mv88e6250_stats_get_strings,
	.stats_get_stats = mv88e6250_stats_get_stats,
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
	.watchdog_ops = &mv88e6250_watchdog_ops,
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
	.pot_clear = mv88e6xxx_g2_pot_clear,
	.reset = mv88e6250_g1_reset,
	.vtu_getnext = mv88e6250_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6250_g1_vtu_loadpurge,
4074 4075
	.avb_ops = &mv88e6352_avb_ops,
	.ptp_ops = &mv88e6250_ptp_ops,
4076 4077 4078
	.phylink_validate = mv88e6065_phylink_validate,
};

4079
static const struct mv88e6xxx_ops mv88e6290_ops = {
4080
	/* MV88E6XXX_FAMILY_6390 */
4081
	.setup_errata = mv88e6390_setup_errata,
4082
	.irl_init_all = mv88e6390_g2_irl_init_all,
4083 4084
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4085 4086 4087 4088 4089 4090 4091
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
	.port_set_speed = mv88e6390_port_set_speed,
4092
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
4093
	.port_tag_remap = mv88e6390_port_tag_remap,
4094
	.port_set_policy = mv88e6352_port_set_policy,
4095
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4096
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4097
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4098
	.port_pause_limit = mv88e6390_port_pause_limit,
4099
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4100
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4101
	.port_link_state = mv88e6352_port_link_state,
4102
	.port_get_cmode = mv88e6352_port_get_cmode,
4103
	.port_set_cmode = mv88e6390_port_set_cmode,
4104
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4105
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4106
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4107 4108
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4109
	.stats_get_stats = mv88e6390_stats_get_stats,
4110 4111
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4112
	.watchdog_ops = &mv88e6390_watchdog_ops,
4113
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4114
	.pot_clear = mv88e6xxx_g2_pot_clear,
4115
	.reset = mv88e6352_g1_reset,
4116
	.rmu_disable = mv88e6390_g1_rmu_disable,
4117 4118
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4119 4120
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4121
	.serdes_power = mv88e6390_serdes_power,
4122
	.serdes_get_lane = mv88e6390_serdes_get_lane,
4123
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4124
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4125
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4126 4127
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
4128 4129
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
4130
	.phylink_validate = mv88e6390_phylink_validate,
4131
	.gpio_ops = &mv88e6352_gpio_ops,
4132
	.avb_ops = &mv88e6390_avb_ops,
4133
	.ptp_ops = &mv88e6352_ptp_ops,
4134
	.phylink_validate = mv88e6390_phylink_validate,
4135 4136
};

4137
static const struct mv88e6xxx_ops mv88e6320_ops = {
4138
	/* MV88E6XXX_FAMILY_6320 */
4139 4140
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4141
	.irl_init_all = mv88e6352_g2_irl_init_all,
4142 4143
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
4144
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4145 4146
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4147
	.port_set_link = mv88e6xxx_port_set_link,
4148
	.port_set_duplex = mv88e6xxx_port_set_duplex,
4149
	.port_set_speed = mv88e6185_port_set_speed,
4150
	.port_tag_remap = mv88e6095_port_tag_remap,
4151
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4152
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4153
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4154
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4155
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4156
	.port_pause_limit = mv88e6097_port_pause_limit,
4157
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4158
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4159
	.port_link_state = mv88e6352_port_link_state,
4160
	.port_get_cmode = mv88e6352_port_get_cmode,
4161
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4162
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4163
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4164 4165
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4166
	.stats_get_stats = mv88e6320_stats_get_stats,
4167 4168
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4169
	.watchdog_ops = &mv88e6390_watchdog_ops,
4170
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4171
	.pot_clear = mv88e6xxx_g2_pot_clear,
4172
	.reset = mv88e6352_g1_reset,
4173
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
4174
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
4175
	.gpio_ops = &mv88e6352_gpio_ops,
4176
	.avb_ops = &mv88e6352_avb_ops,
4177
	.ptp_ops = &mv88e6352_ptp_ops,
4178
	.phylink_validate = mv88e6185_phylink_validate,
4179 4180 4181
};

static const struct mv88e6xxx_ops mv88e6321_ops = {
4182
	/* MV88E6XXX_FAMILY_6320 */
4183 4184
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4185
	.irl_init_all = mv88e6352_g2_irl_init_all,
4186 4187
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
4188
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4189 4190
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4191
	.port_set_link = mv88e6xxx_port_set_link,
4192
	.port_set_duplex = mv88e6xxx_port_set_duplex,
4193
	.port_set_speed = mv88e6185_port_set_speed,
4194
	.port_tag_remap = mv88e6095_port_tag_remap,
4195
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4196
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4197
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4198
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4199
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4200
	.port_pause_limit = mv88e6097_port_pause_limit,
4201
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4202
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4203
	.port_link_state = mv88e6352_port_link_state,
4204
	.port_get_cmode = mv88e6352_port_get_cmode,
4205
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4206
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4207
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4208 4209
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4210
	.stats_get_stats = mv88e6320_stats_get_stats,
4211 4212
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4213
	.watchdog_ops = &mv88e6390_watchdog_ops,
4214
	.reset = mv88e6352_g1_reset,
4215
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
4216
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
4217
	.gpio_ops = &mv88e6352_gpio_ops,
4218
	.avb_ops = &mv88e6352_avb_ops,
4219
	.ptp_ops = &mv88e6352_ptp_ops,
4220
	.phylink_validate = mv88e6185_phylink_validate,
4221 4222
};

4223 4224
static const struct mv88e6xxx_ops mv88e6341_ops = {
	/* MV88E6XXX_FAMILY_6341 */
4225 4226
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4227
	.irl_init_all = mv88e6352_g2_irl_init_all,
4228 4229 4230 4231 4232 4233 4234 4235
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4236
	.port_set_speed = mv88e6341_port_set_speed,
4237
	.port_max_speed_mode = mv88e6341_port_max_speed_mode,
4238 4239 4240 4241
	.port_tag_remap = mv88e6095_port_tag_remap,
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4242
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4243
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4244
	.port_pause_limit = mv88e6097_port_pause_limit,
4245 4246
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4247
	.port_link_state = mv88e6352_port_link_state,
4248
	.port_get_cmode = mv88e6352_port_get_cmode,
4249
	.port_set_cmode = mv88e6341_port_set_cmode,
4250
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4251
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4252
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4253 4254 4255
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
4256 4257
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4258 4259
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
4260
	.pot_clear = mv88e6xxx_g2_pot_clear,
4261
	.reset = mv88e6352_g1_reset,
4262
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4263
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4264 4265
	.serdes_power = mv88e6390_serdes_power,
	.serdes_get_lane = mv88e6341_serdes_get_lane,
4266
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4267
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4268
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4269
	.gpio_ops = &mv88e6352_gpio_ops,
4270
	.avb_ops = &mv88e6390_avb_ops,
4271
	.ptp_ops = &mv88e6352_ptp_ops,
4272
	.phylink_validate = mv88e6341_phylink_validate,
4273 4274
};

4275
static const struct mv88e6xxx_ops mv88e6350_ops = {
4276
	/* MV88E6XXX_FAMILY_6351 */
4277 4278
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4279
	.irl_init_all = mv88e6352_g2_irl_init_all,
4280
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4281 4282
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4283
	.port_set_link = mv88e6xxx_port_set_link,
4284
	.port_set_duplex = mv88e6xxx_port_set_duplex,
4285
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4286
	.port_set_speed = mv88e6185_port_set_speed,
4287
	.port_tag_remap = mv88e6095_port_tag_remap,
4288
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4289
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4290
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4291
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4292
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4293
	.port_pause_limit = mv88e6097_port_pause_limit,
4294
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4295
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4296
	.port_link_state = mv88e6352_port_link_state,
4297
	.port_get_cmode = mv88e6352_port_get_cmode,
4298
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4299
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4300
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4301 4302
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
4303
	.stats_get_stats = mv88e6095_stats_get_stats,
4304 4305
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4306
	.watchdog_ops = &mv88e6097_watchdog_ops,
4307
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4308
	.pot_clear = mv88e6xxx_g2_pot_clear,
4309
	.reset = mv88e6352_g1_reset,
4310 4311
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4312
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4313
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4314
	.phylink_validate = mv88e6185_phylink_validate,
4315 4316 4317
};

static const struct mv88e6xxx_ops mv88e6351_ops = {
4318
	/* MV88E6XXX_FAMILY_6351 */
4319 4320
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4321
	.irl_init_all = mv88e6352_g2_irl_init_all,
4322
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4323 4324
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4325
	.port_set_link = mv88e6xxx_port_set_link,
4326
	.port_set_duplex = mv88e6xxx_port_set_duplex,
4327
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4328
	.port_set_speed = mv88e6185_port_set_speed,
4329
	.port_tag_remap = mv88e6095_port_tag_remap,
4330
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4331
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4332
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4333
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4334
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4335
	.port_pause_limit = mv88e6097_port_pause_limit,
4336
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4337
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4338
	.port_link_state = mv88e6352_port_link_state,
4339
	.port_get_cmode = mv88e6352_port_get_cmode,
4340
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4341
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4342
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4343 4344
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
4345
	.stats_get_stats = mv88e6095_stats_get_stats,
4346 4347
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4348
	.watchdog_ops = &mv88e6097_watchdog_ops,
4349
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4350
	.pot_clear = mv88e6xxx_g2_pot_clear,
4351
	.reset = mv88e6352_g1_reset,
4352 4353
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4354
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4355
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4356
	.avb_ops = &mv88e6352_avb_ops,
4357
	.ptp_ops = &mv88e6352_ptp_ops,
4358
	.phylink_validate = mv88e6185_phylink_validate,
4359 4360 4361
};

static const struct mv88e6xxx_ops mv88e6352_ops = {
4362
	/* MV88E6XXX_FAMILY_6352 */
4363 4364
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4365
	.irl_init_all = mv88e6352_g2_irl_init_all,
4366 4367
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
4368
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4369 4370
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4371
	.port_set_link = mv88e6xxx_port_set_link,
4372
	.port_set_duplex = mv88e6xxx_port_set_duplex,
4373
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4374
	.port_set_speed = mv88e6352_port_set_speed,
4375
	.port_tag_remap = mv88e6095_port_tag_remap,
4376
	.port_set_policy = mv88e6352_port_set_policy,
4377
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4378
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4379
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4380
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4381
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4382
	.port_pause_limit = mv88e6097_port_pause_limit,
4383
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4384
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4385
	.port_link_state = mv88e6352_port_link_state,
4386
	.port_get_cmode = mv88e6352_port_get_cmode,
4387
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4388
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4389
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4390 4391
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
4392
	.stats_get_stats = mv88e6095_stats_get_stats,
4393 4394
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4395
	.watchdog_ops = &mv88e6097_watchdog_ops,
4396
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4397
	.pot_clear = mv88e6xxx_g2_pot_clear,
4398
	.reset = mv88e6352_g1_reset,
4399
	.rmu_disable = mv88e6352_g1_rmu_disable,
4400 4401
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4402
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4403
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4404
	.serdes_get_lane = mv88e6352_serdes_get_lane,
4405
	.serdes_power = mv88e6352_serdes_power,
4406
	.serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
4407
	.serdes_irq_enable = mv88e6352_serdes_irq_enable,
4408
	.serdes_irq_status = mv88e6352_serdes_irq_status,
4409
	.gpio_ops = &mv88e6352_gpio_ops,
4410
	.avb_ops = &mv88e6352_avb_ops,
4411
	.ptp_ops = &mv88e6352_ptp_ops,
4412 4413 4414
	.serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
	.serdes_get_strings = mv88e6352_serdes_get_strings,
	.serdes_get_stats = mv88e6352_serdes_get_stats,
4415 4416
	.serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
	.serdes_get_regs = mv88e6352_serdes_get_regs,
4417
	.phylink_validate = mv88e6352_phylink_validate,
4418 4419
};

4420
static const struct mv88e6xxx_ops mv88e6390_ops = {
4421
	/* MV88E6XXX_FAMILY_6390 */
4422
	.setup_errata = mv88e6390_setup_errata,
4423
	.irl_init_all = mv88e6390_g2_irl_init_all,
4424 4425
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4426 4427 4428 4429 4430 4431 4432
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
	.port_set_speed = mv88e6390_port_set_speed,
4433
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
4434
	.port_tag_remap = mv88e6390_port_tag_remap,
4435
	.port_set_policy = mv88e6352_port_set_policy,
4436
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4437
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
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 = mv88e6390_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_link_state = mv88e6352_port_link_state,
4445
	.port_get_cmode = mv88e6352_port_get_cmode,
4446
	.port_set_cmode = mv88e6390_port_set_cmode,
4447
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4448
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4449
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4450 4451
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4452
	.stats_get_stats = mv88e6390_stats_get_stats,
4453 4454
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4455
	.watchdog_ops = &mv88e6390_watchdog_ops,
4456
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4457
	.pot_clear = mv88e6xxx_g2_pot_clear,
4458
	.reset = mv88e6352_g1_reset,
4459
	.rmu_disable = mv88e6390_g1_rmu_disable,
4460 4461
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4462 4463
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4464
	.serdes_power = mv88e6390_serdes_power,
4465
	.serdes_get_lane = mv88e6390_serdes_get_lane,
4466
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4467
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4468
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4469
	.gpio_ops = &mv88e6352_gpio_ops,
4470
	.avb_ops = &mv88e6390_avb_ops,
4471
	.ptp_ops = &mv88e6352_ptp_ops,
4472 4473 4474
	.serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
4475 4476
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
4477
	.phylink_validate = mv88e6390_phylink_validate,
4478 4479 4480
};

static const struct mv88e6xxx_ops mv88e6390x_ops = {
4481
	/* MV88E6XXX_FAMILY_6390 */
4482
	.setup_errata = mv88e6390_setup_errata,
4483
	.irl_init_all = mv88e6390_g2_irl_init_all,
4484 4485
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4486 4487 4488 4489 4490 4491 4492
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
	.port_set_speed = mv88e6390x_port_set_speed,
4493
	.port_max_speed_mode = mv88e6390x_port_max_speed_mode,
4494
	.port_tag_remap = mv88e6390_port_tag_remap,
4495
	.port_set_policy = mv88e6352_port_set_policy,
4496
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4497
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4498
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4499
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4500
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4501
	.port_pause_limit = mv88e6390_port_pause_limit,
4502
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4503
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4504
	.port_link_state = mv88e6352_port_link_state,
4505
	.port_get_cmode = mv88e6352_port_get_cmode,
4506
	.port_set_cmode = mv88e6390x_port_set_cmode,
4507
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4508
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4509
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4510 4511
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4512
	.stats_get_stats = mv88e6390_stats_get_stats,
4513 4514
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4515
	.watchdog_ops = &mv88e6390_watchdog_ops,
4516
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4517
	.pot_clear = mv88e6xxx_g2_pot_clear,
4518
	.reset = mv88e6352_g1_reset,
4519
	.rmu_disable = mv88e6390_g1_rmu_disable,
4520 4521
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4522 4523
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4524
	.serdes_power = mv88e6390_serdes_power,
4525
	.serdes_get_lane = mv88e6390x_serdes_get_lane,
4526
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4527
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4528
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4529 4530 4531
	.serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
4532 4533
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
4534
	.gpio_ops = &mv88e6352_gpio_ops,
4535
	.avb_ops = &mv88e6390_avb_ops,
4536
	.ptp_ops = &mv88e6352_ptp_ops,
4537
	.phylink_validate = mv88e6390x_phylink_validate,
4538 4539
};

4540 4541
static const struct mv88e6xxx_info mv88e6xxx_table[] = {
	[MV88E6085] = {
4542
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
4543 4544 4545
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6085",
		.num_databases = 4096,
4546
		.num_macs = 8192,
4547
		.num_ports = 10,
4548
		.num_internal_phys = 5,
4549
		.max_vid = 4095,
4550
		.port_base_addr = 0x10,
4551
		.phy_base_addr = 0x0,
4552
		.global1_addr = 0x1b,
4553
		.global2_addr = 0x1c,
4554
		.age_time_coeff = 15000,
4555
		.g1_irqs = 8,
4556
		.g2_irqs = 10,
4557
		.atu_move_port_mask = 0xf,
4558
		.pvt = true,
4559
		.multi_chip = true,
4560
		.tag_protocol = DSA_TAG_PROTO_DSA,
4561
		.ops = &mv88e6085_ops,
4562 4563 4564
	},

	[MV88E6095] = {
4565
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
4566 4567 4568
		.family = MV88E6XXX_FAMILY_6095,
		.name = "Marvell 88E6095/88E6095F",
		.num_databases = 256,
4569
		.num_macs = 8192,
4570
		.num_ports = 11,
4571
		.num_internal_phys = 0,
4572
		.max_vid = 4095,
4573
		.port_base_addr = 0x10,
4574
		.phy_base_addr = 0x0,
4575
		.global1_addr = 0x1b,
4576
		.global2_addr = 0x1c,
4577
		.age_time_coeff = 15000,
4578
		.g1_irqs = 8,
4579
		.atu_move_port_mask = 0xf,
4580
		.multi_chip = true,
4581
		.tag_protocol = DSA_TAG_PROTO_DSA,
4582
		.ops = &mv88e6095_ops,
4583 4584
	},

4585
	[MV88E6097] = {
4586
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
4587 4588 4589
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6097/88E6097F",
		.num_databases = 4096,
4590
		.num_macs = 8192,
4591
		.num_ports = 11,
4592
		.num_internal_phys = 8,
4593
		.max_vid = 4095,
4594
		.port_base_addr = 0x10,
4595
		.phy_base_addr = 0x0,
4596
		.global1_addr = 0x1b,
4597
		.global2_addr = 0x1c,
4598
		.age_time_coeff = 15000,
4599
		.g1_irqs = 8,
4600
		.g2_irqs = 10,
4601
		.atu_move_port_mask = 0xf,
4602
		.pvt = true,
4603
		.multi_chip = true,
4604
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4605 4606 4607
		.ops = &mv88e6097_ops,
	},

4608
	[MV88E6123] = {
4609
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
4610 4611 4612
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6123",
		.num_databases = 4096,
4613
		.num_macs = 1024,
4614
		.num_ports = 3,
4615
		.num_internal_phys = 5,
4616
		.max_vid = 4095,
4617
		.port_base_addr = 0x10,
4618
		.phy_base_addr = 0x0,
4619
		.global1_addr = 0x1b,
4620
		.global2_addr = 0x1c,
4621
		.age_time_coeff = 15000,
4622
		.g1_irqs = 9,
4623
		.g2_irqs = 10,
4624
		.atu_move_port_mask = 0xf,
4625
		.pvt = true,
4626
		.multi_chip = true,
4627
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4628
		.ops = &mv88e6123_ops,
4629 4630 4631
	},

	[MV88E6131] = {
4632
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
4633 4634 4635
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6131",
		.num_databases = 256,
4636
		.num_macs = 8192,
4637
		.num_ports = 8,
4638
		.num_internal_phys = 0,
4639
		.max_vid = 4095,
4640
		.port_base_addr = 0x10,
4641
		.phy_base_addr = 0x0,
4642
		.global1_addr = 0x1b,
4643
		.global2_addr = 0x1c,
4644
		.age_time_coeff = 15000,
4645
		.g1_irqs = 9,
4646
		.atu_move_port_mask = 0xf,
4647
		.multi_chip = true,
4648
		.tag_protocol = DSA_TAG_PROTO_DSA,
4649
		.ops = &mv88e6131_ops,
4650 4651
	},

4652
	[MV88E6141] = {
4653
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
4654
		.family = MV88E6XXX_FAMILY_6341,
4655
		.name = "Marvell 88E6141",
4656
		.num_databases = 4096,
4657
		.num_macs = 2048,
4658
		.num_ports = 6,
4659
		.num_internal_phys = 5,
4660
		.num_gpio = 11,
4661
		.max_vid = 4095,
4662
		.port_base_addr = 0x10,
4663
		.phy_base_addr = 0x10,
4664
		.global1_addr = 0x1b,
4665
		.global2_addr = 0x1c,
4666 4667
		.age_time_coeff = 3750,
		.atu_move_port_mask = 0x1f,
4668
		.g1_irqs = 9,
4669
		.g2_irqs = 10,
4670
		.pvt = true,
4671
		.multi_chip = true,
4672 4673 4674 4675
		.tag_protocol = DSA_TAG_PROTO_EDSA,
		.ops = &mv88e6141_ops,
	},

4676
	[MV88E6161] = {
4677
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
4678 4679 4680
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6161",
		.num_databases = 4096,
4681
		.num_macs = 1024,
4682
		.num_ports = 6,
4683
		.num_internal_phys = 5,
4684
		.max_vid = 4095,
4685
		.port_base_addr = 0x10,
4686
		.phy_base_addr = 0x0,
4687
		.global1_addr = 0x1b,
4688
		.global2_addr = 0x1c,
4689
		.age_time_coeff = 15000,
4690
		.g1_irqs = 9,
4691
		.g2_irqs = 10,
4692
		.atu_move_port_mask = 0xf,
4693
		.pvt = true,
4694
		.multi_chip = true,
4695
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4696
		.ptp_support = true,
4697
		.ops = &mv88e6161_ops,
4698 4699 4700
	},

	[MV88E6165] = {
4701
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
4702 4703 4704
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6165",
		.num_databases = 4096,
4705
		.num_macs = 8192,
4706
		.num_ports = 6,
4707
		.num_internal_phys = 0,
4708
		.max_vid = 4095,
4709
		.port_base_addr = 0x10,
4710
		.phy_base_addr = 0x0,
4711
		.global1_addr = 0x1b,
4712
		.global2_addr = 0x1c,
4713
		.age_time_coeff = 15000,
4714
		.g1_irqs = 9,
4715
		.g2_irqs = 10,
4716
		.atu_move_port_mask = 0xf,
4717
		.pvt = true,
4718
		.multi_chip = true,
4719
		.tag_protocol = DSA_TAG_PROTO_DSA,
4720
		.ptp_support = true,
4721
		.ops = &mv88e6165_ops,
4722 4723 4724
	},

	[MV88E6171] = {
4725
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
4726 4727 4728
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6171",
		.num_databases = 4096,
4729
		.num_macs = 8192,
4730
		.num_ports = 7,
4731
		.num_internal_phys = 5,
4732
		.max_vid = 4095,
4733
		.port_base_addr = 0x10,
4734
		.phy_base_addr = 0x0,
4735
		.global1_addr = 0x1b,
4736
		.global2_addr = 0x1c,
4737
		.age_time_coeff = 15000,
4738
		.g1_irqs = 9,
4739
		.g2_irqs = 10,
4740
		.atu_move_port_mask = 0xf,
4741
		.pvt = true,
4742
		.multi_chip = true,
4743
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4744
		.ops = &mv88e6171_ops,
4745 4746 4747
	},

	[MV88E6172] = {
4748
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
4749 4750 4751
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6172",
		.num_databases = 4096,
4752
		.num_macs = 8192,
4753
		.num_ports = 7,
4754
		.num_internal_phys = 5,
4755
		.num_gpio = 15,
4756
		.max_vid = 4095,
4757
		.port_base_addr = 0x10,
4758
		.phy_base_addr = 0x0,
4759
		.global1_addr = 0x1b,
4760
		.global2_addr = 0x1c,
4761
		.age_time_coeff = 15000,
4762
		.g1_irqs = 9,
4763
		.g2_irqs = 10,
4764
		.atu_move_port_mask = 0xf,
4765
		.pvt = true,
4766
		.multi_chip = true,
4767
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4768
		.ops = &mv88e6172_ops,
4769 4770 4771
	},

	[MV88E6175] = {
4772
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
4773 4774 4775
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6175",
		.num_databases = 4096,
4776
		.num_macs = 8192,
4777
		.num_ports = 7,
4778
		.num_internal_phys = 5,
4779
		.max_vid = 4095,
4780
		.port_base_addr = 0x10,
4781
		.phy_base_addr = 0x0,
4782
		.global1_addr = 0x1b,
4783
		.global2_addr = 0x1c,
4784
		.age_time_coeff = 15000,
4785
		.g1_irqs = 9,
4786
		.g2_irqs = 10,
4787
		.atu_move_port_mask = 0xf,
4788
		.pvt = true,
4789
		.multi_chip = true,
4790
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4791
		.ops = &mv88e6175_ops,
4792 4793 4794
	},

	[MV88E6176] = {
4795
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
4796 4797 4798
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6176",
		.num_databases = 4096,
4799
		.num_macs = 8192,
4800
		.num_ports = 7,
4801
		.num_internal_phys = 5,
4802
		.num_gpio = 15,
4803
		.max_vid = 4095,
4804
		.port_base_addr = 0x10,
4805
		.phy_base_addr = 0x0,
4806
		.global1_addr = 0x1b,
4807
		.global2_addr = 0x1c,
4808
		.age_time_coeff = 15000,
4809
		.g1_irqs = 9,
4810
		.g2_irqs = 10,
4811
		.atu_move_port_mask = 0xf,
4812
		.pvt = true,
4813
		.multi_chip = true,
4814
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4815
		.ops = &mv88e6176_ops,
4816 4817 4818
	},

	[MV88E6185] = {
4819
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
4820 4821 4822
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6185",
		.num_databases = 256,
4823
		.num_macs = 8192,
4824
		.num_ports = 10,
4825
		.num_internal_phys = 0,
4826
		.max_vid = 4095,
4827
		.port_base_addr = 0x10,
4828
		.phy_base_addr = 0x0,
4829
		.global1_addr = 0x1b,
4830
		.global2_addr = 0x1c,
4831
		.age_time_coeff = 15000,
4832
		.g1_irqs = 8,
4833
		.atu_move_port_mask = 0xf,
4834
		.multi_chip = true,
4835
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4836
		.ops = &mv88e6185_ops,
4837 4838
	},

4839
	[MV88E6190] = {
4840
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
4841 4842 4843
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190",
		.num_databases = 4096,
4844
		.num_macs = 16384,
4845
		.num_ports = 11,	/* 10 + Z80 */
4846
		.num_internal_phys = 9,
4847
		.num_gpio = 16,
4848
		.max_vid = 8191,
4849
		.port_base_addr = 0x0,
4850
		.phy_base_addr = 0x0,
4851
		.global1_addr = 0x1b,
4852
		.global2_addr = 0x1c,
4853
		.tag_protocol = DSA_TAG_PROTO_DSA,
4854
		.age_time_coeff = 3750,
4855
		.g1_irqs = 9,
4856
		.g2_irqs = 14,
4857
		.pvt = true,
4858
		.multi_chip = true,
4859
		.atu_move_port_mask = 0x1f,
4860 4861 4862 4863
		.ops = &mv88e6190_ops,
	},

	[MV88E6190X] = {
4864
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
4865 4866 4867
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190X",
		.num_databases = 4096,
4868
		.num_macs = 16384,
4869
		.num_ports = 11,	/* 10 + Z80 */
4870
		.num_internal_phys = 9,
4871
		.num_gpio = 16,
4872
		.max_vid = 8191,
4873
		.port_base_addr = 0x0,
4874
		.phy_base_addr = 0x0,
4875
		.global1_addr = 0x1b,
4876
		.global2_addr = 0x1c,
4877
		.age_time_coeff = 3750,
4878
		.g1_irqs = 9,
4879
		.g2_irqs = 14,
4880
		.atu_move_port_mask = 0x1f,
4881
		.pvt = true,
4882
		.multi_chip = true,
4883
		.tag_protocol = DSA_TAG_PROTO_DSA,
4884 4885 4886 4887
		.ops = &mv88e6190x_ops,
	},

	[MV88E6191] = {
4888
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
4889 4890 4891
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6191",
		.num_databases = 4096,
4892
		.num_macs = 16384,
4893
		.num_ports = 11,	/* 10 + Z80 */
4894
		.num_internal_phys = 9,
4895
		.max_vid = 8191,
4896
		.port_base_addr = 0x0,
4897
		.phy_base_addr = 0x0,
4898
		.global1_addr = 0x1b,
4899
		.global2_addr = 0x1c,
4900
		.age_time_coeff = 3750,
4901
		.g1_irqs = 9,
4902
		.g2_irqs = 14,
4903
		.atu_move_port_mask = 0x1f,
4904
		.pvt = true,
4905
		.multi_chip = true,
4906
		.tag_protocol = DSA_TAG_PROTO_DSA,
4907
		.ptp_support = true,
4908
		.ops = &mv88e6191_ops,
4909 4910
	},

4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921
	[MV88E6220] = {
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6220,
		.family = MV88E6XXX_FAMILY_6250,
		.name = "Marvell 88E6220",
		.num_databases = 64,

		/* Ports 2-4 are not routed to pins
		 * => usable ports 0, 1, 5, 6
		 */
		.num_ports = 7,
		.num_internal_phys = 2,
4922
		.invalid_port_mask = BIT(2) | BIT(3) | BIT(4),
4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933
		.max_vid = 4095,
		.port_base_addr = 0x08,
		.phy_base_addr = 0x00,
		.global1_addr = 0x0f,
		.global2_addr = 0x07,
		.age_time_coeff = 15000,
		.g1_irqs = 9,
		.g2_irqs = 10,
		.atu_move_port_mask = 0xf,
		.dual_chip = true,
		.tag_protocol = DSA_TAG_PROTO_DSA,
4934
		.ptp_support = true,
4935 4936 4937
		.ops = &mv88e6250_ops,
	},

4938
	[MV88E6240] = {
4939
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
4940 4941 4942
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6240",
		.num_databases = 4096,
4943
		.num_macs = 8192,
4944
		.num_ports = 7,
4945
		.num_internal_phys = 5,
4946
		.num_gpio = 15,
4947
		.max_vid = 4095,
4948
		.port_base_addr = 0x10,
4949
		.phy_base_addr = 0x0,
4950
		.global1_addr = 0x1b,
4951
		.global2_addr = 0x1c,
4952
		.age_time_coeff = 15000,
4953
		.g1_irqs = 9,
4954
		.g2_irqs = 10,
4955
		.atu_move_port_mask = 0xf,
4956
		.pvt = true,
4957
		.multi_chip = true,
4958
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4959
		.ptp_support = true,
4960
		.ops = &mv88e6240_ops,
4961 4962
	},

4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980
	[MV88E6250] = {
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6250,
		.family = MV88E6XXX_FAMILY_6250,
		.name = "Marvell 88E6250",
		.num_databases = 64,
		.num_ports = 7,
		.num_internal_phys = 5,
		.max_vid = 4095,
		.port_base_addr = 0x08,
		.phy_base_addr = 0x00,
		.global1_addr = 0x0f,
		.global2_addr = 0x07,
		.age_time_coeff = 15000,
		.g1_irqs = 9,
		.g2_irqs = 10,
		.atu_move_port_mask = 0xf,
		.dual_chip = true,
		.tag_protocol = DSA_TAG_PROTO_DSA,
4981
		.ptp_support = true,
4982 4983 4984
		.ops = &mv88e6250_ops,
	},

4985
	[MV88E6290] = {
4986
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
4987 4988 4989 4990
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6290",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4991
		.num_internal_phys = 9,
4992
		.num_gpio = 16,
4993
		.max_vid = 8191,
4994
		.port_base_addr = 0x0,
4995
		.phy_base_addr = 0x0,
4996
		.global1_addr = 0x1b,
4997
		.global2_addr = 0x1c,
4998
		.age_time_coeff = 3750,
4999
		.g1_irqs = 9,
5000
		.g2_irqs = 14,
5001
		.atu_move_port_mask = 0x1f,
5002
		.pvt = true,
5003
		.multi_chip = true,
5004
		.tag_protocol = DSA_TAG_PROTO_DSA,
5005
		.ptp_support = true,
5006 5007 5008
		.ops = &mv88e6290_ops,
	},

5009
	[MV88E6320] = {
5010
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
5011 5012 5013
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6320",
		.num_databases = 4096,
5014
		.num_macs = 8192,
5015
		.num_ports = 7,
5016
		.num_internal_phys = 5,
5017
		.num_gpio = 15,
5018
		.max_vid = 4095,
5019
		.port_base_addr = 0x10,
5020
		.phy_base_addr = 0x0,
5021
		.global1_addr = 0x1b,
5022
		.global2_addr = 0x1c,
5023
		.age_time_coeff = 15000,
5024
		.g1_irqs = 8,
5025
		.g2_irqs = 10,
5026
		.atu_move_port_mask = 0xf,
5027
		.pvt = true,
5028
		.multi_chip = true,
5029
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5030
		.ptp_support = true,
5031
		.ops = &mv88e6320_ops,
5032 5033 5034
	},

	[MV88E6321] = {
5035
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
5036 5037 5038
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6321",
		.num_databases = 4096,
5039
		.num_macs = 8192,
5040
		.num_ports = 7,
5041
		.num_internal_phys = 5,
5042
		.num_gpio = 15,
5043
		.max_vid = 4095,
5044
		.port_base_addr = 0x10,
5045
		.phy_base_addr = 0x0,
5046
		.global1_addr = 0x1b,
5047
		.global2_addr = 0x1c,
5048
		.age_time_coeff = 15000,
5049
		.g1_irqs = 8,
5050
		.g2_irqs = 10,
5051
		.atu_move_port_mask = 0xf,
5052
		.multi_chip = true,
5053
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5054
		.ptp_support = true,
5055
		.ops = &mv88e6321_ops,
5056 5057
	},

5058
	[MV88E6341] = {
5059
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
5060 5061 5062
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
5063
		.num_macs = 2048,
5064
		.num_internal_phys = 5,
5065
		.num_ports = 6,
5066
		.num_gpio = 11,
5067
		.max_vid = 4095,
5068
		.port_base_addr = 0x10,
5069
		.phy_base_addr = 0x10,
5070
		.global1_addr = 0x1b,
5071
		.global2_addr = 0x1c,
5072
		.age_time_coeff = 3750,
5073
		.atu_move_port_mask = 0x1f,
5074
		.g1_irqs = 9,
5075
		.g2_irqs = 10,
5076
		.pvt = true,
5077
		.multi_chip = true,
5078
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5079
		.ptp_support = true,
5080 5081 5082
		.ops = &mv88e6341_ops,
	},

5083
	[MV88E6350] = {
5084
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
5085 5086 5087
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6350",
		.num_databases = 4096,
5088
		.num_macs = 8192,
5089
		.num_ports = 7,
5090
		.num_internal_phys = 5,
5091
		.max_vid = 4095,
5092
		.port_base_addr = 0x10,
5093
		.phy_base_addr = 0x0,
5094
		.global1_addr = 0x1b,
5095
		.global2_addr = 0x1c,
5096
		.age_time_coeff = 15000,
5097
		.g1_irqs = 9,
5098
		.g2_irqs = 10,
5099
		.atu_move_port_mask = 0xf,
5100
		.pvt = true,
5101
		.multi_chip = true,
5102
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5103
		.ops = &mv88e6350_ops,
5104 5105 5106
	},

	[MV88E6351] = {
5107
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
5108 5109 5110
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6351",
		.num_databases = 4096,
5111
		.num_macs = 8192,
5112
		.num_ports = 7,
5113
		.num_internal_phys = 5,
5114
		.max_vid = 4095,
5115
		.port_base_addr = 0x10,
5116
		.phy_base_addr = 0x0,
5117
		.global1_addr = 0x1b,
5118
		.global2_addr = 0x1c,
5119
		.age_time_coeff = 15000,
5120
		.g1_irqs = 9,
5121
		.g2_irqs = 10,
5122
		.atu_move_port_mask = 0xf,
5123
		.pvt = true,
5124
		.multi_chip = true,
5125
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5126
		.ops = &mv88e6351_ops,
5127 5128 5129
	},

	[MV88E6352] = {
5130
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
5131 5132 5133
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6352",
		.num_databases = 4096,
5134
		.num_macs = 8192,
5135
		.num_ports = 7,
5136
		.num_internal_phys = 5,
5137
		.num_gpio = 15,
5138
		.max_vid = 4095,
5139
		.port_base_addr = 0x10,
5140
		.phy_base_addr = 0x0,
5141
		.global1_addr = 0x1b,
5142
		.global2_addr = 0x1c,
5143
		.age_time_coeff = 15000,
5144
		.g1_irqs = 9,
5145
		.g2_irqs = 10,
5146
		.atu_move_port_mask = 0xf,
5147
		.pvt = true,
5148
		.multi_chip = true,
5149
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5150
		.ptp_support = true,
5151
		.ops = &mv88e6352_ops,
5152
	},
5153
	[MV88E6390] = {
5154
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
5155 5156 5157
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390",
		.num_databases = 4096,
5158
		.num_macs = 16384,
5159
		.num_ports = 11,	/* 10 + Z80 */
5160
		.num_internal_phys = 9,
5161
		.num_gpio = 16,
5162
		.max_vid = 8191,
5163
		.port_base_addr = 0x0,
5164
		.phy_base_addr = 0x0,
5165
		.global1_addr = 0x1b,
5166
		.global2_addr = 0x1c,
5167
		.age_time_coeff = 3750,
5168
		.g1_irqs = 9,
5169
		.g2_irqs = 14,
5170
		.atu_move_port_mask = 0x1f,
5171
		.pvt = true,
5172
		.multi_chip = true,
5173
		.tag_protocol = DSA_TAG_PROTO_DSA,
5174
		.ptp_support = true,
5175 5176 5177
		.ops = &mv88e6390_ops,
	},
	[MV88E6390X] = {
5178
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
5179 5180 5181
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390X",
		.num_databases = 4096,
5182
		.num_macs = 16384,
5183
		.num_ports = 11,	/* 10 + Z80 */
5184
		.num_internal_phys = 9,
5185
		.num_gpio = 16,
5186
		.max_vid = 8191,
5187
		.port_base_addr = 0x0,
5188
		.phy_base_addr = 0x0,
5189
		.global1_addr = 0x1b,
5190
		.global2_addr = 0x1c,
5191
		.age_time_coeff = 3750,
5192
		.g1_irqs = 9,
5193
		.g2_irqs = 14,
5194
		.atu_move_port_mask = 0x1f,
5195
		.pvt = true,
5196
		.multi_chip = true,
5197
		.tag_protocol = DSA_TAG_PROTO_DSA,
5198
		.ptp_support = true,
5199 5200
		.ops = &mv88e6390x_ops,
	},
5201 5202
};

5203
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
5204
{
5205
	int i;
5206

5207 5208 5209
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
5210 5211 5212 5213

	return NULL;
}

5214
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
5215 5216
{
	const struct mv88e6xxx_info *info;
5217 5218 5219
	unsigned int prod_num, rev;
	u16 id;
	int err;
5220

5221
	mv88e6xxx_reg_lock(chip);
5222
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
5223
	mv88e6xxx_reg_unlock(chip);
5224 5225
	if (err)
		return err;
5226

5227 5228
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
5229 5230 5231 5232 5233

	info = mv88e6xxx_lookup_info(prod_num);
	if (!info)
		return -ENODEV;

5234
	/* Update the compatible info with the probed one */
5235
	chip->info = info;
5236

5237 5238 5239 5240
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

5241 5242
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
5243 5244 5245 5246

	return 0;
}

5247
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
5248
{
5249
	struct mv88e6xxx_chip *chip;
5250

5251 5252
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
5253 5254
		return NULL;

5255
	chip->dev = dev;
5256

5257
	mutex_init(&chip->reg_lock);
5258
	INIT_LIST_HEAD(&chip->mdios);
5259
	idr_init(&chip->policies);
5260

5261
	return chip;
5262 5263
}

5264
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
5265 5266
							int port,
							enum dsa_tag_protocol m)
5267
{
V
Vivien Didelot 已提交
5268
	struct mv88e6xxx_chip *chip = ds->priv;
5269

5270
	return chip->info->tag_protocol;
5271 5272
}

5273
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
5274
				      const struct switchdev_obj_port_mdb *mdb)
5275 5276 5277 5278 5279 5280 5281 5282 5283
{
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */

	return 0;
}

static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
5284
				   const struct switchdev_obj_port_mdb *mdb)
5285
{
V
Vivien Didelot 已提交
5286
	struct mv88e6xxx_chip *chip = ds->priv;
5287

5288
	mv88e6xxx_reg_lock(chip);
5289
	if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
5290
					 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
5291 5292
		dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
			port);
5293
	mv88e6xxx_reg_unlock(chip);
5294 5295 5296 5297 5298
}

static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
				  const struct switchdev_obj_port_mdb *mdb)
{
V
Vivien Didelot 已提交
5299
	struct mv88e6xxx_chip *chip = ds->priv;
5300 5301
	int err;

5302
	mv88e6xxx_reg_lock(chip);
5303
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 0);
5304
	mv88e6xxx_reg_unlock(chip);
5305 5306 5307 5308

	return err;
}

5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375
static int mv88e6xxx_port_mirror_add(struct dsa_switch *ds, int port,
				     struct dsa_mall_mirror_tc_entry *mirror,
				     bool ingress)
{
	enum mv88e6xxx_egress_direction direction = ingress ?
						MV88E6XXX_EGRESS_DIR_INGRESS :
						MV88E6XXX_EGRESS_DIR_EGRESS;
	struct mv88e6xxx_chip *chip = ds->priv;
	bool other_mirrors = false;
	int i;
	int err;

	if (!chip->info->ops->set_egress_port)
		return -EOPNOTSUPP;

	mutex_lock(&chip->reg_lock);
	if ((ingress ? chip->ingress_dest_port : chip->egress_dest_port) !=
	    mirror->to_local_port) {
		for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
			other_mirrors |= ingress ?
					 chip->ports[i].mirror_ingress :
					 chip->ports[i].mirror_egress;

		/* Can't change egress port when other mirror is active */
		if (other_mirrors) {
			err = -EBUSY;
			goto out;
		}

		err = chip->info->ops->set_egress_port(chip,
						       direction,
						       mirror->to_local_port);
		if (err)
			goto out;
	}

	err = mv88e6xxx_port_set_mirror(chip, port, direction, true);
out:
	mutex_unlock(&chip->reg_lock);

	return err;
}

static void mv88e6xxx_port_mirror_del(struct dsa_switch *ds, int port,
				      struct dsa_mall_mirror_tc_entry *mirror)
{
	enum mv88e6xxx_egress_direction direction = mirror->ingress ?
						MV88E6XXX_EGRESS_DIR_INGRESS :
						MV88E6XXX_EGRESS_DIR_EGRESS;
	struct mv88e6xxx_chip *chip = ds->priv;
	bool other_mirrors = false;
	int i;

	mutex_lock(&chip->reg_lock);
	if (mv88e6xxx_port_set_mirror(chip, port, direction, false))
		dev_err(ds->dev, "p%d: failed to disable mirroring\n", port);

	for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
		other_mirrors |= mirror->ingress ?
				 chip->ports[i].mirror_ingress :
				 chip->ports[i].mirror_egress;

	/* Reset egress port when no other mirror is active */
	if (!other_mirrors) {
		if (chip->info->ops->set_egress_port(chip,
						     direction,
						     dsa_upstream_port(ds,
5376
								       port)))
5377 5378 5379 5380 5381 5382
			dev_err(ds->dev, "failed to set egress port\n");
	}

	mutex_unlock(&chip->reg_lock);
}

5383 5384 5385 5386 5387 5388
static int mv88e6xxx_port_egress_floods(struct dsa_switch *ds, int port,
					 bool unicast, bool multicast)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err = -EOPNOTSUPP;

5389
	mv88e6xxx_reg_lock(chip);
5390 5391 5392 5393
	if (chip->info->ops->port_set_egress_floods)
		err = chip->info->ops->port_set_egress_floods(chip, port,
							      unicast,
							      multicast);
5394
	mv88e6xxx_reg_unlock(chip);
5395 5396 5397 5398

	return err;
}

5399
static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
5400
	.get_tag_protocol	= mv88e6xxx_get_tag_protocol,
5401
	.setup			= mv88e6xxx_setup,
5402
	.teardown		= mv88e6xxx_teardown,
5403 5404 5405 5406 5407
	.phylink_validate	= mv88e6xxx_validate,
	.phylink_mac_link_state	= mv88e6xxx_link_state,
	.phylink_mac_config	= mv88e6xxx_mac_config,
	.phylink_mac_link_down	= mv88e6xxx_mac_link_down,
	.phylink_mac_link_up	= mv88e6xxx_mac_link_up,
5408 5409 5410
	.get_strings		= mv88e6xxx_get_strings,
	.get_ethtool_stats	= mv88e6xxx_get_ethtool_stats,
	.get_sset_count		= mv88e6xxx_get_sset_count,
5411 5412
	.port_enable		= mv88e6xxx_port_enable,
	.port_disable		= mv88e6xxx_port_disable,
V
Vivien Didelot 已提交
5413 5414
	.get_mac_eee		= mv88e6xxx_get_mac_eee,
	.set_mac_eee		= mv88e6xxx_set_mac_eee,
5415
	.get_eeprom_len		= mv88e6xxx_get_eeprom_len,
5416 5417 5418 5419
	.get_eeprom		= mv88e6xxx_get_eeprom,
	.set_eeprom		= mv88e6xxx_set_eeprom,
	.get_regs_len		= mv88e6xxx_get_regs_len,
	.get_regs		= mv88e6xxx_get_regs,
5420 5421
	.get_rxnfc		= mv88e6xxx_get_rxnfc,
	.set_rxnfc		= mv88e6xxx_set_rxnfc,
5422
	.set_ageing_time	= mv88e6xxx_set_ageing_time,
5423 5424
	.port_bridge_join	= mv88e6xxx_port_bridge_join,
	.port_bridge_leave	= mv88e6xxx_port_bridge_leave,
5425
	.port_egress_floods	= mv88e6xxx_port_egress_floods,
5426
	.port_stp_state_set	= mv88e6xxx_port_stp_state_set,
5427
	.port_fast_age		= mv88e6xxx_port_fast_age,
5428 5429 5430 5431 5432 5433 5434
	.port_vlan_filtering	= mv88e6xxx_port_vlan_filtering,
	.port_vlan_prepare	= mv88e6xxx_port_vlan_prepare,
	.port_vlan_add		= mv88e6xxx_port_vlan_add,
	.port_vlan_del		= mv88e6xxx_port_vlan_del,
	.port_fdb_add           = mv88e6xxx_port_fdb_add,
	.port_fdb_del           = mv88e6xxx_port_fdb_del,
	.port_fdb_dump          = mv88e6xxx_port_fdb_dump,
5435 5436 5437
	.port_mdb_prepare       = mv88e6xxx_port_mdb_prepare,
	.port_mdb_add           = mv88e6xxx_port_mdb_add,
	.port_mdb_del           = mv88e6xxx_port_mdb_del,
5438 5439
	.port_mirror_add	= mv88e6xxx_port_mirror_add,
	.port_mirror_del	= mv88e6xxx_port_mirror_del,
5440 5441
	.crosschip_bridge_join	= mv88e6xxx_crosschip_bridge_join,
	.crosschip_bridge_leave	= mv88e6xxx_crosschip_bridge_leave,
5442 5443 5444 5445 5446
	.port_hwtstamp_set	= mv88e6xxx_port_hwtstamp_set,
	.port_hwtstamp_get	= mv88e6xxx_port_hwtstamp_get,
	.port_txtstamp		= mv88e6xxx_port_txtstamp,
	.port_rxtstamp		= mv88e6xxx_port_rxtstamp,
	.get_ts_info		= mv88e6xxx_get_ts_info,
5447 5448
	.devlink_param_get	= mv88e6xxx_devlink_param_get,
	.devlink_param_set	= mv88e6xxx_devlink_param_set,
5449 5450
};

5451
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
5452
{
5453
	struct device *dev = chip->dev;
5454 5455
	struct dsa_switch *ds;

5456
	ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
5457 5458 5459
	if (!ds)
		return -ENOMEM;

5460 5461
	ds->dev = dev;
	ds->num_ports = mv88e6xxx_num_ports(chip);
5462
	ds->priv = chip;
5463
	ds->dev = dev;
5464
	ds->ops = &mv88e6xxx_switch_ops;
5465 5466
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
5467 5468 5469

	dev_set_drvdata(dev, ds);

5470
	return dsa_register_switch(ds);
5471 5472
}

5473
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
5474
{
5475
	dsa_unregister_switch(chip->ds);
5476 5477
}

5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490
static const void *pdata_device_get_match_data(struct device *dev)
{
	const struct of_device_id *matches = dev->driver->of_match_table;
	const struct dsa_mv88e6xxx_pdata *pdata = dev->platform_data;

	for (; matches->name[0] || matches->type[0] || matches->compatible[0];
	     matches++) {
		if (!strcmp(pdata->compatible, matches->compatible))
			return matches->data;
	}
	return NULL;
}

5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505
/* There is no suspend to RAM support at DSA level yet, the switch configuration
 * would be lost after a power cycle so prevent it to be suspended.
 */
static int __maybe_unused mv88e6xxx_suspend(struct device *dev)
{
	return -EOPNOTSUPP;
}

static int __maybe_unused mv88e6xxx_resume(struct device *dev)
{
	return 0;
}

static SIMPLE_DEV_PM_OPS(mv88e6xxx_pm_ops, mv88e6xxx_suspend, mv88e6xxx_resume);

5506
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
5507
{
5508
	struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
5509
	const struct mv88e6xxx_info *compat_info = NULL;
5510
	struct device *dev = &mdiodev->dev;
5511
	struct device_node *np = dev->of_node;
5512
	struct mv88e6xxx_chip *chip;
5513
	int port;
5514
	int err;
5515

5516 5517 5518
	if (!np && !pdata)
		return -EINVAL;

5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537
	if (np)
		compat_info = of_device_get_match_data(dev);

	if (pdata) {
		compat_info = pdata_device_get_match_data(dev);

		if (!pdata->netdev)
			return -EINVAL;

		for (port = 0; port < DSA_MAX_PORTS; port++) {
			if (!(pdata->enabled_ports & (1 << port)))
				continue;
			if (strcmp(pdata->cd.port_names[port], "cpu"))
				continue;
			pdata->cd.netdev[port] = &pdata->netdev->dev;
			break;
		}
	}

5538 5539 5540
	if (!compat_info)
		return -EINVAL;

5541
	chip = mv88e6xxx_alloc_chip(dev);
5542 5543 5544 5545
	if (!chip) {
		err = -ENOMEM;
		goto out;
	}
5546

5547
	chip->info = compat_info;
5548

5549
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
5550
	if (err)
5551
		goto out;
5552

5553
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
5554 5555 5556 5557
	if (IS_ERR(chip->reset)) {
		err = PTR_ERR(chip->reset);
		goto out;
	}
5558 5559
	if (chip->reset)
		usleep_range(1000, 2000);
5560

5561
	err = mv88e6xxx_detect(chip);
5562
	if (err)
5563
		goto out;
5564

5565 5566
	mv88e6xxx_phy_init(chip);

5567 5568 5569 5570 5571 5572 5573
	if (chip->info->ops->get_eeprom) {
		if (np)
			of_property_read_u32(np, "eeprom-length",
					     &chip->eeprom_len);
		else
			chip->eeprom_len = pdata->eeprom_len;
	}
5574

5575
	mv88e6xxx_reg_lock(chip);
5576
	err = mv88e6xxx_switch_reset(chip);
5577
	mv88e6xxx_reg_unlock(chip);
5578 5579 5580
	if (err)
		goto out;

5581 5582 5583 5584 5585 5586
	if (np) {
		chip->irq = of_irq_get(np, 0);
		if (chip->irq == -EPROBE_DEFER) {
			err = chip->irq;
			goto out;
		}
5587 5588
	}

5589 5590 5591
	if (pdata)
		chip->irq = pdata->irq;

5592
	/* Has to be performed before the MDIO bus is created, because
5593
	 * the PHYs will link their interrupts to these interrupt
5594 5595
	 * controllers
	 */
5596
	mv88e6xxx_reg_lock(chip);
5597
	if (chip->irq > 0)
5598
		err = mv88e6xxx_g1_irq_setup(chip);
5599 5600
	else
		err = mv88e6xxx_irq_poll_setup(chip);
5601
	mv88e6xxx_reg_unlock(chip);
5602

5603 5604
	if (err)
		goto out;
5605

5606 5607
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
5608
		if (err)
5609
			goto out_g1_irq;
5610 5611
	}

5612 5613 5614 5615 5616 5617 5618 5619
	err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
	if (err)
		goto out_g2_irq;

	err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
	if (err)
		goto out_g1_atu_prob_irq;

5620
	err = mv88e6xxx_mdios_register(chip, np);
5621
	if (err)
5622
		goto out_g1_vtu_prob_irq;
5623

5624
	err = mv88e6xxx_register_switch(chip);
5625 5626
	if (err)
		goto out_mdio;
5627

5628
	return 0;
5629 5630

out_mdio:
5631
	mv88e6xxx_mdios_unregister(chip);
5632
out_g1_vtu_prob_irq:
5633
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
5634
out_g1_atu_prob_irq:
5635
	mv88e6xxx_g1_atu_prob_irq_free(chip);
5636
out_g2_irq:
5637
	if (chip->info->g2_irqs > 0)
5638 5639
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
5640
	if (chip->irq > 0)
5641
		mv88e6xxx_g1_irq_free(chip);
5642 5643
	else
		mv88e6xxx_irq_poll_free(chip);
5644
out:
5645 5646 5647
	if (pdata)
		dev_put(pdata->netdev);

5648
	return err;
5649
}
5650 5651 5652 5653

static void mv88e6xxx_remove(struct mdio_device *mdiodev)
{
	struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
V
Vivien Didelot 已提交
5654
	struct mv88e6xxx_chip *chip = ds->priv;
5655

5656 5657
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
5658
		mv88e6xxx_ptp_free(chip);
5659
	}
5660

5661
	mv88e6xxx_phy_destroy(chip);
5662
	mv88e6xxx_unregister_switch(chip);
5663
	mv88e6xxx_mdios_unregister(chip);
5664

5665 5666 5667 5668 5669 5670 5671
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
	mv88e6xxx_g1_atu_prob_irq_free(chip);

	if (chip->info->g2_irqs > 0)
		mv88e6xxx_g2_irq_free(chip);

	if (chip->irq > 0)
5672
		mv88e6xxx_g1_irq_free(chip);
5673 5674
	else
		mv88e6xxx_irq_poll_free(chip);
5675 5676 5677
}

static const struct of_device_id mv88e6xxx_of_match[] = {
5678 5679 5680 5681
	{
		.compatible = "marvell,mv88e6085",
		.data = &mv88e6xxx_table[MV88E6085],
	},
5682 5683 5684 5685
	{
		.compatible = "marvell,mv88e6190",
		.data = &mv88e6xxx_table[MV88E6190],
	},
5686 5687 5688 5689
	{
		.compatible = "marvell,mv88e6250",
		.data = &mv88e6xxx_table[MV88E6250],
	},
5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700
	{ /* sentinel */ },
};

MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);

static struct mdio_driver mv88e6xxx_driver = {
	.probe	= mv88e6xxx_probe,
	.remove = mv88e6xxx_remove,
	.mdiodrv.driver = {
		.name = "mv88e6085",
		.of_match_table = mv88e6xxx_of_match,
5701
		.pm = &mv88e6xxx_pm_ops,
5702 5703 5704
	},
};

5705
mdio_module_driver(mv88e6xxx_driver);
5706 5707 5708 5709

MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
MODULE_LICENSE("GPL");