chip.c 127.8 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/platform_data/mv88e6xxx.h>
32
#include <linux/netdevice.h>
33
#include <linux/gpio/consumer.h>
34
#include <linux/phy.h>
35
#include <linux/phylink.h>
36
#include <net/dsa.h>
37

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

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

55 56 57 58 59 60 61 62 63 64
/* 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.
65
 */
66

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

73
	return chip->smi_ops->read(chip, addr, reg, val);
74 75
}

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

82
	return chip->smi_ops->write(chip, addr, reg, val);
83 84
}

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

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

	*val = ret & 0xffff;

	return 0;
}

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

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

	return 0;
}

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

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

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

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

	return -ETIMEDOUT;
}

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

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

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

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

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

159
	*val = ret & 0xffff;
160

161
	return 0;
162 163
}

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

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

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

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

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

	return 0;
}

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

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

202
	assert_reg_lock(chip);
203

204
	err = mv88e6xxx_smi_read(chip, addr, reg, val);
205 206 207
	if (err)
		return err;

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

	return 0;
}

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

218
	assert_reg_lock(chip);
219

220
	err = mv88e6xxx_smi_write(chip, addr, reg, val);
221 222 223
	if (err)
		return err;

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

227 228 229
	return 0;
}

230
struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
231 232 233 234 235 236 237 238 239 240 241
{
	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;
}

242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
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);
}

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

	mutex_lock(&chip->reg_lock);
267
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
	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);
}

284 285 286 287 288 289 290
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);
}

291 292 293 294 295 296 297 298 299 300 301 302 303 304
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;

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

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

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

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

320
static const struct irq_chip mv88e6xxx_g1_irq_chip = {
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
	.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,
};

346
/* To be called with reg_lock held */
347
static void mv88e6xxx_g1_irq_free_common(struct mv88e6xxx_chip *chip)
348 349
{
	int irq, virq;
350 351
	u16 mask;

352
	mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
353
	mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
354
	mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
355

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

361
	irq_domain_remove(chip->g1_irq.domain);
362 363
}

364 365
static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
{
366 367 368 369
	/*
	 * free_irq must be called without reg_lock taken because the irq
	 * handler takes this lock, too.
	 */
370
	free_irq(chip->irq, chip);
371 372 373 374

	mutex_lock(&chip->reg_lock);
	mv88e6xxx_g1_irq_free_common(chip);
	mutex_unlock(&chip->reg_lock);
375 376 377
}

static int mv88e6xxx_g1_irq_setup_common(struct mv88e6xxx_chip *chip)
378
{
379 380
	int err, irq, virq;
	u16 reg, mask;
381 382 383 384 385 386 387 388 389 390 391 392 393 394

	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;

395
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
396
	if (err)
397
		goto out_mapping;
398

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

401
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
402
	if (err)
403
		goto out_disable;
404 405

	/* Reading the interrupt status clears (most of) them */
406
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
407
	if (err)
408
		goto out_disable;
409 410 411

	return 0;

412
out_disable:
413
	mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
414
	mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
415 416 417 418 419 420 421 422

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);
423 424 425 426

	return err;
}

427 428 429 430 431 432 433 434 435 436
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,
437
				   IRQF_ONESHOT,
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 470 471 472 473 474 475 476 477 478 479 480
				   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)
{
	kthread_cancel_delayed_work_sync(&chip->irq_poll_work);
	kthread_destroy_worker(chip->kworker);
481 482 483 484

	mutex_lock(&chip->reg_lock);
	mv88e6xxx_g1_irq_free_common(chip);
	mutex_unlock(&chip->reg_lock);
485 486
}

487
int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask)
488
{
489
	int i;
490

491
	for (i = 0; i < 16; i++) {
492 493 494 495 496 497 498 499 500 501 502 503 504
		u16 val;
		int err;

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

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

		usleep_range(1000, 2000);
	}

505
	dev_err(chip->dev, "Timeout while waiting for switch\n");
506 507 508
	return -ETIMEDOUT;
}

509
/* Indirect write to single pointer-data register with an Update bit */
510
int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
511 512
{
	u16 val;
513
	int err;
514 515

	/* Wait until the previous operation is completed */
516 517 518
	err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
	if (err)
		return err;
519 520 521 522 523 524 525

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

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

526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557
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;
	}

558 559 560 561 562 563
	if (chip->info->ops->port_set_cmode) {
		err = chip->info->ops->port_set_cmode(chip, port, mode);
		if (err && err != -EOPNOTSUPP)
			goto restore_link;
	}

564 565 566
	err = 0;
restore_link:
	if (chip->info->ops->port_set_link(chip, port, link))
567
		dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
568 569 570 571

	return err;
}

572 573 574 575
/* 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.
 */
576 577
static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
				  struct phy_device *phydev)
578
{
V
Vivien Didelot 已提交
579
	struct mv88e6xxx_chip *chip = ds->priv;
580
	int err;
581 582 583 584

	if (!phy_is_pseudo_fixed_link(phydev))
		return;

585
	mutex_lock(&chip->reg_lock);
586 587
	err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
				       phydev->duplex, phydev->interface);
588
	mutex_unlock(&chip->reg_lock);
589 590

	if (err && err != -EOPNOTSUPP)
591
		dev_err(ds->dev, "p%d: failed to configure MAC\n", port);
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 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670
static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
			       unsigned long *supported,
			       struct phylink_link_state *state)
{
}

static int mv88e6xxx_link_state(struct dsa_switch *ds, int port,
				struct phylink_link_state *state)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_port_link_state(chip, port, state);
	mutex_unlock(&chip->reg_lock);

	return err;
}

static void mv88e6xxx_mac_config(struct dsa_switch *ds, int port,
				 unsigned int mode,
				 const struct phylink_link_state *state)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int speed, duplex, link, err;

	if (mode == MLO_AN_PHY)
		return;

	if (mode == MLO_AN_FIXED) {
		link = LINK_FORCED_UP;
		speed = state->speed;
		duplex = state->duplex;
	} else {
		speed = SPEED_UNFORCED;
		duplex = DUPLEX_UNFORCED;
		link = LINK_UNFORCED;
	}

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_port_setup_mac(chip, port, link, speed, duplex,
				       state->interface);
	mutex_unlock(&chip->reg_lock);

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

static void mv88e6xxx_mac_link_force(struct dsa_switch *ds, int port, int link)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

	mutex_lock(&chip->reg_lock);
	err = chip->info->ops->port_set_link(chip, port, link);
	mutex_unlock(&chip->reg_lock);

	if (err)
		dev_err(chip->dev, "p%d: failed to force MAC link\n", port);
}

static void mv88e6xxx_mac_link_down(struct dsa_switch *ds, int port,
				    unsigned int mode,
				    phy_interface_t interface)
{
	if (mode == MLO_AN_FIXED)
		mv88e6xxx_mac_link_force(ds, port, LINK_FORCED_DOWN);
}

static void mv88e6xxx_mac_link_up(struct dsa_switch *ds, int port,
				  unsigned int mode, phy_interface_t interface,
				  struct phy_device *phydev)
{
	if (mode == MLO_AN_FIXED)
		mv88e6xxx_mac_link_force(ds, port, LINK_FORCED_UP);
}

671
static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
672
{
673 674
	if (!chip->info->ops->stats_snapshot)
		return -EOPNOTSUPP;
675

676
	return chip->info->ops->stats_snapshot(chip, port);
677 678
}

679
static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738
	{ "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, },
739 740
};

741
static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
742
					    struct mv88e6xxx_hw_stat *s,
743 744
					    int port, u16 bank1_select,
					    u16 histogram)
745 746 747
{
	u32 low;
	u32 high = 0;
748
	u16 reg = 0;
749
	int err;
750 751
	u64 value;

752
	switch (s->type) {
753
	case STATS_TYPE_PORT:
754 755
		err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
		if (err)
756
			return U64_MAX;
757

758
		low = reg;
759
		if (s->size == 4) {
760 761
			err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
			if (err)
762
				return U64_MAX;
763
			high = reg;
764
		}
765
		break;
766
	case STATS_TYPE_BANK1:
767
		reg = bank1_select;
768 769
		/* fall through */
	case STATS_TYPE_BANK0:
770
		reg |= s->reg | histogram;
771
		mv88e6xxx_g1_stats_read(chip, reg, &low);
772
		if (s->size == 8)
773
			mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
774 775
		break;
	default:
776
		return U64_MAX;
777 778 779 780 781
	}
	value = (((u64)high) << 16) | low;
	return value;
}

782 783
static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data, int types)
784
{
785 786
	struct mv88e6xxx_hw_stat *stat;
	int i, j;
787

788 789
	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
		stat = &mv88e6xxx_hw_stats[i];
790
		if (stat->type & types) {
791 792 793 794
			memcpy(data + j * ETH_GSTRING_LEN, stat->string,
			       ETH_GSTRING_LEN);
			j++;
		}
795
	}
796 797

	return j;
798 799
}

800 801
static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
802
{
803 804
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_PORT);
805 806
}

807 808
static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
809
{
810 811
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
812 813
}

814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831
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);
}

832
static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
833
				  u32 stringset, uint8_t *data)
834
{
V
Vivien Didelot 已提交
835
	struct mv88e6xxx_chip *chip = ds->priv;
836
	int count = 0;
837

838 839 840
	if (stringset != ETH_SS_STATS)
		return;

841 842
	mutex_lock(&chip->reg_lock);

843
	if (chip->info->ops->stats_get_strings)
844 845 846 847
		count = chip->info->ops->stats_get_strings(chip, data);

	if (chip->info->ops->serdes_get_strings) {
		data += count * ETH_GSTRING_LEN;
848
		count = chip->info->ops->serdes_get_strings(chip, port, data);
849
	}
850

851 852 853
	data += count * ETH_GSTRING_LEN;
	mv88e6xxx_atu_vtu_get_strings(data);

854
	mutex_unlock(&chip->reg_lock);
855 856 857 858 859
}

static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
					  int types)
{
860 861 862 863 864
	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];
865
		if (stat->type & types)
866 867 868
			j++;
	}
	return j;
869 870
}

871 872 873 874 875 876 877 878 879 880 881 882
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);
}

883
static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
884 885
{
	struct mv88e6xxx_chip *chip = ds->priv;
886 887
	int serdes_count = 0;
	int count = 0;
888

889 890 891
	if (sset != ETH_SS_STATS)
		return 0;

892
	mutex_lock(&chip->reg_lock);
893
	if (chip->info->ops->stats_get_sset_count)
894 895 896 897 898 899 900
		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);
901
	if (serdes_count < 0) {
902
		count = serdes_count;
903 904 905 906 907
		goto out;
	}
	count += serdes_count;
	count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);

908
out:
909
	mutex_unlock(&chip->reg_lock);
910

911
	return count;
912 913
}

914 915 916
static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data, int types,
				     u16 bank1_select, u16 histogram)
917 918 919 920 921 922 923
{
	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) {
924
			mutex_lock(&chip->reg_lock);
925 926 927
			data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
							      bank1_select,
							      histogram);
928 929
			mutex_unlock(&chip->reg_lock);

930 931 932
			j++;
		}
	}
933
	return j;
934 935
}

936 937
static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
938 939
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
940
					 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
941
					 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
942 943
}

944 945
static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
946 947
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
948
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
949 950
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
					 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
951 952
}

953 954
static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
955 956 957
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
958 959
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
					 0);
960 961
}

962 963 964 965 966 967 968 969 970 971
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;
}

972 973 974
static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
				uint64_t *data)
{
975 976
	int count = 0;

977
	if (chip->info->ops->stats_get_stats)
978 979
		count = chip->info->ops->stats_get_stats(chip, port, data);

980
	mutex_lock(&chip->reg_lock);
981 982
	if (chip->info->ops->serdes_get_stats) {
		data += count;
983
		count = chip->info->ops->serdes_get_stats(chip, port, data);
984
	}
985 986 987
	data += count;
	mv88e6xxx_atu_vtu_get_stats(chip, port, data);
	mutex_unlock(&chip->reg_lock);
988 989
}

990 991
static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
					uint64_t *data)
992
{
V
Vivien Didelot 已提交
993
	struct mv88e6xxx_chip *chip = ds->priv;
994 995
	int ret;

996
	mutex_lock(&chip->reg_lock);
997

998
	ret = mv88e6xxx_stats_snapshot(chip, port);
999 1000 1001
	mutex_unlock(&chip->reg_lock);

	if (ret < 0)
1002
		return;
1003 1004

	mv88e6xxx_get_stats(chip, port, data);
1005

1006 1007
}

1008
static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
1009 1010 1011 1012
{
	return 32 * sizeof(u16);
}

1013 1014
static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
			       struct ethtool_regs *regs, void *_p)
1015
{
V
Vivien Didelot 已提交
1016
	struct mv88e6xxx_chip *chip = ds->priv;
1017 1018
	int err;
	u16 reg;
1019 1020 1021 1022 1023 1024 1025
	u16 *p = _p;
	int i;

	regs->version = 0;

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

1026
	mutex_lock(&chip->reg_lock);
1027

1028 1029
	for (i = 0; i < 32; i++) {

1030 1031 1032
		err = mv88e6xxx_port_read(chip, port, i, &reg);
		if (!err)
			p[i] = reg;
1033
	}
1034

1035
	mutex_unlock(&chip->reg_lock);
1036 1037
}

V
Vivien Didelot 已提交
1038 1039
static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
1040
{
1041 1042
	/* Nothing to do on the port's MAC */
	return 0;
1043 1044
}

V
Vivien Didelot 已提交
1045 1046
static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
1047
{
1048 1049
	/* Nothing to do on the port's MAC */
	return 0;
1050 1051
}

1052
static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
1053
{
1054 1055 1056
	struct dsa_switch *ds = NULL;
	struct net_device *br;
	u16 pvlan;
1057 1058
	int i;

1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078
	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 已提交
1079
		    (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
1080 1081 1082 1083 1084
			pvlan |= BIT(i);

	return pvlan;
}

1085
static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
1086 1087
{
	u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
1088 1089 1090

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

1092
	return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
1093 1094
}

1095 1096
static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
					 u8 state)
1097
{
V
Vivien Didelot 已提交
1098
	struct mv88e6xxx_chip *chip = ds->priv;
1099
	int err;
1100

1101
	mutex_lock(&chip->reg_lock);
1102
	err = mv88e6xxx_port_set_state(chip, port, state);
1103
	mutex_unlock(&chip->reg_lock);
1104 1105

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

1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127
static int mv88e6xxx_pri_setup(struct mv88e6xxx_chip *chip)
{
	int err;

	if (chip->info->ops->ieee_pri_map) {
		err = chip->info->ops->ieee_pri_map(chip);
		if (err)
			return err;
	}

	if (chip->info->ops->ip_pri_map) {
		err = chip->info->ops->ip_pri_map(chip);
		if (err)
			return err;
	}

	return 0;
}

1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147
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;
	}

1148 1149 1150 1151 1152 1153 1154
	if (chip->info->ops->set_cascade_port) {
		port = MV88E6XXX_CASCADE_PORT_MULTIPLE;
		err = chip->info->ops->set_cascade_port(chip, port);
		if (err)
			return err;
	}

1155 1156 1157 1158
	err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
	if (err)
		return err;

1159 1160 1161
	return 0;
}

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

1171 1172 1173 1174 1175 1176 1177 1178
static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->rmu_disable)
		return chip->info->ops->rmu_disable(chip);

	return 0;
}

1179 1180 1181 1182 1183 1184 1185 1186
static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->pot_clear)
		return chip->info->ops->pot_clear(chip);

	return 0;
}

1187 1188 1189 1190 1191 1192 1193 1194
static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->mgmt_rsvd2cpu)
		return chip->info->ops->mgmt_rsvd2cpu(chip);

	return 0;
}

1195 1196
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
1197 1198
	int err;

1199 1200 1201 1202
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

1203 1204 1205 1206
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

1207 1208 1209
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229
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;
}

1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242
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;
}

1243 1244 1245 1246 1247 1248 1249 1250 1251
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)
1252
		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1253 1254 1255 1256

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

1257 1258
static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
{
1259 1260 1261
	int dev, port;
	int err;

1262 1263 1264 1265 1266 1267
	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.
	 */
1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280
	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;
1281 1282
}

1283 1284 1285 1286 1287 1288
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);
1289
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1290 1291 1292
	mutex_unlock(&chip->reg_lock);

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

1296 1297 1298 1299 1300 1301 1302 1303
static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
{
	if (!chip->info->max_vid)
		return 0;

	return mv88e6xxx_g1_vtu_flush(chip);
}

1304 1305 1306 1307 1308 1309 1310 1311 1312
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);
}

1313 1314 1315 1316 1317 1318 1319 1320 1321
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);
}

1322
static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1323 1324
{
	DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1325 1326 1327
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = chip->info->max_vid,
	};
1328
	int i, err;
1329 1330 1331

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

1332
	/* Set every FID bit used by the (un)bridged ports */
1333
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1334
		err = mv88e6xxx_port_get_fid(chip, i, fid);
1335 1336 1337 1338 1339 1340
		if (err)
			return err;

		set_bit(*fid, fid_bitmap);
	}

1341 1342
	/* Set every FID bit used by the VLAN entries */
	do {
1343
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1344 1345 1346 1347 1348 1349 1350
		if (err)
			return err;

		if (!vlan.valid)
			break;

		set_bit(vlan.fid, fid_bitmap);
1351
	} while (vlan.vid < chip->info->max_vid);
1352 1353 1354 1355 1356

	/* 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);
1357
	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1358 1359 1360
		return -ENOSPC;

	/* Clear the database */
1361
	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1362 1363
}

1364 1365
static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
			     struct mv88e6xxx_vtu_entry *entry, bool new)
1366 1367 1368 1369 1370 1371
{
	int err;

	if (!vid)
		return -EINVAL;

1372 1373
	entry->vid = vid - 1;
	entry->valid = false;
1374

1375
	err = mv88e6xxx_vtu_getnext(chip, entry);
1376 1377 1378
	if (err)
		return err;

1379 1380
	if (entry->vid == vid && entry->valid)
		return 0;
1381

1382 1383 1384 1385 1386 1387 1388 1389
	if (new) {
		int i;

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

1390
		/* Exclude all ports */
1391
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1392
			entry->member[i] =
1393
				MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1394 1395

		return mv88e6xxx_atu_new(chip, &entry->fid);
1396 1397
	}

1398 1399
	/* switchdev expects -EOPNOTSUPP to honor software VLANs */
	return -EOPNOTSUPP;
1400 1401
}

1402 1403 1404
static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
					u16 vid_begin, u16 vid_end)
{
V
Vivien Didelot 已提交
1405
	struct mv88e6xxx_chip *chip = ds->priv;
1406 1407 1408
	struct mv88e6xxx_vtu_entry vlan = {
		.vid = vid_begin - 1,
	};
1409 1410
	int i, err;

1411 1412 1413 1414
	/* 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;

1415 1416 1417
	if (!vid_begin)
		return -EOPNOTSUPP;

1418
	mutex_lock(&chip->reg_lock);
1419 1420

	do {
1421
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1422 1423 1424 1425 1426 1427 1428 1429 1430
		if (err)
			goto unlock;

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

1431
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1432 1433 1434
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

1435
			if (!ds->ports[i].slave)
1436 1437
				continue;

1438
			if (vlan.member[i] ==
1439
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1440 1441
				continue;

V
Vivien Didelot 已提交
1442
			if (dsa_to_port(ds, i)->bridge_dev ==
1443
			    ds->ports[port].bridge_dev)
1444 1445
				break; /* same bridge, check next VLAN */

V
Vivien Didelot 已提交
1446
			if (!dsa_to_port(ds, i)->bridge_dev)
1447 1448
				continue;

1449 1450
			dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
				port, vlan.vid, i,
V
Vivien Didelot 已提交
1451
				netdev_name(dsa_to_port(ds, i)->bridge_dev));
1452 1453 1454 1455 1456 1457
			err = -EOPNOTSUPP;
			goto unlock;
		}
	} while (vlan.vid < vid_end);

unlock:
1458
	mutex_unlock(&chip->reg_lock);
1459 1460 1461 1462

	return err;
}

1463 1464
static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
					 bool vlan_filtering)
1465
{
V
Vivien Didelot 已提交
1466
	struct mv88e6xxx_chip *chip = ds->priv;
1467 1468
	u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
		MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
1469
	int err;
1470

1471
	if (!chip->info->max_vid)
1472 1473
		return -EOPNOTSUPP;

1474
	mutex_lock(&chip->reg_lock);
1475
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1476
	mutex_unlock(&chip->reg_lock);
1477

1478
	return err;
1479 1480
}

1481 1482
static int
mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1483
			    const struct switchdev_obj_port_vlan *vlan)
1484
{
V
Vivien Didelot 已提交
1485
	struct mv88e6xxx_chip *chip = ds->priv;
1486 1487
	int err;

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

1491 1492 1493 1494 1495 1496 1497 1498
	/* 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;

1499 1500 1501 1502 1503 1504
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */
	return 0;
}

1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548
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);
}

1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571
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;
}

1572
static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
1573
				    u16 vid, u8 member)
1574
{
1575
	struct mv88e6xxx_vtu_entry vlan;
1576 1577
	int err;

1578
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
1579
	if (err)
1580
		return err;
1581

1582
	vlan.member[port] = member;
1583

1584 1585 1586 1587 1588
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
	if (err)
		return err;

	return mv88e6xxx_broadcast_setup(chip, vid);
1589 1590
}

1591
static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1592
				    const struct switchdev_obj_port_vlan *vlan)
1593
{
V
Vivien Didelot 已提交
1594
	struct mv88e6xxx_chip *chip = ds->priv;
1595 1596
	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1597
	u8 member;
1598 1599
	u16 vid;

1600
	if (!chip->info->max_vid)
1601 1602
		return;

1603
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1604
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1605
	else if (untagged)
1606
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
1607
	else
1608
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
1609

1610
	mutex_lock(&chip->reg_lock);
1611

1612
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
1613
		if (_mv88e6xxx_port_vlan_add(chip, port, vid, member))
1614 1615
			dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
				vid, untagged ? 'u' : 't');
1616

1617
	if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1618 1619
		dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
			vlan->vid_end);
1620

1621
	mutex_unlock(&chip->reg_lock);
1622 1623
}

1624
static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
1625
				    int port, u16 vid)
1626
{
1627
	struct mv88e6xxx_vtu_entry vlan;
1628 1629
	int i, err;

1630
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1631
	if (err)
1632
		return err;
1633

1634
	/* Tell switchdev if this VLAN is handled in software */
1635
	if (vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1636
		return -EOPNOTSUPP;
1637

1638
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1639 1640

	/* keep the VLAN unless all ports are excluded */
1641
	vlan.valid = false;
1642
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1643 1644
		if (vlan.member[i] !=
		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
1645
			vlan.valid = true;
1646 1647 1648 1649
			break;
		}
	}

1650
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1651 1652 1653
	if (err)
		return err;

1654
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
1655 1656
}

1657 1658
static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
				   const struct switchdev_obj_port_vlan *vlan)
1659
{
V
Vivien Didelot 已提交
1660
	struct mv88e6xxx_chip *chip = ds->priv;
1661 1662 1663
	u16 pvid, vid;
	int err = 0;

1664
	if (!chip->info->max_vid)
1665 1666
		return -EOPNOTSUPP;

1667
	mutex_lock(&chip->reg_lock);
1668

1669
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
1670 1671 1672
	if (err)
		goto unlock;

1673
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1674
		err = _mv88e6xxx_port_vlan_del(chip, port, vid);
1675 1676 1677 1678
		if (err)
			goto unlock;

		if (vid == pvid) {
1679
			err = mv88e6xxx_port_set_pvid(chip, port, 0);
1680 1681 1682 1683 1684
			if (err)
				goto unlock;
		}
	}

1685
unlock:
1686
	mutex_unlock(&chip->reg_lock);
1687 1688 1689 1690

	return err;
}

1691 1692
static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
				  const unsigned char *addr, u16 vid)
1693
{
V
Vivien Didelot 已提交
1694
	struct mv88e6xxx_chip *chip = ds->priv;
1695
	int err;
1696

1697
	mutex_lock(&chip->reg_lock);
1698 1699
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1700
	mutex_unlock(&chip->reg_lock);
1701 1702

	return err;
1703 1704
}

1705
static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1706
				  const unsigned char *addr, u16 vid)
1707
{
V
Vivien Didelot 已提交
1708
	struct mv88e6xxx_chip *chip = ds->priv;
1709
	int err;
1710

1711
	mutex_lock(&chip->reg_lock);
1712
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1713
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
1714
	mutex_unlock(&chip->reg_lock);
1715

1716
	return err;
1717 1718
}

1719 1720
static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
				      u16 fid, u16 vid, int port,
1721
				      dsa_fdb_dump_cb_t *cb, void *data)
1722
{
1723
	struct mv88e6xxx_atu_entry addr;
1724
	bool is_static;
1725 1726
	int err;

1727
	addr.state = MV88E6XXX_G1_ATU_DATA_STATE_UNUSED;
1728
	eth_broadcast_addr(addr.mac);
1729 1730

	do {
1731
		mutex_lock(&chip->reg_lock);
1732
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
1733
		mutex_unlock(&chip->reg_lock);
1734
		if (err)
1735
			return err;
1736

1737
		if (addr.state == MV88E6XXX_G1_ATU_DATA_STATE_UNUSED)
1738 1739
			break;

1740
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
1741 1742
			continue;

1743 1744
		if (!is_unicast_ether_addr(addr.mac))
			continue;
1745

1746 1747 1748
		is_static = (addr.state ==
			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
		err = cb(addr.mac, vid, is_static, data);
1749 1750
		if (err)
			return err;
1751 1752 1753 1754 1755
	} while (!is_broadcast_ether_addr(addr.mac));

	return err;
}

1756
static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
1757
				  dsa_fdb_dump_cb_t *cb, void *data)
1758
{
1759
	struct mv88e6xxx_vtu_entry vlan = {
1760
		.vid = chip->info->max_vid,
1761
	};
1762
	u16 fid;
1763 1764
	int err;

1765
	/* Dump port's default Filtering Information Database (VLAN ID 0) */
1766
	mutex_lock(&chip->reg_lock);
1767
	err = mv88e6xxx_port_get_fid(chip, port, &fid);
1768 1769
	mutex_unlock(&chip->reg_lock);

1770
	if (err)
1771
		return err;
1772

1773
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
1774
	if (err)
1775
		return err;
1776

1777
	/* Dump VLANs' Filtering Information Databases */
1778
	do {
1779
		mutex_lock(&chip->reg_lock);
1780
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1781
		mutex_unlock(&chip->reg_lock);
1782
		if (err)
1783
			return err;
1784 1785 1786 1787

		if (!vlan.valid)
			break;

1788
		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
1789
						 cb, data);
1790
		if (err)
1791
			return err;
1792
	} while (vlan.vid < chip->info->max_vid);
1793

1794 1795 1796 1797
	return err;
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
1798
				   dsa_fdb_dump_cb_t *cb, void *data)
1799
{
V
Vivien Didelot 已提交
1800
	struct mv88e6xxx_chip *chip = ds->priv;
1801

1802
	return mv88e6xxx_port_db_dump(chip, port, cb, data);
1803 1804
}

1805 1806
static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
				struct net_device *br)
1807
{
1808
	struct dsa_switch *ds;
1809
	int port;
1810
	int dev;
1811
	int err;
1812

1813 1814 1815 1816
	/* 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);
1817
			if (err)
1818
				return err;
1819 1820 1821
		}
	}

1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839
	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;
			}
		}
	}

1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850
	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);
1851
	mutex_unlock(&chip->reg_lock);
1852

1853
	return err;
1854 1855
}

1856 1857
static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
					struct net_device *br)
1858
{
V
Vivien Didelot 已提交
1859
	struct mv88e6xxx_chip *chip = ds->priv;
1860

1861
	mutex_lock(&chip->reg_lock);
1862 1863 1864
	if (mv88e6xxx_bridge_map(chip, br) ||
	    mv88e6xxx_port_vlan_map(chip, port))
		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
1865
	mutex_unlock(&chip->reg_lock);
1866 1867
}

1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897
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);
}

1898 1899 1900 1901 1902 1903 1904 1905
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->reset)
		return chip->info->ops->reset(chip);

	return 0;
}

1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918
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);
	}
}

1919
static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
1920
{
1921
	int i, err;
1922

1923
	/* Set all ports to the Disabled state */
1924
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
1925
		err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
1926 1927
		if (err)
			return err;
1928 1929
	}

1930 1931 1932
	/* Wait for transmit queues to drain,
	 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
	 */
1933 1934
	usleep_range(2000, 4000);

1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945
	return 0;
}

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

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

1946
	mv88e6xxx_hardware_reset(chip);
1947

1948
	return mv88e6xxx_software_reset(chip);
1949 1950
}

1951
static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
1952 1953
				   enum mv88e6xxx_frame_mode frame,
				   enum mv88e6xxx_egress_mode egress, u16 etype)
1954 1955 1956
{
	int err;

1957 1958 1959 1960
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
1961 1962 1963
	if (err)
		return err;

1964 1965 1966 1967 1968 1969 1970 1971
	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;
1972 1973
}

1974
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1975
{
1976
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
1977
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
1978
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
1979
}
1980

1981 1982 1983
static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
1984
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
1985
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
1986
}
1987

1988 1989 1990 1991
static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port,
				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
1992 1993
				       MV88E6XXX_EGRESS_MODE_ETHERTYPE,
				       ETH_P_EDSA);
1994
}
1995

1996 1997 1998 1999
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);
2000

2001
	if (dsa_is_user_port(chip->ds, port))
2002
		return mv88e6xxx_set_port_mode_normal(chip, port);
2003

2004 2005 2006
	/* 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);
2007

2008 2009
	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
		return mv88e6xxx_set_port_mode_edsa(chip, port);
2010

2011
	return -EINVAL;
2012 2013
}

2014
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2015
{
2016
	bool message = dsa_is_dsa_port(chip->ds, port);
2017

2018
	return mv88e6xxx_port_set_message_port(chip, port, message);
2019
}
2020

2021
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2022
{
2023 2024
	struct dsa_switch *ds = chip->ds;
	bool flood;
2025

2026
	/* Upstream ports flood frames with unknown unicast or multicast DA */
2027
	flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
2028 2029 2030
	if (chip->info->ops->port_set_egress_floods)
		return chip->info->ops->port_set_egress_floods(chip, port,
							       flood, flood);
2031

2032
	return 0;
2033 2034
}

2035 2036 2037
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
2038 2039
	if (chip->info->ops->serdes_power)
		return chip->info->ops->serdes_power(chip, port, on);
2040

2041
	return 0;
2042 2043
}

2044 2045 2046 2047 2048 2049
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

2050
	upstream_port = dsa_upstream_port(ds, port);
2051 2052 2053 2054 2055 2056 2057
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073
	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;
		}
	}

2074 2075 2076
	return 0;
}

2077
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
2078
{
2079
	struct dsa_switch *ds = chip->ds;
2080
	int err;
2081
	u16 reg;
2082

2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096
	/* 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;
2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111

	/* 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.
	 */
2112 2113 2114 2115
	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);
2116 2117
	if (err)
		return err;
2118

2119
	err = mv88e6xxx_setup_port_mode(chip, port);
2120 2121
	if (err)
		return err;
2122

2123
	err = mv88e6xxx_setup_egress_floods(chip, port);
2124 2125 2126
	if (err)
		return err;

2127 2128 2129
	/* 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.
2130
	 */
2131 2132 2133 2134 2135
	if ((dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) {
		err = mv88e6xxx_serdes_power(chip, port, true);
		if (err)
			return err;
	}
2136

2137
	/* Port Control 2: don't force a good FCS, set the maximum frame size to
2138
	 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
2139 2140 2141
	 * 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.
2142
	 */
2143 2144 2145
	err = mv88e6xxx_port_set_map_da(chip, port);
	if (err)
		return err;
2146

2147 2148 2149
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
2150

2151
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
2152
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
2153 2154 2155
	if (err)
		return err;

2156 2157
	if (chip->info->ops->port_set_jumbo_size) {
		err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
2158 2159 2160 2161
		if (err)
			return err;
	}

2162 2163 2164 2165 2166
	/* 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.
	 */
2167
	reg = 1 << port;
2168 2169
	/* Disable learning for CPU port */
	if (dsa_is_cpu_port(ds, port))
2170
		reg = 0;
2171

2172 2173
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
2174 2175
	if (err)
		return err;
2176 2177

	/* Egress rate control 2: disable egress rate control. */
2178 2179
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
				   0x0000);
2180 2181
	if (err)
		return err;
2182

2183 2184
	if (chip->info->ops->port_pause_limit) {
		err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
2185 2186
		if (err)
			return err;
2187
	}
2188

2189 2190 2191 2192 2193 2194
	if (chip->info->ops->port_disable_learn_limit) {
		err = chip->info->ops->port_disable_learn_limit(chip, port);
		if (err)
			return err;
	}

2195 2196
	if (chip->info->ops->port_disable_pri_override) {
		err = chip->info->ops->port_disable_pri_override(chip, port);
2197 2198
		if (err)
			return err;
2199
	}
2200

2201 2202
	if (chip->info->ops->port_tag_remap) {
		err = chip->info->ops->port_tag_remap(chip, port);
2203 2204
		if (err)
			return err;
2205 2206
	}

2207 2208
	if (chip->info->ops->port_egress_rate_limiting) {
		err = chip->info->ops->port_egress_rate_limiting(chip, port);
2209 2210
		if (err)
			return err;
2211 2212
	}

2213
	err = mv88e6xxx_setup_message_port(chip, port);
2214 2215
	if (err)
		return err;
2216

2217
	/* Port based VLAN map: give each port the same default address
2218 2219
	 * database, and allow bidirectional communication between the
	 * CPU and DSA port(s), and the other ports.
2220
	 */
2221
	err = mv88e6xxx_port_set_fid(chip, port, 0);
2222 2223
	if (err)
		return err;
2224

2225
	err = mv88e6xxx_port_vlan_map(chip, port);
2226 2227
	if (err)
		return err;
2228 2229 2230 2231

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

2235 2236 2237 2238
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
2239
	int err;
2240 2241

	mutex_lock(&chip->reg_lock);
2242
	err = mv88e6xxx_serdes_power(chip, port, true);
2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253
	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);
2254 2255
	if (mv88e6xxx_serdes_power(chip, port, false))
		dev_err(chip->dev, "failed to power off SERDES\n");
2256 2257 2258
	mutex_unlock(&chip->reg_lock);
}

2259 2260 2261
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
2262
	struct mv88e6xxx_chip *chip = ds->priv;
2263 2264 2265
	int err;

	mutex_lock(&chip->reg_lock);
2266
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2267 2268 2269 2270 2271
	mutex_unlock(&chip->reg_lock);

	return err;
}

2272
static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
2273
{
2274
	int err;
2275

2276
	/* Initialize the statistics unit */
2277 2278 2279 2280 2281
	if (chip->info->ops->stats_set_histogram) {
		err = chip->info->ops->stats_set_histogram(chip);
		if (err)
			return err;
	}
2282

2283
	return mv88e6xxx_g1_stats_clear(chip);
2284 2285
}

2286
static int mv88e6xxx_setup(struct dsa_switch *ds)
2287
{
V
Vivien Didelot 已提交
2288
	struct mv88e6xxx_chip *chip = ds->priv;
2289
	int err;
2290 2291
	int i;

2292
	chip->ds = ds;
2293
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
2294

2295
	mutex_lock(&chip->reg_lock);
2296

2297
	/* Setup Switch Port Registers */
2298
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2299 2300 2301
		if (dsa_is_unused_port(ds, i))
			continue;

2302 2303 2304 2305 2306
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

2307 2308 2309 2310
	err = mv88e6xxx_irl_setup(chip);
	if (err)
		goto unlock;

2311 2312 2313 2314
	err = mv88e6xxx_mac_setup(chip);
	if (err)
		goto unlock;

2315 2316 2317 2318
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

2319 2320 2321 2322
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

2323 2324 2325 2326
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

2327 2328 2329 2330
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

2331 2332 2333 2334
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

2335 2336 2337 2338
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

2339 2340 2341 2342
	err = mv88e6xxx_rmu_setup(chip);
	if (err)
		goto unlock;

2343 2344 2345
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
2346

2347 2348 2349 2350
	err = mv88e6xxx_trunk_setup(chip);
	if (err)
		goto unlock;

2351 2352 2353 2354
	err = mv88e6xxx_devmap_setup(chip);
	if (err)
		goto unlock;

2355 2356 2357 2358
	err = mv88e6xxx_pri_setup(chip);
	if (err)
		goto unlock;

2359
	/* Setup PTP Hardware Clock and timestamping */
2360 2361 2362 2363
	if (chip->info->ptp_support) {
		err = mv88e6xxx_ptp_setup(chip);
		if (err)
			goto unlock;
2364 2365 2366 2367

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
2368 2369
	}

2370 2371 2372 2373
	err = mv88e6xxx_stats_setup(chip);
	if (err)
		goto unlock;

2374
unlock:
2375
	mutex_unlock(&chip->reg_lock);
2376

2377
	return err;
2378 2379
}

2380
static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
2381
{
2382 2383
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2384 2385
	u16 val;
	int err;
2386

2387 2388 2389
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

2390
	mutex_lock(&chip->reg_lock);
2391
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
2392
	mutex_unlock(&chip->reg_lock);
2393

2394 2395 2396 2397 2398
	if (reg == MII_PHYSID2) {
		/* Some internal PHYS don't have a model number.  Use
		 * the mv88e6390 family model number instead.
		 */
		if (!(val & 0x3f0))
2399
			val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
2400 2401
	}

2402
	return err ? err : val;
2403 2404
}

2405
static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
2406
{
2407 2408
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2409
	int err;
2410

2411 2412 2413
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

2414
	mutex_lock(&chip->reg_lock);
2415
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
2416
	mutex_unlock(&chip->reg_lock);
2417 2418

	return err;
2419 2420
}

2421
static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
2422 2423
				   struct device_node *np,
				   bool external)
2424 2425
{
	static int index;
2426
	struct mv88e6xxx_mdio_bus *mdio_bus;
2427 2428 2429
	struct mii_bus *bus;
	int err;

2430 2431 2432 2433 2434 2435 2436 2437 2438
	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;
	}

2439
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
2440 2441 2442
	if (!bus)
		return -ENOMEM;

2443
	mdio_bus = bus->priv;
2444
	mdio_bus->bus = bus;
2445
	mdio_bus->chip = chip;
2446 2447
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
2448

2449 2450
	if (np) {
		bus->name = np->full_name;
2451
		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
2452 2453 2454 2455 2456 2457 2458
	} 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;
2459
	bus->parent = chip->dev;
2460

2461 2462 2463 2464 2465 2466
	if (!external) {
		err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
		if (err)
			return err;
	}

2467
	err = of_mdiobus_register(bus, np);
2468
	if (err) {
2469
		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
2470
		mv88e6xxx_g2_irq_mdio_free(chip, bus);
2471
		return err;
2472
	}
2473 2474 2475 2476 2477

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

	return 0;
2480
}
2481

2482 2483 2484 2485 2486
static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
	{ .compatible = "marvell,mv88e6xxx-mdio-external",
	  .data = (void *)true },
	{ },
};
2487

2488 2489 2490 2491 2492 2493 2494 2495 2496
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;

2497 2498 2499
		if (!mdio_bus->external)
			mv88e6xxx_g2_irq_mdio_free(chip, bus);

2500 2501 2502 2503
		mdiobus_unregister(bus);
	}
}

2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527
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);
2528 2529
			if (err) {
				mv88e6xxx_mdios_unregister(chip);
2530
				return err;
2531
			}
2532 2533 2534 2535
		}
	}

	return 0;
2536 2537
}

2538 2539
static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
2540
	struct mv88e6xxx_chip *chip = ds->priv;
2541 2542 2543 2544 2545 2546 2547

	return chip->eeprom_len;
}

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

2551 2552
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
2553

2554 2555
	mutex_lock(&chip->reg_lock);
	err = chip->info->ops->get_eeprom(chip, eeprom, data);
2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568
	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 已提交
2569
	struct mv88e6xxx_chip *chip = ds->priv;
2570 2571
	int err;

2572 2573 2574
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

2575 2576 2577 2578
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

	mutex_lock(&chip->reg_lock);
2579
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
2580 2581 2582 2583 2584
	mutex_unlock(&chip->reg_lock);

	return err;
}

2585
static const struct mv88e6xxx_ops mv88e6085_ops = {
2586
	/* MV88E6XXX_FAMILY_6097 */
2587 2588
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2589
	.irl_init_all = mv88e6352_g2_irl_init_all,
2590
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2591 2592
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2593
	.port_set_link = mv88e6xxx_port_set_link,
2594
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2595
	.port_set_speed = mv88e6185_port_set_speed,
2596
	.port_tag_remap = mv88e6095_port_tag_remap,
2597
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2598
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2599
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2600
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2601
	.port_pause_limit = mv88e6097_port_pause_limit,
2602
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2603
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2604
	.stats_snapshot = mv88e6xxx_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 2615
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2616
	.reset = mv88e6185_g1_reset,
2617
	.rmu_disable = mv88e6085_g1_rmu_disable,
2618
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2619
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2620 2621 2622
};

static const struct mv88e6xxx_ops mv88e6095_ops = {
2623
	/* MV88E6XXX_FAMILY_6095 */
2624 2625
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2626
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2627 2628
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2629
	.port_set_link = mv88e6xxx_port_set_link,
2630
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2631
	.port_set_speed = mv88e6185_port_set_speed,
2632
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2633
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2634
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
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
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
2641 2642
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2643
	.reset = mv88e6185_g1_reset,
2644
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2645
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2646 2647
};

2648
static const struct mv88e6xxx_ops mv88e6097_ops = {
2649
	/* MV88E6XXX_FAMILY_6097 */
2650 2651
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2652
	.irl_init_all = mv88e6352_g2_irl_init_all,
2653 2654 2655 2656 2657 2658
	.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,
2659
	.port_tag_remap = mv88e6095_port_tag_remap,
2660
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2661
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2662
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2663
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2664
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
2665
	.port_pause_limit = mv88e6097_port_pause_limit,
2666
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2667
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2668
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2669
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2670 2671 2672
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
	.stats_get_stats = mv88e6095_stats_get_stats,
2673 2674
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2675
	.watchdog_ops = &mv88e6097_watchdog_ops,
2676
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2677
	.pot_clear = mv88e6xxx_g2_pot_clear,
2678
	.reset = mv88e6352_g1_reset,
2679
	.rmu_disable = mv88e6085_g1_rmu_disable,
2680
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2681
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2682 2683
};

2684
static const struct mv88e6xxx_ops mv88e6123_ops = {
2685
	/* MV88E6XXX_FAMILY_6165 */
2686 2687
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2688
	.irl_init_all = mv88e6352_g2_irl_init_all,
2689
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2690 2691
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2692
	.port_set_link = mv88e6xxx_port_set_link,
2693
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2694
	.port_set_speed = mv88e6185_port_set_speed,
2695
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2696
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2697
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2698
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2699
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2700
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2701 2702
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2703
	.stats_get_stats = mv88e6095_stats_get_stats,
2704 2705
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2706
	.watchdog_ops = &mv88e6097_watchdog_ops,
2707
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2708
	.pot_clear = mv88e6xxx_g2_pot_clear,
2709
	.reset = mv88e6352_g1_reset,
2710
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2711
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2712 2713 2714
};

static const struct mv88e6xxx_ops mv88e6131_ops = {
2715
	/* MV88E6XXX_FAMILY_6185 */
2716 2717
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2718
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2719 2720
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
2721
	.port_set_link = mv88e6xxx_port_set_link,
2722
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2723
	.port_set_speed = mv88e6185_port_set_speed,
2724
	.port_tag_remap = mv88e6095_port_tag_remap,
2725
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2726
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2727
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2728
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2729
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2730
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2731
	.port_pause_limit = mv88e6097_port_pause_limit,
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 = mv88e6185_g2_mgmt_rsvd2cpu,
2741
	.ppu_enable = mv88e6185_g1_ppu_enable,
2742
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
2743
	.ppu_disable = mv88e6185_g1_ppu_disable,
2744
	.reset = mv88e6185_g1_reset,
2745
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2746
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2747 2748
};

2749 2750
static const struct mv88e6xxx_ops mv88e6141_ops = {
	/* MV88E6XXX_FAMILY_6341 */
2751 2752
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2753
	.irl_init_all = mv88e6352_g2_irl_init_all,
2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766
	.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,
2767
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2768
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2769
	.port_pause_limit = mv88e6097_port_pause_limit,
2770 2771 2772
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
2773
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2774 2775 2776
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
2777 2778
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
2779 2780
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
2781
	.pot_clear = mv88e6xxx_g2_pot_clear,
2782
	.reset = mv88e6352_g1_reset,
2783
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2784
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2785
	.serdes_power = mv88e6341_serdes_power,
2786
	.gpio_ops = &mv88e6352_gpio_ops,
2787 2788
};

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

static const struct mv88e6xxx_ops mv88e6165_ops = {
2827
	/* MV88E6XXX_FAMILY_6165 */
2828 2829
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2830
	.irl_init_all = mv88e6352_g2_irl_init_all,
2831
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2832 2833
	.phy_read = mv88e6165_phy_read,
	.phy_write = mv88e6165_phy_write,
2834
	.port_set_link = mv88e6xxx_port_set_link,
2835
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2836
	.port_set_speed = mv88e6185_port_set_speed,
2837
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2838
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2839
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2840
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2841 2842
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2843
	.stats_get_stats = mv88e6095_stats_get_stats,
2844 2845
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2846
	.watchdog_ops = &mv88e6097_watchdog_ops,
2847
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2848
	.pot_clear = mv88e6xxx_g2_pot_clear,
2849
	.reset = mv88e6352_g1_reset,
2850
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2851
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2852
	.avb_ops = &mv88e6165_avb_ops,
2853
	.ptp_ops = &mv88e6165_ptp_ops,
2854 2855 2856
};

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

static const struct mv88e6xxx_ops mv88e6172_ops = {
2893
	/* MV88E6XXX_FAMILY_6352 */
2894 2895
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2896
	.irl_init_all = mv88e6352_g2_irl_init_all,
2897 2898
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
2899
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2900 2901
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2902
	.port_set_link = mv88e6xxx_port_set_link,
2903
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2904
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
2905
	.port_set_speed = mv88e6352_port_set_speed,
2906
	.port_tag_remap = mv88e6095_port_tag_remap,
2907
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2908
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2909
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2910
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2911
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2912
	.port_pause_limit = mv88e6097_port_pause_limit,
2913
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2914
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2915
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2916
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2917 2918
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2919
	.stats_get_stats = mv88e6095_stats_get_stats,
2920 2921
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2922
	.watchdog_ops = &mv88e6097_watchdog_ops,
2923
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2924
	.pot_clear = mv88e6xxx_g2_pot_clear,
2925
	.reset = mv88e6352_g1_reset,
2926
	.rmu_disable = mv88e6352_g1_rmu_disable,
2927
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2928
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2929
	.serdes_power = mv88e6352_serdes_power,
2930
	.gpio_ops = &mv88e6352_gpio_ops,
2931 2932 2933
};

static const struct mv88e6xxx_ops mv88e6175_ops = {
2934
	/* MV88E6XXX_FAMILY_6351 */
2935 2936
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2937
	.irl_init_all = mv88e6352_g2_irl_init_all,
2938
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2939 2940
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2941
	.port_set_link = mv88e6xxx_port_set_link,
2942
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2943
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
2944
	.port_set_speed = mv88e6185_port_set_speed,
2945
	.port_tag_remap = mv88e6095_port_tag_remap,
2946
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2947
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2948
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2949
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2950
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2951
	.port_pause_limit = mv88e6097_port_pause_limit,
2952
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2953
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2954
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2955
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2956 2957
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2958
	.stats_get_stats = mv88e6095_stats_get_stats,
2959 2960
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2961
	.watchdog_ops = &mv88e6097_watchdog_ops,
2962
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
2963
	.pot_clear = mv88e6xxx_g2_pot_clear,
2964
	.reset = mv88e6352_g1_reset,
2965
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2966
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2967 2968 2969
};

static const struct mv88e6xxx_ops mv88e6176_ops = {
2970
	/* MV88E6XXX_FAMILY_6352 */
2971 2972
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
2973
	.irl_init_all = mv88e6352_g2_irl_init_all,
2974 2975
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
2976
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2977 2978
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2979
	.port_set_link = mv88e6xxx_port_set_link,
2980
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2981
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
2982
	.port_set_speed = mv88e6352_port_set_speed,
2983
	.port_tag_remap = mv88e6095_port_tag_remap,
2984
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2985
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2986
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2987
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
2988
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2989
	.port_pause_limit = mv88e6097_port_pause_limit,
2990
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2991
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2992
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2993
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
2994 2995
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2996
	.stats_get_stats = mv88e6095_stats_get_stats,
2997 2998
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
2999
	.watchdog_ops = &mv88e6097_watchdog_ops,
3000
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3001
	.pot_clear = mv88e6xxx_g2_pot_clear,
3002
	.reset = mv88e6352_g1_reset,
3003
	.rmu_disable = mv88e6352_g1_rmu_disable,
3004
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3005
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3006
	.serdes_power = mv88e6352_serdes_power,
3007
	.gpio_ops = &mv88e6352_gpio_ops,
3008 3009 3010
};

static const struct mv88e6xxx_ops mv88e6185_ops = {
3011
	/* MV88E6XXX_FAMILY_6185 */
3012 3013
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3014
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3015 3016
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3017
	.port_set_link = mv88e6xxx_port_set_link,
3018
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3019
	.port_set_speed = mv88e6185_port_set_speed,
3020
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
3021
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
3022
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
3023
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
3024
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3025
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3026 3027
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3028
	.stats_get_stats = mv88e6095_stats_get_stats,
3029 3030
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3031
	.watchdog_ops = &mv88e6097_watchdog_ops,
3032
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3033
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
3034 3035
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
3036
	.reset = mv88e6185_g1_reset,
3037
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3038
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3039 3040
};

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

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

static const struct mv88e6xxx_ops mv88e6191_ops = {
3116
	/* MV88E6XXX_FAMILY_6390 */
3117
	.irl_init_all = mv88e6390_g2_irl_init_all,
3118 3119
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3120 3121 3122 3123 3124 3125 3126
	.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,
3127
	.port_tag_remap = mv88e6390_port_tag_remap,
3128
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3129
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3130
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3131
	.port_pause_limit = mv88e6390_port_pause_limit,
3132
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3133
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3134
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3135
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3136 3137
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3138
	.stats_get_stats = mv88e6390_stats_get_stats,
3139 3140
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3141
	.watchdog_ops = &mv88e6390_watchdog_ops,
3142
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3143
	.pot_clear = mv88e6xxx_g2_pot_clear,
3144
	.reset = mv88e6352_g1_reset,
3145
	.rmu_disable = mv88e6390_g1_rmu_disable,
3146 3147
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3148
	.serdes_power = mv88e6390_serdes_power,
3149 3150
	.avb_ops = &mv88e6390_avb_ops,
	.ptp_ops = &mv88e6352_ptp_ops,
3151 3152
};

3153
static const struct mv88e6xxx_ops mv88e6240_ops = {
3154
	/* MV88E6XXX_FAMILY_6352 */
3155 3156
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3157
	.irl_init_all = mv88e6352_g2_irl_init_all,
3158 3159
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3160
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3161 3162
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3163
	.port_set_link = mv88e6xxx_port_set_link,
3164
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3165
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3166
	.port_set_speed = mv88e6352_port_set_speed,
3167
	.port_tag_remap = mv88e6095_port_tag_remap,
3168
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3169
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3170
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3171
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3172
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3173
	.port_pause_limit = mv88e6097_port_pause_limit,
3174
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3175
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3176
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3177
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3178 3179
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3180
	.stats_get_stats = mv88e6095_stats_get_stats,
3181 3182
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3183
	.watchdog_ops = &mv88e6097_watchdog_ops,
3184
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3185
	.pot_clear = mv88e6xxx_g2_pot_clear,
3186
	.reset = mv88e6352_g1_reset,
3187
	.rmu_disable = mv88e6352_g1_rmu_disable,
3188
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3189
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3190
	.serdes_power = mv88e6352_serdes_power,
3191
	.gpio_ops = &mv88e6352_gpio_ops,
3192
	.avb_ops = &mv88e6352_avb_ops,
3193
	.ptp_ops = &mv88e6352_ptp_ops,
3194 3195
};

3196
static const struct mv88e6xxx_ops mv88e6290_ops = {
3197
	/* MV88E6XXX_FAMILY_6390 */
3198
	.irl_init_all = mv88e6390_g2_irl_init_all,
3199 3200
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3201 3202 3203 3204 3205 3206 3207
	.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,
3208
	.port_tag_remap = mv88e6390_port_tag_remap,
3209
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3210
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3211
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3212
	.port_pause_limit = mv88e6390_port_pause_limit,
3213
	.port_set_cmode = mv88e6390x_port_set_cmode,
3214
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3215
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3216
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3217
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3218 3219
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3220
	.stats_get_stats = mv88e6390_stats_get_stats,
3221 3222
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3223
	.watchdog_ops = &mv88e6390_watchdog_ops,
3224
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3225
	.pot_clear = mv88e6xxx_g2_pot_clear,
3226
	.reset = mv88e6352_g1_reset,
3227
	.rmu_disable = mv88e6390_g1_rmu_disable,
3228 3229
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3230
	.serdes_power = mv88e6390_serdes_power,
3231
	.gpio_ops = &mv88e6352_gpio_ops,
3232
	.avb_ops = &mv88e6390_avb_ops,
3233
	.ptp_ops = &mv88e6352_ptp_ops,
3234 3235
};

3236
static const struct mv88e6xxx_ops mv88e6320_ops = {
3237
	/* MV88E6XXX_FAMILY_6320 */
3238 3239
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3240
	.irl_init_all = mv88e6352_g2_irl_init_all,
3241 3242
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3243
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3244 3245
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3246
	.port_set_link = mv88e6xxx_port_set_link,
3247
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3248
	.port_set_speed = mv88e6185_port_set_speed,
3249
	.port_tag_remap = mv88e6095_port_tag_remap,
3250
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3251
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3252
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3253
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3254
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3255
	.port_pause_limit = mv88e6097_port_pause_limit,
3256
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3257
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3258
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3259
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3260 3261
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3262
	.stats_get_stats = mv88e6320_stats_get_stats,
3263 3264
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3265
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3266
	.pot_clear = mv88e6xxx_g2_pot_clear,
3267
	.reset = mv88e6352_g1_reset,
3268
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3269
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3270
	.gpio_ops = &mv88e6352_gpio_ops,
3271
	.avb_ops = &mv88e6352_avb_ops,
3272
	.ptp_ops = &mv88e6352_ptp_ops,
3273 3274 3275
};

static const struct mv88e6xxx_ops mv88e6321_ops = {
3276
	/* MV88E6XXX_FAMILY_6320 */
3277 3278
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3279
	.irl_init_all = mv88e6352_g2_irl_init_all,
3280 3281
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3282
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3283 3284
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3285
	.port_set_link = mv88e6xxx_port_set_link,
3286
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3287
	.port_set_speed = mv88e6185_port_set_speed,
3288
	.port_tag_remap = mv88e6095_port_tag_remap,
3289
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3290
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3291
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3292
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3293
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3294
	.port_pause_limit = mv88e6097_port_pause_limit,
3295
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3296
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3297
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3298
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3299 3300
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3301
	.stats_get_stats = mv88e6320_stats_get_stats,
3302 3303
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3304
	.reset = mv88e6352_g1_reset,
3305
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3306
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3307
	.gpio_ops = &mv88e6352_gpio_ops,
3308
	.avb_ops = &mv88e6352_avb_ops,
3309
	.ptp_ops = &mv88e6352_ptp_ops,
3310 3311
};

3312 3313
static const struct mv88e6xxx_ops mv88e6341_ops = {
	/* MV88E6XXX_FAMILY_6341 */
3314 3315
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3316
	.irl_init_all = mv88e6352_g2_irl_init_all,
3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329
	.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,
3330
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3331
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3332
	.port_pause_limit = mv88e6097_port_pause_limit,
3333 3334 3335
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3336
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3337 3338 3339
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
3340 3341
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3342 3343
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
3344
	.pot_clear = mv88e6xxx_g2_pot_clear,
3345
	.reset = mv88e6352_g1_reset,
3346
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3347
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3348
	.serdes_power = mv88e6341_serdes_power,
3349
	.gpio_ops = &mv88e6352_gpio_ops,
3350
	.avb_ops = &mv88e6390_avb_ops,
3351
	.ptp_ops = &mv88e6352_ptp_ops,
3352 3353
};

3354
static const struct mv88e6xxx_ops mv88e6350_ops = {
3355
	/* MV88E6XXX_FAMILY_6351 */
3356 3357
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3358
	.irl_init_all = mv88e6352_g2_irl_init_all,
3359
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3360 3361
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3362
	.port_set_link = mv88e6xxx_port_set_link,
3363
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3364
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3365
	.port_set_speed = mv88e6185_port_set_speed,
3366
	.port_tag_remap = mv88e6095_port_tag_remap,
3367
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3368
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3369
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3370
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3371
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3372
	.port_pause_limit = mv88e6097_port_pause_limit,
3373
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3374
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3375
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3376
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3377 3378
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3379
	.stats_get_stats = mv88e6095_stats_get_stats,
3380 3381
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3382
	.watchdog_ops = &mv88e6097_watchdog_ops,
3383
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3384
	.pot_clear = mv88e6xxx_g2_pot_clear,
3385
	.reset = mv88e6352_g1_reset,
3386
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3387
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3388 3389 3390
};

static const struct mv88e6xxx_ops mv88e6351_ops = {
3391
	/* MV88E6XXX_FAMILY_6351 */
3392 3393
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3394
	.irl_init_all = mv88e6352_g2_irl_init_all,
3395
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3396 3397
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3398
	.port_set_link = mv88e6xxx_port_set_link,
3399
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3400
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3401
	.port_set_speed = mv88e6185_port_set_speed,
3402
	.port_tag_remap = mv88e6095_port_tag_remap,
3403
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3404
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3405
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3406
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3407
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3408
	.port_pause_limit = mv88e6097_port_pause_limit,
3409
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3410
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3411
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3412
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3413 3414
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3415
	.stats_get_stats = mv88e6095_stats_get_stats,
3416 3417
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3418
	.watchdog_ops = &mv88e6097_watchdog_ops,
3419
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3420
	.pot_clear = mv88e6xxx_g2_pot_clear,
3421
	.reset = mv88e6352_g1_reset,
3422
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3423
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3424
	.avb_ops = &mv88e6352_avb_ops,
3425
	.ptp_ops = &mv88e6352_ptp_ops,
3426 3427 3428
};

static const struct mv88e6xxx_ops mv88e6352_ops = {
3429
	/* MV88E6XXX_FAMILY_6352 */
3430 3431
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3432
	.irl_init_all = mv88e6352_g2_irl_init_all,
3433 3434
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3435
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3436 3437
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3438
	.port_set_link = mv88e6xxx_port_set_link,
3439
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3440
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3441
	.port_set_speed = mv88e6352_port_set_speed,
3442
	.port_tag_remap = mv88e6095_port_tag_remap,
3443
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3444
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3445
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3446
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3447
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3448
	.port_pause_limit = mv88e6097_port_pause_limit,
3449
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3450
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3451
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3452
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3453 3454
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3455
	.stats_get_stats = mv88e6095_stats_get_stats,
3456 3457
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3458
	.watchdog_ops = &mv88e6097_watchdog_ops,
3459
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3460
	.pot_clear = mv88e6xxx_g2_pot_clear,
3461
	.reset = mv88e6352_g1_reset,
3462
	.rmu_disable = mv88e6352_g1_rmu_disable,
3463
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3464
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3465
	.serdes_power = mv88e6352_serdes_power,
3466
	.gpio_ops = &mv88e6352_gpio_ops,
3467
	.avb_ops = &mv88e6352_avb_ops,
3468
	.ptp_ops = &mv88e6352_ptp_ops,
3469 3470 3471
	.serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
	.serdes_get_strings = mv88e6352_serdes_get_strings,
	.serdes_get_stats = mv88e6352_serdes_get_stats,
3472 3473
};

3474
static const struct mv88e6xxx_ops mv88e6390_ops = {
3475
	/* MV88E6XXX_FAMILY_6390 */
3476
	.irl_init_all = mv88e6390_g2_irl_init_all,
3477 3478
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3479 3480 3481 3482 3483 3484 3485
	.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,
3486
	.port_tag_remap = mv88e6390_port_tag_remap,
3487
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3488
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3489
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3490
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3491
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3492
	.port_pause_limit = mv88e6390_port_pause_limit,
3493
	.port_set_cmode = mv88e6390x_port_set_cmode,
3494
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3495
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3496
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3497
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3498 3499
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3500
	.stats_get_stats = mv88e6390_stats_get_stats,
3501 3502
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3503
	.watchdog_ops = &mv88e6390_watchdog_ops,
3504
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3505
	.pot_clear = mv88e6xxx_g2_pot_clear,
3506
	.reset = mv88e6352_g1_reset,
3507
	.rmu_disable = mv88e6390_g1_rmu_disable,
3508 3509
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3510
	.serdes_power = mv88e6390_serdes_power,
3511
	.gpio_ops = &mv88e6352_gpio_ops,
3512
	.avb_ops = &mv88e6390_avb_ops,
3513
	.ptp_ops = &mv88e6352_ptp_ops,
3514 3515 3516
};

static const struct mv88e6xxx_ops mv88e6390x_ops = {
3517
	/* MV88E6XXX_FAMILY_6390 */
3518
	.irl_init_all = mv88e6390_g2_irl_init_all,
3519 3520
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3521 3522 3523 3524 3525 3526 3527
	.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,
3528
	.port_tag_remap = mv88e6390_port_tag_remap,
3529
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3530
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3531
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3532
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3533
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3534
	.port_pause_limit = mv88e6390_port_pause_limit,
3535
	.port_set_cmode = mv88e6390x_port_set_cmode,
3536
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3537
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3538
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3539
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3540 3541
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3542
	.stats_get_stats = mv88e6390_stats_get_stats,
3543 3544
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3545
	.watchdog_ops = &mv88e6390_watchdog_ops,
3546
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3547
	.pot_clear = mv88e6xxx_g2_pot_clear,
3548
	.reset = mv88e6352_g1_reset,
3549
	.rmu_disable = mv88e6390_g1_rmu_disable,
3550 3551
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3552
	.serdes_power = mv88e6390_serdes_power,
3553
	.gpio_ops = &mv88e6352_gpio_ops,
3554
	.avb_ops = &mv88e6390_avb_ops,
3555
	.ptp_ops = &mv88e6352_ptp_ops,
3556 3557
};

3558 3559
static const struct mv88e6xxx_info mv88e6xxx_table[] = {
	[MV88E6085] = {
3560
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
3561 3562 3563 3564
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6085",
		.num_databases = 4096,
		.num_ports = 10,
3565
		.num_internal_phys = 5,
3566
		.max_vid = 4095,
3567
		.port_base_addr = 0x10,
3568
		.phy_base_addr = 0x0,
3569
		.global1_addr = 0x1b,
3570
		.global2_addr = 0x1c,
3571
		.age_time_coeff = 15000,
3572
		.g1_irqs = 8,
3573
		.g2_irqs = 10,
3574
		.atu_move_port_mask = 0xf,
3575
		.pvt = true,
3576
		.multi_chip = true,
3577
		.tag_protocol = DSA_TAG_PROTO_DSA,
3578
		.ops = &mv88e6085_ops,
3579 3580 3581
	},

	[MV88E6095] = {
3582
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
3583 3584 3585 3586
		.family = MV88E6XXX_FAMILY_6095,
		.name = "Marvell 88E6095/88E6095F",
		.num_databases = 256,
		.num_ports = 11,
3587
		.num_internal_phys = 0,
3588
		.max_vid = 4095,
3589
		.port_base_addr = 0x10,
3590
		.phy_base_addr = 0x0,
3591
		.global1_addr = 0x1b,
3592
		.global2_addr = 0x1c,
3593
		.age_time_coeff = 15000,
3594
		.g1_irqs = 8,
3595
		.atu_move_port_mask = 0xf,
3596
		.multi_chip = true,
3597
		.tag_protocol = DSA_TAG_PROTO_DSA,
3598
		.ops = &mv88e6095_ops,
3599 3600
	},

3601
	[MV88E6097] = {
3602
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
3603 3604 3605 3606
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6097/88E6097F",
		.num_databases = 4096,
		.num_ports = 11,
3607
		.num_internal_phys = 8,
3608
		.max_vid = 4095,
3609
		.port_base_addr = 0x10,
3610
		.phy_base_addr = 0x0,
3611
		.global1_addr = 0x1b,
3612
		.global2_addr = 0x1c,
3613
		.age_time_coeff = 15000,
3614
		.g1_irqs = 8,
3615
		.g2_irqs = 10,
3616
		.atu_move_port_mask = 0xf,
3617
		.pvt = true,
3618
		.multi_chip = true,
3619
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3620 3621 3622
		.ops = &mv88e6097_ops,
	},

3623
	[MV88E6123] = {
3624
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
3625 3626 3627 3628
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6123",
		.num_databases = 4096,
		.num_ports = 3,
3629
		.num_internal_phys = 5,
3630
		.max_vid = 4095,
3631
		.port_base_addr = 0x10,
3632
		.phy_base_addr = 0x0,
3633
		.global1_addr = 0x1b,
3634
		.global2_addr = 0x1c,
3635
		.age_time_coeff = 15000,
3636
		.g1_irqs = 9,
3637
		.g2_irqs = 10,
3638
		.atu_move_port_mask = 0xf,
3639
		.pvt = true,
3640
		.multi_chip = true,
3641
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3642
		.ops = &mv88e6123_ops,
3643 3644 3645
	},

	[MV88E6131] = {
3646
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
3647 3648 3649 3650
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6131",
		.num_databases = 256,
		.num_ports = 8,
3651
		.num_internal_phys = 0,
3652
		.max_vid = 4095,
3653
		.port_base_addr = 0x10,
3654
		.phy_base_addr = 0x0,
3655
		.global1_addr = 0x1b,
3656
		.global2_addr = 0x1c,
3657
		.age_time_coeff = 15000,
3658
		.g1_irqs = 9,
3659
		.atu_move_port_mask = 0xf,
3660
		.multi_chip = true,
3661
		.tag_protocol = DSA_TAG_PROTO_DSA,
3662
		.ops = &mv88e6131_ops,
3663 3664
	},

3665
	[MV88E6141] = {
3666
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
3667
		.family = MV88E6XXX_FAMILY_6341,
3668
		.name = "Marvell 88E6141",
3669 3670
		.num_databases = 4096,
		.num_ports = 6,
3671
		.num_internal_phys = 5,
3672
		.num_gpio = 11,
3673
		.max_vid = 4095,
3674
		.port_base_addr = 0x10,
3675
		.phy_base_addr = 0x10,
3676
		.global1_addr = 0x1b,
3677
		.global2_addr = 0x1c,
3678 3679
		.age_time_coeff = 3750,
		.atu_move_port_mask = 0x1f,
3680
		.g1_irqs = 9,
3681
		.g2_irqs = 10,
3682
		.pvt = true,
3683
		.multi_chip = true,
3684 3685 3686 3687
		.tag_protocol = DSA_TAG_PROTO_EDSA,
		.ops = &mv88e6141_ops,
	},

3688
	[MV88E6161] = {
3689
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
3690 3691 3692 3693
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6161",
		.num_databases = 4096,
		.num_ports = 6,
3694
		.num_internal_phys = 5,
3695
		.max_vid = 4095,
3696
		.port_base_addr = 0x10,
3697
		.phy_base_addr = 0x0,
3698
		.global1_addr = 0x1b,
3699
		.global2_addr = 0x1c,
3700
		.age_time_coeff = 15000,
3701
		.g1_irqs = 9,
3702
		.g2_irqs = 10,
3703
		.atu_move_port_mask = 0xf,
3704
		.pvt = true,
3705
		.multi_chip = true,
3706
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3707
		.ptp_support = true,
3708
		.ops = &mv88e6161_ops,
3709 3710 3711
	},

	[MV88E6165] = {
3712
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
3713 3714 3715 3716
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6165",
		.num_databases = 4096,
		.num_ports = 6,
3717
		.num_internal_phys = 0,
3718
		.max_vid = 4095,
3719
		.port_base_addr = 0x10,
3720
		.phy_base_addr = 0x0,
3721
		.global1_addr = 0x1b,
3722
		.global2_addr = 0x1c,
3723
		.age_time_coeff = 15000,
3724
		.g1_irqs = 9,
3725
		.g2_irqs = 10,
3726
		.atu_move_port_mask = 0xf,
3727
		.pvt = true,
3728
		.multi_chip = true,
3729
		.tag_protocol = DSA_TAG_PROTO_DSA,
3730
		.ptp_support = true,
3731
		.ops = &mv88e6165_ops,
3732 3733 3734
	},

	[MV88E6171] = {
3735
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
3736 3737 3738 3739
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6171",
		.num_databases = 4096,
		.num_ports = 7,
3740
		.num_internal_phys = 5,
3741
		.max_vid = 4095,
3742
		.port_base_addr = 0x10,
3743
		.phy_base_addr = 0x0,
3744
		.global1_addr = 0x1b,
3745
		.global2_addr = 0x1c,
3746
		.age_time_coeff = 15000,
3747
		.g1_irqs = 9,
3748
		.g2_irqs = 10,
3749
		.atu_move_port_mask = 0xf,
3750
		.pvt = true,
3751
		.multi_chip = true,
3752
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3753
		.ops = &mv88e6171_ops,
3754 3755 3756
	},

	[MV88E6172] = {
3757
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
3758 3759 3760 3761
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6172",
		.num_databases = 4096,
		.num_ports = 7,
3762
		.num_internal_phys = 5,
3763
		.num_gpio = 15,
3764
		.max_vid = 4095,
3765
		.port_base_addr = 0x10,
3766
		.phy_base_addr = 0x0,
3767
		.global1_addr = 0x1b,
3768
		.global2_addr = 0x1c,
3769
		.age_time_coeff = 15000,
3770
		.g1_irqs = 9,
3771
		.g2_irqs = 10,
3772
		.atu_move_port_mask = 0xf,
3773
		.pvt = true,
3774
		.multi_chip = true,
3775
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3776
		.ops = &mv88e6172_ops,
3777 3778 3779
	},

	[MV88E6175] = {
3780
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
3781 3782 3783 3784
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6175",
		.num_databases = 4096,
		.num_ports = 7,
3785
		.num_internal_phys = 5,
3786
		.max_vid = 4095,
3787
		.port_base_addr = 0x10,
3788
		.phy_base_addr = 0x0,
3789
		.global1_addr = 0x1b,
3790
		.global2_addr = 0x1c,
3791
		.age_time_coeff = 15000,
3792
		.g1_irqs = 9,
3793
		.g2_irqs = 10,
3794
		.atu_move_port_mask = 0xf,
3795
		.pvt = true,
3796
		.multi_chip = true,
3797
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3798
		.ops = &mv88e6175_ops,
3799 3800 3801
	},

	[MV88E6176] = {
3802
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
3803 3804 3805 3806
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6176",
		.num_databases = 4096,
		.num_ports = 7,
3807
		.num_internal_phys = 5,
3808
		.num_gpio = 15,
3809
		.max_vid = 4095,
3810
		.port_base_addr = 0x10,
3811
		.phy_base_addr = 0x0,
3812
		.global1_addr = 0x1b,
3813
		.global2_addr = 0x1c,
3814
		.age_time_coeff = 15000,
3815
		.g1_irqs = 9,
3816
		.g2_irqs = 10,
3817
		.atu_move_port_mask = 0xf,
3818
		.pvt = true,
3819
		.multi_chip = true,
3820
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3821
		.ops = &mv88e6176_ops,
3822 3823 3824
	},

	[MV88E6185] = {
3825
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
3826 3827 3828 3829
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6185",
		.num_databases = 256,
		.num_ports = 10,
3830
		.num_internal_phys = 0,
3831
		.max_vid = 4095,
3832
		.port_base_addr = 0x10,
3833
		.phy_base_addr = 0x0,
3834
		.global1_addr = 0x1b,
3835
		.global2_addr = 0x1c,
3836
		.age_time_coeff = 15000,
3837
		.g1_irqs = 8,
3838
		.atu_move_port_mask = 0xf,
3839
		.multi_chip = true,
3840
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3841
		.ops = &mv88e6185_ops,
3842 3843
	},

3844
	[MV88E6190] = {
3845
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
3846 3847 3848 3849
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3850
		.num_internal_phys = 11,
3851
		.num_gpio = 16,
3852
		.max_vid = 8191,
3853
		.port_base_addr = 0x0,
3854
		.phy_base_addr = 0x0,
3855
		.global1_addr = 0x1b,
3856
		.global2_addr = 0x1c,
3857
		.tag_protocol = DSA_TAG_PROTO_DSA,
3858
		.age_time_coeff = 3750,
3859
		.g1_irqs = 9,
3860
		.g2_irqs = 14,
3861
		.pvt = true,
3862
		.multi_chip = true,
3863
		.atu_move_port_mask = 0x1f,
3864 3865 3866 3867
		.ops = &mv88e6190_ops,
	},

	[MV88E6190X] = {
3868
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
3869 3870 3871 3872
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3873
		.num_internal_phys = 11,
3874
		.num_gpio = 16,
3875
		.max_vid = 8191,
3876
		.port_base_addr = 0x0,
3877
		.phy_base_addr = 0x0,
3878
		.global1_addr = 0x1b,
3879
		.global2_addr = 0x1c,
3880
		.age_time_coeff = 3750,
3881
		.g1_irqs = 9,
3882
		.g2_irqs = 14,
3883
		.atu_move_port_mask = 0x1f,
3884
		.pvt = true,
3885
		.multi_chip = true,
3886
		.tag_protocol = DSA_TAG_PROTO_DSA,
3887 3888 3889 3890
		.ops = &mv88e6190x_ops,
	},

	[MV88E6191] = {
3891
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
3892 3893 3894 3895
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6191",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3896
		.num_internal_phys = 11,
3897
		.max_vid = 8191,
3898
		.port_base_addr = 0x0,
3899
		.phy_base_addr = 0x0,
3900
		.global1_addr = 0x1b,
3901
		.global2_addr = 0x1c,
3902
		.age_time_coeff = 3750,
3903
		.g1_irqs = 9,
3904
		.g2_irqs = 14,
3905
		.atu_move_port_mask = 0x1f,
3906
		.pvt = true,
3907
		.multi_chip = true,
3908
		.tag_protocol = DSA_TAG_PROTO_DSA,
3909
		.ptp_support = true,
3910
		.ops = &mv88e6191_ops,
3911 3912
	},

3913
	[MV88E6240] = {
3914
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
3915 3916 3917 3918
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6240",
		.num_databases = 4096,
		.num_ports = 7,
3919
		.num_internal_phys = 5,
3920
		.num_gpio = 15,
3921
		.max_vid = 4095,
3922
		.port_base_addr = 0x10,
3923
		.phy_base_addr = 0x0,
3924
		.global1_addr = 0x1b,
3925
		.global2_addr = 0x1c,
3926
		.age_time_coeff = 15000,
3927
		.g1_irqs = 9,
3928
		.g2_irqs = 10,
3929
		.atu_move_port_mask = 0xf,
3930
		.pvt = true,
3931
		.multi_chip = true,
3932
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3933
		.ptp_support = true,
3934
		.ops = &mv88e6240_ops,
3935 3936
	},

3937
	[MV88E6290] = {
3938
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
3939 3940 3941 3942
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6290",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3943
		.num_internal_phys = 11,
3944
		.num_gpio = 16,
3945
		.max_vid = 8191,
3946
		.port_base_addr = 0x0,
3947
		.phy_base_addr = 0x0,
3948
		.global1_addr = 0x1b,
3949
		.global2_addr = 0x1c,
3950
		.age_time_coeff = 3750,
3951
		.g1_irqs = 9,
3952
		.g2_irqs = 14,
3953
		.atu_move_port_mask = 0x1f,
3954
		.pvt = true,
3955
		.multi_chip = true,
3956
		.tag_protocol = DSA_TAG_PROTO_DSA,
3957
		.ptp_support = true,
3958 3959 3960
		.ops = &mv88e6290_ops,
	},

3961
	[MV88E6320] = {
3962
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
3963 3964 3965 3966
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6320",
		.num_databases = 4096,
		.num_ports = 7,
3967
		.num_internal_phys = 5,
3968
		.num_gpio = 15,
3969
		.max_vid = 4095,
3970
		.port_base_addr = 0x10,
3971
		.phy_base_addr = 0x0,
3972
		.global1_addr = 0x1b,
3973
		.global2_addr = 0x1c,
3974
		.age_time_coeff = 15000,
3975
		.g1_irqs = 8,
3976
		.g2_irqs = 10,
3977
		.atu_move_port_mask = 0xf,
3978
		.pvt = true,
3979
		.multi_chip = true,
3980
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3981
		.ptp_support = true,
3982
		.ops = &mv88e6320_ops,
3983 3984 3985
	},

	[MV88E6321] = {
3986
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
3987 3988 3989 3990
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6321",
		.num_databases = 4096,
		.num_ports = 7,
3991
		.num_internal_phys = 5,
3992
		.num_gpio = 15,
3993
		.max_vid = 4095,
3994
		.port_base_addr = 0x10,
3995
		.phy_base_addr = 0x0,
3996
		.global1_addr = 0x1b,
3997
		.global2_addr = 0x1c,
3998
		.age_time_coeff = 15000,
3999
		.g1_irqs = 8,
4000
		.g2_irqs = 10,
4001
		.atu_move_port_mask = 0xf,
4002
		.multi_chip = true,
4003
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4004
		.ptp_support = true,
4005
		.ops = &mv88e6321_ops,
4006 4007
	},

4008
	[MV88E6341] = {
4009
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
4010 4011 4012
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
4013
		.num_internal_phys = 5,
4014
		.num_ports = 6,
4015
		.num_gpio = 11,
4016
		.max_vid = 4095,
4017
		.port_base_addr = 0x10,
4018
		.phy_base_addr = 0x10,
4019
		.global1_addr = 0x1b,
4020
		.global2_addr = 0x1c,
4021
		.age_time_coeff = 3750,
4022
		.atu_move_port_mask = 0x1f,
4023
		.g1_irqs = 9,
4024
		.g2_irqs = 10,
4025
		.pvt = true,
4026
		.multi_chip = true,
4027
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4028
		.ptp_support = true,
4029 4030 4031
		.ops = &mv88e6341_ops,
	},

4032
	[MV88E6350] = {
4033
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
4034 4035 4036 4037
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6350",
		.num_databases = 4096,
		.num_ports = 7,
4038
		.num_internal_phys = 5,
4039
		.max_vid = 4095,
4040
		.port_base_addr = 0x10,
4041
		.phy_base_addr = 0x0,
4042
		.global1_addr = 0x1b,
4043
		.global2_addr = 0x1c,
4044
		.age_time_coeff = 15000,
4045
		.g1_irqs = 9,
4046
		.g2_irqs = 10,
4047
		.atu_move_port_mask = 0xf,
4048
		.pvt = true,
4049
		.multi_chip = true,
4050
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4051
		.ops = &mv88e6350_ops,
4052 4053 4054
	},

	[MV88E6351] = {
4055
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
4056 4057 4058 4059
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6351",
		.num_databases = 4096,
		.num_ports = 7,
4060
		.num_internal_phys = 5,
4061
		.max_vid = 4095,
4062
		.port_base_addr = 0x10,
4063
		.phy_base_addr = 0x0,
4064
		.global1_addr = 0x1b,
4065
		.global2_addr = 0x1c,
4066
		.age_time_coeff = 15000,
4067
		.g1_irqs = 9,
4068
		.g2_irqs = 10,
4069
		.atu_move_port_mask = 0xf,
4070
		.pvt = true,
4071
		.multi_chip = true,
4072
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4073
		.ops = &mv88e6351_ops,
4074 4075 4076
	},

	[MV88E6352] = {
4077
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
4078 4079 4080 4081
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6352",
		.num_databases = 4096,
		.num_ports = 7,
4082
		.num_internal_phys = 5,
4083
		.num_gpio = 15,
4084
		.max_vid = 4095,
4085
		.port_base_addr = 0x10,
4086
		.phy_base_addr = 0x0,
4087
		.global1_addr = 0x1b,
4088
		.global2_addr = 0x1c,
4089
		.age_time_coeff = 15000,
4090
		.g1_irqs = 9,
4091
		.g2_irqs = 10,
4092
		.atu_move_port_mask = 0xf,
4093
		.pvt = true,
4094
		.multi_chip = true,
4095
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4096
		.ptp_support = true,
4097
		.ops = &mv88e6352_ops,
4098
	},
4099
	[MV88E6390] = {
4100
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
4101 4102 4103 4104
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4105
		.num_internal_phys = 11,
4106
		.num_gpio = 16,
4107
		.max_vid = 8191,
4108
		.port_base_addr = 0x0,
4109
		.phy_base_addr = 0x0,
4110
		.global1_addr = 0x1b,
4111
		.global2_addr = 0x1c,
4112
		.age_time_coeff = 3750,
4113
		.g1_irqs = 9,
4114
		.g2_irqs = 14,
4115
		.atu_move_port_mask = 0x1f,
4116
		.pvt = true,
4117
		.multi_chip = true,
4118
		.tag_protocol = DSA_TAG_PROTO_DSA,
4119
		.ptp_support = true,
4120 4121 4122
		.ops = &mv88e6390_ops,
	},
	[MV88E6390X] = {
4123
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
4124 4125 4126 4127
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4128
		.num_internal_phys = 11,
4129
		.num_gpio = 16,
4130
		.max_vid = 8191,
4131
		.port_base_addr = 0x0,
4132
		.phy_base_addr = 0x0,
4133
		.global1_addr = 0x1b,
4134
		.global2_addr = 0x1c,
4135
		.age_time_coeff = 3750,
4136
		.g1_irqs = 9,
4137
		.g2_irqs = 14,
4138
		.atu_move_port_mask = 0x1f,
4139
		.pvt = true,
4140
		.multi_chip = true,
4141
		.tag_protocol = DSA_TAG_PROTO_DSA,
4142
		.ptp_support = true,
4143 4144
		.ops = &mv88e6390x_ops,
	},
4145 4146
};

4147
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
4148
{
4149
	int i;
4150

4151 4152 4153
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
4154 4155 4156 4157

	return NULL;
}

4158
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
4159 4160
{
	const struct mv88e6xxx_info *info;
4161 4162 4163
	unsigned int prod_num, rev;
	u16 id;
	int err;
4164

4165
	mutex_lock(&chip->reg_lock);
4166
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
4167 4168 4169
	mutex_unlock(&chip->reg_lock);
	if (err)
		return err;
4170

4171 4172
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
4173 4174 4175 4176 4177

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

4178
	/* Update the compatible info with the probed one */
4179
	chip->info = info;
4180

4181 4182 4183 4184
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

4185 4186
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
4187 4188 4189 4190

	return 0;
}

4191
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
4192
{
4193
	struct mv88e6xxx_chip *chip;
4194

4195 4196
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
4197 4198
		return NULL;

4199
	chip->dev = dev;
4200

4201
	mutex_init(&chip->reg_lock);
4202
	INIT_LIST_HEAD(&chip->mdios);
4203

4204
	return chip;
4205 4206
}

4207
static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
4208 4209
			      struct mii_bus *bus, int sw_addr)
{
4210
	if (sw_addr == 0)
4211
		chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
4212
	else if (chip->info->multi_chip)
4213
		chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
4214 4215 4216
	else
		return -EINVAL;

4217 4218
	chip->bus = bus;
	chip->sw_addr = sw_addr;
4219 4220 4221 4222

	return 0;
}

4223 4224
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
							int port)
4225
{
V
Vivien Didelot 已提交
4226
	struct mv88e6xxx_chip *chip = ds->priv;
4227

4228
	return chip->info->tag_protocol;
4229 4230
}

4231
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
4232 4233 4234
static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
				       struct device *host_dev, int sw_addr,
				       void **priv)
4235
{
4236
	struct mv88e6xxx_chip *chip;
4237
	struct mii_bus *bus;
4238
	int err;
4239

4240
	bus = dsa_host_dev_to_mii_bus(host_dev);
4241 4242 4243
	if (!bus)
		return NULL;

4244 4245
	chip = mv88e6xxx_alloc_chip(dsa_dev);
	if (!chip)
4246 4247
		return NULL;

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

4251
	err = mv88e6xxx_smi_init(chip, bus, sw_addr);
4252 4253 4254
	if (err)
		goto free;

4255
	err = mv88e6xxx_detect(chip);
4256
	if (err)
4257
		goto free;
4258

4259 4260 4261 4262 4263 4264
	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_switch_reset(chip);
	mutex_unlock(&chip->reg_lock);
	if (err)
		goto free;

4265 4266
	mv88e6xxx_phy_init(chip);

4267
	err = mv88e6xxx_mdios_register(chip, NULL);
4268
	if (err)
4269
		goto free;
4270

4271
	*priv = chip;
4272

4273
	return chip->info->name;
4274
free:
4275
	devm_kfree(dsa_dev, chip);
4276 4277

	return NULL;
4278
}
4279
#endif
4280

4281
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4282
				      const struct switchdev_obj_port_mdb *mdb)
4283 4284 4285 4286 4287 4288 4289 4290 4291
{
	/* 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,
4292
				   const struct switchdev_obj_port_mdb *mdb)
4293
{
V
Vivien Didelot 已提交
4294
	struct mv88e6xxx_chip *chip = ds->priv;
4295 4296 4297

	mutex_lock(&chip->reg_lock);
	if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4298
					 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
4299 4300
		dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
			port);
4301 4302 4303 4304 4305 4306
	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 已提交
4307
	struct mv88e6xxx_chip *chip = ds->priv;
4308 4309 4310 4311
	int err;

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4312
					   MV88E6XXX_G1_ATU_DATA_STATE_UNUSED);
4313 4314 4315 4316 4317
	mutex_unlock(&chip->reg_lock);

	return err;
}

4318
static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
4319
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
4320
	.probe			= mv88e6xxx_drv_probe,
4321
#endif
4322
	.get_tag_protocol	= mv88e6xxx_get_tag_protocol,
4323 4324
	.setup			= mv88e6xxx_setup,
	.adjust_link		= mv88e6xxx_adjust_link,
4325 4326 4327 4328 4329
	.phylink_validate	= mv88e6xxx_validate,
	.phylink_mac_link_state	= mv88e6xxx_link_state,
	.phylink_mac_config	= mv88e6xxx_mac_config,
	.phylink_mac_link_down	= mv88e6xxx_mac_link_down,
	.phylink_mac_link_up	= mv88e6xxx_mac_link_up,
4330 4331 4332
	.get_strings		= mv88e6xxx_get_strings,
	.get_ethtool_stats	= mv88e6xxx_get_ethtool_stats,
	.get_sset_count		= mv88e6xxx_get_sset_count,
4333 4334
	.port_enable		= mv88e6xxx_port_enable,
	.port_disable		= mv88e6xxx_port_disable,
V
Vivien Didelot 已提交
4335 4336
	.get_mac_eee		= mv88e6xxx_get_mac_eee,
	.set_mac_eee		= mv88e6xxx_set_mac_eee,
4337
	.get_eeprom_len		= mv88e6xxx_get_eeprom_len,
4338 4339 4340 4341
	.get_eeprom		= mv88e6xxx_get_eeprom,
	.set_eeprom		= mv88e6xxx_set_eeprom,
	.get_regs_len		= mv88e6xxx_get_regs_len,
	.get_regs		= mv88e6xxx_get_regs,
4342
	.set_ageing_time	= mv88e6xxx_set_ageing_time,
4343 4344 4345
	.port_bridge_join	= mv88e6xxx_port_bridge_join,
	.port_bridge_leave	= mv88e6xxx_port_bridge_leave,
	.port_stp_state_set	= mv88e6xxx_port_stp_state_set,
4346
	.port_fast_age		= mv88e6xxx_port_fast_age,
4347 4348 4349 4350 4351 4352 4353
	.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,
4354 4355 4356
	.port_mdb_prepare       = mv88e6xxx_port_mdb_prepare,
	.port_mdb_add           = mv88e6xxx_port_mdb_add,
	.port_mdb_del           = mv88e6xxx_port_mdb_del,
4357 4358
	.crosschip_bridge_join	= mv88e6xxx_crosschip_bridge_join,
	.crosschip_bridge_leave	= mv88e6xxx_crosschip_bridge_leave,
4359 4360 4361 4362 4363
	.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,
4364 4365
};

4366 4367 4368 4369
static struct dsa_switch_driver mv88e6xxx_switch_drv = {
	.ops			= &mv88e6xxx_switch_ops,
};

4370
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
4371
{
4372
	struct device *dev = chip->dev;
4373 4374
	struct dsa_switch *ds;

4375
	ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
4376 4377 4378
	if (!ds)
		return -ENOMEM;

4379
	ds->priv = chip;
4380
	ds->dev = dev;
4381
	ds->ops = &mv88e6xxx_switch_ops;
4382 4383
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
4384 4385 4386

	dev_set_drvdata(dev, ds);

4387
	return dsa_register_switch(ds);
4388 4389
}

4390
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
4391
{
4392
	dsa_unregister_switch(chip->ds);
4393 4394
}

4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407
static const void *pdata_device_get_match_data(struct device *dev)
{
	const struct of_device_id *matches = dev->driver->of_match_table;
	const struct dsa_mv88e6xxx_pdata *pdata = dev->platform_data;

	for (; matches->name[0] || matches->type[0] || matches->compatible[0];
	     matches++) {
		if (!strcmp(pdata->compatible, matches->compatible))
			return matches->data;
	}
	return NULL;
}

4408
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
4409
{
4410
	struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
4411
	const struct mv88e6xxx_info *compat_info = NULL;
4412
	struct device *dev = &mdiodev->dev;
4413
	struct device_node *np = dev->of_node;
4414
	struct mv88e6xxx_chip *chip;
4415
	int port;
4416
	int err;
4417

4418 4419 4420
	if (!np && !pdata)
		return -EINVAL;

4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439
	if (np)
		compat_info = of_device_get_match_data(dev);

	if (pdata) {
		compat_info = pdata_device_get_match_data(dev);

		if (!pdata->netdev)
			return -EINVAL;

		for (port = 0; port < DSA_MAX_PORTS; port++) {
			if (!(pdata->enabled_ports & (1 << port)))
				continue;
			if (strcmp(pdata->cd.port_names[port], "cpu"))
				continue;
			pdata->cd.netdev[port] = &pdata->netdev->dev;
			break;
		}
	}

4440 4441 4442
	if (!compat_info)
		return -EINVAL;

4443
	chip = mv88e6xxx_alloc_chip(dev);
4444 4445 4446 4447
	if (!chip) {
		err = -ENOMEM;
		goto out;
	}
4448

4449
	chip->info = compat_info;
4450

4451
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
4452
	if (err)
4453
		goto out;
4454

4455
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4456 4457 4458 4459
	if (IS_ERR(chip->reset)) {
		err = PTR_ERR(chip->reset);
		goto out;
	}
4460

4461
	err = mv88e6xxx_detect(chip);
4462
	if (err)
4463
		goto out;
4464

4465 4466
	mv88e6xxx_phy_init(chip);

4467 4468 4469 4470 4471 4472 4473
	if (chip->info->ops->get_eeprom) {
		if (np)
			of_property_read_u32(np, "eeprom-length",
					     &chip->eeprom_len);
		else
			chip->eeprom_len = pdata->eeprom_len;
	}
4474

4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486
	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;
	}

4487
	/* Has to be performed before the MDIO bus is created, because
4488
	 * the PHYs will link their interrupts to these interrupt
4489 4490 4491 4492
	 * controllers
	 */
	mutex_lock(&chip->reg_lock);
	if (chip->irq > 0)
4493
		err = mv88e6xxx_g1_irq_setup(chip);
4494 4495 4496
	else
		err = mv88e6xxx_irq_poll_setup(chip);
	mutex_unlock(&chip->reg_lock);
4497

4498 4499
	if (err)
		goto out;
4500

4501 4502
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
4503
		if (err)
4504
			goto out_g1_irq;
4505 4506
	}

4507 4508 4509 4510 4511 4512 4513 4514
	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;

4515
	err = mv88e6xxx_mdios_register(chip, np);
4516
	if (err)
4517
		goto out_g1_vtu_prob_irq;
4518

4519
	err = mv88e6xxx_register_switch(chip);
4520 4521
	if (err)
		goto out_mdio;
4522

4523
	return 0;
4524 4525

out_mdio:
4526
	mv88e6xxx_mdios_unregister(chip);
4527
out_g1_vtu_prob_irq:
4528
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
4529
out_g1_atu_prob_irq:
4530
	mv88e6xxx_g1_atu_prob_irq_free(chip);
4531
out_g2_irq:
4532
	if (chip->info->g2_irqs > 0)
4533 4534
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
4535
	if (chip->irq > 0)
4536
		mv88e6xxx_g1_irq_free(chip);
4537 4538
	else
		mv88e6xxx_irq_poll_free(chip);
4539
out:
4540 4541 4542
	if (pdata)
		dev_put(pdata->netdev);

4543
	return err;
4544
}
4545 4546 4547 4548

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

4551 4552
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
4553
		mv88e6xxx_ptp_free(chip);
4554
	}
4555

4556
	mv88e6xxx_phy_destroy(chip);
4557
	mv88e6xxx_unregister_switch(chip);
4558
	mv88e6xxx_mdios_unregister(chip);
4559

4560 4561 4562 4563 4564 4565 4566
	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);

	if (chip->irq > 0)
4567
		mv88e6xxx_g1_irq_free(chip);
4568 4569
	else
		mv88e6xxx_irq_poll_free(chip);
4570 4571 4572
}

static const struct of_device_id mv88e6xxx_of_match[] = {
4573 4574 4575 4576
	{
		.compatible = "marvell,mv88e6085",
		.data = &mv88e6xxx_table[MV88E6085],
	},
4577 4578 4579 4580
	{
		.compatible = "marvell,mv88e6190",
		.data = &mv88e6xxx_table[MV88E6190],
	},
4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596
	{ /* 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)
{
4597
	register_switch_driver(&mv88e6xxx_switch_drv);
4598 4599
	return mdio_driver_register(&mv88e6xxx_driver);
}
4600 4601 4602 4603
module_init(mv88e6xxx_init);

static void __exit mv88e6xxx_cleanup(void)
{
4604
	mdio_driver_unregister(&mv88e6xxx_driver);
4605
	unregister_switch_driver(&mv88e6xxx_switch_drv);
4606 4607
}
module_exit(mv88e6xxx_cleanup);
4608 4609 4610 4611

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