chip.c 117.9 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 729 730 731 732 733

	if (chip->info->ops->stats_get_strings)
		chip->info->ops->stats_get_strings(chip, data);
}

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

745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766
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);
}

static int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
{
	struct mv88e6xxx_chip *chip = ds->priv;

	if (chip->info->ops->stats_get_sset_count)
		return chip->info->ops->stats_get_sset_count(chip);

	return 0;
}

767
static void mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
768 769
				      uint64_t *data, int types,
				      u16 bank1_select, u16 histogram)
770 771 772 773 774 775 776
{
	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) {
777
			mutex_lock(&chip->reg_lock);
778 779 780
			data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
							      bank1_select,
							      histogram);
781 782
			mutex_unlock(&chip->reg_lock);

783 784 785 786 787 788 789 790 791
			j++;
		}
	}
}

static void mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				      uint64_t *data)
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
792
					 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
793
					 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
794 795 796 797 798 799
}

static void mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				      uint64_t *data)
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
800
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
801 802
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
					 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
803 804 805 806 807 808 809
}

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,
810 811
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
					 0);
812 813 814 815 816 817 818 819 820
}

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

821 822
static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
					uint64_t *data)
823
{
V
Vivien Didelot 已提交
824
	struct mv88e6xxx_chip *chip = ds->priv;
825 826
	int ret;

827
	mutex_lock(&chip->reg_lock);
828

829
	ret = mv88e6xxx_stats_snapshot(chip, port);
830 831 832
	mutex_unlock(&chip->reg_lock);

	if (ret < 0)
833
		return;
834 835

	mv88e6xxx_get_stats(chip, port, data);
836

837 838
}

839 840 841 842 843 844 845 846
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;
}

847
static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
848 849 850 851
{
	return 32 * sizeof(u16);
}

852 853
static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
			       struct ethtool_regs *regs, void *_p)
854
{
V
Vivien Didelot 已提交
855
	struct mv88e6xxx_chip *chip = ds->priv;
856 857
	int err;
	u16 reg;
858 859 860 861 862 863 864
	u16 *p = _p;
	int i;

	regs->version = 0;

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

865
	mutex_lock(&chip->reg_lock);
866

867 868
	for (i = 0; i < 32; i++) {

869 870 871
		err = mv88e6xxx_port_read(chip, port, i, &reg);
		if (!err)
			p[i] = reg;
872
	}
873

874
	mutex_unlock(&chip->reg_lock);
875 876
}

V
Vivien Didelot 已提交
877 878
static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
879
{
880 881
	/* Nothing to do on the port's MAC */
	return 0;
882 883
}

V
Vivien Didelot 已提交
884 885
static int mv88e6xxx_set_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
}

891
static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
892
{
893 894 895
	struct dsa_switch *ds = NULL;
	struct net_device *br;
	u16 pvlan;
896 897
	int i;

898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917
	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 已提交
918
		    (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
919 920 921 922 923
			pvlan |= BIT(i);

	return pvlan;
}

924
static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
925 926
{
	u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
927 928 929

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

931
	return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
932 933
}

934 935
static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
					 u8 state)
936
{
V
Vivien Didelot 已提交
937
	struct mv88e6xxx_chip *chip = ds->priv;
938
	int err;
939

940
	mutex_lock(&chip->reg_lock);
941
	err = mv88e6xxx_port_set_state(chip, port, state);
942
	mutex_unlock(&chip->reg_lock);
943 944

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

948 949 950 951 952 953 954 955
static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->pot_clear)
		return chip->info->ops->pot_clear(chip);

	return 0;
}

956 957 958 959 960 961 962 963
static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->mgmt_rsvd2cpu)
		return chip->info->ops->mgmt_rsvd2cpu(chip);

	return 0;
}

964 965
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
966 967
	int err;

968 969 970 971
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

972 973 974 975
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

976 977 978
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998
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;
}

999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011
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;
}

1012 1013 1014 1015 1016 1017 1018 1019 1020
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)
1021
		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1022 1023 1024 1025

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

1026 1027
static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
{
1028 1029 1030
	int dev, port;
	int err;

1031 1032 1033 1034 1035 1036
	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.
	 */
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049
	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;
1050 1051
}

1052 1053 1054 1055 1056 1057
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);
1058
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1059 1060 1061
	mutex_unlock(&chip->reg_lock);

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

1065 1066 1067 1068 1069 1070 1071 1072
static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
{
	if (!chip->info->max_vid)
		return 0;

	return mv88e6xxx_g1_vtu_flush(chip);
}

1073 1074 1075 1076 1077 1078 1079 1080 1081
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);
}

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

1091
static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1092 1093
{
	DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1094 1095 1096
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = chip->info->max_vid,
	};
1097
	int i, err;
1098 1099 1100

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

1101
	/* Set every FID bit used by the (un)bridged ports */
1102
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1103
		err = mv88e6xxx_port_get_fid(chip, i, fid);
1104 1105 1106 1107 1108 1109
		if (err)
			return err;

		set_bit(*fid, fid_bitmap);
	}

1110 1111
	/* Set every FID bit used by the VLAN entries */
	do {
1112
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1113 1114 1115 1116 1117 1118 1119
		if (err)
			return err;

		if (!vlan.valid)
			break;

		set_bit(vlan.fid, fid_bitmap);
1120
	} while (vlan.vid < chip->info->max_vid);
1121 1122 1123 1124 1125

	/* 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);
1126
	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1127 1128 1129
		return -ENOSPC;

	/* Clear the database */
1130
	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1131 1132
}

1133 1134
static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
			     struct mv88e6xxx_vtu_entry *entry, bool new)
1135 1136 1137 1138 1139 1140
{
	int err;

	if (!vid)
		return -EINVAL;

1141 1142
	entry->vid = vid - 1;
	entry->valid = false;
1143

1144
	err = mv88e6xxx_vtu_getnext(chip, entry);
1145 1146 1147
	if (err)
		return err;

1148 1149
	if (entry->vid == vid && entry->valid)
		return 0;
1150

1151 1152 1153 1154 1155 1156 1157 1158
	if (new) {
		int i;

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

1159
		/* Exclude all ports */
1160
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1161
			entry->member[i] =
1162
				MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1163 1164

		return mv88e6xxx_atu_new(chip, &entry->fid);
1165 1166
	}

1167 1168
	/* switchdev expects -EOPNOTSUPP to honor software VLANs */
	return -EOPNOTSUPP;
1169 1170
}

1171 1172 1173
static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
					u16 vid_begin, u16 vid_end)
{
V
Vivien Didelot 已提交
1174
	struct mv88e6xxx_chip *chip = ds->priv;
1175 1176 1177
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = vid_begin - 1,
	};
1178 1179
	int i, err;

1180 1181 1182 1183
	/* 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;

1184 1185 1186
	if (!vid_begin)
		return -EOPNOTSUPP;

1187
	mutex_lock(&chip->reg_lock);
1188 1189

	do {
1190
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1191 1192 1193 1194 1195 1196 1197 1198 1199
		if (err)
			goto unlock;

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

1200
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1201 1202 1203
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

1204
			if (!ds->ports[i].slave)
1205 1206
				continue;

1207
			if (vlan.member[i] ==
1208
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1209 1210
				continue;

V
Vivien Didelot 已提交
1211
			if (dsa_to_port(ds, i)->bridge_dev ==
1212
			    ds->ports[port].bridge_dev)
1213 1214
				break; /* same bridge, check next VLAN */

V
Vivien Didelot 已提交
1215
			if (!dsa_to_port(ds, i)->bridge_dev)
1216 1217
				continue;

1218 1219
			dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
				port, vlan.vid, i,
V
Vivien Didelot 已提交
1220
				netdev_name(dsa_to_port(ds, i)->bridge_dev));
1221 1222 1223 1224 1225 1226
			err = -EOPNOTSUPP;
			goto unlock;
		}
	} while (vlan.vid < vid_end);

unlock:
1227
	mutex_unlock(&chip->reg_lock);
1228 1229 1230 1231

	return err;
}

1232 1233
static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
					 bool vlan_filtering)
1234
{
V
Vivien Didelot 已提交
1235
	struct mv88e6xxx_chip *chip = ds->priv;
1236 1237
	u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
		MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
1238
	int err;
1239

1240
	if (!chip->info->max_vid)
1241 1242
		return -EOPNOTSUPP;

1243
	mutex_lock(&chip->reg_lock);
1244
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1245
	mutex_unlock(&chip->reg_lock);
1246

1247
	return err;
1248 1249
}

1250 1251
static int
mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1252
			    const struct switchdev_obj_port_vlan *vlan)
1253
{
V
Vivien Didelot 已提交
1254
	struct mv88e6xxx_chip *chip = ds->priv;
1255 1256
	int err;

1257
	if (!chip->info->max_vid)
1258 1259
		return -EOPNOTSUPP;

1260 1261 1262 1263 1264 1265 1266 1267
	/* 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;

1268 1269 1270 1271 1272 1273
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */
	return 0;
}

1274 1275 1276 1277 1278 1279 1280 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
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);
}

1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340
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;
}

1341
static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
1342
				    u16 vid, u8 member)
1343
{
1344
	struct mv88e6xxx_vtu_entry vlan;
1345 1346
	int err;

1347
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
1348
	if (err)
1349
		return err;
1350

1351
	vlan.member[port] = member;
1352

1353 1354 1355 1356 1357
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
	if (err)
		return err;

	return mv88e6xxx_broadcast_setup(chip, vid);
1358 1359
}

1360
static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1361
				    const struct switchdev_obj_port_vlan *vlan)
1362
{
V
Vivien Didelot 已提交
1363
	struct mv88e6xxx_chip *chip = ds->priv;
1364 1365
	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1366
	u8 member;
1367 1368
	u16 vid;

1369
	if (!chip->info->max_vid)
1370 1371
		return;

1372
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1373
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1374
	else if (untagged)
1375
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
1376
	else
1377
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
1378

1379
	mutex_lock(&chip->reg_lock);
1380

1381
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
1382
		if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
1383 1384
			dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
				vid, untagged ? 'u' : 't');
1385

1386
	if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1387 1388
		dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
			vlan->vid_end);
1389

1390
	mutex_unlock(&chip->reg_lock);
1391 1392
}

1393
static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
1394
				    int port, u16 vid)
1395
{
1396
	struct mv88e6xxx_vtu_entry vlan;
1397 1398
	int i, err;

1399
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1400
	if (err)
1401
		return err;
1402

1403
	/* Tell switchdev if this VLAN is handled in software */
1404
	if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1405
		return -EOPNOTSUPP;
1406

1407
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1408 1409

	/* keep the VLAN unless all ports are excluded */
1410
	vlan.valid = false;
1411
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1412 1413
		if (vlan.member[i] !=
		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
1414
			vlan.valid = true;
1415 1416 1417 1418
			break;
		}
	}

1419
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1420 1421 1422
	if (err)
		return err;

1423
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
1424 1425
}

1426 1427
static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
				   const struct switchdev_obj_port_vlan *vlan)
1428
{
V
Vivien Didelot 已提交
1429
	struct mv88e6xxx_chip *chip = ds->priv;
1430 1431 1432
	u16 pvid, vid;
	int err = 0;

1433
	if (!chip->info->max_vid)
1434 1435
		return -EOPNOTSUPP;

1436
	mutex_lock(&chip->reg_lock);
1437

1438
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
1439 1440 1441
	if (err)
		goto unlock;

1442
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1443
		err = _mv88e6xxx_port_vlan_del(chip, port, vid);
1444 1445 1446 1447
		if (err)
			goto unlock;

		if (vid == pvid) {
1448
			err = mv88e6xxx_port_set_pvid(chip, port, 0);
1449 1450 1451 1452 1453
			if (err)
				goto unlock;
		}
	}

1454
unlock:
1455
	mutex_unlock(&chip->reg_lock);
1456 1457 1458 1459

	return err;
}

1460 1461
static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
				  const unsigned char *addr, u16 vid)
1462
{
V
Vivien Didelot 已提交
1463
	struct mv88e6xxx_chip *chip = ds->priv;
1464
	int err;
1465

1466
	mutex_lock(&chip->reg_lock);
1467 1468
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1469
	mutex_unlock(&chip->reg_lock);
1470 1471

	return err;
1472 1473
}

1474
static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1475
				  const unsigned char *addr, u16 vid)
1476
{
V
Vivien Didelot 已提交
1477
	struct mv88e6xxx_chip *chip = ds->priv;
1478
	int err;
1479

1480
	mutex_lock(&chip->reg_lock);
1481
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1482
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
1483
	mutex_unlock(&chip->reg_lock);
1484

1485
	return err;
1486 1487
}

1488 1489
static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
				      u16 fid, u16 vid, int port,
1490
				      dsa_fdb_dump_cb_t *cb, void *data)
1491
{
1492
	struct mv88e6xxx_atu_entry addr;
1493
	bool is_static;
1494 1495
	int err;

1496
	addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1497
	eth_broadcast_addr(addr.mac);
1498 1499

	do {
1500
		mutex_lock(&chip->reg_lock);
1501
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
1502
		mutex_unlock(&chip->reg_lock);
1503
		if (err)
1504
			return err;
1505

1506
		if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
1507 1508
			break;

1509
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
1510 1511
			continue;

1512 1513
		if (!is_unicast_ether_addr(addr.mac))
			continue;
1514

1515 1516 1517
		is_static = (addr.state ==
			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
		err = cb(addr.mac, vid, is_static, data);
1518 1519
		if (err)
			return err;
1520 1521 1522 1523 1524
	} while (!is_broadcast_ether_addr(addr.mac));

	return err;
}

1525
static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1526
				  dsa_fdb_dump_cb_t *cb, void *data)
1527
{
1528
	struct mv88e6xxx_vtu_entry vlan = {
1529
		.vid = chip->info->max_vid,
1530
	};
1531
	u16 fid;
1532 1533
	int err;

1534
	/* Dump port's default Filtering Information Database (VLAN ID 0) */
1535
	mutex_lock(&chip->reg_lock);
1536
	err = mv88e6xxx_port_get_fid(chip, port, &fid);
1537 1538
	mutex_unlock(&chip->reg_lock);

1539
	if (err)
1540
		return err;
1541

1542
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
1543
	if (err)
1544
		return err;
1545

1546
	/* Dump VLANs' Filtering Information Databases */
1547
	do {
1548
		mutex_lock(&chip->reg_lock);
1549
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1550
		mutex_unlock(&chip->reg_lock);
1551
		if (err)
1552
			return err;
1553 1554 1555 1556

		if (!vlan.valid)
			break;

1557
		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1558
						 cb, data);
1559
		if (err)
1560
			return err;
1561
	} while (vlan.vid < chip->info->max_vid);
1562

1563 1564 1565 1566
	return err;
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1567
				   dsa_fdb_dump_cb_t *cb, void *data)
1568
{
V
Vivien Didelot 已提交
1569
	struct mv88e6xxx_chip *chip = ds->priv;
1570

1571
	return mv88e6xxx_port_db_dump(chip, port, cb, data);
1572 1573
}

1574 1575
static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
				struct net_device *br)
1576
{
1577
	struct dsa_switch *ds;
1578
	int port;
1579
	int dev;
1580
	int err;
1581

1582 1583 1584 1585
	/* 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);
1586
			if (err)
1587
				return err;
1588 1589 1590
		}
	}

1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608
	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;
			}
		}
	}

1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619
	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);
1620
	mutex_unlock(&chip->reg_lock);
1621

1622
	return err;
1623 1624
}

1625 1626
static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
					struct net_device *br)
1627
{
V
Vivien Didelot 已提交
1628
	struct mv88e6xxx_chip *chip = ds->priv;
1629

1630
	mutex_lock(&chip->reg_lock);
1631 1632 1633
	if (mv88e6xxx_bridge_map(chip, br) ||
	    mv88e6xxx_port_vlan_map(chip, port))
		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
1634
	mutex_unlock(&chip->reg_lock);
1635 1636
}

1637 1638 1639 1640 1641 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
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);
}

1667 1668 1669 1670 1671 1672 1673 1674
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->reset)
		return chip->info->ops->reset(chip);

	return 0;
}

1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687
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);
	}
}

1688
static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1689
{
1690
	int i, err;
1691

1692
	/* Set all ports to the Disabled state */
1693
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
1694
		err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
1695 1696
		if (err)
			return err;
1697 1698
	}

1699 1700 1701
	/* Wait for transmit queues to drain,
	 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
	 */
1702 1703
	usleep_range(2000, 4000);

1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714
	return 0;
}

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

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

1715
	mv88e6xxx_hardware_reset(chip);
1716

1717
	return mv88e6xxx_software_reset(chip);
1718 1719
}

1720
static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
1721 1722
				   enum mv88e6xxx_frame_mode frame,
				   enum mv88e6xxx_egress_mode egress, u16 etype)
1723 1724 1725
{
	int err;

1726 1727 1728 1729
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
1730 1731 1732
	if (err)
		return err;

1733 1734 1735 1736 1737 1738 1739 1740
	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;
1741 1742
}

1743
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1744
{
1745
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
1746
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
1747
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
1748
}
1749

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

1757 1758 1759 1760
static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port,
				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
1761 1762
				       MV88E6XXX_EGRESS_MODE_ETHERTYPE,
				       ETH_P_EDSA);
1763
}
1764

1765 1766 1767 1768
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);
1769

1770
	if (dsa_is_user_port(chip->ds, port))
1771
		return mv88e6xxx_set_port_mode_normal(chip, port);
1772

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

1777 1778
	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
		return mv88e6xxx_set_port_mode_edsa(chip, port);
1779

1780
	return -EINVAL;
1781 1782
}

1783
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
1784
{
1785
	bool message = dsa_is_dsa_port(chip->ds, port);
1786

1787
	return mv88e6xxx_port_set_message_port(chip, port, message);
1788
}
1789

1790
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
1791
{
1792 1793
	struct dsa_switch *ds = chip->ds;
	bool flood;
1794

1795
	/* Upstream ports flood frames with unknown unicast or multicast DA */
1796
	flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
1797 1798 1799
	if (chip->info->ops->port_set_egress_floods)
		return chip->info->ops->port_set_egress_floods(chip, port,
							       flood, flood);
1800

1801
	return 0;
1802 1803
}

1804 1805 1806
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
1807 1808
	if (chip->info->ops->serdes_power)
		return chip->info->ops->serdes_power(chip, port, on);
1809

1810
	return 0;
1811 1812
}

1813 1814 1815 1816 1817 1818
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

1819
	upstream_port = dsa_upstream_port(ds, port);
1820 1821 1822 1823 1824 1825 1826
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842
	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;
		}
	}

1843 1844 1845
	return 0;
}

1846
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
1847
{
1848
	struct dsa_switch *ds = chip->ds;
1849
	int err;
1850
	u16 reg;
1851

1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865
	/* 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;
1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880

	/* 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.
	 */
1881 1882 1883 1884
	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);
1885 1886
	if (err)
		return err;
1887

1888
	err = mv88e6xxx_setup_port_mode(chip, port);
1889 1890
	if (err)
		return err;
1891

1892
	err = mv88e6xxx_setup_egress_floods(chip, port);
1893 1894 1895
	if (err)
		return err;

1896 1897 1898
	/* 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.
1899
	 */
1900 1901 1902 1903 1904
	if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
		err = mv88e6xxx_serdes_power(chip, port, true);
		if (err)
			return err;
	}
1905

1906
	/* Port Control 2: don't force a good FCS, set the maximum frame size to
1907
	 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
1908 1909 1910
	 * 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.
1911
	 */
1912 1913 1914
	err = mv88e6xxx_port_set_map_da(chip, port);
	if (err)
		return err;
1915

1916 1917 1918
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
1919

1920
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
1921
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
1922 1923 1924
	if (err)
		return err;

1925 1926
	if (chip->info->ops->port_set_jumbo_size) {
		err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
1927 1928 1929 1930
		if (err)
			return err;
	}

1931 1932 1933 1934 1935
	/* 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.
	 */
1936
	reg = 1 << port;
1937 1938
	/* Disable learning for CPU port */
	if (dsa_is_cpu_port(ds, port))
1939
		reg = 0;
1940

1941 1942
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
1943 1944
	if (err)
		return err;
1945 1946

	/* Egress rate control 2: disable egress rate control. */
1947 1948
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
				   0x0000);
1949 1950
	if (err)
		return err;
1951

1952 1953
	if (chip->info->ops->port_pause_limit) {
		err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
1954 1955
		if (err)
			return err;
1956
	}
1957

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

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

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

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

1982
	err = mv88e6xxx_setup_message_port(chip, port);
1983 1984
	if (err)
		return err;
1985

1986
	/* Port based VLAN map: give each port the same default address
1987 1988
	 * database, and allow bidirectional communication between the
	 * CPU and DSA port(s), and the other ports.
1989
	 */
1990
	err = mv88e6xxx_port_set_fid(chip, port, 0);
1991 1992
	if (err)
		return err;
1993

1994
	err = mv88e6xxx_port_vlan_map(chip, port);
1995 1996
	if (err)
		return err;
1997 1998 1999 2000

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

2004 2005 2006 2007
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
2008
	int err;
2009 2010

	mutex_lock(&chip->reg_lock);
2011
	err = mv88e6xxx_serdes_power(chip, port, true);
2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022
	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);
2023 2024
	if (mv88e6xxx_serdes_power(chip, port, false))
		dev_err(chip->dev, "failed to power off SERDES\n");
2025 2026 2027
	mutex_unlock(&chip->reg_lock);
}

2028 2029 2030
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
2031
	struct mv88e6xxx_chip *chip = ds->priv;
2032 2033 2034
	int err;

	mutex_lock(&chip->reg_lock);
2035
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2036 2037 2038 2039 2040
	mutex_unlock(&chip->reg_lock);

	return err;
}

2041
static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
2042
{
2043
	struct dsa_switch *ds = chip->ds;
2044
	int err;
2045

2046
	/* Disable remote management, and set the switch's DSA device number. */
2047 2048
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL2,
				 MV88E6XXX_G1_CTL2_MULTIPLE_CASCADE |
2049
				 (ds->index & 0x1f));
2050 2051 2052
	if (err)
		return err;

2053
	/* Configure the IP ToS mapping registers. */
2054
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_0, 0x0000);
2055
	if (err)
2056
		return err;
2057
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_1, 0x0000);
2058
	if (err)
2059
		return err;
2060
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_2, 0x5555);
2061
	if (err)
2062
		return err;
2063
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_3, 0x5555);
2064
	if (err)
2065
		return err;
2066
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_4, 0xaaaa);
2067
	if (err)
2068
		return err;
2069
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_5, 0xaaaa);
2070
	if (err)
2071
		return err;
2072
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_6, 0xffff);
2073
	if (err)
2074
		return err;
2075
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_7, 0xffff);
2076
	if (err)
2077
		return err;
2078 2079

	/* Configure the IEEE 802.1p priority mapping register. */
2080
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IEEE_PRI, 0xfa41);
2081
	if (err)
2082
		return err;
2083

2084 2085 2086 2087 2088
	/* Initialize the statistics unit */
	err = mv88e6xxx_stats_set_histogram(chip);
	if (err)
		return err;

2089
	return mv88e6xxx_g1_stats_clear(chip);
2090 2091
}

2092
static int mv88e6xxx_setup(struct dsa_switch *ds)
2093
{
V
Vivien Didelot 已提交
2094
	struct mv88e6xxx_chip *chip = ds->priv;
2095
	int err;
2096 2097
	int i;

2098
	chip->ds = ds;
2099
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
2100

2101
	mutex_lock(&chip->reg_lock);
2102

2103
	/* Setup Switch Port Registers */
2104
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2105 2106 2107
		if (dsa_is_unused_port(ds, i))
			continue;

2108 2109 2110 2111 2112 2113 2114
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

	/* Setup Switch Global 1 Registers */
	err = mv88e6xxx_g1_setup(chip);
2115 2116 2117
	if (err)
		goto unlock;

2118
	/* Setup Switch Global 2 Registers */
2119
	if (chip->info->global2_addr) {
2120
		err = mv88e6xxx_g2_setup(chip);
2121 2122 2123
		if (err)
			goto unlock;
	}
2124

2125 2126 2127 2128
	err = mv88e6xxx_irl_setup(chip);
	if (err)
		goto unlock;

2129 2130 2131 2132
	err = mv88e6xxx_mac_setup(chip);
	if (err)
		goto unlock;

2133 2134 2135 2136
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

2137 2138 2139 2140
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

2141 2142 2143 2144
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

2145 2146 2147 2148
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

2149 2150 2151 2152
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

2153 2154 2155 2156
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

2157 2158 2159
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
2160

2161
	/* Setup PTP Hardware Clock and timestamping */
2162 2163 2164 2165
	if (chip->info->ptp_support) {
		err = mv88e6xxx_ptp_setup(chip);
		if (err)
			goto unlock;
2166 2167 2168 2169

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
2170 2171
	}

2172
unlock:
2173
	mutex_unlock(&chip->reg_lock);
2174

2175
	return err;
2176 2177
}

2178
static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
2179
{
2180 2181
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2182 2183
	u16 val;
	int err;
2184

2185 2186 2187
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

2188
	mutex_lock(&chip->reg_lock);
2189
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
2190
	mutex_unlock(&chip->reg_lock);
2191

2192 2193 2194 2195 2196
	if (reg == MII_PHYSID2) {
		/* Some internal PHYS don't have a model number.  Use
		 * the mv88e6390 family model number instead.
		 */
		if (!(val & 0x3f0))
2197
			val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
2198 2199
	}

2200
	return err ? err : val;
2201 2202
}

2203
static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
2204
{
2205 2206
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2207
	int err;
2208

2209 2210 2211
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

2212
	mutex_lock(&chip->reg_lock);
2213
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
2214
	mutex_unlock(&chip->reg_lock);
2215 2216

	return err;
2217 2218
}

2219
static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
2220 2221
				   struct device_node *np,
				   bool external)
2222 2223
{
	static int index;
2224
	struct mv88e6xxx_mdio_bus *mdio_bus;
2225 2226 2227
	struct mii_bus *bus;
	int err;

2228 2229 2230 2231 2232 2233 2234 2235 2236
	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;
	}

2237
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
2238 2239 2240
	if (!bus)
		return -ENOMEM;

2241
	mdio_bus = bus->priv;
2242
	mdio_bus->bus = bus;
2243
	mdio_bus->chip = chip;
2244 2245
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
2246

2247 2248
	if (np) {
		bus->name = np->full_name;
2249
		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
2250 2251 2252 2253 2254 2255 2256
	} 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;
2257
	bus->parent = chip->dev;
2258

2259 2260
	if (np)
		err = of_mdiobus_register(bus, np);
2261 2262 2263
	else
		err = mdiobus_register(bus);
	if (err) {
2264
		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
2265
		return err;
2266
	}
2267 2268 2269 2270 2271

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

	return 0;
2274
}
2275

2276 2277 2278 2279 2280
static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
	{ .compatible = "marvell,mv88e6xxx-mdio-external",
	  .data = (void *)true },
	{ },
};
2281

2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294
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);
	}
}

2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318
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);
2319 2320
			if (err) {
				mv88e6xxx_mdios_unregister(chip);
2321
				return err;
2322
			}
2323 2324 2325 2326
		}
	}

	return 0;
2327 2328
}

2329 2330
static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
2331
	struct mv88e6xxx_chip *chip = ds->priv;
2332 2333 2334 2335 2336 2337 2338

	return chip->eeprom_len;
}

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

2342 2343
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
2344

2345 2346
	mutex_lock(&chip->reg_lock);
	err = chip->info->ops->get_eeprom(chip, eeprom, data);
2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359
	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 已提交
2360
	struct mv88e6xxx_chip *chip = ds->priv;
2361 2362
	int err;

2363 2364 2365
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

2366 2367 2368 2369
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

	mutex_lock(&chip->reg_lock);
2370
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
2371 2372 2373 2374 2375
	mutex_unlock(&chip->reg_lock);

	return err;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	[MV88E6095] = {
3297
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
3298 3299 3300 3301
		.family = MV88E6XXX_FAMILY_6095,
		.name = "Marvell 88E6095/88E6095F",
		.num_databases = 256,
		.num_ports = 11,
3302
		.max_vid = 4095,
3303
		.port_base_addr = 0x10,
3304
		.global1_addr = 0x1b,
3305
		.global2_addr = 0x1c,
3306
		.age_time_coeff = 15000,
3307
		.g1_irqs = 8,
3308
		.atu_move_port_mask = 0xf,
3309
		.multi_chip = true,
3310
		.tag_protocol = DSA_TAG_PROTO_DSA,
3311
		.ops = &mv88e6095_ops,
3312 3313
	},

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

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

	[MV88E6131] = {
3355
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
3356 3357 3358 3359
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6131",
		.num_databases = 256,
		.num_ports = 8,
3360
		.max_vid = 4095,
3361
		.port_base_addr = 0x10,
3362
		.global1_addr = 0x1b,
3363
		.global2_addr = 0x1c,
3364
		.age_time_coeff = 15000,
3365
		.g1_irqs = 9,
3366
		.atu_move_port_mask = 0xf,
3367
		.multi_chip = true,
3368
		.tag_protocol = DSA_TAG_PROTO_DSA,
3369
		.ops = &mv88e6131_ops,
3370 3371
	},

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

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

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

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

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

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

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

	[MV88E6185] = {
3515
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
3516 3517 3518 3519
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6185",
		.num_databases = 256,
		.num_ports = 10,
3520
		.max_vid = 4095,
3521
		.port_base_addr = 0x10,
3522
		.global1_addr = 0x1b,
3523
		.global2_addr = 0x1c,
3524
		.age_time_coeff = 15000,
3525
		.g1_irqs = 8,
3526
		.atu_move_port_mask = 0xf,
3527
		.multi_chip = true,
3528
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3529
		.ops = &mv88e6185_ops,
3530 3531
	},

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

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

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

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

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

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

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

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

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

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

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

3806
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
3807
{
3808
	int i;
3809

3810 3811 3812
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
3813 3814 3815 3816

	return NULL;
}

3817
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
3818 3819
{
	const struct mv88e6xxx_info *info;
3820 3821 3822
	unsigned int prod_num, rev;
	u16 id;
	int err;
3823

3824
	mutex_lock(&chip->reg_lock);
3825
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
3826 3827 3828
	mutex_unlock(&chip->reg_lock);
	if (err)
		return err;
3829

3830 3831
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
3832 3833 3834 3835 3836

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

3837
	/* Update the compatible info with the probed one */
3838
	chip->info = info;
3839

3840 3841 3842 3843
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

3844 3845
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
3846 3847 3848 3849

	return 0;
}

3850
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
3851
{
3852
	struct mv88e6xxx_chip *chip;
3853

3854 3855
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
3856 3857
		return NULL;

3858
	chip->dev = dev;
3859

3860
	mutex_init(&chip->reg_lock);
3861
	INIT_LIST_HEAD(&chip->mdios);
3862

3863
	return chip;
3864 3865
}

3866
static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
3867 3868
			      struct mii_bus *bus, int sw_addr)
{
3869
	if (sw_addr == 0)
3870
		chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
3871
	else if (chip->info->multi_chip)
3872
		chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
3873 3874 3875
	else
		return -EINVAL;

3876 3877
	chip->bus = bus;
	chip->sw_addr = sw_addr;
3878 3879 3880 3881

	return 0;
}

3882 3883
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
							int port)
3884
{
V
Vivien Didelot 已提交
3885
	struct mv88e6xxx_chip *chip = ds->priv;
3886

3887
	return chip->info->tag_protocol;
3888 3889
}

3890
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
3891 3892 3893
static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
				       struct device *host_dev, int sw_addr,
				       void **priv)
3894
{
3895
	struct mv88e6xxx_chip *chip;
3896
	struct mii_bus *bus;
3897
	int err;
3898

3899
	bus = dsa_host_dev_to_mii_bus(host_dev);
3900 3901 3902
	if (!bus)
		return NULL;

3903 3904
	chip = mv88e6xxx_alloc_chip(dsa_dev);
	if (!chip)
3905 3906
		return NULL;

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

3910
	err = mv88e6xxx_smi_init(chip, bus, sw_addr);
3911 3912 3913
	if (err)
		goto free;

3914
	err = mv88e6xxx_detect(chip);
3915
	if (err)
3916
		goto free;
3917

3918 3919 3920 3921 3922 3923
	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_switch_reset(chip);
	mutex_unlock(&chip->reg_lock);
	if (err)
		goto free;

3924 3925
	mv88e6xxx_phy_init(chip);

3926
	err = mv88e6xxx_mdios_register(chip, NULL);
3927
	if (err)
3928
		goto free;
3929

3930
	*priv = chip;
3931

3932
	return chip->info->name;
3933
free:
3934
	devm_kfree(dsa_dev, chip);
3935 3936

	return NULL;
3937
}
3938
#endif
3939

3940
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
3941
				      const struct switchdev_obj_port_mdb *mdb)
3942 3943 3944 3945 3946 3947 3948 3949 3950
{
	/* 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,
3951
				   const struct switchdev_obj_port_mdb *mdb)
3952
{
V
Vivien Didelot 已提交
3953
	struct mv88e6xxx_chip *chip = ds->priv;
3954 3955 3956

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

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
3971
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
3972 3973 3974 3975 3976
	mutex_unlock(&chip->reg_lock);

	return err;
}

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

4020 4021 4022 4023
static struct dsa_switch_driver mv88e6xxx_switch_drv = {
	.ops			= &mv88e6xxx_switch_ops,
};

4024
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
4025
{
4026
	struct device *dev = chip->dev;
4027 4028
	struct dsa_switch *ds;

4029
	ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
4030 4031 4032
	if (!ds)
		return -ENOMEM;

4033
	ds->priv = chip;
4034
	ds->ops = &mv88e6xxx_switch_ops;
4035 4036
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
4037 4038 4039

	dev_set_drvdata(dev, ds);

4040
	return dsa_register_switch(ds);
4041 4042
}

4043
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
4044
{
4045
	dsa_unregister_switch(chip->ds);
4046 4047
}

4048
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
4049
{
4050
	struct device *dev = &mdiodev->dev;
4051
	struct device_node *np = dev->of_node;
4052
	const struct mv88e6xxx_info *compat_info;
4053
	struct mv88e6xxx_chip *chip;
4054
	u32 eeprom_len;
4055
	int err;
4056

4057 4058 4059 4060
	compat_info = of_device_get_match_data(dev);
	if (!compat_info)
		return -EINVAL;

4061 4062
	chip = mv88e6xxx_alloc_chip(dev);
	if (!chip)
4063 4064
		return -ENOMEM;

4065
	chip->info = compat_info;
4066

4067
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
4068 4069
	if (err)
		return err;
4070

4071 4072 4073 4074
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
	if (IS_ERR(chip->reset))
		return PTR_ERR(chip->reset);

4075
	err = mv88e6xxx_detect(chip);
4076 4077
	if (err)
		return err;
4078

4079 4080
	mv88e6xxx_phy_init(chip);

4081
	if (chip->info->ops->get_eeprom &&
4082
	    !of_property_read_u32(np, "eeprom-length", &eeprom_len))
4083
		chip->eeprom_len = eeprom_len;
4084

4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096
	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;
	}

4097 4098 4099 4100 4101 4102
	/* 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)
4103
		err = mv88e6xxx_g1_irq_setup(chip);
4104 4105 4106
	else
		err = mv88e6xxx_irq_poll_setup(chip);
	mutex_unlock(&chip->reg_lock);
4107

4108 4109
	if (err)
		goto out;
4110

4111 4112
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
4113
		if (err)
4114
			goto out_g1_irq;
4115 4116
	}

4117 4118 4119 4120 4121 4122 4123 4124
	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;

4125
	err = mv88e6xxx_mdios_register(chip, np);
4126
	if (err)
4127
		goto out_g1_vtu_prob_irq;
4128

4129
	err = mv88e6xxx_register_switch(chip);
4130 4131
	if (err)
		goto out_mdio;
4132

4133
	return 0;
4134 4135

out_mdio:
4136
	mv88e6xxx_mdios_unregister(chip);
4137
out_g1_vtu_prob_irq:
4138
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
4139
out_g1_atu_prob_irq:
4140
	mv88e6xxx_g1_atu_prob_irq_free(chip);
4141
out_g2_irq:
4142
	if (chip->info->g2_irqs > 0)
4143 4144
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
4145 4146
	mutex_lock(&chip->reg_lock);
	if (chip->irq > 0)
4147
		mv88e6xxx_g1_irq_free(chip);
4148 4149 4150
	else
		mv88e6xxx_irq_poll_free(chip);
	mutex_unlock(&chip->reg_lock);
4151 4152
out:
	return err;
4153
}
4154 4155 4156 4157

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

4160 4161
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
4162
		mv88e6xxx_ptp_free(chip);
4163
	}
4164

4165
	mv88e6xxx_phy_destroy(chip);
4166
	mv88e6xxx_unregister_switch(chip);
4167
	mv88e6xxx_mdios_unregister(chip);
4168

4169
	if (chip->irq > 0) {
4170
		mv88e6xxx_g1_vtu_prob_irq_free(chip);
4171
		mv88e6xxx_g1_atu_prob_irq_free(chip);
4172
		if (chip->info->g2_irqs > 0)
4173
			mv88e6xxx_g2_irq_free(chip);
4174
		mutex_lock(&chip->reg_lock);
4175
		mv88e6xxx_g1_irq_free(chip);
4176
		mutex_unlock(&chip->reg_lock);
4177
	}
4178 4179 4180
}

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

static void __exit mv88e6xxx_cleanup(void)
{
4212
	mdio_driver_unregister(&mv88e6xxx_driver);
4213
	unregister_switch_driver(&mv88e6xxx_switch_drv);
4214 4215
}
module_exit(mv88e6xxx_cleanup);
4216 4217 4218 4219

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