chip.c 119.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
		count = chip->info->ops->stats_get_stats(chip, port, data);

	if (chip->info->ops->serdes_get_stats) {
		data += count;
852
		mutex_lock(&chip->reg_lock);
853
		chip->info->ops->serdes_get_stats(chip, port, data);
854
		mutex_unlock(&chip->reg_lock);
855
	}
856 857
}

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

864
	mutex_lock(&chip->reg_lock);
865

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

	if (ret < 0)
870
		return;
871 872

	mv88e6xxx_get_stats(chip, port, data);
873

874 875
}

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

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

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

	regs->version = 0;

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

902
	mutex_lock(&chip->reg_lock);
903

904 905
	for (i = 0; i < 32; i++) {

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

911
	mutex_unlock(&chip->reg_lock);
912 913
}

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

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

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

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

	return pvlan;
}

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

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

968
	return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
969 970
}

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

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

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

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

	return 0;
}

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

	return 0;
}

1001 1002
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
1003 1004
	int err;

1005 1006 1007 1008
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

1009 1010 1011 1012
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

1013 1014 1015
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

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

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

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

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

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

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

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

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

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

	return mv88e6xxx_g1_vtu_flush(chip);
}

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

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

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

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

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

		set_bit(*fid, fid_bitmap);
	}

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

		if (!vlan.valid)
			break;

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

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

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

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

	if (!vid)
		return -EINVAL;

1178 1179
	entry->vid = vid - 1;
	entry->valid = false;
1180

1181
	err = mv88e6xxx_vtu_getnext(chip, entry);
1182 1183 1184
	if (err)
		return err;

1185 1186
	if (entry->vid == vid && entry->valid)
		return 0;
1187

1188 1189 1190 1191 1192 1193 1194 1195
	if (new) {
		int i;

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

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

		return mv88e6xxx_atu_new(chip, &entry->fid);
1202 1203
	}

1204 1205
	/* switchdev expects -EOPNOTSUPP to honor software VLANs */
	return -EOPNOTSUPP;
1206 1207
}

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

1217 1218 1219 1220
	/* 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;

1221 1222 1223
	if (!vid_begin)
		return -EOPNOTSUPP;

1224
	mutex_lock(&chip->reg_lock);
1225 1226

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

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

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

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

1244
			if (vlan.member[i] ==
1245
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1246 1247
				continue;

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

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

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

unlock:
1264
	mutex_unlock(&chip->reg_lock);
1265 1266 1267 1268

	return err;
}

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

1277
	if (!chip->info->max_vid)
1278 1279
		return -EOPNOTSUPP;

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

1284
	return err;
1285 1286
}

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

1294
	if (!chip->info->max_vid)
1295 1296
		return -EOPNOTSUPP;

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

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

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

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

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

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

1388
	vlan.member[port] = member;
1389

1390 1391 1392 1393 1394
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
	if (err)
		return err;

	return mv88e6xxx_broadcast_setup(chip, vid);
1395 1396
}

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

1406
	if (!chip->info->max_vid)
1407 1408
		return;

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

1416
	mutex_lock(&chip->reg_lock);
1417

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

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

1427
	mutex_unlock(&chip->reg_lock);
1428 1429
}

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

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

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

1444
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1445 1446

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

1456
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1457 1458 1459
	if (err)
		return err;

1460
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
1461 1462
}

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

1470
	if (!chip->info->max_vid)
1471 1472
		return -EOPNOTSUPP;

1473
	mutex_lock(&chip->reg_lock);
1474

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

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

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

1491
unlock:
1492
	mutex_unlock(&chip->reg_lock);
1493 1494 1495 1496

	return err;
}

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

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

	return err;
1509 1510
}

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

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

1522
	return err;
1523 1524
}

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

1533
	addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1534
	eth_broadcast_addr(addr.mac);
1535 1536

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

1543
		if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
1544 1545
			break;

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

1549 1550
		if (!is_unicast_ether_addr(addr.mac))
			continue;
1551

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

	return err;
}

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

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

1576
	if (err)
1577
		return err;
1578

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

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

		if (!vlan.valid)
			break;

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

1600 1601 1602 1603
	return err;
}

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

1608
	return mv88e6xxx_port_db_dump(chip, port, cb, data);
1609 1610
}

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

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

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

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

1659
	return err;
1660 1661
}

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

1667
	mutex_lock(&chip->reg_lock);
1668 1669 1670
	if (mv88e6xxx_bridge_map(chip, br) ||
	    mv88e6xxx_port_vlan_map(chip, port))
		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
1671
	mutex_unlock(&chip->reg_lock);
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 1702 1703
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);
}

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

	return 0;
}

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

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

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

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

1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751
	return 0;
}

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

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

1752
	mv88e6xxx_hardware_reset(chip);
1753

1754
	return mv88e6xxx_software_reset(chip);
1755 1756
}

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

1763 1764 1765 1766
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
1767 1768 1769
	if (err)
		return err;

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

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

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

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

1802 1803 1804 1805
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);
1806

1807
	if (dsa_is_user_port(chip->ds, port))
1808
		return mv88e6xxx_set_port_mode_normal(chip, port);
1809

1810 1811 1812
	/* 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);
1813

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

1817
	return -EINVAL;
1818 1819
}

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

1824
	return mv88e6xxx_port_set_message_port(chip, port, message);
1825
}
1826

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

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

1838
	return 0;
1839 1840
}

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

1847
	return 0;
1848 1849
}

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

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

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

1880 1881 1882
	return 0;
}

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

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

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

1925
	err = mv88e6xxx_setup_port_mode(chip, port);
1926 1927
	if (err)
		return err;
1928

1929
	err = mv88e6xxx_setup_egress_floods(chip, port);
1930 1931 1932
	if (err)
		return err;

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

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

1953 1954 1955
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
1956

1957
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
1958
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
1959 1960 1961
	if (err)
		return err;

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

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

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

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

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

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

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

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

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

2019
	err = mv88e6xxx_setup_message_port(chip, port);
2020 2021
	if (err)
		return err;
2022

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

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

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

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

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

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

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

	return err;
}

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

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

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

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

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

2126
	return mv88e6xxx_g1_stats_clear(chip);
2127 2128
}

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

2135
	chip->ds = ds;
2136
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
2137

2138
	mutex_lock(&chip->reg_lock);
2139

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

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

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

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

2162 2163 2164 2165
	err = mv88e6xxx_irl_setup(chip);
	if (err)
		goto unlock;

2166 2167 2168 2169
	err = mv88e6xxx_mac_setup(chip);
	if (err)
		goto unlock;

2170 2171 2172 2173
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

2174 2175 2176 2177
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

2178 2179 2180 2181
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

2182 2183 2184 2185
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

2186 2187 2188 2189
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

2190 2191 2192 2193
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

2194 2195 2196
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
2197

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

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
2207 2208
	}

2209
unlock:
2210
	mutex_unlock(&chip->reg_lock);
2211

2212
	return err;
2213 2214
}

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

2222 2223 2224
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

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

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

2237
	return err ? err : val;
2238 2239
}

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

2246 2247 2248
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

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

	return err;
2254 2255
}

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

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

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

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

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

2296 2297 2298 2299 2300 2301
	if (!external) {
		err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
		if (err)
			return err;
	}

2302 2303
	if (np)
		err = of_mdiobus_register(bus, np);
2304 2305 2306
	else
		err = mdiobus_register(bus);
	if (err) {
2307
		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
2308
		mv88e6xxx_g2_irq_mdio_free(chip, bus);
2309
		return err;
2310
	}
2311 2312 2313 2314 2315

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

	return 0;
2318
}
2319

2320 2321 2322 2323 2324
static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
	{ .compatible = "marvell,mv88e6xxx-mdio-external",
	  .data = (void *)true },
	{ },
};
2325

2326 2327 2328 2329 2330 2331 2332 2333 2334
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;

2335 2336 2337
		if (!mdio_bus->external)
			mv88e6xxx_g2_irq_mdio_free(chip, bus);

2338 2339 2340 2341
		mdiobus_unregister(bus);
	}
}

2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365
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);
2366 2367
			if (err) {
				mv88e6xxx_mdios_unregister(chip);
2368
				return err;
2369
			}
2370 2371 2372 2373
		}
	}

	return 0;
2374 2375
}

2376 2377
static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
2378
	struct mv88e6xxx_chip *chip = ds->priv;
2379 2380 2381 2382 2383 2384 2385

	return chip->eeprom_len;
}

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

2389 2390
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
2391

2392 2393
	mutex_lock(&chip->reg_lock);
	err = chip->info->ops->get_eeprom(chip, eeprom, data);
2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406
	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 已提交
2407
	struct mv88e6xxx_chip *chip = ds->priv;
2408 2409
	int err;

2410 2411 2412
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

2413 2414 2415 2416
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

	mutex_lock(&chip->reg_lock);
2417
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
2418 2419 2420 2421 2422
	mutex_unlock(&chip->reg_lock);

	return err;
}

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

static const struct mv88e6xxx_ops mv88e6095_ops = {
2458
	/* MV88E6XXX_FAMILY_6095 */
2459
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2460 2461
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2462
	.port_set_link = mv88e6xxx_port_set_link,
2463
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2464
	.port_set_speed = mv88e6185_port_set_speed,
2465
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2466
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2467
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2468
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2469
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2470 2471
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2472
	.stats_get_stats = mv88e6095_stats_get_stats,
2473
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2474 2475
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2476
	.reset = mv88e6185_g1_reset,
2477
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2478
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2479 2480
};

2481
static const struct mv88e6xxx_ops mv88e6097_ops = {
2482
	/* MV88E6XXX_FAMILY_6097 */
2483
	.irl_init_all = mv88e6352_g2_irl_init_all,
2484 2485 2486 2487 2488 2489
	.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,
2490
	.port_tag_remap = mv88e6095_port_tag_remap,
2491
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2492
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2493
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2494
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2495
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
2496
	.port_pause_limit = mv88e6097_port_pause_limit,
2497
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2498
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2499
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2500
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2501 2502 2503
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
	.stats_get_stats = mv88e6095_stats_get_stats,
2504 2505
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2506
	.watchdog_ops = &mv88e6097_watchdog_ops,
2507
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2508
	.pot_clear = mv88e6xxx_g2_pot_clear,
2509
	.reset = mv88e6352_g1_reset,
2510
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2511
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2512 2513
};

2514
static const struct mv88e6xxx_ops mv88e6123_ops = {
2515
	/* MV88E6XXX_FAMILY_6165 */
2516
	.irl_init_all = mv88e6352_g2_irl_init_all,
2517
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2518 2519
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2520
	.port_set_link = mv88e6xxx_port_set_link,
2521
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2522
	.port_set_speed = mv88e6185_port_set_speed,
2523
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2524
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2525
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2526
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2527
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2528
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2529 2530
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2531
	.stats_get_stats = mv88e6095_stats_get_stats,
2532 2533
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2534
	.watchdog_ops = &mv88e6097_watchdog_ops,
2535
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2536
	.pot_clear = mv88e6xxx_g2_pot_clear,
2537
	.reset = mv88e6352_g1_reset,
2538
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2539
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2540 2541 2542
};

static const struct mv88e6xxx_ops mv88e6131_ops = {
2543
	/* MV88E6XXX_FAMILY_6185 */
2544
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2545 2546
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2547
	.port_set_link = mv88e6xxx_port_set_link,
2548
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2549
	.port_set_speed = mv88e6185_port_set_speed,
2550
	.port_tag_remap = mv88e6095_port_tag_remap,
2551
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2552
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2553
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2554
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2555
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2556
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2557
	.port_pause_limit = mv88e6097_port_pause_limit,
2558
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2559
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2560 2561
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2562
	.stats_get_stats = mv88e6095_stats_get_stats,
2563 2564
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2565
	.watchdog_ops = &mv88e6097_watchdog_ops,
2566
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2567 2568
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2569
	.reset = mv88e6185_g1_reset,
2570
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2571
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2572 2573
};

2574 2575
static const struct mv88e6xxx_ops mv88e6141_ops = {
	/* MV88E6XXX_FAMILY_6341 */
2576
	.irl_init_all = mv88e6352_g2_irl_init_all,
2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589
	.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,
2590
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2591
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2592
	.port_pause_limit = mv88e6097_port_pause_limit,
2593 2594 2595
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
2596
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2597 2598 2599
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
2600 2601
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
2602 2603
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
2604
	.pot_clear = mv88e6xxx_g2_pot_clear,
2605
	.reset = mv88e6352_g1_reset,
2606
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2607
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2608
	.gpio_ops = &mv88e6352_gpio_ops,
2609 2610
};

2611
static const struct mv88e6xxx_ops mv88e6161_ops = {
2612
	/* MV88E6XXX_FAMILY_6165 */
2613
	.irl_init_all = mv88e6352_g2_irl_init_all,
2614
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2615 2616
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2617
	.port_set_link = mv88e6xxx_port_set_link,
2618
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2619
	.port_set_speed = mv88e6185_port_set_speed,
2620
	.port_tag_remap = mv88e6095_port_tag_remap,
2621
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2622
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2623
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2624
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2625
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2626
	.port_pause_limit = mv88e6097_port_pause_limit,
2627
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2628
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2629
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2630
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2631 2632
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2633
	.stats_get_stats = mv88e6095_stats_get_stats,
2634 2635
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2636
	.watchdog_ops = &mv88e6097_watchdog_ops,
2637
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2638
	.pot_clear = mv88e6xxx_g2_pot_clear,
2639
	.reset = mv88e6352_g1_reset,
2640
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2641
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2642 2643 2644
};

static const struct mv88e6xxx_ops mv88e6165_ops = {
2645
	/* MV88E6XXX_FAMILY_6165 */
2646
	.irl_init_all = mv88e6352_g2_irl_init_all,
2647
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2648 2649
	.phy_read = mv88e6165_phy_read,
	.phy_write = mv88e6165_phy_write,
2650
	.port_set_link = mv88e6xxx_port_set_link,
2651
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2652
	.port_set_speed = mv88e6185_port_set_speed,
2653
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2654
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2655
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2656
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2657 2658
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2659
	.stats_get_stats = mv88e6095_stats_get_stats,
2660 2661
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2662
	.watchdog_ops = &mv88e6097_watchdog_ops,
2663
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2664
	.pot_clear = mv88e6xxx_g2_pot_clear,
2665
	.reset = mv88e6352_g1_reset,
2666
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2667
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2668 2669 2670
};

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

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

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

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

static const struct mv88e6xxx_ops mv88e6185_ops = {
2815
	/* MV88E6XXX_FAMILY_6185 */
2816
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2817 2818
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2819
	.port_set_link = mv88e6xxx_port_set_link,
2820
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2821
	.port_set_speed = mv88e6185_port_set_speed,
2822
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2823
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2824
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
2825
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2826
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2827
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2828 2829
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2830
	.stats_get_stats = mv88e6095_stats_get_stats,
2831 2832
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2833
	.watchdog_ops = &mv88e6097_watchdog_ops,
2834
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2835 2836
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2837
	.reset = mv88e6185_g1_reset,
2838
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2839
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2840 2841
};

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

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

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

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

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

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

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

3096 3097
static const struct mv88e6xxx_ops mv88e6341_ops = {
	/* MV88E6XXX_FAMILY_6341 */
3098
	.irl_init_all = mv88e6352_g2_irl_init_all,
3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111
	.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,
3112
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3113
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3114
	.port_pause_limit = mv88e6097_port_pause_limit,
3115 3116 3117
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3118
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3119 3120 3121
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
3122 3123
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3124 3125
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
3126
	.pot_clear = mv88e6xxx_g2_pot_clear,
3127
	.reset = mv88e6352_g1_reset,
3128
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3129
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3130
	.gpio_ops = &mv88e6352_gpio_ops,
3131
	.avb_ops = &mv88e6390_avb_ops,
3132 3133
};

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

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

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

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

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

3325 3326
static const struct mv88e6xxx_info mv88e6xxx_table[] = {
	[MV88E6085] = {
3327
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
3328 3329 3330 3331
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6085",
		.num_databases = 4096,
		.num_ports = 10,
3332
		.num_internal_phys = 5,
3333
		.max_vid = 4095,
3334
		.port_base_addr = 0x10,
3335
		.global1_addr = 0x1b,
3336
		.global2_addr = 0x1c,
3337
		.age_time_coeff = 15000,
3338
		.g1_irqs = 8,
3339
		.g2_irqs = 10,
3340
		.atu_move_port_mask = 0xf,
3341
		.pvt = true,
3342
		.multi_chip = true,
3343
		.tag_protocol = DSA_TAG_PROTO_DSA,
3344
		.ops = &mv88e6085_ops,
3345 3346 3347
	},

	[MV88E6095] = {
3348
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
3349 3350 3351 3352
		.family = MV88E6XXX_FAMILY_6095,
		.name = "Marvell 88E6095/88E6095F",
		.num_databases = 256,
		.num_ports = 11,
3353
		.num_internal_phys = 0,
3354
		.max_vid = 4095,
3355
		.port_base_addr = 0x10,
3356
		.global1_addr = 0x1b,
3357
		.global2_addr = 0x1c,
3358
		.age_time_coeff = 15000,
3359
		.g1_irqs = 8,
3360
		.atu_move_port_mask = 0xf,
3361
		.multi_chip = true,
3362
		.tag_protocol = DSA_TAG_PROTO_DSA,
3363
		.ops = &mv88e6095_ops,
3364 3365
	},

3366
	[MV88E6097] = {
3367
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
3368 3369 3370 3371
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6097/88E6097F",
		.num_databases = 4096,
		.num_ports = 11,
3372
		.num_internal_phys = 8,
3373
		.max_vid = 4095,
3374 3375
		.port_base_addr = 0x10,
		.global1_addr = 0x1b,
3376
		.global2_addr = 0x1c,
3377
		.age_time_coeff = 15000,
3378
		.g1_irqs = 8,
3379
		.g2_irqs = 10,
3380
		.atu_move_port_mask = 0xf,
3381
		.pvt = true,
3382
		.multi_chip = true,
3383
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3384 3385 3386
		.ops = &mv88e6097_ops,
	},

3387
	[MV88E6123] = {
3388
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
3389 3390 3391 3392
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6123",
		.num_databases = 4096,
		.num_ports = 3,
3393
		.num_internal_phys = 5,
3394
		.max_vid = 4095,
3395
		.port_base_addr = 0x10,
3396
		.global1_addr = 0x1b,
3397
		.global2_addr = 0x1c,
3398
		.age_time_coeff = 15000,
3399
		.g1_irqs = 9,
3400
		.g2_irqs = 10,
3401
		.atu_move_port_mask = 0xf,
3402
		.pvt = true,
3403
		.multi_chip = true,
3404
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3405
		.ops = &mv88e6123_ops,
3406 3407 3408
	},

	[MV88E6131] = {
3409
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
3410 3411 3412 3413
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6131",
		.num_databases = 256,
		.num_ports = 8,
3414
		.num_internal_phys = 0,
3415
		.max_vid = 4095,
3416
		.port_base_addr = 0x10,
3417
		.global1_addr = 0x1b,
3418
		.global2_addr = 0x1c,
3419
		.age_time_coeff = 15000,
3420
		.g1_irqs = 9,
3421
		.atu_move_port_mask = 0xf,
3422
		.multi_chip = true,
3423
		.tag_protocol = DSA_TAG_PROTO_DSA,
3424
		.ops = &mv88e6131_ops,
3425 3426
	},

3427
	[MV88E6141] = {
3428
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
3429
		.family = MV88E6XXX_FAMILY_6341,
3430
		.name = "Marvell 88E6141",
3431 3432
		.num_databases = 4096,
		.num_ports = 6,
3433
		.num_internal_phys = 5,
3434
		.num_gpio = 11,
3435
		.max_vid = 4095,
3436 3437
		.port_base_addr = 0x10,
		.global1_addr = 0x1b,
3438
		.global2_addr = 0x1c,
3439 3440
		.age_time_coeff = 3750,
		.atu_move_port_mask = 0x1f,
3441
		.g1_irqs = 9,
3442
		.g2_irqs = 10,
3443
		.pvt = true,
3444
		.multi_chip = true,
3445 3446 3447 3448
		.tag_protocol = DSA_TAG_PROTO_EDSA,
		.ops = &mv88e6141_ops,
	},

3449
	[MV88E6161] = {
3450
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
3451 3452 3453 3454
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6161",
		.num_databases = 4096,
		.num_ports = 6,
3455
		.num_internal_phys = 5,
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_EDSA,
3467
		.ops = &mv88e6161_ops,
3468 3469 3470
	},

	[MV88E6165] = {
3471
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
3472 3473 3474 3475
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6165",
		.num_databases = 4096,
		.num_ports = 6,
3476
		.num_internal_phys = 0,
3477
		.max_vid = 4095,
3478
		.port_base_addr = 0x10,
3479
		.global1_addr = 0x1b,
3480
		.global2_addr = 0x1c,
3481
		.age_time_coeff = 15000,
3482
		.g1_irqs = 9,
3483
		.g2_irqs = 10,
3484
		.atu_move_port_mask = 0xf,
3485
		.pvt = true,
3486
		.multi_chip = true,
3487
		.tag_protocol = DSA_TAG_PROTO_DSA,
3488
		.ops = &mv88e6165_ops,
3489 3490 3491
	},

	[MV88E6171] = {
3492
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
3493 3494 3495 3496
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6171",
		.num_databases = 4096,
		.num_ports = 7,
3497
		.num_internal_phys = 5,
3498
		.max_vid = 4095,
3499
		.port_base_addr = 0x10,
3500
		.global1_addr = 0x1b,
3501
		.global2_addr = 0x1c,
3502
		.age_time_coeff = 15000,
3503
		.g1_irqs = 9,
3504
		.g2_irqs = 10,
3505
		.atu_move_port_mask = 0xf,
3506
		.pvt = true,
3507
		.multi_chip = true,
3508
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3509
		.ops = &mv88e6171_ops,
3510 3511 3512
	},

	[MV88E6172] = {
3513
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
3514 3515 3516 3517
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6172",
		.num_databases = 4096,
		.num_ports = 7,
3518
		.num_internal_phys = 5,
3519
		.num_gpio = 15,
3520
		.max_vid = 4095,
3521
		.port_base_addr = 0x10,
3522
		.global1_addr = 0x1b,
3523
		.global2_addr = 0x1c,
3524
		.age_time_coeff = 15000,
3525
		.g1_irqs = 9,
3526
		.g2_irqs = 10,
3527
		.atu_move_port_mask = 0xf,
3528
		.pvt = true,
3529
		.multi_chip = true,
3530
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3531
		.ops = &mv88e6172_ops,
3532 3533 3534
	},

	[MV88E6175] = {
3535
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
3536 3537 3538 3539
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6175",
		.num_databases = 4096,
		.num_ports = 7,
3540
		.num_internal_phys = 5,
3541
		.max_vid = 4095,
3542
		.port_base_addr = 0x10,
3543
		.global1_addr = 0x1b,
3544
		.global2_addr = 0x1c,
3545
		.age_time_coeff = 15000,
3546
		.g1_irqs = 9,
3547
		.g2_irqs = 10,
3548
		.atu_move_port_mask = 0xf,
3549
		.pvt = true,
3550
		.multi_chip = true,
3551
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3552
		.ops = &mv88e6175_ops,
3553 3554 3555
	},

	[MV88E6176] = {
3556
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
3557 3558 3559 3560
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6176",
		.num_databases = 4096,
		.num_ports = 7,
3561
		.num_internal_phys = 5,
3562
		.num_gpio = 15,
3563
		.max_vid = 4095,
3564
		.port_base_addr = 0x10,
3565
		.global1_addr = 0x1b,
3566
		.global2_addr = 0x1c,
3567
		.age_time_coeff = 15000,
3568
		.g1_irqs = 9,
3569
		.g2_irqs = 10,
3570
		.atu_move_port_mask = 0xf,
3571
		.pvt = true,
3572
		.multi_chip = true,
3573
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3574
		.ops = &mv88e6176_ops,
3575 3576 3577
	},

	[MV88E6185] = {
3578
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
3579 3580 3581 3582
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6185",
		.num_databases = 256,
		.num_ports = 10,
3583
		.num_internal_phys = 0,
3584
		.max_vid = 4095,
3585
		.port_base_addr = 0x10,
3586
		.global1_addr = 0x1b,
3587
		.global2_addr = 0x1c,
3588
		.age_time_coeff = 15000,
3589
		.g1_irqs = 8,
3590
		.atu_move_port_mask = 0xf,
3591
		.multi_chip = true,
3592
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3593
		.ops = &mv88e6185_ops,
3594 3595
	},

3596
	[MV88E6190] = {
3597
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
3598 3599 3600 3601
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3602
		.num_internal_phys = 11,
3603
		.num_gpio = 16,
3604
		.max_vid = 8191,
3605 3606
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3607
		.global2_addr = 0x1c,
3608
		.tag_protocol = DSA_TAG_PROTO_DSA,
3609
		.age_time_coeff = 3750,
3610
		.g1_irqs = 9,
3611
		.g2_irqs = 14,
3612
		.pvt = true,
3613
		.multi_chip = true,
3614
		.atu_move_port_mask = 0x1f,
3615 3616 3617 3618
		.ops = &mv88e6190_ops,
	},

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

	[MV88E6191] = {
3641
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
3642 3643 3644 3645
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6191",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3646
		.num_internal_phys = 11,
3647
		.max_vid = 8191,
3648 3649
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3650
		.global2_addr = 0x1c,
3651
		.age_time_coeff = 3750,
3652
		.g1_irqs = 9,
3653
		.g2_irqs = 14,
3654
		.atu_move_port_mask = 0x1f,
3655
		.pvt = true,
3656
		.multi_chip = true,
3657
		.tag_protocol = DSA_TAG_PROTO_DSA,
3658
		.ptp_support = true,
3659
		.ops = &mv88e6191_ops,
3660 3661
	},

3662
	[MV88E6240] = {
3663
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
3664 3665 3666 3667
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6240",
		.num_databases = 4096,
		.num_ports = 7,
3668
		.num_internal_phys = 5,
3669
		.num_gpio = 15,
3670
		.max_vid = 4095,
3671
		.port_base_addr = 0x10,
3672
		.global1_addr = 0x1b,
3673
		.global2_addr = 0x1c,
3674
		.age_time_coeff = 15000,
3675
		.g1_irqs = 9,
3676
		.g2_irqs = 10,
3677
		.atu_move_port_mask = 0xf,
3678
		.pvt = true,
3679
		.multi_chip = true,
3680
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3681
		.ptp_support = true,
3682
		.ops = &mv88e6240_ops,
3683 3684
	},

3685
	[MV88E6290] = {
3686
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
3687 3688 3689 3690
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6290",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3691
		.num_internal_phys = 11,
3692
		.num_gpio = 16,
3693
		.max_vid = 8191,
3694 3695
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3696
		.global2_addr = 0x1c,
3697
		.age_time_coeff = 3750,
3698
		.g1_irqs = 9,
3699
		.g2_irqs = 14,
3700
		.atu_move_port_mask = 0x1f,
3701
		.pvt = true,
3702
		.multi_chip = true,
3703
		.tag_protocol = DSA_TAG_PROTO_DSA,
3704
		.ptp_support = true,
3705 3706 3707
		.ops = &mv88e6290_ops,
	},

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

	[MV88E6321] = {
3732
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
3733 3734 3735 3736
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6321",
		.num_databases = 4096,
		.num_ports = 7,
3737
		.num_internal_phys = 5,
3738
		.num_gpio = 15,
3739
		.max_vid = 4095,
3740
		.port_base_addr = 0x10,
3741
		.global1_addr = 0x1b,
3742
		.global2_addr = 0x1c,
3743
		.age_time_coeff = 15000,
3744
		.g1_irqs = 8,
3745
		.g2_irqs = 10,
3746
		.atu_move_port_mask = 0xf,
3747
		.multi_chip = true,
3748
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3749
		.ptp_support = true,
3750
		.ops = &mv88e6321_ops,
3751 3752
	},

3753
	[MV88E6341] = {
3754
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
3755 3756 3757
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
3758
		.num_internal_phys = 5,
3759
		.num_ports = 6,
3760
		.num_gpio = 11,
3761
		.max_vid = 4095,
3762 3763
		.port_base_addr = 0x10,
		.global1_addr = 0x1b,
3764
		.global2_addr = 0x1c,
3765
		.age_time_coeff = 3750,
3766
		.atu_move_port_mask = 0x1f,
3767
		.g1_irqs = 9,
3768
		.g2_irqs = 10,
3769
		.pvt = true,
3770
		.multi_chip = true,
3771
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3772
		.ptp_support = true,
3773 3774 3775
		.ops = &mv88e6341_ops,
	},

3776
	[MV88E6350] = {
3777
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
3778 3779 3780 3781
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6350",
		.num_databases = 4096,
		.num_ports = 7,
3782
		.num_internal_phys = 5,
3783
		.max_vid = 4095,
3784
		.port_base_addr = 0x10,
3785
		.global1_addr = 0x1b,
3786
		.global2_addr = 0x1c,
3787
		.age_time_coeff = 15000,
3788
		.g1_irqs = 9,
3789
		.g2_irqs = 10,
3790
		.atu_move_port_mask = 0xf,
3791
		.pvt = true,
3792
		.multi_chip = true,
3793
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3794
		.ops = &mv88e6350_ops,
3795 3796 3797
	},

	[MV88E6351] = {
3798
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
3799 3800 3801 3802
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6351",
		.num_databases = 4096,
		.num_ports = 7,
3803
		.num_internal_phys = 5,
3804
		.max_vid = 4095,
3805
		.port_base_addr = 0x10,
3806
		.global1_addr = 0x1b,
3807
		.global2_addr = 0x1c,
3808
		.age_time_coeff = 15000,
3809
		.g1_irqs = 9,
3810
		.g2_irqs = 10,
3811
		.atu_move_port_mask = 0xf,
3812
		.pvt = true,
3813
		.multi_chip = true,
3814
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3815
		.ops = &mv88e6351_ops,
3816 3817 3818
	},

	[MV88E6352] = {
3819
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
3820 3821 3822 3823
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6352",
		.num_databases = 4096,
		.num_ports = 7,
3824
		.num_internal_phys = 5,
3825
		.num_gpio = 15,
3826
		.max_vid = 4095,
3827
		.port_base_addr = 0x10,
3828
		.global1_addr = 0x1b,
3829
		.global2_addr = 0x1c,
3830
		.age_time_coeff = 15000,
3831
		.g1_irqs = 9,
3832
		.g2_irqs = 10,
3833
		.atu_move_port_mask = 0xf,
3834
		.pvt = true,
3835
		.multi_chip = true,
3836
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3837
		.ptp_support = true,
3838
		.ops = &mv88e6352_ops,
3839
	},
3840
	[MV88E6390] = {
3841
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
3842 3843 3844 3845
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3846
		.num_internal_phys = 11,
3847
		.num_gpio = 16,
3848
		.max_vid = 8191,
3849 3850
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3851
		.global2_addr = 0x1c,
3852
		.age_time_coeff = 3750,
3853
		.g1_irqs = 9,
3854
		.g2_irqs = 14,
3855
		.atu_move_port_mask = 0x1f,
3856
		.pvt = true,
3857
		.multi_chip = true,
3858
		.tag_protocol = DSA_TAG_PROTO_DSA,
3859
		.ptp_support = true,
3860 3861 3862
		.ops = &mv88e6390_ops,
	},
	[MV88E6390X] = {
3863
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
3864 3865 3866 3867
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3868
		.num_internal_phys = 11,
3869
		.num_gpio = 16,
3870
		.max_vid = 8191,
3871 3872
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3873
		.global2_addr = 0x1c,
3874
		.age_time_coeff = 3750,
3875
		.g1_irqs = 9,
3876
		.g2_irqs = 14,
3877
		.atu_move_port_mask = 0x1f,
3878
		.pvt = true,
3879
		.multi_chip = true,
3880
		.tag_protocol = DSA_TAG_PROTO_DSA,
3881
		.ptp_support = true,
3882 3883
		.ops = &mv88e6390x_ops,
	},
3884 3885
};

3886
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
3887
{
3888
	int i;
3889

3890 3891 3892
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
3893 3894 3895 3896

	return NULL;
}

3897
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
3898 3899
{
	const struct mv88e6xxx_info *info;
3900 3901 3902
	unsigned int prod_num, rev;
	u16 id;
	int err;
3903

3904
	mutex_lock(&chip->reg_lock);
3905
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
3906 3907 3908
	mutex_unlock(&chip->reg_lock);
	if (err)
		return err;
3909

3910 3911
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
3912 3913 3914 3915 3916

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

3917
	/* Update the compatible info with the probed one */
3918
	chip->info = info;
3919

3920 3921 3922 3923
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

3924 3925
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
3926 3927 3928 3929

	return 0;
}

3930
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
3931
{
3932
	struct mv88e6xxx_chip *chip;
3933

3934 3935
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
3936 3937
		return NULL;

3938
	chip->dev = dev;
3939

3940
	mutex_init(&chip->reg_lock);
3941
	INIT_LIST_HEAD(&chip->mdios);
3942

3943
	return chip;
3944 3945
}

3946
static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
3947 3948
			      struct mii_bus *bus, int sw_addr)
{
3949
	if (sw_addr == 0)
3950
		chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
3951
	else if (chip->info->multi_chip)
3952
		chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
3953 3954 3955
	else
		return -EINVAL;

3956 3957
	chip->bus = bus;
	chip->sw_addr = sw_addr;
3958 3959 3960 3961

	return 0;
}

3962 3963
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
							int port)
3964
{
V
Vivien Didelot 已提交
3965
	struct mv88e6xxx_chip *chip = ds->priv;
3966

3967
	return chip->info->tag_protocol;
3968 3969
}

3970
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
3971 3972 3973
static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
				       struct device *host_dev, int sw_addr,
				       void **priv)
3974
{
3975
	struct mv88e6xxx_chip *chip;
3976
	struct mii_bus *bus;
3977
	int err;
3978

3979
	bus = dsa_host_dev_to_mii_bus(host_dev);
3980 3981 3982
	if (!bus)
		return NULL;

3983 3984
	chip = mv88e6xxx_alloc_chip(dsa_dev);
	if (!chip)
3985 3986
		return NULL;

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

3990
	err = mv88e6xxx_smi_init(chip, bus, sw_addr);
3991 3992 3993
	if (err)
		goto free;

3994
	err = mv88e6xxx_detect(chip);
3995
	if (err)
3996
		goto free;
3997

3998 3999 4000 4001 4002 4003
	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_switch_reset(chip);
	mutex_unlock(&chip->reg_lock);
	if (err)
		goto free;

4004 4005
	mv88e6xxx_phy_init(chip);

4006
	err = mv88e6xxx_mdios_register(chip, NULL);
4007
	if (err)
4008
		goto free;
4009

4010
	*priv = chip;
4011

4012
	return chip->info->name;
4013
free:
4014
	devm_kfree(dsa_dev, chip);
4015 4016

	return NULL;
4017
}
4018
#endif
4019

4020
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4021
				      const struct switchdev_obj_port_mdb *mdb)
4022 4023 4024 4025 4026 4027 4028 4029 4030
{
	/* 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,
4031
				   const struct switchdev_obj_port_mdb *mdb)
4032
{
V
Vivien Didelot 已提交
4033
	struct mv88e6xxx_chip *chip = ds->priv;
4034 4035 4036

	mutex_lock(&chip->reg_lock);
	if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4037
					 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
4038 4039
		dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
			port);
4040 4041 4042 4043 4044 4045
	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 已提交
4046
	struct mv88e6xxx_chip *chip = ds->priv;
4047 4048 4049 4050
	int err;

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4051
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
4052 4053 4054 4055 4056
	mutex_unlock(&chip->reg_lock);

	return err;
}

4057
static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
4058
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
4059
	.probe			= mv88e6xxx_drv_probe,
4060
#endif
4061
	.get_tag_protocol	= mv88e6xxx_get_tag_protocol,
4062 4063 4064 4065 4066
	.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,
4067 4068
	.port_enable		= mv88e6xxx_port_enable,
	.port_disable		= mv88e6xxx_port_disable,
V
Vivien Didelot 已提交
4069 4070
	.get_mac_eee		= mv88e6xxx_get_mac_eee,
	.set_mac_eee		= mv88e6xxx_set_mac_eee,
4071
	.get_eeprom_len		= mv88e6xxx_get_eeprom_len,
4072 4073 4074 4075
	.get_eeprom		= mv88e6xxx_get_eeprom,
	.set_eeprom		= mv88e6xxx_set_eeprom,
	.get_regs_len		= mv88e6xxx_get_regs_len,
	.get_regs		= mv88e6xxx_get_regs,
4076
	.set_ageing_time	= mv88e6xxx_set_ageing_time,
4077 4078 4079
	.port_bridge_join	= mv88e6xxx_port_bridge_join,
	.port_bridge_leave	= mv88e6xxx_port_bridge_leave,
	.port_stp_state_set	= mv88e6xxx_port_stp_state_set,
4080
	.port_fast_age		= mv88e6xxx_port_fast_age,
4081 4082 4083 4084 4085 4086 4087
	.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,
4088 4089 4090
	.port_mdb_prepare       = mv88e6xxx_port_mdb_prepare,
	.port_mdb_add           = mv88e6xxx_port_mdb_add,
	.port_mdb_del           = mv88e6xxx_port_mdb_del,
4091 4092
	.crosschip_bridge_join	= mv88e6xxx_crosschip_bridge_join,
	.crosschip_bridge_leave	= mv88e6xxx_crosschip_bridge_leave,
4093 4094 4095 4096 4097
	.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,
4098 4099
};

4100 4101 4102 4103
static struct dsa_switch_driver mv88e6xxx_switch_drv = {
	.ops			= &mv88e6xxx_switch_ops,
};

4104
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
4105
{
4106
	struct device *dev = chip->dev;
4107 4108
	struct dsa_switch *ds;

4109
	ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
4110 4111 4112
	if (!ds)
		return -ENOMEM;

4113
	ds->priv = chip;
4114
	ds->ops = &mv88e6xxx_switch_ops;
4115 4116
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
4117 4118 4119

	dev_set_drvdata(dev, ds);

4120
	return dsa_register_switch(ds);
4121 4122
}

4123
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
4124
{
4125
	dsa_unregister_switch(chip->ds);
4126 4127
}

4128
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
4129
{
4130
	struct device *dev = &mdiodev->dev;
4131
	struct device_node *np = dev->of_node;
4132
	const struct mv88e6xxx_info *compat_info;
4133
	struct mv88e6xxx_chip *chip;
4134
	u32 eeprom_len;
4135
	int err;
4136

4137 4138 4139 4140
	compat_info = of_device_get_match_data(dev);
	if (!compat_info)
		return -EINVAL;

4141 4142
	chip = mv88e6xxx_alloc_chip(dev);
	if (!chip)
4143 4144
		return -ENOMEM;

4145
	chip->info = compat_info;
4146

4147
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
4148 4149
	if (err)
		return err;
4150

4151 4152 4153 4154
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
	if (IS_ERR(chip->reset))
		return PTR_ERR(chip->reset);

4155
	err = mv88e6xxx_detect(chip);
4156 4157
	if (err)
		return err;
4158

4159 4160
	mv88e6xxx_phy_init(chip);

4161
	if (chip->info->ops->get_eeprom &&
4162
	    !of_property_read_u32(np, "eeprom-length", &eeprom_len))
4163
		chip->eeprom_len = eeprom_len;
4164

4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176
	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;
	}

4177 4178 4179 4180 4181 4182
	/* 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)
4183
		err = mv88e6xxx_g1_irq_setup(chip);
4184 4185 4186
	else
		err = mv88e6xxx_irq_poll_setup(chip);
	mutex_unlock(&chip->reg_lock);
4187

4188 4189
	if (err)
		goto out;
4190

4191 4192
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
4193
		if (err)
4194
			goto out_g1_irq;
4195 4196
	}

4197 4198 4199 4200 4201 4202 4203 4204
	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;

4205
	err = mv88e6xxx_mdios_register(chip, np);
4206
	if (err)
4207
		goto out_g1_vtu_prob_irq;
4208

4209
	err = mv88e6xxx_register_switch(chip);
4210 4211
	if (err)
		goto out_mdio;
4212

4213
	return 0;
4214 4215

out_mdio:
4216
	mv88e6xxx_mdios_unregister(chip);
4217
out_g1_vtu_prob_irq:
4218
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
4219
out_g1_atu_prob_irq:
4220
	mv88e6xxx_g1_atu_prob_irq_free(chip);
4221
out_g2_irq:
4222
	if (chip->info->g2_irqs > 0)
4223 4224
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
4225 4226
	mutex_lock(&chip->reg_lock);
	if (chip->irq > 0)
4227
		mv88e6xxx_g1_irq_free(chip);
4228 4229 4230
	else
		mv88e6xxx_irq_poll_free(chip);
	mutex_unlock(&chip->reg_lock);
4231 4232
out:
	return err;
4233
}
4234 4235 4236 4237

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

4240 4241
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
4242
		mv88e6xxx_ptp_free(chip);
4243
	}
4244

4245
	mv88e6xxx_phy_destroy(chip);
4246
	mv88e6xxx_unregister_switch(chip);
4247
	mv88e6xxx_mdios_unregister(chip);
4248

4249 4250 4251 4252 4253 4254 4255 4256
	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)
4257
		mv88e6xxx_g1_irq_free(chip);
4258 4259 4260
	else
		mv88e6xxx_irq_poll_free(chip);
	mutex_unlock(&chip->reg_lock);
4261 4262 4263
}

static const struct of_device_id mv88e6xxx_of_match[] = {
4264 4265 4266 4267
	{
		.compatible = "marvell,mv88e6085",
		.data = &mv88e6xxx_table[MV88E6085],
	},
4268 4269 4270 4271
	{
		.compatible = "marvell,mv88e6190",
		.data = &mv88e6xxx_table[MV88E6190],
	},
4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287
	{ /* 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)
{
4288
	register_switch_driver(&mv88e6xxx_switch_drv);
4289 4290
	return mdio_driver_register(&mv88e6xxx_driver);
}
4291 4292 4293 4294
module_init(mv88e6xxx_init);

static void __exit mv88e6xxx_cleanup(void)
{
4295
	mdio_driver_unregister(&mv88e6xxx_driver);
4296
	unregister_switch_driver(&mv88e6xxx_switch_drv);
4297 4298
}
module_exit(mv88e6xxx_cleanup);
4299 4300 4301 4302

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