chip.c 116.3 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
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
1441
		if (err)
1442
			return err;
1443

1444
		if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
1445 1446
			break;

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

1450 1451
		if (!is_unicast_ether_addr(addr.mac))
			continue;
1452

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

	return err;
}

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

1472
	/* Dump port's default Filtering Information Database (VLAN ID 0) */
1473
	err = mv88e6xxx_port_get_fid(chip, port, &fid);
1474
	if (err)
1475
		return err;
1476

1477
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
1478
	if (err)
1479
		return err;
1480

1481
	/* Dump VLANs' Filtering Information Databases */
1482
	do {
1483
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1484
		if (err)
1485
			return err;
1486 1487 1488 1489

		if (!vlan.valid)
			break;

1490
		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1491
						 cb, data);
1492
		if (err)
1493
			return err;
1494
	} while (vlan.vid < chip->info->max_vid);
1495

1496 1497 1498 1499
	return err;
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1500
				   dsa_fdb_dump_cb_t *cb, void *data)
1501
{
V
Vivien Didelot 已提交
1502
	struct mv88e6xxx_chip *chip = ds->priv;
1503 1504 1505
	int err;

	mutex_lock(&chip->reg_lock);
1506
	err = mv88e6xxx_port_db_dump(chip, port, cb, data);
1507
	mutex_unlock(&chip->reg_lock);
1508 1509 1510 1511

	return err;
}

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

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

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

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

1560
	return err;
1561 1562
}

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

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

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

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

	return 0;
}

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

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

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

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

1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652
	return 0;
}

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

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

1653
	mv88e6xxx_hardware_reset(chip);
1654

1655
	return mv88e6xxx_software_reset(chip);
1656 1657
}

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

1664 1665 1666 1667
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
1668 1669 1670
	if (err)
		return err;

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

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

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

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

1703 1704 1705 1706
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);
1707

1708
	if (dsa_is_user_port(chip->ds, port))
1709
		return mv88e6xxx_set_port_mode_normal(chip, port);
1710

1711 1712 1713
	/* 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);
1714

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

1718
	return -EINVAL;
1719 1720
}

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

1725
	return mv88e6xxx_port_set_message_port(chip, port, message);
1726
}
1727

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

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

1739
	return 0;
1740 1741
}

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

1748
	return 0;
1749 1750
}

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

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

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

1781 1782 1783
	return 0;
}

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

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

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

1826
	err = mv88e6xxx_setup_port_mode(chip, port);
1827 1828
	if (err)
		return err;
1829

1830
	err = mv88e6xxx_setup_egress_floods(chip, port);
1831 1832 1833
	if (err)
		return err;

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

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

1854 1855 1856
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
1857

1858
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
1859
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
1860 1861 1862
	if (err)
		return err;

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

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

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

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

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

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

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

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

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

1920
	err = mv88e6xxx_setup_message_port(chip, port);
1921 1922
	if (err)
		return err;
1923

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

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

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

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

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

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

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

	return err;
}

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

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

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

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

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

2027
	return mv88e6xxx_g1_stats_clear(chip);
2028 2029
}

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

2036
	chip->ds = ds;
2037
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
2038

2039
	mutex_lock(&chip->reg_lock);
2040

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

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

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

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

2063 2064 2065 2066
	err = mv88e6xxx_irl_setup(chip);
	if (err)
		goto unlock;

2067 2068 2069 2070
	err = mv88e6xxx_mac_setup(chip);
	if (err)
		goto unlock;

2071 2072 2073 2074
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

2075 2076 2077 2078
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

2079 2080 2081 2082
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

2083 2084 2085 2086
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

2087 2088 2089 2090
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

2091 2092 2093 2094
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

2095 2096 2097
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
2098

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

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
2108 2109
	}

2110
unlock:
2111
	mutex_unlock(&chip->reg_lock);
2112

2113
	return err;
2114 2115
}

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

2123 2124 2125
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

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

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

2138
	return err ? err : val;
2139 2140
}

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

2147 2148 2149
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

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

	return err;
2155 2156
}

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

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

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

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

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

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

	return 0;
2203
}
2204

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

2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223
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);
	}
}

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

	return 0;
2256 2257
}

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

	return chip->eeprom_len;
}

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

2271 2272
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
2273

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

2292 2293 2294
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

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

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

	return err;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return NULL;
}

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

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

3759 3760
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
3761 3762 3763 3764 3765

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

3766
	/* Update the compatible info with the probed one */
3767
	chip->info = info;
3768

3769 3770 3771 3772
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

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

	return 0;
}

3779
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
3780
{
3781
	struct mv88e6xxx_chip *chip;
3782

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

3787
	chip->dev = dev;
3788

3789
	mutex_init(&chip->reg_lock);
3790
	INIT_LIST_HEAD(&chip->mdios);
3791

3792
	return chip;
3793 3794
}

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

3805 3806
	chip->bus = bus;
	chip->sw_addr = sw_addr;
3807 3808 3809 3810

	return 0;
}

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

3816
	return chip->info->tag_protocol;
3817 3818
}

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

3828
	bus = dsa_host_dev_to_mii_bus(host_dev);
3829 3830 3831
	if (!bus)
		return NULL;

3832 3833
	chip = mv88e6xxx_alloc_chip(dsa_dev);
	if (!chip)
3834 3835
		return NULL;

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

3839
	err = mv88e6xxx_smi_init(chip, bus, sw_addr);
3840 3841 3842
	if (err)
		goto free;

3843
	err = mv88e6xxx_detect(chip);
3844
	if (err)
3845
		goto free;
3846

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

3853 3854
	mv88e6xxx_phy_init(chip);

3855
	err = mv88e6xxx_mdios_register(chip, NULL);
3856
	if (err)
3857
		goto free;
3858

3859
	*priv = chip;
3860

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

	return NULL;
3866
}
3867
#endif
3868

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

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

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

	return err;
}

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

3949 3950 3951 3952
static struct dsa_switch_driver mv88e6xxx_switch_drv = {
	.ops			= &mv88e6xxx_switch_ops,
};

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

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

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

	dev_set_drvdata(dev, ds);

3969
	return dsa_register_switch(ds);
3970 3971
}

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

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

3986 3987 3988 3989
	compat_info = of_device_get_match_data(dev);
	if (!compat_info)
		return -EINVAL;

3990 3991
	chip = mv88e6xxx_alloc_chip(dev);
	if (!chip)
3992 3993
		return -ENOMEM;

3994
	chip->info = compat_info;
3995

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

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

4004
	err = mv88e6xxx_detect(chip);
4005 4006
	if (err)
		return err;
4007

4008 4009
	mv88e6xxx_phy_init(chip);

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

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

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

		err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
		if (err)
			goto out_g2_irq;
4047 4048 4049 4050

		err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
		if (err)
			goto out_g1_atu_prob_irq;
4051 4052
	}

4053
	err = mv88e6xxx_mdios_register(chip, np);
4054
	if (err)
4055
		goto out_g1_vtu_prob_irq;
4056

4057
	err = mv88e6xxx_register_switch(chip);
4058 4059
	if (err)
		goto out_mdio;
4060

4061
	return 0;
4062 4063

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

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

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

4094
	mv88e6xxx_phy_destroy(chip);
4095
	mv88e6xxx_unregister_switch(chip);
4096
	mv88e6xxx_mdios_unregister(chip);
4097

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

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

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

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