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

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

36
#include "mv88e6xxx.h"
37
#include "global1.h"
38
#include "global2.h"
39
#include "port.h"
40

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

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

61
static int mv88e6xxx_smi_read(struct mv88e6xxx_chip *chip,
62 63
			      int addr, int reg, u16 *val)
{
64
	if (!chip->smi_ops)
65 66
		return -EOPNOTSUPP;

67
	return chip->smi_ops->read(chip, addr, reg, val);
68 69
}

70
static int mv88e6xxx_smi_write(struct mv88e6xxx_chip *chip,
71 72
			       int addr, int reg, u16 val)
{
73
	if (!chip->smi_ops)
74 75
		return -EOPNOTSUPP;

76
	return chip->smi_ops->write(chip, addr, reg, val);
77 78
}

79
static int mv88e6xxx_smi_single_chip_read(struct mv88e6xxx_chip *chip,
80 81 82 83
					  int addr, int reg, u16 *val)
{
	int ret;

84
	ret = mdiobus_read_nested(chip->bus, addr, reg);
85 86 87 88 89 90 91 92
	if (ret < 0)
		return ret;

	*val = ret & 0xffff;

	return 0;
}

93
static int mv88e6xxx_smi_single_chip_write(struct mv88e6xxx_chip *chip,
94 95 96 97
					   int addr, int reg, u16 val)
{
	int ret;

98
	ret = mdiobus_write_nested(chip->bus, addr, reg, val);
99 100 101 102 103 104
	if (ret < 0)
		return ret;

	return 0;
}

105
static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_single_chip_ops = {
106 107 108 109
	.read = mv88e6xxx_smi_single_chip_read,
	.write = mv88e6xxx_smi_single_chip_write,
};

110
static int mv88e6xxx_smi_multi_chip_wait(struct mv88e6xxx_chip *chip)
111 112 113 114 115
{
	int ret;
	int i;

	for (i = 0; i < 16; i++) {
116
		ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_CMD);
117 118 119
		if (ret < 0)
			return ret;

120
		if ((ret & SMI_CMD_BUSY) == 0)
121 122 123 124 125 126
			return 0;
	}

	return -ETIMEDOUT;
}

127
static int mv88e6xxx_smi_multi_chip_read(struct mv88e6xxx_chip *chip,
128
					 int addr, int reg, u16 *val)
129 130 131
{
	int ret;

132
	/* Wait for the bus to become free. */
133
	ret = mv88e6xxx_smi_multi_chip_wait(chip);
134 135 136
	if (ret < 0)
		return ret;

137
	/* Transmit the read command. */
138
	ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
139
				   SMI_CMD_OP_22_READ | (addr << 5) | reg);
140 141 142
	if (ret < 0)
		return ret;

143
	/* Wait for the read command to complete. */
144
	ret = mv88e6xxx_smi_multi_chip_wait(chip);
145 146 147
	if (ret < 0)
		return ret;

148
	/* Read the data. */
149
	ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_DATA);
150 151 152
	if (ret < 0)
		return ret;

153
	*val = ret & 0xffff;
154

155
	return 0;
156 157
}

158
static int mv88e6xxx_smi_multi_chip_write(struct mv88e6xxx_chip *chip,
159
					  int addr, int reg, u16 val)
160 161 162
{
	int ret;

163
	/* Wait for the bus to become free. */
164
	ret = mv88e6xxx_smi_multi_chip_wait(chip);
165 166 167
	if (ret < 0)
		return ret;

168
	/* Transmit the data to write. */
169
	ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_DATA, val);
170 171 172
	if (ret < 0)
		return ret;

173
	/* Transmit the write command. */
174
	ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
175
				   SMI_CMD_OP_22_WRITE | (addr << 5) | reg);
176 177 178
	if (ret < 0)
		return ret;

179
	/* Wait for the write command to complete. */
180
	ret = mv88e6xxx_smi_multi_chip_wait(chip);
181 182 183 184 185 186
	if (ret < 0)
		return ret;

	return 0;
}

187
static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_multi_chip_ops = {
188 189 190 191
	.read = mv88e6xxx_smi_multi_chip_read,
	.write = mv88e6xxx_smi_multi_chip_write,
};

192
int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val)
193 194 195
{
	int err;

196
	assert_reg_lock(chip);
197

198
	err = mv88e6xxx_smi_read(chip, addr, reg, val);
199 200 201
	if (err)
		return err;

202
	dev_dbg(chip->dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
203 204 205 206 207
		addr, reg, *val);

	return 0;
}

208
int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val)
209
{
210 211
	int err;

212
	assert_reg_lock(chip);
213

214
	err = mv88e6xxx_smi_write(chip, addr, reg, val);
215 216 217
	if (err)
		return err;

218
	dev_dbg(chip->dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
219 220
		addr, reg, val);

221 222 223
	return 0;
}

224 225 226
static int mv88e6165_phy_read(struct mv88e6xxx_chip *chip,
			      struct mii_bus *bus,
			      int addr, int reg, u16 *val)
227 228 229 230
{
	return mv88e6xxx_read(chip, addr, reg, val);
}

231 232 233
static int mv88e6165_phy_write(struct mv88e6xxx_chip *chip,
			       struct mii_bus *bus,
			       int addr, int reg, u16 val)
234 235 236 237
{
	return mv88e6xxx_write(chip, addr, reg, val);
}

238 239 240 241 242 243 244 245 246 247 248 249
static struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
{
	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;
}

250 251 252 253
static int mv88e6xxx_phy_read(struct mv88e6xxx_chip *chip, int phy,
			      int reg, u16 *val)
{
	int addr = phy; /* PHY devices addresses start at 0x0 */
254
	struct mii_bus *bus;
255

256 257
	bus = mv88e6xxx_default_mdio_bus(chip);
	if (!bus)
258 259
		return -EOPNOTSUPP;

260
	if (!chip->info->ops->phy_read)
261 262 263
		return -EOPNOTSUPP;

	return chip->info->ops->phy_read(chip, bus, addr, reg, val);
264 265 266 267 268 269
}

static int mv88e6xxx_phy_write(struct mv88e6xxx_chip *chip, int phy,
			       int reg, u16 val)
{
	int addr = phy; /* PHY devices addresses start at 0x0 */
270
	struct mii_bus *bus;
271

272 273
	bus = mv88e6xxx_default_mdio_bus(chip);
	if (!bus)
274 275
		return -EOPNOTSUPP;

276
	if (!chip->info->ops->phy_write)
277 278 279
		return -EOPNOTSUPP;

	return chip->info->ops->phy_write(chip, bus, addr, reg, val);
280 281
}

282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
static int mv88e6xxx_phy_page_get(struct mv88e6xxx_chip *chip, int phy, u8 page)
{
	if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_PHY_PAGE))
		return -EOPNOTSUPP;

	return mv88e6xxx_phy_write(chip, phy, PHY_PAGE, page);
}

static void mv88e6xxx_phy_page_put(struct mv88e6xxx_chip *chip, int phy)
{
	int err;

	/* Restore PHY page Copper 0x0 for access via the registered MDIO bus */
	err = mv88e6xxx_phy_write(chip, phy, PHY_PAGE, PHY_PAGE_COPPER);
	if (unlikely(err)) {
		dev_err(chip->dev, "failed to restore PHY %d page Copper (%d)\n",
			phy, err);
	}
}

static int mv88e6xxx_phy_page_read(struct mv88e6xxx_chip *chip, int phy,
				   u8 page, int reg, u16 *val)
{
	int err;

	/* There is no paging for registers 22 */
	if (reg == PHY_PAGE)
		return -EINVAL;

	err = mv88e6xxx_phy_page_get(chip, phy, page);
	if (!err) {
		err = mv88e6xxx_phy_read(chip, phy, reg, val);
		mv88e6xxx_phy_page_put(chip, phy);
	}

	return err;
}

static int mv88e6xxx_phy_page_write(struct mv88e6xxx_chip *chip, int phy,
				    u8 page, int reg, u16 val)
{
	int err;

	/* There is no paging for registers 22 */
	if (reg == PHY_PAGE)
		return -EINVAL;

	err = mv88e6xxx_phy_page_get(chip, phy, page);
	if (!err) {
		err = mv88e6xxx_phy_write(chip, phy, PHY_PAGE, page);
		mv88e6xxx_phy_page_put(chip, phy);
	}

	return err;
}

static int mv88e6xxx_serdes_read(struct mv88e6xxx_chip *chip, int reg, u16 *val)
{
	return mv88e6xxx_phy_page_read(chip, ADDR_SERDES, SERDES_PAGE_FIBER,
				       reg, val);
}

static int mv88e6xxx_serdes_write(struct mv88e6xxx_chip *chip, int reg, u16 val)
{
	return mv88e6xxx_phy_page_write(chip, ADDR_SERDES, SERDES_PAGE_FIBER,
					reg, val);
}

350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
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);
}

static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id)
{
	struct mv88e6xxx_chip *chip = dev_id;
	unsigned int nhandled = 0;
	unsigned int sub_irq;
	unsigned int n;
	u16 reg;
	int err;

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &reg);
	mutex_unlock(&chip->reg_lock);

	if (err)
		goto out;

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

static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
{
	struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);

	mutex_lock(&chip->reg_lock);
}

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

	err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &reg);
	if (err)
		goto out;

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

	err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, reg);
	if (err)
		goto out;

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

static struct irq_chip mv88e6xxx_g1_irq_chip = {
	.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,
};

static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
{
	int irq, virq;
451 452 453 454 455 456 457
	u16 mask;

	mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &mask);
	mask |= GENMASK(chip->g1_irq.nirqs, 0);
	mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);

	free_irq(chip->irq, chip);
458

459
	for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
460
		virq = irq_find_mapping(chip->g1_irq.domain, irq);
461 462 463
		irq_dispose_mapping(virq);
	}

464
	irq_domain_remove(chip->g1_irq.domain);
465 466 467 468
}

static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
{
469 470
	int err, irq, virq;
	u16 reg, mask;
471 472 473 474 475 476 477 478 479 480 481 482 483 484

	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;

485
	err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &mask);
486
	if (err)
487
		goto out_mapping;
488

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

491
	err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
492
	if (err)
493
		goto out_disable;
494 495 496 497

	/* Reading the interrupt status clears (most of) them */
	err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &reg);
	if (err)
498
		goto out_disable;
499 500 501 502 503 504

	err = request_threaded_irq(chip->irq, NULL,
				   mv88e6xxx_g1_irq_thread_fn,
				   IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
				   dev_name(chip->dev), chip);
	if (err)
505
		goto out_disable;
506 507 508

	return 0;

509 510 511 512 513 514 515 516 517 518 519
out_disable:
	mask |= GENMASK(chip->g1_irq.nirqs, 0);
	mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);

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);
520 521 522 523

	return err;
}

524
int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask)
525
{
526
	int i;
527

528
	for (i = 0; i < 16; i++) {
529 530 531 532 533 534 535 536 537 538 539 540 541
		u16 val;
		int err;

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

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

		usleep_range(1000, 2000);
	}

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

546
/* Indirect write to single pointer-data register with an Update bit */
547
int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
548 549
{
	u16 val;
550
	int err;
551 552

	/* Wait until the previous operation is completed */
553 554 555
	err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
	if (err)
		return err;
556 557 558 559 560 561 562

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

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

563
static int mv88e6xxx_ppu_disable(struct mv88e6xxx_chip *chip)
564
{
565 566
	if (!chip->info->ops->ppu_disable)
		return 0;
567

568
	return chip->info->ops->ppu_disable(chip);
569 570
}

571
static int mv88e6xxx_ppu_enable(struct mv88e6xxx_chip *chip)
572
{
573 574
	if (!chip->info->ops->ppu_enable)
		return 0;
575

576
	return chip->info->ops->ppu_enable(chip);
577 578 579 580
}

static void mv88e6xxx_ppu_reenable_work(struct work_struct *ugly)
{
581
	struct mv88e6xxx_chip *chip;
582

583
	chip = container_of(ugly, struct mv88e6xxx_chip, ppu_work);
584

585
	mutex_lock(&chip->reg_lock);
586

587 588 589 590
	if (mutex_trylock(&chip->ppu_mutex)) {
		if (mv88e6xxx_ppu_enable(chip) == 0)
			chip->ppu_disabled = 0;
		mutex_unlock(&chip->ppu_mutex);
591
	}
592

593
	mutex_unlock(&chip->reg_lock);
594 595 596 597
}

static void mv88e6xxx_ppu_reenable_timer(unsigned long _ps)
{
598
	struct mv88e6xxx_chip *chip = (void *)_ps;
599

600
	schedule_work(&chip->ppu_work);
601 602
}

603
static int mv88e6xxx_ppu_access_get(struct mv88e6xxx_chip *chip)
604 605 606
{
	int ret;

607
	mutex_lock(&chip->ppu_mutex);
608

609
	/* If the PHY polling unit is enabled, disable it so that
610 611 612 613
	 * we can access the PHY registers.  If it was already
	 * disabled, cancel the timer that is going to re-enable
	 * it.
	 */
614 615
	if (!chip->ppu_disabled) {
		ret = mv88e6xxx_ppu_disable(chip);
616
		if (ret < 0) {
617
			mutex_unlock(&chip->ppu_mutex);
618 619
			return ret;
		}
620
		chip->ppu_disabled = 1;
621
	} else {
622
		del_timer(&chip->ppu_timer);
623
		ret = 0;
624 625 626 627 628
	}

	return ret;
}

629
static void mv88e6xxx_ppu_access_put(struct mv88e6xxx_chip *chip)
630
{
631
	/* Schedule a timer to re-enable the PHY polling unit. */
632 633
	mod_timer(&chip->ppu_timer, jiffies + msecs_to_jiffies(10));
	mutex_unlock(&chip->ppu_mutex);
634 635
}

636
static void mv88e6xxx_ppu_state_init(struct mv88e6xxx_chip *chip)
637
{
638 639
	mutex_init(&chip->ppu_mutex);
	INIT_WORK(&chip->ppu_work, mv88e6xxx_ppu_reenable_work);
640 641
	setup_timer(&chip->ppu_timer, mv88e6xxx_ppu_reenable_timer,
		    (unsigned long)chip);
642 643
}

644 645 646 647 648
static void mv88e6xxx_ppu_state_destroy(struct mv88e6xxx_chip *chip)
{
	del_timer_sync(&chip->ppu_timer);
}

649 650 651
static int mv88e6xxx_phy_ppu_read(struct mv88e6xxx_chip *chip,
				  struct mii_bus *bus,
				  int addr, int reg, u16 *val)
652
{
653
	int err;
654

655 656 657
	err = mv88e6xxx_ppu_access_get(chip);
	if (!err) {
		err = mv88e6xxx_read(chip, addr, reg, val);
658
		mv88e6xxx_ppu_access_put(chip);
659 660
	}

661
	return err;
662 663
}

664 665 666
static int mv88e6xxx_phy_ppu_write(struct mv88e6xxx_chip *chip,
				   struct mii_bus *bus,
				   int addr, int reg, u16 val)
667
{
668
	int err;
669

670 671 672
	err = mv88e6xxx_ppu_access_get(chip);
	if (!err) {
		err = mv88e6xxx_write(chip, addr, reg, val);
673
		mv88e6xxx_ppu_access_put(chip);
674 675
	}

676
	return err;
677 678
}

679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710
static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
				    int link, int speed, int duplex,
				    phy_interface_t mode)
{
	int err;

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

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

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

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

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

711 712 713 714 715 716
	if (chip->info->ops->port_set_cmode) {
		err = chip->info->ops->port_set_cmode(chip, port, mode);
		if (err && err != -EOPNOTSUPP)
			goto restore_link;
	}

717 718 719 720 721 722 723 724 725
	err = 0;
restore_link:
	if (chip->info->ops->port_set_link(chip, port, link))
		netdev_err(chip->ds->ports[port].netdev,
			   "failed to restore MAC's link\n");

	return err;
}

726 727 728 729
/* We expect the switch to perform auto negotiation if there is a real
 * phy. However, in the case of a fixed link phy, we force the port
 * settings from the fixed link settings.
 */
730 731
static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
				  struct phy_device *phydev)
732
{
V
Vivien Didelot 已提交
733
	struct mv88e6xxx_chip *chip = ds->priv;
734
	int err;
735 736 737 738

	if (!phy_is_pseudo_fixed_link(phydev))
		return;

739
	mutex_lock(&chip->reg_lock);
740 741
	err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
				       phydev->duplex, phydev->interface);
742
	mutex_unlock(&chip->reg_lock);
743 744 745

	if (err && err != -EOPNOTSUPP)
		netdev_err(ds->ports[port].netdev, "failed to configure MAC\n");
746 747
}

748
static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
749
{
750 751
	if (!chip->info->ops->stats_snapshot)
		return -EOPNOTSUPP;
752

753
	return chip->info->ops->stats_snapshot(chip, port);
754 755
}

756
static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815
	{ "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, },
816 817
};

818
static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
819
					    struct mv88e6xxx_hw_stat *s,
820 821
					    int port, u16 bank1_select,
					    u16 histogram)
822 823 824
{
	u32 low;
	u32 high = 0;
825
	u16 reg = 0;
826
	int err;
827 828
	u64 value;

829
	switch (s->type) {
830
	case STATS_TYPE_PORT:
831 832
		err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
		if (err)
833 834
			return UINT64_MAX;

835
		low = reg;
836
		if (s->sizeof_stat == 4) {
837 838
			err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
			if (err)
839
				return UINT64_MAX;
840
			high = reg;
841
		}
842
		break;
843
	case STATS_TYPE_BANK1:
844
		reg = bank1_select;
845 846
		/* fall through */
	case STATS_TYPE_BANK0:
847
		reg |= s->reg | histogram;
848
		mv88e6xxx_g1_stats_read(chip, reg, &low);
849
		if (s->sizeof_stat == 8)
850
			mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
851 852 853
		break;
	default:
		return UINT64_MAX;
854 855 856 857 858
	}
	value = (((u64)high) << 16) | low;
	return value;
}

859 860
static void mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
					uint8_t *data, int types)
861
{
862 863
	struct mv88e6xxx_hw_stat *stat;
	int i, j;
864

865 866
	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
		stat = &mv88e6xxx_hw_stats[i];
867
		if (stat->type & types) {
868 869 870 871
			memcpy(data + j * ETH_GSTRING_LEN, stat->string,
			       ETH_GSTRING_LEN);
			j++;
		}
872
	}
873 874
}

875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890
static void mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
					uint8_t *data)
{
	mv88e6xxx_stats_get_strings(chip, data,
				    STATS_TYPE_BANK0 | STATS_TYPE_PORT);
}

static void mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
					uint8_t *data)
{
	mv88e6xxx_stats_get_strings(chip, data,
				    STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
}

static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
				  uint8_t *data)
891
{
V
Vivien Didelot 已提交
892
	struct mv88e6xxx_chip *chip = ds->priv;
893 894 895 896 897 898 899 900

	if (chip->info->ops->stats_get_strings)
		chip->info->ops->stats_get_strings(chip, data);
}

static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
					  int types)
{
901 902 903 904 905
	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];
906
		if (stat->type & types)
907 908 909
			j++;
	}
	return j;
910 911
}

912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933
static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
{
	return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
					      STATS_TYPE_PORT);
}

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

static int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
{
	struct mv88e6xxx_chip *chip = ds->priv;

	if (chip->info->ops->stats_get_sset_count)
		return chip->info->ops->stats_get_sset_count(chip);

	return 0;
}

934
static void mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
935 936
				      uint64_t *data, int types,
				      u16 bank1_select, u16 histogram)
937 938 939 940 941 942 943
{
	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) {
944 945 946
			data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
							      bank1_select,
							      histogram);
947 948 949 950 951 952 953 954 955
			j++;
		}
	}
}

static void mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				      uint64_t *data)
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
956 957
					 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
					 0, GLOBAL_STATS_OP_HIST_RX_TX);
958 959 960 961 962 963
}

static void mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				      uint64_t *data)
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
964 965 966 967 968 969 970 971 972 973 974
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
					 GLOBAL_STATS_OP_BANK_1_BIT_9,
					 GLOBAL_STATS_OP_HIST_RX_TX);
}

static void mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
				      uint64_t *data)
{
	return mv88e6xxx_stats_get_stats(chip, port, data,
					 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
					 GLOBAL_STATS_OP_BANK_1_BIT_10, 0);
975 976 977 978 979 980 981 982 983
}

static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
				uint64_t *data)
{
	if (chip->info->ops->stats_get_stats)
		chip->info->ops->stats_get_stats(chip, port, data);
}

984 985
static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
					uint64_t *data)
986
{
V
Vivien Didelot 已提交
987
	struct mv88e6xxx_chip *chip = ds->priv;
988 989
	int ret;

990
	mutex_lock(&chip->reg_lock);
991

992
	ret = mv88e6xxx_stats_snapshot(chip, port);
993
	if (ret < 0) {
994
		mutex_unlock(&chip->reg_lock);
995 996
		return;
	}
997 998

	mv88e6xxx_get_stats(chip, port, data);
999

1000
	mutex_unlock(&chip->reg_lock);
1001 1002
}

1003 1004 1005 1006 1007 1008 1009 1010
static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
{
	if (chip->info->ops->stats_set_histogram)
		return chip->info->ops->stats_set_histogram(chip);

	return 0;
}

1011
static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
1012 1013 1014 1015
{
	return 32 * sizeof(u16);
}

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

	regs->version = 0;

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

1029
	mutex_lock(&chip->reg_lock);
1030

1031 1032
	for (i = 0; i < 32; i++) {

1033 1034 1035
		err = mv88e6xxx_port_read(chip, port, i, &reg);
		if (!err)
			p[i] = reg;
1036
	}
1037

1038
	mutex_unlock(&chip->reg_lock);
1039 1040
}

1041 1042
static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
			     struct ethtool_eee *e)
1043
{
V
Vivien Didelot 已提交
1044
	struct mv88e6xxx_chip *chip = ds->priv;
1045 1046
	u16 reg;
	int err;
1047

1048
	if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
1049 1050
		return -EOPNOTSUPP;

1051
	mutex_lock(&chip->reg_lock);
1052

1053 1054
	err = mv88e6xxx_phy_read(chip, port, 16, &reg);
	if (err)
1055
		goto out;
1056 1057 1058 1059

	e->eee_enabled = !!(reg & 0x0200);
	e->tx_lpi_enabled = !!(reg & 0x0100);

1060
	err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
1061
	if (err)
1062
		goto out;
1063

1064
	e->eee_active = !!(reg & PORT_STATUS_EEE);
1065
out:
1066
	mutex_unlock(&chip->reg_lock);
1067 1068

	return err;
1069 1070
}

1071 1072
static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
			     struct phy_device *phydev, struct ethtool_eee *e)
1073
{
V
Vivien Didelot 已提交
1074
	struct mv88e6xxx_chip *chip = ds->priv;
1075 1076
	u16 reg;
	int err;
1077

1078
	if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
1079 1080
		return -EOPNOTSUPP;

1081
	mutex_lock(&chip->reg_lock);
1082

1083 1084
	err = mv88e6xxx_phy_read(chip, port, 16, &reg);
	if (err)
1085 1086
		goto out;

1087
	reg &= ~0x0300;
1088 1089 1090 1091 1092
	if (e->eee_enabled)
		reg |= 0x0200;
	if (e->tx_lpi_enabled)
		reg |= 0x0100;

1093
	err = mv88e6xxx_phy_write(chip, port, 16, reg);
1094
out:
1095
	mutex_unlock(&chip->reg_lock);
1096

1097
	return err;
1098 1099
}

1100
static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
1101
{
1102 1103 1104
	struct dsa_switch *ds = NULL;
	struct net_device *br;
	u16 pvlan;
1105 1106
	int i;

1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132
	if (dev < DSA_MAX_SWITCHES)
		ds = chip->ds->dst->ds[dev];

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

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

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

	/* Frames from user ports can egress any local DSA links and CPU ports,
	 * as well as any local member of their bridge group.
	 */
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
		if (dsa_is_cpu_port(chip->ds, i) ||
		    dsa_is_dsa_port(chip->ds, i) ||
		    (br && chip->ds->ports[i].bridge_dev == br))
			pvlan |= BIT(i);

	return pvlan;
}

1133
static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
1134 1135
{
	u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
1136 1137 1138

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

1140
	return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
1141 1142
}

1143 1144
static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
					 u8 state)
1145
{
V
Vivien Didelot 已提交
1146
	struct mv88e6xxx_chip *chip = ds->priv;
1147
	int stp_state;
1148
	int err;
1149 1150 1151

	switch (state) {
	case BR_STATE_DISABLED:
1152
		stp_state = PORT_CONTROL_STATE_DISABLED;
1153 1154 1155
		break;
	case BR_STATE_BLOCKING:
	case BR_STATE_LISTENING:
1156
		stp_state = PORT_CONTROL_STATE_BLOCKING;
1157 1158
		break;
	case BR_STATE_LEARNING:
1159
		stp_state = PORT_CONTROL_STATE_LEARNING;
1160 1161 1162
		break;
	case BR_STATE_FORWARDING:
	default:
1163
		stp_state = PORT_CONTROL_STATE_FORWARDING;
1164 1165 1166
		break;
	}

1167
	mutex_lock(&chip->reg_lock);
1168
	err = mv88e6xxx_port_set_state(chip, port, stp_state);
1169
	mutex_unlock(&chip->reg_lock);
1170 1171

	if (err)
1172
		netdev_err(ds->ports[port].netdev, "failed to update state\n");
1173 1174
}

1175 1176
static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
{
1177 1178
	int err;

1179 1180 1181 1182
	err = mv88e6xxx_g1_atu_flush(chip, 0, true);
	if (err)
		return err;

1183 1184 1185 1186
	err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
	if (err)
		return err;

1187 1188 1189
	return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
}

1190 1191 1192 1193 1194 1195 1196 1197 1198
static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
{
	u16 pvlan = 0;

	if (!mv88e6xxx_has_pvt(chip))
		return -EOPNOTSUPP;

	/* Skip the local source device, which uses in-chip port VLAN */
	if (dev != chip->ds->index)
1199
		pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1200 1201 1202 1203

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

1204 1205
static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
{
1206 1207 1208
	int dev, port;
	int err;

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

1230 1231 1232 1233 1234 1235
static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

	mutex_lock(&chip->reg_lock);
1236
	err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
1237 1238 1239 1240 1241 1242
	mutex_unlock(&chip->reg_lock);

	if (err)
		netdev_err(ds->ports[port].netdev, "failed to flush ATU\n");
}

1243 1244 1245 1246 1247 1248 1249 1250
static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
{
	if (!chip->info->max_vid)
		return 0;

	return mv88e6xxx_g1_vtu_flush(chip);
}

1251 1252 1253 1254 1255 1256 1257 1258 1259
static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
				 struct mv88e6xxx_vtu_entry *entry)
{
	if (!chip->info->ops->vtu_getnext)
		return -EOPNOTSUPP;

	return chip->info->ops->vtu_getnext(chip, entry);
}

1260 1261 1262 1263 1264 1265 1266 1267 1268
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);
}

1269 1270 1271
static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
				    struct switchdev_obj_port_vlan *vlan,
				    int (*cb)(struct switchdev_obj *obj))
1272
{
V
Vivien Didelot 已提交
1273
	struct mv88e6xxx_chip *chip = ds->priv;
1274 1275 1276
	struct mv88e6xxx_vtu_entry next = {
		.vid = chip->info->max_vid,
	};
1277 1278 1279
	u16 pvid;
	int err;

1280
	if (!chip->info->max_vid)
1281 1282
		return -EOPNOTSUPP;

1283
	mutex_lock(&chip->reg_lock);
1284

1285
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
1286 1287 1288 1289
	if (err)
		goto unlock;

	do {
1290
		err = mv88e6xxx_vtu_getnext(chip, &next);
1291 1292 1293 1294 1295 1296
		if (err)
			break;

		if (!next.valid)
			break;

1297
		if (next.member[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1298 1299 1300
			continue;

		/* reinit and dump this VLAN obj */
1301 1302
		vlan->vid_begin = next.vid;
		vlan->vid_end = next.vid;
1303 1304
		vlan->flags = 0;

1305
		if (next.member[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
1306 1307 1308 1309 1310 1311 1312 1313
			vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;

		if (next.vid == pvid)
			vlan->flags |= BRIDGE_VLAN_INFO_PVID;

		err = cb(&vlan->obj);
		if (err)
			break;
1314
	} while (next.vid < chip->info->max_vid);
1315 1316

unlock:
1317
	mutex_unlock(&chip->reg_lock);
1318 1319 1320 1321

	return err;
}

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

	bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);

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

		set_bit(*fid, fid_bitmap);
	}

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

		if (!vlan.valid)
			break;

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

	/* The reset value 0x000 is used to indicate that multiple address
	 * databases are not needed. Return the next positive available.
	 */
	*fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
1357
	if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1358 1359 1360
		return -ENOSPC;

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

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

	if (!vid)
		return -EINVAL;

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

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

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

1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396
	if (new) {
		int i;

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

		/* Include only CPU and DSA ports */
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
			entry->member[i] = dsa_is_normal_port(chip->ds, i) ?
				GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER :
				GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED;

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

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

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

	if (!vid_begin)
		return -EOPNOTSUPP;

1415
	mutex_lock(&chip->reg_lock);
1416 1417

	do {
1418
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1419 1420 1421 1422 1423 1424 1425 1426 1427
		if (err)
			goto unlock;

		if (!vlan.valid)
			break;

		if (vlan.vid > vid_end)
			break;

1428
		for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1429 1430 1431
			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
				continue;

1432 1433 1434
			if (!ds->ports[port].netdev)
				continue;

1435
			if (vlan.member[i] ==
1436 1437 1438
			    GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
				continue;

1439 1440
			if (ds->ports[i].bridge_dev ==
			    ds->ports[port].bridge_dev)
1441 1442
				break; /* same bridge, check next VLAN */

1443
			if (!ds->ports[i].bridge_dev)
1444 1445
				continue;

1446
			netdev_warn(ds->ports[port].netdev,
1447 1448
				    "hardware VLAN %d already used by %s\n",
				    vlan.vid,
1449
				    netdev_name(ds->ports[i].bridge_dev));
1450 1451 1452 1453 1454 1455
			err = -EOPNOTSUPP;
			goto unlock;
		}
	} while (vlan.vid < vid_end);

unlock:
1456
	mutex_unlock(&chip->reg_lock);
1457 1458 1459 1460

	return err;
}

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

1469
	if (!chip->info->max_vid)
1470 1471
		return -EOPNOTSUPP;

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

1476
	return err;
1477 1478
}

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

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

1490 1491 1492 1493 1494 1495 1496 1497
	/* If the requested port doesn't belong to the same bridge as the VLAN
	 * members, do not support it (yet) and fallback to software VLAN.
	 */
	err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
					   vlan->vid_end);
	if (err)
		return err;

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

1504
static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
1505
				    u16 vid, bool untagged)
1506
{
1507
	struct mv88e6xxx_vtu_entry vlan;
1508 1509
	int err;

1510
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, true);
1511
	if (err)
1512
		return err;
1513

1514
	vlan.member[port] = untagged ?
1515 1516 1517
		GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED :
		GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED;

1518
	return mv88e6xxx_vtu_loadpurge(chip, &vlan);
1519 1520
}

1521 1522 1523
static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
				    const struct switchdev_obj_port_vlan *vlan,
				    struct switchdev_trans *trans)
1524
{
V
Vivien Didelot 已提交
1525
	struct mv88e6xxx_chip *chip = ds->priv;
1526 1527 1528 1529
	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
	bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
	u16 vid;

1530
	if (!chip->info->max_vid)
1531 1532
		return;

1533
	mutex_lock(&chip->reg_lock);
1534

1535
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
1536
		if (_mv88e6xxx_port_vlan_add(chip, port, vid, untagged))
1537 1538
			netdev_err(ds->ports[port].netdev,
				   "failed to add VLAN %d%c\n",
1539
				   vid, untagged ? 'u' : 't');
1540

1541
	if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1542
		netdev_err(ds->ports[port].netdev, "failed to set PVID %d\n",
1543
			   vlan->vid_end);
1544

1545
	mutex_unlock(&chip->reg_lock);
1546 1547
}

1548
static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
1549
				    int port, u16 vid)
1550
{
1551
	struct dsa_switch *ds = chip->ds;
1552
	struct mv88e6xxx_vtu_entry vlan;
1553 1554
	int i, err;

1555
	err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1556
	if (err)
1557
		return err;
1558

1559
	/* Tell switchdev if this VLAN is handled in software */
1560
	if (vlan.member[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1561
		return -EOPNOTSUPP;
1562

1563
	vlan.member[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1564 1565

	/* keep the VLAN unless all ports are excluded */
1566
	vlan.valid = false;
1567
	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1568
		if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
1569 1570
			continue;

1571
		if (vlan.member[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
1572
			vlan.valid = true;
1573 1574 1575 1576
			break;
		}
	}

1577
	err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1578 1579 1580
	if (err)
		return err;

1581
	return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
1582 1583
}

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

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

1594
	mutex_lock(&chip->reg_lock);
1595

1596
	err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
1597 1598 1599
	if (err)
		goto unlock;

1600
	for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1601
		err = _mv88e6xxx_port_vlan_del(chip, port, vid);
1602 1603 1604 1605
		if (err)
			goto unlock;

		if (vid == pvid) {
1606
			err = mv88e6xxx_port_set_pvid(chip, port, 0);
1607 1608 1609 1610 1611
			if (err)
				goto unlock;
		}
	}

1612
unlock:
1613
	mutex_unlock(&chip->reg_lock);
1614 1615 1616 1617

	return err;
}

1618 1619 1620
static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
					const unsigned char *addr, u16 vid,
					u8 state)
1621
{
1622
	struct mv88e6xxx_vtu_entry vlan;
1623
	struct mv88e6xxx_atu_entry entry;
1624 1625
	int err;

1626 1627
	/* Null VLAN ID corresponds to the port private database */
	if (vid == 0)
1628
		err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
1629
	else
1630
		err = mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1631 1632
	if (err)
		return err;
1633

1634 1635 1636 1637 1638
	entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
	ether_addr_copy(entry.mac, addr);
	eth_addr_dec(entry.mac);

	err = mv88e6xxx_g1_atu_getnext(chip, vlan.fid, &entry);
1639 1640 1641
	if (err)
		return err;

1642 1643 1644 1645 1646 1647 1648
	/* Initialize a fresh ATU entry if it isn't found */
	if (entry.state == GLOBAL_ATU_DATA_STATE_UNUSED ||
	    !ether_addr_equal(entry.mac, addr)) {
		memset(&entry, 0, sizeof(entry));
		ether_addr_copy(entry.mac, addr);
	}

1649 1650
	/* Purge the ATU entry only if no port is using it anymore */
	if (state == GLOBAL_ATU_DATA_STATE_UNUSED) {
1651 1652
		entry.portvec &= ~BIT(port);
		if (!entry.portvec)
1653 1654
			entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
	} else {
1655
		entry.portvec |= BIT(port);
1656
		entry.state = state;
1657 1658
	}

1659
	return mv88e6xxx_g1_atu_loadpurge(chip, vlan.fid, &entry);
1660 1661
}

1662 1663 1664
static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
				      const struct switchdev_obj_port_fdb *fdb,
				      struct switchdev_trans *trans)
V
Vivien Didelot 已提交
1665 1666 1667 1668 1669 1670 1671
{
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */
	return 0;
}

1672 1673 1674
static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
				   const struct switchdev_obj_port_fdb *fdb,
				   struct switchdev_trans *trans)
1675
{
V
Vivien Didelot 已提交
1676
	struct mv88e6xxx_chip *chip = ds->priv;
1677

1678
	mutex_lock(&chip->reg_lock);
1679 1680 1681
	if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
					 GLOBAL_ATU_DATA_STATE_UC_STATIC))
		netdev_err(ds->ports[port].netdev, "failed to load unicast MAC address\n");
1682
	mutex_unlock(&chip->reg_lock);
1683 1684
}

1685 1686
static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
				  const struct switchdev_obj_port_fdb *fdb)
1687
{
V
Vivien Didelot 已提交
1688
	struct mv88e6xxx_chip *chip = ds->priv;
1689
	int err;
1690

1691
	mutex_lock(&chip->reg_lock);
1692 1693
	err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
					   GLOBAL_ATU_DATA_STATE_UNUSED);
1694
	mutex_unlock(&chip->reg_lock);
1695

1696
	return err;
1697 1698
}

1699 1700 1701 1702
static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
				      u16 fid, u16 vid, int port,
				      struct switchdev_obj *obj,
				      int (*cb)(struct switchdev_obj *obj))
1703
{
1704
	struct mv88e6xxx_atu_entry addr;
1705 1706
	int err;

1707 1708
	addr.state = GLOBAL_ATU_DATA_STATE_UNUSED;
	eth_broadcast_addr(addr.mac);
1709 1710

	do {
1711
		err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
1712
		if (err)
1713
			return err;
1714 1715 1716 1717

		if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED)
			break;

1718
		if (addr.trunk || (addr.portvec & BIT(port)) == 0)
1719 1720 1721 1722
			continue;

		if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
			struct switchdev_obj_port_fdb *fdb;
1723

1724 1725 1726 1727
			if (!is_unicast_ether_addr(addr.mac))
				continue;

			fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
1728 1729
			fdb->vid = vid;
			ether_addr_copy(fdb->addr, addr.mac);
1730 1731 1732 1733
			if (addr.state == GLOBAL_ATU_DATA_STATE_UC_STATIC)
				fdb->ndm_state = NUD_NOARP;
			else
				fdb->ndm_state = NUD_REACHABLE;
1734 1735 1736 1737 1738 1739 1740 1741 1742
		} else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
			struct switchdev_obj_port_mdb *mdb;

			if (!is_multicast_ether_addr(addr.mac))
				continue;

			mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
			mdb->vid = vid;
			ether_addr_copy(mdb->addr, addr.mac);
1743 1744
		} else {
			return -EOPNOTSUPP;
1745
		}
1746 1747 1748 1749

		err = cb(obj);
		if (err)
			return err;
1750 1751 1752 1753 1754
	} while (!is_broadcast_ether_addr(addr.mac));

	return err;
}

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

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

1770
	err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
1771
	if (err)
1772
		return err;
1773

1774
	/* Dump VLANs' Filtering Information Databases */
1775
	do {
1776
		err = mv88e6xxx_vtu_getnext(chip, &vlan);
1777
		if (err)
1778
			return err;
1779 1780 1781 1782

		if (!vlan.valid)
			break;

1783 1784
		err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
						 obj, cb);
1785
		if (err)
1786
			return err;
1787
	} while (vlan.vid < chip->info->max_vid);
1788

1789 1790 1791 1792 1793 1794 1795
	return err;
}

static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
				   struct switchdev_obj_port_fdb *fdb,
				   int (*cb)(struct switchdev_obj *obj))
{
V
Vivien Didelot 已提交
1796
	struct mv88e6xxx_chip *chip = ds->priv;
1797 1798 1799 1800
	int err;

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
1801
	mutex_unlock(&chip->reg_lock);
1802 1803 1804 1805

	return err;
}

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

1814 1815 1816 1817
	/* Remap the Port VLAN of each local bridge group member */
	for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) {
		if (chip->ds->ports[port].bridge_dev == br) {
			err = mv88e6xxx_port_vlan_map(chip, port);
1818
			if (err)
1819
				return err;
1820 1821 1822
		}
	}

1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840
	if (!mv88e6xxx_has_pvt(chip))
		return 0;

	/* Remap the Port VLAN of each cross-chip bridge group member */
	for (dev = 0; dev < DSA_MAX_SWITCHES; ++dev) {
		ds = chip->ds->dst->ds[dev];
		if (!ds)
			break;

		for (port = 0; port < ds->num_ports; ++port) {
			if (ds->ports[port].bridge_dev == br) {
				err = mv88e6xxx_pvt_map(chip, dev, port);
				if (err)
					return err;
			}
		}
	}

1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851
	return 0;
}

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

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_bridge_map(chip, br);
1852
	mutex_unlock(&chip->reg_lock);
1853

1854
	return err;
1855 1856
}

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

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

1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898
static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, int dev,
					   int port, struct net_device *br)
{
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;

	if (!mv88e6xxx_has_pvt(chip))
		return 0;

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_pvt_map(chip, dev, port);
	mutex_unlock(&chip->reg_lock);

	return err;
}

static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, int dev,
					     int port, struct net_device *br)
{
	struct mv88e6xxx_chip *chip = ds->priv;

	if (!mv88e6xxx_has_pvt(chip))
		return;

	mutex_lock(&chip->reg_lock);
	if (mv88e6xxx_pvt_map(chip, dev, port))
		dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
	mutex_unlock(&chip->reg_lock);
}

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

	return 0;
}

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

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

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

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

1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947
	return 0;
}

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

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

1948
	mv88e6xxx_hardware_reset(chip);
1949

1950
	return mv88e6xxx_software_reset(chip);
1951 1952
}

1953
static int mv88e6xxx_serdes_power_on(struct mv88e6xxx_chip *chip)
1954
{
1955 1956
	u16 val;
	int err;
1957

1958 1959 1960 1961
	/* Clear Power Down bit */
	err = mv88e6xxx_serdes_read(chip, MII_BMCR, &val);
	if (err)
		return err;
1962

1963 1964 1965
	if (val & BMCR_PDOWN) {
		val &= ~BMCR_PDOWN;
		err = mv88e6xxx_serdes_write(chip, MII_BMCR, val);
1966 1967
	}

1968
	return err;
1969 1970
}

1971 1972 1973
static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
				   enum mv88e6xxx_frame_mode frame, u16 egress,
				   u16 etype)
1974 1975 1976
{
	int err;

1977 1978 1979 1980
	if (!chip->info->ops->port_set_frame_mode)
		return -EOPNOTSUPP;

	err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
1981 1982 1983
	if (err)
		return err;

1984 1985 1986 1987 1988 1989 1990 1991
	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;
1992 1993
}

1994
static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
1995
{
1996 1997 1998 1999
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
				       PORT_CONTROL_EGRESS_UNMODIFIED,
				       PORT_ETH_TYPE_DEFAULT);
}
2000

2001 2002 2003 2004 2005 2006
static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
				       PORT_CONTROL_EGRESS_UNMODIFIED,
				       PORT_ETH_TYPE_DEFAULT);
}
2007

2008 2009 2010 2011 2012 2013
static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
{
	return mv88e6xxx_set_port_mode(chip, port,
				       MV88E6XXX_FRAME_MODE_ETHERTYPE,
				       PORT_CONTROL_EGRESS_ADD_TAG, ETH_P_EDSA);
}
2014

2015 2016 2017 2018
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);
2019

2020 2021
	if (dsa_is_normal_port(chip->ds, port))
		return mv88e6xxx_set_port_mode_normal(chip, port);
2022

2023 2024 2025
	/* Setup CPU port mode depending on its supported tag format */
	if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
		return mv88e6xxx_set_port_mode_dsa(chip, port);
2026

2027 2028
	if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
		return mv88e6xxx_set_port_mode_edsa(chip, port);
2029

2030
	return -EINVAL;
2031 2032
}

2033
static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2034
{
2035
	bool message = dsa_is_dsa_port(chip->ds, port);
2036

2037
	return mv88e6xxx_port_set_message_port(chip, port, message);
2038
}
2039

2040
static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2041
{
2042
	bool flood = port == dsa_upstream_port(chip->ds);
2043

2044 2045 2046 2047
	/* Upstream ports flood frames with unknown unicast or multicast DA */
	if (chip->info->ops->port_set_egress_floods)
		return chip->info->ops->port_set_egress_floods(chip, port,
							       flood, flood);
2048

2049
	return 0;
2050 2051
}

2052
static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
2053
{
2054
	struct dsa_switch *ds = chip->ds;
2055
	int err;
2056
	u16 reg;
2057

2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071
	/* MAC Forcing register: don't force link, speed, duplex or flow control
	 * state to any particular values on physical ports, but force the CPU
	 * port and all DSA ports to their maximum bandwidth and full duplex.
	 */
	if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
		err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
					       SPEED_MAX, DUPLEX_FULL,
					       PHY_INTERFACE_MODE_NA);
	else
		err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
					       SPEED_UNFORCED, DUPLEX_UNFORCED,
					       PHY_INTERFACE_MODE_NA);
	if (err)
		return err;
2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086

	/* 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.
	 */
2087
	reg = PORT_CONTROL_IGMP_MLD_SNOOP |
2088 2089
		PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
		PORT_CONTROL_STATE_FORWARDING;
2090 2091 2092
	err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
	if (err)
		return err;
2093

2094
	err = mv88e6xxx_setup_port_mode(chip, port);
2095 2096
	if (err)
		return err;
2097

2098
	err = mv88e6xxx_setup_egress_floods(chip, port);
2099 2100 2101
	if (err)
		return err;

2102 2103 2104
	/* If this port is connected to a SerDes, make sure the SerDes is not
	 * powered down.
	 */
2105
	if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_SERDES)) {
2106 2107 2108 2109 2110 2111 2112 2113 2114 2115
		err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
		if (err)
			return err;
		reg &= PORT_STATUS_CMODE_MASK;
		if ((reg == PORT_STATUS_CMODE_100BASE_X) ||
		    (reg == PORT_STATUS_CMODE_1000BASE_X) ||
		    (reg == PORT_STATUS_CMODE_SGMII)) {
			err = mv88e6xxx_serdes_power_on(chip);
			if (err < 0)
				return err;
2116 2117 2118
		}
	}

2119
	/* Port Control 2: don't force a good FCS, set the maximum frame size to
2120
	 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
2121 2122 2123
	 * 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.
2124
	 */
2125 2126 2127
	err = mv88e6xxx_port_set_map_da(chip, port);
	if (err)
		return err;
2128

2129 2130 2131 2132
	reg = 0;
	if (chip->info->ops->port_set_upstream_port) {
		err = chip->info->ops->port_set_upstream_port(
			chip, port, dsa_upstream_port(ds));
2133 2134
		if (err)
			return err;
2135 2136
	}

2137 2138 2139 2140 2141
	err = mv88e6xxx_port_set_8021q_mode(chip, port,
					    PORT_CONTROL_2_8021Q_DISABLED);
	if (err)
		return err;

2142 2143 2144 2145 2146 2147
	if (chip->info->ops->port_jumbo_config) {
		err = chip->info->ops->port_jumbo_config(chip, port);
		if (err)
			return err;
	}

2148 2149 2150 2151 2152
	/* Port Association Vector: when learning source addresses
	 * of packets, add the address to the address database using
	 * a port bitmap that has only the bit for this port set and
	 * the other bits clear.
	 */
2153
	reg = 1 << port;
2154 2155
	/* Disable learning for CPU port */
	if (dsa_is_cpu_port(ds, port))
2156
		reg = 0;
2157

2158 2159 2160
	err = mv88e6xxx_port_write(chip, port, PORT_ASSOC_VECTOR, reg);
	if (err)
		return err;
2161 2162

	/* Egress rate control 2: disable egress rate control. */
2163 2164 2165
	err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL_2, 0x0000);
	if (err)
		return err;
2166

2167 2168
	if (chip->info->ops->port_pause_config) {
		err = chip->info->ops->port_pause_config(chip, port);
2169 2170
		if (err)
			return err;
2171
	}
2172

2173 2174 2175 2176 2177 2178
	if (chip->info->ops->port_disable_learn_limit) {
		err = chip->info->ops->port_disable_learn_limit(chip, port);
		if (err)
			return err;
	}

2179 2180
	if (chip->info->ops->port_disable_pri_override) {
		err = chip->info->ops->port_disable_pri_override(chip, port);
2181 2182
		if (err)
			return err;
2183
	}
2184

2185 2186
	if (chip->info->ops->port_tag_remap) {
		err = chip->info->ops->port_tag_remap(chip, port);
2187 2188
		if (err)
			return err;
2189 2190
	}

2191 2192
	if (chip->info->ops->port_egress_rate_limiting) {
		err = chip->info->ops->port_egress_rate_limiting(chip, port);
2193 2194
		if (err)
			return err;
2195 2196
	}

2197
	err = mv88e6xxx_setup_message_port(chip, port);
2198 2199
	if (err)
		return err;
2200

2201
	/* Port based VLAN map: give each port the same default address
2202 2203
	 * database, and allow bidirectional communication between the
	 * CPU and DSA port(s), and the other ports.
2204
	 */
2205
	err = mv88e6xxx_port_set_fid(chip, port, 0);
2206 2207
	if (err)
		return err;
2208

2209
	err = mv88e6xxx_port_vlan_map(chip, port);
2210 2211
	if (err)
		return err;
2212 2213 2214 2215

	/* Default VLAN ID and priority: don't set a default VLAN
	 * ID, and set the default packet priority to zero.
	 */
2216
	return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000);
2217 2218
}

2219
static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
2220 2221 2222
{
	int err;

2223
	err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
2224 2225 2226
	if (err)
		return err;

2227
	err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
2228 2229 2230
	if (err)
		return err;

2231 2232 2233 2234 2235
	err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
	if (err)
		return err;

	return 0;
2236 2237
}

2238 2239 2240
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
				     unsigned int ageing_time)
{
V
Vivien Didelot 已提交
2241
	struct mv88e6xxx_chip *chip = ds->priv;
2242 2243 2244
	int err;

	mutex_lock(&chip->reg_lock);
2245
	err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
2246 2247 2248 2249 2250
	mutex_unlock(&chip->reg_lock);

	return err;
}

2251
static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
2252
{
2253
	struct dsa_switch *ds = chip->ds;
2254
	u32 upstream_port = dsa_upstream_port(ds);
2255
	int err;
2256

2257 2258 2259
	/* Enable the PHY Polling Unit if present, don't discard any packets,
	 * and mask all interrupt sources.
	 */
2260
	err = mv88e6xxx_ppu_enable(chip);
2261 2262 2263
	if (err)
		return err;

2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274
	if (chip->info->ops->g1_set_cpu_port) {
		err = chip->info->ops->g1_set_cpu_port(chip, upstream_port);
		if (err)
			return err;
	}

	if (chip->info->ops->g1_set_egress_port) {
		err = chip->info->ops->g1_set_egress_port(chip, upstream_port);
		if (err)
			return err;
	}
2275

2276
	/* Disable remote management, and set the switch's DSA device number. */
2277 2278 2279
	err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2,
				 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
				 (ds->index & 0x1f));
2280 2281 2282
	if (err)
		return err;

2283
	/* Configure the IP ToS mapping registers. */
2284
	err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
2285
	if (err)
2286
		return err;
2287
	err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_1, 0x0000);
2288
	if (err)
2289
		return err;
2290
	err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_2, 0x5555);
2291
	if (err)
2292
		return err;
2293
	err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_3, 0x5555);
2294
	if (err)
2295
		return err;
2296
	err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_4, 0xaaaa);
2297
	if (err)
2298
		return err;
2299
	err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_5, 0xaaaa);
2300
	if (err)
2301
		return err;
2302
	err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_6, 0xffff);
2303
	if (err)
2304
		return err;
2305
	err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_7, 0xffff);
2306
	if (err)
2307
		return err;
2308 2309

	/* Configure the IEEE 802.1p priority mapping register. */
2310
	err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
2311
	if (err)
2312
		return err;
2313

2314 2315 2316 2317 2318
	/* Initialize the statistics unit */
	err = mv88e6xxx_stats_set_histogram(chip);
	if (err)
		return err;

2319
	/* Clear the statistics counters for all ports */
2320 2321
	err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
				 GLOBAL_STATS_OP_FLUSH_ALL);
2322 2323 2324 2325
	if (err)
		return err;

	/* Wait for the flush to complete. */
2326
	err = mv88e6xxx_g1_stats_wait(chip);
2327 2328 2329 2330 2331 2332
	if (err)
		return err;

	return 0;
}

2333
static int mv88e6xxx_setup(struct dsa_switch *ds)
2334
{
V
Vivien Didelot 已提交
2335
	struct mv88e6xxx_chip *chip = ds->priv;
2336
	int err;
2337 2338
	int i;

2339
	chip->ds = ds;
2340
	ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
2341

2342
	mutex_lock(&chip->reg_lock);
2343

2344
	/* Setup Switch Port Registers */
2345
	for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2346 2347 2348 2349 2350 2351 2352
		err = mv88e6xxx_setup_port(chip, i);
		if (err)
			goto unlock;
	}

	/* Setup Switch Global 1 Registers */
	err = mv88e6xxx_g1_setup(chip);
2353 2354 2355
	if (err)
		goto unlock;

2356 2357 2358
	/* Setup Switch Global 2 Registers */
	if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
		err = mv88e6xxx_g2_setup(chip);
2359 2360 2361
		if (err)
			goto unlock;
	}
2362

2363 2364 2365 2366
	err = mv88e6xxx_vtu_setup(chip);
	if (err)
		goto unlock;

2367 2368 2369 2370
	err = mv88e6xxx_pvt_setup(chip);
	if (err)
		goto unlock;

2371 2372 2373 2374
	err = mv88e6xxx_atu_setup(chip);
	if (err)
		goto unlock;

2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385
	/* Some generations have the configuration of sending reserved
	 * management frames to the CPU in global2, others in
	 * global1. Hence it does not fit the two setup functions
	 * above.
	 */
	if (chip->info->ops->mgmt_rsvd2cpu) {
		err = chip->info->ops->mgmt_rsvd2cpu(chip);
		if (err)
			goto unlock;
	}

2386
unlock:
2387
	mutex_unlock(&chip->reg_lock);
2388

2389
	return err;
2390 2391
}

2392 2393
static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
{
V
Vivien Didelot 已提交
2394
	struct mv88e6xxx_chip *chip = ds->priv;
2395 2396
	int err;

2397 2398
	if (!chip->info->ops->set_switch_mac)
		return -EOPNOTSUPP;
2399

2400 2401
	mutex_lock(&chip->reg_lock);
	err = chip->info->ops->set_switch_mac(chip, addr);
2402 2403 2404 2405 2406
	mutex_unlock(&chip->reg_lock);

	return err;
}

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

2414 2415 2416
	if (!chip->info->ops->phy_read)
		return -EOPNOTSUPP;

2417
	mutex_lock(&chip->reg_lock);
2418
	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
2419
	mutex_unlock(&chip->reg_lock);
2420

2421 2422 2423 2424 2425 2426 2427 2428
	if (reg == MII_PHYSID2) {
		/* Some internal PHYS don't have a model number.  Use
		 * the mv88e6390 family model number instead.
		 */
		if (!(val & 0x3f0))
			val |= PORT_SWITCH_ID_PROD_NUM_6390;
	}

2429
	return err ? err : val;
2430 2431
}

2432
static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
2433
{
2434 2435
	struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
	struct mv88e6xxx_chip *chip = mdio_bus->chip;
2436
	int err;
2437

2438 2439 2440
	if (!chip->info->ops->phy_write)
		return -EOPNOTSUPP;

2441
	mutex_lock(&chip->reg_lock);
2442
	err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
2443
	mutex_unlock(&chip->reg_lock);
2444 2445

	return err;
2446 2447
}

2448
static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
2449 2450
				   struct device_node *np,
				   bool external)
2451 2452
{
	static int index;
2453
	struct mv88e6xxx_mdio_bus *mdio_bus;
2454 2455 2456
	struct mii_bus *bus;
	int err;

2457
	bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
2458 2459 2460
	if (!bus)
		return -ENOMEM;

2461
	mdio_bus = bus->priv;
2462
	mdio_bus->bus = bus;
2463
	mdio_bus->chip = chip;
2464 2465
	INIT_LIST_HEAD(&mdio_bus->list);
	mdio_bus->external = external;
2466

2467 2468 2469 2470 2471 2472 2473 2474 2475 2476
	if (np) {
		bus->name = np->full_name;
		snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
	} 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;
2477
	bus->parent = chip->dev;
2478

2479 2480
	if (np)
		err = of_mdiobus_register(bus, np);
2481 2482 2483
	else
		err = mdiobus_register(bus);
	if (err) {
2484
		dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
2485
		return err;
2486
	}
2487 2488 2489 2490 2491

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

	return 0;
2494
}
2495

2496 2497 2498 2499 2500
static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
	{ .compatible = "marvell,mv88e6xxx-mdio-external",
	  .data = (void *)true },
	{ },
};
2501

2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531
static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
				    struct device_node *np)
{
	const struct of_device_id *match;
	struct device_node *child;
	int err;

	/* Always register one mdio bus for the internal/default mdio
	 * bus. This maybe represented in the device tree, but is
	 * optional.
	 */
	child = of_get_child_by_name(np, "mdio");
	err = mv88e6xxx_mdio_register(chip, child, false);
	if (err)
		return err;

	/* Walk the device tree, and see if there are any other nodes
	 * which say they are compatible with the external mdio
	 * bus.
	 */
	for_each_available_child_of_node(np, child) {
		match = of_match_node(mv88e6xxx_mdio_external_match, child);
		if (match) {
			err = mv88e6xxx_mdio_register(chip, child, true);
			if (err)
				return err;
		}
	}

	return 0;
2532 2533
}

2534
static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
2535 2536

{
2537 2538
	struct mv88e6xxx_mdio_bus *mdio_bus;
	struct mii_bus *bus;
2539

2540 2541
	list_for_each_entry(mdio_bus, &chip->mdios, list) {
		bus = mdio_bus->bus;
2542

2543 2544
		mdiobus_unregister(bus);
	}
2545 2546
}

2547 2548
static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
2549
	struct mv88e6xxx_chip *chip = ds->priv;
2550 2551 2552 2553 2554 2555 2556

	return chip->eeprom_len;
}

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

2560 2561
	if (!chip->info->ops->get_eeprom)
		return -EOPNOTSUPP;
2562

2563 2564
	mutex_lock(&chip->reg_lock);
	err = chip->info->ops->get_eeprom(chip, eeprom, data);
2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577
	mutex_unlock(&chip->reg_lock);

	if (err)
		return err;

	eeprom->magic = 0xc3ec4951;

	return 0;
}

static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
				struct ethtool_eeprom *eeprom, u8 *data)
{
V
Vivien Didelot 已提交
2578
	struct mv88e6xxx_chip *chip = ds->priv;
2579 2580
	int err;

2581 2582 2583
	if (!chip->info->ops->set_eeprom)
		return -EOPNOTSUPP;

2584 2585 2586 2587
	if (eeprom->magic != 0xc3ec4951)
		return -EINVAL;

	mutex_lock(&chip->reg_lock);
2588
	err = chip->info->ops->set_eeprom(chip, eeprom, data);
2589 2590 2591 2592 2593
	mutex_unlock(&chip->reg_lock);

	return err;
}

2594
static const struct mv88e6xxx_ops mv88e6085_ops = {
2595
	/* MV88E6XXX_FAMILY_6097 */
2596
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2597 2598
	.phy_read = mv88e6xxx_phy_ppu_read,
	.phy_write = mv88e6xxx_phy_ppu_write,
2599
	.port_set_link = mv88e6xxx_port_set_link,
2600
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2601
	.port_set_speed = mv88e6185_port_set_speed,
2602
	.port_tag_remap = mv88e6095_port_tag_remap,
2603
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2604
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2605
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2606
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2607
	.port_pause_config = mv88e6097_port_pause_config,
2608
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2609
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2610
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2611 2612
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2613
	.stats_get_stats = mv88e6095_stats_get_stats,
2614 2615
	.g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
	.g1_set_egress_port = mv88e6095_g1_set_egress_port,
2616
	.watchdog_ops = &mv88e6097_watchdog_ops,
2617
	.mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
2618 2619
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2620
	.reset = mv88e6185_g1_reset,
2621
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2622
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2623 2624 2625
};

static const struct mv88e6xxx_ops mv88e6095_ops = {
2626
	/* MV88E6XXX_FAMILY_6095 */
2627
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2628 2629
	.phy_read = mv88e6xxx_phy_ppu_read,
	.phy_write = mv88e6xxx_phy_ppu_write,
2630
	.port_set_link = mv88e6xxx_port_set_link,
2631
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2632
	.port_set_speed = mv88e6185_port_set_speed,
2633
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2634
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2635
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2636
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2637 2638
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2639
	.stats_get_stats = mv88e6095_stats_get_stats,
2640
	.mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
2641 2642
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2643
	.reset = mv88e6185_g1_reset,
2644
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2645
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2646 2647
};

2648
static const struct mv88e6xxx_ops mv88e6097_ops = {
2649
	/* MV88E6XXX_FAMILY_6097 */
2650 2651 2652 2653 2654 2655
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_speed = mv88e6185_port_set_speed,
2656
	.port_tag_remap = mv88e6095_port_tag_remap,
2657
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2658
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2659
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2660
	.port_jumbo_config = mv88e6165_port_jumbo_config,
2661
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
2662
	.port_pause_config = mv88e6097_port_pause_config,
2663
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2664
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2665 2666 2667 2668
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
	.stats_get_stats = mv88e6095_stats_get_stats,
2669 2670
	.g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
	.g1_set_egress_port = mv88e6095_g1_set_egress_port,
2671
	.watchdog_ops = &mv88e6097_watchdog_ops,
2672
	.mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
2673
	.reset = mv88e6352_g1_reset,
2674
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2675
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2676 2677
};

2678
static const struct mv88e6xxx_ops mv88e6123_ops = {
2679
	/* MV88E6XXX_FAMILY_6165 */
2680
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2681 2682
	.phy_read = mv88e6165_phy_read,
	.phy_write = mv88e6165_phy_write,
2683
	.port_set_link = mv88e6xxx_port_set_link,
2684
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2685
	.port_set_speed = mv88e6185_port_set_speed,
2686
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2687
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2688
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2689
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2690
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2691 2692
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2693
	.stats_get_stats = mv88e6095_stats_get_stats,
2694 2695
	.g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
	.g1_set_egress_port = mv88e6095_g1_set_egress_port,
2696
	.watchdog_ops = &mv88e6097_watchdog_ops,
2697
	.mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
2698
	.reset = mv88e6352_g1_reset,
2699
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2700
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2701 2702 2703
};

static const struct mv88e6xxx_ops mv88e6131_ops = {
2704
	/* MV88E6XXX_FAMILY_6185 */
2705
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2706 2707
	.phy_read = mv88e6xxx_phy_ppu_read,
	.phy_write = mv88e6xxx_phy_ppu_write,
2708
	.port_set_link = mv88e6xxx_port_set_link,
2709
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2710
	.port_set_speed = mv88e6185_port_set_speed,
2711
	.port_tag_remap = mv88e6095_port_tag_remap,
2712
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2713
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2714
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2715
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2716
	.port_jumbo_config = mv88e6165_port_jumbo_config,
2717
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2718
	.port_pause_config = mv88e6097_port_pause_config,
2719
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2720 2721
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2722
	.stats_get_stats = mv88e6095_stats_get_stats,
2723 2724
	.g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
	.g1_set_egress_port = mv88e6095_g1_set_egress_port,
2725
	.watchdog_ops = &mv88e6097_watchdog_ops,
2726
	.mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
2727 2728
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2729
	.reset = mv88e6185_g1_reset,
2730
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2731
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2732 2733
};

2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762
static const struct mv88e6xxx_ops mv88e6141_ops = {
	/* MV88E6XXX_FAMILY_6341 */
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
	.port_set_speed = mv88e6390_port_set_speed,
	.port_tag_remap = mv88e6095_port_tag_remap,
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
	.port_set_ether_type = mv88e6351_port_set_ether_type,
	.port_jumbo_config = mv88e6165_port_jumbo_config,
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
	.port_pause_config = mv88e6097_port_pause_config,
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
	.g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
	.g1_set_egress_port = mv88e6390_g1_set_egress_port,
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
	.reset = mv88e6352_g1_reset,
2763
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2764
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2765 2766
};

2767
static const struct mv88e6xxx_ops mv88e6161_ops = {
2768
	/* MV88E6XXX_FAMILY_6165 */
2769
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2770 2771
	.phy_read = mv88e6165_phy_read,
	.phy_write = mv88e6165_phy_write,
2772
	.port_set_link = mv88e6xxx_port_set_link,
2773
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2774
	.port_set_speed = mv88e6185_port_set_speed,
2775
	.port_tag_remap = mv88e6095_port_tag_remap,
2776
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2777
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2778
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2779
	.port_jumbo_config = mv88e6165_port_jumbo_config,
2780
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2781
	.port_pause_config = mv88e6097_port_pause_config,
2782
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2783
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2784
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2785 2786
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2787
	.stats_get_stats = mv88e6095_stats_get_stats,
2788 2789
	.g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
	.g1_set_egress_port = mv88e6095_g1_set_egress_port,
2790
	.watchdog_ops = &mv88e6097_watchdog_ops,
2791
	.mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
2792
	.reset = mv88e6352_g1_reset,
2793
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2794
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2795 2796 2797
};

static const struct mv88e6xxx_ops mv88e6165_ops = {
2798
	/* MV88E6XXX_FAMILY_6165 */
2799
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2800 2801
	.phy_read = mv88e6165_phy_read,
	.phy_write = mv88e6165_phy_write,
2802
	.port_set_link = mv88e6xxx_port_set_link,
2803
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2804
	.port_set_speed = mv88e6185_port_set_speed,
2805
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2806
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2807
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2808 2809
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2810
	.stats_get_stats = mv88e6095_stats_get_stats,
2811 2812
	.g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
	.g1_set_egress_port = mv88e6095_g1_set_egress_port,
2813
	.watchdog_ops = &mv88e6097_watchdog_ops,
2814
	.mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
2815
	.reset = mv88e6352_g1_reset,
2816
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2817
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2818 2819 2820
};

static const struct mv88e6xxx_ops mv88e6171_ops = {
2821
	/* MV88E6XXX_FAMILY_6351 */
2822
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2823 2824
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2825
	.port_set_link = mv88e6xxx_port_set_link,
2826
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2827
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
2828
	.port_set_speed = mv88e6185_port_set_speed,
2829
	.port_tag_remap = mv88e6095_port_tag_remap,
2830
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2831
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2832
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2833
	.port_jumbo_config = mv88e6165_port_jumbo_config,
2834
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2835
	.port_pause_config = mv88e6097_port_pause_config,
2836
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2837
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2838
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2839 2840
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2841
	.stats_get_stats = mv88e6095_stats_get_stats,
2842 2843
	.g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
	.g1_set_egress_port = mv88e6095_g1_set_egress_port,
2844
	.watchdog_ops = &mv88e6097_watchdog_ops,
2845
	.mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
2846
	.reset = mv88e6352_g1_reset,
2847
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2848
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2849 2850 2851
};

static const struct mv88e6xxx_ops mv88e6172_ops = {
2852
	/* MV88E6XXX_FAMILY_6352 */
2853 2854
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
2855
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2856 2857
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2858
	.port_set_link = mv88e6xxx_port_set_link,
2859
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2860
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
2861
	.port_set_speed = mv88e6352_port_set_speed,
2862
	.port_tag_remap = mv88e6095_port_tag_remap,
2863
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2864
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2865
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2866
	.port_jumbo_config = mv88e6165_port_jumbo_config,
2867
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2868
	.port_pause_config = mv88e6097_port_pause_config,
2869
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2870
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2871
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2872 2873
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2874
	.stats_get_stats = mv88e6095_stats_get_stats,
2875 2876
	.g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
	.g1_set_egress_port = mv88e6095_g1_set_egress_port,
2877
	.watchdog_ops = &mv88e6097_watchdog_ops,
2878
	.mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
2879
	.reset = mv88e6352_g1_reset,
2880
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2881
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2882 2883 2884
};

static const struct mv88e6xxx_ops mv88e6175_ops = {
2885
	/* MV88E6XXX_FAMILY_6351 */
2886
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2887 2888
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2889
	.port_set_link = mv88e6xxx_port_set_link,
2890
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2891
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
2892
	.port_set_speed = mv88e6185_port_set_speed,
2893
	.port_tag_remap = mv88e6095_port_tag_remap,
2894
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2895
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2896
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2897
	.port_jumbo_config = mv88e6165_port_jumbo_config,
2898
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2899
	.port_pause_config = mv88e6097_port_pause_config,
2900
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2901
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2902
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2903 2904
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2905
	.stats_get_stats = mv88e6095_stats_get_stats,
2906 2907
	.g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
	.g1_set_egress_port = mv88e6095_g1_set_egress_port,
2908
	.watchdog_ops = &mv88e6097_watchdog_ops,
2909
	.mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
2910
	.reset = mv88e6352_g1_reset,
2911
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2912
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2913 2914 2915
};

static const struct mv88e6xxx_ops mv88e6176_ops = {
2916
	/* MV88E6XXX_FAMILY_6352 */
2917 2918
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
2919
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2920 2921
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
2922
	.port_set_link = mv88e6xxx_port_set_link,
2923
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2924
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
2925
	.port_set_speed = mv88e6352_port_set_speed,
2926
	.port_tag_remap = mv88e6095_port_tag_remap,
2927
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2928
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2929
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2930
	.port_jumbo_config = mv88e6165_port_jumbo_config,
2931
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2932
	.port_pause_config = mv88e6097_port_pause_config,
2933
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2934
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2935
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
2936 2937
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2938
	.stats_get_stats = mv88e6095_stats_get_stats,
2939 2940
	.g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
	.g1_set_egress_port = mv88e6095_g1_set_egress_port,
2941
	.watchdog_ops = &mv88e6097_watchdog_ops,
2942
	.mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
2943
	.reset = mv88e6352_g1_reset,
2944
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
2945
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
2946 2947 2948
};

static const struct mv88e6xxx_ops mv88e6185_ops = {
2949
	/* MV88E6XXX_FAMILY_6185 */
2950
	.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
2951 2952
	.phy_read = mv88e6xxx_phy_ppu_read,
	.phy_write = mv88e6xxx_phy_ppu_write,
2953
	.port_set_link = mv88e6xxx_port_set_link,
2954
	.port_set_duplex = mv88e6xxx_port_set_duplex,
2955
	.port_set_speed = mv88e6185_port_set_speed,
2956
	.port_set_frame_mode = mv88e6085_port_set_frame_mode,
2957
	.port_set_egress_floods = mv88e6185_port_set_egress_floods,
2958
	.port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
2959
	.port_set_upstream_port = mv88e6095_port_set_upstream_port,
2960
	.stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2961 2962
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
2963
	.stats_get_stats = mv88e6095_stats_get_stats,
2964 2965
	.g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
	.g1_set_egress_port = mv88e6095_g1_set_egress_port,
2966
	.watchdog_ops = &mv88e6097_watchdog_ops,
2967
	.mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
2968 2969
	.ppu_enable = mv88e6185_g1_ppu_enable,
	.ppu_disable = mv88e6185_g1_ppu_disable,
2970
	.reset = mv88e6185_g1_reset,
2971
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
2972
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
2973 2974
};

2975
static const struct mv88e6xxx_ops mv88e6190_ops = {
2976
	/* MV88E6XXX_FAMILY_6390 */
2977 2978
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
2979 2980 2981 2982 2983 2984 2985
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
	.port_set_speed = mv88e6390_port_set_speed,
2986
	.port_tag_remap = mv88e6390_port_tag_remap,
2987
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
2988
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
2989
	.port_set_ether_type = mv88e6351_port_set_ether_type,
2990
	.port_pause_config = mv88e6390_port_pause_config,
2991
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2992
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2993
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
2994
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
2995 2996
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
2997
	.stats_get_stats = mv88e6390_stats_get_stats,
2998 2999
	.g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
	.g1_set_egress_port = mv88e6390_g1_set_egress_port,
3000
	.watchdog_ops = &mv88e6390_watchdog_ops,
3001
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3002
	.reset = mv88e6352_g1_reset,
3003 3004
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3005 3006 3007
};

static const struct mv88e6xxx_ops mv88e6190x_ops = {
3008
	/* MV88E6XXX_FAMILY_6390 */
3009 3010
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3011 3012 3013 3014 3015 3016 3017
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
	.port_set_speed = mv88e6390x_port_set_speed,
3018
	.port_tag_remap = mv88e6390_port_tag_remap,
3019
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3020
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3021
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3022
	.port_pause_config = mv88e6390_port_pause_config,
3023
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3024
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3025
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3026
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3027 3028
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3029
	.stats_get_stats = mv88e6390_stats_get_stats,
3030 3031
	.g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
	.g1_set_egress_port = mv88e6390_g1_set_egress_port,
3032
	.watchdog_ops = &mv88e6390_watchdog_ops,
3033
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3034
	.reset = mv88e6352_g1_reset,
3035 3036
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3037 3038 3039
};

static const struct mv88e6xxx_ops mv88e6191_ops = {
3040
	/* MV88E6XXX_FAMILY_6390 */
3041 3042
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3043 3044 3045 3046 3047 3048 3049
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
	.port_set_speed = mv88e6390_port_set_speed,
3050
	.port_tag_remap = mv88e6390_port_tag_remap,
3051
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3052
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3053
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3054
	.port_pause_config = mv88e6390_port_pause_config,
3055
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3056
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3057
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3058
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3059 3060
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3061
	.stats_get_stats = mv88e6390_stats_get_stats,
3062 3063
	.g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
	.g1_set_egress_port = mv88e6390_g1_set_egress_port,
3064
	.watchdog_ops = &mv88e6390_watchdog_ops,
3065
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3066
	.reset = mv88e6352_g1_reset,
3067 3068
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3069 3070
};

3071
static const struct mv88e6xxx_ops mv88e6240_ops = {
3072
	/* MV88E6XXX_FAMILY_6352 */
3073 3074
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3075
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3076 3077
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3078
	.port_set_link = mv88e6xxx_port_set_link,
3079
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3080
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3081
	.port_set_speed = mv88e6352_port_set_speed,
3082
	.port_tag_remap = mv88e6095_port_tag_remap,
3083
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3084
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3085
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3086
	.port_jumbo_config = mv88e6165_port_jumbo_config,
3087
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3088
	.port_pause_config = mv88e6097_port_pause_config,
3089
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3090
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3091
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3092 3093
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3094
	.stats_get_stats = mv88e6095_stats_get_stats,
3095 3096
	.g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
	.g1_set_egress_port = mv88e6095_g1_set_egress_port,
3097
	.watchdog_ops = &mv88e6097_watchdog_ops,
3098
	.mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
3099
	.reset = mv88e6352_g1_reset,
3100
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3101
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3102 3103
};

3104
static const struct mv88e6xxx_ops mv88e6290_ops = {
3105
	/* MV88E6XXX_FAMILY_6390 */
3106 3107
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3108 3109 3110 3111 3112 3113 3114
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
	.port_set_speed = mv88e6390_port_set_speed,
3115
	.port_tag_remap = mv88e6390_port_tag_remap,
3116
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3117
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3118
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3119
	.port_pause_config = mv88e6390_port_pause_config,
3120
	.port_set_cmode = mv88e6390x_port_set_cmode,
3121
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3122
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3123
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3124
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3125 3126
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3127
	.stats_get_stats = mv88e6390_stats_get_stats,
3128 3129
	.g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
	.g1_set_egress_port = mv88e6390_g1_set_egress_port,
3130
	.watchdog_ops = &mv88e6390_watchdog_ops,
3131
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3132
	.reset = mv88e6352_g1_reset,
3133 3134
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3135 3136
};

3137
static const struct mv88e6xxx_ops mv88e6320_ops = {
3138
	/* MV88E6XXX_FAMILY_6320 */
3139 3140
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3141
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3142 3143
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3144
	.port_set_link = mv88e6xxx_port_set_link,
3145
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3146
	.port_set_speed = mv88e6185_port_set_speed,
3147
	.port_tag_remap = mv88e6095_port_tag_remap,
3148
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3149
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3150
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3151
	.port_jumbo_config = mv88e6165_port_jumbo_config,
3152
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3153
	.port_pause_config = mv88e6097_port_pause_config,
3154
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3155
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3156
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3157 3158
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3159
	.stats_get_stats = mv88e6320_stats_get_stats,
3160 3161
	.g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
	.g1_set_egress_port = mv88e6095_g1_set_egress_port,
3162
	.mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
3163
	.reset = mv88e6352_g1_reset,
3164
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3165
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3166 3167 3168
};

static const struct mv88e6xxx_ops mv88e6321_ops = {
3169
	/* MV88E6XXX_FAMILY_6321 */
3170 3171
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3172
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3173 3174
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3175
	.port_set_link = mv88e6xxx_port_set_link,
3176
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3177
	.port_set_speed = mv88e6185_port_set_speed,
3178
	.port_tag_remap = mv88e6095_port_tag_remap,
3179
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3180
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3181
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3182
	.port_jumbo_config = mv88e6165_port_jumbo_config,
3183
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3184
	.port_pause_config = mv88e6097_port_pause_config,
3185
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3186
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3187
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3188 3189
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3190
	.stats_get_stats = mv88e6320_stats_get_stats,
3191 3192
	.g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
	.g1_set_egress_port = mv88e6095_g1_set_egress_port,
3193
	.reset = mv88e6352_g1_reset,
3194
	.vtu_getnext = mv88e6185_g1_vtu_getnext,
3195
	.vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
3196 3197
};

3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226
static const struct mv88e6xxx_ops mv88e6341_ops = {
	/* MV88E6XXX_FAMILY_6341 */
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
	.port_set_speed = mv88e6390_port_set_speed,
	.port_tag_remap = mv88e6095_port_tag_remap,
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
	.port_set_ether_type = mv88e6351_port_set_ether_type,
	.port_jumbo_config = mv88e6165_port_jumbo_config,
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
	.port_pause_config = mv88e6097_port_pause_config,
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
	.stats_get_stats = mv88e6390_stats_get_stats,
	.g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
	.g1_set_egress_port = mv88e6390_g1_set_egress_port,
	.watchdog_ops = &mv88e6390_watchdog_ops,
	.mgmt_rsvd2cpu =  mv88e6390_g1_mgmt_rsvd2cpu,
	.reset = mv88e6352_g1_reset,
3227
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3228
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3229 3230
};

3231
static const struct mv88e6xxx_ops mv88e6350_ops = {
3232
	/* MV88E6XXX_FAMILY_6351 */
3233
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3234 3235
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3236
	.port_set_link = mv88e6xxx_port_set_link,
3237
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3238
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3239
	.port_set_speed = mv88e6185_port_set_speed,
3240
	.port_tag_remap = mv88e6095_port_tag_remap,
3241
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3242
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3243
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3244
	.port_jumbo_config = mv88e6165_port_jumbo_config,
3245
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3246
	.port_pause_config = mv88e6097_port_pause_config,
3247
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3248
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3249
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3250 3251
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3252
	.stats_get_stats = mv88e6095_stats_get_stats,
3253 3254
	.g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
	.g1_set_egress_port = mv88e6095_g1_set_egress_port,
3255
	.watchdog_ops = &mv88e6097_watchdog_ops,
3256
	.mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
3257
	.reset = mv88e6352_g1_reset,
3258
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3259
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3260 3261 3262
};

static const struct mv88e6xxx_ops mv88e6351_ops = {
3263
	/* MV88E6XXX_FAMILY_6351 */
3264
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3265 3266
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3267
	.port_set_link = mv88e6xxx_port_set_link,
3268
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3269
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3270
	.port_set_speed = mv88e6185_port_set_speed,
3271
	.port_tag_remap = mv88e6095_port_tag_remap,
3272
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3273
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3274
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3275
	.port_jumbo_config = mv88e6165_port_jumbo_config,
3276
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3277
	.port_pause_config = mv88e6097_port_pause_config,
3278
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3279
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3280
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3281 3282
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3283
	.stats_get_stats = mv88e6095_stats_get_stats,
3284 3285
	.g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
	.g1_set_egress_port = mv88e6095_g1_set_egress_port,
3286
	.watchdog_ops = &mv88e6097_watchdog_ops,
3287
	.mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
3288
	.reset = mv88e6352_g1_reset,
3289
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3290
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3291 3292 3293
};

static const struct mv88e6xxx_ops mv88e6352_ops = {
3294
	/* MV88E6XXX_FAMILY_6352 */
3295 3296
	.get_eeprom = mv88e6xxx_g2_get_eeprom16,
	.set_eeprom = mv88e6xxx_g2_set_eeprom16,
3297
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3298 3299
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
3300
	.port_set_link = mv88e6xxx_port_set_link,
3301
	.port_set_duplex = mv88e6xxx_port_set_duplex,
3302
	.port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3303
	.port_set_speed = mv88e6352_port_set_speed,
3304
	.port_tag_remap = mv88e6095_port_tag_remap,
3305
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3306
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3307
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3308
	.port_jumbo_config = mv88e6165_port_jumbo_config,
3309
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3310
	.port_pause_config = mv88e6097_port_pause_config,
3311
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3312
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3313
	.stats_snapshot = mv88e6320_g1_stats_snapshot,
3314 3315
	.stats_get_sset_count = mv88e6095_stats_get_sset_count,
	.stats_get_strings = mv88e6095_stats_get_strings,
3316
	.stats_get_stats = mv88e6095_stats_get_stats,
3317 3318
	.g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
	.g1_set_egress_port = mv88e6095_g1_set_egress_port,
3319
	.watchdog_ops = &mv88e6097_watchdog_ops,
3320
	.mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
3321
	.reset = mv88e6352_g1_reset,
3322
	.vtu_getnext = mv88e6352_g1_vtu_getnext,
3323
	.vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
3324 3325
};

3326
static const struct mv88e6xxx_ops mv88e6390_ops = {
3327
	/* MV88E6XXX_FAMILY_6390 */
3328 3329
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3330 3331 3332 3333 3334 3335 3336
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
	.port_set_speed = mv88e6390_port_set_speed,
3337
	.port_tag_remap = mv88e6390_port_tag_remap,
3338
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3339
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3340
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3341
	.port_jumbo_config = mv88e6165_port_jumbo_config,
3342
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3343
	.port_pause_config = mv88e6390_port_pause_config,
3344
	.port_set_cmode = mv88e6390x_port_set_cmode,
3345
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3346
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3347
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3348
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3349 3350
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3351
	.stats_get_stats = mv88e6390_stats_get_stats,
3352 3353
	.g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
	.g1_set_egress_port = mv88e6390_g1_set_egress_port,
3354
	.watchdog_ops = &mv88e6390_watchdog_ops,
3355
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3356
	.reset = mv88e6352_g1_reset,
3357 3358
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3359 3360 3361
};

static const struct mv88e6xxx_ops mv88e6390x_ops = {
3362
	/* MV88E6XXX_FAMILY_6390 */
3363 3364
	.get_eeprom = mv88e6xxx_g2_get_eeprom8,
	.set_eeprom = mv88e6xxx_g2_set_eeprom8,
3365 3366 3367 3368 3369 3370 3371
	.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
	.phy_read = mv88e6xxx_g2_smi_phy_read,
	.phy_write = mv88e6xxx_g2_smi_phy_write,
	.port_set_link = mv88e6xxx_port_set_link,
	.port_set_duplex = mv88e6xxx_port_set_duplex,
	.port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
	.port_set_speed = mv88e6390x_port_set_speed,
3372
	.port_tag_remap = mv88e6390_port_tag_remap,
3373
	.port_set_frame_mode = mv88e6351_port_set_frame_mode,
3374
	.port_set_egress_floods = mv88e6352_port_set_egress_floods,
3375
	.port_set_ether_type = mv88e6351_port_set_ether_type,
3376
	.port_jumbo_config = mv88e6165_port_jumbo_config,
3377
	.port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3378
	.port_pause_config = mv88e6390_port_pause_config,
3379
	.port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3380
	.port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3381
	.stats_snapshot = mv88e6390_g1_stats_snapshot,
3382
	.stats_set_histogram = mv88e6390_g1_stats_set_histogram,
3383 3384
	.stats_get_sset_count = mv88e6320_stats_get_sset_count,
	.stats_get_strings = mv88e6320_stats_get_strings,
3385
	.stats_get_stats = mv88e6390_stats_get_stats,
3386 3387
	.g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
	.g1_set_egress_port = mv88e6390_g1_set_egress_port,
3388
	.watchdog_ops = &mv88e6390_watchdog_ops,
3389
	.mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3390
	.reset = mv88e6352_g1_reset,
3391 3392
	.vtu_getnext = mv88e6390_g1_vtu_getnext,
	.vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
3393 3394
};

3395 3396 3397 3398 3399 3400 3401
static const struct mv88e6xxx_info mv88e6xxx_table[] = {
	[MV88E6085] = {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6085",
		.num_databases = 4096,
		.num_ports = 10,
3402
		.max_vid = 4095,
3403
		.port_base_addr = 0x10,
3404
		.global1_addr = 0x1b,
3405
		.age_time_coeff = 15000,
3406
		.g1_irqs = 8,
3407
		.atu_move_port_mask = 0xf,
3408
		.pvt = true,
3409
		.tag_protocol = DSA_TAG_PROTO_DSA,
3410
		.flags = MV88E6XXX_FLAGS_FAMILY_6097,
3411
		.ops = &mv88e6085_ops,
3412 3413 3414 3415 3416 3417 3418 3419
	},

	[MV88E6095] = {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
		.family = MV88E6XXX_FAMILY_6095,
		.name = "Marvell 88E6095/88E6095F",
		.num_databases = 256,
		.num_ports = 11,
3420
		.max_vid = 4095,
3421
		.port_base_addr = 0x10,
3422
		.global1_addr = 0x1b,
3423
		.age_time_coeff = 15000,
3424
		.g1_irqs = 8,
3425
		.atu_move_port_mask = 0xf,
3426
		.tag_protocol = DSA_TAG_PROTO_DSA,
3427
		.flags = MV88E6XXX_FLAGS_FAMILY_6095,
3428
		.ops = &mv88e6095_ops,
3429 3430
	},

3431 3432 3433 3434 3435 3436
	[MV88E6097] = {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6097,
		.family = MV88E6XXX_FAMILY_6097,
		.name = "Marvell 88E6097/88E6097F",
		.num_databases = 4096,
		.num_ports = 11,
3437
		.max_vid = 4095,
3438 3439 3440
		.port_base_addr = 0x10,
		.global1_addr = 0x1b,
		.age_time_coeff = 15000,
3441
		.g1_irqs = 8,
3442
		.atu_move_port_mask = 0xf,
3443
		.pvt = true,
3444
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3445 3446 3447 3448
		.flags = MV88E6XXX_FLAGS_FAMILY_6097,
		.ops = &mv88e6097_ops,
	},

3449 3450 3451 3452 3453 3454
	[MV88E6123] = {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6123",
		.num_databases = 4096,
		.num_ports = 3,
3455
		.max_vid = 4095,
3456
		.port_base_addr = 0x10,
3457
		.global1_addr = 0x1b,
3458
		.age_time_coeff = 15000,
3459
		.g1_irqs = 9,
3460
		.atu_move_port_mask = 0xf,
3461
		.pvt = true,
3462
		.tag_protocol = DSA_TAG_PROTO_DSA,
3463
		.flags = MV88E6XXX_FLAGS_FAMILY_6165,
3464
		.ops = &mv88e6123_ops,
3465 3466 3467 3468 3469 3470 3471 3472
	},

	[MV88E6131] = {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6131",
		.num_databases = 256,
		.num_ports = 8,
3473
		.max_vid = 4095,
3474
		.port_base_addr = 0x10,
3475
		.global1_addr = 0x1b,
3476
		.age_time_coeff = 15000,
3477
		.g1_irqs = 9,
3478
		.atu_move_port_mask = 0xf,
3479
		.tag_protocol = DSA_TAG_PROTO_DSA,
3480
		.flags = MV88E6XXX_FLAGS_FAMILY_6185,
3481
		.ops = &mv88e6131_ops,
3482 3483
	},

3484 3485 3486 3487 3488 3489
	[MV88E6141] = {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6141,
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
		.num_ports = 6,
3490
		.max_vid = 4095,
3491 3492 3493 3494
		.port_base_addr = 0x10,
		.global1_addr = 0x1b,
		.age_time_coeff = 3750,
		.atu_move_port_mask = 0x1f,
3495
		.pvt = true,
3496 3497 3498 3499 3500
		.tag_protocol = DSA_TAG_PROTO_EDSA,
		.flags = MV88E6XXX_FLAGS_FAMILY_6341,
		.ops = &mv88e6141_ops,
	},

3501 3502 3503 3504 3505 3506
	[MV88E6161] = {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6161",
		.num_databases = 4096,
		.num_ports = 6,
3507
		.max_vid = 4095,
3508
		.port_base_addr = 0x10,
3509
		.global1_addr = 0x1b,
3510
		.age_time_coeff = 15000,
3511
		.g1_irqs = 9,
3512
		.atu_move_port_mask = 0xf,
3513
		.pvt = true,
3514
		.tag_protocol = DSA_TAG_PROTO_DSA,
3515
		.flags = MV88E6XXX_FLAGS_FAMILY_6165,
3516
		.ops = &mv88e6161_ops,
3517 3518 3519 3520 3521 3522 3523 3524
	},

	[MV88E6165] = {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
		.family = MV88E6XXX_FAMILY_6165,
		.name = "Marvell 88E6165",
		.num_databases = 4096,
		.num_ports = 6,
3525
		.max_vid = 4095,
3526
		.port_base_addr = 0x10,
3527
		.global1_addr = 0x1b,
3528
		.age_time_coeff = 15000,
3529
		.g1_irqs = 9,
3530
		.atu_move_port_mask = 0xf,
3531
		.pvt = true,
3532
		.tag_protocol = DSA_TAG_PROTO_DSA,
3533
		.flags = MV88E6XXX_FLAGS_FAMILY_6165,
3534
		.ops = &mv88e6165_ops,
3535 3536 3537 3538 3539 3540 3541 3542
	},

	[MV88E6171] = {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6171",
		.num_databases = 4096,
		.num_ports = 7,
3543
		.max_vid = 4095,
3544
		.port_base_addr = 0x10,
3545
		.global1_addr = 0x1b,
3546
		.age_time_coeff = 15000,
3547
		.g1_irqs = 9,
3548
		.atu_move_port_mask = 0xf,
3549
		.pvt = true,
3550
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3551
		.flags = MV88E6XXX_FLAGS_FAMILY_6351,
3552
		.ops = &mv88e6171_ops,
3553 3554 3555 3556 3557 3558 3559 3560
	},

	[MV88E6172] = {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6172",
		.num_databases = 4096,
		.num_ports = 7,
3561
		.max_vid = 4095,
3562
		.port_base_addr = 0x10,
3563
		.global1_addr = 0x1b,
3564
		.age_time_coeff = 15000,
3565
		.g1_irqs = 9,
3566
		.atu_move_port_mask = 0xf,
3567
		.pvt = true,
3568
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3569
		.flags = MV88E6XXX_FLAGS_FAMILY_6352,
3570
		.ops = &mv88e6172_ops,
3571 3572 3573 3574 3575 3576 3577 3578
	},

	[MV88E6175] = {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6175",
		.num_databases = 4096,
		.num_ports = 7,
3579
		.max_vid = 4095,
3580
		.port_base_addr = 0x10,
3581
		.global1_addr = 0x1b,
3582
		.age_time_coeff = 15000,
3583
		.g1_irqs = 9,
3584
		.atu_move_port_mask = 0xf,
3585
		.pvt = true,
3586
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3587
		.flags = MV88E6XXX_FLAGS_FAMILY_6351,
3588
		.ops = &mv88e6175_ops,
3589 3590 3591 3592 3593 3594 3595 3596
	},

	[MV88E6176] = {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6176",
		.num_databases = 4096,
		.num_ports = 7,
3597
		.max_vid = 4095,
3598
		.port_base_addr = 0x10,
3599
		.global1_addr = 0x1b,
3600
		.age_time_coeff = 15000,
3601
		.g1_irqs = 9,
3602
		.atu_move_port_mask = 0xf,
3603
		.pvt = true,
3604
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3605
		.flags = MV88E6XXX_FLAGS_FAMILY_6352,
3606
		.ops = &mv88e6176_ops,
3607 3608 3609 3610 3611 3612 3613 3614
	},

	[MV88E6185] = {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
		.family = MV88E6XXX_FAMILY_6185,
		.name = "Marvell 88E6185",
		.num_databases = 256,
		.num_ports = 10,
3615
		.max_vid = 4095,
3616
		.port_base_addr = 0x10,
3617
		.global1_addr = 0x1b,
3618
		.age_time_coeff = 15000,
3619
		.g1_irqs = 8,
3620
		.atu_move_port_mask = 0xf,
3621
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3622
		.flags = MV88E6XXX_FLAGS_FAMILY_6185,
3623
		.ops = &mv88e6185_ops,
3624 3625
	},

3626 3627 3628 3629 3630 3631
	[MV88E6190] = {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6190,
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3632
		.max_vid = 8191,
3633 3634
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3635
		.tag_protocol = DSA_TAG_PROTO_DSA,
3636
		.age_time_coeff = 3750,
3637
		.g1_irqs = 9,
3638
		.pvt = true,
3639
		.atu_move_port_mask = 0x1f,
3640 3641 3642 3643 3644 3645 3646 3647 3648 3649
		.flags = MV88E6XXX_FLAGS_FAMILY_6390,
		.ops = &mv88e6190_ops,
	},

	[MV88E6190X] = {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6190X,
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6190X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3650
		.max_vid = 8191,
3651 3652
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3653
		.age_time_coeff = 3750,
3654
		.g1_irqs = 9,
3655
		.atu_move_port_mask = 0x1f,
3656
		.pvt = true,
3657
		.tag_protocol = DSA_TAG_PROTO_DSA,
3658 3659 3660 3661 3662 3663 3664 3665 3666 3667
		.flags = MV88E6XXX_FLAGS_FAMILY_6390,
		.ops = &mv88e6190x_ops,
	},

	[MV88E6191] = {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6191,
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6191",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3668
		.max_vid = 8191,
3669 3670
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3671
		.age_time_coeff = 3750,
3672
		.g1_irqs = 9,
3673
		.atu_move_port_mask = 0x1f,
3674
		.pvt = true,
3675
		.tag_protocol = DSA_TAG_PROTO_DSA,
3676
		.flags = MV88E6XXX_FLAGS_FAMILY_6390,
3677
		.ops = &mv88e6191_ops,
3678 3679
	},

3680 3681 3682 3683 3684 3685
	[MV88E6240] = {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6240",
		.num_databases = 4096,
		.num_ports = 7,
3686
		.max_vid = 4095,
3687
		.port_base_addr = 0x10,
3688
		.global1_addr = 0x1b,
3689
		.age_time_coeff = 15000,
3690
		.g1_irqs = 9,
3691
		.atu_move_port_mask = 0xf,
3692
		.pvt = true,
3693
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3694
		.flags = MV88E6XXX_FLAGS_FAMILY_6352,
3695
		.ops = &mv88e6240_ops,
3696 3697
	},

3698 3699 3700 3701 3702 3703
	[MV88E6290] = {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6290,
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6290",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3704
		.max_vid = 8191,
3705 3706
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3707
		.age_time_coeff = 3750,
3708
		.g1_irqs = 9,
3709
		.atu_move_port_mask = 0x1f,
3710
		.pvt = true,
3711
		.tag_protocol = DSA_TAG_PROTO_DSA,
3712 3713 3714 3715
		.flags = MV88E6XXX_FLAGS_FAMILY_6390,
		.ops = &mv88e6290_ops,
	},

3716 3717 3718 3719 3720 3721
	[MV88E6320] = {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6320",
		.num_databases = 4096,
		.num_ports = 7,
3722
		.max_vid = 4095,
3723
		.port_base_addr = 0x10,
3724
		.global1_addr = 0x1b,
3725
		.age_time_coeff = 15000,
3726
		.g1_irqs = 8,
3727
		.atu_move_port_mask = 0xf,
3728
		.pvt = true,
3729
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3730
		.flags = MV88E6XXX_FLAGS_FAMILY_6320,
3731
		.ops = &mv88e6320_ops,
3732 3733 3734 3735 3736 3737 3738 3739
	},

	[MV88E6321] = {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
		.family = MV88E6XXX_FAMILY_6320,
		.name = "Marvell 88E6321",
		.num_databases = 4096,
		.num_ports = 7,
3740
		.max_vid = 4095,
3741
		.port_base_addr = 0x10,
3742
		.global1_addr = 0x1b,
3743
		.age_time_coeff = 15000,
3744
		.g1_irqs = 8,
3745
		.atu_move_port_mask = 0xf,
3746
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3747
		.flags = MV88E6XXX_FLAGS_FAMILY_6320,
3748
		.ops = &mv88e6321_ops,
3749 3750
	},

3751 3752 3753 3754 3755 3756
	[MV88E6341] = {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6341,
		.family = MV88E6XXX_FAMILY_6341,
		.name = "Marvell 88E6341",
		.num_databases = 4096,
		.num_ports = 6,
3757
		.max_vid = 4095,
3758 3759 3760
		.port_base_addr = 0x10,
		.global1_addr = 0x1b,
		.age_time_coeff = 3750,
3761
		.atu_move_port_mask = 0x1f,
3762
		.pvt = true,
3763 3764 3765 3766 3767
		.tag_protocol = DSA_TAG_PROTO_EDSA,
		.flags = MV88E6XXX_FLAGS_FAMILY_6341,
		.ops = &mv88e6341_ops,
	},

3768 3769 3770 3771 3772 3773
	[MV88E6350] = {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6350",
		.num_databases = 4096,
		.num_ports = 7,
3774
		.max_vid = 4095,
3775
		.port_base_addr = 0x10,
3776
		.global1_addr = 0x1b,
3777
		.age_time_coeff = 15000,
3778
		.g1_irqs = 9,
3779
		.atu_move_port_mask = 0xf,
3780
		.pvt = true,
3781
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3782
		.flags = MV88E6XXX_FLAGS_FAMILY_6351,
3783
		.ops = &mv88e6350_ops,
3784 3785 3786 3787 3788 3789 3790 3791
	},

	[MV88E6351] = {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
		.family = MV88E6XXX_FAMILY_6351,
		.name = "Marvell 88E6351",
		.num_databases = 4096,
		.num_ports = 7,
3792
		.max_vid = 4095,
3793
		.port_base_addr = 0x10,
3794
		.global1_addr = 0x1b,
3795
		.age_time_coeff = 15000,
3796
		.g1_irqs = 9,
3797
		.atu_move_port_mask = 0xf,
3798
		.pvt = true,
3799
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3800
		.flags = MV88E6XXX_FLAGS_FAMILY_6351,
3801
		.ops = &mv88e6351_ops,
3802 3803 3804 3805 3806 3807 3808 3809
	},

	[MV88E6352] = {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
		.family = MV88E6XXX_FAMILY_6352,
		.name = "Marvell 88E6352",
		.num_databases = 4096,
		.num_ports = 7,
3810
		.max_vid = 4095,
3811
		.port_base_addr = 0x10,
3812
		.global1_addr = 0x1b,
3813
		.age_time_coeff = 15000,
3814
		.g1_irqs = 9,
3815
		.atu_move_port_mask = 0xf,
3816
		.pvt = true,
3817
		.tag_protocol = DSA_TAG_PROTO_EDSA,
3818
		.flags = MV88E6XXX_FLAGS_FAMILY_6352,
3819
		.ops = &mv88e6352_ops,
3820
	},
3821 3822 3823 3824 3825 3826
	[MV88E6390] = {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6390,
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3827
		.max_vid = 8191,
3828 3829
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3830
		.age_time_coeff = 3750,
3831
		.g1_irqs = 9,
3832
		.atu_move_port_mask = 0x1f,
3833
		.pvt = true,
3834
		.tag_protocol = DSA_TAG_PROTO_DSA,
3835 3836 3837 3838 3839 3840 3841 3842 3843
		.flags = MV88E6XXX_FLAGS_FAMILY_6390,
		.ops = &mv88e6390_ops,
	},
	[MV88E6390X] = {
		.prod_num = PORT_SWITCH_ID_PROD_NUM_6390X,
		.family = MV88E6XXX_FAMILY_6390,
		.name = "Marvell 88E6390X",
		.num_databases = 4096,
		.num_ports = 11,	/* 10 + Z80 */
3844
		.max_vid = 8191,
3845 3846
		.port_base_addr = 0x0,
		.global1_addr = 0x1b,
3847
		.age_time_coeff = 3750,
3848
		.g1_irqs = 9,
3849
		.atu_move_port_mask = 0x1f,
3850
		.pvt = true,
3851
		.tag_protocol = DSA_TAG_PROTO_DSA,
3852 3853 3854
		.flags = MV88E6XXX_FLAGS_FAMILY_6390,
		.ops = &mv88e6390x_ops,
	},
3855 3856
};

3857
static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
3858
{
3859
	int i;
3860

3861 3862 3863
	for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
		if (mv88e6xxx_table[i].prod_num == prod_num)
			return &mv88e6xxx_table[i];
3864 3865 3866 3867

	return NULL;
}

3868
static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
3869 3870
{
	const struct mv88e6xxx_info *info;
3871 3872 3873
	unsigned int prod_num, rev;
	u16 id;
	int err;
3874

3875 3876 3877 3878 3879
	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id);
	mutex_unlock(&chip->reg_lock);
	if (err)
		return err;
3880 3881 3882 3883 3884 3885 3886 3887

	prod_num = (id & 0xfff0) >> 4;
	rev = id & 0x000f;

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

3888
	/* Update the compatible info with the probed one */
3889
	chip->info = info;
3890

3891 3892 3893 3894
	err = mv88e6xxx_g2_require(chip);
	if (err)
		return err;

3895 3896
	dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
		 chip->info->prod_num, chip->info->name, rev);
3897 3898 3899 3900

	return 0;
}

3901
static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
3902
{
3903
	struct mv88e6xxx_chip *chip;
3904

3905 3906
	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
3907 3908
		return NULL;

3909
	chip->dev = dev;
3910

3911
	mutex_init(&chip->reg_lock);
3912
	INIT_LIST_HEAD(&chip->mdios);
3913

3914
	return chip;
3915 3916
}

3917 3918
static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip)
{
3919
	if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
3920 3921 3922
		mv88e6xxx_ppu_state_init(chip);
}

3923 3924
static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip)
{
3925
	if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
3926 3927 3928
		mv88e6xxx_ppu_state_destroy(chip);
}

3929
static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
3930 3931
			      struct mii_bus *bus, int sw_addr)
{
3932
	if (sw_addr == 0)
3933
		chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
3934
	else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
3935
		chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
3936 3937 3938
	else
		return -EINVAL;

3939 3940
	chip->bus = bus;
	chip->sw_addr = sw_addr;
3941 3942 3943 3944

	return 0;
}

3945 3946
static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
{
V
Vivien Didelot 已提交
3947
	struct mv88e6xxx_chip *chip = ds->priv;
3948

3949
	return chip->info->tag_protocol;
3950 3951
}

3952 3953 3954
static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
				       struct device *host_dev, int sw_addr,
				       void **priv)
3955
{
3956
	struct mv88e6xxx_chip *chip;
3957
	struct mii_bus *bus;
3958
	int err;
3959

3960
	bus = dsa_host_dev_to_mii_bus(host_dev);
3961 3962 3963
	if (!bus)
		return NULL;

3964 3965
	chip = mv88e6xxx_alloc_chip(dsa_dev);
	if (!chip)
3966 3967
		return NULL;

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

3971
	err = mv88e6xxx_smi_init(chip, bus, sw_addr);
3972 3973 3974
	if (err)
		goto free;

3975
	err = mv88e6xxx_detect(chip);
3976
	if (err)
3977
		goto free;
3978

3979 3980 3981 3982 3983 3984
	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_switch_reset(chip);
	mutex_unlock(&chip->reg_lock);
	if (err)
		goto free;

3985 3986
	mv88e6xxx_phy_init(chip);

3987
	err = mv88e6xxx_mdios_register(chip, NULL);
3988
	if (err)
3989
		goto free;
3990

3991
	*priv = chip;
3992

3993
	return chip->info->name;
3994
free:
3995
	devm_kfree(dsa_dev, chip);
3996 3997

	return NULL;
3998 3999
}

4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
				      const struct switchdev_obj_port_mdb *mdb,
				      struct switchdev_trans *trans)
{
	/* We don't need any dynamic resource from the kernel (yet),
	 * so skip the prepare phase.
	 */

	return 0;
}

static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
				   const struct switchdev_obj_port_mdb *mdb,
				   struct switchdev_trans *trans)
{
V
Vivien Didelot 已提交
4015
	struct mv88e6xxx_chip *chip = ds->priv;
4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026

	mutex_lock(&chip->reg_lock);
	if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
					 GLOBAL_ATU_DATA_STATE_MC_STATIC))
		netdev_err(ds->ports[port].netdev, "failed to load multicast MAC address\n");
	mutex_unlock(&chip->reg_lock);
}

static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
				  const struct switchdev_obj_port_mdb *mdb)
{
V
Vivien Didelot 已提交
4027
	struct mv88e6xxx_chip *chip = ds->priv;
4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041
	int err;

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
					   GLOBAL_ATU_DATA_STATE_UNUSED);
	mutex_unlock(&chip->reg_lock);

	return err;
}

static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
				   struct switchdev_obj_port_mdb *mdb,
				   int (*cb)(struct switchdev_obj *obj))
{
V
Vivien Didelot 已提交
4042
	struct mv88e6xxx_chip *chip = ds->priv;
4043 4044 4045 4046 4047 4048 4049 4050 4051
	int err;

	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
	mutex_unlock(&chip->reg_lock);

	return err;
}

4052
static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
4053
	.probe			= mv88e6xxx_drv_probe,
4054
	.get_tag_protocol	= mv88e6xxx_get_tag_protocol,
4055 4056 4057 4058 4059 4060 4061 4062
	.setup			= mv88e6xxx_setup,
	.set_addr		= mv88e6xxx_set_addr,
	.adjust_link		= mv88e6xxx_adjust_link,
	.get_strings		= mv88e6xxx_get_strings,
	.get_ethtool_stats	= mv88e6xxx_get_ethtool_stats,
	.get_sset_count		= mv88e6xxx_get_sset_count,
	.set_eee		= mv88e6xxx_set_eee,
	.get_eee		= mv88e6xxx_get_eee,
4063
	.get_eeprom_len		= mv88e6xxx_get_eeprom_len,
4064 4065 4066 4067
	.get_eeprom		= mv88e6xxx_get_eeprom,
	.set_eeprom		= mv88e6xxx_set_eeprom,
	.get_regs_len		= mv88e6xxx_get_regs_len,
	.get_regs		= mv88e6xxx_get_regs,
4068
	.set_ageing_time	= mv88e6xxx_set_ageing_time,
4069 4070 4071
	.port_bridge_join	= mv88e6xxx_port_bridge_join,
	.port_bridge_leave	= mv88e6xxx_port_bridge_leave,
	.port_stp_state_set	= mv88e6xxx_port_stp_state_set,
4072
	.port_fast_age		= mv88e6xxx_port_fast_age,
4073 4074 4075 4076 4077 4078 4079 4080 4081
	.port_vlan_filtering	= mv88e6xxx_port_vlan_filtering,
	.port_vlan_prepare	= mv88e6xxx_port_vlan_prepare,
	.port_vlan_add		= mv88e6xxx_port_vlan_add,
	.port_vlan_del		= mv88e6xxx_port_vlan_del,
	.port_vlan_dump		= mv88e6xxx_port_vlan_dump,
	.port_fdb_prepare       = mv88e6xxx_port_fdb_prepare,
	.port_fdb_add           = mv88e6xxx_port_fdb_add,
	.port_fdb_del           = mv88e6xxx_port_fdb_del,
	.port_fdb_dump          = mv88e6xxx_port_fdb_dump,
4082 4083 4084 4085
	.port_mdb_prepare       = mv88e6xxx_port_mdb_prepare,
	.port_mdb_add           = mv88e6xxx_port_mdb_add,
	.port_mdb_del           = mv88e6xxx_port_mdb_del,
	.port_mdb_dump          = mv88e6xxx_port_mdb_dump,
4086 4087
	.crosschip_bridge_join	= mv88e6xxx_crosschip_bridge_join,
	.crosschip_bridge_leave	= mv88e6xxx_crosschip_bridge_leave,
4088 4089
};

4090 4091 4092 4093
static struct dsa_switch_driver mv88e6xxx_switch_drv = {
	.ops			= &mv88e6xxx_switch_ops,
};

4094
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
4095
{
4096
	struct device *dev = chip->dev;
4097 4098
	struct dsa_switch *ds;

4099
	ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
4100 4101 4102
	if (!ds)
		return -ENOMEM;

4103
	ds->priv = chip;
4104
	ds->ops = &mv88e6xxx_switch_ops;
4105 4106
	ds->ageing_time_min = chip->info->age_time_coeff;
	ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
4107 4108 4109

	dev_set_drvdata(dev, ds);

4110
	return dsa_register_switch(ds, dev);
4111 4112
}

4113
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
4114
{
4115
	dsa_unregister_switch(chip->ds);
4116 4117
}

4118
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
4119
{
4120
	struct device *dev = &mdiodev->dev;
4121
	struct device_node *np = dev->of_node;
4122
	const struct mv88e6xxx_info *compat_info;
4123
	struct mv88e6xxx_chip *chip;
4124
	u32 eeprom_len;
4125
	int err;
4126

4127 4128 4129 4130
	compat_info = of_device_get_match_data(dev);
	if (!compat_info)
		return -EINVAL;

4131 4132
	chip = mv88e6xxx_alloc_chip(dev);
	if (!chip)
4133 4134
		return -ENOMEM;

4135
	chip->info = compat_info;
4136

4137
	err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
4138 4139
	if (err)
		return err;
4140

4141 4142 4143 4144
	chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
	if (IS_ERR(chip->reset))
		return PTR_ERR(chip->reset);

4145
	err = mv88e6xxx_detect(chip);
4146 4147
	if (err)
		return err;
4148

4149 4150
	mv88e6xxx_phy_init(chip);

4151
	if (chip->info->ops->get_eeprom &&
4152
	    !of_property_read_u32(np, "eeprom-length", &eeprom_len))
4153
		chip->eeprom_len = eeprom_len;
4154

4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185
	mutex_lock(&chip->reg_lock);
	err = mv88e6xxx_switch_reset(chip);
	mutex_unlock(&chip->reg_lock);
	if (err)
		goto out;

	chip->irq = of_irq_get(np, 0);
	if (chip->irq == -EPROBE_DEFER) {
		err = chip->irq;
		goto out;
	}

	if (chip->irq > 0) {
		/* Has to be performed before the MDIO bus is created,
		 * because the PHYs will link there interrupts to these
		 * interrupt controllers
		 */
		mutex_lock(&chip->reg_lock);
		err = mv88e6xxx_g1_irq_setup(chip);
		mutex_unlock(&chip->reg_lock);

		if (err)
			goto out;

		if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
			err = mv88e6xxx_g2_irq_setup(chip);
			if (err)
				goto out_g1_irq;
		}
	}

4186
	err = mv88e6xxx_mdios_register(chip, np);
4187
	if (err)
4188
		goto out_g2_irq;
4189

4190
	err = mv88e6xxx_register_switch(chip);
4191 4192
	if (err)
		goto out_mdio;
4193

4194
	return 0;
4195 4196

out_mdio:
4197
	mv88e6xxx_mdios_unregister(chip);
4198
out_g2_irq:
4199
	if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
4200 4201
		mv88e6xxx_g2_irq_free(chip);
out_g1_irq:
4202 4203
	if (chip->irq > 0) {
		mutex_lock(&chip->reg_lock);
4204
		mv88e6xxx_g1_irq_free(chip);
4205 4206
		mutex_unlock(&chip->reg_lock);
	}
4207 4208
out:
	return err;
4209
}
4210 4211 4212 4213

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

4216
	mv88e6xxx_phy_destroy(chip);
4217
	mv88e6xxx_unregister_switch(chip);
4218
	mv88e6xxx_mdios_unregister(chip);
4219

4220 4221 4222 4223 4224
	if (chip->irq > 0) {
		if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
			mv88e6xxx_g2_irq_free(chip);
		mv88e6xxx_g1_irq_free(chip);
	}
4225 4226 4227
}

static const struct of_device_id mv88e6xxx_of_match[] = {
4228 4229 4230 4231
	{
		.compatible = "marvell,mv88e6085",
		.data = &mv88e6xxx_table[MV88E6085],
	},
4232 4233 4234 4235
	{
		.compatible = "marvell,mv88e6190",
		.data = &mv88e6xxx_table[MV88E6190],
	},
4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251
	{ /* sentinel */ },
};

MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);

static struct mdio_driver mv88e6xxx_driver = {
	.probe	= mv88e6xxx_probe,
	.remove = mv88e6xxx_remove,
	.mdiodrv.driver = {
		.name = "mv88e6085",
		.of_match_table = mv88e6xxx_of_match,
	},
};

static int __init mv88e6xxx_init(void)
{
4252
	register_switch_driver(&mv88e6xxx_switch_drv);
4253 4254
	return mdio_driver_register(&mv88e6xxx_driver);
}
4255 4256 4257 4258
module_init(mv88e6xxx_init);

static void __exit mv88e6xxx_cleanup(void)
{
4259
	mdio_driver_unregister(&mv88e6xxx_driver);
4260
	unregister_switch_driver(&mv88e6xxx_switch_drv);
4261 4262
}
module_exit(mv88e6xxx_cleanup);
4263 4264 4265 4266

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