chip.c 166.0 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0-or-later
2
/*
3 4
 * Marvell 88e6xxx Ethernet switch single-chip support
 *
5 6
 * Copyright (c) 2008 Marvell Semiconductor
 *
7 8
 * Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch>
 *
V
Vivien Didelot 已提交
9 10
 * Copyright (c) 2016-2017 Savoir-faire Linux Inc.
 *	Vivien Didelot <vivien.didelot@savoirfairelinux.com>
11 12
 */

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

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

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

52
int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val)
53 54 55
{
	int err;

56
	assert_reg_lock(chip);
57

58
	err = mv88e6xxx_smi_read(chip, addr, reg, val);
59 60 61
	if (err)
		return err;

62
	dev_dbg(chip->dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
63 64 65 66 67
		addr, reg, *val);

	return 0;
}

68
int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val)
69
{
70 71
	int err;

72
	assert_reg_lock(chip);
73

74
	err = mv88e6xxx_smi_write(chip, addr, reg, val);
75 76 77
	if (err)
		return err;

78
	dev_dbg(chip->dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
79 80
		addr, reg, val);

81 82 83
	return 0;
}

84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
int mv88e6xxx_wait_mask(struct mv88e6xxx_chip *chip, int addr, int reg,
			u16 mask, u16 val)
{
	u16 data;
	int err;
	int i;

	/* There's no bus specific operation to wait for a mask */
	for (i = 0; i < 16; i++) {
		err = mv88e6xxx_read(chip, addr, reg, &data);
		if (err)
			return err;

		if ((data & mask) == val)
			return 0;

		usleep_range(1000, 2000);
	}

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

107 108 109 110 111 112 113
int mv88e6xxx_wait_bit(struct mv88e6xxx_chip *chip, int addr, int reg,
		       int bit, int val)
{
	return mv88e6xxx_wait_mask(chip, addr, reg, BIT(bit),
				   val ? BIT(bit) : 0x0000);
}

114
struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
115 116 117 118 119 120 121 122 123 124 125
{
	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;
}

126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
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);
}

142
static irqreturn_t mv88e6xxx_g1_irq_thread_work(struct mv88e6xxx_chip *chip)
143 144 145 146 147
{
	unsigned int nhandled = 0;
	unsigned int sub_irq;
	unsigned int n;
	u16 reg;
148
	u16 ctl1;
149 150
	int err;

151
	mv88e6xxx_reg_lock(chip);
152
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
153
	mv88e6xxx_reg_unlock(chip);
154 155 156 157

	if (err)
		goto out;

158 159 160 161 162 163 164 165
	do {
		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;
			}
166
		}
167

168
		mv88e6xxx_reg_lock(chip);
169 170 171 172 173
		err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &ctl1);
		if (err)
			goto unlock;
		err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
unlock:
174
		mv88e6xxx_reg_unlock(chip);
175 176 177 178 179
		if (err)
			goto out;
		ctl1 &= GENMASK(chip->g1_irq.nirqs, 0);
	} while (reg & ctl1);

180 181 182 183
out:
	return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
}

184 185 186 187 188 189 190
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);
}

191 192 193 194
static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
{
	struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);

195
	mv88e6xxx_reg_lock(chip);
196 197 198 199 200 201 202 203 204
}

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;

205
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &reg);
206 207 208 209 210 211
	if (err)
		goto out;

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

212
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, reg);
213 214 215 216
	if (err)
		goto out;

out:
217
	mv88e6xxx_reg_unlock(chip);
218 219
}

220
static const struct irq_chip mv88e6xxx_g1_irq_chip = {
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
	.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,
};

246
/* To be called with reg_lock held */
247
static void mv88e6xxx_g1_irq_free_common(struct mv88e6xxx_chip *chip)
248 249
{
	int irq, virq;
250 251
	u16 mask;

252
	mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
253
	mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
254
	mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
255

256
	for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
257
		virq = irq_find_mapping(chip->g1_irq.domain, irq);
258 259 260
		irq_dispose_mapping(virq);
	}

261
	irq_domain_remove(chip->g1_irq.domain);
262 263
}

264 265
static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
{
266 267 268 269
	/*
	 * free_irq must be called without reg_lock taken because the irq
	 * handler takes this lock, too.
	 */
270
	free_irq(chip->irq, chip);
271

272
	mv88e6xxx_reg_lock(chip);
273
	mv88e6xxx_g1_irq_free_common(chip);
274
	mv88e6xxx_reg_unlock(chip);
275 276 277
}

static int mv88e6xxx_g1_irq_setup_common(struct mv88e6xxx_chip *chip)
278
{
279 280
	int err, irq, virq;
	u16 reg, mask;
281 282 283 284 285 286 287 288 289 290 291 292 293 294

	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;

295
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
296
	if (err)
297
		goto out_mapping;
298

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

301
	err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
302
	if (err)
303
		goto out_disable;
304 305

	/* Reading the interrupt status clears (most of) them */
306
	err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
307
	if (err)
308
		goto out_disable;
309 310 311

	return 0;

312
out_disable:
313
	mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
314
	mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
315 316 317 318 319 320 321 322

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);
323 324 325 326

	return err;
}

327 328
static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
{
329 330
	static struct lock_class_key lock_key;
	static struct lock_class_key request_key;
331 332 333 334 335 336
	int err;

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

337 338 339 340 341 342
	/* These lock classes tells lockdep that global 1 irqs are in
	 * a different category than their parent GPIO, so it won't
	 * report false recursion.
	 */
	irq_set_lockdep_class(chip->irq, &lock_key, &request_key);

343 344 345
	snprintf(chip->irq_name, sizeof(chip->irq_name),
		 "mv88e6xxx-%s", dev_name(chip->dev));

346
	mv88e6xxx_reg_unlock(chip);
347 348
	err = request_threaded_irq(chip->irq, NULL,
				   mv88e6xxx_g1_irq_thread_fn,
349
				   IRQF_ONESHOT | IRQF_SHARED,
350
				   chip->irq_name, chip);
351
	mv88e6xxx_reg_lock(chip);
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
	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);

380
	chip->kworker = kthread_create_worker(0, "%s", dev_name(chip->dev));
381 382 383 384 385 386 387 388 389 390 391 392 393
	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);
394

395
	mv88e6xxx_reg_lock(chip);
396
	mv88e6xxx_g1_irq_free_common(chip);
397
	mv88e6xxx_reg_unlock(chip);
398 399
}

400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
static int mv88e6xxx_port_config_interface(struct mv88e6xxx_chip *chip,
					   int port, phy_interface_t interface)
{
	int err;

	if (chip->info->ops->port_set_rgmii_delay) {
		err = chip->info->ops->port_set_rgmii_delay(chip, port,
							    interface);
		if (err && err != -EOPNOTSUPP)
			return err;
	}

	if (chip->info->ops->port_set_cmode) {
		err = chip->info->ops->port_set_cmode(chip, port,
						      interface);
		if (err && err != -EOPNOTSUPP)
			return err;
	}

	return 0;
}

422 423 424
static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
				    int link, int speed, int duplex, int pause,
				    phy_interface_t mode)
425 426 427 428 429 430 431
{
	int err;

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

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

436 437 438
	if (chip->info->ops->port_set_speed_duplex) {
		err = chip->info->ops->port_set_speed_duplex(chip, port,
							     speed, duplex);
439 440 441 442
		if (err && err != -EOPNOTSUPP)
			goto restore_link;
	}

443 444 445
	if (speed == SPEED_MAX && chip->info->ops->port_max_speed_mode)
		mode = chip->info->ops->port_max_speed_mode(port);

446 447 448 449 450 451
	if (chip->info->ops->port_set_pause) {
		err = chip->info->ops->port_set_pause(chip, port, pause);
		if (err)
			goto restore_link;
	}

452
	err = mv88e6xxx_port_config_interface(chip, port, mode);
453 454
restore_link:
	if (chip->info->ops->port_set_link(chip, port, link))
455
		dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
456 457 458 459

	return err;
}

460 461 462 463 464 465 466
static int mv88e6xxx_phy_is_internal(struct dsa_switch *ds, int port)
{
	struct mv88e6xxx_chip *chip = ds->priv;

	return port < chip->info->num_internal_phys;
}

467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
static int mv88e6xxx_port_ppu_updates(struct mv88e6xxx_chip *chip, int port)
{
	u16 reg;
	int err;

	err = mv88e6xxx_port_read(chip, port, MV88E6XXX_PORT_STS, &reg);
	if (err) {
		dev_err(chip->dev,
			"p%d: %s: failed to read port status\n",
			port, __func__);
		return err;
	}

	return !!(reg & MV88E6XXX_PORT_STS_PHY_DETECT);
}

483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557
static int mv88e6xxx_serdes_pcs_get_state(struct dsa_switch *ds, int port,
					  struct phylink_link_state *state)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	u8 lane;
	int err;

	mv88e6xxx_reg_lock(chip);
	lane = mv88e6xxx_serdes_get_lane(chip, port);
	if (lane && chip->info->ops->serdes_pcs_get_state)
		err = chip->info->ops->serdes_pcs_get_state(chip, port, lane,
							    state);
	else
		err = -EOPNOTSUPP;
	mv88e6xxx_reg_unlock(chip);

	return err;
}

static int mv88e6xxx_serdes_pcs_config(struct mv88e6xxx_chip *chip, int port,
				       unsigned int mode,
				       phy_interface_t interface,
				       const unsigned long *advertise)
{
	const struct mv88e6xxx_ops *ops = chip->info->ops;
	u8 lane;

	if (ops->serdes_pcs_config) {
		lane = mv88e6xxx_serdes_get_lane(chip, port);
		if (lane)
			return ops->serdes_pcs_config(chip, port, lane, mode,
						      interface, advertise);
	}

	return 0;
}

static void mv88e6xxx_serdes_pcs_an_restart(struct dsa_switch *ds, int port)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	const struct mv88e6xxx_ops *ops;
	int err = 0;
	u8 lane;

	ops = chip->info->ops;

	if (ops->serdes_pcs_an_restart) {
		mv88e6xxx_reg_lock(chip);
		lane = mv88e6xxx_serdes_get_lane(chip, port);
		if (lane)
			err = ops->serdes_pcs_an_restart(chip, port, lane);
		mv88e6xxx_reg_unlock(chip);

		if (err)
			dev_err(ds->dev, "p%d: failed to restart AN\n", port);
	}
}

static int mv88e6xxx_serdes_pcs_link_up(struct mv88e6xxx_chip *chip, int port,
					unsigned int mode,
					int speed, int duplex)
{
	const struct mv88e6xxx_ops *ops = chip->info->ops;
	u8 lane;

	if (!phylink_autoneg_inband(mode) && ops->serdes_pcs_link_up) {
		lane = mv88e6xxx_serdes_get_lane(chip, port);
		if (lane)
			return ops->serdes_pcs_link_up(chip, port, lane,
						       speed, duplex);
	}

	return 0;
}

558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
static void mv88e6065_phylink_validate(struct mv88e6xxx_chip *chip, int port,
				       unsigned long *mask,
				       struct phylink_link_state *state)
{
	if (!phy_interface_mode_is_8023z(state->interface)) {
		/* 10M and 100M are only supported in non-802.3z mode */
		phylink_set(mask, 10baseT_Half);
		phylink_set(mask, 10baseT_Full);
		phylink_set(mask, 100baseT_Half);
		phylink_set(mask, 100baseT_Full);
	}
}

static void mv88e6185_phylink_validate(struct mv88e6xxx_chip *chip, int port,
				       unsigned long *mask,
				       struct phylink_link_state *state)
{
	/* FIXME: if the port is in 1000Base-X mode, then it only supports
	 * 1000M FD speeds.  In this case, CMODE will indicate 5.
	 */
	phylink_set(mask, 1000baseT_Full);
	phylink_set(mask, 1000baseX_Full);

	mv88e6065_phylink_validate(chip, port, mask, state);
}

584 585 586 587 588 589 590 591 592 593 594 595 596 597
static void mv88e6341_phylink_validate(struct mv88e6xxx_chip *chip, int port,
				       unsigned long *mask,
				       struct phylink_link_state *state)
{
	if (port >= 5)
		phylink_set(mask, 2500baseX_Full);

	/* No ethtool bits for 200Mbps */
	phylink_set(mask, 1000baseT_Full);
	phylink_set(mask, 1000baseX_Full);

	mv88e6065_phylink_validate(chip, port, mask, state);
}

598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
static void mv88e6352_phylink_validate(struct mv88e6xxx_chip *chip, int port,
				       unsigned long *mask,
				       struct phylink_link_state *state)
{
	/* No ethtool bits for 200Mbps */
	phylink_set(mask, 1000baseT_Full);
	phylink_set(mask, 1000baseX_Full);

	mv88e6065_phylink_validate(chip, port, mask, state);
}

static void mv88e6390_phylink_validate(struct mv88e6xxx_chip *chip, int port,
				       unsigned long *mask,
				       struct phylink_link_state *state)
{
613
	if (port >= 9) {
614
		phylink_set(mask, 2500baseX_Full);
615 616
		phylink_set(mask, 2500baseT_Full);
	}
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636

	/* No ethtool bits for 200Mbps */
	phylink_set(mask, 1000baseT_Full);
	phylink_set(mask, 1000baseX_Full);

	mv88e6065_phylink_validate(chip, port, mask, state);
}

static void mv88e6390x_phylink_validate(struct mv88e6xxx_chip *chip, int port,
					unsigned long *mask,
					struct phylink_link_state *state)
{
	if (port >= 9) {
		phylink_set(mask, 10000baseT_Full);
		phylink_set(mask, 10000baseKR_Full);
	}

	mv88e6390_phylink_validate(chip, port, mask, state);
}

637 638 639 640
static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
			       unsigned long *supported,
			       struct phylink_link_state *state)
{
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
	__ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
	struct mv88e6xxx_chip *chip = ds->priv;

	/* Allow all the expected bits */
	phylink_set(mask, Autoneg);
	phylink_set(mask, Pause);
	phylink_set_port_modes(mask);

	if (chip->info->ops->phylink_validate)
		chip->info->ops->phylink_validate(chip, port, mask, state);

	bitmap_and(supported, supported, mask, __ETHTOOL_LINK_MODE_MASK_NBITS);
	bitmap_and(state->advertising, state->advertising, mask,
		   __ETHTOOL_LINK_MODE_MASK_NBITS);

	/* We can only operate at 2500BaseX or 1000BaseX.  If requested
	 * to advertise both, only report advertising at 2500BaseX.
	 */
	phylink_helper_basex_speed(state);
660 661 662 663 664 665 666
}

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;
667
	int err;
668

669 670 671 672 673
	/* FIXME: is this the correct test? If we're in fixed mode on an
	 * internal port, why should we process this any different from
	 * PHY mode? On the other hand, the port may be automedia between
	 * an internal PHY and the serdes...
	 */
674
	if ((mode == MLO_AN_PHY) && mv88e6xxx_phy_is_internal(ds, port))
675 676
		return;

677
	mv88e6xxx_reg_lock(chip);
678 679 680 681 682
	/* FIXME: should we force the link down here - but if we do, how
	 * do we restore the link force/unforce state? The driver layering
	 * gets in the way.
	 */
	err = mv88e6xxx_port_config_interface(chip, port, state->interface);
683 684 685 686 687 688 689 690 691 692 693 694
	if (err && err != -EOPNOTSUPP)
		goto err_unlock;

	err = mv88e6xxx_serdes_pcs_config(chip, port, mode, state->interface,
					  state->advertising);
	/* FIXME: we should restart negotiation if something changed - which
	 * is something we get if we convert to using phylinks PCS operations.
	 */
	if (err > 0)
		err = 0;

err_unlock:
695
	mv88e6xxx_reg_unlock(chip);
696 697

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

701 702 703
static void mv88e6xxx_mac_link_down(struct dsa_switch *ds, int port,
				    unsigned int mode,
				    phy_interface_t interface)
704 705
{
	struct mv88e6xxx_chip *chip = ds->priv;
706 707
	const struct mv88e6xxx_ops *ops;
	int err = 0;
708

709
	ops = chip->info->ops;
710

711
	mv88e6xxx_reg_lock(chip);
712 713
	if ((!mv88e6xxx_port_ppu_updates(chip, port) ||
	     mode == MLO_AN_FIXED) && ops->port_set_link)
714
		err = ops->port_set_link(chip, port, LINK_FORCED_DOWN);
715
	mv88e6xxx_reg_unlock(chip);
716

717 718 719
	if (err)
		dev_err(chip->dev,
			"p%d: failed to force MAC link down\n", port);
720 721 722 723
}

static void mv88e6xxx_mac_link_up(struct dsa_switch *ds, int port,
				  unsigned int mode, phy_interface_t interface,
724 725 726
				  struct phy_device *phydev,
				  int speed, int duplex,
				  bool tx_pause, bool rx_pause)
727
{
728 729 730 731 732 733
	struct mv88e6xxx_chip *chip = ds->priv;
	const struct mv88e6xxx_ops *ops;
	int err = 0;

	ops = chip->info->ops;

734
	mv88e6xxx_reg_lock(chip);
735
	if (!mv88e6xxx_port_ppu_updates(chip, port) || mode == MLO_AN_FIXED) {
736 737 738
		/* FIXME: for an automedia port, should we force the link
		 * down here - what if the link comes up due to "other" media
		 * while we're bringing the port up, how is the exclusivity
739
		 * handled in the Marvell hardware? E.g. port 2 on 88E6390
740 741
		 * shared between internal PHY and Serdes.
		 */
742 743 744 745 746
		err = mv88e6xxx_serdes_pcs_link_up(chip, port, mode, speed,
						   duplex);
		if (err)
			goto error;

747 748 749
		if (ops->port_set_speed_duplex) {
			err = ops->port_set_speed_duplex(chip, port,
							 speed, duplex);
750 751 752 753 754 755
			if (err && err != -EOPNOTSUPP)
				goto error;
		}

		if (ops->port_set_link)
			err = ops->port_set_link(chip, port, LINK_FORCED_UP);
756
	}
757
error:
758
	mv88e6xxx_reg_unlock(chip);
759

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

765
static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
766
{
767 768
	if (!chip->info->ops->stats_snapshot)
		return -EOPNOTSUPP;
769

770
	return chip->info->ops->stats_snapshot(chip, port);
771 772
}

773
static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832
	{ "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, },
833 834
};

835
static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
836
					    struct mv88e6xxx_hw_stat *s,
837 838
					    int port, u16 bank1_select,
					    u16 histogram)
839 840 841
{
	u32 low;
	u32 high = 0;
842
	u16 reg = 0;
843
	int err;
844 845
	u64 value;

846
	switch (s->type) {
847
	case STATS_TYPE_PORT:
848 849
		err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
		if (err)
850
			return U64_MAX;
851

852
		low = reg;
853
		if (s->size == 4) {
854 855
			err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
			if (err)
856
				return U64_MAX;
857
			low |= ((u32)reg) << 16;
858
		}
859
		break;
860
	case STATS_TYPE_BANK1:
861
		reg = bank1_select;
862 863
		/* fall through */
	case STATS_TYPE_BANK0:
864
		reg |= s->reg | histogram;
865
		mv88e6xxx_g1_stats_read(chip, reg, &low);
866
		if (s->size == 8)
867
			mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
868 869
		break;
	default:
870
		return U64_MAX;
871
	}
872
	value = (((u64)high) << 32) | low;
873 874 875
	return value;
}

876 877
static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data, int types)
878
{
879 880
	struct mv88e6xxx_hw_stat *stat;
	int i, j;
881

882 883
	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
		stat = &mv88e6xxx_hw_stats[i];
884
		if (stat->type & types) {
885 886 887 888
			memcpy(data + j * ETH_GSTRING_LEN, stat->string,
			       ETH_GSTRING_LEN);
			j++;
		}
889
	}
890 891

	return j;
892 893
}

894 895
static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
896
{
897 898
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_PORT);
899 900
}

901 902 903 904 905 906
static int mv88e6250_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
{
	return mv88e6xxx_stats_get_strings(chip, data, STATS_TYPE_BANK0);
}

907 908
static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
909
{
910 911
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
912 913
}

914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931
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);
}

932
static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
933
				  u32 stringset, uint8_t *data)
934
{
V
Vivien Didelot 已提交
935
	struct mv88e6xxx_chip *chip = ds->priv;
936
	int count = 0;
937

938 939 940
	if (stringset != ETH_SS_STATS)
		return;

941
	mv88e6xxx_reg_lock(chip);
942

943
	if (chip->info->ops->stats_get_strings)
944 945 946 947
		count = chip->info->ops->stats_get_strings(chip, data);

	if (chip->info->ops->serdes_get_strings) {
		data += count * ETH_GSTRING_LEN;
948
		count = chip->info->ops->serdes_get_strings(chip, port, data);
949
	}
950

951 952 953
	data += count * ETH_GSTRING_LEN;
	mv88e6xxx_atu_vtu_get_strings(data);

954
	mv88e6xxx_reg_unlock(chip);
955 956 957 958 959
}

static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
					  int types)
{
960 961 962 963 964
	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];
965
		if (stat->type & types)
966 967 968
			j++;
	}
	return j;
969 970
}

971 972 973 974 975 976
static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
{
	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
					      STATS_TYPE_PORT);
}

977 978 979 980 981
static int mv88e6250_stats_get_sset_count(struct mv88e6xxx_chip *chip)
{
	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0);
}

982 983 984 985 986 987
static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
{
	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
					      STATS_TYPE_BANK1);
}

988
static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
989 990
{
	struct mv88e6xxx_chip *chip = ds->priv;
991 992
	int serdes_count = 0;
	int count = 0;
993

994 995 996
	if (sset != ETH_SS_STATS)
		return 0;

997
	mv88e6xxx_reg_lock(chip);
998
	if (chip->info->ops->stats_get_sset_count)
999 1000 1001 1002 1003 1004 1005
		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);
1006
	if (serdes_count < 0) {
1007
		count = serdes_count;
1008 1009 1010 1011 1012
		goto out;
	}
	count += serdes_count;
	count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);

1013
out:
1014
	mv88e6xxx_reg_unlock(chip);
1015

1016
	return count;
1017 1018
}

1019 1020 1021
static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data, int types,
				     u16 bank1_select, u16 histogram)
1022 1023 1024 1025 1026 1027 1028
{
	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) {
1029
			mv88e6xxx_reg_lock(chip);
1030 1031 1032
			data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
							      bank1_select,
							      histogram);
1033
			mv88e6xxx_reg_unlock(chip);
1034

1035 1036 1037
			j++;
		}
	}
1038
	return j;
1039 1040
}

1041 1042
static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
1043 1044
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
1045
					 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
1046
					 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1047 1048
}

1049 1050 1051 1052 1053 1054 1055
static int mv88e6250_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
{
	return mv88e6xxx_stats_get_stats(chip, port, data, STATS_TYPE_BANK0,
					 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
}

1056 1057
static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
1058 1059
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
1060
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1061 1062
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
					 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1063 1064
}

1065 1066
static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
1067 1068 1069
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1070 1071
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
					 0);
1072 1073
}

1074 1075 1076 1077 1078 1079 1080 1081 1082 1083
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;
}

1084 1085 1086
static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
				uint64_t *data)
{
1087 1088
	int count = 0;

1089
	if (chip->info->ops->stats_get_stats)
1090 1091
		count = chip->info->ops->stats_get_stats(chip, port, data);

1092
	mv88e6xxx_reg_lock(chip);
1093 1094
	if (chip->info->ops->serdes_get_stats) {
		data += count;
1095
		count = chip->info->ops->serdes_get_stats(chip, port, data);
1096
	}
1097 1098
	data += count;
	mv88e6xxx_atu_vtu_get_stats(chip, port, data);
1099
	mv88e6xxx_reg_unlock(chip);
1100 1101
}

1102 1103
static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
					uint64_t *data)
1104
{
V
Vivien Didelot 已提交
1105
	struct mv88e6xxx_chip *chip = ds->priv;
1106 1107
	int ret;

1108
	mv88e6xxx_reg_lock(chip);
1109

1110
	ret = mv88e6xxx_stats_snapshot(chip, port);
1111
	mv88e6xxx_reg_unlock(chip);
1112 1113

	if (ret < 0)
1114
		return;
1115 1116

	mv88e6xxx_get_stats(chip, port, data);
1117

1118 1119
}

1120
static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
1121
{
1122 1123 1124 1125 1126 1127 1128 1129
	struct mv88e6xxx_chip *chip = ds->priv;
	int len;

	len = 32 * sizeof(u16);
	if (chip->info->ops->serdes_get_regs_len)
		len += chip->info->ops->serdes_get_regs_len(chip, port);

	return len;
1130 1131
}

1132 1133
static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
			       struct ethtool_regs *regs, void *_p)
1134
{
V
Vivien Didelot 已提交
1135
	struct mv88e6xxx_chip *chip = ds->priv;
1136 1137
	int err;
	u16 reg;
1138 1139 1140
	u16 *p = _p;
	int i;

1141
	regs->version = chip->info->prod_num;
1142 1143 1144

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

1145
	mv88e6xxx_reg_lock(chip);
1146

1147 1148
	for (i = 0; i < 32; i++) {

1149 1150 1151
		err = mv88e6xxx_port_read(chip, port, i, &reg);
		if (!err)
			p[i] = reg;
1152
	}
1153

1154 1155 1156
	if (chip->info->ops->serdes_get_regs)
		chip->info->ops->serdes_get_regs(chip, port, &p[i]);

1157
	mv88e6xxx_reg_unlock(chip);
1158 1159
}

V
Vivien Didelot 已提交
1160 1161
static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
1162
{
1163 1164
	/* Nothing to do on the port's MAC */
	return 0;
1165 1166
}

V
Vivien Didelot 已提交
1167 1168
static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
1169
{
1170 1171
	/* Nothing to do on the port's MAC */
	return 0;
1172 1173
}

1174
/* Mask of the local ports allowed to receive frames from a given fabric port */
1175
static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
1176
{
1177 1178
	struct dsa_switch *ds = chip->ds;
	struct dsa_switch_tree *dst = ds->dst;
1179
	struct net_device *br;
1180 1181
	struct dsa_port *dp;
	bool found = false;
1182
	u16 pvlan;
1183

1184 1185 1186 1187 1188 1189
	list_for_each_entry(dp, &dst->ports, list) {
		if (dp->ds->index == dev && dp->index == port) {
			found = true;
			break;
		}
	}
1190 1191

	/* Prevent frames from unknown switch or port */
1192
	if (!found)
1193 1194 1195
		return 0;

	/* Frames from DSA links and CPU ports can egress any local port */
1196
	if (dp->type == DSA_PORT_TYPE_CPU || dp->type == DSA_PORT_TYPE_DSA)
1197 1198
		return mv88e6xxx_port_mask(chip);

1199
	br = dp->bridge_dev;
1200 1201 1202 1203 1204
	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.
	 */
1205 1206 1207 1208 1209 1210
	list_for_each_entry(dp, &dst->ports, list)
		if (dp->ds == ds &&
		    (dp->type == DSA_PORT_TYPE_CPU ||
		     dp->type == DSA_PORT_TYPE_DSA ||
		     (br && dp->bridge_dev == br)))
			pvlan |= BIT(dp->index);
1211 1212 1213 1214

	return pvlan;
}

1215
static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
1216 1217
{
	u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
1218 1219 1220

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

1222
	return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
1223 1224
}

1225 1226
static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
					 u8 state)
1227
{
V
Vivien Didelot 已提交
1228
	struct mv88e6xxx_chip *chip = ds->priv;
1229
	int err;
1230

1231
	mv88e6xxx_reg_lock(chip);
1232
	err = mv88e6xxx_port_set_state(chip, port, state);
1233
	mv88e6xxx_reg_unlock(chip);
1234 1235

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

1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257
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;
}

1258 1259
static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
{
1260
	struct dsa_switch *ds = chip->ds;
1261 1262 1263 1264 1265 1266 1267 1268
	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++) {
1269 1270 1271
		port = dsa_routing_port(ds, target);
		if (port == ds->num_ports)
			port = 0x1f;
1272 1273 1274 1275 1276 1277

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

1278 1279 1280 1281 1282 1283 1284
	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;
	}

1285 1286 1287 1288
	err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
	if (err)
		return err;

1289 1290 1291
	return 0;
}

1292 1293 1294 1295 1296 1297 1298 1299 1300
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;
}

1301 1302 1303 1304 1305 1306 1307 1308
static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->rmu_disable)
		return chip->info->ops->rmu_disable(chip);

	return 0;
}

1309 1310 1311 1312 1313 1314 1315 1316
static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->pot_clear)
		return chip->info->ops->pot_clear(chip);

	return 0;
}

1317 1318 1319 1320 1321 1322 1323 1324
static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->mgmt_rsvd2cpu)
		return chip->info->ops->mgmt_rsvd2cpu(chip);

	return 0;
}

1325 1326
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
1327 1328
	int err;

1329 1330 1331 1332
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

1333 1334 1335 1336
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

1337 1338 1339
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359
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;
}

1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372
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;
}

1373 1374 1375 1376 1377
static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
{
	u16 pvlan = 0;

	if (!mv88e6xxx_has_pvt(chip))
1378
		return 0;
1379 1380 1381

	/* Skip the local source device, which uses in-chip port VLAN */
	if (dev != chip->ds->index)
1382
		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1383 1384 1385 1386

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

1387 1388
static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
{
1389 1390 1391
	int dev, port;
	int err;

1392 1393 1394 1395 1396 1397
	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.
	 */
1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410
	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;
1411 1412
}

1413 1414 1415 1416 1417
static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

1418
	mv88e6xxx_reg_lock(chip);
1419
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1420
	mv88e6xxx_reg_unlock(chip);
1421 1422

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

1426 1427 1428 1429 1430 1431 1432 1433
static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
{
	if (!chip->info->max_vid)
		return 0;

	return mv88e6xxx_g1_vtu_flush(chip);
}

1434 1435 1436 1437 1438 1439 1440 1441 1442
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);
}

1443 1444 1445 1446 1447 1448 1449 1450 1451
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);
}

1452
static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1453 1454
{
	DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1455
	struct mv88e6xxx_vtu_entry vlan;
1456
	int i, err;
1457 1458 1459

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

1460
	/* Set every FID bit used by the (un)bridged ports */
1461
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1462
		err = mv88e6xxx_port_get_fid(chip, i, fid);
1463 1464 1465 1466 1467 1468
		if (err)
			return err;

		set_bit(*fid, fid_bitmap);
	}

1469
	/* Set every FID bit used by the VLAN entries */
1470 1471 1472
	vlan.vid = chip->info->max_vid;
	vlan.valid = false;

1473
	do {
1474
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1475 1476 1477 1478 1479 1480 1481
		if (err)
			return err;

		if (!vlan.valid)
			break;

		set_bit(vlan.fid, fid_bitmap);
1482
	} while (vlan.vid < chip->info->max_vid);
1483 1484 1485 1486 1487

	/* 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);
1488
	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1489 1490 1491
		return -ENOSPC;

	/* Clear the database */
1492
	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1493 1494
}

1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510
static int mv88e6xxx_atu_get_hash(struct mv88e6xxx_chip *chip, u8 *hash)
{
	if (chip->info->ops->atu_get_hash)
		return chip->info->ops->atu_get_hash(chip, hash);

	return -EOPNOTSUPP;
}

static int mv88e6xxx_atu_set_hash(struct mv88e6xxx_chip *chip, u8 hash)
{
	if (chip->info->ops->atu_set_hash)
		return chip->info->ops->atu_set_hash(chip, hash);

	return -EOPNOTSUPP;
}

1511 1512 1513
static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
					u16 vid_begin, u16 vid_end)
{
V
Vivien Didelot 已提交
1514
	struct mv88e6xxx_chip *chip = ds->priv;
1515
	struct mv88e6xxx_vtu_entry vlan;
1516 1517
	int i, err;

1518 1519 1520 1521
	/* 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;

1522 1523 1524
	if (!vid_begin)
		return -EOPNOTSUPP;

1525 1526 1527
	vlan.vid = vid_begin - 1;
	vlan.valid = false;

1528
	do {
1529
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1530
		if (err)
1531
			return err;
1532 1533 1534 1535 1536 1537 1538

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

1539
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1540 1541 1542
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

1543
			if (!dsa_to_port(ds, i)->slave)
1544 1545
				continue;

1546
			if (vlan.member[i] ==
1547
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1548 1549
				continue;

V
Vivien Didelot 已提交
1550
			if (dsa_to_port(ds, i)->bridge_dev ==
1551
			    dsa_to_port(ds, port)->bridge_dev)
1552 1553
				break; /* same bridge, check next VLAN */

V
Vivien Didelot 已提交
1554
			if (!dsa_to_port(ds, i)->bridge_dev)
1555 1556
				continue;

1557 1558
			dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
				port, vlan.vid, i,
V
Vivien Didelot 已提交
1559
				netdev_name(dsa_to_port(ds, i)->bridge_dev));
1560
			return -EOPNOTSUPP;
1561 1562 1563
		}
	} while (vlan.vid < vid_end);

1564
	return 0;
1565 1566
}

1567 1568
static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
					 bool vlan_filtering)
1569
{
V
Vivien Didelot 已提交
1570
	struct mv88e6xxx_chip *chip = ds->priv;
1571 1572
	u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
		MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
1573
	int err;
1574

1575
	if (!chip->info->max_vid)
1576 1577
		return -EOPNOTSUPP;

1578
	mv88e6xxx_reg_lock(chip);
1579
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1580
	mv88e6xxx_reg_unlock(chip);
1581

1582
	return err;
1583 1584
}

1585 1586
static int
mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1587
			    const struct switchdev_obj_port_vlan *vlan)
1588
{
V
Vivien Didelot 已提交
1589
	struct mv88e6xxx_chip *chip = ds->priv;
1590 1591
	int err;

1592
	if (!chip->info->max_vid)
1593 1594
		return -EOPNOTSUPP;

1595 1596 1597
	/* 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.
	 */
1598
	mv88e6xxx_reg_lock(chip);
1599 1600
	err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
					   vlan->vid_end);
1601
	mv88e6xxx_reg_unlock(chip);
1602

1603 1604 1605
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */
1606
	return err;
1607 1608
}

1609 1610 1611 1612 1613
static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
					const unsigned char *addr, u16 vid,
					u8 state)
{
	struct mv88e6xxx_atu_entry entry;
1614 1615
	struct mv88e6xxx_vtu_entry vlan;
	u16 fid;
1616 1617 1618
	int err;

	/* Null VLAN ID corresponds to the port private database */
1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636
	if (vid == 0) {
		err = mv88e6xxx_port_get_fid(chip, port, &fid);
		if (err)
			return err;
	} else {
		vlan.vid = vid - 1;
		vlan.valid = false;

		err = mv88e6xxx_vtu_getnext(chip, &vlan);
		if (err)
			return err;

		/* switchdev expects -EOPNOTSUPP to honor software VLANs */
		if (vlan.vid != vid || !vlan.valid)
			return -EOPNOTSUPP;

		fid = vlan.fid;
	}
1637

1638
	entry.state = 0;
1639 1640 1641
	ether_addr_copy(entry.mac, addr);
	eth_addr_dec(entry.mac);

1642
	err = mv88e6xxx_g1_atu_getnext(chip, fid, &entry);
1643 1644 1645 1646
	if (err)
		return err;

	/* Initialize a fresh ATU entry if it isn't found */
1647
	if (!entry.state || !ether_addr_equal(entry.mac, addr)) {
1648 1649 1650 1651 1652
		memset(&entry, 0, sizeof(entry));
		ether_addr_copy(entry.mac, addr);
	}

	/* Purge the ATU entry only if no port is using it anymore */
1653
	if (!state) {
1654 1655
		entry.portvec &= ~BIT(port);
		if (!entry.portvec)
1656
			entry.state = 0;
1657 1658 1659 1660 1661
	} else {
		entry.portvec |= BIT(port);
		entry.state = state;
	}

1662
	return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry);
1663 1664
}

1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753
static int mv88e6xxx_policy_apply(struct mv88e6xxx_chip *chip, int port,
				  const struct mv88e6xxx_policy *policy)
{
	enum mv88e6xxx_policy_mapping mapping = policy->mapping;
	enum mv88e6xxx_policy_action action = policy->action;
	const u8 *addr = policy->addr;
	u16 vid = policy->vid;
	u8 state;
	int err;
	int id;

	if (!chip->info->ops->port_set_policy)
		return -EOPNOTSUPP;

	switch (mapping) {
	case MV88E6XXX_POLICY_MAPPING_DA:
	case MV88E6XXX_POLICY_MAPPING_SA:
		if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
			state = 0; /* Dissociate the port and address */
		else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
			 is_multicast_ether_addr(addr))
			state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC_POLICY;
		else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
			 is_unicast_ether_addr(addr))
			state = MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC_POLICY;
		else
			return -EOPNOTSUPP;

		err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
						   state);
		if (err)
			return err;
		break;
	default:
		return -EOPNOTSUPP;
	}

	/* Skip the port's policy clearing if the mapping is still in use */
	if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
		idr_for_each_entry(&chip->policies, policy, id)
			if (policy->port == port &&
			    policy->mapping == mapping &&
			    policy->action != action)
				return 0;

	return chip->info->ops->port_set_policy(chip, port, mapping, action);
}

static int mv88e6xxx_policy_insert(struct mv88e6xxx_chip *chip, int port,
				   struct ethtool_rx_flow_spec *fs)
{
	struct ethhdr *mac_entry = &fs->h_u.ether_spec;
	struct ethhdr *mac_mask = &fs->m_u.ether_spec;
	enum mv88e6xxx_policy_mapping mapping;
	enum mv88e6xxx_policy_action action;
	struct mv88e6xxx_policy *policy;
	u16 vid = 0;
	u8 *addr;
	int err;
	int id;

	if (fs->location != RX_CLS_LOC_ANY)
		return -EINVAL;

	if (fs->ring_cookie == RX_CLS_FLOW_DISC)
		action = MV88E6XXX_POLICY_ACTION_DISCARD;
	else
		return -EOPNOTSUPP;

	switch (fs->flow_type & ~FLOW_EXT) {
	case ETHER_FLOW:
		if (!is_zero_ether_addr(mac_mask->h_dest) &&
		    is_zero_ether_addr(mac_mask->h_source)) {
			mapping = MV88E6XXX_POLICY_MAPPING_DA;
			addr = mac_entry->h_dest;
		} else if (is_zero_ether_addr(mac_mask->h_dest) &&
		    !is_zero_ether_addr(mac_mask->h_source)) {
			mapping = MV88E6XXX_POLICY_MAPPING_SA;
			addr = mac_entry->h_source;
		} else {
			/* Cannot support DA and SA mapping in the same rule */
			return -EOPNOTSUPP;
		}
		break;
	default:
		return -EOPNOTSUPP;
	}

	if ((fs->flow_type & FLOW_EXT) && fs->m_ext.vlan_tci) {
1754
		if (fs->m_ext.vlan_tci != htons(0xffff))
1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874
			return -EOPNOTSUPP;
		vid = be16_to_cpu(fs->h_ext.vlan_tci) & VLAN_VID_MASK;
	}

	idr_for_each_entry(&chip->policies, policy, id) {
		if (policy->port == port && policy->mapping == mapping &&
		    policy->action == action && policy->vid == vid &&
		    ether_addr_equal(policy->addr, addr))
			return -EEXIST;
	}

	policy = devm_kzalloc(chip->dev, sizeof(*policy), GFP_KERNEL);
	if (!policy)
		return -ENOMEM;

	fs->location = 0;
	err = idr_alloc_u32(&chip->policies, policy, &fs->location, 0xffffffff,
			    GFP_KERNEL);
	if (err) {
		devm_kfree(chip->dev, policy);
		return err;
	}

	memcpy(&policy->fs, fs, sizeof(*fs));
	ether_addr_copy(policy->addr, addr);
	policy->mapping = mapping;
	policy->action = action;
	policy->port = port;
	policy->vid = vid;

	err = mv88e6xxx_policy_apply(chip, port, policy);
	if (err) {
		idr_remove(&chip->policies, fs->location);
		devm_kfree(chip->dev, policy);
		return err;
	}

	return 0;
}

static int mv88e6xxx_get_rxnfc(struct dsa_switch *ds, int port,
			       struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
{
	struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
	struct mv88e6xxx_chip *chip = ds->priv;
	struct mv88e6xxx_policy *policy;
	int err;
	int id;

	mv88e6xxx_reg_lock(chip);

	switch (rxnfc->cmd) {
	case ETHTOOL_GRXCLSRLCNT:
		rxnfc->data = 0;
		rxnfc->data |= RX_CLS_LOC_SPECIAL;
		rxnfc->rule_cnt = 0;
		idr_for_each_entry(&chip->policies, policy, id)
			if (policy->port == port)
				rxnfc->rule_cnt++;
		err = 0;
		break;
	case ETHTOOL_GRXCLSRULE:
		err = -ENOENT;
		policy = idr_find(&chip->policies, fs->location);
		if (policy) {
			memcpy(fs, &policy->fs, sizeof(*fs));
			err = 0;
		}
		break;
	case ETHTOOL_GRXCLSRLALL:
		rxnfc->data = 0;
		rxnfc->rule_cnt = 0;
		idr_for_each_entry(&chip->policies, policy, id)
			if (policy->port == port)
				rule_locs[rxnfc->rule_cnt++] = id;
		err = 0;
		break;
	default:
		err = -EOPNOTSUPP;
		break;
	}

	mv88e6xxx_reg_unlock(chip);

	return err;
}

static int mv88e6xxx_set_rxnfc(struct dsa_switch *ds, int port,
			       struct ethtool_rxnfc *rxnfc)
{
	struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
	struct mv88e6xxx_chip *chip = ds->priv;
	struct mv88e6xxx_policy *policy;
	int err;

	mv88e6xxx_reg_lock(chip);

	switch (rxnfc->cmd) {
	case ETHTOOL_SRXCLSRLINS:
		err = mv88e6xxx_policy_insert(chip, port, fs);
		break;
	case ETHTOOL_SRXCLSRLDEL:
		err = -ENOENT;
		policy = idr_remove(&chip->policies, fs->location);
		if (policy) {
			policy->action = MV88E6XXX_POLICY_ACTION_NORMAL;
			err = mv88e6xxx_policy_apply(chip, port, policy);
			devm_kfree(chip->dev, policy);
		}
		break;
	default:
		err = -EOPNOTSUPP;
		break;
	}

	mv88e6xxx_reg_unlock(chip);

	return err;
}

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_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;
}

1898
static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port,
1899
				    u16 vid, u8 member, bool warn)
1900
{
1901
	const u8 non_member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1902
	struct mv88e6xxx_vtu_entry vlan;
1903
	int i, err;
1904

1905 1906
	if (!vid)
		return -EOPNOTSUPP;
1907

1908 1909
	vlan.vid = vid - 1;
	vlan.valid = false;
1910

1911
	err = mv88e6xxx_vtu_getnext(chip, &vlan);
1912 1913 1914
	if (err)
		return err;

1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943
	if (vlan.vid != vid || !vlan.valid) {
		memset(&vlan, 0, sizeof(vlan));

		err = mv88e6xxx_atu_new(chip, &vlan.fid);
		if (err)
			return err;

		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
			if (i == port)
				vlan.member[i] = member;
			else
				vlan.member[i] = non_member;

		vlan.vid = vid;
		vlan.valid = true;

		err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
		if (err)
			return err;

		err = mv88e6xxx_broadcast_setup(chip, vlan.vid);
		if (err)
			return err;
	} else if (vlan.member[port] != member) {
		vlan.member[port] = member;

		err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
		if (err)
			return err;
1944
	} else if (warn) {
1945 1946 1947 1948 1949
		dev_info(chip->dev, "p%d: already a member of VLAN %d\n",
			 port, vid);
	}

	return 0;
1950 1951
}

1952
static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1953
				    const struct switchdev_obj_port_vlan *vlan)
1954
{
V
Vivien Didelot 已提交
1955
	struct mv88e6xxx_chip *chip = ds->priv;
1956 1957
	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1958
	bool warn;
1959
	u8 member;
1960 1961
	u16 vid;

1962
	if (!chip->info->max_vid)
1963 1964
		return;

1965
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1966
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1967
	else if (untagged)
1968
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
1969
	else
1970
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
1971

1972 1973 1974 1975 1976
	/* net/dsa/slave.c will call dsa_port_vlan_add() for the affected port
	 * and then the CPU port. Do not warn for duplicates for the CPU port.
	 */
	warn = !dsa_is_cpu_port(ds, port) && !dsa_is_dsa_port(ds, port);

1977
	mv88e6xxx_reg_lock(chip);
1978

1979
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
1980
		if (mv88e6xxx_port_vlan_join(chip, port, vid, member, warn))
1981 1982
			dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
				vid, untagged ? 'u' : 't');
1983

1984
	if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1985 1986
		dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
			vlan->vid_end);
1987

1988
	mv88e6xxx_reg_unlock(chip);
1989 1990
}

1991 1992
static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,
				     int port, u16 vid)
1993
{
1994
	struct mv88e6xxx_vtu_entry vlan;
1995 1996
	int i, err;

1997 1998 1999 2000 2001 2002 2003
	if (!vid)
		return -EOPNOTSUPP;

	vlan.vid = vid - 1;
	vlan.valid = false;

	err = mv88e6xxx_vtu_getnext(chip, &vlan);
2004
	if (err)
2005
		return err;
2006

2007 2008 2009 2010 2011
	/* If the VLAN doesn't exist in hardware or the port isn't a member,
	 * tell switchdev that this VLAN is likely handled in software.
	 */
	if (vlan.vid != vid || !vlan.valid ||
	    vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
2012
		return -EOPNOTSUPP;
2013

2014
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
2015 2016

	/* keep the VLAN unless all ports are excluded */
2017
	vlan.valid = false;
2018
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
2019 2020
		if (vlan.member[i] !=
		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
2021
			vlan.valid = true;
2022 2023 2024 2025
			break;
		}
	}

2026
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
2027 2028 2029
	if (err)
		return err;

2030
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
2031 2032
}

2033 2034
static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
				   const struct switchdev_obj_port_vlan *vlan)
2035
{
V
Vivien Didelot 已提交
2036
	struct mv88e6xxx_chip *chip = ds->priv;
2037 2038 2039
	u16 pvid, vid;
	int err = 0;

2040
	if (!chip->info->max_vid)
2041 2042
		return -EOPNOTSUPP;

2043
	mv88e6xxx_reg_lock(chip);
2044

2045
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
2046 2047 2048
	if (err)
		goto unlock;

2049
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
2050
		err = mv88e6xxx_port_vlan_leave(chip, port, vid);
2051 2052 2053 2054
		if (err)
			goto unlock;

		if (vid == pvid) {
2055
			err = mv88e6xxx_port_set_pvid(chip, port, 0);
2056 2057 2058 2059 2060
			if (err)
				goto unlock;
		}
	}

2061
unlock:
2062
	mv88e6xxx_reg_unlock(chip);
2063 2064 2065 2066

	return err;
}

2067 2068
static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
				  const unsigned char *addr, u16 vid)
2069
{
V
Vivien Didelot 已提交
2070
	struct mv88e6xxx_chip *chip = ds->priv;
2071
	int err;
2072

2073
	mv88e6xxx_reg_lock(chip);
2074 2075
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
2076
	mv88e6xxx_reg_unlock(chip);
2077 2078

	return err;
2079 2080
}

2081
static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
2082
				  const unsigned char *addr, u16 vid)
2083
{
V
Vivien Didelot 已提交
2084
	struct mv88e6xxx_chip *chip = ds->priv;
2085
	int err;
2086

2087
	mv88e6xxx_reg_lock(chip);
2088
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid, 0);
2089
	mv88e6xxx_reg_unlock(chip);
2090

2091
	return err;
2092 2093
}

2094 2095
static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
				      u16 fid, u16 vid, int port,
2096
				      dsa_fdb_dump_cb_t *cb, void *data)
2097
{
2098
	struct mv88e6xxx_atu_entry addr;
2099
	bool is_static;
2100 2101
	int err;

2102
	addr.state = 0;
2103
	eth_broadcast_addr(addr.mac);
2104 2105

	do {
2106
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
2107
		if (err)
2108
			return err;
2109

2110
		if (!addr.state)
2111 2112
			break;

2113
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
2114 2115
			continue;

2116 2117
		if (!is_unicast_ether_addr(addr.mac))
			continue;
2118

2119 2120 2121
		is_static = (addr.state ==
			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
		err = cb(addr.mac, vid, is_static, data);
2122 2123
		if (err)
			return err;
2124 2125 2126 2127 2128
	} while (!is_broadcast_ether_addr(addr.mac));

	return err;
}

2129
static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2130
				  dsa_fdb_dump_cb_t *cb, void *data)
2131
{
2132
	struct mv88e6xxx_vtu_entry vlan;
2133
	u16 fid;
2134 2135
	int err;

2136
	/* Dump port's default Filtering Information Database (VLAN ID 0) */
2137
	err = mv88e6xxx_port_get_fid(chip, port, &fid);
2138
	if (err)
2139
		return err;
2140

2141
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
2142
	if (err)
2143
		return err;
2144

2145
	/* Dump VLANs' Filtering Information Databases */
2146 2147 2148
	vlan.vid = chip->info->max_vid;
	vlan.valid = false;

2149
	do {
2150
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
2151
		if (err)
2152
			return err;
2153 2154 2155 2156

		if (!vlan.valid)
			break;

2157
		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
2158
						 cb, data);
2159
		if (err)
2160
			return err;
2161
	} while (vlan.vid < chip->info->max_vid);
2162

2163 2164 2165 2166
	return err;
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2167
				   dsa_fdb_dump_cb_t *cb, void *data)
2168
{
V
Vivien Didelot 已提交
2169
	struct mv88e6xxx_chip *chip = ds->priv;
2170 2171
	int err;

2172
	mv88e6xxx_reg_lock(chip);
2173
	err = mv88e6xxx_port_db_dump(chip, port, cb, data);
2174
	mv88e6xxx_reg_unlock(chip);
2175

2176
	return err;
2177 2178
}

2179 2180
static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
				struct net_device *br)
2181
{
2182 2183 2184
	struct dsa_switch *ds = chip->ds;
	struct dsa_switch_tree *dst = ds->dst;
	struct dsa_port *dp;
2185
	int err;
2186

2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201
	list_for_each_entry(dp, &dst->ports, list) {
		if (dp->bridge_dev == br) {
			if (dp->ds == ds) {
				/* This is a local bridge group member,
				 * remap its Port VLAN Map.
				 */
				err = mv88e6xxx_port_vlan_map(chip, dp->index);
				if (err)
					return err;
			} else {
				/* This is an external bridge group member,
				 * remap its cross-chip Port VLAN Table entry.
				 */
				err = mv88e6xxx_pvt_map(chip, dp->ds->index,
							dp->index);
2202 2203 2204 2205 2206 2207
				if (err)
					return err;
			}
		}
	}

2208 2209 2210 2211 2212 2213 2214 2215 2216
	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;

2217
	mv88e6xxx_reg_lock(chip);
2218
	err = mv88e6xxx_bridge_map(chip, br);
2219
	mv88e6xxx_reg_unlock(chip);
2220

2221
	return err;
2222 2223
}

2224 2225
static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
					struct net_device *br)
2226
{
V
Vivien Didelot 已提交
2227
	struct mv88e6xxx_chip *chip = ds->priv;
2228

2229
	mv88e6xxx_reg_lock(chip);
2230 2231 2232
	if (mv88e6xxx_bridge_map(chip, br) ||
	    mv88e6xxx_port_vlan_map(chip, port))
		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
2233
	mv88e6xxx_reg_unlock(chip);
2234 2235
}

2236 2237
static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds,
					   int tree_index, int sw_index,
2238 2239 2240 2241 2242
					   int port, struct net_device *br)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

2243 2244 2245
	if (tree_index != ds->dst->index)
		return 0;

2246
	mv88e6xxx_reg_lock(chip);
2247
	err = mv88e6xxx_pvt_map(chip, sw_index, port);
2248
	mv88e6xxx_reg_unlock(chip);
2249 2250 2251 2252

	return err;
}

2253 2254
static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds,
					     int tree_index, int sw_index,
2255 2256 2257 2258
					     int port, struct net_device *br)
{
	struct mv88e6xxx_chip *chip = ds->priv;

2259 2260 2261
	if (tree_index != ds->dst->index)
		return;

2262
	mv88e6xxx_reg_lock(chip);
2263
	if (mv88e6xxx_pvt_map(chip, sw_index, port))
2264
		dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
2265
	mv88e6xxx_reg_unlock(chip);
2266 2267
}

2268 2269 2270 2271 2272 2273 2274 2275
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->reset)
		return chip->info->ops->reset(chip);

	return 0;
}

2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288
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);
	}
}

2289
static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2290
{
2291
	int i, err;
2292

2293
	/* Set all ports to the Disabled state */
2294
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2295
		err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
2296 2297
		if (err)
			return err;
2298 2299
	}

2300 2301 2302
	/* Wait for transmit queues to drain,
	 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
	 */
2303 2304
	usleep_range(2000, 4000);

2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315
	return 0;
}

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

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

2316
	mv88e6xxx_hardware_reset(chip);
2317

2318
	return mv88e6xxx_software_reset(chip);
2319 2320
}

2321
static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
2322 2323
				   enum mv88e6xxx_frame_mode frame,
				   enum mv88e6xxx_egress_mode egress, u16 etype)
2324 2325 2326
{
	int err;

2327 2328 2329 2330
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
2331 2332 2333
	if (err)
		return err;

2334 2335 2336 2337 2338 2339 2340 2341
	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;
2342 2343
}

2344
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2345
{
2346
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
2347
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2348
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2349
}
2350

2351 2352 2353
static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
2354
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2355
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2356
}
2357

2358 2359 2360 2361
static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port,
				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
2362 2363
				       MV88E6XXX_EGRESS_MODE_ETHERTYPE,
				       ETH_P_EDSA);
2364
}
2365

2366 2367 2368 2369
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);
2370

2371
	if (dsa_is_user_port(chip->ds, port))
2372
		return mv88e6xxx_set_port_mode_normal(chip, port);
2373

2374 2375 2376
	/* 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);
2377

2378 2379
	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
		return mv88e6xxx_set_port_mode_edsa(chip, port);
2380

2381
	return -EINVAL;
2382 2383
}

2384
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2385
{
2386
	bool message = dsa_is_dsa_port(chip->ds, port);
2387

2388
	return mv88e6xxx_port_set_message_port(chip, port, message);
2389
}
2390

2391
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2392
{
2393
	struct dsa_switch *ds = chip->ds;
2394
	bool flood;
2395

2396 2397 2398 2399 2400
	/* Upstream ports flood frames with unknown unicast or multicast DA */
	flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
	if (chip->info->ops->port_set_egress_floods)
		return chip->info->ops->port_set_egress_floods(chip, port,
							       flood, flood);
2401

2402
	return 0;
2403 2404
}

2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433
static irqreturn_t mv88e6xxx_serdes_irq_thread_fn(int irq, void *dev_id)
{
	struct mv88e6xxx_port *mvp = dev_id;
	struct mv88e6xxx_chip *chip = mvp->chip;
	irqreturn_t ret = IRQ_NONE;
	int port = mvp->port;
	u8 lane;

	mv88e6xxx_reg_lock(chip);
	lane = mv88e6xxx_serdes_get_lane(chip, port);
	if (lane)
		ret = mv88e6xxx_serdes_irq_status(chip, port, lane);
	mv88e6xxx_reg_unlock(chip);

	return ret;
}

static int mv88e6xxx_serdes_irq_request(struct mv88e6xxx_chip *chip, int port,
					u8 lane)
{
	struct mv88e6xxx_port *dev_id = &chip->ports[port];
	unsigned int irq;
	int err;

	/* Nothing to request if this SERDES port has no IRQ */
	irq = mv88e6xxx_serdes_irq_mapping(chip, port);
	if (!irq)
		return 0;

2434 2435 2436
	snprintf(dev_id->serdes_irq_name, sizeof(dev_id->serdes_irq_name),
		 "mv88e6xxx-%s-serdes-%d", dev_name(chip->dev), port);

2437 2438 2439
	/* Requesting the IRQ will trigger IRQ callbacks, so release the lock */
	mv88e6xxx_reg_unlock(chip);
	err = request_threaded_irq(irq, NULL, mv88e6xxx_serdes_irq_thread_fn,
2440 2441
				   IRQF_ONESHOT, dev_id->serdes_irq_name,
				   dev_id);
2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473
	mv88e6xxx_reg_lock(chip);
	if (err)
		return err;

	dev_id->serdes_irq = irq;

	return mv88e6xxx_serdes_irq_enable(chip, port, lane);
}

static int mv88e6xxx_serdes_irq_free(struct mv88e6xxx_chip *chip, int port,
				     u8 lane)
{
	struct mv88e6xxx_port *dev_id = &chip->ports[port];
	unsigned int irq = dev_id->serdes_irq;
	int err;

	/* Nothing to free if no IRQ has been requested */
	if (!irq)
		return 0;

	err = mv88e6xxx_serdes_irq_disable(chip, port, lane);

	/* Freeing the IRQ will trigger IRQ callbacks, so release the lock */
	mv88e6xxx_reg_unlock(chip);
	free_irq(irq, dev_id);
	mv88e6xxx_reg_lock(chip);

	dev_id->serdes_irq = 0;

	return err;
}

2474 2475 2476
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
2477
	u8 lane;
2478
	int err;
2479

2480 2481
	lane = mv88e6xxx_serdes_get_lane(chip, port);
	if (!lane)
2482 2483 2484
		return 0;

	if (on) {
2485
		err = mv88e6xxx_serdes_power_up(chip, port, lane);
2486 2487 2488
		if (err)
			return err;

2489
		err = mv88e6xxx_serdes_irq_request(chip, port, lane);
2490
	} else {
2491 2492 2493
		err = mv88e6xxx_serdes_irq_free(chip, port, lane);
		if (err)
			return err;
2494

2495
		err = mv88e6xxx_serdes_power_down(chip, port, lane);
2496 2497 2498
	}

	return err;
2499 2500
}

2501 2502 2503 2504 2505 2506
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

2507
	upstream_port = dsa_upstream_port(ds, port);
2508 2509 2510 2511 2512 2513 2514
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

2515 2516 2517 2518 2519 2520 2521 2522 2523 2524
	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,
2525 2526 2527 2528 2529 2530 2531 2532
						MV88E6XXX_EGRESS_DIR_INGRESS,
						upstream_port);
			if (err)
				return err;

			err = chip->info->ops->set_egress_port(chip,
						MV88E6XXX_EGRESS_DIR_EGRESS,
						upstream_port);
2533 2534 2535 2536 2537
			if (err)
				return err;
		}
	}

2538 2539 2540
	return 0;
}

2541
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
2542
{
2543
	struct dsa_switch *ds = chip->ds;
2544
	int err;
2545
	u16 reg;
2546

2547 2548 2549
	chip->ports[port].chip = chip;
	chip->ports[port].port = port;

2550 2551 2552 2553 2554 2555 2556
	/* 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,
2557
					       PAUSE_OFF,
2558 2559 2560 2561
					       PHY_INTERFACE_MODE_NA);
	else
		err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
					       SPEED_UNFORCED, DUPLEX_UNFORCED,
2562
					       PAUSE_ON,
2563 2564 2565
					       PHY_INTERFACE_MODE_NA);
	if (err)
		return err;
2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580

	/* 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.
	 */
2581 2582 2583 2584
	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);
2585 2586
	if (err)
		return err;
2587

2588
	err = mv88e6xxx_setup_port_mode(chip, port);
2589 2590
	if (err)
		return err;
2591

2592
	err = mv88e6xxx_setup_egress_floods(chip, port);
2593 2594 2595
	if (err)
		return err;

2596
	/* Port Control 2: don't force a good FCS, set the maximum frame size to
2597
	 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
2598 2599 2600
	 * 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.
2601
	 */
2602 2603 2604
	err = mv88e6xxx_port_set_map_da(chip, port);
	if (err)
		return err;
2605

2606 2607 2608
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
2609

2610
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
2611
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
2612 2613 2614
	if (err)
		return err;

2615 2616
	if (chip->info->ops->port_set_jumbo_size) {
		err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
2617 2618 2619 2620
		if (err)
			return err;
	}

2621 2622 2623 2624 2625
	/* 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.
	 */
2626
	reg = 1 << port;
2627 2628
	/* Disable learning for CPU port */
	if (dsa_is_cpu_port(ds, port))
2629
		reg = 0;
2630

2631 2632
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
2633 2634
	if (err)
		return err;
2635 2636

	/* Egress rate control 2: disable egress rate control. */
2637 2638
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
				   0x0000);
2639 2640
	if (err)
		return err;
2641

2642 2643
	if (chip->info->ops->port_pause_limit) {
		err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
2644 2645
		if (err)
			return err;
2646
	}
2647

2648 2649 2650 2651 2652 2653
	if (chip->info->ops->port_disable_learn_limit) {
		err = chip->info->ops->port_disable_learn_limit(chip, port);
		if (err)
			return err;
	}

2654 2655
	if (chip->info->ops->port_disable_pri_override) {
		err = chip->info->ops->port_disable_pri_override(chip, port);
2656 2657
		if (err)
			return err;
2658
	}
2659

2660 2661
	if (chip->info->ops->port_tag_remap) {
		err = chip->info->ops->port_tag_remap(chip, port);
2662 2663
		if (err)
			return err;
2664 2665
	}

2666 2667
	if (chip->info->ops->port_egress_rate_limiting) {
		err = chip->info->ops->port_egress_rate_limiting(chip, port);
2668 2669
		if (err)
			return err;
2670 2671
	}

2672 2673 2674 2675 2676
	if (chip->info->ops->port_setup_message_port) {
		err = chip->info->ops->port_setup_message_port(chip, port);
		if (err)
			return err;
	}
2677

2678
	/* Port based VLAN map: give each port the same default address
2679 2680
	 * database, and allow bidirectional communication between the
	 * CPU and DSA port(s), and the other ports.
2681
	 */
2682
	err = mv88e6xxx_port_set_fid(chip, port, 0);
2683 2684
	if (err)
		return err;
2685

2686
	err = mv88e6xxx_port_vlan_map(chip, port);
2687 2688
	if (err)
		return err;
2689 2690 2691 2692

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

2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720
static int mv88e6xxx_get_max_mtu(struct dsa_switch *ds, int port)
{
	struct mv88e6xxx_chip *chip = ds->priv;

	if (chip->info->ops->port_set_jumbo_size)
		return 10240;
	return 1522;
}

static int mv88e6xxx_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int ret = 0;

	mv88e6xxx_reg_lock(chip);
	if (chip->info->ops->port_set_jumbo_size)
		ret = chip->info->ops->port_set_jumbo_size(chip, port, new_mtu);
	else
		if (new_mtu > 1522)
			ret = -EINVAL;
	mv88e6xxx_reg_unlock(chip);

	return ret;
}

2721 2722 2723 2724
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
2725
	int err;
2726

2727
	mv88e6xxx_reg_lock(chip);
2728
	err = mv88e6xxx_serdes_power(chip, port, true);
2729
	mv88e6xxx_reg_unlock(chip);
2730 2731 2732 2733

	return err;
}

2734
static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port)
2735 2736 2737
{
	struct mv88e6xxx_chip *chip = ds->priv;

2738
	mv88e6xxx_reg_lock(chip);
2739 2740
	if (mv88e6xxx_serdes_power(chip, port, false))
		dev_err(chip->dev, "failed to power off SERDES\n");
2741
	mv88e6xxx_reg_unlock(chip);
2742 2743
}

2744 2745 2746
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
2747
	struct mv88e6xxx_chip *chip = ds->priv;
2748 2749
	int err;

2750
	mv88e6xxx_reg_lock(chip);
2751
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2752
	mv88e6xxx_reg_unlock(chip);
2753 2754 2755 2756

	return err;
}

2757
static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
2758
{
2759
	int err;
2760

2761
	/* Initialize the statistics unit */
2762 2763 2764 2765 2766
	if (chip->info->ops->stats_set_histogram) {
		err = chip->info->ops->stats_set_histogram(chip);
		if (err)
			return err;
	}
2767

2768
	return mv88e6xxx_g1_stats_clear(chip);
2769 2770
}

2771 2772 2773 2774 2775 2776 2777 2778
/* Check if the errata has already been applied. */
static bool mv88e6390_setup_errata_applied(struct mv88e6xxx_chip *chip)
{
	int port;
	int err;
	u16 val;

	for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
2779
		err = mv88e6xxx_port_hidden_read(chip, 0xf, port, 0, &val);
2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811
		if (err) {
			dev_err(chip->dev,
				"Error reading hidden register: %d\n", err);
			return false;
		}
		if (val != 0x01c0)
			return false;
	}

	return true;
}

/* The 6390 copper ports have an errata which require poking magic
 * values into undocumented hidden registers and then performing a
 * software reset.
 */
static int mv88e6390_setup_errata(struct mv88e6xxx_chip *chip)
{
	int port;
	int err;

	if (mv88e6390_setup_errata_applied(chip))
		return 0;

	/* Set the ports into blocking mode */
	for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
		err = mv88e6xxx_port_set_state(chip, port, BR_STATE_DISABLED);
		if (err)
			return err;
	}

	for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
2812
		err = mv88e6xxx_port_hidden_write(chip, 0xf, port, 0, 0x01c0);
2813 2814 2815 2816 2817 2818 2819
		if (err)
			return err;
	}

	return mv88e6xxx_software_reset(chip);
}

2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886
enum mv88e6xxx_devlink_param_id {
	MV88E6XXX_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,
	MV88E6XXX_DEVLINK_PARAM_ID_ATU_HASH,
};

static int mv88e6xxx_devlink_param_get(struct dsa_switch *ds, u32 id,
				       struct devlink_param_gset_ctx *ctx)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

	mv88e6xxx_reg_lock(chip);

	switch (id) {
	case MV88E6XXX_DEVLINK_PARAM_ID_ATU_HASH:
		err = mv88e6xxx_atu_get_hash(chip, &ctx->val.vu8);
		break;
	default:
		err = -EOPNOTSUPP;
		break;
	}

	mv88e6xxx_reg_unlock(chip);

	return err;
}

static int mv88e6xxx_devlink_param_set(struct dsa_switch *ds, u32 id,
				       struct devlink_param_gset_ctx *ctx)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

	mv88e6xxx_reg_lock(chip);

	switch (id) {
	case MV88E6XXX_DEVLINK_PARAM_ID_ATU_HASH:
		err = mv88e6xxx_atu_set_hash(chip, ctx->val.vu8);
		break;
	default:
		err = -EOPNOTSUPP;
		break;
	}

	mv88e6xxx_reg_unlock(chip);

	return err;
}

static const struct devlink_param mv88e6xxx_devlink_params[] = {
	DSA_DEVLINK_PARAM_DRIVER(MV88E6XXX_DEVLINK_PARAM_ID_ATU_HASH,
				 "ATU_hash", DEVLINK_PARAM_TYPE_U8,
				 BIT(DEVLINK_PARAM_CMODE_RUNTIME)),
};

static int mv88e6xxx_setup_devlink_params(struct dsa_switch *ds)
{
	return dsa_devlink_params_register(ds, mv88e6xxx_devlink_params,
					   ARRAY_SIZE(mv88e6xxx_devlink_params));
}

static void mv88e6xxx_teardown_devlink_params(struct dsa_switch *ds)
{
	dsa_devlink_params_unregister(ds, mv88e6xxx_devlink_params,
				      ARRAY_SIZE(mv88e6xxx_devlink_params));
}

2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921
enum mv88e6xxx_devlink_resource_id {
	MV88E6XXX_RESOURCE_ID_ATU,
	MV88E6XXX_RESOURCE_ID_ATU_BIN_0,
	MV88E6XXX_RESOURCE_ID_ATU_BIN_1,
	MV88E6XXX_RESOURCE_ID_ATU_BIN_2,
	MV88E6XXX_RESOURCE_ID_ATU_BIN_3,
};

static u64 mv88e6xxx_devlink_atu_bin_get(struct mv88e6xxx_chip *chip,
					 u16 bin)
{
	u16 occupancy = 0;
	int err;

	mv88e6xxx_reg_lock(chip);

	err = mv88e6xxx_g2_atu_stats_set(chip, MV88E6XXX_G2_ATU_STATS_MODE_ALL,
					 bin);
	if (err) {
		dev_err(chip->dev, "failed to set ATU stats kind/bin\n");
		goto unlock;
	}

	err = mv88e6xxx_g1_atu_get_next(chip, 0);
	if (err) {
		dev_err(chip->dev, "failed to perform ATU get next\n");
		goto unlock;
	}

	err = mv88e6xxx_g2_atu_stats_get(chip, &occupancy);
	if (err) {
		dev_err(chip->dev, "failed to get ATU stats\n");
		goto unlock;
	}

2922 2923
	occupancy &= MV88E6XXX_G2_ATU_STATS_MASK;

2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057
unlock:
	mv88e6xxx_reg_unlock(chip);

	return occupancy;
}

static u64 mv88e6xxx_devlink_atu_bin_0_get(void *priv)
{
	struct mv88e6xxx_chip *chip = priv;

	return mv88e6xxx_devlink_atu_bin_get(chip,
					     MV88E6XXX_G2_ATU_STATS_BIN_0);
}

static u64 mv88e6xxx_devlink_atu_bin_1_get(void *priv)
{
	struct mv88e6xxx_chip *chip = priv;

	return mv88e6xxx_devlink_atu_bin_get(chip,
					     MV88E6XXX_G2_ATU_STATS_BIN_1);
}

static u64 mv88e6xxx_devlink_atu_bin_2_get(void *priv)
{
	struct mv88e6xxx_chip *chip = priv;

	return mv88e6xxx_devlink_atu_bin_get(chip,
					     MV88E6XXX_G2_ATU_STATS_BIN_2);
}

static u64 mv88e6xxx_devlink_atu_bin_3_get(void *priv)
{
	struct mv88e6xxx_chip *chip = priv;

	return mv88e6xxx_devlink_atu_bin_get(chip,
					     MV88E6XXX_G2_ATU_STATS_BIN_3);
}

static u64 mv88e6xxx_devlink_atu_get(void *priv)
{
	return mv88e6xxx_devlink_atu_bin_0_get(priv) +
		mv88e6xxx_devlink_atu_bin_1_get(priv) +
		mv88e6xxx_devlink_atu_bin_2_get(priv) +
		mv88e6xxx_devlink_atu_bin_3_get(priv);
}

static int mv88e6xxx_setup_devlink_resources(struct dsa_switch *ds)
{
	struct devlink_resource_size_params size_params;
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

	devlink_resource_size_params_init(&size_params,
					  mv88e6xxx_num_macs(chip),
					  mv88e6xxx_num_macs(chip),
					  1, DEVLINK_RESOURCE_UNIT_ENTRY);

	err = dsa_devlink_resource_register(ds, "ATU",
					    mv88e6xxx_num_macs(chip),
					    MV88E6XXX_RESOURCE_ID_ATU,
					    DEVLINK_RESOURCE_ID_PARENT_TOP,
					    &size_params);
	if (err)
		goto out;

	devlink_resource_size_params_init(&size_params,
					  mv88e6xxx_num_macs(chip) / 4,
					  mv88e6xxx_num_macs(chip) / 4,
					  1, DEVLINK_RESOURCE_UNIT_ENTRY);

	err = dsa_devlink_resource_register(ds, "ATU_bin_0",
					    mv88e6xxx_num_macs(chip) / 4,
					    MV88E6XXX_RESOURCE_ID_ATU_BIN_0,
					    MV88E6XXX_RESOURCE_ID_ATU,
					    &size_params);
	if (err)
		goto out;

	err = dsa_devlink_resource_register(ds, "ATU_bin_1",
					    mv88e6xxx_num_macs(chip) / 4,
					    MV88E6XXX_RESOURCE_ID_ATU_BIN_1,
					    MV88E6XXX_RESOURCE_ID_ATU,
					    &size_params);
	if (err)
		goto out;

	err = dsa_devlink_resource_register(ds, "ATU_bin_2",
					    mv88e6xxx_num_macs(chip) / 4,
					    MV88E6XXX_RESOURCE_ID_ATU_BIN_2,
					    MV88E6XXX_RESOURCE_ID_ATU,
					    &size_params);
	if (err)
		goto out;

	err = dsa_devlink_resource_register(ds, "ATU_bin_3",
					    mv88e6xxx_num_macs(chip) / 4,
					    MV88E6XXX_RESOURCE_ID_ATU_BIN_3,
					    MV88E6XXX_RESOURCE_ID_ATU,
					    &size_params);
	if (err)
		goto out;

	dsa_devlink_resource_occ_get_register(ds,
					      MV88E6XXX_RESOURCE_ID_ATU,
					      mv88e6xxx_devlink_atu_get,
					      chip);

	dsa_devlink_resource_occ_get_register(ds,
					      MV88E6XXX_RESOURCE_ID_ATU_BIN_0,
					      mv88e6xxx_devlink_atu_bin_0_get,
					      chip);

	dsa_devlink_resource_occ_get_register(ds,
					      MV88E6XXX_RESOURCE_ID_ATU_BIN_1,
					      mv88e6xxx_devlink_atu_bin_1_get,
					      chip);

	dsa_devlink_resource_occ_get_register(ds,
					      MV88E6XXX_RESOURCE_ID_ATU_BIN_2,
					      mv88e6xxx_devlink_atu_bin_2_get,
					      chip);

	dsa_devlink_resource_occ_get_register(ds,
					      MV88E6XXX_RESOURCE_ID_ATU_BIN_3,
					      mv88e6xxx_devlink_atu_bin_3_get,
					      chip);

	return 0;

out:
	dsa_devlink_resources_unregister(ds);
	return err;
}

3058 3059 3060
static void mv88e6xxx_teardown(struct dsa_switch *ds)
{
	mv88e6xxx_teardown_devlink_params(ds);
3061
	dsa_devlink_resources_unregister(ds);
3062 3063
}

3064
static int mv88e6xxx_setup(struct dsa_switch *ds)
3065
{
V
Vivien Didelot 已提交
3066
	struct mv88e6xxx_chip *chip = ds->priv;
3067
	u8 cmode;
3068
	int err;
3069 3070
	int i;

3071
	chip->ds = ds;
3072
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
3073

3074
	mv88e6xxx_reg_lock(chip);
3075

3076 3077 3078 3079 3080 3081
	if (chip->info->ops->setup_errata) {
		err = chip->info->ops->setup_errata(chip);
		if (err)
			goto unlock;
	}

3082 3083 3084 3085 3086
	/* Cache the cmode of each port. */
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
		if (chip->info->ops->port_get_cmode) {
			err = chip->info->ops->port_get_cmode(chip, i, &cmode);
			if (err)
3087
				goto unlock;
3088 3089 3090 3091 3092

			chip->ports[i].cmode = cmode;
		}
	}

3093
	/* Setup Switch Port Registers */
3094
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
3095 3096 3097
		if (dsa_is_unused_port(ds, i))
			continue;

3098
		/* Prevent the use of an invalid port. */
3099
		if (mv88e6xxx_is_invalid_port(chip, i)) {
3100 3101 3102 3103 3104
			dev_err(chip->dev, "port %d is invalid\n", i);
			err = -EINVAL;
			goto unlock;
		}

3105 3106 3107 3108 3109
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

3110 3111 3112 3113
	err = mv88e6xxx_irl_setup(chip);
	if (err)
		goto unlock;

3114 3115 3116 3117
	err = mv88e6xxx_mac_setup(chip);
	if (err)
		goto unlock;

3118 3119 3120 3121
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

3122 3123 3124 3125
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

3126 3127 3128 3129
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

3130 3131 3132 3133
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

3134 3135 3136 3137
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

3138 3139 3140 3141
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

3142 3143 3144 3145
	err = mv88e6xxx_rmu_setup(chip);
	if (err)
		goto unlock;

3146 3147 3148
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
3149

3150 3151 3152 3153
	err = mv88e6xxx_trunk_setup(chip);
	if (err)
		goto unlock;

3154 3155 3156 3157
	err = mv88e6xxx_devmap_setup(chip);
	if (err)
		goto unlock;

3158 3159 3160 3161
	err = mv88e6xxx_pri_setup(chip);
	if (err)
		goto unlock;

3162
	/* Setup PTP Hardware Clock and timestamping */
3163 3164 3165 3166
	if (chip->info->ptp_support) {
		err = mv88e6xxx_ptp_setup(chip);
		if (err)
			goto unlock;
3167 3168 3169 3170

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
3171 3172
	}

3173 3174 3175 3176
	err = mv88e6xxx_stats_setup(chip);
	if (err)
		goto unlock;

3177
unlock:
3178
	mv88e6xxx_reg_unlock(chip);
3179

3180 3181 3182 3183 3184 3185 3186
	if (err)
		return err;

	/* Have to be called without holding the register lock, since
	 * they take the devlink lock, and we later take the locks in
	 * the reverse order when getting/setting parameters or
	 * resource occupancy.
3187
	 */
3188 3189 3190 3191 3192 3193 3194 3195 3196
	err = mv88e6xxx_setup_devlink_resources(ds);
	if (err)
		return err;

	err = mv88e6xxx_setup_devlink_params(ds);
	if (err)
		dsa_devlink_resources_unregister(ds);

	return err;
3197 3198
}

3199
static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
3200
{
3201 3202
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
3203 3204
	u16 val;
	int err;
3205

3206 3207 3208
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

3209
	mv88e6xxx_reg_lock(chip);
3210
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
3211
	mv88e6xxx_reg_unlock(chip);
3212

3213
	if (reg == MII_PHYSID2) {
3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229
		/* Some internal PHYs don't have a model number. */
		if (chip->info->family != MV88E6XXX_FAMILY_6165)
			/* Then there is the 6165 family. It gets is
			 * PHYs correct. But it can also have two
			 * SERDES interfaces in the PHY address
			 * space. And these don't have a model
			 * number. But they are not PHYs, so we don't
			 * want to give them something a PHY driver
			 * will recognise.
			 *
			 * Use the mv88e6390 family model number
			 * instead, for anything which really could be
			 * a PHY,
			 */
			if (!(val & 0x3f0))
				val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
3230 3231
	}

3232
	return err ? err : val;
3233 3234
}

3235
static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
3236
{
3237 3238
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
3239
	int err;
3240

3241 3242 3243
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

3244
	mv88e6xxx_reg_lock(chip);
3245
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
3246
	mv88e6xxx_reg_unlock(chip);
3247 3248

	return err;
3249 3250
}

3251
static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
3252 3253
				   struct device_node *np,
				   bool external)
3254 3255
{
	static int index;
3256
	struct mv88e6xxx_mdio_bus *mdio_bus;
3257 3258 3259
	struct mii_bus *bus;
	int err;

3260
	if (external) {
3261
		mv88e6xxx_reg_lock(chip);
3262
		err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
3263
		mv88e6xxx_reg_unlock(chip);
3264 3265 3266 3267 3268

		if (err)
			return err;
	}

3269
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
3270 3271 3272
	if (!bus)
		return -ENOMEM;

3273
	mdio_bus = bus->priv;
3274
	mdio_bus->bus = bus;
3275
	mdio_bus->chip = chip;
3276 3277
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
3278

3279 3280
	if (np) {
		bus->name = np->full_name;
3281
		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
3282 3283 3284 3285 3286 3287 3288
	} 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;
3289
	bus->parent = chip->dev;
3290

3291 3292 3293 3294 3295 3296
	if (!external) {
		err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
		if (err)
			return err;
	}

3297
	err = of_mdiobus_register(bus, np);
3298
	if (err) {
3299
		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
3300
		mv88e6xxx_g2_irq_mdio_free(chip, bus);
3301
		return err;
3302
	}
3303 3304 3305 3306 3307

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

	return 0;
3310
}
3311

3312 3313 3314 3315 3316
static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
	{ .compatible = "marvell,mv88e6xxx-mdio-external",
	  .data = (void *)true },
	{ },
};
3317

3318 3319 3320 3321 3322 3323 3324 3325 3326
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;

3327 3328 3329
		if (!mdio_bus->external)
			mv88e6xxx_g2_irq_mdio_free(chip, bus);

3330 3331 3332 3333
		mdiobus_unregister(bus);
	}
}

3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357
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);
3358 3359
			if (err) {
				mv88e6xxx_mdios_unregister(chip);
3360
				of_node_put(child);
3361
				return err;
3362
			}
3363 3364 3365 3366
		}
	}

	return 0;
3367 3368
}

3369 3370
static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
3371
	struct mv88e6xxx_chip *chip = ds->priv;
3372 3373 3374 3375 3376 3377 3378

	return chip->eeprom_len;
}

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

3382 3383
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
3384

3385
	mv88e6xxx_reg_lock(chip);
3386
	err = chip->info->ops->get_eeprom(chip, eeprom, data);
3387
	mv88e6xxx_reg_unlock(chip);
3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399

	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 已提交
3400
	struct mv88e6xxx_chip *chip = ds->priv;
3401 3402
	int err;

3403 3404 3405
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

3406 3407 3408
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

3409
	mv88e6xxx_reg_lock(chip);
3410
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
3411
	mv88e6xxx_reg_unlock(chip);
3412 3413 3414 3415

	return err;
}

3416
static const struct mv88e6xxx_ops mv88e6085_ops = {
3417
	/* MV88E6XXX_FAMILY_6097 */
3418 3419
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3420
	.irl_init_all = mv88e6352_g2_irl_init_all,
3421
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3422 3423
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3424
	.port_set_link = mv88e6xxx_port_set_link,
3425
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3426
	.port_tag_remap = mv88e6095_port_tag_remap,
3427
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3428
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3429
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3430
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3431
	.port_pause_limit = mv88e6097_port_pause_limit,
3432
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3433
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3434
	.port_get_cmode = mv88e6185_port_get_cmode,
3435
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3436
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3437
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3438 3439
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3440
	.stats_get_stats = mv88e6095_stats_get_stats,
3441 3442
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3443
	.watchdog_ops = &mv88e6097_watchdog_ops,
3444
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3445
	.pot_clear = mv88e6xxx_g2_pot_clear,
3446 3447
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
3448
	.reset = mv88e6185_g1_reset,
3449
	.rmu_disable = mv88e6085_g1_rmu_disable,
3450
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3451
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3452
	.phylink_validate = mv88e6185_phylink_validate,
3453 3454 3455
};

static const struct mv88e6xxx_ops mv88e6095_ops = {
3456
	/* MV88E6XXX_FAMILY_6095 */
3457 3458
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3459
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3460 3461
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3462
	.port_set_link = mv88e6xxx_port_set_link,
3463
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3464
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
3465
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
3466
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
3467
	.port_get_cmode = mv88e6185_port_get_cmode,
3468
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3469
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3470
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3471 3472
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3473
	.stats_get_stats = mv88e6095_stats_get_stats,
3474
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3475 3476
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
3477
	.reset = mv88e6185_g1_reset,
3478
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3479
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3480
	.phylink_validate = mv88e6185_phylink_validate,
3481 3482
};

3483
static const struct mv88e6xxx_ops mv88e6097_ops = {
3484
	/* MV88E6XXX_FAMILY_6097 */
3485 3486
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3487
	.irl_init_all = mv88e6352_g2_irl_init_all,
3488 3489 3490 3491
	.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,
3492
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3493
	.port_tag_remap = mv88e6095_port_tag_remap,
3494
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3495
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3496
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3497
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
3498
	.port_pause_limit = mv88e6097_port_pause_limit,
3499
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3500
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3501
	.port_get_cmode = mv88e6185_port_get_cmode,
3502
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3503
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3504
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3505 3506 3507
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
	.stats_get_stats = mv88e6095_stats_get_stats,
3508 3509
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3510
	.watchdog_ops = &mv88e6097_watchdog_ops,
3511
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3512
	.pot_clear = mv88e6xxx_g2_pot_clear,
3513
	.reset = mv88e6352_g1_reset,
3514
	.rmu_disable = mv88e6085_g1_rmu_disable,
3515
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3516
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3517
	.phylink_validate = mv88e6185_phylink_validate,
3518 3519
};

3520
static const struct mv88e6xxx_ops mv88e6123_ops = {
3521
	/* MV88E6XXX_FAMILY_6165 */
3522 3523
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3524
	.irl_init_all = mv88e6352_g2_irl_init_all,
3525
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3526 3527
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3528
	.port_set_link = mv88e6xxx_port_set_link,
3529
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3530
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
3531
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3532
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3533
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3534
	.port_get_cmode = mv88e6185_port_get_cmode,
3535
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3536
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3537
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3538 3539
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3540
	.stats_get_stats = mv88e6095_stats_get_stats,
3541 3542
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3543
	.watchdog_ops = &mv88e6097_watchdog_ops,
3544
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3545
	.pot_clear = mv88e6xxx_g2_pot_clear,
3546
	.reset = mv88e6352_g1_reset,
3547 3548
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3549
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3550
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3551
	.phylink_validate = mv88e6185_phylink_validate,
3552 3553 3554
};

static const struct mv88e6xxx_ops mv88e6131_ops = {
3555
	/* MV88E6XXX_FAMILY_6185 */
3556 3557
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3558
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3559 3560
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3561
	.port_set_link = mv88e6xxx_port_set_link,
3562
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3563
	.port_tag_remap = mv88e6095_port_tag_remap,
3564
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3565
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
3566
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3567
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
3568
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3569
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3570
	.port_pause_limit = mv88e6097_port_pause_limit,
3571
	.port_set_pause = mv88e6185_port_set_pause,
3572
	.port_get_cmode = mv88e6185_port_get_cmode,
3573
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3574
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3575
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3576 3577
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3578
	.stats_get_stats = mv88e6095_stats_get_stats,
3579 3580
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3581
	.watchdog_ops = &mv88e6097_watchdog_ops,
3582
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3583
	.ppu_enable = mv88e6185_g1_ppu_enable,
3584
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
3585
	.ppu_disable = mv88e6185_g1_ppu_disable,
3586
	.reset = mv88e6185_g1_reset,
3587
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3588
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3589
	.phylink_validate = mv88e6185_phylink_validate,
3590 3591
};

3592 3593
static const struct mv88e6xxx_ops mv88e6141_ops = {
	/* MV88E6XXX_FAMILY_6341 */
3594 3595
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3596
	.irl_init_all = mv88e6352_g2_irl_init_all,
3597 3598 3599 3600 3601 3602 3603
	.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_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3604
	.port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
3605
	.port_max_speed_mode = mv88e6341_port_max_speed_mode,
3606 3607 3608 3609
	.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,
3610
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3611
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3612
	.port_pause_limit = mv88e6097_port_pause_limit,
3613 3614
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3615
	.port_get_cmode = mv88e6352_port_get_cmode,
3616
	.port_set_cmode = mv88e6341_port_set_cmode,
3617
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3618
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3619
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3620 3621 3622
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
3623 3624
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3625 3626
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
3627
	.pot_clear = mv88e6xxx_g2_pot_clear,
3628
	.reset = mv88e6352_g1_reset,
3629
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3630
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3631 3632
	.serdes_power = mv88e6390_serdes_power,
	.serdes_get_lane = mv88e6341_serdes_get_lane,
3633 3634 3635 3636 3637
	/* Check status register pause & lpa register */
	.serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
	.serdes_pcs_config = mv88e6390_serdes_pcs_config,
	.serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
	.serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
3638
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3639
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
3640
	.serdes_irq_status = mv88e6390_serdes_irq_status,
3641
	.gpio_ops = &mv88e6352_gpio_ops,
3642
	.phylink_validate = mv88e6341_phylink_validate,
3643 3644
};

3645
static const struct mv88e6xxx_ops mv88e6161_ops = {
3646
	/* MV88E6XXX_FAMILY_6165 */
3647 3648
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3649
	.irl_init_all = mv88e6352_g2_irl_init_all,
3650
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3651 3652
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3653
	.port_set_link = mv88e6xxx_port_set_link,
3654
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3655
	.port_tag_remap = mv88e6095_port_tag_remap,
3656
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3657
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3658
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3659
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3660
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3661
	.port_pause_limit = mv88e6097_port_pause_limit,
3662
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3663
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3664
	.port_get_cmode = mv88e6185_port_get_cmode,
3665
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3666
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3667
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3668 3669
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3670
	.stats_get_stats = mv88e6095_stats_get_stats,
3671 3672
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3673
	.watchdog_ops = &mv88e6097_watchdog_ops,
3674
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3675
	.pot_clear = mv88e6xxx_g2_pot_clear,
3676
	.reset = mv88e6352_g1_reset,
3677 3678
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3679
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3680
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3681
	.avb_ops = &mv88e6165_avb_ops,
3682
	.ptp_ops = &mv88e6165_ptp_ops,
3683
	.phylink_validate = mv88e6185_phylink_validate,
3684 3685 3686
};

static const struct mv88e6xxx_ops mv88e6165_ops = {
3687
	/* MV88E6XXX_FAMILY_6165 */
3688 3689
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3690
	.irl_init_all = mv88e6352_g2_irl_init_all,
3691
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3692 3693
	.phy_read = mv88e6165_phy_read,
	.phy_write = mv88e6165_phy_write,
3694
	.port_set_link = mv88e6xxx_port_set_link,
3695
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3696
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3697
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3698
	.port_get_cmode = mv88e6185_port_get_cmode,
3699
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3700
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3701
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3702 3703
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3704
	.stats_get_stats = mv88e6095_stats_get_stats,
3705 3706
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3707
	.watchdog_ops = &mv88e6097_watchdog_ops,
3708
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3709
	.pot_clear = mv88e6xxx_g2_pot_clear,
3710
	.reset = mv88e6352_g1_reset,
3711 3712
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3713
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3714
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3715
	.avb_ops = &mv88e6165_avb_ops,
3716
	.ptp_ops = &mv88e6165_ptp_ops,
3717
	.phylink_validate = mv88e6185_phylink_validate,
3718 3719 3720
};

static const struct mv88e6xxx_ops mv88e6171_ops = {
3721
	/* MV88E6XXX_FAMILY_6351 */
3722 3723
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3724
	.irl_init_all = mv88e6352_g2_irl_init_all,
3725
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3726 3727
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3728
	.port_set_link = mv88e6xxx_port_set_link,
3729
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3730
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3731
	.port_tag_remap = mv88e6095_port_tag_remap,
3732
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3733
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3734
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3735
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3736
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3737
	.port_pause_limit = mv88e6097_port_pause_limit,
3738
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3739
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3740
	.port_get_cmode = mv88e6352_port_get_cmode,
3741
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3742
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3743
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3744 3745
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3746
	.stats_get_stats = mv88e6095_stats_get_stats,
3747 3748
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3749
	.watchdog_ops = &mv88e6097_watchdog_ops,
3750
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3751
	.pot_clear = mv88e6xxx_g2_pot_clear,
3752
	.reset = mv88e6352_g1_reset,
3753 3754
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3755
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3756
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3757
	.phylink_validate = mv88e6185_phylink_validate,
3758 3759 3760
};

static const struct mv88e6xxx_ops mv88e6172_ops = {
3761
	/* MV88E6XXX_FAMILY_6352 */
3762 3763
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3764
	.irl_init_all = mv88e6352_g2_irl_init_all,
3765 3766
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3767
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3768 3769
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3770
	.port_set_link = mv88e6xxx_port_set_link,
3771
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3772
	.port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
3773
	.port_tag_remap = mv88e6095_port_tag_remap,
3774
	.port_set_policy = mv88e6352_port_set_policy,
3775
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3776
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3777
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3778
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3779
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3780
	.port_pause_limit = mv88e6097_port_pause_limit,
3781
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3782
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3783
	.port_get_cmode = mv88e6352_port_get_cmode,
3784
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3785
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3786
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3787 3788
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3789
	.stats_get_stats = mv88e6095_stats_get_stats,
3790 3791
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3792
	.watchdog_ops = &mv88e6097_watchdog_ops,
3793
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3794
	.pot_clear = mv88e6xxx_g2_pot_clear,
3795
	.reset = mv88e6352_g1_reset,
3796
	.rmu_disable = mv88e6352_g1_rmu_disable,
3797 3798
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3799
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3800
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3801
	.serdes_get_lane = mv88e6352_serdes_get_lane,
3802 3803 3804 3805
	.serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
	.serdes_pcs_config = mv88e6352_serdes_pcs_config,
	.serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
	.serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
3806
	.serdes_power = mv88e6352_serdes_power,
3807 3808
	.serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
	.serdes_get_regs = mv88e6352_serdes_get_regs,
3809
	.gpio_ops = &mv88e6352_gpio_ops,
3810
	.phylink_validate = mv88e6352_phylink_validate,
3811 3812 3813
};

static const struct mv88e6xxx_ops mv88e6175_ops = {
3814
	/* MV88E6XXX_FAMILY_6351 */
3815 3816
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3817
	.irl_init_all = mv88e6352_g2_irl_init_all,
3818
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3819 3820
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3821
	.port_set_link = mv88e6xxx_port_set_link,
3822
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3823
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3824
	.port_tag_remap = mv88e6095_port_tag_remap,
3825
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3826
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3827
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3828
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3829
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3830
	.port_pause_limit = mv88e6097_port_pause_limit,
3831
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3832
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3833
	.port_get_cmode = mv88e6352_port_get_cmode,
3834
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3835
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3836
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3837 3838
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3839
	.stats_get_stats = mv88e6095_stats_get_stats,
3840 3841
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3842
	.watchdog_ops = &mv88e6097_watchdog_ops,
3843
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3844
	.pot_clear = mv88e6xxx_g2_pot_clear,
3845
	.reset = mv88e6352_g1_reset,
3846 3847
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3848
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3849
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3850
	.phylink_validate = mv88e6185_phylink_validate,
3851 3852 3853
};

static const struct mv88e6xxx_ops mv88e6176_ops = {
3854
	/* MV88E6XXX_FAMILY_6352 */
3855 3856
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3857
	.irl_init_all = mv88e6352_g2_irl_init_all,
3858 3859
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3860
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3861 3862
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3863
	.port_set_link = mv88e6xxx_port_set_link,
3864
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3865
	.port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
3866
	.port_tag_remap = mv88e6095_port_tag_remap,
3867
	.port_set_policy = mv88e6352_port_set_policy,
3868
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3869
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3870
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3871
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3872
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3873
	.port_pause_limit = mv88e6097_port_pause_limit,
3874
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3875
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3876
	.port_get_cmode = mv88e6352_port_get_cmode,
3877
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3878
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3879
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3880 3881
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3882
	.stats_get_stats = mv88e6095_stats_get_stats,
3883 3884
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3885
	.watchdog_ops = &mv88e6097_watchdog_ops,
3886
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3887
	.pot_clear = mv88e6xxx_g2_pot_clear,
3888
	.reset = mv88e6352_g1_reset,
3889
	.rmu_disable = mv88e6352_g1_rmu_disable,
3890 3891
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3892
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3893
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3894
	.serdes_get_lane = mv88e6352_serdes_get_lane,
3895 3896 3897 3898
	.serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
	.serdes_pcs_config = mv88e6352_serdes_pcs_config,
	.serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
	.serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
3899
	.serdes_power = mv88e6352_serdes_power,
3900
	.serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
3901
	.serdes_irq_enable = mv88e6352_serdes_irq_enable,
3902
	.serdes_irq_status = mv88e6352_serdes_irq_status,
3903 3904
	.serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
	.serdes_get_regs = mv88e6352_serdes_get_regs,
3905
	.gpio_ops = &mv88e6352_gpio_ops,
3906
	.phylink_validate = mv88e6352_phylink_validate,
3907 3908 3909
};

static const struct mv88e6xxx_ops mv88e6185_ops = {
3910
	/* MV88E6XXX_FAMILY_6185 */
3911 3912
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3913
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3914 3915
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3916
	.port_set_link = mv88e6xxx_port_set_link,
3917
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3918
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
3919
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
3920
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
3921
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
3922
	.port_set_pause = mv88e6185_port_set_pause,
3923
	.port_get_cmode = mv88e6185_port_get_cmode,
3924
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3925
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3926
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3927 3928
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3929
	.stats_get_stats = mv88e6095_stats_get_stats,
3930 3931
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3932
	.watchdog_ops = &mv88e6097_watchdog_ops,
3933
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3934
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
3935 3936
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
3937
	.reset = mv88e6185_g1_reset,
3938
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3939
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3940
	.phylink_validate = mv88e6185_phylink_validate,
3941 3942
};

3943
static const struct mv88e6xxx_ops mv88e6190_ops = {
3944
	/* MV88E6XXX_FAMILY_6390 */
3945
	.setup_errata = mv88e6390_setup_errata,
3946
	.irl_init_all = mv88e6390_g2_irl_init_all,
3947 3948
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3949 3950 3951 3952 3953
	.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_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3954
	.port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
3955
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
3956
	.port_tag_remap = mv88e6390_port_tag_remap,
3957
	.port_set_policy = mv88e6352_port_set_policy,
3958
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3959
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3960
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3961
	.port_pause_limit = mv88e6390_port_pause_limit,
3962
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3963
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3964
	.port_get_cmode = mv88e6352_port_get_cmode,
3965
	.port_set_cmode = mv88e6390_port_set_cmode,
3966
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3967
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3968
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3969 3970
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3971
	.stats_get_stats = mv88e6390_stats_get_stats,
3972 3973
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3974
	.watchdog_ops = &mv88e6390_watchdog_ops,
3975
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3976
	.pot_clear = mv88e6xxx_g2_pot_clear,
3977
	.reset = mv88e6352_g1_reset,
3978
	.rmu_disable = mv88e6390_g1_rmu_disable,
3979 3980
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3981 3982
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3983
	.serdes_power = mv88e6390_serdes_power,
3984
	.serdes_get_lane = mv88e6390_serdes_get_lane,
3985 3986 3987 3988 3989
	/* Check status register pause & lpa register */
	.serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
	.serdes_pcs_config = mv88e6390_serdes_pcs_config,
	.serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
	.serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
3990
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3991
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
3992
	.serdes_irq_status = mv88e6390_serdes_irq_status,
3993 3994
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
3995 3996
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
3997
	.gpio_ops = &mv88e6352_gpio_ops,
3998
	.phylink_validate = mv88e6390_phylink_validate,
3999 4000 4001
};

static const struct mv88e6xxx_ops mv88e6190x_ops = {
4002
	/* MV88E6XXX_FAMILY_6390 */
4003
	.setup_errata = mv88e6390_setup_errata,
4004
	.irl_init_all = mv88e6390_g2_irl_init_all,
4005 4006
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4007 4008 4009 4010 4011
	.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_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4012
	.port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
4013
	.port_max_speed_mode = mv88e6390x_port_max_speed_mode,
4014
	.port_tag_remap = mv88e6390_port_tag_remap,
4015
	.port_set_policy = mv88e6352_port_set_policy,
4016
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4017
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4018
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4019
	.port_pause_limit = mv88e6390_port_pause_limit,
4020
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4021
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4022
	.port_get_cmode = mv88e6352_port_get_cmode,
4023
	.port_set_cmode = mv88e6390x_port_set_cmode,
4024
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4025
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4026
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4027 4028
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4029
	.stats_get_stats = mv88e6390_stats_get_stats,
4030 4031
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4032
	.watchdog_ops = &mv88e6390_watchdog_ops,
4033
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4034
	.pot_clear = mv88e6xxx_g2_pot_clear,
4035
	.reset = mv88e6352_g1_reset,
4036
	.rmu_disable = mv88e6390_g1_rmu_disable,
4037 4038
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4039 4040
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4041
	.serdes_power = mv88e6390_serdes_power,
4042
	.serdes_get_lane = mv88e6390x_serdes_get_lane,
4043 4044 4045 4046 4047
	/* Check status register pause & lpa register */
	.serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
	.serdes_pcs_config = mv88e6390_serdes_pcs_config,
	.serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
	.serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
4048
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4049
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4050
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4051 4052
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
4053 4054
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
4055
	.gpio_ops = &mv88e6352_gpio_ops,
4056
	.phylink_validate = mv88e6390x_phylink_validate,
4057 4058 4059
};

static const struct mv88e6xxx_ops mv88e6191_ops = {
4060
	/* MV88E6XXX_FAMILY_6390 */
4061
	.setup_errata = mv88e6390_setup_errata,
4062
	.irl_init_all = mv88e6390_g2_irl_init_all,
4063 4064
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4065 4066 4067 4068 4069
	.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_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4070
	.port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
4071
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
4072
	.port_tag_remap = mv88e6390_port_tag_remap,
4073
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4074
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4075
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4076
	.port_pause_limit = mv88e6390_port_pause_limit,
4077
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4078
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4079
	.port_get_cmode = mv88e6352_port_get_cmode,
4080
	.port_set_cmode = mv88e6390_port_set_cmode,
4081
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4082
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4083
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4084 4085
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4086
	.stats_get_stats = mv88e6390_stats_get_stats,
4087 4088
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4089
	.watchdog_ops = &mv88e6390_watchdog_ops,
4090
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4091
	.pot_clear = mv88e6xxx_g2_pot_clear,
4092
	.reset = mv88e6352_g1_reset,
4093
	.rmu_disable = mv88e6390_g1_rmu_disable,
4094 4095
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4096 4097
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4098
	.serdes_power = mv88e6390_serdes_power,
4099
	.serdes_get_lane = mv88e6390_serdes_get_lane,
4100 4101 4102 4103 4104
	/* Check status register pause & lpa register */
	.serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
	.serdes_pcs_config = mv88e6390_serdes_pcs_config,
	.serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
	.serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
4105
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4106
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4107
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4108 4109
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
4110 4111
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
4112 4113
	.avb_ops = &mv88e6390_avb_ops,
	.ptp_ops = &mv88e6352_ptp_ops,
4114
	.phylink_validate = mv88e6390_phylink_validate,
4115 4116
};

4117
static const struct mv88e6xxx_ops mv88e6240_ops = {
4118
	/* MV88E6XXX_FAMILY_6352 */
4119 4120
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4121
	.irl_init_all = mv88e6352_g2_irl_init_all,
4122 4123
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
4124
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4125 4126
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4127
	.port_set_link = mv88e6xxx_port_set_link,
4128
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4129
	.port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
4130
	.port_tag_remap = mv88e6095_port_tag_remap,
4131
	.port_set_policy = mv88e6352_port_set_policy,
4132
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4133
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4134
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4135
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4136
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4137
	.port_pause_limit = mv88e6097_port_pause_limit,
4138
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4139
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4140
	.port_get_cmode = mv88e6352_port_get_cmode,
4141
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4142
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4143
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4144 4145
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
4146
	.stats_get_stats = mv88e6095_stats_get_stats,
4147 4148
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4149
	.watchdog_ops = &mv88e6097_watchdog_ops,
4150
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4151
	.pot_clear = mv88e6xxx_g2_pot_clear,
4152
	.reset = mv88e6352_g1_reset,
4153
	.rmu_disable = mv88e6352_g1_rmu_disable,
4154 4155
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4156
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4157
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4158
	.serdes_get_lane = mv88e6352_serdes_get_lane,
4159 4160 4161 4162
	.serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
	.serdes_pcs_config = mv88e6352_serdes_pcs_config,
	.serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
	.serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
4163
	.serdes_power = mv88e6352_serdes_power,
4164
	.serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
4165
	.serdes_irq_enable = mv88e6352_serdes_irq_enable,
4166
	.serdes_irq_status = mv88e6352_serdes_irq_status,
4167 4168
	.serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
	.serdes_get_regs = mv88e6352_serdes_get_regs,
4169
	.gpio_ops = &mv88e6352_gpio_ops,
4170
	.avb_ops = &mv88e6352_avb_ops,
4171
	.ptp_ops = &mv88e6352_ptp_ops,
4172
	.phylink_validate = mv88e6352_phylink_validate,
4173 4174
};

4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186
static const struct mv88e6xxx_ops mv88e6250_ops = {
	/* MV88E6XXX_FAMILY_6250 */
	.ieee_pri_map = mv88e6250_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
	.irl_init_all = mv88e6352_g2_irl_init_all,
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
	.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_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4187
	.port_set_speed_duplex = mv88e6250_port_set_speed_duplex,
4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207
	.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,
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
	.port_pause_limit = mv88e6097_port_pause_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
	.stats_get_sset_count = mv88e6250_stats_get_sset_count,
	.stats_get_strings = mv88e6250_stats_get_strings,
	.stats_get_stats = mv88e6250_stats_get_stats,
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
	.watchdog_ops = &mv88e6250_watchdog_ops,
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
	.pot_clear = mv88e6xxx_g2_pot_clear,
	.reset = mv88e6250_g1_reset,
	.vtu_getnext = mv88e6250_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6250_g1_vtu_loadpurge,
4208 4209
	.avb_ops = &mv88e6352_avb_ops,
	.ptp_ops = &mv88e6250_ptp_ops,
4210 4211 4212
	.phylink_validate = mv88e6065_phylink_validate,
};

4213
static const struct mv88e6xxx_ops mv88e6290_ops = {
4214
	/* MV88E6XXX_FAMILY_6390 */
4215
	.setup_errata = mv88e6390_setup_errata,
4216
	.irl_init_all = mv88e6390_g2_irl_init_all,
4217 4218
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4219 4220 4221 4222 4223
	.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_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4224
	.port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
4225
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
4226
	.port_tag_remap = mv88e6390_port_tag_remap,
4227
	.port_set_policy = mv88e6352_port_set_policy,
4228
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4229
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4230
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4231
	.port_pause_limit = mv88e6390_port_pause_limit,
4232
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4233
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4234
	.port_get_cmode = mv88e6352_port_get_cmode,
4235
	.port_set_cmode = mv88e6390_port_set_cmode,
4236
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4237
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4238
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4239 4240
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4241
	.stats_get_stats = mv88e6390_stats_get_stats,
4242 4243
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4244
	.watchdog_ops = &mv88e6390_watchdog_ops,
4245
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4246
	.pot_clear = mv88e6xxx_g2_pot_clear,
4247
	.reset = mv88e6352_g1_reset,
4248
	.rmu_disable = mv88e6390_g1_rmu_disable,
4249 4250
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4251 4252
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4253
	.serdes_power = mv88e6390_serdes_power,
4254
	.serdes_get_lane = mv88e6390_serdes_get_lane,
4255 4256 4257 4258 4259
	/* Check status register pause & lpa register */
	.serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
	.serdes_pcs_config = mv88e6390_serdes_pcs_config,
	.serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
	.serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
4260
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4261
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4262
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4263 4264
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
4265 4266
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
4267
	.gpio_ops = &mv88e6352_gpio_ops,
4268
	.avb_ops = &mv88e6390_avb_ops,
4269
	.ptp_ops = &mv88e6352_ptp_ops,
4270
	.phylink_validate = mv88e6390_phylink_validate,
4271 4272
};

4273
static const struct mv88e6xxx_ops mv88e6320_ops = {
4274
	/* MV88E6XXX_FAMILY_6320 */
4275 4276
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4277
	.irl_init_all = mv88e6352_g2_irl_init_all,
4278 4279
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
4280
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4281 4282
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4283
	.port_set_link = mv88e6xxx_port_set_link,
4284
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4285
	.port_tag_remap = mv88e6095_port_tag_remap,
4286
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4287
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4288
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4289
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4290
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4291
	.port_pause_limit = mv88e6097_port_pause_limit,
4292
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4293
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4294
	.port_get_cmode = mv88e6352_port_get_cmode,
4295
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4296
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4297
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4298 4299
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4300
	.stats_get_stats = mv88e6320_stats_get_stats,
4301 4302
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4303
	.watchdog_ops = &mv88e6390_watchdog_ops,
4304
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4305
	.pot_clear = mv88e6xxx_g2_pot_clear,
4306
	.reset = mv88e6352_g1_reset,
4307
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
4308
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
4309
	.gpio_ops = &mv88e6352_gpio_ops,
4310
	.avb_ops = &mv88e6352_avb_ops,
4311
	.ptp_ops = &mv88e6352_ptp_ops,
4312
	.phylink_validate = mv88e6185_phylink_validate,
4313 4314 4315
};

static const struct mv88e6xxx_ops mv88e6321_ops = {
4316
	/* MV88E6XXX_FAMILY_6320 */
4317 4318
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4319
	.irl_init_all = mv88e6352_g2_irl_init_all,
4320 4321
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
4322
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4323 4324
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4325
	.port_set_link = mv88e6xxx_port_set_link,
4326
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4327
	.port_tag_remap = mv88e6095_port_tag_remap,
4328
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4329
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4330
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4331
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4332
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4333
	.port_pause_limit = mv88e6097_port_pause_limit,
4334
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4335
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4336
	.port_get_cmode = mv88e6352_port_get_cmode,
4337
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4338
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4339
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4340 4341
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4342
	.stats_get_stats = mv88e6320_stats_get_stats,
4343 4344
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4345
	.watchdog_ops = &mv88e6390_watchdog_ops,
4346
	.reset = mv88e6352_g1_reset,
4347
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
4348
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
4349
	.gpio_ops = &mv88e6352_gpio_ops,
4350
	.avb_ops = &mv88e6352_avb_ops,
4351
	.ptp_ops = &mv88e6352_ptp_ops,
4352
	.phylink_validate = mv88e6185_phylink_validate,
4353 4354
};

4355 4356
static const struct mv88e6xxx_ops mv88e6341_ops = {
	/* MV88E6XXX_FAMILY_6341 */
4357 4358
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4359
	.irl_init_all = mv88e6352_g2_irl_init_all,
4360 4361 4362 4363 4364 4365 4366
	.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_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4367
	.port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
4368
	.port_max_speed_mode = mv88e6341_port_max_speed_mode,
4369 4370 4371 4372
	.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,
4373
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4374
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4375
	.port_pause_limit = mv88e6097_port_pause_limit,
4376 4377
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4378
	.port_get_cmode = mv88e6352_port_get_cmode,
4379
	.port_set_cmode = mv88e6341_port_set_cmode,
4380
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4381
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4382
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4383 4384 4385
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
4386 4387
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4388 4389
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
4390
	.pot_clear = mv88e6xxx_g2_pot_clear,
4391
	.reset = mv88e6352_g1_reset,
4392
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4393
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4394 4395
	.serdes_power = mv88e6390_serdes_power,
	.serdes_get_lane = mv88e6341_serdes_get_lane,
4396 4397 4398 4399 4400
	/* Check status register pause & lpa register */
	.serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
	.serdes_pcs_config = mv88e6390_serdes_pcs_config,
	.serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
	.serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
4401
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4402
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4403
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4404
	.gpio_ops = &mv88e6352_gpio_ops,
4405
	.avb_ops = &mv88e6390_avb_ops,
4406
	.ptp_ops = &mv88e6352_ptp_ops,
4407
	.phylink_validate = mv88e6341_phylink_validate,
4408 4409
};

4410
static const struct mv88e6xxx_ops mv88e6350_ops = {
4411
	/* MV88E6XXX_FAMILY_6351 */
4412 4413
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4414
	.irl_init_all = mv88e6352_g2_irl_init_all,
4415
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4416 4417
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4418
	.port_set_link = mv88e6xxx_port_set_link,
4419
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4420
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4421
	.port_tag_remap = mv88e6095_port_tag_remap,
4422
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4423
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4424
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4425
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4426
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4427
	.port_pause_limit = mv88e6097_port_pause_limit,
4428
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4429
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4430
	.port_get_cmode = mv88e6352_port_get_cmode,
4431
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4432
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4433
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4434 4435
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
4436
	.stats_get_stats = mv88e6095_stats_get_stats,
4437 4438
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4439
	.watchdog_ops = &mv88e6097_watchdog_ops,
4440
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4441
	.pot_clear = mv88e6xxx_g2_pot_clear,
4442
	.reset = mv88e6352_g1_reset,
4443 4444
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4445
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4446
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4447
	.phylink_validate = mv88e6185_phylink_validate,
4448 4449 4450
};

static const struct mv88e6xxx_ops mv88e6351_ops = {
4451
	/* MV88E6XXX_FAMILY_6351 */
4452 4453
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4454
	.irl_init_all = mv88e6352_g2_irl_init_all,
4455
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4456 4457
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4458
	.port_set_link = mv88e6xxx_port_set_link,
4459
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4460
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4461
	.port_tag_remap = mv88e6095_port_tag_remap,
4462
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4463
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4464
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4465
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4466
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4467
	.port_pause_limit = mv88e6097_port_pause_limit,
4468
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4469
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4470
	.port_get_cmode = mv88e6352_port_get_cmode,
4471
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4472
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4473
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4474 4475
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
4476
	.stats_get_stats = mv88e6095_stats_get_stats,
4477 4478
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4479
	.watchdog_ops = &mv88e6097_watchdog_ops,
4480
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4481
	.pot_clear = mv88e6xxx_g2_pot_clear,
4482
	.reset = mv88e6352_g1_reset,
4483 4484
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4485
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4486
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4487
	.avb_ops = &mv88e6352_avb_ops,
4488
	.ptp_ops = &mv88e6352_ptp_ops,
4489
	.phylink_validate = mv88e6185_phylink_validate,
4490 4491 4492
};

static const struct mv88e6xxx_ops mv88e6352_ops = {
4493
	/* MV88E6XXX_FAMILY_6352 */
4494 4495
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4496
	.irl_init_all = mv88e6352_g2_irl_init_all,
4497 4498
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
4499
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4500 4501
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4502
	.port_set_link = mv88e6xxx_port_set_link,
4503
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4504
	.port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
4505
	.port_tag_remap = mv88e6095_port_tag_remap,
4506
	.port_set_policy = mv88e6352_port_set_policy,
4507
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4508
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4509
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4510
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4511
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4512
	.port_pause_limit = mv88e6097_port_pause_limit,
4513
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4514
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4515
	.port_get_cmode = mv88e6352_port_get_cmode,
4516
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4517
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4518
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4519 4520
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
4521
	.stats_get_stats = mv88e6095_stats_get_stats,
4522 4523
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4524
	.watchdog_ops = &mv88e6097_watchdog_ops,
4525
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4526
	.pot_clear = mv88e6xxx_g2_pot_clear,
4527
	.reset = mv88e6352_g1_reset,
4528
	.rmu_disable = mv88e6352_g1_rmu_disable,
4529 4530
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4531
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4532
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4533
	.serdes_get_lane = mv88e6352_serdes_get_lane,
4534 4535 4536 4537
	.serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
	.serdes_pcs_config = mv88e6352_serdes_pcs_config,
	.serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
	.serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
4538
	.serdes_power = mv88e6352_serdes_power,
4539
	.serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
4540
	.serdes_irq_enable = mv88e6352_serdes_irq_enable,
4541
	.serdes_irq_status = mv88e6352_serdes_irq_status,
4542
	.gpio_ops = &mv88e6352_gpio_ops,
4543
	.avb_ops = &mv88e6352_avb_ops,
4544
	.ptp_ops = &mv88e6352_ptp_ops,
4545 4546 4547
	.serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
	.serdes_get_strings = mv88e6352_serdes_get_strings,
	.serdes_get_stats = mv88e6352_serdes_get_stats,
4548 4549
	.serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
	.serdes_get_regs = mv88e6352_serdes_get_regs,
4550
	.phylink_validate = mv88e6352_phylink_validate,
4551 4552
};

4553
static const struct mv88e6xxx_ops mv88e6390_ops = {
4554
	/* MV88E6XXX_FAMILY_6390 */
4555
	.setup_errata = mv88e6390_setup_errata,
4556
	.irl_init_all = mv88e6390_g2_irl_init_all,
4557 4558
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4559 4560 4561 4562 4563
	.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_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4564
	.port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
4565
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
4566
	.port_tag_remap = mv88e6390_port_tag_remap,
4567
	.port_set_policy = mv88e6352_port_set_policy,
4568
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4569
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4570
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4571
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4572
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4573
	.port_pause_limit = mv88e6390_port_pause_limit,
4574
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4575
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4576
	.port_get_cmode = mv88e6352_port_get_cmode,
4577
	.port_set_cmode = mv88e6390_port_set_cmode,
4578
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4579
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4580
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4581 4582
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4583
	.stats_get_stats = mv88e6390_stats_get_stats,
4584 4585
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4586
	.watchdog_ops = &mv88e6390_watchdog_ops,
4587
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4588
	.pot_clear = mv88e6xxx_g2_pot_clear,
4589
	.reset = mv88e6352_g1_reset,
4590
	.rmu_disable = mv88e6390_g1_rmu_disable,
4591 4592
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4593 4594
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4595
	.serdes_power = mv88e6390_serdes_power,
4596
	.serdes_get_lane = mv88e6390_serdes_get_lane,
4597 4598 4599 4600 4601
	/* Check status register pause & lpa register */
	.serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
	.serdes_pcs_config = mv88e6390_serdes_pcs_config,
	.serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
	.serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
4602
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4603
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4604
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4605
	.gpio_ops = &mv88e6352_gpio_ops,
4606
	.avb_ops = &mv88e6390_avb_ops,
4607
	.ptp_ops = &mv88e6352_ptp_ops,
4608 4609 4610
	.serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
4611 4612
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
4613
	.phylink_validate = mv88e6390_phylink_validate,
4614 4615 4616
};

static const struct mv88e6xxx_ops mv88e6390x_ops = {
4617
	/* MV88E6XXX_FAMILY_6390 */
4618
	.setup_errata = mv88e6390_setup_errata,
4619
	.irl_init_all = mv88e6390_g2_irl_init_all,
4620 4621
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4622 4623 4624 4625 4626
	.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_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4627
	.port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
4628
	.port_max_speed_mode = mv88e6390x_port_max_speed_mode,
4629
	.port_tag_remap = mv88e6390_port_tag_remap,
4630
	.port_set_policy = mv88e6352_port_set_policy,
4631
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4632
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4633
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4634
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4635
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4636
	.port_pause_limit = mv88e6390_port_pause_limit,
4637
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4638
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4639
	.port_get_cmode = mv88e6352_port_get_cmode,
4640
	.port_set_cmode = mv88e6390x_port_set_cmode,
4641
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4642
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4643
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4644 4645
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4646
	.stats_get_stats = mv88e6390_stats_get_stats,
4647 4648
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4649
	.watchdog_ops = &mv88e6390_watchdog_ops,
4650
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4651
	.pot_clear = mv88e6xxx_g2_pot_clear,
4652
	.reset = mv88e6352_g1_reset,
4653
	.rmu_disable = mv88e6390_g1_rmu_disable,
4654 4655
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4656 4657
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4658
	.serdes_power = mv88e6390_serdes_power,
4659
	.serdes_get_lane = mv88e6390x_serdes_get_lane,
4660 4661 4662 4663
	.serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
	.serdes_pcs_config = mv88e6390_serdes_pcs_config,
	.serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
	.serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
4664
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4665
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4666
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4667 4668 4669
	.serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
4670 4671
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
4672
	.gpio_ops = &mv88e6352_gpio_ops,
4673
	.avb_ops = &mv88e6390_avb_ops,
4674
	.ptp_ops = &mv88e6352_ptp_ops,
4675
	.phylink_validate = mv88e6390x_phylink_validate,
4676 4677
};

4678 4679
static const struct mv88e6xxx_info mv88e6xxx_table[] = {
	[MV88E6085] = {
4680
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
4681 4682 4683
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6085",
		.num_databases = 4096,
4684
		.num_macs = 8192,
4685
		.num_ports = 10,
4686
		.num_internal_phys = 5,
4687
		.max_vid = 4095,
4688
		.port_base_addr = 0x10,
4689
		.phy_base_addr = 0x0,
4690
		.global1_addr = 0x1b,
4691
		.global2_addr = 0x1c,
4692
		.age_time_coeff = 15000,
4693
		.g1_irqs = 8,
4694
		.g2_irqs = 10,
4695
		.atu_move_port_mask = 0xf,
4696
		.pvt = true,
4697
		.multi_chip = true,
4698
		.tag_protocol = DSA_TAG_PROTO_DSA,
4699
		.ops = &mv88e6085_ops,
4700 4701 4702
	},

	[MV88E6095] = {
4703
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
4704 4705 4706
		.family = MV88E6XXX_FAMILY_6095,
		.name = "Marvell 88E6095/88E6095F",
		.num_databases = 256,
4707
		.num_macs = 8192,
4708
		.num_ports = 11,
4709
		.num_internal_phys = 0,
4710
		.max_vid = 4095,
4711
		.port_base_addr = 0x10,
4712
		.phy_base_addr = 0x0,
4713
		.global1_addr = 0x1b,
4714
		.global2_addr = 0x1c,
4715
		.age_time_coeff = 15000,
4716
		.g1_irqs = 8,
4717
		.atu_move_port_mask = 0xf,
4718
		.multi_chip = true,
4719
		.tag_protocol = DSA_TAG_PROTO_DSA,
4720
		.ops = &mv88e6095_ops,
4721 4722
	},

4723
	[MV88E6097] = {
4724
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
4725 4726 4727
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6097/88E6097F",
		.num_databases = 4096,
4728
		.num_macs = 8192,
4729
		.num_ports = 11,
4730
		.num_internal_phys = 8,
4731
		.max_vid = 4095,
4732
		.port_base_addr = 0x10,
4733
		.phy_base_addr = 0x0,
4734
		.global1_addr = 0x1b,
4735
		.global2_addr = 0x1c,
4736
		.age_time_coeff = 15000,
4737
		.g1_irqs = 8,
4738
		.g2_irqs = 10,
4739
		.atu_move_port_mask = 0xf,
4740
		.pvt = true,
4741
		.multi_chip = true,
4742
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4743 4744 4745
		.ops = &mv88e6097_ops,
	},

4746
	[MV88E6123] = {
4747
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
4748 4749 4750
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6123",
		.num_databases = 4096,
4751
		.num_macs = 1024,
4752
		.num_ports = 3,
4753
		.num_internal_phys = 5,
4754
		.max_vid = 4095,
4755
		.port_base_addr = 0x10,
4756
		.phy_base_addr = 0x0,
4757
		.global1_addr = 0x1b,
4758
		.global2_addr = 0x1c,
4759
		.age_time_coeff = 15000,
4760
		.g1_irqs = 9,
4761
		.g2_irqs = 10,
4762
		.atu_move_port_mask = 0xf,
4763
		.pvt = true,
4764
		.multi_chip = true,
4765
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4766
		.ops = &mv88e6123_ops,
4767 4768 4769
	},

	[MV88E6131] = {
4770
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
4771 4772 4773
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6131",
		.num_databases = 256,
4774
		.num_macs = 8192,
4775
		.num_ports = 8,
4776
		.num_internal_phys = 0,
4777
		.max_vid = 4095,
4778
		.port_base_addr = 0x10,
4779
		.phy_base_addr = 0x0,
4780
		.global1_addr = 0x1b,
4781
		.global2_addr = 0x1c,
4782
		.age_time_coeff = 15000,
4783
		.g1_irqs = 9,
4784
		.atu_move_port_mask = 0xf,
4785
		.multi_chip = true,
4786
		.tag_protocol = DSA_TAG_PROTO_DSA,
4787
		.ops = &mv88e6131_ops,
4788 4789
	},

4790
	[MV88E6141] = {
4791
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
4792
		.family = MV88E6XXX_FAMILY_6341,
4793
		.name = "Marvell 88E6141",
4794
		.num_databases = 4096,
4795
		.num_macs = 2048,
4796
		.num_ports = 6,
4797
		.num_internal_phys = 5,
4798
		.num_gpio = 11,
4799
		.max_vid = 4095,
4800
		.port_base_addr = 0x10,
4801
		.phy_base_addr = 0x10,
4802
		.global1_addr = 0x1b,
4803
		.global2_addr = 0x1c,
4804 4805
		.age_time_coeff = 3750,
		.atu_move_port_mask = 0x1f,
4806
		.g1_irqs = 9,
4807
		.g2_irqs = 10,
4808
		.pvt = true,
4809
		.multi_chip = true,
4810 4811 4812 4813
		.tag_protocol = DSA_TAG_PROTO_EDSA,
		.ops = &mv88e6141_ops,
	},

4814
	[MV88E6161] = {
4815
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
4816 4817 4818
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6161",
		.num_databases = 4096,
4819
		.num_macs = 1024,
4820
		.num_ports = 6,
4821
		.num_internal_phys = 5,
4822
		.max_vid = 4095,
4823
		.port_base_addr = 0x10,
4824
		.phy_base_addr = 0x0,
4825
		.global1_addr = 0x1b,
4826
		.global2_addr = 0x1c,
4827
		.age_time_coeff = 15000,
4828
		.g1_irqs = 9,
4829
		.g2_irqs = 10,
4830
		.atu_move_port_mask = 0xf,
4831
		.pvt = true,
4832
		.multi_chip = true,
4833
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4834
		.ptp_support = true,
4835
		.ops = &mv88e6161_ops,
4836 4837 4838
	},

	[MV88E6165] = {
4839
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
4840 4841 4842
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6165",
		.num_databases = 4096,
4843
		.num_macs = 8192,
4844
		.num_ports = 6,
4845
		.num_internal_phys = 0,
4846
		.max_vid = 4095,
4847
		.port_base_addr = 0x10,
4848
		.phy_base_addr = 0x0,
4849
		.global1_addr = 0x1b,
4850
		.global2_addr = 0x1c,
4851
		.age_time_coeff = 15000,
4852
		.g1_irqs = 9,
4853
		.g2_irqs = 10,
4854
		.atu_move_port_mask = 0xf,
4855
		.pvt = true,
4856
		.multi_chip = true,
4857
		.tag_protocol = DSA_TAG_PROTO_DSA,
4858
		.ptp_support = true,
4859
		.ops = &mv88e6165_ops,
4860 4861 4862
	},

	[MV88E6171] = {
4863
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
4864 4865 4866
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6171",
		.num_databases = 4096,
4867
		.num_macs = 8192,
4868
		.num_ports = 7,
4869
		.num_internal_phys = 5,
4870
		.max_vid = 4095,
4871
		.port_base_addr = 0x10,
4872
		.phy_base_addr = 0x0,
4873
		.global1_addr = 0x1b,
4874
		.global2_addr = 0x1c,
4875
		.age_time_coeff = 15000,
4876
		.g1_irqs = 9,
4877
		.g2_irqs = 10,
4878
		.atu_move_port_mask = 0xf,
4879
		.pvt = true,
4880
		.multi_chip = true,
4881
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4882
		.ops = &mv88e6171_ops,
4883 4884 4885
	},

	[MV88E6172] = {
4886
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
4887 4888 4889
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6172",
		.num_databases = 4096,
4890
		.num_macs = 8192,
4891
		.num_ports = 7,
4892
		.num_internal_phys = 5,
4893
		.num_gpio = 15,
4894
		.max_vid = 4095,
4895
		.port_base_addr = 0x10,
4896
		.phy_base_addr = 0x0,
4897
		.global1_addr = 0x1b,
4898
		.global2_addr = 0x1c,
4899
		.age_time_coeff = 15000,
4900
		.g1_irqs = 9,
4901
		.g2_irqs = 10,
4902
		.atu_move_port_mask = 0xf,
4903
		.pvt = true,
4904
		.multi_chip = true,
4905
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4906
		.ops = &mv88e6172_ops,
4907 4908 4909
	},

	[MV88E6175] = {
4910
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
4911 4912 4913
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6175",
		.num_databases = 4096,
4914
		.num_macs = 8192,
4915
		.num_ports = 7,
4916
		.num_internal_phys = 5,
4917
		.max_vid = 4095,
4918
		.port_base_addr = 0x10,
4919
		.phy_base_addr = 0x0,
4920
		.global1_addr = 0x1b,
4921
		.global2_addr = 0x1c,
4922
		.age_time_coeff = 15000,
4923
		.g1_irqs = 9,
4924
		.g2_irqs = 10,
4925
		.atu_move_port_mask = 0xf,
4926
		.pvt = true,
4927
		.multi_chip = true,
4928
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4929
		.ops = &mv88e6175_ops,
4930 4931 4932
	},

	[MV88E6176] = {
4933
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
4934 4935 4936
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6176",
		.num_databases = 4096,
4937
		.num_macs = 8192,
4938
		.num_ports = 7,
4939
		.num_internal_phys = 5,
4940
		.num_gpio = 15,
4941
		.max_vid = 4095,
4942
		.port_base_addr = 0x10,
4943
		.phy_base_addr = 0x0,
4944
		.global1_addr = 0x1b,
4945
		.global2_addr = 0x1c,
4946
		.age_time_coeff = 15000,
4947
		.g1_irqs = 9,
4948
		.g2_irqs = 10,
4949
		.atu_move_port_mask = 0xf,
4950
		.pvt = true,
4951
		.multi_chip = true,
4952
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4953
		.ops = &mv88e6176_ops,
4954 4955 4956
	},

	[MV88E6185] = {
4957
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
4958 4959 4960
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6185",
		.num_databases = 256,
4961
		.num_macs = 8192,
4962
		.num_ports = 10,
4963
		.num_internal_phys = 0,
4964
		.max_vid = 4095,
4965
		.port_base_addr = 0x10,
4966
		.phy_base_addr = 0x0,
4967
		.global1_addr = 0x1b,
4968
		.global2_addr = 0x1c,
4969
		.age_time_coeff = 15000,
4970
		.g1_irqs = 8,
4971
		.atu_move_port_mask = 0xf,
4972
		.multi_chip = true,
4973
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4974
		.ops = &mv88e6185_ops,
4975 4976
	},

4977
	[MV88E6190] = {
4978
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
4979 4980 4981
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190",
		.num_databases = 4096,
4982
		.num_macs = 16384,
4983
		.num_ports = 11,	/* 10 + Z80 */
4984
		.num_internal_phys = 9,
4985
		.num_gpio = 16,
4986
		.max_vid = 8191,
4987
		.port_base_addr = 0x0,
4988
		.phy_base_addr = 0x0,
4989
		.global1_addr = 0x1b,
4990
		.global2_addr = 0x1c,
4991
		.tag_protocol = DSA_TAG_PROTO_DSA,
4992
		.age_time_coeff = 3750,
4993
		.g1_irqs = 9,
4994
		.g2_irqs = 14,
4995
		.pvt = true,
4996
		.multi_chip = true,
4997
		.atu_move_port_mask = 0x1f,
4998 4999 5000 5001
		.ops = &mv88e6190_ops,
	},

	[MV88E6190X] = {
5002
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
5003 5004 5005
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190X",
		.num_databases = 4096,
5006
		.num_macs = 16384,
5007
		.num_ports = 11,	/* 10 + Z80 */
5008
		.num_internal_phys = 9,
5009
		.num_gpio = 16,
5010
		.max_vid = 8191,
5011
		.port_base_addr = 0x0,
5012
		.phy_base_addr = 0x0,
5013
		.global1_addr = 0x1b,
5014
		.global2_addr = 0x1c,
5015
		.age_time_coeff = 3750,
5016
		.g1_irqs = 9,
5017
		.g2_irqs = 14,
5018
		.atu_move_port_mask = 0x1f,
5019
		.pvt = true,
5020
		.multi_chip = true,
5021
		.tag_protocol = DSA_TAG_PROTO_DSA,
5022 5023 5024 5025
		.ops = &mv88e6190x_ops,
	},

	[MV88E6191] = {
5026
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
5027 5028 5029
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6191",
		.num_databases = 4096,
5030
		.num_macs = 16384,
5031
		.num_ports = 11,	/* 10 + Z80 */
5032
		.num_internal_phys = 9,
5033
		.max_vid = 8191,
5034
		.port_base_addr = 0x0,
5035
		.phy_base_addr = 0x0,
5036
		.global1_addr = 0x1b,
5037
		.global2_addr = 0x1c,
5038
		.age_time_coeff = 3750,
5039
		.g1_irqs = 9,
5040
		.g2_irqs = 14,
5041
		.atu_move_port_mask = 0x1f,
5042
		.pvt = true,
5043
		.multi_chip = true,
5044
		.tag_protocol = DSA_TAG_PROTO_DSA,
5045
		.ptp_support = true,
5046
		.ops = &mv88e6191_ops,
5047 5048
	},

5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059
	[MV88E6220] = {
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6220,
		.family = MV88E6XXX_FAMILY_6250,
		.name = "Marvell 88E6220",
		.num_databases = 64,

		/* Ports 2-4 are not routed to pins
		 * => usable ports 0, 1, 5, 6
		 */
		.num_ports = 7,
		.num_internal_phys = 2,
5060
		.invalid_port_mask = BIT(2) | BIT(3) | BIT(4),
5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071
		.max_vid = 4095,
		.port_base_addr = 0x08,
		.phy_base_addr = 0x00,
		.global1_addr = 0x0f,
		.global2_addr = 0x07,
		.age_time_coeff = 15000,
		.g1_irqs = 9,
		.g2_irqs = 10,
		.atu_move_port_mask = 0xf,
		.dual_chip = true,
		.tag_protocol = DSA_TAG_PROTO_DSA,
5072
		.ptp_support = true,
5073 5074 5075
		.ops = &mv88e6250_ops,
	},

5076
	[MV88E6240] = {
5077
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
5078 5079 5080
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6240",
		.num_databases = 4096,
5081
		.num_macs = 8192,
5082
		.num_ports = 7,
5083
		.num_internal_phys = 5,
5084
		.num_gpio = 15,
5085
		.max_vid = 4095,
5086
		.port_base_addr = 0x10,
5087
		.phy_base_addr = 0x0,
5088
		.global1_addr = 0x1b,
5089
		.global2_addr = 0x1c,
5090
		.age_time_coeff = 15000,
5091
		.g1_irqs = 9,
5092
		.g2_irqs = 10,
5093
		.atu_move_port_mask = 0xf,
5094
		.pvt = true,
5095
		.multi_chip = true,
5096
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5097
		.ptp_support = true,
5098
		.ops = &mv88e6240_ops,
5099 5100
	},

5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118
	[MV88E6250] = {
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6250,
		.family = MV88E6XXX_FAMILY_6250,
		.name = "Marvell 88E6250",
		.num_databases = 64,
		.num_ports = 7,
		.num_internal_phys = 5,
		.max_vid = 4095,
		.port_base_addr = 0x08,
		.phy_base_addr = 0x00,
		.global1_addr = 0x0f,
		.global2_addr = 0x07,
		.age_time_coeff = 15000,
		.g1_irqs = 9,
		.g2_irqs = 10,
		.atu_move_port_mask = 0xf,
		.dual_chip = true,
		.tag_protocol = DSA_TAG_PROTO_DSA,
5119
		.ptp_support = true,
5120 5121 5122
		.ops = &mv88e6250_ops,
	},

5123
	[MV88E6290] = {
5124
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
5125 5126 5127 5128
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6290",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
5129
		.num_internal_phys = 9,
5130
		.num_gpio = 16,
5131
		.max_vid = 8191,
5132
		.port_base_addr = 0x0,
5133
		.phy_base_addr = 0x0,
5134
		.global1_addr = 0x1b,
5135
		.global2_addr = 0x1c,
5136
		.age_time_coeff = 3750,
5137
		.g1_irqs = 9,
5138
		.g2_irqs = 14,
5139
		.atu_move_port_mask = 0x1f,
5140
		.pvt = true,
5141
		.multi_chip = true,
5142
		.tag_protocol = DSA_TAG_PROTO_DSA,
5143
		.ptp_support = true,
5144 5145 5146
		.ops = &mv88e6290_ops,
	},

5147
	[MV88E6320] = {
5148
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
5149 5150 5151
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6320",
		.num_databases = 4096,
5152
		.num_macs = 8192,
5153
		.num_ports = 7,
5154
		.num_internal_phys = 5,
5155
		.num_gpio = 15,
5156
		.max_vid = 4095,
5157
		.port_base_addr = 0x10,
5158
		.phy_base_addr = 0x0,
5159
		.global1_addr = 0x1b,
5160
		.global2_addr = 0x1c,
5161
		.age_time_coeff = 15000,
5162
		.g1_irqs = 8,
5163
		.g2_irqs = 10,
5164
		.atu_move_port_mask = 0xf,
5165
		.pvt = true,
5166
		.multi_chip = true,
5167
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5168
		.ptp_support = true,
5169
		.ops = &mv88e6320_ops,
5170 5171 5172
	},

	[MV88E6321] = {
5173
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
5174 5175 5176
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6321",
		.num_databases = 4096,
5177
		.num_macs = 8192,
5178
		.num_ports = 7,
5179
		.num_internal_phys = 5,
5180
		.num_gpio = 15,
5181
		.max_vid = 4095,
5182
		.port_base_addr = 0x10,
5183
		.phy_base_addr = 0x0,
5184
		.global1_addr = 0x1b,
5185
		.global2_addr = 0x1c,
5186
		.age_time_coeff = 15000,
5187
		.g1_irqs = 8,
5188
		.g2_irqs = 10,
5189
		.atu_move_port_mask = 0xf,
5190
		.multi_chip = true,
5191
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5192
		.ptp_support = true,
5193
		.ops = &mv88e6321_ops,
5194 5195
	},

5196
	[MV88E6341] = {
5197
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
5198 5199 5200
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
5201
		.num_macs = 2048,
5202
		.num_internal_phys = 5,
5203
		.num_ports = 6,
5204
		.num_gpio = 11,
5205
		.max_vid = 4095,
5206
		.port_base_addr = 0x10,
5207
		.phy_base_addr = 0x10,
5208
		.global1_addr = 0x1b,
5209
		.global2_addr = 0x1c,
5210
		.age_time_coeff = 3750,
5211
		.atu_move_port_mask = 0x1f,
5212
		.g1_irqs = 9,
5213
		.g2_irqs = 10,
5214
		.pvt = true,
5215
		.multi_chip = true,
5216
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5217
		.ptp_support = true,
5218 5219 5220
		.ops = &mv88e6341_ops,
	},

5221
	[MV88E6350] = {
5222
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
5223 5224 5225
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6350",
		.num_databases = 4096,
5226
		.num_macs = 8192,
5227
		.num_ports = 7,
5228
		.num_internal_phys = 5,
5229
		.max_vid = 4095,
5230
		.port_base_addr = 0x10,
5231
		.phy_base_addr = 0x0,
5232
		.global1_addr = 0x1b,
5233
		.global2_addr = 0x1c,
5234
		.age_time_coeff = 15000,
5235
		.g1_irqs = 9,
5236
		.g2_irqs = 10,
5237
		.atu_move_port_mask = 0xf,
5238
		.pvt = true,
5239
		.multi_chip = true,
5240
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5241
		.ops = &mv88e6350_ops,
5242 5243 5244
	},

	[MV88E6351] = {
5245
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
5246 5247 5248
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6351",
		.num_databases = 4096,
5249
		.num_macs = 8192,
5250
		.num_ports = 7,
5251
		.num_internal_phys = 5,
5252
		.max_vid = 4095,
5253
		.port_base_addr = 0x10,
5254
		.phy_base_addr = 0x0,
5255
		.global1_addr = 0x1b,
5256
		.global2_addr = 0x1c,
5257
		.age_time_coeff = 15000,
5258
		.g1_irqs = 9,
5259
		.g2_irqs = 10,
5260
		.atu_move_port_mask = 0xf,
5261
		.pvt = true,
5262
		.multi_chip = true,
5263
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5264
		.ops = &mv88e6351_ops,
5265 5266 5267
	},

	[MV88E6352] = {
5268
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
5269 5270 5271
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6352",
		.num_databases = 4096,
5272
		.num_macs = 8192,
5273
		.num_ports = 7,
5274
		.num_internal_phys = 5,
5275
		.num_gpio = 15,
5276
		.max_vid = 4095,
5277
		.port_base_addr = 0x10,
5278
		.phy_base_addr = 0x0,
5279
		.global1_addr = 0x1b,
5280
		.global2_addr = 0x1c,
5281
		.age_time_coeff = 15000,
5282
		.g1_irqs = 9,
5283
		.g2_irqs = 10,
5284
		.atu_move_port_mask = 0xf,
5285
		.pvt = true,
5286
		.multi_chip = true,
5287
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5288
		.ptp_support = true,
5289
		.ops = &mv88e6352_ops,
5290
	},
5291
	[MV88E6390] = {
5292
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
5293 5294 5295
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390",
		.num_databases = 4096,
5296
		.num_macs = 16384,
5297
		.num_ports = 11,	/* 10 + Z80 */
5298
		.num_internal_phys = 9,
5299
		.num_gpio = 16,
5300
		.max_vid = 8191,
5301
		.port_base_addr = 0x0,
5302
		.phy_base_addr = 0x0,
5303
		.global1_addr = 0x1b,
5304
		.global2_addr = 0x1c,
5305
		.age_time_coeff = 3750,
5306
		.g1_irqs = 9,
5307
		.g2_irqs = 14,
5308
		.atu_move_port_mask = 0x1f,
5309
		.pvt = true,
5310
		.multi_chip = true,
5311
		.tag_protocol = DSA_TAG_PROTO_DSA,
5312
		.ptp_support = true,
5313 5314 5315
		.ops = &mv88e6390_ops,
	},
	[MV88E6390X] = {
5316
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
5317 5318 5319
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390X",
		.num_databases = 4096,
5320
		.num_macs = 16384,
5321
		.num_ports = 11,	/* 10 + Z80 */
5322
		.num_internal_phys = 9,
5323
		.num_gpio = 16,
5324
		.max_vid = 8191,
5325
		.port_base_addr = 0x0,
5326
		.phy_base_addr = 0x0,
5327
		.global1_addr = 0x1b,
5328
		.global2_addr = 0x1c,
5329
		.age_time_coeff = 3750,
5330
		.g1_irqs = 9,
5331
		.g2_irqs = 14,
5332
		.atu_move_port_mask = 0x1f,
5333
		.pvt = true,
5334
		.multi_chip = true,
5335
		.tag_protocol = DSA_TAG_PROTO_DSA,
5336
		.ptp_support = true,
5337 5338
		.ops = &mv88e6390x_ops,
	},
5339 5340
};

5341
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
5342
{
5343
	int i;
5344

5345 5346 5347
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
5348 5349 5350 5351

	return NULL;
}

5352
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
5353 5354
{
	const struct mv88e6xxx_info *info;
5355 5356 5357
	unsigned int prod_num, rev;
	u16 id;
	int err;
5358

5359
	mv88e6xxx_reg_lock(chip);
5360
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
5361
	mv88e6xxx_reg_unlock(chip);
5362 5363
	if (err)
		return err;
5364

5365 5366
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
5367 5368 5369 5370 5371

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

5372
	/* Update the compatible info with the probed one */
5373
	chip->info = info;
5374

5375 5376 5377 5378
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

5379 5380
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
5381 5382 5383 5384

	return 0;
}

5385
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
5386
{
5387
	struct mv88e6xxx_chip *chip;
5388

5389 5390
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
5391 5392
		return NULL;

5393
	chip->dev = dev;
5394

5395
	mutex_init(&chip->reg_lock);
5396
	INIT_LIST_HEAD(&chip->mdios);
5397
	idr_init(&chip->policies);
5398

5399
	return chip;
5400 5401
}

5402
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
5403 5404
							int port,
							enum dsa_tag_protocol m)
5405
{
V
Vivien Didelot 已提交
5406
	struct mv88e6xxx_chip *chip = ds->priv;
5407

5408
	return chip->info->tag_protocol;
5409 5410
}

5411
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
5412
				      const struct switchdev_obj_port_mdb *mdb)
5413 5414 5415 5416 5417 5418 5419 5420 5421
{
	/* 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,
5422
				   const struct switchdev_obj_port_mdb *mdb)
5423
{
V
Vivien Didelot 已提交
5424
	struct mv88e6xxx_chip *chip = ds->priv;
5425

5426
	mv88e6xxx_reg_lock(chip);
5427
	if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
5428
					 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
5429 5430
		dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
			port);
5431
	mv88e6xxx_reg_unlock(chip);
5432 5433 5434 5435 5436
}

static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
				  const struct switchdev_obj_port_mdb *mdb)
{
V
Vivien Didelot 已提交
5437
	struct mv88e6xxx_chip *chip = ds->priv;
5438 5439
	int err;

5440
	mv88e6xxx_reg_lock(chip);
5441
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 0);
5442
	mv88e6xxx_reg_unlock(chip);
5443 5444 5445 5446

	return err;
}

5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513
static int mv88e6xxx_port_mirror_add(struct dsa_switch *ds, int port,
				     struct dsa_mall_mirror_tc_entry *mirror,
				     bool ingress)
{
	enum mv88e6xxx_egress_direction direction = ingress ?
						MV88E6XXX_EGRESS_DIR_INGRESS :
						MV88E6XXX_EGRESS_DIR_EGRESS;
	struct mv88e6xxx_chip *chip = ds->priv;
	bool other_mirrors = false;
	int i;
	int err;

	if (!chip->info->ops->set_egress_port)
		return -EOPNOTSUPP;

	mutex_lock(&chip->reg_lock);
	if ((ingress ? chip->ingress_dest_port : chip->egress_dest_port) !=
	    mirror->to_local_port) {
		for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
			other_mirrors |= ingress ?
					 chip->ports[i].mirror_ingress :
					 chip->ports[i].mirror_egress;

		/* Can't change egress port when other mirror is active */
		if (other_mirrors) {
			err = -EBUSY;
			goto out;
		}

		err = chip->info->ops->set_egress_port(chip,
						       direction,
						       mirror->to_local_port);
		if (err)
			goto out;
	}

	err = mv88e6xxx_port_set_mirror(chip, port, direction, true);
out:
	mutex_unlock(&chip->reg_lock);

	return err;
}

static void mv88e6xxx_port_mirror_del(struct dsa_switch *ds, int port,
				      struct dsa_mall_mirror_tc_entry *mirror)
{
	enum mv88e6xxx_egress_direction direction = mirror->ingress ?
						MV88E6XXX_EGRESS_DIR_INGRESS :
						MV88E6XXX_EGRESS_DIR_EGRESS;
	struct mv88e6xxx_chip *chip = ds->priv;
	bool other_mirrors = false;
	int i;

	mutex_lock(&chip->reg_lock);
	if (mv88e6xxx_port_set_mirror(chip, port, direction, false))
		dev_err(ds->dev, "p%d: failed to disable mirroring\n", port);

	for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
		other_mirrors |= mirror->ingress ?
				 chip->ports[i].mirror_ingress :
				 chip->ports[i].mirror_egress;

	/* Reset egress port when no other mirror is active */
	if (!other_mirrors) {
		if (chip->info->ops->set_egress_port(chip,
						     direction,
						     dsa_upstream_port(ds,
5514
								       port)))
5515 5516 5517 5518 5519 5520
			dev_err(ds->dev, "failed to set egress port\n");
	}

	mutex_unlock(&chip->reg_lock);
}

5521 5522 5523 5524 5525 5526
static int mv88e6xxx_port_egress_floods(struct dsa_switch *ds, int port,
					 bool unicast, bool multicast)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err = -EOPNOTSUPP;

5527
	mv88e6xxx_reg_lock(chip);
5528 5529 5530 5531
	if (chip->info->ops->port_set_egress_floods)
		err = chip->info->ops->port_set_egress_floods(chip, port,
							      unicast,
							      multicast);
5532
	mv88e6xxx_reg_unlock(chip);
5533 5534 5535 5536

	return err;
}

5537
static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
5538
	.get_tag_protocol	= mv88e6xxx_get_tag_protocol,
5539
	.setup			= mv88e6xxx_setup,
5540
	.teardown		= mv88e6xxx_teardown,
5541
	.phylink_validate	= mv88e6xxx_validate,
5542
	.phylink_mac_link_state	= mv88e6xxx_serdes_pcs_get_state,
5543
	.phylink_mac_config	= mv88e6xxx_mac_config,
5544
	.phylink_mac_an_restart	= mv88e6xxx_serdes_pcs_an_restart,
5545 5546
	.phylink_mac_link_down	= mv88e6xxx_mac_link_down,
	.phylink_mac_link_up	= mv88e6xxx_mac_link_up,
5547 5548 5549
	.get_strings		= mv88e6xxx_get_strings,
	.get_ethtool_stats	= mv88e6xxx_get_ethtool_stats,
	.get_sset_count		= mv88e6xxx_get_sset_count,
5550 5551
	.port_enable		= mv88e6xxx_port_enable,
	.port_disable		= mv88e6xxx_port_disable,
5552 5553
	.port_max_mtu		= mv88e6xxx_get_max_mtu,
	.port_change_mtu	= mv88e6xxx_change_mtu,
V
Vivien Didelot 已提交
5554 5555
	.get_mac_eee		= mv88e6xxx_get_mac_eee,
	.set_mac_eee		= mv88e6xxx_set_mac_eee,
5556
	.get_eeprom_len		= mv88e6xxx_get_eeprom_len,
5557 5558 5559 5560
	.get_eeprom		= mv88e6xxx_get_eeprom,
	.set_eeprom		= mv88e6xxx_set_eeprom,
	.get_regs_len		= mv88e6xxx_get_regs_len,
	.get_regs		= mv88e6xxx_get_regs,
5561 5562
	.get_rxnfc		= mv88e6xxx_get_rxnfc,
	.set_rxnfc		= mv88e6xxx_set_rxnfc,
5563
	.set_ageing_time	= mv88e6xxx_set_ageing_time,
5564 5565
	.port_bridge_join	= mv88e6xxx_port_bridge_join,
	.port_bridge_leave	= mv88e6xxx_port_bridge_leave,
5566
	.port_egress_floods	= mv88e6xxx_port_egress_floods,
5567
	.port_stp_state_set	= mv88e6xxx_port_stp_state_set,
5568
	.port_fast_age		= mv88e6xxx_port_fast_age,
5569 5570 5571 5572 5573 5574 5575
	.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,
5576 5577 5578
	.port_mdb_prepare       = mv88e6xxx_port_mdb_prepare,
	.port_mdb_add           = mv88e6xxx_port_mdb_add,
	.port_mdb_del           = mv88e6xxx_port_mdb_del,
5579 5580
	.port_mirror_add	= mv88e6xxx_port_mirror_add,
	.port_mirror_del	= mv88e6xxx_port_mirror_del,
5581 5582
	.crosschip_bridge_join	= mv88e6xxx_crosschip_bridge_join,
	.crosschip_bridge_leave	= mv88e6xxx_crosschip_bridge_leave,
5583 5584 5585 5586 5587
	.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,
5588 5589
	.devlink_param_get	= mv88e6xxx_devlink_param_get,
	.devlink_param_set	= mv88e6xxx_devlink_param_set,
5590 5591
};

5592
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
5593
{
5594
	struct device *dev = chip->dev;
5595 5596
	struct dsa_switch *ds;

5597
	ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
5598 5599 5600
	if (!ds)
		return -ENOMEM;

5601 5602
	ds->dev = dev;
	ds->num_ports = mv88e6xxx_num_ports(chip);
5603
	ds->priv = chip;
5604
	ds->dev = dev;
5605
	ds->ops = &mv88e6xxx_switch_ops;
5606 5607
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
5608 5609 5610

	dev_set_drvdata(dev, ds);

5611
	return dsa_register_switch(ds);
5612 5613
}

5614
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
5615
{
5616
	dsa_unregister_switch(chip->ds);
5617 5618
}

5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631
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;
}

5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646
/* There is no suspend to RAM support at DSA level yet, the switch configuration
 * would be lost after a power cycle so prevent it to be suspended.
 */
static int __maybe_unused mv88e6xxx_suspend(struct device *dev)
{
	return -EOPNOTSUPP;
}

static int __maybe_unused mv88e6xxx_resume(struct device *dev)
{
	return 0;
}

static SIMPLE_DEV_PM_OPS(mv88e6xxx_pm_ops, mv88e6xxx_suspend, mv88e6xxx_resume);

5647
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
5648
{
5649
	struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
5650
	const struct mv88e6xxx_info *compat_info = NULL;
5651
	struct device *dev = &mdiodev->dev;
5652
	struct device_node *np = dev->of_node;
5653
	struct mv88e6xxx_chip *chip;
5654
	int port;
5655
	int err;
5656

5657 5658 5659
	if (!np && !pdata)
		return -EINVAL;

5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678
	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;
		}
	}

5679 5680 5681
	if (!compat_info)
		return -EINVAL;

5682
	chip = mv88e6xxx_alloc_chip(dev);
5683 5684 5685 5686
	if (!chip) {
		err = -ENOMEM;
		goto out;
	}
5687

5688
	chip->info = compat_info;
5689

5690
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
5691
	if (err)
5692
		goto out;
5693

5694
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
5695 5696 5697 5698
	if (IS_ERR(chip->reset)) {
		err = PTR_ERR(chip->reset);
		goto out;
	}
5699 5700
	if (chip->reset)
		usleep_range(1000, 2000);
5701

5702
	err = mv88e6xxx_detect(chip);
5703
	if (err)
5704
		goto out;
5705

5706 5707
	mv88e6xxx_phy_init(chip);

5708 5709 5710 5711 5712 5713 5714
	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;
	}
5715

5716
	mv88e6xxx_reg_lock(chip);
5717
	err = mv88e6xxx_switch_reset(chip);
5718
	mv88e6xxx_reg_unlock(chip);
5719 5720 5721
	if (err)
		goto out;

5722 5723 5724 5725 5726 5727
	if (np) {
		chip->irq = of_irq_get(np, 0);
		if (chip->irq == -EPROBE_DEFER) {
			err = chip->irq;
			goto out;
		}
5728 5729
	}

5730 5731 5732
	if (pdata)
		chip->irq = pdata->irq;

5733
	/* Has to be performed before the MDIO bus is created, because
5734
	 * the PHYs will link their interrupts to these interrupt
5735 5736
	 * controllers
	 */
5737
	mv88e6xxx_reg_lock(chip);
5738
	if (chip->irq > 0)
5739
		err = mv88e6xxx_g1_irq_setup(chip);
5740 5741
	else
		err = mv88e6xxx_irq_poll_setup(chip);
5742
	mv88e6xxx_reg_unlock(chip);
5743

5744 5745
	if (err)
		goto out;
5746

5747 5748
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
5749
		if (err)
5750
			goto out_g1_irq;
5751 5752
	}

5753 5754 5755 5756 5757 5758 5759 5760
	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;

5761
	err = mv88e6xxx_mdios_register(chip, np);
5762
	if (err)
5763
		goto out_g1_vtu_prob_irq;
5764

5765
	err = mv88e6xxx_register_switch(chip);
5766 5767
	if (err)
		goto out_mdio;
5768

5769
	return 0;
5770 5771

out_mdio:
5772
	mv88e6xxx_mdios_unregister(chip);
5773
out_g1_vtu_prob_irq:
5774
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
5775
out_g1_atu_prob_irq:
5776
	mv88e6xxx_g1_atu_prob_irq_free(chip);
5777
out_g2_irq:
5778
	if (chip->info->g2_irqs > 0)
5779 5780
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
5781
	if (chip->irq > 0)
5782
		mv88e6xxx_g1_irq_free(chip);
5783 5784
	else
		mv88e6xxx_irq_poll_free(chip);
5785
out:
5786 5787 5788
	if (pdata)
		dev_put(pdata->netdev);

5789
	return err;
5790
}
5791 5792 5793 5794

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

5797 5798
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
5799
		mv88e6xxx_ptp_free(chip);
5800
	}
5801

5802
	mv88e6xxx_phy_destroy(chip);
5803
	mv88e6xxx_unregister_switch(chip);
5804
	mv88e6xxx_mdios_unregister(chip);
5805

5806 5807 5808 5809 5810 5811 5812
	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)
5813
		mv88e6xxx_g1_irq_free(chip);
5814 5815
	else
		mv88e6xxx_irq_poll_free(chip);
5816 5817 5818
}

static const struct of_device_id mv88e6xxx_of_match[] = {
5819 5820 5821 5822
	{
		.compatible = "marvell,mv88e6085",
		.data = &mv88e6xxx_table[MV88E6085],
	},
5823 5824 5825 5826
	{
		.compatible = "marvell,mv88e6190",
		.data = &mv88e6xxx_table[MV88E6190],
	},
5827 5828 5829 5830
	{
		.compatible = "marvell,mv88e6250",
		.data = &mv88e6xxx_table[MV88E6250],
	},
5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841
	{ /* 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,
5842
		.pm = &mv88e6xxx_pm_ops,
5843 5844 5845
	},
};

5846
mdio_module_driver(mv88e6xxx_driver);
5847 5848 5849 5850

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