chip.c 163.3 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 "devlink.h"
36
#include "global1.h"
37
#include "global2.h"
38
#include "hwtstamp.h"
39
#include "phy.h"
40
#include "port.h"
41
#include "ptp.h"
42
#include "serdes.h"
43
#include "smi.h"
44

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

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

57
	assert_reg_lock(chip);
58

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

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

	return 0;
}

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

73
	assert_reg_lock(chip);
74

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

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

82 83 84
	return 0;
}

85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
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;
}

108 109 110 111 112 113 114
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);
}

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

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

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

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

	if (err)
		goto out;

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

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

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

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

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

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

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;

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

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

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

out:
218
	mv88e6xxx_reg_unlock(chip);
219 220
}

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

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

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

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

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

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

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

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

	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;

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

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

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

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

	return 0;

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

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

	return err;
}

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

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

338 339 340 341 342 343
	/* 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);

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

347
	mv88e6xxx_reg_unlock(chip);
348 349
	err = request_threaded_irq(chip->irq, NULL,
				   mv88e6xxx_g1_irq_thread_fn,
350
				   IRQF_ONESHOT | IRQF_SHARED,
351
				   chip->irq_name, chip);
352
	mv88e6xxx_reg_lock(chip);
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 380
	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);

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

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

401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
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;
}

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

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

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

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

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

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

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

	return err;
}

461 462 463 464 465 466 467
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;
}

468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
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);
}

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

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 584
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);
}

585 586 587 588 589 590 591 592 593 594 595 596 597 598
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);
}

599 600 601 602 603 604 605 606 607 608 609 610 611 612 613
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)
{
614
	if (port >= 9) {
615
		phylink_set(mask, 2500baseX_Full);
616 617
		phylink_set(mask, 2500baseT_Full);
	}
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637

	/* 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);
}

638 639 640 641
static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
			       unsigned long *supported,
			       struct phylink_link_state *state)
{
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660
	__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);
661 662 663 664 665 666 667
}

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;
668
	struct mv88e6xxx_port *p;
669
	int err;
670

671 672
	p = &chip->ports[port];

673 674 675 676 677
	/* 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...
	 */
678
	if ((mode == MLO_AN_PHY) && mv88e6xxx_phy_is_internal(ds, port))
679 680
		return;

681
	mv88e6xxx_reg_lock(chip);
682 683 684
	/* In inband mode, the link may come up at any time while the link
	 * is not forced down. Force the link down while we reconfigure the
	 * interface mode.
685
	 */
686 687 688 689
	if (mode == MLO_AN_INBAND && p->interface != state->interface &&
	    chip->info->ops->port_set_link)
		chip->info->ops->port_set_link(chip, port, LINK_FORCED_DOWN);

690
	err = mv88e6xxx_port_config_interface(chip, port, state->interface);
691 692 693 694 695 696 697 698 699 700 701
	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;

702 703 704 705 706 707 708 709 710
	/* Undo the forced down state above after completing configuration
	 * irrespective of its state on entry, which allows the link to come up.
	 */
	if (mode == MLO_AN_INBAND && p->interface != state->interface &&
	    chip->info->ops->port_set_link)
		chip->info->ops->port_set_link(chip, port, LINK_UNFORCED);

	p->interface = state->interface;

711
err_unlock:
712
	mv88e6xxx_reg_unlock(chip);
713 714

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

718 719 720
static void mv88e6xxx_mac_link_down(struct dsa_switch *ds, int port,
				    unsigned int mode,
				    phy_interface_t interface)
721 722
{
	struct mv88e6xxx_chip *chip = ds->priv;
723 724
	const struct mv88e6xxx_ops *ops;
	int err = 0;
725

726
	ops = chip->info->ops;
727

728
	mv88e6xxx_reg_lock(chip);
729
	if ((!mv88e6xxx_port_ppu_updates(chip, port) ||
730 731
	     mode == MLO_AN_FIXED) && ops->port_sync_link)
		err = ops->port_sync_link(chip, port, mode, false);
732
	mv88e6xxx_reg_unlock(chip);
733

734 735 736
	if (err)
		dev_err(chip->dev,
			"p%d: failed to force MAC link down\n", port);
737 738 739 740
}

static void mv88e6xxx_mac_link_up(struct dsa_switch *ds, int port,
				  unsigned int mode, phy_interface_t interface,
741 742 743
				  struct phy_device *phydev,
				  int speed, int duplex,
				  bool tx_pause, bool rx_pause)
744
{
745 746 747 748 749 750
	struct mv88e6xxx_chip *chip = ds->priv;
	const struct mv88e6xxx_ops *ops;
	int err = 0;

	ops = chip->info->ops;

751
	mv88e6xxx_reg_lock(chip);
752
	if (!mv88e6xxx_port_ppu_updates(chip, port) || mode == MLO_AN_FIXED) {
753 754 755
		/* 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
756
		 * handled in the Marvell hardware? E.g. port 2 on 88E6390
757 758
		 * shared between internal PHY and Serdes.
		 */
759 760 761 762 763
		err = mv88e6xxx_serdes_pcs_link_up(chip, port, mode, speed,
						   duplex);
		if (err)
			goto error;

764 765 766
		if (ops->port_set_speed_duplex) {
			err = ops->port_set_speed_duplex(chip, port,
							 speed, duplex);
767 768 769 770
			if (err && err != -EOPNOTSUPP)
				goto error;
		}

771 772
		if (ops->port_sync_link)
			err = ops->port_sync_link(chip, port, mode, true);
773
	}
774
error:
775
	mv88e6xxx_reg_unlock(chip);
776

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

782
static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
783
{
784 785
	if (!chip->info->ops->stats_snapshot)
		return -EOPNOTSUPP;
786

787
	return chip->info->ops->stats_snapshot(chip, port);
788 789
}

790
static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
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 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849
	{ "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, },
850 851
};

852
static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
853
					    struct mv88e6xxx_hw_stat *s,
854 855
					    int port, u16 bank1_select,
					    u16 histogram)
856 857 858
{
	u32 low;
	u32 high = 0;
859
	u16 reg = 0;
860
	int err;
861 862
	u64 value;

863
	switch (s->type) {
864
	case STATS_TYPE_PORT:
865 866
		err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
		if (err)
867
			return U64_MAX;
868

869
		low = reg;
870
		if (s->size == 4) {
871 872
			err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
			if (err)
873
				return U64_MAX;
874
			low |= ((u32)reg) << 16;
875
		}
876
		break;
877
	case STATS_TYPE_BANK1:
878
		reg = bank1_select;
879
		fallthrough;
880
	case STATS_TYPE_BANK0:
881
		reg |= s->reg | histogram;
882
		mv88e6xxx_g1_stats_read(chip, reg, &low);
883
		if (s->size == 8)
884
			mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
885 886
		break;
	default:
887
		return U64_MAX;
888
	}
889
	value = (((u64)high) << 32) | low;
890 891 892
	return value;
}

893 894
static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data, int types)
895
{
896 897
	struct mv88e6xxx_hw_stat *stat;
	int i, j;
898

899 900
	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
		stat = &mv88e6xxx_hw_stats[i];
901
		if (stat->type & types) {
902 903 904 905
			memcpy(data + j * ETH_GSTRING_LEN, stat->string,
			       ETH_GSTRING_LEN);
			j++;
		}
906
	}
907 908

	return j;
909 910
}

911 912
static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
913
{
914 915
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_PORT);
916 917
}

918 919 920 921 922 923
static int mv88e6250_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
{
	return mv88e6xxx_stats_get_strings(chip, data, STATS_TYPE_BANK0);
}

924 925
static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
926
{
927 928
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
929 930
}

931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948
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);
}

949
static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
950
				  u32 stringset, uint8_t *data)
951
{
V
Vivien Didelot 已提交
952
	struct mv88e6xxx_chip *chip = ds->priv;
953
	int count = 0;
954

955 956 957
	if (stringset != ETH_SS_STATS)
		return;

958
	mv88e6xxx_reg_lock(chip);
959

960
	if (chip->info->ops->stats_get_strings)
961 962 963 964
		count = chip->info->ops->stats_get_strings(chip, data);

	if (chip->info->ops->serdes_get_strings) {
		data += count * ETH_GSTRING_LEN;
965
		count = chip->info->ops->serdes_get_strings(chip, port, data);
966
	}
967

968 969 970
	data += count * ETH_GSTRING_LEN;
	mv88e6xxx_atu_vtu_get_strings(data);

971
	mv88e6xxx_reg_unlock(chip);
972 973 974 975 976
}

static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
					  int types)
{
977 978 979 980 981
	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];
982
		if (stat->type & types)
983 984 985
			j++;
	}
	return j;
986 987
}

988 989 990 991 992 993
static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
{
	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
					      STATS_TYPE_PORT);
}

994 995 996 997 998
static int mv88e6250_stats_get_sset_count(struct mv88e6xxx_chip *chip)
{
	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0);
}

999 1000 1001 1002 1003 1004
static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
{
	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
					      STATS_TYPE_BANK1);
}

1005
static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
1006 1007
{
	struct mv88e6xxx_chip *chip = ds->priv;
1008 1009
	int serdes_count = 0;
	int count = 0;
1010

1011 1012 1013
	if (sset != ETH_SS_STATS)
		return 0;

1014
	mv88e6xxx_reg_lock(chip);
1015
	if (chip->info->ops->stats_get_sset_count)
1016 1017 1018 1019 1020 1021 1022
		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);
1023
	if (serdes_count < 0) {
1024
		count = serdes_count;
1025 1026 1027 1028 1029
		goto out;
	}
	count += serdes_count;
	count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);

1030
out:
1031
	mv88e6xxx_reg_unlock(chip);
1032

1033
	return count;
1034 1035
}

1036 1037 1038
static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data, int types,
				     u16 bank1_select, u16 histogram)
1039 1040 1041 1042 1043 1044 1045
{
	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) {
1046
			mv88e6xxx_reg_lock(chip);
1047 1048 1049
			data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
							      bank1_select,
							      histogram);
1050
			mv88e6xxx_reg_unlock(chip);
1051

1052 1053 1054
			j++;
		}
	}
1055
	return j;
1056 1057
}

1058 1059
static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
1060 1061
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
1062
					 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
1063
					 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1064 1065
}

1066 1067 1068 1069 1070 1071 1072
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);
}

1073 1074
static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
1075 1076
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
1077
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1078 1079
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
					 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1080 1081
}

1082 1083
static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
1084 1085 1086
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1087 1088
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
					 0);
1089 1090
}

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

1101 1102 1103
static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
				uint64_t *data)
{
1104 1105
	int count = 0;

1106
	if (chip->info->ops->stats_get_stats)
1107 1108
		count = chip->info->ops->stats_get_stats(chip, port, data);

1109
	mv88e6xxx_reg_lock(chip);
1110 1111
	if (chip->info->ops->serdes_get_stats) {
		data += count;
1112
		count = chip->info->ops->serdes_get_stats(chip, port, data);
1113
	}
1114 1115
	data += count;
	mv88e6xxx_atu_vtu_get_stats(chip, port, data);
1116
	mv88e6xxx_reg_unlock(chip);
1117 1118
}

1119 1120
static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
					uint64_t *data)
1121
{
V
Vivien Didelot 已提交
1122
	struct mv88e6xxx_chip *chip = ds->priv;
1123 1124
	int ret;

1125
	mv88e6xxx_reg_lock(chip);
1126

1127
	ret = mv88e6xxx_stats_snapshot(chip, port);
1128
	mv88e6xxx_reg_unlock(chip);
1129 1130

	if (ret < 0)
1131
		return;
1132 1133

	mv88e6xxx_get_stats(chip, port, data);
1134

1135 1136
}

1137
static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
1138
{
1139 1140 1141 1142 1143 1144 1145 1146
	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;
1147 1148
}

1149 1150
static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
			       struct ethtool_regs *regs, void *_p)
1151
{
V
Vivien Didelot 已提交
1152
	struct mv88e6xxx_chip *chip = ds->priv;
1153 1154
	int err;
	u16 reg;
1155 1156 1157
	u16 *p = _p;
	int i;

1158
	regs->version = chip->info->prod_num;
1159 1160 1161

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

1162
	mv88e6xxx_reg_lock(chip);
1163

1164 1165
	for (i = 0; i < 32; i++) {

1166 1167 1168
		err = mv88e6xxx_port_read(chip, port, i, &reg);
		if (!err)
			p[i] = reg;
1169
	}
1170

1171 1172 1173
	if (chip->info->ops->serdes_get_regs)
		chip->info->ops->serdes_get_regs(chip, port, &p[i]);

1174
	mv88e6xxx_reg_unlock(chip);
1175 1176
}

V
Vivien Didelot 已提交
1177 1178
static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
1179
{
1180 1181
	/* Nothing to do on the port's MAC */
	return 0;
1182 1183
}

V
Vivien Didelot 已提交
1184 1185
static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
1186
{
1187 1188
	/* Nothing to do on the port's MAC */
	return 0;
1189 1190
}

1191
/* Mask of the local ports allowed to receive frames from a given fabric port */
1192
static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
1193
{
1194 1195
	struct dsa_switch *ds = chip->ds;
	struct dsa_switch_tree *dst = ds->dst;
1196
	struct net_device *br;
1197 1198
	struct dsa_port *dp;
	bool found = false;
1199
	u16 pvlan;
1200

1201 1202 1203 1204 1205 1206
	list_for_each_entry(dp, &dst->ports, list) {
		if (dp->ds->index == dev && dp->index == port) {
			found = true;
			break;
		}
	}
1207 1208

	/* Prevent frames from unknown switch or port */
1209
	if (!found)
1210 1211 1212
		return 0;

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

1216
	br = dp->bridge_dev;
1217 1218 1219 1220 1221
	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.
	 */
1222 1223 1224 1225 1226 1227
	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);
1228 1229 1230 1231

	return pvlan;
}

1232
static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
1233 1234
{
	u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
1235 1236 1237

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

1239
	return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
1240 1241
}

1242 1243
static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
					 u8 state)
1244
{
V
Vivien Didelot 已提交
1245
	struct mv88e6xxx_chip *chip = ds->priv;
1246
	int err;
1247

1248
	mv88e6xxx_reg_lock(chip);
1249
	err = mv88e6xxx_port_set_state(chip, port, state);
1250
	mv88e6xxx_reg_unlock(chip);
1251 1252

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

1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274
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;
}

1275 1276
static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
{
1277
	struct dsa_switch *ds = chip->ds;
1278 1279 1280 1281 1282 1283 1284 1285
	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++) {
1286 1287 1288
		port = dsa_routing_port(ds, target);
		if (port == ds->num_ports)
			port = 0x1f;
1289 1290 1291 1292 1293 1294

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

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

1302 1303 1304 1305
	err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
	if (err)
		return err;

1306 1307 1308
	return 0;
}

1309 1310 1311 1312 1313 1314 1315 1316 1317
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;
}

1318 1319 1320 1321 1322 1323 1324 1325
static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->rmu_disable)
		return chip->info->ops->rmu_disable(chip);

	return 0;
}

1326 1327 1328 1329 1330 1331 1332 1333
static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->pot_clear)
		return chip->info->ops->pot_clear(chip);

	return 0;
}

1334 1335 1336 1337 1338 1339 1340 1341
static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->mgmt_rsvd2cpu)
		return chip->info->ops->mgmt_rsvd2cpu(chip);

	return 0;
}

1342 1343
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
1344 1345
	int err;

1346 1347 1348 1349
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

1350 1351 1352 1353
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

1354 1355 1356
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376
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;
}

1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389
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;
}

1390 1391 1392 1393 1394
static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
{
	u16 pvlan = 0;

	if (!mv88e6xxx_has_pvt(chip))
1395
		return 0;
1396 1397 1398

	/* Skip the local source device, which uses in-chip port VLAN */
	if (dev != chip->ds->index)
1399
		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1400 1401 1402 1403

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

1404 1405
static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
{
1406 1407 1408
	int dev, port;
	int err;

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

1430 1431 1432 1433 1434
static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

1435
	mv88e6xxx_reg_lock(chip);
1436
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1437
	mv88e6xxx_reg_unlock(chip);
1438 1439

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

1443 1444
static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
{
1445
	if (!mv88e6xxx_max_vid(chip))
1446 1447 1448 1449 1450
		return 0;

	return mv88e6xxx_g1_vtu_flush(chip);
}

1451 1452 1453 1454 1455 1456 1457 1458 1459
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);
}

1460 1461 1462 1463 1464 1465 1466 1467 1468
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);
}

1469
int mv88e6xxx_fid_map(struct mv88e6xxx_chip *chip, unsigned long *fid_bitmap)
1470
{
1471
	struct mv88e6xxx_vtu_entry vlan;
1472
	int i, err;
1473
	u16 fid;
1474 1475 1476

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

1477
	/* Set every FID bit used by the (un)bridged ports */
1478
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1479
		err = mv88e6xxx_port_get_fid(chip, i, &fid);
1480 1481 1482
		if (err)
			return err;

1483
		set_bit(fid, fid_bitmap);
1484 1485
	}

1486
	/* Set every FID bit used by the VLAN entries */
1487
	vlan.vid = mv88e6xxx_max_vid(chip);
1488 1489
	vlan.valid = false;

1490
	do {
1491
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1492 1493 1494 1495 1496 1497 1498
		if (err)
			return err;

		if (!vlan.valid)
			break;

		set_bit(vlan.fid, fid_bitmap);
1499
	} while (vlan.vid < mv88e6xxx_max_vid(chip));
1500

1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512
	return 0;
}

static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
{
	DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
	int err;

	err = mv88e6xxx_fid_map(chip, fid_bitmap);
	if (err)
		return err;

1513 1514 1515 1516
	/* 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);
1517
	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1518 1519 1520
		return -ENOSPC;

	/* Clear the database */
1521
	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1522 1523
}

1524 1525 1526
static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
					u16 vid_begin, u16 vid_end)
{
V
Vivien Didelot 已提交
1527
	struct mv88e6xxx_chip *chip = ds->priv;
1528
	struct mv88e6xxx_vtu_entry vlan;
1529 1530
	int i, err;

1531 1532 1533 1534
	/* 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;

1535 1536 1537
	if (!vid_begin)
		return -EOPNOTSUPP;

1538 1539 1540
	vlan.vid = vid_begin - 1;
	vlan.valid = false;

1541
	do {
1542
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1543
		if (err)
1544
			return err;
1545 1546 1547 1548 1549 1550 1551

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

1552
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1553 1554 1555
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

1556
			if (!dsa_to_port(ds, i)->slave)
1557 1558
				continue;

1559
			if (vlan.member[i] ==
1560
			    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1561 1562
				continue;

V
Vivien Didelot 已提交
1563
			if (dsa_to_port(ds, i)->bridge_dev ==
1564
			    dsa_to_port(ds, port)->bridge_dev)
1565 1566
				break; /* same bridge, check next VLAN */

V
Vivien Didelot 已提交
1567
			if (!dsa_to_port(ds, i)->bridge_dev)
1568 1569
				continue;

1570 1571
			dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
				port, vlan.vid, i,
V
Vivien Didelot 已提交
1572
				netdev_name(dsa_to_port(ds, i)->bridge_dev));
1573
			return -EOPNOTSUPP;
1574 1575 1576
		}
	} while (vlan.vid < vid_end);

1577
	return 0;
1578 1579
}

1580
static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1581 1582
					 bool vlan_filtering,
					 struct switchdev_trans *trans)
1583
{
V
Vivien Didelot 已提交
1584
	struct mv88e6xxx_chip *chip = ds->priv;
1585 1586
	u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
		MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
1587
	int err;
1588

1589
	if (switchdev_trans_ph_prepare(trans))
1590
		return mv88e6xxx_max_vid(chip) ? 0 : -EOPNOTSUPP;
1591

1592
	mv88e6xxx_reg_lock(chip);
1593
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1594
	mv88e6xxx_reg_unlock(chip);
1595

1596
	return err;
1597 1598
}

1599 1600
static int
mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1601
			    const struct switchdev_obj_port_vlan *vlan)
1602
{
V
Vivien Didelot 已提交
1603
	struct mv88e6xxx_chip *chip = ds->priv;
1604 1605
	int err;

1606
	if (!mv88e6xxx_max_vid(chip))
1607 1608
		return -EOPNOTSUPP;

1609 1610 1611
	/* 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.
	 */
1612
	mv88e6xxx_reg_lock(chip);
1613 1614
	err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
					   vlan->vid_end);
1615
	mv88e6xxx_reg_unlock(chip);
1616

1617 1618 1619
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */
1620
	return err;
1621 1622
}

1623 1624 1625 1626 1627
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;
1628 1629
	struct mv88e6xxx_vtu_entry vlan;
	u16 fid;
1630 1631 1632
	int err;

	/* Null VLAN ID corresponds to the port private database */
1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650
	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;
	}
1651

1652
	entry.state = 0;
1653 1654 1655
	ether_addr_copy(entry.mac, addr);
	eth_addr_dec(entry.mac);

1656
	err = mv88e6xxx_g1_atu_getnext(chip, fid, &entry);
1657 1658 1659 1660
	if (err)
		return err;

	/* Initialize a fresh ATU entry if it isn't found */
1661
	if (!entry.state || !ether_addr_equal(entry.mac, addr)) {
1662 1663 1664 1665 1666
		memset(&entry, 0, sizeof(entry));
		ether_addr_copy(entry.mac, addr);
	}

	/* Purge the ATU entry only if no port is using it anymore */
1667
	if (!state) {
1668 1669
		entry.portvec &= ~BIT(port);
		if (!entry.portvec)
1670
			entry.state = 0;
1671 1672 1673 1674 1675
	} else {
		entry.portvec |= BIT(port);
		entry.state = state;
	}

1676
	return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry);
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 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767
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) {
1768
		if (fs->m_ext.vlan_tci != htons(0xffff))
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 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888
			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;
}

1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911
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;
}

1912
static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port,
1913
				    u16 vid, u8 member, bool warn)
1914
{
1915
	const u8 non_member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1916
	struct mv88e6xxx_vtu_entry vlan;
1917
	int i, err;
1918

1919 1920
	if (!vid)
		return -EOPNOTSUPP;
1921

1922 1923
	vlan.vid = vid - 1;
	vlan.valid = false;
1924

1925
	err = mv88e6xxx_vtu_getnext(chip, &vlan);
1926 1927 1928
	if (err)
		return err;

1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957
	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;
1958
	} else if (warn) {
1959 1960 1961 1962 1963
		dev_info(chip->dev, "p%d: already a member of VLAN %d\n",
			 port, vid);
	}

	return 0;
1964 1965
}

1966
static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1967
				    const struct switchdev_obj_port_vlan *vlan)
1968
{
V
Vivien Didelot 已提交
1969
	struct mv88e6xxx_chip *chip = ds->priv;
1970 1971
	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1972
	bool warn;
1973
	u8 member;
1974 1975
	u16 vid;

1976
	if (!mv88e6xxx_max_vid(chip))
1977 1978
		return;

1979
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1980
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
1981
	else if (untagged)
1982
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
1983
	else
1984
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
1985

1986 1987 1988 1989 1990
	/* 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);

1991
	mv88e6xxx_reg_lock(chip);
1992

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

1998
	if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1999 2000
		dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
			vlan->vid_end);
2001

2002
	mv88e6xxx_reg_unlock(chip);
2003 2004
}

2005 2006
static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,
				     int port, u16 vid)
2007
{
2008
	struct mv88e6xxx_vtu_entry vlan;
2009 2010
	int i, err;

2011 2012 2013 2014 2015 2016 2017
	if (!vid)
		return -EOPNOTSUPP;

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

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

2021 2022 2023 2024 2025
	/* 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)
2026
		return -EOPNOTSUPP;
2027

2028
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
2029 2030

	/* keep the VLAN unless all ports are excluded */
2031
	vlan.valid = false;
2032
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
2033 2034
		if (vlan.member[i] !=
		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
2035
			vlan.valid = true;
2036 2037 2038 2039
			break;
		}
	}

2040
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
2041 2042 2043
	if (err)
		return err;

2044
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
2045 2046
}

2047 2048
static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
				   const struct switchdev_obj_port_vlan *vlan)
2049
{
V
Vivien Didelot 已提交
2050
	struct mv88e6xxx_chip *chip = ds->priv;
2051 2052 2053
	u16 pvid, vid;
	int err = 0;

2054
	if (!mv88e6xxx_max_vid(chip))
2055 2056
		return -EOPNOTSUPP;

2057
	mv88e6xxx_reg_lock(chip);
2058

2059
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
2060 2061 2062
	if (err)
		goto unlock;

2063
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
2064
		err = mv88e6xxx_port_vlan_leave(chip, port, vid);
2065 2066 2067 2068
		if (err)
			goto unlock;

		if (vid == pvid) {
2069
			err = mv88e6xxx_port_set_pvid(chip, port, 0);
2070 2071 2072 2073 2074
			if (err)
				goto unlock;
		}
	}

2075
unlock:
2076
	mv88e6xxx_reg_unlock(chip);
2077 2078 2079 2080

	return err;
}

2081 2082
static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
				  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 2089
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
2090
	mv88e6xxx_reg_unlock(chip);
2091 2092

	return err;
2093 2094
}

2095
static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
2096
				  const unsigned char *addr, u16 vid)
2097
{
V
Vivien Didelot 已提交
2098
	struct mv88e6xxx_chip *chip = ds->priv;
2099
	int err;
2100

2101
	mv88e6xxx_reg_lock(chip);
2102
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid, 0);
2103
	mv88e6xxx_reg_unlock(chip);
2104

2105
	return err;
2106 2107
}

2108 2109
static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
				      u16 fid, u16 vid, int port,
2110
				      dsa_fdb_dump_cb_t *cb, void *data)
2111
{
2112
	struct mv88e6xxx_atu_entry addr;
2113
	bool is_static;
2114 2115
	int err;

2116
	addr.state = 0;
2117
	eth_broadcast_addr(addr.mac);
2118 2119

	do {
2120
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
2121
		if (err)
2122
			return err;
2123

2124
		if (!addr.state)
2125 2126
			break;

2127
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
2128 2129
			continue;

2130 2131
		if (!is_unicast_ether_addr(addr.mac))
			continue;
2132

2133 2134 2135
		is_static = (addr.state ==
			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
		err = cb(addr.mac, vid, is_static, data);
2136 2137
		if (err)
			return err;
2138 2139 2140 2141 2142
	} while (!is_broadcast_ether_addr(addr.mac));

	return err;
}

2143
static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2144
				  dsa_fdb_dump_cb_t *cb, void *data)
2145
{
2146
	struct mv88e6xxx_vtu_entry vlan;
2147
	u16 fid;
2148 2149
	int err;

2150
	/* Dump port's default Filtering Information Database (VLAN ID 0) */
2151
	err = mv88e6xxx_port_get_fid(chip, port, &fid);
2152
	if (err)
2153
		return err;
2154

2155
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
2156
	if (err)
2157
		return err;
2158

2159
	/* Dump VLANs' Filtering Information Databases */
2160
	vlan.vid = mv88e6xxx_max_vid(chip);
2161 2162
	vlan.valid = false;

2163
	do {
2164
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
2165
		if (err)
2166
			return err;
2167 2168 2169 2170

		if (!vlan.valid)
			break;

2171
		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
2172
						 cb, data);
2173
		if (err)
2174
			return err;
2175
	} while (vlan.vid < mv88e6xxx_max_vid(chip));
2176

2177 2178 2179 2180
	return err;
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2181
				   dsa_fdb_dump_cb_t *cb, void *data)
2182
{
V
Vivien Didelot 已提交
2183
	struct mv88e6xxx_chip *chip = ds->priv;
2184 2185
	int err;

2186
	mv88e6xxx_reg_lock(chip);
2187
	err = mv88e6xxx_port_db_dump(chip, port, cb, data);
2188
	mv88e6xxx_reg_unlock(chip);
2189

2190
	return err;
2191 2192
}

2193 2194
static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
				struct net_device *br)
2195
{
2196 2197 2198
	struct dsa_switch *ds = chip->ds;
	struct dsa_switch_tree *dst = ds->dst;
	struct dsa_port *dp;
2199
	int err;
2200

2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215
	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);
2216 2217 2218 2219 2220 2221
				if (err)
					return err;
			}
		}
	}

2222 2223 2224 2225 2226 2227 2228 2229 2230
	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;

2231
	mv88e6xxx_reg_lock(chip);
2232
	err = mv88e6xxx_bridge_map(chip, br);
2233
	mv88e6xxx_reg_unlock(chip);
2234

2235
	return err;
2236 2237
}

2238 2239
static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
					struct net_device *br)
2240
{
V
Vivien Didelot 已提交
2241
	struct mv88e6xxx_chip *chip = ds->priv;
2242

2243
	mv88e6xxx_reg_lock(chip);
2244 2245 2246
	if (mv88e6xxx_bridge_map(chip, br) ||
	    mv88e6xxx_port_vlan_map(chip, port))
		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
2247
	mv88e6xxx_reg_unlock(chip);
2248 2249
}

2250 2251
static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds,
					   int tree_index, int sw_index,
2252 2253 2254 2255 2256
					   int port, struct net_device *br)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

2257 2258 2259
	if (tree_index != ds->dst->index)
		return 0;

2260
	mv88e6xxx_reg_lock(chip);
2261
	err = mv88e6xxx_pvt_map(chip, sw_index, port);
2262
	mv88e6xxx_reg_unlock(chip);
2263 2264 2265 2266

	return err;
}

2267 2268
static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds,
					     int tree_index, int sw_index,
2269 2270 2271 2272
					     int port, struct net_device *br)
{
	struct mv88e6xxx_chip *chip = ds->priv;

2273 2274 2275
	if (tree_index != ds->dst->index)
		return;

2276
	mv88e6xxx_reg_lock(chip);
2277
	if (mv88e6xxx_pvt_map(chip, sw_index, port))
2278
		dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
2279
	mv88e6xxx_reg_unlock(chip);
2280 2281
}

2282 2283 2284 2285 2286 2287 2288 2289
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->reset)
		return chip->info->ops->reset(chip);

	return 0;
}

2290 2291 2292 2293 2294 2295 2296 2297 2298 2299
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);
2300 2301

		mv88e6xxx_g1_wait_eeprom_done(chip);
2302 2303 2304
	}
}

2305
static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2306
{
2307
	int i, err;
2308

2309
	/* Set all ports to the Disabled state */
2310
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2311
		err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
2312 2313
		if (err)
			return err;
2314 2315
	}

2316 2317 2318
	/* Wait for transmit queues to drain,
	 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
	 */
2319 2320
	usleep_range(2000, 4000);

2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331
	return 0;
}

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

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

2332
	mv88e6xxx_hardware_reset(chip);
2333

2334
	return mv88e6xxx_software_reset(chip);
2335 2336
}

2337
static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
2338 2339
				   enum mv88e6xxx_frame_mode frame,
				   enum mv88e6xxx_egress_mode egress, u16 etype)
2340 2341 2342
{
	int err;

2343 2344 2345 2346
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
2347 2348 2349
	if (err)
		return err;

2350 2351 2352 2353 2354 2355 2356 2357
	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;
2358 2359
}

2360
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2361
{
2362
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
2363
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2364
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2365
}
2366

2367 2368 2369
static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
2370
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2371
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2372
}
2373

2374 2375 2376 2377
static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port,
				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
2378 2379
				       MV88E6XXX_EGRESS_MODE_ETHERTYPE,
				       ETH_P_EDSA);
2380
}
2381

2382 2383 2384 2385
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);
2386

2387
	if (dsa_is_user_port(chip->ds, port))
2388
		return mv88e6xxx_set_port_mode_normal(chip, port);
2389

2390 2391 2392
	/* 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);
2393

2394 2395
	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
		return mv88e6xxx_set_port_mode_edsa(chip, port);
2396

2397
	return -EINVAL;
2398 2399
}

2400
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2401
{
2402
	bool message = dsa_is_dsa_port(chip->ds, port);
2403

2404
	return mv88e6xxx_port_set_message_port(chip, port, message);
2405
}
2406

2407
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2408
{
2409
	struct dsa_switch *ds = chip->ds;
2410
	bool flood;
2411

2412 2413 2414 2415 2416
	/* 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);
2417

2418
	return 0;
2419 2420
}

2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449
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;

2450 2451 2452
	snprintf(dev_id->serdes_irq_name, sizeof(dev_id->serdes_irq_name),
		 "mv88e6xxx-%s-serdes-%d", dev_name(chip->dev), port);

2453 2454 2455
	/* 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,
2456 2457
				   IRQF_ONESHOT, dev_id->serdes_irq_name,
				   dev_id);
2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489
	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;
}

2490 2491 2492
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
2493
	u8 lane;
2494
	int err;
2495

2496 2497
	lane = mv88e6xxx_serdes_get_lane(chip, port);
	if (!lane)
2498 2499 2500
		return 0;

	if (on) {
2501
		err = mv88e6xxx_serdes_power_up(chip, port, lane);
2502 2503 2504
		if (err)
			return err;

2505
		err = mv88e6xxx_serdes_irq_request(chip, port, lane);
2506
	} else {
2507 2508 2509
		err = mv88e6xxx_serdes_irq_free(chip, port, lane);
		if (err)
			return err;
2510

2511
		err = mv88e6xxx_serdes_power_down(chip, port, lane);
2512 2513 2514
	}

	return err;
2515 2516
}

2517 2518 2519 2520 2521 2522
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

2523
	upstream_port = dsa_upstream_port(ds, port);
2524 2525 2526 2527 2528 2529 2530
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

2531 2532 2533 2534 2535 2536 2537 2538 2539 2540
	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,
2541 2542 2543 2544 2545 2546 2547 2548
						MV88E6XXX_EGRESS_DIR_INGRESS,
						upstream_port);
			if (err)
				return err;

			err = chip->info->ops->set_egress_port(chip,
						MV88E6XXX_EGRESS_DIR_EGRESS,
						upstream_port);
2549 2550 2551 2552 2553
			if (err)
				return err;
		}
	}

2554 2555 2556
	return 0;
}

2557
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
2558
{
2559
	struct dsa_switch *ds = chip->ds;
2560
	int err;
2561
	u16 reg;
2562

2563 2564 2565
	chip->ports[port].chip = chip;
	chip->ports[port].port = port;

2566 2567 2568 2569 2570 2571 2572
	/* 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,
2573
					       PAUSE_OFF,
2574 2575 2576 2577
					       PHY_INTERFACE_MODE_NA);
	else
		err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
					       SPEED_UNFORCED, DUPLEX_UNFORCED,
2578
					       PAUSE_ON,
2579 2580 2581
					       PHY_INTERFACE_MODE_NA);
	if (err)
		return err;
2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596

	/* 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.
	 */
2597 2598 2599 2600
	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);
2601 2602
	if (err)
		return err;
2603

2604
	err = mv88e6xxx_setup_port_mode(chip, port);
2605 2606
	if (err)
		return err;
2607

2608
	err = mv88e6xxx_setup_egress_floods(chip, port);
2609 2610 2611
	if (err)
		return err;

2612
	/* Port Control 2: don't force a good FCS, set the maximum frame size to
2613
	 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
2614 2615 2616
	 * 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.
2617
	 */
2618 2619 2620
	err = mv88e6xxx_port_set_map_da(chip, port);
	if (err)
		return err;
2621

2622 2623 2624
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
2625

2626
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
2627
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
2628 2629 2630
	if (err)
		return err;

2631 2632
	if (chip->info->ops->port_set_jumbo_size) {
		err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
2633 2634 2635 2636
		if (err)
			return err;
	}

2637 2638 2639 2640 2641
	/* 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.
	 */
2642
	reg = 1 << port;
2643 2644
	/* Disable learning for CPU port */
	if (dsa_is_cpu_port(ds, port))
2645
		reg = 0;
2646

2647 2648
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
2649 2650
	if (err)
		return err;
2651 2652

	/* Egress rate control 2: disable egress rate control. */
2653 2654
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
				   0x0000);
2655 2656
	if (err)
		return err;
2657

2658 2659
	if (chip->info->ops->port_pause_limit) {
		err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
2660 2661
		if (err)
			return err;
2662
	}
2663

2664 2665 2666 2667 2668 2669
	if (chip->info->ops->port_disable_learn_limit) {
		err = chip->info->ops->port_disable_learn_limit(chip, port);
		if (err)
			return err;
	}

2670 2671
	if (chip->info->ops->port_disable_pri_override) {
		err = chip->info->ops->port_disable_pri_override(chip, port);
2672 2673
		if (err)
			return err;
2674
	}
2675

2676 2677
	if (chip->info->ops->port_tag_remap) {
		err = chip->info->ops->port_tag_remap(chip, port);
2678 2679
		if (err)
			return err;
2680 2681
	}

2682 2683
	if (chip->info->ops->port_egress_rate_limiting) {
		err = chip->info->ops->port_egress_rate_limiting(chip, port);
2684 2685
		if (err)
			return err;
2686 2687
	}

2688 2689 2690 2691 2692
	if (chip->info->ops->port_setup_message_port) {
		err = chip->info->ops->port_setup_message_port(chip, port);
		if (err)
			return err;
	}
2693

2694
	/* Port based VLAN map: give each port the same default address
2695 2696
	 * database, and allow bidirectional communication between the
	 * CPU and DSA port(s), and the other ports.
2697
	 */
2698
	err = mv88e6xxx_port_set_fid(chip, port, 0);
2699 2700
	if (err)
		return err;
2701

2702
	err = mv88e6xxx_port_vlan_map(chip, port);
2703 2704
	if (err)
		return err;
2705 2706 2707 2708

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

2712 2713 2714 2715 2716 2717
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;
2718 2719
	else if (chip->info->ops->set_max_frame_size)
		return 1632;
2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730
	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);
2731 2732
	else if (chip->info->ops->set_max_frame_size)
		ret = chip->info->ops->set_max_frame_size(chip, new_mtu);
2733 2734 2735 2736 2737 2738 2739 2740
	else
		if (new_mtu > 1522)
			ret = -EINVAL;
	mv88e6xxx_reg_unlock(chip);

	return ret;
}

2741 2742 2743 2744
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
2745
	int err;
2746

2747
	mv88e6xxx_reg_lock(chip);
2748
	err = mv88e6xxx_serdes_power(chip, port, true);
2749
	mv88e6xxx_reg_unlock(chip);
2750 2751 2752 2753

	return err;
}

2754
static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port)
2755 2756 2757
{
	struct mv88e6xxx_chip *chip = ds->priv;

2758
	mv88e6xxx_reg_lock(chip);
2759 2760
	if (mv88e6xxx_serdes_power(chip, port, false))
		dev_err(chip->dev, "failed to power off SERDES\n");
2761
	mv88e6xxx_reg_unlock(chip);
2762 2763
}

2764 2765 2766
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
2767
	struct mv88e6xxx_chip *chip = ds->priv;
2768 2769
	int err;

2770
	mv88e6xxx_reg_lock(chip);
2771
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2772
	mv88e6xxx_reg_unlock(chip);
2773 2774 2775 2776

	return err;
}

2777
static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
2778
{
2779
	int err;
2780

2781
	/* Initialize the statistics unit */
2782 2783 2784 2785 2786
	if (chip->info->ops->stats_set_histogram) {
		err = chip->info->ops->stats_set_histogram(chip);
		if (err)
			return err;
	}
2787

2788
	return mv88e6xxx_g1_stats_clear(chip);
2789 2790
}

2791 2792 2793 2794 2795 2796 2797 2798
/* 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++) {
2799
		err = mv88e6xxx_port_hidden_read(chip, 0xf, port, 0, &val);
2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831
		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++) {
2832
		err = mv88e6xxx_port_hidden_write(chip, 0xf, port, 0, 0x01c0);
2833 2834 2835 2836 2837 2838 2839
		if (err)
			return err;
	}

	return mv88e6xxx_software_reset(chip);
}

2840 2841 2842
static void mv88e6xxx_teardown(struct dsa_switch *ds)
{
	mv88e6xxx_teardown_devlink_params(ds);
2843
	dsa_devlink_resources_unregister(ds);
2844
	mv88e6xxx_teardown_devlink_regions(ds);
2845 2846
}

2847
static int mv88e6xxx_setup(struct dsa_switch *ds)
2848
{
V
Vivien Didelot 已提交
2849
	struct mv88e6xxx_chip *chip = ds->priv;
2850
	u8 cmode;
2851
	int err;
2852 2853
	int i;

2854
	chip->ds = ds;
2855
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
R
Russell King 已提交
2856
	ds->configure_vlan_while_not_filtering = true;
2857

2858
	mv88e6xxx_reg_lock(chip);
2859

2860 2861 2862 2863 2864 2865
	if (chip->info->ops->setup_errata) {
		err = chip->info->ops->setup_errata(chip);
		if (err)
			goto unlock;
	}

2866 2867 2868 2869 2870
	/* 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)
2871
				goto unlock;
2872 2873 2874 2875 2876

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

2877
	/* Setup Switch Port Registers */
2878
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2879 2880 2881
		if (dsa_is_unused_port(ds, i))
			continue;

2882
		/* Prevent the use of an invalid port. */
2883
		if (mv88e6xxx_is_invalid_port(chip, i)) {
2884 2885 2886 2887 2888
			dev_err(chip->dev, "port %d is invalid\n", i);
			err = -EINVAL;
			goto unlock;
		}

2889 2890 2891 2892 2893
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

2894 2895 2896 2897
	err = mv88e6xxx_irl_setup(chip);
	if (err)
		goto unlock;

2898 2899 2900 2901
	err = mv88e6xxx_mac_setup(chip);
	if (err)
		goto unlock;

2902 2903 2904 2905
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

2906 2907 2908 2909
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

2910 2911 2912 2913
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

2914 2915 2916 2917
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

2918 2919 2920 2921
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

2922 2923 2924 2925
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

2926 2927 2928 2929
	err = mv88e6xxx_rmu_setup(chip);
	if (err)
		goto unlock;

2930 2931 2932
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
2933

2934 2935 2936 2937
	err = mv88e6xxx_trunk_setup(chip);
	if (err)
		goto unlock;

2938 2939 2940 2941
	err = mv88e6xxx_devmap_setup(chip);
	if (err)
		goto unlock;

2942 2943 2944 2945
	err = mv88e6xxx_pri_setup(chip);
	if (err)
		goto unlock;

2946
	/* Setup PTP Hardware Clock and timestamping */
2947 2948 2949 2950
	if (chip->info->ptp_support) {
		err = mv88e6xxx_ptp_setup(chip);
		if (err)
			goto unlock;
2951 2952 2953 2954

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
2955 2956
	}

2957 2958 2959 2960
	err = mv88e6xxx_stats_setup(chip);
	if (err)
		goto unlock;

2961
unlock:
2962
	mv88e6xxx_reg_unlock(chip);
2963

2964 2965 2966 2967 2968 2969 2970
	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.
2971
	 */
2972 2973 2974 2975 2976 2977
	err = mv88e6xxx_setup_devlink_resources(ds);
	if (err)
		return err;

	err = mv88e6xxx_setup_devlink_params(ds);
	if (err)
2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989
		goto out_resources;

	err = mv88e6xxx_setup_devlink_regions(ds);
	if (err)
		goto out_params;

	return 0;

out_params:
	mv88e6xxx_teardown_devlink_params(ds);
out_resources:
	dsa_devlink_resources_unregister(ds);
2990 2991

	return err;
2992 2993
}

2994
static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
2995
{
2996 2997
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2998 2999
	u16 val;
	int err;
3000

3001 3002 3003
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

3004
	mv88e6xxx_reg_lock(chip);
3005
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
3006
	mv88e6xxx_reg_unlock(chip);
3007

3008
	if (reg == MII_PHYSID2) {
3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024
		/* 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;
3025 3026
	}

3027
	return err ? err : val;
3028 3029
}

3030
static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
3031
{
3032 3033
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
3034
	int err;
3035

3036 3037 3038
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

3039
	mv88e6xxx_reg_lock(chip);
3040
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
3041
	mv88e6xxx_reg_unlock(chip);
3042 3043

	return err;
3044 3045
}

3046
static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
3047 3048
				   struct device_node *np,
				   bool external)
3049 3050
{
	static int index;
3051
	struct mv88e6xxx_mdio_bus *mdio_bus;
3052 3053 3054
	struct mii_bus *bus;
	int err;

3055
	if (external) {
3056
		mv88e6xxx_reg_lock(chip);
3057
		err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
3058
		mv88e6xxx_reg_unlock(chip);
3059 3060 3061 3062 3063

		if (err)
			return err;
	}

3064
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
3065 3066 3067
	if (!bus)
		return -ENOMEM;

3068
	mdio_bus = bus->priv;
3069
	mdio_bus->bus = bus;
3070
	mdio_bus->chip = chip;
3071 3072
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
3073

3074 3075
	if (np) {
		bus->name = np->full_name;
3076
		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
3077 3078 3079 3080 3081 3082 3083
	} 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;
3084
	bus->parent = chip->dev;
3085

3086 3087 3088 3089 3090 3091
	if (!external) {
		err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
		if (err)
			return err;
	}

3092
	err = of_mdiobus_register(bus, np);
3093
	if (err) {
3094
		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
3095
		mv88e6xxx_g2_irq_mdio_free(chip, bus);
3096
		return err;
3097
	}
3098 3099 3100 3101 3102

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

	return 0;
3105
}
3106

3107 3108 3109 3110 3111 3112 3113 3114 3115
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;

3116 3117 3118
		if (!mdio_bus->external)
			mv88e6xxx_g2_irq_mdio_free(chip, bus);

3119 3120 3121 3122
		mdiobus_unregister(bus);
	}
}

3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142
static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
				    struct device_node *np)
{
	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) {
3143 3144
		if (of_device_is_compatible(
			    child, "marvell,mv88e6xxx-mdio-external")) {
3145
			err = mv88e6xxx_mdio_register(chip, child, true);
3146 3147
			if (err) {
				mv88e6xxx_mdios_unregister(chip);
3148
				of_node_put(child);
3149
				return err;
3150
			}
3151 3152 3153 3154
		}
	}

	return 0;
3155 3156
}

3157 3158
static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
3159
	struct mv88e6xxx_chip *chip = ds->priv;
3160 3161 3162 3163 3164 3165 3166

	return chip->eeprom_len;
}

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

3170 3171
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
3172

3173
	mv88e6xxx_reg_lock(chip);
3174
	err = chip->info->ops->get_eeprom(chip, eeprom, data);
3175
	mv88e6xxx_reg_unlock(chip);
3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187

	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 已提交
3188
	struct mv88e6xxx_chip *chip = ds->priv;
3189 3190
	int err;

3191 3192 3193
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

3194 3195 3196
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

3197
	mv88e6xxx_reg_lock(chip);
3198
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
3199
	mv88e6xxx_reg_unlock(chip);
3200 3201 3202 3203

	return err;
}

3204
static const struct mv88e6xxx_ops mv88e6085_ops = {
3205
	/* MV88E6XXX_FAMILY_6097 */
3206 3207
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3208
	.irl_init_all = mv88e6352_g2_irl_init_all,
3209
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3210 3211
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3212
	.port_set_link = mv88e6xxx_port_set_link,
3213
	.port_sync_link = mv88e6xxx_port_sync_link,
3214
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3215
	.port_tag_remap = mv88e6095_port_tag_remap,
3216
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3217
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3218
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3219
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3220
	.port_pause_limit = mv88e6097_port_pause_limit,
3221
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3222
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3223
	.port_get_cmode = mv88e6185_port_get_cmode,
3224
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3225
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3226
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3227 3228
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3229
	.stats_get_stats = mv88e6095_stats_get_stats,
3230 3231
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3232
	.watchdog_ops = &mv88e6097_watchdog_ops,
3233
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3234
	.pot_clear = mv88e6xxx_g2_pot_clear,
3235 3236
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
3237
	.reset = mv88e6185_g1_reset,
3238
	.rmu_disable = mv88e6085_g1_rmu_disable,
3239
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3240
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3241
	.phylink_validate = mv88e6185_phylink_validate,
3242
	.set_max_frame_size = mv88e6185_g1_set_max_frame_size,
3243 3244 3245
};

static const struct mv88e6xxx_ops mv88e6095_ops = {
3246
	/* MV88E6XXX_FAMILY_6095 */
3247 3248
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3249
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3250 3251
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3252
	.port_set_link = mv88e6xxx_port_set_link,
3253
	.port_sync_link = mv88e6185_port_sync_link,
3254
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3255
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
3256
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
3257
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
3258
	.port_get_cmode = mv88e6185_port_get_cmode,
3259
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3260
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3261
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3262 3263
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3264
	.stats_get_stats = mv88e6095_stats_get_stats,
3265
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3266 3267 3268
	.serdes_power = mv88e6185_serdes_power,
	.serdes_get_lane = mv88e6185_serdes_get_lane,
	.serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
3269 3270
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
3271
	.reset = mv88e6185_g1_reset,
3272
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3273
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3274
	.phylink_validate = mv88e6185_phylink_validate,
3275
	.set_max_frame_size = mv88e6185_g1_set_max_frame_size,
3276 3277
};

3278
static const struct mv88e6xxx_ops mv88e6097_ops = {
3279
	/* MV88E6XXX_FAMILY_6097 */
3280 3281
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3282
	.irl_init_all = mv88e6352_g2_irl_init_all,
3283 3284 3285 3286
	.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,
3287
	.port_sync_link = mv88e6185_port_sync_link,
3288
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3289
	.port_tag_remap = mv88e6095_port_tag_remap,
3290
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3291
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3292
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3293
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
3294
	.port_pause_limit = mv88e6097_port_pause_limit,
3295
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3296
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3297
	.port_get_cmode = mv88e6185_port_get_cmode,
3298
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3299
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3300
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3301 3302 3303
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
	.stats_get_stats = mv88e6095_stats_get_stats,
3304 3305
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3306
	.watchdog_ops = &mv88e6097_watchdog_ops,
3307
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3308 3309 3310
	.serdes_power = mv88e6185_serdes_power,
	.serdes_get_lane = mv88e6185_serdes_get_lane,
	.serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
3311 3312 3313
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
	.serdes_irq_enable = mv88e6097_serdes_irq_enable,
	.serdes_irq_status = mv88e6097_serdes_irq_status,
3314
	.pot_clear = mv88e6xxx_g2_pot_clear,
3315
	.reset = mv88e6352_g1_reset,
3316
	.rmu_disable = mv88e6085_g1_rmu_disable,
3317
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3318
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3319
	.phylink_validate = mv88e6185_phylink_validate,
3320
	.set_max_frame_size = mv88e6185_g1_set_max_frame_size,
3321 3322
};

3323
static const struct mv88e6xxx_ops mv88e6123_ops = {
3324
	/* MV88E6XXX_FAMILY_6165 */
3325 3326
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3327
	.irl_init_all = mv88e6352_g2_irl_init_all,
3328
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3329 3330
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3331
	.port_set_link = mv88e6xxx_port_set_link,
3332
	.port_sync_link = mv88e6xxx_port_sync_link,
3333
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3334
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
3335
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3336
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3337
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3338
	.port_get_cmode = mv88e6185_port_get_cmode,
3339
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3340
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3341
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3342 3343
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3344
	.stats_get_stats = mv88e6095_stats_get_stats,
3345 3346
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3347
	.watchdog_ops = &mv88e6097_watchdog_ops,
3348
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3349
	.pot_clear = mv88e6xxx_g2_pot_clear,
3350
	.reset = mv88e6352_g1_reset,
3351 3352
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3353
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3354
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3355
	.phylink_validate = mv88e6185_phylink_validate,
3356
	.set_max_frame_size = mv88e6185_g1_set_max_frame_size,
3357 3358 3359
};

static const struct mv88e6xxx_ops mv88e6131_ops = {
3360
	/* MV88E6XXX_FAMILY_6185 */
3361 3362
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3363
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3364 3365
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3366
	.port_set_link = mv88e6xxx_port_set_link,
3367
	.port_sync_link = mv88e6xxx_port_sync_link,
3368
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3369
	.port_tag_remap = mv88e6095_port_tag_remap,
3370
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3371
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
3372
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3373
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
3374
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3375
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3376
	.port_pause_limit = mv88e6097_port_pause_limit,
3377
	.port_set_pause = mv88e6185_port_set_pause,
3378
	.port_get_cmode = mv88e6185_port_get_cmode,
3379
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3380
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3381
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3382 3383
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3384
	.stats_get_stats = mv88e6095_stats_get_stats,
3385 3386
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3387
	.watchdog_ops = &mv88e6097_watchdog_ops,
3388
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3389
	.ppu_enable = mv88e6185_g1_ppu_enable,
3390
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
3391
	.ppu_disable = mv88e6185_g1_ppu_disable,
3392
	.reset = mv88e6185_g1_reset,
3393
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3394
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3395
	.phylink_validate = mv88e6185_phylink_validate,
3396 3397
};

3398 3399
static const struct mv88e6xxx_ops mv88e6141_ops = {
	/* MV88E6XXX_FAMILY_6341 */
3400 3401
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3402
	.irl_init_all = mv88e6352_g2_irl_init_all,
3403 3404 3405 3406 3407 3408
	.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,
3409
	.port_sync_link = mv88e6xxx_port_sync_link,
3410
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3411
	.port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
3412
	.port_max_speed_mode = mv88e6341_port_max_speed_mode,
3413 3414 3415 3416
	.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,
3417
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3418
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3419
	.port_pause_limit = mv88e6097_port_pause_limit,
3420 3421
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3422
	.port_get_cmode = mv88e6352_port_get_cmode,
3423
	.port_set_cmode = mv88e6341_port_set_cmode,
3424
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3425
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3426
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3427 3428 3429
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
3430 3431
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3432 3433
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
3434
	.pot_clear = mv88e6xxx_g2_pot_clear,
3435
	.reset = mv88e6352_g1_reset,
3436
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3437
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3438 3439
	.serdes_power = mv88e6390_serdes_power,
	.serdes_get_lane = mv88e6341_serdes_get_lane,
3440 3441 3442 3443 3444
	/* 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,
3445
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3446
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
3447
	.serdes_irq_status = mv88e6390_serdes_irq_status,
3448
	.gpio_ops = &mv88e6352_gpio_ops,
3449
	.phylink_validate = mv88e6341_phylink_validate,
3450 3451
};

3452
static const struct mv88e6xxx_ops mv88e6161_ops = {
3453
	/* MV88E6XXX_FAMILY_6165 */
3454 3455
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3456
	.irl_init_all = mv88e6352_g2_irl_init_all,
3457
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3458 3459
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3460
	.port_set_link = mv88e6xxx_port_set_link,
3461
	.port_sync_link = mv88e6xxx_port_sync_link,
3462
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3463
	.port_tag_remap = mv88e6095_port_tag_remap,
3464
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3465
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3466
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3467
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3468
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3469
	.port_pause_limit = mv88e6097_port_pause_limit,
3470
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3471
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3472
	.port_get_cmode = mv88e6185_port_get_cmode,
3473
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3474
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3475
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3476 3477
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3478
	.stats_get_stats = mv88e6095_stats_get_stats,
3479 3480
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3481
	.watchdog_ops = &mv88e6097_watchdog_ops,
3482
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3483
	.pot_clear = mv88e6xxx_g2_pot_clear,
3484
	.reset = mv88e6352_g1_reset,
3485 3486
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3487
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3488
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3489
	.avb_ops = &mv88e6165_avb_ops,
3490
	.ptp_ops = &mv88e6165_ptp_ops,
3491
	.phylink_validate = mv88e6185_phylink_validate,
3492 3493 3494
};

static const struct mv88e6xxx_ops mv88e6165_ops = {
3495
	/* MV88E6XXX_FAMILY_6165 */
3496 3497
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3498
	.irl_init_all = mv88e6352_g2_irl_init_all,
3499
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3500 3501
	.phy_read = mv88e6165_phy_read,
	.phy_write = mv88e6165_phy_write,
3502
	.port_set_link = mv88e6xxx_port_set_link,
3503
	.port_sync_link = mv88e6xxx_port_sync_link,
3504
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3505
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3506
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3507
	.port_get_cmode = mv88e6185_port_get_cmode,
3508
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3509
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3510
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3511 3512
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3513
	.stats_get_stats = mv88e6095_stats_get_stats,
3514 3515
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3516
	.watchdog_ops = &mv88e6097_watchdog_ops,
3517
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3518
	.pot_clear = mv88e6xxx_g2_pot_clear,
3519
	.reset = mv88e6352_g1_reset,
3520 3521
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3522
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3523
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3524
	.avb_ops = &mv88e6165_avb_ops,
3525
	.ptp_ops = &mv88e6165_ptp_ops,
3526
	.phylink_validate = mv88e6185_phylink_validate,
3527 3528 3529
};

static const struct mv88e6xxx_ops mv88e6171_ops = {
3530
	/* MV88E6XXX_FAMILY_6351 */
3531 3532
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3533
	.irl_init_all = mv88e6352_g2_irl_init_all,
3534
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3535 3536
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3537
	.port_set_link = mv88e6xxx_port_set_link,
3538
	.port_sync_link = mv88e6xxx_port_sync_link,
3539
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3540
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3541
	.port_tag_remap = mv88e6095_port_tag_remap,
3542
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3543
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3544
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3545
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3546
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3547
	.port_pause_limit = mv88e6097_port_pause_limit,
3548
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3549
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3550
	.port_get_cmode = mv88e6352_port_get_cmode,
3551
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3552
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3553
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3554 3555
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3556
	.stats_get_stats = mv88e6095_stats_get_stats,
3557 3558
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3559
	.watchdog_ops = &mv88e6097_watchdog_ops,
3560
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3561
	.pot_clear = mv88e6xxx_g2_pot_clear,
3562
	.reset = mv88e6352_g1_reset,
3563 3564
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3565
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3566
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3567
	.phylink_validate = mv88e6185_phylink_validate,
3568 3569 3570
};

static const struct mv88e6xxx_ops mv88e6172_ops = {
3571
	/* MV88E6XXX_FAMILY_6352 */
3572 3573
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3574
	.irl_init_all = mv88e6352_g2_irl_init_all,
3575 3576
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3577
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3578 3579
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3580
	.port_set_link = mv88e6xxx_port_set_link,
3581
	.port_sync_link = mv88e6xxx_port_sync_link,
3582
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3583
	.port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
3584
	.port_tag_remap = mv88e6095_port_tag_remap,
3585
	.port_set_policy = mv88e6352_port_set_policy,
3586
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3587
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3588
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3589
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3590
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3591
	.port_pause_limit = mv88e6097_port_pause_limit,
3592
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3593
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3594
	.port_get_cmode = mv88e6352_port_get_cmode,
3595
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3596
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3597
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3598 3599
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3600
	.stats_get_stats = mv88e6095_stats_get_stats,
3601 3602
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3603
	.watchdog_ops = &mv88e6097_watchdog_ops,
3604
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3605
	.pot_clear = mv88e6xxx_g2_pot_clear,
3606
	.reset = mv88e6352_g1_reset,
3607
	.rmu_disable = mv88e6352_g1_rmu_disable,
3608 3609
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3610
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3611
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3612
	.serdes_get_lane = mv88e6352_serdes_get_lane,
3613 3614 3615 3616
	.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,
3617
	.serdes_power = mv88e6352_serdes_power,
3618 3619
	.serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
	.serdes_get_regs = mv88e6352_serdes_get_regs,
3620
	.gpio_ops = &mv88e6352_gpio_ops,
3621
	.phylink_validate = mv88e6352_phylink_validate,
3622 3623 3624
};

static const struct mv88e6xxx_ops mv88e6175_ops = {
3625
	/* MV88E6XXX_FAMILY_6351 */
3626 3627
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3628
	.irl_init_all = mv88e6352_g2_irl_init_all,
3629
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3630 3631
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3632
	.port_set_link = mv88e6xxx_port_set_link,
3633
	.port_sync_link = mv88e6xxx_port_sync_link,
3634
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3635
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3636
	.port_tag_remap = mv88e6095_port_tag_remap,
3637
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3638
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3639
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3640
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3641
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3642
	.port_pause_limit = mv88e6097_port_pause_limit,
3643
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3644
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3645
	.port_get_cmode = mv88e6352_port_get_cmode,
3646
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3647
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3648
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3649 3650
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3651
	.stats_get_stats = mv88e6095_stats_get_stats,
3652 3653
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3654
	.watchdog_ops = &mv88e6097_watchdog_ops,
3655
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3656
	.pot_clear = mv88e6xxx_g2_pot_clear,
3657
	.reset = mv88e6352_g1_reset,
3658 3659
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3660
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3661
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3662
	.phylink_validate = mv88e6185_phylink_validate,
3663 3664 3665
};

static const struct mv88e6xxx_ops mv88e6176_ops = {
3666
	/* MV88E6XXX_FAMILY_6352 */
3667 3668
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3669
	.irl_init_all = mv88e6352_g2_irl_init_all,
3670 3671
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3672
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3673 3674
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3675
	.port_set_link = mv88e6xxx_port_set_link,
3676
	.port_sync_link = mv88e6xxx_port_sync_link,
3677
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3678
	.port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
3679
	.port_tag_remap = mv88e6095_port_tag_remap,
3680
	.port_set_policy = mv88e6352_port_set_policy,
3681
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3682
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3683
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3684
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3685
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3686
	.port_pause_limit = mv88e6097_port_pause_limit,
3687
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3688
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3689
	.port_get_cmode = mv88e6352_port_get_cmode,
3690
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3691
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3692
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3693 3694
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3695
	.stats_get_stats = mv88e6095_stats_get_stats,
3696 3697
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3698
	.watchdog_ops = &mv88e6097_watchdog_ops,
3699
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3700
	.pot_clear = mv88e6xxx_g2_pot_clear,
3701
	.reset = mv88e6352_g1_reset,
3702
	.rmu_disable = mv88e6352_g1_rmu_disable,
3703 3704
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3705
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3706
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3707
	.serdes_get_lane = mv88e6352_serdes_get_lane,
3708 3709 3710 3711
	.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,
3712
	.serdes_power = mv88e6352_serdes_power,
3713
	.serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
3714
	.serdes_irq_enable = mv88e6352_serdes_irq_enable,
3715
	.serdes_irq_status = mv88e6352_serdes_irq_status,
3716 3717
	.serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
	.serdes_get_regs = mv88e6352_serdes_get_regs,
3718
	.gpio_ops = &mv88e6352_gpio_ops,
3719
	.phylink_validate = mv88e6352_phylink_validate,
3720 3721 3722
};

static const struct mv88e6xxx_ops mv88e6185_ops = {
3723
	/* MV88E6XXX_FAMILY_6185 */
3724 3725
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3726
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3727 3728
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3729
	.port_set_link = mv88e6xxx_port_set_link,
3730
	.port_sync_link = mv88e6185_port_sync_link,
3731
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3732
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
3733
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
3734
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
3735
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
3736
	.port_set_pause = mv88e6185_port_set_pause,
3737
	.port_get_cmode = mv88e6185_port_get_cmode,
3738
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3739
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3740
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3741 3742
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3743
	.stats_get_stats = mv88e6095_stats_get_stats,
3744 3745
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3746
	.watchdog_ops = &mv88e6097_watchdog_ops,
3747
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3748 3749 3750
	.serdes_power = mv88e6185_serdes_power,
	.serdes_get_lane = mv88e6185_serdes_get_lane,
	.serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
3751
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
3752 3753
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
3754
	.reset = mv88e6185_g1_reset,
3755
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3756
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3757
	.phylink_validate = mv88e6185_phylink_validate,
3758
	.set_max_frame_size = mv88e6185_g1_set_max_frame_size,
3759 3760
};

3761
static const struct mv88e6xxx_ops mv88e6190_ops = {
3762
	/* MV88E6XXX_FAMILY_6390 */
3763
	.setup_errata = mv88e6390_setup_errata,
3764
	.irl_init_all = mv88e6390_g2_irl_init_all,
3765 3766
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3767 3768 3769 3770
	.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,
3771
	.port_sync_link = mv88e6xxx_port_sync_link,
3772
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3773
	.port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
3774
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
3775
	.port_tag_remap = mv88e6390_port_tag_remap,
3776
	.port_set_policy = mv88e6352_port_set_policy,
3777
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3778
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3779
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3780
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3781
	.port_pause_limit = mv88e6390_port_pause_limit,
3782
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3783
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3784
	.port_get_cmode = mv88e6352_port_get_cmode,
3785
	.port_set_cmode = mv88e6390_port_set_cmode,
3786
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3787
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3788
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3789 3790
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3791
	.stats_get_stats = mv88e6390_stats_get_stats,
3792 3793
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3794
	.watchdog_ops = &mv88e6390_watchdog_ops,
3795
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3796
	.pot_clear = mv88e6xxx_g2_pot_clear,
3797
	.reset = mv88e6352_g1_reset,
3798
	.rmu_disable = mv88e6390_g1_rmu_disable,
3799 3800
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3801 3802
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3803
	.serdes_power = mv88e6390_serdes_power,
3804
	.serdes_get_lane = mv88e6390_serdes_get_lane,
3805 3806 3807 3808 3809
	/* 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,
3810
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3811
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
3812
	.serdes_irq_status = mv88e6390_serdes_irq_status,
3813 3814
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
3815 3816
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
3817
	.gpio_ops = &mv88e6352_gpio_ops,
3818
	.phylink_validate = mv88e6390_phylink_validate,
3819 3820 3821
};

static const struct mv88e6xxx_ops mv88e6190x_ops = {
3822
	/* MV88E6XXX_FAMILY_6390 */
3823
	.setup_errata = mv88e6390_setup_errata,
3824
	.irl_init_all = mv88e6390_g2_irl_init_all,
3825 3826
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3827 3828 3829 3830
	.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,
3831
	.port_sync_link = mv88e6xxx_port_sync_link,
3832
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3833
	.port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
3834
	.port_max_speed_mode = mv88e6390x_port_max_speed_mode,
3835
	.port_tag_remap = mv88e6390_port_tag_remap,
3836
	.port_set_policy = mv88e6352_port_set_policy,
3837
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3838
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3839
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3840
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3841
	.port_pause_limit = mv88e6390_port_pause_limit,
3842
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3843
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3844
	.port_get_cmode = mv88e6352_port_get_cmode,
3845
	.port_set_cmode = mv88e6390x_port_set_cmode,
3846
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3847
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3848
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3849 3850
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3851
	.stats_get_stats = mv88e6390_stats_get_stats,
3852 3853
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3854
	.watchdog_ops = &mv88e6390_watchdog_ops,
3855
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3856
	.pot_clear = mv88e6xxx_g2_pot_clear,
3857
	.reset = mv88e6352_g1_reset,
3858
	.rmu_disable = mv88e6390_g1_rmu_disable,
3859 3860
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3861 3862
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3863
	.serdes_power = mv88e6390_serdes_power,
3864
	.serdes_get_lane = mv88e6390x_serdes_get_lane,
3865 3866 3867 3868 3869
	/* 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,
3870
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3871
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
3872
	.serdes_irq_status = mv88e6390_serdes_irq_status,
3873 3874
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
3875 3876
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
3877
	.gpio_ops = &mv88e6352_gpio_ops,
3878
	.phylink_validate = mv88e6390x_phylink_validate,
3879 3880 3881
};

static const struct mv88e6xxx_ops mv88e6191_ops = {
3882
	/* MV88E6XXX_FAMILY_6390 */
3883
	.setup_errata = mv88e6390_setup_errata,
3884
	.irl_init_all = mv88e6390_g2_irl_init_all,
3885 3886
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3887 3888 3889 3890
	.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,
3891
	.port_sync_link = mv88e6xxx_port_sync_link,
3892
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3893
	.port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
3894
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
3895
	.port_tag_remap = mv88e6390_port_tag_remap,
3896
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3897
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3898
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3899
	.port_pause_limit = mv88e6390_port_pause_limit,
3900
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3901
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3902
	.port_get_cmode = mv88e6352_port_get_cmode,
3903
	.port_set_cmode = mv88e6390_port_set_cmode,
3904
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3905
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3906
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3907 3908
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3909
	.stats_get_stats = mv88e6390_stats_get_stats,
3910 3911
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3912
	.watchdog_ops = &mv88e6390_watchdog_ops,
3913
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3914
	.pot_clear = mv88e6xxx_g2_pot_clear,
3915
	.reset = mv88e6352_g1_reset,
3916
	.rmu_disable = mv88e6390_g1_rmu_disable,
3917 3918
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3919 3920
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3921
	.serdes_power = mv88e6390_serdes_power,
3922
	.serdes_get_lane = mv88e6390_serdes_get_lane,
3923 3924 3925 3926 3927
	/* 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,
3928
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3929
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
3930
	.serdes_irq_status = mv88e6390_serdes_irq_status,
3931 3932
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
3933 3934
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
3935 3936
	.avb_ops = &mv88e6390_avb_ops,
	.ptp_ops = &mv88e6352_ptp_ops,
3937
	.phylink_validate = mv88e6390_phylink_validate,
3938 3939
};

3940
static const struct mv88e6xxx_ops mv88e6240_ops = {
3941
	/* MV88E6XXX_FAMILY_6352 */
3942 3943
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3944
	.irl_init_all = mv88e6352_g2_irl_init_all,
3945 3946
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3947
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3948 3949
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3950
	.port_set_link = mv88e6xxx_port_set_link,
3951
	.port_sync_link = mv88e6xxx_port_sync_link,
3952
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3953
	.port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
3954
	.port_tag_remap = mv88e6095_port_tag_remap,
3955
	.port_set_policy = mv88e6352_port_set_policy,
3956
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3957
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3958
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3959
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3960
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3961
	.port_pause_limit = mv88e6097_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_setup_message_port = mv88e6xxx_setup_message_port,
3966
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3967
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3968 3969
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3970
	.stats_get_stats = mv88e6095_stats_get_stats,
3971 3972
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3973
	.watchdog_ops = &mv88e6097_watchdog_ops,
3974
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3975
	.pot_clear = mv88e6xxx_g2_pot_clear,
3976
	.reset = mv88e6352_g1_reset,
3977
	.rmu_disable = mv88e6352_g1_rmu_disable,
3978 3979
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3980
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3981
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3982
	.serdes_get_lane = mv88e6352_serdes_get_lane,
3983 3984 3985 3986
	.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,
3987
	.serdes_power = mv88e6352_serdes_power,
3988
	.serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
3989
	.serdes_irq_enable = mv88e6352_serdes_irq_enable,
3990
	.serdes_irq_status = mv88e6352_serdes_irq_status,
3991 3992
	.serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
	.serdes_get_regs = mv88e6352_serdes_get_regs,
3993
	.gpio_ops = &mv88e6352_gpio_ops,
3994
	.avb_ops = &mv88e6352_avb_ops,
3995
	.ptp_ops = &mv88e6352_ptp_ops,
3996
	.phylink_validate = mv88e6352_phylink_validate,
3997 3998
};

3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009
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,
4010
	.port_sync_link = mv88e6xxx_port_sync_link,
4011
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4012
	.port_set_speed_duplex = mv88e6250_port_set_speed_duplex,
4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032
	.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,
4033 4034
	.avb_ops = &mv88e6352_avb_ops,
	.ptp_ops = &mv88e6250_ptp_ops,
4035 4036 4037
	.phylink_validate = mv88e6065_phylink_validate,
};

4038
static const struct mv88e6xxx_ops mv88e6290_ops = {
4039
	/* MV88E6XXX_FAMILY_6390 */
4040
	.setup_errata = mv88e6390_setup_errata,
4041
	.irl_init_all = mv88e6390_g2_irl_init_all,
4042 4043
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4044 4045 4046 4047
	.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,
4048
	.port_sync_link = mv88e6xxx_port_sync_link,
4049
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4050
	.port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
4051
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
4052
	.port_tag_remap = mv88e6390_port_tag_remap,
4053
	.port_set_policy = mv88e6352_port_set_policy,
4054
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4055
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4056
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4057
	.port_pause_limit = mv88e6390_port_pause_limit,
4058
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4059
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4060
	.port_get_cmode = mv88e6352_port_get_cmode,
4061
	.port_set_cmode = mv88e6390_port_set_cmode,
4062
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4063
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4064
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4065 4066
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4067
	.stats_get_stats = mv88e6390_stats_get_stats,
4068 4069
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4070
	.watchdog_ops = &mv88e6390_watchdog_ops,
4071
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4072
	.pot_clear = mv88e6xxx_g2_pot_clear,
4073
	.reset = mv88e6352_g1_reset,
4074
	.rmu_disable = mv88e6390_g1_rmu_disable,
4075 4076
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4077 4078
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4079
	.serdes_power = mv88e6390_serdes_power,
4080
	.serdes_get_lane = mv88e6390_serdes_get_lane,
4081 4082 4083 4084 4085
	/* 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,
4086
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4087
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4088
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4089 4090
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
4091 4092
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
4093
	.gpio_ops = &mv88e6352_gpio_ops,
4094
	.avb_ops = &mv88e6390_avb_ops,
4095
	.ptp_ops = &mv88e6352_ptp_ops,
4096
	.phylink_validate = mv88e6390_phylink_validate,
4097 4098
};

4099
static const struct mv88e6xxx_ops mv88e6320_ops = {
4100
	/* MV88E6XXX_FAMILY_6320 */
4101 4102
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4103
	.irl_init_all = mv88e6352_g2_irl_init_all,
4104 4105
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
4106
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4107 4108
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4109
	.port_set_link = mv88e6xxx_port_set_link,
4110
	.port_sync_link = mv88e6xxx_port_sync_link,
4111
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4112
	.port_tag_remap = mv88e6095_port_tag_remap,
4113
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4114
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4115
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4116
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4117
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4118
	.port_pause_limit = mv88e6097_port_pause_limit,
4119
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4120
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4121
	.port_get_cmode = mv88e6352_port_get_cmode,
4122
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4123
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4124
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4125 4126
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4127
	.stats_get_stats = mv88e6320_stats_get_stats,
4128 4129
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4130
	.watchdog_ops = &mv88e6390_watchdog_ops,
4131
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4132
	.pot_clear = mv88e6xxx_g2_pot_clear,
4133
	.reset = mv88e6352_g1_reset,
4134
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
4135
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
4136
	.gpio_ops = &mv88e6352_gpio_ops,
4137
	.avb_ops = &mv88e6352_avb_ops,
4138
	.ptp_ops = &mv88e6352_ptp_ops,
4139
	.phylink_validate = mv88e6185_phylink_validate,
4140 4141 4142
};

static const struct mv88e6xxx_ops mv88e6321_ops = {
4143
	/* MV88E6XXX_FAMILY_6320 */
4144 4145
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4146
	.irl_init_all = mv88e6352_g2_irl_init_all,
4147 4148
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
4149
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4150 4151
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4152
	.port_set_link = mv88e6xxx_port_set_link,
4153
	.port_sync_link = mv88e6xxx_port_sync_link,
4154
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4155
	.port_tag_remap = mv88e6095_port_tag_remap,
4156
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4157
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4158
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4159
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4160
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4161
	.port_pause_limit = mv88e6097_port_pause_limit,
4162
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4163
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4164
	.port_get_cmode = mv88e6352_port_get_cmode,
4165
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4166
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4167
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4168 4169
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4170
	.stats_get_stats = mv88e6320_stats_get_stats,
4171 4172
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4173
	.watchdog_ops = &mv88e6390_watchdog_ops,
4174
	.reset = mv88e6352_g1_reset,
4175
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
4176
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
4177
	.gpio_ops = &mv88e6352_gpio_ops,
4178
	.avb_ops = &mv88e6352_avb_ops,
4179
	.ptp_ops = &mv88e6352_ptp_ops,
4180
	.phylink_validate = mv88e6185_phylink_validate,
4181 4182
};

4183 4184
static const struct mv88e6xxx_ops mv88e6341_ops = {
	/* MV88E6XXX_FAMILY_6341 */
4185 4186
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4187
	.irl_init_all = mv88e6352_g2_irl_init_all,
4188 4189 4190 4191 4192 4193
	.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,
4194
	.port_sync_link = mv88e6xxx_port_sync_link,
4195
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4196
	.port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
4197
	.port_max_speed_mode = mv88e6341_port_max_speed_mode,
4198 4199 4200 4201
	.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,
4202
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4203
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4204
	.port_pause_limit = mv88e6097_port_pause_limit,
4205 4206
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4207
	.port_get_cmode = mv88e6352_port_get_cmode,
4208
	.port_set_cmode = mv88e6341_port_set_cmode,
4209
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4210
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4211
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4212 4213 4214
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
4215 4216
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4217 4218
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
4219
	.pot_clear = mv88e6xxx_g2_pot_clear,
4220
	.reset = mv88e6352_g1_reset,
4221
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4222
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4223 4224
	.serdes_power = mv88e6390_serdes_power,
	.serdes_get_lane = mv88e6341_serdes_get_lane,
4225 4226 4227 4228 4229
	/* 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,
4230
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4231
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4232
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4233
	.gpio_ops = &mv88e6352_gpio_ops,
4234
	.avb_ops = &mv88e6390_avb_ops,
4235
	.ptp_ops = &mv88e6352_ptp_ops,
4236
	.phylink_validate = mv88e6341_phylink_validate,
4237 4238
};

4239
static const struct mv88e6xxx_ops mv88e6350_ops = {
4240
	/* MV88E6XXX_FAMILY_6351 */
4241 4242
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4243
	.irl_init_all = mv88e6352_g2_irl_init_all,
4244
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4245 4246
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4247
	.port_set_link = mv88e6xxx_port_set_link,
4248
	.port_sync_link = mv88e6xxx_port_sync_link,
4249
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4250
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4251
	.port_tag_remap = mv88e6095_port_tag_remap,
4252
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4253
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4254
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4255
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4256
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4257
	.port_pause_limit = mv88e6097_port_pause_limit,
4258
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4259
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4260
	.port_get_cmode = mv88e6352_port_get_cmode,
4261
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4262
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4263
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4264 4265
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
4266
	.stats_get_stats = mv88e6095_stats_get_stats,
4267 4268
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4269
	.watchdog_ops = &mv88e6097_watchdog_ops,
4270
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4271
	.pot_clear = mv88e6xxx_g2_pot_clear,
4272
	.reset = mv88e6352_g1_reset,
4273 4274
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4275
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4276
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4277
	.phylink_validate = mv88e6185_phylink_validate,
4278 4279 4280
};

static const struct mv88e6xxx_ops mv88e6351_ops = {
4281
	/* MV88E6XXX_FAMILY_6351 */
4282 4283
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4284
	.irl_init_all = mv88e6352_g2_irl_init_all,
4285
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4286 4287
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4288
	.port_set_link = mv88e6xxx_port_set_link,
4289
	.port_sync_link = mv88e6xxx_port_sync_link,
4290
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4291
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4292
	.port_tag_remap = mv88e6095_port_tag_remap,
4293
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4294
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4295
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4296
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4297
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4298
	.port_pause_limit = mv88e6097_port_pause_limit,
4299
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4300
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4301
	.port_get_cmode = mv88e6352_port_get_cmode,
4302
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4303
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4304
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4305 4306
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
4307
	.stats_get_stats = mv88e6095_stats_get_stats,
4308 4309
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4310
	.watchdog_ops = &mv88e6097_watchdog_ops,
4311
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4312
	.pot_clear = mv88e6xxx_g2_pot_clear,
4313
	.reset = mv88e6352_g1_reset,
4314 4315
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4316
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4317
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4318
	.avb_ops = &mv88e6352_avb_ops,
4319
	.ptp_ops = &mv88e6352_ptp_ops,
4320
	.phylink_validate = mv88e6185_phylink_validate,
4321 4322 4323
};

static const struct mv88e6xxx_ops mv88e6352_ops = {
4324
	/* MV88E6XXX_FAMILY_6352 */
4325 4326
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4327
	.irl_init_all = mv88e6352_g2_irl_init_all,
4328 4329
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
4330
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4331 4332
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4333
	.port_set_link = mv88e6xxx_port_set_link,
4334
	.port_sync_link = mv88e6xxx_port_sync_link,
4335
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4336
	.port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
4337
	.port_tag_remap = mv88e6095_port_tag_remap,
4338
	.port_set_policy = mv88e6352_port_set_policy,
4339
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4340
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4341
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4342
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4343
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4344
	.port_pause_limit = mv88e6097_port_pause_limit,
4345
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4346
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4347
	.port_get_cmode = mv88e6352_port_get_cmode,
4348
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4349
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4350
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4351 4352
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
4353
	.stats_get_stats = mv88e6095_stats_get_stats,
4354 4355
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4356
	.watchdog_ops = &mv88e6097_watchdog_ops,
4357
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4358
	.pot_clear = mv88e6xxx_g2_pot_clear,
4359
	.reset = mv88e6352_g1_reset,
4360
	.rmu_disable = mv88e6352_g1_rmu_disable,
4361 4362
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4363
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4364
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4365
	.serdes_get_lane = mv88e6352_serdes_get_lane,
4366 4367 4368 4369
	.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,
4370
	.serdes_power = mv88e6352_serdes_power,
4371
	.serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
4372
	.serdes_irq_enable = mv88e6352_serdes_irq_enable,
4373
	.serdes_irq_status = mv88e6352_serdes_irq_status,
4374
	.gpio_ops = &mv88e6352_gpio_ops,
4375
	.avb_ops = &mv88e6352_avb_ops,
4376
	.ptp_ops = &mv88e6352_ptp_ops,
4377 4378 4379
	.serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
	.serdes_get_strings = mv88e6352_serdes_get_strings,
	.serdes_get_stats = mv88e6352_serdes_get_stats,
4380 4381
	.serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
	.serdes_get_regs = mv88e6352_serdes_get_regs,
4382
	.phylink_validate = mv88e6352_phylink_validate,
4383 4384
};

4385
static const struct mv88e6xxx_ops mv88e6390_ops = {
4386
	/* MV88E6XXX_FAMILY_6390 */
4387
	.setup_errata = mv88e6390_setup_errata,
4388
	.irl_init_all = mv88e6390_g2_irl_init_all,
4389 4390
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4391 4392 4393 4394
	.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,
4395
	.port_sync_link = mv88e6xxx_port_sync_link,
4396
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4397
	.port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
4398
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
4399
	.port_tag_remap = mv88e6390_port_tag_remap,
4400
	.port_set_policy = mv88e6352_port_set_policy,
4401
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4402
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4403
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4404
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4405
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4406
	.port_pause_limit = mv88e6390_port_pause_limit,
4407
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4408
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4409
	.port_get_cmode = mv88e6352_port_get_cmode,
4410
	.port_set_cmode = mv88e6390_port_set_cmode,
4411
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4412
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4413
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4414 4415
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4416
	.stats_get_stats = mv88e6390_stats_get_stats,
4417 4418
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4419
	.watchdog_ops = &mv88e6390_watchdog_ops,
4420
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4421
	.pot_clear = mv88e6xxx_g2_pot_clear,
4422
	.reset = mv88e6352_g1_reset,
4423
	.rmu_disable = mv88e6390_g1_rmu_disable,
4424 4425
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4426 4427
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4428
	.serdes_power = mv88e6390_serdes_power,
4429
	.serdes_get_lane = mv88e6390_serdes_get_lane,
4430 4431 4432 4433 4434
	/* 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,
4435
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4436
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4437
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4438
	.gpio_ops = &mv88e6352_gpio_ops,
4439
	.avb_ops = &mv88e6390_avb_ops,
4440
	.ptp_ops = &mv88e6352_ptp_ops,
4441 4442 4443
	.serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
4444 4445
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
4446
	.phylink_validate = mv88e6390_phylink_validate,
4447 4448 4449
};

static const struct mv88e6xxx_ops mv88e6390x_ops = {
4450
	/* MV88E6XXX_FAMILY_6390 */
4451
	.setup_errata = mv88e6390_setup_errata,
4452
	.irl_init_all = mv88e6390_g2_irl_init_all,
4453 4454
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4455 4456 4457 4458
	.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,
4459
	.port_sync_link = mv88e6xxx_port_sync_link,
4460
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4461
	.port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
4462
	.port_max_speed_mode = mv88e6390x_port_max_speed_mode,
4463
	.port_tag_remap = mv88e6390_port_tag_remap,
4464
	.port_set_policy = mv88e6352_port_set_policy,
4465
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4466
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
4467
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4468
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4469
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4470
	.port_pause_limit = mv88e6390_port_pause_limit,
4471
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4472
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4473
	.port_get_cmode = mv88e6352_port_get_cmode,
4474
	.port_set_cmode = mv88e6390x_port_set_cmode,
4475
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4476
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4477
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4478 4479
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4480
	.stats_get_stats = mv88e6390_stats_get_stats,
4481 4482
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4483
	.watchdog_ops = &mv88e6390_watchdog_ops,
4484
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4485
	.pot_clear = mv88e6xxx_g2_pot_clear,
4486
	.reset = mv88e6352_g1_reset,
4487
	.rmu_disable = mv88e6390_g1_rmu_disable,
4488 4489
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4490 4491
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4492
	.serdes_power = mv88e6390_serdes_power,
4493
	.serdes_get_lane = mv88e6390x_serdes_get_lane,
4494 4495 4496 4497
	.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,
4498
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4499
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4500
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4501 4502 4503
	.serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
4504 4505
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
4506
	.gpio_ops = &mv88e6352_gpio_ops,
4507
	.avb_ops = &mv88e6390_avb_ops,
4508
	.ptp_ops = &mv88e6352_ptp_ops,
4509
	.phylink_validate = mv88e6390x_phylink_validate,
4510 4511
};

4512 4513
static const struct mv88e6xxx_info mv88e6xxx_table[] = {
	[MV88E6085] = {
4514
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
4515 4516 4517
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6085",
		.num_databases = 4096,
4518
		.num_macs = 8192,
4519
		.num_ports = 10,
4520
		.num_internal_phys = 5,
4521
		.max_vid = 4095,
4522
		.port_base_addr = 0x10,
4523
		.phy_base_addr = 0x0,
4524
		.global1_addr = 0x1b,
4525
		.global2_addr = 0x1c,
4526
		.age_time_coeff = 15000,
4527
		.g1_irqs = 8,
4528
		.g2_irqs = 10,
4529
		.atu_move_port_mask = 0xf,
4530
		.pvt = true,
4531
		.multi_chip = true,
4532
		.tag_protocol = DSA_TAG_PROTO_DSA,
4533
		.ops = &mv88e6085_ops,
4534 4535 4536
	},

	[MV88E6095] = {
4537
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
4538 4539 4540
		.family = MV88E6XXX_FAMILY_6095,
		.name = "Marvell 88E6095/88E6095F",
		.num_databases = 256,
4541
		.num_macs = 8192,
4542
		.num_ports = 11,
4543
		.num_internal_phys = 0,
4544
		.max_vid = 4095,
4545
		.port_base_addr = 0x10,
4546
		.phy_base_addr = 0x0,
4547
		.global1_addr = 0x1b,
4548
		.global2_addr = 0x1c,
4549
		.age_time_coeff = 15000,
4550
		.g1_irqs = 8,
4551
		.atu_move_port_mask = 0xf,
4552
		.multi_chip = true,
4553
		.tag_protocol = DSA_TAG_PROTO_DSA,
4554
		.ops = &mv88e6095_ops,
4555 4556
	},

4557
	[MV88E6097] = {
4558
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
4559 4560 4561
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6097/88E6097F",
		.num_databases = 4096,
4562
		.num_macs = 8192,
4563
		.num_ports = 11,
4564
		.num_internal_phys = 8,
4565
		.max_vid = 4095,
4566
		.port_base_addr = 0x10,
4567
		.phy_base_addr = 0x0,
4568
		.global1_addr = 0x1b,
4569
		.global2_addr = 0x1c,
4570
		.age_time_coeff = 15000,
4571
		.g1_irqs = 8,
4572
		.g2_irqs = 10,
4573
		.atu_move_port_mask = 0xf,
4574
		.pvt = true,
4575
		.multi_chip = true,
4576
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4577 4578 4579
		.ops = &mv88e6097_ops,
	},

4580
	[MV88E6123] = {
4581
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
4582 4583 4584
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6123",
		.num_databases = 4096,
4585
		.num_macs = 1024,
4586
		.num_ports = 3,
4587
		.num_internal_phys = 5,
4588
		.max_vid = 4095,
4589
		.port_base_addr = 0x10,
4590
		.phy_base_addr = 0x0,
4591
		.global1_addr = 0x1b,
4592
		.global2_addr = 0x1c,
4593
		.age_time_coeff = 15000,
4594
		.g1_irqs = 9,
4595
		.g2_irqs = 10,
4596
		.atu_move_port_mask = 0xf,
4597
		.pvt = true,
4598
		.multi_chip = true,
4599
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4600
		.ops = &mv88e6123_ops,
4601 4602 4603
	},

	[MV88E6131] = {
4604
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
4605 4606 4607
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6131",
		.num_databases = 256,
4608
		.num_macs = 8192,
4609
		.num_ports = 8,
4610
		.num_internal_phys = 0,
4611
		.max_vid = 4095,
4612
		.port_base_addr = 0x10,
4613
		.phy_base_addr = 0x0,
4614
		.global1_addr = 0x1b,
4615
		.global2_addr = 0x1c,
4616
		.age_time_coeff = 15000,
4617
		.g1_irqs = 9,
4618
		.atu_move_port_mask = 0xf,
4619
		.multi_chip = true,
4620
		.tag_protocol = DSA_TAG_PROTO_DSA,
4621
		.ops = &mv88e6131_ops,
4622 4623
	},

4624
	[MV88E6141] = {
4625
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
4626
		.family = MV88E6XXX_FAMILY_6341,
4627
		.name = "Marvell 88E6141",
4628
		.num_databases = 4096,
4629
		.num_macs = 2048,
4630
		.num_ports = 6,
4631
		.num_internal_phys = 5,
4632
		.num_gpio = 11,
4633
		.max_vid = 4095,
4634
		.port_base_addr = 0x10,
4635
		.phy_base_addr = 0x10,
4636
		.global1_addr = 0x1b,
4637
		.global2_addr = 0x1c,
4638 4639
		.age_time_coeff = 3750,
		.atu_move_port_mask = 0x1f,
4640
		.g1_irqs = 9,
4641
		.g2_irqs = 10,
4642
		.pvt = true,
4643
		.multi_chip = true,
4644 4645 4646 4647
		.tag_protocol = DSA_TAG_PROTO_EDSA,
		.ops = &mv88e6141_ops,
	},

4648
	[MV88E6161] = {
4649
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
4650 4651 4652
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6161",
		.num_databases = 4096,
4653
		.num_macs = 1024,
4654
		.num_ports = 6,
4655
		.num_internal_phys = 5,
4656
		.max_vid = 4095,
4657
		.port_base_addr = 0x10,
4658
		.phy_base_addr = 0x0,
4659
		.global1_addr = 0x1b,
4660
		.global2_addr = 0x1c,
4661
		.age_time_coeff = 15000,
4662
		.g1_irqs = 9,
4663
		.g2_irqs = 10,
4664
		.atu_move_port_mask = 0xf,
4665
		.pvt = true,
4666
		.multi_chip = true,
4667
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4668
		.ptp_support = true,
4669
		.ops = &mv88e6161_ops,
4670 4671 4672
	},

	[MV88E6165] = {
4673
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
4674 4675 4676
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6165",
		.num_databases = 4096,
4677
		.num_macs = 8192,
4678
		.num_ports = 6,
4679
		.num_internal_phys = 0,
4680
		.max_vid = 4095,
4681
		.port_base_addr = 0x10,
4682
		.phy_base_addr = 0x0,
4683
		.global1_addr = 0x1b,
4684
		.global2_addr = 0x1c,
4685
		.age_time_coeff = 15000,
4686
		.g1_irqs = 9,
4687
		.g2_irqs = 10,
4688
		.atu_move_port_mask = 0xf,
4689
		.pvt = true,
4690
		.multi_chip = true,
4691
		.tag_protocol = DSA_TAG_PROTO_DSA,
4692
		.ptp_support = true,
4693
		.ops = &mv88e6165_ops,
4694 4695 4696
	},

	[MV88E6171] = {
4697
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
4698 4699 4700
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6171",
		.num_databases = 4096,
4701
		.num_macs = 8192,
4702
		.num_ports = 7,
4703
		.num_internal_phys = 5,
4704
		.max_vid = 4095,
4705
		.port_base_addr = 0x10,
4706
		.phy_base_addr = 0x0,
4707
		.global1_addr = 0x1b,
4708
		.global2_addr = 0x1c,
4709
		.age_time_coeff = 15000,
4710
		.g1_irqs = 9,
4711
		.g2_irqs = 10,
4712
		.atu_move_port_mask = 0xf,
4713
		.pvt = true,
4714
		.multi_chip = true,
4715
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4716
		.ops = &mv88e6171_ops,
4717 4718 4719
	},

	[MV88E6172] = {
4720
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
4721 4722 4723
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6172",
		.num_databases = 4096,
4724
		.num_macs = 8192,
4725
		.num_ports = 7,
4726
		.num_internal_phys = 5,
4727
		.num_gpio = 15,
4728
		.max_vid = 4095,
4729
		.port_base_addr = 0x10,
4730
		.phy_base_addr = 0x0,
4731
		.global1_addr = 0x1b,
4732
		.global2_addr = 0x1c,
4733
		.age_time_coeff = 15000,
4734
		.g1_irqs = 9,
4735
		.g2_irqs = 10,
4736
		.atu_move_port_mask = 0xf,
4737
		.pvt = true,
4738
		.multi_chip = true,
4739
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4740
		.ops = &mv88e6172_ops,
4741 4742 4743
	},

	[MV88E6175] = {
4744
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
4745 4746 4747
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6175",
		.num_databases = 4096,
4748
		.num_macs = 8192,
4749
		.num_ports = 7,
4750
		.num_internal_phys = 5,
4751
		.max_vid = 4095,
4752
		.port_base_addr = 0x10,
4753
		.phy_base_addr = 0x0,
4754
		.global1_addr = 0x1b,
4755
		.global2_addr = 0x1c,
4756
		.age_time_coeff = 15000,
4757
		.g1_irqs = 9,
4758
		.g2_irqs = 10,
4759
		.atu_move_port_mask = 0xf,
4760
		.pvt = true,
4761
		.multi_chip = true,
4762
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4763
		.ops = &mv88e6175_ops,
4764 4765 4766
	},

	[MV88E6176] = {
4767
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
4768 4769 4770
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6176",
		.num_databases = 4096,
4771
		.num_macs = 8192,
4772
		.num_ports = 7,
4773
		.num_internal_phys = 5,
4774
		.num_gpio = 15,
4775
		.max_vid = 4095,
4776
		.port_base_addr = 0x10,
4777
		.phy_base_addr = 0x0,
4778
		.global1_addr = 0x1b,
4779
		.global2_addr = 0x1c,
4780
		.age_time_coeff = 15000,
4781
		.g1_irqs = 9,
4782
		.g2_irqs = 10,
4783
		.atu_move_port_mask = 0xf,
4784
		.pvt = true,
4785
		.multi_chip = true,
4786
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4787
		.ops = &mv88e6176_ops,
4788 4789 4790
	},

	[MV88E6185] = {
4791
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
4792 4793 4794
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6185",
		.num_databases = 256,
4795
		.num_macs = 8192,
4796
		.num_ports = 10,
4797
		.num_internal_phys = 0,
4798
		.max_vid = 4095,
4799
		.port_base_addr = 0x10,
4800
		.phy_base_addr = 0x0,
4801
		.global1_addr = 0x1b,
4802
		.global2_addr = 0x1c,
4803
		.age_time_coeff = 15000,
4804
		.g1_irqs = 8,
4805
		.atu_move_port_mask = 0xf,
4806
		.multi_chip = true,
4807
		.tag_protocol = DSA_TAG_PROTO_EDSA,
4808
		.ops = &mv88e6185_ops,
4809 4810
	},

4811
	[MV88E6190] = {
4812
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
4813 4814 4815
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190",
		.num_databases = 4096,
4816
		.num_macs = 16384,
4817
		.num_ports = 11,	/* 10 + Z80 */
4818
		.num_internal_phys = 9,
4819
		.num_gpio = 16,
4820
		.max_vid = 8191,
4821
		.port_base_addr = 0x0,
4822
		.phy_base_addr = 0x0,
4823
		.global1_addr = 0x1b,
4824
		.global2_addr = 0x1c,
4825
		.tag_protocol = DSA_TAG_PROTO_DSA,
4826
		.age_time_coeff = 3750,
4827
		.g1_irqs = 9,
4828
		.g2_irqs = 14,
4829
		.pvt = true,
4830
		.multi_chip = true,
4831
		.atu_move_port_mask = 0x1f,
4832 4833 4834 4835
		.ops = &mv88e6190_ops,
	},

	[MV88E6190X] = {
4836
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
4837 4838 4839
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190X",
		.num_databases = 4096,
4840
		.num_macs = 16384,
4841
		.num_ports = 11,	/* 10 + Z80 */
4842
		.num_internal_phys = 9,
4843
		.num_gpio = 16,
4844
		.max_vid = 8191,
4845
		.port_base_addr = 0x0,
4846
		.phy_base_addr = 0x0,
4847
		.global1_addr = 0x1b,
4848
		.global2_addr = 0x1c,
4849
		.age_time_coeff = 3750,
4850
		.g1_irqs = 9,
4851
		.g2_irqs = 14,
4852
		.atu_move_port_mask = 0x1f,
4853
		.pvt = true,
4854
		.multi_chip = true,
4855
		.tag_protocol = DSA_TAG_PROTO_DSA,
4856 4857 4858 4859
		.ops = &mv88e6190x_ops,
	},

	[MV88E6191] = {
4860
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
4861 4862 4863
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6191",
		.num_databases = 4096,
4864
		.num_macs = 16384,
4865
		.num_ports = 11,	/* 10 + Z80 */
4866
		.num_internal_phys = 9,
4867
		.max_vid = 8191,
4868
		.port_base_addr = 0x0,
4869
		.phy_base_addr = 0x0,
4870
		.global1_addr = 0x1b,
4871
		.global2_addr = 0x1c,
4872
		.age_time_coeff = 3750,
4873
		.g1_irqs = 9,
4874
		.g2_irqs = 14,
4875
		.atu_move_port_mask = 0x1f,
4876
		.pvt = true,
4877
		.multi_chip = true,
4878
		.tag_protocol = DSA_TAG_PROTO_DSA,
4879
		.ptp_support = true,
4880
		.ops = &mv88e6191_ops,
4881 4882
	},

4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893
	[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,
4894
		.invalid_port_mask = BIT(2) | BIT(3) | BIT(4),
4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905
		.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,
4906
		.ptp_support = true,
4907 4908 4909
		.ops = &mv88e6250_ops,
	},

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

4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952
	[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,
4953
		.ptp_support = true,
4954 4955 4956
		.ops = &mv88e6250_ops,
	},

4957
	[MV88E6290] = {
4958
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
4959 4960 4961 4962
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6290",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
4963
		.num_internal_phys = 9,
4964
		.num_gpio = 16,
4965
		.max_vid = 8191,
4966
		.port_base_addr = 0x0,
4967
		.phy_base_addr = 0x0,
4968
		.global1_addr = 0x1b,
4969
		.global2_addr = 0x1c,
4970
		.age_time_coeff = 3750,
4971
		.g1_irqs = 9,
4972
		.g2_irqs = 14,
4973
		.atu_move_port_mask = 0x1f,
4974
		.pvt = true,
4975
		.multi_chip = true,
4976
		.tag_protocol = DSA_TAG_PROTO_DSA,
4977
		.ptp_support = true,
4978 4979 4980
		.ops = &mv88e6290_ops,
	},

4981
	[MV88E6320] = {
4982
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
4983 4984 4985
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6320",
		.num_databases = 4096,
4986
		.num_macs = 8192,
4987
		.num_ports = 7,
4988
		.num_internal_phys = 5,
4989
		.num_gpio = 15,
4990
		.max_vid = 4095,
4991
		.port_base_addr = 0x10,
4992
		.phy_base_addr = 0x0,
4993
		.global1_addr = 0x1b,
4994
		.global2_addr = 0x1c,
4995
		.age_time_coeff = 15000,
4996
		.g1_irqs = 8,
4997
		.g2_irqs = 10,
4998
		.atu_move_port_mask = 0xf,
4999
		.pvt = true,
5000
		.multi_chip = true,
5001
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5002
		.ptp_support = true,
5003
		.ops = &mv88e6320_ops,
5004 5005 5006
	},

	[MV88E6321] = {
5007
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
5008 5009 5010
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6321",
		.num_databases = 4096,
5011
		.num_macs = 8192,
5012
		.num_ports = 7,
5013
		.num_internal_phys = 5,
5014
		.num_gpio = 15,
5015
		.max_vid = 4095,
5016
		.port_base_addr = 0x10,
5017
		.phy_base_addr = 0x0,
5018
		.global1_addr = 0x1b,
5019
		.global2_addr = 0x1c,
5020
		.age_time_coeff = 15000,
5021
		.g1_irqs = 8,
5022
		.g2_irqs = 10,
5023
		.atu_move_port_mask = 0xf,
5024
		.multi_chip = true,
5025
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5026
		.ptp_support = true,
5027
		.ops = &mv88e6321_ops,
5028 5029
	},

5030
	[MV88E6341] = {
5031
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
5032 5033 5034
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
5035
		.num_macs = 2048,
5036
		.num_internal_phys = 5,
5037
		.num_ports = 6,
5038
		.num_gpio = 11,
5039
		.max_vid = 4095,
5040
		.port_base_addr = 0x10,
5041
		.phy_base_addr = 0x10,
5042
		.global1_addr = 0x1b,
5043
		.global2_addr = 0x1c,
5044
		.age_time_coeff = 3750,
5045
		.atu_move_port_mask = 0x1f,
5046
		.g1_irqs = 9,
5047
		.g2_irqs = 10,
5048
		.pvt = true,
5049
		.multi_chip = true,
5050
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5051
		.ptp_support = true,
5052 5053 5054
		.ops = &mv88e6341_ops,
	},

5055
	[MV88E6350] = {
5056
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
5057 5058 5059
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6350",
		.num_databases = 4096,
5060
		.num_macs = 8192,
5061
		.num_ports = 7,
5062
		.num_internal_phys = 5,
5063
		.max_vid = 4095,
5064
		.port_base_addr = 0x10,
5065
		.phy_base_addr = 0x0,
5066
		.global1_addr = 0x1b,
5067
		.global2_addr = 0x1c,
5068
		.age_time_coeff = 15000,
5069
		.g1_irqs = 9,
5070
		.g2_irqs = 10,
5071
		.atu_move_port_mask = 0xf,
5072
		.pvt = true,
5073
		.multi_chip = true,
5074
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5075
		.ops = &mv88e6350_ops,
5076 5077 5078
	},

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

	[MV88E6352] = {
5102
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
5103 5104 5105
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6352",
		.num_databases = 4096,
5106
		.num_macs = 8192,
5107
		.num_ports = 7,
5108
		.num_internal_phys = 5,
5109
		.num_gpio = 15,
5110
		.max_vid = 4095,
5111
		.port_base_addr = 0x10,
5112
		.phy_base_addr = 0x0,
5113
		.global1_addr = 0x1b,
5114
		.global2_addr = 0x1c,
5115
		.age_time_coeff = 15000,
5116
		.g1_irqs = 9,
5117
		.g2_irqs = 10,
5118
		.atu_move_port_mask = 0xf,
5119
		.pvt = true,
5120
		.multi_chip = true,
5121
		.tag_protocol = DSA_TAG_PROTO_EDSA,
5122
		.ptp_support = true,
5123
		.ops = &mv88e6352_ops,
5124
	},
5125
	[MV88E6390] = {
5126
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
5127 5128 5129
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390",
		.num_databases = 4096,
5130
		.num_macs = 16384,
5131
		.num_ports = 11,	/* 10 + Z80 */
5132
		.num_internal_phys = 9,
5133
		.num_gpio = 16,
5134
		.max_vid = 8191,
5135
		.port_base_addr = 0x0,
5136
		.phy_base_addr = 0x0,
5137
		.global1_addr = 0x1b,
5138
		.global2_addr = 0x1c,
5139
		.age_time_coeff = 3750,
5140
		.g1_irqs = 9,
5141
		.g2_irqs = 14,
5142
		.atu_move_port_mask = 0x1f,
5143
		.pvt = true,
5144
		.multi_chip = true,
5145
		.tag_protocol = DSA_TAG_PROTO_DSA,
5146
		.ptp_support = true,
5147 5148 5149
		.ops = &mv88e6390_ops,
	},
	[MV88E6390X] = {
5150
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
5151 5152 5153
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390X",
		.num_databases = 4096,
5154
		.num_macs = 16384,
5155
		.num_ports = 11,	/* 10 + Z80 */
5156
		.num_internal_phys = 9,
5157
		.num_gpio = 16,
5158
		.max_vid = 8191,
5159
		.port_base_addr = 0x0,
5160
		.phy_base_addr = 0x0,
5161
		.global1_addr = 0x1b,
5162
		.global2_addr = 0x1c,
5163
		.age_time_coeff = 3750,
5164
		.g1_irqs = 9,
5165
		.g2_irqs = 14,
5166
		.atu_move_port_mask = 0x1f,
5167
		.pvt = true,
5168
		.multi_chip = true,
5169
		.tag_protocol = DSA_TAG_PROTO_DSA,
5170
		.ptp_support = true,
5171 5172
		.ops = &mv88e6390x_ops,
	},
5173 5174
};

5175
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
5176
{
5177
	int i;
5178

5179 5180 5181
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
5182 5183 5184 5185

	return NULL;
}

5186
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
5187 5188
{
	const struct mv88e6xxx_info *info;
5189 5190 5191
	unsigned int prod_num, rev;
	u16 id;
	int err;
5192

5193
	mv88e6xxx_reg_lock(chip);
5194
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
5195
	mv88e6xxx_reg_unlock(chip);
5196 5197
	if (err)
		return err;
5198

5199 5200
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
5201 5202 5203 5204 5205

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

5206
	/* Update the compatible info with the probed one */
5207
	chip->info = info;
5208

5209 5210 5211 5212
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

5213 5214
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
5215 5216 5217 5218

	return 0;
}

5219
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
5220
{
5221
	struct mv88e6xxx_chip *chip;
5222

5223 5224
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
5225 5226
		return NULL;

5227
	chip->dev = dev;
5228

5229
	mutex_init(&chip->reg_lock);
5230
	INIT_LIST_HEAD(&chip->mdios);
5231
	idr_init(&chip->policies);
5232

5233
	return chip;
5234 5235
}

5236
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
5237 5238
							int port,
							enum dsa_tag_protocol m)
5239
{
V
Vivien Didelot 已提交
5240
	struct mv88e6xxx_chip *chip = ds->priv;
5241

5242
	return chip->info->tag_protocol;
5243 5244
}

5245
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
5246
				      const struct switchdev_obj_port_mdb *mdb)
5247 5248 5249 5250 5251 5252 5253 5254 5255
{
	/* 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,
5256
				   const struct switchdev_obj_port_mdb *mdb)
5257
{
V
Vivien Didelot 已提交
5258
	struct mv88e6xxx_chip *chip = ds->priv;
5259

5260
	mv88e6xxx_reg_lock(chip);
5261
	if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
5262
					 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
5263 5264
		dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
			port);
5265
	mv88e6xxx_reg_unlock(chip);
5266 5267 5268 5269 5270
}

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

5274
	mv88e6xxx_reg_lock(chip);
5275
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 0);
5276
	mv88e6xxx_reg_unlock(chip);
5277 5278 5279 5280

	return err;
}

5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347
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,
5348
								       port)))
5349 5350 5351 5352 5353 5354
			dev_err(ds->dev, "failed to set egress port\n");
	}

	mutex_unlock(&chip->reg_lock);
}

5355 5356 5357 5358 5359 5360
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;

5361
	mv88e6xxx_reg_lock(chip);
5362 5363 5364 5365
	if (chip->info->ops->port_set_egress_floods)
		err = chip->info->ops->port_set_egress_floods(chip, port,
							      unicast,
							      multicast);
5366
	mv88e6xxx_reg_unlock(chip);
5367 5368 5369 5370

	return err;
}

5371
static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
5372
	.get_tag_protocol	= mv88e6xxx_get_tag_protocol,
5373
	.setup			= mv88e6xxx_setup,
5374
	.teardown		= mv88e6xxx_teardown,
5375
	.phylink_validate	= mv88e6xxx_validate,
5376
	.phylink_mac_link_state	= mv88e6xxx_serdes_pcs_get_state,
5377
	.phylink_mac_config	= mv88e6xxx_mac_config,
5378
	.phylink_mac_an_restart	= mv88e6xxx_serdes_pcs_an_restart,
5379 5380
	.phylink_mac_link_down	= mv88e6xxx_mac_link_down,
	.phylink_mac_link_up	= mv88e6xxx_mac_link_up,
5381 5382 5383
	.get_strings		= mv88e6xxx_get_strings,
	.get_ethtool_stats	= mv88e6xxx_get_ethtool_stats,
	.get_sset_count		= mv88e6xxx_get_sset_count,
5384 5385
	.port_enable		= mv88e6xxx_port_enable,
	.port_disable		= mv88e6xxx_port_disable,
5386 5387
	.port_max_mtu		= mv88e6xxx_get_max_mtu,
	.port_change_mtu	= mv88e6xxx_change_mtu,
V
Vivien Didelot 已提交
5388 5389
	.get_mac_eee		= mv88e6xxx_get_mac_eee,
	.set_mac_eee		= mv88e6xxx_set_mac_eee,
5390
	.get_eeprom_len		= mv88e6xxx_get_eeprom_len,
5391 5392 5393 5394
	.get_eeprom		= mv88e6xxx_get_eeprom,
	.set_eeprom		= mv88e6xxx_set_eeprom,
	.get_regs_len		= mv88e6xxx_get_regs_len,
	.get_regs		= mv88e6xxx_get_regs,
5395 5396
	.get_rxnfc		= mv88e6xxx_get_rxnfc,
	.set_rxnfc		= mv88e6xxx_set_rxnfc,
5397
	.set_ageing_time	= mv88e6xxx_set_ageing_time,
5398 5399
	.port_bridge_join	= mv88e6xxx_port_bridge_join,
	.port_bridge_leave	= mv88e6xxx_port_bridge_leave,
5400
	.port_egress_floods	= mv88e6xxx_port_egress_floods,
5401
	.port_stp_state_set	= mv88e6xxx_port_stp_state_set,
5402
	.port_fast_age		= mv88e6xxx_port_fast_age,
5403 5404 5405 5406 5407 5408 5409
	.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,
5410 5411 5412
	.port_mdb_prepare       = mv88e6xxx_port_mdb_prepare,
	.port_mdb_add           = mv88e6xxx_port_mdb_add,
	.port_mdb_del           = mv88e6xxx_port_mdb_del,
5413 5414
	.port_mirror_add	= mv88e6xxx_port_mirror_add,
	.port_mirror_del	= mv88e6xxx_port_mirror_del,
5415 5416
	.crosschip_bridge_join	= mv88e6xxx_crosschip_bridge_join,
	.crosschip_bridge_leave	= mv88e6xxx_crosschip_bridge_leave,
5417 5418 5419 5420 5421
	.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,
5422 5423
	.devlink_param_get	= mv88e6xxx_devlink_param_get,
	.devlink_param_set	= mv88e6xxx_devlink_param_set,
5424
	.devlink_info_get	= mv88e6xxx_devlink_info_get,
5425 5426
};

5427
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
5428
{
5429
	struct device *dev = chip->dev;
5430 5431
	struct dsa_switch *ds;

5432
	ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
5433 5434 5435
	if (!ds)
		return -ENOMEM;

5436 5437
	ds->dev = dev;
	ds->num_ports = mv88e6xxx_num_ports(chip);
5438
	ds->priv = chip;
5439
	ds->dev = dev;
5440
	ds->ops = &mv88e6xxx_switch_ops;
5441 5442
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
5443 5444 5445

	dev_set_drvdata(dev, ds);

5446
	return dsa_register_switch(ds);
5447 5448
}

5449
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
5450
{
5451
	dsa_unregister_switch(chip->ds);
5452 5453
}

5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466
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;
}

5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481
/* 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);

5482
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
5483
{
5484
	struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
5485
	const struct mv88e6xxx_info *compat_info = NULL;
5486
	struct device *dev = &mdiodev->dev;
5487
	struct device_node *np = dev->of_node;
5488
	struct mv88e6xxx_chip *chip;
5489
	int port;
5490
	int err;
5491

5492 5493 5494
	if (!np && !pdata)
		return -EINVAL;

5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513
	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;
		}
	}

5514 5515 5516
	if (!compat_info)
		return -EINVAL;

5517
	chip = mv88e6xxx_alloc_chip(dev);
5518 5519 5520 5521
	if (!chip) {
		err = -ENOMEM;
		goto out;
	}
5522

5523
	chip->info = compat_info;
5524

5525
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
5526
	if (err)
5527
		goto out;
5528

5529
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
5530 5531 5532 5533
	if (IS_ERR(chip->reset)) {
		err = PTR_ERR(chip->reset);
		goto out;
	}
5534 5535
	if (chip->reset)
		usleep_range(1000, 2000);
5536

5537
	err = mv88e6xxx_detect(chip);
5538
	if (err)
5539
		goto out;
5540

5541 5542
	mv88e6xxx_phy_init(chip);

5543 5544 5545 5546 5547 5548 5549
	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;
	}
5550

5551
	mv88e6xxx_reg_lock(chip);
5552
	err = mv88e6xxx_switch_reset(chip);
5553
	mv88e6xxx_reg_unlock(chip);
5554 5555 5556
	if (err)
		goto out;

5557 5558 5559 5560 5561 5562
	if (np) {
		chip->irq = of_irq_get(np, 0);
		if (chip->irq == -EPROBE_DEFER) {
			err = chip->irq;
			goto out;
		}
5563 5564
	}

5565 5566 5567
	if (pdata)
		chip->irq = pdata->irq;

5568
	/* Has to be performed before the MDIO bus is created, because
5569
	 * the PHYs will link their interrupts to these interrupt
5570 5571
	 * controllers
	 */
5572
	mv88e6xxx_reg_lock(chip);
5573
	if (chip->irq > 0)
5574
		err = mv88e6xxx_g1_irq_setup(chip);
5575 5576
	else
		err = mv88e6xxx_irq_poll_setup(chip);
5577
	mv88e6xxx_reg_unlock(chip);
5578

5579 5580
	if (err)
		goto out;
5581

5582 5583
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
5584
		if (err)
5585
			goto out_g1_irq;
5586 5587
	}

5588 5589 5590 5591 5592 5593 5594 5595
	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;

5596
	err = mv88e6xxx_mdios_register(chip, np);
5597
	if (err)
5598
		goto out_g1_vtu_prob_irq;
5599

5600
	err = mv88e6xxx_register_switch(chip);
5601 5602
	if (err)
		goto out_mdio;
5603

5604
	return 0;
5605 5606

out_mdio:
5607
	mv88e6xxx_mdios_unregister(chip);
5608
out_g1_vtu_prob_irq:
5609
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
5610
out_g1_atu_prob_irq:
5611
	mv88e6xxx_g1_atu_prob_irq_free(chip);
5612
out_g2_irq:
5613
	if (chip->info->g2_irqs > 0)
5614 5615
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
5616
	if (chip->irq > 0)
5617
		mv88e6xxx_g1_irq_free(chip);
5618 5619
	else
		mv88e6xxx_irq_poll_free(chip);
5620
out:
5621 5622 5623
	if (pdata)
		dev_put(pdata->netdev);

5624
	return err;
5625
}
5626 5627 5628 5629

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

5632 5633
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
5634
		mv88e6xxx_ptp_free(chip);
5635
	}
5636

5637
	mv88e6xxx_phy_destroy(chip);
5638
	mv88e6xxx_unregister_switch(chip);
5639
	mv88e6xxx_mdios_unregister(chip);
5640

5641 5642 5643 5644 5645 5646 5647
	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)
5648
		mv88e6xxx_g1_irq_free(chip);
5649 5650
	else
		mv88e6xxx_irq_poll_free(chip);
5651 5652 5653
}

static const struct of_device_id mv88e6xxx_of_match[] = {
5654 5655 5656 5657
	{
		.compatible = "marvell,mv88e6085",
		.data = &mv88e6xxx_table[MV88E6085],
	},
5658 5659 5660 5661
	{
		.compatible = "marvell,mv88e6190",
		.data = &mv88e6xxx_table[MV88E6190],
	},
5662 5663 5664 5665
	{
		.compatible = "marvell,mv88e6250",
		.data = &mv88e6xxx_table[MV88E6250],
	},
5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676
	{ /* 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,
5677
		.pm = &mv88e6xxx_pm_ops,
5678 5679 5680
	},
};

5681
mdio_module_driver(mv88e6xxx_driver);
5682 5683 5684 5685

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