chip.c 118.0 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 363 364 365 366 367 368
static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
{
	mv88e6xxx_g1_irq_free(chip);

	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 428 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 470 471 472 473
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,
				   IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
				   dev_name(chip->dev), chip);
	if (err)
		mv88e6xxx_g1_irq_free_common(chip);

	return err;
}

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

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

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

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

	kthread_init_delayed_work(&chip->irq_poll_work,
				  mv88e6xxx_irq_poll);

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

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

	return 0;
}

static void mv88e6xxx_irq_poll_free(struct mv88e6xxx_chip *chip)
{
	kthread_cancel_delayed_work_sync(&chip->irq_poll_work);
	kthread_destroy_worker(chip->kworker);
}

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

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

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

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

		usleep_range(1000, 2000);
	}

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

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

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

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

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

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

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

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

	return err;
}

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

	if (!phy_is_pseudo_fixed_link(phydev))
		return;

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

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

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

586
	return chip->info->ops->stats_snapshot(chip, port);
587 588
}

589
static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648
	{ "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, },
649 650
};

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

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

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

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

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

708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723
static void mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
					uint8_t *data)
{
	mv88e6xxx_stats_get_strings(chip, data,
				    STATS_TYPE_BANK0 | STATS_TYPE_PORT);
}

static void mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
					uint8_t *data)
{
	mv88e6xxx_stats_get_strings(chip, data,
				    STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
}

static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
				  uint8_t *data)
724
{
V
Vivien Didelot 已提交
725
	struct mv88e6xxx_chip *chip = ds->priv;
726

727 728
	mutex_lock(&chip->reg_lock);

729 730
	if (chip->info->ops->stats_get_strings)
		chip->info->ops->stats_get_strings(chip, data);
731 732

	mutex_unlock(&chip->reg_lock);
733 734 735 736 737
}

static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
					  int types)
{
738 739 740 741 742
	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];
743
		if (stat->type & types)
744 745 746
			j++;
	}
	return j;
747 748
}

749 750 751 752 753 754 755 756 757 758 759 760
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);
}

761
static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port)
762 763
{
	struct mv88e6xxx_chip *chip = ds->priv;
764
	int ret = 0;
765

766
	mutex_lock(&chip->reg_lock);
767
	if (chip->info->ops->stats_get_sset_count)
768 769
		ret = chip->info->ops->stats_get_sset_count(chip);
	mutex_unlock(&chip->reg_lock);
770

771
	return ret;
772 773
}

774
static void mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
775 776
				      uint64_t *data, int types,
				      u16 bank1_select, u16 histogram)
777 778 779 780 781 782 783
{
	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) {
784
			mutex_lock(&chip->reg_lock);
785 786 787
			data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
							      bank1_select,
							      histogram);
788 789
			mutex_unlock(&chip->reg_lock);

790 791 792 793 794 795 796 797 798
			j++;
		}
	}
}

static void mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				      uint64_t *data)
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
799
					 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
800
					 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
801 802 803 804 805 806
}

static void mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				      uint64_t *data)
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
807
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
808 809
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
					 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
810 811 812 813 814 815 816
}

static void mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				      uint64_t *data)
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
817 818
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
					 0);
819 820 821 822 823 824 825 826 827
}

static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
				uint64_t *data)
{
	if (chip->info->ops->stats_get_stats)
		chip->info->ops->stats_get_stats(chip, port, data);
}

828 829
static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
					uint64_t *data)
830
{
V
Vivien Didelot 已提交
831
	struct mv88e6xxx_chip *chip = ds->priv;
832 833
	int ret;

834
	mutex_lock(&chip->reg_lock);
835

836
	ret = mv88e6xxx_stats_snapshot(chip, port);
837 838 839
	mutex_unlock(&chip->reg_lock);

	if (ret < 0)
840
		return;
841 842

	mv88e6xxx_get_stats(chip, port, data);
843

844 845
}

846 847 848 849 850 851 852 853
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;
}

854
static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
855 856 857 858
{
	return 32 * sizeof(u16);
}

859 860
static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
			       struct ethtool_regs *regs, void *_p)
861
{
V
Vivien Didelot 已提交
862
	struct mv88e6xxx_chip *chip = ds->priv;
863 864
	int err;
	u16 reg;
865 866 867 868 869 870 871
	u16 *p = _p;
	int i;

	regs->version = 0;

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

872
	mutex_lock(&chip->reg_lock);
873

874 875
	for (i = 0; i < 32; i++) {

876 877 878
		err = mv88e6xxx_port_read(chip, port, i, &reg);
		if (!err)
			p[i] = reg;
879
	}
880

881
	mutex_unlock(&chip->reg_lock);
882 883
}

V
Vivien Didelot 已提交
884 885
static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
886
{
887 888
	/* Nothing to do on the port's MAC */
	return 0;
889 890
}

V
Vivien Didelot 已提交
891 892
static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
893
{
894 895
	/* Nothing to do on the port's MAC */
	return 0;
896 897
}

898
static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
899
{
900 901 902
	struct dsa_switch *ds = NULL;
	struct net_device *br;
	u16 pvlan;
903 904
	int i;

905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924
	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 已提交
925
		    (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
926 927 928 929 930
			pvlan |= BIT(i);

	return pvlan;
}

931
static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
932 933
{
	u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
934 935 936

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

938
	return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
939 940
}

941 942
static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
					 u8 state)
943
{
V
Vivien Didelot 已提交
944
	struct mv88e6xxx_chip *chip = ds->priv;
945
	int err;
946

947
	mutex_lock(&chip->reg_lock);
948
	err = mv88e6xxx_port_set_state(chip, port, state);
949
	mutex_unlock(&chip->reg_lock);
950 951

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

955 956 957 958 959 960 961 962
static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->pot_clear)
		return chip->info->ops->pot_clear(chip);

	return 0;
}

963 964 965 966 967 968 969 970
static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->mgmt_rsvd2cpu)
		return chip->info->ops->mgmt_rsvd2cpu(chip);

	return 0;
}

971 972
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
973 974
	int err;

975 976 977 978
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

979 980 981 982
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

983 984 985
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005
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;
}

1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018
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;
}

1019 1020 1021 1022 1023 1024 1025 1026 1027
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)
1028
		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1029 1030 1031 1032

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

1033 1034
static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
{
1035 1036 1037
	int dev, port;
	int err;

1038 1039 1040 1041 1042 1043
	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.
	 */
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056
	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;
1057 1058
}

1059 1060 1061 1062 1063 1064
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);
1065
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1066 1067 1068
	mutex_unlock(&chip->reg_lock);

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

1072 1073 1074 1075 1076 1077 1078 1079
static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
{
	if (!chip->info->max_vid)
		return 0;

	return mv88e6xxx_g1_vtu_flush(chip);
}

1080 1081 1082 1083 1084 1085 1086 1087 1088
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);
}

1089 1090 1091 1092 1093 1094 1095 1096 1097
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);
}

1098
static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1099 1100
{
	DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1101 1102 1103
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = chip->info->max_vid,
	};
1104
	int i, err;
1105 1106 1107

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

1108
	/* Set every FID bit used by the (un)bridged ports */
1109
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1110
		err = mv88e6xxx_port_get_fid(chip, i, fid);
1111 1112 1113 1114 1115 1116
		if (err)
			return err;

		set_bit(*fid, fid_bitmap);
	}

1117 1118
	/* Set every FID bit used by the VLAN entries */
	do {
1119
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1120 1121 1122 1123 1124 1125 1126
		if (err)
			return err;

		if (!vlan.valid)
			break;

		set_bit(vlan.fid, fid_bitmap);
1127
	} while (vlan.vid < chip->info->max_vid);
1128 1129 1130 1131 1132

	/* 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);
1133
	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1134 1135 1136
		return -ENOSPC;

	/* Clear the database */
1137
	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1138 1139
}

1140 1141
static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
			     struct mv88e6xxx_vtu_entry *entry, bool new)
1142 1143 1144 1145 1146 1147
{
	int err;

	if (!vid)
		return -EINVAL;

1148 1149
	entry->vid = vid - 1;
	entry->valid = false;
1150

1151
	err = mv88e6xxx_vtu_getnext(chip, entry);
1152 1153 1154
	if (err)
		return err;

1155 1156
	if (entry->vid == vid && entry->valid)
		return 0;
1157

1158 1159 1160 1161 1162 1163 1164 1165
	if (new) {
		int i;

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

1166
		/* Exclude all ports */
1167
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1168
			entry->member[i] =
1169
				MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1170 1171

		return mv88e6xxx_atu_new(chip, &entry->fid);
1172 1173
	}

1174 1175
	/* switchdev expects -EOPNOTSUPP to honor software VLANs */
	return -EOPNOTSUPP;
1176 1177
}

1178 1179 1180
static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
					u16 vid_begin, u16 vid_end)
{
V
Vivien Didelot 已提交
1181
	struct mv88e6xxx_chip *chip = ds->priv;
1182 1183 1184
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = vid_begin - 1,
	};
1185 1186
	int i, err;

1187 1188 1189 1190
	/* 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;

1191 1192 1193
	if (!vid_begin)
		return -EOPNOTSUPP;

1194
	mutex_lock(&chip->reg_lock);
1195 1196

	do {
1197
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1198 1199 1200 1201 1202 1203 1204 1205 1206
		if (err)
			goto unlock;

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

1207
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1208 1209 1210
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

1211
			if (!ds->ports[i].slave)
1212 1213
				continue;

1214
			if (vlan.member[i] ==
1215
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1216 1217
				continue;

V
Vivien Didelot 已提交
1218
			if (dsa_to_port(ds, i)->bridge_dev ==
1219
			    ds->ports[port].bridge_dev)
1220 1221
				break; /* same bridge, check next VLAN */

V
Vivien Didelot 已提交
1222
			if (!dsa_to_port(ds, i)->bridge_dev)
1223 1224
				continue;

1225 1226
			dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
				port, vlan.vid, i,
V
Vivien Didelot 已提交
1227
				netdev_name(dsa_to_port(ds, i)->bridge_dev));
1228 1229 1230 1231 1232 1233
			err = -EOPNOTSUPP;
			goto unlock;
		}
	} while (vlan.vid < vid_end);

unlock:
1234
	mutex_unlock(&chip->reg_lock);
1235 1236 1237 1238

	return err;
}

1239 1240
static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
					 bool vlan_filtering)
1241
{
V
Vivien Didelot 已提交
1242
	struct mv88e6xxx_chip *chip = ds->priv;
1243 1244
	u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
		MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
1245
	int err;
1246

1247
	if (!chip->info->max_vid)
1248 1249
		return -EOPNOTSUPP;

1250
	mutex_lock(&chip->reg_lock);
1251
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1252
	mutex_unlock(&chip->reg_lock);
1253

1254
	return err;
1255 1256
}

1257 1258
static int
mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1259
			    const struct switchdev_obj_port_vlan *vlan)
1260
{
V
Vivien Didelot 已提交
1261
	struct mv88e6xxx_chip *chip = ds->priv;
1262 1263
	int err;

1264
	if (!chip->info->max_vid)
1265 1266
		return -EOPNOTSUPP;

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

1275 1276 1277 1278 1279 1280
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */
	return 0;
}

1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324
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);
}

1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347
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;
}

1348
static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
1349
				    u16 vid, u8 member)
1350
{
1351
	struct mv88e6xxx_vtu_entry vlan;
1352 1353
	int err;

1354
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
1355
	if (err)
1356
		return err;
1357

1358
	vlan.member[port] = member;
1359

1360 1361 1362 1363 1364
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
	if (err)
		return err;

	return mv88e6xxx_broadcast_setup(chip, vid);
1365 1366
}

1367
static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1368
				    const struct switchdev_obj_port_vlan *vlan)
1369
{
V
Vivien Didelot 已提交
1370
	struct mv88e6xxx_chip *chip = ds->priv;
1371 1372
	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1373
	u8 member;
1374 1375
	u16 vid;

1376
	if (!chip->info->max_vid)
1377 1378
		return;

1379
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1380
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1381
	else if (untagged)
1382
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
1383
	else
1384
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
1385

1386
	mutex_lock(&chip->reg_lock);
1387

1388
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
1389
		if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
1390 1391
			dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
				vid, untagged ? 'u' : 't');
1392

1393
	if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1394 1395
		dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
			vlan->vid_end);
1396

1397
	mutex_unlock(&chip->reg_lock);
1398 1399
}

1400
static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
1401
				    int port, u16 vid)
1402
{
1403
	struct mv88e6xxx_vtu_entry vlan;
1404 1405
	int i, err;

1406
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1407
	if (err)
1408
		return err;
1409

1410
	/* Tell switchdev if this VLAN is handled in software */
1411
	if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1412
		return -EOPNOTSUPP;
1413

1414
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1415 1416

	/* keep the VLAN unless all ports are excluded */
1417
	vlan.valid = false;
1418
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1419 1420
		if (vlan.member[i] !=
		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
1421
			vlan.valid = true;
1422 1423 1424 1425
			break;
		}
	}

1426
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1427 1428 1429
	if (err)
		return err;

1430
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
1431 1432
}

1433 1434
static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
				   const struct switchdev_obj_port_vlan *vlan)
1435
{
V
Vivien Didelot 已提交
1436
	struct mv88e6xxx_chip *chip = ds->priv;
1437 1438 1439
	u16 pvid, vid;
	int err = 0;

1440
	if (!chip->info->max_vid)
1441 1442
		return -EOPNOTSUPP;

1443
	mutex_lock(&chip->reg_lock);
1444

1445
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
1446 1447 1448
	if (err)
		goto unlock;

1449
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1450
		err = _mv88e6xxx_port_vlan_del(chip, port, vid);
1451 1452 1453 1454
		if (err)
			goto unlock;

		if (vid == pvid) {
1455
			err = mv88e6xxx_port_set_pvid(chip, port, 0);
1456 1457 1458 1459 1460
			if (err)
				goto unlock;
		}
	}

1461
unlock:
1462
	mutex_unlock(&chip->reg_lock);
1463 1464 1465 1466

	return err;
}

1467 1468
static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
				  const unsigned char *addr, u16 vid)
1469
{
V
Vivien Didelot 已提交
1470
	struct mv88e6xxx_chip *chip = ds->priv;
1471
	int err;
1472

1473
	mutex_lock(&chip->reg_lock);
1474 1475
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1476
	mutex_unlock(&chip->reg_lock);
1477 1478

	return err;
1479 1480
}

1481
static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1482
				  const unsigned char *addr, u16 vid)
1483
{
V
Vivien Didelot 已提交
1484
	struct mv88e6xxx_chip *chip = ds->priv;
1485
	int err;
1486

1487
	mutex_lock(&chip->reg_lock);
1488
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1489
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
1490
	mutex_unlock(&chip->reg_lock);
1491

1492
	return err;
1493 1494
}

1495 1496
static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
				      u16 fid, u16 vid, int port,
1497
				      dsa_fdb_dump_cb_t *cb, void *data)
1498
{
1499
	struct mv88e6xxx_atu_entry addr;
1500
	bool is_static;
1501 1502
	int err;

1503
	addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1504
	eth_broadcast_addr(addr.mac);
1505 1506

	do {
1507
		mutex_lock(&chip->reg_lock);
1508
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
1509
		mutex_unlock(&chip->reg_lock);
1510
		if (err)
1511
			return err;
1512

1513
		if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
1514 1515
			break;

1516
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
1517 1518
			continue;

1519 1520
		if (!is_unicast_ether_addr(addr.mac))
			continue;
1521

1522 1523 1524
		is_static = (addr.state ==
			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
		err = cb(addr.mac, vid, is_static, data);
1525 1526
		if (err)
			return err;
1527 1528 1529 1530 1531
	} while (!is_broadcast_ether_addr(addr.mac));

	return err;
}

1532
static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1533
				  dsa_fdb_dump_cb_t *cb, void *data)
1534
{
1535
	struct mv88e6xxx_vtu_entry vlan = {
1536
		.vid = chip->info->max_vid,
1537
	};
1538
	u16 fid;
1539 1540
	int err;

1541
	/* Dump port's default Filtering Information Database (VLAN ID 0) */
1542
	mutex_lock(&chip->reg_lock);
1543
	err = mv88e6xxx_port_get_fid(chip, port, &fid);
1544 1545
	mutex_unlock(&chip->reg_lock);

1546
	if (err)
1547
		return err;
1548

1549
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
1550
	if (err)
1551
		return err;
1552

1553
	/* Dump VLANs' Filtering Information Databases */
1554
	do {
1555
		mutex_lock(&chip->reg_lock);
1556
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1557
		mutex_unlock(&chip->reg_lock);
1558
		if (err)
1559
			return err;
1560 1561 1562 1563

		if (!vlan.valid)
			break;

1564
		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1565
						 cb, data);
1566
		if (err)
1567
			return err;
1568
	} while (vlan.vid < chip->info->max_vid);
1569

1570 1571 1572 1573
	return err;
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1574
				   dsa_fdb_dump_cb_t *cb, void *data)
1575
{
V
Vivien Didelot 已提交
1576
	struct mv88e6xxx_chip *chip = ds->priv;
1577

1578
	return mv88e6xxx_port_db_dump(chip, port, cb, data);
1579 1580
}

1581 1582
static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
				struct net_device *br)
1583
{
1584
	struct dsa_switch *ds;
1585
	int port;
1586
	int dev;
1587
	int err;
1588

1589 1590 1591 1592
	/* 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);
1593
			if (err)
1594
				return err;
1595 1596 1597
		}
	}

1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615
	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;
			}
		}
	}

1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626
	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);
1627
	mutex_unlock(&chip->reg_lock);
1628

1629
	return err;
1630 1631
}

1632 1633
static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
					struct net_device *br)
1634
{
V
Vivien Didelot 已提交
1635
	struct mv88e6xxx_chip *chip = ds->priv;
1636

1637
	mutex_lock(&chip->reg_lock);
1638 1639 1640
	if (mv88e6xxx_bridge_map(chip, br) ||
	    mv88e6xxx_port_vlan_map(chip, port))
		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
1641
	mutex_unlock(&chip->reg_lock);
1642 1643
}

1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673
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);
}

1674 1675 1676 1677 1678 1679 1680 1681
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->reset)
		return chip->info->ops->reset(chip);

	return 0;
}

1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694
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);
	}
}

1695
static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1696
{
1697
	int i, err;
1698

1699
	/* Set all ports to the Disabled state */
1700
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
1701
		err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
1702 1703
		if (err)
			return err;
1704 1705
	}

1706 1707 1708
	/* Wait for transmit queues to drain,
	 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
	 */
1709 1710
	usleep_range(2000, 4000);

1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721
	return 0;
}

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

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

1722
	mv88e6xxx_hardware_reset(chip);
1723

1724
	return mv88e6xxx_software_reset(chip);
1725 1726
}

1727
static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
1728 1729
				   enum mv88e6xxx_frame_mode frame,
				   enum mv88e6xxx_egress_mode egress, u16 etype)
1730 1731 1732
{
	int err;

1733 1734 1735 1736
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
1737 1738 1739
	if (err)
		return err;

1740 1741 1742 1743 1744 1745 1746 1747
	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;
1748 1749
}

1750
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1751
{
1752
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
1753
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
1754
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
1755
}
1756

1757 1758 1759
static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
1760
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
1761
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
1762
}
1763

1764 1765 1766 1767
static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port,
				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
1768 1769
				       MV88E6XXX_EGRESS_MODE_ETHERTYPE,
				       ETH_P_EDSA);
1770
}
1771

1772 1773 1774 1775
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);
1776

1777
	if (dsa_is_user_port(chip->ds, port))
1778
		return mv88e6xxx_set_port_mode_normal(chip, port);
1779

1780 1781 1782
	/* 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);
1783

1784 1785
	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
		return mv88e6xxx_set_port_mode_edsa(chip, port);
1786

1787
	return -EINVAL;
1788 1789
}

1790
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
1791
{
1792
	bool message = dsa_is_dsa_port(chip->ds, port);
1793

1794
	return mv88e6xxx_port_set_message_port(chip, port, message);
1795
}
1796

1797
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
1798
{
1799 1800
	struct dsa_switch *ds = chip->ds;
	bool flood;
1801

1802
	/* Upstream ports flood frames with unknown unicast or multicast DA */
1803
	flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
1804 1805 1806
	if (chip->info->ops->port_set_egress_floods)
		return chip->info->ops->port_set_egress_floods(chip, port,
							       flood, flood);
1807

1808
	return 0;
1809 1810
}

1811 1812 1813
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
1814 1815
	if (chip->info->ops->serdes_power)
		return chip->info->ops->serdes_power(chip, port, on);
1816

1817
	return 0;
1818 1819
}

1820 1821 1822 1823 1824 1825
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

1826
	upstream_port = dsa_upstream_port(ds, port);
1827 1828 1829 1830 1831 1832 1833
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

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

1850 1851 1852
	return 0;
}

1853
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
1854
{
1855
	struct dsa_switch *ds = chip->ds;
1856
	int err;
1857
	u16 reg;
1858

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

	/* 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.
	 */
1888 1889 1890 1891
	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);
1892 1893
	if (err)
		return err;
1894

1895
	err = mv88e6xxx_setup_port_mode(chip, port);
1896 1897
	if (err)
		return err;
1898

1899
	err = mv88e6xxx_setup_egress_floods(chip, port);
1900 1901 1902
	if (err)
		return err;

1903 1904 1905
	/* 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.
1906
	 */
1907 1908 1909 1910 1911
	if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
		err = mv88e6xxx_serdes_power(chip, port, true);
		if (err)
			return err;
	}
1912

1913
	/* Port Control 2: don't force a good FCS, set the maximum frame size to
1914
	 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
1915 1916 1917
	 * 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.
1918
	 */
1919 1920 1921
	err = mv88e6xxx_port_set_map_da(chip, port);
	if (err)
		return err;
1922

1923 1924 1925
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
1926

1927
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
1928
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
1929 1930 1931
	if (err)
		return err;

1932 1933
	if (chip->info->ops->port_set_jumbo_size) {
		err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
1934 1935 1936 1937
		if (err)
			return err;
	}

1938 1939 1940 1941 1942
	/* 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.
	 */
1943
	reg = 1 << port;
1944 1945
	/* Disable learning for CPU port */
	if (dsa_is_cpu_port(ds, port))
1946
		reg = 0;
1947

1948 1949
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
1950 1951
	if (err)
		return err;
1952 1953

	/* Egress rate control 2: disable egress rate control. */
1954 1955
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
				   0x0000);
1956 1957
	if (err)
		return err;
1958

1959 1960
	if (chip->info->ops->port_pause_limit) {
		err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
1961 1962
		if (err)
			return err;
1963
	}
1964

1965 1966 1967 1968 1969 1970
	if (chip->info->ops->port_disable_learn_limit) {
		err = chip->info->ops->port_disable_learn_limit(chip, port);
		if (err)
			return err;
	}

1971 1972
	if (chip->info->ops->port_disable_pri_override) {
		err = chip->info->ops->port_disable_pri_override(chip, port);
1973 1974
		if (err)
			return err;
1975
	}
1976

1977 1978
	if (chip->info->ops->port_tag_remap) {
		err = chip->info->ops->port_tag_remap(chip, port);
1979 1980
		if (err)
			return err;
1981 1982
	}

1983 1984
	if (chip->info->ops->port_egress_rate_limiting) {
		err = chip->info->ops->port_egress_rate_limiting(chip, port);
1985 1986
		if (err)
			return err;
1987 1988
	}

1989
	err = mv88e6xxx_setup_message_port(chip, port);
1990 1991
	if (err)
		return err;
1992

1993
	/* Port based VLAN map: give each port the same default address
1994 1995
	 * database, and allow bidirectional communication between the
	 * CPU and DSA port(s), and the other ports.
1996
	 */
1997
	err = mv88e6xxx_port_set_fid(chip, port, 0);
1998 1999
	if (err)
		return err;
2000

2001
	err = mv88e6xxx_port_vlan_map(chip, port);
2002 2003
	if (err)
		return err;
2004 2005 2006 2007

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

2011 2012 2013 2014
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
2015
	int err;
2016 2017

	mutex_lock(&chip->reg_lock);
2018
	err = mv88e6xxx_serdes_power(chip, port, true);
2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029
	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);
2030 2031
	if (mv88e6xxx_serdes_power(chip, port, false))
		dev_err(chip->dev, "failed to power off SERDES\n");
2032 2033 2034
	mutex_unlock(&chip->reg_lock);
}

2035 2036 2037
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
2038
	struct mv88e6xxx_chip *chip = ds->priv;
2039 2040 2041
	int err;

	mutex_lock(&chip->reg_lock);
2042
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2043 2044 2045 2046 2047
	mutex_unlock(&chip->reg_lock);

	return err;
}

2048
static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
2049
{
2050
	struct dsa_switch *ds = chip->ds;
2051
	int err;
2052

2053
	/* Disable remote management, and set the switch's DSA device number. */
2054 2055
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL2,
				 MV88E6XXX_G1_CTL2_MULTIPLE_CASCADE |
2056
				 (ds->index & 0x1f));
2057 2058 2059
	if (err)
		return err;

2060
	/* Configure the IP ToS mapping registers. */
2061
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_0, 0x0000);
2062
	if (err)
2063
		return err;
2064
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_1, 0x0000);
2065
	if (err)
2066
		return err;
2067
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_2, 0x5555);
2068
	if (err)
2069
		return err;
2070
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_3, 0x5555);
2071
	if (err)
2072
		return err;
2073
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_4, 0xaaaa);
2074
	if (err)
2075
		return err;
2076
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_5, 0xaaaa);
2077
	if (err)
2078
		return err;
2079
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_6, 0xffff);
2080
	if (err)
2081
		return err;
2082
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_7, 0xffff);
2083
	if (err)
2084
		return err;
2085 2086

	/* Configure the IEEE 802.1p priority mapping register. */
2087
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IEEE_PRI, 0xfa41);
2088
	if (err)
2089
		return err;
2090

2091 2092 2093 2094 2095
	/* Initialize the statistics unit */
	err = mv88e6xxx_stats_set_histogram(chip);
	if (err)
		return err;

2096
	return mv88e6xxx_g1_stats_clear(chip);
2097 2098
}

2099
static int mv88e6xxx_setup(struct dsa_switch *ds)
2100
{
V
Vivien Didelot 已提交
2101
	struct mv88e6xxx_chip *chip = ds->priv;
2102
	int err;
2103 2104
	int i;

2105
	chip->ds = ds;
2106
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
2107

2108
	mutex_lock(&chip->reg_lock);
2109

2110
	/* Setup Switch Port Registers */
2111
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2112 2113 2114
		if (dsa_is_unused_port(ds, i))
			continue;

2115 2116 2117 2118 2119 2120 2121
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

	/* Setup Switch Global 1 Registers */
	err = mv88e6xxx_g1_setup(chip);
2122 2123 2124
	if (err)
		goto unlock;

2125
	/* Setup Switch Global 2 Registers */
2126
	if (chip->info->global2_addr) {
2127
		err = mv88e6xxx_g2_setup(chip);
2128 2129 2130
		if (err)
			goto unlock;
	}
2131

2132 2133 2134 2135
	err = mv88e6xxx_irl_setup(chip);
	if (err)
		goto unlock;

2136 2137 2138 2139
	err = mv88e6xxx_mac_setup(chip);
	if (err)
		goto unlock;

2140 2141 2142 2143
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

2144 2145 2146 2147
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

2148 2149 2150 2151
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

2152 2153 2154 2155
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

2156 2157 2158 2159
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

2160 2161 2162 2163
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

2164 2165 2166
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
2167

2168
	/* Setup PTP Hardware Clock and timestamping */
2169 2170 2171 2172
	if (chip->info->ptp_support) {
		err = mv88e6xxx_ptp_setup(chip);
		if (err)
			goto unlock;
2173 2174 2175 2176

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
2177 2178
	}

2179
unlock:
2180
	mutex_unlock(&chip->reg_lock);
2181

2182
	return err;
2183 2184
}

2185
static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
2186
{
2187 2188
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2189 2190
	u16 val;
	int err;
2191

2192 2193 2194
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

2195
	mutex_lock(&chip->reg_lock);
2196
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
2197
	mutex_unlock(&chip->reg_lock);
2198

2199 2200 2201 2202 2203
	if (reg == MII_PHYSID2) {
		/* Some internal PHYS don't have a model number.  Use
		 * the mv88e6390 family model number instead.
		 */
		if (!(val & 0x3f0))
2204
			val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
2205 2206
	}

2207
	return err ? err : val;
2208 2209
}

2210
static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
2211
{
2212 2213
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2214
	int err;
2215

2216 2217 2218
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

2219
	mutex_lock(&chip->reg_lock);
2220
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
2221
	mutex_unlock(&chip->reg_lock);
2222 2223

	return err;
2224 2225
}

2226
static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
2227 2228
				   struct device_node *np,
				   bool external)
2229 2230
{
	static int index;
2231
	struct mv88e6xxx_mdio_bus *mdio_bus;
2232 2233 2234
	struct mii_bus *bus;
	int err;

2235 2236 2237 2238 2239 2240 2241 2242 2243
	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;
	}

2244
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
2245 2246 2247
	if (!bus)
		return -ENOMEM;

2248
	mdio_bus = bus->priv;
2249
	mdio_bus->bus = bus;
2250
	mdio_bus->chip = chip;
2251 2252
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
2253

2254 2255
	if (np) {
		bus->name = np->full_name;
2256
		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
2257 2258 2259 2260 2261 2262 2263
	} 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;
2264
	bus->parent = chip->dev;
2265

2266 2267
	if (np)
		err = of_mdiobus_register(bus, np);
2268 2269 2270
	else
		err = mdiobus_register(bus);
	if (err) {
2271
		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
2272
		return err;
2273
	}
2274 2275 2276 2277 2278

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

	return 0;
2281
}
2282

2283 2284 2285 2286 2287
static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
	{ .compatible = "marvell,mv88e6xxx-mdio-external",
	  .data = (void *)true },
	{ },
};
2288

2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301
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;

		mdiobus_unregister(bus);
	}
}

2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325
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);
2326 2327
			if (err) {
				mv88e6xxx_mdios_unregister(chip);
2328
				return err;
2329
			}
2330 2331 2332 2333
		}
	}

	return 0;
2334 2335
}

2336 2337
static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
2338
	struct mv88e6xxx_chip *chip = ds->priv;
2339 2340 2341 2342 2343 2344 2345

	return chip->eeprom_len;
}

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

2349 2350
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
2351

2352 2353
	mutex_lock(&chip->reg_lock);
	err = chip->info->ops->get_eeprom(chip, eeprom, data);
2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366
	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 已提交
2367
	struct mv88e6xxx_chip *chip = ds->priv;
2368 2369
	int err;

2370 2371 2372
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

2373 2374 2375 2376
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

	mutex_lock(&chip->reg_lock);
2377
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
2378 2379 2380 2381 2382
	mutex_unlock(&chip->reg_lock);

	return err;
}

2383
static const struct mv88e6xxx_ops mv88e6085_ops = {
2384
	/* MV88E6XXX_FAMILY_6097 */
2385
	.irl_init_all = mv88e6352_g2_irl_init_all,
2386
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2387 2388
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2389
	.port_set_link = mv88e6xxx_port_set_link,
2390
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2391
	.port_set_speed = mv88e6185_port_set_speed,
2392
	.port_tag_remap = mv88e6095_port_tag_remap,
2393
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2394
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2395
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2396
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2397
	.port_pause_limit = mv88e6097_port_pause_limit,
2398
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2399
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2400
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2401
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2402 2403
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2404
	.stats_get_stats = mv88e6095_stats_get_stats,
2405 2406
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2407
	.watchdog_ops = &mv88e6097_watchdog_ops,
2408
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2409
	.pot_clear = mv88e6xxx_g2_pot_clear,
2410 2411
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2412
	.reset = mv88e6185_g1_reset,
2413
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2414
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2415 2416 2417
};

static const struct mv88e6xxx_ops mv88e6095_ops = {
2418
	/* MV88E6XXX_FAMILY_6095 */
2419
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2420 2421
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2422
	.port_set_link = mv88e6xxx_port_set_link,
2423
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2424
	.port_set_speed = mv88e6185_port_set_speed,
2425
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2426
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2427
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2428
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2429
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2430 2431
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2432
	.stats_get_stats = mv88e6095_stats_get_stats,
2433
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2434 2435
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2436
	.reset = mv88e6185_g1_reset,
2437
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2438
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2439 2440
};

2441
static const struct mv88e6xxx_ops mv88e6097_ops = {
2442
	/* MV88E6XXX_FAMILY_6097 */
2443
	.irl_init_all = mv88e6352_g2_irl_init_all,
2444 2445 2446 2447 2448 2449
	.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,
2450
	.port_tag_remap = mv88e6095_port_tag_remap,
2451
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2452
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2453
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2454
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2455
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
2456
	.port_pause_limit = mv88e6097_port_pause_limit,
2457
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2458
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2459
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2460
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2461 2462 2463
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
	.stats_get_stats = mv88e6095_stats_get_stats,
2464 2465
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2466
	.watchdog_ops = &mv88e6097_watchdog_ops,
2467
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2468
	.pot_clear = mv88e6xxx_g2_pot_clear,
2469
	.reset = mv88e6352_g1_reset,
2470
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2471
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2472 2473
};

2474
static const struct mv88e6xxx_ops mv88e6123_ops = {
2475
	/* MV88E6XXX_FAMILY_6165 */
2476
	.irl_init_all = mv88e6352_g2_irl_init_all,
2477
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2478 2479
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2480
	.port_set_link = mv88e6xxx_port_set_link,
2481
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2482
	.port_set_speed = mv88e6185_port_set_speed,
2483
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2484
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2485
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2486
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2487
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2488
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2489 2490
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2491
	.stats_get_stats = mv88e6095_stats_get_stats,
2492 2493
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2494
	.watchdog_ops = &mv88e6097_watchdog_ops,
2495
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2496
	.pot_clear = mv88e6xxx_g2_pot_clear,
2497
	.reset = mv88e6352_g1_reset,
2498
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2499
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2500 2501 2502
};

static const struct mv88e6xxx_ops mv88e6131_ops = {
2503
	/* MV88E6XXX_FAMILY_6185 */
2504
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2505 2506
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2507
	.port_set_link = mv88e6xxx_port_set_link,
2508
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2509
	.port_set_speed = mv88e6185_port_set_speed,
2510
	.port_tag_remap = mv88e6095_port_tag_remap,
2511
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2512
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2513
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2514
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2515
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2516
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2517
	.port_pause_limit = mv88e6097_port_pause_limit,
2518
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2519
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2520 2521
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2522
	.stats_get_stats = mv88e6095_stats_get_stats,
2523 2524
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2525
	.watchdog_ops = &mv88e6097_watchdog_ops,
2526
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2527 2528
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2529
	.reset = mv88e6185_g1_reset,
2530
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2531
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2532 2533
};

2534 2535
static const struct mv88e6xxx_ops mv88e6141_ops = {
	/* MV88E6XXX_FAMILY_6341 */
2536
	.irl_init_all = mv88e6352_g2_irl_init_all,
2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549
	.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,
2550
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2551
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2552
	.port_pause_limit = mv88e6097_port_pause_limit,
2553 2554 2555
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
2556
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2557 2558 2559
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
2560 2561
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
2562 2563
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
2564
	.pot_clear = mv88e6xxx_g2_pot_clear,
2565
	.reset = mv88e6352_g1_reset,
2566
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2567
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2568
	.gpio_ops = &mv88e6352_gpio_ops,
2569 2570
};

2571
static const struct mv88e6xxx_ops mv88e6161_ops = {
2572
	/* MV88E6XXX_FAMILY_6165 */
2573
	.irl_init_all = mv88e6352_g2_irl_init_all,
2574
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2575 2576
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2577
	.port_set_link = mv88e6xxx_port_set_link,
2578
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2579
	.port_set_speed = mv88e6185_port_set_speed,
2580
	.port_tag_remap = mv88e6095_port_tag_remap,
2581
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2582
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2583
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2584
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2585
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2586
	.port_pause_limit = mv88e6097_port_pause_limit,
2587
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2588
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2589
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2590
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2591 2592
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2593
	.stats_get_stats = mv88e6095_stats_get_stats,
2594 2595
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2596
	.watchdog_ops = &mv88e6097_watchdog_ops,
2597
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2598
	.pot_clear = mv88e6xxx_g2_pot_clear,
2599
	.reset = mv88e6352_g1_reset,
2600
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2601
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2602 2603 2604
};

static const struct mv88e6xxx_ops mv88e6165_ops = {
2605
	/* MV88E6XXX_FAMILY_6165 */
2606
	.irl_init_all = mv88e6352_g2_irl_init_all,
2607
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2608 2609
	.phy_read = mv88e6165_phy_read,
	.phy_write = mv88e6165_phy_write,
2610
	.port_set_link = mv88e6xxx_port_set_link,
2611
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2612
	.port_set_speed = mv88e6185_port_set_speed,
2613
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2614
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2615
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2616
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2617 2618
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2619
	.stats_get_stats = mv88e6095_stats_get_stats,
2620 2621
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2622
	.watchdog_ops = &mv88e6097_watchdog_ops,
2623
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2624
	.pot_clear = mv88e6xxx_g2_pot_clear,
2625
	.reset = mv88e6352_g1_reset,
2626
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2627
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2628 2629 2630
};

static const struct mv88e6xxx_ops mv88e6171_ops = {
2631
	/* MV88E6XXX_FAMILY_6351 */
2632
	.irl_init_all = mv88e6352_g2_irl_init_all,
2633
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2634 2635
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2636
	.port_set_link = mv88e6xxx_port_set_link,
2637
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2638
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
2639
	.port_set_speed = mv88e6185_port_set_speed,
2640
	.port_tag_remap = mv88e6095_port_tag_remap,
2641
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2642
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2643
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2644
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2645
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2646
	.port_pause_limit = mv88e6097_port_pause_limit,
2647
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2648
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2649
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2650
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2651 2652
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2653
	.stats_get_stats = mv88e6095_stats_get_stats,
2654 2655
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2656
	.watchdog_ops = &mv88e6097_watchdog_ops,
2657
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2658
	.pot_clear = mv88e6xxx_g2_pot_clear,
2659
	.reset = mv88e6352_g1_reset,
2660
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2661
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2662 2663 2664
};

static const struct mv88e6xxx_ops mv88e6172_ops = {
2665
	/* MV88E6XXX_FAMILY_6352 */
2666
	.irl_init_all = mv88e6352_g2_irl_init_all,
2667 2668
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
2669
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2670 2671
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2672
	.port_set_link = mv88e6xxx_port_set_link,
2673
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2674
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
2675
	.port_set_speed = mv88e6352_port_set_speed,
2676
	.port_tag_remap = mv88e6095_port_tag_remap,
2677
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2678
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2679
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2680
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2681
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2682
	.port_pause_limit = mv88e6097_port_pause_limit,
2683
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2684
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2685
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2686
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2687 2688
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2689
	.stats_get_stats = mv88e6095_stats_get_stats,
2690 2691
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2692
	.watchdog_ops = &mv88e6097_watchdog_ops,
2693
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2694
	.pot_clear = mv88e6xxx_g2_pot_clear,
2695
	.reset = mv88e6352_g1_reset,
2696
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2697
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2698
	.serdes_power = mv88e6352_serdes_power,
2699
	.gpio_ops = &mv88e6352_gpio_ops,
2700 2701 2702
};

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

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

static const struct mv88e6xxx_ops mv88e6185_ops = {
2775
	/* MV88E6XXX_FAMILY_6185 */
2776
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2777 2778
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2779
	.port_set_link = mv88e6xxx_port_set_link,
2780
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2781
	.port_set_speed = mv88e6185_port_set_speed,
2782
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2783
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2784
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
2785
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2786
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2787
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2788 2789
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2790
	.stats_get_stats = mv88e6095_stats_get_stats,
2791 2792
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2793
	.watchdog_ops = &mv88e6097_watchdog_ops,
2794
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2795 2796
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2797
	.reset = mv88e6185_g1_reset,
2798
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2799
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2800 2801
};

2802
static const struct mv88e6xxx_ops mv88e6190_ops = {
2803
	/* MV88E6XXX_FAMILY_6390 */
2804
	.irl_init_all = mv88e6390_g2_irl_init_all,
2805 2806
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
2807 2808 2809 2810 2811 2812 2813
	.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,
2814
	.port_tag_remap = mv88e6390_port_tag_remap,
2815
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2816
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2817
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2818
	.port_pause_limit = mv88e6390_port_pause_limit,
2819
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2820
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2821
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
2822
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
2823 2824
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
2825
	.stats_get_stats = mv88e6390_stats_get_stats,
2826 2827
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
2828
	.watchdog_ops = &mv88e6390_watchdog_ops,
2829
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
2830
	.pot_clear = mv88e6xxx_g2_pot_clear,
2831
	.reset = mv88e6352_g1_reset,
2832 2833
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
2834
	.serdes_power = mv88e6390_serdes_power,
2835
	.gpio_ops = &mv88e6352_gpio_ops,
2836 2837 2838
};

static const struct mv88e6xxx_ops mv88e6190x_ops = {
2839
	/* MV88E6XXX_FAMILY_6390 */
2840
	.irl_init_all = mv88e6390_g2_irl_init_all,
2841 2842
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
2843 2844 2845 2846 2847 2848 2849
	.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,
2850
	.port_tag_remap = mv88e6390_port_tag_remap,
2851
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2852
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2853
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2854
	.port_pause_limit = mv88e6390_port_pause_limit,
2855
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2856
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2857
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
2858
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
2859 2860
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
2861
	.stats_get_stats = mv88e6390_stats_get_stats,
2862 2863
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
2864
	.watchdog_ops = &mv88e6390_watchdog_ops,
2865
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
2866
	.pot_clear = mv88e6xxx_g2_pot_clear,
2867
	.reset = mv88e6352_g1_reset,
2868 2869
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
2870
	.serdes_power = mv88e6390_serdes_power,
2871
	.gpio_ops = &mv88e6352_gpio_ops,
2872 2873 2874
};

static const struct mv88e6xxx_ops mv88e6191_ops = {
2875
	/* MV88E6XXX_FAMILY_6390 */
2876
	.irl_init_all = mv88e6390_g2_irl_init_all,
2877 2878
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
2879 2880 2881 2882 2883 2884 2885
	.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,
2886
	.port_tag_remap = mv88e6390_port_tag_remap,
2887
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2888
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2889
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2890
	.port_pause_limit = mv88e6390_port_pause_limit,
2891
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2892
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2893
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
2894
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
2895 2896
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
2897
	.stats_get_stats = mv88e6390_stats_get_stats,
2898 2899
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
2900
	.watchdog_ops = &mv88e6390_watchdog_ops,
2901
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
2902
	.pot_clear = mv88e6xxx_g2_pot_clear,
2903
	.reset = mv88e6352_g1_reset,
2904 2905
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
2906
	.serdes_power = mv88e6390_serdes_power,
2907 2908
};

2909
static const struct mv88e6xxx_ops mv88e6240_ops = {
2910
	/* MV88E6XXX_FAMILY_6352 */
2911
	.irl_init_all = mv88e6352_g2_irl_init_all,
2912 2913
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
2914
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2915 2916
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2917
	.port_set_link = mv88e6xxx_port_set_link,
2918
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2919
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
2920
	.port_set_speed = mv88e6352_port_set_speed,
2921
	.port_tag_remap = mv88e6095_port_tag_remap,
2922
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2923
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2924
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2925
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2926
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2927
	.port_pause_limit = mv88e6097_port_pause_limit,
2928
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2929
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2930
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2931
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2932 2933
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2934
	.stats_get_stats = mv88e6095_stats_get_stats,
2935 2936
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2937
	.watchdog_ops = &mv88e6097_watchdog_ops,
2938
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2939
	.pot_clear = mv88e6xxx_g2_pot_clear,
2940
	.reset = mv88e6352_g1_reset,
2941
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2942
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2943
	.serdes_power = mv88e6352_serdes_power,
2944
	.gpio_ops = &mv88e6352_gpio_ops,
2945
	.avb_ops = &mv88e6352_avb_ops,
2946 2947
};

2948
static const struct mv88e6xxx_ops mv88e6290_ops = {
2949
	/* MV88E6XXX_FAMILY_6390 */
2950
	.irl_init_all = mv88e6390_g2_irl_init_all,
2951 2952
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
2953 2954 2955 2956 2957 2958 2959
	.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,
2960
	.port_tag_remap = mv88e6390_port_tag_remap,
2961
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2962
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2963
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2964
	.port_pause_limit = mv88e6390_port_pause_limit,
2965
	.port_set_cmode = mv88e6390x_port_set_cmode,
2966
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2967
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2968
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
2969
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
2970 2971
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
2972
	.stats_get_stats = mv88e6390_stats_get_stats,
2973 2974
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
2975
	.watchdog_ops = &mv88e6390_watchdog_ops,
2976
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
2977
	.pot_clear = mv88e6xxx_g2_pot_clear,
2978
	.reset = mv88e6352_g1_reset,
2979 2980
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
2981
	.serdes_power = mv88e6390_serdes_power,
2982
	.gpio_ops = &mv88e6352_gpio_ops,
2983
	.avb_ops = &mv88e6390_avb_ops,
2984 2985
};

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

static const struct mv88e6xxx_ops mv88e6321_ops = {
3023
	/* MV88E6XXX_FAMILY_6320 */
3024
	.irl_init_all = mv88e6352_g2_irl_init_all,
3025 3026
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3027
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3028 3029
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3030
	.port_set_link = mv88e6xxx_port_set_link,
3031
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3032
	.port_set_speed = mv88e6185_port_set_speed,
3033
	.port_tag_remap = mv88e6095_port_tag_remap,
3034
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3035
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3036
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3037
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3038
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3039
	.port_pause_limit = mv88e6097_port_pause_limit,
3040
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3041
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3042
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3043
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3044 3045
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3046
	.stats_get_stats = mv88e6320_stats_get_stats,
3047 3048
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3049
	.reset = mv88e6352_g1_reset,
3050
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3051
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3052
	.gpio_ops = &mv88e6352_gpio_ops,
3053
	.avb_ops = &mv88e6352_avb_ops,
3054 3055
};

3056 3057
static const struct mv88e6xxx_ops mv88e6341_ops = {
	/* MV88E6XXX_FAMILY_6341 */
3058
	.irl_init_all = mv88e6352_g2_irl_init_all,
3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071
	.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,
3072
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3073
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3074
	.port_pause_limit = mv88e6097_port_pause_limit,
3075 3076 3077
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3078
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3079 3080 3081
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
3082 3083
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3084 3085
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
3086
	.pot_clear = mv88e6xxx_g2_pot_clear,
3087
	.reset = mv88e6352_g1_reset,
3088
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3089
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3090
	.gpio_ops = &mv88e6352_gpio_ops,
3091
	.avb_ops = &mv88e6390_avb_ops,
3092 3093
};

3094
static const struct mv88e6xxx_ops mv88e6350_ops = {
3095
	/* MV88E6XXX_FAMILY_6351 */
3096
	.irl_init_all = mv88e6352_g2_irl_init_all,
3097
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3098 3099
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3100
	.port_set_link = mv88e6xxx_port_set_link,
3101
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3102
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3103
	.port_set_speed = mv88e6185_port_set_speed,
3104
	.port_tag_remap = mv88e6095_port_tag_remap,
3105
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3106
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3107
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3108
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3109
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3110
	.port_pause_limit = mv88e6097_port_pause_limit,
3111
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3112
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3113
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3114
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3115 3116
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3117
	.stats_get_stats = mv88e6095_stats_get_stats,
3118 3119
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3120
	.watchdog_ops = &mv88e6097_watchdog_ops,
3121
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3122
	.pot_clear = mv88e6xxx_g2_pot_clear,
3123
	.reset = mv88e6352_g1_reset,
3124
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3125
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3126 3127 3128
};

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

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

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

static const struct mv88e6xxx_ops mv88e6390x_ops = {
3243
	/* MV88E6XXX_FAMILY_6390 */
3244
	.irl_init_all = mv88e6390_g2_irl_init_all,
3245 3246
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3247 3248 3249 3250 3251 3252 3253
	.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,
3254
	.port_tag_remap = mv88e6390_port_tag_remap,
3255
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3256
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3257
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3258
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3259
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3260
	.port_pause_limit = mv88e6390_port_pause_limit,
3261
	.port_set_cmode = mv88e6390x_port_set_cmode,
3262
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3263
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3264
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3265
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3266 3267
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3268
	.stats_get_stats = mv88e6390_stats_get_stats,
3269 3270
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3271
	.watchdog_ops = &mv88e6390_watchdog_ops,
3272
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3273
	.pot_clear = mv88e6xxx_g2_pot_clear,
3274
	.reset = mv88e6352_g1_reset,
3275 3276
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3277
	.serdes_power = mv88e6390_serdes_power,
3278
	.gpio_ops = &mv88e6352_gpio_ops,
3279
	.avb_ops = &mv88e6390_avb_ops,
3280 3281
};

3282 3283
static const struct mv88e6xxx_info mv88e6xxx_table[] = {
	[MV88E6085] = {
3284
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
3285 3286 3287 3288
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6085",
		.num_databases = 4096,
		.num_ports = 10,
3289
		.max_vid = 4095,
3290
		.port_base_addr = 0x10,
3291
		.global1_addr = 0x1b,
3292
		.global2_addr = 0x1c,
3293
		.age_time_coeff = 15000,
3294
		.g1_irqs = 8,
3295
		.g2_irqs = 10,
3296
		.atu_move_port_mask = 0xf,
3297
		.pvt = true,
3298
		.multi_chip = true,
3299
		.tag_protocol = DSA_TAG_PROTO_DSA,
3300
		.ops = &mv88e6085_ops,
3301 3302 3303
	},

	[MV88E6095] = {
3304
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
3305 3306 3307 3308
		.family = MV88E6XXX_FAMILY_6095,
		.name = "Marvell 88E6095/88E6095F",
		.num_databases = 256,
		.num_ports = 11,
3309
		.max_vid = 4095,
3310
		.port_base_addr = 0x10,
3311
		.global1_addr = 0x1b,
3312
		.global2_addr = 0x1c,
3313
		.age_time_coeff = 15000,
3314
		.g1_irqs = 8,
3315
		.atu_move_port_mask = 0xf,
3316
		.multi_chip = true,
3317
		.tag_protocol = DSA_TAG_PROTO_DSA,
3318
		.ops = &mv88e6095_ops,
3319 3320
	},

3321
	[MV88E6097] = {
3322
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
3323 3324 3325 3326
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6097/88E6097F",
		.num_databases = 4096,
		.num_ports = 11,
3327
		.max_vid = 4095,
3328 3329
		.port_base_addr = 0x10,
		.global1_addr = 0x1b,
3330
		.global2_addr = 0x1c,
3331
		.age_time_coeff = 15000,
3332
		.g1_irqs = 8,
3333
		.g2_irqs = 10,
3334
		.atu_move_port_mask = 0xf,
3335
		.pvt = true,
3336
		.multi_chip = true,
3337
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3338 3339 3340
		.ops = &mv88e6097_ops,
	},

3341
	[MV88E6123] = {
3342
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
3343 3344 3345 3346
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6123",
		.num_databases = 4096,
		.num_ports = 3,
3347
		.max_vid = 4095,
3348
		.port_base_addr = 0x10,
3349
		.global1_addr = 0x1b,
3350
		.global2_addr = 0x1c,
3351
		.age_time_coeff = 15000,
3352
		.g1_irqs = 9,
3353
		.g2_irqs = 10,
3354
		.atu_move_port_mask = 0xf,
3355
		.pvt = true,
3356
		.multi_chip = true,
3357
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3358
		.ops = &mv88e6123_ops,
3359 3360 3361
	},

	[MV88E6131] = {
3362
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
3363 3364 3365 3366
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6131",
		.num_databases = 256,
		.num_ports = 8,
3367
		.max_vid = 4095,
3368
		.port_base_addr = 0x10,
3369
		.global1_addr = 0x1b,
3370
		.global2_addr = 0x1c,
3371
		.age_time_coeff = 15000,
3372
		.g1_irqs = 9,
3373
		.atu_move_port_mask = 0xf,
3374
		.multi_chip = true,
3375
		.tag_protocol = DSA_TAG_PROTO_DSA,
3376
		.ops = &mv88e6131_ops,
3377 3378
	},

3379
	[MV88E6141] = {
3380
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
3381 3382 3383 3384
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
		.num_ports = 6,
3385
		.num_gpio = 11,
3386
		.max_vid = 4095,
3387 3388
		.port_base_addr = 0x10,
		.global1_addr = 0x1b,
3389
		.global2_addr = 0x1c,
3390 3391
		.age_time_coeff = 3750,
		.atu_move_port_mask = 0x1f,
3392
		.g2_irqs = 10,
3393
		.pvt = true,
3394
		.multi_chip = true,
3395 3396 3397 3398
		.tag_protocol = DSA_TAG_PROTO_EDSA,
		.ops = &mv88e6141_ops,
	},

3399
	[MV88E6161] = {
3400
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
3401 3402 3403 3404
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6161",
		.num_databases = 4096,
		.num_ports = 6,
3405
		.max_vid = 4095,
3406
		.port_base_addr = 0x10,
3407
		.global1_addr = 0x1b,
3408
		.global2_addr = 0x1c,
3409
		.age_time_coeff = 15000,
3410
		.g1_irqs = 9,
3411
		.g2_irqs = 10,
3412
		.atu_move_port_mask = 0xf,
3413
		.pvt = true,
3414
		.multi_chip = true,
3415
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3416
		.ops = &mv88e6161_ops,
3417 3418 3419
	},

	[MV88E6165] = {
3420
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
3421 3422 3423 3424
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6165",
		.num_databases = 4096,
		.num_ports = 6,
3425
		.max_vid = 4095,
3426
		.port_base_addr = 0x10,
3427
		.global1_addr = 0x1b,
3428
		.global2_addr = 0x1c,
3429
		.age_time_coeff = 15000,
3430
		.g1_irqs = 9,
3431
		.g2_irqs = 10,
3432
		.atu_move_port_mask = 0xf,
3433
		.pvt = true,
3434
		.multi_chip = true,
3435
		.tag_protocol = DSA_TAG_PROTO_DSA,
3436
		.ops = &mv88e6165_ops,
3437 3438 3439
	},

	[MV88E6171] = {
3440
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
3441 3442 3443 3444
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6171",
		.num_databases = 4096,
		.num_ports = 7,
3445
		.max_vid = 4095,
3446
		.port_base_addr = 0x10,
3447
		.global1_addr = 0x1b,
3448
		.global2_addr = 0x1c,
3449
		.age_time_coeff = 15000,
3450
		.g1_irqs = 9,
3451
		.g2_irqs = 10,
3452
		.atu_move_port_mask = 0xf,
3453
		.pvt = true,
3454
		.multi_chip = true,
3455
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3456
		.ops = &mv88e6171_ops,
3457 3458 3459
	},

	[MV88E6172] = {
3460
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
3461 3462 3463 3464
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6172",
		.num_databases = 4096,
		.num_ports = 7,
3465
		.num_gpio = 15,
3466
		.max_vid = 4095,
3467
		.port_base_addr = 0x10,
3468
		.global1_addr = 0x1b,
3469
		.global2_addr = 0x1c,
3470
		.age_time_coeff = 15000,
3471
		.g1_irqs = 9,
3472
		.g2_irqs = 10,
3473
		.atu_move_port_mask = 0xf,
3474
		.pvt = true,
3475
		.multi_chip = true,
3476
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3477
		.ops = &mv88e6172_ops,
3478 3479 3480
	},

	[MV88E6175] = {
3481
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
3482 3483 3484 3485
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6175",
		.num_databases = 4096,
		.num_ports = 7,
3486
		.max_vid = 4095,
3487
		.port_base_addr = 0x10,
3488
		.global1_addr = 0x1b,
3489
		.global2_addr = 0x1c,
3490
		.age_time_coeff = 15000,
3491
		.g1_irqs = 9,
3492
		.g2_irqs = 10,
3493
		.atu_move_port_mask = 0xf,
3494
		.pvt = true,
3495
		.multi_chip = true,
3496
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3497
		.ops = &mv88e6175_ops,
3498 3499 3500
	},

	[MV88E6176] = {
3501
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
3502 3503 3504 3505
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6176",
		.num_databases = 4096,
		.num_ports = 7,
3506
		.num_gpio = 15,
3507
		.max_vid = 4095,
3508
		.port_base_addr = 0x10,
3509
		.global1_addr = 0x1b,
3510
		.global2_addr = 0x1c,
3511
		.age_time_coeff = 15000,
3512
		.g1_irqs = 9,
3513
		.g2_irqs = 10,
3514
		.atu_move_port_mask = 0xf,
3515
		.pvt = true,
3516
		.multi_chip = true,
3517
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3518
		.ops = &mv88e6176_ops,
3519 3520 3521
	},

	[MV88E6185] = {
3522
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
3523 3524 3525 3526
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6185",
		.num_databases = 256,
		.num_ports = 10,
3527
		.max_vid = 4095,
3528
		.port_base_addr = 0x10,
3529
		.global1_addr = 0x1b,
3530
		.global2_addr = 0x1c,
3531
		.age_time_coeff = 15000,
3532
		.g1_irqs = 8,
3533
		.atu_move_port_mask = 0xf,
3534
		.multi_chip = true,
3535
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3536
		.ops = &mv88e6185_ops,
3537 3538
	},

3539
	[MV88E6190] = {
3540
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
3541 3542 3543 3544
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3545
		.num_gpio = 16,
3546
		.max_vid = 8191,
3547 3548
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3549
		.global2_addr = 0x1c,
3550
		.tag_protocol = DSA_TAG_PROTO_DSA,
3551
		.age_time_coeff = 3750,
3552
		.g1_irqs = 9,
3553
		.g2_irqs = 14,
3554
		.pvt = true,
3555
		.multi_chip = true,
3556
		.atu_move_port_mask = 0x1f,
3557 3558 3559 3560
		.ops = &mv88e6190_ops,
	},

	[MV88E6190X] = {
3561
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
3562 3563 3564 3565
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3566
		.num_gpio = 16,
3567
		.max_vid = 8191,
3568 3569
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3570
		.global2_addr = 0x1c,
3571
		.age_time_coeff = 3750,
3572
		.g1_irqs = 9,
3573
		.g2_irqs = 14,
3574
		.atu_move_port_mask = 0x1f,
3575
		.pvt = true,
3576
		.multi_chip = true,
3577
		.tag_protocol = DSA_TAG_PROTO_DSA,
3578 3579 3580 3581
		.ops = &mv88e6190x_ops,
	},

	[MV88E6191] = {
3582
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
3583 3584 3585 3586
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6191",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3587
		.max_vid = 8191,
3588 3589
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3590
		.global2_addr = 0x1c,
3591
		.age_time_coeff = 3750,
3592
		.g1_irqs = 9,
3593
		.g2_irqs = 14,
3594
		.atu_move_port_mask = 0x1f,
3595
		.pvt = true,
3596
		.multi_chip = true,
3597
		.tag_protocol = DSA_TAG_PROTO_DSA,
3598
		.ptp_support = true,
3599
		.ops = &mv88e6191_ops,
3600 3601
	},

3602
	[MV88E6240] = {
3603
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
3604 3605 3606 3607
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6240",
		.num_databases = 4096,
		.num_ports = 7,
3608
		.num_gpio = 15,
3609
		.max_vid = 4095,
3610
		.port_base_addr = 0x10,
3611
		.global1_addr = 0x1b,
3612
		.global2_addr = 0x1c,
3613
		.age_time_coeff = 15000,
3614
		.g1_irqs = 9,
3615
		.g2_irqs = 10,
3616
		.atu_move_port_mask = 0xf,
3617
		.pvt = true,
3618
		.multi_chip = true,
3619
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3620
		.ptp_support = true,
3621
		.ops = &mv88e6240_ops,
3622 3623
	},

3624
	[MV88E6290] = {
3625
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
3626 3627 3628 3629
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6290",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3630
		.num_gpio = 16,
3631
		.max_vid = 8191,
3632 3633
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3634
		.global2_addr = 0x1c,
3635
		.age_time_coeff = 3750,
3636
		.g1_irqs = 9,
3637
		.g2_irqs = 14,
3638
		.atu_move_port_mask = 0x1f,
3639
		.pvt = true,
3640
		.multi_chip = true,
3641
		.tag_protocol = DSA_TAG_PROTO_DSA,
3642
		.ptp_support = true,
3643 3644 3645
		.ops = &mv88e6290_ops,
	},

3646
	[MV88E6320] = {
3647
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
3648 3649 3650 3651
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6320",
		.num_databases = 4096,
		.num_ports = 7,
3652
		.num_gpio = 15,
3653
		.max_vid = 4095,
3654
		.port_base_addr = 0x10,
3655
		.global1_addr = 0x1b,
3656
		.global2_addr = 0x1c,
3657
		.age_time_coeff = 15000,
3658
		.g1_irqs = 8,
3659
		.atu_move_port_mask = 0xf,
3660
		.pvt = true,
3661
		.multi_chip = true,
3662
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3663
		.ptp_support = true,
3664
		.ops = &mv88e6320_ops,
3665 3666 3667
	},

	[MV88E6321] = {
3668
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
3669 3670 3671 3672
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6321",
		.num_databases = 4096,
		.num_ports = 7,
3673
		.num_gpio = 15,
3674
		.max_vid = 4095,
3675
		.port_base_addr = 0x10,
3676
		.global1_addr = 0x1b,
3677
		.global2_addr = 0x1c,
3678
		.age_time_coeff = 15000,
3679
		.g1_irqs = 8,
3680
		.atu_move_port_mask = 0xf,
3681
		.multi_chip = true,
3682
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3683
		.ptp_support = true,
3684
		.ops = &mv88e6321_ops,
3685 3686
	},

3687
	[MV88E6341] = {
3688
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
3689 3690 3691 3692
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
		.num_ports = 6,
3693
		.num_gpio = 11,
3694
		.max_vid = 4095,
3695 3696
		.port_base_addr = 0x10,
		.global1_addr = 0x1b,
3697
		.global2_addr = 0x1c,
3698
		.age_time_coeff = 3750,
3699
		.atu_move_port_mask = 0x1f,
3700
		.g2_irqs = 10,
3701
		.pvt = true,
3702
		.multi_chip = true,
3703
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3704
		.ptp_support = true,
3705 3706 3707
		.ops = &mv88e6341_ops,
	},

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

	[MV88E6351] = {
3729
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
3730 3731 3732 3733
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6351",
		.num_databases = 4096,
		.num_ports = 7,
3734
		.max_vid = 4095,
3735
		.port_base_addr = 0x10,
3736
		.global1_addr = 0x1b,
3737
		.global2_addr = 0x1c,
3738
		.age_time_coeff = 15000,
3739
		.g1_irqs = 9,
3740
		.g2_irqs = 10,
3741
		.atu_move_port_mask = 0xf,
3742
		.pvt = true,
3743
		.multi_chip = true,
3744
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3745
		.ops = &mv88e6351_ops,
3746 3747 3748
	},

	[MV88E6352] = {
3749
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
3750 3751 3752 3753
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6352",
		.num_databases = 4096,
		.num_ports = 7,
3754
		.num_gpio = 15,
3755
		.max_vid = 4095,
3756
		.port_base_addr = 0x10,
3757
		.global1_addr = 0x1b,
3758
		.global2_addr = 0x1c,
3759
		.age_time_coeff = 15000,
3760
		.g1_irqs = 9,
3761
		.g2_irqs = 10,
3762
		.atu_move_port_mask = 0xf,
3763
		.pvt = true,
3764
		.multi_chip = true,
3765
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3766
		.ptp_support = true,
3767
		.ops = &mv88e6352_ops,
3768
	},
3769
	[MV88E6390] = {
3770
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
3771 3772 3773 3774
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3775
		.num_gpio = 16,
3776
		.max_vid = 8191,
3777 3778
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3779
		.global2_addr = 0x1c,
3780
		.age_time_coeff = 3750,
3781
		.g1_irqs = 9,
3782
		.g2_irqs = 14,
3783
		.atu_move_port_mask = 0x1f,
3784
		.pvt = true,
3785
		.multi_chip = true,
3786
		.tag_protocol = DSA_TAG_PROTO_DSA,
3787
		.ptp_support = true,
3788 3789 3790
		.ops = &mv88e6390_ops,
	},
	[MV88E6390X] = {
3791
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
3792 3793 3794 3795
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3796
		.num_gpio = 16,
3797
		.max_vid = 8191,
3798 3799
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3800
		.global2_addr = 0x1c,
3801
		.age_time_coeff = 3750,
3802
		.g1_irqs = 9,
3803
		.g2_irqs = 14,
3804
		.atu_move_port_mask = 0x1f,
3805
		.pvt = true,
3806
		.multi_chip = true,
3807
		.tag_protocol = DSA_TAG_PROTO_DSA,
3808
		.ptp_support = true,
3809 3810
		.ops = &mv88e6390x_ops,
	},
3811 3812
};

3813
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
3814
{
3815
	int i;
3816

3817 3818 3819
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
3820 3821 3822 3823

	return NULL;
}

3824
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
3825 3826
{
	const struct mv88e6xxx_info *info;
3827 3828 3829
	unsigned int prod_num, rev;
	u16 id;
	int err;
3830

3831
	mutex_lock(&chip->reg_lock);
3832
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
3833 3834 3835
	mutex_unlock(&chip->reg_lock);
	if (err)
		return err;
3836

3837 3838
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
3839 3840 3841 3842 3843

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

3844
	/* Update the compatible info with the probed one */
3845
	chip->info = info;
3846

3847 3848 3849 3850
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

3851 3852
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
3853 3854 3855 3856

	return 0;
}

3857
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
3858
{
3859
	struct mv88e6xxx_chip *chip;
3860

3861 3862
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
3863 3864
		return NULL;

3865
	chip->dev = dev;
3866

3867
	mutex_init(&chip->reg_lock);
3868
	INIT_LIST_HEAD(&chip->mdios);
3869

3870
	return chip;
3871 3872
}

3873
static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
3874 3875
			      struct mii_bus *bus, int sw_addr)
{
3876
	if (sw_addr == 0)
3877
		chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
3878
	else if (chip->info->multi_chip)
3879
		chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
3880 3881 3882
	else
		return -EINVAL;

3883 3884
	chip->bus = bus;
	chip->sw_addr = sw_addr;
3885 3886 3887 3888

	return 0;
}

3889 3890
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
							int port)
3891
{
V
Vivien Didelot 已提交
3892
	struct mv88e6xxx_chip *chip = ds->priv;
3893

3894
	return chip->info->tag_protocol;
3895 3896
}

3897
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
3898 3899 3900
static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
				       struct device *host_dev, int sw_addr,
				       void **priv)
3901
{
3902
	struct mv88e6xxx_chip *chip;
3903
	struct mii_bus *bus;
3904
	int err;
3905

3906
	bus = dsa_host_dev_to_mii_bus(host_dev);
3907 3908 3909
	if (!bus)
		return NULL;

3910 3911
	chip = mv88e6xxx_alloc_chip(dsa_dev);
	if (!chip)
3912 3913
		return NULL;

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

3917
	err = mv88e6xxx_smi_init(chip, bus, sw_addr);
3918 3919 3920
	if (err)
		goto free;

3921
	err = mv88e6xxx_detect(chip);
3922
	if (err)
3923
		goto free;
3924

3925 3926 3927 3928 3929 3930
	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_switch_reset(chip);
	mutex_unlock(&chip->reg_lock);
	if (err)
		goto free;

3931 3932
	mv88e6xxx_phy_init(chip);

3933
	err = mv88e6xxx_mdios_register(chip, NULL);
3934
	if (err)
3935
		goto free;
3936

3937
	*priv = chip;
3938

3939
	return chip->info->name;
3940
free:
3941
	devm_kfree(dsa_dev, chip);
3942 3943

	return NULL;
3944
}
3945
#endif
3946

3947
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
3948
				      const struct switchdev_obj_port_mdb *mdb)
3949 3950 3951 3952 3953 3954 3955 3956 3957
{
	/* 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,
3958
				   const struct switchdev_obj_port_mdb *mdb)
3959
{
V
Vivien Didelot 已提交
3960
	struct mv88e6xxx_chip *chip = ds->priv;
3961 3962 3963

	mutex_lock(&chip->reg_lock);
	if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
3964
					 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
3965 3966
		dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
			port);
3967 3968 3969 3970 3971 3972
	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 已提交
3973
	struct mv88e6xxx_chip *chip = ds->priv;
3974 3975 3976 3977
	int err;

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
3978
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
3979 3980 3981 3982 3983
	mutex_unlock(&chip->reg_lock);

	return err;
}

3984
static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
3985
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
3986
	.probe			= mv88e6xxx_drv_probe,
3987
#endif
3988
	.get_tag_protocol	= mv88e6xxx_get_tag_protocol,
3989 3990 3991 3992 3993
	.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,
3994 3995
	.port_enable		= mv88e6xxx_port_enable,
	.port_disable		= mv88e6xxx_port_disable,
V
Vivien Didelot 已提交
3996 3997
	.get_mac_eee		= mv88e6xxx_get_mac_eee,
	.set_mac_eee		= mv88e6xxx_set_mac_eee,
3998
	.get_eeprom_len		= mv88e6xxx_get_eeprom_len,
3999 4000 4001 4002
	.get_eeprom		= mv88e6xxx_get_eeprom,
	.set_eeprom		= mv88e6xxx_set_eeprom,
	.get_regs_len		= mv88e6xxx_get_regs_len,
	.get_regs		= mv88e6xxx_get_regs,
4003
	.set_ageing_time	= mv88e6xxx_set_ageing_time,
4004 4005 4006
	.port_bridge_join	= mv88e6xxx_port_bridge_join,
	.port_bridge_leave	= mv88e6xxx_port_bridge_leave,
	.port_stp_state_set	= mv88e6xxx_port_stp_state_set,
4007
	.port_fast_age		= mv88e6xxx_port_fast_age,
4008 4009 4010 4011 4012 4013 4014
	.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,
4015 4016 4017
	.port_mdb_prepare       = mv88e6xxx_port_mdb_prepare,
	.port_mdb_add           = mv88e6xxx_port_mdb_add,
	.port_mdb_del           = mv88e6xxx_port_mdb_del,
4018 4019
	.crosschip_bridge_join	= mv88e6xxx_crosschip_bridge_join,
	.crosschip_bridge_leave	= mv88e6xxx_crosschip_bridge_leave,
4020 4021 4022 4023 4024
	.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,
4025 4026
};

4027 4028 4029 4030
static struct dsa_switch_driver mv88e6xxx_switch_drv = {
	.ops			= &mv88e6xxx_switch_ops,
};

4031
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
4032
{
4033
	struct device *dev = chip->dev;
4034 4035
	struct dsa_switch *ds;

4036
	ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
4037 4038 4039
	if (!ds)
		return -ENOMEM;

4040
	ds->priv = chip;
4041
	ds->ops = &mv88e6xxx_switch_ops;
4042 4043
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
4044 4045 4046

	dev_set_drvdata(dev, ds);

4047
	return dsa_register_switch(ds);
4048 4049
}

4050
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
4051
{
4052
	dsa_unregister_switch(chip->ds);
4053 4054
}

4055
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
4056
{
4057
	struct device *dev = &mdiodev->dev;
4058
	struct device_node *np = dev->of_node;
4059
	const struct mv88e6xxx_info *compat_info;
4060
	struct mv88e6xxx_chip *chip;
4061
	u32 eeprom_len;
4062
	int err;
4063

4064 4065 4066 4067
	compat_info = of_device_get_match_data(dev);
	if (!compat_info)
		return -EINVAL;

4068 4069
	chip = mv88e6xxx_alloc_chip(dev);
	if (!chip)
4070 4071
		return -ENOMEM;

4072
	chip->info = compat_info;
4073

4074
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
4075 4076
	if (err)
		return err;
4077

4078 4079 4080 4081
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
	if (IS_ERR(chip->reset))
		return PTR_ERR(chip->reset);

4082
	err = mv88e6xxx_detect(chip);
4083 4084
	if (err)
		return err;
4085

4086 4087
	mv88e6xxx_phy_init(chip);

4088
	if (chip->info->ops->get_eeprom &&
4089
	    !of_property_read_u32(np, "eeprom-length", &eeprom_len))
4090
		chip->eeprom_len = eeprom_len;
4091

4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103
	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;
	}

4104 4105 4106 4107 4108 4109
	/* Has to be performed before the MDIO bus is created, because
	 * the PHYs will link there interrupts to these interrupt
	 * controllers
	 */
	mutex_lock(&chip->reg_lock);
	if (chip->irq > 0)
4110
		err = mv88e6xxx_g1_irq_setup(chip);
4111 4112 4113
	else
		err = mv88e6xxx_irq_poll_setup(chip);
	mutex_unlock(&chip->reg_lock);
4114

4115 4116
	if (err)
		goto out;
4117

4118 4119
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
4120
		if (err)
4121
			goto out_g1_irq;
4122 4123
	}

4124 4125 4126 4127 4128 4129 4130 4131
	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;

4132
	err = mv88e6xxx_mdios_register(chip, np);
4133
	if (err)
4134
		goto out_g1_vtu_prob_irq;
4135

4136
	err = mv88e6xxx_register_switch(chip);
4137 4138
	if (err)
		goto out_mdio;
4139

4140
	return 0;
4141 4142

out_mdio:
4143
	mv88e6xxx_mdios_unregister(chip);
4144
out_g1_vtu_prob_irq:
4145
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
4146
out_g1_atu_prob_irq:
4147
	mv88e6xxx_g1_atu_prob_irq_free(chip);
4148
out_g2_irq:
4149
	if (chip->info->g2_irqs > 0)
4150 4151
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
4152 4153
	mutex_lock(&chip->reg_lock);
	if (chip->irq > 0)
4154
		mv88e6xxx_g1_irq_free(chip);
4155 4156 4157
	else
		mv88e6xxx_irq_poll_free(chip);
	mutex_unlock(&chip->reg_lock);
4158 4159
out:
	return err;
4160
}
4161 4162 4163 4164

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

4167 4168
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
4169
		mv88e6xxx_ptp_free(chip);
4170
	}
4171

4172
	mv88e6xxx_phy_destroy(chip);
4173
	mv88e6xxx_unregister_switch(chip);
4174
	mv88e6xxx_mdios_unregister(chip);
4175

4176
	if (chip->irq > 0) {
4177
		mv88e6xxx_g1_vtu_prob_irq_free(chip);
4178
		mv88e6xxx_g1_atu_prob_irq_free(chip);
4179
		if (chip->info->g2_irqs > 0)
4180
			mv88e6xxx_g2_irq_free(chip);
4181
		mutex_lock(&chip->reg_lock);
4182
		mv88e6xxx_g1_irq_free(chip);
4183
		mutex_unlock(&chip->reg_lock);
4184
	}
4185 4186 4187
}

static const struct of_device_id mv88e6xxx_of_match[] = {
4188 4189 4190 4191
	{
		.compatible = "marvell,mv88e6085",
		.data = &mv88e6xxx_table[MV88E6085],
	},
4192 4193 4194 4195
	{
		.compatible = "marvell,mv88e6190",
		.data = &mv88e6xxx_table[MV88E6190],
	},
4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211
	{ /* 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)
{
4212
	register_switch_driver(&mv88e6xxx_switch_drv);
4213 4214
	return mdio_driver_register(&mv88e6xxx_driver);
}
4215 4216 4217 4218
module_init(mv88e6xxx_init);

static void __exit mv88e6xxx_cleanup(void)
{
4219
	mdio_driver_unregister(&mv88e6xxx_driver);
4220
	unregister_switch_driver(&mv88e6xxx_switch_drv);
4221 4222
}
module_exit(mv88e6xxx_cleanup);
4223 4224 4225 4226

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