chip.c 141.3 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
static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
1061
{
1062 1063 1064
	struct dsa_switch *ds = NULL;
	struct net_device *br;
	u16 pvlan;
1065 1066
	int i;

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

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

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

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

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

	return pvlan;
}

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

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

1100
	return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
1101 1102
}

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

1109
	mv88e6xxx_reg_lock(chip);
1110
	err = mv88e6xxx_port_set_state(chip, port, state);
1111
	mv88e6xxx_reg_unlock(chip);
1112 1113

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

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

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

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

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

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

1156 1157 1158 1159 1160 1161 1162
	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;
	}

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

1167 1168 1169
	return 0;
}

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

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

	return 0;
}

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

	return 0;
}

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

	return 0;
}

1203 1204
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
1205 1206
	int err;

1207 1208 1209 1210
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

1211 1212 1213 1214
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

1215 1216 1217
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

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

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

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

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

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

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

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

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

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

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

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

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

	return mv88e6xxx_g1_vtu_flush(chip);
}

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

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

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

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

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

		set_bit(*fid, fid_bitmap);
	}

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

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

		if (!vlan.valid)
			break;

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

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

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

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

1380 1381 1382 1383
	/* 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;

1384 1385 1386
	if (!vid_begin)
		return -EOPNOTSUPP;

1387 1388 1389
	vlan.vid = vid_begin - 1;
	vlan.valid = false;

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

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

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

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

1408
			if (vlan.member[i] ==
1409
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1410 1411
				continue;

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

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

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

1426
	return 0;
1427 1428
}

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

1437
	if (!chip->info->max_vid)
1438 1439
		return -EOPNOTSUPP;

1440
	mv88e6xxx_reg_lock(chip);
1441
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1442
	mv88e6xxx_reg_unlock(chip);
1443

1444
	return err;
1445 1446
}

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

1454
	if (!chip->info->max_vid)
1455 1456
		return -EOPNOTSUPP;

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

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

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

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

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

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

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

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

1525
	return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry);
1526 1527
}

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

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

1558 1559
	if (!vid)
		return -EOPNOTSUPP;
1560

1561 1562
	vlan.vid = vid - 1;
	vlan.valid = false;
1563

1564
	err = mv88e6xxx_vtu_getnext(chip, &vlan);
1565 1566 1567
	if (err)
		return err;

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
	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;
1603 1604
}

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

1614
	if (!chip->info->max_vid)
1615 1616
		return;

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

1624
	mv88e6xxx_reg_lock(chip);
1625

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

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

1635
	mv88e6xxx_reg_unlock(chip);
1636 1637
}

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

1644 1645 1646 1647 1648 1649 1650
	if (!vid)
		return -EOPNOTSUPP;

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

	err = mv88e6xxx_vtu_getnext(chip, &vlan);
1651
	if (err)
1652
		return err;
1653

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

1661
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1662 1663

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

1673
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1674 1675 1676
	if (err)
		return err;

1677
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
1678 1679
}

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

1687
	if (!chip->info->max_vid)
1688 1689
		return -EOPNOTSUPP;

1690
	mv88e6xxx_reg_lock(chip);
1691

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

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

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

1708
unlock:
1709
	mv88e6xxx_reg_unlock(chip);
1710 1711 1712 1713

	return err;
}

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

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

	return err;
1726 1727
}

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

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

1739
	return err;
1740 1741
}

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

1750
	addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1751
	eth_broadcast_addr(addr.mac);
1752 1753

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

1758
		if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
1759 1760
			break;

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

1764 1765
		if (!is_unicast_ether_addr(addr.mac))
			continue;
1766

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

	return err;
}

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

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

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

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

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

		if (!vlan.valid)
			break;

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

1811 1812 1813 1814
	return err;
}

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

1820
	mv88e6xxx_reg_lock(chip);
1821
	err = mv88e6xxx_port_db_dump(chip, port, cb, data);
1822
	mv88e6xxx_reg_unlock(chip);
1823

1824
	return err;
1825 1826
}

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

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

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

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

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

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

1871
	mv88e6xxx_reg_lock(chip);
1872
	err = mv88e6xxx_bridge_map(chip, br);
1873
	mv88e6xxx_reg_unlock(chip);
1874

1875
	return err;
1876 1877
}

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

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

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

	if (!mv88e6xxx_has_pvt(chip))
		return 0;

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

	return err;
}

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

	if (!mv88e6xxx_has_pvt(chip))
		return;

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

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

	return 0;
}

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

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

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

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

1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967
	return 0;
}

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

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

1968
	mv88e6xxx_hardware_reset(chip);
1969

1970
	return mv88e6xxx_software_reset(chip);
1971 1972
}

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

1979 1980 1981 1982
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
1983 1984 1985
	if (err)
		return err;

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

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

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

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

2018 2019 2020 2021
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);
2022

2023
	if (dsa_is_user_port(chip->ds, port))
2024
		return mv88e6xxx_set_port_mode_normal(chip, port);
2025

2026 2027 2028
	/* 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);
2029

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

2033
	return -EINVAL;
2034 2035
}

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

2040
	return mv88e6xxx_port_set_message_port(chip, port, message);
2041
}
2042

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

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

2054
	return 0;
2055 2056
}

2057 2058 2059
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
2060
	int err;
2061

2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079
	if (!chip->info->ops->serdes_power)
		return 0;

	if (on) {
		err = chip->info->ops->serdes_power(chip, port, true);
		if (err)
			return err;

		if (chip->info->ops->serdes_irq_setup)
			err = chip->info->ops->serdes_irq_setup(chip, port);
	} else {
		if (chip->info->ops->serdes_irq_free)
			chip->info->ops->serdes_irq_free(chip, port);

		err = chip->info->ops->serdes_power(chip, port, false);
	}

	return err;
2080 2081
}

2082 2083 2084 2085 2086 2087
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

2088
	upstream_port = dsa_upstream_port(ds, port);
2089 2090 2091 2092 2093 2094 2095
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111
	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;
		}
	}

2112 2113 2114
	return 0;
}

2115
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
2116
{
2117
	struct dsa_switch *ds = chip->ds;
2118
	int err;
2119
	u16 reg;
2120

2121 2122 2123
	chip->ports[port].chip = chip;
	chip->ports[port].port = port;

2124 2125 2126 2127 2128 2129 2130
	/* 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,
2131
					       PAUSE_OFF,
2132 2133 2134 2135
					       PHY_INTERFACE_MODE_NA);
	else
		err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
					       SPEED_UNFORCED, DUPLEX_UNFORCED,
2136
					       PAUSE_ON,
2137 2138 2139
					       PHY_INTERFACE_MODE_NA);
	if (err)
		return err;
2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154

	/* 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.
	 */
2155 2156 2157 2158
	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);
2159 2160
	if (err)
		return err;
2161

2162
	err = mv88e6xxx_setup_port_mode(chip, port);
2163 2164
	if (err)
		return err;
2165

2166
	err = mv88e6xxx_setup_egress_floods(chip, port);
2167 2168 2169
	if (err)
		return err;

2170
	/* Port Control 2: don't force a good FCS, set the maximum frame size to
2171
	 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
2172 2173 2174
	 * 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.
2175
	 */
2176 2177 2178
	err = mv88e6xxx_port_set_map_da(chip, port);
	if (err)
		return err;
2179

2180 2181 2182
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
2183

2184
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
2185
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
2186 2187 2188
	if (err)
		return err;

2189 2190
	if (chip->info->ops->port_set_jumbo_size) {
		err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
2191 2192 2193 2194
		if (err)
			return err;
	}

2195 2196 2197 2198 2199
	/* 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.
	 */
2200
	reg = 1 << port;
2201 2202
	/* Disable learning for CPU port */
	if (dsa_is_cpu_port(ds, port))
2203
		reg = 0;
2204

2205 2206
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
2207 2208
	if (err)
		return err;
2209 2210

	/* Egress rate control 2: disable egress rate control. */
2211 2212
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
				   0x0000);
2213 2214
	if (err)
		return err;
2215

2216 2217
	if (chip->info->ops->port_pause_limit) {
		err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
2218 2219
		if (err)
			return err;
2220
	}
2221

2222 2223 2224 2225 2226 2227
	if (chip->info->ops->port_disable_learn_limit) {
		err = chip->info->ops->port_disable_learn_limit(chip, port);
		if (err)
			return err;
	}

2228 2229
	if (chip->info->ops->port_disable_pri_override) {
		err = chip->info->ops->port_disable_pri_override(chip, port);
2230 2231
		if (err)
			return err;
2232
	}
2233

2234 2235
	if (chip->info->ops->port_tag_remap) {
		err = chip->info->ops->port_tag_remap(chip, port);
2236 2237
		if (err)
			return err;
2238 2239
	}

2240 2241
	if (chip->info->ops->port_egress_rate_limiting) {
		err = chip->info->ops->port_egress_rate_limiting(chip, port);
2242 2243
		if (err)
			return err;
2244 2245
	}

2246 2247 2248 2249 2250
	if (chip->info->ops->port_setup_message_port) {
		err = chip->info->ops->port_setup_message_port(chip, port);
		if (err)
			return err;
	}
2251

2252
	/* Port based VLAN map: give each port the same default address
2253 2254
	 * database, and allow bidirectional communication between the
	 * CPU and DSA port(s), and the other ports.
2255
	 */
2256
	err = mv88e6xxx_port_set_fid(chip, port, 0);
2257 2258
	if (err)
		return err;
2259

2260
	err = mv88e6xxx_port_vlan_map(chip, port);
2261 2262
	if (err)
		return err;
2263 2264 2265 2266

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

2270 2271 2272 2273
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
2274
	int err;
2275

2276
	mv88e6xxx_reg_lock(chip);
2277
	err = mv88e6xxx_serdes_power(chip, port, true);
2278
	mv88e6xxx_reg_unlock(chip);
2279 2280 2281 2282

	return err;
}

2283
static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port)
2284 2285 2286
{
	struct mv88e6xxx_chip *chip = ds->priv;

2287
	mv88e6xxx_reg_lock(chip);
2288 2289
	if (mv88e6xxx_serdes_power(chip, port, false))
		dev_err(chip->dev, "failed to power off SERDES\n");
2290
	mv88e6xxx_reg_unlock(chip);
2291 2292
}

2293 2294 2295
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
2296
	struct mv88e6xxx_chip *chip = ds->priv;
2297 2298
	int err;

2299
	mv88e6xxx_reg_lock(chip);
2300
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2301
	mv88e6xxx_reg_unlock(chip);
2302 2303 2304 2305

	return err;
}

2306
static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
2307
{
2308
	int err;
2309

2310
	/* Initialize the statistics unit */
2311 2312 2313 2314 2315
	if (chip->info->ops->stats_set_histogram) {
		err = chip->info->ops->stats_set_histogram(chip);
		if (err)
			return err;
	}
2316

2317
	return mv88e6xxx_g1_stats_clear(chip);
2318 2319
}

2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343
/* The mv88e6390 has some hidden registers used for debug and
 * development. The errata also makes use of them.
 */
static int mv88e6390_hidden_write(struct mv88e6xxx_chip *chip, int port,
				  int reg, u16 val)
{
	u16 ctrl;
	int err;

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

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

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

static int mv88e6390_hidden_wait(struct mv88e6xxx_chip *chip)
{
2344 2345 2346 2347
	int bit = __bf_shf(PORT_RESERVED_1A_BUSY);

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


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

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

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

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

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

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

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

	return true;
}

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

	if (mv88e6390_setup_errata_applied(chip))
		return 0;

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

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

	return mv88e6xxx_software_reset(chip);
}

2423
static int mv88e6xxx_setup(struct dsa_switch *ds)
2424
{
V
Vivien Didelot 已提交
2425
	struct mv88e6xxx_chip *chip = ds->priv;
2426
	u8 cmode;
2427
	int err;
2428 2429
	int i;

2430
	chip->ds = ds;
2431
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
2432

2433
	mv88e6xxx_reg_lock(chip);
2434

2435 2436 2437 2438 2439 2440
	if (chip->info->ops->setup_errata) {
		err = chip->info->ops->setup_errata(chip);
		if (err)
			goto unlock;
	}

2441 2442 2443 2444 2445
	/* 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)
2446
				goto unlock;
2447 2448 2449 2450 2451

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

2452
	/* Setup Switch Port Registers */
2453
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2454 2455 2456
		if (dsa_is_unused_port(ds, i))
			continue;

2457
		/* Prevent the use of an invalid port. */
2458
		if (mv88e6xxx_is_invalid_port(chip, i)) {
2459 2460 2461 2462 2463
			dev_err(chip->dev, "port %d is invalid\n", i);
			err = -EINVAL;
			goto unlock;
		}

2464 2465 2466 2467 2468
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

2469 2470 2471 2472
	err = mv88e6xxx_irl_setup(chip);
	if (err)
		goto unlock;

2473 2474 2475 2476
	err = mv88e6xxx_mac_setup(chip);
	if (err)
		goto unlock;

2477 2478 2479 2480
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

2481 2482 2483 2484
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

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

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

2493 2494 2495 2496
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

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

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

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

2509 2510 2511 2512
	err = mv88e6xxx_trunk_setup(chip);
	if (err)
		goto unlock;

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

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

2521
	/* Setup PTP Hardware Clock and timestamping */
2522 2523 2524 2525
	if (chip->info->ptp_support) {
		err = mv88e6xxx_ptp_setup(chip);
		if (err)
			goto unlock;
2526 2527 2528 2529

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
2530 2531
	}

2532 2533 2534 2535
	err = mv88e6xxx_stats_setup(chip);
	if (err)
		goto unlock;

2536
unlock:
2537
	mv88e6xxx_reg_unlock(chip);
2538

2539
	return err;
2540 2541
}

2542
static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
2543
{
2544 2545
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2546 2547
	u16 val;
	int err;
2548

2549 2550 2551
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

2552
	mv88e6xxx_reg_lock(chip);
2553
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
2554
	mv88e6xxx_reg_unlock(chip);
2555

2556
	if (reg == MII_PHYSID2) {
2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572
		/* 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;
2573 2574
	}

2575
	return err ? err : val;
2576 2577
}

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

2584 2585 2586
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

2587
	mv88e6xxx_reg_lock(chip);
2588
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
2589
	mv88e6xxx_reg_unlock(chip);
2590 2591

	return err;
2592 2593
}

2594
static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
2595 2596
				   struct device_node *np,
				   bool external)
2597 2598
{
	static int index;
2599
	struct mv88e6xxx_mdio_bus *mdio_bus;
2600 2601 2602
	struct mii_bus *bus;
	int err;

2603
	if (external) {
2604
		mv88e6xxx_reg_lock(chip);
2605
		err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
2606
		mv88e6xxx_reg_unlock(chip);
2607 2608 2609 2610 2611

		if (err)
			return err;
	}

2612
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
2613 2614 2615
	if (!bus)
		return -ENOMEM;

2616
	mdio_bus = bus->priv;
2617
	mdio_bus->bus = bus;
2618
	mdio_bus->chip = chip;
2619 2620
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
2621

2622 2623
	if (np) {
		bus->name = np->full_name;
2624
		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
2625 2626 2627 2628 2629 2630 2631
	} 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;
2632
	bus->parent = chip->dev;
2633

2634 2635 2636 2637 2638 2639
	if (!external) {
		err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
		if (err)
			return err;
	}

2640
	err = of_mdiobus_register(bus, np);
2641
	if (err) {
2642
		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
2643
		mv88e6xxx_g2_irq_mdio_free(chip, bus);
2644
		return err;
2645
	}
2646 2647 2648 2649 2650

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

	return 0;
2653
}
2654

2655 2656 2657 2658 2659
static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
	{ .compatible = "marvell,mv88e6xxx-mdio-external",
	  .data = (void *)true },
	{ },
};
2660

2661 2662 2663 2664 2665 2666 2667 2668 2669
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;

2670 2671 2672
		if (!mdio_bus->external)
			mv88e6xxx_g2_irq_mdio_free(chip, bus);

2673 2674 2675 2676
		mdiobus_unregister(bus);
	}
}

2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700
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);
2701 2702
			if (err) {
				mv88e6xxx_mdios_unregister(chip);
2703
				of_node_put(child);
2704
				return err;
2705
			}
2706 2707 2708 2709
		}
	}

	return 0;
2710 2711
}

2712 2713
static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
2714
	struct mv88e6xxx_chip *chip = ds->priv;
2715 2716 2717 2718 2719 2720 2721

	return chip->eeprom_len;
}

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

2725 2726
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
2727

2728
	mv88e6xxx_reg_lock(chip);
2729
	err = chip->info->ops->get_eeprom(chip, eeprom, data);
2730
	mv88e6xxx_reg_unlock(chip);
2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742

	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 已提交
2743
	struct mv88e6xxx_chip *chip = ds->priv;
2744 2745
	int err;

2746 2747 2748
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

2749 2750 2751
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

2752
	mv88e6xxx_reg_lock(chip);
2753
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
2754
	mv88e6xxx_reg_unlock(chip);
2755 2756 2757 2758

	return err;
}

2759
static const struct mv88e6xxx_ops mv88e6085_ops = {
2760
	/* MV88E6XXX_FAMILY_6097 */
2761 2762
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2763
	.irl_init_all = mv88e6352_g2_irl_init_all,
2764
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2765 2766
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2767
	.port_set_link = mv88e6xxx_port_set_link,
2768
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2769
	.port_set_speed = mv88e6185_port_set_speed,
2770
	.port_tag_remap = mv88e6095_port_tag_remap,
2771
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2772
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2773
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2774
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2775
	.port_pause_limit = mv88e6097_port_pause_limit,
2776
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2777
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2778
	.port_link_state = mv88e6352_port_link_state,
2779
	.port_get_cmode = mv88e6185_port_get_cmode,
2780
	.port_setup_message_port = mv88e6xxx_setup_message_port,
2781
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2782
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2783 2784
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2785
	.stats_get_stats = mv88e6095_stats_get_stats,
2786 2787
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2788
	.watchdog_ops = &mv88e6097_watchdog_ops,
2789
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2790
	.pot_clear = mv88e6xxx_g2_pot_clear,
2791 2792
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2793
	.reset = mv88e6185_g1_reset,
2794
	.rmu_disable = mv88e6085_g1_rmu_disable,
2795
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2796
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2797
	.phylink_validate = mv88e6185_phylink_validate,
2798 2799 2800
};

static const struct mv88e6xxx_ops mv88e6095_ops = {
2801
	/* MV88E6XXX_FAMILY_6095 */
2802 2803
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2804
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2805 2806
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2807
	.port_set_link = mv88e6xxx_port_set_link,
2808
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2809
	.port_set_speed = mv88e6185_port_set_speed,
2810
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2811
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2812
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2813
	.port_link_state = mv88e6185_port_link_state,
2814
	.port_get_cmode = mv88e6185_port_get_cmode,
2815
	.port_setup_message_port = mv88e6xxx_setup_message_port,
2816
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2817
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2818 2819
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2820
	.stats_get_stats = mv88e6095_stats_get_stats,
2821
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2822 2823
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2824
	.reset = mv88e6185_g1_reset,
2825
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2826
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2827
	.phylink_validate = mv88e6185_phylink_validate,
2828 2829
};

2830
static const struct mv88e6xxx_ops mv88e6097_ops = {
2831
	/* MV88E6XXX_FAMILY_6097 */
2832 2833
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2834
	.irl_init_all = mv88e6352_g2_irl_init_all,
2835 2836 2837 2838 2839 2840
	.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,
2841
	.port_tag_remap = mv88e6095_port_tag_remap,
2842
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2843
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2844
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2845
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2846
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
2847
	.port_pause_limit = mv88e6097_port_pause_limit,
2848
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2849
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2850
	.port_link_state = mv88e6352_port_link_state,
2851
	.port_get_cmode = mv88e6185_port_get_cmode,
2852
	.port_setup_message_port = mv88e6xxx_setup_message_port,
2853
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2854
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2855 2856 2857
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
	.stats_get_stats = mv88e6095_stats_get_stats,
2858 2859
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2860
	.watchdog_ops = &mv88e6097_watchdog_ops,
2861
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2862
	.pot_clear = mv88e6xxx_g2_pot_clear,
2863
	.reset = mv88e6352_g1_reset,
2864
	.rmu_disable = mv88e6085_g1_rmu_disable,
2865
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2866
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2867
	.phylink_validate = mv88e6185_phylink_validate,
2868 2869
};

2870
static const struct mv88e6xxx_ops mv88e6123_ops = {
2871
	/* MV88E6XXX_FAMILY_6165 */
2872 2873
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2874
	.irl_init_all = mv88e6352_g2_irl_init_all,
2875
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2876 2877
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2878
	.port_set_link = mv88e6xxx_port_set_link,
2879
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2880
	.port_set_speed = mv88e6185_port_set_speed,
2881
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2882
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2883
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2884
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2885
	.port_link_state = mv88e6352_port_link_state,
2886
	.port_get_cmode = mv88e6185_port_get_cmode,
2887
	.port_setup_message_port = mv88e6xxx_setup_message_port,
2888
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2889
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2890 2891
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2892
	.stats_get_stats = mv88e6095_stats_get_stats,
2893 2894
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2895
	.watchdog_ops = &mv88e6097_watchdog_ops,
2896
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2897
	.pot_clear = mv88e6xxx_g2_pot_clear,
2898
	.reset = mv88e6352_g1_reset,
2899
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2900
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2901
	.phylink_validate = mv88e6185_phylink_validate,
2902 2903 2904
};

static const struct mv88e6xxx_ops mv88e6131_ops = {
2905
	/* MV88E6XXX_FAMILY_6185 */
2906 2907
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2908
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2909 2910
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2911
	.port_set_link = mv88e6xxx_port_set_link,
2912
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2913
	.port_set_speed = mv88e6185_port_set_speed,
2914
	.port_tag_remap = mv88e6095_port_tag_remap,
2915
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2916
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2917
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2918
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2919
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2920
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2921
	.port_pause_limit = mv88e6097_port_pause_limit,
2922
	.port_set_pause = mv88e6185_port_set_pause,
2923
	.port_link_state = mv88e6352_port_link_state,
2924
	.port_get_cmode = mv88e6185_port_get_cmode,
2925
	.port_setup_message_port = mv88e6xxx_setup_message_port,
2926
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2927
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2928 2929
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2930
	.stats_get_stats = mv88e6095_stats_get_stats,
2931 2932
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2933
	.watchdog_ops = &mv88e6097_watchdog_ops,
2934
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2935
	.ppu_enable = mv88e6185_g1_ppu_enable,
2936
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
2937
	.ppu_disable = mv88e6185_g1_ppu_disable,
2938
	.reset = mv88e6185_g1_reset,
2939
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2940
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2941
	.phylink_validate = mv88e6185_phylink_validate,
2942 2943
};

2944 2945
static const struct mv88e6xxx_ops mv88e6141_ops = {
	/* MV88E6XXX_FAMILY_6341 */
2946 2947
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2948
	.irl_init_all = mv88e6352_g2_irl_init_all,
2949 2950 2951 2952 2953 2954 2955 2956
	.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,
2957
	.port_set_speed = mv88e6341_port_set_speed,
2958
	.port_max_speed_mode = mv88e6341_port_max_speed_mode,
2959 2960 2961 2962
	.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,
2963
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2964
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2965
	.port_pause_limit = mv88e6097_port_pause_limit,
2966 2967
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2968
	.port_link_state = mv88e6352_port_link_state,
2969
	.port_get_cmode = mv88e6352_port_get_cmode,
2970
	.port_setup_message_port = mv88e6xxx_setup_message_port,
2971
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
2972
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2973 2974 2975
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
2976 2977
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
2978 2979
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
2980
	.pot_clear = mv88e6xxx_g2_pot_clear,
2981
	.reset = mv88e6352_g1_reset,
2982
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2983
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2984
	.serdes_power = mv88e6341_serdes_power,
2985
	.gpio_ops = &mv88e6352_gpio_ops,
2986
	.phylink_validate = mv88e6341_phylink_validate,
2987 2988
};

2989
static const struct mv88e6xxx_ops mv88e6161_ops = {
2990
	/* MV88E6XXX_FAMILY_6165 */
2991 2992
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2993
	.irl_init_all = mv88e6352_g2_irl_init_all,
2994
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2995 2996
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2997
	.port_set_link = mv88e6xxx_port_set_link,
2998
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2999
	.port_set_speed = mv88e6185_port_set_speed,
3000
	.port_tag_remap = mv88e6095_port_tag_remap,
3001
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3002
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3003
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3004
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3005
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3006
	.port_pause_limit = mv88e6097_port_pause_limit,
3007
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3008
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3009
	.port_link_state = mv88e6352_port_link_state,
3010
	.port_get_cmode = mv88e6185_port_get_cmode,
3011
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3012
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3013
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3014 3015
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3016
	.stats_get_stats = mv88e6095_stats_get_stats,
3017 3018
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3019
	.watchdog_ops = &mv88e6097_watchdog_ops,
3020
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3021
	.pot_clear = mv88e6xxx_g2_pot_clear,
3022
	.reset = mv88e6352_g1_reset,
3023
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3024
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3025
	.avb_ops = &mv88e6165_avb_ops,
3026
	.ptp_ops = &mv88e6165_ptp_ops,
3027
	.phylink_validate = mv88e6185_phylink_validate,
3028 3029 3030
};

static const struct mv88e6xxx_ops mv88e6165_ops = {
3031
	/* MV88E6XXX_FAMILY_6165 */
3032 3033
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3034
	.irl_init_all = mv88e6352_g2_irl_init_all,
3035
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3036 3037
	.phy_read = mv88e6165_phy_read,
	.phy_write = mv88e6165_phy_write,
3038
	.port_set_link = mv88e6xxx_port_set_link,
3039
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3040
	.port_set_speed = mv88e6185_port_set_speed,
3041
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3042
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3043
	.port_link_state = mv88e6352_port_link_state,
3044
	.port_get_cmode = mv88e6185_port_get_cmode,
3045
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3046
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3047
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3048 3049
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3050
	.stats_get_stats = mv88e6095_stats_get_stats,
3051 3052
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3053
	.watchdog_ops = &mv88e6097_watchdog_ops,
3054
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3055
	.pot_clear = mv88e6xxx_g2_pot_clear,
3056
	.reset = mv88e6352_g1_reset,
3057
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3058
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3059
	.avb_ops = &mv88e6165_avb_ops,
3060
	.ptp_ops = &mv88e6165_ptp_ops,
3061
	.phylink_validate = mv88e6185_phylink_validate,
3062 3063 3064
};

static const struct mv88e6xxx_ops mv88e6171_ops = {
3065
	/* MV88E6XXX_FAMILY_6351 */
3066 3067
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3068
	.irl_init_all = mv88e6352_g2_irl_init_all,
3069
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3070 3071
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3072
	.port_set_link = mv88e6xxx_port_set_link,
3073
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3074
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3075
	.port_set_speed = mv88e6185_port_set_speed,
3076
	.port_tag_remap = mv88e6095_port_tag_remap,
3077
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3078
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3079
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3080
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3081
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3082
	.port_pause_limit = mv88e6097_port_pause_limit,
3083
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3084
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3085
	.port_link_state = mv88e6352_port_link_state,
3086
	.port_get_cmode = mv88e6352_port_get_cmode,
3087
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3088
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3089
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3090 3091
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3092
	.stats_get_stats = mv88e6095_stats_get_stats,
3093 3094
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3095
	.watchdog_ops = &mv88e6097_watchdog_ops,
3096
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3097
	.pot_clear = mv88e6xxx_g2_pot_clear,
3098
	.reset = mv88e6352_g1_reset,
3099
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3100
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3101
	.phylink_validate = mv88e6185_phylink_validate,
3102 3103 3104
};

static const struct mv88e6xxx_ops mv88e6172_ops = {
3105
	/* MV88E6XXX_FAMILY_6352 */
3106 3107
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3108
	.irl_init_all = mv88e6352_g2_irl_init_all,
3109 3110
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3111
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3112 3113
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3114
	.port_set_link = mv88e6xxx_port_set_link,
3115
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3116
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3117
	.port_set_speed = mv88e6352_port_set_speed,
3118
	.port_tag_remap = mv88e6095_port_tag_remap,
3119
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3120
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3121
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3122
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3123
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3124
	.port_pause_limit = mv88e6097_port_pause_limit,
3125
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3126
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3127
	.port_link_state = mv88e6352_port_link_state,
3128
	.port_get_cmode = mv88e6352_port_get_cmode,
3129
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3130
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3131
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3132 3133
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3134
	.stats_get_stats = mv88e6095_stats_get_stats,
3135 3136
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3137
	.watchdog_ops = &mv88e6097_watchdog_ops,
3138
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3139
	.pot_clear = mv88e6xxx_g2_pot_clear,
3140
	.reset = mv88e6352_g1_reset,
3141
	.rmu_disable = mv88e6352_g1_rmu_disable,
3142
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3143
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3144
	.serdes_power = mv88e6352_serdes_power,
3145
	.gpio_ops = &mv88e6352_gpio_ops,
3146
	.phylink_validate = mv88e6352_phylink_validate,
3147 3148 3149
};

static const struct mv88e6xxx_ops mv88e6175_ops = {
3150
	/* MV88E6XXX_FAMILY_6351 */
3151 3152
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3153
	.irl_init_all = mv88e6352_g2_irl_init_all,
3154
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3155 3156
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3157
	.port_set_link = mv88e6xxx_port_set_link,
3158
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3159
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3160
	.port_set_speed = mv88e6185_port_set_speed,
3161
	.port_tag_remap = mv88e6095_port_tag_remap,
3162
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3163
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3164
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3165
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3166
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3167
	.port_pause_limit = mv88e6097_port_pause_limit,
3168
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3169
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3170
	.port_link_state = mv88e6352_port_link_state,
3171
	.port_get_cmode = mv88e6352_port_get_cmode,
3172
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3173
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3174
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3175 3176
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3177
	.stats_get_stats = mv88e6095_stats_get_stats,
3178 3179
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3180
	.watchdog_ops = &mv88e6097_watchdog_ops,
3181
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3182
	.pot_clear = mv88e6xxx_g2_pot_clear,
3183
	.reset = mv88e6352_g1_reset,
3184
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3185
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3186
	.phylink_validate = mv88e6185_phylink_validate,
3187 3188 3189
};

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

static const struct mv88e6xxx_ops mv88e6185_ops = {
3237
	/* MV88E6XXX_FAMILY_6185 */
3238 3239
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3240
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3241 3242
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3243
	.port_set_link = mv88e6xxx_port_set_link,
3244
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3245
	.port_set_speed = mv88e6185_port_set_speed,
3246
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
3247
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
3248
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
3249
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
3250
	.port_set_pause = mv88e6185_port_set_pause,
3251
	.port_link_state = mv88e6185_port_link_state,
3252
	.port_get_cmode = mv88e6185_port_get_cmode,
3253
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3254
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3255
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3256 3257
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3258
	.stats_get_stats = mv88e6095_stats_get_stats,
3259 3260
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3261
	.watchdog_ops = &mv88e6097_watchdog_ops,
3262
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3263
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
3264 3265
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
3266
	.reset = mv88e6185_g1_reset,
3267
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3268
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3269
	.phylink_validate = mv88e6185_phylink_validate,
3270 3271
};

3272
static const struct mv88e6xxx_ops mv88e6190_ops = {
3273
	/* MV88E6XXX_FAMILY_6390 */
3274
	.setup_errata = mv88e6390_setup_errata,
3275
	.irl_init_all = mv88e6390_g2_irl_init_all,
3276 3277
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3278 3279 3280 3281 3282 3283 3284
	.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,
3285
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
3286
	.port_tag_remap = mv88e6390_port_tag_remap,
3287
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3288
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3289
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3290
	.port_pause_limit = mv88e6390_port_pause_limit,
3291
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3292
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3293
	.port_link_state = mv88e6352_port_link_state,
3294
	.port_get_cmode = mv88e6352_port_get_cmode,
3295
	.port_set_cmode = mv88e6390_port_set_cmode,
3296
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3297
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3298
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3299 3300
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3301
	.stats_get_stats = mv88e6390_stats_get_stats,
3302 3303
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3304
	.watchdog_ops = &mv88e6390_watchdog_ops,
3305
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3306
	.pot_clear = mv88e6xxx_g2_pot_clear,
3307
	.reset = mv88e6352_g1_reset,
3308
	.rmu_disable = mv88e6390_g1_rmu_disable,
3309 3310
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3311
	.serdes_power = mv88e6390_serdes_power,
3312 3313
	.serdes_irq_setup = mv88e6390_serdes_irq_setup,
	.serdes_irq_free = mv88e6390_serdes_irq_free,
3314
	.gpio_ops = &mv88e6352_gpio_ops,
3315
	.phylink_validate = mv88e6390_phylink_validate,
3316 3317 3318
};

static const struct mv88e6xxx_ops mv88e6190x_ops = {
3319
	/* MV88E6XXX_FAMILY_6390 */
3320
	.setup_errata = mv88e6390_setup_errata,
3321
	.irl_init_all = mv88e6390_g2_irl_init_all,
3322 3323
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3324 3325 3326 3327 3328 3329 3330
	.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,
3331
	.port_max_speed_mode = mv88e6390x_port_max_speed_mode,
3332
	.port_tag_remap = mv88e6390_port_tag_remap,
3333
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3334
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3335
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3336
	.port_pause_limit = mv88e6390_port_pause_limit,
3337
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3338
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3339
	.port_link_state = mv88e6352_port_link_state,
3340
	.port_get_cmode = mv88e6352_port_get_cmode,
3341
	.port_set_cmode = mv88e6390x_port_set_cmode,
3342
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3343
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3344
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3345 3346
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3347
	.stats_get_stats = mv88e6390_stats_get_stats,
3348 3349
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3350
	.watchdog_ops = &mv88e6390_watchdog_ops,
3351
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3352
	.pot_clear = mv88e6xxx_g2_pot_clear,
3353
	.reset = mv88e6352_g1_reset,
3354
	.rmu_disable = mv88e6390_g1_rmu_disable,
3355 3356
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3357
	.serdes_power = mv88e6390x_serdes_power,
3358 3359
	.serdes_irq_setup = mv88e6390x_serdes_irq_setup,
	.serdes_irq_free = mv88e6390x_serdes_irq_free,
3360
	.gpio_ops = &mv88e6352_gpio_ops,
3361
	.phylink_validate = mv88e6390x_phylink_validate,
3362 3363 3364
};

static const struct mv88e6xxx_ops mv88e6191_ops = {
3365
	/* MV88E6XXX_FAMILY_6390 */
3366
	.setup_errata = mv88e6390_setup_errata,
3367
	.irl_init_all = mv88e6390_g2_irl_init_all,
3368 3369
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3370 3371 3372 3373 3374 3375 3376
	.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,
3377
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
3378
	.port_tag_remap = mv88e6390_port_tag_remap,
3379
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3380
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3381
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3382
	.port_pause_limit = mv88e6390_port_pause_limit,
3383
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3384
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3385
	.port_link_state = mv88e6352_port_link_state,
3386
	.port_get_cmode = mv88e6352_port_get_cmode,
3387
	.port_set_cmode = mv88e6390_port_set_cmode,
3388
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3389
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3390
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3391 3392
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3393
	.stats_get_stats = mv88e6390_stats_get_stats,
3394 3395
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3396
	.watchdog_ops = &mv88e6390_watchdog_ops,
3397
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3398
	.pot_clear = mv88e6xxx_g2_pot_clear,
3399
	.reset = mv88e6352_g1_reset,
3400
	.rmu_disable = mv88e6390_g1_rmu_disable,
3401 3402
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3403
	.serdes_power = mv88e6390_serdes_power,
3404 3405
	.serdes_irq_setup = mv88e6390_serdes_irq_setup,
	.serdes_irq_free = mv88e6390_serdes_irq_free,
3406 3407
	.avb_ops = &mv88e6390_avb_ops,
	.ptp_ops = &mv88e6352_ptp_ops,
3408
	.phylink_validate = mv88e6390_phylink_validate,
3409 3410
};

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

3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494
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,
3495 3496
	.avb_ops = &mv88e6352_avb_ops,
	.ptp_ops = &mv88e6250_ptp_ops,
3497 3498 3499
	.phylink_validate = mv88e6065_phylink_validate,
};

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

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

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

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

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

static const struct mv88e6xxx_ops mv88e6351_ops = {
3722
	/* MV88E6XXX_FAMILY_6351 */
3723 3724
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3725
	.irl_init_all = mv88e6352_g2_irl_init_all,
3726
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3727 3728
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3729
	.port_set_link = mv88e6xxx_port_set_link,
3730
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3731
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3732
	.port_set_speed = mv88e6185_port_set_speed,
3733
	.port_tag_remap = mv88e6095_port_tag_remap,
3734
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3735
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3736
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3737
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3738
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3739
	.port_pause_limit = mv88e6097_port_pause_limit,
3740
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3741
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3742
	.port_link_state = mv88e6352_port_link_state,
3743
	.port_get_cmode = mv88e6352_port_get_cmode,
3744
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3745
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3746
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3747 3748
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3749
	.stats_get_stats = mv88e6095_stats_get_stats,
3750 3751
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3752
	.watchdog_ops = &mv88e6097_watchdog_ops,
3753
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3754
	.pot_clear = mv88e6xxx_g2_pot_clear,
3755
	.reset = mv88e6352_g1_reset,
3756
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3757
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3758
	.avb_ops = &mv88e6352_avb_ops,
3759
	.ptp_ops = &mv88e6352_ptp_ops,
3760
	.phylink_validate = mv88e6185_phylink_validate,
3761 3762 3763
};

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280
	[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,
4281
		.invalid_port_mask = BIT(2) | BIT(3) | BIT(4),
4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292
		.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,
4293
		.ptp_support = true,
4294 4295 4296
		.ops = &mv88e6250_ops,
	},

4297
	[MV88E6240] = {
4298
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
4299 4300 4301 4302
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6240",
		.num_databases = 4096,
		.num_ports = 7,
4303
		.num_internal_phys = 5,
4304
		.num_gpio = 15,
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 = 9,
4312
		.g2_irqs = 10,
4313
		.atu_move_port_mask = 0xf,
4314
		.pvt = true,
4315
		.multi_chip = true,
4316
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4317
		.ptp_support = true,
4318
		.ops = &mv88e6240_ops,
4319 4320
	},

4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338
	[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,
4339
		.ptp_support = true,
4340 4341 4342
		.ops = &mv88e6250_ops,
	},

4343
	[MV88E6290] = {
4344
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
4345 4346 4347 4348
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6290",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4349
		.num_internal_phys = 9,
4350
		.num_gpio = 16,
4351
		.max_vid = 8191,
4352
		.port_base_addr = 0x0,
4353
		.phy_base_addr = 0x0,
4354
		.global1_addr = 0x1b,
4355
		.global2_addr = 0x1c,
4356
		.age_time_coeff = 3750,
4357
		.g1_irqs = 9,
4358
		.g2_irqs = 14,
4359
		.atu_move_port_mask = 0x1f,
4360
		.pvt = true,
4361
		.multi_chip = true,
4362
		.tag_protocol = DSA_TAG_PROTO_DSA,
4363
		.ptp_support = true,
4364 4365 4366
		.ops = &mv88e6290_ops,
	},

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

	[MV88E6321] = {
4392
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
4393 4394 4395 4396
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6321",
		.num_databases = 4096,
		.num_ports = 7,
4397
		.num_internal_phys = 5,
4398
		.num_gpio = 15,
4399
		.max_vid = 4095,
4400
		.port_base_addr = 0x10,
4401
		.phy_base_addr = 0x0,
4402
		.global1_addr = 0x1b,
4403
		.global2_addr = 0x1c,
4404
		.age_time_coeff = 15000,
4405
		.g1_irqs = 8,
4406
		.g2_irqs = 10,
4407
		.atu_move_port_mask = 0xf,
4408
		.multi_chip = true,
4409
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4410
		.ptp_support = true,
4411
		.ops = &mv88e6321_ops,
4412 4413
	},

4414
	[MV88E6341] = {
4415
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
4416 4417 4418
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
4419
		.num_internal_phys = 5,
4420
		.num_ports = 6,
4421
		.num_gpio = 11,
4422
		.max_vid = 4095,
4423
		.port_base_addr = 0x10,
4424
		.phy_base_addr = 0x10,
4425
		.global1_addr = 0x1b,
4426
		.global2_addr = 0x1c,
4427
		.age_time_coeff = 3750,
4428
		.atu_move_port_mask = 0x1f,
4429
		.g1_irqs = 9,
4430
		.g2_irqs = 10,
4431
		.pvt = true,
4432
		.multi_chip = true,
4433
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4434
		.ptp_support = true,
4435 4436 4437
		.ops = &mv88e6341_ops,
	},

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

	[MV88E6351] = {
4461
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
4462 4463 4464 4465
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6351",
		.num_databases = 4096,
		.num_ports = 7,
4466
		.num_internal_phys = 5,
4467
		.max_vid = 4095,
4468
		.port_base_addr = 0x10,
4469
		.phy_base_addr = 0x0,
4470
		.global1_addr = 0x1b,
4471
		.global2_addr = 0x1c,
4472
		.age_time_coeff = 15000,
4473
		.g1_irqs = 9,
4474
		.g2_irqs = 10,
4475
		.atu_move_port_mask = 0xf,
4476
		.pvt = true,
4477
		.multi_chip = true,
4478
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4479
		.ops = &mv88e6351_ops,
4480 4481 4482
	},

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

4553
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
4554
{
4555
	int i;
4556

4557 4558 4559
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
4560 4561 4562 4563

	return NULL;
}

4564
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
4565 4566
{
	const struct mv88e6xxx_info *info;
4567 4568 4569
	unsigned int prod_num, rev;
	u16 id;
	int err;
4570

4571
	mv88e6xxx_reg_lock(chip);
4572
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
4573
	mv88e6xxx_reg_unlock(chip);
4574 4575
	if (err)
		return err;
4576

4577 4578
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
4579 4580 4581 4582 4583

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

4584
	/* Update the compatible info with the probed one */
4585
	chip->info = info;
4586

4587 4588 4589 4590
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

4591 4592
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
4593 4594 4595 4596

	return 0;
}

4597
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
4598
{
4599
	struct mv88e6xxx_chip *chip;
4600

4601 4602
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
4603 4604
		return NULL;

4605
	chip->dev = dev;
4606

4607
	mutex_init(&chip->reg_lock);
4608
	INIT_LIST_HEAD(&chip->mdios);
4609

4610
	return chip;
4611 4612
}

4613 4614
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
							int port)
4615
{
V
Vivien Didelot 已提交
4616
	struct mv88e6xxx_chip *chip = ds->priv;
4617

4618
	return chip->info->tag_protocol;
4619 4620
}

4621
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4622
				      const struct switchdev_obj_port_mdb *mdb)
4623 4624 4625 4626 4627 4628 4629 4630 4631
{
	/* 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,
4632
				   const struct switchdev_obj_port_mdb *mdb)
4633
{
V
Vivien Didelot 已提交
4634
	struct mv88e6xxx_chip *chip = ds->priv;
4635

4636
	mv88e6xxx_reg_lock(chip);
4637
	if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4638
					 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
4639 4640
		dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
			port);
4641
	mv88e6xxx_reg_unlock(chip);
4642 4643 4644 4645 4646
}

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

4650
	mv88e6xxx_reg_lock(chip);
4651
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4652
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
4653
	mv88e6xxx_reg_unlock(chip);
4654 4655 4656 4657

	return err;
}

4658 4659 4660 4661 4662 4663
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;

4664
	mv88e6xxx_reg_lock(chip);
4665 4666 4667 4668
	if (chip->info->ops->port_set_egress_floods)
		err = chip->info->ops->port_set_egress_floods(chip, port,
							      unicast,
							      multicast);
4669
	mv88e6xxx_reg_unlock(chip);
4670 4671 4672 4673

	return err;
}

4674
static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
4675
	.get_tag_protocol	= mv88e6xxx_get_tag_protocol,
4676
	.setup			= mv88e6xxx_setup,
4677 4678 4679 4680 4681
	.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,
4682 4683 4684
	.get_strings		= mv88e6xxx_get_strings,
	.get_ethtool_stats	= mv88e6xxx_get_ethtool_stats,
	.get_sset_count		= mv88e6xxx_get_sset_count,
4685 4686
	.port_enable		= mv88e6xxx_port_enable,
	.port_disable		= mv88e6xxx_port_disable,
V
Vivien Didelot 已提交
4687 4688
	.get_mac_eee		= mv88e6xxx_get_mac_eee,
	.set_mac_eee		= mv88e6xxx_set_mac_eee,
4689
	.get_eeprom_len		= mv88e6xxx_get_eeprom_len,
4690 4691 4692 4693
	.get_eeprom		= mv88e6xxx_get_eeprom,
	.set_eeprom		= mv88e6xxx_set_eeprom,
	.get_regs_len		= mv88e6xxx_get_regs_len,
	.get_regs		= mv88e6xxx_get_regs,
4694
	.set_ageing_time	= mv88e6xxx_set_ageing_time,
4695 4696
	.port_bridge_join	= mv88e6xxx_port_bridge_join,
	.port_bridge_leave	= mv88e6xxx_port_bridge_leave,
4697
	.port_egress_floods	= mv88e6xxx_port_egress_floods,
4698
	.port_stp_state_set	= mv88e6xxx_port_stp_state_set,
4699
	.port_fast_age		= mv88e6xxx_port_fast_age,
4700 4701 4702 4703 4704 4705 4706
	.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,
4707 4708 4709
	.port_mdb_prepare       = mv88e6xxx_port_mdb_prepare,
	.port_mdb_add           = mv88e6xxx_port_mdb_add,
	.port_mdb_del           = mv88e6xxx_port_mdb_del,
4710 4711
	.crosschip_bridge_join	= mv88e6xxx_crosschip_bridge_join,
	.crosschip_bridge_leave	= mv88e6xxx_crosschip_bridge_leave,
4712 4713 4714 4715 4716
	.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,
4717 4718
};

4719
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
4720
{
4721
	struct device *dev = chip->dev;
4722 4723
	struct dsa_switch *ds;

4724
	ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
4725 4726 4727
	if (!ds)
		return -ENOMEM;

4728
	ds->priv = chip;
4729
	ds->dev = dev;
4730
	ds->ops = &mv88e6xxx_switch_ops;
4731 4732
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
4733 4734 4735

	dev_set_drvdata(dev, ds);

4736
	return dsa_register_switch(ds);
4737 4738
}

4739
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
4740
{
4741
	dsa_unregister_switch(chip->ds);
4742 4743
}

4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756
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;
}

4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771
/* 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);

4772
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
4773
{
4774
	struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
4775
	const struct mv88e6xxx_info *compat_info = NULL;
4776
	struct device *dev = &mdiodev->dev;
4777
	struct device_node *np = dev->of_node;
4778
	struct mv88e6xxx_chip *chip;
4779
	int port;
4780
	int err;
4781

4782 4783 4784
	if (!np && !pdata)
		return -EINVAL;

4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803
	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;
		}
	}

4804 4805 4806
	if (!compat_info)
		return -EINVAL;

4807
	chip = mv88e6xxx_alloc_chip(dev);
4808 4809 4810 4811
	if (!chip) {
		err = -ENOMEM;
		goto out;
	}
4812

4813
	chip->info = compat_info;
4814

4815
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
4816
	if (err)
4817
		goto out;
4818

4819
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4820 4821 4822 4823
	if (IS_ERR(chip->reset)) {
		err = PTR_ERR(chip->reset);
		goto out;
	}
4824 4825
	if (chip->reset)
		usleep_range(1000, 2000);
4826

4827
	err = mv88e6xxx_detect(chip);
4828
	if (err)
4829
		goto out;
4830

4831 4832
	mv88e6xxx_phy_init(chip);

4833 4834 4835 4836 4837 4838 4839
	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;
	}
4840

4841
	mv88e6xxx_reg_lock(chip);
4842
	err = mv88e6xxx_switch_reset(chip);
4843
	mv88e6xxx_reg_unlock(chip);
4844 4845 4846
	if (err)
		goto out;

4847 4848 4849 4850 4851 4852
	if (np) {
		chip->irq = of_irq_get(np, 0);
		if (chip->irq == -EPROBE_DEFER) {
			err = chip->irq;
			goto out;
		}
4853 4854
	}

4855 4856 4857
	if (pdata)
		chip->irq = pdata->irq;

4858
	/* Has to be performed before the MDIO bus is created, because
4859
	 * the PHYs will link their interrupts to these interrupt
4860 4861
	 * controllers
	 */
4862
	mv88e6xxx_reg_lock(chip);
4863
	if (chip->irq > 0)
4864
		err = mv88e6xxx_g1_irq_setup(chip);
4865 4866
	else
		err = mv88e6xxx_irq_poll_setup(chip);
4867
	mv88e6xxx_reg_unlock(chip);
4868

4869 4870
	if (err)
		goto out;
4871

4872 4873
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
4874
		if (err)
4875
			goto out_g1_irq;
4876 4877
	}

4878 4879 4880 4881 4882 4883 4884 4885
	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;

4886
	err = mv88e6xxx_mdios_register(chip, np);
4887
	if (err)
4888
		goto out_g1_vtu_prob_irq;
4889

4890
	err = mv88e6xxx_register_switch(chip);
4891 4892
	if (err)
		goto out_mdio;
4893

4894
	return 0;
4895 4896

out_mdio:
4897
	mv88e6xxx_mdios_unregister(chip);
4898
out_g1_vtu_prob_irq:
4899
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
4900
out_g1_atu_prob_irq:
4901
	mv88e6xxx_g1_atu_prob_irq_free(chip);
4902
out_g2_irq:
4903
	if (chip->info->g2_irqs > 0)
4904 4905
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
4906
	if (chip->irq > 0)
4907
		mv88e6xxx_g1_irq_free(chip);
4908 4909
	else
		mv88e6xxx_irq_poll_free(chip);
4910
out:
4911 4912 4913
	if (pdata)
		dev_put(pdata->netdev);

4914
	return err;
4915
}
4916 4917 4918 4919

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

4922 4923
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
4924
		mv88e6xxx_ptp_free(chip);
4925
	}
4926

4927
	mv88e6xxx_phy_destroy(chip);
4928
	mv88e6xxx_unregister_switch(chip);
4929
	mv88e6xxx_mdios_unregister(chip);
4930

4931 4932 4933 4934 4935 4936 4937
	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)
4938
		mv88e6xxx_g1_irq_free(chip);
4939 4940
	else
		mv88e6xxx_irq_poll_free(chip);
4941 4942 4943
}

static const struct of_device_id mv88e6xxx_of_match[] = {
4944 4945 4946 4947
	{
		.compatible = "marvell,mv88e6085",
		.data = &mv88e6xxx_table[MV88E6085],
	},
4948 4949 4950 4951
	{
		.compatible = "marvell,mv88e6190",
		.data = &mv88e6xxx_table[MV88E6190],
	},
4952 4953 4954 4955
	{
		.compatible = "marvell,mv88e6250",
		.data = &mv88e6xxx_table[MV88E6250],
	},
4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966
	{ /* 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,
4967
		.pm = &mv88e6xxx_pm_ops,
4968 4969 4970
	},
};

4971
mdio_module_driver(mv88e6xxx_driver);
4972 4973 4974 4975

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