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

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

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

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

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

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

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

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

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

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

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

	*val = ret & 0xffff;

	return 0;
}

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

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

	return 0;
}

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

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

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

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

	return -ETIMEDOUT;
}

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

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

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

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

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

157
	*val = ret & 0xffff;
158

159
	return 0;
160 161
}

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

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

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

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

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

	return 0;
}

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

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

200
	assert_reg_lock(chip);
201

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

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

	return 0;
}

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

216
	assert_reg_lock(chip);
217

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

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

225 226 227
	return 0;
}

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

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

	return mdio_bus->bus;
}

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

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

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

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

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

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

	if (err)
		goto out;

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

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

	return mv88e6xxx_g1_irq_thread_work(chip);
}

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

	mutex_lock(&chip->reg_lock);
}

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

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

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

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

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

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

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

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

	return 0;
}

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

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

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

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

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

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

	free_irq(chip->irq, chip);
}

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

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

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

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

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

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

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

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

	return 0;

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

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

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

	return err;
}

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

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

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

	return err;
}

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

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

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

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

	kthread_init_delayed_work(&chip->irq_poll_work,
				  mv88e6xxx_irq_poll);

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

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

	return 0;
}

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

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

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

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

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

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

		usleep_range(1000, 2000);
	}

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

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

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

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

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

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

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

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

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

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

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

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

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

	return err;
}

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

	if (!phy_is_pseudo_fixed_link(phydev))
		return;

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

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

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

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

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

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

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

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

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

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

	return j;
710 711
}

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

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

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

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

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

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

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

753 754
	mutex_lock(&chip->reg_lock);

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

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

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

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

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

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

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

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

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

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

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

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

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

823
	return count;
824 825
}

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

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

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

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

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

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

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

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

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

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

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

908
	mutex_lock(&chip->reg_lock);
909

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

	if (ret < 0)
914
		return;
915 916

	mv88e6xxx_get_stats(chip, port, data);
917

918 919
}

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

	return 0;
}

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

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

	regs->version = 0;

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

946
	mutex_lock(&chip->reg_lock);
947

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

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

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

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

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

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

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

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

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

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

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

	return pvlan;
}

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

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

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

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

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

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

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

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

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

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

	return 0;
}

1052 1053 1054 1055 1056 1057 1058 1059 1060
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;
}

1061 1062 1063 1064 1065 1066 1067 1068
static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->pot_clear)
		return chip->info->ops->pot_clear(chip);

	return 0;
}

1069 1070 1071 1072 1073 1074 1075 1076
static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->mgmt_rsvd2cpu)
		return chip->info->ops->mgmt_rsvd2cpu(chip);

	return 0;
}

1077 1078
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
1079 1080
	int err;

1081 1082 1083 1084
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

1085 1086 1087 1088
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

1089 1090 1091
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111
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;
}

1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124
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;
}

1125 1126 1127 1128 1129 1130 1131 1132 1133
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)
1134
		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1135 1136 1137 1138

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

1139 1140
static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
{
1141 1142 1143
	int dev, port;
	int err;

1144 1145 1146 1147 1148 1149
	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.
	 */
1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162
	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;
1163 1164
}

1165 1166 1167 1168 1169 1170
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);
1171
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1172 1173 1174
	mutex_unlock(&chip->reg_lock);

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

1178 1179 1180 1181 1182 1183 1184 1185
static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
{
	if (!chip->info->max_vid)
		return 0;

	return mv88e6xxx_g1_vtu_flush(chip);
}

1186 1187 1188 1189 1190 1191 1192 1193 1194
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);
}

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

1204
static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1205 1206
{
	DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1207 1208 1209
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = chip->info->max_vid,
	};
1210
	int i, err;
1211 1212 1213

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

1214
	/* Set every FID bit used by the (un)bridged ports */
1215
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1216
		err = mv88e6xxx_port_get_fid(chip, i, fid);
1217 1218 1219 1220 1221 1222
		if (err)
			return err;

		set_bit(*fid, fid_bitmap);
	}

1223 1224
	/* Set every FID bit used by the VLAN entries */
	do {
1225
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1226 1227 1228 1229 1230 1231 1232
		if (err)
			return err;

		if (!vlan.valid)
			break;

		set_bit(vlan.fid, fid_bitmap);
1233
	} while (vlan.vid < chip->info->max_vid);
1234 1235 1236 1237 1238

	/* 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);
1239
	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1240 1241 1242
		return -ENOSPC;

	/* Clear the database */
1243
	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1244 1245
}

1246 1247
static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
			     struct mv88e6xxx_vtu_entry *entry, bool new)
1248 1249 1250 1251 1252 1253
{
	int err;

	if (!vid)
		return -EINVAL;

1254 1255
	entry->vid = vid - 1;
	entry->valid = false;
1256

1257
	err = mv88e6xxx_vtu_getnext(chip, entry);
1258 1259 1260
	if (err)
		return err;

1261 1262
	if (entry->vid == vid && entry->valid)
		return 0;
1263

1264 1265 1266 1267 1268 1269 1270 1271
	if (new) {
		int i;

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

1272
		/* Exclude all ports */
1273
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1274
			entry->member[i] =
1275
				MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1276 1277

		return mv88e6xxx_atu_new(chip, &entry->fid);
1278 1279
	}

1280 1281
	/* switchdev expects -EOPNOTSUPP to honor software VLANs */
	return -EOPNOTSUPP;
1282 1283
}

1284 1285 1286
static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
					u16 vid_begin, u16 vid_end)
{
V
Vivien Didelot 已提交
1287
	struct mv88e6xxx_chip *chip = ds->priv;
1288 1289 1290
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = vid_begin - 1,
	};
1291 1292
	int i, err;

1293 1294 1295 1296
	/* 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;

1297 1298 1299
	if (!vid_begin)
		return -EOPNOTSUPP;

1300
	mutex_lock(&chip->reg_lock);
1301 1302

	do {
1303
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1304 1305 1306 1307 1308 1309 1310 1311 1312
		if (err)
			goto unlock;

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

1313
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1314 1315 1316
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

1317
			if (!ds->ports[i].slave)
1318 1319
				continue;

1320
			if (vlan.member[i] ==
1321
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1322 1323
				continue;

V
Vivien Didelot 已提交
1324
			if (dsa_to_port(ds, i)->bridge_dev ==
1325
			    ds->ports[port].bridge_dev)
1326 1327
				break; /* same bridge, check next VLAN */

V
Vivien Didelot 已提交
1328
			if (!dsa_to_port(ds, i)->bridge_dev)
1329 1330
				continue;

1331 1332
			dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
				port, vlan.vid, i,
V
Vivien Didelot 已提交
1333
				netdev_name(dsa_to_port(ds, i)->bridge_dev));
1334 1335 1336 1337 1338 1339
			err = -EOPNOTSUPP;
			goto unlock;
		}
	} while (vlan.vid < vid_end);

unlock:
1340
	mutex_unlock(&chip->reg_lock);
1341 1342 1343 1344

	return err;
}

1345 1346
static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
					 bool vlan_filtering)
1347
{
V
Vivien Didelot 已提交
1348
	struct mv88e6xxx_chip *chip = ds->priv;
1349 1350
	u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
		MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
1351
	int err;
1352

1353
	if (!chip->info->max_vid)
1354 1355
		return -EOPNOTSUPP;

1356
	mutex_lock(&chip->reg_lock);
1357
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1358
	mutex_unlock(&chip->reg_lock);
1359

1360
	return err;
1361 1362
}

1363 1364
static int
mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1365
			    const struct switchdev_obj_port_vlan *vlan)
1366
{
V
Vivien Didelot 已提交
1367
	struct mv88e6xxx_chip *chip = ds->priv;
1368 1369
	int err;

1370
	if (!chip->info->max_vid)
1371 1372
		return -EOPNOTSUPP;

1373 1374 1375 1376 1377 1378 1379 1380
	/* 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;

1381 1382 1383 1384 1385 1386
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */
	return 0;
}

1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430
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);
}

1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453
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;
}

1454
static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
1455
				    u16 vid, u8 member)
1456
{
1457
	struct mv88e6xxx_vtu_entry vlan;
1458 1459
	int err;

1460
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
1461
	if (err)
1462
		return err;
1463

1464
	vlan.member[port] = member;
1465

1466 1467 1468 1469 1470
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
	if (err)
		return err;

	return mv88e6xxx_broadcast_setup(chip, vid);
1471 1472
}

1473
static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1474
				    const struct switchdev_obj_port_vlan *vlan)
1475
{
V
Vivien Didelot 已提交
1476
	struct mv88e6xxx_chip *chip = ds->priv;
1477 1478
	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1479
	u8 member;
1480 1481
	u16 vid;

1482
	if (!chip->info->max_vid)
1483 1484
		return;

1485
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1486
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1487
	else if (untagged)
1488
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
1489
	else
1490
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
1491

1492
	mutex_lock(&chip->reg_lock);
1493

1494
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
1495
		if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
1496 1497
			dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
				vid, untagged ? 'u' : 't');
1498

1499
	if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1500 1501
		dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
			vlan->vid_end);
1502

1503
	mutex_unlock(&chip->reg_lock);
1504 1505
}

1506
static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
1507
				    int port, u16 vid)
1508
{
1509
	struct mv88e6xxx_vtu_entry vlan;
1510 1511
	int i, err;

1512
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1513
	if (err)
1514
		return err;
1515

1516
	/* Tell switchdev if this VLAN is handled in software */
1517
	if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1518
		return -EOPNOTSUPP;
1519

1520
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1521 1522

	/* keep the VLAN unless all ports are excluded */
1523
	vlan.valid = false;
1524
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1525 1526
		if (vlan.member[i] !=
		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
1527
			vlan.valid = true;
1528 1529 1530 1531
			break;
		}
	}

1532
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1533 1534 1535
	if (err)
		return err;

1536
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
1537 1538
}

1539 1540
static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
				   const struct switchdev_obj_port_vlan *vlan)
1541
{
V
Vivien Didelot 已提交
1542
	struct mv88e6xxx_chip *chip = ds->priv;
1543 1544 1545
	u16 pvid, vid;
	int err = 0;

1546
	if (!chip->info->max_vid)
1547 1548
		return -EOPNOTSUPP;

1549
	mutex_lock(&chip->reg_lock);
1550

1551
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
1552 1553 1554
	if (err)
		goto unlock;

1555
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1556
		err = _mv88e6xxx_port_vlan_del(chip, port, vid);
1557 1558 1559 1560
		if (err)
			goto unlock;

		if (vid == pvid) {
1561
			err = mv88e6xxx_port_set_pvid(chip, port, 0);
1562 1563 1564 1565 1566
			if (err)
				goto unlock;
		}
	}

1567
unlock:
1568
	mutex_unlock(&chip->reg_lock);
1569 1570 1571 1572

	return err;
}

1573 1574
static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
				  const unsigned char *addr, u16 vid)
1575
{
V
Vivien Didelot 已提交
1576
	struct mv88e6xxx_chip *chip = ds->priv;
1577
	int err;
1578

1579
	mutex_lock(&chip->reg_lock);
1580 1581
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1582
	mutex_unlock(&chip->reg_lock);
1583 1584

	return err;
1585 1586
}

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

1593
	mutex_lock(&chip->reg_lock);
1594
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1595
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
1596
	mutex_unlock(&chip->reg_lock);
1597

1598
	return err;
1599 1600
}

1601 1602
static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
				      u16 fid, u16 vid, int port,
1603
				      dsa_fdb_dump_cb_t *cb, void *data)
1604
{
1605
	struct mv88e6xxx_atu_entry addr;
1606
	bool is_static;
1607 1608
	int err;

1609
	addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1610
	eth_broadcast_addr(addr.mac);
1611 1612

	do {
1613
		mutex_lock(&chip->reg_lock);
1614
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
1615
		mutex_unlock(&chip->reg_lock);
1616
		if (err)
1617
			return err;
1618

1619
		if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
1620 1621
			break;

1622
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
1623 1624
			continue;

1625 1626
		if (!is_unicast_ether_addr(addr.mac))
			continue;
1627

1628 1629 1630
		is_static = (addr.state ==
			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
		err = cb(addr.mac, vid, is_static, data);
1631 1632
		if (err)
			return err;
1633 1634 1635 1636 1637
	} while (!is_broadcast_ether_addr(addr.mac));

	return err;
}

1638
static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1639
				  dsa_fdb_dump_cb_t *cb, void *data)
1640
{
1641
	struct mv88e6xxx_vtu_entry vlan = {
1642
		.vid = chip->info->max_vid,
1643
	};
1644
	u16 fid;
1645 1646
	int err;

1647
	/* Dump port's default Filtering Information Database (VLAN ID 0) */
1648
	mutex_lock(&chip->reg_lock);
1649
	err = mv88e6xxx_port_get_fid(chip, port, &fid);
1650 1651
	mutex_unlock(&chip->reg_lock);

1652
	if (err)
1653
		return err;
1654

1655
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
1656
	if (err)
1657
		return err;
1658

1659
	/* Dump VLANs' Filtering Information Databases */
1660
	do {
1661
		mutex_lock(&chip->reg_lock);
1662
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1663
		mutex_unlock(&chip->reg_lock);
1664
		if (err)
1665
			return err;
1666 1667 1668 1669

		if (!vlan.valid)
			break;

1670
		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1671
						 cb, data);
1672
		if (err)
1673
			return err;
1674
	} while (vlan.vid < chip->info->max_vid);
1675

1676 1677 1678 1679
	return err;
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1680
				   dsa_fdb_dump_cb_t *cb, void *data)
1681
{
V
Vivien Didelot 已提交
1682
	struct mv88e6xxx_chip *chip = ds->priv;
1683

1684
	return mv88e6xxx_port_db_dump(chip, port, cb, data);
1685 1686
}

1687 1688
static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
				struct net_device *br)
1689
{
1690
	struct dsa_switch *ds;
1691
	int port;
1692
	int dev;
1693
	int err;
1694

1695 1696 1697 1698
	/* 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);
1699
			if (err)
1700
				return err;
1701 1702 1703
		}
	}

1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721
	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;
			}
		}
	}

1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732
	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);
1733
	mutex_unlock(&chip->reg_lock);
1734

1735
	return err;
1736 1737
}

1738 1739
static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
					struct net_device *br)
1740
{
V
Vivien Didelot 已提交
1741
	struct mv88e6xxx_chip *chip = ds->priv;
1742

1743
	mutex_lock(&chip->reg_lock);
1744 1745 1746
	if (mv88e6xxx_bridge_map(chip, br) ||
	    mv88e6xxx_port_vlan_map(chip, port))
		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
1747
	mutex_unlock(&chip->reg_lock);
1748 1749
}

1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779
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);
}

1780 1781 1782 1783 1784 1785 1786 1787
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->reset)
		return chip->info->ops->reset(chip);

	return 0;
}

1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800
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);
	}
}

1801
static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1802
{
1803
	int i, err;
1804

1805
	/* Set all ports to the Disabled state */
1806
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
1807
		err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
1808 1809
		if (err)
			return err;
1810 1811
	}

1812 1813 1814
	/* Wait for transmit queues to drain,
	 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
	 */
1815 1816
	usleep_range(2000, 4000);

1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827
	return 0;
}

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

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

1828
	mv88e6xxx_hardware_reset(chip);
1829

1830
	return mv88e6xxx_software_reset(chip);
1831 1832
}

1833
static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
1834 1835
				   enum mv88e6xxx_frame_mode frame,
				   enum mv88e6xxx_egress_mode egress, u16 etype)
1836 1837 1838
{
	int err;

1839 1840 1841 1842
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
1843 1844 1845
	if (err)
		return err;

1846 1847 1848 1849 1850 1851 1852 1853
	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;
1854 1855
}

1856
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1857
{
1858
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
1859
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
1860
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
1861
}
1862

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

1870 1871 1872 1873
static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port,
				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
1874 1875
				       MV88E6XXX_EGRESS_MODE_ETHERTYPE,
				       ETH_P_EDSA);
1876
}
1877

1878 1879 1880 1881
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);
1882

1883
	if (dsa_is_user_port(chip->ds, port))
1884
		return mv88e6xxx_set_port_mode_normal(chip, port);
1885

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

1890 1891
	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
		return mv88e6xxx_set_port_mode_edsa(chip, port);
1892

1893
	return -EINVAL;
1894 1895
}

1896
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
1897
{
1898
	bool message = dsa_is_dsa_port(chip->ds, port);
1899

1900
	return mv88e6xxx_port_set_message_port(chip, port, message);
1901
}
1902

1903
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
1904
{
1905 1906
	struct dsa_switch *ds = chip->ds;
	bool flood;
1907

1908
	/* Upstream ports flood frames with unknown unicast or multicast DA */
1909
	flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
1910 1911 1912
	if (chip->info->ops->port_set_egress_floods)
		return chip->info->ops->port_set_egress_floods(chip, port,
							       flood, flood);
1913

1914
	return 0;
1915 1916
}

1917 1918 1919
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
1920 1921
	if (chip->info->ops->serdes_power)
		return chip->info->ops->serdes_power(chip, port, on);
1922

1923
	return 0;
1924 1925
}

1926 1927 1928 1929 1930 1931
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

1932
	upstream_port = dsa_upstream_port(ds, port);
1933 1934 1935 1936 1937 1938 1939
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955
	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;
		}
	}

1956 1957 1958
	return 0;
}

1959
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
1960
{
1961
	struct dsa_switch *ds = chip->ds;
1962
	int err;
1963
	u16 reg;
1964

1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978
	/* 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;
1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993

	/* 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.
	 */
1994 1995 1996 1997
	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);
1998 1999
	if (err)
		return err;
2000

2001
	err = mv88e6xxx_setup_port_mode(chip, port);
2002 2003
	if (err)
		return err;
2004

2005
	err = mv88e6xxx_setup_egress_floods(chip, port);
2006 2007 2008
	if (err)
		return err;

2009 2010 2011
	/* 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.
2012
	 */
2013 2014 2015 2016 2017
	if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
		err = mv88e6xxx_serdes_power(chip, port, true);
		if (err)
			return err;
	}
2018

2019
	/* Port Control 2: don't force a good FCS, set the maximum frame size to
2020
	 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
2021 2022 2023
	 * 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.
2024
	 */
2025 2026 2027
	err = mv88e6xxx_port_set_map_da(chip, port);
	if (err)
		return err;
2028

2029 2030 2031
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
2032

2033
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
2034
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
2035 2036 2037
	if (err)
		return err;

2038 2039
	if (chip->info->ops->port_set_jumbo_size) {
		err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
2040 2041 2042 2043
		if (err)
			return err;
	}

2044 2045 2046 2047 2048
	/* 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.
	 */
2049
	reg = 1 << port;
2050 2051
	/* Disable learning for CPU port */
	if (dsa_is_cpu_port(ds, port))
2052
		reg = 0;
2053

2054 2055
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
2056 2057
	if (err)
		return err;
2058 2059

	/* Egress rate control 2: disable egress rate control. */
2060 2061
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
				   0x0000);
2062 2063
	if (err)
		return err;
2064

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

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

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

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

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

2095
	err = mv88e6xxx_setup_message_port(chip, port);
2096 2097
	if (err)
		return err;
2098

2099
	/* Port based VLAN map: give each port the same default address
2100 2101
	 * database, and allow bidirectional communication between the
	 * CPU and DSA port(s), and the other ports.
2102
	 */
2103
	err = mv88e6xxx_port_set_fid(chip, port, 0);
2104 2105
	if (err)
		return err;
2106

2107
	err = mv88e6xxx_port_vlan_map(chip, port);
2108 2109
	if (err)
		return err;
2110 2111 2112 2113

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

2117 2118 2119 2120
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
2121
	int err;
2122 2123

	mutex_lock(&chip->reg_lock);
2124
	err = mv88e6xxx_serdes_power(chip, port, true);
2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135
	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);
2136 2137
	if (mv88e6xxx_serdes_power(chip, port, false))
		dev_err(chip->dev, "failed to power off SERDES\n");
2138 2139 2140
	mutex_unlock(&chip->reg_lock);
}

2141 2142 2143
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
2144
	struct mv88e6xxx_chip *chip = ds->priv;
2145 2146 2147
	int err;

	mutex_lock(&chip->reg_lock);
2148
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2149 2150 2151 2152 2153
	mutex_unlock(&chip->reg_lock);

	return err;
}

2154
static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
2155
{
2156
	struct dsa_switch *ds = chip->ds;
2157
	int err;
2158

2159
	/* Disable remote management, and set the switch's DSA device number. */
2160 2161
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL2,
				 MV88E6XXX_G1_CTL2_MULTIPLE_CASCADE |
2162
				 (ds->index & 0x1f));
2163 2164 2165
	if (err)
		return err;

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

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

2197 2198 2199 2200 2201
	/* Initialize the statistics unit */
	err = mv88e6xxx_stats_set_histogram(chip);
	if (err)
		return err;

2202
	return mv88e6xxx_g1_stats_clear(chip);
2203 2204
}

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

2211
	chip->ds = ds;
2212
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
2213

2214
	mutex_lock(&chip->reg_lock);
2215

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

2221 2222 2223 2224 2225 2226 2227
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

	/* Setup Switch Global 1 Registers */
	err = mv88e6xxx_g1_setup(chip);
2228 2229 2230
	if (err)
		goto unlock;

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

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

2239 2240 2241 2242
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

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

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

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

2255 2256 2257 2258
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

2259 2260 2261 2262
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

2263 2264 2265
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
2266

2267 2268 2269 2270
	err = mv88e6xxx_trunk_setup(chip);
	if (err)
		goto unlock;

2271 2272 2273 2274
	err = mv88e6xxx_devmap_setup(chip);
	if (err)
		goto unlock;

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

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
2284 2285
	}

2286
unlock:
2287
	mutex_unlock(&chip->reg_lock);
2288

2289
	return err;
2290 2291
}

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

2299 2300 2301
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

2302
	mutex_lock(&chip->reg_lock);
2303
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
2304
	mutex_unlock(&chip->reg_lock);
2305

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

2314
	return err ? err : val;
2315 2316
}

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

2323 2324 2325
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

2326
	mutex_lock(&chip->reg_lock);
2327
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
2328
	mutex_unlock(&chip->reg_lock);
2329 2330

	return err;
2331 2332
}

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

2342 2343 2344 2345 2346 2347 2348 2349 2350
	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;
	}

2351
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
2352 2353 2354
	if (!bus)
		return -ENOMEM;

2355
	mdio_bus = bus->priv;
2356
	mdio_bus->bus = bus;
2357
	mdio_bus->chip = chip;
2358 2359
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
2360

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

2373 2374 2375 2376 2377 2378
	if (!external) {
		err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
		if (err)
			return err;
	}

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

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

	return 0;
2395
}
2396

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

2403 2404 2405 2406 2407 2408 2409 2410 2411
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;

2412 2413 2414
		if (!mdio_bus->external)
			mv88e6xxx_g2_irq_mdio_free(chip, bus);

2415 2416 2417 2418
		mdiobus_unregister(bus);
	}
}

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

	return 0;
2451 2452
}

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

	return chip->eeprom_len;
}

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

2466 2467
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
2468

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

2487 2488 2489
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

2490 2491 2492 2493
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

	mutex_lock(&chip->reg_lock);
2494
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
2495 2496 2497 2498 2499
	mutex_unlock(&chip->reg_lock);

	return err;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	[MV88E6131] = {
3486
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
3487 3488 3489 3490
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6131",
		.num_databases = 256,
		.num_ports = 8,
3491
		.num_internal_phys = 0,
3492
		.max_vid = 4095,
3493
		.port_base_addr = 0x10,
3494
		.global1_addr = 0x1b,
3495
		.global2_addr = 0x1c,
3496
		.age_time_coeff = 15000,
3497
		.g1_irqs = 9,
3498
		.atu_move_port_mask = 0xf,
3499
		.multi_chip = true,
3500
		.tag_protocol = DSA_TAG_PROTO_DSA,
3501
		.ops = &mv88e6131_ops,
3502 3503
	},

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

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

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

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

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

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

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

	[MV88E6185] = {
3655
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
3656 3657 3658 3659
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6185",
		.num_databases = 256,
		.num_ports = 10,
3660
		.num_internal_phys = 0,
3661
		.max_vid = 4095,
3662
		.port_base_addr = 0x10,
3663
		.global1_addr = 0x1b,
3664
		.global2_addr = 0x1c,
3665
		.age_time_coeff = 15000,
3666
		.g1_irqs = 8,
3667
		.atu_move_port_mask = 0xf,
3668
		.multi_chip = true,
3669
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3670
		.ops = &mv88e6185_ops,
3671 3672
	},

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

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

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

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

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

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

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

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

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

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

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

3963
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
3964
{
3965
	int i;
3966

3967 3968 3969
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
3970 3971 3972 3973

	return NULL;
}

3974
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
3975 3976
{
	const struct mv88e6xxx_info *info;
3977 3978 3979
	unsigned int prod_num, rev;
	u16 id;
	int err;
3980

3981
	mutex_lock(&chip->reg_lock);
3982
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
3983 3984 3985
	mutex_unlock(&chip->reg_lock);
	if (err)
		return err;
3986

3987 3988
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
3989 3990 3991 3992 3993

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

3994
	/* Update the compatible info with the probed one */
3995
	chip->info = info;
3996

3997 3998 3999 4000
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

4001 4002
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
4003 4004 4005 4006

	return 0;
}

4007
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
4008
{
4009
	struct mv88e6xxx_chip *chip;
4010

4011 4012
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
4013 4014
		return NULL;

4015
	chip->dev = dev;
4016

4017
	mutex_init(&chip->reg_lock);
4018
	INIT_LIST_HEAD(&chip->mdios);
4019

4020
	return chip;
4021 4022
}

4023
static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
4024 4025
			      struct mii_bus *bus, int sw_addr)
{
4026
	if (sw_addr == 0)
4027
		chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
4028
	else if (chip->info->multi_chip)
4029
		chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
4030 4031 4032
	else
		return -EINVAL;

4033 4034
	chip->bus = bus;
	chip->sw_addr = sw_addr;
4035 4036 4037 4038

	return 0;
}

4039 4040
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
							int port)
4041
{
V
Vivien Didelot 已提交
4042
	struct mv88e6xxx_chip *chip = ds->priv;
4043

4044
	return chip->info->tag_protocol;
4045 4046
}

4047
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
4048 4049 4050
static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
				       struct device *host_dev, int sw_addr,
				       void **priv)
4051
{
4052
	struct mv88e6xxx_chip *chip;
4053
	struct mii_bus *bus;
4054
	int err;
4055

4056
	bus = dsa_host_dev_to_mii_bus(host_dev);
4057 4058 4059
	if (!bus)
		return NULL;

4060 4061
	chip = mv88e6xxx_alloc_chip(dsa_dev);
	if (!chip)
4062 4063
		return NULL;

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

4067
	err = mv88e6xxx_smi_init(chip, bus, sw_addr);
4068 4069 4070
	if (err)
		goto free;

4071
	err = mv88e6xxx_detect(chip);
4072
	if (err)
4073
		goto free;
4074

4075 4076 4077 4078 4079 4080
	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_switch_reset(chip);
	mutex_unlock(&chip->reg_lock);
	if (err)
		goto free;

4081 4082
	mv88e6xxx_phy_init(chip);

4083
	err = mv88e6xxx_mdios_register(chip, NULL);
4084
	if (err)
4085
		goto free;
4086

4087
	*priv = chip;
4088

4089
	return chip->info->name;
4090
free:
4091
	devm_kfree(dsa_dev, chip);
4092 4093

	return NULL;
4094
}
4095
#endif
4096

4097
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4098
				      const struct switchdev_obj_port_mdb *mdb)
4099 4100 4101 4102 4103 4104 4105 4106 4107
{
	/* 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,
4108
				   const struct switchdev_obj_port_mdb *mdb)
4109
{
V
Vivien Didelot 已提交
4110
	struct mv88e6xxx_chip *chip = ds->priv;
4111 4112 4113

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

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4128
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
4129 4130 4131 4132 4133
	mutex_unlock(&chip->reg_lock);

	return err;
}

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

4177 4178 4179 4180
static struct dsa_switch_driver mv88e6xxx_switch_drv = {
	.ops			= &mv88e6xxx_switch_ops,
};

4181
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
4182
{
4183
	struct device *dev = chip->dev;
4184 4185
	struct dsa_switch *ds;

4186
	ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
4187 4188 4189
	if (!ds)
		return -ENOMEM;

4190
	ds->priv = chip;
4191
	ds->ops = &mv88e6xxx_switch_ops;
4192 4193
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
4194 4195 4196

	dev_set_drvdata(dev, ds);

4197
	return dsa_register_switch(ds);
4198 4199
}

4200
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
4201
{
4202
	dsa_unregister_switch(chip->ds);
4203 4204
}

4205
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
4206
{
4207
	struct device *dev = &mdiodev->dev;
4208
	struct device_node *np = dev->of_node;
4209
	const struct mv88e6xxx_info *compat_info;
4210
	struct mv88e6xxx_chip *chip;
4211
	u32 eeprom_len;
4212
	int err;
4213

4214 4215 4216 4217
	compat_info = of_device_get_match_data(dev);
	if (!compat_info)
		return -EINVAL;

4218 4219
	chip = mv88e6xxx_alloc_chip(dev);
	if (!chip)
4220 4221
		return -ENOMEM;

4222
	chip->info = compat_info;
4223

4224
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
4225 4226
	if (err)
		return err;
4227

4228 4229 4230 4231
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
	if (IS_ERR(chip->reset))
		return PTR_ERR(chip->reset);

4232
	err = mv88e6xxx_detect(chip);
4233 4234
	if (err)
		return err;
4235

4236 4237
	mv88e6xxx_phy_init(chip);

4238
	if (chip->info->ops->get_eeprom &&
4239
	    !of_property_read_u32(np, "eeprom-length", &eeprom_len))
4240
		chip->eeprom_len = eeprom_len;
4241

4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253
	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;
	}

4254
	/* Has to be performed before the MDIO bus is created, because
4255
	 * the PHYs will link their interrupts to these interrupt
4256 4257 4258 4259
	 * controllers
	 */
	mutex_lock(&chip->reg_lock);
	if (chip->irq > 0)
4260
		err = mv88e6xxx_g1_irq_setup(chip);
4261 4262 4263
	else
		err = mv88e6xxx_irq_poll_setup(chip);
	mutex_unlock(&chip->reg_lock);
4264

4265 4266
	if (err)
		goto out;
4267

4268 4269
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
4270
		if (err)
4271
			goto out_g1_irq;
4272 4273
	}

4274 4275 4276 4277 4278 4279 4280 4281
	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;

4282
	err = mv88e6xxx_mdios_register(chip, np);
4283
	if (err)
4284
		goto out_g1_vtu_prob_irq;
4285

4286
	err = mv88e6xxx_register_switch(chip);
4287 4288
	if (err)
		goto out_mdio;
4289

4290
	return 0;
4291 4292

out_mdio:
4293
	mv88e6xxx_mdios_unregister(chip);
4294
out_g1_vtu_prob_irq:
4295
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
4296
out_g1_atu_prob_irq:
4297
	mv88e6xxx_g1_atu_prob_irq_free(chip);
4298
out_g2_irq:
4299
	if (chip->info->g2_irqs > 0)
4300 4301
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
4302 4303
	mutex_lock(&chip->reg_lock);
	if (chip->irq > 0)
4304
		mv88e6xxx_g1_irq_free(chip);
4305 4306 4307
	else
		mv88e6xxx_irq_poll_free(chip);
	mutex_unlock(&chip->reg_lock);
4308 4309
out:
	return err;
4310
}
4311 4312 4313 4314

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

4317 4318
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
4319
		mv88e6xxx_ptp_free(chip);
4320
	}
4321

4322
	mv88e6xxx_phy_destroy(chip);
4323
	mv88e6xxx_unregister_switch(chip);
4324
	mv88e6xxx_mdios_unregister(chip);
4325

4326 4327 4328 4329 4330 4331 4332 4333
	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)
4334
		mv88e6xxx_g1_irq_free(chip);
4335 4336 4337
	else
		mv88e6xxx_irq_poll_free(chip);
	mutex_unlock(&chip->reg_lock);
4338 4339 4340
}

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

static void __exit mv88e6xxx_cleanup(void)
{
4372
	mdio_driver_unregister(&mv88e6xxx_driver);
4373
	unregister_switch_driver(&mv88e6xxx_switch_drv);
4374 4375
}
module_exit(mv88e6xxx_cleanup);
4376 4377 4378 4379

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