chip.c 140.9 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
static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
{
445 446
	static struct lock_class_key lock_key;
	static struct lock_class_key request_key;
447 448 449 450 451 452
	int err;

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

453 454 455 456 457 458
	/* These lock classes tells lockdep that global 1 irqs are in
	 * a different category than their parent GPIO, so it won't
	 * report false recursion.
	 */
	irq_set_lockdep_class(chip->irq, &lock_key, &request_key);

459
	mutex_unlock(&chip->reg_lock);
460 461
	err = request_threaded_irq(chip->irq, NULL,
				   mv88e6xxx_g1_irq_thread_fn,
462
				   IRQF_ONESHOT | IRQF_SHARED,
463
				   dev_name(chip->dev), chip);
464
	mutex_lock(&chip->reg_lock);
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492
	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);

493
	chip->kworker = kthread_create_worker(0, "%s", dev_name(chip->dev));
494 495 496 497 498 499 500 501 502 503 504 505 506
	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);
507 508 509 510

	mutex_lock(&chip->reg_lock);
	mv88e6xxx_g1_irq_free_common(chip);
	mutex_unlock(&chip->reg_lock);
511 512
}

513
int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask)
514
{
515
	int i;
516

517
	for (i = 0; i < 16; i++) {
518 519 520 521 522 523 524 525 526 527 528 529 530
		u16 val;
		int err;

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

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

		usleep_range(1000, 2000);
	}

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

535
/* Indirect write to single pointer-data register with an Update bit */
536
int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
537 538
{
	u16 val;
539
	int err;
540 541

	/* Wait until the previous operation is completed */
542 543 544
	err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
	if (err)
		return err;
545 546 547 548 549 550 551

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

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

552
static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
553
				    int link, int speed, int duplex, int pause,
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571
				    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;
	}

572 573 574 575 576 577
	if (chip->info->ops->port_set_pause) {
		err = chip->info->ops->port_set_pause(chip, port, pause);
		if (err)
			goto restore_link;
	}

578 579 580 581 582 583 584 585 586 587 588 589
	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;
	}

590 591 592 593 594 595
	if (chip->info->ops->port_set_cmode) {
		err = chip->info->ops->port_set_cmode(chip, port, mode);
		if (err && err != -EOPNOTSUPP)
			goto restore_link;
	}

596 597 598
	err = 0;
restore_link:
	if (chip->info->ops->port_set_link(chip, port, link))
599
		dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
600 601 602 603

	return err;
}

604 605 606 607 608 609 610
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;
}

611 612 613 614
/* 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.
 */
615 616
static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
				  struct phy_device *phydev)
617
{
V
Vivien Didelot 已提交
618
	struct mv88e6xxx_chip *chip = ds->priv;
619
	int err;
620

621 622
	if (!phy_is_pseudo_fixed_link(phydev) &&
	    mv88e6xxx_phy_is_internal(ds, port))
623 624
		return;

625
	mutex_lock(&chip->reg_lock);
626
	err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
627 628
				       phydev->duplex, phydev->pause,
				       phydev->interface);
629
	mutex_unlock(&chip->reg_lock);
630 631

	if (err && err != -EOPNOTSUPP)
632
		dev_err(ds->dev, "p%d: failed to configure MAC\n", port);
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 666 667 668 669 670 671 672 673 674 675
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)
{
676
	if (port >= 9) {
677
		phylink_set(mask, 2500baseX_Full);
678 679
		phylink_set(mask, 2500baseT_Full);
	}
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699

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

700 701 702 703
static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
			       unsigned long *supported,
			       struct phylink_link_state *state)
{
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722
	__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);
723 724 725 726 727 728 729 730 731
}

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);
732 733 734 735
	if (chip->info->ops->port_link_state)
		err = chip->info->ops->port_link_state(chip, port, state);
	else
		err = -EOPNOTSUPP;
736 737 738 739 740 741 742 743 744 745
	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;
746
	int speed, duplex, link, pause, err;
747

748
	if ((mode == MLO_AN_PHY) && mv88e6xxx_phy_is_internal(ds, port))
749 750 751 752 753 754
		return;

	if (mode == MLO_AN_FIXED) {
		link = LINK_FORCED_UP;
		speed = state->speed;
		duplex = state->duplex;
755 756 757 758
	} else if (!mv88e6xxx_phy_is_internal(ds, port)) {
		link = state->link;
		speed = state->speed;
		duplex = state->duplex;
759 760 761 762 763
	} else {
		speed = SPEED_UNFORCED;
		duplex = DUPLEX_UNFORCED;
		link = LINK_UNFORCED;
	}
764
	pause = !!phylink_test(state->advertising, Pause);
765 766

	mutex_lock(&chip->reg_lock);
767
	err = mv88e6xxx_port_setup_mac(chip, port, link, speed, duplex, pause,
768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803
				       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);
}

804
static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
805
{
806 807
	if (!chip->info->ops->stats_snapshot)
		return -EOPNOTSUPP;
808

809
	return chip->info->ops->stats_snapshot(chip, port);
810 811
}

812
static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
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 862 863 864 865 866 867 868 869 870 871
	{ "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, },
872 873
};

874
static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
875
					    struct mv88e6xxx_hw_stat *s,
876 877
					    int port, u16 bank1_select,
					    u16 histogram)
878 879 880
{
	u32 low;
	u32 high = 0;
881
	u16 reg = 0;
882
	int err;
883 884
	u64 value;

885
	switch (s->type) {
886
	case STATS_TYPE_PORT:
887 888
		err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
		if (err)
889
			return U64_MAX;
890

891
		low = reg;
892
		if (s->size == 4) {
893 894
			err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
			if (err)
895
				return U64_MAX;
896
			high = reg;
897
		}
898
		break;
899
	case STATS_TYPE_BANK1:
900
		reg = bank1_select;
901 902
		/* fall through */
	case STATS_TYPE_BANK0:
903
		reg |= s->reg | histogram;
904
		mv88e6xxx_g1_stats_read(chip, reg, &low);
905
		if (s->size == 8)
906
			mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
907 908
		break;
	default:
909
		return U64_MAX;
910 911 912 913 914
	}
	value = (((u64)high) << 16) | low;
	return value;
}

915 916
static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data, int types)
917
{
918 919
	struct mv88e6xxx_hw_stat *stat;
	int i, j;
920

921 922
	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
		stat = &mv88e6xxx_hw_stats[i];
923
		if (stat->type & types) {
924 925 926 927
			memcpy(data + j * ETH_GSTRING_LEN, stat->string,
			       ETH_GSTRING_LEN);
			j++;
		}
928
	}
929 930

	return j;
931 932
}

933 934
static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
935
{
936 937
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_PORT);
938 939
}

940 941
static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
942
{
943 944
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
945 946
}

947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964
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);
}

965
static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
966
				  u32 stringset, uint8_t *data)
967
{
V
Vivien Didelot 已提交
968
	struct mv88e6xxx_chip *chip = ds->priv;
969
	int count = 0;
970

971 972 973
	if (stringset != ETH_SS_STATS)
		return;

974 975
	mutex_lock(&chip->reg_lock);

976
	if (chip->info->ops->stats_get_strings)
977 978 979 980
		count = chip->info->ops->stats_get_strings(chip, data);

	if (chip->info->ops->serdes_get_strings) {
		data += count * ETH_GSTRING_LEN;
981
		count = chip->info->ops->serdes_get_strings(chip, port, data);
982
	}
983

984 985 986
	data += count * ETH_GSTRING_LEN;
	mv88e6xxx_atu_vtu_get_strings(data);

987
	mutex_unlock(&chip->reg_lock);
988 989 990 991 992
}

static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
					  int types)
{
993 994 995 996 997
	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];
998
		if (stat->type & types)
999 1000 1001
			j++;
	}
	return j;
1002 1003
}

1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
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);
}

1016
static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
1017 1018
{
	struct mv88e6xxx_chip *chip = ds->priv;
1019 1020
	int serdes_count = 0;
	int count = 0;
1021

1022 1023 1024
	if (sset != ETH_SS_STATS)
		return 0;

1025
	mutex_lock(&chip->reg_lock);
1026
	if (chip->info->ops->stats_get_sset_count)
1027 1028 1029 1030 1031 1032 1033
		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);
1034
	if (serdes_count < 0) {
1035
		count = serdes_count;
1036 1037 1038 1039 1040
		goto out;
	}
	count += serdes_count;
	count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);

1041
out:
1042
	mutex_unlock(&chip->reg_lock);
1043

1044
	return count;
1045 1046
}

1047 1048 1049
static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data, int types,
				     u16 bank1_select, u16 histogram)
1050 1051 1052 1053 1054 1055 1056
{
	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) {
1057
			mutex_lock(&chip->reg_lock);
1058 1059 1060
			data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
							      bank1_select,
							      histogram);
1061 1062
			mutex_unlock(&chip->reg_lock);

1063 1064 1065
			j++;
		}
	}
1066
	return j;
1067 1068
}

1069 1070
static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
1071 1072
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
1073
					 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
1074
					 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1075 1076
}

1077 1078
static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
1079 1080
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
1081
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1082 1083
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
					 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1084 1085
}

1086 1087
static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
1088 1089 1090
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1091 1092
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
					 0);
1093 1094
}

1095 1096 1097 1098 1099 1100 1101 1102 1103 1104
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;
}

1105 1106 1107
static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
				uint64_t *data)
{
1108 1109
	int count = 0;

1110
	if (chip->info->ops->stats_get_stats)
1111 1112
		count = chip->info->ops->stats_get_stats(chip, port, data);

1113
	mutex_lock(&chip->reg_lock);
1114 1115
	if (chip->info->ops->serdes_get_stats) {
		data += count;
1116
		count = chip->info->ops->serdes_get_stats(chip, port, data);
1117
	}
1118 1119 1120
	data += count;
	mv88e6xxx_atu_vtu_get_stats(chip, port, data);
	mutex_unlock(&chip->reg_lock);
1121 1122
}

1123 1124
static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
					uint64_t *data)
1125
{
V
Vivien Didelot 已提交
1126
	struct mv88e6xxx_chip *chip = ds->priv;
1127 1128
	int ret;

1129
	mutex_lock(&chip->reg_lock);
1130

1131
	ret = mv88e6xxx_stats_snapshot(chip, port);
1132 1133 1134
	mutex_unlock(&chip->reg_lock);

	if (ret < 0)
1135
		return;
1136 1137

	mv88e6xxx_get_stats(chip, port, data);
1138

1139 1140
}

1141
static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
1142 1143 1144 1145
{
	return 32 * sizeof(u16);
}

1146 1147
static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
			       struct ethtool_regs *regs, void *_p)
1148
{
V
Vivien Didelot 已提交
1149
	struct mv88e6xxx_chip *chip = ds->priv;
1150 1151
	int err;
	u16 reg;
1152 1153 1154
	u16 *p = _p;
	int i;

1155
	regs->version = chip->info->prod_num;
1156 1157 1158

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

1159
	mutex_lock(&chip->reg_lock);
1160

1161 1162
	for (i = 0; i < 32; i++) {

1163 1164 1165
		err = mv88e6xxx_port_read(chip, port, i, &reg);
		if (!err)
			p[i] = reg;
1166
	}
1167

1168
	mutex_unlock(&chip->reg_lock);
1169 1170
}

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

V
Vivien Didelot 已提交
1178 1179
static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
1180
{
1181 1182
	/* Nothing to do on the port's MAC */
	return 0;
1183 1184
}

1185
static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
1186
{
1187 1188 1189
	struct dsa_switch *ds = NULL;
	struct net_device *br;
	u16 pvlan;
1190 1191
	int i;

1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211
	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 已提交
1212
		    (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
1213 1214 1215 1216 1217
			pvlan |= BIT(i);

	return pvlan;
}

1218
static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
1219 1220
{
	u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
1221 1222 1223

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

1225
	return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
1226 1227
}

1228 1229
static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
					 u8 state)
1230
{
V
Vivien Didelot 已提交
1231
	struct mv88e6xxx_chip *chip = ds->priv;
1232
	int err;
1233

1234
	mutex_lock(&chip->reg_lock);
1235
	err = mv88e6xxx_port_set_state(chip, port, state);
1236
	mutex_unlock(&chip->reg_lock);
1237 1238

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

1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260
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;
}

1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280
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;
	}

1281 1282 1283 1284 1285 1286 1287
	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;
	}

1288 1289 1290 1291
	err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
	if (err)
		return err;

1292 1293 1294
	return 0;
}

1295 1296 1297 1298 1299 1300 1301 1302 1303
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;
}

1304 1305 1306 1307 1308 1309 1310 1311
static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->rmu_disable)
		return chip->info->ops->rmu_disable(chip);

	return 0;
}

1312 1313 1314 1315 1316 1317 1318 1319
static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->pot_clear)
		return chip->info->ops->pot_clear(chip);

	return 0;
}

1320 1321 1322 1323 1324 1325 1326 1327
static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->mgmt_rsvd2cpu)
		return chip->info->ops->mgmt_rsvd2cpu(chip);

	return 0;
}

1328 1329
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
1330 1331
	int err;

1332 1333 1334 1335
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

1336 1337 1338 1339
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

1340 1341 1342
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362
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;
}

1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375
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;
}

1376 1377 1378 1379 1380 1381 1382 1383 1384
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)
1385
		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1386 1387 1388 1389

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

1390 1391
static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
{
1392 1393 1394
	int dev, port;
	int err;

1395 1396 1397 1398 1399 1400
	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.
	 */
1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413
	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;
1414 1415
}

1416 1417 1418 1419 1420 1421
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);
1422
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1423 1424 1425
	mutex_unlock(&chip->reg_lock);

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

1429 1430 1431 1432 1433 1434 1435 1436
static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
{
	if (!chip->info->max_vid)
		return 0;

	return mv88e6xxx_g1_vtu_flush(chip);
}

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

1446 1447 1448 1449 1450 1451 1452 1453 1454
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);
}

1455
static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1456 1457
{
	DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1458 1459 1460
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = chip->info->max_vid,
	};
1461
	int i, err;
1462 1463 1464

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

1465
	/* Set every FID bit used by the (un)bridged ports */
1466
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1467
		err = mv88e6xxx_port_get_fid(chip, i, fid);
1468 1469 1470 1471 1472 1473
		if (err)
			return err;

		set_bit(*fid, fid_bitmap);
	}

1474 1475
	/* Set every FID bit used by the VLAN entries */
	do {
1476
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1477 1478 1479 1480 1481 1482 1483
		if (err)
			return err;

		if (!vlan.valid)
			break;

		set_bit(vlan.fid, fid_bitmap);
1484
	} while (vlan.vid < chip->info->max_vid);
1485 1486 1487 1488 1489

	/* 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);
1490
	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1491 1492 1493
		return -ENOSPC;

	/* Clear the database */
1494
	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1495 1496
}

1497 1498
static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
			     struct mv88e6xxx_vtu_entry *entry, bool new)
1499 1500 1501 1502 1503 1504
{
	int err;

	if (!vid)
		return -EINVAL;

1505 1506
	entry->vid = vid - 1;
	entry->valid = false;
1507

1508
	err = mv88e6xxx_vtu_getnext(chip, entry);
1509 1510 1511
	if (err)
		return err;

1512 1513
	if (entry->vid == vid && entry->valid)
		return 0;
1514

1515 1516 1517 1518 1519 1520 1521 1522
	if (new) {
		int i;

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

1523
		/* Exclude all ports */
1524
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1525
			entry->member[i] =
1526
				MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1527 1528

		return mv88e6xxx_atu_new(chip, &entry->fid);
1529 1530
	}

1531 1532
	/* switchdev expects -EOPNOTSUPP to honor software VLANs */
	return -EOPNOTSUPP;
1533 1534
}

1535 1536 1537
static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
					u16 vid_begin, u16 vid_end)
{
V
Vivien Didelot 已提交
1538
	struct mv88e6xxx_chip *chip = ds->priv;
1539 1540 1541
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = vid_begin - 1,
	};
1542 1543
	int i, err;

1544 1545 1546 1547
	/* 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;

1548 1549 1550
	if (!vid_begin)
		return -EOPNOTSUPP;

1551
	mutex_lock(&chip->reg_lock);
1552 1553

	do {
1554
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1555 1556 1557 1558 1559 1560 1561 1562 1563
		if (err)
			goto unlock;

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

1564
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1565 1566 1567
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

1568
			if (!ds->ports[i].slave)
1569 1570
				continue;

1571
			if (vlan.member[i] ==
1572
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1573 1574
				continue;

V
Vivien Didelot 已提交
1575
			if (dsa_to_port(ds, i)->bridge_dev ==
1576
			    ds->ports[port].bridge_dev)
1577 1578
				break; /* same bridge, check next VLAN */

V
Vivien Didelot 已提交
1579
			if (!dsa_to_port(ds, i)->bridge_dev)
1580 1581
				continue;

1582 1583
			dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
				port, vlan.vid, i,
V
Vivien Didelot 已提交
1584
				netdev_name(dsa_to_port(ds, i)->bridge_dev));
1585 1586 1587 1588 1589 1590
			err = -EOPNOTSUPP;
			goto unlock;
		}
	} while (vlan.vid < vid_end);

unlock:
1591
	mutex_unlock(&chip->reg_lock);
1592 1593 1594 1595

	return err;
}

1596 1597
static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
					 bool vlan_filtering)
1598
{
V
Vivien Didelot 已提交
1599
	struct mv88e6xxx_chip *chip = ds->priv;
1600 1601
	u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
		MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
1602
	int err;
1603

1604
	if (!chip->info->max_vid)
1605 1606
		return -EOPNOTSUPP;

1607
	mutex_lock(&chip->reg_lock);
1608
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1609
	mutex_unlock(&chip->reg_lock);
1610

1611
	return err;
1612 1613
}

1614 1615
static int
mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1616
			    const struct switchdev_obj_port_vlan *vlan)
1617
{
V
Vivien Didelot 已提交
1618
	struct mv88e6xxx_chip *chip = ds->priv;
1619 1620
	int err;

1621
	if (!chip->info->max_vid)
1622 1623
		return -EOPNOTSUPP;

1624 1625 1626 1627 1628 1629 1630 1631
	/* 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;

1632 1633 1634 1635 1636 1637
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */
	return 0;
}

1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681
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);
}

1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704
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;
}

1705
static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
1706
				    u16 vid, u8 member)
1707
{
1708
	struct mv88e6xxx_vtu_entry vlan;
1709 1710
	int err;

1711
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
1712
	if (err)
1713
		return err;
1714

1715
	vlan.member[port] = member;
1716

1717 1718 1719 1720 1721
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
	if (err)
		return err;

	return mv88e6xxx_broadcast_setup(chip, vid);
1722 1723
}

1724
static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1725
				    const struct switchdev_obj_port_vlan *vlan)
1726
{
V
Vivien Didelot 已提交
1727
	struct mv88e6xxx_chip *chip = ds->priv;
1728 1729
	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1730
	u8 member;
1731 1732
	u16 vid;

1733
	if (!chip->info->max_vid)
1734 1735
		return;

1736
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1737
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1738
	else if (untagged)
1739
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
1740
	else
1741
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
1742

1743
	mutex_lock(&chip->reg_lock);
1744

1745
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
1746
		if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
1747 1748
			dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
				vid, untagged ? 'u' : 't');
1749

1750
	if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1751 1752
		dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
			vlan->vid_end);
1753

1754
	mutex_unlock(&chip->reg_lock);
1755 1756
}

1757
static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
1758
				    int port, u16 vid)
1759
{
1760
	struct mv88e6xxx_vtu_entry vlan;
1761 1762
	int i, err;

1763
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1764
	if (err)
1765
		return err;
1766

1767
	/* Tell switchdev if this VLAN is handled in software */
1768
	if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1769
		return -EOPNOTSUPP;
1770

1771
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1772 1773

	/* keep the VLAN unless all ports are excluded */
1774
	vlan.valid = false;
1775
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1776 1777
		if (vlan.member[i] !=
		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
1778
			vlan.valid = true;
1779 1780 1781 1782
			break;
		}
	}

1783
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1784 1785 1786
	if (err)
		return err;

1787
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
1788 1789
}

1790 1791
static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
				   const struct switchdev_obj_port_vlan *vlan)
1792
{
V
Vivien Didelot 已提交
1793
	struct mv88e6xxx_chip *chip = ds->priv;
1794 1795 1796
	u16 pvid, vid;
	int err = 0;

1797
	if (!chip->info->max_vid)
1798 1799
		return -EOPNOTSUPP;

1800
	mutex_lock(&chip->reg_lock);
1801

1802
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
1803 1804 1805
	if (err)
		goto unlock;

1806
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1807
		err = _mv88e6xxx_port_vlan_del(chip, port, vid);
1808 1809 1810 1811
		if (err)
			goto unlock;

		if (vid == pvid) {
1812
			err = mv88e6xxx_port_set_pvid(chip, port, 0);
1813 1814 1815 1816 1817
			if (err)
				goto unlock;
		}
	}

1818
unlock:
1819
	mutex_unlock(&chip->reg_lock);
1820 1821 1822 1823

	return err;
}

1824 1825
static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
				  const unsigned char *addr, u16 vid)
1826
{
V
Vivien Didelot 已提交
1827
	struct mv88e6xxx_chip *chip = ds->priv;
1828
	int err;
1829

1830
	mutex_lock(&chip->reg_lock);
1831 1832
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1833
	mutex_unlock(&chip->reg_lock);
1834 1835

	return err;
1836 1837
}

1838
static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1839
				  const unsigned char *addr, u16 vid)
1840
{
V
Vivien Didelot 已提交
1841
	struct mv88e6xxx_chip *chip = ds->priv;
1842
	int err;
1843

1844
	mutex_lock(&chip->reg_lock);
1845
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1846
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
1847
	mutex_unlock(&chip->reg_lock);
1848

1849
	return err;
1850 1851
}

1852 1853
static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
				      u16 fid, u16 vid, int port,
1854
				      dsa_fdb_dump_cb_t *cb, void *data)
1855
{
1856
	struct mv88e6xxx_atu_entry addr;
1857
	bool is_static;
1858 1859
	int err;

1860
	addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1861
	eth_broadcast_addr(addr.mac);
1862 1863

	do {
1864
		mutex_lock(&chip->reg_lock);
1865
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
1866
		mutex_unlock(&chip->reg_lock);
1867
		if (err)
1868
			return err;
1869

1870
		if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
1871 1872
			break;

1873
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
1874 1875
			continue;

1876 1877
		if (!is_unicast_ether_addr(addr.mac))
			continue;
1878

1879 1880 1881
		is_static = (addr.state ==
			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
		err = cb(addr.mac, vid, is_static, data);
1882 1883
		if (err)
			return err;
1884 1885 1886 1887 1888
	} while (!is_broadcast_ether_addr(addr.mac));

	return err;
}

1889
static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1890
				  dsa_fdb_dump_cb_t *cb, void *data)
1891
{
1892
	struct mv88e6xxx_vtu_entry vlan = {
1893
		.vid = chip->info->max_vid,
1894
	};
1895
	u16 fid;
1896 1897
	int err;

1898
	/* Dump port's default Filtering Information Database (VLAN ID 0) */
1899
	mutex_lock(&chip->reg_lock);
1900
	err = mv88e6xxx_port_get_fid(chip, port, &fid);
1901 1902
	mutex_unlock(&chip->reg_lock);

1903
	if (err)
1904
		return err;
1905

1906
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
1907
	if (err)
1908
		return err;
1909

1910
	/* Dump VLANs' Filtering Information Databases */
1911
	do {
1912
		mutex_lock(&chip->reg_lock);
1913
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1914
		mutex_unlock(&chip->reg_lock);
1915
		if (err)
1916
			return err;
1917 1918 1919 1920

		if (!vlan.valid)
			break;

1921
		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1922
						 cb, data);
1923
		if (err)
1924
			return err;
1925
	} while (vlan.vid < chip->info->max_vid);
1926

1927 1928 1929 1930
	return err;
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1931
				   dsa_fdb_dump_cb_t *cb, void *data)
1932
{
V
Vivien Didelot 已提交
1933
	struct mv88e6xxx_chip *chip = ds->priv;
1934

1935
	return mv88e6xxx_port_db_dump(chip, port, cb, data);
1936 1937
}

1938 1939
static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
				struct net_device *br)
1940
{
1941
	struct dsa_switch *ds;
1942
	int port;
1943
	int dev;
1944
	int err;
1945

1946 1947 1948 1949
	/* 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);
1950
			if (err)
1951
				return err;
1952 1953 1954
		}
	}

1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972
	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;
			}
		}
	}

1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983
	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);
1984
	mutex_unlock(&chip->reg_lock);
1985

1986
	return err;
1987 1988
}

1989 1990
static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
					struct net_device *br)
1991
{
V
Vivien Didelot 已提交
1992
	struct mv88e6xxx_chip *chip = ds->priv;
1993

1994
	mutex_lock(&chip->reg_lock);
1995 1996 1997
	if (mv88e6xxx_bridge_map(chip, br) ||
	    mv88e6xxx_port_vlan_map(chip, port))
		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
1998
	mutex_unlock(&chip->reg_lock);
1999 2000
}

2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030
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);
}

2031 2032 2033 2034 2035 2036 2037 2038
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->reset)
		return chip->info->ops->reset(chip);

	return 0;
}

2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051
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);
	}
}

2052
static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2053
{
2054
	int i, err;
2055

2056
	/* Set all ports to the Disabled state */
2057
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2058
		err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
2059 2060
		if (err)
			return err;
2061 2062
	}

2063 2064 2065
	/* Wait for transmit queues to drain,
	 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
	 */
2066 2067
	usleep_range(2000, 4000);

2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078
	return 0;
}

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

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

2079
	mv88e6xxx_hardware_reset(chip);
2080

2081
	return mv88e6xxx_software_reset(chip);
2082 2083
}

2084
static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
2085 2086
				   enum mv88e6xxx_frame_mode frame,
				   enum mv88e6xxx_egress_mode egress, u16 etype)
2087 2088 2089
{
	int err;

2090 2091 2092 2093
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
2094 2095 2096
	if (err)
		return err;

2097 2098 2099 2100 2101 2102 2103 2104
	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;
2105 2106
}

2107
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2108
{
2109
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
2110
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2111
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2112
}
2113

2114 2115 2116
static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
2117
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2118
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2119
}
2120

2121 2122 2123 2124
static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port,
				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
2125 2126
				       MV88E6XXX_EGRESS_MODE_ETHERTYPE,
				       ETH_P_EDSA);
2127
}
2128

2129 2130 2131 2132
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);
2133

2134
	if (dsa_is_user_port(chip->ds, port))
2135
		return mv88e6xxx_set_port_mode_normal(chip, port);
2136

2137 2138 2139
	/* 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);
2140

2141 2142
	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
		return mv88e6xxx_set_port_mode_edsa(chip, port);
2143

2144
	return -EINVAL;
2145 2146
}

2147
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2148
{
2149
	bool message = dsa_is_dsa_port(chip->ds, port);
2150

2151
	return mv88e6xxx_port_set_message_port(chip, port, message);
2152
}
2153

2154
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2155
{
2156 2157
	struct dsa_switch *ds = chip->ds;
	bool flood;
2158

2159
	/* Upstream ports flood frames with unknown unicast or multicast DA */
2160
	flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
2161 2162 2163
	if (chip->info->ops->port_set_egress_floods)
		return chip->info->ops->port_set_egress_floods(chip, port,
							       flood, flood);
2164

2165
	return 0;
2166 2167
}

2168 2169 2170
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
2171 2172
	if (chip->info->ops->serdes_power)
		return chip->info->ops->serdes_power(chip, port, on);
2173

2174
	return 0;
2175 2176
}

2177 2178 2179 2180 2181 2182
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

2183
	upstream_port = dsa_upstream_port(ds, port);
2184 2185 2186 2187 2188 2189 2190
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206
	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;
		}
	}

2207 2208 2209
	return 0;
}

2210
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
2211
{
2212
	struct dsa_switch *ds = chip->ds;
2213
	int err;
2214
	u16 reg;
2215

2216 2217 2218
	chip->ports[port].chip = chip;
	chip->ports[port].port = port;

2219 2220 2221 2222 2223 2224 2225
	/* 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,
2226
					       PAUSE_OFF,
2227 2228 2229 2230
					       PHY_INTERFACE_MODE_NA);
	else
		err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
					       SPEED_UNFORCED, DUPLEX_UNFORCED,
2231
					       PAUSE_ON,
2232 2233 2234
					       PHY_INTERFACE_MODE_NA);
	if (err)
		return err;
2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249

	/* 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.
	 */
2250 2251 2252 2253
	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);
2254 2255
	if (err)
		return err;
2256

2257
	err = mv88e6xxx_setup_port_mode(chip, port);
2258 2259
	if (err)
		return err;
2260

2261
	err = mv88e6xxx_setup_egress_floods(chip, port);
2262 2263 2264
	if (err)
		return err;

2265 2266 2267
	/* 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.
2268
	 */
2269 2270 2271 2272 2273
	if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
		err = mv88e6xxx_serdes_power(chip, port, true);
		if (err)
			return err;
	}
2274

2275
	/* Port Control 2: don't force a good FCS, set the maximum frame size to
2276
	 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
2277 2278 2279
	 * 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.
2280
	 */
2281 2282 2283
	err = mv88e6xxx_port_set_map_da(chip, port);
	if (err)
		return err;
2284

2285 2286 2287
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
2288

2289
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
2290
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
2291 2292 2293
	if (err)
		return err;

2294 2295
	if (chip->info->ops->port_set_jumbo_size) {
		err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
2296 2297 2298 2299
		if (err)
			return err;
	}

2300 2301 2302 2303 2304
	/* 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.
	 */
2305
	reg = 1 << port;
2306 2307
	/* Disable learning for CPU port */
	if (dsa_is_cpu_port(ds, port))
2308
		reg = 0;
2309

2310 2311
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
2312 2313
	if (err)
		return err;
2314 2315

	/* Egress rate control 2: disable egress rate control. */
2316 2317
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
				   0x0000);
2318 2319
	if (err)
		return err;
2320

2321 2322
	if (chip->info->ops->port_pause_limit) {
		err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
2323 2324
		if (err)
			return err;
2325
	}
2326

2327 2328 2329 2330 2331 2332
	if (chip->info->ops->port_disable_learn_limit) {
		err = chip->info->ops->port_disable_learn_limit(chip, port);
		if (err)
			return err;
	}

2333 2334
	if (chip->info->ops->port_disable_pri_override) {
		err = chip->info->ops->port_disable_pri_override(chip, port);
2335 2336
		if (err)
			return err;
2337
	}
2338

2339 2340
	if (chip->info->ops->port_tag_remap) {
		err = chip->info->ops->port_tag_remap(chip, port);
2341 2342
		if (err)
			return err;
2343 2344
	}

2345 2346
	if (chip->info->ops->port_egress_rate_limiting) {
		err = chip->info->ops->port_egress_rate_limiting(chip, port);
2347 2348
		if (err)
			return err;
2349 2350
	}

2351
	err = mv88e6xxx_setup_message_port(chip, port);
2352 2353
	if (err)
		return err;
2354

2355
	/* Port based VLAN map: give each port the same default address
2356 2357
	 * database, and allow bidirectional communication between the
	 * CPU and DSA port(s), and the other ports.
2358
	 */
2359
	err = mv88e6xxx_port_set_fid(chip, port, 0);
2360 2361
	if (err)
		return err;
2362

2363
	err = mv88e6xxx_port_vlan_map(chip, port);
2364 2365
	if (err)
		return err;
2366 2367 2368 2369

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

2373 2374 2375 2376
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
2377
	int err;
2378 2379

	mutex_lock(&chip->reg_lock);
2380

2381
	err = mv88e6xxx_serdes_power(chip, port, true);
2382 2383 2384 2385

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

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

	return err;
}

2391
static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port)
2392 2393 2394 2395
{
	struct mv88e6xxx_chip *chip = ds->priv;

	mutex_lock(&chip->reg_lock);
2396 2397 2398 2399

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

2400 2401
	if (mv88e6xxx_serdes_power(chip, port, false))
		dev_err(chip->dev, "failed to power off SERDES\n");
2402

2403 2404 2405
	mutex_unlock(&chip->reg_lock);
}

2406 2407 2408
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
2409
	struct mv88e6xxx_chip *chip = ds->priv;
2410 2411 2412
	int err;

	mutex_lock(&chip->reg_lock);
2413
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2414 2415 2416 2417 2418
	mutex_unlock(&chip->reg_lock);

	return err;
}

2419
static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
2420
{
2421
	int err;
2422

2423
	/* Initialize the statistics unit */
2424 2425 2426 2427 2428
	if (chip->info->ops->stats_set_histogram) {
		err = chip->info->ops->stats_set_histogram(chip);
		if (err)
			return err;
	}
2429

2430
	return mv88e6xxx_g1_stats_clear(chip);
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 2525 2526 2527 2528 2529 2530 2531 2532 2533
/* 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);
}

2534
static int mv88e6xxx_setup(struct dsa_switch *ds)
2535
{
V
Vivien Didelot 已提交
2536
	struct mv88e6xxx_chip *chip = ds->priv;
2537
	u8 cmode;
2538
	int err;
2539 2540
	int i;

2541
	chip->ds = ds;
2542
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
2543

2544
	mutex_lock(&chip->reg_lock);
2545

2546 2547 2548 2549 2550 2551
	if (chip->info->ops->setup_errata) {
		err = chip->info->ops->setup_errata(chip);
		if (err)
			goto unlock;
	}

2552 2553 2554 2555 2556
	/* 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)
2557
				goto unlock;
2558 2559 2560 2561 2562

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

2563
	/* Setup Switch Port Registers */
2564
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2565 2566 2567
		if (dsa_is_unused_port(ds, i))
			continue;

2568 2569 2570 2571 2572
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

2573 2574 2575 2576
	err = mv88e6xxx_irl_setup(chip);
	if (err)
		goto unlock;

2577 2578 2579 2580
	err = mv88e6xxx_mac_setup(chip);
	if (err)
		goto unlock;

2581 2582 2583 2584
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

2585 2586 2587 2588
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

2589 2590 2591 2592
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

2593 2594 2595 2596
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

2597 2598 2599 2600
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

2601 2602 2603 2604
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

2605 2606 2607 2608
	err = mv88e6xxx_rmu_setup(chip);
	if (err)
		goto unlock;

2609 2610 2611
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
2612

2613 2614 2615 2616
	err = mv88e6xxx_trunk_setup(chip);
	if (err)
		goto unlock;

2617 2618 2619 2620
	err = mv88e6xxx_devmap_setup(chip);
	if (err)
		goto unlock;

2621 2622 2623 2624
	err = mv88e6xxx_pri_setup(chip);
	if (err)
		goto unlock;

2625
	/* Setup PTP Hardware Clock and timestamping */
2626 2627 2628 2629
	if (chip->info->ptp_support) {
		err = mv88e6xxx_ptp_setup(chip);
		if (err)
			goto unlock;
2630 2631 2632 2633

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
2634 2635
	}

2636 2637 2638 2639
	err = mv88e6xxx_stats_setup(chip);
	if (err)
		goto unlock;

2640
unlock:
2641
	mutex_unlock(&chip->reg_lock);
2642

2643
	return err;
2644 2645
}

2646
static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
2647
{
2648 2649
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2650 2651
	u16 val;
	int err;
2652

2653 2654 2655
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

2656
	mutex_lock(&chip->reg_lock);
2657
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
2658
	mutex_unlock(&chip->reg_lock);
2659

2660
	if (reg == MII_PHYSID2) {
2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676
		/* 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;
2677 2678
	}

2679
	return err ? err : val;
2680 2681
}

2682
static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
2683
{
2684 2685
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2686
	int err;
2687

2688 2689 2690
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

2691
	mutex_lock(&chip->reg_lock);
2692
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
2693
	mutex_unlock(&chip->reg_lock);
2694 2695

	return err;
2696 2697
}

2698
static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
2699 2700
				   struct device_node *np,
				   bool external)
2701 2702
{
	static int index;
2703
	struct mv88e6xxx_mdio_bus *mdio_bus;
2704 2705 2706
	struct mii_bus *bus;
	int err;

2707 2708 2709 2710 2711 2712 2713 2714 2715
	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;
	}

2716
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
2717 2718 2719
	if (!bus)
		return -ENOMEM;

2720
	mdio_bus = bus->priv;
2721
	mdio_bus->bus = bus;
2722
	mdio_bus->chip = chip;
2723 2724
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
2725

2726 2727
	if (np) {
		bus->name = np->full_name;
2728
		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
2729 2730 2731 2732 2733 2734 2735
	} 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;
2736
	bus->parent = chip->dev;
2737

2738 2739 2740 2741 2742 2743
	if (!external) {
		err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
		if (err)
			return err;
	}

2744
	err = of_mdiobus_register(bus, np);
2745
	if (err) {
2746
		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
2747
		mv88e6xxx_g2_irq_mdio_free(chip, bus);
2748
		return err;
2749
	}
2750 2751 2752 2753 2754

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

	return 0;
2757
}
2758

2759 2760 2761 2762 2763
static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
	{ .compatible = "marvell,mv88e6xxx-mdio-external",
	  .data = (void *)true },
	{ },
};
2764

2765 2766 2767 2768 2769 2770 2771 2772 2773
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;

2774 2775 2776
		if (!mdio_bus->external)
			mv88e6xxx_g2_irq_mdio_free(chip, bus);

2777 2778 2779 2780
		mdiobus_unregister(bus);
	}
}

2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804
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);
2805 2806
			if (err) {
				mv88e6xxx_mdios_unregister(chip);
2807
				return err;
2808
			}
2809 2810 2811 2812
		}
	}

	return 0;
2813 2814
}

2815 2816
static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
2817
	struct mv88e6xxx_chip *chip = ds->priv;
2818 2819 2820 2821 2822 2823 2824

	return chip->eeprom_len;
}

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

2828 2829
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
2830

2831 2832
	mutex_lock(&chip->reg_lock);
	err = chip->info->ops->get_eeprom(chip, eeprom, data);
2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845
	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 已提交
2846
	struct mv88e6xxx_chip *chip = ds->priv;
2847 2848
	int err;

2849 2850 2851
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

2852 2853 2854 2855
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

	mutex_lock(&chip->reg_lock);
2856
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
2857 2858 2859 2860 2861
	mutex_unlock(&chip->reg_lock);

	return err;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

3944 3945
static const struct mv88e6xxx_info mv88e6xxx_table[] = {
	[MV88E6085] = {
3946
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
3947 3948 3949 3950
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6085",
		.num_databases = 4096,
		.num_ports = 10,
3951
		.num_internal_phys = 5,
3952
		.max_vid = 4095,
3953
		.port_base_addr = 0x10,
3954
		.phy_base_addr = 0x0,
3955
		.global1_addr = 0x1b,
3956
		.global2_addr = 0x1c,
3957
		.age_time_coeff = 15000,
3958
		.g1_irqs = 8,
3959
		.g2_irqs = 10,
3960
		.atu_move_port_mask = 0xf,
3961
		.pvt = true,
3962
		.multi_chip = true,
3963
		.tag_protocol = DSA_TAG_PROTO_DSA,
3964
		.ops = &mv88e6085_ops,
3965 3966 3967
	},

	[MV88E6095] = {
3968
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
3969 3970 3971 3972
		.family = MV88E6XXX_FAMILY_6095,
		.name = "Marvell 88E6095/88E6095F",
		.num_databases = 256,
		.num_ports = 11,
3973
		.num_internal_phys = 0,
3974
		.max_vid = 4095,
3975
		.port_base_addr = 0x10,
3976
		.phy_base_addr = 0x0,
3977
		.global1_addr = 0x1b,
3978
		.global2_addr = 0x1c,
3979
		.age_time_coeff = 15000,
3980
		.g1_irqs = 8,
3981
		.atu_move_port_mask = 0xf,
3982
		.multi_chip = true,
3983
		.tag_protocol = DSA_TAG_PROTO_DSA,
3984
		.ops = &mv88e6095_ops,
3985 3986
	},

3987
	[MV88E6097] = {
3988
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
3989 3990 3991 3992
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6097/88E6097F",
		.num_databases = 4096,
		.num_ports = 11,
3993
		.num_internal_phys = 8,
3994
		.max_vid = 4095,
3995
		.port_base_addr = 0x10,
3996
		.phy_base_addr = 0x0,
3997
		.global1_addr = 0x1b,
3998
		.global2_addr = 0x1c,
3999
		.age_time_coeff = 15000,
4000
		.g1_irqs = 8,
4001
		.g2_irqs = 10,
4002
		.atu_move_port_mask = 0xf,
4003
		.pvt = true,
4004
		.multi_chip = true,
4005
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4006 4007 4008
		.ops = &mv88e6097_ops,
	},

4009
	[MV88E6123] = {
4010
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
4011 4012 4013 4014
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6123",
		.num_databases = 4096,
		.num_ports = 3,
4015
		.num_internal_phys = 5,
4016
		.max_vid = 4095,
4017
		.port_base_addr = 0x10,
4018
		.phy_base_addr = 0x0,
4019
		.global1_addr = 0x1b,
4020
		.global2_addr = 0x1c,
4021
		.age_time_coeff = 15000,
4022
		.g1_irqs = 9,
4023
		.g2_irqs = 10,
4024
		.atu_move_port_mask = 0xf,
4025
		.pvt = true,
4026
		.multi_chip = true,
4027
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4028
		.ops = &mv88e6123_ops,
4029 4030 4031
	},

	[MV88E6131] = {
4032
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
4033 4034 4035 4036
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6131",
		.num_databases = 256,
		.num_ports = 8,
4037
		.num_internal_phys = 0,
4038
		.max_vid = 4095,
4039
		.port_base_addr = 0x10,
4040
		.phy_base_addr = 0x0,
4041
		.global1_addr = 0x1b,
4042
		.global2_addr = 0x1c,
4043
		.age_time_coeff = 15000,
4044
		.g1_irqs = 9,
4045
		.atu_move_port_mask = 0xf,
4046
		.multi_chip = true,
4047
		.tag_protocol = DSA_TAG_PROTO_DSA,
4048
		.ops = &mv88e6131_ops,
4049 4050
	},

4051
	[MV88E6141] = {
4052
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
4053
		.family = MV88E6XXX_FAMILY_6341,
4054
		.name = "Marvell 88E6141",
4055 4056
		.num_databases = 4096,
		.num_ports = 6,
4057
		.num_internal_phys = 5,
4058
		.num_gpio = 11,
4059
		.max_vid = 4095,
4060
		.port_base_addr = 0x10,
4061
		.phy_base_addr = 0x10,
4062
		.global1_addr = 0x1b,
4063
		.global2_addr = 0x1c,
4064 4065
		.age_time_coeff = 3750,
		.atu_move_port_mask = 0x1f,
4066
		.g1_irqs = 9,
4067
		.g2_irqs = 10,
4068
		.pvt = true,
4069
		.multi_chip = true,
4070 4071 4072 4073
		.tag_protocol = DSA_TAG_PROTO_EDSA,
		.ops = &mv88e6141_ops,
	},

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

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

	[MV88E6171] = {
4121
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
4122 4123 4124 4125
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6171",
		.num_databases = 4096,
		.num_ports = 7,
4126
		.num_internal_phys = 5,
4127
		.max_vid = 4095,
4128
		.port_base_addr = 0x10,
4129
		.phy_base_addr = 0x0,
4130
		.global1_addr = 0x1b,
4131
		.global2_addr = 0x1c,
4132
		.age_time_coeff = 15000,
4133
		.g1_irqs = 9,
4134
		.g2_irqs = 10,
4135
		.atu_move_port_mask = 0xf,
4136
		.pvt = true,
4137
		.multi_chip = true,
4138
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4139
		.ops = &mv88e6171_ops,
4140 4141 4142
	},

	[MV88E6172] = {
4143
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
4144 4145 4146 4147
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6172",
		.num_databases = 4096,
		.num_ports = 7,
4148
		.num_internal_phys = 5,
4149
		.num_gpio = 15,
4150
		.max_vid = 4095,
4151
		.port_base_addr = 0x10,
4152
		.phy_base_addr = 0x0,
4153
		.global1_addr = 0x1b,
4154
		.global2_addr = 0x1c,
4155
		.age_time_coeff = 15000,
4156
		.g1_irqs = 9,
4157
		.g2_irqs = 10,
4158
		.atu_move_port_mask = 0xf,
4159
		.pvt = true,
4160
		.multi_chip = true,
4161
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4162
		.ops = &mv88e6172_ops,
4163 4164 4165
	},

	[MV88E6175] = {
4166
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
4167 4168 4169 4170
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6175",
		.num_databases = 4096,
		.num_ports = 7,
4171
		.num_internal_phys = 5,
4172
		.max_vid = 4095,
4173
		.port_base_addr = 0x10,
4174
		.phy_base_addr = 0x0,
4175
		.global1_addr = 0x1b,
4176
		.global2_addr = 0x1c,
4177
		.age_time_coeff = 15000,
4178
		.g1_irqs = 9,
4179
		.g2_irqs = 10,
4180
		.atu_move_port_mask = 0xf,
4181
		.pvt = true,
4182
		.multi_chip = true,
4183
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4184
		.ops = &mv88e6175_ops,
4185 4186 4187
	},

	[MV88E6176] = {
4188
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
4189 4190 4191 4192
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6176",
		.num_databases = 4096,
		.num_ports = 7,
4193
		.num_internal_phys = 5,
4194
		.num_gpio = 15,
4195
		.max_vid = 4095,
4196
		.port_base_addr = 0x10,
4197
		.phy_base_addr = 0x0,
4198
		.global1_addr = 0x1b,
4199
		.global2_addr = 0x1c,
4200
		.age_time_coeff = 15000,
4201
		.g1_irqs = 9,
4202
		.g2_irqs = 10,
4203
		.atu_move_port_mask = 0xf,
4204
		.pvt = true,
4205
		.multi_chip = true,
4206
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4207
		.ops = &mv88e6176_ops,
4208 4209 4210
	},

	[MV88E6185] = {
4211
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
4212 4213 4214 4215
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6185",
		.num_databases = 256,
		.num_ports = 10,
4216
		.num_internal_phys = 0,
4217
		.max_vid = 4095,
4218
		.port_base_addr = 0x10,
4219
		.phy_base_addr = 0x0,
4220
		.global1_addr = 0x1b,
4221
		.global2_addr = 0x1c,
4222
		.age_time_coeff = 15000,
4223
		.g1_irqs = 8,
4224
		.atu_move_port_mask = 0xf,
4225
		.multi_chip = true,
4226
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4227
		.ops = &mv88e6185_ops,
4228 4229
	},

4230
	[MV88E6190] = {
4231
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
4232 4233 4234 4235
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4236
		.num_internal_phys = 11,
4237
		.num_gpio = 16,
4238
		.max_vid = 8191,
4239
		.port_base_addr = 0x0,
4240
		.phy_base_addr = 0x0,
4241
		.global1_addr = 0x1b,
4242
		.global2_addr = 0x1c,
4243
		.tag_protocol = DSA_TAG_PROTO_DSA,
4244
		.age_time_coeff = 3750,
4245
		.g1_irqs = 9,
4246
		.g2_irqs = 14,
4247
		.pvt = true,
4248
		.multi_chip = true,
4249
		.atu_move_port_mask = 0x1f,
4250 4251 4252 4253
		.ops = &mv88e6190_ops,
	},

	[MV88E6190X] = {
4254
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
4255 4256 4257 4258
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4259
		.num_internal_phys = 11,
4260
		.num_gpio = 16,
4261
		.max_vid = 8191,
4262
		.port_base_addr = 0x0,
4263
		.phy_base_addr = 0x0,
4264
		.global1_addr = 0x1b,
4265
		.global2_addr = 0x1c,
4266
		.age_time_coeff = 3750,
4267
		.g1_irqs = 9,
4268
		.g2_irqs = 14,
4269
		.atu_move_port_mask = 0x1f,
4270
		.pvt = true,
4271
		.multi_chip = true,
4272
		.tag_protocol = DSA_TAG_PROTO_DSA,
4273 4274 4275 4276
		.ops = &mv88e6190x_ops,
	},

	[MV88E6191] = {
4277
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
4278 4279 4280 4281
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6191",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4282
		.num_internal_phys = 11,
4283
		.max_vid = 8191,
4284
		.port_base_addr = 0x0,
4285
		.phy_base_addr = 0x0,
4286
		.global1_addr = 0x1b,
4287
		.global2_addr = 0x1c,
4288
		.age_time_coeff = 3750,
4289
		.g1_irqs = 9,
4290
		.g2_irqs = 14,
4291
		.atu_move_port_mask = 0x1f,
4292
		.pvt = true,
4293
		.multi_chip = true,
4294
		.tag_protocol = DSA_TAG_PROTO_DSA,
4295
		.ptp_support = true,
4296
		.ops = &mv88e6191_ops,
4297 4298
	},

4299
	[MV88E6240] = {
4300
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
4301 4302 4303 4304
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6240",
		.num_databases = 4096,
		.num_ports = 7,
4305
		.num_internal_phys = 5,
4306
		.num_gpio = 15,
4307
		.max_vid = 4095,
4308
		.port_base_addr = 0x10,
4309
		.phy_base_addr = 0x0,
4310
		.global1_addr = 0x1b,
4311
		.global2_addr = 0x1c,
4312
		.age_time_coeff = 15000,
4313
		.g1_irqs = 9,
4314
		.g2_irqs = 10,
4315
		.atu_move_port_mask = 0xf,
4316
		.pvt = true,
4317
		.multi_chip = true,
4318
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4319
		.ptp_support = true,
4320
		.ops = &mv88e6240_ops,
4321 4322
	},

4323
	[MV88E6290] = {
4324
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
4325 4326 4327 4328
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6290",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4329
		.num_internal_phys = 11,
4330
		.num_gpio = 16,
4331
		.max_vid = 8191,
4332
		.port_base_addr = 0x0,
4333
		.phy_base_addr = 0x0,
4334
		.global1_addr = 0x1b,
4335
		.global2_addr = 0x1c,
4336
		.age_time_coeff = 3750,
4337
		.g1_irqs = 9,
4338
		.g2_irqs = 14,
4339
		.atu_move_port_mask = 0x1f,
4340
		.pvt = true,
4341
		.multi_chip = true,
4342
		.tag_protocol = DSA_TAG_PROTO_DSA,
4343
		.ptp_support = true,
4344 4345 4346
		.ops = &mv88e6290_ops,
	},

4347
	[MV88E6320] = {
4348
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
4349 4350 4351 4352
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6320",
		.num_databases = 4096,
		.num_ports = 7,
4353
		.num_internal_phys = 5,
4354
		.num_gpio = 15,
4355
		.max_vid = 4095,
4356
		.port_base_addr = 0x10,
4357
		.phy_base_addr = 0x0,
4358
		.global1_addr = 0x1b,
4359
		.global2_addr = 0x1c,
4360
		.age_time_coeff = 15000,
4361
		.g1_irqs = 8,
4362
		.g2_irqs = 10,
4363
		.atu_move_port_mask = 0xf,
4364
		.pvt = true,
4365
		.multi_chip = true,
4366
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4367
		.ptp_support = true,
4368
		.ops = &mv88e6320_ops,
4369 4370 4371
	},

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

4394
	[MV88E6341] = {
4395
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
4396 4397 4398
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
4399
		.num_internal_phys = 5,
4400
		.num_ports = 6,
4401
		.num_gpio = 11,
4402
		.max_vid = 4095,
4403
		.port_base_addr = 0x10,
4404
		.phy_base_addr = 0x10,
4405
		.global1_addr = 0x1b,
4406
		.global2_addr = 0x1c,
4407
		.age_time_coeff = 3750,
4408
		.atu_move_port_mask = 0x1f,
4409
		.g1_irqs = 9,
4410
		.g2_irqs = 10,
4411
		.pvt = true,
4412
		.multi_chip = true,
4413
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4414
		.ptp_support = true,
4415 4416 4417
		.ops = &mv88e6341_ops,
	},

4418
	[MV88E6350] = {
4419
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
4420 4421 4422 4423
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6350",
		.num_databases = 4096,
		.num_ports = 7,
4424
		.num_internal_phys = 5,
4425
		.max_vid = 4095,
4426
		.port_base_addr = 0x10,
4427
		.phy_base_addr = 0x0,
4428
		.global1_addr = 0x1b,
4429
		.global2_addr = 0x1c,
4430
		.age_time_coeff = 15000,
4431
		.g1_irqs = 9,
4432
		.g2_irqs = 10,
4433
		.atu_move_port_mask = 0xf,
4434
		.pvt = true,
4435
		.multi_chip = true,
4436
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4437
		.ops = &mv88e6350_ops,
4438 4439 4440
	},

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

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

4533
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
4534
{
4535
	int i;
4536

4537 4538 4539
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
4540 4541 4542 4543

	return NULL;
}

4544
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
4545 4546
{
	const struct mv88e6xxx_info *info;
4547 4548 4549
	unsigned int prod_num, rev;
	u16 id;
	int err;
4550

4551
	mutex_lock(&chip->reg_lock);
4552
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
4553 4554 4555
	mutex_unlock(&chip->reg_lock);
	if (err)
		return err;
4556

4557 4558
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
4559 4560 4561 4562 4563

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

4564
	/* Update the compatible info with the probed one */
4565
	chip->info = info;
4566

4567 4568 4569 4570
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

4571 4572
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
4573 4574 4575 4576

	return 0;
}

4577
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
4578
{
4579
	struct mv88e6xxx_chip *chip;
4580

4581 4582
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
4583 4584
		return NULL;

4585
	chip->dev = dev;
4586

4587
	mutex_init(&chip->reg_lock);
4588
	INIT_LIST_HEAD(&chip->mdios);
4589

4590
	return chip;
4591 4592
}

4593
static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
4594 4595
			      struct mii_bus *bus, int sw_addr)
{
4596
	if (sw_addr == 0)
4597
		chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
4598
	else if (chip->info->multi_chip)
4599
		chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
4600 4601 4602
	else
		return -EINVAL;

4603 4604
	chip->bus = bus;
	chip->sw_addr = sw_addr;
4605 4606 4607 4608

	return 0;
}

4609 4610
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
							int port)
4611
{
V
Vivien Didelot 已提交
4612
	struct mv88e6xxx_chip *chip = ds->priv;
4613

4614
	return chip->info->tag_protocol;
4615 4616
}

4617
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
4618 4619 4620
static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
				       struct device *host_dev, int sw_addr,
				       void **priv)
4621
{
4622
	struct mv88e6xxx_chip *chip;
4623
	struct mii_bus *bus;
4624
	int err;
4625

4626
	bus = dsa_host_dev_to_mii_bus(host_dev);
4627 4628 4629
	if (!bus)
		return NULL;

4630 4631
	chip = mv88e6xxx_alloc_chip(dsa_dev);
	if (!chip)
4632 4633
		return NULL;

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

4637
	err = mv88e6xxx_smi_init(chip, bus, sw_addr);
4638 4639 4640
	if (err)
		goto free;

4641
	err = mv88e6xxx_detect(chip);
4642
	if (err)
4643
		goto free;
4644

4645 4646 4647 4648 4649 4650
	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_switch_reset(chip);
	mutex_unlock(&chip->reg_lock);
	if (err)
		goto free;

4651 4652
	mv88e6xxx_phy_init(chip);

4653
	err = mv88e6xxx_mdios_register(chip, NULL);
4654
	if (err)
4655
		goto free;
4656

4657
	*priv = chip;
4658

4659
	return chip->info->name;
4660
free:
4661
	devm_kfree(dsa_dev, chip);
4662 4663

	return NULL;
4664
}
4665
#endif
4666

4667
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4668
				      const struct switchdev_obj_port_mdb *mdb)
4669 4670 4671 4672 4673 4674 4675 4676 4677
{
	/* 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,
4678
				   const struct switchdev_obj_port_mdb *mdb)
4679
{
V
Vivien Didelot 已提交
4680
	struct mv88e6xxx_chip *chip = ds->priv;
4681 4682 4683

	mutex_lock(&chip->reg_lock);
	if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4684
					 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
4685 4686
		dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
			port);
4687 4688 4689 4690 4691 4692
	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 已提交
4693
	struct mv88e6xxx_chip *chip = ds->priv;
4694 4695 4696 4697
	int err;

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4698
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
4699 4700 4701 4702 4703
	mutex_unlock(&chip->reg_lock);

	return err;
}

4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719
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;
}

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

4769 4770 4771 4772
static struct dsa_switch_driver mv88e6xxx_switch_drv = {
	.ops			= &mv88e6xxx_switch_ops,
};

4773
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
4774
{
4775
	struct device *dev = chip->dev;
4776 4777
	struct dsa_switch *ds;

4778
	ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
4779 4780 4781
	if (!ds)
		return -ENOMEM;

4782
	ds->priv = chip;
4783
	ds->dev = dev;
4784
	ds->ops = &mv88e6xxx_switch_ops;
4785 4786
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
4787 4788 4789

	dev_set_drvdata(dev, ds);

4790
	return dsa_register_switch(ds);
4791 4792
}

4793
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
4794
{
4795
	dsa_unregister_switch(chip->ds);
4796 4797
}

4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810
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;
}

4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825
/* 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);

4826
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
4827
{
4828
	struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
4829
	const struct mv88e6xxx_info *compat_info = NULL;
4830
	struct device *dev = &mdiodev->dev;
4831
	struct device_node *np = dev->of_node;
4832
	struct mv88e6xxx_chip *chip;
4833
	int port;
4834
	int err;
4835

4836 4837 4838
	if (!np && !pdata)
		return -EINVAL;

4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857
	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;
		}
	}

4858 4859 4860
	if (!compat_info)
		return -EINVAL;

4861
	chip = mv88e6xxx_alloc_chip(dev);
4862 4863 4864 4865
	if (!chip) {
		err = -ENOMEM;
		goto out;
	}
4866

4867
	chip->info = compat_info;
4868

4869
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
4870
	if (err)
4871
		goto out;
4872

4873
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4874 4875 4876 4877
	if (IS_ERR(chip->reset)) {
		err = PTR_ERR(chip->reset);
		goto out;
	}
4878

4879
	err = mv88e6xxx_detect(chip);
4880
	if (err)
4881
		goto out;
4882

4883 4884
	mv88e6xxx_phy_init(chip);

4885 4886 4887 4888 4889 4890 4891
	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;
	}
4892

4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904
	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;
	}

4905
	/* Has to be performed before the MDIO bus is created, because
4906
	 * the PHYs will link their interrupts to these interrupt
4907 4908 4909 4910
	 * controllers
	 */
	mutex_lock(&chip->reg_lock);
	if (chip->irq > 0)
4911
		err = mv88e6xxx_g1_irq_setup(chip);
4912 4913 4914
	else
		err = mv88e6xxx_irq_poll_setup(chip);
	mutex_unlock(&chip->reg_lock);
4915

4916 4917
	if (err)
		goto out;
4918

4919 4920
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
4921
		if (err)
4922
			goto out_g1_irq;
4923 4924
	}

4925 4926 4927 4928 4929 4930 4931 4932
	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;

4933
	err = mv88e6xxx_mdios_register(chip, np);
4934
	if (err)
4935
		goto out_g1_vtu_prob_irq;
4936

4937
	err = mv88e6xxx_register_switch(chip);
4938 4939
	if (err)
		goto out_mdio;
4940

4941
	return 0;
4942 4943

out_mdio:
4944
	mv88e6xxx_mdios_unregister(chip);
4945
out_g1_vtu_prob_irq:
4946
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
4947
out_g1_atu_prob_irq:
4948
	mv88e6xxx_g1_atu_prob_irq_free(chip);
4949
out_g2_irq:
4950
	if (chip->info->g2_irqs > 0)
4951 4952
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
4953
	if (chip->irq > 0)
4954
		mv88e6xxx_g1_irq_free(chip);
4955 4956
	else
		mv88e6xxx_irq_poll_free(chip);
4957
out:
4958 4959 4960
	if (pdata)
		dev_put(pdata->netdev);

4961
	return err;
4962
}
4963 4964 4965 4966

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

4969 4970
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
4971
		mv88e6xxx_ptp_free(chip);
4972
	}
4973

4974
	mv88e6xxx_phy_destroy(chip);
4975
	mv88e6xxx_unregister_switch(chip);
4976
	mv88e6xxx_mdios_unregister(chip);
4977

4978 4979 4980 4981 4982 4983 4984
	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)
4985
		mv88e6xxx_g1_irq_free(chip);
4986 4987
	else
		mv88e6xxx_irq_poll_free(chip);
4988 4989 4990
}

static const struct of_device_id mv88e6xxx_of_match[] = {
4991 4992 4993 4994
	{
		.compatible = "marvell,mv88e6085",
		.data = &mv88e6xxx_table[MV88E6085],
	},
4995 4996 4997 4998
	{
		.compatible = "marvell,mv88e6190",
		.data = &mv88e6xxx_table[MV88E6190],
	},
4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009
	{ /* 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,
5010
		.pm = &mv88e6xxx_pm_ops,
5011 5012 5013 5014 5015
	},
};

static int __init mv88e6xxx_init(void)
{
5016
	register_switch_driver(&mv88e6xxx_switch_drv);
5017 5018
	return mdio_driver_register(&mv88e6xxx_driver);
}
5019 5020 5021 5022
module_init(mv88e6xxx_init);

static void __exit mv88e6xxx_cleanup(void)
{
5023
	mdio_driver_unregister(&mv88e6xxx_driver);
5024
	unregister_switch_driver(&mv88e6xxx_switch_drv);
5025 5026
}
module_exit(mv88e6xxx_cleanup);
5027 5028 5029 5030

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