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

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

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

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

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

56
	assert_reg_lock(chip);
57

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

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

	return 0;
}

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

72
	assert_reg_lock(chip);
73

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

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

81 82 83
	return 0;
}

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

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

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

		usleep_range(1000, 2000);
	}

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

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

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

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

	return mdio_bus->bus;
}

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

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

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

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

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

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

	if (err)
		goto out;

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

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

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

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

	return mv88e6xxx_g1_irq_thread_work(chip);
}

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

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

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

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

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

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

out:
217
	mv88e6xxx_reg_unlock(chip);
218 219
}

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

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

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

	return 0;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return 0;

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

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

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

	return err;
}

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

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

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

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

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

	return err;
}

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

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

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

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

	kthread_init_delayed_work(&chip->irq_poll_work,
				  mv88e6xxx_irq_poll);

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

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

	return 0;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return err;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return err;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return j;
791 792
}

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

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

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

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

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

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

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

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

840
	mv88e6xxx_reg_lock(chip);
841

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

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

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

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

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

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

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

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

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

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

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

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

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

912
out:
913
	mv88e6xxx_reg_unlock(chip);
914

915
	return count;
916 917
}

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

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

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

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

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

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

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

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

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

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

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

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

1007
	mv88e6xxx_reg_lock(chip);
1008

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

	if (ret < 0)
1013
		return;
1014 1015

	mv88e6xxx_get_stats(chip, port, data);
1016

1017 1018
}

1019
static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
1020 1021 1022 1023
{
	return 32 * sizeof(u16);
}

1024 1025
static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
			       struct ethtool_regs *regs, void *_p)
1026
{
V
Vivien Didelot 已提交
1027
	struct mv88e6xxx_chip *chip = ds->priv;
1028 1029
	int err;
	u16 reg;
1030 1031 1032
	u16 *p = _p;
	int i;

1033
	regs->version = chip->info->prod_num;
1034 1035 1036

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

1037
	mv88e6xxx_reg_lock(chip);
1038

1039 1040
	for (i = 0; i < 32; i++) {

1041 1042 1043
		err = mv88e6xxx_port_read(chip, port, i, &reg);
		if (!err)
			p[i] = reg;
1044
	}
1045

1046
	mv88e6xxx_reg_unlock(chip);
1047 1048
}

V
Vivien Didelot 已提交
1049 1050
static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
1051
{
1052 1053
	/* Nothing to do on the port's MAC */
	return 0;
1054 1055
}

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

1063
/* Mask of the local ports allowed to receive frames from a given fabric port */
1064
static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
1065
{
1066 1067
	struct dsa_switch *ds = chip->ds;
	struct dsa_switch_tree *dst = ds->dst;
1068
	struct net_device *br;
1069 1070
	struct dsa_port *dp;
	bool found = false;
1071
	u16 pvlan;
1072

1073 1074 1075 1076 1077 1078
	list_for_each_entry(dp, &dst->ports, list) {
		if (dp->ds->index == dev && dp->index == port) {
			found = true;
			break;
		}
	}
1079 1080

	/* Prevent frames from unknown switch or port */
1081
	if (!found)
1082 1083 1084
		return 0;

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

1088
	br = dp->bridge_dev;
1089 1090 1091 1092 1093
	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.
	 */
1094 1095 1096 1097 1098 1099
	list_for_each_entry(dp, &dst->ports, list)
		if (dp->ds == ds &&
		    (dp->type == DSA_PORT_TYPE_CPU ||
		     dp->type == DSA_PORT_TYPE_DSA ||
		     (br && dp->bridge_dev == br)))
			pvlan |= BIT(dp->index);
1100 1101 1102 1103

	return pvlan;
}

1104
static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
1105 1106
{
	u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
1107 1108 1109

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

1111
	return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
1112 1113
}

1114 1115
static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
					 u8 state)
1116
{
V
Vivien Didelot 已提交
1117
	struct mv88e6xxx_chip *chip = ds->priv;
1118
	int err;
1119

1120
	mv88e6xxx_reg_lock(chip);
1121
	err = mv88e6xxx_port_set_state(chip, port, state);
1122
	mv88e6xxx_reg_unlock(chip);
1123 1124

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

1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146
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;
}

1147 1148
static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
{
1149
	struct dsa_switch *ds = chip->ds;
1150 1151 1152 1153 1154 1155 1156 1157
	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++) {
1158 1159 1160
		port = dsa_routing_port(ds, target);
		if (port == ds->num_ports)
			port = 0x1f;
1161 1162 1163 1164 1165 1166

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

1167 1168 1169 1170 1171 1172 1173
	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;
	}

1174 1175 1176 1177
	err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
	if (err)
		return err;

1178 1179 1180
	return 0;
}

1181 1182 1183 1184 1185 1186 1187 1188 1189
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;
}

1190 1191 1192 1193 1194 1195 1196 1197
static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->rmu_disable)
		return chip->info->ops->rmu_disable(chip);

	return 0;
}

1198 1199 1200 1201 1202 1203 1204 1205
static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->pot_clear)
		return chip->info->ops->pot_clear(chip);

	return 0;
}

1206 1207 1208 1209 1210 1211 1212 1213
static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->mgmt_rsvd2cpu)
		return chip->info->ops->mgmt_rsvd2cpu(chip);

	return 0;
}

1214 1215
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
1216 1217
	int err;

1218 1219 1220 1221
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

1222 1223 1224 1225
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

1226 1227 1228
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248
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;
}

1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261
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;
}

1262 1263 1264 1265 1266
static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
{
	u16 pvlan = 0;

	if (!mv88e6xxx_has_pvt(chip))
1267
		return 0;
1268 1269 1270

	/* Skip the local source device, which uses in-chip port VLAN */
	if (dev != chip->ds->index)
1271
		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1272 1273 1274 1275

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

1276 1277
static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
{
1278 1279 1280
	int dev, port;
	int err;

1281 1282 1283 1284 1285 1286
	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.
	 */
1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299
	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;
1300 1301
}

1302 1303 1304 1305 1306
static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

1307
	mv88e6xxx_reg_lock(chip);
1308
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1309
	mv88e6xxx_reg_unlock(chip);
1310 1311

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

1315 1316 1317 1318 1319 1320 1321 1322
static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
{
	if (!chip->info->max_vid)
		return 0;

	return mv88e6xxx_g1_vtu_flush(chip);
}

1323 1324 1325 1326 1327 1328 1329 1330 1331
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);
}

1332 1333 1334 1335 1336 1337 1338 1339 1340
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);
}

1341
static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1342 1343
{
	DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1344
	struct mv88e6xxx_vtu_entry vlan;
1345
	int i, err;
1346 1347 1348

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

1349
	/* Set every FID bit used by the (un)bridged ports */
1350
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1351
		err = mv88e6xxx_port_get_fid(chip, i, fid);
1352 1353 1354 1355 1356 1357
		if (err)
			return err;

		set_bit(*fid, fid_bitmap);
	}

1358
	/* Set every FID bit used by the VLAN entries */
1359 1360 1361
	vlan.vid = chip->info->max_vid;
	vlan.valid = false;

1362
	do {
1363
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1364 1365 1366 1367 1368 1369 1370
		if (err)
			return err;

		if (!vlan.valid)
			break;

		set_bit(vlan.fid, fid_bitmap);
1371
	} while (vlan.vid < chip->info->max_vid);
1372 1373 1374 1375 1376

	/* 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);
1377
	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1378 1379 1380
		return -ENOSPC;

	/* Clear the database */
1381
	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1382 1383
}

1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399
static int mv88e6xxx_atu_get_hash(struct mv88e6xxx_chip *chip, u8 *hash)
{
	if (chip->info->ops->atu_get_hash)
		return chip->info->ops->atu_get_hash(chip, hash);

	return -EOPNOTSUPP;
}

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

	return -EOPNOTSUPP;
}

1400 1401 1402
static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
					u16 vid_begin, u16 vid_end)
{
V
Vivien Didelot 已提交
1403
	struct mv88e6xxx_chip *chip = ds->priv;
1404
	struct mv88e6xxx_vtu_entry vlan;
1405 1406
	int i, err;

1407 1408 1409 1410
	/* 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;

1411 1412 1413
	if (!vid_begin)
		return -EOPNOTSUPP;

1414 1415 1416
	vlan.vid = vid_begin - 1;
	vlan.valid = false;

1417
	do {
1418
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1419
		if (err)
1420
			return err;
1421 1422 1423 1424 1425 1426 1427

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

1428
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1429 1430 1431
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

1432
			if (!dsa_to_port(ds, i)->slave)
1433 1434
				continue;

1435
			if (vlan.member[i] ==
1436
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1437 1438
				continue;

V
Vivien Didelot 已提交
1439
			if (dsa_to_port(ds, i)->bridge_dev ==
1440
			    dsa_to_port(ds, port)->bridge_dev)
1441 1442
				break; /* same bridge, check next VLAN */

V
Vivien Didelot 已提交
1443
			if (!dsa_to_port(ds, i)->bridge_dev)
1444 1445
				continue;

1446 1447
			dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
				port, vlan.vid, i,
V
Vivien Didelot 已提交
1448
				netdev_name(dsa_to_port(ds, i)->bridge_dev));
1449
			return -EOPNOTSUPP;
1450 1451 1452
		}
	} while (vlan.vid < vid_end);

1453
	return 0;
1454 1455
}

1456 1457
static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
					 bool vlan_filtering)
1458
{
V
Vivien Didelot 已提交
1459
	struct mv88e6xxx_chip *chip = ds->priv;
1460 1461
	u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
		MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
1462
	int err;
1463

1464
	if (!chip->info->max_vid)
1465 1466
		return -EOPNOTSUPP;

1467
	mv88e6xxx_reg_lock(chip);
1468
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1469
	mv88e6xxx_reg_unlock(chip);
1470

1471
	return err;
1472 1473
}

1474 1475
static int
mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1476
			    const struct switchdev_obj_port_vlan *vlan)
1477
{
V
Vivien Didelot 已提交
1478
	struct mv88e6xxx_chip *chip = ds->priv;
1479 1480
	int err;

1481
	if (!chip->info->max_vid)
1482 1483
		return -EOPNOTSUPP;

1484 1485 1486
	/* 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.
	 */
1487
	mv88e6xxx_reg_lock(chip);
1488 1489
	err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
					   vlan->vid_end);
1490
	mv88e6xxx_reg_unlock(chip);
1491

1492 1493 1494
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */
1495
	return err;
1496 1497
}

1498 1499 1500 1501 1502
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;
1503 1504
	struct mv88e6xxx_vtu_entry vlan;
	u16 fid;
1505 1506 1507
	int err;

	/* Null VLAN ID corresponds to the port private database */
1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525
	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;
	}
1526

1527
	entry.state = 0;
1528 1529 1530
	ether_addr_copy(entry.mac, addr);
	eth_addr_dec(entry.mac);

1531
	err = mv88e6xxx_g1_atu_getnext(chip, fid, &entry);
1532 1533 1534 1535
	if (err)
		return err;

	/* Initialize a fresh ATU entry if it isn't found */
1536
	if (!entry.state || !ether_addr_equal(entry.mac, addr)) {
1537 1538 1539 1540 1541
		memset(&entry, 0, sizeof(entry));
		ether_addr_copy(entry.mac, addr);
	}

	/* Purge the ATU entry only if no port is using it anymore */
1542
	if (!state) {
1543 1544
		entry.portvec &= ~BIT(port);
		if (!entry.portvec)
1545
			entry.state = 0;
1546 1547 1548 1549 1550
	} else {
		entry.portvec |= BIT(port);
		entry.state = state;
	}

1551
	return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry);
1552 1553
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return 0;
}

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

	mv88e6xxx_reg_lock(chip);

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

	mv88e6xxx_reg_unlock(chip);

	return err;
}

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

	mv88e6xxx_reg_lock(chip);

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

	mv88e6xxx_reg_unlock(chip);

	return err;
}

1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786
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;
}

1787
static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port,
1788
				    u16 vid, u8 member)
1789
{
1790
	const u8 non_member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1791
	struct mv88e6xxx_vtu_entry vlan;
1792
	int i, err;
1793

1794 1795
	if (!vid)
		return -EOPNOTSUPP;
1796

1797 1798
	vlan.vid = vid - 1;
	vlan.valid = false;
1799

1800
	err = mv88e6xxx_vtu_getnext(chip, &vlan);
1801 1802 1803
	if (err)
		return err;

1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838
	if (vlan.vid != vid || !vlan.valid) {
		memset(&vlan, 0, sizeof(vlan));

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

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

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

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

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

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

	return 0;
1839 1840
}

1841
static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1842
				    const struct switchdev_obj_port_vlan *vlan)
1843
{
V
Vivien Didelot 已提交
1844
	struct mv88e6xxx_chip *chip = ds->priv;
1845 1846
	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1847
	u8 member;
1848 1849
	u16 vid;

1850
	if (!chip->info->max_vid)
1851 1852
		return;

1853
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1854
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1855
	else if (untagged)
1856
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
1857
	else
1858
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
1859

1860
	mv88e6xxx_reg_lock(chip);
1861

1862
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
1863
		if (mv88e6xxx_port_vlan_join(chip, port, vid, member))
1864 1865
			dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
				vid, untagged ? 'u' : 't');
1866

1867
	if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1868 1869
		dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
			vlan->vid_end);
1870

1871
	mv88e6xxx_reg_unlock(chip);
1872 1873
}

1874 1875
static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,
				     int port, u16 vid)
1876
{
1877
	struct mv88e6xxx_vtu_entry vlan;
1878 1879
	int i, err;

1880 1881 1882 1883 1884 1885 1886
	if (!vid)
		return -EOPNOTSUPP;

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

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

1890 1891 1892 1893 1894
	/* If the VLAN doesn't exist in hardware or the port isn't a member,
	 * tell switchdev that this VLAN is likely handled in software.
	 */
	if (vlan.vid != vid || !vlan.valid ||
	    vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1895
		return -EOPNOTSUPP;
1896

1897
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1898 1899

	/* keep the VLAN unless all ports are excluded */
1900
	vlan.valid = false;
1901
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1902 1903
		if (vlan.member[i] !=
		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
1904
			vlan.valid = true;
1905 1906 1907 1908
			break;
		}
	}

1909
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1910 1911 1912
	if (err)
		return err;

1913
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
1914 1915
}

1916 1917
static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
				   const struct switchdev_obj_port_vlan *vlan)
1918
{
V
Vivien Didelot 已提交
1919
	struct mv88e6xxx_chip *chip = ds->priv;
1920 1921 1922
	u16 pvid, vid;
	int err = 0;

1923
	if (!chip->info->max_vid)
1924 1925
		return -EOPNOTSUPP;

1926
	mv88e6xxx_reg_lock(chip);
1927

1928
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
1929 1930 1931
	if (err)
		goto unlock;

1932
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1933
		err = mv88e6xxx_port_vlan_leave(chip, port, vid);
1934 1935 1936 1937
		if (err)
			goto unlock;

		if (vid == pvid) {
1938
			err = mv88e6xxx_port_set_pvid(chip, port, 0);
1939 1940 1941 1942 1943
			if (err)
				goto unlock;
		}
	}

1944
unlock:
1945
	mv88e6xxx_reg_unlock(chip);
1946 1947 1948 1949

	return err;
}

1950 1951
static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
				  const unsigned char *addr, u16 vid)
1952
{
V
Vivien Didelot 已提交
1953
	struct mv88e6xxx_chip *chip = ds->priv;
1954
	int err;
1955

1956
	mv88e6xxx_reg_lock(chip);
1957 1958
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1959
	mv88e6xxx_reg_unlock(chip);
1960 1961

	return err;
1962 1963
}

1964
static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1965
				  const unsigned char *addr, u16 vid)
1966
{
V
Vivien Didelot 已提交
1967
	struct mv88e6xxx_chip *chip = ds->priv;
1968
	int err;
1969

1970
	mv88e6xxx_reg_lock(chip);
1971
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid, 0);
1972
	mv88e6xxx_reg_unlock(chip);
1973

1974
	return err;
1975 1976
}

1977 1978
static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
				      u16 fid, u16 vid, int port,
1979
				      dsa_fdb_dump_cb_t *cb, void *data)
1980
{
1981
	struct mv88e6xxx_atu_entry addr;
1982
	bool is_static;
1983 1984
	int err;

1985
	addr.state = 0;
1986
	eth_broadcast_addr(addr.mac);
1987 1988

	do {
1989
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
1990
		if (err)
1991
			return err;
1992

1993
		if (!addr.state)
1994 1995
			break;

1996
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
1997 1998
			continue;

1999 2000
		if (!is_unicast_ether_addr(addr.mac))
			continue;
2001

2002 2003 2004
		is_static = (addr.state ==
			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
		err = cb(addr.mac, vid, is_static, data);
2005 2006
		if (err)
			return err;
2007 2008 2009 2010 2011
	} while (!is_broadcast_ether_addr(addr.mac));

	return err;
}

2012
static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2013
				  dsa_fdb_dump_cb_t *cb, void *data)
2014
{
2015
	struct mv88e6xxx_vtu_entry vlan;
2016
	u16 fid;
2017 2018
	int err;

2019
	/* Dump port's default Filtering Information Database (VLAN ID 0) */
2020
	err = mv88e6xxx_port_get_fid(chip, port, &fid);
2021
	if (err)
2022
		return err;
2023

2024
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
2025
	if (err)
2026
		return err;
2027

2028
	/* Dump VLANs' Filtering Information Databases */
2029 2030 2031
	vlan.vid = chip->info->max_vid;
	vlan.valid = false;

2032
	do {
2033
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
2034
		if (err)
2035
			return err;
2036 2037 2038 2039

		if (!vlan.valid)
			break;

2040
		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
2041
						 cb, data);
2042
		if (err)
2043
			return err;
2044
	} while (vlan.vid < chip->info->max_vid);
2045

2046 2047 2048 2049
	return err;
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2050
				   dsa_fdb_dump_cb_t *cb, void *data)
2051
{
V
Vivien Didelot 已提交
2052
	struct mv88e6xxx_chip *chip = ds->priv;
2053 2054
	int err;

2055
	mv88e6xxx_reg_lock(chip);
2056
	err = mv88e6xxx_port_db_dump(chip, port, cb, data);
2057
	mv88e6xxx_reg_unlock(chip);
2058

2059
	return err;
2060 2061
}

2062 2063
static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
				struct net_device *br)
2064
{
2065 2066 2067
	struct dsa_switch *ds = chip->ds;
	struct dsa_switch_tree *dst = ds->dst;
	struct dsa_port *dp;
2068
	int err;
2069

2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084
	list_for_each_entry(dp, &dst->ports, list) {
		if (dp->bridge_dev == br) {
			if (dp->ds == ds) {
				/* This is a local bridge group member,
				 * remap its Port VLAN Map.
				 */
				err = mv88e6xxx_port_vlan_map(chip, dp->index);
				if (err)
					return err;
			} else {
				/* This is an external bridge group member,
				 * remap its cross-chip Port VLAN Table entry.
				 */
				err = mv88e6xxx_pvt_map(chip, dp->ds->index,
							dp->index);
2085 2086 2087 2088 2089 2090
				if (err)
					return err;
			}
		}
	}

2091 2092 2093 2094 2095 2096 2097 2098 2099
	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;

2100
	mv88e6xxx_reg_lock(chip);
2101
	err = mv88e6xxx_bridge_map(chip, br);
2102
	mv88e6xxx_reg_unlock(chip);
2103

2104
	return err;
2105 2106
}

2107 2108
static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
					struct net_device *br)
2109
{
V
Vivien Didelot 已提交
2110
	struct mv88e6xxx_chip *chip = ds->priv;
2111

2112
	mv88e6xxx_reg_lock(chip);
2113 2114 2115
	if (mv88e6xxx_bridge_map(chip, br) ||
	    mv88e6xxx_port_vlan_map(chip, port))
		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
2116
	mv88e6xxx_reg_unlock(chip);
2117 2118
}

2119 2120 2121 2122 2123 2124
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;

2125
	mv88e6xxx_reg_lock(chip);
2126
	err = mv88e6xxx_pvt_map(chip, dev, port);
2127
	mv88e6xxx_reg_unlock(chip);
2128 2129 2130 2131 2132 2133 2134 2135 2136

	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;

2137
	mv88e6xxx_reg_lock(chip);
2138 2139
	if (mv88e6xxx_pvt_map(chip, dev, port))
		dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
2140
	mv88e6xxx_reg_unlock(chip);
2141 2142
}

2143 2144 2145 2146 2147 2148 2149 2150
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->reset)
		return chip->info->ops->reset(chip);

	return 0;
}

2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163
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);
	}
}

2164
static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2165
{
2166
	int i, err;
2167

2168
	/* Set all ports to the Disabled state */
2169
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2170
		err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
2171 2172
		if (err)
			return err;
2173 2174
	}

2175 2176 2177
	/* Wait for transmit queues to drain,
	 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
	 */
2178 2179
	usleep_range(2000, 4000);

2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190
	return 0;
}

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

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

2191
	mv88e6xxx_hardware_reset(chip);
2192

2193
	return mv88e6xxx_software_reset(chip);
2194 2195
}

2196
static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
2197 2198
				   enum mv88e6xxx_frame_mode frame,
				   enum mv88e6xxx_egress_mode egress, u16 etype)
2199 2200 2201
{
	int err;

2202 2203 2204 2205
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
2206 2207 2208
	if (err)
		return err;

2209 2210 2211 2212 2213 2214 2215 2216
	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;
2217 2218
}

2219
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2220
{
2221
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
2222
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2223
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2224
}
2225

2226 2227 2228
static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
2229
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2230
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2231
}
2232

2233 2234 2235 2236
static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port,
				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
2237 2238
				       MV88E6XXX_EGRESS_MODE_ETHERTYPE,
				       ETH_P_EDSA);
2239
}
2240

2241 2242 2243 2244
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);
2245

2246
	if (dsa_is_user_port(chip->ds, port))
2247
		return mv88e6xxx_set_port_mode_normal(chip, port);
2248

2249 2250 2251
	/* 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);
2252

2253 2254
	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
		return mv88e6xxx_set_port_mode_edsa(chip, port);
2255

2256
	return -EINVAL;
2257 2258
}

2259
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2260
{
2261
	bool message = dsa_is_dsa_port(chip->ds, port);
2262

2263
	return mv88e6xxx_port_set_message_port(chip, port, message);
2264
}
2265

2266
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2267
{
2268
	struct dsa_switch *ds = chip->ds;
2269
	bool flood;
2270

2271 2272 2273 2274 2275
	/* 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);
2276

2277
	return 0;
2278 2279
}

2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308
static irqreturn_t mv88e6xxx_serdes_irq_thread_fn(int irq, void *dev_id)
{
	struct mv88e6xxx_port *mvp = dev_id;
	struct mv88e6xxx_chip *chip = mvp->chip;
	irqreturn_t ret = IRQ_NONE;
	int port = mvp->port;
	u8 lane;

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

	return ret;
}

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

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

2309 2310 2311
	snprintf(dev_id->serdes_irq_name, sizeof(dev_id->serdes_irq_name),
		 "mv88e6xxx-%s-serdes-%d", dev_name(chip->dev), port);

2312 2313 2314
	/* Requesting the IRQ will trigger IRQ callbacks, so release the lock */
	mv88e6xxx_reg_unlock(chip);
	err = request_threaded_irq(irq, NULL, mv88e6xxx_serdes_irq_thread_fn,
2315 2316
				   IRQF_ONESHOT, dev_id->serdes_irq_name,
				   dev_id);
2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348
	mv88e6xxx_reg_lock(chip);
	if (err)
		return err;

	dev_id->serdes_irq = irq;

	return mv88e6xxx_serdes_irq_enable(chip, port, lane);
}

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

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

	err = mv88e6xxx_serdes_irq_disable(chip, port, lane);

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

	dev_id->serdes_irq = 0;

	return err;
}

2349 2350 2351
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
2352
	u8 lane;
2353
	int err;
2354

2355 2356
	lane = mv88e6xxx_serdes_get_lane(chip, port);
	if (!lane)
2357 2358 2359
		return 0;

	if (on) {
2360
		err = mv88e6xxx_serdes_power_up(chip, port, lane);
2361 2362 2363
		if (err)
			return err;

2364
		err = mv88e6xxx_serdes_irq_request(chip, port, lane);
2365
	} else {
2366 2367 2368
		err = mv88e6xxx_serdes_irq_free(chip, port, lane);
		if (err)
			return err;
2369

2370
		err = mv88e6xxx_serdes_power_down(chip, port, lane);
2371 2372 2373
	}

	return err;
2374 2375
}

2376 2377 2378 2379 2380 2381
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

2382
	upstream_port = dsa_upstream_port(ds, port);
2383 2384 2385 2386 2387 2388 2389
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

2390 2391 2392 2393 2394 2395 2396 2397 2398 2399
	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,
2400 2401 2402 2403 2404 2405 2406 2407
						MV88E6XXX_EGRESS_DIR_INGRESS,
						upstream_port);
			if (err)
				return err;

			err = chip->info->ops->set_egress_port(chip,
						MV88E6XXX_EGRESS_DIR_EGRESS,
						upstream_port);
2408 2409 2410 2411 2412
			if (err)
				return err;
		}
	}

2413 2414 2415
	return 0;
}

2416
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
2417
{
2418
	struct dsa_switch *ds = chip->ds;
2419
	int err;
2420
	u16 reg;
2421

2422 2423 2424
	chip->ports[port].chip = chip;
	chip->ports[port].port = port;

2425 2426 2427 2428 2429 2430 2431
	/* 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,
2432
					       PAUSE_OFF,
2433 2434 2435 2436
					       PHY_INTERFACE_MODE_NA);
	else
		err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
					       SPEED_UNFORCED, DUPLEX_UNFORCED,
2437
					       PAUSE_ON,
2438 2439 2440
					       PHY_INTERFACE_MODE_NA);
	if (err)
		return err;
2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455

	/* 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.
	 */
2456 2457 2458 2459
	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);
2460 2461
	if (err)
		return err;
2462

2463
	err = mv88e6xxx_setup_port_mode(chip, port);
2464 2465
	if (err)
		return err;
2466

2467
	err = mv88e6xxx_setup_egress_floods(chip, port);
2468 2469 2470
	if (err)
		return err;

2471
	/* Port Control 2: don't force a good FCS, set the maximum frame size to
2472
	 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
2473 2474 2475
	 * 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.
2476
	 */
2477 2478 2479
	err = mv88e6xxx_port_set_map_da(chip, port);
	if (err)
		return err;
2480

2481 2482 2483
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
2484

2485
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
2486
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
2487 2488 2489
	if (err)
		return err;

2490 2491
	if (chip->info->ops->port_set_jumbo_size) {
		err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
2492 2493 2494 2495
		if (err)
			return err;
	}

2496 2497 2498 2499 2500
	/* 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.
	 */
2501
	reg = 1 << port;
2502 2503
	/* Disable learning for CPU port */
	if (dsa_is_cpu_port(ds, port))
2504
		reg = 0;
2505

2506 2507
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
2508 2509
	if (err)
		return err;
2510 2511

	/* Egress rate control 2: disable egress rate control. */
2512 2513
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
				   0x0000);
2514 2515
	if (err)
		return err;
2516

2517 2518
	if (chip->info->ops->port_pause_limit) {
		err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
2519 2520
		if (err)
			return err;
2521
	}
2522

2523 2524 2525 2526 2527 2528
	if (chip->info->ops->port_disable_learn_limit) {
		err = chip->info->ops->port_disable_learn_limit(chip, port);
		if (err)
			return err;
	}

2529 2530
	if (chip->info->ops->port_disable_pri_override) {
		err = chip->info->ops->port_disable_pri_override(chip, port);
2531 2532
		if (err)
			return err;
2533
	}
2534

2535 2536
	if (chip->info->ops->port_tag_remap) {
		err = chip->info->ops->port_tag_remap(chip, port);
2537 2538
		if (err)
			return err;
2539 2540
	}

2541 2542
	if (chip->info->ops->port_egress_rate_limiting) {
		err = chip->info->ops->port_egress_rate_limiting(chip, port);
2543 2544
		if (err)
			return err;
2545 2546
	}

2547 2548 2549 2550 2551
	if (chip->info->ops->port_setup_message_port) {
		err = chip->info->ops->port_setup_message_port(chip, port);
		if (err)
			return err;
	}
2552

2553
	/* Port based VLAN map: give each port the same default address
2554 2555
	 * database, and allow bidirectional communication between the
	 * CPU and DSA port(s), and the other ports.
2556
	 */
2557
	err = mv88e6xxx_port_set_fid(chip, port, 0);
2558 2559
	if (err)
		return err;
2560

2561
	err = mv88e6xxx_port_vlan_map(chip, port);
2562 2563
	if (err)
		return err;
2564 2565 2566 2567

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

2571 2572 2573 2574
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
2575
	int err;
2576

2577
	mv88e6xxx_reg_lock(chip);
2578
	err = mv88e6xxx_serdes_power(chip, port, true);
2579
	mv88e6xxx_reg_unlock(chip);
2580 2581 2582 2583

	return err;
}

2584
static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port)
2585 2586 2587
{
	struct mv88e6xxx_chip *chip = ds->priv;

2588
	mv88e6xxx_reg_lock(chip);
2589 2590
	if (mv88e6xxx_serdes_power(chip, port, false))
		dev_err(chip->dev, "failed to power off SERDES\n");
2591
	mv88e6xxx_reg_unlock(chip);
2592 2593
}

2594 2595 2596
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
2597
	struct mv88e6xxx_chip *chip = ds->priv;
2598 2599
	int err;

2600
	mv88e6xxx_reg_lock(chip);
2601
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2602
	mv88e6xxx_reg_unlock(chip);
2603 2604 2605 2606

	return err;
}

2607
static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
2608
{
2609
	int err;
2610

2611
	/* Initialize the statistics unit */
2612 2613 2614 2615 2616
	if (chip->info->ops->stats_set_histogram) {
		err = chip->info->ops->stats_set_histogram(chip);
		if (err)
			return err;
	}
2617

2618
	return mv88e6xxx_g1_stats_clear(chip);
2619 2620
}

2621 2622 2623 2624 2625 2626 2627 2628
/* 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++) {
2629
		err = mv88e6xxx_port_hidden_read(chip, 0xf, port, 0, &val);
2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661
		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++) {
2662
		err = mv88e6xxx_port_hidden_write(chip, 0xf, port, 0, 0x01c0);
2663 2664 2665 2666 2667 2668 2669
		if (err)
			return err;
	}

	return mv88e6xxx_software_reset(chip);
}

2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736
enum mv88e6xxx_devlink_param_id {
	MV88E6XXX_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,
	MV88E6XXX_DEVLINK_PARAM_ID_ATU_HASH,
};

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

	mv88e6xxx_reg_lock(chip);

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

	mv88e6xxx_reg_unlock(chip);

	return err;
}

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

	mv88e6xxx_reg_lock(chip);

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

	mv88e6xxx_reg_unlock(chip);

	return err;
}

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

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

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

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

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

	mv88e6xxx_reg_lock(chip);

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

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

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

unlock:
	mv88e6xxx_reg_unlock(chip);

	return occupancy;
}

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

	return mv88e6xxx_devlink_atu_bin_get(chip,
					     MV88E6XXX_G2_ATU_STATS_BIN_0);
}

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

	return mv88e6xxx_devlink_atu_bin_get(chip,
					     MV88E6XXX_G2_ATU_STATS_BIN_1);
}

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

	return mv88e6xxx_devlink_atu_bin_get(chip,
					     MV88E6XXX_G2_ATU_STATS_BIN_2);
}

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

	return mv88e6xxx_devlink_atu_bin_get(chip,
					     MV88E6XXX_G2_ATU_STATS_BIN_3);
}

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

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

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

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

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

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

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

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

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

	dsa_devlink_resource_occ_get_register(ds,
					      MV88E6XXX_RESOURCE_ID_ATU,
					      mv88e6xxx_devlink_atu_get,
					      chip);

	dsa_devlink_resource_occ_get_register(ds,
					      MV88E6XXX_RESOURCE_ID_ATU_BIN_0,
					      mv88e6xxx_devlink_atu_bin_0_get,
					      chip);

	dsa_devlink_resource_occ_get_register(ds,
					      MV88E6XXX_RESOURCE_ID_ATU_BIN_1,
					      mv88e6xxx_devlink_atu_bin_1_get,
					      chip);

	dsa_devlink_resource_occ_get_register(ds,
					      MV88E6XXX_RESOURCE_ID_ATU_BIN_2,
					      mv88e6xxx_devlink_atu_bin_2_get,
					      chip);

	dsa_devlink_resource_occ_get_register(ds,
					      MV88E6XXX_RESOURCE_ID_ATU_BIN_3,
					      mv88e6xxx_devlink_atu_bin_3_get,
					      chip);

	return 0;

out:
	dsa_devlink_resources_unregister(ds);
	return err;
}

2906 2907 2908
static void mv88e6xxx_teardown(struct dsa_switch *ds)
{
	mv88e6xxx_teardown_devlink_params(ds);
2909
	dsa_devlink_resources_unregister(ds);
2910 2911
}

2912
static int mv88e6xxx_setup(struct dsa_switch *ds)
2913
{
V
Vivien Didelot 已提交
2914
	struct mv88e6xxx_chip *chip = ds->priv;
2915
	u8 cmode;
2916
	int err;
2917 2918
	int i;

2919
	chip->ds = ds;
2920
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
2921

2922
	mv88e6xxx_reg_lock(chip);
2923

2924 2925 2926 2927 2928 2929
	if (chip->info->ops->setup_errata) {
		err = chip->info->ops->setup_errata(chip);
		if (err)
			goto unlock;
	}

2930 2931 2932 2933 2934
	/* 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)
2935
				goto unlock;
2936 2937 2938 2939 2940

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

2941
	/* Setup Switch Port Registers */
2942
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2943 2944 2945
		if (dsa_is_unused_port(ds, i))
			continue;

2946
		/* Prevent the use of an invalid port. */
2947
		if (mv88e6xxx_is_invalid_port(chip, i)) {
2948 2949 2950 2951 2952
			dev_err(chip->dev, "port %d is invalid\n", i);
			err = -EINVAL;
			goto unlock;
		}

2953 2954 2955 2956 2957
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

2958 2959 2960 2961
	err = mv88e6xxx_irl_setup(chip);
	if (err)
		goto unlock;

2962 2963 2964 2965
	err = mv88e6xxx_mac_setup(chip);
	if (err)
		goto unlock;

2966 2967 2968 2969
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

2970 2971 2972 2973
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

2974 2975 2976 2977
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

2978 2979 2980 2981
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

2982 2983 2984 2985
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

2986 2987 2988 2989
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

2990 2991 2992 2993
	err = mv88e6xxx_rmu_setup(chip);
	if (err)
		goto unlock;

2994 2995 2996
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
2997

2998 2999 3000 3001
	err = mv88e6xxx_trunk_setup(chip);
	if (err)
		goto unlock;

3002 3003 3004 3005
	err = mv88e6xxx_devmap_setup(chip);
	if (err)
		goto unlock;

3006 3007 3008 3009
	err = mv88e6xxx_pri_setup(chip);
	if (err)
		goto unlock;

3010
	/* Setup PTP Hardware Clock and timestamping */
3011 3012 3013 3014
	if (chip->info->ptp_support) {
		err = mv88e6xxx_ptp_setup(chip);
		if (err)
			goto unlock;
3015 3016 3017 3018

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
3019 3020
	}

3021 3022 3023 3024
	err = mv88e6xxx_stats_setup(chip);
	if (err)
		goto unlock;

3025
unlock:
3026
	mv88e6xxx_reg_unlock(chip);
3027

3028 3029 3030 3031 3032 3033 3034
	if (err)
		return err;

	/* Have to be called without holding the register lock, since
	 * they take the devlink lock, and we later take the locks in
	 * the reverse order when getting/setting parameters or
	 * resource occupancy.
3035
	 */
3036 3037 3038 3039 3040 3041 3042 3043 3044
	err = mv88e6xxx_setup_devlink_resources(ds);
	if (err)
		return err;

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

	return err;
3045 3046
}

3047
static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
3048
{
3049 3050
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
3051 3052
	u16 val;
	int err;
3053

3054 3055 3056
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

3057
	mv88e6xxx_reg_lock(chip);
3058
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
3059
	mv88e6xxx_reg_unlock(chip);
3060

3061
	if (reg == MII_PHYSID2) {
3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077
		/* 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;
3078 3079
	}

3080
	return err ? err : val;
3081 3082
}

3083
static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
3084
{
3085 3086
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
3087
	int err;
3088

3089 3090 3091
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

3092
	mv88e6xxx_reg_lock(chip);
3093
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
3094
	mv88e6xxx_reg_unlock(chip);
3095 3096

	return err;
3097 3098
}

3099
static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
3100 3101
				   struct device_node *np,
				   bool external)
3102 3103
{
	static int index;
3104
	struct mv88e6xxx_mdio_bus *mdio_bus;
3105 3106 3107
	struct mii_bus *bus;
	int err;

3108
	if (external) {
3109
		mv88e6xxx_reg_lock(chip);
3110
		err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
3111
		mv88e6xxx_reg_unlock(chip);
3112 3113 3114 3115 3116

		if (err)
			return err;
	}

3117
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
3118 3119 3120
	if (!bus)
		return -ENOMEM;

3121
	mdio_bus = bus->priv;
3122
	mdio_bus->bus = bus;
3123
	mdio_bus->chip = chip;
3124 3125
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
3126

3127 3128
	if (np) {
		bus->name = np->full_name;
3129
		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
3130 3131 3132 3133 3134 3135 3136
	} 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;
3137
	bus->parent = chip->dev;
3138

3139 3140 3141 3142 3143 3144
	if (!external) {
		err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
		if (err)
			return err;
	}

3145
	err = of_mdiobus_register(bus, np);
3146
	if (err) {
3147
		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
3148
		mv88e6xxx_g2_irq_mdio_free(chip, bus);
3149
		return err;
3150
	}
3151 3152 3153 3154 3155

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

	return 0;
3158
}
3159

3160 3161 3162 3163 3164
static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
	{ .compatible = "marvell,mv88e6xxx-mdio-external",
	  .data = (void *)true },
	{ },
};
3165

3166 3167 3168 3169 3170 3171 3172 3173 3174
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;

3175 3176 3177
		if (!mdio_bus->external)
			mv88e6xxx_g2_irq_mdio_free(chip, bus);

3178 3179 3180 3181
		mdiobus_unregister(bus);
	}
}

3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205
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);
3206 3207
			if (err) {
				mv88e6xxx_mdios_unregister(chip);
3208
				of_node_put(child);
3209
				return err;
3210
			}
3211 3212 3213 3214
		}
	}

	return 0;
3215 3216
}

3217 3218
static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
3219
	struct mv88e6xxx_chip *chip = ds->priv;
3220 3221 3222 3223 3224 3225 3226

	return chip->eeprom_len;
}

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

3230 3231
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
3232

3233
	mv88e6xxx_reg_lock(chip);
3234
	err = chip->info->ops->get_eeprom(chip, eeprom, data);
3235
	mv88e6xxx_reg_unlock(chip);
3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247

	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 已提交
3248
	struct mv88e6xxx_chip *chip = ds->priv;
3249 3250
	int err;

3251 3252 3253
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

3254 3255 3256
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

3257
	mv88e6xxx_reg_lock(chip);
3258
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
3259
	mv88e6xxx_reg_unlock(chip);
3260 3261 3262 3263

	return err;
}

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

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

3335
static const struct mv88e6xxx_ops mv88e6097_ops = {
3336
	/* MV88E6XXX_FAMILY_6097 */
3337 3338
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3339
	.irl_init_all = mv88e6352_g2_irl_init_all,
3340 3341 3342 3343 3344 3345
	.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,
3346
	.port_tag_remap = mv88e6095_port_tag_remap,
3347
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3348
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3349
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3350
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3351
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
3352
	.port_pause_limit = mv88e6097_port_pause_limit,
3353
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3354
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3355
	.port_link_state = mv88e6352_port_link_state,
3356
	.port_get_cmode = mv88e6185_port_get_cmode,
3357
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3358
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3359
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3360 3361 3362
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
	.stats_get_stats = mv88e6095_stats_get_stats,
3363 3364
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3365
	.watchdog_ops = &mv88e6097_watchdog_ops,
3366
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3367
	.pot_clear = mv88e6xxx_g2_pot_clear,
3368
	.reset = mv88e6352_g1_reset,
3369
	.rmu_disable = mv88e6085_g1_rmu_disable,
3370
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3371
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3372
	.phylink_validate = mv88e6185_phylink_validate,
3373 3374
};

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

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

3451 3452
static const struct mv88e6xxx_ops mv88e6141_ops = {
	/* MV88E6XXX_FAMILY_6341 */
3453 3454
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3455
	.irl_init_all = mv88e6352_g2_irl_init_all,
3456 3457 3458 3459 3460 3461 3462 3463
	.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,
3464
	.port_set_speed = mv88e6341_port_set_speed,
3465
	.port_max_speed_mode = mv88e6341_port_max_speed_mode,
3466 3467 3468 3469
	.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,
3470
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3471
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3472
	.port_pause_limit = mv88e6097_port_pause_limit,
3473 3474
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3475
	.port_link_state = mv88e6352_port_link_state,
3476
	.port_get_cmode = mv88e6352_port_get_cmode,
3477
	.port_set_cmode = mv88e6341_port_set_cmode,
3478
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3479
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3480
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3481 3482 3483
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
3484 3485
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3486 3487
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
3488
	.pot_clear = mv88e6xxx_g2_pot_clear,
3489
	.reset = mv88e6352_g1_reset,
3490
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3491
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3492 3493
	.serdes_power = mv88e6390_serdes_power,
	.serdes_get_lane = mv88e6341_serdes_get_lane,
3494
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3495
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
3496
	.serdes_irq_status = mv88e6390_serdes_irq_status,
3497
	.gpio_ops = &mv88e6352_gpio_ops,
3498
	.phylink_validate = mv88e6341_phylink_validate,
3499 3500
};

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

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

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

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

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

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

static const struct mv88e6xxx_ops mv88e6185_ops = {
3766
	/* MV88E6XXX_FAMILY_6185 */
3767 3768
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3769
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3770 3771
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3772
	.port_set_link = mv88e6xxx_port_set_link,
3773
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3774
	.port_set_speed = mv88e6185_port_set_speed,
3775
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
3776
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
3777
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
3778
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
3779
	.port_set_pause = mv88e6185_port_set_pause,
3780
	.port_link_state = mv88e6185_port_link_state,
3781
	.port_get_cmode = mv88e6185_port_get_cmode,
3782
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3783
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3784
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3785 3786
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3787
	.stats_get_stats = mv88e6095_stats_get_stats,
3788 3789
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3790
	.watchdog_ops = &mv88e6097_watchdog_ops,
3791
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3792
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
3793 3794
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
3795
	.reset = mv88e6185_g1_reset,
3796
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3797
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3798
	.phylink_validate = mv88e6185_phylink_validate,
3799 3800
};

3801
static const struct mv88e6xxx_ops mv88e6190_ops = {
3802
	/* MV88E6XXX_FAMILY_6390 */
3803
	.setup_errata = mv88e6390_setup_errata,
3804
	.irl_init_all = mv88e6390_g2_irl_init_all,
3805 3806
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3807 3808 3809 3810 3811 3812 3813
	.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,
3814
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
3815
	.port_tag_remap = mv88e6390_port_tag_remap,
3816
	.port_set_policy = mv88e6352_port_set_policy,
3817
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3818
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3819
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3820
	.port_pause_limit = mv88e6390_port_pause_limit,
3821
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3822
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3823
	.port_link_state = mv88e6352_port_link_state,
3824
	.port_get_cmode = mv88e6352_port_get_cmode,
3825
	.port_set_cmode = mv88e6390_port_set_cmode,
3826
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3827
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3828
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3829 3830
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3831
	.stats_get_stats = mv88e6390_stats_get_stats,
3832 3833
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3834
	.watchdog_ops = &mv88e6390_watchdog_ops,
3835
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3836
	.pot_clear = mv88e6xxx_g2_pot_clear,
3837
	.reset = mv88e6352_g1_reset,
3838
	.rmu_disable = mv88e6390_g1_rmu_disable,
3839 3840
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3841 3842
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3843
	.serdes_power = mv88e6390_serdes_power,
3844
	.serdes_get_lane = mv88e6390_serdes_get_lane,
3845
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3846
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
3847
	.serdes_irq_status = mv88e6390_serdes_irq_status,
3848
	.gpio_ops = &mv88e6352_gpio_ops,
3849
	.phylink_validate = mv88e6390_phylink_validate,
3850 3851 3852
};

static const struct mv88e6xxx_ops mv88e6190x_ops = {
3853
	/* MV88E6XXX_FAMILY_6390 */
3854
	.setup_errata = mv88e6390_setup_errata,
3855
	.irl_init_all = mv88e6390_g2_irl_init_all,
3856 3857
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3858 3859 3860 3861 3862 3863 3864
	.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,
3865
	.port_max_speed_mode = mv88e6390x_port_max_speed_mode,
3866
	.port_tag_remap = mv88e6390_port_tag_remap,
3867
	.port_set_policy = mv88e6352_port_set_policy,
3868
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3869
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3870
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3871
	.port_pause_limit = mv88e6390_port_pause_limit,
3872
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3873
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3874
	.port_link_state = mv88e6352_port_link_state,
3875
	.port_get_cmode = mv88e6352_port_get_cmode,
3876
	.port_set_cmode = mv88e6390x_port_set_cmode,
3877
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3878
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3879
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3880 3881
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3882
	.stats_get_stats = mv88e6390_stats_get_stats,
3883 3884
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3885
	.watchdog_ops = &mv88e6390_watchdog_ops,
3886
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3887
	.pot_clear = mv88e6xxx_g2_pot_clear,
3888
	.reset = mv88e6352_g1_reset,
3889
	.rmu_disable = mv88e6390_g1_rmu_disable,
3890 3891
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3892 3893
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3894
	.serdes_power = mv88e6390_serdes_power,
3895
	.serdes_get_lane = mv88e6390x_serdes_get_lane,
3896
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3897
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
3898
	.serdes_irq_status = mv88e6390_serdes_irq_status,
3899
	.gpio_ops = &mv88e6352_gpio_ops,
3900
	.phylink_validate = mv88e6390x_phylink_validate,
3901 3902 3903
};

static const struct mv88e6xxx_ops mv88e6191_ops = {
3904
	/* MV88E6XXX_FAMILY_6390 */
3905
	.setup_errata = mv88e6390_setup_errata,
3906
	.irl_init_all = mv88e6390_g2_irl_init_all,
3907 3908
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3909 3910 3911 3912 3913 3914 3915
	.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,
3916
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
3917
	.port_tag_remap = mv88e6390_port_tag_remap,
3918
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3919
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3920
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3921
	.port_pause_limit = mv88e6390_port_pause_limit,
3922
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3923
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3924
	.port_link_state = mv88e6352_port_link_state,
3925
	.port_get_cmode = mv88e6352_port_get_cmode,
3926
	.port_set_cmode = mv88e6390_port_set_cmode,
3927
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3928
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3929
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3930 3931
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3932
	.stats_get_stats = mv88e6390_stats_get_stats,
3933 3934
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3935
	.watchdog_ops = &mv88e6390_watchdog_ops,
3936
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3937
	.pot_clear = mv88e6xxx_g2_pot_clear,
3938
	.reset = mv88e6352_g1_reset,
3939
	.rmu_disable = mv88e6390_g1_rmu_disable,
3940 3941
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3942 3943
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3944
	.serdes_power = mv88e6390_serdes_power,
3945
	.serdes_get_lane = mv88e6390_serdes_get_lane,
3946
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3947
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
3948
	.serdes_irq_status = mv88e6390_serdes_irq_status,
3949 3950
	.avb_ops = &mv88e6390_avb_ops,
	.ptp_ops = &mv88e6352_ptp_ops,
3951
	.phylink_validate = mv88e6390_phylink_validate,
3952 3953
};

3954
static const struct mv88e6xxx_ops mv88e6240_ops = {
3955
	/* MV88E6XXX_FAMILY_6352 */
3956 3957
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3958
	.irl_init_all = mv88e6352_g2_irl_init_all,
3959 3960
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3961
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3962 3963
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3964
	.port_set_link = mv88e6xxx_port_set_link,
3965
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3966
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3967
	.port_set_speed = mv88e6352_port_set_speed,
3968
	.port_tag_remap = mv88e6095_port_tag_remap,
3969
	.port_set_policy = mv88e6352_port_set_policy,
3970
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3971
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3972
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3973
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3974
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3975
	.port_pause_limit = mv88e6097_port_pause_limit,
3976
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3977
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3978
	.port_link_state = mv88e6352_port_link_state,
3979
	.port_get_cmode = mv88e6352_port_get_cmode,
3980
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3981
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3982
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3983 3984
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3985
	.stats_get_stats = mv88e6095_stats_get_stats,
3986 3987
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3988
	.watchdog_ops = &mv88e6097_watchdog_ops,
3989
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3990
	.pot_clear = mv88e6xxx_g2_pot_clear,
3991
	.reset = mv88e6352_g1_reset,
3992
	.rmu_disable = mv88e6352_g1_rmu_disable,
3993 3994
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3995
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3996
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3997
	.serdes_get_lane = mv88e6352_serdes_get_lane,
3998
	.serdes_power = mv88e6352_serdes_power,
3999
	.serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
4000
	.serdes_irq_enable = mv88e6352_serdes_irq_enable,
4001
	.serdes_irq_status = mv88e6352_serdes_irq_status,
4002
	.gpio_ops = &mv88e6352_gpio_ops,
4003
	.avb_ops = &mv88e6352_avb_ops,
4004
	.ptp_ops = &mv88e6352_ptp_ops,
4005
	.phylink_validate = mv88e6352_phylink_validate,
4006 4007
};

4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042
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,
4043 4044
	.avb_ops = &mv88e6352_avb_ops,
	.ptp_ops = &mv88e6250_ptp_ops,
4045 4046 4047
	.phylink_validate = mv88e6065_phylink_validate,
};

4048
static const struct mv88e6xxx_ops mv88e6290_ops = {
4049
	/* MV88E6XXX_FAMILY_6390 */
4050
	.setup_errata = mv88e6390_setup_errata,
4051
	.irl_init_all = mv88e6390_g2_irl_init_all,
4052 4053
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4054 4055 4056 4057 4058 4059 4060
	.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,
4061
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
4062
	.port_tag_remap = mv88e6390_port_tag_remap,
4063
	.port_set_policy = mv88e6352_port_set_policy,
4064
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4065
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4066
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4067
	.port_pause_limit = mv88e6390_port_pause_limit,
4068
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4069
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4070
	.port_link_state = mv88e6352_port_link_state,
4071
	.port_get_cmode = mv88e6352_port_get_cmode,
4072
	.port_set_cmode = mv88e6390_port_set_cmode,
4073
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4074
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4075
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4076 4077
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4078
	.stats_get_stats = mv88e6390_stats_get_stats,
4079 4080
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4081
	.watchdog_ops = &mv88e6390_watchdog_ops,
4082
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4083
	.pot_clear = mv88e6xxx_g2_pot_clear,
4084
	.reset = mv88e6352_g1_reset,
4085
	.rmu_disable = mv88e6390_g1_rmu_disable,
4086 4087
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4088 4089
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4090
	.serdes_power = mv88e6390_serdes_power,
4091
	.serdes_get_lane = mv88e6390_serdes_get_lane,
4092
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4093
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4094
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4095
	.gpio_ops = &mv88e6352_gpio_ops,
4096
	.avb_ops = &mv88e6390_avb_ops,
4097
	.ptp_ops = &mv88e6352_ptp_ops,
4098
	.phylink_validate = mv88e6390_phylink_validate,
4099 4100
};

4101
static const struct mv88e6xxx_ops mv88e6320_ops = {
4102
	/* MV88E6XXX_FAMILY_6320 */
4103 4104
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4105
	.irl_init_all = mv88e6352_g2_irl_init_all,
4106 4107
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
4108
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4109 4110
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4111
	.port_set_link = mv88e6xxx_port_set_link,
4112
	.port_set_duplex = mv88e6xxx_port_set_duplex,
4113
	.port_set_speed = mv88e6185_port_set_speed,
4114
	.port_tag_remap = mv88e6095_port_tag_remap,
4115
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4116
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4117
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4118
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4119
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4120
	.port_pause_limit = mv88e6097_port_pause_limit,
4121
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4122
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4123
	.port_link_state = mv88e6352_port_link_state,
4124
	.port_get_cmode = mv88e6352_port_get_cmode,
4125
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4126
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4127
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4128 4129
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4130
	.stats_get_stats = mv88e6320_stats_get_stats,
4131 4132
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4133
	.watchdog_ops = &mv88e6390_watchdog_ops,
4134
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4135
	.pot_clear = mv88e6xxx_g2_pot_clear,
4136
	.reset = mv88e6352_g1_reset,
4137
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
4138
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
4139
	.gpio_ops = &mv88e6352_gpio_ops,
4140
	.avb_ops = &mv88e6352_avb_ops,
4141
	.ptp_ops = &mv88e6352_ptp_ops,
4142
	.phylink_validate = mv88e6185_phylink_validate,
4143 4144 4145
};

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

4187 4188
static const struct mv88e6xxx_ops mv88e6341_ops = {
	/* MV88E6XXX_FAMILY_6341 */
4189 4190
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4191
	.irl_init_all = mv88e6352_g2_irl_init_all,
4192 4193 4194 4195 4196 4197 4198 4199
	.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,
4200
	.port_set_speed = mv88e6341_port_set_speed,
4201
	.port_max_speed_mode = mv88e6341_port_max_speed_mode,
4202 4203 4204 4205
	.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,
4206
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4207
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4208
	.port_pause_limit = mv88e6097_port_pause_limit,
4209 4210
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4211
	.port_link_state = mv88e6352_port_link_state,
4212
	.port_get_cmode = mv88e6352_port_get_cmode,
4213
	.port_set_cmode = mv88e6341_port_set_cmode,
4214
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4215
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4216
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4217 4218 4219
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
4220 4221
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4222 4223
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
4224
	.pot_clear = mv88e6xxx_g2_pot_clear,
4225
	.reset = mv88e6352_g1_reset,
4226
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4227
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4228 4229
	.serdes_power = mv88e6390_serdes_power,
	.serdes_get_lane = mv88e6341_serdes_get_lane,
4230
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4231
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4232
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4233
	.gpio_ops = &mv88e6352_gpio_ops,
4234
	.avb_ops = &mv88e6390_avb_ops,
4235
	.ptp_ops = &mv88e6352_ptp_ops,
4236
	.phylink_validate = mv88e6341_phylink_validate,
4237 4238
};

4239
static const struct mv88e6xxx_ops mv88e6350_ops = {
4240
	/* MV88E6XXX_FAMILY_6351 */
4241 4242
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4243
	.irl_init_all = mv88e6352_g2_irl_init_all,
4244
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4245 4246
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4247
	.port_set_link = mv88e6xxx_port_set_link,
4248
	.port_set_duplex = mv88e6xxx_port_set_duplex,
4249
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4250
	.port_set_speed = mv88e6185_port_set_speed,
4251
	.port_tag_remap = mv88e6095_port_tag_remap,
4252
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4253
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4254
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4255
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4256
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4257
	.port_pause_limit = mv88e6097_port_pause_limit,
4258
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4259
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4260
	.port_link_state = mv88e6352_port_link_state,
4261
	.port_get_cmode = mv88e6352_port_get_cmode,
4262
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4263
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4264
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4265 4266
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
4267
	.stats_get_stats = mv88e6095_stats_get_stats,
4268 4269
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4270
	.watchdog_ops = &mv88e6097_watchdog_ops,
4271
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4272
	.pot_clear = mv88e6xxx_g2_pot_clear,
4273
	.reset = mv88e6352_g1_reset,
4274 4275
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4276
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4277
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4278
	.phylink_validate = mv88e6185_phylink_validate,
4279 4280 4281
};

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

static const struct mv88e6xxx_ops mv88e6352_ops = {
4326
	/* MV88E6XXX_FAMILY_6352 */
4327 4328
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4329
	.irl_init_all = mv88e6352_g2_irl_init_all,
4330 4331
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
4332
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4333 4334
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4335
	.port_set_link = mv88e6xxx_port_set_link,
4336
	.port_set_duplex = mv88e6xxx_port_set_duplex,
4337
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4338
	.port_set_speed = mv88e6352_port_set_speed,
4339
	.port_tag_remap = mv88e6095_port_tag_remap,
4340
	.port_set_policy = mv88e6352_port_set_policy,
4341
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4342
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4343
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4344
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4345
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4346
	.port_pause_limit = mv88e6097_port_pause_limit,
4347
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4348
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4349
	.port_link_state = mv88e6352_port_link_state,
4350
	.port_get_cmode = mv88e6352_port_get_cmode,
4351
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4352
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4353
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4354 4355
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
4356
	.stats_get_stats = mv88e6095_stats_get_stats,
4357 4358
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4359
	.watchdog_ops = &mv88e6097_watchdog_ops,
4360
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4361
	.pot_clear = mv88e6xxx_g2_pot_clear,
4362
	.reset = mv88e6352_g1_reset,
4363
	.rmu_disable = mv88e6352_g1_rmu_disable,
4364 4365
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4366
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4367
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4368
	.serdes_get_lane = mv88e6352_serdes_get_lane,
4369
	.serdes_power = mv88e6352_serdes_power,
4370
	.serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
4371
	.serdes_irq_enable = mv88e6352_serdes_irq_enable,
4372
	.serdes_irq_status = mv88e6352_serdes_irq_status,
4373
	.gpio_ops = &mv88e6352_gpio_ops,
4374
	.avb_ops = &mv88e6352_avb_ops,
4375
	.ptp_ops = &mv88e6352_ptp_ops,
4376 4377 4378
	.serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
	.serdes_get_strings = mv88e6352_serdes_get_strings,
	.serdes_get_stats = mv88e6352_serdes_get_stats,
4379
	.phylink_validate = mv88e6352_phylink_validate,
4380 4381
};

4382
static const struct mv88e6xxx_ops mv88e6390_ops = {
4383
	/* MV88E6XXX_FAMILY_6390 */
4384
	.setup_errata = mv88e6390_setup_errata,
4385
	.irl_init_all = mv88e6390_g2_irl_init_all,
4386 4387
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4388 4389 4390 4391 4392 4393 4394
	.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,
4395
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
4396
	.port_tag_remap = mv88e6390_port_tag_remap,
4397
	.port_set_policy = mv88e6352_port_set_policy,
4398
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4399
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4400
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4401
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4402
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4403
	.port_pause_limit = mv88e6390_port_pause_limit,
4404
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4405
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4406
	.port_link_state = mv88e6352_port_link_state,
4407
	.port_get_cmode = mv88e6352_port_get_cmode,
4408
	.port_set_cmode = mv88e6390_port_set_cmode,
4409
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4410
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4411
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4412 4413
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4414
	.stats_get_stats = mv88e6390_stats_get_stats,
4415 4416
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4417
	.watchdog_ops = &mv88e6390_watchdog_ops,
4418
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4419
	.pot_clear = mv88e6xxx_g2_pot_clear,
4420
	.reset = mv88e6352_g1_reset,
4421
	.rmu_disable = mv88e6390_g1_rmu_disable,
4422 4423
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4424 4425
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4426
	.serdes_power = mv88e6390_serdes_power,
4427
	.serdes_get_lane = mv88e6390_serdes_get_lane,
4428
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4429
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4430
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4431
	.gpio_ops = &mv88e6352_gpio_ops,
4432
	.avb_ops = &mv88e6390_avb_ops,
4433
	.ptp_ops = &mv88e6352_ptp_ops,
4434 4435 4436
	.serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
4437
	.phylink_validate = mv88e6390_phylink_validate,
4438 4439 4440
};

static const struct mv88e6xxx_ops mv88e6390x_ops = {
4441
	/* MV88E6XXX_FAMILY_6390 */
4442
	.setup_errata = mv88e6390_setup_errata,
4443
	.irl_init_all = mv88e6390_g2_irl_init_all,
4444 4445
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4446 4447 4448 4449 4450 4451 4452
	.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,
4453
	.port_max_speed_mode = mv88e6390x_port_max_speed_mode,
4454
	.port_tag_remap = mv88e6390_port_tag_remap,
4455
	.port_set_policy = mv88e6352_port_set_policy,
4456
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4457
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4458
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4459
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4460
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4461
	.port_pause_limit = mv88e6390_port_pause_limit,
4462
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4463
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4464
	.port_link_state = mv88e6352_port_link_state,
4465
	.port_get_cmode = mv88e6352_port_get_cmode,
4466
	.port_set_cmode = mv88e6390x_port_set_cmode,
4467
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4468
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4469
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4470 4471
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4472
	.stats_get_stats = mv88e6390_stats_get_stats,
4473 4474
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4475
	.watchdog_ops = &mv88e6390_watchdog_ops,
4476
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4477
	.pot_clear = mv88e6xxx_g2_pot_clear,
4478
	.reset = mv88e6352_g1_reset,
4479
	.rmu_disable = mv88e6390_g1_rmu_disable,
4480 4481
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4482 4483
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4484
	.serdes_power = mv88e6390_serdes_power,
4485
	.serdes_get_lane = mv88e6390x_serdes_get_lane,
4486
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4487
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4488
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4489
	.gpio_ops = &mv88e6352_gpio_ops,
4490
	.avb_ops = &mv88e6390_avb_ops,
4491
	.ptp_ops = &mv88e6352_ptp_ops,
4492
	.phylink_validate = mv88e6390x_phylink_validate,
4493 4494
};

4495 4496
static const struct mv88e6xxx_info mv88e6xxx_table[] = {
	[MV88E6085] = {
4497
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
4498 4499 4500
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6085",
		.num_databases = 4096,
4501
		.num_macs = 8192,
4502
		.num_ports = 10,
4503
		.num_internal_phys = 5,
4504
		.max_vid = 4095,
4505
		.port_base_addr = 0x10,
4506
		.phy_base_addr = 0x0,
4507
		.global1_addr = 0x1b,
4508
		.global2_addr = 0x1c,
4509
		.age_time_coeff = 15000,
4510
		.g1_irqs = 8,
4511
		.g2_irqs = 10,
4512
		.atu_move_port_mask = 0xf,
4513
		.pvt = true,
4514
		.multi_chip = true,
4515
		.tag_protocol = DSA_TAG_PROTO_DSA,
4516
		.ops = &mv88e6085_ops,
4517 4518 4519
	},

	[MV88E6095] = {
4520
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
4521 4522 4523
		.family = MV88E6XXX_FAMILY_6095,
		.name = "Marvell 88E6095/88E6095F",
		.num_databases = 256,
4524
		.num_macs = 8192,
4525
		.num_ports = 11,
4526
		.num_internal_phys = 0,
4527
		.max_vid = 4095,
4528
		.port_base_addr = 0x10,
4529
		.phy_base_addr = 0x0,
4530
		.global1_addr = 0x1b,
4531
		.global2_addr = 0x1c,
4532
		.age_time_coeff = 15000,
4533
		.g1_irqs = 8,
4534
		.atu_move_port_mask = 0xf,
4535
		.multi_chip = true,
4536
		.tag_protocol = DSA_TAG_PROTO_DSA,
4537
		.ops = &mv88e6095_ops,
4538 4539
	},

4540
	[MV88E6097] = {
4541
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
4542 4543 4544
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6097/88E6097F",
		.num_databases = 4096,
4545
		.num_macs = 8192,
4546
		.num_ports = 11,
4547
		.num_internal_phys = 8,
4548
		.max_vid = 4095,
4549
		.port_base_addr = 0x10,
4550
		.phy_base_addr = 0x0,
4551
		.global1_addr = 0x1b,
4552
		.global2_addr = 0x1c,
4553
		.age_time_coeff = 15000,
4554
		.g1_irqs = 8,
4555
		.g2_irqs = 10,
4556
		.atu_move_port_mask = 0xf,
4557
		.pvt = true,
4558
		.multi_chip = true,
4559
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4560 4561 4562
		.ops = &mv88e6097_ops,
	},

4563
	[MV88E6123] = {
4564
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
4565 4566 4567
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6123",
		.num_databases = 4096,
4568
		.num_macs = 1024,
4569
		.num_ports = 3,
4570
		.num_internal_phys = 5,
4571
		.max_vid = 4095,
4572
		.port_base_addr = 0x10,
4573
		.phy_base_addr = 0x0,
4574
		.global1_addr = 0x1b,
4575
		.global2_addr = 0x1c,
4576
		.age_time_coeff = 15000,
4577
		.g1_irqs = 9,
4578
		.g2_irqs = 10,
4579
		.atu_move_port_mask = 0xf,
4580
		.pvt = true,
4581
		.multi_chip = true,
4582
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4583
		.ops = &mv88e6123_ops,
4584 4585 4586
	},

	[MV88E6131] = {
4587
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
4588 4589 4590
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6131",
		.num_databases = 256,
4591
		.num_macs = 8192,
4592
		.num_ports = 8,
4593
		.num_internal_phys = 0,
4594
		.max_vid = 4095,
4595
		.port_base_addr = 0x10,
4596
		.phy_base_addr = 0x0,
4597
		.global1_addr = 0x1b,
4598
		.global2_addr = 0x1c,
4599
		.age_time_coeff = 15000,
4600
		.g1_irqs = 9,
4601
		.atu_move_port_mask = 0xf,
4602
		.multi_chip = true,
4603
		.tag_protocol = DSA_TAG_PROTO_DSA,
4604
		.ops = &mv88e6131_ops,
4605 4606
	},

4607
	[MV88E6141] = {
4608
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
4609
		.family = MV88E6XXX_FAMILY_6341,
4610
		.name = "Marvell 88E6141",
4611
		.num_databases = 4096,
4612
		.num_macs = 2048,
4613
		.num_ports = 6,
4614
		.num_internal_phys = 5,
4615
		.num_gpio = 11,
4616
		.max_vid = 4095,
4617
		.port_base_addr = 0x10,
4618
		.phy_base_addr = 0x10,
4619
		.global1_addr = 0x1b,
4620
		.global2_addr = 0x1c,
4621 4622
		.age_time_coeff = 3750,
		.atu_move_port_mask = 0x1f,
4623
		.g1_irqs = 9,
4624
		.g2_irqs = 10,
4625
		.pvt = true,
4626
		.multi_chip = true,
4627 4628 4629 4630
		.tag_protocol = DSA_TAG_PROTO_EDSA,
		.ops = &mv88e6141_ops,
	},

4631
	[MV88E6161] = {
4632
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
4633 4634 4635
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6161",
		.num_databases = 4096,
4636
		.num_macs = 1024,
4637
		.num_ports = 6,
4638
		.num_internal_phys = 5,
4639
		.max_vid = 4095,
4640
		.port_base_addr = 0x10,
4641
		.phy_base_addr = 0x0,
4642
		.global1_addr = 0x1b,
4643
		.global2_addr = 0x1c,
4644
		.age_time_coeff = 15000,
4645
		.g1_irqs = 9,
4646
		.g2_irqs = 10,
4647
		.atu_move_port_mask = 0xf,
4648
		.pvt = true,
4649
		.multi_chip = true,
4650
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4651
		.ptp_support = true,
4652
		.ops = &mv88e6161_ops,
4653 4654 4655
	},

	[MV88E6165] = {
4656
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
4657 4658 4659
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6165",
		.num_databases = 4096,
4660
		.num_macs = 8192,
4661
		.num_ports = 6,
4662
		.num_internal_phys = 0,
4663
		.max_vid = 4095,
4664
		.port_base_addr = 0x10,
4665
		.phy_base_addr = 0x0,
4666
		.global1_addr = 0x1b,
4667
		.global2_addr = 0x1c,
4668
		.age_time_coeff = 15000,
4669
		.g1_irqs = 9,
4670
		.g2_irqs = 10,
4671
		.atu_move_port_mask = 0xf,
4672
		.pvt = true,
4673
		.multi_chip = true,
4674
		.tag_protocol = DSA_TAG_PROTO_DSA,
4675
		.ptp_support = true,
4676
		.ops = &mv88e6165_ops,
4677 4678 4679
	},

	[MV88E6171] = {
4680
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
4681 4682 4683
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6171",
		.num_databases = 4096,
4684
		.num_macs = 8192,
4685
		.num_ports = 7,
4686
		.num_internal_phys = 5,
4687
		.max_vid = 4095,
4688
		.port_base_addr = 0x10,
4689
		.phy_base_addr = 0x0,
4690
		.global1_addr = 0x1b,
4691
		.global2_addr = 0x1c,
4692
		.age_time_coeff = 15000,
4693
		.g1_irqs = 9,
4694
		.g2_irqs = 10,
4695
		.atu_move_port_mask = 0xf,
4696
		.pvt = true,
4697
		.multi_chip = true,
4698
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4699
		.ops = &mv88e6171_ops,
4700 4701 4702
	},

	[MV88E6172] = {
4703
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
4704 4705 4706
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6172",
		.num_databases = 4096,
4707
		.num_macs = 8192,
4708
		.num_ports = 7,
4709
		.num_internal_phys = 5,
4710
		.num_gpio = 15,
4711
		.max_vid = 4095,
4712
		.port_base_addr = 0x10,
4713
		.phy_base_addr = 0x0,
4714
		.global1_addr = 0x1b,
4715
		.global2_addr = 0x1c,
4716
		.age_time_coeff = 15000,
4717
		.g1_irqs = 9,
4718
		.g2_irqs = 10,
4719
		.atu_move_port_mask = 0xf,
4720
		.pvt = true,
4721
		.multi_chip = true,
4722
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4723
		.ops = &mv88e6172_ops,
4724 4725 4726
	},

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

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

	[MV88E6185] = {
4774
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
4775 4776 4777
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6185",
		.num_databases = 256,
4778
		.num_macs = 8192,
4779
		.num_ports = 10,
4780
		.num_internal_phys = 0,
4781
		.max_vid = 4095,
4782
		.port_base_addr = 0x10,
4783
		.phy_base_addr = 0x0,
4784
		.global1_addr = 0x1b,
4785
		.global2_addr = 0x1c,
4786
		.age_time_coeff = 15000,
4787
		.g1_irqs = 8,
4788
		.atu_move_port_mask = 0xf,
4789
		.multi_chip = true,
4790
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4791
		.ops = &mv88e6185_ops,
4792 4793
	},

4794
	[MV88E6190] = {
4795
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
4796 4797 4798
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190",
		.num_databases = 4096,
4799
		.num_macs = 16384,
4800
		.num_ports = 11,	/* 10 + Z80 */
4801
		.num_internal_phys = 9,
4802
		.num_gpio = 16,
4803
		.max_vid = 8191,
4804
		.port_base_addr = 0x0,
4805
		.phy_base_addr = 0x0,
4806
		.global1_addr = 0x1b,
4807
		.global2_addr = 0x1c,
4808
		.tag_protocol = DSA_TAG_PROTO_DSA,
4809
		.age_time_coeff = 3750,
4810
		.g1_irqs = 9,
4811
		.g2_irqs = 14,
4812
		.pvt = true,
4813
		.multi_chip = true,
4814
		.atu_move_port_mask = 0x1f,
4815 4816 4817 4818
		.ops = &mv88e6190_ops,
	},

	[MV88E6190X] = {
4819
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
4820 4821 4822
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190X",
		.num_databases = 4096,
4823
		.num_macs = 16384,
4824
		.num_ports = 11,	/* 10 + Z80 */
4825
		.num_internal_phys = 9,
4826
		.num_gpio = 16,
4827
		.max_vid = 8191,
4828
		.port_base_addr = 0x0,
4829
		.phy_base_addr = 0x0,
4830
		.global1_addr = 0x1b,
4831
		.global2_addr = 0x1c,
4832
		.age_time_coeff = 3750,
4833
		.g1_irqs = 9,
4834
		.g2_irqs = 14,
4835
		.atu_move_port_mask = 0x1f,
4836
		.pvt = true,
4837
		.multi_chip = true,
4838
		.tag_protocol = DSA_TAG_PROTO_DSA,
4839 4840 4841 4842
		.ops = &mv88e6190x_ops,
	},

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

4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876
	[MV88E6220] = {
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6220,
		.family = MV88E6XXX_FAMILY_6250,
		.name = "Marvell 88E6220",
		.num_databases = 64,

		/* Ports 2-4 are not routed to pins
		 * => usable ports 0, 1, 5, 6
		 */
		.num_ports = 7,
		.num_internal_phys = 2,
4877
		.invalid_port_mask = BIT(2) | BIT(3) | BIT(4),
4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888
		.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,
4889
		.ptp_support = true,
4890 4891 4892
		.ops = &mv88e6250_ops,
	},

4893
	[MV88E6240] = {
4894
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
4895 4896 4897
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6240",
		.num_databases = 4096,
4898
		.num_macs = 8192,
4899
		.num_ports = 7,
4900
		.num_internal_phys = 5,
4901
		.num_gpio = 15,
4902
		.max_vid = 4095,
4903
		.port_base_addr = 0x10,
4904
		.phy_base_addr = 0x0,
4905
		.global1_addr = 0x1b,
4906
		.global2_addr = 0x1c,
4907
		.age_time_coeff = 15000,
4908
		.g1_irqs = 9,
4909
		.g2_irqs = 10,
4910
		.atu_move_port_mask = 0xf,
4911
		.pvt = true,
4912
		.multi_chip = true,
4913
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4914
		.ptp_support = true,
4915
		.ops = &mv88e6240_ops,
4916 4917
	},

4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935
	[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,
4936
		.ptp_support = true,
4937 4938 4939
		.ops = &mv88e6250_ops,
	},

4940
	[MV88E6290] = {
4941
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
4942 4943 4944 4945
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6290",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4946
		.num_internal_phys = 9,
4947
		.num_gpio = 16,
4948
		.max_vid = 8191,
4949
		.port_base_addr = 0x0,
4950
		.phy_base_addr = 0x0,
4951
		.global1_addr = 0x1b,
4952
		.global2_addr = 0x1c,
4953
		.age_time_coeff = 3750,
4954
		.g1_irqs = 9,
4955
		.g2_irqs = 14,
4956
		.atu_move_port_mask = 0x1f,
4957
		.pvt = true,
4958
		.multi_chip = true,
4959
		.tag_protocol = DSA_TAG_PROTO_DSA,
4960
		.ptp_support = true,
4961 4962 4963
		.ops = &mv88e6290_ops,
	},

4964
	[MV88E6320] = {
4965
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
4966 4967 4968
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6320",
		.num_databases = 4096,
4969
		.num_macs = 8192,
4970
		.num_ports = 7,
4971
		.num_internal_phys = 5,
4972
		.num_gpio = 15,
4973
		.max_vid = 4095,
4974
		.port_base_addr = 0x10,
4975
		.phy_base_addr = 0x0,
4976
		.global1_addr = 0x1b,
4977
		.global2_addr = 0x1c,
4978
		.age_time_coeff = 15000,
4979
		.g1_irqs = 8,
4980
		.g2_irqs = 10,
4981
		.atu_move_port_mask = 0xf,
4982
		.pvt = true,
4983
		.multi_chip = true,
4984
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4985
		.ptp_support = true,
4986
		.ops = &mv88e6320_ops,
4987 4988 4989
	},

	[MV88E6321] = {
4990
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
4991 4992 4993
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6321",
		.num_databases = 4096,
4994
		.num_macs = 8192,
4995
		.num_ports = 7,
4996
		.num_internal_phys = 5,
4997
		.num_gpio = 15,
4998
		.max_vid = 4095,
4999
		.port_base_addr = 0x10,
5000
		.phy_base_addr = 0x0,
5001
		.global1_addr = 0x1b,
5002
		.global2_addr = 0x1c,
5003
		.age_time_coeff = 15000,
5004
		.g1_irqs = 8,
5005
		.g2_irqs = 10,
5006
		.atu_move_port_mask = 0xf,
5007
		.multi_chip = true,
5008
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5009
		.ptp_support = true,
5010
		.ops = &mv88e6321_ops,
5011 5012
	},

5013
	[MV88E6341] = {
5014
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
5015 5016 5017
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
5018
		.num_macs = 2048,
5019
		.num_internal_phys = 5,
5020
		.num_ports = 6,
5021
		.num_gpio = 11,
5022
		.max_vid = 4095,
5023
		.port_base_addr = 0x10,
5024
		.phy_base_addr = 0x10,
5025
		.global1_addr = 0x1b,
5026
		.global2_addr = 0x1c,
5027
		.age_time_coeff = 3750,
5028
		.atu_move_port_mask = 0x1f,
5029
		.g1_irqs = 9,
5030
		.g2_irqs = 10,
5031
		.pvt = true,
5032
		.multi_chip = true,
5033
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5034
		.ptp_support = true,
5035 5036 5037
		.ops = &mv88e6341_ops,
	},

5038
	[MV88E6350] = {
5039
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
5040 5041 5042
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6350",
		.num_databases = 4096,
5043
		.num_macs = 8192,
5044
		.num_ports = 7,
5045
		.num_internal_phys = 5,
5046
		.max_vid = 4095,
5047
		.port_base_addr = 0x10,
5048
		.phy_base_addr = 0x0,
5049
		.global1_addr = 0x1b,
5050
		.global2_addr = 0x1c,
5051
		.age_time_coeff = 15000,
5052
		.g1_irqs = 9,
5053
		.g2_irqs = 10,
5054
		.atu_move_port_mask = 0xf,
5055
		.pvt = true,
5056
		.multi_chip = true,
5057
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5058
		.ops = &mv88e6350_ops,
5059 5060 5061
	},

	[MV88E6351] = {
5062
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
5063 5064 5065
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6351",
		.num_databases = 4096,
5066
		.num_macs = 8192,
5067
		.num_ports = 7,
5068
		.num_internal_phys = 5,
5069
		.max_vid = 4095,
5070
		.port_base_addr = 0x10,
5071
		.phy_base_addr = 0x0,
5072
		.global1_addr = 0x1b,
5073
		.global2_addr = 0x1c,
5074
		.age_time_coeff = 15000,
5075
		.g1_irqs = 9,
5076
		.g2_irqs = 10,
5077
		.atu_move_port_mask = 0xf,
5078
		.pvt = true,
5079
		.multi_chip = true,
5080
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5081
		.ops = &mv88e6351_ops,
5082 5083 5084
	},

	[MV88E6352] = {
5085
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
5086 5087 5088
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6352",
		.num_databases = 4096,
5089
		.num_macs = 8192,
5090
		.num_ports = 7,
5091
		.num_internal_phys = 5,
5092
		.num_gpio = 15,
5093
		.max_vid = 4095,
5094
		.port_base_addr = 0x10,
5095
		.phy_base_addr = 0x0,
5096
		.global1_addr = 0x1b,
5097
		.global2_addr = 0x1c,
5098
		.age_time_coeff = 15000,
5099
		.g1_irqs = 9,
5100
		.g2_irqs = 10,
5101
		.atu_move_port_mask = 0xf,
5102
		.pvt = true,
5103
		.multi_chip = true,
5104
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5105
		.ptp_support = true,
5106
		.ops = &mv88e6352_ops,
5107
	},
5108
	[MV88E6390] = {
5109
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
5110 5111 5112
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390",
		.num_databases = 4096,
5113
		.num_macs = 16384,
5114
		.num_ports = 11,	/* 10 + Z80 */
5115
		.num_internal_phys = 9,
5116
		.num_gpio = 16,
5117
		.max_vid = 8191,
5118
		.port_base_addr = 0x0,
5119
		.phy_base_addr = 0x0,
5120
		.global1_addr = 0x1b,
5121
		.global2_addr = 0x1c,
5122
		.age_time_coeff = 3750,
5123
		.g1_irqs = 9,
5124
		.g2_irqs = 14,
5125
		.atu_move_port_mask = 0x1f,
5126
		.pvt = true,
5127
		.multi_chip = true,
5128
		.tag_protocol = DSA_TAG_PROTO_DSA,
5129
		.ptp_support = true,
5130 5131 5132
		.ops = &mv88e6390_ops,
	},
	[MV88E6390X] = {
5133
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
5134 5135 5136
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390X",
		.num_databases = 4096,
5137
		.num_macs = 16384,
5138
		.num_ports = 11,	/* 10 + Z80 */
5139
		.num_internal_phys = 9,
5140
		.num_gpio = 16,
5141
		.max_vid = 8191,
5142
		.port_base_addr = 0x0,
5143
		.phy_base_addr = 0x0,
5144
		.global1_addr = 0x1b,
5145
		.global2_addr = 0x1c,
5146
		.age_time_coeff = 3750,
5147
		.g1_irqs = 9,
5148
		.g2_irqs = 14,
5149
		.atu_move_port_mask = 0x1f,
5150
		.pvt = true,
5151
		.multi_chip = true,
5152
		.tag_protocol = DSA_TAG_PROTO_DSA,
5153
		.ptp_support = true,
5154 5155
		.ops = &mv88e6390x_ops,
	},
5156 5157
};

5158
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
5159
{
5160
	int i;
5161

5162 5163 5164
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
5165 5166 5167 5168

	return NULL;
}

5169
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
5170 5171
{
	const struct mv88e6xxx_info *info;
5172 5173 5174
	unsigned int prod_num, rev;
	u16 id;
	int err;
5175

5176
	mv88e6xxx_reg_lock(chip);
5177
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
5178
	mv88e6xxx_reg_unlock(chip);
5179 5180
	if (err)
		return err;
5181

5182 5183
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
5184 5185 5186 5187 5188

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

5189
	/* Update the compatible info with the probed one */
5190
	chip->info = info;
5191

5192 5193 5194 5195
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

5196 5197
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
5198 5199 5200 5201

	return 0;
}

5202
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
5203
{
5204
	struct mv88e6xxx_chip *chip;
5205

5206 5207
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
5208 5209
		return NULL;

5210
	chip->dev = dev;
5211

5212
	mutex_init(&chip->reg_lock);
5213
	INIT_LIST_HEAD(&chip->mdios);
5214
	idr_init(&chip->policies);
5215

5216
	return chip;
5217 5218
}

5219
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
5220 5221
							int port,
							enum dsa_tag_protocol m)
5222
{
V
Vivien Didelot 已提交
5223
	struct mv88e6xxx_chip *chip = ds->priv;
5224

5225
	return chip->info->tag_protocol;
5226 5227
}

5228
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
5229
				      const struct switchdev_obj_port_mdb *mdb)
5230 5231 5232 5233 5234 5235 5236 5237 5238
{
	/* 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,
5239
				   const struct switchdev_obj_port_mdb *mdb)
5240
{
V
Vivien Didelot 已提交
5241
	struct mv88e6xxx_chip *chip = ds->priv;
5242

5243
	mv88e6xxx_reg_lock(chip);
5244
	if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
5245
					 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
5246 5247
		dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
			port);
5248
	mv88e6xxx_reg_unlock(chip);
5249 5250 5251 5252 5253
}

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

5257
	mv88e6xxx_reg_lock(chip);
5258
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 0);
5259
	mv88e6xxx_reg_unlock(chip);
5260 5261 5262 5263

	return err;
}

5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330
static int mv88e6xxx_port_mirror_add(struct dsa_switch *ds, int port,
				     struct dsa_mall_mirror_tc_entry *mirror,
				     bool ingress)
{
	enum mv88e6xxx_egress_direction direction = ingress ?
						MV88E6XXX_EGRESS_DIR_INGRESS :
						MV88E6XXX_EGRESS_DIR_EGRESS;
	struct mv88e6xxx_chip *chip = ds->priv;
	bool other_mirrors = false;
	int i;
	int err;

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

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

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

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

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

	return err;
}

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

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

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

	/* Reset egress port when no other mirror is active */
	if (!other_mirrors) {
		if (chip->info->ops->set_egress_port(chip,
						     direction,
						     dsa_upstream_port(ds,
5331
								       port)))
5332 5333 5334 5335 5336 5337
			dev_err(ds->dev, "failed to set egress port\n");
	}

	mutex_unlock(&chip->reg_lock);
}

5338 5339 5340 5341 5342 5343
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;

5344
	mv88e6xxx_reg_lock(chip);
5345 5346 5347 5348
	if (chip->info->ops->port_set_egress_floods)
		err = chip->info->ops->port_set_egress_floods(chip, port,
							      unicast,
							      multicast);
5349
	mv88e6xxx_reg_unlock(chip);
5350 5351 5352 5353

	return err;
}

5354
static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
5355
	.get_tag_protocol	= mv88e6xxx_get_tag_protocol,
5356
	.setup			= mv88e6xxx_setup,
5357
	.teardown		= mv88e6xxx_teardown,
5358 5359 5360 5361 5362
	.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,
5363 5364 5365
	.get_strings		= mv88e6xxx_get_strings,
	.get_ethtool_stats	= mv88e6xxx_get_ethtool_stats,
	.get_sset_count		= mv88e6xxx_get_sset_count,
5366 5367
	.port_enable		= mv88e6xxx_port_enable,
	.port_disable		= mv88e6xxx_port_disable,
V
Vivien Didelot 已提交
5368 5369
	.get_mac_eee		= mv88e6xxx_get_mac_eee,
	.set_mac_eee		= mv88e6xxx_set_mac_eee,
5370
	.get_eeprom_len		= mv88e6xxx_get_eeprom_len,
5371 5372 5373 5374
	.get_eeprom		= mv88e6xxx_get_eeprom,
	.set_eeprom		= mv88e6xxx_set_eeprom,
	.get_regs_len		= mv88e6xxx_get_regs_len,
	.get_regs		= mv88e6xxx_get_regs,
5375 5376
	.get_rxnfc		= mv88e6xxx_get_rxnfc,
	.set_rxnfc		= mv88e6xxx_set_rxnfc,
5377
	.set_ageing_time	= mv88e6xxx_set_ageing_time,
5378 5379
	.port_bridge_join	= mv88e6xxx_port_bridge_join,
	.port_bridge_leave	= mv88e6xxx_port_bridge_leave,
5380
	.port_egress_floods	= mv88e6xxx_port_egress_floods,
5381
	.port_stp_state_set	= mv88e6xxx_port_stp_state_set,
5382
	.port_fast_age		= mv88e6xxx_port_fast_age,
5383 5384 5385 5386 5387 5388 5389
	.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,
5390 5391 5392
	.port_mdb_prepare       = mv88e6xxx_port_mdb_prepare,
	.port_mdb_add           = mv88e6xxx_port_mdb_add,
	.port_mdb_del           = mv88e6xxx_port_mdb_del,
5393 5394
	.port_mirror_add	= mv88e6xxx_port_mirror_add,
	.port_mirror_del	= mv88e6xxx_port_mirror_del,
5395 5396
	.crosschip_bridge_join	= mv88e6xxx_crosschip_bridge_join,
	.crosschip_bridge_leave	= mv88e6xxx_crosschip_bridge_leave,
5397 5398 5399 5400 5401
	.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,
5402 5403
	.devlink_param_get	= mv88e6xxx_devlink_param_get,
	.devlink_param_set	= mv88e6xxx_devlink_param_set,
5404 5405
};

5406
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
5407
{
5408
	struct device *dev = chip->dev;
5409 5410
	struct dsa_switch *ds;

5411
	ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
5412 5413 5414
	if (!ds)
		return -ENOMEM;

5415 5416
	ds->dev = dev;
	ds->num_ports = mv88e6xxx_num_ports(chip);
5417
	ds->priv = chip;
5418
	ds->dev = dev;
5419
	ds->ops = &mv88e6xxx_switch_ops;
5420 5421
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
5422 5423 5424

	dev_set_drvdata(dev, ds);

5425
	return dsa_register_switch(ds);
5426 5427
}

5428
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
5429
{
5430
	dsa_unregister_switch(chip->ds);
5431 5432
}

5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445
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;
}

5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460
/* 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);

5461
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
5462
{
5463
	struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
5464
	const struct mv88e6xxx_info *compat_info = NULL;
5465
	struct device *dev = &mdiodev->dev;
5466
	struct device_node *np = dev->of_node;
5467
	struct mv88e6xxx_chip *chip;
5468
	int port;
5469
	int err;
5470

5471 5472 5473
	if (!np && !pdata)
		return -EINVAL;

5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492
	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;
		}
	}

5493 5494 5495
	if (!compat_info)
		return -EINVAL;

5496
	chip = mv88e6xxx_alloc_chip(dev);
5497 5498 5499 5500
	if (!chip) {
		err = -ENOMEM;
		goto out;
	}
5501

5502
	chip->info = compat_info;
5503

5504
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
5505
	if (err)
5506
		goto out;
5507

5508
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
5509 5510 5511 5512
	if (IS_ERR(chip->reset)) {
		err = PTR_ERR(chip->reset);
		goto out;
	}
5513 5514
	if (chip->reset)
		usleep_range(1000, 2000);
5515

5516
	err = mv88e6xxx_detect(chip);
5517
	if (err)
5518
		goto out;
5519

5520 5521
	mv88e6xxx_phy_init(chip);

5522 5523 5524 5525 5526 5527 5528
	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;
	}
5529

5530
	mv88e6xxx_reg_lock(chip);
5531
	err = mv88e6xxx_switch_reset(chip);
5532
	mv88e6xxx_reg_unlock(chip);
5533 5534 5535
	if (err)
		goto out;

5536 5537 5538 5539 5540 5541
	if (np) {
		chip->irq = of_irq_get(np, 0);
		if (chip->irq == -EPROBE_DEFER) {
			err = chip->irq;
			goto out;
		}
5542 5543
	}

5544 5545 5546
	if (pdata)
		chip->irq = pdata->irq;

5547
	/* Has to be performed before the MDIO bus is created, because
5548
	 * the PHYs will link their interrupts to these interrupt
5549 5550
	 * controllers
	 */
5551
	mv88e6xxx_reg_lock(chip);
5552
	if (chip->irq > 0)
5553
		err = mv88e6xxx_g1_irq_setup(chip);
5554 5555
	else
		err = mv88e6xxx_irq_poll_setup(chip);
5556
	mv88e6xxx_reg_unlock(chip);
5557

5558 5559
	if (err)
		goto out;
5560

5561 5562
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
5563
		if (err)
5564
			goto out_g1_irq;
5565 5566
	}

5567 5568 5569 5570 5571 5572 5573 5574
	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;

5575
	err = mv88e6xxx_mdios_register(chip, np);
5576
	if (err)
5577
		goto out_g1_vtu_prob_irq;
5578

5579
	err = mv88e6xxx_register_switch(chip);
5580 5581
	if (err)
		goto out_mdio;
5582

5583
	return 0;
5584 5585

out_mdio:
5586
	mv88e6xxx_mdios_unregister(chip);
5587
out_g1_vtu_prob_irq:
5588
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
5589
out_g1_atu_prob_irq:
5590
	mv88e6xxx_g1_atu_prob_irq_free(chip);
5591
out_g2_irq:
5592
	if (chip->info->g2_irqs > 0)
5593 5594
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
5595
	if (chip->irq > 0)
5596
		mv88e6xxx_g1_irq_free(chip);
5597 5598
	else
		mv88e6xxx_irq_poll_free(chip);
5599
out:
5600 5601 5602
	if (pdata)
		dev_put(pdata->netdev);

5603
	return err;
5604
}
5605 5606 5607 5608

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

5611 5612
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
5613
		mv88e6xxx_ptp_free(chip);
5614
	}
5615

5616
	mv88e6xxx_phy_destroy(chip);
5617
	mv88e6xxx_unregister_switch(chip);
5618
	mv88e6xxx_mdios_unregister(chip);
5619

5620 5621 5622 5623 5624 5625 5626
	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)
5627
		mv88e6xxx_g1_irq_free(chip);
5628 5629
	else
		mv88e6xxx_irq_poll_free(chip);
5630 5631 5632
}

static const struct of_device_id mv88e6xxx_of_match[] = {
5633 5634 5635 5636
	{
		.compatible = "marvell,mv88e6085",
		.data = &mv88e6xxx_table[MV88E6085],
	},
5637 5638 5639 5640
	{
		.compatible = "marvell,mv88e6190",
		.data = &mv88e6xxx_table[MV88E6190],
	},
5641 5642 5643 5644
	{
		.compatible = "marvell,mv88e6250",
		.data = &mv88e6xxx_table[MV88E6250],
	},
5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655
	{ /* 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,
5656
		.pm = &mv88e6xxx_pm_ops,
5657 5658 5659
	},
};

5660
mdio_module_driver(mv88e6xxx_driver);
5661 5662 5663 5664

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