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

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

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

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

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

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

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

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

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

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

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

	*val = ret & 0xffff;

	return 0;
}

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

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

	return 0;
}

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

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

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

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

	return -ETIMEDOUT;
}

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

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

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

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

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

157
	*val = ret & 0xffff;
158

159
	return 0;
160 161
}

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

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

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

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

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

	return 0;
}

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

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

200
	assert_reg_lock(chip);
201

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

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

	return 0;
}

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

216
	assert_reg_lock(chip);
217

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

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

225 226 227
	return 0;
}

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

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

	return mdio_bus->bus;
}

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

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

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

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

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

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

	if (err)
		goto out;

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

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

	return mv88e6xxx_g1_irq_thread_work(chip);
}

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

	mutex_lock(&chip->reg_lock);
}

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

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

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

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

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

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

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

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

	return 0;
}

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

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

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

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

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

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

	free_irq(chip->irq, chip);
}

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

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

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

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

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

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

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

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

	return 0;

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

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

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

	return err;
}

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

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

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

	return err;
}

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

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

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

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

	kthread_init_delayed_work(&chip->irq_poll_work,
				  mv88e6xxx_irq_poll);

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

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

	return 0;
}

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

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

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

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

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

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

		usleep_range(1000, 2000);
	}

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

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

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

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

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

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

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

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

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

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

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

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

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

	return err;
}

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

	if (!phy_is_pseudo_fixed_link(phydev))
		return;

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

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

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

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

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

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

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

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

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

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

	return j;
710 711
}

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

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

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

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

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

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

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

753 754
	mutex_lock(&chip->reg_lock);

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

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

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

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

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

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

783 784 785 786 787 788 789 790 791 792 793 794
static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
{
	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
					      STATS_TYPE_PORT);
}

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

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

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

804
	mutex_lock(&chip->reg_lock);
805
	if (chip->info->ops->stats_get_sset_count)
806 807 808 809 810 811 812
		count = chip->info->ops->stats_get_sset_count(chip);
	if (count < 0)
		goto out;

	if (chip->info->ops->serdes_get_sset_count)
		serdes_count = chip->info->ops->serdes_get_sset_count(chip,
								      port);
813
	if (serdes_count < 0) {
814
		count = serdes_count;
815 816 817 818 819
		goto out;
	}
	count += serdes_count;
	count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);

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

823
	return count;
824 825
}

826 827 828
static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data, int types,
				     u16 bank1_select, u16 histogram)
829 830 831 832 833 834 835
{
	struct mv88e6xxx_hw_stat *stat;
	int i, j;

	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
		stat = &mv88e6xxx_hw_stats[i];
		if (stat->type & types) {
836
			mutex_lock(&chip->reg_lock);
837 838 839
			data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
							      bank1_select,
							      histogram);
840 841
			mutex_unlock(&chip->reg_lock);

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

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

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

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

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

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

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

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

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

908
	mutex_lock(&chip->reg_lock);
909

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

	if (ret < 0)
914
		return;
915 916

	mv88e6xxx_get_stats(chip, port, data);
917

918 919
}

920 921 922 923 924 925 926 927
static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->stats_set_histogram)
		return chip->info->ops->stats_set_histogram(chip);

	return 0;
}

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

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

	regs->version = 0;

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

946
	mutex_lock(&chip->reg_lock);
947

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

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

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

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

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

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

979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998
	if (dev < DSA_MAX_SWITCHES)
		ds = chip->ds->dst->ds[dev];

	/* Prevent frames from unknown switch or port */
	if (!ds || port >= ds->num_ports)
		return 0;

	/* Frames from DSA links and CPU ports can egress any local port */
	if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
		return mv88e6xxx_port_mask(chip);

	br = ds->ports[port].bridge_dev;
	pvlan = 0;

	/* Frames from user ports can egress any local DSA links and CPU ports,
	 * as well as any local member of their bridge group.
	 */
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
		if (dsa_is_cpu_port(chip->ds, i) ||
		    dsa_is_dsa_port(chip->ds, i) ||
V
Vivien Didelot 已提交
999
		    (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
1000 1001 1002 1003 1004
			pvlan |= BIT(i);

	return pvlan;
}

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

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

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

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

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

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

1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048
static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
{
	int target, port;
	int err;

	if (!chip->info->global2_addr)
		return 0;

	/* Initialize the routing port to the 32 possible target devices */
	for (target = 0; target < 32; target++) {
		port = 0x1f;
		if (target < DSA_MAX_SWITCHES)
			if (chip->ds->rtable[target] != DSA_RTABLE_NONE)
				port = chip->ds->rtable[target];

		err = mv88e6xxx_g2_device_mapping_write(chip, target, port);
		if (err)
			return err;
	}

1049 1050 1051 1052 1053 1054 1055
	if (chip->info->ops->set_cascade_port) {
		port = MV88E6XXX_CASCADE_PORT_MULTIPLE;
		err = chip->info->ops->set_cascade_port(chip, port);
		if (err)
			return err;
	}

1056 1057 1058
	return 0;
}

1059 1060 1061 1062 1063 1064 1065 1066 1067
static int mv88e6xxx_trunk_setup(struct mv88e6xxx_chip *chip)
{
	/* Clear all trunk masks and mapping */
	if (chip->info->global2_addr)
		return mv88e6xxx_g2_trunk_clear(chip);

	return 0;
}

1068 1069 1070 1071 1072 1073 1074 1075
static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->pot_clear)
		return chip->info->ops->pot_clear(chip);

	return 0;
}

1076 1077 1078 1079 1080 1081 1082 1083
static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->mgmt_rsvd2cpu)
		return chip->info->ops->mgmt_rsvd2cpu(chip);

	return 0;
}

1084 1085
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
1086 1087
	int err;

1088 1089 1090 1091
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

1092 1093 1094 1095
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

1096 1097 1098
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118
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;
}

1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131
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;
}

1132 1133 1134 1135 1136 1137 1138 1139 1140
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)
1141
		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1142 1143 1144 1145

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

1146 1147
static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
{
1148 1149 1150
	int dev, port;
	int err;

1151 1152 1153 1154 1155 1156
	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.
	 */
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169
	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;
1170 1171
}

1172 1173 1174 1175 1176 1177
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);
1178
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1179 1180 1181
	mutex_unlock(&chip->reg_lock);

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

1185 1186 1187 1188 1189 1190 1191 1192
static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
{
	if (!chip->info->max_vid)
		return 0;

	return mv88e6xxx_g1_vtu_flush(chip);
}

1193 1194 1195 1196 1197 1198 1199 1200 1201
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);
}

1202 1203 1204 1205 1206 1207 1208 1209 1210
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);
}

1211
static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1212 1213
{
	DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1214 1215 1216
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = chip->info->max_vid,
	};
1217
	int i, err;
1218 1219 1220

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

1221
	/* Set every FID bit used by the (un)bridged ports */
1222
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1223
		err = mv88e6xxx_port_get_fid(chip, i, fid);
1224 1225 1226 1227 1228 1229
		if (err)
			return err;

		set_bit(*fid, fid_bitmap);
	}

1230 1231
	/* Set every FID bit used by the VLAN entries */
	do {
1232
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1233 1234 1235 1236 1237 1238 1239
		if (err)
			return err;

		if (!vlan.valid)
			break;

		set_bit(vlan.fid, fid_bitmap);
1240
	} while (vlan.vid < chip->info->max_vid);
1241 1242 1243 1244 1245

	/* 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);
1246
	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1247 1248 1249
		return -ENOSPC;

	/* Clear the database */
1250
	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1251 1252
}

1253 1254
static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
			     struct mv88e6xxx_vtu_entry *entry, bool new)
1255 1256 1257 1258 1259 1260
{
	int err;

	if (!vid)
		return -EINVAL;

1261 1262
	entry->vid = vid - 1;
	entry->valid = false;
1263

1264
	err = mv88e6xxx_vtu_getnext(chip, entry);
1265 1266 1267
	if (err)
		return err;

1268 1269
	if (entry->vid == vid && entry->valid)
		return 0;
1270

1271 1272 1273 1274 1275 1276 1277 1278
	if (new) {
		int i;

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

1279
		/* Exclude all ports */
1280
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1281
			entry->member[i] =
1282
				MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1283 1284

		return mv88e6xxx_atu_new(chip, &entry->fid);
1285 1286
	}

1287 1288
	/* switchdev expects -EOPNOTSUPP to honor software VLANs */
	return -EOPNOTSUPP;
1289 1290
}

1291 1292 1293
static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
					u16 vid_begin, u16 vid_end)
{
V
Vivien Didelot 已提交
1294
	struct mv88e6xxx_chip *chip = ds->priv;
1295 1296 1297
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = vid_begin - 1,
	};
1298 1299
	int i, err;

1300 1301 1302 1303
	/* 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;

1304 1305 1306
	if (!vid_begin)
		return -EOPNOTSUPP;

1307
	mutex_lock(&chip->reg_lock);
1308 1309

	do {
1310
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1311 1312 1313 1314 1315 1316 1317 1318 1319
		if (err)
			goto unlock;

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

1320
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1321 1322 1323
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

1324
			if (!ds->ports[i].slave)
1325 1326
				continue;

1327
			if (vlan.member[i] ==
1328
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1329 1330
				continue;

V
Vivien Didelot 已提交
1331
			if (dsa_to_port(ds, i)->bridge_dev ==
1332
			    ds->ports[port].bridge_dev)
1333 1334
				break; /* same bridge, check next VLAN */

V
Vivien Didelot 已提交
1335
			if (!dsa_to_port(ds, i)->bridge_dev)
1336 1337
				continue;

1338 1339
			dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
				port, vlan.vid, i,
V
Vivien Didelot 已提交
1340
				netdev_name(dsa_to_port(ds, i)->bridge_dev));
1341 1342 1343 1344 1345 1346
			err = -EOPNOTSUPP;
			goto unlock;
		}
	} while (vlan.vid < vid_end);

unlock:
1347
	mutex_unlock(&chip->reg_lock);
1348 1349 1350 1351

	return err;
}

1352 1353
static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
					 bool vlan_filtering)
1354
{
V
Vivien Didelot 已提交
1355
	struct mv88e6xxx_chip *chip = ds->priv;
1356 1357
	u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
		MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
1358
	int err;
1359

1360
	if (!chip->info->max_vid)
1361 1362
		return -EOPNOTSUPP;

1363
	mutex_lock(&chip->reg_lock);
1364
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1365
	mutex_unlock(&chip->reg_lock);
1366

1367
	return err;
1368 1369
}

1370 1371
static int
mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1372
			    const struct switchdev_obj_port_vlan *vlan)
1373
{
V
Vivien Didelot 已提交
1374
	struct mv88e6xxx_chip *chip = ds->priv;
1375 1376
	int err;

1377
	if (!chip->info->max_vid)
1378 1379
		return -EOPNOTSUPP;

1380 1381 1382 1383 1384 1385 1386 1387
	/* 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;

1388 1389 1390 1391 1392 1393
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */
	return 0;
}

1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437
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);
}

1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460
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;
}

1461
static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
1462
				    u16 vid, u8 member)
1463
{
1464
	struct mv88e6xxx_vtu_entry vlan;
1465 1466
	int err;

1467
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
1468
	if (err)
1469
		return err;
1470

1471
	vlan.member[port] = member;
1472

1473 1474 1475 1476 1477
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
	if (err)
		return err;

	return mv88e6xxx_broadcast_setup(chip, vid);
1478 1479
}

1480
static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1481
				    const struct switchdev_obj_port_vlan *vlan)
1482
{
V
Vivien Didelot 已提交
1483
	struct mv88e6xxx_chip *chip = ds->priv;
1484 1485
	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1486
	u8 member;
1487 1488
	u16 vid;

1489
	if (!chip->info->max_vid)
1490 1491
		return;

1492
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1493
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1494
	else if (untagged)
1495
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
1496
	else
1497
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
1498

1499
	mutex_lock(&chip->reg_lock);
1500

1501
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
1502
		if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
1503 1504
			dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
				vid, untagged ? 'u' : 't');
1505

1506
	if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1507 1508
		dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
			vlan->vid_end);
1509

1510
	mutex_unlock(&chip->reg_lock);
1511 1512
}

1513
static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
1514
				    int port, u16 vid)
1515
{
1516
	struct mv88e6xxx_vtu_entry vlan;
1517 1518
	int i, err;

1519
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1520
	if (err)
1521
		return err;
1522

1523
	/* Tell switchdev if this VLAN is handled in software */
1524
	if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1525
		return -EOPNOTSUPP;
1526

1527
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1528 1529

	/* keep the VLAN unless all ports are excluded */
1530
	vlan.valid = false;
1531
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1532 1533
		if (vlan.member[i] !=
		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
1534
			vlan.valid = true;
1535 1536 1537 1538
			break;
		}
	}

1539
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1540 1541 1542
	if (err)
		return err;

1543
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
1544 1545
}

1546 1547
static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
				   const struct switchdev_obj_port_vlan *vlan)
1548
{
V
Vivien Didelot 已提交
1549
	struct mv88e6xxx_chip *chip = ds->priv;
1550 1551 1552
	u16 pvid, vid;
	int err = 0;

1553
	if (!chip->info->max_vid)
1554 1555
		return -EOPNOTSUPP;

1556
	mutex_lock(&chip->reg_lock);
1557

1558
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
1559 1560 1561
	if (err)
		goto unlock;

1562
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1563
		err = _mv88e6xxx_port_vlan_del(chip, port, vid);
1564 1565 1566 1567
		if (err)
			goto unlock;

		if (vid == pvid) {
1568
			err = mv88e6xxx_port_set_pvid(chip, port, 0);
1569 1570 1571 1572 1573
			if (err)
				goto unlock;
		}
	}

1574
unlock:
1575
	mutex_unlock(&chip->reg_lock);
1576 1577 1578 1579

	return err;
}

1580 1581
static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
				  const unsigned char *addr, u16 vid)
1582
{
V
Vivien Didelot 已提交
1583
	struct mv88e6xxx_chip *chip = ds->priv;
1584
	int err;
1585

1586
	mutex_lock(&chip->reg_lock);
1587 1588
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1589
	mutex_unlock(&chip->reg_lock);
1590 1591

	return err;
1592 1593
}

1594
static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1595
				  const unsigned char *addr, u16 vid)
1596
{
V
Vivien Didelot 已提交
1597
	struct mv88e6xxx_chip *chip = ds->priv;
1598
	int err;
1599

1600
	mutex_lock(&chip->reg_lock);
1601
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1602
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
1603
	mutex_unlock(&chip->reg_lock);
1604

1605
	return err;
1606 1607
}

1608 1609
static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
				      u16 fid, u16 vid, int port,
1610
				      dsa_fdb_dump_cb_t *cb, void *data)
1611
{
1612
	struct mv88e6xxx_atu_entry addr;
1613
	bool is_static;
1614 1615
	int err;

1616
	addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1617
	eth_broadcast_addr(addr.mac);
1618 1619

	do {
1620
		mutex_lock(&chip->reg_lock);
1621
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
1622
		mutex_unlock(&chip->reg_lock);
1623
		if (err)
1624
			return err;
1625

1626
		if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
1627 1628
			break;

1629
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
1630 1631
			continue;

1632 1633
		if (!is_unicast_ether_addr(addr.mac))
			continue;
1634

1635 1636 1637
		is_static = (addr.state ==
			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
		err = cb(addr.mac, vid, is_static, data);
1638 1639
		if (err)
			return err;
1640 1641 1642 1643 1644
	} while (!is_broadcast_ether_addr(addr.mac));

	return err;
}

1645
static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1646
				  dsa_fdb_dump_cb_t *cb, void *data)
1647
{
1648
	struct mv88e6xxx_vtu_entry vlan = {
1649
		.vid = chip->info->max_vid,
1650
	};
1651
	u16 fid;
1652 1653
	int err;

1654
	/* Dump port's default Filtering Information Database (VLAN ID 0) */
1655
	mutex_lock(&chip->reg_lock);
1656
	err = mv88e6xxx_port_get_fid(chip, port, &fid);
1657 1658
	mutex_unlock(&chip->reg_lock);

1659
	if (err)
1660
		return err;
1661

1662
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
1663
	if (err)
1664
		return err;
1665

1666
	/* Dump VLANs' Filtering Information Databases */
1667
	do {
1668
		mutex_lock(&chip->reg_lock);
1669
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1670
		mutex_unlock(&chip->reg_lock);
1671
		if (err)
1672
			return err;
1673 1674 1675 1676

		if (!vlan.valid)
			break;

1677
		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1678
						 cb, data);
1679
		if (err)
1680
			return err;
1681
	} while (vlan.vid < chip->info->max_vid);
1682

1683 1684 1685 1686
	return err;
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1687
				   dsa_fdb_dump_cb_t *cb, void *data)
1688
{
V
Vivien Didelot 已提交
1689
	struct mv88e6xxx_chip *chip = ds->priv;
1690

1691
	return mv88e6xxx_port_db_dump(chip, port, cb, data);
1692 1693
}

1694 1695
static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
				struct net_device *br)
1696
{
1697
	struct dsa_switch *ds;
1698
	int port;
1699
	int dev;
1700
	int err;
1701

1702 1703 1704 1705
	/* 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);
1706
			if (err)
1707
				return err;
1708 1709 1710
		}
	}

1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728
	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;
			}
		}
	}

1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739
	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);
1740
	mutex_unlock(&chip->reg_lock);
1741

1742
	return err;
1743 1744
}

1745 1746
static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
					struct net_device *br)
1747
{
V
Vivien Didelot 已提交
1748
	struct mv88e6xxx_chip *chip = ds->priv;
1749

1750
	mutex_lock(&chip->reg_lock);
1751 1752 1753
	if (mv88e6xxx_bridge_map(chip, br) ||
	    mv88e6xxx_port_vlan_map(chip, port))
		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
1754
	mutex_unlock(&chip->reg_lock);
1755 1756
}

1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786
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);
}

1787 1788 1789 1790 1791 1792 1793 1794
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->reset)
		return chip->info->ops->reset(chip);

	return 0;
}

1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807
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);
	}
}

1808
static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1809
{
1810
	int i, err;
1811

1812
	/* Set all ports to the Disabled state */
1813
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
1814
		err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
1815 1816
		if (err)
			return err;
1817 1818
	}

1819 1820 1821
	/* Wait for transmit queues to drain,
	 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
	 */
1822 1823
	usleep_range(2000, 4000);

1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834
	return 0;
}

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

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

1835
	mv88e6xxx_hardware_reset(chip);
1836

1837
	return mv88e6xxx_software_reset(chip);
1838 1839
}

1840
static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
1841 1842
				   enum mv88e6xxx_frame_mode frame,
				   enum mv88e6xxx_egress_mode egress, u16 etype)
1843 1844 1845
{
	int err;

1846 1847 1848 1849
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
1850 1851 1852
	if (err)
		return err;

1853 1854 1855 1856 1857 1858 1859 1860
	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;
1861 1862
}

1863
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1864
{
1865
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
1866
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
1867
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
1868
}
1869

1870 1871 1872
static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
1873
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
1874
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
1875
}
1876

1877 1878 1879 1880
static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port,
				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
1881 1882
				       MV88E6XXX_EGRESS_MODE_ETHERTYPE,
				       ETH_P_EDSA);
1883
}
1884

1885 1886 1887 1888
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);
1889

1890
	if (dsa_is_user_port(chip->ds, port))
1891
		return mv88e6xxx_set_port_mode_normal(chip, port);
1892

1893 1894 1895
	/* 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);
1896

1897 1898
	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
		return mv88e6xxx_set_port_mode_edsa(chip, port);
1899

1900
	return -EINVAL;
1901 1902
}

1903
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
1904
{
1905
	bool message = dsa_is_dsa_port(chip->ds, port);
1906

1907
	return mv88e6xxx_port_set_message_port(chip, port, message);
1908
}
1909

1910
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
1911
{
1912 1913
	struct dsa_switch *ds = chip->ds;
	bool flood;
1914

1915
	/* Upstream ports flood frames with unknown unicast or multicast DA */
1916
	flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
1917 1918 1919
	if (chip->info->ops->port_set_egress_floods)
		return chip->info->ops->port_set_egress_floods(chip, port,
							       flood, flood);
1920

1921
	return 0;
1922 1923
}

1924 1925 1926
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
1927 1928
	if (chip->info->ops->serdes_power)
		return chip->info->ops->serdes_power(chip, port, on);
1929

1930
	return 0;
1931 1932
}

1933 1934 1935 1936 1937 1938
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

1939
	upstream_port = dsa_upstream_port(ds, port);
1940 1941 1942 1943 1944 1945 1946
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962
	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;
		}
	}

1963 1964 1965
	return 0;
}

1966
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
1967
{
1968
	struct dsa_switch *ds = chip->ds;
1969
	int err;
1970
	u16 reg;
1971

1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985
	/* 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;
1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000

	/* 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.
	 */
2001 2002 2003 2004
	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);
2005 2006
	if (err)
		return err;
2007

2008
	err = mv88e6xxx_setup_port_mode(chip, port);
2009 2010
	if (err)
		return err;
2011

2012
	err = mv88e6xxx_setup_egress_floods(chip, port);
2013 2014 2015
	if (err)
		return err;

2016 2017 2018
	/* 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.
2019
	 */
2020 2021 2022 2023 2024
	if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
		err = mv88e6xxx_serdes_power(chip, port, true);
		if (err)
			return err;
	}
2025

2026
	/* Port Control 2: don't force a good FCS, set the maximum frame size to
2027
	 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
2028 2029 2030
	 * 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.
2031
	 */
2032 2033 2034
	err = mv88e6xxx_port_set_map_da(chip, port);
	if (err)
		return err;
2035

2036 2037 2038
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
2039

2040
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
2041
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
2042 2043 2044
	if (err)
		return err;

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

2051 2052 2053 2054 2055
	/* 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.
	 */
2056
	reg = 1 << port;
2057 2058
	/* Disable learning for CPU port */
	if (dsa_is_cpu_port(ds, port))
2059
		reg = 0;
2060

2061 2062
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
2063 2064
	if (err)
		return err;
2065 2066

	/* Egress rate control 2: disable egress rate control. */
2067 2068
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
				   0x0000);
2069 2070
	if (err)
		return err;
2071

2072 2073
	if (chip->info->ops->port_pause_limit) {
		err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
2074 2075
		if (err)
			return err;
2076
	}
2077

2078 2079 2080 2081 2082 2083
	if (chip->info->ops->port_disable_learn_limit) {
		err = chip->info->ops->port_disable_learn_limit(chip, port);
		if (err)
			return err;
	}

2084 2085
	if (chip->info->ops->port_disable_pri_override) {
		err = chip->info->ops->port_disable_pri_override(chip, port);
2086 2087
		if (err)
			return err;
2088
	}
2089

2090 2091
	if (chip->info->ops->port_tag_remap) {
		err = chip->info->ops->port_tag_remap(chip, port);
2092 2093
		if (err)
			return err;
2094 2095
	}

2096 2097
	if (chip->info->ops->port_egress_rate_limiting) {
		err = chip->info->ops->port_egress_rate_limiting(chip, port);
2098 2099
		if (err)
			return err;
2100 2101
	}

2102
	err = mv88e6xxx_setup_message_port(chip, port);
2103 2104
	if (err)
		return err;
2105

2106
	/* Port based VLAN map: give each port the same default address
2107 2108
	 * database, and allow bidirectional communication between the
	 * CPU and DSA port(s), and the other ports.
2109
	 */
2110
	err = mv88e6xxx_port_set_fid(chip, port, 0);
2111 2112
	if (err)
		return err;
2113

2114
	err = mv88e6xxx_port_vlan_map(chip, port);
2115 2116
	if (err)
		return err;
2117 2118 2119 2120

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

2124 2125 2126 2127
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
2128
	int err;
2129 2130

	mutex_lock(&chip->reg_lock);
2131
	err = mv88e6xxx_serdes_power(chip, port, true);
2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142
	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);
2143 2144
	if (mv88e6xxx_serdes_power(chip, port, false))
		dev_err(chip->dev, "failed to power off SERDES\n");
2145 2146 2147
	mutex_unlock(&chip->reg_lock);
}

2148 2149 2150
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
2151
	struct mv88e6xxx_chip *chip = ds->priv;
2152 2153 2154
	int err;

	mutex_lock(&chip->reg_lock);
2155
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2156 2157 2158 2159 2160
	mutex_unlock(&chip->reg_lock);

	return err;
}

2161
static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
2162
{
2163
	struct dsa_switch *ds = chip->ds;
2164
	int err;
2165

2166
	/* Disable remote management, and set the switch's DSA device number. */
2167
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL2,
2168
				 (ds->index & 0x1f));
2169 2170 2171
	if (err)
		return err;

2172
	/* Configure the IP ToS mapping registers. */
2173
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_0, 0x0000);
2174
	if (err)
2175
		return err;
2176
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_1, 0x0000);
2177
	if (err)
2178
		return err;
2179
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_2, 0x5555);
2180
	if (err)
2181
		return err;
2182
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_3, 0x5555);
2183
	if (err)
2184
		return err;
2185
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_4, 0xaaaa);
2186
	if (err)
2187
		return err;
2188
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_5, 0xaaaa);
2189
	if (err)
2190
		return err;
2191
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_6, 0xffff);
2192
	if (err)
2193
		return err;
2194
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_7, 0xffff);
2195
	if (err)
2196
		return err;
2197 2198

	/* Configure the IEEE 802.1p priority mapping register. */
2199
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IEEE_PRI, 0xfa41);
2200
	if (err)
2201
		return err;
2202

2203 2204 2205 2206 2207
	/* Initialize the statistics unit */
	err = mv88e6xxx_stats_set_histogram(chip);
	if (err)
		return err;

2208
	return mv88e6xxx_g1_stats_clear(chip);
2209 2210
}

2211
static int mv88e6xxx_setup(struct dsa_switch *ds)
2212
{
V
Vivien Didelot 已提交
2213
	struct mv88e6xxx_chip *chip = ds->priv;
2214
	int err;
2215 2216
	int i;

2217
	chip->ds = ds;
2218
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
2219

2220
	mutex_lock(&chip->reg_lock);
2221

2222
	/* Setup Switch Port Registers */
2223
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2224 2225 2226
		if (dsa_is_unused_port(ds, i))
			continue;

2227 2228 2229 2230 2231 2232 2233
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

	/* Setup Switch Global 1 Registers */
	err = mv88e6xxx_g1_setup(chip);
2234 2235 2236
	if (err)
		goto unlock;

2237 2238 2239 2240
	err = mv88e6xxx_irl_setup(chip);
	if (err)
		goto unlock;

2241 2242 2243 2244
	err = mv88e6xxx_mac_setup(chip);
	if (err)
		goto unlock;

2245 2246 2247 2248
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

2249 2250 2251 2252
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

2253 2254 2255 2256
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

2257 2258 2259 2260
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

2261 2262 2263 2264
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

2265 2266 2267 2268
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

2269 2270 2271
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
2272

2273 2274 2275 2276
	err = mv88e6xxx_trunk_setup(chip);
	if (err)
		goto unlock;

2277 2278 2279 2280
	err = mv88e6xxx_devmap_setup(chip);
	if (err)
		goto unlock;

2281
	/* Setup PTP Hardware Clock and timestamping */
2282 2283 2284 2285
	if (chip->info->ptp_support) {
		err = mv88e6xxx_ptp_setup(chip);
		if (err)
			goto unlock;
2286 2287 2288 2289

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
2290 2291
	}

2292
unlock:
2293
	mutex_unlock(&chip->reg_lock);
2294

2295
	return err;
2296 2297
}

2298
static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
2299
{
2300 2301
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2302 2303
	u16 val;
	int err;
2304

2305 2306 2307
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

2308
	mutex_lock(&chip->reg_lock);
2309
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
2310
	mutex_unlock(&chip->reg_lock);
2311

2312 2313 2314 2315 2316
	if (reg == MII_PHYSID2) {
		/* Some internal PHYS don't have a model number.  Use
		 * the mv88e6390 family model number instead.
		 */
		if (!(val & 0x3f0))
2317
			val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
2318 2319
	}

2320
	return err ? err : val;
2321 2322
}

2323
static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
2324
{
2325 2326
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2327
	int err;
2328

2329 2330 2331
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

2332
	mutex_lock(&chip->reg_lock);
2333
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
2334
	mutex_unlock(&chip->reg_lock);
2335 2336

	return err;
2337 2338
}

2339
static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
2340 2341
				   struct device_node *np,
				   bool external)
2342 2343
{
	static int index;
2344
	struct mv88e6xxx_mdio_bus *mdio_bus;
2345 2346 2347
	struct mii_bus *bus;
	int err;

2348 2349 2350 2351 2352 2353 2354 2355 2356
	if (external) {
		mutex_lock(&chip->reg_lock);
		err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
		mutex_unlock(&chip->reg_lock);

		if (err)
			return err;
	}

2357
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
2358 2359 2360
	if (!bus)
		return -ENOMEM;

2361
	mdio_bus = bus->priv;
2362
	mdio_bus->bus = bus;
2363
	mdio_bus->chip = chip;
2364 2365
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
2366

2367 2368
	if (np) {
		bus->name = np->full_name;
2369
		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
2370 2371 2372 2373 2374 2375 2376
	} 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;
2377
	bus->parent = chip->dev;
2378

2379 2380 2381 2382 2383 2384
	if (!external) {
		err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
		if (err)
			return err;
	}

2385 2386
	if (np)
		err = of_mdiobus_register(bus, np);
2387 2388 2389
	else
		err = mdiobus_register(bus);
	if (err) {
2390
		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
2391
		mv88e6xxx_g2_irq_mdio_free(chip, bus);
2392
		return err;
2393
	}
2394 2395 2396 2397 2398

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

	return 0;
2401
}
2402

2403 2404 2405 2406 2407
static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
	{ .compatible = "marvell,mv88e6xxx-mdio-external",
	  .data = (void *)true },
	{ },
};
2408

2409 2410 2411 2412 2413 2414 2415 2416 2417
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;

2418 2419 2420
		if (!mdio_bus->external)
			mv88e6xxx_g2_irq_mdio_free(chip, bus);

2421 2422 2423 2424
		mdiobus_unregister(bus);
	}
}

2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448
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);
2449 2450
			if (err) {
				mv88e6xxx_mdios_unregister(chip);
2451
				return err;
2452
			}
2453 2454 2455 2456
		}
	}

	return 0;
2457 2458
}

2459 2460
static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
2461
	struct mv88e6xxx_chip *chip = ds->priv;
2462 2463 2464 2465 2466 2467 2468

	return chip->eeprom_len;
}

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

2472 2473
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
2474

2475 2476
	mutex_lock(&chip->reg_lock);
	err = chip->info->ops->get_eeprom(chip, eeprom, data);
2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489
	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 已提交
2490
	struct mv88e6xxx_chip *chip = ds->priv;
2491 2492
	int err;

2493 2494 2495
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

2496 2497 2498 2499
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

	mutex_lock(&chip->reg_lock);
2500
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
2501 2502 2503 2504 2505
	mutex_unlock(&chip->reg_lock);

	return err;
}

2506
static const struct mv88e6xxx_ops mv88e6085_ops = {
2507
	/* MV88E6XXX_FAMILY_6097 */
2508
	.irl_init_all = mv88e6352_g2_irl_init_all,
2509
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2510 2511
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2512
	.port_set_link = mv88e6xxx_port_set_link,
2513
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2514
	.port_set_speed = mv88e6185_port_set_speed,
2515
	.port_tag_remap = mv88e6095_port_tag_remap,
2516
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2517
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2518
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2519
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2520
	.port_pause_limit = mv88e6097_port_pause_limit,
2521
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2522
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2523
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2524
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2525 2526
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2527
	.stats_get_stats = mv88e6095_stats_get_stats,
2528 2529
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2530
	.watchdog_ops = &mv88e6097_watchdog_ops,
2531
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2532
	.pot_clear = mv88e6xxx_g2_pot_clear,
2533 2534
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2535
	.reset = mv88e6185_g1_reset,
2536
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2537
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2538
	.serdes_power = mv88e6341_serdes_power,
2539 2540 2541
};

static const struct mv88e6xxx_ops mv88e6095_ops = {
2542
	/* MV88E6XXX_FAMILY_6095 */
2543
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2544 2545
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2546
	.port_set_link = mv88e6xxx_port_set_link,
2547
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2548
	.port_set_speed = mv88e6185_port_set_speed,
2549
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2550
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2551
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2552
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2553
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2554 2555
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2556
	.stats_get_stats = mv88e6095_stats_get_stats,
2557
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2558 2559
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2560
	.reset = mv88e6185_g1_reset,
2561
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2562
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2563 2564
};

2565
static const struct mv88e6xxx_ops mv88e6097_ops = {
2566
	/* MV88E6XXX_FAMILY_6097 */
2567
	.irl_init_all = mv88e6352_g2_irl_init_all,
2568 2569 2570 2571 2572 2573
	.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,
2574
	.port_tag_remap = mv88e6095_port_tag_remap,
2575
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2576
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2577
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2578
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2579
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
2580
	.port_pause_limit = mv88e6097_port_pause_limit,
2581
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2582
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2583
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2584
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2585 2586 2587
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
	.stats_get_stats = mv88e6095_stats_get_stats,
2588 2589
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2590
	.watchdog_ops = &mv88e6097_watchdog_ops,
2591
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2592
	.pot_clear = mv88e6xxx_g2_pot_clear,
2593
	.reset = mv88e6352_g1_reset,
2594
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2595
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2596 2597
};

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

static const struct mv88e6xxx_ops mv88e6131_ops = {
2627
	/* MV88E6XXX_FAMILY_6185 */
2628
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2629 2630
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2631
	.port_set_link = mv88e6xxx_port_set_link,
2632
	.port_set_duplex = mv88e6xxx_port_set_duplex,
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 = mv88e6185_port_set_egress_floods,
2637
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2638
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2639
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2640
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2641
	.port_pause_limit = mv88e6097_port_pause_limit,
2642
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2643
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2644 2645
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2646
	.stats_get_stats = mv88e6095_stats_get_stats,
2647 2648
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2649
	.watchdog_ops = &mv88e6097_watchdog_ops,
2650
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2651
	.ppu_enable = mv88e6185_g1_ppu_enable,
2652
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
2653
	.ppu_disable = mv88e6185_g1_ppu_disable,
2654
	.reset = mv88e6185_g1_reset,
2655
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2656
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2657 2658
};

2659 2660
static const struct mv88e6xxx_ops mv88e6141_ops = {
	/* MV88E6XXX_FAMILY_6341 */
2661
	.irl_init_all = mv88e6352_g2_irl_init_all,
2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674
	.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,
2675
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2676
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2677
	.port_pause_limit = mv88e6097_port_pause_limit,
2678 2679 2680
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
2681
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2682 2683 2684
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
2685 2686
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
2687 2688
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
2689
	.pot_clear = mv88e6xxx_g2_pot_clear,
2690
	.reset = mv88e6352_g1_reset,
2691
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2692
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2693
	.gpio_ops = &mv88e6352_gpio_ops,
2694 2695
};

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

static const struct mv88e6xxx_ops mv88e6165_ops = {
2730
	/* MV88E6XXX_FAMILY_6165 */
2731
	.irl_init_all = mv88e6352_g2_irl_init_all,
2732
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2733 2734
	.phy_read = mv88e6165_phy_read,
	.phy_write = mv88e6165_phy_write,
2735
	.port_set_link = mv88e6xxx_port_set_link,
2736
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2737
	.port_set_speed = mv88e6185_port_set_speed,
2738
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2739
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2740
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2741
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2742 2743
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2744
	.stats_get_stats = mv88e6095_stats_get_stats,
2745 2746
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2747
	.watchdog_ops = &mv88e6097_watchdog_ops,
2748
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2749
	.pot_clear = mv88e6xxx_g2_pot_clear,
2750
	.reset = mv88e6352_g1_reset,
2751
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2752
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2753 2754 2755
};

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

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

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

static const struct mv88e6xxx_ops mv88e6176_ops = {
2863
	/* MV88E6XXX_FAMILY_6352 */
2864
	.irl_init_all = mv88e6352_g2_irl_init_all,
2865 2866
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
2867
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2868 2869
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2870
	.port_set_link = mv88e6xxx_port_set_link,
2871
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2872
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
2873
	.port_set_speed = mv88e6352_port_set_speed,
2874
	.port_tag_remap = mv88e6095_port_tag_remap,
2875
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2876
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2877
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2878
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2879
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2880
	.port_pause_limit = mv88e6097_port_pause_limit,
2881
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2882
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2883
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2884
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2885 2886
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2887
	.stats_get_stats = mv88e6095_stats_get_stats,
2888 2889
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2890
	.watchdog_ops = &mv88e6097_watchdog_ops,
2891
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2892
	.pot_clear = mv88e6xxx_g2_pot_clear,
2893
	.reset = mv88e6352_g1_reset,
2894
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2895
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2896
	.serdes_power = mv88e6352_serdes_power,
2897
	.gpio_ops = &mv88e6352_gpio_ops,
2898 2899 2900
};

static const struct mv88e6xxx_ops mv88e6185_ops = {
2901
	/* MV88E6XXX_FAMILY_6185 */
2902
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2903 2904
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2905
	.port_set_link = mv88e6xxx_port_set_link,
2906
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2907
	.port_set_speed = mv88e6185_port_set_speed,
2908
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2909
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2910
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
2911
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2912
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2913
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2914 2915
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2916
	.stats_get_stats = mv88e6095_stats_get_stats,
2917 2918
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2919
	.watchdog_ops = &mv88e6097_watchdog_ops,
2920
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2921
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
2922 2923
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2924
	.reset = mv88e6185_g1_reset,
2925
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2926
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2927 2928
};

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

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

static const struct mv88e6xxx_ops mv88e6191_ops = {
3002
	/* MV88E6XXX_FAMILY_6390 */
3003
	.irl_init_all = mv88e6390_g2_irl_init_all,
3004 3005
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3006 3007 3008 3009 3010 3011 3012
	.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,
3013
	.port_tag_remap = mv88e6390_port_tag_remap,
3014
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3015
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3016
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3017
	.port_pause_limit = mv88e6390_port_pause_limit,
3018
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3019
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3020
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3021
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3022 3023
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3024
	.stats_get_stats = mv88e6390_stats_get_stats,
3025 3026
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3027
	.watchdog_ops = &mv88e6390_watchdog_ops,
3028
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3029
	.pot_clear = mv88e6xxx_g2_pot_clear,
3030
	.reset = mv88e6352_g1_reset,
3031 3032
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3033
	.serdes_power = mv88e6390_serdes_power,
3034 3035
};

3036
static const struct mv88e6xxx_ops mv88e6240_ops = {
3037
	/* MV88E6XXX_FAMILY_6352 */
3038
	.irl_init_all = mv88e6352_g2_irl_init_all,
3039 3040
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3041
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3042 3043
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3044
	.port_set_link = mv88e6xxx_port_set_link,
3045
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3046
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3047
	.port_set_speed = mv88e6352_port_set_speed,
3048
	.port_tag_remap = mv88e6095_port_tag_remap,
3049
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3050
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3051
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3052
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3053
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3054
	.port_pause_limit = mv88e6097_port_pause_limit,
3055
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3056
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3057
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3058
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3059 3060
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3061
	.stats_get_stats = mv88e6095_stats_get_stats,
3062 3063
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3064
	.watchdog_ops = &mv88e6097_watchdog_ops,
3065
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3066
	.pot_clear = mv88e6xxx_g2_pot_clear,
3067
	.reset = mv88e6352_g1_reset,
3068
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3069
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3070
	.serdes_power = mv88e6352_serdes_power,
3071
	.gpio_ops = &mv88e6352_gpio_ops,
3072
	.avb_ops = &mv88e6352_avb_ops,
3073 3074
};

3075
static const struct mv88e6xxx_ops mv88e6290_ops = {
3076
	/* MV88E6XXX_FAMILY_6390 */
3077
	.irl_init_all = mv88e6390_g2_irl_init_all,
3078 3079
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3080 3081 3082 3083 3084 3085 3086
	.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,
3087
	.port_tag_remap = mv88e6390_port_tag_remap,
3088
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3089
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3090
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3091
	.port_pause_limit = mv88e6390_port_pause_limit,
3092
	.port_set_cmode = mv88e6390x_port_set_cmode,
3093
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3094
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3095
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3096
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3097 3098
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3099
	.stats_get_stats = mv88e6390_stats_get_stats,
3100 3101
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3102
	.watchdog_ops = &mv88e6390_watchdog_ops,
3103
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3104
	.pot_clear = mv88e6xxx_g2_pot_clear,
3105
	.reset = mv88e6352_g1_reset,
3106 3107
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3108
	.serdes_power = mv88e6390_serdes_power,
3109
	.gpio_ops = &mv88e6352_gpio_ops,
3110
	.avb_ops = &mv88e6390_avb_ops,
3111 3112
};

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

static const struct mv88e6xxx_ops mv88e6321_ops = {
3150
	/* MV88E6XXX_FAMILY_6320 */
3151
	.irl_init_all = mv88e6352_g2_irl_init_all,
3152 3153
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3154
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3155 3156
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3157
	.port_set_link = mv88e6xxx_port_set_link,
3158
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3159
	.port_set_speed = mv88e6185_port_set_speed,
3160
	.port_tag_remap = mv88e6095_port_tag_remap,
3161
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3162
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3163
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3164
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3165
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3166
	.port_pause_limit = mv88e6097_port_pause_limit,
3167
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3168
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3169
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3170
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3171 3172
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3173
	.stats_get_stats = mv88e6320_stats_get_stats,
3174 3175
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3176
	.reset = mv88e6352_g1_reset,
3177
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3178
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3179
	.gpio_ops = &mv88e6352_gpio_ops,
3180
	.avb_ops = &mv88e6352_avb_ops,
3181 3182
};

3183 3184
static const struct mv88e6xxx_ops mv88e6341_ops = {
	/* MV88E6XXX_FAMILY_6341 */
3185
	.irl_init_all = mv88e6352_g2_irl_init_all,
3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198
	.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,
3199
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3200
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3201
	.port_pause_limit = mv88e6097_port_pause_limit,
3202 3203 3204
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3205
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3206 3207 3208
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
3209 3210
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3211 3212
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
3213
	.pot_clear = mv88e6xxx_g2_pot_clear,
3214
	.reset = mv88e6352_g1_reset,
3215
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3216
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3217
	.gpio_ops = &mv88e6352_gpio_ops,
3218
	.avb_ops = &mv88e6390_avb_ops,
3219 3220
};

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

static const struct mv88e6xxx_ops mv88e6351_ops = {
3256
	/* MV88E6XXX_FAMILY_6351 */
3257
	.irl_init_all = mv88e6352_g2_irl_init_all,
3258
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3259 3260
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3261
	.port_set_link = mv88e6xxx_port_set_link,
3262
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3263
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3264
	.port_set_speed = mv88e6185_port_set_speed,
3265
	.port_tag_remap = mv88e6095_port_tag_remap,
3266
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3267
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3268
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3269
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3270
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3271
	.port_pause_limit = mv88e6097_port_pause_limit,
3272
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3273
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3274
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3275
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3276 3277
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3278
	.stats_get_stats = mv88e6095_stats_get_stats,
3279 3280
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3281
	.watchdog_ops = &mv88e6097_watchdog_ops,
3282
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3283
	.pot_clear = mv88e6xxx_g2_pot_clear,
3284
	.reset = mv88e6352_g1_reset,
3285
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3286
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3287
	.avb_ops = &mv88e6352_avb_ops,
3288 3289 3290
};

static const struct mv88e6xxx_ops mv88e6352_ops = {
3291
	/* MV88E6XXX_FAMILY_6352 */
3292
	.irl_init_all = mv88e6352_g2_irl_init_all,
3293 3294
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3295
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3296 3297
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3298
	.port_set_link = mv88e6xxx_port_set_link,
3299
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3300
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3301
	.port_set_speed = mv88e6352_port_set_speed,
3302
	.port_tag_remap = mv88e6095_port_tag_remap,
3303
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3304
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3305
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3306
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3307
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3308
	.port_pause_limit = mv88e6097_port_pause_limit,
3309
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3310
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3311
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3312
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3313 3314
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3315
	.stats_get_stats = mv88e6095_stats_get_stats,
3316 3317
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3318
	.watchdog_ops = &mv88e6097_watchdog_ops,
3319
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3320
	.pot_clear = mv88e6xxx_g2_pot_clear,
3321
	.reset = mv88e6352_g1_reset,
3322
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3323
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3324
	.serdes_power = mv88e6352_serdes_power,
3325
	.gpio_ops = &mv88e6352_gpio_ops,
3326
	.avb_ops = &mv88e6352_avb_ops,
3327 3328 3329
	.serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
	.serdes_get_strings = mv88e6352_serdes_get_strings,
	.serdes_get_stats = mv88e6352_serdes_get_stats,
3330 3331
};

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

static const struct mv88e6xxx_ops mv88e6390x_ops = {
3373
	/* MV88E6XXX_FAMILY_6390 */
3374
	.irl_init_all = mv88e6390_g2_irl_init_all,
3375 3376
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3377 3378 3379 3380 3381 3382 3383
	.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,
3384
	.port_tag_remap = mv88e6390_port_tag_remap,
3385
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3386
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3387
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3388
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3389
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3390
	.port_pause_limit = mv88e6390_port_pause_limit,
3391
	.port_set_cmode = mv88e6390x_port_set_cmode,
3392
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3393
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3394
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3395
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3396 3397
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3398
	.stats_get_stats = mv88e6390_stats_get_stats,
3399 3400
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3401
	.watchdog_ops = &mv88e6390_watchdog_ops,
3402
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3403
	.pot_clear = mv88e6xxx_g2_pot_clear,
3404
	.reset = mv88e6352_g1_reset,
3405 3406
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3407
	.serdes_power = mv88e6390_serdes_power,
3408
	.gpio_ops = &mv88e6352_gpio_ops,
3409
	.avb_ops = &mv88e6390_avb_ops,
3410 3411
};

3412 3413
static const struct mv88e6xxx_info mv88e6xxx_table[] = {
	[MV88E6085] = {
3414
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
3415 3416 3417 3418
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6085",
		.num_databases = 4096,
		.num_ports = 10,
3419
		.num_internal_phys = 5,
3420
		.max_vid = 4095,
3421
		.port_base_addr = 0x10,
3422
		.global1_addr = 0x1b,
3423
		.global2_addr = 0x1c,
3424
		.age_time_coeff = 15000,
3425
		.g1_irqs = 8,
3426
		.g2_irqs = 10,
3427
		.atu_move_port_mask = 0xf,
3428
		.pvt = true,
3429
		.multi_chip = true,
3430
		.tag_protocol = DSA_TAG_PROTO_DSA,
3431
		.ops = &mv88e6085_ops,
3432 3433 3434
	},

	[MV88E6095] = {
3435
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
3436 3437 3438 3439
		.family = MV88E6XXX_FAMILY_6095,
		.name = "Marvell 88E6095/88E6095F",
		.num_databases = 256,
		.num_ports = 11,
3440
		.num_internal_phys = 0,
3441
		.max_vid = 4095,
3442
		.port_base_addr = 0x10,
3443
		.global1_addr = 0x1b,
3444
		.global2_addr = 0x1c,
3445
		.age_time_coeff = 15000,
3446
		.g1_irqs = 8,
3447
		.atu_move_port_mask = 0xf,
3448
		.multi_chip = true,
3449
		.tag_protocol = DSA_TAG_PROTO_DSA,
3450
		.ops = &mv88e6095_ops,
3451 3452
	},

3453
	[MV88E6097] = {
3454
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
3455 3456 3457 3458
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6097/88E6097F",
		.num_databases = 4096,
		.num_ports = 11,
3459
		.num_internal_phys = 8,
3460
		.max_vid = 4095,
3461 3462
		.port_base_addr = 0x10,
		.global1_addr = 0x1b,
3463
		.global2_addr = 0x1c,
3464
		.age_time_coeff = 15000,
3465
		.g1_irqs = 8,
3466
		.g2_irqs = 10,
3467
		.atu_move_port_mask = 0xf,
3468
		.pvt = true,
3469
		.multi_chip = true,
3470
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3471 3472 3473
		.ops = &mv88e6097_ops,
	},

3474
	[MV88E6123] = {
3475
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
3476 3477 3478 3479
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6123",
		.num_databases = 4096,
		.num_ports = 3,
3480
		.num_internal_phys = 5,
3481
		.max_vid = 4095,
3482
		.port_base_addr = 0x10,
3483
		.global1_addr = 0x1b,
3484
		.global2_addr = 0x1c,
3485
		.age_time_coeff = 15000,
3486
		.g1_irqs = 9,
3487
		.g2_irqs = 10,
3488
		.atu_move_port_mask = 0xf,
3489
		.pvt = true,
3490
		.multi_chip = true,
3491
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3492
		.ops = &mv88e6123_ops,
3493 3494 3495
	},

	[MV88E6131] = {
3496
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
3497 3498 3499 3500
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6131",
		.num_databases = 256,
		.num_ports = 8,
3501
		.num_internal_phys = 0,
3502
		.max_vid = 4095,
3503
		.port_base_addr = 0x10,
3504
		.global1_addr = 0x1b,
3505
		.global2_addr = 0x1c,
3506
		.age_time_coeff = 15000,
3507
		.g1_irqs = 9,
3508
		.atu_move_port_mask = 0xf,
3509
		.multi_chip = true,
3510
		.tag_protocol = DSA_TAG_PROTO_DSA,
3511
		.ops = &mv88e6131_ops,
3512 3513
	},

3514
	[MV88E6141] = {
3515
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
3516
		.family = MV88E6XXX_FAMILY_6341,
3517
		.name = "Marvell 88E6141",
3518 3519
		.num_databases = 4096,
		.num_ports = 6,
3520
		.num_internal_phys = 5,
3521
		.num_gpio = 11,
3522
		.max_vid = 4095,
3523 3524
		.port_base_addr = 0x10,
		.global1_addr = 0x1b,
3525
		.global2_addr = 0x1c,
3526 3527
		.age_time_coeff = 3750,
		.atu_move_port_mask = 0x1f,
3528
		.g1_irqs = 9,
3529
		.g2_irqs = 10,
3530
		.pvt = true,
3531
		.multi_chip = true,
3532 3533 3534 3535
		.tag_protocol = DSA_TAG_PROTO_EDSA,
		.ops = &mv88e6141_ops,
	},

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

	[MV88E6165] = {
3558
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
3559 3560 3561 3562
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6165",
		.num_databases = 4096,
		.num_ports = 6,
3563
		.num_internal_phys = 0,
3564
		.max_vid = 4095,
3565
		.port_base_addr = 0x10,
3566
		.global1_addr = 0x1b,
3567
		.global2_addr = 0x1c,
3568
		.age_time_coeff = 15000,
3569
		.g1_irqs = 9,
3570
		.g2_irqs = 10,
3571
		.atu_move_port_mask = 0xf,
3572
		.pvt = true,
3573
		.multi_chip = true,
3574
		.tag_protocol = DSA_TAG_PROTO_DSA,
3575
		.ops = &mv88e6165_ops,
3576 3577 3578
	},

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

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

	[MV88E6175] = {
3622
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
3623 3624 3625 3626
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6175",
		.num_databases = 4096,
		.num_ports = 7,
3627
		.num_internal_phys = 5,
3628
		.max_vid = 4095,
3629
		.port_base_addr = 0x10,
3630
		.global1_addr = 0x1b,
3631
		.global2_addr = 0x1c,
3632
		.age_time_coeff = 15000,
3633
		.g1_irqs = 9,
3634
		.g2_irqs = 10,
3635
		.atu_move_port_mask = 0xf,
3636
		.pvt = true,
3637
		.multi_chip = true,
3638
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3639
		.ops = &mv88e6175_ops,
3640 3641 3642
	},

	[MV88E6176] = {
3643
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
3644 3645 3646 3647
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6176",
		.num_databases = 4096,
		.num_ports = 7,
3648
		.num_internal_phys = 5,
3649
		.num_gpio = 15,
3650
		.max_vid = 4095,
3651
		.port_base_addr = 0x10,
3652
		.global1_addr = 0x1b,
3653
		.global2_addr = 0x1c,
3654
		.age_time_coeff = 15000,
3655
		.g1_irqs = 9,
3656
		.g2_irqs = 10,
3657
		.atu_move_port_mask = 0xf,
3658
		.pvt = true,
3659
		.multi_chip = true,
3660
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3661
		.ops = &mv88e6176_ops,
3662 3663 3664
	},

	[MV88E6185] = {
3665
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
3666 3667 3668 3669
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6185",
		.num_databases = 256,
		.num_ports = 10,
3670
		.num_internal_phys = 0,
3671
		.max_vid = 4095,
3672
		.port_base_addr = 0x10,
3673
		.global1_addr = 0x1b,
3674
		.global2_addr = 0x1c,
3675
		.age_time_coeff = 15000,
3676
		.g1_irqs = 8,
3677
		.atu_move_port_mask = 0xf,
3678
		.multi_chip = true,
3679
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3680
		.ops = &mv88e6185_ops,
3681 3682
	},

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

	[MV88E6190X] = {
3706
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
3707 3708 3709 3710
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3711
		.num_internal_phys = 11,
3712
		.num_gpio = 16,
3713
		.max_vid = 8191,
3714 3715
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3716
		.global2_addr = 0x1c,
3717
		.age_time_coeff = 3750,
3718
		.g1_irqs = 9,
3719
		.g2_irqs = 14,
3720
		.atu_move_port_mask = 0x1f,
3721
		.pvt = true,
3722
		.multi_chip = true,
3723
		.tag_protocol = DSA_TAG_PROTO_DSA,
3724 3725 3726 3727
		.ops = &mv88e6190x_ops,
	},

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

3749
	[MV88E6240] = {
3750
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
3751 3752 3753 3754
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6240",
		.num_databases = 4096,
		.num_ports = 7,
3755
		.num_internal_phys = 5,
3756
		.num_gpio = 15,
3757
		.max_vid = 4095,
3758
		.port_base_addr = 0x10,
3759
		.global1_addr = 0x1b,
3760
		.global2_addr = 0x1c,
3761
		.age_time_coeff = 15000,
3762
		.g1_irqs = 9,
3763
		.g2_irqs = 10,
3764
		.atu_move_port_mask = 0xf,
3765
		.pvt = true,
3766
		.multi_chip = true,
3767
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3768
		.ptp_support = true,
3769
		.ops = &mv88e6240_ops,
3770 3771
	},

3772
	[MV88E6290] = {
3773
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
3774 3775 3776 3777
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6290",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3778
		.num_internal_phys = 11,
3779
		.num_gpio = 16,
3780
		.max_vid = 8191,
3781 3782
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3783
		.global2_addr = 0x1c,
3784
		.age_time_coeff = 3750,
3785
		.g1_irqs = 9,
3786
		.g2_irqs = 14,
3787
		.atu_move_port_mask = 0x1f,
3788
		.pvt = true,
3789
		.multi_chip = true,
3790
		.tag_protocol = DSA_TAG_PROTO_DSA,
3791
		.ptp_support = true,
3792 3793 3794
		.ops = &mv88e6290_ops,
	},

3795
	[MV88E6320] = {
3796
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
3797 3798 3799 3800
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6320",
		.num_databases = 4096,
		.num_ports = 7,
3801
		.num_internal_phys = 5,
3802
		.num_gpio = 15,
3803
		.max_vid = 4095,
3804
		.port_base_addr = 0x10,
3805
		.global1_addr = 0x1b,
3806
		.global2_addr = 0x1c,
3807
		.age_time_coeff = 15000,
3808
		.g1_irqs = 8,
3809
		.g2_irqs = 10,
3810
		.atu_move_port_mask = 0xf,
3811
		.pvt = true,
3812
		.multi_chip = true,
3813
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3814
		.ptp_support = true,
3815
		.ops = &mv88e6320_ops,
3816 3817 3818
	},

	[MV88E6321] = {
3819
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
3820 3821 3822 3823
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6321",
		.num_databases = 4096,
		.num_ports = 7,
3824
		.num_internal_phys = 5,
3825
		.num_gpio = 15,
3826
		.max_vid = 4095,
3827
		.port_base_addr = 0x10,
3828
		.global1_addr = 0x1b,
3829
		.global2_addr = 0x1c,
3830
		.age_time_coeff = 15000,
3831
		.g1_irqs = 8,
3832
		.g2_irqs = 10,
3833
		.atu_move_port_mask = 0xf,
3834
		.multi_chip = true,
3835
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3836
		.ptp_support = true,
3837
		.ops = &mv88e6321_ops,
3838 3839
	},

3840
	[MV88E6341] = {
3841
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
3842 3843 3844
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
3845
		.num_internal_phys = 5,
3846
		.num_ports = 6,
3847
		.num_gpio = 11,
3848
		.max_vid = 4095,
3849 3850
		.port_base_addr = 0x10,
		.global1_addr = 0x1b,
3851
		.global2_addr = 0x1c,
3852
		.age_time_coeff = 3750,
3853
		.atu_move_port_mask = 0x1f,
3854
		.g1_irqs = 9,
3855
		.g2_irqs = 10,
3856
		.pvt = true,
3857
		.multi_chip = true,
3858
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3859
		.ptp_support = true,
3860 3861 3862
		.ops = &mv88e6341_ops,
	},

3863
	[MV88E6350] = {
3864
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
3865 3866 3867 3868
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6350",
		.num_databases = 4096,
		.num_ports = 7,
3869
		.num_internal_phys = 5,
3870
		.max_vid = 4095,
3871
		.port_base_addr = 0x10,
3872
		.global1_addr = 0x1b,
3873
		.global2_addr = 0x1c,
3874
		.age_time_coeff = 15000,
3875
		.g1_irqs = 9,
3876
		.g2_irqs = 10,
3877
		.atu_move_port_mask = 0xf,
3878
		.pvt = true,
3879
		.multi_chip = true,
3880
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3881
		.ops = &mv88e6350_ops,
3882 3883 3884
	},

	[MV88E6351] = {
3885
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
3886 3887 3888 3889
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6351",
		.num_databases = 4096,
		.num_ports = 7,
3890
		.num_internal_phys = 5,
3891
		.max_vid = 4095,
3892
		.port_base_addr = 0x10,
3893
		.global1_addr = 0x1b,
3894
		.global2_addr = 0x1c,
3895
		.age_time_coeff = 15000,
3896
		.g1_irqs = 9,
3897
		.g2_irqs = 10,
3898
		.atu_move_port_mask = 0xf,
3899
		.pvt = true,
3900
		.multi_chip = true,
3901
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3902
		.ops = &mv88e6351_ops,
3903 3904 3905
	},

	[MV88E6352] = {
3906
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
3907 3908 3909 3910
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6352",
		.num_databases = 4096,
		.num_ports = 7,
3911
		.num_internal_phys = 5,
3912
		.num_gpio = 15,
3913
		.max_vid = 4095,
3914
		.port_base_addr = 0x10,
3915
		.global1_addr = 0x1b,
3916
		.global2_addr = 0x1c,
3917
		.age_time_coeff = 15000,
3918
		.g1_irqs = 9,
3919
		.g2_irqs = 10,
3920
		.atu_move_port_mask = 0xf,
3921
		.pvt = true,
3922
		.multi_chip = true,
3923
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3924
		.ptp_support = true,
3925
		.ops = &mv88e6352_ops,
3926
	},
3927
	[MV88E6390] = {
3928
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
3929 3930 3931 3932
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3933
		.num_internal_phys = 11,
3934
		.num_gpio = 16,
3935
		.max_vid = 8191,
3936 3937
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3938
		.global2_addr = 0x1c,
3939
		.age_time_coeff = 3750,
3940
		.g1_irqs = 9,
3941
		.g2_irqs = 14,
3942
		.atu_move_port_mask = 0x1f,
3943
		.pvt = true,
3944
		.multi_chip = true,
3945
		.tag_protocol = DSA_TAG_PROTO_DSA,
3946
		.ptp_support = true,
3947 3948 3949
		.ops = &mv88e6390_ops,
	},
	[MV88E6390X] = {
3950
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
3951 3952 3953 3954
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3955
		.num_internal_phys = 11,
3956
		.num_gpio = 16,
3957
		.max_vid = 8191,
3958 3959
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3960
		.global2_addr = 0x1c,
3961
		.age_time_coeff = 3750,
3962
		.g1_irqs = 9,
3963
		.g2_irqs = 14,
3964
		.atu_move_port_mask = 0x1f,
3965
		.pvt = true,
3966
		.multi_chip = true,
3967
		.tag_protocol = DSA_TAG_PROTO_DSA,
3968
		.ptp_support = true,
3969 3970
		.ops = &mv88e6390x_ops,
	},
3971 3972
};

3973
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
3974
{
3975
	int i;
3976

3977 3978 3979
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
3980 3981 3982 3983

	return NULL;
}

3984
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
3985 3986
{
	const struct mv88e6xxx_info *info;
3987 3988 3989
	unsigned int prod_num, rev;
	u16 id;
	int err;
3990

3991
	mutex_lock(&chip->reg_lock);
3992
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
3993 3994 3995
	mutex_unlock(&chip->reg_lock);
	if (err)
		return err;
3996

3997 3998
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
3999 4000 4001 4002 4003

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

4004
	/* Update the compatible info with the probed one */
4005
	chip->info = info;
4006

4007 4008 4009 4010
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

4011 4012
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
4013 4014 4015 4016

	return 0;
}

4017
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
4018
{
4019
	struct mv88e6xxx_chip *chip;
4020

4021 4022
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
4023 4024
		return NULL;

4025
	chip->dev = dev;
4026

4027
	mutex_init(&chip->reg_lock);
4028
	INIT_LIST_HEAD(&chip->mdios);
4029

4030
	return chip;
4031 4032
}

4033
static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
4034 4035
			      struct mii_bus *bus, int sw_addr)
{
4036
	if (sw_addr == 0)
4037
		chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
4038
	else if (chip->info->multi_chip)
4039
		chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
4040 4041 4042
	else
		return -EINVAL;

4043 4044
	chip->bus = bus;
	chip->sw_addr = sw_addr;
4045 4046 4047 4048

	return 0;
}

4049 4050
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
							int port)
4051
{
V
Vivien Didelot 已提交
4052
	struct mv88e6xxx_chip *chip = ds->priv;
4053

4054
	return chip->info->tag_protocol;
4055 4056
}

4057
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
4058 4059 4060
static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
				       struct device *host_dev, int sw_addr,
				       void **priv)
4061
{
4062
	struct mv88e6xxx_chip *chip;
4063
	struct mii_bus *bus;
4064
	int err;
4065

4066
	bus = dsa_host_dev_to_mii_bus(host_dev);
4067 4068 4069
	if (!bus)
		return NULL;

4070 4071
	chip = mv88e6xxx_alloc_chip(dsa_dev);
	if (!chip)
4072 4073
		return NULL;

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

4077
	err = mv88e6xxx_smi_init(chip, bus, sw_addr);
4078 4079 4080
	if (err)
		goto free;

4081
	err = mv88e6xxx_detect(chip);
4082
	if (err)
4083
		goto free;
4084

4085 4086 4087 4088 4089 4090
	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_switch_reset(chip);
	mutex_unlock(&chip->reg_lock);
	if (err)
		goto free;

4091 4092
	mv88e6xxx_phy_init(chip);

4093
	err = mv88e6xxx_mdios_register(chip, NULL);
4094
	if (err)
4095
		goto free;
4096

4097
	*priv = chip;
4098

4099
	return chip->info->name;
4100
free:
4101
	devm_kfree(dsa_dev, chip);
4102 4103

	return NULL;
4104
}
4105
#endif
4106

4107
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4108
				      const struct switchdev_obj_port_mdb *mdb)
4109 4110 4111 4112 4113 4114 4115 4116 4117
{
	/* 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,
4118
				   const struct switchdev_obj_port_mdb *mdb)
4119
{
V
Vivien Didelot 已提交
4120
	struct mv88e6xxx_chip *chip = ds->priv;
4121 4122 4123

	mutex_lock(&chip->reg_lock);
	if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4124
					 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
4125 4126
		dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
			port);
4127 4128 4129 4130 4131 4132
	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 已提交
4133
	struct mv88e6xxx_chip *chip = ds->priv;
4134 4135 4136 4137
	int err;

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4138
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
4139 4140 4141 4142 4143
	mutex_unlock(&chip->reg_lock);

	return err;
}

4144
static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
4145
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
4146
	.probe			= mv88e6xxx_drv_probe,
4147
#endif
4148
	.get_tag_protocol	= mv88e6xxx_get_tag_protocol,
4149 4150 4151 4152 4153
	.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,
4154 4155
	.port_enable		= mv88e6xxx_port_enable,
	.port_disable		= mv88e6xxx_port_disable,
V
Vivien Didelot 已提交
4156 4157
	.get_mac_eee		= mv88e6xxx_get_mac_eee,
	.set_mac_eee		= mv88e6xxx_set_mac_eee,
4158
	.get_eeprom_len		= mv88e6xxx_get_eeprom_len,
4159 4160 4161 4162
	.get_eeprom		= mv88e6xxx_get_eeprom,
	.set_eeprom		= mv88e6xxx_set_eeprom,
	.get_regs_len		= mv88e6xxx_get_regs_len,
	.get_regs		= mv88e6xxx_get_regs,
4163
	.set_ageing_time	= mv88e6xxx_set_ageing_time,
4164 4165 4166
	.port_bridge_join	= mv88e6xxx_port_bridge_join,
	.port_bridge_leave	= mv88e6xxx_port_bridge_leave,
	.port_stp_state_set	= mv88e6xxx_port_stp_state_set,
4167
	.port_fast_age		= mv88e6xxx_port_fast_age,
4168 4169 4170 4171 4172 4173 4174
	.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,
4175 4176 4177
	.port_mdb_prepare       = mv88e6xxx_port_mdb_prepare,
	.port_mdb_add           = mv88e6xxx_port_mdb_add,
	.port_mdb_del           = mv88e6xxx_port_mdb_del,
4178 4179
	.crosschip_bridge_join	= mv88e6xxx_crosschip_bridge_join,
	.crosschip_bridge_leave	= mv88e6xxx_crosschip_bridge_leave,
4180 4181 4182 4183 4184
	.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,
4185 4186
};

4187 4188 4189 4190
static struct dsa_switch_driver mv88e6xxx_switch_drv = {
	.ops			= &mv88e6xxx_switch_ops,
};

4191
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
4192
{
4193
	struct device *dev = chip->dev;
4194 4195
	struct dsa_switch *ds;

4196
	ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
4197 4198 4199
	if (!ds)
		return -ENOMEM;

4200
	ds->priv = chip;
4201
	ds->ops = &mv88e6xxx_switch_ops;
4202 4203
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
4204 4205 4206

	dev_set_drvdata(dev, ds);

4207
	return dsa_register_switch(ds);
4208 4209
}

4210
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
4211
{
4212
	dsa_unregister_switch(chip->ds);
4213 4214
}

4215
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
4216
{
4217
	struct device *dev = &mdiodev->dev;
4218
	struct device_node *np = dev->of_node;
4219
	const struct mv88e6xxx_info *compat_info;
4220
	struct mv88e6xxx_chip *chip;
4221
	u32 eeprom_len;
4222
	int err;
4223

4224 4225 4226 4227
	compat_info = of_device_get_match_data(dev);
	if (!compat_info)
		return -EINVAL;

4228 4229
	chip = mv88e6xxx_alloc_chip(dev);
	if (!chip)
4230 4231
		return -ENOMEM;

4232
	chip->info = compat_info;
4233

4234
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
4235 4236
	if (err)
		return err;
4237

4238 4239 4240 4241
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
	if (IS_ERR(chip->reset))
		return PTR_ERR(chip->reset);

4242
	err = mv88e6xxx_detect(chip);
4243 4244
	if (err)
		return err;
4245

4246 4247
	mv88e6xxx_phy_init(chip);

4248
	if (chip->info->ops->get_eeprom &&
4249
	    !of_property_read_u32(np, "eeprom-length", &eeprom_len))
4250
		chip->eeprom_len = eeprom_len;
4251

4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263
	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;
	}

4264
	/* Has to be performed before the MDIO bus is created, because
4265
	 * the PHYs will link their interrupts to these interrupt
4266 4267 4268 4269
	 * controllers
	 */
	mutex_lock(&chip->reg_lock);
	if (chip->irq > 0)
4270
		err = mv88e6xxx_g1_irq_setup(chip);
4271 4272 4273
	else
		err = mv88e6xxx_irq_poll_setup(chip);
	mutex_unlock(&chip->reg_lock);
4274

4275 4276
	if (err)
		goto out;
4277

4278 4279
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
4280
		if (err)
4281
			goto out_g1_irq;
4282 4283
	}

4284 4285 4286 4287 4288 4289 4290 4291
	err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
	if (err)
		goto out_g2_irq;

	err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
	if (err)
		goto out_g1_atu_prob_irq;

4292
	err = mv88e6xxx_mdios_register(chip, np);
4293
	if (err)
4294
		goto out_g1_vtu_prob_irq;
4295

4296
	err = mv88e6xxx_register_switch(chip);
4297 4298
	if (err)
		goto out_mdio;
4299

4300
	return 0;
4301 4302

out_mdio:
4303
	mv88e6xxx_mdios_unregister(chip);
4304
out_g1_vtu_prob_irq:
4305
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
4306
out_g1_atu_prob_irq:
4307
	mv88e6xxx_g1_atu_prob_irq_free(chip);
4308
out_g2_irq:
4309
	if (chip->info->g2_irqs > 0)
4310 4311
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
4312 4313
	mutex_lock(&chip->reg_lock);
	if (chip->irq > 0)
4314
		mv88e6xxx_g1_irq_free(chip);
4315 4316 4317
	else
		mv88e6xxx_irq_poll_free(chip);
	mutex_unlock(&chip->reg_lock);
4318 4319
out:
	return err;
4320
}
4321 4322 4323 4324

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

4327 4328
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
4329
		mv88e6xxx_ptp_free(chip);
4330
	}
4331

4332
	mv88e6xxx_phy_destroy(chip);
4333
	mv88e6xxx_unregister_switch(chip);
4334
	mv88e6xxx_mdios_unregister(chip);
4335

4336 4337 4338 4339 4340 4341 4342 4343
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
	mv88e6xxx_g1_atu_prob_irq_free(chip);

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

	mutex_lock(&chip->reg_lock);
	if (chip->irq > 0)
4344
		mv88e6xxx_g1_irq_free(chip);
4345 4346 4347
	else
		mv88e6xxx_irq_poll_free(chip);
	mutex_unlock(&chip->reg_lock);
4348 4349 4350
}

static const struct of_device_id mv88e6xxx_of_match[] = {
4351 4352 4353 4354
	{
		.compatible = "marvell,mv88e6085",
		.data = &mv88e6xxx_table[MV88E6085],
	},
4355 4356 4357 4358
	{
		.compatible = "marvell,mv88e6190",
		.data = &mv88e6xxx_table[MV88E6190],
	},
4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374
	{ /* 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)
{
4375
	register_switch_driver(&mv88e6xxx_switch_drv);
4376 4377
	return mdio_driver_register(&mv88e6xxx_driver);
}
4378 4379 4380 4381
module_init(mv88e6xxx_init);

static void __exit mv88e6xxx_cleanup(void)
{
4382
	mdio_driver_unregister(&mv88e6xxx_driver);
4383
	unregister_switch_driver(&mv88e6xxx_switch_drv);
4384 4385
}
module_exit(mv88e6xxx_cleanup);
4386 4387 4388 4389

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