chip.c 125.2 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 999 1000 1001 1002 1003 1004 1005
static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->stats_set_histogram)
		return chip->info->ops->stats_set_histogram(chip);

	return 0;
}

1006
static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
1007 1008 1009 1010
{
	return 32 * sizeof(u16);
}

1011 1012
static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
			       struct ethtool_regs *regs, void *_p)
1013
{
V
Vivien Didelot 已提交
1014
	struct mv88e6xxx_chip *chip = ds->priv;
1015 1016
	int err;
	u16 reg;
1017 1018 1019 1020 1021 1022 1023
	u16 *p = _p;
	int i;

	regs->version = 0;

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

1024
	mutex_lock(&chip->reg_lock);
1025

1026 1027
	for (i = 0; i < 32; i++) {

1028 1029 1030
		err = mv88e6xxx_port_read(chip, port, i, &reg);
		if (!err)
			p[i] = reg;
1031
	}
1032

1033
	mutex_unlock(&chip->reg_lock);
1034 1035
}

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

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

1050
static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
1051
{
1052 1053 1054
	struct dsa_switch *ds = NULL;
	struct net_device *br;
	u16 pvlan;
1055 1056
	int i;

1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076
	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 已提交
1077
		    (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
1078 1079 1080 1081 1082
			pvlan |= BIT(i);

	return pvlan;
}

1083
static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
1084 1085
{
	u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
1086 1087 1088

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

1090
	return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
1091 1092
}

1093 1094
static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
					 u8 state)
1095
{
V
Vivien Didelot 已提交
1096
	struct mv88e6xxx_chip *chip = ds->priv;
1097
	int err;
1098

1099
	mutex_lock(&chip->reg_lock);
1100
	err = mv88e6xxx_port_set_state(chip, port, state);
1101
	mutex_unlock(&chip->reg_lock);
1102 1103

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

1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126
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;
	}

1127 1128 1129 1130 1131 1132 1133
	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;
	}

1134 1135 1136 1137
	err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
	if (err)
		return err;

1138 1139 1140
	return 0;
}

1141 1142 1143 1144 1145 1146 1147 1148 1149
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;
}

1150 1151 1152 1153 1154 1155 1156 1157
static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->rmu_disable)
		return chip->info->ops->rmu_disable(chip);

	return 0;
}

1158 1159 1160 1161 1162 1163 1164 1165
static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->pot_clear)
		return chip->info->ops->pot_clear(chip);

	return 0;
}

1166 1167 1168 1169 1170 1171 1172 1173
static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->mgmt_rsvd2cpu)
		return chip->info->ops->mgmt_rsvd2cpu(chip);

	return 0;
}

1174 1175
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
1176 1177
	int err;

1178 1179 1180 1181
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

1182 1183 1184 1185
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

1186 1187 1188
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208
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;
}

1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221
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;
}

1222 1223 1224 1225 1226 1227 1228 1229 1230
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)
1231
		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1232 1233 1234 1235

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

1236 1237
static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
{
1238 1239 1240
	int dev, port;
	int err;

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

1262 1263 1264 1265 1266 1267
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);
1268
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1269 1270 1271
	mutex_unlock(&chip->reg_lock);

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

1275 1276 1277 1278 1279 1280 1281 1282
static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
{
	if (!chip->info->max_vid)
		return 0;

	return mv88e6xxx_g1_vtu_flush(chip);
}

1283 1284 1285 1286 1287 1288 1289 1290 1291
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);
}

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

1301
static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1302 1303
{
	DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1304 1305 1306
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = chip->info->max_vid,
	};
1307
	int i, err;
1308 1309 1310

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

1311
	/* Set every FID bit used by the (un)bridged ports */
1312
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1313
		err = mv88e6xxx_port_get_fid(chip, i, fid);
1314 1315 1316 1317 1318 1319
		if (err)
			return err;

		set_bit(*fid, fid_bitmap);
	}

1320 1321
	/* Set every FID bit used by the VLAN entries */
	do {
1322
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1323 1324 1325 1326 1327 1328 1329
		if (err)
			return err;

		if (!vlan.valid)
			break;

		set_bit(vlan.fid, fid_bitmap);
1330
	} while (vlan.vid < chip->info->max_vid);
1331 1332 1333 1334 1335

	/* 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);
1336
	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1337 1338 1339
		return -ENOSPC;

	/* Clear the database */
1340
	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1341 1342
}

1343 1344
static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
			     struct mv88e6xxx_vtu_entry *entry, bool new)
1345 1346 1347 1348 1349 1350
{
	int err;

	if (!vid)
		return -EINVAL;

1351 1352
	entry->vid = vid - 1;
	entry->valid = false;
1353

1354
	err = mv88e6xxx_vtu_getnext(chip, entry);
1355 1356 1357
	if (err)
		return err;

1358 1359
	if (entry->vid == vid && entry->valid)
		return 0;
1360

1361 1362 1363 1364 1365 1366 1367 1368
	if (new) {
		int i;

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

1369
		/* Exclude all ports */
1370
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1371
			entry->member[i] =
1372
				MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1373 1374

		return mv88e6xxx_atu_new(chip, &entry->fid);
1375 1376
	}

1377 1378
	/* switchdev expects -EOPNOTSUPP to honor software VLANs */
	return -EOPNOTSUPP;
1379 1380
}

1381 1382 1383
static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
					u16 vid_begin, u16 vid_end)
{
V
Vivien Didelot 已提交
1384
	struct mv88e6xxx_chip *chip = ds->priv;
1385 1386 1387
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = vid_begin - 1,
	};
1388 1389
	int i, err;

1390 1391 1392 1393
	/* 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;

1394 1395 1396
	if (!vid_begin)
		return -EOPNOTSUPP;

1397
	mutex_lock(&chip->reg_lock);
1398 1399

	do {
1400
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1401 1402 1403 1404 1405 1406 1407 1408 1409
		if (err)
			goto unlock;

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

1410
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1411 1412 1413
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

1414
			if (!ds->ports[i].slave)
1415 1416
				continue;

1417
			if (vlan.member[i] ==
1418
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1419 1420
				continue;

V
Vivien Didelot 已提交
1421
			if (dsa_to_port(ds, i)->bridge_dev ==
1422
			    ds->ports[port].bridge_dev)
1423 1424
				break; /* same bridge, check next VLAN */

V
Vivien Didelot 已提交
1425
			if (!dsa_to_port(ds, i)->bridge_dev)
1426 1427
				continue;

1428 1429
			dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
				port, vlan.vid, i,
V
Vivien Didelot 已提交
1430
				netdev_name(dsa_to_port(ds, i)->bridge_dev));
1431 1432 1433 1434 1435 1436
			err = -EOPNOTSUPP;
			goto unlock;
		}
	} while (vlan.vid < vid_end);

unlock:
1437
	mutex_unlock(&chip->reg_lock);
1438 1439 1440 1441

	return err;
}

1442 1443
static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
					 bool vlan_filtering)
1444
{
V
Vivien Didelot 已提交
1445
	struct mv88e6xxx_chip *chip = ds->priv;
1446 1447
	u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
		MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
1448
	int err;
1449

1450
	if (!chip->info->max_vid)
1451 1452
		return -EOPNOTSUPP;

1453
	mutex_lock(&chip->reg_lock);
1454
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1455
	mutex_unlock(&chip->reg_lock);
1456

1457
	return err;
1458 1459
}

1460 1461
static int
mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1462
			    const struct switchdev_obj_port_vlan *vlan)
1463
{
V
Vivien Didelot 已提交
1464
	struct mv88e6xxx_chip *chip = ds->priv;
1465 1466
	int err;

1467
	if (!chip->info->max_vid)
1468 1469
		return -EOPNOTSUPP;

1470 1471 1472 1473 1474 1475 1476 1477
	/* 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;

1478 1479 1480 1481 1482 1483
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */
	return 0;
}

1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 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
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);
}

1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550
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;
}

1551
static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
1552
				    u16 vid, u8 member)
1553
{
1554
	struct mv88e6xxx_vtu_entry vlan;
1555 1556
	int err;

1557
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
1558
	if (err)
1559
		return err;
1560

1561
	vlan.member[port] = member;
1562

1563 1564 1565 1566 1567
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
	if (err)
		return err;

	return mv88e6xxx_broadcast_setup(chip, vid);
1568 1569
}

1570
static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1571
				    const struct switchdev_obj_port_vlan *vlan)
1572
{
V
Vivien Didelot 已提交
1573
	struct mv88e6xxx_chip *chip = ds->priv;
1574 1575
	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1576
	u8 member;
1577 1578
	u16 vid;

1579
	if (!chip->info->max_vid)
1580 1581
		return;

1582
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1583
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1584
	else if (untagged)
1585
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
1586
	else
1587
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
1588

1589
	mutex_lock(&chip->reg_lock);
1590

1591
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
1592
		if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
1593 1594
			dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
				vid, untagged ? 'u' : 't');
1595

1596
	if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1597 1598
		dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
			vlan->vid_end);
1599

1600
	mutex_unlock(&chip->reg_lock);
1601 1602
}

1603
static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
1604
				    int port, u16 vid)
1605
{
1606
	struct mv88e6xxx_vtu_entry vlan;
1607 1608
	int i, err;

1609
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1610
	if (err)
1611
		return err;
1612

1613
	/* Tell switchdev if this VLAN is handled in software */
1614
	if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1615
		return -EOPNOTSUPP;
1616

1617
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1618 1619

	/* keep the VLAN unless all ports are excluded */
1620
	vlan.valid = false;
1621
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1622 1623
		if (vlan.member[i] !=
		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
1624
			vlan.valid = true;
1625 1626 1627 1628
			break;
		}
	}

1629
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1630 1631 1632
	if (err)
		return err;

1633
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
1634 1635
}

1636 1637
static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
				   const struct switchdev_obj_port_vlan *vlan)
1638
{
V
Vivien Didelot 已提交
1639
	struct mv88e6xxx_chip *chip = ds->priv;
1640 1641 1642
	u16 pvid, vid;
	int err = 0;

1643
	if (!chip->info->max_vid)
1644 1645
		return -EOPNOTSUPP;

1646
	mutex_lock(&chip->reg_lock);
1647

1648
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
1649 1650 1651
	if (err)
		goto unlock;

1652
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1653
		err = _mv88e6xxx_port_vlan_del(chip, port, vid);
1654 1655 1656 1657
		if (err)
			goto unlock;

		if (vid == pvid) {
1658
			err = mv88e6xxx_port_set_pvid(chip, port, 0);
1659 1660 1661 1662 1663
			if (err)
				goto unlock;
		}
	}

1664
unlock:
1665
	mutex_unlock(&chip->reg_lock);
1666 1667 1668 1669

	return err;
}

1670 1671
static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
				  const unsigned char *addr, u16 vid)
1672
{
V
Vivien Didelot 已提交
1673
	struct mv88e6xxx_chip *chip = ds->priv;
1674
	int err;
1675

1676
	mutex_lock(&chip->reg_lock);
1677 1678
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1679
	mutex_unlock(&chip->reg_lock);
1680 1681

	return err;
1682 1683
}

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

1690
	mutex_lock(&chip->reg_lock);
1691
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1692
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
1693
	mutex_unlock(&chip->reg_lock);
1694

1695
	return err;
1696 1697
}

1698 1699
static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
				      u16 fid, u16 vid, int port,
1700
				      dsa_fdb_dump_cb_t *cb, void *data)
1701
{
1702
	struct mv88e6xxx_atu_entry addr;
1703
	bool is_static;
1704 1705
	int err;

1706
	addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1707
	eth_broadcast_addr(addr.mac);
1708 1709

	do {
1710
		mutex_lock(&chip->reg_lock);
1711
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
1712
		mutex_unlock(&chip->reg_lock);
1713
		if (err)
1714
			return err;
1715

1716
		if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
1717 1718
			break;

1719
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
1720 1721
			continue;

1722 1723
		if (!is_unicast_ether_addr(addr.mac))
			continue;
1724

1725 1726 1727
		is_static = (addr.state ==
			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
		err = cb(addr.mac, vid, is_static, data);
1728 1729
		if (err)
			return err;
1730 1731 1732 1733 1734
	} while (!is_broadcast_ether_addr(addr.mac));

	return err;
}

1735
static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1736
				  dsa_fdb_dump_cb_t *cb, void *data)
1737
{
1738
	struct mv88e6xxx_vtu_entry vlan = {
1739
		.vid = chip->info->max_vid,
1740
	};
1741
	u16 fid;
1742 1743
	int err;

1744
	/* Dump port's default Filtering Information Database (VLAN ID 0) */
1745
	mutex_lock(&chip->reg_lock);
1746
	err = mv88e6xxx_port_get_fid(chip, port, &fid);
1747 1748
	mutex_unlock(&chip->reg_lock);

1749
	if (err)
1750
		return err;
1751

1752
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
1753
	if (err)
1754
		return err;
1755

1756
	/* Dump VLANs' Filtering Information Databases */
1757
	do {
1758
		mutex_lock(&chip->reg_lock);
1759
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1760
		mutex_unlock(&chip->reg_lock);
1761
		if (err)
1762
			return err;
1763 1764 1765 1766

		if (!vlan.valid)
			break;

1767
		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1768
						 cb, data);
1769
		if (err)
1770
			return err;
1771
	} while (vlan.vid < chip->info->max_vid);
1772

1773 1774 1775 1776
	return err;
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1777
				   dsa_fdb_dump_cb_t *cb, void *data)
1778
{
V
Vivien Didelot 已提交
1779
	struct mv88e6xxx_chip *chip = ds->priv;
1780

1781
	return mv88e6xxx_port_db_dump(chip, port, cb, data);
1782 1783
}

1784 1785
static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
				struct net_device *br)
1786
{
1787
	struct dsa_switch *ds;
1788
	int port;
1789
	int dev;
1790
	int err;
1791

1792 1793 1794 1795
	/* 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);
1796
			if (err)
1797
				return err;
1798 1799 1800
		}
	}

1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818
	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;
			}
		}
	}

1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829
	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);
1830
	mutex_unlock(&chip->reg_lock);
1831

1832
	return err;
1833 1834
}

1835 1836
static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
					struct net_device *br)
1837
{
V
Vivien Didelot 已提交
1838
	struct mv88e6xxx_chip *chip = ds->priv;
1839

1840
	mutex_lock(&chip->reg_lock);
1841 1842 1843
	if (mv88e6xxx_bridge_map(chip, br) ||
	    mv88e6xxx_port_vlan_map(chip, port))
		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
1844
	mutex_unlock(&chip->reg_lock);
1845 1846
}

1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876
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);
}

1877 1878 1879 1880 1881 1882 1883 1884
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->reset)
		return chip->info->ops->reset(chip);

	return 0;
}

1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897
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);
	}
}

1898
static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1899
{
1900
	int i, err;
1901

1902
	/* Set all ports to the Disabled state */
1903
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
1904
		err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
1905 1906
		if (err)
			return err;
1907 1908
	}

1909 1910 1911
	/* Wait for transmit queues to drain,
	 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
	 */
1912 1913
	usleep_range(2000, 4000);

1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924
	return 0;
}

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

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

1925
	mv88e6xxx_hardware_reset(chip);
1926

1927
	return mv88e6xxx_software_reset(chip);
1928 1929
}

1930
static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
1931 1932
				   enum mv88e6xxx_frame_mode frame,
				   enum mv88e6xxx_egress_mode egress, u16 etype)
1933 1934 1935
{
	int err;

1936 1937 1938 1939
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
1940 1941 1942
	if (err)
		return err;

1943 1944 1945 1946 1947 1948 1949 1950
	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;
1951 1952
}

1953
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1954
{
1955
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
1956
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
1957
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
1958
}
1959

1960 1961 1962
static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
1963
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
1964
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
1965
}
1966

1967 1968 1969 1970
static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port,
				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
1971 1972
				       MV88E6XXX_EGRESS_MODE_ETHERTYPE,
				       ETH_P_EDSA);
1973
}
1974

1975 1976 1977 1978
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);
1979

1980
	if (dsa_is_user_port(chip->ds, port))
1981
		return mv88e6xxx_set_port_mode_normal(chip, port);
1982

1983 1984 1985
	/* 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);
1986

1987 1988
	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
		return mv88e6xxx_set_port_mode_edsa(chip, port);
1989

1990
	return -EINVAL;
1991 1992
}

1993
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
1994
{
1995
	bool message = dsa_is_dsa_port(chip->ds, port);
1996

1997
	return mv88e6xxx_port_set_message_port(chip, port, message);
1998
}
1999

2000
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2001
{
2002 2003
	struct dsa_switch *ds = chip->ds;
	bool flood;
2004

2005
	/* Upstream ports flood frames with unknown unicast or multicast DA */
2006
	flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
2007 2008 2009
	if (chip->info->ops->port_set_egress_floods)
		return chip->info->ops->port_set_egress_floods(chip, port,
							       flood, flood);
2010

2011
	return 0;
2012 2013
}

2014 2015 2016
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
2017 2018
	if (chip->info->ops->serdes_power)
		return chip->info->ops->serdes_power(chip, port, on);
2019

2020
	return 0;
2021 2022
}

2023 2024 2025 2026 2027 2028
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

2029
	upstream_port = dsa_upstream_port(ds, port);
2030 2031 2032 2033 2034 2035 2036
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

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

2053 2054 2055
	return 0;
}

2056
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
2057
{
2058
	struct dsa_switch *ds = chip->ds;
2059
	int err;
2060
	u16 reg;
2061

2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075
	/* 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;
2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090

	/* 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.
	 */
2091 2092 2093 2094
	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);
2095 2096
	if (err)
		return err;
2097

2098
	err = mv88e6xxx_setup_port_mode(chip, port);
2099 2100
	if (err)
		return err;
2101

2102
	err = mv88e6xxx_setup_egress_floods(chip, port);
2103 2104 2105
	if (err)
		return err;

2106 2107 2108
	/* 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.
2109
	 */
2110 2111 2112 2113 2114
	if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
		err = mv88e6xxx_serdes_power(chip, port, true);
		if (err)
			return err;
	}
2115

2116
	/* Port Control 2: don't force a good FCS, set the maximum frame size to
2117
	 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
2118 2119 2120
	 * 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.
2121
	 */
2122 2123 2124
	err = mv88e6xxx_port_set_map_da(chip, port);
	if (err)
		return err;
2125

2126 2127 2128
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
2129

2130
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
2131
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
2132 2133 2134
	if (err)
		return err;

2135 2136
	if (chip->info->ops->port_set_jumbo_size) {
		err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
2137 2138 2139 2140
		if (err)
			return err;
	}

2141 2142 2143 2144 2145
	/* 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.
	 */
2146
	reg = 1 << port;
2147 2148
	/* Disable learning for CPU port */
	if (dsa_is_cpu_port(ds, port))
2149
		reg = 0;
2150

2151 2152
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
2153 2154
	if (err)
		return err;
2155 2156

	/* Egress rate control 2: disable egress rate control. */
2157 2158
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
				   0x0000);
2159 2160
	if (err)
		return err;
2161

2162 2163
	if (chip->info->ops->port_pause_limit) {
		err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
2164 2165
		if (err)
			return err;
2166
	}
2167

2168 2169 2170 2171 2172 2173
	if (chip->info->ops->port_disable_learn_limit) {
		err = chip->info->ops->port_disable_learn_limit(chip, port);
		if (err)
			return err;
	}

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

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

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

2192
	err = mv88e6xxx_setup_message_port(chip, port);
2193 2194
	if (err)
		return err;
2195

2196
	/* Port based VLAN map: give each port the same default address
2197 2198
	 * database, and allow bidirectional communication between the
	 * CPU and DSA port(s), and the other ports.
2199
	 */
2200
	err = mv88e6xxx_port_set_fid(chip, port, 0);
2201 2202
	if (err)
		return err;
2203

2204
	err = mv88e6xxx_port_vlan_map(chip, port);
2205 2206
	if (err)
		return err;
2207 2208 2209 2210

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

2214 2215 2216 2217
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
2218
	int err;
2219 2220

	mutex_lock(&chip->reg_lock);
2221
	err = mv88e6xxx_serdes_power(chip, port, true);
2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232
	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);
2233 2234
	if (mv88e6xxx_serdes_power(chip, port, false))
		dev_err(chip->dev, "failed to power off SERDES\n");
2235 2236 2237
	mutex_unlock(&chip->reg_lock);
}

2238 2239 2240
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
2241
	struct mv88e6xxx_chip *chip = ds->priv;
2242 2243 2244
	int err;

	mutex_lock(&chip->reg_lock);
2245
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2246 2247 2248 2249 2250
	mutex_unlock(&chip->reg_lock);

	return err;
}

2251
static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
2252
{
2253
	int err;
2254 2255

	/* Configure the IP ToS mapping registers. */
2256
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_0, 0x0000);
2257
	if (err)
2258
		return err;
2259
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_1, 0x0000);
2260
	if (err)
2261
		return err;
2262
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_2, 0x5555);
2263
	if (err)
2264
		return err;
2265
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_3, 0x5555);
2266
	if (err)
2267
		return err;
2268
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_4, 0xaaaa);
2269
	if (err)
2270
		return err;
2271
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_5, 0xaaaa);
2272
	if (err)
2273
		return err;
2274
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_6, 0xffff);
2275
	if (err)
2276
		return err;
2277
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_7, 0xffff);
2278
	if (err)
2279
		return err;
2280 2281

	/* Configure the IEEE 802.1p priority mapping register. */
2282
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IEEE_PRI, 0xfa41);
2283
	if (err)
2284
		return err;
2285

2286 2287 2288 2289 2290
	/* Initialize the statistics unit */
	err = mv88e6xxx_stats_set_histogram(chip);
	if (err)
		return err;

2291
	return mv88e6xxx_g1_stats_clear(chip);
2292 2293
}

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

2300
	chip->ds = ds;
2301
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
2302

2303
	mutex_lock(&chip->reg_lock);
2304

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

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

	/* Setup Switch Global 1 Registers */
	err = mv88e6xxx_g1_setup(chip);
2317 2318 2319
	if (err)
		goto unlock;

2320 2321 2322 2323
	err = mv88e6xxx_irl_setup(chip);
	if (err)
		goto unlock;

2324 2325 2326 2327
	err = mv88e6xxx_mac_setup(chip);
	if (err)
		goto unlock;

2328 2329 2330 2331
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

2332 2333 2334 2335
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

2336 2337 2338 2339
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

2340 2341 2342 2343
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

2344 2345 2346 2347
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

2348 2349 2350 2351
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

2352 2353 2354 2355
	err = mv88e6xxx_rmu_setup(chip);
	if (err)
		goto unlock;

2356 2357 2358
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
2359

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

2364 2365 2366 2367
	err = mv88e6xxx_devmap_setup(chip);
	if (err)
		goto unlock;

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

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

2379
unlock:
2380
	mutex_unlock(&chip->reg_lock);
2381

2382
	return err;
2383 2384
}

2385
static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
2386
{
2387 2388
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2389 2390
	u16 val;
	int err;
2391

2392 2393 2394
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

2395
	mutex_lock(&chip->reg_lock);
2396
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
2397
	mutex_unlock(&chip->reg_lock);
2398

2399 2400 2401 2402 2403
	if (reg == MII_PHYSID2) {
		/* Some internal PHYS don't have a model number.  Use
		 * the mv88e6390 family model number instead.
		 */
		if (!(val & 0x3f0))
2404
			val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
2405 2406
	}

2407
	return err ? err : val;
2408 2409
}

2410
static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
2411
{
2412 2413
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2414
	int err;
2415

2416 2417 2418
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

2419
	mutex_lock(&chip->reg_lock);
2420
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
2421
	mutex_unlock(&chip->reg_lock);
2422 2423

	return err;
2424 2425
}

2426
static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
2427 2428
				   struct device_node *np,
				   bool external)
2429 2430
{
	static int index;
2431
	struct mv88e6xxx_mdio_bus *mdio_bus;
2432 2433 2434
	struct mii_bus *bus;
	int err;

2435 2436 2437 2438 2439 2440 2441 2442 2443
	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;
	}

2444
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
2445 2446 2447
	if (!bus)
		return -ENOMEM;

2448
	mdio_bus = bus->priv;
2449
	mdio_bus->bus = bus;
2450
	mdio_bus->chip = chip;
2451 2452
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
2453

2454 2455
	if (np) {
		bus->name = np->full_name;
2456
		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
2457 2458 2459 2460 2461 2462 2463
	} 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;
2464
	bus->parent = chip->dev;
2465

2466 2467 2468 2469 2470 2471
	if (!external) {
		err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
		if (err)
			return err;
	}

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

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

	return 0;
2488
}
2489

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

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

2505 2506 2507
		if (!mdio_bus->external)
			mv88e6xxx_g2_irq_mdio_free(chip, bus);

2508 2509 2510 2511
		mdiobus_unregister(bus);
	}
}

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

	return 0;
2544 2545
}

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

	return chip->eeprom_len;
}

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

2559 2560
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
2561

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

2580 2581 2582
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

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

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

	return err;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

3279 3280
static const struct mv88e6xxx_ops mv88e6341_ops = {
	/* MV88E6XXX_FAMILY_6341 */
3281
	.irl_init_all = mv88e6352_g2_irl_init_all,
3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294
	.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,
3295
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3296
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3297
	.port_pause_limit = mv88e6097_port_pause_limit,
3298 3299 3300
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3301
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3302 3303 3304
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
3305 3306
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3307 3308
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
3309
	.pot_clear = mv88e6xxx_g2_pot_clear,
3310
	.reset = mv88e6352_g1_reset,
3311
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3312
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3313
	.gpio_ops = &mv88e6352_gpio_ops,
3314
	.avb_ops = &mv88e6390_avb_ops,
3315 3316
};

3317
static const struct mv88e6xxx_ops mv88e6350_ops = {
3318
	/* MV88E6XXX_FAMILY_6351 */
3319
	.irl_init_all = mv88e6352_g2_irl_init_all,
3320
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3321 3322
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3323
	.port_set_link = mv88e6xxx_port_set_link,
3324
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3325
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3326
	.port_set_speed = mv88e6185_port_set_speed,
3327
	.port_tag_remap = mv88e6095_port_tag_remap,
3328
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3329
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3330
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3331
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3332
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3333
	.port_pause_limit = mv88e6097_port_pause_limit,
3334
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3335
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3336
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3337
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3338 3339
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3340
	.stats_get_stats = mv88e6095_stats_get_stats,
3341 3342
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3343
	.watchdog_ops = &mv88e6097_watchdog_ops,
3344
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3345
	.pot_clear = mv88e6xxx_g2_pot_clear,
3346
	.reset = mv88e6352_g1_reset,
3347
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3348
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3349 3350 3351
};

static const struct mv88e6xxx_ops mv88e6351_ops = {
3352
	/* MV88E6XXX_FAMILY_6351 */
3353
	.irl_init_all = mv88e6352_g2_irl_init_all,
3354
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3355 3356
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3357
	.port_set_link = mv88e6xxx_port_set_link,
3358
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3359
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3360
	.port_set_speed = mv88e6185_port_set_speed,
3361
	.port_tag_remap = mv88e6095_port_tag_remap,
3362
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3363
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3364
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3365
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3366
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3367
	.port_pause_limit = mv88e6097_port_pause_limit,
3368
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3369
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3370
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3371
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3372 3373
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3374
	.stats_get_stats = mv88e6095_stats_get_stats,
3375 3376
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3377
	.watchdog_ops = &mv88e6097_watchdog_ops,
3378
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3379
	.pot_clear = mv88e6xxx_g2_pot_clear,
3380
	.reset = mv88e6352_g1_reset,
3381
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3382
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3383
	.avb_ops = &mv88e6352_avb_ops,
3384 3385 3386
};

static const struct mv88e6xxx_ops mv88e6352_ops = {
3387
	/* MV88E6XXX_FAMILY_6352 */
3388
	.irl_init_all = mv88e6352_g2_irl_init_all,
3389 3390
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3391
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3392 3393
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3394
	.port_set_link = mv88e6xxx_port_set_link,
3395
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3396
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3397
	.port_set_speed = mv88e6352_port_set_speed,
3398
	.port_tag_remap = mv88e6095_port_tag_remap,
3399
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3400
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3401
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3402
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3403
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3404
	.port_pause_limit = mv88e6097_port_pause_limit,
3405
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3406
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3407
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3408
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3409 3410
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3411
	.stats_get_stats = mv88e6095_stats_get_stats,
3412 3413
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3414
	.watchdog_ops = &mv88e6097_watchdog_ops,
3415
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3416
	.pot_clear = mv88e6xxx_g2_pot_clear,
3417
	.reset = mv88e6352_g1_reset,
3418
	.rmu_disable = mv88e6352_g1_rmu_disable,
3419
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3420
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3421
	.serdes_power = mv88e6352_serdes_power,
3422
	.gpio_ops = &mv88e6352_gpio_ops,
3423
	.avb_ops = &mv88e6352_avb_ops,
3424 3425 3426
	.serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
	.serdes_get_strings = mv88e6352_serdes_get_strings,
	.serdes_get_stats = mv88e6352_serdes_get_stats,
3427 3428
};

3429
static const struct mv88e6xxx_ops mv88e6390_ops = {
3430
	/* MV88E6XXX_FAMILY_6390 */
3431
	.irl_init_all = mv88e6390_g2_irl_init_all,
3432 3433
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3434 3435 3436 3437 3438 3439 3440
	.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,
3441
	.port_tag_remap = mv88e6390_port_tag_remap,
3442
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3443
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3444
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3445
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3446
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3447
	.port_pause_limit = mv88e6390_port_pause_limit,
3448
	.port_set_cmode = mv88e6390x_port_set_cmode,
3449
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3450
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3451
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3452
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3453 3454
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3455
	.stats_get_stats = mv88e6390_stats_get_stats,
3456 3457
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3458
	.watchdog_ops = &mv88e6390_watchdog_ops,
3459
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3460
	.pot_clear = mv88e6xxx_g2_pot_clear,
3461
	.reset = mv88e6352_g1_reset,
3462
	.rmu_disable = mv88e6390_g1_rmu_disable,
3463 3464
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3465
	.serdes_power = mv88e6390_serdes_power,
3466
	.gpio_ops = &mv88e6352_gpio_ops,
3467
	.avb_ops = &mv88e6390_avb_ops,
3468 3469 3470
};

static const struct mv88e6xxx_ops mv88e6390x_ops = {
3471
	/* MV88E6XXX_FAMILY_6390 */
3472
	.irl_init_all = mv88e6390_g2_irl_init_all,
3473 3474
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3475 3476 3477 3478 3479 3480 3481
	.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,
3482
	.port_tag_remap = mv88e6390_port_tag_remap,
3483
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3484
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3485
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3486
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3487
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3488
	.port_pause_limit = mv88e6390_port_pause_limit,
3489
	.port_set_cmode = mv88e6390x_port_set_cmode,
3490
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3491
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3492
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3493
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3494 3495
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3496
	.stats_get_stats = mv88e6390_stats_get_stats,
3497 3498
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3499
	.watchdog_ops = &mv88e6390_watchdog_ops,
3500
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3501
	.pot_clear = mv88e6xxx_g2_pot_clear,
3502
	.reset = mv88e6352_g1_reset,
3503
	.rmu_disable = mv88e6390_g1_rmu_disable,
3504 3505
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3506
	.serdes_power = mv88e6390_serdes_power,
3507
	.gpio_ops = &mv88e6352_gpio_ops,
3508
	.avb_ops = &mv88e6390_avb_ops,
3509 3510
};

3511 3512
static const struct mv88e6xxx_info mv88e6xxx_table[] = {
	[MV88E6085] = {
3513
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
3514 3515 3516 3517
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6085",
		.num_databases = 4096,
		.num_ports = 10,
3518
		.num_internal_phys = 5,
3519
		.max_vid = 4095,
3520
		.port_base_addr = 0x10,
3521
		.phy_base_addr = 0x0,
3522
		.global1_addr = 0x1b,
3523
		.global2_addr = 0x1c,
3524
		.age_time_coeff = 15000,
3525
		.g1_irqs = 8,
3526
		.g2_irqs = 10,
3527
		.atu_move_port_mask = 0xf,
3528
		.pvt = true,
3529
		.multi_chip = true,
3530
		.tag_protocol = DSA_TAG_PROTO_DSA,
3531
		.ops = &mv88e6085_ops,
3532 3533 3534
	},

	[MV88E6095] = {
3535
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
3536 3537 3538 3539
		.family = MV88E6XXX_FAMILY_6095,
		.name = "Marvell 88E6095/88E6095F",
		.num_databases = 256,
		.num_ports = 11,
3540
		.num_internal_phys = 0,
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
		.atu_move_port_mask = 0xf,
3549
		.multi_chip = true,
3550
		.tag_protocol = DSA_TAG_PROTO_DSA,
3551
		.ops = &mv88e6095_ops,
3552 3553
	},

3554
	[MV88E6097] = {
3555
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
3556 3557 3558 3559
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6097/88E6097F",
		.num_databases = 4096,
		.num_ports = 11,
3560
		.num_internal_phys = 8,
3561
		.max_vid = 4095,
3562
		.port_base_addr = 0x10,
3563
		.phy_base_addr = 0x0,
3564
		.global1_addr = 0x1b,
3565
		.global2_addr = 0x1c,
3566
		.age_time_coeff = 15000,
3567
		.g1_irqs = 8,
3568
		.g2_irqs = 10,
3569
		.atu_move_port_mask = 0xf,
3570
		.pvt = true,
3571
		.multi_chip = true,
3572
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3573 3574 3575
		.ops = &mv88e6097_ops,
	},

3576
	[MV88E6123] = {
3577
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
3578 3579 3580 3581
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6123",
		.num_databases = 4096,
		.num_ports = 3,
3582
		.num_internal_phys = 5,
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 = 9,
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
		.ops = &mv88e6123_ops,
3596 3597 3598
	},

	[MV88E6131] = {
3599
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
3600 3601 3602 3603
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6131",
		.num_databases = 256,
		.num_ports = 8,
3604
		.num_internal_phys = 0,
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
		.atu_move_port_mask = 0xf,
3613
		.multi_chip = true,
3614
		.tag_protocol = DSA_TAG_PROTO_DSA,
3615
		.ops = &mv88e6131_ops,
3616 3617
	},

3618
	[MV88E6141] = {
3619
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
3620
		.family = MV88E6XXX_FAMILY_6341,
3621
		.name = "Marvell 88E6141",
3622 3623
		.num_databases = 4096,
		.num_ports = 6,
3624
		.num_internal_phys = 5,
3625
		.num_gpio = 11,
3626
		.max_vid = 4095,
3627
		.port_base_addr = 0x10,
3628
		.phy_base_addr = 0x10,
3629
		.global1_addr = 0x1b,
3630
		.global2_addr = 0x1c,
3631 3632
		.age_time_coeff = 3750,
		.atu_move_port_mask = 0x1f,
3633
		.g1_irqs = 9,
3634
		.g2_irqs = 10,
3635
		.pvt = true,
3636
		.multi_chip = true,
3637 3638 3639 3640
		.tag_protocol = DSA_TAG_PROTO_EDSA,
		.ops = &mv88e6141_ops,
	},

3641
	[MV88E6161] = {
3642
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
3643 3644 3645 3646
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6161",
		.num_databases = 4096,
		.num_ports = 6,
3647
		.num_internal_phys = 5,
3648
		.max_vid = 4095,
3649
		.port_base_addr = 0x10,
3650
		.phy_base_addr = 0x0,
3651
		.global1_addr = 0x1b,
3652
		.global2_addr = 0x1c,
3653
		.age_time_coeff = 15000,
3654
		.g1_irqs = 9,
3655
		.g2_irqs = 10,
3656
		.atu_move_port_mask = 0xf,
3657
		.pvt = true,
3658
		.multi_chip = true,
3659
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3660
		.ops = &mv88e6161_ops,
3661 3662 3663
	},

	[MV88E6165] = {
3664
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
3665 3666 3667 3668
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6165",
		.num_databases = 4096,
		.num_ports = 6,
3669
		.num_internal_phys = 0,
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_DSA,
3682
		.ops = &mv88e6165_ops,
3683 3684 3685
	},

	[MV88E6171] = {
3686
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
3687 3688 3689 3690
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6171",
		.num_databases = 4096,
		.num_ports = 7,
3691
		.num_internal_phys = 5,
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_EDSA,
3704
		.ops = &mv88e6171_ops,
3705 3706 3707
	},

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

	[MV88E6175] = {
3731
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
3732 3733 3734 3735
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6175",
		.num_databases = 4096,
		.num_ports = 7,
3736
		.num_internal_phys = 5,
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 = &mv88e6175_ops,
3750 3751 3752
	},

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

	[MV88E6185] = {
3776
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
3777 3778 3779 3780
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6185",
		.num_databases = 256,
		.num_ports = 10,
3781
		.num_internal_phys = 0,
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 = 8,
3789
		.atu_move_port_mask = 0xf,
3790
		.multi_chip = true,
3791
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3792
		.ops = &mv88e6185_ops,
3793 3794
	},

3795
	[MV88E6190] = {
3796
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
3797 3798 3799 3800
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3801
		.num_internal_phys = 11,
3802
		.num_gpio = 16,
3803
		.max_vid = 8191,
3804
		.port_base_addr = 0x0,
3805
		.phy_base_addr = 0x0,
3806
		.global1_addr = 0x1b,
3807
		.global2_addr = 0x1c,
3808
		.tag_protocol = DSA_TAG_PROTO_DSA,
3809
		.age_time_coeff = 3750,
3810
		.g1_irqs = 9,
3811
		.g2_irqs = 14,
3812
		.pvt = true,
3813
		.multi_chip = true,
3814
		.atu_move_port_mask = 0x1f,
3815 3816 3817 3818
		.ops = &mv88e6190_ops,
	},

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

	[MV88E6191] = {
3842
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
3843 3844 3845 3846
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6191",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3847
		.num_internal_phys = 11,
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
		.ptp_support = true,
3861
		.ops = &mv88e6191_ops,
3862 3863
	},

3864
	[MV88E6240] = {
3865
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
3866 3867 3868 3869
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6240",
		.num_databases = 4096,
		.num_ports = 7,
3870
		.num_internal_phys = 5,
3871
		.num_gpio = 15,
3872
		.max_vid = 4095,
3873
		.port_base_addr = 0x10,
3874
		.phy_base_addr = 0x0,
3875
		.global1_addr = 0x1b,
3876
		.global2_addr = 0x1c,
3877
		.age_time_coeff = 15000,
3878
		.g1_irqs = 9,
3879
		.g2_irqs = 10,
3880
		.atu_move_port_mask = 0xf,
3881
		.pvt = true,
3882
		.multi_chip = true,
3883
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3884
		.ptp_support = true,
3885
		.ops = &mv88e6240_ops,
3886 3887
	},

3888
	[MV88E6290] = {
3889
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
3890 3891 3892 3893
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6290",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3894
		.num_internal_phys = 11,
3895
		.num_gpio = 16,
3896
		.max_vid = 8191,
3897
		.port_base_addr = 0x0,
3898
		.phy_base_addr = 0x0,
3899
		.global1_addr = 0x1b,
3900
		.global2_addr = 0x1c,
3901
		.age_time_coeff = 3750,
3902
		.g1_irqs = 9,
3903
		.g2_irqs = 14,
3904
		.atu_move_port_mask = 0x1f,
3905
		.pvt = true,
3906
		.multi_chip = true,
3907
		.tag_protocol = DSA_TAG_PROTO_DSA,
3908
		.ptp_support = true,
3909 3910 3911
		.ops = &mv88e6290_ops,
	},

3912
	[MV88E6320] = {
3913
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
3914 3915 3916 3917
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6320",
		.num_databases = 4096,
		.num_ports = 7,
3918
		.num_internal_phys = 5,
3919
		.num_gpio = 15,
3920
		.max_vid = 4095,
3921
		.port_base_addr = 0x10,
3922
		.phy_base_addr = 0x0,
3923
		.global1_addr = 0x1b,
3924
		.global2_addr = 0x1c,
3925
		.age_time_coeff = 15000,
3926
		.g1_irqs = 8,
3927
		.g2_irqs = 10,
3928
		.atu_move_port_mask = 0xf,
3929
		.pvt = true,
3930
		.multi_chip = true,
3931
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3932
		.ptp_support = true,
3933
		.ops = &mv88e6320_ops,
3934 3935 3936
	},

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

3959
	[MV88E6341] = {
3960
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
3961 3962 3963
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
3964
		.num_internal_phys = 5,
3965
		.num_ports = 6,
3966
		.num_gpio = 11,
3967
		.max_vid = 4095,
3968
		.port_base_addr = 0x10,
3969
		.phy_base_addr = 0x10,
3970
		.global1_addr = 0x1b,
3971
		.global2_addr = 0x1c,
3972
		.age_time_coeff = 3750,
3973
		.atu_move_port_mask = 0x1f,
3974
		.g1_irqs = 9,
3975
		.g2_irqs = 10,
3976
		.pvt = true,
3977
		.multi_chip = true,
3978
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3979
		.ptp_support = true,
3980 3981 3982
		.ops = &mv88e6341_ops,
	},

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

	[MV88E6351] = {
4006
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
4007 4008 4009 4010
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6351",
		.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 = &mv88e6351_ops,
4025 4026 4027
	},

	[MV88E6352] = {
4028
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
4029 4030 4031 4032
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6352",
		.num_databases = 4096,
		.num_ports = 7,
4033
		.num_internal_phys = 5,
4034
		.num_gpio = 15,
4035
		.max_vid = 4095,
4036
		.port_base_addr = 0x10,
4037
		.phy_base_addr = 0x0,
4038
		.global1_addr = 0x1b,
4039
		.global2_addr = 0x1c,
4040
		.age_time_coeff = 15000,
4041
		.g1_irqs = 9,
4042
		.g2_irqs = 10,
4043
		.atu_move_port_mask = 0xf,
4044
		.pvt = true,
4045
		.multi_chip = true,
4046
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4047
		.ptp_support = true,
4048
		.ops = &mv88e6352_ops,
4049
	},
4050
	[MV88E6390] = {
4051
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
4052 4053 4054 4055
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4056
		.num_internal_phys = 11,
4057
		.num_gpio = 16,
4058
		.max_vid = 8191,
4059
		.port_base_addr = 0x0,
4060
		.phy_base_addr = 0x0,
4061
		.global1_addr = 0x1b,
4062
		.global2_addr = 0x1c,
4063
		.age_time_coeff = 3750,
4064
		.g1_irqs = 9,
4065
		.g2_irqs = 14,
4066
		.atu_move_port_mask = 0x1f,
4067
		.pvt = true,
4068
		.multi_chip = true,
4069
		.tag_protocol = DSA_TAG_PROTO_DSA,
4070
		.ptp_support = true,
4071 4072 4073
		.ops = &mv88e6390_ops,
	},
	[MV88E6390X] = {
4074
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
4075 4076 4077 4078
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4079
		.num_internal_phys = 11,
4080
		.num_gpio = 16,
4081
		.max_vid = 8191,
4082
		.port_base_addr = 0x0,
4083
		.phy_base_addr = 0x0,
4084
		.global1_addr = 0x1b,
4085
		.global2_addr = 0x1c,
4086
		.age_time_coeff = 3750,
4087
		.g1_irqs = 9,
4088
		.g2_irqs = 14,
4089
		.atu_move_port_mask = 0x1f,
4090
		.pvt = true,
4091
		.multi_chip = true,
4092
		.tag_protocol = DSA_TAG_PROTO_DSA,
4093
		.ptp_support = true,
4094 4095
		.ops = &mv88e6390x_ops,
	},
4096 4097
};

4098
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
4099
{
4100
	int i;
4101

4102 4103 4104
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
4105 4106 4107 4108

	return NULL;
}

4109
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
4110 4111
{
	const struct mv88e6xxx_info *info;
4112 4113 4114
	unsigned int prod_num, rev;
	u16 id;
	int err;
4115

4116
	mutex_lock(&chip->reg_lock);
4117
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
4118 4119 4120
	mutex_unlock(&chip->reg_lock);
	if (err)
		return err;
4121

4122 4123
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
4124 4125 4126 4127 4128

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

4129
	/* Update the compatible info with the probed one */
4130
	chip->info = info;
4131

4132 4133 4134 4135
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

4136 4137
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
4138 4139 4140 4141

	return 0;
}

4142
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
4143
{
4144
	struct mv88e6xxx_chip *chip;
4145

4146 4147
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
4148 4149
		return NULL;

4150
	chip->dev = dev;
4151

4152
	mutex_init(&chip->reg_lock);
4153
	INIT_LIST_HEAD(&chip->mdios);
4154

4155
	return chip;
4156 4157
}

4158
static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
4159 4160
			      struct mii_bus *bus, int sw_addr)
{
4161
	if (sw_addr == 0)
4162
		chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
4163
	else if (chip->info->multi_chip)
4164
		chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
4165 4166 4167
	else
		return -EINVAL;

4168 4169
	chip->bus = bus;
	chip->sw_addr = sw_addr;
4170 4171 4172 4173

	return 0;
}

4174 4175
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
							int port)
4176
{
V
Vivien Didelot 已提交
4177
	struct mv88e6xxx_chip *chip = ds->priv;
4178

4179
	return chip->info->tag_protocol;
4180 4181
}

4182
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
4183 4184 4185
static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
				       struct device *host_dev, int sw_addr,
				       void **priv)
4186
{
4187
	struct mv88e6xxx_chip *chip;
4188
	struct mii_bus *bus;
4189
	int err;
4190

4191
	bus = dsa_host_dev_to_mii_bus(host_dev);
4192 4193 4194
	if (!bus)
		return NULL;

4195 4196
	chip = mv88e6xxx_alloc_chip(dsa_dev);
	if (!chip)
4197 4198
		return NULL;

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

4202
	err = mv88e6xxx_smi_init(chip, bus, sw_addr);
4203 4204 4205
	if (err)
		goto free;

4206
	err = mv88e6xxx_detect(chip);
4207
	if (err)
4208
		goto free;
4209

4210 4211 4212 4213 4214 4215
	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_switch_reset(chip);
	mutex_unlock(&chip->reg_lock);
	if (err)
		goto free;

4216 4217
	mv88e6xxx_phy_init(chip);

4218
	err = mv88e6xxx_mdios_register(chip, NULL);
4219
	if (err)
4220
		goto free;
4221

4222
	*priv = chip;
4223

4224
	return chip->info->name;
4225
free:
4226
	devm_kfree(dsa_dev, chip);
4227 4228

	return NULL;
4229
}
4230
#endif
4231

4232
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4233
				      const struct switchdev_obj_port_mdb *mdb)
4234 4235 4236 4237 4238 4239 4240 4241 4242
{
	/* 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,
4243
				   const struct switchdev_obj_port_mdb *mdb)
4244
{
V
Vivien Didelot 已提交
4245
	struct mv88e6xxx_chip *chip = ds->priv;
4246 4247 4248

	mutex_lock(&chip->reg_lock);
	if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4249
					 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
4250 4251
		dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
			port);
4252 4253 4254 4255 4256 4257
	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 已提交
4258
	struct mv88e6xxx_chip *chip = ds->priv;
4259 4260 4261 4262
	int err;

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4263
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
4264 4265 4266 4267 4268
	mutex_unlock(&chip->reg_lock);

	return err;
}

4269
static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
4270
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
4271
	.probe			= mv88e6xxx_drv_probe,
4272
#endif
4273
	.get_tag_protocol	= mv88e6xxx_get_tag_protocol,
4274 4275
	.setup			= mv88e6xxx_setup,
	.adjust_link		= mv88e6xxx_adjust_link,
4276 4277 4278 4279 4280
	.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,
4281 4282 4283
	.get_strings		= mv88e6xxx_get_strings,
	.get_ethtool_stats	= mv88e6xxx_get_ethtool_stats,
	.get_sset_count		= mv88e6xxx_get_sset_count,
4284 4285
	.port_enable		= mv88e6xxx_port_enable,
	.port_disable		= mv88e6xxx_port_disable,
V
Vivien Didelot 已提交
4286 4287
	.get_mac_eee		= mv88e6xxx_get_mac_eee,
	.set_mac_eee		= mv88e6xxx_set_mac_eee,
4288
	.get_eeprom_len		= mv88e6xxx_get_eeprom_len,
4289 4290 4291 4292
	.get_eeprom		= mv88e6xxx_get_eeprom,
	.set_eeprom		= mv88e6xxx_set_eeprom,
	.get_regs_len		= mv88e6xxx_get_regs_len,
	.get_regs		= mv88e6xxx_get_regs,
4293
	.set_ageing_time	= mv88e6xxx_set_ageing_time,
4294 4295 4296
	.port_bridge_join	= mv88e6xxx_port_bridge_join,
	.port_bridge_leave	= mv88e6xxx_port_bridge_leave,
	.port_stp_state_set	= mv88e6xxx_port_stp_state_set,
4297
	.port_fast_age		= mv88e6xxx_port_fast_age,
4298 4299 4300 4301 4302 4303 4304
	.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,
4305 4306 4307
	.port_mdb_prepare       = mv88e6xxx_port_mdb_prepare,
	.port_mdb_add           = mv88e6xxx_port_mdb_add,
	.port_mdb_del           = mv88e6xxx_port_mdb_del,
4308 4309
	.crosschip_bridge_join	= mv88e6xxx_crosschip_bridge_join,
	.crosschip_bridge_leave	= mv88e6xxx_crosschip_bridge_leave,
4310 4311 4312 4313 4314
	.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,
4315 4316
};

4317 4318 4319 4320
static struct dsa_switch_driver mv88e6xxx_switch_drv = {
	.ops			= &mv88e6xxx_switch_ops,
};

4321
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
4322
{
4323
	struct device *dev = chip->dev;
4324 4325
	struct dsa_switch *ds;

4326
	ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
4327 4328 4329
	if (!ds)
		return -ENOMEM;

4330
	ds->priv = chip;
4331
	ds->ops = &mv88e6xxx_switch_ops;
4332 4333
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
4334 4335 4336

	dev_set_drvdata(dev, ds);

4337
	return dsa_register_switch(ds);
4338 4339
}

4340
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
4341
{
4342
	dsa_unregister_switch(chip->ds);
4343 4344
}

4345
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
4346
{
4347
	struct device *dev = &mdiodev->dev;
4348
	struct device_node *np = dev->of_node;
4349
	const struct mv88e6xxx_info *compat_info;
4350
	struct mv88e6xxx_chip *chip;
4351
	u32 eeprom_len;
4352
	int err;
4353

4354 4355 4356 4357
	compat_info = of_device_get_match_data(dev);
	if (!compat_info)
		return -EINVAL;

4358 4359
	chip = mv88e6xxx_alloc_chip(dev);
	if (!chip)
4360 4361
		return -ENOMEM;

4362
	chip->info = compat_info;
4363

4364
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
4365 4366
	if (err)
		return err;
4367

4368 4369 4370 4371
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
	if (IS_ERR(chip->reset))
		return PTR_ERR(chip->reset);

4372
	err = mv88e6xxx_detect(chip);
4373 4374
	if (err)
		return err;
4375

4376 4377
	mv88e6xxx_phy_init(chip);

4378
	if (chip->info->ops->get_eeprom &&
4379
	    !of_property_read_u32(np, "eeprom-length", &eeprom_len))
4380
		chip->eeprom_len = eeprom_len;
4381

4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393
	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;
	}

4394
	/* Has to be performed before the MDIO bus is created, because
4395
	 * the PHYs will link their interrupts to these interrupt
4396 4397 4398 4399
	 * controllers
	 */
	mutex_lock(&chip->reg_lock);
	if (chip->irq > 0)
4400
		err = mv88e6xxx_g1_irq_setup(chip);
4401 4402 4403
	else
		err = mv88e6xxx_irq_poll_setup(chip);
	mutex_unlock(&chip->reg_lock);
4404

4405 4406
	if (err)
		goto out;
4407

4408 4409
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
4410
		if (err)
4411
			goto out_g1_irq;
4412 4413
	}

4414 4415 4416 4417 4418 4419 4420 4421
	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;

4422
	err = mv88e6xxx_mdios_register(chip, np);
4423
	if (err)
4424
		goto out_g1_vtu_prob_irq;
4425

4426
	err = mv88e6xxx_register_switch(chip);
4427 4428
	if (err)
		goto out_mdio;
4429

4430
	return 0;
4431 4432

out_mdio:
4433
	mv88e6xxx_mdios_unregister(chip);
4434
out_g1_vtu_prob_irq:
4435
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
4436
out_g1_atu_prob_irq:
4437
	mv88e6xxx_g1_atu_prob_irq_free(chip);
4438
out_g2_irq:
4439
	if (chip->info->g2_irqs > 0)
4440 4441
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
4442 4443
	mutex_lock(&chip->reg_lock);
	if (chip->irq > 0)
4444
		mv88e6xxx_g1_irq_free(chip);
4445 4446 4447
	else
		mv88e6xxx_irq_poll_free(chip);
	mutex_unlock(&chip->reg_lock);
4448 4449
out:
	return err;
4450
}
4451 4452 4453 4454

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

4457 4458
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
4459
		mv88e6xxx_ptp_free(chip);
4460
	}
4461

4462
	mv88e6xxx_phy_destroy(chip);
4463
	mv88e6xxx_unregister_switch(chip);
4464
	mv88e6xxx_mdios_unregister(chip);
4465

4466 4467 4468 4469 4470 4471 4472 4473
	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)
4474
		mv88e6xxx_g1_irq_free(chip);
4475 4476 4477
	else
		mv88e6xxx_irq_poll_free(chip);
	mutex_unlock(&chip->reg_lock);
4478 4479 4480
}

static const struct of_device_id mv88e6xxx_of_match[] = {
4481 4482 4483 4484
	{
		.compatible = "marvell,mv88e6085",
		.data = &mv88e6xxx_table[MV88E6085],
	},
4485 4486 4487 4488
	{
		.compatible = "marvell,mv88e6190",
		.data = &mv88e6xxx_table[MV88E6190],
	},
4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504
	{ /* 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)
{
4505
	register_switch_driver(&mv88e6xxx_switch_drv);
4506 4507
	return mdio_driver_register(&mv88e6xxx_driver);
}
4508 4509 4510 4511
module_init(mv88e6xxx_init);

static void __exit mv88e6xxx_cleanup(void)
{
4512
	mdio_driver_unregister(&mv88e6xxx_driver);
4513
	unregister_switch_driver(&mv88e6xxx_switch_drv);
4514 4515
}
module_exit(mv88e6xxx_cleanup);
4516 4517 4518 4519

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