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

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

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

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

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

56
	assert_reg_lock(chip);
57

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

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

	return 0;
}

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

72
	assert_reg_lock(chip);
73

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

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

81 82 83
	return 0;
}

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

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

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

		usleep_range(1000, 2000);
	}

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

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

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

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

	return mdio_bus->bus;
}

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

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

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

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

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

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

	if (err)
		goto out;

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

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

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

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

	return mv88e6xxx_g1_irq_thread_work(chip);
}

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

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

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

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

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

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

out:
217
	mv88e6xxx_reg_unlock(chip);
218 219
}

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

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

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

	return 0;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return 0;

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

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

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

	return err;
}

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

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

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

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

	return err;
}

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

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

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

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

	kthread_init_delayed_work(&chip->irq_poll_work,
				  mv88e6xxx_irq_poll);

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

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

	return 0;
}

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

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

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

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

407 408 409 410 411 412 413 414 415 416 417 418 419
	if (!chip->info->ops->port_link_state)
		return 0;

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

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

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

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

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

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

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

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

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

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

	return err;
}

471 472 473 474 475 476 477
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;
}

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

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

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

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

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

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

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

	return err;
}

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

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

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

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

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

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

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

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

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

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

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

666
	return chip->info->ops->stats_snapshot(chip, port);
667 668
}

669
static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728
	{ "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, },
729 730
};

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

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

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

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

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

	return j;
788 789
}

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

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

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

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

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

834 835 836
	if (stringset != ETH_SS_STATS)
		return;

837
	mv88e6xxx_reg_lock(chip);
838

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

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

847 848 849
	data += count * ETH_GSTRING_LEN;
	mv88e6xxx_atu_vtu_get_strings(data);

850
	mv88e6xxx_reg_unlock(chip);
851 852 853 854 855
}

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

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

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

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

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

890 891 892
	if (sset != ETH_SS_STATS)
		return 0;

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

909
out:
910
	mv88e6xxx_reg_unlock(chip);
911

912
	return count;
913 914
}

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

931 932 933
			j++;
		}
	}
934
	return j;
935 936
}

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

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

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

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

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

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

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

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

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

1004
	mv88e6xxx_reg_lock(chip);
1005

1006
	ret = mv88e6xxx_stats_snapshot(chip, port);
1007
	mv88e6xxx_reg_unlock(chip);
1008 1009

	if (ret < 0)
1010
		return;
1011 1012

	mv88e6xxx_get_stats(chip, port, data);
1013

1014 1015
}

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

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

1030
	regs->version = chip->info->prod_num;
1031 1032 1033

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

1034
	mv88e6xxx_reg_lock(chip);
1035

1036 1037
	for (i = 0; i < 32; i++) {

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

1043
	mv88e6xxx_reg_unlock(chip);
1044 1045
}

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

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

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

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

	/* Prevent frames from unknown switch or port */
1078
	if (!found)
1079 1080 1081
		return 0;

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

1085
	br = dp->bridge_dev;
1086 1087 1088 1089 1090
	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.
	 */
1091 1092 1093 1094 1095 1096
	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);
1097 1098 1099 1100

	return pvlan;
}

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

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

1108
	return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
1109 1110
}

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

1117
	mv88e6xxx_reg_lock(chip);
1118
	err = mv88e6xxx_port_set_state(chip, port, state);
1119
	mv88e6xxx_reg_unlock(chip);
1120 1121

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

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

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

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

1164 1165 1166 1167 1168 1169 1170
	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;
	}

1171 1172 1173 1174
	err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
	if (err)
		return err;

1175 1176 1177
	return 0;
}

1178 1179 1180 1181 1182 1183 1184 1185 1186
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;
}

1187 1188 1189 1190 1191 1192 1193 1194
static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->rmu_disable)
		return chip->info->ops->rmu_disable(chip);

	return 0;
}

1195 1196 1197 1198 1199 1200 1201 1202
static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->pot_clear)
		return chip->info->ops->pot_clear(chip);

	return 0;
}

1203 1204 1205 1206 1207 1208 1209 1210
static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->mgmt_rsvd2cpu)
		return chip->info->ops->mgmt_rsvd2cpu(chip);

	return 0;
}

1211 1212
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
1213 1214
	int err;

1215 1216 1217 1218
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

1219 1220 1221 1222
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

1223 1224 1225
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

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

1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258
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;
}

1259 1260 1261 1262 1263
static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
{
	u16 pvlan = 0;

	if (!mv88e6xxx_has_pvt(chip))
1264
		return 0;
1265 1266 1267

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

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

1273 1274
static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
{
1275 1276 1277
	int dev, port;
	int err;

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

1299 1300 1301 1302 1303
static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

1304
	mv88e6xxx_reg_lock(chip);
1305
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1306
	mv88e6xxx_reg_unlock(chip);
1307 1308

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

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

	return mv88e6xxx_g1_vtu_flush(chip);
}

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

1329 1330 1331 1332 1333 1334 1335 1336 1337
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);
}

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

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

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

		set_bit(*fid, fid_bitmap);
	}

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

1359
	do {
1360
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1361 1362 1363 1364 1365 1366 1367
		if (err)
			return err;

		if (!vlan.valid)
			break;

		set_bit(vlan.fid, fid_bitmap);
1368
	} while (vlan.vid < chip->info->max_vid);
1369 1370 1371 1372 1373

	/* 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);
1374
	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1375 1376 1377
		return -ENOSPC;

	/* Clear the database */
1378
	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1379 1380
}

1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396
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;
}

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

1404 1405 1406 1407
	/* 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;

1408 1409 1410
	if (!vid_begin)
		return -EOPNOTSUPP;

1411 1412 1413
	vlan.vid = vid_begin - 1;
	vlan.valid = false;

1414
	do {
1415
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1416
		if (err)
1417
			return err;
1418 1419 1420 1421 1422 1423 1424

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

1425
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1426 1427 1428
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

1429
			if (!dsa_to_port(ds, i)->slave)
1430 1431
				continue;

1432
			if (vlan.member[i] ==
1433
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1434 1435
				continue;

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

V
Vivien Didelot 已提交
1440
			if (!dsa_to_port(ds, i)->bridge_dev)
1441 1442
				continue;

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

1450
	return 0;
1451 1452
}

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

1461
	if (!chip->info->max_vid)
1462 1463
		return -EOPNOTSUPP;

1464
	mv88e6xxx_reg_lock(chip);
1465
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1466
	mv88e6xxx_reg_unlock(chip);
1467

1468
	return err;
1469 1470
}

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

1478
	if (!chip->info->max_vid)
1479 1480
		return -EOPNOTSUPP;

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

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

1495 1496 1497 1498 1499
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;
1500 1501
	struct mv88e6xxx_vtu_entry vlan;
	u16 fid;
1502 1503 1504
	int err;

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

1524
	entry.state = 0;
1525 1526 1527
	ether_addr_copy(entry.mac, addr);
	eth_addr_dec(entry.mac);

1528
	err = mv88e6xxx_g1_atu_getnext(chip, fid, &entry);
1529 1530 1531 1532
	if (err)
		return err;

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

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

1548
	return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry);
1549 1550
}

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

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

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

1791 1792
	if (!vid)
		return -EOPNOTSUPP;
1793

1794 1795
	vlan.vid = vid - 1;
	vlan.valid = false;
1796

1797
	err = mv88e6xxx_vtu_getnext(chip, &vlan);
1798 1799 1800
	if (err)
		return err;

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
	if (vlan.vid != vid || !vlan.valid) {
		memset(&vlan, 0, sizeof(vlan));

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

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

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

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

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

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

	return 0;
1836 1837
}

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

1847
	if (!chip->info->max_vid)
1848 1849
		return;

1850
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1851
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1852
	else if (untagged)
1853
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
1854
	else
1855
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
1856

1857
	mv88e6xxx_reg_lock(chip);
1858

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

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

1868
	mv88e6xxx_reg_unlock(chip);
1869 1870
}

1871 1872
static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,
				     int port, u16 vid)
1873
{
1874
	struct mv88e6xxx_vtu_entry vlan;
1875 1876
	int i, err;

1877 1878 1879 1880 1881 1882 1883
	if (!vid)
		return -EOPNOTSUPP;

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

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

1887 1888 1889 1890 1891
	/* 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)
1892
		return -EOPNOTSUPP;
1893

1894
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1895 1896

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

1906
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1907 1908 1909
	if (err)
		return err;

1910
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
1911 1912
}

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

1920
	if (!chip->info->max_vid)
1921 1922
		return -EOPNOTSUPP;

1923
	mv88e6xxx_reg_lock(chip);
1924

1925
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
1926 1927 1928
	if (err)
		goto unlock;

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

		if (vid == pvid) {
1935
			err = mv88e6xxx_port_set_pvid(chip, port, 0);
1936 1937 1938 1939 1940
			if (err)
				goto unlock;
		}
	}

1941
unlock:
1942
	mv88e6xxx_reg_unlock(chip);
1943 1944 1945 1946

	return err;
}

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

1953
	mv88e6xxx_reg_lock(chip);
1954 1955
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1956
	mv88e6xxx_reg_unlock(chip);
1957 1958

	return err;
1959 1960
}

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

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

1971
	return err;
1972 1973
}

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

1982
	addr.state = 0;
1983
	eth_broadcast_addr(addr.mac);
1984 1985

	do {
1986
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
1987
		if (err)
1988
			return err;
1989

1990
		if (!addr.state)
1991 1992
			break;

1993
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
1994 1995
			continue;

1996 1997
		if (!is_unicast_ether_addr(addr.mac))
			continue;
1998

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

	return err;
}

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

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

2021
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
2022
	if (err)
2023
		return err;
2024

2025
	/* Dump VLANs' Filtering Information Databases */
2026 2027 2028
	vlan.vid = chip->info->max_vid;
	vlan.valid = false;

2029
	do {
2030
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
2031
		if (err)
2032
			return err;
2033 2034 2035 2036

		if (!vlan.valid)
			break;

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

2043 2044 2045 2046
	return err;
}

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

2052
	mv88e6xxx_reg_lock(chip);
2053
	err = mv88e6xxx_port_db_dump(chip, port, cb, data);
2054
	mv88e6xxx_reg_unlock(chip);
2055

2056
	return err;
2057 2058
}

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

2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081
	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);
2082 2083 2084 2085 2086 2087
				if (err)
					return err;
			}
		}
	}

2088 2089 2090 2091 2092 2093 2094 2095 2096
	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;

2097
	mv88e6xxx_reg_lock(chip);
2098
	err = mv88e6xxx_bridge_map(chip, br);
2099
	mv88e6xxx_reg_unlock(chip);
2100

2101
	return err;
2102 2103
}

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

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

2116 2117 2118 2119 2120 2121
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;

2122
	mv88e6xxx_reg_lock(chip);
2123
	err = mv88e6xxx_pvt_map(chip, dev, port);
2124
	mv88e6xxx_reg_unlock(chip);
2125 2126 2127 2128 2129 2130 2131 2132 2133

	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;

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

2140 2141 2142 2143 2144 2145 2146 2147
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->reset)
		return chip->info->ops->reset(chip);

	return 0;
}

2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160
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);
	}
}

2161
static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2162
{
2163
	int i, err;
2164

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

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

2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187
	return 0;
}

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

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

2188
	mv88e6xxx_hardware_reset(chip);
2189

2190
	return mv88e6xxx_software_reset(chip);
2191 2192
}

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

2199 2200 2201 2202
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
2203 2204 2205
	if (err)
		return err;

2206 2207 2208 2209 2210 2211 2212 2213
	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;
2214 2215
}

2216
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2217
{
2218
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
2219
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2220
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2221
}
2222

2223 2224 2225
static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
2226
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2227
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2228
}
2229

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

2238 2239 2240 2241
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);
2242

2243
	if (dsa_is_user_port(chip->ds, port))
2244
		return mv88e6xxx_set_port_mode_normal(chip, port);
2245

2246 2247 2248
	/* 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);
2249

2250 2251
	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
		return mv88e6xxx_set_port_mode_edsa(chip, port);
2252

2253
	return -EINVAL;
2254 2255
}

2256
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2257
{
2258
	bool message = dsa_is_dsa_port(chip->ds, port);
2259

2260
	return mv88e6xxx_port_set_message_port(chip, port, message);
2261
}
2262

2263
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2264
{
2265
	struct dsa_switch *ds = chip->ds;
2266
	bool flood;
2267

2268 2269 2270 2271 2272
	/* 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);
2273

2274
	return 0;
2275 2276
}

2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341
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;

	/* 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,
				   IRQF_ONESHOT, "mv88e6xxx-serdes", dev_id);
	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;
}

2342 2343 2344
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
2345
	u8 lane;
2346
	int err;
2347

2348 2349
	lane = mv88e6xxx_serdes_get_lane(chip, port);
	if (!lane)
2350 2351 2352
		return 0;

	if (on) {
2353
		err = mv88e6xxx_serdes_power_up(chip, port, lane);
2354 2355 2356
		if (err)
			return err;

2357
		err = mv88e6xxx_serdes_irq_request(chip, port, lane);
2358
	} else {
2359 2360 2361
		err = mv88e6xxx_serdes_irq_free(chip, port, lane);
		if (err)
			return err;
2362

2363
		err = mv88e6xxx_serdes_power_down(chip, port, lane);
2364 2365 2366
	}

	return err;
2367 2368
}

2369 2370 2371 2372 2373 2374
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

2375
	upstream_port = dsa_upstream_port(ds, port);
2376 2377 2378 2379 2380 2381 2382
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398
	if (port == upstream_port) {
		if (chip->info->ops->set_cpu_port) {
			err = chip->info->ops->set_cpu_port(chip,
							    upstream_port);
			if (err)
				return err;
		}

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

2399 2400 2401
	return 0;
}

2402
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
2403
{
2404
	struct dsa_switch *ds = chip->ds;
2405
	int err;
2406
	u16 reg;
2407

2408 2409 2410
	chip->ports[port].chip = chip;
	chip->ports[port].port = port;

2411 2412 2413 2414 2415 2416 2417
	/* 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,
2418
					       PAUSE_OFF,
2419 2420 2421 2422
					       PHY_INTERFACE_MODE_NA);
	else
		err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
					       SPEED_UNFORCED, DUPLEX_UNFORCED,
2423
					       PAUSE_ON,
2424 2425 2426
					       PHY_INTERFACE_MODE_NA);
	if (err)
		return err;
2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441

	/* 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.
	 */
2442 2443 2444 2445
	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);
2446 2447
	if (err)
		return err;
2448

2449
	err = mv88e6xxx_setup_port_mode(chip, port);
2450 2451
	if (err)
		return err;
2452

2453
	err = mv88e6xxx_setup_egress_floods(chip, port);
2454 2455 2456
	if (err)
		return err;

2457
	/* Port Control 2: don't force a good FCS, set the maximum frame size to
2458
	 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
2459 2460 2461
	 * 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.
2462
	 */
2463 2464 2465
	err = mv88e6xxx_port_set_map_da(chip, port);
	if (err)
		return err;
2466

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

2471
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
2472
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
2473 2474 2475
	if (err)
		return err;

2476 2477
	if (chip->info->ops->port_set_jumbo_size) {
		err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
2478 2479 2480 2481
		if (err)
			return err;
	}

2482 2483 2484 2485 2486
	/* 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.
	 */
2487
	reg = 1 << port;
2488 2489
	/* Disable learning for CPU port */
	if (dsa_is_cpu_port(ds, port))
2490
		reg = 0;
2491

2492 2493
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
2494 2495
	if (err)
		return err;
2496 2497

	/* Egress rate control 2: disable egress rate control. */
2498 2499
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
				   0x0000);
2500 2501
	if (err)
		return err;
2502

2503 2504
	if (chip->info->ops->port_pause_limit) {
		err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
2505 2506
		if (err)
			return err;
2507
	}
2508

2509 2510 2511 2512 2513 2514
	if (chip->info->ops->port_disable_learn_limit) {
		err = chip->info->ops->port_disable_learn_limit(chip, port);
		if (err)
			return err;
	}

2515 2516
	if (chip->info->ops->port_disable_pri_override) {
		err = chip->info->ops->port_disable_pri_override(chip, port);
2517 2518
		if (err)
			return err;
2519
	}
2520

2521 2522
	if (chip->info->ops->port_tag_remap) {
		err = chip->info->ops->port_tag_remap(chip, port);
2523 2524
		if (err)
			return err;
2525 2526
	}

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

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

2539
	/* Port based VLAN map: give each port the same default address
2540 2541
	 * database, and allow bidirectional communication between the
	 * CPU and DSA port(s), and the other ports.
2542
	 */
2543
	err = mv88e6xxx_port_set_fid(chip, port, 0);
2544 2545
	if (err)
		return err;
2546

2547
	err = mv88e6xxx_port_vlan_map(chip, port);
2548 2549
	if (err)
		return err;
2550 2551 2552 2553

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

2557 2558 2559 2560
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
2561
	int err;
2562

2563
	mv88e6xxx_reg_lock(chip);
2564
	err = mv88e6xxx_serdes_power(chip, port, true);
2565
	mv88e6xxx_reg_unlock(chip);
2566 2567 2568 2569

	return err;
}

2570
static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port)
2571 2572 2573
{
	struct mv88e6xxx_chip *chip = ds->priv;

2574
	mv88e6xxx_reg_lock(chip);
2575 2576
	if (mv88e6xxx_serdes_power(chip, port, false))
		dev_err(chip->dev, "failed to power off SERDES\n");
2577
	mv88e6xxx_reg_unlock(chip);
2578 2579
}

2580 2581 2582
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
2583
	struct mv88e6xxx_chip *chip = ds->priv;
2584 2585
	int err;

2586
	mv88e6xxx_reg_lock(chip);
2587
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2588
	mv88e6xxx_reg_unlock(chip);
2589 2590 2591 2592

	return err;
}

2593
static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
2594
{
2595
	int err;
2596

2597
	/* Initialize the statistics unit */
2598 2599 2600 2601 2602
	if (chip->info->ops->stats_set_histogram) {
		err = chip->info->ops->stats_set_histogram(chip);
		if (err)
			return err;
	}
2603

2604
	return mv88e6xxx_g1_stats_clear(chip);
2605 2606
}

2607 2608 2609 2610 2611 2612 2613 2614
/* 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++) {
2615
		err = mv88e6xxx_port_hidden_read(chip, 0xf, port, 0, &val);
2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647
		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++) {
2648
		err = mv88e6xxx_port_hidden_write(chip, 0xf, port, 0, 0x01c0);
2649 2650 2651 2652 2653 2654 2655
		if (err)
			return err;
	}

	return mv88e6xxx_software_reset(chip);
}

2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727
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));
}

static void mv88e6xxx_teardown(struct dsa_switch *ds)
{
	mv88e6xxx_teardown_devlink_params(ds);
}

2728
static int mv88e6xxx_setup(struct dsa_switch *ds)
2729
{
V
Vivien Didelot 已提交
2730
	struct mv88e6xxx_chip *chip = ds->priv;
2731
	u8 cmode;
2732
	int err;
2733 2734
	int i;

2735
	chip->ds = ds;
2736
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
2737

2738
	mv88e6xxx_reg_lock(chip);
2739

2740 2741 2742 2743 2744 2745
	if (chip->info->ops->setup_errata) {
		err = chip->info->ops->setup_errata(chip);
		if (err)
			goto unlock;
	}

2746 2747 2748 2749 2750
	/* 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)
2751
				goto unlock;
2752 2753 2754 2755 2756

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

2757
	/* Setup Switch Port Registers */
2758
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2759 2760 2761
		if (dsa_is_unused_port(ds, i))
			continue;

2762
		/* Prevent the use of an invalid port. */
2763
		if (mv88e6xxx_is_invalid_port(chip, i)) {
2764 2765 2766 2767 2768
			dev_err(chip->dev, "port %d is invalid\n", i);
			err = -EINVAL;
			goto unlock;
		}

2769 2770 2771 2772 2773
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

2774 2775 2776 2777
	err = mv88e6xxx_irl_setup(chip);
	if (err)
		goto unlock;

2778 2779 2780 2781
	err = mv88e6xxx_mac_setup(chip);
	if (err)
		goto unlock;

2782 2783 2784 2785
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

2786 2787 2788 2789
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

2790 2791 2792 2793
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

2794 2795 2796 2797
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

2798 2799 2800 2801
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

2802 2803 2804 2805
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

2806 2807 2808 2809
	err = mv88e6xxx_rmu_setup(chip);
	if (err)
		goto unlock;

2810 2811 2812
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
2813

2814 2815 2816 2817
	err = mv88e6xxx_trunk_setup(chip);
	if (err)
		goto unlock;

2818 2819 2820 2821
	err = mv88e6xxx_devmap_setup(chip);
	if (err)
		goto unlock;

2822 2823 2824 2825
	err = mv88e6xxx_pri_setup(chip);
	if (err)
		goto unlock;

2826
	/* Setup PTP Hardware Clock and timestamping */
2827 2828 2829 2830
	if (chip->info->ptp_support) {
		err = mv88e6xxx_ptp_setup(chip);
		if (err)
			goto unlock;
2831 2832 2833 2834

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
2835 2836
	}

2837 2838 2839 2840
	err = mv88e6xxx_stats_setup(chip);
	if (err)
		goto unlock;

2841
unlock:
2842
	mv88e6xxx_reg_unlock(chip);
2843

2844 2845 2846 2847 2848
	/* Has to be called without holding the register lock, since
	 * it takes the devlink lock, and we later take the locks in
	 * the reverse order when getting/setting parameters.
	 */
	return mv88e6xxx_setup_devlink_params(ds);
2849 2850
}

2851
static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
2852
{
2853 2854
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2855 2856
	u16 val;
	int err;
2857

2858 2859 2860
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

2861
	mv88e6xxx_reg_lock(chip);
2862
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
2863
	mv88e6xxx_reg_unlock(chip);
2864

2865
	if (reg == MII_PHYSID2) {
2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881
		/* 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;
2882 2883
	}

2884
	return err ? err : val;
2885 2886
}

2887
static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
2888
{
2889 2890
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2891
	int err;
2892

2893 2894 2895
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

2896
	mv88e6xxx_reg_lock(chip);
2897
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
2898
	mv88e6xxx_reg_unlock(chip);
2899 2900

	return err;
2901 2902
}

2903
static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
2904 2905
				   struct device_node *np,
				   bool external)
2906 2907
{
	static int index;
2908
	struct mv88e6xxx_mdio_bus *mdio_bus;
2909 2910 2911
	struct mii_bus *bus;
	int err;

2912
	if (external) {
2913
		mv88e6xxx_reg_lock(chip);
2914
		err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
2915
		mv88e6xxx_reg_unlock(chip);
2916 2917 2918 2919 2920

		if (err)
			return err;
	}

2921
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
2922 2923 2924
	if (!bus)
		return -ENOMEM;

2925
	mdio_bus = bus->priv;
2926
	mdio_bus->bus = bus;
2927
	mdio_bus->chip = chip;
2928 2929
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
2930

2931 2932
	if (np) {
		bus->name = np->full_name;
2933
		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
2934 2935 2936 2937 2938 2939 2940
	} 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;
2941
	bus->parent = chip->dev;
2942

2943 2944 2945 2946 2947 2948
	if (!external) {
		err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
		if (err)
			return err;
	}

2949
	err = of_mdiobus_register(bus, np);
2950
	if (err) {
2951
		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
2952
		mv88e6xxx_g2_irq_mdio_free(chip, bus);
2953
		return err;
2954
	}
2955 2956 2957 2958 2959

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

	return 0;
2962
}
2963

2964 2965 2966 2967 2968
static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
	{ .compatible = "marvell,mv88e6xxx-mdio-external",
	  .data = (void *)true },
	{ },
};
2969

2970 2971 2972 2973 2974 2975 2976 2977 2978
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;

2979 2980 2981
		if (!mdio_bus->external)
			mv88e6xxx_g2_irq_mdio_free(chip, bus);

2982 2983 2984 2985
		mdiobus_unregister(bus);
	}
}

2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009
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);
3010 3011
			if (err) {
				mv88e6xxx_mdios_unregister(chip);
3012
				of_node_put(child);
3013
				return err;
3014
			}
3015 3016 3017 3018
		}
	}

	return 0;
3019 3020
}

3021 3022
static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
3023
	struct mv88e6xxx_chip *chip = ds->priv;
3024 3025 3026 3027 3028 3029 3030

	return chip->eeprom_len;
}

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

3034 3035
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
3036

3037
	mv88e6xxx_reg_lock(chip);
3038
	err = chip->info->ops->get_eeprom(chip, eeprom, data);
3039
	mv88e6xxx_reg_unlock(chip);
3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051

	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 已提交
3052
	struct mv88e6xxx_chip *chip = ds->priv;
3053 3054
	int err;

3055 3056 3057
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

3058 3059 3060
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

3061
	mv88e6xxx_reg_lock(chip);
3062
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
3063
	mv88e6xxx_reg_unlock(chip);
3064 3065 3066 3067

	return err;
}

3068
static const struct mv88e6xxx_ops mv88e6085_ops = {
3069
	/* MV88E6XXX_FAMILY_6097 */
3070 3071
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3072
	.irl_init_all = mv88e6352_g2_irl_init_all,
3073
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3074 3075
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3076
	.port_set_link = mv88e6xxx_port_set_link,
3077
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3078
	.port_set_speed = mv88e6185_port_set_speed,
3079
	.port_tag_remap = mv88e6095_port_tag_remap,
3080
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3081
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3082
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3083
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3084
	.port_pause_limit = mv88e6097_port_pause_limit,
3085
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3086
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3087
	.port_link_state = mv88e6352_port_link_state,
3088
	.port_get_cmode = mv88e6185_port_get_cmode,
3089
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3090
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3091
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3092 3093
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3094
	.stats_get_stats = mv88e6095_stats_get_stats,
3095 3096
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3097
	.watchdog_ops = &mv88e6097_watchdog_ops,
3098
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3099
	.pot_clear = mv88e6xxx_g2_pot_clear,
3100 3101
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
3102
	.reset = mv88e6185_g1_reset,
3103
	.rmu_disable = mv88e6085_g1_rmu_disable,
3104
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3105
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3106
	.phylink_validate = mv88e6185_phylink_validate,
3107 3108 3109
};

static const struct mv88e6xxx_ops mv88e6095_ops = {
3110
	/* MV88E6XXX_FAMILY_6095 */
3111 3112
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3113
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3114 3115
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3116
	.port_set_link = mv88e6xxx_port_set_link,
3117
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3118
	.port_set_speed = mv88e6185_port_set_speed,
3119
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
3120
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
3121
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
3122
	.port_link_state = mv88e6185_port_link_state,
3123
	.port_get_cmode = mv88e6185_port_get_cmode,
3124
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3125
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3126
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3127 3128
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3129
	.stats_get_stats = mv88e6095_stats_get_stats,
3130
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3131 3132
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
3133
	.reset = mv88e6185_g1_reset,
3134
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3135
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3136
	.phylink_validate = mv88e6185_phylink_validate,
3137 3138
};

3139
static const struct mv88e6xxx_ops mv88e6097_ops = {
3140
	/* MV88E6XXX_FAMILY_6097 */
3141 3142
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3143
	.irl_init_all = mv88e6352_g2_irl_init_all,
3144 3145 3146 3147 3148 3149
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_speed = mv88e6185_port_set_speed,
3150
	.port_tag_remap = mv88e6095_port_tag_remap,
3151
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3152
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3153
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3154
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3155
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
3156
	.port_pause_limit = mv88e6097_port_pause_limit,
3157
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3158
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3159
	.port_link_state = mv88e6352_port_link_state,
3160
	.port_get_cmode = mv88e6185_port_get_cmode,
3161
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3162
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3163
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3164 3165 3166
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
	.stats_get_stats = mv88e6095_stats_get_stats,
3167 3168
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3169
	.watchdog_ops = &mv88e6097_watchdog_ops,
3170
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3171
	.pot_clear = mv88e6xxx_g2_pot_clear,
3172
	.reset = mv88e6352_g1_reset,
3173
	.rmu_disable = mv88e6085_g1_rmu_disable,
3174
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3175
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3176
	.phylink_validate = mv88e6185_phylink_validate,
3177 3178
};

3179
static const struct mv88e6xxx_ops mv88e6123_ops = {
3180
	/* MV88E6XXX_FAMILY_6165 */
3181 3182
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3183
	.irl_init_all = mv88e6352_g2_irl_init_all,
3184
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3185 3186
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3187
	.port_set_link = mv88e6xxx_port_set_link,
3188
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3189
	.port_set_speed = mv88e6185_port_set_speed,
3190
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
3191
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3192
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3193
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3194
	.port_link_state = mv88e6352_port_link_state,
3195
	.port_get_cmode = mv88e6185_port_get_cmode,
3196
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3197
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3198
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3199 3200
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3201
	.stats_get_stats = mv88e6095_stats_get_stats,
3202 3203
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3204
	.watchdog_ops = &mv88e6097_watchdog_ops,
3205
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3206
	.pot_clear = mv88e6xxx_g2_pot_clear,
3207
	.reset = mv88e6352_g1_reset,
3208 3209
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3210
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3211
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3212
	.phylink_validate = mv88e6185_phylink_validate,
3213 3214 3215
};

static const struct mv88e6xxx_ops mv88e6131_ops = {
3216
	/* MV88E6XXX_FAMILY_6185 */
3217 3218
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3219
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3220 3221
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3222
	.port_set_link = mv88e6xxx_port_set_link,
3223
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3224
	.port_set_speed = mv88e6185_port_set_speed,
3225
	.port_tag_remap = mv88e6095_port_tag_remap,
3226
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3227
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
3228
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3229
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
3230
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3231
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3232
	.port_pause_limit = mv88e6097_port_pause_limit,
3233
	.port_set_pause = mv88e6185_port_set_pause,
3234
	.port_link_state = mv88e6352_port_link_state,
3235
	.port_get_cmode = mv88e6185_port_get_cmode,
3236
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3237
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3238
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3239 3240
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3241
	.stats_get_stats = mv88e6095_stats_get_stats,
3242 3243
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3244
	.watchdog_ops = &mv88e6097_watchdog_ops,
3245
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3246
	.ppu_enable = mv88e6185_g1_ppu_enable,
3247
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
3248
	.ppu_disable = mv88e6185_g1_ppu_disable,
3249
	.reset = mv88e6185_g1_reset,
3250
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3251
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3252
	.phylink_validate = mv88e6185_phylink_validate,
3253 3254
};

3255 3256
static const struct mv88e6xxx_ops mv88e6141_ops = {
	/* MV88E6XXX_FAMILY_6341 */
3257 3258
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3259
	.irl_init_all = mv88e6352_g2_irl_init_all,
3260 3261 3262 3263 3264 3265 3266 3267
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3268
	.port_set_speed = mv88e6341_port_set_speed,
3269
	.port_max_speed_mode = mv88e6341_port_max_speed_mode,
3270 3271 3272 3273
	.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,
3274
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3275
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3276
	.port_pause_limit = mv88e6097_port_pause_limit,
3277 3278
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3279
	.port_link_state = mv88e6352_port_link_state,
3280
	.port_get_cmode = mv88e6352_port_get_cmode,
3281
	.port_set_cmode = mv88e6341_port_set_cmode,
3282
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3283
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3284
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3285 3286 3287
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
3288 3289
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3290 3291
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
3292
	.pot_clear = mv88e6xxx_g2_pot_clear,
3293
	.reset = mv88e6352_g1_reset,
3294
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3295
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3296 3297
	.serdes_power = mv88e6390_serdes_power,
	.serdes_get_lane = mv88e6341_serdes_get_lane,
3298
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3299
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
3300
	.serdes_irq_status = mv88e6390_serdes_irq_status,
3301
	.gpio_ops = &mv88e6352_gpio_ops,
3302
	.phylink_validate = mv88e6341_phylink_validate,
3303 3304
};

3305
static const struct mv88e6xxx_ops mv88e6161_ops = {
3306
	/* MV88E6XXX_FAMILY_6165 */
3307 3308
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3309
	.irl_init_all = mv88e6352_g2_irl_init_all,
3310
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3311 3312
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3313
	.port_set_link = mv88e6xxx_port_set_link,
3314
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3315
	.port_set_speed = mv88e6185_port_set_speed,
3316
	.port_tag_remap = mv88e6095_port_tag_remap,
3317
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3318
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3319
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3320
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3321
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3322
	.port_pause_limit = mv88e6097_port_pause_limit,
3323
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3324
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3325
	.port_link_state = mv88e6352_port_link_state,
3326
	.port_get_cmode = mv88e6185_port_get_cmode,
3327
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3328
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3329
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3330 3331
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3332
	.stats_get_stats = mv88e6095_stats_get_stats,
3333 3334
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3335
	.watchdog_ops = &mv88e6097_watchdog_ops,
3336
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3337
	.pot_clear = mv88e6xxx_g2_pot_clear,
3338
	.reset = mv88e6352_g1_reset,
3339 3340
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3341
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3342
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3343
	.avb_ops = &mv88e6165_avb_ops,
3344
	.ptp_ops = &mv88e6165_ptp_ops,
3345
	.phylink_validate = mv88e6185_phylink_validate,
3346 3347 3348
};

static const struct mv88e6xxx_ops mv88e6165_ops = {
3349
	/* MV88E6XXX_FAMILY_6165 */
3350 3351
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3352
	.irl_init_all = mv88e6352_g2_irl_init_all,
3353
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3354 3355
	.phy_read = mv88e6165_phy_read,
	.phy_write = mv88e6165_phy_write,
3356
	.port_set_link = mv88e6xxx_port_set_link,
3357
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3358
	.port_set_speed = mv88e6185_port_set_speed,
3359
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3360
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3361
	.port_link_state = mv88e6352_port_link_state,
3362
	.port_get_cmode = mv88e6185_port_get_cmode,
3363
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3364
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3365
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3366 3367
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3368
	.stats_get_stats = mv88e6095_stats_get_stats,
3369 3370
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3371
	.watchdog_ops = &mv88e6097_watchdog_ops,
3372
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3373
	.pot_clear = mv88e6xxx_g2_pot_clear,
3374
	.reset = mv88e6352_g1_reset,
3375 3376
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3377
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3378
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3379
	.avb_ops = &mv88e6165_avb_ops,
3380
	.ptp_ops = &mv88e6165_ptp_ops,
3381
	.phylink_validate = mv88e6185_phylink_validate,
3382 3383 3384
};

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

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

static const struct mv88e6xxx_ops mv88e6175_ops = {
3476
	/* MV88E6XXX_FAMILY_6351 */
3477 3478
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3479
	.irl_init_all = mv88e6352_g2_irl_init_all,
3480
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3481 3482
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3483
	.port_set_link = mv88e6xxx_port_set_link,
3484
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3485
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3486
	.port_set_speed = mv88e6185_port_set_speed,
3487
	.port_tag_remap = mv88e6095_port_tag_remap,
3488
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3489
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3490
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3491
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3492
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3493
	.port_pause_limit = mv88e6097_port_pause_limit,
3494
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3495
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3496
	.port_link_state = mv88e6352_port_link_state,
3497
	.port_get_cmode = mv88e6352_port_get_cmode,
3498
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3499
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3500
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3501 3502
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3503
	.stats_get_stats = mv88e6095_stats_get_stats,
3504 3505
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3506
	.watchdog_ops = &mv88e6097_watchdog_ops,
3507
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3508
	.pot_clear = mv88e6xxx_g2_pot_clear,
3509
	.reset = mv88e6352_g1_reset,
3510 3511
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3512
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3513
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3514
	.phylink_validate = mv88e6185_phylink_validate,
3515 3516 3517
};

static const struct mv88e6xxx_ops mv88e6176_ops = {
3518
	/* MV88E6XXX_FAMILY_6352 */
3519 3520
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3521
	.irl_init_all = mv88e6352_g2_irl_init_all,
3522 3523
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3524
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3525 3526
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3527
	.port_set_link = mv88e6xxx_port_set_link,
3528
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3529
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3530
	.port_set_speed = mv88e6352_port_set_speed,
3531
	.port_tag_remap = mv88e6095_port_tag_remap,
3532
	.port_set_policy = mv88e6352_port_set_policy,
3533
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3534
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3535
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3536
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3537
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3538
	.port_pause_limit = mv88e6097_port_pause_limit,
3539
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3540
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3541
	.port_link_state = mv88e6352_port_link_state,
3542
	.port_get_cmode = mv88e6352_port_get_cmode,
3543
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3544
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3545
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3546 3547
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3548
	.stats_get_stats = mv88e6095_stats_get_stats,
3549 3550
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3551
	.watchdog_ops = &mv88e6097_watchdog_ops,
3552
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3553
	.pot_clear = mv88e6xxx_g2_pot_clear,
3554
	.reset = mv88e6352_g1_reset,
3555
	.rmu_disable = mv88e6352_g1_rmu_disable,
3556 3557
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3558
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3559
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3560
	.serdes_get_lane = mv88e6352_serdes_get_lane,
3561
	.serdes_power = mv88e6352_serdes_power,
3562
	.serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
3563
	.serdes_irq_enable = mv88e6352_serdes_irq_enable,
3564
	.serdes_irq_status = mv88e6352_serdes_irq_status,
3565
	.gpio_ops = &mv88e6352_gpio_ops,
3566
	.phylink_validate = mv88e6352_phylink_validate,
3567 3568 3569
};

static const struct mv88e6xxx_ops mv88e6185_ops = {
3570
	/* MV88E6XXX_FAMILY_6185 */
3571 3572
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3573
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3574 3575
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3576
	.port_set_link = mv88e6xxx_port_set_link,
3577
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3578
	.port_set_speed = mv88e6185_port_set_speed,
3579
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
3580
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
3581
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
3582
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
3583
	.port_set_pause = mv88e6185_port_set_pause,
3584
	.port_link_state = mv88e6185_port_link_state,
3585
	.port_get_cmode = mv88e6185_port_get_cmode,
3586
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3587
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3588
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3589 3590
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3591
	.stats_get_stats = mv88e6095_stats_get_stats,
3592 3593
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3594
	.watchdog_ops = &mv88e6097_watchdog_ops,
3595
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3596
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
3597 3598
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
3599
	.reset = mv88e6185_g1_reset,
3600
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3601
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3602
	.phylink_validate = mv88e6185_phylink_validate,
3603 3604
};

3605
static const struct mv88e6xxx_ops mv88e6190_ops = {
3606
	/* MV88E6XXX_FAMILY_6390 */
3607
	.setup_errata = mv88e6390_setup_errata,
3608
	.irl_init_all = mv88e6390_g2_irl_init_all,
3609 3610
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3611 3612 3613 3614 3615 3616 3617
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
	.port_set_speed = mv88e6390_port_set_speed,
3618
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
3619
	.port_tag_remap = mv88e6390_port_tag_remap,
3620
	.port_set_policy = mv88e6352_port_set_policy,
3621
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3622
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3623
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3624
	.port_pause_limit = mv88e6390_port_pause_limit,
3625
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3626
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3627
	.port_link_state = mv88e6352_port_link_state,
3628
	.port_get_cmode = mv88e6352_port_get_cmode,
3629
	.port_set_cmode = mv88e6390_port_set_cmode,
3630
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3631
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3632
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3633 3634
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3635
	.stats_get_stats = mv88e6390_stats_get_stats,
3636 3637
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3638
	.watchdog_ops = &mv88e6390_watchdog_ops,
3639
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3640
	.pot_clear = mv88e6xxx_g2_pot_clear,
3641
	.reset = mv88e6352_g1_reset,
3642
	.rmu_disable = mv88e6390_g1_rmu_disable,
3643 3644
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3645 3646
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3647
	.serdes_power = mv88e6390_serdes_power,
3648
	.serdes_get_lane = mv88e6390_serdes_get_lane,
3649
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3650
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
3651
	.serdes_irq_status = mv88e6390_serdes_irq_status,
3652
	.gpio_ops = &mv88e6352_gpio_ops,
3653
	.phylink_validate = mv88e6390_phylink_validate,
3654 3655 3656
};

static const struct mv88e6xxx_ops mv88e6190x_ops = {
3657
	/* MV88E6XXX_FAMILY_6390 */
3658
	.setup_errata = mv88e6390_setup_errata,
3659
	.irl_init_all = mv88e6390_g2_irl_init_all,
3660 3661
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3662 3663 3664 3665 3666 3667 3668
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
	.port_set_speed = mv88e6390x_port_set_speed,
3669
	.port_max_speed_mode = mv88e6390x_port_max_speed_mode,
3670
	.port_tag_remap = mv88e6390_port_tag_remap,
3671
	.port_set_policy = mv88e6352_port_set_policy,
3672
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3673
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3674
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3675
	.port_pause_limit = mv88e6390_port_pause_limit,
3676
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3677
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3678
	.port_link_state = mv88e6352_port_link_state,
3679
	.port_get_cmode = mv88e6352_port_get_cmode,
3680
	.port_set_cmode = mv88e6390x_port_set_cmode,
3681
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3682
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3683
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3684 3685
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3686
	.stats_get_stats = mv88e6390_stats_get_stats,
3687 3688
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3689
	.watchdog_ops = &mv88e6390_watchdog_ops,
3690
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3691
	.pot_clear = mv88e6xxx_g2_pot_clear,
3692
	.reset = mv88e6352_g1_reset,
3693
	.rmu_disable = mv88e6390_g1_rmu_disable,
3694 3695
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3696 3697
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3698
	.serdes_power = mv88e6390_serdes_power,
3699
	.serdes_get_lane = mv88e6390x_serdes_get_lane,
3700
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3701
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
3702
	.serdes_irq_status = mv88e6390_serdes_irq_status,
3703
	.gpio_ops = &mv88e6352_gpio_ops,
3704
	.phylink_validate = mv88e6390x_phylink_validate,
3705 3706 3707
};

static const struct mv88e6xxx_ops mv88e6191_ops = {
3708
	/* MV88E6XXX_FAMILY_6390 */
3709
	.setup_errata = mv88e6390_setup_errata,
3710
	.irl_init_all = mv88e6390_g2_irl_init_all,
3711 3712
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3713 3714 3715 3716 3717 3718 3719
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
	.port_set_speed = mv88e6390_port_set_speed,
3720
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
3721
	.port_tag_remap = mv88e6390_port_tag_remap,
3722
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3723
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3724
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3725
	.port_pause_limit = mv88e6390_port_pause_limit,
3726
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3727
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3728
	.port_link_state = mv88e6352_port_link_state,
3729
	.port_get_cmode = mv88e6352_port_get_cmode,
3730
	.port_set_cmode = mv88e6390_port_set_cmode,
3731
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3732
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3733
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3734 3735
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3736
	.stats_get_stats = mv88e6390_stats_get_stats,
3737 3738
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3739
	.watchdog_ops = &mv88e6390_watchdog_ops,
3740
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3741
	.pot_clear = mv88e6xxx_g2_pot_clear,
3742
	.reset = mv88e6352_g1_reset,
3743
	.rmu_disable = mv88e6390_g1_rmu_disable,
3744 3745
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3746 3747
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3748
	.serdes_power = mv88e6390_serdes_power,
3749
	.serdes_get_lane = mv88e6390_serdes_get_lane,
3750
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3751
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
3752
	.serdes_irq_status = mv88e6390_serdes_irq_status,
3753 3754
	.avb_ops = &mv88e6390_avb_ops,
	.ptp_ops = &mv88e6352_ptp_ops,
3755
	.phylink_validate = mv88e6390_phylink_validate,
3756 3757
};

3758
static const struct mv88e6xxx_ops mv88e6240_ops = {
3759
	/* MV88E6XXX_FAMILY_6352 */
3760 3761
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3762
	.irl_init_all = mv88e6352_g2_irl_init_all,
3763 3764
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3765
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3766 3767
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3768
	.port_set_link = mv88e6xxx_port_set_link,
3769
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3770
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3771
	.port_set_speed = mv88e6352_port_set_speed,
3772
	.port_tag_remap = mv88e6095_port_tag_remap,
3773
	.port_set_policy = mv88e6352_port_set_policy,
3774
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3775
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3776
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3777
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3778
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3779
	.port_pause_limit = mv88e6097_port_pause_limit,
3780
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3781
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3782
	.port_link_state = mv88e6352_port_link_state,
3783
	.port_get_cmode = mv88e6352_port_get_cmode,
3784
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3785
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3786
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3787 3788
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3789
	.stats_get_stats = mv88e6095_stats_get_stats,
3790 3791
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3792
	.watchdog_ops = &mv88e6097_watchdog_ops,
3793
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3794
	.pot_clear = mv88e6xxx_g2_pot_clear,
3795
	.reset = mv88e6352_g1_reset,
3796
	.rmu_disable = mv88e6352_g1_rmu_disable,
3797 3798
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3799
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3800
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3801
	.serdes_get_lane = mv88e6352_serdes_get_lane,
3802
	.serdes_power = mv88e6352_serdes_power,
3803
	.serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
3804
	.serdes_irq_enable = mv88e6352_serdes_irq_enable,
3805
	.serdes_irq_status = mv88e6352_serdes_irq_status,
3806
	.gpio_ops = &mv88e6352_gpio_ops,
3807
	.avb_ops = &mv88e6352_avb_ops,
3808
	.ptp_ops = &mv88e6352_ptp_ops,
3809
	.phylink_validate = mv88e6352_phylink_validate,
3810 3811
};

3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846
static const struct mv88e6xxx_ops mv88e6250_ops = {
	/* MV88E6XXX_FAMILY_6250 */
	.ieee_pri_map = mv88e6250_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
	.irl_init_all = mv88e6352_g2_irl_init_all,
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
	.port_set_speed = mv88e6250_port_set_speed,
	.port_tag_remap = mv88e6095_port_tag_remap,
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
	.port_set_ether_type = mv88e6351_port_set_ether_type,
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
	.port_pause_limit = mv88e6097_port_pause_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
	.port_link_state = mv88e6250_port_link_state,
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
	.stats_get_sset_count = mv88e6250_stats_get_sset_count,
	.stats_get_strings = mv88e6250_stats_get_strings,
	.stats_get_stats = mv88e6250_stats_get_stats,
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
	.watchdog_ops = &mv88e6250_watchdog_ops,
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
	.pot_clear = mv88e6xxx_g2_pot_clear,
	.reset = mv88e6250_g1_reset,
	.vtu_getnext = mv88e6250_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6250_g1_vtu_loadpurge,
3847 3848
	.avb_ops = &mv88e6352_avb_ops,
	.ptp_ops = &mv88e6250_ptp_ops,
3849 3850 3851
	.phylink_validate = mv88e6065_phylink_validate,
};

3852
static const struct mv88e6xxx_ops mv88e6290_ops = {
3853
	/* MV88E6XXX_FAMILY_6390 */
3854
	.setup_errata = mv88e6390_setup_errata,
3855
	.irl_init_all = mv88e6390_g2_irl_init_all,
3856 3857
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3858 3859 3860 3861 3862 3863 3864
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
	.port_set_speed = mv88e6390_port_set_speed,
3865
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
3866
	.port_tag_remap = mv88e6390_port_tag_remap,
3867
	.port_set_policy = mv88e6352_port_set_policy,
3868
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3869
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3870
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3871
	.port_pause_limit = mv88e6390_port_pause_limit,
3872
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3873
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3874
	.port_link_state = mv88e6352_port_link_state,
3875
	.port_get_cmode = mv88e6352_port_get_cmode,
3876
	.port_set_cmode = mv88e6390_port_set_cmode,
3877
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3878
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3879
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3880 3881
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3882
	.stats_get_stats = mv88e6390_stats_get_stats,
3883 3884
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3885
	.watchdog_ops = &mv88e6390_watchdog_ops,
3886
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3887
	.pot_clear = mv88e6xxx_g2_pot_clear,
3888
	.reset = mv88e6352_g1_reset,
3889
	.rmu_disable = mv88e6390_g1_rmu_disable,
3890 3891
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3892 3893
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3894
	.serdes_power = mv88e6390_serdes_power,
3895
	.serdes_get_lane = mv88e6390_serdes_get_lane,
3896
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3897
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
3898
	.serdes_irq_status = mv88e6390_serdes_irq_status,
3899
	.gpio_ops = &mv88e6352_gpio_ops,
3900
	.avb_ops = &mv88e6390_avb_ops,
3901
	.ptp_ops = &mv88e6352_ptp_ops,
3902
	.phylink_validate = mv88e6390_phylink_validate,
3903 3904
};

3905
static const struct mv88e6xxx_ops mv88e6320_ops = {
3906
	/* MV88E6XXX_FAMILY_6320 */
3907 3908
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3909
	.irl_init_all = mv88e6352_g2_irl_init_all,
3910 3911
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3912
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3913 3914
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3915
	.port_set_link = mv88e6xxx_port_set_link,
3916
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3917
	.port_set_speed = mv88e6185_port_set_speed,
3918
	.port_tag_remap = mv88e6095_port_tag_remap,
3919
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3920
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3921
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3922
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3923
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3924
	.port_pause_limit = mv88e6097_port_pause_limit,
3925
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3926
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3927
	.port_link_state = mv88e6352_port_link_state,
3928
	.port_get_cmode = mv88e6352_port_get_cmode,
3929
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3930
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3931
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3932 3933
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3934
	.stats_get_stats = mv88e6320_stats_get_stats,
3935 3936
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3937
	.watchdog_ops = &mv88e6390_watchdog_ops,
3938
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3939
	.pot_clear = mv88e6xxx_g2_pot_clear,
3940
	.reset = mv88e6352_g1_reset,
3941
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3942
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3943
	.gpio_ops = &mv88e6352_gpio_ops,
3944
	.avb_ops = &mv88e6352_avb_ops,
3945
	.ptp_ops = &mv88e6352_ptp_ops,
3946
	.phylink_validate = mv88e6185_phylink_validate,
3947 3948 3949
};

static const struct mv88e6xxx_ops mv88e6321_ops = {
3950
	/* MV88E6XXX_FAMILY_6320 */
3951 3952
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3953
	.irl_init_all = mv88e6352_g2_irl_init_all,
3954 3955
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3956
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3957 3958
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3959
	.port_set_link = mv88e6xxx_port_set_link,
3960
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3961
	.port_set_speed = mv88e6185_port_set_speed,
3962
	.port_tag_remap = mv88e6095_port_tag_remap,
3963
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3964
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3965
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3966
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3967
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3968
	.port_pause_limit = mv88e6097_port_pause_limit,
3969
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3970
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3971
	.port_link_state = mv88e6352_port_link_state,
3972
	.port_get_cmode = mv88e6352_port_get_cmode,
3973
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3974
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3975
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3976 3977
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3978
	.stats_get_stats = mv88e6320_stats_get_stats,
3979 3980
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3981
	.watchdog_ops = &mv88e6390_watchdog_ops,
3982
	.reset = mv88e6352_g1_reset,
3983
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3984
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3985
	.gpio_ops = &mv88e6352_gpio_ops,
3986
	.avb_ops = &mv88e6352_avb_ops,
3987
	.ptp_ops = &mv88e6352_ptp_ops,
3988
	.phylink_validate = mv88e6185_phylink_validate,
3989 3990
};

3991 3992
static const struct mv88e6xxx_ops mv88e6341_ops = {
	/* MV88E6XXX_FAMILY_6341 */
3993 3994
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3995
	.irl_init_all = mv88e6352_g2_irl_init_all,
3996 3997 3998 3999 4000 4001 4002 4003
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4004
	.port_set_speed = mv88e6341_port_set_speed,
4005
	.port_max_speed_mode = mv88e6341_port_max_speed_mode,
4006 4007 4008 4009
	.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,
4010
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4011
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4012
	.port_pause_limit = mv88e6097_port_pause_limit,
4013 4014
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4015
	.port_link_state = mv88e6352_port_link_state,
4016
	.port_get_cmode = mv88e6352_port_get_cmode,
4017
	.port_set_cmode = mv88e6341_port_set_cmode,
4018
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4019
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4020
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4021 4022 4023
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
4024 4025
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4026 4027
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
4028
	.pot_clear = mv88e6xxx_g2_pot_clear,
4029
	.reset = mv88e6352_g1_reset,
4030
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4031
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4032 4033
	.serdes_power = mv88e6390_serdes_power,
	.serdes_get_lane = mv88e6341_serdes_get_lane,
4034
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4035
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4036
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4037
	.gpio_ops = &mv88e6352_gpio_ops,
4038
	.avb_ops = &mv88e6390_avb_ops,
4039
	.ptp_ops = &mv88e6352_ptp_ops,
4040
	.phylink_validate = mv88e6341_phylink_validate,
4041 4042
};

4043
static const struct mv88e6xxx_ops mv88e6350_ops = {
4044
	/* MV88E6XXX_FAMILY_6351 */
4045 4046
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4047
	.irl_init_all = mv88e6352_g2_irl_init_all,
4048
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4049 4050
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4051
	.port_set_link = mv88e6xxx_port_set_link,
4052
	.port_set_duplex = mv88e6xxx_port_set_duplex,
4053
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4054
	.port_set_speed = mv88e6185_port_set_speed,
4055
	.port_tag_remap = mv88e6095_port_tag_remap,
4056
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4057
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4058
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4059
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4060
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4061
	.port_pause_limit = mv88e6097_port_pause_limit,
4062
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4063
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4064
	.port_link_state = mv88e6352_port_link_state,
4065
	.port_get_cmode = mv88e6352_port_get_cmode,
4066
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4067
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4068
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4069 4070
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
4071
	.stats_get_stats = mv88e6095_stats_get_stats,
4072 4073
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4074
	.watchdog_ops = &mv88e6097_watchdog_ops,
4075
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4076
	.pot_clear = mv88e6xxx_g2_pot_clear,
4077
	.reset = mv88e6352_g1_reset,
4078 4079
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4080
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4081
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4082
	.phylink_validate = mv88e6185_phylink_validate,
4083 4084 4085
};

static const struct mv88e6xxx_ops mv88e6351_ops = {
4086
	/* MV88E6XXX_FAMILY_6351 */
4087 4088
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4089
	.irl_init_all = mv88e6352_g2_irl_init_all,
4090
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4091 4092
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4093
	.port_set_link = mv88e6xxx_port_set_link,
4094
	.port_set_duplex = mv88e6xxx_port_set_duplex,
4095
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4096
	.port_set_speed = mv88e6185_port_set_speed,
4097
	.port_tag_remap = mv88e6095_port_tag_remap,
4098
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4099
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4100
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4101
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4102
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4103
	.port_pause_limit = mv88e6097_port_pause_limit,
4104
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4105
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4106
	.port_link_state = mv88e6352_port_link_state,
4107
	.port_get_cmode = mv88e6352_port_get_cmode,
4108
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4109
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4110
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4111 4112
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
4113
	.stats_get_stats = mv88e6095_stats_get_stats,
4114 4115
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4116
	.watchdog_ops = &mv88e6097_watchdog_ops,
4117
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4118
	.pot_clear = mv88e6xxx_g2_pot_clear,
4119
	.reset = mv88e6352_g1_reset,
4120 4121
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4122
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4123
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4124
	.avb_ops = &mv88e6352_avb_ops,
4125
	.ptp_ops = &mv88e6352_ptp_ops,
4126
	.phylink_validate = mv88e6185_phylink_validate,
4127 4128 4129
};

static const struct mv88e6xxx_ops mv88e6352_ops = {
4130
	/* MV88E6XXX_FAMILY_6352 */
4131 4132
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4133
	.irl_init_all = mv88e6352_g2_irl_init_all,
4134 4135
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
4136
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4137 4138
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4139
	.port_set_link = mv88e6xxx_port_set_link,
4140
	.port_set_duplex = mv88e6xxx_port_set_duplex,
4141
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4142
	.port_set_speed = mv88e6352_port_set_speed,
4143
	.port_tag_remap = mv88e6095_port_tag_remap,
4144
	.port_set_policy = mv88e6352_port_set_policy,
4145
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4146
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4147
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4148
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4149
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4150
	.port_pause_limit = mv88e6097_port_pause_limit,
4151
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4152
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4153
	.port_link_state = mv88e6352_port_link_state,
4154
	.port_get_cmode = mv88e6352_port_get_cmode,
4155
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4156
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4157
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4158 4159
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
4160
	.stats_get_stats = mv88e6095_stats_get_stats,
4161 4162
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4163
	.watchdog_ops = &mv88e6097_watchdog_ops,
4164
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4165
	.pot_clear = mv88e6xxx_g2_pot_clear,
4166
	.reset = mv88e6352_g1_reset,
4167
	.rmu_disable = mv88e6352_g1_rmu_disable,
4168 4169
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4170
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4171
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4172
	.serdes_get_lane = mv88e6352_serdes_get_lane,
4173
	.serdes_power = mv88e6352_serdes_power,
4174
	.serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
4175
	.serdes_irq_enable = mv88e6352_serdes_irq_enable,
4176
	.serdes_irq_status = mv88e6352_serdes_irq_status,
4177
	.gpio_ops = &mv88e6352_gpio_ops,
4178
	.avb_ops = &mv88e6352_avb_ops,
4179
	.ptp_ops = &mv88e6352_ptp_ops,
4180 4181 4182
	.serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
	.serdes_get_strings = mv88e6352_serdes_get_strings,
	.serdes_get_stats = mv88e6352_serdes_get_stats,
4183
	.phylink_validate = mv88e6352_phylink_validate,
4184 4185
};

4186
static const struct mv88e6xxx_ops mv88e6390_ops = {
4187
	/* MV88E6XXX_FAMILY_6390 */
4188
	.setup_errata = mv88e6390_setup_errata,
4189
	.irl_init_all = mv88e6390_g2_irl_init_all,
4190 4191
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4192 4193 4194 4195 4196 4197 4198
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
	.port_set_speed = mv88e6390_port_set_speed,
4199
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
4200
	.port_tag_remap = mv88e6390_port_tag_remap,
4201
	.port_set_policy = mv88e6352_port_set_policy,
4202
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4203
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4204
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4205
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4206
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4207
	.port_pause_limit = mv88e6390_port_pause_limit,
4208
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4209
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4210
	.port_link_state = mv88e6352_port_link_state,
4211
	.port_get_cmode = mv88e6352_port_get_cmode,
4212
	.port_set_cmode = mv88e6390_port_set_cmode,
4213
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4214
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4215
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4216 4217
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4218
	.stats_get_stats = mv88e6390_stats_get_stats,
4219 4220
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4221
	.watchdog_ops = &mv88e6390_watchdog_ops,
4222
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4223
	.pot_clear = mv88e6xxx_g2_pot_clear,
4224
	.reset = mv88e6352_g1_reset,
4225
	.rmu_disable = mv88e6390_g1_rmu_disable,
4226 4227
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4228 4229
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4230
	.serdes_power = mv88e6390_serdes_power,
4231
	.serdes_get_lane = mv88e6390_serdes_get_lane,
4232
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4233
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4234
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4235
	.gpio_ops = &mv88e6352_gpio_ops,
4236
	.avb_ops = &mv88e6390_avb_ops,
4237
	.ptp_ops = &mv88e6352_ptp_ops,
4238
	.phylink_validate = mv88e6390_phylink_validate,
4239 4240 4241
};

static const struct mv88e6xxx_ops mv88e6390x_ops = {
4242
	/* MV88E6XXX_FAMILY_6390 */
4243
	.setup_errata = mv88e6390_setup_errata,
4244
	.irl_init_all = mv88e6390_g2_irl_init_all,
4245 4246
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4247 4248 4249 4250 4251 4252 4253
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
	.port_set_speed = mv88e6390x_port_set_speed,
4254
	.port_max_speed_mode = mv88e6390x_port_max_speed_mode,
4255
	.port_tag_remap = mv88e6390_port_tag_remap,
4256
	.port_set_policy = mv88e6352_port_set_policy,
4257
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4258
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4259
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4260
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4261
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4262
	.port_pause_limit = mv88e6390_port_pause_limit,
4263
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4264
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4265
	.port_link_state = mv88e6352_port_link_state,
4266
	.port_get_cmode = mv88e6352_port_get_cmode,
4267
	.port_set_cmode = mv88e6390x_port_set_cmode,
4268
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4269
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4270
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4271 4272
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4273
	.stats_get_stats = mv88e6390_stats_get_stats,
4274 4275
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4276
	.watchdog_ops = &mv88e6390_watchdog_ops,
4277
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4278
	.pot_clear = mv88e6xxx_g2_pot_clear,
4279
	.reset = mv88e6352_g1_reset,
4280
	.rmu_disable = mv88e6390_g1_rmu_disable,
4281 4282
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4283 4284
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4285
	.serdes_power = mv88e6390_serdes_power,
4286
	.serdes_get_lane = mv88e6390x_serdes_get_lane,
4287
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4288
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4289
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4290
	.gpio_ops = &mv88e6352_gpio_ops,
4291
	.avb_ops = &mv88e6390_avb_ops,
4292
	.ptp_ops = &mv88e6352_ptp_ops,
4293
	.phylink_validate = mv88e6390x_phylink_validate,
4294 4295
};

4296 4297
static const struct mv88e6xxx_info mv88e6xxx_table[] = {
	[MV88E6085] = {
4298
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
4299 4300 4301
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6085",
		.num_databases = 4096,
4302
		.num_macs = 8192,
4303
		.num_ports = 10,
4304
		.num_internal_phys = 5,
4305
		.max_vid = 4095,
4306
		.port_base_addr = 0x10,
4307
		.phy_base_addr = 0x0,
4308
		.global1_addr = 0x1b,
4309
		.global2_addr = 0x1c,
4310
		.age_time_coeff = 15000,
4311
		.g1_irqs = 8,
4312
		.g2_irqs = 10,
4313
		.atu_move_port_mask = 0xf,
4314
		.pvt = true,
4315
		.multi_chip = true,
4316
		.tag_protocol = DSA_TAG_PROTO_DSA,
4317
		.ops = &mv88e6085_ops,
4318 4319 4320
	},

	[MV88E6095] = {
4321
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
4322 4323 4324
		.family = MV88E6XXX_FAMILY_6095,
		.name = "Marvell 88E6095/88E6095F",
		.num_databases = 256,
4325
		.num_macs = 8192,
4326
		.num_ports = 11,
4327
		.num_internal_phys = 0,
4328
		.max_vid = 4095,
4329
		.port_base_addr = 0x10,
4330
		.phy_base_addr = 0x0,
4331
		.global1_addr = 0x1b,
4332
		.global2_addr = 0x1c,
4333
		.age_time_coeff = 15000,
4334
		.g1_irqs = 8,
4335
		.atu_move_port_mask = 0xf,
4336
		.multi_chip = true,
4337
		.tag_protocol = DSA_TAG_PROTO_DSA,
4338
		.ops = &mv88e6095_ops,
4339 4340
	},

4341
	[MV88E6097] = {
4342
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
4343 4344 4345
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6097/88E6097F",
		.num_databases = 4096,
4346
		.num_macs = 8192,
4347
		.num_ports = 11,
4348
		.num_internal_phys = 8,
4349
		.max_vid = 4095,
4350
		.port_base_addr = 0x10,
4351
		.phy_base_addr = 0x0,
4352
		.global1_addr = 0x1b,
4353
		.global2_addr = 0x1c,
4354
		.age_time_coeff = 15000,
4355
		.g1_irqs = 8,
4356
		.g2_irqs = 10,
4357
		.atu_move_port_mask = 0xf,
4358
		.pvt = true,
4359
		.multi_chip = true,
4360
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4361 4362 4363
		.ops = &mv88e6097_ops,
	},

4364
	[MV88E6123] = {
4365
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
4366 4367 4368
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6123",
		.num_databases = 4096,
4369
		.num_macs = 1024,
4370
		.num_ports = 3,
4371
		.num_internal_phys = 5,
4372
		.max_vid = 4095,
4373
		.port_base_addr = 0x10,
4374
		.phy_base_addr = 0x0,
4375
		.global1_addr = 0x1b,
4376
		.global2_addr = 0x1c,
4377
		.age_time_coeff = 15000,
4378
		.g1_irqs = 9,
4379
		.g2_irqs = 10,
4380
		.atu_move_port_mask = 0xf,
4381
		.pvt = true,
4382
		.multi_chip = true,
4383
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4384
		.ops = &mv88e6123_ops,
4385 4386 4387
	},

	[MV88E6131] = {
4388
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
4389 4390 4391
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6131",
		.num_databases = 256,
4392
		.num_macs = 8192,
4393
		.num_ports = 8,
4394
		.num_internal_phys = 0,
4395
		.max_vid = 4095,
4396
		.port_base_addr = 0x10,
4397
		.phy_base_addr = 0x0,
4398
		.global1_addr = 0x1b,
4399
		.global2_addr = 0x1c,
4400
		.age_time_coeff = 15000,
4401
		.g1_irqs = 9,
4402
		.atu_move_port_mask = 0xf,
4403
		.multi_chip = true,
4404
		.tag_protocol = DSA_TAG_PROTO_DSA,
4405
		.ops = &mv88e6131_ops,
4406 4407
	},

4408
	[MV88E6141] = {
4409
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
4410
		.family = MV88E6XXX_FAMILY_6341,
4411
		.name = "Marvell 88E6141",
4412
		.num_databases = 4096,
4413
		.num_macs = 2048,
4414
		.num_ports = 6,
4415
		.num_internal_phys = 5,
4416
		.num_gpio = 11,
4417
		.max_vid = 4095,
4418
		.port_base_addr = 0x10,
4419
		.phy_base_addr = 0x10,
4420
		.global1_addr = 0x1b,
4421
		.global2_addr = 0x1c,
4422 4423
		.age_time_coeff = 3750,
		.atu_move_port_mask = 0x1f,
4424
		.g1_irqs = 9,
4425
		.g2_irqs = 10,
4426
		.pvt = true,
4427
		.multi_chip = true,
4428 4429 4430 4431
		.tag_protocol = DSA_TAG_PROTO_EDSA,
		.ops = &mv88e6141_ops,
	},

4432
	[MV88E6161] = {
4433
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
4434 4435 4436
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6161",
		.num_databases = 4096,
4437
		.num_macs = 1024,
4438
		.num_ports = 6,
4439
		.num_internal_phys = 5,
4440
		.max_vid = 4095,
4441
		.port_base_addr = 0x10,
4442
		.phy_base_addr = 0x0,
4443
		.global1_addr = 0x1b,
4444
		.global2_addr = 0x1c,
4445
		.age_time_coeff = 15000,
4446
		.g1_irqs = 9,
4447
		.g2_irqs = 10,
4448
		.atu_move_port_mask = 0xf,
4449
		.pvt = true,
4450
		.multi_chip = true,
4451
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4452
		.ptp_support = true,
4453
		.ops = &mv88e6161_ops,
4454 4455 4456
	},

	[MV88E6165] = {
4457
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
4458 4459 4460
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6165",
		.num_databases = 4096,
4461
		.num_macs = 8192,
4462
		.num_ports = 6,
4463
		.num_internal_phys = 0,
4464
		.max_vid = 4095,
4465
		.port_base_addr = 0x10,
4466
		.phy_base_addr = 0x0,
4467
		.global1_addr = 0x1b,
4468
		.global2_addr = 0x1c,
4469
		.age_time_coeff = 15000,
4470
		.g1_irqs = 9,
4471
		.g2_irqs = 10,
4472
		.atu_move_port_mask = 0xf,
4473
		.pvt = true,
4474
		.multi_chip = true,
4475
		.tag_protocol = DSA_TAG_PROTO_DSA,
4476
		.ptp_support = true,
4477
		.ops = &mv88e6165_ops,
4478 4479 4480
	},

	[MV88E6171] = {
4481
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
4482 4483 4484
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6171",
		.num_databases = 4096,
4485
		.num_macs = 8192,
4486
		.num_ports = 7,
4487
		.num_internal_phys = 5,
4488
		.max_vid = 4095,
4489
		.port_base_addr = 0x10,
4490
		.phy_base_addr = 0x0,
4491
		.global1_addr = 0x1b,
4492
		.global2_addr = 0x1c,
4493
		.age_time_coeff = 15000,
4494
		.g1_irqs = 9,
4495
		.g2_irqs = 10,
4496
		.atu_move_port_mask = 0xf,
4497
		.pvt = true,
4498
		.multi_chip = true,
4499
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4500
		.ops = &mv88e6171_ops,
4501 4502 4503
	},

	[MV88E6172] = {
4504
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
4505 4506 4507
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6172",
		.num_databases = 4096,
4508
		.num_macs = 8192,
4509
		.num_ports = 7,
4510
		.num_internal_phys = 5,
4511
		.num_gpio = 15,
4512
		.max_vid = 4095,
4513
		.port_base_addr = 0x10,
4514
		.phy_base_addr = 0x0,
4515
		.global1_addr = 0x1b,
4516
		.global2_addr = 0x1c,
4517
		.age_time_coeff = 15000,
4518
		.g1_irqs = 9,
4519
		.g2_irqs = 10,
4520
		.atu_move_port_mask = 0xf,
4521
		.pvt = true,
4522
		.multi_chip = true,
4523
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4524
		.ops = &mv88e6172_ops,
4525 4526 4527
	},

	[MV88E6175] = {
4528
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
4529 4530 4531
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6175",
		.num_databases = 4096,
4532
		.num_macs = 8192,
4533
		.num_ports = 7,
4534
		.num_internal_phys = 5,
4535
		.max_vid = 4095,
4536
		.port_base_addr = 0x10,
4537
		.phy_base_addr = 0x0,
4538
		.global1_addr = 0x1b,
4539
		.global2_addr = 0x1c,
4540
		.age_time_coeff = 15000,
4541
		.g1_irqs = 9,
4542
		.g2_irqs = 10,
4543
		.atu_move_port_mask = 0xf,
4544
		.pvt = true,
4545
		.multi_chip = true,
4546
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4547
		.ops = &mv88e6175_ops,
4548 4549 4550
	},

	[MV88E6176] = {
4551
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
4552 4553 4554
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6176",
		.num_databases = 4096,
4555
		.num_macs = 8192,
4556
		.num_ports = 7,
4557
		.num_internal_phys = 5,
4558
		.num_gpio = 15,
4559
		.max_vid = 4095,
4560
		.port_base_addr = 0x10,
4561
		.phy_base_addr = 0x0,
4562
		.global1_addr = 0x1b,
4563
		.global2_addr = 0x1c,
4564
		.age_time_coeff = 15000,
4565
		.g1_irqs = 9,
4566
		.g2_irqs = 10,
4567
		.atu_move_port_mask = 0xf,
4568
		.pvt = true,
4569
		.multi_chip = true,
4570
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4571
		.ops = &mv88e6176_ops,
4572 4573 4574
	},

	[MV88E6185] = {
4575
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
4576 4577 4578
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6185",
		.num_databases = 256,
4579
		.num_macs = 8192,
4580
		.num_ports = 10,
4581
		.num_internal_phys = 0,
4582
		.max_vid = 4095,
4583
		.port_base_addr = 0x10,
4584
		.phy_base_addr = 0x0,
4585
		.global1_addr = 0x1b,
4586
		.global2_addr = 0x1c,
4587
		.age_time_coeff = 15000,
4588
		.g1_irqs = 8,
4589
		.atu_move_port_mask = 0xf,
4590
		.multi_chip = true,
4591
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4592
		.ops = &mv88e6185_ops,
4593 4594
	},

4595
	[MV88E6190] = {
4596
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
4597 4598 4599
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190",
		.num_databases = 4096,
4600
		.num_macs = 16384,
4601
		.num_ports = 11,	/* 10 + Z80 */
4602
		.num_internal_phys = 9,
4603
		.num_gpio = 16,
4604
		.max_vid = 8191,
4605
		.port_base_addr = 0x0,
4606
		.phy_base_addr = 0x0,
4607
		.global1_addr = 0x1b,
4608
		.global2_addr = 0x1c,
4609
		.tag_protocol = DSA_TAG_PROTO_DSA,
4610
		.age_time_coeff = 3750,
4611
		.g1_irqs = 9,
4612
		.g2_irqs = 14,
4613
		.pvt = true,
4614
		.multi_chip = true,
4615
		.atu_move_port_mask = 0x1f,
4616 4617 4618 4619
		.ops = &mv88e6190_ops,
	},

	[MV88E6190X] = {
4620
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
4621 4622 4623
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190X",
		.num_databases = 4096,
4624
		.num_macs = 16384,
4625
		.num_ports = 11,	/* 10 + Z80 */
4626
		.num_internal_phys = 9,
4627
		.num_gpio = 16,
4628
		.max_vid = 8191,
4629
		.port_base_addr = 0x0,
4630
		.phy_base_addr = 0x0,
4631
		.global1_addr = 0x1b,
4632
		.global2_addr = 0x1c,
4633
		.age_time_coeff = 3750,
4634
		.g1_irqs = 9,
4635
		.g2_irqs = 14,
4636
		.atu_move_port_mask = 0x1f,
4637
		.pvt = true,
4638
		.multi_chip = true,
4639
		.tag_protocol = DSA_TAG_PROTO_DSA,
4640 4641 4642 4643
		.ops = &mv88e6190x_ops,
	},

	[MV88E6191] = {
4644
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
4645 4646 4647
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6191",
		.num_databases = 4096,
4648
		.num_macs = 16384,
4649
		.num_ports = 11,	/* 10 + Z80 */
4650
		.num_internal_phys = 9,
4651
		.max_vid = 8191,
4652
		.port_base_addr = 0x0,
4653
		.phy_base_addr = 0x0,
4654
		.global1_addr = 0x1b,
4655
		.global2_addr = 0x1c,
4656
		.age_time_coeff = 3750,
4657
		.g1_irqs = 9,
4658
		.g2_irqs = 14,
4659
		.atu_move_port_mask = 0x1f,
4660
		.pvt = true,
4661
		.multi_chip = true,
4662
		.tag_protocol = DSA_TAG_PROTO_DSA,
4663
		.ptp_support = true,
4664
		.ops = &mv88e6191_ops,
4665 4666
	},

4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677
	[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,
4678
		.invalid_port_mask = BIT(2) | BIT(3) | BIT(4),
4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689
		.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,
4690
		.ptp_support = true,
4691 4692 4693
		.ops = &mv88e6250_ops,
	},

4694
	[MV88E6240] = {
4695
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
4696 4697 4698
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6240",
		.num_databases = 4096,
4699
		.num_macs = 8192,
4700
		.num_ports = 7,
4701
		.num_internal_phys = 5,
4702
		.num_gpio = 15,
4703
		.max_vid = 4095,
4704
		.port_base_addr = 0x10,
4705
		.phy_base_addr = 0x0,
4706
		.global1_addr = 0x1b,
4707
		.global2_addr = 0x1c,
4708
		.age_time_coeff = 15000,
4709
		.g1_irqs = 9,
4710
		.g2_irqs = 10,
4711
		.atu_move_port_mask = 0xf,
4712
		.pvt = true,
4713
		.multi_chip = true,
4714
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4715
		.ptp_support = true,
4716
		.ops = &mv88e6240_ops,
4717 4718
	},

4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736
	[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,
4737
		.ptp_support = true,
4738 4739 4740
		.ops = &mv88e6250_ops,
	},

4741
	[MV88E6290] = {
4742
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
4743 4744 4745 4746
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6290",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4747
		.num_internal_phys = 9,
4748
		.num_gpio = 16,
4749
		.max_vid = 8191,
4750
		.port_base_addr = 0x0,
4751
		.phy_base_addr = 0x0,
4752
		.global1_addr = 0x1b,
4753
		.global2_addr = 0x1c,
4754
		.age_time_coeff = 3750,
4755
		.g1_irqs = 9,
4756
		.g2_irqs = 14,
4757
		.atu_move_port_mask = 0x1f,
4758
		.pvt = true,
4759
		.multi_chip = true,
4760
		.tag_protocol = DSA_TAG_PROTO_DSA,
4761
		.ptp_support = true,
4762 4763 4764
		.ops = &mv88e6290_ops,
	},

4765
	[MV88E6320] = {
4766
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
4767 4768 4769
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6320",
		.num_databases = 4096,
4770
		.num_macs = 8192,
4771
		.num_ports = 7,
4772
		.num_internal_phys = 5,
4773
		.num_gpio = 15,
4774
		.max_vid = 4095,
4775
		.port_base_addr = 0x10,
4776
		.phy_base_addr = 0x0,
4777
		.global1_addr = 0x1b,
4778
		.global2_addr = 0x1c,
4779
		.age_time_coeff = 15000,
4780
		.g1_irqs = 8,
4781
		.g2_irqs = 10,
4782
		.atu_move_port_mask = 0xf,
4783
		.pvt = true,
4784
		.multi_chip = true,
4785
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4786
		.ptp_support = true,
4787
		.ops = &mv88e6320_ops,
4788 4789 4790
	},

	[MV88E6321] = {
4791
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
4792 4793 4794
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6321",
		.num_databases = 4096,
4795
		.num_macs = 8192,
4796
		.num_ports = 7,
4797
		.num_internal_phys = 5,
4798
		.num_gpio = 15,
4799
		.max_vid = 4095,
4800
		.port_base_addr = 0x10,
4801
		.phy_base_addr = 0x0,
4802
		.global1_addr = 0x1b,
4803
		.global2_addr = 0x1c,
4804
		.age_time_coeff = 15000,
4805
		.g1_irqs = 8,
4806
		.g2_irqs = 10,
4807
		.atu_move_port_mask = 0xf,
4808
		.multi_chip = true,
4809
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4810
		.ptp_support = true,
4811
		.ops = &mv88e6321_ops,
4812 4813
	},

4814
	[MV88E6341] = {
4815
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
4816 4817 4818
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
4819
		.num_macs = 2048,
4820
		.num_internal_phys = 5,
4821
		.num_ports = 6,
4822
		.num_gpio = 11,
4823
		.max_vid = 4095,
4824
		.port_base_addr = 0x10,
4825
		.phy_base_addr = 0x10,
4826
		.global1_addr = 0x1b,
4827
		.global2_addr = 0x1c,
4828
		.age_time_coeff = 3750,
4829
		.atu_move_port_mask = 0x1f,
4830
		.g1_irqs = 9,
4831
		.g2_irqs = 10,
4832
		.pvt = true,
4833
		.multi_chip = true,
4834
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4835
		.ptp_support = true,
4836 4837 4838
		.ops = &mv88e6341_ops,
	},

4839
	[MV88E6350] = {
4840
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
4841 4842 4843
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6350",
		.num_databases = 4096,
4844
		.num_macs = 8192,
4845
		.num_ports = 7,
4846
		.num_internal_phys = 5,
4847
		.max_vid = 4095,
4848
		.port_base_addr = 0x10,
4849
		.phy_base_addr = 0x0,
4850
		.global1_addr = 0x1b,
4851
		.global2_addr = 0x1c,
4852
		.age_time_coeff = 15000,
4853
		.g1_irqs = 9,
4854
		.g2_irqs = 10,
4855
		.atu_move_port_mask = 0xf,
4856
		.pvt = true,
4857
		.multi_chip = true,
4858
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4859
		.ops = &mv88e6350_ops,
4860 4861 4862
	},

	[MV88E6351] = {
4863
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
4864 4865 4866
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6351",
		.num_databases = 4096,
4867
		.num_macs = 8192,
4868
		.num_ports = 7,
4869
		.num_internal_phys = 5,
4870
		.max_vid = 4095,
4871
		.port_base_addr = 0x10,
4872
		.phy_base_addr = 0x0,
4873
		.global1_addr = 0x1b,
4874
		.global2_addr = 0x1c,
4875
		.age_time_coeff = 15000,
4876
		.g1_irqs = 9,
4877
		.g2_irqs = 10,
4878
		.atu_move_port_mask = 0xf,
4879
		.pvt = true,
4880
		.multi_chip = true,
4881
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4882
		.ops = &mv88e6351_ops,
4883 4884 4885
	},

	[MV88E6352] = {
4886
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
4887 4888 4889
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6352",
		.num_databases = 4096,
4890
		.num_macs = 8192,
4891
		.num_ports = 7,
4892
		.num_internal_phys = 5,
4893
		.num_gpio = 15,
4894
		.max_vid = 4095,
4895
		.port_base_addr = 0x10,
4896
		.phy_base_addr = 0x0,
4897
		.global1_addr = 0x1b,
4898
		.global2_addr = 0x1c,
4899
		.age_time_coeff = 15000,
4900
		.g1_irqs = 9,
4901
		.g2_irqs = 10,
4902
		.atu_move_port_mask = 0xf,
4903
		.pvt = true,
4904
		.multi_chip = true,
4905
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4906
		.ptp_support = true,
4907
		.ops = &mv88e6352_ops,
4908
	},
4909
	[MV88E6390] = {
4910
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
4911 4912 4913
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390",
		.num_databases = 4096,
4914
		.num_macs = 16384,
4915
		.num_ports = 11,	/* 10 + Z80 */
4916
		.num_internal_phys = 9,
4917
		.num_gpio = 16,
4918
		.max_vid = 8191,
4919
		.port_base_addr = 0x0,
4920
		.phy_base_addr = 0x0,
4921
		.global1_addr = 0x1b,
4922
		.global2_addr = 0x1c,
4923
		.age_time_coeff = 3750,
4924
		.g1_irqs = 9,
4925
		.g2_irqs = 14,
4926
		.atu_move_port_mask = 0x1f,
4927
		.pvt = true,
4928
		.multi_chip = true,
4929
		.tag_protocol = DSA_TAG_PROTO_DSA,
4930
		.ptp_support = true,
4931 4932 4933
		.ops = &mv88e6390_ops,
	},
	[MV88E6390X] = {
4934
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
4935 4936 4937
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390X",
		.num_databases = 4096,
4938
		.num_macs = 16384,
4939
		.num_ports = 11,	/* 10 + Z80 */
4940
		.num_internal_phys = 9,
4941
		.num_gpio = 16,
4942
		.max_vid = 8191,
4943
		.port_base_addr = 0x0,
4944
		.phy_base_addr = 0x0,
4945
		.global1_addr = 0x1b,
4946
		.global2_addr = 0x1c,
4947
		.age_time_coeff = 3750,
4948
		.g1_irqs = 9,
4949
		.g2_irqs = 14,
4950
		.atu_move_port_mask = 0x1f,
4951
		.pvt = true,
4952
		.multi_chip = true,
4953
		.tag_protocol = DSA_TAG_PROTO_DSA,
4954
		.ptp_support = true,
4955 4956
		.ops = &mv88e6390x_ops,
	},
4957 4958
};

4959
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
4960
{
4961
	int i;
4962

4963 4964 4965
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
4966 4967 4968 4969

	return NULL;
}

4970
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
4971 4972
{
	const struct mv88e6xxx_info *info;
4973 4974 4975
	unsigned int prod_num, rev;
	u16 id;
	int err;
4976

4977
	mv88e6xxx_reg_lock(chip);
4978
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
4979
	mv88e6xxx_reg_unlock(chip);
4980 4981
	if (err)
		return err;
4982

4983 4984
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
4985 4986 4987 4988 4989

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

4990
	/* Update the compatible info with the probed one */
4991
	chip->info = info;
4992

4993 4994 4995 4996
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

4997 4998
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
4999 5000 5001 5002

	return 0;
}

5003
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
5004
{
5005
	struct mv88e6xxx_chip *chip;
5006

5007 5008
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
5009 5010
		return NULL;

5011
	chip->dev = dev;
5012

5013
	mutex_init(&chip->reg_lock);
5014
	INIT_LIST_HEAD(&chip->mdios);
5015
	idr_init(&chip->policies);
5016

5017
	return chip;
5018 5019
}

5020 5021
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
							int port)
5022
{
V
Vivien Didelot 已提交
5023
	struct mv88e6xxx_chip *chip = ds->priv;
5024

5025
	return chip->info->tag_protocol;
5026 5027
}

5028
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
5029
				      const struct switchdev_obj_port_mdb *mdb)
5030 5031 5032 5033 5034 5035 5036 5037 5038
{
	/* 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,
5039
				   const struct switchdev_obj_port_mdb *mdb)
5040
{
V
Vivien Didelot 已提交
5041
	struct mv88e6xxx_chip *chip = ds->priv;
5042

5043
	mv88e6xxx_reg_lock(chip);
5044
	if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
5045
					 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
5046 5047
		dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
			port);
5048
	mv88e6xxx_reg_unlock(chip);
5049 5050 5051 5052 5053
}

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

5057
	mv88e6xxx_reg_lock(chip);
5058
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 0);
5059
	mv88e6xxx_reg_unlock(chip);
5060 5061 5062 5063

	return err;
}

5064 5065 5066 5067 5068 5069
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;

5070
	mv88e6xxx_reg_lock(chip);
5071 5072 5073 5074
	if (chip->info->ops->port_set_egress_floods)
		err = chip->info->ops->port_set_egress_floods(chip, port,
							      unicast,
							      multicast);
5075
	mv88e6xxx_reg_unlock(chip);
5076 5077 5078 5079

	return err;
}

5080
static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
5081
	.get_tag_protocol	= mv88e6xxx_get_tag_protocol,
5082
	.setup			= mv88e6xxx_setup,
5083
	.teardown		= mv88e6xxx_teardown,
5084 5085 5086 5087 5088
	.phylink_validate	= mv88e6xxx_validate,
	.phylink_mac_link_state	= mv88e6xxx_link_state,
	.phylink_mac_config	= mv88e6xxx_mac_config,
	.phylink_mac_link_down	= mv88e6xxx_mac_link_down,
	.phylink_mac_link_up	= mv88e6xxx_mac_link_up,
5089 5090 5091
	.get_strings		= mv88e6xxx_get_strings,
	.get_ethtool_stats	= mv88e6xxx_get_ethtool_stats,
	.get_sset_count		= mv88e6xxx_get_sset_count,
5092 5093
	.port_enable		= mv88e6xxx_port_enable,
	.port_disable		= mv88e6xxx_port_disable,
V
Vivien Didelot 已提交
5094 5095
	.get_mac_eee		= mv88e6xxx_get_mac_eee,
	.set_mac_eee		= mv88e6xxx_set_mac_eee,
5096
	.get_eeprom_len		= mv88e6xxx_get_eeprom_len,
5097 5098 5099 5100
	.get_eeprom		= mv88e6xxx_get_eeprom,
	.set_eeprom		= mv88e6xxx_set_eeprom,
	.get_regs_len		= mv88e6xxx_get_regs_len,
	.get_regs		= mv88e6xxx_get_regs,
5101 5102
	.get_rxnfc		= mv88e6xxx_get_rxnfc,
	.set_rxnfc		= mv88e6xxx_set_rxnfc,
5103
	.set_ageing_time	= mv88e6xxx_set_ageing_time,
5104 5105
	.port_bridge_join	= mv88e6xxx_port_bridge_join,
	.port_bridge_leave	= mv88e6xxx_port_bridge_leave,
5106
	.port_egress_floods	= mv88e6xxx_port_egress_floods,
5107
	.port_stp_state_set	= mv88e6xxx_port_stp_state_set,
5108
	.port_fast_age		= mv88e6xxx_port_fast_age,
5109 5110 5111 5112 5113 5114 5115
	.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,
5116 5117 5118
	.port_mdb_prepare       = mv88e6xxx_port_mdb_prepare,
	.port_mdb_add           = mv88e6xxx_port_mdb_add,
	.port_mdb_del           = mv88e6xxx_port_mdb_del,
5119 5120
	.crosschip_bridge_join	= mv88e6xxx_crosschip_bridge_join,
	.crosschip_bridge_leave	= mv88e6xxx_crosschip_bridge_leave,
5121 5122 5123 5124 5125
	.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,
5126 5127
	.devlink_param_get	= mv88e6xxx_devlink_param_get,
	.devlink_param_set	= mv88e6xxx_devlink_param_set,
5128 5129
};

5130
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
5131
{
5132
	struct device *dev = chip->dev;
5133 5134
	struct dsa_switch *ds;

5135
	ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
5136 5137 5138
	if (!ds)
		return -ENOMEM;

5139 5140
	ds->dev = dev;
	ds->num_ports = mv88e6xxx_num_ports(chip);
5141
	ds->priv = chip;
5142
	ds->dev = dev;
5143
	ds->ops = &mv88e6xxx_switch_ops;
5144 5145
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
5146 5147 5148

	dev_set_drvdata(dev, ds);

5149
	return dsa_register_switch(ds);
5150 5151
}

5152
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
5153
{
5154
	dsa_unregister_switch(chip->ds);
5155 5156
}

5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169
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;
}

5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184
/* 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);

5185
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
5186
{
5187
	struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
5188
	const struct mv88e6xxx_info *compat_info = NULL;
5189
	struct device *dev = &mdiodev->dev;
5190
	struct device_node *np = dev->of_node;
5191
	struct mv88e6xxx_chip *chip;
5192
	int port;
5193
	int err;
5194

5195 5196 5197
	if (!np && !pdata)
		return -EINVAL;

5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216
	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;
		}
	}

5217 5218 5219
	if (!compat_info)
		return -EINVAL;

5220
	chip = mv88e6xxx_alloc_chip(dev);
5221 5222 5223 5224
	if (!chip) {
		err = -ENOMEM;
		goto out;
	}
5225

5226
	chip->info = compat_info;
5227

5228
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
5229
	if (err)
5230
		goto out;
5231

5232
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
5233 5234 5235 5236
	if (IS_ERR(chip->reset)) {
		err = PTR_ERR(chip->reset);
		goto out;
	}
5237 5238
	if (chip->reset)
		usleep_range(1000, 2000);
5239

5240
	err = mv88e6xxx_detect(chip);
5241
	if (err)
5242
		goto out;
5243

5244 5245
	mv88e6xxx_phy_init(chip);

5246 5247 5248 5249 5250 5251 5252
	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;
	}
5253

5254
	mv88e6xxx_reg_lock(chip);
5255
	err = mv88e6xxx_switch_reset(chip);
5256
	mv88e6xxx_reg_unlock(chip);
5257 5258 5259
	if (err)
		goto out;

5260 5261 5262 5263 5264 5265
	if (np) {
		chip->irq = of_irq_get(np, 0);
		if (chip->irq == -EPROBE_DEFER) {
			err = chip->irq;
			goto out;
		}
5266 5267
	}

5268 5269 5270
	if (pdata)
		chip->irq = pdata->irq;

5271
	/* Has to be performed before the MDIO bus is created, because
5272
	 * the PHYs will link their interrupts to these interrupt
5273 5274
	 * controllers
	 */
5275
	mv88e6xxx_reg_lock(chip);
5276
	if (chip->irq > 0)
5277
		err = mv88e6xxx_g1_irq_setup(chip);
5278 5279
	else
		err = mv88e6xxx_irq_poll_setup(chip);
5280
	mv88e6xxx_reg_unlock(chip);
5281

5282 5283
	if (err)
		goto out;
5284

5285 5286
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
5287
		if (err)
5288
			goto out_g1_irq;
5289 5290
	}

5291 5292 5293 5294 5295 5296 5297 5298
	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;

5299
	err = mv88e6xxx_mdios_register(chip, np);
5300
	if (err)
5301
		goto out_g1_vtu_prob_irq;
5302

5303
	err = mv88e6xxx_register_switch(chip);
5304 5305
	if (err)
		goto out_mdio;
5306

5307
	return 0;
5308 5309

out_mdio:
5310
	mv88e6xxx_mdios_unregister(chip);
5311
out_g1_vtu_prob_irq:
5312
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
5313
out_g1_atu_prob_irq:
5314
	mv88e6xxx_g1_atu_prob_irq_free(chip);
5315
out_g2_irq:
5316
	if (chip->info->g2_irqs > 0)
5317 5318
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
5319
	if (chip->irq > 0)
5320
		mv88e6xxx_g1_irq_free(chip);
5321 5322
	else
		mv88e6xxx_irq_poll_free(chip);
5323
out:
5324 5325 5326
	if (pdata)
		dev_put(pdata->netdev);

5327
	return err;
5328
}
5329 5330 5331 5332

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

5335 5336
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
5337
		mv88e6xxx_ptp_free(chip);
5338
	}
5339

5340
	mv88e6xxx_phy_destroy(chip);
5341
	mv88e6xxx_unregister_switch(chip);
5342
	mv88e6xxx_mdios_unregister(chip);
5343

5344 5345 5346 5347 5348 5349 5350
	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)
5351
		mv88e6xxx_g1_irq_free(chip);
5352 5353
	else
		mv88e6xxx_irq_poll_free(chip);
5354 5355 5356
}

static const struct of_device_id mv88e6xxx_of_match[] = {
5357 5358 5359 5360
	{
		.compatible = "marvell,mv88e6085",
		.data = &mv88e6xxx_table[MV88E6085],
	},
5361 5362 5363 5364
	{
		.compatible = "marvell,mv88e6190",
		.data = &mv88e6xxx_table[MV88E6190],
	},
5365 5366 5367 5368
	{
		.compatible = "marvell,mv88e6250",
		.data = &mv88e6xxx_table[MV88E6250],
	},
5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379
	{ /* 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,
5380
		.pm = &mv88e6xxx_pm_ops,
5381 5382 5383
	},
};

5384
mdio_module_driver(mv88e6xxx_driver);
5385 5386 5387 5388

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