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

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

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

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

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

56
	assert_reg_lock(chip);
57

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

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

	return 0;
}

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

72
	assert_reg_lock(chip);
73

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

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

81 82 83
	return 0;
}

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

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

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

		usleep_range(1000, 2000);
	}

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

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

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

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

	return mdio_bus->bus;
}

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

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

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

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

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

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

	if (err)
		goto out;

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

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

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

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

	return mv88e6xxx_g1_irq_thread_work(chip);
}

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

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

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

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

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

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

out:
217
	mv88e6xxx_reg_unlock(chip);
218 219
}

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

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

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

	return 0;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return 0;

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

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

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

	return err;
}

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

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

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

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

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

	return err;
}

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

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

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

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

	kthread_init_delayed_work(&chip->irq_poll_work,
				  mv88e6xxx_irq_poll);

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

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

	return 0;
}

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

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

400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
static int mv88e6xxx_port_config_interface(struct mv88e6xxx_chip *chip,
					   int port, phy_interface_t interface)
{
	int err;

	if (chip->info->ops->port_set_rgmii_delay) {
		err = chip->info->ops->port_set_rgmii_delay(chip, port,
							    interface);
		if (err && err != -EOPNOTSUPP)
			return err;
	}

	if (chip->info->ops->port_set_cmode) {
		err = chip->info->ops->port_set_cmode(chip, port,
						      interface);
		if (err && err != -EOPNOTSUPP)
			return err;
	}

	return 0;
}

422 423 424
static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
				    int link, int speed, int duplex, int pause,
				    phy_interface_t mode)
425 426 427 428 429 430 431
{
	int err;

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

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

436 437 438
	if (chip->info->ops->port_set_speed_duplex) {
		err = chip->info->ops->port_set_speed_duplex(chip, port,
							     speed, duplex);
439 440 441 442
		if (err && err != -EOPNOTSUPP)
			goto restore_link;
	}

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

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

452
	err = mv88e6xxx_port_config_interface(chip, port, mode);
453 454
restore_link:
	if (chip->info->ops->port_set_link(chip, port, link))
455
		dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
456 457 458 459

	return err;
}

460 461 462 463 464 465 466
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;
}

467 468 469 470 471 472 473 474 475 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 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
static int mv88e6xxx_serdes_pcs_get_state(struct dsa_switch *ds, int port,
					  struct phylink_link_state *state)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	u8 lane;
	int err;

	mv88e6xxx_reg_lock(chip);
	lane = mv88e6xxx_serdes_get_lane(chip, port);
	if (lane && chip->info->ops->serdes_pcs_get_state)
		err = chip->info->ops->serdes_pcs_get_state(chip, port, lane,
							    state);
	else
		err = -EOPNOTSUPP;
	mv88e6xxx_reg_unlock(chip);

	return err;
}

static int mv88e6xxx_serdes_pcs_config(struct mv88e6xxx_chip *chip, int port,
				       unsigned int mode,
				       phy_interface_t interface,
				       const unsigned long *advertise)
{
	const struct mv88e6xxx_ops *ops = chip->info->ops;
	u8 lane;

	if (ops->serdes_pcs_config) {
		lane = mv88e6xxx_serdes_get_lane(chip, port);
		if (lane)
			return ops->serdes_pcs_config(chip, port, lane, mode,
						      interface, advertise);
	}

	return 0;
}

static void mv88e6xxx_serdes_pcs_an_restart(struct dsa_switch *ds, int port)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	const struct mv88e6xxx_ops *ops;
	int err = 0;
	u8 lane;

	ops = chip->info->ops;

	if (ops->serdes_pcs_an_restart) {
		mv88e6xxx_reg_lock(chip);
		lane = mv88e6xxx_serdes_get_lane(chip, port);
		if (lane)
			err = ops->serdes_pcs_an_restart(chip, port, lane);
		mv88e6xxx_reg_unlock(chip);

		if (err)
			dev_err(ds->dev, "p%d: failed to restart AN\n", port);
	}
}

static int mv88e6xxx_serdes_pcs_link_up(struct mv88e6xxx_chip *chip, int port,
					unsigned int mode,
					int speed, int duplex)
{
	const struct mv88e6xxx_ops *ops = chip->info->ops;
	u8 lane;

	if (!phylink_autoneg_inband(mode) && ops->serdes_pcs_link_up) {
		lane = mv88e6xxx_serdes_get_lane(chip, port);
		if (lane)
			return ops->serdes_pcs_link_up(chip, port, lane,
						       speed, duplex);
	}

	return 0;
}

542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
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);
}

568 569 570 571 572 573 574 575 576 577 578 579 580 581
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);
}

582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
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)
{
597
	if (port >= 9) {
598
		phylink_set(mask, 2500baseX_Full);
599 600
		phylink_set(mask, 2500baseT_Full);
	}
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620

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

621 622 623 624
static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
			       unsigned long *supported,
			       struct phylink_link_state *state)
{
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
	__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);
644 645 646 647 648 649 650
}

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;
651
	int err;
652

653 654 655 656 657
	/* FIXME: is this the correct test? If we're in fixed mode on an
	 * internal port, why should we process this any different from
	 * PHY mode? On the other hand, the port may be automedia between
	 * an internal PHY and the serdes...
	 */
658
	if ((mode == MLO_AN_PHY) && mv88e6xxx_phy_is_internal(ds, port))
659 660
		return;

661
	mv88e6xxx_reg_lock(chip);
662 663 664 665 666
	/* FIXME: should we force the link down here - but if we do, how
	 * do we restore the link force/unforce state? The driver layering
	 * gets in the way.
	 */
	err = mv88e6xxx_port_config_interface(chip, port, state->interface);
667 668 669 670 671 672 673 674 675 676 677 678
	if (err && err != -EOPNOTSUPP)
		goto err_unlock;

	err = mv88e6xxx_serdes_pcs_config(chip, port, mode, state->interface,
					  state->advertising);
	/* FIXME: we should restart negotiation if something changed - which
	 * is something we get if we convert to using phylinks PCS operations.
	 */
	if (err > 0)
		err = 0;

err_unlock:
679
	mv88e6xxx_reg_unlock(chip);
680 681

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

685 686 687
static void mv88e6xxx_mac_link_down(struct dsa_switch *ds, int port,
				    unsigned int mode,
				    phy_interface_t interface)
688 689
{
	struct mv88e6xxx_chip *chip = ds->priv;
690 691
	const struct mv88e6xxx_ops *ops;
	int err = 0;
692

693
	ops = chip->info->ops;
694

695 696 697 698 699 700 701 702 703
	/* Internal PHYs propagate their configuration directly to the MAC.
	 * External PHYs depend on whether the PPU is enabled for this port.
	 * FIXME: we should be using the PPU enable state here. What about
	 * an automedia port?
	 */
	if (!mv88e6xxx_phy_is_internal(ds, port) && ops->port_set_link) {
		mv88e6xxx_reg_lock(chip);
		err = ops->port_set_link(chip, port, LINK_FORCED_DOWN);
		mv88e6xxx_reg_unlock(chip);
704

705 706 707 708
		if (err)
			dev_err(chip->dev,
				"p%d: failed to force MAC link down\n", port);
	}
709 710 711 712
}

static void mv88e6xxx_mac_link_up(struct dsa_switch *ds, int port,
				  unsigned int mode, phy_interface_t interface,
713 714 715
				  struct phy_device *phydev,
				  int speed, int duplex,
				  bool tx_pause, bool rx_pause)
716
{
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732
	struct mv88e6xxx_chip *chip = ds->priv;
	const struct mv88e6xxx_ops *ops;
	int err = 0;

	ops = chip->info->ops;

	/* Internal PHYs propagate their configuration directly to the MAC.
	 * External PHYs depend on whether the PPU is enabled for this port.
	 * FIXME: we should be using the PPU enable state here. What about
	 * an automedia port?
	 */
	if (!mv88e6xxx_phy_is_internal(ds, port)) {
		mv88e6xxx_reg_lock(chip);
		/* FIXME: for an automedia port, should we force the link
		 * down here - what if the link comes up due to "other" media
		 * while we're bringing the port up, how is the exclusivity
733
		 * handled in the Marvell hardware? E.g. port 2 on 88E6390
734 735
		 * shared between internal PHY and Serdes.
		 */
736 737 738 739 740
		err = mv88e6xxx_serdes_pcs_link_up(chip, port, mode, speed,
						   duplex);
		if (err)
			goto error;

741 742 743
		if (ops->port_set_speed_duplex) {
			err = ops->port_set_speed_duplex(chip, port,
							 speed, duplex);
744 745 746 747 748 749 750 751 752 753 754 755 756
			if (err && err != -EOPNOTSUPP)
				goto error;
		}

		if (ops->port_set_link)
			err = ops->port_set_link(chip, port, LINK_FORCED_UP);
error:
		mv88e6xxx_reg_unlock(chip);

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

759
static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
760
{
761 762
	if (!chip->info->ops->stats_snapshot)
		return -EOPNOTSUPP;
763

764
	return chip->info->ops->stats_snapshot(chip, port);
765 766
}

767
static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826
	{ "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, },
827 828
};

829
static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
830
					    struct mv88e6xxx_hw_stat *s,
831 832
					    int port, u16 bank1_select,
					    u16 histogram)
833 834 835
{
	u32 low;
	u32 high = 0;
836
	u16 reg = 0;
837
	int err;
838 839
	u64 value;

840
	switch (s->type) {
841
	case STATS_TYPE_PORT:
842 843
		err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
		if (err)
844
			return U64_MAX;
845

846
		low = reg;
847
		if (s->size == 4) {
848 849
			err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
			if (err)
850
				return U64_MAX;
851
			low |= ((u32)reg) << 16;
852
		}
853
		break;
854
	case STATS_TYPE_BANK1:
855
		reg = bank1_select;
856 857
		/* fall through */
	case STATS_TYPE_BANK0:
858
		reg |= s->reg | histogram;
859
		mv88e6xxx_g1_stats_read(chip, reg, &low);
860
		if (s->size == 8)
861
			mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
862 863
		break;
	default:
864
		return U64_MAX;
865
	}
866
	value = (((u64)high) << 32) | low;
867 868 869
	return value;
}

870 871
static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data, int types)
872
{
873 874
	struct mv88e6xxx_hw_stat *stat;
	int i, j;
875

876 877
	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
		stat = &mv88e6xxx_hw_stats[i];
878
		if (stat->type & types) {
879 880 881 882
			memcpy(data + j * ETH_GSTRING_LEN, stat->string,
			       ETH_GSTRING_LEN);
			j++;
		}
883
	}
884 885

	return j;
886 887
}

888 889
static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
890
{
891 892
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_PORT);
893 894
}

895 896 897 898 899 900
static int mv88e6250_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
{
	return mv88e6xxx_stats_get_strings(chip, data, STATS_TYPE_BANK0);
}

901 902
static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
903
{
904 905
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
906 907
}

908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925
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);
}

926
static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
927
				  u32 stringset, uint8_t *data)
928
{
V
Vivien Didelot 已提交
929
	struct mv88e6xxx_chip *chip = ds->priv;
930
	int count = 0;
931

932 933 934
	if (stringset != ETH_SS_STATS)
		return;

935
	mv88e6xxx_reg_lock(chip);
936

937
	if (chip->info->ops->stats_get_strings)
938 939 940 941
		count = chip->info->ops->stats_get_strings(chip, data);

	if (chip->info->ops->serdes_get_strings) {
		data += count * ETH_GSTRING_LEN;
942
		count = chip->info->ops->serdes_get_strings(chip, port, data);
943
	}
944

945 946 947
	data += count * ETH_GSTRING_LEN;
	mv88e6xxx_atu_vtu_get_strings(data);

948
	mv88e6xxx_reg_unlock(chip);
949 950 951 952 953
}

static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
					  int types)
{
954 955 956 957 958
	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];
959
		if (stat->type & types)
960 961 962
			j++;
	}
	return j;
963 964
}

965 966 967 968 969 970
static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
{
	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
					      STATS_TYPE_PORT);
}

971 972 973 974 975
static int mv88e6250_stats_get_sset_count(struct mv88e6xxx_chip *chip)
{
	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0);
}

976 977 978 979 980 981
static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
{
	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
					      STATS_TYPE_BANK1);
}

982
static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
983 984
{
	struct mv88e6xxx_chip *chip = ds->priv;
985 986
	int serdes_count = 0;
	int count = 0;
987

988 989 990
	if (sset != ETH_SS_STATS)
		return 0;

991
	mv88e6xxx_reg_lock(chip);
992
	if (chip->info->ops->stats_get_sset_count)
993 994 995 996 997 998 999
		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);
1000
	if (serdes_count < 0) {
1001
		count = serdes_count;
1002 1003 1004 1005 1006
		goto out;
	}
	count += serdes_count;
	count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);

1007
out:
1008
	mv88e6xxx_reg_unlock(chip);
1009

1010
	return count;
1011 1012
}

1013 1014 1015
static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data, int types,
				     u16 bank1_select, u16 histogram)
1016 1017 1018 1019 1020 1021 1022
{
	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) {
1023
			mv88e6xxx_reg_lock(chip);
1024 1025 1026
			data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
							      bank1_select,
							      histogram);
1027
			mv88e6xxx_reg_unlock(chip);
1028

1029 1030 1031
			j++;
		}
	}
1032
	return j;
1033 1034
}

1035 1036
static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
1037 1038
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
1039
					 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
1040
					 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1041 1042
}

1043 1044 1045 1046 1047 1048 1049
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);
}

1050 1051
static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
1052 1053
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
1054
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1055 1056
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
					 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1057 1058
}

1059 1060
static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
1061 1062 1063
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1064 1065
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
					 0);
1066 1067
}

1068 1069 1070 1071 1072 1073 1074 1075 1076 1077
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;
}

1078 1079 1080
static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
				uint64_t *data)
{
1081 1082
	int count = 0;

1083
	if (chip->info->ops->stats_get_stats)
1084 1085
		count = chip->info->ops->stats_get_stats(chip, port, data);

1086
	mv88e6xxx_reg_lock(chip);
1087 1088
	if (chip->info->ops->serdes_get_stats) {
		data += count;
1089
		count = chip->info->ops->serdes_get_stats(chip, port, data);
1090
	}
1091 1092
	data += count;
	mv88e6xxx_atu_vtu_get_stats(chip, port, data);
1093
	mv88e6xxx_reg_unlock(chip);
1094 1095
}

1096 1097
static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
					uint64_t *data)
1098
{
V
Vivien Didelot 已提交
1099
	struct mv88e6xxx_chip *chip = ds->priv;
1100 1101
	int ret;

1102
	mv88e6xxx_reg_lock(chip);
1103

1104
	ret = mv88e6xxx_stats_snapshot(chip, port);
1105
	mv88e6xxx_reg_unlock(chip);
1106 1107

	if (ret < 0)
1108
		return;
1109 1110

	mv88e6xxx_get_stats(chip, port, data);
1111

1112 1113
}

1114
static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
1115
{
1116 1117 1118 1119 1120 1121 1122 1123
	struct mv88e6xxx_chip *chip = ds->priv;
	int len;

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

	return len;
1124 1125
}

1126 1127
static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
			       struct ethtool_regs *regs, void *_p)
1128
{
V
Vivien Didelot 已提交
1129
	struct mv88e6xxx_chip *chip = ds->priv;
1130 1131
	int err;
	u16 reg;
1132 1133 1134
	u16 *p = _p;
	int i;

1135
	regs->version = chip->info->prod_num;
1136 1137 1138

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

1139
	mv88e6xxx_reg_lock(chip);
1140

1141 1142
	for (i = 0; i < 32; i++) {

1143 1144 1145
		err = mv88e6xxx_port_read(chip, port, i, &reg);
		if (!err)
			p[i] = reg;
1146
	}
1147

1148 1149 1150
	if (chip->info->ops->serdes_get_regs)
		chip->info->ops->serdes_get_regs(chip, port, &p[i]);

1151
	mv88e6xxx_reg_unlock(chip);
1152 1153
}

V
Vivien Didelot 已提交
1154 1155
static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
1156
{
1157 1158
	/* Nothing to do on the port's MAC */
	return 0;
1159 1160
}

V
Vivien Didelot 已提交
1161 1162
static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
1163
{
1164 1165
	/* Nothing to do on the port's MAC */
	return 0;
1166 1167
}

1168
/* Mask of the local ports allowed to receive frames from a given fabric port */
1169
static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
1170
{
1171 1172
	struct dsa_switch *ds = chip->ds;
	struct dsa_switch_tree *dst = ds->dst;
1173
	struct net_device *br;
1174 1175
	struct dsa_port *dp;
	bool found = false;
1176
	u16 pvlan;
1177

1178 1179 1180 1181 1182 1183
	list_for_each_entry(dp, &dst->ports, list) {
		if (dp->ds->index == dev && dp->index == port) {
			found = true;
			break;
		}
	}
1184 1185

	/* Prevent frames from unknown switch or port */
1186
	if (!found)
1187 1188 1189
		return 0;

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

1193
	br = dp->bridge_dev;
1194 1195 1196 1197 1198
	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.
	 */
1199 1200 1201 1202 1203 1204
	list_for_each_entry(dp, &dst->ports, list)
		if (dp->ds == ds &&
		    (dp->type == DSA_PORT_TYPE_CPU ||
		     dp->type == DSA_PORT_TYPE_DSA ||
		     (br && dp->bridge_dev == br)))
			pvlan |= BIT(dp->index);
1205 1206 1207 1208

	return pvlan;
}

1209
static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
1210 1211
{
	u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
1212 1213 1214

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

1216
	return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
1217 1218
}

1219 1220
static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
					 u8 state)
1221
{
V
Vivien Didelot 已提交
1222
	struct mv88e6xxx_chip *chip = ds->priv;
1223
	int err;
1224

1225
	mv88e6xxx_reg_lock(chip);
1226
	err = mv88e6xxx_port_set_state(chip, port, state);
1227
	mv88e6xxx_reg_unlock(chip);
1228 1229

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

1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251
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;
}

1252 1253
static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
{
1254
	struct dsa_switch *ds = chip->ds;
1255 1256 1257 1258 1259 1260 1261 1262
	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++) {
1263 1264 1265
		port = dsa_routing_port(ds, target);
		if (port == ds->num_ports)
			port = 0x1f;
1266 1267 1268 1269 1270 1271

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

1272 1273 1274 1275 1276 1277 1278
	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;
	}

1279 1280 1281 1282
	err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
	if (err)
		return err;

1283 1284 1285
	return 0;
}

1286 1287 1288 1289 1290 1291 1292 1293 1294
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;
}

1295 1296 1297 1298 1299 1300 1301 1302
static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->rmu_disable)
		return chip->info->ops->rmu_disable(chip);

	return 0;
}

1303 1304 1305 1306 1307 1308 1309 1310
static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->pot_clear)
		return chip->info->ops->pot_clear(chip);

	return 0;
}

1311 1312 1313 1314 1315 1316 1317 1318
static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->mgmt_rsvd2cpu)
		return chip->info->ops->mgmt_rsvd2cpu(chip);

	return 0;
}

1319 1320
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
1321 1322
	int err;

1323 1324 1325 1326
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

1327 1328 1329 1330
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

1331 1332 1333
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353
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;
}

1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366
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;
}

1367 1368 1369 1370 1371
static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
{
	u16 pvlan = 0;

	if (!mv88e6xxx_has_pvt(chip))
1372
		return 0;
1373 1374 1375

	/* Skip the local source device, which uses in-chip port VLAN */
	if (dev != chip->ds->index)
1376
		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1377 1378 1379 1380

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

1381 1382
static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
{
1383 1384 1385
	int dev, port;
	int err;

1386 1387 1388 1389 1390 1391
	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.
	 */
1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404
	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;
1405 1406
}

1407 1408 1409 1410 1411
static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

1412
	mv88e6xxx_reg_lock(chip);
1413
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1414
	mv88e6xxx_reg_unlock(chip);
1415 1416

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

1420 1421 1422 1423 1424 1425 1426 1427
static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
{
	if (!chip->info->max_vid)
		return 0;

	return mv88e6xxx_g1_vtu_flush(chip);
}

1428 1429 1430 1431 1432 1433 1434 1435 1436
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);
}

1437 1438 1439 1440 1441 1442 1443 1444 1445
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);
}

1446
static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1447 1448
{
	DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1449
	struct mv88e6xxx_vtu_entry vlan;
1450
	int i, err;
1451 1452 1453

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

1454
	/* Set every FID bit used by the (un)bridged ports */
1455
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1456
		err = mv88e6xxx_port_get_fid(chip, i, fid);
1457 1458 1459 1460 1461 1462
		if (err)
			return err;

		set_bit(*fid, fid_bitmap);
	}

1463
	/* Set every FID bit used by the VLAN entries */
1464 1465 1466
	vlan.vid = chip->info->max_vid;
	vlan.valid = false;

1467
	do {
1468
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1469 1470 1471 1472 1473 1474 1475
		if (err)
			return err;

		if (!vlan.valid)
			break;

		set_bit(vlan.fid, fid_bitmap);
1476
	} while (vlan.vid < chip->info->max_vid);
1477 1478 1479 1480 1481

	/* 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);
1482
	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1483 1484 1485
		return -ENOSPC;

	/* Clear the database */
1486
	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1487 1488
}

1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504
static int mv88e6xxx_atu_get_hash(struct mv88e6xxx_chip *chip, u8 *hash)
{
	if (chip->info->ops->atu_get_hash)
		return chip->info->ops->atu_get_hash(chip, hash);

	return -EOPNOTSUPP;
}

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

	return -EOPNOTSUPP;
}

1505 1506 1507
static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
					u16 vid_begin, u16 vid_end)
{
V
Vivien Didelot 已提交
1508
	struct mv88e6xxx_chip *chip = ds->priv;
1509
	struct mv88e6xxx_vtu_entry vlan;
1510 1511
	int i, err;

1512 1513 1514 1515
	/* 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;

1516 1517 1518
	if (!vid_begin)
		return -EOPNOTSUPP;

1519 1520 1521
	vlan.vid = vid_begin - 1;
	vlan.valid = false;

1522
	do {
1523
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1524
		if (err)
1525
			return err;
1526 1527 1528 1529 1530 1531 1532

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

1533
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1534 1535 1536
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

1537
			if (!dsa_to_port(ds, i)->slave)
1538 1539
				continue;

1540
			if (vlan.member[i] ==
1541
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1542 1543
				continue;

V
Vivien Didelot 已提交
1544
			if (dsa_to_port(ds, i)->bridge_dev ==
1545
			    dsa_to_port(ds, port)->bridge_dev)
1546 1547
				break; /* same bridge, check next VLAN */

V
Vivien Didelot 已提交
1548
			if (!dsa_to_port(ds, i)->bridge_dev)
1549 1550
				continue;

1551 1552
			dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
				port, vlan.vid, i,
V
Vivien Didelot 已提交
1553
				netdev_name(dsa_to_port(ds, i)->bridge_dev));
1554
			return -EOPNOTSUPP;
1555 1556 1557
		}
	} while (vlan.vid < vid_end);

1558
	return 0;
1559 1560
}

1561 1562
static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
					 bool vlan_filtering)
1563
{
V
Vivien Didelot 已提交
1564
	struct mv88e6xxx_chip *chip = ds->priv;
1565 1566
	u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
		MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
1567
	int err;
1568

1569
	if (!chip->info->max_vid)
1570 1571
		return -EOPNOTSUPP;

1572
	mv88e6xxx_reg_lock(chip);
1573
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1574
	mv88e6xxx_reg_unlock(chip);
1575

1576
	return err;
1577 1578
}

1579 1580
static int
mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1581
			    const struct switchdev_obj_port_vlan *vlan)
1582
{
V
Vivien Didelot 已提交
1583
	struct mv88e6xxx_chip *chip = ds->priv;
1584 1585
	int err;

1586
	if (!chip->info->max_vid)
1587 1588
		return -EOPNOTSUPP;

1589 1590 1591
	/* 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.
	 */
1592
	mv88e6xxx_reg_lock(chip);
1593 1594
	err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
					   vlan->vid_end);
1595
	mv88e6xxx_reg_unlock(chip);
1596

1597 1598 1599
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */
1600
	return err;
1601 1602
}

1603 1604 1605 1606 1607
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;
1608 1609
	struct mv88e6xxx_vtu_entry vlan;
	u16 fid;
1610 1611 1612
	int err;

	/* Null VLAN ID corresponds to the port private database */
1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630
	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;
	}
1631

1632
	entry.state = 0;
1633 1634 1635
	ether_addr_copy(entry.mac, addr);
	eth_addr_dec(entry.mac);

1636
	err = mv88e6xxx_g1_atu_getnext(chip, fid, &entry);
1637 1638 1639 1640
	if (err)
		return err;

	/* Initialize a fresh ATU entry if it isn't found */
1641
	if (!entry.state || !ether_addr_equal(entry.mac, addr)) {
1642 1643 1644 1645 1646
		memset(&entry, 0, sizeof(entry));
		ether_addr_copy(entry.mac, addr);
	}

	/* Purge the ATU entry only if no port is using it anymore */
1647
	if (!state) {
1648 1649
		entry.portvec &= ~BIT(port);
		if (!entry.portvec)
1650
			entry.state = 0;
1651 1652 1653 1654 1655
	} else {
		entry.portvec |= BIT(port);
		entry.state = state;
	}

1656
	return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry);
1657 1658
}

1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868
static int mv88e6xxx_policy_apply(struct mv88e6xxx_chip *chip, int port,
				  const struct mv88e6xxx_policy *policy)
{
	enum mv88e6xxx_policy_mapping mapping = policy->mapping;
	enum mv88e6xxx_policy_action action = policy->action;
	const u8 *addr = policy->addr;
	u16 vid = policy->vid;
	u8 state;
	int err;
	int id;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return 0;
}

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

	mv88e6xxx_reg_lock(chip);

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

	mv88e6xxx_reg_unlock(chip);

	return err;
}

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

	mv88e6xxx_reg_lock(chip);

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

	mv88e6xxx_reg_unlock(chip);

	return err;
}

1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891
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;
}

1892
static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port,
1893
				    u16 vid, u8 member, bool warn)
1894
{
1895
	const u8 non_member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1896
	struct mv88e6xxx_vtu_entry vlan;
1897
	int i, err;
1898

1899 1900
	if (!vid)
		return -EOPNOTSUPP;
1901

1902 1903
	vlan.vid = vid - 1;
	vlan.valid = false;
1904

1905
	err = mv88e6xxx_vtu_getnext(chip, &vlan);
1906 1907 1908
	if (err)
		return err;

1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937
	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;
1938
	} else if (warn) {
1939 1940 1941 1942 1943
		dev_info(chip->dev, "p%d: already a member of VLAN %d\n",
			 port, vid);
	}

	return 0;
1944 1945
}

1946
static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1947
				    const struct switchdev_obj_port_vlan *vlan)
1948
{
V
Vivien Didelot 已提交
1949
	struct mv88e6xxx_chip *chip = ds->priv;
1950 1951
	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1952
	bool warn;
1953
	u8 member;
1954 1955
	u16 vid;

1956
	if (!chip->info->max_vid)
1957 1958
		return;

1959
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1960
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1961
	else if (untagged)
1962
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
1963
	else
1964
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
1965

1966 1967 1968 1969 1970
	/* net/dsa/slave.c will call dsa_port_vlan_add() for the affected port
	 * and then the CPU port. Do not warn for duplicates for the CPU port.
	 */
	warn = !dsa_is_cpu_port(ds, port) && !dsa_is_dsa_port(ds, port);

1971
	mv88e6xxx_reg_lock(chip);
1972

1973
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
1974
		if (mv88e6xxx_port_vlan_join(chip, port, vid, member, warn))
1975 1976
			dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
				vid, untagged ? 'u' : 't');
1977

1978
	if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1979 1980
		dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
			vlan->vid_end);
1981

1982
	mv88e6xxx_reg_unlock(chip);
1983 1984
}

1985 1986
static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,
				     int port, u16 vid)
1987
{
1988
	struct mv88e6xxx_vtu_entry vlan;
1989 1990
	int i, err;

1991 1992 1993 1994 1995 1996 1997
	if (!vid)
		return -EOPNOTSUPP;

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

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

2001 2002 2003 2004 2005
	/* 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)
2006
		return -EOPNOTSUPP;
2007

2008
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
2009 2010

	/* keep the VLAN unless all ports are excluded */
2011
	vlan.valid = false;
2012
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
2013 2014
		if (vlan.member[i] !=
		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
2015
			vlan.valid = true;
2016 2017 2018 2019
			break;
		}
	}

2020
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
2021 2022 2023
	if (err)
		return err;

2024
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
2025 2026
}

2027 2028
static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
				   const struct switchdev_obj_port_vlan *vlan)
2029
{
V
Vivien Didelot 已提交
2030
	struct mv88e6xxx_chip *chip = ds->priv;
2031 2032 2033
	u16 pvid, vid;
	int err = 0;

2034
	if (!chip->info->max_vid)
2035 2036
		return -EOPNOTSUPP;

2037
	mv88e6xxx_reg_lock(chip);
2038

2039
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
2040 2041 2042
	if (err)
		goto unlock;

2043
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
2044
		err = mv88e6xxx_port_vlan_leave(chip, port, vid);
2045 2046 2047 2048
		if (err)
			goto unlock;

		if (vid == pvid) {
2049
			err = mv88e6xxx_port_set_pvid(chip, port, 0);
2050 2051 2052 2053 2054
			if (err)
				goto unlock;
		}
	}

2055
unlock:
2056
	mv88e6xxx_reg_unlock(chip);
2057 2058 2059 2060

	return err;
}

2061 2062
static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
				  const unsigned char *addr, u16 vid)
2063
{
V
Vivien Didelot 已提交
2064
	struct mv88e6xxx_chip *chip = ds->priv;
2065
	int err;
2066

2067
	mv88e6xxx_reg_lock(chip);
2068 2069
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
2070
	mv88e6xxx_reg_unlock(chip);
2071 2072

	return err;
2073 2074
}

2075
static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
2076
				  const unsigned char *addr, u16 vid)
2077
{
V
Vivien Didelot 已提交
2078
	struct mv88e6xxx_chip *chip = ds->priv;
2079
	int err;
2080

2081
	mv88e6xxx_reg_lock(chip);
2082
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid, 0);
2083
	mv88e6xxx_reg_unlock(chip);
2084

2085
	return err;
2086 2087
}

2088 2089
static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
				      u16 fid, u16 vid, int port,
2090
				      dsa_fdb_dump_cb_t *cb, void *data)
2091
{
2092
	struct mv88e6xxx_atu_entry addr;
2093
	bool is_static;
2094 2095
	int err;

2096
	addr.state = 0;
2097
	eth_broadcast_addr(addr.mac);
2098 2099

	do {
2100
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
2101
		if (err)
2102
			return err;
2103

2104
		if (!addr.state)
2105 2106
			break;

2107
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
2108 2109
			continue;

2110 2111
		if (!is_unicast_ether_addr(addr.mac))
			continue;
2112

2113 2114 2115
		is_static = (addr.state ==
			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
		err = cb(addr.mac, vid, is_static, data);
2116 2117
		if (err)
			return err;
2118 2119 2120 2121 2122
	} while (!is_broadcast_ether_addr(addr.mac));

	return err;
}

2123
static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2124
				  dsa_fdb_dump_cb_t *cb, void *data)
2125
{
2126
	struct mv88e6xxx_vtu_entry vlan;
2127
	u16 fid;
2128 2129
	int err;

2130
	/* Dump port's default Filtering Information Database (VLAN ID 0) */
2131
	err = mv88e6xxx_port_get_fid(chip, port, &fid);
2132
	if (err)
2133
		return err;
2134

2135
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
2136
	if (err)
2137
		return err;
2138

2139
	/* Dump VLANs' Filtering Information Databases */
2140 2141 2142
	vlan.vid = chip->info->max_vid;
	vlan.valid = false;

2143
	do {
2144
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
2145
		if (err)
2146
			return err;
2147 2148 2149 2150

		if (!vlan.valid)
			break;

2151
		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
2152
						 cb, data);
2153
		if (err)
2154
			return err;
2155
	} while (vlan.vid < chip->info->max_vid);
2156

2157 2158 2159 2160
	return err;
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2161
				   dsa_fdb_dump_cb_t *cb, void *data)
2162
{
V
Vivien Didelot 已提交
2163
	struct mv88e6xxx_chip *chip = ds->priv;
2164 2165
	int err;

2166
	mv88e6xxx_reg_lock(chip);
2167
	err = mv88e6xxx_port_db_dump(chip, port, cb, data);
2168
	mv88e6xxx_reg_unlock(chip);
2169

2170
	return err;
2171 2172
}

2173 2174
static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
				struct net_device *br)
2175
{
2176 2177 2178
	struct dsa_switch *ds = chip->ds;
	struct dsa_switch_tree *dst = ds->dst;
	struct dsa_port *dp;
2179
	int err;
2180

2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195
	list_for_each_entry(dp, &dst->ports, list) {
		if (dp->bridge_dev == br) {
			if (dp->ds == ds) {
				/* This is a local bridge group member,
				 * remap its Port VLAN Map.
				 */
				err = mv88e6xxx_port_vlan_map(chip, dp->index);
				if (err)
					return err;
			} else {
				/* This is an external bridge group member,
				 * remap its cross-chip Port VLAN Table entry.
				 */
				err = mv88e6xxx_pvt_map(chip, dp->ds->index,
							dp->index);
2196 2197 2198 2199 2200 2201
				if (err)
					return err;
			}
		}
	}

2202 2203 2204 2205 2206 2207 2208 2209 2210
	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;

2211
	mv88e6xxx_reg_lock(chip);
2212
	err = mv88e6xxx_bridge_map(chip, br);
2213
	mv88e6xxx_reg_unlock(chip);
2214

2215
	return err;
2216 2217
}

2218 2219
static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
					struct net_device *br)
2220
{
V
Vivien Didelot 已提交
2221
	struct mv88e6xxx_chip *chip = ds->priv;
2222

2223
	mv88e6xxx_reg_lock(chip);
2224 2225 2226
	if (mv88e6xxx_bridge_map(chip, br) ||
	    mv88e6xxx_port_vlan_map(chip, port))
		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
2227
	mv88e6xxx_reg_unlock(chip);
2228 2229
}

2230 2231 2232 2233 2234 2235
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;

2236
	mv88e6xxx_reg_lock(chip);
2237
	err = mv88e6xxx_pvt_map(chip, dev, port);
2238
	mv88e6xxx_reg_unlock(chip);
2239 2240 2241 2242 2243 2244 2245 2246 2247

	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;

2248
	mv88e6xxx_reg_lock(chip);
2249 2250
	if (mv88e6xxx_pvt_map(chip, dev, port))
		dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
2251
	mv88e6xxx_reg_unlock(chip);
2252 2253
}

2254 2255 2256 2257 2258 2259 2260 2261
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->reset)
		return chip->info->ops->reset(chip);

	return 0;
}

2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274
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);
	}
}

2275
static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2276
{
2277
	int i, err;
2278

2279
	/* Set all ports to the Disabled state */
2280
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2281
		err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
2282 2283
		if (err)
			return err;
2284 2285
	}

2286 2287 2288
	/* Wait for transmit queues to drain,
	 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
	 */
2289 2290
	usleep_range(2000, 4000);

2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301
	return 0;
}

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

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

2302
	mv88e6xxx_hardware_reset(chip);
2303

2304
	return mv88e6xxx_software_reset(chip);
2305 2306
}

2307
static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
2308 2309
				   enum mv88e6xxx_frame_mode frame,
				   enum mv88e6xxx_egress_mode egress, u16 etype)
2310 2311 2312
{
	int err;

2313 2314 2315 2316
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
2317 2318 2319
	if (err)
		return err;

2320 2321 2322 2323 2324 2325 2326 2327
	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;
2328 2329
}

2330
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2331
{
2332
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
2333
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2334
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2335
}
2336

2337 2338 2339
static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
2340
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2341
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2342
}
2343

2344 2345 2346 2347
static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port,
				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
2348 2349
				       MV88E6XXX_EGRESS_MODE_ETHERTYPE,
				       ETH_P_EDSA);
2350
}
2351

2352 2353 2354 2355
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);
2356

2357
	if (dsa_is_user_port(chip->ds, port))
2358
		return mv88e6xxx_set_port_mode_normal(chip, port);
2359

2360 2361 2362
	/* 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);
2363

2364 2365
	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
		return mv88e6xxx_set_port_mode_edsa(chip, port);
2366

2367
	return -EINVAL;
2368 2369
}

2370
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2371
{
2372
	bool message = dsa_is_dsa_port(chip->ds, port);
2373

2374
	return mv88e6xxx_port_set_message_port(chip, port, message);
2375
}
2376

2377
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2378
{
2379
	struct dsa_switch *ds = chip->ds;
2380
	bool flood;
2381

2382 2383 2384 2385 2386
	/* 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);
2387

2388
	return 0;
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
static irqreturn_t mv88e6xxx_serdes_irq_thread_fn(int irq, void *dev_id)
{
	struct mv88e6xxx_port *mvp = dev_id;
	struct mv88e6xxx_chip *chip = mvp->chip;
	irqreturn_t ret = IRQ_NONE;
	int port = mvp->port;
	u8 lane;

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

	return ret;
}

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

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

2420 2421 2422
	snprintf(dev_id->serdes_irq_name, sizeof(dev_id->serdes_irq_name),
		 "mv88e6xxx-%s-serdes-%d", dev_name(chip->dev), port);

2423 2424 2425
	/* Requesting the IRQ will trigger IRQ callbacks, so release the lock */
	mv88e6xxx_reg_unlock(chip);
	err = request_threaded_irq(irq, NULL, mv88e6xxx_serdes_irq_thread_fn,
2426 2427
				   IRQF_ONESHOT, dev_id->serdes_irq_name,
				   dev_id);
2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459
	mv88e6xxx_reg_lock(chip);
	if (err)
		return err;

	dev_id->serdes_irq = irq;

	return mv88e6xxx_serdes_irq_enable(chip, port, lane);
}

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

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

	err = mv88e6xxx_serdes_irq_disable(chip, port, lane);

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

	dev_id->serdes_irq = 0;

	return err;
}

2460 2461 2462
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
2463
	u8 lane;
2464
	int err;
2465

2466 2467
	lane = mv88e6xxx_serdes_get_lane(chip, port);
	if (!lane)
2468 2469 2470
		return 0;

	if (on) {
2471
		err = mv88e6xxx_serdes_power_up(chip, port, lane);
2472 2473 2474
		if (err)
			return err;

2475
		err = mv88e6xxx_serdes_irq_request(chip, port, lane);
2476
	} else {
2477 2478 2479
		err = mv88e6xxx_serdes_irq_free(chip, port, lane);
		if (err)
			return err;
2480

2481
		err = mv88e6xxx_serdes_power_down(chip, port, lane);
2482 2483 2484
	}

	return err;
2485 2486
}

2487 2488 2489 2490 2491 2492
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

2493
	upstream_port = dsa_upstream_port(ds, port);
2494 2495 2496 2497 2498 2499 2500
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

2501 2502 2503 2504 2505 2506 2507 2508 2509 2510
	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,
2511 2512 2513 2514 2515 2516 2517 2518
						MV88E6XXX_EGRESS_DIR_INGRESS,
						upstream_port);
			if (err)
				return err;

			err = chip->info->ops->set_egress_port(chip,
						MV88E6XXX_EGRESS_DIR_EGRESS,
						upstream_port);
2519 2520 2521 2522 2523
			if (err)
				return err;
		}
	}

2524 2525 2526
	return 0;
}

2527
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
2528
{
2529
	struct dsa_switch *ds = chip->ds;
2530
	int err;
2531
	u16 reg;
2532

2533 2534 2535
	chip->ports[port].chip = chip;
	chip->ports[port].port = port;

2536 2537 2538 2539 2540 2541 2542
	/* 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,
2543
					       PAUSE_OFF,
2544 2545 2546 2547
					       PHY_INTERFACE_MODE_NA);
	else
		err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
					       SPEED_UNFORCED, DUPLEX_UNFORCED,
2548
					       PAUSE_ON,
2549 2550 2551
					       PHY_INTERFACE_MODE_NA);
	if (err)
		return err;
2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566

	/* 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.
	 */
2567 2568 2569 2570
	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);
2571 2572
	if (err)
		return err;
2573

2574
	err = mv88e6xxx_setup_port_mode(chip, port);
2575 2576
	if (err)
		return err;
2577

2578
	err = mv88e6xxx_setup_egress_floods(chip, port);
2579 2580 2581
	if (err)
		return err;

2582
	/* Port Control 2: don't force a good FCS, set the maximum frame size to
2583
	 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
2584 2585 2586
	 * 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.
2587
	 */
2588 2589 2590
	err = mv88e6xxx_port_set_map_da(chip, port);
	if (err)
		return err;
2591

2592 2593 2594
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
2595

2596
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
2597
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
2598 2599 2600
	if (err)
		return err;

2601 2602
	if (chip->info->ops->port_set_jumbo_size) {
		err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
2603 2604 2605 2606
		if (err)
			return err;
	}

2607 2608 2609 2610 2611
	/* 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.
	 */
2612
	reg = 1 << port;
2613 2614
	/* Disable learning for CPU port */
	if (dsa_is_cpu_port(ds, port))
2615
		reg = 0;
2616

2617 2618
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
2619 2620
	if (err)
		return err;
2621 2622

	/* Egress rate control 2: disable egress rate control. */
2623 2624
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
				   0x0000);
2625 2626
	if (err)
		return err;
2627

2628 2629
	if (chip->info->ops->port_pause_limit) {
		err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
2630 2631
		if (err)
			return err;
2632
	}
2633

2634 2635 2636 2637 2638 2639
	if (chip->info->ops->port_disable_learn_limit) {
		err = chip->info->ops->port_disable_learn_limit(chip, port);
		if (err)
			return err;
	}

2640 2641
	if (chip->info->ops->port_disable_pri_override) {
		err = chip->info->ops->port_disable_pri_override(chip, port);
2642 2643
		if (err)
			return err;
2644
	}
2645

2646 2647
	if (chip->info->ops->port_tag_remap) {
		err = chip->info->ops->port_tag_remap(chip, port);
2648 2649
		if (err)
			return err;
2650 2651
	}

2652 2653
	if (chip->info->ops->port_egress_rate_limiting) {
		err = chip->info->ops->port_egress_rate_limiting(chip, port);
2654 2655
		if (err)
			return err;
2656 2657
	}

2658 2659 2660 2661 2662
	if (chip->info->ops->port_setup_message_port) {
		err = chip->info->ops->port_setup_message_port(chip, port);
		if (err)
			return err;
	}
2663

2664
	/* Port based VLAN map: give each port the same default address
2665 2666
	 * database, and allow bidirectional communication between the
	 * CPU and DSA port(s), and the other ports.
2667
	 */
2668
	err = mv88e6xxx_port_set_fid(chip, port, 0);
2669 2670
	if (err)
		return err;
2671

2672
	err = mv88e6xxx_port_vlan_map(chip, port);
2673 2674
	if (err)
		return err;
2675 2676 2677 2678

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

2682 2683 2684 2685
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
2686
	int err;
2687

2688
	mv88e6xxx_reg_lock(chip);
2689
	err = mv88e6xxx_serdes_power(chip, port, true);
2690
	mv88e6xxx_reg_unlock(chip);
2691 2692 2693 2694

	return err;
}

2695
static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port)
2696 2697 2698
{
	struct mv88e6xxx_chip *chip = ds->priv;

2699
	mv88e6xxx_reg_lock(chip);
2700 2701
	if (mv88e6xxx_serdes_power(chip, port, false))
		dev_err(chip->dev, "failed to power off SERDES\n");
2702
	mv88e6xxx_reg_unlock(chip);
2703 2704
}

2705 2706 2707
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
2708
	struct mv88e6xxx_chip *chip = ds->priv;
2709 2710
	int err;

2711
	mv88e6xxx_reg_lock(chip);
2712
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2713
	mv88e6xxx_reg_unlock(chip);
2714 2715 2716 2717

	return err;
}

2718
static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
2719
{
2720
	int err;
2721

2722
	/* Initialize the statistics unit */
2723 2724 2725 2726 2727
	if (chip->info->ops->stats_set_histogram) {
		err = chip->info->ops->stats_set_histogram(chip);
		if (err)
			return err;
	}
2728

2729
	return mv88e6xxx_g1_stats_clear(chip);
2730 2731
}

2732 2733 2734 2735 2736 2737 2738 2739
/* 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++) {
2740
		err = mv88e6xxx_port_hidden_read(chip, 0xf, port, 0, &val);
2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772
		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++) {
2773
		err = mv88e6xxx_port_hidden_write(chip, 0xf, port, 0, 0x01c0);
2774 2775 2776 2777 2778 2779 2780
		if (err)
			return err;
	}

	return mv88e6xxx_software_reset(chip);
}

2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847
enum mv88e6xxx_devlink_param_id {
	MV88E6XXX_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,
	MV88E6XXX_DEVLINK_PARAM_ID_ATU_HASH,
};

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

	mv88e6xxx_reg_lock(chip);

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

	mv88e6xxx_reg_unlock(chip);

	return err;
}

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

	mv88e6xxx_reg_lock(chip);

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

	mv88e6xxx_reg_unlock(chip);

	return err;
}

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

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

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

2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882
enum mv88e6xxx_devlink_resource_id {
	MV88E6XXX_RESOURCE_ID_ATU,
	MV88E6XXX_RESOURCE_ID_ATU_BIN_0,
	MV88E6XXX_RESOURCE_ID_ATU_BIN_1,
	MV88E6XXX_RESOURCE_ID_ATU_BIN_2,
	MV88E6XXX_RESOURCE_ID_ATU_BIN_3,
};

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

	mv88e6xxx_reg_lock(chip);

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

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

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

2883 2884
	occupancy &= MV88E6XXX_G2_ATU_STATS_MASK;

2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018
unlock:
	mv88e6xxx_reg_unlock(chip);

	return occupancy;
}

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

	return mv88e6xxx_devlink_atu_bin_get(chip,
					     MV88E6XXX_G2_ATU_STATS_BIN_0);
}

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

	return mv88e6xxx_devlink_atu_bin_get(chip,
					     MV88E6XXX_G2_ATU_STATS_BIN_1);
}

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

	return mv88e6xxx_devlink_atu_bin_get(chip,
					     MV88E6XXX_G2_ATU_STATS_BIN_2);
}

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

	return mv88e6xxx_devlink_atu_bin_get(chip,
					     MV88E6XXX_G2_ATU_STATS_BIN_3);
}

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

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

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

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

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

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

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

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

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

	dsa_devlink_resource_occ_get_register(ds,
					      MV88E6XXX_RESOURCE_ID_ATU,
					      mv88e6xxx_devlink_atu_get,
					      chip);

	dsa_devlink_resource_occ_get_register(ds,
					      MV88E6XXX_RESOURCE_ID_ATU_BIN_0,
					      mv88e6xxx_devlink_atu_bin_0_get,
					      chip);

	dsa_devlink_resource_occ_get_register(ds,
					      MV88E6XXX_RESOURCE_ID_ATU_BIN_1,
					      mv88e6xxx_devlink_atu_bin_1_get,
					      chip);

	dsa_devlink_resource_occ_get_register(ds,
					      MV88E6XXX_RESOURCE_ID_ATU_BIN_2,
					      mv88e6xxx_devlink_atu_bin_2_get,
					      chip);

	dsa_devlink_resource_occ_get_register(ds,
					      MV88E6XXX_RESOURCE_ID_ATU_BIN_3,
					      mv88e6xxx_devlink_atu_bin_3_get,
					      chip);

	return 0;

out:
	dsa_devlink_resources_unregister(ds);
	return err;
}

3019 3020 3021
static void mv88e6xxx_teardown(struct dsa_switch *ds)
{
	mv88e6xxx_teardown_devlink_params(ds);
3022
	dsa_devlink_resources_unregister(ds);
3023 3024
}

3025
static int mv88e6xxx_setup(struct dsa_switch *ds)
3026
{
V
Vivien Didelot 已提交
3027
	struct mv88e6xxx_chip *chip = ds->priv;
3028
	u8 cmode;
3029
	int err;
3030 3031
	int i;

3032
	chip->ds = ds;
3033
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
3034

3035
	mv88e6xxx_reg_lock(chip);
3036

3037 3038 3039 3040 3041 3042
	if (chip->info->ops->setup_errata) {
		err = chip->info->ops->setup_errata(chip);
		if (err)
			goto unlock;
	}

3043 3044 3045 3046 3047
	/* 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)
3048
				goto unlock;
3049 3050 3051 3052 3053

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

3054
	/* Setup Switch Port Registers */
3055
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
3056 3057 3058
		if (dsa_is_unused_port(ds, i))
			continue;

3059
		/* Prevent the use of an invalid port. */
3060
		if (mv88e6xxx_is_invalid_port(chip, i)) {
3061 3062 3063 3064 3065
			dev_err(chip->dev, "port %d is invalid\n", i);
			err = -EINVAL;
			goto unlock;
		}

3066 3067 3068 3069 3070
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

3071 3072 3073 3074
	err = mv88e6xxx_irl_setup(chip);
	if (err)
		goto unlock;

3075 3076 3077 3078
	err = mv88e6xxx_mac_setup(chip);
	if (err)
		goto unlock;

3079 3080 3081 3082
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

3083 3084 3085 3086
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

3087 3088 3089 3090
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

3091 3092 3093 3094
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

3095 3096 3097 3098
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

3099 3100 3101 3102
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

3103 3104 3105 3106
	err = mv88e6xxx_rmu_setup(chip);
	if (err)
		goto unlock;

3107 3108 3109
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
3110

3111 3112 3113 3114
	err = mv88e6xxx_trunk_setup(chip);
	if (err)
		goto unlock;

3115 3116 3117 3118
	err = mv88e6xxx_devmap_setup(chip);
	if (err)
		goto unlock;

3119 3120 3121 3122
	err = mv88e6xxx_pri_setup(chip);
	if (err)
		goto unlock;

3123
	/* Setup PTP Hardware Clock and timestamping */
3124 3125 3126 3127
	if (chip->info->ptp_support) {
		err = mv88e6xxx_ptp_setup(chip);
		if (err)
			goto unlock;
3128 3129 3130 3131

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
3132 3133
	}

3134 3135 3136 3137
	err = mv88e6xxx_stats_setup(chip);
	if (err)
		goto unlock;

3138
unlock:
3139
	mv88e6xxx_reg_unlock(chip);
3140

3141 3142 3143 3144 3145 3146 3147
	if (err)
		return err;

	/* Have to be called without holding the register lock, since
	 * they take the devlink lock, and we later take the locks in
	 * the reverse order when getting/setting parameters or
	 * resource occupancy.
3148
	 */
3149 3150 3151 3152 3153 3154 3155 3156 3157
	err = mv88e6xxx_setup_devlink_resources(ds);
	if (err)
		return err;

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

	return err;
3158 3159
}

3160
static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
3161
{
3162 3163
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
3164 3165
	u16 val;
	int err;
3166

3167 3168 3169
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

3170
	mv88e6xxx_reg_lock(chip);
3171
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
3172
	mv88e6xxx_reg_unlock(chip);
3173

3174
	if (reg == MII_PHYSID2) {
3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190
		/* 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;
3191 3192
	}

3193
	return err ? err : val;
3194 3195
}

3196
static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
3197
{
3198 3199
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
3200
	int err;
3201

3202 3203 3204
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

3205
	mv88e6xxx_reg_lock(chip);
3206
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
3207
	mv88e6xxx_reg_unlock(chip);
3208 3209

	return err;
3210 3211
}

3212
static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
3213 3214
				   struct device_node *np,
				   bool external)
3215 3216
{
	static int index;
3217
	struct mv88e6xxx_mdio_bus *mdio_bus;
3218 3219 3220
	struct mii_bus *bus;
	int err;

3221
	if (external) {
3222
		mv88e6xxx_reg_lock(chip);
3223
		err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
3224
		mv88e6xxx_reg_unlock(chip);
3225 3226 3227 3228 3229

		if (err)
			return err;
	}

3230
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
3231 3232 3233
	if (!bus)
		return -ENOMEM;

3234
	mdio_bus = bus->priv;
3235
	mdio_bus->bus = bus;
3236
	mdio_bus->chip = chip;
3237 3238
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
3239

3240 3241
	if (np) {
		bus->name = np->full_name;
3242
		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
3243 3244 3245 3246 3247 3248 3249
	} 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;
3250
	bus->parent = chip->dev;
3251

3252 3253 3254 3255 3256 3257
	if (!external) {
		err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
		if (err)
			return err;
	}

3258
	err = of_mdiobus_register(bus, np);
3259
	if (err) {
3260
		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
3261
		mv88e6xxx_g2_irq_mdio_free(chip, bus);
3262
		return err;
3263
	}
3264 3265 3266 3267 3268

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

	return 0;
3271
}
3272

3273 3274 3275 3276 3277
static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
	{ .compatible = "marvell,mv88e6xxx-mdio-external",
	  .data = (void *)true },
	{ },
};
3278

3279 3280 3281 3282 3283 3284 3285 3286 3287
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;

3288 3289 3290
		if (!mdio_bus->external)
			mv88e6xxx_g2_irq_mdio_free(chip, bus);

3291 3292 3293 3294
		mdiobus_unregister(bus);
	}
}

3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318
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);
3319 3320
			if (err) {
				mv88e6xxx_mdios_unregister(chip);
3321
				of_node_put(child);
3322
				return err;
3323
			}
3324 3325 3326 3327
		}
	}

	return 0;
3328 3329
}

3330 3331
static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
3332
	struct mv88e6xxx_chip *chip = ds->priv;
3333 3334 3335 3336 3337 3338 3339

	return chip->eeprom_len;
}

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

3343 3344
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
3345

3346
	mv88e6xxx_reg_lock(chip);
3347
	err = chip->info->ops->get_eeprom(chip, eeprom, data);
3348
	mv88e6xxx_reg_unlock(chip);
3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360

	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 已提交
3361
	struct mv88e6xxx_chip *chip = ds->priv;
3362 3363
	int err;

3364 3365 3366
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

3367 3368 3369
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

3370
	mv88e6xxx_reg_lock(chip);
3371
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
3372
	mv88e6xxx_reg_unlock(chip);
3373 3374 3375 3376

	return err;
}

3377
static const struct mv88e6xxx_ops mv88e6085_ops = {
3378
	/* MV88E6XXX_FAMILY_6097 */
3379 3380
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3381
	.irl_init_all = mv88e6352_g2_irl_init_all,
3382
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3383 3384
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3385
	.port_set_link = mv88e6xxx_port_set_link,
3386
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3387
	.port_tag_remap = mv88e6095_port_tag_remap,
3388
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3389
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3390
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3391
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3392
	.port_pause_limit = mv88e6097_port_pause_limit,
3393
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3394
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3395
	.port_get_cmode = mv88e6185_port_get_cmode,
3396
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3397
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3398
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3399 3400
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3401
	.stats_get_stats = mv88e6095_stats_get_stats,
3402 3403
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3404
	.watchdog_ops = &mv88e6097_watchdog_ops,
3405
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3406
	.pot_clear = mv88e6xxx_g2_pot_clear,
3407 3408
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
3409
	.reset = mv88e6185_g1_reset,
3410
	.rmu_disable = mv88e6085_g1_rmu_disable,
3411
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3412
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3413
	.phylink_validate = mv88e6185_phylink_validate,
3414 3415 3416
};

static const struct mv88e6xxx_ops mv88e6095_ops = {
3417
	/* MV88E6XXX_FAMILY_6095 */
3418 3419
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3420
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3421 3422
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3423
	.port_set_link = mv88e6xxx_port_set_link,
3424
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3425
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
3426
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
3427
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
3428
	.port_get_cmode = mv88e6185_port_get_cmode,
3429
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3430
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3431
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3432 3433
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3434
	.stats_get_stats = mv88e6095_stats_get_stats,
3435
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3436 3437
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
3438
	.reset = mv88e6185_g1_reset,
3439
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3440
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3441
	.phylink_validate = mv88e6185_phylink_validate,
3442 3443
};

3444
static const struct mv88e6xxx_ops mv88e6097_ops = {
3445
	/* MV88E6XXX_FAMILY_6097 */
3446 3447
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3448
	.irl_init_all = mv88e6352_g2_irl_init_all,
3449 3450 3451 3452
	.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,
3453
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3454
	.port_tag_remap = mv88e6095_port_tag_remap,
3455
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3456
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3457
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3458
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3459
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
3460
	.port_pause_limit = mv88e6097_port_pause_limit,
3461
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3462
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3463
	.port_get_cmode = mv88e6185_port_get_cmode,
3464
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3465
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3466
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3467 3468 3469
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
	.stats_get_stats = mv88e6095_stats_get_stats,
3470 3471
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3472
	.watchdog_ops = &mv88e6097_watchdog_ops,
3473
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3474
	.pot_clear = mv88e6xxx_g2_pot_clear,
3475
	.reset = mv88e6352_g1_reset,
3476
	.rmu_disable = mv88e6085_g1_rmu_disable,
3477
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3478
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3479
	.phylink_validate = mv88e6185_phylink_validate,
3480 3481
};

3482
static const struct mv88e6xxx_ops mv88e6123_ops = {
3483
	/* MV88E6XXX_FAMILY_6165 */
3484 3485
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3486
	.irl_init_all = mv88e6352_g2_irl_init_all,
3487
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3488 3489
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3490
	.port_set_link = mv88e6xxx_port_set_link,
3491
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3492
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
3493
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3494
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3495
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3496
	.port_get_cmode = mv88e6185_port_get_cmode,
3497
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3498
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3499
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3500 3501
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3502
	.stats_get_stats = mv88e6095_stats_get_stats,
3503 3504
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3505
	.watchdog_ops = &mv88e6097_watchdog_ops,
3506
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3507
	.pot_clear = mv88e6xxx_g2_pot_clear,
3508
	.reset = mv88e6352_g1_reset,
3509 3510
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3511
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3512
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3513
	.phylink_validate = mv88e6185_phylink_validate,
3514 3515 3516
};

static const struct mv88e6xxx_ops mv88e6131_ops = {
3517
	/* MV88E6XXX_FAMILY_6185 */
3518 3519
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3520
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3521 3522
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3523
	.port_set_link = mv88e6xxx_port_set_link,
3524
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3525
	.port_tag_remap = mv88e6095_port_tag_remap,
3526
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3527
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
3528
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3529
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
3530
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3531
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3532
	.port_pause_limit = mv88e6097_port_pause_limit,
3533
	.port_set_pause = mv88e6185_port_set_pause,
3534
	.port_get_cmode = mv88e6185_port_get_cmode,
3535
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3536
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3537
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3538 3539
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3540
	.stats_get_stats = mv88e6095_stats_get_stats,
3541 3542
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3543
	.watchdog_ops = &mv88e6097_watchdog_ops,
3544
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3545
	.ppu_enable = mv88e6185_g1_ppu_enable,
3546
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
3547
	.ppu_disable = mv88e6185_g1_ppu_disable,
3548
	.reset = mv88e6185_g1_reset,
3549
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3550
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3551
	.phylink_validate = mv88e6185_phylink_validate,
3552 3553
};

3554 3555
static const struct mv88e6xxx_ops mv88e6141_ops = {
	/* MV88E6XXX_FAMILY_6341 */
3556 3557
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3558
	.irl_init_all = mv88e6352_g2_irl_init_all,
3559 3560 3561 3562 3563 3564 3565
	.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_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3566
	.port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
3567
	.port_max_speed_mode = mv88e6341_port_max_speed_mode,
3568 3569 3570 3571
	.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,
3572
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3573
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3574
	.port_pause_limit = mv88e6097_port_pause_limit,
3575 3576
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3577
	.port_get_cmode = mv88e6352_port_get_cmode,
3578
	.port_set_cmode = mv88e6341_port_set_cmode,
3579
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3580
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3581
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3582 3583 3584
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
3585 3586
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3587 3588
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
3589
	.pot_clear = mv88e6xxx_g2_pot_clear,
3590
	.reset = mv88e6352_g1_reset,
3591
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3592
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3593 3594
	.serdes_power = mv88e6390_serdes_power,
	.serdes_get_lane = mv88e6341_serdes_get_lane,
3595 3596 3597 3598 3599
	/* Check status register pause & lpa register */
	.serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
	.serdes_pcs_config = mv88e6390_serdes_pcs_config,
	.serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
	.serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
3600
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3601
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
3602
	.serdes_irq_status = mv88e6390_serdes_irq_status,
3603
	.gpio_ops = &mv88e6352_gpio_ops,
3604
	.phylink_validate = mv88e6341_phylink_validate,
3605 3606
};

3607
static const struct mv88e6xxx_ops mv88e6161_ops = {
3608
	/* MV88E6XXX_FAMILY_6165 */
3609 3610
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3611
	.irl_init_all = mv88e6352_g2_irl_init_all,
3612
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3613 3614
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3615
	.port_set_link = mv88e6xxx_port_set_link,
3616
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3617
	.port_tag_remap = mv88e6095_port_tag_remap,
3618
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3619
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3620
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3621
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3622
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3623
	.port_pause_limit = mv88e6097_port_pause_limit,
3624
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3625
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3626
	.port_get_cmode = mv88e6185_port_get_cmode,
3627
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3628
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3629
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3630 3631
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3632
	.stats_get_stats = mv88e6095_stats_get_stats,
3633 3634
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3635
	.watchdog_ops = &mv88e6097_watchdog_ops,
3636
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3637
	.pot_clear = mv88e6xxx_g2_pot_clear,
3638
	.reset = mv88e6352_g1_reset,
3639 3640
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3641
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3642
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3643
	.avb_ops = &mv88e6165_avb_ops,
3644
	.ptp_ops = &mv88e6165_ptp_ops,
3645
	.phylink_validate = mv88e6185_phylink_validate,
3646 3647 3648
};

static const struct mv88e6xxx_ops mv88e6165_ops = {
3649
	/* MV88E6XXX_FAMILY_6165 */
3650 3651
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3652
	.irl_init_all = mv88e6352_g2_irl_init_all,
3653
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3654 3655
	.phy_read = mv88e6165_phy_read,
	.phy_write = mv88e6165_phy_write,
3656
	.port_set_link = mv88e6xxx_port_set_link,
3657
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3658
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3659
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3660
	.port_get_cmode = mv88e6185_port_get_cmode,
3661
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3662
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3663
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3664 3665
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3666
	.stats_get_stats = mv88e6095_stats_get_stats,
3667 3668
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3669
	.watchdog_ops = &mv88e6097_watchdog_ops,
3670
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3671
	.pot_clear = mv88e6xxx_g2_pot_clear,
3672
	.reset = mv88e6352_g1_reset,
3673 3674
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3675
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3676
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3677
	.avb_ops = &mv88e6165_avb_ops,
3678
	.ptp_ops = &mv88e6165_ptp_ops,
3679
	.phylink_validate = mv88e6185_phylink_validate,
3680 3681 3682
};

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

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

static const struct mv88e6xxx_ops mv88e6175_ops = {
3776
	/* MV88E6XXX_FAMILY_6351 */
3777 3778
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3779
	.irl_init_all = mv88e6352_g2_irl_init_all,
3780
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3781 3782
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3783
	.port_set_link = mv88e6xxx_port_set_link,
3784
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3785
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3786
	.port_tag_remap = mv88e6095_port_tag_remap,
3787
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3788
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3789
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3790
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3791
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3792
	.port_pause_limit = mv88e6097_port_pause_limit,
3793
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3794
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3795
	.port_get_cmode = mv88e6352_port_get_cmode,
3796
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3797
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3798
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3799 3800
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3801
	.stats_get_stats = mv88e6095_stats_get_stats,
3802 3803
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3804
	.watchdog_ops = &mv88e6097_watchdog_ops,
3805
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3806
	.pot_clear = mv88e6xxx_g2_pot_clear,
3807
	.reset = mv88e6352_g1_reset,
3808 3809
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3810
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3811
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3812
	.phylink_validate = mv88e6185_phylink_validate,
3813 3814 3815
};

static const struct mv88e6xxx_ops mv88e6176_ops = {
3816
	/* MV88E6XXX_FAMILY_6352 */
3817 3818
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3819
	.irl_init_all = mv88e6352_g2_irl_init_all,
3820 3821
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3822
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3823 3824
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3825
	.port_set_link = mv88e6xxx_port_set_link,
3826
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3827
	.port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
3828
	.port_tag_remap = mv88e6095_port_tag_remap,
3829
	.port_set_policy = mv88e6352_port_set_policy,
3830
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3831
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3832
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3833
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3834
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3835
	.port_pause_limit = mv88e6097_port_pause_limit,
3836
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3837
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3838
	.port_get_cmode = mv88e6352_port_get_cmode,
3839
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3840
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3841
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3842 3843
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3844
	.stats_get_stats = mv88e6095_stats_get_stats,
3845 3846
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3847
	.watchdog_ops = &mv88e6097_watchdog_ops,
3848
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3849
	.pot_clear = mv88e6xxx_g2_pot_clear,
3850
	.reset = mv88e6352_g1_reset,
3851
	.rmu_disable = mv88e6352_g1_rmu_disable,
3852 3853
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3854
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3855
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3856
	.serdes_get_lane = mv88e6352_serdes_get_lane,
3857 3858 3859 3860
	.serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
	.serdes_pcs_config = mv88e6352_serdes_pcs_config,
	.serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
	.serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
3861
	.serdes_power = mv88e6352_serdes_power,
3862
	.serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
3863
	.serdes_irq_enable = mv88e6352_serdes_irq_enable,
3864
	.serdes_irq_status = mv88e6352_serdes_irq_status,
3865 3866
	.serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
	.serdes_get_regs = mv88e6352_serdes_get_regs,
3867
	.gpio_ops = &mv88e6352_gpio_ops,
3868
	.phylink_validate = mv88e6352_phylink_validate,
3869 3870 3871
};

static const struct mv88e6xxx_ops mv88e6185_ops = {
3872
	/* MV88E6XXX_FAMILY_6185 */
3873 3874
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3875
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3876 3877
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3878
	.port_set_link = mv88e6xxx_port_set_link,
3879
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3880
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
3881
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
3882
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
3883
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
3884
	.port_set_pause = mv88e6185_port_set_pause,
3885
	.port_get_cmode = mv88e6185_port_get_cmode,
3886
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3887
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3888
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3889 3890
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3891
	.stats_get_stats = mv88e6095_stats_get_stats,
3892 3893
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3894
	.watchdog_ops = &mv88e6097_watchdog_ops,
3895
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3896
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
3897 3898
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
3899
	.reset = mv88e6185_g1_reset,
3900
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3901
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3902
	.phylink_validate = mv88e6185_phylink_validate,
3903 3904
};

3905
static const struct mv88e6xxx_ops mv88e6190_ops = {
3906
	/* MV88E6XXX_FAMILY_6390 */
3907
	.setup_errata = mv88e6390_setup_errata,
3908
	.irl_init_all = mv88e6390_g2_irl_init_all,
3909 3910
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3911 3912 3913 3914 3915
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3916
	.port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
3917
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
3918
	.port_tag_remap = mv88e6390_port_tag_remap,
3919
	.port_set_policy = mv88e6352_port_set_policy,
3920
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3921
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3922
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3923
	.port_pause_limit = mv88e6390_port_pause_limit,
3924
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3925
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3926
	.port_get_cmode = mv88e6352_port_get_cmode,
3927
	.port_set_cmode = mv88e6390_port_set_cmode,
3928
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3929
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3930
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3931 3932
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3933
	.stats_get_stats = mv88e6390_stats_get_stats,
3934 3935
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3936
	.watchdog_ops = &mv88e6390_watchdog_ops,
3937
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3938
	.pot_clear = mv88e6xxx_g2_pot_clear,
3939
	.reset = mv88e6352_g1_reset,
3940
	.rmu_disable = mv88e6390_g1_rmu_disable,
3941 3942
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3943 3944
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3945
	.serdes_power = mv88e6390_serdes_power,
3946
	.serdes_get_lane = mv88e6390_serdes_get_lane,
3947 3948 3949 3950 3951
	/* Check status register pause & lpa register */
	.serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
	.serdes_pcs_config = mv88e6390_serdes_pcs_config,
	.serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
	.serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
3952
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3953
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
3954
	.serdes_irq_status = mv88e6390_serdes_irq_status,
3955 3956
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
3957 3958
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
3959
	.phylink_validate = mv88e6390_phylink_validate,
3960
	.gpio_ops = &mv88e6352_gpio_ops,
3961
	.phylink_validate = mv88e6390_phylink_validate,
3962 3963 3964
};

static const struct mv88e6xxx_ops mv88e6190x_ops = {
3965
	/* MV88E6XXX_FAMILY_6390 */
3966
	.setup_errata = mv88e6390_setup_errata,
3967
	.irl_init_all = mv88e6390_g2_irl_init_all,
3968 3969
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3970 3971 3972 3973 3974
	.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_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3975
	.port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
3976
	.port_max_speed_mode = mv88e6390x_port_max_speed_mode,
3977
	.port_tag_remap = mv88e6390_port_tag_remap,
3978
	.port_set_policy = mv88e6352_port_set_policy,
3979
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3980
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3981
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3982
	.port_pause_limit = mv88e6390_port_pause_limit,
3983
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3984
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3985
	.port_get_cmode = mv88e6352_port_get_cmode,
3986
	.port_set_cmode = mv88e6390x_port_set_cmode,
3987
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3988
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3989
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3990 3991
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3992
	.stats_get_stats = mv88e6390_stats_get_stats,
3993 3994
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3995
	.watchdog_ops = &mv88e6390_watchdog_ops,
3996
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3997
	.pot_clear = mv88e6xxx_g2_pot_clear,
3998
	.reset = mv88e6352_g1_reset,
3999
	.rmu_disable = mv88e6390_g1_rmu_disable,
4000 4001
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4002 4003
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4004
	.serdes_power = mv88e6390_serdes_power,
4005
	.serdes_get_lane = mv88e6390x_serdes_get_lane,
4006 4007 4008 4009 4010
	/* Check status register pause & lpa register */
	.serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
	.serdes_pcs_config = mv88e6390_serdes_pcs_config,
	.serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
	.serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
4011
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4012
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4013
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4014 4015
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
4016 4017
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
4018
	.phylink_validate = mv88e6390_phylink_validate,
4019
	.gpio_ops = &mv88e6352_gpio_ops,
4020
	.phylink_validate = mv88e6390x_phylink_validate,
4021 4022 4023
};

static const struct mv88e6xxx_ops mv88e6191_ops = {
4024
	/* MV88E6XXX_FAMILY_6390 */
4025
	.setup_errata = mv88e6390_setup_errata,
4026
	.irl_init_all = mv88e6390_g2_irl_init_all,
4027 4028
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4029 4030 4031 4032 4033
	.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_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4034
	.port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
4035
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
4036
	.port_tag_remap = mv88e6390_port_tag_remap,
4037
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4038
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4039
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4040
	.port_pause_limit = mv88e6390_port_pause_limit,
4041
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4042
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4043
	.port_get_cmode = mv88e6352_port_get_cmode,
4044
	.port_set_cmode = mv88e6390_port_set_cmode,
4045
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4046
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4047
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4048 4049
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4050
	.stats_get_stats = mv88e6390_stats_get_stats,
4051 4052
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4053
	.watchdog_ops = &mv88e6390_watchdog_ops,
4054
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4055
	.pot_clear = mv88e6xxx_g2_pot_clear,
4056
	.reset = mv88e6352_g1_reset,
4057
	.rmu_disable = mv88e6390_g1_rmu_disable,
4058 4059
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4060 4061
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4062
	.serdes_power = mv88e6390_serdes_power,
4063
	.serdes_get_lane = mv88e6390_serdes_get_lane,
4064 4065 4066 4067 4068
	/* Check status register pause & lpa register */
	.serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
	.serdes_pcs_config = mv88e6390_serdes_pcs_config,
	.serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
	.serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
4069
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4070
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4071
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4072 4073
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
4074 4075
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
4076
	.phylink_validate = mv88e6390_phylink_validate,
4077 4078
	.avb_ops = &mv88e6390_avb_ops,
	.ptp_ops = &mv88e6352_ptp_ops,
4079
	.phylink_validate = mv88e6390_phylink_validate,
4080 4081
};

4082
static const struct mv88e6xxx_ops mv88e6240_ops = {
4083
	/* MV88E6XXX_FAMILY_6352 */
4084 4085
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4086
	.irl_init_all = mv88e6352_g2_irl_init_all,
4087 4088
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
4089
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4090 4091
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4092
	.port_set_link = mv88e6xxx_port_set_link,
4093
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4094
	.port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
4095
	.port_tag_remap = mv88e6095_port_tag_remap,
4096
	.port_set_policy = mv88e6352_port_set_policy,
4097
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4098
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4099
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4100
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4101
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4102
	.port_pause_limit = mv88e6097_port_pause_limit,
4103
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4104
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4105
	.port_get_cmode = mv88e6352_port_get_cmode,
4106
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4107
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4108
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4109 4110
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
4111
	.stats_get_stats = mv88e6095_stats_get_stats,
4112 4113
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4114
	.watchdog_ops = &mv88e6097_watchdog_ops,
4115
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4116
	.pot_clear = mv88e6xxx_g2_pot_clear,
4117
	.reset = mv88e6352_g1_reset,
4118
	.rmu_disable = mv88e6352_g1_rmu_disable,
4119 4120
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4121
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4122
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4123
	.serdes_get_lane = mv88e6352_serdes_get_lane,
4124 4125 4126 4127
	.serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
	.serdes_pcs_config = mv88e6352_serdes_pcs_config,
	.serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
	.serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
4128
	.serdes_power = mv88e6352_serdes_power,
4129
	.serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
4130
	.serdes_irq_enable = mv88e6352_serdes_irq_enable,
4131
	.serdes_irq_status = mv88e6352_serdes_irq_status,
4132 4133
	.serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
	.serdes_get_regs = mv88e6352_serdes_get_regs,
4134
	.gpio_ops = &mv88e6352_gpio_ops,
4135
	.avb_ops = &mv88e6352_avb_ops,
4136
	.ptp_ops = &mv88e6352_ptp_ops,
4137
	.phylink_validate = mv88e6352_phylink_validate,
4138 4139
};

4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151
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_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4152
	.port_set_speed_duplex = mv88e6250_port_set_speed_duplex,
4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172
	.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,
	.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,
4173 4174
	.avb_ops = &mv88e6352_avb_ops,
	.ptp_ops = &mv88e6250_ptp_ops,
4175 4176 4177
	.phylink_validate = mv88e6065_phylink_validate,
};

4178
static const struct mv88e6xxx_ops mv88e6290_ops = {
4179
	/* MV88E6XXX_FAMILY_6390 */
4180
	.setup_errata = mv88e6390_setup_errata,
4181
	.irl_init_all = mv88e6390_g2_irl_init_all,
4182 4183
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4184 4185 4186 4187 4188
	.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_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4189
	.port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
4190
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
4191
	.port_tag_remap = mv88e6390_port_tag_remap,
4192
	.port_set_policy = mv88e6352_port_set_policy,
4193
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4194
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4195
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4196
	.port_pause_limit = mv88e6390_port_pause_limit,
4197
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4198
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4199
	.port_get_cmode = mv88e6352_port_get_cmode,
4200
	.port_set_cmode = mv88e6390_port_set_cmode,
4201
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4202
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4203
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4204 4205
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4206
	.stats_get_stats = mv88e6390_stats_get_stats,
4207 4208
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4209
	.watchdog_ops = &mv88e6390_watchdog_ops,
4210
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4211
	.pot_clear = mv88e6xxx_g2_pot_clear,
4212
	.reset = mv88e6352_g1_reset,
4213
	.rmu_disable = mv88e6390_g1_rmu_disable,
4214 4215
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4216 4217
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4218
	.serdes_power = mv88e6390_serdes_power,
4219
	.serdes_get_lane = mv88e6390_serdes_get_lane,
4220 4221 4222 4223 4224
	/* Check status register pause & lpa register */
	.serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
	.serdes_pcs_config = mv88e6390_serdes_pcs_config,
	.serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
	.serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
4225
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4226
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4227
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4228 4229
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
4230 4231
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
4232
	.phylink_validate = mv88e6390_phylink_validate,
4233
	.gpio_ops = &mv88e6352_gpio_ops,
4234
	.avb_ops = &mv88e6390_avb_ops,
4235
	.ptp_ops = &mv88e6352_ptp_ops,
4236
	.phylink_validate = mv88e6390_phylink_validate,
4237 4238
};

4239
static const struct mv88e6xxx_ops mv88e6320_ops = {
4240
	/* MV88E6XXX_FAMILY_6320 */
4241 4242
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4243
	.irl_init_all = mv88e6352_g2_irl_init_all,
4244 4245
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
4246
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4247 4248
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4249
	.port_set_link = mv88e6xxx_port_set_link,
4250
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4251
	.port_tag_remap = mv88e6095_port_tag_remap,
4252
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4253
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4254
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4255
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4256
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4257
	.port_pause_limit = mv88e6097_port_pause_limit,
4258
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4259
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4260
	.port_get_cmode = mv88e6352_port_get_cmode,
4261
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4262
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4263
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4264 4265
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4266
	.stats_get_stats = mv88e6320_stats_get_stats,
4267 4268
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4269
	.watchdog_ops = &mv88e6390_watchdog_ops,
4270
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4271
	.pot_clear = mv88e6xxx_g2_pot_clear,
4272
	.reset = mv88e6352_g1_reset,
4273
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
4274
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
4275
	.gpio_ops = &mv88e6352_gpio_ops,
4276
	.avb_ops = &mv88e6352_avb_ops,
4277
	.ptp_ops = &mv88e6352_ptp_ops,
4278
	.phylink_validate = mv88e6185_phylink_validate,
4279 4280 4281
};

static const struct mv88e6xxx_ops mv88e6321_ops = {
4282
	/* MV88E6XXX_FAMILY_6320 */
4283 4284
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4285
	.irl_init_all = mv88e6352_g2_irl_init_all,
4286 4287
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
4288
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4289 4290
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4291
	.port_set_link = mv88e6xxx_port_set_link,
4292
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4293
	.port_tag_remap = mv88e6095_port_tag_remap,
4294
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4295
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4296
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4297
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4298
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4299
	.port_pause_limit = mv88e6097_port_pause_limit,
4300
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4301
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4302
	.port_get_cmode = mv88e6352_port_get_cmode,
4303
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4304
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4305
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4306 4307
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4308
	.stats_get_stats = mv88e6320_stats_get_stats,
4309 4310
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4311
	.watchdog_ops = &mv88e6390_watchdog_ops,
4312
	.reset = mv88e6352_g1_reset,
4313
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
4314
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
4315
	.gpio_ops = &mv88e6352_gpio_ops,
4316
	.avb_ops = &mv88e6352_avb_ops,
4317
	.ptp_ops = &mv88e6352_ptp_ops,
4318
	.phylink_validate = mv88e6185_phylink_validate,
4319 4320
};

4321 4322
static const struct mv88e6xxx_ops mv88e6341_ops = {
	/* MV88E6XXX_FAMILY_6341 */
4323 4324
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4325
	.irl_init_all = mv88e6352_g2_irl_init_all,
4326 4327 4328 4329 4330 4331 4332
	.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_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4333
	.port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
4334
	.port_max_speed_mode = mv88e6341_port_max_speed_mode,
4335 4336 4337 4338
	.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,
4339
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4340
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4341
	.port_pause_limit = mv88e6097_port_pause_limit,
4342 4343
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4344
	.port_get_cmode = mv88e6352_port_get_cmode,
4345
	.port_set_cmode = mv88e6341_port_set_cmode,
4346
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4347
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4348
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4349 4350 4351
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
4352 4353
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4354 4355
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
4356
	.pot_clear = mv88e6xxx_g2_pot_clear,
4357
	.reset = mv88e6352_g1_reset,
4358
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4359
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4360 4361
	.serdes_power = mv88e6390_serdes_power,
	.serdes_get_lane = mv88e6341_serdes_get_lane,
4362 4363 4364 4365 4366
	/* Check status register pause & lpa register */
	.serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
	.serdes_pcs_config = mv88e6390_serdes_pcs_config,
	.serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
	.serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
4367
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4368
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4369
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4370
	.gpio_ops = &mv88e6352_gpio_ops,
4371
	.avb_ops = &mv88e6390_avb_ops,
4372
	.ptp_ops = &mv88e6352_ptp_ops,
4373
	.phylink_validate = mv88e6341_phylink_validate,
4374 4375
};

4376
static const struct mv88e6xxx_ops mv88e6350_ops = {
4377
	/* MV88E6XXX_FAMILY_6351 */
4378 4379
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4380
	.irl_init_all = mv88e6352_g2_irl_init_all,
4381
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4382 4383
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4384
	.port_set_link = mv88e6xxx_port_set_link,
4385
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4386
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4387
	.port_tag_remap = mv88e6095_port_tag_remap,
4388
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4389
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4390
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4391
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4392
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4393
	.port_pause_limit = mv88e6097_port_pause_limit,
4394
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4395
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4396
	.port_get_cmode = mv88e6352_port_get_cmode,
4397
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4398
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4399
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4400 4401
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
4402
	.stats_get_stats = mv88e6095_stats_get_stats,
4403 4404
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4405
	.watchdog_ops = &mv88e6097_watchdog_ops,
4406
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4407
	.pot_clear = mv88e6xxx_g2_pot_clear,
4408
	.reset = mv88e6352_g1_reset,
4409 4410
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4411
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4412
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4413
	.phylink_validate = mv88e6185_phylink_validate,
4414 4415 4416
};

static const struct mv88e6xxx_ops mv88e6351_ops = {
4417
	/* MV88E6XXX_FAMILY_6351 */
4418 4419
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4420
	.irl_init_all = mv88e6352_g2_irl_init_all,
4421
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4422 4423
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4424
	.port_set_link = mv88e6xxx_port_set_link,
4425
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4426
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4427
	.port_tag_remap = mv88e6095_port_tag_remap,
4428
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4429
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4430
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4431
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4432
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4433
	.port_pause_limit = mv88e6097_port_pause_limit,
4434
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4435
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4436
	.port_get_cmode = mv88e6352_port_get_cmode,
4437
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4438
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4439
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4440 4441
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
4442
	.stats_get_stats = mv88e6095_stats_get_stats,
4443 4444
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4445
	.watchdog_ops = &mv88e6097_watchdog_ops,
4446
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4447
	.pot_clear = mv88e6xxx_g2_pot_clear,
4448
	.reset = mv88e6352_g1_reset,
4449 4450
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4451
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4452
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4453
	.avb_ops = &mv88e6352_avb_ops,
4454
	.ptp_ops = &mv88e6352_ptp_ops,
4455
	.phylink_validate = mv88e6185_phylink_validate,
4456 4457 4458
};

static const struct mv88e6xxx_ops mv88e6352_ops = {
4459
	/* MV88E6XXX_FAMILY_6352 */
4460 4461
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4462
	.irl_init_all = mv88e6352_g2_irl_init_all,
4463 4464
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
4465
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4466 4467
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4468
	.port_set_link = mv88e6xxx_port_set_link,
4469
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4470
	.port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
4471
	.port_tag_remap = mv88e6095_port_tag_remap,
4472
	.port_set_policy = mv88e6352_port_set_policy,
4473
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4474
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4475
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4476
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4477
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4478
	.port_pause_limit = mv88e6097_port_pause_limit,
4479
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4480
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4481
	.port_get_cmode = mv88e6352_port_get_cmode,
4482
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4483
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4484
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4485 4486
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
4487
	.stats_get_stats = mv88e6095_stats_get_stats,
4488 4489
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4490
	.watchdog_ops = &mv88e6097_watchdog_ops,
4491
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4492
	.pot_clear = mv88e6xxx_g2_pot_clear,
4493
	.reset = mv88e6352_g1_reset,
4494
	.rmu_disable = mv88e6352_g1_rmu_disable,
4495 4496
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4497
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4498
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4499
	.serdes_get_lane = mv88e6352_serdes_get_lane,
4500 4501 4502 4503
	.serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
	.serdes_pcs_config = mv88e6352_serdes_pcs_config,
	.serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
	.serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
4504
	.serdes_power = mv88e6352_serdes_power,
4505
	.serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
4506
	.serdes_irq_enable = mv88e6352_serdes_irq_enable,
4507
	.serdes_irq_status = mv88e6352_serdes_irq_status,
4508
	.gpio_ops = &mv88e6352_gpio_ops,
4509
	.avb_ops = &mv88e6352_avb_ops,
4510
	.ptp_ops = &mv88e6352_ptp_ops,
4511 4512 4513
	.serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
	.serdes_get_strings = mv88e6352_serdes_get_strings,
	.serdes_get_stats = mv88e6352_serdes_get_stats,
4514 4515
	.serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
	.serdes_get_regs = mv88e6352_serdes_get_regs,
4516
	.phylink_validate = mv88e6352_phylink_validate,
4517 4518
};

4519
static const struct mv88e6xxx_ops mv88e6390_ops = {
4520
	/* MV88E6XXX_FAMILY_6390 */
4521
	.setup_errata = mv88e6390_setup_errata,
4522
	.irl_init_all = mv88e6390_g2_irl_init_all,
4523 4524
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4525 4526 4527 4528 4529
	.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_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4530
	.port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
4531
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
4532
	.port_tag_remap = mv88e6390_port_tag_remap,
4533
	.port_set_policy = mv88e6352_port_set_policy,
4534
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4535
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4536
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4537
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4538
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4539
	.port_pause_limit = mv88e6390_port_pause_limit,
4540
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4541
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4542
	.port_get_cmode = mv88e6352_port_get_cmode,
4543
	.port_set_cmode = mv88e6390_port_set_cmode,
4544
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4545
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4546
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4547 4548
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4549
	.stats_get_stats = mv88e6390_stats_get_stats,
4550 4551
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4552
	.watchdog_ops = &mv88e6390_watchdog_ops,
4553
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4554
	.pot_clear = mv88e6xxx_g2_pot_clear,
4555
	.reset = mv88e6352_g1_reset,
4556
	.rmu_disable = mv88e6390_g1_rmu_disable,
4557 4558
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4559 4560
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4561
	.serdes_power = mv88e6390_serdes_power,
4562
	.serdes_get_lane = mv88e6390_serdes_get_lane,
4563 4564 4565 4566 4567
	/* Check status register pause & lpa register */
	.serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
	.serdes_pcs_config = mv88e6390_serdes_pcs_config,
	.serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
	.serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
4568
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4569
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4570
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4571
	.gpio_ops = &mv88e6352_gpio_ops,
4572
	.avb_ops = &mv88e6390_avb_ops,
4573
	.ptp_ops = &mv88e6352_ptp_ops,
4574 4575 4576
	.serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
4577 4578
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
4579
	.phylink_validate = mv88e6390_phylink_validate,
4580 4581 4582
};

static const struct mv88e6xxx_ops mv88e6390x_ops = {
4583
	/* MV88E6XXX_FAMILY_6390 */
4584
	.setup_errata = mv88e6390_setup_errata,
4585
	.irl_init_all = mv88e6390_g2_irl_init_all,
4586 4587
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4588 4589 4590 4591 4592
	.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_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4593
	.port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
4594
	.port_max_speed_mode = mv88e6390x_port_max_speed_mode,
4595
	.port_tag_remap = mv88e6390_port_tag_remap,
4596
	.port_set_policy = mv88e6352_port_set_policy,
4597
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4598
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4599
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4600
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4601
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4602
	.port_pause_limit = mv88e6390_port_pause_limit,
4603
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4604
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4605
	.port_get_cmode = mv88e6352_port_get_cmode,
4606
	.port_set_cmode = mv88e6390x_port_set_cmode,
4607
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4608
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4609
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4610 4611
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4612
	.stats_get_stats = mv88e6390_stats_get_stats,
4613 4614
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4615
	.watchdog_ops = &mv88e6390_watchdog_ops,
4616
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4617
	.pot_clear = mv88e6xxx_g2_pot_clear,
4618
	.reset = mv88e6352_g1_reset,
4619
	.rmu_disable = mv88e6390_g1_rmu_disable,
4620 4621
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4622 4623
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4624
	.serdes_power = mv88e6390_serdes_power,
4625
	.serdes_get_lane = mv88e6390x_serdes_get_lane,
4626 4627 4628 4629
	.serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
	.serdes_pcs_config = mv88e6390_serdes_pcs_config,
	.serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
	.serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
4630
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4631
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4632
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4633 4634 4635
	.serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
4636 4637
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
4638
	.gpio_ops = &mv88e6352_gpio_ops,
4639
	.avb_ops = &mv88e6390_avb_ops,
4640
	.ptp_ops = &mv88e6352_ptp_ops,
4641
	.phylink_validate = mv88e6390x_phylink_validate,
4642 4643
};

4644 4645
static const struct mv88e6xxx_info mv88e6xxx_table[] = {
	[MV88E6085] = {
4646
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
4647 4648 4649
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6085",
		.num_databases = 4096,
4650
		.num_macs = 8192,
4651
		.num_ports = 10,
4652
		.num_internal_phys = 5,
4653
		.max_vid = 4095,
4654
		.port_base_addr = 0x10,
4655
		.phy_base_addr = 0x0,
4656
		.global1_addr = 0x1b,
4657
		.global2_addr = 0x1c,
4658
		.age_time_coeff = 15000,
4659
		.g1_irqs = 8,
4660
		.g2_irqs = 10,
4661
		.atu_move_port_mask = 0xf,
4662
		.pvt = true,
4663
		.multi_chip = true,
4664
		.tag_protocol = DSA_TAG_PROTO_DSA,
4665
		.ops = &mv88e6085_ops,
4666 4667 4668
	},

	[MV88E6095] = {
4669
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
4670 4671 4672
		.family = MV88E6XXX_FAMILY_6095,
		.name = "Marvell 88E6095/88E6095F",
		.num_databases = 256,
4673
		.num_macs = 8192,
4674
		.num_ports = 11,
4675
		.num_internal_phys = 0,
4676
		.max_vid = 4095,
4677
		.port_base_addr = 0x10,
4678
		.phy_base_addr = 0x0,
4679
		.global1_addr = 0x1b,
4680
		.global2_addr = 0x1c,
4681
		.age_time_coeff = 15000,
4682
		.g1_irqs = 8,
4683
		.atu_move_port_mask = 0xf,
4684
		.multi_chip = true,
4685
		.tag_protocol = DSA_TAG_PROTO_DSA,
4686
		.ops = &mv88e6095_ops,
4687 4688
	},

4689
	[MV88E6097] = {
4690
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
4691 4692 4693
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6097/88E6097F",
		.num_databases = 4096,
4694
		.num_macs = 8192,
4695
		.num_ports = 11,
4696
		.num_internal_phys = 8,
4697
		.max_vid = 4095,
4698
		.port_base_addr = 0x10,
4699
		.phy_base_addr = 0x0,
4700
		.global1_addr = 0x1b,
4701
		.global2_addr = 0x1c,
4702
		.age_time_coeff = 15000,
4703
		.g1_irqs = 8,
4704
		.g2_irqs = 10,
4705
		.atu_move_port_mask = 0xf,
4706
		.pvt = true,
4707
		.multi_chip = true,
4708
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4709 4710 4711
		.ops = &mv88e6097_ops,
	},

4712
	[MV88E6123] = {
4713
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
4714 4715 4716
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6123",
		.num_databases = 4096,
4717
		.num_macs = 1024,
4718
		.num_ports = 3,
4719
		.num_internal_phys = 5,
4720
		.max_vid = 4095,
4721
		.port_base_addr = 0x10,
4722
		.phy_base_addr = 0x0,
4723
		.global1_addr = 0x1b,
4724
		.global2_addr = 0x1c,
4725
		.age_time_coeff = 15000,
4726
		.g1_irqs = 9,
4727
		.g2_irqs = 10,
4728
		.atu_move_port_mask = 0xf,
4729
		.pvt = true,
4730
		.multi_chip = true,
4731
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4732
		.ops = &mv88e6123_ops,
4733 4734 4735
	},

	[MV88E6131] = {
4736
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
4737 4738 4739
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6131",
		.num_databases = 256,
4740
		.num_macs = 8192,
4741
		.num_ports = 8,
4742
		.num_internal_phys = 0,
4743
		.max_vid = 4095,
4744
		.port_base_addr = 0x10,
4745
		.phy_base_addr = 0x0,
4746
		.global1_addr = 0x1b,
4747
		.global2_addr = 0x1c,
4748
		.age_time_coeff = 15000,
4749
		.g1_irqs = 9,
4750
		.atu_move_port_mask = 0xf,
4751
		.multi_chip = true,
4752
		.tag_protocol = DSA_TAG_PROTO_DSA,
4753
		.ops = &mv88e6131_ops,
4754 4755
	},

4756
	[MV88E6141] = {
4757
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
4758
		.family = MV88E6XXX_FAMILY_6341,
4759
		.name = "Marvell 88E6141",
4760
		.num_databases = 4096,
4761
		.num_macs = 2048,
4762
		.num_ports = 6,
4763
		.num_internal_phys = 5,
4764
		.num_gpio = 11,
4765
		.max_vid = 4095,
4766
		.port_base_addr = 0x10,
4767
		.phy_base_addr = 0x10,
4768
		.global1_addr = 0x1b,
4769
		.global2_addr = 0x1c,
4770 4771
		.age_time_coeff = 3750,
		.atu_move_port_mask = 0x1f,
4772
		.g1_irqs = 9,
4773
		.g2_irqs = 10,
4774
		.pvt = true,
4775
		.multi_chip = true,
4776 4777 4778 4779
		.tag_protocol = DSA_TAG_PROTO_EDSA,
		.ops = &mv88e6141_ops,
	},

4780
	[MV88E6161] = {
4781
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
4782 4783 4784
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6161",
		.num_databases = 4096,
4785
		.num_macs = 1024,
4786
		.num_ports = 6,
4787
		.num_internal_phys = 5,
4788
		.max_vid = 4095,
4789
		.port_base_addr = 0x10,
4790
		.phy_base_addr = 0x0,
4791
		.global1_addr = 0x1b,
4792
		.global2_addr = 0x1c,
4793
		.age_time_coeff = 15000,
4794
		.g1_irqs = 9,
4795
		.g2_irqs = 10,
4796
		.atu_move_port_mask = 0xf,
4797
		.pvt = true,
4798
		.multi_chip = true,
4799
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4800
		.ptp_support = true,
4801
		.ops = &mv88e6161_ops,
4802 4803 4804
	},

	[MV88E6165] = {
4805
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
4806 4807 4808
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6165",
		.num_databases = 4096,
4809
		.num_macs = 8192,
4810
		.num_ports = 6,
4811
		.num_internal_phys = 0,
4812
		.max_vid = 4095,
4813
		.port_base_addr = 0x10,
4814
		.phy_base_addr = 0x0,
4815
		.global1_addr = 0x1b,
4816
		.global2_addr = 0x1c,
4817
		.age_time_coeff = 15000,
4818
		.g1_irqs = 9,
4819
		.g2_irqs = 10,
4820
		.atu_move_port_mask = 0xf,
4821
		.pvt = true,
4822
		.multi_chip = true,
4823
		.tag_protocol = DSA_TAG_PROTO_DSA,
4824
		.ptp_support = true,
4825
		.ops = &mv88e6165_ops,
4826 4827 4828
	},

	[MV88E6171] = {
4829
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
4830 4831 4832
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6171",
		.num_databases = 4096,
4833
		.num_macs = 8192,
4834
		.num_ports = 7,
4835
		.num_internal_phys = 5,
4836
		.max_vid = 4095,
4837
		.port_base_addr = 0x10,
4838
		.phy_base_addr = 0x0,
4839
		.global1_addr = 0x1b,
4840
		.global2_addr = 0x1c,
4841
		.age_time_coeff = 15000,
4842
		.g1_irqs = 9,
4843
		.g2_irqs = 10,
4844
		.atu_move_port_mask = 0xf,
4845
		.pvt = true,
4846
		.multi_chip = true,
4847
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4848
		.ops = &mv88e6171_ops,
4849 4850 4851
	},

	[MV88E6172] = {
4852
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
4853 4854 4855
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6172",
		.num_databases = 4096,
4856
		.num_macs = 8192,
4857
		.num_ports = 7,
4858
		.num_internal_phys = 5,
4859
		.num_gpio = 15,
4860
		.max_vid = 4095,
4861
		.port_base_addr = 0x10,
4862
		.phy_base_addr = 0x0,
4863
		.global1_addr = 0x1b,
4864
		.global2_addr = 0x1c,
4865
		.age_time_coeff = 15000,
4866
		.g1_irqs = 9,
4867
		.g2_irqs = 10,
4868
		.atu_move_port_mask = 0xf,
4869
		.pvt = true,
4870
		.multi_chip = true,
4871
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4872
		.ops = &mv88e6172_ops,
4873 4874 4875
	},

	[MV88E6175] = {
4876
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
4877 4878 4879
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6175",
		.num_databases = 4096,
4880
		.num_macs = 8192,
4881
		.num_ports = 7,
4882
		.num_internal_phys = 5,
4883
		.max_vid = 4095,
4884
		.port_base_addr = 0x10,
4885
		.phy_base_addr = 0x0,
4886
		.global1_addr = 0x1b,
4887
		.global2_addr = 0x1c,
4888
		.age_time_coeff = 15000,
4889
		.g1_irqs = 9,
4890
		.g2_irqs = 10,
4891
		.atu_move_port_mask = 0xf,
4892
		.pvt = true,
4893
		.multi_chip = true,
4894
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4895
		.ops = &mv88e6175_ops,
4896 4897 4898
	},

	[MV88E6176] = {
4899
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
4900 4901 4902
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6176",
		.num_databases = 4096,
4903
		.num_macs = 8192,
4904
		.num_ports = 7,
4905
		.num_internal_phys = 5,
4906
		.num_gpio = 15,
4907
		.max_vid = 4095,
4908
		.port_base_addr = 0x10,
4909
		.phy_base_addr = 0x0,
4910
		.global1_addr = 0x1b,
4911
		.global2_addr = 0x1c,
4912
		.age_time_coeff = 15000,
4913
		.g1_irqs = 9,
4914
		.g2_irqs = 10,
4915
		.atu_move_port_mask = 0xf,
4916
		.pvt = true,
4917
		.multi_chip = true,
4918
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4919
		.ops = &mv88e6176_ops,
4920 4921 4922
	},

	[MV88E6185] = {
4923
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
4924 4925 4926
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6185",
		.num_databases = 256,
4927
		.num_macs = 8192,
4928
		.num_ports = 10,
4929
		.num_internal_phys = 0,
4930
		.max_vid = 4095,
4931
		.port_base_addr = 0x10,
4932
		.phy_base_addr = 0x0,
4933
		.global1_addr = 0x1b,
4934
		.global2_addr = 0x1c,
4935
		.age_time_coeff = 15000,
4936
		.g1_irqs = 8,
4937
		.atu_move_port_mask = 0xf,
4938
		.multi_chip = true,
4939
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4940
		.ops = &mv88e6185_ops,
4941 4942
	},

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

	[MV88E6190X] = {
4968
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
4969 4970 4971
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190X",
		.num_databases = 4096,
4972
		.num_macs = 16384,
4973
		.num_ports = 11,	/* 10 + Z80 */
4974
		.num_internal_phys = 9,
4975
		.num_gpio = 16,
4976
		.max_vid = 8191,
4977
		.port_base_addr = 0x0,
4978
		.phy_base_addr = 0x0,
4979
		.global1_addr = 0x1b,
4980
		.global2_addr = 0x1c,
4981
		.age_time_coeff = 3750,
4982
		.g1_irqs = 9,
4983
		.g2_irqs = 14,
4984
		.atu_move_port_mask = 0x1f,
4985
		.pvt = true,
4986
		.multi_chip = true,
4987
		.tag_protocol = DSA_TAG_PROTO_DSA,
4988 4989 4990 4991
		.ops = &mv88e6190x_ops,
	},

	[MV88E6191] = {
4992
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
4993 4994 4995
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6191",
		.num_databases = 4096,
4996
		.num_macs = 16384,
4997
		.num_ports = 11,	/* 10 + Z80 */
4998
		.num_internal_phys = 9,
4999
		.max_vid = 8191,
5000
		.port_base_addr = 0x0,
5001
		.phy_base_addr = 0x0,
5002
		.global1_addr = 0x1b,
5003
		.global2_addr = 0x1c,
5004
		.age_time_coeff = 3750,
5005
		.g1_irqs = 9,
5006
		.g2_irqs = 14,
5007
		.atu_move_port_mask = 0x1f,
5008
		.pvt = true,
5009
		.multi_chip = true,
5010
		.tag_protocol = DSA_TAG_PROTO_DSA,
5011
		.ptp_support = true,
5012
		.ops = &mv88e6191_ops,
5013 5014
	},

5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025
	[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,
5026
		.invalid_port_mask = BIT(2) | BIT(3) | BIT(4),
5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037
		.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,
5038
		.ptp_support = true,
5039 5040 5041
		.ops = &mv88e6250_ops,
	},

5042
	[MV88E6240] = {
5043
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
5044 5045 5046
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6240",
		.num_databases = 4096,
5047
		.num_macs = 8192,
5048
		.num_ports = 7,
5049
		.num_internal_phys = 5,
5050
		.num_gpio = 15,
5051
		.max_vid = 4095,
5052
		.port_base_addr = 0x10,
5053
		.phy_base_addr = 0x0,
5054
		.global1_addr = 0x1b,
5055
		.global2_addr = 0x1c,
5056
		.age_time_coeff = 15000,
5057
		.g1_irqs = 9,
5058
		.g2_irqs = 10,
5059
		.atu_move_port_mask = 0xf,
5060
		.pvt = true,
5061
		.multi_chip = true,
5062
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5063
		.ptp_support = true,
5064
		.ops = &mv88e6240_ops,
5065 5066
	},

5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084
	[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,
5085
		.ptp_support = true,
5086 5087 5088
		.ops = &mv88e6250_ops,
	},

5089
	[MV88E6290] = {
5090
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
5091 5092 5093 5094
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6290",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
5095
		.num_internal_phys = 9,
5096
		.num_gpio = 16,
5097
		.max_vid = 8191,
5098
		.port_base_addr = 0x0,
5099
		.phy_base_addr = 0x0,
5100
		.global1_addr = 0x1b,
5101
		.global2_addr = 0x1c,
5102
		.age_time_coeff = 3750,
5103
		.g1_irqs = 9,
5104
		.g2_irqs = 14,
5105
		.atu_move_port_mask = 0x1f,
5106
		.pvt = true,
5107
		.multi_chip = true,
5108
		.tag_protocol = DSA_TAG_PROTO_DSA,
5109
		.ptp_support = true,
5110 5111 5112
		.ops = &mv88e6290_ops,
	},

5113
	[MV88E6320] = {
5114
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
5115 5116 5117
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6320",
		.num_databases = 4096,
5118
		.num_macs = 8192,
5119
		.num_ports = 7,
5120
		.num_internal_phys = 5,
5121
		.num_gpio = 15,
5122
		.max_vid = 4095,
5123
		.port_base_addr = 0x10,
5124
		.phy_base_addr = 0x0,
5125
		.global1_addr = 0x1b,
5126
		.global2_addr = 0x1c,
5127
		.age_time_coeff = 15000,
5128
		.g1_irqs = 8,
5129
		.g2_irqs = 10,
5130
		.atu_move_port_mask = 0xf,
5131
		.pvt = true,
5132
		.multi_chip = true,
5133
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5134
		.ptp_support = true,
5135
		.ops = &mv88e6320_ops,
5136 5137 5138
	},

	[MV88E6321] = {
5139
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
5140 5141 5142
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6321",
		.num_databases = 4096,
5143
		.num_macs = 8192,
5144
		.num_ports = 7,
5145
		.num_internal_phys = 5,
5146
		.num_gpio = 15,
5147
		.max_vid = 4095,
5148
		.port_base_addr = 0x10,
5149
		.phy_base_addr = 0x0,
5150
		.global1_addr = 0x1b,
5151
		.global2_addr = 0x1c,
5152
		.age_time_coeff = 15000,
5153
		.g1_irqs = 8,
5154
		.g2_irqs = 10,
5155
		.atu_move_port_mask = 0xf,
5156
		.multi_chip = true,
5157
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5158
		.ptp_support = true,
5159
		.ops = &mv88e6321_ops,
5160 5161
	},

5162
	[MV88E6341] = {
5163
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
5164 5165 5166
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
5167
		.num_macs = 2048,
5168
		.num_internal_phys = 5,
5169
		.num_ports = 6,
5170
		.num_gpio = 11,
5171
		.max_vid = 4095,
5172
		.port_base_addr = 0x10,
5173
		.phy_base_addr = 0x10,
5174
		.global1_addr = 0x1b,
5175
		.global2_addr = 0x1c,
5176
		.age_time_coeff = 3750,
5177
		.atu_move_port_mask = 0x1f,
5178
		.g1_irqs = 9,
5179
		.g2_irqs = 10,
5180
		.pvt = true,
5181
		.multi_chip = true,
5182
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5183
		.ptp_support = true,
5184 5185 5186
		.ops = &mv88e6341_ops,
	},

5187
	[MV88E6350] = {
5188
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
5189 5190 5191
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6350",
		.num_databases = 4096,
5192
		.num_macs = 8192,
5193
		.num_ports = 7,
5194
		.num_internal_phys = 5,
5195
		.max_vid = 4095,
5196
		.port_base_addr = 0x10,
5197
		.phy_base_addr = 0x0,
5198
		.global1_addr = 0x1b,
5199
		.global2_addr = 0x1c,
5200
		.age_time_coeff = 15000,
5201
		.g1_irqs = 9,
5202
		.g2_irqs = 10,
5203
		.atu_move_port_mask = 0xf,
5204
		.pvt = true,
5205
		.multi_chip = true,
5206
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5207
		.ops = &mv88e6350_ops,
5208 5209 5210
	},

	[MV88E6351] = {
5211
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
5212 5213 5214
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6351",
		.num_databases = 4096,
5215
		.num_macs = 8192,
5216
		.num_ports = 7,
5217
		.num_internal_phys = 5,
5218
		.max_vid = 4095,
5219
		.port_base_addr = 0x10,
5220
		.phy_base_addr = 0x0,
5221
		.global1_addr = 0x1b,
5222
		.global2_addr = 0x1c,
5223
		.age_time_coeff = 15000,
5224
		.g1_irqs = 9,
5225
		.g2_irqs = 10,
5226
		.atu_move_port_mask = 0xf,
5227
		.pvt = true,
5228
		.multi_chip = true,
5229
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5230
		.ops = &mv88e6351_ops,
5231 5232 5233
	},

	[MV88E6352] = {
5234
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
5235 5236 5237
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6352",
		.num_databases = 4096,
5238
		.num_macs = 8192,
5239
		.num_ports = 7,
5240
		.num_internal_phys = 5,
5241
		.num_gpio = 15,
5242
		.max_vid = 4095,
5243
		.port_base_addr = 0x10,
5244
		.phy_base_addr = 0x0,
5245
		.global1_addr = 0x1b,
5246
		.global2_addr = 0x1c,
5247
		.age_time_coeff = 15000,
5248
		.g1_irqs = 9,
5249
		.g2_irqs = 10,
5250
		.atu_move_port_mask = 0xf,
5251
		.pvt = true,
5252
		.multi_chip = true,
5253
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5254
		.ptp_support = true,
5255
		.ops = &mv88e6352_ops,
5256
	},
5257
	[MV88E6390] = {
5258
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
5259 5260 5261
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390",
		.num_databases = 4096,
5262
		.num_macs = 16384,
5263
		.num_ports = 11,	/* 10 + Z80 */
5264
		.num_internal_phys = 9,
5265
		.num_gpio = 16,
5266
		.max_vid = 8191,
5267
		.port_base_addr = 0x0,
5268
		.phy_base_addr = 0x0,
5269
		.global1_addr = 0x1b,
5270
		.global2_addr = 0x1c,
5271
		.age_time_coeff = 3750,
5272
		.g1_irqs = 9,
5273
		.g2_irqs = 14,
5274
		.atu_move_port_mask = 0x1f,
5275
		.pvt = true,
5276
		.multi_chip = true,
5277
		.tag_protocol = DSA_TAG_PROTO_DSA,
5278
		.ptp_support = true,
5279 5280 5281
		.ops = &mv88e6390_ops,
	},
	[MV88E6390X] = {
5282
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
5283 5284 5285
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390X",
		.num_databases = 4096,
5286
		.num_macs = 16384,
5287
		.num_ports = 11,	/* 10 + Z80 */
5288
		.num_internal_phys = 9,
5289
		.num_gpio = 16,
5290
		.max_vid = 8191,
5291
		.port_base_addr = 0x0,
5292
		.phy_base_addr = 0x0,
5293
		.global1_addr = 0x1b,
5294
		.global2_addr = 0x1c,
5295
		.age_time_coeff = 3750,
5296
		.g1_irqs = 9,
5297
		.g2_irqs = 14,
5298
		.atu_move_port_mask = 0x1f,
5299
		.pvt = true,
5300
		.multi_chip = true,
5301
		.tag_protocol = DSA_TAG_PROTO_DSA,
5302
		.ptp_support = true,
5303 5304
		.ops = &mv88e6390x_ops,
	},
5305 5306
};

5307
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
5308
{
5309
	int i;
5310

5311 5312 5313
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
5314 5315 5316 5317

	return NULL;
}

5318
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
5319 5320
{
	const struct mv88e6xxx_info *info;
5321 5322 5323
	unsigned int prod_num, rev;
	u16 id;
	int err;
5324

5325
	mv88e6xxx_reg_lock(chip);
5326
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
5327
	mv88e6xxx_reg_unlock(chip);
5328 5329
	if (err)
		return err;
5330

5331 5332
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
5333 5334 5335 5336 5337

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

5338
	/* Update the compatible info with the probed one */
5339
	chip->info = info;
5340

5341 5342 5343 5344
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

5345 5346
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
5347 5348 5349 5350

	return 0;
}

5351
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
5352
{
5353
	struct mv88e6xxx_chip *chip;
5354

5355 5356
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
5357 5358
		return NULL;

5359
	chip->dev = dev;
5360

5361
	mutex_init(&chip->reg_lock);
5362
	INIT_LIST_HEAD(&chip->mdios);
5363
	idr_init(&chip->policies);
5364

5365
	return chip;
5366 5367
}

5368
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
5369 5370
							int port,
							enum dsa_tag_protocol m)
5371
{
V
Vivien Didelot 已提交
5372
	struct mv88e6xxx_chip *chip = ds->priv;
5373

5374
	return chip->info->tag_protocol;
5375 5376
}

5377
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
5378
				      const struct switchdev_obj_port_mdb *mdb)
5379 5380 5381 5382 5383 5384 5385 5386 5387
{
	/* 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,
5388
				   const struct switchdev_obj_port_mdb *mdb)
5389
{
V
Vivien Didelot 已提交
5390
	struct mv88e6xxx_chip *chip = ds->priv;
5391

5392
	mv88e6xxx_reg_lock(chip);
5393
	if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
5394
					 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
5395 5396
		dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
			port);
5397
	mv88e6xxx_reg_unlock(chip);
5398 5399 5400 5401 5402
}

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

5406
	mv88e6xxx_reg_lock(chip);
5407
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 0);
5408
	mv88e6xxx_reg_unlock(chip);
5409 5410 5411 5412

	return err;
}

5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479
static int mv88e6xxx_port_mirror_add(struct dsa_switch *ds, int port,
				     struct dsa_mall_mirror_tc_entry *mirror,
				     bool ingress)
{
	enum mv88e6xxx_egress_direction direction = ingress ?
						MV88E6XXX_EGRESS_DIR_INGRESS :
						MV88E6XXX_EGRESS_DIR_EGRESS;
	struct mv88e6xxx_chip *chip = ds->priv;
	bool other_mirrors = false;
	int i;
	int err;

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

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

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

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

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

	return err;
}

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

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

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

	/* Reset egress port when no other mirror is active */
	if (!other_mirrors) {
		if (chip->info->ops->set_egress_port(chip,
						     direction,
						     dsa_upstream_port(ds,
5480
								       port)))
5481 5482 5483 5484 5485 5486
			dev_err(ds->dev, "failed to set egress port\n");
	}

	mutex_unlock(&chip->reg_lock);
}

5487 5488 5489 5490 5491 5492
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;

5493
	mv88e6xxx_reg_lock(chip);
5494 5495 5496 5497
	if (chip->info->ops->port_set_egress_floods)
		err = chip->info->ops->port_set_egress_floods(chip, port,
							      unicast,
							      multicast);
5498
	mv88e6xxx_reg_unlock(chip);
5499 5500 5501 5502

	return err;
}

5503
static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
5504
	.get_tag_protocol	= mv88e6xxx_get_tag_protocol,
5505
	.setup			= mv88e6xxx_setup,
5506
	.teardown		= mv88e6xxx_teardown,
5507
	.phylink_validate	= mv88e6xxx_validate,
5508
	.phylink_mac_link_state	= mv88e6xxx_serdes_pcs_get_state,
5509
	.phylink_mac_config	= mv88e6xxx_mac_config,
5510
	.phylink_mac_an_restart	= mv88e6xxx_serdes_pcs_an_restart,
5511 5512
	.phylink_mac_link_down	= mv88e6xxx_mac_link_down,
	.phylink_mac_link_up	= mv88e6xxx_mac_link_up,
5513 5514 5515
	.get_strings		= mv88e6xxx_get_strings,
	.get_ethtool_stats	= mv88e6xxx_get_ethtool_stats,
	.get_sset_count		= mv88e6xxx_get_sset_count,
5516 5517
	.port_enable		= mv88e6xxx_port_enable,
	.port_disable		= mv88e6xxx_port_disable,
V
Vivien Didelot 已提交
5518 5519
	.get_mac_eee		= mv88e6xxx_get_mac_eee,
	.set_mac_eee		= mv88e6xxx_set_mac_eee,
5520
	.get_eeprom_len		= mv88e6xxx_get_eeprom_len,
5521 5522 5523 5524
	.get_eeprom		= mv88e6xxx_get_eeprom,
	.set_eeprom		= mv88e6xxx_set_eeprom,
	.get_regs_len		= mv88e6xxx_get_regs_len,
	.get_regs		= mv88e6xxx_get_regs,
5525 5526
	.get_rxnfc		= mv88e6xxx_get_rxnfc,
	.set_rxnfc		= mv88e6xxx_set_rxnfc,
5527
	.set_ageing_time	= mv88e6xxx_set_ageing_time,
5528 5529
	.port_bridge_join	= mv88e6xxx_port_bridge_join,
	.port_bridge_leave	= mv88e6xxx_port_bridge_leave,
5530
	.port_egress_floods	= mv88e6xxx_port_egress_floods,
5531
	.port_stp_state_set	= mv88e6xxx_port_stp_state_set,
5532
	.port_fast_age		= mv88e6xxx_port_fast_age,
5533 5534 5535 5536 5537 5538 5539
	.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,
5540 5541 5542
	.port_mdb_prepare       = mv88e6xxx_port_mdb_prepare,
	.port_mdb_add           = mv88e6xxx_port_mdb_add,
	.port_mdb_del           = mv88e6xxx_port_mdb_del,
5543 5544
	.port_mirror_add	= mv88e6xxx_port_mirror_add,
	.port_mirror_del	= mv88e6xxx_port_mirror_del,
5545 5546
	.crosschip_bridge_join	= mv88e6xxx_crosschip_bridge_join,
	.crosschip_bridge_leave	= mv88e6xxx_crosschip_bridge_leave,
5547 5548 5549 5550 5551
	.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,
5552 5553
	.devlink_param_get	= mv88e6xxx_devlink_param_get,
	.devlink_param_set	= mv88e6xxx_devlink_param_set,
5554 5555
};

5556
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
5557
{
5558
	struct device *dev = chip->dev;
5559 5560
	struct dsa_switch *ds;

5561
	ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
5562 5563 5564
	if (!ds)
		return -ENOMEM;

5565 5566
	ds->dev = dev;
	ds->num_ports = mv88e6xxx_num_ports(chip);
5567
	ds->priv = chip;
5568
	ds->dev = dev;
5569
	ds->ops = &mv88e6xxx_switch_ops;
5570 5571
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
5572 5573 5574

	dev_set_drvdata(dev, ds);

5575
	return dsa_register_switch(ds);
5576 5577
}

5578
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
5579
{
5580
	dsa_unregister_switch(chip->ds);
5581 5582
}

5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595
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;
}

5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610
/* 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);

5611
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
5612
{
5613
	struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
5614
	const struct mv88e6xxx_info *compat_info = NULL;
5615
	struct device *dev = &mdiodev->dev;
5616
	struct device_node *np = dev->of_node;
5617
	struct mv88e6xxx_chip *chip;
5618
	int port;
5619
	int err;
5620

5621 5622 5623
	if (!np && !pdata)
		return -EINVAL;

5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642
	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;
		}
	}

5643 5644 5645
	if (!compat_info)
		return -EINVAL;

5646
	chip = mv88e6xxx_alloc_chip(dev);
5647 5648 5649 5650
	if (!chip) {
		err = -ENOMEM;
		goto out;
	}
5651

5652
	chip->info = compat_info;
5653

5654
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
5655
	if (err)
5656
		goto out;
5657

5658
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
5659 5660 5661 5662
	if (IS_ERR(chip->reset)) {
		err = PTR_ERR(chip->reset);
		goto out;
	}
5663 5664
	if (chip->reset)
		usleep_range(1000, 2000);
5665

5666
	err = mv88e6xxx_detect(chip);
5667
	if (err)
5668
		goto out;
5669

5670 5671
	mv88e6xxx_phy_init(chip);

5672 5673 5674 5675 5676 5677 5678
	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;
	}
5679

5680
	mv88e6xxx_reg_lock(chip);
5681
	err = mv88e6xxx_switch_reset(chip);
5682
	mv88e6xxx_reg_unlock(chip);
5683 5684 5685
	if (err)
		goto out;

5686 5687 5688 5689 5690 5691
	if (np) {
		chip->irq = of_irq_get(np, 0);
		if (chip->irq == -EPROBE_DEFER) {
			err = chip->irq;
			goto out;
		}
5692 5693
	}

5694 5695 5696
	if (pdata)
		chip->irq = pdata->irq;

5697
	/* Has to be performed before the MDIO bus is created, because
5698
	 * the PHYs will link their interrupts to these interrupt
5699 5700
	 * controllers
	 */
5701
	mv88e6xxx_reg_lock(chip);
5702
	if (chip->irq > 0)
5703
		err = mv88e6xxx_g1_irq_setup(chip);
5704 5705
	else
		err = mv88e6xxx_irq_poll_setup(chip);
5706
	mv88e6xxx_reg_unlock(chip);
5707

5708 5709
	if (err)
		goto out;
5710

5711 5712
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
5713
		if (err)
5714
			goto out_g1_irq;
5715 5716
	}

5717 5718 5719 5720 5721 5722 5723 5724
	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;

5725
	err = mv88e6xxx_mdios_register(chip, np);
5726
	if (err)
5727
		goto out_g1_vtu_prob_irq;
5728

5729
	err = mv88e6xxx_register_switch(chip);
5730 5731
	if (err)
		goto out_mdio;
5732

5733
	return 0;
5734 5735

out_mdio:
5736
	mv88e6xxx_mdios_unregister(chip);
5737
out_g1_vtu_prob_irq:
5738
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
5739
out_g1_atu_prob_irq:
5740
	mv88e6xxx_g1_atu_prob_irq_free(chip);
5741
out_g2_irq:
5742
	if (chip->info->g2_irqs > 0)
5743 5744
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
5745
	if (chip->irq > 0)
5746
		mv88e6xxx_g1_irq_free(chip);
5747 5748
	else
		mv88e6xxx_irq_poll_free(chip);
5749
out:
5750 5751 5752
	if (pdata)
		dev_put(pdata->netdev);

5753
	return err;
5754
}
5755 5756 5757 5758

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

5761 5762
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
5763
		mv88e6xxx_ptp_free(chip);
5764
	}
5765

5766
	mv88e6xxx_phy_destroy(chip);
5767
	mv88e6xxx_unregister_switch(chip);
5768
	mv88e6xxx_mdios_unregister(chip);
5769

5770 5771 5772 5773 5774 5775 5776
	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)
5777
		mv88e6xxx_g1_irq_free(chip);
5778 5779
	else
		mv88e6xxx_irq_poll_free(chip);
5780 5781 5782
}

static const struct of_device_id mv88e6xxx_of_match[] = {
5783 5784 5785 5786
	{
		.compatible = "marvell,mv88e6085",
		.data = &mv88e6xxx_table[MV88E6085],
	},
5787 5788 5789 5790
	{
		.compatible = "marvell,mv88e6190",
		.data = &mv88e6xxx_table[MV88E6190],
	},
5791 5792 5793 5794
	{
		.compatible = "marvell,mv88e6250",
		.data = &mv88e6xxx_table[MV88E6250],
	},
5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805
	{ /* 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,
5806
		.pm = &mv88e6xxx_pm_ops,
5807 5808 5809
	},
};

5810
mdio_module_driver(mv88e6xxx_driver);
5811 5812 5813 5814

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