chip.c 137.5 KB
Newer Older
1
/*
2 3
 * Marvell 88e6xxx Ethernet switch single-chip support
 *
4 5
 * Copyright (c) 2008 Marvell Semiconductor
 *
6 7
 * Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch>
 *
V
Vivien Didelot 已提交
8 9 10
 * Copyright (c) 2016-2017 Savoir-faire Linux Inc.
 *	Vivien Didelot <vivien.didelot@savoirfairelinux.com>
 *
11 12 13 14 15 16
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */

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

38
#include "chip.h"
39
#include "global1.h"
40
#include "global2.h"
41
#include "hwtstamp.h"
42
#include "phy.h"
43
#include "port.h"
44
#include "ptp.h"
45
#include "serdes.h"
46
#include "smi.h"
47

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

56
int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val)
57 58 59
{
	int err;

60
	assert_reg_lock(chip);
61

62
	err = mv88e6xxx_smi_read(chip, addr, reg, val);
63 64 65
	if (err)
		return err;

66
	dev_dbg(chip->dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
67 68 69 70 71
		addr, reg, *val);

	return 0;
}

72
int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val)
73
{
74 75
	int err;

76
	assert_reg_lock(chip);
77

78
	err = mv88e6xxx_smi_write(chip, addr, reg, val);
79 80 81
	if (err)
		return err;

82
	dev_dbg(chip->dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
83 84
		addr, reg, val);

85 86 87
	return 0;
}

88
struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
89 90 91 92 93 94 95 96 97 98 99
{
	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;
}

100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
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);
}

116
static irqreturn_t mv88e6xxx_g1_irq_thread_work(struct mv88e6xxx_chip *chip)
117 118 119 120 121
{
	unsigned int nhandled = 0;
	unsigned int sub_irq;
	unsigned int n;
	u16 reg;
122
	u16 ctl1;
123 124 125
	int err;

	mutex_lock(&chip->reg_lock);
126
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
127 128 129 130 131
	mutex_unlock(&chip->reg_lock);

	if (err)
		goto out;

132 133 134 135 136 137 138 139
	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;
			}
140
		}
141 142 143 144 145 146 147 148 149 150 151 152 153

		mutex_lock(&chip->reg_lock);
		err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &ctl1);
		if (err)
			goto unlock;
		err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
unlock:
		mutex_unlock(&chip->reg_lock);
		if (err)
			goto out;
		ctl1 &= GENMASK(chip->g1_irq.nirqs, 0);
	} while (reg & ctl1);

154 155 156 157
out:
	return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
}

158 159 160 161 162 163 164
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);
}

165 166 167 168 169 170 171 172 173 174 175 176 177 178
static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
{
	struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);

	mutex_lock(&chip->reg_lock);
}

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;

179
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &reg);
180 181 182 183 184 185
	if (err)
		goto out;

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

186
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, reg);
187 188 189 190 191 192 193
	if (err)
		goto out;

out:
	mutex_unlock(&chip->reg_lock);
}

194
static const struct irq_chip mv88e6xxx_g1_irq_chip = {
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
	.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,
};

220
/* To be called with reg_lock held */
221
static void mv88e6xxx_g1_irq_free_common(struct mv88e6xxx_chip *chip)
222 223
{
	int irq, virq;
224 225
	u16 mask;

226
	mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
227
	mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
228
	mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
229

230
	for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
231
		virq = irq_find_mapping(chip->g1_irq.domain, irq);
232 233 234
		irq_dispose_mapping(virq);
	}

235
	irq_domain_remove(chip->g1_irq.domain);
236 237
}

238 239
static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
{
240 241 242 243
	/*
	 * free_irq must be called without reg_lock taken because the irq
	 * handler takes this lock, too.
	 */
244
	free_irq(chip->irq, chip);
245 246 247 248

	mutex_lock(&chip->reg_lock);
	mv88e6xxx_g1_irq_free_common(chip);
	mutex_unlock(&chip->reg_lock);
249 250 251
}

static int mv88e6xxx_g1_irq_setup_common(struct mv88e6xxx_chip *chip)
252
{
253 254
	int err, irq, virq;
	u16 reg, mask;
255 256 257 258 259 260 261 262 263 264 265 266 267 268

	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;

269
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
270
	if (err)
271
		goto out_mapping;
272

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

275
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
276
	if (err)
277
		goto out_disable;
278 279

	/* Reading the interrupt status clears (most of) them */
280
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
281
	if (err)
282
		goto out_disable;
283 284 285

	return 0;

286
out_disable:
287
	mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
288
	mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
289 290 291 292 293 294 295 296

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);
297 298 299 300

	return err;
}

301 302
static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
{
303 304
	static struct lock_class_key lock_key;
	static struct lock_class_key request_key;
305 306 307 308 309 310
	int err;

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

311 312 313 314 315 316
	/* 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);

317
	mutex_unlock(&chip->reg_lock);
318 319
	err = request_threaded_irq(chip->irq, NULL,
				   mv88e6xxx_g1_irq_thread_fn,
320
				   IRQF_ONESHOT | IRQF_SHARED,
321
				   dev_name(chip->dev), chip);
322
	mutex_lock(&chip->reg_lock);
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
	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);

351
	chip->kworker = kthread_create_worker(0, "%s", dev_name(chip->dev));
352 353 354 355 356 357 358 359 360 361 362 363 364
	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);
365 366 367 368

	mutex_lock(&chip->reg_lock);
	mv88e6xxx_g1_irq_free_common(chip);
	mutex_unlock(&chip->reg_lock);
369 370
}

371
int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask)
372
{
373
	int i;
374

375
	for (i = 0; i < 16; i++) {
376 377 378 379 380 381 382 383 384 385 386 387 388
		u16 val;
		int err;

		err = mv88e6xxx_read(chip, addr, reg, &val);
		if (err)
			return err;

		if (!(val & mask))
			return 0;

		usleep_range(1000, 2000);
	}

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

393
/* Indirect write to single pointer-data register with an Update bit */
394
int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
395 396
{
	u16 val;
397
	int err;
398 399

	/* Wait until the previous operation is completed */
400 401 402
	err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
	if (err)
		return err;
403 404 405 406 407 408 409

	/* Set the Update bit to trigger a write operation */
	val = BIT(15) | update;

	return mv88e6xxx_write(chip, addr, reg, val);
}

410 411 412
int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port, int link,
			     int speed, int duplex, int pause,
			     phy_interface_t mode)
413
{
414
	struct phylink_link_state state;
415 416 417 418 419
	int err;

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

420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
	if (!chip->info->ops->port_link_state)
		return 0;

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

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

436 437 438 439 440 441 442 443 444 445 446
	/* Port's MAC control must not be changed unless the link is down */
	err = chip->info->ops->port_set_link(chip, port, 0);
	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;
	}

447 448 449
	if (speed == SPEED_MAX && chip->info->ops->port_max_speed_mode)
		mode = chip->info->ops->port_max_speed_mode(port);

450 451 452 453 454 455
	if (chip->info->ops->port_set_pause) {
		err = chip->info->ops->port_set_pause(chip, port, pause);
		if (err)
			goto restore_link;
	}

456 457 458 459 460 461 462 463 464 465 466 467
	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;
	}

468 469 470 471 472 473
	if (chip->info->ops->port_set_cmode) {
		err = chip->info->ops->port_set_cmode(chip, port, mode);
		if (err && err != -EOPNOTSUPP)
			goto restore_link;
	}

474 475 476
	err = 0;
restore_link:
	if (chip->info->ops->port_set_link(chip, port, link))
477
		dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
478 479 480 481

	return err;
}

482 483 484 485 486 487 488
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;
}

489 490 491 492
/* We expect the switch to perform auto negotiation if there is a real
 * phy. However, in the case of a fixed link phy, we force the port
 * settings from the fixed link settings.
 */
493 494
static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
				  struct phy_device *phydev)
495
{
V
Vivien Didelot 已提交
496
	struct mv88e6xxx_chip *chip = ds->priv;
497
	int err;
498

499 500
	if (!phy_is_pseudo_fixed_link(phydev) &&
	    mv88e6xxx_phy_is_internal(ds, port))
501 502
		return;

503
	mutex_lock(&chip->reg_lock);
504
	err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
505 506
				       phydev->duplex, phydev->pause,
				       phydev->interface);
507
	mutex_unlock(&chip->reg_lock);
508 509

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

513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
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);
}

539 540 541 542 543 544 545 546 547 548 549 550 551 552
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);
}

553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
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)
{
568
	if (port >= 9) {
569
		phylink_set(mask, 2500baseX_Full);
570 571
		phylink_set(mask, 2500baseT_Full);
	}
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591

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

592 593 594 595
static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
			       unsigned long *supported,
			       struct phylink_link_state *state)
{
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614
	__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);
615 616 617 618 619 620 621 622 623
}

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

	mutex_lock(&chip->reg_lock);
624 625 626 627
	if (chip->info->ops->port_link_state)
		err = chip->info->ops->port_link_state(chip, port, state);
	else
		err = -EOPNOTSUPP;
628 629 630 631 632 633 634 635 636 637
	mutex_unlock(&chip->reg_lock);

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

640
	if ((mode == MLO_AN_PHY) && mv88e6xxx_phy_is_internal(ds, port))
641 642 643 644 645 646
		return;

	if (mode == MLO_AN_FIXED) {
		link = LINK_FORCED_UP;
		speed = state->speed;
		duplex = state->duplex;
647 648 649 650
	} else if (!mv88e6xxx_phy_is_internal(ds, port)) {
		link = state->link;
		speed = state->speed;
		duplex = state->duplex;
651 652 653 654 655
	} else {
		speed = SPEED_UNFORCED;
		duplex = DUPLEX_UNFORCED;
		link = LINK_UNFORCED;
	}
656
	pause = !!phylink_test(state->advertising, Pause);
657 658

	mutex_lock(&chip->reg_lock);
659
	err = mv88e6xxx_port_setup_mac(chip, port, link, speed, duplex, pause,
660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695
				       state->interface);
	mutex_unlock(&chip->reg_lock);

	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;

	mutex_lock(&chip->reg_lock);
	err = chip->info->ops->port_set_link(chip, port, link);
	mutex_unlock(&chip->reg_lock);

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

696
static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
697
{
698 699
	if (!chip->info->ops->stats_snapshot)
		return -EOPNOTSUPP;
700

701
	return chip->info->ops->stats_snapshot(chip, port);
702 703
}

704
static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763
	{ "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, },
764 765
};

766
static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
767
					    struct mv88e6xxx_hw_stat *s,
768 769
					    int port, u16 bank1_select,
					    u16 histogram)
770 771 772
{
	u32 low;
	u32 high = 0;
773
	u16 reg = 0;
774
	int err;
775 776
	u64 value;

777
	switch (s->type) {
778
	case STATS_TYPE_PORT:
779 780
		err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
		if (err)
781
			return U64_MAX;
782

783
		low = reg;
784
		if (s->size == 4) {
785 786
			err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
			if (err)
787
				return U64_MAX;
788
			low |= ((u32)reg) << 16;
789
		}
790
		break;
791
	case STATS_TYPE_BANK1:
792
		reg = bank1_select;
793 794
		/* fall through */
	case STATS_TYPE_BANK0:
795
		reg |= s->reg | histogram;
796
		mv88e6xxx_g1_stats_read(chip, reg, &low);
797
		if (s->size == 8)
798
			mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
799 800
		break;
	default:
801
		return U64_MAX;
802
	}
803
	value = (((u64)high) << 32) | low;
804 805 806
	return value;
}

807 808
static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data, int types)
809
{
810 811
	struct mv88e6xxx_hw_stat *stat;
	int i, j;
812

813 814
	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
		stat = &mv88e6xxx_hw_stats[i];
815
		if (stat->type & types) {
816 817 818 819
			memcpy(data + j * ETH_GSTRING_LEN, stat->string,
			       ETH_GSTRING_LEN);
			j++;
		}
820
	}
821 822

	return j;
823 824
}

825 826
static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
827
{
828 829
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_PORT);
830 831
}

832 833
static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
834
{
835 836
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
837 838
}

839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856
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);
}

857
static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
858
				  u32 stringset, uint8_t *data)
859
{
V
Vivien Didelot 已提交
860
	struct mv88e6xxx_chip *chip = ds->priv;
861
	int count = 0;
862

863 864 865
	if (stringset != ETH_SS_STATS)
		return;

866 867
	mutex_lock(&chip->reg_lock);

868
	if (chip->info->ops->stats_get_strings)
869 870 871 872
		count = chip->info->ops->stats_get_strings(chip, data);

	if (chip->info->ops->serdes_get_strings) {
		data += count * ETH_GSTRING_LEN;
873
		count = chip->info->ops->serdes_get_strings(chip, port, data);
874
	}
875

876 877 878
	data += count * ETH_GSTRING_LEN;
	mv88e6xxx_atu_vtu_get_strings(data);

879
	mutex_unlock(&chip->reg_lock);
880 881 882 883 884
}

static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
					  int types)
{
885 886 887 888 889
	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];
890
		if (stat->type & types)
891 892 893
			j++;
	}
	return j;
894 895
}

896 897 898 899 900 901 902 903 904 905 906 907
static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
{
	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
					      STATS_TYPE_PORT);
}

static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
{
	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
					      STATS_TYPE_BANK1);
}

908
static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
909 910
{
	struct mv88e6xxx_chip *chip = ds->priv;
911 912
	int serdes_count = 0;
	int count = 0;
913

914 915 916
	if (sset != ETH_SS_STATS)
		return 0;

917
	mutex_lock(&chip->reg_lock);
918
	if (chip->info->ops->stats_get_sset_count)
919 920 921 922 923 924 925
		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);
926
	if (serdes_count < 0) {
927
		count = serdes_count;
928 929 930 931 932
		goto out;
	}
	count += serdes_count;
	count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);

933
out:
934
	mutex_unlock(&chip->reg_lock);
935

936
	return count;
937 938
}

939 940 941
static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data, int types,
				     u16 bank1_select, u16 histogram)
942 943 944 945 946 947 948
{
	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) {
949
			mutex_lock(&chip->reg_lock);
950 951 952
			data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
							      bank1_select,
							      histogram);
953 954
			mutex_unlock(&chip->reg_lock);

955 956 957
			j++;
		}
	}
958
	return j;
959 960
}

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

969 970
static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
971 972
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
973
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
974 975
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
					 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
976 977
}

978 979
static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
980 981 982
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
983 984
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
					 0);
985 986
}

987 988 989 990 991 992 993 994 995 996
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;
}

997 998 999
static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
				uint64_t *data)
{
1000 1001
	int count = 0;

1002
	if (chip->info->ops->stats_get_stats)
1003 1004
		count = chip->info->ops->stats_get_stats(chip, port, data);

1005
	mutex_lock(&chip->reg_lock);
1006 1007
	if (chip->info->ops->serdes_get_stats) {
		data += count;
1008
		count = chip->info->ops->serdes_get_stats(chip, port, data);
1009
	}
1010 1011 1012
	data += count;
	mv88e6xxx_atu_vtu_get_stats(chip, port, data);
	mutex_unlock(&chip->reg_lock);
1013 1014
}

1015 1016
static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
					uint64_t *data)
1017
{
V
Vivien Didelot 已提交
1018
	struct mv88e6xxx_chip *chip = ds->priv;
1019 1020
	int ret;

1021
	mutex_lock(&chip->reg_lock);
1022

1023
	ret = mv88e6xxx_stats_snapshot(chip, port);
1024 1025 1026
	mutex_unlock(&chip->reg_lock);

	if (ret < 0)
1027
		return;
1028 1029

	mv88e6xxx_get_stats(chip, port, data);
1030

1031 1032
}

1033
static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
1034 1035 1036 1037
{
	return 32 * sizeof(u16);
}

1038 1039
static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
			       struct ethtool_regs *regs, void *_p)
1040
{
V
Vivien Didelot 已提交
1041
	struct mv88e6xxx_chip *chip = ds->priv;
1042 1043
	int err;
	u16 reg;
1044 1045 1046
	u16 *p = _p;
	int i;

1047
	regs->version = chip->info->prod_num;
1048 1049 1050

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

1051
	mutex_lock(&chip->reg_lock);
1052

1053 1054
	for (i = 0; i < 32; i++) {

1055 1056 1057
		err = mv88e6xxx_port_read(chip, port, i, &reg);
		if (!err)
			p[i] = reg;
1058
	}
1059

1060
	mutex_unlock(&chip->reg_lock);
1061 1062
}

V
Vivien Didelot 已提交
1063 1064
static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
1065
{
1066 1067
	/* Nothing to do on the port's MAC */
	return 0;
1068 1069
}

V
Vivien Didelot 已提交
1070 1071
static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
1072
{
1073 1074
	/* Nothing to do on the port's MAC */
	return 0;
1075 1076
}

1077
static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
1078
{
1079 1080 1081
	struct dsa_switch *ds = NULL;
	struct net_device *br;
	u16 pvlan;
1082 1083
	int i;

1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103
	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 已提交
1104
		    (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
1105 1106 1107 1108 1109
			pvlan |= BIT(i);

	return pvlan;
}

1110
static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
1111 1112
{
	u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
1113 1114 1115

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

1117
	return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
1118 1119
}

1120 1121
static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
					 u8 state)
1122
{
V
Vivien Didelot 已提交
1123
	struct mv88e6xxx_chip *chip = ds->priv;
1124
	int err;
1125

1126
	mutex_lock(&chip->reg_lock);
1127
	err = mv88e6xxx_port_set_state(chip, port, state);
1128
	mutex_unlock(&chip->reg_lock);
1129 1130

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

1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152
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;
}

1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172
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;
	}

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

1180 1181 1182 1183
	err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
	if (err)
		return err;

1184 1185 1186
	return 0;
}

1187 1188 1189 1190 1191 1192 1193 1194 1195
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;
}

1196 1197 1198 1199 1200 1201 1202 1203
static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->rmu_disable)
		return chip->info->ops->rmu_disable(chip);

	return 0;
}

1204 1205 1206 1207 1208 1209 1210 1211
static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->pot_clear)
		return chip->info->ops->pot_clear(chip);

	return 0;
}

1212 1213 1214 1215 1216 1217 1218 1219
static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->mgmt_rsvd2cpu)
		return chip->info->ops->mgmt_rsvd2cpu(chip);

	return 0;
}

1220 1221
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
1222 1223
	int err;

1224 1225 1226 1227
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

1228 1229 1230 1231
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

1232 1233 1234
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

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

1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267
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;
}

1268 1269 1270 1271 1272 1273 1274 1275 1276
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)
1277
		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1278 1279 1280 1281

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

1282 1283
static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
{
1284 1285 1286
	int dev, port;
	int err;

1287 1288 1289 1290 1291 1292
	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.
	 */
1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305
	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;
1306 1307
}

1308 1309 1310 1311 1312 1313
static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

	mutex_lock(&chip->reg_lock);
1314
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1315 1316 1317
	mutex_unlock(&chip->reg_lock);

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

1321 1322 1323 1324 1325 1326 1327 1328
static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
{
	if (!chip->info->max_vid)
		return 0;

	return mv88e6xxx_g1_vtu_flush(chip);
}

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

1338 1339 1340 1341 1342 1343 1344 1345 1346
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);
}

1347
static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1348 1349
{
	DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1350 1351 1352
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = chip->info->max_vid,
	};
1353
	int i, err;
1354 1355 1356

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

1357
	/* Set every FID bit used by the (un)bridged ports */
1358
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1359
		err = mv88e6xxx_port_get_fid(chip, i, fid);
1360 1361 1362 1363 1364 1365
		if (err)
			return err;

		set_bit(*fid, fid_bitmap);
	}

1366 1367
	/* Set every FID bit used by the VLAN entries */
	do {
1368
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1369 1370 1371 1372 1373 1374 1375
		if (err)
			return err;

		if (!vlan.valid)
			break;

		set_bit(vlan.fid, fid_bitmap);
1376
	} while (vlan.vid < chip->info->max_vid);
1377 1378 1379 1380 1381

	/* 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);
1382
	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1383 1384 1385
		return -ENOSPC;

	/* Clear the database */
1386
	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1387 1388
}

1389 1390
static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
			     struct mv88e6xxx_vtu_entry *entry, bool new)
1391 1392 1393 1394 1395 1396
{
	int err;

	if (!vid)
		return -EINVAL;

1397 1398
	entry->vid = vid - 1;
	entry->valid = false;
1399

1400
	err = mv88e6xxx_vtu_getnext(chip, entry);
1401 1402 1403
	if (err)
		return err;

1404 1405
	if (entry->vid == vid && entry->valid)
		return 0;
1406

1407 1408 1409 1410 1411 1412 1413 1414
	if (new) {
		int i;

		/* Initialize a fresh VLAN entry */
		memset(entry, 0, sizeof(*entry));
		entry->valid = true;
		entry->vid = vid;

1415
		/* Exclude all ports */
1416
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1417
			entry->member[i] =
1418
				MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1419 1420

		return mv88e6xxx_atu_new(chip, &entry->fid);
1421 1422
	}

1423 1424
	/* switchdev expects -EOPNOTSUPP to honor software VLANs */
	return -EOPNOTSUPP;
1425 1426
}

1427 1428 1429
static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
					u16 vid_begin, u16 vid_end)
{
V
Vivien Didelot 已提交
1430
	struct mv88e6xxx_chip *chip = ds->priv;
1431 1432 1433
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = vid_begin - 1,
	};
1434 1435
	int i, err;

1436 1437 1438 1439
	/* 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;

1440 1441 1442
	if (!vid_begin)
		return -EOPNOTSUPP;

1443
	mutex_lock(&chip->reg_lock);
1444 1445

	do {
1446
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1447 1448 1449 1450 1451 1452 1453 1454 1455
		if (err)
			goto unlock;

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

1456
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1457 1458 1459
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

1460
			if (!ds->ports[i].slave)
1461 1462
				continue;

1463
			if (vlan.member[i] ==
1464
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1465 1466
				continue;

V
Vivien Didelot 已提交
1467
			if (dsa_to_port(ds, i)->bridge_dev ==
1468
			    ds->ports[port].bridge_dev)
1469 1470
				break; /* same bridge, check next VLAN */

V
Vivien Didelot 已提交
1471
			if (!dsa_to_port(ds, i)->bridge_dev)
1472 1473
				continue;

1474 1475
			dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
				port, vlan.vid, i,
V
Vivien Didelot 已提交
1476
				netdev_name(dsa_to_port(ds, i)->bridge_dev));
1477 1478 1479 1480 1481 1482
			err = -EOPNOTSUPP;
			goto unlock;
		}
	} while (vlan.vid < vid_end);

unlock:
1483
	mutex_unlock(&chip->reg_lock);
1484 1485 1486 1487

	return err;
}

1488 1489
static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
					 bool vlan_filtering)
1490
{
V
Vivien Didelot 已提交
1491
	struct mv88e6xxx_chip *chip = ds->priv;
1492 1493
	u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
		MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
1494
	int err;
1495

1496
	if (!chip->info->max_vid)
1497 1498
		return -EOPNOTSUPP;

1499
	mutex_lock(&chip->reg_lock);
1500
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1501
	mutex_unlock(&chip->reg_lock);
1502

1503
	return err;
1504 1505
}

1506 1507
static int
mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1508
			    const struct switchdev_obj_port_vlan *vlan)
1509
{
V
Vivien Didelot 已提交
1510
	struct mv88e6xxx_chip *chip = ds->priv;
1511 1512
	int err;

1513
	if (!chip->info->max_vid)
1514 1515
		return -EOPNOTSUPP;

1516 1517 1518 1519 1520 1521 1522 1523
	/* 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.
	 */
	err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
					   vlan->vid_end);
	if (err)
		return err;

1524 1525 1526 1527 1528 1529
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */
	return 0;
}

1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573
static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
					const unsigned char *addr, u16 vid,
					u8 state)
{
	struct mv88e6xxx_vtu_entry vlan;
	struct mv88e6xxx_atu_entry entry;
	int err;

	/* Null VLAN ID corresponds to the port private database */
	if (vid == 0)
		err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
	else
		err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
	if (err)
		return err;

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

	err = mv88e6xxx_g1_atu_getnext(chip, vlan.fid, &entry);
	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;
	}

	return mv88e6xxx_g1_atu_loadpurge(chip, vlan.fid, &entry);
}

1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596
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;
}

1597
static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
1598
				    u16 vid, u8 member)
1599
{
1600
	struct mv88e6xxx_vtu_entry vlan;
1601 1602
	int err;

1603
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
1604
	if (err)
1605
		return err;
1606

1607
	vlan.member[port] = member;
1608

1609 1610 1611 1612 1613
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
	if (err)
		return err;

	return mv88e6xxx_broadcast_setup(chip, vid);
1614 1615
}

1616
static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1617
				    const struct switchdev_obj_port_vlan *vlan)
1618
{
V
Vivien Didelot 已提交
1619
	struct mv88e6xxx_chip *chip = ds->priv;
1620 1621
	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1622
	u8 member;
1623 1624
	u16 vid;

1625
	if (!chip->info->max_vid)
1626 1627
		return;

1628
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1629
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1630
	else if (untagged)
1631
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
1632
	else
1633
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
1634

1635
	mutex_lock(&chip->reg_lock);
1636

1637
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
1638
		if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
1639 1640
			dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
				vid, untagged ? 'u' : 't');
1641

1642
	if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1643 1644
		dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
			vlan->vid_end);
1645

1646
	mutex_unlock(&chip->reg_lock);
1647 1648
}

1649
static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
1650
				    int port, u16 vid)
1651
{
1652
	struct mv88e6xxx_vtu_entry vlan;
1653 1654
	int i, err;

1655
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1656
	if (err)
1657
		return err;
1658

1659
	/* Tell switchdev if this VLAN is handled in software */
1660
	if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1661
		return -EOPNOTSUPP;
1662

1663
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1664 1665

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

1675
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1676 1677 1678
	if (err)
		return err;

1679
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
1680 1681
}

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

1689
	if (!chip->info->max_vid)
1690 1691
		return -EOPNOTSUPP;

1692
	mutex_lock(&chip->reg_lock);
1693

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

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

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

1710
unlock:
1711
	mutex_unlock(&chip->reg_lock);
1712 1713 1714 1715

	return err;
}

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

1722
	mutex_lock(&chip->reg_lock);
1723 1724
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1725
	mutex_unlock(&chip->reg_lock);
1726 1727

	return err;
1728 1729
}

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

1736
	mutex_lock(&chip->reg_lock);
1737
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1738
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
1739
	mutex_unlock(&chip->reg_lock);
1740

1741
	return err;
1742 1743
}

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

1752
	addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1753
	eth_broadcast_addr(addr.mac);
1754 1755

	do {
1756
		mutex_lock(&chip->reg_lock);
1757
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
1758
		mutex_unlock(&chip->reg_lock);
1759
		if (err)
1760
			return err;
1761

1762
		if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
1763 1764
			break;

1765
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
1766 1767
			continue;

1768 1769
		if (!is_unicast_ether_addr(addr.mac))
			continue;
1770

1771 1772 1773
		is_static = (addr.state ==
			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
		err = cb(addr.mac, vid, is_static, data);
1774 1775
		if (err)
			return err;
1776 1777 1778 1779 1780
	} while (!is_broadcast_ether_addr(addr.mac));

	return err;
}

1781
static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1782
				  dsa_fdb_dump_cb_t *cb, void *data)
1783
{
1784
	struct mv88e6xxx_vtu_entry vlan = {
1785
		.vid = chip->info->max_vid,
1786
	};
1787
	u16 fid;
1788 1789
	int err;

1790
	/* Dump port's default Filtering Information Database (VLAN ID 0) */
1791
	mutex_lock(&chip->reg_lock);
1792
	err = mv88e6xxx_port_get_fid(chip, port, &fid);
1793 1794
	mutex_unlock(&chip->reg_lock);

1795
	if (err)
1796
		return err;
1797

1798
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
1799
	if (err)
1800
		return err;
1801

1802
	/* Dump VLANs' Filtering Information Databases */
1803
	do {
1804
		mutex_lock(&chip->reg_lock);
1805
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1806
		mutex_unlock(&chip->reg_lock);
1807
		if (err)
1808
			return err;
1809 1810 1811 1812

		if (!vlan.valid)
			break;

1813
		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1814
						 cb, data);
1815
		if (err)
1816
			return err;
1817
	} while (vlan.vid < chip->info->max_vid);
1818

1819 1820 1821 1822
	return err;
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1823
				   dsa_fdb_dump_cb_t *cb, void *data)
1824
{
V
Vivien Didelot 已提交
1825
	struct mv88e6xxx_chip *chip = ds->priv;
1826

1827
	return mv88e6xxx_port_db_dump(chip, port, cb, data);
1828 1829
}

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

1838 1839 1840 1841
	/* 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);
1842
			if (err)
1843
				return err;
1844 1845 1846
		}
	}

1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864
	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;
			}
		}
	}

1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875
	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;

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_bridge_map(chip, br);
1876
	mutex_unlock(&chip->reg_lock);
1877

1878
	return err;
1879 1880
}

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

1886
	mutex_lock(&chip->reg_lock);
1887 1888 1889
	if (mv88e6xxx_bridge_map(chip, br) ||
	    mv88e6xxx_port_vlan_map(chip, port))
		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
1890
	mutex_unlock(&chip->reg_lock);
1891 1892
}

1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922
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;

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_pvt_map(chip, dev, port);
	mutex_unlock(&chip->reg_lock);

	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;

	mutex_lock(&chip->reg_lock);
	if (mv88e6xxx_pvt_map(chip, dev, port))
		dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
	mutex_unlock(&chip->reg_lock);
}

1923 1924 1925 1926 1927 1928 1929 1930
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->reset)
		return chip->info->ops->reset(chip);

	return 0;
}

1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943
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);
	}
}

1944
static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1945
{
1946
	int i, err;
1947

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

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

1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970
	return 0;
}

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

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

1971
	mv88e6xxx_hardware_reset(chip);
1972

1973
	return mv88e6xxx_software_reset(chip);
1974 1975
}

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

1982 1983 1984 1985
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
1986 1987 1988
	if (err)
		return err;

1989 1990 1991 1992 1993 1994 1995 1996
	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;
1997 1998
}

1999
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2000
{
2001
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
2002
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2003
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2004
}
2005

2006 2007 2008
static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
2009
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2010
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2011
}
2012

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

2021 2022 2023 2024
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);
2025

2026
	if (dsa_is_user_port(chip->ds, port))
2027
		return mv88e6xxx_set_port_mode_normal(chip, port);
2028

2029 2030 2031
	/* 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);
2032

2033 2034
	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
		return mv88e6xxx_set_port_mode_edsa(chip, port);
2035

2036
	return -EINVAL;
2037 2038
}

2039
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2040
{
2041
	bool message = dsa_is_dsa_port(chip->ds, port);
2042

2043
	return mv88e6xxx_port_set_message_port(chip, port, message);
2044
}
2045

2046
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2047
{
2048 2049
	struct dsa_switch *ds = chip->ds;
	bool flood;
2050

2051
	/* Upstream ports flood frames with unknown unicast or multicast DA */
2052
	flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
2053 2054 2055
	if (chip->info->ops->port_set_egress_floods)
		return chip->info->ops->port_set_egress_floods(chip, port,
							       flood, flood);
2056

2057
	return 0;
2058 2059
}

2060 2061 2062
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
2063 2064
	if (chip->info->ops->serdes_power)
		return chip->info->ops->serdes_power(chip, port, on);
2065

2066
	return 0;
2067 2068
}

2069 2070 2071 2072 2073 2074
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

2075
	upstream_port = dsa_upstream_port(ds, port);
2076 2077 2078 2079 2080 2081 2082
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098
	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;
		}
	}

2099 2100 2101
	return 0;
}

2102
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
2103
{
2104
	struct dsa_switch *ds = chip->ds;
2105
	int err;
2106
	u16 reg;
2107

2108 2109 2110
	chip->ports[port].chip = chip;
	chip->ports[port].port = port;

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

	/* 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.
	 */
2142 2143 2144 2145
	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);
2146 2147
	if (err)
		return err;
2148

2149
	err = mv88e6xxx_setup_port_mode(chip, port);
2150 2151
	if (err)
		return err;
2152

2153
	err = mv88e6xxx_setup_egress_floods(chip, port);
2154 2155 2156
	if (err)
		return err;

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

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

2177 2178 2179
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
2180

2181
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
2182
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
2183 2184 2185
	if (err)
		return err;

2186 2187
	if (chip->info->ops->port_set_jumbo_size) {
		err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
2188 2189 2190 2191
		if (err)
			return err;
	}

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

2202 2203
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
2204 2205
	if (err)
		return err;
2206 2207

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

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

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

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

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

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

2243
	err = mv88e6xxx_setup_message_port(chip, port);
2244 2245
	if (err)
		return err;
2246

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

2255
	err = mv88e6xxx_port_vlan_map(chip, port);
2256 2257
	if (err)
		return err;
2258 2259 2260 2261

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

2265 2266 2267 2268
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
2269
	int err;
2270 2271

	mutex_lock(&chip->reg_lock);
2272

2273
	err = mv88e6xxx_serdes_power(chip, port, true);
2274 2275 2276 2277

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

2278 2279 2280 2281 2282
	mutex_unlock(&chip->reg_lock);

	return err;
}

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

	mutex_lock(&chip->reg_lock);
2288

2289 2290 2291
	if (mv88e6xxx_port_set_state(chip, port, BR_STATE_DISABLED))
		dev_err(chip->dev, "failed to disable port\n");

2292 2293 2294
	if (chip->info->ops->serdes_irq_free)
		chip->info->ops->serdes_irq_free(chip, port);

2295 2296
	if (mv88e6xxx_serdes_power(chip, port, false))
		dev_err(chip->dev, "failed to power off SERDES\n");
2297

2298 2299 2300
	mutex_unlock(&chip->reg_lock);
}

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

	mutex_lock(&chip->reg_lock);
2308
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2309 2310 2311 2312 2313
	mutex_unlock(&chip->reg_lock);

	return err;
}

2314
static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
2315
{
2316
	int err;
2317

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

2325
	return mv88e6xxx_g1_stats_clear(chip);
2326 2327
}

2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 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 2423 2424 2425 2426 2427 2428
/* 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)
{
	return mv88e6xxx_wait(chip, PORT_RESERVED_1A_CTRL_PORT,
			      PORT_RESERVED_1A, PORT_RESERVED_1A_BUSY);
}


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

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

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

2439
	mutex_lock(&chip->reg_lock);
2440

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

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

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

2458
	/* Setup Switch Port Registers */
2459
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2460 2461 2462 2463 2464 2465 2466 2467 2468 2469
		if (dsa_is_unused_port(ds, i)) {
			err = mv88e6xxx_port_set_state(chip, i,
						       BR_STATE_DISABLED);
			if (err)
				goto unlock;

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

2470
			continue;
2471
		}
2472

2473 2474 2475 2476 2477
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

2478 2479 2480 2481
	err = mv88e6xxx_irl_setup(chip);
	if (err)
		goto unlock;

2482 2483 2484 2485
	err = mv88e6xxx_mac_setup(chip);
	if (err)
		goto unlock;

2486 2487 2488 2489
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

2490 2491 2492 2493
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

2494 2495 2496 2497
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

2498 2499 2500 2501
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

2502 2503 2504 2505
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

2506 2507 2508 2509
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

2510 2511 2512 2513
	err = mv88e6xxx_rmu_setup(chip);
	if (err)
		goto unlock;

2514 2515 2516
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
2517

2518 2519 2520 2521
	err = mv88e6xxx_trunk_setup(chip);
	if (err)
		goto unlock;

2522 2523 2524 2525
	err = mv88e6xxx_devmap_setup(chip);
	if (err)
		goto unlock;

2526 2527 2528 2529
	err = mv88e6xxx_pri_setup(chip);
	if (err)
		goto unlock;

2530
	/* Setup PTP Hardware Clock and timestamping */
2531 2532 2533 2534
	if (chip->info->ptp_support) {
		err = mv88e6xxx_ptp_setup(chip);
		if (err)
			goto unlock;
2535 2536 2537 2538

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
2539 2540
	}

2541 2542 2543 2544
	err = mv88e6xxx_stats_setup(chip);
	if (err)
		goto unlock;

2545
unlock:
2546
	mutex_unlock(&chip->reg_lock);
2547

2548
	return err;
2549 2550
}

2551
static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
2552
{
2553 2554
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2555 2556
	u16 val;
	int err;
2557

2558 2559 2560
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

2561
	mutex_lock(&chip->reg_lock);
2562
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
2563
	mutex_unlock(&chip->reg_lock);
2564

2565
	if (reg == MII_PHYSID2) {
2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581
		/* 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;
2582 2583
	}

2584
	return err ? err : val;
2585 2586
}

2587
static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
2588
{
2589 2590
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2591
	int err;
2592

2593 2594 2595
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

2596
	mutex_lock(&chip->reg_lock);
2597
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
2598
	mutex_unlock(&chip->reg_lock);
2599 2600

	return err;
2601 2602
}

2603
static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
2604 2605
				   struct device_node *np,
				   bool external)
2606 2607
{
	static int index;
2608
	struct mv88e6xxx_mdio_bus *mdio_bus;
2609 2610 2611
	struct mii_bus *bus;
	int err;

2612 2613 2614 2615 2616 2617 2618 2619 2620
	if (external) {
		mutex_lock(&chip->reg_lock);
		err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
		mutex_unlock(&chip->reg_lock);

		if (err)
			return err;
	}

2621
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
2622 2623 2624
	if (!bus)
		return -ENOMEM;

2625
	mdio_bus = bus->priv;
2626
	mdio_bus->bus = bus;
2627
	mdio_bus->chip = chip;
2628 2629
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
2630

2631 2632
	if (np) {
		bus->name = np->full_name;
2633
		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
2634 2635 2636 2637 2638 2639 2640
	} 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;
2641
	bus->parent = chip->dev;
2642

2643 2644 2645 2646 2647 2648
	if (!external) {
		err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
		if (err)
			return err;
	}

2649
	err = of_mdiobus_register(bus, np);
2650
	if (err) {
2651
		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
2652
		mv88e6xxx_g2_irq_mdio_free(chip, bus);
2653
		return err;
2654
	}
2655 2656 2657 2658 2659

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

	return 0;
2662
}
2663

2664 2665 2666 2667 2668
static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
	{ .compatible = "marvell,mv88e6xxx-mdio-external",
	  .data = (void *)true },
	{ },
};
2669

2670 2671 2672 2673 2674 2675 2676 2677 2678
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;

2679 2680 2681
		if (!mdio_bus->external)
			mv88e6xxx_g2_irq_mdio_free(chip, bus);

2682 2683 2684 2685
		mdiobus_unregister(bus);
	}
}

2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709
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);
2710 2711
			if (err) {
				mv88e6xxx_mdios_unregister(chip);
2712
				return err;
2713
			}
2714 2715 2716 2717
		}
	}

	return 0;
2718 2719
}

2720 2721
static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
2722
	struct mv88e6xxx_chip *chip = ds->priv;
2723 2724 2725 2726 2727 2728 2729

	return chip->eeprom_len;
}

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

2733 2734
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
2735

2736 2737
	mutex_lock(&chip->reg_lock);
	err = chip->info->ops->get_eeprom(chip, eeprom, data);
2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750
	mutex_unlock(&chip->reg_lock);

	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 已提交
2751
	struct mv88e6xxx_chip *chip = ds->priv;
2752 2753
	int err;

2754 2755 2756
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

2757 2758 2759 2760
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

	mutex_lock(&chip->reg_lock);
2761
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
2762 2763 2764 2765 2766
	mutex_unlock(&chip->reg_lock);

	return err;
}

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

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

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

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

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

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

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

static const struct mv88e6xxx_ops mv88e6165_ops = {
3032
	/* MV88E6XXX_FAMILY_6165 */
3033 3034
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3035
	.irl_init_all = mv88e6352_g2_irl_init_all,
3036
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3037 3038
	.phy_read = mv88e6165_phy_read,
	.phy_write = mv88e6165_phy_write,
3039
	.port_set_link = mv88e6xxx_port_set_link,
3040
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3041
	.port_set_speed = mv88e6185_port_set_speed,
3042
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3043
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3044
	.port_link_state = mv88e6352_port_link_state,
3045
	.port_get_cmode = mv88e6185_port_get_cmode,
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
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3088
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3089 3090
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3091
	.stats_get_stats = mv88e6095_stats_get_stats,
3092 3093
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3094
	.watchdog_ops = &mv88e6097_watchdog_ops,
3095
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3096
	.pot_clear = mv88e6xxx_g2_pot_clear,
3097
	.reset = mv88e6352_g1_reset,
3098
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3099
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3100
	.phylink_validate = mv88e6185_phylink_validate,
3101 3102 3103
};

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

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

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

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

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

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

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

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

3451
static const struct mv88e6xxx_ops mv88e6290_ops = {
3452
	/* MV88E6XXX_FAMILY_6390 */
3453
	.setup_errata = mv88e6390_setup_errata,
3454
	.irl_init_all = mv88e6390_g2_irl_init_all,
3455 3456
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3457 3458 3459 3460 3461 3462 3463
	.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,
3464
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
3465
	.port_tag_remap = mv88e6390_port_tag_remap,
3466
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3467
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3468
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3469
	.port_pause_limit = mv88e6390_port_pause_limit,
3470
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3471
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3472
	.port_link_state = mv88e6352_port_link_state,
3473
	.port_get_cmode = mv88e6352_port_get_cmode,
3474
	.port_set_cmode = mv88e6390_port_set_cmode,
3475
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3476
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3477 3478
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3479
	.stats_get_stats = mv88e6390_stats_get_stats,
3480 3481
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3482
	.watchdog_ops = &mv88e6390_watchdog_ops,
3483
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3484
	.pot_clear = mv88e6xxx_g2_pot_clear,
3485
	.reset = mv88e6352_g1_reset,
3486
	.rmu_disable = mv88e6390_g1_rmu_disable,
3487 3488
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3489
	.serdes_power = mv88e6390_serdes_power,
3490 3491
	.serdes_irq_setup = mv88e6390_serdes_irq_setup,
	.serdes_irq_free = mv88e6390_serdes_irq_free,
3492
	.gpio_ops = &mv88e6352_gpio_ops,
3493
	.avb_ops = &mv88e6390_avb_ops,
3494
	.ptp_ops = &mv88e6352_ptp_ops,
3495
	.phylink_validate = mv88e6390_phylink_validate,
3496 3497
};

3498
static const struct mv88e6xxx_ops mv88e6320_ops = {
3499
	/* MV88E6XXX_FAMILY_6320 */
3500 3501
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3502
	.irl_init_all = mv88e6352_g2_irl_init_all,
3503 3504
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3505
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3506 3507
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3508
	.port_set_link = mv88e6xxx_port_set_link,
3509
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3510
	.port_set_speed = mv88e6185_port_set_speed,
3511
	.port_tag_remap = mv88e6095_port_tag_remap,
3512
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3513
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3514
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3515
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3516
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3517
	.port_pause_limit = mv88e6097_port_pause_limit,
3518
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3519
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3520
	.port_link_state = mv88e6352_port_link_state,
3521
	.port_get_cmode = mv88e6352_port_get_cmode,
3522
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3523
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3524 3525
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3526
	.stats_get_stats = mv88e6320_stats_get_stats,
3527 3528
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3529
	.watchdog_ops = &mv88e6390_watchdog_ops,
3530
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3531
	.pot_clear = mv88e6xxx_g2_pot_clear,
3532
	.reset = mv88e6352_g1_reset,
3533
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3534
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3535
	.gpio_ops = &mv88e6352_gpio_ops,
3536
	.avb_ops = &mv88e6352_avb_ops,
3537
	.ptp_ops = &mv88e6352_ptp_ops,
3538
	.phylink_validate = mv88e6185_phylink_validate,
3539 3540 3541
};

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

3582 3583
static const struct mv88e6xxx_ops mv88e6341_ops = {
	/* MV88E6XXX_FAMILY_6341 */
3584 3585
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3586
	.irl_init_all = mv88e6352_g2_irl_init_all,
3587 3588 3589 3590 3591 3592 3593 3594
	.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,
3595
	.port_set_speed = mv88e6341_port_set_speed,
3596
	.port_max_speed_mode = mv88e6341_port_max_speed_mode,
3597 3598 3599 3600
	.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,
3601
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3602
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3603
	.port_pause_limit = mv88e6097_port_pause_limit,
3604 3605
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3606
	.port_link_state = mv88e6352_port_link_state,
3607
	.port_get_cmode = mv88e6352_port_get_cmode,
3608
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3609
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3610 3611 3612
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
3613 3614
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3615 3616
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
3617
	.pot_clear = mv88e6xxx_g2_pot_clear,
3618
	.reset = mv88e6352_g1_reset,
3619
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3620
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3621
	.serdes_power = mv88e6341_serdes_power,
3622
	.gpio_ops = &mv88e6352_gpio_ops,
3623
	.avb_ops = &mv88e6390_avb_ops,
3624
	.ptp_ops = &mv88e6352_ptp_ops,
3625
	.phylink_validate = mv88e6341_phylink_validate,
3626 3627
};

3628
static const struct mv88e6xxx_ops mv88e6350_ops = {
3629
	/* MV88E6XXX_FAMILY_6351 */
3630 3631
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3632
	.irl_init_all = mv88e6352_g2_irl_init_all,
3633
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3634 3635
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3636
	.port_set_link = mv88e6xxx_port_set_link,
3637
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3638
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3639
	.port_set_speed = mv88e6185_port_set_speed,
3640
	.port_tag_remap = mv88e6095_port_tag_remap,
3641
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3642
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3643
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3644
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3645
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3646
	.port_pause_limit = mv88e6097_port_pause_limit,
3647
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3648
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3649
	.port_link_state = mv88e6352_port_link_state,
3650
	.port_get_cmode = mv88e6352_port_get_cmode,
3651
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3652
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3653 3654
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3655
	.stats_get_stats = mv88e6095_stats_get_stats,
3656 3657
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3658
	.watchdog_ops = &mv88e6097_watchdog_ops,
3659
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3660
	.pot_clear = mv88e6xxx_g2_pot_clear,
3661
	.reset = mv88e6352_g1_reset,
3662
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3663
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3664
	.phylink_validate = mv88e6185_phylink_validate,
3665 3666 3667
};

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

static const struct mv88e6xxx_ops mv88e6352_ops = {
3709
	/* MV88E6XXX_FAMILY_6352 */
3710 3711
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3712
	.irl_init_all = mv88e6352_g2_irl_init_all,
3713 3714
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3715
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3716 3717
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3718
	.port_set_link = mv88e6xxx_port_set_link,
3719
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3720
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3721
	.port_set_speed = mv88e6352_port_set_speed,
3722
	.port_tag_remap = mv88e6095_port_tag_remap,
3723
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3724
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3725
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3726
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3727
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3728
	.port_pause_limit = mv88e6097_port_pause_limit,
3729
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3730
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3731
	.port_link_state = mv88e6352_port_link_state,
3732
	.port_get_cmode = mv88e6352_port_get_cmode,
3733
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3734
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3735 3736
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3737
	.stats_get_stats = mv88e6095_stats_get_stats,
3738 3739
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3740
	.watchdog_ops = &mv88e6097_watchdog_ops,
3741
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3742
	.pot_clear = mv88e6xxx_g2_pot_clear,
3743
	.reset = mv88e6352_g1_reset,
3744
	.rmu_disable = mv88e6352_g1_rmu_disable,
3745
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3746
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3747
	.serdes_power = mv88e6352_serdes_power,
3748 3749
	.serdes_irq_setup = mv88e6352_serdes_irq_setup,
	.serdes_irq_free = mv88e6352_serdes_irq_free,
3750
	.gpio_ops = &mv88e6352_gpio_ops,
3751
	.avb_ops = &mv88e6352_avb_ops,
3752
	.ptp_ops = &mv88e6352_ptp_ops,
3753 3754 3755
	.serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
	.serdes_get_strings = mv88e6352_serdes_get_strings,
	.serdes_get_stats = mv88e6352_serdes_get_stats,
3756
	.phylink_validate = mv88e6352_phylink_validate,
3757 3758
};

3759
static const struct mv88e6xxx_ops mv88e6390_ops = {
3760
	/* MV88E6XXX_FAMILY_6390 */
3761
	.setup_errata = mv88e6390_setup_errata,
3762
	.irl_init_all = mv88e6390_g2_irl_init_all,
3763 3764
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3765 3766 3767 3768 3769 3770 3771
	.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,
3772
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
3773
	.port_tag_remap = mv88e6390_port_tag_remap,
3774
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3775
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3776
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3777
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3778
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3779
	.port_pause_limit = mv88e6390_port_pause_limit,
3780
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3781
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3782
	.port_link_state = mv88e6352_port_link_state,
3783
	.port_get_cmode = mv88e6352_port_get_cmode,
3784
	.port_set_cmode = mv88e6390_port_set_cmode,
3785
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3786
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3787 3788
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3789
	.stats_get_stats = mv88e6390_stats_get_stats,
3790 3791
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3792
	.watchdog_ops = &mv88e6390_watchdog_ops,
3793
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3794
	.pot_clear = mv88e6xxx_g2_pot_clear,
3795
	.reset = mv88e6352_g1_reset,
3796
	.rmu_disable = mv88e6390_g1_rmu_disable,
3797 3798
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3799
	.serdes_power = mv88e6390_serdes_power,
3800 3801
	.serdes_irq_setup = mv88e6390_serdes_irq_setup,
	.serdes_irq_free = mv88e6390_serdes_irq_free,
3802
	.gpio_ops = &mv88e6352_gpio_ops,
3803
	.avb_ops = &mv88e6390_avb_ops,
3804
	.ptp_ops = &mv88e6352_ptp_ops,
3805
	.phylink_validate = mv88e6390_phylink_validate,
3806 3807 3808
};

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

3857 3858
static const struct mv88e6xxx_info mv88e6xxx_table[] = {
	[MV88E6085] = {
3859
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
3860 3861 3862 3863
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6085",
		.num_databases = 4096,
		.num_ports = 10,
3864
		.num_internal_phys = 5,
3865
		.max_vid = 4095,
3866
		.port_base_addr = 0x10,
3867
		.phy_base_addr = 0x0,
3868
		.global1_addr = 0x1b,
3869
		.global2_addr = 0x1c,
3870
		.age_time_coeff = 15000,
3871
		.g1_irqs = 8,
3872
		.g2_irqs = 10,
3873
		.atu_move_port_mask = 0xf,
3874
		.pvt = true,
3875
		.multi_chip = true,
3876
		.tag_protocol = DSA_TAG_PROTO_DSA,
3877
		.ops = &mv88e6085_ops,
3878 3879 3880
	},

	[MV88E6095] = {
3881
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
3882 3883 3884 3885
		.family = MV88E6XXX_FAMILY_6095,
		.name = "Marvell 88E6095/88E6095F",
		.num_databases = 256,
		.num_ports = 11,
3886
		.num_internal_phys = 0,
3887
		.max_vid = 4095,
3888
		.port_base_addr = 0x10,
3889
		.phy_base_addr = 0x0,
3890
		.global1_addr = 0x1b,
3891
		.global2_addr = 0x1c,
3892
		.age_time_coeff = 15000,
3893
		.g1_irqs = 8,
3894
		.atu_move_port_mask = 0xf,
3895
		.multi_chip = true,
3896
		.tag_protocol = DSA_TAG_PROTO_DSA,
3897
		.ops = &mv88e6095_ops,
3898 3899
	},

3900
	[MV88E6097] = {
3901
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
3902 3903 3904 3905
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6097/88E6097F",
		.num_databases = 4096,
		.num_ports = 11,
3906
		.num_internal_phys = 8,
3907
		.max_vid = 4095,
3908
		.port_base_addr = 0x10,
3909
		.phy_base_addr = 0x0,
3910
		.global1_addr = 0x1b,
3911
		.global2_addr = 0x1c,
3912
		.age_time_coeff = 15000,
3913
		.g1_irqs = 8,
3914
		.g2_irqs = 10,
3915
		.atu_move_port_mask = 0xf,
3916
		.pvt = true,
3917
		.multi_chip = true,
3918
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3919 3920 3921
		.ops = &mv88e6097_ops,
	},

3922
	[MV88E6123] = {
3923
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
3924 3925 3926 3927
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6123",
		.num_databases = 4096,
		.num_ports = 3,
3928
		.num_internal_phys = 5,
3929
		.max_vid = 4095,
3930
		.port_base_addr = 0x10,
3931
		.phy_base_addr = 0x0,
3932
		.global1_addr = 0x1b,
3933
		.global2_addr = 0x1c,
3934
		.age_time_coeff = 15000,
3935
		.g1_irqs = 9,
3936
		.g2_irqs = 10,
3937
		.atu_move_port_mask = 0xf,
3938
		.pvt = true,
3939
		.multi_chip = true,
3940
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3941
		.ops = &mv88e6123_ops,
3942 3943 3944
	},

	[MV88E6131] = {
3945
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
3946 3947 3948 3949
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6131",
		.num_databases = 256,
		.num_ports = 8,
3950
		.num_internal_phys = 0,
3951
		.max_vid = 4095,
3952
		.port_base_addr = 0x10,
3953
		.phy_base_addr = 0x0,
3954
		.global1_addr = 0x1b,
3955
		.global2_addr = 0x1c,
3956
		.age_time_coeff = 15000,
3957
		.g1_irqs = 9,
3958
		.atu_move_port_mask = 0xf,
3959
		.multi_chip = true,
3960
		.tag_protocol = DSA_TAG_PROTO_DSA,
3961
		.ops = &mv88e6131_ops,
3962 3963
	},

3964
	[MV88E6141] = {
3965
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
3966
		.family = MV88E6XXX_FAMILY_6341,
3967
		.name = "Marvell 88E6141",
3968 3969
		.num_databases = 4096,
		.num_ports = 6,
3970
		.num_internal_phys = 5,
3971
		.num_gpio = 11,
3972
		.max_vid = 4095,
3973
		.port_base_addr = 0x10,
3974
		.phy_base_addr = 0x10,
3975
		.global1_addr = 0x1b,
3976
		.global2_addr = 0x1c,
3977 3978
		.age_time_coeff = 3750,
		.atu_move_port_mask = 0x1f,
3979
		.g1_irqs = 9,
3980
		.g2_irqs = 10,
3981
		.pvt = true,
3982
		.multi_chip = true,
3983 3984 3985 3986
		.tag_protocol = DSA_TAG_PROTO_EDSA,
		.ops = &mv88e6141_ops,
	},

3987
	[MV88E6161] = {
3988
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
3989 3990 3991 3992
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6161",
		.num_databases = 4096,
		.num_ports = 6,
3993
		.num_internal_phys = 5,
3994
		.max_vid = 4095,
3995
		.port_base_addr = 0x10,
3996
		.phy_base_addr = 0x0,
3997
		.global1_addr = 0x1b,
3998
		.global2_addr = 0x1c,
3999
		.age_time_coeff = 15000,
4000
		.g1_irqs = 9,
4001
		.g2_irqs = 10,
4002
		.atu_move_port_mask = 0xf,
4003
		.pvt = true,
4004
		.multi_chip = true,
4005
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4006
		.ptp_support = true,
4007
		.ops = &mv88e6161_ops,
4008 4009 4010
	},

	[MV88E6165] = {
4011
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
4012 4013 4014 4015
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6165",
		.num_databases = 4096,
		.num_ports = 6,
4016
		.num_internal_phys = 0,
4017
		.max_vid = 4095,
4018
		.port_base_addr = 0x10,
4019
		.phy_base_addr = 0x0,
4020
		.global1_addr = 0x1b,
4021
		.global2_addr = 0x1c,
4022
		.age_time_coeff = 15000,
4023
		.g1_irqs = 9,
4024
		.g2_irqs = 10,
4025
		.atu_move_port_mask = 0xf,
4026
		.pvt = true,
4027
		.multi_chip = true,
4028
		.tag_protocol = DSA_TAG_PROTO_DSA,
4029
		.ptp_support = true,
4030
		.ops = &mv88e6165_ops,
4031 4032 4033
	},

	[MV88E6171] = {
4034
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
4035 4036 4037 4038
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6171",
		.num_databases = 4096,
		.num_ports = 7,
4039
		.num_internal_phys = 5,
4040
		.max_vid = 4095,
4041
		.port_base_addr = 0x10,
4042
		.phy_base_addr = 0x0,
4043
		.global1_addr = 0x1b,
4044
		.global2_addr = 0x1c,
4045
		.age_time_coeff = 15000,
4046
		.g1_irqs = 9,
4047
		.g2_irqs = 10,
4048
		.atu_move_port_mask = 0xf,
4049
		.pvt = true,
4050
		.multi_chip = true,
4051
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4052
		.ops = &mv88e6171_ops,
4053 4054 4055
	},

	[MV88E6172] = {
4056
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
4057 4058 4059 4060
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6172",
		.num_databases = 4096,
		.num_ports = 7,
4061
		.num_internal_phys = 5,
4062
		.num_gpio = 15,
4063
		.max_vid = 4095,
4064
		.port_base_addr = 0x10,
4065
		.phy_base_addr = 0x0,
4066
		.global1_addr = 0x1b,
4067
		.global2_addr = 0x1c,
4068
		.age_time_coeff = 15000,
4069
		.g1_irqs = 9,
4070
		.g2_irqs = 10,
4071
		.atu_move_port_mask = 0xf,
4072
		.pvt = true,
4073
		.multi_chip = true,
4074
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4075
		.ops = &mv88e6172_ops,
4076 4077 4078
	},

	[MV88E6175] = {
4079
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
4080 4081 4082 4083
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6175",
		.num_databases = 4096,
		.num_ports = 7,
4084
		.num_internal_phys = 5,
4085
		.max_vid = 4095,
4086
		.port_base_addr = 0x10,
4087
		.phy_base_addr = 0x0,
4088
		.global1_addr = 0x1b,
4089
		.global2_addr = 0x1c,
4090
		.age_time_coeff = 15000,
4091
		.g1_irqs = 9,
4092
		.g2_irqs = 10,
4093
		.atu_move_port_mask = 0xf,
4094
		.pvt = true,
4095
		.multi_chip = true,
4096
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4097
		.ops = &mv88e6175_ops,
4098 4099 4100
	},

	[MV88E6176] = {
4101
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
4102 4103 4104 4105
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6176",
		.num_databases = 4096,
		.num_ports = 7,
4106
		.num_internal_phys = 5,
4107
		.num_gpio = 15,
4108
		.max_vid = 4095,
4109
		.port_base_addr = 0x10,
4110
		.phy_base_addr = 0x0,
4111
		.global1_addr = 0x1b,
4112
		.global2_addr = 0x1c,
4113
		.age_time_coeff = 15000,
4114
		.g1_irqs = 9,
4115
		.g2_irqs = 10,
4116
		.atu_move_port_mask = 0xf,
4117
		.pvt = true,
4118
		.multi_chip = true,
4119
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4120
		.ops = &mv88e6176_ops,
4121 4122 4123
	},

	[MV88E6185] = {
4124
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
4125 4126 4127 4128
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6185",
		.num_databases = 256,
		.num_ports = 10,
4129
		.num_internal_phys = 0,
4130
		.max_vid = 4095,
4131
		.port_base_addr = 0x10,
4132
		.phy_base_addr = 0x0,
4133
		.global1_addr = 0x1b,
4134
		.global2_addr = 0x1c,
4135
		.age_time_coeff = 15000,
4136
		.g1_irqs = 8,
4137
		.atu_move_port_mask = 0xf,
4138
		.multi_chip = true,
4139
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4140
		.ops = &mv88e6185_ops,
4141 4142
	},

4143
	[MV88E6190] = {
4144
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
4145 4146 4147 4148
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4149
		.num_internal_phys = 9,
4150
		.num_gpio = 16,
4151
		.max_vid = 8191,
4152
		.port_base_addr = 0x0,
4153
		.phy_base_addr = 0x0,
4154
		.global1_addr = 0x1b,
4155
		.global2_addr = 0x1c,
4156
		.tag_protocol = DSA_TAG_PROTO_DSA,
4157
		.age_time_coeff = 3750,
4158
		.g1_irqs = 9,
4159
		.g2_irqs = 14,
4160
		.pvt = true,
4161
		.multi_chip = true,
4162
		.atu_move_port_mask = 0x1f,
4163 4164 4165 4166
		.ops = &mv88e6190_ops,
	},

	[MV88E6190X] = {
4167
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
4168 4169 4170 4171
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4172
		.num_internal_phys = 9,
4173
		.num_gpio = 16,
4174
		.max_vid = 8191,
4175
		.port_base_addr = 0x0,
4176
		.phy_base_addr = 0x0,
4177
		.global1_addr = 0x1b,
4178
		.global2_addr = 0x1c,
4179
		.age_time_coeff = 3750,
4180
		.g1_irqs = 9,
4181
		.g2_irqs = 14,
4182
		.atu_move_port_mask = 0x1f,
4183
		.pvt = true,
4184
		.multi_chip = true,
4185
		.tag_protocol = DSA_TAG_PROTO_DSA,
4186 4187 4188 4189
		.ops = &mv88e6190x_ops,
	},

	[MV88E6191] = {
4190
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
4191 4192 4193 4194
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6191",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4195
		.num_internal_phys = 9,
4196
		.max_vid = 8191,
4197
		.port_base_addr = 0x0,
4198
		.phy_base_addr = 0x0,
4199
		.global1_addr = 0x1b,
4200
		.global2_addr = 0x1c,
4201
		.age_time_coeff = 3750,
4202
		.g1_irqs = 9,
4203
		.g2_irqs = 14,
4204
		.atu_move_port_mask = 0x1f,
4205
		.pvt = true,
4206
		.multi_chip = true,
4207
		.tag_protocol = DSA_TAG_PROTO_DSA,
4208
		.ptp_support = true,
4209
		.ops = &mv88e6191_ops,
4210 4211
	},

4212
	[MV88E6240] = {
4213
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
4214 4215 4216 4217
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6240",
		.num_databases = 4096,
		.num_ports = 7,
4218
		.num_internal_phys = 5,
4219
		.num_gpio = 15,
4220
		.max_vid = 4095,
4221
		.port_base_addr = 0x10,
4222
		.phy_base_addr = 0x0,
4223
		.global1_addr = 0x1b,
4224
		.global2_addr = 0x1c,
4225
		.age_time_coeff = 15000,
4226
		.g1_irqs = 9,
4227
		.g2_irqs = 10,
4228
		.atu_move_port_mask = 0xf,
4229
		.pvt = true,
4230
		.multi_chip = true,
4231
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4232
		.ptp_support = true,
4233
		.ops = &mv88e6240_ops,
4234 4235
	},

4236
	[MV88E6290] = {
4237
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
4238 4239 4240 4241
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6290",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4242
		.num_internal_phys = 9,
4243
		.num_gpio = 16,
4244
		.max_vid = 8191,
4245
		.port_base_addr = 0x0,
4246
		.phy_base_addr = 0x0,
4247
		.global1_addr = 0x1b,
4248
		.global2_addr = 0x1c,
4249
		.age_time_coeff = 3750,
4250
		.g1_irqs = 9,
4251
		.g2_irqs = 14,
4252
		.atu_move_port_mask = 0x1f,
4253
		.pvt = true,
4254
		.multi_chip = true,
4255
		.tag_protocol = DSA_TAG_PROTO_DSA,
4256
		.ptp_support = true,
4257 4258 4259
		.ops = &mv88e6290_ops,
	},

4260
	[MV88E6320] = {
4261
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
4262 4263 4264 4265
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6320",
		.num_databases = 4096,
		.num_ports = 7,
4266
		.num_internal_phys = 5,
4267
		.num_gpio = 15,
4268
		.max_vid = 4095,
4269
		.port_base_addr = 0x10,
4270
		.phy_base_addr = 0x0,
4271
		.global1_addr = 0x1b,
4272
		.global2_addr = 0x1c,
4273
		.age_time_coeff = 15000,
4274
		.g1_irqs = 8,
4275
		.g2_irqs = 10,
4276
		.atu_move_port_mask = 0xf,
4277
		.pvt = true,
4278
		.multi_chip = true,
4279
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4280
		.ptp_support = true,
4281
		.ops = &mv88e6320_ops,
4282 4283 4284
	},

	[MV88E6321] = {
4285
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
4286 4287 4288 4289
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6321",
		.num_databases = 4096,
		.num_ports = 7,
4290
		.num_internal_phys = 5,
4291
		.num_gpio = 15,
4292
		.max_vid = 4095,
4293
		.port_base_addr = 0x10,
4294
		.phy_base_addr = 0x0,
4295
		.global1_addr = 0x1b,
4296
		.global2_addr = 0x1c,
4297
		.age_time_coeff = 15000,
4298
		.g1_irqs = 8,
4299
		.g2_irqs = 10,
4300
		.atu_move_port_mask = 0xf,
4301
		.multi_chip = true,
4302
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4303
		.ptp_support = true,
4304
		.ops = &mv88e6321_ops,
4305 4306
	},

4307
	[MV88E6341] = {
4308
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
4309 4310 4311
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
4312
		.num_internal_phys = 5,
4313
		.num_ports = 6,
4314
		.num_gpio = 11,
4315
		.max_vid = 4095,
4316
		.port_base_addr = 0x10,
4317
		.phy_base_addr = 0x10,
4318
		.global1_addr = 0x1b,
4319
		.global2_addr = 0x1c,
4320
		.age_time_coeff = 3750,
4321
		.atu_move_port_mask = 0x1f,
4322
		.g1_irqs = 9,
4323
		.g2_irqs = 10,
4324
		.pvt = true,
4325
		.multi_chip = true,
4326
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4327
		.ptp_support = true,
4328 4329 4330
		.ops = &mv88e6341_ops,
	},

4331
	[MV88E6350] = {
4332
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
4333 4334 4335 4336
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6350",
		.num_databases = 4096,
		.num_ports = 7,
4337
		.num_internal_phys = 5,
4338
		.max_vid = 4095,
4339
		.port_base_addr = 0x10,
4340
		.phy_base_addr = 0x0,
4341
		.global1_addr = 0x1b,
4342
		.global2_addr = 0x1c,
4343
		.age_time_coeff = 15000,
4344
		.g1_irqs = 9,
4345
		.g2_irqs = 10,
4346
		.atu_move_port_mask = 0xf,
4347
		.pvt = true,
4348
		.multi_chip = true,
4349
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4350
		.ops = &mv88e6350_ops,
4351 4352 4353
	},

	[MV88E6351] = {
4354
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
4355 4356 4357 4358
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6351",
		.num_databases = 4096,
		.num_ports = 7,
4359
		.num_internal_phys = 5,
4360
		.max_vid = 4095,
4361
		.port_base_addr = 0x10,
4362
		.phy_base_addr = 0x0,
4363
		.global1_addr = 0x1b,
4364
		.global2_addr = 0x1c,
4365
		.age_time_coeff = 15000,
4366
		.g1_irqs = 9,
4367
		.g2_irqs = 10,
4368
		.atu_move_port_mask = 0xf,
4369
		.pvt = true,
4370
		.multi_chip = true,
4371
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4372
		.ops = &mv88e6351_ops,
4373 4374 4375
	},

	[MV88E6352] = {
4376
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
4377 4378 4379 4380
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6352",
		.num_databases = 4096,
		.num_ports = 7,
4381
		.num_internal_phys = 5,
4382
		.num_gpio = 15,
4383
		.max_vid = 4095,
4384
		.port_base_addr = 0x10,
4385
		.phy_base_addr = 0x0,
4386
		.global1_addr = 0x1b,
4387
		.global2_addr = 0x1c,
4388
		.age_time_coeff = 15000,
4389
		.g1_irqs = 9,
4390
		.g2_irqs = 10,
4391
		.atu_move_port_mask = 0xf,
4392
		.pvt = true,
4393
		.multi_chip = true,
4394
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4395
		.ptp_support = true,
4396
		.ops = &mv88e6352_ops,
4397
	},
4398
	[MV88E6390] = {
4399
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
4400 4401 4402 4403
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4404
		.num_internal_phys = 9,
4405
		.num_gpio = 16,
4406
		.max_vid = 8191,
4407
		.port_base_addr = 0x0,
4408
		.phy_base_addr = 0x0,
4409
		.global1_addr = 0x1b,
4410
		.global2_addr = 0x1c,
4411
		.age_time_coeff = 3750,
4412
		.g1_irqs = 9,
4413
		.g2_irqs = 14,
4414
		.atu_move_port_mask = 0x1f,
4415
		.pvt = true,
4416
		.multi_chip = true,
4417
		.tag_protocol = DSA_TAG_PROTO_DSA,
4418
		.ptp_support = true,
4419 4420 4421
		.ops = &mv88e6390_ops,
	},
	[MV88E6390X] = {
4422
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
4423 4424 4425 4426
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4427
		.num_internal_phys = 9,
4428
		.num_gpio = 16,
4429
		.max_vid = 8191,
4430
		.port_base_addr = 0x0,
4431
		.phy_base_addr = 0x0,
4432
		.global1_addr = 0x1b,
4433
		.global2_addr = 0x1c,
4434
		.age_time_coeff = 3750,
4435
		.g1_irqs = 9,
4436
		.g2_irqs = 14,
4437
		.atu_move_port_mask = 0x1f,
4438
		.pvt = true,
4439
		.multi_chip = true,
4440
		.tag_protocol = DSA_TAG_PROTO_DSA,
4441
		.ptp_support = true,
4442 4443
		.ops = &mv88e6390x_ops,
	},
4444 4445
};

4446
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
4447
{
4448
	int i;
4449

4450 4451 4452
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
4453 4454 4455 4456

	return NULL;
}

4457
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
4458 4459
{
	const struct mv88e6xxx_info *info;
4460 4461 4462
	unsigned int prod_num, rev;
	u16 id;
	int err;
4463

4464
	mutex_lock(&chip->reg_lock);
4465
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
4466 4467 4468
	mutex_unlock(&chip->reg_lock);
	if (err)
		return err;
4469

4470 4471
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
4472 4473 4474 4475 4476

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

4477
	/* Update the compatible info with the probed one */
4478
	chip->info = info;
4479

4480 4481 4482 4483
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

4484 4485
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
4486 4487 4488 4489

	return 0;
}

4490
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
4491
{
4492
	struct mv88e6xxx_chip *chip;
4493

4494 4495
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
4496 4497
		return NULL;

4498
	chip->dev = dev;
4499

4500
	mutex_init(&chip->reg_lock);
4501
	INIT_LIST_HEAD(&chip->mdios);
4502

4503
	return chip;
4504 4505
}

4506 4507
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
							int port)
4508
{
V
Vivien Didelot 已提交
4509
	struct mv88e6xxx_chip *chip = ds->priv;
4510

4511
	return chip->info->tag_protocol;
4512 4513
}

4514
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4515
				      const struct switchdev_obj_port_mdb *mdb)
4516 4517 4518 4519 4520 4521 4522 4523 4524
{
	/* 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,
4525
				   const struct switchdev_obj_port_mdb *mdb)
4526
{
V
Vivien Didelot 已提交
4527
	struct mv88e6xxx_chip *chip = ds->priv;
4528 4529 4530

	mutex_lock(&chip->reg_lock);
	if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4531
					 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
4532 4533
		dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
			port);
4534 4535 4536 4537 4538 4539
	mutex_unlock(&chip->reg_lock);
}

static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
				  const struct switchdev_obj_port_mdb *mdb)
{
V
Vivien Didelot 已提交
4540
	struct mv88e6xxx_chip *chip = ds->priv;
4541 4542 4543 4544
	int err;

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4545
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
4546 4547 4548 4549 4550
	mutex_unlock(&chip->reg_lock);

	return err;
}

4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566
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;

	mutex_lock(&chip->reg_lock);
	if (chip->info->ops->port_set_egress_floods)
		err = chip->info->ops->port_set_egress_floods(chip, port,
							      unicast,
							      multicast);
	mutex_unlock(&chip->reg_lock);

	return err;
}

4567
static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
4568
	.get_tag_protocol	= mv88e6xxx_get_tag_protocol,
4569 4570
	.setup			= mv88e6xxx_setup,
	.adjust_link		= mv88e6xxx_adjust_link,
4571 4572 4573 4574 4575
	.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,
4576 4577 4578
	.get_strings		= mv88e6xxx_get_strings,
	.get_ethtool_stats	= mv88e6xxx_get_ethtool_stats,
	.get_sset_count		= mv88e6xxx_get_sset_count,
4579 4580
	.port_enable		= mv88e6xxx_port_enable,
	.port_disable		= mv88e6xxx_port_disable,
V
Vivien Didelot 已提交
4581 4582
	.get_mac_eee		= mv88e6xxx_get_mac_eee,
	.set_mac_eee		= mv88e6xxx_set_mac_eee,
4583
	.get_eeprom_len		= mv88e6xxx_get_eeprom_len,
4584 4585 4586 4587
	.get_eeprom		= mv88e6xxx_get_eeprom,
	.set_eeprom		= mv88e6xxx_set_eeprom,
	.get_regs_len		= mv88e6xxx_get_regs_len,
	.get_regs		= mv88e6xxx_get_regs,
4588
	.set_ageing_time	= mv88e6xxx_set_ageing_time,
4589 4590
	.port_bridge_join	= mv88e6xxx_port_bridge_join,
	.port_bridge_leave	= mv88e6xxx_port_bridge_leave,
4591
	.port_egress_floods	= mv88e6xxx_port_egress_floods,
4592
	.port_stp_state_set	= mv88e6xxx_port_stp_state_set,
4593
	.port_fast_age		= mv88e6xxx_port_fast_age,
4594 4595 4596 4597 4598 4599 4600
	.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,
4601 4602 4603
	.port_mdb_prepare       = mv88e6xxx_port_mdb_prepare,
	.port_mdb_add           = mv88e6xxx_port_mdb_add,
	.port_mdb_del           = mv88e6xxx_port_mdb_del,
4604 4605
	.crosschip_bridge_join	= mv88e6xxx_crosschip_bridge_join,
	.crosschip_bridge_leave	= mv88e6xxx_crosschip_bridge_leave,
4606 4607 4608 4609 4610
	.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,
4611 4612
};

4613
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
4614
{
4615
	struct device *dev = chip->dev;
4616 4617
	struct dsa_switch *ds;

4618
	ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
4619 4620 4621
	if (!ds)
		return -ENOMEM;

4622
	ds->priv = chip;
4623
	ds->dev = dev;
4624
	ds->ops = &mv88e6xxx_switch_ops;
4625 4626
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
4627 4628 4629

	dev_set_drvdata(dev, ds);

4630
	return dsa_register_switch(ds);
4631 4632
}

4633
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
4634
{
4635
	dsa_unregister_switch(chip->ds);
4636 4637
}

4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650
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;
}

4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665
/* 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);

4666
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
4667
{
4668
	struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
4669
	const struct mv88e6xxx_info *compat_info = NULL;
4670
	struct device *dev = &mdiodev->dev;
4671
	struct device_node *np = dev->of_node;
4672
	struct mv88e6xxx_chip *chip;
4673
	int port;
4674
	int err;
4675

4676 4677 4678
	if (!np && !pdata)
		return -EINVAL;

4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697
	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;
		}
	}

4698 4699 4700
	if (!compat_info)
		return -EINVAL;

4701
	chip = mv88e6xxx_alloc_chip(dev);
4702 4703 4704 4705
	if (!chip) {
		err = -ENOMEM;
		goto out;
	}
4706

4707
	chip->info = compat_info;
4708

4709
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
4710
	if (err)
4711
		goto out;
4712

4713
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4714 4715 4716 4717
	if (IS_ERR(chip->reset)) {
		err = PTR_ERR(chip->reset);
		goto out;
	}
4718

4719
	err = mv88e6xxx_detect(chip);
4720
	if (err)
4721
		goto out;
4722

4723 4724
	mv88e6xxx_phy_init(chip);

4725 4726 4727 4728 4729 4730 4731
	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;
	}
4732

4733 4734 4735 4736 4737 4738
	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_switch_reset(chip);
	mutex_unlock(&chip->reg_lock);
	if (err)
		goto out;

4739 4740 4741 4742 4743 4744
	if (np) {
		chip->irq = of_irq_get(np, 0);
		if (chip->irq == -EPROBE_DEFER) {
			err = chip->irq;
			goto out;
		}
4745 4746
	}

4747 4748 4749
	if (pdata)
		chip->irq = pdata->irq;

4750
	/* Has to be performed before the MDIO bus is created, because
4751
	 * the PHYs will link their interrupts to these interrupt
4752 4753 4754 4755
	 * controllers
	 */
	mutex_lock(&chip->reg_lock);
	if (chip->irq > 0)
4756
		err = mv88e6xxx_g1_irq_setup(chip);
4757 4758 4759
	else
		err = mv88e6xxx_irq_poll_setup(chip);
	mutex_unlock(&chip->reg_lock);
4760

4761 4762
	if (err)
		goto out;
4763

4764 4765
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
4766
		if (err)
4767
			goto out_g1_irq;
4768 4769
	}

4770 4771 4772 4773 4774 4775 4776 4777
	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;

4778
	err = mv88e6xxx_mdios_register(chip, np);
4779
	if (err)
4780
		goto out_g1_vtu_prob_irq;
4781

4782
	err = mv88e6xxx_register_switch(chip);
4783 4784
	if (err)
		goto out_mdio;
4785

4786
	return 0;
4787 4788

out_mdio:
4789
	mv88e6xxx_mdios_unregister(chip);
4790
out_g1_vtu_prob_irq:
4791
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
4792
out_g1_atu_prob_irq:
4793
	mv88e6xxx_g1_atu_prob_irq_free(chip);
4794
out_g2_irq:
4795
	if (chip->info->g2_irqs > 0)
4796 4797
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
4798
	if (chip->irq > 0)
4799
		mv88e6xxx_g1_irq_free(chip);
4800 4801
	else
		mv88e6xxx_irq_poll_free(chip);
4802
out:
4803 4804 4805
	if (pdata)
		dev_put(pdata->netdev);

4806
	return err;
4807
}
4808 4809 4810 4811

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

4814 4815
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
4816
		mv88e6xxx_ptp_free(chip);
4817
	}
4818

4819
	mv88e6xxx_phy_destroy(chip);
4820
	mv88e6xxx_unregister_switch(chip);
4821
	mv88e6xxx_mdios_unregister(chip);
4822

4823 4824 4825 4826 4827 4828 4829
	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)
4830
		mv88e6xxx_g1_irq_free(chip);
4831 4832
	else
		mv88e6xxx_irq_poll_free(chip);
4833 4834 4835
}

static const struct of_device_id mv88e6xxx_of_match[] = {
4836 4837 4838 4839
	{
		.compatible = "marvell,mv88e6085",
		.data = &mv88e6xxx_table[MV88E6085],
	},
4840 4841 4842 4843
	{
		.compatible = "marvell,mv88e6190",
		.data = &mv88e6xxx_table[MV88E6190],
	},
4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854
	{ /* 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,
4855
		.pm = &mv88e6xxx_pm_ops,
4856 4857 4858
	},
};

4859
mdio_module_driver(mv88e6xxx_driver);
4860 4861 4862 4863

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