chip.c 185.8 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
static int mv88e6xxx_serdes_pcs_get_state(struct dsa_switch *ds, int port,
					  struct phylink_link_state *state)
{
	struct mv88e6xxx_chip *chip = ds->priv;
488
	int lane;
489 490 491 492
	int err;

	mv88e6xxx_reg_lock(chip);
	lane = mv88e6xxx_serdes_get_lane(chip, port);
493
	if (lane >= 0 && chip->info->ops->serdes_pcs_get_state)
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
		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;
509
	int lane;
510 511 512

	if (ops->serdes_pcs_config) {
		lane = mv88e6xxx_serdes_get_lane(chip, port);
513
		if (lane >= 0)
514 515 516 517 518 519 520 521 522 523 524 525
			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;
526
	int lane;
527 528 529 530 531 532

	ops = chip->info->ops;

	if (ops->serdes_pcs_an_restart) {
		mv88e6xxx_reg_lock(chip);
		lane = mv88e6xxx_serdes_get_lane(chip, port);
533
		if (lane >= 0)
534 535 536 537 538 539 540 541 542 543 544 545 546
			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;
547
	int lane;
548 549 550

	if (!phylink_autoneg_inband(mode) && ops->serdes_pcs_link_up) {
		lane = mv88e6xxx_serdes_get_lane(chip, port);
551
		if (lane >= 0)
552 553 554 555 556 557 558
			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 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660
static void mv88e6393x_phylink_validate(struct mv88e6xxx_chip *chip, int port,
					unsigned long *mask,
					struct phylink_link_state *state)
{
	if (port == 0 || port == 9 || port == 10) {
		phylink_set(mask, 10000baseT_Full);
		phylink_set(mask, 10000baseKR_Full);
		phylink_set(mask, 10000baseCR_Full);
		phylink_set(mask, 10000baseSR_Full);
		phylink_set(mask, 10000baseLR_Full);
		phylink_set(mask, 10000baseLRM_Full);
		phylink_set(mask, 10000baseER_Full);
		phylink_set(mask, 5000baseT_Full);
		phylink_set(mask, 2500baseX_Full);
		phylink_set(mask, 2500baseT_Full);
	}

	phylink_set(mask, 1000baseT_Full);
	phylink_set(mask, 1000baseX_Full);

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

661 662 663 664
static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
			       unsigned long *supported,
			       struct phylink_link_state *state)
{
665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683
	__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);
684 685 686 687 688 689 690
}

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;
691
	struct mv88e6xxx_port *p;
692
	int err;
693

694 695
	p = &chip->ports[port];

696 697 698 699 700
	/* 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...
	 */
701
	if ((mode == MLO_AN_PHY) && mv88e6xxx_phy_is_internal(ds, port))
702 703
		return;

704
	mv88e6xxx_reg_lock(chip);
705 706 707
	/* 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.
708
	 */
709 710 711 712
	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);

713
	err = mv88e6xxx_port_config_interface(chip, port, state->interface);
714 715 716 717 718 719 720 721 722 723 724
	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;

725 726 727 728 729 730 731 732 733
	/* 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;

734
err_unlock:
735
	mv88e6xxx_reg_unlock(chip);
736 737

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

741 742 743
static void mv88e6xxx_mac_link_down(struct dsa_switch *ds, int port,
				    unsigned int mode,
				    phy_interface_t interface)
744 745
{
	struct mv88e6xxx_chip *chip = ds->priv;
746 747
	const struct mv88e6xxx_ops *ops;
	int err = 0;
748

749
	ops = chip->info->ops;
750

751
	mv88e6xxx_reg_lock(chip);
752
	if ((!mv88e6xxx_port_ppu_updates(chip, port) ||
753 754
	     mode == MLO_AN_FIXED) && ops->port_sync_link)
		err = ops->port_sync_link(chip, port, mode, false);
755
	mv88e6xxx_reg_unlock(chip);
756

757 758 759
	if (err)
		dev_err(chip->dev,
			"p%d: failed to force MAC link down\n", port);
760 761 762 763
}

static void mv88e6xxx_mac_link_up(struct dsa_switch *ds, int port,
				  unsigned int mode, phy_interface_t interface,
764 765 766
				  struct phy_device *phydev,
				  int speed, int duplex,
				  bool tx_pause, bool rx_pause)
767
{
768 769 770 771 772 773
	struct mv88e6xxx_chip *chip = ds->priv;
	const struct mv88e6xxx_ops *ops;
	int err = 0;

	ops = chip->info->ops;

774
	mv88e6xxx_reg_lock(chip);
775
	if (!mv88e6xxx_port_ppu_updates(chip, port) || mode == MLO_AN_FIXED) {
776 777 778
		/* 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
779
		 * handled in the Marvell hardware? E.g. port 2 on 88E6390
780 781
		 * shared between internal PHY and Serdes.
		 */
782 783 784 785 786
		err = mv88e6xxx_serdes_pcs_link_up(chip, port, mode, speed,
						   duplex);
		if (err)
			goto error;

787 788 789
		if (ops->port_set_speed_duplex) {
			err = ops->port_set_speed_duplex(chip, port,
							 speed, duplex);
790 791 792 793
			if (err && err != -EOPNOTSUPP)
				goto error;
		}

794 795
		if (ops->port_sync_link)
			err = ops->port_sync_link(chip, port, mode, true);
796
	}
797
error:
798
	mv88e6xxx_reg_unlock(chip);
799

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

805
static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
806
{
807 808
	if (!chip->info->ops->stats_snapshot)
		return -EOPNOTSUPP;
809

810
	return chip->info->ops->stats_snapshot(chip, port);
811 812
}

813
static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
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 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872
	{ "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, },
873 874
};

875
static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
876
					    struct mv88e6xxx_hw_stat *s,
877 878
					    int port, u16 bank1_select,
					    u16 histogram)
879 880 881
{
	u32 low;
	u32 high = 0;
882
	u16 reg = 0;
883
	int err;
884 885
	u64 value;

886
	switch (s->type) {
887
	case STATS_TYPE_PORT:
888 889
		err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
		if (err)
890
			return U64_MAX;
891

892
		low = reg;
893
		if (s->size == 4) {
894 895
			err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
			if (err)
896
				return U64_MAX;
897
			low |= ((u32)reg) << 16;
898
		}
899
		break;
900
	case STATS_TYPE_BANK1:
901
		reg = bank1_select;
902
		fallthrough;
903
	case STATS_TYPE_BANK0:
904
		reg |= s->reg | histogram;
905
		mv88e6xxx_g1_stats_read(chip, reg, &low);
906
		if (s->size == 8)
907
			mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
908 909
		break;
	default:
910
		return U64_MAX;
911
	}
912
	value = (((u64)high) << 32) | low;
913 914 915
	return value;
}

916 917
static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data, int types)
918
{
919 920
	struct mv88e6xxx_hw_stat *stat;
	int i, j;
921

922 923
	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
		stat = &mv88e6xxx_hw_stats[i];
924
		if (stat->type & types) {
925 926 927 928
			memcpy(data + j * ETH_GSTRING_LEN, stat->string,
			       ETH_GSTRING_LEN);
			j++;
		}
929
	}
930 931

	return j;
932 933
}

934 935
static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
936
{
937 938
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_PORT);
939 940
}

941 942 943 944 945 946
static int mv88e6250_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
{
	return mv88e6xxx_stats_get_strings(chip, data, STATS_TYPE_BANK0);
}

947 948
static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
				       uint8_t *data)
949
{
950 951
	return mv88e6xxx_stats_get_strings(chip, data,
					   STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
952 953
}

954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971
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);
}

972
static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
973
				  u32 stringset, uint8_t *data)
974
{
V
Vivien Didelot 已提交
975
	struct mv88e6xxx_chip *chip = ds->priv;
976
	int count = 0;
977

978 979 980
	if (stringset != ETH_SS_STATS)
		return;

981
	mv88e6xxx_reg_lock(chip);
982

983
	if (chip->info->ops->stats_get_strings)
984 985 986 987
		count = chip->info->ops->stats_get_strings(chip, data);

	if (chip->info->ops->serdes_get_strings) {
		data += count * ETH_GSTRING_LEN;
988
		count = chip->info->ops->serdes_get_strings(chip, port, data);
989
	}
990

991 992 993
	data += count * ETH_GSTRING_LEN;
	mv88e6xxx_atu_vtu_get_strings(data);

994
	mv88e6xxx_reg_unlock(chip);
995 996 997 998 999
}

static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
					  int types)
{
1000 1001 1002 1003 1004
	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];
1005
		if (stat->type & types)
1006 1007 1008
			j++;
	}
	return j;
1009 1010
}

1011 1012 1013 1014 1015 1016
static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
{
	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
					      STATS_TYPE_PORT);
}

1017 1018 1019 1020 1021
static int mv88e6250_stats_get_sset_count(struct mv88e6xxx_chip *chip)
{
	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0);
}

1022 1023 1024 1025 1026 1027
static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
{
	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
					      STATS_TYPE_BANK1);
}

1028
static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
1029 1030
{
	struct mv88e6xxx_chip *chip = ds->priv;
1031 1032
	int serdes_count = 0;
	int count = 0;
1033

1034 1035 1036
	if (sset != ETH_SS_STATS)
		return 0;

1037
	mv88e6xxx_reg_lock(chip);
1038
	if (chip->info->ops->stats_get_sset_count)
1039 1040 1041 1042 1043 1044 1045
		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);
1046
	if (serdes_count < 0) {
1047
		count = serdes_count;
1048 1049 1050 1051 1052
		goto out;
	}
	count += serdes_count;
	count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);

1053
out:
1054
	mv88e6xxx_reg_unlock(chip);
1055

1056
	return count;
1057 1058
}

1059 1060 1061
static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data, int types,
				     u16 bank1_select, u16 histogram)
1062 1063 1064 1065 1066 1067 1068
{
	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) {
1069
			mv88e6xxx_reg_lock(chip);
1070 1071 1072
			data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
							      bank1_select,
							      histogram);
1073
			mv88e6xxx_reg_unlock(chip);
1074

1075 1076 1077
			j++;
		}
	}
1078
	return j;
1079 1080
}

1081 1082
static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
1083 1084
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
1085
					 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
1086
					 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1087 1088
}

1089 1090 1091 1092 1093 1094 1095
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);
}

1096 1097
static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
1098 1099
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
1100
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1101 1102
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
					 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1103 1104
}

1105 1106
static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				     uint64_t *data)
1107 1108 1109
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1110 1111
					 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
					 0);
1112 1113
}

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

1124 1125 1126
static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
				uint64_t *data)
{
1127 1128
	int count = 0;

1129
	if (chip->info->ops->stats_get_stats)
1130 1131
		count = chip->info->ops->stats_get_stats(chip, port, data);

1132
	mv88e6xxx_reg_lock(chip);
1133 1134
	if (chip->info->ops->serdes_get_stats) {
		data += count;
1135
		count = chip->info->ops->serdes_get_stats(chip, port, data);
1136
	}
1137 1138
	data += count;
	mv88e6xxx_atu_vtu_get_stats(chip, port, data);
1139
	mv88e6xxx_reg_unlock(chip);
1140 1141
}

1142 1143
static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
					uint64_t *data)
1144
{
V
Vivien Didelot 已提交
1145
	struct mv88e6xxx_chip *chip = ds->priv;
1146 1147
	int ret;

1148
	mv88e6xxx_reg_lock(chip);
1149

1150
	ret = mv88e6xxx_stats_snapshot(chip, port);
1151
	mv88e6xxx_reg_unlock(chip);
1152 1153

	if (ret < 0)
1154
		return;
1155 1156

	mv88e6xxx_get_stats(chip, port, data);
1157

1158 1159
}

1160
static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
1161
{
1162 1163 1164 1165 1166 1167 1168 1169
	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;
1170 1171
}

1172 1173
static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
			       struct ethtool_regs *regs, void *_p)
1174
{
V
Vivien Didelot 已提交
1175
	struct mv88e6xxx_chip *chip = ds->priv;
1176 1177
	int err;
	u16 reg;
1178 1179 1180
	u16 *p = _p;
	int i;

1181
	regs->version = chip->info->prod_num;
1182 1183 1184

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

1185
	mv88e6xxx_reg_lock(chip);
1186

1187 1188
	for (i = 0; i < 32; i++) {

1189 1190 1191
		err = mv88e6xxx_port_read(chip, port, i, &reg);
		if (!err)
			p[i] = reg;
1192
	}
1193

1194 1195 1196
	if (chip->info->ops->serdes_get_regs)
		chip->info->ops->serdes_get_regs(chip, port, &p[i]);

1197
	mv88e6xxx_reg_unlock(chip);
1198 1199
}

V
Vivien Didelot 已提交
1200 1201
static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
1202
{
1203 1204
	/* Nothing to do on the port's MAC */
	return 0;
1205 1206
}

V
Vivien Didelot 已提交
1207 1208
static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
				 struct ethtool_eee *e)
1209
{
1210 1211
	/* Nothing to do on the port's MAC */
	return 0;
1212 1213
}

1214
/* Mask of the local ports allowed to receive frames from a given fabric port */
1215
static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
1216
{
1217 1218
	struct dsa_switch *ds = chip->ds;
	struct dsa_switch_tree *dst = ds->dst;
1219
	struct net_device *br;
1220 1221
	struct dsa_port *dp;
	bool found = false;
1222
	u16 pvlan;
1223

1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247
	/* dev is a physical switch */
	if (dev <= dst->last_switch) {
		list_for_each_entry(dp, &dst->ports, list) {
			if (dp->ds->index == dev && dp->index == port) {
				/* dp might be a DSA link or a user port, so it
				 * might or might not have a bridge_dev
				 * pointer. Use the "found" variable for both
				 * cases.
				 */
				br = dp->bridge_dev;
				found = true;
				break;
			}
		}
	/* dev is a virtual bridge */
	} else {
		list_for_each_entry(dp, &dst->ports, list) {
			if (dp->bridge_num < 0)
				continue;

			if (dp->bridge_num + 1 + dst->last_switch != dev)
				continue;

			br = dp->bridge_dev;
1248 1249 1250 1251
			found = true;
			break;
		}
	}
1252

1253
	/* Prevent frames from unknown switch or virtual bridge */
1254
	if (!found)
1255 1256 1257
		return 0;

	/* Frames from DSA links and CPU ports can egress any local port */
1258
	if (dp->type == DSA_PORT_TYPE_CPU || dp->type == DSA_PORT_TYPE_DSA)
1259 1260 1261 1262 1263 1264 1265
		return mv88e6xxx_port_mask(chip);

	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.
	 */
1266 1267 1268 1269 1270 1271
	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);
1272 1273 1274 1275

	return pvlan;
}

1276
static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
1277 1278
{
	u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
1279 1280 1281

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

1283
	return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
1284 1285
}

1286 1287
static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
					 u8 state)
1288
{
V
Vivien Didelot 已提交
1289
	struct mv88e6xxx_chip *chip = ds->priv;
1290
	int err;
1291

1292
	mv88e6xxx_reg_lock(chip);
1293
	err = mv88e6xxx_port_set_state(chip, port, state);
1294
	mv88e6xxx_reg_unlock(chip);
1295 1296

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

1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318
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;
}

1319 1320
static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
{
1321
	struct dsa_switch *ds = chip->ds;
1322 1323 1324 1325 1326 1327 1328 1329
	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++) {
1330 1331 1332
		port = dsa_routing_port(ds, target);
		if (port == ds->num_ports)
			port = 0x1f;
1333 1334 1335 1336 1337 1338

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

1339 1340 1341 1342 1343 1344 1345
	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;
	}

1346 1347 1348 1349
	err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
	if (err)
		return err;

1350 1351 1352
	return 0;
}

1353 1354 1355 1356 1357 1358 1359 1360 1361
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;
}

1362 1363 1364 1365 1366 1367 1368 1369
static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->rmu_disable)
		return chip->info->ops->rmu_disable(chip);

	return 0;
}

1370 1371 1372 1373 1374 1375 1376 1377
static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->pot_clear)
		return chip->info->ops->pot_clear(chip);

	return 0;
}

1378 1379 1380 1381 1382 1383 1384 1385
static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->mgmt_rsvd2cpu)
		return chip->info->ops->mgmt_rsvd2cpu(chip);

	return 0;
}

1386 1387
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
1388 1389
	int err;

1390 1391 1392 1393
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

1394 1395 1396 1397 1398 1399 1400 1401 1402 1403
	/* The chips that have a "learn2all" bit in Global1, ATU
	 * Control are precisely those whose port registers have a
	 * Message Port bit in Port Control 1 and hence implement
	 * ->port_setup_message_port.
	 */
	if (chip->info->ops->port_setup_message_port) {
		err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
		if (err)
			return err;
	}
1404

1405 1406 1407
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

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

1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440
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;
}

1441 1442
static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
{
1443 1444 1445
	struct dsa_switch_tree *dst = chip->ds->dst;
	struct dsa_switch *ds;
	struct dsa_port *dp;
1446 1447 1448
	u16 pvlan = 0;

	if (!mv88e6xxx_has_pvt(chip))
1449
		return 0;
1450 1451

	/* Skip the local source device, which uses in-chip port VLAN */
1452
	if (dev != chip->ds->index) {
1453
		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1454

1455 1456 1457 1458 1459 1460 1461 1462 1463
		ds = dsa_switch_find(dst->index, dev);
		dp = ds ? dsa_to_port(ds, port) : NULL;
		if (dp && dp->lag_dev) {
			/* As the PVT is used to limit flooding of
			 * FORWARD frames, which use the LAG ID as the
			 * source port, we must translate dev/port to
			 * the special "LAG device" in the PVT, using
			 * the LAG ID as the port number.
			 */
1464
			dev = MV88E6XXX_G2_PVT_ADDR_DEV_TRUNK;
1465 1466 1467 1468
			port = dsa_lag_id(dst, dp->lag_dev);
		}
	}

1469 1470 1471
	return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
}

1472 1473
static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
{
1474 1475 1476
	int dev, port;
	int err;

1477 1478 1479 1480 1481 1482
	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.
	 */
1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495
	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;
1496 1497
}

1498 1499 1500 1501 1502
static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

1503 1504 1505 1506 1507 1508 1509
	if (dsa_to_port(ds, port)->lag_dev)
		/* Hardware is incapable of fast-aging a LAG through a
		 * regular ATU move operation. Until we have something
		 * more fancy in place this is a no-op.
		 */
		return;

1510
	mv88e6xxx_reg_lock(chip);
1511
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1512
	mv88e6xxx_reg_unlock(chip);
1513 1514

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

1518 1519
static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
{
1520
	if (!mv88e6xxx_max_vid(chip))
1521 1522 1523 1524 1525
		return 0;

	return mv88e6xxx_g1_vtu_flush(chip);
}

1526 1527
static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
			     struct mv88e6xxx_vtu_entry *entry)
1528
{
1529 1530
	int err;

1531 1532 1533
	if (!chip->info->ops->vtu_getnext)
		return -EOPNOTSUPP;

1534 1535 1536 1537 1538 1539 1540 1541 1542
	entry->vid = vid ? vid - 1 : mv88e6xxx_max_vid(chip);
	entry->valid = false;

	err = chip->info->ops->vtu_getnext(chip, entry);

	if (entry->vid != vid)
		entry->valid = false;

	return err;
1543 1544
}

1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575
static int mv88e6xxx_vtu_walk(struct mv88e6xxx_chip *chip,
			      int (*cb)(struct mv88e6xxx_chip *chip,
					const struct mv88e6xxx_vtu_entry *entry,
					void *priv),
			      void *priv)
{
	struct mv88e6xxx_vtu_entry entry = {
		.vid = mv88e6xxx_max_vid(chip),
		.valid = false,
	};
	int err;

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

	do {
		err = chip->info->ops->vtu_getnext(chip, &entry);
		if (err)
			return err;

		if (!entry.valid)
			break;

		err = cb(chip, &entry, priv);
		if (err)
			return err;
	} while (entry.vid < mv88e6xxx_max_vid(chip));

	return 0;
}

1576 1577 1578 1579 1580 1581 1582 1583 1584
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);
}

1585 1586 1587 1588 1589 1590 1591 1592 1593 1594
static int mv88e6xxx_fid_map_vlan(struct mv88e6xxx_chip *chip,
				  const struct mv88e6xxx_vtu_entry *entry,
				  void *_fid_bitmap)
{
	unsigned long *fid_bitmap = _fid_bitmap;

	set_bit(entry->fid, fid_bitmap);
	return 0;
}

1595
int mv88e6xxx_fid_map(struct mv88e6xxx_chip *chip, unsigned long *fid_bitmap)
1596
{
1597
	int i, err;
1598
	u16 fid;
1599 1600 1601

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

1602
	/* Set every FID bit used by the (un)bridged ports */
1603
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1604
		err = mv88e6xxx_port_get_fid(chip, i, &fid);
1605 1606 1607
		if (err)
			return err;

1608
		set_bit(fid, fid_bitmap);
1609 1610
	}

1611
	/* Set every FID bit used by the VLAN entries */
1612
	return mv88e6xxx_vtu_walk(chip, mv88e6xxx_fid_map_vlan, fid_bitmap);
1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623
}

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;

1624 1625 1626 1627
	/* 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);
1628
	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1629 1630 1631
		return -ENOSPC;

	/* Clear the database */
1632
	return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1633 1634
}

1635
static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1636
					u16 vid)
1637
{
V
Vivien Didelot 已提交
1638
	struct mv88e6xxx_chip *chip = ds->priv;
1639
	struct mv88e6xxx_vtu_entry vlan;
1640 1641
	int i, err;

1642 1643 1644 1645
	/* 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;

1646
	err = mv88e6xxx_vtu_get(chip, vid, &vlan);
1647 1648
	if (err)
		return err;
1649

1650 1651
	if (!vlan.valid)
		return 0;
1652

1653 1654 1655
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
		if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
			continue;
1656

1657 1658
		if (!dsa_to_port(ds, i)->slave)
			continue;
1659

1660 1661 1662
		if (vlan.member[i] ==
		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
			continue;
1663

1664 1665 1666
		if (dsa_to_port(ds, i)->bridge_dev ==
		    dsa_to_port(ds, port)->bridge_dev)
			break; /* same bridge, check next VLAN */
1667

1668 1669
		if (!dsa_to_port(ds, i)->bridge_dev)
			continue;
1670

1671 1672 1673 1674 1675
		dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
			port, vlan.vid, i,
			netdev_name(dsa_to_port(ds, i)->bridge_dev));
		return -EOPNOTSUPP;
	}
1676

1677
	return 0;
1678 1679
}

1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699
static int mv88e6xxx_port_commit_pvid(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_port *dp = dsa_to_port(chip->ds, port);
	struct mv88e6xxx_port *p = &chip->ports[port];
	bool drop_untagged = false;
	u16 pvid = 0;
	int err;

	if (dp->bridge_dev && br_vlan_enabled(dp->bridge_dev)) {
		pvid = p->bridge_pvid.vid;
		drop_untagged = !p->bridge_pvid.valid;
	}

	err = mv88e6xxx_port_set_pvid(chip, port, pvid);
	if (err)
		return err;

	return mv88e6xxx_port_drop_untagged(chip, port, drop_untagged);
}

1700
static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1701 1702
					 bool vlan_filtering,
					 struct netlink_ext_ack *extack)
1703
{
V
Vivien Didelot 已提交
1704
	struct mv88e6xxx_chip *chip = ds->priv;
1705 1706
	u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
		MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
1707
	int err;
1708

1709 1710
	if (!mv88e6xxx_max_vid(chip))
		return -EOPNOTSUPP;
1711

1712
	mv88e6xxx_reg_lock(chip);
1713

1714
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1715 1716 1717 1718 1719 1720 1721 1722
	if (err)
		goto unlock;

	err = mv88e6xxx_port_commit_pvid(chip, port);
	if (err)
		goto unlock;

unlock:
1723
	mv88e6xxx_reg_unlock(chip);
1724

1725
	return err;
1726 1727
}

1728 1729
static int
mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1730
			    const struct switchdev_obj_port_vlan *vlan)
1731
{
V
Vivien Didelot 已提交
1732
	struct mv88e6xxx_chip *chip = ds->priv;
1733 1734
	int err;

1735
	if (!mv88e6xxx_max_vid(chip))
1736 1737
		return -EOPNOTSUPP;

1738 1739 1740
	/* 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.
	 */
1741
	mv88e6xxx_reg_lock(chip);
1742
	err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid);
1743
	mv88e6xxx_reg_unlock(chip);
1744

1745
	return err;
1746 1747
}

1748 1749 1750 1751 1752
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;
1753 1754
	struct mv88e6xxx_vtu_entry vlan;
	u16 fid;
1755 1756 1757
	int err;

	/* Null VLAN ID corresponds to the port private database */
1758 1759 1760 1761 1762
	if (vid == 0) {
		err = mv88e6xxx_port_get_fid(chip, port, &fid);
		if (err)
			return err;
	} else {
1763
		err = mv88e6xxx_vtu_get(chip, vid, &vlan);
1764 1765 1766 1767
		if (err)
			return err;

		/* switchdev expects -EOPNOTSUPP to honor software VLANs */
1768
		if (!vlan.valid)
1769 1770 1771 1772
			return -EOPNOTSUPP;

		fid = vlan.fid;
	}
1773

1774
	entry.state = 0;
1775 1776 1777
	ether_addr_copy(entry.mac, addr);
	eth_addr_dec(entry.mac);

1778
	err = mv88e6xxx_g1_atu_getnext(chip, fid, &entry);
1779 1780 1781 1782
	if (err)
		return err;

	/* Initialize a fresh ATU entry if it isn't found */
1783
	if (!entry.state || !ether_addr_equal(entry.mac, addr)) {
1784 1785 1786 1787 1788
		memset(&entry, 0, sizeof(entry));
		ether_addr_copy(entry.mac, addr);
	}

	/* Purge the ATU entry only if no port is using it anymore */
1789
	if (!state) {
1790 1791
		entry.portvec &= ~BIT(port);
		if (!entry.portvec)
1792
			entry.state = 0;
1793
	} else {
1794 1795 1796 1797 1798
		if (state == MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC)
			entry.portvec = BIT(port);
		else
			entry.portvec |= BIT(port);

1799 1800 1801
		entry.state = state;
	}

1802
	return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry);
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 1889 1890 1891 1892 1893
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) {
1894
		if (fs->m_ext.vlan_tci != htons(0xffff))
1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014
			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;
}

2015 2016 2017 2018
static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
					u16 vid)
{
	u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
2019 2020 2021
	u8 broadcast[ETH_ALEN];

	eth_broadcast_addr(broadcast);
2022 2023 2024 2025 2026 2027 2028 2029 2030 2031

	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++) {
2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044
		struct dsa_port *dp = dsa_to_port(chip->ds, port);
		struct net_device *brport;

		if (dsa_is_unused_port(chip->ds, port))
			continue;

		brport = dsa_port_to_bridge_port(dp);
		if (brport && !br_port_flag_is_set(brport, BR_BCAST_FLOOD))
			/* Skip bridged user ports where broadcast
			 * flooding is disabled.
			 */
			continue;

2045 2046 2047 2048 2049 2050 2051 2052
		err = mv88e6xxx_port_add_broadcast(chip, port, vid);
		if (err)
			return err;
	}

	return 0;
}

2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099
struct mv88e6xxx_port_broadcast_sync_ctx {
	int port;
	bool flood;
};

static int
mv88e6xxx_port_broadcast_sync_vlan(struct mv88e6xxx_chip *chip,
				   const struct mv88e6xxx_vtu_entry *vlan,
				   void *_ctx)
{
	struct mv88e6xxx_port_broadcast_sync_ctx *ctx = _ctx;
	u8 broadcast[ETH_ALEN];
	u8 state;

	if (ctx->flood)
		state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
	else
		state = MV88E6XXX_G1_ATU_DATA_STATE_MC_UNUSED;

	eth_broadcast_addr(broadcast);

	return mv88e6xxx_port_db_load_purge(chip, ctx->port, broadcast,
					    vlan->vid, state);
}

static int mv88e6xxx_port_broadcast_sync(struct mv88e6xxx_chip *chip, int port,
					 bool flood)
{
	struct mv88e6xxx_port_broadcast_sync_ctx ctx = {
		.port = port,
		.flood = flood,
	};
	struct mv88e6xxx_vtu_entry vid0 = {
		.vid = 0,
	};
	int err;

	/* Update the port's private database... */
	err = mv88e6xxx_port_broadcast_sync_vlan(chip, &vid0, &ctx);
	if (err)
		return err;

	/* ...and the database for all VLANs. */
	return mv88e6xxx_vtu_walk(chip, mv88e6xxx_port_broadcast_sync_vlan,
				  &ctx);
}

2100
static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port,
2101
				    u16 vid, u8 member, bool warn)
2102
{
2103
	const u8 non_member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
2104
	struct mv88e6xxx_vtu_entry vlan;
2105
	int i, err;
2106

2107
	err = mv88e6xxx_vtu_get(chip, vid, &vlan);
2108 2109 2110
	if (err)
		return err;

2111
	if (!vlan.valid) {
2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139
		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;
2140
	} else if (warn) {
2141 2142 2143 2144 2145
		dev_info(chip->dev, "p%d: already a member of VLAN %d\n",
			 port, vid);
	}

	return 0;
2146 2147
}

2148
static int mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
2149 2150
				   const struct switchdev_obj_port_vlan *vlan,
				   struct netlink_ext_ack *extack)
2151
{
V
Vivien Didelot 已提交
2152
	struct mv88e6xxx_chip *chip = ds->priv;
2153 2154
	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
2155
	struct mv88e6xxx_port *p = &chip->ports[port];
2156
	bool warn;
2157
	u8 member;
2158
	int err;
2159

2160 2161 2162
	if (!vlan->vid)
		return 0;

2163 2164 2165
	err = mv88e6xxx_port_vlan_prepare(ds, port, vlan);
	if (err)
		return err;
2166

2167
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
2168
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
2169
	else if (untagged)
2170
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
2171
	else
2172
		member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
2173

2174 2175 2176 2177 2178
	/* 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);

2179
	mv88e6xxx_reg_lock(chip);
2180

2181 2182
	err = mv88e6xxx_port_vlan_join(chip, port, vlan->vid, member, warn);
	if (err) {
2183 2184
		dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
			vlan->vid, untagged ? 'u' : 't');
2185 2186
		goto out;
	}
2187

2188
	if (pvid) {
2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200
		p->bridge_pvid.vid = vlan->vid;
		p->bridge_pvid.valid = true;

		err = mv88e6xxx_port_commit_pvid(chip, port);
		if (err)
			goto out;
	} else if (vlan->vid && p->bridge_pvid.vid == vlan->vid) {
		/* The old pvid was reinstalled as a non-pvid VLAN */
		p->bridge_pvid.valid = false;

		err = mv88e6xxx_port_commit_pvid(chip, port);
		if (err)
2201 2202
			goto out;
	}
2203

2204
out:
2205
	mv88e6xxx_reg_unlock(chip);
2206 2207

	return err;
2208 2209
}

2210 2211
static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,
				     int port, u16 vid)
2212
{
2213
	struct mv88e6xxx_vtu_entry vlan;
2214 2215
	int i, err;

2216
	if (!vid)
2217
		return 0;
2218

2219
	err = mv88e6xxx_vtu_get(chip, vid, &vlan);
2220
	if (err)
2221
		return err;
2222

2223 2224 2225
	/* 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.
	 */
2226
	if (!vlan.valid ||
2227
	    vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
2228
		return -EOPNOTSUPP;
2229

2230
	vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
2231 2232

	/* keep the VLAN unless all ports are excluded */
2233
	vlan.valid = false;
2234
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
2235 2236
		if (vlan.member[i] !=
		    MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
2237
			vlan.valid = true;
2238 2239 2240 2241
			break;
		}
	}

2242
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
2243 2244 2245
	if (err)
		return err;

2246
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
2247 2248
}

2249 2250
static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
				   const struct switchdev_obj_port_vlan *vlan)
2251
{
V
Vivien Didelot 已提交
2252
	struct mv88e6xxx_chip *chip = ds->priv;
2253
	struct mv88e6xxx_port *p = &chip->ports[port];
2254
	int err = 0;
2255
	u16 pvid;
2256

2257
	if (!mv88e6xxx_max_vid(chip))
2258 2259
		return -EOPNOTSUPP;

2260
	mv88e6xxx_reg_lock(chip);
2261

2262
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
2263 2264 2265
	if (err)
		goto unlock;

2266 2267 2268 2269 2270
	err = mv88e6xxx_port_vlan_leave(chip, port, vlan->vid);
	if (err)
		goto unlock;

	if (vlan->vid == pvid) {
2271 2272 2273
		p->bridge_pvid.valid = false;

		err = mv88e6xxx_port_commit_pvid(chip, port);
2274 2275 2276 2277
		if (err)
			goto unlock;
	}

2278
unlock:
2279
	mv88e6xxx_reg_unlock(chip);
2280 2281 2282 2283

	return err;
}

2284 2285
static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
				  const unsigned char *addr, u16 vid)
2286
{
V
Vivien Didelot 已提交
2287
	struct mv88e6xxx_chip *chip = ds->priv;
2288
	int err;
2289

2290
	mv88e6xxx_reg_lock(chip);
2291 2292
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
2293
	mv88e6xxx_reg_unlock(chip);
2294 2295

	return err;
2296 2297
}

2298
static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
2299
				  const unsigned char *addr, u16 vid)
2300
{
V
Vivien Didelot 已提交
2301
	struct mv88e6xxx_chip *chip = ds->priv;
2302
	int err;
2303

2304
	mv88e6xxx_reg_lock(chip);
2305
	err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid, 0);
2306
	mv88e6xxx_reg_unlock(chip);
2307

2308
	return err;
2309 2310
}

2311 2312
static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
				      u16 fid, u16 vid, int port,
2313
				      dsa_fdb_dump_cb_t *cb, void *data)
2314
{
2315
	struct mv88e6xxx_atu_entry addr;
2316
	bool is_static;
2317 2318
	int err;

2319
	addr.state = 0;
2320
	eth_broadcast_addr(addr.mac);
2321 2322

	do {
2323
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
2324
		if (err)
2325
			return err;
2326

2327
		if (!addr.state)
2328 2329
			break;

2330
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
2331 2332
			continue;

2333 2334
		if (!is_unicast_ether_addr(addr.mac))
			continue;
2335

2336 2337 2338
		is_static = (addr.state ==
			     MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
		err = cb(addr.mac, vid, is_static, data);
2339 2340
		if (err)
			return err;
2341 2342 2343 2344 2345
	} while (!is_broadcast_ether_addr(addr.mac));

	return err;
}

2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361
struct mv88e6xxx_port_db_dump_vlan_ctx {
	int port;
	dsa_fdb_dump_cb_t *cb;
	void *data;
};

static int mv88e6xxx_port_db_dump_vlan(struct mv88e6xxx_chip *chip,
				       const struct mv88e6xxx_vtu_entry *entry,
				       void *_data)
{
	struct mv88e6xxx_port_db_dump_vlan_ctx *ctx = _data;

	return mv88e6xxx_port_db_dump_fid(chip, entry->fid, entry->vid,
					  ctx->port, ctx->cb, ctx->data);
}

2362
static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2363
				  dsa_fdb_dump_cb_t *cb, void *data)
2364
{
2365 2366 2367 2368 2369
	struct mv88e6xxx_port_db_dump_vlan_ctx ctx = {
		.port = port,
		.cb = cb,
		.data = data,
	};
2370
	u16 fid;
2371 2372
	int err;

2373
	/* Dump port's default Filtering Information Database (VLAN ID 0) */
2374
	err = mv88e6xxx_port_get_fid(chip, port, &fid);
2375
	if (err)
2376
		return err;
2377

2378
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
2379
	if (err)
2380
		return err;
2381

2382
	return mv88e6xxx_vtu_walk(chip, mv88e6xxx_port_db_dump_vlan, &ctx);
2383 2384 2385
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2386
				   dsa_fdb_dump_cb_t *cb, void *data)
2387
{
V
Vivien Didelot 已提交
2388
	struct mv88e6xxx_chip *chip = ds->priv;
2389 2390
	int err;

2391
	mv88e6xxx_reg_lock(chip);
2392
	err = mv88e6xxx_port_db_dump(chip, port, cb, data);
2393
	mv88e6xxx_reg_unlock(chip);
2394

2395
	return err;
2396 2397
}

2398 2399
static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
				struct net_device *br)
2400
{
2401 2402 2403
	struct dsa_switch *ds = chip->ds;
	struct dsa_switch_tree *dst = ds->dst;
	struct dsa_port *dp;
2404
	int err;
2405

2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420
	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);
2421 2422 2423 2424 2425 2426
				if (err)
					return err;
			}
		}
	}

2427 2428 2429 2430 2431 2432 2433 2434 2435
	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;

2436
	mv88e6xxx_reg_lock(chip);
2437
	err = mv88e6xxx_bridge_map(chip, br);
2438
	mv88e6xxx_reg_unlock(chip);
2439

2440
	return err;
2441 2442
}

2443 2444
static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
					struct net_device *br)
2445
{
V
Vivien Didelot 已提交
2446
	struct mv88e6xxx_chip *chip = ds->priv;
2447

2448
	mv88e6xxx_reg_lock(chip);
2449 2450 2451
	if (mv88e6xxx_bridge_map(chip, br) ||
	    mv88e6xxx_port_vlan_map(chip, port))
		dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
2452
	mv88e6xxx_reg_unlock(chip);
2453 2454
}

2455 2456
static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds,
					   int tree_index, int sw_index,
2457 2458 2459 2460 2461
					   int port, struct net_device *br)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

2462 2463 2464
	if (tree_index != ds->dst->index)
		return 0;

2465
	mv88e6xxx_reg_lock(chip);
2466
	err = mv88e6xxx_pvt_map(chip, sw_index, port);
2467
	mv88e6xxx_reg_unlock(chip);
2468 2469 2470 2471

	return err;
}

2472 2473
static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds,
					     int tree_index, int sw_index,
2474 2475 2476 2477
					     int port, struct net_device *br)
{
	struct mv88e6xxx_chip *chip = ds->priv;

2478 2479 2480
	if (tree_index != ds->dst->index)
		return;

2481
	mv88e6xxx_reg_lock(chip);
2482
	if (mv88e6xxx_pvt_map(chip, sw_index, port))
2483
		dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
2484
	mv88e6xxx_reg_unlock(chip);
2485 2486
}

2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524
/* Treat the software bridge as a virtual single-port switch behind the
 * CPU and map in the PVT. First dst->last_switch elements are taken by
 * physical switches, so start from beyond that range.
 */
static int mv88e6xxx_map_virtual_bridge_to_pvt(struct dsa_switch *ds,
					       int bridge_num)
{
	u8 dev = bridge_num + ds->dst->last_switch + 1;
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

	mv88e6xxx_reg_lock(chip);
	err = mv88e6xxx_pvt_map(chip, dev, 0);
	mv88e6xxx_reg_unlock(chip);

	return err;
}

static int mv88e6xxx_bridge_tx_fwd_offload(struct dsa_switch *ds, int port,
					   struct net_device *br,
					   int bridge_num)
{
	return mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge_num);
}

static void mv88e6xxx_bridge_tx_fwd_unoffload(struct dsa_switch *ds, int port,
					      struct net_device *br,
					      int bridge_num)
{
	int err;

	err = mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge_num);
	if (err) {
		dev_err(ds->dev, "failed to remap cross-chip Port VLAN: %pe\n",
			ERR_PTR(err));
	}
}

2525 2526 2527 2528 2529 2530 2531 2532
static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->reset)
		return chip->info->ops->reset(chip);

	return 0;
}

2533 2534 2535 2536 2537 2538 2539 2540 2541 2542
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);
2543 2544

		mv88e6xxx_g1_wait_eeprom_done(chip);
2545 2546 2547
	}
}

2548
static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2549
{
2550
	int i, err;
2551

2552
	/* Set all ports to the Disabled state */
2553
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2554
		err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
2555 2556
		if (err)
			return err;
2557 2558
	}

2559 2560 2561
	/* Wait for transmit queues to drain,
	 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
	 */
2562 2563
	usleep_range(2000, 4000);

2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574
	return 0;
}

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

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

2575
	mv88e6xxx_hardware_reset(chip);
2576

2577
	return mv88e6xxx_software_reset(chip);
2578 2579
}

2580
static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
2581 2582
				   enum mv88e6xxx_frame_mode frame,
				   enum mv88e6xxx_egress_mode egress, u16 etype)
2583 2584 2585
{
	int err;

2586 2587 2588 2589
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
2590 2591 2592
	if (err)
		return err;

2593 2594 2595 2596 2597 2598 2599 2600
	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;
2601 2602
}

2603
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2604
{
2605
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
2606
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2607
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2608
}
2609

2610 2611 2612
static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
2613
				       MV88E6XXX_EGRESS_MODE_UNMODIFIED,
2614
				       MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
2615
}
2616

2617 2618 2619 2620
static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port,
				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
2621 2622
				       MV88E6XXX_EGRESS_MODE_ETHERTYPE,
				       ETH_P_EDSA);
2623
}
2624

2625 2626 2627 2628
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);
2629

2630
	if (dsa_is_user_port(chip->ds, port))
2631
		return mv88e6xxx_set_port_mode_normal(chip, port);
2632

2633
	/* Setup CPU port mode depending on its supported tag format */
2634
	if (chip->tag_protocol == DSA_TAG_PROTO_DSA)
2635
		return mv88e6xxx_set_port_mode_dsa(chip, port);
2636

2637
	if (chip->tag_protocol == DSA_TAG_PROTO_EDSA)
2638
		return mv88e6xxx_set_port_mode_edsa(chip, port);
2639

2640
	return -EINVAL;
2641 2642
}

2643
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2644
{
2645
	bool message = dsa_is_dsa_port(chip->ds, port);
2646

2647
	return mv88e6xxx_port_set_message_port(chip, port, message);
2648
}
2649

2650
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2651
{
2652
	int err;
2653

2654
	if (chip->info->ops->port_set_ucast_flood) {
2655
		err = chip->info->ops->port_set_ucast_flood(chip, port, true);
2656 2657 2658 2659
		if (err)
			return err;
	}
	if (chip->info->ops->port_set_mcast_flood) {
2660
		err = chip->info->ops->port_set_mcast_flood(chip, port, true);
2661 2662 2663
		if (err)
			return err;
	}
2664

2665
	return 0;
2666 2667
}

2668 2669 2670 2671 2672 2673
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;
2674
	int lane;
2675 2676 2677

	mv88e6xxx_reg_lock(chip);
	lane = mv88e6xxx_serdes_get_lane(chip, port);
2678
	if (lane >= 0)
2679 2680 2681 2682 2683 2684 2685
		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,
2686
					int lane)
2687 2688 2689 2690 2691 2692 2693 2694 2695 2696
{
	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;

2697 2698 2699
	snprintf(dev_id->serdes_irq_name, sizeof(dev_id->serdes_irq_name),
		 "mv88e6xxx-%s-serdes-%d", dev_name(chip->dev), port);

2700 2701 2702
	/* 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,
2703 2704
				   IRQF_ONESHOT, dev_id->serdes_irq_name,
				   dev_id);
2705 2706 2707 2708 2709 2710 2711 2712 2713 2714
	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,
2715
				     int lane)
2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736
{
	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;
}

2737 2738 2739
static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
				  bool on)
{
2740
	int lane;
2741
	int err;
2742

2743
	lane = mv88e6xxx_serdes_get_lane(chip, port);
2744
	if (lane < 0)
2745 2746 2747
		return 0;

	if (on) {
2748
		err = mv88e6xxx_serdes_power_up(chip, port, lane);
2749 2750 2751
		if (err)
			return err;

2752
		err = mv88e6xxx_serdes_irq_request(chip, port, lane);
2753
	} else {
2754 2755 2756
		err = mv88e6xxx_serdes_irq_free(chip, port, lane);
		if (err)
			return err;
2757

2758
		err = mv88e6xxx_serdes_power_down(chip, port, lane);
2759 2760 2761
	}

	return err;
2762 2763
}

2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784
static int mv88e6xxx_set_egress_port(struct mv88e6xxx_chip *chip,
				     enum mv88e6xxx_egress_direction direction,
				     int port)
{
	int err;

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

	err = chip->info->ops->set_egress_port(chip, direction, port);
	if (err)
		return err;

	if (direction == MV88E6XXX_EGRESS_DIR_INGRESS)
		chip->ingress_dest_port = port;
	else
		chip->egress_dest_port = port;

	return 0;
}

2785 2786 2787 2788 2789 2790
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{
	struct dsa_switch *ds = chip->ds;
	int upstream_port;
	int err;

2791
	upstream_port = dsa_upstream_port(ds, port);
2792 2793 2794 2795 2796 2797 2798
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(chip, port,
							      upstream_port);
		if (err)
			return err;
	}

2799 2800 2801 2802 2803 2804 2805 2806
	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;
		}

2807
		err = mv88e6xxx_set_egress_port(chip,
2808 2809
						MV88E6XXX_EGRESS_DIR_INGRESS,
						upstream_port);
2810 2811
		if (err && err != -EOPNOTSUPP)
			return err;
2812

2813
		err = mv88e6xxx_set_egress_port(chip,
2814 2815
						MV88E6XXX_EGRESS_DIR_EGRESS,
						upstream_port);
2816 2817
		if (err && err != -EOPNOTSUPP)
			return err;
2818 2819
	}

2820 2821 2822
	return 0;
}

2823
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
2824
{
2825
	struct dsa_switch *ds = chip->ds;
2826
	int err;
2827
	u16 reg;
2828

2829 2830 2831
	chip->ports[port].chip = chip;
	chip->ports[port].port = port;

2832 2833 2834 2835 2836 2837 2838
	/* 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,
2839
					       PAUSE_OFF,
2840 2841 2842 2843
					       PHY_INTERFACE_MODE_NA);
	else
		err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
					       SPEED_UNFORCED, DUPLEX_UNFORCED,
2844
					       PAUSE_ON,
2845 2846 2847
					       PHY_INTERFACE_MODE_NA);
	if (err)
		return err;
2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862

	/* 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.
	 */
2863 2864 2865 2866
	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);
2867 2868
	if (err)
		return err;
2869

2870
	err = mv88e6xxx_setup_port_mode(chip, port);
2871 2872
	if (err)
		return err;
2873

2874
	err = mv88e6xxx_setup_egress_floods(chip, port);
2875 2876 2877
	if (err)
		return err;

A
Andrew Lunn 已提交
2878 2879
	/* Port Control 2: don't force a good FCS, set the MTU size to
	 * 10222 bytes, disable 802.1q tags checking, don't discard tagged or
2880 2881 2882
	 * 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.
2883
	 */
2884 2885 2886
	err = mv88e6xxx_port_set_map_da(chip, port);
	if (err)
		return err;
2887

2888 2889 2890
	err = mv88e6xxx_setup_upstream_port(chip, port);
	if (err)
		return err;
2891

2892
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
2893
				MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
2894 2895 2896
	if (err)
		return err;

2897
	if (chip->info->ops->port_set_jumbo_size) {
A
Andrew Lunn 已提交
2898
		err = chip->info->ops->port_set_jumbo_size(chip, port, 10218);
2899 2900 2901 2902
		if (err)
			return err;
	}

2903 2904 2905 2906 2907 2908 2909 2910 2911
	/* Port Association Vector: disable automatic address learning
	 * on all user ports since they start out in standalone
	 * mode. When joining a bridge, learning will be configured to
	 * match the bridge port settings. Enable learning on all
	 * DSA/CPU ports. NOTE: FROM_CPU frames always bypass the
	 * learning process.
	 *
	 * Disable HoldAt1, IntOnAgeOut, LockedPort, IgnoreWrongData,
	 * and RefreshLocked. I.e. setup standard automatic learning.
2912
	 */
2913
	if (dsa_is_user_port(ds, port))
2914
		reg = 0;
2915 2916
	else
		reg = 1 << port;
2917

2918 2919
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
				   reg);
2920 2921
	if (err)
		return err;
2922 2923

	/* Egress rate control 2: disable egress rate control. */
2924 2925
	err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
				   0x0000);
2926 2927
	if (err)
		return err;
2928

2929 2930
	if (chip->info->ops->port_pause_limit) {
		err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
2931 2932
		if (err)
			return err;
2933
	}
2934

2935 2936 2937 2938 2939 2940
	if (chip->info->ops->port_disable_learn_limit) {
		err = chip->info->ops->port_disable_learn_limit(chip, port);
		if (err)
			return err;
	}

2941 2942
	if (chip->info->ops->port_disable_pri_override) {
		err = chip->info->ops->port_disable_pri_override(chip, port);
2943 2944
		if (err)
			return err;
2945
	}
2946

2947 2948
	if (chip->info->ops->port_tag_remap) {
		err = chip->info->ops->port_tag_remap(chip, port);
2949 2950
		if (err)
			return err;
2951 2952
	}

2953 2954
	if (chip->info->ops->port_egress_rate_limiting) {
		err = chip->info->ops->port_egress_rate_limiting(chip, port);
2955 2956
		if (err)
			return err;
2957 2958
	}

2959 2960 2961 2962 2963
	if (chip->info->ops->port_setup_message_port) {
		err = chip->info->ops->port_setup_message_port(chip, port);
		if (err)
			return err;
	}
2964

2965
	/* Port based VLAN map: give each port the same default address
2966 2967
	 * database, and allow bidirectional communication between the
	 * CPU and DSA port(s), and the other ports.
2968
	 */
2969
	err = mv88e6xxx_port_set_fid(chip, port, 0);
2970 2971
	if (err)
		return err;
2972

2973
	err = mv88e6xxx_port_vlan_map(chip, port);
2974 2975
	if (err)
		return err;
2976 2977 2978 2979

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

2983 2984 2985 2986 2987
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)
2988
		return 10240 - VLAN_ETH_HLEN - EDSA_HLEN - ETH_FCS_LEN;
2989
	else if (chip->info->ops->set_max_frame_size)
2990 2991
		return 1632 - VLAN_ETH_HLEN - EDSA_HLEN - ETH_FCS_LEN;
	return 1522 - VLAN_ETH_HLEN - EDSA_HLEN - ETH_FCS_LEN;
2992 2993 2994 2995 2996 2997 2998
}

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

2999 3000 3001
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
		new_mtu += EDSA_HLEN;

3002 3003 3004
	mv88e6xxx_reg_lock(chip);
	if (chip->info->ops->port_set_jumbo_size)
		ret = chip->info->ops->port_set_jumbo_size(chip, port, new_mtu);
3005 3006
	else if (chip->info->ops->set_max_frame_size)
		ret = chip->info->ops->set_max_frame_size(chip, new_mtu);
3007 3008 3009 3010 3011 3012 3013 3014
	else
		if (new_mtu > 1522)
			ret = -EINVAL;
	mv88e6xxx_reg_unlock(chip);

	return ret;
}

3015 3016 3017 3018
static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
				 struct phy_device *phydev)
{
	struct mv88e6xxx_chip *chip = ds->priv;
3019
	int err;
3020

3021
	mv88e6xxx_reg_lock(chip);
3022
	err = mv88e6xxx_serdes_power(chip, port, true);
3023
	mv88e6xxx_reg_unlock(chip);
3024 3025 3026 3027

	return err;
}

3028
static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port)
3029 3030 3031
{
	struct mv88e6xxx_chip *chip = ds->priv;

3032
	mv88e6xxx_reg_lock(chip);
3033 3034
	if (mv88e6xxx_serdes_power(chip, port, false))
		dev_err(chip->dev, "failed to power off SERDES\n");
3035
	mv88e6xxx_reg_unlock(chip);
3036 3037
}

3038 3039 3040
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
3041
	struct mv88e6xxx_chip *chip = ds->priv;
3042 3043
	int err;

3044
	mv88e6xxx_reg_lock(chip);
3045
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
3046
	mv88e6xxx_reg_unlock(chip);
3047 3048 3049 3050

	return err;
}

3051
static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
3052
{
3053
	int err;
3054

3055
	/* Initialize the statistics unit */
3056 3057 3058 3059 3060
	if (chip->info->ops->stats_set_histogram) {
		err = chip->info->ops->stats_set_histogram(chip);
		if (err)
			return err;
	}
3061

3062
	return mv88e6xxx_g1_stats_clear(chip);
3063 3064
}

3065 3066 3067 3068 3069 3070 3071 3072
/* 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++) {
3073
		err = mv88e6xxx_port_hidden_read(chip, 0xf, port, 0, &val);
3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105
		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++) {
3106
		err = mv88e6xxx_port_hidden_write(chip, 0xf, port, 0, 0x01c0);
3107 3108 3109 3110 3111 3112 3113
		if (err)
			return err;
	}

	return mv88e6xxx_software_reset(chip);
}

3114 3115 3116
static void mv88e6xxx_teardown(struct dsa_switch *ds)
{
	mv88e6xxx_teardown_devlink_params(ds);
3117
	dsa_devlink_resources_unregister(ds);
3118
	mv88e6xxx_teardown_devlink_regions_global(ds);
3119 3120
}

3121
static int mv88e6xxx_setup(struct dsa_switch *ds)
3122
{
V
Vivien Didelot 已提交
3123
	struct mv88e6xxx_chip *chip = ds->priv;
3124
	u8 cmode;
3125
	int err;
3126 3127
	int i;

3128
	chip->ds = ds;
3129
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
3130

3131 3132 3133 3134 3135 3136 3137 3138 3139
	/* Since virtual bridges are mapped in the PVT, the number we support
	 * depends on the physical switch topology. We need to let DSA figure
	 * that out and therefore we cannot set this at dsa_register_switch()
	 * time.
	 */
	if (mv88e6xxx_has_pvt(chip))
		ds->num_fwd_offloading_bridges = MV88E6XXX_MAX_PVT_SWITCHES -
						 ds->dst->last_switch - 1;

3140
	mv88e6xxx_reg_lock(chip);
3141

3142 3143 3144 3145 3146 3147
	if (chip->info->ops->setup_errata) {
		err = chip->info->ops->setup_errata(chip);
		if (err)
			goto unlock;
	}

3148 3149 3150 3151 3152
	/* 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)
3153
				goto unlock;
3154 3155 3156 3157 3158

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

3159
	/* Setup Switch Port Registers */
3160
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
3161 3162 3163
		if (dsa_is_unused_port(ds, i))
			continue;

3164
		/* Prevent the use of an invalid port. */
3165
		if (mv88e6xxx_is_invalid_port(chip, i)) {
3166 3167 3168 3169 3170
			dev_err(chip->dev, "port %d is invalid\n", i);
			err = -EINVAL;
			goto unlock;
		}

3171 3172 3173 3174 3175
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

3176 3177 3178 3179
	err = mv88e6xxx_irl_setup(chip);
	if (err)
		goto unlock;

3180 3181 3182 3183
	err = mv88e6xxx_mac_setup(chip);
	if (err)
		goto unlock;

3184 3185 3186 3187
	err = mv88e6xxx_phy_setup(chip);
	if (err)
		goto unlock;

3188 3189 3190 3191
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

3192 3193 3194 3195
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

3196 3197 3198 3199
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

3200 3201 3202 3203
	err = mv88e6xxx_broadcast_setup(chip, 0);
	if (err)
		goto unlock;

3204 3205 3206 3207
	err = mv88e6xxx_pot_setup(chip);
	if (err)
		goto unlock;

3208 3209 3210 3211
	err = mv88e6xxx_rmu_setup(chip);
	if (err)
		goto unlock;

3212 3213 3214
	err = mv88e6xxx_rsvd2cpu_setup(chip);
	if (err)
		goto unlock;
3215

3216 3217 3218 3219
	err = mv88e6xxx_trunk_setup(chip);
	if (err)
		goto unlock;

3220 3221 3222 3223
	err = mv88e6xxx_devmap_setup(chip);
	if (err)
		goto unlock;

3224 3225 3226 3227
	err = mv88e6xxx_pri_setup(chip);
	if (err)
		goto unlock;

3228
	/* Setup PTP Hardware Clock and timestamping */
3229 3230 3231 3232
	if (chip->info->ptp_support) {
		err = mv88e6xxx_ptp_setup(chip);
		if (err)
			goto unlock;
3233 3234 3235 3236

		err = mv88e6xxx_hwtstamp_setup(chip);
		if (err)
			goto unlock;
3237 3238
	}

3239 3240 3241 3242
	err = mv88e6xxx_stats_setup(chip);
	if (err)
		goto unlock;

3243
unlock:
3244
	mv88e6xxx_reg_unlock(chip);
3245

3246 3247 3248 3249 3250 3251 3252
	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.
3253
	 */
3254 3255 3256 3257 3258 3259
	err = mv88e6xxx_setup_devlink_resources(ds);
	if (err)
		return err;

	err = mv88e6xxx_setup_devlink_params(ds);
	if (err)
3260 3261
		goto out_resources;

3262
	err = mv88e6xxx_setup_devlink_regions_global(ds);
3263 3264 3265 3266 3267 3268 3269 3270 3271
	if (err)
		goto out_params;

	return 0;

out_params:
	mv88e6xxx_teardown_devlink_params(ds);
out_resources:
	dsa_devlink_resources_unregister(ds);
3272 3273

	return err;
3274 3275
}

3276 3277 3278 3279 3280 3281 3282 3283 3284 3285
static int mv88e6xxx_port_setup(struct dsa_switch *ds, int port)
{
	return mv88e6xxx_setup_devlink_regions_port(ds, port);
}

static void mv88e6xxx_port_teardown(struct dsa_switch *ds, int port)
{
	mv88e6xxx_teardown_devlink_regions_port(ds, port);
}

3286 3287 3288 3289
/* prod_id for switch families which do not have a PHY model number */
static const u16 family_prod_id_table[] = {
	[MV88E6XXX_FAMILY_6341] = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
	[MV88E6XXX_FAMILY_6390] = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
3290
	[MV88E6XXX_FAMILY_6393] = MV88E6XXX_PORT_SWITCH_ID_PROD_6393X,
3291 3292
};

3293
static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
3294
{
3295 3296
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
3297
	u16 prod_id;
3298 3299
	u16 val;
	int err;
3300

3301 3302 3303
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

3304
	mv88e6xxx_reg_lock(chip);
3305
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
3306
	mv88e6xxx_reg_unlock(chip);
3307

3308 3309 3310 3311 3312 3313
	/* Some internal PHYs don't have a model number. */
	if (reg == MII_PHYSID2 && !(val & 0x3f0) &&
	    chip->info->family < ARRAY_SIZE(family_prod_id_table)) {
		prod_id = family_prod_id_table[chip->info->family];
		if (prod_id)
			val |= prod_id >> 4;
3314 3315
	}

3316
	return err ? err : val;
3317 3318
}

3319
static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
3320
{
3321 3322
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
3323
	int err;
3324

3325 3326 3327
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

3328
	mv88e6xxx_reg_lock(chip);
3329
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
3330
	mv88e6xxx_reg_unlock(chip);
3331 3332

	return err;
3333 3334
}

3335
static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
3336 3337
				   struct device_node *np,
				   bool external)
3338 3339
{
	static int index;
3340
	struct mv88e6xxx_mdio_bus *mdio_bus;
3341 3342 3343
	struct mii_bus *bus;
	int err;

3344
	if (external) {
3345
		mv88e6xxx_reg_lock(chip);
3346
		err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
3347
		mv88e6xxx_reg_unlock(chip);
3348 3349 3350 3351 3352

		if (err)
			return err;
	}

3353
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
3354 3355 3356
	if (!bus)
		return -ENOMEM;

3357
	mdio_bus = bus->priv;
3358
	mdio_bus->bus = bus;
3359
	mdio_bus->chip = chip;
3360 3361
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
3362

3363 3364
	if (np) {
		bus->name = np->full_name;
3365
		snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
3366 3367 3368 3369 3370 3371 3372
	} 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;
3373
	bus->parent = chip->dev;
3374

3375 3376 3377 3378 3379 3380
	if (!external) {
		err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
		if (err)
			return err;
	}

3381
	err = of_mdiobus_register(bus, np);
3382
	if (err) {
3383
		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
3384
		mv88e6xxx_g2_irq_mdio_free(chip, bus);
3385
		return err;
3386
	}
3387 3388 3389 3390 3391

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

	return 0;
3394
}
3395

3396 3397 3398 3399 3400 3401 3402 3403 3404
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;

3405 3406 3407
		if (!mdio_bus->external)
			mv88e6xxx_g2_irq_mdio_free(chip, bus);

3408 3409 3410 3411
		mdiobus_unregister(bus);
	}
}

3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431
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) {
3432 3433
		if (of_device_is_compatible(
			    child, "marvell,mv88e6xxx-mdio-external")) {
3434
			err = mv88e6xxx_mdio_register(chip, child, true);
3435 3436
			if (err) {
				mv88e6xxx_mdios_unregister(chip);
3437
				of_node_put(child);
3438
				return err;
3439
			}
3440 3441 3442 3443
		}
	}

	return 0;
3444 3445
}

3446 3447
static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
3448
	struct mv88e6xxx_chip *chip = ds->priv;
3449 3450 3451 3452 3453 3454 3455

	return chip->eeprom_len;
}

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

3459 3460
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
3461

3462
	mv88e6xxx_reg_lock(chip);
3463
	err = chip->info->ops->get_eeprom(chip, eeprom, data);
3464
	mv88e6xxx_reg_unlock(chip);
3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476

	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 已提交
3477
	struct mv88e6xxx_chip *chip = ds->priv;
3478 3479
	int err;

3480 3481 3482
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

3483 3484 3485
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

3486
	mv88e6xxx_reg_lock(chip);
3487
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
3488
	mv88e6xxx_reg_unlock(chip);
3489 3490 3491 3492

	return err;
}

3493
static const struct mv88e6xxx_ops mv88e6085_ops = {
3494
	/* MV88E6XXX_FAMILY_6097 */
3495 3496
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3497
	.irl_init_all = mv88e6352_g2_irl_init_all,
3498
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3499 3500
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3501
	.port_set_link = mv88e6xxx_port_set_link,
3502
	.port_sync_link = mv88e6xxx_port_sync_link,
3503
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3504
	.port_tag_remap = mv88e6095_port_tag_remap,
3505
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3506 3507
	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
3508
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3509
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3510
	.port_pause_limit = mv88e6097_port_pause_limit,
3511
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3512
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3513
	.port_get_cmode = mv88e6185_port_get_cmode,
3514
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3515
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3516
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3517 3518
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3519
	.stats_get_stats = mv88e6095_stats_get_stats,
3520 3521
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3522
	.watchdog_ops = &mv88e6097_watchdog_ops,
3523
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3524
	.pot_clear = mv88e6xxx_g2_pot_clear,
3525 3526
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
3527
	.reset = mv88e6185_g1_reset,
3528
	.rmu_disable = mv88e6085_g1_rmu_disable,
3529
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3530
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3531
	.phylink_validate = mv88e6185_phylink_validate,
3532
	.set_max_frame_size = mv88e6185_g1_set_max_frame_size,
3533 3534 3535
};

static const struct mv88e6xxx_ops mv88e6095_ops = {
3536
	/* MV88E6XXX_FAMILY_6095 */
3537 3538
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3539
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3540 3541
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3542
	.port_set_link = mv88e6xxx_port_set_link,
3543
	.port_sync_link = mv88e6185_port_sync_link,
3544
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3545
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
3546 3547
	.port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
	.port_set_mcast_flood = mv88e6185_port_set_default_forward,
3548
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
3549
	.port_get_cmode = mv88e6185_port_get_cmode,
3550
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3551
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3552
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3553 3554
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3555
	.stats_get_stats = mv88e6095_stats_get_stats,
3556
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3557 3558 3559
	.serdes_power = mv88e6185_serdes_power,
	.serdes_get_lane = mv88e6185_serdes_get_lane,
	.serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
3560 3561
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
3562
	.reset = mv88e6185_g1_reset,
3563
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3564
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3565
	.phylink_validate = mv88e6185_phylink_validate,
3566
	.set_max_frame_size = mv88e6185_g1_set_max_frame_size,
3567 3568
};

3569
static const struct mv88e6xxx_ops mv88e6097_ops = {
3570
	/* MV88E6XXX_FAMILY_6097 */
3571 3572
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3573
	.irl_init_all = mv88e6352_g2_irl_init_all,
3574 3575 3576 3577
	.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,
3578
	.port_sync_link = mv88e6185_port_sync_link,
3579
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3580
	.port_tag_remap = mv88e6095_port_tag_remap,
3581
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3582 3583
	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
3584
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3585
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
3586
	.port_pause_limit = mv88e6097_port_pause_limit,
3587
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3588
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3589
	.port_get_cmode = mv88e6185_port_get_cmode,
3590
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3591
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3592
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3593 3594 3595
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
	.stats_get_stats = mv88e6095_stats_get_stats,
3596 3597
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3598
	.watchdog_ops = &mv88e6097_watchdog_ops,
3599
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3600 3601 3602
	.serdes_power = mv88e6185_serdes_power,
	.serdes_get_lane = mv88e6185_serdes_get_lane,
	.serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
3603 3604 3605
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
	.serdes_irq_enable = mv88e6097_serdes_irq_enable,
	.serdes_irq_status = mv88e6097_serdes_irq_status,
3606
	.pot_clear = mv88e6xxx_g2_pot_clear,
3607
	.reset = mv88e6352_g1_reset,
3608
	.rmu_disable = mv88e6085_g1_rmu_disable,
3609
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3610
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3611
	.phylink_validate = mv88e6185_phylink_validate,
3612
	.set_max_frame_size = mv88e6185_g1_set_max_frame_size,
3613 3614
};

3615
static const struct mv88e6xxx_ops mv88e6123_ops = {
3616
	/* MV88E6XXX_FAMILY_6165 */
3617 3618
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3619
	.irl_init_all = mv88e6352_g2_irl_init_all,
3620
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3621 3622
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3623
	.port_set_link = mv88e6xxx_port_set_link,
3624
	.port_sync_link = mv88e6xxx_port_sync_link,
3625
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3626
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
3627 3628
	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
3629
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3630
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3631
	.port_get_cmode = mv88e6185_port_get_cmode,
3632
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3633
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3634
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3635 3636
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3637
	.stats_get_stats = mv88e6095_stats_get_stats,
3638 3639
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3640
	.watchdog_ops = &mv88e6097_watchdog_ops,
3641
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3642
	.pot_clear = mv88e6xxx_g2_pot_clear,
3643
	.reset = mv88e6352_g1_reset,
3644 3645
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3646
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3647
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3648
	.phylink_validate = mv88e6185_phylink_validate,
3649
	.set_max_frame_size = mv88e6185_g1_set_max_frame_size,
3650 3651 3652
};

static const struct mv88e6xxx_ops mv88e6131_ops = {
3653
	/* MV88E6XXX_FAMILY_6185 */
3654 3655
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3656
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3657 3658
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
3659
	.port_set_link = mv88e6xxx_port_set_link,
3660
	.port_sync_link = mv88e6xxx_port_sync_link,
3661
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3662
	.port_tag_remap = mv88e6095_port_tag_remap,
3663
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3664 3665
	.port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
	.port_set_mcast_flood = mv88e6185_port_set_default_forward,
3666
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3667
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
3668
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3669
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3670
	.port_pause_limit = mv88e6097_port_pause_limit,
3671
	.port_set_pause = mv88e6185_port_set_pause,
3672
	.port_get_cmode = mv88e6185_port_get_cmode,
3673
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3674
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3675
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3676 3677
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3678
	.stats_get_stats = mv88e6095_stats_get_stats,
3679 3680
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3681
	.watchdog_ops = &mv88e6097_watchdog_ops,
3682
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
3683
	.ppu_enable = mv88e6185_g1_ppu_enable,
3684
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
3685
	.ppu_disable = mv88e6185_g1_ppu_disable,
3686
	.reset = mv88e6185_g1_reset,
3687
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3688
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3689
	.phylink_validate = mv88e6185_phylink_validate,
3690 3691
};

3692 3693
static const struct mv88e6xxx_ops mv88e6141_ops = {
	/* MV88E6XXX_FAMILY_6341 */
3694 3695
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3696
	.irl_init_all = mv88e6352_g2_irl_init_all,
3697 3698 3699 3700 3701 3702
	.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,
3703
	.port_sync_link = mv88e6xxx_port_sync_link,
3704
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3705
	.port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
3706
	.port_max_speed_mode = mv88e6341_port_max_speed_mode,
3707
	.port_tag_remap = mv88e6095_port_tag_remap,
3708
	.port_set_policy = mv88e6352_port_set_policy,
3709
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3710 3711
	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
3712
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3713
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3714
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3715
	.port_pause_limit = mv88e6097_port_pause_limit,
3716 3717
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3718
	.port_get_cmode = mv88e6352_port_get_cmode,
3719
	.port_set_cmode = mv88e6341_port_set_cmode,
3720
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3721
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3722
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3723 3724 3725
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
3726 3727
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
3728 3729
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
3730
	.pot_clear = mv88e6xxx_g2_pot_clear,
3731
	.reset = mv88e6352_g1_reset,
3732
	.rmu_disable = mv88e6390_g1_rmu_disable,
3733 3734
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3735
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3736
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3737 3738
	.serdes_power = mv88e6390_serdes_power,
	.serdes_get_lane = mv88e6341_serdes_get_lane,
3739 3740 3741 3742 3743
	/* 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,
3744
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3745
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
3746
	.serdes_irq_status = mv88e6390_serdes_irq_status,
3747
	.gpio_ops = &mv88e6352_gpio_ops,
3748 3749 3750
	.serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
3751 3752
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
3753
	.phylink_validate = mv88e6341_phylink_validate,
3754 3755
};

3756
static const struct mv88e6xxx_ops mv88e6161_ops = {
3757
	/* MV88E6XXX_FAMILY_6165 */
3758 3759
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3760
	.irl_init_all = mv88e6352_g2_irl_init_all,
3761
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3762 3763
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3764
	.port_set_link = mv88e6xxx_port_set_link,
3765
	.port_sync_link = mv88e6xxx_port_sync_link,
3766
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3767
	.port_tag_remap = mv88e6095_port_tag_remap,
3768
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3769 3770
	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
3771
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3772
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3773
	.port_pause_limit = mv88e6097_port_pause_limit,
3774
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3775
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3776
	.port_get_cmode = mv88e6185_port_get_cmode,
3777
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3778
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3779
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3780 3781
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3782
	.stats_get_stats = mv88e6095_stats_get_stats,
3783 3784
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3785
	.watchdog_ops = &mv88e6097_watchdog_ops,
3786
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3787
	.pot_clear = mv88e6xxx_g2_pot_clear,
3788
	.reset = mv88e6352_g1_reset,
3789 3790
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3791
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3792
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3793
	.avb_ops = &mv88e6165_avb_ops,
3794
	.ptp_ops = &mv88e6165_ptp_ops,
3795
	.phylink_validate = mv88e6185_phylink_validate,
3796
	.set_max_frame_size = mv88e6185_g1_set_max_frame_size,
3797 3798 3799
};

static const struct mv88e6xxx_ops mv88e6165_ops = {
3800
	/* MV88E6XXX_FAMILY_6165 */
3801 3802
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3803
	.irl_init_all = mv88e6352_g2_irl_init_all,
3804
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3805 3806
	.phy_read = mv88e6165_phy_read,
	.phy_write = mv88e6165_phy_write,
3807
	.port_set_link = mv88e6xxx_port_set_link,
3808
	.port_sync_link = mv88e6xxx_port_sync_link,
3809
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3810
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3811
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3812
	.port_get_cmode = mv88e6185_port_get_cmode,
3813
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3814
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3815
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3816 3817
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3818
	.stats_get_stats = mv88e6095_stats_get_stats,
3819 3820
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3821
	.watchdog_ops = &mv88e6097_watchdog_ops,
3822
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3823
	.pot_clear = mv88e6xxx_g2_pot_clear,
3824
	.reset = mv88e6352_g1_reset,
3825 3826
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3827
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3828
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3829
	.avb_ops = &mv88e6165_avb_ops,
3830
	.ptp_ops = &mv88e6165_ptp_ops,
3831
	.phylink_validate = mv88e6185_phylink_validate,
3832 3833 3834
};

static const struct mv88e6xxx_ops mv88e6171_ops = {
3835
	/* MV88E6XXX_FAMILY_6351 */
3836 3837
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3838
	.irl_init_all = mv88e6352_g2_irl_init_all,
3839
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3840 3841
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3842
	.port_set_link = mv88e6xxx_port_set_link,
3843
	.port_sync_link = mv88e6xxx_port_sync_link,
3844
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3845
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3846
	.port_tag_remap = mv88e6095_port_tag_remap,
3847
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3848 3849
	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
3850
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3851
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3852
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3853
	.port_pause_limit = mv88e6097_port_pause_limit,
3854
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3855
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3856
	.port_get_cmode = mv88e6352_port_get_cmode,
3857
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3858
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3859
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3860 3861
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3862
	.stats_get_stats = mv88e6095_stats_get_stats,
3863 3864
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3865
	.watchdog_ops = &mv88e6097_watchdog_ops,
3866
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3867
	.pot_clear = mv88e6xxx_g2_pot_clear,
3868
	.reset = mv88e6352_g1_reset,
3869 3870
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3871
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3872
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3873
	.phylink_validate = mv88e6185_phylink_validate,
3874 3875 3876
};

static const struct mv88e6xxx_ops mv88e6172_ops = {
3877
	/* MV88E6XXX_FAMILY_6352 */
3878 3879
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3880
	.irl_init_all = mv88e6352_g2_irl_init_all,
3881 3882
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3883
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3884 3885
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3886
	.port_set_link = mv88e6xxx_port_set_link,
3887
	.port_sync_link = mv88e6xxx_port_sync_link,
3888
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3889
	.port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
3890
	.port_tag_remap = mv88e6095_port_tag_remap,
3891
	.port_set_policy = mv88e6352_port_set_policy,
3892
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3893 3894
	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
3895
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3896
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3897
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3898
	.port_pause_limit = mv88e6097_port_pause_limit,
3899
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3900
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3901
	.port_get_cmode = mv88e6352_port_get_cmode,
3902
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3903
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3904
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3905 3906
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3907
	.stats_get_stats = mv88e6095_stats_get_stats,
3908 3909
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3910
	.watchdog_ops = &mv88e6097_watchdog_ops,
3911
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3912
	.pot_clear = mv88e6xxx_g2_pot_clear,
3913
	.reset = mv88e6352_g1_reset,
3914
	.rmu_disable = mv88e6352_g1_rmu_disable,
3915 3916
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3917
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3918
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3919
	.serdes_get_lane = mv88e6352_serdes_get_lane,
3920 3921 3922 3923
	.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,
3924
	.serdes_power = mv88e6352_serdes_power,
3925 3926
	.serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
	.serdes_get_regs = mv88e6352_serdes_get_regs,
3927
	.gpio_ops = &mv88e6352_gpio_ops,
3928
	.phylink_validate = mv88e6352_phylink_validate,
3929 3930 3931
};

static const struct mv88e6xxx_ops mv88e6175_ops = {
3932
	/* MV88E6XXX_FAMILY_6351 */
3933 3934
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3935
	.irl_init_all = mv88e6352_g2_irl_init_all,
3936
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3937 3938
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3939
	.port_set_link = mv88e6xxx_port_set_link,
3940
	.port_sync_link = mv88e6xxx_port_sync_link,
3941
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3942
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
3943
	.port_tag_remap = mv88e6095_port_tag_remap,
3944
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3945 3946
	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
3947
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3948
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3949
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3950
	.port_pause_limit = mv88e6097_port_pause_limit,
3951
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3952
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3953
	.port_get_cmode = mv88e6352_port_get_cmode,
3954
	.port_setup_message_port = mv88e6xxx_setup_message_port,
3955
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3956
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3957 3958
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3959
	.stats_get_stats = mv88e6095_stats_get_stats,
3960 3961
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
3962
	.watchdog_ops = &mv88e6097_watchdog_ops,
3963
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3964
	.pot_clear = mv88e6xxx_g2_pot_clear,
3965
	.reset = mv88e6352_g1_reset,
3966 3967
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
3968
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3969
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3970
	.phylink_validate = mv88e6185_phylink_validate,
3971 3972 3973
};

static const struct mv88e6xxx_ops mv88e6176_ops = {
3974
	/* MV88E6XXX_FAMILY_6352 */
3975 3976
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
3977
	.irl_init_all = mv88e6352_g2_irl_init_all,
3978 3979
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3980
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3981 3982
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3983
	.port_set_link = mv88e6xxx_port_set_link,
3984
	.port_sync_link = mv88e6xxx_port_sync_link,
3985
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3986
	.port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
3987
	.port_tag_remap = mv88e6095_port_tag_remap,
3988
	.port_set_policy = mv88e6352_port_set_policy,
3989
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3990 3991
	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
3992
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3993
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
3994
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3995
	.port_pause_limit = mv88e6097_port_pause_limit,
3996
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3997
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3998
	.port_get_cmode = mv88e6352_port_get_cmode,
3999
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4000
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4001
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4002 4003
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
4004
	.stats_get_stats = mv88e6095_stats_get_stats,
4005 4006
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4007
	.watchdog_ops = &mv88e6097_watchdog_ops,
4008
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4009
	.pot_clear = mv88e6xxx_g2_pot_clear,
4010
	.reset = mv88e6352_g1_reset,
4011
	.rmu_disable = mv88e6352_g1_rmu_disable,
4012 4013
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4014
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4015
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4016
	.serdes_get_lane = mv88e6352_serdes_get_lane,
4017 4018 4019 4020
	.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,
4021
	.serdes_power = mv88e6352_serdes_power,
4022
	.serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
4023
	.serdes_irq_enable = mv88e6352_serdes_irq_enable,
4024
	.serdes_irq_status = mv88e6352_serdes_irq_status,
4025 4026
	.serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
	.serdes_get_regs = mv88e6352_serdes_get_regs,
4027
	.gpio_ops = &mv88e6352_gpio_ops,
4028
	.phylink_validate = mv88e6352_phylink_validate,
4029 4030 4031
};

static const struct mv88e6xxx_ops mv88e6185_ops = {
4032
	/* MV88E6XXX_FAMILY_6185 */
4033 4034
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4035
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
4036 4037
	.phy_read = mv88e6185_phy_ppu_read,
	.phy_write = mv88e6185_phy_ppu_write,
4038
	.port_set_link = mv88e6xxx_port_set_link,
4039
	.port_sync_link = mv88e6185_port_sync_link,
4040
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4041
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
4042 4043
	.port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
	.port_set_mcast_flood = mv88e6185_port_set_default_forward,
4044
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
4045
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
4046
	.port_set_pause = mv88e6185_port_set_pause,
4047
	.port_get_cmode = mv88e6185_port_get_cmode,
4048
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4049
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
4050
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4051 4052
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
4053
	.stats_get_stats = mv88e6095_stats_get_stats,
4054 4055
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4056
	.watchdog_ops = &mv88e6097_watchdog_ops,
4057
	.mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
4058 4059 4060
	.serdes_power = mv88e6185_serdes_power,
	.serdes_get_lane = mv88e6185_serdes_get_lane,
	.serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
4061
	.set_cascade_port = mv88e6185_g1_set_cascade_port,
4062 4063
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
4064
	.reset = mv88e6185_g1_reset,
4065
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
4066
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
4067
	.phylink_validate = mv88e6185_phylink_validate,
4068
	.set_max_frame_size = mv88e6185_g1_set_max_frame_size,
4069 4070
};

4071
static const struct mv88e6xxx_ops mv88e6190_ops = {
4072
	/* MV88E6XXX_FAMILY_6390 */
4073
	.setup_errata = mv88e6390_setup_errata,
4074
	.irl_init_all = mv88e6390_g2_irl_init_all,
4075 4076
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4077 4078 4079 4080
	.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,
4081
	.port_sync_link = mv88e6xxx_port_sync_link,
4082
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4083
	.port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
4084
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
4085
	.port_tag_remap = mv88e6390_port_tag_remap,
4086
	.port_set_policy = mv88e6352_port_set_policy,
4087
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4088 4089
	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4090
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4091
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4092
	.port_pause_limit = mv88e6390_port_pause_limit,
4093
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4094
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4095
	.port_get_cmode = mv88e6352_port_get_cmode,
4096
	.port_set_cmode = mv88e6390_port_set_cmode,
4097
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4098
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4099
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4100 4101
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4102
	.stats_get_stats = mv88e6390_stats_get_stats,
4103 4104
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4105
	.watchdog_ops = &mv88e6390_watchdog_ops,
4106
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4107
	.pot_clear = mv88e6xxx_g2_pot_clear,
4108
	.reset = mv88e6352_g1_reset,
4109
	.rmu_disable = mv88e6390_g1_rmu_disable,
4110 4111
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4112 4113
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4114
	.serdes_power = mv88e6390_serdes_power,
4115
	.serdes_get_lane = mv88e6390_serdes_get_lane,
4116 4117 4118 4119 4120
	/* 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,
4121
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4122
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4123
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4124 4125
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
4126 4127
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
4128
	.gpio_ops = &mv88e6352_gpio_ops,
4129
	.phylink_validate = mv88e6390_phylink_validate,
4130 4131 4132
};

static const struct mv88e6xxx_ops mv88e6190x_ops = {
4133
	/* MV88E6XXX_FAMILY_6390 */
4134
	.setup_errata = mv88e6390_setup_errata,
4135
	.irl_init_all = mv88e6390_g2_irl_init_all,
4136 4137
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4138 4139 4140 4141
	.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,
4142
	.port_sync_link = mv88e6xxx_port_sync_link,
4143
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4144
	.port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
4145
	.port_max_speed_mode = mv88e6390x_port_max_speed_mode,
4146
	.port_tag_remap = mv88e6390_port_tag_remap,
4147
	.port_set_policy = mv88e6352_port_set_policy,
4148
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4149 4150
	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4151
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4152
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4153
	.port_pause_limit = mv88e6390_port_pause_limit,
4154
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4155
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4156
	.port_get_cmode = mv88e6352_port_get_cmode,
4157
	.port_set_cmode = mv88e6390x_port_set_cmode,
4158
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4159
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4160
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4161 4162
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4163
	.stats_get_stats = mv88e6390_stats_get_stats,
4164 4165
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4166
	.watchdog_ops = &mv88e6390_watchdog_ops,
4167
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4168
	.pot_clear = mv88e6xxx_g2_pot_clear,
4169
	.reset = mv88e6352_g1_reset,
4170
	.rmu_disable = mv88e6390_g1_rmu_disable,
4171 4172
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4173 4174
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4175
	.serdes_power = mv88e6390_serdes_power,
4176
	.serdes_get_lane = mv88e6390x_serdes_get_lane,
4177 4178 4179 4180 4181
	/* 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,
4182
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4183
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4184
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4185 4186
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
4187 4188
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
4189
	.gpio_ops = &mv88e6352_gpio_ops,
4190
	.phylink_validate = mv88e6390x_phylink_validate,
4191 4192 4193
};

static const struct mv88e6xxx_ops mv88e6191_ops = {
4194
	/* MV88E6XXX_FAMILY_6390 */
4195
	.setup_errata = mv88e6390_setup_errata,
4196
	.irl_init_all = mv88e6390_g2_irl_init_all,
4197 4198
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4199 4200 4201 4202
	.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,
4203
	.port_sync_link = mv88e6xxx_port_sync_link,
4204
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4205
	.port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
4206
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
4207
	.port_tag_remap = mv88e6390_port_tag_remap,
4208
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4209 4210
	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4211
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4212
	.port_pause_limit = mv88e6390_port_pause_limit,
4213
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4214
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4215
	.port_get_cmode = mv88e6352_port_get_cmode,
4216
	.port_set_cmode = mv88e6390_port_set_cmode,
4217
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4218
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4219
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4220 4221
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4222
	.stats_get_stats = mv88e6390_stats_get_stats,
4223 4224
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4225
	.watchdog_ops = &mv88e6390_watchdog_ops,
4226
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4227
	.pot_clear = mv88e6xxx_g2_pot_clear,
4228
	.reset = mv88e6352_g1_reset,
4229
	.rmu_disable = mv88e6390_g1_rmu_disable,
4230 4231
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4232 4233
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4234
	.serdes_power = mv88e6390_serdes_power,
4235
	.serdes_get_lane = mv88e6390_serdes_get_lane,
4236 4237 4238 4239 4240
	/* 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,
4241
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4242
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4243
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4244 4245
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
4246 4247
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
4248 4249
	.avb_ops = &mv88e6390_avb_ops,
	.ptp_ops = &mv88e6352_ptp_ops,
4250
	.phylink_validate = mv88e6390_phylink_validate,
4251 4252
};

4253
static const struct mv88e6xxx_ops mv88e6240_ops = {
4254
	/* MV88E6XXX_FAMILY_6352 */
4255 4256
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4257
	.irl_init_all = mv88e6352_g2_irl_init_all,
4258 4259
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
4260
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4261 4262
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4263
	.port_set_link = mv88e6xxx_port_set_link,
4264
	.port_sync_link = mv88e6xxx_port_sync_link,
4265
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4266
	.port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
4267
	.port_tag_remap = mv88e6095_port_tag_remap,
4268
	.port_set_policy = mv88e6352_port_set_policy,
4269
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4270 4271
	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4272
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4273
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4274
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4275
	.port_pause_limit = mv88e6097_port_pause_limit,
4276
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4277
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4278
	.port_get_cmode = mv88e6352_port_get_cmode,
4279
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4280
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4281
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4282 4283
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
4284
	.stats_get_stats = mv88e6095_stats_get_stats,
4285 4286
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4287
	.watchdog_ops = &mv88e6097_watchdog_ops,
4288
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4289
	.pot_clear = mv88e6xxx_g2_pot_clear,
4290
	.reset = mv88e6352_g1_reset,
4291
	.rmu_disable = mv88e6352_g1_rmu_disable,
4292 4293
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4294
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4295
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4296
	.serdes_get_lane = mv88e6352_serdes_get_lane,
4297 4298 4299 4300
	.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,
4301
	.serdes_power = mv88e6352_serdes_power,
4302
	.serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
4303
	.serdes_irq_enable = mv88e6352_serdes_irq_enable,
4304
	.serdes_irq_status = mv88e6352_serdes_irq_status,
4305 4306
	.serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
	.serdes_get_regs = mv88e6352_serdes_get_regs,
4307
	.gpio_ops = &mv88e6352_gpio_ops,
4308
	.avb_ops = &mv88e6352_avb_ops,
4309
	.ptp_ops = &mv88e6352_ptp_ops,
4310
	.phylink_validate = mv88e6352_phylink_validate,
4311 4312
};

4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323
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,
4324
	.port_sync_link = mv88e6xxx_port_sync_link,
4325
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4326
	.port_set_speed_duplex = mv88e6250_port_set_speed_duplex,
4327 4328
	.port_tag_remap = mv88e6095_port_tag_remap,
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4329 4330
	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345
	.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,
4346
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
4347
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
4348 4349
	.avb_ops = &mv88e6352_avb_ops,
	.ptp_ops = &mv88e6250_ptp_ops,
4350 4351 4352
	.phylink_validate = mv88e6065_phylink_validate,
};

4353
static const struct mv88e6xxx_ops mv88e6290_ops = {
4354
	/* MV88E6XXX_FAMILY_6390 */
4355
	.setup_errata = mv88e6390_setup_errata,
4356
	.irl_init_all = mv88e6390_g2_irl_init_all,
4357 4358
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4359 4360 4361 4362
	.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,
4363
	.port_sync_link = mv88e6xxx_port_sync_link,
4364
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4365
	.port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
4366
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
4367
	.port_tag_remap = mv88e6390_port_tag_remap,
4368
	.port_set_policy = mv88e6352_port_set_policy,
4369
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4370 4371
	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4372
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4373
	.port_pause_limit = mv88e6390_port_pause_limit,
4374
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4375
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4376
	.port_get_cmode = mv88e6352_port_get_cmode,
4377
	.port_set_cmode = mv88e6390_port_set_cmode,
4378
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4379
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4380
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4381 4382
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4383
	.stats_get_stats = mv88e6390_stats_get_stats,
4384 4385
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4386
	.watchdog_ops = &mv88e6390_watchdog_ops,
4387
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4388
	.pot_clear = mv88e6xxx_g2_pot_clear,
4389
	.reset = mv88e6352_g1_reset,
4390
	.rmu_disable = mv88e6390_g1_rmu_disable,
4391 4392
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4393 4394
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4395
	.serdes_power = mv88e6390_serdes_power,
4396
	.serdes_get_lane = mv88e6390_serdes_get_lane,
4397 4398 4399 4400 4401
	/* 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,
4402
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4403
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4404
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4405 4406
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
4407 4408
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
4409
	.gpio_ops = &mv88e6352_gpio_ops,
4410
	.avb_ops = &mv88e6390_avb_ops,
4411
	.ptp_ops = &mv88e6352_ptp_ops,
4412
	.phylink_validate = mv88e6390_phylink_validate,
4413 4414
};

4415
static const struct mv88e6xxx_ops mv88e6320_ops = {
4416
	/* MV88E6XXX_FAMILY_6320 */
4417 4418
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4419
	.irl_init_all = mv88e6352_g2_irl_init_all,
4420 4421
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
4422
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4423 4424
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4425
	.port_set_link = mv88e6xxx_port_set_link,
4426
	.port_sync_link = mv88e6xxx_port_sync_link,
4427
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4428
	.port_tag_remap = mv88e6095_port_tag_remap,
4429
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4430 4431
	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4432
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4433
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4434
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4435
	.port_pause_limit = mv88e6097_port_pause_limit,
4436
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4437
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4438
	.port_get_cmode = mv88e6352_port_get_cmode,
4439
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4440
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4441
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4442 4443
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4444
	.stats_get_stats = mv88e6320_stats_get_stats,
4445 4446
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4447
	.watchdog_ops = &mv88e6390_watchdog_ops,
4448
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4449
	.pot_clear = mv88e6xxx_g2_pot_clear,
4450
	.reset = mv88e6352_g1_reset,
4451
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
4452
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
4453
	.gpio_ops = &mv88e6352_gpio_ops,
4454
	.avb_ops = &mv88e6352_avb_ops,
4455
	.ptp_ops = &mv88e6352_ptp_ops,
4456
	.phylink_validate = mv88e6185_phylink_validate,
4457 4458 4459
};

static const struct mv88e6xxx_ops mv88e6321_ops = {
4460
	/* MV88E6XXX_FAMILY_6320 */
4461 4462
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4463
	.irl_init_all = mv88e6352_g2_irl_init_all,
4464 4465
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
4466
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4467 4468
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4469
	.port_set_link = mv88e6xxx_port_set_link,
4470
	.port_sync_link = mv88e6xxx_port_sync_link,
4471
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4472
	.port_tag_remap = mv88e6095_port_tag_remap,
4473
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4474 4475
	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4476
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4477
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4478
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4479
	.port_pause_limit = mv88e6097_port_pause_limit,
4480
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4481
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4482
	.port_get_cmode = mv88e6352_port_get_cmode,
4483
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4484
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4485
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4486 4487
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4488
	.stats_get_stats = mv88e6320_stats_get_stats,
4489 4490
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4491
	.watchdog_ops = &mv88e6390_watchdog_ops,
4492
	.reset = mv88e6352_g1_reset,
4493
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
4494
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
4495
	.gpio_ops = &mv88e6352_gpio_ops,
4496
	.avb_ops = &mv88e6352_avb_ops,
4497
	.ptp_ops = &mv88e6352_ptp_ops,
4498
	.phylink_validate = mv88e6185_phylink_validate,
4499 4500
};

4501 4502
static const struct mv88e6xxx_ops mv88e6341_ops = {
	/* MV88E6XXX_FAMILY_6341 */
4503 4504
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4505
	.irl_init_all = mv88e6352_g2_irl_init_all,
4506 4507 4508 4509 4510 4511
	.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,
4512
	.port_sync_link = mv88e6xxx_port_sync_link,
4513
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4514
	.port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
4515
	.port_max_speed_mode = mv88e6341_port_max_speed_mode,
4516
	.port_tag_remap = mv88e6095_port_tag_remap,
4517
	.port_set_policy = mv88e6352_port_set_policy,
4518
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4519 4520
	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4521
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4522
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4523
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4524
	.port_pause_limit = mv88e6097_port_pause_limit,
4525 4526
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4527
	.port_get_cmode = mv88e6352_port_get_cmode,
4528
	.port_set_cmode = mv88e6341_port_set_cmode,
4529
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4530
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4531
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4532 4533 4534
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
4535 4536
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4537 4538
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
4539
	.pot_clear = mv88e6xxx_g2_pot_clear,
4540
	.reset = mv88e6352_g1_reset,
4541
	.rmu_disable = mv88e6390_g1_rmu_disable,
4542 4543
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4544
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4545
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4546 4547
	.serdes_power = mv88e6390_serdes_power,
	.serdes_get_lane = mv88e6341_serdes_get_lane,
4548 4549 4550 4551 4552
	/* 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,
4553
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4554
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4555
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4556
	.gpio_ops = &mv88e6352_gpio_ops,
4557
	.avb_ops = &mv88e6390_avb_ops,
4558
	.ptp_ops = &mv88e6352_ptp_ops,
4559 4560 4561
	.serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
4562 4563
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
4564
	.phylink_validate = mv88e6341_phylink_validate,
4565 4566
};

4567
static const struct mv88e6xxx_ops mv88e6350_ops = {
4568
	/* MV88E6XXX_FAMILY_6351 */
4569 4570
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4571
	.irl_init_all = mv88e6352_g2_irl_init_all,
4572
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4573 4574
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4575
	.port_set_link = mv88e6xxx_port_set_link,
4576
	.port_sync_link = mv88e6xxx_port_sync_link,
4577
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4578
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4579
	.port_tag_remap = mv88e6095_port_tag_remap,
4580
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4581 4582
	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4583
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4584
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4585
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4586
	.port_pause_limit = mv88e6097_port_pause_limit,
4587
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4588
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4589
	.port_get_cmode = mv88e6352_port_get_cmode,
4590
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4591
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4592
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4593 4594
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
4595
	.stats_get_stats = mv88e6095_stats_get_stats,
4596 4597
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4598
	.watchdog_ops = &mv88e6097_watchdog_ops,
4599
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4600
	.pot_clear = mv88e6xxx_g2_pot_clear,
4601
	.reset = mv88e6352_g1_reset,
4602 4603
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4604
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4605
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4606
	.phylink_validate = mv88e6185_phylink_validate,
4607 4608 4609
};

static const struct mv88e6xxx_ops mv88e6351_ops = {
4610
	/* MV88E6XXX_FAMILY_6351 */
4611 4612
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4613
	.irl_init_all = mv88e6352_g2_irl_init_all,
4614
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4615 4616
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4617
	.port_set_link = mv88e6xxx_port_set_link,
4618
	.port_sync_link = mv88e6xxx_port_sync_link,
4619
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4620
	.port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4621
	.port_tag_remap = mv88e6095_port_tag_remap,
4622
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4623 4624
	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4625
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4626
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4627
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4628
	.port_pause_limit = mv88e6097_port_pause_limit,
4629
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4630
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4631
	.port_get_cmode = mv88e6352_port_get_cmode,
4632
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4633
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4634
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4635 4636
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
4637
	.stats_get_stats = mv88e6095_stats_get_stats,
4638 4639
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4640
	.watchdog_ops = &mv88e6097_watchdog_ops,
4641
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4642
	.pot_clear = mv88e6xxx_g2_pot_clear,
4643
	.reset = mv88e6352_g1_reset,
4644 4645
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4646
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4647
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4648
	.avb_ops = &mv88e6352_avb_ops,
4649
	.ptp_ops = &mv88e6352_ptp_ops,
4650
	.phylink_validate = mv88e6185_phylink_validate,
4651 4652 4653
};

static const struct mv88e6xxx_ops mv88e6352_ops = {
4654
	/* MV88E6XXX_FAMILY_6352 */
4655 4656
	.ieee_pri_map = mv88e6085_g1_ieee_pri_map,
	.ip_pri_map = mv88e6085_g1_ip_pri_map,
4657
	.irl_init_all = mv88e6352_g2_irl_init_all,
4658 4659
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
4660
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4661 4662
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
4663
	.port_set_link = mv88e6xxx_port_set_link,
4664
	.port_sync_link = mv88e6xxx_port_sync_link,
4665
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4666
	.port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
4667
	.port_tag_remap = mv88e6095_port_tag_remap,
4668
	.port_set_policy = mv88e6352_port_set_policy,
4669
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4670 4671
	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4672
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4673
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4674
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4675
	.port_pause_limit = mv88e6097_port_pause_limit,
4676
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4677
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4678
	.port_get_cmode = mv88e6352_port_get_cmode,
4679
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4680
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
4681
	.stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4682 4683
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
4684
	.stats_get_stats = mv88e6095_stats_get_stats,
4685 4686
	.set_cpu_port = mv88e6095_g1_set_cpu_port,
	.set_egress_port = mv88e6095_g1_set_egress_port,
4687
	.watchdog_ops = &mv88e6097_watchdog_ops,
4688
	.mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4689
	.pot_clear = mv88e6xxx_g2_pot_clear,
4690
	.reset = mv88e6352_g1_reset,
4691
	.rmu_disable = mv88e6352_g1_rmu_disable,
4692 4693
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4694
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
4695
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4696
	.serdes_get_lane = mv88e6352_serdes_get_lane,
4697 4698 4699 4700
	.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,
4701
	.serdes_power = mv88e6352_serdes_power,
4702
	.serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
4703
	.serdes_irq_enable = mv88e6352_serdes_irq_enable,
4704
	.serdes_irq_status = mv88e6352_serdes_irq_status,
4705
	.gpio_ops = &mv88e6352_gpio_ops,
4706
	.avb_ops = &mv88e6352_avb_ops,
4707
	.ptp_ops = &mv88e6352_ptp_ops,
4708 4709 4710
	.serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
	.serdes_get_strings = mv88e6352_serdes_get_strings,
	.serdes_get_stats = mv88e6352_serdes_get_stats,
4711 4712
	.serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
	.serdes_get_regs = mv88e6352_serdes_get_regs,
4713
	.phylink_validate = mv88e6352_phylink_validate,
4714 4715
};

4716
static const struct mv88e6xxx_ops mv88e6390_ops = {
4717
	/* MV88E6XXX_FAMILY_6390 */
4718
	.setup_errata = mv88e6390_setup_errata,
4719
	.irl_init_all = mv88e6390_g2_irl_init_all,
4720 4721
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4722 4723 4724 4725
	.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,
4726
	.port_sync_link = mv88e6xxx_port_sync_link,
4727
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4728
	.port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
4729
	.port_max_speed_mode = mv88e6390_port_max_speed_mode,
4730
	.port_tag_remap = mv88e6390_port_tag_remap,
4731
	.port_set_policy = mv88e6352_port_set_policy,
4732
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4733 4734
	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4735
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4736
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4737
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4738
	.port_pause_limit = mv88e6390_port_pause_limit,
4739
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4740
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4741
	.port_get_cmode = mv88e6352_port_get_cmode,
4742
	.port_set_cmode = mv88e6390_port_set_cmode,
4743
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4744
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4745
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4746 4747
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4748
	.stats_get_stats = mv88e6390_stats_get_stats,
4749 4750
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4751
	.watchdog_ops = &mv88e6390_watchdog_ops,
4752
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4753
	.pot_clear = mv88e6xxx_g2_pot_clear,
4754
	.reset = mv88e6352_g1_reset,
4755
	.rmu_disable = mv88e6390_g1_rmu_disable,
4756 4757
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4758 4759
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4760
	.serdes_power = mv88e6390_serdes_power,
4761
	.serdes_get_lane = mv88e6390_serdes_get_lane,
4762 4763 4764 4765 4766
	/* 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,
4767
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4768
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4769
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4770
	.gpio_ops = &mv88e6352_gpio_ops,
4771
	.avb_ops = &mv88e6390_avb_ops,
4772
	.ptp_ops = &mv88e6352_ptp_ops,
4773 4774 4775
	.serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
4776 4777
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
4778
	.phylink_validate = mv88e6390_phylink_validate,
4779 4780 4781
};

static const struct mv88e6xxx_ops mv88e6390x_ops = {
4782
	/* MV88E6XXX_FAMILY_6390 */
4783
	.setup_errata = mv88e6390_setup_errata,
4784
	.irl_init_all = mv88e6390_g2_irl_init_all,
4785 4786
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
4787 4788 4789 4790
	.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,
4791
	.port_sync_link = mv88e6xxx_port_sync_link,
4792
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4793
	.port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
4794
	.port_max_speed_mode = mv88e6390x_port_max_speed_mode,
4795
	.port_tag_remap = mv88e6390_port_tag_remap,
4796
	.port_set_policy = mv88e6352_port_set_policy,
4797
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
4798 4799
	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4800
	.port_set_ether_type = mv88e6351_port_set_ether_type,
4801
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4802
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4803
	.port_pause_limit = mv88e6390_port_pause_limit,
4804
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4805
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4806
	.port_get_cmode = mv88e6352_port_get_cmode,
4807
	.port_set_cmode = mv88e6390x_port_set_cmode,
4808
	.port_setup_message_port = mv88e6xxx_setup_message_port,
4809
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
4810
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4811 4812
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
4813
	.stats_get_stats = mv88e6390_stats_get_stats,
4814 4815
	.set_cpu_port = mv88e6390_g1_set_cpu_port,
	.set_egress_port = mv88e6390_g1_set_egress_port,
4816
	.watchdog_ops = &mv88e6390_watchdog_ops,
4817
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4818
	.pot_clear = mv88e6xxx_g2_pot_clear,
4819
	.reset = mv88e6352_g1_reset,
4820
	.rmu_disable = mv88e6390_g1_rmu_disable,
4821 4822
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
4823 4824
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4825
	.serdes_power = mv88e6390_serdes_power,
4826
	.serdes_get_lane = mv88e6390x_serdes_get_lane,
4827 4828 4829 4830
	.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,
4831
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4832
	.serdes_irq_enable = mv88e6390_serdes_irq_enable,
4833
	.serdes_irq_status = mv88e6390_serdes_irq_status,
4834 4835 4836
	.serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
	.serdes_get_strings = mv88e6390_serdes_get_strings,
	.serdes_get_stats = mv88e6390_serdes_get_stats,
4837 4838
	.serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
	.serdes_get_regs = mv88e6390_serdes_get_regs,
4839
	.gpio_ops = &mv88e6352_gpio_ops,
4840
	.avb_ops = &mv88e6390_avb_ops,
4841
	.ptp_ops = &mv88e6352_ptp_ops,
4842
	.phylink_validate = mv88e6390x_phylink_validate,
4843 4844
};

4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859
static const struct mv88e6xxx_ops mv88e6393x_ops = {
	/* MV88E6XXX_FAMILY_6393 */
	.setup_errata = mv88e6393x_serdes_setup_errata,
	.irl_init_all = mv88e6390_g2_irl_init_all,
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_sync_link = mv88e6xxx_port_sync_link,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
	.port_set_speed_duplex = mv88e6393x_port_set_speed_duplex,
	.port_max_speed_mode = mv88e6393x_port_max_speed_mode,
	.port_tag_remap = mv88e6390_port_tag_remap,
4860
	.port_set_policy = mv88e6393x_port_set_policy,
4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
	.port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
	.port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
	.port_set_ether_type = mv88e6393x_port_set_ether_type,
	.port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
	.port_pause_limit = mv88e6390_port_pause_limit,
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
	.port_get_cmode = mv88e6352_port_get_cmode,
	.port_set_cmode = mv88e6393x_port_set_cmode,
	.port_setup_message_port = mv88e6xxx_setup_message_port,
	.port_set_upstream_port = mv88e6393x_port_set_upstream_port,
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
	/* .set_cpu_port is missing because this family does not support a global
	 * CPU port, only per port CPU port which is set via
	 * .port_set_upstream_port method.
	 */
	.set_egress_port = mv88e6393x_set_egress_port,
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu = mv88e6393x_port_mgmt_rsvd2cpu,
	.pot_clear = mv88e6xxx_g2_pot_clear,
	.reset = mv88e6352_g1_reset,
	.rmu_disable = mv88e6390_g1_rmu_disable,
	.atu_get_hash = mv88e6165_g1_atu_get_hash,
	.atu_set_hash = mv88e6165_g1_atu_set_hash,
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
	.serdes_power = mv88e6393x_serdes_power,
	.serdes_get_lane = mv88e6393x_serdes_get_lane,
	.serdes_pcs_get_state = mv88e6393x_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,
	.serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
	.serdes_irq_enable = mv88e6393x_serdes_irq_enable,
	.serdes_irq_status = mv88e6393x_serdes_irq_status,
	/* TODO: serdes stats */
	.gpio_ops = &mv88e6352_gpio_ops,
	.avb_ops = &mv88e6390_avb_ops,
	.ptp_ops = &mv88e6352_ptp_ops,
	.phylink_validate = mv88e6393x_phylink_validate,
};

4909 4910
static const struct mv88e6xxx_info mv88e6xxx_table[] = {
	[MV88E6085] = {
4911
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
4912 4913 4914
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6085",
		.num_databases = 4096,
4915
		.num_macs = 8192,
4916
		.num_ports = 10,
4917
		.num_internal_phys = 5,
4918
		.max_vid = 4095,
4919
		.port_base_addr = 0x10,
4920
		.phy_base_addr = 0x0,
4921
		.global1_addr = 0x1b,
4922
		.global2_addr = 0x1c,
4923
		.age_time_coeff = 15000,
4924
		.g1_irqs = 8,
4925
		.g2_irqs = 10,
4926
		.atu_move_port_mask = 0xf,
4927
		.pvt = true,
4928
		.multi_chip = true,
4929
		.ops = &mv88e6085_ops,
4930 4931 4932
	},

	[MV88E6095] = {
4933
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
4934 4935 4936
		.family = MV88E6XXX_FAMILY_6095,
		.name = "Marvell 88E6095/88E6095F",
		.num_databases = 256,
4937
		.num_macs = 8192,
4938
		.num_ports = 11,
4939
		.num_internal_phys = 0,
4940
		.max_vid = 4095,
4941
		.port_base_addr = 0x10,
4942
		.phy_base_addr = 0x0,
4943
		.global1_addr = 0x1b,
4944
		.global2_addr = 0x1c,
4945
		.age_time_coeff = 15000,
4946
		.g1_irqs = 8,
4947
		.atu_move_port_mask = 0xf,
4948
		.multi_chip = true,
4949
		.ops = &mv88e6095_ops,
4950 4951
	},

4952
	[MV88E6097] = {
4953
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
4954 4955 4956
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6097/88E6097F",
		.num_databases = 4096,
4957
		.num_macs = 8192,
4958
		.num_ports = 11,
4959
		.num_internal_phys = 8,
4960
		.max_vid = 4095,
4961
		.port_base_addr = 0x10,
4962
		.phy_base_addr = 0x0,
4963
		.global1_addr = 0x1b,
4964
		.global2_addr = 0x1c,
4965
		.age_time_coeff = 15000,
4966
		.g1_irqs = 8,
4967
		.g2_irqs = 10,
4968
		.atu_move_port_mask = 0xf,
4969
		.pvt = true,
4970
		.multi_chip = true,
4971
		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
4972 4973 4974
		.ops = &mv88e6097_ops,
	},

4975
	[MV88E6123] = {
4976
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
4977 4978 4979
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6123",
		.num_databases = 4096,
4980
		.num_macs = 1024,
4981
		.num_ports = 3,
4982
		.num_internal_phys = 5,
4983
		.max_vid = 4095,
4984
		.port_base_addr = 0x10,
4985
		.phy_base_addr = 0x0,
4986
		.global1_addr = 0x1b,
4987
		.global2_addr = 0x1c,
4988
		.age_time_coeff = 15000,
4989
		.g1_irqs = 9,
4990
		.g2_irqs = 10,
4991
		.atu_move_port_mask = 0xf,
4992
		.pvt = true,
4993
		.multi_chip = true,
4994
		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
4995
		.ops = &mv88e6123_ops,
4996 4997 4998
	},

	[MV88E6131] = {
4999
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
5000 5001 5002
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6131",
		.num_databases = 256,
5003
		.num_macs = 8192,
5004
		.num_ports = 8,
5005
		.num_internal_phys = 0,
5006
		.max_vid = 4095,
5007
		.port_base_addr = 0x10,
5008
		.phy_base_addr = 0x0,
5009
		.global1_addr = 0x1b,
5010
		.global2_addr = 0x1c,
5011
		.age_time_coeff = 15000,
5012
		.g1_irqs = 9,
5013
		.atu_move_port_mask = 0xf,
5014
		.multi_chip = true,
5015
		.ops = &mv88e6131_ops,
5016 5017
	},

5018
	[MV88E6141] = {
5019
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
5020
		.family = MV88E6XXX_FAMILY_6341,
5021
		.name = "Marvell 88E6141",
5022
		.num_databases = 4096,
5023
		.num_macs = 2048,
5024
		.num_ports = 6,
5025
		.num_internal_phys = 5,
5026
		.num_gpio = 11,
5027
		.max_vid = 4095,
5028
		.port_base_addr = 0x10,
5029
		.phy_base_addr = 0x10,
5030
		.global1_addr = 0x1b,
5031
		.global2_addr = 0x1c,
5032 5033
		.age_time_coeff = 3750,
		.atu_move_port_mask = 0x1f,
5034
		.g1_irqs = 9,
5035
		.g2_irqs = 10,
5036
		.pvt = true,
5037
		.multi_chip = true,
5038
		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5039 5040 5041
		.ops = &mv88e6141_ops,
	},

5042
	[MV88E6161] = {
5043
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
5044 5045 5046
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6161",
		.num_databases = 4096,
5047
		.num_macs = 1024,
5048
		.num_ports = 6,
5049
		.num_internal_phys = 5,
5050
		.max_vid = 4095,
5051
		.port_base_addr = 0x10,
5052
		.phy_base_addr = 0x0,
5053
		.global1_addr = 0x1b,
5054
		.global2_addr = 0x1c,
5055
		.age_time_coeff = 15000,
5056
		.g1_irqs = 9,
5057
		.g2_irqs = 10,
5058
		.atu_move_port_mask = 0xf,
5059
		.pvt = true,
5060
		.multi_chip = true,
5061
		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5062
		.ptp_support = true,
5063
		.ops = &mv88e6161_ops,
5064 5065 5066
	},

	[MV88E6165] = {
5067
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
5068 5069 5070
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6165",
		.num_databases = 4096,
5071
		.num_macs = 8192,
5072
		.num_ports = 6,
5073
		.num_internal_phys = 0,
5074
		.max_vid = 4095,
5075
		.port_base_addr = 0x10,
5076
		.phy_base_addr = 0x0,
5077
		.global1_addr = 0x1b,
5078
		.global2_addr = 0x1c,
5079
		.age_time_coeff = 15000,
5080
		.g1_irqs = 9,
5081
		.g2_irqs = 10,
5082
		.atu_move_port_mask = 0xf,
5083
		.pvt = true,
5084
		.multi_chip = true,
5085
		.ptp_support = true,
5086
		.ops = &mv88e6165_ops,
5087 5088 5089
	},

	[MV88E6171] = {
5090
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
5091 5092 5093
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6171",
		.num_databases = 4096,
5094
		.num_macs = 8192,
5095
		.num_ports = 7,
5096
		.num_internal_phys = 5,
5097
		.max_vid = 4095,
5098
		.port_base_addr = 0x10,
5099
		.phy_base_addr = 0x0,
5100
		.global1_addr = 0x1b,
5101
		.global2_addr = 0x1c,
5102
		.age_time_coeff = 15000,
5103
		.g1_irqs = 9,
5104
		.g2_irqs = 10,
5105
		.atu_move_port_mask = 0xf,
5106
		.pvt = true,
5107
		.multi_chip = true,
5108
		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5109
		.ops = &mv88e6171_ops,
5110 5111 5112
	},

	[MV88E6172] = {
5113
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
5114 5115 5116
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6172",
		.num_databases = 4096,
5117
		.num_macs = 8192,
5118
		.num_ports = 7,
5119
		.num_internal_phys = 5,
5120
		.num_gpio = 15,
5121
		.max_vid = 4095,
5122
		.port_base_addr = 0x10,
5123
		.phy_base_addr = 0x0,
5124
		.global1_addr = 0x1b,
5125
		.global2_addr = 0x1c,
5126
		.age_time_coeff = 15000,
5127
		.g1_irqs = 9,
5128
		.g2_irqs = 10,
5129
		.atu_move_port_mask = 0xf,
5130
		.pvt = true,
5131
		.multi_chip = true,
5132
		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5133
		.ops = &mv88e6172_ops,
5134 5135 5136
	},

	[MV88E6175] = {
5137
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
5138 5139 5140
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6175",
		.num_databases = 4096,
5141
		.num_macs = 8192,
5142
		.num_ports = 7,
5143
		.num_internal_phys = 5,
5144
		.max_vid = 4095,
5145
		.port_base_addr = 0x10,
5146
		.phy_base_addr = 0x0,
5147
		.global1_addr = 0x1b,
5148
		.global2_addr = 0x1c,
5149
		.age_time_coeff = 15000,
5150
		.g1_irqs = 9,
5151
		.g2_irqs = 10,
5152
		.atu_move_port_mask = 0xf,
5153
		.pvt = true,
5154
		.multi_chip = true,
5155
		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5156
		.ops = &mv88e6175_ops,
5157 5158 5159
	},

	[MV88E6176] = {
5160
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
5161 5162 5163
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6176",
		.num_databases = 4096,
5164
		.num_macs = 8192,
5165
		.num_ports = 7,
5166
		.num_internal_phys = 5,
5167
		.num_gpio = 15,
5168
		.max_vid = 4095,
5169
		.port_base_addr = 0x10,
5170
		.phy_base_addr = 0x0,
5171
		.global1_addr = 0x1b,
5172
		.global2_addr = 0x1c,
5173
		.age_time_coeff = 15000,
5174
		.g1_irqs = 9,
5175
		.g2_irqs = 10,
5176
		.atu_move_port_mask = 0xf,
5177
		.pvt = true,
5178
		.multi_chip = true,
5179
		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5180
		.ops = &mv88e6176_ops,
5181 5182 5183
	},

	[MV88E6185] = {
5184
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
5185 5186 5187
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6185",
		.num_databases = 256,
5188
		.num_macs = 8192,
5189
		.num_ports = 10,
5190
		.num_internal_phys = 0,
5191
		.max_vid = 4095,
5192
		.port_base_addr = 0x10,
5193
		.phy_base_addr = 0x0,
5194
		.global1_addr = 0x1b,
5195
		.global2_addr = 0x1c,
5196
		.age_time_coeff = 15000,
5197
		.g1_irqs = 8,
5198
		.atu_move_port_mask = 0xf,
5199
		.multi_chip = true,
5200
		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5201
		.ops = &mv88e6185_ops,
5202 5203
	},

5204
	[MV88E6190] = {
5205
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
5206 5207 5208
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190",
		.num_databases = 4096,
5209
		.num_macs = 16384,
5210
		.num_ports = 11,	/* 10 + Z80 */
5211
		.num_internal_phys = 9,
5212
		.num_gpio = 16,
5213
		.max_vid = 8191,
5214
		.port_base_addr = 0x0,
5215
		.phy_base_addr = 0x0,
5216
		.global1_addr = 0x1b,
5217
		.global2_addr = 0x1c,
5218
		.age_time_coeff = 3750,
5219
		.g1_irqs = 9,
5220
		.g2_irqs = 14,
5221
		.pvt = true,
5222
		.multi_chip = true,
5223
		.atu_move_port_mask = 0x1f,
5224 5225 5226 5227
		.ops = &mv88e6190_ops,
	},

	[MV88E6190X] = {
5228
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
5229 5230 5231
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190X",
		.num_databases = 4096,
5232
		.num_macs = 16384,
5233
		.num_ports = 11,	/* 10 + Z80 */
5234
		.num_internal_phys = 9,
5235
		.num_gpio = 16,
5236
		.max_vid = 8191,
5237
		.port_base_addr = 0x0,
5238
		.phy_base_addr = 0x0,
5239
		.global1_addr = 0x1b,
5240
		.global2_addr = 0x1c,
5241
		.age_time_coeff = 3750,
5242
		.g1_irqs = 9,
5243
		.g2_irqs = 14,
5244
		.atu_move_port_mask = 0x1f,
5245
		.pvt = true,
5246
		.multi_chip = true,
5247 5248 5249 5250
		.ops = &mv88e6190x_ops,
	},

	[MV88E6191] = {
5251
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
5252 5253 5254
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6191",
		.num_databases = 4096,
5255
		.num_macs = 16384,
5256
		.num_ports = 11,	/* 10 + Z80 */
5257
		.num_internal_phys = 9,
5258
		.max_vid = 8191,
5259
		.port_base_addr = 0x0,
5260
		.phy_base_addr = 0x0,
5261
		.global1_addr = 0x1b,
5262
		.global2_addr = 0x1c,
5263
		.age_time_coeff = 3750,
5264
		.g1_irqs = 9,
5265
		.g2_irqs = 14,
5266
		.atu_move_port_mask = 0x1f,
5267
		.pvt = true,
5268
		.multi_chip = true,
5269
		.ptp_support = true,
5270
		.ops = &mv88e6191_ops,
5271 5272
	},

5273 5274 5275 5276 5277 5278 5279 5280 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
	[MV88E6191X] = {
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191X,
		.family = MV88E6XXX_FAMILY_6393,
		.name = "Marvell 88E6191X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
		.num_internal_phys = 9,
		.max_vid = 8191,
		.port_base_addr = 0x0,
		.phy_base_addr = 0x0,
		.global1_addr = 0x1b,
		.global2_addr = 0x1c,
		.age_time_coeff = 3750,
		.g1_irqs = 10,
		.g2_irqs = 14,
		.atu_move_port_mask = 0x1f,
		.pvt = true,
		.multi_chip = true,
		.ptp_support = true,
		.ops = &mv88e6393x_ops,
	},

	[MV88E6193X] = {
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6193X,
		.family = MV88E6XXX_FAMILY_6393,
		.name = "Marvell 88E6193X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
		.num_internal_phys = 9,
		.max_vid = 8191,
		.port_base_addr = 0x0,
		.phy_base_addr = 0x0,
		.global1_addr = 0x1b,
		.global2_addr = 0x1c,
		.age_time_coeff = 3750,
		.g1_irqs = 10,
		.g2_irqs = 14,
		.atu_move_port_mask = 0x1f,
		.pvt = true,
		.multi_chip = true,
		.ptp_support = true,
		.ops = &mv88e6393x_ops,
	},

5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327
	[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,
5328
		.invalid_port_mask = BIT(2) | BIT(3) | BIT(4),
5329 5330 5331 5332 5333 5334 5335 5336 5337 5338
		.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,
5339
		.ptp_support = true,
5340 5341 5342
		.ops = &mv88e6250_ops,
	},

5343
	[MV88E6240] = {
5344
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
5345 5346 5347
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6240",
		.num_databases = 4096,
5348
		.num_macs = 8192,
5349
		.num_ports = 7,
5350
		.num_internal_phys = 5,
5351
		.num_gpio = 15,
5352
		.max_vid = 4095,
5353
		.port_base_addr = 0x10,
5354
		.phy_base_addr = 0x0,
5355
		.global1_addr = 0x1b,
5356
		.global2_addr = 0x1c,
5357
		.age_time_coeff = 15000,
5358
		.g1_irqs = 9,
5359
		.g2_irqs = 10,
5360
		.atu_move_port_mask = 0xf,
5361
		.pvt = true,
5362
		.multi_chip = true,
5363
		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5364
		.ptp_support = true,
5365
		.ops = &mv88e6240_ops,
5366 5367
	},

5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384
	[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,
5385
		.ptp_support = true,
5386 5387 5388
		.ops = &mv88e6250_ops,
	},

5389
	[MV88E6290] = {
5390
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
5391 5392 5393 5394
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6290",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
5395
		.num_internal_phys = 9,
5396
		.num_gpio = 16,
5397
		.max_vid = 8191,
5398
		.port_base_addr = 0x0,
5399
		.phy_base_addr = 0x0,
5400
		.global1_addr = 0x1b,
5401
		.global2_addr = 0x1c,
5402
		.age_time_coeff = 3750,
5403
		.g1_irqs = 9,
5404
		.g2_irqs = 14,
5405
		.atu_move_port_mask = 0x1f,
5406
		.pvt = true,
5407
		.multi_chip = true,
5408
		.ptp_support = true,
5409 5410 5411
		.ops = &mv88e6290_ops,
	},

5412
	[MV88E6320] = {
5413
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
5414 5415 5416
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6320",
		.num_databases = 4096,
5417
		.num_macs = 8192,
5418
		.num_ports = 7,
5419
		.num_internal_phys = 5,
5420
		.num_gpio = 15,
5421
		.max_vid = 4095,
5422
		.port_base_addr = 0x10,
5423
		.phy_base_addr = 0x0,
5424
		.global1_addr = 0x1b,
5425
		.global2_addr = 0x1c,
5426
		.age_time_coeff = 15000,
5427
		.g1_irqs = 8,
5428
		.g2_irqs = 10,
5429
		.atu_move_port_mask = 0xf,
5430
		.pvt = true,
5431
		.multi_chip = true,
5432
		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5433
		.ptp_support = true,
5434
		.ops = &mv88e6320_ops,
5435 5436 5437
	},

	[MV88E6321] = {
5438
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
5439 5440 5441
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6321",
		.num_databases = 4096,
5442
		.num_macs = 8192,
5443
		.num_ports = 7,
5444
		.num_internal_phys = 5,
5445
		.num_gpio = 15,
5446
		.max_vid = 4095,
5447
		.port_base_addr = 0x10,
5448
		.phy_base_addr = 0x0,
5449
		.global1_addr = 0x1b,
5450
		.global2_addr = 0x1c,
5451
		.age_time_coeff = 15000,
5452
		.g1_irqs = 8,
5453
		.g2_irqs = 10,
5454
		.atu_move_port_mask = 0xf,
5455
		.multi_chip = true,
5456
		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5457
		.ptp_support = true,
5458
		.ops = &mv88e6321_ops,
5459 5460
	},

5461
	[MV88E6341] = {
5462
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
5463 5464 5465
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
5466
		.num_macs = 2048,
5467
		.num_internal_phys = 5,
5468
		.num_ports = 6,
5469
		.num_gpio = 11,
5470
		.max_vid = 4095,
5471
		.port_base_addr = 0x10,
5472
		.phy_base_addr = 0x10,
5473
		.global1_addr = 0x1b,
5474
		.global2_addr = 0x1c,
5475
		.age_time_coeff = 3750,
5476
		.atu_move_port_mask = 0x1f,
5477
		.g1_irqs = 9,
5478
		.g2_irqs = 10,
5479
		.pvt = true,
5480
		.multi_chip = true,
5481
		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5482
		.ptp_support = true,
5483 5484 5485
		.ops = &mv88e6341_ops,
	},

5486
	[MV88E6350] = {
5487
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
5488 5489 5490
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6350",
		.num_databases = 4096,
5491
		.num_macs = 8192,
5492
		.num_ports = 7,
5493
		.num_internal_phys = 5,
5494
		.max_vid = 4095,
5495
		.port_base_addr = 0x10,
5496
		.phy_base_addr = 0x0,
5497
		.global1_addr = 0x1b,
5498
		.global2_addr = 0x1c,
5499
		.age_time_coeff = 15000,
5500
		.g1_irqs = 9,
5501
		.g2_irqs = 10,
5502
		.atu_move_port_mask = 0xf,
5503
		.pvt = true,
5504
		.multi_chip = true,
5505
		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5506
		.ops = &mv88e6350_ops,
5507 5508 5509
	},

	[MV88E6351] = {
5510
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
5511 5512 5513
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6351",
		.num_databases = 4096,
5514
		.num_macs = 8192,
5515
		.num_ports = 7,
5516
		.num_internal_phys = 5,
5517
		.max_vid = 4095,
5518
		.port_base_addr = 0x10,
5519
		.phy_base_addr = 0x0,
5520
		.global1_addr = 0x1b,
5521
		.global2_addr = 0x1c,
5522
		.age_time_coeff = 15000,
5523
		.g1_irqs = 9,
5524
		.g2_irqs = 10,
5525
		.atu_move_port_mask = 0xf,
5526
		.pvt = true,
5527
		.multi_chip = true,
5528
		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5529
		.ops = &mv88e6351_ops,
5530 5531 5532
	},

	[MV88E6352] = {
5533
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
5534 5535 5536
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6352",
		.num_databases = 4096,
5537
		.num_macs = 8192,
5538
		.num_ports = 7,
5539
		.num_internal_phys = 5,
5540
		.num_gpio = 15,
5541
		.max_vid = 4095,
5542
		.port_base_addr = 0x10,
5543
		.phy_base_addr = 0x0,
5544
		.global1_addr = 0x1b,
5545
		.global2_addr = 0x1c,
5546
		.age_time_coeff = 15000,
5547
		.g1_irqs = 9,
5548
		.g2_irqs = 10,
5549
		.atu_move_port_mask = 0xf,
5550
		.pvt = true,
5551
		.multi_chip = true,
5552
		.edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5553
		.ptp_support = true,
5554
		.ops = &mv88e6352_ops,
5555
	},
5556
	[MV88E6390] = {
5557
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
5558 5559 5560
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390",
		.num_databases = 4096,
5561
		.num_macs = 16384,
5562
		.num_ports = 11,	/* 10 + Z80 */
5563
		.num_internal_phys = 9,
5564
		.num_gpio = 16,
5565
		.max_vid = 8191,
5566
		.port_base_addr = 0x0,
5567
		.phy_base_addr = 0x0,
5568
		.global1_addr = 0x1b,
5569
		.global2_addr = 0x1c,
5570
		.age_time_coeff = 3750,
5571
		.g1_irqs = 9,
5572
		.g2_irqs = 14,
5573
		.atu_move_port_mask = 0x1f,
5574
		.pvt = true,
5575
		.multi_chip = true,
5576
		.edsa_support = MV88E6XXX_EDSA_UNDOCUMENTED,
5577
		.ptp_support = true,
5578 5579 5580
		.ops = &mv88e6390_ops,
	},
	[MV88E6390X] = {
5581
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
5582 5583 5584
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390X",
		.num_databases = 4096,
5585
		.num_macs = 16384,
5586
		.num_ports = 11,	/* 10 + Z80 */
5587
		.num_internal_phys = 9,
5588
		.num_gpio = 16,
5589
		.max_vid = 8191,
5590
		.port_base_addr = 0x0,
5591
		.phy_base_addr = 0x0,
5592
		.global1_addr = 0x1b,
5593
		.global2_addr = 0x1c,
5594
		.age_time_coeff = 3750,
5595
		.g1_irqs = 9,
5596
		.g2_irqs = 14,
5597
		.atu_move_port_mask = 0x1f,
5598
		.pvt = true,
5599
		.multi_chip = true,
5600
		.edsa_support = MV88E6XXX_EDSA_UNDOCUMENTED,
5601
		.ptp_support = true,
5602 5603
		.ops = &mv88e6390x_ops,
	},
5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625

	[MV88E6393X] = {
		.prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6393X,
		.family = MV88E6XXX_FAMILY_6393,
		.name = "Marvell 88E6393X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
		.num_internal_phys = 9,
		.max_vid = 8191,
		.port_base_addr = 0x0,
		.phy_base_addr = 0x0,
		.global1_addr = 0x1b,
		.global2_addr = 0x1c,
		.age_time_coeff = 3750,
		.g1_irqs = 10,
		.g2_irqs = 14,
		.atu_move_port_mask = 0x1f,
		.pvt = true,
		.multi_chip = true,
		.ptp_support = true,
		.ops = &mv88e6393x_ops,
	},
5626 5627
};

5628
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
5629
{
5630
	int i;
5631

5632 5633 5634
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
5635 5636 5637 5638

	return NULL;
}

5639
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
5640 5641
{
	const struct mv88e6xxx_info *info;
5642 5643 5644
	unsigned int prod_num, rev;
	u16 id;
	int err;
5645

5646
	mv88e6xxx_reg_lock(chip);
5647
	err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
5648
	mv88e6xxx_reg_unlock(chip);
5649 5650
	if (err)
		return err;
5651

5652 5653
	prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
	rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
5654 5655 5656 5657 5658

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

5659
	/* Update the compatible info with the probed one */
5660
	chip->info = info;
5661

5662 5663
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
5664 5665 5666 5667

	return 0;
}

5668
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
5669
{
5670
	struct mv88e6xxx_chip *chip;
5671

5672 5673
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
5674 5675
		return NULL;

5676
	chip->dev = dev;
5677

5678
	mutex_init(&chip->reg_lock);
5679
	INIT_LIST_HEAD(&chip->mdios);
5680
	idr_init(&chip->policies);
5681

5682
	return chip;
5683 5684
}

5685
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
5686 5687
							int port,
							enum dsa_tag_protocol m)
5688
{
V
Vivien Didelot 已提交
5689
	struct mv88e6xxx_chip *chip = ds->priv;
5690

5691
	return chip->tag_protocol;
5692 5693
}

5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731
static int mv88e6xxx_change_tag_protocol(struct dsa_switch *ds, int port,
					 enum dsa_tag_protocol proto)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	enum dsa_tag_protocol old_protocol;
	int err;

	switch (proto) {
	case DSA_TAG_PROTO_EDSA:
		switch (chip->info->edsa_support) {
		case MV88E6XXX_EDSA_UNSUPPORTED:
			return -EPROTONOSUPPORT;
		case MV88E6XXX_EDSA_UNDOCUMENTED:
			dev_warn(chip->dev, "Relying on undocumented EDSA tagging behavior\n");
			fallthrough;
		case MV88E6XXX_EDSA_SUPPORTED:
			break;
		}
		break;
	case DSA_TAG_PROTO_DSA:
		break;
	default:
		return -EPROTONOSUPPORT;
	}

	old_protocol = chip->tag_protocol;
	chip->tag_protocol = proto;

	mv88e6xxx_reg_lock(chip);
	err = mv88e6xxx_setup_port_mode(chip, port);
	mv88e6xxx_reg_unlock(chip);

	if (err)
		chip->tag_protocol = old_protocol;

	return err;
}

5732 5733
static int mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
				  const struct switchdev_obj_port_mdb *mdb)
5734
{
V
Vivien Didelot 已提交
5735
	struct mv88e6xxx_chip *chip = ds->priv;
5736
	int err;
5737

5738
	mv88e6xxx_reg_lock(chip);
5739 5740
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
					   MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC);
5741
	mv88e6xxx_reg_unlock(chip);
5742 5743

	return err;
5744 5745 5746 5747 5748
}

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

5752
	mv88e6xxx_reg_lock(chip);
5753
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 0);
5754
	mv88e6xxx_reg_unlock(chip);
5755 5756 5757 5758

	return err;
}

5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784
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;

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

5785 5786
		err = mv88e6xxx_set_egress_port(chip, direction,
						mirror->to_local_port);
5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818
		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) {
5819 5820
		if (mv88e6xxx_set_egress_port(chip, direction,
					      dsa_upstream_port(ds, port)))
5821 5822 5823 5824 5825 5826
			dev_err(ds->dev, "failed to set egress port\n");
	}

	mutex_unlock(&chip->reg_lock);
}

5827 5828 5829 5830 5831 5832 5833
static int mv88e6xxx_port_pre_bridge_flags(struct dsa_switch *ds, int port,
					   struct switchdev_brport_flags flags,
					   struct netlink_ext_ack *extack)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	const struct mv88e6xxx_ops *ops;

5834 5835
	if (flags.mask & ~(BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD |
			   BR_BCAST_FLOOD))
5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851
		return -EINVAL;

	ops = chip->info->ops;

	if ((flags.mask & BR_FLOOD) && !ops->port_set_ucast_flood)
		return -EINVAL;

	if ((flags.mask & BR_MCAST_FLOOD) && !ops->port_set_mcast_flood)
		return -EINVAL;

	return 0;
}

static int mv88e6xxx_port_bridge_flags(struct dsa_switch *ds, int port,
				       struct switchdev_brport_flags flags,
				       struct netlink_ext_ack *extack)
5852 5853 5854 5855
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err = -EOPNOTSUPP;

5856
	mv88e6xxx_reg_lock(chip);
5857

5858 5859 5860 5861 5862 5863 5864 5865 5866
	if (flags.mask & BR_LEARNING) {
		bool learning = !!(flags.val & BR_LEARNING);
		u16 pav = learning ? (1 << port) : 0;

		err = mv88e6xxx_port_set_assoc_vector(chip, port, pav);
		if (err)
			goto out;
	}

5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884
	if (flags.mask & BR_FLOOD) {
		bool unicast = !!(flags.val & BR_FLOOD);

		err = chip->info->ops->port_set_ucast_flood(chip, port,
							    unicast);
		if (err)
			goto out;
	}

	if (flags.mask & BR_MCAST_FLOOD) {
		bool multicast = !!(flags.val & BR_MCAST_FLOOD);

		err = chip->info->ops->port_set_mcast_flood(chip, port,
							    multicast);
		if (err)
			goto out;
	}

5885 5886 5887 5888 5889 5890 5891 5892
	if (flags.mask & BR_BCAST_FLOOD) {
		bool broadcast = !!(flags.val & BR_BCAST_FLOOD);

		err = mv88e6xxx_port_broadcast_sync(chip, port, broadcast);
		if (err)
			goto out;
	}

5893 5894 5895 5896 5897 5898
out:
	mv88e6xxx_reg_unlock(chip);

	return err;
}

5899 5900 5901 5902
static bool mv88e6xxx_lag_can_offload(struct dsa_switch *ds,
				      struct net_device *lag,
				      struct netdev_lag_upper_info *info)
{
5903
	struct mv88e6xxx_chip *chip = ds->priv;
5904 5905 5906
	struct dsa_port *dp;
	int id, members = 0;

5907 5908 5909
	if (!mv88e6xxx_has_lag(chip))
		return false;

5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167
	id = dsa_lag_id(ds->dst, lag);
	if (id < 0 || id >= ds->num_lag_ids)
		return false;

	dsa_lag_foreach_port(dp, ds->dst, lag)
		/* Includes the port joining the LAG */
		members++;

	if (members > 8)
		return false;

	/* We could potentially relax this to include active
	 * backup in the future.
	 */
	if (info->tx_type != NETDEV_LAG_TX_TYPE_HASH)
		return false;

	/* Ideally we would also validate that the hash type matches
	 * the hardware. Alas, this is always set to unknown on team
	 * interfaces.
	 */
	return true;
}

static int mv88e6xxx_lag_sync_map(struct dsa_switch *ds, struct net_device *lag)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	struct dsa_port *dp;
	u16 map = 0;
	int id;

	id = dsa_lag_id(ds->dst, lag);

	/* Build the map of all ports to distribute flows destined for
	 * this LAG. This can be either a local user port, or a DSA
	 * port if the LAG port is on a remote chip.
	 */
	dsa_lag_foreach_port(dp, ds->dst, lag)
		map |= BIT(dsa_towards_port(ds, dp->ds->index, dp->index));

	return mv88e6xxx_g2_trunk_mapping_write(chip, id, map);
}

static const u8 mv88e6xxx_lag_mask_table[8][8] = {
	/* Row number corresponds to the number of active members in a
	 * LAG. Each column states which of the eight hash buckets are
	 * mapped to the column:th port in the LAG.
	 *
	 * Example: In a LAG with three active ports, the second port
	 * ([2][1]) would be selected for traffic mapped to buckets
	 * 3,4,5 (0x38).
	 */
	{ 0xff,    0,    0,    0,    0,    0,    0,    0 },
	{ 0x0f, 0xf0,    0,    0,    0,    0,    0,    0 },
	{ 0x07, 0x38, 0xc0,    0,    0,    0,    0,    0 },
	{ 0x03, 0x0c, 0x30, 0xc0,    0,    0,    0,    0 },
	{ 0x03, 0x0c, 0x30, 0x40, 0x80,    0,    0,    0 },
	{ 0x03, 0x0c, 0x10, 0x20, 0x40, 0x80,    0,    0 },
	{ 0x03, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,    0 },
	{ 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 },
};

static void mv88e6xxx_lag_set_port_mask(u16 *mask, int port,
					int num_tx, int nth)
{
	u8 active = 0;
	int i;

	num_tx = num_tx <= 8 ? num_tx : 8;
	if (nth < num_tx)
		active = mv88e6xxx_lag_mask_table[num_tx - 1][nth];

	for (i = 0; i < 8; i++) {
		if (BIT(i) & active)
			mask[i] |= BIT(port);
	}
}

static int mv88e6xxx_lag_sync_masks(struct dsa_switch *ds)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	unsigned int id, num_tx;
	struct net_device *lag;
	struct dsa_port *dp;
	int i, err, nth;
	u16 mask[8];
	u16 ivec;

	/* Assume no port is a member of any LAG. */
	ivec = BIT(mv88e6xxx_num_ports(chip)) - 1;

	/* Disable all masks for ports that _are_ members of a LAG. */
	list_for_each_entry(dp, &ds->dst->ports, list) {
		if (!dp->lag_dev || dp->ds != ds)
			continue;

		ivec &= ~BIT(dp->index);
	}

	for (i = 0; i < 8; i++)
		mask[i] = ivec;

	/* Enable the correct subset of masks for all LAG ports that
	 * are in the Tx set.
	 */
	dsa_lags_foreach_id(id, ds->dst) {
		lag = dsa_lag_dev(ds->dst, id);
		if (!lag)
			continue;

		num_tx = 0;
		dsa_lag_foreach_port(dp, ds->dst, lag) {
			if (dp->lag_tx_enabled)
				num_tx++;
		}

		if (!num_tx)
			continue;

		nth = 0;
		dsa_lag_foreach_port(dp, ds->dst, lag) {
			if (!dp->lag_tx_enabled)
				continue;

			if (dp->ds == ds)
				mv88e6xxx_lag_set_port_mask(mask, dp->index,
							    num_tx, nth);

			nth++;
		}
	}

	for (i = 0; i < 8; i++) {
		err = mv88e6xxx_g2_trunk_mask_write(chip, i, true, mask[i]);
		if (err)
			return err;
	}

	return 0;
}

static int mv88e6xxx_lag_sync_masks_map(struct dsa_switch *ds,
					struct net_device *lag)
{
	int err;

	err = mv88e6xxx_lag_sync_masks(ds);

	if (!err)
		err = mv88e6xxx_lag_sync_map(ds, lag);

	return err;
}

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

	mv88e6xxx_reg_lock(chip);
	err = mv88e6xxx_lag_sync_masks(ds);
	mv88e6xxx_reg_unlock(chip);
	return err;
}

static int mv88e6xxx_port_lag_join(struct dsa_switch *ds, int port,
				   struct net_device *lag,
				   struct netdev_lag_upper_info *info)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err, id;

	if (!mv88e6xxx_lag_can_offload(ds, lag, info))
		return -EOPNOTSUPP;

	id = dsa_lag_id(ds->dst, lag);

	mv88e6xxx_reg_lock(chip);

	err = mv88e6xxx_port_set_trunk(chip, port, true, id);
	if (err)
		goto err_unlock;

	err = mv88e6xxx_lag_sync_masks_map(ds, lag);
	if (err)
		goto err_clear_trunk;

	mv88e6xxx_reg_unlock(chip);
	return 0;

err_clear_trunk:
	mv88e6xxx_port_set_trunk(chip, port, false, 0);
err_unlock:
	mv88e6xxx_reg_unlock(chip);
	return err;
}

static int mv88e6xxx_port_lag_leave(struct dsa_switch *ds, int port,
				    struct net_device *lag)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err_sync, err_trunk;

	mv88e6xxx_reg_lock(chip);
	err_sync = mv88e6xxx_lag_sync_masks_map(ds, lag);
	err_trunk = mv88e6xxx_port_set_trunk(chip, port, false, 0);
	mv88e6xxx_reg_unlock(chip);
	return err_sync ? : err_trunk;
}

static int mv88e6xxx_crosschip_lag_change(struct dsa_switch *ds, int sw_index,
					  int port)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

	mv88e6xxx_reg_lock(chip);
	err = mv88e6xxx_lag_sync_masks(ds);
	mv88e6xxx_reg_unlock(chip);
	return err;
}

static int mv88e6xxx_crosschip_lag_join(struct dsa_switch *ds, int sw_index,
					int port, struct net_device *lag,
					struct netdev_lag_upper_info *info)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

	if (!mv88e6xxx_lag_can_offload(ds, lag, info))
		return -EOPNOTSUPP;

	mv88e6xxx_reg_lock(chip);

	err = mv88e6xxx_lag_sync_masks_map(ds, lag);
	if (err)
		goto unlock;

	err = mv88e6xxx_pvt_map(chip, sw_index, port);

unlock:
	mv88e6xxx_reg_unlock(chip);
	return err;
}

static int mv88e6xxx_crosschip_lag_leave(struct dsa_switch *ds, int sw_index,
					 int port, struct net_device *lag)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err_sync, err_pvt;

	mv88e6xxx_reg_lock(chip);
	err_sync = mv88e6xxx_lag_sync_masks_map(ds, lag);
	err_pvt = mv88e6xxx_pvt_map(chip, sw_index, port);
	mv88e6xxx_reg_unlock(chip);
	return err_sync ? : err_pvt;
}

6168
static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
6169
	.get_tag_protocol	= mv88e6xxx_get_tag_protocol,
6170
	.change_tag_protocol	= mv88e6xxx_change_tag_protocol,
6171
	.setup			= mv88e6xxx_setup,
6172
	.teardown		= mv88e6xxx_teardown,
6173 6174
	.port_setup		= mv88e6xxx_port_setup,
	.port_teardown		= mv88e6xxx_port_teardown,
6175
	.phylink_validate	= mv88e6xxx_validate,
6176
	.phylink_mac_link_state	= mv88e6xxx_serdes_pcs_get_state,
6177
	.phylink_mac_config	= mv88e6xxx_mac_config,
6178
	.phylink_mac_an_restart	= mv88e6xxx_serdes_pcs_an_restart,
6179 6180
	.phylink_mac_link_down	= mv88e6xxx_mac_link_down,
	.phylink_mac_link_up	= mv88e6xxx_mac_link_up,
6181 6182 6183
	.get_strings		= mv88e6xxx_get_strings,
	.get_ethtool_stats	= mv88e6xxx_get_ethtool_stats,
	.get_sset_count		= mv88e6xxx_get_sset_count,
6184 6185
	.port_enable		= mv88e6xxx_port_enable,
	.port_disable		= mv88e6xxx_port_disable,
6186 6187
	.port_max_mtu		= mv88e6xxx_get_max_mtu,
	.port_change_mtu	= mv88e6xxx_change_mtu,
V
Vivien Didelot 已提交
6188 6189
	.get_mac_eee		= mv88e6xxx_get_mac_eee,
	.set_mac_eee		= mv88e6xxx_set_mac_eee,
6190
	.get_eeprom_len		= mv88e6xxx_get_eeprom_len,
6191 6192 6193 6194
	.get_eeprom		= mv88e6xxx_get_eeprom,
	.set_eeprom		= mv88e6xxx_set_eeprom,
	.get_regs_len		= mv88e6xxx_get_regs_len,
	.get_regs		= mv88e6xxx_get_regs,
6195 6196
	.get_rxnfc		= mv88e6xxx_get_rxnfc,
	.set_rxnfc		= mv88e6xxx_set_rxnfc,
6197
	.set_ageing_time	= mv88e6xxx_set_ageing_time,
6198 6199
	.port_bridge_join	= mv88e6xxx_port_bridge_join,
	.port_bridge_leave	= mv88e6xxx_port_bridge_leave,
6200 6201
	.port_pre_bridge_flags	= mv88e6xxx_port_pre_bridge_flags,
	.port_bridge_flags	= mv88e6xxx_port_bridge_flags,
6202
	.port_stp_state_set	= mv88e6xxx_port_stp_state_set,
6203
	.port_fast_age		= mv88e6xxx_port_fast_age,
6204 6205 6206 6207 6208 6209
	.port_vlan_filtering	= mv88e6xxx_port_vlan_filtering,
	.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,
6210 6211
	.port_mdb_add           = mv88e6xxx_port_mdb_add,
	.port_mdb_del           = mv88e6xxx_port_mdb_del,
6212 6213
	.port_mirror_add	= mv88e6xxx_port_mirror_add,
	.port_mirror_del	= mv88e6xxx_port_mirror_del,
6214 6215
	.crosschip_bridge_join	= mv88e6xxx_crosschip_bridge_join,
	.crosschip_bridge_leave	= mv88e6xxx_crosschip_bridge_leave,
6216 6217 6218 6219 6220
	.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,
6221 6222
	.devlink_param_get	= mv88e6xxx_devlink_param_get,
	.devlink_param_set	= mv88e6xxx_devlink_param_set,
6223
	.devlink_info_get	= mv88e6xxx_devlink_info_get,
6224 6225 6226 6227 6228 6229
	.port_lag_change	= mv88e6xxx_port_lag_change,
	.port_lag_join		= mv88e6xxx_port_lag_join,
	.port_lag_leave		= mv88e6xxx_port_lag_leave,
	.crosschip_lag_change	= mv88e6xxx_crosschip_lag_change,
	.crosschip_lag_join	= mv88e6xxx_crosschip_lag_join,
	.crosschip_lag_leave	= mv88e6xxx_crosschip_lag_leave,
6230 6231
	.port_bridge_tx_fwd_offload = mv88e6xxx_bridge_tx_fwd_offload,
	.port_bridge_tx_fwd_unoffload = mv88e6xxx_bridge_tx_fwd_unoffload,
6232 6233
};

6234
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
6235
{
6236
	struct device *dev = chip->dev;
6237 6238
	struct dsa_switch *ds;

6239
	ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
6240 6241 6242
	if (!ds)
		return -ENOMEM;

6243 6244
	ds->dev = dev;
	ds->num_ports = mv88e6xxx_num_ports(chip);
6245
	ds->priv = chip;
6246
	ds->dev = dev;
6247
	ds->ops = &mv88e6xxx_switch_ops;
6248 6249
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
6250

6251 6252 6253 6254
	/* Some chips support up to 32, but that requires enabling the
	 * 5-bit port mode, which we do not support. 640k^W16 ought to
	 * be enough for anyone.
	 */
6255
	ds->num_lag_ids = mv88e6xxx_has_lag(chip) ? 16 : 0;
6256

6257 6258
	dev_set_drvdata(dev, ds);

6259
	return dsa_register_switch(ds);
6260 6261
}

6262
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
6263
{
6264
	dsa_unregister_switch(chip->ds);
6265 6266
}

6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279
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;
}

6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294
/* 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);

6295
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
6296
{
6297
	struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
6298
	const struct mv88e6xxx_info *compat_info = NULL;
6299
	struct device *dev = &mdiodev->dev;
6300
	struct device_node *np = dev->of_node;
6301
	struct mv88e6xxx_chip *chip;
6302
	int port;
6303
	int err;
6304

6305 6306 6307
	if (!np && !pdata)
		return -EINVAL;

6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326
	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;
		}
	}

6327 6328 6329
	if (!compat_info)
		return -EINVAL;

6330
	chip = mv88e6xxx_alloc_chip(dev);
6331 6332 6333 6334
	if (!chip) {
		err = -ENOMEM;
		goto out;
	}
6335

6336
	chip->info = compat_info;
6337

6338
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
6339
	if (err)
6340
		goto out;
6341

6342
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
6343 6344 6345 6346
	if (IS_ERR(chip->reset)) {
		err = PTR_ERR(chip->reset);
		goto out;
	}
6347 6348
	if (chip->reset)
		usleep_range(1000, 2000);
6349

6350
	err = mv88e6xxx_detect(chip);
6351
	if (err)
6352
		goto out;
6353

6354 6355 6356 6357 6358
	if (chip->info->edsa_support == MV88E6XXX_EDSA_SUPPORTED)
		chip->tag_protocol = DSA_TAG_PROTO_EDSA;
	else
		chip->tag_protocol = DSA_TAG_PROTO_DSA;

6359 6360
	mv88e6xxx_phy_init(chip);

6361 6362 6363 6364 6365 6366 6367
	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;
	}
6368

6369
	mv88e6xxx_reg_lock(chip);
6370
	err = mv88e6xxx_switch_reset(chip);
6371
	mv88e6xxx_reg_unlock(chip);
6372 6373 6374
	if (err)
		goto out;

6375 6376 6377 6378 6379 6380
	if (np) {
		chip->irq = of_irq_get(np, 0);
		if (chip->irq == -EPROBE_DEFER) {
			err = chip->irq;
			goto out;
		}
6381 6382
	}

6383 6384 6385
	if (pdata)
		chip->irq = pdata->irq;

6386
	/* Has to be performed before the MDIO bus is created, because
6387
	 * the PHYs will link their interrupts to these interrupt
6388 6389
	 * controllers
	 */
6390
	mv88e6xxx_reg_lock(chip);
6391
	if (chip->irq > 0)
6392
		err = mv88e6xxx_g1_irq_setup(chip);
6393 6394
	else
		err = mv88e6xxx_irq_poll_setup(chip);
6395
	mv88e6xxx_reg_unlock(chip);
6396

6397 6398
	if (err)
		goto out;
6399

6400 6401
	if (chip->info->g2_irqs > 0) {
		err = mv88e6xxx_g2_irq_setup(chip);
6402
		if (err)
6403
			goto out_g1_irq;
6404 6405
	}

6406 6407 6408 6409 6410 6411 6412 6413
	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;

6414
	err = mv88e6xxx_mdios_register(chip, np);
6415
	if (err)
6416
		goto out_g1_vtu_prob_irq;
6417

6418
	err = mv88e6xxx_register_switch(chip);
6419 6420
	if (err)
		goto out_mdio;
6421

6422
	return 0;
6423 6424

out_mdio:
6425
	mv88e6xxx_mdios_unregister(chip);
6426
out_g1_vtu_prob_irq:
6427
	mv88e6xxx_g1_vtu_prob_irq_free(chip);
6428
out_g1_atu_prob_irq:
6429
	mv88e6xxx_g1_atu_prob_irq_free(chip);
6430
out_g2_irq:
6431
	if (chip->info->g2_irqs > 0)
6432 6433
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
6434
	if (chip->irq > 0)
6435
		mv88e6xxx_g1_irq_free(chip);
6436 6437
	else
		mv88e6xxx_irq_poll_free(chip);
6438
out:
6439 6440 6441
	if (pdata)
		dev_put(pdata->netdev);

6442
	return err;
6443
}
6444 6445 6446 6447

static void mv88e6xxx_remove(struct mdio_device *mdiodev)
{
	struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
6448 6449 6450 6451 6452 6453
	struct mv88e6xxx_chip *chip;

	if (!ds)
		return;

	chip = ds->priv;
6454

6455 6456
	if (chip->info->ptp_support) {
		mv88e6xxx_hwtstamp_free(chip);
6457
		mv88e6xxx_ptp_free(chip);
6458
	}
6459

6460
	mv88e6xxx_phy_destroy(chip);
6461
	mv88e6xxx_unregister_switch(chip);
6462
	mv88e6xxx_mdios_unregister(chip);
6463

6464 6465 6466 6467 6468 6469 6470
	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)
6471
		mv88e6xxx_g1_irq_free(chip);
6472 6473
	else
		mv88e6xxx_irq_poll_free(chip);
6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487

	dev_set_drvdata(&mdiodev->dev, NULL);
}

static void mv88e6xxx_shutdown(struct mdio_device *mdiodev)
{
	struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);

	if (!ds)
		return;

	dsa_switch_shutdown(ds);

	dev_set_drvdata(&mdiodev->dev, NULL);
6488 6489 6490
}

static const struct of_device_id mv88e6xxx_of_match[] = {
6491 6492 6493 6494
	{
		.compatible = "marvell,mv88e6085",
		.data = &mv88e6xxx_table[MV88E6085],
	},
6495 6496 6497 6498
	{
		.compatible = "marvell,mv88e6190",
		.data = &mv88e6xxx_table[MV88E6190],
	},
6499 6500 6501 6502
	{
		.compatible = "marvell,mv88e6250",
		.data = &mv88e6xxx_table[MV88E6250],
	},
6503 6504 6505 6506 6507 6508 6509 6510
	{ /* sentinel */ },
};

MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);

static struct mdio_driver mv88e6xxx_driver = {
	.probe	= mv88e6xxx_probe,
	.remove = mv88e6xxx_remove,
6511
	.shutdown = mv88e6xxx_shutdown,
6512 6513 6514
	.mdiodrv.driver = {
		.name = "mv88e6085",
		.of_match_table = mv88e6xxx_of_match,
6515
		.pm = &mv88e6xxx_pm_ops,
6516 6517 6518
	},
};

6519
mdio_module_driver(mv88e6xxx_driver);
6520 6521 6522 6523

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