chip.c 140.6 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

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

55 56 57 58 59 60 61 62 63 64
/* The switch ADDR[4:1] configuration pins define the chip SMI device address
 * (ADDR[0] is always zero, thus only even SMI addresses can be strapped).
 *
 * When ADDR is all zero, the chip uses Single-chip Addressing Mode, assuming it
 * is the only device connected to the SMI master. In this mode it responds to
 * all 32 possible SMI addresses, and thus maps directly the internal devices.
 *
 * When ADDR is non-zero, the chip uses Multi-chip Addressing Mode, allowing
 * multiple devices to share the SMI interface. In this mode it responds to only
 * 2 registers, used to indirectly access the internal SMI devices.
65
 */
66

67
static int mv88e6xxx_smi_read(struct mv88e6xxx_chip *chip,
68 69
			      int addr, int reg, u16 *val)
{
70
	if (!chip->smi_ops)
71 72
		return -EOPNOTSUPP;

73
	return chip->smi_ops->read(chip, addr, reg, val);
74 75
}

76
static int mv88e6xxx_smi_write(struct mv88e6xxx_chip *chip,
77 78
			       int addr, int reg, u16 val)
{
79
	if (!chip->smi_ops)
80 81
		return -EOPNOTSUPP;

82
	return chip->smi_ops->write(chip, addr, reg, val);
83 84
}

85
static int mv88e6xxx_smi_single_chip_read(struct mv88e6xxx_chip *chip,
86 87 88 89
					  int addr, int reg, u16 *val)
{
	int ret;

90
	ret = mdiobus_read_nested(chip->bus, addr, reg);
91 92 93 94 95 96 97 98
	if (ret < 0)
		return ret;

	*val = ret & 0xffff;

	return 0;
}

99
static int mv88e6xxx_smi_single_chip_write(struct mv88e6xxx_chip *chip,
100 101 102 103
					   int addr, int reg, u16 val)
{
	int ret;

104
	ret = mdiobus_write_nested(chip->bus, addr, reg, val);
105 106 107 108 109 110
	if (ret < 0)
		return ret;

	return 0;
}

111
static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_single_chip_ops = {
112 113 114 115
	.read = mv88e6xxx_smi_single_chip_read,
	.write = mv88e6xxx_smi_single_chip_write,
};

116
static int mv88e6xxx_smi_multi_chip_wait(struct mv88e6xxx_chip *chip)
117 118 119 120 121
{
	int ret;
	int i;

	for (i = 0; i < 16; i++) {
122
		ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_CMD);
123 124 125
		if (ret < 0)
			return ret;

126
		if ((ret & SMI_CMD_BUSY) == 0)
127 128 129 130 131 132
			return 0;
	}

	return -ETIMEDOUT;
}

133
static int mv88e6xxx_smi_multi_chip_read(struct mv88e6xxx_chip *chip,
134
					 int addr, int reg, u16 *val)
135 136 137
{
	int ret;

138
	/* Wait for the bus to become free. */
139
	ret = mv88e6xxx_smi_multi_chip_wait(chip);
140 141 142
	if (ret < 0)
		return ret;

143
	/* Transmit the read command. */
144
	ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
145
				   SMI_CMD_OP_22_READ | (addr << 5) | reg);
146 147 148
	if (ret < 0)
		return ret;

149
	/* Wait for the read command to complete. */
150
	ret = mv88e6xxx_smi_multi_chip_wait(chip);
151 152 153
	if (ret < 0)
		return ret;

154
	/* Read the data. */
155
	ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_DATA);
156 157 158
	if (ret < 0)
		return ret;

159
	*val = ret & 0xffff;
160

161
	return 0;
162 163
}

164
static int mv88e6xxx_smi_multi_chip_write(struct mv88e6xxx_chip *chip,
165
					  int addr, int reg, u16 val)
166 167 168
{
	int ret;

169
	/* Wait for the bus to become free. */
170
	ret = mv88e6xxx_smi_multi_chip_wait(chip);
171 172 173
	if (ret < 0)
		return ret;

174
	/* Transmit the data to write. */
175
	ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_DATA, val);
176 177 178
	if (ret < 0)
		return ret;

179
	/* Transmit the write command. */
180
	ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
181
				   SMI_CMD_OP_22_WRITE | (addr << 5) | reg);
182 183 184
	if (ret < 0)
		return ret;

185
	/* Wait for the write command to complete. */
186
	ret = mv88e6xxx_smi_multi_chip_wait(chip);
187 188 189 190 191 192
	if (ret < 0)
		return ret;

	return 0;
}

193
static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_multi_chip_ops = {
194 195 196 197
	.read = mv88e6xxx_smi_multi_chip_read,
	.write = mv88e6xxx_smi_multi_chip_write,
};

198
int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val)
199 200 201
{
	int err;

202
	assert_reg_lock(chip);
203

204
	err = mv88e6xxx_smi_read(chip, addr, reg, val);
205 206 207
	if (err)
		return err;

208
	dev_dbg(chip->dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
209 210 211 212 213
		addr, reg, *val);

	return 0;
}

214
int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val)
215
{
216 217
	int err;

218
	assert_reg_lock(chip);
219

220
	err = mv88e6xxx_smi_write(chip, addr, reg, val);
221 222 223
	if (err)
		return err;

224
	dev_dbg(chip->dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
225 226
		addr, reg, val);

227 228 229
	return 0;
}

230
struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
231 232 233 234 235 236 237 238 239 240 241
{
	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;
}

242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
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);
}

258
static irqreturn_t mv88e6xxx_g1_irq_thread_work(struct mv88e6xxx_chip *chip)
259 260 261 262 263
{
	unsigned int nhandled = 0;
	unsigned int sub_irq;
	unsigned int n;
	u16 reg;
264
	u16 ctl1;
265 266 267
	int err;

	mutex_lock(&chip->reg_lock);
268
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
269 270 271 272 273
	mutex_unlock(&chip->reg_lock);

	if (err)
		goto out;

274 275 276 277 278 279 280 281
	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;
			}
282
		}
283 284 285 286 287 288 289 290 291 292 293 294 295

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

296 297 298 299
out:
	return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
}

300 301 302 303 304 305 306
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);
}

307 308 309 310 311 312 313 314 315 316 317 318 319 320
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;

321
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &reg);
322 323 324 325 326 327
	if (err)
		goto out;

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

328
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, reg);
329 330 331 332 333 334 335
	if (err)
		goto out;

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

336
static const struct irq_chip mv88e6xxx_g1_irq_chip = {
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
	.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,
};

362
/* To be called with reg_lock held */
363
static void mv88e6xxx_g1_irq_free_common(struct mv88e6xxx_chip *chip)
364 365
{
	int irq, virq;
366 367
	u16 mask;

368
	mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
369
	mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
370
	mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
371

372
	for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
373
		virq = irq_find_mapping(chip->g1_irq.domain, irq);
374 375 376
		irq_dispose_mapping(virq);
	}

377
	irq_domain_remove(chip->g1_irq.domain);
378 379
}

380 381
static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
{
382 383 384 385
	/*
	 * free_irq must be called without reg_lock taken because the irq
	 * handler takes this lock, too.
	 */
386
	free_irq(chip->irq, chip);
387 388 389 390

	mutex_lock(&chip->reg_lock);
	mv88e6xxx_g1_irq_free_common(chip);
	mutex_unlock(&chip->reg_lock);
391 392 393
}

static int mv88e6xxx_g1_irq_setup_common(struct mv88e6xxx_chip *chip)
394
{
395 396
	int err, irq, virq;
	u16 reg, mask;
397 398 399 400 401 402 403 404 405 406 407 408 409 410

	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;

411
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
412
	if (err)
413
		goto out_mapping;
414

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

417
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
418
	if (err)
419
		goto out_disable;
420 421

	/* Reading the interrupt status clears (most of) them */
422
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
423
	if (err)
424
		goto out_disable;
425 426 427

	return 0;

428
out_disable:
429
	mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
430
	mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
431 432 433 434 435 436 437 438

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);
439 440 441 442

	return err;
}

443 444 445 446 447 448 449 450 451 452
static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
{
	int err;

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

	err = request_threaded_irq(chip->irq, NULL,
				   mv88e6xxx_g1_irq_thread_fn,
453
				   IRQF_ONESHOT | IRQF_SHARED,
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
				   dev_name(chip->dev), chip);
	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);

483
	chip->kworker = kthread_create_worker(0, "%s", dev_name(chip->dev));
484 485 486 487 488 489 490 491 492 493 494 495 496
	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);
497 498 499 500

	mutex_lock(&chip->reg_lock);
	mv88e6xxx_g1_irq_free_common(chip);
	mutex_unlock(&chip->reg_lock);
501 502
}

503
int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask)
504
{
505
	int i;
506

507
	for (i = 0; i < 16; i++) {
508 509 510 511 512 513 514 515 516 517 518 519 520
		u16 val;
		int err;

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

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

		usleep_range(1000, 2000);
	}

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

525
/* Indirect write to single pointer-data register with an Update bit */
526
int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
527 528
{
	u16 val;
529
	int err;
530 531

	/* Wait until the previous operation is completed */
532 533 534
	err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
	if (err)
		return err;
535 536 537 538 539 540 541

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

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

542
static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
543
				    int link, int speed, int duplex, int pause,
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
				    phy_interface_t mode)
{
	int err;

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

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

562 563 564 565 566 567
	if (chip->info->ops->port_set_pause) {
		err = chip->info->ops->port_set_pause(chip, port, pause);
		if (err)
			goto restore_link;
	}

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

580 581 582 583 584 585
	if (chip->info->ops->port_set_cmode) {
		err = chip->info->ops->port_set_cmode(chip, port, mode);
		if (err && err != -EOPNOTSUPP)
			goto restore_link;
	}

586 587 588
	err = 0;
restore_link:
	if (chip->info->ops->port_set_link(chip, port, link))
589
		dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
590 591 592 593

	return err;
}

594 595 596 597 598 599 600
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;
}

601 602 603 604
/* 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.
 */
605 606
static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
				  struct phy_device *phydev)
607
{
V
Vivien Didelot 已提交
608
	struct mv88e6xxx_chip *chip = ds->priv;
609
	int err;
610

611 612
	if (!phy_is_pseudo_fixed_link(phydev) &&
	    mv88e6xxx_phy_is_internal(ds, port))
613 614
		return;

615
	mutex_lock(&chip->reg_lock);
616
	err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
617 618
				       phydev->duplex, phydev->pause,
				       phydev->interface);
619
	mutex_unlock(&chip->reg_lock);
620 621

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

625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
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);
}

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)
{
666
	if (port >= 9) {
667
		phylink_set(mask, 2500baseX_Full);
668 669
		phylink_set(mask, 2500baseT_Full);
	}
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689

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

690 691 692 693
static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
			       unsigned long *supported,
			       struct phylink_link_state *state)
{
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712
	__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);
713 714 715 716 717 718 719 720 721
}

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);
722 723 724 725
	if (chip->info->ops->port_link_state)
		err = chip->info->ops->port_link_state(chip, port, state);
	else
		err = -EOPNOTSUPP;
726 727 728 729 730 731 732 733 734 735
	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;
736
	int speed, duplex, link, pause, err;
737

738
	if ((mode == MLO_AN_PHY) && mv88e6xxx_phy_is_internal(ds, port))
739 740 741 742 743 744
		return;

	if (mode == MLO_AN_FIXED) {
		link = LINK_FORCED_UP;
		speed = state->speed;
		duplex = state->duplex;
745 746 747 748
	} else if (!mv88e6xxx_phy_is_internal(ds, port)) {
		link = state->link;
		speed = state->speed;
		duplex = state->duplex;
749 750 751 752 753
	} else {
		speed = SPEED_UNFORCED;
		duplex = DUPLEX_UNFORCED;
		link = LINK_UNFORCED;
	}
754
	pause = !!phylink_test(state->advertising, Pause);
755 756

	mutex_lock(&chip->reg_lock);
757
	err = mv88e6xxx_port_setup_mac(chip, port, link, speed, duplex, pause,
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793
				       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);
}

794
static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
795
{
796 797
	if (!chip->info->ops->stats_snapshot)
		return -EOPNOTSUPP;
798

799
	return chip->info->ops->stats_snapshot(chip, port);
800 801
}

802
static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861
	{ "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, },
862 863
};

864
static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
865
					    struct mv88e6xxx_hw_stat *s,
866 867
					    int port, u16 bank1_select,
					    u16 histogram)
868 869 870
{
	u32 low;
	u32 high = 0;
871
	u16 reg = 0;
872
	int err;
873 874
	u64 value;

875
	switch (s->type) {
876
	case STATS_TYPE_PORT:
877 878
		err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
		if (err)
879
			return U64_MAX;
880

881
		low = reg;
882
		if (s->size == 4) {
883 884
			err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
			if (err)
885
				return U64_MAX;
886
			high = reg;
887
		}
888
		break;
889
	case STATS_TYPE_BANK1:
890
		reg = bank1_select;
891 892
		/* fall through */
	case STATS_TYPE_BANK0:
893
		reg |= s->reg | histogram;
894
		mv88e6xxx_g1_stats_read(chip, reg, &low);
895
		if (s->size == 8)
896
			mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
897 898
		break;
	default:
899
		return U64_MAX;
900 901 902 903 904
	}
	value = (((u64)high) << 16) | low;
	return value;
}

905 906
static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data, int types)
907
{
908 909
	struct mv88e6xxx_hw_stat *stat;
	int i, j;
910

911 912
	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
		stat = &mv88e6xxx_hw_stats[i];
913
		if (stat->type & types) {
914 915 916 917
			memcpy(data + j * ETH_GSTRING_LEN, stat->string,
			       ETH_GSTRING_LEN);
			j++;
		}
918
	}
919 920

	return j;
921 922
}

923 924
static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
925
{
926 927
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_PORT);
928 929
}

930 931
static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
932
{
933 934
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
935 936
}

937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954
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);
}

955
static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
956
				  u32 stringset, uint8_t *data)
957
{
V
Vivien Didelot 已提交
958
	struct mv88e6xxx_chip *chip = ds->priv;
959
	int count = 0;
960

961 962 963
	if (stringset != ETH_SS_STATS)
		return;

964 965
	mutex_lock(&chip->reg_lock);

966
	if (chip->info->ops->stats_get_strings)
967 968 969 970
		count = chip->info->ops->stats_get_strings(chip, data);

	if (chip->info->ops->serdes_get_strings) {
		data += count * ETH_GSTRING_LEN;
971
		count = chip->info->ops->serdes_get_strings(chip, port, data);
972
	}
973

974 975 976
	data += count * ETH_GSTRING_LEN;
	mv88e6xxx_atu_vtu_get_strings(data);

977
	mutex_unlock(&chip->reg_lock);
978 979 980 981 982
}

static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
					  int types)
{
983 984 985 986 987
	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];
988
		if (stat->type & types)
989 990 991
			j++;
	}
	return j;
992 993
}

994 995 996 997 998 999 1000 1001 1002 1003 1004 1005
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);
}

1006
static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
1007 1008
{
	struct mv88e6xxx_chip *chip = ds->priv;
1009 1010
	int serdes_count = 0;
	int count = 0;
1011

1012 1013 1014
	if (sset != ETH_SS_STATS)
		return 0;

1015
	mutex_lock(&chip->reg_lock);
1016
	if (chip->info->ops->stats_get_sset_count)
1017 1018 1019 1020 1021 1022 1023
		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);
1024
	if (serdes_count < 0) {
1025
		count = serdes_count;
1026 1027 1028 1029 1030
		goto out;
	}
	count += serdes_count;
	count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);

1031
out:
1032
	mutex_unlock(&chip->reg_lock);
1033

1034
	return count;
1035 1036
}

1037 1038 1039
static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data, int types,
				     u16 bank1_select, u16 histogram)
1040 1041 1042 1043 1044 1045 1046
{
	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) {
1047
			mutex_lock(&chip->reg_lock);
1048 1049 1050
			data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
							      bank1_select,
							      histogram);
1051 1052
			mutex_unlock(&chip->reg_lock);

1053 1054 1055
			j++;
		}
	}
1056
	return j;
1057 1058
}

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

1067 1068
static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
1069 1070
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
1071
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1072 1073
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
					 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1074 1075
}

1076 1077
static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
1078 1079 1080
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1081 1082
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
					 0);
1083 1084
}

1085 1086 1087 1088 1089 1090 1091 1092 1093 1094
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;
}

1095 1096 1097
static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
				uint64_t *data)
{
1098 1099
	int count = 0;

1100
	if (chip->info->ops->stats_get_stats)
1101 1102
		count = chip->info->ops->stats_get_stats(chip, port, data);

1103
	mutex_lock(&chip->reg_lock);
1104 1105
	if (chip->info->ops->serdes_get_stats) {
		data += count;
1106
		count = chip->info->ops->serdes_get_stats(chip, port, data);
1107
	}
1108 1109 1110
	data += count;
	mv88e6xxx_atu_vtu_get_stats(chip, port, data);
	mutex_unlock(&chip->reg_lock);
1111 1112
}

1113 1114
static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
					uint64_t *data)
1115
{
V
Vivien Didelot 已提交
1116
	struct mv88e6xxx_chip *chip = ds->priv;
1117 1118
	int ret;

1119
	mutex_lock(&chip->reg_lock);
1120

1121
	ret = mv88e6xxx_stats_snapshot(chip, port);
1122 1123 1124
	mutex_unlock(&chip->reg_lock);

	if (ret < 0)
1125
		return;
1126 1127

	mv88e6xxx_get_stats(chip, port, data);
1128

1129 1130
}

1131
static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
1132 1133 1134 1135
{
	return 32 * sizeof(u16);
}

1136 1137
static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
			       struct ethtool_regs *regs, void *_p)
1138
{
V
Vivien Didelot 已提交
1139
	struct mv88e6xxx_chip *chip = ds->priv;
1140 1141
	int err;
	u16 reg;
1142 1143 1144
	u16 *p = _p;
	int i;

1145
	regs->version = chip->info->prod_num;
1146 1147 1148

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

1149
	mutex_lock(&chip->reg_lock);
1150

1151 1152
	for (i = 0; i < 32; i++) {

1153 1154 1155
		err = mv88e6xxx_port_read(chip, port, i, &reg);
		if (!err)
			p[i] = reg;
1156
	}
1157

1158
	mutex_unlock(&chip->reg_lock);
1159 1160
}

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

V
Vivien Didelot 已提交
1168 1169
static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
1170
{
1171 1172
	/* Nothing to do on the port's MAC */
	return 0;
1173 1174
}

1175
static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
1176
{
1177 1178 1179
	struct dsa_switch *ds = NULL;
	struct net_device *br;
	u16 pvlan;
1180 1181
	int i;

1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201
	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 已提交
1202
		    (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
1203 1204 1205 1206 1207
			pvlan |= BIT(i);

	return pvlan;
}

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

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

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

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

1224
	mutex_lock(&chip->reg_lock);
1225
	err = mv88e6xxx_port_set_state(chip, port, state);
1226
	mutex_unlock(&chip->reg_lock);
1227 1228

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

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

1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270
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;
	}

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

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

1282 1283 1284
	return 0;
}

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

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

	return 0;
}

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

	return 0;
}

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

	return 0;
}

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

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

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

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

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

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

1366 1367 1368 1369 1370 1371 1372 1373 1374
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)
1375
		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1376 1377 1378 1379

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

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

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

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

	mutex_lock(&chip->reg_lock);
1412
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1413 1414 1415
	mutex_unlock(&chip->reg_lock);

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

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

	return mv88e6xxx_g1_vtu_flush(chip);
}

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

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

1445
static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1446 1447
{
	DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1448 1449 1450
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = chip->info->max_vid,
	};
1451
	int i, err;
1452 1453 1454

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

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

		set_bit(*fid, fid_bitmap);
	}

1464 1465
	/* Set every FID bit used by the VLAN entries */
	do {
1466
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1467 1468 1469 1470 1471 1472 1473
		if (err)
			return err;

		if (!vlan.valid)
			break;

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

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

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

1487 1488
static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
			     struct mv88e6xxx_vtu_entry *entry, bool new)
1489 1490 1491 1492 1493 1494
{
	int err;

	if (!vid)
		return -EINVAL;

1495 1496
	entry->vid = vid - 1;
	entry->valid = false;
1497

1498
	err = mv88e6xxx_vtu_getnext(chip, entry);
1499 1500 1501
	if (err)
		return err;

1502 1503
	if (entry->vid == vid && entry->valid)
		return 0;
1504

1505 1506 1507 1508 1509 1510 1511 1512
	if (new) {
		int i;

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

1513
		/* Exclude all ports */
1514
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1515
			entry->member[i] =
1516
				MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1517 1518

		return mv88e6xxx_atu_new(chip, &entry->fid);
1519 1520
	}

1521 1522
	/* switchdev expects -EOPNOTSUPP to honor software VLANs */
	return -EOPNOTSUPP;
1523 1524
}

1525 1526 1527
static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
					u16 vid_begin, u16 vid_end)
{
V
Vivien Didelot 已提交
1528
	struct mv88e6xxx_chip *chip = ds->priv;
1529 1530 1531
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = vid_begin - 1,
	};
1532 1533
	int i, err;

1534 1535 1536 1537
	/* 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;

1538 1539 1540
	if (!vid_begin)
		return -EOPNOTSUPP;

1541
	mutex_lock(&chip->reg_lock);
1542 1543

	do {
1544
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1545 1546 1547 1548 1549 1550 1551 1552 1553
		if (err)
			goto unlock;

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

1554
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1555 1556 1557
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

1558
			if (!ds->ports[i].slave)
1559 1560
				continue;

1561
			if (vlan.member[i] ==
1562
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1563 1564
				continue;

V
Vivien Didelot 已提交
1565
			if (dsa_to_port(ds, i)->bridge_dev ==
1566
			    ds->ports[port].bridge_dev)
1567 1568
				break; /* same bridge, check next VLAN */

V
Vivien Didelot 已提交
1569
			if (!dsa_to_port(ds, i)->bridge_dev)
1570 1571
				continue;

1572 1573
			dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
				port, vlan.vid, i,
V
Vivien Didelot 已提交
1574
				netdev_name(dsa_to_port(ds, i)->bridge_dev));
1575 1576 1577 1578 1579 1580
			err = -EOPNOTSUPP;
			goto unlock;
		}
	} while (vlan.vid < vid_end);

unlock:
1581
	mutex_unlock(&chip->reg_lock);
1582 1583 1584 1585

	return err;
}

1586 1587
static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
					 bool vlan_filtering)
1588
{
V
Vivien Didelot 已提交
1589
	struct mv88e6xxx_chip *chip = ds->priv;
1590 1591
	u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
		MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
1592
	int err;
1593

1594
	if (!chip->info->max_vid)
1595 1596
		return -EOPNOTSUPP;

1597
	mutex_lock(&chip->reg_lock);
1598
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1599
	mutex_unlock(&chip->reg_lock);
1600

1601
	return err;
1602 1603
}

1604 1605
static int
mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1606
			    const struct switchdev_obj_port_vlan *vlan)
1607
{
V
Vivien Didelot 已提交
1608
	struct mv88e6xxx_chip *chip = ds->priv;
1609 1610
	int err;

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

1614 1615 1616 1617 1618 1619 1620 1621
	/* 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;

1622 1623 1624 1625 1626 1627
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */
	return 0;
}

1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671
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);
}

1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694
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;
}

1695
static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
1696
				    u16 vid, u8 member)
1697
{
1698
	struct mv88e6xxx_vtu_entry vlan;
1699 1700
	int err;

1701
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
1702
	if (err)
1703
		return err;
1704

1705
	vlan.member[port] = member;
1706

1707 1708 1709 1710 1711
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
	if (err)
		return err;

	return mv88e6xxx_broadcast_setup(chip, vid);
1712 1713
}

1714
static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1715
				    const struct switchdev_obj_port_vlan *vlan)
1716
{
V
Vivien Didelot 已提交
1717
	struct mv88e6xxx_chip *chip = ds->priv;
1718 1719
	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1720
	u8 member;
1721 1722
	u16 vid;

1723
	if (!chip->info->max_vid)
1724 1725
		return;

1726
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1727
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1728
	else if (untagged)
1729
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
1730
	else
1731
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
1732

1733
	mutex_lock(&chip->reg_lock);
1734

1735
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
1736
		if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
1737 1738
			dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
				vid, untagged ? 'u' : 't');
1739

1740
	if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1741 1742
		dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
			vlan->vid_end);
1743

1744
	mutex_unlock(&chip->reg_lock);
1745 1746
}

1747
static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
1748
				    int port, u16 vid)
1749
{
1750
	struct mv88e6xxx_vtu_entry vlan;
1751 1752
	int i, err;

1753
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1754
	if (err)
1755
		return err;
1756

1757
	/* Tell switchdev if this VLAN is handled in software */
1758
	if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1759
		return -EOPNOTSUPP;
1760

1761
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1762 1763

	/* keep the VLAN unless all ports are excluded */
1764
	vlan.valid = false;
1765
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1766 1767
		if (vlan.member[i] !=
		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
1768
			vlan.valid = true;
1769 1770 1771 1772
			break;
		}
	}

1773
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1774 1775 1776
	if (err)
		return err;

1777
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
1778 1779
}

1780 1781
static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
				   const struct switchdev_obj_port_vlan *vlan)
1782
{
V
Vivien Didelot 已提交
1783
	struct mv88e6xxx_chip *chip = ds->priv;
1784 1785 1786
	u16 pvid, vid;
	int err = 0;

1787
	if (!chip->info->max_vid)
1788 1789
		return -EOPNOTSUPP;

1790
	mutex_lock(&chip->reg_lock);
1791

1792
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
1793 1794 1795
	if (err)
		goto unlock;

1796
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1797
		err = _mv88e6xxx_port_vlan_del(chip, port, vid);
1798 1799 1800 1801
		if (err)
			goto unlock;

		if (vid == pvid) {
1802
			err = mv88e6xxx_port_set_pvid(chip, port, 0);
1803 1804 1805 1806 1807
			if (err)
				goto unlock;
		}
	}

1808
unlock:
1809
	mutex_unlock(&chip->reg_lock);
1810 1811 1812 1813

	return err;
}

1814 1815
static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
				  const unsigned char *addr, u16 vid)
1816
{
V
Vivien Didelot 已提交
1817
	struct mv88e6xxx_chip *chip = ds->priv;
1818
	int err;
1819

1820
	mutex_lock(&chip->reg_lock);
1821 1822
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1823
	mutex_unlock(&chip->reg_lock);
1824 1825

	return err;
1826 1827
}

1828
static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1829
				  const unsigned char *addr, u16 vid)
1830
{
V
Vivien Didelot 已提交
1831
	struct mv88e6xxx_chip *chip = ds->priv;
1832
	int err;
1833

1834
	mutex_lock(&chip->reg_lock);
1835
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1836
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
1837
	mutex_unlock(&chip->reg_lock);
1838

1839
	return err;
1840 1841
}

1842 1843
static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
				      u16 fid, u16 vid, int port,
1844
				      dsa_fdb_dump_cb_t *cb, void *data)
1845
{
1846
	struct mv88e6xxx_atu_entry addr;
1847
	bool is_static;
1848 1849
	int err;

1850
	addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1851
	eth_broadcast_addr(addr.mac);
1852 1853

	do {
1854
		mutex_lock(&chip->reg_lock);
1855
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
1856
		mutex_unlock(&chip->reg_lock);
1857
		if (err)
1858
			return err;
1859

1860
		if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
1861 1862
			break;

1863
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
1864 1865
			continue;

1866 1867
		if (!is_unicast_ether_addr(addr.mac))
			continue;
1868

1869 1870 1871
		is_static = (addr.state ==
			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
		err = cb(addr.mac, vid, is_static, data);
1872 1873
		if (err)
			return err;
1874 1875 1876 1877 1878
	} while (!is_broadcast_ether_addr(addr.mac));

	return err;
}

1879
static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1880
				  dsa_fdb_dump_cb_t *cb, void *data)
1881
{
1882
	struct mv88e6xxx_vtu_entry vlan = {
1883
		.vid = chip->info->max_vid,
1884
	};
1885
	u16 fid;
1886 1887
	int err;

1888
	/* Dump port's default Filtering Information Database (VLAN ID 0) */
1889
	mutex_lock(&chip->reg_lock);
1890
	err = mv88e6xxx_port_get_fid(chip, port, &fid);
1891 1892
	mutex_unlock(&chip->reg_lock);

1893
	if (err)
1894
		return err;
1895

1896
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
1897
	if (err)
1898
		return err;
1899

1900
	/* Dump VLANs' Filtering Information Databases */
1901
	do {
1902
		mutex_lock(&chip->reg_lock);
1903
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1904
		mutex_unlock(&chip->reg_lock);
1905
		if (err)
1906
			return err;
1907 1908 1909 1910

		if (!vlan.valid)
			break;

1911
		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1912
						 cb, data);
1913
		if (err)
1914
			return err;
1915
	} while (vlan.vid < chip->info->max_vid);
1916

1917 1918 1919 1920
	return err;
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1921
				   dsa_fdb_dump_cb_t *cb, void *data)
1922
{
V
Vivien Didelot 已提交
1923
	struct mv88e6xxx_chip *chip = ds->priv;
1924

1925
	return mv88e6xxx_port_db_dump(chip, port, cb, data);
1926 1927
}

1928 1929
static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
				struct net_device *br)
1930
{
1931
	struct dsa_switch *ds;
1932
	int port;
1933
	int dev;
1934
	int err;
1935

1936 1937 1938 1939
	/* 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);
1940
			if (err)
1941
				return err;
1942 1943 1944
		}
	}

1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962
	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;
			}
		}
	}

1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973
	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);
1974
	mutex_unlock(&chip->reg_lock);
1975

1976
	return err;
1977 1978
}

1979 1980
static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
					struct net_device *br)
1981
{
V
Vivien Didelot 已提交
1982
	struct mv88e6xxx_chip *chip = ds->priv;
1983

1984
	mutex_lock(&chip->reg_lock);
1985 1986 1987
	if (mv88e6xxx_bridge_map(chip, br) ||
	    mv88e6xxx_port_vlan_map(chip, port))
		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
1988
	mutex_unlock(&chip->reg_lock);
1989 1990
}

1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020
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);
}

2021 2022 2023 2024 2025 2026 2027 2028
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->reset)
		return chip->info->ops->reset(chip);

	return 0;
}

2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041
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);
	}
}

2042
static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2043
{
2044
	int i, err;
2045

2046
	/* Set all ports to the Disabled state */
2047
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2048
		err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
2049 2050
		if (err)
			return err;
2051 2052
	}

2053 2054 2055
	/* Wait for transmit queues to drain,
	 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
	 */
2056 2057
	usleep_range(2000, 4000);

2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068
	return 0;
}

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

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

2069
	mv88e6xxx_hardware_reset(chip);
2070

2071
	return mv88e6xxx_software_reset(chip);
2072 2073
}

2074
static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
2075 2076
				   enum mv88e6xxx_frame_mode frame,
				   enum mv88e6xxx_egress_mode egress, u16 etype)
2077 2078 2079
{
	int err;

2080 2081 2082 2083
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
2084 2085 2086
	if (err)
		return err;

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

2097
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2098
{
2099
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
2100
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2101
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2102
}
2103

2104 2105 2106
static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
2107
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2108
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2109
}
2110

2111 2112 2113 2114
static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port,
				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
2115 2116
				       MV88E6XXX_EGRESS_MODE_ETHERTYPE,
				       ETH_P_EDSA);
2117
}
2118

2119 2120 2121 2122
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);
2123

2124
	if (dsa_is_user_port(chip->ds, port))
2125
		return mv88e6xxx_set_port_mode_normal(chip, port);
2126

2127 2128 2129
	/* 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);
2130

2131 2132
	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
		return mv88e6xxx_set_port_mode_edsa(chip, port);
2133

2134
	return -EINVAL;
2135 2136
}

2137
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2138
{
2139
	bool message = dsa_is_dsa_port(chip->ds, port);
2140

2141
	return mv88e6xxx_port_set_message_port(chip, port, message);
2142
}
2143

2144
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2145
{
2146 2147
	struct dsa_switch *ds = chip->ds;
	bool flood;
2148

2149
	/* Upstream ports flood frames with unknown unicast or multicast DA */
2150
	flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
2151 2152 2153
	if (chip->info->ops->port_set_egress_floods)
		return chip->info->ops->port_set_egress_floods(chip, port,
							       flood, flood);
2154

2155
	return 0;
2156 2157
}

2158 2159 2160
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
2161 2162
	if (chip->info->ops->serdes_power)
		return chip->info->ops->serdes_power(chip, port, on);
2163

2164
	return 0;
2165 2166
}

2167 2168 2169 2170 2171 2172
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

2173
	upstream_port = dsa_upstream_port(ds, port);
2174 2175 2176 2177 2178 2179 2180
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196
	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;
		}
	}

2197 2198 2199
	return 0;
}

2200
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
2201
{
2202
	struct dsa_switch *ds = chip->ds;
2203
	int err;
2204
	u16 reg;
2205

2206 2207 2208
	chip->ports[port].chip = chip;
	chip->ports[port].port = port;

2209 2210 2211 2212 2213 2214 2215
	/* 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,
2216
					       PAUSE_OFF,
2217 2218 2219 2220
					       PHY_INTERFACE_MODE_NA);
	else
		err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
					       SPEED_UNFORCED, DUPLEX_UNFORCED,
2221
					       PAUSE_ON,
2222 2223 2224
					       PHY_INTERFACE_MODE_NA);
	if (err)
		return err;
2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239

	/* 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.
	 */
2240 2241 2242 2243
	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);
2244 2245
	if (err)
		return err;
2246

2247
	err = mv88e6xxx_setup_port_mode(chip, port);
2248 2249
	if (err)
		return err;
2250

2251
	err = mv88e6xxx_setup_egress_floods(chip, port);
2252 2253 2254
	if (err)
		return err;

2255 2256 2257
	/* 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.
2258
	 */
2259 2260 2261 2262 2263
	if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
		err = mv88e6xxx_serdes_power(chip, port, true);
		if (err)
			return err;
	}
2264

2265
	/* Port Control 2: don't force a good FCS, set the maximum frame size to
2266
	 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
2267 2268 2269
	 * 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.
2270
	 */
2271 2272 2273
	err = mv88e6xxx_port_set_map_da(chip, port);
	if (err)
		return err;
2274

2275 2276 2277
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
2278

2279
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
2280
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
2281 2282 2283
	if (err)
		return err;

2284 2285
	if (chip->info->ops->port_set_jumbo_size) {
		err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
2286 2287 2288 2289
		if (err)
			return err;
	}

2290 2291 2292 2293 2294
	/* 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.
	 */
2295
	reg = 1 << port;
2296 2297
	/* Disable learning for CPU port */
	if (dsa_is_cpu_port(ds, port))
2298
		reg = 0;
2299

2300 2301
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
2302 2303
	if (err)
		return err;
2304 2305

	/* Egress rate control 2: disable egress rate control. */
2306 2307
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
				   0x0000);
2308 2309
	if (err)
		return err;
2310

2311 2312
	if (chip->info->ops->port_pause_limit) {
		err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
2313 2314
		if (err)
			return err;
2315
	}
2316

2317 2318 2319 2320 2321 2322
	if (chip->info->ops->port_disable_learn_limit) {
		err = chip->info->ops->port_disable_learn_limit(chip, port);
		if (err)
			return err;
	}

2323 2324
	if (chip->info->ops->port_disable_pri_override) {
		err = chip->info->ops->port_disable_pri_override(chip, port);
2325 2326
		if (err)
			return err;
2327
	}
2328

2329 2330
	if (chip->info->ops->port_tag_remap) {
		err = chip->info->ops->port_tag_remap(chip, port);
2331 2332
		if (err)
			return err;
2333 2334
	}

2335 2336
	if (chip->info->ops->port_egress_rate_limiting) {
		err = chip->info->ops->port_egress_rate_limiting(chip, port);
2337 2338
		if (err)
			return err;
2339 2340
	}

2341
	err = mv88e6xxx_setup_message_port(chip, port);
2342 2343
	if (err)
		return err;
2344

2345
	/* Port based VLAN map: give each port the same default address
2346 2347
	 * database, and allow bidirectional communication between the
	 * CPU and DSA port(s), and the other ports.
2348
	 */
2349
	err = mv88e6xxx_port_set_fid(chip, port, 0);
2350 2351
	if (err)
		return err;
2352

2353
	err = mv88e6xxx_port_vlan_map(chip, port);
2354 2355
	if (err)
		return err;
2356 2357 2358 2359

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

2363 2364 2365 2366
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
2367
	int err;
2368 2369

	mutex_lock(&chip->reg_lock);
2370

2371
	err = mv88e6xxx_serdes_power(chip, port, true);
2372 2373 2374 2375

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

2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386
	mutex_unlock(&chip->reg_lock);

	return err;
}

static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port,
				   struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;

	mutex_lock(&chip->reg_lock);
2387 2388 2389 2390

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

2391 2392
	if (mv88e6xxx_serdes_power(chip, port, false))
		dev_err(chip->dev, "failed to power off SERDES\n");
2393

2394 2395 2396
	mutex_unlock(&chip->reg_lock);
}

2397 2398 2399
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
2400
	struct mv88e6xxx_chip *chip = ds->priv;
2401 2402 2403
	int err;

	mutex_lock(&chip->reg_lock);
2404
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2405 2406 2407 2408 2409
	mutex_unlock(&chip->reg_lock);

	return err;
}

2410
static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
2411
{
2412
	int err;
2413

2414
	/* Initialize the statistics unit */
2415 2416 2417 2418 2419
	if (chip->info->ops->stats_set_histogram) {
		err = chip->info->ops->stats_set_histogram(chip);
		if (err)
			return err;
	}
2420

2421
	return mv88e6xxx_g1_stats_clear(chip);
2422 2423
}

2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524
/* 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);
}

2525
static int mv88e6xxx_setup(struct dsa_switch *ds)
2526
{
V
Vivien Didelot 已提交
2527
	struct mv88e6xxx_chip *chip = ds->priv;
2528
	u8 cmode;
2529
	int err;
2530 2531
	int i;

2532
	chip->ds = ds;
2533
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
2534

2535
	mutex_lock(&chip->reg_lock);
2536

2537 2538 2539 2540 2541 2542
	if (chip->info->ops->setup_errata) {
		err = chip->info->ops->setup_errata(chip);
		if (err)
			goto unlock;
	}

2543 2544 2545 2546 2547
	/* 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)
2548
				goto unlock;
2549 2550 2551 2552 2553

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

2554
	/* Setup Switch Port Registers */
2555
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2556 2557 2558
		if (dsa_is_unused_port(ds, i))
			continue;

2559 2560 2561 2562 2563
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

2564 2565 2566 2567
	err = mv88e6xxx_irl_setup(chip);
	if (err)
		goto unlock;

2568 2569 2570 2571
	err = mv88e6xxx_mac_setup(chip);
	if (err)
		goto unlock;

2572 2573 2574 2575
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

2576 2577 2578 2579
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

2580 2581 2582 2583
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

2584 2585 2586 2587
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

2588 2589 2590 2591
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

2592 2593 2594 2595
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

2596 2597 2598 2599
	err = mv88e6xxx_rmu_setup(chip);
	if (err)
		goto unlock;

2600 2601 2602
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
2603

2604 2605 2606 2607
	err = mv88e6xxx_trunk_setup(chip);
	if (err)
		goto unlock;

2608 2609 2610 2611
	err = mv88e6xxx_devmap_setup(chip);
	if (err)
		goto unlock;

2612 2613 2614 2615
	err = mv88e6xxx_pri_setup(chip);
	if (err)
		goto unlock;

2616
	/* Setup PTP Hardware Clock and timestamping */
2617 2618 2619 2620
	if (chip->info->ptp_support) {
		err = mv88e6xxx_ptp_setup(chip);
		if (err)
			goto unlock;
2621 2622 2623 2624

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
2625 2626
	}

2627 2628 2629 2630
	err = mv88e6xxx_stats_setup(chip);
	if (err)
		goto unlock;

2631
unlock:
2632
	mutex_unlock(&chip->reg_lock);
2633

2634
	return err;
2635 2636
}

2637
static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
2638
{
2639 2640
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2641 2642
	u16 val;
	int err;
2643

2644 2645 2646
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

2647
	mutex_lock(&chip->reg_lock);
2648
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
2649
	mutex_unlock(&chip->reg_lock);
2650

2651
	if (reg == MII_PHYSID2) {
2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667
		/* 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;
2668 2669
	}

2670
	return err ? err : val;
2671 2672
}

2673
static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
2674
{
2675 2676
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2677
	int err;
2678

2679 2680 2681
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

2682
	mutex_lock(&chip->reg_lock);
2683
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
2684
	mutex_unlock(&chip->reg_lock);
2685 2686

	return err;
2687 2688
}

2689
static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
2690 2691
				   struct device_node *np,
				   bool external)
2692 2693
{
	static int index;
2694
	struct mv88e6xxx_mdio_bus *mdio_bus;
2695 2696 2697
	struct mii_bus *bus;
	int err;

2698 2699 2700 2701 2702 2703 2704 2705 2706
	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;
	}

2707
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
2708 2709 2710
	if (!bus)
		return -ENOMEM;

2711
	mdio_bus = bus->priv;
2712
	mdio_bus->bus = bus;
2713
	mdio_bus->chip = chip;
2714 2715
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
2716

2717 2718
	if (np) {
		bus->name = np->full_name;
2719
		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
2720 2721 2722 2723 2724 2725 2726
	} 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;
2727
	bus->parent = chip->dev;
2728

2729 2730 2731 2732 2733 2734
	if (!external) {
		err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
		if (err)
			return err;
	}

2735
	err = of_mdiobus_register(bus, np);
2736
	if (err) {
2737
		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
2738
		mv88e6xxx_g2_irq_mdio_free(chip, bus);
2739
		return err;
2740
	}
2741 2742 2743 2744 2745

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

	return 0;
2748
}
2749

2750 2751 2752 2753 2754
static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
	{ .compatible = "marvell,mv88e6xxx-mdio-external",
	  .data = (void *)true },
	{ },
};
2755

2756 2757 2758 2759 2760 2761 2762 2763 2764
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;

2765 2766 2767
		if (!mdio_bus->external)
			mv88e6xxx_g2_irq_mdio_free(chip, bus);

2768 2769 2770 2771
		mdiobus_unregister(bus);
	}
}

2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795
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);
2796 2797
			if (err) {
				mv88e6xxx_mdios_unregister(chip);
2798
				return err;
2799
			}
2800 2801 2802 2803
		}
	}

	return 0;
2804 2805
}

2806 2807
static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
2808
	struct mv88e6xxx_chip *chip = ds->priv;
2809 2810 2811 2812 2813 2814 2815

	return chip->eeprom_len;
}

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

2819 2820
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
2821

2822 2823
	mutex_lock(&chip->reg_lock);
	err = chip->info->ops->get_eeprom(chip, eeprom, data);
2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836
	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 已提交
2837
	struct mv88e6xxx_chip *chip = ds->priv;
2838 2839
	int err;

2840 2841 2842
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

2843 2844 2845 2846
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

	mutex_lock(&chip->reg_lock);
2847
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
2848 2849 2850 2851 2852
	mutex_unlock(&chip->reg_lock);

	return err;
}

2853
static const struct mv88e6xxx_ops mv88e6085_ops = {
2854
	/* MV88E6XXX_FAMILY_6097 */
2855 2856
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2857
	.irl_init_all = mv88e6352_g2_irl_init_all,
2858
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2859 2860
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2861
	.port_set_link = mv88e6xxx_port_set_link,
2862
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2863
	.port_set_speed = mv88e6185_port_set_speed,
2864
	.port_tag_remap = mv88e6095_port_tag_remap,
2865
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2866
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2867
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2868
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2869
	.port_pause_limit = mv88e6097_port_pause_limit,
2870
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2871
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2872
	.port_link_state = mv88e6352_port_link_state,
2873
	.port_get_cmode = mv88e6185_port_get_cmode,
2874
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2875
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2876 2877
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2878
	.stats_get_stats = mv88e6095_stats_get_stats,
2879 2880
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2881
	.watchdog_ops = &mv88e6097_watchdog_ops,
2882
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2883
	.pot_clear = mv88e6xxx_g2_pot_clear,
2884 2885
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2886
	.reset = mv88e6185_g1_reset,
2887
	.rmu_disable = mv88e6085_g1_rmu_disable,
2888
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2889
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2890
	.phylink_validate = mv88e6185_phylink_validate,
2891 2892 2893
};

static const struct mv88e6xxx_ops mv88e6095_ops = {
2894
	/* MV88E6XXX_FAMILY_6095 */
2895 2896
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2897
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2898 2899
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2900
	.port_set_link = mv88e6xxx_port_set_link,
2901
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2902
	.port_set_speed = mv88e6185_port_set_speed,
2903
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2904
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2905
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2906
	.port_link_state = mv88e6185_port_link_state,
2907
	.port_get_cmode = mv88e6185_port_get_cmode,
2908
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2909
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2910 2911
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2912
	.stats_get_stats = mv88e6095_stats_get_stats,
2913
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2914 2915
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2916
	.reset = mv88e6185_g1_reset,
2917
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2918
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2919
	.phylink_validate = mv88e6185_phylink_validate,
2920 2921
};

2922
static const struct mv88e6xxx_ops mv88e6097_ops = {
2923
	/* MV88E6XXX_FAMILY_6097 */
2924 2925
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2926
	.irl_init_all = mv88e6352_g2_irl_init_all,
2927 2928 2929 2930 2931 2932
	.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,
2933
	.port_tag_remap = mv88e6095_port_tag_remap,
2934
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2935
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2936
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2937
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2938
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
2939
	.port_pause_limit = mv88e6097_port_pause_limit,
2940
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2941
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2942
	.port_link_state = mv88e6352_port_link_state,
2943
	.port_get_cmode = mv88e6185_port_get_cmode,
2944
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2945
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2946 2947 2948
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
	.stats_get_stats = mv88e6095_stats_get_stats,
2949 2950
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2951
	.watchdog_ops = &mv88e6097_watchdog_ops,
2952
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2953
	.pot_clear = mv88e6xxx_g2_pot_clear,
2954
	.reset = mv88e6352_g1_reset,
2955
	.rmu_disable = mv88e6085_g1_rmu_disable,
2956
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2957
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2958
	.phylink_validate = mv88e6185_phylink_validate,
2959 2960
};

2961
static const struct mv88e6xxx_ops mv88e6123_ops = {
2962
	/* MV88E6XXX_FAMILY_6165 */
2963 2964
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2965
	.irl_init_all = mv88e6352_g2_irl_init_all,
2966
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2967 2968
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2969
	.port_set_link = mv88e6xxx_port_set_link,
2970
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2971
	.port_set_speed = mv88e6185_port_set_speed,
2972
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2973
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2974
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2975
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2976
	.port_link_state = mv88e6352_port_link_state,
2977
	.port_get_cmode = mv88e6185_port_get_cmode,
2978
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2979
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2980 2981
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2982
	.stats_get_stats = mv88e6095_stats_get_stats,
2983 2984
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2985
	.watchdog_ops = &mv88e6097_watchdog_ops,
2986
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2987
	.pot_clear = mv88e6xxx_g2_pot_clear,
2988
	.reset = mv88e6352_g1_reset,
2989
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2990
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2991
	.phylink_validate = mv88e6185_phylink_validate,
2992 2993 2994
};

static const struct mv88e6xxx_ops mv88e6131_ops = {
2995
	/* MV88E6XXX_FAMILY_6185 */
2996 2997
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2998
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2999 3000
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3001
	.port_set_link = mv88e6xxx_port_set_link,
3002
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3003
	.port_set_speed = mv88e6185_port_set_speed,
3004
	.port_tag_remap = mv88e6095_port_tag_remap,
3005
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3006
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
3007
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3008
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
3009
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3010
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3011
	.port_pause_limit = mv88e6097_port_pause_limit,
3012
	.port_set_pause = mv88e6185_port_set_pause,
3013
	.port_link_state = mv88e6352_port_link_state,
3014
	.port_get_cmode = mv88e6185_port_get_cmode,
3015
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3016
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3017 3018
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3019
	.stats_get_stats = mv88e6095_stats_get_stats,
3020 3021
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3022
	.watchdog_ops = &mv88e6097_watchdog_ops,
3023
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3024
	.ppu_enable = mv88e6185_g1_ppu_enable,
3025
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
3026
	.ppu_disable = mv88e6185_g1_ppu_disable,
3027
	.reset = mv88e6185_g1_reset,
3028
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3029
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3030
	.phylink_validate = mv88e6185_phylink_validate,
3031 3032
};

3033 3034
static const struct mv88e6xxx_ops mv88e6141_ops = {
	/* MV88E6XXX_FAMILY_6341 */
3035 3036
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3037
	.irl_init_all = mv88e6352_g2_irl_init_all,
3038 3039 3040 3041 3042 3043 3044 3045
	.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,
3046
	.port_set_speed = mv88e6341_port_set_speed,
3047 3048 3049 3050
	.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,
3051
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3052
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3053
	.port_pause_limit = mv88e6097_port_pause_limit,
3054 3055
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3056
	.port_link_state = mv88e6352_port_link_state,
3057
	.port_get_cmode = mv88e6352_port_get_cmode,
3058
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3059
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3060 3061 3062
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
3063 3064
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3065 3066
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
3067
	.pot_clear = mv88e6xxx_g2_pot_clear,
3068
	.reset = mv88e6352_g1_reset,
3069
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3070
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3071
	.serdes_power = mv88e6341_serdes_power,
3072
	.gpio_ops = &mv88e6352_gpio_ops,
3073
	.phylink_validate = mv88e6390_phylink_validate,
3074 3075
};

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

static const struct mv88e6xxx_ops mv88e6165_ops = {
3117
	/* MV88E6XXX_FAMILY_6165 */
3118 3119
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3120
	.irl_init_all = mv88e6352_g2_irl_init_all,
3121
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3122 3123
	.phy_read = mv88e6165_phy_read,
	.phy_write = mv88e6165_phy_write,
3124
	.port_set_link = mv88e6xxx_port_set_link,
3125
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3126
	.port_set_speed = mv88e6185_port_set_speed,
3127
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3128
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3129
	.port_link_state = mv88e6352_port_link_state,
3130
	.port_get_cmode = mv88e6185_port_get_cmode,
3131
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3132
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3133 3134
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3135
	.stats_get_stats = mv88e6095_stats_get_stats,
3136 3137
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3138
	.watchdog_ops = &mv88e6097_watchdog_ops,
3139
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3140
	.pot_clear = mv88e6xxx_g2_pot_clear,
3141
	.reset = mv88e6352_g1_reset,
3142
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3143
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3144
	.avb_ops = &mv88e6165_avb_ops,
3145
	.ptp_ops = &mv88e6165_ptp_ops,
3146
	.phylink_validate = mv88e6185_phylink_validate,
3147 3148 3149
};

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

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

static const struct mv88e6xxx_ops mv88e6175_ops = {
3233
	/* MV88E6XXX_FAMILY_6351 */
3234 3235
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3236
	.irl_init_all = mv88e6352_g2_irl_init_all,
3237
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3238 3239
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3240
	.port_set_link = mv88e6xxx_port_set_link,
3241
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3242
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3243
	.port_set_speed = mv88e6185_port_set_speed,
3244
	.port_tag_remap = mv88e6095_port_tag_remap,
3245
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3246
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3247
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3248
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3249
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3250
	.port_pause_limit = mv88e6097_port_pause_limit,
3251
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3252
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3253
	.port_link_state = mv88e6352_port_link_state,
3254
	.port_get_cmode = mv88e6352_port_get_cmode,
3255
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3256
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3257 3258
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3259
	.stats_get_stats = mv88e6095_stats_get_stats,
3260 3261
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3262
	.watchdog_ops = &mv88e6097_watchdog_ops,
3263
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3264
	.pot_clear = mv88e6xxx_g2_pot_clear,
3265
	.reset = mv88e6352_g1_reset,
3266
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3267
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3268
	.phylink_validate = mv88e6185_phylink_validate,
3269 3270 3271
};

static const struct mv88e6xxx_ops mv88e6176_ops = {
3272
	/* MV88E6XXX_FAMILY_6352 */
3273 3274
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3275
	.irl_init_all = mv88e6352_g2_irl_init_all,
3276 3277
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3278
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3279 3280
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3281
	.port_set_link = mv88e6xxx_port_set_link,
3282
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3283
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3284
	.port_set_speed = mv88e6352_port_set_speed,
3285
	.port_tag_remap = mv88e6095_port_tag_remap,
3286
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3287
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3288
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3289
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3290
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3291
	.port_pause_limit = mv88e6097_port_pause_limit,
3292
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3293
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3294
	.port_link_state = mv88e6352_port_link_state,
3295
	.port_get_cmode = mv88e6352_port_get_cmode,
3296
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3297
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3298 3299
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3300
	.stats_get_stats = mv88e6095_stats_get_stats,
3301 3302
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3303
	.watchdog_ops = &mv88e6097_watchdog_ops,
3304
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3305
	.pot_clear = mv88e6xxx_g2_pot_clear,
3306
	.reset = mv88e6352_g1_reset,
3307
	.rmu_disable = mv88e6352_g1_rmu_disable,
3308
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3309
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3310
	.serdes_power = mv88e6352_serdes_power,
3311 3312
	.serdes_irq_setup = mv88e6352_serdes_irq_setup,
	.serdes_irq_free = mv88e6352_serdes_irq_free,
3313
	.gpio_ops = &mv88e6352_gpio_ops,
3314
	.phylink_validate = mv88e6352_phylink_validate,
3315 3316 3317
};

static const struct mv88e6xxx_ops mv88e6185_ops = {
3318
	/* MV88E6XXX_FAMILY_6185 */
3319 3320
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3321
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3322 3323
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3324
	.port_set_link = mv88e6xxx_port_set_link,
3325
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3326
	.port_set_speed = mv88e6185_port_set_speed,
3327
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
3328
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
3329
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
3330
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
3331
	.port_set_pause = mv88e6185_port_set_pause,
3332
	.port_link_state = mv88e6185_port_link_state,
3333
	.port_get_cmode = mv88e6185_port_get_cmode,
3334
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3335
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3336 3337
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3338
	.stats_get_stats = mv88e6095_stats_get_stats,
3339 3340
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3341
	.watchdog_ops = &mv88e6097_watchdog_ops,
3342
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3343
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
3344 3345
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
3346
	.reset = mv88e6185_g1_reset,
3347
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3348
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3349
	.phylink_validate = mv88e6185_phylink_validate,
3350 3351
};

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

static const struct mv88e6xxx_ops mv88e6190x_ops = {
3397
	/* MV88E6XXX_FAMILY_6390 */
3398
	.setup_errata = mv88e6390_setup_errata,
3399
	.irl_init_all = mv88e6390_g2_irl_init_all,
3400 3401
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3402 3403 3404 3405 3406 3407 3408
	.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,
3409
	.port_tag_remap = mv88e6390_port_tag_remap,
3410
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3411
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3412
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3413
	.port_pause_limit = mv88e6390_port_pause_limit,
3414
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3415
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3416
	.port_link_state = mv88e6352_port_link_state,
3417
	.port_get_cmode = mv88e6352_port_get_cmode,
3418
	.port_set_cmode = mv88e6390x_port_set_cmode,
3419
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3420
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3421 3422
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3423
	.stats_get_stats = mv88e6390_stats_get_stats,
3424 3425
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3426
	.watchdog_ops = &mv88e6390_watchdog_ops,
3427
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3428
	.pot_clear = mv88e6xxx_g2_pot_clear,
3429
	.reset = mv88e6352_g1_reset,
3430
	.rmu_disable = mv88e6390_g1_rmu_disable,
3431 3432
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3433
	.serdes_power = mv88e6390x_serdes_power,
3434 3435
	.serdes_irq_setup = mv88e6390x_serdes_irq_setup,
	.serdes_irq_free = mv88e6390x_serdes_irq_free,
3436
	.gpio_ops = &mv88e6352_gpio_ops,
3437
	.phylink_validate = mv88e6390x_phylink_validate,
3438 3439 3440
};

static const struct mv88e6xxx_ops mv88e6191_ops = {
3441
	/* MV88E6XXX_FAMILY_6390 */
3442
	.setup_errata = mv88e6390_setup_errata,
3443
	.irl_init_all = mv88e6390_g2_irl_init_all,
3444 3445
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3446 3447 3448 3449 3450 3451 3452
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
	.port_set_speed = mv88e6390_port_set_speed,
3453
	.port_tag_remap = mv88e6390_port_tag_remap,
3454
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3455
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3456
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3457
	.port_pause_limit = mv88e6390_port_pause_limit,
3458
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3459
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3460
	.port_link_state = mv88e6352_port_link_state,
3461
	.port_get_cmode = mv88e6352_port_get_cmode,
3462
	.port_set_cmode = mv88e6390_port_set_cmode,
3463
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3464
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3465 3466
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3467
	.stats_get_stats = mv88e6390_stats_get_stats,
3468 3469
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3470
	.watchdog_ops = &mv88e6390_watchdog_ops,
3471
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3472
	.pot_clear = mv88e6xxx_g2_pot_clear,
3473
	.reset = mv88e6352_g1_reset,
3474
	.rmu_disable = mv88e6390_g1_rmu_disable,
3475 3476
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3477
	.serdes_power = mv88e6390_serdes_power,
3478 3479
	.serdes_irq_setup = mv88e6390_serdes_irq_setup,
	.serdes_irq_free = mv88e6390_serdes_irq_free,
3480 3481
	.avb_ops = &mv88e6390_avb_ops,
	.ptp_ops = &mv88e6352_ptp_ops,
3482
	.phylink_validate = mv88e6390_phylink_validate,
3483 3484
};

3485
static const struct mv88e6xxx_ops mv88e6240_ops = {
3486
	/* MV88E6XXX_FAMILY_6352 */
3487 3488
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3489
	.irl_init_all = mv88e6352_g2_irl_init_all,
3490 3491
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3492
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3493 3494
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3495
	.port_set_link = mv88e6xxx_port_set_link,
3496
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3497
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3498
	.port_set_speed = mv88e6352_port_set_speed,
3499
	.port_tag_remap = mv88e6095_port_tag_remap,
3500
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3501
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3502
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3503
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3504
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3505
	.port_pause_limit = mv88e6097_port_pause_limit,
3506
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3507
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3508
	.port_link_state = mv88e6352_port_link_state,
3509
	.port_get_cmode = mv88e6352_port_get_cmode,
3510
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3511
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3512 3513
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3514
	.stats_get_stats = mv88e6095_stats_get_stats,
3515 3516
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3517
	.watchdog_ops = &mv88e6097_watchdog_ops,
3518
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3519
	.pot_clear = mv88e6xxx_g2_pot_clear,
3520
	.reset = mv88e6352_g1_reset,
3521
	.rmu_disable = mv88e6352_g1_rmu_disable,
3522
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3523
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3524
	.serdes_power = mv88e6352_serdes_power,
3525 3526
	.serdes_irq_setup = mv88e6352_serdes_irq_setup,
	.serdes_irq_free = mv88e6352_serdes_irq_free,
3527
	.gpio_ops = &mv88e6352_gpio_ops,
3528
	.avb_ops = &mv88e6352_avb_ops,
3529
	.ptp_ops = &mv88e6352_ptp_ops,
3530
	.phylink_validate = mv88e6352_phylink_validate,
3531 3532
};

3533
static const struct mv88e6xxx_ops mv88e6290_ops = {
3534
	/* MV88E6XXX_FAMILY_6390 */
3535
	.setup_errata = mv88e6390_setup_errata,
3536
	.irl_init_all = mv88e6390_g2_irl_init_all,
3537 3538
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3539 3540 3541 3542 3543 3544 3545
	.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,
3546
	.port_tag_remap = mv88e6390_port_tag_remap,
3547
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3548
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3549
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3550
	.port_pause_limit = mv88e6390_port_pause_limit,
3551
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3552
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3553
	.port_link_state = mv88e6352_port_link_state,
3554
	.port_get_cmode = mv88e6352_port_get_cmode,
3555
	.port_set_cmode = mv88e6390_port_set_cmode,
3556
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3557
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3558 3559
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3560
	.stats_get_stats = mv88e6390_stats_get_stats,
3561 3562
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3563
	.watchdog_ops = &mv88e6390_watchdog_ops,
3564
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3565
	.pot_clear = mv88e6xxx_g2_pot_clear,
3566
	.reset = mv88e6352_g1_reset,
3567
	.rmu_disable = mv88e6390_g1_rmu_disable,
3568 3569
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3570
	.serdes_power = mv88e6390_serdes_power,
3571 3572
	.serdes_irq_setup = mv88e6390_serdes_irq_setup,
	.serdes_irq_free = mv88e6390_serdes_irq_free,
3573
	.gpio_ops = &mv88e6352_gpio_ops,
3574
	.avb_ops = &mv88e6390_avb_ops,
3575
	.ptp_ops = &mv88e6352_ptp_ops,
3576
	.phylink_validate = mv88e6390_phylink_validate,
3577 3578
};

3579
static const struct mv88e6xxx_ops mv88e6320_ops = {
3580
	/* MV88E6XXX_FAMILY_6320 */
3581 3582
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3583
	.irl_init_all = mv88e6352_g2_irl_init_all,
3584 3585
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3586
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3587 3588
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3589
	.port_set_link = mv88e6xxx_port_set_link,
3590
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3591
	.port_set_speed = mv88e6185_port_set_speed,
3592
	.port_tag_remap = mv88e6095_port_tag_remap,
3593
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3594
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3595
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3596
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3597
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3598
	.port_pause_limit = mv88e6097_port_pause_limit,
3599
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3600
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3601
	.port_link_state = mv88e6352_port_link_state,
3602
	.port_get_cmode = mv88e6352_port_get_cmode,
3603
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3604
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3605 3606
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3607
	.stats_get_stats = mv88e6320_stats_get_stats,
3608 3609
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3610
	.watchdog_ops = &mv88e6390_watchdog_ops,
3611
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3612
	.pot_clear = mv88e6xxx_g2_pot_clear,
3613
	.reset = mv88e6352_g1_reset,
3614
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3615
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3616
	.gpio_ops = &mv88e6352_gpio_ops,
3617
	.avb_ops = &mv88e6352_avb_ops,
3618
	.ptp_ops = &mv88e6352_ptp_ops,
3619
	.phylink_validate = mv88e6185_phylink_validate,
3620 3621 3622
};

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

3663 3664
static const struct mv88e6xxx_ops mv88e6341_ops = {
	/* MV88E6XXX_FAMILY_6341 */
3665 3666
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3667
	.irl_init_all = mv88e6352_g2_irl_init_all,
3668 3669 3670 3671 3672 3673 3674 3675
	.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,
3676
	.port_set_speed = mv88e6341_port_set_speed,
3677 3678 3679 3680
	.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,
3681
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3682
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3683
	.port_pause_limit = mv88e6097_port_pause_limit,
3684 3685
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3686
	.port_link_state = mv88e6352_port_link_state,
3687
	.port_get_cmode = mv88e6352_port_get_cmode,
3688
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3689
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3690 3691 3692
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
3693 3694
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3695 3696
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
3697
	.pot_clear = mv88e6xxx_g2_pot_clear,
3698
	.reset = mv88e6352_g1_reset,
3699
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3700
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3701
	.serdes_power = mv88e6341_serdes_power,
3702
	.gpio_ops = &mv88e6352_gpio_ops,
3703
	.avb_ops = &mv88e6390_avb_ops,
3704
	.ptp_ops = &mv88e6352_ptp_ops,
3705
	.phylink_validate = mv88e6390_phylink_validate,
3706 3707
};

3708
static const struct mv88e6xxx_ops mv88e6350_ops = {
3709
	/* MV88E6XXX_FAMILY_6351 */
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
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3714 3715
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3716
	.port_set_link = mv88e6xxx_port_set_link,
3717
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3718
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3719
	.port_set_speed = mv88e6185_port_set_speed,
3720
	.port_tag_remap = mv88e6095_port_tag_remap,
3721
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3722
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3723
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3724
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3725
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3726
	.port_pause_limit = mv88e6097_port_pause_limit,
3727
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3728
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3729
	.port_link_state = mv88e6352_port_link_state,
3730
	.port_get_cmode = mv88e6352_port_get_cmode,
3731
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3732
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3733 3734
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3735
	.stats_get_stats = mv88e6095_stats_get_stats,
3736 3737
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3738
	.watchdog_ops = &mv88e6097_watchdog_ops,
3739
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3740
	.pot_clear = mv88e6xxx_g2_pot_clear,
3741
	.reset = mv88e6352_g1_reset,
3742
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3743
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3744
	.phylink_validate = mv88e6185_phylink_validate,
3745 3746 3747
};

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

4290
	[MV88E6240] = {
4291
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
4292 4293 4294 4295
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6240",
		.num_databases = 4096,
		.num_ports = 7,
4296
		.num_internal_phys = 5,
4297
		.num_gpio = 15,
4298
		.max_vid = 4095,
4299
		.port_base_addr = 0x10,
4300
		.phy_base_addr = 0x0,
4301
		.global1_addr = 0x1b,
4302
		.global2_addr = 0x1c,
4303
		.age_time_coeff = 15000,
4304
		.g1_irqs = 9,
4305
		.g2_irqs = 10,
4306
		.atu_move_port_mask = 0xf,
4307
		.pvt = true,
4308
		.multi_chip = true,
4309
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4310
		.ptp_support = true,
4311
		.ops = &mv88e6240_ops,
4312 4313
	},

4314
	[MV88E6290] = {
4315
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
4316 4317 4318 4319
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6290",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4320
		.num_internal_phys = 11,
4321
		.num_gpio = 16,
4322
		.max_vid = 8191,
4323
		.port_base_addr = 0x0,
4324
		.phy_base_addr = 0x0,
4325
		.global1_addr = 0x1b,
4326
		.global2_addr = 0x1c,
4327
		.age_time_coeff = 3750,
4328
		.g1_irqs = 9,
4329
		.g2_irqs = 14,
4330
		.atu_move_port_mask = 0x1f,
4331
		.pvt = true,
4332
		.multi_chip = true,
4333
		.tag_protocol = DSA_TAG_PROTO_DSA,
4334
		.ptp_support = true,
4335 4336 4337
		.ops = &mv88e6290_ops,
	},

4338
	[MV88E6320] = {
4339
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
4340 4341 4342 4343
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6320",
		.num_databases = 4096,
		.num_ports = 7,
4344
		.num_internal_phys = 5,
4345
		.num_gpio = 15,
4346
		.max_vid = 4095,
4347
		.port_base_addr = 0x10,
4348
		.phy_base_addr = 0x0,
4349
		.global1_addr = 0x1b,
4350
		.global2_addr = 0x1c,
4351
		.age_time_coeff = 15000,
4352
		.g1_irqs = 8,
4353
		.g2_irqs = 10,
4354
		.atu_move_port_mask = 0xf,
4355
		.pvt = true,
4356
		.multi_chip = true,
4357
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4358
		.ptp_support = true,
4359
		.ops = &mv88e6320_ops,
4360 4361 4362
	},

	[MV88E6321] = {
4363
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
4364 4365 4366 4367
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6321",
		.num_databases = 4096,
		.num_ports = 7,
4368
		.num_internal_phys = 5,
4369
		.num_gpio = 15,
4370
		.max_vid = 4095,
4371
		.port_base_addr = 0x10,
4372
		.phy_base_addr = 0x0,
4373
		.global1_addr = 0x1b,
4374
		.global2_addr = 0x1c,
4375
		.age_time_coeff = 15000,
4376
		.g1_irqs = 8,
4377
		.g2_irqs = 10,
4378
		.atu_move_port_mask = 0xf,
4379
		.multi_chip = true,
4380
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4381
		.ptp_support = true,
4382
		.ops = &mv88e6321_ops,
4383 4384
	},

4385
	[MV88E6341] = {
4386
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
4387 4388 4389
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
4390
		.num_internal_phys = 5,
4391
		.num_ports = 6,
4392
		.num_gpio = 11,
4393
		.max_vid = 4095,
4394
		.port_base_addr = 0x10,
4395
		.phy_base_addr = 0x10,
4396
		.global1_addr = 0x1b,
4397
		.global2_addr = 0x1c,
4398
		.age_time_coeff = 3750,
4399
		.atu_move_port_mask = 0x1f,
4400
		.g1_irqs = 9,
4401
		.g2_irqs = 10,
4402
		.pvt = true,
4403
		.multi_chip = true,
4404
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4405
		.ptp_support = true,
4406 4407 4408
		.ops = &mv88e6341_ops,
	},

4409
	[MV88E6350] = {
4410
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
4411 4412 4413 4414
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6350",
		.num_databases = 4096,
		.num_ports = 7,
4415
		.num_internal_phys = 5,
4416
		.max_vid = 4095,
4417
		.port_base_addr = 0x10,
4418
		.phy_base_addr = 0x0,
4419
		.global1_addr = 0x1b,
4420
		.global2_addr = 0x1c,
4421
		.age_time_coeff = 15000,
4422
		.g1_irqs = 9,
4423
		.g2_irqs = 10,
4424
		.atu_move_port_mask = 0xf,
4425
		.pvt = true,
4426
		.multi_chip = true,
4427
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4428
		.ops = &mv88e6350_ops,
4429 4430 4431
	},

	[MV88E6351] = {
4432
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
4433 4434 4435 4436
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6351",
		.num_databases = 4096,
		.num_ports = 7,
4437
		.num_internal_phys = 5,
4438
		.max_vid = 4095,
4439
		.port_base_addr = 0x10,
4440
		.phy_base_addr = 0x0,
4441
		.global1_addr = 0x1b,
4442
		.global2_addr = 0x1c,
4443
		.age_time_coeff = 15000,
4444
		.g1_irqs = 9,
4445
		.g2_irqs = 10,
4446
		.atu_move_port_mask = 0xf,
4447
		.pvt = true,
4448
		.multi_chip = true,
4449
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4450
		.ops = &mv88e6351_ops,
4451 4452 4453
	},

	[MV88E6352] = {
4454
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
4455 4456 4457 4458
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6352",
		.num_databases = 4096,
		.num_ports = 7,
4459
		.num_internal_phys = 5,
4460
		.num_gpio = 15,
4461
		.max_vid = 4095,
4462
		.port_base_addr = 0x10,
4463
		.phy_base_addr = 0x0,
4464
		.global1_addr = 0x1b,
4465
		.global2_addr = 0x1c,
4466
		.age_time_coeff = 15000,
4467
		.g1_irqs = 9,
4468
		.g2_irqs = 10,
4469
		.atu_move_port_mask = 0xf,
4470
		.pvt = true,
4471
		.multi_chip = true,
4472
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4473
		.ptp_support = true,
4474
		.ops = &mv88e6352_ops,
4475
	},
4476
	[MV88E6390] = {
4477
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
4478 4479 4480 4481
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4482
		.num_internal_phys = 11,
4483
		.num_gpio = 16,
4484
		.max_vid = 8191,
4485
		.port_base_addr = 0x0,
4486
		.phy_base_addr = 0x0,
4487
		.global1_addr = 0x1b,
4488
		.global2_addr = 0x1c,
4489
		.age_time_coeff = 3750,
4490
		.g1_irqs = 9,
4491
		.g2_irqs = 14,
4492
		.atu_move_port_mask = 0x1f,
4493
		.pvt = true,
4494
		.multi_chip = true,
4495
		.tag_protocol = DSA_TAG_PROTO_DSA,
4496
		.ptp_support = true,
4497 4498 4499
		.ops = &mv88e6390_ops,
	},
	[MV88E6390X] = {
4500
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
4501 4502 4503 4504
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4505
		.num_internal_phys = 11,
4506
		.num_gpio = 16,
4507
		.max_vid = 8191,
4508
		.port_base_addr = 0x0,
4509
		.phy_base_addr = 0x0,
4510
		.global1_addr = 0x1b,
4511
		.global2_addr = 0x1c,
4512
		.age_time_coeff = 3750,
4513
		.g1_irqs = 9,
4514
		.g2_irqs = 14,
4515
		.atu_move_port_mask = 0x1f,
4516
		.pvt = true,
4517
		.multi_chip = true,
4518
		.tag_protocol = DSA_TAG_PROTO_DSA,
4519
		.ptp_support = true,
4520 4521
		.ops = &mv88e6390x_ops,
	},
4522 4523
};

4524
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
4525
{
4526
	int i;
4527

4528 4529 4530
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
4531 4532 4533 4534

	return NULL;
}

4535
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
4536 4537
{
	const struct mv88e6xxx_info *info;
4538 4539 4540
	unsigned int prod_num, rev;
	u16 id;
	int err;
4541

4542
	mutex_lock(&chip->reg_lock);
4543
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
4544 4545 4546
	mutex_unlock(&chip->reg_lock);
	if (err)
		return err;
4547

4548 4549
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
4550 4551 4552 4553 4554

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

4555
	/* Update the compatible info with the probed one */
4556
	chip->info = info;
4557

4558 4559 4560 4561
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

4562 4563
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
4564 4565 4566 4567

	return 0;
}

4568
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
4569
{
4570
	struct mv88e6xxx_chip *chip;
4571

4572 4573
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
4574 4575
		return NULL;

4576
	chip->dev = dev;
4577

4578
	mutex_init(&chip->reg_lock);
4579
	INIT_LIST_HEAD(&chip->mdios);
4580

4581
	return chip;
4582 4583
}

4584
static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
4585 4586
			      struct mii_bus *bus, int sw_addr)
{
4587
	if (sw_addr == 0)
4588
		chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
4589
	else if (chip->info->multi_chip)
4590
		chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
4591 4592 4593
	else
		return -EINVAL;

4594 4595
	chip->bus = bus;
	chip->sw_addr = sw_addr;
4596 4597 4598 4599

	return 0;
}

4600 4601
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
							int port)
4602
{
V
Vivien Didelot 已提交
4603
	struct mv88e6xxx_chip *chip = ds->priv;
4604

4605
	return chip->info->tag_protocol;
4606 4607
}

4608
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
4609 4610 4611
static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
				       struct device *host_dev, int sw_addr,
				       void **priv)
4612
{
4613
	struct mv88e6xxx_chip *chip;
4614
	struct mii_bus *bus;
4615
	int err;
4616

4617
	bus = dsa_host_dev_to_mii_bus(host_dev);
4618 4619 4620
	if (!bus)
		return NULL;

4621 4622
	chip = mv88e6xxx_alloc_chip(dsa_dev);
	if (!chip)
4623 4624
		return NULL;

4625
	/* Legacy SMI probing will only support chips similar to 88E6085 */
4626
	chip->info = &mv88e6xxx_table[MV88E6085];
4627

4628
	err = mv88e6xxx_smi_init(chip, bus, sw_addr);
4629 4630 4631
	if (err)
		goto free;

4632
	err = mv88e6xxx_detect(chip);
4633
	if (err)
4634
		goto free;
4635

4636 4637 4638 4639 4640 4641
	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_switch_reset(chip);
	mutex_unlock(&chip->reg_lock);
	if (err)
		goto free;

4642 4643
	mv88e6xxx_phy_init(chip);

4644
	err = mv88e6xxx_mdios_register(chip, NULL);
4645
	if (err)
4646
		goto free;
4647

4648
	*priv = chip;
4649

4650
	return chip->info->name;
4651
free:
4652
	devm_kfree(dsa_dev, chip);
4653 4654

	return NULL;
4655
}
4656
#endif
4657

4658
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4659
				      const struct switchdev_obj_port_mdb *mdb)
4660 4661 4662 4663 4664 4665 4666 4667 4668
{
	/* 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,
4669
				   const struct switchdev_obj_port_mdb *mdb)
4670
{
V
Vivien Didelot 已提交
4671
	struct mv88e6xxx_chip *chip = ds->priv;
4672 4673 4674

	mutex_lock(&chip->reg_lock);
	if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4675
					 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
4676 4677
		dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
			port);
4678 4679 4680 4681 4682 4683
	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 已提交
4684
	struct mv88e6xxx_chip *chip = ds->priv;
4685 4686 4687 4688
	int err;

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4689
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
4690 4691 4692 4693 4694
	mutex_unlock(&chip->reg_lock);

	return err;
}

4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710
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;
}

4711
static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
4712
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
4713
	.probe			= mv88e6xxx_drv_probe,
4714
#endif
4715
	.get_tag_protocol	= mv88e6xxx_get_tag_protocol,
4716 4717
	.setup			= mv88e6xxx_setup,
	.adjust_link		= mv88e6xxx_adjust_link,
4718 4719 4720 4721 4722
	.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,
4723 4724 4725
	.get_strings		= mv88e6xxx_get_strings,
	.get_ethtool_stats	= mv88e6xxx_get_ethtool_stats,
	.get_sset_count		= mv88e6xxx_get_sset_count,
4726 4727
	.port_enable		= mv88e6xxx_port_enable,
	.port_disable		= mv88e6xxx_port_disable,
V
Vivien Didelot 已提交
4728 4729
	.get_mac_eee		= mv88e6xxx_get_mac_eee,
	.set_mac_eee		= mv88e6xxx_set_mac_eee,
4730
	.get_eeprom_len		= mv88e6xxx_get_eeprom_len,
4731 4732 4733 4734
	.get_eeprom		= mv88e6xxx_get_eeprom,
	.set_eeprom		= mv88e6xxx_set_eeprom,
	.get_regs_len		= mv88e6xxx_get_regs_len,
	.get_regs		= mv88e6xxx_get_regs,
4735
	.set_ageing_time	= mv88e6xxx_set_ageing_time,
4736 4737
	.port_bridge_join	= mv88e6xxx_port_bridge_join,
	.port_bridge_leave	= mv88e6xxx_port_bridge_leave,
4738
	.port_egress_floods	= mv88e6xxx_port_egress_floods,
4739
	.port_stp_state_set	= mv88e6xxx_port_stp_state_set,
4740
	.port_fast_age		= mv88e6xxx_port_fast_age,
4741 4742 4743 4744 4745 4746 4747
	.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,
4748 4749 4750
	.port_mdb_prepare       = mv88e6xxx_port_mdb_prepare,
	.port_mdb_add           = mv88e6xxx_port_mdb_add,
	.port_mdb_del           = mv88e6xxx_port_mdb_del,
4751 4752
	.crosschip_bridge_join	= mv88e6xxx_crosschip_bridge_join,
	.crosschip_bridge_leave	= mv88e6xxx_crosschip_bridge_leave,
4753 4754 4755 4756 4757
	.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,
4758 4759
};

4760 4761 4762 4763
static struct dsa_switch_driver mv88e6xxx_switch_drv = {
	.ops			= &mv88e6xxx_switch_ops,
};

4764
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
4765
{
4766
	struct device *dev = chip->dev;
4767 4768
	struct dsa_switch *ds;

4769
	ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
4770 4771 4772
	if (!ds)
		return -ENOMEM;

4773
	ds->priv = chip;
4774
	ds->dev = dev;
4775
	ds->ops = &mv88e6xxx_switch_ops;
4776 4777
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
4778 4779 4780

	dev_set_drvdata(dev, ds);

4781
	return dsa_register_switch(ds);
4782 4783
}

4784
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
4785
{
4786
	dsa_unregister_switch(chip->ds);
4787 4788
}

4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801
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;
}

4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816
/* 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);

4817
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
4818
{
4819
	struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
4820
	const struct mv88e6xxx_info *compat_info = NULL;
4821
	struct device *dev = &mdiodev->dev;
4822
	struct device_node *np = dev->of_node;
4823
	struct mv88e6xxx_chip *chip;
4824
	int port;
4825
	int err;
4826

4827 4828 4829
	if (!np && !pdata)
		return -EINVAL;

4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848
	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;
		}
	}

4849 4850 4851
	if (!compat_info)
		return -EINVAL;

4852
	chip = mv88e6xxx_alloc_chip(dev);
4853 4854 4855 4856
	if (!chip) {
		err = -ENOMEM;
		goto out;
	}
4857

4858
	chip->info = compat_info;
4859

4860
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
4861
	if (err)
4862
		goto out;
4863

4864
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4865 4866 4867 4868
	if (IS_ERR(chip->reset)) {
		err = PTR_ERR(chip->reset);
		goto out;
	}
4869

4870
	err = mv88e6xxx_detect(chip);
4871
	if (err)
4872
		goto out;
4873

4874 4875
	mv88e6xxx_phy_init(chip);

4876 4877 4878 4879 4880 4881 4882
	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;
	}
4883

4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895
	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_switch_reset(chip);
	mutex_unlock(&chip->reg_lock);
	if (err)
		goto out;

	chip->irq = of_irq_get(np, 0);
	if (chip->irq == -EPROBE_DEFER) {
		err = chip->irq;
		goto out;
	}

4896
	/* Has to be performed before the MDIO bus is created, because
4897
	 * the PHYs will link their interrupts to these interrupt
4898 4899 4900 4901
	 * controllers
	 */
	mutex_lock(&chip->reg_lock);
	if (chip->irq > 0)
4902
		err = mv88e6xxx_g1_irq_setup(chip);
4903 4904 4905
	else
		err = mv88e6xxx_irq_poll_setup(chip);
	mutex_unlock(&chip->reg_lock);
4906

4907 4908
	if (err)
		goto out;
4909

4910 4911
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
4912
		if (err)
4913
			goto out_g1_irq;
4914 4915
	}

4916 4917 4918 4919 4920 4921 4922 4923
	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;

4924
	err = mv88e6xxx_mdios_register(chip, np);
4925
	if (err)
4926
		goto out_g1_vtu_prob_irq;
4927

4928
	err = mv88e6xxx_register_switch(chip);
4929 4930
	if (err)
		goto out_mdio;
4931

4932
	return 0;
4933 4934

out_mdio:
4935
	mv88e6xxx_mdios_unregister(chip);
4936
out_g1_vtu_prob_irq:
4937
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
4938
out_g1_atu_prob_irq:
4939
	mv88e6xxx_g1_atu_prob_irq_free(chip);
4940
out_g2_irq:
4941
	if (chip->info->g2_irqs > 0)
4942 4943
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
4944
	if (chip->irq > 0)
4945
		mv88e6xxx_g1_irq_free(chip);
4946 4947
	else
		mv88e6xxx_irq_poll_free(chip);
4948
out:
4949 4950 4951
	if (pdata)
		dev_put(pdata->netdev);

4952
	return err;
4953
}
4954 4955 4956 4957

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

4960 4961
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
4962
		mv88e6xxx_ptp_free(chip);
4963
	}
4964

4965
	mv88e6xxx_phy_destroy(chip);
4966
	mv88e6xxx_unregister_switch(chip);
4967
	mv88e6xxx_mdios_unregister(chip);
4968

4969 4970 4971 4972 4973 4974 4975
	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)
4976
		mv88e6xxx_g1_irq_free(chip);
4977 4978
	else
		mv88e6xxx_irq_poll_free(chip);
4979 4980 4981
}

static const struct of_device_id mv88e6xxx_of_match[] = {
4982 4983 4984 4985
	{
		.compatible = "marvell,mv88e6085",
		.data = &mv88e6xxx_table[MV88E6085],
	},
4986 4987 4988 4989
	{
		.compatible = "marvell,mv88e6190",
		.data = &mv88e6xxx_table[MV88E6190],
	},
4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000
	{ /* 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,
5001
		.pm = &mv88e6xxx_pm_ops,
5002 5003 5004 5005 5006
	},
};

static int __init mv88e6xxx_init(void)
{
5007
	register_switch_driver(&mv88e6xxx_switch_drv);
5008 5009
	return mdio_driver_register(&mv88e6xxx_driver);
}
5010 5011 5012 5013
module_init(mv88e6xxx_init);

static void __exit mv88e6xxx_cleanup(void)
{
5014
	mdio_driver_unregister(&mv88e6xxx_driver);
5015
	unregister_switch_driver(&mv88e6xxx_switch_drv);
5016 5017
}
module_exit(mv88e6xxx_cleanup);
5018 5019 5020 5021

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