chip.c 118.8 KB
Newer Older
1
/*
2 3
 * Marvell 88e6xxx Ethernet switch single-chip support
 *
4 5
 * Copyright (c) 2008 Marvell Semiconductor
 *
6 7
 * Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch>
 *
V
Vivien Didelot 已提交
8 9 10
 * Copyright (c) 2016-2017 Savoir-faire Linux Inc.
 *	Vivien Didelot <vivien.didelot@savoirfairelinux.com>
 *
11 12 13 14 15 16
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */

17
#include <linux/delay.h>
18
#include <linux/etherdevice.h>
19
#include <linux/ethtool.h>
20
#include <linux/if_bridge.h>
21 22 23
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/irqdomain.h>
24
#include <linux/jiffies.h>
25
#include <linux/list.h>
26
#include <linux/mdio.h>
27
#include <linux/module.h>
28
#include <linux/of_device.h>
29
#include <linux/of_irq.h>
30
#include <linux/of_mdio.h>
31
#include <linux/netdevice.h>
32
#include <linux/gpio/consumer.h>
33
#include <linux/phy.h>
34
#include <net/dsa.h>
35

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

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

53 54 55 56 57 58 59 60 61 62
/* The switch ADDR[4:1] configuration pins define the chip SMI device address
 * (ADDR[0] is always zero, thus only even SMI addresses can be strapped).
 *
 * When ADDR is all zero, the chip uses Single-chip Addressing Mode, assuming it
 * is the only device connected to the SMI master. In this mode it responds to
 * all 32 possible SMI addresses, and thus maps directly the internal devices.
 *
 * When ADDR is non-zero, the chip uses Multi-chip Addressing Mode, allowing
 * multiple devices to share the SMI interface. In this mode it responds to only
 * 2 registers, used to indirectly access the internal SMI devices.
63
 */
64

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

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

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

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

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

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

	*val = ret & 0xffff;

	return 0;
}

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

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

	return 0;
}

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

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

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

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

	return -ETIMEDOUT;
}

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

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

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

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

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

157
	*val = ret & 0xffff;
158

159
	return 0;
160 161
}

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

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

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

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

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

	return 0;
}

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

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

200
	assert_reg_lock(chip);
201

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

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

	return 0;
}

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

216
	assert_reg_lock(chip);
217

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

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

225 226 227
	return 0;
}

228
struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
229 230 231 232 233 234 235 236 237 238 239
{
	struct mv88e6xxx_mdio_bus *mdio_bus;

	mdio_bus = list_first_entry(&chip->mdios, struct mv88e6xxx_mdio_bus,
				    list);
	if (!mdio_bus)
		return NULL;

	return mdio_bus->bus;
}

240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
static void mv88e6xxx_g1_irq_mask(struct irq_data *d)
{
	struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
	unsigned int n = d->hwirq;

	chip->g1_irq.masked |= (1 << n);
}

static void mv88e6xxx_g1_irq_unmask(struct irq_data *d)
{
	struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
	unsigned int n = d->hwirq;

	chip->g1_irq.masked &= ~(1 << n);
}

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

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

	if (err)
		goto out;

	for (n = 0; n < chip->g1_irq.nirqs; ++n) {
		if (reg & (1 << n)) {
			sub_irq = irq_find_mapping(chip->g1_irq.domain, n);
			handle_nested_irq(sub_irq);
			++nhandled;
		}
	}
out:
	return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
}

282 283 284 285 286 287 288
static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id)
{
	struct mv88e6xxx_chip *chip = dev_id;

	return mv88e6xxx_g1_irq_thread_work(chip);
}

289 290 291 292 293 294 295 296 297 298 299 300 301 302
static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
{
	struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);

	mutex_lock(&chip->reg_lock);
}

static void mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data *d)
{
	struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
	u16 mask = GENMASK(chip->g1_irq.nirqs, 0);
	u16 reg;
	int err;

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

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

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

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

318
static const struct irq_chip mv88e6xxx_g1_irq_chip = {
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
	.name			= "mv88e6xxx-g1",
	.irq_mask		= mv88e6xxx_g1_irq_mask,
	.irq_unmask		= mv88e6xxx_g1_irq_unmask,
	.irq_bus_lock		= mv88e6xxx_g1_irq_bus_lock,
	.irq_bus_sync_unlock	= mv88e6xxx_g1_irq_bus_sync_unlock,
};

static int mv88e6xxx_g1_irq_domain_map(struct irq_domain *d,
				       unsigned int irq,
				       irq_hw_number_t hwirq)
{
	struct mv88e6xxx_chip *chip = d->host_data;

	irq_set_chip_data(irq, d->host_data);
	irq_set_chip_and_handler(irq, &chip->g1_irq.chip, handle_level_irq);
	irq_set_noprobe(irq);

	return 0;
}

static const struct irq_domain_ops mv88e6xxx_g1_irq_domain_ops = {
	.map	= mv88e6xxx_g1_irq_domain_map,
	.xlate	= irq_domain_xlate_twocell,
};

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

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

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

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

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

	free_irq(chip->irq, chip);
}

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

	chip->g1_irq.nirqs = chip->info->g1_irqs;
	chip->g1_irq.domain = irq_domain_add_simple(
		NULL, chip->g1_irq.nirqs, 0,
		&mv88e6xxx_g1_irq_domain_ops, chip);
	if (!chip->g1_irq.domain)
		return -ENOMEM;

	for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
		irq_create_mapping(chip->g1_irq.domain, irq);

	chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
	chip->g1_irq.masked = ~0;

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

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

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

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

	return 0;

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

out_mapping:
	for (irq = 0; irq < 16; irq++) {
		virq = irq_find_mapping(chip->g1_irq.domain, irq);
		irq_dispose_mapping(virq);
	}

	irq_domain_remove(chip->g1_irq.domain);
414 415 416 417

	return err;
}

418 419 420 421 422 423 424 425 426 427 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->size == 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->size == 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 int 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

	return j;
708 709
}

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

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

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

730 731
	mutex_lock(&chip->reg_lock);

732
	if (chip->info->ops->stats_get_strings)
733 734 735 736 737 738
		count = chip->info->ops->stats_get_strings(chip, data);

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

	mutex_unlock(&chip->reg_lock);
741 742 743 744 745
}

static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
					  int types)
{
746 747 748 749 750
	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];
751
		if (stat->type & types)
752 753 754
			j++;
	}
	return j;
755 756
}

757 758 759 760 761 762 763 764 765 766 767 768
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);
}

769
static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port)
770 771
{
	struct mv88e6xxx_chip *chip = ds->priv;
772 773
	int serdes_count = 0;
	int count = 0;
774

775
	mutex_lock(&chip->reg_lock);
776
	if (chip->info->ops->stats_get_sset_count)
777 778 779 780 781 782 783 784 785 786 787 788
		count = chip->info->ops->stats_get_sset_count(chip);
	if (count < 0)
		goto out;

	if (chip->info->ops->serdes_get_sset_count)
		serdes_count = chip->info->ops->serdes_get_sset_count(chip,
								      port);
	if (serdes_count < 0)
		count = serdes_count;
	else
		count += serdes_count;
out:
789
	mutex_unlock(&chip->reg_lock);
790

791
	return count;
792 793
}

794 795 796
static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data, int types,
				     u16 bank1_select, u16 histogram)
797 798 799 800 801 802 803
{
	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) {
804
			mutex_lock(&chip->reg_lock);
805 806 807
			data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
							      bank1_select,
							      histogram);
808 809
			mutex_unlock(&chip->reg_lock);

810 811 812
			j++;
		}
	}
813
	return j;
814 815
}

816 817
static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
818 819
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
820
					 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
821
					 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
822 823
}

824 825
static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
826 827
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
828
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
829 830
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
					 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
831 832
}

833 834
static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
835 836 837
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
838 839
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
					 0);
840 841 842 843 844
}

static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
				uint64_t *data)
{
845 846
	int count = 0;

847
	if (chip->info->ops->stats_get_stats)
848 849 850 851 852 853
		count = chip->info->ops->stats_get_stats(chip, port, data);

	if (chip->info->ops->serdes_get_stats) {
		data += count;
		chip->info->ops->serdes_get_stats(chip, port, data);
	}
854 855
}

856 857
static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
					uint64_t *data)
858
{
V
Vivien Didelot 已提交
859
	struct mv88e6xxx_chip *chip = ds->priv;
860 861
	int ret;

862
	mutex_lock(&chip->reg_lock);
863

864
	ret = mv88e6xxx_stats_snapshot(chip, port);
865 866 867
	mutex_unlock(&chip->reg_lock);

	if (ret < 0)
868
		return;
869 870

	mv88e6xxx_get_stats(chip, port, data);
871

872 873
}

874 875 876 877 878 879 880 881
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;
}

882
static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
883 884 885 886
{
	return 32 * sizeof(u16);
}

887 888
static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
			       struct ethtool_regs *regs, void *_p)
889
{
V
Vivien Didelot 已提交
890
	struct mv88e6xxx_chip *chip = ds->priv;
891 892
	int err;
	u16 reg;
893 894 895 896 897 898 899
	u16 *p = _p;
	int i;

	regs->version = 0;

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

900
	mutex_lock(&chip->reg_lock);
901

902 903
	for (i = 0; i < 32; i++) {

904 905 906
		err = mv88e6xxx_port_read(chip, port, i, &reg);
		if (!err)
			p[i] = reg;
907
	}
908

909
	mutex_unlock(&chip->reg_lock);
910 911
}

V
Vivien Didelot 已提交
912 913
static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
914
{
915 916
	/* Nothing to do on the port's MAC */
	return 0;
917 918
}

V
Vivien Didelot 已提交
919 920
static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
921
{
922 923
	/* Nothing to do on the port's MAC */
	return 0;
924 925
}

926
static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
927
{
928 929 930
	struct dsa_switch *ds = NULL;
	struct net_device *br;
	u16 pvlan;
931 932
	int i;

933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952
	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 已提交
953
		    (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
954 955 956 957 958
			pvlan |= BIT(i);

	return pvlan;
}

959
static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
960 961
{
	u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
962 963 964

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

966
	return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
967 968
}

969 970
static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
					 u8 state)
971
{
V
Vivien Didelot 已提交
972
	struct mv88e6xxx_chip *chip = ds->priv;
973
	int err;
974

975
	mutex_lock(&chip->reg_lock);
976
	err = mv88e6xxx_port_set_state(chip, port, state);
977
	mutex_unlock(&chip->reg_lock);
978 979

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

983 984 985 986 987 988 989 990
static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->pot_clear)
		return chip->info->ops->pot_clear(chip);

	return 0;
}

991 992 993 994 995 996 997 998
static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->mgmt_rsvd2cpu)
		return chip->info->ops->mgmt_rsvd2cpu(chip);

	return 0;
}

999 1000
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
1001 1002
	int err;

1003 1004 1005 1006
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

1007 1008 1009 1010
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

1011 1012 1013
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033
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;
}

1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046
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;
}

1047 1048 1049 1050 1051 1052 1053 1054 1055
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)
1056
		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1057 1058 1059 1060

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

1061 1062
static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
{
1063 1064 1065
	int dev, port;
	int err;

1066 1067 1068 1069 1070 1071
	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.
	 */
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084
	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;
1085 1086
}

1087 1088 1089 1090 1091 1092
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);
1093
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1094 1095 1096
	mutex_unlock(&chip->reg_lock);

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

1100 1101 1102 1103 1104 1105 1106 1107
static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
{
	if (!chip->info->max_vid)
		return 0;

	return mv88e6xxx_g1_vtu_flush(chip);
}

1108 1109 1110 1111 1112 1113 1114 1115 1116
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);
}

1117 1118 1119 1120 1121 1122 1123 1124 1125
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);
}

1126
static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1127 1128
{
	DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1129 1130 1131
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = chip->info->max_vid,
	};
1132
	int i, err;
1133 1134 1135

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

1136
	/* Set every FID bit used by the (un)bridged ports */
1137
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1138
		err = mv88e6xxx_port_get_fid(chip, i, fid);
1139 1140 1141 1142 1143 1144
		if (err)
			return err;

		set_bit(*fid, fid_bitmap);
	}

1145 1146
	/* Set every FID bit used by the VLAN entries */
	do {
1147
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1148 1149 1150 1151 1152 1153 1154
		if (err)
			return err;

		if (!vlan.valid)
			break;

		set_bit(vlan.fid, fid_bitmap);
1155
	} while (vlan.vid < chip->info->max_vid);
1156 1157 1158 1159 1160

	/* 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);
1161
	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1162 1163 1164
		return -ENOSPC;

	/* Clear the database */
1165
	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1166 1167
}

1168 1169
static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
			     struct mv88e6xxx_vtu_entry *entry, bool new)
1170 1171 1172 1173 1174 1175
{
	int err;

	if (!vid)
		return -EINVAL;

1176 1177
	entry->vid = vid - 1;
	entry->valid = false;
1178

1179
	err = mv88e6xxx_vtu_getnext(chip, entry);
1180 1181 1182
	if (err)
		return err;

1183 1184
	if (entry->vid == vid && entry->valid)
		return 0;
1185

1186 1187 1188 1189 1190 1191 1192 1193
	if (new) {
		int i;

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

1194
		/* Exclude all ports */
1195
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1196
			entry->member[i] =
1197
				MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1198 1199

		return mv88e6xxx_atu_new(chip, &entry->fid);
1200 1201
	}

1202 1203
	/* switchdev expects -EOPNOTSUPP to honor software VLANs */
	return -EOPNOTSUPP;
1204 1205
}

1206 1207 1208
static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
					u16 vid_begin, u16 vid_end)
{
V
Vivien Didelot 已提交
1209
	struct mv88e6xxx_chip *chip = ds->priv;
1210 1211 1212
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = vid_begin - 1,
	};
1213 1214
	int i, err;

1215 1216 1217 1218
	/* 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;

1219 1220 1221
	if (!vid_begin)
		return -EOPNOTSUPP;

1222
	mutex_lock(&chip->reg_lock);
1223 1224

	do {
1225
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1226 1227 1228 1229 1230 1231 1232 1233 1234
		if (err)
			goto unlock;

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

1235
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1236 1237 1238
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

1239
			if (!ds->ports[i].slave)
1240 1241
				continue;

1242
			if (vlan.member[i] ==
1243
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1244 1245
				continue;

V
Vivien Didelot 已提交
1246
			if (dsa_to_port(ds, i)->bridge_dev ==
1247
			    ds->ports[port].bridge_dev)
1248 1249
				break; /* same bridge, check next VLAN */

V
Vivien Didelot 已提交
1250
			if (!dsa_to_port(ds, i)->bridge_dev)
1251 1252
				continue;

1253 1254
			dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
				port, vlan.vid, i,
V
Vivien Didelot 已提交
1255
				netdev_name(dsa_to_port(ds, i)->bridge_dev));
1256 1257 1258 1259 1260 1261
			err = -EOPNOTSUPP;
			goto unlock;
		}
	} while (vlan.vid < vid_end);

unlock:
1262
	mutex_unlock(&chip->reg_lock);
1263 1264 1265 1266

	return err;
}

1267 1268
static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
					 bool vlan_filtering)
1269
{
V
Vivien Didelot 已提交
1270
	struct mv88e6xxx_chip *chip = ds->priv;
1271 1272
	u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
		MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
1273
	int err;
1274

1275
	if (!chip->info->max_vid)
1276 1277
		return -EOPNOTSUPP;

1278
	mutex_lock(&chip->reg_lock);
1279
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1280
	mutex_unlock(&chip->reg_lock);
1281

1282
	return err;
1283 1284
}

1285 1286
static int
mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1287
			    const struct switchdev_obj_port_vlan *vlan)
1288
{
V
Vivien Didelot 已提交
1289
	struct mv88e6xxx_chip *chip = ds->priv;
1290 1291
	int err;

1292
	if (!chip->info->max_vid)
1293 1294
		return -EOPNOTSUPP;

1295 1296 1297 1298 1299 1300 1301 1302
	/* 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;

1303 1304 1305 1306 1307 1308
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */
	return 0;
}

1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352
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);
}

1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375
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;
}

1376
static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
1377
				    u16 vid, u8 member)
1378
{
1379
	struct mv88e6xxx_vtu_entry vlan;
1380 1381
	int err;

1382
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
1383
	if (err)
1384
		return err;
1385

1386
	vlan.member[port] = member;
1387

1388 1389 1390 1391 1392
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
	if (err)
		return err;

	return mv88e6xxx_broadcast_setup(chip, vid);
1393 1394
}

1395
static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1396
				    const struct switchdev_obj_port_vlan *vlan)
1397
{
V
Vivien Didelot 已提交
1398
	struct mv88e6xxx_chip *chip = ds->priv;
1399 1400
	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1401
	u8 member;
1402 1403
	u16 vid;

1404
	if (!chip->info->max_vid)
1405 1406
		return;

1407
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1408
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1409
	else if (untagged)
1410
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
1411
	else
1412
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
1413

1414
	mutex_lock(&chip->reg_lock);
1415

1416
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
1417
		if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
1418 1419
			dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
				vid, untagged ? 'u' : 't');
1420

1421
	if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1422 1423
		dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
			vlan->vid_end);
1424

1425
	mutex_unlock(&chip->reg_lock);
1426 1427
}

1428
static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
1429
				    int port, u16 vid)
1430
{
1431
	struct mv88e6xxx_vtu_entry vlan;
1432 1433
	int i, err;

1434
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1435
	if (err)
1436
		return err;
1437

1438
	/* Tell switchdev if this VLAN is handled in software */
1439
	if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1440
		return -EOPNOTSUPP;
1441

1442
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1443 1444

	/* keep the VLAN unless all ports are excluded */
1445
	vlan.valid = false;
1446
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1447 1448
		if (vlan.member[i] !=
		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
1449
			vlan.valid = true;
1450 1451 1452 1453
			break;
		}
	}

1454
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1455 1456 1457
	if (err)
		return err;

1458
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
1459 1460
}

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

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

1471
	mutex_lock(&chip->reg_lock);
1472

1473
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
1474 1475 1476
	if (err)
		goto unlock;

1477
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1478
		err = _mv88e6xxx_port_vlan_del(chip, port, vid);
1479 1480 1481 1482
		if (err)
			goto unlock;

		if (vid == pvid) {
1483
			err = mv88e6xxx_port_set_pvid(chip, port, 0);
1484 1485 1486 1487 1488
			if (err)
				goto unlock;
		}
	}

1489
unlock:
1490
	mutex_unlock(&chip->reg_lock);
1491 1492 1493 1494

	return err;
}

1495 1496
static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
				  const unsigned char *addr, u16 vid)
1497
{
V
Vivien Didelot 已提交
1498
	struct mv88e6xxx_chip *chip = ds->priv;
1499
	int err;
1500

1501
	mutex_lock(&chip->reg_lock);
1502 1503
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1504
	mutex_unlock(&chip->reg_lock);
1505 1506

	return err;
1507 1508
}

1509
static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1510
				  const unsigned char *addr, u16 vid)
1511
{
V
Vivien Didelot 已提交
1512
	struct mv88e6xxx_chip *chip = ds->priv;
1513
	int err;
1514

1515
	mutex_lock(&chip->reg_lock);
1516
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1517
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
1518
	mutex_unlock(&chip->reg_lock);
1519

1520
	return err;
1521 1522
}

1523 1524
static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
				      u16 fid, u16 vid, int port,
1525
				      dsa_fdb_dump_cb_t *cb, void *data)
1526
{
1527
	struct mv88e6xxx_atu_entry addr;
1528
	bool is_static;
1529 1530
	int err;

1531
	addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1532
	eth_broadcast_addr(addr.mac);
1533 1534

	do {
1535
		mutex_lock(&chip->reg_lock);
1536
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
1537
		mutex_unlock(&chip->reg_lock);
1538
		if (err)
1539
			return err;
1540

1541
		if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
1542 1543
			break;

1544
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
1545 1546
			continue;

1547 1548
		if (!is_unicast_ether_addr(addr.mac))
			continue;
1549

1550 1551 1552
		is_static = (addr.state ==
			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
		err = cb(addr.mac, vid, is_static, data);
1553 1554
		if (err)
			return err;
1555 1556 1557 1558 1559
	} while (!is_broadcast_ether_addr(addr.mac));

	return err;
}

1560
static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1561
				  dsa_fdb_dump_cb_t *cb, void *data)
1562
{
1563
	struct mv88e6xxx_vtu_entry vlan = {
1564
		.vid = chip->info->max_vid,
1565
	};
1566
	u16 fid;
1567 1568
	int err;

1569
	/* Dump port's default Filtering Information Database (VLAN ID 0) */
1570
	mutex_lock(&chip->reg_lock);
1571
	err = mv88e6xxx_port_get_fid(chip, port, &fid);
1572 1573
	mutex_unlock(&chip->reg_lock);

1574
	if (err)
1575
		return err;
1576

1577
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
1578
	if (err)
1579
		return err;
1580

1581
	/* Dump VLANs' Filtering Information Databases */
1582
	do {
1583
		mutex_lock(&chip->reg_lock);
1584
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1585
		mutex_unlock(&chip->reg_lock);
1586
		if (err)
1587
			return err;
1588 1589 1590 1591

		if (!vlan.valid)
			break;

1592
		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1593
						 cb, data);
1594
		if (err)
1595
			return err;
1596
	} while (vlan.vid < chip->info->max_vid);
1597

1598 1599 1600 1601
	return err;
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1602
				   dsa_fdb_dump_cb_t *cb, void *data)
1603
{
V
Vivien Didelot 已提交
1604
	struct mv88e6xxx_chip *chip = ds->priv;
1605

1606
	return mv88e6xxx_port_db_dump(chip, port, cb, data);
1607 1608
}

1609 1610
static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
				struct net_device *br)
1611
{
1612
	struct dsa_switch *ds;
1613
	int port;
1614
	int dev;
1615
	int err;
1616

1617 1618 1619 1620
	/* 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);
1621
			if (err)
1622
				return err;
1623 1624 1625
		}
	}

1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643
	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;
			}
		}
	}

1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654
	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);
1655
	mutex_unlock(&chip->reg_lock);
1656

1657
	return err;
1658 1659
}

1660 1661
static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
					struct net_device *br)
1662
{
V
Vivien Didelot 已提交
1663
	struct mv88e6xxx_chip *chip = ds->priv;
1664

1665
	mutex_lock(&chip->reg_lock);
1666 1667 1668
	if (mv88e6xxx_bridge_map(chip, br) ||
	    mv88e6xxx_port_vlan_map(chip, port))
		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
1669
	mutex_unlock(&chip->reg_lock);
1670 1671
}

1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701
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);
}

1702 1703 1704 1705 1706 1707 1708 1709
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->reset)
		return chip->info->ops->reset(chip);

	return 0;
}

1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722
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);
	}
}

1723
static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1724
{
1725
	int i, err;
1726

1727
	/* Set all ports to the Disabled state */
1728
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
1729
		err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
1730 1731
		if (err)
			return err;
1732 1733
	}

1734 1735 1736
	/* Wait for transmit queues to drain,
	 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
	 */
1737 1738
	usleep_range(2000, 4000);

1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749
	return 0;
}

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

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

1750
	mv88e6xxx_hardware_reset(chip);
1751

1752
	return mv88e6xxx_software_reset(chip);
1753 1754
}

1755
static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
1756 1757
				   enum mv88e6xxx_frame_mode frame,
				   enum mv88e6xxx_egress_mode egress, u16 etype)
1758 1759 1760
{
	int err;

1761 1762 1763 1764
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
1765 1766 1767
	if (err)
		return err;

1768 1769 1770 1771 1772 1773 1774 1775
	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;
1776 1777
}

1778
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1779
{
1780
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
1781
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
1782
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
1783
}
1784

1785 1786 1787
static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
1788
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
1789
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
1790
}
1791

1792 1793 1794 1795
static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port,
				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
1796 1797
				       MV88E6XXX_EGRESS_MODE_ETHERTYPE,
				       ETH_P_EDSA);
1798
}
1799

1800 1801 1802 1803
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);
1804

1805
	if (dsa_is_user_port(chip->ds, port))
1806
		return mv88e6xxx_set_port_mode_normal(chip, port);
1807

1808 1809 1810
	/* 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);
1811

1812 1813
	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
		return mv88e6xxx_set_port_mode_edsa(chip, port);
1814

1815
	return -EINVAL;
1816 1817
}

1818
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
1819
{
1820
	bool message = dsa_is_dsa_port(chip->ds, port);
1821

1822
	return mv88e6xxx_port_set_message_port(chip, port, message);
1823
}
1824

1825
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
1826
{
1827 1828
	struct dsa_switch *ds = chip->ds;
	bool flood;
1829

1830
	/* Upstream ports flood frames with unknown unicast or multicast DA */
1831
	flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
1832 1833 1834
	if (chip->info->ops->port_set_egress_floods)
		return chip->info->ops->port_set_egress_floods(chip, port,
							       flood, flood);
1835

1836
	return 0;
1837 1838
}

1839 1840 1841
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
1842 1843
	if (chip->info->ops->serdes_power)
		return chip->info->ops->serdes_power(chip, port, on);
1844

1845
	return 0;
1846 1847
}

1848 1849 1850 1851 1852 1853
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

1854
	upstream_port = dsa_upstream_port(ds, port);
1855 1856 1857 1858 1859 1860 1861
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877
	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;
		}
	}

1878 1879 1880
	return 0;
}

1881
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
1882
{
1883
	struct dsa_switch *ds = chip->ds;
1884
	int err;
1885
	u16 reg;
1886

1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900
	/* 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;
1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915

	/* 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.
	 */
1916 1917 1918 1919
	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);
1920 1921
	if (err)
		return err;
1922

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

1927
	err = mv88e6xxx_setup_egress_floods(chip, port);
1928 1929 1930
	if (err)
		return err;

1931 1932 1933
	/* 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.
1934
	 */
1935 1936 1937 1938 1939
	if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
		err = mv88e6xxx_serdes_power(chip, port, true);
		if (err)
			return err;
	}
1940

1941
	/* Port Control 2: don't force a good FCS, set the maximum frame size to
1942
	 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
1943 1944 1945
	 * 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.
1946
	 */
1947 1948 1949
	err = mv88e6xxx_port_set_map_da(chip, port);
	if (err)
		return err;
1950

1951 1952 1953
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
1954

1955
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
1956
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
1957 1958 1959
	if (err)
		return err;

1960 1961
	if (chip->info->ops->port_set_jumbo_size) {
		err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
1962 1963 1964 1965
		if (err)
			return err;
	}

1966 1967 1968 1969 1970
	/* 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.
	 */
1971
	reg = 1 << port;
1972 1973
	/* Disable learning for CPU port */
	if (dsa_is_cpu_port(ds, port))
1974
		reg = 0;
1975

1976 1977
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
1978 1979
	if (err)
		return err;
1980 1981

	/* Egress rate control 2: disable egress rate control. */
1982 1983
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
				   0x0000);
1984 1985
	if (err)
		return err;
1986

1987 1988
	if (chip->info->ops->port_pause_limit) {
		err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
1989 1990
		if (err)
			return err;
1991
	}
1992

1993 1994 1995 1996 1997 1998
	if (chip->info->ops->port_disable_learn_limit) {
		err = chip->info->ops->port_disable_learn_limit(chip, port);
		if (err)
			return err;
	}

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

2005 2006
	if (chip->info->ops->port_tag_remap) {
		err = chip->info->ops->port_tag_remap(chip, port);
2007 2008
		if (err)
			return err;
2009 2010
	}

2011 2012
	if (chip->info->ops->port_egress_rate_limiting) {
		err = chip->info->ops->port_egress_rate_limiting(chip, port);
2013 2014
		if (err)
			return err;
2015 2016
	}

2017
	err = mv88e6xxx_setup_message_port(chip, port);
2018 2019
	if (err)
		return err;
2020

2021
	/* Port based VLAN map: give each port the same default address
2022 2023
	 * database, and allow bidirectional communication between the
	 * CPU and DSA port(s), and the other ports.
2024
	 */
2025
	err = mv88e6xxx_port_set_fid(chip, port, 0);
2026 2027
	if (err)
		return err;
2028

2029
	err = mv88e6xxx_port_vlan_map(chip, port);
2030 2031
	if (err)
		return err;
2032 2033 2034 2035

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

2039 2040 2041 2042
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
2043
	int err;
2044 2045

	mutex_lock(&chip->reg_lock);
2046
	err = mv88e6xxx_serdes_power(chip, port, true);
2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057
	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);
2058 2059
	if (mv88e6xxx_serdes_power(chip, port, false))
		dev_err(chip->dev, "failed to power off SERDES\n");
2060 2061 2062
	mutex_unlock(&chip->reg_lock);
}

2063 2064 2065
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
2066
	struct mv88e6xxx_chip *chip = ds->priv;
2067 2068 2069
	int err;

	mutex_lock(&chip->reg_lock);
2070
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2071 2072 2073 2074 2075
	mutex_unlock(&chip->reg_lock);

	return err;
}

2076
static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
2077
{
2078
	struct dsa_switch *ds = chip->ds;
2079
	int err;
2080

2081
	/* Disable remote management, and set the switch's DSA device number. */
2082 2083
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL2,
				 MV88E6XXX_G1_CTL2_MULTIPLE_CASCADE |
2084
				 (ds->index & 0x1f));
2085 2086 2087
	if (err)
		return err;

2088
	/* Configure the IP ToS mapping registers. */
2089
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_0, 0x0000);
2090
	if (err)
2091
		return err;
2092
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_1, 0x0000);
2093
	if (err)
2094
		return err;
2095
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_2, 0x5555);
2096
	if (err)
2097
		return err;
2098
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_3, 0x5555);
2099
	if (err)
2100
		return err;
2101
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_4, 0xaaaa);
2102
	if (err)
2103
		return err;
2104
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_5, 0xaaaa);
2105
	if (err)
2106
		return err;
2107
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_6, 0xffff);
2108
	if (err)
2109
		return err;
2110
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_7, 0xffff);
2111
	if (err)
2112
		return err;
2113 2114

	/* Configure the IEEE 802.1p priority mapping register. */
2115
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IEEE_PRI, 0xfa41);
2116
	if (err)
2117
		return err;
2118

2119 2120 2121 2122 2123
	/* Initialize the statistics unit */
	err = mv88e6xxx_stats_set_histogram(chip);
	if (err)
		return err;

2124
	return mv88e6xxx_g1_stats_clear(chip);
2125 2126
}

2127
static int mv88e6xxx_setup(struct dsa_switch *ds)
2128
{
V
Vivien Didelot 已提交
2129
	struct mv88e6xxx_chip *chip = ds->priv;
2130
	int err;
2131 2132
	int i;

2133
	chip->ds = ds;
2134
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
2135

2136
	mutex_lock(&chip->reg_lock);
2137

2138
	/* Setup Switch Port Registers */
2139
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2140 2141 2142
		if (dsa_is_unused_port(ds, i))
			continue;

2143 2144 2145 2146 2147 2148 2149
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

	/* Setup Switch Global 1 Registers */
	err = mv88e6xxx_g1_setup(chip);
2150 2151 2152
	if (err)
		goto unlock;

2153
	/* Setup Switch Global 2 Registers */
2154
	if (chip->info->global2_addr) {
2155
		err = mv88e6xxx_g2_setup(chip);
2156 2157 2158
		if (err)
			goto unlock;
	}
2159

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

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

2168 2169 2170 2171
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

2172 2173 2174 2175
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

2176 2177 2178 2179
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

2180 2181 2182 2183
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

2184 2185 2186 2187
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

2188 2189 2190 2191
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

2192 2193 2194
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
2195

2196
	/* Setup PTP Hardware Clock and timestamping */
2197 2198 2199 2200
	if (chip->info->ptp_support) {
		err = mv88e6xxx_ptp_setup(chip);
		if (err)
			goto unlock;
2201 2202 2203 2204

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
2205 2206
	}

2207
unlock:
2208
	mutex_unlock(&chip->reg_lock);
2209

2210
	return err;
2211 2212
}

2213
static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
2214
{
2215 2216
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2217 2218
	u16 val;
	int err;
2219

2220 2221 2222
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

2223
	mutex_lock(&chip->reg_lock);
2224
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
2225
	mutex_unlock(&chip->reg_lock);
2226

2227 2228 2229 2230 2231
	if (reg == MII_PHYSID2) {
		/* Some internal PHYS don't have a model number.  Use
		 * the mv88e6390 family model number instead.
		 */
		if (!(val & 0x3f0))
2232
			val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
2233 2234
	}

2235
	return err ? err : val;
2236 2237
}

2238
static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
2239
{
2240 2241
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2242
	int err;
2243

2244 2245 2246
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

2247
	mutex_lock(&chip->reg_lock);
2248
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
2249
	mutex_unlock(&chip->reg_lock);
2250 2251

	return err;
2252 2253
}

2254
static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
2255 2256
				   struct device_node *np,
				   bool external)
2257 2258
{
	static int index;
2259
	struct mv88e6xxx_mdio_bus *mdio_bus;
2260 2261 2262
	struct mii_bus *bus;
	int err;

2263 2264 2265 2266 2267 2268 2269 2270 2271
	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;
	}

2272
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
2273 2274 2275
	if (!bus)
		return -ENOMEM;

2276
	mdio_bus = bus->priv;
2277
	mdio_bus->bus = bus;
2278
	mdio_bus->chip = chip;
2279 2280
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
2281

2282 2283
	if (np) {
		bus->name = np->full_name;
2284
		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
2285 2286 2287 2288 2289 2290 2291
	} 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;
2292
	bus->parent = chip->dev;
2293

2294 2295
	if (np)
		err = of_mdiobus_register(bus, np);
2296 2297 2298
	else
		err = mdiobus_register(bus);
	if (err) {
2299
		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
2300
		return err;
2301
	}
2302 2303 2304 2305 2306

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

	return 0;
2309
}
2310

2311 2312 2313 2314 2315
static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
	{ .compatible = "marvell,mv88e6xxx-mdio-external",
	  .data = (void *)true },
	{ },
};
2316

2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329
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);
	}
}

2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353
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);
2354 2355
			if (err) {
				mv88e6xxx_mdios_unregister(chip);
2356
				return err;
2357
			}
2358 2359 2360 2361
		}
	}

	return 0;
2362 2363
}

2364 2365
static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
2366
	struct mv88e6xxx_chip *chip = ds->priv;
2367 2368 2369 2370 2371 2372 2373

	return chip->eeprom_len;
}

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

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

2380 2381
	mutex_lock(&chip->reg_lock);
	err = chip->info->ops->get_eeprom(chip, eeprom, data);
2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394
	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 已提交
2395
	struct mv88e6xxx_chip *chip = ds->priv;
2396 2397
	int err;

2398 2399 2400
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

2401 2402 2403 2404
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

	mutex_lock(&chip->reg_lock);
2405
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
2406 2407 2408 2409 2410
	mutex_unlock(&chip->reg_lock);

	return err;
}

2411
static const struct mv88e6xxx_ops mv88e6085_ops = {
2412
	/* MV88E6XXX_FAMILY_6097 */
2413
	.irl_init_all = mv88e6352_g2_irl_init_all,
2414
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2415 2416
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2417
	.port_set_link = mv88e6xxx_port_set_link,
2418
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2419
	.port_set_speed = mv88e6185_port_set_speed,
2420
	.port_tag_remap = mv88e6095_port_tag_remap,
2421
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2422
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2423
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2424
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2425
	.port_pause_limit = mv88e6097_port_pause_limit,
2426
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2427
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2428
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2429
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2430 2431
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2432
	.stats_get_stats = mv88e6095_stats_get_stats,
2433 2434
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2435
	.watchdog_ops = &mv88e6097_watchdog_ops,
2436
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2437
	.pot_clear = mv88e6xxx_g2_pot_clear,
2438 2439
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2440
	.reset = mv88e6185_g1_reset,
2441
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2442
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2443 2444 2445
};

static const struct mv88e6xxx_ops mv88e6095_ops = {
2446
	/* MV88E6XXX_FAMILY_6095 */
2447
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2448 2449
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2450
	.port_set_link = mv88e6xxx_port_set_link,
2451
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2452
	.port_set_speed = mv88e6185_port_set_speed,
2453
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2454
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2455
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2456
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2457
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2458 2459
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2460
	.stats_get_stats = mv88e6095_stats_get_stats,
2461
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2462 2463
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2464
	.reset = mv88e6185_g1_reset,
2465
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2466
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2467 2468
};

2469
static const struct mv88e6xxx_ops mv88e6097_ops = {
2470
	/* MV88E6XXX_FAMILY_6097 */
2471
	.irl_init_all = mv88e6352_g2_irl_init_all,
2472 2473 2474 2475 2476 2477
	.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,
2478
	.port_tag_remap = mv88e6095_port_tag_remap,
2479
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2480
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2481
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2482
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2483
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
2484
	.port_pause_limit = mv88e6097_port_pause_limit,
2485
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2486
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2487
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2488
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2489 2490 2491
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
	.stats_get_stats = mv88e6095_stats_get_stats,
2492 2493
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2494
	.watchdog_ops = &mv88e6097_watchdog_ops,
2495
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2496
	.pot_clear = mv88e6xxx_g2_pot_clear,
2497
	.reset = mv88e6352_g1_reset,
2498
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2499
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2500 2501
};

2502
static const struct mv88e6xxx_ops mv88e6123_ops = {
2503
	/* MV88E6XXX_FAMILY_6165 */
2504
	.irl_init_all = mv88e6352_g2_irl_init_all,
2505
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2506 2507
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2508
	.port_set_link = mv88e6xxx_port_set_link,
2509
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2510
	.port_set_speed = mv88e6185_port_set_speed,
2511
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2512
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2513
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2514
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2515
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2516
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2517 2518
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2519
	.stats_get_stats = mv88e6095_stats_get_stats,
2520 2521
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2522
	.watchdog_ops = &mv88e6097_watchdog_ops,
2523
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2524
	.pot_clear = mv88e6xxx_g2_pot_clear,
2525
	.reset = mv88e6352_g1_reset,
2526
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2527
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2528 2529 2530
};

static const struct mv88e6xxx_ops mv88e6131_ops = {
2531
	/* MV88E6XXX_FAMILY_6185 */
2532
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2533 2534
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2535
	.port_set_link = mv88e6xxx_port_set_link,
2536
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2537
	.port_set_speed = mv88e6185_port_set_speed,
2538
	.port_tag_remap = mv88e6095_port_tag_remap,
2539
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2540
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2541
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2542
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
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
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2547
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2548 2549
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2550
	.stats_get_stats = mv88e6095_stats_get_stats,
2551 2552
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2553
	.watchdog_ops = &mv88e6097_watchdog_ops,
2554
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2555 2556
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2557
	.reset = mv88e6185_g1_reset,
2558
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2559
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2560 2561
};

2562 2563
static const struct mv88e6xxx_ops mv88e6141_ops = {
	/* MV88E6XXX_FAMILY_6341 */
2564
	.irl_init_all = mv88e6352_g2_irl_init_all,
2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577
	.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,
2578
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2579
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2580
	.port_pause_limit = mv88e6097_port_pause_limit,
2581 2582 2583
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
2584
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2585 2586 2587
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
2588 2589
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
2590 2591
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
2592
	.pot_clear = mv88e6xxx_g2_pot_clear,
2593
	.reset = mv88e6352_g1_reset,
2594
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2595
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2596
	.gpio_ops = &mv88e6352_gpio_ops,
2597 2598
};

2599
static const struct mv88e6xxx_ops mv88e6161_ops = {
2600
	/* MV88E6XXX_FAMILY_6165 */
2601
	.irl_init_all = mv88e6352_g2_irl_init_all,
2602
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2603 2604
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2605
	.port_set_link = mv88e6xxx_port_set_link,
2606
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2607
	.port_set_speed = mv88e6185_port_set_speed,
2608
	.port_tag_remap = mv88e6095_port_tag_remap,
2609
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2610
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2611
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2612
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2613
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2614
	.port_pause_limit = mv88e6097_port_pause_limit,
2615
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2616
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2617
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2618
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2619 2620
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2621
	.stats_get_stats = mv88e6095_stats_get_stats,
2622 2623
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2624
	.watchdog_ops = &mv88e6097_watchdog_ops,
2625
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2626
	.pot_clear = mv88e6xxx_g2_pot_clear,
2627
	.reset = mv88e6352_g1_reset,
2628
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2629
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2630 2631 2632
};

static const struct mv88e6xxx_ops mv88e6165_ops = {
2633
	/* MV88E6XXX_FAMILY_6165 */
2634
	.irl_init_all = mv88e6352_g2_irl_init_all,
2635
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2636 2637
	.phy_read = mv88e6165_phy_read,
	.phy_write = mv88e6165_phy_write,
2638
	.port_set_link = mv88e6xxx_port_set_link,
2639
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2640
	.port_set_speed = mv88e6185_port_set_speed,
2641
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2642
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2643
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2644
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2645 2646
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2647
	.stats_get_stats = mv88e6095_stats_get_stats,
2648 2649
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2650
	.watchdog_ops = &mv88e6097_watchdog_ops,
2651
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2652
	.pot_clear = mv88e6xxx_g2_pot_clear,
2653
	.reset = mv88e6352_g1_reset,
2654
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2655
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2656 2657 2658
};

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

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

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

static const struct mv88e6xxx_ops mv88e6176_ops = {
2765
	/* MV88E6XXX_FAMILY_6352 */
2766
	.irl_init_all = mv88e6352_g2_irl_init_all,
2767 2768
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
2769
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2770 2771
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2772
	.port_set_link = mv88e6xxx_port_set_link,
2773
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2774
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
2775
	.port_set_speed = mv88e6352_port_set_speed,
2776
	.port_tag_remap = mv88e6095_port_tag_remap,
2777
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2778
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2779
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2780
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2781
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2782
	.port_pause_limit = mv88e6097_port_pause_limit,
2783
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2784
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2785
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2786
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2787 2788
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2789
	.stats_get_stats = mv88e6095_stats_get_stats,
2790 2791
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2792
	.watchdog_ops = &mv88e6097_watchdog_ops,
2793
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2794
	.pot_clear = mv88e6xxx_g2_pot_clear,
2795
	.reset = mv88e6352_g1_reset,
2796
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2797
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2798
	.serdes_power = mv88e6352_serdes_power,
2799
	.gpio_ops = &mv88e6352_gpio_ops,
2800 2801 2802
};

static const struct mv88e6xxx_ops mv88e6185_ops = {
2803
	/* MV88E6XXX_FAMILY_6185 */
2804
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2805 2806
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2807
	.port_set_link = mv88e6xxx_port_set_link,
2808
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2809
	.port_set_speed = mv88e6185_port_set_speed,
2810
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2811
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2812
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
2813
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2814
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2815
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2816 2817
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2818
	.stats_get_stats = mv88e6095_stats_get_stats,
2819 2820
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2821
	.watchdog_ops = &mv88e6097_watchdog_ops,
2822
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2823 2824
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2825
	.reset = mv88e6185_g1_reset,
2826
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2827
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2828 2829
};

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

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

static const struct mv88e6xxx_ops mv88e6191_ops = {
2903
	/* MV88E6XXX_FAMILY_6390 */
2904
	.irl_init_all = mv88e6390_g2_irl_init_all,
2905 2906
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
2907 2908 2909 2910 2911 2912 2913
	.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,
2914
	.port_tag_remap = mv88e6390_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_pause_limit = mv88e6390_port_pause_limit,
2919
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2920
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2921
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
2922
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
2923 2924
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
2925
	.stats_get_stats = mv88e6390_stats_get_stats,
2926 2927
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
2928
	.watchdog_ops = &mv88e6390_watchdog_ops,
2929
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
2930
	.pot_clear = mv88e6xxx_g2_pot_clear,
2931
	.reset = mv88e6352_g1_reset,
2932 2933
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
2934
	.serdes_power = mv88e6390_serdes_power,
2935 2936
};

2937
static const struct mv88e6xxx_ops mv88e6240_ops = {
2938
	/* MV88E6XXX_FAMILY_6352 */
2939
	.irl_init_all = mv88e6352_g2_irl_init_all,
2940 2941
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
2942
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2943 2944
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2945
	.port_set_link = mv88e6xxx_port_set_link,
2946
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2947
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
2948
	.port_set_speed = mv88e6352_port_set_speed,
2949
	.port_tag_remap = mv88e6095_port_tag_remap,
2950
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2951
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2952
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2953
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2954
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2955
	.port_pause_limit = mv88e6097_port_pause_limit,
2956
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2957
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2958
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2959
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2960 2961
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2962
	.stats_get_stats = mv88e6095_stats_get_stats,
2963 2964
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2965
	.watchdog_ops = &mv88e6097_watchdog_ops,
2966
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2967
	.pot_clear = mv88e6xxx_g2_pot_clear,
2968
	.reset = mv88e6352_g1_reset,
2969
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2970
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2971
	.serdes_power = mv88e6352_serdes_power,
2972
	.gpio_ops = &mv88e6352_gpio_ops,
2973
	.avb_ops = &mv88e6352_avb_ops,
2974 2975
};

2976
static const struct mv88e6xxx_ops mv88e6290_ops = {
2977
	/* MV88E6XXX_FAMILY_6390 */
2978
	.irl_init_all = mv88e6390_g2_irl_init_all,
2979 2980
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
2981 2982 2983 2984 2985 2986 2987
	.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,
2988
	.port_tag_remap = mv88e6390_port_tag_remap,
2989
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2990
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2991
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2992
	.port_pause_limit = mv88e6390_port_pause_limit,
2993
	.port_set_cmode = mv88e6390x_port_set_cmode,
2994
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2995
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2996
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
2997
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
2998 2999
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3000
	.stats_get_stats = mv88e6390_stats_get_stats,
3001 3002
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3003
	.watchdog_ops = &mv88e6390_watchdog_ops,
3004
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3005
	.pot_clear = mv88e6xxx_g2_pot_clear,
3006
	.reset = mv88e6352_g1_reset,
3007 3008
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3009
	.serdes_power = mv88e6390_serdes_power,
3010
	.gpio_ops = &mv88e6352_gpio_ops,
3011
	.avb_ops = &mv88e6390_avb_ops,
3012 3013
};

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

static const struct mv88e6xxx_ops mv88e6321_ops = {
3051
	/* MV88E6XXX_FAMILY_6320 */
3052
	.irl_init_all = mv88e6352_g2_irl_init_all,
3053 3054
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3055
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3056 3057
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3058
	.port_set_link = mv88e6xxx_port_set_link,
3059
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3060
	.port_set_speed = mv88e6185_port_set_speed,
3061
	.port_tag_remap = mv88e6095_port_tag_remap,
3062
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3063
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3064
	.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
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3069
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3070
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3071
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3072 3073
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3074
	.stats_get_stats = mv88e6320_stats_get_stats,
3075 3076
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3077
	.reset = mv88e6352_g1_reset,
3078
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3079
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3080
	.gpio_ops = &mv88e6352_gpio_ops,
3081
	.avb_ops = &mv88e6352_avb_ops,
3082 3083
};

3084 3085
static const struct mv88e6xxx_ops mv88e6341_ops = {
	/* MV88E6XXX_FAMILY_6341 */
3086
	.irl_init_all = mv88e6352_g2_irl_init_all,
3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099
	.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,
3100
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3101
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3102
	.port_pause_limit = mv88e6097_port_pause_limit,
3103 3104 3105
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3106
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3107 3108 3109
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
3110 3111
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3112 3113
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
3114
	.pot_clear = mv88e6xxx_g2_pot_clear,
3115
	.reset = mv88e6352_g1_reset,
3116
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3117
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3118
	.gpio_ops = &mv88e6352_gpio_ops,
3119
	.avb_ops = &mv88e6390_avb_ops,
3120 3121
};

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

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

static const struct mv88e6xxx_ops mv88e6352_ops = {
3192
	/* MV88E6XXX_FAMILY_6352 */
3193
	.irl_init_all = mv88e6352_g2_irl_init_all,
3194 3195
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3196
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3197 3198
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3199
	.port_set_link = mv88e6xxx_port_set_link,
3200
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3201
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3202
	.port_set_speed = mv88e6352_port_set_speed,
3203
	.port_tag_remap = mv88e6095_port_tag_remap,
3204
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3205
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3206
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3207
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3208
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3209
	.port_pause_limit = mv88e6097_port_pause_limit,
3210
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3211
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3212
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3213
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3214 3215
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3216
	.stats_get_stats = mv88e6095_stats_get_stats,
3217 3218
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3219
	.watchdog_ops = &mv88e6097_watchdog_ops,
3220
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3221
	.pot_clear = mv88e6xxx_g2_pot_clear,
3222
	.reset = mv88e6352_g1_reset,
3223
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3224
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3225
	.serdes_power = mv88e6352_serdes_power,
3226
	.gpio_ops = &mv88e6352_gpio_ops,
3227
	.avb_ops = &mv88e6352_avb_ops,
3228 3229 3230
	.serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
	.serdes_get_strings = mv88e6352_serdes_get_strings,
	.serdes_get_stats = mv88e6352_serdes_get_stats,
3231 3232
};

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

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

3313 3314
static const struct mv88e6xxx_info mv88e6xxx_table[] = {
	[MV88E6085] = {
3315
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
3316 3317 3318 3319
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6085",
		.num_databases = 4096,
		.num_ports = 10,
3320
		.max_vid = 4095,
3321
		.port_base_addr = 0x10,
3322
		.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_DSA,
3331
		.ops = &mv88e6085_ops,
3332 3333 3334
	},

	[MV88E6095] = {
3335
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
3336 3337 3338 3339
		.family = MV88E6XXX_FAMILY_6095,
		.name = "Marvell 88E6095/88E6095F",
		.num_databases = 256,
		.num_ports = 11,
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 = 8,
3346
		.atu_move_port_mask = 0xf,
3347
		.multi_chip = true,
3348
		.tag_protocol = DSA_TAG_PROTO_DSA,
3349
		.ops = &mv88e6095_ops,
3350 3351
	},

3352
	[MV88E6097] = {
3353
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
3354 3355 3356 3357
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6097/88E6097F",
		.num_databases = 4096,
		.num_ports = 11,
3358
		.max_vid = 4095,
3359 3360
		.port_base_addr = 0x10,
		.global1_addr = 0x1b,
3361
		.global2_addr = 0x1c,
3362
		.age_time_coeff = 15000,
3363
		.g1_irqs = 8,
3364
		.g2_irqs = 10,
3365
		.atu_move_port_mask = 0xf,
3366
		.pvt = true,
3367
		.multi_chip = true,
3368
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3369 3370 3371
		.ops = &mv88e6097_ops,
	},

3372
	[MV88E6123] = {
3373
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
3374 3375 3376 3377
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6123",
		.num_databases = 4096,
		.num_ports = 3,
3378
		.max_vid = 4095,
3379
		.port_base_addr = 0x10,
3380
		.global1_addr = 0x1b,
3381
		.global2_addr = 0x1c,
3382
		.age_time_coeff = 15000,
3383
		.g1_irqs = 9,
3384
		.g2_irqs = 10,
3385
		.atu_move_port_mask = 0xf,
3386
		.pvt = true,
3387
		.multi_chip = true,
3388
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3389
		.ops = &mv88e6123_ops,
3390 3391 3392
	},

	[MV88E6131] = {
3393
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
3394 3395 3396 3397
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6131",
		.num_databases = 256,
		.num_ports = 8,
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
		.atu_move_port_mask = 0xf,
3405
		.multi_chip = true,
3406
		.tag_protocol = DSA_TAG_PROTO_DSA,
3407
		.ops = &mv88e6131_ops,
3408 3409
	},

3410
	[MV88E6141] = {
3411
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
3412 3413 3414 3415
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
		.num_ports = 6,
3416
		.num_gpio = 11,
3417
		.max_vid = 4095,
3418 3419
		.port_base_addr = 0x10,
		.global1_addr = 0x1b,
3420
		.global2_addr = 0x1c,
3421 3422
		.age_time_coeff = 3750,
		.atu_move_port_mask = 0x1f,
3423
		.g2_irqs = 10,
3424
		.pvt = true,
3425
		.multi_chip = true,
3426 3427 3428 3429
		.tag_protocol = DSA_TAG_PROTO_EDSA,
		.ops = &mv88e6141_ops,
	},

3430
	[MV88E6161] = {
3431
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
3432 3433 3434 3435
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6161",
		.num_databases = 4096,
		.num_ports = 6,
3436
		.max_vid = 4095,
3437
		.port_base_addr = 0x10,
3438
		.global1_addr = 0x1b,
3439
		.global2_addr = 0x1c,
3440
		.age_time_coeff = 15000,
3441
		.g1_irqs = 9,
3442
		.g2_irqs = 10,
3443
		.atu_move_port_mask = 0xf,
3444
		.pvt = true,
3445
		.multi_chip = true,
3446
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3447
		.ops = &mv88e6161_ops,
3448 3449 3450
	},

	[MV88E6165] = {
3451
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
3452 3453 3454 3455
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6165",
		.num_databases = 4096,
		.num_ports = 6,
3456
		.max_vid = 4095,
3457
		.port_base_addr = 0x10,
3458
		.global1_addr = 0x1b,
3459
		.global2_addr = 0x1c,
3460
		.age_time_coeff = 15000,
3461
		.g1_irqs = 9,
3462
		.g2_irqs = 10,
3463
		.atu_move_port_mask = 0xf,
3464
		.pvt = true,
3465
		.multi_chip = true,
3466
		.tag_protocol = DSA_TAG_PROTO_DSA,
3467
		.ops = &mv88e6165_ops,
3468 3469 3470
	},

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

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

	[MV88E6175] = {
3512
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
3513 3514 3515 3516
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6175",
		.num_databases = 4096,
		.num_ports = 7,
3517
		.max_vid = 4095,
3518
		.port_base_addr = 0x10,
3519
		.global1_addr = 0x1b,
3520
		.global2_addr = 0x1c,
3521
		.age_time_coeff = 15000,
3522
		.g1_irqs = 9,
3523
		.g2_irqs = 10,
3524
		.atu_move_port_mask = 0xf,
3525
		.pvt = true,
3526
		.multi_chip = true,
3527
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3528
		.ops = &mv88e6175_ops,
3529 3530 3531
	},

	[MV88E6176] = {
3532
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
3533 3534 3535 3536
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6176",
		.num_databases = 4096,
		.num_ports = 7,
3537
		.num_gpio = 15,
3538
		.max_vid = 4095,
3539
		.port_base_addr = 0x10,
3540
		.global1_addr = 0x1b,
3541
		.global2_addr = 0x1c,
3542
		.age_time_coeff = 15000,
3543
		.g1_irqs = 9,
3544
		.g2_irqs = 10,
3545
		.atu_move_port_mask = 0xf,
3546
		.pvt = true,
3547
		.multi_chip = true,
3548
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3549
		.ops = &mv88e6176_ops,
3550 3551 3552
	},

	[MV88E6185] = {
3553
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
3554 3555 3556 3557
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6185",
		.num_databases = 256,
		.num_ports = 10,
3558
		.max_vid = 4095,
3559
		.port_base_addr = 0x10,
3560
		.global1_addr = 0x1b,
3561
		.global2_addr = 0x1c,
3562
		.age_time_coeff = 15000,
3563
		.g1_irqs = 8,
3564
		.atu_move_port_mask = 0xf,
3565
		.multi_chip = true,
3566
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3567
		.ops = &mv88e6185_ops,
3568 3569
	},

3570
	[MV88E6190] = {
3571
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
3572 3573 3574 3575
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3576
		.num_gpio = 16,
3577
		.max_vid = 8191,
3578 3579
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3580
		.global2_addr = 0x1c,
3581
		.tag_protocol = DSA_TAG_PROTO_DSA,
3582
		.age_time_coeff = 3750,
3583
		.g1_irqs = 9,
3584
		.g2_irqs = 14,
3585
		.pvt = true,
3586
		.multi_chip = true,
3587
		.atu_move_port_mask = 0x1f,
3588 3589 3590 3591
		.ops = &mv88e6190_ops,
	},

	[MV88E6190X] = {
3592
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
3593 3594 3595 3596
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3597
		.num_gpio = 16,
3598
		.max_vid = 8191,
3599 3600
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3601
		.global2_addr = 0x1c,
3602
		.age_time_coeff = 3750,
3603
		.g1_irqs = 9,
3604
		.g2_irqs = 14,
3605
		.atu_move_port_mask = 0x1f,
3606
		.pvt = true,
3607
		.multi_chip = true,
3608
		.tag_protocol = DSA_TAG_PROTO_DSA,
3609 3610 3611 3612
		.ops = &mv88e6190x_ops,
	},

	[MV88E6191] = {
3613
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
3614 3615 3616 3617
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6191",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3618
		.max_vid = 8191,
3619 3620
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3621
		.global2_addr = 0x1c,
3622
		.age_time_coeff = 3750,
3623
		.g1_irqs = 9,
3624
		.g2_irqs = 14,
3625
		.atu_move_port_mask = 0x1f,
3626
		.pvt = true,
3627
		.multi_chip = true,
3628
		.tag_protocol = DSA_TAG_PROTO_DSA,
3629
		.ptp_support = true,
3630
		.ops = &mv88e6191_ops,
3631 3632
	},

3633
	[MV88E6240] = {
3634
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
3635 3636 3637 3638
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6240",
		.num_databases = 4096,
		.num_ports = 7,
3639
		.num_gpio = 15,
3640
		.max_vid = 4095,
3641
		.port_base_addr = 0x10,
3642
		.global1_addr = 0x1b,
3643
		.global2_addr = 0x1c,
3644
		.age_time_coeff = 15000,
3645
		.g1_irqs = 9,
3646
		.g2_irqs = 10,
3647
		.atu_move_port_mask = 0xf,
3648
		.pvt = true,
3649
		.multi_chip = true,
3650
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3651
		.ptp_support = true,
3652
		.ops = &mv88e6240_ops,
3653 3654
	},

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

3677
	[MV88E6320] = {
3678
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
3679 3680 3681 3682
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6320",
		.num_databases = 4096,
		.num_ports = 7,
3683
		.num_gpio = 15,
3684
		.max_vid = 4095,
3685
		.port_base_addr = 0x10,
3686
		.global1_addr = 0x1b,
3687
		.global2_addr = 0x1c,
3688
		.age_time_coeff = 15000,
3689
		.g1_irqs = 8,
3690
		.atu_move_port_mask = 0xf,
3691
		.pvt = true,
3692
		.multi_chip = true,
3693
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3694
		.ptp_support = true,
3695
		.ops = &mv88e6320_ops,
3696 3697 3698
	},

	[MV88E6321] = {
3699
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
3700 3701 3702 3703
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6321",
		.num_databases = 4096,
		.num_ports = 7,
3704
		.num_gpio = 15,
3705
		.max_vid = 4095,
3706
		.port_base_addr = 0x10,
3707
		.global1_addr = 0x1b,
3708
		.global2_addr = 0x1c,
3709
		.age_time_coeff = 15000,
3710
		.g1_irqs = 8,
3711
		.atu_move_port_mask = 0xf,
3712
		.multi_chip = true,
3713
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3714
		.ptp_support = true,
3715
		.ops = &mv88e6321_ops,
3716 3717
	},

3718
	[MV88E6341] = {
3719
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
3720 3721 3722 3723
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
		.num_ports = 6,
3724
		.num_gpio = 11,
3725
		.max_vid = 4095,
3726 3727
		.port_base_addr = 0x10,
		.global1_addr = 0x1b,
3728
		.global2_addr = 0x1c,
3729
		.age_time_coeff = 3750,
3730
		.atu_move_port_mask = 0x1f,
3731
		.g2_irqs = 10,
3732
		.pvt = true,
3733
		.multi_chip = true,
3734
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3735
		.ptp_support = true,
3736 3737 3738
		.ops = &mv88e6341_ops,
	},

3739
	[MV88E6350] = {
3740
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
3741 3742 3743 3744
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6350",
		.num_databases = 4096,
		.num_ports = 7,
3745
		.max_vid = 4095,
3746
		.port_base_addr = 0x10,
3747
		.global1_addr = 0x1b,
3748
		.global2_addr = 0x1c,
3749
		.age_time_coeff = 15000,
3750
		.g1_irqs = 9,
3751
		.g2_irqs = 10,
3752
		.atu_move_port_mask = 0xf,
3753
		.pvt = true,
3754
		.multi_chip = true,
3755
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3756
		.ops = &mv88e6350_ops,
3757 3758 3759
	},

	[MV88E6351] = {
3760
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
3761 3762 3763 3764
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6351",
		.num_databases = 4096,
		.num_ports = 7,
3765
		.max_vid = 4095,
3766
		.port_base_addr = 0x10,
3767
		.global1_addr = 0x1b,
3768
		.global2_addr = 0x1c,
3769
		.age_time_coeff = 15000,
3770
		.g1_irqs = 9,
3771
		.g2_irqs = 10,
3772
		.atu_move_port_mask = 0xf,
3773
		.pvt = true,
3774
		.multi_chip = true,
3775
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3776
		.ops = &mv88e6351_ops,
3777 3778 3779
	},

	[MV88E6352] = {
3780
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
3781 3782 3783 3784
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6352",
		.num_databases = 4096,
		.num_ports = 7,
3785
		.num_gpio = 15,
3786
		.max_vid = 4095,
3787
		.port_base_addr = 0x10,
3788
		.global1_addr = 0x1b,
3789
		.global2_addr = 0x1c,
3790
		.age_time_coeff = 15000,
3791
		.g1_irqs = 9,
3792
		.g2_irqs = 10,
3793
		.atu_move_port_mask = 0xf,
3794
		.pvt = true,
3795
		.multi_chip = true,
3796
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3797
		.ptp_support = true,
3798
		.ops = &mv88e6352_ops,
3799
	},
3800
	[MV88E6390] = {
3801
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
3802 3803 3804 3805
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3806
		.num_gpio = 16,
3807
		.max_vid = 8191,
3808 3809
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3810
		.global2_addr = 0x1c,
3811
		.age_time_coeff = 3750,
3812
		.g1_irqs = 9,
3813
		.g2_irqs = 14,
3814
		.atu_move_port_mask = 0x1f,
3815
		.pvt = true,
3816
		.multi_chip = true,
3817
		.tag_protocol = DSA_TAG_PROTO_DSA,
3818
		.ptp_support = true,
3819 3820 3821
		.ops = &mv88e6390_ops,
	},
	[MV88E6390X] = {
3822
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
3823 3824 3825 3826
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3827
		.num_gpio = 16,
3828
		.max_vid = 8191,
3829 3830
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3831
		.global2_addr = 0x1c,
3832
		.age_time_coeff = 3750,
3833
		.g1_irqs = 9,
3834
		.g2_irqs = 14,
3835
		.atu_move_port_mask = 0x1f,
3836
		.pvt = true,
3837
		.multi_chip = true,
3838
		.tag_protocol = DSA_TAG_PROTO_DSA,
3839
		.ptp_support = true,
3840 3841
		.ops = &mv88e6390x_ops,
	},
3842 3843
};

3844
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
3845
{
3846
	int i;
3847

3848 3849 3850
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
3851 3852 3853 3854

	return NULL;
}

3855
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
3856 3857
{
	const struct mv88e6xxx_info *info;
3858 3859 3860
	unsigned int prod_num, rev;
	u16 id;
	int err;
3861

3862
	mutex_lock(&chip->reg_lock);
3863
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
3864 3865 3866
	mutex_unlock(&chip->reg_lock);
	if (err)
		return err;
3867

3868 3869
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
3870 3871 3872 3873 3874

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

3875
	/* Update the compatible info with the probed one */
3876
	chip->info = info;
3877

3878 3879 3880 3881
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

3882 3883
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
3884 3885 3886 3887

	return 0;
}

3888
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
3889
{
3890
	struct mv88e6xxx_chip *chip;
3891

3892 3893
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
3894 3895
		return NULL;

3896
	chip->dev = dev;
3897

3898
	mutex_init(&chip->reg_lock);
3899
	INIT_LIST_HEAD(&chip->mdios);
3900

3901
	return chip;
3902 3903
}

3904
static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
3905 3906
			      struct mii_bus *bus, int sw_addr)
{
3907
	if (sw_addr == 0)
3908
		chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
3909
	else if (chip->info->multi_chip)
3910
		chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
3911 3912 3913
	else
		return -EINVAL;

3914 3915
	chip->bus = bus;
	chip->sw_addr = sw_addr;
3916 3917 3918 3919

	return 0;
}

3920 3921
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
							int port)
3922
{
V
Vivien Didelot 已提交
3923
	struct mv88e6xxx_chip *chip = ds->priv;
3924

3925
	return chip->info->tag_protocol;
3926 3927
}

3928
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
3929 3930 3931
static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
				       struct device *host_dev, int sw_addr,
				       void **priv)
3932
{
3933
	struct mv88e6xxx_chip *chip;
3934
	struct mii_bus *bus;
3935
	int err;
3936

3937
	bus = dsa_host_dev_to_mii_bus(host_dev);
3938 3939 3940
	if (!bus)
		return NULL;

3941 3942
	chip = mv88e6xxx_alloc_chip(dsa_dev);
	if (!chip)
3943 3944
		return NULL;

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

3948
	err = mv88e6xxx_smi_init(chip, bus, sw_addr);
3949 3950 3951
	if (err)
		goto free;

3952
	err = mv88e6xxx_detect(chip);
3953
	if (err)
3954
		goto free;
3955

3956 3957 3958 3959 3960 3961
	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_switch_reset(chip);
	mutex_unlock(&chip->reg_lock);
	if (err)
		goto free;

3962 3963
	mv88e6xxx_phy_init(chip);

3964
	err = mv88e6xxx_mdios_register(chip, NULL);
3965
	if (err)
3966
		goto free;
3967

3968
	*priv = chip;
3969

3970
	return chip->info->name;
3971
free:
3972
	devm_kfree(dsa_dev, chip);
3973 3974

	return NULL;
3975
}
3976
#endif
3977

3978
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
3979
				      const struct switchdev_obj_port_mdb *mdb)
3980 3981 3982 3983 3984 3985 3986 3987 3988
{
	/* 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,
3989
				   const struct switchdev_obj_port_mdb *mdb)
3990
{
V
Vivien Didelot 已提交
3991
	struct mv88e6xxx_chip *chip = ds->priv;
3992 3993 3994

	mutex_lock(&chip->reg_lock);
	if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
3995
					 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
3996 3997
		dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
			port);
3998 3999 4000 4001 4002 4003
	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 已提交
4004
	struct mv88e6xxx_chip *chip = ds->priv;
4005 4006 4007 4008
	int err;

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4009
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
4010 4011 4012 4013 4014
	mutex_unlock(&chip->reg_lock);

	return err;
}

4015
static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
4016
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
4017
	.probe			= mv88e6xxx_drv_probe,
4018
#endif
4019
	.get_tag_protocol	= mv88e6xxx_get_tag_protocol,
4020 4021 4022 4023 4024
	.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,
4025 4026
	.port_enable		= mv88e6xxx_port_enable,
	.port_disable		= mv88e6xxx_port_disable,
V
Vivien Didelot 已提交
4027 4028
	.get_mac_eee		= mv88e6xxx_get_mac_eee,
	.set_mac_eee		= mv88e6xxx_set_mac_eee,
4029
	.get_eeprom_len		= mv88e6xxx_get_eeprom_len,
4030 4031 4032 4033
	.get_eeprom		= mv88e6xxx_get_eeprom,
	.set_eeprom		= mv88e6xxx_set_eeprom,
	.get_regs_len		= mv88e6xxx_get_regs_len,
	.get_regs		= mv88e6xxx_get_regs,
4034
	.set_ageing_time	= mv88e6xxx_set_ageing_time,
4035 4036 4037
	.port_bridge_join	= mv88e6xxx_port_bridge_join,
	.port_bridge_leave	= mv88e6xxx_port_bridge_leave,
	.port_stp_state_set	= mv88e6xxx_port_stp_state_set,
4038
	.port_fast_age		= mv88e6xxx_port_fast_age,
4039 4040 4041 4042 4043 4044 4045
	.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,
4046 4047 4048
	.port_mdb_prepare       = mv88e6xxx_port_mdb_prepare,
	.port_mdb_add           = mv88e6xxx_port_mdb_add,
	.port_mdb_del           = mv88e6xxx_port_mdb_del,
4049 4050
	.crosschip_bridge_join	= mv88e6xxx_crosschip_bridge_join,
	.crosschip_bridge_leave	= mv88e6xxx_crosschip_bridge_leave,
4051 4052 4053 4054 4055
	.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,
4056 4057
};

4058 4059 4060 4061
static struct dsa_switch_driver mv88e6xxx_switch_drv = {
	.ops			= &mv88e6xxx_switch_ops,
};

4062
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
4063
{
4064
	struct device *dev = chip->dev;
4065 4066
	struct dsa_switch *ds;

4067
	ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
4068 4069 4070
	if (!ds)
		return -ENOMEM;

4071
	ds->priv = chip;
4072
	ds->ops = &mv88e6xxx_switch_ops;
4073 4074
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
4075 4076 4077

	dev_set_drvdata(dev, ds);

4078
	return dsa_register_switch(ds);
4079 4080
}

4081
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
4082
{
4083
	dsa_unregister_switch(chip->ds);
4084 4085
}

4086
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
4087
{
4088
	struct device *dev = &mdiodev->dev;
4089
	struct device_node *np = dev->of_node;
4090
	const struct mv88e6xxx_info *compat_info;
4091
	struct mv88e6xxx_chip *chip;
4092
	u32 eeprom_len;
4093
	int err;
4094

4095 4096 4097 4098
	compat_info = of_device_get_match_data(dev);
	if (!compat_info)
		return -EINVAL;

4099 4100
	chip = mv88e6xxx_alloc_chip(dev);
	if (!chip)
4101 4102
		return -ENOMEM;

4103
	chip->info = compat_info;
4104

4105
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
4106 4107
	if (err)
		return err;
4108

4109 4110 4111 4112
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
	if (IS_ERR(chip->reset))
		return PTR_ERR(chip->reset);

4113
	err = mv88e6xxx_detect(chip);
4114 4115
	if (err)
		return err;
4116

4117 4118
	mv88e6xxx_phy_init(chip);

4119
	if (chip->info->ops->get_eeprom &&
4120
	    !of_property_read_u32(np, "eeprom-length", &eeprom_len))
4121
		chip->eeprom_len = eeprom_len;
4122

4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134
	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;
	}

4135 4136 4137 4138 4139 4140
	/* 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)
4141
		err = mv88e6xxx_g1_irq_setup(chip);
4142 4143 4144
	else
		err = mv88e6xxx_irq_poll_setup(chip);
	mutex_unlock(&chip->reg_lock);
4145

4146 4147
	if (err)
		goto out;
4148

4149 4150
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
4151
		if (err)
4152
			goto out_g1_irq;
4153 4154
	}

4155 4156 4157 4158 4159 4160 4161 4162
	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;

4163
	err = mv88e6xxx_mdios_register(chip, np);
4164
	if (err)
4165
		goto out_g1_vtu_prob_irq;
4166

4167
	err = mv88e6xxx_register_switch(chip);
4168 4169
	if (err)
		goto out_mdio;
4170

4171
	return 0;
4172 4173

out_mdio:
4174
	mv88e6xxx_mdios_unregister(chip);
4175
out_g1_vtu_prob_irq:
4176
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
4177
out_g1_atu_prob_irq:
4178
	mv88e6xxx_g1_atu_prob_irq_free(chip);
4179
out_g2_irq:
4180
	if (chip->info->g2_irqs > 0)
4181 4182
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
4183 4184
	mutex_lock(&chip->reg_lock);
	if (chip->irq > 0)
4185
		mv88e6xxx_g1_irq_free(chip);
4186 4187 4188
	else
		mv88e6xxx_irq_poll_free(chip);
	mutex_unlock(&chip->reg_lock);
4189 4190
out:
	return err;
4191
}
4192 4193 4194 4195

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

4198 4199
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
4200
		mv88e6xxx_ptp_free(chip);
4201
	}
4202

4203
	mv88e6xxx_phy_destroy(chip);
4204
	mv88e6xxx_unregister_switch(chip);
4205
	mv88e6xxx_mdios_unregister(chip);
4206

4207 4208 4209 4210 4211 4212 4213 4214
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
	mv88e6xxx_g1_atu_prob_irq_free(chip);

	if (chip->info->g2_irqs > 0)
		mv88e6xxx_g2_irq_free(chip);

	mutex_lock(&chip->reg_lock);
	if (chip->irq > 0)
4215
		mv88e6xxx_g1_irq_free(chip);
4216 4217 4218
	else
		mv88e6xxx_irq_poll_free(chip);
	mutex_unlock(&chip->reg_lock);
4219 4220 4221
}

static const struct of_device_id mv88e6xxx_of_match[] = {
4222 4223 4224 4225
	{
		.compatible = "marvell,mv88e6085",
		.data = &mv88e6xxx_table[MV88E6085],
	},
4226 4227 4228 4229
	{
		.compatible = "marvell,mv88e6190",
		.data = &mv88e6xxx_table[MV88E6190],
	},
4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245
	{ /* 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)
{
4246
	register_switch_driver(&mv88e6xxx_switch_drv);
4247 4248
	return mdio_driver_register(&mv88e6xxx_driver);
}
4249 4250 4251 4252
module_init(mv88e6xxx_init);

static void __exit mv88e6xxx_cleanup(void)
{
4253
	mdio_driver_unregister(&mv88e6xxx_driver);
4254
	unregister_switch_driver(&mv88e6xxx_switch_drv);
4255 4256
}
module_exit(mv88e6xxx_cleanup);
4257 4258 4259 4260

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