chip.c 116.4 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 256 257 258 259 260 261 262 263 264 265
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);
}

static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id)
{
	struct mv88e6xxx_chip *chip = dev_id;
	unsigned int nhandled = 0;
	unsigned int sub_irq;
	unsigned int n;
	u16 reg;
	int err;

	mutex_lock(&chip->reg_lock);
266
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
	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);
}

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;

297
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &reg);
298 299 300 301 302 303
	if (err)
		goto out;

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

304
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, reg);
305 306 307 308 309 310 311
	if (err)
		goto out;

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

312
static const struct irq_chip mv88e6xxx_g1_irq_chip = {
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
	.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,
};

static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
{
	int irq, virq;
341 342
	u16 mask;

343
	mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
344
	mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
345
	mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
346 347

	free_irq(chip->irq, chip);
348

349
	for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
350
		virq = irq_find_mapping(chip->g1_irq.domain, irq);
351 352 353
		irq_dispose_mapping(virq);
	}

354
	irq_domain_remove(chip->g1_irq.domain);
355 356 357 358
}

static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
{
359 360
	int err, irq, virq;
	u16 reg, mask;
361 362 363 364 365 366 367 368 369 370 371 372 373 374

	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;

375
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
376
	if (err)
377
		goto out_mapping;
378

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

381
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
382
	if (err)
383
		goto out_disable;
384 385

	/* Reading the interrupt status clears (most of) them */
386
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
387
	if (err)
388
		goto out_disable;
389 390 391 392 393 394

	err = request_threaded_irq(chip->irq, NULL,
				   mv88e6xxx_g1_irq_thread_fn,
				   IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
				   dev_name(chip->dev), chip);
	if (err)
395
		goto out_disable;
396 397 398

	return 0;

399
out_disable:
400
	mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
401
	mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
402 403 404 405 406 407 408 409

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);
410 411 412 413

	return err;
}

414
int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask)
415
{
416
	int i;
417

418
	for (i = 0; i < 16; i++) {
419 420 421 422 423 424 425 426 427 428 429 430 431
		u16 val;
		int err;

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

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

		usleep_range(1000, 2000);
	}

432
	dev_err(chip->dev, "Timeout while waiting for switch\n");
433 434 435
	return -ETIMEDOUT;
}

436
/* Indirect write to single pointer-data register with an Update bit */
437
int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
438 439
{
	u16 val;
440
	int err;
441 442

	/* Wait until the previous operation is completed */
443 444 445
	err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
	if (err)
		return err;
446 447 448 449 450 451 452

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

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

453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
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;
	}

485 486 487 488 489 490
	if (chip->info->ops->port_set_cmode) {
		err = chip->info->ops->port_set_cmode(chip, port, mode);
		if (err && err != -EOPNOTSUPP)
			goto restore_link;
	}

491 492 493
	err = 0;
restore_link:
	if (chip->info->ops->port_set_link(chip, port, link))
494
		dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
495 496 497 498

	return err;
}

499 500 501 502
/* 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.
 */
503 504
static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
				  struct phy_device *phydev)
505
{
V
Vivien Didelot 已提交
506
	struct mv88e6xxx_chip *chip = ds->priv;
507
	int err;
508 509 510 511

	if (!phy_is_pseudo_fixed_link(phydev))
		return;

512
	mutex_lock(&chip->reg_lock);
513 514
	err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
				       phydev->duplex, phydev->interface);
515
	mutex_unlock(&chip->reg_lock);
516 517

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

521
static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
522
{
523 524
	if (!chip->info->ops->stats_snapshot)
		return -EOPNOTSUPP;
525

526
	return chip->info->ops->stats_snapshot(chip, port);
527 528
}

529
static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588
	{ "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, },
589 590
};

591
static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
592
					    struct mv88e6xxx_hw_stat *s,
593 594
					    int port, u16 bank1_select,
					    u16 histogram)
595 596 597
{
	u32 low;
	u32 high = 0;
598
	u16 reg = 0;
599
	int err;
600 601
	u64 value;

602
	switch (s->type) {
603
	case STATS_TYPE_PORT:
604 605
		err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
		if (err)
606 607
			return UINT64_MAX;

608
		low = reg;
609
		if (s->sizeof_stat == 4) {
610 611
			err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
			if (err)
612
				return UINT64_MAX;
613
			high = reg;
614
		}
615
		break;
616
	case STATS_TYPE_BANK1:
617
		reg = bank1_select;
618 619
		/* fall through */
	case STATS_TYPE_BANK0:
620
		reg |= s->reg | histogram;
621
		mv88e6xxx_g1_stats_read(chip, reg, &low);
622
		if (s->sizeof_stat == 8)
623
			mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
624 625 626
		break;
	default:
		return UINT64_MAX;
627 628 629 630 631
	}
	value = (((u64)high) << 16) | low;
	return value;
}

632 633
static void mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
					uint8_t *data, int types)
634
{
635 636
	struct mv88e6xxx_hw_stat *stat;
	int i, j;
637

638 639
	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
		stat = &mv88e6xxx_hw_stats[i];
640
		if (stat->type & types) {
641 642 643 644
			memcpy(data + j * ETH_GSTRING_LEN, stat->string,
			       ETH_GSTRING_LEN);
			j++;
		}
645
	}
646 647
}

648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663
static void mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
					uint8_t *data)
{
	mv88e6xxx_stats_get_strings(chip, data,
				    STATS_TYPE_BANK0 | STATS_TYPE_PORT);
}

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

static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
				  uint8_t *data)
664
{
V
Vivien Didelot 已提交
665
	struct mv88e6xxx_chip *chip = ds->priv;
666 667 668 669 670 671 672 673

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

static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
					  int types)
{
674 675 676 677 678
	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];
679
		if (stat->type & types)
680 681 682
			j++;
	}
	return j;
683 684
}

685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706
static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
{
	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
					      STATS_TYPE_PORT);
}

static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
{
	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
					      STATS_TYPE_BANK1);
}

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

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

	return 0;
}

707
static void mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
708 709
				      uint64_t *data, int types,
				      u16 bank1_select, u16 histogram)
710 711 712 713 714 715 716
{
	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) {
717
			mutex_lock(&chip->reg_lock);
718 719 720
			data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
							      bank1_select,
							      histogram);
721 722
			mutex_unlock(&chip->reg_lock);

723 724 725 726 727 728 729 730 731
			j++;
		}
	}
}

static void mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				      uint64_t *data)
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
732
					 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
733
					 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
734 735 736 737 738 739
}

static void mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				      uint64_t *data)
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
740
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
741 742
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
					 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
743 744 745 746 747 748 749
}

static void mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				      uint64_t *data)
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
750 751
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
					 0);
752 753 754 755 756 757 758 759 760
}

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

761 762
static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
					uint64_t *data)
763
{
V
Vivien Didelot 已提交
764
	struct mv88e6xxx_chip *chip = ds->priv;
765 766
	int ret;

767
	mutex_lock(&chip->reg_lock);
768

769
	ret = mv88e6xxx_stats_snapshot(chip, port);
770 771 772
	mutex_unlock(&chip->reg_lock);

	if (ret < 0)
773
		return;
774 775

	mv88e6xxx_get_stats(chip, port, data);
776

777 778
}

779 780 781 782 783 784 785 786
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;
}

787
static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
788 789 790 791
{
	return 32 * sizeof(u16);
}

792 793
static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
			       struct ethtool_regs *regs, void *_p)
794
{
V
Vivien Didelot 已提交
795
	struct mv88e6xxx_chip *chip = ds->priv;
796 797
	int err;
	u16 reg;
798 799 800 801 802 803 804
	u16 *p = _p;
	int i;

	regs->version = 0;

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

805
	mutex_lock(&chip->reg_lock);
806

807 808
	for (i = 0; i < 32; i++) {

809 810 811
		err = mv88e6xxx_port_read(chip, port, i, &reg);
		if (!err)
			p[i] = reg;
812
	}
813

814
	mutex_unlock(&chip->reg_lock);
815 816
}

V
Vivien Didelot 已提交
817 818
static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
819
{
820 821
	/* Nothing to do on the port's MAC */
	return 0;
822 823
}

V
Vivien Didelot 已提交
824 825
static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
826
{
827 828
	/* Nothing to do on the port's MAC */
	return 0;
829 830
}

831
static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
832
{
833 834 835
	struct dsa_switch *ds = NULL;
	struct net_device *br;
	u16 pvlan;
836 837
	int i;

838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857
	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 已提交
858
		    (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
859 860 861 862 863
			pvlan |= BIT(i);

	return pvlan;
}

864
static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
865 866
{
	u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
867 868 869

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

871
	return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
872 873
}

874 875
static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
					 u8 state)
876
{
V
Vivien Didelot 已提交
877
	struct mv88e6xxx_chip *chip = ds->priv;
878
	int err;
879

880
	mutex_lock(&chip->reg_lock);
881
	err = mv88e6xxx_port_set_state(chip, port, state);
882
	mutex_unlock(&chip->reg_lock);
883 884

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

888 889 890 891 892 893 894 895
static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->pot_clear)
		return chip->info->ops->pot_clear(chip);

	return 0;
}

896 897 898 899 900 901 902 903
static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->mgmt_rsvd2cpu)
		return chip->info->ops->mgmt_rsvd2cpu(chip);

	return 0;
}

904 905
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
906 907
	int err;

908 909 910 911
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

912 913 914 915
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

916 917 918
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938
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;
}

939 940 941 942 943 944 945 946 947 948 949 950 951
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;
}

952 953 954 955 956 957 958 959 960
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)
961
		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
962 963 964 965

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

966 967
static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
{
968 969 970
	int dev, port;
	int err;

971 972 973 974 975 976
	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.
	 */
977 978 979 980 981 982 983 984 985 986 987 988 989
	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;
990 991
}

992 993 994 995 996 997
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);
998
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
999 1000 1001
	mutex_unlock(&chip->reg_lock);

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

1005 1006 1007 1008 1009 1010 1011 1012
static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
{
	if (!chip->info->max_vid)
		return 0;

	return mv88e6xxx_g1_vtu_flush(chip);
}

1013 1014 1015 1016 1017 1018 1019 1020 1021
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);
}

1022 1023 1024 1025 1026 1027 1028 1029 1030
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);
}

1031
static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1032 1033
{
	DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1034 1035 1036
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = chip->info->max_vid,
	};
1037
	int i, err;
1038 1039 1040

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

1041
	/* Set every FID bit used by the (un)bridged ports */
1042
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1043
		err = mv88e6xxx_port_get_fid(chip, i, fid);
1044 1045 1046 1047 1048 1049
		if (err)
			return err;

		set_bit(*fid, fid_bitmap);
	}

1050 1051
	/* Set every FID bit used by the VLAN entries */
	do {
1052
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1053 1054 1055 1056 1057 1058 1059
		if (err)
			return err;

		if (!vlan.valid)
			break;

		set_bit(vlan.fid, fid_bitmap);
1060
	} while (vlan.vid < chip->info->max_vid);
1061 1062 1063 1064 1065

	/* 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);
1066
	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1067 1068 1069
		return -ENOSPC;

	/* Clear the database */
1070
	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1071 1072
}

1073 1074
static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
			     struct mv88e6xxx_vtu_entry *entry, bool new)
1075 1076 1077 1078 1079 1080
{
	int err;

	if (!vid)
		return -EINVAL;

1081 1082
	entry->vid = vid - 1;
	entry->valid = false;
1083

1084
	err = mv88e6xxx_vtu_getnext(chip, entry);
1085 1086 1087
	if (err)
		return err;

1088 1089
	if (entry->vid == vid && entry->valid)
		return 0;
1090

1091 1092 1093 1094 1095 1096 1097 1098
	if (new) {
		int i;

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

1099
		/* Exclude all ports */
1100
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1101
			entry->member[i] =
1102
				MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1103 1104

		return mv88e6xxx_atu_new(chip, &entry->fid);
1105 1106
	}

1107 1108
	/* switchdev expects -EOPNOTSUPP to honor software VLANs */
	return -EOPNOTSUPP;
1109 1110
}

1111 1112 1113
static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
					u16 vid_begin, u16 vid_end)
{
V
Vivien Didelot 已提交
1114
	struct mv88e6xxx_chip *chip = ds->priv;
1115 1116 1117
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = vid_begin - 1,
	};
1118 1119
	int i, err;

1120 1121 1122 1123
	/* 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;

1124 1125 1126
	if (!vid_begin)
		return -EOPNOTSUPP;

1127
	mutex_lock(&chip->reg_lock);
1128 1129

	do {
1130
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1131 1132 1133 1134 1135 1136 1137 1138 1139
		if (err)
			goto unlock;

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

1140
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1141 1142 1143
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

1144
			if (!ds->ports[i].slave)
1145 1146
				continue;

1147
			if (vlan.member[i] ==
1148
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1149 1150
				continue;

V
Vivien Didelot 已提交
1151
			if (dsa_to_port(ds, i)->bridge_dev ==
1152
			    ds->ports[port].bridge_dev)
1153 1154
				break; /* same bridge, check next VLAN */

V
Vivien Didelot 已提交
1155
			if (!dsa_to_port(ds, i)->bridge_dev)
1156 1157
				continue;

1158 1159
			dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
				port, vlan.vid, i,
V
Vivien Didelot 已提交
1160
				netdev_name(dsa_to_port(ds, i)->bridge_dev));
1161 1162 1163 1164 1165 1166
			err = -EOPNOTSUPP;
			goto unlock;
		}
	} while (vlan.vid < vid_end);

unlock:
1167
	mutex_unlock(&chip->reg_lock);
1168 1169 1170 1171

	return err;
}

1172 1173
static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
					 bool vlan_filtering)
1174
{
V
Vivien Didelot 已提交
1175
	struct mv88e6xxx_chip *chip = ds->priv;
1176 1177
	u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
		MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
1178
	int err;
1179

1180
	if (!chip->info->max_vid)
1181 1182
		return -EOPNOTSUPP;

1183
	mutex_lock(&chip->reg_lock);
1184
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1185
	mutex_unlock(&chip->reg_lock);
1186

1187
	return err;
1188 1189
}

1190 1191
static int
mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1192
			    const struct switchdev_obj_port_vlan *vlan)
1193
{
V
Vivien Didelot 已提交
1194
	struct mv88e6xxx_chip *chip = ds->priv;
1195 1196
	int err;

1197
	if (!chip->info->max_vid)
1198 1199
		return -EOPNOTSUPP;

1200 1201 1202 1203 1204 1205 1206 1207
	/* 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;

1208 1209 1210 1211 1212 1213
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */
	return 0;
}

1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257
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);
}

1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280
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;
}

1281
static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
1282
				    u16 vid, u8 member)
1283
{
1284
	struct mv88e6xxx_vtu_entry vlan;
1285 1286
	int err;

1287
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
1288
	if (err)
1289
		return err;
1290

1291
	vlan.member[port] = member;
1292

1293 1294 1295 1296 1297
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
	if (err)
		return err;

	return mv88e6xxx_broadcast_setup(chip, vid);
1298 1299
}

1300
static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1301
				    const struct switchdev_obj_port_vlan *vlan)
1302
{
V
Vivien Didelot 已提交
1303
	struct mv88e6xxx_chip *chip = ds->priv;
1304 1305
	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1306
	u8 member;
1307 1308
	u16 vid;

1309
	if (!chip->info->max_vid)
1310 1311
		return;

1312
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1313
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1314
	else if (untagged)
1315
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
1316
	else
1317
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
1318

1319
	mutex_lock(&chip->reg_lock);
1320

1321
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
1322
		if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
1323 1324
			dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
				vid, untagged ? 'u' : 't');
1325

1326
	if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1327 1328
		dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
			vlan->vid_end);
1329

1330
	mutex_unlock(&chip->reg_lock);
1331 1332
}

1333
static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
1334
				    int port, u16 vid)
1335
{
1336
	struct mv88e6xxx_vtu_entry vlan;
1337 1338
	int i, err;

1339
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1340
	if (err)
1341
		return err;
1342

1343
	/* Tell switchdev if this VLAN is handled in software */
1344
	if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1345
		return -EOPNOTSUPP;
1346

1347
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1348 1349

	/* keep the VLAN unless all ports are excluded */
1350
	vlan.valid = false;
1351
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1352 1353
		if (vlan.member[i] !=
		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
1354
			vlan.valid = true;
1355 1356 1357 1358
			break;
		}
	}

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

1363
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
1364 1365
}

1366 1367
static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
				   const struct switchdev_obj_port_vlan *vlan)
1368
{
V
Vivien Didelot 已提交
1369
	struct mv88e6xxx_chip *chip = ds->priv;
1370 1371 1372
	u16 pvid, vid;
	int err = 0;

1373
	if (!chip->info->max_vid)
1374 1375
		return -EOPNOTSUPP;

1376
	mutex_lock(&chip->reg_lock);
1377

1378
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
1379 1380 1381
	if (err)
		goto unlock;

1382
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1383
		err = _mv88e6xxx_port_vlan_del(chip, port, vid);
1384 1385 1386 1387
		if (err)
			goto unlock;

		if (vid == pvid) {
1388
			err = mv88e6xxx_port_set_pvid(chip, port, 0);
1389 1390 1391 1392 1393
			if (err)
				goto unlock;
		}
	}

1394
unlock:
1395
	mutex_unlock(&chip->reg_lock);
1396 1397 1398 1399

	return err;
}

1400 1401
static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
				  const unsigned char *addr, u16 vid)
1402
{
V
Vivien Didelot 已提交
1403
	struct mv88e6xxx_chip *chip = ds->priv;
1404
	int err;
1405

1406
	mutex_lock(&chip->reg_lock);
1407 1408
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1409
	mutex_unlock(&chip->reg_lock);
1410 1411

	return err;
1412 1413
}

1414
static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1415
				  const unsigned char *addr, u16 vid)
1416
{
V
Vivien Didelot 已提交
1417
	struct mv88e6xxx_chip *chip = ds->priv;
1418
	int err;
1419

1420
	mutex_lock(&chip->reg_lock);
1421
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1422
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
1423
	mutex_unlock(&chip->reg_lock);
1424

1425
	return err;
1426 1427
}

1428 1429
static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
				      u16 fid, u16 vid, int port,
1430
				      dsa_fdb_dump_cb_t *cb, void *data)
1431
{
1432
	struct mv88e6xxx_atu_entry addr;
1433
	bool is_static;
1434 1435
	int err;

1436
	addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1437
	eth_broadcast_addr(addr.mac);
1438 1439

	do {
1440
		mutex_lock(&chip->reg_lock);
1441
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
1442
		mutex_unlock(&chip->reg_lock);
1443
		if (err)
1444
			return err;
1445

1446
		if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
1447 1448
			break;

1449
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
1450 1451
			continue;

1452 1453
		if (!is_unicast_ether_addr(addr.mac))
			continue;
1454

1455 1456 1457
		is_static = (addr.state ==
			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
		err = cb(addr.mac, vid, is_static, data);
1458 1459
		if (err)
			return err;
1460 1461 1462 1463 1464
	} while (!is_broadcast_ether_addr(addr.mac));

	return err;
}

1465
static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1466
				  dsa_fdb_dump_cb_t *cb, void *data)
1467
{
1468
	struct mv88e6xxx_vtu_entry vlan = {
1469
		.vid = chip->info->max_vid,
1470
	};
1471
	u16 fid;
1472 1473
	int err;

1474
	/* Dump port's default Filtering Information Database (VLAN ID 0) */
1475
	mutex_lock(&chip->reg_lock);
1476
	err = mv88e6xxx_port_get_fid(chip, port, &fid);
1477 1478
	mutex_unlock(&chip->reg_lock);

1479
	if (err)
1480
		return err;
1481

1482
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
1483
	if (err)
1484
		return err;
1485

1486
	/* Dump VLANs' Filtering Information Databases */
1487
	do {
1488
		mutex_lock(&chip->reg_lock);
1489
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1490
		mutex_unlock(&chip->reg_lock);
1491
		if (err)
1492
			return err;
1493 1494 1495 1496

		if (!vlan.valid)
			break;

1497
		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1498
						 cb, data);
1499
		if (err)
1500
			return err;
1501
	} while (vlan.vid < chip->info->max_vid);
1502

1503 1504 1505 1506
	return err;
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1507
				   dsa_fdb_dump_cb_t *cb, void *data)
1508
{
V
Vivien Didelot 已提交
1509
	struct mv88e6xxx_chip *chip = ds->priv;
1510

1511
	return mv88e6xxx_port_db_dump(chip, port, cb, data);
1512 1513
}

1514 1515
static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
				struct net_device *br)
1516
{
1517
	struct dsa_switch *ds;
1518
	int port;
1519
	int dev;
1520
	int err;
1521

1522 1523 1524 1525
	/* 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);
1526
			if (err)
1527
				return err;
1528 1529 1530
		}
	}

1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548
	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;
			}
		}
	}

1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559
	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);
1560
	mutex_unlock(&chip->reg_lock);
1561

1562
	return err;
1563 1564
}

1565 1566
static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
					struct net_device *br)
1567
{
V
Vivien Didelot 已提交
1568
	struct mv88e6xxx_chip *chip = ds->priv;
1569

1570
	mutex_lock(&chip->reg_lock);
1571 1572 1573
	if (mv88e6xxx_bridge_map(chip, br) ||
	    mv88e6xxx_port_vlan_map(chip, port))
		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
1574
	mutex_unlock(&chip->reg_lock);
1575 1576
}

1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606
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);
}

1607 1608 1609 1610 1611 1612 1613 1614
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->reset)
		return chip->info->ops->reset(chip);

	return 0;
}

1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627
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);
	}
}

1628
static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1629
{
1630
	int i, err;
1631

1632
	/* Set all ports to the Disabled state */
1633
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
1634
		err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
1635 1636
		if (err)
			return err;
1637 1638
	}

1639 1640 1641
	/* Wait for transmit queues to drain,
	 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
	 */
1642 1643
	usleep_range(2000, 4000);

1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654
	return 0;
}

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

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

1655
	mv88e6xxx_hardware_reset(chip);
1656

1657
	return mv88e6xxx_software_reset(chip);
1658 1659
}

1660
static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
1661 1662
				   enum mv88e6xxx_frame_mode frame,
				   enum mv88e6xxx_egress_mode egress, u16 etype)
1663 1664 1665
{
	int err;

1666 1667 1668 1669
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
1670 1671 1672
	if (err)
		return err;

1673 1674 1675 1676 1677 1678 1679 1680
	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;
1681 1682
}

1683
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1684
{
1685
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
1686
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
1687
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
1688
}
1689

1690 1691 1692
static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
1693
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
1694
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
1695
}
1696

1697 1698 1699 1700
static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port,
				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
1701 1702
				       MV88E6XXX_EGRESS_MODE_ETHERTYPE,
				       ETH_P_EDSA);
1703
}
1704

1705 1706 1707 1708
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);
1709

1710
	if (dsa_is_user_port(chip->ds, port))
1711
		return mv88e6xxx_set_port_mode_normal(chip, port);
1712

1713 1714 1715
	/* 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);
1716

1717 1718
	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
		return mv88e6xxx_set_port_mode_edsa(chip, port);
1719

1720
	return -EINVAL;
1721 1722
}

1723
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
1724
{
1725
	bool message = dsa_is_dsa_port(chip->ds, port);
1726

1727
	return mv88e6xxx_port_set_message_port(chip, port, message);
1728
}
1729

1730
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
1731
{
1732 1733
	struct dsa_switch *ds = chip->ds;
	bool flood;
1734

1735
	/* Upstream ports flood frames with unknown unicast or multicast DA */
1736
	flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
1737 1738 1739
	if (chip->info->ops->port_set_egress_floods)
		return chip->info->ops->port_set_egress_floods(chip, port,
							       flood, flood);
1740

1741
	return 0;
1742 1743
}

1744 1745 1746
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
1747 1748
	if (chip->info->ops->serdes_power)
		return chip->info->ops->serdes_power(chip, port, on);
1749

1750
	return 0;
1751 1752
}

1753 1754 1755 1756 1757 1758
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

1759
	upstream_port = dsa_upstream_port(ds, port);
1760 1761 1762 1763 1764 1765 1766
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782
	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;
		}
	}

1783 1784 1785
	return 0;
}

1786
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
1787
{
1788
	struct dsa_switch *ds = chip->ds;
1789
	int err;
1790
	u16 reg;
1791

1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805
	/* 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;
1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820

	/* 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.
	 */
1821 1822 1823 1824
	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);
1825 1826
	if (err)
		return err;
1827

1828
	err = mv88e6xxx_setup_port_mode(chip, port);
1829 1830
	if (err)
		return err;
1831

1832
	err = mv88e6xxx_setup_egress_floods(chip, port);
1833 1834 1835
	if (err)
		return err;

1836 1837 1838
	/* 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.
1839
	 */
1840 1841 1842 1843 1844
	if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
		err = mv88e6xxx_serdes_power(chip, port, true);
		if (err)
			return err;
	}
1845

1846
	/* Port Control 2: don't force a good FCS, set the maximum frame size to
1847
	 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
1848 1849 1850
	 * 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.
1851
	 */
1852 1853 1854
	err = mv88e6xxx_port_set_map_da(chip, port);
	if (err)
		return err;
1855

1856 1857 1858
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
1859

1860
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
1861
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
1862 1863 1864
	if (err)
		return err;

1865 1866
	if (chip->info->ops->port_set_jumbo_size) {
		err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
1867 1868 1869 1870
		if (err)
			return err;
	}

1871 1872 1873 1874 1875
	/* 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.
	 */
1876
	reg = 1 << port;
1877 1878
	/* Disable learning for CPU port */
	if (dsa_is_cpu_port(ds, port))
1879
		reg = 0;
1880

1881 1882
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
1883 1884
	if (err)
		return err;
1885 1886

	/* Egress rate control 2: disable egress rate control. */
1887 1888
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
				   0x0000);
1889 1890
	if (err)
		return err;
1891

1892 1893
	if (chip->info->ops->port_pause_limit) {
		err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
1894 1895
		if (err)
			return err;
1896
	}
1897

1898 1899 1900 1901 1902 1903
	if (chip->info->ops->port_disable_learn_limit) {
		err = chip->info->ops->port_disable_learn_limit(chip, port);
		if (err)
			return err;
	}

1904 1905
	if (chip->info->ops->port_disable_pri_override) {
		err = chip->info->ops->port_disable_pri_override(chip, port);
1906 1907
		if (err)
			return err;
1908
	}
1909

1910 1911
	if (chip->info->ops->port_tag_remap) {
		err = chip->info->ops->port_tag_remap(chip, port);
1912 1913
		if (err)
			return err;
1914 1915
	}

1916 1917
	if (chip->info->ops->port_egress_rate_limiting) {
		err = chip->info->ops->port_egress_rate_limiting(chip, port);
1918 1919
		if (err)
			return err;
1920 1921
	}

1922
	err = mv88e6xxx_setup_message_port(chip, port);
1923 1924
	if (err)
		return err;
1925

1926
	/* Port based VLAN map: give each port the same default address
1927 1928
	 * database, and allow bidirectional communication between the
	 * CPU and DSA port(s), and the other ports.
1929
	 */
1930
	err = mv88e6xxx_port_set_fid(chip, port, 0);
1931 1932
	if (err)
		return err;
1933

1934
	err = mv88e6xxx_port_vlan_map(chip, port);
1935 1936
	if (err)
		return err;
1937 1938 1939 1940

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

1944 1945 1946 1947
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
1948
	int err;
1949 1950

	mutex_lock(&chip->reg_lock);
1951
	err = mv88e6xxx_serdes_power(chip, port, true);
1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962
	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);
1963 1964
	if (mv88e6xxx_serdes_power(chip, port, false))
		dev_err(chip->dev, "failed to power off SERDES\n");
1965 1966 1967
	mutex_unlock(&chip->reg_lock);
}

1968 1969 1970
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
1971
	struct mv88e6xxx_chip *chip = ds->priv;
1972 1973 1974
	int err;

	mutex_lock(&chip->reg_lock);
1975
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
1976 1977 1978 1979 1980
	mutex_unlock(&chip->reg_lock);

	return err;
}

1981
static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
1982
{
1983
	struct dsa_switch *ds = chip->ds;
1984
	int err;
1985

1986
	/* Disable remote management, and set the switch's DSA device number. */
1987 1988
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL2,
				 MV88E6XXX_G1_CTL2_MULTIPLE_CASCADE |
1989
				 (ds->index & 0x1f));
1990 1991 1992
	if (err)
		return err;

1993
	/* Configure the IP ToS mapping registers. */
1994
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_0, 0x0000);
1995
	if (err)
1996
		return err;
1997
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_1, 0x0000);
1998
	if (err)
1999
		return err;
2000
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_2, 0x5555);
2001
	if (err)
2002
		return err;
2003
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_3, 0x5555);
2004
	if (err)
2005
		return err;
2006
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_4, 0xaaaa);
2007
	if (err)
2008
		return err;
2009
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_5, 0xaaaa);
2010
	if (err)
2011
		return err;
2012
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_6, 0xffff);
2013
	if (err)
2014
		return err;
2015
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_7, 0xffff);
2016
	if (err)
2017
		return err;
2018 2019

	/* Configure the IEEE 802.1p priority mapping register. */
2020
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IEEE_PRI, 0xfa41);
2021
	if (err)
2022
		return err;
2023

2024 2025 2026 2027 2028
	/* Initialize the statistics unit */
	err = mv88e6xxx_stats_set_histogram(chip);
	if (err)
		return err;

2029
	return mv88e6xxx_g1_stats_clear(chip);
2030 2031
}

2032
static int mv88e6xxx_setup(struct dsa_switch *ds)
2033
{
V
Vivien Didelot 已提交
2034
	struct mv88e6xxx_chip *chip = ds->priv;
2035
	int err;
2036 2037
	int i;

2038
	chip->ds = ds;
2039
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
2040

2041
	mutex_lock(&chip->reg_lock);
2042

2043
	/* Setup Switch Port Registers */
2044
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2045 2046 2047
		if (dsa_is_unused_port(ds, i))
			continue;

2048 2049 2050 2051 2052 2053 2054
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

	/* Setup Switch Global 1 Registers */
	err = mv88e6xxx_g1_setup(chip);
2055 2056 2057
	if (err)
		goto unlock;

2058
	/* Setup Switch Global 2 Registers */
2059
	if (chip->info->global2_addr) {
2060
		err = mv88e6xxx_g2_setup(chip);
2061 2062 2063
		if (err)
			goto unlock;
	}
2064

2065 2066 2067 2068
	err = mv88e6xxx_irl_setup(chip);
	if (err)
		goto unlock;

2069 2070 2071 2072
	err = mv88e6xxx_mac_setup(chip);
	if (err)
		goto unlock;

2073 2074 2075 2076
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

2077 2078 2079 2080
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

2081 2082 2083 2084
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

2085 2086 2087 2088
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

2089 2090 2091 2092
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

2093 2094 2095 2096
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

2097 2098 2099
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
2100

2101
	/* Setup PTP Hardware Clock and timestamping */
2102 2103 2104 2105
	if (chip->info->ptp_support) {
		err = mv88e6xxx_ptp_setup(chip);
		if (err)
			goto unlock;
2106 2107 2108 2109

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
2110 2111
	}

2112
unlock:
2113
	mutex_unlock(&chip->reg_lock);
2114

2115
	return err;
2116 2117
}

2118
static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
2119
{
2120 2121
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2122 2123
	u16 val;
	int err;
2124

2125 2126 2127
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

2128
	mutex_lock(&chip->reg_lock);
2129
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
2130
	mutex_unlock(&chip->reg_lock);
2131

2132 2133 2134 2135 2136
	if (reg == MII_PHYSID2) {
		/* Some internal PHYS don't have a model number.  Use
		 * the mv88e6390 family model number instead.
		 */
		if (!(val & 0x3f0))
2137
			val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
2138 2139
	}

2140
	return err ? err : val;
2141 2142
}

2143
static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
2144
{
2145 2146
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2147
	int err;
2148

2149 2150 2151
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

2152
	mutex_lock(&chip->reg_lock);
2153
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
2154
	mutex_unlock(&chip->reg_lock);
2155 2156

	return err;
2157 2158
}

2159
static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
2160 2161
				   struct device_node *np,
				   bool external)
2162 2163
{
	static int index;
2164
	struct mv88e6xxx_mdio_bus *mdio_bus;
2165 2166 2167
	struct mii_bus *bus;
	int err;

2168
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
2169 2170 2171
	if (!bus)
		return -ENOMEM;

2172
	mdio_bus = bus->priv;
2173
	mdio_bus->bus = bus;
2174
	mdio_bus->chip = chip;
2175 2176
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
2177

2178 2179
	if (np) {
		bus->name = np->full_name;
2180
		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
2181 2182 2183 2184 2185 2186 2187
	} 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;
2188
	bus->parent = chip->dev;
2189

2190 2191
	if (np)
		err = of_mdiobus_register(bus, np);
2192 2193 2194
	else
		err = mdiobus_register(bus);
	if (err) {
2195
		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
2196
		return err;
2197
	}
2198 2199 2200 2201 2202

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

	return 0;
2205
}
2206

2207 2208 2209 2210 2211
static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
	{ .compatible = "marvell,mv88e6xxx-mdio-external",
	  .data = (void *)true },
	{ },
};
2212

2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225
static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)

{
	struct mv88e6xxx_mdio_bus *mdio_bus;
	struct mii_bus *bus;

	list_for_each_entry(mdio_bus, &chip->mdios, list) {
		bus = mdio_bus->bus;

		mdiobus_unregister(bus);
	}
}

2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249
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);
2250 2251
			if (err) {
				mv88e6xxx_mdios_unregister(chip);
2252
				return err;
2253
			}
2254 2255 2256 2257
		}
	}

	return 0;
2258 2259
}

2260 2261
static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
2262
	struct mv88e6xxx_chip *chip = ds->priv;
2263 2264 2265 2266 2267 2268 2269

	return chip->eeprom_len;
}

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

2273 2274
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
2275

2276 2277
	mutex_lock(&chip->reg_lock);
	err = chip->info->ops->get_eeprom(chip, eeprom, data);
2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290
	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 已提交
2291
	struct mv88e6xxx_chip *chip = ds->priv;
2292 2293
	int err;

2294 2295 2296
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

2297 2298 2299 2300
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

	mutex_lock(&chip->reg_lock);
2301
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
2302 2303 2304 2305 2306
	mutex_unlock(&chip->reg_lock);

	return err;
}

2307
static const struct mv88e6xxx_ops mv88e6085_ops = {
2308
	/* MV88E6XXX_FAMILY_6097 */
2309
	.irl_init_all = mv88e6352_g2_irl_init_all,
2310
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2311 2312
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2313
	.port_set_link = mv88e6xxx_port_set_link,
2314
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2315
	.port_set_speed = mv88e6185_port_set_speed,
2316
	.port_tag_remap = mv88e6095_port_tag_remap,
2317
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2318
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2319
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2320
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2321
	.port_pause_limit = mv88e6097_port_pause_limit,
2322
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2323
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2324
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2325
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2326 2327
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2328
	.stats_get_stats = mv88e6095_stats_get_stats,
2329 2330
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2331
	.watchdog_ops = &mv88e6097_watchdog_ops,
2332
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2333
	.pot_clear = mv88e6xxx_g2_pot_clear,
2334 2335
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2336
	.reset = mv88e6185_g1_reset,
2337
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2338
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2339 2340 2341
};

static const struct mv88e6xxx_ops mv88e6095_ops = {
2342
	/* MV88E6XXX_FAMILY_6095 */
2343
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2344 2345
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2346
	.port_set_link = mv88e6xxx_port_set_link,
2347
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2348
	.port_set_speed = mv88e6185_port_set_speed,
2349
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2350
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2351
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2352
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2353
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2354 2355
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2356
	.stats_get_stats = mv88e6095_stats_get_stats,
2357
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2358 2359
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2360
	.reset = mv88e6185_g1_reset,
2361
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2362
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2363 2364
};

2365
static const struct mv88e6xxx_ops mv88e6097_ops = {
2366
	/* MV88E6XXX_FAMILY_6097 */
2367
	.irl_init_all = mv88e6352_g2_irl_init_all,
2368 2369 2370 2371 2372 2373
	.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,
2374
	.port_tag_remap = mv88e6095_port_tag_remap,
2375
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2376
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2377
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2378
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2379
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
2380
	.port_pause_limit = mv88e6097_port_pause_limit,
2381
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2382
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2383
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2384
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2385 2386 2387
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
	.stats_get_stats = mv88e6095_stats_get_stats,
2388 2389
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2390
	.watchdog_ops = &mv88e6097_watchdog_ops,
2391
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2392
	.pot_clear = mv88e6xxx_g2_pot_clear,
2393
	.reset = mv88e6352_g1_reset,
2394
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2395
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2396 2397
};

2398
static const struct mv88e6xxx_ops mv88e6123_ops = {
2399
	/* MV88E6XXX_FAMILY_6165 */
2400
	.irl_init_all = mv88e6352_g2_irl_init_all,
2401
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2402 2403
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2404
	.port_set_link = mv88e6xxx_port_set_link,
2405
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2406
	.port_set_speed = mv88e6185_port_set_speed,
2407
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2408
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2409
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2410
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2411
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2412
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2413 2414
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2415
	.stats_get_stats = mv88e6095_stats_get_stats,
2416 2417
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2418
	.watchdog_ops = &mv88e6097_watchdog_ops,
2419
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2420
	.pot_clear = mv88e6xxx_g2_pot_clear,
2421
	.reset = mv88e6352_g1_reset,
2422
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2423
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2424 2425 2426
};

static const struct mv88e6xxx_ops mv88e6131_ops = {
2427
	/* MV88E6XXX_FAMILY_6185 */
2428
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2429 2430
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2431
	.port_set_link = mv88e6xxx_port_set_link,
2432
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2433
	.port_set_speed = mv88e6185_port_set_speed,
2434
	.port_tag_remap = mv88e6095_port_tag_remap,
2435
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2436
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2437
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2438
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2439
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2440
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2441
	.port_pause_limit = mv88e6097_port_pause_limit,
2442
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2443
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2444 2445
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2446
	.stats_get_stats = mv88e6095_stats_get_stats,
2447 2448
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2449
	.watchdog_ops = &mv88e6097_watchdog_ops,
2450
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2451 2452
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2453
	.reset = mv88e6185_g1_reset,
2454
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2455
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2456 2457
};

2458 2459
static const struct mv88e6xxx_ops mv88e6141_ops = {
	/* MV88E6XXX_FAMILY_6341 */
2460
	.irl_init_all = mv88e6352_g2_irl_init_all,
2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473
	.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,
2474
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2475
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2476
	.port_pause_limit = mv88e6097_port_pause_limit,
2477 2478 2479
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
2480
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2481 2482 2483
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
2484 2485
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
2486 2487
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
2488
	.pot_clear = mv88e6xxx_g2_pot_clear,
2489
	.reset = mv88e6352_g1_reset,
2490
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2491
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2492
	.gpio_ops = &mv88e6352_gpio_ops,
2493 2494
};

2495
static const struct mv88e6xxx_ops mv88e6161_ops = {
2496
	/* MV88E6XXX_FAMILY_6165 */
2497
	.irl_init_all = mv88e6352_g2_irl_init_all,
2498
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2499 2500
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2501
	.port_set_link = mv88e6xxx_port_set_link,
2502
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2503
	.port_set_speed = mv88e6185_port_set_speed,
2504
	.port_tag_remap = mv88e6095_port_tag_remap,
2505
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2506
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2507
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2508
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2509
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2510
	.port_pause_limit = mv88e6097_port_pause_limit,
2511
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2512
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2513
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2514
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2515 2516
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2517
	.stats_get_stats = mv88e6095_stats_get_stats,
2518 2519
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2520
	.watchdog_ops = &mv88e6097_watchdog_ops,
2521
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2522
	.pot_clear = mv88e6xxx_g2_pot_clear,
2523
	.reset = mv88e6352_g1_reset,
2524
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2525
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2526 2527 2528
};

static const struct mv88e6xxx_ops mv88e6165_ops = {
2529
	/* MV88E6XXX_FAMILY_6165 */
2530
	.irl_init_all = mv88e6352_g2_irl_init_all,
2531
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2532 2533
	.phy_read = mv88e6165_phy_read,
	.phy_write = mv88e6165_phy_write,
2534
	.port_set_link = mv88e6xxx_port_set_link,
2535
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2536
	.port_set_speed = mv88e6185_port_set_speed,
2537
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2538
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2539
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2540
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2541 2542
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2543
	.stats_get_stats = mv88e6095_stats_get_stats,
2544 2545
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2546
	.watchdog_ops = &mv88e6097_watchdog_ops,
2547
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2548
	.pot_clear = mv88e6xxx_g2_pot_clear,
2549
	.reset = mv88e6352_g1_reset,
2550
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2551
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2552 2553 2554
};

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

static const struct mv88e6xxx_ops mv88e6172_ops = {
2589
	/* MV88E6XXX_FAMILY_6352 */
2590
	.irl_init_all = mv88e6352_g2_irl_init_all,
2591 2592
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
2593
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2594 2595
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2596
	.port_set_link = mv88e6xxx_port_set_link,
2597
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2598
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
2599
	.port_set_speed = mv88e6352_port_set_speed,
2600
	.port_tag_remap = mv88e6095_port_tag_remap,
2601
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2602
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2603
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2604
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2605
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2606
	.port_pause_limit = mv88e6097_port_pause_limit,
2607
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2608
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2609
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2610
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2611 2612
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2613
	.stats_get_stats = mv88e6095_stats_get_stats,
2614 2615
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2616
	.watchdog_ops = &mv88e6097_watchdog_ops,
2617
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2618
	.pot_clear = mv88e6xxx_g2_pot_clear,
2619
	.reset = mv88e6352_g1_reset,
2620
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2621
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2622
	.serdes_power = mv88e6352_serdes_power,
2623
	.gpio_ops = &mv88e6352_gpio_ops,
2624 2625 2626
};

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

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

static const struct mv88e6xxx_ops mv88e6185_ops = {
2699
	/* MV88E6XXX_FAMILY_6185 */
2700
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2701 2702
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2703
	.port_set_link = mv88e6xxx_port_set_link,
2704
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2705
	.port_set_speed = mv88e6185_port_set_speed,
2706
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2707
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2708
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
2709
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2710
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2711
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2712 2713
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2714
	.stats_get_stats = mv88e6095_stats_get_stats,
2715 2716
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2717
	.watchdog_ops = &mv88e6097_watchdog_ops,
2718
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2719 2720
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2721
	.reset = mv88e6185_g1_reset,
2722
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2723
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2724 2725
};

2726
static const struct mv88e6xxx_ops mv88e6190_ops = {
2727
	/* MV88E6XXX_FAMILY_6390 */
2728
	.irl_init_all = mv88e6390_g2_irl_init_all,
2729 2730
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
2731 2732 2733 2734 2735 2736 2737
	.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,
2738
	.port_tag_remap = mv88e6390_port_tag_remap,
2739
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2740
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2741
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2742
	.port_pause_limit = mv88e6390_port_pause_limit,
2743
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2744
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2745
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
2746
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
2747 2748
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
2749
	.stats_get_stats = mv88e6390_stats_get_stats,
2750 2751
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
2752
	.watchdog_ops = &mv88e6390_watchdog_ops,
2753
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
2754
	.pot_clear = mv88e6xxx_g2_pot_clear,
2755
	.reset = mv88e6352_g1_reset,
2756 2757
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
2758
	.serdes_power = mv88e6390_serdes_power,
2759
	.gpio_ops = &mv88e6352_gpio_ops,
2760 2761 2762
};

static const struct mv88e6xxx_ops mv88e6190x_ops = {
2763
	/* MV88E6XXX_FAMILY_6390 */
2764
	.irl_init_all = mv88e6390_g2_irl_init_all,
2765 2766
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
2767 2768 2769 2770 2771 2772 2773
	.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,
2774
	.port_tag_remap = mv88e6390_port_tag_remap,
2775
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2776
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2777
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2778
	.port_pause_limit = mv88e6390_port_pause_limit,
2779
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2780
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2781
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
2782
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
2783 2784
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
2785
	.stats_get_stats = mv88e6390_stats_get_stats,
2786 2787
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
2788
	.watchdog_ops = &mv88e6390_watchdog_ops,
2789
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
2790
	.pot_clear = mv88e6xxx_g2_pot_clear,
2791
	.reset = mv88e6352_g1_reset,
2792 2793
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
2794
	.serdes_power = mv88e6390_serdes_power,
2795
	.gpio_ops = &mv88e6352_gpio_ops,
2796 2797 2798
};

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

2833
static const struct mv88e6xxx_ops mv88e6240_ops = {
2834
	/* MV88E6XXX_FAMILY_6352 */
2835
	.irl_init_all = mv88e6352_g2_irl_init_all,
2836 2837
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
2838
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2839 2840
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2841
	.port_set_link = mv88e6xxx_port_set_link,
2842
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2843
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
2844
	.port_set_speed = mv88e6352_port_set_speed,
2845
	.port_tag_remap = mv88e6095_port_tag_remap,
2846
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2847
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2848
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2849
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2850
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2851
	.port_pause_limit = mv88e6097_port_pause_limit,
2852
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2853
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2854
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2855
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2856 2857
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2858
	.stats_get_stats = mv88e6095_stats_get_stats,
2859 2860
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2861
	.watchdog_ops = &mv88e6097_watchdog_ops,
2862
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2863
	.pot_clear = mv88e6xxx_g2_pot_clear,
2864
	.reset = mv88e6352_g1_reset,
2865
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2866
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2867
	.serdes_power = mv88e6352_serdes_power,
2868
	.gpio_ops = &mv88e6352_gpio_ops,
2869
	.avb_ops = &mv88e6352_avb_ops,
2870 2871
};

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

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

static const struct mv88e6xxx_ops mv88e6321_ops = {
2947
	/* MV88E6XXX_FAMILY_6320 */
2948
	.irl_init_all = mv88e6352_g2_irl_init_all,
2949 2950
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
2951
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2952 2953
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2954
	.port_set_link = mv88e6xxx_port_set_link,
2955
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2956
	.port_set_speed = mv88e6185_port_set_speed,
2957
	.port_tag_remap = mv88e6095_port_tag_remap,
2958
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2959
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2960
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2961
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2962
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2963
	.port_pause_limit = mv88e6097_port_pause_limit,
2964
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2965
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2966
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2967
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2968 2969
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
2970
	.stats_get_stats = mv88e6320_stats_get_stats,
2971 2972
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2973
	.reset = mv88e6352_g1_reset,
2974
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2975
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2976
	.gpio_ops = &mv88e6352_gpio_ops,
2977
	.avb_ops = &mv88e6352_avb_ops,
2978 2979
};

2980 2981
static const struct mv88e6xxx_ops mv88e6341_ops = {
	/* MV88E6XXX_FAMILY_6341 */
2982
	.irl_init_all = mv88e6352_g2_irl_init_all,
2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995
	.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,
2996
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2997
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2998
	.port_pause_limit = mv88e6097_port_pause_limit,
2999 3000 3001
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3002
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3003 3004 3005
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
3006 3007
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3008 3009
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
3010
	.pot_clear = mv88e6xxx_g2_pot_clear,
3011
	.reset = mv88e6352_g1_reset,
3012
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3013
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3014
	.gpio_ops = &mv88e6352_gpio_ops,
3015
	.avb_ops = &mv88e6390_avb_ops,
3016 3017
};

3018
static const struct mv88e6xxx_ops mv88e6350_ops = {
3019
	/* MV88E6XXX_FAMILY_6351 */
3020
	.irl_init_all = mv88e6352_g2_irl_init_all,
3021
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3022 3023
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3024
	.port_set_link = mv88e6xxx_port_set_link,
3025
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3026
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3027
	.port_set_speed = mv88e6185_port_set_speed,
3028
	.port_tag_remap = mv88e6095_port_tag_remap,
3029
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3030
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3031
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3032
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3033
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3034
	.port_pause_limit = mv88e6097_port_pause_limit,
3035
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3036
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3037
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3038
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3039 3040
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3041
	.stats_get_stats = mv88e6095_stats_get_stats,
3042 3043
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3044
	.watchdog_ops = &mv88e6097_watchdog_ops,
3045
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3046
	.pot_clear = mv88e6xxx_g2_pot_clear,
3047
	.reset = mv88e6352_g1_reset,
3048
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3049
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3050 3051 3052
};

static const struct mv88e6xxx_ops mv88e6351_ops = {
3053
	/* MV88E6XXX_FAMILY_6351 */
3054
	.irl_init_all = mv88e6352_g2_irl_init_all,
3055
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3056 3057
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3058
	.port_set_link = mv88e6xxx_port_set_link,
3059
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3060
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3061
	.port_set_speed = mv88e6185_port_set_speed,
3062
	.port_tag_remap = mv88e6095_port_tag_remap,
3063
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3064
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3065
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3066
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3067
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3068
	.port_pause_limit = mv88e6097_port_pause_limit,
3069
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3070
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3071
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3072
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3073 3074
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3075
	.stats_get_stats = mv88e6095_stats_get_stats,
3076 3077
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3078
	.watchdog_ops = &mv88e6097_watchdog_ops,
3079
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3080
	.pot_clear = mv88e6xxx_g2_pot_clear,
3081
	.reset = mv88e6352_g1_reset,
3082
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3083
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3084
	.avb_ops = &mv88e6352_avb_ops,
3085 3086 3087
};

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

3126
static const struct mv88e6xxx_ops mv88e6390_ops = {
3127
	/* MV88E6XXX_FAMILY_6390 */
3128
	.irl_init_all = mv88e6390_g2_irl_init_all,
3129 3130
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3131 3132 3133 3134 3135 3136 3137
	.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,
3138
	.port_tag_remap = mv88e6390_port_tag_remap,
3139
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3140
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3141
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3142
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3143
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3144
	.port_pause_limit = mv88e6390_port_pause_limit,
3145
	.port_set_cmode = mv88e6390x_port_set_cmode,
3146
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3147
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3148
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3149
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3150 3151
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3152
	.stats_get_stats = mv88e6390_stats_get_stats,
3153 3154
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3155
	.watchdog_ops = &mv88e6390_watchdog_ops,
3156
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3157
	.pot_clear = mv88e6xxx_g2_pot_clear,
3158
	.reset = mv88e6352_g1_reset,
3159 3160
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3161
	.serdes_power = mv88e6390_serdes_power,
3162
	.gpio_ops = &mv88e6352_gpio_ops,
3163
	.avb_ops = &mv88e6390_avb_ops,
3164 3165 3166
};

static const struct mv88e6xxx_ops mv88e6390x_ops = {
3167
	/* MV88E6XXX_FAMILY_6390 */
3168
	.irl_init_all = mv88e6390_g2_irl_init_all,
3169 3170
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3171 3172 3173 3174 3175 3176 3177
	.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,
3178
	.port_tag_remap = mv88e6390_port_tag_remap,
3179
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3180
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3181
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3182
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3183
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3184
	.port_pause_limit = mv88e6390_port_pause_limit,
3185
	.port_set_cmode = mv88e6390x_port_set_cmode,
3186
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3187
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3188
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3189
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3190 3191
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3192
	.stats_get_stats = mv88e6390_stats_get_stats,
3193 3194
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3195
	.watchdog_ops = &mv88e6390_watchdog_ops,
3196
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3197
	.pot_clear = mv88e6xxx_g2_pot_clear,
3198
	.reset = mv88e6352_g1_reset,
3199 3200
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3201
	.serdes_power = mv88e6390_serdes_power,
3202
	.gpio_ops = &mv88e6352_gpio_ops,
3203
	.avb_ops = &mv88e6390_avb_ops,
3204 3205
};

3206 3207
static const struct mv88e6xxx_info mv88e6xxx_table[] = {
	[MV88E6085] = {
3208
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
3209 3210 3211 3212
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6085",
		.num_databases = 4096,
		.num_ports = 10,
3213
		.max_vid = 4095,
3214
		.port_base_addr = 0x10,
3215
		.global1_addr = 0x1b,
3216
		.global2_addr = 0x1c,
3217
		.age_time_coeff = 15000,
3218
		.g1_irqs = 8,
3219
		.g2_irqs = 10,
3220
		.atu_move_port_mask = 0xf,
3221
		.pvt = true,
3222
		.multi_chip = true,
3223
		.tag_protocol = DSA_TAG_PROTO_DSA,
3224
		.ops = &mv88e6085_ops,
3225 3226 3227
	},

	[MV88E6095] = {
3228
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
3229 3230 3231 3232
		.family = MV88E6XXX_FAMILY_6095,
		.name = "Marvell 88E6095/88E6095F",
		.num_databases = 256,
		.num_ports = 11,
3233
		.max_vid = 4095,
3234
		.port_base_addr = 0x10,
3235
		.global1_addr = 0x1b,
3236
		.global2_addr = 0x1c,
3237
		.age_time_coeff = 15000,
3238
		.g1_irqs = 8,
3239
		.atu_move_port_mask = 0xf,
3240
		.multi_chip = true,
3241
		.tag_protocol = DSA_TAG_PROTO_DSA,
3242
		.ops = &mv88e6095_ops,
3243 3244
	},

3245
	[MV88E6097] = {
3246
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
3247 3248 3249 3250
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6097/88E6097F",
		.num_databases = 4096,
		.num_ports = 11,
3251
		.max_vid = 4095,
3252 3253
		.port_base_addr = 0x10,
		.global1_addr = 0x1b,
3254
		.global2_addr = 0x1c,
3255
		.age_time_coeff = 15000,
3256
		.g1_irqs = 8,
3257
		.g2_irqs = 10,
3258
		.atu_move_port_mask = 0xf,
3259
		.pvt = true,
3260
		.multi_chip = true,
3261
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3262 3263 3264
		.ops = &mv88e6097_ops,
	},

3265
	[MV88E6123] = {
3266
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
3267 3268 3269 3270
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6123",
		.num_databases = 4096,
		.num_ports = 3,
3271
		.max_vid = 4095,
3272
		.port_base_addr = 0x10,
3273
		.global1_addr = 0x1b,
3274
		.global2_addr = 0x1c,
3275
		.age_time_coeff = 15000,
3276
		.g1_irqs = 9,
3277
		.g2_irqs = 10,
3278
		.atu_move_port_mask = 0xf,
3279
		.pvt = true,
3280
		.multi_chip = true,
3281
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3282
		.ops = &mv88e6123_ops,
3283 3284 3285
	},

	[MV88E6131] = {
3286
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
3287 3288 3289 3290
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6131",
		.num_databases = 256,
		.num_ports = 8,
3291
		.max_vid = 4095,
3292
		.port_base_addr = 0x10,
3293
		.global1_addr = 0x1b,
3294
		.global2_addr = 0x1c,
3295
		.age_time_coeff = 15000,
3296
		.g1_irqs = 9,
3297
		.atu_move_port_mask = 0xf,
3298
		.multi_chip = true,
3299
		.tag_protocol = DSA_TAG_PROTO_DSA,
3300
		.ops = &mv88e6131_ops,
3301 3302
	},

3303
	[MV88E6141] = {
3304
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
3305 3306 3307 3308
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
		.num_ports = 6,
3309
		.num_gpio = 11,
3310
		.max_vid = 4095,
3311 3312
		.port_base_addr = 0x10,
		.global1_addr = 0x1b,
3313
		.global2_addr = 0x1c,
3314 3315
		.age_time_coeff = 3750,
		.atu_move_port_mask = 0x1f,
3316
		.g2_irqs = 10,
3317
		.pvt = true,
3318
		.multi_chip = true,
3319 3320 3321 3322
		.tag_protocol = DSA_TAG_PROTO_EDSA,
		.ops = &mv88e6141_ops,
	},

3323
	[MV88E6161] = {
3324
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
3325 3326 3327 3328
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6161",
		.num_databases = 4096,
		.num_ports = 6,
3329
		.max_vid = 4095,
3330
		.port_base_addr = 0x10,
3331
		.global1_addr = 0x1b,
3332
		.global2_addr = 0x1c,
3333
		.age_time_coeff = 15000,
3334
		.g1_irqs = 9,
3335
		.g2_irqs = 10,
3336
		.atu_move_port_mask = 0xf,
3337
		.pvt = true,
3338
		.multi_chip = true,
3339
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3340
		.ops = &mv88e6161_ops,
3341 3342 3343
	},

	[MV88E6165] = {
3344
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
3345 3346 3347 3348
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6165",
		.num_databases = 4096,
		.num_ports = 6,
3349
		.max_vid = 4095,
3350
		.port_base_addr = 0x10,
3351
		.global1_addr = 0x1b,
3352
		.global2_addr = 0x1c,
3353
		.age_time_coeff = 15000,
3354
		.g1_irqs = 9,
3355
		.g2_irqs = 10,
3356
		.atu_move_port_mask = 0xf,
3357
		.pvt = true,
3358
		.multi_chip = true,
3359
		.tag_protocol = DSA_TAG_PROTO_DSA,
3360
		.ops = &mv88e6165_ops,
3361 3362 3363
	},

	[MV88E6171] = {
3364
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
3365 3366 3367 3368
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6171",
		.num_databases = 4096,
		.num_ports = 7,
3369
		.max_vid = 4095,
3370
		.port_base_addr = 0x10,
3371
		.global1_addr = 0x1b,
3372
		.global2_addr = 0x1c,
3373
		.age_time_coeff = 15000,
3374
		.g1_irqs = 9,
3375
		.g2_irqs = 10,
3376
		.atu_move_port_mask = 0xf,
3377
		.pvt = true,
3378
		.multi_chip = true,
3379
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3380
		.ops = &mv88e6171_ops,
3381 3382 3383
	},

	[MV88E6172] = {
3384
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
3385 3386 3387 3388
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6172",
		.num_databases = 4096,
		.num_ports = 7,
3389
		.num_gpio = 15,
3390
		.max_vid = 4095,
3391
		.port_base_addr = 0x10,
3392
		.global1_addr = 0x1b,
3393
		.global2_addr = 0x1c,
3394
		.age_time_coeff = 15000,
3395
		.g1_irqs = 9,
3396
		.g2_irqs = 10,
3397
		.atu_move_port_mask = 0xf,
3398
		.pvt = true,
3399
		.multi_chip = true,
3400
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3401
		.ops = &mv88e6172_ops,
3402 3403 3404
	},

	[MV88E6175] = {
3405
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
3406 3407 3408 3409
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6175",
		.num_databases = 4096,
		.num_ports = 7,
3410
		.max_vid = 4095,
3411
		.port_base_addr = 0x10,
3412
		.global1_addr = 0x1b,
3413
		.global2_addr = 0x1c,
3414
		.age_time_coeff = 15000,
3415
		.g1_irqs = 9,
3416
		.g2_irqs = 10,
3417
		.atu_move_port_mask = 0xf,
3418
		.pvt = true,
3419
		.multi_chip = true,
3420
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3421
		.ops = &mv88e6175_ops,
3422 3423 3424
	},

	[MV88E6176] = {
3425
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
3426 3427 3428 3429
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6176",
		.num_databases = 4096,
		.num_ports = 7,
3430
		.num_gpio = 15,
3431
		.max_vid = 4095,
3432
		.port_base_addr = 0x10,
3433
		.global1_addr = 0x1b,
3434
		.global2_addr = 0x1c,
3435
		.age_time_coeff = 15000,
3436
		.g1_irqs = 9,
3437
		.g2_irqs = 10,
3438
		.atu_move_port_mask = 0xf,
3439
		.pvt = true,
3440
		.multi_chip = true,
3441
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3442
		.ops = &mv88e6176_ops,
3443 3444 3445
	},

	[MV88E6185] = {
3446
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
3447 3448 3449 3450
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6185",
		.num_databases = 256,
		.num_ports = 10,
3451
		.max_vid = 4095,
3452
		.port_base_addr = 0x10,
3453
		.global1_addr = 0x1b,
3454
		.global2_addr = 0x1c,
3455
		.age_time_coeff = 15000,
3456
		.g1_irqs = 8,
3457
		.atu_move_port_mask = 0xf,
3458
		.multi_chip = true,
3459
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3460
		.ops = &mv88e6185_ops,
3461 3462
	},

3463
	[MV88E6190] = {
3464
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
3465 3466 3467 3468
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3469
		.num_gpio = 16,
3470
		.max_vid = 8191,
3471 3472
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3473
		.global2_addr = 0x1c,
3474
		.tag_protocol = DSA_TAG_PROTO_DSA,
3475
		.age_time_coeff = 3750,
3476
		.g1_irqs = 9,
3477
		.g2_irqs = 14,
3478
		.pvt = true,
3479
		.multi_chip = true,
3480
		.atu_move_port_mask = 0x1f,
3481 3482 3483 3484
		.ops = &mv88e6190_ops,
	},

	[MV88E6190X] = {
3485
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
3486 3487 3488 3489
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3490
		.num_gpio = 16,
3491
		.max_vid = 8191,
3492 3493
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3494
		.global2_addr = 0x1c,
3495
		.age_time_coeff = 3750,
3496
		.g1_irqs = 9,
3497
		.g2_irqs = 14,
3498
		.atu_move_port_mask = 0x1f,
3499
		.pvt = true,
3500
		.multi_chip = true,
3501
		.tag_protocol = DSA_TAG_PROTO_DSA,
3502 3503 3504 3505
		.ops = &mv88e6190x_ops,
	},

	[MV88E6191] = {
3506
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
3507 3508 3509 3510
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6191",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3511
		.max_vid = 8191,
3512 3513
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3514
		.global2_addr = 0x1c,
3515
		.age_time_coeff = 3750,
3516
		.g1_irqs = 9,
3517
		.g2_irqs = 14,
3518
		.atu_move_port_mask = 0x1f,
3519
		.pvt = true,
3520
		.multi_chip = true,
3521
		.tag_protocol = DSA_TAG_PROTO_DSA,
3522
		.ptp_support = true,
3523
		.ops = &mv88e6191_ops,
3524 3525
	},

3526
	[MV88E6240] = {
3527
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
3528 3529 3530 3531
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6240",
		.num_databases = 4096,
		.num_ports = 7,
3532
		.num_gpio = 15,
3533
		.max_vid = 4095,
3534
		.port_base_addr = 0x10,
3535
		.global1_addr = 0x1b,
3536
		.global2_addr = 0x1c,
3537
		.age_time_coeff = 15000,
3538
		.g1_irqs = 9,
3539
		.g2_irqs = 10,
3540
		.atu_move_port_mask = 0xf,
3541
		.pvt = true,
3542
		.multi_chip = true,
3543
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3544
		.ptp_support = true,
3545
		.ops = &mv88e6240_ops,
3546 3547
	},

3548
	[MV88E6290] = {
3549
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
3550 3551 3552 3553
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6290",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3554
		.num_gpio = 16,
3555
		.max_vid = 8191,
3556 3557
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3558
		.global2_addr = 0x1c,
3559
		.age_time_coeff = 3750,
3560
		.g1_irqs = 9,
3561
		.g2_irqs = 14,
3562
		.atu_move_port_mask = 0x1f,
3563
		.pvt = true,
3564
		.multi_chip = true,
3565
		.tag_protocol = DSA_TAG_PROTO_DSA,
3566
		.ptp_support = true,
3567 3568 3569
		.ops = &mv88e6290_ops,
	},

3570
	[MV88E6320] = {
3571
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
3572 3573 3574 3575
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6320",
		.num_databases = 4096,
		.num_ports = 7,
3576
		.num_gpio = 15,
3577
		.max_vid = 4095,
3578
		.port_base_addr = 0x10,
3579
		.global1_addr = 0x1b,
3580
		.global2_addr = 0x1c,
3581
		.age_time_coeff = 15000,
3582
		.g1_irqs = 8,
3583
		.atu_move_port_mask = 0xf,
3584
		.pvt = true,
3585
		.multi_chip = true,
3586
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3587
		.ptp_support = true,
3588
		.ops = &mv88e6320_ops,
3589 3590 3591
	},

	[MV88E6321] = {
3592
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
3593 3594 3595 3596
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6321",
		.num_databases = 4096,
		.num_ports = 7,
3597
		.num_gpio = 15,
3598
		.max_vid = 4095,
3599
		.port_base_addr = 0x10,
3600
		.global1_addr = 0x1b,
3601
		.global2_addr = 0x1c,
3602
		.age_time_coeff = 15000,
3603
		.g1_irqs = 8,
3604
		.atu_move_port_mask = 0xf,
3605
		.multi_chip = true,
3606
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3607
		.ptp_support = true,
3608
		.ops = &mv88e6321_ops,
3609 3610
	},

3611
	[MV88E6341] = {
3612
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
3613 3614 3615 3616
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
		.num_ports = 6,
3617
		.num_gpio = 11,
3618
		.max_vid = 4095,
3619 3620
		.port_base_addr = 0x10,
		.global1_addr = 0x1b,
3621
		.global2_addr = 0x1c,
3622
		.age_time_coeff = 3750,
3623
		.atu_move_port_mask = 0x1f,
3624
		.g2_irqs = 10,
3625
		.pvt = true,
3626
		.multi_chip = true,
3627
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3628
		.ptp_support = true,
3629 3630 3631
		.ops = &mv88e6341_ops,
	},

3632
	[MV88E6350] = {
3633
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
3634 3635 3636 3637
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6350",
		.num_databases = 4096,
		.num_ports = 7,
3638
		.max_vid = 4095,
3639
		.port_base_addr = 0x10,
3640
		.global1_addr = 0x1b,
3641
		.global2_addr = 0x1c,
3642
		.age_time_coeff = 15000,
3643
		.g1_irqs = 9,
3644
		.g2_irqs = 10,
3645
		.atu_move_port_mask = 0xf,
3646
		.pvt = true,
3647
		.multi_chip = true,
3648
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3649
		.ops = &mv88e6350_ops,
3650 3651 3652
	},

	[MV88E6351] = {
3653
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
3654 3655 3656 3657
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6351",
		.num_databases = 4096,
		.num_ports = 7,
3658
		.max_vid = 4095,
3659
		.port_base_addr = 0x10,
3660
		.global1_addr = 0x1b,
3661
		.global2_addr = 0x1c,
3662
		.age_time_coeff = 15000,
3663
		.g1_irqs = 9,
3664
		.g2_irqs = 10,
3665
		.atu_move_port_mask = 0xf,
3666
		.pvt = true,
3667
		.multi_chip = true,
3668
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3669
		.ops = &mv88e6351_ops,
3670 3671 3672
	},

	[MV88E6352] = {
3673
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
3674 3675 3676 3677
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6352",
		.num_databases = 4096,
		.num_ports = 7,
3678
		.num_gpio = 15,
3679
		.max_vid = 4095,
3680
		.port_base_addr = 0x10,
3681
		.global1_addr = 0x1b,
3682
		.global2_addr = 0x1c,
3683
		.age_time_coeff = 15000,
3684
		.g1_irqs = 9,
3685
		.g2_irqs = 10,
3686
		.atu_move_port_mask = 0xf,
3687
		.pvt = true,
3688
		.multi_chip = true,
3689
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3690
		.ptp_support = true,
3691
		.ops = &mv88e6352_ops,
3692
	},
3693
	[MV88E6390] = {
3694
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
3695 3696 3697 3698
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3699
		.num_gpio = 16,
3700
		.max_vid = 8191,
3701 3702
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3703
		.global2_addr = 0x1c,
3704
		.age_time_coeff = 3750,
3705
		.g1_irqs = 9,
3706
		.g2_irqs = 14,
3707
		.atu_move_port_mask = 0x1f,
3708
		.pvt = true,
3709
		.multi_chip = true,
3710
		.tag_protocol = DSA_TAG_PROTO_DSA,
3711
		.ptp_support = true,
3712 3713 3714
		.ops = &mv88e6390_ops,
	},
	[MV88E6390X] = {
3715
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
3716 3717 3718 3719
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3720
		.num_gpio = 16,
3721
		.max_vid = 8191,
3722 3723
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3724
		.global2_addr = 0x1c,
3725
		.age_time_coeff = 3750,
3726
		.g1_irqs = 9,
3727
		.g2_irqs = 14,
3728
		.atu_move_port_mask = 0x1f,
3729
		.pvt = true,
3730
		.multi_chip = true,
3731
		.tag_protocol = DSA_TAG_PROTO_DSA,
3732
		.ptp_support = true,
3733 3734
		.ops = &mv88e6390x_ops,
	},
3735 3736
};

3737
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
3738
{
3739
	int i;
3740

3741 3742 3743
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
3744 3745 3746 3747

	return NULL;
}

3748
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
3749 3750
{
	const struct mv88e6xxx_info *info;
3751 3752 3753
	unsigned int prod_num, rev;
	u16 id;
	int err;
3754

3755
	mutex_lock(&chip->reg_lock);
3756
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
3757 3758 3759
	mutex_unlock(&chip->reg_lock);
	if (err)
		return err;
3760

3761 3762
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
3763 3764 3765 3766 3767

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

3768
	/* Update the compatible info with the probed one */
3769
	chip->info = info;
3770

3771 3772 3773 3774
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

3775 3776
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
3777 3778 3779 3780

	return 0;
}

3781
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
3782
{
3783
	struct mv88e6xxx_chip *chip;
3784

3785 3786
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
3787 3788
		return NULL;

3789
	chip->dev = dev;
3790

3791
	mutex_init(&chip->reg_lock);
3792
	INIT_LIST_HEAD(&chip->mdios);
3793

3794
	return chip;
3795 3796
}

3797
static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
3798 3799
			      struct mii_bus *bus, int sw_addr)
{
3800
	if (sw_addr == 0)
3801
		chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
3802
	else if (chip->info->multi_chip)
3803
		chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
3804 3805 3806
	else
		return -EINVAL;

3807 3808
	chip->bus = bus;
	chip->sw_addr = sw_addr;
3809 3810 3811 3812

	return 0;
}

3813 3814
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
							int port)
3815
{
V
Vivien Didelot 已提交
3816
	struct mv88e6xxx_chip *chip = ds->priv;
3817

3818
	return chip->info->tag_protocol;
3819 3820
}

3821
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
3822 3823 3824
static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
				       struct device *host_dev, int sw_addr,
				       void **priv)
3825
{
3826
	struct mv88e6xxx_chip *chip;
3827
	struct mii_bus *bus;
3828
	int err;
3829

3830
	bus = dsa_host_dev_to_mii_bus(host_dev);
3831 3832 3833
	if (!bus)
		return NULL;

3834 3835
	chip = mv88e6xxx_alloc_chip(dsa_dev);
	if (!chip)
3836 3837
		return NULL;

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

3841
	err = mv88e6xxx_smi_init(chip, bus, sw_addr);
3842 3843 3844
	if (err)
		goto free;

3845
	err = mv88e6xxx_detect(chip);
3846
	if (err)
3847
		goto free;
3848

3849 3850 3851 3852 3853 3854
	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_switch_reset(chip);
	mutex_unlock(&chip->reg_lock);
	if (err)
		goto free;

3855 3856
	mv88e6xxx_phy_init(chip);

3857
	err = mv88e6xxx_mdios_register(chip, NULL);
3858
	if (err)
3859
		goto free;
3860

3861
	*priv = chip;
3862

3863
	return chip->info->name;
3864
free:
3865
	devm_kfree(dsa_dev, chip);
3866 3867

	return NULL;
3868
}
3869
#endif
3870

3871
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
3872
				      const struct switchdev_obj_port_mdb *mdb)
3873 3874 3875 3876 3877 3878 3879 3880 3881
{
	/* 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,
3882
				   const struct switchdev_obj_port_mdb *mdb)
3883
{
V
Vivien Didelot 已提交
3884
	struct mv88e6xxx_chip *chip = ds->priv;
3885 3886 3887

	mutex_lock(&chip->reg_lock);
	if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
3888
					 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
3889 3890
		dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
			port);
3891 3892 3893 3894 3895 3896
	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 已提交
3897
	struct mv88e6xxx_chip *chip = ds->priv;
3898 3899 3900 3901
	int err;

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
3902
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
3903 3904 3905 3906 3907
	mutex_unlock(&chip->reg_lock);

	return err;
}

3908
static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
3909
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
3910
	.probe			= mv88e6xxx_drv_probe,
3911
#endif
3912
	.get_tag_protocol	= mv88e6xxx_get_tag_protocol,
3913 3914 3915 3916 3917
	.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,
3918 3919
	.port_enable		= mv88e6xxx_port_enable,
	.port_disable		= mv88e6xxx_port_disable,
V
Vivien Didelot 已提交
3920 3921
	.get_mac_eee		= mv88e6xxx_get_mac_eee,
	.set_mac_eee		= mv88e6xxx_set_mac_eee,
3922
	.get_eeprom_len		= mv88e6xxx_get_eeprom_len,
3923 3924 3925 3926
	.get_eeprom		= mv88e6xxx_get_eeprom,
	.set_eeprom		= mv88e6xxx_set_eeprom,
	.get_regs_len		= mv88e6xxx_get_regs_len,
	.get_regs		= mv88e6xxx_get_regs,
3927
	.set_ageing_time	= mv88e6xxx_set_ageing_time,
3928 3929 3930
	.port_bridge_join	= mv88e6xxx_port_bridge_join,
	.port_bridge_leave	= mv88e6xxx_port_bridge_leave,
	.port_stp_state_set	= mv88e6xxx_port_stp_state_set,
3931
	.port_fast_age		= mv88e6xxx_port_fast_age,
3932 3933 3934 3935 3936 3937 3938
	.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,
3939 3940 3941
	.port_mdb_prepare       = mv88e6xxx_port_mdb_prepare,
	.port_mdb_add           = mv88e6xxx_port_mdb_add,
	.port_mdb_del           = mv88e6xxx_port_mdb_del,
3942 3943
	.crosschip_bridge_join	= mv88e6xxx_crosschip_bridge_join,
	.crosschip_bridge_leave	= mv88e6xxx_crosschip_bridge_leave,
3944 3945 3946 3947 3948
	.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,
3949 3950
};

3951 3952 3953 3954
static struct dsa_switch_driver mv88e6xxx_switch_drv = {
	.ops			= &mv88e6xxx_switch_ops,
};

3955
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
3956
{
3957
	struct device *dev = chip->dev;
3958 3959
	struct dsa_switch *ds;

3960
	ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
3961 3962 3963
	if (!ds)
		return -ENOMEM;

3964
	ds->priv = chip;
3965
	ds->ops = &mv88e6xxx_switch_ops;
3966 3967
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
3968 3969 3970

	dev_set_drvdata(dev, ds);

3971
	return dsa_register_switch(ds);
3972 3973
}

3974
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
3975
{
3976
	dsa_unregister_switch(chip->ds);
3977 3978
}

3979
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
3980
{
3981
	struct device *dev = &mdiodev->dev;
3982
	struct device_node *np = dev->of_node;
3983
	const struct mv88e6xxx_info *compat_info;
3984
	struct mv88e6xxx_chip *chip;
3985
	u32 eeprom_len;
3986
	int err;
3987

3988 3989 3990 3991
	compat_info = of_device_get_match_data(dev);
	if (!compat_info)
		return -EINVAL;

3992 3993
	chip = mv88e6xxx_alloc_chip(dev);
	if (!chip)
3994 3995
		return -ENOMEM;

3996
	chip->info = compat_info;
3997

3998
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
3999 4000
	if (err)
		return err;
4001

4002 4003 4004 4005
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
	if (IS_ERR(chip->reset))
		return PTR_ERR(chip->reset);

4006
	err = mv88e6xxx_detect(chip);
4007 4008
	if (err)
		return err;
4009

4010 4011
	mv88e6xxx_phy_init(chip);

4012
	if (chip->info->ops->get_eeprom &&
4013
	    !of_property_read_u32(np, "eeprom-length", &eeprom_len))
4014
		chip->eeprom_len = eeprom_len;
4015

4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039
	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;
	}

	if (chip->irq > 0) {
		/* Has to be performed before the MDIO bus is created,
		 * because the PHYs will link there interrupts to these
		 * interrupt controllers
		 */
		mutex_lock(&chip->reg_lock);
		err = mv88e6xxx_g1_irq_setup(chip);
		mutex_unlock(&chip->reg_lock);

		if (err)
			goto out;

4040
		if (chip->info->g2_irqs > 0) {
4041 4042 4043 4044
			err = mv88e6xxx_g2_irq_setup(chip);
			if (err)
				goto out_g1_irq;
		}
4045 4046 4047 4048

		err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
		if (err)
			goto out_g2_irq;
4049 4050 4051 4052

		err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
		if (err)
			goto out_g1_atu_prob_irq;
4053 4054
	}

4055
	err = mv88e6xxx_mdios_register(chip, np);
4056
	if (err)
4057
		goto out_g1_vtu_prob_irq;
4058

4059
	err = mv88e6xxx_register_switch(chip);
4060 4061
	if (err)
		goto out_mdio;
4062

4063
	return 0;
4064 4065

out_mdio:
4066
	mv88e6xxx_mdios_unregister(chip);
4067
out_g1_vtu_prob_irq:
4068 4069
	if (chip->irq > 0)
		mv88e6xxx_g1_vtu_prob_irq_free(chip);
4070
out_g1_atu_prob_irq:
4071 4072
	if (chip->irq > 0)
		mv88e6xxx_g1_atu_prob_irq_free(chip);
4073
out_g2_irq:
4074
	if (chip->info->g2_irqs > 0 && chip->irq > 0)
4075 4076
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
4077 4078
	if (chip->irq > 0) {
		mutex_lock(&chip->reg_lock);
4079
		mv88e6xxx_g1_irq_free(chip);
4080 4081
		mutex_unlock(&chip->reg_lock);
	}
4082 4083
out:
	return err;
4084
}
4085 4086 4087 4088

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

4091 4092
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
4093
		mv88e6xxx_ptp_free(chip);
4094
	}
4095

4096
	mv88e6xxx_phy_destroy(chip);
4097
	mv88e6xxx_unregister_switch(chip);
4098
	mv88e6xxx_mdios_unregister(chip);
4099

4100
	if (chip->irq > 0) {
4101
		mv88e6xxx_g1_vtu_prob_irq_free(chip);
4102
		mv88e6xxx_g1_atu_prob_irq_free(chip);
4103
		if (chip->info->g2_irqs > 0)
4104
			mv88e6xxx_g2_irq_free(chip);
4105
		mutex_lock(&chip->reg_lock);
4106
		mv88e6xxx_g1_irq_free(chip);
4107
		mutex_unlock(&chip->reg_lock);
4108
	}
4109 4110 4111
}

static const struct of_device_id mv88e6xxx_of_match[] = {
4112 4113 4114 4115
	{
		.compatible = "marvell,mv88e6085",
		.data = &mv88e6xxx_table[MV88E6085],
	},
4116 4117 4118 4119
	{
		.compatible = "marvell,mv88e6190",
		.data = &mv88e6xxx_table[MV88E6190],
	},
4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135
	{ /* 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)
{
4136
	register_switch_driver(&mv88e6xxx_switch_drv);
4137 4138
	return mdio_driver_register(&mv88e6xxx_driver);
}
4139 4140 4141 4142
module_init(mv88e6xxx_init);

static void __exit mv88e6xxx_cleanup(void)
{
4143
	mdio_driver_unregister(&mv88e6xxx_driver);
4144
	unregister_switch_driver(&mv88e6xxx_switch_drv);
4145 4146
}
module_exit(mv88e6xxx_cleanup);
4147 4148 4149 4150

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