chip.c 120.8 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 <net/dsa.h>
35

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

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

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

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

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

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

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

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

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

	*val = ret & 0xffff;

	return 0;
}

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

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

	return 0;
}

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

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

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

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

	return -ETIMEDOUT;
}

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

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

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

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

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

157
	*val = ret & 0xffff;
158

159
	return 0;
160 161
}

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

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

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

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

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

	return 0;
}

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

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

200
	assert_reg_lock(chip);
201

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

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

	return 0;
}

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

216
	assert_reg_lock(chip);
217

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

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

225 226 227
	return 0;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	free_irq(chip->irq, chip);
}

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

	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;

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

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

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

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

	return 0;

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

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

	return err;
}

418 419 420 421 422 423 424 425 426 427
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,
428
				   IRQF_ONESHOT,
429 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
				   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)
{
470 471
	mv88e6xxx_g1_irq_free_common(chip);

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

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

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

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

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

		usleep_range(1000, 2000);
	}

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

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

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

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

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

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

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

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

	return err;
}

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

	if (!phy_is_pseudo_fixed_link(phydev))
		return;

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

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

583
static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
584
{
585 586
	if (!chip->info->ops->stats_snapshot)
		return -EOPNOTSUPP;
587

588
	return chip->info->ops->stats_snapshot(chip, port);
589 590
}

591
static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
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
	{ "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, },
651 652
};

653
static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
654
					    struct mv88e6xxx_hw_stat *s,
655 656
					    int port, u16 bank1_select,
					    u16 histogram)
657 658 659
{
	u32 low;
	u32 high = 0;
660
	u16 reg = 0;
661
	int err;
662 663
	u64 value;

664
	switch (s->type) {
665
	case STATS_TYPE_PORT:
666 667
		err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
		if (err)
668 669
			return UINT64_MAX;

670
		low = reg;
671
		if (s->size == 4) {
672 673
			err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
			if (err)
674
				return UINT64_MAX;
675
			high = reg;
676
		}
677
		break;
678
	case STATS_TYPE_BANK1:
679
		reg = bank1_select;
680 681
		/* fall through */
	case STATS_TYPE_BANK0:
682
		reg |= s->reg | histogram;
683
		mv88e6xxx_g1_stats_read(chip, reg, &low);
684
		if (s->size == 8)
685
			mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
686 687 688
		break;
	default:
		return UINT64_MAX;
689 690 691 692 693
	}
	value = (((u64)high) << 16) | low;
	return value;
}

694 695
static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data, int types)
696
{
697 698
	struct mv88e6xxx_hw_stat *stat;
	int i, j;
699

700 701
	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
		stat = &mv88e6xxx_hw_stats[i];
702
		if (stat->type & types) {
703 704 705 706
			memcpy(data + j * ETH_GSTRING_LEN, stat->string,
			       ETH_GSTRING_LEN);
			j++;
		}
707
	}
708 709

	return j;
710 711
}

712 713
static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
714
{
715 716
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_PORT);
717 718
}

719 720
static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
721
{
722 723
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
724 725
}

726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743
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);
}

744 745
static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
				  uint8_t *data)
746
{
V
Vivien Didelot 已提交
747
	struct mv88e6xxx_chip *chip = ds->priv;
748
	int count = 0;
749

750 751
	mutex_lock(&chip->reg_lock);

752
	if (chip->info->ops->stats_get_strings)
753 754 755 756
		count = chip->info->ops->stats_get_strings(chip, data);

	if (chip->info->ops->serdes_get_strings) {
		data += count * ETH_GSTRING_LEN;
757
		count = chip->info->ops->serdes_get_strings(chip, port, data);
758
	}
759

760 761 762
	data += count * ETH_GSTRING_LEN;
	mv88e6xxx_atu_vtu_get_strings(data);

763
	mutex_unlock(&chip->reg_lock);
764 765 766 767 768
}

static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
					  int types)
{
769 770 771 772 773
	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];
774
		if (stat->type & types)
775 776 777
			j++;
	}
	return j;
778 779
}

780 781 782 783 784 785 786 787 788 789 790 791
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);
}

792
static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port)
793 794
{
	struct mv88e6xxx_chip *chip = ds->priv;
795 796
	int serdes_count = 0;
	int count = 0;
797

798
	mutex_lock(&chip->reg_lock);
799
	if (chip->info->ops->stats_get_sset_count)
800 801 802 803 804 805 806
		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);
807
	if (serdes_count < 0) {
808
		count = serdes_count;
809 810 811 812 813
		goto out;
	}
	count += serdes_count;
	count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);

814
out:
815
	mutex_unlock(&chip->reg_lock);
816

817
	return count;
818 819
}

820 821 822
static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data, int types,
				     u16 bank1_select, u16 histogram)
823 824 825 826 827 828 829
{
	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) {
830
			mutex_lock(&chip->reg_lock);
831 832 833
			data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
							      bank1_select,
							      histogram);
834 835
			mutex_unlock(&chip->reg_lock);

836 837 838
			j++;
		}
	}
839
	return j;
840 841
}

842 843
static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
844 845
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
846
					 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
847
					 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
848 849
}

850 851
static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
852 853
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
854
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
855 856
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
					 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
857 858
}

859 860
static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
861 862 863
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
864 865
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
					 0);
866 867
}

868 869 870 871 872 873 874 875 876 877
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;
}

878 879 880
static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
				uint64_t *data)
{
881 882
	int count = 0;

883
	if (chip->info->ops->stats_get_stats)
884 885
		count = chip->info->ops->stats_get_stats(chip, port, data);

886
	mutex_lock(&chip->reg_lock);
887 888
	if (chip->info->ops->serdes_get_stats) {
		data += count;
889
		count = chip->info->ops->serdes_get_stats(chip, port, data);
890
	}
891 892 893
	data += count;
	mv88e6xxx_atu_vtu_get_stats(chip, port, data);
	mutex_unlock(&chip->reg_lock);
894 895
}

896 897
static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
					uint64_t *data)
898
{
V
Vivien Didelot 已提交
899
	struct mv88e6xxx_chip *chip = ds->priv;
900 901
	int ret;

902
	mutex_lock(&chip->reg_lock);
903

904
	ret = mv88e6xxx_stats_snapshot(chip, port);
905 906 907
	mutex_unlock(&chip->reg_lock);

	if (ret < 0)
908
		return;
909 910

	mv88e6xxx_get_stats(chip, port, data);
911

912 913
}

914 915 916 917 918 919 920 921
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;
}

922
static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
923 924 925 926
{
	return 32 * sizeof(u16);
}

927 928
static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
			       struct ethtool_regs *regs, void *_p)
929
{
V
Vivien Didelot 已提交
930
	struct mv88e6xxx_chip *chip = ds->priv;
931 932
	int err;
	u16 reg;
933 934 935 936 937 938 939
	u16 *p = _p;
	int i;

	regs->version = 0;

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

940
	mutex_lock(&chip->reg_lock);
941

942 943
	for (i = 0; i < 32; i++) {

944 945 946
		err = mv88e6xxx_port_read(chip, port, i, &reg);
		if (!err)
			p[i] = reg;
947
	}
948

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

V
Vivien Didelot 已提交
952 953
static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
954
{
955 956
	/* Nothing to do on the port's MAC */
	return 0;
957 958
}

V
Vivien Didelot 已提交
959 960
static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
961
{
962 963
	/* Nothing to do on the port's MAC */
	return 0;
964 965
}

966
static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
967
{
968 969 970
	struct dsa_switch *ds = NULL;
	struct net_device *br;
	u16 pvlan;
971 972
	int i;

973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992
	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 已提交
993
		    (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
994 995 996 997 998
			pvlan |= BIT(i);

	return pvlan;
}

999
static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
1000 1001
{
	u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
1002 1003 1004

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

1006
	return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
1007 1008
}

1009 1010
static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
					 u8 state)
1011
{
V
Vivien Didelot 已提交
1012
	struct mv88e6xxx_chip *chip = ds->priv;
1013
	int err;
1014

1015
	mutex_lock(&chip->reg_lock);
1016
	err = mv88e6xxx_port_set_state(chip, port, state);
1017
	mutex_unlock(&chip->reg_lock);
1018 1019

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

1023 1024 1025 1026 1027 1028 1029 1030
static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->pot_clear)
		return chip->info->ops->pot_clear(chip);

	return 0;
}

1031 1032 1033 1034 1035 1036 1037 1038
static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->mgmt_rsvd2cpu)
		return chip->info->ops->mgmt_rsvd2cpu(chip);

	return 0;
}

1039 1040
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
1041 1042
	int err;

1043 1044 1045 1046
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

1047 1048 1049 1050
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

1051 1052 1053
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
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;
}

1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086
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;
}

1087 1088 1089 1090 1091 1092 1093 1094 1095
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)
1096
		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1097 1098 1099 1100

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

1101 1102
static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
{
1103 1104 1105
	int dev, port;
	int err;

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

1127 1128 1129 1130 1131 1132
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);
1133
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1134 1135 1136
	mutex_unlock(&chip->reg_lock);

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

1140 1141 1142 1143 1144 1145 1146 1147
static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
{
	if (!chip->info->max_vid)
		return 0;

	return mv88e6xxx_g1_vtu_flush(chip);
}

1148 1149 1150 1151 1152 1153 1154 1155 1156
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);
}

1157 1158 1159 1160 1161 1162 1163 1164 1165
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);
}

1166
static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1167 1168
{
	DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1169 1170 1171
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = chip->info->max_vid,
	};
1172
	int i, err;
1173 1174 1175

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

1176
	/* Set every FID bit used by the (un)bridged ports */
1177
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1178
		err = mv88e6xxx_port_get_fid(chip, i, fid);
1179 1180 1181 1182 1183 1184
		if (err)
			return err;

		set_bit(*fid, fid_bitmap);
	}

1185 1186
	/* Set every FID bit used by the VLAN entries */
	do {
1187
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1188 1189 1190 1191 1192 1193 1194
		if (err)
			return err;

		if (!vlan.valid)
			break;

		set_bit(vlan.fid, fid_bitmap);
1195
	} while (vlan.vid < chip->info->max_vid);
1196 1197 1198 1199 1200

	/* 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);
1201
	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1202 1203 1204
		return -ENOSPC;

	/* Clear the database */
1205
	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1206 1207
}

1208 1209
static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
			     struct mv88e6xxx_vtu_entry *entry, bool new)
1210 1211 1212 1213 1214 1215
{
	int err;

	if (!vid)
		return -EINVAL;

1216 1217
	entry->vid = vid - 1;
	entry->valid = false;
1218

1219
	err = mv88e6xxx_vtu_getnext(chip, entry);
1220 1221 1222
	if (err)
		return err;

1223 1224
	if (entry->vid == vid && entry->valid)
		return 0;
1225

1226 1227 1228 1229 1230 1231 1232 1233
	if (new) {
		int i;

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

1234
		/* Exclude all ports */
1235
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1236
			entry->member[i] =
1237
				MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1238 1239

		return mv88e6xxx_atu_new(chip, &entry->fid);
1240 1241
	}

1242 1243
	/* switchdev expects -EOPNOTSUPP to honor software VLANs */
	return -EOPNOTSUPP;
1244 1245
}

1246 1247 1248
static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
					u16 vid_begin, u16 vid_end)
{
V
Vivien Didelot 已提交
1249
	struct mv88e6xxx_chip *chip = ds->priv;
1250 1251 1252
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = vid_begin - 1,
	};
1253 1254
	int i, err;

1255 1256 1257 1258
	/* 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;

1259 1260 1261
	if (!vid_begin)
		return -EOPNOTSUPP;

1262
	mutex_lock(&chip->reg_lock);
1263 1264

	do {
1265
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1266 1267 1268 1269 1270 1271 1272 1273 1274
		if (err)
			goto unlock;

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

1275
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1276 1277 1278
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

1279
			if (!ds->ports[i].slave)
1280 1281
				continue;

1282
			if (vlan.member[i] ==
1283
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1284 1285
				continue;

V
Vivien Didelot 已提交
1286
			if (dsa_to_port(ds, i)->bridge_dev ==
1287
			    ds->ports[port].bridge_dev)
1288 1289
				break; /* same bridge, check next VLAN */

V
Vivien Didelot 已提交
1290
			if (!dsa_to_port(ds, i)->bridge_dev)
1291 1292
				continue;

1293 1294
			dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
				port, vlan.vid, i,
V
Vivien Didelot 已提交
1295
				netdev_name(dsa_to_port(ds, i)->bridge_dev));
1296 1297 1298 1299 1300 1301
			err = -EOPNOTSUPP;
			goto unlock;
		}
	} while (vlan.vid < vid_end);

unlock:
1302
	mutex_unlock(&chip->reg_lock);
1303 1304 1305 1306

	return err;
}

1307 1308
static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
					 bool vlan_filtering)
1309
{
V
Vivien Didelot 已提交
1310
	struct mv88e6xxx_chip *chip = ds->priv;
1311 1312
	u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
		MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
1313
	int err;
1314

1315
	if (!chip->info->max_vid)
1316 1317
		return -EOPNOTSUPP;

1318
	mutex_lock(&chip->reg_lock);
1319
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1320
	mutex_unlock(&chip->reg_lock);
1321

1322
	return err;
1323 1324
}

1325 1326
static int
mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1327
			    const struct switchdev_obj_port_vlan *vlan)
1328
{
V
Vivien Didelot 已提交
1329
	struct mv88e6xxx_chip *chip = ds->priv;
1330 1331
	int err;

1332
	if (!chip->info->max_vid)
1333 1334
		return -EOPNOTSUPP;

1335 1336 1337 1338 1339 1340 1341 1342
	/* 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;

1343 1344 1345 1346 1347 1348
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */
	return 0;
}

1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392
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);
}

1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415
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;
}

1416
static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
1417
				    u16 vid, u8 member)
1418
{
1419
	struct mv88e6xxx_vtu_entry vlan;
1420 1421
	int err;

1422
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
1423
	if (err)
1424
		return err;
1425

1426
	vlan.member[port] = member;
1427

1428 1429 1430 1431 1432
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
	if (err)
		return err;

	return mv88e6xxx_broadcast_setup(chip, vid);
1433 1434
}

1435
static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1436
				    const struct switchdev_obj_port_vlan *vlan)
1437
{
V
Vivien Didelot 已提交
1438
	struct mv88e6xxx_chip *chip = ds->priv;
1439 1440
	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1441
	u8 member;
1442 1443
	u16 vid;

1444
	if (!chip->info->max_vid)
1445 1446
		return;

1447
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1448
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1449
	else if (untagged)
1450
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
1451
	else
1452
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
1453

1454
	mutex_lock(&chip->reg_lock);
1455

1456
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
1457
		if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
1458 1459
			dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
				vid, untagged ? 'u' : 't');
1460

1461
	if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1462 1463
		dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
			vlan->vid_end);
1464

1465
	mutex_unlock(&chip->reg_lock);
1466 1467
}

1468
static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
1469
				    int port, u16 vid)
1470
{
1471
	struct mv88e6xxx_vtu_entry vlan;
1472 1473
	int i, err;

1474
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1475
	if (err)
1476
		return err;
1477

1478
	/* Tell switchdev if this VLAN is handled in software */
1479
	if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1480
		return -EOPNOTSUPP;
1481

1482
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1483 1484

	/* keep the VLAN unless all ports are excluded */
1485
	vlan.valid = false;
1486
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1487 1488
		if (vlan.member[i] !=
		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
1489
			vlan.valid = true;
1490 1491 1492 1493
			break;
		}
	}

1494
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1495 1496 1497
	if (err)
		return err;

1498
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
1499 1500
}

1501 1502
static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
				   const struct switchdev_obj_port_vlan *vlan)
1503
{
V
Vivien Didelot 已提交
1504
	struct mv88e6xxx_chip *chip = ds->priv;
1505 1506 1507
	u16 pvid, vid;
	int err = 0;

1508
	if (!chip->info->max_vid)
1509 1510
		return -EOPNOTSUPP;

1511
	mutex_lock(&chip->reg_lock);
1512

1513
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
1514 1515 1516
	if (err)
		goto unlock;

1517
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1518
		err = _mv88e6xxx_port_vlan_del(chip, port, vid);
1519 1520 1521 1522
		if (err)
			goto unlock;

		if (vid == pvid) {
1523
			err = mv88e6xxx_port_set_pvid(chip, port, 0);
1524 1525 1526 1527 1528
			if (err)
				goto unlock;
		}
	}

1529
unlock:
1530
	mutex_unlock(&chip->reg_lock);
1531 1532 1533 1534

	return err;
}

1535 1536
static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
				  const unsigned char *addr, u16 vid)
1537
{
V
Vivien Didelot 已提交
1538
	struct mv88e6xxx_chip *chip = ds->priv;
1539
	int err;
1540

1541
	mutex_lock(&chip->reg_lock);
1542 1543
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1544
	mutex_unlock(&chip->reg_lock);
1545 1546

	return err;
1547 1548
}

1549
static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1550
				  const unsigned char *addr, u16 vid)
1551
{
V
Vivien Didelot 已提交
1552
	struct mv88e6xxx_chip *chip = ds->priv;
1553
	int err;
1554

1555
	mutex_lock(&chip->reg_lock);
1556
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1557
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
1558
	mutex_unlock(&chip->reg_lock);
1559

1560
	return err;
1561 1562
}

1563 1564
static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
				      u16 fid, u16 vid, int port,
1565
				      dsa_fdb_dump_cb_t *cb, void *data)
1566
{
1567
	struct mv88e6xxx_atu_entry addr;
1568
	bool is_static;
1569 1570
	int err;

1571
	addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1572
	eth_broadcast_addr(addr.mac);
1573 1574

	do {
1575
		mutex_lock(&chip->reg_lock);
1576
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
1577
		mutex_unlock(&chip->reg_lock);
1578
		if (err)
1579
			return err;
1580

1581
		if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
1582 1583
			break;

1584
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
1585 1586
			continue;

1587 1588
		if (!is_unicast_ether_addr(addr.mac))
			continue;
1589

1590 1591 1592
		is_static = (addr.state ==
			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
		err = cb(addr.mac, vid, is_static, data);
1593 1594
		if (err)
			return err;
1595 1596 1597 1598 1599
	} while (!is_broadcast_ether_addr(addr.mac));

	return err;
}

1600
static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1601
				  dsa_fdb_dump_cb_t *cb, void *data)
1602
{
1603
	struct mv88e6xxx_vtu_entry vlan = {
1604
		.vid = chip->info->max_vid,
1605
	};
1606
	u16 fid;
1607 1608
	int err;

1609
	/* Dump port's default Filtering Information Database (VLAN ID 0) */
1610
	mutex_lock(&chip->reg_lock);
1611
	err = mv88e6xxx_port_get_fid(chip, port, &fid);
1612 1613
	mutex_unlock(&chip->reg_lock);

1614
	if (err)
1615
		return err;
1616

1617
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
1618
	if (err)
1619
		return err;
1620

1621
	/* Dump VLANs' Filtering Information Databases */
1622
	do {
1623
		mutex_lock(&chip->reg_lock);
1624
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1625
		mutex_unlock(&chip->reg_lock);
1626
		if (err)
1627
			return err;
1628 1629 1630 1631

		if (!vlan.valid)
			break;

1632
		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1633
						 cb, data);
1634
		if (err)
1635
			return err;
1636
	} while (vlan.vid < chip->info->max_vid);
1637

1638 1639 1640 1641
	return err;
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1642
				   dsa_fdb_dump_cb_t *cb, void *data)
1643
{
V
Vivien Didelot 已提交
1644
	struct mv88e6xxx_chip *chip = ds->priv;
1645

1646
	return mv88e6xxx_port_db_dump(chip, port, cb, data);
1647 1648
}

1649 1650
static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
				struct net_device *br)
1651
{
1652
	struct dsa_switch *ds;
1653
	int port;
1654
	int dev;
1655
	int err;
1656

1657 1658 1659 1660
	/* 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);
1661
			if (err)
1662
				return err;
1663 1664 1665
		}
	}

1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683
	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;
			}
		}
	}

1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694
	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);
1695
	mutex_unlock(&chip->reg_lock);
1696

1697
	return err;
1698 1699
}

1700 1701
static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
					struct net_device *br)
1702
{
V
Vivien Didelot 已提交
1703
	struct mv88e6xxx_chip *chip = ds->priv;
1704

1705
	mutex_lock(&chip->reg_lock);
1706 1707 1708
	if (mv88e6xxx_bridge_map(chip, br) ||
	    mv88e6xxx_port_vlan_map(chip, port))
		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
1709
	mutex_unlock(&chip->reg_lock);
1710 1711
}

1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741
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);
}

1742 1743 1744 1745 1746 1747 1748 1749
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->reset)
		return chip->info->ops->reset(chip);

	return 0;
}

1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762
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);
	}
}

1763
static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1764
{
1765
	int i, err;
1766

1767
	/* Set all ports to the Disabled state */
1768
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
1769
		err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
1770 1771
		if (err)
			return err;
1772 1773
	}

1774 1775 1776
	/* Wait for transmit queues to drain,
	 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
	 */
1777 1778
	usleep_range(2000, 4000);

1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789
	return 0;
}

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

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

1790
	mv88e6xxx_hardware_reset(chip);
1791

1792
	return mv88e6xxx_software_reset(chip);
1793 1794
}

1795
static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
1796 1797
				   enum mv88e6xxx_frame_mode frame,
				   enum mv88e6xxx_egress_mode egress, u16 etype)
1798 1799 1800
{
	int err;

1801 1802 1803 1804
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
1805 1806 1807
	if (err)
		return err;

1808 1809 1810 1811 1812 1813 1814 1815
	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;
1816 1817
}

1818
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1819
{
1820
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
1821
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
1822
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
1823
}
1824

1825 1826 1827
static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
1828
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
1829
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
1830
}
1831

1832 1833 1834 1835
static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port,
				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
1836 1837
				       MV88E6XXX_EGRESS_MODE_ETHERTYPE,
				       ETH_P_EDSA);
1838
}
1839

1840 1841 1842 1843
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);
1844

1845
	if (dsa_is_user_port(chip->ds, port))
1846
		return mv88e6xxx_set_port_mode_normal(chip, port);
1847

1848 1849 1850
	/* 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);
1851

1852 1853
	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
		return mv88e6xxx_set_port_mode_edsa(chip, port);
1854

1855
	return -EINVAL;
1856 1857
}

1858
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
1859
{
1860
	bool message = dsa_is_dsa_port(chip->ds, port);
1861

1862
	return mv88e6xxx_port_set_message_port(chip, port, message);
1863
}
1864

1865
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
1866
{
1867 1868
	struct dsa_switch *ds = chip->ds;
	bool flood;
1869

1870
	/* Upstream ports flood frames with unknown unicast or multicast DA */
1871
	flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
1872 1873 1874
	if (chip->info->ops->port_set_egress_floods)
		return chip->info->ops->port_set_egress_floods(chip, port,
							       flood, flood);
1875

1876
	return 0;
1877 1878
}

1879 1880 1881
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
1882 1883
	if (chip->info->ops->serdes_power)
		return chip->info->ops->serdes_power(chip, port, on);
1884

1885
	return 0;
1886 1887
}

1888 1889 1890 1891 1892 1893
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

1894
	upstream_port = dsa_upstream_port(ds, port);
1895 1896 1897 1898 1899 1900 1901
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917
	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;
		}
	}

1918 1919 1920
	return 0;
}

1921
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
1922
{
1923
	struct dsa_switch *ds = chip->ds;
1924
	int err;
1925
	u16 reg;
1926

1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940
	/* 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;
1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955

	/* 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.
	 */
1956 1957 1958 1959
	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);
1960 1961
	if (err)
		return err;
1962

1963
	err = mv88e6xxx_setup_port_mode(chip, port);
1964 1965
	if (err)
		return err;
1966

1967
	err = mv88e6xxx_setup_egress_floods(chip, port);
1968 1969 1970
	if (err)
		return err;

1971 1972 1973
	/* 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.
1974
	 */
1975 1976 1977 1978 1979
	if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
		err = mv88e6xxx_serdes_power(chip, port, true);
		if (err)
			return err;
	}
1980

1981
	/* Port Control 2: don't force a good FCS, set the maximum frame size to
1982
	 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
1983 1984 1985
	 * 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.
1986
	 */
1987 1988 1989
	err = mv88e6xxx_port_set_map_da(chip, port);
	if (err)
		return err;
1990

1991 1992 1993
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
1994

1995
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
1996
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
1997 1998 1999
	if (err)
		return err;

2000 2001
	if (chip->info->ops->port_set_jumbo_size) {
		err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
2002 2003 2004 2005
		if (err)
			return err;
	}

2006 2007 2008 2009 2010
	/* 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.
	 */
2011
	reg = 1 << port;
2012 2013
	/* Disable learning for CPU port */
	if (dsa_is_cpu_port(ds, port))
2014
		reg = 0;
2015

2016 2017
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
2018 2019
	if (err)
		return err;
2020 2021

	/* Egress rate control 2: disable egress rate control. */
2022 2023
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
				   0x0000);
2024 2025
	if (err)
		return err;
2026

2027 2028
	if (chip->info->ops->port_pause_limit) {
		err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
2029 2030
		if (err)
			return err;
2031
	}
2032

2033 2034 2035 2036 2037 2038
	if (chip->info->ops->port_disable_learn_limit) {
		err = chip->info->ops->port_disable_learn_limit(chip, port);
		if (err)
			return err;
	}

2039 2040
	if (chip->info->ops->port_disable_pri_override) {
		err = chip->info->ops->port_disable_pri_override(chip, port);
2041 2042
		if (err)
			return err;
2043
	}
2044

2045 2046
	if (chip->info->ops->port_tag_remap) {
		err = chip->info->ops->port_tag_remap(chip, port);
2047 2048
		if (err)
			return err;
2049 2050
	}

2051 2052
	if (chip->info->ops->port_egress_rate_limiting) {
		err = chip->info->ops->port_egress_rate_limiting(chip, port);
2053 2054
		if (err)
			return err;
2055 2056
	}

2057
	err = mv88e6xxx_setup_message_port(chip, port);
2058 2059
	if (err)
		return err;
2060

2061
	/* Port based VLAN map: give each port the same default address
2062 2063
	 * database, and allow bidirectional communication between the
	 * CPU and DSA port(s), and the other ports.
2064
	 */
2065
	err = mv88e6xxx_port_set_fid(chip, port, 0);
2066 2067
	if (err)
		return err;
2068

2069
	err = mv88e6xxx_port_vlan_map(chip, port);
2070 2071
	if (err)
		return err;
2072 2073 2074 2075

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

2079 2080 2081 2082
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
2083
	int err;
2084 2085

	mutex_lock(&chip->reg_lock);
2086
	err = mv88e6xxx_serdes_power(chip, port, true);
2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097
	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);
2098 2099
	if (mv88e6xxx_serdes_power(chip, port, false))
		dev_err(chip->dev, "failed to power off SERDES\n");
2100 2101 2102
	mutex_unlock(&chip->reg_lock);
}

2103 2104 2105
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
2106
	struct mv88e6xxx_chip *chip = ds->priv;
2107 2108 2109
	int err;

	mutex_lock(&chip->reg_lock);
2110
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2111 2112 2113 2114 2115
	mutex_unlock(&chip->reg_lock);

	return err;
}

2116
static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
2117
{
2118
	struct dsa_switch *ds = chip->ds;
2119
	int err;
2120

2121
	/* Disable remote management, and set the switch's DSA device number. */
2122 2123
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL2,
				 MV88E6XXX_G1_CTL2_MULTIPLE_CASCADE |
2124
				 (ds->index & 0x1f));
2125 2126 2127
	if (err)
		return err;

2128
	/* Configure the IP ToS mapping registers. */
2129
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_0, 0x0000);
2130
	if (err)
2131
		return err;
2132
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_1, 0x0000);
2133
	if (err)
2134
		return err;
2135
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_2, 0x5555);
2136
	if (err)
2137
		return err;
2138
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_3, 0x5555);
2139
	if (err)
2140
		return err;
2141
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_4, 0xaaaa);
2142
	if (err)
2143
		return err;
2144
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_5, 0xaaaa);
2145
	if (err)
2146
		return err;
2147
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_6, 0xffff);
2148
	if (err)
2149
		return err;
2150
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_7, 0xffff);
2151
	if (err)
2152
		return err;
2153 2154

	/* Configure the IEEE 802.1p priority mapping register. */
2155
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IEEE_PRI, 0xfa41);
2156
	if (err)
2157
		return err;
2158

2159 2160 2161 2162 2163
	/* Initialize the statistics unit */
	err = mv88e6xxx_stats_set_histogram(chip);
	if (err)
		return err;

2164
	return mv88e6xxx_g1_stats_clear(chip);
2165 2166
}

2167
static int mv88e6xxx_setup(struct dsa_switch *ds)
2168
{
V
Vivien Didelot 已提交
2169
	struct mv88e6xxx_chip *chip = ds->priv;
2170
	int err;
2171 2172
	int i;

2173
	chip->ds = ds;
2174
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
2175

2176
	mutex_lock(&chip->reg_lock);
2177

2178
	/* Setup Switch Port Registers */
2179
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2180 2181 2182
		if (dsa_is_unused_port(ds, i))
			continue;

2183 2184 2185 2186 2187 2188 2189
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

	/* Setup Switch Global 1 Registers */
	err = mv88e6xxx_g1_setup(chip);
2190 2191 2192
	if (err)
		goto unlock;

2193
	/* Setup Switch Global 2 Registers */
2194
	if (chip->info->global2_addr) {
2195
		err = mv88e6xxx_g2_setup(chip);
2196 2197 2198
		if (err)
			goto unlock;
	}
2199

2200 2201 2202 2203
	err = mv88e6xxx_irl_setup(chip);
	if (err)
		goto unlock;

2204 2205 2206 2207
	err = mv88e6xxx_mac_setup(chip);
	if (err)
		goto unlock;

2208 2209 2210 2211
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

2212 2213 2214 2215
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

2216 2217 2218 2219
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

2220 2221 2222 2223
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

2224 2225 2226 2227
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

2228 2229 2230 2231
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

2232 2233 2234
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
2235

2236
	/* Setup PTP Hardware Clock and timestamping */
2237 2238 2239 2240
	if (chip->info->ptp_support) {
		err = mv88e6xxx_ptp_setup(chip);
		if (err)
			goto unlock;
2241 2242 2243 2244

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
2245 2246
	}

2247
unlock:
2248
	mutex_unlock(&chip->reg_lock);
2249

2250
	return err;
2251 2252
}

2253
static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
2254
{
2255 2256
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2257 2258
	u16 val;
	int err;
2259

2260 2261 2262
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

2263
	mutex_lock(&chip->reg_lock);
2264
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
2265
	mutex_unlock(&chip->reg_lock);
2266

2267 2268 2269 2270 2271
	if (reg == MII_PHYSID2) {
		/* Some internal PHYS don't have a model number.  Use
		 * the mv88e6390 family model number instead.
		 */
		if (!(val & 0x3f0))
2272
			val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
2273 2274
	}

2275
	return err ? err : val;
2276 2277
}

2278
static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
2279
{
2280 2281
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2282
	int err;
2283

2284 2285 2286
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

2287
	mutex_lock(&chip->reg_lock);
2288
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
2289
	mutex_unlock(&chip->reg_lock);
2290 2291

	return err;
2292 2293
}

2294
static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
2295 2296
				   struct device_node *np,
				   bool external)
2297 2298
{
	static int index;
2299
	struct mv88e6xxx_mdio_bus *mdio_bus;
2300 2301 2302
	struct mii_bus *bus;
	int err;

2303 2304 2305 2306 2307 2308 2309 2310 2311
	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;
	}

2312
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
2313 2314 2315
	if (!bus)
		return -ENOMEM;

2316
	mdio_bus = bus->priv;
2317
	mdio_bus->bus = bus;
2318
	mdio_bus->chip = chip;
2319 2320
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
2321

2322 2323
	if (np) {
		bus->name = np->full_name;
2324
		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
2325 2326 2327 2328 2329 2330 2331
	} 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;
2332
	bus->parent = chip->dev;
2333

2334 2335 2336 2337 2338 2339
	if (!external) {
		err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
		if (err)
			return err;
	}

2340 2341
	if (np)
		err = of_mdiobus_register(bus, np);
2342 2343 2344
	else
		err = mdiobus_register(bus);
	if (err) {
2345
		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
2346
		mv88e6xxx_g2_irq_mdio_free(chip, bus);
2347
		return err;
2348
	}
2349 2350 2351 2352 2353

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

	return 0;
2356
}
2357

2358 2359 2360 2361 2362
static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
	{ .compatible = "marvell,mv88e6xxx-mdio-external",
	  .data = (void *)true },
	{ },
};
2363

2364 2365 2366 2367 2368 2369 2370 2371 2372
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;

2373 2374 2375
		if (!mdio_bus->external)
			mv88e6xxx_g2_irq_mdio_free(chip, bus);

2376 2377 2378 2379
		mdiobus_unregister(bus);
	}
}

2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403
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);
2404 2405
			if (err) {
				mv88e6xxx_mdios_unregister(chip);
2406
				return err;
2407
			}
2408 2409 2410 2411
		}
	}

	return 0;
2412 2413
}

2414 2415
static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
2416
	struct mv88e6xxx_chip *chip = ds->priv;
2417 2418 2419 2420 2421 2422 2423

	return chip->eeprom_len;
}

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

2427 2428
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
2429

2430 2431
	mutex_lock(&chip->reg_lock);
	err = chip->info->ops->get_eeprom(chip, eeprom, data);
2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444
	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 已提交
2445
	struct mv88e6xxx_chip *chip = ds->priv;
2446 2447
	int err;

2448 2449 2450
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

2451 2452 2453 2454
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

	mutex_lock(&chip->reg_lock);
2455
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
2456 2457 2458 2459 2460
	mutex_unlock(&chip->reg_lock);

	return err;
}

2461
static const struct mv88e6xxx_ops mv88e6085_ops = {
2462
	/* MV88E6XXX_FAMILY_6097 */
2463
	.irl_init_all = mv88e6352_g2_irl_init_all,
2464
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2465 2466
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2467
	.port_set_link = mv88e6xxx_port_set_link,
2468
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2469
	.port_set_speed = mv88e6185_port_set_speed,
2470
	.port_tag_remap = mv88e6095_port_tag_remap,
2471
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2472
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2473
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2474
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2475
	.port_pause_limit = mv88e6097_port_pause_limit,
2476
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2477
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2478
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2479
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2480 2481
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2482
	.stats_get_stats = mv88e6095_stats_get_stats,
2483 2484
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2485
	.watchdog_ops = &mv88e6097_watchdog_ops,
2486
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2487
	.pot_clear = mv88e6xxx_g2_pot_clear,
2488 2489
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2490
	.reset = mv88e6185_g1_reset,
2491
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2492
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2493 2494 2495
};

static const struct mv88e6xxx_ops mv88e6095_ops = {
2496
	/* MV88E6XXX_FAMILY_6095 */
2497
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2498 2499
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2500
	.port_set_link = mv88e6xxx_port_set_link,
2501
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2502
	.port_set_speed = mv88e6185_port_set_speed,
2503
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2504
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2505
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2506
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2507
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2508 2509
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2510
	.stats_get_stats = mv88e6095_stats_get_stats,
2511
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2512 2513
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2514
	.reset = mv88e6185_g1_reset,
2515
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2516
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2517 2518
};

2519
static const struct mv88e6xxx_ops mv88e6097_ops = {
2520
	/* MV88E6XXX_FAMILY_6097 */
2521
	.irl_init_all = mv88e6352_g2_irl_init_all,
2522 2523 2524 2525 2526 2527
	.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,
2528
	.port_tag_remap = mv88e6095_port_tag_remap,
2529
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2530
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2531
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2532
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2533
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
2534
	.port_pause_limit = mv88e6097_port_pause_limit,
2535
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2536
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2537
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2538
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2539 2540 2541
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
	.stats_get_stats = mv88e6095_stats_get_stats,
2542 2543
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2544
	.watchdog_ops = &mv88e6097_watchdog_ops,
2545
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2546
	.pot_clear = mv88e6xxx_g2_pot_clear,
2547
	.reset = mv88e6352_g1_reset,
2548
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2549
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2550 2551
};

2552
static const struct mv88e6xxx_ops mv88e6123_ops = {
2553
	/* MV88E6XXX_FAMILY_6165 */
2554
	.irl_init_all = mv88e6352_g2_irl_init_all,
2555
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2556 2557
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2558
	.port_set_link = mv88e6xxx_port_set_link,
2559
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2560
	.port_set_speed = mv88e6185_port_set_speed,
2561
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2562
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2563
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2564
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2565
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2566
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2567 2568
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2569
	.stats_get_stats = mv88e6095_stats_get_stats,
2570 2571
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2572
	.watchdog_ops = &mv88e6097_watchdog_ops,
2573
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2574
	.pot_clear = mv88e6xxx_g2_pot_clear,
2575
	.reset = mv88e6352_g1_reset,
2576
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2577
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2578 2579 2580
};

static const struct mv88e6xxx_ops mv88e6131_ops = {
2581
	/* MV88E6XXX_FAMILY_6185 */
2582
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2583 2584
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2585
	.port_set_link = mv88e6xxx_port_set_link,
2586
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2587
	.port_set_speed = mv88e6185_port_set_speed,
2588
	.port_tag_remap = mv88e6095_port_tag_remap,
2589
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2590
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2591
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2592
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2593
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2594
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2595
	.port_pause_limit = mv88e6097_port_pause_limit,
2596
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2597
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2598 2599
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2600
	.stats_get_stats = mv88e6095_stats_get_stats,
2601 2602
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2603
	.watchdog_ops = &mv88e6097_watchdog_ops,
2604
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2605 2606
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2607
	.reset = mv88e6185_g1_reset,
2608
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2609
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2610 2611
};

2612 2613
static const struct mv88e6xxx_ops mv88e6141_ops = {
	/* MV88E6XXX_FAMILY_6341 */
2614
	.irl_init_all = mv88e6352_g2_irl_init_all,
2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627
	.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,
2628
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2629
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2630
	.port_pause_limit = mv88e6097_port_pause_limit,
2631 2632 2633
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
2634
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2635 2636 2637
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
2638 2639
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
2640 2641
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
2642
	.pot_clear = mv88e6xxx_g2_pot_clear,
2643
	.reset = mv88e6352_g1_reset,
2644
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2645
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2646
	.gpio_ops = &mv88e6352_gpio_ops,
2647 2648
};

2649
static const struct mv88e6xxx_ops mv88e6161_ops = {
2650
	/* MV88E6XXX_FAMILY_6165 */
2651
	.irl_init_all = mv88e6352_g2_irl_init_all,
2652
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2653 2654
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2655
	.port_set_link = mv88e6xxx_port_set_link,
2656
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2657
	.port_set_speed = mv88e6185_port_set_speed,
2658
	.port_tag_remap = mv88e6095_port_tag_remap,
2659
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2660
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2661
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2662
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2663
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2664
	.port_pause_limit = mv88e6097_port_pause_limit,
2665
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2666
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2667
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2668
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2669 2670
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2671
	.stats_get_stats = mv88e6095_stats_get_stats,
2672 2673
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2674
	.watchdog_ops = &mv88e6097_watchdog_ops,
2675
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2676
	.pot_clear = mv88e6xxx_g2_pot_clear,
2677
	.reset = mv88e6352_g1_reset,
2678
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2679
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2680 2681 2682
};

static const struct mv88e6xxx_ops mv88e6165_ops = {
2683
	/* MV88E6XXX_FAMILY_6165 */
2684
	.irl_init_all = mv88e6352_g2_irl_init_all,
2685
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2686 2687
	.phy_read = mv88e6165_phy_read,
	.phy_write = mv88e6165_phy_write,
2688
	.port_set_link = mv88e6xxx_port_set_link,
2689
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2690
	.port_set_speed = mv88e6185_port_set_speed,
2691
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2692
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2693
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2694
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2695 2696
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2697
	.stats_get_stats = mv88e6095_stats_get_stats,
2698 2699
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2700
	.watchdog_ops = &mv88e6097_watchdog_ops,
2701
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2702
	.pot_clear = mv88e6xxx_g2_pot_clear,
2703
	.reset = mv88e6352_g1_reset,
2704
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2705
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2706 2707 2708
};

static const struct mv88e6xxx_ops mv88e6171_ops = {
2709
	/* MV88E6XXX_FAMILY_6351 */
2710
	.irl_init_all = mv88e6352_g2_irl_init_all,
2711
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2712 2713
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2714
	.port_set_link = mv88e6xxx_port_set_link,
2715
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2716
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
2717
	.port_set_speed = mv88e6185_port_set_speed,
2718
	.port_tag_remap = mv88e6095_port_tag_remap,
2719
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2720
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2721
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2722
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2723
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2724
	.port_pause_limit = mv88e6097_port_pause_limit,
2725
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2726
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2727
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2728
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2729 2730
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2731
	.stats_get_stats = mv88e6095_stats_get_stats,
2732 2733
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2734
	.watchdog_ops = &mv88e6097_watchdog_ops,
2735
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2736
	.pot_clear = mv88e6xxx_g2_pot_clear,
2737
	.reset = mv88e6352_g1_reset,
2738
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2739
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2740 2741 2742
};

static const struct mv88e6xxx_ops mv88e6172_ops = {
2743
	/* MV88E6XXX_FAMILY_6352 */
2744
	.irl_init_all = mv88e6352_g2_irl_init_all,
2745 2746
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
2747
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2748 2749
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2750
	.port_set_link = mv88e6xxx_port_set_link,
2751
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2752
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
2753
	.port_set_speed = mv88e6352_port_set_speed,
2754
	.port_tag_remap = mv88e6095_port_tag_remap,
2755
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2756
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2757
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2758
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2759
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2760
	.port_pause_limit = mv88e6097_port_pause_limit,
2761
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2762
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2763
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2764
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2765 2766
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2767
	.stats_get_stats = mv88e6095_stats_get_stats,
2768 2769
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2770
	.watchdog_ops = &mv88e6097_watchdog_ops,
2771
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2772
	.pot_clear = mv88e6xxx_g2_pot_clear,
2773
	.reset = mv88e6352_g1_reset,
2774
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2775
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2776
	.serdes_power = mv88e6352_serdes_power,
2777
	.gpio_ops = &mv88e6352_gpio_ops,
2778 2779 2780
};

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

static const struct mv88e6xxx_ops mv88e6176_ops = {
2815
	/* MV88E6XXX_FAMILY_6352 */
2816
	.irl_init_all = mv88e6352_g2_irl_init_all,
2817 2818
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
2819
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2820 2821
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2822
	.port_set_link = mv88e6xxx_port_set_link,
2823
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2824
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
2825
	.port_set_speed = mv88e6352_port_set_speed,
2826
	.port_tag_remap = mv88e6095_port_tag_remap,
2827
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2828
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2829
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2830
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2831
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2832
	.port_pause_limit = mv88e6097_port_pause_limit,
2833
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2834
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2835
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2836
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2837 2838
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2839
	.stats_get_stats = mv88e6095_stats_get_stats,
2840 2841
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2842
	.watchdog_ops = &mv88e6097_watchdog_ops,
2843
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2844
	.pot_clear = mv88e6xxx_g2_pot_clear,
2845
	.reset = mv88e6352_g1_reset,
2846
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2847
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2848
	.serdes_power = mv88e6352_serdes_power,
2849
	.gpio_ops = &mv88e6352_gpio_ops,
2850 2851 2852
};

static const struct mv88e6xxx_ops mv88e6185_ops = {
2853
	/* MV88E6XXX_FAMILY_6185 */
2854
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2855 2856
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2857
	.port_set_link = mv88e6xxx_port_set_link,
2858
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2859
	.port_set_speed = mv88e6185_port_set_speed,
2860
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2861
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2862
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
2863
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2864
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2865
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2866 2867
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2868
	.stats_get_stats = mv88e6095_stats_get_stats,
2869 2870
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2871
	.watchdog_ops = &mv88e6097_watchdog_ops,
2872
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2873 2874
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2875
	.reset = mv88e6185_g1_reset,
2876
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2877
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2878 2879
};

2880
static const struct mv88e6xxx_ops mv88e6190_ops = {
2881
	/* MV88E6XXX_FAMILY_6390 */
2882
	.irl_init_all = mv88e6390_g2_irl_init_all,
2883 2884
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
2885 2886 2887 2888 2889 2890 2891
	.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,
2892
	.port_tag_remap = mv88e6390_port_tag_remap,
2893
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2894
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2895
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2896
	.port_pause_limit = mv88e6390_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 = mv88e6390_g1_stats_snapshot,
2900
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
2901 2902
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
2903
	.stats_get_stats = mv88e6390_stats_get_stats,
2904 2905
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
2906
	.watchdog_ops = &mv88e6390_watchdog_ops,
2907
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
2908
	.pot_clear = mv88e6xxx_g2_pot_clear,
2909
	.reset = mv88e6352_g1_reset,
2910 2911
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
2912
	.serdes_power = mv88e6390_serdes_power,
2913
	.gpio_ops = &mv88e6352_gpio_ops,
2914 2915 2916
};

static const struct mv88e6xxx_ops mv88e6190x_ops = {
2917
	/* MV88E6XXX_FAMILY_6390 */
2918
	.irl_init_all = mv88e6390_g2_irl_init_all,
2919 2920
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
2921 2922 2923 2924 2925 2926 2927
	.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,
2928
	.port_tag_remap = mv88e6390_port_tag_remap,
2929
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2930
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2931
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2932
	.port_pause_limit = mv88e6390_port_pause_limit,
2933
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2934
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2935
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
2936
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
2937 2938
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
2939
	.stats_get_stats = mv88e6390_stats_get_stats,
2940 2941
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
2942
	.watchdog_ops = &mv88e6390_watchdog_ops,
2943
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
2944
	.pot_clear = mv88e6xxx_g2_pot_clear,
2945
	.reset = mv88e6352_g1_reset,
2946 2947
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
2948
	.serdes_power = mv88e6390_serdes_power,
2949
	.gpio_ops = &mv88e6352_gpio_ops,
2950 2951 2952
};

static const struct mv88e6xxx_ops mv88e6191_ops = {
2953
	/* MV88E6XXX_FAMILY_6390 */
2954
	.irl_init_all = mv88e6390_g2_irl_init_all,
2955 2956
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
2957 2958 2959 2960 2961 2962 2963
	.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,
2964
	.port_tag_remap = mv88e6390_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_pause_limit = mv88e6390_port_pause_limit,
2969
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2970
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2971
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
2972
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
2973 2974
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
2975
	.stats_get_stats = mv88e6390_stats_get_stats,
2976 2977
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
2978
	.watchdog_ops = &mv88e6390_watchdog_ops,
2979
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
2980
	.pot_clear = mv88e6xxx_g2_pot_clear,
2981
	.reset = mv88e6352_g1_reset,
2982 2983
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
2984
	.serdes_power = mv88e6390_serdes_power,
2985 2986
};

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

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

3064
static const struct mv88e6xxx_ops mv88e6320_ops = {
3065
	/* MV88E6XXX_FAMILY_6320 */
3066
	.irl_init_all = mv88e6352_g2_irl_init_all,
3067 3068
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3069
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3070 3071
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3072
	.port_set_link = mv88e6xxx_port_set_link,
3073
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3074
	.port_set_speed = mv88e6185_port_set_speed,
3075
	.port_tag_remap = mv88e6095_port_tag_remap,
3076
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3077
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3078
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3079
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3080
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3081
	.port_pause_limit = mv88e6097_port_pause_limit,
3082
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3083
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3084
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3085
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3086 3087
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3088
	.stats_get_stats = mv88e6320_stats_get_stats,
3089 3090
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3091
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3092
	.pot_clear = mv88e6xxx_g2_pot_clear,
3093
	.reset = mv88e6352_g1_reset,
3094
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3095
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3096
	.gpio_ops = &mv88e6352_gpio_ops,
3097
	.avb_ops = &mv88e6352_avb_ops,
3098 3099 3100
};

static const struct mv88e6xxx_ops mv88e6321_ops = {
3101
	/* MV88E6XXX_FAMILY_6320 */
3102
	.irl_init_all = mv88e6352_g2_irl_init_all,
3103 3104
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3105
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3106 3107
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3108
	.port_set_link = mv88e6xxx_port_set_link,
3109
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3110
	.port_set_speed = mv88e6185_port_set_speed,
3111
	.port_tag_remap = mv88e6095_port_tag_remap,
3112
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3113
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3114
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3115
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3116
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3117
	.port_pause_limit = mv88e6097_port_pause_limit,
3118
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3119
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3120
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3121
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3122 3123
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3124
	.stats_get_stats = mv88e6320_stats_get_stats,
3125 3126
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3127
	.reset = mv88e6352_g1_reset,
3128
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3129
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3130
	.gpio_ops = &mv88e6352_gpio_ops,
3131
	.avb_ops = &mv88e6352_avb_ops,
3132 3133
};

3134 3135
static const struct mv88e6xxx_ops mv88e6341_ops = {
	/* MV88E6XXX_FAMILY_6341 */
3136
	.irl_init_all = mv88e6352_g2_irl_init_all,
3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149
	.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,
3150
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3151
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3152
	.port_pause_limit = mv88e6097_port_pause_limit,
3153 3154 3155
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3156
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3157 3158 3159
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
3160 3161
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3162 3163
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
3164
	.pot_clear = mv88e6xxx_g2_pot_clear,
3165
	.reset = mv88e6352_g1_reset,
3166
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3167
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3168
	.gpio_ops = &mv88e6352_gpio_ops,
3169
	.avb_ops = &mv88e6390_avb_ops,
3170 3171
};

3172
static const struct mv88e6xxx_ops mv88e6350_ops = {
3173
	/* MV88E6XXX_FAMILY_6351 */
3174
	.irl_init_all = mv88e6352_g2_irl_init_all,
3175
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3176 3177
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3178
	.port_set_link = mv88e6xxx_port_set_link,
3179
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3180
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3181
	.port_set_speed = mv88e6185_port_set_speed,
3182
	.port_tag_remap = mv88e6095_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_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3187
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3188
	.port_pause_limit = mv88e6097_port_pause_limit,
3189
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3190
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3191
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3192
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3193 3194
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3195
	.stats_get_stats = mv88e6095_stats_get_stats,
3196 3197
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3198
	.watchdog_ops = &mv88e6097_watchdog_ops,
3199
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3200
	.pot_clear = mv88e6xxx_g2_pot_clear,
3201
	.reset = mv88e6352_g1_reset,
3202
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3203
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3204 3205 3206
};

static const struct mv88e6xxx_ops mv88e6351_ops = {
3207
	/* MV88E6XXX_FAMILY_6351 */
3208
	.irl_init_all = mv88e6352_g2_irl_init_all,
3209
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3210 3211
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3212
	.port_set_link = mv88e6xxx_port_set_link,
3213
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3214
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3215
	.port_set_speed = mv88e6185_port_set_speed,
3216
	.port_tag_remap = mv88e6095_port_tag_remap,
3217
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3218
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3219
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3220
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3221
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3222
	.port_pause_limit = mv88e6097_port_pause_limit,
3223
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3224
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3225
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3226
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3227 3228
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3229
	.stats_get_stats = mv88e6095_stats_get_stats,
3230 3231
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3232
	.watchdog_ops = &mv88e6097_watchdog_ops,
3233
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3234
	.pot_clear = mv88e6xxx_g2_pot_clear,
3235
	.reset = mv88e6352_g1_reset,
3236
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3237
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3238
	.avb_ops = &mv88e6352_avb_ops,
3239 3240 3241
};

static const struct mv88e6xxx_ops mv88e6352_ops = {
3242
	/* MV88E6XXX_FAMILY_6352 */
3243
	.irl_init_all = mv88e6352_g2_irl_init_all,
3244 3245
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3246
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3247 3248
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3249
	.port_set_link = mv88e6xxx_port_set_link,
3250
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3251
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3252
	.port_set_speed = mv88e6352_port_set_speed,
3253
	.port_tag_remap = mv88e6095_port_tag_remap,
3254
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3255
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3256
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3257
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3258
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3259
	.port_pause_limit = mv88e6097_port_pause_limit,
3260
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3261
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3262
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3263
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3264 3265
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3266
	.stats_get_stats = mv88e6095_stats_get_stats,
3267 3268
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3269
	.watchdog_ops = &mv88e6097_watchdog_ops,
3270
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3271
	.pot_clear = mv88e6xxx_g2_pot_clear,
3272
	.reset = mv88e6352_g1_reset,
3273
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3274
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3275
	.serdes_power = mv88e6352_serdes_power,
3276
	.gpio_ops = &mv88e6352_gpio_ops,
3277
	.avb_ops = &mv88e6352_avb_ops,
3278 3279 3280
	.serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
	.serdes_get_strings = mv88e6352_serdes_get_strings,
	.serdes_get_stats = mv88e6352_serdes_get_stats,
3281 3282
};

3283
static const struct mv88e6xxx_ops mv88e6390_ops = {
3284
	/* MV88E6XXX_FAMILY_6390 */
3285
	.irl_init_all = mv88e6390_g2_irl_init_all,
3286 3287
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3288 3289 3290 3291 3292 3293 3294
	.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,
3295
	.port_tag_remap = mv88e6390_port_tag_remap,
3296
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3297
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3298
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3299
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3300
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3301
	.port_pause_limit = mv88e6390_port_pause_limit,
3302
	.port_set_cmode = mv88e6390x_port_set_cmode,
3303
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3304
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3305
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3306
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3307 3308
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3309
	.stats_get_stats = mv88e6390_stats_get_stats,
3310 3311
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3312
	.watchdog_ops = &mv88e6390_watchdog_ops,
3313
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3314
	.pot_clear = mv88e6xxx_g2_pot_clear,
3315
	.reset = mv88e6352_g1_reset,
3316 3317
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3318
	.serdes_power = mv88e6390_serdes_power,
3319
	.gpio_ops = &mv88e6352_gpio_ops,
3320
	.avb_ops = &mv88e6390_avb_ops,
3321 3322 3323
};

static const struct mv88e6xxx_ops mv88e6390x_ops = {
3324
	/* MV88E6XXX_FAMILY_6390 */
3325
	.irl_init_all = mv88e6390_g2_irl_init_all,
3326 3327
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3328 3329 3330 3331 3332 3333 3334
	.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,
3335
	.port_tag_remap = mv88e6390_port_tag_remap,
3336
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3337
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3338
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3339
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3340
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3341
	.port_pause_limit = mv88e6390_port_pause_limit,
3342
	.port_set_cmode = mv88e6390x_port_set_cmode,
3343
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3344
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3345
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3346
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3347 3348
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3349
	.stats_get_stats = mv88e6390_stats_get_stats,
3350 3351
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3352
	.watchdog_ops = &mv88e6390_watchdog_ops,
3353
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3354
	.pot_clear = mv88e6xxx_g2_pot_clear,
3355
	.reset = mv88e6352_g1_reset,
3356 3357
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3358
	.serdes_power = mv88e6390_serdes_power,
3359
	.gpio_ops = &mv88e6352_gpio_ops,
3360
	.avb_ops = &mv88e6390_avb_ops,
3361 3362
};

3363 3364
static const struct mv88e6xxx_info mv88e6xxx_table[] = {
	[MV88E6085] = {
3365
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
3366 3367 3368 3369
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6085",
		.num_databases = 4096,
		.num_ports = 10,
3370
		.num_internal_phys = 5,
3371
		.max_vid = 4095,
3372
		.port_base_addr = 0x10,
3373
		.global1_addr = 0x1b,
3374
		.global2_addr = 0x1c,
3375
		.age_time_coeff = 15000,
3376
		.g1_irqs = 8,
3377
		.g2_irqs = 10,
3378
		.atu_move_port_mask = 0xf,
3379
		.pvt = true,
3380
		.multi_chip = true,
3381
		.tag_protocol = DSA_TAG_PROTO_DSA,
3382
		.ops = &mv88e6085_ops,
3383 3384 3385
	},

	[MV88E6095] = {
3386
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
3387 3388 3389 3390
		.family = MV88E6XXX_FAMILY_6095,
		.name = "Marvell 88E6095/88E6095F",
		.num_databases = 256,
		.num_ports = 11,
3391
		.num_internal_phys = 0,
3392
		.max_vid = 4095,
3393
		.port_base_addr = 0x10,
3394
		.global1_addr = 0x1b,
3395
		.global2_addr = 0x1c,
3396
		.age_time_coeff = 15000,
3397
		.g1_irqs = 8,
3398
		.atu_move_port_mask = 0xf,
3399
		.multi_chip = true,
3400
		.tag_protocol = DSA_TAG_PROTO_DSA,
3401
		.ops = &mv88e6095_ops,
3402 3403
	},

3404
	[MV88E6097] = {
3405
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
3406 3407 3408 3409
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6097/88E6097F",
		.num_databases = 4096,
		.num_ports = 11,
3410
		.num_internal_phys = 8,
3411
		.max_vid = 4095,
3412 3413
		.port_base_addr = 0x10,
		.global1_addr = 0x1b,
3414
		.global2_addr = 0x1c,
3415
		.age_time_coeff = 15000,
3416
		.g1_irqs = 8,
3417
		.g2_irqs = 10,
3418
		.atu_move_port_mask = 0xf,
3419
		.pvt = true,
3420
		.multi_chip = true,
3421
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3422 3423 3424
		.ops = &mv88e6097_ops,
	},

3425
	[MV88E6123] = {
3426
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
3427 3428 3429 3430
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6123",
		.num_databases = 4096,
		.num_ports = 3,
3431
		.num_internal_phys = 5,
3432
		.max_vid = 4095,
3433
		.port_base_addr = 0x10,
3434
		.global1_addr = 0x1b,
3435
		.global2_addr = 0x1c,
3436
		.age_time_coeff = 15000,
3437
		.g1_irqs = 9,
3438
		.g2_irqs = 10,
3439
		.atu_move_port_mask = 0xf,
3440
		.pvt = true,
3441
		.multi_chip = true,
3442
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3443
		.ops = &mv88e6123_ops,
3444 3445 3446
	},

	[MV88E6131] = {
3447
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
3448 3449 3450 3451
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6131",
		.num_databases = 256,
		.num_ports = 8,
3452
		.num_internal_phys = 0,
3453
		.max_vid = 4095,
3454
		.port_base_addr = 0x10,
3455
		.global1_addr = 0x1b,
3456
		.global2_addr = 0x1c,
3457
		.age_time_coeff = 15000,
3458
		.g1_irqs = 9,
3459
		.atu_move_port_mask = 0xf,
3460
		.multi_chip = true,
3461
		.tag_protocol = DSA_TAG_PROTO_DSA,
3462
		.ops = &mv88e6131_ops,
3463 3464
	},

3465
	[MV88E6141] = {
3466
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
3467
		.family = MV88E6XXX_FAMILY_6341,
3468
		.name = "Marvell 88E6141",
3469 3470
		.num_databases = 4096,
		.num_ports = 6,
3471
		.num_internal_phys = 5,
3472
		.num_gpio = 11,
3473
		.max_vid = 4095,
3474 3475
		.port_base_addr = 0x10,
		.global1_addr = 0x1b,
3476
		.global2_addr = 0x1c,
3477 3478
		.age_time_coeff = 3750,
		.atu_move_port_mask = 0x1f,
3479
		.g1_irqs = 9,
3480
		.g2_irqs = 10,
3481
		.pvt = true,
3482
		.multi_chip = true,
3483 3484 3485 3486
		.tag_protocol = DSA_TAG_PROTO_EDSA,
		.ops = &mv88e6141_ops,
	},

3487
	[MV88E6161] = {
3488
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
3489 3490 3491 3492
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6161",
		.num_databases = 4096,
		.num_ports = 6,
3493
		.num_internal_phys = 5,
3494
		.max_vid = 4095,
3495
		.port_base_addr = 0x10,
3496
		.global1_addr = 0x1b,
3497
		.global2_addr = 0x1c,
3498
		.age_time_coeff = 15000,
3499
		.g1_irqs = 9,
3500
		.g2_irqs = 10,
3501
		.atu_move_port_mask = 0xf,
3502
		.pvt = true,
3503
		.multi_chip = true,
3504
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3505
		.ops = &mv88e6161_ops,
3506 3507 3508
	},

	[MV88E6165] = {
3509
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
3510 3511 3512 3513
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6165",
		.num_databases = 4096,
		.num_ports = 6,
3514
		.num_internal_phys = 0,
3515
		.max_vid = 4095,
3516
		.port_base_addr = 0x10,
3517
		.global1_addr = 0x1b,
3518
		.global2_addr = 0x1c,
3519
		.age_time_coeff = 15000,
3520
		.g1_irqs = 9,
3521
		.g2_irqs = 10,
3522
		.atu_move_port_mask = 0xf,
3523
		.pvt = true,
3524
		.multi_chip = true,
3525
		.tag_protocol = DSA_TAG_PROTO_DSA,
3526
		.ops = &mv88e6165_ops,
3527 3528 3529
	},

	[MV88E6171] = {
3530
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
3531 3532 3533 3534
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6171",
		.num_databases = 4096,
		.num_ports = 7,
3535
		.num_internal_phys = 5,
3536
		.max_vid = 4095,
3537
		.port_base_addr = 0x10,
3538
		.global1_addr = 0x1b,
3539
		.global2_addr = 0x1c,
3540
		.age_time_coeff = 15000,
3541
		.g1_irqs = 9,
3542
		.g2_irqs = 10,
3543
		.atu_move_port_mask = 0xf,
3544
		.pvt = true,
3545
		.multi_chip = true,
3546
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3547
		.ops = &mv88e6171_ops,
3548 3549 3550
	},

	[MV88E6172] = {
3551
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
3552 3553 3554 3555
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6172",
		.num_databases = 4096,
		.num_ports = 7,
3556
		.num_internal_phys = 5,
3557
		.num_gpio = 15,
3558
		.max_vid = 4095,
3559
		.port_base_addr = 0x10,
3560
		.global1_addr = 0x1b,
3561
		.global2_addr = 0x1c,
3562
		.age_time_coeff = 15000,
3563
		.g1_irqs = 9,
3564
		.g2_irqs = 10,
3565
		.atu_move_port_mask = 0xf,
3566
		.pvt = true,
3567
		.multi_chip = true,
3568
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3569
		.ops = &mv88e6172_ops,
3570 3571 3572
	},

	[MV88E6175] = {
3573
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
3574 3575 3576 3577
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6175",
		.num_databases = 4096,
		.num_ports = 7,
3578
		.num_internal_phys = 5,
3579
		.max_vid = 4095,
3580
		.port_base_addr = 0x10,
3581
		.global1_addr = 0x1b,
3582
		.global2_addr = 0x1c,
3583
		.age_time_coeff = 15000,
3584
		.g1_irqs = 9,
3585
		.g2_irqs = 10,
3586
		.atu_move_port_mask = 0xf,
3587
		.pvt = true,
3588
		.multi_chip = true,
3589
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3590
		.ops = &mv88e6175_ops,
3591 3592 3593
	},

	[MV88E6176] = {
3594
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
3595 3596 3597 3598
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6176",
		.num_databases = 4096,
		.num_ports = 7,
3599
		.num_internal_phys = 5,
3600
		.num_gpio = 15,
3601
		.max_vid = 4095,
3602
		.port_base_addr = 0x10,
3603
		.global1_addr = 0x1b,
3604
		.global2_addr = 0x1c,
3605
		.age_time_coeff = 15000,
3606
		.g1_irqs = 9,
3607
		.g2_irqs = 10,
3608
		.atu_move_port_mask = 0xf,
3609
		.pvt = true,
3610
		.multi_chip = true,
3611
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3612
		.ops = &mv88e6176_ops,
3613 3614 3615
	},

	[MV88E6185] = {
3616
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
3617 3618 3619 3620
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6185",
		.num_databases = 256,
		.num_ports = 10,
3621
		.num_internal_phys = 0,
3622
		.max_vid = 4095,
3623
		.port_base_addr = 0x10,
3624
		.global1_addr = 0x1b,
3625
		.global2_addr = 0x1c,
3626
		.age_time_coeff = 15000,
3627
		.g1_irqs = 8,
3628
		.atu_move_port_mask = 0xf,
3629
		.multi_chip = true,
3630
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3631
		.ops = &mv88e6185_ops,
3632 3633
	},

3634
	[MV88E6190] = {
3635
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
3636 3637 3638 3639
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3640
		.num_internal_phys = 11,
3641
		.num_gpio = 16,
3642
		.max_vid = 8191,
3643 3644
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3645
		.global2_addr = 0x1c,
3646
		.tag_protocol = DSA_TAG_PROTO_DSA,
3647
		.age_time_coeff = 3750,
3648
		.g1_irqs = 9,
3649
		.g2_irqs = 14,
3650
		.pvt = true,
3651
		.multi_chip = true,
3652
		.atu_move_port_mask = 0x1f,
3653 3654 3655 3656
		.ops = &mv88e6190_ops,
	},

	[MV88E6190X] = {
3657
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
3658 3659 3660 3661
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3662
		.num_internal_phys = 11,
3663
		.num_gpio = 16,
3664
		.max_vid = 8191,
3665 3666
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3667
		.global2_addr = 0x1c,
3668
		.age_time_coeff = 3750,
3669
		.g1_irqs = 9,
3670
		.g2_irqs = 14,
3671
		.atu_move_port_mask = 0x1f,
3672
		.pvt = true,
3673
		.multi_chip = true,
3674
		.tag_protocol = DSA_TAG_PROTO_DSA,
3675 3676 3677 3678
		.ops = &mv88e6190x_ops,
	},

	[MV88E6191] = {
3679
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
3680 3681 3682 3683
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6191",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3684
		.num_internal_phys = 11,
3685
		.max_vid = 8191,
3686 3687
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3688
		.global2_addr = 0x1c,
3689
		.age_time_coeff = 3750,
3690
		.g1_irqs = 9,
3691
		.g2_irqs = 14,
3692
		.atu_move_port_mask = 0x1f,
3693
		.pvt = true,
3694
		.multi_chip = true,
3695
		.tag_protocol = DSA_TAG_PROTO_DSA,
3696
		.ptp_support = true,
3697
		.ops = &mv88e6191_ops,
3698 3699
	},

3700
	[MV88E6240] = {
3701
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
3702 3703 3704 3705
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6240",
		.num_databases = 4096,
		.num_ports = 7,
3706
		.num_internal_phys = 5,
3707
		.num_gpio = 15,
3708
		.max_vid = 4095,
3709
		.port_base_addr = 0x10,
3710
		.global1_addr = 0x1b,
3711
		.global2_addr = 0x1c,
3712
		.age_time_coeff = 15000,
3713
		.g1_irqs = 9,
3714
		.g2_irqs = 10,
3715
		.atu_move_port_mask = 0xf,
3716
		.pvt = true,
3717
		.multi_chip = true,
3718
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3719
		.ptp_support = true,
3720
		.ops = &mv88e6240_ops,
3721 3722
	},

3723
	[MV88E6290] = {
3724
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
3725 3726 3727 3728
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6290",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3729
		.num_internal_phys = 11,
3730
		.num_gpio = 16,
3731
		.max_vid = 8191,
3732 3733
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3734
		.global2_addr = 0x1c,
3735
		.age_time_coeff = 3750,
3736
		.g1_irqs = 9,
3737
		.g2_irqs = 14,
3738
		.atu_move_port_mask = 0x1f,
3739
		.pvt = true,
3740
		.multi_chip = true,
3741
		.tag_protocol = DSA_TAG_PROTO_DSA,
3742
		.ptp_support = true,
3743 3744 3745
		.ops = &mv88e6290_ops,
	},

3746
	[MV88E6320] = {
3747
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
3748 3749 3750 3751
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6320",
		.num_databases = 4096,
		.num_ports = 7,
3752
		.num_internal_phys = 5,
3753
		.num_gpio = 15,
3754
		.max_vid = 4095,
3755
		.port_base_addr = 0x10,
3756
		.global1_addr = 0x1b,
3757
		.global2_addr = 0x1c,
3758
		.age_time_coeff = 15000,
3759
		.g1_irqs = 8,
3760
		.g2_irqs = 10,
3761
		.atu_move_port_mask = 0xf,
3762
		.pvt = true,
3763
		.multi_chip = true,
3764
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3765
		.ptp_support = true,
3766
		.ops = &mv88e6320_ops,
3767 3768 3769
	},

	[MV88E6321] = {
3770
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
3771 3772 3773 3774
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6321",
		.num_databases = 4096,
		.num_ports = 7,
3775
		.num_internal_phys = 5,
3776
		.num_gpio = 15,
3777
		.max_vid = 4095,
3778
		.port_base_addr = 0x10,
3779
		.global1_addr = 0x1b,
3780
		.global2_addr = 0x1c,
3781
		.age_time_coeff = 15000,
3782
		.g1_irqs = 8,
3783
		.g2_irqs = 10,
3784
		.atu_move_port_mask = 0xf,
3785
		.multi_chip = true,
3786
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3787
		.ptp_support = true,
3788
		.ops = &mv88e6321_ops,
3789 3790
	},

3791
	[MV88E6341] = {
3792
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
3793 3794 3795
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
3796
		.num_internal_phys = 5,
3797
		.num_ports = 6,
3798
		.num_gpio = 11,
3799
		.max_vid = 4095,
3800 3801
		.port_base_addr = 0x10,
		.global1_addr = 0x1b,
3802
		.global2_addr = 0x1c,
3803
		.age_time_coeff = 3750,
3804
		.atu_move_port_mask = 0x1f,
3805
		.g1_irqs = 9,
3806
		.g2_irqs = 10,
3807
		.pvt = true,
3808
		.multi_chip = true,
3809
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3810
		.ptp_support = true,
3811 3812 3813
		.ops = &mv88e6341_ops,
	},

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

	[MV88E6351] = {
3836
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
3837 3838 3839 3840
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6351",
		.num_databases = 4096,
		.num_ports = 7,
3841
		.num_internal_phys = 5,
3842
		.max_vid = 4095,
3843
		.port_base_addr = 0x10,
3844
		.global1_addr = 0x1b,
3845
		.global2_addr = 0x1c,
3846
		.age_time_coeff = 15000,
3847
		.g1_irqs = 9,
3848
		.g2_irqs = 10,
3849
		.atu_move_port_mask = 0xf,
3850
		.pvt = true,
3851
		.multi_chip = true,
3852
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3853
		.ops = &mv88e6351_ops,
3854 3855 3856
	},

	[MV88E6352] = {
3857
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
3858 3859 3860 3861
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6352",
		.num_databases = 4096,
		.num_ports = 7,
3862
		.num_internal_phys = 5,
3863
		.num_gpio = 15,
3864
		.max_vid = 4095,
3865
		.port_base_addr = 0x10,
3866
		.global1_addr = 0x1b,
3867
		.global2_addr = 0x1c,
3868
		.age_time_coeff = 15000,
3869
		.g1_irqs = 9,
3870
		.g2_irqs = 10,
3871
		.atu_move_port_mask = 0xf,
3872
		.pvt = true,
3873
		.multi_chip = true,
3874
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3875
		.ptp_support = true,
3876
		.ops = &mv88e6352_ops,
3877
	},
3878
	[MV88E6390] = {
3879
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
3880 3881 3882 3883
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3884
		.num_internal_phys = 11,
3885
		.num_gpio = 16,
3886
		.max_vid = 8191,
3887 3888
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3889
		.global2_addr = 0x1c,
3890
		.age_time_coeff = 3750,
3891
		.g1_irqs = 9,
3892
		.g2_irqs = 14,
3893
		.atu_move_port_mask = 0x1f,
3894
		.pvt = true,
3895
		.multi_chip = true,
3896
		.tag_protocol = DSA_TAG_PROTO_DSA,
3897
		.ptp_support = true,
3898 3899 3900
		.ops = &mv88e6390_ops,
	},
	[MV88E6390X] = {
3901
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
3902 3903 3904 3905
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3906
		.num_internal_phys = 11,
3907
		.num_gpio = 16,
3908
		.max_vid = 8191,
3909 3910
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3911
		.global2_addr = 0x1c,
3912
		.age_time_coeff = 3750,
3913
		.g1_irqs = 9,
3914
		.g2_irqs = 14,
3915
		.atu_move_port_mask = 0x1f,
3916
		.pvt = true,
3917
		.multi_chip = true,
3918
		.tag_protocol = DSA_TAG_PROTO_DSA,
3919
		.ptp_support = true,
3920 3921
		.ops = &mv88e6390x_ops,
	},
3922 3923
};

3924
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
3925
{
3926
	int i;
3927

3928 3929 3930
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
3931 3932 3933 3934

	return NULL;
}

3935
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
3936 3937
{
	const struct mv88e6xxx_info *info;
3938 3939 3940
	unsigned int prod_num, rev;
	u16 id;
	int err;
3941

3942
	mutex_lock(&chip->reg_lock);
3943
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
3944 3945 3946
	mutex_unlock(&chip->reg_lock);
	if (err)
		return err;
3947

3948 3949
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
3950 3951 3952 3953 3954

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

3955
	/* Update the compatible info with the probed one */
3956
	chip->info = info;
3957

3958 3959 3960 3961
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

3962 3963
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
3964 3965 3966 3967

	return 0;
}

3968
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
3969
{
3970
	struct mv88e6xxx_chip *chip;
3971

3972 3973
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
3974 3975
		return NULL;

3976
	chip->dev = dev;
3977

3978
	mutex_init(&chip->reg_lock);
3979
	INIT_LIST_HEAD(&chip->mdios);
3980

3981
	return chip;
3982 3983
}

3984
static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
3985 3986
			      struct mii_bus *bus, int sw_addr)
{
3987
	if (sw_addr == 0)
3988
		chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
3989
	else if (chip->info->multi_chip)
3990
		chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
3991 3992 3993
	else
		return -EINVAL;

3994 3995
	chip->bus = bus;
	chip->sw_addr = sw_addr;
3996 3997 3998 3999

	return 0;
}

4000 4001
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
							int port)
4002
{
V
Vivien Didelot 已提交
4003
	struct mv88e6xxx_chip *chip = ds->priv;
4004

4005
	return chip->info->tag_protocol;
4006 4007
}

4008
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
4009 4010 4011
static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
				       struct device *host_dev, int sw_addr,
				       void **priv)
4012
{
4013
	struct mv88e6xxx_chip *chip;
4014
	struct mii_bus *bus;
4015
	int err;
4016

4017
	bus = dsa_host_dev_to_mii_bus(host_dev);
4018 4019 4020
	if (!bus)
		return NULL;

4021 4022
	chip = mv88e6xxx_alloc_chip(dsa_dev);
	if (!chip)
4023 4024
		return NULL;

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

4028
	err = mv88e6xxx_smi_init(chip, bus, sw_addr);
4029 4030 4031
	if (err)
		goto free;

4032
	err = mv88e6xxx_detect(chip);
4033
	if (err)
4034
		goto free;
4035

4036 4037 4038 4039 4040 4041
	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_switch_reset(chip);
	mutex_unlock(&chip->reg_lock);
	if (err)
		goto free;

4042 4043
	mv88e6xxx_phy_init(chip);

4044
	err = mv88e6xxx_mdios_register(chip, NULL);
4045
	if (err)
4046
		goto free;
4047

4048
	*priv = chip;
4049

4050
	return chip->info->name;
4051
free:
4052
	devm_kfree(dsa_dev, chip);
4053 4054

	return NULL;
4055
}
4056
#endif
4057

4058
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4059
				      const struct switchdev_obj_port_mdb *mdb)
4060 4061 4062 4063 4064 4065 4066 4067 4068
{
	/* 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,
4069
				   const struct switchdev_obj_port_mdb *mdb)
4070
{
V
Vivien Didelot 已提交
4071
	struct mv88e6xxx_chip *chip = ds->priv;
4072 4073 4074

	mutex_lock(&chip->reg_lock);
	if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4075
					 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
4076 4077
		dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
			port);
4078 4079 4080 4081 4082 4083
	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 已提交
4084
	struct mv88e6xxx_chip *chip = ds->priv;
4085 4086 4087 4088
	int err;

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4089
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
4090 4091 4092 4093 4094
	mutex_unlock(&chip->reg_lock);

	return err;
}

4095
static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
4096
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
4097
	.probe			= mv88e6xxx_drv_probe,
4098
#endif
4099
	.get_tag_protocol	= mv88e6xxx_get_tag_protocol,
4100 4101 4102 4103 4104
	.setup			= mv88e6xxx_setup,
	.adjust_link		= mv88e6xxx_adjust_link,
	.get_strings		= mv88e6xxx_get_strings,
	.get_ethtool_stats	= mv88e6xxx_get_ethtool_stats,
	.get_sset_count		= mv88e6xxx_get_sset_count,
4105 4106
	.port_enable		= mv88e6xxx_port_enable,
	.port_disable		= mv88e6xxx_port_disable,
V
Vivien Didelot 已提交
4107 4108
	.get_mac_eee		= mv88e6xxx_get_mac_eee,
	.set_mac_eee		= mv88e6xxx_set_mac_eee,
4109
	.get_eeprom_len		= mv88e6xxx_get_eeprom_len,
4110 4111 4112 4113
	.get_eeprom		= mv88e6xxx_get_eeprom,
	.set_eeprom		= mv88e6xxx_set_eeprom,
	.get_regs_len		= mv88e6xxx_get_regs_len,
	.get_regs		= mv88e6xxx_get_regs,
4114
	.set_ageing_time	= mv88e6xxx_set_ageing_time,
4115 4116 4117
	.port_bridge_join	= mv88e6xxx_port_bridge_join,
	.port_bridge_leave	= mv88e6xxx_port_bridge_leave,
	.port_stp_state_set	= mv88e6xxx_port_stp_state_set,
4118
	.port_fast_age		= mv88e6xxx_port_fast_age,
4119 4120 4121 4122 4123 4124 4125
	.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,
4126 4127 4128
	.port_mdb_prepare       = mv88e6xxx_port_mdb_prepare,
	.port_mdb_add           = mv88e6xxx_port_mdb_add,
	.port_mdb_del           = mv88e6xxx_port_mdb_del,
4129 4130
	.crosschip_bridge_join	= mv88e6xxx_crosschip_bridge_join,
	.crosschip_bridge_leave	= mv88e6xxx_crosschip_bridge_leave,
4131 4132 4133 4134 4135
	.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,
4136 4137
};

4138 4139 4140 4141
static struct dsa_switch_driver mv88e6xxx_switch_drv = {
	.ops			= &mv88e6xxx_switch_ops,
};

4142
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
4143
{
4144
	struct device *dev = chip->dev;
4145 4146
	struct dsa_switch *ds;

4147
	ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
4148 4149 4150
	if (!ds)
		return -ENOMEM;

4151
	ds->priv = chip;
4152
	ds->ops = &mv88e6xxx_switch_ops;
4153 4154
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
4155 4156 4157

	dev_set_drvdata(dev, ds);

4158
	return dsa_register_switch(ds);
4159 4160
}

4161
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
4162
{
4163
	dsa_unregister_switch(chip->ds);
4164 4165
}

4166
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
4167
{
4168
	struct device *dev = &mdiodev->dev;
4169
	struct device_node *np = dev->of_node;
4170
	const struct mv88e6xxx_info *compat_info;
4171
	struct mv88e6xxx_chip *chip;
4172
	u32 eeprom_len;
4173
	int err;
4174

4175 4176 4177 4178
	compat_info = of_device_get_match_data(dev);
	if (!compat_info)
		return -EINVAL;

4179 4180
	chip = mv88e6xxx_alloc_chip(dev);
	if (!chip)
4181 4182
		return -ENOMEM;

4183
	chip->info = compat_info;
4184

4185
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
4186 4187
	if (err)
		return err;
4188

4189 4190 4191 4192
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
	if (IS_ERR(chip->reset))
		return PTR_ERR(chip->reset);

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

4197 4198
	mv88e6xxx_phy_init(chip);

4199
	if (chip->info->ops->get_eeprom &&
4200
	    !of_property_read_u32(np, "eeprom-length", &eeprom_len))
4201
		chip->eeprom_len = eeprom_len;
4202

4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214
	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;
	}

4215
	/* Has to be performed before the MDIO bus is created, because
4216
	 * the PHYs will link their interrupts to these interrupt
4217 4218 4219 4220
	 * controllers
	 */
	mutex_lock(&chip->reg_lock);
	if (chip->irq > 0)
4221
		err = mv88e6xxx_g1_irq_setup(chip);
4222 4223 4224
	else
		err = mv88e6xxx_irq_poll_setup(chip);
	mutex_unlock(&chip->reg_lock);
4225

4226 4227
	if (err)
		goto out;
4228

4229 4230
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
4231
		if (err)
4232
			goto out_g1_irq;
4233 4234
	}

4235 4236 4237 4238 4239 4240 4241 4242
	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;

4243
	err = mv88e6xxx_mdios_register(chip, np);
4244
	if (err)
4245
		goto out_g1_vtu_prob_irq;
4246

4247
	err = mv88e6xxx_register_switch(chip);
4248 4249
	if (err)
		goto out_mdio;
4250

4251
	return 0;
4252 4253

out_mdio:
4254
	mv88e6xxx_mdios_unregister(chip);
4255
out_g1_vtu_prob_irq:
4256
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
4257
out_g1_atu_prob_irq:
4258
	mv88e6xxx_g1_atu_prob_irq_free(chip);
4259
out_g2_irq:
4260
	if (chip->info->g2_irqs > 0)
4261 4262
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
4263 4264
	mutex_lock(&chip->reg_lock);
	if (chip->irq > 0)
4265
		mv88e6xxx_g1_irq_free(chip);
4266 4267 4268
	else
		mv88e6xxx_irq_poll_free(chip);
	mutex_unlock(&chip->reg_lock);
4269 4270
out:
	return err;
4271
}
4272 4273 4274 4275

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

4278 4279
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
4280
		mv88e6xxx_ptp_free(chip);
4281
	}
4282

4283
	mv88e6xxx_phy_destroy(chip);
4284
	mv88e6xxx_unregister_switch(chip);
4285
	mv88e6xxx_mdios_unregister(chip);
4286

4287 4288 4289 4290 4291 4292 4293 4294
	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)
4295
		mv88e6xxx_g1_irq_free(chip);
4296 4297 4298
	else
		mv88e6xxx_irq_poll_free(chip);
	mutex_unlock(&chip->reg_lock);
4299 4300 4301
}

static const struct of_device_id mv88e6xxx_of_match[] = {
4302 4303 4304 4305
	{
		.compatible = "marvell,mv88e6085",
		.data = &mv88e6xxx_table[MV88E6085],
	},
4306 4307 4308 4309
	{
		.compatible = "marvell,mv88e6190",
		.data = &mv88e6xxx_table[MV88E6190],
	},
4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325
	{ /* 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)
{
4326
	register_switch_driver(&mv88e6xxx_switch_drv);
4327 4328
	return mdio_driver_register(&mv88e6xxx_driver);
}
4329 4330 4331 4332
module_init(mv88e6xxx_init);

static void __exit mv88e6xxx_cleanup(void)
{
4333
	mdio_driver_unregister(&mv88e6xxx_driver);
4334
	unregister_switch_driver(&mv88e6xxx_switch_drv);
4335 4336
}
module_exit(mv88e6xxx_cleanup);
4337 4338 4339 4340

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