chip.c 121.1 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
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;
}

1038 1039 1040 1041 1042 1043 1044 1045
static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->pot_clear)
		return chip->info->ops->pot_clear(chip);

	return 0;
}

1046 1047 1048 1049 1050 1051 1052 1053
static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->mgmt_rsvd2cpu)
		return chip->info->ops->mgmt_rsvd2cpu(chip);

	return 0;
}

1054 1055
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
1056 1057
	int err;

1058 1059 1060 1061
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

1062 1063 1064 1065
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

1066 1067 1068
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088
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;
}

1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101
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;
}

1102 1103 1104 1105 1106 1107 1108 1109 1110
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)
1111
		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1112 1113 1114 1115

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

1116 1117
static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
{
1118 1119 1120
	int dev, port;
	int err;

1121 1122 1123 1124 1125 1126
	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.
	 */
1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139
	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;
1140 1141
}

1142 1143 1144 1145 1146 1147
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);
1148
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1149 1150 1151
	mutex_unlock(&chip->reg_lock);

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

1155 1156 1157 1158 1159 1160 1161 1162
static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
{
	if (!chip->info->max_vid)
		return 0;

	return mv88e6xxx_g1_vtu_flush(chip);
}

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

1172 1173 1174 1175 1176 1177 1178 1179 1180
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);
}

1181
static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1182 1183
{
	DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1184 1185 1186
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = chip->info->max_vid,
	};
1187
	int i, err;
1188 1189 1190

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

1191
	/* Set every FID bit used by the (un)bridged ports */
1192
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1193
		err = mv88e6xxx_port_get_fid(chip, i, fid);
1194 1195 1196 1197 1198 1199
		if (err)
			return err;

		set_bit(*fid, fid_bitmap);
	}

1200 1201
	/* Set every FID bit used by the VLAN entries */
	do {
1202
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1203 1204 1205 1206 1207 1208 1209
		if (err)
			return err;

		if (!vlan.valid)
			break;

		set_bit(vlan.fid, fid_bitmap);
1210
	} while (vlan.vid < chip->info->max_vid);
1211 1212 1213 1214 1215

	/* 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);
1216
	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1217 1218 1219
		return -ENOSPC;

	/* Clear the database */
1220
	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1221 1222
}

1223 1224
static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
			     struct mv88e6xxx_vtu_entry *entry, bool new)
1225 1226 1227 1228 1229 1230
{
	int err;

	if (!vid)
		return -EINVAL;

1231 1232
	entry->vid = vid - 1;
	entry->valid = false;
1233

1234
	err = mv88e6xxx_vtu_getnext(chip, entry);
1235 1236 1237
	if (err)
		return err;

1238 1239
	if (entry->vid == vid && entry->valid)
		return 0;
1240

1241 1242 1243 1244 1245 1246 1247 1248
	if (new) {
		int i;

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

1249
		/* Exclude all ports */
1250
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1251
			entry->member[i] =
1252
				MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1253 1254

		return mv88e6xxx_atu_new(chip, &entry->fid);
1255 1256
	}

1257 1258
	/* switchdev expects -EOPNOTSUPP to honor software VLANs */
	return -EOPNOTSUPP;
1259 1260
}

1261 1262 1263
static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
					u16 vid_begin, u16 vid_end)
{
V
Vivien Didelot 已提交
1264
	struct mv88e6xxx_chip *chip = ds->priv;
1265 1266 1267
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = vid_begin - 1,
	};
1268 1269
	int i, err;

1270 1271 1272 1273
	/* 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;

1274 1275 1276
	if (!vid_begin)
		return -EOPNOTSUPP;

1277
	mutex_lock(&chip->reg_lock);
1278 1279

	do {
1280
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1281 1282 1283 1284 1285 1286 1287 1288 1289
		if (err)
			goto unlock;

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

1290
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1291 1292 1293
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

1294
			if (!ds->ports[i].slave)
1295 1296
				continue;

1297
			if (vlan.member[i] ==
1298
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1299 1300
				continue;

V
Vivien Didelot 已提交
1301
			if (dsa_to_port(ds, i)->bridge_dev ==
1302
			    ds->ports[port].bridge_dev)
1303 1304
				break; /* same bridge, check next VLAN */

V
Vivien Didelot 已提交
1305
			if (!dsa_to_port(ds, i)->bridge_dev)
1306 1307
				continue;

1308 1309
			dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
				port, vlan.vid, i,
V
Vivien Didelot 已提交
1310
				netdev_name(dsa_to_port(ds, i)->bridge_dev));
1311 1312 1313 1314 1315 1316
			err = -EOPNOTSUPP;
			goto unlock;
		}
	} while (vlan.vid < vid_end);

unlock:
1317
	mutex_unlock(&chip->reg_lock);
1318 1319 1320 1321

	return err;
}

1322 1323
static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
					 bool vlan_filtering)
1324
{
V
Vivien Didelot 已提交
1325
	struct mv88e6xxx_chip *chip = ds->priv;
1326 1327
	u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
		MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
1328
	int err;
1329

1330
	if (!chip->info->max_vid)
1331 1332
		return -EOPNOTSUPP;

1333
	mutex_lock(&chip->reg_lock);
1334
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1335
	mutex_unlock(&chip->reg_lock);
1336

1337
	return err;
1338 1339
}

1340 1341
static int
mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1342
			    const struct switchdev_obj_port_vlan *vlan)
1343
{
V
Vivien Didelot 已提交
1344
	struct mv88e6xxx_chip *chip = ds->priv;
1345 1346
	int err;

1347
	if (!chip->info->max_vid)
1348 1349
		return -EOPNOTSUPP;

1350 1351 1352 1353 1354 1355 1356 1357
	/* 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;

1358 1359 1360 1361 1362 1363
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */
	return 0;
}

1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407
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);
}

1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430
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;
}

1431
static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
1432
				    u16 vid, u8 member)
1433
{
1434
	struct mv88e6xxx_vtu_entry vlan;
1435 1436
	int err;

1437
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
1438
	if (err)
1439
		return err;
1440

1441
	vlan.member[port] = member;
1442

1443 1444 1445 1446 1447
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
	if (err)
		return err;

	return mv88e6xxx_broadcast_setup(chip, vid);
1448 1449
}

1450
static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1451
				    const struct switchdev_obj_port_vlan *vlan)
1452
{
V
Vivien Didelot 已提交
1453
	struct mv88e6xxx_chip *chip = ds->priv;
1454 1455
	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1456
	u8 member;
1457 1458
	u16 vid;

1459
	if (!chip->info->max_vid)
1460 1461
		return;

1462
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1463
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1464
	else if (untagged)
1465
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
1466
	else
1467
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
1468

1469
	mutex_lock(&chip->reg_lock);
1470

1471
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
1472
		if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
1473 1474
			dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
				vid, untagged ? 'u' : 't');
1475

1476
	if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1477 1478
		dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
			vlan->vid_end);
1479

1480
	mutex_unlock(&chip->reg_lock);
1481 1482
}

1483
static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
1484
				    int port, u16 vid)
1485
{
1486
	struct mv88e6xxx_vtu_entry vlan;
1487 1488
	int i, err;

1489
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1490
	if (err)
1491
		return err;
1492

1493
	/* Tell switchdev if this VLAN is handled in software */
1494
	if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1495
		return -EOPNOTSUPP;
1496

1497
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1498 1499

	/* keep the VLAN unless all ports are excluded */
1500
	vlan.valid = false;
1501
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1502 1503
		if (vlan.member[i] !=
		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
1504
			vlan.valid = true;
1505 1506 1507 1508
			break;
		}
	}

1509
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1510 1511 1512
	if (err)
		return err;

1513
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
1514 1515
}

1516 1517
static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
				   const struct switchdev_obj_port_vlan *vlan)
1518
{
V
Vivien Didelot 已提交
1519
	struct mv88e6xxx_chip *chip = ds->priv;
1520 1521 1522
	u16 pvid, vid;
	int err = 0;

1523
	if (!chip->info->max_vid)
1524 1525
		return -EOPNOTSUPP;

1526
	mutex_lock(&chip->reg_lock);
1527

1528
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
1529 1530 1531
	if (err)
		goto unlock;

1532
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1533
		err = _mv88e6xxx_port_vlan_del(chip, port, vid);
1534 1535 1536 1537
		if (err)
			goto unlock;

		if (vid == pvid) {
1538
			err = mv88e6xxx_port_set_pvid(chip, port, 0);
1539 1540 1541 1542 1543
			if (err)
				goto unlock;
		}
	}

1544
unlock:
1545
	mutex_unlock(&chip->reg_lock);
1546 1547 1548 1549

	return err;
}

1550 1551
static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
				  const unsigned char *addr, u16 vid)
1552
{
V
Vivien Didelot 已提交
1553
	struct mv88e6xxx_chip *chip = ds->priv;
1554
	int err;
1555

1556
	mutex_lock(&chip->reg_lock);
1557 1558
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1559
	mutex_unlock(&chip->reg_lock);
1560 1561

	return err;
1562 1563
}

1564
static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1565
				  const unsigned char *addr, u16 vid)
1566
{
V
Vivien Didelot 已提交
1567
	struct mv88e6xxx_chip *chip = ds->priv;
1568
	int err;
1569

1570
	mutex_lock(&chip->reg_lock);
1571
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1572
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
1573
	mutex_unlock(&chip->reg_lock);
1574

1575
	return err;
1576 1577
}

1578 1579
static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
				      u16 fid, u16 vid, int port,
1580
				      dsa_fdb_dump_cb_t *cb, void *data)
1581
{
1582
	struct mv88e6xxx_atu_entry addr;
1583
	bool is_static;
1584 1585
	int err;

1586
	addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1587
	eth_broadcast_addr(addr.mac);
1588 1589

	do {
1590
		mutex_lock(&chip->reg_lock);
1591
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
1592
		mutex_unlock(&chip->reg_lock);
1593
		if (err)
1594
			return err;
1595

1596
		if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
1597 1598
			break;

1599
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
1600 1601
			continue;

1602 1603
		if (!is_unicast_ether_addr(addr.mac))
			continue;
1604

1605 1606 1607
		is_static = (addr.state ==
			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
		err = cb(addr.mac, vid, is_static, data);
1608 1609
		if (err)
			return err;
1610 1611 1612 1613 1614
	} while (!is_broadcast_ether_addr(addr.mac));

	return err;
}

1615
static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1616
				  dsa_fdb_dump_cb_t *cb, void *data)
1617
{
1618
	struct mv88e6xxx_vtu_entry vlan = {
1619
		.vid = chip->info->max_vid,
1620
	};
1621
	u16 fid;
1622 1623
	int err;

1624
	/* Dump port's default Filtering Information Database (VLAN ID 0) */
1625
	mutex_lock(&chip->reg_lock);
1626
	err = mv88e6xxx_port_get_fid(chip, port, &fid);
1627 1628
	mutex_unlock(&chip->reg_lock);

1629
	if (err)
1630
		return err;
1631

1632
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
1633
	if (err)
1634
		return err;
1635

1636
	/* Dump VLANs' Filtering Information Databases */
1637
	do {
1638
		mutex_lock(&chip->reg_lock);
1639
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1640
		mutex_unlock(&chip->reg_lock);
1641
		if (err)
1642
			return err;
1643 1644 1645 1646

		if (!vlan.valid)
			break;

1647
		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1648
						 cb, data);
1649
		if (err)
1650
			return err;
1651
	} while (vlan.vid < chip->info->max_vid);
1652

1653 1654 1655 1656
	return err;
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1657
				   dsa_fdb_dump_cb_t *cb, void *data)
1658
{
V
Vivien Didelot 已提交
1659
	struct mv88e6xxx_chip *chip = ds->priv;
1660

1661
	return mv88e6xxx_port_db_dump(chip, port, cb, data);
1662 1663
}

1664 1665
static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
				struct net_device *br)
1666
{
1667
	struct dsa_switch *ds;
1668
	int port;
1669
	int dev;
1670
	int err;
1671

1672 1673 1674 1675
	/* 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);
1676
			if (err)
1677
				return err;
1678 1679 1680
		}
	}

1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698
	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;
			}
		}
	}

1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709
	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);
1710
	mutex_unlock(&chip->reg_lock);
1711

1712
	return err;
1713 1714
}

1715 1716
static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
					struct net_device *br)
1717
{
V
Vivien Didelot 已提交
1718
	struct mv88e6xxx_chip *chip = ds->priv;
1719

1720
	mutex_lock(&chip->reg_lock);
1721 1722 1723
	if (mv88e6xxx_bridge_map(chip, br) ||
	    mv88e6xxx_port_vlan_map(chip, port))
		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
1724
	mutex_unlock(&chip->reg_lock);
1725 1726
}

1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756
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);
}

1757 1758 1759 1760 1761 1762 1763 1764
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->reset)
		return chip->info->ops->reset(chip);

	return 0;
}

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

1778
static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1779
{
1780
	int i, err;
1781

1782
	/* Set all ports to the Disabled state */
1783
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
1784
		err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
1785 1786
		if (err)
			return err;
1787 1788
	}

1789 1790 1791
	/* Wait for transmit queues to drain,
	 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
	 */
1792 1793
	usleep_range(2000, 4000);

1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804
	return 0;
}

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

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

1805
	mv88e6xxx_hardware_reset(chip);
1806

1807
	return mv88e6xxx_software_reset(chip);
1808 1809
}

1810
static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
1811 1812
				   enum mv88e6xxx_frame_mode frame,
				   enum mv88e6xxx_egress_mode egress, u16 etype)
1813 1814 1815
{
	int err;

1816 1817 1818 1819
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
1820 1821 1822
	if (err)
		return err;

1823 1824 1825 1826 1827 1828 1829 1830
	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;
1831 1832
}

1833
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1834
{
1835
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
1836
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
1837
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
1838
}
1839

1840 1841 1842
static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
1843
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
1844
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
1845
}
1846

1847 1848 1849 1850
static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port,
				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
1851 1852
				       MV88E6XXX_EGRESS_MODE_ETHERTYPE,
				       ETH_P_EDSA);
1853
}
1854

1855 1856 1857 1858
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);
1859

1860
	if (dsa_is_user_port(chip->ds, port))
1861
		return mv88e6xxx_set_port_mode_normal(chip, port);
1862

1863 1864 1865
	/* 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);
1866

1867 1868
	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
		return mv88e6xxx_set_port_mode_edsa(chip, port);
1869

1870
	return -EINVAL;
1871 1872
}

1873
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
1874
{
1875
	bool message = dsa_is_dsa_port(chip->ds, port);
1876

1877
	return mv88e6xxx_port_set_message_port(chip, port, message);
1878
}
1879

1880
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
1881
{
1882 1883
	struct dsa_switch *ds = chip->ds;
	bool flood;
1884

1885
	/* Upstream ports flood frames with unknown unicast or multicast DA */
1886
	flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
1887 1888 1889
	if (chip->info->ops->port_set_egress_floods)
		return chip->info->ops->port_set_egress_floods(chip, port,
							       flood, flood);
1890

1891
	return 0;
1892 1893
}

1894 1895 1896
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
1897 1898
	if (chip->info->ops->serdes_power)
		return chip->info->ops->serdes_power(chip, port, on);
1899

1900
	return 0;
1901 1902
}

1903 1904 1905 1906 1907 1908
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

1909
	upstream_port = dsa_upstream_port(ds, port);
1910 1911 1912 1913 1914 1915 1916
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932
	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;
		}
	}

1933 1934 1935
	return 0;
}

1936
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
1937
{
1938
	struct dsa_switch *ds = chip->ds;
1939
	int err;
1940
	u16 reg;
1941

1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955
	/* 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;
1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970

	/* 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.
	 */
1971 1972 1973 1974
	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);
1975 1976
	if (err)
		return err;
1977

1978
	err = mv88e6xxx_setup_port_mode(chip, port);
1979 1980
	if (err)
		return err;
1981

1982
	err = mv88e6xxx_setup_egress_floods(chip, port);
1983 1984 1985
	if (err)
		return err;

1986 1987 1988
	/* 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.
1989
	 */
1990 1991 1992 1993 1994
	if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
		err = mv88e6xxx_serdes_power(chip, port, true);
		if (err)
			return err;
	}
1995

1996
	/* Port Control 2: don't force a good FCS, set the maximum frame size to
1997
	 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
1998 1999 2000
	 * 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.
2001
	 */
2002 2003 2004
	err = mv88e6xxx_port_set_map_da(chip, port);
	if (err)
		return err;
2005

2006 2007 2008
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
2009

2010
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
2011
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
2012 2013 2014
	if (err)
		return err;

2015 2016
	if (chip->info->ops->port_set_jumbo_size) {
		err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
2017 2018 2019 2020
		if (err)
			return err;
	}

2021 2022 2023 2024 2025
	/* 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.
	 */
2026
	reg = 1 << port;
2027 2028
	/* Disable learning for CPU port */
	if (dsa_is_cpu_port(ds, port))
2029
		reg = 0;
2030

2031 2032
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
2033 2034
	if (err)
		return err;
2035 2036

	/* Egress rate control 2: disable egress rate control. */
2037 2038
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
				   0x0000);
2039 2040
	if (err)
		return err;
2041

2042 2043
	if (chip->info->ops->port_pause_limit) {
		err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
2044 2045
		if (err)
			return err;
2046
	}
2047

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

2054 2055
	if (chip->info->ops->port_disable_pri_override) {
		err = chip->info->ops->port_disable_pri_override(chip, port);
2056 2057
		if (err)
			return err;
2058
	}
2059

2060 2061
	if (chip->info->ops->port_tag_remap) {
		err = chip->info->ops->port_tag_remap(chip, port);
2062 2063
		if (err)
			return err;
2064 2065
	}

2066 2067
	if (chip->info->ops->port_egress_rate_limiting) {
		err = chip->info->ops->port_egress_rate_limiting(chip, port);
2068 2069
		if (err)
			return err;
2070 2071
	}

2072
	err = mv88e6xxx_setup_message_port(chip, port);
2073 2074
	if (err)
		return err;
2075

2076
	/* Port based VLAN map: give each port the same default address
2077 2078
	 * database, and allow bidirectional communication between the
	 * CPU and DSA port(s), and the other ports.
2079
	 */
2080
	err = mv88e6xxx_port_set_fid(chip, port, 0);
2081 2082
	if (err)
		return err;
2083

2084
	err = mv88e6xxx_port_vlan_map(chip, port);
2085 2086
	if (err)
		return err;
2087 2088 2089 2090

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

2094 2095 2096 2097
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
2098
	int err;
2099 2100

	mutex_lock(&chip->reg_lock);
2101
	err = mv88e6xxx_serdes_power(chip, port, true);
2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112
	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);
2113 2114
	if (mv88e6xxx_serdes_power(chip, port, false))
		dev_err(chip->dev, "failed to power off SERDES\n");
2115 2116 2117
	mutex_unlock(&chip->reg_lock);
}

2118 2119 2120
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
2121
	struct mv88e6xxx_chip *chip = ds->priv;
2122 2123 2124
	int err;

	mutex_lock(&chip->reg_lock);
2125
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2126 2127 2128 2129 2130
	mutex_unlock(&chip->reg_lock);

	return err;
}

2131
static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
2132
{
2133
	struct dsa_switch *ds = chip->ds;
2134
	int err;
2135

2136
	/* Disable remote management, and set the switch's DSA device number. */
2137 2138
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL2,
				 MV88E6XXX_G1_CTL2_MULTIPLE_CASCADE |
2139
				 (ds->index & 0x1f));
2140 2141 2142
	if (err)
		return err;

2143
	/* Configure the IP ToS mapping registers. */
2144
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_0, 0x0000);
2145
	if (err)
2146
		return err;
2147
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_1, 0x0000);
2148
	if (err)
2149
		return err;
2150
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_2, 0x5555);
2151
	if (err)
2152
		return err;
2153
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_3, 0x5555);
2154
	if (err)
2155
		return err;
2156
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_4, 0xaaaa);
2157
	if (err)
2158
		return err;
2159
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_5, 0xaaaa);
2160
	if (err)
2161
		return err;
2162
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_6, 0xffff);
2163
	if (err)
2164
		return err;
2165
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IP_PRI_7, 0xffff);
2166
	if (err)
2167
		return err;
2168 2169

	/* Configure the IEEE 802.1p priority mapping register. */
2170
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_IEEE_PRI, 0xfa41);
2171
	if (err)
2172
		return err;
2173

2174 2175 2176 2177 2178
	/* Initialize the statistics unit */
	err = mv88e6xxx_stats_set_histogram(chip);
	if (err)
		return err;

2179
	return mv88e6xxx_g1_stats_clear(chip);
2180 2181
}

2182
static int mv88e6xxx_setup(struct dsa_switch *ds)
2183
{
V
Vivien Didelot 已提交
2184
	struct mv88e6xxx_chip *chip = ds->priv;
2185
	int err;
2186 2187
	int i;

2188
	chip->ds = ds;
2189
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
2190

2191
	mutex_lock(&chip->reg_lock);
2192

2193
	/* Setup Switch Port Registers */
2194
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2195 2196 2197
		if (dsa_is_unused_port(ds, i))
			continue;

2198 2199 2200 2201 2202 2203 2204
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

	/* Setup Switch Global 1 Registers */
	err = mv88e6xxx_g1_setup(chip);
2205 2206 2207
	if (err)
		goto unlock;

2208
	/* Setup Switch Global 2 Registers */
2209
	if (chip->info->global2_addr) {
2210
		err = mv88e6xxx_g2_setup(chip);
2211 2212 2213
		if (err)
			goto unlock;
	}
2214

2215 2216 2217 2218
	err = mv88e6xxx_irl_setup(chip);
	if (err)
		goto unlock;

2219 2220 2221 2222
	err = mv88e6xxx_mac_setup(chip);
	if (err)
		goto unlock;

2223 2224 2225 2226
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

2227 2228 2229 2230
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

2231 2232 2233 2234
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

2235 2236 2237 2238
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

2239 2240 2241 2242
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

2243 2244 2245 2246
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

2247 2248 2249
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
2250

2251 2252 2253 2254
	err = mv88e6xxx_trunk_setup(chip);
	if (err)
		goto unlock;

2255
	/* Setup PTP Hardware Clock and timestamping */
2256 2257 2258 2259
	if (chip->info->ptp_support) {
		err = mv88e6xxx_ptp_setup(chip);
		if (err)
			goto unlock;
2260 2261 2262 2263

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
2264 2265
	}

2266
unlock:
2267
	mutex_unlock(&chip->reg_lock);
2268

2269
	return err;
2270 2271
}

2272
static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
2273
{
2274 2275
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2276 2277
	u16 val;
	int err;
2278

2279 2280 2281
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

2282
	mutex_lock(&chip->reg_lock);
2283
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
2284
	mutex_unlock(&chip->reg_lock);
2285

2286 2287 2288 2289 2290
	if (reg == MII_PHYSID2) {
		/* Some internal PHYS don't have a model number.  Use
		 * the mv88e6390 family model number instead.
		 */
		if (!(val & 0x3f0))
2291
			val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
2292 2293
	}

2294
	return err ? err : val;
2295 2296
}

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

2303 2304 2305
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

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

	return err;
2311 2312
}

2313
static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
2314 2315
				   struct device_node *np,
				   bool external)
2316 2317
{
	static int index;
2318
	struct mv88e6xxx_mdio_bus *mdio_bus;
2319 2320 2321
	struct mii_bus *bus;
	int err;

2322 2323 2324 2325 2326 2327 2328 2329 2330
	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;
	}

2331
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
2332 2333 2334
	if (!bus)
		return -ENOMEM;

2335
	mdio_bus = bus->priv;
2336
	mdio_bus->bus = bus;
2337
	mdio_bus->chip = chip;
2338 2339
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
2340

2341 2342
	if (np) {
		bus->name = np->full_name;
2343
		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
2344 2345 2346 2347 2348 2349 2350
	} 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;
2351
	bus->parent = chip->dev;
2352

2353 2354 2355 2356 2357 2358
	if (!external) {
		err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
		if (err)
			return err;
	}

2359 2360
	if (np)
		err = of_mdiobus_register(bus, np);
2361 2362 2363
	else
		err = mdiobus_register(bus);
	if (err) {
2364
		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
2365
		mv88e6xxx_g2_irq_mdio_free(chip, bus);
2366
		return err;
2367
	}
2368 2369 2370 2371 2372

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

	return 0;
2375
}
2376

2377 2378 2379 2380 2381
static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
	{ .compatible = "marvell,mv88e6xxx-mdio-external",
	  .data = (void *)true },
	{ },
};
2382

2383 2384 2385 2386 2387 2388 2389 2390 2391
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;

2392 2393 2394
		if (!mdio_bus->external)
			mv88e6xxx_g2_irq_mdio_free(chip, bus);

2395 2396 2397 2398
		mdiobus_unregister(bus);
	}
}

2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422
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);
2423 2424
			if (err) {
				mv88e6xxx_mdios_unregister(chip);
2425
				return err;
2426
			}
2427 2428 2429 2430
		}
	}

	return 0;
2431 2432
}

2433 2434
static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
2435
	struct mv88e6xxx_chip *chip = ds->priv;
2436 2437 2438 2439 2440 2441 2442

	return chip->eeprom_len;
}

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

2446 2447
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
2448

2449 2450
	mutex_lock(&chip->reg_lock);
	err = chip->info->ops->get_eeprom(chip, eeprom, data);
2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463
	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 已提交
2464
	struct mv88e6xxx_chip *chip = ds->priv;
2465 2466
	int err;

2467 2468 2469
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

2470 2471 2472 2473
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

	mutex_lock(&chip->reg_lock);
2474
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
2475 2476 2477 2478 2479
	mutex_unlock(&chip->reg_lock);

	return err;
}

2480
static const struct mv88e6xxx_ops mv88e6085_ops = {
2481
	/* MV88E6XXX_FAMILY_6097 */
2482
	.irl_init_all = mv88e6352_g2_irl_init_all,
2483
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2484 2485
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2486
	.port_set_link = mv88e6xxx_port_set_link,
2487
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2488
	.port_set_speed = mv88e6185_port_set_speed,
2489
	.port_tag_remap = mv88e6095_port_tag_remap,
2490
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2491
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2492
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2493
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2494
	.port_pause_limit = mv88e6097_port_pause_limit,
2495
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2496
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2497
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2498
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2499 2500
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2501
	.stats_get_stats = mv88e6095_stats_get_stats,
2502 2503
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2504
	.watchdog_ops = &mv88e6097_watchdog_ops,
2505
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2506
	.pot_clear = mv88e6xxx_g2_pot_clear,
2507 2508
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2509
	.reset = mv88e6185_g1_reset,
2510
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2511
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2512 2513 2514
};

static const struct mv88e6xxx_ops mv88e6095_ops = {
2515
	/* MV88E6XXX_FAMILY_6095 */
2516
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2517 2518
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2519
	.port_set_link = mv88e6xxx_port_set_link,
2520
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2521
	.port_set_speed = mv88e6185_port_set_speed,
2522
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2523
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2524
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2525
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2526
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2527 2528
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2529
	.stats_get_stats = mv88e6095_stats_get_stats,
2530
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2531 2532
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2533
	.reset = mv88e6185_g1_reset,
2534
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2535
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2536 2537
};

2538
static const struct mv88e6xxx_ops mv88e6097_ops = {
2539
	/* MV88E6XXX_FAMILY_6097 */
2540
	.irl_init_all = mv88e6352_g2_irl_init_all,
2541 2542 2543 2544 2545 2546
	.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,
2547
	.port_tag_remap = mv88e6095_port_tag_remap,
2548
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2549
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2550
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2551
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2552
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
2553
	.port_pause_limit = mv88e6097_port_pause_limit,
2554
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2555
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2556
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2557
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2558 2559 2560
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
	.stats_get_stats = mv88e6095_stats_get_stats,
2561 2562
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2563
	.watchdog_ops = &mv88e6097_watchdog_ops,
2564
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2565
	.pot_clear = mv88e6xxx_g2_pot_clear,
2566
	.reset = mv88e6352_g1_reset,
2567
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2568
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2569 2570
};

2571
static const struct mv88e6xxx_ops mv88e6123_ops = {
2572
	/* MV88E6XXX_FAMILY_6165 */
2573
	.irl_init_all = mv88e6352_g2_irl_init_all,
2574
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2575 2576
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2577
	.port_set_link = mv88e6xxx_port_set_link,
2578
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2579
	.port_set_speed = mv88e6185_port_set_speed,
2580
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2581
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2582
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2583
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2584
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2585
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2586 2587
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2588
	.stats_get_stats = mv88e6095_stats_get_stats,
2589 2590
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2591
	.watchdog_ops = &mv88e6097_watchdog_ops,
2592
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2593
	.pot_clear = mv88e6xxx_g2_pot_clear,
2594
	.reset = mv88e6352_g1_reset,
2595
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2596
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2597 2598 2599
};

static const struct mv88e6xxx_ops mv88e6131_ops = {
2600
	/* MV88E6XXX_FAMILY_6185 */
2601
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2602 2603
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2604
	.port_set_link = mv88e6xxx_port_set_link,
2605
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2606
	.port_set_speed = mv88e6185_port_set_speed,
2607
	.port_tag_remap = mv88e6095_port_tag_remap,
2608
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2609
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2610
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2611
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2612
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2613
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2614
	.port_pause_limit = mv88e6097_port_pause_limit,
2615
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2616
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2617 2618
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2619
	.stats_get_stats = mv88e6095_stats_get_stats,
2620 2621
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2622
	.watchdog_ops = &mv88e6097_watchdog_ops,
2623
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2624 2625
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2626
	.reset = mv88e6185_g1_reset,
2627
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2628
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2629 2630
};

2631 2632
static const struct mv88e6xxx_ops mv88e6141_ops = {
	/* MV88E6XXX_FAMILY_6341 */
2633
	.irl_init_all = mv88e6352_g2_irl_init_all,
2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646
	.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,
2647
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2648
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2649
	.port_pause_limit = mv88e6097_port_pause_limit,
2650 2651 2652
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
2653
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2654 2655 2656
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
2657 2658
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
2659 2660
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
2661
	.pot_clear = mv88e6xxx_g2_pot_clear,
2662
	.reset = mv88e6352_g1_reset,
2663
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2664
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2665
	.gpio_ops = &mv88e6352_gpio_ops,
2666 2667
};

2668
static const struct mv88e6xxx_ops mv88e6161_ops = {
2669
	/* MV88E6XXX_FAMILY_6165 */
2670
	.irl_init_all = mv88e6352_g2_irl_init_all,
2671
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2672 2673
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2674
	.port_set_link = mv88e6xxx_port_set_link,
2675
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2676
	.port_set_speed = mv88e6185_port_set_speed,
2677
	.port_tag_remap = mv88e6095_port_tag_remap,
2678
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2679
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2680
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2681
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2682
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2683
	.port_pause_limit = mv88e6097_port_pause_limit,
2684
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2685
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2686
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2687
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2688 2689
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2690
	.stats_get_stats = mv88e6095_stats_get_stats,
2691 2692
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2693
	.watchdog_ops = &mv88e6097_watchdog_ops,
2694
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2695
	.pot_clear = mv88e6xxx_g2_pot_clear,
2696
	.reset = mv88e6352_g1_reset,
2697
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2698
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2699 2700 2701
};

static const struct mv88e6xxx_ops mv88e6165_ops = {
2702
	/* MV88E6XXX_FAMILY_6165 */
2703
	.irl_init_all = mv88e6352_g2_irl_init_all,
2704
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2705 2706
	.phy_read = mv88e6165_phy_read,
	.phy_write = mv88e6165_phy_write,
2707
	.port_set_link = mv88e6xxx_port_set_link,
2708
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2709
	.port_set_speed = mv88e6185_port_set_speed,
2710
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2711
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2712
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2713
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2714 2715
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2716
	.stats_get_stats = mv88e6095_stats_get_stats,
2717 2718
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2719
	.watchdog_ops = &mv88e6097_watchdog_ops,
2720
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2721
	.pot_clear = mv88e6xxx_g2_pot_clear,
2722
	.reset = mv88e6352_g1_reset,
2723
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2724
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2725 2726 2727
};

static const struct mv88e6xxx_ops mv88e6171_ops = {
2728
	/* MV88E6XXX_FAMILY_6351 */
2729
	.irl_init_all = mv88e6352_g2_irl_init_all,
2730
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2731 2732
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2733
	.port_set_link = mv88e6xxx_port_set_link,
2734
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2735
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
2736
	.port_set_speed = mv88e6185_port_set_speed,
2737
	.port_tag_remap = mv88e6095_port_tag_remap,
2738
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2739
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2740
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2741
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2742
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2743
	.port_pause_limit = mv88e6097_port_pause_limit,
2744
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2745
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2746
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2747
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2748 2749
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2750
	.stats_get_stats = mv88e6095_stats_get_stats,
2751 2752
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2753
	.watchdog_ops = &mv88e6097_watchdog_ops,
2754
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2755
	.pot_clear = mv88e6xxx_g2_pot_clear,
2756
	.reset = mv88e6352_g1_reset,
2757
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2758
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2759 2760 2761
};

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

static const struct mv88e6xxx_ops mv88e6175_ops = {
2800
	/* MV88E6XXX_FAMILY_6351 */
2801
	.irl_init_all = mv88e6352_g2_irl_init_all,
2802
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2803 2804
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2805
	.port_set_link = mv88e6xxx_port_set_link,
2806
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2807
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
2808
	.port_set_speed = mv88e6185_port_set_speed,
2809
	.port_tag_remap = mv88e6095_port_tag_remap,
2810
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2811
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2812
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2813
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2814
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2815
	.port_pause_limit = mv88e6097_port_pause_limit,
2816
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2817
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2818
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2819
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2820 2821
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2822
	.stats_get_stats = mv88e6095_stats_get_stats,
2823 2824
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2825
	.watchdog_ops = &mv88e6097_watchdog_ops,
2826
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2827
	.pot_clear = mv88e6xxx_g2_pot_clear,
2828
	.reset = mv88e6352_g1_reset,
2829
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2830
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2831 2832 2833
};

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

static const struct mv88e6xxx_ops mv88e6185_ops = {
2872
	/* MV88E6XXX_FAMILY_6185 */
2873
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2874 2875
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2876
	.port_set_link = mv88e6xxx_port_set_link,
2877
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2878
	.port_set_speed = mv88e6185_port_set_speed,
2879
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2880
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2881
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
2882
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2883
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2884
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2885 2886
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2887
	.stats_get_stats = mv88e6095_stats_get_stats,
2888 2889
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2890
	.watchdog_ops = &mv88e6097_watchdog_ops,
2891
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2892 2893
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2894
	.reset = mv88e6185_g1_reset,
2895
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2896
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2897 2898
};

2899
static const struct mv88e6xxx_ops mv88e6190_ops = {
2900
	/* MV88E6XXX_FAMILY_6390 */
2901
	.irl_init_all = mv88e6390_g2_irl_init_all,
2902 2903
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
2904 2905 2906 2907 2908 2909 2910
	.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,
2911
	.port_tag_remap = mv88e6390_port_tag_remap,
2912
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2913
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2914
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2915
	.port_pause_limit = mv88e6390_port_pause_limit,
2916
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2917
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2918
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
2919
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
2920 2921
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
2922
	.stats_get_stats = mv88e6390_stats_get_stats,
2923 2924
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
2925
	.watchdog_ops = &mv88e6390_watchdog_ops,
2926
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
2927
	.pot_clear = mv88e6xxx_g2_pot_clear,
2928
	.reset = mv88e6352_g1_reset,
2929 2930
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
2931
	.serdes_power = mv88e6390_serdes_power,
2932
	.gpio_ops = &mv88e6352_gpio_ops,
2933 2934 2935
};

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

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

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

3045
static const struct mv88e6xxx_ops mv88e6290_ops = {
3046
	/* MV88E6XXX_FAMILY_6390 */
3047
	.irl_init_all = mv88e6390_g2_irl_init_all,
3048 3049
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3050 3051 3052 3053 3054 3055 3056
	.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,
3057
	.port_tag_remap = mv88e6390_port_tag_remap,
3058
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3059
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3060
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3061
	.port_pause_limit = mv88e6390_port_pause_limit,
3062
	.port_set_cmode = mv88e6390x_port_set_cmode,
3063
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3064
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3065
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3066
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3067 3068
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3069
	.stats_get_stats = mv88e6390_stats_get_stats,
3070 3071
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3072
	.watchdog_ops = &mv88e6390_watchdog_ops,
3073
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3074
	.pot_clear = mv88e6xxx_g2_pot_clear,
3075
	.reset = mv88e6352_g1_reset,
3076 3077
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3078
	.serdes_power = mv88e6390_serdes_power,
3079
	.gpio_ops = &mv88e6352_gpio_ops,
3080
	.avb_ops = &mv88e6390_avb_ops,
3081 3082
};

3083
static const struct mv88e6xxx_ops mv88e6320_ops = {
3084
	/* MV88E6XXX_FAMILY_6320 */
3085
	.irl_init_all = mv88e6352_g2_irl_init_all,
3086 3087
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3088
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3089 3090
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3091
	.port_set_link = mv88e6xxx_port_set_link,
3092
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3093
	.port_set_speed = mv88e6185_port_set_speed,
3094
	.port_tag_remap = mv88e6095_port_tag_remap,
3095
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3096
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3097
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3098
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3099
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3100
	.port_pause_limit = mv88e6097_port_pause_limit,
3101
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3102
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3103
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3104
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3105 3106
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3107
	.stats_get_stats = mv88e6320_stats_get_stats,
3108 3109
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3110
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3111
	.pot_clear = mv88e6xxx_g2_pot_clear,
3112
	.reset = mv88e6352_g1_reset,
3113
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3114
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3115
	.gpio_ops = &mv88e6352_gpio_ops,
3116
	.avb_ops = &mv88e6352_avb_ops,
3117 3118 3119
};

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

3153 3154
static const struct mv88e6xxx_ops mv88e6341_ops = {
	/* MV88E6XXX_FAMILY_6341 */
3155
	.irl_init_all = mv88e6352_g2_irl_init_all,
3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168
	.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,
3169
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3170
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3171
	.port_pause_limit = mv88e6097_port_pause_limit,
3172 3173 3174
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3175
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3176 3177 3178
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
3179 3180
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3181 3182
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
3183
	.pot_clear = mv88e6xxx_g2_pot_clear,
3184
	.reset = mv88e6352_g1_reset,
3185
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3186
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3187
	.gpio_ops = &mv88e6352_gpio_ops,
3188
	.avb_ops = &mv88e6390_avb_ops,
3189 3190
};

3191
static const struct mv88e6xxx_ops mv88e6350_ops = {
3192
	/* MV88E6XXX_FAMILY_6351 */
3193
	.irl_init_all = mv88e6352_g2_irl_init_all,
3194
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3195 3196
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3197
	.port_set_link = mv88e6xxx_port_set_link,
3198
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3199
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3200
	.port_set_speed = mv88e6185_port_set_speed,
3201
	.port_tag_remap = mv88e6095_port_tag_remap,
3202
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3203
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3204
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3205
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3206
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3207
	.port_pause_limit = mv88e6097_port_pause_limit,
3208
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3209
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3210
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3211
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3212 3213
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3214
	.stats_get_stats = mv88e6095_stats_get_stats,
3215 3216
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3217
	.watchdog_ops = &mv88e6097_watchdog_ops,
3218
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3219
	.pot_clear = mv88e6xxx_g2_pot_clear,
3220
	.reset = mv88e6352_g1_reset,
3221
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3222
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3223 3224 3225
};

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

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

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

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

3382 3383
static const struct mv88e6xxx_info mv88e6xxx_table[] = {
	[MV88E6085] = {
3384
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
3385 3386 3387 3388
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6085",
		.num_databases = 4096,
		.num_ports = 10,
3389
		.num_internal_phys = 5,
3390
		.max_vid = 4095,
3391
		.port_base_addr = 0x10,
3392
		.global1_addr = 0x1b,
3393
		.global2_addr = 0x1c,
3394
		.age_time_coeff = 15000,
3395
		.g1_irqs = 8,
3396
		.g2_irqs = 10,
3397
		.atu_move_port_mask = 0xf,
3398
		.pvt = true,
3399
		.multi_chip = true,
3400
		.tag_protocol = DSA_TAG_PROTO_DSA,
3401
		.ops = &mv88e6085_ops,
3402 3403 3404
	},

	[MV88E6095] = {
3405
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
3406 3407 3408 3409
		.family = MV88E6XXX_FAMILY_6095,
		.name = "Marvell 88E6095/88E6095F",
		.num_databases = 256,
		.num_ports = 11,
3410
		.num_internal_phys = 0,
3411
		.max_vid = 4095,
3412
		.port_base_addr = 0x10,
3413
		.global1_addr = 0x1b,
3414
		.global2_addr = 0x1c,
3415
		.age_time_coeff = 15000,
3416
		.g1_irqs = 8,
3417
		.atu_move_port_mask = 0xf,
3418
		.multi_chip = true,
3419
		.tag_protocol = DSA_TAG_PROTO_DSA,
3420
		.ops = &mv88e6095_ops,
3421 3422
	},

3423
	[MV88E6097] = {
3424
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
3425 3426 3427 3428
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6097/88E6097F",
		.num_databases = 4096,
		.num_ports = 11,
3429
		.num_internal_phys = 8,
3430
		.max_vid = 4095,
3431 3432
		.port_base_addr = 0x10,
		.global1_addr = 0x1b,
3433
		.global2_addr = 0x1c,
3434
		.age_time_coeff = 15000,
3435
		.g1_irqs = 8,
3436
		.g2_irqs = 10,
3437
		.atu_move_port_mask = 0xf,
3438
		.pvt = true,
3439
		.multi_chip = true,
3440
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3441 3442 3443
		.ops = &mv88e6097_ops,
	},

3444
	[MV88E6123] = {
3445
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
3446 3447 3448 3449
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6123",
		.num_databases = 4096,
		.num_ports = 3,
3450
		.num_internal_phys = 5,
3451
		.max_vid = 4095,
3452
		.port_base_addr = 0x10,
3453
		.global1_addr = 0x1b,
3454
		.global2_addr = 0x1c,
3455
		.age_time_coeff = 15000,
3456
		.g1_irqs = 9,
3457
		.g2_irqs = 10,
3458
		.atu_move_port_mask = 0xf,
3459
		.pvt = true,
3460
		.multi_chip = true,
3461
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3462
		.ops = &mv88e6123_ops,
3463 3464 3465
	},

	[MV88E6131] = {
3466
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
3467 3468 3469 3470
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6131",
		.num_databases = 256,
		.num_ports = 8,
3471
		.num_internal_phys = 0,
3472
		.max_vid = 4095,
3473
		.port_base_addr = 0x10,
3474
		.global1_addr = 0x1b,
3475
		.global2_addr = 0x1c,
3476
		.age_time_coeff = 15000,
3477
		.g1_irqs = 9,
3478
		.atu_move_port_mask = 0xf,
3479
		.multi_chip = true,
3480
		.tag_protocol = DSA_TAG_PROTO_DSA,
3481
		.ops = &mv88e6131_ops,
3482 3483
	},

3484
	[MV88E6141] = {
3485
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
3486
		.family = MV88E6XXX_FAMILY_6341,
3487
		.name = "Marvell 88E6141",
3488 3489
		.num_databases = 4096,
		.num_ports = 6,
3490
		.num_internal_phys = 5,
3491
		.num_gpio = 11,
3492
		.max_vid = 4095,
3493 3494
		.port_base_addr = 0x10,
		.global1_addr = 0x1b,
3495
		.global2_addr = 0x1c,
3496 3497
		.age_time_coeff = 3750,
		.atu_move_port_mask = 0x1f,
3498
		.g1_irqs = 9,
3499
		.g2_irqs = 10,
3500
		.pvt = true,
3501
		.multi_chip = true,
3502 3503 3504 3505
		.tag_protocol = DSA_TAG_PROTO_EDSA,
		.ops = &mv88e6141_ops,
	},

3506
	[MV88E6161] = {
3507
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
3508 3509 3510 3511
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6161",
		.num_databases = 4096,
		.num_ports = 6,
3512
		.num_internal_phys = 5,
3513
		.max_vid = 4095,
3514
		.port_base_addr = 0x10,
3515
		.global1_addr = 0x1b,
3516
		.global2_addr = 0x1c,
3517
		.age_time_coeff = 15000,
3518
		.g1_irqs = 9,
3519
		.g2_irqs = 10,
3520
		.atu_move_port_mask = 0xf,
3521
		.pvt = true,
3522
		.multi_chip = true,
3523
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3524
		.ops = &mv88e6161_ops,
3525 3526 3527
	},

	[MV88E6165] = {
3528
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
3529 3530 3531 3532
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6165",
		.num_databases = 4096,
		.num_ports = 6,
3533
		.num_internal_phys = 0,
3534
		.max_vid = 4095,
3535
		.port_base_addr = 0x10,
3536
		.global1_addr = 0x1b,
3537
		.global2_addr = 0x1c,
3538
		.age_time_coeff = 15000,
3539
		.g1_irqs = 9,
3540
		.g2_irqs = 10,
3541
		.atu_move_port_mask = 0xf,
3542
		.pvt = true,
3543
		.multi_chip = true,
3544
		.tag_protocol = DSA_TAG_PROTO_DSA,
3545
		.ops = &mv88e6165_ops,
3546 3547 3548
	},

	[MV88E6171] = {
3549
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
3550 3551 3552 3553
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6171",
		.num_databases = 4096,
		.num_ports = 7,
3554
		.num_internal_phys = 5,
3555
		.max_vid = 4095,
3556
		.port_base_addr = 0x10,
3557
		.global1_addr = 0x1b,
3558
		.global2_addr = 0x1c,
3559
		.age_time_coeff = 15000,
3560
		.g1_irqs = 9,
3561
		.g2_irqs = 10,
3562
		.atu_move_port_mask = 0xf,
3563
		.pvt = true,
3564
		.multi_chip = true,
3565
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3566
		.ops = &mv88e6171_ops,
3567 3568 3569
	},

	[MV88E6172] = {
3570
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
3571 3572 3573 3574
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6172",
		.num_databases = 4096,
		.num_ports = 7,
3575
		.num_internal_phys = 5,
3576
		.num_gpio = 15,
3577
		.max_vid = 4095,
3578
		.port_base_addr = 0x10,
3579
		.global1_addr = 0x1b,
3580
		.global2_addr = 0x1c,
3581
		.age_time_coeff = 15000,
3582
		.g1_irqs = 9,
3583
		.g2_irqs = 10,
3584
		.atu_move_port_mask = 0xf,
3585
		.pvt = true,
3586
		.multi_chip = true,
3587
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3588
		.ops = &mv88e6172_ops,
3589 3590 3591
	},

	[MV88E6175] = {
3592
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
3593 3594 3595 3596
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6175",
		.num_databases = 4096,
		.num_ports = 7,
3597
		.num_internal_phys = 5,
3598
		.max_vid = 4095,
3599
		.port_base_addr = 0x10,
3600
		.global1_addr = 0x1b,
3601
		.global2_addr = 0x1c,
3602
		.age_time_coeff = 15000,
3603
		.g1_irqs = 9,
3604
		.g2_irqs = 10,
3605
		.atu_move_port_mask = 0xf,
3606
		.pvt = true,
3607
		.multi_chip = true,
3608
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3609
		.ops = &mv88e6175_ops,
3610 3611 3612
	},

	[MV88E6176] = {
3613
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
3614 3615 3616 3617
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6176",
		.num_databases = 4096,
		.num_ports = 7,
3618
		.num_internal_phys = 5,
3619
		.num_gpio = 15,
3620
		.max_vid = 4095,
3621
		.port_base_addr = 0x10,
3622
		.global1_addr = 0x1b,
3623
		.global2_addr = 0x1c,
3624
		.age_time_coeff = 15000,
3625
		.g1_irqs = 9,
3626
		.g2_irqs = 10,
3627
		.atu_move_port_mask = 0xf,
3628
		.pvt = true,
3629
		.multi_chip = true,
3630
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3631
		.ops = &mv88e6176_ops,
3632 3633 3634
	},

	[MV88E6185] = {
3635
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
3636 3637 3638 3639
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6185",
		.num_databases = 256,
		.num_ports = 10,
3640
		.num_internal_phys = 0,
3641
		.max_vid = 4095,
3642
		.port_base_addr = 0x10,
3643
		.global1_addr = 0x1b,
3644
		.global2_addr = 0x1c,
3645
		.age_time_coeff = 15000,
3646
		.g1_irqs = 8,
3647
		.atu_move_port_mask = 0xf,
3648
		.multi_chip = true,
3649
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3650
		.ops = &mv88e6185_ops,
3651 3652
	},

3653
	[MV88E6190] = {
3654
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
3655 3656 3657 3658
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3659
		.num_internal_phys = 11,
3660
		.num_gpio = 16,
3661
		.max_vid = 8191,
3662 3663
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3664
		.global2_addr = 0x1c,
3665
		.tag_protocol = DSA_TAG_PROTO_DSA,
3666
		.age_time_coeff = 3750,
3667
		.g1_irqs = 9,
3668
		.g2_irqs = 14,
3669
		.pvt = true,
3670
		.multi_chip = true,
3671
		.atu_move_port_mask = 0x1f,
3672 3673 3674 3675
		.ops = &mv88e6190_ops,
	},

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

	[MV88E6191] = {
3698
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
3699 3700 3701 3702
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6191",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3703
		.num_internal_phys = 11,
3704
		.max_vid = 8191,
3705 3706
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3707
		.global2_addr = 0x1c,
3708
		.age_time_coeff = 3750,
3709
		.g1_irqs = 9,
3710
		.g2_irqs = 14,
3711
		.atu_move_port_mask = 0x1f,
3712
		.pvt = true,
3713
		.multi_chip = true,
3714
		.tag_protocol = DSA_TAG_PROTO_DSA,
3715
		.ptp_support = true,
3716
		.ops = &mv88e6191_ops,
3717 3718
	},

3719
	[MV88E6240] = {
3720
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
3721 3722 3723 3724
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6240",
		.num_databases = 4096,
		.num_ports = 7,
3725
		.num_internal_phys = 5,
3726
		.num_gpio = 15,
3727
		.max_vid = 4095,
3728
		.port_base_addr = 0x10,
3729
		.global1_addr = 0x1b,
3730
		.global2_addr = 0x1c,
3731
		.age_time_coeff = 15000,
3732
		.g1_irqs = 9,
3733
		.g2_irqs = 10,
3734
		.atu_move_port_mask = 0xf,
3735
		.pvt = true,
3736
		.multi_chip = true,
3737
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3738
		.ptp_support = true,
3739
		.ops = &mv88e6240_ops,
3740 3741
	},

3742
	[MV88E6290] = {
3743
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
3744 3745 3746 3747
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6290",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3748
		.num_internal_phys = 11,
3749
		.num_gpio = 16,
3750
		.max_vid = 8191,
3751 3752
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3753
		.global2_addr = 0x1c,
3754
		.age_time_coeff = 3750,
3755
		.g1_irqs = 9,
3756
		.g2_irqs = 14,
3757
		.atu_move_port_mask = 0x1f,
3758
		.pvt = true,
3759
		.multi_chip = true,
3760
		.tag_protocol = DSA_TAG_PROTO_DSA,
3761
		.ptp_support = true,
3762 3763 3764
		.ops = &mv88e6290_ops,
	},

3765
	[MV88E6320] = {
3766
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
3767 3768 3769 3770
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6320",
		.num_databases = 4096,
		.num_ports = 7,
3771
		.num_internal_phys = 5,
3772
		.num_gpio = 15,
3773
		.max_vid = 4095,
3774
		.port_base_addr = 0x10,
3775
		.global1_addr = 0x1b,
3776
		.global2_addr = 0x1c,
3777
		.age_time_coeff = 15000,
3778
		.g1_irqs = 8,
3779
		.g2_irqs = 10,
3780
		.atu_move_port_mask = 0xf,
3781
		.pvt = true,
3782
		.multi_chip = true,
3783
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3784
		.ptp_support = true,
3785
		.ops = &mv88e6320_ops,
3786 3787 3788
	},

	[MV88E6321] = {
3789
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
3790 3791 3792 3793
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6321",
		.num_databases = 4096,
		.num_ports = 7,
3794
		.num_internal_phys = 5,
3795
		.num_gpio = 15,
3796
		.max_vid = 4095,
3797
		.port_base_addr = 0x10,
3798
		.global1_addr = 0x1b,
3799
		.global2_addr = 0x1c,
3800
		.age_time_coeff = 15000,
3801
		.g1_irqs = 8,
3802
		.g2_irqs = 10,
3803
		.atu_move_port_mask = 0xf,
3804
		.multi_chip = true,
3805
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3806
		.ptp_support = true,
3807
		.ops = &mv88e6321_ops,
3808 3809
	},

3810
	[MV88E6341] = {
3811
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
3812 3813 3814
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
3815
		.num_internal_phys = 5,
3816
		.num_ports = 6,
3817
		.num_gpio = 11,
3818
		.max_vid = 4095,
3819 3820
		.port_base_addr = 0x10,
		.global1_addr = 0x1b,
3821
		.global2_addr = 0x1c,
3822
		.age_time_coeff = 3750,
3823
		.atu_move_port_mask = 0x1f,
3824
		.g1_irqs = 9,
3825
		.g2_irqs = 10,
3826
		.pvt = true,
3827
		.multi_chip = true,
3828
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3829
		.ptp_support = true,
3830 3831 3832
		.ops = &mv88e6341_ops,
	},

3833
	[MV88E6350] = {
3834
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
3835 3836 3837 3838
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6350",
		.num_databases = 4096,
		.num_ports = 7,
3839
		.num_internal_phys = 5,
3840
		.max_vid = 4095,
3841
		.port_base_addr = 0x10,
3842
		.global1_addr = 0x1b,
3843
		.global2_addr = 0x1c,
3844
		.age_time_coeff = 15000,
3845
		.g1_irqs = 9,
3846
		.g2_irqs = 10,
3847
		.atu_move_port_mask = 0xf,
3848
		.pvt = true,
3849
		.multi_chip = true,
3850
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3851
		.ops = &mv88e6350_ops,
3852 3853 3854
	},

	[MV88E6351] = {
3855
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
3856 3857 3858 3859
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6351",
		.num_databases = 4096,
		.num_ports = 7,
3860
		.num_internal_phys = 5,
3861
		.max_vid = 4095,
3862
		.port_base_addr = 0x10,
3863
		.global1_addr = 0x1b,
3864
		.global2_addr = 0x1c,
3865
		.age_time_coeff = 15000,
3866
		.g1_irqs = 9,
3867
		.g2_irqs = 10,
3868
		.atu_move_port_mask = 0xf,
3869
		.pvt = true,
3870
		.multi_chip = true,
3871
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3872
		.ops = &mv88e6351_ops,
3873 3874 3875
	},

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

3943
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
3944
{
3945
	int i;
3946

3947 3948 3949
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
3950 3951 3952 3953

	return NULL;
}

3954
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
3955 3956
{
	const struct mv88e6xxx_info *info;
3957 3958 3959
	unsigned int prod_num, rev;
	u16 id;
	int err;
3960

3961
	mutex_lock(&chip->reg_lock);
3962
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
3963 3964 3965
	mutex_unlock(&chip->reg_lock);
	if (err)
		return err;
3966

3967 3968
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
3969 3970 3971 3972 3973

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

3974
	/* Update the compatible info with the probed one */
3975
	chip->info = info;
3976

3977 3978 3979 3980
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

3981 3982
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
3983 3984 3985 3986

	return 0;
}

3987
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
3988
{
3989
	struct mv88e6xxx_chip *chip;
3990

3991 3992
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
3993 3994
		return NULL;

3995
	chip->dev = dev;
3996

3997
	mutex_init(&chip->reg_lock);
3998
	INIT_LIST_HEAD(&chip->mdios);
3999

4000
	return chip;
4001 4002
}

4003
static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
4004 4005
			      struct mii_bus *bus, int sw_addr)
{
4006
	if (sw_addr == 0)
4007
		chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
4008
	else if (chip->info->multi_chip)
4009
		chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
4010 4011 4012
	else
		return -EINVAL;

4013 4014
	chip->bus = bus;
	chip->sw_addr = sw_addr;
4015 4016 4017 4018

	return 0;
}

4019 4020
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
							int port)
4021
{
V
Vivien Didelot 已提交
4022
	struct mv88e6xxx_chip *chip = ds->priv;
4023

4024
	return chip->info->tag_protocol;
4025 4026
}

4027
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
4028 4029 4030
static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
				       struct device *host_dev, int sw_addr,
				       void **priv)
4031
{
4032
	struct mv88e6xxx_chip *chip;
4033
	struct mii_bus *bus;
4034
	int err;
4035

4036
	bus = dsa_host_dev_to_mii_bus(host_dev);
4037 4038 4039
	if (!bus)
		return NULL;

4040 4041
	chip = mv88e6xxx_alloc_chip(dsa_dev);
	if (!chip)
4042 4043
		return NULL;

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

4047
	err = mv88e6xxx_smi_init(chip, bus, sw_addr);
4048 4049 4050
	if (err)
		goto free;

4051
	err = mv88e6xxx_detect(chip);
4052
	if (err)
4053
		goto free;
4054

4055 4056 4057 4058 4059 4060
	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_switch_reset(chip);
	mutex_unlock(&chip->reg_lock);
	if (err)
		goto free;

4061 4062
	mv88e6xxx_phy_init(chip);

4063
	err = mv88e6xxx_mdios_register(chip, NULL);
4064
	if (err)
4065
		goto free;
4066

4067
	*priv = chip;
4068

4069
	return chip->info->name;
4070
free:
4071
	devm_kfree(dsa_dev, chip);
4072 4073

	return NULL;
4074
}
4075
#endif
4076

4077
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4078
				      const struct switchdev_obj_port_mdb *mdb)
4079 4080 4081 4082 4083 4084 4085 4086 4087
{
	/* 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,
4088
				   const struct switchdev_obj_port_mdb *mdb)
4089
{
V
Vivien Didelot 已提交
4090
	struct mv88e6xxx_chip *chip = ds->priv;
4091 4092 4093

	mutex_lock(&chip->reg_lock);
	if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4094
					 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
4095 4096
		dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
			port);
4097 4098 4099 4100 4101 4102
	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 已提交
4103
	struct mv88e6xxx_chip *chip = ds->priv;
4104 4105 4106 4107
	int err;

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4108
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
4109 4110 4111 4112 4113
	mutex_unlock(&chip->reg_lock);

	return err;
}

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

4157 4158 4159 4160
static struct dsa_switch_driver mv88e6xxx_switch_drv = {
	.ops			= &mv88e6xxx_switch_ops,
};

4161
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
4162
{
4163
	struct device *dev = chip->dev;
4164 4165
	struct dsa_switch *ds;

4166
	ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
4167 4168 4169
	if (!ds)
		return -ENOMEM;

4170
	ds->priv = chip;
4171
	ds->ops = &mv88e6xxx_switch_ops;
4172 4173
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
4174 4175 4176

	dev_set_drvdata(dev, ds);

4177
	return dsa_register_switch(ds);
4178 4179
}

4180
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
4181
{
4182
	dsa_unregister_switch(chip->ds);
4183 4184
}

4185
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
4186
{
4187
	struct device *dev = &mdiodev->dev;
4188
	struct device_node *np = dev->of_node;
4189
	const struct mv88e6xxx_info *compat_info;
4190
	struct mv88e6xxx_chip *chip;
4191
	u32 eeprom_len;
4192
	int err;
4193

4194 4195 4196 4197
	compat_info = of_device_get_match_data(dev);
	if (!compat_info)
		return -EINVAL;

4198 4199
	chip = mv88e6xxx_alloc_chip(dev);
	if (!chip)
4200 4201
		return -ENOMEM;

4202
	chip->info = compat_info;
4203

4204
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
4205 4206
	if (err)
		return err;
4207

4208 4209 4210 4211
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
	if (IS_ERR(chip->reset))
		return PTR_ERR(chip->reset);

4212
	err = mv88e6xxx_detect(chip);
4213 4214
	if (err)
		return err;
4215

4216 4217
	mv88e6xxx_phy_init(chip);

4218
	if (chip->info->ops->get_eeprom &&
4219
	    !of_property_read_u32(np, "eeprom-length", &eeprom_len))
4220
		chip->eeprom_len = eeprom_len;
4221

4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233
	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;
	}

4234
	/* Has to be performed before the MDIO bus is created, because
4235
	 * the PHYs will link their interrupts to these interrupt
4236 4237 4238 4239
	 * controllers
	 */
	mutex_lock(&chip->reg_lock);
	if (chip->irq > 0)
4240
		err = mv88e6xxx_g1_irq_setup(chip);
4241 4242 4243
	else
		err = mv88e6xxx_irq_poll_setup(chip);
	mutex_unlock(&chip->reg_lock);
4244

4245 4246
	if (err)
		goto out;
4247

4248 4249
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
4250
		if (err)
4251
			goto out_g1_irq;
4252 4253
	}

4254 4255 4256 4257 4258 4259 4260 4261
	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;

4262
	err = mv88e6xxx_mdios_register(chip, np);
4263
	if (err)
4264
		goto out_g1_vtu_prob_irq;
4265

4266
	err = mv88e6xxx_register_switch(chip);
4267 4268
	if (err)
		goto out_mdio;
4269

4270
	return 0;
4271 4272

out_mdio:
4273
	mv88e6xxx_mdios_unregister(chip);
4274
out_g1_vtu_prob_irq:
4275
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
4276
out_g1_atu_prob_irq:
4277
	mv88e6xxx_g1_atu_prob_irq_free(chip);
4278
out_g2_irq:
4279
	if (chip->info->g2_irqs > 0)
4280 4281
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
4282 4283
	mutex_lock(&chip->reg_lock);
	if (chip->irq > 0)
4284
		mv88e6xxx_g1_irq_free(chip);
4285 4286 4287
	else
		mv88e6xxx_irq_poll_free(chip);
	mutex_unlock(&chip->reg_lock);
4288 4289
out:
	return err;
4290
}
4291 4292 4293 4294

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

4297 4298
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
4299
		mv88e6xxx_ptp_free(chip);
4300
	}
4301

4302
	mv88e6xxx_phy_destroy(chip);
4303
	mv88e6xxx_unregister_switch(chip);
4304
	mv88e6xxx_mdios_unregister(chip);
4305

4306 4307 4308 4309 4310 4311 4312 4313
	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)
4314
		mv88e6xxx_g1_irq_free(chip);
4315 4316 4317
	else
		mv88e6xxx_irq_poll_free(chip);
	mutex_unlock(&chip->reg_lock);
4318 4319 4320
}

static const struct of_device_id mv88e6xxx_of_match[] = {
4321 4322 4323 4324
	{
		.compatible = "marvell,mv88e6085",
		.data = &mv88e6xxx_table[MV88E6085],
	},
4325 4326 4327 4328
	{
		.compatible = "marvell,mv88e6190",
		.data = &mv88e6xxx_table[MV88E6190],
	},
4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344
	{ /* 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)
{
4345
	register_switch_driver(&mv88e6xxx_switch_drv);
4346 4347
	return mdio_driver_register(&mv88e6xxx_driver);
}
4348 4349 4350 4351
module_init(mv88e6xxx_init);

static void __exit mv88e6xxx_cleanup(void)
{
4352
	mdio_driver_unregister(&mv88e6xxx_driver);
4353
	unregister_switch_driver(&mv88e6xxx_switch_drv);
4354 4355
}
module_exit(mv88e6xxx_cleanup);
4356 4357 4358 4359

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