chip.c 121.7 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 1059
	err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
	if (err)
		return err;

1060 1061 1062
	return 0;
}

1063 1064 1065 1066 1067 1068 1069 1070 1071
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;
}

1072 1073 1074 1075 1076 1077 1078 1079
static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->pot_clear)
		return chip->info->ops->pot_clear(chip);

	return 0;
}

1080 1081 1082 1083 1084 1085 1086 1087
static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->mgmt_rsvd2cpu)
		return chip->info->ops->mgmt_rsvd2cpu(chip);

	return 0;
}

1088 1089
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
1090 1091
	int err;

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

1096 1097 1098 1099
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

1100 1101 1102
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122
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;
}

1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135
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;
}

1136 1137 1138 1139 1140 1141 1142 1143 1144
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)
1145
		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1146 1147 1148 1149

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

1150 1151
static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
{
1152 1153 1154
	int dev, port;
	int err;

1155 1156 1157 1158 1159 1160
	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.
	 */
1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173
	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;
1174 1175
}

1176 1177 1178 1179 1180 1181
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);
1182
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1183 1184 1185
	mutex_unlock(&chip->reg_lock);

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

1189 1190 1191 1192 1193 1194 1195 1196
static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
{
	if (!chip->info->max_vid)
		return 0;

	return mv88e6xxx_g1_vtu_flush(chip);
}

1197 1198 1199 1200 1201 1202 1203 1204 1205
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);
}

1206 1207 1208 1209 1210 1211 1212 1213 1214
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);
}

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

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

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

		set_bit(*fid, fid_bitmap);
	}

1234 1235
	/* Set every FID bit used by the VLAN entries */
	do {
1236
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1237 1238 1239 1240 1241 1242 1243
		if (err)
			return err;

		if (!vlan.valid)
			break;

		set_bit(vlan.fid, fid_bitmap);
1244
	} while (vlan.vid < chip->info->max_vid);
1245 1246 1247 1248 1249

	/* 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);
1250
	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1251 1252 1253
		return -ENOSPC;

	/* Clear the database */
1254
	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1255 1256
}

1257 1258
static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
			     struct mv88e6xxx_vtu_entry *entry, bool new)
1259 1260 1261 1262 1263 1264
{
	int err;

	if (!vid)
		return -EINVAL;

1265 1266
	entry->vid = vid - 1;
	entry->valid = false;
1267

1268
	err = mv88e6xxx_vtu_getnext(chip, entry);
1269 1270 1271
	if (err)
		return err;

1272 1273
	if (entry->vid == vid && entry->valid)
		return 0;
1274

1275 1276 1277 1278 1279 1280 1281 1282
	if (new) {
		int i;

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

1283
		/* Exclude all ports */
1284
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1285
			entry->member[i] =
1286
				MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1287 1288

		return mv88e6xxx_atu_new(chip, &entry->fid);
1289 1290
	}

1291 1292
	/* switchdev expects -EOPNOTSUPP to honor software VLANs */
	return -EOPNOTSUPP;
1293 1294
}

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

1304 1305 1306 1307
	/* 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;

1308 1309 1310
	if (!vid_begin)
		return -EOPNOTSUPP;

1311
	mutex_lock(&chip->reg_lock);
1312 1313

	do {
1314
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1315 1316 1317 1318 1319 1320 1321 1322 1323
		if (err)
			goto unlock;

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

1324
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1325 1326 1327
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

1328
			if (!ds->ports[i].slave)
1329 1330
				continue;

1331
			if (vlan.member[i] ==
1332
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1333 1334
				continue;

V
Vivien Didelot 已提交
1335
			if (dsa_to_port(ds, i)->bridge_dev ==
1336
			    ds->ports[port].bridge_dev)
1337 1338
				break; /* same bridge, check next VLAN */

V
Vivien Didelot 已提交
1339
			if (!dsa_to_port(ds, i)->bridge_dev)
1340 1341
				continue;

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

unlock:
1351
	mutex_unlock(&chip->reg_lock);
1352 1353 1354 1355

	return err;
}

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

1364
	if (!chip->info->max_vid)
1365 1366
		return -EOPNOTSUPP;

1367
	mutex_lock(&chip->reg_lock);
1368
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1369
	mutex_unlock(&chip->reg_lock);
1370

1371
	return err;
1372 1373
}

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

1381
	if (!chip->info->max_vid)
1382 1383
		return -EOPNOTSUPP;

1384 1385 1386 1387 1388 1389 1390 1391
	/* 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;

1392 1393 1394 1395 1396 1397
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */
	return 0;
}

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 1438 1439 1440 1441
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);
}

1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464
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;
}

1465
static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
1466
				    u16 vid, u8 member)
1467
{
1468
	struct mv88e6xxx_vtu_entry vlan;
1469 1470
	int err;

1471
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
1472
	if (err)
1473
		return err;
1474

1475
	vlan.member[port] = member;
1476

1477 1478 1479 1480 1481
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
	if (err)
		return err;

	return mv88e6xxx_broadcast_setup(chip, vid);
1482 1483
}

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

1493
	if (!chip->info->max_vid)
1494 1495
		return;

1496
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1497
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1498
	else if (untagged)
1499
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
1500
	else
1501
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
1502

1503
	mutex_lock(&chip->reg_lock);
1504

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

1510
	if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1511 1512
		dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
			vlan->vid_end);
1513

1514
	mutex_unlock(&chip->reg_lock);
1515 1516
}

1517
static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
1518
				    int port, u16 vid)
1519
{
1520
	struct mv88e6xxx_vtu_entry vlan;
1521 1522
	int i, err;

1523
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1524
	if (err)
1525
		return err;
1526

1527
	/* Tell switchdev if this VLAN is handled in software */
1528
	if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1529
		return -EOPNOTSUPP;
1530

1531
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1532 1533

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

1543
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1544 1545 1546
	if (err)
		return err;

1547
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
1548 1549
}

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

1557
	if (!chip->info->max_vid)
1558 1559
		return -EOPNOTSUPP;

1560
	mutex_lock(&chip->reg_lock);
1561

1562
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
1563 1564 1565
	if (err)
		goto unlock;

1566
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1567
		err = _mv88e6xxx_port_vlan_del(chip, port, vid);
1568 1569 1570 1571
		if (err)
			goto unlock;

		if (vid == pvid) {
1572
			err = mv88e6xxx_port_set_pvid(chip, port, 0);
1573 1574 1575 1576 1577
			if (err)
				goto unlock;
		}
	}

1578
unlock:
1579
	mutex_unlock(&chip->reg_lock);
1580 1581 1582 1583

	return err;
}

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

1590
	mutex_lock(&chip->reg_lock);
1591 1592
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1593
	mutex_unlock(&chip->reg_lock);
1594 1595

	return err;
1596 1597
}

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

1604
	mutex_lock(&chip->reg_lock);
1605
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1606
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
1607
	mutex_unlock(&chip->reg_lock);
1608

1609
	return err;
1610 1611
}

1612 1613
static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
				      u16 fid, u16 vid, int port,
1614
				      dsa_fdb_dump_cb_t *cb, void *data)
1615
{
1616
	struct mv88e6xxx_atu_entry addr;
1617
	bool is_static;
1618 1619
	int err;

1620
	addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1621
	eth_broadcast_addr(addr.mac);
1622 1623

	do {
1624
		mutex_lock(&chip->reg_lock);
1625
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
1626
		mutex_unlock(&chip->reg_lock);
1627
		if (err)
1628
			return err;
1629

1630
		if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
1631 1632
			break;

1633
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
1634 1635
			continue;

1636 1637
		if (!is_unicast_ether_addr(addr.mac))
			continue;
1638

1639 1640 1641
		is_static = (addr.state ==
			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
		err = cb(addr.mac, vid, is_static, data);
1642 1643
		if (err)
			return err;
1644 1645 1646 1647 1648
	} while (!is_broadcast_ether_addr(addr.mac));

	return err;
}

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

1658
	/* Dump port's default Filtering Information Database (VLAN ID 0) */
1659
	mutex_lock(&chip->reg_lock);
1660
	err = mv88e6xxx_port_get_fid(chip, port, &fid);
1661 1662
	mutex_unlock(&chip->reg_lock);

1663
	if (err)
1664
		return err;
1665

1666
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
1667
	if (err)
1668
		return err;
1669

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

		if (!vlan.valid)
			break;

1681
		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1682
						 cb, data);
1683
		if (err)
1684
			return err;
1685
	} while (vlan.vid < chip->info->max_vid);
1686

1687 1688 1689 1690
	return err;
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1691
				   dsa_fdb_dump_cb_t *cb, void *data)
1692
{
V
Vivien Didelot 已提交
1693
	struct mv88e6xxx_chip *chip = ds->priv;
1694

1695
	return mv88e6xxx_port_db_dump(chip, port, cb, data);
1696 1697
}

1698 1699
static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
				struct net_device *br)
1700
{
1701
	struct dsa_switch *ds;
1702
	int port;
1703
	int dev;
1704
	int err;
1705

1706 1707 1708 1709
	/* 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);
1710
			if (err)
1711
				return err;
1712 1713 1714
		}
	}

1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732
	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;
			}
		}
	}

1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743
	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);
1744
	mutex_unlock(&chip->reg_lock);
1745

1746
	return err;
1747 1748
}

1749 1750
static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
					struct net_device *br)
1751
{
V
Vivien Didelot 已提交
1752
	struct mv88e6xxx_chip *chip = ds->priv;
1753

1754
	mutex_lock(&chip->reg_lock);
1755 1756 1757
	if (mv88e6xxx_bridge_map(chip, br) ||
	    mv88e6xxx_port_vlan_map(chip, port))
		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
1758
	mutex_unlock(&chip->reg_lock);
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 1787 1788 1789 1790
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);
}

1791 1792 1793 1794 1795 1796 1797 1798
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->reset)
		return chip->info->ops->reset(chip);

	return 0;
}

1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811
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);
	}
}

1812
static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1813
{
1814
	int i, err;
1815

1816
	/* Set all ports to the Disabled state */
1817
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
1818
		err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
1819 1820
		if (err)
			return err;
1821 1822
	}

1823 1824 1825
	/* Wait for transmit queues to drain,
	 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
	 */
1826 1827
	usleep_range(2000, 4000);

1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838
	return 0;
}

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

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

1839
	mv88e6xxx_hardware_reset(chip);
1840

1841
	return mv88e6xxx_software_reset(chip);
1842 1843
}

1844
static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
1845 1846
				   enum mv88e6xxx_frame_mode frame,
				   enum mv88e6xxx_egress_mode egress, u16 etype)
1847 1848 1849
{
	int err;

1850 1851 1852 1853
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
1854 1855 1856
	if (err)
		return err;

1857 1858 1859 1860 1861 1862 1863 1864
	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;
1865 1866
}

1867
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1868
{
1869
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
1870
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
1871
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
1872
}
1873

1874 1875 1876
static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
1877
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
1878
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
1879
}
1880

1881 1882 1883 1884
static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port,
				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
1885 1886
				       MV88E6XXX_EGRESS_MODE_ETHERTYPE,
				       ETH_P_EDSA);
1887
}
1888

1889 1890 1891 1892
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);
1893

1894
	if (dsa_is_user_port(chip->ds, port))
1895
		return mv88e6xxx_set_port_mode_normal(chip, port);
1896

1897 1898 1899
	/* 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);
1900

1901 1902
	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
		return mv88e6xxx_set_port_mode_edsa(chip, port);
1903

1904
	return -EINVAL;
1905 1906
}

1907
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
1908
{
1909
	bool message = dsa_is_dsa_port(chip->ds, port);
1910

1911
	return mv88e6xxx_port_set_message_port(chip, port, message);
1912
}
1913

1914
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
1915
{
1916 1917
	struct dsa_switch *ds = chip->ds;
	bool flood;
1918

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

1925
	return 0;
1926 1927
}

1928 1929 1930
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
1931 1932
	if (chip->info->ops->serdes_power)
		return chip->info->ops->serdes_power(chip, port, on);
1933

1934
	return 0;
1935 1936
}

1937 1938 1939 1940 1941 1942
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

1943
	upstream_port = dsa_upstream_port(ds, port);
1944 1945 1946 1947 1948 1949 1950
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966
	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;
		}
	}

1967 1968 1969
	return 0;
}

1970
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
1971
{
1972
	struct dsa_switch *ds = chip->ds;
1973
	int err;
1974
	u16 reg;
1975

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

	/* 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.
	 */
2005 2006 2007 2008
	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);
2009 2010
	if (err)
		return err;
2011

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

2016
	err = mv88e6xxx_setup_egress_floods(chip, port);
2017 2018 2019
	if (err)
		return err;

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

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

2040 2041 2042
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
2043

2044
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
2045
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
2046 2047 2048
	if (err)
		return err;

2049 2050
	if (chip->info->ops->port_set_jumbo_size) {
		err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
2051 2052 2053 2054
		if (err)
			return err;
	}

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

2065 2066
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
2067 2068
	if (err)
		return err;
2069 2070

	/* Egress rate control 2: disable egress rate control. */
2071 2072
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
				   0x0000);
2073 2074
	if (err)
		return err;
2075

2076 2077
	if (chip->info->ops->port_pause_limit) {
		err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
2078 2079
		if (err)
			return err;
2080
	}
2081

2082 2083 2084 2085 2086 2087
	if (chip->info->ops->port_disable_learn_limit) {
		err = chip->info->ops->port_disable_learn_limit(chip, port);
		if (err)
			return err;
	}

2088 2089
	if (chip->info->ops->port_disable_pri_override) {
		err = chip->info->ops->port_disable_pri_override(chip, port);
2090 2091
		if (err)
			return err;
2092
	}
2093

2094 2095
	if (chip->info->ops->port_tag_remap) {
		err = chip->info->ops->port_tag_remap(chip, port);
2096 2097
		if (err)
			return err;
2098 2099
	}

2100 2101
	if (chip->info->ops->port_egress_rate_limiting) {
		err = chip->info->ops->port_egress_rate_limiting(chip, port);
2102 2103
		if (err)
			return err;
2104 2105
	}

2106
	err = mv88e6xxx_setup_message_port(chip, port);
2107 2108
	if (err)
		return err;
2109

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

2118
	err = mv88e6xxx_port_vlan_map(chip, port);
2119 2120
	if (err)
		return err;
2121 2122 2123 2124

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

2128 2129 2130 2131
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
2132
	int err;
2133 2134

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

2152 2153 2154
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
2155
	struct mv88e6xxx_chip *chip = ds->priv;
2156 2157 2158
	int err;

	mutex_lock(&chip->reg_lock);
2159
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2160 2161 2162 2163 2164
	mutex_unlock(&chip->reg_lock);

	return err;
}

2165
static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
2166
{
2167
	int err;
2168 2169

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

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

2200 2201 2202 2203 2204
	/* Initialize the statistics unit */
	err = mv88e6xxx_stats_set_histogram(chip);
	if (err)
		return err;

2205
	return mv88e6xxx_g1_stats_clear(chip);
2206 2207
}

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

2214
	chip->ds = ds;
2215
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
2216

2217
	mutex_lock(&chip->reg_lock);
2218

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

2224 2225 2226 2227 2228 2229 2230
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

	/* Setup Switch Global 1 Registers */
	err = mv88e6xxx_g1_setup(chip);
2231 2232 2233
	if (err)
		goto unlock;

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

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

2242 2243 2244 2245
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

2246 2247 2248 2249
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

2250 2251 2252 2253
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

2254 2255 2256 2257
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

2258 2259 2260 2261
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

2262 2263 2264 2265
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

2266 2267 2268
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
2269

2270 2271 2272 2273
	err = mv88e6xxx_trunk_setup(chip);
	if (err)
		goto unlock;

2274 2275 2276 2277
	err = mv88e6xxx_devmap_setup(chip);
	if (err)
		goto unlock;

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

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
2287 2288
	}

2289
unlock:
2290
	mutex_unlock(&chip->reg_lock);
2291

2292
	return err;
2293 2294
}

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

2302 2303 2304
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

2305
	mutex_lock(&chip->reg_lock);
2306
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
2307
	mutex_unlock(&chip->reg_lock);
2308

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

2317
	return err ? err : val;
2318 2319
}

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

2326 2327 2328
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

2329
	mutex_lock(&chip->reg_lock);
2330
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
2331
	mutex_unlock(&chip->reg_lock);
2332 2333

	return err;
2334 2335
}

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

2345 2346 2347 2348 2349 2350 2351 2352 2353
	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;
	}

2354
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
2355 2356 2357
	if (!bus)
		return -ENOMEM;

2358
	mdio_bus = bus->priv;
2359
	mdio_bus->bus = bus;
2360
	mdio_bus->chip = chip;
2361 2362
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
2363

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

2376 2377 2378 2379 2380 2381
	if (!external) {
		err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
		if (err)
			return err;
	}

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

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

	return 0;
2398
}
2399

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

2406 2407 2408 2409 2410 2411 2412 2413 2414
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;

2415 2416 2417
		if (!mdio_bus->external)
			mv88e6xxx_g2_irq_mdio_free(chip, bus);

2418 2419 2420 2421
		mdiobus_unregister(bus);
	}
}

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

	return 0;
2454 2455
}

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

	return chip->eeprom_len;
}

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

2469 2470
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
2471

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

2490 2491 2492
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

2493 2494 2495 2496
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

	mutex_lock(&chip->reg_lock);
2497
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
2498 2499 2500 2501 2502
	mutex_unlock(&chip->reg_lock);

	return err;
}

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

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

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

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

static const struct mv88e6xxx_ops mv88e6131_ops = {
2624
	/* MV88E6XXX_FAMILY_6185 */
2625
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2626 2627
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2628
	.port_set_link = mv88e6xxx_port_set_link,
2629
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2630
	.port_set_speed = mv88e6185_port_set_speed,
2631
	.port_tag_remap = mv88e6095_port_tag_remap,
2632
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2633
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2634
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2635
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2636
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2637
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2638
	.port_pause_limit = mv88e6097_port_pause_limit,
2639
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2640
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2641 2642
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2643
	.stats_get_stats = mv88e6095_stats_get_stats,
2644 2645
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2646
	.watchdog_ops = &mv88e6097_watchdog_ops,
2647
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2648
	.ppu_enable = mv88e6185_g1_ppu_enable,
2649
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
2650
	.ppu_disable = mv88e6185_g1_ppu_disable,
2651
	.reset = mv88e6185_g1_reset,
2652
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2653
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2654 2655
};

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

3970
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
3971
{
3972
	int i;
3973

3974 3975 3976
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
3977 3978 3979 3980

	return NULL;
}

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

3988
	mutex_lock(&chip->reg_lock);
3989
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
3990 3991 3992
	mutex_unlock(&chip->reg_lock);
	if (err)
		return err;
3993

3994 3995
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
3996 3997 3998 3999 4000

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

4001
	/* Update the compatible info with the probed one */
4002
	chip->info = info;
4003

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

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

	return 0;
}

4014
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
4015
{
4016
	struct mv88e6xxx_chip *chip;
4017

4018 4019
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
4020 4021
		return NULL;

4022
	chip->dev = dev;
4023

4024
	mutex_init(&chip->reg_lock);
4025
	INIT_LIST_HEAD(&chip->mdios);
4026

4027
	return chip;
4028 4029
}

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

4040 4041
	chip->bus = bus;
	chip->sw_addr = sw_addr;
4042 4043 4044 4045

	return 0;
}

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

4051
	return chip->info->tag_protocol;
4052 4053
}

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

4063
	bus = dsa_host_dev_to_mii_bus(host_dev);
4064 4065 4066
	if (!bus)
		return NULL;

4067 4068
	chip = mv88e6xxx_alloc_chip(dsa_dev);
	if (!chip)
4069 4070
		return NULL;

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

4074
	err = mv88e6xxx_smi_init(chip, bus, sw_addr);
4075 4076 4077
	if (err)
		goto free;

4078
	err = mv88e6xxx_detect(chip);
4079
	if (err)
4080
		goto free;
4081

4082 4083 4084 4085 4086 4087
	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_switch_reset(chip);
	mutex_unlock(&chip->reg_lock);
	if (err)
		goto free;

4088 4089
	mv88e6xxx_phy_init(chip);

4090
	err = mv88e6xxx_mdios_register(chip, NULL);
4091
	if (err)
4092
		goto free;
4093

4094
	*priv = chip;
4095

4096
	return chip->info->name;
4097
free:
4098
	devm_kfree(dsa_dev, chip);
4099 4100

	return NULL;
4101
}
4102
#endif
4103

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

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

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4135
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
4136 4137 4138 4139 4140
	mutex_unlock(&chip->reg_lock);

	return err;
}

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

4184 4185 4186 4187
static struct dsa_switch_driver mv88e6xxx_switch_drv = {
	.ops			= &mv88e6xxx_switch_ops,
};

4188
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
4189
{
4190
	struct device *dev = chip->dev;
4191 4192
	struct dsa_switch *ds;

4193
	ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
4194 4195 4196
	if (!ds)
		return -ENOMEM;

4197
	ds->priv = chip;
4198
	ds->ops = &mv88e6xxx_switch_ops;
4199 4200
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
4201 4202 4203

	dev_set_drvdata(dev, ds);

4204
	return dsa_register_switch(ds);
4205 4206
}

4207
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
4208
{
4209
	dsa_unregister_switch(chip->ds);
4210 4211
}

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

4221 4222 4223 4224
	compat_info = of_device_get_match_data(dev);
	if (!compat_info)
		return -EINVAL;

4225 4226
	chip = mv88e6xxx_alloc_chip(dev);
	if (!chip)
4227 4228
		return -ENOMEM;

4229
	chip->info = compat_info;
4230

4231
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
4232 4233
	if (err)
		return err;
4234

4235 4236 4237 4238
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
	if (IS_ERR(chip->reset))
		return PTR_ERR(chip->reset);

4239
	err = mv88e6xxx_detect(chip);
4240 4241
	if (err)
		return err;
4242

4243 4244
	mv88e6xxx_phy_init(chip);

4245
	if (chip->info->ops->get_eeprom &&
4246
	    !of_property_read_u32(np, "eeprom-length", &eeprom_len))
4247
		chip->eeprom_len = eeprom_len;
4248

4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260
	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;
	}

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

4272 4273
	if (err)
		goto out;
4274

4275 4276
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
4277
		if (err)
4278
			goto out_g1_irq;
4279 4280
	}

4281 4282 4283 4284 4285 4286 4287 4288
	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;

4289
	err = mv88e6xxx_mdios_register(chip, np);
4290
	if (err)
4291
		goto out_g1_vtu_prob_irq;
4292

4293
	err = mv88e6xxx_register_switch(chip);
4294 4295
	if (err)
		goto out_mdio;
4296

4297
	return 0;
4298 4299

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

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

4324 4325
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
4326
		mv88e6xxx_ptp_free(chip);
4327
	}
4328

4329
	mv88e6xxx_phy_destroy(chip);
4330
	mv88e6xxx_unregister_switch(chip);
4331
	mv88e6xxx_mdios_unregister(chip);
4332

4333 4334 4335 4336 4337 4338 4339 4340
	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)
4341
		mv88e6xxx_g1_irq_free(chip);
4342 4343 4344
	else
		mv88e6xxx_irq_poll_free(chip);
	mutex_unlock(&chip->reg_lock);
4345 4346 4347
}

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

static void __exit mv88e6xxx_cleanup(void)
{
4379
	mdio_driver_unregister(&mv88e6xxx_driver);
4380
	unregister_switch_driver(&mv88e6xxx_switch_drv);
4381 4382
}
module_exit(mv88e6xxx_cleanup);
4383 4384 4385 4386

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