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

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

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

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

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

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

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

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

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

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

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

	*val = ret & 0xffff;

	return 0;
}

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

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

	return 0;
}

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

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

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

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

	return -ETIMEDOUT;
}

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

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

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

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

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

159
	*val = ret & 0xffff;
160

161
	return 0;
162 163
}

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

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

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

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

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

	return 0;
}

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

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

202
	assert_reg_lock(chip);
203

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

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

	return 0;
}

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

218
	assert_reg_lock(chip);
219

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

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

227 228 229
	return 0;
}

230
struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
231 232 233 234 235 236 237 238 239 240 241
{
	struct mv88e6xxx_mdio_bus *mdio_bus;

	mdio_bus = list_first_entry(&chip->mdios, struct mv88e6xxx_mdio_bus,
				    list);
	if (!mdio_bus)
		return NULL;

	return mdio_bus->bus;
}

242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
static void mv88e6xxx_g1_irq_mask(struct irq_data *d)
{
	struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
	unsigned int n = d->hwirq;

	chip->g1_irq.masked |= (1 << n);
}

static void mv88e6xxx_g1_irq_unmask(struct irq_data *d)
{
	struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
	unsigned int n = d->hwirq;

	chip->g1_irq.masked &= ~(1 << n);
}

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

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

	if (err)
		goto out;

	for (n = 0; n < chip->g1_irq.nirqs; ++n) {
		if (reg & (1 << n)) {
			sub_irq = irq_find_mapping(chip->g1_irq.domain, n);
			handle_nested_irq(sub_irq);
			++nhandled;
		}
	}
out:
	return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
}

284 285 286 287 288 289 290
static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id)
{
	struct mv88e6xxx_chip *chip = dev_id;

	return mv88e6xxx_g1_irq_thread_work(chip);
}

291 292 293 294 295 296 297 298 299 300 301 302 303 304
static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
{
	struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);

	mutex_lock(&chip->reg_lock);
}

static void mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data *d)
{
	struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
	u16 mask = GENMASK(chip->g1_irq.nirqs, 0);
	u16 reg;
	int err;

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

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

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

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

320
static const struct irq_chip mv88e6xxx_g1_irq_chip = {
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
	.name			= "mv88e6xxx-g1",
	.irq_mask		= mv88e6xxx_g1_irq_mask,
	.irq_unmask		= mv88e6xxx_g1_irq_unmask,
	.irq_bus_lock		= mv88e6xxx_g1_irq_bus_lock,
	.irq_bus_sync_unlock	= mv88e6xxx_g1_irq_bus_sync_unlock,
};

static int mv88e6xxx_g1_irq_domain_map(struct irq_domain *d,
				       unsigned int irq,
				       irq_hw_number_t hwirq)
{
	struct mv88e6xxx_chip *chip = d->host_data;

	irq_set_chip_data(irq, d->host_data);
	irq_set_chip_and_handler(irq, &chip->g1_irq.chip, handle_level_irq);
	irq_set_noprobe(irq);

	return 0;
}

static const struct irq_domain_ops mv88e6xxx_g1_irq_domain_ops = {
	.map	= mv88e6xxx_g1_irq_domain_map,
	.xlate	= irq_domain_xlate_twocell,
};

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

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

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

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

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

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

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

	chip->g1_irq.nirqs = chip->info->g1_irqs;
	chip->g1_irq.domain = irq_domain_add_simple(
		NULL, chip->g1_irq.nirqs, 0,
		&mv88e6xxx_g1_irq_domain_ops, chip);
	if (!chip->g1_irq.domain)
		return -ENOMEM;

	for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
		irq_create_mapping(chip->g1_irq.domain, irq);

	chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
	chip->g1_irq.masked = ~0;

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

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

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

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

	return 0;

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

out_mapping:
	for (irq = 0; irq < 16; irq++) {
		virq = irq_find_mapping(chip->g1_irq.domain, irq);
		irq_dispose_mapping(virq);
	}

	irq_domain_remove(chip->g1_irq.domain);
423 424 425 426

	return err;
}

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

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

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

	return err;
}

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

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

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

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

	kthread_init_delayed_work(&chip->irq_poll_work,
				  mv88e6xxx_irq_poll);

	chip->kworker = kthread_create_worker(0, dev_name(chip->dev));
	if (IS_ERR(chip->kworker))
		return PTR_ERR(chip->kworker);

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

	return 0;
}

static void mv88e6xxx_irq_poll_free(struct mv88e6xxx_chip *chip)
{
	kthread_cancel_delayed_work_sync(&chip->irq_poll_work);
	kthread_destroy_worker(chip->kworker);
481 482 483 484

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

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

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

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

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

		usleep_range(1000, 2000);
	}

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

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

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

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

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

526
static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
527
				    int link, int speed, int duplex, int pause,
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
				    phy_interface_t mode)
{
	int err;

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

	/* Port's MAC control must not be changed unless the link is down */
	err = chip->info->ops->port_set_link(chip, port, 0);
	if (err)
		return err;

	if (chip->info->ops->port_set_speed) {
		err = chip->info->ops->port_set_speed(chip, port, speed);
		if (err && err != -EOPNOTSUPP)
			goto restore_link;
	}

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

552 553 554 555 556 557 558 559 560 561 562 563
	if (chip->info->ops->port_set_duplex) {
		err = chip->info->ops->port_set_duplex(chip, port, duplex);
		if (err && err != -EOPNOTSUPP)
			goto restore_link;
	}

	if (chip->info->ops->port_set_rgmii_delay) {
		err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
		if (err && err != -EOPNOTSUPP)
			goto restore_link;
	}

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

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

	return err;
}

578 579 580 581
/* We expect the switch to perform auto negotiation if there is a real
 * phy. However, in the case of a fixed link phy, we force the port
 * settings from the fixed link settings.
 */
582 583
static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
				  struct phy_device *phydev)
584
{
V
Vivien Didelot 已提交
585
	struct mv88e6xxx_chip *chip = ds->priv;
586
	int err;
587 588 589 590

	if (!phy_is_pseudo_fixed_link(phydev))
		return;

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

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

601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
			       unsigned long *supported,
			       struct phylink_link_state *state)
{
}

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);
	err = mv88e6xxx_port_link_state(chip, port, state);
	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;
625
	int speed, duplex, link, pause, err;
626 627 628 629 630 631 632 633 634 635 636 637 638

	if (mode == MLO_AN_PHY)
		return;

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

	mutex_lock(&chip->reg_lock);
642
	err = mv88e6xxx_port_setup_mac(chip, port, link, speed, duplex, pause,
643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678
				       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);
}

679
static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
680
{
681 682
	if (!chip->info->ops->stats_snapshot)
		return -EOPNOTSUPP;
683

684
	return chip->info->ops->stats_snapshot(chip, port);
685 686
}

687
static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746
	{ "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, },
747 748
};

749
static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
750
					    struct mv88e6xxx_hw_stat *s,
751 752
					    int port, u16 bank1_select,
					    u16 histogram)
753 754 755
{
	u32 low;
	u32 high = 0;
756
	u16 reg = 0;
757
	int err;
758 759
	u64 value;

760
	switch (s->type) {
761
	case STATS_TYPE_PORT:
762 763
		err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
		if (err)
764
			return U64_MAX;
765

766
		low = reg;
767
		if (s->size == 4) {
768 769
			err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
			if (err)
770
				return U64_MAX;
771
			high = reg;
772
		}
773
		break;
774
	case STATS_TYPE_BANK1:
775
		reg = bank1_select;
776 777
		/* fall through */
	case STATS_TYPE_BANK0:
778
		reg |= s->reg | histogram;
779
		mv88e6xxx_g1_stats_read(chip, reg, &low);
780
		if (s->size == 8)
781
			mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
782 783
		break;
	default:
784
		return U64_MAX;
785 786 787 788 789
	}
	value = (((u64)high) << 16) | low;
	return value;
}

790 791
static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data, int types)
792
{
793 794
	struct mv88e6xxx_hw_stat *stat;
	int i, j;
795

796 797
	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
		stat = &mv88e6xxx_hw_stats[i];
798
		if (stat->type & types) {
799 800 801 802
			memcpy(data + j * ETH_GSTRING_LEN, stat->string,
			       ETH_GSTRING_LEN);
			j++;
		}
803
	}
804 805

	return j;
806 807
}

808 809
static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
810
{
811 812
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_PORT);
813 814
}

815 816
static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
817
{
818 819
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
820 821
}

822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839
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);
}

840
static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
841
				  u32 stringset, uint8_t *data)
842
{
V
Vivien Didelot 已提交
843
	struct mv88e6xxx_chip *chip = ds->priv;
844
	int count = 0;
845

846 847 848
	if (stringset != ETH_SS_STATS)
		return;

849 850
	mutex_lock(&chip->reg_lock);

851
	if (chip->info->ops->stats_get_strings)
852 853 854 855
		count = chip->info->ops->stats_get_strings(chip, data);

	if (chip->info->ops->serdes_get_strings) {
		data += count * ETH_GSTRING_LEN;
856
		count = chip->info->ops->serdes_get_strings(chip, port, data);
857
	}
858

859 860 861
	data += count * ETH_GSTRING_LEN;
	mv88e6xxx_atu_vtu_get_strings(data);

862
	mutex_unlock(&chip->reg_lock);
863 864 865 866 867
}

static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
					  int types)
{
868 869 870 871 872
	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];
873
		if (stat->type & types)
874 875 876
			j++;
	}
	return j;
877 878
}

879 880 881 882 883 884 885 886 887 888 889 890
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);
}

891
static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
892 893
{
	struct mv88e6xxx_chip *chip = ds->priv;
894 895
	int serdes_count = 0;
	int count = 0;
896

897 898 899
	if (sset != ETH_SS_STATS)
		return 0;

900
	mutex_lock(&chip->reg_lock);
901
	if (chip->info->ops->stats_get_sset_count)
902 903 904 905 906 907 908
		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);
909
	if (serdes_count < 0) {
910
		count = serdes_count;
911 912 913 914 915
		goto out;
	}
	count += serdes_count;
	count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);

916
out:
917
	mutex_unlock(&chip->reg_lock);
918

919
	return count;
920 921
}

922 923 924
static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data, int types,
				     u16 bank1_select, u16 histogram)
925 926 927 928 929 930 931
{
	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) {
932
			mutex_lock(&chip->reg_lock);
933 934 935
			data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
							      bank1_select,
							      histogram);
936 937
			mutex_unlock(&chip->reg_lock);

938 939 940
			j++;
		}
	}
941
	return j;
942 943
}

944 945
static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
946 947
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
948
					 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
949
					 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
950 951
}

952 953
static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
954 955
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
956
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
957 958
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
					 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
959 960
}

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

970 971 972 973 974 975 976 977 978 979
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;
}

980 981 982
static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
				uint64_t *data)
{
983 984
	int count = 0;

985
	if (chip->info->ops->stats_get_stats)
986 987
		count = chip->info->ops->stats_get_stats(chip, port, data);

988
	mutex_lock(&chip->reg_lock);
989 990
	if (chip->info->ops->serdes_get_stats) {
		data += count;
991
		count = chip->info->ops->serdes_get_stats(chip, port, data);
992
	}
993 994 995
	data += count;
	mv88e6xxx_atu_vtu_get_stats(chip, port, data);
	mutex_unlock(&chip->reg_lock);
996 997
}

998 999
static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
					uint64_t *data)
1000
{
V
Vivien Didelot 已提交
1001
	struct mv88e6xxx_chip *chip = ds->priv;
1002 1003
	int ret;

1004
	mutex_lock(&chip->reg_lock);
1005

1006
	ret = mv88e6xxx_stats_snapshot(chip, port);
1007 1008 1009
	mutex_unlock(&chip->reg_lock);

	if (ret < 0)
1010
		return;
1011 1012

	mv88e6xxx_get_stats(chip, port, data);
1013

1014 1015
}

1016
static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
1017 1018 1019 1020
{
	return 32 * sizeof(u16);
}

1021 1022
static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
			       struct ethtool_regs *regs, void *_p)
1023
{
V
Vivien Didelot 已提交
1024
	struct mv88e6xxx_chip *chip = ds->priv;
1025 1026
	int err;
	u16 reg;
1027 1028 1029 1030 1031 1032 1033
	u16 *p = _p;
	int i;

	regs->version = 0;

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

1034
	mutex_lock(&chip->reg_lock);
1035

1036 1037
	for (i = 0; i < 32; i++) {

1038 1039 1040
		err = mv88e6xxx_port_read(chip, port, i, &reg);
		if (!err)
			p[i] = reg;
1041
	}
1042

1043
	mutex_unlock(&chip->reg_lock);
1044 1045
}

V
Vivien Didelot 已提交
1046 1047
static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
1048
{
1049 1050
	/* Nothing to do on the port's MAC */
	return 0;
1051 1052
}

V
Vivien Didelot 已提交
1053 1054
static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
1055
{
1056 1057
	/* Nothing to do on the port's MAC */
	return 0;
1058 1059
}

1060
static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
1061
{
1062 1063 1064
	struct dsa_switch *ds = NULL;
	struct net_device *br;
	u16 pvlan;
1065 1066
	int i;

1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086
	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 已提交
1087
		    (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
1088 1089 1090 1091 1092
			pvlan |= BIT(i);

	return pvlan;
}

1093
static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
1094 1095
{
	u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
1096 1097 1098

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

1100
	return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
1101 1102
}

1103 1104
static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
					 u8 state)
1105
{
V
Vivien Didelot 已提交
1106
	struct mv88e6xxx_chip *chip = ds->priv;
1107
	int err;
1108

1109
	mutex_lock(&chip->reg_lock);
1110
	err = mv88e6xxx_port_set_state(chip, port, state);
1111
	mutex_unlock(&chip->reg_lock);
1112 1113

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

1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135
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;
}

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

1156 1157 1158 1159 1160 1161 1162
	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;
	}

1163 1164 1165 1166
	err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
	if (err)
		return err;

1167 1168 1169
	return 0;
}

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

1179 1180 1181 1182 1183 1184 1185 1186
static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->rmu_disable)
		return chip->info->ops->rmu_disable(chip);

	return 0;
}

1187 1188 1189 1190 1191 1192 1193 1194
static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->pot_clear)
		return chip->info->ops->pot_clear(chip);

	return 0;
}

1195 1196 1197 1198 1199 1200 1201 1202
static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->mgmt_rsvd2cpu)
		return chip->info->ops->mgmt_rsvd2cpu(chip);

	return 0;
}

1203 1204
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
1205 1206
	int err;

1207 1208 1209 1210
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

1211 1212 1213 1214
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

1215 1216 1217
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

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

1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250
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;
}

1251 1252 1253 1254 1255 1256 1257 1258 1259
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)
1260
		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1261 1262 1263 1264

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

1265 1266
static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
{
1267 1268 1269
	int dev, port;
	int err;

1270 1271 1272 1273 1274 1275
	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.
	 */
1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288
	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;
1289 1290
}

1291 1292 1293 1294 1295 1296
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);
1297
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1298 1299 1300
	mutex_unlock(&chip->reg_lock);

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

1304 1305 1306 1307 1308 1309 1310 1311
static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
{
	if (!chip->info->max_vid)
		return 0;

	return mv88e6xxx_g1_vtu_flush(chip);
}

1312 1313 1314 1315 1316 1317 1318 1319 1320
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);
}

1321 1322 1323 1324 1325 1326 1327 1328 1329
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);
}

1330
static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1331 1332
{
	DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1333 1334 1335
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = chip->info->max_vid,
	};
1336
	int i, err;
1337 1338 1339

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

1340
	/* Set every FID bit used by the (un)bridged ports */
1341
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1342
		err = mv88e6xxx_port_get_fid(chip, i, fid);
1343 1344 1345 1346 1347 1348
		if (err)
			return err;

		set_bit(*fid, fid_bitmap);
	}

1349 1350
	/* Set every FID bit used by the VLAN entries */
	do {
1351
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1352 1353 1354 1355 1356 1357 1358
		if (err)
			return err;

		if (!vlan.valid)
			break;

		set_bit(vlan.fid, fid_bitmap);
1359
	} while (vlan.vid < chip->info->max_vid);
1360 1361 1362 1363 1364

	/* 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);
1365
	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1366 1367 1368
		return -ENOSPC;

	/* Clear the database */
1369
	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1370 1371
}

1372 1373
static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
			     struct mv88e6xxx_vtu_entry *entry, bool new)
1374 1375 1376 1377 1378 1379
{
	int err;

	if (!vid)
		return -EINVAL;

1380 1381
	entry->vid = vid - 1;
	entry->valid = false;
1382

1383
	err = mv88e6xxx_vtu_getnext(chip, entry);
1384 1385 1386
	if (err)
		return err;

1387 1388
	if (entry->vid == vid && entry->valid)
		return 0;
1389

1390 1391 1392 1393 1394 1395 1396 1397
	if (new) {
		int i;

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

1398
		/* Exclude all ports */
1399
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1400
			entry->member[i] =
1401
				MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1402 1403

		return mv88e6xxx_atu_new(chip, &entry->fid);
1404 1405
	}

1406 1407
	/* switchdev expects -EOPNOTSUPP to honor software VLANs */
	return -EOPNOTSUPP;
1408 1409
}

1410 1411 1412
static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
					u16 vid_begin, u16 vid_end)
{
V
Vivien Didelot 已提交
1413
	struct mv88e6xxx_chip *chip = ds->priv;
1414 1415 1416
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = vid_begin - 1,
	};
1417 1418
	int i, err;

1419 1420 1421 1422
	/* 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;

1423 1424 1425
	if (!vid_begin)
		return -EOPNOTSUPP;

1426
	mutex_lock(&chip->reg_lock);
1427 1428

	do {
1429
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1430 1431 1432 1433 1434 1435 1436 1437 1438
		if (err)
			goto unlock;

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

1439
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1440 1441 1442
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

1443
			if (!ds->ports[i].slave)
1444 1445
				continue;

1446
			if (vlan.member[i] ==
1447
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1448 1449
				continue;

V
Vivien Didelot 已提交
1450
			if (dsa_to_port(ds, i)->bridge_dev ==
1451
			    ds->ports[port].bridge_dev)
1452 1453
				break; /* same bridge, check next VLAN */

V
Vivien Didelot 已提交
1454
			if (!dsa_to_port(ds, i)->bridge_dev)
1455 1456
				continue;

1457 1458
			dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
				port, vlan.vid, i,
V
Vivien Didelot 已提交
1459
				netdev_name(dsa_to_port(ds, i)->bridge_dev));
1460 1461 1462 1463 1464 1465
			err = -EOPNOTSUPP;
			goto unlock;
		}
	} while (vlan.vid < vid_end);

unlock:
1466
	mutex_unlock(&chip->reg_lock);
1467 1468 1469 1470

	return err;
}

1471 1472
static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
					 bool vlan_filtering)
1473
{
V
Vivien Didelot 已提交
1474
	struct mv88e6xxx_chip *chip = ds->priv;
1475 1476
	u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
		MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
1477
	int err;
1478

1479
	if (!chip->info->max_vid)
1480 1481
		return -EOPNOTSUPP;

1482
	mutex_lock(&chip->reg_lock);
1483
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1484
	mutex_unlock(&chip->reg_lock);
1485

1486
	return err;
1487 1488
}

1489 1490
static int
mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1491
			    const struct switchdev_obj_port_vlan *vlan)
1492
{
V
Vivien Didelot 已提交
1493
	struct mv88e6xxx_chip *chip = ds->priv;
1494 1495
	int err;

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

1499 1500 1501 1502 1503 1504 1505 1506
	/* 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;

1507 1508 1509 1510 1511 1512
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */
	return 0;
}

1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556
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);
}

1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579
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;
}

1580
static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
1581
				    u16 vid, u8 member)
1582
{
1583
	struct mv88e6xxx_vtu_entry vlan;
1584 1585
	int err;

1586
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
1587
	if (err)
1588
		return err;
1589

1590
	vlan.member[port] = member;
1591

1592 1593 1594 1595 1596
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
	if (err)
		return err;

	return mv88e6xxx_broadcast_setup(chip, vid);
1597 1598
}

1599
static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1600
				    const struct switchdev_obj_port_vlan *vlan)
1601
{
V
Vivien Didelot 已提交
1602
	struct mv88e6xxx_chip *chip = ds->priv;
1603 1604
	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1605
	u8 member;
1606 1607
	u16 vid;

1608
	if (!chip->info->max_vid)
1609 1610
		return;

1611
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1612
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1613
	else if (untagged)
1614
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
1615
	else
1616
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
1617

1618
	mutex_lock(&chip->reg_lock);
1619

1620
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
1621
		if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
1622 1623
			dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
				vid, untagged ? 'u' : 't');
1624

1625
	if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1626 1627
		dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
			vlan->vid_end);
1628

1629
	mutex_unlock(&chip->reg_lock);
1630 1631
}

1632
static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
1633
				    int port, u16 vid)
1634
{
1635
	struct mv88e6xxx_vtu_entry vlan;
1636 1637
	int i, err;

1638
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1639
	if (err)
1640
		return err;
1641

1642
	/* Tell switchdev if this VLAN is handled in software */
1643
	if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1644
		return -EOPNOTSUPP;
1645

1646
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1647 1648

	/* keep the VLAN unless all ports are excluded */
1649
	vlan.valid = false;
1650
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1651 1652
		if (vlan.member[i] !=
		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
1653
			vlan.valid = true;
1654 1655 1656 1657
			break;
		}
	}

1658
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1659 1660 1661
	if (err)
		return err;

1662
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
1663 1664
}

1665 1666
static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
				   const struct switchdev_obj_port_vlan *vlan)
1667
{
V
Vivien Didelot 已提交
1668
	struct mv88e6xxx_chip *chip = ds->priv;
1669 1670 1671
	u16 pvid, vid;
	int err = 0;

1672
	if (!chip->info->max_vid)
1673 1674
		return -EOPNOTSUPP;

1675
	mutex_lock(&chip->reg_lock);
1676

1677
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
1678 1679 1680
	if (err)
		goto unlock;

1681
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1682
		err = _mv88e6xxx_port_vlan_del(chip, port, vid);
1683 1684 1685 1686
		if (err)
			goto unlock;

		if (vid == pvid) {
1687
			err = mv88e6xxx_port_set_pvid(chip, port, 0);
1688 1689 1690 1691 1692
			if (err)
				goto unlock;
		}
	}

1693
unlock:
1694
	mutex_unlock(&chip->reg_lock);
1695 1696 1697 1698

	return err;
}

1699 1700
static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
				  const unsigned char *addr, u16 vid)
1701
{
V
Vivien Didelot 已提交
1702
	struct mv88e6xxx_chip *chip = ds->priv;
1703
	int err;
1704

1705
	mutex_lock(&chip->reg_lock);
1706 1707
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1708
	mutex_unlock(&chip->reg_lock);
1709 1710

	return err;
1711 1712
}

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

1719
	mutex_lock(&chip->reg_lock);
1720
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1721
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
1722
	mutex_unlock(&chip->reg_lock);
1723

1724
	return err;
1725 1726
}

1727 1728
static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
				      u16 fid, u16 vid, int port,
1729
				      dsa_fdb_dump_cb_t *cb, void *data)
1730
{
1731
	struct mv88e6xxx_atu_entry addr;
1732
	bool is_static;
1733 1734
	int err;

1735
	addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1736
	eth_broadcast_addr(addr.mac);
1737 1738

	do {
1739
		mutex_lock(&chip->reg_lock);
1740
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
1741
		mutex_unlock(&chip->reg_lock);
1742
		if (err)
1743
			return err;
1744

1745
		if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
1746 1747
			break;

1748
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
1749 1750
			continue;

1751 1752
		if (!is_unicast_ether_addr(addr.mac))
			continue;
1753

1754 1755 1756
		is_static = (addr.state ==
			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
		err = cb(addr.mac, vid, is_static, data);
1757 1758
		if (err)
			return err;
1759 1760 1761 1762 1763
	} while (!is_broadcast_ether_addr(addr.mac));

	return err;
}

1764
static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1765
				  dsa_fdb_dump_cb_t *cb, void *data)
1766
{
1767
	struct mv88e6xxx_vtu_entry vlan = {
1768
		.vid = chip->info->max_vid,
1769
	};
1770
	u16 fid;
1771 1772
	int err;

1773
	/* Dump port's default Filtering Information Database (VLAN ID 0) */
1774
	mutex_lock(&chip->reg_lock);
1775
	err = mv88e6xxx_port_get_fid(chip, port, &fid);
1776 1777
	mutex_unlock(&chip->reg_lock);

1778
	if (err)
1779
		return err;
1780

1781
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
1782
	if (err)
1783
		return err;
1784

1785
	/* Dump VLANs' Filtering Information Databases */
1786
	do {
1787
		mutex_lock(&chip->reg_lock);
1788
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1789
		mutex_unlock(&chip->reg_lock);
1790
		if (err)
1791
			return err;
1792 1793 1794 1795

		if (!vlan.valid)
			break;

1796
		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1797
						 cb, data);
1798
		if (err)
1799
			return err;
1800
	} while (vlan.vid < chip->info->max_vid);
1801

1802 1803 1804 1805
	return err;
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1806
				   dsa_fdb_dump_cb_t *cb, void *data)
1807
{
V
Vivien Didelot 已提交
1808
	struct mv88e6xxx_chip *chip = ds->priv;
1809

1810
	return mv88e6xxx_port_db_dump(chip, port, cb, data);
1811 1812
}

1813 1814
static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
				struct net_device *br)
1815
{
1816
	struct dsa_switch *ds;
1817
	int port;
1818
	int dev;
1819
	int err;
1820

1821 1822 1823 1824
	/* 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);
1825
			if (err)
1826
				return err;
1827 1828 1829
		}
	}

1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847
	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;
			}
		}
	}

1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858
	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);
1859
	mutex_unlock(&chip->reg_lock);
1860

1861
	return err;
1862 1863
}

1864 1865
static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
					struct net_device *br)
1866
{
V
Vivien Didelot 已提交
1867
	struct mv88e6xxx_chip *chip = ds->priv;
1868

1869
	mutex_lock(&chip->reg_lock);
1870 1871 1872
	if (mv88e6xxx_bridge_map(chip, br) ||
	    mv88e6xxx_port_vlan_map(chip, port))
		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
1873
	mutex_unlock(&chip->reg_lock);
1874 1875
}

1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905
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);
}

1906 1907 1908 1909 1910 1911 1912 1913
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->reset)
		return chip->info->ops->reset(chip);

	return 0;
}

1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926
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);
	}
}

1927
static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1928
{
1929
	int i, err;
1930

1931
	/* Set all ports to the Disabled state */
1932
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
1933
		err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
1934 1935
		if (err)
			return err;
1936 1937
	}

1938 1939 1940
	/* Wait for transmit queues to drain,
	 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
	 */
1941 1942
	usleep_range(2000, 4000);

1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953
	return 0;
}

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

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

1954
	mv88e6xxx_hardware_reset(chip);
1955

1956
	return mv88e6xxx_software_reset(chip);
1957 1958
}

1959
static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
1960 1961
				   enum mv88e6xxx_frame_mode frame,
				   enum mv88e6xxx_egress_mode egress, u16 etype)
1962 1963 1964
{
	int err;

1965 1966 1967 1968
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
1969 1970 1971
	if (err)
		return err;

1972 1973 1974 1975 1976 1977 1978 1979
	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;
1980 1981
}

1982
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1983
{
1984
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
1985
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
1986
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
1987
}
1988

1989 1990 1991
static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
1992
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
1993
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
1994
}
1995

1996 1997 1998 1999
static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port,
				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
2000 2001
				       MV88E6XXX_EGRESS_MODE_ETHERTYPE,
				       ETH_P_EDSA);
2002
}
2003

2004 2005 2006 2007
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);
2008

2009
	if (dsa_is_user_port(chip->ds, port))
2010
		return mv88e6xxx_set_port_mode_normal(chip, port);
2011

2012 2013 2014
	/* 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);
2015

2016 2017
	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
		return mv88e6xxx_set_port_mode_edsa(chip, port);
2018

2019
	return -EINVAL;
2020 2021
}

2022
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2023
{
2024
	bool message = dsa_is_dsa_port(chip->ds, port);
2025

2026
	return mv88e6xxx_port_set_message_port(chip, port, message);
2027
}
2028

2029
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2030
{
2031 2032
	struct dsa_switch *ds = chip->ds;
	bool flood;
2033

2034
	/* Upstream ports flood frames with unknown unicast or multicast DA */
2035
	flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
2036 2037 2038
	if (chip->info->ops->port_set_egress_floods)
		return chip->info->ops->port_set_egress_floods(chip, port,
							       flood, flood);
2039

2040
	return 0;
2041 2042
}

2043 2044 2045
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
2046 2047
	if (chip->info->ops->serdes_power)
		return chip->info->ops->serdes_power(chip, port, on);
2048

2049
	return 0;
2050 2051
}

2052 2053 2054 2055 2056 2057
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

2058
	upstream_port = dsa_upstream_port(ds, port);
2059 2060 2061 2062 2063 2064 2065
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081
	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;
		}
	}

2082 2083 2084
	return 0;
}

2085
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
2086
{
2087
	struct dsa_switch *ds = chip->ds;
2088
	int err;
2089
	u16 reg;
2090

2091 2092 2093 2094 2095 2096 2097
	/* 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,
2098
					       PAUSE_OFF,
2099 2100 2101 2102
					       PHY_INTERFACE_MODE_NA);
	else
		err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
					       SPEED_UNFORCED, DUPLEX_UNFORCED,
2103
					       PAUSE_ON,
2104 2105 2106
					       PHY_INTERFACE_MODE_NA);
	if (err)
		return err;
2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121

	/* 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.
	 */
2122 2123 2124 2125
	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);
2126 2127
	if (err)
		return err;
2128

2129
	err = mv88e6xxx_setup_port_mode(chip, port);
2130 2131
	if (err)
		return err;
2132

2133
	err = mv88e6xxx_setup_egress_floods(chip, port);
2134 2135 2136
	if (err)
		return err;

2137 2138 2139
	/* 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.
2140
	 */
2141 2142 2143 2144 2145
	if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
		err = mv88e6xxx_serdes_power(chip, port, true);
		if (err)
			return err;
	}
2146

2147
	/* Port Control 2: don't force a good FCS, set the maximum frame size to
2148
	 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
2149 2150 2151
	 * 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.
2152
	 */
2153 2154 2155
	err = mv88e6xxx_port_set_map_da(chip, port);
	if (err)
		return err;
2156

2157 2158 2159
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
2160

2161
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
2162
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
2163 2164 2165
	if (err)
		return err;

2166 2167
	if (chip->info->ops->port_set_jumbo_size) {
		err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
2168 2169 2170 2171
		if (err)
			return err;
	}

2172 2173 2174 2175 2176
	/* 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.
	 */
2177
	reg = 1 << port;
2178 2179
	/* Disable learning for CPU port */
	if (dsa_is_cpu_port(ds, port))
2180
		reg = 0;
2181

2182 2183
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
2184 2185
	if (err)
		return err;
2186 2187

	/* Egress rate control 2: disable egress rate control. */
2188 2189
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
				   0x0000);
2190 2191
	if (err)
		return err;
2192

2193 2194
	if (chip->info->ops->port_pause_limit) {
		err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
2195 2196
		if (err)
			return err;
2197
	}
2198

2199 2200 2201 2202 2203 2204
	if (chip->info->ops->port_disable_learn_limit) {
		err = chip->info->ops->port_disable_learn_limit(chip, port);
		if (err)
			return err;
	}

2205 2206
	if (chip->info->ops->port_disable_pri_override) {
		err = chip->info->ops->port_disable_pri_override(chip, port);
2207 2208
		if (err)
			return err;
2209
	}
2210

2211 2212
	if (chip->info->ops->port_tag_remap) {
		err = chip->info->ops->port_tag_remap(chip, port);
2213 2214
		if (err)
			return err;
2215 2216
	}

2217 2218
	if (chip->info->ops->port_egress_rate_limiting) {
		err = chip->info->ops->port_egress_rate_limiting(chip, port);
2219 2220
		if (err)
			return err;
2221 2222
	}

2223
	err = mv88e6xxx_setup_message_port(chip, port);
2224 2225
	if (err)
		return err;
2226

2227
	/* Port based VLAN map: give each port the same default address
2228 2229
	 * database, and allow bidirectional communication between the
	 * CPU and DSA port(s), and the other ports.
2230
	 */
2231
	err = mv88e6xxx_port_set_fid(chip, port, 0);
2232 2233
	if (err)
		return err;
2234

2235
	err = mv88e6xxx_port_vlan_map(chip, port);
2236 2237
	if (err)
		return err;
2238 2239 2240 2241

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

2245 2246 2247 2248
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
2249
	int err;
2250 2251

	mutex_lock(&chip->reg_lock);
2252
	err = mv88e6xxx_serdes_power(chip, port, true);
2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263
	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);
2264 2265
	if (mv88e6xxx_serdes_power(chip, port, false))
		dev_err(chip->dev, "failed to power off SERDES\n");
2266 2267 2268
	mutex_unlock(&chip->reg_lock);
}

2269 2270 2271
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
2272
	struct mv88e6xxx_chip *chip = ds->priv;
2273 2274 2275
	int err;

	mutex_lock(&chip->reg_lock);
2276
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2277 2278 2279 2280 2281
	mutex_unlock(&chip->reg_lock);

	return err;
}

2282
static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
2283
{
2284
	int err;
2285

2286
	/* Initialize the statistics unit */
2287 2288 2289 2290 2291
	if (chip->info->ops->stats_set_histogram) {
		err = chip->info->ops->stats_set_histogram(chip);
		if (err)
			return err;
	}
2292

2293
	return mv88e6xxx_g1_stats_clear(chip);
2294 2295
}

2296
static int mv88e6xxx_setup(struct dsa_switch *ds)
2297
{
V
Vivien Didelot 已提交
2298
	struct mv88e6xxx_chip *chip = ds->priv;
2299
	int err;
2300 2301
	int i;

2302
	chip->ds = ds;
2303
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
2304

2305
	mutex_lock(&chip->reg_lock);
2306

2307
	/* Setup Switch Port Registers */
2308
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2309 2310 2311
		if (dsa_is_unused_port(ds, i))
			continue;

2312 2313 2314 2315 2316
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

2317 2318 2319 2320
	err = mv88e6xxx_irl_setup(chip);
	if (err)
		goto unlock;

2321 2322 2323 2324
	err = mv88e6xxx_mac_setup(chip);
	if (err)
		goto unlock;

2325 2326 2327 2328
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

2329 2330 2331 2332
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

2333 2334 2335 2336
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

2337 2338 2339 2340
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

2341 2342 2343 2344
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

2345 2346 2347 2348
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

2349 2350 2351 2352
	err = mv88e6xxx_rmu_setup(chip);
	if (err)
		goto unlock;

2353 2354 2355
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
2356

2357 2358 2359 2360
	err = mv88e6xxx_trunk_setup(chip);
	if (err)
		goto unlock;

2361 2362 2363 2364
	err = mv88e6xxx_devmap_setup(chip);
	if (err)
		goto unlock;

2365 2366 2367 2368
	err = mv88e6xxx_pri_setup(chip);
	if (err)
		goto unlock;

2369
	/* Setup PTP Hardware Clock and timestamping */
2370 2371 2372 2373
	if (chip->info->ptp_support) {
		err = mv88e6xxx_ptp_setup(chip);
		if (err)
			goto unlock;
2374 2375 2376 2377

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
2378 2379
	}

2380 2381 2382 2383
	err = mv88e6xxx_stats_setup(chip);
	if (err)
		goto unlock;

2384
unlock:
2385
	mutex_unlock(&chip->reg_lock);
2386

2387
	return err;
2388 2389
}

2390
static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
2391
{
2392 2393
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2394 2395
	u16 val;
	int err;
2396

2397 2398 2399
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

2400
	mutex_lock(&chip->reg_lock);
2401
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
2402
	mutex_unlock(&chip->reg_lock);
2403

2404 2405 2406 2407 2408
	if (reg == MII_PHYSID2) {
		/* Some internal PHYS don't have a model number.  Use
		 * the mv88e6390 family model number instead.
		 */
		if (!(val & 0x3f0))
2409
			val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
2410 2411
	}

2412
	return err ? err : val;
2413 2414
}

2415
static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
2416
{
2417 2418
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2419
	int err;
2420

2421 2422 2423
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

2424
	mutex_lock(&chip->reg_lock);
2425
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
2426
	mutex_unlock(&chip->reg_lock);
2427 2428

	return err;
2429 2430
}

2431
static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
2432 2433
				   struct device_node *np,
				   bool external)
2434 2435
{
	static int index;
2436
	struct mv88e6xxx_mdio_bus *mdio_bus;
2437 2438 2439
	struct mii_bus *bus;
	int err;

2440 2441 2442 2443 2444 2445 2446 2447 2448
	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;
	}

2449
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
2450 2451 2452
	if (!bus)
		return -ENOMEM;

2453
	mdio_bus = bus->priv;
2454
	mdio_bus->bus = bus;
2455
	mdio_bus->chip = chip;
2456 2457
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
2458

2459 2460
	if (np) {
		bus->name = np->full_name;
2461
		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
2462 2463 2464 2465 2466 2467 2468
	} 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;
2469
	bus->parent = chip->dev;
2470

2471 2472 2473 2474 2475 2476
	if (!external) {
		err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
		if (err)
			return err;
	}

2477
	err = of_mdiobus_register(bus, np);
2478
	if (err) {
2479
		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
2480
		mv88e6xxx_g2_irq_mdio_free(chip, bus);
2481
		return err;
2482
	}
2483 2484 2485 2486 2487

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

	return 0;
2490
}
2491

2492 2493 2494 2495 2496
static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
	{ .compatible = "marvell,mv88e6xxx-mdio-external",
	  .data = (void *)true },
	{ },
};
2497

2498 2499 2500 2501 2502 2503 2504 2505 2506
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;

2507 2508 2509
		if (!mdio_bus->external)
			mv88e6xxx_g2_irq_mdio_free(chip, bus);

2510 2511 2512 2513
		mdiobus_unregister(bus);
	}
}

2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537
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);
2538 2539
			if (err) {
				mv88e6xxx_mdios_unregister(chip);
2540
				return err;
2541
			}
2542 2543 2544 2545
		}
	}

	return 0;
2546 2547
}

2548 2549
static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
2550
	struct mv88e6xxx_chip *chip = ds->priv;
2551 2552 2553 2554 2555 2556 2557

	return chip->eeprom_len;
}

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

2561 2562
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
2563

2564 2565
	mutex_lock(&chip->reg_lock);
	err = chip->info->ops->get_eeprom(chip, eeprom, data);
2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578
	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 已提交
2579
	struct mv88e6xxx_chip *chip = ds->priv;
2580 2581
	int err;

2582 2583 2584
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

2585 2586 2587 2588
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

	mutex_lock(&chip->reg_lock);
2589
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
2590 2591 2592 2593 2594
	mutex_unlock(&chip->reg_lock);

	return err;
}

2595
static const struct mv88e6xxx_ops mv88e6085_ops = {
2596
	/* MV88E6XXX_FAMILY_6097 */
2597 2598
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2599
	.irl_init_all = mv88e6352_g2_irl_init_all,
2600
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2601 2602
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2603
	.port_set_link = mv88e6xxx_port_set_link,
2604
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2605
	.port_set_speed = mv88e6185_port_set_speed,
2606
	.port_tag_remap = mv88e6095_port_tag_remap,
2607
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2608
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2609
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2610
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2611
	.port_pause_limit = mv88e6097_port_pause_limit,
2612
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2613
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2614
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2615
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2616 2617
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2618
	.stats_get_stats = mv88e6095_stats_get_stats,
2619 2620
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2621
	.watchdog_ops = &mv88e6097_watchdog_ops,
2622
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2623
	.pot_clear = mv88e6xxx_g2_pot_clear,
2624 2625
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2626
	.reset = mv88e6185_g1_reset,
2627
	.rmu_disable = mv88e6085_g1_rmu_disable,
2628
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2629
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2630 2631 2632
};

static const struct mv88e6xxx_ops mv88e6095_ops = {
2633
	/* MV88E6XXX_FAMILY_6095 */
2634 2635
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2636
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2637 2638
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2639
	.port_set_link = mv88e6xxx_port_set_link,
2640
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2641
	.port_set_speed = mv88e6185_port_set_speed,
2642
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2643
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2644
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2645
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2646
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2647 2648
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2649
	.stats_get_stats = mv88e6095_stats_get_stats,
2650
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2651 2652
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2653
	.reset = mv88e6185_g1_reset,
2654
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2655
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2656 2657
};

2658
static const struct mv88e6xxx_ops mv88e6097_ops = {
2659
	/* MV88E6XXX_FAMILY_6097 */
2660 2661
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2662
	.irl_init_all = mv88e6352_g2_irl_init_all,
2663 2664 2665 2666 2667 2668
	.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,
2669
	.port_tag_remap = mv88e6095_port_tag_remap,
2670
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2671
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2672
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2673
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2674
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
2675
	.port_pause_limit = mv88e6097_port_pause_limit,
2676
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2677
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2678
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2679
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2680 2681 2682
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
	.stats_get_stats = mv88e6095_stats_get_stats,
2683 2684
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2685
	.watchdog_ops = &mv88e6097_watchdog_ops,
2686
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2687
	.pot_clear = mv88e6xxx_g2_pot_clear,
2688
	.reset = mv88e6352_g1_reset,
2689
	.rmu_disable = mv88e6085_g1_rmu_disable,
2690
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2691
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2692 2693
};

2694
static const struct mv88e6xxx_ops mv88e6123_ops = {
2695
	/* MV88E6XXX_FAMILY_6165 */
2696 2697
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2698
	.irl_init_all = mv88e6352_g2_irl_init_all,
2699
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2700 2701
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2702
	.port_set_link = mv88e6xxx_port_set_link,
2703
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2704
	.port_set_speed = mv88e6185_port_set_speed,
2705
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2706
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2707
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2708
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2709
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2710
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2711 2712
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2713
	.stats_get_stats = mv88e6095_stats_get_stats,
2714 2715
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2716
	.watchdog_ops = &mv88e6097_watchdog_ops,
2717
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2718
	.pot_clear = mv88e6xxx_g2_pot_clear,
2719
	.reset = mv88e6352_g1_reset,
2720
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2721
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2722 2723 2724
};

static const struct mv88e6xxx_ops mv88e6131_ops = {
2725
	/* MV88E6XXX_FAMILY_6185 */
2726 2727
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2728
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2729 2730
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2731
	.port_set_link = mv88e6xxx_port_set_link,
2732
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2733
	.port_set_speed = mv88e6185_port_set_speed,
2734
	.port_tag_remap = mv88e6095_port_tag_remap,
2735
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2736
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2737
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2738
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2739
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2740
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2741
	.port_pause_limit = mv88e6097_port_pause_limit,
2742
	.port_set_pause = mv88e6185_port_set_pause,
2743
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2744
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2745 2746
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2747
	.stats_get_stats = mv88e6095_stats_get_stats,
2748 2749
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2750
	.watchdog_ops = &mv88e6097_watchdog_ops,
2751
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2752
	.ppu_enable = mv88e6185_g1_ppu_enable,
2753
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
2754
	.ppu_disable = mv88e6185_g1_ppu_disable,
2755
	.reset = mv88e6185_g1_reset,
2756
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2757
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2758 2759
};

2760 2761
static const struct mv88e6xxx_ops mv88e6141_ops = {
	/* MV88E6XXX_FAMILY_6341 */
2762 2763
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2764
	.irl_init_all = mv88e6352_g2_irl_init_all,
2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
	.port_set_speed = mv88e6390_port_set_speed,
	.port_tag_remap = mv88e6095_port_tag_remap,
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2778
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2779
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2780
	.port_pause_limit = mv88e6097_port_pause_limit,
2781 2782 2783
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
2784
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2785 2786 2787
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
2788 2789
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
2790 2791
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
2792
	.pot_clear = mv88e6xxx_g2_pot_clear,
2793
	.reset = mv88e6352_g1_reset,
2794
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2795
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2796
	.serdes_power = mv88e6341_serdes_power,
2797
	.gpio_ops = &mv88e6352_gpio_ops,
2798 2799
};

2800
static const struct mv88e6xxx_ops mv88e6161_ops = {
2801
	/* MV88E6XXX_FAMILY_6165 */
2802 2803
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2804
	.irl_init_all = mv88e6352_g2_irl_init_all,
2805
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2806 2807
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2808
	.port_set_link = mv88e6xxx_port_set_link,
2809
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2810
	.port_set_speed = mv88e6185_port_set_speed,
2811
	.port_tag_remap = mv88e6095_port_tag_remap,
2812
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2813
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2814
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2815
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2816
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2817
	.port_pause_limit = mv88e6097_port_pause_limit,
2818
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2819
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2820
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2821
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2822 2823
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2824
	.stats_get_stats = mv88e6095_stats_get_stats,
2825 2826
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2827
	.watchdog_ops = &mv88e6097_watchdog_ops,
2828
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2829
	.pot_clear = mv88e6xxx_g2_pot_clear,
2830
	.reset = mv88e6352_g1_reset,
2831
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2832
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2833
	.avb_ops = &mv88e6165_avb_ops,
2834
	.ptp_ops = &mv88e6165_ptp_ops,
2835 2836 2837
};

static const struct mv88e6xxx_ops mv88e6165_ops = {
2838
	/* MV88E6XXX_FAMILY_6165 */
2839 2840
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2841
	.irl_init_all = mv88e6352_g2_irl_init_all,
2842
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2843 2844
	.phy_read = mv88e6165_phy_read,
	.phy_write = mv88e6165_phy_write,
2845
	.port_set_link = mv88e6xxx_port_set_link,
2846
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2847
	.port_set_speed = mv88e6185_port_set_speed,
2848
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2849
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2850
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2851
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2852 2853
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2854
	.stats_get_stats = mv88e6095_stats_get_stats,
2855 2856
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2857
	.watchdog_ops = &mv88e6097_watchdog_ops,
2858
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2859
	.pot_clear = mv88e6xxx_g2_pot_clear,
2860
	.reset = mv88e6352_g1_reset,
2861
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2862
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2863
	.avb_ops = &mv88e6165_avb_ops,
2864
	.ptp_ops = &mv88e6165_ptp_ops,
2865 2866 2867
};

static const struct mv88e6xxx_ops mv88e6171_ops = {
2868
	/* MV88E6XXX_FAMILY_6351 */
2869 2870
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2871
	.irl_init_all = mv88e6352_g2_irl_init_all,
2872
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2873 2874
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2875
	.port_set_link = mv88e6xxx_port_set_link,
2876
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2877
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
2878
	.port_set_speed = mv88e6185_port_set_speed,
2879
	.port_tag_remap = mv88e6095_port_tag_remap,
2880
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2881
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2882
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2883
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2884
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2885
	.port_pause_limit = mv88e6097_port_pause_limit,
2886
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2887
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2888
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2889
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2890 2891
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2892
	.stats_get_stats = mv88e6095_stats_get_stats,
2893 2894
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2895
	.watchdog_ops = &mv88e6097_watchdog_ops,
2896
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2897
	.pot_clear = mv88e6xxx_g2_pot_clear,
2898
	.reset = mv88e6352_g1_reset,
2899
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2900
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2901 2902 2903
};

static const struct mv88e6xxx_ops mv88e6172_ops = {
2904
	/* MV88E6XXX_FAMILY_6352 */
2905 2906
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2907
	.irl_init_all = mv88e6352_g2_irl_init_all,
2908 2909
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
2910
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2911 2912
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2913
	.port_set_link = mv88e6xxx_port_set_link,
2914
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2915
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
2916
	.port_set_speed = mv88e6352_port_set_speed,
2917
	.port_tag_remap = mv88e6095_port_tag_remap,
2918
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2919
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2920
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2921
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2922
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2923
	.port_pause_limit = mv88e6097_port_pause_limit,
2924
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2925
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2926
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2927
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2928 2929
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2930
	.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 = mv88e6352_g1_rmu_disable,
2938
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2939
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2940
	.serdes_power = mv88e6352_serdes_power,
2941
	.gpio_ops = &mv88e6352_gpio_ops,
2942 2943 2944
};

static const struct mv88e6xxx_ops mv88e6175_ops = {
2945
	/* MV88E6XXX_FAMILY_6351 */
2946 2947
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2948
	.irl_init_all = mv88e6352_g2_irl_init_all,
2949
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2950 2951
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2952
	.port_set_link = mv88e6xxx_port_set_link,
2953
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2954
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
2955
	.port_set_speed = mv88e6185_port_set_speed,
2956
	.port_tag_remap = mv88e6095_port_tag_remap,
2957
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2958
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2959
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2960
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2961
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2962
	.port_pause_limit = mv88e6097_port_pause_limit,
2963
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2964
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2965
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2966
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2967 2968
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2969
	.stats_get_stats = mv88e6095_stats_get_stats,
2970 2971
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2972
	.watchdog_ops = &mv88e6097_watchdog_ops,
2973
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2974
	.pot_clear = mv88e6xxx_g2_pot_clear,
2975
	.reset = mv88e6352_g1_reset,
2976
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2977
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2978 2979 2980
};

static const struct mv88e6xxx_ops mv88e6176_ops = {
2981
	/* MV88E6XXX_FAMILY_6352 */
2982 2983
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2984
	.irl_init_all = mv88e6352_g2_irl_init_all,
2985 2986
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
2987
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2988 2989
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2990
	.port_set_link = mv88e6xxx_port_set_link,
2991
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2992
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
2993
	.port_set_speed = mv88e6352_port_set_speed,
2994
	.port_tag_remap = mv88e6095_port_tag_remap,
2995
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2996
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2997
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2998
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2999
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3000
	.port_pause_limit = mv88e6097_port_pause_limit,
3001
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3002
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3003
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3004
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3005 3006
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3007
	.stats_get_stats = mv88e6095_stats_get_stats,
3008 3009
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3010
	.watchdog_ops = &mv88e6097_watchdog_ops,
3011
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3012
	.pot_clear = mv88e6xxx_g2_pot_clear,
3013
	.reset = mv88e6352_g1_reset,
3014
	.rmu_disable = mv88e6352_g1_rmu_disable,
3015
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3016
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3017
	.serdes_power = mv88e6352_serdes_power,
3018
	.gpio_ops = &mv88e6352_gpio_ops,
3019 3020 3021
};

static const struct mv88e6xxx_ops mv88e6185_ops = {
3022
	/* MV88E6XXX_FAMILY_6185 */
3023 3024
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3025
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3026 3027
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3028
	.port_set_link = mv88e6xxx_port_set_link,
3029
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3030
	.port_set_speed = mv88e6185_port_set_speed,
3031
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
3032
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
3033
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
3034
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
3035
	.port_set_pause = mv88e6185_port_set_pause,
3036
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3037
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3038 3039
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3040
	.stats_get_stats = mv88e6095_stats_get_stats,
3041 3042
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3043
	.watchdog_ops = &mv88e6097_watchdog_ops,
3044
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3045
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
3046 3047
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
3048
	.reset = mv88e6185_g1_reset,
3049
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3050
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3051 3052
};

3053
static const struct mv88e6xxx_ops mv88e6190_ops = {
3054
	/* MV88E6XXX_FAMILY_6390 */
3055
	.irl_init_all = mv88e6390_g2_irl_init_all,
3056 3057
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3058 3059 3060 3061 3062 3063 3064
	.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,
3065
	.port_tag_remap = mv88e6390_port_tag_remap,
3066
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3067
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3068
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3069
	.port_pause_limit = mv88e6390_port_pause_limit,
3070
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3071
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3072
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3073
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3074 3075
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3076
	.stats_get_stats = mv88e6390_stats_get_stats,
3077 3078
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3079
	.watchdog_ops = &mv88e6390_watchdog_ops,
3080
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3081
	.pot_clear = mv88e6xxx_g2_pot_clear,
3082
	.reset = mv88e6352_g1_reset,
3083
	.rmu_disable = mv88e6390_g1_rmu_disable,
3084 3085
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3086
	.serdes_power = mv88e6390_serdes_power,
3087
	.gpio_ops = &mv88e6352_gpio_ops,
3088 3089 3090
};

static const struct mv88e6xxx_ops mv88e6190x_ops = {
3091
	/* MV88E6XXX_FAMILY_6390 */
3092
	.irl_init_all = mv88e6390_g2_irl_init_all,
3093 3094
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3095 3096 3097 3098 3099 3100 3101
	.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,
3102
	.port_tag_remap = mv88e6390_port_tag_remap,
3103
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3104
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3105
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3106
	.port_pause_limit = mv88e6390_port_pause_limit,
3107
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3108
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3109
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3110
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3111 3112
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3113
	.stats_get_stats = mv88e6390_stats_get_stats,
3114 3115
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3116
	.watchdog_ops = &mv88e6390_watchdog_ops,
3117
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3118
	.pot_clear = mv88e6xxx_g2_pot_clear,
3119
	.reset = mv88e6352_g1_reset,
3120
	.rmu_disable = mv88e6390_g1_rmu_disable,
3121 3122
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3123
	.serdes_power = mv88e6390_serdes_power,
3124
	.gpio_ops = &mv88e6352_gpio_ops,
3125 3126 3127
};

static const struct mv88e6xxx_ops mv88e6191_ops = {
3128
	/* MV88E6XXX_FAMILY_6390 */
3129
	.irl_init_all = mv88e6390_g2_irl_init_all,
3130 3131
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3132 3133 3134 3135 3136 3137 3138
	.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,
3139
	.port_tag_remap = mv88e6390_port_tag_remap,
3140
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3141
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3142
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3143
	.port_pause_limit = mv88e6390_port_pause_limit,
3144
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3145
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3146
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3147
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3148 3149
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3150
	.stats_get_stats = mv88e6390_stats_get_stats,
3151 3152
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3153
	.watchdog_ops = &mv88e6390_watchdog_ops,
3154
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3155
	.pot_clear = mv88e6xxx_g2_pot_clear,
3156
	.reset = mv88e6352_g1_reset,
3157
	.rmu_disable = mv88e6390_g1_rmu_disable,
3158 3159
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3160
	.serdes_power = mv88e6390_serdes_power,
3161 3162
	.avb_ops = &mv88e6390_avb_ops,
	.ptp_ops = &mv88e6352_ptp_ops,
3163 3164
};

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

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

3248
static const struct mv88e6xxx_ops mv88e6320_ops = {
3249
	/* MV88E6XXX_FAMILY_6320 */
3250 3251
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3252
	.irl_init_all = mv88e6352_g2_irl_init_all,
3253 3254
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3255
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3256 3257
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3258
	.port_set_link = mv88e6xxx_port_set_link,
3259
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3260
	.port_set_speed = mv88e6185_port_set_speed,
3261
	.port_tag_remap = mv88e6095_port_tag_remap,
3262
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3263
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3264
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3265
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3266
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3267
	.port_pause_limit = mv88e6097_port_pause_limit,
3268
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3269
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3270
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3271
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3272 3273
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3274
	.stats_get_stats = mv88e6320_stats_get_stats,
3275 3276
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3277
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3278
	.pot_clear = mv88e6xxx_g2_pot_clear,
3279
	.reset = mv88e6352_g1_reset,
3280
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3281
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3282
	.gpio_ops = &mv88e6352_gpio_ops,
3283
	.avb_ops = &mv88e6352_avb_ops,
3284
	.ptp_ops = &mv88e6352_ptp_ops,
3285 3286 3287
};

static const struct mv88e6xxx_ops mv88e6321_ops = {
3288
	/* MV88E6XXX_FAMILY_6320 */
3289 3290
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3291
	.irl_init_all = mv88e6352_g2_irl_init_all,
3292 3293
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3294
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3295 3296
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3297
	.port_set_link = mv88e6xxx_port_set_link,
3298
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3299
	.port_set_speed = mv88e6185_port_set_speed,
3300
	.port_tag_remap = mv88e6095_port_tag_remap,
3301
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3302
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3303
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3304
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3305
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3306
	.port_pause_limit = mv88e6097_port_pause_limit,
3307
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3308
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3309
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3310
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3311 3312
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3313
	.stats_get_stats = mv88e6320_stats_get_stats,
3314 3315
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3316
	.reset = mv88e6352_g1_reset,
3317
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3318
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3319
	.gpio_ops = &mv88e6352_gpio_ops,
3320
	.avb_ops = &mv88e6352_avb_ops,
3321
	.ptp_ops = &mv88e6352_ptp_ops,
3322 3323
};

3324 3325
static const struct mv88e6xxx_ops mv88e6341_ops = {
	/* MV88E6XXX_FAMILY_6341 */
3326 3327
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3328
	.irl_init_all = mv88e6352_g2_irl_init_all,
3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
	.port_set_speed = mv88e6390_port_set_speed,
	.port_tag_remap = mv88e6095_port_tag_remap,
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3342
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3343
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3344
	.port_pause_limit = mv88e6097_port_pause_limit,
3345 3346 3347
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3348
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3349 3350 3351
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
3352 3353
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3354 3355
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
3356
	.pot_clear = mv88e6xxx_g2_pot_clear,
3357
	.reset = mv88e6352_g1_reset,
3358
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3359
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3360
	.serdes_power = mv88e6341_serdes_power,
3361
	.gpio_ops = &mv88e6352_gpio_ops,
3362
	.avb_ops = &mv88e6390_avb_ops,
3363
	.ptp_ops = &mv88e6352_ptp_ops,
3364 3365
};

3366
static const struct mv88e6xxx_ops mv88e6350_ops = {
3367
	/* MV88E6XXX_FAMILY_6351 */
3368 3369
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3370
	.irl_init_all = mv88e6352_g2_irl_init_all,
3371
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3372 3373
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3374
	.port_set_link = mv88e6xxx_port_set_link,
3375
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3376
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3377
	.port_set_speed = mv88e6185_port_set_speed,
3378
	.port_tag_remap = mv88e6095_port_tag_remap,
3379
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3380
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3381
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3382
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3383
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3384
	.port_pause_limit = mv88e6097_port_pause_limit,
3385
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3386
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3387
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3388
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3389 3390
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3391
	.stats_get_stats = mv88e6095_stats_get_stats,
3392 3393
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3394
	.watchdog_ops = &mv88e6097_watchdog_ops,
3395
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3396
	.pot_clear = mv88e6xxx_g2_pot_clear,
3397
	.reset = mv88e6352_g1_reset,
3398
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3399
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3400 3401 3402
};

static const struct mv88e6xxx_ops mv88e6351_ops = {
3403
	/* MV88E6XXX_FAMILY_6351 */
3404 3405
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3406
	.irl_init_all = mv88e6352_g2_irl_init_all,
3407
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3408 3409
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3410
	.port_set_link = mv88e6xxx_port_set_link,
3411
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3412
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3413
	.port_set_speed = mv88e6185_port_set_speed,
3414
	.port_tag_remap = mv88e6095_port_tag_remap,
3415
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3416
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3417
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3418
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3419
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3420
	.port_pause_limit = mv88e6097_port_pause_limit,
3421
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3422
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3423
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3424
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3425 3426
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3427
	.stats_get_stats = mv88e6095_stats_get_stats,
3428 3429
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3430
	.watchdog_ops = &mv88e6097_watchdog_ops,
3431
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3432
	.pot_clear = mv88e6xxx_g2_pot_clear,
3433
	.reset = mv88e6352_g1_reset,
3434
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3435
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3436
	.avb_ops = &mv88e6352_avb_ops,
3437
	.ptp_ops = &mv88e6352_ptp_ops,
3438 3439 3440
};

static const struct mv88e6xxx_ops mv88e6352_ops = {
3441
	/* MV88E6XXX_FAMILY_6352 */
3442 3443
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3444
	.irl_init_all = mv88e6352_g2_irl_init_all,
3445 3446
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3447
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3448 3449
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3450
	.port_set_link = mv88e6xxx_port_set_link,
3451
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3452
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3453
	.port_set_speed = mv88e6352_port_set_speed,
3454
	.port_tag_remap = mv88e6095_port_tag_remap,
3455
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3456
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3457
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3458
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3459
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3460
	.port_pause_limit = mv88e6097_port_pause_limit,
3461
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3462
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3463
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3464
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3465 3466
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3467
	.stats_get_stats = mv88e6095_stats_get_stats,
3468 3469
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3470
	.watchdog_ops = &mv88e6097_watchdog_ops,
3471
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3472
	.pot_clear = mv88e6xxx_g2_pot_clear,
3473
	.reset = mv88e6352_g1_reset,
3474
	.rmu_disable = mv88e6352_g1_rmu_disable,
3475
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3476
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3477
	.serdes_power = mv88e6352_serdes_power,
3478
	.gpio_ops = &mv88e6352_gpio_ops,
3479
	.avb_ops = &mv88e6352_avb_ops,
3480
	.ptp_ops = &mv88e6352_ptp_ops,
3481 3482 3483
	.serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
	.serdes_get_strings = mv88e6352_serdes_get_strings,
	.serdes_get_stats = mv88e6352_serdes_get_stats,
3484 3485
};

3486
static const struct mv88e6xxx_ops mv88e6390_ops = {
3487
	/* MV88E6XXX_FAMILY_6390 */
3488
	.irl_init_all = mv88e6390_g2_irl_init_all,
3489 3490
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3491 3492 3493 3494 3495 3496 3497
	.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,
3498
	.port_tag_remap = mv88e6390_port_tag_remap,
3499
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3500
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3501
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3502
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3503
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3504
	.port_pause_limit = mv88e6390_port_pause_limit,
3505
	.port_set_cmode = mv88e6390x_port_set_cmode,
3506
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3507
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3508
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3509
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3510 3511
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3512
	.stats_get_stats = mv88e6390_stats_get_stats,
3513 3514
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3515
	.watchdog_ops = &mv88e6390_watchdog_ops,
3516
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3517
	.pot_clear = mv88e6xxx_g2_pot_clear,
3518
	.reset = mv88e6352_g1_reset,
3519
	.rmu_disable = mv88e6390_g1_rmu_disable,
3520 3521
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3522
	.serdes_power = mv88e6390_serdes_power,
3523
	.gpio_ops = &mv88e6352_gpio_ops,
3524
	.avb_ops = &mv88e6390_avb_ops,
3525
	.ptp_ops = &mv88e6352_ptp_ops,
3526 3527 3528
};

static const struct mv88e6xxx_ops mv88e6390x_ops = {
3529
	/* MV88E6XXX_FAMILY_6390 */
3530
	.irl_init_all = mv88e6390_g2_irl_init_all,
3531 3532
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3533 3534 3535 3536 3537 3538 3539
	.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,
3540
	.port_tag_remap = mv88e6390_port_tag_remap,
3541
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3542
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3543
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3544
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3545
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3546
	.port_pause_limit = mv88e6390_port_pause_limit,
3547
	.port_set_cmode = mv88e6390x_port_set_cmode,
3548
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3549
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3550
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3551
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3552 3553
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3554
	.stats_get_stats = mv88e6390_stats_get_stats,
3555 3556
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3557
	.watchdog_ops = &mv88e6390_watchdog_ops,
3558
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3559
	.pot_clear = mv88e6xxx_g2_pot_clear,
3560
	.reset = mv88e6352_g1_reset,
3561
	.rmu_disable = mv88e6390_g1_rmu_disable,
3562 3563
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3564
	.serdes_power = mv88e6390_serdes_power,
3565
	.gpio_ops = &mv88e6352_gpio_ops,
3566
	.avb_ops = &mv88e6390_avb_ops,
3567
	.ptp_ops = &mv88e6352_ptp_ops,
3568 3569
};

3570 3571
static const struct mv88e6xxx_info mv88e6xxx_table[] = {
	[MV88E6085] = {
3572
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
3573 3574 3575 3576
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6085",
		.num_databases = 4096,
		.num_ports = 10,
3577
		.num_internal_phys = 5,
3578
		.max_vid = 4095,
3579
		.port_base_addr = 0x10,
3580
		.phy_base_addr = 0x0,
3581
		.global1_addr = 0x1b,
3582
		.global2_addr = 0x1c,
3583
		.age_time_coeff = 15000,
3584
		.g1_irqs = 8,
3585
		.g2_irqs = 10,
3586
		.atu_move_port_mask = 0xf,
3587
		.pvt = true,
3588
		.multi_chip = true,
3589
		.tag_protocol = DSA_TAG_PROTO_DSA,
3590
		.ops = &mv88e6085_ops,
3591 3592 3593
	},

	[MV88E6095] = {
3594
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
3595 3596 3597 3598
		.family = MV88E6XXX_FAMILY_6095,
		.name = "Marvell 88E6095/88E6095F",
		.num_databases = 256,
		.num_ports = 11,
3599
		.num_internal_phys = 0,
3600
		.max_vid = 4095,
3601
		.port_base_addr = 0x10,
3602
		.phy_base_addr = 0x0,
3603
		.global1_addr = 0x1b,
3604
		.global2_addr = 0x1c,
3605
		.age_time_coeff = 15000,
3606
		.g1_irqs = 8,
3607
		.atu_move_port_mask = 0xf,
3608
		.multi_chip = true,
3609
		.tag_protocol = DSA_TAG_PROTO_DSA,
3610
		.ops = &mv88e6095_ops,
3611 3612
	},

3613
	[MV88E6097] = {
3614
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
3615 3616 3617 3618
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6097/88E6097F",
		.num_databases = 4096,
		.num_ports = 11,
3619
		.num_internal_phys = 8,
3620
		.max_vid = 4095,
3621
		.port_base_addr = 0x10,
3622
		.phy_base_addr = 0x0,
3623
		.global1_addr = 0x1b,
3624
		.global2_addr = 0x1c,
3625
		.age_time_coeff = 15000,
3626
		.g1_irqs = 8,
3627
		.g2_irqs = 10,
3628
		.atu_move_port_mask = 0xf,
3629
		.pvt = true,
3630
		.multi_chip = true,
3631
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3632 3633 3634
		.ops = &mv88e6097_ops,
	},

3635
	[MV88E6123] = {
3636
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
3637 3638 3639 3640
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6123",
		.num_databases = 4096,
		.num_ports = 3,
3641
		.num_internal_phys = 5,
3642
		.max_vid = 4095,
3643
		.port_base_addr = 0x10,
3644
		.phy_base_addr = 0x0,
3645
		.global1_addr = 0x1b,
3646
		.global2_addr = 0x1c,
3647
		.age_time_coeff = 15000,
3648
		.g1_irqs = 9,
3649
		.g2_irqs = 10,
3650
		.atu_move_port_mask = 0xf,
3651
		.pvt = true,
3652
		.multi_chip = true,
3653
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3654
		.ops = &mv88e6123_ops,
3655 3656 3657
	},

	[MV88E6131] = {
3658
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
3659 3660 3661 3662
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6131",
		.num_databases = 256,
		.num_ports = 8,
3663
		.num_internal_phys = 0,
3664
		.max_vid = 4095,
3665
		.port_base_addr = 0x10,
3666
		.phy_base_addr = 0x0,
3667
		.global1_addr = 0x1b,
3668
		.global2_addr = 0x1c,
3669
		.age_time_coeff = 15000,
3670
		.g1_irqs = 9,
3671
		.atu_move_port_mask = 0xf,
3672
		.multi_chip = true,
3673
		.tag_protocol = DSA_TAG_PROTO_DSA,
3674
		.ops = &mv88e6131_ops,
3675 3676
	},

3677
	[MV88E6141] = {
3678
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
3679
		.family = MV88E6XXX_FAMILY_6341,
3680
		.name = "Marvell 88E6141",
3681 3682
		.num_databases = 4096,
		.num_ports = 6,
3683
		.num_internal_phys = 5,
3684
		.num_gpio = 11,
3685
		.max_vid = 4095,
3686
		.port_base_addr = 0x10,
3687
		.phy_base_addr = 0x10,
3688
		.global1_addr = 0x1b,
3689
		.global2_addr = 0x1c,
3690 3691
		.age_time_coeff = 3750,
		.atu_move_port_mask = 0x1f,
3692
		.g1_irqs = 9,
3693
		.g2_irqs = 10,
3694
		.pvt = true,
3695
		.multi_chip = true,
3696 3697 3698 3699
		.tag_protocol = DSA_TAG_PROTO_EDSA,
		.ops = &mv88e6141_ops,
	},

3700
	[MV88E6161] = {
3701
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
3702 3703 3704 3705
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6161",
		.num_databases = 4096,
		.num_ports = 6,
3706
		.num_internal_phys = 5,
3707
		.max_vid = 4095,
3708
		.port_base_addr = 0x10,
3709
		.phy_base_addr = 0x0,
3710
		.global1_addr = 0x1b,
3711
		.global2_addr = 0x1c,
3712
		.age_time_coeff = 15000,
3713
		.g1_irqs = 9,
3714
		.g2_irqs = 10,
3715
		.atu_move_port_mask = 0xf,
3716
		.pvt = true,
3717
		.multi_chip = true,
3718
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3719
		.ptp_support = true,
3720
		.ops = &mv88e6161_ops,
3721 3722 3723
	},

	[MV88E6165] = {
3724
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
3725 3726 3727 3728
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6165",
		.num_databases = 4096,
		.num_ports = 6,
3729
		.num_internal_phys = 0,
3730
		.max_vid = 4095,
3731
		.port_base_addr = 0x10,
3732
		.phy_base_addr = 0x0,
3733
		.global1_addr = 0x1b,
3734
		.global2_addr = 0x1c,
3735
		.age_time_coeff = 15000,
3736
		.g1_irqs = 9,
3737
		.g2_irqs = 10,
3738
		.atu_move_port_mask = 0xf,
3739
		.pvt = true,
3740
		.multi_chip = true,
3741
		.tag_protocol = DSA_TAG_PROTO_DSA,
3742
		.ptp_support = true,
3743
		.ops = &mv88e6165_ops,
3744 3745 3746
	},

	[MV88E6171] = {
3747
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
3748 3749 3750 3751
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6171",
		.num_databases = 4096,
		.num_ports = 7,
3752
		.num_internal_phys = 5,
3753
		.max_vid = 4095,
3754
		.port_base_addr = 0x10,
3755
		.phy_base_addr = 0x0,
3756
		.global1_addr = 0x1b,
3757
		.global2_addr = 0x1c,
3758
		.age_time_coeff = 15000,
3759
		.g1_irqs = 9,
3760
		.g2_irqs = 10,
3761
		.atu_move_port_mask = 0xf,
3762
		.pvt = true,
3763
		.multi_chip = true,
3764
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3765
		.ops = &mv88e6171_ops,
3766 3767 3768
	},

	[MV88E6172] = {
3769
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
3770 3771 3772 3773
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6172",
		.num_databases = 4096,
		.num_ports = 7,
3774
		.num_internal_phys = 5,
3775
		.num_gpio = 15,
3776
		.max_vid = 4095,
3777
		.port_base_addr = 0x10,
3778
		.phy_base_addr = 0x0,
3779
		.global1_addr = 0x1b,
3780
		.global2_addr = 0x1c,
3781
		.age_time_coeff = 15000,
3782
		.g1_irqs = 9,
3783
		.g2_irqs = 10,
3784
		.atu_move_port_mask = 0xf,
3785
		.pvt = true,
3786
		.multi_chip = true,
3787
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3788
		.ops = &mv88e6172_ops,
3789 3790 3791
	},

	[MV88E6175] = {
3792
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
3793 3794 3795 3796
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6175",
		.num_databases = 4096,
		.num_ports = 7,
3797
		.num_internal_phys = 5,
3798
		.max_vid = 4095,
3799
		.port_base_addr = 0x10,
3800
		.phy_base_addr = 0x0,
3801
		.global1_addr = 0x1b,
3802
		.global2_addr = 0x1c,
3803
		.age_time_coeff = 15000,
3804
		.g1_irqs = 9,
3805
		.g2_irqs = 10,
3806
		.atu_move_port_mask = 0xf,
3807
		.pvt = true,
3808
		.multi_chip = true,
3809
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3810
		.ops = &mv88e6175_ops,
3811 3812 3813
	},

	[MV88E6176] = {
3814
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
3815 3816 3817 3818
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6176",
		.num_databases = 4096,
		.num_ports = 7,
3819
		.num_internal_phys = 5,
3820
		.num_gpio = 15,
3821
		.max_vid = 4095,
3822
		.port_base_addr = 0x10,
3823
		.phy_base_addr = 0x0,
3824
		.global1_addr = 0x1b,
3825
		.global2_addr = 0x1c,
3826
		.age_time_coeff = 15000,
3827
		.g1_irqs = 9,
3828
		.g2_irqs = 10,
3829
		.atu_move_port_mask = 0xf,
3830
		.pvt = true,
3831
		.multi_chip = true,
3832
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3833
		.ops = &mv88e6176_ops,
3834 3835 3836
	},

	[MV88E6185] = {
3837
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
3838 3839 3840 3841
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6185",
		.num_databases = 256,
		.num_ports = 10,
3842
		.num_internal_phys = 0,
3843
		.max_vid = 4095,
3844
		.port_base_addr = 0x10,
3845
		.phy_base_addr = 0x0,
3846
		.global1_addr = 0x1b,
3847
		.global2_addr = 0x1c,
3848
		.age_time_coeff = 15000,
3849
		.g1_irqs = 8,
3850
		.atu_move_port_mask = 0xf,
3851
		.multi_chip = true,
3852
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3853
		.ops = &mv88e6185_ops,
3854 3855
	},

3856
	[MV88E6190] = {
3857
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
3858 3859 3860 3861
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3862
		.num_internal_phys = 11,
3863
		.num_gpio = 16,
3864
		.max_vid = 8191,
3865
		.port_base_addr = 0x0,
3866
		.phy_base_addr = 0x0,
3867
		.global1_addr = 0x1b,
3868
		.global2_addr = 0x1c,
3869
		.tag_protocol = DSA_TAG_PROTO_DSA,
3870
		.age_time_coeff = 3750,
3871
		.g1_irqs = 9,
3872
		.g2_irqs = 14,
3873
		.pvt = true,
3874
		.multi_chip = true,
3875
		.atu_move_port_mask = 0x1f,
3876 3877 3878 3879
		.ops = &mv88e6190_ops,
	},

	[MV88E6190X] = {
3880
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
3881 3882 3883 3884
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3885
		.num_internal_phys = 11,
3886
		.num_gpio = 16,
3887
		.max_vid = 8191,
3888
		.port_base_addr = 0x0,
3889
		.phy_base_addr = 0x0,
3890
		.global1_addr = 0x1b,
3891
		.global2_addr = 0x1c,
3892
		.age_time_coeff = 3750,
3893
		.g1_irqs = 9,
3894
		.g2_irqs = 14,
3895
		.atu_move_port_mask = 0x1f,
3896
		.pvt = true,
3897
		.multi_chip = true,
3898
		.tag_protocol = DSA_TAG_PROTO_DSA,
3899 3900 3901 3902
		.ops = &mv88e6190x_ops,
	},

	[MV88E6191] = {
3903
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
3904 3905 3906 3907
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6191",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3908
		.num_internal_phys = 11,
3909
		.max_vid = 8191,
3910
		.port_base_addr = 0x0,
3911
		.phy_base_addr = 0x0,
3912
		.global1_addr = 0x1b,
3913
		.global2_addr = 0x1c,
3914
		.age_time_coeff = 3750,
3915
		.g1_irqs = 9,
3916
		.g2_irqs = 14,
3917
		.atu_move_port_mask = 0x1f,
3918
		.pvt = true,
3919
		.multi_chip = true,
3920
		.tag_protocol = DSA_TAG_PROTO_DSA,
3921
		.ptp_support = true,
3922
		.ops = &mv88e6191_ops,
3923 3924
	},

3925
	[MV88E6240] = {
3926
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
3927 3928 3929 3930
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6240",
		.num_databases = 4096,
		.num_ports = 7,
3931
		.num_internal_phys = 5,
3932
		.num_gpio = 15,
3933
		.max_vid = 4095,
3934
		.port_base_addr = 0x10,
3935
		.phy_base_addr = 0x0,
3936
		.global1_addr = 0x1b,
3937
		.global2_addr = 0x1c,
3938
		.age_time_coeff = 15000,
3939
		.g1_irqs = 9,
3940
		.g2_irqs = 10,
3941
		.atu_move_port_mask = 0xf,
3942
		.pvt = true,
3943
		.multi_chip = true,
3944
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3945
		.ptp_support = true,
3946
		.ops = &mv88e6240_ops,
3947 3948
	},

3949
	[MV88E6290] = {
3950
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
3951 3952 3953 3954
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6290",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3955
		.num_internal_phys = 11,
3956
		.num_gpio = 16,
3957
		.max_vid = 8191,
3958
		.port_base_addr = 0x0,
3959
		.phy_base_addr = 0x0,
3960
		.global1_addr = 0x1b,
3961
		.global2_addr = 0x1c,
3962
		.age_time_coeff = 3750,
3963
		.g1_irqs = 9,
3964
		.g2_irqs = 14,
3965
		.atu_move_port_mask = 0x1f,
3966
		.pvt = true,
3967
		.multi_chip = true,
3968
		.tag_protocol = DSA_TAG_PROTO_DSA,
3969
		.ptp_support = true,
3970 3971 3972
		.ops = &mv88e6290_ops,
	},

3973
	[MV88E6320] = {
3974
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
3975 3976 3977 3978
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6320",
		.num_databases = 4096,
		.num_ports = 7,
3979
		.num_internal_phys = 5,
3980
		.num_gpio = 15,
3981
		.max_vid = 4095,
3982
		.port_base_addr = 0x10,
3983
		.phy_base_addr = 0x0,
3984
		.global1_addr = 0x1b,
3985
		.global2_addr = 0x1c,
3986
		.age_time_coeff = 15000,
3987
		.g1_irqs = 8,
3988
		.g2_irqs = 10,
3989
		.atu_move_port_mask = 0xf,
3990
		.pvt = true,
3991
		.multi_chip = true,
3992
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3993
		.ptp_support = true,
3994
		.ops = &mv88e6320_ops,
3995 3996 3997
	},

	[MV88E6321] = {
3998
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
3999 4000 4001 4002
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6321",
		.num_databases = 4096,
		.num_ports = 7,
4003
		.num_internal_phys = 5,
4004
		.num_gpio = 15,
4005
		.max_vid = 4095,
4006
		.port_base_addr = 0x10,
4007
		.phy_base_addr = 0x0,
4008
		.global1_addr = 0x1b,
4009
		.global2_addr = 0x1c,
4010
		.age_time_coeff = 15000,
4011
		.g1_irqs = 8,
4012
		.g2_irqs = 10,
4013
		.atu_move_port_mask = 0xf,
4014
		.multi_chip = true,
4015
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4016
		.ptp_support = true,
4017
		.ops = &mv88e6321_ops,
4018 4019
	},

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

4044
	[MV88E6350] = {
4045
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
4046 4047 4048 4049
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6350",
		.num_databases = 4096,
		.num_ports = 7,
4050
		.num_internal_phys = 5,
4051
		.max_vid = 4095,
4052
		.port_base_addr = 0x10,
4053
		.phy_base_addr = 0x0,
4054
		.global1_addr = 0x1b,
4055
		.global2_addr = 0x1c,
4056
		.age_time_coeff = 15000,
4057
		.g1_irqs = 9,
4058
		.g2_irqs = 10,
4059
		.atu_move_port_mask = 0xf,
4060
		.pvt = true,
4061
		.multi_chip = true,
4062
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4063
		.ops = &mv88e6350_ops,
4064 4065 4066
	},

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

	[MV88E6352] = {
4089
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
4090 4091 4092 4093
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6352",
		.num_databases = 4096,
		.num_ports = 7,
4094
		.num_internal_phys = 5,
4095
		.num_gpio = 15,
4096
		.max_vid = 4095,
4097
		.port_base_addr = 0x10,
4098
		.phy_base_addr = 0x0,
4099
		.global1_addr = 0x1b,
4100
		.global2_addr = 0x1c,
4101
		.age_time_coeff = 15000,
4102
		.g1_irqs = 9,
4103
		.g2_irqs = 10,
4104
		.atu_move_port_mask = 0xf,
4105
		.pvt = true,
4106
		.multi_chip = true,
4107
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4108
		.ptp_support = true,
4109
		.ops = &mv88e6352_ops,
4110
	},
4111
	[MV88E6390] = {
4112
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
4113 4114 4115 4116
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4117
		.num_internal_phys = 11,
4118
		.num_gpio = 16,
4119
		.max_vid = 8191,
4120
		.port_base_addr = 0x0,
4121
		.phy_base_addr = 0x0,
4122
		.global1_addr = 0x1b,
4123
		.global2_addr = 0x1c,
4124
		.age_time_coeff = 3750,
4125
		.g1_irqs = 9,
4126
		.g2_irqs = 14,
4127
		.atu_move_port_mask = 0x1f,
4128
		.pvt = true,
4129
		.multi_chip = true,
4130
		.tag_protocol = DSA_TAG_PROTO_DSA,
4131
		.ptp_support = true,
4132 4133 4134
		.ops = &mv88e6390_ops,
	},
	[MV88E6390X] = {
4135
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
4136 4137 4138 4139
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4140
		.num_internal_phys = 11,
4141
		.num_gpio = 16,
4142
		.max_vid = 8191,
4143
		.port_base_addr = 0x0,
4144
		.phy_base_addr = 0x0,
4145
		.global1_addr = 0x1b,
4146
		.global2_addr = 0x1c,
4147
		.age_time_coeff = 3750,
4148
		.g1_irqs = 9,
4149
		.g2_irqs = 14,
4150
		.atu_move_port_mask = 0x1f,
4151
		.pvt = true,
4152
		.multi_chip = true,
4153
		.tag_protocol = DSA_TAG_PROTO_DSA,
4154
		.ptp_support = true,
4155 4156
		.ops = &mv88e6390x_ops,
	},
4157 4158
};

4159
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
4160
{
4161
	int i;
4162

4163 4164 4165
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
4166 4167 4168 4169

	return NULL;
}

4170
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
4171 4172
{
	const struct mv88e6xxx_info *info;
4173 4174 4175
	unsigned int prod_num, rev;
	u16 id;
	int err;
4176

4177
	mutex_lock(&chip->reg_lock);
4178
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
4179 4180 4181
	mutex_unlock(&chip->reg_lock);
	if (err)
		return err;
4182

4183 4184
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
4185 4186 4187 4188 4189

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

4190
	/* Update the compatible info with the probed one */
4191
	chip->info = info;
4192

4193 4194 4195 4196
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

4197 4198
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
4199 4200 4201 4202

	return 0;
}

4203
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
4204
{
4205
	struct mv88e6xxx_chip *chip;
4206

4207 4208
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
4209 4210
		return NULL;

4211
	chip->dev = dev;
4212

4213
	mutex_init(&chip->reg_lock);
4214
	INIT_LIST_HEAD(&chip->mdios);
4215

4216
	return chip;
4217 4218
}

4219
static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
4220 4221
			      struct mii_bus *bus, int sw_addr)
{
4222
	if (sw_addr == 0)
4223
		chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
4224
	else if (chip->info->multi_chip)
4225
		chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
4226 4227 4228
	else
		return -EINVAL;

4229 4230
	chip->bus = bus;
	chip->sw_addr = sw_addr;
4231 4232 4233 4234

	return 0;
}

4235 4236
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
							int port)
4237
{
V
Vivien Didelot 已提交
4238
	struct mv88e6xxx_chip *chip = ds->priv;
4239

4240
	return chip->info->tag_protocol;
4241 4242
}

4243
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
4244 4245 4246
static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
				       struct device *host_dev, int sw_addr,
				       void **priv)
4247
{
4248
	struct mv88e6xxx_chip *chip;
4249
	struct mii_bus *bus;
4250
	int err;
4251

4252
	bus = dsa_host_dev_to_mii_bus(host_dev);
4253 4254 4255
	if (!bus)
		return NULL;

4256 4257
	chip = mv88e6xxx_alloc_chip(dsa_dev);
	if (!chip)
4258 4259
		return NULL;

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

4263
	err = mv88e6xxx_smi_init(chip, bus, sw_addr);
4264 4265 4266
	if (err)
		goto free;

4267
	err = mv88e6xxx_detect(chip);
4268
	if (err)
4269
		goto free;
4270

4271 4272 4273 4274 4275 4276
	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_switch_reset(chip);
	mutex_unlock(&chip->reg_lock);
	if (err)
		goto free;

4277 4278
	mv88e6xxx_phy_init(chip);

4279
	err = mv88e6xxx_mdios_register(chip, NULL);
4280
	if (err)
4281
		goto free;
4282

4283
	*priv = chip;
4284

4285
	return chip->info->name;
4286
free:
4287
	devm_kfree(dsa_dev, chip);
4288 4289

	return NULL;
4290
}
4291
#endif
4292

4293
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4294
				      const struct switchdev_obj_port_mdb *mdb)
4295 4296 4297 4298 4299 4300 4301 4302 4303
{
	/* 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,
4304
				   const struct switchdev_obj_port_mdb *mdb)
4305
{
V
Vivien Didelot 已提交
4306
	struct mv88e6xxx_chip *chip = ds->priv;
4307 4308 4309

	mutex_lock(&chip->reg_lock);
	if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4310
					 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
4311 4312
		dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
			port);
4313 4314 4315 4316 4317 4318
	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 已提交
4319
	struct mv88e6xxx_chip *chip = ds->priv;
4320 4321 4322 4323
	int err;

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4324
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
4325 4326 4327 4328 4329
	mutex_unlock(&chip->reg_lock);

	return err;
}

4330
static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
4331
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
4332
	.probe			= mv88e6xxx_drv_probe,
4333
#endif
4334
	.get_tag_protocol	= mv88e6xxx_get_tag_protocol,
4335 4336
	.setup			= mv88e6xxx_setup,
	.adjust_link		= mv88e6xxx_adjust_link,
4337 4338 4339 4340 4341
	.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,
4342 4343 4344
	.get_strings		= mv88e6xxx_get_strings,
	.get_ethtool_stats	= mv88e6xxx_get_ethtool_stats,
	.get_sset_count		= mv88e6xxx_get_sset_count,
4345 4346
	.port_enable		= mv88e6xxx_port_enable,
	.port_disable		= mv88e6xxx_port_disable,
V
Vivien Didelot 已提交
4347 4348
	.get_mac_eee		= mv88e6xxx_get_mac_eee,
	.set_mac_eee		= mv88e6xxx_set_mac_eee,
4349
	.get_eeprom_len		= mv88e6xxx_get_eeprom_len,
4350 4351 4352 4353
	.get_eeprom		= mv88e6xxx_get_eeprom,
	.set_eeprom		= mv88e6xxx_set_eeprom,
	.get_regs_len		= mv88e6xxx_get_regs_len,
	.get_regs		= mv88e6xxx_get_regs,
4354
	.set_ageing_time	= mv88e6xxx_set_ageing_time,
4355 4356 4357
	.port_bridge_join	= mv88e6xxx_port_bridge_join,
	.port_bridge_leave	= mv88e6xxx_port_bridge_leave,
	.port_stp_state_set	= mv88e6xxx_port_stp_state_set,
4358
	.port_fast_age		= mv88e6xxx_port_fast_age,
4359 4360 4361 4362 4363 4364 4365
	.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,
4366 4367 4368
	.port_mdb_prepare       = mv88e6xxx_port_mdb_prepare,
	.port_mdb_add           = mv88e6xxx_port_mdb_add,
	.port_mdb_del           = mv88e6xxx_port_mdb_del,
4369 4370
	.crosschip_bridge_join	= mv88e6xxx_crosschip_bridge_join,
	.crosschip_bridge_leave	= mv88e6xxx_crosschip_bridge_leave,
4371 4372 4373 4374 4375
	.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,
4376 4377
};

4378 4379 4380 4381
static struct dsa_switch_driver mv88e6xxx_switch_drv = {
	.ops			= &mv88e6xxx_switch_ops,
};

4382
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
4383
{
4384
	struct device *dev = chip->dev;
4385 4386
	struct dsa_switch *ds;

4387
	ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
4388 4389 4390
	if (!ds)
		return -ENOMEM;

4391
	ds->priv = chip;
4392
	ds->dev = dev;
4393
	ds->ops = &mv88e6xxx_switch_ops;
4394 4395
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
4396 4397 4398

	dev_set_drvdata(dev, ds);

4399
	return dsa_register_switch(ds);
4400 4401
}

4402
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
4403
{
4404
	dsa_unregister_switch(chip->ds);
4405 4406
}

4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419
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;
}

4420
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
4421
{
4422
	struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
4423
	const struct mv88e6xxx_info *compat_info = NULL;
4424
	struct device *dev = &mdiodev->dev;
4425
	struct device_node *np = dev->of_node;
4426
	struct mv88e6xxx_chip *chip;
4427
	int port;
4428
	int err;
4429

4430 4431 4432
	if (!np && !pdata)
		return -EINVAL;

4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451
	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;
		}
	}

4452 4453 4454
	if (!compat_info)
		return -EINVAL;

4455
	chip = mv88e6xxx_alloc_chip(dev);
4456 4457 4458 4459
	if (!chip) {
		err = -ENOMEM;
		goto out;
	}
4460

4461
	chip->info = compat_info;
4462

4463
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
4464
	if (err)
4465
		goto out;
4466

4467
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4468 4469 4470 4471
	if (IS_ERR(chip->reset)) {
		err = PTR_ERR(chip->reset);
		goto out;
	}
4472

4473
	err = mv88e6xxx_detect(chip);
4474
	if (err)
4475
		goto out;
4476

4477 4478
	mv88e6xxx_phy_init(chip);

4479 4480 4481 4482 4483 4484 4485
	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;
	}
4486

4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498
	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;
	}

4499
	/* Has to be performed before the MDIO bus is created, because
4500
	 * the PHYs will link their interrupts to these interrupt
4501 4502 4503 4504
	 * controllers
	 */
	mutex_lock(&chip->reg_lock);
	if (chip->irq > 0)
4505
		err = mv88e6xxx_g1_irq_setup(chip);
4506 4507 4508
	else
		err = mv88e6xxx_irq_poll_setup(chip);
	mutex_unlock(&chip->reg_lock);
4509

4510 4511
	if (err)
		goto out;
4512

4513 4514
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
4515
		if (err)
4516
			goto out_g1_irq;
4517 4518
	}

4519 4520 4521 4522 4523 4524 4525 4526
	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;

4527
	err = mv88e6xxx_mdios_register(chip, np);
4528
	if (err)
4529
		goto out_g1_vtu_prob_irq;
4530

4531
	err = mv88e6xxx_register_switch(chip);
4532 4533
	if (err)
		goto out_mdio;
4534

4535
	return 0;
4536 4537

out_mdio:
4538
	mv88e6xxx_mdios_unregister(chip);
4539
out_g1_vtu_prob_irq:
4540
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
4541
out_g1_atu_prob_irq:
4542
	mv88e6xxx_g1_atu_prob_irq_free(chip);
4543
out_g2_irq:
4544
	if (chip->info->g2_irqs > 0)
4545 4546
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
4547
	if (chip->irq > 0)
4548
		mv88e6xxx_g1_irq_free(chip);
4549 4550
	else
		mv88e6xxx_irq_poll_free(chip);
4551
out:
4552 4553 4554
	if (pdata)
		dev_put(pdata->netdev);

4555
	return err;
4556
}
4557 4558 4559 4560

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

4563 4564
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
4565
		mv88e6xxx_ptp_free(chip);
4566
	}
4567

4568
	mv88e6xxx_phy_destroy(chip);
4569
	mv88e6xxx_unregister_switch(chip);
4570
	mv88e6xxx_mdios_unregister(chip);
4571

4572 4573 4574 4575 4576 4577 4578
	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)
4579
		mv88e6xxx_g1_irq_free(chip);
4580 4581
	else
		mv88e6xxx_irq_poll_free(chip);
4582 4583 4584
}

static const struct of_device_id mv88e6xxx_of_match[] = {
4585 4586 4587 4588
	{
		.compatible = "marvell,mv88e6085",
		.data = &mv88e6xxx_table[MV88E6085],
	},
4589 4590 4591 4592
	{
		.compatible = "marvell,mv88e6190",
		.data = &mv88e6xxx_table[MV88E6190],
	},
4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608
	{ /* 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)
{
4609
	register_switch_driver(&mv88e6xxx_switch_drv);
4610 4611
	return mdio_driver_register(&mv88e6xxx_driver);
}
4612 4613 4614 4615
module_init(mv88e6xxx_init);

static void __exit mv88e6xxx_cleanup(void)
{
4616
	mdio_driver_unregister(&mv88e6xxx_driver);
4617
	unregister_switch_driver(&mv88e6xxx_switch_drv);
4618 4619
}
module_exit(mv88e6xxx_cleanup);
4620 4621 4622 4623

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