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

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

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

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

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

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

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

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

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

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

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

	*val = ret & 0xffff;

	return 0;
}

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

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

	return 0;
}

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

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

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

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

	return -ETIMEDOUT;
}

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

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

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

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

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

157
	*val = ret & 0xffff;
158

159
	return 0;
160 161
}

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

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

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

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

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

	return 0;
}

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

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

200
	assert_reg_lock(chip);
201

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

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

	return 0;
}

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

216
	assert_reg_lock(chip);
217

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

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

225 226 227
	return 0;
}

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

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

	return mdio_bus->bus;
}

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

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

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

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

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

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

	if (err)
		goto out;

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

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

	return mv88e6xxx_g1_irq_thread_work(chip);
}

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

	mutex_lock(&chip->reg_lock);
}

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

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

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

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

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

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

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

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

	return 0;
}

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

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

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

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

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

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

	free_irq(chip->irq, chip);
}

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

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

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

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

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

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

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

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

	return 0;

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

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

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

	return err;
}

418 419 420 421 422 423 424 425 426 427
static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
{
	int err;

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

	err = request_threaded_irq(chip->irq, NULL,
				   mv88e6xxx_g1_irq_thread_fn,
428
				   IRQF_ONESHOT,
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
				   dev_name(chip->dev), chip);
	if (err)
		mv88e6xxx_g1_irq_free_common(chip);

	return err;
}

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

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

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

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

	kthread_init_delayed_work(&chip->irq_poll_work,
				  mv88e6xxx_irq_poll);

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

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

	return 0;
}

static void mv88e6xxx_irq_poll_free(struct mv88e6xxx_chip *chip)
{
470 471
	mv88e6xxx_g1_irq_free_common(chip);

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

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

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

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

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

		usleep_range(1000, 2000);
	}

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

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

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

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

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

515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546
static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
				    int link, int speed, int duplex,
				    phy_interface_t mode)
{
	int err;

	if (!chip->info->ops->port_set_link)
		return 0;

	/* Port's MAC control must not be changed unless the link is down */
	err = chip->info->ops->port_set_link(chip, port, 0);
	if (err)
		return err;

	if (chip->info->ops->port_set_speed) {
		err = chip->info->ops->port_set_speed(chip, port, speed);
		if (err && err != -EOPNOTSUPP)
			goto restore_link;
	}

	if (chip->info->ops->port_set_duplex) {
		err = chip->info->ops->port_set_duplex(chip, port, duplex);
		if (err && err != -EOPNOTSUPP)
			goto restore_link;
	}

	if (chip->info->ops->port_set_rgmii_delay) {
		err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
		if (err && err != -EOPNOTSUPP)
			goto restore_link;
	}

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

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

	return err;
}

561 562 563 564
/* We expect the switch to perform auto negotiation if there is a real
 * phy. However, in the case of a fixed link phy, we force the port
 * settings from the fixed link settings.
 */
565 566
static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
				  struct phy_device *phydev)
567
{
V
Vivien Didelot 已提交
568
	struct mv88e6xxx_chip *chip = ds->priv;
569
	int err;
570 571 572 573

	if (!phy_is_pseudo_fixed_link(phydev))
		return;

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

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

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

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

591
static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650
	{ "in_good_octets",		8, 0x00, STATS_TYPE_BANK0, },
	{ "in_bad_octets",		4, 0x02, STATS_TYPE_BANK0, },
	{ "in_unicast",			4, 0x04, STATS_TYPE_BANK0, },
	{ "in_broadcasts",		4, 0x06, STATS_TYPE_BANK0, },
	{ "in_multicasts",		4, 0x07, STATS_TYPE_BANK0, },
	{ "in_pause",			4, 0x16, STATS_TYPE_BANK0, },
	{ "in_undersize",		4, 0x18, STATS_TYPE_BANK0, },
	{ "in_fragments",		4, 0x19, STATS_TYPE_BANK0, },
	{ "in_oversize",		4, 0x1a, STATS_TYPE_BANK0, },
	{ "in_jabber",			4, 0x1b, STATS_TYPE_BANK0, },
	{ "in_rx_error",		4, 0x1c, STATS_TYPE_BANK0, },
	{ "in_fcs_error",		4, 0x1d, STATS_TYPE_BANK0, },
	{ "out_octets",			8, 0x0e, STATS_TYPE_BANK0, },
	{ "out_unicast",		4, 0x10, STATS_TYPE_BANK0, },
	{ "out_broadcasts",		4, 0x13, STATS_TYPE_BANK0, },
	{ "out_multicasts",		4, 0x12, STATS_TYPE_BANK0, },
	{ "out_pause",			4, 0x15, STATS_TYPE_BANK0, },
	{ "excessive",			4, 0x11, STATS_TYPE_BANK0, },
	{ "collisions",			4, 0x1e, STATS_TYPE_BANK0, },
	{ "deferred",			4, 0x05, STATS_TYPE_BANK0, },
	{ "single",			4, 0x14, STATS_TYPE_BANK0, },
	{ "multiple",			4, 0x17, STATS_TYPE_BANK0, },
	{ "out_fcs_error",		4, 0x03, STATS_TYPE_BANK0, },
	{ "late",			4, 0x1f, STATS_TYPE_BANK0, },
	{ "hist_64bytes",		4, 0x08, STATS_TYPE_BANK0, },
	{ "hist_65_127bytes",		4, 0x09, STATS_TYPE_BANK0, },
	{ "hist_128_255bytes",		4, 0x0a, STATS_TYPE_BANK0, },
	{ "hist_256_511bytes",		4, 0x0b, STATS_TYPE_BANK0, },
	{ "hist_512_1023bytes",		4, 0x0c, STATS_TYPE_BANK0, },
	{ "hist_1024_max_bytes",	4, 0x0d, STATS_TYPE_BANK0, },
	{ "sw_in_discards",		4, 0x10, STATS_TYPE_PORT, },
	{ "sw_in_filtered",		2, 0x12, STATS_TYPE_PORT, },
	{ "sw_out_filtered",		2, 0x13, STATS_TYPE_PORT, },
	{ "in_discards",		4, 0x00, STATS_TYPE_BANK1, },
	{ "in_filtered",		4, 0x01, STATS_TYPE_BANK1, },
	{ "in_accepted",		4, 0x02, STATS_TYPE_BANK1, },
	{ "in_bad_accepted",		4, 0x03, STATS_TYPE_BANK1, },
	{ "in_good_avb_class_a",	4, 0x04, STATS_TYPE_BANK1, },
	{ "in_good_avb_class_b",	4, 0x05, STATS_TYPE_BANK1, },
	{ "in_bad_avb_class_a",		4, 0x06, STATS_TYPE_BANK1, },
	{ "in_bad_avb_class_b",		4, 0x07, STATS_TYPE_BANK1, },
	{ "tcam_counter_0",		4, 0x08, STATS_TYPE_BANK1, },
	{ "tcam_counter_1",		4, 0x09, STATS_TYPE_BANK1, },
	{ "tcam_counter_2",		4, 0x0a, STATS_TYPE_BANK1, },
	{ "tcam_counter_3",		4, 0x0b, STATS_TYPE_BANK1, },
	{ "in_da_unknown",		4, 0x0e, STATS_TYPE_BANK1, },
	{ "in_management",		4, 0x0f, STATS_TYPE_BANK1, },
	{ "out_queue_0",		4, 0x10, STATS_TYPE_BANK1, },
	{ "out_queue_1",		4, 0x11, STATS_TYPE_BANK1, },
	{ "out_queue_2",		4, 0x12, STATS_TYPE_BANK1, },
	{ "out_queue_3",		4, 0x13, STATS_TYPE_BANK1, },
	{ "out_queue_4",		4, 0x14, STATS_TYPE_BANK1, },
	{ "out_queue_5",		4, 0x15, STATS_TYPE_BANK1, },
	{ "out_queue_6",		4, 0x16, STATS_TYPE_BANK1, },
	{ "out_queue_7",		4, 0x17, STATS_TYPE_BANK1, },
	{ "out_cut_through",		4, 0x18, STATS_TYPE_BANK1, },
	{ "out_octets_a",		4, 0x1a, STATS_TYPE_BANK1, },
	{ "out_octets_b",		4, 0x1b, STATS_TYPE_BANK1, },
	{ "out_management",		4, 0x1f, STATS_TYPE_BANK1, },
651 652
};

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

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

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

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

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

	return j;
710 711
}

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

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

726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743
static const uint8_t *mv88e6xxx_atu_vtu_stats_strings[] = {
	"atu_member_violation",
	"atu_miss_violation",
	"atu_full_violation",
	"vtu_member_violation",
	"vtu_miss_violation",
};

static void mv88e6xxx_atu_vtu_get_strings(uint8_t *data)
{
	unsigned int i;

	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings); i++)
		strlcpy(data + i * ETH_GSTRING_LEN,
			mv88e6xxx_atu_vtu_stats_strings[i],
			ETH_GSTRING_LEN);
}

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

750 751 752
	if (stringset != ETH_SS_STATS)
		return;

753 754
	mutex_lock(&chip->reg_lock);

755
	if (chip->info->ops->stats_get_strings)
756 757 758 759
		count = chip->info->ops->stats_get_strings(chip, data);

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

763 764 765
	data += count * ETH_GSTRING_LEN;
	mv88e6xxx_atu_vtu_get_strings(data);

766
	mutex_unlock(&chip->reg_lock);
767 768 769 770 771
}

static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
					  int types)
{
772 773 774 775 776
	struct mv88e6xxx_hw_stat *stat;
	int i, j;

	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
		stat = &mv88e6xxx_hw_stats[i];
777
		if (stat->type & types)
778 779 780
			j++;
	}
	return j;
781 782
}

783 784 785 786 787 788 789 790 791 792 793 794
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);
}

795
static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
796 797
{
	struct mv88e6xxx_chip *chip = ds->priv;
798 799
	int serdes_count = 0;
	int count = 0;
800

801 802 803
	if (sset != ETH_SS_STATS)
		return 0;

804
	mutex_lock(&chip->reg_lock);
805
	if (chip->info->ops->stats_get_sset_count)
806 807 808 809 810 811 812
		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);
813
	if (serdes_count < 0) {
814
		count = serdes_count;
815 816 817 818 819
		goto out;
	}
	count += serdes_count;
	count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);

820
out:
821
	mutex_unlock(&chip->reg_lock);
822

823
	return count;
824 825
}

826 827 828
static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data, int types,
				     u16 bank1_select, u16 histogram)
829 830 831 832 833 834 835
{
	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) {
836
			mutex_lock(&chip->reg_lock);
837 838 839
			data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
							      bank1_select,
							      histogram);
840 841
			mutex_unlock(&chip->reg_lock);

842 843 844
			j++;
		}
	}
845
	return j;
846 847
}

848 849
static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
850 851
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
852
					 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
853
					 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
854 855
}

856 857
static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
858 859
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
860
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
861 862
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
					 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
863 864
}

865 866
static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
867 868 869
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
870 871
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
					 0);
872 873
}

874 875 876 877 878 879 880 881 882 883
static void mv88e6xxx_atu_vtu_get_stats(struct mv88e6xxx_chip *chip, int port,
					uint64_t *data)
{
	*data++ = chip->ports[port].atu_member_violation;
	*data++ = chip->ports[port].atu_miss_violation;
	*data++ = chip->ports[port].atu_full_violation;
	*data++ = chip->ports[port].vtu_member_violation;
	*data++ = chip->ports[port].vtu_miss_violation;
}

884 885 886
static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
				uint64_t *data)
{
887 888
	int count = 0;

889
	if (chip->info->ops->stats_get_stats)
890 891
		count = chip->info->ops->stats_get_stats(chip, port, data);

892
	mutex_lock(&chip->reg_lock);
893 894
	if (chip->info->ops->serdes_get_stats) {
		data += count;
895
		count = chip->info->ops->serdes_get_stats(chip, port, data);
896
	}
897 898 899
	data += count;
	mv88e6xxx_atu_vtu_get_stats(chip, port, data);
	mutex_unlock(&chip->reg_lock);
900 901
}

902 903
static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
					uint64_t *data)
904
{
V
Vivien Didelot 已提交
905
	struct mv88e6xxx_chip *chip = ds->priv;
906 907
	int ret;

908
	mutex_lock(&chip->reg_lock);
909

910
	ret = mv88e6xxx_stats_snapshot(chip, port);
911 912 913
	mutex_unlock(&chip->reg_lock);

	if (ret < 0)
914
		return;
915 916

	mv88e6xxx_get_stats(chip, port, data);
917

918 919
}

920 921 922 923 924 925 926 927
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;
}

928
static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
929 930 931 932
{
	return 32 * sizeof(u16);
}

933 934
static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
			       struct ethtool_regs *regs, void *_p)
935
{
V
Vivien Didelot 已提交
936
	struct mv88e6xxx_chip *chip = ds->priv;
937 938
	int err;
	u16 reg;
939 940 941 942 943 944 945
	u16 *p = _p;
	int i;

	regs->version = 0;

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

946
	mutex_lock(&chip->reg_lock);
947

948 949
	for (i = 0; i < 32; i++) {

950 951 952
		err = mv88e6xxx_port_read(chip, port, i, &reg);
		if (!err)
			p[i] = reg;
953
	}
954

955
	mutex_unlock(&chip->reg_lock);
956 957
}

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

V
Vivien Didelot 已提交
965 966
static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
967
{
968 969
	/* Nothing to do on the port's MAC */
	return 0;
970 971
}

972
static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
973
{
974 975 976
	struct dsa_switch *ds = NULL;
	struct net_device *br;
	u16 pvlan;
977 978
	int i;

979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998
	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 已提交
999
		    (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
1000 1001 1002 1003 1004
			pvlan |= BIT(i);

	return pvlan;
}

1005
static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
1006 1007
{
	u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
1008 1009 1010

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

1012
	return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
1013 1014
}

1015 1016
static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
					 u8 state)
1017
{
V
Vivien Didelot 已提交
1018
	struct mv88e6xxx_chip *chip = ds->priv;
1019
	int err;
1020

1021
	mutex_lock(&chip->reg_lock);
1022
	err = mv88e6xxx_port_set_state(chip, port, state);
1023
	mutex_unlock(&chip->reg_lock);
1024 1025

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

1029 1030 1031 1032 1033 1034 1035 1036
static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->pot_clear)
		return chip->info->ops->pot_clear(chip);

	return 0;
}

1037 1038 1039 1040 1041 1042 1043 1044
static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->mgmt_rsvd2cpu)
		return chip->info->ops->mgmt_rsvd2cpu(chip);

	return 0;
}

1045 1046
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
1047 1048
	int err;

1049 1050 1051 1052
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

1053 1054 1055 1056
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

1057 1058 1059
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079
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;
}

1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092
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;
}

1093 1094 1095 1096 1097 1098 1099 1100 1101
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)
1102
		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1103 1104 1105 1106

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

1107 1108
static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
{
1109 1110 1111
	int dev, port;
	int err;

1112 1113 1114 1115 1116 1117
	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.
	 */
1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130
	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;
1131 1132
}

1133 1134 1135 1136 1137 1138
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);
1139
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1140 1141 1142
	mutex_unlock(&chip->reg_lock);

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

1146 1147 1148 1149 1150 1151 1152 1153
static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
{
	if (!chip->info->max_vid)
		return 0;

	return mv88e6xxx_g1_vtu_flush(chip);
}

1154 1155 1156 1157 1158 1159 1160 1161 1162
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);
}

1163 1164 1165 1166 1167 1168 1169 1170 1171
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);
}

1172
static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1173 1174
{
	DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1175 1176 1177
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = chip->info->max_vid,
	};
1178
	int i, err;
1179 1180 1181

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

1182
	/* Set every FID bit used by the (un)bridged ports */
1183
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1184
		err = mv88e6xxx_port_get_fid(chip, i, fid);
1185 1186 1187 1188 1189 1190
		if (err)
			return err;

		set_bit(*fid, fid_bitmap);
	}

1191 1192
	/* Set every FID bit used by the VLAN entries */
	do {
1193
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1194 1195 1196 1197 1198 1199 1200
		if (err)
			return err;

		if (!vlan.valid)
			break;

		set_bit(vlan.fid, fid_bitmap);
1201
	} while (vlan.vid < chip->info->max_vid);
1202 1203 1204 1205 1206

	/* 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);
1207
	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1208 1209 1210
		return -ENOSPC;

	/* Clear the database */
1211
	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1212 1213
}

1214 1215
static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
			     struct mv88e6xxx_vtu_entry *entry, bool new)
1216 1217 1218 1219 1220 1221
{
	int err;

	if (!vid)
		return -EINVAL;

1222 1223
	entry->vid = vid - 1;
	entry->valid = false;
1224

1225
	err = mv88e6xxx_vtu_getnext(chip, entry);
1226 1227 1228
	if (err)
		return err;

1229 1230
	if (entry->vid == vid && entry->valid)
		return 0;
1231

1232 1233 1234 1235 1236 1237 1238 1239
	if (new) {
		int i;

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

1240
		/* Exclude all ports */
1241
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1242
			entry->member[i] =
1243
				MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1244 1245

		return mv88e6xxx_atu_new(chip, &entry->fid);
1246 1247
	}

1248 1249
	/* switchdev expects -EOPNOTSUPP to honor software VLANs */
	return -EOPNOTSUPP;
1250 1251
}

1252 1253 1254
static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
					u16 vid_begin, u16 vid_end)
{
V
Vivien Didelot 已提交
1255
	struct mv88e6xxx_chip *chip = ds->priv;
1256 1257 1258
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = vid_begin - 1,
	};
1259 1260
	int i, err;

1261 1262 1263 1264
	/* 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;

1265 1266 1267
	if (!vid_begin)
		return -EOPNOTSUPP;

1268
	mutex_lock(&chip->reg_lock);
1269 1270

	do {
1271
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1272 1273 1274 1275 1276 1277 1278 1279 1280
		if (err)
			goto unlock;

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

1281
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1282 1283 1284
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

1285
			if (!ds->ports[i].slave)
1286 1287
				continue;

1288
			if (vlan.member[i] ==
1289
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1290 1291
				continue;

V
Vivien Didelot 已提交
1292
			if (dsa_to_port(ds, i)->bridge_dev ==
1293
			    ds->ports[port].bridge_dev)
1294 1295
				break; /* same bridge, check next VLAN */

V
Vivien Didelot 已提交
1296
			if (!dsa_to_port(ds, i)->bridge_dev)
1297 1298
				continue;

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

unlock:
1308
	mutex_unlock(&chip->reg_lock);
1309 1310 1311 1312

	return err;
}

1313 1314
static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
					 bool vlan_filtering)
1315
{
V
Vivien Didelot 已提交
1316
	struct mv88e6xxx_chip *chip = ds->priv;
1317 1318
	u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
		MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
1319
	int err;
1320

1321
	if (!chip->info->max_vid)
1322 1323
		return -EOPNOTSUPP;

1324
	mutex_lock(&chip->reg_lock);
1325
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1326
	mutex_unlock(&chip->reg_lock);
1327

1328
	return err;
1329 1330
}

1331 1332
static int
mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1333
			    const struct switchdev_obj_port_vlan *vlan)
1334
{
V
Vivien Didelot 已提交
1335
	struct mv88e6xxx_chip *chip = ds->priv;
1336 1337
	int err;

1338
	if (!chip->info->max_vid)
1339 1340
		return -EOPNOTSUPP;

1341 1342 1343 1344 1345 1346 1347 1348
	/* 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;

1349 1350 1351 1352 1353 1354
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */
	return 0;
}

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

1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421
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;
}

1422
static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
1423
				    u16 vid, u8 member)
1424
{
1425
	struct mv88e6xxx_vtu_entry vlan;
1426 1427
	int err;

1428
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
1429
	if (err)
1430
		return err;
1431

1432
	vlan.member[port] = member;
1433

1434 1435 1436 1437 1438
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
	if (err)
		return err;

	return mv88e6xxx_broadcast_setup(chip, vid);
1439 1440
}

1441
static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1442
				    const struct switchdev_obj_port_vlan *vlan)
1443
{
V
Vivien Didelot 已提交
1444
	struct mv88e6xxx_chip *chip = ds->priv;
1445 1446
	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1447
	u8 member;
1448 1449
	u16 vid;

1450
	if (!chip->info->max_vid)
1451 1452
		return;

1453
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1454
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1455
	else if (untagged)
1456
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
1457
	else
1458
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
1459

1460
	mutex_lock(&chip->reg_lock);
1461

1462
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
1463
		if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
1464 1465
			dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
				vid, untagged ? 'u' : 't');
1466

1467
	if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1468 1469
		dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
			vlan->vid_end);
1470

1471
	mutex_unlock(&chip->reg_lock);
1472 1473
}

1474
static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
1475
				    int port, u16 vid)
1476
{
1477
	struct mv88e6xxx_vtu_entry vlan;
1478 1479
	int i, err;

1480
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1481
	if (err)
1482
		return err;
1483

1484
	/* Tell switchdev if this VLAN is handled in software */
1485
	if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1486
		return -EOPNOTSUPP;
1487

1488
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1489 1490

	/* keep the VLAN unless all ports are excluded */
1491
	vlan.valid = false;
1492
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1493 1494
		if (vlan.member[i] !=
		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
1495
			vlan.valid = true;
1496 1497 1498 1499
			break;
		}
	}

1500
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1501 1502 1503
	if (err)
		return err;

1504
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
1505 1506
}

1507 1508
static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
				   const struct switchdev_obj_port_vlan *vlan)
1509
{
V
Vivien Didelot 已提交
1510
	struct mv88e6xxx_chip *chip = ds->priv;
1511 1512 1513
	u16 pvid, vid;
	int err = 0;

1514
	if (!chip->info->max_vid)
1515 1516
		return -EOPNOTSUPP;

1517
	mutex_lock(&chip->reg_lock);
1518

1519
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
1520 1521 1522
	if (err)
		goto unlock;

1523
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1524
		err = _mv88e6xxx_port_vlan_del(chip, port, vid);
1525 1526 1527 1528
		if (err)
			goto unlock;

		if (vid == pvid) {
1529
			err = mv88e6xxx_port_set_pvid(chip, port, 0);
1530 1531 1532 1533 1534
			if (err)
				goto unlock;
		}
	}

1535
unlock:
1536
	mutex_unlock(&chip->reg_lock);
1537 1538 1539 1540

	return err;
}

1541 1542
static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
				  const unsigned char *addr, u16 vid)
1543
{
V
Vivien Didelot 已提交
1544
	struct mv88e6xxx_chip *chip = ds->priv;
1545
	int err;
1546

1547
	mutex_lock(&chip->reg_lock);
1548 1549
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1550
	mutex_unlock(&chip->reg_lock);
1551 1552

	return err;
1553 1554
}

1555
static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1556
				  const unsigned char *addr, u16 vid)
1557
{
V
Vivien Didelot 已提交
1558
	struct mv88e6xxx_chip *chip = ds->priv;
1559
	int err;
1560

1561
	mutex_lock(&chip->reg_lock);
1562
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1563
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
1564
	mutex_unlock(&chip->reg_lock);
1565

1566
	return err;
1567 1568
}

1569 1570
static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
				      u16 fid, u16 vid, int port,
1571
				      dsa_fdb_dump_cb_t *cb, void *data)
1572
{
1573
	struct mv88e6xxx_atu_entry addr;
1574
	bool is_static;
1575 1576
	int err;

1577
	addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1578
	eth_broadcast_addr(addr.mac);
1579 1580

	do {
1581
		mutex_lock(&chip->reg_lock);
1582
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
1583
		mutex_unlock(&chip->reg_lock);
1584
		if (err)
1585
			return err;
1586

1587
		if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
1588 1589
			break;

1590
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
1591 1592
			continue;

1593 1594
		if (!is_unicast_ether_addr(addr.mac))
			continue;
1595

1596 1597 1598
		is_static = (addr.state ==
			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
		err = cb(addr.mac, vid, is_static, data);
1599 1600
		if (err)
			return err;
1601 1602 1603 1604 1605
	} while (!is_broadcast_ether_addr(addr.mac));

	return err;
}

1606
static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1607
				  dsa_fdb_dump_cb_t *cb, void *data)
1608
{
1609
	struct mv88e6xxx_vtu_entry vlan = {
1610
		.vid = chip->info->max_vid,
1611
	};
1612
	u16 fid;
1613 1614
	int err;

1615
	/* Dump port's default Filtering Information Database (VLAN ID 0) */
1616
	mutex_lock(&chip->reg_lock);
1617
	err = mv88e6xxx_port_get_fid(chip, port, &fid);
1618 1619
	mutex_unlock(&chip->reg_lock);

1620
	if (err)
1621
		return err;
1622

1623
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
1624
	if (err)
1625
		return err;
1626

1627
	/* Dump VLANs' Filtering Information Databases */
1628
	do {
1629
		mutex_lock(&chip->reg_lock);
1630
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1631
		mutex_unlock(&chip->reg_lock);
1632
		if (err)
1633
			return err;
1634 1635 1636 1637

		if (!vlan.valid)
			break;

1638
		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1639
						 cb, data);
1640
		if (err)
1641
			return err;
1642
	} while (vlan.vid < chip->info->max_vid);
1643

1644 1645 1646 1647
	return err;
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1648
				   dsa_fdb_dump_cb_t *cb, void *data)
1649
{
V
Vivien Didelot 已提交
1650
	struct mv88e6xxx_chip *chip = ds->priv;
1651

1652
	return mv88e6xxx_port_db_dump(chip, port, cb, data);
1653 1654
}

1655 1656
static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
				struct net_device *br)
1657
{
1658
	struct dsa_switch *ds;
1659
	int port;
1660
	int dev;
1661
	int err;
1662

1663 1664 1665 1666
	/* 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);
1667
			if (err)
1668
				return err;
1669 1670 1671
		}
	}

1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689
	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;
			}
		}
	}

1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700
	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);
1701
	mutex_unlock(&chip->reg_lock);
1702

1703
	return err;
1704 1705
}

1706 1707
static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
					struct net_device *br)
1708
{
V
Vivien Didelot 已提交
1709
	struct mv88e6xxx_chip *chip = ds->priv;
1710

1711
	mutex_lock(&chip->reg_lock);
1712 1713 1714
	if (mv88e6xxx_bridge_map(chip, br) ||
	    mv88e6xxx_port_vlan_map(chip, port))
		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
1715
	mutex_unlock(&chip->reg_lock);
1716 1717
}

1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747
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);
}

1748 1749 1750 1751 1752 1753 1754 1755
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->reset)
		return chip->info->ops->reset(chip);

	return 0;
}

1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768
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);
	}
}

1769
static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1770
{
1771
	int i, err;
1772

1773
	/* Set all ports to the Disabled state */
1774
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
1775
		err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
1776 1777
		if (err)
			return err;
1778 1779
	}

1780 1781 1782
	/* Wait for transmit queues to drain,
	 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
	 */
1783 1784
	usleep_range(2000, 4000);

1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795
	return 0;
}

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

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

1796
	mv88e6xxx_hardware_reset(chip);
1797

1798
	return mv88e6xxx_software_reset(chip);
1799 1800
}

1801
static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
1802 1803
				   enum mv88e6xxx_frame_mode frame,
				   enum mv88e6xxx_egress_mode egress, u16 etype)
1804 1805 1806
{
	int err;

1807 1808 1809 1810
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
1811 1812 1813
	if (err)
		return err;

1814 1815 1816 1817 1818 1819 1820 1821
	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;
1822 1823
}

1824
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1825
{
1826
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
1827
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
1828
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
1829
}
1830

1831 1832 1833
static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
1834
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
1835
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
1836
}
1837

1838 1839 1840 1841
static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port,
				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
1842 1843
				       MV88E6XXX_EGRESS_MODE_ETHERTYPE,
				       ETH_P_EDSA);
1844
}
1845

1846 1847 1848 1849
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);
1850

1851
	if (dsa_is_user_port(chip->ds, port))
1852
		return mv88e6xxx_set_port_mode_normal(chip, port);
1853

1854 1855 1856
	/* 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);
1857

1858 1859
	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
		return mv88e6xxx_set_port_mode_edsa(chip, port);
1860

1861
	return -EINVAL;
1862 1863
}

1864
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
1865
{
1866
	bool message = dsa_is_dsa_port(chip->ds, port);
1867

1868
	return mv88e6xxx_port_set_message_port(chip, port, message);
1869
}
1870

1871
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
1872
{
1873 1874
	struct dsa_switch *ds = chip->ds;
	bool flood;
1875

1876
	/* Upstream ports flood frames with unknown unicast or multicast DA */
1877
	flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
1878 1879 1880
	if (chip->info->ops->port_set_egress_floods)
		return chip->info->ops->port_set_egress_floods(chip, port,
							       flood, flood);
1881

1882
	return 0;
1883 1884
}

1885 1886 1887
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
1888 1889
	if (chip->info->ops->serdes_power)
		return chip->info->ops->serdes_power(chip, port, on);
1890

1891
	return 0;
1892 1893
}

1894 1895 1896 1897 1898 1899
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

1900
	upstream_port = dsa_upstream_port(ds, port);
1901 1902 1903 1904 1905 1906 1907
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923
	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;
		}
	}

1924 1925 1926
	return 0;
}

1927
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
1928
{
1929
	struct dsa_switch *ds = chip->ds;
1930
	int err;
1931
	u16 reg;
1932

1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946
	/* 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;
1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961

	/* 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.
	 */
1962 1963 1964 1965
	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);
1966 1967
	if (err)
		return err;
1968

1969
	err = mv88e6xxx_setup_port_mode(chip, port);
1970 1971
	if (err)
		return err;
1972

1973
	err = mv88e6xxx_setup_egress_floods(chip, port);
1974 1975 1976
	if (err)
		return err;

1977 1978 1979
	/* 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.
1980
	 */
1981 1982 1983 1984 1985
	if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
		err = mv88e6xxx_serdes_power(chip, port, true);
		if (err)
			return err;
	}
1986

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

1997 1998 1999
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
2000

2001
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
2002
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
2003 2004 2005
	if (err)
		return err;

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

2012 2013 2014 2015 2016
	/* 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.
	 */
2017
	reg = 1 << port;
2018 2019
	/* Disable learning for CPU port */
	if (dsa_is_cpu_port(ds, port))
2020
		reg = 0;
2021

2022 2023
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
2024 2025
	if (err)
		return err;
2026 2027

	/* Egress rate control 2: disable egress rate control. */
2028 2029
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
				   0x0000);
2030 2031
	if (err)
		return err;
2032

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

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

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

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

2057 2058
	if (chip->info->ops->port_egress_rate_limiting) {
		err = chip->info->ops->port_egress_rate_limiting(chip, port);
2059 2060
		if (err)
			return err;
2061 2062
	}

2063
	err = mv88e6xxx_setup_message_port(chip, port);
2064 2065
	if (err)
		return err;
2066

2067
	/* Port based VLAN map: give each port the same default address
2068 2069
	 * database, and allow bidirectional communication between the
	 * CPU and DSA port(s), and the other ports.
2070
	 */
2071
	err = mv88e6xxx_port_set_fid(chip, port, 0);
2072 2073
	if (err)
		return err;
2074

2075
	err = mv88e6xxx_port_vlan_map(chip, port);
2076 2077
	if (err)
		return err;
2078 2079 2080 2081

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

2085 2086 2087 2088
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
2089
	int err;
2090 2091

	mutex_lock(&chip->reg_lock);
2092
	err = mv88e6xxx_serdes_power(chip, port, true);
2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103
	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);
2104 2105
	if (mv88e6xxx_serdes_power(chip, port, false))
		dev_err(chip->dev, "failed to power off SERDES\n");
2106 2107 2108
	mutex_unlock(&chip->reg_lock);
}

2109 2110 2111
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
2112
	struct mv88e6xxx_chip *chip = ds->priv;
2113 2114 2115
	int err;

	mutex_lock(&chip->reg_lock);
2116
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2117 2118 2119 2120 2121
	mutex_unlock(&chip->reg_lock);

	return err;
}

2122
static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
2123
{
2124
	struct dsa_switch *ds = chip->ds;
2125
	int err;
2126

2127
	/* Disable remote management, and set the switch's DSA device number. */
2128 2129
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL2,
				 MV88E6XXX_G1_CTL2_MULTIPLE_CASCADE |
2130
				 (ds->index & 0x1f));
2131 2132 2133
	if (err)
		return err;

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

	/* Configure the IEEE 802.1p priority mapping register. */
2161
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IEEE_PRI, 0xfa41);
2162
	if (err)
2163
		return err;
2164

2165 2166 2167 2168 2169
	/* Initialize the statistics unit */
	err = mv88e6xxx_stats_set_histogram(chip);
	if (err)
		return err;

2170
	return mv88e6xxx_g1_stats_clear(chip);
2171 2172
}

2173
static int mv88e6xxx_setup(struct dsa_switch *ds)
2174
{
V
Vivien Didelot 已提交
2175
	struct mv88e6xxx_chip *chip = ds->priv;
2176
	int err;
2177 2178
	int i;

2179
	chip->ds = ds;
2180
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
2181

2182
	mutex_lock(&chip->reg_lock);
2183

2184
	/* Setup Switch Port Registers */
2185
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2186 2187 2188
		if (dsa_is_unused_port(ds, i))
			continue;

2189 2190 2191 2192 2193 2194 2195
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

	/* Setup Switch Global 1 Registers */
	err = mv88e6xxx_g1_setup(chip);
2196 2197 2198
	if (err)
		goto unlock;

2199
	/* Setup Switch Global 2 Registers */
2200
	if (chip->info->global2_addr) {
2201
		err = mv88e6xxx_g2_setup(chip);
2202 2203 2204
		if (err)
			goto unlock;
	}
2205

2206 2207 2208 2209
	err = mv88e6xxx_irl_setup(chip);
	if (err)
		goto unlock;

2210 2211 2212 2213
	err = mv88e6xxx_mac_setup(chip);
	if (err)
		goto unlock;

2214 2215 2216 2217
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

2218 2219 2220 2221
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

2222 2223 2224 2225
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

2226 2227 2228 2229
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

2230 2231 2232 2233
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

2234 2235 2236 2237
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

2238 2239 2240
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
2241

2242
	/* Setup PTP Hardware Clock and timestamping */
2243 2244 2245 2246
	if (chip->info->ptp_support) {
		err = mv88e6xxx_ptp_setup(chip);
		if (err)
			goto unlock;
2247 2248 2249 2250

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
2251 2252
	}

2253
unlock:
2254
	mutex_unlock(&chip->reg_lock);
2255

2256
	return err;
2257 2258
}

2259
static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
2260
{
2261 2262
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2263 2264
	u16 val;
	int err;
2265

2266 2267 2268
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

2269
	mutex_lock(&chip->reg_lock);
2270
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
2271
	mutex_unlock(&chip->reg_lock);
2272

2273 2274 2275 2276 2277
	if (reg == MII_PHYSID2) {
		/* Some internal PHYS don't have a model number.  Use
		 * the mv88e6390 family model number instead.
		 */
		if (!(val & 0x3f0))
2278
			val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
2279 2280
	}

2281
	return err ? err : val;
2282 2283
}

2284
static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
2285
{
2286 2287
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2288
	int err;
2289

2290 2291 2292
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

2293
	mutex_lock(&chip->reg_lock);
2294
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
2295
	mutex_unlock(&chip->reg_lock);
2296 2297

	return err;
2298 2299
}

2300
static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
2301 2302
				   struct device_node *np,
				   bool external)
2303 2304
{
	static int index;
2305
	struct mv88e6xxx_mdio_bus *mdio_bus;
2306 2307 2308
	struct mii_bus *bus;
	int err;

2309 2310 2311 2312 2313 2314 2315 2316 2317
	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;
	}

2318
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
2319 2320 2321
	if (!bus)
		return -ENOMEM;

2322
	mdio_bus = bus->priv;
2323
	mdio_bus->bus = bus;
2324
	mdio_bus->chip = chip;
2325 2326
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
2327

2328 2329
	if (np) {
		bus->name = np->full_name;
2330
		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
2331 2332 2333 2334 2335 2336 2337
	} 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;
2338
	bus->parent = chip->dev;
2339

2340 2341 2342 2343 2344 2345
	if (!external) {
		err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
		if (err)
			return err;
	}

2346 2347
	if (np)
		err = of_mdiobus_register(bus, np);
2348 2349 2350
	else
		err = mdiobus_register(bus);
	if (err) {
2351
		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
2352
		mv88e6xxx_g2_irq_mdio_free(chip, bus);
2353
		return err;
2354
	}
2355 2356 2357 2358 2359

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

	return 0;
2362
}
2363

2364 2365 2366 2367 2368
static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
	{ .compatible = "marvell,mv88e6xxx-mdio-external",
	  .data = (void *)true },
	{ },
};
2369

2370 2371 2372 2373 2374 2375 2376 2377 2378
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;

2379 2380 2381
		if (!mdio_bus->external)
			mv88e6xxx_g2_irq_mdio_free(chip, bus);

2382 2383 2384 2385
		mdiobus_unregister(bus);
	}
}

2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409
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);
2410 2411
			if (err) {
				mv88e6xxx_mdios_unregister(chip);
2412
				return err;
2413
			}
2414 2415 2416 2417
		}
	}

	return 0;
2418 2419
}

2420 2421
static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
2422
	struct mv88e6xxx_chip *chip = ds->priv;
2423 2424 2425 2426 2427 2428 2429

	return chip->eeprom_len;
}

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

2433 2434
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
2435

2436 2437
	mutex_lock(&chip->reg_lock);
	err = chip->info->ops->get_eeprom(chip, eeprom, data);
2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450
	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 已提交
2451
	struct mv88e6xxx_chip *chip = ds->priv;
2452 2453
	int err;

2454 2455 2456
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

2457 2458 2459 2460
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

	mutex_lock(&chip->reg_lock);
2461
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
2462 2463 2464 2465 2466
	mutex_unlock(&chip->reg_lock);

	return err;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

static const struct mv88e6xxx_ops mv88e6191_ops = {
2959
	/* MV88E6XXX_FAMILY_6390 */
2960
	.irl_init_all = mv88e6390_g2_irl_init_all,
2961 2962
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
2963 2964 2965 2966 2967 2968 2969
	.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,
2970
	.port_tag_remap = mv88e6390_port_tag_remap,
2971
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2972
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2973
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2974
	.port_pause_limit = mv88e6390_port_pause_limit,
2975
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2976
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2977
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
2978
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
2979 2980
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
2981
	.stats_get_stats = mv88e6390_stats_get_stats,
2982 2983
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
2984
	.watchdog_ops = &mv88e6390_watchdog_ops,
2985
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
2986
	.pot_clear = mv88e6xxx_g2_pot_clear,
2987
	.reset = mv88e6352_g1_reset,
2988 2989
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
2990
	.serdes_power = mv88e6390_serdes_power,
2991 2992
};

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	[MV88E6321] = {
3776
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
3777 3778 3779 3780
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6321",
		.num_databases = 4096,
		.num_ports = 7,
3781
		.num_internal_phys = 5,
3782
		.num_gpio = 15,
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 = 8,
3789
		.g2_irqs = 10,
3790
		.atu_move_port_mask = 0xf,
3791
		.multi_chip = true,
3792
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3793
		.ptp_support = true,
3794
		.ops = &mv88e6321_ops,
3795 3796
	},

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

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

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

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

3930
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
3931
{
3932
	int i;
3933

3934 3935 3936
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
3937 3938 3939 3940

	return NULL;
}

3941
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
3942 3943
{
	const struct mv88e6xxx_info *info;
3944 3945 3946
	unsigned int prod_num, rev;
	u16 id;
	int err;
3947

3948
	mutex_lock(&chip->reg_lock);
3949
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
3950 3951 3952
	mutex_unlock(&chip->reg_lock);
	if (err)
		return err;
3953

3954 3955
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
3956 3957 3958 3959 3960

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

3961
	/* Update the compatible info with the probed one */
3962
	chip->info = info;
3963

3964 3965 3966 3967
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

3968 3969
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
3970 3971 3972 3973

	return 0;
}

3974
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
3975
{
3976
	struct mv88e6xxx_chip *chip;
3977

3978 3979
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
3980 3981
		return NULL;

3982
	chip->dev = dev;
3983

3984
	mutex_init(&chip->reg_lock);
3985
	INIT_LIST_HEAD(&chip->mdios);
3986

3987
	return chip;
3988 3989
}

3990
static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
3991 3992
			      struct mii_bus *bus, int sw_addr)
{
3993
	if (sw_addr == 0)
3994
		chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
3995
	else if (chip->info->multi_chip)
3996
		chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
3997 3998 3999
	else
		return -EINVAL;

4000 4001
	chip->bus = bus;
	chip->sw_addr = sw_addr;
4002 4003 4004 4005

	return 0;
}

4006 4007
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
							int port)
4008
{
V
Vivien Didelot 已提交
4009
	struct mv88e6xxx_chip *chip = ds->priv;
4010

4011
	return chip->info->tag_protocol;
4012 4013
}

4014
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
4015 4016 4017
static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
				       struct device *host_dev, int sw_addr,
				       void **priv)
4018
{
4019
	struct mv88e6xxx_chip *chip;
4020
	struct mii_bus *bus;
4021
	int err;
4022

4023
	bus = dsa_host_dev_to_mii_bus(host_dev);
4024 4025 4026
	if (!bus)
		return NULL;

4027 4028
	chip = mv88e6xxx_alloc_chip(dsa_dev);
	if (!chip)
4029 4030
		return NULL;

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

4034
	err = mv88e6xxx_smi_init(chip, bus, sw_addr);
4035 4036 4037
	if (err)
		goto free;

4038
	err = mv88e6xxx_detect(chip);
4039
	if (err)
4040
		goto free;
4041

4042 4043 4044 4045 4046 4047
	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_switch_reset(chip);
	mutex_unlock(&chip->reg_lock);
	if (err)
		goto free;

4048 4049
	mv88e6xxx_phy_init(chip);

4050
	err = mv88e6xxx_mdios_register(chip, NULL);
4051
	if (err)
4052
		goto free;
4053

4054
	*priv = chip;
4055

4056
	return chip->info->name;
4057
free:
4058
	devm_kfree(dsa_dev, chip);
4059 4060

	return NULL;
4061
}
4062
#endif
4063

4064
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4065
				      const struct switchdev_obj_port_mdb *mdb)
4066 4067 4068 4069 4070 4071 4072 4073 4074
{
	/* 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,
4075
				   const struct switchdev_obj_port_mdb *mdb)
4076
{
V
Vivien Didelot 已提交
4077
	struct mv88e6xxx_chip *chip = ds->priv;
4078 4079 4080

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

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4095
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
4096 4097 4098 4099 4100
	mutex_unlock(&chip->reg_lock);

	return err;
}

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

4144 4145 4146 4147
static struct dsa_switch_driver mv88e6xxx_switch_drv = {
	.ops			= &mv88e6xxx_switch_ops,
};

4148
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
4149
{
4150
	struct device *dev = chip->dev;
4151 4152
	struct dsa_switch *ds;

4153
	ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
4154 4155 4156
	if (!ds)
		return -ENOMEM;

4157
	ds->priv = chip;
4158
	ds->ops = &mv88e6xxx_switch_ops;
4159 4160
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
4161 4162 4163

	dev_set_drvdata(dev, ds);

4164
	return dsa_register_switch(ds);
4165 4166
}

4167
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
4168
{
4169
	dsa_unregister_switch(chip->ds);
4170 4171
}

4172
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
4173
{
4174
	struct device *dev = &mdiodev->dev;
4175
	struct device_node *np = dev->of_node;
4176
	const struct mv88e6xxx_info *compat_info;
4177
	struct mv88e6xxx_chip *chip;
4178
	u32 eeprom_len;
4179
	int err;
4180

4181 4182 4183 4184
	compat_info = of_device_get_match_data(dev);
	if (!compat_info)
		return -EINVAL;

4185 4186
	chip = mv88e6xxx_alloc_chip(dev);
	if (!chip)
4187 4188
		return -ENOMEM;

4189
	chip->info = compat_info;
4190

4191
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
4192 4193
	if (err)
		return err;
4194

4195 4196 4197 4198
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
	if (IS_ERR(chip->reset))
		return PTR_ERR(chip->reset);

4199
	err = mv88e6xxx_detect(chip);
4200 4201
	if (err)
		return err;
4202

4203 4204
	mv88e6xxx_phy_init(chip);

4205
	if (chip->info->ops->get_eeprom &&
4206
	    !of_property_read_u32(np, "eeprom-length", &eeprom_len))
4207
		chip->eeprom_len = eeprom_len;
4208

4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220
	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;
	}

4221
	/* Has to be performed before the MDIO bus is created, because
4222
	 * the PHYs will link their interrupts to these interrupt
4223 4224 4225 4226
	 * controllers
	 */
	mutex_lock(&chip->reg_lock);
	if (chip->irq > 0)
4227
		err = mv88e6xxx_g1_irq_setup(chip);
4228 4229 4230
	else
		err = mv88e6xxx_irq_poll_setup(chip);
	mutex_unlock(&chip->reg_lock);
4231

4232 4233
	if (err)
		goto out;
4234

4235 4236
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
4237
		if (err)
4238
			goto out_g1_irq;
4239 4240
	}

4241 4242 4243 4244 4245 4246 4247 4248
	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;

4249
	err = mv88e6xxx_mdios_register(chip, np);
4250
	if (err)
4251
		goto out_g1_vtu_prob_irq;
4252

4253
	err = mv88e6xxx_register_switch(chip);
4254 4255
	if (err)
		goto out_mdio;
4256

4257
	return 0;
4258 4259

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

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

4284 4285
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
4286
		mv88e6xxx_ptp_free(chip);
4287
	}
4288

4289
	mv88e6xxx_phy_destroy(chip);
4290
	mv88e6xxx_unregister_switch(chip);
4291
	mv88e6xxx_mdios_unregister(chip);
4292

4293 4294 4295 4296 4297 4298 4299 4300
	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)
4301
		mv88e6xxx_g1_irq_free(chip);
4302 4303 4304
	else
		mv88e6xxx_irq_poll_free(chip);
	mutex_unlock(&chip->reg_lock);
4305 4306 4307
}

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

static void __exit mv88e6xxx_cleanup(void)
{
4339
	mdio_driver_unregister(&mv88e6xxx_driver);
4340
	unregister_switch_driver(&mv88e6xxx_switch_drv);
4341 4342
}
module_exit(mv88e6xxx_cleanup);
4343 4344 4345 4346

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