chip.c 126.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/netdevice.h>
32
#include <linux/gpio/consumer.h>
33
#include <linux/phy.h>
34
#include <linux/phylink.h>
35
#include <net/dsa.h>
36

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

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

54 55 56 57 58 59 60 61 62 63
/* 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.
64
 */
65

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

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

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

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

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

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

	*val = ret & 0xffff;

	return 0;
}

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

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

	return 0;
}

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

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

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

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

	return -ETIMEDOUT;
}

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

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

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

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

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

158
	*val = ret & 0xffff;
159

160
	return 0;
161 162
}

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

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

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

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

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

	return 0;
}

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

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

201
	assert_reg_lock(chip);
202

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

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

	return 0;
}

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

217
	assert_reg_lock(chip);
218

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

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

226 227 228
	return 0;
}

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

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

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

	mutex_lock(&chip->reg_lock);
266
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
	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);
}

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

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

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

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

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

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

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

345
static void mv88e6xxx_g1_irq_free_common(struct mv88e6xxx_chip *chip)
346 347
{
	int irq, virq;
348 349
	u16 mask;

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

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

359
	irq_domain_remove(chip->g1_irq.domain);
360 361
}

362 363
static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
{
364
	mv88e6xxx_g1_irq_free_common(chip);
365 366 367 368 369

	free_irq(chip->irq, chip);
}

static int mv88e6xxx_g1_irq_setup_common(struct mv88e6xxx_chip *chip)
370
{
371 372
	int err, irq, virq;
	u16 reg, mask;
373 374 375 376 377 378 379 380 381 382 383 384 385 386

	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;

387
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
388
	if (err)
389
		goto out_mapping;
390

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

393
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
394
	if (err)
395
		goto out_disable;
396 397

	/* Reading the interrupt status clears (most of) them */
398
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
399
	if (err)
400
		goto out_disable;
401 402 403

	return 0;

404
out_disable:
405
	mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
406
	mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
407 408 409 410 411 412 413 414

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);
415 416 417 418

	return err;
}

419 420 421 422 423 424 425 426 427 428
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,
429
				   IRQF_ONESHOT,
430 431 432 433 434 435 436 437 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
				   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)
{
471 472
	mv88e6xxx_g1_irq_free_common(chip);

473 474 475 476
	kthread_cancel_delayed_work_sync(&chip->irq_poll_work);
	kthread_destroy_worker(chip->kworker);
}

477
int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask)
478
{
479
	int i;
480

481
	for (i = 0; i < 16; i++) {
482 483 484 485 486 487 488 489 490 491 492 493 494
		u16 val;
		int err;

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

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

		usleep_range(1000, 2000);
	}

495
	dev_err(chip->dev, "Timeout while waiting for switch\n");
496 497 498
	return -ETIMEDOUT;
}

499
/* Indirect write to single pointer-data register with an Update bit */
500
int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
501 502
{
	u16 val;
503
	int err;
504 505

	/* Wait until the previous operation is completed */
506 507 508
	err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
	if (err)
		return err;
509 510 511 512 513 514 515

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

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

516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547
static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
				    int link, int speed, int duplex,
				    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;
	}

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

548 549 550 551 552 553
	if (chip->info->ops->port_set_cmode) {
		err = chip->info->ops->port_set_cmode(chip, port, mode);
		if (err && err != -EOPNOTSUPP)
			goto restore_link;
	}

554 555 556
	err = 0;
restore_link:
	if (chip->info->ops->port_set_link(chip, port, link))
557
		dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
558 559 560 561

	return err;
}

562 563 564 565
/* 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.
 */
566 567
static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
				  struct phy_device *phydev)
568
{
V
Vivien Didelot 已提交
569
	struct mv88e6xxx_chip *chip = ds->priv;
570
	int err;
571 572 573 574

	if (!phy_is_pseudo_fixed_link(phydev))
		return;

575
	mutex_lock(&chip->reg_lock);
576 577
	err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
				       phydev->duplex, phydev->interface);
578
	mutex_unlock(&chip->reg_lock);
579 580

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

584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660
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;
	int speed, duplex, link, err;

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

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_port_setup_mac(chip, port, link, speed, duplex,
				       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);
}

661
static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
662
{
663 664
	if (!chip->info->ops->stats_snapshot)
		return -EOPNOTSUPP;
665

666
	return chip->info->ops->stats_snapshot(chip, port);
667 668
}

669
static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 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
	{ "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, },
729 730
};

731
static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
732
					    struct mv88e6xxx_hw_stat *s,
733 734
					    int port, u16 bank1_select,
					    u16 histogram)
735 736 737
{
	u32 low;
	u32 high = 0;
738
	u16 reg = 0;
739
	int err;
740 741
	u64 value;

742
	switch (s->type) {
743
	case STATS_TYPE_PORT:
744 745
		err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
		if (err)
746
			return U64_MAX;
747

748
		low = reg;
749
		if (s->size == 4) {
750 751
			err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
			if (err)
752
				return U64_MAX;
753
			high = reg;
754
		}
755
		break;
756
	case STATS_TYPE_BANK1:
757
		reg = bank1_select;
758 759
		/* fall through */
	case STATS_TYPE_BANK0:
760
		reg |= s->reg | histogram;
761
		mv88e6xxx_g1_stats_read(chip, reg, &low);
762
		if (s->size == 8)
763
			mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
764 765
		break;
	default:
766
		return U64_MAX;
767 768 769 770 771
	}
	value = (((u64)high) << 16) | low;
	return value;
}

772 773
static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data, int types)
774
{
775 776
	struct mv88e6xxx_hw_stat *stat;
	int i, j;
777

778 779
	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
		stat = &mv88e6xxx_hw_stats[i];
780
		if (stat->type & types) {
781 782 783 784
			memcpy(data + j * ETH_GSTRING_LEN, stat->string,
			       ETH_GSTRING_LEN);
			j++;
		}
785
	}
786 787

	return j;
788 789
}

790 791
static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
792
{
793 794
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_PORT);
795 796
}

797 798
static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
799
{
800 801
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
802 803
}

804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821
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);
}

822
static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
823
				  u32 stringset, uint8_t *data)
824
{
V
Vivien Didelot 已提交
825
	struct mv88e6xxx_chip *chip = ds->priv;
826
	int count = 0;
827

828 829 830
	if (stringset != ETH_SS_STATS)
		return;

831 832
	mutex_lock(&chip->reg_lock);

833
	if (chip->info->ops->stats_get_strings)
834 835 836 837
		count = chip->info->ops->stats_get_strings(chip, data);

	if (chip->info->ops->serdes_get_strings) {
		data += count * ETH_GSTRING_LEN;
838
		count = chip->info->ops->serdes_get_strings(chip, port, data);
839
	}
840

841 842 843
	data += count * ETH_GSTRING_LEN;
	mv88e6xxx_atu_vtu_get_strings(data);

844
	mutex_unlock(&chip->reg_lock);
845 846 847 848 849
}

static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
					  int types)
{
850 851 852 853 854
	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];
855
		if (stat->type & types)
856 857 858
			j++;
	}
	return j;
859 860
}

861 862 863 864 865 866 867 868 869 870 871 872
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);
}

873
static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
874 875
{
	struct mv88e6xxx_chip *chip = ds->priv;
876 877
	int serdes_count = 0;
	int count = 0;
878

879 880 881
	if (sset != ETH_SS_STATS)
		return 0;

882
	mutex_lock(&chip->reg_lock);
883
	if (chip->info->ops->stats_get_sset_count)
884 885 886 887 888 889 890
		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);
891
	if (serdes_count < 0) {
892
		count = serdes_count;
893 894 895 896 897
		goto out;
	}
	count += serdes_count;
	count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);

898
out:
899
	mutex_unlock(&chip->reg_lock);
900

901
	return count;
902 903
}

904 905 906
static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data, int types,
				     u16 bank1_select, u16 histogram)
907 908 909 910 911 912 913
{
	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) {
914
			mutex_lock(&chip->reg_lock);
915 916 917
			data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
							      bank1_select,
							      histogram);
918 919
			mutex_unlock(&chip->reg_lock);

920 921 922
			j++;
		}
	}
923
	return j;
924 925
}

926 927
static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
928 929
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
930
					 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
931
					 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
932 933
}

934 935
static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
936 937
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
938
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
939 940
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
					 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
941 942
}

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

952 953 954 955 956 957 958 959 960 961
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;
}

962 963 964
static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
				uint64_t *data)
{
965 966
	int count = 0;

967
	if (chip->info->ops->stats_get_stats)
968 969
		count = chip->info->ops->stats_get_stats(chip, port, data);

970
	mutex_lock(&chip->reg_lock);
971 972
	if (chip->info->ops->serdes_get_stats) {
		data += count;
973
		count = chip->info->ops->serdes_get_stats(chip, port, data);
974
	}
975 976 977
	data += count;
	mv88e6xxx_atu_vtu_get_stats(chip, port, data);
	mutex_unlock(&chip->reg_lock);
978 979
}

980 981
static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
					uint64_t *data)
982
{
V
Vivien Didelot 已提交
983
	struct mv88e6xxx_chip *chip = ds->priv;
984 985
	int ret;

986
	mutex_lock(&chip->reg_lock);
987

988
	ret = mv88e6xxx_stats_snapshot(chip, port);
989 990 991
	mutex_unlock(&chip->reg_lock);

	if (ret < 0)
992
		return;
993 994

	mv88e6xxx_get_stats(chip, port, data);
995

996 997
}

998
static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
999 1000 1001 1002
{
	return 32 * sizeof(u16);
}

1003 1004
static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
			       struct ethtool_regs *regs, void *_p)
1005
{
V
Vivien Didelot 已提交
1006
	struct mv88e6xxx_chip *chip = ds->priv;
1007 1008
	int err;
	u16 reg;
1009 1010 1011 1012 1013 1014 1015
	u16 *p = _p;
	int i;

	regs->version = 0;

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

1016
	mutex_lock(&chip->reg_lock);
1017

1018 1019
	for (i = 0; i < 32; i++) {

1020 1021 1022
		err = mv88e6xxx_port_read(chip, port, i, &reg);
		if (!err)
			p[i] = reg;
1023
	}
1024

1025
	mutex_unlock(&chip->reg_lock);
1026 1027
}

V
Vivien Didelot 已提交
1028 1029
static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
1030
{
1031 1032
	/* Nothing to do on the port's MAC */
	return 0;
1033 1034
}

V
Vivien Didelot 已提交
1035 1036
static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
1037
{
1038 1039
	/* Nothing to do on the port's MAC */
	return 0;
1040 1041
}

1042
static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
1043
{
1044 1045 1046
	struct dsa_switch *ds = NULL;
	struct net_device *br;
	u16 pvlan;
1047 1048
	int i;

1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068
	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 已提交
1069
		    (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
1070 1071 1072 1073 1074
			pvlan |= BIT(i);

	return pvlan;
}

1075
static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
1076 1077
{
	u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
1078 1079 1080

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

1082
	return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
1083 1084
}

1085 1086
static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
					 u8 state)
1087
{
V
Vivien Didelot 已提交
1088
	struct mv88e6xxx_chip *chip = ds->priv;
1089
	int err;
1090

1091
	mutex_lock(&chip->reg_lock);
1092
	err = mv88e6xxx_port_set_state(chip, port, state);
1093
	mutex_unlock(&chip->reg_lock);
1094 1095

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

1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117
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;
}

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

1138 1139 1140 1141 1142 1143 1144
	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;
	}

1145 1146 1147 1148
	err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
	if (err)
		return err;

1149 1150 1151
	return 0;
}

1152 1153 1154 1155 1156 1157 1158 1159 1160
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;
}

1161 1162 1163 1164 1165 1166 1167 1168
static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->rmu_disable)
		return chip->info->ops->rmu_disable(chip);

	return 0;
}

1169 1170 1171 1172 1173 1174 1175 1176
static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->pot_clear)
		return chip->info->ops->pot_clear(chip);

	return 0;
}

1177 1178 1179 1180 1181 1182 1183 1184
static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->mgmt_rsvd2cpu)
		return chip->info->ops->mgmt_rsvd2cpu(chip);

	return 0;
}

1185 1186
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
1187 1188
	int err;

1189 1190 1191 1192
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

1193 1194 1195 1196
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

1197 1198 1199
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

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

1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232
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;
}

1233 1234 1235 1236 1237 1238 1239 1240 1241
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)
1242
		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1243 1244 1245 1246

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

1247 1248
static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
{
1249 1250 1251
	int dev, port;
	int err;

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

1273 1274 1275 1276 1277 1278
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);
1279
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1280 1281 1282
	mutex_unlock(&chip->reg_lock);

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

1286 1287 1288 1289 1290 1291 1292 1293
static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
{
	if (!chip->info->max_vid)
		return 0;

	return mv88e6xxx_g1_vtu_flush(chip);
}

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

1303 1304 1305 1306 1307 1308 1309 1310 1311
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);
}

1312
static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1313 1314
{
	DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1315 1316 1317
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = chip->info->max_vid,
	};
1318
	int i, err;
1319 1320 1321

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

1322
	/* Set every FID bit used by the (un)bridged ports */
1323
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1324
		err = mv88e6xxx_port_get_fid(chip, i, fid);
1325 1326 1327 1328 1329 1330
		if (err)
			return err;

		set_bit(*fid, fid_bitmap);
	}

1331 1332
	/* Set every FID bit used by the VLAN entries */
	do {
1333
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1334 1335 1336 1337 1338 1339 1340
		if (err)
			return err;

		if (!vlan.valid)
			break;

		set_bit(vlan.fid, fid_bitmap);
1341
	} while (vlan.vid < chip->info->max_vid);
1342 1343 1344 1345 1346

	/* 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);
1347
	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1348 1349 1350
		return -ENOSPC;

	/* Clear the database */
1351
	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1352 1353
}

1354 1355
static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
			     struct mv88e6xxx_vtu_entry *entry, bool new)
1356 1357 1358 1359 1360 1361
{
	int err;

	if (!vid)
		return -EINVAL;

1362 1363
	entry->vid = vid - 1;
	entry->valid = false;
1364

1365
	err = mv88e6xxx_vtu_getnext(chip, entry);
1366 1367 1368
	if (err)
		return err;

1369 1370
	if (entry->vid == vid && entry->valid)
		return 0;
1371

1372 1373 1374 1375 1376 1377 1378 1379
	if (new) {
		int i;

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

1380
		/* Exclude all ports */
1381
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1382
			entry->member[i] =
1383
				MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1384 1385

		return mv88e6xxx_atu_new(chip, &entry->fid);
1386 1387
	}

1388 1389
	/* switchdev expects -EOPNOTSUPP to honor software VLANs */
	return -EOPNOTSUPP;
1390 1391
}

1392 1393 1394
static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
					u16 vid_begin, u16 vid_end)
{
V
Vivien Didelot 已提交
1395
	struct mv88e6xxx_chip *chip = ds->priv;
1396 1397 1398
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = vid_begin - 1,
	};
1399 1400
	int i, err;

1401 1402 1403 1404
	/* 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;

1405 1406 1407
	if (!vid_begin)
		return -EOPNOTSUPP;

1408
	mutex_lock(&chip->reg_lock);
1409 1410

	do {
1411
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1412 1413 1414 1415 1416 1417 1418 1419 1420
		if (err)
			goto unlock;

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

1421
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1422 1423 1424
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

1425
			if (!ds->ports[i].slave)
1426 1427
				continue;

1428
			if (vlan.member[i] ==
1429
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1430 1431
				continue;

V
Vivien Didelot 已提交
1432
			if (dsa_to_port(ds, i)->bridge_dev ==
1433
			    ds->ports[port].bridge_dev)
1434 1435
				break; /* same bridge, check next VLAN */

V
Vivien Didelot 已提交
1436
			if (!dsa_to_port(ds, i)->bridge_dev)
1437 1438
				continue;

1439 1440
			dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
				port, vlan.vid, i,
V
Vivien Didelot 已提交
1441
				netdev_name(dsa_to_port(ds, i)->bridge_dev));
1442 1443 1444 1445 1446 1447
			err = -EOPNOTSUPP;
			goto unlock;
		}
	} while (vlan.vid < vid_end);

unlock:
1448
	mutex_unlock(&chip->reg_lock);
1449 1450 1451 1452

	return err;
}

1453 1454
static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
					 bool vlan_filtering)
1455
{
V
Vivien Didelot 已提交
1456
	struct mv88e6xxx_chip *chip = ds->priv;
1457 1458
	u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
		MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
1459
	int err;
1460

1461
	if (!chip->info->max_vid)
1462 1463
		return -EOPNOTSUPP;

1464
	mutex_lock(&chip->reg_lock);
1465
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1466
	mutex_unlock(&chip->reg_lock);
1467

1468
	return err;
1469 1470
}

1471 1472
static int
mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1473
			    const struct switchdev_obj_port_vlan *vlan)
1474
{
V
Vivien Didelot 已提交
1475
	struct mv88e6xxx_chip *chip = ds->priv;
1476 1477
	int err;

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

1481 1482 1483 1484 1485 1486 1487 1488
	/* 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;

1489 1490 1491 1492 1493 1494
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */
	return 0;
}

1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 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
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);
}

1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561
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;
}

1562
static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
1563
				    u16 vid, u8 member)
1564
{
1565
	struct mv88e6xxx_vtu_entry vlan;
1566 1567
	int err;

1568
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
1569
	if (err)
1570
		return err;
1571

1572
	vlan.member[port] = member;
1573

1574 1575 1576 1577 1578
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
	if (err)
		return err;

	return mv88e6xxx_broadcast_setup(chip, vid);
1579 1580
}

1581
static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1582
				    const struct switchdev_obj_port_vlan *vlan)
1583
{
V
Vivien Didelot 已提交
1584
	struct mv88e6xxx_chip *chip = ds->priv;
1585 1586
	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1587
	u8 member;
1588 1589
	u16 vid;

1590
	if (!chip->info->max_vid)
1591 1592
		return;

1593
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1594
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1595
	else if (untagged)
1596
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
1597
	else
1598
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
1599

1600
	mutex_lock(&chip->reg_lock);
1601

1602
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
1603
		if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
1604 1605
			dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
				vid, untagged ? 'u' : 't');
1606

1607
	if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1608 1609
		dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
			vlan->vid_end);
1610

1611
	mutex_unlock(&chip->reg_lock);
1612 1613
}

1614
static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
1615
				    int port, u16 vid)
1616
{
1617
	struct mv88e6xxx_vtu_entry vlan;
1618 1619
	int i, err;

1620
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1621
	if (err)
1622
		return err;
1623

1624
	/* Tell switchdev if this VLAN is handled in software */
1625
	if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1626
		return -EOPNOTSUPP;
1627

1628
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1629 1630

	/* keep the VLAN unless all ports are excluded */
1631
	vlan.valid = false;
1632
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1633 1634
		if (vlan.member[i] !=
		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
1635
			vlan.valid = true;
1636 1637 1638 1639
			break;
		}
	}

1640
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1641 1642 1643
	if (err)
		return err;

1644
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
1645 1646
}

1647 1648
static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
				   const struct switchdev_obj_port_vlan *vlan)
1649
{
V
Vivien Didelot 已提交
1650
	struct mv88e6xxx_chip *chip = ds->priv;
1651 1652 1653
	u16 pvid, vid;
	int err = 0;

1654
	if (!chip->info->max_vid)
1655 1656
		return -EOPNOTSUPP;

1657
	mutex_lock(&chip->reg_lock);
1658

1659
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
1660 1661 1662
	if (err)
		goto unlock;

1663
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1664
		err = _mv88e6xxx_port_vlan_del(chip, port, vid);
1665 1666 1667 1668
		if (err)
			goto unlock;

		if (vid == pvid) {
1669
			err = mv88e6xxx_port_set_pvid(chip, port, 0);
1670 1671 1672 1673 1674
			if (err)
				goto unlock;
		}
	}

1675
unlock:
1676
	mutex_unlock(&chip->reg_lock);
1677 1678 1679 1680

	return err;
}

1681 1682
static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
				  const unsigned char *addr, u16 vid)
1683
{
V
Vivien Didelot 已提交
1684
	struct mv88e6xxx_chip *chip = ds->priv;
1685
	int err;
1686

1687
	mutex_lock(&chip->reg_lock);
1688 1689
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1690
	mutex_unlock(&chip->reg_lock);
1691 1692

	return err;
1693 1694
}

1695
static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1696
				  const unsigned char *addr, u16 vid)
1697
{
V
Vivien Didelot 已提交
1698
	struct mv88e6xxx_chip *chip = ds->priv;
1699
	int err;
1700

1701
	mutex_lock(&chip->reg_lock);
1702
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1703
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
1704
	mutex_unlock(&chip->reg_lock);
1705

1706
	return err;
1707 1708
}

1709 1710
static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
				      u16 fid, u16 vid, int port,
1711
				      dsa_fdb_dump_cb_t *cb, void *data)
1712
{
1713
	struct mv88e6xxx_atu_entry addr;
1714
	bool is_static;
1715 1716
	int err;

1717
	addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1718
	eth_broadcast_addr(addr.mac);
1719 1720

	do {
1721
		mutex_lock(&chip->reg_lock);
1722
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
1723
		mutex_unlock(&chip->reg_lock);
1724
		if (err)
1725
			return err;
1726

1727
		if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
1728 1729
			break;

1730
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
1731 1732
			continue;

1733 1734
		if (!is_unicast_ether_addr(addr.mac))
			continue;
1735

1736 1737 1738
		is_static = (addr.state ==
			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
		err = cb(addr.mac, vid, is_static, data);
1739 1740
		if (err)
			return err;
1741 1742 1743 1744 1745
	} while (!is_broadcast_ether_addr(addr.mac));

	return err;
}

1746
static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1747
				  dsa_fdb_dump_cb_t *cb, void *data)
1748
{
1749
	struct mv88e6xxx_vtu_entry vlan = {
1750
		.vid = chip->info->max_vid,
1751
	};
1752
	u16 fid;
1753 1754
	int err;

1755
	/* Dump port's default Filtering Information Database (VLAN ID 0) */
1756
	mutex_lock(&chip->reg_lock);
1757
	err = mv88e6xxx_port_get_fid(chip, port, &fid);
1758 1759
	mutex_unlock(&chip->reg_lock);

1760
	if (err)
1761
		return err;
1762

1763
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
1764
	if (err)
1765
		return err;
1766

1767
	/* Dump VLANs' Filtering Information Databases */
1768
	do {
1769
		mutex_lock(&chip->reg_lock);
1770
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1771
		mutex_unlock(&chip->reg_lock);
1772
		if (err)
1773
			return err;
1774 1775 1776 1777

		if (!vlan.valid)
			break;

1778
		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1779
						 cb, data);
1780
		if (err)
1781
			return err;
1782
	} while (vlan.vid < chip->info->max_vid);
1783

1784 1785 1786 1787
	return err;
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1788
				   dsa_fdb_dump_cb_t *cb, void *data)
1789
{
V
Vivien Didelot 已提交
1790
	struct mv88e6xxx_chip *chip = ds->priv;
1791

1792
	return mv88e6xxx_port_db_dump(chip, port, cb, data);
1793 1794
}

1795 1796
static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
				struct net_device *br)
1797
{
1798
	struct dsa_switch *ds;
1799
	int port;
1800
	int dev;
1801
	int err;
1802

1803 1804 1805 1806
	/* 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);
1807
			if (err)
1808
				return err;
1809 1810 1811
		}
	}

1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829
	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;
			}
		}
	}

1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840
	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);
1841
	mutex_unlock(&chip->reg_lock);
1842

1843
	return err;
1844 1845
}

1846 1847
static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
					struct net_device *br)
1848
{
V
Vivien Didelot 已提交
1849
	struct mv88e6xxx_chip *chip = ds->priv;
1850

1851
	mutex_lock(&chip->reg_lock);
1852 1853 1854
	if (mv88e6xxx_bridge_map(chip, br) ||
	    mv88e6xxx_port_vlan_map(chip, port))
		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
1855
	mutex_unlock(&chip->reg_lock);
1856 1857
}

1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887
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);
}

1888 1889 1890 1891 1892 1893 1894 1895
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->reset)
		return chip->info->ops->reset(chip);

	return 0;
}

1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908
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);
	}
}

1909
static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1910
{
1911
	int i, err;
1912

1913
	/* Set all ports to the Disabled state */
1914
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
1915
		err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
1916 1917
		if (err)
			return err;
1918 1919
	}

1920 1921 1922
	/* Wait for transmit queues to drain,
	 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
	 */
1923 1924
	usleep_range(2000, 4000);

1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935
	return 0;
}

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

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

1936
	mv88e6xxx_hardware_reset(chip);
1937

1938
	return mv88e6xxx_software_reset(chip);
1939 1940
}

1941
static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
1942 1943
				   enum mv88e6xxx_frame_mode frame,
				   enum mv88e6xxx_egress_mode egress, u16 etype)
1944 1945 1946
{
	int err;

1947 1948 1949 1950
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
1951 1952 1953
	if (err)
		return err;

1954 1955 1956 1957 1958 1959 1960 1961
	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;
1962 1963
}

1964
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1965
{
1966
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
1967
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
1968
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
1969
}
1970

1971 1972 1973
static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
1974
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
1975
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
1976
}
1977

1978 1979 1980 1981
static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port,
				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
1982 1983
				       MV88E6XXX_EGRESS_MODE_ETHERTYPE,
				       ETH_P_EDSA);
1984
}
1985

1986 1987 1988 1989
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);
1990

1991
	if (dsa_is_user_port(chip->ds, port))
1992
		return mv88e6xxx_set_port_mode_normal(chip, port);
1993

1994 1995 1996
	/* 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);
1997

1998 1999
	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
		return mv88e6xxx_set_port_mode_edsa(chip, port);
2000

2001
	return -EINVAL;
2002 2003
}

2004
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2005
{
2006
	bool message = dsa_is_dsa_port(chip->ds, port);
2007

2008
	return mv88e6xxx_port_set_message_port(chip, port, message);
2009
}
2010

2011
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2012
{
2013 2014
	struct dsa_switch *ds = chip->ds;
	bool flood;
2015

2016
	/* Upstream ports flood frames with unknown unicast or multicast DA */
2017
	flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
2018 2019 2020
	if (chip->info->ops->port_set_egress_floods)
		return chip->info->ops->port_set_egress_floods(chip, port,
							       flood, flood);
2021

2022
	return 0;
2023 2024
}

2025 2026 2027
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
2028 2029
	if (chip->info->ops->serdes_power)
		return chip->info->ops->serdes_power(chip, port, on);
2030

2031
	return 0;
2032 2033
}

2034 2035 2036 2037 2038 2039
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

2040
	upstream_port = dsa_upstream_port(ds, port);
2041 2042 2043 2044 2045 2046 2047
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063
	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;
		}
	}

2064 2065 2066
	return 0;
}

2067
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
2068
{
2069
	struct dsa_switch *ds = chip->ds;
2070
	int err;
2071
	u16 reg;
2072

2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086
	/* 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,
					       PHY_INTERFACE_MODE_NA);
	else
		err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
					       SPEED_UNFORCED, DUPLEX_UNFORCED,
					       PHY_INTERFACE_MODE_NA);
	if (err)
		return err;
2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101

	/* 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.
	 */
2102 2103 2104 2105
	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);
2106 2107
	if (err)
		return err;
2108

2109
	err = mv88e6xxx_setup_port_mode(chip, port);
2110 2111
	if (err)
		return err;
2112

2113
	err = mv88e6xxx_setup_egress_floods(chip, port);
2114 2115 2116
	if (err)
		return err;

2117 2118 2119
	/* 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.
2120
	 */
2121 2122 2123 2124 2125
	if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
		err = mv88e6xxx_serdes_power(chip, port, true);
		if (err)
			return err;
	}
2126

2127
	/* Port Control 2: don't force a good FCS, set the maximum frame size to
2128
	 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
2129 2130 2131
	 * 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.
2132
	 */
2133 2134 2135
	err = mv88e6xxx_port_set_map_da(chip, port);
	if (err)
		return err;
2136

2137 2138 2139
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
2140

2141
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
2142
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
2143 2144 2145
	if (err)
		return err;

2146 2147
	if (chip->info->ops->port_set_jumbo_size) {
		err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
2148 2149 2150 2151
		if (err)
			return err;
	}

2152 2153 2154 2155 2156
	/* 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.
	 */
2157
	reg = 1 << port;
2158 2159
	/* Disable learning for CPU port */
	if (dsa_is_cpu_port(ds, port))
2160
		reg = 0;
2161

2162 2163
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
2164 2165
	if (err)
		return err;
2166 2167

	/* Egress rate control 2: disable egress rate control. */
2168 2169
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
				   0x0000);
2170 2171
	if (err)
		return err;
2172

2173 2174
	if (chip->info->ops->port_pause_limit) {
		err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
2175 2176
		if (err)
			return err;
2177
	}
2178

2179 2180 2181 2182 2183 2184
	if (chip->info->ops->port_disable_learn_limit) {
		err = chip->info->ops->port_disable_learn_limit(chip, port);
		if (err)
			return err;
	}

2185 2186
	if (chip->info->ops->port_disable_pri_override) {
		err = chip->info->ops->port_disable_pri_override(chip, port);
2187 2188
		if (err)
			return err;
2189
	}
2190

2191 2192
	if (chip->info->ops->port_tag_remap) {
		err = chip->info->ops->port_tag_remap(chip, port);
2193 2194
		if (err)
			return err;
2195 2196
	}

2197 2198
	if (chip->info->ops->port_egress_rate_limiting) {
		err = chip->info->ops->port_egress_rate_limiting(chip, port);
2199 2200
		if (err)
			return err;
2201 2202
	}

2203
	err = mv88e6xxx_setup_message_port(chip, port);
2204 2205
	if (err)
		return err;
2206

2207
	/* Port based VLAN map: give each port the same default address
2208 2209
	 * database, and allow bidirectional communication between the
	 * CPU and DSA port(s), and the other ports.
2210
	 */
2211
	err = mv88e6xxx_port_set_fid(chip, port, 0);
2212 2213
	if (err)
		return err;
2214

2215
	err = mv88e6xxx_port_vlan_map(chip, port);
2216 2217
	if (err)
		return err;
2218 2219 2220 2221

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

2225 2226 2227 2228
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
2229
	int err;
2230 2231

	mutex_lock(&chip->reg_lock);
2232
	err = mv88e6xxx_serdes_power(chip, port, true);
2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243
	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);
2244 2245
	if (mv88e6xxx_serdes_power(chip, port, false))
		dev_err(chip->dev, "failed to power off SERDES\n");
2246 2247 2248
	mutex_unlock(&chip->reg_lock);
}

2249 2250 2251
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
2252
	struct mv88e6xxx_chip *chip = ds->priv;
2253 2254 2255
	int err;

	mutex_lock(&chip->reg_lock);
2256
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2257 2258 2259 2260 2261
	mutex_unlock(&chip->reg_lock);

	return err;
}

2262
static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
2263
{
2264
	int err;
2265

2266
	/* Initialize the statistics unit */
2267 2268 2269 2270 2271
	if (chip->info->ops->stats_set_histogram) {
		err = chip->info->ops->stats_set_histogram(chip);
		if (err)
			return err;
	}
2272

2273
	return mv88e6xxx_g1_stats_clear(chip);
2274 2275
}

2276
static int mv88e6xxx_setup(struct dsa_switch *ds)
2277
{
V
Vivien Didelot 已提交
2278
	struct mv88e6xxx_chip *chip = ds->priv;
2279
	int err;
2280 2281
	int i;

2282
	chip->ds = ds;
2283
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
2284

2285
	mutex_lock(&chip->reg_lock);
2286

2287
	/* Setup Switch Port Registers */
2288
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2289 2290 2291
		if (dsa_is_unused_port(ds, i))
			continue;

2292 2293 2294 2295 2296
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

2297 2298 2299 2300
	err = mv88e6xxx_irl_setup(chip);
	if (err)
		goto unlock;

2301 2302 2303 2304
	err = mv88e6xxx_mac_setup(chip);
	if (err)
		goto unlock;

2305 2306 2307 2308
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

2309 2310 2311 2312
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

2313 2314 2315 2316
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

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

2321 2322 2323 2324
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

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

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

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

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

2341 2342 2343 2344
	err = mv88e6xxx_devmap_setup(chip);
	if (err)
		goto unlock;

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

2349
	/* Setup PTP Hardware Clock and timestamping */
2350 2351 2352 2353
	if (chip->info->ptp_support) {
		err = mv88e6xxx_ptp_setup(chip);
		if (err)
			goto unlock;
2354 2355 2356 2357

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
2358 2359
	}

2360 2361 2362 2363
	err = mv88e6xxx_stats_setup(chip);
	if (err)
		goto unlock;

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

2367
	return err;
2368 2369
}

2370
static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
2371
{
2372 2373
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2374 2375
	u16 val;
	int err;
2376

2377 2378 2379
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

2380
	mutex_lock(&chip->reg_lock);
2381
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
2382
	mutex_unlock(&chip->reg_lock);
2383

2384 2385 2386 2387 2388
	if (reg == MII_PHYSID2) {
		/* Some internal PHYS don't have a model number.  Use
		 * the mv88e6390 family model number instead.
		 */
		if (!(val & 0x3f0))
2389
			val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
2390 2391
	}

2392
	return err ? err : val;
2393 2394
}

2395
static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
2396
{
2397 2398
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2399
	int err;
2400

2401 2402 2403
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

2404
	mutex_lock(&chip->reg_lock);
2405
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
2406
	mutex_unlock(&chip->reg_lock);
2407 2408

	return err;
2409 2410
}

2411
static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
2412 2413
				   struct device_node *np,
				   bool external)
2414 2415
{
	static int index;
2416
	struct mv88e6xxx_mdio_bus *mdio_bus;
2417 2418 2419
	struct mii_bus *bus;
	int err;

2420 2421 2422 2423 2424 2425 2426 2427 2428
	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;
	}

2429
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
2430 2431 2432
	if (!bus)
		return -ENOMEM;

2433
	mdio_bus = bus->priv;
2434
	mdio_bus->bus = bus;
2435
	mdio_bus->chip = chip;
2436 2437
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
2438

2439 2440
	if (np) {
		bus->name = np->full_name;
2441
		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
2442 2443 2444 2445 2446 2447 2448
	} 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;
2449
	bus->parent = chip->dev;
2450

2451 2452 2453 2454 2455 2456
	if (!external) {
		err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
		if (err)
			return err;
	}

2457
	err = of_mdiobus_register(bus, np);
2458
	if (err) {
2459
		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
2460
		mv88e6xxx_g2_irq_mdio_free(chip, bus);
2461
		return err;
2462
	}
2463 2464 2465 2466 2467

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

	return 0;
2470
}
2471

2472 2473 2474 2475 2476
static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
	{ .compatible = "marvell,mv88e6xxx-mdio-external",
	  .data = (void *)true },
	{ },
};
2477

2478 2479 2480 2481 2482 2483 2484 2485 2486
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;

2487 2488 2489
		if (!mdio_bus->external)
			mv88e6xxx_g2_irq_mdio_free(chip, bus);

2490 2491 2492 2493
		mdiobus_unregister(bus);
	}
}

2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517
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);
2518 2519
			if (err) {
				mv88e6xxx_mdios_unregister(chip);
2520
				return err;
2521
			}
2522 2523 2524 2525
		}
	}

	return 0;
2526 2527
}

2528 2529
static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
2530
	struct mv88e6xxx_chip *chip = ds->priv;
2531 2532 2533 2534 2535 2536 2537

	return chip->eeprom_len;
}

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

2541 2542
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
2543

2544 2545
	mutex_lock(&chip->reg_lock);
	err = chip->info->ops->get_eeprom(chip, eeprom, data);
2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558
	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 已提交
2559
	struct mv88e6xxx_chip *chip = ds->priv;
2560 2561
	int err;

2562 2563 2564
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

2565 2566 2567 2568
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

	mutex_lock(&chip->reg_lock);
2569
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
2570 2571 2572 2573 2574
	mutex_unlock(&chip->reg_lock);

	return err;
}

2575
static const struct mv88e6xxx_ops mv88e6085_ops = {
2576
	/* MV88E6XXX_FAMILY_6097 */
2577 2578
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2579
	.irl_init_all = mv88e6352_g2_irl_init_all,
2580
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2581 2582
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2583
	.port_set_link = mv88e6xxx_port_set_link,
2584
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2585
	.port_set_speed = mv88e6185_port_set_speed,
2586
	.port_tag_remap = mv88e6095_port_tag_remap,
2587
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2588
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2589
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2590
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2591
	.port_pause_limit = mv88e6097_port_pause_limit,
2592
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2593
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2594
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2595
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2596 2597
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2598
	.stats_get_stats = mv88e6095_stats_get_stats,
2599 2600
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2601
	.watchdog_ops = &mv88e6097_watchdog_ops,
2602
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2603
	.pot_clear = mv88e6xxx_g2_pot_clear,
2604 2605
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2606
	.reset = mv88e6185_g1_reset,
2607
	.rmu_disable = mv88e6085_g1_rmu_disable,
2608
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2609
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2610
	.serdes_power = mv88e6341_serdes_power,
2611 2612 2613
};

static const struct mv88e6xxx_ops mv88e6095_ops = {
2614
	/* MV88E6XXX_FAMILY_6095 */
2615 2616
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2617
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2618 2619
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2620
	.port_set_link = mv88e6xxx_port_set_link,
2621
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2622
	.port_set_speed = mv88e6185_port_set_speed,
2623
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2624
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2625
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2626
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2627
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2628 2629
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2630
	.stats_get_stats = mv88e6095_stats_get_stats,
2631
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2632 2633
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2634
	.reset = mv88e6185_g1_reset,
2635
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2636
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2637 2638
};

2639
static const struct mv88e6xxx_ops mv88e6097_ops = {
2640
	/* MV88E6XXX_FAMILY_6097 */
2641 2642
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2643
	.irl_init_all = mv88e6352_g2_irl_init_all,
2644 2645 2646 2647 2648 2649
	.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,
2650
	.port_tag_remap = mv88e6095_port_tag_remap,
2651
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2652
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2653
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2654
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2655
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
2656
	.port_pause_limit = mv88e6097_port_pause_limit,
2657
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2658
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2659
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2660
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2661 2662 2663
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
	.stats_get_stats = mv88e6095_stats_get_stats,
2664 2665
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2666
	.watchdog_ops = &mv88e6097_watchdog_ops,
2667
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2668
	.pot_clear = mv88e6xxx_g2_pot_clear,
2669
	.reset = mv88e6352_g1_reset,
2670
	.rmu_disable = mv88e6085_g1_rmu_disable,
2671
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2672
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2673 2674
};

2675
static const struct mv88e6xxx_ops mv88e6123_ops = {
2676
	/* MV88E6XXX_FAMILY_6165 */
2677 2678
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2679
	.irl_init_all = mv88e6352_g2_irl_init_all,
2680
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2681 2682
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2683
	.port_set_link = mv88e6xxx_port_set_link,
2684
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2685
	.port_set_speed = mv88e6185_port_set_speed,
2686
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2687
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2688
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2689
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2690
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2691
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2692 2693
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2694
	.stats_get_stats = mv88e6095_stats_get_stats,
2695 2696
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2697
	.watchdog_ops = &mv88e6097_watchdog_ops,
2698
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2699
	.pot_clear = mv88e6xxx_g2_pot_clear,
2700
	.reset = mv88e6352_g1_reset,
2701
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2702
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2703 2704 2705
};

static const struct mv88e6xxx_ops mv88e6131_ops = {
2706
	/* MV88E6XXX_FAMILY_6185 */
2707 2708
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2709
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2710 2711
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2712
	.port_set_link = mv88e6xxx_port_set_link,
2713
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2714
	.port_set_speed = mv88e6185_port_set_speed,
2715
	.port_tag_remap = mv88e6095_port_tag_remap,
2716
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2717
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2718
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2719
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2720
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2721
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2722
	.port_pause_limit = mv88e6097_port_pause_limit,
2723
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2724
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2725 2726
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2727
	.stats_get_stats = mv88e6095_stats_get_stats,
2728 2729
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2730
	.watchdog_ops = &mv88e6097_watchdog_ops,
2731
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2732
	.ppu_enable = mv88e6185_g1_ppu_enable,
2733
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
2734
	.ppu_disable = mv88e6185_g1_ppu_disable,
2735
	.reset = mv88e6185_g1_reset,
2736
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2737
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2738 2739
};

2740 2741
static const struct mv88e6xxx_ops mv88e6141_ops = {
	/* MV88E6XXX_FAMILY_6341 */
2742 2743
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2744
	.irl_init_all = mv88e6352_g2_irl_init_all,
2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757
	.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,
2758
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2759
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2760
	.port_pause_limit = mv88e6097_port_pause_limit,
2761 2762 2763
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
2764
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2765 2766 2767
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
2768 2769
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
2770 2771
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
2772
	.pot_clear = mv88e6xxx_g2_pot_clear,
2773
	.reset = mv88e6352_g1_reset,
2774
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2775
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2776
	.gpio_ops = &mv88e6352_gpio_ops,
2777 2778
};

2779
static const struct mv88e6xxx_ops mv88e6161_ops = {
2780
	/* MV88E6XXX_FAMILY_6165 */
2781 2782
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2783
	.irl_init_all = mv88e6352_g2_irl_init_all,
2784
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2785 2786
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2787
	.port_set_link = mv88e6xxx_port_set_link,
2788
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2789
	.port_set_speed = mv88e6185_port_set_speed,
2790
	.port_tag_remap = mv88e6095_port_tag_remap,
2791
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2792
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2793
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2794
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2795
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2796
	.port_pause_limit = mv88e6097_port_pause_limit,
2797
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2798
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2799
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2800
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2801 2802
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2803
	.stats_get_stats = mv88e6095_stats_get_stats,
2804 2805
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2806
	.watchdog_ops = &mv88e6097_watchdog_ops,
2807
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2808
	.pot_clear = mv88e6xxx_g2_pot_clear,
2809
	.reset = mv88e6352_g1_reset,
2810
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2811
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2812 2813 2814
};

static const struct mv88e6xxx_ops mv88e6165_ops = {
2815
	/* MV88E6XXX_FAMILY_6165 */
2816 2817
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2818
	.irl_init_all = mv88e6352_g2_irl_init_all,
2819
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2820 2821
	.phy_read = mv88e6165_phy_read,
	.phy_write = mv88e6165_phy_write,
2822
	.port_set_link = mv88e6xxx_port_set_link,
2823
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2824
	.port_set_speed = mv88e6185_port_set_speed,
2825
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2826
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2827
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2828
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2829 2830
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2831
	.stats_get_stats = mv88e6095_stats_get_stats,
2832 2833
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2834
	.watchdog_ops = &mv88e6097_watchdog_ops,
2835
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2836
	.pot_clear = mv88e6xxx_g2_pot_clear,
2837
	.reset = mv88e6352_g1_reset,
2838
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2839
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2840 2841 2842
};

static const struct mv88e6xxx_ops mv88e6171_ops = {
2843
	/* MV88E6XXX_FAMILY_6351 */
2844 2845
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2846
	.irl_init_all = mv88e6352_g2_irl_init_all,
2847
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2848 2849
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2850
	.port_set_link = mv88e6xxx_port_set_link,
2851
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2852
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
2853
	.port_set_speed = mv88e6185_port_set_speed,
2854
	.port_tag_remap = mv88e6095_port_tag_remap,
2855
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2856
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2857
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2858
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2859
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2860
	.port_pause_limit = mv88e6097_port_pause_limit,
2861
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2862
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2863
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2864
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2865 2866
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2867
	.stats_get_stats = mv88e6095_stats_get_stats,
2868 2869
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2870
	.watchdog_ops = &mv88e6097_watchdog_ops,
2871
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2872
	.pot_clear = mv88e6xxx_g2_pot_clear,
2873
	.reset = mv88e6352_g1_reset,
2874
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2875
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2876 2877 2878
};

static const struct mv88e6xxx_ops mv88e6172_ops = {
2879
	/* MV88E6XXX_FAMILY_6352 */
2880 2881
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2882
	.irl_init_all = mv88e6352_g2_irl_init_all,
2883 2884
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
2885
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2886 2887
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2888
	.port_set_link = mv88e6xxx_port_set_link,
2889
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2890
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
2891
	.port_set_speed = mv88e6352_port_set_speed,
2892
	.port_tag_remap = mv88e6095_port_tag_remap,
2893
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2894
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2895
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2896
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2897
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2898
	.port_pause_limit = mv88e6097_port_pause_limit,
2899
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2900
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2901
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2902
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2903 2904
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2905
	.stats_get_stats = mv88e6095_stats_get_stats,
2906 2907
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2908
	.watchdog_ops = &mv88e6097_watchdog_ops,
2909
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2910
	.pot_clear = mv88e6xxx_g2_pot_clear,
2911
	.reset = mv88e6352_g1_reset,
2912
	.rmu_disable = mv88e6352_g1_rmu_disable,
2913
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2914
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2915
	.serdes_power = mv88e6352_serdes_power,
2916
	.gpio_ops = &mv88e6352_gpio_ops,
2917 2918 2919
};

static const struct mv88e6xxx_ops mv88e6175_ops = {
2920
	/* MV88E6XXX_FAMILY_6351 */
2921 2922
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2923
	.irl_init_all = mv88e6352_g2_irl_init_all,
2924
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2925 2926
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2927
	.port_set_link = mv88e6xxx_port_set_link,
2928
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2929
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
2930
	.port_set_speed = mv88e6185_port_set_speed,
2931
	.port_tag_remap = mv88e6095_port_tag_remap,
2932
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2933
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2934
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2935
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2936
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2937
	.port_pause_limit = mv88e6097_port_pause_limit,
2938
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2939
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2940
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2941
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2942 2943
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2944
	.stats_get_stats = mv88e6095_stats_get_stats,
2945 2946
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2947
	.watchdog_ops = &mv88e6097_watchdog_ops,
2948
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2949
	.pot_clear = mv88e6xxx_g2_pot_clear,
2950
	.reset = mv88e6352_g1_reset,
2951
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2952
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2953
	.serdes_power = mv88e6341_serdes_power,
2954 2955 2956
};

static const struct mv88e6xxx_ops mv88e6176_ops = {
2957
	/* MV88E6XXX_FAMILY_6352 */
2958 2959
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2960
	.irl_init_all = mv88e6352_g2_irl_init_all,
2961 2962
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
2963
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2964 2965
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2966
	.port_set_link = mv88e6xxx_port_set_link,
2967
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2968
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
2969
	.port_set_speed = mv88e6352_port_set_speed,
2970
	.port_tag_remap = mv88e6095_port_tag_remap,
2971
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2972
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2973
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2974
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2975
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2976
	.port_pause_limit = mv88e6097_port_pause_limit,
2977
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2978
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2979
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2980
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2981 2982
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2983
	.stats_get_stats = mv88e6095_stats_get_stats,
2984 2985
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2986
	.watchdog_ops = &mv88e6097_watchdog_ops,
2987
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2988
	.pot_clear = mv88e6xxx_g2_pot_clear,
2989
	.reset = mv88e6352_g1_reset,
2990
	.rmu_disable = mv88e6352_g1_rmu_disable,
2991
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2992
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2993
	.serdes_power = mv88e6352_serdes_power,
2994
	.gpio_ops = &mv88e6352_gpio_ops,
2995 2996 2997
};

static const struct mv88e6xxx_ops mv88e6185_ops = {
2998
	/* MV88E6XXX_FAMILY_6185 */
2999 3000
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3001
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3002 3003
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3004
	.port_set_link = mv88e6xxx_port_set_link,
3005
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3006
	.port_set_speed = mv88e6185_port_set_speed,
3007
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
3008
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
3009
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
3010
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
3011
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3012
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3013 3014
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3015
	.stats_get_stats = mv88e6095_stats_get_stats,
3016 3017
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3018
	.watchdog_ops = &mv88e6097_watchdog_ops,
3019
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3020
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
3021 3022
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
3023
	.reset = mv88e6185_g1_reset,
3024
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3025
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3026 3027
};

3028
static const struct mv88e6xxx_ops mv88e6190_ops = {
3029
	/* MV88E6XXX_FAMILY_6390 */
3030
	.irl_init_all = mv88e6390_g2_irl_init_all,
3031 3032
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3033 3034 3035 3036 3037 3038 3039
	.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,
3040
	.port_tag_remap = mv88e6390_port_tag_remap,
3041
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3042
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3043
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3044
	.port_pause_limit = mv88e6390_port_pause_limit,
3045
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3046
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3047
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3048
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3049 3050
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3051
	.stats_get_stats = mv88e6390_stats_get_stats,
3052 3053
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3054
	.watchdog_ops = &mv88e6390_watchdog_ops,
3055
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3056
	.pot_clear = mv88e6xxx_g2_pot_clear,
3057
	.reset = mv88e6352_g1_reset,
3058
	.rmu_disable = mv88e6390_g1_rmu_disable,
3059 3060
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3061
	.serdes_power = mv88e6390_serdes_power,
3062
	.gpio_ops = &mv88e6352_gpio_ops,
3063 3064 3065
};

static const struct mv88e6xxx_ops mv88e6190x_ops = {
3066
	/* MV88E6XXX_FAMILY_6390 */
3067
	.irl_init_all = mv88e6390_g2_irl_init_all,
3068 3069
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3070 3071 3072 3073 3074 3075 3076
	.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,
3077
	.port_tag_remap = mv88e6390_port_tag_remap,
3078
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3079
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3080
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3081
	.port_pause_limit = mv88e6390_port_pause_limit,
3082
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3083
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3084
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3085
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3086 3087
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3088
	.stats_get_stats = mv88e6390_stats_get_stats,
3089 3090
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3091
	.watchdog_ops = &mv88e6390_watchdog_ops,
3092
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3093
	.pot_clear = mv88e6xxx_g2_pot_clear,
3094
	.reset = mv88e6352_g1_reset,
3095
	.rmu_disable = mv88e6390_g1_rmu_disable,
3096 3097
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3098
	.serdes_power = mv88e6390_serdes_power,
3099
	.gpio_ops = &mv88e6352_gpio_ops,
3100 3101 3102
};

static const struct mv88e6xxx_ops mv88e6191_ops = {
3103
	/* MV88E6XXX_FAMILY_6390 */
3104
	.irl_init_all = mv88e6390_g2_irl_init_all,
3105 3106
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3107 3108 3109 3110 3111 3112 3113
	.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,
3114
	.port_tag_remap = mv88e6390_port_tag_remap,
3115
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3116
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3117
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3118
	.port_pause_limit = mv88e6390_port_pause_limit,
3119
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3120
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3121
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3122
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3123 3124
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3125
	.stats_get_stats = mv88e6390_stats_get_stats,
3126 3127
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3128
	.watchdog_ops = &mv88e6390_watchdog_ops,
3129
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3130
	.pot_clear = mv88e6xxx_g2_pot_clear,
3131
	.reset = mv88e6352_g1_reset,
3132
	.rmu_disable = mv88e6390_g1_rmu_disable,
3133 3134
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3135
	.serdes_power = mv88e6390_serdes_power,
3136 3137
};

3138
static const struct mv88e6xxx_ops mv88e6240_ops = {
3139
	/* MV88E6XXX_FAMILY_6352 */
3140 3141
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3142
	.irl_init_all = mv88e6352_g2_irl_init_all,
3143 3144
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3145
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3146 3147
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3148
	.port_set_link = mv88e6xxx_port_set_link,
3149
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3150
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3151
	.port_set_speed = mv88e6352_port_set_speed,
3152
	.port_tag_remap = mv88e6095_port_tag_remap,
3153
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3154
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3155
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3156
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3157
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3158
	.port_pause_limit = mv88e6097_port_pause_limit,
3159
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3160
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3161
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3162
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3163 3164
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3165
	.stats_get_stats = mv88e6095_stats_get_stats,
3166 3167
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3168
	.watchdog_ops = &mv88e6097_watchdog_ops,
3169
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3170
	.pot_clear = mv88e6xxx_g2_pot_clear,
3171
	.reset = mv88e6352_g1_reset,
3172
	.rmu_disable = mv88e6352_g1_rmu_disable,
3173
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3174
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3175
	.serdes_power = mv88e6352_serdes_power,
3176
	.gpio_ops = &mv88e6352_gpio_ops,
3177
	.avb_ops = &mv88e6352_avb_ops,
3178 3179
};

3180
static const struct mv88e6xxx_ops mv88e6290_ops = {
3181
	/* MV88E6XXX_FAMILY_6390 */
3182
	.irl_init_all = mv88e6390_g2_irl_init_all,
3183 3184
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3185 3186 3187 3188 3189 3190 3191
	.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,
3192
	.port_tag_remap = mv88e6390_port_tag_remap,
3193
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3194
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3195
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3196
	.port_pause_limit = mv88e6390_port_pause_limit,
3197
	.port_set_cmode = mv88e6390x_port_set_cmode,
3198
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3199
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3200
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3201
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3202 3203
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3204
	.stats_get_stats = mv88e6390_stats_get_stats,
3205 3206
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3207
	.watchdog_ops = &mv88e6390_watchdog_ops,
3208
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3209
	.pot_clear = mv88e6xxx_g2_pot_clear,
3210
	.reset = mv88e6352_g1_reset,
3211
	.rmu_disable = mv88e6390_g1_rmu_disable,
3212 3213
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3214
	.serdes_power = mv88e6390_serdes_power,
3215
	.gpio_ops = &mv88e6352_gpio_ops,
3216
	.avb_ops = &mv88e6390_avb_ops,
3217 3218
};

3219
static const struct mv88e6xxx_ops mv88e6320_ops = {
3220
	/* MV88E6XXX_FAMILY_6320 */
3221 3222
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3223
	.irl_init_all = mv88e6352_g2_irl_init_all,
3224 3225
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3226
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3227 3228
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3229
	.port_set_link = mv88e6xxx_port_set_link,
3230
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3231
	.port_set_speed = mv88e6185_port_set_speed,
3232
	.port_tag_remap = mv88e6095_port_tag_remap,
3233
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3234
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3235
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3236
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3237
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3238
	.port_pause_limit = mv88e6097_port_pause_limit,
3239
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3240
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3241
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3242
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3243 3244
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3245
	.stats_get_stats = mv88e6320_stats_get_stats,
3246 3247
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3248
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3249
	.pot_clear = mv88e6xxx_g2_pot_clear,
3250
	.reset = mv88e6352_g1_reset,
3251
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3252
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3253
	.gpio_ops = &mv88e6352_gpio_ops,
3254
	.avb_ops = &mv88e6352_avb_ops,
3255 3256 3257
};

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

3293 3294
static const struct mv88e6xxx_ops mv88e6341_ops = {
	/* MV88E6XXX_FAMILY_6341 */
3295 3296
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3297
	.irl_init_all = mv88e6352_g2_irl_init_all,
3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310
	.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,
3311
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3312
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3313
	.port_pause_limit = mv88e6097_port_pause_limit,
3314 3315 3316
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3317
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3318 3319 3320
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
3321 3322
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3323 3324
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
3325
	.pot_clear = mv88e6xxx_g2_pot_clear,
3326
	.reset = mv88e6352_g1_reset,
3327
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3328
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3329
	.gpio_ops = &mv88e6352_gpio_ops,
3330
	.avb_ops = &mv88e6390_avb_ops,
3331 3332
};

3333
static const struct mv88e6xxx_ops mv88e6350_ops = {
3334
	/* MV88E6XXX_FAMILY_6351 */
3335 3336
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3337
	.irl_init_all = mv88e6352_g2_irl_init_all,
3338
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3339 3340
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3341
	.port_set_link = mv88e6xxx_port_set_link,
3342
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3343
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3344
	.port_set_speed = mv88e6185_port_set_speed,
3345
	.port_tag_remap = mv88e6095_port_tag_remap,
3346
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3347
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3348
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3349
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3350
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3351
	.port_pause_limit = mv88e6097_port_pause_limit,
3352
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3353
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3354
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3355
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3356 3357
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3358
	.stats_get_stats = mv88e6095_stats_get_stats,
3359 3360
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3361
	.watchdog_ops = &mv88e6097_watchdog_ops,
3362
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3363
	.pot_clear = mv88e6xxx_g2_pot_clear,
3364
	.reset = mv88e6352_g1_reset,
3365
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3366
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3367 3368 3369
};

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

static const struct mv88e6xxx_ops mv88e6352_ops = {
3407
	/* MV88E6XXX_FAMILY_6352 */
3408 3409
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3410
	.irl_init_all = mv88e6352_g2_irl_init_all,
3411 3412
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3413
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3414 3415
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3416
	.port_set_link = mv88e6xxx_port_set_link,
3417
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3418
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3419
	.port_set_speed = mv88e6352_port_set_speed,
3420
	.port_tag_remap = mv88e6095_port_tag_remap,
3421
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3422
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3423
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3424
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3425
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3426
	.port_pause_limit = mv88e6097_port_pause_limit,
3427
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3428
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3429
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3430
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3431 3432
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3433
	.stats_get_stats = mv88e6095_stats_get_stats,
3434 3435
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3436
	.watchdog_ops = &mv88e6097_watchdog_ops,
3437
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3438
	.pot_clear = mv88e6xxx_g2_pot_clear,
3439
	.reset = mv88e6352_g1_reset,
3440
	.rmu_disable = mv88e6352_g1_rmu_disable,
3441
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3442
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3443
	.serdes_power = mv88e6352_serdes_power,
3444
	.gpio_ops = &mv88e6352_gpio_ops,
3445
	.avb_ops = &mv88e6352_avb_ops,
3446 3447 3448
	.serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
	.serdes_get_strings = mv88e6352_serdes_get_strings,
	.serdes_get_stats = mv88e6352_serdes_get_stats,
3449 3450
};

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

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

3533 3534
static const struct mv88e6xxx_info mv88e6xxx_table[] = {
	[MV88E6085] = {
3535
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
3536 3537 3538 3539
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6085",
		.num_databases = 4096,
		.num_ports = 10,
3540
		.num_internal_phys = 5,
3541
		.max_vid = 4095,
3542
		.port_base_addr = 0x10,
3543
		.phy_base_addr = 0x0,
3544
		.global1_addr = 0x1b,
3545
		.global2_addr = 0x1c,
3546
		.age_time_coeff = 15000,
3547
		.g1_irqs = 8,
3548
		.g2_irqs = 10,
3549
		.atu_move_port_mask = 0xf,
3550
		.pvt = true,
3551
		.multi_chip = true,
3552
		.tag_protocol = DSA_TAG_PROTO_DSA,
3553
		.ops = &mv88e6085_ops,
3554 3555 3556
	},

	[MV88E6095] = {
3557
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
3558 3559 3560 3561
		.family = MV88E6XXX_FAMILY_6095,
		.name = "Marvell 88E6095/88E6095F",
		.num_databases = 256,
		.num_ports = 11,
3562
		.num_internal_phys = 0,
3563
		.max_vid = 4095,
3564
		.port_base_addr = 0x10,
3565
		.phy_base_addr = 0x0,
3566
		.global1_addr = 0x1b,
3567
		.global2_addr = 0x1c,
3568
		.age_time_coeff = 15000,
3569
		.g1_irqs = 8,
3570
		.atu_move_port_mask = 0xf,
3571
		.multi_chip = true,
3572
		.tag_protocol = DSA_TAG_PROTO_DSA,
3573
		.ops = &mv88e6095_ops,
3574 3575
	},

3576
	[MV88E6097] = {
3577
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
3578 3579 3580 3581
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6097/88E6097F",
		.num_databases = 4096,
		.num_ports = 11,
3582
		.num_internal_phys = 8,
3583
		.max_vid = 4095,
3584
		.port_base_addr = 0x10,
3585
		.phy_base_addr = 0x0,
3586
		.global1_addr = 0x1b,
3587
		.global2_addr = 0x1c,
3588
		.age_time_coeff = 15000,
3589
		.g1_irqs = 8,
3590
		.g2_irqs = 10,
3591
		.atu_move_port_mask = 0xf,
3592
		.pvt = true,
3593
		.multi_chip = true,
3594
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3595 3596 3597
		.ops = &mv88e6097_ops,
	},

3598
	[MV88E6123] = {
3599
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
3600 3601 3602 3603
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6123",
		.num_databases = 4096,
		.num_ports = 3,
3604
		.num_internal_phys = 5,
3605
		.max_vid = 4095,
3606
		.port_base_addr = 0x10,
3607
		.phy_base_addr = 0x0,
3608
		.global1_addr = 0x1b,
3609
		.global2_addr = 0x1c,
3610
		.age_time_coeff = 15000,
3611
		.g1_irqs = 9,
3612
		.g2_irqs = 10,
3613
		.atu_move_port_mask = 0xf,
3614
		.pvt = true,
3615
		.multi_chip = true,
3616
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3617
		.ops = &mv88e6123_ops,
3618 3619 3620
	},

	[MV88E6131] = {
3621
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
3622 3623 3624 3625
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6131",
		.num_databases = 256,
		.num_ports = 8,
3626
		.num_internal_phys = 0,
3627
		.max_vid = 4095,
3628
		.port_base_addr = 0x10,
3629
		.phy_base_addr = 0x0,
3630
		.global1_addr = 0x1b,
3631
		.global2_addr = 0x1c,
3632
		.age_time_coeff = 15000,
3633
		.g1_irqs = 9,
3634
		.atu_move_port_mask = 0xf,
3635
		.multi_chip = true,
3636
		.tag_protocol = DSA_TAG_PROTO_DSA,
3637
		.ops = &mv88e6131_ops,
3638 3639
	},

3640
	[MV88E6141] = {
3641
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
3642
		.family = MV88E6XXX_FAMILY_6341,
3643
		.name = "Marvell 88E6141",
3644 3645
		.num_databases = 4096,
		.num_ports = 6,
3646
		.num_internal_phys = 5,
3647
		.num_gpio = 11,
3648
		.max_vid = 4095,
3649
		.port_base_addr = 0x10,
3650
		.phy_base_addr = 0x10,
3651
		.global1_addr = 0x1b,
3652
		.global2_addr = 0x1c,
3653 3654
		.age_time_coeff = 3750,
		.atu_move_port_mask = 0x1f,
3655
		.g1_irqs = 9,
3656
		.g2_irqs = 10,
3657
		.pvt = true,
3658
		.multi_chip = true,
3659 3660 3661 3662
		.tag_protocol = DSA_TAG_PROTO_EDSA,
		.ops = &mv88e6141_ops,
	},

3663
	[MV88E6161] = {
3664
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
3665 3666 3667 3668
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6161",
		.num_databases = 4096,
		.num_ports = 6,
3669
		.num_internal_phys = 5,
3670
		.max_vid = 4095,
3671
		.port_base_addr = 0x10,
3672
		.phy_base_addr = 0x0,
3673
		.global1_addr = 0x1b,
3674
		.global2_addr = 0x1c,
3675
		.age_time_coeff = 15000,
3676
		.g1_irqs = 9,
3677
		.g2_irqs = 10,
3678
		.atu_move_port_mask = 0xf,
3679
		.pvt = true,
3680
		.multi_chip = true,
3681
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3682
		.ops = &mv88e6161_ops,
3683 3684 3685
	},

	[MV88E6165] = {
3686
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
3687 3688 3689 3690
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6165",
		.num_databases = 4096,
		.num_ports = 6,
3691
		.num_internal_phys = 0,
3692
		.max_vid = 4095,
3693
		.port_base_addr = 0x10,
3694
		.phy_base_addr = 0x0,
3695
		.global1_addr = 0x1b,
3696
		.global2_addr = 0x1c,
3697
		.age_time_coeff = 15000,
3698
		.g1_irqs = 9,
3699
		.g2_irqs = 10,
3700
		.atu_move_port_mask = 0xf,
3701
		.pvt = true,
3702
		.multi_chip = true,
3703
		.tag_protocol = DSA_TAG_PROTO_DSA,
3704
		.ops = &mv88e6165_ops,
3705 3706 3707
	},

	[MV88E6171] = {
3708
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
3709 3710 3711 3712
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6171",
		.num_databases = 4096,
		.num_ports = 7,
3713
		.num_internal_phys = 5,
3714
		.max_vid = 4095,
3715
		.port_base_addr = 0x10,
3716
		.phy_base_addr = 0x0,
3717
		.global1_addr = 0x1b,
3718
		.global2_addr = 0x1c,
3719
		.age_time_coeff = 15000,
3720
		.g1_irqs = 9,
3721
		.g2_irqs = 10,
3722
		.atu_move_port_mask = 0xf,
3723
		.pvt = true,
3724
		.multi_chip = true,
3725
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3726
		.ops = &mv88e6171_ops,
3727 3728 3729
	},

	[MV88E6172] = {
3730
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
3731 3732 3733 3734
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6172",
		.num_databases = 4096,
		.num_ports = 7,
3735
		.num_internal_phys = 5,
3736
		.num_gpio = 15,
3737
		.max_vid = 4095,
3738
		.port_base_addr = 0x10,
3739
		.phy_base_addr = 0x0,
3740
		.global1_addr = 0x1b,
3741
		.global2_addr = 0x1c,
3742
		.age_time_coeff = 15000,
3743
		.g1_irqs = 9,
3744
		.g2_irqs = 10,
3745
		.atu_move_port_mask = 0xf,
3746
		.pvt = true,
3747
		.multi_chip = true,
3748
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3749
		.ops = &mv88e6172_ops,
3750 3751 3752
	},

	[MV88E6175] = {
3753
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
3754 3755 3756 3757
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6175",
		.num_databases = 4096,
		.num_ports = 7,
3758
		.num_internal_phys = 5,
3759
		.max_vid = 4095,
3760
		.port_base_addr = 0x10,
3761
		.phy_base_addr = 0x0,
3762
		.global1_addr = 0x1b,
3763
		.global2_addr = 0x1c,
3764
		.age_time_coeff = 15000,
3765
		.g1_irqs = 9,
3766
		.g2_irqs = 10,
3767
		.atu_move_port_mask = 0xf,
3768
		.pvt = true,
3769
		.multi_chip = true,
3770
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3771
		.ops = &mv88e6175_ops,
3772 3773 3774
	},

	[MV88E6176] = {
3775
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
3776 3777 3778 3779
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6176",
		.num_databases = 4096,
		.num_ports = 7,
3780
		.num_internal_phys = 5,
3781
		.num_gpio = 15,
3782
		.max_vid = 4095,
3783
		.port_base_addr = 0x10,
3784
		.phy_base_addr = 0x0,
3785
		.global1_addr = 0x1b,
3786
		.global2_addr = 0x1c,
3787
		.age_time_coeff = 15000,
3788
		.g1_irqs = 9,
3789
		.g2_irqs = 10,
3790
		.atu_move_port_mask = 0xf,
3791
		.pvt = true,
3792
		.multi_chip = true,
3793
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3794
		.ops = &mv88e6176_ops,
3795 3796 3797
	},

	[MV88E6185] = {
3798
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
3799 3800 3801 3802
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6185",
		.num_databases = 256,
		.num_ports = 10,
3803
		.num_internal_phys = 0,
3804
		.max_vid = 4095,
3805
		.port_base_addr = 0x10,
3806
		.phy_base_addr = 0x0,
3807
		.global1_addr = 0x1b,
3808
		.global2_addr = 0x1c,
3809
		.age_time_coeff = 15000,
3810
		.g1_irqs = 8,
3811
		.atu_move_port_mask = 0xf,
3812
		.multi_chip = true,
3813
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3814
		.ops = &mv88e6185_ops,
3815 3816
	},

3817
	[MV88E6190] = {
3818
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
3819 3820 3821 3822
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3823
		.num_internal_phys = 11,
3824
		.num_gpio = 16,
3825
		.max_vid = 8191,
3826
		.port_base_addr = 0x0,
3827
		.phy_base_addr = 0x0,
3828
		.global1_addr = 0x1b,
3829
		.global2_addr = 0x1c,
3830
		.tag_protocol = DSA_TAG_PROTO_DSA,
3831
		.age_time_coeff = 3750,
3832
		.g1_irqs = 9,
3833
		.g2_irqs = 14,
3834
		.pvt = true,
3835
		.multi_chip = true,
3836
		.atu_move_port_mask = 0x1f,
3837 3838 3839 3840
		.ops = &mv88e6190_ops,
	},

	[MV88E6190X] = {
3841
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
3842 3843 3844 3845
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3846
		.num_internal_phys = 11,
3847
		.num_gpio = 16,
3848
		.max_vid = 8191,
3849
		.port_base_addr = 0x0,
3850
		.phy_base_addr = 0x0,
3851
		.global1_addr = 0x1b,
3852
		.global2_addr = 0x1c,
3853
		.age_time_coeff = 3750,
3854
		.g1_irqs = 9,
3855
		.g2_irqs = 14,
3856
		.atu_move_port_mask = 0x1f,
3857
		.pvt = true,
3858
		.multi_chip = true,
3859
		.tag_protocol = DSA_TAG_PROTO_DSA,
3860 3861 3862 3863
		.ops = &mv88e6190x_ops,
	},

	[MV88E6191] = {
3864
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
3865 3866 3867 3868
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6191",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3869
		.num_internal_phys = 11,
3870
		.max_vid = 8191,
3871
		.port_base_addr = 0x0,
3872
		.phy_base_addr = 0x0,
3873
		.global1_addr = 0x1b,
3874
		.global2_addr = 0x1c,
3875
		.age_time_coeff = 3750,
3876
		.g1_irqs = 9,
3877
		.g2_irqs = 14,
3878
		.atu_move_port_mask = 0x1f,
3879
		.pvt = true,
3880
		.multi_chip = true,
3881
		.tag_protocol = DSA_TAG_PROTO_DSA,
3882
		.ptp_support = true,
3883
		.ops = &mv88e6191_ops,
3884 3885
	},

3886
	[MV88E6240] = {
3887
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
3888 3889 3890 3891
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6240",
		.num_databases = 4096,
		.num_ports = 7,
3892
		.num_internal_phys = 5,
3893
		.num_gpio = 15,
3894
		.max_vid = 4095,
3895
		.port_base_addr = 0x10,
3896
		.phy_base_addr = 0x0,
3897
		.global1_addr = 0x1b,
3898
		.global2_addr = 0x1c,
3899
		.age_time_coeff = 15000,
3900
		.g1_irqs = 9,
3901
		.g2_irqs = 10,
3902
		.atu_move_port_mask = 0xf,
3903
		.pvt = true,
3904
		.multi_chip = true,
3905
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3906
		.ptp_support = true,
3907
		.ops = &mv88e6240_ops,
3908 3909
	},

3910
	[MV88E6290] = {
3911
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
3912 3913 3914 3915
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6290",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3916
		.num_internal_phys = 11,
3917
		.num_gpio = 16,
3918
		.max_vid = 8191,
3919
		.port_base_addr = 0x0,
3920
		.phy_base_addr = 0x0,
3921
		.global1_addr = 0x1b,
3922
		.global2_addr = 0x1c,
3923
		.age_time_coeff = 3750,
3924
		.g1_irqs = 9,
3925
		.g2_irqs = 14,
3926
		.atu_move_port_mask = 0x1f,
3927
		.pvt = true,
3928
		.multi_chip = true,
3929
		.tag_protocol = DSA_TAG_PROTO_DSA,
3930
		.ptp_support = true,
3931 3932 3933
		.ops = &mv88e6290_ops,
	},

3934
	[MV88E6320] = {
3935
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
3936 3937 3938 3939
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6320",
		.num_databases = 4096,
		.num_ports = 7,
3940
		.num_internal_phys = 5,
3941
		.num_gpio = 15,
3942
		.max_vid = 4095,
3943
		.port_base_addr = 0x10,
3944
		.phy_base_addr = 0x0,
3945
		.global1_addr = 0x1b,
3946
		.global2_addr = 0x1c,
3947
		.age_time_coeff = 15000,
3948
		.g1_irqs = 8,
3949
		.g2_irqs = 10,
3950
		.atu_move_port_mask = 0xf,
3951
		.pvt = true,
3952
		.multi_chip = true,
3953
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3954
		.ptp_support = true,
3955
		.ops = &mv88e6320_ops,
3956 3957 3958
	},

	[MV88E6321] = {
3959
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
3960 3961 3962 3963
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6321",
		.num_databases = 4096,
		.num_ports = 7,
3964
		.num_internal_phys = 5,
3965
		.num_gpio = 15,
3966
		.max_vid = 4095,
3967
		.port_base_addr = 0x10,
3968
		.phy_base_addr = 0x0,
3969
		.global1_addr = 0x1b,
3970
		.global2_addr = 0x1c,
3971
		.age_time_coeff = 15000,
3972
		.g1_irqs = 8,
3973
		.g2_irqs = 10,
3974
		.atu_move_port_mask = 0xf,
3975
		.multi_chip = true,
3976
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3977
		.ptp_support = true,
3978
		.ops = &mv88e6321_ops,
3979 3980
	},

3981
	[MV88E6341] = {
3982
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
3983 3984 3985
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
3986
		.num_internal_phys = 5,
3987
		.num_ports = 6,
3988
		.num_gpio = 11,
3989
		.max_vid = 4095,
3990
		.port_base_addr = 0x10,
3991
		.phy_base_addr = 0x10,
3992
		.global1_addr = 0x1b,
3993
		.global2_addr = 0x1c,
3994
		.age_time_coeff = 3750,
3995
		.atu_move_port_mask = 0x1f,
3996
		.g1_irqs = 9,
3997
		.g2_irqs = 10,
3998
		.pvt = true,
3999
		.multi_chip = true,
4000
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4001
		.ptp_support = true,
4002 4003 4004
		.ops = &mv88e6341_ops,
	},

4005
	[MV88E6350] = {
4006
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
4007 4008 4009 4010
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6350",
		.num_databases = 4096,
		.num_ports = 7,
4011
		.num_internal_phys = 5,
4012
		.max_vid = 4095,
4013
		.port_base_addr = 0x10,
4014
		.phy_base_addr = 0x0,
4015
		.global1_addr = 0x1b,
4016
		.global2_addr = 0x1c,
4017
		.age_time_coeff = 15000,
4018
		.g1_irqs = 9,
4019
		.g2_irqs = 10,
4020
		.atu_move_port_mask = 0xf,
4021
		.pvt = true,
4022
		.multi_chip = true,
4023
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4024
		.ops = &mv88e6350_ops,
4025 4026 4027
	},

	[MV88E6351] = {
4028
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
4029 4030 4031 4032
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6351",
		.num_databases = 4096,
		.num_ports = 7,
4033
		.num_internal_phys = 5,
4034
		.max_vid = 4095,
4035
		.port_base_addr = 0x10,
4036
		.phy_base_addr = 0x0,
4037
		.global1_addr = 0x1b,
4038
		.global2_addr = 0x1c,
4039
		.age_time_coeff = 15000,
4040
		.g1_irqs = 9,
4041
		.g2_irqs = 10,
4042
		.atu_move_port_mask = 0xf,
4043
		.pvt = true,
4044
		.multi_chip = true,
4045
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4046
		.ops = &mv88e6351_ops,
4047 4048 4049
	},

	[MV88E6352] = {
4050
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
4051 4052 4053 4054
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6352",
		.num_databases = 4096,
		.num_ports = 7,
4055
		.num_internal_phys = 5,
4056
		.num_gpio = 15,
4057
		.max_vid = 4095,
4058
		.port_base_addr = 0x10,
4059
		.phy_base_addr = 0x0,
4060
		.global1_addr = 0x1b,
4061
		.global2_addr = 0x1c,
4062
		.age_time_coeff = 15000,
4063
		.g1_irqs = 9,
4064
		.g2_irqs = 10,
4065
		.atu_move_port_mask = 0xf,
4066
		.pvt = true,
4067
		.multi_chip = true,
4068
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4069
		.ptp_support = true,
4070
		.ops = &mv88e6352_ops,
4071
	},
4072
	[MV88E6390] = {
4073
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
4074 4075 4076 4077
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4078
		.num_internal_phys = 11,
4079
		.num_gpio = 16,
4080
		.max_vid = 8191,
4081
		.port_base_addr = 0x0,
4082
		.phy_base_addr = 0x0,
4083
		.global1_addr = 0x1b,
4084
		.global2_addr = 0x1c,
4085
		.age_time_coeff = 3750,
4086
		.g1_irqs = 9,
4087
		.g2_irqs = 14,
4088
		.atu_move_port_mask = 0x1f,
4089
		.pvt = true,
4090
		.multi_chip = true,
4091
		.tag_protocol = DSA_TAG_PROTO_DSA,
4092
		.ptp_support = true,
4093 4094 4095
		.ops = &mv88e6390_ops,
	},
	[MV88E6390X] = {
4096
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
4097 4098 4099 4100
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4101
		.num_internal_phys = 11,
4102
		.num_gpio = 16,
4103
		.max_vid = 8191,
4104
		.port_base_addr = 0x0,
4105
		.phy_base_addr = 0x0,
4106
		.global1_addr = 0x1b,
4107
		.global2_addr = 0x1c,
4108
		.age_time_coeff = 3750,
4109
		.g1_irqs = 9,
4110
		.g2_irqs = 14,
4111
		.atu_move_port_mask = 0x1f,
4112
		.pvt = true,
4113
		.multi_chip = true,
4114
		.tag_protocol = DSA_TAG_PROTO_DSA,
4115
		.ptp_support = true,
4116 4117
		.ops = &mv88e6390x_ops,
	},
4118 4119
};

4120
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
4121
{
4122
	int i;
4123

4124 4125 4126
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
4127 4128 4129 4130

	return NULL;
}

4131
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
4132 4133
{
	const struct mv88e6xxx_info *info;
4134 4135 4136
	unsigned int prod_num, rev;
	u16 id;
	int err;
4137

4138
	mutex_lock(&chip->reg_lock);
4139
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
4140 4141 4142
	mutex_unlock(&chip->reg_lock);
	if (err)
		return err;
4143

4144 4145
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
4146 4147 4148 4149 4150

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

4151
	/* Update the compatible info with the probed one */
4152
	chip->info = info;
4153

4154 4155 4156 4157
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

4158 4159
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
4160 4161 4162 4163

	return 0;
}

4164
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
4165
{
4166
	struct mv88e6xxx_chip *chip;
4167

4168 4169
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
4170 4171
		return NULL;

4172
	chip->dev = dev;
4173

4174
	mutex_init(&chip->reg_lock);
4175
	INIT_LIST_HEAD(&chip->mdios);
4176

4177
	return chip;
4178 4179
}

4180
static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
4181 4182
			      struct mii_bus *bus, int sw_addr)
{
4183
	if (sw_addr == 0)
4184
		chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
4185
	else if (chip->info->multi_chip)
4186
		chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
4187 4188 4189
	else
		return -EINVAL;

4190 4191
	chip->bus = bus;
	chip->sw_addr = sw_addr;
4192 4193 4194 4195

	return 0;
}

4196 4197
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
							int port)
4198
{
V
Vivien Didelot 已提交
4199
	struct mv88e6xxx_chip *chip = ds->priv;
4200

4201
	return chip->info->tag_protocol;
4202 4203
}

4204
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
4205 4206 4207
static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
				       struct device *host_dev, int sw_addr,
				       void **priv)
4208
{
4209
	struct mv88e6xxx_chip *chip;
4210
	struct mii_bus *bus;
4211
	int err;
4212

4213
	bus = dsa_host_dev_to_mii_bus(host_dev);
4214 4215 4216
	if (!bus)
		return NULL;

4217 4218
	chip = mv88e6xxx_alloc_chip(dsa_dev);
	if (!chip)
4219 4220
		return NULL;

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

4224
	err = mv88e6xxx_smi_init(chip, bus, sw_addr);
4225 4226 4227
	if (err)
		goto free;

4228
	err = mv88e6xxx_detect(chip);
4229
	if (err)
4230
		goto free;
4231

4232 4233 4234 4235 4236 4237
	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_switch_reset(chip);
	mutex_unlock(&chip->reg_lock);
	if (err)
		goto free;

4238 4239
	mv88e6xxx_phy_init(chip);

4240
	err = mv88e6xxx_mdios_register(chip, NULL);
4241
	if (err)
4242
		goto free;
4243

4244
	*priv = chip;
4245

4246
	return chip->info->name;
4247
free:
4248
	devm_kfree(dsa_dev, chip);
4249 4250

	return NULL;
4251
}
4252
#endif
4253

4254
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4255
				      const struct switchdev_obj_port_mdb *mdb)
4256 4257 4258 4259 4260 4261 4262 4263 4264
{
	/* 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,
4265
				   const struct switchdev_obj_port_mdb *mdb)
4266
{
V
Vivien Didelot 已提交
4267
	struct mv88e6xxx_chip *chip = ds->priv;
4268 4269 4270

	mutex_lock(&chip->reg_lock);
	if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4271
					 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
4272 4273
		dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
			port);
4274 4275 4276 4277 4278 4279
	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 已提交
4280
	struct mv88e6xxx_chip *chip = ds->priv;
4281 4282 4283 4284
	int err;

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4285
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
4286 4287 4288 4289 4290
	mutex_unlock(&chip->reg_lock);

	return err;
}

4291
static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
4292
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
4293
	.probe			= mv88e6xxx_drv_probe,
4294
#endif
4295
	.get_tag_protocol	= mv88e6xxx_get_tag_protocol,
4296 4297
	.setup			= mv88e6xxx_setup,
	.adjust_link		= mv88e6xxx_adjust_link,
4298 4299 4300 4301 4302
	.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,
4303 4304 4305
	.get_strings		= mv88e6xxx_get_strings,
	.get_ethtool_stats	= mv88e6xxx_get_ethtool_stats,
	.get_sset_count		= mv88e6xxx_get_sset_count,
4306 4307
	.port_enable		= mv88e6xxx_port_enable,
	.port_disable		= mv88e6xxx_port_disable,
V
Vivien Didelot 已提交
4308 4309
	.get_mac_eee		= mv88e6xxx_get_mac_eee,
	.set_mac_eee		= mv88e6xxx_set_mac_eee,
4310
	.get_eeprom_len		= mv88e6xxx_get_eeprom_len,
4311 4312 4313 4314
	.get_eeprom		= mv88e6xxx_get_eeprom,
	.set_eeprom		= mv88e6xxx_set_eeprom,
	.get_regs_len		= mv88e6xxx_get_regs_len,
	.get_regs		= mv88e6xxx_get_regs,
4315
	.set_ageing_time	= mv88e6xxx_set_ageing_time,
4316 4317 4318
	.port_bridge_join	= mv88e6xxx_port_bridge_join,
	.port_bridge_leave	= mv88e6xxx_port_bridge_leave,
	.port_stp_state_set	= mv88e6xxx_port_stp_state_set,
4319
	.port_fast_age		= mv88e6xxx_port_fast_age,
4320 4321 4322 4323 4324 4325 4326
	.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,
4327 4328 4329
	.port_mdb_prepare       = mv88e6xxx_port_mdb_prepare,
	.port_mdb_add           = mv88e6xxx_port_mdb_add,
	.port_mdb_del           = mv88e6xxx_port_mdb_del,
4330 4331
	.crosschip_bridge_join	= mv88e6xxx_crosschip_bridge_join,
	.crosschip_bridge_leave	= mv88e6xxx_crosschip_bridge_leave,
4332 4333 4334 4335 4336
	.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,
4337 4338
};

4339 4340 4341 4342
static struct dsa_switch_driver mv88e6xxx_switch_drv = {
	.ops			= &mv88e6xxx_switch_ops,
};

4343
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
4344
{
4345
	struct device *dev = chip->dev;
4346 4347
	struct dsa_switch *ds;

4348
	ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
4349 4350 4351
	if (!ds)
		return -ENOMEM;

4352
	ds->priv = chip;
4353
	ds->ops = &mv88e6xxx_switch_ops;
4354 4355
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
4356 4357 4358

	dev_set_drvdata(dev, ds);

4359
	return dsa_register_switch(ds);
4360 4361
}

4362
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
4363
{
4364
	dsa_unregister_switch(chip->ds);
4365 4366
}

4367
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
4368
{
4369
	struct device *dev = &mdiodev->dev;
4370
	struct device_node *np = dev->of_node;
4371
	const struct mv88e6xxx_info *compat_info;
4372
	struct mv88e6xxx_chip *chip;
4373
	u32 eeprom_len;
4374
	int err;
4375

4376 4377 4378 4379
	compat_info = of_device_get_match_data(dev);
	if (!compat_info)
		return -EINVAL;

4380 4381
	chip = mv88e6xxx_alloc_chip(dev);
	if (!chip)
4382 4383
		return -ENOMEM;

4384
	chip->info = compat_info;
4385

4386
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
4387 4388
	if (err)
		return err;
4389

4390 4391 4392 4393
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
	if (IS_ERR(chip->reset))
		return PTR_ERR(chip->reset);

4394
	err = mv88e6xxx_detect(chip);
4395 4396
	if (err)
		return err;
4397

4398 4399
	mv88e6xxx_phy_init(chip);

4400
	if (chip->info->ops->get_eeprom &&
4401
	    !of_property_read_u32(np, "eeprom-length", &eeprom_len))
4402
		chip->eeprom_len = eeprom_len;
4403

4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415
	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;
	}

4416
	/* Has to be performed before the MDIO bus is created, because
4417
	 * the PHYs will link their interrupts to these interrupt
4418 4419 4420 4421
	 * controllers
	 */
	mutex_lock(&chip->reg_lock);
	if (chip->irq > 0)
4422
		err = mv88e6xxx_g1_irq_setup(chip);
4423 4424 4425
	else
		err = mv88e6xxx_irq_poll_setup(chip);
	mutex_unlock(&chip->reg_lock);
4426

4427 4428
	if (err)
		goto out;
4429

4430 4431
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
4432
		if (err)
4433
			goto out_g1_irq;
4434 4435
	}

4436 4437 4438 4439 4440 4441 4442 4443
	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;

4444
	err = mv88e6xxx_mdios_register(chip, np);
4445
	if (err)
4446
		goto out_g1_vtu_prob_irq;
4447

4448
	err = mv88e6xxx_register_switch(chip);
4449 4450
	if (err)
		goto out_mdio;
4451

4452
	return 0;
4453 4454

out_mdio:
4455
	mv88e6xxx_mdios_unregister(chip);
4456
out_g1_vtu_prob_irq:
4457
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
4458
out_g1_atu_prob_irq:
4459
	mv88e6xxx_g1_atu_prob_irq_free(chip);
4460
out_g2_irq:
4461
	if (chip->info->g2_irqs > 0)
4462 4463
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
4464 4465
	mutex_lock(&chip->reg_lock);
	if (chip->irq > 0)
4466
		mv88e6xxx_g1_irq_free(chip);
4467 4468 4469
	else
		mv88e6xxx_irq_poll_free(chip);
	mutex_unlock(&chip->reg_lock);
4470 4471
out:
	return err;
4472
}
4473 4474 4475 4476

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

4479 4480
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
4481
		mv88e6xxx_ptp_free(chip);
4482
	}
4483

4484
	mv88e6xxx_phy_destroy(chip);
4485
	mv88e6xxx_unregister_switch(chip);
4486
	mv88e6xxx_mdios_unregister(chip);
4487

4488 4489 4490 4491 4492 4493 4494 4495
	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);

	mutex_lock(&chip->reg_lock);
	if (chip->irq > 0)
4496
		mv88e6xxx_g1_irq_free(chip);
4497 4498 4499
	else
		mv88e6xxx_irq_poll_free(chip);
	mutex_unlock(&chip->reg_lock);
4500 4501 4502
}

static const struct of_device_id mv88e6xxx_of_match[] = {
4503 4504 4505 4506
	{
		.compatible = "marvell,mv88e6085",
		.data = &mv88e6xxx_table[MV88E6085],
	},
4507 4508 4509 4510
	{
		.compatible = "marvell,mv88e6190",
		.data = &mv88e6xxx_table[MV88E6190],
	},
4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526
	{ /* 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)
{
4527
	register_switch_driver(&mv88e6xxx_switch_drv);
4528 4529
	return mdio_driver_register(&mv88e6xxx_driver);
}
4530 4531 4532 4533
module_init(mv88e6xxx_init);

static void __exit mv88e6xxx_cleanup(void)
{
4534
	mdio_driver_unregister(&mv88e6xxx_driver);
4535
	unregister_switch_driver(&mv88e6xxx_switch_drv);
4536 4537
}
module_exit(mv88e6xxx_cleanup);
4538 4539 4540 4541

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