chip.c 140.0 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/delay.h>
14
#include <linux/etherdevice.h>
15
#include <linux/ethtool.h>
16
#include <linux/if_bridge.h>
17 18 19
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/irqdomain.h>
20
#include <linux/jiffies.h>
21
#include <linux/list.h>
22
#include <linux/mdio.h>
23
#include <linux/module.h>
24
#include <linux/of_device.h>
25
#include <linux/of_irq.h>
26
#include <linux/of_mdio.h>
27
#include <linux/platform_data/mv88e6xxx.h>
28
#include <linux/netdevice.h>
29
#include <linux/gpio/consumer.h>
30
#include <linux/phy.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
struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
85 86 87 88 89 90 91 92 93 94 95
{
	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;
}

96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
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);
}

112
static irqreturn_t mv88e6xxx_g1_irq_thread_work(struct mv88e6xxx_chip *chip)
113 114 115 116 117
{
	unsigned int nhandled = 0;
	unsigned int sub_irq;
	unsigned int n;
	u16 reg;
118
	u16 ctl1;
119 120
	int err;

121
	mv88e6xxx_reg_lock(chip);
122
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
123
	mv88e6xxx_reg_unlock(chip);
124 125 126 127

	if (err)
		goto out;

128 129 130 131 132 133 134 135
	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;
			}
136
		}
137

138
		mv88e6xxx_reg_lock(chip);
139 140 141 142 143
		err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &ctl1);
		if (err)
			goto unlock;
		err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
unlock:
144
		mv88e6xxx_reg_unlock(chip);
145 146 147 148 149
		if (err)
			goto out;
		ctl1 &= GENMASK(chip->g1_irq.nirqs, 0);
	} while (reg & ctl1);

150 151 152 153
out:
	return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
}

154 155 156 157 158 159 160
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);
}

161 162 163 164
static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
{
	struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);

165
	mv88e6xxx_reg_lock(chip);
166 167 168 169 170 171 172 173 174
}

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;

175
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &reg);
176 177 178 179 180 181
	if (err)
		goto out;

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

182
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, reg);
183 184 185 186
	if (err)
		goto out;

out:
187
	mv88e6xxx_reg_unlock(chip);
188 189
}

190
static const struct irq_chip mv88e6xxx_g1_irq_chip = {
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
	.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,
};

216
/* To be called with reg_lock held */
217
static void mv88e6xxx_g1_irq_free_common(struct mv88e6xxx_chip *chip)
218 219
{
	int irq, virq;
220 221
	u16 mask;

222
	mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
223
	mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
224
	mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
225

226
	for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
227
		virq = irq_find_mapping(chip->g1_irq.domain, irq);
228 229 230
		irq_dispose_mapping(virq);
	}

231
	irq_domain_remove(chip->g1_irq.domain);
232 233
}

234 235
static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
{
236 237 238 239
	/*
	 * free_irq must be called without reg_lock taken because the irq
	 * handler takes this lock, too.
	 */
240
	free_irq(chip->irq, chip);
241

242
	mv88e6xxx_reg_lock(chip);
243
	mv88e6xxx_g1_irq_free_common(chip);
244
	mv88e6xxx_reg_unlock(chip);
245 246 247
}

static int mv88e6xxx_g1_irq_setup_common(struct mv88e6xxx_chip *chip)
248
{
249 250
	int err, irq, virq;
	u16 reg, mask;
251 252 253 254 255 256 257 258 259 260 261 262 263 264

	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;

265
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
266
	if (err)
267
		goto out_mapping;
268

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

271
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
272
	if (err)
273
		goto out_disable;
274 275

	/* Reading the interrupt status clears (most of) them */
276
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
277
	if (err)
278
		goto out_disable;
279 280 281

	return 0;

282
out_disable:
283
	mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
284
	mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
285 286 287 288 289 290 291 292

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);
293 294 295 296

	return err;
}

297 298
static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
{
299 300
	static struct lock_class_key lock_key;
	static struct lock_class_key request_key;
301 302 303 304 305 306
	int err;

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

307 308 309 310 311 312
	/* 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);

313
	mv88e6xxx_reg_unlock(chip);
314 315
	err = request_threaded_irq(chip->irq, NULL,
				   mv88e6xxx_g1_irq_thread_fn,
316
				   IRQF_ONESHOT | IRQF_SHARED,
317
				   dev_name(chip->dev), chip);
318
	mv88e6xxx_reg_lock(chip);
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
	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);

347
	chip->kworker = kthread_create_worker(0, "%s", dev_name(chip->dev));
348 349 350 351 352 353 354 355 356 357 358 359 360
	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);
361

362
	mv88e6xxx_reg_lock(chip);
363
	mv88e6xxx_g1_irq_free_common(chip);
364
	mv88e6xxx_reg_unlock(chip);
365 366
}

367
int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask)
368
{
369
	int i;
370

371
	for (i = 0; i < 16; i++) {
372 373 374 375 376 377 378 379 380 381 382 383 384
		u16 val;
		int err;

		err = mv88e6xxx_read(chip, addr, reg, &val);
		if (err)
			return err;

		if (!(val & mask))
			return 0;

		usleep_range(1000, 2000);
	}

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

389
/* Indirect write to single pointer-data register with an Update bit */
390
int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
391 392
{
	u16 val;
393
	int err;
394 395

	/* Wait until the previous operation is completed */
396 397 398
	err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
	if (err)
		return err;
399 400 401 402 403 404 405

	/* Set the Update bit to trigger a write operation */
	val = BIT(15) | update;

	return mv88e6xxx_write(chip, addr, reg, val);
}

406 407 408
int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port, int link,
			     int speed, int duplex, int pause,
			     phy_interface_t mode)
409
{
410
	struct phylink_link_state state;
411 412 413 414 415
	int err;

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

416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
	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 &&
	    state.duplex == duplex)
		return 0;

432 433 434 435 436 437 438 439 440 441 442
	/* Port's MAC control must not be changed unless the link is down */
	err = chip->info->ops->port_set_link(chip, port, 0);
	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;
	}

443 444 445
	if (speed == SPEED_MAX && chip->info->ops->port_max_speed_mode)
		mode = chip->info->ops->port_max_speed_mode(port);

446 447 448 449 450 451
	if (chip->info->ops->port_set_pause) {
		err = chip->info->ops->port_set_pause(chip, port, pause);
		if (err)
			goto restore_link;
	}

452 453 454 455 456 457 458 459 460 461 462 463
	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;
	}

464 465 466 467 468 469
	if (chip->info->ops->port_set_cmode) {
		err = chip->info->ops->port_set_cmode(chip, port, mode);
		if (err && err != -EOPNOTSUPP)
			goto restore_link;
	}

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

	return err;
}

478 479 480 481 482 483 484
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;
}

485 486 487 488
/* We expect the switch to perform auto negotiation if there is a real
 * phy. However, in the case of a fixed link phy, we force the port
 * settings from the fixed link settings.
 */
489 490
static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
				  struct phy_device *phydev)
491
{
V
Vivien Didelot 已提交
492
	struct mv88e6xxx_chip *chip = ds->priv;
493
	int err;
494

495 496
	if (!phy_is_pseudo_fixed_link(phydev) &&
	    mv88e6xxx_phy_is_internal(ds, port))
497 498
		return;

499
	mv88e6xxx_reg_lock(chip);
500
	err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
501 502
				       phydev->duplex, phydev->pause,
				       phydev->interface);
503
	mv88e6xxx_reg_unlock(chip);
504 505

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

509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
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);
}

535 536 537 538 539 540 541 542 543 544 545 546 547 548
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);
}

549 550 551 552 553 554 555 556 557 558 559 560 561 562 563
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)
{
564
	if (port >= 9) {
565
		phylink_set(mask, 2500baseX_Full);
566 567
		phylink_set(mask, 2500baseT_Full);
	}
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587

	/* 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);
}

588 589 590 591
static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
			       unsigned long *supported,
			       struct phylink_link_state *state)
{
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
	__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);
611 612 613 614 615 616 617 618
}

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

619
	mv88e6xxx_reg_lock(chip);
620 621 622 623
	if (chip->info->ops->port_link_state)
		err = chip->info->ops->port_link_state(chip, port, state);
	else
		err = -EOPNOTSUPP;
624
	mv88e6xxx_reg_unlock(chip);
625 626 627 628 629 630 631 632 633

	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;
634
	int speed, duplex, link, pause, err;
635

636
	if ((mode == MLO_AN_PHY) && mv88e6xxx_phy_is_internal(ds, port))
637 638 639 640 641 642
		return;

	if (mode == MLO_AN_FIXED) {
		link = LINK_FORCED_UP;
		speed = state->speed;
		duplex = state->duplex;
643 644 645 646
	} else if (!mv88e6xxx_phy_is_internal(ds, port)) {
		link = state->link;
		speed = state->speed;
		duplex = state->duplex;
647 648 649 650 651
	} else {
		speed = SPEED_UNFORCED;
		duplex = DUPLEX_UNFORCED;
		link = LINK_UNFORCED;
	}
652
	pause = !!phylink_test(state->advertising, Pause);
653

654
	mv88e6xxx_reg_lock(chip);
655
	err = mv88e6xxx_port_setup_mac(chip, port, link, speed, duplex, pause,
656
				       state->interface);
657
	mv88e6xxx_reg_unlock(chip);
658 659 660 661 662 663 664 665 666 667

	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;

668
	mv88e6xxx_reg_lock(chip);
669
	err = chip->info->ops->port_set_link(chip, port, link);
670
	mv88e6xxx_reg_unlock(chip);
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691

	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);
}

692
static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
693
{
694 695
	if (!chip->info->ops->stats_snapshot)
		return -EOPNOTSUPP;
696

697
	return chip->info->ops->stats_snapshot(chip, port);
698 699
}

700
static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
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 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759
	{ "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, },
760 761
};

762
static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
763
					    struct mv88e6xxx_hw_stat *s,
764 765
					    int port, u16 bank1_select,
					    u16 histogram)
766 767 768
{
	u32 low;
	u32 high = 0;
769
	u16 reg = 0;
770
	int err;
771 772
	u64 value;

773
	switch (s->type) {
774
	case STATS_TYPE_PORT:
775 776
		err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
		if (err)
777
			return U64_MAX;
778

779
		low = reg;
780
		if (s->size == 4) {
781 782
			err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
			if (err)
783
				return U64_MAX;
784
			low |= ((u32)reg) << 16;
785
		}
786
		break;
787
	case STATS_TYPE_BANK1:
788
		reg = bank1_select;
789 790
		/* fall through */
	case STATS_TYPE_BANK0:
791
		reg |= s->reg | histogram;
792
		mv88e6xxx_g1_stats_read(chip, reg, &low);
793
		if (s->size == 8)
794
			mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
795 796
		break;
	default:
797
		return U64_MAX;
798
	}
799
	value = (((u64)high) << 32) | low;
800 801 802
	return value;
}

803 804
static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data, int types)
805
{
806 807
	struct mv88e6xxx_hw_stat *stat;
	int i, j;
808

809 810
	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
		stat = &mv88e6xxx_hw_stats[i];
811
		if (stat->type & types) {
812 813 814 815
			memcpy(data + j * ETH_GSTRING_LEN, stat->string,
			       ETH_GSTRING_LEN);
			j++;
		}
816
	}
817 818

	return j;
819 820
}

821 822
static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
823
{
824 825
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_PORT);
826 827
}

828 829 830 831 832 833
static int mv88e6250_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
{
	return mv88e6xxx_stats_get_strings(chip, data, STATS_TYPE_BANK0);
}

834 835
static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
836
{
837 838
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
839 840
}

841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858
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);
}

859
static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
860
				  u32 stringset, uint8_t *data)
861
{
V
Vivien Didelot 已提交
862
	struct mv88e6xxx_chip *chip = ds->priv;
863
	int count = 0;
864

865 866 867
	if (stringset != ETH_SS_STATS)
		return;

868
	mv88e6xxx_reg_lock(chip);
869

870
	if (chip->info->ops->stats_get_strings)
871 872 873 874
		count = chip->info->ops->stats_get_strings(chip, data);

	if (chip->info->ops->serdes_get_strings) {
		data += count * ETH_GSTRING_LEN;
875
		count = chip->info->ops->serdes_get_strings(chip, port, data);
876
	}
877

878 879 880
	data += count * ETH_GSTRING_LEN;
	mv88e6xxx_atu_vtu_get_strings(data);

881
	mv88e6xxx_reg_unlock(chip);
882 883 884 885 886
}

static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
					  int types)
{
887 888 889 890 891
	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];
892
		if (stat->type & types)
893 894 895
			j++;
	}
	return j;
896 897
}

898 899 900 901 902 903
static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
{
	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
					      STATS_TYPE_PORT);
}

904 905 906 907 908
static int mv88e6250_stats_get_sset_count(struct mv88e6xxx_chip *chip)
{
	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0);
}

909 910 911 912 913 914
static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
{
	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
					      STATS_TYPE_BANK1);
}

915
static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
916 917
{
	struct mv88e6xxx_chip *chip = ds->priv;
918 919
	int serdes_count = 0;
	int count = 0;
920

921 922 923
	if (sset != ETH_SS_STATS)
		return 0;

924
	mv88e6xxx_reg_lock(chip);
925
	if (chip->info->ops->stats_get_sset_count)
926 927 928 929 930 931 932
		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);
933
	if (serdes_count < 0) {
934
		count = serdes_count;
935 936 937 938 939
		goto out;
	}
	count += serdes_count;
	count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);

940
out:
941
	mv88e6xxx_reg_unlock(chip);
942

943
	return count;
944 945
}

946 947 948
static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data, int types,
				     u16 bank1_select, u16 histogram)
949 950 951 952 953 954 955
{
	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) {
956
			mv88e6xxx_reg_lock(chip);
957 958 959
			data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
							      bank1_select,
							      histogram);
960
			mv88e6xxx_reg_unlock(chip);
961

962 963 964
			j++;
		}
	}
965
	return j;
966 967
}

968 969
static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
970 971
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
972
					 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
973
					 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
974 975
}

976 977 978 979 980 981 982
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);
}

983 984
static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
985 986
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
987
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
988 989
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
					 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
990 991
}

992 993
static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
994 995 996
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
997 998
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
					 0);
999 1000
}

1001 1002 1003 1004 1005 1006 1007 1008 1009 1010
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;
}

1011 1012 1013
static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
				uint64_t *data)
{
1014 1015
	int count = 0;

1016
	if (chip->info->ops->stats_get_stats)
1017 1018
		count = chip->info->ops->stats_get_stats(chip, port, data);

1019
	mv88e6xxx_reg_lock(chip);
1020 1021
	if (chip->info->ops->serdes_get_stats) {
		data += count;
1022
		count = chip->info->ops->serdes_get_stats(chip, port, data);
1023
	}
1024 1025
	data += count;
	mv88e6xxx_atu_vtu_get_stats(chip, port, data);
1026
	mv88e6xxx_reg_unlock(chip);
1027 1028
}

1029 1030
static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
					uint64_t *data)
1031
{
V
Vivien Didelot 已提交
1032
	struct mv88e6xxx_chip *chip = ds->priv;
1033 1034
	int ret;

1035
	mv88e6xxx_reg_lock(chip);
1036

1037
	ret = mv88e6xxx_stats_snapshot(chip, port);
1038
	mv88e6xxx_reg_unlock(chip);
1039 1040

	if (ret < 0)
1041
		return;
1042 1043

	mv88e6xxx_get_stats(chip, port, data);
1044

1045 1046
}

1047
static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
1048 1049 1050 1051
{
	return 32 * sizeof(u16);
}

1052 1053
static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
			       struct ethtool_regs *regs, void *_p)
1054
{
V
Vivien Didelot 已提交
1055
	struct mv88e6xxx_chip *chip = ds->priv;
1056 1057
	int err;
	u16 reg;
1058 1059 1060
	u16 *p = _p;
	int i;

1061
	regs->version = chip->info->prod_num;
1062 1063 1064

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

1065
	mv88e6xxx_reg_lock(chip);
1066

1067 1068
	for (i = 0; i < 32; i++) {

1069 1070 1071
		err = mv88e6xxx_port_read(chip, port, i, &reg);
		if (!err)
			p[i] = reg;
1072
	}
1073

1074
	mv88e6xxx_reg_unlock(chip);
1075 1076
}

V
Vivien Didelot 已提交
1077 1078
static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
1079
{
1080 1081
	/* Nothing to do on the port's MAC */
	return 0;
1082 1083
}

V
Vivien Didelot 已提交
1084 1085
static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
1086
{
1087 1088
	/* Nothing to do on the port's MAC */
	return 0;
1089 1090
}

1091
static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
1092
{
1093 1094 1095
	struct dsa_switch *ds = NULL;
	struct net_device *br;
	u16 pvlan;
1096 1097
	int i;

1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117
	if (dev < DSA_MAX_SWITCHES)
		ds = chip->ds->dst->ds[dev];

	/* Prevent frames from unknown switch or port */
	if (!ds || port >= ds->num_ports)
		return 0;

	/* Frames from DSA links and CPU ports can egress any local port */
	if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
		return mv88e6xxx_port_mask(chip);

	br = ds->ports[port].bridge_dev;
	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.
	 */
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
		if (dsa_is_cpu_port(chip->ds, i) ||
		    dsa_is_dsa_port(chip->ds, i) ||
V
Vivien Didelot 已提交
1118
		    (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
1119 1120 1121 1122 1123
			pvlan |= BIT(i);

	return pvlan;
}

1124
static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
1125 1126
{
	u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
1127 1128 1129

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

1131
	return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
1132 1133
}

1134 1135
static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
					 u8 state)
1136
{
V
Vivien Didelot 已提交
1137
	struct mv88e6xxx_chip *chip = ds->priv;
1138
	int err;
1139

1140
	mv88e6xxx_reg_lock(chip);
1141
	err = mv88e6xxx_port_set_state(chip, port, state);
1142
	mv88e6xxx_reg_unlock(chip);
1143 1144

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

1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
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;
}

1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186
static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
{
	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++) {
		port = 0x1f;
		if (target < DSA_MAX_SWITCHES)
			if (chip->ds->rtable[target] != DSA_RTABLE_NONE)
				port = chip->ds->rtable[target];

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

1187 1188 1189 1190 1191 1192 1193
	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;
	}

1194 1195 1196 1197
	err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
	if (err)
		return err;

1198 1199 1200
	return 0;
}

1201 1202 1203 1204 1205 1206 1207 1208 1209
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;
}

1210 1211 1212 1213 1214 1215 1216 1217
static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->rmu_disable)
		return chip->info->ops->rmu_disable(chip);

	return 0;
}

1218 1219 1220 1221 1222 1223 1224 1225
static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->pot_clear)
		return chip->info->ops->pot_clear(chip);

	return 0;
}

1226 1227 1228 1229 1230 1231 1232 1233
static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->mgmt_rsvd2cpu)
		return chip->info->ops->mgmt_rsvd2cpu(chip);

	return 0;
}

1234 1235
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
1236 1237
	int err;

1238 1239 1240 1241
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

1242 1243 1244 1245
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

1246 1247 1248
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268
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;
}

1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281
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;
}

1282 1283 1284 1285 1286 1287 1288 1289 1290
static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
{
	u16 pvlan = 0;

	if (!mv88e6xxx_has_pvt(chip))
		return -EOPNOTSUPP;

	/* Skip the local source device, which uses in-chip port VLAN */
	if (dev != chip->ds->index)
1291
		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1292 1293 1294 1295

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

1296 1297
static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
{
1298 1299 1300
	int dev, port;
	int err;

1301 1302 1303 1304 1305 1306
	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.
	 */
1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319
	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;
1320 1321
}

1322 1323 1324 1325 1326
static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

1327
	mv88e6xxx_reg_lock(chip);
1328
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1329
	mv88e6xxx_reg_unlock(chip);
1330 1331

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

1335 1336 1337 1338 1339 1340 1341 1342
static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
{
	if (!chip->info->max_vid)
		return 0;

	return mv88e6xxx_g1_vtu_flush(chip);
}

1343 1344 1345 1346 1347 1348 1349 1350 1351
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);
}

1352 1353 1354 1355 1356 1357 1358 1359 1360
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);
}

1361
static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1362 1363
{
	DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1364
	struct mv88e6xxx_vtu_entry vlan;
1365
	int i, err;
1366 1367 1368

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

1369
	/* Set every FID bit used by the (un)bridged ports */
1370
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1371
		err = mv88e6xxx_port_get_fid(chip, i, fid);
1372 1373 1374 1375 1376 1377
		if (err)
			return err;

		set_bit(*fid, fid_bitmap);
	}

1378
	/* Set every FID bit used by the VLAN entries */
1379 1380 1381
	vlan.vid = chip->info->max_vid;
	vlan.valid = false;

1382
	do {
1383
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1384 1385 1386 1387 1388 1389 1390
		if (err)
			return err;

		if (!vlan.valid)
			break;

		set_bit(vlan.fid, fid_bitmap);
1391
	} while (vlan.vid < chip->info->max_vid);
1392 1393 1394 1395 1396

	/* 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);
1397
	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1398 1399 1400
		return -ENOSPC;

	/* Clear the database */
1401
	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1402 1403
}

1404 1405
static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
			     struct mv88e6xxx_vtu_entry *entry, bool new)
1406 1407 1408 1409
{
	int err;

	if (!vid)
1410
		return -EOPNOTSUPP;
1411

1412 1413
	entry->vid = vid - 1;
	entry->valid = false;
1414

1415
	err = mv88e6xxx_vtu_getnext(chip, entry);
1416 1417 1418
	if (err)
		return err;

1419 1420
	if (entry->vid == vid && entry->valid)
		return 0;
1421

1422 1423 1424 1425 1426 1427 1428
	if (new) {
		int i;

		/* Initialize a fresh VLAN entry */
		memset(entry, 0, sizeof(*entry));
		entry->vid = vid;

1429
		/* Exclude all ports */
1430
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1431
			entry->member[i] =
1432
				MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1433 1434

		return mv88e6xxx_atu_new(chip, &entry->fid);
1435 1436
	}

1437 1438
	/* switchdev expects -EOPNOTSUPP to honor software VLANs */
	return -EOPNOTSUPP;
1439 1440
}

1441 1442 1443
static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
					u16 vid_begin, u16 vid_end)
{
V
Vivien Didelot 已提交
1444
	struct mv88e6xxx_chip *chip = ds->priv;
1445
	struct mv88e6xxx_vtu_entry vlan;
1446 1447
	int i, err;

1448 1449 1450 1451
	/* 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;

1452 1453 1454
	if (!vid_begin)
		return -EOPNOTSUPP;

1455 1456 1457
	vlan.vid = vid_begin - 1;
	vlan.valid = false;

1458
	do {
1459
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1460
		if (err)
1461
			return err;
1462 1463 1464 1465 1466 1467 1468

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

1469
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1470 1471 1472
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

1473
			if (!ds->ports[i].slave)
1474 1475
				continue;

1476
			if (vlan.member[i] ==
1477
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1478 1479
				continue;

V
Vivien Didelot 已提交
1480
			if (dsa_to_port(ds, i)->bridge_dev ==
1481
			    ds->ports[port].bridge_dev)
1482 1483
				break; /* same bridge, check next VLAN */

V
Vivien Didelot 已提交
1484
			if (!dsa_to_port(ds, i)->bridge_dev)
1485 1486
				continue;

1487 1488
			dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
				port, vlan.vid, i,
V
Vivien Didelot 已提交
1489
				netdev_name(dsa_to_port(ds, i)->bridge_dev));
1490
			return -EOPNOTSUPP;
1491 1492 1493
		}
	} while (vlan.vid < vid_end);

1494
	return 0;
1495 1496
}

1497 1498
static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
					 bool vlan_filtering)
1499
{
V
Vivien Didelot 已提交
1500
	struct mv88e6xxx_chip *chip = ds->priv;
1501 1502
	u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
		MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
1503
	int err;
1504

1505
	if (!chip->info->max_vid)
1506 1507
		return -EOPNOTSUPP;

1508
	mv88e6xxx_reg_lock(chip);
1509
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1510
	mv88e6xxx_reg_unlock(chip);
1511

1512
	return err;
1513 1514
}

1515 1516
static int
mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1517
			    const struct switchdev_obj_port_vlan *vlan)
1518
{
V
Vivien Didelot 已提交
1519
	struct mv88e6xxx_chip *chip = ds->priv;
1520 1521
	int err;

1522
	if (!chip->info->max_vid)
1523 1524
		return -EOPNOTSUPP;

1525 1526 1527
	/* 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.
	 */
1528
	mv88e6xxx_reg_lock(chip);
1529 1530
	err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
					   vlan->vid_end);
1531
	mv88e6xxx_reg_unlock(chip);
1532

1533 1534 1535
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */
1536
	return err;
1537 1538
}

1539 1540 1541 1542 1543
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;
1544 1545
	struct mv88e6xxx_vtu_entry vlan;
	u16 fid;
1546 1547 1548
	int err;

	/* Null VLAN ID corresponds to the port private database */
1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566
	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;
	}
1567 1568 1569 1570 1571

	entry.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
	ether_addr_copy(entry.mac, addr);
	eth_addr_dec(entry.mac);

1572
	err = mv88e6xxx_g1_atu_getnext(chip, fid, &entry);
1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592
	if (err)
		return err;

	/* Initialize a fresh ATU entry if it isn't found */
	if (entry.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED ||
	    !ether_addr_equal(entry.mac, addr)) {
		memset(&entry, 0, sizeof(entry));
		ether_addr_copy(entry.mac, addr);
	}

	/* Purge the ATU entry only if no port is using it anymore */
	if (state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED) {
		entry.portvec &= ~BIT(port);
		if (!entry.portvec)
			entry.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
	} else {
		entry.portvec |= BIT(port);
		entry.state = state;
	}

1593
	return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry);
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
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;
}

1619
static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
1620
				    u16 vid, u8 member)
1621
{
1622
	struct mv88e6xxx_vtu_entry vlan;
1623 1624
	int err;

1625
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
1626
	if (err)
1627
		return err;
1628

1629 1630 1631
	if (vlan.valid && vlan.member[port] == member)
		return 0;
	vlan.valid = true;
1632
	vlan.member[port] = member;
1633

1634 1635 1636 1637 1638
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
	if (err)
		return err;

	return mv88e6xxx_broadcast_setup(chip, vid);
1639 1640
}

1641
static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1642
				    const struct switchdev_obj_port_vlan *vlan)
1643
{
V
Vivien Didelot 已提交
1644
	struct mv88e6xxx_chip *chip = ds->priv;
1645 1646
	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1647
	u8 member;
1648 1649
	u16 vid;

1650
	if (!chip->info->max_vid)
1651 1652
		return;

1653
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1654
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1655
	else if (untagged)
1656
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
1657
	else
1658
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
1659

1660
	mv88e6xxx_reg_lock(chip);
1661

1662
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
1663
		if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
1664 1665
			dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
				vid, untagged ? 'u' : 't');
1666

1667
	if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1668 1669
		dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
			vlan->vid_end);
1670

1671
	mv88e6xxx_reg_unlock(chip);
1672 1673
}

1674
static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
1675
				    int port, u16 vid)
1676
{
1677
	struct mv88e6xxx_vtu_entry vlan;
1678 1679
	int i, err;

1680
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1681
	if (err)
1682
		return err;
1683

1684
	/* Tell switchdev if this VLAN is handled in software */
1685
	if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1686
		return -EOPNOTSUPP;
1687

1688
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1689 1690

	/* keep the VLAN unless all ports are excluded */
1691
	vlan.valid = false;
1692
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1693 1694
		if (vlan.member[i] !=
		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
1695
			vlan.valid = true;
1696 1697 1698 1699
			break;
		}
	}

1700
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1701 1702 1703
	if (err)
		return err;

1704
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
1705 1706
}

1707 1708
static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
				   const struct switchdev_obj_port_vlan *vlan)
1709
{
V
Vivien Didelot 已提交
1710
	struct mv88e6xxx_chip *chip = ds->priv;
1711 1712 1713
	u16 pvid, vid;
	int err = 0;

1714
	if (!chip->info->max_vid)
1715 1716
		return -EOPNOTSUPP;

1717
	mv88e6xxx_reg_lock(chip);
1718

1719
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
1720 1721 1722
	if (err)
		goto unlock;

1723
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1724
		err = _mv88e6xxx_port_vlan_del(chip, port, vid);
1725 1726 1727 1728
		if (err)
			goto unlock;

		if (vid == pvid) {
1729
			err = mv88e6xxx_port_set_pvid(chip, port, 0);
1730 1731 1732 1733 1734
			if (err)
				goto unlock;
		}
	}

1735
unlock:
1736
	mv88e6xxx_reg_unlock(chip);
1737 1738 1739 1740

	return err;
}

1741 1742
static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
				  const unsigned char *addr, u16 vid)
1743
{
V
Vivien Didelot 已提交
1744
	struct mv88e6xxx_chip *chip = ds->priv;
1745
	int err;
1746

1747
	mv88e6xxx_reg_lock(chip);
1748 1749
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1750
	mv88e6xxx_reg_unlock(chip);
1751 1752

	return err;
1753 1754
}

1755
static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1756
				  const unsigned char *addr, u16 vid)
1757
{
V
Vivien Didelot 已提交
1758
	struct mv88e6xxx_chip *chip = ds->priv;
1759
	int err;
1760

1761
	mv88e6xxx_reg_lock(chip);
1762
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1763
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
1764
	mv88e6xxx_reg_unlock(chip);
1765

1766
	return err;
1767 1768
}

1769 1770
static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
				      u16 fid, u16 vid, int port,
1771
				      dsa_fdb_dump_cb_t *cb, void *data)
1772
{
1773
	struct mv88e6xxx_atu_entry addr;
1774
	bool is_static;
1775 1776
	int err;

1777
	addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1778
	eth_broadcast_addr(addr.mac);
1779 1780

	do {
1781
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
1782
		if (err)
1783
			return err;
1784

1785
		if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
1786 1787
			break;

1788
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
1789 1790
			continue;

1791 1792
		if (!is_unicast_ether_addr(addr.mac))
			continue;
1793

1794 1795 1796
		is_static = (addr.state ==
			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
		err = cb(addr.mac, vid, is_static, data);
1797 1798
		if (err)
			return err;
1799 1800 1801 1802 1803
	} while (!is_broadcast_ether_addr(addr.mac));

	return err;
}

1804
static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1805
				  dsa_fdb_dump_cb_t *cb, void *data)
1806
{
1807
	struct mv88e6xxx_vtu_entry vlan;
1808
	u16 fid;
1809 1810
	int err;

1811
	/* Dump port's default Filtering Information Database (VLAN ID 0) */
1812
	err = mv88e6xxx_port_get_fid(chip, port, &fid);
1813
	if (err)
1814
		return err;
1815

1816
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
1817
	if (err)
1818
		return err;
1819

1820
	/* Dump VLANs' Filtering Information Databases */
1821 1822 1823
	vlan.vid = chip->info->max_vid;
	vlan.valid = false;

1824
	do {
1825
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1826
		if (err)
1827
			return err;
1828 1829 1830 1831

		if (!vlan.valid)
			break;

1832
		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1833
						 cb, data);
1834
		if (err)
1835
			return err;
1836
	} while (vlan.vid < chip->info->max_vid);
1837

1838 1839 1840 1841
	return err;
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1842
				   dsa_fdb_dump_cb_t *cb, void *data)
1843
{
V
Vivien Didelot 已提交
1844
	struct mv88e6xxx_chip *chip = ds->priv;
1845 1846
	int err;

1847
	mv88e6xxx_reg_lock(chip);
1848
	err = mv88e6xxx_port_db_dump(chip, port, cb, data);
1849
	mv88e6xxx_reg_unlock(chip);
1850

1851
	return err;
1852 1853
}

1854 1855
static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
				struct net_device *br)
1856
{
1857
	struct dsa_switch *ds;
1858
	int port;
1859
	int dev;
1860
	int err;
1861

1862 1863 1864 1865
	/* Remap the Port VLAN of each local bridge group member */
	for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) {
		if (chip->ds->ports[port].bridge_dev == br) {
			err = mv88e6xxx_port_vlan_map(chip, port);
1866
			if (err)
1867
				return err;
1868 1869 1870
		}
	}

1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888
	if (!mv88e6xxx_has_pvt(chip))
		return 0;

	/* Remap the Port VLAN of each cross-chip bridge group member */
	for (dev = 0; dev < DSA_MAX_SWITCHES; ++dev) {
		ds = chip->ds->dst->ds[dev];
		if (!ds)
			break;

		for (port = 0; port < ds->num_ports; ++port) {
			if (ds->ports[port].bridge_dev == br) {
				err = mv88e6xxx_pvt_map(chip, dev, port);
				if (err)
					return err;
			}
		}
	}

1889 1890 1891 1892 1893 1894 1895 1896 1897
	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;

1898
	mv88e6xxx_reg_lock(chip);
1899
	err = mv88e6xxx_bridge_map(chip, br);
1900
	mv88e6xxx_reg_unlock(chip);
1901

1902
	return err;
1903 1904
}

1905 1906
static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
					struct net_device *br)
1907
{
V
Vivien Didelot 已提交
1908
	struct mv88e6xxx_chip *chip = ds->priv;
1909

1910
	mv88e6xxx_reg_lock(chip);
1911 1912 1913
	if (mv88e6xxx_bridge_map(chip, br) ||
	    mv88e6xxx_port_vlan_map(chip, port))
		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
1914
	mv88e6xxx_reg_unlock(chip);
1915 1916
}

1917 1918 1919 1920 1921 1922 1923 1924 1925
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;

	if (!mv88e6xxx_has_pvt(chip))
		return 0;

1926
	mv88e6xxx_reg_lock(chip);
1927
	err = mv88e6xxx_pvt_map(chip, dev, port);
1928
	mv88e6xxx_reg_unlock(chip);
1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940

	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;

	if (!mv88e6xxx_has_pvt(chip))
		return;

1941
	mv88e6xxx_reg_lock(chip);
1942 1943
	if (mv88e6xxx_pvt_map(chip, dev, port))
		dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
1944
	mv88e6xxx_reg_unlock(chip);
1945 1946
}

1947 1948 1949 1950 1951 1952 1953 1954
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->reset)
		return chip->info->ops->reset(chip);

	return 0;
}

1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967
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);
	}
}

1968
static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1969
{
1970
	int i, err;
1971

1972
	/* Set all ports to the Disabled state */
1973
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
1974
		err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
1975 1976
		if (err)
			return err;
1977 1978
	}

1979 1980 1981
	/* Wait for transmit queues to drain,
	 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
	 */
1982 1983
	usleep_range(2000, 4000);

1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994
	return 0;
}

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

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

1995
	mv88e6xxx_hardware_reset(chip);
1996

1997
	return mv88e6xxx_software_reset(chip);
1998 1999
}

2000
static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
2001 2002
				   enum mv88e6xxx_frame_mode frame,
				   enum mv88e6xxx_egress_mode egress, u16 etype)
2003 2004 2005
{
	int err;

2006 2007 2008 2009
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
2010 2011 2012
	if (err)
		return err;

2013 2014 2015 2016 2017 2018 2019 2020
	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;
2021 2022
}

2023
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2024
{
2025
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
2026
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2027
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2028
}
2029

2030 2031 2032
static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
2033
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2034
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2035
}
2036

2037 2038 2039 2040
static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port,
				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
2041 2042
				       MV88E6XXX_EGRESS_MODE_ETHERTYPE,
				       ETH_P_EDSA);
2043
}
2044

2045 2046 2047 2048
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);
2049

2050
	if (dsa_is_user_port(chip->ds, port))
2051
		return mv88e6xxx_set_port_mode_normal(chip, port);
2052

2053 2054 2055
	/* 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);
2056

2057 2058
	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
		return mv88e6xxx_set_port_mode_edsa(chip, port);
2059

2060
	return -EINVAL;
2061 2062
}

2063
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2064
{
2065
	bool message = dsa_is_dsa_port(chip->ds, port);
2066

2067
	return mv88e6xxx_port_set_message_port(chip, port, message);
2068
}
2069

2070
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2071
{
2072
	struct dsa_switch *ds = chip->ds;
2073
	bool flood;
2074

2075 2076 2077 2078 2079
	/* 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);
2080

2081
	return 0;
2082 2083
}

2084 2085 2086
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
2087 2088
	if (chip->info->ops->serdes_power)
		return chip->info->ops->serdes_power(chip, port, on);
2089

2090
	return 0;
2091 2092
}

2093 2094 2095 2096 2097 2098
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

2099
	upstream_port = dsa_upstream_port(ds, port);
2100 2101 2102 2103 2104 2105 2106
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122
	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,
							       upstream_port);
			if (err)
				return err;
		}
	}

2123 2124 2125
	return 0;
}

2126
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
2127
{
2128
	struct dsa_switch *ds = chip->ds;
2129
	int err;
2130
	u16 reg;
2131

2132 2133 2134
	chip->ports[port].chip = chip;
	chip->ports[port].port = port;

2135 2136 2137 2138 2139 2140 2141
	/* 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,
2142
					       PAUSE_OFF,
2143 2144 2145 2146
					       PHY_INTERFACE_MODE_NA);
	else
		err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
					       SPEED_UNFORCED, DUPLEX_UNFORCED,
2147
					       PAUSE_ON,
2148 2149 2150
					       PHY_INTERFACE_MODE_NA);
	if (err)
		return err;
2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165

	/* 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.
	 */
2166 2167 2168 2169
	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);
2170 2171
	if (err)
		return err;
2172

2173
	err = mv88e6xxx_setup_port_mode(chip, port);
2174 2175
	if (err)
		return err;
2176

2177
	err = mv88e6xxx_setup_egress_floods(chip, port);
2178 2179 2180
	if (err)
		return err;

2181 2182 2183
	/* Enable the SERDES interface for DSA and CPU ports. Normal
	 * ports SERDES are enabled when the port is enabled, thus
	 * saving a bit of power.
2184
	 */
2185 2186 2187 2188 2189
	if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
		err = mv88e6xxx_serdes_power(chip, port, true);
		if (err)
			return err;
	}
2190

2191
	/* Port Control 2: don't force a good FCS, set the maximum frame size to
2192
	 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
2193 2194 2195
	 * 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.
2196
	 */
2197 2198 2199
	err = mv88e6xxx_port_set_map_da(chip, port);
	if (err)
		return err;
2200

2201 2202 2203
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
2204

2205
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
2206
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
2207 2208 2209
	if (err)
		return err;

2210 2211
	if (chip->info->ops->port_set_jumbo_size) {
		err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
2212 2213 2214 2215
		if (err)
			return err;
	}

2216 2217 2218 2219 2220
	/* 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.
	 */
2221
	reg = 1 << port;
2222 2223
	/* Disable learning for CPU port */
	if (dsa_is_cpu_port(ds, port))
2224
		reg = 0;
2225

2226 2227
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
2228 2229
	if (err)
		return err;
2230 2231

	/* Egress rate control 2: disable egress rate control. */
2232 2233
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
				   0x0000);
2234 2235
	if (err)
		return err;
2236

2237 2238
	if (chip->info->ops->port_pause_limit) {
		err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
2239 2240
		if (err)
			return err;
2241
	}
2242

2243 2244 2245 2246 2247 2248
	if (chip->info->ops->port_disable_learn_limit) {
		err = chip->info->ops->port_disable_learn_limit(chip, port);
		if (err)
			return err;
	}

2249 2250
	if (chip->info->ops->port_disable_pri_override) {
		err = chip->info->ops->port_disable_pri_override(chip, port);
2251 2252
		if (err)
			return err;
2253
	}
2254

2255 2256
	if (chip->info->ops->port_tag_remap) {
		err = chip->info->ops->port_tag_remap(chip, port);
2257 2258
		if (err)
			return err;
2259 2260
	}

2261 2262
	if (chip->info->ops->port_egress_rate_limiting) {
		err = chip->info->ops->port_egress_rate_limiting(chip, port);
2263 2264
		if (err)
			return err;
2265 2266
	}

2267
	err = mv88e6xxx_setup_message_port(chip, port);
2268 2269
	if (err)
		return err;
2270

2271
	/* Port based VLAN map: give each port the same default address
2272 2273
	 * database, and allow bidirectional communication between the
	 * CPU and DSA port(s), and the other ports.
2274
	 */
2275
	err = mv88e6xxx_port_set_fid(chip, port, 0);
2276 2277
	if (err)
		return err;
2278

2279
	err = mv88e6xxx_port_vlan_map(chip, port);
2280 2281
	if (err)
		return err;
2282 2283 2284 2285

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

2289 2290 2291 2292
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
2293
	int err;
2294

2295
	mv88e6xxx_reg_lock(chip);
2296

2297
	err = mv88e6xxx_serdes_power(chip, port, true);
2298 2299 2300 2301

	if (!err && chip->info->ops->serdes_irq_setup)
		err = chip->info->ops->serdes_irq_setup(chip, port);

2302
	mv88e6xxx_reg_unlock(chip);
2303 2304 2305 2306

	return err;
}

2307
static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port)
2308 2309 2310
{
	struct mv88e6xxx_chip *chip = ds->priv;

2311
	mv88e6xxx_reg_lock(chip);
2312

2313 2314 2315
	if (mv88e6xxx_port_set_state(chip, port, BR_STATE_DISABLED))
		dev_err(chip->dev, "failed to disable port\n");

2316 2317 2318
	if (chip->info->ops->serdes_irq_free)
		chip->info->ops->serdes_irq_free(chip, port);

2319 2320
	if (mv88e6xxx_serdes_power(chip, port, false))
		dev_err(chip->dev, "failed to power off SERDES\n");
2321

2322
	mv88e6xxx_reg_unlock(chip);
2323 2324
}

2325 2326 2327
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
2328
	struct mv88e6xxx_chip *chip = ds->priv;
2329 2330
	int err;

2331
	mv88e6xxx_reg_lock(chip);
2332
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2333
	mv88e6xxx_reg_unlock(chip);
2334 2335 2336 2337

	return err;
}

2338
static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
2339
{
2340
	int err;
2341

2342
	/* Initialize the statistics unit */
2343 2344 2345 2346 2347
	if (chip->info->ops->stats_set_histogram) {
		err = chip->info->ops->stats_set_histogram(chip);
		if (err)
			return err;
	}
2348

2349
	return mv88e6xxx_g1_stats_clear(chip);
2350 2351
}

2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452
/* The mv88e6390 has some hidden registers used for debug and
 * development. The errata also makes use of them.
 */
static int mv88e6390_hidden_write(struct mv88e6xxx_chip *chip, int port,
				  int reg, u16 val)
{
	u16 ctrl;
	int err;

	err = mv88e6xxx_port_write(chip, PORT_RESERVED_1A_DATA_PORT,
				   PORT_RESERVED_1A, val);
	if (err)
		return err;

	ctrl = PORT_RESERVED_1A_BUSY | PORT_RESERVED_1A_WRITE |
	       PORT_RESERVED_1A_BLOCK | port << PORT_RESERVED_1A_PORT_SHIFT |
	       reg;

	return mv88e6xxx_port_write(chip, PORT_RESERVED_1A_CTRL_PORT,
				    PORT_RESERVED_1A, ctrl);
}

static int mv88e6390_hidden_wait(struct mv88e6xxx_chip *chip)
{
	return mv88e6xxx_wait(chip, PORT_RESERVED_1A_CTRL_PORT,
			      PORT_RESERVED_1A, PORT_RESERVED_1A_BUSY);
}


static int mv88e6390_hidden_read(struct mv88e6xxx_chip *chip, int port,
				  int reg, u16 *val)
{
	u16 ctrl;
	int err;

	ctrl = PORT_RESERVED_1A_BUSY | PORT_RESERVED_1A_READ |
	       PORT_RESERVED_1A_BLOCK | port << PORT_RESERVED_1A_PORT_SHIFT |
	       reg;

	err = mv88e6xxx_port_write(chip, PORT_RESERVED_1A_CTRL_PORT,
				   PORT_RESERVED_1A, ctrl);
	if (err)
		return err;

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

	return 	mv88e6xxx_port_read(chip, PORT_RESERVED_1A_DATA_PORT,
				    PORT_RESERVED_1A, val);
}

/* 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++) {
		err = mv88e6390_hidden_read(chip, port, 0, &val);
		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++) {
		err = mv88e6390_hidden_write(chip, port, 0, 0x01c0);
		if (err)
			return err;
	}

	return mv88e6xxx_software_reset(chip);
}

2453
static int mv88e6xxx_setup(struct dsa_switch *ds)
2454
{
V
Vivien Didelot 已提交
2455
	struct mv88e6xxx_chip *chip = ds->priv;
2456
	u8 cmode;
2457
	int err;
2458 2459
	int i;

2460
	chip->ds = ds;
2461
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
2462

2463
	mv88e6xxx_reg_lock(chip);
2464

2465 2466 2467 2468 2469 2470
	if (chip->info->ops->setup_errata) {
		err = chip->info->ops->setup_errata(chip);
		if (err)
			goto unlock;
	}

2471 2472 2473 2474 2475
	/* 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)
2476
				goto unlock;
2477 2478 2479 2480 2481

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

2482
	/* Setup Switch Port Registers */
2483
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2484 2485 2486 2487 2488 2489 2490 2491 2492 2493
		if (dsa_is_unused_port(ds, i)) {
			err = mv88e6xxx_port_set_state(chip, i,
						       BR_STATE_DISABLED);
			if (err)
				goto unlock;

			err = mv88e6xxx_serdes_power(chip, i, false);
			if (err)
				goto unlock;

2494
			continue;
2495
		}
2496

2497 2498 2499 2500 2501
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

2502 2503 2504 2505
	err = mv88e6xxx_irl_setup(chip);
	if (err)
		goto unlock;

2506 2507 2508 2509
	err = mv88e6xxx_mac_setup(chip);
	if (err)
		goto unlock;

2510 2511 2512 2513
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

2514 2515 2516 2517
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

2518 2519 2520 2521
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

2522 2523 2524 2525
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

2526 2527 2528 2529
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

2530 2531 2532 2533
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

2534 2535 2536 2537
	err = mv88e6xxx_rmu_setup(chip);
	if (err)
		goto unlock;

2538 2539 2540
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
2541

2542 2543 2544 2545
	err = mv88e6xxx_trunk_setup(chip);
	if (err)
		goto unlock;

2546 2547 2548 2549
	err = mv88e6xxx_devmap_setup(chip);
	if (err)
		goto unlock;

2550 2551 2552 2553
	err = mv88e6xxx_pri_setup(chip);
	if (err)
		goto unlock;

2554
	/* Setup PTP Hardware Clock and timestamping */
2555 2556 2557 2558
	if (chip->info->ptp_support) {
		err = mv88e6xxx_ptp_setup(chip);
		if (err)
			goto unlock;
2559 2560 2561 2562

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
2563 2564
	}

2565 2566 2567 2568
	err = mv88e6xxx_stats_setup(chip);
	if (err)
		goto unlock;

2569
unlock:
2570
	mv88e6xxx_reg_unlock(chip);
2571

2572
	return err;
2573 2574
}

2575
static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
2576
{
2577 2578
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2579 2580
	u16 val;
	int err;
2581

2582 2583 2584
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

2585
	mv88e6xxx_reg_lock(chip);
2586
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
2587
	mv88e6xxx_reg_unlock(chip);
2588

2589
	if (reg == MII_PHYSID2) {
2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605
		/* 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;
2606 2607
	}

2608
	return err ? err : val;
2609 2610
}

2611
static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
2612
{
2613 2614
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2615
	int err;
2616

2617 2618 2619
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

2620
	mv88e6xxx_reg_lock(chip);
2621
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
2622
	mv88e6xxx_reg_unlock(chip);
2623 2624

	return err;
2625 2626
}

2627
static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
2628 2629
				   struct device_node *np,
				   bool external)
2630 2631
{
	static int index;
2632
	struct mv88e6xxx_mdio_bus *mdio_bus;
2633 2634 2635
	struct mii_bus *bus;
	int err;

2636
	if (external) {
2637
		mv88e6xxx_reg_lock(chip);
2638
		err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
2639
		mv88e6xxx_reg_unlock(chip);
2640 2641 2642 2643 2644

		if (err)
			return err;
	}

2645
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
2646 2647 2648
	if (!bus)
		return -ENOMEM;

2649
	mdio_bus = bus->priv;
2650
	mdio_bus->bus = bus;
2651
	mdio_bus->chip = chip;
2652 2653
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
2654

2655 2656
	if (np) {
		bus->name = np->full_name;
2657
		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
2658 2659 2660 2661 2662 2663 2664
	} 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;
2665
	bus->parent = chip->dev;
2666

2667 2668 2669 2670 2671 2672
	if (!external) {
		err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
		if (err)
			return err;
	}

2673
	err = of_mdiobus_register(bus, np);
2674
	if (err) {
2675
		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
2676
		mv88e6xxx_g2_irq_mdio_free(chip, bus);
2677
		return err;
2678
	}
2679 2680 2681 2682 2683

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

	return 0;
2686
}
2687

2688 2689 2690 2691 2692
static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
	{ .compatible = "marvell,mv88e6xxx-mdio-external",
	  .data = (void *)true },
	{ },
};
2693

2694 2695 2696 2697 2698 2699 2700 2701 2702
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;

2703 2704 2705
		if (!mdio_bus->external)
			mv88e6xxx_g2_irq_mdio_free(chip, bus);

2706 2707 2708 2709
		mdiobus_unregister(bus);
	}
}

2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733
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);
2734 2735
			if (err) {
				mv88e6xxx_mdios_unregister(chip);
2736
				return err;
2737
			}
2738 2739 2740 2741
		}
	}

	return 0;
2742 2743
}

2744 2745
static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
2746
	struct mv88e6xxx_chip *chip = ds->priv;
2747 2748 2749 2750 2751 2752 2753

	return chip->eeprom_len;
}

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

2757 2758
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
2759

2760
	mv88e6xxx_reg_lock(chip);
2761
	err = chip->info->ops->get_eeprom(chip, eeprom, data);
2762
	mv88e6xxx_reg_unlock(chip);
2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774

	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 已提交
2775
	struct mv88e6xxx_chip *chip = ds->priv;
2776 2777
	int err;

2778 2779 2780
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

2781 2782 2783
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

2784
	mv88e6xxx_reg_lock(chip);
2785
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
2786
	mv88e6xxx_reg_unlock(chip);
2787 2788 2789 2790

	return err;
}

2791
static const struct mv88e6xxx_ops mv88e6085_ops = {
2792
	/* MV88E6XXX_FAMILY_6097 */
2793 2794
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2795
	.irl_init_all = mv88e6352_g2_irl_init_all,
2796
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2797 2798
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2799
	.port_set_link = mv88e6xxx_port_set_link,
2800
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2801
	.port_set_speed = mv88e6185_port_set_speed,
2802
	.port_tag_remap = mv88e6095_port_tag_remap,
2803
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2804
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2805
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2806
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2807
	.port_pause_limit = mv88e6097_port_pause_limit,
2808
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2809
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2810
	.port_link_state = mv88e6352_port_link_state,
2811
	.port_get_cmode = mv88e6185_port_get_cmode,
2812
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2813
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2814 2815
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2816
	.stats_get_stats = mv88e6095_stats_get_stats,
2817 2818
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2819
	.watchdog_ops = &mv88e6097_watchdog_ops,
2820
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2821
	.pot_clear = mv88e6xxx_g2_pot_clear,
2822 2823
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2824
	.reset = mv88e6185_g1_reset,
2825
	.rmu_disable = mv88e6085_g1_rmu_disable,
2826
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2827
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2828
	.phylink_validate = mv88e6185_phylink_validate,
2829 2830 2831
};

static const struct mv88e6xxx_ops mv88e6095_ops = {
2832
	/* MV88E6XXX_FAMILY_6095 */
2833 2834
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2835
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2836 2837
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2838
	.port_set_link = mv88e6xxx_port_set_link,
2839
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2840
	.port_set_speed = mv88e6185_port_set_speed,
2841
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2842
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2843
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2844
	.port_link_state = mv88e6185_port_link_state,
2845
	.port_get_cmode = mv88e6185_port_get_cmode,
2846
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2847
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2848 2849
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2850
	.stats_get_stats = mv88e6095_stats_get_stats,
2851
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2852 2853
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2854
	.reset = mv88e6185_g1_reset,
2855
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2856
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2857
	.phylink_validate = mv88e6185_phylink_validate,
2858 2859
};

2860
static const struct mv88e6xxx_ops mv88e6097_ops = {
2861
	/* MV88E6XXX_FAMILY_6097 */
2862 2863
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2864
	.irl_init_all = mv88e6352_g2_irl_init_all,
2865 2866 2867 2868 2869 2870
	.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,
2871
	.port_tag_remap = mv88e6095_port_tag_remap,
2872
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2873
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2874
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2875
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2876
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
2877
	.port_pause_limit = mv88e6097_port_pause_limit,
2878
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2879
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2880
	.port_link_state = mv88e6352_port_link_state,
2881
	.port_get_cmode = mv88e6185_port_get_cmode,
2882
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2883
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2884 2885 2886
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
	.stats_get_stats = mv88e6095_stats_get_stats,
2887 2888
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2889
	.watchdog_ops = &mv88e6097_watchdog_ops,
2890
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2891
	.pot_clear = mv88e6xxx_g2_pot_clear,
2892
	.reset = mv88e6352_g1_reset,
2893
	.rmu_disable = mv88e6085_g1_rmu_disable,
2894
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2895
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2896
	.phylink_validate = mv88e6185_phylink_validate,
2897 2898
};

2899
static const struct mv88e6xxx_ops mv88e6123_ops = {
2900
	/* MV88E6XXX_FAMILY_6165 */
2901 2902
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2903
	.irl_init_all = mv88e6352_g2_irl_init_all,
2904
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2905 2906
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2907
	.port_set_link = mv88e6xxx_port_set_link,
2908
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2909
	.port_set_speed = mv88e6185_port_set_speed,
2910
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2911
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2912
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2913
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2914
	.port_link_state = mv88e6352_port_link_state,
2915
	.port_get_cmode = mv88e6185_port_get_cmode,
2916
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2917
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2918 2919
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2920
	.stats_get_stats = mv88e6095_stats_get_stats,
2921 2922
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2923
	.watchdog_ops = &mv88e6097_watchdog_ops,
2924
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2925
	.pot_clear = mv88e6xxx_g2_pot_clear,
2926
	.reset = mv88e6352_g1_reset,
2927
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2928
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2929
	.phylink_validate = mv88e6185_phylink_validate,
2930 2931 2932
};

static const struct mv88e6xxx_ops mv88e6131_ops = {
2933
	/* MV88E6XXX_FAMILY_6185 */
2934 2935
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2936
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2937 2938
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2939
	.port_set_link = mv88e6xxx_port_set_link,
2940
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2941
	.port_set_speed = mv88e6185_port_set_speed,
2942
	.port_tag_remap = mv88e6095_port_tag_remap,
2943
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2944
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2945
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2946
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2947
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2948
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2949
	.port_pause_limit = mv88e6097_port_pause_limit,
2950
	.port_set_pause = mv88e6185_port_set_pause,
2951
	.port_link_state = mv88e6352_port_link_state,
2952
	.port_get_cmode = mv88e6185_port_get_cmode,
2953
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2954
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2955 2956
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2957
	.stats_get_stats = mv88e6095_stats_get_stats,
2958 2959
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2960
	.watchdog_ops = &mv88e6097_watchdog_ops,
2961
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2962
	.ppu_enable = mv88e6185_g1_ppu_enable,
2963
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
2964
	.ppu_disable = mv88e6185_g1_ppu_disable,
2965
	.reset = mv88e6185_g1_reset,
2966
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2967
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2968
	.phylink_validate = mv88e6185_phylink_validate,
2969 2970
};

2971 2972
static const struct mv88e6xxx_ops mv88e6141_ops = {
	/* MV88E6XXX_FAMILY_6341 */
2973 2974
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2975
	.irl_init_all = mv88e6352_g2_irl_init_all,
2976 2977 2978 2979 2980 2981 2982 2983
	.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,
2984
	.port_set_speed = mv88e6341_port_set_speed,
2985
	.port_max_speed_mode = mv88e6341_port_max_speed_mode,
2986 2987 2988 2989
	.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,
2990
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2991
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2992
	.port_pause_limit = mv88e6097_port_pause_limit,
2993 2994
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2995
	.port_link_state = mv88e6352_port_link_state,
2996
	.port_get_cmode = mv88e6352_port_get_cmode,
2997
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
2998
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2999 3000 3001
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
3002 3003
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3004 3005
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
3006
	.pot_clear = mv88e6xxx_g2_pot_clear,
3007
	.reset = mv88e6352_g1_reset,
3008
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3009
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3010
	.serdes_power = mv88e6341_serdes_power,
3011
	.gpio_ops = &mv88e6352_gpio_ops,
3012
	.phylink_validate = mv88e6341_phylink_validate,
3013 3014
};

3015
static const struct mv88e6xxx_ops mv88e6161_ops = {
3016
	/* MV88E6XXX_FAMILY_6165 */
3017 3018
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3019
	.irl_init_all = mv88e6352_g2_irl_init_all,
3020
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3021 3022
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3023
	.port_set_link = mv88e6xxx_port_set_link,
3024
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3025
	.port_set_speed = mv88e6185_port_set_speed,
3026
	.port_tag_remap = mv88e6095_port_tag_remap,
3027
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3028
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3029
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3030
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3031
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3032
	.port_pause_limit = mv88e6097_port_pause_limit,
3033
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3034
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3035
	.port_link_state = mv88e6352_port_link_state,
3036
	.port_get_cmode = mv88e6185_port_get_cmode,
3037
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3038
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3039 3040
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3041
	.stats_get_stats = mv88e6095_stats_get_stats,
3042 3043
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3044
	.watchdog_ops = &mv88e6097_watchdog_ops,
3045
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3046
	.pot_clear = mv88e6xxx_g2_pot_clear,
3047
	.reset = mv88e6352_g1_reset,
3048
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3049
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3050
	.avb_ops = &mv88e6165_avb_ops,
3051
	.ptp_ops = &mv88e6165_ptp_ops,
3052
	.phylink_validate = mv88e6185_phylink_validate,
3053 3054 3055
};

static const struct mv88e6xxx_ops mv88e6165_ops = {
3056
	/* MV88E6XXX_FAMILY_6165 */
3057 3058
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3059
	.irl_init_all = mv88e6352_g2_irl_init_all,
3060
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3061 3062
	.phy_read = mv88e6165_phy_read,
	.phy_write = mv88e6165_phy_write,
3063
	.port_set_link = mv88e6xxx_port_set_link,
3064
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3065
	.port_set_speed = mv88e6185_port_set_speed,
3066
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3067
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3068
	.port_link_state = mv88e6352_port_link_state,
3069
	.port_get_cmode = mv88e6185_port_get_cmode,
3070
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3071
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3072 3073
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3074
	.stats_get_stats = mv88e6095_stats_get_stats,
3075 3076
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3077
	.watchdog_ops = &mv88e6097_watchdog_ops,
3078
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3079
	.pot_clear = mv88e6xxx_g2_pot_clear,
3080
	.reset = mv88e6352_g1_reset,
3081
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3082
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3083
	.avb_ops = &mv88e6165_avb_ops,
3084
	.ptp_ops = &mv88e6165_ptp_ops,
3085
	.phylink_validate = mv88e6185_phylink_validate,
3086 3087 3088
};

static const struct mv88e6xxx_ops mv88e6171_ops = {
3089
	/* MV88E6XXX_FAMILY_6351 */
3090 3091
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3092
	.irl_init_all = mv88e6352_g2_irl_init_all,
3093
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3094 3095
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3096
	.port_set_link = mv88e6xxx_port_set_link,
3097
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3098
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3099
	.port_set_speed = mv88e6185_port_set_speed,
3100
	.port_tag_remap = mv88e6095_port_tag_remap,
3101
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3102
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3103
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3104
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3105
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3106
	.port_pause_limit = mv88e6097_port_pause_limit,
3107
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3108
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3109
	.port_link_state = mv88e6352_port_link_state,
3110
	.port_get_cmode = mv88e6352_port_get_cmode,
3111
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3112
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3113 3114
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3115
	.stats_get_stats = mv88e6095_stats_get_stats,
3116 3117
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3118
	.watchdog_ops = &mv88e6097_watchdog_ops,
3119
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3120
	.pot_clear = mv88e6xxx_g2_pot_clear,
3121
	.reset = mv88e6352_g1_reset,
3122
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3123
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3124
	.phylink_validate = mv88e6185_phylink_validate,
3125 3126 3127
};

static const struct mv88e6xxx_ops mv88e6172_ops = {
3128
	/* MV88E6XXX_FAMILY_6352 */
3129 3130
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3131
	.irl_init_all = mv88e6352_g2_irl_init_all,
3132 3133
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3134
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3135 3136
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3137
	.port_set_link = mv88e6xxx_port_set_link,
3138
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3139
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3140
	.port_set_speed = mv88e6352_port_set_speed,
3141
	.port_tag_remap = mv88e6095_port_tag_remap,
3142
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3143
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3144
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3145
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3146
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3147
	.port_pause_limit = mv88e6097_port_pause_limit,
3148
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3149
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3150
	.port_link_state = mv88e6352_port_link_state,
3151
	.port_get_cmode = mv88e6352_port_get_cmode,
3152
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3153
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3154 3155
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3156
	.stats_get_stats = mv88e6095_stats_get_stats,
3157 3158
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3159
	.watchdog_ops = &mv88e6097_watchdog_ops,
3160
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3161
	.pot_clear = mv88e6xxx_g2_pot_clear,
3162
	.reset = mv88e6352_g1_reset,
3163
	.rmu_disable = mv88e6352_g1_rmu_disable,
3164
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3165
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3166
	.serdes_power = mv88e6352_serdes_power,
3167
	.gpio_ops = &mv88e6352_gpio_ops,
3168
	.phylink_validate = mv88e6352_phylink_validate,
3169 3170 3171
};

static const struct mv88e6xxx_ops mv88e6175_ops = {
3172
	/* MV88E6XXX_FAMILY_6351 */
3173 3174
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3175
	.irl_init_all = mv88e6352_g2_irl_init_all,
3176
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3177 3178
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3179
	.port_set_link = mv88e6xxx_port_set_link,
3180
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3181
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3182
	.port_set_speed = mv88e6185_port_set_speed,
3183
	.port_tag_remap = mv88e6095_port_tag_remap,
3184
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3185
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3186
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3187
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3188
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3189
	.port_pause_limit = mv88e6097_port_pause_limit,
3190
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3191
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3192
	.port_link_state = mv88e6352_port_link_state,
3193
	.port_get_cmode = mv88e6352_port_get_cmode,
3194
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3195
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3196 3197
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3198
	.stats_get_stats = mv88e6095_stats_get_stats,
3199 3200
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3201
	.watchdog_ops = &mv88e6097_watchdog_ops,
3202
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3203
	.pot_clear = mv88e6xxx_g2_pot_clear,
3204
	.reset = mv88e6352_g1_reset,
3205
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3206
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3207
	.phylink_validate = mv88e6185_phylink_validate,
3208 3209 3210
};

static const struct mv88e6xxx_ops mv88e6176_ops = {
3211
	/* MV88E6XXX_FAMILY_6352 */
3212 3213
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3214
	.irl_init_all = mv88e6352_g2_irl_init_all,
3215 3216
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3217
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3218 3219
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3220
	.port_set_link = mv88e6xxx_port_set_link,
3221
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3222
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3223
	.port_set_speed = mv88e6352_port_set_speed,
3224
	.port_tag_remap = mv88e6095_port_tag_remap,
3225
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3226
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3227
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3228
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3229
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3230
	.port_pause_limit = mv88e6097_port_pause_limit,
3231
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3232
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3233
	.port_link_state = mv88e6352_port_link_state,
3234
	.port_get_cmode = mv88e6352_port_get_cmode,
3235
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3236
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3237 3238
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3239
	.stats_get_stats = mv88e6095_stats_get_stats,
3240 3241
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3242
	.watchdog_ops = &mv88e6097_watchdog_ops,
3243
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3244
	.pot_clear = mv88e6xxx_g2_pot_clear,
3245
	.reset = mv88e6352_g1_reset,
3246
	.rmu_disable = mv88e6352_g1_rmu_disable,
3247
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3248
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3249
	.serdes_power = mv88e6352_serdes_power,
3250 3251
	.serdes_irq_setup = mv88e6352_serdes_irq_setup,
	.serdes_irq_free = mv88e6352_serdes_irq_free,
3252
	.gpio_ops = &mv88e6352_gpio_ops,
3253
	.phylink_validate = mv88e6352_phylink_validate,
3254 3255 3256
};

static const struct mv88e6xxx_ops mv88e6185_ops = {
3257
	/* MV88E6XXX_FAMILY_6185 */
3258 3259
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3260
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3261 3262
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3263
	.port_set_link = mv88e6xxx_port_set_link,
3264
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3265
	.port_set_speed = mv88e6185_port_set_speed,
3266
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
3267
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
3268
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
3269
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
3270
	.port_set_pause = mv88e6185_port_set_pause,
3271
	.port_link_state = mv88e6185_port_link_state,
3272
	.port_get_cmode = mv88e6185_port_get_cmode,
3273
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3274
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3275 3276
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3277
	.stats_get_stats = mv88e6095_stats_get_stats,
3278 3279
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3280
	.watchdog_ops = &mv88e6097_watchdog_ops,
3281
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3282
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
3283 3284
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
3285
	.reset = mv88e6185_g1_reset,
3286
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3287
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3288
	.phylink_validate = mv88e6185_phylink_validate,
3289 3290
};

3291
static const struct mv88e6xxx_ops mv88e6190_ops = {
3292
	/* MV88E6XXX_FAMILY_6390 */
3293
	.setup_errata = mv88e6390_setup_errata,
3294
	.irl_init_all = mv88e6390_g2_irl_init_all,
3295 3296
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3297 3298 3299 3300 3301 3302 3303
	.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,
3304
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
3305
	.port_tag_remap = mv88e6390_port_tag_remap,
3306
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3307
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3308
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3309
	.port_pause_limit = mv88e6390_port_pause_limit,
3310
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3311
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3312
	.port_link_state = mv88e6352_port_link_state,
3313
	.port_get_cmode = mv88e6352_port_get_cmode,
3314
	.port_set_cmode = mv88e6390_port_set_cmode,
3315
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3316
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3317 3318
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3319
	.stats_get_stats = mv88e6390_stats_get_stats,
3320 3321
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3322
	.watchdog_ops = &mv88e6390_watchdog_ops,
3323
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3324
	.pot_clear = mv88e6xxx_g2_pot_clear,
3325
	.reset = mv88e6352_g1_reset,
3326
	.rmu_disable = mv88e6390_g1_rmu_disable,
3327 3328
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3329
	.serdes_power = mv88e6390_serdes_power,
3330 3331
	.serdes_irq_setup = mv88e6390_serdes_irq_setup,
	.serdes_irq_free = mv88e6390_serdes_irq_free,
3332
	.gpio_ops = &mv88e6352_gpio_ops,
3333
	.phylink_validate = mv88e6390_phylink_validate,
3334 3335 3336
};

static const struct mv88e6xxx_ops mv88e6190x_ops = {
3337
	/* MV88E6XXX_FAMILY_6390 */
3338
	.setup_errata = mv88e6390_setup_errata,
3339
	.irl_init_all = mv88e6390_g2_irl_init_all,
3340 3341
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3342 3343 3344 3345 3346 3347 3348
	.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,
3349
	.port_max_speed_mode = mv88e6390x_port_max_speed_mode,
3350
	.port_tag_remap = mv88e6390_port_tag_remap,
3351
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3352
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3353
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3354
	.port_pause_limit = mv88e6390_port_pause_limit,
3355
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3356
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3357
	.port_link_state = mv88e6352_port_link_state,
3358
	.port_get_cmode = mv88e6352_port_get_cmode,
3359
	.port_set_cmode = mv88e6390x_port_set_cmode,
3360
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3361
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3362 3363
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3364
	.stats_get_stats = mv88e6390_stats_get_stats,
3365 3366
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3367
	.watchdog_ops = &mv88e6390_watchdog_ops,
3368
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3369
	.pot_clear = mv88e6xxx_g2_pot_clear,
3370
	.reset = mv88e6352_g1_reset,
3371
	.rmu_disable = mv88e6390_g1_rmu_disable,
3372 3373
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3374
	.serdes_power = mv88e6390x_serdes_power,
3375 3376
	.serdes_irq_setup = mv88e6390x_serdes_irq_setup,
	.serdes_irq_free = mv88e6390x_serdes_irq_free,
3377
	.gpio_ops = &mv88e6352_gpio_ops,
3378
	.phylink_validate = mv88e6390x_phylink_validate,
3379 3380 3381
};

static const struct mv88e6xxx_ops mv88e6191_ops = {
3382
	/* MV88E6XXX_FAMILY_6390 */
3383
	.setup_errata = mv88e6390_setup_errata,
3384
	.irl_init_all = mv88e6390_g2_irl_init_all,
3385 3386
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3387 3388 3389 3390 3391 3392 3393
	.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,
3394
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
3395
	.port_tag_remap = mv88e6390_port_tag_remap,
3396
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3397
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3398
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3399
	.port_pause_limit = mv88e6390_port_pause_limit,
3400
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3401
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3402
	.port_link_state = mv88e6352_port_link_state,
3403
	.port_get_cmode = mv88e6352_port_get_cmode,
3404
	.port_set_cmode = mv88e6390_port_set_cmode,
3405
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3406
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3407 3408
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3409
	.stats_get_stats = mv88e6390_stats_get_stats,
3410 3411
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3412
	.watchdog_ops = &mv88e6390_watchdog_ops,
3413
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3414
	.pot_clear = mv88e6xxx_g2_pot_clear,
3415
	.reset = mv88e6352_g1_reset,
3416
	.rmu_disable = mv88e6390_g1_rmu_disable,
3417 3418
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3419
	.serdes_power = mv88e6390_serdes_power,
3420 3421
	.serdes_irq_setup = mv88e6390_serdes_irq_setup,
	.serdes_irq_free = mv88e6390_serdes_irq_free,
3422 3423
	.avb_ops = &mv88e6390_avb_ops,
	.ptp_ops = &mv88e6352_ptp_ops,
3424
	.phylink_validate = mv88e6390_phylink_validate,
3425 3426
};

3427
static const struct mv88e6xxx_ops mv88e6240_ops = {
3428
	/* MV88E6XXX_FAMILY_6352 */
3429 3430
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3431
	.irl_init_all = mv88e6352_g2_irl_init_all,
3432 3433
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3434
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3435 3436
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3437
	.port_set_link = mv88e6xxx_port_set_link,
3438
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3439
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3440
	.port_set_speed = mv88e6352_port_set_speed,
3441
	.port_tag_remap = mv88e6095_port_tag_remap,
3442
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3443
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3444
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3445
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3446
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3447
	.port_pause_limit = mv88e6097_port_pause_limit,
3448
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3449
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3450
	.port_link_state = mv88e6352_port_link_state,
3451
	.port_get_cmode = mv88e6352_port_get_cmode,
3452
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3453
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3454 3455
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3456
	.stats_get_stats = mv88e6095_stats_get_stats,
3457 3458
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3459
	.watchdog_ops = &mv88e6097_watchdog_ops,
3460
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3461
	.pot_clear = mv88e6xxx_g2_pot_clear,
3462
	.reset = mv88e6352_g1_reset,
3463
	.rmu_disable = mv88e6352_g1_rmu_disable,
3464
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3465
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3466
	.serdes_power = mv88e6352_serdes_power,
3467 3468
	.serdes_irq_setup = mv88e6352_serdes_irq_setup,
	.serdes_irq_free = mv88e6352_serdes_irq_free,
3469
	.gpio_ops = &mv88e6352_gpio_ops,
3470
	.avb_ops = &mv88e6352_avb_ops,
3471
	.ptp_ops = &mv88e6352_ptp_ops,
3472
	.phylink_validate = mv88e6352_phylink_validate,
3473 3474
};

3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512
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,
	.phylink_validate = mv88e6065_phylink_validate,
};

3513
static const struct mv88e6xxx_ops mv88e6290_ops = {
3514
	/* MV88E6XXX_FAMILY_6390 */
3515
	.setup_errata = mv88e6390_setup_errata,
3516
	.irl_init_all = mv88e6390_g2_irl_init_all,
3517 3518
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3519 3520 3521 3522 3523 3524 3525
	.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,
3526
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
3527
	.port_tag_remap = mv88e6390_port_tag_remap,
3528
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3529
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3530
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3531
	.port_pause_limit = mv88e6390_port_pause_limit,
3532
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3533
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3534
	.port_link_state = mv88e6352_port_link_state,
3535
	.port_get_cmode = mv88e6352_port_get_cmode,
3536
	.port_set_cmode = mv88e6390_port_set_cmode,
3537
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3538
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3539 3540
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3541
	.stats_get_stats = mv88e6390_stats_get_stats,
3542 3543
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3544
	.watchdog_ops = &mv88e6390_watchdog_ops,
3545
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3546
	.pot_clear = mv88e6xxx_g2_pot_clear,
3547
	.reset = mv88e6352_g1_reset,
3548
	.rmu_disable = mv88e6390_g1_rmu_disable,
3549 3550
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3551
	.serdes_power = mv88e6390_serdes_power,
3552 3553
	.serdes_irq_setup = mv88e6390_serdes_irq_setup,
	.serdes_irq_free = mv88e6390_serdes_irq_free,
3554
	.gpio_ops = &mv88e6352_gpio_ops,
3555
	.avb_ops = &mv88e6390_avb_ops,
3556
	.ptp_ops = &mv88e6352_ptp_ops,
3557
	.phylink_validate = mv88e6390_phylink_validate,
3558 3559
};

3560
static const struct mv88e6xxx_ops mv88e6320_ops = {
3561
	/* MV88E6XXX_FAMILY_6320 */
3562 3563
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3564
	.irl_init_all = mv88e6352_g2_irl_init_all,
3565 3566
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3567
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3568 3569
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3570
	.port_set_link = mv88e6xxx_port_set_link,
3571
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3572
	.port_set_speed = mv88e6185_port_set_speed,
3573
	.port_tag_remap = mv88e6095_port_tag_remap,
3574
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3575
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3576
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3577
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3578
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3579
	.port_pause_limit = mv88e6097_port_pause_limit,
3580
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3581
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3582
	.port_link_state = mv88e6352_port_link_state,
3583
	.port_get_cmode = mv88e6352_port_get_cmode,
3584
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3585
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3586 3587
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3588
	.stats_get_stats = mv88e6320_stats_get_stats,
3589 3590
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3591
	.watchdog_ops = &mv88e6390_watchdog_ops,
3592
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3593
	.pot_clear = mv88e6xxx_g2_pot_clear,
3594
	.reset = mv88e6352_g1_reset,
3595
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3596
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3597
	.gpio_ops = &mv88e6352_gpio_ops,
3598
	.avb_ops = &mv88e6352_avb_ops,
3599
	.ptp_ops = &mv88e6352_ptp_ops,
3600
	.phylink_validate = mv88e6185_phylink_validate,
3601 3602 3603
};

static const struct mv88e6xxx_ops mv88e6321_ops = {
3604
	/* MV88E6XXX_FAMILY_6320 */
3605 3606
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3607
	.irl_init_all = mv88e6352_g2_irl_init_all,
3608 3609
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3610
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3611 3612
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3613
	.port_set_link = mv88e6xxx_port_set_link,
3614
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3615
	.port_set_speed = mv88e6185_port_set_speed,
3616
	.port_tag_remap = mv88e6095_port_tag_remap,
3617
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3618
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3619
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3620
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3621
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3622
	.port_pause_limit = mv88e6097_port_pause_limit,
3623
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3624
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3625
	.port_link_state = mv88e6352_port_link_state,
3626
	.port_get_cmode = mv88e6352_port_get_cmode,
3627
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3628
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3629 3630
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3631
	.stats_get_stats = mv88e6320_stats_get_stats,
3632 3633
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3634
	.watchdog_ops = &mv88e6390_watchdog_ops,
3635
	.reset = mv88e6352_g1_reset,
3636
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3637
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3638
	.gpio_ops = &mv88e6352_gpio_ops,
3639
	.avb_ops = &mv88e6352_avb_ops,
3640
	.ptp_ops = &mv88e6352_ptp_ops,
3641
	.phylink_validate = mv88e6185_phylink_validate,
3642 3643
};

3644 3645
static const struct mv88e6xxx_ops mv88e6341_ops = {
	/* MV88E6XXX_FAMILY_6341 */
3646 3647
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3648
	.irl_init_all = mv88e6352_g2_irl_init_all,
3649 3650 3651 3652 3653 3654 3655 3656
	.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,
3657
	.port_set_speed = mv88e6341_port_set_speed,
3658
	.port_max_speed_mode = mv88e6341_port_max_speed_mode,
3659 3660 3661 3662
	.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,
3663
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3664
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3665
	.port_pause_limit = mv88e6097_port_pause_limit,
3666 3667
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3668
	.port_link_state = mv88e6352_port_link_state,
3669
	.port_get_cmode = mv88e6352_port_get_cmode,
3670
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3671
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3672 3673 3674
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
3675 3676
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3677 3678
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
3679
	.pot_clear = mv88e6xxx_g2_pot_clear,
3680
	.reset = mv88e6352_g1_reset,
3681
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3682
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3683
	.serdes_power = mv88e6341_serdes_power,
3684
	.gpio_ops = &mv88e6352_gpio_ops,
3685
	.avb_ops = &mv88e6390_avb_ops,
3686
	.ptp_ops = &mv88e6352_ptp_ops,
3687
	.phylink_validate = mv88e6341_phylink_validate,
3688 3689
};

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

static const struct mv88e6xxx_ops mv88e6351_ops = {
3730
	/* MV88E6XXX_FAMILY_6351 */
3731 3732
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3733
	.irl_init_all = mv88e6352_g2_irl_init_all,
3734
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3735 3736
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3737
	.port_set_link = mv88e6xxx_port_set_link,
3738
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3739
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3740
	.port_set_speed = mv88e6185_port_set_speed,
3741
	.port_tag_remap = mv88e6095_port_tag_remap,
3742
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3743
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3744
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3745
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3746
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3747
	.port_pause_limit = mv88e6097_port_pause_limit,
3748
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3749
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3750
	.port_link_state = mv88e6352_port_link_state,
3751
	.port_get_cmode = mv88e6352_port_get_cmode,
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
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3764
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3765
	.avb_ops = &mv88e6352_avb_ops,
3766
	.ptp_ops = &mv88e6352_ptp_ops,
3767
	.phylink_validate = mv88e6185_phylink_validate,
3768 3769 3770
};

static const struct mv88e6xxx_ops mv88e6352_ops = {
3771
	/* MV88E6XXX_FAMILY_6352 */
3772 3773
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3774
	.irl_init_all = mv88e6352_g2_irl_init_all,
3775 3776
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3777
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3778 3779
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3780
	.port_set_link = mv88e6xxx_port_set_link,
3781
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3782
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3783
	.port_set_speed = mv88e6352_port_set_speed,
3784
	.port_tag_remap = mv88e6095_port_tag_remap,
3785
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3786
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3787
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3788
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3789
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3790
	.port_pause_limit = mv88e6097_port_pause_limit,
3791
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3792
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3793
	.port_link_state = mv88e6352_port_link_state,
3794
	.port_get_cmode = mv88e6352_port_get_cmode,
3795
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3796
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3797 3798
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3799
	.stats_get_stats = mv88e6095_stats_get_stats,
3800 3801
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3802
	.watchdog_ops = &mv88e6097_watchdog_ops,
3803
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3804
	.pot_clear = mv88e6xxx_g2_pot_clear,
3805
	.reset = mv88e6352_g1_reset,
3806
	.rmu_disable = mv88e6352_g1_rmu_disable,
3807
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3808
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3809
	.serdes_power = mv88e6352_serdes_power,
3810 3811
	.serdes_irq_setup = mv88e6352_serdes_irq_setup,
	.serdes_irq_free = mv88e6352_serdes_irq_free,
3812
	.gpio_ops = &mv88e6352_gpio_ops,
3813
	.avb_ops = &mv88e6352_avb_ops,
3814
	.ptp_ops = &mv88e6352_ptp_ops,
3815 3816 3817
	.serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
	.serdes_get_strings = mv88e6352_serdes_get_strings,
	.serdes_get_stats = mv88e6352_serdes_get_stats,
3818
	.phylink_validate = mv88e6352_phylink_validate,
3819 3820
};

3821
static const struct mv88e6xxx_ops mv88e6390_ops = {
3822
	/* MV88E6XXX_FAMILY_6390 */
3823
	.setup_errata = mv88e6390_setup_errata,
3824
	.irl_init_all = mv88e6390_g2_irl_init_all,
3825 3826
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3827 3828 3829 3830 3831 3832 3833
	.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,
3834
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
3835
	.port_tag_remap = mv88e6390_port_tag_remap,
3836
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3837
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3838
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3839
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3840
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3841
	.port_pause_limit = mv88e6390_port_pause_limit,
3842
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3843
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3844
	.port_link_state = mv88e6352_port_link_state,
3845
	.port_get_cmode = mv88e6352_port_get_cmode,
3846
	.port_set_cmode = mv88e6390_port_set_cmode,
3847
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3848
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3849 3850
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3851
	.stats_get_stats = mv88e6390_stats_get_stats,
3852 3853
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3854
	.watchdog_ops = &mv88e6390_watchdog_ops,
3855
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3856
	.pot_clear = mv88e6xxx_g2_pot_clear,
3857
	.reset = mv88e6352_g1_reset,
3858
	.rmu_disable = mv88e6390_g1_rmu_disable,
3859 3860
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3861
	.serdes_power = mv88e6390_serdes_power,
3862 3863
	.serdes_irq_setup = mv88e6390_serdes_irq_setup,
	.serdes_irq_free = mv88e6390_serdes_irq_free,
3864
	.gpio_ops = &mv88e6352_gpio_ops,
3865
	.avb_ops = &mv88e6390_avb_ops,
3866
	.ptp_ops = &mv88e6352_ptp_ops,
3867
	.phylink_validate = mv88e6390_phylink_validate,
3868 3869 3870
};

static const struct mv88e6xxx_ops mv88e6390x_ops = {
3871
	/* MV88E6XXX_FAMILY_6390 */
3872
	.setup_errata = mv88e6390_setup_errata,
3873
	.irl_init_all = mv88e6390_g2_irl_init_all,
3874 3875
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3876 3877 3878 3879 3880 3881 3882
	.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,
3883
	.port_max_speed_mode = mv88e6390x_port_max_speed_mode,
3884
	.port_tag_remap = mv88e6390_port_tag_remap,
3885
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3886
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3887
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3888
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3889
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
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
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3897
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3898 3899
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3900
	.stats_get_stats = mv88e6390_stats_get_stats,
3901 3902
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3903
	.watchdog_ops = &mv88e6390_watchdog_ops,
3904
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3905
	.pot_clear = mv88e6xxx_g2_pot_clear,
3906
	.reset = mv88e6352_g1_reset,
3907
	.rmu_disable = mv88e6390_g1_rmu_disable,
3908 3909
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3910
	.serdes_power = mv88e6390x_serdes_power,
3911 3912
	.serdes_irq_setup = mv88e6390x_serdes_irq_setup,
	.serdes_irq_free = mv88e6390x_serdes_irq_free,
3913
	.gpio_ops = &mv88e6352_gpio_ops,
3914
	.avb_ops = &mv88e6390_avb_ops,
3915
	.ptp_ops = &mv88e6352_ptp_ops,
3916
	.phylink_validate = mv88e6390x_phylink_validate,
3917 3918
};

3919 3920
static const struct mv88e6xxx_info mv88e6xxx_table[] = {
	[MV88E6085] = {
3921
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
3922 3923 3924 3925
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6085",
		.num_databases = 4096,
		.num_ports = 10,
3926
		.num_internal_phys = 5,
3927
		.max_vid = 4095,
3928
		.port_base_addr = 0x10,
3929
		.phy_base_addr = 0x0,
3930
		.global1_addr = 0x1b,
3931
		.global2_addr = 0x1c,
3932
		.age_time_coeff = 15000,
3933
		.g1_irqs = 8,
3934
		.g2_irqs = 10,
3935
		.atu_move_port_mask = 0xf,
3936
		.pvt = true,
3937
		.multi_chip = true,
3938
		.tag_protocol = DSA_TAG_PROTO_DSA,
3939
		.ops = &mv88e6085_ops,
3940 3941 3942
	},

	[MV88E6095] = {
3943
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
3944 3945 3946 3947
		.family = MV88E6XXX_FAMILY_6095,
		.name = "Marvell 88E6095/88E6095F",
		.num_databases = 256,
		.num_ports = 11,
3948
		.num_internal_phys = 0,
3949
		.max_vid = 4095,
3950
		.port_base_addr = 0x10,
3951
		.phy_base_addr = 0x0,
3952
		.global1_addr = 0x1b,
3953
		.global2_addr = 0x1c,
3954
		.age_time_coeff = 15000,
3955
		.g1_irqs = 8,
3956
		.atu_move_port_mask = 0xf,
3957
		.multi_chip = true,
3958
		.tag_protocol = DSA_TAG_PROTO_DSA,
3959
		.ops = &mv88e6095_ops,
3960 3961
	},

3962
	[MV88E6097] = {
3963
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
3964 3965 3966 3967
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6097/88E6097F",
		.num_databases = 4096,
		.num_ports = 11,
3968
		.num_internal_phys = 8,
3969
		.max_vid = 4095,
3970
		.port_base_addr = 0x10,
3971
		.phy_base_addr = 0x0,
3972
		.global1_addr = 0x1b,
3973
		.global2_addr = 0x1c,
3974
		.age_time_coeff = 15000,
3975
		.g1_irqs = 8,
3976
		.g2_irqs = 10,
3977
		.atu_move_port_mask = 0xf,
3978
		.pvt = true,
3979
		.multi_chip = true,
3980
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3981 3982 3983
		.ops = &mv88e6097_ops,
	},

3984
	[MV88E6123] = {
3985
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
3986 3987 3988 3989
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6123",
		.num_databases = 4096,
		.num_ports = 3,
3990
		.num_internal_phys = 5,
3991
		.max_vid = 4095,
3992
		.port_base_addr = 0x10,
3993
		.phy_base_addr = 0x0,
3994
		.global1_addr = 0x1b,
3995
		.global2_addr = 0x1c,
3996
		.age_time_coeff = 15000,
3997
		.g1_irqs = 9,
3998
		.g2_irqs = 10,
3999
		.atu_move_port_mask = 0xf,
4000
		.pvt = true,
4001
		.multi_chip = true,
4002
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4003
		.ops = &mv88e6123_ops,
4004 4005 4006
	},

	[MV88E6131] = {
4007
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
4008 4009 4010 4011
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6131",
		.num_databases = 256,
		.num_ports = 8,
4012
		.num_internal_phys = 0,
4013
		.max_vid = 4095,
4014
		.port_base_addr = 0x10,
4015
		.phy_base_addr = 0x0,
4016
		.global1_addr = 0x1b,
4017
		.global2_addr = 0x1c,
4018
		.age_time_coeff = 15000,
4019
		.g1_irqs = 9,
4020
		.atu_move_port_mask = 0xf,
4021
		.multi_chip = true,
4022
		.tag_protocol = DSA_TAG_PROTO_DSA,
4023
		.ops = &mv88e6131_ops,
4024 4025
	},

4026
	[MV88E6141] = {
4027
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
4028
		.family = MV88E6XXX_FAMILY_6341,
4029
		.name = "Marvell 88E6141",
4030 4031
		.num_databases = 4096,
		.num_ports = 6,
4032
		.num_internal_phys = 5,
4033
		.num_gpio = 11,
4034
		.max_vid = 4095,
4035
		.port_base_addr = 0x10,
4036
		.phy_base_addr = 0x10,
4037
		.global1_addr = 0x1b,
4038
		.global2_addr = 0x1c,
4039 4040
		.age_time_coeff = 3750,
		.atu_move_port_mask = 0x1f,
4041
		.g1_irqs = 9,
4042
		.g2_irqs = 10,
4043
		.pvt = true,
4044
		.multi_chip = true,
4045 4046 4047 4048
		.tag_protocol = DSA_TAG_PROTO_EDSA,
		.ops = &mv88e6141_ops,
	},

4049
	[MV88E6161] = {
4050
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
4051 4052 4053 4054
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6161",
		.num_databases = 4096,
		.num_ports = 6,
4055
		.num_internal_phys = 5,
4056
		.max_vid = 4095,
4057
		.port_base_addr = 0x10,
4058
		.phy_base_addr = 0x0,
4059
		.global1_addr = 0x1b,
4060
		.global2_addr = 0x1c,
4061
		.age_time_coeff = 15000,
4062
		.g1_irqs = 9,
4063
		.g2_irqs = 10,
4064
		.atu_move_port_mask = 0xf,
4065
		.pvt = true,
4066
		.multi_chip = true,
4067
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4068
		.ptp_support = true,
4069
		.ops = &mv88e6161_ops,
4070 4071 4072
	},

	[MV88E6165] = {
4073
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
4074 4075 4076 4077
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6165",
		.num_databases = 4096,
		.num_ports = 6,
4078
		.num_internal_phys = 0,
4079
		.max_vid = 4095,
4080
		.port_base_addr = 0x10,
4081
		.phy_base_addr = 0x0,
4082
		.global1_addr = 0x1b,
4083
		.global2_addr = 0x1c,
4084
		.age_time_coeff = 15000,
4085
		.g1_irqs = 9,
4086
		.g2_irqs = 10,
4087
		.atu_move_port_mask = 0xf,
4088
		.pvt = true,
4089
		.multi_chip = true,
4090
		.tag_protocol = DSA_TAG_PROTO_DSA,
4091
		.ptp_support = true,
4092
		.ops = &mv88e6165_ops,
4093 4094 4095
	},

	[MV88E6171] = {
4096
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
4097 4098 4099 4100
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6171",
		.num_databases = 4096,
		.num_ports = 7,
4101
		.num_internal_phys = 5,
4102
		.max_vid = 4095,
4103
		.port_base_addr = 0x10,
4104
		.phy_base_addr = 0x0,
4105
		.global1_addr = 0x1b,
4106
		.global2_addr = 0x1c,
4107
		.age_time_coeff = 15000,
4108
		.g1_irqs = 9,
4109
		.g2_irqs = 10,
4110
		.atu_move_port_mask = 0xf,
4111
		.pvt = true,
4112
		.multi_chip = true,
4113
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4114
		.ops = &mv88e6171_ops,
4115 4116 4117
	},

	[MV88E6172] = {
4118
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
4119 4120 4121 4122
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6172",
		.num_databases = 4096,
		.num_ports = 7,
4123
		.num_internal_phys = 5,
4124
		.num_gpio = 15,
4125
		.max_vid = 4095,
4126
		.port_base_addr = 0x10,
4127
		.phy_base_addr = 0x0,
4128
		.global1_addr = 0x1b,
4129
		.global2_addr = 0x1c,
4130
		.age_time_coeff = 15000,
4131
		.g1_irqs = 9,
4132
		.g2_irqs = 10,
4133
		.atu_move_port_mask = 0xf,
4134
		.pvt = true,
4135
		.multi_chip = true,
4136
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4137
		.ops = &mv88e6172_ops,
4138 4139 4140
	},

	[MV88E6175] = {
4141
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
4142 4143 4144 4145
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6175",
		.num_databases = 4096,
		.num_ports = 7,
4146
		.num_internal_phys = 5,
4147
		.max_vid = 4095,
4148
		.port_base_addr = 0x10,
4149
		.phy_base_addr = 0x0,
4150
		.global1_addr = 0x1b,
4151
		.global2_addr = 0x1c,
4152
		.age_time_coeff = 15000,
4153
		.g1_irqs = 9,
4154
		.g2_irqs = 10,
4155
		.atu_move_port_mask = 0xf,
4156
		.pvt = true,
4157
		.multi_chip = true,
4158
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4159
		.ops = &mv88e6175_ops,
4160 4161 4162
	},

	[MV88E6176] = {
4163
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
4164 4165 4166 4167
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6176",
		.num_databases = 4096,
		.num_ports = 7,
4168
		.num_internal_phys = 5,
4169
		.num_gpio = 15,
4170
		.max_vid = 4095,
4171
		.port_base_addr = 0x10,
4172
		.phy_base_addr = 0x0,
4173
		.global1_addr = 0x1b,
4174
		.global2_addr = 0x1c,
4175
		.age_time_coeff = 15000,
4176
		.g1_irqs = 9,
4177
		.g2_irqs = 10,
4178
		.atu_move_port_mask = 0xf,
4179
		.pvt = true,
4180
		.multi_chip = true,
4181
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4182
		.ops = &mv88e6176_ops,
4183 4184 4185
	},

	[MV88E6185] = {
4186
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
4187 4188 4189 4190
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6185",
		.num_databases = 256,
		.num_ports = 10,
4191
		.num_internal_phys = 0,
4192
		.max_vid = 4095,
4193
		.port_base_addr = 0x10,
4194
		.phy_base_addr = 0x0,
4195
		.global1_addr = 0x1b,
4196
		.global2_addr = 0x1c,
4197
		.age_time_coeff = 15000,
4198
		.g1_irqs = 8,
4199
		.atu_move_port_mask = 0xf,
4200
		.multi_chip = true,
4201
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4202
		.ops = &mv88e6185_ops,
4203 4204
	},

4205
	[MV88E6190] = {
4206
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
4207 4208 4209 4210
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4211
		.num_internal_phys = 9,
4212
		.num_gpio = 16,
4213
		.max_vid = 8191,
4214
		.port_base_addr = 0x0,
4215
		.phy_base_addr = 0x0,
4216
		.global1_addr = 0x1b,
4217
		.global2_addr = 0x1c,
4218
		.tag_protocol = DSA_TAG_PROTO_DSA,
4219
		.age_time_coeff = 3750,
4220
		.g1_irqs = 9,
4221
		.g2_irqs = 14,
4222
		.pvt = true,
4223
		.multi_chip = true,
4224
		.atu_move_port_mask = 0x1f,
4225 4226 4227 4228
		.ops = &mv88e6190_ops,
	},

	[MV88E6190X] = {
4229
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
4230 4231 4232 4233
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4234
		.num_internal_phys = 9,
4235
		.num_gpio = 16,
4236
		.max_vid = 8191,
4237
		.port_base_addr = 0x0,
4238
		.phy_base_addr = 0x0,
4239
		.global1_addr = 0x1b,
4240
		.global2_addr = 0x1c,
4241
		.age_time_coeff = 3750,
4242
		.g1_irqs = 9,
4243
		.g2_irqs = 14,
4244
		.atu_move_port_mask = 0x1f,
4245
		.pvt = true,
4246
		.multi_chip = true,
4247
		.tag_protocol = DSA_TAG_PROTO_DSA,
4248 4249 4250 4251
		.ops = &mv88e6190x_ops,
	},

	[MV88E6191] = {
4252
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
4253 4254 4255 4256
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6191",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4257
		.num_internal_phys = 9,
4258
		.max_vid = 8191,
4259
		.port_base_addr = 0x0,
4260
		.phy_base_addr = 0x0,
4261
		.global1_addr = 0x1b,
4262
		.global2_addr = 0x1c,
4263
		.age_time_coeff = 3750,
4264
		.g1_irqs = 9,
4265
		.g2_irqs = 14,
4266
		.atu_move_port_mask = 0x1f,
4267
		.pvt = true,
4268
		.multi_chip = true,
4269
		.tag_protocol = DSA_TAG_PROTO_DSA,
4270
		.ptp_support = true,
4271
		.ops = &mv88e6191_ops,
4272 4273
	},

4274
	[MV88E6240] = {
4275
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
4276 4277 4278 4279
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6240",
		.num_databases = 4096,
		.num_ports = 7,
4280
		.num_internal_phys = 5,
4281
		.num_gpio = 15,
4282
		.max_vid = 4095,
4283
		.port_base_addr = 0x10,
4284
		.phy_base_addr = 0x0,
4285
		.global1_addr = 0x1b,
4286
		.global2_addr = 0x1c,
4287
		.age_time_coeff = 15000,
4288
		.g1_irqs = 9,
4289
		.g2_irqs = 10,
4290
		.atu_move_port_mask = 0xf,
4291
		.pvt = true,
4292
		.multi_chip = true,
4293
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4294
		.ptp_support = true,
4295
		.ops = &mv88e6240_ops,
4296 4297
	},

4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318
	[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,
		.ops = &mv88e6250_ops,
	},

4319
	[MV88E6290] = {
4320
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
4321 4322 4323 4324
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6290",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4325
		.num_internal_phys = 9,
4326
		.num_gpio = 16,
4327
		.max_vid = 8191,
4328
		.port_base_addr = 0x0,
4329
		.phy_base_addr = 0x0,
4330
		.global1_addr = 0x1b,
4331
		.global2_addr = 0x1c,
4332
		.age_time_coeff = 3750,
4333
		.g1_irqs = 9,
4334
		.g2_irqs = 14,
4335
		.atu_move_port_mask = 0x1f,
4336
		.pvt = true,
4337
		.multi_chip = true,
4338
		.tag_protocol = DSA_TAG_PROTO_DSA,
4339
		.ptp_support = true,
4340 4341 4342
		.ops = &mv88e6290_ops,
	},

4343
	[MV88E6320] = {
4344
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
4345 4346 4347 4348
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6320",
		.num_databases = 4096,
		.num_ports = 7,
4349
		.num_internal_phys = 5,
4350
		.num_gpio = 15,
4351
		.max_vid = 4095,
4352
		.port_base_addr = 0x10,
4353
		.phy_base_addr = 0x0,
4354
		.global1_addr = 0x1b,
4355
		.global2_addr = 0x1c,
4356
		.age_time_coeff = 15000,
4357
		.g1_irqs = 8,
4358
		.g2_irqs = 10,
4359
		.atu_move_port_mask = 0xf,
4360
		.pvt = true,
4361
		.multi_chip = true,
4362
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4363
		.ptp_support = true,
4364
		.ops = &mv88e6320_ops,
4365 4366 4367
	},

	[MV88E6321] = {
4368
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
4369 4370 4371 4372
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6321",
		.num_databases = 4096,
		.num_ports = 7,
4373
		.num_internal_phys = 5,
4374
		.num_gpio = 15,
4375
		.max_vid = 4095,
4376
		.port_base_addr = 0x10,
4377
		.phy_base_addr = 0x0,
4378
		.global1_addr = 0x1b,
4379
		.global2_addr = 0x1c,
4380
		.age_time_coeff = 15000,
4381
		.g1_irqs = 8,
4382
		.g2_irqs = 10,
4383
		.atu_move_port_mask = 0xf,
4384
		.multi_chip = true,
4385
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4386
		.ptp_support = true,
4387
		.ops = &mv88e6321_ops,
4388 4389
	},

4390
	[MV88E6341] = {
4391
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
4392 4393 4394
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
4395
		.num_internal_phys = 5,
4396
		.num_ports = 6,
4397
		.num_gpio = 11,
4398
		.max_vid = 4095,
4399
		.port_base_addr = 0x10,
4400
		.phy_base_addr = 0x10,
4401
		.global1_addr = 0x1b,
4402
		.global2_addr = 0x1c,
4403
		.age_time_coeff = 3750,
4404
		.atu_move_port_mask = 0x1f,
4405
		.g1_irqs = 9,
4406
		.g2_irqs = 10,
4407
		.pvt = true,
4408
		.multi_chip = true,
4409
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4410
		.ptp_support = true,
4411 4412 4413
		.ops = &mv88e6341_ops,
	},

4414
	[MV88E6350] = {
4415
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
4416 4417 4418 4419
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6350",
		.num_databases = 4096,
		.num_ports = 7,
4420
		.num_internal_phys = 5,
4421
		.max_vid = 4095,
4422
		.port_base_addr = 0x10,
4423
		.phy_base_addr = 0x0,
4424
		.global1_addr = 0x1b,
4425
		.global2_addr = 0x1c,
4426
		.age_time_coeff = 15000,
4427
		.g1_irqs = 9,
4428
		.g2_irqs = 10,
4429
		.atu_move_port_mask = 0xf,
4430
		.pvt = true,
4431
		.multi_chip = true,
4432
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4433
		.ops = &mv88e6350_ops,
4434 4435 4436
	},

	[MV88E6351] = {
4437
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
4438 4439 4440 4441
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6351",
		.num_databases = 4096,
		.num_ports = 7,
4442
		.num_internal_phys = 5,
4443
		.max_vid = 4095,
4444
		.port_base_addr = 0x10,
4445
		.phy_base_addr = 0x0,
4446
		.global1_addr = 0x1b,
4447
		.global2_addr = 0x1c,
4448
		.age_time_coeff = 15000,
4449
		.g1_irqs = 9,
4450
		.g2_irqs = 10,
4451
		.atu_move_port_mask = 0xf,
4452
		.pvt = true,
4453
		.multi_chip = true,
4454
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4455
		.ops = &mv88e6351_ops,
4456 4457 4458
	},

	[MV88E6352] = {
4459
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
4460 4461 4462 4463
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6352",
		.num_databases = 4096,
		.num_ports = 7,
4464
		.num_internal_phys = 5,
4465
		.num_gpio = 15,
4466
		.max_vid = 4095,
4467
		.port_base_addr = 0x10,
4468
		.phy_base_addr = 0x0,
4469
		.global1_addr = 0x1b,
4470
		.global2_addr = 0x1c,
4471
		.age_time_coeff = 15000,
4472
		.g1_irqs = 9,
4473
		.g2_irqs = 10,
4474
		.atu_move_port_mask = 0xf,
4475
		.pvt = true,
4476
		.multi_chip = true,
4477
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4478
		.ptp_support = true,
4479
		.ops = &mv88e6352_ops,
4480
	},
4481
	[MV88E6390] = {
4482
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
4483 4484 4485 4486
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4487
		.num_internal_phys = 9,
4488
		.num_gpio = 16,
4489
		.max_vid = 8191,
4490
		.port_base_addr = 0x0,
4491
		.phy_base_addr = 0x0,
4492
		.global1_addr = 0x1b,
4493
		.global2_addr = 0x1c,
4494
		.age_time_coeff = 3750,
4495
		.g1_irqs = 9,
4496
		.g2_irqs = 14,
4497
		.atu_move_port_mask = 0x1f,
4498
		.pvt = true,
4499
		.multi_chip = true,
4500
		.tag_protocol = DSA_TAG_PROTO_DSA,
4501
		.ptp_support = true,
4502 4503 4504
		.ops = &mv88e6390_ops,
	},
	[MV88E6390X] = {
4505
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
4506 4507 4508 4509
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4510
		.num_internal_phys = 9,
4511
		.num_gpio = 16,
4512
		.max_vid = 8191,
4513
		.port_base_addr = 0x0,
4514
		.phy_base_addr = 0x0,
4515
		.global1_addr = 0x1b,
4516
		.global2_addr = 0x1c,
4517
		.age_time_coeff = 3750,
4518
		.g1_irqs = 9,
4519
		.g2_irqs = 14,
4520
		.atu_move_port_mask = 0x1f,
4521
		.pvt = true,
4522
		.multi_chip = true,
4523
		.tag_protocol = DSA_TAG_PROTO_DSA,
4524
		.ptp_support = true,
4525 4526
		.ops = &mv88e6390x_ops,
	},
4527 4528
};

4529
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
4530
{
4531
	int i;
4532

4533 4534 4535
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
4536 4537 4538 4539

	return NULL;
}

4540
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
4541 4542
{
	const struct mv88e6xxx_info *info;
4543 4544 4545
	unsigned int prod_num, rev;
	u16 id;
	int err;
4546

4547
	mv88e6xxx_reg_lock(chip);
4548
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
4549
	mv88e6xxx_reg_unlock(chip);
4550 4551
	if (err)
		return err;
4552

4553 4554
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
4555 4556 4557 4558 4559

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

4560
	/* Update the compatible info with the probed one */
4561
	chip->info = info;
4562

4563 4564 4565 4566
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

4567 4568
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
4569 4570 4571 4572

	return 0;
}

4573
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
4574
{
4575
	struct mv88e6xxx_chip *chip;
4576

4577 4578
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
4579 4580
		return NULL;

4581
	chip->dev = dev;
4582

4583
	mutex_init(&chip->reg_lock);
4584
	INIT_LIST_HEAD(&chip->mdios);
4585

4586
	return chip;
4587 4588
}

4589 4590
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
							int port)
4591
{
V
Vivien Didelot 已提交
4592
	struct mv88e6xxx_chip *chip = ds->priv;
4593

4594
	return chip->info->tag_protocol;
4595 4596
}

4597
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4598
				      const struct switchdev_obj_port_mdb *mdb)
4599 4600 4601 4602 4603 4604 4605 4606 4607
{
	/* 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,
4608
				   const struct switchdev_obj_port_mdb *mdb)
4609
{
V
Vivien Didelot 已提交
4610
	struct mv88e6xxx_chip *chip = ds->priv;
4611

4612
	mv88e6xxx_reg_lock(chip);
4613
	if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4614
					 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
4615 4616
		dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
			port);
4617
	mv88e6xxx_reg_unlock(chip);
4618 4619 4620 4621 4622
}

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

4626
	mv88e6xxx_reg_lock(chip);
4627
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4628
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
4629
	mv88e6xxx_reg_unlock(chip);
4630 4631 4632 4633

	return err;
}

4634 4635 4636 4637 4638 4639
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;

4640
	mv88e6xxx_reg_lock(chip);
4641 4642 4643 4644
	if (chip->info->ops->port_set_egress_floods)
		err = chip->info->ops->port_set_egress_floods(chip, port,
							      unicast,
							      multicast);
4645
	mv88e6xxx_reg_unlock(chip);
4646 4647 4648 4649

	return err;
}

4650
static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
4651
	.get_tag_protocol	= mv88e6xxx_get_tag_protocol,
4652 4653
	.setup			= mv88e6xxx_setup,
	.adjust_link		= mv88e6xxx_adjust_link,
4654 4655 4656 4657 4658
	.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,
4659 4660 4661
	.get_strings		= mv88e6xxx_get_strings,
	.get_ethtool_stats	= mv88e6xxx_get_ethtool_stats,
	.get_sset_count		= mv88e6xxx_get_sset_count,
4662 4663
	.port_enable		= mv88e6xxx_port_enable,
	.port_disable		= mv88e6xxx_port_disable,
V
Vivien Didelot 已提交
4664 4665
	.get_mac_eee		= mv88e6xxx_get_mac_eee,
	.set_mac_eee		= mv88e6xxx_set_mac_eee,
4666
	.get_eeprom_len		= mv88e6xxx_get_eeprom_len,
4667 4668 4669 4670
	.get_eeprom		= mv88e6xxx_get_eeprom,
	.set_eeprom		= mv88e6xxx_set_eeprom,
	.get_regs_len		= mv88e6xxx_get_regs_len,
	.get_regs		= mv88e6xxx_get_regs,
4671
	.set_ageing_time	= mv88e6xxx_set_ageing_time,
4672 4673
	.port_bridge_join	= mv88e6xxx_port_bridge_join,
	.port_bridge_leave	= mv88e6xxx_port_bridge_leave,
4674
	.port_egress_floods	= mv88e6xxx_port_egress_floods,
4675
	.port_stp_state_set	= mv88e6xxx_port_stp_state_set,
4676
	.port_fast_age		= mv88e6xxx_port_fast_age,
4677 4678 4679 4680 4681 4682 4683
	.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,
4684 4685 4686
	.port_mdb_prepare       = mv88e6xxx_port_mdb_prepare,
	.port_mdb_add           = mv88e6xxx_port_mdb_add,
	.port_mdb_del           = mv88e6xxx_port_mdb_del,
4687 4688
	.crosschip_bridge_join	= mv88e6xxx_crosschip_bridge_join,
	.crosschip_bridge_leave	= mv88e6xxx_crosschip_bridge_leave,
4689 4690 4691 4692 4693
	.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,
4694 4695
};

4696
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
4697
{
4698
	struct device *dev = chip->dev;
4699 4700
	struct dsa_switch *ds;

4701
	ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
4702 4703 4704
	if (!ds)
		return -ENOMEM;

4705
	ds->priv = chip;
4706
	ds->dev = dev;
4707
	ds->ops = &mv88e6xxx_switch_ops;
4708 4709
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
4710 4711 4712

	dev_set_drvdata(dev, ds);

4713
	return dsa_register_switch(ds);
4714 4715
}

4716
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
4717
{
4718
	dsa_unregister_switch(chip->ds);
4719 4720
}

4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733
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;
}

4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748
/* 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);

4749
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
4750
{
4751
	struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
4752
	const struct mv88e6xxx_info *compat_info = NULL;
4753
	struct device *dev = &mdiodev->dev;
4754
	struct device_node *np = dev->of_node;
4755
	struct mv88e6xxx_chip *chip;
4756
	int port;
4757
	int err;
4758

4759 4760 4761
	if (!np && !pdata)
		return -EINVAL;

4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780
	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;
		}
	}

4781 4782 4783
	if (!compat_info)
		return -EINVAL;

4784
	chip = mv88e6xxx_alloc_chip(dev);
4785 4786 4787 4788
	if (!chip) {
		err = -ENOMEM;
		goto out;
	}
4789

4790
	chip->info = compat_info;
4791

4792
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
4793
	if (err)
4794
		goto out;
4795

4796
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4797 4798 4799 4800
	if (IS_ERR(chip->reset)) {
		err = PTR_ERR(chip->reset);
		goto out;
	}
4801 4802
	if (chip->reset)
		usleep_range(1000, 2000);
4803

4804
	err = mv88e6xxx_detect(chip);
4805
	if (err)
4806
		goto out;
4807

4808 4809
	mv88e6xxx_phy_init(chip);

4810 4811 4812 4813 4814 4815 4816
	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;
	}
4817

4818
	mv88e6xxx_reg_lock(chip);
4819
	err = mv88e6xxx_switch_reset(chip);
4820
	mv88e6xxx_reg_unlock(chip);
4821 4822 4823
	if (err)
		goto out;

4824 4825 4826 4827 4828 4829
	if (np) {
		chip->irq = of_irq_get(np, 0);
		if (chip->irq == -EPROBE_DEFER) {
			err = chip->irq;
			goto out;
		}
4830 4831
	}

4832 4833 4834
	if (pdata)
		chip->irq = pdata->irq;

4835
	/* Has to be performed before the MDIO bus is created, because
4836
	 * the PHYs will link their interrupts to these interrupt
4837 4838
	 * controllers
	 */
4839
	mv88e6xxx_reg_lock(chip);
4840
	if (chip->irq > 0)
4841
		err = mv88e6xxx_g1_irq_setup(chip);
4842 4843
	else
		err = mv88e6xxx_irq_poll_setup(chip);
4844
	mv88e6xxx_reg_unlock(chip);
4845

4846 4847
	if (err)
		goto out;
4848

4849 4850
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
4851
		if (err)
4852
			goto out_g1_irq;
4853 4854
	}

4855 4856 4857 4858 4859 4860 4861 4862
	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;

4863
	err = mv88e6xxx_mdios_register(chip, np);
4864
	if (err)
4865
		goto out_g1_vtu_prob_irq;
4866

4867
	err = mv88e6xxx_register_switch(chip);
4868 4869
	if (err)
		goto out_mdio;
4870

4871
	return 0;
4872 4873

out_mdio:
4874
	mv88e6xxx_mdios_unregister(chip);
4875
out_g1_vtu_prob_irq:
4876
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
4877
out_g1_atu_prob_irq:
4878
	mv88e6xxx_g1_atu_prob_irq_free(chip);
4879
out_g2_irq:
4880
	if (chip->info->g2_irqs > 0)
4881 4882
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
4883
	if (chip->irq > 0)
4884
		mv88e6xxx_g1_irq_free(chip);
4885 4886
	else
		mv88e6xxx_irq_poll_free(chip);
4887
out:
4888 4889 4890
	if (pdata)
		dev_put(pdata->netdev);

4891
	return err;
4892
}
4893 4894 4895 4896

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

4899 4900
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
4901
		mv88e6xxx_ptp_free(chip);
4902
	}
4903

4904
	mv88e6xxx_phy_destroy(chip);
4905
	mv88e6xxx_unregister_switch(chip);
4906
	mv88e6xxx_mdios_unregister(chip);
4907

4908 4909 4910 4911 4912 4913 4914
	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)
4915
		mv88e6xxx_g1_irq_free(chip);
4916 4917
	else
		mv88e6xxx_irq_poll_free(chip);
4918 4919 4920
}

static const struct of_device_id mv88e6xxx_of_match[] = {
4921 4922 4923 4924
	{
		.compatible = "marvell,mv88e6085",
		.data = &mv88e6xxx_table[MV88E6085],
	},
4925 4926 4927 4928
	{
		.compatible = "marvell,mv88e6190",
		.data = &mv88e6xxx_table[MV88E6190],
	},
4929 4930 4931 4932
	{
		.compatible = "marvell,mv88e6250",
		.data = &mv88e6xxx_table[MV88E6250],
	},
4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943
	{ /* 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,
4944
		.pm = &mv88e6xxx_pm_ops,
4945 4946 4947
	},
};

4948
mdio_module_driver(mv88e6xxx_driver);
4949 4950 4951 4952

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