chip.c 135.3 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 264 265 266
{
	unsigned int nhandled = 0;
	unsigned int sub_irq;
	unsigned int n;
	u16 reg;
	int err;

	mutex_lock(&chip->reg_lock);
267
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
	mutex_unlock(&chip->reg_lock);

	if (err)
		goto out;

	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;
		}
	}
out:
	return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
}

284 285 286 287 288 289 290
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);
}

291 292 293 294 295 296 297 298 299 300 301 302 303 304
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;

305
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &reg);
306 307 308 309 310 311
	if (err)
		goto out;

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

312
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, reg);
313 314 315 316 317 318 319
	if (err)
		goto out;

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

320
static const struct irq_chip mv88e6xxx_g1_irq_chip = {
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
	.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,
};

346
/* To be called with reg_lock held */
347
static void mv88e6xxx_g1_irq_free_common(struct mv88e6xxx_chip *chip)
348 349
{
	int irq, virq;
350 351
	u16 mask;

352
	mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
353
	mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
354
	mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
355

356
	for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
357
		virq = irq_find_mapping(chip->g1_irq.domain, irq);
358 359 360
		irq_dispose_mapping(virq);
	}

361
	irq_domain_remove(chip->g1_irq.domain);
362 363
}

364 365
static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
{
366 367 368 369
	/*
	 * free_irq must be called without reg_lock taken because the irq
	 * handler takes this lock, too.
	 */
370
	free_irq(chip->irq, chip);
371 372 373 374

	mutex_lock(&chip->reg_lock);
	mv88e6xxx_g1_irq_free_common(chip);
	mutex_unlock(&chip->reg_lock);
375 376 377
}

static int mv88e6xxx_g1_irq_setup_common(struct mv88e6xxx_chip *chip)
378
{
379 380
	int err, irq, virq;
	u16 reg, mask;
381 382 383 384 385 386 387 388 389 390 391 392 393 394

	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;

395
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
396
	if (err)
397
		goto out_mapping;
398

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

401
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
402
	if (err)
403
		goto out_disable;
404 405

	/* Reading the interrupt status clears (most of) them */
406
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
407
	if (err)
408
		goto out_disable;
409 410 411

	return 0;

412
out_disable:
413
	mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
414
	mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
415 416 417 418 419 420 421 422

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);
423 424 425 426

	return err;
}

427 428 429 430 431 432 433 434 435 436
static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
{
	int err;

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

	err = request_threaded_irq(chip->irq, NULL,
				   mv88e6xxx_g1_irq_thread_fn,
437
				   IRQF_ONESHOT,
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
				   dev_name(chip->dev), chip);
	if (err)
		mv88e6xxx_g1_irq_free_common(chip);

	return err;
}

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

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

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

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

	kthread_init_delayed_work(&chip->irq_poll_work,
				  mv88e6xxx_irq_poll);

	chip->kworker = kthread_create_worker(0, dev_name(chip->dev));
	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);
481 482 483 484

	mutex_lock(&chip->reg_lock);
	mv88e6xxx_g1_irq_free_common(chip);
	mutex_unlock(&chip->reg_lock);
485 486
}

487
int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask)
488
{
489
	int i;
490

491
	for (i = 0; i < 16; i++) {
492 493 494 495 496 497 498 499 500 501 502 503 504
		u16 val;
		int err;

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

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

		usleep_range(1000, 2000);
	}

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

509
/* Indirect write to single pointer-data register with an Update bit */
510
int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
511 512
{
	u16 val;
513
	int err;
514 515

	/* Wait until the previous operation is completed */
516 517 518
	err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
	if (err)
		return err;
519 520 521 522 523 524 525

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

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

526
static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
527
				    int link, int speed, int duplex, int pause,
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
				    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;
	}

546 547 548 549 550 551
	if (chip->info->ops->port_set_pause) {
		err = chip->info->ops->port_set_pause(chip, port, pause);
		if (err)
			goto restore_link;
	}

552 553 554 555 556 557 558 559 560 561 562 563
	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;
	}

564 565 566 567 568 569
	if (chip->info->ops->port_set_cmode) {
		err = chip->info->ops->port_set_cmode(chip, port, mode);
		if (err && err != -EOPNOTSUPP)
			goto restore_link;
	}

570 571 572
	err = 0;
restore_link:
	if (chip->info->ops->port_set_link(chip, port, link))
573
		dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
574 575 576 577

	return err;
}

578 579 580 581
/* 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.
 */
582 583
static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
				  struct phy_device *phydev)
584
{
V
Vivien Didelot 已提交
585
	struct mv88e6xxx_chip *chip = ds->priv;
586
	int err;
587 588 589 590

	if (!phy_is_pseudo_fixed_link(phydev))
		return;

591
	mutex_lock(&chip->reg_lock);
592
	err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
593 594
				       phydev->duplex, phydev->pause,
				       phydev->interface);
595
	mutex_unlock(&chip->reg_lock);
596 597

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

601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663
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)
{
	if (port >= 9)
		phylink_set(mask, 2500baseX_Full);

	/* No ethtool bits for 200Mbps */
	phylink_set(mask, 1000baseT_Full);
	phylink_set(mask, 1000baseX_Full);

	mv88e6065_phylink_validate(chip, port, mask, state);
}

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

664 665 666 667
static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
			       unsigned long *supported,
			       struct phylink_link_state *state)
{
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686
	__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);
687 688 689 690 691 692 693 694 695
}

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);
696 697 698 699
	if (chip->info->ops->port_link_state)
		err = chip->info->ops->port_link_state(chip, port, state);
	else
		err = -EOPNOTSUPP;
700 701 702 703 704 705 706 707 708 709
	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;
710
	int speed, duplex, link, pause, err;
711 712 713 714 715 716 717 718 719 720 721 722 723

	if (mode == MLO_AN_PHY)
		return;

	if (mode == MLO_AN_FIXED) {
		link = LINK_FORCED_UP;
		speed = state->speed;
		duplex = state->duplex;
	} else {
		speed = SPEED_UNFORCED;
		duplex = DUPLEX_UNFORCED;
		link = LINK_UNFORCED;
	}
724
	pause = !!phylink_test(state->advertising, Pause);
725 726

	mutex_lock(&chip->reg_lock);
727
	err = mv88e6xxx_port_setup_mac(chip, port, link, speed, duplex, pause,
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763
				       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);
}

764
static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
765
{
766 767
	if (!chip->info->ops->stats_snapshot)
		return -EOPNOTSUPP;
768

769
	return chip->info->ops->stats_snapshot(chip, port);
770 771
}

772
static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
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 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831
	{ "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, },
832 833
};

834
static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
835
					    struct mv88e6xxx_hw_stat *s,
836 837
					    int port, u16 bank1_select,
					    u16 histogram)
838 839 840
{
	u32 low;
	u32 high = 0;
841
	u16 reg = 0;
842
	int err;
843 844
	u64 value;

845
	switch (s->type) {
846
	case STATS_TYPE_PORT:
847 848
		err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
		if (err)
849
			return U64_MAX;
850

851
		low = reg;
852
		if (s->size == 4) {
853 854
			err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
			if (err)
855
				return U64_MAX;
856
			high = reg;
857
		}
858
		break;
859
	case STATS_TYPE_BANK1:
860
		reg = bank1_select;
861 862
		/* fall through */
	case STATS_TYPE_BANK0:
863
		reg |= s->reg | histogram;
864
		mv88e6xxx_g1_stats_read(chip, reg, &low);
865
		if (s->size == 8)
866
			mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
867 868
		break;
	default:
869
		return U64_MAX;
870 871 872 873 874
	}
	value = (((u64)high) << 16) | low;
	return value;
}

875 876
static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data, int types)
877
{
878 879
	struct mv88e6xxx_hw_stat *stat;
	int i, j;
880

881 882
	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
		stat = &mv88e6xxx_hw_stats[i];
883
		if (stat->type & types) {
884 885 886 887
			memcpy(data + j * ETH_GSTRING_LEN, stat->string,
			       ETH_GSTRING_LEN);
			j++;
		}
888
	}
889 890

	return j;
891 892
}

893 894
static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
895
{
896 897
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_PORT);
898 899
}

900 901
static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
902
{
903 904
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
905 906
}

907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924
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);
}

925
static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
926
				  u32 stringset, uint8_t *data)
927
{
V
Vivien Didelot 已提交
928
	struct mv88e6xxx_chip *chip = ds->priv;
929
	int count = 0;
930

931 932 933
	if (stringset != ETH_SS_STATS)
		return;

934 935
	mutex_lock(&chip->reg_lock);

936
	if (chip->info->ops->stats_get_strings)
937 938 939 940
		count = chip->info->ops->stats_get_strings(chip, data);

	if (chip->info->ops->serdes_get_strings) {
		data += count * ETH_GSTRING_LEN;
941
		count = chip->info->ops->serdes_get_strings(chip, port, data);
942
	}
943

944 945 946
	data += count * ETH_GSTRING_LEN;
	mv88e6xxx_atu_vtu_get_strings(data);

947
	mutex_unlock(&chip->reg_lock);
948 949 950 951 952
}

static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
					  int types)
{
953 954 955 956 957
	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];
958
		if (stat->type & types)
959 960 961
			j++;
	}
	return j;
962 963
}

964 965 966 967 968 969 970 971 972 973 974 975
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);
}

976
static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
977 978
{
	struct mv88e6xxx_chip *chip = ds->priv;
979 980
	int serdes_count = 0;
	int count = 0;
981

982 983 984
	if (sset != ETH_SS_STATS)
		return 0;

985
	mutex_lock(&chip->reg_lock);
986
	if (chip->info->ops->stats_get_sset_count)
987 988 989 990 991 992 993
		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);
994
	if (serdes_count < 0) {
995
		count = serdes_count;
996 997 998 999 1000
		goto out;
	}
	count += serdes_count;
	count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);

1001
out:
1002
	mutex_unlock(&chip->reg_lock);
1003

1004
	return count;
1005 1006
}

1007 1008 1009
static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data, int types,
				     u16 bank1_select, u16 histogram)
1010 1011 1012 1013 1014 1015 1016
{
	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) {
1017
			mutex_lock(&chip->reg_lock);
1018 1019 1020
			data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
							      bank1_select,
							      histogram);
1021 1022
			mutex_unlock(&chip->reg_lock);

1023 1024 1025
			j++;
		}
	}
1026
	return j;
1027 1028
}

1029 1030
static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
1031 1032
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
1033
					 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
1034
					 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1035 1036
}

1037 1038
static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
1039 1040
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
1041
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1042 1043
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
					 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1044 1045
}

1046 1047
static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
1048 1049 1050
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1051 1052
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
					 0);
1053 1054
}

1055 1056 1057 1058 1059 1060 1061 1062 1063 1064
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;
}

1065 1066 1067
static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
				uint64_t *data)
{
1068 1069
	int count = 0;

1070
	if (chip->info->ops->stats_get_stats)
1071 1072
		count = chip->info->ops->stats_get_stats(chip, port, data);

1073
	mutex_lock(&chip->reg_lock);
1074 1075
	if (chip->info->ops->serdes_get_stats) {
		data += count;
1076
		count = chip->info->ops->serdes_get_stats(chip, port, data);
1077
	}
1078 1079 1080
	data += count;
	mv88e6xxx_atu_vtu_get_stats(chip, port, data);
	mutex_unlock(&chip->reg_lock);
1081 1082
}

1083 1084
static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
					uint64_t *data)
1085
{
V
Vivien Didelot 已提交
1086
	struct mv88e6xxx_chip *chip = ds->priv;
1087 1088
	int ret;

1089
	mutex_lock(&chip->reg_lock);
1090

1091
	ret = mv88e6xxx_stats_snapshot(chip, port);
1092 1093 1094
	mutex_unlock(&chip->reg_lock);

	if (ret < 0)
1095
		return;
1096 1097

	mv88e6xxx_get_stats(chip, port, data);
1098

1099 1100
}

1101
static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
1102 1103 1104 1105
{
	return 32 * sizeof(u16);
}

1106 1107
static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
			       struct ethtool_regs *regs, void *_p)
1108
{
V
Vivien Didelot 已提交
1109
	struct mv88e6xxx_chip *chip = ds->priv;
1110 1111
	int err;
	u16 reg;
1112 1113 1114 1115 1116 1117 1118
	u16 *p = _p;
	int i;

	regs->version = 0;

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

1119
	mutex_lock(&chip->reg_lock);
1120

1121 1122
	for (i = 0; i < 32; i++) {

1123 1124 1125
		err = mv88e6xxx_port_read(chip, port, i, &reg);
		if (!err)
			p[i] = reg;
1126
	}
1127

1128
	mutex_unlock(&chip->reg_lock);
1129 1130
}

V
Vivien Didelot 已提交
1131 1132
static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
1133
{
1134 1135
	/* Nothing to do on the port's MAC */
	return 0;
1136 1137
}

V
Vivien Didelot 已提交
1138 1139
static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
1140
{
1141 1142
	/* Nothing to do on the port's MAC */
	return 0;
1143 1144
}

1145
static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
1146
{
1147 1148 1149
	struct dsa_switch *ds = NULL;
	struct net_device *br;
	u16 pvlan;
1150 1151
	int i;

1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171
	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 已提交
1172
		    (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
1173 1174 1175 1176 1177
			pvlan |= BIT(i);

	return pvlan;
}

1178
static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
1179 1180
{
	u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
1181 1182 1183

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

1185
	return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
1186 1187
}

1188 1189
static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
					 u8 state)
1190
{
V
Vivien Didelot 已提交
1191
	struct mv88e6xxx_chip *chip = ds->priv;
1192
	int err;
1193

1194
	mutex_lock(&chip->reg_lock);
1195
	err = mv88e6xxx_port_set_state(chip, port, state);
1196
	mutex_unlock(&chip->reg_lock);
1197 1198

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

1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220
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;
}

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

1241 1242 1243 1244 1245 1246 1247
	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;
	}

1248 1249 1250 1251
	err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
	if (err)
		return err;

1252 1253 1254
	return 0;
}

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

1264 1265 1266 1267 1268 1269 1270 1271
static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->rmu_disable)
		return chip->info->ops->rmu_disable(chip);

	return 0;
}

1272 1273 1274 1275 1276 1277 1278 1279
static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->pot_clear)
		return chip->info->ops->pot_clear(chip);

	return 0;
}

1280 1281 1282 1283 1284 1285 1286 1287
static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->mgmt_rsvd2cpu)
		return chip->info->ops->mgmt_rsvd2cpu(chip);

	return 0;
}

1288 1289
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
1290 1291
	int err;

1292 1293 1294 1295
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

1296 1297 1298 1299
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

1300 1301 1302
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322
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;
}

1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335
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;
}

1336 1337 1338 1339 1340 1341 1342 1343 1344
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)
1345
		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1346 1347 1348 1349

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

1350 1351
static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
{
1352 1353 1354
	int dev, port;
	int err;

1355 1356 1357 1358 1359 1360
	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.
	 */
1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373
	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;
1374 1375
}

1376 1377 1378 1379 1380 1381
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);
1382
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1383 1384 1385
	mutex_unlock(&chip->reg_lock);

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

1389 1390 1391 1392 1393 1394 1395 1396
static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
{
	if (!chip->info->max_vid)
		return 0;

	return mv88e6xxx_g1_vtu_flush(chip);
}

1397 1398 1399 1400 1401 1402 1403 1404 1405
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);
}

1406 1407 1408 1409 1410 1411 1412 1413 1414
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);
}

1415
static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1416 1417
{
	DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1418 1419 1420
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = chip->info->max_vid,
	};
1421
	int i, err;
1422 1423 1424

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

1425
	/* Set every FID bit used by the (un)bridged ports */
1426
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1427
		err = mv88e6xxx_port_get_fid(chip, i, fid);
1428 1429 1430 1431 1432 1433
		if (err)
			return err;

		set_bit(*fid, fid_bitmap);
	}

1434 1435
	/* Set every FID bit used by the VLAN entries */
	do {
1436
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1437 1438 1439 1440 1441 1442 1443
		if (err)
			return err;

		if (!vlan.valid)
			break;

		set_bit(vlan.fid, fid_bitmap);
1444
	} while (vlan.vid < chip->info->max_vid);
1445 1446 1447 1448 1449

	/* 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);
1450
	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1451 1452 1453
		return -ENOSPC;

	/* Clear the database */
1454
	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1455 1456
}

1457 1458
static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
			     struct mv88e6xxx_vtu_entry *entry, bool new)
1459 1460 1461 1462 1463 1464
{
	int err;

	if (!vid)
		return -EINVAL;

1465 1466
	entry->vid = vid - 1;
	entry->valid = false;
1467

1468
	err = mv88e6xxx_vtu_getnext(chip, entry);
1469 1470 1471
	if (err)
		return err;

1472 1473
	if (entry->vid == vid && entry->valid)
		return 0;
1474

1475 1476 1477 1478 1479 1480 1481 1482
	if (new) {
		int i;

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

1483
		/* Exclude all ports */
1484
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1485
			entry->member[i] =
1486
				MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1487 1488

		return mv88e6xxx_atu_new(chip, &entry->fid);
1489 1490
	}

1491 1492
	/* switchdev expects -EOPNOTSUPP to honor software VLANs */
	return -EOPNOTSUPP;
1493 1494
}

1495 1496 1497
static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
					u16 vid_begin, u16 vid_end)
{
V
Vivien Didelot 已提交
1498
	struct mv88e6xxx_chip *chip = ds->priv;
1499 1500 1501
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = vid_begin - 1,
	};
1502 1503
	int i, err;

1504 1505 1506 1507
	/* 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;

1508 1509 1510
	if (!vid_begin)
		return -EOPNOTSUPP;

1511
	mutex_lock(&chip->reg_lock);
1512 1513

	do {
1514
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1515 1516 1517 1518 1519 1520 1521 1522 1523
		if (err)
			goto unlock;

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

1524
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1525 1526 1527
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

1528
			if (!ds->ports[i].slave)
1529 1530
				continue;

1531
			if (vlan.member[i] ==
1532
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1533 1534
				continue;

V
Vivien Didelot 已提交
1535
			if (dsa_to_port(ds, i)->bridge_dev ==
1536
			    ds->ports[port].bridge_dev)
1537 1538
				break; /* same bridge, check next VLAN */

V
Vivien Didelot 已提交
1539
			if (!dsa_to_port(ds, i)->bridge_dev)
1540 1541
				continue;

1542 1543
			dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
				port, vlan.vid, i,
V
Vivien Didelot 已提交
1544
				netdev_name(dsa_to_port(ds, i)->bridge_dev));
1545 1546 1547 1548 1549 1550
			err = -EOPNOTSUPP;
			goto unlock;
		}
	} while (vlan.vid < vid_end);

unlock:
1551
	mutex_unlock(&chip->reg_lock);
1552 1553 1554 1555

	return err;
}

1556 1557
static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
					 bool vlan_filtering)
1558
{
V
Vivien Didelot 已提交
1559
	struct mv88e6xxx_chip *chip = ds->priv;
1560 1561
	u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
		MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
1562
	int err;
1563

1564
	if (!chip->info->max_vid)
1565 1566
		return -EOPNOTSUPP;

1567
	mutex_lock(&chip->reg_lock);
1568
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1569
	mutex_unlock(&chip->reg_lock);
1570

1571
	return err;
1572 1573
}

1574 1575
static int
mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1576
			    const struct switchdev_obj_port_vlan *vlan)
1577
{
V
Vivien Didelot 已提交
1578
	struct mv88e6xxx_chip *chip = ds->priv;
1579 1580
	int err;

1581
	if (!chip->info->max_vid)
1582 1583
		return -EOPNOTSUPP;

1584 1585 1586 1587 1588 1589 1590 1591
	/* 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;

1592 1593 1594 1595 1596 1597
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */
	return 0;
}

1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641
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);
}

1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664
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;
}

1665
static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
1666
				    u16 vid, u8 member)
1667
{
1668
	struct mv88e6xxx_vtu_entry vlan;
1669 1670
	int err;

1671
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
1672
	if (err)
1673
		return err;
1674

1675
	vlan.member[port] = member;
1676

1677 1678 1679 1680 1681
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
	if (err)
		return err;

	return mv88e6xxx_broadcast_setup(chip, vid);
1682 1683
}

1684
static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1685
				    const struct switchdev_obj_port_vlan *vlan)
1686
{
V
Vivien Didelot 已提交
1687
	struct mv88e6xxx_chip *chip = ds->priv;
1688 1689
	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1690
	u8 member;
1691 1692
	u16 vid;

1693
	if (!chip->info->max_vid)
1694 1695
		return;

1696
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1697
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1698
	else if (untagged)
1699
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
1700
	else
1701
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
1702

1703
	mutex_lock(&chip->reg_lock);
1704

1705
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
1706
		if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
1707 1708
			dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
				vid, untagged ? 'u' : 't');
1709

1710
	if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1711 1712
		dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
			vlan->vid_end);
1713

1714
	mutex_unlock(&chip->reg_lock);
1715 1716
}

1717
static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
1718
				    int port, u16 vid)
1719
{
1720
	struct mv88e6xxx_vtu_entry vlan;
1721 1722
	int i, err;

1723
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1724
	if (err)
1725
		return err;
1726

1727
	/* Tell switchdev if this VLAN is handled in software */
1728
	if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1729
		return -EOPNOTSUPP;
1730

1731
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1732 1733

	/* keep the VLAN unless all ports are excluded */
1734
	vlan.valid = false;
1735
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1736 1737
		if (vlan.member[i] !=
		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
1738
			vlan.valid = true;
1739 1740 1741 1742
			break;
		}
	}

1743
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1744 1745 1746
	if (err)
		return err;

1747
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
1748 1749
}

1750 1751
static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
				   const struct switchdev_obj_port_vlan *vlan)
1752
{
V
Vivien Didelot 已提交
1753
	struct mv88e6xxx_chip *chip = ds->priv;
1754 1755 1756
	u16 pvid, vid;
	int err = 0;

1757
	if (!chip->info->max_vid)
1758 1759
		return -EOPNOTSUPP;

1760
	mutex_lock(&chip->reg_lock);
1761

1762
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
1763 1764 1765
	if (err)
		goto unlock;

1766
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1767
		err = _mv88e6xxx_port_vlan_del(chip, port, vid);
1768 1769 1770 1771
		if (err)
			goto unlock;

		if (vid == pvid) {
1772
			err = mv88e6xxx_port_set_pvid(chip, port, 0);
1773 1774 1775 1776 1777
			if (err)
				goto unlock;
		}
	}

1778
unlock:
1779
	mutex_unlock(&chip->reg_lock);
1780 1781 1782 1783

	return err;
}

1784 1785
static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
				  const unsigned char *addr, u16 vid)
1786
{
V
Vivien Didelot 已提交
1787
	struct mv88e6xxx_chip *chip = ds->priv;
1788
	int err;
1789

1790
	mutex_lock(&chip->reg_lock);
1791 1792
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1793
	mutex_unlock(&chip->reg_lock);
1794 1795

	return err;
1796 1797
}

1798
static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1799
				  const unsigned char *addr, u16 vid)
1800
{
V
Vivien Didelot 已提交
1801
	struct mv88e6xxx_chip *chip = ds->priv;
1802
	int err;
1803

1804
	mutex_lock(&chip->reg_lock);
1805
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1806
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
1807
	mutex_unlock(&chip->reg_lock);
1808

1809
	return err;
1810 1811
}

1812 1813
static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
				      u16 fid, u16 vid, int port,
1814
				      dsa_fdb_dump_cb_t *cb, void *data)
1815
{
1816
	struct mv88e6xxx_atu_entry addr;
1817
	bool is_static;
1818 1819
	int err;

1820
	addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1821
	eth_broadcast_addr(addr.mac);
1822 1823

	do {
1824
		mutex_lock(&chip->reg_lock);
1825
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
1826
		mutex_unlock(&chip->reg_lock);
1827
		if (err)
1828
			return err;
1829

1830
		if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
1831 1832
			break;

1833
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
1834 1835
			continue;

1836 1837
		if (!is_unicast_ether_addr(addr.mac))
			continue;
1838

1839 1840 1841
		is_static = (addr.state ==
			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
		err = cb(addr.mac, vid, is_static, data);
1842 1843
		if (err)
			return err;
1844 1845 1846 1847 1848
	} while (!is_broadcast_ether_addr(addr.mac));

	return err;
}

1849
static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1850
				  dsa_fdb_dump_cb_t *cb, void *data)
1851
{
1852
	struct mv88e6xxx_vtu_entry vlan = {
1853
		.vid = chip->info->max_vid,
1854
	};
1855
	u16 fid;
1856 1857
	int err;

1858
	/* Dump port's default Filtering Information Database (VLAN ID 0) */
1859
	mutex_lock(&chip->reg_lock);
1860
	err = mv88e6xxx_port_get_fid(chip, port, &fid);
1861 1862
	mutex_unlock(&chip->reg_lock);

1863
	if (err)
1864
		return err;
1865

1866
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
1867
	if (err)
1868
		return err;
1869

1870
	/* Dump VLANs' Filtering Information Databases */
1871
	do {
1872
		mutex_lock(&chip->reg_lock);
1873
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1874
		mutex_unlock(&chip->reg_lock);
1875
		if (err)
1876
			return err;
1877 1878 1879 1880

		if (!vlan.valid)
			break;

1881
		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1882
						 cb, data);
1883
		if (err)
1884
			return err;
1885
	} while (vlan.vid < chip->info->max_vid);
1886

1887 1888 1889 1890
	return err;
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1891
				   dsa_fdb_dump_cb_t *cb, void *data)
1892
{
V
Vivien Didelot 已提交
1893
	struct mv88e6xxx_chip *chip = ds->priv;
1894

1895
	return mv88e6xxx_port_db_dump(chip, port, cb, data);
1896 1897
}

1898 1899
static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
				struct net_device *br)
1900
{
1901
	struct dsa_switch *ds;
1902
	int port;
1903
	int dev;
1904
	int err;
1905

1906 1907 1908 1909
	/* 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);
1910
			if (err)
1911
				return err;
1912 1913 1914
		}
	}

1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932
	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;
			}
		}
	}

1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943
	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);
1944
	mutex_unlock(&chip->reg_lock);
1945

1946
	return err;
1947 1948
}

1949 1950
static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
					struct net_device *br)
1951
{
V
Vivien Didelot 已提交
1952
	struct mv88e6xxx_chip *chip = ds->priv;
1953

1954
	mutex_lock(&chip->reg_lock);
1955 1956 1957
	if (mv88e6xxx_bridge_map(chip, br) ||
	    mv88e6xxx_port_vlan_map(chip, port))
		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
1958
	mutex_unlock(&chip->reg_lock);
1959 1960
}

1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990
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);
}

1991 1992 1993 1994 1995 1996 1997 1998
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->reset)
		return chip->info->ops->reset(chip);

	return 0;
}

1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011
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);
	}
}

2012
static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2013
{
2014
	int i, err;
2015

2016
	/* Set all ports to the Disabled state */
2017
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2018
		err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
2019 2020
		if (err)
			return err;
2021 2022
	}

2023 2024 2025
	/* Wait for transmit queues to drain,
	 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
	 */
2026 2027
	usleep_range(2000, 4000);

2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038
	return 0;
}

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

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

2039
	mv88e6xxx_hardware_reset(chip);
2040

2041
	return mv88e6xxx_software_reset(chip);
2042 2043
}

2044
static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
2045 2046
				   enum mv88e6xxx_frame_mode frame,
				   enum mv88e6xxx_egress_mode egress, u16 etype)
2047 2048 2049
{
	int err;

2050 2051 2052 2053
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
2054 2055 2056
	if (err)
		return err;

2057 2058 2059 2060 2061 2062 2063 2064
	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;
2065 2066
}

2067
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2068
{
2069
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
2070
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2071
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2072
}
2073

2074 2075 2076
static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
2077
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2078
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2079
}
2080

2081 2082 2083 2084
static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port,
				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
2085 2086
				       MV88E6XXX_EGRESS_MODE_ETHERTYPE,
				       ETH_P_EDSA);
2087
}
2088

2089 2090 2091 2092
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);
2093

2094
	if (dsa_is_user_port(chip->ds, port))
2095
		return mv88e6xxx_set_port_mode_normal(chip, port);
2096

2097 2098 2099
	/* 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);
2100

2101 2102
	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
		return mv88e6xxx_set_port_mode_edsa(chip, port);
2103

2104
	return -EINVAL;
2105 2106
}

2107
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2108
{
2109
	bool message = dsa_is_dsa_port(chip->ds, port);
2110

2111
	return mv88e6xxx_port_set_message_port(chip, port, message);
2112
}
2113

2114
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2115
{
2116 2117
	struct dsa_switch *ds = chip->ds;
	bool flood;
2118

2119
	/* Upstream ports flood frames with unknown unicast or multicast DA */
2120
	flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
2121 2122 2123
	if (chip->info->ops->port_set_egress_floods)
		return chip->info->ops->port_set_egress_floods(chip, port,
							       flood, flood);
2124

2125
	return 0;
2126 2127
}

2128 2129 2130
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
2131 2132
	if (chip->info->ops->serdes_power)
		return chip->info->ops->serdes_power(chip, port, on);
2133

2134
	return 0;
2135 2136
}

2137 2138 2139 2140 2141 2142
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

2143
	upstream_port = dsa_upstream_port(ds, port);
2144 2145 2146 2147 2148 2149 2150
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166
	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;
		}
	}

2167 2168 2169
	return 0;
}

2170
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
2171
{
2172
	struct dsa_switch *ds = chip->ds;
2173
	int err;
2174
	u16 reg;
2175

2176 2177 2178
	chip->ports[port].chip = chip;
	chip->ports[port].port = port;

2179 2180 2181 2182 2183 2184 2185
	/* 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,
2186
					       PAUSE_OFF,
2187 2188 2189 2190
					       PHY_INTERFACE_MODE_NA);
	else
		err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
					       SPEED_UNFORCED, DUPLEX_UNFORCED,
2191
					       PAUSE_ON,
2192 2193 2194
					       PHY_INTERFACE_MODE_NA);
	if (err)
		return err;
2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209

	/* 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.
	 */
2210 2211 2212 2213
	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);
2214 2215
	if (err)
		return err;
2216

2217
	err = mv88e6xxx_setup_port_mode(chip, port);
2218 2219
	if (err)
		return err;
2220

2221
	err = mv88e6xxx_setup_egress_floods(chip, port);
2222 2223 2224
	if (err)
		return err;

2225 2226 2227
	/* 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.
2228
	 */
2229 2230 2231 2232 2233
	if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
		err = mv88e6xxx_serdes_power(chip, port, true);
		if (err)
			return err;
	}
2234

2235
	/* Port Control 2: don't force a good FCS, set the maximum frame size to
2236
	 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
2237 2238 2239
	 * 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.
2240
	 */
2241 2242 2243
	err = mv88e6xxx_port_set_map_da(chip, port);
	if (err)
		return err;
2244

2245 2246 2247
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
2248

2249
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
2250
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
2251 2252 2253
	if (err)
		return err;

2254 2255
	if (chip->info->ops->port_set_jumbo_size) {
		err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
2256 2257 2258 2259
		if (err)
			return err;
	}

2260 2261 2262 2263 2264
	/* 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.
	 */
2265
	reg = 1 << port;
2266 2267
	/* Disable learning for CPU port */
	if (dsa_is_cpu_port(ds, port))
2268
		reg = 0;
2269

2270 2271
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
2272 2273
	if (err)
		return err;
2274 2275

	/* Egress rate control 2: disable egress rate control. */
2276 2277
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
				   0x0000);
2278 2279
	if (err)
		return err;
2280

2281 2282
	if (chip->info->ops->port_pause_limit) {
		err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
2283 2284
		if (err)
			return err;
2285
	}
2286

2287 2288 2289 2290 2291 2292
	if (chip->info->ops->port_disable_learn_limit) {
		err = chip->info->ops->port_disable_learn_limit(chip, port);
		if (err)
			return err;
	}

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

2299 2300
	if (chip->info->ops->port_tag_remap) {
		err = chip->info->ops->port_tag_remap(chip, port);
2301 2302
		if (err)
			return err;
2303 2304
	}

2305 2306
	if (chip->info->ops->port_egress_rate_limiting) {
		err = chip->info->ops->port_egress_rate_limiting(chip, port);
2307 2308
		if (err)
			return err;
2309 2310
	}

2311
	err = mv88e6xxx_setup_message_port(chip, port);
2312 2313
	if (err)
		return err;
2314

2315
	/* Port based VLAN map: give each port the same default address
2316 2317
	 * database, and allow bidirectional communication between the
	 * CPU and DSA port(s), and the other ports.
2318
	 */
2319
	err = mv88e6xxx_port_set_fid(chip, port, 0);
2320 2321
	if (err)
		return err;
2322

2323
	err = mv88e6xxx_port_vlan_map(chip, port);
2324 2325
	if (err)
		return err;
2326 2327 2328 2329

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

2333 2334 2335 2336
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
2337
	int err;
2338 2339

	mutex_lock(&chip->reg_lock);
2340

2341
	err = mv88e6xxx_serdes_power(chip, port, true);
2342 2343 2344 2345

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

2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356
	mutex_unlock(&chip->reg_lock);

	return err;
}

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

	mutex_lock(&chip->reg_lock);
2357 2358 2359 2360

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

2361 2362
	if (mv88e6xxx_serdes_power(chip, port, false))
		dev_err(chip->dev, "failed to power off SERDES\n");
2363

2364 2365 2366
	mutex_unlock(&chip->reg_lock);
}

2367 2368 2369
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
2370
	struct mv88e6xxx_chip *chip = ds->priv;
2371 2372 2373
	int err;

	mutex_lock(&chip->reg_lock);
2374
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2375 2376 2377 2378 2379
	mutex_unlock(&chip->reg_lock);

	return err;
}

2380
static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
2381
{
2382
	int err;
2383

2384
	/* Initialize the statistics unit */
2385 2386 2387 2388 2389
	if (chip->info->ops->stats_set_histogram) {
		err = chip->info->ops->stats_set_histogram(chip);
		if (err)
			return err;
	}
2390

2391
	return mv88e6xxx_g1_stats_clear(chip);
2392 2393
}

2394
static int mv88e6xxx_setup(struct dsa_switch *ds)
2395
{
V
Vivien Didelot 已提交
2396
	struct mv88e6xxx_chip *chip = ds->priv;
2397
	u8 cmode;
2398
	int err;
2399 2400
	int i;

2401
	chip->ds = ds;
2402
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
2403

2404
	mutex_lock(&chip->reg_lock);
2405

2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416
	/* 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)
				return err;

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

2417
	/* Setup Switch Port Registers */
2418
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2419 2420 2421
		if (dsa_is_unused_port(ds, i))
			continue;

2422 2423 2424 2425 2426
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

2427 2428 2429 2430
	err = mv88e6xxx_irl_setup(chip);
	if (err)
		goto unlock;

2431 2432 2433 2434
	err = mv88e6xxx_mac_setup(chip);
	if (err)
		goto unlock;

2435 2436 2437 2438
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

2439 2440 2441 2442
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

2443 2444 2445 2446
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

2447 2448 2449 2450
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

2451 2452 2453 2454
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

2455 2456 2457 2458
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

2459 2460 2461 2462
	err = mv88e6xxx_rmu_setup(chip);
	if (err)
		goto unlock;

2463 2464 2465
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
2466

2467 2468 2469 2470
	err = mv88e6xxx_trunk_setup(chip);
	if (err)
		goto unlock;

2471 2472 2473 2474
	err = mv88e6xxx_devmap_setup(chip);
	if (err)
		goto unlock;

2475 2476 2477 2478
	err = mv88e6xxx_pri_setup(chip);
	if (err)
		goto unlock;

2479
	/* Setup PTP Hardware Clock and timestamping */
2480 2481 2482 2483
	if (chip->info->ptp_support) {
		err = mv88e6xxx_ptp_setup(chip);
		if (err)
			goto unlock;
2484 2485 2486 2487

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
2488 2489
	}

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

2494
unlock:
2495
	mutex_unlock(&chip->reg_lock);
2496

2497
	return err;
2498 2499
}

2500
static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
2501
{
2502 2503
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2504 2505
	u16 val;
	int err;
2506

2507 2508 2509
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

2510
	mutex_lock(&chip->reg_lock);
2511
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
2512
	mutex_unlock(&chip->reg_lock);
2513

2514 2515 2516 2517 2518
	if (reg == MII_PHYSID2) {
		/* Some internal PHYS don't have a model number.  Use
		 * the mv88e6390 family model number instead.
		 */
		if (!(val & 0x3f0))
2519
			val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
2520 2521
	}

2522
	return err ? err : val;
2523 2524
}

2525
static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
2526
{
2527 2528
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2529
	int err;
2530

2531 2532 2533
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

2534
	mutex_lock(&chip->reg_lock);
2535
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
2536
	mutex_unlock(&chip->reg_lock);
2537 2538

	return err;
2539 2540
}

2541
static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
2542 2543
				   struct device_node *np,
				   bool external)
2544 2545
{
	static int index;
2546
	struct mv88e6xxx_mdio_bus *mdio_bus;
2547 2548 2549
	struct mii_bus *bus;
	int err;

2550 2551 2552 2553 2554 2555 2556 2557 2558
	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;
	}

2559
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
2560 2561 2562
	if (!bus)
		return -ENOMEM;

2563
	mdio_bus = bus->priv;
2564
	mdio_bus->bus = bus;
2565
	mdio_bus->chip = chip;
2566 2567
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
2568

2569 2570
	if (np) {
		bus->name = np->full_name;
2571
		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
2572 2573 2574 2575 2576 2577 2578
	} 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;
2579
	bus->parent = chip->dev;
2580

2581 2582 2583 2584 2585 2586
	if (!external) {
		err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
		if (err)
			return err;
	}

2587
	err = of_mdiobus_register(bus, np);
2588
	if (err) {
2589
		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
2590
		mv88e6xxx_g2_irq_mdio_free(chip, bus);
2591
		return err;
2592
	}
2593 2594 2595 2596 2597

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

	return 0;
2600
}
2601

2602 2603 2604 2605 2606
static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
	{ .compatible = "marvell,mv88e6xxx-mdio-external",
	  .data = (void *)true },
	{ },
};
2607

2608 2609 2610 2611 2612 2613 2614 2615 2616
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;

2617 2618 2619
		if (!mdio_bus->external)
			mv88e6xxx_g2_irq_mdio_free(chip, bus);

2620 2621 2622 2623
		mdiobus_unregister(bus);
	}
}

2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647
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);
2648 2649
			if (err) {
				mv88e6xxx_mdios_unregister(chip);
2650
				return err;
2651
			}
2652 2653 2654 2655
		}
	}

	return 0;
2656 2657
}

2658 2659
static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
2660
	struct mv88e6xxx_chip *chip = ds->priv;
2661 2662 2663 2664 2665 2666 2667

	return chip->eeprom_len;
}

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

2671 2672
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
2673

2674 2675
	mutex_lock(&chip->reg_lock);
	err = chip->info->ops->get_eeprom(chip, eeprom, data);
2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688
	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 已提交
2689
	struct mv88e6xxx_chip *chip = ds->priv;
2690 2691
	int err;

2692 2693 2694
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

2695 2696 2697 2698
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

	mutex_lock(&chip->reg_lock);
2699
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
2700 2701 2702 2703 2704
	mutex_unlock(&chip->reg_lock);

	return err;
}

2705
static const struct mv88e6xxx_ops mv88e6085_ops = {
2706
	/* MV88E6XXX_FAMILY_6097 */
2707 2708
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2709
	.irl_init_all = mv88e6352_g2_irl_init_all,
2710
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2711 2712
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2713
	.port_set_link = mv88e6xxx_port_set_link,
2714
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2715
	.port_set_speed = mv88e6185_port_set_speed,
2716
	.port_tag_remap = mv88e6095_port_tag_remap,
2717
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2718
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2719
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2720
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2721
	.port_pause_limit = mv88e6097_port_pause_limit,
2722
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2723
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2724
	.port_link_state = mv88e6352_port_link_state,
2725
	.port_get_cmode = mv88e6185_port_get_cmode,
2726
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2727
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2728 2729
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2730
	.stats_get_stats = mv88e6095_stats_get_stats,
2731 2732
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2733
	.watchdog_ops = &mv88e6097_watchdog_ops,
2734
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2735
	.pot_clear = mv88e6xxx_g2_pot_clear,
2736 2737
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2738
	.reset = mv88e6185_g1_reset,
2739
	.rmu_disable = mv88e6085_g1_rmu_disable,
2740
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2741
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2742
	.phylink_validate = mv88e6185_phylink_validate,
2743 2744 2745
};

static const struct mv88e6xxx_ops mv88e6095_ops = {
2746
	/* MV88E6XXX_FAMILY_6095 */
2747 2748
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2749
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2750 2751
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2752
	.port_set_link = mv88e6xxx_port_set_link,
2753
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2754
	.port_set_speed = mv88e6185_port_set_speed,
2755
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2756
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2757
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2758
	.port_link_state = mv88e6185_port_link_state,
2759
	.port_get_cmode = mv88e6185_port_get_cmode,
2760
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2761
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2762 2763
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2764
	.stats_get_stats = mv88e6095_stats_get_stats,
2765
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2766 2767
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2768
	.reset = mv88e6185_g1_reset,
2769
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2770
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2771
	.phylink_validate = mv88e6185_phylink_validate,
2772 2773
};

2774
static const struct mv88e6xxx_ops mv88e6097_ops = {
2775
	/* MV88E6XXX_FAMILY_6097 */
2776 2777
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2778
	.irl_init_all = mv88e6352_g2_irl_init_all,
2779 2780 2781 2782 2783 2784
	.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,
2785
	.port_tag_remap = mv88e6095_port_tag_remap,
2786
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2787
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2788
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2789
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2790
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
2791
	.port_pause_limit = mv88e6097_port_pause_limit,
2792
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2793
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2794
	.port_link_state = mv88e6352_port_link_state,
2795
	.port_get_cmode = mv88e6185_port_get_cmode,
2796
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2797
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2798 2799 2800
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
	.stats_get_stats = mv88e6095_stats_get_stats,
2801 2802
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2803
	.watchdog_ops = &mv88e6097_watchdog_ops,
2804
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2805
	.pot_clear = mv88e6xxx_g2_pot_clear,
2806
	.reset = mv88e6352_g1_reset,
2807
	.rmu_disable = mv88e6085_g1_rmu_disable,
2808
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2809
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2810
	.phylink_validate = mv88e6185_phylink_validate,
2811 2812
};

2813
static const struct mv88e6xxx_ops mv88e6123_ops = {
2814
	/* MV88E6XXX_FAMILY_6165 */
2815 2816
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2817
	.irl_init_all = mv88e6352_g2_irl_init_all,
2818
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2819 2820
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2821
	.port_set_link = mv88e6xxx_port_set_link,
2822
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2823
	.port_set_speed = mv88e6185_port_set_speed,
2824
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2825
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2826
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2827
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2828
	.port_link_state = mv88e6352_port_link_state,
2829
	.port_get_cmode = mv88e6185_port_get_cmode,
2830
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2831
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2832 2833
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2834
	.stats_get_stats = mv88e6095_stats_get_stats,
2835 2836
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2837
	.watchdog_ops = &mv88e6097_watchdog_ops,
2838
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2839
	.pot_clear = mv88e6xxx_g2_pot_clear,
2840
	.reset = mv88e6352_g1_reset,
2841
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2842
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2843
	.phylink_validate = mv88e6185_phylink_validate,
2844 2845 2846
};

static const struct mv88e6xxx_ops mv88e6131_ops = {
2847
	/* MV88E6XXX_FAMILY_6185 */
2848 2849
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2850
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2851 2852
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2853
	.port_set_link = mv88e6xxx_port_set_link,
2854
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2855
	.port_set_speed = mv88e6185_port_set_speed,
2856
	.port_tag_remap = mv88e6095_port_tag_remap,
2857
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2858
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2859
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2860
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2861
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2862
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2863
	.port_pause_limit = mv88e6097_port_pause_limit,
2864
	.port_set_pause = mv88e6185_port_set_pause,
2865
	.port_link_state = mv88e6352_port_link_state,
2866
	.port_get_cmode = mv88e6185_port_get_cmode,
2867
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2868
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2869 2870
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2871
	.stats_get_stats = mv88e6095_stats_get_stats,
2872 2873
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2874
	.watchdog_ops = &mv88e6097_watchdog_ops,
2875
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2876
	.ppu_enable = mv88e6185_g1_ppu_enable,
2877
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
2878
	.ppu_disable = mv88e6185_g1_ppu_disable,
2879
	.reset = mv88e6185_g1_reset,
2880
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2881
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2882
	.phylink_validate = mv88e6185_phylink_validate,
2883 2884
};

2885 2886
static const struct mv88e6xxx_ops mv88e6141_ops = {
	/* MV88E6XXX_FAMILY_6341 */
2887 2888
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2889
	.irl_init_all = mv88e6352_g2_irl_init_all,
2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902
	.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,
	.port_set_speed = mv88e6390_port_set_speed,
	.port_tag_remap = mv88e6095_port_tag_remap,
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2903
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2904
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2905
	.port_pause_limit = mv88e6097_port_pause_limit,
2906 2907
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2908
	.port_link_state = mv88e6352_port_link_state,
2909
	.port_get_cmode = mv88e6352_port_get_cmode,
2910
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
2911
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2912 2913 2914
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
2915 2916
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
2917 2918
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
2919
	.pot_clear = mv88e6xxx_g2_pot_clear,
2920
	.reset = mv88e6352_g1_reset,
2921
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2922
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2923
	.serdes_power = mv88e6341_serdes_power,
2924
	.gpio_ops = &mv88e6352_gpio_ops,
2925
	.phylink_validate = mv88e6390_phylink_validate,
2926 2927
};

2928
static const struct mv88e6xxx_ops mv88e6161_ops = {
2929
	/* MV88E6XXX_FAMILY_6165 */
2930 2931
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2932
	.irl_init_all = mv88e6352_g2_irl_init_all,
2933
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2934 2935
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2936
	.port_set_link = mv88e6xxx_port_set_link,
2937
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2938
	.port_set_speed = mv88e6185_port_set_speed,
2939
	.port_tag_remap = mv88e6095_port_tag_remap,
2940
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2941
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2942
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2943
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2944
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2945
	.port_pause_limit = mv88e6097_port_pause_limit,
2946
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2947
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2948
	.port_link_state = mv88e6352_port_link_state,
2949
	.port_get_cmode = mv88e6185_port_get_cmode,
2950
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2951
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2952 2953
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2954
	.stats_get_stats = mv88e6095_stats_get_stats,
2955 2956
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2957
	.watchdog_ops = &mv88e6097_watchdog_ops,
2958
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2959
	.pot_clear = mv88e6xxx_g2_pot_clear,
2960
	.reset = mv88e6352_g1_reset,
2961
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2962
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2963
	.avb_ops = &mv88e6165_avb_ops,
2964
	.ptp_ops = &mv88e6165_ptp_ops,
2965
	.phylink_validate = mv88e6185_phylink_validate,
2966 2967 2968
};

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

static const struct mv88e6xxx_ops mv88e6171_ops = {
3002
	/* MV88E6XXX_FAMILY_6351 */
3003 3004
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3005
	.irl_init_all = mv88e6352_g2_irl_init_all,
3006
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3007 3008
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3009
	.port_set_link = mv88e6xxx_port_set_link,
3010
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3011
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
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 = mv88e6352_port_set_egress_floods,
3016
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3017
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3018
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3019
	.port_pause_limit = mv88e6097_port_pause_limit,
3020
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3021
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3022
	.port_link_state = mv88e6352_port_link_state,
3023
	.port_get_cmode = mv88e6352_port_get_cmode,
3024
	.stats_snapshot = mv88e6320_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 = mv88e6352_g2_mgmt_rsvd2cpu,
3033
	.pot_clear = mv88e6xxx_g2_pot_clear,
3034
	.reset = mv88e6352_g1_reset,
3035
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3036
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3037
	.phylink_validate = mv88e6185_phylink_validate,
3038 3039 3040
};

static const struct mv88e6xxx_ops mv88e6172_ops = {
3041
	/* MV88E6XXX_FAMILY_6352 */
3042 3043
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3044
	.irl_init_all = mv88e6352_g2_irl_init_all,
3045 3046
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3047
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3048 3049
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3050
	.port_set_link = mv88e6xxx_port_set_link,
3051
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3052
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3053
	.port_set_speed = mv88e6352_port_set_speed,
3054
	.port_tag_remap = mv88e6095_port_tag_remap,
3055
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3056
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3057
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3058
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3059
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3060
	.port_pause_limit = mv88e6097_port_pause_limit,
3061
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3062
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3063
	.port_link_state = mv88e6352_port_link_state,
3064
	.port_get_cmode = mv88e6352_port_get_cmode,
3065
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3066
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3067 3068
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3069
	.stats_get_stats = mv88e6095_stats_get_stats,
3070 3071
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3072
	.watchdog_ops = &mv88e6097_watchdog_ops,
3073
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3074
	.pot_clear = mv88e6xxx_g2_pot_clear,
3075
	.reset = mv88e6352_g1_reset,
3076
	.rmu_disable = mv88e6352_g1_rmu_disable,
3077
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3078
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3079
	.serdes_power = mv88e6352_serdes_power,
3080
	.gpio_ops = &mv88e6352_gpio_ops,
3081
	.phylink_validate = mv88e6352_phylink_validate,
3082 3083 3084
};

static const struct mv88e6xxx_ops mv88e6175_ops = {
3085
	/* MV88E6XXX_FAMILY_6351 */
3086 3087
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3088
	.irl_init_all = mv88e6352_g2_irl_init_all,
3089
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3090 3091
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3092
	.port_set_link = mv88e6xxx_port_set_link,
3093
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3094
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
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 = mv88e6352_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
	.phylink_validate = mv88e6185_phylink_validate,
3121 3122 3123
};

static const struct mv88e6xxx_ops mv88e6176_ops = {
3124
	/* MV88E6XXX_FAMILY_6352 */
3125 3126
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3127
	.irl_init_all = mv88e6352_g2_irl_init_all,
3128 3129
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3130
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3131 3132
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3133
	.port_set_link = mv88e6xxx_port_set_link,
3134
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3135
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3136
	.port_set_speed = mv88e6352_port_set_speed,
3137
	.port_tag_remap = mv88e6095_port_tag_remap,
3138
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3139
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3140
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3141
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3142
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3143
	.port_pause_limit = mv88e6097_port_pause_limit,
3144
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3145
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3146
	.port_link_state = mv88e6352_port_link_state,
3147
	.port_get_cmode = mv88e6352_port_get_cmode,
3148
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3149
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3150 3151
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3152
	.stats_get_stats = mv88e6095_stats_get_stats,
3153 3154
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3155
	.watchdog_ops = &mv88e6097_watchdog_ops,
3156
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3157
	.pot_clear = mv88e6xxx_g2_pot_clear,
3158
	.reset = mv88e6352_g1_reset,
3159
	.rmu_disable = mv88e6352_g1_rmu_disable,
3160
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3161
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3162
	.serdes_power = mv88e6352_serdes_power,
3163
	.gpio_ops = &mv88e6352_gpio_ops,
3164
	.phylink_validate = mv88e6352_phylink_validate,
3165 3166 3167
};

static const struct mv88e6xxx_ops mv88e6185_ops = {
3168
	/* MV88E6XXX_FAMILY_6185 */
3169 3170
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3171
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3172 3173
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3174
	.port_set_link = mv88e6xxx_port_set_link,
3175
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3176
	.port_set_speed = mv88e6185_port_set_speed,
3177
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
3178
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
3179
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
3180
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
3181
	.port_set_pause = mv88e6185_port_set_pause,
3182
	.port_link_state = mv88e6185_port_link_state,
3183
	.port_get_cmode = mv88e6185_port_get_cmode,
3184
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3185
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3186 3187
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3188
	.stats_get_stats = mv88e6095_stats_get_stats,
3189 3190
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3191
	.watchdog_ops = &mv88e6097_watchdog_ops,
3192
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3193
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
3194 3195
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
3196
	.reset = mv88e6185_g1_reset,
3197
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3198
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3199
	.phylink_validate = mv88e6185_phylink_validate,
3200 3201
};

3202
static const struct mv88e6xxx_ops mv88e6190_ops = {
3203
	/* MV88E6XXX_FAMILY_6390 */
3204
	.irl_init_all = mv88e6390_g2_irl_init_all,
3205 3206
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3207 3208 3209 3210 3211 3212 3213
	.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,
3214
	.port_tag_remap = mv88e6390_port_tag_remap,
3215
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3216
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3217
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3218
	.port_pause_limit = mv88e6390_port_pause_limit,
3219
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3220
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3221
	.port_link_state = mv88e6352_port_link_state,
3222
	.port_get_cmode = mv88e6352_port_get_cmode,
3223
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3224
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3225 3226
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3227
	.stats_get_stats = mv88e6390_stats_get_stats,
3228 3229
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3230
	.watchdog_ops = &mv88e6390_watchdog_ops,
3231
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3232
	.pot_clear = mv88e6xxx_g2_pot_clear,
3233
	.reset = mv88e6352_g1_reset,
3234
	.rmu_disable = mv88e6390_g1_rmu_disable,
3235 3236
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3237
	.serdes_power = mv88e6390_serdes_power,
3238 3239
	.serdes_irq_setup = mv88e6390_serdes_irq_setup,
	.serdes_irq_free = mv88e6390_serdes_irq_free,
3240
	.gpio_ops = &mv88e6352_gpio_ops,
3241
	.phylink_validate = mv88e6390_phylink_validate,
3242 3243 3244
};

static const struct mv88e6xxx_ops mv88e6190x_ops = {
3245
	/* MV88E6XXX_FAMILY_6390 */
3246
	.irl_init_all = mv88e6390_g2_irl_init_all,
3247 3248
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3249 3250 3251 3252 3253 3254 3255
	.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,
3256
	.port_tag_remap = mv88e6390_port_tag_remap,
3257
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3258
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3259
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3260
	.port_pause_limit = mv88e6390_port_pause_limit,
3261
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3262
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3263
	.port_link_state = mv88e6352_port_link_state,
3264
	.port_get_cmode = mv88e6352_port_get_cmode,
3265
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3266
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3267 3268
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3269
	.stats_get_stats = mv88e6390_stats_get_stats,
3270 3271
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3272
	.watchdog_ops = &mv88e6390_watchdog_ops,
3273
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3274
	.pot_clear = mv88e6xxx_g2_pot_clear,
3275
	.reset = mv88e6352_g1_reset,
3276
	.rmu_disable = mv88e6390_g1_rmu_disable,
3277 3278
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3279
	.serdes_power = mv88e6390x_serdes_power,
3280 3281
	.serdes_irq_setup = mv88e6390_serdes_irq_setup,
	.serdes_irq_free = mv88e6390_serdes_irq_free,
3282
	.gpio_ops = &mv88e6352_gpio_ops,
3283
	.phylink_validate = mv88e6390x_phylink_validate,
3284 3285 3286
};

static const struct mv88e6xxx_ops mv88e6191_ops = {
3287
	/* MV88E6XXX_FAMILY_6390 */
3288
	.irl_init_all = mv88e6390_g2_irl_init_all,
3289 3290
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3291 3292 3293 3294 3295 3296 3297
	.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,
3298
	.port_tag_remap = mv88e6390_port_tag_remap,
3299
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3300
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3301
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3302
	.port_pause_limit = mv88e6390_port_pause_limit,
3303
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3304
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3305
	.port_link_state = mv88e6352_port_link_state,
3306
	.port_get_cmode = mv88e6352_port_get_cmode,
3307
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3308
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3309 3310
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3311
	.stats_get_stats = mv88e6390_stats_get_stats,
3312 3313
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3314
	.watchdog_ops = &mv88e6390_watchdog_ops,
3315
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3316
	.pot_clear = mv88e6xxx_g2_pot_clear,
3317
	.reset = mv88e6352_g1_reset,
3318
	.rmu_disable = mv88e6390_g1_rmu_disable,
3319 3320
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3321
	.serdes_power = mv88e6390_serdes_power,
3322 3323
	.serdes_irq_setup = mv88e6390_serdes_irq_setup,
	.serdes_irq_free = mv88e6390_serdes_irq_free,
3324 3325
	.avb_ops = &mv88e6390_avb_ops,
	.ptp_ops = &mv88e6352_ptp_ops,
3326
	.phylink_validate = mv88e6390_phylink_validate,
3327 3328
};

3329
static const struct mv88e6xxx_ops mv88e6240_ops = {
3330
	/* MV88E6XXX_FAMILY_6352 */
3331 3332
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3333
	.irl_init_all = mv88e6352_g2_irl_init_all,
3334 3335
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3336
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3337 3338
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3339
	.port_set_link = mv88e6xxx_port_set_link,
3340
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3341
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3342
	.port_set_speed = mv88e6352_port_set_speed,
3343
	.port_tag_remap = mv88e6095_port_tag_remap,
3344
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3345
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3346
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3347
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3348
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3349
	.port_pause_limit = mv88e6097_port_pause_limit,
3350
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3351
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3352
	.port_link_state = mv88e6352_port_link_state,
3353
	.port_get_cmode = mv88e6352_port_get_cmode,
3354
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3355
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3356 3357
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3358
	.stats_get_stats = mv88e6095_stats_get_stats,
3359 3360
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3361
	.watchdog_ops = &mv88e6097_watchdog_ops,
3362
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3363
	.pot_clear = mv88e6xxx_g2_pot_clear,
3364
	.reset = mv88e6352_g1_reset,
3365
	.rmu_disable = mv88e6352_g1_rmu_disable,
3366
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3367
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3368
	.serdes_power = mv88e6352_serdes_power,
3369
	.gpio_ops = &mv88e6352_gpio_ops,
3370
	.avb_ops = &mv88e6352_avb_ops,
3371
	.ptp_ops = &mv88e6352_ptp_ops,
3372
	.phylink_validate = mv88e6352_phylink_validate,
3373 3374
};

3375
static const struct mv88e6xxx_ops mv88e6290_ops = {
3376
	/* MV88E6XXX_FAMILY_6390 */
3377
	.irl_init_all = mv88e6390_g2_irl_init_all,
3378 3379
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3380 3381 3382 3383 3384 3385 3386
	.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,
3387
	.port_tag_remap = mv88e6390_port_tag_remap,
3388
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3389
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3390
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3391
	.port_pause_limit = mv88e6390_port_pause_limit,
3392
	.port_set_cmode = mv88e6390x_port_set_cmode,
3393
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3394
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3395
	.port_link_state = mv88e6352_port_link_state,
3396
	.port_get_cmode = mv88e6352_port_get_cmode,
3397
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3398
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3399 3400
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3401
	.stats_get_stats = mv88e6390_stats_get_stats,
3402 3403
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3404
	.watchdog_ops = &mv88e6390_watchdog_ops,
3405
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3406
	.pot_clear = mv88e6xxx_g2_pot_clear,
3407
	.reset = mv88e6352_g1_reset,
3408
	.rmu_disable = mv88e6390_g1_rmu_disable,
3409 3410
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3411
	.serdes_power = mv88e6390_serdes_power,
3412 3413
	.serdes_irq_setup = mv88e6390_serdes_irq_setup,
	.serdes_irq_free = mv88e6390_serdes_irq_free,
3414
	.gpio_ops = &mv88e6352_gpio_ops,
3415
	.avb_ops = &mv88e6390_avb_ops,
3416
	.ptp_ops = &mv88e6352_ptp_ops,
3417
	.phylink_validate = mv88e6390_phylink_validate,
3418 3419
};

3420
static const struct mv88e6xxx_ops mv88e6320_ops = {
3421
	/* MV88E6XXX_FAMILY_6320 */
3422 3423
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3424
	.irl_init_all = mv88e6352_g2_irl_init_all,
3425 3426
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3427
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3428 3429
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3430
	.port_set_link = mv88e6xxx_port_set_link,
3431
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3432
	.port_set_speed = mv88e6185_port_set_speed,
3433
	.port_tag_remap = mv88e6095_port_tag_remap,
3434
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3435
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3436
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3437
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3438
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3439
	.port_pause_limit = mv88e6097_port_pause_limit,
3440
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3441
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3442
	.port_link_state = mv88e6352_port_link_state,
3443
	.port_get_cmode = mv88e6352_port_get_cmode,
3444
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3445
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3446 3447
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3448
	.stats_get_stats = mv88e6320_stats_get_stats,
3449 3450
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3451
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3452
	.pot_clear = mv88e6xxx_g2_pot_clear,
3453
	.reset = mv88e6352_g1_reset,
3454
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3455
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3456
	.gpio_ops = &mv88e6352_gpio_ops,
3457
	.avb_ops = &mv88e6352_avb_ops,
3458
	.ptp_ops = &mv88e6352_ptp_ops,
3459
	.phylink_validate = mv88e6185_phylink_validate,
3460 3461 3462
};

static const struct mv88e6xxx_ops mv88e6321_ops = {
3463
	/* MV88E6XXX_FAMILY_6320 */
3464 3465
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3466
	.irl_init_all = mv88e6352_g2_irl_init_all,
3467 3468
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3469
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3470 3471
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3472
	.port_set_link = mv88e6xxx_port_set_link,
3473
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3474
	.port_set_speed = mv88e6185_port_set_speed,
3475
	.port_tag_remap = mv88e6095_port_tag_remap,
3476
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3477
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3478
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3479
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3480
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3481
	.port_pause_limit = mv88e6097_port_pause_limit,
3482
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3483
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3484
	.port_link_state = mv88e6352_port_link_state,
3485
	.port_get_cmode = mv88e6352_port_get_cmode,
3486
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3487
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3488 3489
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3490
	.stats_get_stats = mv88e6320_stats_get_stats,
3491 3492
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3493
	.reset = mv88e6352_g1_reset,
3494
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3495
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3496
	.gpio_ops = &mv88e6352_gpio_ops,
3497
	.avb_ops = &mv88e6352_avb_ops,
3498
	.ptp_ops = &mv88e6352_ptp_ops,
3499
	.phylink_validate = mv88e6185_phylink_validate,
3500 3501
};

3502 3503
static const struct mv88e6xxx_ops mv88e6341_ops = {
	/* MV88E6XXX_FAMILY_6341 */
3504 3505
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3506
	.irl_init_all = mv88e6352_g2_irl_init_all,
3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519
	.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,
	.port_set_speed = mv88e6390_port_set_speed,
	.port_tag_remap = mv88e6095_port_tag_remap,
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3520
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3521
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3522
	.port_pause_limit = mv88e6097_port_pause_limit,
3523 3524
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3525
	.port_link_state = mv88e6352_port_link_state,
3526
	.port_get_cmode = mv88e6352_port_get_cmode,
3527
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3528
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3529 3530 3531
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
3532 3533
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3534 3535
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
3536
	.pot_clear = mv88e6xxx_g2_pot_clear,
3537
	.reset = mv88e6352_g1_reset,
3538
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3539
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3540
	.serdes_power = mv88e6341_serdes_power,
3541
	.gpio_ops = &mv88e6352_gpio_ops,
3542
	.avb_ops = &mv88e6390_avb_ops,
3543
	.ptp_ops = &mv88e6352_ptp_ops,
3544
	.phylink_validate = mv88e6390_phylink_validate,
3545 3546
};

3547
static const struct mv88e6xxx_ops mv88e6350_ops = {
3548
	/* MV88E6XXX_FAMILY_6351 */
3549 3550
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3551
	.irl_init_all = mv88e6352_g2_irl_init_all,
3552
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3553 3554
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3555
	.port_set_link = mv88e6xxx_port_set_link,
3556
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3557
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3558
	.port_set_speed = mv88e6185_port_set_speed,
3559
	.port_tag_remap = mv88e6095_port_tag_remap,
3560
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3561
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3562
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3563
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3564
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3565
	.port_pause_limit = mv88e6097_port_pause_limit,
3566
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3567
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3568
	.port_link_state = mv88e6352_port_link_state,
3569
	.port_get_cmode = mv88e6352_port_get_cmode,
3570
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3571
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3572 3573
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3574
	.stats_get_stats = mv88e6095_stats_get_stats,
3575 3576
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3577
	.watchdog_ops = &mv88e6097_watchdog_ops,
3578
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3579
	.pot_clear = mv88e6xxx_g2_pot_clear,
3580
	.reset = mv88e6352_g1_reset,
3581
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3582
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3583
	.phylink_validate = mv88e6185_phylink_validate,
3584 3585 3586
};

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

static const struct mv88e6xxx_ops mv88e6352_ops = {
3628
	/* MV88E6XXX_FAMILY_6352 */
3629 3630
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3631
	.irl_init_all = mv88e6352_g2_irl_init_all,
3632 3633
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3634
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3635 3636
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3637
	.port_set_link = mv88e6xxx_port_set_link,
3638
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3639
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3640
	.port_set_speed = mv88e6352_port_set_speed,
3641
	.port_tag_remap = mv88e6095_port_tag_remap,
3642
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3643
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3644
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3645
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3646
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3647
	.port_pause_limit = mv88e6097_port_pause_limit,
3648
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3649
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3650
	.port_link_state = mv88e6352_port_link_state,
3651
	.port_get_cmode = mv88e6352_port_get_cmode,
3652
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3653
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3654 3655
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3656
	.stats_get_stats = mv88e6095_stats_get_stats,
3657 3658
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3659
	.watchdog_ops = &mv88e6097_watchdog_ops,
3660
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3661
	.pot_clear = mv88e6xxx_g2_pot_clear,
3662
	.reset = mv88e6352_g1_reset,
3663
	.rmu_disable = mv88e6352_g1_rmu_disable,
3664
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3665
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3666
	.serdes_power = mv88e6352_serdes_power,
3667
	.gpio_ops = &mv88e6352_gpio_ops,
3668
	.avb_ops = &mv88e6352_avb_ops,
3669
	.ptp_ops = &mv88e6352_ptp_ops,
3670 3671 3672
	.serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
	.serdes_get_strings = mv88e6352_serdes_get_strings,
	.serdes_get_stats = mv88e6352_serdes_get_stats,
3673
	.phylink_validate = mv88e6352_phylink_validate,
3674 3675
};

3676
static const struct mv88e6xxx_ops mv88e6390_ops = {
3677
	/* MV88E6XXX_FAMILY_6390 */
3678
	.irl_init_all = mv88e6390_g2_irl_init_all,
3679 3680
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3681 3682 3683 3684 3685 3686 3687
	.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,
3688
	.port_tag_remap = mv88e6390_port_tag_remap,
3689
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3690
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3691
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3692
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3693
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3694
	.port_pause_limit = mv88e6390_port_pause_limit,
3695
	.port_set_cmode = mv88e6390x_port_set_cmode,
3696
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3697
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3698
	.port_link_state = mv88e6352_port_link_state,
3699
	.port_get_cmode = mv88e6352_port_get_cmode,
3700
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3701
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3702 3703
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3704
	.stats_get_stats = mv88e6390_stats_get_stats,
3705 3706
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3707
	.watchdog_ops = &mv88e6390_watchdog_ops,
3708
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3709
	.pot_clear = mv88e6xxx_g2_pot_clear,
3710
	.reset = mv88e6352_g1_reset,
3711
	.rmu_disable = mv88e6390_g1_rmu_disable,
3712 3713
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3714
	.serdes_power = mv88e6390_serdes_power,
3715 3716
	.serdes_irq_setup = mv88e6390_serdes_irq_setup,
	.serdes_irq_free = mv88e6390_serdes_irq_free,
3717
	.gpio_ops = &mv88e6352_gpio_ops,
3718
	.avb_ops = &mv88e6390_avb_ops,
3719
	.ptp_ops = &mv88e6352_ptp_ops,
3720
	.phylink_validate = mv88e6390_phylink_validate,
3721 3722 3723
};

static const struct mv88e6xxx_ops mv88e6390x_ops = {
3724
	/* MV88E6XXX_FAMILY_6390 */
3725
	.irl_init_all = mv88e6390_g2_irl_init_all,
3726 3727
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3728 3729 3730 3731 3732 3733 3734
	.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,
3735
	.port_tag_remap = mv88e6390_port_tag_remap,
3736
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3737
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3738
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3739
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3740
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3741
	.port_pause_limit = mv88e6390_port_pause_limit,
3742
	.port_set_cmode = mv88e6390x_port_set_cmode,
3743
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3744
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3745
	.port_link_state = mv88e6352_port_link_state,
3746
	.port_get_cmode = mv88e6352_port_get_cmode,
3747
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3748
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3749 3750
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3751
	.stats_get_stats = mv88e6390_stats_get_stats,
3752 3753
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3754
	.watchdog_ops = &mv88e6390_watchdog_ops,
3755
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3756
	.pot_clear = mv88e6xxx_g2_pot_clear,
3757
	.reset = mv88e6352_g1_reset,
3758
	.rmu_disable = mv88e6390_g1_rmu_disable,
3759 3760
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3761
	.serdes_power = mv88e6390x_serdes_power,
3762 3763
	.serdes_irq_setup = mv88e6390_serdes_irq_setup,
	.serdes_irq_free = mv88e6390_serdes_irq_free,
3764
	.gpio_ops = &mv88e6352_gpio_ops,
3765
	.avb_ops = &mv88e6390_avb_ops,
3766
	.ptp_ops = &mv88e6352_ptp_ops,
3767
	.phylink_validate = mv88e6390x_phylink_validate,
3768 3769
};

3770 3771
static const struct mv88e6xxx_info mv88e6xxx_table[] = {
	[MV88E6085] = {
3772
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
3773 3774 3775 3776
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6085",
		.num_databases = 4096,
		.num_ports = 10,
3777
		.num_internal_phys = 5,
3778
		.max_vid = 4095,
3779
		.port_base_addr = 0x10,
3780
		.phy_base_addr = 0x0,
3781
		.global1_addr = 0x1b,
3782
		.global2_addr = 0x1c,
3783
		.age_time_coeff = 15000,
3784
		.g1_irqs = 8,
3785
		.g2_irqs = 10,
3786
		.atu_move_port_mask = 0xf,
3787
		.pvt = true,
3788
		.multi_chip = true,
3789
		.tag_protocol = DSA_TAG_PROTO_DSA,
3790
		.ops = &mv88e6085_ops,
3791 3792 3793
	},

	[MV88E6095] = {
3794
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
3795 3796 3797 3798
		.family = MV88E6XXX_FAMILY_6095,
		.name = "Marvell 88E6095/88E6095F",
		.num_databases = 256,
		.num_ports = 11,
3799
		.num_internal_phys = 0,
3800
		.max_vid = 4095,
3801
		.port_base_addr = 0x10,
3802
		.phy_base_addr = 0x0,
3803
		.global1_addr = 0x1b,
3804
		.global2_addr = 0x1c,
3805
		.age_time_coeff = 15000,
3806
		.g1_irqs = 8,
3807
		.atu_move_port_mask = 0xf,
3808
		.multi_chip = true,
3809
		.tag_protocol = DSA_TAG_PROTO_DSA,
3810
		.ops = &mv88e6095_ops,
3811 3812
	},

3813
	[MV88E6097] = {
3814
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
3815 3816 3817 3818
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6097/88E6097F",
		.num_databases = 4096,
		.num_ports = 11,
3819
		.num_internal_phys = 8,
3820
		.max_vid = 4095,
3821
		.port_base_addr = 0x10,
3822
		.phy_base_addr = 0x0,
3823
		.global1_addr = 0x1b,
3824
		.global2_addr = 0x1c,
3825
		.age_time_coeff = 15000,
3826
		.g1_irqs = 8,
3827
		.g2_irqs = 10,
3828
		.atu_move_port_mask = 0xf,
3829
		.pvt = true,
3830
		.multi_chip = true,
3831
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3832 3833 3834
		.ops = &mv88e6097_ops,
	},

3835
	[MV88E6123] = {
3836
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
3837 3838 3839 3840
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6123",
		.num_databases = 4096,
		.num_ports = 3,
3841
		.num_internal_phys = 5,
3842
		.max_vid = 4095,
3843
		.port_base_addr = 0x10,
3844
		.phy_base_addr = 0x0,
3845
		.global1_addr = 0x1b,
3846
		.global2_addr = 0x1c,
3847
		.age_time_coeff = 15000,
3848
		.g1_irqs = 9,
3849
		.g2_irqs = 10,
3850
		.atu_move_port_mask = 0xf,
3851
		.pvt = true,
3852
		.multi_chip = true,
3853
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3854
		.ops = &mv88e6123_ops,
3855 3856 3857
	},

	[MV88E6131] = {
3858
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
3859 3860 3861 3862
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6131",
		.num_databases = 256,
		.num_ports = 8,
3863
		.num_internal_phys = 0,
3864
		.max_vid = 4095,
3865
		.port_base_addr = 0x10,
3866
		.phy_base_addr = 0x0,
3867
		.global1_addr = 0x1b,
3868
		.global2_addr = 0x1c,
3869
		.age_time_coeff = 15000,
3870
		.g1_irqs = 9,
3871
		.atu_move_port_mask = 0xf,
3872
		.multi_chip = true,
3873
		.tag_protocol = DSA_TAG_PROTO_DSA,
3874
		.ops = &mv88e6131_ops,
3875 3876
	},

3877
	[MV88E6141] = {
3878
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
3879
		.family = MV88E6XXX_FAMILY_6341,
3880
		.name = "Marvell 88E6141",
3881 3882
		.num_databases = 4096,
		.num_ports = 6,
3883
		.num_internal_phys = 5,
3884
		.num_gpio = 11,
3885
		.max_vid = 4095,
3886
		.port_base_addr = 0x10,
3887
		.phy_base_addr = 0x10,
3888
		.global1_addr = 0x1b,
3889
		.global2_addr = 0x1c,
3890 3891
		.age_time_coeff = 3750,
		.atu_move_port_mask = 0x1f,
3892
		.g1_irqs = 9,
3893
		.g2_irqs = 10,
3894
		.pvt = true,
3895
		.multi_chip = true,
3896 3897 3898 3899
		.tag_protocol = DSA_TAG_PROTO_EDSA,
		.ops = &mv88e6141_ops,
	},

3900
	[MV88E6161] = {
3901
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
3902 3903 3904 3905
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6161",
		.num_databases = 4096,
		.num_ports = 6,
3906
		.num_internal_phys = 5,
3907
		.max_vid = 4095,
3908
		.port_base_addr = 0x10,
3909
		.phy_base_addr = 0x0,
3910
		.global1_addr = 0x1b,
3911
		.global2_addr = 0x1c,
3912
		.age_time_coeff = 15000,
3913
		.g1_irqs = 9,
3914
		.g2_irqs = 10,
3915
		.atu_move_port_mask = 0xf,
3916
		.pvt = true,
3917
		.multi_chip = true,
3918
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3919
		.ptp_support = true,
3920
		.ops = &mv88e6161_ops,
3921 3922 3923
	},

	[MV88E6165] = {
3924
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
3925 3926 3927 3928
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6165",
		.num_databases = 4096,
		.num_ports = 6,
3929
		.num_internal_phys = 0,
3930
		.max_vid = 4095,
3931
		.port_base_addr = 0x10,
3932
		.phy_base_addr = 0x0,
3933
		.global1_addr = 0x1b,
3934
		.global2_addr = 0x1c,
3935
		.age_time_coeff = 15000,
3936
		.g1_irqs = 9,
3937
		.g2_irqs = 10,
3938
		.atu_move_port_mask = 0xf,
3939
		.pvt = true,
3940
		.multi_chip = true,
3941
		.tag_protocol = DSA_TAG_PROTO_DSA,
3942
		.ptp_support = true,
3943
		.ops = &mv88e6165_ops,
3944 3945 3946
	},

	[MV88E6171] = {
3947
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
3948 3949 3950 3951
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6171",
		.num_databases = 4096,
		.num_ports = 7,
3952
		.num_internal_phys = 5,
3953
		.max_vid = 4095,
3954
		.port_base_addr = 0x10,
3955
		.phy_base_addr = 0x0,
3956
		.global1_addr = 0x1b,
3957
		.global2_addr = 0x1c,
3958
		.age_time_coeff = 15000,
3959
		.g1_irqs = 9,
3960
		.g2_irqs = 10,
3961
		.atu_move_port_mask = 0xf,
3962
		.pvt = true,
3963
		.multi_chip = true,
3964
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3965
		.ops = &mv88e6171_ops,
3966 3967 3968
	},

	[MV88E6172] = {
3969
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
3970 3971 3972 3973
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6172",
		.num_databases = 4096,
		.num_ports = 7,
3974
		.num_internal_phys = 5,
3975
		.num_gpio = 15,
3976
		.max_vid = 4095,
3977
		.port_base_addr = 0x10,
3978
		.phy_base_addr = 0x0,
3979
		.global1_addr = 0x1b,
3980
		.global2_addr = 0x1c,
3981
		.age_time_coeff = 15000,
3982
		.g1_irqs = 9,
3983
		.g2_irqs = 10,
3984
		.atu_move_port_mask = 0xf,
3985
		.pvt = true,
3986
		.multi_chip = true,
3987
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3988
		.ops = &mv88e6172_ops,
3989 3990 3991
	},

	[MV88E6175] = {
3992
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
3993 3994 3995 3996
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6175",
		.num_databases = 4096,
		.num_ports = 7,
3997
		.num_internal_phys = 5,
3998
		.max_vid = 4095,
3999
		.port_base_addr = 0x10,
4000
		.phy_base_addr = 0x0,
4001
		.global1_addr = 0x1b,
4002
		.global2_addr = 0x1c,
4003
		.age_time_coeff = 15000,
4004
		.g1_irqs = 9,
4005
		.g2_irqs = 10,
4006
		.atu_move_port_mask = 0xf,
4007
		.pvt = true,
4008
		.multi_chip = true,
4009
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4010
		.ops = &mv88e6175_ops,
4011 4012 4013
	},

	[MV88E6176] = {
4014
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
4015 4016 4017 4018
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6176",
		.num_databases = 4096,
		.num_ports = 7,
4019
		.num_internal_phys = 5,
4020
		.num_gpio = 15,
4021
		.max_vid = 4095,
4022
		.port_base_addr = 0x10,
4023
		.phy_base_addr = 0x0,
4024
		.global1_addr = 0x1b,
4025
		.global2_addr = 0x1c,
4026
		.age_time_coeff = 15000,
4027
		.g1_irqs = 9,
4028
		.g2_irqs = 10,
4029
		.atu_move_port_mask = 0xf,
4030
		.pvt = true,
4031
		.multi_chip = true,
4032
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4033
		.ops = &mv88e6176_ops,
4034 4035 4036
	},

	[MV88E6185] = {
4037
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
4038 4039 4040 4041
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6185",
		.num_databases = 256,
		.num_ports = 10,
4042
		.num_internal_phys = 0,
4043
		.max_vid = 4095,
4044
		.port_base_addr = 0x10,
4045
		.phy_base_addr = 0x0,
4046
		.global1_addr = 0x1b,
4047
		.global2_addr = 0x1c,
4048
		.age_time_coeff = 15000,
4049
		.g1_irqs = 8,
4050
		.atu_move_port_mask = 0xf,
4051
		.multi_chip = true,
4052
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4053
		.ops = &mv88e6185_ops,
4054 4055
	},

4056
	[MV88E6190] = {
4057
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
4058 4059 4060 4061
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4062
		.num_internal_phys = 11,
4063
		.num_gpio = 16,
4064
		.max_vid = 8191,
4065
		.port_base_addr = 0x0,
4066
		.phy_base_addr = 0x0,
4067
		.global1_addr = 0x1b,
4068
		.global2_addr = 0x1c,
4069
		.tag_protocol = DSA_TAG_PROTO_DSA,
4070
		.age_time_coeff = 3750,
4071
		.g1_irqs = 9,
4072
		.g2_irqs = 14,
4073
		.pvt = true,
4074
		.multi_chip = true,
4075
		.atu_move_port_mask = 0x1f,
4076 4077 4078 4079
		.ops = &mv88e6190_ops,
	},

	[MV88E6190X] = {
4080
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
4081 4082 4083 4084
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4085
		.num_internal_phys = 11,
4086
		.num_gpio = 16,
4087
		.max_vid = 8191,
4088
		.port_base_addr = 0x0,
4089
		.phy_base_addr = 0x0,
4090
		.global1_addr = 0x1b,
4091
		.global2_addr = 0x1c,
4092
		.age_time_coeff = 3750,
4093
		.g1_irqs = 9,
4094
		.g2_irqs = 14,
4095
		.atu_move_port_mask = 0x1f,
4096
		.pvt = true,
4097
		.multi_chip = true,
4098
		.tag_protocol = DSA_TAG_PROTO_DSA,
4099 4100 4101 4102
		.ops = &mv88e6190x_ops,
	},

	[MV88E6191] = {
4103
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
4104 4105 4106 4107
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6191",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4108
		.num_internal_phys = 11,
4109
		.max_vid = 8191,
4110
		.port_base_addr = 0x0,
4111
		.phy_base_addr = 0x0,
4112
		.global1_addr = 0x1b,
4113
		.global2_addr = 0x1c,
4114
		.age_time_coeff = 3750,
4115
		.g1_irqs = 9,
4116
		.g2_irqs = 14,
4117
		.atu_move_port_mask = 0x1f,
4118
		.pvt = true,
4119
		.multi_chip = true,
4120
		.tag_protocol = DSA_TAG_PROTO_DSA,
4121
		.ptp_support = true,
4122
		.ops = &mv88e6191_ops,
4123 4124
	},

4125
	[MV88E6240] = {
4126
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
4127 4128 4129 4130
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6240",
		.num_databases = 4096,
		.num_ports = 7,
4131
		.num_internal_phys = 5,
4132
		.num_gpio = 15,
4133
		.max_vid = 4095,
4134
		.port_base_addr = 0x10,
4135
		.phy_base_addr = 0x0,
4136
		.global1_addr = 0x1b,
4137
		.global2_addr = 0x1c,
4138
		.age_time_coeff = 15000,
4139
		.g1_irqs = 9,
4140
		.g2_irqs = 10,
4141
		.atu_move_port_mask = 0xf,
4142
		.pvt = true,
4143
		.multi_chip = true,
4144
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4145
		.ptp_support = true,
4146
		.ops = &mv88e6240_ops,
4147 4148
	},

4149
	[MV88E6290] = {
4150
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
4151 4152 4153 4154
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6290",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4155
		.num_internal_phys = 11,
4156
		.num_gpio = 16,
4157
		.max_vid = 8191,
4158
		.port_base_addr = 0x0,
4159
		.phy_base_addr = 0x0,
4160
		.global1_addr = 0x1b,
4161
		.global2_addr = 0x1c,
4162
		.age_time_coeff = 3750,
4163
		.g1_irqs = 9,
4164
		.g2_irqs = 14,
4165
		.atu_move_port_mask = 0x1f,
4166
		.pvt = true,
4167
		.multi_chip = true,
4168
		.tag_protocol = DSA_TAG_PROTO_DSA,
4169
		.ptp_support = true,
4170 4171 4172
		.ops = &mv88e6290_ops,
	},

4173
	[MV88E6320] = {
4174
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
4175 4176 4177 4178
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6320",
		.num_databases = 4096,
		.num_ports = 7,
4179
		.num_internal_phys = 5,
4180
		.num_gpio = 15,
4181
		.max_vid = 4095,
4182
		.port_base_addr = 0x10,
4183
		.phy_base_addr = 0x0,
4184
		.global1_addr = 0x1b,
4185
		.global2_addr = 0x1c,
4186
		.age_time_coeff = 15000,
4187
		.g1_irqs = 8,
4188
		.g2_irqs = 10,
4189
		.atu_move_port_mask = 0xf,
4190
		.pvt = true,
4191
		.multi_chip = true,
4192
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4193
		.ptp_support = true,
4194
		.ops = &mv88e6320_ops,
4195 4196 4197
	},

	[MV88E6321] = {
4198
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
4199 4200 4201 4202
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6321",
		.num_databases = 4096,
		.num_ports = 7,
4203
		.num_internal_phys = 5,
4204
		.num_gpio = 15,
4205
		.max_vid = 4095,
4206
		.port_base_addr = 0x10,
4207
		.phy_base_addr = 0x0,
4208
		.global1_addr = 0x1b,
4209
		.global2_addr = 0x1c,
4210
		.age_time_coeff = 15000,
4211
		.g1_irqs = 8,
4212
		.g2_irqs = 10,
4213
		.atu_move_port_mask = 0xf,
4214
		.multi_chip = true,
4215
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4216
		.ptp_support = true,
4217
		.ops = &mv88e6321_ops,
4218 4219
	},

4220
	[MV88E6341] = {
4221
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
4222 4223 4224
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
4225
		.num_internal_phys = 5,
4226
		.num_ports = 6,
4227
		.num_gpio = 11,
4228
		.max_vid = 4095,
4229
		.port_base_addr = 0x10,
4230
		.phy_base_addr = 0x10,
4231
		.global1_addr = 0x1b,
4232
		.global2_addr = 0x1c,
4233
		.age_time_coeff = 3750,
4234
		.atu_move_port_mask = 0x1f,
4235
		.g1_irqs = 9,
4236
		.g2_irqs = 10,
4237
		.pvt = true,
4238
		.multi_chip = true,
4239
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4240
		.ptp_support = true,
4241 4242 4243
		.ops = &mv88e6341_ops,
	},

4244
	[MV88E6350] = {
4245
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
4246 4247 4248 4249
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6350",
		.num_databases = 4096,
		.num_ports = 7,
4250
		.num_internal_phys = 5,
4251
		.max_vid = 4095,
4252
		.port_base_addr = 0x10,
4253
		.phy_base_addr = 0x0,
4254
		.global1_addr = 0x1b,
4255
		.global2_addr = 0x1c,
4256
		.age_time_coeff = 15000,
4257
		.g1_irqs = 9,
4258
		.g2_irqs = 10,
4259
		.atu_move_port_mask = 0xf,
4260
		.pvt = true,
4261
		.multi_chip = true,
4262
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4263
		.ops = &mv88e6350_ops,
4264 4265 4266
	},

	[MV88E6351] = {
4267
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
4268 4269 4270 4271
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6351",
		.num_databases = 4096,
		.num_ports = 7,
4272
		.num_internal_phys = 5,
4273
		.max_vid = 4095,
4274
		.port_base_addr = 0x10,
4275
		.phy_base_addr = 0x0,
4276
		.global1_addr = 0x1b,
4277
		.global2_addr = 0x1c,
4278
		.age_time_coeff = 15000,
4279
		.g1_irqs = 9,
4280
		.g2_irqs = 10,
4281
		.atu_move_port_mask = 0xf,
4282
		.pvt = true,
4283
		.multi_chip = true,
4284
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4285
		.ops = &mv88e6351_ops,
4286 4287 4288
	},

	[MV88E6352] = {
4289
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
4290 4291 4292 4293
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6352",
		.num_databases = 4096,
		.num_ports = 7,
4294
		.num_internal_phys = 5,
4295
		.num_gpio = 15,
4296
		.max_vid = 4095,
4297
		.port_base_addr = 0x10,
4298
		.phy_base_addr = 0x0,
4299
		.global1_addr = 0x1b,
4300
		.global2_addr = 0x1c,
4301
		.age_time_coeff = 15000,
4302
		.g1_irqs = 9,
4303
		.g2_irqs = 10,
4304
		.atu_move_port_mask = 0xf,
4305
		.pvt = true,
4306
		.multi_chip = true,
4307
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4308
		.ptp_support = true,
4309
		.ops = &mv88e6352_ops,
4310
	},
4311
	[MV88E6390] = {
4312
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
4313 4314 4315 4316
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4317
		.num_internal_phys = 11,
4318
		.num_gpio = 16,
4319
		.max_vid = 8191,
4320
		.port_base_addr = 0x0,
4321
		.phy_base_addr = 0x0,
4322
		.global1_addr = 0x1b,
4323
		.global2_addr = 0x1c,
4324
		.age_time_coeff = 3750,
4325
		.g1_irqs = 9,
4326
		.g2_irqs = 14,
4327
		.atu_move_port_mask = 0x1f,
4328
		.pvt = true,
4329
		.multi_chip = true,
4330
		.tag_protocol = DSA_TAG_PROTO_DSA,
4331
		.ptp_support = true,
4332 4333 4334
		.ops = &mv88e6390_ops,
	},
	[MV88E6390X] = {
4335
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
4336 4337 4338 4339
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4340
		.num_internal_phys = 11,
4341
		.num_gpio = 16,
4342
		.max_vid = 8191,
4343
		.port_base_addr = 0x0,
4344
		.phy_base_addr = 0x0,
4345
		.global1_addr = 0x1b,
4346
		.global2_addr = 0x1c,
4347
		.age_time_coeff = 3750,
4348
		.g1_irqs = 9,
4349
		.g2_irqs = 14,
4350
		.atu_move_port_mask = 0x1f,
4351
		.pvt = true,
4352
		.multi_chip = true,
4353
		.tag_protocol = DSA_TAG_PROTO_DSA,
4354
		.ptp_support = true,
4355 4356
		.ops = &mv88e6390x_ops,
	},
4357 4358
};

4359
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
4360
{
4361
	int i;
4362

4363 4364 4365
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
4366 4367 4368 4369

	return NULL;
}

4370
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
4371 4372
{
	const struct mv88e6xxx_info *info;
4373 4374 4375
	unsigned int prod_num, rev;
	u16 id;
	int err;
4376

4377
	mutex_lock(&chip->reg_lock);
4378
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
4379 4380 4381
	mutex_unlock(&chip->reg_lock);
	if (err)
		return err;
4382

4383 4384
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
4385 4386 4387 4388 4389

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

4390
	/* Update the compatible info with the probed one */
4391
	chip->info = info;
4392

4393 4394 4395 4396
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

4397 4398
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
4399 4400 4401 4402

	return 0;
}

4403
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
4404
{
4405
	struct mv88e6xxx_chip *chip;
4406

4407 4408
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
4409 4410
		return NULL;

4411
	chip->dev = dev;
4412

4413
	mutex_init(&chip->reg_lock);
4414
	INIT_LIST_HEAD(&chip->mdios);
4415

4416
	return chip;
4417 4418
}

4419
static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
4420 4421
			      struct mii_bus *bus, int sw_addr)
{
4422
	if (sw_addr == 0)
4423
		chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
4424
	else if (chip->info->multi_chip)
4425
		chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
4426 4427 4428
	else
		return -EINVAL;

4429 4430
	chip->bus = bus;
	chip->sw_addr = sw_addr;
4431 4432 4433 4434

	return 0;
}

4435 4436
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
							int port)
4437
{
V
Vivien Didelot 已提交
4438
	struct mv88e6xxx_chip *chip = ds->priv;
4439

4440
	return chip->info->tag_protocol;
4441 4442
}

4443
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
4444 4445 4446
static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
				       struct device *host_dev, int sw_addr,
				       void **priv)
4447
{
4448
	struct mv88e6xxx_chip *chip;
4449
	struct mii_bus *bus;
4450
	int err;
4451

4452
	bus = dsa_host_dev_to_mii_bus(host_dev);
4453 4454 4455
	if (!bus)
		return NULL;

4456 4457
	chip = mv88e6xxx_alloc_chip(dsa_dev);
	if (!chip)
4458 4459
		return NULL;

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

4463
	err = mv88e6xxx_smi_init(chip, bus, sw_addr);
4464 4465 4466
	if (err)
		goto free;

4467
	err = mv88e6xxx_detect(chip);
4468
	if (err)
4469
		goto free;
4470

4471 4472 4473 4474 4475 4476
	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_switch_reset(chip);
	mutex_unlock(&chip->reg_lock);
	if (err)
		goto free;

4477 4478
	mv88e6xxx_phy_init(chip);

4479
	err = mv88e6xxx_mdios_register(chip, NULL);
4480
	if (err)
4481
		goto free;
4482

4483
	*priv = chip;
4484

4485
	return chip->info->name;
4486
free:
4487
	devm_kfree(dsa_dev, chip);
4488 4489

	return NULL;
4490
}
4491
#endif
4492

4493
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4494
				      const struct switchdev_obj_port_mdb *mdb)
4495 4496 4497 4498 4499 4500 4501 4502 4503
{
	/* 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,
4504
				   const struct switchdev_obj_port_mdb *mdb)
4505
{
V
Vivien Didelot 已提交
4506
	struct mv88e6xxx_chip *chip = ds->priv;
4507 4508 4509

	mutex_lock(&chip->reg_lock);
	if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4510
					 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
4511 4512
		dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
			port);
4513 4514 4515 4516 4517 4518
	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 已提交
4519
	struct mv88e6xxx_chip *chip = ds->priv;
4520 4521 4522 4523
	int err;

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4524
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
4525 4526 4527 4528 4529
	mutex_unlock(&chip->reg_lock);

	return err;
}

4530
static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
4531
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
4532
	.probe			= mv88e6xxx_drv_probe,
4533
#endif
4534
	.get_tag_protocol	= mv88e6xxx_get_tag_protocol,
4535 4536
	.setup			= mv88e6xxx_setup,
	.adjust_link		= mv88e6xxx_adjust_link,
4537 4538 4539 4540 4541
	.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,
4542 4543 4544
	.get_strings		= mv88e6xxx_get_strings,
	.get_ethtool_stats	= mv88e6xxx_get_ethtool_stats,
	.get_sset_count		= mv88e6xxx_get_sset_count,
4545 4546
	.port_enable		= mv88e6xxx_port_enable,
	.port_disable		= mv88e6xxx_port_disable,
V
Vivien Didelot 已提交
4547 4548
	.get_mac_eee		= mv88e6xxx_get_mac_eee,
	.set_mac_eee		= mv88e6xxx_set_mac_eee,
4549
	.get_eeprom_len		= mv88e6xxx_get_eeprom_len,
4550 4551 4552 4553
	.get_eeprom		= mv88e6xxx_get_eeprom,
	.set_eeprom		= mv88e6xxx_set_eeprom,
	.get_regs_len		= mv88e6xxx_get_regs_len,
	.get_regs		= mv88e6xxx_get_regs,
4554
	.set_ageing_time	= mv88e6xxx_set_ageing_time,
4555 4556 4557
	.port_bridge_join	= mv88e6xxx_port_bridge_join,
	.port_bridge_leave	= mv88e6xxx_port_bridge_leave,
	.port_stp_state_set	= mv88e6xxx_port_stp_state_set,
4558
	.port_fast_age		= mv88e6xxx_port_fast_age,
4559 4560 4561 4562 4563 4564 4565
	.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,
4566 4567 4568
	.port_mdb_prepare       = mv88e6xxx_port_mdb_prepare,
	.port_mdb_add           = mv88e6xxx_port_mdb_add,
	.port_mdb_del           = mv88e6xxx_port_mdb_del,
4569 4570
	.crosschip_bridge_join	= mv88e6xxx_crosschip_bridge_join,
	.crosschip_bridge_leave	= mv88e6xxx_crosschip_bridge_leave,
4571 4572 4573 4574 4575
	.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,
4576 4577
};

4578 4579 4580 4581
static struct dsa_switch_driver mv88e6xxx_switch_drv = {
	.ops			= &mv88e6xxx_switch_ops,
};

4582
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
4583
{
4584
	struct device *dev = chip->dev;
4585 4586
	struct dsa_switch *ds;

4587
	ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
4588 4589 4590
	if (!ds)
		return -ENOMEM;

4591
	ds->priv = chip;
4592
	ds->dev = dev;
4593
	ds->ops = &mv88e6xxx_switch_ops;
4594 4595
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
4596 4597 4598

	dev_set_drvdata(dev, ds);

4599
	return dsa_register_switch(ds);
4600 4601
}

4602
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
4603
{
4604
	dsa_unregister_switch(chip->ds);
4605 4606
}

4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619
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;
}

4620
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
4621
{
4622
	struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
4623
	const struct mv88e6xxx_info *compat_info = NULL;
4624
	struct device *dev = &mdiodev->dev;
4625
	struct device_node *np = dev->of_node;
4626
	struct mv88e6xxx_chip *chip;
4627
	int port;
4628
	int err;
4629

4630 4631 4632
	if (!np && !pdata)
		return -EINVAL;

4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651
	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;
		}
	}

4652 4653 4654
	if (!compat_info)
		return -EINVAL;

4655
	chip = mv88e6xxx_alloc_chip(dev);
4656 4657 4658 4659
	if (!chip) {
		err = -ENOMEM;
		goto out;
	}
4660

4661
	chip->info = compat_info;
4662

4663
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
4664
	if (err)
4665
		goto out;
4666

4667
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4668 4669 4670 4671
	if (IS_ERR(chip->reset)) {
		err = PTR_ERR(chip->reset);
		goto out;
	}
4672

4673
	err = mv88e6xxx_detect(chip);
4674
	if (err)
4675
		goto out;
4676

4677 4678
	mv88e6xxx_phy_init(chip);

4679 4680 4681 4682 4683 4684 4685
	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;
	}
4686

4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698
	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;
	}

4699
	/* Has to be performed before the MDIO bus is created, because
4700
	 * the PHYs will link their interrupts to these interrupt
4701 4702 4703 4704
	 * controllers
	 */
	mutex_lock(&chip->reg_lock);
	if (chip->irq > 0)
4705
		err = mv88e6xxx_g1_irq_setup(chip);
4706 4707 4708
	else
		err = mv88e6xxx_irq_poll_setup(chip);
	mutex_unlock(&chip->reg_lock);
4709

4710 4711
	if (err)
		goto out;
4712

4713 4714
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
4715
		if (err)
4716
			goto out_g1_irq;
4717 4718
	}

4719 4720 4721 4722 4723 4724 4725 4726
	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;

4727
	err = mv88e6xxx_mdios_register(chip, np);
4728
	if (err)
4729
		goto out_g1_vtu_prob_irq;
4730

4731
	err = mv88e6xxx_register_switch(chip);
4732 4733
	if (err)
		goto out_mdio;
4734

4735
	return 0;
4736 4737

out_mdio:
4738
	mv88e6xxx_mdios_unregister(chip);
4739
out_g1_vtu_prob_irq:
4740
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
4741
out_g1_atu_prob_irq:
4742
	mv88e6xxx_g1_atu_prob_irq_free(chip);
4743
out_g2_irq:
4744
	if (chip->info->g2_irqs > 0)
4745 4746
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
4747
	if (chip->irq > 0)
4748
		mv88e6xxx_g1_irq_free(chip);
4749 4750
	else
		mv88e6xxx_irq_poll_free(chip);
4751
out:
4752 4753 4754
	if (pdata)
		dev_put(pdata->netdev);

4755
	return err;
4756
}
4757 4758 4759 4760

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

4763 4764
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
4765
		mv88e6xxx_ptp_free(chip);
4766
	}
4767

4768
	mv88e6xxx_phy_destroy(chip);
4769
	mv88e6xxx_unregister_switch(chip);
4770
	mv88e6xxx_mdios_unregister(chip);
4771

4772 4773 4774 4775 4776 4777 4778
	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)
4779
		mv88e6xxx_g1_irq_free(chip);
4780 4781
	else
		mv88e6xxx_irq_poll_free(chip);
4782 4783 4784
}

static const struct of_device_id mv88e6xxx_of_match[] = {
4785 4786 4787 4788
	{
		.compatible = "marvell,mv88e6085",
		.data = &mv88e6xxx_table[MV88E6085],
	},
4789 4790 4791 4792
	{
		.compatible = "marvell,mv88e6190",
		.data = &mv88e6xxx_table[MV88E6190],
	},
4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808
	{ /* 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,
	},
};

static int __init mv88e6xxx_init(void)
{
4809
	register_switch_driver(&mv88e6xxx_switch_drv);
4810 4811
	return mdio_driver_register(&mv88e6xxx_driver);
}
4812 4813 4814 4815
module_init(mv88e6xxx_init);

static void __exit mv88e6xxx_cleanup(void)
{
4816
	mdio_driver_unregister(&mv88e6xxx_driver);
4817
	unregister_switch_driver(&mv88e6xxx_switch_drv);
4818 4819
}
module_exit(mv88e6xxx_cleanup);
4820 4821 4822 4823

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