chip.c 139.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 | IRQF_SHARED,
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 582 583 584
static int mv88e6xxx_phy_is_internal(struct dsa_switch *ds, int port)
{
	struct mv88e6xxx_chip *chip = ds->priv;

	return port < chip->info->num_internal_phys;
}

585 586 587 588
/* 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.
 */
589 590
static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
				  struct phy_device *phydev)
591
{
V
Vivien Didelot 已提交
592
	struct mv88e6xxx_chip *chip = ds->priv;
593
	int err;
594

595 596
	if (!phy_is_pseudo_fixed_link(phydev) &&
	    mv88e6xxx_phy_is_internal(ds, port))
597 598
		return;

599
	mutex_lock(&chip->reg_lock);
600
	err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
601 602
				       phydev->duplex, phydev->pause,
				       phydev->interface);
603
	mutex_unlock(&chip->reg_lock);
604 605

	if (err && err != -EOPNOTSUPP)
606
		dev_err(ds->dev, "p%d: failed to configure MAC\n", port);
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 664 665 666 667 668 669 670 671
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);
}

672 673 674 675
static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
			       unsigned long *supported,
			       struct phylink_link_state *state)
{
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694
	__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);
695 696 697 698 699 700 701 702 703
}

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);
704 705 706 707
	if (chip->info->ops->port_link_state)
		err = chip->info->ops->port_link_state(chip, port, state);
	else
		err = -EOPNOTSUPP;
708 709 710 711 712 713 714 715 716 717
	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;
718
	int speed, duplex, link, pause, err;
719

720
	if ((mode == MLO_AN_PHY) && mv88e6xxx_phy_is_internal(ds, port))
721 722 723 724 725 726
		return;

	if (mode == MLO_AN_FIXED) {
		link = LINK_FORCED_UP;
		speed = state->speed;
		duplex = state->duplex;
727 728 729 730
	} else if (!mv88e6xxx_phy_is_internal(ds, port)) {
		link = state->link;
		speed = state->speed;
		duplex = state->duplex;
731 732 733 734 735
	} else {
		speed = SPEED_UNFORCED;
		duplex = DUPLEX_UNFORCED;
		link = LINK_UNFORCED;
	}
736
	pause = !!phylink_test(state->advertising, Pause);
737 738

	mutex_lock(&chip->reg_lock);
739
	err = mv88e6xxx_port_setup_mac(chip, port, link, speed, duplex, pause,
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775
				       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);
}

776
static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
777
{
778 779
	if (!chip->info->ops->stats_snapshot)
		return -EOPNOTSUPP;
780

781
	return chip->info->ops->stats_snapshot(chip, port);
782 783
}

784
static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
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 832 833 834 835 836 837 838 839 840 841 842 843
	{ "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, },
844 845
};

846
static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
847
					    struct mv88e6xxx_hw_stat *s,
848 849
					    int port, u16 bank1_select,
					    u16 histogram)
850 851 852
{
	u32 low;
	u32 high = 0;
853
	u16 reg = 0;
854
	int err;
855 856
	u64 value;

857
	switch (s->type) {
858
	case STATS_TYPE_PORT:
859 860
		err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
		if (err)
861
			return U64_MAX;
862

863
		low = reg;
864
		if (s->size == 4) {
865 866
			err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
			if (err)
867
				return U64_MAX;
868
			high = reg;
869
		}
870
		break;
871
	case STATS_TYPE_BANK1:
872
		reg = bank1_select;
873 874
		/* fall through */
	case STATS_TYPE_BANK0:
875
		reg |= s->reg | histogram;
876
		mv88e6xxx_g1_stats_read(chip, reg, &low);
877
		if (s->size == 8)
878
			mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
879 880
		break;
	default:
881
		return U64_MAX;
882 883 884 885 886
	}
	value = (((u64)high) << 16) | low;
	return value;
}

887 888
static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data, int types)
889
{
890 891
	struct mv88e6xxx_hw_stat *stat;
	int i, j;
892

893 894
	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
		stat = &mv88e6xxx_hw_stats[i];
895
		if (stat->type & types) {
896 897 898 899
			memcpy(data + j * ETH_GSTRING_LEN, stat->string,
			       ETH_GSTRING_LEN);
			j++;
		}
900
	}
901 902

	return j;
903 904
}

905 906
static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
907
{
908 909
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_PORT);
910 911
}

912 913
static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
914
{
915 916
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
917 918
}

919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936
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);
}

937
static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
938
				  u32 stringset, uint8_t *data)
939
{
V
Vivien Didelot 已提交
940
	struct mv88e6xxx_chip *chip = ds->priv;
941
	int count = 0;
942

943 944 945
	if (stringset != ETH_SS_STATS)
		return;

946 947
	mutex_lock(&chip->reg_lock);

948
	if (chip->info->ops->stats_get_strings)
949 950 951 952
		count = chip->info->ops->stats_get_strings(chip, data);

	if (chip->info->ops->serdes_get_strings) {
		data += count * ETH_GSTRING_LEN;
953
		count = chip->info->ops->serdes_get_strings(chip, port, data);
954
	}
955

956 957 958
	data += count * ETH_GSTRING_LEN;
	mv88e6xxx_atu_vtu_get_strings(data);

959
	mutex_unlock(&chip->reg_lock);
960 961 962 963 964
}

static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
					  int types)
{
965 966 967 968 969
	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];
970
		if (stat->type & types)
971 972 973
			j++;
	}
	return j;
974 975
}

976 977 978 979 980 981 982 983 984 985 986 987
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);
}

988
static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
989 990
{
	struct mv88e6xxx_chip *chip = ds->priv;
991 992
	int serdes_count = 0;
	int count = 0;
993

994 995 996
	if (sset != ETH_SS_STATS)
		return 0;

997
	mutex_lock(&chip->reg_lock);
998
	if (chip->info->ops->stats_get_sset_count)
999 1000 1001 1002 1003 1004 1005
		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);
1006
	if (serdes_count < 0) {
1007
		count = serdes_count;
1008 1009 1010 1011 1012
		goto out;
	}
	count += serdes_count;
	count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);

1013
out:
1014
	mutex_unlock(&chip->reg_lock);
1015

1016
	return count;
1017 1018
}

1019 1020 1021
static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data, int types,
				     u16 bank1_select, u16 histogram)
1022 1023 1024 1025 1026 1027 1028
{
	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) {
1029
			mutex_lock(&chip->reg_lock);
1030 1031 1032
			data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
							      bank1_select,
							      histogram);
1033 1034
			mutex_unlock(&chip->reg_lock);

1035 1036 1037
			j++;
		}
	}
1038
	return j;
1039 1040
}

1041 1042
static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
1043 1044
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
1045
					 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
1046
					 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1047 1048
}

1049 1050
static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
1051 1052
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
1053
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1054 1055
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
					 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1056 1057
}

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

1067 1068 1069 1070 1071 1072 1073 1074 1075 1076
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;
}

1077 1078 1079
static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
				uint64_t *data)
{
1080 1081
	int count = 0;

1082
	if (chip->info->ops->stats_get_stats)
1083 1084
		count = chip->info->ops->stats_get_stats(chip, port, data);

1085
	mutex_lock(&chip->reg_lock);
1086 1087
	if (chip->info->ops->serdes_get_stats) {
		data += count;
1088
		count = chip->info->ops->serdes_get_stats(chip, port, data);
1089
	}
1090 1091 1092
	data += count;
	mv88e6xxx_atu_vtu_get_stats(chip, port, data);
	mutex_unlock(&chip->reg_lock);
1093 1094
}

1095 1096
static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
					uint64_t *data)
1097
{
V
Vivien Didelot 已提交
1098
	struct mv88e6xxx_chip *chip = ds->priv;
1099 1100
	int ret;

1101
	mutex_lock(&chip->reg_lock);
1102

1103
	ret = mv88e6xxx_stats_snapshot(chip, port);
1104 1105 1106
	mutex_unlock(&chip->reg_lock);

	if (ret < 0)
1107
		return;
1108 1109

	mv88e6xxx_get_stats(chip, port, data);
1110

1111 1112
}

1113
static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
1114 1115 1116 1117
{
	return 32 * sizeof(u16);
}

1118 1119
static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
			       struct ethtool_regs *regs, void *_p)
1120
{
V
Vivien Didelot 已提交
1121
	struct mv88e6xxx_chip *chip = ds->priv;
1122 1123
	int err;
	u16 reg;
1124 1125 1126
	u16 *p = _p;
	int i;

1127
	regs->version = chip->info->prod_num;
1128 1129 1130

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

1131
	mutex_lock(&chip->reg_lock);
1132

1133 1134
	for (i = 0; i < 32; i++) {

1135 1136 1137
		err = mv88e6xxx_port_read(chip, port, i, &reg);
		if (!err)
			p[i] = reg;
1138
	}
1139

1140
	mutex_unlock(&chip->reg_lock);
1141 1142
}

V
Vivien Didelot 已提交
1143 1144
static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
1145
{
1146 1147
	/* Nothing to do on the port's MAC */
	return 0;
1148 1149
}

V
Vivien Didelot 已提交
1150 1151
static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
1152
{
1153 1154
	/* Nothing to do on the port's MAC */
	return 0;
1155 1156
}

1157
static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
1158
{
1159 1160 1161
	struct dsa_switch *ds = NULL;
	struct net_device *br;
	u16 pvlan;
1162 1163
	int i;

1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183
	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 已提交
1184
		    (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
1185 1186 1187 1188 1189
			pvlan |= BIT(i);

	return pvlan;
}

1190
static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
1191 1192
{
	u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
1193 1194 1195

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

1197
	return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
1198 1199
}

1200 1201
static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
					 u8 state)
1202
{
V
Vivien Didelot 已提交
1203
	struct mv88e6xxx_chip *chip = ds->priv;
1204
	int err;
1205

1206
	mutex_lock(&chip->reg_lock);
1207
	err = mv88e6xxx_port_set_state(chip, port, state);
1208
	mutex_unlock(&chip->reg_lock);
1209 1210

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

1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232
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;
}

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

1253 1254 1255 1256 1257 1258 1259
	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;
	}

1260 1261 1262 1263
	err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
	if (err)
		return err;

1264 1265 1266
	return 0;
}

1267 1268 1269 1270 1271 1272 1273 1274 1275
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;
}

1276 1277 1278 1279 1280 1281 1282 1283
static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->rmu_disable)
		return chip->info->ops->rmu_disable(chip);

	return 0;
}

1284 1285 1286 1287 1288 1289 1290 1291
static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->pot_clear)
		return chip->info->ops->pot_clear(chip);

	return 0;
}

1292 1293 1294 1295 1296 1297 1298 1299
static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->mgmt_rsvd2cpu)
		return chip->info->ops->mgmt_rsvd2cpu(chip);

	return 0;
}

1300 1301
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
1302 1303
	int err;

1304 1305 1306 1307
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

1308 1309 1310 1311
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

1312 1313 1314
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334
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;
}

1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347
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;
}

1348 1349 1350 1351 1352 1353 1354 1355 1356
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)
1357
		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1358 1359 1360 1361

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

1362 1363
static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
{
1364 1365 1366
	int dev, port;
	int err;

1367 1368 1369 1370 1371 1372
	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.
	 */
1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385
	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;
1386 1387
}

1388 1389 1390 1391 1392 1393
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);
1394
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1395 1396 1397
	mutex_unlock(&chip->reg_lock);

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

1401 1402 1403 1404 1405 1406 1407 1408
static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
{
	if (!chip->info->max_vid)
		return 0;

	return mv88e6xxx_g1_vtu_flush(chip);
}

1409 1410 1411 1412 1413 1414 1415 1416 1417
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);
}

1418 1419 1420 1421 1422 1423 1424 1425 1426
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);
}

1427
static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1428 1429
{
	DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1430 1431 1432
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = chip->info->max_vid,
	};
1433
	int i, err;
1434 1435 1436

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

1437
	/* Set every FID bit used by the (un)bridged ports */
1438
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1439
		err = mv88e6xxx_port_get_fid(chip, i, fid);
1440 1441 1442 1443 1444 1445
		if (err)
			return err;

		set_bit(*fid, fid_bitmap);
	}

1446 1447
	/* Set every FID bit used by the VLAN entries */
	do {
1448
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1449 1450 1451 1452 1453 1454 1455
		if (err)
			return err;

		if (!vlan.valid)
			break;

		set_bit(vlan.fid, fid_bitmap);
1456
	} while (vlan.vid < chip->info->max_vid);
1457 1458 1459 1460 1461

	/* 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);
1462
	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1463 1464 1465
		return -ENOSPC;

	/* Clear the database */
1466
	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1467 1468
}

1469 1470
static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
			     struct mv88e6xxx_vtu_entry *entry, bool new)
1471 1472 1473 1474 1475 1476
{
	int err;

	if (!vid)
		return -EINVAL;

1477 1478
	entry->vid = vid - 1;
	entry->valid = false;
1479

1480
	err = mv88e6xxx_vtu_getnext(chip, entry);
1481 1482 1483
	if (err)
		return err;

1484 1485
	if (entry->vid == vid && entry->valid)
		return 0;
1486

1487 1488 1489 1490 1491 1492 1493 1494
	if (new) {
		int i;

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

1495
		/* Exclude all ports */
1496
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1497
			entry->member[i] =
1498
				MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1499 1500

		return mv88e6xxx_atu_new(chip, &entry->fid);
1501 1502
	}

1503 1504
	/* switchdev expects -EOPNOTSUPP to honor software VLANs */
	return -EOPNOTSUPP;
1505 1506
}

1507 1508 1509
static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
					u16 vid_begin, u16 vid_end)
{
V
Vivien Didelot 已提交
1510
	struct mv88e6xxx_chip *chip = ds->priv;
1511 1512 1513
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = vid_begin - 1,
	};
1514 1515
	int i, err;

1516 1517 1518 1519
	/* 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;

1520 1521 1522
	if (!vid_begin)
		return -EOPNOTSUPP;

1523
	mutex_lock(&chip->reg_lock);
1524 1525

	do {
1526
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1527 1528 1529 1530 1531 1532 1533 1534 1535
		if (err)
			goto unlock;

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

1536
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1537 1538 1539
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

1540
			if (!ds->ports[i].slave)
1541 1542
				continue;

1543
			if (vlan.member[i] ==
1544
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1545 1546
				continue;

V
Vivien Didelot 已提交
1547
			if (dsa_to_port(ds, i)->bridge_dev ==
1548
			    ds->ports[port].bridge_dev)
1549 1550
				break; /* same bridge, check next VLAN */

V
Vivien Didelot 已提交
1551
			if (!dsa_to_port(ds, i)->bridge_dev)
1552 1553
				continue;

1554 1555
			dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
				port, vlan.vid, i,
V
Vivien Didelot 已提交
1556
				netdev_name(dsa_to_port(ds, i)->bridge_dev));
1557 1558 1559 1560 1561 1562
			err = -EOPNOTSUPP;
			goto unlock;
		}
	} while (vlan.vid < vid_end);

unlock:
1563
	mutex_unlock(&chip->reg_lock);
1564 1565 1566 1567

	return err;
}

1568 1569
static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
					 bool vlan_filtering)
1570
{
V
Vivien Didelot 已提交
1571
	struct mv88e6xxx_chip *chip = ds->priv;
1572 1573
	u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
		MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
1574
	int err;
1575

1576
	if (!chip->info->max_vid)
1577 1578
		return -EOPNOTSUPP;

1579
	mutex_lock(&chip->reg_lock);
1580
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1581
	mutex_unlock(&chip->reg_lock);
1582

1583
	return err;
1584 1585
}

1586 1587
static int
mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1588
			    const struct switchdev_obj_port_vlan *vlan)
1589
{
V
Vivien Didelot 已提交
1590
	struct mv88e6xxx_chip *chip = ds->priv;
1591 1592
	int err;

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

1596 1597 1598 1599 1600 1601 1602 1603
	/* 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;

1604 1605 1606 1607 1608 1609
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */
	return 0;
}

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 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653
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);
}

1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676
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;
}

1677
static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
1678
				    u16 vid, u8 member)
1679
{
1680
	struct mv88e6xxx_vtu_entry vlan;
1681 1682
	int err;

1683
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
1684
	if (err)
1685
		return err;
1686

1687
	vlan.member[port] = member;
1688

1689 1690 1691 1692 1693
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
	if (err)
		return err;

	return mv88e6xxx_broadcast_setup(chip, vid);
1694 1695
}

1696
static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1697
				    const struct switchdev_obj_port_vlan *vlan)
1698
{
V
Vivien Didelot 已提交
1699
	struct mv88e6xxx_chip *chip = ds->priv;
1700 1701
	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1702
	u8 member;
1703 1704
	u16 vid;

1705
	if (!chip->info->max_vid)
1706 1707
		return;

1708
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1709
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1710
	else if (untagged)
1711
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
1712
	else
1713
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
1714

1715
	mutex_lock(&chip->reg_lock);
1716

1717
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
1718
		if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
1719 1720
			dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
				vid, untagged ? 'u' : 't');
1721

1722
	if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1723 1724
		dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
			vlan->vid_end);
1725

1726
	mutex_unlock(&chip->reg_lock);
1727 1728
}

1729
static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
1730
				    int port, u16 vid)
1731
{
1732
	struct mv88e6xxx_vtu_entry vlan;
1733 1734
	int i, err;

1735
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1736
	if (err)
1737
		return err;
1738

1739
	/* Tell switchdev if this VLAN is handled in software */
1740
	if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1741
		return -EOPNOTSUPP;
1742

1743
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1744 1745

	/* keep the VLAN unless all ports are excluded */
1746
	vlan.valid = false;
1747
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1748 1749
		if (vlan.member[i] !=
		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
1750
			vlan.valid = true;
1751 1752 1753 1754
			break;
		}
	}

1755
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1756 1757 1758
	if (err)
		return err;

1759
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
1760 1761
}

1762 1763
static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
				   const struct switchdev_obj_port_vlan *vlan)
1764
{
V
Vivien Didelot 已提交
1765
	struct mv88e6xxx_chip *chip = ds->priv;
1766 1767 1768
	u16 pvid, vid;
	int err = 0;

1769
	if (!chip->info->max_vid)
1770 1771
		return -EOPNOTSUPP;

1772
	mutex_lock(&chip->reg_lock);
1773

1774
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
1775 1776 1777
	if (err)
		goto unlock;

1778
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1779
		err = _mv88e6xxx_port_vlan_del(chip, port, vid);
1780 1781 1782 1783
		if (err)
			goto unlock;

		if (vid == pvid) {
1784
			err = mv88e6xxx_port_set_pvid(chip, port, 0);
1785 1786 1787 1788 1789
			if (err)
				goto unlock;
		}
	}

1790
unlock:
1791
	mutex_unlock(&chip->reg_lock);
1792 1793 1794 1795

	return err;
}

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

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

	return err;
1808 1809
}

1810
static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1811
				  const unsigned char *addr, u16 vid)
1812
{
V
Vivien Didelot 已提交
1813
	struct mv88e6xxx_chip *chip = ds->priv;
1814
	int err;
1815

1816
	mutex_lock(&chip->reg_lock);
1817
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1818
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
1819
	mutex_unlock(&chip->reg_lock);
1820

1821
	return err;
1822 1823
}

1824 1825
static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
				      u16 fid, u16 vid, int port,
1826
				      dsa_fdb_dump_cb_t *cb, void *data)
1827
{
1828
	struct mv88e6xxx_atu_entry addr;
1829
	bool is_static;
1830 1831
	int err;

1832
	addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1833
	eth_broadcast_addr(addr.mac);
1834 1835

	do {
1836
		mutex_lock(&chip->reg_lock);
1837
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
1838
		mutex_unlock(&chip->reg_lock);
1839
		if (err)
1840
			return err;
1841

1842
		if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
1843 1844
			break;

1845
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
1846 1847
			continue;

1848 1849
		if (!is_unicast_ether_addr(addr.mac))
			continue;
1850

1851 1852 1853
		is_static = (addr.state ==
			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
		err = cb(addr.mac, vid, is_static, data);
1854 1855
		if (err)
			return err;
1856 1857 1858 1859 1860
	} while (!is_broadcast_ether_addr(addr.mac));

	return err;
}

1861
static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1862
				  dsa_fdb_dump_cb_t *cb, void *data)
1863
{
1864
	struct mv88e6xxx_vtu_entry vlan = {
1865
		.vid = chip->info->max_vid,
1866
	};
1867
	u16 fid;
1868 1869
	int err;

1870
	/* Dump port's default Filtering Information Database (VLAN ID 0) */
1871
	mutex_lock(&chip->reg_lock);
1872
	err = mv88e6xxx_port_get_fid(chip, port, &fid);
1873 1874
	mutex_unlock(&chip->reg_lock);

1875
	if (err)
1876
		return err;
1877

1878
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
1879
	if (err)
1880
		return err;
1881

1882
	/* Dump VLANs' Filtering Information Databases */
1883
	do {
1884
		mutex_lock(&chip->reg_lock);
1885
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1886
		mutex_unlock(&chip->reg_lock);
1887
		if (err)
1888
			return err;
1889 1890 1891 1892

		if (!vlan.valid)
			break;

1893
		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1894
						 cb, data);
1895
		if (err)
1896
			return err;
1897
	} while (vlan.vid < chip->info->max_vid);
1898

1899 1900 1901 1902
	return err;
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1903
				   dsa_fdb_dump_cb_t *cb, void *data)
1904
{
V
Vivien Didelot 已提交
1905
	struct mv88e6xxx_chip *chip = ds->priv;
1906

1907
	return mv88e6xxx_port_db_dump(chip, port, cb, data);
1908 1909
}

1910 1911
static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
				struct net_device *br)
1912
{
1913
	struct dsa_switch *ds;
1914
	int port;
1915
	int dev;
1916
	int err;
1917

1918 1919 1920 1921
	/* 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);
1922
			if (err)
1923
				return err;
1924 1925 1926
		}
	}

1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944
	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;
			}
		}
	}

1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955
	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);
1956
	mutex_unlock(&chip->reg_lock);
1957

1958
	return err;
1959 1960
}

1961 1962
static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
					struct net_device *br)
1963
{
V
Vivien Didelot 已提交
1964
	struct mv88e6xxx_chip *chip = ds->priv;
1965

1966
	mutex_lock(&chip->reg_lock);
1967 1968 1969
	if (mv88e6xxx_bridge_map(chip, br) ||
	    mv88e6xxx_port_vlan_map(chip, port))
		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
1970
	mutex_unlock(&chip->reg_lock);
1971 1972
}

1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002
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);
}

2003 2004 2005 2006 2007 2008 2009 2010
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->reset)
		return chip->info->ops->reset(chip);

	return 0;
}

2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023
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);
	}
}

2024
static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2025
{
2026
	int i, err;
2027

2028
	/* Set all ports to the Disabled state */
2029
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2030
		err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
2031 2032
		if (err)
			return err;
2033 2034
	}

2035 2036 2037
	/* Wait for transmit queues to drain,
	 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
	 */
2038 2039
	usleep_range(2000, 4000);

2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050
	return 0;
}

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

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

2051
	mv88e6xxx_hardware_reset(chip);
2052

2053
	return mv88e6xxx_software_reset(chip);
2054 2055
}

2056
static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
2057 2058
				   enum mv88e6xxx_frame_mode frame,
				   enum mv88e6xxx_egress_mode egress, u16 etype)
2059 2060 2061
{
	int err;

2062 2063 2064 2065
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
2066 2067 2068
	if (err)
		return err;

2069 2070 2071 2072 2073 2074 2075 2076
	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;
2077 2078
}

2079
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2080
{
2081
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
2082
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2083
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2084
}
2085

2086 2087 2088
static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
2089
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2090
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2091
}
2092

2093 2094 2095 2096
static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port,
				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
2097 2098
				       MV88E6XXX_EGRESS_MODE_ETHERTYPE,
				       ETH_P_EDSA);
2099
}
2100

2101 2102 2103 2104
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);
2105

2106
	if (dsa_is_user_port(chip->ds, port))
2107
		return mv88e6xxx_set_port_mode_normal(chip, port);
2108

2109 2110 2111
	/* 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);
2112

2113 2114
	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
		return mv88e6xxx_set_port_mode_edsa(chip, port);
2115

2116
	return -EINVAL;
2117 2118
}

2119
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2120
{
2121
	bool message = dsa_is_dsa_port(chip->ds, port);
2122

2123
	return mv88e6xxx_port_set_message_port(chip, port, message);
2124
}
2125

2126
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2127
{
2128 2129
	struct dsa_switch *ds = chip->ds;
	bool flood;
2130

2131
	/* Upstream ports flood frames with unknown unicast or multicast DA */
2132
	flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
2133 2134 2135
	if (chip->info->ops->port_set_egress_floods)
		return chip->info->ops->port_set_egress_floods(chip, port,
							       flood, flood);
2136

2137
	return 0;
2138 2139
}

2140 2141 2142
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
2143 2144
	if (chip->info->ops->serdes_power)
		return chip->info->ops->serdes_power(chip, port, on);
2145

2146
	return 0;
2147 2148
}

2149 2150 2151 2152 2153 2154
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

2155
	upstream_port = dsa_upstream_port(ds, port);
2156 2157 2158 2159 2160 2161 2162
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178
	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;
		}
	}

2179 2180 2181
	return 0;
}

2182
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
2183
{
2184
	struct dsa_switch *ds = chip->ds;
2185
	int err;
2186
	u16 reg;
2187

2188 2189 2190
	chip->ports[port].chip = chip;
	chip->ports[port].port = port;

2191 2192 2193 2194 2195 2196 2197
	/* 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,
2198
					       PAUSE_OFF,
2199 2200 2201 2202
					       PHY_INTERFACE_MODE_NA);
	else
		err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
					       SPEED_UNFORCED, DUPLEX_UNFORCED,
2203
					       PAUSE_ON,
2204 2205 2206
					       PHY_INTERFACE_MODE_NA);
	if (err)
		return err;
2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221

	/* 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.
	 */
2222 2223 2224 2225
	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);
2226 2227
	if (err)
		return err;
2228

2229
	err = mv88e6xxx_setup_port_mode(chip, port);
2230 2231
	if (err)
		return err;
2232

2233
	err = mv88e6xxx_setup_egress_floods(chip, port);
2234 2235 2236
	if (err)
		return err;

2237 2238 2239
	/* 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.
2240
	 */
2241 2242 2243 2244 2245
	if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
		err = mv88e6xxx_serdes_power(chip, port, true);
		if (err)
			return err;
	}
2246

2247
	/* Port Control 2: don't force a good FCS, set the maximum frame size to
2248
	 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
2249 2250 2251
	 * 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.
2252
	 */
2253 2254 2255
	err = mv88e6xxx_port_set_map_da(chip, port);
	if (err)
		return err;
2256

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

2261
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
2262
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
2263 2264 2265
	if (err)
		return err;

2266 2267
	if (chip->info->ops->port_set_jumbo_size) {
		err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
2268 2269 2270 2271
		if (err)
			return err;
	}

2272 2273 2274 2275 2276
	/* 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.
	 */
2277
	reg = 1 << port;
2278 2279
	/* Disable learning for CPU port */
	if (dsa_is_cpu_port(ds, port))
2280
		reg = 0;
2281

2282 2283
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
2284 2285
	if (err)
		return err;
2286 2287

	/* Egress rate control 2: disable egress rate control. */
2288 2289
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
				   0x0000);
2290 2291
	if (err)
		return err;
2292

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

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

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

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

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

2323
	err = mv88e6xxx_setup_message_port(chip, port);
2324 2325
	if (err)
		return err;
2326

2327
	/* Port based VLAN map: give each port the same default address
2328 2329
	 * database, and allow bidirectional communication between the
	 * CPU and DSA port(s), and the other ports.
2330
	 */
2331
	err = mv88e6xxx_port_set_fid(chip, port, 0);
2332 2333
	if (err)
		return err;
2334

2335
	err = mv88e6xxx_port_vlan_map(chip, port);
2336 2337
	if (err)
		return err;
2338 2339 2340 2341

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

2345 2346 2347 2348
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
2349
	int err;
2350 2351

	mutex_lock(&chip->reg_lock);
2352

2353
	err = mv88e6xxx_serdes_power(chip, port, true);
2354 2355 2356 2357

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

2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368
	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);
2369 2370 2371 2372

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

2373 2374
	if (mv88e6xxx_serdes_power(chip, port, false))
		dev_err(chip->dev, "failed to power off SERDES\n");
2375

2376 2377 2378
	mutex_unlock(&chip->reg_lock);
}

2379 2380 2381
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
2382
	struct mv88e6xxx_chip *chip = ds->priv;
2383 2384 2385
	int err;

	mutex_lock(&chip->reg_lock);
2386
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2387 2388 2389 2390 2391
	mutex_unlock(&chip->reg_lock);

	return err;
}

2392
static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
2393
{
2394
	int err;
2395

2396
	/* Initialize the statistics unit */
2397 2398 2399 2400 2401
	if (chip->info->ops->stats_set_histogram) {
		err = chip->info->ops->stats_set_histogram(chip);
		if (err)
			return err;
	}
2402

2403
	return mv88e6xxx_g1_stats_clear(chip);
2404 2405
}

2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506
/* The mv88e6390 has some hidden registers used for debug and
 * development. The errata also makes use of them.
 */
static int mv88e6390_hidden_write(struct mv88e6xxx_chip *chip, int port,
				  int reg, u16 val)
{
	u16 ctrl;
	int err;

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

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

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

static int mv88e6390_hidden_wait(struct mv88e6xxx_chip *chip)
{
	return mv88e6xxx_wait(chip, PORT_RESERVED_1A_CTRL_PORT,
			      PORT_RESERVED_1A, PORT_RESERVED_1A_BUSY);
}


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

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

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

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

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

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

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

	return true;
}

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

	if (mv88e6390_setup_errata_applied(chip))
		return 0;

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

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

	return mv88e6xxx_software_reset(chip);
}

2507
static int mv88e6xxx_setup(struct dsa_switch *ds)
2508
{
V
Vivien Didelot 已提交
2509
	struct mv88e6xxx_chip *chip = ds->priv;
2510
	u8 cmode;
2511
	int err;
2512 2513
	int i;

2514
	chip->ds = ds;
2515
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
2516

2517
	mutex_lock(&chip->reg_lock);
2518

2519 2520 2521 2522 2523 2524
	if (chip->info->ops->setup_errata) {
		err = chip->info->ops->setup_errata(chip);
		if (err)
			goto unlock;
	}

2525 2526 2527 2528 2529
	/* 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)
2530
				goto unlock;
2531 2532 2533 2534 2535

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

2536
	/* Setup Switch Port Registers */
2537
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2538 2539 2540
		if (dsa_is_unused_port(ds, i))
			continue;

2541 2542 2543 2544 2545
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

2546 2547 2548 2549
	err = mv88e6xxx_irl_setup(chip);
	if (err)
		goto unlock;

2550 2551 2552 2553
	err = mv88e6xxx_mac_setup(chip);
	if (err)
		goto unlock;

2554 2555 2556 2557
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

2558 2559 2560 2561
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

2562 2563 2564 2565
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

2566 2567 2568 2569
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

2570 2571 2572 2573
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

2574 2575 2576 2577
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

2578 2579 2580 2581
	err = mv88e6xxx_rmu_setup(chip);
	if (err)
		goto unlock;

2582 2583 2584
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
2585

2586 2587 2588 2589
	err = mv88e6xxx_trunk_setup(chip);
	if (err)
		goto unlock;

2590 2591 2592 2593
	err = mv88e6xxx_devmap_setup(chip);
	if (err)
		goto unlock;

2594 2595 2596 2597
	err = mv88e6xxx_pri_setup(chip);
	if (err)
		goto unlock;

2598
	/* Setup PTP Hardware Clock and timestamping */
2599 2600 2601 2602
	if (chip->info->ptp_support) {
		err = mv88e6xxx_ptp_setup(chip);
		if (err)
			goto unlock;
2603 2604 2605 2606

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
2607 2608
	}

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

2613
unlock:
2614
	mutex_unlock(&chip->reg_lock);
2615

2616
	return err;
2617 2618
}

2619
static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
2620
{
2621 2622
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2623 2624
	u16 val;
	int err;
2625

2626 2627 2628
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

2629
	mutex_lock(&chip->reg_lock);
2630
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
2631
	mutex_unlock(&chip->reg_lock);
2632

2633
	if (reg == MII_PHYSID2) {
2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649
		/* Some internal PHYs don't have a model number. */
		if (chip->info->family != MV88E6XXX_FAMILY_6165)
			/* Then there is the 6165 family. It gets is
			 * PHYs correct. But it can also have two
			 * SERDES interfaces in the PHY address
			 * space. And these don't have a model
			 * number. But they are not PHYs, so we don't
			 * want to give them something a PHY driver
			 * will recognise.
			 *
			 * Use the mv88e6390 family model number
			 * instead, for anything which really could be
			 * a PHY,
			 */
			if (!(val & 0x3f0))
				val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
2650 2651
	}

2652
	return err ? err : val;
2653 2654
}

2655
static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
2656
{
2657 2658
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2659
	int err;
2660

2661 2662 2663
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

2664
	mutex_lock(&chip->reg_lock);
2665
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
2666
	mutex_unlock(&chip->reg_lock);
2667 2668

	return err;
2669 2670
}

2671
static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
2672 2673
				   struct device_node *np,
				   bool external)
2674 2675
{
	static int index;
2676
	struct mv88e6xxx_mdio_bus *mdio_bus;
2677 2678 2679
	struct mii_bus *bus;
	int err;

2680 2681 2682 2683 2684 2685 2686 2687 2688
	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;
	}

2689
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
2690 2691 2692
	if (!bus)
		return -ENOMEM;

2693
	mdio_bus = bus->priv;
2694
	mdio_bus->bus = bus;
2695
	mdio_bus->chip = chip;
2696 2697
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
2698

2699 2700
	if (np) {
		bus->name = np->full_name;
2701
		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
2702 2703 2704 2705 2706 2707 2708
	} 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;
2709
	bus->parent = chip->dev;
2710

2711 2712 2713 2714 2715 2716
	if (!external) {
		err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
		if (err)
			return err;
	}

2717
	err = of_mdiobus_register(bus, np);
2718
	if (err) {
2719
		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
2720
		mv88e6xxx_g2_irq_mdio_free(chip, bus);
2721
		return err;
2722
	}
2723 2724 2725 2726 2727

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

	return 0;
2730
}
2731

2732 2733 2734 2735 2736
static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
	{ .compatible = "marvell,mv88e6xxx-mdio-external",
	  .data = (void *)true },
	{ },
};
2737

2738 2739 2740 2741 2742 2743 2744 2745 2746
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;

2747 2748 2749
		if (!mdio_bus->external)
			mv88e6xxx_g2_irq_mdio_free(chip, bus);

2750 2751 2752 2753
		mdiobus_unregister(bus);
	}
}

2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777
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);
2778 2779
			if (err) {
				mv88e6xxx_mdios_unregister(chip);
2780
				return err;
2781
			}
2782 2783 2784 2785
		}
	}

	return 0;
2786 2787
}

2788 2789
static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
2790
	struct mv88e6xxx_chip *chip = ds->priv;
2791 2792 2793 2794 2795 2796 2797

	return chip->eeprom_len;
}

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

2801 2802
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
2803

2804 2805
	mutex_lock(&chip->reg_lock);
	err = chip->info->ops->get_eeprom(chip, eeprom, data);
2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818
	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 已提交
2819
	struct mv88e6xxx_chip *chip = ds->priv;
2820 2821
	int err;

2822 2823 2824
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

2825 2826 2827 2828
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

	mutex_lock(&chip->reg_lock);
2829
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
2830 2831 2832 2833 2834
	mutex_unlock(&chip->reg_lock);

	return err;
}

2835
static const struct mv88e6xxx_ops mv88e6085_ops = {
2836
	/* MV88E6XXX_FAMILY_6097 */
2837 2838
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2839
	.irl_init_all = mv88e6352_g2_irl_init_all,
2840
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2841 2842
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2843
	.port_set_link = mv88e6xxx_port_set_link,
2844
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2845
	.port_set_speed = mv88e6185_port_set_speed,
2846
	.port_tag_remap = mv88e6095_port_tag_remap,
2847
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2848
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2849
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2850
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2851
	.port_pause_limit = mv88e6097_port_pause_limit,
2852
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2853
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2854
	.port_link_state = mv88e6352_port_link_state,
2855
	.port_get_cmode = mv88e6185_port_get_cmode,
2856
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2857
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2858 2859
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2860
	.stats_get_stats = mv88e6095_stats_get_stats,
2861 2862
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2863
	.watchdog_ops = &mv88e6097_watchdog_ops,
2864
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2865
	.pot_clear = mv88e6xxx_g2_pot_clear,
2866 2867
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2868
	.reset = mv88e6185_g1_reset,
2869
	.rmu_disable = mv88e6085_g1_rmu_disable,
2870
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2871
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2872
	.phylink_validate = mv88e6185_phylink_validate,
2873 2874 2875
};

static const struct mv88e6xxx_ops mv88e6095_ops = {
2876
	/* MV88E6XXX_FAMILY_6095 */
2877 2878
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2879
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2880 2881
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2882
	.port_set_link = mv88e6xxx_port_set_link,
2883
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2884
	.port_set_speed = mv88e6185_port_set_speed,
2885
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2886
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2887
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2888
	.port_link_state = mv88e6185_port_link_state,
2889
	.port_get_cmode = mv88e6185_port_get_cmode,
2890
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2891
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2892 2893
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2894
	.stats_get_stats = mv88e6095_stats_get_stats,
2895
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2896 2897
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2898
	.reset = mv88e6185_g1_reset,
2899
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2900
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2901
	.phylink_validate = mv88e6185_phylink_validate,
2902 2903
};

2904
static const struct mv88e6xxx_ops mv88e6097_ops = {
2905
	/* MV88E6XXX_FAMILY_6097 */
2906 2907
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2908
	.irl_init_all = mv88e6352_g2_irl_init_all,
2909 2910 2911 2912 2913 2914
	.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,
2915
	.port_tag_remap = mv88e6095_port_tag_remap,
2916
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2917
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2918
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2919
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2920
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
2921
	.port_pause_limit = mv88e6097_port_pause_limit,
2922
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2923
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2924
	.port_link_state = mv88e6352_port_link_state,
2925
	.port_get_cmode = mv88e6185_port_get_cmode,
2926
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2927
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2928 2929 2930
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
	.stats_get_stats = mv88e6095_stats_get_stats,
2931 2932
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2933
	.watchdog_ops = &mv88e6097_watchdog_ops,
2934
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2935
	.pot_clear = mv88e6xxx_g2_pot_clear,
2936
	.reset = mv88e6352_g1_reset,
2937
	.rmu_disable = mv88e6085_g1_rmu_disable,
2938
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2939
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2940
	.phylink_validate = mv88e6185_phylink_validate,
2941 2942
};

2943
static const struct mv88e6xxx_ops mv88e6123_ops = {
2944
	/* MV88E6XXX_FAMILY_6165 */
2945 2946
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2947
	.irl_init_all = mv88e6352_g2_irl_init_all,
2948
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2949 2950
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2951
	.port_set_link = mv88e6xxx_port_set_link,
2952
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2953
	.port_set_speed = mv88e6185_port_set_speed,
2954
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2955
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2956
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2957
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2958
	.port_link_state = mv88e6352_port_link_state,
2959
	.port_get_cmode = mv88e6185_port_get_cmode,
2960
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2961
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2962 2963
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2964
	.stats_get_stats = mv88e6095_stats_get_stats,
2965 2966
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2967
	.watchdog_ops = &mv88e6097_watchdog_ops,
2968
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2969
	.pot_clear = mv88e6xxx_g2_pot_clear,
2970
	.reset = mv88e6352_g1_reset,
2971
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2972
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2973
	.phylink_validate = mv88e6185_phylink_validate,
2974 2975 2976
};

static const struct mv88e6xxx_ops mv88e6131_ops = {
2977
	/* MV88E6XXX_FAMILY_6185 */
2978 2979
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2980
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2981 2982
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2983
	.port_set_link = mv88e6xxx_port_set_link,
2984
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2985
	.port_set_speed = mv88e6185_port_set_speed,
2986
	.port_tag_remap = mv88e6095_port_tag_remap,
2987
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2988
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2989
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2990
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2991
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2992
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2993
	.port_pause_limit = mv88e6097_port_pause_limit,
2994
	.port_set_pause = mv88e6185_port_set_pause,
2995
	.port_link_state = mv88e6352_port_link_state,
2996
	.port_get_cmode = mv88e6185_port_get_cmode,
2997
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2998
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2999 3000
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3001
	.stats_get_stats = mv88e6095_stats_get_stats,
3002 3003
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3004
	.watchdog_ops = &mv88e6097_watchdog_ops,
3005
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3006
	.ppu_enable = mv88e6185_g1_ppu_enable,
3007
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
3008
	.ppu_disable = mv88e6185_g1_ppu_disable,
3009
	.reset = mv88e6185_g1_reset,
3010
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3011
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3012
	.phylink_validate = mv88e6185_phylink_validate,
3013 3014
};

3015 3016
static const struct mv88e6xxx_ops mv88e6141_ops = {
	/* MV88E6XXX_FAMILY_6341 */
3017 3018
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3019
	.irl_init_all = mv88e6352_g2_irl_init_all,
3020 3021 3022 3023 3024 3025 3026 3027
	.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,
3028
	.port_set_speed = mv88e6341_port_set_speed,
3029 3030 3031 3032
	.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,
3033
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3034
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3035
	.port_pause_limit = mv88e6097_port_pause_limit,
3036 3037
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3038
	.port_link_state = mv88e6352_port_link_state,
3039
	.port_get_cmode = mv88e6352_port_get_cmode,
3040
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3041
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3042 3043 3044
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
3045 3046
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3047 3048
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
3049
	.pot_clear = mv88e6xxx_g2_pot_clear,
3050
	.reset = mv88e6352_g1_reset,
3051
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3052
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3053
	.serdes_power = mv88e6341_serdes_power,
3054
	.gpio_ops = &mv88e6352_gpio_ops,
3055
	.phylink_validate = mv88e6390_phylink_validate,
3056 3057
};

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

static const struct mv88e6xxx_ops mv88e6165_ops = {
3099
	/* MV88E6XXX_FAMILY_6165 */
3100 3101
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3102
	.irl_init_all = mv88e6352_g2_irl_init_all,
3103
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3104 3105
	.phy_read = mv88e6165_phy_read,
	.phy_write = mv88e6165_phy_write,
3106
	.port_set_link = mv88e6xxx_port_set_link,
3107
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3108
	.port_set_speed = mv88e6185_port_set_speed,
3109
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3110
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3111
	.port_link_state = mv88e6352_port_link_state,
3112
	.port_get_cmode = mv88e6185_port_get_cmode,
3113
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3114
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3115 3116
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3117
	.stats_get_stats = mv88e6095_stats_get_stats,
3118 3119
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3120
	.watchdog_ops = &mv88e6097_watchdog_ops,
3121
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3122
	.pot_clear = mv88e6xxx_g2_pot_clear,
3123
	.reset = mv88e6352_g1_reset,
3124
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3125
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3126
	.avb_ops = &mv88e6165_avb_ops,
3127
	.ptp_ops = &mv88e6165_ptp_ops,
3128
	.phylink_validate = mv88e6185_phylink_validate,
3129 3130 3131
};

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

static const struct mv88e6xxx_ops mv88e6172_ops = {
3171
	/* MV88E6XXX_FAMILY_6352 */
3172 3173
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3174
	.irl_init_all = mv88e6352_g2_irl_init_all,
3175 3176
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3177
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3178 3179
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3180
	.port_set_link = mv88e6xxx_port_set_link,
3181
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3182
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3183
	.port_set_speed = mv88e6352_port_set_speed,
3184
	.port_tag_remap = mv88e6095_port_tag_remap,
3185
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3186
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3187
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3188
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3189
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3190
	.port_pause_limit = mv88e6097_port_pause_limit,
3191
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3192
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3193
	.port_link_state = mv88e6352_port_link_state,
3194
	.port_get_cmode = mv88e6352_port_get_cmode,
3195
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3196
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3197 3198
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3199
	.stats_get_stats = mv88e6095_stats_get_stats,
3200 3201
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3202
	.watchdog_ops = &mv88e6097_watchdog_ops,
3203
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3204
	.pot_clear = mv88e6xxx_g2_pot_clear,
3205
	.reset = mv88e6352_g1_reset,
3206
	.rmu_disable = mv88e6352_g1_rmu_disable,
3207
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3208
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3209
	.serdes_power = mv88e6352_serdes_power,
3210
	.gpio_ops = &mv88e6352_gpio_ops,
3211
	.phylink_validate = mv88e6352_phylink_validate,
3212 3213 3214
};

static const struct mv88e6xxx_ops mv88e6175_ops = {
3215
	/* MV88E6XXX_FAMILY_6351 */
3216 3217
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3218
	.irl_init_all = mv88e6352_g2_irl_init_all,
3219
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3220 3221
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3222
	.port_set_link = mv88e6xxx_port_set_link,
3223
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3224
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3225
	.port_set_speed = mv88e6185_port_set_speed,
3226
	.port_tag_remap = mv88e6095_port_tag_remap,
3227
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3228
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3229
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3230
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3231
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3232
	.port_pause_limit = mv88e6097_port_pause_limit,
3233
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3234
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3235
	.port_link_state = mv88e6352_port_link_state,
3236
	.port_get_cmode = mv88e6352_port_get_cmode,
3237
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3238
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3239 3240
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3241
	.stats_get_stats = mv88e6095_stats_get_stats,
3242 3243
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3244
	.watchdog_ops = &mv88e6097_watchdog_ops,
3245
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3246
	.pot_clear = mv88e6xxx_g2_pot_clear,
3247
	.reset = mv88e6352_g1_reset,
3248
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3249
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3250
	.phylink_validate = mv88e6185_phylink_validate,
3251 3252 3253
};

static const struct mv88e6xxx_ops mv88e6176_ops = {
3254
	/* MV88E6XXX_FAMILY_6352 */
3255 3256
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3257
	.irl_init_all = mv88e6352_g2_irl_init_all,
3258 3259
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3260
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3261 3262
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3263
	.port_set_link = mv88e6xxx_port_set_link,
3264
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3265
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3266
	.port_set_speed = mv88e6352_port_set_speed,
3267
	.port_tag_remap = mv88e6095_port_tag_remap,
3268
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3269
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3270
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3271
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3272
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3273
	.port_pause_limit = mv88e6097_port_pause_limit,
3274
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3275
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3276
	.port_link_state = mv88e6352_port_link_state,
3277
	.port_get_cmode = mv88e6352_port_get_cmode,
3278
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3279
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3280 3281
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3282
	.stats_get_stats = mv88e6095_stats_get_stats,
3283 3284
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3285
	.watchdog_ops = &mv88e6097_watchdog_ops,
3286
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3287
	.pot_clear = mv88e6xxx_g2_pot_clear,
3288
	.reset = mv88e6352_g1_reset,
3289
	.rmu_disable = mv88e6352_g1_rmu_disable,
3290
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3291
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3292
	.serdes_power = mv88e6352_serdes_power,
3293 3294
	.serdes_irq_setup = mv88e6352_serdes_irq_setup,
	.serdes_irq_free = mv88e6352_serdes_irq_free,
3295
	.gpio_ops = &mv88e6352_gpio_ops,
3296
	.phylink_validate = mv88e6352_phylink_validate,
3297 3298 3299
};

static const struct mv88e6xxx_ops mv88e6185_ops = {
3300
	/* MV88E6XXX_FAMILY_6185 */
3301 3302
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3303
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3304 3305
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3306
	.port_set_link = mv88e6xxx_port_set_link,
3307
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3308
	.port_set_speed = mv88e6185_port_set_speed,
3309
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
3310
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
3311
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
3312
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
3313
	.port_set_pause = mv88e6185_port_set_pause,
3314
	.port_link_state = mv88e6185_port_link_state,
3315
	.port_get_cmode = mv88e6185_port_get_cmode,
3316
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3317
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3318 3319
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3320
	.stats_get_stats = mv88e6095_stats_get_stats,
3321 3322
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3323
	.watchdog_ops = &mv88e6097_watchdog_ops,
3324
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3325
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
3326 3327
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
3328
	.reset = mv88e6185_g1_reset,
3329
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3330
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3331
	.phylink_validate = mv88e6185_phylink_validate,
3332 3333
};

3334
static const struct mv88e6xxx_ops mv88e6190_ops = {
3335
	/* MV88E6XXX_FAMILY_6390 */
3336
	.setup_errata = mv88e6390_setup_errata,
3337
	.irl_init_all = mv88e6390_g2_irl_init_all,
3338 3339
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3340 3341 3342 3343 3344 3345 3346
	.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,
3347
	.port_tag_remap = mv88e6390_port_tag_remap,
3348
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3349
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3350
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3351
	.port_pause_limit = mv88e6390_port_pause_limit,
3352
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3353
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3354
	.port_link_state = mv88e6352_port_link_state,
3355
	.port_get_cmode = mv88e6352_port_get_cmode,
3356
	.port_set_cmode = mv88e6390_port_set_cmode,
3357
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3358
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3359 3360
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3361
	.stats_get_stats = mv88e6390_stats_get_stats,
3362 3363
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3364
	.watchdog_ops = &mv88e6390_watchdog_ops,
3365
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3366
	.pot_clear = mv88e6xxx_g2_pot_clear,
3367
	.reset = mv88e6352_g1_reset,
3368
	.rmu_disable = mv88e6390_g1_rmu_disable,
3369 3370
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3371
	.serdes_power = mv88e6390_serdes_power,
3372 3373
	.serdes_irq_setup = mv88e6390_serdes_irq_setup,
	.serdes_irq_free = mv88e6390_serdes_irq_free,
3374
	.gpio_ops = &mv88e6352_gpio_ops,
3375
	.phylink_validate = mv88e6390_phylink_validate,
3376 3377 3378
};

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

static const struct mv88e6xxx_ops mv88e6191_ops = {
3423
	/* MV88E6XXX_FAMILY_6390 */
3424
	.setup_errata = mv88e6390_setup_errata,
3425
	.irl_init_all = mv88e6390_g2_irl_init_all,
3426 3427
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3428 3429 3430 3431 3432 3433 3434
	.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,
3435
	.port_tag_remap = mv88e6390_port_tag_remap,
3436
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3437
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3438
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3439
	.port_pause_limit = mv88e6390_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
	.port_set_cmode = mv88e6390_port_set_cmode,
3445
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3446
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3447 3448
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3449
	.stats_get_stats = mv88e6390_stats_get_stats,
3450 3451
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3452
	.watchdog_ops = &mv88e6390_watchdog_ops,
3453
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3454
	.pot_clear = mv88e6xxx_g2_pot_clear,
3455
	.reset = mv88e6352_g1_reset,
3456
	.rmu_disable = mv88e6390_g1_rmu_disable,
3457 3458
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3459
	.serdes_power = mv88e6390_serdes_power,
3460 3461
	.serdes_irq_setup = mv88e6390_serdes_irq_setup,
	.serdes_irq_free = mv88e6390_serdes_irq_free,
3462 3463
	.avb_ops = &mv88e6390_avb_ops,
	.ptp_ops = &mv88e6352_ptp_ops,
3464
	.phylink_validate = mv88e6390_phylink_validate,
3465 3466
};

3467
static const struct mv88e6xxx_ops mv88e6240_ops = {
3468
	/* MV88E6XXX_FAMILY_6352 */
3469 3470
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3471
	.irl_init_all = mv88e6352_g2_irl_init_all,
3472 3473
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3474
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3475 3476
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3477
	.port_set_link = mv88e6xxx_port_set_link,
3478
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3479
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3480
	.port_set_speed = mv88e6352_port_set_speed,
3481
	.port_tag_remap = mv88e6095_port_tag_remap,
3482
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3483
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3484
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3485
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3486
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3487
	.port_pause_limit = mv88e6097_port_pause_limit,
3488
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3489
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3490
	.port_link_state = mv88e6352_port_link_state,
3491
	.port_get_cmode = mv88e6352_port_get_cmode,
3492
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3493
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3494 3495
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3496
	.stats_get_stats = mv88e6095_stats_get_stats,
3497 3498
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3499
	.watchdog_ops = &mv88e6097_watchdog_ops,
3500
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3501
	.pot_clear = mv88e6xxx_g2_pot_clear,
3502
	.reset = mv88e6352_g1_reset,
3503
	.rmu_disable = mv88e6352_g1_rmu_disable,
3504
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3505
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3506
	.serdes_power = mv88e6352_serdes_power,
3507 3508
	.serdes_irq_setup = mv88e6352_serdes_irq_setup,
	.serdes_irq_free = mv88e6352_serdes_irq_free,
3509
	.gpio_ops = &mv88e6352_gpio_ops,
3510
	.avb_ops = &mv88e6352_avb_ops,
3511
	.ptp_ops = &mv88e6352_ptp_ops,
3512
	.phylink_validate = mv88e6352_phylink_validate,
3513 3514
};

3515
static const struct mv88e6xxx_ops mv88e6290_ops = {
3516
	/* MV88E6XXX_FAMILY_6390 */
3517
	.setup_errata = mv88e6390_setup_errata,
3518
	.irl_init_all = mv88e6390_g2_irl_init_all,
3519 3520
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3521 3522 3523 3524 3525 3526 3527
	.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,
3528
	.port_tag_remap = mv88e6390_port_tag_remap,
3529
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3530
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3531
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3532
	.port_pause_limit = mv88e6390_port_pause_limit,
3533
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3534
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3535
	.port_link_state = mv88e6352_port_link_state,
3536
	.port_get_cmode = mv88e6352_port_get_cmode,
3537
	.port_set_cmode = mv88e6390_port_set_cmode,
3538
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3539
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3540 3541
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3542
	.stats_get_stats = mv88e6390_stats_get_stats,
3543 3544
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3545
	.watchdog_ops = &mv88e6390_watchdog_ops,
3546
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3547
	.pot_clear = mv88e6xxx_g2_pot_clear,
3548
	.reset = mv88e6352_g1_reset,
3549
	.rmu_disable = mv88e6390_g1_rmu_disable,
3550 3551
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3552
	.serdes_power = mv88e6390_serdes_power,
3553 3554
	.serdes_irq_setup = mv88e6390_serdes_irq_setup,
	.serdes_irq_free = mv88e6390_serdes_irq_free,
3555
	.gpio_ops = &mv88e6352_gpio_ops,
3556
	.avb_ops = &mv88e6390_avb_ops,
3557
	.ptp_ops = &mv88e6352_ptp_ops,
3558
	.phylink_validate = mv88e6390_phylink_validate,
3559 3560
};

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

4272
	[MV88E6240] = {
4273
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
4274 4275 4276 4277
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6240",
		.num_databases = 4096,
		.num_ports = 7,
4278
		.num_internal_phys = 5,
4279
		.num_gpio = 15,
4280
		.max_vid = 4095,
4281
		.port_base_addr = 0x10,
4282
		.phy_base_addr = 0x0,
4283
		.global1_addr = 0x1b,
4284
		.global2_addr = 0x1c,
4285
		.age_time_coeff = 15000,
4286
		.g1_irqs = 9,
4287
		.g2_irqs = 10,
4288
		.atu_move_port_mask = 0xf,
4289
		.pvt = true,
4290
		.multi_chip = true,
4291
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4292
		.ptp_support = true,
4293
		.ops = &mv88e6240_ops,
4294 4295
	},

4296
	[MV88E6290] = {
4297
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
4298 4299 4300 4301
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6290",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4302
		.num_internal_phys = 11,
4303
		.num_gpio = 16,
4304
		.max_vid = 8191,
4305
		.port_base_addr = 0x0,
4306
		.phy_base_addr = 0x0,
4307
		.global1_addr = 0x1b,
4308
		.global2_addr = 0x1c,
4309
		.age_time_coeff = 3750,
4310
		.g1_irqs = 9,
4311
		.g2_irqs = 14,
4312
		.atu_move_port_mask = 0x1f,
4313
		.pvt = true,
4314
		.multi_chip = true,
4315
		.tag_protocol = DSA_TAG_PROTO_DSA,
4316
		.ptp_support = true,
4317 4318 4319
		.ops = &mv88e6290_ops,
	},

4320
	[MV88E6320] = {
4321
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
4322 4323 4324 4325
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6320",
		.num_databases = 4096,
		.num_ports = 7,
4326
		.num_internal_phys = 5,
4327
		.num_gpio = 15,
4328
		.max_vid = 4095,
4329
		.port_base_addr = 0x10,
4330
		.phy_base_addr = 0x0,
4331
		.global1_addr = 0x1b,
4332
		.global2_addr = 0x1c,
4333
		.age_time_coeff = 15000,
4334
		.g1_irqs = 8,
4335
		.g2_irqs = 10,
4336
		.atu_move_port_mask = 0xf,
4337
		.pvt = true,
4338
		.multi_chip = true,
4339
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4340
		.ptp_support = true,
4341
		.ops = &mv88e6320_ops,
4342 4343 4344
	},

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

4367
	[MV88E6341] = {
4368
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
4369 4370 4371
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
4372
		.num_internal_phys = 5,
4373
		.num_ports = 6,
4374
		.num_gpio = 11,
4375
		.max_vid = 4095,
4376
		.port_base_addr = 0x10,
4377
		.phy_base_addr = 0x10,
4378
		.global1_addr = 0x1b,
4379
		.global2_addr = 0x1c,
4380
		.age_time_coeff = 3750,
4381
		.atu_move_port_mask = 0x1f,
4382
		.g1_irqs = 9,
4383
		.g2_irqs = 10,
4384
		.pvt = true,
4385
		.multi_chip = true,
4386
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4387
		.ptp_support = true,
4388 4389 4390
		.ops = &mv88e6341_ops,
	},

4391
	[MV88E6350] = {
4392
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
4393 4394 4395 4396
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6350",
		.num_databases = 4096,
		.num_ports = 7,
4397
		.num_internal_phys = 5,
4398
		.max_vid = 4095,
4399
		.port_base_addr = 0x10,
4400
		.phy_base_addr = 0x0,
4401
		.global1_addr = 0x1b,
4402
		.global2_addr = 0x1c,
4403
		.age_time_coeff = 15000,
4404
		.g1_irqs = 9,
4405
		.g2_irqs = 10,
4406
		.atu_move_port_mask = 0xf,
4407
		.pvt = true,
4408
		.multi_chip = true,
4409
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4410
		.ops = &mv88e6350_ops,
4411 4412 4413
	},

	[MV88E6351] = {
4414
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
4415 4416 4417 4418
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6351",
		.num_databases = 4096,
		.num_ports = 7,
4419
		.num_internal_phys = 5,
4420
		.max_vid = 4095,
4421
		.port_base_addr = 0x10,
4422
		.phy_base_addr = 0x0,
4423
		.global1_addr = 0x1b,
4424
		.global2_addr = 0x1c,
4425
		.age_time_coeff = 15000,
4426
		.g1_irqs = 9,
4427
		.g2_irqs = 10,
4428
		.atu_move_port_mask = 0xf,
4429
		.pvt = true,
4430
		.multi_chip = true,
4431
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4432
		.ops = &mv88e6351_ops,
4433 4434 4435
	},

	[MV88E6352] = {
4436
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
4437 4438 4439 4440
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6352",
		.num_databases = 4096,
		.num_ports = 7,
4441
		.num_internal_phys = 5,
4442
		.num_gpio = 15,
4443
		.max_vid = 4095,
4444
		.port_base_addr = 0x10,
4445
		.phy_base_addr = 0x0,
4446
		.global1_addr = 0x1b,
4447
		.global2_addr = 0x1c,
4448
		.age_time_coeff = 15000,
4449
		.g1_irqs = 9,
4450
		.g2_irqs = 10,
4451
		.atu_move_port_mask = 0xf,
4452
		.pvt = true,
4453
		.multi_chip = true,
4454
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4455
		.ptp_support = true,
4456
		.ops = &mv88e6352_ops,
4457
	},
4458
	[MV88E6390] = {
4459
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
4460 4461 4462 4463
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4464
		.num_internal_phys = 11,
4465
		.num_gpio = 16,
4466
		.max_vid = 8191,
4467
		.port_base_addr = 0x0,
4468
		.phy_base_addr = 0x0,
4469
		.global1_addr = 0x1b,
4470
		.global2_addr = 0x1c,
4471
		.age_time_coeff = 3750,
4472
		.g1_irqs = 9,
4473
		.g2_irqs = 14,
4474
		.atu_move_port_mask = 0x1f,
4475
		.pvt = true,
4476
		.multi_chip = true,
4477
		.tag_protocol = DSA_TAG_PROTO_DSA,
4478
		.ptp_support = true,
4479 4480 4481
		.ops = &mv88e6390_ops,
	},
	[MV88E6390X] = {
4482
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
4483 4484 4485 4486
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4487
		.num_internal_phys = 11,
4488
		.num_gpio = 16,
4489
		.max_vid = 8191,
4490
		.port_base_addr = 0x0,
4491
		.phy_base_addr = 0x0,
4492
		.global1_addr = 0x1b,
4493
		.global2_addr = 0x1c,
4494
		.age_time_coeff = 3750,
4495
		.g1_irqs = 9,
4496
		.g2_irqs = 14,
4497
		.atu_move_port_mask = 0x1f,
4498
		.pvt = true,
4499
		.multi_chip = true,
4500
		.tag_protocol = DSA_TAG_PROTO_DSA,
4501
		.ptp_support = true,
4502 4503
		.ops = &mv88e6390x_ops,
	},
4504 4505
};

4506
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
4507
{
4508
	int i;
4509

4510 4511 4512
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
4513 4514 4515 4516

	return NULL;
}

4517
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
4518 4519
{
	const struct mv88e6xxx_info *info;
4520 4521 4522
	unsigned int prod_num, rev;
	u16 id;
	int err;
4523

4524
	mutex_lock(&chip->reg_lock);
4525
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
4526 4527 4528
	mutex_unlock(&chip->reg_lock);
	if (err)
		return err;
4529

4530 4531
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
4532 4533 4534 4535 4536

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

4537
	/* Update the compatible info with the probed one */
4538
	chip->info = info;
4539

4540 4541 4542 4543
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

4544 4545
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
4546 4547 4548 4549

	return 0;
}

4550
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
4551
{
4552
	struct mv88e6xxx_chip *chip;
4553

4554 4555
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
4556 4557
		return NULL;

4558
	chip->dev = dev;
4559

4560
	mutex_init(&chip->reg_lock);
4561
	INIT_LIST_HEAD(&chip->mdios);
4562

4563
	return chip;
4564 4565
}

4566
static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
4567 4568
			      struct mii_bus *bus, int sw_addr)
{
4569
	if (sw_addr == 0)
4570
		chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
4571
	else if (chip->info->multi_chip)
4572
		chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
4573 4574 4575
	else
		return -EINVAL;

4576 4577
	chip->bus = bus;
	chip->sw_addr = sw_addr;
4578 4579 4580 4581

	return 0;
}

4582 4583
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
							int port)
4584
{
V
Vivien Didelot 已提交
4585
	struct mv88e6xxx_chip *chip = ds->priv;
4586

4587
	return chip->info->tag_protocol;
4588 4589
}

4590
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
4591 4592 4593
static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
				       struct device *host_dev, int sw_addr,
				       void **priv)
4594
{
4595
	struct mv88e6xxx_chip *chip;
4596
	struct mii_bus *bus;
4597
	int err;
4598

4599
	bus = dsa_host_dev_to_mii_bus(host_dev);
4600 4601 4602
	if (!bus)
		return NULL;

4603 4604
	chip = mv88e6xxx_alloc_chip(dsa_dev);
	if (!chip)
4605 4606
		return NULL;

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

4610
	err = mv88e6xxx_smi_init(chip, bus, sw_addr);
4611 4612 4613
	if (err)
		goto free;

4614
	err = mv88e6xxx_detect(chip);
4615
	if (err)
4616
		goto free;
4617

4618 4619 4620 4621 4622 4623
	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_switch_reset(chip);
	mutex_unlock(&chip->reg_lock);
	if (err)
		goto free;

4624 4625
	mv88e6xxx_phy_init(chip);

4626
	err = mv88e6xxx_mdios_register(chip, NULL);
4627
	if (err)
4628
		goto free;
4629

4630
	*priv = chip;
4631

4632
	return chip->info->name;
4633
free:
4634
	devm_kfree(dsa_dev, chip);
4635 4636

	return NULL;
4637
}
4638
#endif
4639

4640
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4641
				      const struct switchdev_obj_port_mdb *mdb)
4642 4643 4644 4645 4646 4647 4648 4649 4650
{
	/* 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,
4651
				   const struct switchdev_obj_port_mdb *mdb)
4652
{
V
Vivien Didelot 已提交
4653
	struct mv88e6xxx_chip *chip = ds->priv;
4654 4655 4656

	mutex_lock(&chip->reg_lock);
	if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4657
					 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
4658 4659
		dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
			port);
4660 4661 4662 4663 4664 4665
	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 已提交
4666
	struct mv88e6xxx_chip *chip = ds->priv;
4667 4668 4669 4670
	int err;

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4671
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
4672 4673 4674 4675 4676
	mutex_unlock(&chip->reg_lock);

	return err;
}

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

4725 4726 4727 4728
static struct dsa_switch_driver mv88e6xxx_switch_drv = {
	.ops			= &mv88e6xxx_switch_ops,
};

4729
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
4730
{
4731
	struct device *dev = chip->dev;
4732 4733
	struct dsa_switch *ds;

4734
	ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
4735 4736 4737
	if (!ds)
		return -ENOMEM;

4738
	ds->priv = chip;
4739
	ds->dev = dev;
4740
	ds->ops = &mv88e6xxx_switch_ops;
4741 4742
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
4743 4744 4745

	dev_set_drvdata(dev, ds);

4746
	return dsa_register_switch(ds);
4747 4748
}

4749
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
4750
{
4751
	dsa_unregister_switch(chip->ds);
4752 4753
}

4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766
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;
}

4767
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
4768
{
4769
	struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
4770
	const struct mv88e6xxx_info *compat_info = NULL;
4771
	struct device *dev = &mdiodev->dev;
4772
	struct device_node *np = dev->of_node;
4773
	struct mv88e6xxx_chip *chip;
4774
	int port;
4775
	int err;
4776

4777 4778 4779
	if (!np && !pdata)
		return -EINVAL;

4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798
	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;
		}
	}

4799 4800 4801
	if (!compat_info)
		return -EINVAL;

4802
	chip = mv88e6xxx_alloc_chip(dev);
4803 4804 4805 4806
	if (!chip) {
		err = -ENOMEM;
		goto out;
	}
4807

4808
	chip->info = compat_info;
4809

4810
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
4811
	if (err)
4812
		goto out;
4813

4814
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4815 4816 4817 4818
	if (IS_ERR(chip->reset)) {
		err = PTR_ERR(chip->reset);
		goto out;
	}
4819

4820
	err = mv88e6xxx_detect(chip);
4821
	if (err)
4822
		goto out;
4823

4824 4825
	mv88e6xxx_phy_init(chip);

4826 4827 4828 4829 4830 4831 4832
	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;
	}
4833

4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845
	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;
	}

4846
	/* Has to be performed before the MDIO bus is created, because
4847
	 * the PHYs will link their interrupts to these interrupt
4848 4849 4850 4851
	 * controllers
	 */
	mutex_lock(&chip->reg_lock);
	if (chip->irq > 0)
4852
		err = mv88e6xxx_g1_irq_setup(chip);
4853 4854 4855
	else
		err = mv88e6xxx_irq_poll_setup(chip);
	mutex_unlock(&chip->reg_lock);
4856

4857 4858
	if (err)
		goto out;
4859

4860 4861
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
4862
		if (err)
4863
			goto out_g1_irq;
4864 4865
	}

4866 4867 4868 4869 4870 4871 4872 4873
	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;

4874
	err = mv88e6xxx_mdios_register(chip, np);
4875
	if (err)
4876
		goto out_g1_vtu_prob_irq;
4877

4878
	err = mv88e6xxx_register_switch(chip);
4879 4880
	if (err)
		goto out_mdio;
4881

4882
	return 0;
4883 4884

out_mdio:
4885
	mv88e6xxx_mdios_unregister(chip);
4886
out_g1_vtu_prob_irq:
4887
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
4888
out_g1_atu_prob_irq:
4889
	mv88e6xxx_g1_atu_prob_irq_free(chip);
4890
out_g2_irq:
4891
	if (chip->info->g2_irqs > 0)
4892 4893
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
4894
	if (chip->irq > 0)
4895
		mv88e6xxx_g1_irq_free(chip);
4896 4897
	else
		mv88e6xxx_irq_poll_free(chip);
4898
out:
4899 4900 4901
	if (pdata)
		dev_put(pdata->netdev);

4902
	return err;
4903
}
4904 4905 4906 4907

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

4910 4911
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
4912
		mv88e6xxx_ptp_free(chip);
4913
	}
4914

4915
	mv88e6xxx_phy_destroy(chip);
4916
	mv88e6xxx_unregister_switch(chip);
4917
	mv88e6xxx_mdios_unregister(chip);
4918

4919 4920 4921 4922 4923 4924 4925
	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)
4926
		mv88e6xxx_g1_irq_free(chip);
4927 4928
	else
		mv88e6xxx_irq_poll_free(chip);
4929 4930 4931
}

static const struct of_device_id mv88e6xxx_of_match[] = {
4932 4933 4934 4935
	{
		.compatible = "marvell,mv88e6085",
		.data = &mv88e6xxx_table[MV88E6085],
	},
4936 4937 4938 4939
	{
		.compatible = "marvell,mv88e6190",
		.data = &mv88e6xxx_table[MV88E6190],
	},
4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955
	{ /* 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)
{
4956
	register_switch_driver(&mv88e6xxx_switch_drv);
4957 4958
	return mdio_driver_register(&mv88e6xxx_driver);
}
4959 4960 4961 4962
module_init(mv88e6xxx_init);

static void __exit mv88e6xxx_cleanup(void)
{
4963
	mdio_driver_unregister(&mv88e6xxx_driver);
4964
	unregister_switch_driver(&mv88e6xxx_switch_drv);
4965 4966
}
module_exit(mv88e6xxx_cleanup);
4967 4968 4969 4970

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