chip.c 141.7 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
	mv88e6xxx_reg_unlock(chip);
344 345
	err = request_threaded_irq(chip->irq, NULL,
				   mv88e6xxx_g1_irq_thread_fn,
346
				   IRQF_ONESHOT | IRQF_SHARED,
347
				   dev_name(chip->dev), chip);
348
	mv88e6xxx_reg_lock(chip);
349 350 351 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
	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);

377
	chip->kworker = kthread_create_worker(0, "%s", dev_name(chip->dev));
378 379 380 381 382 383 384 385 386 387 388 389 390
	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);
391

392
	mv88e6xxx_reg_lock(chip);
393
	mv88e6xxx_g1_irq_free_common(chip);
394
	mv88e6xxx_reg_unlock(chip);
395 396
}

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

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

407 408 409 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 &&
	    state.duplex == duplex)
		return 0;

423
	/* Port's MAC control must not be changed unless the link is down */
424
	err = chip->info->ops->port_set_link(chip, port, LINK_FORCED_DOWN);
425 426 427 428 429 430 431 432 433
	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;
	}

434 435 436
	if (speed == SPEED_MAX && chip->info->ops->port_max_speed_mode)
		mode = chip->info->ops->port_max_speed_mode(port);

437 438 439 440 441 442
	if (chip->info->ops->port_set_pause) {
		err = chip->info->ops->port_set_pause(chip, port, pause);
		if (err)
			goto restore_link;
	}

443 444 445 446 447 448 449 450 451 452 453 454
	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;
	}

455 456 457 458 459 460
	if (chip->info->ops->port_set_cmode) {
		err = chip->info->ops->port_set_cmode(chip, port, mode);
		if (err && err != -EOPNOTSUPP)
			goto restore_link;
	}

461 462 463
	err = 0;
restore_link:
	if (chip->info->ops->port_set_link(chip, port, link))
464
		dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
465 466 467 468

	return err;
}

469 470 471 472 473 474 475
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;
}

476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
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);
}

502 503 504 505 506 507 508 509 510 511 512 513 514 515
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);
}

516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
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)
{
531
	if (port >= 9) {
532
		phylink_set(mask, 2500baseX_Full);
533 534
		phylink_set(mask, 2500baseT_Full);
	}
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554

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

555 556 557 558
static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
			       unsigned long *supported,
			       struct phylink_link_state *state)
{
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577
	__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);
578 579 580 581 582 583 584 585
}

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

586
	mv88e6xxx_reg_lock(chip);
587 588 589 590
	if (chip->info->ops->port_link_state)
		err = chip->info->ops->port_link_state(chip, port, state);
	else
		err = -EOPNOTSUPP;
591
	mv88e6xxx_reg_unlock(chip);
592 593 594 595 596 597 598 599 600

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

603
	if ((mode == MLO_AN_PHY) && mv88e6xxx_phy_is_internal(ds, port))
604 605 606 607 608 609
		return;

	if (mode == MLO_AN_FIXED) {
		link = LINK_FORCED_UP;
		speed = state->speed;
		duplex = state->duplex;
610 611 612 613
	} else if (!mv88e6xxx_phy_is_internal(ds, port)) {
		link = state->link;
		speed = state->speed;
		duplex = state->duplex;
614 615 616 617 618
	} else {
		speed = SPEED_UNFORCED;
		duplex = DUPLEX_UNFORCED;
		link = LINK_UNFORCED;
	}
619
	pause = !!phylink_test(state->advertising, Pause);
620

621
	mv88e6xxx_reg_lock(chip);
622
	err = mv88e6xxx_port_setup_mac(chip, port, link, speed, duplex, pause,
623
				       state->interface);
624
	mv88e6xxx_reg_unlock(chip);
625 626 627 628 629 630 631 632 633 634

	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;

635
	mv88e6xxx_reg_lock(chip);
636
	err = chip->info->ops->port_set_link(chip, port, link);
637
	mv88e6xxx_reg_unlock(chip);
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658

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

659
static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
660
{
661 662
	if (!chip->info->ops->stats_snapshot)
		return -EOPNOTSUPP;
663

664
	return chip->info->ops->stats_snapshot(chip, port);
665 666
}

667
static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
668 669 670 671 672 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
	{ "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, },
727 728
};

729
static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
730
					    struct mv88e6xxx_hw_stat *s,
731 732
					    int port, u16 bank1_select,
					    u16 histogram)
733 734 735
{
	u32 low;
	u32 high = 0;
736
	u16 reg = 0;
737
	int err;
738 739
	u64 value;

740
	switch (s->type) {
741
	case STATS_TYPE_PORT:
742 743
		err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
		if (err)
744
			return U64_MAX;
745

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

770 771
static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data, int types)
772
{
773 774
	struct mv88e6xxx_hw_stat *stat;
	int i, j;
775

776 777
	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
		stat = &mv88e6xxx_hw_stats[i];
778
		if (stat->type & types) {
779 780 781 782
			memcpy(data + j * ETH_GSTRING_LEN, stat->string,
			       ETH_GSTRING_LEN);
			j++;
		}
783
	}
784 785

	return j;
786 787
}

788 789
static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
790
{
791 792
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_PORT);
793 794
}

795 796 797 798 799 800
static int mv88e6250_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
{
	return mv88e6xxx_stats_get_strings(chip, data, STATS_TYPE_BANK0);
}

801 802
static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
803
{
804 805
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
806 807
}

808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825
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);
}

826
static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
827
				  u32 stringset, uint8_t *data)
828
{
V
Vivien Didelot 已提交
829
	struct mv88e6xxx_chip *chip = ds->priv;
830
	int count = 0;
831

832 833 834
	if (stringset != ETH_SS_STATS)
		return;

835
	mv88e6xxx_reg_lock(chip);
836

837
	if (chip->info->ops->stats_get_strings)
838 839 840 841
		count = chip->info->ops->stats_get_strings(chip, data);

	if (chip->info->ops->serdes_get_strings) {
		data += count * ETH_GSTRING_LEN;
842
		count = chip->info->ops->serdes_get_strings(chip, port, data);
843
	}
844

845 846 847
	data += count * ETH_GSTRING_LEN;
	mv88e6xxx_atu_vtu_get_strings(data);

848
	mv88e6xxx_reg_unlock(chip);
849 850 851 852 853
}

static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
					  int types)
{
854 855 856 857 858
	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];
859
		if (stat->type & types)
860 861 862
			j++;
	}
	return j;
863 864
}

865 866 867 868 869 870
static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
{
	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
					      STATS_TYPE_PORT);
}

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

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

882
static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
883 884
{
	struct mv88e6xxx_chip *chip = ds->priv;
885 886
	int serdes_count = 0;
	int count = 0;
887

888 889 890
	if (sset != ETH_SS_STATS)
		return 0;

891
	mv88e6xxx_reg_lock(chip);
892
	if (chip->info->ops->stats_get_sset_count)
893 894 895 896 897 898 899
		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);
900
	if (serdes_count < 0) {
901
		count = serdes_count;
902 903 904 905 906
		goto out;
	}
	count += serdes_count;
	count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);

907
out:
908
	mv88e6xxx_reg_unlock(chip);
909

910
	return count;
911 912
}

913 914 915
static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data, int types,
				     u16 bank1_select, u16 histogram)
916 917 918 919 920 921 922
{
	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) {
923
			mv88e6xxx_reg_lock(chip);
924 925 926
			data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
							      bank1_select,
							      histogram);
927
			mv88e6xxx_reg_unlock(chip);
928

929 930 931
			j++;
		}
	}
932
	return j;
933 934
}

935 936
static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
937 938
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
939
					 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
940
					 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
941 942
}

943 944 945 946 947 948 949
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);
}

950 951
static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
952 953
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
954
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
955 956
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
					 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
957 958
}

959 960
static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
961 962 963
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
964 965
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
					 0);
966 967
}

968 969 970 971 972 973 974 975 976 977
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;
}

978 979 980
static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
				uint64_t *data)
{
981 982
	int count = 0;

983
	if (chip->info->ops->stats_get_stats)
984 985
		count = chip->info->ops->stats_get_stats(chip, port, data);

986
	mv88e6xxx_reg_lock(chip);
987 988
	if (chip->info->ops->serdes_get_stats) {
		data += count;
989
		count = chip->info->ops->serdes_get_stats(chip, port, data);
990
	}
991 992
	data += count;
	mv88e6xxx_atu_vtu_get_stats(chip, port, data);
993
	mv88e6xxx_reg_unlock(chip);
994 995
}

996 997
static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
					uint64_t *data)
998
{
V
Vivien Didelot 已提交
999
	struct mv88e6xxx_chip *chip = ds->priv;
1000 1001
	int ret;

1002
	mv88e6xxx_reg_lock(chip);
1003

1004
	ret = mv88e6xxx_stats_snapshot(chip, port);
1005
	mv88e6xxx_reg_unlock(chip);
1006 1007

	if (ret < 0)
1008
		return;
1009 1010

	mv88e6xxx_get_stats(chip, port, data);
1011

1012 1013
}

1014
static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
1015 1016 1017 1018
{
	return 32 * sizeof(u16);
}

1019 1020
static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
			       struct ethtool_regs *regs, void *_p)
1021
{
V
Vivien Didelot 已提交
1022
	struct mv88e6xxx_chip *chip = ds->priv;
1023 1024
	int err;
	u16 reg;
1025 1026 1027
	u16 *p = _p;
	int i;

1028
	regs->version = chip->info->prod_num;
1029 1030 1031

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

1032
	mv88e6xxx_reg_lock(chip);
1033

1034 1035
	for (i = 0; i < 32; i++) {

1036 1037 1038
		err = mv88e6xxx_port_read(chip, port, i, &reg);
		if (!err)
			p[i] = reg;
1039
	}
1040

1041
	mv88e6xxx_reg_unlock(chip);
1042 1043
}

V
Vivien Didelot 已提交
1044 1045
static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
1046
{
1047 1048
	/* Nothing to do on the port's MAC */
	return 0;
1049 1050
}

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

1058
static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
1059
{
1060 1061 1062
	struct dsa_switch *ds = NULL;
	struct net_device *br;
	u16 pvlan;
1063 1064
	int i;

1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084
	if (dev < DSA_MAX_SWITCHES)
		ds = chip->ds->dst->ds[dev];

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

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

	br = ds->ports[port].bridge_dev;
	pvlan = 0;

	/* Frames from user ports can egress any local DSA links and CPU ports,
	 * as well as any local member of their bridge group.
	 */
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
		if (dsa_is_cpu_port(chip->ds, i) ||
		    dsa_is_dsa_port(chip->ds, i) ||
V
Vivien Didelot 已提交
1085
		    (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
1086 1087 1088 1089 1090
			pvlan |= BIT(i);

	return pvlan;
}

1091
static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
1092 1093
{
	u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
1094 1095 1096

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

1098
	return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
1099 1100
}

1101 1102
static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
					 u8 state)
1103
{
V
Vivien Didelot 已提交
1104
	struct mv88e6xxx_chip *chip = ds->priv;
1105
	int err;
1106

1107
	mv88e6xxx_reg_lock(chip);
1108
	err = mv88e6xxx_port_set_state(chip, port, state);
1109
	mv88e6xxx_reg_unlock(chip);
1110 1111

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

1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133
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;
}

1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153
static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
{
	int target, port;
	int err;

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

	/* Initialize the routing port to the 32 possible target devices */
	for (target = 0; target < 32; target++) {
		port = 0x1f;
		if (target < DSA_MAX_SWITCHES)
			if (chip->ds->rtable[target] != DSA_RTABLE_NONE)
				port = chip->ds->rtable[target];

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

1154 1155 1156 1157 1158 1159 1160
	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;
	}

1161 1162 1163 1164
	err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
	if (err)
		return err;

1165 1166 1167
	return 0;
}

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

1177 1178 1179 1180 1181 1182 1183 1184
static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->rmu_disable)
		return chip->info->ops->rmu_disable(chip);

	return 0;
}

1185 1186 1187 1188 1189 1190 1191 1192
static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->pot_clear)
		return chip->info->ops->pot_clear(chip);

	return 0;
}

1193 1194 1195 1196 1197 1198 1199 1200
static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->mgmt_rsvd2cpu)
		return chip->info->ops->mgmt_rsvd2cpu(chip);

	return 0;
}

1201 1202
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
1203 1204
	int err;

1205 1206 1207 1208
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

1209 1210 1211 1212
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

1213 1214 1215
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235
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;
}

1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248
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;
}

1249 1250 1251 1252 1253 1254 1255 1256 1257
static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
{
	u16 pvlan = 0;

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

	/* Skip the local source device, which uses in-chip port VLAN */
	if (dev != chip->ds->index)
1258
		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1259 1260 1261 1262

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

1263 1264
static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
{
1265 1266 1267
	int dev, port;
	int err;

1268 1269 1270 1271 1272 1273
	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.
	 */
1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286
	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;
1287 1288
}

1289 1290 1291 1292 1293
static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

1294
	mv88e6xxx_reg_lock(chip);
1295
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1296
	mv88e6xxx_reg_unlock(chip);
1297 1298

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

1302 1303 1304 1305 1306 1307 1308 1309
static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
{
	if (!chip->info->max_vid)
		return 0;

	return mv88e6xxx_g1_vtu_flush(chip);
}

1310 1311 1312 1313 1314 1315 1316 1317 1318
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);
}

1319 1320 1321 1322 1323 1324 1325 1326 1327
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);
}

1328
static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1329 1330
{
	DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1331
	struct mv88e6xxx_vtu_entry vlan;
1332
	int i, err;
1333 1334 1335

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

1336
	/* Set every FID bit used by the (un)bridged ports */
1337
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1338
		err = mv88e6xxx_port_get_fid(chip, i, fid);
1339 1340 1341 1342 1343 1344
		if (err)
			return err;

		set_bit(*fid, fid_bitmap);
	}

1345
	/* Set every FID bit used by the VLAN entries */
1346 1347 1348
	vlan.vid = chip->info->max_vid;
	vlan.valid = false;

1349
	do {
1350
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1351 1352 1353 1354 1355 1356 1357
		if (err)
			return err;

		if (!vlan.valid)
			break;

		set_bit(vlan.fid, fid_bitmap);
1358
	} while (vlan.vid < chip->info->max_vid);
1359 1360 1361 1362 1363

	/* 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);
1364
	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1365 1366 1367
		return -ENOSPC;

	/* Clear the database */
1368
	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1369 1370
}

1371 1372 1373
static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
					u16 vid_begin, u16 vid_end)
{
V
Vivien Didelot 已提交
1374
	struct mv88e6xxx_chip *chip = ds->priv;
1375
	struct mv88e6xxx_vtu_entry vlan;
1376 1377
	int i, err;

1378 1379 1380 1381
	/* 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;

1382 1383 1384
	if (!vid_begin)
		return -EOPNOTSUPP;

1385 1386 1387
	vlan.vid = vid_begin - 1;
	vlan.valid = false;

1388
	do {
1389
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1390
		if (err)
1391
			return err;
1392 1393 1394 1395 1396 1397 1398

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

1399
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1400 1401 1402
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

1403
			if (!ds->ports[i].slave)
1404 1405
				continue;

1406
			if (vlan.member[i] ==
1407
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1408 1409
				continue;

V
Vivien Didelot 已提交
1410
			if (dsa_to_port(ds, i)->bridge_dev ==
1411
			    ds->ports[port].bridge_dev)
1412 1413
				break; /* same bridge, check next VLAN */

V
Vivien Didelot 已提交
1414
			if (!dsa_to_port(ds, i)->bridge_dev)
1415 1416
				continue;

1417 1418
			dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
				port, vlan.vid, i,
V
Vivien Didelot 已提交
1419
				netdev_name(dsa_to_port(ds, i)->bridge_dev));
1420
			return -EOPNOTSUPP;
1421 1422 1423
		}
	} while (vlan.vid < vid_end);

1424
	return 0;
1425 1426
}

1427 1428
static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
					 bool vlan_filtering)
1429
{
V
Vivien Didelot 已提交
1430
	struct mv88e6xxx_chip *chip = ds->priv;
1431 1432
	u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
		MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
1433
	int err;
1434

1435
	if (!chip->info->max_vid)
1436 1437
		return -EOPNOTSUPP;

1438
	mv88e6xxx_reg_lock(chip);
1439
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1440
	mv88e6xxx_reg_unlock(chip);
1441

1442
	return err;
1443 1444
}

1445 1446
static int
mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1447
			    const struct switchdev_obj_port_vlan *vlan)
1448
{
V
Vivien Didelot 已提交
1449
	struct mv88e6xxx_chip *chip = ds->priv;
1450 1451
	int err;

1452
	if (!chip->info->max_vid)
1453 1454
		return -EOPNOTSUPP;

1455 1456 1457
	/* 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.
	 */
1458
	mv88e6xxx_reg_lock(chip);
1459 1460
	err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
					   vlan->vid_end);
1461
	mv88e6xxx_reg_unlock(chip);
1462

1463 1464 1465
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */
1466
	return err;
1467 1468
}

1469 1470 1471 1472 1473
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;
1474 1475
	struct mv88e6xxx_vtu_entry vlan;
	u16 fid;
1476 1477 1478
	int err;

	/* Null VLAN ID corresponds to the port private database */
1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496
	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;
	}
1497 1498 1499 1500 1501

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

1502
	err = mv88e6xxx_g1_atu_getnext(chip, fid, &entry);
1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522
	if (err)
		return err;

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

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

1523
	return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry);
1524 1525
}

1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548
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;
}

1549
static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port,
1550
				    u16 vid, u8 member)
1551
{
1552
	const u8 non_member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1553
	struct mv88e6xxx_vtu_entry vlan;
1554
	int i, err;
1555

1556 1557
	if (!vid)
		return -EOPNOTSUPP;
1558

1559 1560
	vlan.vid = vid - 1;
	vlan.valid = false;
1561

1562
	err = mv88e6xxx_vtu_getnext(chip, &vlan);
1563 1564 1565
	if (err)
		return err;

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
	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;
1601 1602
}

1603
static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1604
				    const struct switchdev_obj_port_vlan *vlan)
1605
{
V
Vivien Didelot 已提交
1606
	struct mv88e6xxx_chip *chip = ds->priv;
1607 1608
	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1609
	u8 member;
1610 1611
	u16 vid;

1612
	if (!chip->info->max_vid)
1613 1614
		return;

1615
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1616
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1617
	else if (untagged)
1618
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
1619
	else
1620
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
1621

1622
	mv88e6xxx_reg_lock(chip);
1623

1624
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
1625
		if (mv88e6xxx_port_vlan_join(chip, port, vid, member))
1626 1627
			dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
				vid, untagged ? 'u' : 't');
1628

1629
	if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1630 1631
		dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
			vlan->vid_end);
1632

1633
	mv88e6xxx_reg_unlock(chip);
1634 1635
}

1636 1637
static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,
				     int port, u16 vid)
1638
{
1639
	struct mv88e6xxx_vtu_entry vlan;
1640 1641
	int i, err;

1642 1643 1644 1645 1646 1647 1648
	if (!vid)
		return -EOPNOTSUPP;

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

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

1652 1653 1654 1655 1656
	/* 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)
1657
		return -EOPNOTSUPP;
1658

1659
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1660 1661

	/* keep the VLAN unless all ports are excluded */
1662
	vlan.valid = false;
1663
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1664 1665
		if (vlan.member[i] !=
		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
1666
			vlan.valid = true;
1667 1668 1669 1670
			break;
		}
	}

1671
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1672 1673 1674
	if (err)
		return err;

1675
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
1676 1677
}

1678 1679
static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
				   const struct switchdev_obj_port_vlan *vlan)
1680
{
V
Vivien Didelot 已提交
1681
	struct mv88e6xxx_chip *chip = ds->priv;
1682 1683 1684
	u16 pvid, vid;
	int err = 0;

1685
	if (!chip->info->max_vid)
1686 1687
		return -EOPNOTSUPP;

1688
	mv88e6xxx_reg_lock(chip);
1689

1690
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
1691 1692 1693
	if (err)
		goto unlock;

1694
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1695
		err = mv88e6xxx_port_vlan_leave(chip, port, vid);
1696 1697 1698 1699
		if (err)
			goto unlock;

		if (vid == pvid) {
1700
			err = mv88e6xxx_port_set_pvid(chip, port, 0);
1701 1702 1703 1704 1705
			if (err)
				goto unlock;
		}
	}

1706
unlock:
1707
	mv88e6xxx_reg_unlock(chip);
1708 1709 1710 1711

	return err;
}

1712 1713
static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
				  const unsigned char *addr, u16 vid)
1714
{
V
Vivien Didelot 已提交
1715
	struct mv88e6xxx_chip *chip = ds->priv;
1716
	int err;
1717

1718
	mv88e6xxx_reg_lock(chip);
1719 1720
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1721
	mv88e6xxx_reg_unlock(chip);
1722 1723

	return err;
1724 1725
}

1726
static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1727
				  const unsigned char *addr, u16 vid)
1728
{
V
Vivien Didelot 已提交
1729
	struct mv88e6xxx_chip *chip = ds->priv;
1730
	int err;
1731

1732
	mv88e6xxx_reg_lock(chip);
1733
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1734
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
1735
	mv88e6xxx_reg_unlock(chip);
1736

1737
	return err;
1738 1739
}

1740 1741
static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
				      u16 fid, u16 vid, int port,
1742
				      dsa_fdb_dump_cb_t *cb, void *data)
1743
{
1744
	struct mv88e6xxx_atu_entry addr;
1745
	bool is_static;
1746 1747
	int err;

1748
	addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1749
	eth_broadcast_addr(addr.mac);
1750 1751

	do {
1752
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
1753
		if (err)
1754
			return err;
1755

1756
		if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
1757 1758
			break;

1759
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
1760 1761
			continue;

1762 1763
		if (!is_unicast_ether_addr(addr.mac))
			continue;
1764

1765 1766 1767
		is_static = (addr.state ==
			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
		err = cb(addr.mac, vid, is_static, data);
1768 1769
		if (err)
			return err;
1770 1771 1772 1773 1774
	} while (!is_broadcast_ether_addr(addr.mac));

	return err;
}

1775
static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1776
				  dsa_fdb_dump_cb_t *cb, void *data)
1777
{
1778
	struct mv88e6xxx_vtu_entry vlan;
1779
	u16 fid;
1780 1781
	int err;

1782
	/* Dump port's default Filtering Information Database (VLAN ID 0) */
1783
	err = mv88e6xxx_port_get_fid(chip, port, &fid);
1784
	if (err)
1785
		return err;
1786

1787
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
1788
	if (err)
1789
		return err;
1790

1791
	/* Dump VLANs' Filtering Information Databases */
1792 1793 1794
	vlan.vid = chip->info->max_vid;
	vlan.valid = false;

1795
	do {
1796
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1797
		if (err)
1798
			return err;
1799 1800 1801 1802

		if (!vlan.valid)
			break;

1803
		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1804
						 cb, data);
1805
		if (err)
1806
			return err;
1807
	} while (vlan.vid < chip->info->max_vid);
1808

1809 1810 1811 1812
	return err;
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1813
				   dsa_fdb_dump_cb_t *cb, void *data)
1814
{
V
Vivien Didelot 已提交
1815
	struct mv88e6xxx_chip *chip = ds->priv;
1816 1817
	int err;

1818
	mv88e6xxx_reg_lock(chip);
1819
	err = mv88e6xxx_port_db_dump(chip, port, cb, data);
1820
	mv88e6xxx_reg_unlock(chip);
1821

1822
	return err;
1823 1824
}

1825 1826
static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
				struct net_device *br)
1827
{
1828
	struct dsa_switch *ds;
1829
	int port;
1830
	int dev;
1831
	int err;
1832

1833 1834 1835 1836
	/* Remap the Port VLAN of each local bridge group member */
	for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) {
		if (chip->ds->ports[port].bridge_dev == br) {
			err = mv88e6xxx_port_vlan_map(chip, port);
1837
			if (err)
1838
				return err;
1839 1840 1841
		}
	}

1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859
	if (!mv88e6xxx_has_pvt(chip))
		return 0;

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

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

1860 1861 1862 1863 1864 1865 1866 1867 1868
	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;

1869
	mv88e6xxx_reg_lock(chip);
1870
	err = mv88e6xxx_bridge_map(chip, br);
1871
	mv88e6xxx_reg_unlock(chip);
1872

1873
	return err;
1874 1875
}

1876 1877
static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
					struct net_device *br)
1878
{
V
Vivien Didelot 已提交
1879
	struct mv88e6xxx_chip *chip = ds->priv;
1880

1881
	mv88e6xxx_reg_lock(chip);
1882 1883 1884
	if (mv88e6xxx_bridge_map(chip, br) ||
	    mv88e6xxx_port_vlan_map(chip, port))
		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
1885
	mv88e6xxx_reg_unlock(chip);
1886 1887
}

1888 1889 1890 1891 1892 1893 1894 1895 1896
static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, int dev,
					   int port, struct net_device *br)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

	if (!mv88e6xxx_has_pvt(chip))
		return 0;

1897
	mv88e6xxx_reg_lock(chip);
1898
	err = mv88e6xxx_pvt_map(chip, dev, port);
1899
	mv88e6xxx_reg_unlock(chip);
1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911

	return err;
}

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

	if (!mv88e6xxx_has_pvt(chip))
		return;

1912
	mv88e6xxx_reg_lock(chip);
1913 1914
	if (mv88e6xxx_pvt_map(chip, dev, port))
		dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
1915
	mv88e6xxx_reg_unlock(chip);
1916 1917
}

1918 1919 1920 1921 1922 1923 1924 1925
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->reset)
		return chip->info->ops->reset(chip);

	return 0;
}

1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938
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);
	}
}

1939
static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1940
{
1941
	int i, err;
1942

1943
	/* Set all ports to the Disabled state */
1944
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
1945
		err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
1946 1947
		if (err)
			return err;
1948 1949
	}

1950 1951 1952
	/* Wait for transmit queues to drain,
	 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
	 */
1953 1954
	usleep_range(2000, 4000);

1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965
	return 0;
}

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

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

1966
	mv88e6xxx_hardware_reset(chip);
1967

1968
	return mv88e6xxx_software_reset(chip);
1969 1970
}

1971
static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
1972 1973
				   enum mv88e6xxx_frame_mode frame,
				   enum mv88e6xxx_egress_mode egress, u16 etype)
1974 1975 1976
{
	int err;

1977 1978 1979 1980
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
1981 1982 1983
	if (err)
		return err;

1984 1985 1986 1987 1988 1989 1990 1991
	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;
1992 1993
}

1994
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1995
{
1996
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
1997
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
1998
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
1999
}
2000

2001 2002 2003
static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
2004
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2005
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2006
}
2007

2008 2009 2010 2011
static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port,
				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
2012 2013
				       MV88E6XXX_EGRESS_MODE_ETHERTYPE,
				       ETH_P_EDSA);
2014
}
2015

2016 2017 2018 2019
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);
2020

2021
	if (dsa_is_user_port(chip->ds, port))
2022
		return mv88e6xxx_set_port_mode_normal(chip, port);
2023

2024 2025 2026
	/* 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);
2027

2028 2029
	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
		return mv88e6xxx_set_port_mode_edsa(chip, port);
2030

2031
	return -EINVAL;
2032 2033
}

2034
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2035
{
2036
	bool message = dsa_is_dsa_port(chip->ds, port);
2037

2038
	return mv88e6xxx_port_set_message_port(chip, port, message);
2039
}
2040

2041
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2042
{
2043
	struct dsa_switch *ds = chip->ds;
2044
	bool flood;
2045

2046 2047 2048 2049 2050
	/* 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);
2051

2052
	return 0;
2053 2054
}

2055 2056 2057
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
2058 2059
	if (chip->info->ops->serdes_power)
		return chip->info->ops->serdes_power(chip, port, on);
2060

2061
	return 0;
2062 2063
}

2064 2065 2066 2067 2068 2069
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

2070
	upstream_port = dsa_upstream_port(ds, port);
2071 2072 2073 2074 2075 2076 2077
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093
	if (port == upstream_port) {
		if (chip->info->ops->set_cpu_port) {
			err = chip->info->ops->set_cpu_port(chip,
							    upstream_port);
			if (err)
				return err;
		}

		if (chip->info->ops->set_egress_port) {
			err = chip->info->ops->set_egress_port(chip,
							       upstream_port);
			if (err)
				return err;
		}
	}

2094 2095 2096
	return 0;
}

2097
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
2098
{
2099
	struct dsa_switch *ds = chip->ds;
2100
	int err;
2101
	u16 reg;
2102

2103 2104 2105
	chip->ports[port].chip = chip;
	chip->ports[port].port = port;

2106 2107 2108 2109 2110 2111 2112
	/* 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,
2113
					       PAUSE_OFF,
2114 2115 2116 2117
					       PHY_INTERFACE_MODE_NA);
	else
		err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
					       SPEED_UNFORCED, DUPLEX_UNFORCED,
2118
					       PAUSE_ON,
2119 2120 2121
					       PHY_INTERFACE_MODE_NA);
	if (err)
		return err;
2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136

	/* 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.
	 */
2137 2138 2139 2140
	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);
2141 2142
	if (err)
		return err;
2143

2144
	err = mv88e6xxx_setup_port_mode(chip, port);
2145 2146
	if (err)
		return err;
2147

2148
	err = mv88e6xxx_setup_egress_floods(chip, port);
2149 2150 2151
	if (err)
		return err;

2152 2153 2154
	/* Enable the SERDES interface for DSA and CPU ports. Normal
	 * ports SERDES are enabled when the port is enabled, thus
	 * saving a bit of power.
2155
	 */
2156 2157 2158 2159 2160
	if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
		err = mv88e6xxx_serdes_power(chip, port, true);
		if (err)
			return err;
	}
2161

2162
	/* Port Control 2: don't force a good FCS, set the maximum frame size to
2163
	 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
2164 2165 2166
	 * 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.
2167
	 */
2168 2169 2170
	err = mv88e6xxx_port_set_map_da(chip, port);
	if (err)
		return err;
2171

2172 2173 2174
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
2175

2176
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
2177
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
2178 2179 2180
	if (err)
		return err;

2181 2182
	if (chip->info->ops->port_set_jumbo_size) {
		err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
2183 2184 2185 2186
		if (err)
			return err;
	}

2187 2188 2189 2190 2191
	/* 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.
	 */
2192
	reg = 1 << port;
2193 2194
	/* Disable learning for CPU port */
	if (dsa_is_cpu_port(ds, port))
2195
		reg = 0;
2196

2197 2198
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
2199 2200
	if (err)
		return err;
2201 2202

	/* Egress rate control 2: disable egress rate control. */
2203 2204
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
				   0x0000);
2205 2206
	if (err)
		return err;
2207

2208 2209
	if (chip->info->ops->port_pause_limit) {
		err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
2210 2211
		if (err)
			return err;
2212
	}
2213

2214 2215 2216 2217 2218 2219
	if (chip->info->ops->port_disable_learn_limit) {
		err = chip->info->ops->port_disable_learn_limit(chip, port);
		if (err)
			return err;
	}

2220 2221
	if (chip->info->ops->port_disable_pri_override) {
		err = chip->info->ops->port_disable_pri_override(chip, port);
2222 2223
		if (err)
			return err;
2224
	}
2225

2226 2227
	if (chip->info->ops->port_tag_remap) {
		err = chip->info->ops->port_tag_remap(chip, port);
2228 2229
		if (err)
			return err;
2230 2231
	}

2232 2233
	if (chip->info->ops->port_egress_rate_limiting) {
		err = chip->info->ops->port_egress_rate_limiting(chip, port);
2234 2235
		if (err)
			return err;
2236 2237
	}

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

2244
	/* Port based VLAN map: give each port the same default address
2245 2246
	 * database, and allow bidirectional communication between the
	 * CPU and DSA port(s), and the other ports.
2247
	 */
2248
	err = mv88e6xxx_port_set_fid(chip, port, 0);
2249 2250
	if (err)
		return err;
2251

2252
	err = mv88e6xxx_port_vlan_map(chip, port);
2253 2254
	if (err)
		return err;
2255 2256 2257 2258

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

2262 2263 2264 2265
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
2266
	int err;
2267

2268
	mv88e6xxx_reg_lock(chip);
2269

2270
	err = mv88e6xxx_serdes_power(chip, port, true);
2271 2272 2273 2274

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

2275
	mv88e6xxx_reg_unlock(chip);
2276 2277 2278 2279

	return err;
}

2280
static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port)
2281 2282 2283
{
	struct mv88e6xxx_chip *chip = ds->priv;

2284
	mv88e6xxx_reg_lock(chip);
2285

2286 2287 2288
	if (mv88e6xxx_port_set_state(chip, port, BR_STATE_DISABLED))
		dev_err(chip->dev, "failed to disable port\n");

2289 2290 2291
	if (chip->info->ops->serdes_irq_free)
		chip->info->ops->serdes_irq_free(chip, port);

2292 2293
	if (mv88e6xxx_serdes_power(chip, port, false))
		dev_err(chip->dev, "failed to power off SERDES\n");
2294

2295
	mv88e6xxx_reg_unlock(chip);
2296 2297
}

2298 2299 2300
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
2301
	struct mv88e6xxx_chip *chip = ds->priv;
2302 2303
	int err;

2304
	mv88e6xxx_reg_lock(chip);
2305
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2306
	mv88e6xxx_reg_unlock(chip);
2307 2308 2309 2310

	return err;
}

2311
static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
2312
{
2313
	int err;
2314

2315
	/* Initialize the statistics unit */
2316 2317 2318 2319 2320
	if (chip->info->ops->stats_set_histogram) {
		err = chip->info->ops->stats_set_histogram(chip);
		if (err)
			return err;
	}
2321

2322
	return mv88e6xxx_g1_stats_clear(chip);
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
/* The mv88e6390 has some hidden registers used for debug and
 * development. The errata also makes use of them.
 */
static int mv88e6390_hidden_write(struct mv88e6xxx_chip *chip, int port,
				  int reg, u16 val)
{
	u16 ctrl;
	int err;

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

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

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

static int mv88e6390_hidden_wait(struct mv88e6xxx_chip *chip)
{
2349 2350 2351 2352
	int bit = __bf_shf(PORT_RESERVED_1A_BUSY);

	return mv88e6xxx_wait_bit(chip, PORT_RESERVED_1A_CTRL_PORT,
				  PORT_RESERVED_1A, bit, 0);
2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427
}


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

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

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

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

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

/* Check if the errata has already been applied. */
static bool mv88e6390_setup_errata_applied(struct mv88e6xxx_chip *chip)
{
	int port;
	int err;
	u16 val;

	for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
		err = mv88e6390_hidden_read(chip, port, 0, &val);
		if (err) {
			dev_err(chip->dev,
				"Error reading hidden register: %d\n", err);
			return false;
		}
		if (val != 0x01c0)
			return false;
	}

	return true;
}

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

	if (mv88e6390_setup_errata_applied(chip))
		return 0;

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

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

	return mv88e6xxx_software_reset(chip);
}

2428
static int mv88e6xxx_setup(struct dsa_switch *ds)
2429
{
V
Vivien Didelot 已提交
2430
	struct mv88e6xxx_chip *chip = ds->priv;
2431
	u8 cmode;
2432
	int err;
2433 2434
	int i;

2435
	chip->ds = ds;
2436
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
2437

2438
	mv88e6xxx_reg_lock(chip);
2439

2440 2441 2442 2443 2444 2445
	if (chip->info->ops->setup_errata) {
		err = chip->info->ops->setup_errata(chip);
		if (err)
			goto unlock;
	}

2446 2447 2448 2449 2450
	/* 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)
2451
				goto unlock;
2452 2453 2454 2455 2456

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

2457
	/* Setup Switch Port Registers */
2458
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2459 2460 2461 2462 2463 2464 2465 2466
		/* Prevent the use of an invalid port. */
		if (mv88e6xxx_is_invalid_port(chip, i) &&
		    !dsa_is_unused_port(ds, i)) {
			dev_err(chip->dev, "port %d is invalid\n", i);
			err = -EINVAL;
			goto unlock;
		}

2467 2468 2469 2470 2471 2472 2473 2474 2475 2476
		if (dsa_is_unused_port(ds, i)) {
			err = mv88e6xxx_port_set_state(chip, i,
						       BR_STATE_DISABLED);
			if (err)
				goto unlock;

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

2477
			continue;
2478
		}
2479

2480 2481 2482 2483 2484
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

2485 2486 2487 2488
	err = mv88e6xxx_irl_setup(chip);
	if (err)
		goto unlock;

2489 2490 2491 2492
	err = mv88e6xxx_mac_setup(chip);
	if (err)
		goto unlock;

2493 2494 2495 2496
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

2497 2498 2499 2500
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

2501 2502 2503 2504
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

2505 2506 2507 2508
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

2509 2510 2511 2512
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

2513 2514 2515 2516
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

2517 2518 2519 2520
	err = mv88e6xxx_rmu_setup(chip);
	if (err)
		goto unlock;

2521 2522 2523
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
2524

2525 2526 2527 2528
	err = mv88e6xxx_trunk_setup(chip);
	if (err)
		goto unlock;

2529 2530 2531 2532
	err = mv88e6xxx_devmap_setup(chip);
	if (err)
		goto unlock;

2533 2534 2535 2536
	err = mv88e6xxx_pri_setup(chip);
	if (err)
		goto unlock;

2537
	/* Setup PTP Hardware Clock and timestamping */
2538 2539 2540 2541
	if (chip->info->ptp_support) {
		err = mv88e6xxx_ptp_setup(chip);
		if (err)
			goto unlock;
2542 2543 2544 2545

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
2546 2547
	}

2548 2549 2550 2551
	err = mv88e6xxx_stats_setup(chip);
	if (err)
		goto unlock;

2552
unlock:
2553
	mv88e6xxx_reg_unlock(chip);
2554

2555
	return err;
2556 2557
}

2558
static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
2559
{
2560 2561
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2562 2563
	u16 val;
	int err;
2564

2565 2566 2567
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

2568
	mv88e6xxx_reg_lock(chip);
2569
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
2570
	mv88e6xxx_reg_unlock(chip);
2571

2572
	if (reg == MII_PHYSID2) {
2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588
		/* 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;
2589 2590
	}

2591
	return err ? err : val;
2592 2593
}

2594
static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
2595
{
2596 2597
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2598
	int err;
2599

2600 2601 2602
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

2603
	mv88e6xxx_reg_lock(chip);
2604
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
2605
	mv88e6xxx_reg_unlock(chip);
2606 2607

	return err;
2608 2609
}

2610
static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
2611 2612
				   struct device_node *np,
				   bool external)
2613 2614
{
	static int index;
2615
	struct mv88e6xxx_mdio_bus *mdio_bus;
2616 2617 2618
	struct mii_bus *bus;
	int err;

2619
	if (external) {
2620
		mv88e6xxx_reg_lock(chip);
2621
		err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
2622
		mv88e6xxx_reg_unlock(chip);
2623 2624 2625 2626 2627

		if (err)
			return err;
	}

2628
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
2629 2630 2631
	if (!bus)
		return -ENOMEM;

2632
	mdio_bus = bus->priv;
2633
	mdio_bus->bus = bus;
2634
	mdio_bus->chip = chip;
2635 2636
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
2637

2638 2639
	if (np) {
		bus->name = np->full_name;
2640
		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
2641 2642 2643 2644 2645 2646 2647
	} 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;
2648
	bus->parent = chip->dev;
2649

2650 2651 2652 2653 2654 2655
	if (!external) {
		err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
		if (err)
			return err;
	}

2656
	err = of_mdiobus_register(bus, np);
2657
	if (err) {
2658
		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
2659
		mv88e6xxx_g2_irq_mdio_free(chip, bus);
2660
		return err;
2661
	}
2662 2663 2664 2665 2666

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

	return 0;
2669
}
2670

2671 2672 2673 2674 2675
static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
	{ .compatible = "marvell,mv88e6xxx-mdio-external",
	  .data = (void *)true },
	{ },
};
2676

2677 2678 2679 2680 2681 2682 2683 2684 2685
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;

2686 2687 2688
		if (!mdio_bus->external)
			mv88e6xxx_g2_irq_mdio_free(chip, bus);

2689 2690 2691 2692
		mdiobus_unregister(bus);
	}
}

2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716
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);
2717 2718
			if (err) {
				mv88e6xxx_mdios_unregister(chip);
2719
				of_node_put(child);
2720
				return err;
2721
			}
2722 2723 2724 2725
		}
	}

	return 0;
2726 2727
}

2728 2729
static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
2730
	struct mv88e6xxx_chip *chip = ds->priv;
2731 2732 2733 2734 2735 2736 2737

	return chip->eeprom_len;
}

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

2741 2742
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
2743

2744
	mv88e6xxx_reg_lock(chip);
2745
	err = chip->info->ops->get_eeprom(chip, eeprom, data);
2746
	mv88e6xxx_reg_unlock(chip);
2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758

	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 已提交
2759
	struct mv88e6xxx_chip *chip = ds->priv;
2760 2761
	int err;

2762 2763 2764
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

2765 2766 2767
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

2768
	mv88e6xxx_reg_lock(chip);
2769
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
2770
	mv88e6xxx_reg_unlock(chip);
2771 2772 2773 2774

	return err;
}

2775
static const struct mv88e6xxx_ops mv88e6085_ops = {
2776
	/* MV88E6XXX_FAMILY_6097 */
2777 2778
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2779
	.irl_init_all = mv88e6352_g2_irl_init_all,
2780
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2781 2782
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2783
	.port_set_link = mv88e6xxx_port_set_link,
2784
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2785
	.port_set_speed = mv88e6185_port_set_speed,
2786
	.port_tag_remap = mv88e6095_port_tag_remap,
2787
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2788
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2789
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2790
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2791
	.port_pause_limit = mv88e6097_port_pause_limit,
2792
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2793
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2794
	.port_link_state = mv88e6352_port_link_state,
2795
	.port_get_cmode = mv88e6185_port_get_cmode,
2796
	.port_setup_message_port = mv88e6xxx_setup_message_port,
2797
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2798
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2799 2800
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2801
	.stats_get_stats = mv88e6095_stats_get_stats,
2802 2803
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2804
	.watchdog_ops = &mv88e6097_watchdog_ops,
2805
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2806
	.pot_clear = mv88e6xxx_g2_pot_clear,
2807 2808
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2809
	.reset = mv88e6185_g1_reset,
2810
	.rmu_disable = mv88e6085_g1_rmu_disable,
2811
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2812
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2813
	.phylink_validate = mv88e6185_phylink_validate,
2814 2815 2816
};

static const struct mv88e6xxx_ops mv88e6095_ops = {
2817
	/* MV88E6XXX_FAMILY_6095 */
2818 2819
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2820
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2821 2822
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2823
	.port_set_link = mv88e6xxx_port_set_link,
2824
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2825
	.port_set_speed = mv88e6185_port_set_speed,
2826
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2827
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2828
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2829
	.port_link_state = mv88e6185_port_link_state,
2830
	.port_get_cmode = mv88e6185_port_get_cmode,
2831
	.port_setup_message_port = mv88e6xxx_setup_message_port,
2832
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2833
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2834 2835
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2836
	.stats_get_stats = mv88e6095_stats_get_stats,
2837
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2838 2839
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2840
	.reset = mv88e6185_g1_reset,
2841
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2842
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2843
	.phylink_validate = mv88e6185_phylink_validate,
2844 2845
};

2846
static const struct mv88e6xxx_ops mv88e6097_ops = {
2847
	/* MV88E6XXX_FAMILY_6097 */
2848 2849
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2850
	.irl_init_all = mv88e6352_g2_irl_init_all,
2851 2852 2853 2854 2855 2856
	.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,
2857
	.port_tag_remap = mv88e6095_port_tag_remap,
2858
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2859
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2860
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2861
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2862
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
2863
	.port_pause_limit = mv88e6097_port_pause_limit,
2864
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2865
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2866
	.port_link_state = mv88e6352_port_link_state,
2867
	.port_get_cmode = mv88e6185_port_get_cmode,
2868
	.port_setup_message_port = mv88e6xxx_setup_message_port,
2869
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2870
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2871 2872 2873
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
	.stats_get_stats = mv88e6095_stats_get_stats,
2874 2875
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2876
	.watchdog_ops = &mv88e6097_watchdog_ops,
2877
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2878
	.pot_clear = mv88e6xxx_g2_pot_clear,
2879
	.reset = mv88e6352_g1_reset,
2880
	.rmu_disable = mv88e6085_g1_rmu_disable,
2881
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2882
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2883
	.phylink_validate = mv88e6185_phylink_validate,
2884 2885
};

2886
static const struct mv88e6xxx_ops mv88e6123_ops = {
2887
	/* MV88E6XXX_FAMILY_6165 */
2888 2889
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2890
	.irl_init_all = mv88e6352_g2_irl_init_all,
2891
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2892 2893
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2894
	.port_set_link = mv88e6xxx_port_set_link,
2895
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2896
	.port_set_speed = mv88e6185_port_set_speed,
2897
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2898
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2899
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2900
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2901
	.port_link_state = mv88e6352_port_link_state,
2902
	.port_get_cmode = mv88e6185_port_get_cmode,
2903
	.port_setup_message_port = mv88e6xxx_setup_message_port,
2904
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2905
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2906 2907
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2908
	.stats_get_stats = mv88e6095_stats_get_stats,
2909 2910
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2911
	.watchdog_ops = &mv88e6097_watchdog_ops,
2912
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2913
	.pot_clear = mv88e6xxx_g2_pot_clear,
2914
	.reset = mv88e6352_g1_reset,
2915
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2916
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2917
	.phylink_validate = mv88e6185_phylink_validate,
2918 2919 2920
};

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

static const struct mv88e6xxx_ops mv88e6351_ops = {
3738
	/* MV88E6XXX_FAMILY_6351 */
3739 3740
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3741
	.irl_init_all = mv88e6352_g2_irl_init_all,
3742
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3743 3744
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3745
	.port_set_link = mv88e6xxx_port_set_link,
3746
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3747
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3748
	.port_set_speed = mv88e6185_port_set_speed,
3749
	.port_tag_remap = mv88e6095_port_tag_remap,
3750
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3751
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3752
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3753
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3754
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3755
	.port_pause_limit = mv88e6097_port_pause_limit,
3756
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3757
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3758
	.port_link_state = mv88e6352_port_link_state,
3759
	.port_get_cmode = mv88e6352_port_get_cmode,
3760
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3761
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3762
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3763 3764
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3765
	.stats_get_stats = mv88e6095_stats_get_stats,
3766 3767
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3768
	.watchdog_ops = &mv88e6097_watchdog_ops,
3769
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3770
	.pot_clear = mv88e6xxx_g2_pot_clear,
3771
	.reset = mv88e6352_g1_reset,
3772
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3773
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3774
	.avb_ops = &mv88e6352_avb_ops,
3775
	.ptp_ops = &mv88e6352_ptp_ops,
3776
	.phylink_validate = mv88e6185_phylink_validate,
3777 3778 3779
};

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

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

static const struct mv88e6xxx_ops mv88e6390x_ops = {
3882
	/* MV88E6XXX_FAMILY_6390 */
3883
	.setup_errata = mv88e6390_setup_errata,
3884
	.irl_init_all = mv88e6390_g2_irl_init_all,
3885 3886
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3887 3888 3889 3890 3891 3892 3893
	.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,
3894
	.port_max_speed_mode = mv88e6390x_port_max_speed_mode,
3895
	.port_tag_remap = mv88e6390_port_tag_remap,
3896
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3897
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3898
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3899
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3900
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3901
	.port_pause_limit = mv88e6390_port_pause_limit,
3902
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3903
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3904
	.port_link_state = mv88e6352_port_link_state,
3905
	.port_get_cmode = mv88e6352_port_get_cmode,
3906
	.port_set_cmode = mv88e6390x_port_set_cmode,
3907
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3908
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3909
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3910 3911
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3912
	.stats_get_stats = mv88e6390_stats_get_stats,
3913 3914
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3915
	.watchdog_ops = &mv88e6390_watchdog_ops,
3916
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3917
	.pot_clear = mv88e6xxx_g2_pot_clear,
3918
	.reset = mv88e6352_g1_reset,
3919
	.rmu_disable = mv88e6390_g1_rmu_disable,
3920 3921
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3922
	.serdes_power = mv88e6390x_serdes_power,
3923 3924
	.serdes_irq_setup = mv88e6390x_serdes_irq_setup,
	.serdes_irq_free = mv88e6390x_serdes_irq_free,
3925
	.gpio_ops = &mv88e6352_gpio_ops,
3926
	.avb_ops = &mv88e6390_avb_ops,
3927
	.ptp_ops = &mv88e6352_ptp_ops,
3928
	.phylink_validate = mv88e6390x_phylink_validate,
3929 3930
};

3931 3932
static const struct mv88e6xxx_info mv88e6xxx_table[] = {
	[MV88E6085] = {
3933
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
3934 3935 3936 3937
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6085",
		.num_databases = 4096,
		.num_ports = 10,
3938
		.num_internal_phys = 5,
3939
		.max_vid = 4095,
3940
		.port_base_addr = 0x10,
3941
		.phy_base_addr = 0x0,
3942
		.global1_addr = 0x1b,
3943
		.global2_addr = 0x1c,
3944
		.age_time_coeff = 15000,
3945
		.g1_irqs = 8,
3946
		.g2_irqs = 10,
3947
		.atu_move_port_mask = 0xf,
3948
		.pvt = true,
3949
		.multi_chip = true,
3950
		.tag_protocol = DSA_TAG_PROTO_DSA,
3951
		.ops = &mv88e6085_ops,
3952 3953 3954
	},

	[MV88E6095] = {
3955
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
3956 3957 3958 3959
		.family = MV88E6XXX_FAMILY_6095,
		.name = "Marvell 88E6095/88E6095F",
		.num_databases = 256,
		.num_ports = 11,
3960
		.num_internal_phys = 0,
3961
		.max_vid = 4095,
3962
		.port_base_addr = 0x10,
3963
		.phy_base_addr = 0x0,
3964
		.global1_addr = 0x1b,
3965
		.global2_addr = 0x1c,
3966
		.age_time_coeff = 15000,
3967
		.g1_irqs = 8,
3968
		.atu_move_port_mask = 0xf,
3969
		.multi_chip = true,
3970
		.tag_protocol = DSA_TAG_PROTO_DSA,
3971
		.ops = &mv88e6095_ops,
3972 3973
	},

3974
	[MV88E6097] = {
3975
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
3976 3977 3978 3979
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6097/88E6097F",
		.num_databases = 4096,
		.num_ports = 11,
3980
		.num_internal_phys = 8,
3981
		.max_vid = 4095,
3982
		.port_base_addr = 0x10,
3983
		.phy_base_addr = 0x0,
3984
		.global1_addr = 0x1b,
3985
		.global2_addr = 0x1c,
3986
		.age_time_coeff = 15000,
3987
		.g1_irqs = 8,
3988
		.g2_irqs = 10,
3989
		.atu_move_port_mask = 0xf,
3990
		.pvt = true,
3991
		.multi_chip = true,
3992
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3993 3994 3995
		.ops = &mv88e6097_ops,
	},

3996
	[MV88E6123] = {
3997
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
3998 3999 4000 4001
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6123",
		.num_databases = 4096,
		.num_ports = 3,
4002
		.num_internal_phys = 5,
4003
		.max_vid = 4095,
4004
		.port_base_addr = 0x10,
4005
		.phy_base_addr = 0x0,
4006
		.global1_addr = 0x1b,
4007
		.global2_addr = 0x1c,
4008
		.age_time_coeff = 15000,
4009
		.g1_irqs = 9,
4010
		.g2_irqs = 10,
4011
		.atu_move_port_mask = 0xf,
4012
		.pvt = true,
4013
		.multi_chip = true,
4014
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4015
		.ops = &mv88e6123_ops,
4016 4017 4018
	},

	[MV88E6131] = {
4019
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
4020 4021 4022 4023
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6131",
		.num_databases = 256,
		.num_ports = 8,
4024
		.num_internal_phys = 0,
4025
		.max_vid = 4095,
4026
		.port_base_addr = 0x10,
4027
		.phy_base_addr = 0x0,
4028
		.global1_addr = 0x1b,
4029
		.global2_addr = 0x1c,
4030
		.age_time_coeff = 15000,
4031
		.g1_irqs = 9,
4032
		.atu_move_port_mask = 0xf,
4033
		.multi_chip = true,
4034
		.tag_protocol = DSA_TAG_PROTO_DSA,
4035
		.ops = &mv88e6131_ops,
4036 4037
	},

4038
	[MV88E6141] = {
4039
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
4040
		.family = MV88E6XXX_FAMILY_6341,
4041
		.name = "Marvell 88E6141",
4042 4043
		.num_databases = 4096,
		.num_ports = 6,
4044
		.num_internal_phys = 5,
4045
		.num_gpio = 11,
4046
		.max_vid = 4095,
4047
		.port_base_addr = 0x10,
4048
		.phy_base_addr = 0x10,
4049
		.global1_addr = 0x1b,
4050
		.global2_addr = 0x1c,
4051 4052
		.age_time_coeff = 3750,
		.atu_move_port_mask = 0x1f,
4053
		.g1_irqs = 9,
4054
		.g2_irqs = 10,
4055
		.pvt = true,
4056
		.multi_chip = true,
4057 4058 4059 4060
		.tag_protocol = DSA_TAG_PROTO_EDSA,
		.ops = &mv88e6141_ops,
	},

4061
	[MV88E6161] = {
4062
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
4063 4064 4065 4066
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6161",
		.num_databases = 4096,
		.num_ports = 6,
4067
		.num_internal_phys = 5,
4068
		.max_vid = 4095,
4069
		.port_base_addr = 0x10,
4070
		.phy_base_addr = 0x0,
4071
		.global1_addr = 0x1b,
4072
		.global2_addr = 0x1c,
4073
		.age_time_coeff = 15000,
4074
		.g1_irqs = 9,
4075
		.g2_irqs = 10,
4076
		.atu_move_port_mask = 0xf,
4077
		.pvt = true,
4078
		.multi_chip = true,
4079
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4080
		.ptp_support = true,
4081
		.ops = &mv88e6161_ops,
4082 4083 4084
	},

	[MV88E6165] = {
4085
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
4086 4087 4088 4089
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6165",
		.num_databases = 4096,
		.num_ports = 6,
4090
		.num_internal_phys = 0,
4091
		.max_vid = 4095,
4092
		.port_base_addr = 0x10,
4093
		.phy_base_addr = 0x0,
4094
		.global1_addr = 0x1b,
4095
		.global2_addr = 0x1c,
4096
		.age_time_coeff = 15000,
4097
		.g1_irqs = 9,
4098
		.g2_irqs = 10,
4099
		.atu_move_port_mask = 0xf,
4100
		.pvt = true,
4101
		.multi_chip = true,
4102
		.tag_protocol = DSA_TAG_PROTO_DSA,
4103
		.ptp_support = true,
4104
		.ops = &mv88e6165_ops,
4105 4106 4107
	},

	[MV88E6171] = {
4108
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
4109 4110 4111 4112
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6171",
		.num_databases = 4096,
		.num_ports = 7,
4113
		.num_internal_phys = 5,
4114
		.max_vid = 4095,
4115
		.port_base_addr = 0x10,
4116
		.phy_base_addr = 0x0,
4117
		.global1_addr = 0x1b,
4118
		.global2_addr = 0x1c,
4119
		.age_time_coeff = 15000,
4120
		.g1_irqs = 9,
4121
		.g2_irqs = 10,
4122
		.atu_move_port_mask = 0xf,
4123
		.pvt = true,
4124
		.multi_chip = true,
4125
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4126
		.ops = &mv88e6171_ops,
4127 4128 4129
	},

	[MV88E6172] = {
4130
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
4131 4132 4133 4134
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6172",
		.num_databases = 4096,
		.num_ports = 7,
4135
		.num_internal_phys = 5,
4136
		.num_gpio = 15,
4137
		.max_vid = 4095,
4138
		.port_base_addr = 0x10,
4139
		.phy_base_addr = 0x0,
4140
		.global1_addr = 0x1b,
4141
		.global2_addr = 0x1c,
4142
		.age_time_coeff = 15000,
4143
		.g1_irqs = 9,
4144
		.g2_irqs = 10,
4145
		.atu_move_port_mask = 0xf,
4146
		.pvt = true,
4147
		.multi_chip = true,
4148
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4149
		.ops = &mv88e6172_ops,
4150 4151 4152
	},

	[MV88E6175] = {
4153
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
4154 4155 4156 4157
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6175",
		.num_databases = 4096,
		.num_ports = 7,
4158
		.num_internal_phys = 5,
4159
		.max_vid = 4095,
4160
		.port_base_addr = 0x10,
4161
		.phy_base_addr = 0x0,
4162
		.global1_addr = 0x1b,
4163
		.global2_addr = 0x1c,
4164
		.age_time_coeff = 15000,
4165
		.g1_irqs = 9,
4166
		.g2_irqs = 10,
4167
		.atu_move_port_mask = 0xf,
4168
		.pvt = true,
4169
		.multi_chip = true,
4170
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4171
		.ops = &mv88e6175_ops,
4172 4173 4174
	},

	[MV88E6176] = {
4175
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
4176 4177 4178 4179
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6176",
		.num_databases = 4096,
		.num_ports = 7,
4180
		.num_internal_phys = 5,
4181
		.num_gpio = 15,
4182
		.max_vid = 4095,
4183
		.port_base_addr = 0x10,
4184
		.phy_base_addr = 0x0,
4185
		.global1_addr = 0x1b,
4186
		.global2_addr = 0x1c,
4187
		.age_time_coeff = 15000,
4188
		.g1_irqs = 9,
4189
		.g2_irqs = 10,
4190
		.atu_move_port_mask = 0xf,
4191
		.pvt = true,
4192
		.multi_chip = true,
4193
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4194
		.ops = &mv88e6176_ops,
4195 4196 4197
	},

	[MV88E6185] = {
4198
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
4199 4200 4201 4202
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6185",
		.num_databases = 256,
		.num_ports = 10,
4203
		.num_internal_phys = 0,
4204
		.max_vid = 4095,
4205
		.port_base_addr = 0x10,
4206
		.phy_base_addr = 0x0,
4207
		.global1_addr = 0x1b,
4208
		.global2_addr = 0x1c,
4209
		.age_time_coeff = 15000,
4210
		.g1_irqs = 8,
4211
		.atu_move_port_mask = 0xf,
4212
		.multi_chip = true,
4213
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4214
		.ops = &mv88e6185_ops,
4215 4216
	},

4217
	[MV88E6190] = {
4218
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
4219 4220 4221 4222
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4223
		.num_internal_phys = 9,
4224
		.num_gpio = 16,
4225
		.max_vid = 8191,
4226
		.port_base_addr = 0x0,
4227
		.phy_base_addr = 0x0,
4228
		.global1_addr = 0x1b,
4229
		.global2_addr = 0x1c,
4230
		.tag_protocol = DSA_TAG_PROTO_DSA,
4231
		.age_time_coeff = 3750,
4232
		.g1_irqs = 9,
4233
		.g2_irqs = 14,
4234
		.pvt = true,
4235
		.multi_chip = true,
4236
		.atu_move_port_mask = 0x1f,
4237 4238 4239 4240
		.ops = &mv88e6190_ops,
	},

	[MV88E6190X] = {
4241
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
4242 4243 4244 4245
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4246
		.num_internal_phys = 9,
4247
		.num_gpio = 16,
4248
		.max_vid = 8191,
4249
		.port_base_addr = 0x0,
4250
		.phy_base_addr = 0x0,
4251
		.global1_addr = 0x1b,
4252
		.global2_addr = 0x1c,
4253
		.age_time_coeff = 3750,
4254
		.g1_irqs = 9,
4255
		.g2_irqs = 14,
4256
		.atu_move_port_mask = 0x1f,
4257
		.pvt = true,
4258
		.multi_chip = true,
4259
		.tag_protocol = DSA_TAG_PROTO_DSA,
4260 4261 4262 4263
		.ops = &mv88e6190x_ops,
	},

	[MV88E6191] = {
4264
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
4265 4266 4267 4268
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6191",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4269
		.num_internal_phys = 9,
4270
		.max_vid = 8191,
4271
		.port_base_addr = 0x0,
4272
		.phy_base_addr = 0x0,
4273
		.global1_addr = 0x1b,
4274
		.global2_addr = 0x1c,
4275
		.age_time_coeff = 3750,
4276
		.g1_irqs = 9,
4277
		.g2_irqs = 14,
4278
		.atu_move_port_mask = 0x1f,
4279
		.pvt = true,
4280
		.multi_chip = true,
4281
		.tag_protocol = DSA_TAG_PROTO_DSA,
4282
		.ptp_support = true,
4283
		.ops = &mv88e6191_ops,
4284 4285
	},

4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296
	[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,
4297
		.invalid_port_mask = BIT(2) | BIT(3) | BIT(4),
4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308
		.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,
4309
		.ptp_support = true,
4310 4311 4312
		.ops = &mv88e6250_ops,
	},

4313
	[MV88E6240] = {
4314
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
4315 4316 4317 4318
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6240",
		.num_databases = 4096,
		.num_ports = 7,
4319
		.num_internal_phys = 5,
4320
		.num_gpio = 15,
4321
		.max_vid = 4095,
4322
		.port_base_addr = 0x10,
4323
		.phy_base_addr = 0x0,
4324
		.global1_addr = 0x1b,
4325
		.global2_addr = 0x1c,
4326
		.age_time_coeff = 15000,
4327
		.g1_irqs = 9,
4328
		.g2_irqs = 10,
4329
		.atu_move_port_mask = 0xf,
4330
		.pvt = true,
4331
		.multi_chip = true,
4332
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4333
		.ptp_support = true,
4334
		.ops = &mv88e6240_ops,
4335 4336
	},

4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354
	[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,
4355
		.ptp_support = true,
4356 4357 4358
		.ops = &mv88e6250_ops,
	},

4359
	[MV88E6290] = {
4360
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
4361 4362 4363 4364
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6290",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4365
		.num_internal_phys = 9,
4366
		.num_gpio = 16,
4367
		.max_vid = 8191,
4368
		.port_base_addr = 0x0,
4369
		.phy_base_addr = 0x0,
4370
		.global1_addr = 0x1b,
4371
		.global2_addr = 0x1c,
4372
		.age_time_coeff = 3750,
4373
		.g1_irqs = 9,
4374
		.g2_irqs = 14,
4375
		.atu_move_port_mask = 0x1f,
4376
		.pvt = true,
4377
		.multi_chip = true,
4378
		.tag_protocol = DSA_TAG_PROTO_DSA,
4379
		.ptp_support = true,
4380 4381 4382
		.ops = &mv88e6290_ops,
	},

4383
	[MV88E6320] = {
4384
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
4385 4386 4387 4388
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6320",
		.num_databases = 4096,
		.num_ports = 7,
4389
		.num_internal_phys = 5,
4390
		.num_gpio = 15,
4391
		.max_vid = 4095,
4392
		.port_base_addr = 0x10,
4393
		.phy_base_addr = 0x0,
4394
		.global1_addr = 0x1b,
4395
		.global2_addr = 0x1c,
4396
		.age_time_coeff = 15000,
4397
		.g1_irqs = 8,
4398
		.g2_irqs = 10,
4399
		.atu_move_port_mask = 0xf,
4400
		.pvt = true,
4401
		.multi_chip = true,
4402
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4403
		.ptp_support = true,
4404
		.ops = &mv88e6320_ops,
4405 4406 4407
	},

	[MV88E6321] = {
4408
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
4409 4410 4411 4412
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6321",
		.num_databases = 4096,
		.num_ports = 7,
4413
		.num_internal_phys = 5,
4414
		.num_gpio = 15,
4415
		.max_vid = 4095,
4416
		.port_base_addr = 0x10,
4417
		.phy_base_addr = 0x0,
4418
		.global1_addr = 0x1b,
4419
		.global2_addr = 0x1c,
4420
		.age_time_coeff = 15000,
4421
		.g1_irqs = 8,
4422
		.g2_irqs = 10,
4423
		.atu_move_port_mask = 0xf,
4424
		.multi_chip = true,
4425
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4426
		.ptp_support = true,
4427
		.ops = &mv88e6321_ops,
4428 4429
	},

4430
	[MV88E6341] = {
4431
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
4432 4433 4434
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
4435
		.num_internal_phys = 5,
4436
		.num_ports = 6,
4437
		.num_gpio = 11,
4438
		.max_vid = 4095,
4439
		.port_base_addr = 0x10,
4440
		.phy_base_addr = 0x10,
4441
		.global1_addr = 0x1b,
4442
		.global2_addr = 0x1c,
4443
		.age_time_coeff = 3750,
4444
		.atu_move_port_mask = 0x1f,
4445
		.g1_irqs = 9,
4446
		.g2_irqs = 10,
4447
		.pvt = true,
4448
		.multi_chip = true,
4449
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4450
		.ptp_support = true,
4451 4452 4453
		.ops = &mv88e6341_ops,
	},

4454
	[MV88E6350] = {
4455
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
4456 4457 4458 4459
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6350",
		.num_databases = 4096,
		.num_ports = 7,
4460
		.num_internal_phys = 5,
4461
		.max_vid = 4095,
4462
		.port_base_addr = 0x10,
4463
		.phy_base_addr = 0x0,
4464
		.global1_addr = 0x1b,
4465
		.global2_addr = 0x1c,
4466
		.age_time_coeff = 15000,
4467
		.g1_irqs = 9,
4468
		.g2_irqs = 10,
4469
		.atu_move_port_mask = 0xf,
4470
		.pvt = true,
4471
		.multi_chip = true,
4472
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4473
		.ops = &mv88e6350_ops,
4474 4475 4476
	},

	[MV88E6351] = {
4477
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
4478 4479 4480 4481
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6351",
		.num_databases = 4096,
		.num_ports = 7,
4482
		.num_internal_phys = 5,
4483
		.max_vid = 4095,
4484
		.port_base_addr = 0x10,
4485
		.phy_base_addr = 0x0,
4486
		.global1_addr = 0x1b,
4487
		.global2_addr = 0x1c,
4488
		.age_time_coeff = 15000,
4489
		.g1_irqs = 9,
4490
		.g2_irqs = 10,
4491
		.atu_move_port_mask = 0xf,
4492
		.pvt = true,
4493
		.multi_chip = true,
4494
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4495
		.ops = &mv88e6351_ops,
4496 4497 4498
	},

	[MV88E6352] = {
4499
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
4500 4501 4502 4503
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6352",
		.num_databases = 4096,
		.num_ports = 7,
4504
		.num_internal_phys = 5,
4505
		.num_gpio = 15,
4506
		.max_vid = 4095,
4507
		.port_base_addr = 0x10,
4508
		.phy_base_addr = 0x0,
4509
		.global1_addr = 0x1b,
4510
		.global2_addr = 0x1c,
4511
		.age_time_coeff = 15000,
4512
		.g1_irqs = 9,
4513
		.g2_irqs = 10,
4514
		.atu_move_port_mask = 0xf,
4515
		.pvt = true,
4516
		.multi_chip = true,
4517
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4518
		.ptp_support = true,
4519
		.ops = &mv88e6352_ops,
4520
	},
4521
	[MV88E6390] = {
4522
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
4523 4524 4525 4526
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4527
		.num_internal_phys = 9,
4528
		.num_gpio = 16,
4529
		.max_vid = 8191,
4530
		.port_base_addr = 0x0,
4531
		.phy_base_addr = 0x0,
4532
		.global1_addr = 0x1b,
4533
		.global2_addr = 0x1c,
4534
		.age_time_coeff = 3750,
4535
		.g1_irqs = 9,
4536
		.g2_irqs = 14,
4537
		.atu_move_port_mask = 0x1f,
4538
		.pvt = true,
4539
		.multi_chip = true,
4540
		.tag_protocol = DSA_TAG_PROTO_DSA,
4541
		.ptp_support = true,
4542 4543 4544
		.ops = &mv88e6390_ops,
	},
	[MV88E6390X] = {
4545
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
4546 4547 4548 4549
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4550
		.num_internal_phys = 9,
4551
		.num_gpio = 16,
4552
		.max_vid = 8191,
4553
		.port_base_addr = 0x0,
4554
		.phy_base_addr = 0x0,
4555
		.global1_addr = 0x1b,
4556
		.global2_addr = 0x1c,
4557
		.age_time_coeff = 3750,
4558
		.g1_irqs = 9,
4559
		.g2_irqs = 14,
4560
		.atu_move_port_mask = 0x1f,
4561
		.pvt = true,
4562
		.multi_chip = true,
4563
		.tag_protocol = DSA_TAG_PROTO_DSA,
4564
		.ptp_support = true,
4565 4566
		.ops = &mv88e6390x_ops,
	},
4567 4568
};

4569
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
4570
{
4571
	int i;
4572

4573 4574 4575
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
4576 4577 4578 4579

	return NULL;
}

4580
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
4581 4582
{
	const struct mv88e6xxx_info *info;
4583 4584 4585
	unsigned int prod_num, rev;
	u16 id;
	int err;
4586

4587
	mv88e6xxx_reg_lock(chip);
4588
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
4589
	mv88e6xxx_reg_unlock(chip);
4590 4591
	if (err)
		return err;
4592

4593 4594
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
4595 4596 4597 4598 4599

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

4600
	/* Update the compatible info with the probed one */
4601
	chip->info = info;
4602

4603 4604 4605 4606
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

4607 4608
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
4609 4610 4611 4612

	return 0;
}

4613
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
4614
{
4615
	struct mv88e6xxx_chip *chip;
4616

4617 4618
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
4619 4620
		return NULL;

4621
	chip->dev = dev;
4622

4623
	mutex_init(&chip->reg_lock);
4624
	INIT_LIST_HEAD(&chip->mdios);
4625

4626
	return chip;
4627 4628
}

4629 4630
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
							int port)
4631
{
V
Vivien Didelot 已提交
4632
	struct mv88e6xxx_chip *chip = ds->priv;
4633

4634
	return chip->info->tag_protocol;
4635 4636
}

4637
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4638
				      const struct switchdev_obj_port_mdb *mdb)
4639 4640 4641 4642 4643 4644 4645 4646 4647
{
	/* 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,
4648
				   const struct switchdev_obj_port_mdb *mdb)
4649
{
V
Vivien Didelot 已提交
4650
	struct mv88e6xxx_chip *chip = ds->priv;
4651

4652
	mv88e6xxx_reg_lock(chip);
4653
	if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4654
					 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
4655 4656
		dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
			port);
4657
	mv88e6xxx_reg_unlock(chip);
4658 4659 4660 4661 4662
}

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

4666
	mv88e6xxx_reg_lock(chip);
4667
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4668
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
4669
	mv88e6xxx_reg_unlock(chip);
4670 4671 4672 4673

	return err;
}

4674 4675 4676 4677 4678 4679
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;

4680
	mv88e6xxx_reg_lock(chip);
4681 4682 4683 4684
	if (chip->info->ops->port_set_egress_floods)
		err = chip->info->ops->port_set_egress_floods(chip, port,
							      unicast,
							      multicast);
4685
	mv88e6xxx_reg_unlock(chip);
4686 4687 4688 4689

	return err;
}

4690
static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
4691
	.get_tag_protocol	= mv88e6xxx_get_tag_protocol,
4692
	.setup			= mv88e6xxx_setup,
4693 4694 4695 4696 4697
	.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,
4698 4699 4700
	.get_strings		= mv88e6xxx_get_strings,
	.get_ethtool_stats	= mv88e6xxx_get_ethtool_stats,
	.get_sset_count		= mv88e6xxx_get_sset_count,
4701 4702
	.port_enable		= mv88e6xxx_port_enable,
	.port_disable		= mv88e6xxx_port_disable,
V
Vivien Didelot 已提交
4703 4704
	.get_mac_eee		= mv88e6xxx_get_mac_eee,
	.set_mac_eee		= mv88e6xxx_set_mac_eee,
4705
	.get_eeprom_len		= mv88e6xxx_get_eeprom_len,
4706 4707 4708 4709
	.get_eeprom		= mv88e6xxx_get_eeprom,
	.set_eeprom		= mv88e6xxx_set_eeprom,
	.get_regs_len		= mv88e6xxx_get_regs_len,
	.get_regs		= mv88e6xxx_get_regs,
4710
	.set_ageing_time	= mv88e6xxx_set_ageing_time,
4711 4712
	.port_bridge_join	= mv88e6xxx_port_bridge_join,
	.port_bridge_leave	= mv88e6xxx_port_bridge_leave,
4713
	.port_egress_floods	= mv88e6xxx_port_egress_floods,
4714
	.port_stp_state_set	= mv88e6xxx_port_stp_state_set,
4715
	.port_fast_age		= mv88e6xxx_port_fast_age,
4716 4717 4718 4719 4720 4721 4722
	.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,
4723 4724 4725
	.port_mdb_prepare       = mv88e6xxx_port_mdb_prepare,
	.port_mdb_add           = mv88e6xxx_port_mdb_add,
	.port_mdb_del           = mv88e6xxx_port_mdb_del,
4726 4727
	.crosschip_bridge_join	= mv88e6xxx_crosschip_bridge_join,
	.crosschip_bridge_leave	= mv88e6xxx_crosschip_bridge_leave,
4728 4729 4730 4731 4732
	.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,
4733 4734
};

4735
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
4736
{
4737
	struct device *dev = chip->dev;
4738 4739
	struct dsa_switch *ds;

4740
	ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
4741 4742 4743
	if (!ds)
		return -ENOMEM;

4744
	ds->priv = chip;
4745
	ds->dev = dev;
4746
	ds->ops = &mv88e6xxx_switch_ops;
4747 4748
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
4749 4750 4751

	dev_set_drvdata(dev, ds);

4752
	return dsa_register_switch(ds);
4753 4754
}

4755
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
4756
{
4757
	dsa_unregister_switch(chip->ds);
4758 4759
}

4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772
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;
}

4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787
/* 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);

4788
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
4789
{
4790
	struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
4791
	const struct mv88e6xxx_info *compat_info = NULL;
4792
	struct device *dev = &mdiodev->dev;
4793
	struct device_node *np = dev->of_node;
4794
	struct mv88e6xxx_chip *chip;
4795
	int port;
4796
	int err;
4797

4798 4799 4800
	if (!np && !pdata)
		return -EINVAL;

4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819
	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;
		}
	}

4820 4821 4822
	if (!compat_info)
		return -EINVAL;

4823
	chip = mv88e6xxx_alloc_chip(dev);
4824 4825 4826 4827
	if (!chip) {
		err = -ENOMEM;
		goto out;
	}
4828

4829
	chip->info = compat_info;
4830

4831
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
4832
	if (err)
4833
		goto out;
4834

4835
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4836 4837 4838 4839
	if (IS_ERR(chip->reset)) {
		err = PTR_ERR(chip->reset);
		goto out;
	}
4840 4841
	if (chip->reset)
		usleep_range(1000, 2000);
4842

4843
	err = mv88e6xxx_detect(chip);
4844
	if (err)
4845
		goto out;
4846

4847 4848
	mv88e6xxx_phy_init(chip);

4849 4850 4851 4852 4853 4854 4855
	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;
	}
4856

4857
	mv88e6xxx_reg_lock(chip);
4858
	err = mv88e6xxx_switch_reset(chip);
4859
	mv88e6xxx_reg_unlock(chip);
4860 4861 4862
	if (err)
		goto out;

4863 4864 4865 4866 4867 4868
	if (np) {
		chip->irq = of_irq_get(np, 0);
		if (chip->irq == -EPROBE_DEFER) {
			err = chip->irq;
			goto out;
		}
4869 4870
	}

4871 4872 4873
	if (pdata)
		chip->irq = pdata->irq;

4874
	/* Has to be performed before the MDIO bus is created, because
4875
	 * the PHYs will link their interrupts to these interrupt
4876 4877
	 * controllers
	 */
4878
	mv88e6xxx_reg_lock(chip);
4879
	if (chip->irq > 0)
4880
		err = mv88e6xxx_g1_irq_setup(chip);
4881 4882
	else
		err = mv88e6xxx_irq_poll_setup(chip);
4883
	mv88e6xxx_reg_unlock(chip);
4884

4885 4886
	if (err)
		goto out;
4887

4888 4889
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
4890
		if (err)
4891
			goto out_g1_irq;
4892 4893
	}

4894 4895 4896 4897 4898 4899 4900 4901
	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;

4902
	err = mv88e6xxx_mdios_register(chip, np);
4903
	if (err)
4904
		goto out_g1_vtu_prob_irq;
4905

4906
	err = mv88e6xxx_register_switch(chip);
4907 4908
	if (err)
		goto out_mdio;
4909

4910
	return 0;
4911 4912

out_mdio:
4913
	mv88e6xxx_mdios_unregister(chip);
4914
out_g1_vtu_prob_irq:
4915
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
4916
out_g1_atu_prob_irq:
4917
	mv88e6xxx_g1_atu_prob_irq_free(chip);
4918
out_g2_irq:
4919
	if (chip->info->g2_irqs > 0)
4920 4921
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
4922
	if (chip->irq > 0)
4923
		mv88e6xxx_g1_irq_free(chip);
4924 4925
	else
		mv88e6xxx_irq_poll_free(chip);
4926
out:
4927 4928 4929
	if (pdata)
		dev_put(pdata->netdev);

4930
	return err;
4931
}
4932 4933 4934 4935

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

4938 4939
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
4940
		mv88e6xxx_ptp_free(chip);
4941
	}
4942

4943
	mv88e6xxx_phy_destroy(chip);
4944
	mv88e6xxx_unregister_switch(chip);
4945
	mv88e6xxx_mdios_unregister(chip);
4946

4947 4948 4949 4950 4951 4952 4953
	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)
4954
		mv88e6xxx_g1_irq_free(chip);
4955 4956
	else
		mv88e6xxx_irq_poll_free(chip);
4957 4958 4959
}

static const struct of_device_id mv88e6xxx_of_match[] = {
4960 4961 4962 4963
	{
		.compatible = "marvell,mv88e6085",
		.data = &mv88e6xxx_table[MV88E6085],
	},
4964 4965 4966 4967
	{
		.compatible = "marvell,mv88e6190",
		.data = &mv88e6xxx_table[MV88E6190],
	},
4968 4969 4970 4971
	{
		.compatible = "marvell,mv88e6250",
		.data = &mv88e6xxx_table[MV88E6250],
	},
4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982
	{ /* 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,
4983
		.pm = &mv88e6xxx_pm_ops,
4984 4985 4986
	},
};

4987
mdio_module_driver(mv88e6xxx_driver);
4988 4989 4990 4991

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