1 // SPDX-License-Identifier: GPL-2.0-or-later 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> 8 * 9 * Copyright (c) 2016-2017 Savoir-faire Linux Inc. 10 * Vivien Didelot <vivien.didelot@savoirfairelinux.com> 11 */ 12 13 #include <linux/bitfield.h> 14 #include <linux/delay.h> 15 #include <linux/dsa/mv88e6xxx.h> 16 #include <linux/etherdevice.h> 17 #include <linux/ethtool.h> 18 #include <linux/if_bridge.h> 19 #include <linux/interrupt.h> 20 #include <linux/irq.h> 21 #include <linux/irqdomain.h> 22 #include <linux/jiffies.h> 23 #include <linux/list.h> 24 #include <linux/mdio.h> 25 #include <linux/module.h> 26 #include <linux/of.h> 27 #include <linux/of_irq.h> 28 #include <linux/of_mdio.h> 29 #include <linux/platform_data/mv88e6xxx.h> 30 #include <linux/netdevice.h> 31 #include <linux/gpio/consumer.h> 32 #include <linux/phylink.h> 33 #include <net/dsa.h> 34 35 #include "chip.h" 36 #include "devlink.h" 37 #include "global1.h" 38 #include "global2.h" 39 #include "hwtstamp.h" 40 #include "phy.h" 41 #include "port.h" 42 #include "ptp.h" 43 #include "serdes.h" 44 #include "smi.h" 45 46 static void assert_reg_lock(struct mv88e6xxx_chip *chip) 47 { 48 if (unlikely(!mutex_is_locked(&chip->reg_lock))) { 49 dev_err(chip->dev, "Switch registers lock not held!\n"); 50 dump_stack(); 51 } 52 } 53 54 int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val) 55 { 56 int err; 57 58 assert_reg_lock(chip); 59 60 err = mv88e6xxx_smi_read(chip, addr, reg, val); 61 if (err) 62 return err; 63 64 dev_dbg(chip->dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n", 65 addr, reg, *val); 66 67 return 0; 68 } 69 70 int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val) 71 { 72 int err; 73 74 assert_reg_lock(chip); 75 76 err = mv88e6xxx_smi_write(chip, addr, reg, val); 77 if (err) 78 return err; 79 80 dev_dbg(chip->dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n", 81 addr, reg, val); 82 83 return 0; 84 } 85 86 int mv88e6xxx_wait_mask(struct mv88e6xxx_chip *chip, int addr, int reg, 87 u16 mask, u16 val) 88 { 89 const unsigned long timeout = jiffies + msecs_to_jiffies(50); 90 u16 data; 91 int err; 92 int i; 93 94 /* There's no bus specific operation to wait for a mask. Even 95 * if the initial poll takes longer than 50ms, always do at 96 * least one more attempt. 97 */ 98 for (i = 0; time_before(jiffies, timeout) || (i < 2); i++) { 99 err = mv88e6xxx_read(chip, addr, reg, &data); 100 if (err) 101 return err; 102 103 if ((data & mask) == val) 104 return 0; 105 106 if (i < 2) 107 cpu_relax(); 108 else 109 usleep_range(1000, 2000); 110 } 111 112 err = mv88e6xxx_read(chip, addr, reg, &data); 113 if (err) 114 return err; 115 116 if ((data & mask) == val) 117 return 0; 118 119 dev_err(chip->dev, "Timeout while waiting for switch\n"); 120 return -ETIMEDOUT; 121 } 122 123 int mv88e6xxx_wait_bit(struct mv88e6xxx_chip *chip, int addr, int reg, 124 int bit, int val) 125 { 126 return mv88e6xxx_wait_mask(chip, addr, reg, BIT(bit), 127 val ? BIT(bit) : 0x0000); 128 } 129 130 struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip) 131 { 132 struct mv88e6xxx_mdio_bus *mdio_bus; 133 134 mdio_bus = list_first_entry(&chip->mdios, struct mv88e6xxx_mdio_bus, 135 list); 136 if (!mdio_bus) 137 return NULL; 138 139 return mdio_bus->bus; 140 } 141 142 static void mv88e6xxx_g1_irq_mask(struct irq_data *d) 143 { 144 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d); 145 unsigned int n = d->hwirq; 146 147 chip->g1_irq.masked |= (1 << n); 148 } 149 150 static void mv88e6xxx_g1_irq_unmask(struct irq_data *d) 151 { 152 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d); 153 unsigned int n = d->hwirq; 154 155 chip->g1_irq.masked &= ~(1 << n); 156 } 157 158 static irqreturn_t mv88e6xxx_g1_irq_thread_work(struct mv88e6xxx_chip *chip) 159 { 160 unsigned int nhandled = 0; 161 unsigned int sub_irq; 162 unsigned int n; 163 u16 reg; 164 u16 ctl1; 165 int err; 166 167 mv88e6xxx_reg_lock(chip); 168 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, ®); 169 mv88e6xxx_reg_unlock(chip); 170 171 if (err) 172 goto out; 173 174 do { 175 for (n = 0; n < chip->g1_irq.nirqs; ++n) { 176 if (reg & (1 << n)) { 177 sub_irq = irq_find_mapping(chip->g1_irq.domain, 178 n); 179 handle_nested_irq(sub_irq); 180 ++nhandled; 181 } 182 } 183 184 mv88e6xxx_reg_lock(chip); 185 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &ctl1); 186 if (err) 187 goto unlock; 188 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, ®); 189 unlock: 190 mv88e6xxx_reg_unlock(chip); 191 if (err) 192 goto out; 193 ctl1 &= GENMASK(chip->g1_irq.nirqs, 0); 194 } while (reg & ctl1); 195 196 out: 197 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE); 198 } 199 200 static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id) 201 { 202 struct mv88e6xxx_chip *chip = dev_id; 203 204 return mv88e6xxx_g1_irq_thread_work(chip); 205 } 206 207 static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d) 208 { 209 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d); 210 211 mv88e6xxx_reg_lock(chip); 212 } 213 214 static void mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data *d) 215 { 216 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d); 217 u16 mask = GENMASK(chip->g1_irq.nirqs, 0); 218 u16 reg; 219 int err; 220 221 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, ®); 222 if (err) 223 goto out; 224 225 reg &= ~mask; 226 reg |= (~chip->g1_irq.masked & mask); 227 228 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, reg); 229 if (err) 230 goto out; 231 232 out: 233 mv88e6xxx_reg_unlock(chip); 234 } 235 236 static const struct irq_chip mv88e6xxx_g1_irq_chip = { 237 .name = "mv88e6xxx-g1", 238 .irq_mask = mv88e6xxx_g1_irq_mask, 239 .irq_unmask = mv88e6xxx_g1_irq_unmask, 240 .irq_bus_lock = mv88e6xxx_g1_irq_bus_lock, 241 .irq_bus_sync_unlock = mv88e6xxx_g1_irq_bus_sync_unlock, 242 }; 243 244 static int mv88e6xxx_g1_irq_domain_map(struct irq_domain *d, 245 unsigned int irq, 246 irq_hw_number_t hwirq) 247 { 248 struct mv88e6xxx_chip *chip = d->host_data; 249 250 irq_set_chip_data(irq, d->host_data); 251 irq_set_chip_and_handler(irq, &chip->g1_irq.chip, handle_level_irq); 252 irq_set_noprobe(irq); 253 254 return 0; 255 } 256 257 static const struct irq_domain_ops mv88e6xxx_g1_irq_domain_ops = { 258 .map = mv88e6xxx_g1_irq_domain_map, 259 .xlate = irq_domain_xlate_twocell, 260 }; 261 262 /* To be called with reg_lock held */ 263 static void mv88e6xxx_g1_irq_free_common(struct mv88e6xxx_chip *chip) 264 { 265 int irq, virq; 266 u16 mask; 267 268 mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask); 269 mask &= ~GENMASK(chip->g1_irq.nirqs, 0); 270 mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask); 271 272 for (irq = 0; irq < chip->g1_irq.nirqs; irq++) { 273 virq = irq_find_mapping(chip->g1_irq.domain, irq); 274 irq_dispose_mapping(virq); 275 } 276 277 irq_domain_remove(chip->g1_irq.domain); 278 } 279 280 static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip) 281 { 282 /* 283 * free_irq must be called without reg_lock taken because the irq 284 * handler takes this lock, too. 285 */ 286 free_irq(chip->irq, chip); 287 288 mv88e6xxx_reg_lock(chip); 289 mv88e6xxx_g1_irq_free_common(chip); 290 mv88e6xxx_reg_unlock(chip); 291 } 292 293 static int mv88e6xxx_g1_irq_setup_common(struct mv88e6xxx_chip *chip) 294 { 295 int err, irq, virq; 296 u16 reg, mask; 297 298 chip->g1_irq.nirqs = chip->info->g1_irqs; 299 chip->g1_irq.domain = irq_domain_add_simple( 300 NULL, chip->g1_irq.nirqs, 0, 301 &mv88e6xxx_g1_irq_domain_ops, chip); 302 if (!chip->g1_irq.domain) 303 return -ENOMEM; 304 305 for (irq = 0; irq < chip->g1_irq.nirqs; irq++) 306 irq_create_mapping(chip->g1_irq.domain, irq); 307 308 chip->g1_irq.chip = mv88e6xxx_g1_irq_chip; 309 chip->g1_irq.masked = ~0; 310 311 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask); 312 if (err) 313 goto out_mapping; 314 315 mask &= ~GENMASK(chip->g1_irq.nirqs, 0); 316 317 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask); 318 if (err) 319 goto out_disable; 320 321 /* Reading the interrupt status clears (most of) them */ 322 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, ®); 323 if (err) 324 goto out_disable; 325 326 return 0; 327 328 out_disable: 329 mask &= ~GENMASK(chip->g1_irq.nirqs, 0); 330 mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask); 331 332 out_mapping: 333 for (irq = 0; irq < 16; irq++) { 334 virq = irq_find_mapping(chip->g1_irq.domain, irq); 335 irq_dispose_mapping(virq); 336 } 337 338 irq_domain_remove(chip->g1_irq.domain); 339 340 return err; 341 } 342 343 static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip) 344 { 345 static struct lock_class_key lock_key; 346 static struct lock_class_key request_key; 347 int err; 348 349 err = mv88e6xxx_g1_irq_setup_common(chip); 350 if (err) 351 return err; 352 353 /* These lock classes tells lockdep that global 1 irqs are in 354 * a different category than their parent GPIO, so it won't 355 * report false recursion. 356 */ 357 irq_set_lockdep_class(chip->irq, &lock_key, &request_key); 358 359 snprintf(chip->irq_name, sizeof(chip->irq_name), 360 "mv88e6xxx-%s", dev_name(chip->dev)); 361 362 mv88e6xxx_reg_unlock(chip); 363 err = request_threaded_irq(chip->irq, NULL, 364 mv88e6xxx_g1_irq_thread_fn, 365 IRQF_ONESHOT | IRQF_SHARED, 366 chip->irq_name, chip); 367 mv88e6xxx_reg_lock(chip); 368 if (err) 369 mv88e6xxx_g1_irq_free_common(chip); 370 371 return err; 372 } 373 374 static void mv88e6xxx_irq_poll(struct kthread_work *work) 375 { 376 struct mv88e6xxx_chip *chip = container_of(work, 377 struct mv88e6xxx_chip, 378 irq_poll_work.work); 379 mv88e6xxx_g1_irq_thread_work(chip); 380 381 kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work, 382 msecs_to_jiffies(100)); 383 } 384 385 static int mv88e6xxx_irq_poll_setup(struct mv88e6xxx_chip *chip) 386 { 387 int err; 388 389 err = mv88e6xxx_g1_irq_setup_common(chip); 390 if (err) 391 return err; 392 393 kthread_init_delayed_work(&chip->irq_poll_work, 394 mv88e6xxx_irq_poll); 395 396 chip->kworker = kthread_create_worker(0, "%s", dev_name(chip->dev)); 397 if (IS_ERR(chip->kworker)) 398 return PTR_ERR(chip->kworker); 399 400 kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work, 401 msecs_to_jiffies(100)); 402 403 return 0; 404 } 405 406 static void mv88e6xxx_irq_poll_free(struct mv88e6xxx_chip *chip) 407 { 408 kthread_cancel_delayed_work_sync(&chip->irq_poll_work); 409 kthread_destroy_worker(chip->kworker); 410 411 mv88e6xxx_reg_lock(chip); 412 mv88e6xxx_g1_irq_free_common(chip); 413 mv88e6xxx_reg_unlock(chip); 414 } 415 416 static int mv88e6xxx_port_config_interface(struct mv88e6xxx_chip *chip, 417 int port, phy_interface_t interface) 418 { 419 int err; 420 421 if (chip->info->ops->port_set_rgmii_delay) { 422 err = chip->info->ops->port_set_rgmii_delay(chip, port, 423 interface); 424 if (err && err != -EOPNOTSUPP) 425 return err; 426 } 427 428 if (chip->info->ops->port_set_cmode) { 429 err = chip->info->ops->port_set_cmode(chip, port, 430 interface); 431 if (err && err != -EOPNOTSUPP) 432 return err; 433 } 434 435 return 0; 436 } 437 438 static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port, 439 int link, int speed, int duplex, int pause, 440 phy_interface_t mode) 441 { 442 int err; 443 444 if (!chip->info->ops->port_set_link) 445 return 0; 446 447 /* Port's MAC control must not be changed unless the link is down */ 448 err = chip->info->ops->port_set_link(chip, port, LINK_FORCED_DOWN); 449 if (err) 450 return err; 451 452 if (chip->info->ops->port_set_speed_duplex) { 453 err = chip->info->ops->port_set_speed_duplex(chip, port, 454 speed, duplex); 455 if (err && err != -EOPNOTSUPP) 456 goto restore_link; 457 } 458 459 if (chip->info->ops->port_set_pause) { 460 err = chip->info->ops->port_set_pause(chip, port, pause); 461 if (err) 462 goto restore_link; 463 } 464 465 err = mv88e6xxx_port_config_interface(chip, port, mode); 466 restore_link: 467 if (chip->info->ops->port_set_link(chip, port, link)) 468 dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port); 469 470 return err; 471 } 472 473 static int mv88e6xxx_phy_is_internal(struct mv88e6xxx_chip *chip, int port) 474 { 475 return port >= chip->info->internal_phys_offset && 476 port < chip->info->num_internal_phys + 477 chip->info->internal_phys_offset; 478 } 479 480 static int mv88e6xxx_port_ppu_updates(struct mv88e6xxx_chip *chip, int port) 481 { 482 u16 reg; 483 int err; 484 485 /* The 88e6250 family does not have the PHY detect bit. Instead, 486 * report whether the port is internal. 487 */ 488 if (chip->info->family == MV88E6XXX_FAMILY_6250) 489 return mv88e6xxx_phy_is_internal(chip, port); 490 491 err = mv88e6xxx_port_read(chip, port, MV88E6XXX_PORT_STS, ®); 492 if (err) { 493 dev_err(chip->dev, 494 "p%d: %s: failed to read port status\n", 495 port, __func__); 496 return err; 497 } 498 499 return !!(reg & MV88E6XXX_PORT_STS_PHY_DETECT); 500 } 501 502 static const u8 mv88e6185_phy_interface_modes[] = { 503 [MV88E6185_PORT_STS_CMODE_GMII_FD] = PHY_INTERFACE_MODE_GMII, 504 [MV88E6185_PORT_STS_CMODE_MII_100_FD_PS] = PHY_INTERFACE_MODE_MII, 505 [MV88E6185_PORT_STS_CMODE_MII_100] = PHY_INTERFACE_MODE_MII, 506 [MV88E6185_PORT_STS_CMODE_MII_10] = PHY_INTERFACE_MODE_MII, 507 [MV88E6185_PORT_STS_CMODE_SERDES] = PHY_INTERFACE_MODE_1000BASEX, 508 [MV88E6185_PORT_STS_CMODE_1000BASE_X] = PHY_INTERFACE_MODE_1000BASEX, 509 [MV88E6185_PORT_STS_CMODE_PHY] = PHY_INTERFACE_MODE_SGMII, 510 }; 511 512 static void mv88e6095_phylink_get_caps(struct mv88e6xxx_chip *chip, int port, 513 struct phylink_config *config) 514 { 515 u8 cmode = chip->ports[port].cmode; 516 517 config->mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100; 518 519 if (mv88e6xxx_phy_is_internal(chip, port)) { 520 __set_bit(PHY_INTERFACE_MODE_MII, config->supported_interfaces); 521 } else { 522 if (cmode < ARRAY_SIZE(mv88e6185_phy_interface_modes) && 523 mv88e6185_phy_interface_modes[cmode]) 524 __set_bit(mv88e6185_phy_interface_modes[cmode], 525 config->supported_interfaces); 526 527 config->mac_capabilities |= MAC_1000FD; 528 } 529 } 530 531 static void mv88e6185_phylink_get_caps(struct mv88e6xxx_chip *chip, int port, 532 struct phylink_config *config) 533 { 534 u8 cmode = chip->ports[port].cmode; 535 536 if (cmode < ARRAY_SIZE(mv88e6185_phy_interface_modes) && 537 mv88e6185_phy_interface_modes[cmode]) 538 __set_bit(mv88e6185_phy_interface_modes[cmode], 539 config->supported_interfaces); 540 541 config->mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100 | 542 MAC_1000FD; 543 } 544 545 static const u8 mv88e6xxx_phy_interface_modes[] = { 546 [MV88E6XXX_PORT_STS_CMODE_MII_PHY] = PHY_INTERFACE_MODE_REVMII, 547 [MV88E6XXX_PORT_STS_CMODE_MII] = PHY_INTERFACE_MODE_MII, 548 [MV88E6XXX_PORT_STS_CMODE_GMII] = PHY_INTERFACE_MODE_GMII, 549 [MV88E6XXX_PORT_STS_CMODE_RMII_PHY] = PHY_INTERFACE_MODE_REVRMII, 550 [MV88E6XXX_PORT_STS_CMODE_RMII] = PHY_INTERFACE_MODE_RMII, 551 [MV88E6XXX_PORT_STS_CMODE_100BASEX] = PHY_INTERFACE_MODE_100BASEX, 552 [MV88E6XXX_PORT_STS_CMODE_1000BASEX] = PHY_INTERFACE_MODE_1000BASEX, 553 [MV88E6XXX_PORT_STS_CMODE_SGMII] = PHY_INTERFACE_MODE_SGMII, 554 /* higher interface modes are not needed here, since ports supporting 555 * them are writable, and so the supported interfaces are filled in the 556 * corresponding .phylink_set_interfaces() implementation below 557 */ 558 }; 559 560 static void mv88e6xxx_translate_cmode(u8 cmode, unsigned long *supported) 561 { 562 if (cmode < ARRAY_SIZE(mv88e6xxx_phy_interface_modes) && 563 mv88e6xxx_phy_interface_modes[cmode]) 564 __set_bit(mv88e6xxx_phy_interface_modes[cmode], supported); 565 else if (cmode == MV88E6XXX_PORT_STS_CMODE_RGMII) 566 phy_interface_set_rgmii(supported); 567 } 568 569 static void mv88e6250_phylink_get_caps(struct mv88e6xxx_chip *chip, int port, 570 struct phylink_config *config) 571 { 572 unsigned long *supported = config->supported_interfaces; 573 574 /* Translate the default cmode */ 575 mv88e6xxx_translate_cmode(chip->ports[port].cmode, supported); 576 577 config->mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100; 578 } 579 580 static int mv88e6352_get_port4_serdes_cmode(struct mv88e6xxx_chip *chip) 581 { 582 u16 reg, val; 583 int err; 584 585 err = mv88e6xxx_port_read(chip, 4, MV88E6XXX_PORT_STS, ®); 586 if (err) 587 return err; 588 589 /* If PHY_DETECT is zero, then we are not in auto-media mode */ 590 if (!(reg & MV88E6XXX_PORT_STS_PHY_DETECT)) 591 return 0xf; 592 593 val = reg & ~MV88E6XXX_PORT_STS_PHY_DETECT; 594 err = mv88e6xxx_port_write(chip, 4, MV88E6XXX_PORT_STS, val); 595 if (err) 596 return err; 597 598 err = mv88e6xxx_port_read(chip, 4, MV88E6XXX_PORT_STS, &val); 599 if (err) 600 return err; 601 602 /* Restore PHY_DETECT value */ 603 err = mv88e6xxx_port_write(chip, 4, MV88E6XXX_PORT_STS, reg); 604 if (err) 605 return err; 606 607 return val & MV88E6XXX_PORT_STS_CMODE_MASK; 608 } 609 610 static void mv88e6352_phylink_get_caps(struct mv88e6xxx_chip *chip, int port, 611 struct phylink_config *config) 612 { 613 unsigned long *supported = config->supported_interfaces; 614 int err, cmode; 615 616 /* Translate the default cmode */ 617 mv88e6xxx_translate_cmode(chip->ports[port].cmode, supported); 618 619 config->mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100 | 620 MAC_1000FD; 621 622 /* Port 4 supports automedia if the serdes is associated with it. */ 623 if (port == 4) { 624 err = mv88e6352_g2_scratch_port_has_serdes(chip, port); 625 if (err < 0) 626 dev_err(chip->dev, "p%d: failed to read scratch\n", 627 port); 628 if (err <= 0) 629 return; 630 631 cmode = mv88e6352_get_port4_serdes_cmode(chip); 632 if (cmode < 0) 633 dev_err(chip->dev, "p%d: failed to read serdes cmode\n", 634 port); 635 else 636 mv88e6xxx_translate_cmode(cmode, supported); 637 } 638 } 639 640 static void mv88e6341_phylink_get_caps(struct mv88e6xxx_chip *chip, int port, 641 struct phylink_config *config) 642 { 643 unsigned long *supported = config->supported_interfaces; 644 645 /* Translate the default cmode */ 646 mv88e6xxx_translate_cmode(chip->ports[port].cmode, supported); 647 648 /* No ethtool bits for 200Mbps */ 649 config->mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100 | 650 MAC_1000FD; 651 652 /* The C_Mode field is programmable on port 5 */ 653 if (port == 5) { 654 __set_bit(PHY_INTERFACE_MODE_SGMII, supported); 655 __set_bit(PHY_INTERFACE_MODE_1000BASEX, supported); 656 __set_bit(PHY_INTERFACE_MODE_2500BASEX, supported); 657 658 config->mac_capabilities |= MAC_2500FD; 659 } 660 } 661 662 static void mv88e6390_phylink_get_caps(struct mv88e6xxx_chip *chip, int port, 663 struct phylink_config *config) 664 { 665 unsigned long *supported = config->supported_interfaces; 666 667 /* Translate the default cmode */ 668 mv88e6xxx_translate_cmode(chip->ports[port].cmode, supported); 669 670 /* No ethtool bits for 200Mbps */ 671 config->mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100 | 672 MAC_1000FD; 673 674 /* The C_Mode field is programmable on ports 9 and 10 */ 675 if (port == 9 || port == 10) { 676 __set_bit(PHY_INTERFACE_MODE_SGMII, supported); 677 __set_bit(PHY_INTERFACE_MODE_1000BASEX, supported); 678 __set_bit(PHY_INTERFACE_MODE_2500BASEX, supported); 679 680 config->mac_capabilities |= MAC_2500FD; 681 } 682 } 683 684 static void mv88e6390x_phylink_get_caps(struct mv88e6xxx_chip *chip, int port, 685 struct phylink_config *config) 686 { 687 unsigned long *supported = config->supported_interfaces; 688 689 mv88e6390_phylink_get_caps(chip, port, config); 690 691 /* For the 6x90X, ports 2-7 can be in automedia mode. 692 * (Note that 6x90 doesn't support RXAUI nor XAUI). 693 * 694 * Port 2 can also support 1000BASE-X in automedia mode if port 9 is 695 * configured for 1000BASE-X, SGMII or 2500BASE-X. 696 * Port 3-4 can also support 1000BASE-X in automedia mode if port 9 is 697 * configured for RXAUI, 1000BASE-X, SGMII or 2500BASE-X. 698 * 699 * Port 5 can also support 1000BASE-X in automedia mode if port 10 is 700 * configured for 1000BASE-X, SGMII or 2500BASE-X. 701 * Port 6-7 can also support 1000BASE-X in automedia mode if port 10 is 702 * configured for RXAUI, 1000BASE-X, SGMII or 2500BASE-X. 703 * 704 * For now, be permissive (as the old code was) and allow 1000BASE-X 705 * on ports 2..7. 706 */ 707 if (port >= 2 && port <= 7) 708 __set_bit(PHY_INTERFACE_MODE_1000BASEX, supported); 709 710 /* The C_Mode field can also be programmed for 10G speeds */ 711 if (port == 9 || port == 10) { 712 __set_bit(PHY_INTERFACE_MODE_XAUI, supported); 713 __set_bit(PHY_INTERFACE_MODE_RXAUI, supported); 714 715 config->mac_capabilities |= MAC_10000FD; 716 } 717 } 718 719 static void mv88e6393x_phylink_get_caps(struct mv88e6xxx_chip *chip, int port, 720 struct phylink_config *config) 721 { 722 unsigned long *supported = config->supported_interfaces; 723 bool is_6191x = 724 chip->info->prod_num == MV88E6XXX_PORT_SWITCH_ID_PROD_6191X; 725 bool is_6361 = 726 chip->info->prod_num == MV88E6XXX_PORT_SWITCH_ID_PROD_6361; 727 728 mv88e6xxx_translate_cmode(chip->ports[port].cmode, supported); 729 730 config->mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100 | 731 MAC_1000FD; 732 733 /* The C_Mode field can be programmed for ports 0, 9 and 10 */ 734 if (port == 0 || port == 9 || port == 10) { 735 __set_bit(PHY_INTERFACE_MODE_SGMII, supported); 736 __set_bit(PHY_INTERFACE_MODE_1000BASEX, supported); 737 738 /* 6191X supports >1G modes only on port 10 */ 739 if (!is_6191x || port == 10) { 740 __set_bit(PHY_INTERFACE_MODE_2500BASEX, supported); 741 config->mac_capabilities |= MAC_2500FD; 742 743 /* 6361 only supports up to 2500BaseX */ 744 if (!is_6361) { 745 __set_bit(PHY_INTERFACE_MODE_5GBASER, supported); 746 __set_bit(PHY_INTERFACE_MODE_10GBASER, supported); 747 __set_bit(PHY_INTERFACE_MODE_USXGMII, supported); 748 config->mac_capabilities |= MAC_5000FD | 749 MAC_10000FD; 750 } 751 } 752 } 753 754 if (port == 0) { 755 __set_bit(PHY_INTERFACE_MODE_RMII, supported); 756 __set_bit(PHY_INTERFACE_MODE_RGMII, supported); 757 __set_bit(PHY_INTERFACE_MODE_RGMII_ID, supported); 758 __set_bit(PHY_INTERFACE_MODE_RGMII_RXID, supported); 759 __set_bit(PHY_INTERFACE_MODE_RGMII_TXID, supported); 760 } 761 } 762 763 static void mv88e6xxx_get_caps(struct dsa_switch *ds, int port, 764 struct phylink_config *config) 765 { 766 struct mv88e6xxx_chip *chip = ds->priv; 767 768 mv88e6xxx_reg_lock(chip); 769 chip->info->ops->phylink_get_caps(chip, port, config); 770 mv88e6xxx_reg_unlock(chip); 771 772 if (mv88e6xxx_phy_is_internal(chip, port)) { 773 __set_bit(PHY_INTERFACE_MODE_INTERNAL, 774 config->supported_interfaces); 775 /* Internal ports with no phy-mode need GMII for PHYLIB */ 776 __set_bit(PHY_INTERFACE_MODE_GMII, 777 config->supported_interfaces); 778 } 779 } 780 781 static struct phylink_pcs *mv88e6xxx_mac_select_pcs(struct dsa_switch *ds, 782 int port, 783 phy_interface_t interface) 784 { 785 struct mv88e6xxx_chip *chip = ds->priv; 786 struct phylink_pcs *pcs = ERR_PTR(-EOPNOTSUPP); 787 788 if (chip->info->ops->pcs_ops) 789 pcs = chip->info->ops->pcs_ops->pcs_select(chip, port, 790 interface); 791 792 return pcs; 793 } 794 795 static int mv88e6xxx_mac_prepare(struct dsa_switch *ds, int port, 796 unsigned int mode, phy_interface_t interface) 797 { 798 struct mv88e6xxx_chip *chip = ds->priv; 799 int err = 0; 800 801 /* In inband mode, the link may come up at any time while the link 802 * is not forced down. Force the link down while we reconfigure the 803 * interface mode. 804 */ 805 if (mode == MLO_AN_INBAND && 806 chip->ports[port].interface != interface && 807 chip->info->ops->port_set_link) { 808 mv88e6xxx_reg_lock(chip); 809 err = chip->info->ops->port_set_link(chip, port, 810 LINK_FORCED_DOWN); 811 mv88e6xxx_reg_unlock(chip); 812 } 813 814 return err; 815 } 816 817 static void mv88e6xxx_mac_config(struct dsa_switch *ds, int port, 818 unsigned int mode, 819 const struct phylink_link_state *state) 820 { 821 struct mv88e6xxx_chip *chip = ds->priv; 822 int err = 0; 823 824 mv88e6xxx_reg_lock(chip); 825 826 if (mode != MLO_AN_PHY || !mv88e6xxx_phy_is_internal(chip, port)) { 827 err = mv88e6xxx_port_config_interface(chip, port, 828 state->interface); 829 if (err && err != -EOPNOTSUPP) 830 goto err_unlock; 831 } 832 833 err_unlock: 834 mv88e6xxx_reg_unlock(chip); 835 836 if (err && err != -EOPNOTSUPP) 837 dev_err(ds->dev, "p%d: failed to configure MAC/PCS\n", port); 838 } 839 840 static int mv88e6xxx_mac_finish(struct dsa_switch *ds, int port, 841 unsigned int mode, phy_interface_t interface) 842 { 843 struct mv88e6xxx_chip *chip = ds->priv; 844 int err = 0; 845 846 /* Undo the forced down state above after completing configuration 847 * irrespective of its state on entry, which allows the link to come 848 * up in the in-band case where there is no separate SERDES. Also 849 * ensure that the link can come up if the PPU is in use and we are 850 * in PHY mode (we treat the PPU as an effective in-band mechanism.) 851 */ 852 mv88e6xxx_reg_lock(chip); 853 854 if (chip->info->ops->port_set_link && 855 ((mode == MLO_AN_INBAND && 856 chip->ports[port].interface != interface) || 857 (mode == MLO_AN_PHY && mv88e6xxx_port_ppu_updates(chip, port)))) 858 err = chip->info->ops->port_set_link(chip, port, LINK_UNFORCED); 859 860 mv88e6xxx_reg_unlock(chip); 861 862 chip->ports[port].interface = interface; 863 864 return err; 865 } 866 867 static void mv88e6xxx_mac_link_down(struct dsa_switch *ds, int port, 868 unsigned int mode, 869 phy_interface_t interface) 870 { 871 struct mv88e6xxx_chip *chip = ds->priv; 872 const struct mv88e6xxx_ops *ops; 873 int err = 0; 874 875 ops = chip->info->ops; 876 877 mv88e6xxx_reg_lock(chip); 878 /* Force the link down if we know the port may not be automatically 879 * updated by the switch or if we are using fixed-link mode. 880 */ 881 if ((!mv88e6xxx_port_ppu_updates(chip, port) || 882 mode == MLO_AN_FIXED) && ops->port_sync_link) 883 err = ops->port_sync_link(chip, port, mode, false); 884 885 if (!err && ops->port_set_speed_duplex) 886 err = ops->port_set_speed_duplex(chip, port, SPEED_UNFORCED, 887 DUPLEX_UNFORCED); 888 mv88e6xxx_reg_unlock(chip); 889 890 if (err) 891 dev_err(chip->dev, 892 "p%d: failed to force MAC link down\n", port); 893 } 894 895 static void mv88e6xxx_mac_link_up(struct dsa_switch *ds, int port, 896 unsigned int mode, phy_interface_t interface, 897 struct phy_device *phydev, 898 int speed, int duplex, 899 bool tx_pause, bool rx_pause) 900 { 901 struct mv88e6xxx_chip *chip = ds->priv; 902 const struct mv88e6xxx_ops *ops; 903 int err = 0; 904 905 ops = chip->info->ops; 906 907 mv88e6xxx_reg_lock(chip); 908 /* Configure and force the link up if we know that the port may not 909 * automatically updated by the switch or if we are using fixed-link 910 * mode. 911 */ 912 if (!mv88e6xxx_port_ppu_updates(chip, port) || 913 mode == MLO_AN_FIXED) { 914 if (ops->port_set_speed_duplex) { 915 err = ops->port_set_speed_duplex(chip, port, 916 speed, duplex); 917 if (err && err != -EOPNOTSUPP) 918 goto error; 919 } 920 921 if (ops->port_sync_link) 922 err = ops->port_sync_link(chip, port, mode, true); 923 } 924 error: 925 mv88e6xxx_reg_unlock(chip); 926 927 if (err && err != -EOPNOTSUPP) 928 dev_err(ds->dev, 929 "p%d: failed to configure MAC link up\n", port); 930 } 931 932 static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port) 933 { 934 if (!chip->info->ops->stats_snapshot) 935 return -EOPNOTSUPP; 936 937 return chip->info->ops->stats_snapshot(chip, port); 938 } 939 940 static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = { 941 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, }, 942 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, }, 943 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, }, 944 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, }, 945 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, }, 946 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, }, 947 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, }, 948 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, }, 949 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, }, 950 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, }, 951 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, }, 952 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, }, 953 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, }, 954 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, }, 955 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, }, 956 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, }, 957 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, }, 958 { "excessive", 4, 0x11, STATS_TYPE_BANK0, }, 959 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, }, 960 { "deferred", 4, 0x05, STATS_TYPE_BANK0, }, 961 { "single", 4, 0x14, STATS_TYPE_BANK0, }, 962 { "multiple", 4, 0x17, STATS_TYPE_BANK0, }, 963 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, }, 964 { "late", 4, 0x1f, STATS_TYPE_BANK0, }, 965 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, }, 966 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, }, 967 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, }, 968 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, }, 969 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, }, 970 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, }, 971 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, }, 972 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, }, 973 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, }, 974 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, }, 975 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, }, 976 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, }, 977 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, }, 978 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, }, 979 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, }, 980 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, }, 981 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, }, 982 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, }, 983 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, }, 984 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, }, 985 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, }, 986 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, }, 987 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, }, 988 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, }, 989 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, }, 990 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, }, 991 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, }, 992 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, }, 993 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, }, 994 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, }, 995 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, }, 996 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, }, 997 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, }, 998 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, }, 999 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, }, 1000 }; 1001 1002 static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip, 1003 struct mv88e6xxx_hw_stat *s, 1004 int port, u16 bank1_select, 1005 u16 histogram) 1006 { 1007 u32 low; 1008 u32 high = 0; 1009 u16 reg = 0; 1010 int err; 1011 u64 value; 1012 1013 switch (s->type) { 1014 case STATS_TYPE_PORT: 1015 err = mv88e6xxx_port_read(chip, port, s->reg, ®); 1016 if (err) 1017 return U64_MAX; 1018 1019 low = reg; 1020 if (s->size == 4) { 1021 err = mv88e6xxx_port_read(chip, port, s->reg + 1, ®); 1022 if (err) 1023 return U64_MAX; 1024 low |= ((u32)reg) << 16; 1025 } 1026 break; 1027 case STATS_TYPE_BANK1: 1028 reg = bank1_select; 1029 fallthrough; 1030 case STATS_TYPE_BANK0: 1031 reg |= s->reg | histogram; 1032 mv88e6xxx_g1_stats_read(chip, reg, &low); 1033 if (s->size == 8) 1034 mv88e6xxx_g1_stats_read(chip, reg + 1, &high); 1035 break; 1036 default: 1037 return U64_MAX; 1038 } 1039 value = (((u64)high) << 32) | low; 1040 return value; 1041 } 1042 1043 static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip, 1044 uint8_t *data, int types) 1045 { 1046 struct mv88e6xxx_hw_stat *stat; 1047 int i, j; 1048 1049 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) { 1050 stat = &mv88e6xxx_hw_stats[i]; 1051 if (stat->type & types) { 1052 memcpy(data + j * ETH_GSTRING_LEN, stat->string, 1053 ETH_GSTRING_LEN); 1054 j++; 1055 } 1056 } 1057 1058 return j; 1059 } 1060 1061 static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip, 1062 uint8_t *data) 1063 { 1064 return mv88e6xxx_stats_get_strings(chip, data, 1065 STATS_TYPE_BANK0 | STATS_TYPE_PORT); 1066 } 1067 1068 static int mv88e6250_stats_get_strings(struct mv88e6xxx_chip *chip, 1069 uint8_t *data) 1070 { 1071 return mv88e6xxx_stats_get_strings(chip, data, STATS_TYPE_BANK0); 1072 } 1073 1074 static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip, 1075 uint8_t *data) 1076 { 1077 return mv88e6xxx_stats_get_strings(chip, data, 1078 STATS_TYPE_BANK0 | STATS_TYPE_BANK1); 1079 } 1080 1081 static const uint8_t *mv88e6xxx_atu_vtu_stats_strings[] = { 1082 "atu_member_violation", 1083 "atu_miss_violation", 1084 "atu_full_violation", 1085 "vtu_member_violation", 1086 "vtu_miss_violation", 1087 }; 1088 1089 static void mv88e6xxx_atu_vtu_get_strings(uint8_t *data) 1090 { 1091 unsigned int i; 1092 1093 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings); i++) 1094 strscpy(data + i * ETH_GSTRING_LEN, 1095 mv88e6xxx_atu_vtu_stats_strings[i], 1096 ETH_GSTRING_LEN); 1097 } 1098 1099 static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port, 1100 u32 stringset, uint8_t *data) 1101 { 1102 struct mv88e6xxx_chip *chip = ds->priv; 1103 int count = 0; 1104 1105 if (stringset != ETH_SS_STATS) 1106 return; 1107 1108 mv88e6xxx_reg_lock(chip); 1109 1110 if (chip->info->ops->stats_get_strings) 1111 count = chip->info->ops->stats_get_strings(chip, data); 1112 1113 if (chip->info->ops->serdes_get_strings) { 1114 data += count * ETH_GSTRING_LEN; 1115 count = chip->info->ops->serdes_get_strings(chip, port, data); 1116 } 1117 1118 data += count * ETH_GSTRING_LEN; 1119 mv88e6xxx_atu_vtu_get_strings(data); 1120 1121 mv88e6xxx_reg_unlock(chip); 1122 } 1123 1124 static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip, 1125 int types) 1126 { 1127 struct mv88e6xxx_hw_stat *stat; 1128 int i, j; 1129 1130 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) { 1131 stat = &mv88e6xxx_hw_stats[i]; 1132 if (stat->type & types) 1133 j++; 1134 } 1135 return j; 1136 } 1137 1138 static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip) 1139 { 1140 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 | 1141 STATS_TYPE_PORT); 1142 } 1143 1144 static int mv88e6250_stats_get_sset_count(struct mv88e6xxx_chip *chip) 1145 { 1146 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0); 1147 } 1148 1149 static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip) 1150 { 1151 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 | 1152 STATS_TYPE_BANK1); 1153 } 1154 1155 static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset) 1156 { 1157 struct mv88e6xxx_chip *chip = ds->priv; 1158 int serdes_count = 0; 1159 int count = 0; 1160 1161 if (sset != ETH_SS_STATS) 1162 return 0; 1163 1164 mv88e6xxx_reg_lock(chip); 1165 if (chip->info->ops->stats_get_sset_count) 1166 count = chip->info->ops->stats_get_sset_count(chip); 1167 if (count < 0) 1168 goto out; 1169 1170 if (chip->info->ops->serdes_get_sset_count) 1171 serdes_count = chip->info->ops->serdes_get_sset_count(chip, 1172 port); 1173 if (serdes_count < 0) { 1174 count = serdes_count; 1175 goto out; 1176 } 1177 count += serdes_count; 1178 count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings); 1179 1180 out: 1181 mv88e6xxx_reg_unlock(chip); 1182 1183 return count; 1184 } 1185 1186 static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port, 1187 uint64_t *data, int types, 1188 u16 bank1_select, u16 histogram) 1189 { 1190 struct mv88e6xxx_hw_stat *stat; 1191 int i, j; 1192 1193 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) { 1194 stat = &mv88e6xxx_hw_stats[i]; 1195 if (stat->type & types) { 1196 mv88e6xxx_reg_lock(chip); 1197 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port, 1198 bank1_select, 1199 histogram); 1200 mv88e6xxx_reg_unlock(chip); 1201 1202 j++; 1203 } 1204 } 1205 return j; 1206 } 1207 1208 static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port, 1209 uint64_t *data) 1210 { 1211 return mv88e6xxx_stats_get_stats(chip, port, data, 1212 STATS_TYPE_BANK0 | STATS_TYPE_PORT, 1213 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX); 1214 } 1215 1216 static int mv88e6250_stats_get_stats(struct mv88e6xxx_chip *chip, int port, 1217 uint64_t *data) 1218 { 1219 return mv88e6xxx_stats_get_stats(chip, port, data, STATS_TYPE_BANK0, 1220 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX); 1221 } 1222 1223 static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port, 1224 uint64_t *data) 1225 { 1226 return mv88e6xxx_stats_get_stats(chip, port, data, 1227 STATS_TYPE_BANK0 | STATS_TYPE_BANK1, 1228 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9, 1229 MV88E6XXX_G1_STATS_OP_HIST_RX_TX); 1230 } 1231 1232 static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port, 1233 uint64_t *data) 1234 { 1235 return mv88e6xxx_stats_get_stats(chip, port, data, 1236 STATS_TYPE_BANK0 | STATS_TYPE_BANK1, 1237 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10, 1238 0); 1239 } 1240 1241 static void mv88e6xxx_atu_vtu_get_stats(struct mv88e6xxx_chip *chip, int port, 1242 uint64_t *data) 1243 { 1244 *data++ = chip->ports[port].atu_member_violation; 1245 *data++ = chip->ports[port].atu_miss_violation; 1246 *data++ = chip->ports[port].atu_full_violation; 1247 *data++ = chip->ports[port].vtu_member_violation; 1248 *data++ = chip->ports[port].vtu_miss_violation; 1249 } 1250 1251 static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port, 1252 uint64_t *data) 1253 { 1254 int count = 0; 1255 1256 if (chip->info->ops->stats_get_stats) 1257 count = chip->info->ops->stats_get_stats(chip, port, data); 1258 1259 mv88e6xxx_reg_lock(chip); 1260 if (chip->info->ops->serdes_get_stats) { 1261 data += count; 1262 count = chip->info->ops->serdes_get_stats(chip, port, data); 1263 } 1264 data += count; 1265 mv88e6xxx_atu_vtu_get_stats(chip, port, data); 1266 mv88e6xxx_reg_unlock(chip); 1267 } 1268 1269 static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port, 1270 uint64_t *data) 1271 { 1272 struct mv88e6xxx_chip *chip = ds->priv; 1273 int ret; 1274 1275 mv88e6xxx_reg_lock(chip); 1276 1277 ret = mv88e6xxx_stats_snapshot(chip, port); 1278 mv88e6xxx_reg_unlock(chip); 1279 1280 if (ret < 0) 1281 return; 1282 1283 mv88e6xxx_get_stats(chip, port, data); 1284 1285 } 1286 1287 static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port) 1288 { 1289 struct mv88e6xxx_chip *chip = ds->priv; 1290 int len; 1291 1292 len = 32 * sizeof(u16); 1293 if (chip->info->ops->serdes_get_regs_len) 1294 len += chip->info->ops->serdes_get_regs_len(chip, port); 1295 1296 return len; 1297 } 1298 1299 static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port, 1300 struct ethtool_regs *regs, void *_p) 1301 { 1302 struct mv88e6xxx_chip *chip = ds->priv; 1303 int err; 1304 u16 reg; 1305 u16 *p = _p; 1306 int i; 1307 1308 regs->version = chip->info->prod_num; 1309 1310 memset(p, 0xff, 32 * sizeof(u16)); 1311 1312 mv88e6xxx_reg_lock(chip); 1313 1314 for (i = 0; i < 32; i++) { 1315 1316 err = mv88e6xxx_port_read(chip, port, i, ®); 1317 if (!err) 1318 p[i] = reg; 1319 } 1320 1321 if (chip->info->ops->serdes_get_regs) 1322 chip->info->ops->serdes_get_regs(chip, port, &p[i]); 1323 1324 mv88e6xxx_reg_unlock(chip); 1325 } 1326 1327 static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port, 1328 struct ethtool_eee *e) 1329 { 1330 /* Nothing to do on the port's MAC */ 1331 return 0; 1332 } 1333 1334 static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port, 1335 struct ethtool_eee *e) 1336 { 1337 /* Nothing to do on the port's MAC */ 1338 return 0; 1339 } 1340 1341 /* Mask of the local ports allowed to receive frames from a given fabric port */ 1342 static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port) 1343 { 1344 struct dsa_switch *ds = chip->ds; 1345 struct dsa_switch_tree *dst = ds->dst; 1346 struct dsa_port *dp, *other_dp; 1347 bool found = false; 1348 u16 pvlan; 1349 1350 /* dev is a physical switch */ 1351 if (dev <= dst->last_switch) { 1352 list_for_each_entry(dp, &dst->ports, list) { 1353 if (dp->ds->index == dev && dp->index == port) { 1354 /* dp might be a DSA link or a user port, so it 1355 * might or might not have a bridge. 1356 * Use the "found" variable for both cases. 1357 */ 1358 found = true; 1359 break; 1360 } 1361 } 1362 /* dev is a virtual bridge */ 1363 } else { 1364 list_for_each_entry(dp, &dst->ports, list) { 1365 unsigned int bridge_num = dsa_port_bridge_num_get(dp); 1366 1367 if (!bridge_num) 1368 continue; 1369 1370 if (bridge_num + dst->last_switch != dev) 1371 continue; 1372 1373 found = true; 1374 break; 1375 } 1376 } 1377 1378 /* Prevent frames from unknown switch or virtual bridge */ 1379 if (!found) 1380 return 0; 1381 1382 /* Frames from DSA links and CPU ports can egress any local port */ 1383 if (dp->type == DSA_PORT_TYPE_CPU || dp->type == DSA_PORT_TYPE_DSA) 1384 return mv88e6xxx_port_mask(chip); 1385 1386 pvlan = 0; 1387 1388 /* Frames from standalone user ports can only egress on the 1389 * upstream port. 1390 */ 1391 if (!dsa_port_bridge_dev_get(dp)) 1392 return BIT(dsa_switch_upstream_port(ds)); 1393 1394 /* Frames from bridged user ports can egress any local DSA 1395 * links and CPU ports, as well as any local member of their 1396 * bridge group. 1397 */ 1398 dsa_switch_for_each_port(other_dp, ds) 1399 if (other_dp->type == DSA_PORT_TYPE_CPU || 1400 other_dp->type == DSA_PORT_TYPE_DSA || 1401 dsa_port_bridge_same(dp, other_dp)) 1402 pvlan |= BIT(other_dp->index); 1403 1404 return pvlan; 1405 } 1406 1407 static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port) 1408 { 1409 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port); 1410 1411 /* prevent frames from going back out of the port they came in on */ 1412 output_ports &= ~BIT(port); 1413 1414 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports); 1415 } 1416 1417 static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port, 1418 u8 state) 1419 { 1420 struct mv88e6xxx_chip *chip = ds->priv; 1421 int err; 1422 1423 mv88e6xxx_reg_lock(chip); 1424 err = mv88e6xxx_port_set_state(chip, port, state); 1425 mv88e6xxx_reg_unlock(chip); 1426 1427 if (err) 1428 dev_err(ds->dev, "p%d: failed to update state\n", port); 1429 } 1430 1431 static int mv88e6xxx_pri_setup(struct mv88e6xxx_chip *chip) 1432 { 1433 int err; 1434 1435 if (chip->info->ops->ieee_pri_map) { 1436 err = chip->info->ops->ieee_pri_map(chip); 1437 if (err) 1438 return err; 1439 } 1440 1441 if (chip->info->ops->ip_pri_map) { 1442 err = chip->info->ops->ip_pri_map(chip); 1443 if (err) 1444 return err; 1445 } 1446 1447 return 0; 1448 } 1449 1450 static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip) 1451 { 1452 struct dsa_switch *ds = chip->ds; 1453 int target, port; 1454 int err; 1455 1456 if (!chip->info->global2_addr) 1457 return 0; 1458 1459 /* Initialize the routing port to the 32 possible target devices */ 1460 for (target = 0; target < 32; target++) { 1461 port = dsa_routing_port(ds, target); 1462 if (port == ds->num_ports) 1463 port = 0x1f; 1464 1465 err = mv88e6xxx_g2_device_mapping_write(chip, target, port); 1466 if (err) 1467 return err; 1468 } 1469 1470 if (chip->info->ops->set_cascade_port) { 1471 port = MV88E6XXX_CASCADE_PORT_MULTIPLE; 1472 err = chip->info->ops->set_cascade_port(chip, port); 1473 if (err) 1474 return err; 1475 } 1476 1477 err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index); 1478 if (err) 1479 return err; 1480 1481 return 0; 1482 } 1483 1484 static int mv88e6xxx_trunk_setup(struct mv88e6xxx_chip *chip) 1485 { 1486 /* Clear all trunk masks and mapping */ 1487 if (chip->info->global2_addr) 1488 return mv88e6xxx_g2_trunk_clear(chip); 1489 1490 return 0; 1491 } 1492 1493 static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip) 1494 { 1495 if (chip->info->ops->rmu_disable) 1496 return chip->info->ops->rmu_disable(chip); 1497 1498 return 0; 1499 } 1500 1501 static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip) 1502 { 1503 if (chip->info->ops->pot_clear) 1504 return chip->info->ops->pot_clear(chip); 1505 1506 return 0; 1507 } 1508 1509 static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip) 1510 { 1511 if (chip->info->ops->mgmt_rsvd2cpu) 1512 return chip->info->ops->mgmt_rsvd2cpu(chip); 1513 1514 return 0; 1515 } 1516 1517 static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip) 1518 { 1519 int err; 1520 1521 err = mv88e6xxx_g1_atu_flush(chip, 0, true); 1522 if (err) 1523 return err; 1524 1525 /* The chips that have a "learn2all" bit in Global1, ATU 1526 * Control are precisely those whose port registers have a 1527 * Message Port bit in Port Control 1 and hence implement 1528 * ->port_setup_message_port. 1529 */ 1530 if (chip->info->ops->port_setup_message_port) { 1531 err = mv88e6xxx_g1_atu_set_learn2all(chip, true); 1532 if (err) 1533 return err; 1534 } 1535 1536 return mv88e6xxx_g1_atu_set_age_time(chip, 300000); 1537 } 1538 1539 static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip) 1540 { 1541 int port; 1542 int err; 1543 1544 if (!chip->info->ops->irl_init_all) 1545 return 0; 1546 1547 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) { 1548 /* Disable ingress rate limiting by resetting all per port 1549 * ingress rate limit resources to their initial state. 1550 */ 1551 err = chip->info->ops->irl_init_all(chip, port); 1552 if (err) 1553 return err; 1554 } 1555 1556 return 0; 1557 } 1558 1559 static int mv88e6xxx_mac_setup(struct mv88e6xxx_chip *chip) 1560 { 1561 if (chip->info->ops->set_switch_mac) { 1562 u8 addr[ETH_ALEN]; 1563 1564 eth_random_addr(addr); 1565 1566 return chip->info->ops->set_switch_mac(chip, addr); 1567 } 1568 1569 return 0; 1570 } 1571 1572 static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port) 1573 { 1574 struct dsa_switch_tree *dst = chip->ds->dst; 1575 struct dsa_switch *ds; 1576 struct dsa_port *dp; 1577 u16 pvlan = 0; 1578 1579 if (!mv88e6xxx_has_pvt(chip)) 1580 return 0; 1581 1582 /* Skip the local source device, which uses in-chip port VLAN */ 1583 if (dev != chip->ds->index) { 1584 pvlan = mv88e6xxx_port_vlan(chip, dev, port); 1585 1586 ds = dsa_switch_find(dst->index, dev); 1587 dp = ds ? dsa_to_port(ds, port) : NULL; 1588 if (dp && dp->lag) { 1589 /* As the PVT is used to limit flooding of 1590 * FORWARD frames, which use the LAG ID as the 1591 * source port, we must translate dev/port to 1592 * the special "LAG device" in the PVT, using 1593 * the LAG ID (one-based) as the port number 1594 * (zero-based). 1595 */ 1596 dev = MV88E6XXX_G2_PVT_ADDR_DEV_TRUNK; 1597 port = dsa_port_lag_id_get(dp) - 1; 1598 } 1599 } 1600 1601 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan); 1602 } 1603 1604 static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip) 1605 { 1606 int dev, port; 1607 int err; 1608 1609 if (!mv88e6xxx_has_pvt(chip)) 1610 return 0; 1611 1612 /* Clear 5 Bit Port for usage with Marvell Link Street devices: 1613 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev. 1614 */ 1615 err = mv88e6xxx_g2_misc_4_bit_port(chip); 1616 if (err) 1617 return err; 1618 1619 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) { 1620 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) { 1621 err = mv88e6xxx_pvt_map(chip, dev, port); 1622 if (err) 1623 return err; 1624 } 1625 } 1626 1627 return 0; 1628 } 1629 1630 static int mv88e6xxx_port_fast_age_fid(struct mv88e6xxx_chip *chip, int port, 1631 u16 fid) 1632 { 1633 if (dsa_to_port(chip->ds, port)->lag) 1634 /* Hardware is incapable of fast-aging a LAG through a 1635 * regular ATU move operation. Until we have something 1636 * more fancy in place this is a no-op. 1637 */ 1638 return -EOPNOTSUPP; 1639 1640 return mv88e6xxx_g1_atu_remove(chip, fid, port, false); 1641 } 1642 1643 static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port) 1644 { 1645 struct mv88e6xxx_chip *chip = ds->priv; 1646 int err; 1647 1648 mv88e6xxx_reg_lock(chip); 1649 err = mv88e6xxx_port_fast_age_fid(chip, port, 0); 1650 mv88e6xxx_reg_unlock(chip); 1651 1652 if (err) 1653 dev_err(chip->ds->dev, "p%d: failed to flush ATU: %d\n", 1654 port, err); 1655 } 1656 1657 static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip) 1658 { 1659 if (!mv88e6xxx_max_vid(chip)) 1660 return 0; 1661 1662 return mv88e6xxx_g1_vtu_flush(chip); 1663 } 1664 1665 static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid, 1666 struct mv88e6xxx_vtu_entry *entry) 1667 { 1668 int err; 1669 1670 if (!chip->info->ops->vtu_getnext) 1671 return -EOPNOTSUPP; 1672 1673 entry->vid = vid ? vid - 1 : mv88e6xxx_max_vid(chip); 1674 entry->valid = false; 1675 1676 err = chip->info->ops->vtu_getnext(chip, entry); 1677 1678 if (entry->vid != vid) 1679 entry->valid = false; 1680 1681 return err; 1682 } 1683 1684 int mv88e6xxx_vtu_walk(struct mv88e6xxx_chip *chip, 1685 int (*cb)(struct mv88e6xxx_chip *chip, 1686 const struct mv88e6xxx_vtu_entry *entry, 1687 void *priv), 1688 void *priv) 1689 { 1690 struct mv88e6xxx_vtu_entry entry = { 1691 .vid = mv88e6xxx_max_vid(chip), 1692 .valid = false, 1693 }; 1694 int err; 1695 1696 if (!chip->info->ops->vtu_getnext) 1697 return -EOPNOTSUPP; 1698 1699 do { 1700 err = chip->info->ops->vtu_getnext(chip, &entry); 1701 if (err) 1702 return err; 1703 1704 if (!entry.valid) 1705 break; 1706 1707 err = cb(chip, &entry, priv); 1708 if (err) 1709 return err; 1710 } while (entry.vid < mv88e6xxx_max_vid(chip)); 1711 1712 return 0; 1713 } 1714 1715 static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip, 1716 struct mv88e6xxx_vtu_entry *entry) 1717 { 1718 if (!chip->info->ops->vtu_loadpurge) 1719 return -EOPNOTSUPP; 1720 1721 return chip->info->ops->vtu_loadpurge(chip, entry); 1722 } 1723 1724 static int mv88e6xxx_fid_map_vlan(struct mv88e6xxx_chip *chip, 1725 const struct mv88e6xxx_vtu_entry *entry, 1726 void *_fid_bitmap) 1727 { 1728 unsigned long *fid_bitmap = _fid_bitmap; 1729 1730 set_bit(entry->fid, fid_bitmap); 1731 return 0; 1732 } 1733 1734 int mv88e6xxx_fid_map(struct mv88e6xxx_chip *chip, unsigned long *fid_bitmap) 1735 { 1736 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID); 1737 1738 /* Every FID has an associated VID, so walking the VTU 1739 * will discover the full set of FIDs in use. 1740 */ 1741 return mv88e6xxx_vtu_walk(chip, mv88e6xxx_fid_map_vlan, fid_bitmap); 1742 } 1743 1744 static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid) 1745 { 1746 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID); 1747 int err; 1748 1749 err = mv88e6xxx_fid_map(chip, fid_bitmap); 1750 if (err) 1751 return err; 1752 1753 *fid = find_first_zero_bit(fid_bitmap, MV88E6XXX_N_FID); 1754 if (unlikely(*fid >= mv88e6xxx_num_databases(chip))) 1755 return -ENOSPC; 1756 1757 /* Clear the database */ 1758 return mv88e6xxx_g1_atu_flush(chip, *fid, true); 1759 } 1760 1761 static int mv88e6xxx_stu_loadpurge(struct mv88e6xxx_chip *chip, 1762 struct mv88e6xxx_stu_entry *entry) 1763 { 1764 if (!chip->info->ops->stu_loadpurge) 1765 return -EOPNOTSUPP; 1766 1767 return chip->info->ops->stu_loadpurge(chip, entry); 1768 } 1769 1770 static int mv88e6xxx_stu_setup(struct mv88e6xxx_chip *chip) 1771 { 1772 struct mv88e6xxx_stu_entry stu = { 1773 .valid = true, 1774 .sid = 0 1775 }; 1776 1777 if (!mv88e6xxx_has_stu(chip)) 1778 return 0; 1779 1780 /* Make sure that SID 0 is always valid. This is used by VTU 1781 * entries that do not make use of the STU, e.g. when creating 1782 * a VLAN upper on a port that is also part of a VLAN 1783 * filtering bridge. 1784 */ 1785 return mv88e6xxx_stu_loadpurge(chip, &stu); 1786 } 1787 1788 static int mv88e6xxx_sid_get(struct mv88e6xxx_chip *chip, u8 *sid) 1789 { 1790 DECLARE_BITMAP(busy, MV88E6XXX_N_SID) = { 0 }; 1791 struct mv88e6xxx_mst *mst; 1792 1793 __set_bit(0, busy); 1794 1795 list_for_each_entry(mst, &chip->msts, node) 1796 __set_bit(mst->stu.sid, busy); 1797 1798 *sid = find_first_zero_bit(busy, MV88E6XXX_N_SID); 1799 1800 return (*sid >= mv88e6xxx_max_sid(chip)) ? -ENOSPC : 0; 1801 } 1802 1803 static int mv88e6xxx_mst_put(struct mv88e6xxx_chip *chip, u8 sid) 1804 { 1805 struct mv88e6xxx_mst *mst, *tmp; 1806 int err; 1807 1808 if (!sid) 1809 return 0; 1810 1811 list_for_each_entry_safe(mst, tmp, &chip->msts, node) { 1812 if (mst->stu.sid != sid) 1813 continue; 1814 1815 if (!refcount_dec_and_test(&mst->refcnt)) 1816 return 0; 1817 1818 mst->stu.valid = false; 1819 err = mv88e6xxx_stu_loadpurge(chip, &mst->stu); 1820 if (err) { 1821 refcount_set(&mst->refcnt, 1); 1822 return err; 1823 } 1824 1825 list_del(&mst->node); 1826 kfree(mst); 1827 return 0; 1828 } 1829 1830 return -ENOENT; 1831 } 1832 1833 static int mv88e6xxx_mst_get(struct mv88e6xxx_chip *chip, struct net_device *br, 1834 u16 msti, u8 *sid) 1835 { 1836 struct mv88e6xxx_mst *mst; 1837 int err, i; 1838 1839 if (!mv88e6xxx_has_stu(chip)) { 1840 err = -EOPNOTSUPP; 1841 goto err; 1842 } 1843 1844 if (!msti) { 1845 *sid = 0; 1846 return 0; 1847 } 1848 1849 list_for_each_entry(mst, &chip->msts, node) { 1850 if (mst->br == br && mst->msti == msti) { 1851 refcount_inc(&mst->refcnt); 1852 *sid = mst->stu.sid; 1853 return 0; 1854 } 1855 } 1856 1857 err = mv88e6xxx_sid_get(chip, sid); 1858 if (err) 1859 goto err; 1860 1861 mst = kzalloc(sizeof(*mst), GFP_KERNEL); 1862 if (!mst) { 1863 err = -ENOMEM; 1864 goto err; 1865 } 1866 1867 INIT_LIST_HEAD(&mst->node); 1868 refcount_set(&mst->refcnt, 1); 1869 mst->br = br; 1870 mst->msti = msti; 1871 mst->stu.valid = true; 1872 mst->stu.sid = *sid; 1873 1874 /* The bridge starts out all ports in the disabled state. But 1875 * a STU state of disabled means to go by the port-global 1876 * state. So we set all user port's initial state to blocking, 1877 * to match the bridge's behavior. 1878 */ 1879 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) 1880 mst->stu.state[i] = dsa_is_user_port(chip->ds, i) ? 1881 MV88E6XXX_PORT_CTL0_STATE_BLOCKING : 1882 MV88E6XXX_PORT_CTL0_STATE_DISABLED; 1883 1884 err = mv88e6xxx_stu_loadpurge(chip, &mst->stu); 1885 if (err) 1886 goto err_free; 1887 1888 list_add_tail(&mst->node, &chip->msts); 1889 return 0; 1890 1891 err_free: 1892 kfree(mst); 1893 err: 1894 return err; 1895 } 1896 1897 static int mv88e6xxx_port_mst_state_set(struct dsa_switch *ds, int port, 1898 const struct switchdev_mst_state *st) 1899 { 1900 struct dsa_port *dp = dsa_to_port(ds, port); 1901 struct mv88e6xxx_chip *chip = ds->priv; 1902 struct mv88e6xxx_mst *mst; 1903 u8 state; 1904 int err; 1905 1906 if (!mv88e6xxx_has_stu(chip)) 1907 return -EOPNOTSUPP; 1908 1909 switch (st->state) { 1910 case BR_STATE_DISABLED: 1911 case BR_STATE_BLOCKING: 1912 case BR_STATE_LISTENING: 1913 state = MV88E6XXX_PORT_CTL0_STATE_BLOCKING; 1914 break; 1915 case BR_STATE_LEARNING: 1916 state = MV88E6XXX_PORT_CTL0_STATE_LEARNING; 1917 break; 1918 case BR_STATE_FORWARDING: 1919 state = MV88E6XXX_PORT_CTL0_STATE_FORWARDING; 1920 break; 1921 default: 1922 return -EINVAL; 1923 } 1924 1925 list_for_each_entry(mst, &chip->msts, node) { 1926 if (mst->br == dsa_port_bridge_dev_get(dp) && 1927 mst->msti == st->msti) { 1928 if (mst->stu.state[port] == state) 1929 return 0; 1930 1931 mst->stu.state[port] = state; 1932 mv88e6xxx_reg_lock(chip); 1933 err = mv88e6xxx_stu_loadpurge(chip, &mst->stu); 1934 mv88e6xxx_reg_unlock(chip); 1935 return err; 1936 } 1937 } 1938 1939 return -ENOENT; 1940 } 1941 1942 static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port, 1943 u16 vid) 1944 { 1945 struct dsa_port *dp = dsa_to_port(ds, port), *other_dp; 1946 struct mv88e6xxx_chip *chip = ds->priv; 1947 struct mv88e6xxx_vtu_entry vlan; 1948 int err; 1949 1950 /* DSA and CPU ports have to be members of multiple vlans */ 1951 if (dsa_port_is_dsa(dp) || dsa_port_is_cpu(dp)) 1952 return 0; 1953 1954 err = mv88e6xxx_vtu_get(chip, vid, &vlan); 1955 if (err) 1956 return err; 1957 1958 if (!vlan.valid) 1959 return 0; 1960 1961 dsa_switch_for_each_user_port(other_dp, ds) { 1962 struct net_device *other_br; 1963 1964 if (vlan.member[other_dp->index] == 1965 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) 1966 continue; 1967 1968 if (dsa_port_bridge_same(dp, other_dp)) 1969 break; /* same bridge, check next VLAN */ 1970 1971 other_br = dsa_port_bridge_dev_get(other_dp); 1972 if (!other_br) 1973 continue; 1974 1975 dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n", 1976 port, vlan.vid, other_dp->index, netdev_name(other_br)); 1977 return -EOPNOTSUPP; 1978 } 1979 1980 return 0; 1981 } 1982 1983 static int mv88e6xxx_port_commit_pvid(struct mv88e6xxx_chip *chip, int port) 1984 { 1985 struct dsa_port *dp = dsa_to_port(chip->ds, port); 1986 struct net_device *br = dsa_port_bridge_dev_get(dp); 1987 struct mv88e6xxx_port *p = &chip->ports[port]; 1988 u16 pvid = MV88E6XXX_VID_STANDALONE; 1989 bool drop_untagged = false; 1990 int err; 1991 1992 if (br) { 1993 if (br_vlan_enabled(br)) { 1994 pvid = p->bridge_pvid.vid; 1995 drop_untagged = !p->bridge_pvid.valid; 1996 } else { 1997 pvid = MV88E6XXX_VID_BRIDGED; 1998 } 1999 } 2000 2001 err = mv88e6xxx_port_set_pvid(chip, port, pvid); 2002 if (err) 2003 return err; 2004 2005 return mv88e6xxx_port_drop_untagged(chip, port, drop_untagged); 2006 } 2007 2008 static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port, 2009 bool vlan_filtering, 2010 struct netlink_ext_ack *extack) 2011 { 2012 struct mv88e6xxx_chip *chip = ds->priv; 2013 u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE : 2014 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED; 2015 int err; 2016 2017 if (!mv88e6xxx_max_vid(chip)) 2018 return -EOPNOTSUPP; 2019 2020 mv88e6xxx_reg_lock(chip); 2021 2022 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode); 2023 if (err) 2024 goto unlock; 2025 2026 err = mv88e6xxx_port_commit_pvid(chip, port); 2027 if (err) 2028 goto unlock; 2029 2030 unlock: 2031 mv88e6xxx_reg_unlock(chip); 2032 2033 return err; 2034 } 2035 2036 static int 2037 mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port, 2038 const struct switchdev_obj_port_vlan *vlan) 2039 { 2040 struct mv88e6xxx_chip *chip = ds->priv; 2041 int err; 2042 2043 if (!mv88e6xxx_max_vid(chip)) 2044 return -EOPNOTSUPP; 2045 2046 /* If the requested port doesn't belong to the same bridge as the VLAN 2047 * members, do not support it (yet) and fallback to software VLAN. 2048 */ 2049 mv88e6xxx_reg_lock(chip); 2050 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid); 2051 mv88e6xxx_reg_unlock(chip); 2052 2053 return err; 2054 } 2055 2056 static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port, 2057 const unsigned char *addr, u16 vid, 2058 u8 state) 2059 { 2060 struct mv88e6xxx_atu_entry entry; 2061 struct mv88e6xxx_vtu_entry vlan; 2062 u16 fid; 2063 int err; 2064 2065 /* Ports have two private address databases: one for when the port is 2066 * standalone and one for when the port is under a bridge and the 2067 * 802.1Q mode is disabled. When the port is standalone, DSA wants its 2068 * address database to remain 100% empty, so we never load an ATU entry 2069 * into a standalone port's database. Therefore, translate the null 2070 * VLAN ID into the port's database used for VLAN-unaware bridging. 2071 */ 2072 if (vid == 0) { 2073 fid = MV88E6XXX_FID_BRIDGED; 2074 } else { 2075 err = mv88e6xxx_vtu_get(chip, vid, &vlan); 2076 if (err) 2077 return err; 2078 2079 /* switchdev expects -EOPNOTSUPP to honor software VLANs */ 2080 if (!vlan.valid) 2081 return -EOPNOTSUPP; 2082 2083 fid = vlan.fid; 2084 } 2085 2086 entry.state = 0; 2087 ether_addr_copy(entry.mac, addr); 2088 eth_addr_dec(entry.mac); 2089 2090 err = mv88e6xxx_g1_atu_getnext(chip, fid, &entry); 2091 if (err) 2092 return err; 2093 2094 /* Initialize a fresh ATU entry if it isn't found */ 2095 if (!entry.state || !ether_addr_equal(entry.mac, addr)) { 2096 memset(&entry, 0, sizeof(entry)); 2097 ether_addr_copy(entry.mac, addr); 2098 } 2099 2100 /* Purge the ATU entry only if no port is using it anymore */ 2101 if (!state) { 2102 entry.portvec &= ~BIT(port); 2103 if (!entry.portvec) 2104 entry.state = 0; 2105 } else { 2106 if (state == MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC) 2107 entry.portvec = BIT(port); 2108 else 2109 entry.portvec |= BIT(port); 2110 2111 entry.state = state; 2112 } 2113 2114 return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry); 2115 } 2116 2117 static int mv88e6xxx_policy_apply(struct mv88e6xxx_chip *chip, int port, 2118 const struct mv88e6xxx_policy *policy) 2119 { 2120 enum mv88e6xxx_policy_mapping mapping = policy->mapping; 2121 enum mv88e6xxx_policy_action action = policy->action; 2122 const u8 *addr = policy->addr; 2123 u16 vid = policy->vid; 2124 u8 state; 2125 int err; 2126 int id; 2127 2128 if (!chip->info->ops->port_set_policy) 2129 return -EOPNOTSUPP; 2130 2131 switch (mapping) { 2132 case MV88E6XXX_POLICY_MAPPING_DA: 2133 case MV88E6XXX_POLICY_MAPPING_SA: 2134 if (action == MV88E6XXX_POLICY_ACTION_NORMAL) 2135 state = 0; /* Dissociate the port and address */ 2136 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD && 2137 is_multicast_ether_addr(addr)) 2138 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC_POLICY; 2139 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD && 2140 is_unicast_ether_addr(addr)) 2141 state = MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC_POLICY; 2142 else 2143 return -EOPNOTSUPP; 2144 2145 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid, 2146 state); 2147 if (err) 2148 return err; 2149 break; 2150 default: 2151 return -EOPNOTSUPP; 2152 } 2153 2154 /* Skip the port's policy clearing if the mapping is still in use */ 2155 if (action == MV88E6XXX_POLICY_ACTION_NORMAL) 2156 idr_for_each_entry(&chip->policies, policy, id) 2157 if (policy->port == port && 2158 policy->mapping == mapping && 2159 policy->action != action) 2160 return 0; 2161 2162 return chip->info->ops->port_set_policy(chip, port, mapping, action); 2163 } 2164 2165 static int mv88e6xxx_policy_insert(struct mv88e6xxx_chip *chip, int port, 2166 struct ethtool_rx_flow_spec *fs) 2167 { 2168 struct ethhdr *mac_entry = &fs->h_u.ether_spec; 2169 struct ethhdr *mac_mask = &fs->m_u.ether_spec; 2170 enum mv88e6xxx_policy_mapping mapping; 2171 enum mv88e6xxx_policy_action action; 2172 struct mv88e6xxx_policy *policy; 2173 u16 vid = 0; 2174 u8 *addr; 2175 int err; 2176 int id; 2177 2178 if (fs->location != RX_CLS_LOC_ANY) 2179 return -EINVAL; 2180 2181 if (fs->ring_cookie == RX_CLS_FLOW_DISC) 2182 action = MV88E6XXX_POLICY_ACTION_DISCARD; 2183 else 2184 return -EOPNOTSUPP; 2185 2186 switch (fs->flow_type & ~FLOW_EXT) { 2187 case ETHER_FLOW: 2188 if (!is_zero_ether_addr(mac_mask->h_dest) && 2189 is_zero_ether_addr(mac_mask->h_source)) { 2190 mapping = MV88E6XXX_POLICY_MAPPING_DA; 2191 addr = mac_entry->h_dest; 2192 } else if (is_zero_ether_addr(mac_mask->h_dest) && 2193 !is_zero_ether_addr(mac_mask->h_source)) { 2194 mapping = MV88E6XXX_POLICY_MAPPING_SA; 2195 addr = mac_entry->h_source; 2196 } else { 2197 /* Cannot support DA and SA mapping in the same rule */ 2198 return -EOPNOTSUPP; 2199 } 2200 break; 2201 default: 2202 return -EOPNOTSUPP; 2203 } 2204 2205 if ((fs->flow_type & FLOW_EXT) && fs->m_ext.vlan_tci) { 2206 if (fs->m_ext.vlan_tci != htons(0xffff)) 2207 return -EOPNOTSUPP; 2208 vid = be16_to_cpu(fs->h_ext.vlan_tci) & VLAN_VID_MASK; 2209 } 2210 2211 idr_for_each_entry(&chip->policies, policy, id) { 2212 if (policy->port == port && policy->mapping == mapping && 2213 policy->action == action && policy->vid == vid && 2214 ether_addr_equal(policy->addr, addr)) 2215 return -EEXIST; 2216 } 2217 2218 policy = devm_kzalloc(chip->dev, sizeof(*policy), GFP_KERNEL); 2219 if (!policy) 2220 return -ENOMEM; 2221 2222 fs->location = 0; 2223 err = idr_alloc_u32(&chip->policies, policy, &fs->location, 0xffffffff, 2224 GFP_KERNEL); 2225 if (err) { 2226 devm_kfree(chip->dev, policy); 2227 return err; 2228 } 2229 2230 memcpy(&policy->fs, fs, sizeof(*fs)); 2231 ether_addr_copy(policy->addr, addr); 2232 policy->mapping = mapping; 2233 policy->action = action; 2234 policy->port = port; 2235 policy->vid = vid; 2236 2237 err = mv88e6xxx_policy_apply(chip, port, policy); 2238 if (err) { 2239 idr_remove(&chip->policies, fs->location); 2240 devm_kfree(chip->dev, policy); 2241 return err; 2242 } 2243 2244 return 0; 2245 } 2246 2247 static int mv88e6xxx_get_rxnfc(struct dsa_switch *ds, int port, 2248 struct ethtool_rxnfc *rxnfc, u32 *rule_locs) 2249 { 2250 struct ethtool_rx_flow_spec *fs = &rxnfc->fs; 2251 struct mv88e6xxx_chip *chip = ds->priv; 2252 struct mv88e6xxx_policy *policy; 2253 int err; 2254 int id; 2255 2256 mv88e6xxx_reg_lock(chip); 2257 2258 switch (rxnfc->cmd) { 2259 case ETHTOOL_GRXCLSRLCNT: 2260 rxnfc->data = 0; 2261 rxnfc->data |= RX_CLS_LOC_SPECIAL; 2262 rxnfc->rule_cnt = 0; 2263 idr_for_each_entry(&chip->policies, policy, id) 2264 if (policy->port == port) 2265 rxnfc->rule_cnt++; 2266 err = 0; 2267 break; 2268 case ETHTOOL_GRXCLSRULE: 2269 err = -ENOENT; 2270 policy = idr_find(&chip->policies, fs->location); 2271 if (policy) { 2272 memcpy(fs, &policy->fs, sizeof(*fs)); 2273 err = 0; 2274 } 2275 break; 2276 case ETHTOOL_GRXCLSRLALL: 2277 rxnfc->data = 0; 2278 rxnfc->rule_cnt = 0; 2279 idr_for_each_entry(&chip->policies, policy, id) 2280 if (policy->port == port) 2281 rule_locs[rxnfc->rule_cnt++] = id; 2282 err = 0; 2283 break; 2284 default: 2285 err = -EOPNOTSUPP; 2286 break; 2287 } 2288 2289 mv88e6xxx_reg_unlock(chip); 2290 2291 return err; 2292 } 2293 2294 static int mv88e6xxx_set_rxnfc(struct dsa_switch *ds, int port, 2295 struct ethtool_rxnfc *rxnfc) 2296 { 2297 struct ethtool_rx_flow_spec *fs = &rxnfc->fs; 2298 struct mv88e6xxx_chip *chip = ds->priv; 2299 struct mv88e6xxx_policy *policy; 2300 int err; 2301 2302 mv88e6xxx_reg_lock(chip); 2303 2304 switch (rxnfc->cmd) { 2305 case ETHTOOL_SRXCLSRLINS: 2306 err = mv88e6xxx_policy_insert(chip, port, fs); 2307 break; 2308 case ETHTOOL_SRXCLSRLDEL: 2309 err = -ENOENT; 2310 policy = idr_remove(&chip->policies, fs->location); 2311 if (policy) { 2312 policy->action = MV88E6XXX_POLICY_ACTION_NORMAL; 2313 err = mv88e6xxx_policy_apply(chip, port, policy); 2314 devm_kfree(chip->dev, policy); 2315 } 2316 break; 2317 default: 2318 err = -EOPNOTSUPP; 2319 break; 2320 } 2321 2322 mv88e6xxx_reg_unlock(chip); 2323 2324 return err; 2325 } 2326 2327 static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port, 2328 u16 vid) 2329 { 2330 u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC; 2331 u8 broadcast[ETH_ALEN]; 2332 2333 eth_broadcast_addr(broadcast); 2334 2335 return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state); 2336 } 2337 2338 static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid) 2339 { 2340 int port; 2341 int err; 2342 2343 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) { 2344 struct dsa_port *dp = dsa_to_port(chip->ds, port); 2345 struct net_device *brport; 2346 2347 if (dsa_is_unused_port(chip->ds, port)) 2348 continue; 2349 2350 brport = dsa_port_to_bridge_port(dp); 2351 if (brport && !br_port_flag_is_set(brport, BR_BCAST_FLOOD)) 2352 /* Skip bridged user ports where broadcast 2353 * flooding is disabled. 2354 */ 2355 continue; 2356 2357 err = mv88e6xxx_port_add_broadcast(chip, port, vid); 2358 if (err) 2359 return err; 2360 } 2361 2362 return 0; 2363 } 2364 2365 struct mv88e6xxx_port_broadcast_sync_ctx { 2366 int port; 2367 bool flood; 2368 }; 2369 2370 static int 2371 mv88e6xxx_port_broadcast_sync_vlan(struct mv88e6xxx_chip *chip, 2372 const struct mv88e6xxx_vtu_entry *vlan, 2373 void *_ctx) 2374 { 2375 struct mv88e6xxx_port_broadcast_sync_ctx *ctx = _ctx; 2376 u8 broadcast[ETH_ALEN]; 2377 u8 state; 2378 2379 if (ctx->flood) 2380 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC; 2381 else 2382 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_UNUSED; 2383 2384 eth_broadcast_addr(broadcast); 2385 2386 return mv88e6xxx_port_db_load_purge(chip, ctx->port, broadcast, 2387 vlan->vid, state); 2388 } 2389 2390 static int mv88e6xxx_port_broadcast_sync(struct mv88e6xxx_chip *chip, int port, 2391 bool flood) 2392 { 2393 struct mv88e6xxx_port_broadcast_sync_ctx ctx = { 2394 .port = port, 2395 .flood = flood, 2396 }; 2397 struct mv88e6xxx_vtu_entry vid0 = { 2398 .vid = 0, 2399 }; 2400 int err; 2401 2402 /* Update the port's private database... */ 2403 err = mv88e6xxx_port_broadcast_sync_vlan(chip, &vid0, &ctx); 2404 if (err) 2405 return err; 2406 2407 /* ...and the database for all VLANs. */ 2408 return mv88e6xxx_vtu_walk(chip, mv88e6xxx_port_broadcast_sync_vlan, 2409 &ctx); 2410 } 2411 2412 static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port, 2413 u16 vid, u8 member, bool warn) 2414 { 2415 const u8 non_member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER; 2416 struct mv88e6xxx_vtu_entry vlan; 2417 int i, err; 2418 2419 err = mv88e6xxx_vtu_get(chip, vid, &vlan); 2420 if (err) 2421 return err; 2422 2423 if (!vlan.valid) { 2424 memset(&vlan, 0, sizeof(vlan)); 2425 2426 if (vid == MV88E6XXX_VID_STANDALONE) 2427 vlan.policy = true; 2428 2429 err = mv88e6xxx_atu_new(chip, &vlan.fid); 2430 if (err) 2431 return err; 2432 2433 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) 2434 if (i == port) 2435 vlan.member[i] = member; 2436 else 2437 vlan.member[i] = non_member; 2438 2439 vlan.vid = vid; 2440 vlan.valid = true; 2441 2442 err = mv88e6xxx_vtu_loadpurge(chip, &vlan); 2443 if (err) 2444 return err; 2445 2446 err = mv88e6xxx_broadcast_setup(chip, vlan.vid); 2447 if (err) 2448 return err; 2449 } else if (vlan.member[port] != member) { 2450 vlan.member[port] = member; 2451 2452 err = mv88e6xxx_vtu_loadpurge(chip, &vlan); 2453 if (err) 2454 return err; 2455 } else if (warn) { 2456 dev_info(chip->dev, "p%d: already a member of VLAN %d\n", 2457 port, vid); 2458 } 2459 2460 return 0; 2461 } 2462 2463 static int mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port, 2464 const struct switchdev_obj_port_vlan *vlan, 2465 struct netlink_ext_ack *extack) 2466 { 2467 struct mv88e6xxx_chip *chip = ds->priv; 2468 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; 2469 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID; 2470 struct mv88e6xxx_port *p = &chip->ports[port]; 2471 bool warn; 2472 u8 member; 2473 int err; 2474 2475 if (!vlan->vid) 2476 return 0; 2477 2478 err = mv88e6xxx_port_vlan_prepare(ds, port, vlan); 2479 if (err) 2480 return err; 2481 2482 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port)) 2483 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED; 2484 else if (untagged) 2485 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED; 2486 else 2487 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED; 2488 2489 /* net/dsa/slave.c will call dsa_port_vlan_add() for the affected port 2490 * and then the CPU port. Do not warn for duplicates for the CPU port. 2491 */ 2492 warn = !dsa_is_cpu_port(ds, port) && !dsa_is_dsa_port(ds, port); 2493 2494 mv88e6xxx_reg_lock(chip); 2495 2496 err = mv88e6xxx_port_vlan_join(chip, port, vlan->vid, member, warn); 2497 if (err) { 2498 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port, 2499 vlan->vid, untagged ? 'u' : 't'); 2500 goto out; 2501 } 2502 2503 if (pvid) { 2504 p->bridge_pvid.vid = vlan->vid; 2505 p->bridge_pvid.valid = true; 2506 2507 err = mv88e6xxx_port_commit_pvid(chip, port); 2508 if (err) 2509 goto out; 2510 } else if (vlan->vid && p->bridge_pvid.vid == vlan->vid) { 2511 /* The old pvid was reinstalled as a non-pvid VLAN */ 2512 p->bridge_pvid.valid = false; 2513 2514 err = mv88e6xxx_port_commit_pvid(chip, port); 2515 if (err) 2516 goto out; 2517 } 2518 2519 out: 2520 mv88e6xxx_reg_unlock(chip); 2521 2522 return err; 2523 } 2524 2525 static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip, 2526 int port, u16 vid) 2527 { 2528 struct mv88e6xxx_vtu_entry vlan; 2529 int i, err; 2530 2531 if (!vid) 2532 return 0; 2533 2534 err = mv88e6xxx_vtu_get(chip, vid, &vlan); 2535 if (err) 2536 return err; 2537 2538 /* If the VLAN doesn't exist in hardware or the port isn't a member, 2539 * tell switchdev that this VLAN is likely handled in software. 2540 */ 2541 if (!vlan.valid || 2542 vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) 2543 return -EOPNOTSUPP; 2544 2545 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER; 2546 2547 /* keep the VLAN unless all ports are excluded */ 2548 vlan.valid = false; 2549 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) { 2550 if (vlan.member[i] != 2551 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) { 2552 vlan.valid = true; 2553 break; 2554 } 2555 } 2556 2557 err = mv88e6xxx_vtu_loadpurge(chip, &vlan); 2558 if (err) 2559 return err; 2560 2561 if (!vlan.valid) { 2562 err = mv88e6xxx_mst_put(chip, vlan.sid); 2563 if (err) 2564 return err; 2565 } 2566 2567 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false); 2568 } 2569 2570 static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port, 2571 const struct switchdev_obj_port_vlan *vlan) 2572 { 2573 struct mv88e6xxx_chip *chip = ds->priv; 2574 struct mv88e6xxx_port *p = &chip->ports[port]; 2575 int err = 0; 2576 u16 pvid; 2577 2578 if (!mv88e6xxx_max_vid(chip)) 2579 return -EOPNOTSUPP; 2580 2581 /* The ATU removal procedure needs the FID to be mapped in the VTU, 2582 * but FDB deletion runs concurrently with VLAN deletion. Flush the DSA 2583 * switchdev workqueue to ensure that all FDB entries are deleted 2584 * before we remove the VLAN. 2585 */ 2586 dsa_flush_workqueue(); 2587 2588 mv88e6xxx_reg_lock(chip); 2589 2590 err = mv88e6xxx_port_get_pvid(chip, port, &pvid); 2591 if (err) 2592 goto unlock; 2593 2594 err = mv88e6xxx_port_vlan_leave(chip, port, vlan->vid); 2595 if (err) 2596 goto unlock; 2597 2598 if (vlan->vid == pvid) { 2599 p->bridge_pvid.valid = false; 2600 2601 err = mv88e6xxx_port_commit_pvid(chip, port); 2602 if (err) 2603 goto unlock; 2604 } 2605 2606 unlock: 2607 mv88e6xxx_reg_unlock(chip); 2608 2609 return err; 2610 } 2611 2612 static int mv88e6xxx_port_vlan_fast_age(struct dsa_switch *ds, int port, u16 vid) 2613 { 2614 struct mv88e6xxx_chip *chip = ds->priv; 2615 struct mv88e6xxx_vtu_entry vlan; 2616 int err; 2617 2618 mv88e6xxx_reg_lock(chip); 2619 2620 err = mv88e6xxx_vtu_get(chip, vid, &vlan); 2621 if (err) 2622 goto unlock; 2623 2624 err = mv88e6xxx_port_fast_age_fid(chip, port, vlan.fid); 2625 2626 unlock: 2627 mv88e6xxx_reg_unlock(chip); 2628 2629 return err; 2630 } 2631 2632 static int mv88e6xxx_vlan_msti_set(struct dsa_switch *ds, 2633 struct dsa_bridge bridge, 2634 const struct switchdev_vlan_msti *msti) 2635 { 2636 struct mv88e6xxx_chip *chip = ds->priv; 2637 struct mv88e6xxx_vtu_entry vlan; 2638 u8 old_sid, new_sid; 2639 int err; 2640 2641 if (!mv88e6xxx_has_stu(chip)) 2642 return -EOPNOTSUPP; 2643 2644 mv88e6xxx_reg_lock(chip); 2645 2646 err = mv88e6xxx_vtu_get(chip, msti->vid, &vlan); 2647 if (err) 2648 goto unlock; 2649 2650 if (!vlan.valid) { 2651 err = -EINVAL; 2652 goto unlock; 2653 } 2654 2655 old_sid = vlan.sid; 2656 2657 err = mv88e6xxx_mst_get(chip, bridge.dev, msti->msti, &new_sid); 2658 if (err) 2659 goto unlock; 2660 2661 if (new_sid != old_sid) { 2662 vlan.sid = new_sid; 2663 2664 err = mv88e6xxx_vtu_loadpurge(chip, &vlan); 2665 if (err) { 2666 mv88e6xxx_mst_put(chip, new_sid); 2667 goto unlock; 2668 } 2669 } 2670 2671 err = mv88e6xxx_mst_put(chip, old_sid); 2672 2673 unlock: 2674 mv88e6xxx_reg_unlock(chip); 2675 return err; 2676 } 2677 2678 static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port, 2679 const unsigned char *addr, u16 vid, 2680 struct dsa_db db) 2681 { 2682 struct mv88e6xxx_chip *chip = ds->priv; 2683 int err; 2684 2685 mv88e6xxx_reg_lock(chip); 2686 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid, 2687 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC); 2688 mv88e6xxx_reg_unlock(chip); 2689 2690 return err; 2691 } 2692 2693 static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port, 2694 const unsigned char *addr, u16 vid, 2695 struct dsa_db db) 2696 { 2697 struct mv88e6xxx_chip *chip = ds->priv; 2698 int err; 2699 2700 mv88e6xxx_reg_lock(chip); 2701 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid, 0); 2702 mv88e6xxx_reg_unlock(chip); 2703 2704 return err; 2705 } 2706 2707 static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip, 2708 u16 fid, u16 vid, int port, 2709 dsa_fdb_dump_cb_t *cb, void *data) 2710 { 2711 struct mv88e6xxx_atu_entry addr; 2712 bool is_static; 2713 int err; 2714 2715 addr.state = 0; 2716 eth_broadcast_addr(addr.mac); 2717 2718 do { 2719 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr); 2720 if (err) 2721 return err; 2722 2723 if (!addr.state) 2724 break; 2725 2726 if (addr.trunk || (addr.portvec & BIT(port)) == 0) 2727 continue; 2728 2729 if (!is_unicast_ether_addr(addr.mac)) 2730 continue; 2731 2732 is_static = (addr.state == 2733 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC); 2734 err = cb(addr.mac, vid, is_static, data); 2735 if (err) 2736 return err; 2737 } while (!is_broadcast_ether_addr(addr.mac)); 2738 2739 return err; 2740 } 2741 2742 struct mv88e6xxx_port_db_dump_vlan_ctx { 2743 int port; 2744 dsa_fdb_dump_cb_t *cb; 2745 void *data; 2746 }; 2747 2748 static int mv88e6xxx_port_db_dump_vlan(struct mv88e6xxx_chip *chip, 2749 const struct mv88e6xxx_vtu_entry *entry, 2750 void *_data) 2751 { 2752 struct mv88e6xxx_port_db_dump_vlan_ctx *ctx = _data; 2753 2754 return mv88e6xxx_port_db_dump_fid(chip, entry->fid, entry->vid, 2755 ctx->port, ctx->cb, ctx->data); 2756 } 2757 2758 static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port, 2759 dsa_fdb_dump_cb_t *cb, void *data) 2760 { 2761 struct mv88e6xxx_port_db_dump_vlan_ctx ctx = { 2762 .port = port, 2763 .cb = cb, 2764 .data = data, 2765 }; 2766 u16 fid; 2767 int err; 2768 2769 /* Dump port's default Filtering Information Database (VLAN ID 0) */ 2770 err = mv88e6xxx_port_get_fid(chip, port, &fid); 2771 if (err) 2772 return err; 2773 2774 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data); 2775 if (err) 2776 return err; 2777 2778 return mv88e6xxx_vtu_walk(chip, mv88e6xxx_port_db_dump_vlan, &ctx); 2779 } 2780 2781 static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port, 2782 dsa_fdb_dump_cb_t *cb, void *data) 2783 { 2784 struct mv88e6xxx_chip *chip = ds->priv; 2785 int err; 2786 2787 mv88e6xxx_reg_lock(chip); 2788 err = mv88e6xxx_port_db_dump(chip, port, cb, data); 2789 mv88e6xxx_reg_unlock(chip); 2790 2791 return err; 2792 } 2793 2794 static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip, 2795 struct dsa_bridge bridge) 2796 { 2797 struct dsa_switch *ds = chip->ds; 2798 struct dsa_switch_tree *dst = ds->dst; 2799 struct dsa_port *dp; 2800 int err; 2801 2802 list_for_each_entry(dp, &dst->ports, list) { 2803 if (dsa_port_offloads_bridge(dp, &bridge)) { 2804 if (dp->ds == ds) { 2805 /* This is a local bridge group member, 2806 * remap its Port VLAN Map. 2807 */ 2808 err = mv88e6xxx_port_vlan_map(chip, dp->index); 2809 if (err) 2810 return err; 2811 } else { 2812 /* This is an external bridge group member, 2813 * remap its cross-chip Port VLAN Table entry. 2814 */ 2815 err = mv88e6xxx_pvt_map(chip, dp->ds->index, 2816 dp->index); 2817 if (err) 2818 return err; 2819 } 2820 } 2821 } 2822 2823 return 0; 2824 } 2825 2826 /* Treat the software bridge as a virtual single-port switch behind the 2827 * CPU and map in the PVT. First dst->last_switch elements are taken by 2828 * physical switches, so start from beyond that range. 2829 */ 2830 static int mv88e6xxx_map_virtual_bridge_to_pvt(struct dsa_switch *ds, 2831 unsigned int bridge_num) 2832 { 2833 u8 dev = bridge_num + ds->dst->last_switch; 2834 struct mv88e6xxx_chip *chip = ds->priv; 2835 2836 return mv88e6xxx_pvt_map(chip, dev, 0); 2837 } 2838 2839 static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port, 2840 struct dsa_bridge bridge, 2841 bool *tx_fwd_offload, 2842 struct netlink_ext_ack *extack) 2843 { 2844 struct mv88e6xxx_chip *chip = ds->priv; 2845 int err; 2846 2847 mv88e6xxx_reg_lock(chip); 2848 2849 err = mv88e6xxx_bridge_map(chip, bridge); 2850 if (err) 2851 goto unlock; 2852 2853 err = mv88e6xxx_port_set_map_da(chip, port, true); 2854 if (err) 2855 goto unlock; 2856 2857 err = mv88e6xxx_port_commit_pvid(chip, port); 2858 if (err) 2859 goto unlock; 2860 2861 if (mv88e6xxx_has_pvt(chip)) { 2862 err = mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge.num); 2863 if (err) 2864 goto unlock; 2865 2866 *tx_fwd_offload = true; 2867 } 2868 2869 unlock: 2870 mv88e6xxx_reg_unlock(chip); 2871 2872 return err; 2873 } 2874 2875 static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port, 2876 struct dsa_bridge bridge) 2877 { 2878 struct mv88e6xxx_chip *chip = ds->priv; 2879 int err; 2880 2881 mv88e6xxx_reg_lock(chip); 2882 2883 if (bridge.tx_fwd_offload && 2884 mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge.num)) 2885 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n"); 2886 2887 if (mv88e6xxx_bridge_map(chip, bridge) || 2888 mv88e6xxx_port_vlan_map(chip, port)) 2889 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n"); 2890 2891 err = mv88e6xxx_port_set_map_da(chip, port, false); 2892 if (err) 2893 dev_err(ds->dev, 2894 "port %d failed to restore map-DA: %pe\n", 2895 port, ERR_PTR(err)); 2896 2897 err = mv88e6xxx_port_commit_pvid(chip, port); 2898 if (err) 2899 dev_err(ds->dev, 2900 "port %d failed to restore standalone pvid: %pe\n", 2901 port, ERR_PTR(err)); 2902 2903 mv88e6xxx_reg_unlock(chip); 2904 } 2905 2906 static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, 2907 int tree_index, int sw_index, 2908 int port, struct dsa_bridge bridge, 2909 struct netlink_ext_ack *extack) 2910 { 2911 struct mv88e6xxx_chip *chip = ds->priv; 2912 int err; 2913 2914 if (tree_index != ds->dst->index) 2915 return 0; 2916 2917 mv88e6xxx_reg_lock(chip); 2918 err = mv88e6xxx_pvt_map(chip, sw_index, port); 2919 err = err ? : mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge.num); 2920 mv88e6xxx_reg_unlock(chip); 2921 2922 return err; 2923 } 2924 2925 static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, 2926 int tree_index, int sw_index, 2927 int port, struct dsa_bridge bridge) 2928 { 2929 struct mv88e6xxx_chip *chip = ds->priv; 2930 2931 if (tree_index != ds->dst->index) 2932 return; 2933 2934 mv88e6xxx_reg_lock(chip); 2935 if (mv88e6xxx_pvt_map(chip, sw_index, port) || 2936 mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge.num)) 2937 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n"); 2938 mv88e6xxx_reg_unlock(chip); 2939 } 2940 2941 static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip) 2942 { 2943 if (chip->info->ops->reset) 2944 return chip->info->ops->reset(chip); 2945 2946 return 0; 2947 } 2948 2949 static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip) 2950 { 2951 struct gpio_desc *gpiod = chip->reset; 2952 2953 /* If there is a GPIO connected to the reset pin, toggle it */ 2954 if (gpiod) { 2955 /* If the switch has just been reset and not yet completed 2956 * loading EEPROM, the reset may interrupt the I2C transaction 2957 * mid-byte, causing the first EEPROM read after the reset 2958 * from the wrong location resulting in the switch booting 2959 * to wrong mode and inoperable. 2960 */ 2961 mv88e6xxx_g1_wait_eeprom_done(chip); 2962 2963 gpiod_set_value_cansleep(gpiod, 1); 2964 usleep_range(10000, 20000); 2965 gpiod_set_value_cansleep(gpiod, 0); 2966 usleep_range(10000, 20000); 2967 2968 mv88e6xxx_g1_wait_eeprom_done(chip); 2969 } 2970 } 2971 2972 static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip) 2973 { 2974 int i, err; 2975 2976 /* Set all ports to the Disabled state */ 2977 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) { 2978 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED); 2979 if (err) 2980 return err; 2981 } 2982 2983 /* Wait for transmit queues to drain, 2984 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps. 2985 */ 2986 usleep_range(2000, 4000); 2987 2988 return 0; 2989 } 2990 2991 static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip) 2992 { 2993 int err; 2994 2995 err = mv88e6xxx_disable_ports(chip); 2996 if (err) 2997 return err; 2998 2999 mv88e6xxx_hardware_reset(chip); 3000 3001 return mv88e6xxx_software_reset(chip); 3002 } 3003 3004 static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port, 3005 enum mv88e6xxx_frame_mode frame, 3006 enum mv88e6xxx_egress_mode egress, u16 etype) 3007 { 3008 int err; 3009 3010 if (!chip->info->ops->port_set_frame_mode) 3011 return -EOPNOTSUPP; 3012 3013 err = mv88e6xxx_port_set_egress_mode(chip, port, egress); 3014 if (err) 3015 return err; 3016 3017 err = chip->info->ops->port_set_frame_mode(chip, port, frame); 3018 if (err) 3019 return err; 3020 3021 if (chip->info->ops->port_set_ether_type) 3022 return chip->info->ops->port_set_ether_type(chip, port, etype); 3023 3024 return 0; 3025 } 3026 3027 static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port) 3028 { 3029 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL, 3030 MV88E6XXX_EGRESS_MODE_UNMODIFIED, 3031 MV88E6XXX_PORT_ETH_TYPE_DEFAULT); 3032 } 3033 3034 static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port) 3035 { 3036 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA, 3037 MV88E6XXX_EGRESS_MODE_UNMODIFIED, 3038 MV88E6XXX_PORT_ETH_TYPE_DEFAULT); 3039 } 3040 3041 static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port) 3042 { 3043 return mv88e6xxx_set_port_mode(chip, port, 3044 MV88E6XXX_FRAME_MODE_ETHERTYPE, 3045 MV88E6XXX_EGRESS_MODE_ETHERTYPE, 3046 ETH_P_EDSA); 3047 } 3048 3049 static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port) 3050 { 3051 if (dsa_is_dsa_port(chip->ds, port)) 3052 return mv88e6xxx_set_port_mode_dsa(chip, port); 3053 3054 if (dsa_is_user_port(chip->ds, port)) 3055 return mv88e6xxx_set_port_mode_normal(chip, port); 3056 3057 /* Setup CPU port mode depending on its supported tag format */ 3058 if (chip->tag_protocol == DSA_TAG_PROTO_DSA) 3059 return mv88e6xxx_set_port_mode_dsa(chip, port); 3060 3061 if (chip->tag_protocol == DSA_TAG_PROTO_EDSA) 3062 return mv88e6xxx_set_port_mode_edsa(chip, port); 3063 3064 return -EINVAL; 3065 } 3066 3067 static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port) 3068 { 3069 bool message = dsa_is_dsa_port(chip->ds, port); 3070 3071 return mv88e6xxx_port_set_message_port(chip, port, message); 3072 } 3073 3074 static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port) 3075 { 3076 int err; 3077 3078 if (chip->info->ops->port_set_ucast_flood) { 3079 err = chip->info->ops->port_set_ucast_flood(chip, port, true); 3080 if (err) 3081 return err; 3082 } 3083 if (chip->info->ops->port_set_mcast_flood) { 3084 err = chip->info->ops->port_set_mcast_flood(chip, port, true); 3085 if (err) 3086 return err; 3087 } 3088 3089 return 0; 3090 } 3091 3092 static int mv88e6xxx_set_egress_port(struct mv88e6xxx_chip *chip, 3093 enum mv88e6xxx_egress_direction direction, 3094 int port) 3095 { 3096 int err; 3097 3098 if (!chip->info->ops->set_egress_port) 3099 return -EOPNOTSUPP; 3100 3101 err = chip->info->ops->set_egress_port(chip, direction, port); 3102 if (err) 3103 return err; 3104 3105 if (direction == MV88E6XXX_EGRESS_DIR_INGRESS) 3106 chip->ingress_dest_port = port; 3107 else 3108 chip->egress_dest_port = port; 3109 3110 return 0; 3111 } 3112 3113 static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port) 3114 { 3115 struct dsa_switch *ds = chip->ds; 3116 int upstream_port; 3117 int err; 3118 3119 upstream_port = dsa_upstream_port(ds, port); 3120 if (chip->info->ops->port_set_upstream_port) { 3121 err = chip->info->ops->port_set_upstream_port(chip, port, 3122 upstream_port); 3123 if (err) 3124 return err; 3125 } 3126 3127 if (port == upstream_port) { 3128 if (chip->info->ops->set_cpu_port) { 3129 err = chip->info->ops->set_cpu_port(chip, 3130 upstream_port); 3131 if (err) 3132 return err; 3133 } 3134 3135 err = mv88e6xxx_set_egress_port(chip, 3136 MV88E6XXX_EGRESS_DIR_INGRESS, 3137 upstream_port); 3138 if (err && err != -EOPNOTSUPP) 3139 return err; 3140 3141 err = mv88e6xxx_set_egress_port(chip, 3142 MV88E6XXX_EGRESS_DIR_EGRESS, 3143 upstream_port); 3144 if (err && err != -EOPNOTSUPP) 3145 return err; 3146 } 3147 3148 return 0; 3149 } 3150 3151 static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port) 3152 { 3153 struct device_node *phy_handle = NULL; 3154 struct dsa_switch *ds = chip->ds; 3155 struct dsa_port *dp; 3156 int tx_amp; 3157 int err; 3158 u16 reg; 3159 3160 chip->ports[port].chip = chip; 3161 chip->ports[port].port = port; 3162 3163 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED, 3164 SPEED_UNFORCED, DUPLEX_UNFORCED, 3165 PAUSE_ON, PHY_INTERFACE_MODE_NA); 3166 if (err) 3167 return err; 3168 3169 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock, 3170 * disable Header mode, enable IGMP/MLD snooping, disable VLAN 3171 * tunneling, determine priority by looking at 802.1p and IP 3172 * priority fields (IP prio has precedence), and set STP state 3173 * to Forwarding. 3174 * 3175 * If this is the CPU link, use DSA or EDSA tagging depending 3176 * on which tagging mode was configured. 3177 * 3178 * If this is a link to another switch, use DSA tagging mode. 3179 * 3180 * If this is the upstream port for this switch, enable 3181 * forwarding of unknown unicasts and multicasts. 3182 */ 3183 reg = MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP | 3184 MV88E6XXX_PORT_CTL0_STATE_FORWARDING; 3185 /* Forward any IPv4 IGMP or IPv6 MLD frames received 3186 * by a USER port to the CPU port to allow snooping. 3187 */ 3188 if (dsa_is_user_port(ds, port)) 3189 reg |= MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP; 3190 3191 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg); 3192 if (err) 3193 return err; 3194 3195 err = mv88e6xxx_setup_port_mode(chip, port); 3196 if (err) 3197 return err; 3198 3199 err = mv88e6xxx_setup_egress_floods(chip, port); 3200 if (err) 3201 return err; 3202 3203 /* Port Control 2: don't force a good FCS, set the MTU size to 3204 * 10222 bytes, disable 802.1q tags checking, don't discard 3205 * tagged or untagged frames on this port, skip destination 3206 * address lookup on user ports, disable ARP mirroring and don't 3207 * send a copy of all transmitted/received frames on this port 3208 * to the CPU. 3209 */ 3210 err = mv88e6xxx_port_set_map_da(chip, port, !dsa_is_user_port(ds, port)); 3211 if (err) 3212 return err; 3213 3214 err = mv88e6xxx_setup_upstream_port(chip, port); 3215 if (err) 3216 return err; 3217 3218 /* On chips that support it, set all downstream DSA ports' 3219 * VLAN policy to TRAP. In combination with loading 3220 * MV88E6XXX_VID_STANDALONE as a policy entry in the VTU, this 3221 * provides a better isolation barrier between standalone 3222 * ports, as the ATU is bypassed on any intermediate switches 3223 * between the incoming port and the CPU. 3224 */ 3225 if (dsa_is_downstream_port(ds, port) && 3226 chip->info->ops->port_set_policy) { 3227 err = chip->info->ops->port_set_policy(chip, port, 3228 MV88E6XXX_POLICY_MAPPING_VTU, 3229 MV88E6XXX_POLICY_ACTION_TRAP); 3230 if (err) 3231 return err; 3232 } 3233 3234 /* User ports start out in standalone mode and 802.1Q is 3235 * therefore disabled. On DSA ports, all valid VIDs are always 3236 * loaded in the VTU - therefore, enable 802.1Q in order to take 3237 * advantage of VLAN policy on chips that supports it. 3238 */ 3239 err = mv88e6xxx_port_set_8021q_mode(chip, port, 3240 dsa_is_user_port(ds, port) ? 3241 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED : 3242 MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE); 3243 if (err) 3244 return err; 3245 3246 /* Bind MV88E6XXX_VID_STANDALONE to MV88E6XXX_FID_STANDALONE by 3247 * virtue of the fact that mv88e6xxx_atu_new() will pick it as 3248 * the first free FID. This will be used as the private PVID for 3249 * unbridged ports. Shared (DSA and CPU) ports must also be 3250 * members of this VID, in order to trap all frames assigned to 3251 * it to the CPU. 3252 */ 3253 err = mv88e6xxx_port_vlan_join(chip, port, MV88E6XXX_VID_STANDALONE, 3254 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED, 3255 false); 3256 if (err) 3257 return err; 3258 3259 /* Associate MV88E6XXX_VID_BRIDGED with MV88E6XXX_FID_BRIDGED in the 3260 * ATU by virtue of the fact that mv88e6xxx_atu_new() will pick it as 3261 * the first free FID after MV88E6XXX_FID_STANDALONE. This will be used 3262 * as the private PVID on ports under a VLAN-unaware bridge. 3263 * Shared (DSA and CPU) ports must also be members of it, to translate 3264 * the VID from the DSA tag into MV88E6XXX_FID_BRIDGED, instead of 3265 * relying on their port default FID. 3266 */ 3267 err = mv88e6xxx_port_vlan_join(chip, port, MV88E6XXX_VID_BRIDGED, 3268 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED, 3269 false); 3270 if (err) 3271 return err; 3272 3273 if (chip->info->ops->port_set_jumbo_size) { 3274 err = chip->info->ops->port_set_jumbo_size(chip, port, 10218); 3275 if (err) 3276 return err; 3277 } 3278 3279 /* Port Association Vector: disable automatic address learning 3280 * on all user ports since they start out in standalone 3281 * mode. When joining a bridge, learning will be configured to 3282 * match the bridge port settings. Enable learning on all 3283 * DSA/CPU ports. NOTE: FROM_CPU frames always bypass the 3284 * learning process. 3285 * 3286 * Disable HoldAt1, IntOnAgeOut, LockedPort, IgnoreWrongData, 3287 * and RefreshLocked. I.e. setup standard automatic learning. 3288 */ 3289 if (dsa_is_user_port(ds, port)) 3290 reg = 0; 3291 else 3292 reg = 1 << port; 3293 3294 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR, 3295 reg); 3296 if (err) 3297 return err; 3298 3299 /* Egress rate control 2: disable egress rate control. */ 3300 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2, 3301 0x0000); 3302 if (err) 3303 return err; 3304 3305 if (chip->info->ops->port_pause_limit) { 3306 err = chip->info->ops->port_pause_limit(chip, port, 0, 0); 3307 if (err) 3308 return err; 3309 } 3310 3311 if (chip->info->ops->port_disable_learn_limit) { 3312 err = chip->info->ops->port_disable_learn_limit(chip, port); 3313 if (err) 3314 return err; 3315 } 3316 3317 if (chip->info->ops->port_disable_pri_override) { 3318 err = chip->info->ops->port_disable_pri_override(chip, port); 3319 if (err) 3320 return err; 3321 } 3322 3323 if (chip->info->ops->port_tag_remap) { 3324 err = chip->info->ops->port_tag_remap(chip, port); 3325 if (err) 3326 return err; 3327 } 3328 3329 if (chip->info->ops->port_egress_rate_limiting) { 3330 err = chip->info->ops->port_egress_rate_limiting(chip, port); 3331 if (err) 3332 return err; 3333 } 3334 3335 if (chip->info->ops->port_setup_message_port) { 3336 err = chip->info->ops->port_setup_message_port(chip, port); 3337 if (err) 3338 return err; 3339 } 3340 3341 if (chip->info->ops->serdes_set_tx_amplitude) { 3342 dp = dsa_to_port(ds, port); 3343 if (dp) 3344 phy_handle = of_parse_phandle(dp->dn, "phy-handle", 0); 3345 3346 if (phy_handle && !of_property_read_u32(phy_handle, 3347 "tx-p2p-microvolt", 3348 &tx_amp)) 3349 err = chip->info->ops->serdes_set_tx_amplitude(chip, 3350 port, tx_amp); 3351 if (phy_handle) { 3352 of_node_put(phy_handle); 3353 if (err) 3354 return err; 3355 } 3356 } 3357 3358 /* Port based VLAN map: give each port the same default address 3359 * database, and allow bidirectional communication between the 3360 * CPU and DSA port(s), and the other ports. 3361 */ 3362 err = mv88e6xxx_port_set_fid(chip, port, MV88E6XXX_FID_STANDALONE); 3363 if (err) 3364 return err; 3365 3366 err = mv88e6xxx_port_vlan_map(chip, port); 3367 if (err) 3368 return err; 3369 3370 /* Default VLAN ID and priority: don't set a default VLAN 3371 * ID, and set the default packet priority to zero. 3372 */ 3373 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0); 3374 } 3375 3376 static int mv88e6xxx_get_max_mtu(struct dsa_switch *ds, int port) 3377 { 3378 struct mv88e6xxx_chip *chip = ds->priv; 3379 3380 if (chip->info->ops->port_set_jumbo_size) 3381 return 10240 - VLAN_ETH_HLEN - EDSA_HLEN - ETH_FCS_LEN; 3382 else if (chip->info->ops->set_max_frame_size) 3383 return 1632 - VLAN_ETH_HLEN - EDSA_HLEN - ETH_FCS_LEN; 3384 return ETH_DATA_LEN; 3385 } 3386 3387 static int mv88e6xxx_change_mtu(struct dsa_switch *ds, int port, int new_mtu) 3388 { 3389 struct mv88e6xxx_chip *chip = ds->priv; 3390 int ret = 0; 3391 3392 /* For families where we don't know how to alter the MTU, 3393 * just accept any value up to ETH_DATA_LEN 3394 */ 3395 if (!chip->info->ops->port_set_jumbo_size && 3396 !chip->info->ops->set_max_frame_size) { 3397 if (new_mtu > ETH_DATA_LEN) 3398 return -EINVAL; 3399 3400 return 0; 3401 } 3402 3403 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port)) 3404 new_mtu += EDSA_HLEN; 3405 3406 mv88e6xxx_reg_lock(chip); 3407 if (chip->info->ops->port_set_jumbo_size) 3408 ret = chip->info->ops->port_set_jumbo_size(chip, port, new_mtu); 3409 else if (chip->info->ops->set_max_frame_size) 3410 ret = chip->info->ops->set_max_frame_size(chip, new_mtu); 3411 mv88e6xxx_reg_unlock(chip); 3412 3413 return ret; 3414 } 3415 3416 static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds, 3417 unsigned int ageing_time) 3418 { 3419 struct mv88e6xxx_chip *chip = ds->priv; 3420 int err; 3421 3422 mv88e6xxx_reg_lock(chip); 3423 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time); 3424 mv88e6xxx_reg_unlock(chip); 3425 3426 return err; 3427 } 3428 3429 static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip) 3430 { 3431 int err; 3432 3433 /* Initialize the statistics unit */ 3434 if (chip->info->ops->stats_set_histogram) { 3435 err = chip->info->ops->stats_set_histogram(chip); 3436 if (err) 3437 return err; 3438 } 3439 3440 return mv88e6xxx_g1_stats_clear(chip); 3441 } 3442 3443 /* Check if the errata has already been applied. */ 3444 static bool mv88e6390_setup_errata_applied(struct mv88e6xxx_chip *chip) 3445 { 3446 int port; 3447 int err; 3448 u16 val; 3449 3450 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) { 3451 err = mv88e6xxx_port_hidden_read(chip, 0xf, port, 0, &val); 3452 if (err) { 3453 dev_err(chip->dev, 3454 "Error reading hidden register: %d\n", err); 3455 return false; 3456 } 3457 if (val != 0x01c0) 3458 return false; 3459 } 3460 3461 return true; 3462 } 3463 3464 /* The 6390 copper ports have an errata which require poking magic 3465 * values into undocumented hidden registers and then performing a 3466 * software reset. 3467 */ 3468 static int mv88e6390_setup_errata(struct mv88e6xxx_chip *chip) 3469 { 3470 int port; 3471 int err; 3472 3473 if (mv88e6390_setup_errata_applied(chip)) 3474 return 0; 3475 3476 /* Set the ports into blocking mode */ 3477 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) { 3478 err = mv88e6xxx_port_set_state(chip, port, BR_STATE_DISABLED); 3479 if (err) 3480 return err; 3481 } 3482 3483 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) { 3484 err = mv88e6xxx_port_hidden_write(chip, 0xf, port, 0, 0x01c0); 3485 if (err) 3486 return err; 3487 } 3488 3489 return mv88e6xxx_software_reset(chip); 3490 } 3491 3492 /* prod_id for switch families which do not have a PHY model number */ 3493 static const u16 family_prod_id_table[] = { 3494 [MV88E6XXX_FAMILY_6341] = MV88E6XXX_PORT_SWITCH_ID_PROD_6341, 3495 [MV88E6XXX_FAMILY_6390] = MV88E6XXX_PORT_SWITCH_ID_PROD_6390, 3496 [MV88E6XXX_FAMILY_6393] = MV88E6XXX_PORT_SWITCH_ID_PROD_6393X, 3497 }; 3498 3499 static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg) 3500 { 3501 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv; 3502 struct mv88e6xxx_chip *chip = mdio_bus->chip; 3503 u16 prod_id; 3504 u16 val; 3505 int err; 3506 3507 if (!chip->info->ops->phy_read) 3508 return -EOPNOTSUPP; 3509 3510 mv88e6xxx_reg_lock(chip); 3511 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val); 3512 mv88e6xxx_reg_unlock(chip); 3513 3514 /* Some internal PHYs don't have a model number. */ 3515 if (reg == MII_PHYSID2 && !(val & 0x3f0) && 3516 chip->info->family < ARRAY_SIZE(family_prod_id_table)) { 3517 prod_id = family_prod_id_table[chip->info->family]; 3518 if (prod_id) 3519 val |= prod_id >> 4; 3520 } 3521 3522 return err ? err : val; 3523 } 3524 3525 static int mv88e6xxx_mdio_read_c45(struct mii_bus *bus, int phy, int devad, 3526 int reg) 3527 { 3528 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv; 3529 struct mv88e6xxx_chip *chip = mdio_bus->chip; 3530 u16 val; 3531 int err; 3532 3533 if (!chip->info->ops->phy_read_c45) 3534 return -EOPNOTSUPP; 3535 3536 mv88e6xxx_reg_lock(chip); 3537 err = chip->info->ops->phy_read_c45(chip, bus, phy, devad, reg, &val); 3538 mv88e6xxx_reg_unlock(chip); 3539 3540 return err ? err : val; 3541 } 3542 3543 static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val) 3544 { 3545 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv; 3546 struct mv88e6xxx_chip *chip = mdio_bus->chip; 3547 int err; 3548 3549 if (!chip->info->ops->phy_write) 3550 return -EOPNOTSUPP; 3551 3552 mv88e6xxx_reg_lock(chip); 3553 err = chip->info->ops->phy_write(chip, bus, phy, reg, val); 3554 mv88e6xxx_reg_unlock(chip); 3555 3556 return err; 3557 } 3558 3559 static int mv88e6xxx_mdio_write_c45(struct mii_bus *bus, int phy, int devad, 3560 int reg, u16 val) 3561 { 3562 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv; 3563 struct mv88e6xxx_chip *chip = mdio_bus->chip; 3564 int err; 3565 3566 if (!chip->info->ops->phy_write_c45) 3567 return -EOPNOTSUPP; 3568 3569 mv88e6xxx_reg_lock(chip); 3570 err = chip->info->ops->phy_write_c45(chip, bus, phy, devad, reg, val); 3571 mv88e6xxx_reg_unlock(chip); 3572 3573 return err; 3574 } 3575 3576 static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip, 3577 struct device_node *np, 3578 bool external) 3579 { 3580 static int index; 3581 struct mv88e6xxx_mdio_bus *mdio_bus; 3582 struct mii_bus *bus; 3583 int err; 3584 3585 if (external) { 3586 mv88e6xxx_reg_lock(chip); 3587 err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true); 3588 mv88e6xxx_reg_unlock(chip); 3589 3590 if (err) 3591 return err; 3592 } 3593 3594 bus = mdiobus_alloc_size(sizeof(*mdio_bus)); 3595 if (!bus) 3596 return -ENOMEM; 3597 3598 mdio_bus = bus->priv; 3599 mdio_bus->bus = bus; 3600 mdio_bus->chip = chip; 3601 INIT_LIST_HEAD(&mdio_bus->list); 3602 mdio_bus->external = external; 3603 3604 if (np) { 3605 bus->name = np->full_name; 3606 snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np); 3607 } else { 3608 bus->name = "mv88e6xxx SMI"; 3609 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++); 3610 } 3611 3612 bus->read = mv88e6xxx_mdio_read; 3613 bus->write = mv88e6xxx_mdio_write; 3614 bus->read_c45 = mv88e6xxx_mdio_read_c45; 3615 bus->write_c45 = mv88e6xxx_mdio_write_c45; 3616 bus->parent = chip->dev; 3617 bus->phy_mask = ~GENMASK(chip->info->phy_base_addr + 3618 mv88e6xxx_num_ports(chip) - 1, 3619 chip->info->phy_base_addr); 3620 3621 if (!external) { 3622 err = mv88e6xxx_g2_irq_mdio_setup(chip, bus); 3623 if (err) 3624 goto out; 3625 } 3626 3627 err = of_mdiobus_register(bus, np); 3628 if (err) { 3629 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err); 3630 mv88e6xxx_g2_irq_mdio_free(chip, bus); 3631 goto out; 3632 } 3633 3634 if (external) 3635 list_add_tail(&mdio_bus->list, &chip->mdios); 3636 else 3637 list_add(&mdio_bus->list, &chip->mdios); 3638 3639 return 0; 3640 3641 out: 3642 mdiobus_free(bus); 3643 return err; 3644 } 3645 3646 static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip) 3647 3648 { 3649 struct mv88e6xxx_mdio_bus *mdio_bus, *p; 3650 struct mii_bus *bus; 3651 3652 list_for_each_entry_safe(mdio_bus, p, &chip->mdios, list) { 3653 bus = mdio_bus->bus; 3654 3655 if (!mdio_bus->external) 3656 mv88e6xxx_g2_irq_mdio_free(chip, bus); 3657 3658 mdiobus_unregister(bus); 3659 mdiobus_free(bus); 3660 } 3661 } 3662 3663 static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip) 3664 { 3665 struct device_node *np = chip->dev->of_node; 3666 struct device_node *child; 3667 int err; 3668 3669 /* Always register one mdio bus for the internal/default mdio 3670 * bus. This maybe represented in the device tree, but is 3671 * optional. 3672 */ 3673 child = of_get_child_by_name(np, "mdio"); 3674 err = mv88e6xxx_mdio_register(chip, child, false); 3675 of_node_put(child); 3676 if (err) 3677 return err; 3678 3679 /* Walk the device tree, and see if there are any other nodes 3680 * which say they are compatible with the external mdio 3681 * bus. 3682 */ 3683 for_each_available_child_of_node(np, child) { 3684 if (of_device_is_compatible( 3685 child, "marvell,mv88e6xxx-mdio-external")) { 3686 err = mv88e6xxx_mdio_register(chip, child, true); 3687 if (err) { 3688 mv88e6xxx_mdios_unregister(chip); 3689 of_node_put(child); 3690 return err; 3691 } 3692 } 3693 } 3694 3695 return 0; 3696 } 3697 3698 static void mv88e6xxx_teardown(struct dsa_switch *ds) 3699 { 3700 struct mv88e6xxx_chip *chip = ds->priv; 3701 3702 mv88e6xxx_teardown_devlink_params(ds); 3703 dsa_devlink_resources_unregister(ds); 3704 mv88e6xxx_teardown_devlink_regions_global(ds); 3705 mv88e6xxx_mdios_unregister(chip); 3706 } 3707 3708 static int mv88e6xxx_setup(struct dsa_switch *ds) 3709 { 3710 struct mv88e6xxx_chip *chip = ds->priv; 3711 u8 cmode; 3712 int err; 3713 int i; 3714 3715 err = mv88e6xxx_mdios_register(chip); 3716 if (err) 3717 return err; 3718 3719 chip->ds = ds; 3720 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip); 3721 3722 /* Since virtual bridges are mapped in the PVT, the number we support 3723 * depends on the physical switch topology. We need to let DSA figure 3724 * that out and therefore we cannot set this at dsa_register_switch() 3725 * time. 3726 */ 3727 if (mv88e6xxx_has_pvt(chip)) 3728 ds->max_num_bridges = MV88E6XXX_MAX_PVT_SWITCHES - 3729 ds->dst->last_switch - 1; 3730 3731 mv88e6xxx_reg_lock(chip); 3732 3733 if (chip->info->ops->setup_errata) { 3734 err = chip->info->ops->setup_errata(chip); 3735 if (err) 3736 goto unlock; 3737 } 3738 3739 /* Cache the cmode of each port. */ 3740 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) { 3741 if (chip->info->ops->port_get_cmode) { 3742 err = chip->info->ops->port_get_cmode(chip, i, &cmode); 3743 if (err) 3744 goto unlock; 3745 3746 chip->ports[i].cmode = cmode; 3747 } 3748 } 3749 3750 err = mv88e6xxx_vtu_setup(chip); 3751 if (err) 3752 goto unlock; 3753 3754 /* Must be called after mv88e6xxx_vtu_setup (which flushes the 3755 * VTU, thereby also flushing the STU). 3756 */ 3757 err = mv88e6xxx_stu_setup(chip); 3758 if (err) 3759 goto unlock; 3760 3761 /* Setup Switch Port Registers */ 3762 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) { 3763 if (dsa_is_unused_port(ds, i)) 3764 continue; 3765 3766 /* Prevent the use of an invalid port. */ 3767 if (mv88e6xxx_is_invalid_port(chip, i)) { 3768 dev_err(chip->dev, "port %d is invalid\n", i); 3769 err = -EINVAL; 3770 goto unlock; 3771 } 3772 3773 err = mv88e6xxx_setup_port(chip, i); 3774 if (err) 3775 goto unlock; 3776 } 3777 3778 err = mv88e6xxx_irl_setup(chip); 3779 if (err) 3780 goto unlock; 3781 3782 err = mv88e6xxx_mac_setup(chip); 3783 if (err) 3784 goto unlock; 3785 3786 err = mv88e6xxx_phy_setup(chip); 3787 if (err) 3788 goto unlock; 3789 3790 err = mv88e6xxx_pvt_setup(chip); 3791 if (err) 3792 goto unlock; 3793 3794 err = mv88e6xxx_atu_setup(chip); 3795 if (err) 3796 goto unlock; 3797 3798 err = mv88e6xxx_broadcast_setup(chip, 0); 3799 if (err) 3800 goto unlock; 3801 3802 err = mv88e6xxx_pot_setup(chip); 3803 if (err) 3804 goto unlock; 3805 3806 err = mv88e6xxx_rmu_setup(chip); 3807 if (err) 3808 goto unlock; 3809 3810 err = mv88e6xxx_rsvd2cpu_setup(chip); 3811 if (err) 3812 goto unlock; 3813 3814 err = mv88e6xxx_trunk_setup(chip); 3815 if (err) 3816 goto unlock; 3817 3818 err = mv88e6xxx_devmap_setup(chip); 3819 if (err) 3820 goto unlock; 3821 3822 err = mv88e6xxx_pri_setup(chip); 3823 if (err) 3824 goto unlock; 3825 3826 /* Setup PTP Hardware Clock and timestamping */ 3827 if (chip->info->ptp_support) { 3828 err = mv88e6xxx_ptp_setup(chip); 3829 if (err) 3830 goto unlock; 3831 3832 err = mv88e6xxx_hwtstamp_setup(chip); 3833 if (err) 3834 goto unlock; 3835 } 3836 3837 err = mv88e6xxx_stats_setup(chip); 3838 if (err) 3839 goto unlock; 3840 3841 unlock: 3842 mv88e6xxx_reg_unlock(chip); 3843 3844 if (err) 3845 goto out_mdios; 3846 3847 /* Have to be called without holding the register lock, since 3848 * they take the devlink lock, and we later take the locks in 3849 * the reverse order when getting/setting parameters or 3850 * resource occupancy. 3851 */ 3852 err = mv88e6xxx_setup_devlink_resources(ds); 3853 if (err) 3854 goto out_mdios; 3855 3856 err = mv88e6xxx_setup_devlink_params(ds); 3857 if (err) 3858 goto out_resources; 3859 3860 err = mv88e6xxx_setup_devlink_regions_global(ds); 3861 if (err) 3862 goto out_params; 3863 3864 return 0; 3865 3866 out_params: 3867 mv88e6xxx_teardown_devlink_params(ds); 3868 out_resources: 3869 dsa_devlink_resources_unregister(ds); 3870 out_mdios: 3871 mv88e6xxx_mdios_unregister(chip); 3872 3873 return err; 3874 } 3875 3876 static int mv88e6xxx_port_setup(struct dsa_switch *ds, int port) 3877 { 3878 struct mv88e6xxx_chip *chip = ds->priv; 3879 int err; 3880 3881 if (chip->info->ops->pcs_ops->pcs_init) { 3882 err = chip->info->ops->pcs_ops->pcs_init(chip, port); 3883 if (err) 3884 return err; 3885 } 3886 3887 return mv88e6xxx_setup_devlink_regions_port(ds, port); 3888 } 3889 3890 static void mv88e6xxx_port_teardown(struct dsa_switch *ds, int port) 3891 { 3892 struct mv88e6xxx_chip *chip = ds->priv; 3893 3894 mv88e6xxx_teardown_devlink_regions_port(ds, port); 3895 3896 if (chip->info->ops->pcs_ops->pcs_teardown) 3897 chip->info->ops->pcs_ops->pcs_teardown(chip, port); 3898 } 3899 3900 static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds) 3901 { 3902 struct mv88e6xxx_chip *chip = ds->priv; 3903 3904 return chip->eeprom_len; 3905 } 3906 3907 static int mv88e6xxx_get_eeprom(struct dsa_switch *ds, 3908 struct ethtool_eeprom *eeprom, u8 *data) 3909 { 3910 struct mv88e6xxx_chip *chip = ds->priv; 3911 int err; 3912 3913 if (!chip->info->ops->get_eeprom) 3914 return -EOPNOTSUPP; 3915 3916 mv88e6xxx_reg_lock(chip); 3917 err = chip->info->ops->get_eeprom(chip, eeprom, data); 3918 mv88e6xxx_reg_unlock(chip); 3919 3920 if (err) 3921 return err; 3922 3923 eeprom->magic = 0xc3ec4951; 3924 3925 return 0; 3926 } 3927 3928 static int mv88e6xxx_set_eeprom(struct dsa_switch *ds, 3929 struct ethtool_eeprom *eeprom, u8 *data) 3930 { 3931 struct mv88e6xxx_chip *chip = ds->priv; 3932 int err; 3933 3934 if (!chip->info->ops->set_eeprom) 3935 return -EOPNOTSUPP; 3936 3937 if (eeprom->magic != 0xc3ec4951) 3938 return -EINVAL; 3939 3940 mv88e6xxx_reg_lock(chip); 3941 err = chip->info->ops->set_eeprom(chip, eeprom, data); 3942 mv88e6xxx_reg_unlock(chip); 3943 3944 return err; 3945 } 3946 3947 static const struct mv88e6xxx_ops mv88e6085_ops = { 3948 /* MV88E6XXX_FAMILY_6097 */ 3949 .ieee_pri_map = mv88e6085_g1_ieee_pri_map, 3950 .ip_pri_map = mv88e6085_g1_ip_pri_map, 3951 .irl_init_all = mv88e6352_g2_irl_init_all, 3952 .set_switch_mac = mv88e6xxx_g1_set_switch_mac, 3953 .phy_read = mv88e6185_phy_ppu_read, 3954 .phy_write = mv88e6185_phy_ppu_write, 3955 .port_set_link = mv88e6xxx_port_set_link, 3956 .port_sync_link = mv88e6xxx_port_sync_link, 3957 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex, 3958 .port_tag_remap = mv88e6095_port_tag_remap, 3959 .port_set_policy = mv88e6352_port_set_policy, 3960 .port_set_frame_mode = mv88e6351_port_set_frame_mode, 3961 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood, 3962 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood, 3963 .port_set_ether_type = mv88e6351_port_set_ether_type, 3964 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, 3965 .port_pause_limit = mv88e6097_port_pause_limit, 3966 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit, 3967 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, 3968 .port_get_cmode = mv88e6185_port_get_cmode, 3969 .port_setup_message_port = mv88e6xxx_setup_message_port, 3970 .stats_snapshot = mv88e6xxx_g1_stats_snapshot, 3971 .stats_set_histogram = mv88e6095_g1_stats_set_histogram, 3972 .stats_get_sset_count = mv88e6095_stats_get_sset_count, 3973 .stats_get_strings = mv88e6095_stats_get_strings, 3974 .stats_get_stats = mv88e6095_stats_get_stats, 3975 .set_cpu_port = mv88e6095_g1_set_cpu_port, 3976 .set_egress_port = mv88e6095_g1_set_egress_port, 3977 .watchdog_ops = &mv88e6097_watchdog_ops, 3978 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu, 3979 .pot_clear = mv88e6xxx_g2_pot_clear, 3980 .ppu_enable = mv88e6185_g1_ppu_enable, 3981 .ppu_disable = mv88e6185_g1_ppu_disable, 3982 .reset = mv88e6185_g1_reset, 3983 .rmu_disable = mv88e6085_g1_rmu_disable, 3984 .vtu_getnext = mv88e6352_g1_vtu_getnext, 3985 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge, 3986 .stu_getnext = mv88e6352_g1_stu_getnext, 3987 .stu_loadpurge = mv88e6352_g1_stu_loadpurge, 3988 .phylink_get_caps = mv88e6185_phylink_get_caps, 3989 .set_max_frame_size = mv88e6185_g1_set_max_frame_size, 3990 }; 3991 3992 static const struct mv88e6xxx_ops mv88e6095_ops = { 3993 /* MV88E6XXX_FAMILY_6095 */ 3994 .ieee_pri_map = mv88e6085_g1_ieee_pri_map, 3995 .ip_pri_map = mv88e6085_g1_ip_pri_map, 3996 .set_switch_mac = mv88e6xxx_g1_set_switch_mac, 3997 .phy_read = mv88e6185_phy_ppu_read, 3998 .phy_write = mv88e6185_phy_ppu_write, 3999 .port_set_link = mv88e6xxx_port_set_link, 4000 .port_sync_link = mv88e6185_port_sync_link, 4001 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex, 4002 .port_set_frame_mode = mv88e6085_port_set_frame_mode, 4003 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown, 4004 .port_set_mcast_flood = mv88e6185_port_set_default_forward, 4005 .port_set_upstream_port = mv88e6095_port_set_upstream_port, 4006 .port_get_cmode = mv88e6185_port_get_cmode, 4007 .port_setup_message_port = mv88e6xxx_setup_message_port, 4008 .stats_snapshot = mv88e6xxx_g1_stats_snapshot, 4009 .stats_set_histogram = mv88e6095_g1_stats_set_histogram, 4010 .stats_get_sset_count = mv88e6095_stats_get_sset_count, 4011 .stats_get_strings = mv88e6095_stats_get_strings, 4012 .stats_get_stats = mv88e6095_stats_get_stats, 4013 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu, 4014 .ppu_enable = mv88e6185_g1_ppu_enable, 4015 .ppu_disable = mv88e6185_g1_ppu_disable, 4016 .reset = mv88e6185_g1_reset, 4017 .vtu_getnext = mv88e6185_g1_vtu_getnext, 4018 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge, 4019 .phylink_get_caps = mv88e6095_phylink_get_caps, 4020 .pcs_ops = &mv88e6185_pcs_ops, 4021 .set_max_frame_size = mv88e6185_g1_set_max_frame_size, 4022 }; 4023 4024 static const struct mv88e6xxx_ops mv88e6097_ops = { 4025 /* MV88E6XXX_FAMILY_6097 */ 4026 .ieee_pri_map = mv88e6085_g1_ieee_pri_map, 4027 .ip_pri_map = mv88e6085_g1_ip_pri_map, 4028 .irl_init_all = mv88e6352_g2_irl_init_all, 4029 .set_switch_mac = mv88e6xxx_g2_set_switch_mac, 4030 .phy_read = mv88e6xxx_g2_smi_phy_read_c22, 4031 .phy_write = mv88e6xxx_g2_smi_phy_write_c22, 4032 .phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45, 4033 .phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45, 4034 .port_set_link = mv88e6xxx_port_set_link, 4035 .port_sync_link = mv88e6185_port_sync_link, 4036 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex, 4037 .port_tag_remap = mv88e6095_port_tag_remap, 4038 .port_set_policy = mv88e6352_port_set_policy, 4039 .port_set_frame_mode = mv88e6351_port_set_frame_mode, 4040 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood, 4041 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood, 4042 .port_set_ether_type = mv88e6351_port_set_ether_type, 4043 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting, 4044 .port_pause_limit = mv88e6097_port_pause_limit, 4045 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit, 4046 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, 4047 .port_get_cmode = mv88e6185_port_get_cmode, 4048 .port_setup_message_port = mv88e6xxx_setup_message_port, 4049 .stats_snapshot = mv88e6xxx_g1_stats_snapshot, 4050 .stats_set_histogram = mv88e6095_g1_stats_set_histogram, 4051 .stats_get_sset_count = mv88e6095_stats_get_sset_count, 4052 .stats_get_strings = mv88e6095_stats_get_strings, 4053 .stats_get_stats = mv88e6095_stats_get_stats, 4054 .set_cpu_port = mv88e6095_g1_set_cpu_port, 4055 .set_egress_port = mv88e6095_g1_set_egress_port, 4056 .watchdog_ops = &mv88e6097_watchdog_ops, 4057 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu, 4058 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping, 4059 .pot_clear = mv88e6xxx_g2_pot_clear, 4060 .reset = mv88e6352_g1_reset, 4061 .rmu_disable = mv88e6085_g1_rmu_disable, 4062 .vtu_getnext = mv88e6352_g1_vtu_getnext, 4063 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge, 4064 .phylink_get_caps = mv88e6095_phylink_get_caps, 4065 .pcs_ops = &mv88e6185_pcs_ops, 4066 .stu_getnext = mv88e6352_g1_stu_getnext, 4067 .stu_loadpurge = mv88e6352_g1_stu_loadpurge, 4068 .set_max_frame_size = mv88e6185_g1_set_max_frame_size, 4069 }; 4070 4071 static const struct mv88e6xxx_ops mv88e6123_ops = { 4072 /* MV88E6XXX_FAMILY_6165 */ 4073 .ieee_pri_map = mv88e6085_g1_ieee_pri_map, 4074 .ip_pri_map = mv88e6085_g1_ip_pri_map, 4075 .irl_init_all = mv88e6352_g2_irl_init_all, 4076 .set_switch_mac = mv88e6xxx_g2_set_switch_mac, 4077 .phy_read = mv88e6xxx_g2_smi_phy_read_c22, 4078 .phy_write = mv88e6xxx_g2_smi_phy_write_c22, 4079 .phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45, 4080 .phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45, 4081 .port_set_link = mv88e6xxx_port_set_link, 4082 .port_sync_link = mv88e6xxx_port_sync_link, 4083 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex, 4084 .port_set_frame_mode = mv88e6085_port_set_frame_mode, 4085 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood, 4086 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood, 4087 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit, 4088 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, 4089 .port_get_cmode = mv88e6185_port_get_cmode, 4090 .port_setup_message_port = mv88e6xxx_setup_message_port, 4091 .stats_snapshot = mv88e6320_g1_stats_snapshot, 4092 .stats_set_histogram = mv88e6095_g1_stats_set_histogram, 4093 .stats_get_sset_count = mv88e6095_stats_get_sset_count, 4094 .stats_get_strings = mv88e6095_stats_get_strings, 4095 .stats_get_stats = mv88e6095_stats_get_stats, 4096 .set_cpu_port = mv88e6095_g1_set_cpu_port, 4097 .set_egress_port = mv88e6095_g1_set_egress_port, 4098 .watchdog_ops = &mv88e6097_watchdog_ops, 4099 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu, 4100 .pot_clear = mv88e6xxx_g2_pot_clear, 4101 .reset = mv88e6352_g1_reset, 4102 .atu_get_hash = mv88e6165_g1_atu_get_hash, 4103 .atu_set_hash = mv88e6165_g1_atu_set_hash, 4104 .vtu_getnext = mv88e6352_g1_vtu_getnext, 4105 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge, 4106 .stu_getnext = mv88e6352_g1_stu_getnext, 4107 .stu_loadpurge = mv88e6352_g1_stu_loadpurge, 4108 .phylink_get_caps = mv88e6185_phylink_get_caps, 4109 .set_max_frame_size = mv88e6185_g1_set_max_frame_size, 4110 }; 4111 4112 static const struct mv88e6xxx_ops mv88e6131_ops = { 4113 /* MV88E6XXX_FAMILY_6185 */ 4114 .ieee_pri_map = mv88e6085_g1_ieee_pri_map, 4115 .ip_pri_map = mv88e6085_g1_ip_pri_map, 4116 .set_switch_mac = mv88e6xxx_g1_set_switch_mac, 4117 .phy_read = mv88e6185_phy_ppu_read, 4118 .phy_write = mv88e6185_phy_ppu_write, 4119 .port_set_link = mv88e6xxx_port_set_link, 4120 .port_sync_link = mv88e6xxx_port_sync_link, 4121 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex, 4122 .port_tag_remap = mv88e6095_port_tag_remap, 4123 .port_set_frame_mode = mv88e6351_port_set_frame_mode, 4124 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown, 4125 .port_set_mcast_flood = mv88e6185_port_set_default_forward, 4126 .port_set_ether_type = mv88e6351_port_set_ether_type, 4127 .port_set_upstream_port = mv88e6095_port_set_upstream_port, 4128 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size, 4129 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, 4130 .port_pause_limit = mv88e6097_port_pause_limit, 4131 .port_set_pause = mv88e6185_port_set_pause, 4132 .port_get_cmode = mv88e6185_port_get_cmode, 4133 .port_setup_message_port = mv88e6xxx_setup_message_port, 4134 .stats_snapshot = mv88e6xxx_g1_stats_snapshot, 4135 .stats_set_histogram = mv88e6095_g1_stats_set_histogram, 4136 .stats_get_sset_count = mv88e6095_stats_get_sset_count, 4137 .stats_get_strings = mv88e6095_stats_get_strings, 4138 .stats_get_stats = mv88e6095_stats_get_stats, 4139 .set_cpu_port = mv88e6095_g1_set_cpu_port, 4140 .set_egress_port = mv88e6095_g1_set_egress_port, 4141 .watchdog_ops = &mv88e6097_watchdog_ops, 4142 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu, 4143 .ppu_enable = mv88e6185_g1_ppu_enable, 4144 .set_cascade_port = mv88e6185_g1_set_cascade_port, 4145 .ppu_disable = mv88e6185_g1_ppu_disable, 4146 .reset = mv88e6185_g1_reset, 4147 .vtu_getnext = mv88e6185_g1_vtu_getnext, 4148 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge, 4149 .phylink_get_caps = mv88e6185_phylink_get_caps, 4150 }; 4151 4152 static const struct mv88e6xxx_ops mv88e6141_ops = { 4153 /* MV88E6XXX_FAMILY_6341 */ 4154 .ieee_pri_map = mv88e6085_g1_ieee_pri_map, 4155 .ip_pri_map = mv88e6085_g1_ip_pri_map, 4156 .irl_init_all = mv88e6352_g2_irl_init_all, 4157 .get_eeprom = mv88e6xxx_g2_get_eeprom8, 4158 .set_eeprom = mv88e6xxx_g2_set_eeprom8, 4159 .set_switch_mac = mv88e6xxx_g2_set_switch_mac, 4160 .phy_read = mv88e6xxx_g2_smi_phy_read_c22, 4161 .phy_write = mv88e6xxx_g2_smi_phy_write_c22, 4162 .phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45, 4163 .phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45, 4164 .port_set_link = mv88e6xxx_port_set_link, 4165 .port_sync_link = mv88e6xxx_port_sync_link, 4166 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay, 4167 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex, 4168 .port_max_speed_mode = mv88e6341_port_max_speed_mode, 4169 .port_tag_remap = mv88e6095_port_tag_remap, 4170 .port_set_policy = mv88e6352_port_set_policy, 4171 .port_set_frame_mode = mv88e6351_port_set_frame_mode, 4172 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood, 4173 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood, 4174 .port_set_ether_type = mv88e6351_port_set_ether_type, 4175 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size, 4176 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, 4177 .port_pause_limit = mv88e6097_port_pause_limit, 4178 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit, 4179 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, 4180 .port_get_cmode = mv88e6352_port_get_cmode, 4181 .port_set_cmode = mv88e6341_port_set_cmode, 4182 .port_setup_message_port = mv88e6xxx_setup_message_port, 4183 .stats_snapshot = mv88e6390_g1_stats_snapshot, 4184 .stats_set_histogram = mv88e6390_g1_stats_set_histogram, 4185 .stats_get_sset_count = mv88e6320_stats_get_sset_count, 4186 .stats_get_strings = mv88e6320_stats_get_strings, 4187 .stats_get_stats = mv88e6390_stats_get_stats, 4188 .set_cpu_port = mv88e6390_g1_set_cpu_port, 4189 .set_egress_port = mv88e6390_g1_set_egress_port, 4190 .watchdog_ops = &mv88e6390_watchdog_ops, 4191 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu, 4192 .pot_clear = mv88e6xxx_g2_pot_clear, 4193 .reset = mv88e6352_g1_reset, 4194 .rmu_disable = mv88e6390_g1_rmu_disable, 4195 .atu_get_hash = mv88e6165_g1_atu_get_hash, 4196 .atu_set_hash = mv88e6165_g1_atu_set_hash, 4197 .vtu_getnext = mv88e6352_g1_vtu_getnext, 4198 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge, 4199 .stu_getnext = mv88e6352_g1_stu_getnext, 4200 .stu_loadpurge = mv88e6352_g1_stu_loadpurge, 4201 .serdes_get_lane = mv88e6341_serdes_get_lane, 4202 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping, 4203 .gpio_ops = &mv88e6352_gpio_ops, 4204 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count, 4205 .serdes_get_strings = mv88e6390_serdes_get_strings, 4206 .serdes_get_stats = mv88e6390_serdes_get_stats, 4207 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len, 4208 .serdes_get_regs = mv88e6390_serdes_get_regs, 4209 .phylink_get_caps = mv88e6341_phylink_get_caps, 4210 .pcs_ops = &mv88e6390_pcs_ops, 4211 }; 4212 4213 static const struct mv88e6xxx_ops mv88e6161_ops = { 4214 /* MV88E6XXX_FAMILY_6165 */ 4215 .ieee_pri_map = mv88e6085_g1_ieee_pri_map, 4216 .ip_pri_map = mv88e6085_g1_ip_pri_map, 4217 .irl_init_all = mv88e6352_g2_irl_init_all, 4218 .set_switch_mac = mv88e6xxx_g2_set_switch_mac, 4219 .phy_read = mv88e6xxx_g2_smi_phy_read_c22, 4220 .phy_write = mv88e6xxx_g2_smi_phy_write_c22, 4221 .phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45, 4222 .phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45, 4223 .port_set_link = mv88e6xxx_port_set_link, 4224 .port_sync_link = mv88e6xxx_port_sync_link, 4225 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex, 4226 .port_tag_remap = mv88e6095_port_tag_remap, 4227 .port_set_policy = mv88e6352_port_set_policy, 4228 .port_set_frame_mode = mv88e6351_port_set_frame_mode, 4229 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood, 4230 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood, 4231 .port_set_ether_type = mv88e6351_port_set_ether_type, 4232 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, 4233 .port_pause_limit = mv88e6097_port_pause_limit, 4234 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit, 4235 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, 4236 .port_get_cmode = mv88e6185_port_get_cmode, 4237 .port_setup_message_port = mv88e6xxx_setup_message_port, 4238 .stats_snapshot = mv88e6xxx_g1_stats_snapshot, 4239 .stats_set_histogram = mv88e6095_g1_stats_set_histogram, 4240 .stats_get_sset_count = mv88e6095_stats_get_sset_count, 4241 .stats_get_strings = mv88e6095_stats_get_strings, 4242 .stats_get_stats = mv88e6095_stats_get_stats, 4243 .set_cpu_port = mv88e6095_g1_set_cpu_port, 4244 .set_egress_port = mv88e6095_g1_set_egress_port, 4245 .watchdog_ops = &mv88e6097_watchdog_ops, 4246 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu, 4247 .pot_clear = mv88e6xxx_g2_pot_clear, 4248 .reset = mv88e6352_g1_reset, 4249 .atu_get_hash = mv88e6165_g1_atu_get_hash, 4250 .atu_set_hash = mv88e6165_g1_atu_set_hash, 4251 .vtu_getnext = mv88e6352_g1_vtu_getnext, 4252 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge, 4253 .stu_getnext = mv88e6352_g1_stu_getnext, 4254 .stu_loadpurge = mv88e6352_g1_stu_loadpurge, 4255 .avb_ops = &mv88e6165_avb_ops, 4256 .ptp_ops = &mv88e6165_ptp_ops, 4257 .phylink_get_caps = mv88e6185_phylink_get_caps, 4258 .set_max_frame_size = mv88e6185_g1_set_max_frame_size, 4259 }; 4260 4261 static const struct mv88e6xxx_ops mv88e6165_ops = { 4262 /* MV88E6XXX_FAMILY_6165 */ 4263 .ieee_pri_map = mv88e6085_g1_ieee_pri_map, 4264 .ip_pri_map = mv88e6085_g1_ip_pri_map, 4265 .irl_init_all = mv88e6352_g2_irl_init_all, 4266 .set_switch_mac = mv88e6xxx_g2_set_switch_mac, 4267 .phy_read = mv88e6165_phy_read, 4268 .phy_write = mv88e6165_phy_write, 4269 .port_set_link = mv88e6xxx_port_set_link, 4270 .port_sync_link = mv88e6xxx_port_sync_link, 4271 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex, 4272 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit, 4273 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, 4274 .port_get_cmode = mv88e6185_port_get_cmode, 4275 .port_setup_message_port = mv88e6xxx_setup_message_port, 4276 .stats_snapshot = mv88e6xxx_g1_stats_snapshot, 4277 .stats_set_histogram = mv88e6095_g1_stats_set_histogram, 4278 .stats_get_sset_count = mv88e6095_stats_get_sset_count, 4279 .stats_get_strings = mv88e6095_stats_get_strings, 4280 .stats_get_stats = mv88e6095_stats_get_stats, 4281 .set_cpu_port = mv88e6095_g1_set_cpu_port, 4282 .set_egress_port = mv88e6095_g1_set_egress_port, 4283 .watchdog_ops = &mv88e6097_watchdog_ops, 4284 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu, 4285 .pot_clear = mv88e6xxx_g2_pot_clear, 4286 .reset = mv88e6352_g1_reset, 4287 .atu_get_hash = mv88e6165_g1_atu_get_hash, 4288 .atu_set_hash = mv88e6165_g1_atu_set_hash, 4289 .vtu_getnext = mv88e6352_g1_vtu_getnext, 4290 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge, 4291 .stu_getnext = mv88e6352_g1_stu_getnext, 4292 .stu_loadpurge = mv88e6352_g1_stu_loadpurge, 4293 .avb_ops = &mv88e6165_avb_ops, 4294 .ptp_ops = &mv88e6165_ptp_ops, 4295 .phylink_get_caps = mv88e6185_phylink_get_caps, 4296 }; 4297 4298 static const struct mv88e6xxx_ops mv88e6171_ops = { 4299 /* MV88E6XXX_FAMILY_6351 */ 4300 .ieee_pri_map = mv88e6085_g1_ieee_pri_map, 4301 .ip_pri_map = mv88e6085_g1_ip_pri_map, 4302 .irl_init_all = mv88e6352_g2_irl_init_all, 4303 .set_switch_mac = mv88e6xxx_g2_set_switch_mac, 4304 .phy_read = mv88e6xxx_g2_smi_phy_read_c22, 4305 .phy_write = mv88e6xxx_g2_smi_phy_write_c22, 4306 .phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45, 4307 .phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45, 4308 .port_set_link = mv88e6xxx_port_set_link, 4309 .port_sync_link = mv88e6xxx_port_sync_link, 4310 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay, 4311 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex, 4312 .port_tag_remap = mv88e6095_port_tag_remap, 4313 .port_set_frame_mode = mv88e6351_port_set_frame_mode, 4314 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood, 4315 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood, 4316 .port_set_ether_type = mv88e6351_port_set_ether_type, 4317 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size, 4318 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, 4319 .port_pause_limit = mv88e6097_port_pause_limit, 4320 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit, 4321 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, 4322 .port_get_cmode = mv88e6352_port_get_cmode, 4323 .port_setup_message_port = mv88e6xxx_setup_message_port, 4324 .stats_snapshot = mv88e6320_g1_stats_snapshot, 4325 .stats_set_histogram = mv88e6095_g1_stats_set_histogram, 4326 .stats_get_sset_count = mv88e6095_stats_get_sset_count, 4327 .stats_get_strings = mv88e6095_stats_get_strings, 4328 .stats_get_stats = mv88e6095_stats_get_stats, 4329 .set_cpu_port = mv88e6095_g1_set_cpu_port, 4330 .set_egress_port = mv88e6095_g1_set_egress_port, 4331 .watchdog_ops = &mv88e6097_watchdog_ops, 4332 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu, 4333 .pot_clear = mv88e6xxx_g2_pot_clear, 4334 .reset = mv88e6352_g1_reset, 4335 .atu_get_hash = mv88e6165_g1_atu_get_hash, 4336 .atu_set_hash = mv88e6165_g1_atu_set_hash, 4337 .vtu_getnext = mv88e6352_g1_vtu_getnext, 4338 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge, 4339 .stu_getnext = mv88e6352_g1_stu_getnext, 4340 .stu_loadpurge = mv88e6352_g1_stu_loadpurge, 4341 .phylink_get_caps = mv88e6185_phylink_get_caps, 4342 }; 4343 4344 static const struct mv88e6xxx_ops mv88e6172_ops = { 4345 /* MV88E6XXX_FAMILY_6352 */ 4346 .ieee_pri_map = mv88e6085_g1_ieee_pri_map, 4347 .ip_pri_map = mv88e6085_g1_ip_pri_map, 4348 .irl_init_all = mv88e6352_g2_irl_init_all, 4349 .get_eeprom = mv88e6xxx_g2_get_eeprom16, 4350 .set_eeprom = mv88e6xxx_g2_set_eeprom16, 4351 .set_switch_mac = mv88e6xxx_g2_set_switch_mac, 4352 .phy_read = mv88e6xxx_g2_smi_phy_read_c22, 4353 .phy_write = mv88e6xxx_g2_smi_phy_write_c22, 4354 .phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45, 4355 .phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45, 4356 .port_set_link = mv88e6xxx_port_set_link, 4357 .port_sync_link = mv88e6xxx_port_sync_link, 4358 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay, 4359 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex, 4360 .port_tag_remap = mv88e6095_port_tag_remap, 4361 .port_set_policy = mv88e6352_port_set_policy, 4362 .port_set_frame_mode = mv88e6351_port_set_frame_mode, 4363 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood, 4364 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood, 4365 .port_set_ether_type = mv88e6351_port_set_ether_type, 4366 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size, 4367 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, 4368 .port_pause_limit = mv88e6097_port_pause_limit, 4369 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit, 4370 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, 4371 .port_get_cmode = mv88e6352_port_get_cmode, 4372 .port_setup_message_port = mv88e6xxx_setup_message_port, 4373 .stats_snapshot = mv88e6320_g1_stats_snapshot, 4374 .stats_set_histogram = mv88e6095_g1_stats_set_histogram, 4375 .stats_get_sset_count = mv88e6095_stats_get_sset_count, 4376 .stats_get_strings = mv88e6095_stats_get_strings, 4377 .stats_get_stats = mv88e6095_stats_get_stats, 4378 .set_cpu_port = mv88e6095_g1_set_cpu_port, 4379 .set_egress_port = mv88e6095_g1_set_egress_port, 4380 .watchdog_ops = &mv88e6097_watchdog_ops, 4381 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu, 4382 .pot_clear = mv88e6xxx_g2_pot_clear, 4383 .reset = mv88e6352_g1_reset, 4384 .rmu_disable = mv88e6352_g1_rmu_disable, 4385 .atu_get_hash = mv88e6165_g1_atu_get_hash, 4386 .atu_set_hash = mv88e6165_g1_atu_set_hash, 4387 .vtu_getnext = mv88e6352_g1_vtu_getnext, 4388 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge, 4389 .stu_getnext = mv88e6352_g1_stu_getnext, 4390 .stu_loadpurge = mv88e6352_g1_stu_loadpurge, 4391 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len, 4392 .serdes_get_regs = mv88e6352_serdes_get_regs, 4393 .gpio_ops = &mv88e6352_gpio_ops, 4394 .phylink_get_caps = mv88e6352_phylink_get_caps, 4395 .pcs_ops = &mv88e6352_pcs_ops, 4396 }; 4397 4398 static const struct mv88e6xxx_ops mv88e6175_ops = { 4399 /* MV88E6XXX_FAMILY_6351 */ 4400 .ieee_pri_map = mv88e6085_g1_ieee_pri_map, 4401 .ip_pri_map = mv88e6085_g1_ip_pri_map, 4402 .irl_init_all = mv88e6352_g2_irl_init_all, 4403 .set_switch_mac = mv88e6xxx_g2_set_switch_mac, 4404 .phy_read = mv88e6xxx_g2_smi_phy_read_c22, 4405 .phy_write = mv88e6xxx_g2_smi_phy_write_c22, 4406 .phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45, 4407 .phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45, 4408 .port_set_link = mv88e6xxx_port_set_link, 4409 .port_sync_link = mv88e6xxx_port_sync_link, 4410 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay, 4411 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex, 4412 .port_tag_remap = mv88e6095_port_tag_remap, 4413 .port_set_frame_mode = mv88e6351_port_set_frame_mode, 4414 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood, 4415 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood, 4416 .port_set_ether_type = mv88e6351_port_set_ether_type, 4417 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size, 4418 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, 4419 .port_pause_limit = mv88e6097_port_pause_limit, 4420 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit, 4421 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, 4422 .port_get_cmode = mv88e6352_port_get_cmode, 4423 .port_setup_message_port = mv88e6xxx_setup_message_port, 4424 .stats_snapshot = mv88e6320_g1_stats_snapshot, 4425 .stats_set_histogram = mv88e6095_g1_stats_set_histogram, 4426 .stats_get_sset_count = mv88e6095_stats_get_sset_count, 4427 .stats_get_strings = mv88e6095_stats_get_strings, 4428 .stats_get_stats = mv88e6095_stats_get_stats, 4429 .set_cpu_port = mv88e6095_g1_set_cpu_port, 4430 .set_egress_port = mv88e6095_g1_set_egress_port, 4431 .watchdog_ops = &mv88e6097_watchdog_ops, 4432 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu, 4433 .pot_clear = mv88e6xxx_g2_pot_clear, 4434 .reset = mv88e6352_g1_reset, 4435 .atu_get_hash = mv88e6165_g1_atu_get_hash, 4436 .atu_set_hash = mv88e6165_g1_atu_set_hash, 4437 .vtu_getnext = mv88e6352_g1_vtu_getnext, 4438 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge, 4439 .stu_getnext = mv88e6352_g1_stu_getnext, 4440 .stu_loadpurge = mv88e6352_g1_stu_loadpurge, 4441 .phylink_get_caps = mv88e6185_phylink_get_caps, 4442 }; 4443 4444 static const struct mv88e6xxx_ops mv88e6176_ops = { 4445 /* MV88E6XXX_FAMILY_6352 */ 4446 .ieee_pri_map = mv88e6085_g1_ieee_pri_map, 4447 .ip_pri_map = mv88e6085_g1_ip_pri_map, 4448 .irl_init_all = mv88e6352_g2_irl_init_all, 4449 .get_eeprom = mv88e6xxx_g2_get_eeprom16, 4450 .set_eeprom = mv88e6xxx_g2_set_eeprom16, 4451 .set_switch_mac = mv88e6xxx_g2_set_switch_mac, 4452 .phy_read = mv88e6xxx_g2_smi_phy_read_c22, 4453 .phy_write = mv88e6xxx_g2_smi_phy_write_c22, 4454 .phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45, 4455 .phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45, 4456 .port_set_link = mv88e6xxx_port_set_link, 4457 .port_sync_link = mv88e6xxx_port_sync_link, 4458 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay, 4459 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex, 4460 .port_tag_remap = mv88e6095_port_tag_remap, 4461 .port_set_policy = mv88e6352_port_set_policy, 4462 .port_set_frame_mode = mv88e6351_port_set_frame_mode, 4463 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood, 4464 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood, 4465 .port_set_ether_type = mv88e6351_port_set_ether_type, 4466 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size, 4467 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, 4468 .port_pause_limit = mv88e6097_port_pause_limit, 4469 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit, 4470 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, 4471 .port_get_cmode = mv88e6352_port_get_cmode, 4472 .port_setup_message_port = mv88e6xxx_setup_message_port, 4473 .stats_snapshot = mv88e6320_g1_stats_snapshot, 4474 .stats_set_histogram = mv88e6095_g1_stats_set_histogram, 4475 .stats_get_sset_count = mv88e6095_stats_get_sset_count, 4476 .stats_get_strings = mv88e6095_stats_get_strings, 4477 .stats_get_stats = mv88e6095_stats_get_stats, 4478 .set_cpu_port = mv88e6095_g1_set_cpu_port, 4479 .set_egress_port = mv88e6095_g1_set_egress_port, 4480 .watchdog_ops = &mv88e6097_watchdog_ops, 4481 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu, 4482 .pot_clear = mv88e6xxx_g2_pot_clear, 4483 .reset = mv88e6352_g1_reset, 4484 .rmu_disable = mv88e6352_g1_rmu_disable, 4485 .atu_get_hash = mv88e6165_g1_atu_get_hash, 4486 .atu_set_hash = mv88e6165_g1_atu_set_hash, 4487 .vtu_getnext = mv88e6352_g1_vtu_getnext, 4488 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge, 4489 .stu_getnext = mv88e6352_g1_stu_getnext, 4490 .stu_loadpurge = mv88e6352_g1_stu_loadpurge, 4491 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping, 4492 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len, 4493 .serdes_get_regs = mv88e6352_serdes_get_regs, 4494 .serdes_set_tx_amplitude = mv88e6352_serdes_set_tx_amplitude, 4495 .gpio_ops = &mv88e6352_gpio_ops, 4496 .phylink_get_caps = mv88e6352_phylink_get_caps, 4497 .pcs_ops = &mv88e6352_pcs_ops, 4498 }; 4499 4500 static const struct mv88e6xxx_ops mv88e6185_ops = { 4501 /* MV88E6XXX_FAMILY_6185 */ 4502 .ieee_pri_map = mv88e6085_g1_ieee_pri_map, 4503 .ip_pri_map = mv88e6085_g1_ip_pri_map, 4504 .set_switch_mac = mv88e6xxx_g1_set_switch_mac, 4505 .phy_read = mv88e6185_phy_ppu_read, 4506 .phy_write = mv88e6185_phy_ppu_write, 4507 .port_set_link = mv88e6xxx_port_set_link, 4508 .port_sync_link = mv88e6185_port_sync_link, 4509 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex, 4510 .port_set_frame_mode = mv88e6085_port_set_frame_mode, 4511 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown, 4512 .port_set_mcast_flood = mv88e6185_port_set_default_forward, 4513 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting, 4514 .port_set_upstream_port = mv88e6095_port_set_upstream_port, 4515 .port_set_pause = mv88e6185_port_set_pause, 4516 .port_get_cmode = mv88e6185_port_get_cmode, 4517 .port_setup_message_port = mv88e6xxx_setup_message_port, 4518 .stats_snapshot = mv88e6xxx_g1_stats_snapshot, 4519 .stats_set_histogram = mv88e6095_g1_stats_set_histogram, 4520 .stats_get_sset_count = mv88e6095_stats_get_sset_count, 4521 .stats_get_strings = mv88e6095_stats_get_strings, 4522 .stats_get_stats = mv88e6095_stats_get_stats, 4523 .set_cpu_port = mv88e6095_g1_set_cpu_port, 4524 .set_egress_port = mv88e6095_g1_set_egress_port, 4525 .watchdog_ops = &mv88e6097_watchdog_ops, 4526 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu, 4527 .set_cascade_port = mv88e6185_g1_set_cascade_port, 4528 .ppu_enable = mv88e6185_g1_ppu_enable, 4529 .ppu_disable = mv88e6185_g1_ppu_disable, 4530 .reset = mv88e6185_g1_reset, 4531 .vtu_getnext = mv88e6185_g1_vtu_getnext, 4532 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge, 4533 .phylink_get_caps = mv88e6185_phylink_get_caps, 4534 .pcs_ops = &mv88e6185_pcs_ops, 4535 .set_max_frame_size = mv88e6185_g1_set_max_frame_size, 4536 }; 4537 4538 static const struct mv88e6xxx_ops mv88e6190_ops = { 4539 /* MV88E6XXX_FAMILY_6390 */ 4540 .setup_errata = mv88e6390_setup_errata, 4541 .irl_init_all = mv88e6390_g2_irl_init_all, 4542 .get_eeprom = mv88e6xxx_g2_get_eeprom8, 4543 .set_eeprom = mv88e6xxx_g2_set_eeprom8, 4544 .set_switch_mac = mv88e6xxx_g2_set_switch_mac, 4545 .phy_read = mv88e6xxx_g2_smi_phy_read_c22, 4546 .phy_write = mv88e6xxx_g2_smi_phy_write_c22, 4547 .phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45, 4548 .phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45, 4549 .port_set_link = mv88e6xxx_port_set_link, 4550 .port_sync_link = mv88e6xxx_port_sync_link, 4551 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay, 4552 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex, 4553 .port_max_speed_mode = mv88e6390_port_max_speed_mode, 4554 .port_tag_remap = mv88e6390_port_tag_remap, 4555 .port_set_policy = mv88e6352_port_set_policy, 4556 .port_set_frame_mode = mv88e6351_port_set_frame_mode, 4557 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood, 4558 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood, 4559 .port_set_ether_type = mv88e6351_port_set_ether_type, 4560 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size, 4561 .port_pause_limit = mv88e6390_port_pause_limit, 4562 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit, 4563 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, 4564 .port_get_cmode = mv88e6352_port_get_cmode, 4565 .port_set_cmode = mv88e6390_port_set_cmode, 4566 .port_setup_message_port = mv88e6xxx_setup_message_port, 4567 .stats_snapshot = mv88e6390_g1_stats_snapshot, 4568 .stats_set_histogram = mv88e6390_g1_stats_set_histogram, 4569 .stats_get_sset_count = mv88e6320_stats_get_sset_count, 4570 .stats_get_strings = mv88e6320_stats_get_strings, 4571 .stats_get_stats = mv88e6390_stats_get_stats, 4572 .set_cpu_port = mv88e6390_g1_set_cpu_port, 4573 .set_egress_port = mv88e6390_g1_set_egress_port, 4574 .watchdog_ops = &mv88e6390_watchdog_ops, 4575 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu, 4576 .pot_clear = mv88e6xxx_g2_pot_clear, 4577 .reset = mv88e6352_g1_reset, 4578 .rmu_disable = mv88e6390_g1_rmu_disable, 4579 .atu_get_hash = mv88e6165_g1_atu_get_hash, 4580 .atu_set_hash = mv88e6165_g1_atu_set_hash, 4581 .vtu_getnext = mv88e6390_g1_vtu_getnext, 4582 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge, 4583 .stu_getnext = mv88e6390_g1_stu_getnext, 4584 .stu_loadpurge = mv88e6390_g1_stu_loadpurge, 4585 .serdes_get_lane = mv88e6390_serdes_get_lane, 4586 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping, 4587 .serdes_get_strings = mv88e6390_serdes_get_strings, 4588 .serdes_get_stats = mv88e6390_serdes_get_stats, 4589 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len, 4590 .serdes_get_regs = mv88e6390_serdes_get_regs, 4591 .gpio_ops = &mv88e6352_gpio_ops, 4592 .phylink_get_caps = mv88e6390_phylink_get_caps, 4593 .pcs_ops = &mv88e6390_pcs_ops, 4594 }; 4595 4596 static const struct mv88e6xxx_ops mv88e6190x_ops = { 4597 /* MV88E6XXX_FAMILY_6390 */ 4598 .setup_errata = mv88e6390_setup_errata, 4599 .irl_init_all = mv88e6390_g2_irl_init_all, 4600 .get_eeprom = mv88e6xxx_g2_get_eeprom8, 4601 .set_eeprom = mv88e6xxx_g2_set_eeprom8, 4602 .set_switch_mac = mv88e6xxx_g2_set_switch_mac, 4603 .phy_read = mv88e6xxx_g2_smi_phy_read_c22, 4604 .phy_write = mv88e6xxx_g2_smi_phy_write_c22, 4605 .phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45, 4606 .phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45, 4607 .port_set_link = mv88e6xxx_port_set_link, 4608 .port_sync_link = mv88e6xxx_port_sync_link, 4609 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay, 4610 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex, 4611 .port_max_speed_mode = mv88e6390x_port_max_speed_mode, 4612 .port_tag_remap = mv88e6390_port_tag_remap, 4613 .port_set_policy = mv88e6352_port_set_policy, 4614 .port_set_frame_mode = mv88e6351_port_set_frame_mode, 4615 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood, 4616 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood, 4617 .port_set_ether_type = mv88e6351_port_set_ether_type, 4618 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size, 4619 .port_pause_limit = mv88e6390_port_pause_limit, 4620 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit, 4621 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, 4622 .port_get_cmode = mv88e6352_port_get_cmode, 4623 .port_set_cmode = mv88e6390x_port_set_cmode, 4624 .port_setup_message_port = mv88e6xxx_setup_message_port, 4625 .stats_snapshot = mv88e6390_g1_stats_snapshot, 4626 .stats_set_histogram = mv88e6390_g1_stats_set_histogram, 4627 .stats_get_sset_count = mv88e6320_stats_get_sset_count, 4628 .stats_get_strings = mv88e6320_stats_get_strings, 4629 .stats_get_stats = mv88e6390_stats_get_stats, 4630 .set_cpu_port = mv88e6390_g1_set_cpu_port, 4631 .set_egress_port = mv88e6390_g1_set_egress_port, 4632 .watchdog_ops = &mv88e6390_watchdog_ops, 4633 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu, 4634 .pot_clear = mv88e6xxx_g2_pot_clear, 4635 .reset = mv88e6352_g1_reset, 4636 .rmu_disable = mv88e6390_g1_rmu_disable, 4637 .atu_get_hash = mv88e6165_g1_atu_get_hash, 4638 .atu_set_hash = mv88e6165_g1_atu_set_hash, 4639 .vtu_getnext = mv88e6390_g1_vtu_getnext, 4640 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge, 4641 .stu_getnext = mv88e6390_g1_stu_getnext, 4642 .stu_loadpurge = mv88e6390_g1_stu_loadpurge, 4643 .serdes_get_lane = mv88e6390x_serdes_get_lane, 4644 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping, 4645 .serdes_get_strings = mv88e6390_serdes_get_strings, 4646 .serdes_get_stats = mv88e6390_serdes_get_stats, 4647 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len, 4648 .serdes_get_regs = mv88e6390_serdes_get_regs, 4649 .gpio_ops = &mv88e6352_gpio_ops, 4650 .phylink_get_caps = mv88e6390x_phylink_get_caps, 4651 .pcs_ops = &mv88e6390_pcs_ops, 4652 }; 4653 4654 static const struct mv88e6xxx_ops mv88e6191_ops = { 4655 /* MV88E6XXX_FAMILY_6390 */ 4656 .setup_errata = mv88e6390_setup_errata, 4657 .irl_init_all = mv88e6390_g2_irl_init_all, 4658 .get_eeprom = mv88e6xxx_g2_get_eeprom8, 4659 .set_eeprom = mv88e6xxx_g2_set_eeprom8, 4660 .set_switch_mac = mv88e6xxx_g2_set_switch_mac, 4661 .phy_read = mv88e6xxx_g2_smi_phy_read_c22, 4662 .phy_write = mv88e6xxx_g2_smi_phy_write_c22, 4663 .phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45, 4664 .phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45, 4665 .port_set_link = mv88e6xxx_port_set_link, 4666 .port_sync_link = mv88e6xxx_port_sync_link, 4667 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay, 4668 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex, 4669 .port_max_speed_mode = mv88e6390_port_max_speed_mode, 4670 .port_tag_remap = mv88e6390_port_tag_remap, 4671 .port_set_frame_mode = mv88e6351_port_set_frame_mode, 4672 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood, 4673 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood, 4674 .port_set_ether_type = mv88e6351_port_set_ether_type, 4675 .port_pause_limit = mv88e6390_port_pause_limit, 4676 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit, 4677 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, 4678 .port_get_cmode = mv88e6352_port_get_cmode, 4679 .port_set_cmode = mv88e6390_port_set_cmode, 4680 .port_setup_message_port = mv88e6xxx_setup_message_port, 4681 .stats_snapshot = mv88e6390_g1_stats_snapshot, 4682 .stats_set_histogram = mv88e6390_g1_stats_set_histogram, 4683 .stats_get_sset_count = mv88e6320_stats_get_sset_count, 4684 .stats_get_strings = mv88e6320_stats_get_strings, 4685 .stats_get_stats = mv88e6390_stats_get_stats, 4686 .set_cpu_port = mv88e6390_g1_set_cpu_port, 4687 .set_egress_port = mv88e6390_g1_set_egress_port, 4688 .watchdog_ops = &mv88e6390_watchdog_ops, 4689 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu, 4690 .pot_clear = mv88e6xxx_g2_pot_clear, 4691 .reset = mv88e6352_g1_reset, 4692 .rmu_disable = mv88e6390_g1_rmu_disable, 4693 .atu_get_hash = mv88e6165_g1_atu_get_hash, 4694 .atu_set_hash = mv88e6165_g1_atu_set_hash, 4695 .vtu_getnext = mv88e6390_g1_vtu_getnext, 4696 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge, 4697 .stu_getnext = mv88e6390_g1_stu_getnext, 4698 .stu_loadpurge = mv88e6390_g1_stu_loadpurge, 4699 .serdes_get_lane = mv88e6390_serdes_get_lane, 4700 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping, 4701 .serdes_get_strings = mv88e6390_serdes_get_strings, 4702 .serdes_get_stats = mv88e6390_serdes_get_stats, 4703 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len, 4704 .serdes_get_regs = mv88e6390_serdes_get_regs, 4705 .avb_ops = &mv88e6390_avb_ops, 4706 .ptp_ops = &mv88e6352_ptp_ops, 4707 .phylink_get_caps = mv88e6390_phylink_get_caps, 4708 .pcs_ops = &mv88e6390_pcs_ops, 4709 }; 4710 4711 static const struct mv88e6xxx_ops mv88e6240_ops = { 4712 /* MV88E6XXX_FAMILY_6352 */ 4713 .ieee_pri_map = mv88e6085_g1_ieee_pri_map, 4714 .ip_pri_map = mv88e6085_g1_ip_pri_map, 4715 .irl_init_all = mv88e6352_g2_irl_init_all, 4716 .get_eeprom = mv88e6xxx_g2_get_eeprom16, 4717 .set_eeprom = mv88e6xxx_g2_set_eeprom16, 4718 .set_switch_mac = mv88e6xxx_g2_set_switch_mac, 4719 .phy_read = mv88e6xxx_g2_smi_phy_read_c22, 4720 .phy_write = mv88e6xxx_g2_smi_phy_write_c22, 4721 .phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45, 4722 .phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45, 4723 .port_set_link = mv88e6xxx_port_set_link, 4724 .port_sync_link = mv88e6xxx_port_sync_link, 4725 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay, 4726 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex, 4727 .port_tag_remap = mv88e6095_port_tag_remap, 4728 .port_set_policy = mv88e6352_port_set_policy, 4729 .port_set_frame_mode = mv88e6351_port_set_frame_mode, 4730 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood, 4731 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood, 4732 .port_set_ether_type = mv88e6351_port_set_ether_type, 4733 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size, 4734 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, 4735 .port_pause_limit = mv88e6097_port_pause_limit, 4736 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit, 4737 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, 4738 .port_get_cmode = mv88e6352_port_get_cmode, 4739 .port_setup_message_port = mv88e6xxx_setup_message_port, 4740 .stats_snapshot = mv88e6320_g1_stats_snapshot, 4741 .stats_set_histogram = mv88e6095_g1_stats_set_histogram, 4742 .stats_get_sset_count = mv88e6095_stats_get_sset_count, 4743 .stats_get_strings = mv88e6095_stats_get_strings, 4744 .stats_get_stats = mv88e6095_stats_get_stats, 4745 .set_cpu_port = mv88e6095_g1_set_cpu_port, 4746 .set_egress_port = mv88e6095_g1_set_egress_port, 4747 .watchdog_ops = &mv88e6097_watchdog_ops, 4748 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu, 4749 .pot_clear = mv88e6xxx_g2_pot_clear, 4750 .reset = mv88e6352_g1_reset, 4751 .rmu_disable = mv88e6352_g1_rmu_disable, 4752 .atu_get_hash = mv88e6165_g1_atu_get_hash, 4753 .atu_set_hash = mv88e6165_g1_atu_set_hash, 4754 .vtu_getnext = mv88e6352_g1_vtu_getnext, 4755 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge, 4756 .stu_getnext = mv88e6352_g1_stu_getnext, 4757 .stu_loadpurge = mv88e6352_g1_stu_loadpurge, 4758 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping, 4759 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len, 4760 .serdes_get_regs = mv88e6352_serdes_get_regs, 4761 .serdes_set_tx_amplitude = mv88e6352_serdes_set_tx_amplitude, 4762 .gpio_ops = &mv88e6352_gpio_ops, 4763 .avb_ops = &mv88e6352_avb_ops, 4764 .ptp_ops = &mv88e6352_ptp_ops, 4765 .phylink_get_caps = mv88e6352_phylink_get_caps, 4766 .pcs_ops = &mv88e6352_pcs_ops, 4767 }; 4768 4769 static const struct mv88e6xxx_ops mv88e6250_ops = { 4770 /* MV88E6XXX_FAMILY_6250 */ 4771 .ieee_pri_map = mv88e6250_g1_ieee_pri_map, 4772 .ip_pri_map = mv88e6085_g1_ip_pri_map, 4773 .irl_init_all = mv88e6352_g2_irl_init_all, 4774 .get_eeprom = mv88e6xxx_g2_get_eeprom16, 4775 .set_eeprom = mv88e6xxx_g2_set_eeprom16, 4776 .set_switch_mac = mv88e6xxx_g2_set_switch_mac, 4777 .phy_read = mv88e6xxx_g2_smi_phy_read_c22, 4778 .phy_write = mv88e6xxx_g2_smi_phy_write_c22, 4779 .phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45, 4780 .phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45, 4781 .port_set_link = mv88e6xxx_port_set_link, 4782 .port_sync_link = mv88e6xxx_port_sync_link, 4783 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay, 4784 .port_set_speed_duplex = mv88e6250_port_set_speed_duplex, 4785 .port_tag_remap = mv88e6095_port_tag_remap, 4786 .port_set_frame_mode = mv88e6351_port_set_frame_mode, 4787 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood, 4788 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood, 4789 .port_set_ether_type = mv88e6351_port_set_ether_type, 4790 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, 4791 .port_pause_limit = mv88e6097_port_pause_limit, 4792 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, 4793 .stats_snapshot = mv88e6320_g1_stats_snapshot, 4794 .stats_set_histogram = mv88e6095_g1_stats_set_histogram, 4795 .stats_get_sset_count = mv88e6250_stats_get_sset_count, 4796 .stats_get_strings = mv88e6250_stats_get_strings, 4797 .stats_get_stats = mv88e6250_stats_get_stats, 4798 .set_cpu_port = mv88e6095_g1_set_cpu_port, 4799 .set_egress_port = mv88e6095_g1_set_egress_port, 4800 .watchdog_ops = &mv88e6250_watchdog_ops, 4801 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu, 4802 .pot_clear = mv88e6xxx_g2_pot_clear, 4803 .reset = mv88e6250_g1_reset, 4804 .vtu_getnext = mv88e6185_g1_vtu_getnext, 4805 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge, 4806 .avb_ops = &mv88e6352_avb_ops, 4807 .ptp_ops = &mv88e6250_ptp_ops, 4808 .phylink_get_caps = mv88e6250_phylink_get_caps, 4809 .set_max_frame_size = mv88e6185_g1_set_max_frame_size, 4810 }; 4811 4812 static const struct mv88e6xxx_ops mv88e6290_ops = { 4813 /* MV88E6XXX_FAMILY_6390 */ 4814 .setup_errata = mv88e6390_setup_errata, 4815 .irl_init_all = mv88e6390_g2_irl_init_all, 4816 .get_eeprom = mv88e6xxx_g2_get_eeprom8, 4817 .set_eeprom = mv88e6xxx_g2_set_eeprom8, 4818 .set_switch_mac = mv88e6xxx_g2_set_switch_mac, 4819 .phy_read = mv88e6xxx_g2_smi_phy_read_c22, 4820 .phy_write = mv88e6xxx_g2_smi_phy_write_c22, 4821 .phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45, 4822 .phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45, 4823 .port_set_link = mv88e6xxx_port_set_link, 4824 .port_sync_link = mv88e6xxx_port_sync_link, 4825 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay, 4826 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex, 4827 .port_max_speed_mode = mv88e6390_port_max_speed_mode, 4828 .port_tag_remap = mv88e6390_port_tag_remap, 4829 .port_set_policy = mv88e6352_port_set_policy, 4830 .port_set_frame_mode = mv88e6351_port_set_frame_mode, 4831 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood, 4832 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood, 4833 .port_set_ether_type = mv88e6351_port_set_ether_type, 4834 .port_pause_limit = mv88e6390_port_pause_limit, 4835 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit, 4836 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, 4837 .port_get_cmode = mv88e6352_port_get_cmode, 4838 .port_set_cmode = mv88e6390_port_set_cmode, 4839 .port_setup_message_port = mv88e6xxx_setup_message_port, 4840 .stats_snapshot = mv88e6390_g1_stats_snapshot, 4841 .stats_set_histogram = mv88e6390_g1_stats_set_histogram, 4842 .stats_get_sset_count = mv88e6320_stats_get_sset_count, 4843 .stats_get_strings = mv88e6320_stats_get_strings, 4844 .stats_get_stats = mv88e6390_stats_get_stats, 4845 .set_cpu_port = mv88e6390_g1_set_cpu_port, 4846 .set_egress_port = mv88e6390_g1_set_egress_port, 4847 .watchdog_ops = &mv88e6390_watchdog_ops, 4848 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu, 4849 .pot_clear = mv88e6xxx_g2_pot_clear, 4850 .reset = mv88e6352_g1_reset, 4851 .rmu_disable = mv88e6390_g1_rmu_disable, 4852 .atu_get_hash = mv88e6165_g1_atu_get_hash, 4853 .atu_set_hash = mv88e6165_g1_atu_set_hash, 4854 .vtu_getnext = mv88e6390_g1_vtu_getnext, 4855 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge, 4856 .stu_getnext = mv88e6390_g1_stu_getnext, 4857 .stu_loadpurge = mv88e6390_g1_stu_loadpurge, 4858 .serdes_get_lane = mv88e6390_serdes_get_lane, 4859 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping, 4860 .serdes_get_strings = mv88e6390_serdes_get_strings, 4861 .serdes_get_stats = mv88e6390_serdes_get_stats, 4862 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len, 4863 .serdes_get_regs = mv88e6390_serdes_get_regs, 4864 .gpio_ops = &mv88e6352_gpio_ops, 4865 .avb_ops = &mv88e6390_avb_ops, 4866 .ptp_ops = &mv88e6390_ptp_ops, 4867 .phylink_get_caps = mv88e6390_phylink_get_caps, 4868 .pcs_ops = &mv88e6390_pcs_ops, 4869 }; 4870 4871 static const struct mv88e6xxx_ops mv88e6320_ops = { 4872 /* MV88E6XXX_FAMILY_6320 */ 4873 .ieee_pri_map = mv88e6085_g1_ieee_pri_map, 4874 .ip_pri_map = mv88e6085_g1_ip_pri_map, 4875 .irl_init_all = mv88e6352_g2_irl_init_all, 4876 .get_eeprom = mv88e6xxx_g2_get_eeprom16, 4877 .set_eeprom = mv88e6xxx_g2_set_eeprom16, 4878 .set_switch_mac = mv88e6xxx_g2_set_switch_mac, 4879 .phy_read = mv88e6xxx_g2_smi_phy_read_c22, 4880 .phy_write = mv88e6xxx_g2_smi_phy_write_c22, 4881 .phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45, 4882 .phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45, 4883 .port_set_link = mv88e6xxx_port_set_link, 4884 .port_sync_link = mv88e6xxx_port_sync_link, 4885 .port_set_rgmii_delay = mv88e6320_port_set_rgmii_delay, 4886 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex, 4887 .port_tag_remap = mv88e6095_port_tag_remap, 4888 .port_set_frame_mode = mv88e6351_port_set_frame_mode, 4889 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood, 4890 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood, 4891 .port_set_ether_type = mv88e6351_port_set_ether_type, 4892 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size, 4893 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, 4894 .port_pause_limit = mv88e6097_port_pause_limit, 4895 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit, 4896 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, 4897 .port_get_cmode = mv88e6352_port_get_cmode, 4898 .port_setup_message_port = mv88e6xxx_setup_message_port, 4899 .stats_snapshot = mv88e6320_g1_stats_snapshot, 4900 .stats_set_histogram = mv88e6095_g1_stats_set_histogram, 4901 .stats_get_sset_count = mv88e6320_stats_get_sset_count, 4902 .stats_get_strings = mv88e6320_stats_get_strings, 4903 .stats_get_stats = mv88e6320_stats_get_stats, 4904 .set_cpu_port = mv88e6095_g1_set_cpu_port, 4905 .set_egress_port = mv88e6095_g1_set_egress_port, 4906 .watchdog_ops = &mv88e6390_watchdog_ops, 4907 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu, 4908 .pot_clear = mv88e6xxx_g2_pot_clear, 4909 .reset = mv88e6352_g1_reset, 4910 .vtu_getnext = mv88e6185_g1_vtu_getnext, 4911 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge, 4912 .gpio_ops = &mv88e6352_gpio_ops, 4913 .avb_ops = &mv88e6352_avb_ops, 4914 .ptp_ops = &mv88e6352_ptp_ops, 4915 .phylink_get_caps = mv88e6185_phylink_get_caps, 4916 }; 4917 4918 static const struct mv88e6xxx_ops mv88e6321_ops = { 4919 /* MV88E6XXX_FAMILY_6320 */ 4920 .ieee_pri_map = mv88e6085_g1_ieee_pri_map, 4921 .ip_pri_map = mv88e6085_g1_ip_pri_map, 4922 .irl_init_all = mv88e6352_g2_irl_init_all, 4923 .get_eeprom = mv88e6xxx_g2_get_eeprom16, 4924 .set_eeprom = mv88e6xxx_g2_set_eeprom16, 4925 .set_switch_mac = mv88e6xxx_g2_set_switch_mac, 4926 .phy_read = mv88e6xxx_g2_smi_phy_read_c22, 4927 .phy_write = mv88e6xxx_g2_smi_phy_write_c22, 4928 .phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45, 4929 .phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45, 4930 .port_set_link = mv88e6xxx_port_set_link, 4931 .port_sync_link = mv88e6xxx_port_sync_link, 4932 .port_set_rgmii_delay = mv88e6320_port_set_rgmii_delay, 4933 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex, 4934 .port_tag_remap = mv88e6095_port_tag_remap, 4935 .port_set_frame_mode = mv88e6351_port_set_frame_mode, 4936 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood, 4937 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood, 4938 .port_set_ether_type = mv88e6351_port_set_ether_type, 4939 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size, 4940 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, 4941 .port_pause_limit = mv88e6097_port_pause_limit, 4942 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit, 4943 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, 4944 .port_get_cmode = mv88e6352_port_get_cmode, 4945 .port_setup_message_port = mv88e6xxx_setup_message_port, 4946 .stats_snapshot = mv88e6320_g1_stats_snapshot, 4947 .stats_set_histogram = mv88e6095_g1_stats_set_histogram, 4948 .stats_get_sset_count = mv88e6320_stats_get_sset_count, 4949 .stats_get_strings = mv88e6320_stats_get_strings, 4950 .stats_get_stats = mv88e6320_stats_get_stats, 4951 .set_cpu_port = mv88e6095_g1_set_cpu_port, 4952 .set_egress_port = mv88e6095_g1_set_egress_port, 4953 .watchdog_ops = &mv88e6390_watchdog_ops, 4954 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu, 4955 .reset = mv88e6352_g1_reset, 4956 .vtu_getnext = mv88e6185_g1_vtu_getnext, 4957 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge, 4958 .gpio_ops = &mv88e6352_gpio_ops, 4959 .avb_ops = &mv88e6352_avb_ops, 4960 .ptp_ops = &mv88e6352_ptp_ops, 4961 .phylink_get_caps = mv88e6185_phylink_get_caps, 4962 }; 4963 4964 static const struct mv88e6xxx_ops mv88e6341_ops = { 4965 /* MV88E6XXX_FAMILY_6341 */ 4966 .ieee_pri_map = mv88e6085_g1_ieee_pri_map, 4967 .ip_pri_map = mv88e6085_g1_ip_pri_map, 4968 .irl_init_all = mv88e6352_g2_irl_init_all, 4969 .get_eeprom = mv88e6xxx_g2_get_eeprom8, 4970 .set_eeprom = mv88e6xxx_g2_set_eeprom8, 4971 .set_switch_mac = mv88e6xxx_g2_set_switch_mac, 4972 .phy_read = mv88e6xxx_g2_smi_phy_read_c22, 4973 .phy_write = mv88e6xxx_g2_smi_phy_write_c22, 4974 .phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45, 4975 .phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45, 4976 .port_set_link = mv88e6xxx_port_set_link, 4977 .port_sync_link = mv88e6xxx_port_sync_link, 4978 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay, 4979 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex, 4980 .port_max_speed_mode = mv88e6341_port_max_speed_mode, 4981 .port_tag_remap = mv88e6095_port_tag_remap, 4982 .port_set_policy = mv88e6352_port_set_policy, 4983 .port_set_frame_mode = mv88e6351_port_set_frame_mode, 4984 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood, 4985 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood, 4986 .port_set_ether_type = mv88e6351_port_set_ether_type, 4987 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size, 4988 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, 4989 .port_pause_limit = mv88e6097_port_pause_limit, 4990 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit, 4991 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, 4992 .port_get_cmode = mv88e6352_port_get_cmode, 4993 .port_set_cmode = mv88e6341_port_set_cmode, 4994 .port_setup_message_port = mv88e6xxx_setup_message_port, 4995 .stats_snapshot = mv88e6390_g1_stats_snapshot, 4996 .stats_set_histogram = mv88e6390_g1_stats_set_histogram, 4997 .stats_get_sset_count = mv88e6320_stats_get_sset_count, 4998 .stats_get_strings = mv88e6320_stats_get_strings, 4999 .stats_get_stats = mv88e6390_stats_get_stats, 5000 .set_cpu_port = mv88e6390_g1_set_cpu_port, 5001 .set_egress_port = mv88e6390_g1_set_egress_port, 5002 .watchdog_ops = &mv88e6390_watchdog_ops, 5003 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu, 5004 .pot_clear = mv88e6xxx_g2_pot_clear, 5005 .reset = mv88e6352_g1_reset, 5006 .rmu_disable = mv88e6390_g1_rmu_disable, 5007 .atu_get_hash = mv88e6165_g1_atu_get_hash, 5008 .atu_set_hash = mv88e6165_g1_atu_set_hash, 5009 .vtu_getnext = mv88e6352_g1_vtu_getnext, 5010 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge, 5011 .stu_getnext = mv88e6352_g1_stu_getnext, 5012 .stu_loadpurge = mv88e6352_g1_stu_loadpurge, 5013 .serdes_get_lane = mv88e6341_serdes_get_lane, 5014 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping, 5015 .gpio_ops = &mv88e6352_gpio_ops, 5016 .avb_ops = &mv88e6390_avb_ops, 5017 .ptp_ops = &mv88e6352_ptp_ops, 5018 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count, 5019 .serdes_get_strings = mv88e6390_serdes_get_strings, 5020 .serdes_get_stats = mv88e6390_serdes_get_stats, 5021 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len, 5022 .serdes_get_regs = mv88e6390_serdes_get_regs, 5023 .phylink_get_caps = mv88e6341_phylink_get_caps, 5024 .pcs_ops = &mv88e6390_pcs_ops, 5025 }; 5026 5027 static const struct mv88e6xxx_ops mv88e6350_ops = { 5028 /* MV88E6XXX_FAMILY_6351 */ 5029 .ieee_pri_map = mv88e6085_g1_ieee_pri_map, 5030 .ip_pri_map = mv88e6085_g1_ip_pri_map, 5031 .irl_init_all = mv88e6352_g2_irl_init_all, 5032 .set_switch_mac = mv88e6xxx_g2_set_switch_mac, 5033 .phy_read = mv88e6xxx_g2_smi_phy_read_c22, 5034 .phy_write = mv88e6xxx_g2_smi_phy_write_c22, 5035 .phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45, 5036 .phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45, 5037 .port_set_link = mv88e6xxx_port_set_link, 5038 .port_sync_link = mv88e6xxx_port_sync_link, 5039 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay, 5040 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex, 5041 .port_tag_remap = mv88e6095_port_tag_remap, 5042 .port_set_frame_mode = mv88e6351_port_set_frame_mode, 5043 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood, 5044 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood, 5045 .port_set_ether_type = mv88e6351_port_set_ether_type, 5046 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size, 5047 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, 5048 .port_pause_limit = mv88e6097_port_pause_limit, 5049 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit, 5050 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, 5051 .port_get_cmode = mv88e6352_port_get_cmode, 5052 .port_setup_message_port = mv88e6xxx_setup_message_port, 5053 .stats_snapshot = mv88e6320_g1_stats_snapshot, 5054 .stats_set_histogram = mv88e6095_g1_stats_set_histogram, 5055 .stats_get_sset_count = mv88e6095_stats_get_sset_count, 5056 .stats_get_strings = mv88e6095_stats_get_strings, 5057 .stats_get_stats = mv88e6095_stats_get_stats, 5058 .set_cpu_port = mv88e6095_g1_set_cpu_port, 5059 .set_egress_port = mv88e6095_g1_set_egress_port, 5060 .watchdog_ops = &mv88e6097_watchdog_ops, 5061 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu, 5062 .pot_clear = mv88e6xxx_g2_pot_clear, 5063 .reset = mv88e6352_g1_reset, 5064 .atu_get_hash = mv88e6165_g1_atu_get_hash, 5065 .atu_set_hash = mv88e6165_g1_atu_set_hash, 5066 .vtu_getnext = mv88e6352_g1_vtu_getnext, 5067 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge, 5068 .stu_getnext = mv88e6352_g1_stu_getnext, 5069 .stu_loadpurge = mv88e6352_g1_stu_loadpurge, 5070 .phylink_get_caps = mv88e6185_phylink_get_caps, 5071 }; 5072 5073 static const struct mv88e6xxx_ops mv88e6351_ops = { 5074 /* MV88E6XXX_FAMILY_6351 */ 5075 .ieee_pri_map = mv88e6085_g1_ieee_pri_map, 5076 .ip_pri_map = mv88e6085_g1_ip_pri_map, 5077 .irl_init_all = mv88e6352_g2_irl_init_all, 5078 .set_switch_mac = mv88e6xxx_g2_set_switch_mac, 5079 .phy_read = mv88e6xxx_g2_smi_phy_read_c22, 5080 .phy_write = mv88e6xxx_g2_smi_phy_write_c22, 5081 .phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45, 5082 .phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45, 5083 .port_set_link = mv88e6xxx_port_set_link, 5084 .port_sync_link = mv88e6xxx_port_sync_link, 5085 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay, 5086 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex, 5087 .port_tag_remap = mv88e6095_port_tag_remap, 5088 .port_set_frame_mode = mv88e6351_port_set_frame_mode, 5089 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood, 5090 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood, 5091 .port_set_ether_type = mv88e6351_port_set_ether_type, 5092 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size, 5093 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, 5094 .port_pause_limit = mv88e6097_port_pause_limit, 5095 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit, 5096 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, 5097 .port_get_cmode = mv88e6352_port_get_cmode, 5098 .port_setup_message_port = mv88e6xxx_setup_message_port, 5099 .stats_snapshot = mv88e6320_g1_stats_snapshot, 5100 .stats_set_histogram = mv88e6095_g1_stats_set_histogram, 5101 .stats_get_sset_count = mv88e6095_stats_get_sset_count, 5102 .stats_get_strings = mv88e6095_stats_get_strings, 5103 .stats_get_stats = mv88e6095_stats_get_stats, 5104 .set_cpu_port = mv88e6095_g1_set_cpu_port, 5105 .set_egress_port = mv88e6095_g1_set_egress_port, 5106 .watchdog_ops = &mv88e6097_watchdog_ops, 5107 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu, 5108 .pot_clear = mv88e6xxx_g2_pot_clear, 5109 .reset = mv88e6352_g1_reset, 5110 .atu_get_hash = mv88e6165_g1_atu_get_hash, 5111 .atu_set_hash = mv88e6165_g1_atu_set_hash, 5112 .vtu_getnext = mv88e6352_g1_vtu_getnext, 5113 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge, 5114 .stu_getnext = mv88e6352_g1_stu_getnext, 5115 .stu_loadpurge = mv88e6352_g1_stu_loadpurge, 5116 .avb_ops = &mv88e6352_avb_ops, 5117 .ptp_ops = &mv88e6352_ptp_ops, 5118 .phylink_get_caps = mv88e6185_phylink_get_caps, 5119 }; 5120 5121 static const struct mv88e6xxx_ops mv88e6352_ops = { 5122 /* MV88E6XXX_FAMILY_6352 */ 5123 .ieee_pri_map = mv88e6085_g1_ieee_pri_map, 5124 .ip_pri_map = mv88e6085_g1_ip_pri_map, 5125 .irl_init_all = mv88e6352_g2_irl_init_all, 5126 .get_eeprom = mv88e6xxx_g2_get_eeprom16, 5127 .set_eeprom = mv88e6xxx_g2_set_eeprom16, 5128 .set_switch_mac = mv88e6xxx_g2_set_switch_mac, 5129 .phy_read = mv88e6xxx_g2_smi_phy_read_c22, 5130 .phy_write = mv88e6xxx_g2_smi_phy_write_c22, 5131 .phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45, 5132 .phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45, 5133 .port_set_link = mv88e6xxx_port_set_link, 5134 .port_sync_link = mv88e6xxx_port_sync_link, 5135 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay, 5136 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex, 5137 .port_tag_remap = mv88e6095_port_tag_remap, 5138 .port_set_policy = mv88e6352_port_set_policy, 5139 .port_set_frame_mode = mv88e6351_port_set_frame_mode, 5140 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood, 5141 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood, 5142 .port_set_ether_type = mv88e6351_port_set_ether_type, 5143 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size, 5144 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, 5145 .port_pause_limit = mv88e6097_port_pause_limit, 5146 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit, 5147 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, 5148 .port_get_cmode = mv88e6352_port_get_cmode, 5149 .port_setup_message_port = mv88e6xxx_setup_message_port, 5150 .stats_snapshot = mv88e6320_g1_stats_snapshot, 5151 .stats_set_histogram = mv88e6095_g1_stats_set_histogram, 5152 .stats_get_sset_count = mv88e6095_stats_get_sset_count, 5153 .stats_get_strings = mv88e6095_stats_get_strings, 5154 .stats_get_stats = mv88e6095_stats_get_stats, 5155 .set_cpu_port = mv88e6095_g1_set_cpu_port, 5156 .set_egress_port = mv88e6095_g1_set_egress_port, 5157 .watchdog_ops = &mv88e6097_watchdog_ops, 5158 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu, 5159 .pot_clear = mv88e6xxx_g2_pot_clear, 5160 .reset = mv88e6352_g1_reset, 5161 .rmu_disable = mv88e6352_g1_rmu_disable, 5162 .atu_get_hash = mv88e6165_g1_atu_get_hash, 5163 .atu_set_hash = mv88e6165_g1_atu_set_hash, 5164 .vtu_getnext = mv88e6352_g1_vtu_getnext, 5165 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge, 5166 .stu_getnext = mv88e6352_g1_stu_getnext, 5167 .stu_loadpurge = mv88e6352_g1_stu_loadpurge, 5168 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping, 5169 .gpio_ops = &mv88e6352_gpio_ops, 5170 .avb_ops = &mv88e6352_avb_ops, 5171 .ptp_ops = &mv88e6352_ptp_ops, 5172 .serdes_get_sset_count = mv88e6352_serdes_get_sset_count, 5173 .serdes_get_strings = mv88e6352_serdes_get_strings, 5174 .serdes_get_stats = mv88e6352_serdes_get_stats, 5175 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len, 5176 .serdes_get_regs = mv88e6352_serdes_get_regs, 5177 .serdes_set_tx_amplitude = mv88e6352_serdes_set_tx_amplitude, 5178 .phylink_get_caps = mv88e6352_phylink_get_caps, 5179 .pcs_ops = &mv88e6352_pcs_ops, 5180 }; 5181 5182 static const struct mv88e6xxx_ops mv88e6390_ops = { 5183 /* MV88E6XXX_FAMILY_6390 */ 5184 .setup_errata = mv88e6390_setup_errata, 5185 .irl_init_all = mv88e6390_g2_irl_init_all, 5186 .get_eeprom = mv88e6xxx_g2_get_eeprom8, 5187 .set_eeprom = mv88e6xxx_g2_set_eeprom8, 5188 .set_switch_mac = mv88e6xxx_g2_set_switch_mac, 5189 .phy_read = mv88e6xxx_g2_smi_phy_read_c22, 5190 .phy_write = mv88e6xxx_g2_smi_phy_write_c22, 5191 .phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45, 5192 .phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45, 5193 .port_set_link = mv88e6xxx_port_set_link, 5194 .port_sync_link = mv88e6xxx_port_sync_link, 5195 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay, 5196 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex, 5197 .port_max_speed_mode = mv88e6390_port_max_speed_mode, 5198 .port_tag_remap = mv88e6390_port_tag_remap, 5199 .port_set_policy = mv88e6352_port_set_policy, 5200 .port_set_frame_mode = mv88e6351_port_set_frame_mode, 5201 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood, 5202 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood, 5203 .port_set_ether_type = mv88e6351_port_set_ether_type, 5204 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size, 5205 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, 5206 .port_pause_limit = mv88e6390_port_pause_limit, 5207 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit, 5208 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, 5209 .port_get_cmode = mv88e6352_port_get_cmode, 5210 .port_set_cmode = mv88e6390_port_set_cmode, 5211 .port_setup_message_port = mv88e6xxx_setup_message_port, 5212 .stats_snapshot = mv88e6390_g1_stats_snapshot, 5213 .stats_set_histogram = mv88e6390_g1_stats_set_histogram, 5214 .stats_get_sset_count = mv88e6320_stats_get_sset_count, 5215 .stats_get_strings = mv88e6320_stats_get_strings, 5216 .stats_get_stats = mv88e6390_stats_get_stats, 5217 .set_cpu_port = mv88e6390_g1_set_cpu_port, 5218 .set_egress_port = mv88e6390_g1_set_egress_port, 5219 .watchdog_ops = &mv88e6390_watchdog_ops, 5220 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu, 5221 .pot_clear = mv88e6xxx_g2_pot_clear, 5222 .reset = mv88e6352_g1_reset, 5223 .rmu_disable = mv88e6390_g1_rmu_disable, 5224 .atu_get_hash = mv88e6165_g1_atu_get_hash, 5225 .atu_set_hash = mv88e6165_g1_atu_set_hash, 5226 .vtu_getnext = mv88e6390_g1_vtu_getnext, 5227 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge, 5228 .stu_getnext = mv88e6390_g1_stu_getnext, 5229 .stu_loadpurge = mv88e6390_g1_stu_loadpurge, 5230 .serdes_get_lane = mv88e6390_serdes_get_lane, 5231 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping, 5232 .gpio_ops = &mv88e6352_gpio_ops, 5233 .avb_ops = &mv88e6390_avb_ops, 5234 .ptp_ops = &mv88e6390_ptp_ops, 5235 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count, 5236 .serdes_get_strings = mv88e6390_serdes_get_strings, 5237 .serdes_get_stats = mv88e6390_serdes_get_stats, 5238 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len, 5239 .serdes_get_regs = mv88e6390_serdes_get_regs, 5240 .phylink_get_caps = mv88e6390_phylink_get_caps, 5241 .pcs_ops = &mv88e6390_pcs_ops, 5242 }; 5243 5244 static const struct mv88e6xxx_ops mv88e6390x_ops = { 5245 /* MV88E6XXX_FAMILY_6390 */ 5246 .setup_errata = mv88e6390_setup_errata, 5247 .irl_init_all = mv88e6390_g2_irl_init_all, 5248 .get_eeprom = mv88e6xxx_g2_get_eeprom8, 5249 .set_eeprom = mv88e6xxx_g2_set_eeprom8, 5250 .set_switch_mac = mv88e6xxx_g2_set_switch_mac, 5251 .phy_read = mv88e6xxx_g2_smi_phy_read_c22, 5252 .phy_write = mv88e6xxx_g2_smi_phy_write_c22, 5253 .phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45, 5254 .phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45, 5255 .port_set_link = mv88e6xxx_port_set_link, 5256 .port_sync_link = mv88e6xxx_port_sync_link, 5257 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay, 5258 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex, 5259 .port_max_speed_mode = mv88e6390x_port_max_speed_mode, 5260 .port_tag_remap = mv88e6390_port_tag_remap, 5261 .port_set_policy = mv88e6352_port_set_policy, 5262 .port_set_frame_mode = mv88e6351_port_set_frame_mode, 5263 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood, 5264 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood, 5265 .port_set_ether_type = mv88e6351_port_set_ether_type, 5266 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size, 5267 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, 5268 .port_pause_limit = mv88e6390_port_pause_limit, 5269 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit, 5270 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, 5271 .port_get_cmode = mv88e6352_port_get_cmode, 5272 .port_set_cmode = mv88e6390x_port_set_cmode, 5273 .port_setup_message_port = mv88e6xxx_setup_message_port, 5274 .stats_snapshot = mv88e6390_g1_stats_snapshot, 5275 .stats_set_histogram = mv88e6390_g1_stats_set_histogram, 5276 .stats_get_sset_count = mv88e6320_stats_get_sset_count, 5277 .stats_get_strings = mv88e6320_stats_get_strings, 5278 .stats_get_stats = mv88e6390_stats_get_stats, 5279 .set_cpu_port = mv88e6390_g1_set_cpu_port, 5280 .set_egress_port = mv88e6390_g1_set_egress_port, 5281 .watchdog_ops = &mv88e6390_watchdog_ops, 5282 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu, 5283 .pot_clear = mv88e6xxx_g2_pot_clear, 5284 .reset = mv88e6352_g1_reset, 5285 .rmu_disable = mv88e6390_g1_rmu_disable, 5286 .atu_get_hash = mv88e6165_g1_atu_get_hash, 5287 .atu_set_hash = mv88e6165_g1_atu_set_hash, 5288 .vtu_getnext = mv88e6390_g1_vtu_getnext, 5289 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge, 5290 .stu_getnext = mv88e6390_g1_stu_getnext, 5291 .stu_loadpurge = mv88e6390_g1_stu_loadpurge, 5292 .serdes_get_lane = mv88e6390x_serdes_get_lane, 5293 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping, 5294 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count, 5295 .serdes_get_strings = mv88e6390_serdes_get_strings, 5296 .serdes_get_stats = mv88e6390_serdes_get_stats, 5297 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len, 5298 .serdes_get_regs = mv88e6390_serdes_get_regs, 5299 .gpio_ops = &mv88e6352_gpio_ops, 5300 .avb_ops = &mv88e6390_avb_ops, 5301 .ptp_ops = &mv88e6390_ptp_ops, 5302 .phylink_get_caps = mv88e6390x_phylink_get_caps, 5303 .pcs_ops = &mv88e6390_pcs_ops, 5304 }; 5305 5306 static const struct mv88e6xxx_ops mv88e6393x_ops = { 5307 /* MV88E6XXX_FAMILY_6393 */ 5308 .irl_init_all = mv88e6390_g2_irl_init_all, 5309 .get_eeprom = mv88e6xxx_g2_get_eeprom8, 5310 .set_eeprom = mv88e6xxx_g2_set_eeprom8, 5311 .set_switch_mac = mv88e6xxx_g2_set_switch_mac, 5312 .phy_read = mv88e6xxx_g2_smi_phy_read_c22, 5313 .phy_write = mv88e6xxx_g2_smi_phy_write_c22, 5314 .phy_read_c45 = mv88e6xxx_g2_smi_phy_read_c45, 5315 .phy_write_c45 = mv88e6xxx_g2_smi_phy_write_c45, 5316 .port_set_link = mv88e6xxx_port_set_link, 5317 .port_sync_link = mv88e6xxx_port_sync_link, 5318 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay, 5319 .port_set_speed_duplex = mv88e6393x_port_set_speed_duplex, 5320 .port_max_speed_mode = mv88e6393x_port_max_speed_mode, 5321 .port_tag_remap = mv88e6390_port_tag_remap, 5322 .port_set_policy = mv88e6393x_port_set_policy, 5323 .port_set_frame_mode = mv88e6351_port_set_frame_mode, 5324 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood, 5325 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood, 5326 .port_set_ether_type = mv88e6393x_port_set_ether_type, 5327 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size, 5328 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting, 5329 .port_pause_limit = mv88e6390_port_pause_limit, 5330 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit, 5331 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, 5332 .port_get_cmode = mv88e6352_port_get_cmode, 5333 .port_set_cmode = mv88e6393x_port_set_cmode, 5334 .port_setup_message_port = mv88e6xxx_setup_message_port, 5335 .port_set_upstream_port = mv88e6393x_port_set_upstream_port, 5336 .stats_snapshot = mv88e6390_g1_stats_snapshot, 5337 .stats_set_histogram = mv88e6390_g1_stats_set_histogram, 5338 .stats_get_sset_count = mv88e6320_stats_get_sset_count, 5339 .stats_get_strings = mv88e6320_stats_get_strings, 5340 .stats_get_stats = mv88e6390_stats_get_stats, 5341 /* .set_cpu_port is missing because this family does not support a global 5342 * CPU port, only per port CPU port which is set via 5343 * .port_set_upstream_port method. 5344 */ 5345 .set_egress_port = mv88e6393x_set_egress_port, 5346 .watchdog_ops = &mv88e6393x_watchdog_ops, 5347 .mgmt_rsvd2cpu = mv88e6393x_port_mgmt_rsvd2cpu, 5348 .pot_clear = mv88e6xxx_g2_pot_clear, 5349 .reset = mv88e6352_g1_reset, 5350 .rmu_disable = mv88e6390_g1_rmu_disable, 5351 .atu_get_hash = mv88e6165_g1_atu_get_hash, 5352 .atu_set_hash = mv88e6165_g1_atu_set_hash, 5353 .vtu_getnext = mv88e6390_g1_vtu_getnext, 5354 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge, 5355 .stu_getnext = mv88e6390_g1_stu_getnext, 5356 .stu_loadpurge = mv88e6390_g1_stu_loadpurge, 5357 .serdes_get_lane = mv88e6393x_serdes_get_lane, 5358 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping, 5359 /* TODO: serdes stats */ 5360 .gpio_ops = &mv88e6352_gpio_ops, 5361 .avb_ops = &mv88e6390_avb_ops, 5362 .ptp_ops = &mv88e6352_ptp_ops, 5363 .phylink_get_caps = mv88e6393x_phylink_get_caps, 5364 .pcs_ops = &mv88e6393x_pcs_ops, 5365 }; 5366 5367 static const struct mv88e6xxx_info mv88e6xxx_table[] = { 5368 [MV88E6020] = { 5369 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6020, 5370 .family = MV88E6XXX_FAMILY_6250, 5371 .name = "Marvell 88E6020", 5372 .num_databases = 64, 5373 .num_ports = 4, 5374 .num_internal_phys = 2, 5375 .max_vid = 4095, 5376 .port_base_addr = 0x8, 5377 .phy_base_addr = 0x0, 5378 .global1_addr = 0xf, 5379 .global2_addr = 0x7, 5380 .age_time_coeff = 15000, 5381 .g1_irqs = 9, 5382 .g2_irqs = 5, 5383 .atu_move_port_mask = 0xf, 5384 .dual_chip = true, 5385 .ops = &mv88e6250_ops, 5386 }, 5387 5388 [MV88E6071] = { 5389 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6071, 5390 .family = MV88E6XXX_FAMILY_6250, 5391 .name = "Marvell 88E6071", 5392 .num_databases = 64, 5393 .num_ports = 7, 5394 .num_internal_phys = 5, 5395 .max_vid = 4095, 5396 .port_base_addr = 0x08, 5397 .phy_base_addr = 0x00, 5398 .global1_addr = 0x0f, 5399 .global2_addr = 0x07, 5400 .age_time_coeff = 15000, 5401 .g1_irqs = 9, 5402 .g2_irqs = 5, 5403 .atu_move_port_mask = 0xf, 5404 .dual_chip = true, 5405 .ops = &mv88e6250_ops, 5406 }, 5407 5408 [MV88E6085] = { 5409 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085, 5410 .family = MV88E6XXX_FAMILY_6097, 5411 .name = "Marvell 88E6085", 5412 .num_databases = 4096, 5413 .num_macs = 8192, 5414 .num_ports = 10, 5415 .num_internal_phys = 5, 5416 .max_vid = 4095, 5417 .max_sid = 63, 5418 .port_base_addr = 0x10, 5419 .phy_base_addr = 0x0, 5420 .global1_addr = 0x1b, 5421 .global2_addr = 0x1c, 5422 .age_time_coeff = 15000, 5423 .g1_irqs = 8, 5424 .g2_irqs = 10, 5425 .atu_move_port_mask = 0xf, 5426 .pvt = true, 5427 .multi_chip = true, 5428 .ops = &mv88e6085_ops, 5429 }, 5430 5431 [MV88E6095] = { 5432 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095, 5433 .family = MV88E6XXX_FAMILY_6095, 5434 .name = "Marvell 88E6095/88E6095F", 5435 .num_databases = 256, 5436 .num_macs = 8192, 5437 .num_ports = 11, 5438 .num_internal_phys = 0, 5439 .max_vid = 4095, 5440 .port_base_addr = 0x10, 5441 .phy_base_addr = 0x0, 5442 .global1_addr = 0x1b, 5443 .global2_addr = 0x1c, 5444 .age_time_coeff = 15000, 5445 .g1_irqs = 8, 5446 .atu_move_port_mask = 0xf, 5447 .multi_chip = true, 5448 .ops = &mv88e6095_ops, 5449 }, 5450 5451 [MV88E6097] = { 5452 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097, 5453 .family = MV88E6XXX_FAMILY_6097, 5454 .name = "Marvell 88E6097/88E6097F", 5455 .num_databases = 4096, 5456 .num_macs = 8192, 5457 .num_ports = 11, 5458 .num_internal_phys = 8, 5459 .max_vid = 4095, 5460 .max_sid = 63, 5461 .port_base_addr = 0x10, 5462 .phy_base_addr = 0x0, 5463 .global1_addr = 0x1b, 5464 .global2_addr = 0x1c, 5465 .age_time_coeff = 15000, 5466 .g1_irqs = 8, 5467 .g2_irqs = 10, 5468 .atu_move_port_mask = 0xf, 5469 .pvt = true, 5470 .multi_chip = true, 5471 .edsa_support = MV88E6XXX_EDSA_SUPPORTED, 5472 .ops = &mv88e6097_ops, 5473 }, 5474 5475 [MV88E6123] = { 5476 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123, 5477 .family = MV88E6XXX_FAMILY_6165, 5478 .name = "Marvell 88E6123", 5479 .num_databases = 4096, 5480 .num_macs = 1024, 5481 .num_ports = 3, 5482 .num_internal_phys = 5, 5483 .max_vid = 4095, 5484 .max_sid = 63, 5485 .port_base_addr = 0x10, 5486 .phy_base_addr = 0x0, 5487 .global1_addr = 0x1b, 5488 .global2_addr = 0x1c, 5489 .age_time_coeff = 15000, 5490 .g1_irqs = 9, 5491 .g2_irqs = 10, 5492 .atu_move_port_mask = 0xf, 5493 .pvt = true, 5494 .multi_chip = true, 5495 .edsa_support = MV88E6XXX_EDSA_SUPPORTED, 5496 .ops = &mv88e6123_ops, 5497 }, 5498 5499 [MV88E6131] = { 5500 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131, 5501 .family = MV88E6XXX_FAMILY_6185, 5502 .name = "Marvell 88E6131", 5503 .num_databases = 256, 5504 .num_macs = 8192, 5505 .num_ports = 8, 5506 .num_internal_phys = 0, 5507 .max_vid = 4095, 5508 .port_base_addr = 0x10, 5509 .phy_base_addr = 0x0, 5510 .global1_addr = 0x1b, 5511 .global2_addr = 0x1c, 5512 .age_time_coeff = 15000, 5513 .g1_irqs = 9, 5514 .atu_move_port_mask = 0xf, 5515 .multi_chip = true, 5516 .ops = &mv88e6131_ops, 5517 }, 5518 5519 [MV88E6141] = { 5520 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141, 5521 .family = MV88E6XXX_FAMILY_6341, 5522 .name = "Marvell 88E6141", 5523 .num_databases = 4096, 5524 .num_macs = 2048, 5525 .num_ports = 6, 5526 .num_internal_phys = 5, 5527 .num_gpio = 11, 5528 .max_vid = 4095, 5529 .max_sid = 63, 5530 .port_base_addr = 0x10, 5531 .phy_base_addr = 0x10, 5532 .global1_addr = 0x1b, 5533 .global2_addr = 0x1c, 5534 .age_time_coeff = 3750, 5535 .atu_move_port_mask = 0x1f, 5536 .g1_irqs = 9, 5537 .g2_irqs = 10, 5538 .pvt = true, 5539 .multi_chip = true, 5540 .edsa_support = MV88E6XXX_EDSA_SUPPORTED, 5541 .ops = &mv88e6141_ops, 5542 }, 5543 5544 [MV88E6161] = { 5545 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161, 5546 .family = MV88E6XXX_FAMILY_6165, 5547 .name = "Marvell 88E6161", 5548 .num_databases = 4096, 5549 .num_macs = 1024, 5550 .num_ports = 6, 5551 .num_internal_phys = 5, 5552 .max_vid = 4095, 5553 .max_sid = 63, 5554 .port_base_addr = 0x10, 5555 .phy_base_addr = 0x0, 5556 .global1_addr = 0x1b, 5557 .global2_addr = 0x1c, 5558 .age_time_coeff = 15000, 5559 .g1_irqs = 9, 5560 .g2_irqs = 10, 5561 .atu_move_port_mask = 0xf, 5562 .pvt = true, 5563 .multi_chip = true, 5564 .edsa_support = MV88E6XXX_EDSA_SUPPORTED, 5565 .ptp_support = true, 5566 .ops = &mv88e6161_ops, 5567 }, 5568 5569 [MV88E6165] = { 5570 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165, 5571 .family = MV88E6XXX_FAMILY_6165, 5572 .name = "Marvell 88E6165", 5573 .num_databases = 4096, 5574 .num_macs = 8192, 5575 .num_ports = 6, 5576 .num_internal_phys = 0, 5577 .max_vid = 4095, 5578 .max_sid = 63, 5579 .port_base_addr = 0x10, 5580 .phy_base_addr = 0x0, 5581 .global1_addr = 0x1b, 5582 .global2_addr = 0x1c, 5583 .age_time_coeff = 15000, 5584 .g1_irqs = 9, 5585 .g2_irqs = 10, 5586 .atu_move_port_mask = 0xf, 5587 .pvt = true, 5588 .multi_chip = true, 5589 .ptp_support = true, 5590 .ops = &mv88e6165_ops, 5591 }, 5592 5593 [MV88E6171] = { 5594 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171, 5595 .family = MV88E6XXX_FAMILY_6351, 5596 .name = "Marvell 88E6171", 5597 .num_databases = 4096, 5598 .num_macs = 8192, 5599 .num_ports = 7, 5600 .num_internal_phys = 5, 5601 .max_vid = 4095, 5602 .max_sid = 63, 5603 .port_base_addr = 0x10, 5604 .phy_base_addr = 0x0, 5605 .global1_addr = 0x1b, 5606 .global2_addr = 0x1c, 5607 .age_time_coeff = 15000, 5608 .g1_irqs = 9, 5609 .g2_irqs = 10, 5610 .atu_move_port_mask = 0xf, 5611 .pvt = true, 5612 .multi_chip = true, 5613 .edsa_support = MV88E6XXX_EDSA_SUPPORTED, 5614 .ops = &mv88e6171_ops, 5615 }, 5616 5617 [MV88E6172] = { 5618 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172, 5619 .family = MV88E6XXX_FAMILY_6352, 5620 .name = "Marvell 88E6172", 5621 .num_databases = 4096, 5622 .num_macs = 8192, 5623 .num_ports = 7, 5624 .num_internal_phys = 5, 5625 .num_gpio = 15, 5626 .max_vid = 4095, 5627 .max_sid = 63, 5628 .port_base_addr = 0x10, 5629 .phy_base_addr = 0x0, 5630 .global1_addr = 0x1b, 5631 .global2_addr = 0x1c, 5632 .age_time_coeff = 15000, 5633 .g1_irqs = 9, 5634 .g2_irqs = 10, 5635 .atu_move_port_mask = 0xf, 5636 .pvt = true, 5637 .multi_chip = true, 5638 .edsa_support = MV88E6XXX_EDSA_SUPPORTED, 5639 .ops = &mv88e6172_ops, 5640 }, 5641 5642 [MV88E6175] = { 5643 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175, 5644 .family = MV88E6XXX_FAMILY_6351, 5645 .name = "Marvell 88E6175", 5646 .num_databases = 4096, 5647 .num_macs = 8192, 5648 .num_ports = 7, 5649 .num_internal_phys = 5, 5650 .max_vid = 4095, 5651 .max_sid = 63, 5652 .port_base_addr = 0x10, 5653 .phy_base_addr = 0x0, 5654 .global1_addr = 0x1b, 5655 .global2_addr = 0x1c, 5656 .age_time_coeff = 15000, 5657 .g1_irqs = 9, 5658 .g2_irqs = 10, 5659 .atu_move_port_mask = 0xf, 5660 .pvt = true, 5661 .multi_chip = true, 5662 .edsa_support = MV88E6XXX_EDSA_SUPPORTED, 5663 .ops = &mv88e6175_ops, 5664 }, 5665 5666 [MV88E6176] = { 5667 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176, 5668 .family = MV88E6XXX_FAMILY_6352, 5669 .name = "Marvell 88E6176", 5670 .num_databases = 4096, 5671 .num_macs = 8192, 5672 .num_ports = 7, 5673 .num_internal_phys = 5, 5674 .num_gpio = 15, 5675 .max_vid = 4095, 5676 .max_sid = 63, 5677 .port_base_addr = 0x10, 5678 .phy_base_addr = 0x0, 5679 .global1_addr = 0x1b, 5680 .global2_addr = 0x1c, 5681 .age_time_coeff = 15000, 5682 .g1_irqs = 9, 5683 .g2_irqs = 10, 5684 .atu_move_port_mask = 0xf, 5685 .pvt = true, 5686 .multi_chip = true, 5687 .edsa_support = MV88E6XXX_EDSA_SUPPORTED, 5688 .ops = &mv88e6176_ops, 5689 }, 5690 5691 [MV88E6185] = { 5692 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185, 5693 .family = MV88E6XXX_FAMILY_6185, 5694 .name = "Marvell 88E6185", 5695 .num_databases = 256, 5696 .num_macs = 8192, 5697 .num_ports = 10, 5698 .num_internal_phys = 0, 5699 .max_vid = 4095, 5700 .port_base_addr = 0x10, 5701 .phy_base_addr = 0x0, 5702 .global1_addr = 0x1b, 5703 .global2_addr = 0x1c, 5704 .age_time_coeff = 15000, 5705 .g1_irqs = 8, 5706 .atu_move_port_mask = 0xf, 5707 .multi_chip = true, 5708 .edsa_support = MV88E6XXX_EDSA_SUPPORTED, 5709 .ops = &mv88e6185_ops, 5710 }, 5711 5712 [MV88E6190] = { 5713 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190, 5714 .family = MV88E6XXX_FAMILY_6390, 5715 .name = "Marvell 88E6190", 5716 .num_databases = 4096, 5717 .num_macs = 16384, 5718 .num_ports = 11, /* 10 + Z80 */ 5719 .num_internal_phys = 9, 5720 .num_gpio = 16, 5721 .max_vid = 8191, 5722 .max_sid = 63, 5723 .port_base_addr = 0x0, 5724 .phy_base_addr = 0x0, 5725 .global1_addr = 0x1b, 5726 .global2_addr = 0x1c, 5727 .age_time_coeff = 3750, 5728 .g1_irqs = 9, 5729 .g2_irqs = 14, 5730 .pvt = true, 5731 .multi_chip = true, 5732 .atu_move_port_mask = 0x1f, 5733 .ops = &mv88e6190_ops, 5734 }, 5735 5736 [MV88E6190X] = { 5737 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X, 5738 .family = MV88E6XXX_FAMILY_6390, 5739 .name = "Marvell 88E6190X", 5740 .num_databases = 4096, 5741 .num_macs = 16384, 5742 .num_ports = 11, /* 10 + Z80 */ 5743 .num_internal_phys = 9, 5744 .num_gpio = 16, 5745 .max_vid = 8191, 5746 .max_sid = 63, 5747 .port_base_addr = 0x0, 5748 .phy_base_addr = 0x0, 5749 .global1_addr = 0x1b, 5750 .global2_addr = 0x1c, 5751 .age_time_coeff = 3750, 5752 .g1_irqs = 9, 5753 .g2_irqs = 14, 5754 .atu_move_port_mask = 0x1f, 5755 .pvt = true, 5756 .multi_chip = true, 5757 .ops = &mv88e6190x_ops, 5758 }, 5759 5760 [MV88E6191] = { 5761 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191, 5762 .family = MV88E6XXX_FAMILY_6390, 5763 .name = "Marvell 88E6191", 5764 .num_databases = 4096, 5765 .num_macs = 16384, 5766 .num_ports = 11, /* 10 + Z80 */ 5767 .num_internal_phys = 9, 5768 .max_vid = 8191, 5769 .max_sid = 63, 5770 .port_base_addr = 0x0, 5771 .phy_base_addr = 0x0, 5772 .global1_addr = 0x1b, 5773 .global2_addr = 0x1c, 5774 .age_time_coeff = 3750, 5775 .g1_irqs = 9, 5776 .g2_irqs = 14, 5777 .atu_move_port_mask = 0x1f, 5778 .pvt = true, 5779 .multi_chip = true, 5780 .ptp_support = true, 5781 .ops = &mv88e6191_ops, 5782 }, 5783 5784 [MV88E6191X] = { 5785 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191X, 5786 .family = MV88E6XXX_FAMILY_6393, 5787 .name = "Marvell 88E6191X", 5788 .num_databases = 4096, 5789 .num_ports = 11, /* 10 + Z80 */ 5790 .num_internal_phys = 8, 5791 .internal_phys_offset = 1, 5792 .max_vid = 8191, 5793 .max_sid = 63, 5794 .port_base_addr = 0x0, 5795 .phy_base_addr = 0x0, 5796 .global1_addr = 0x1b, 5797 .global2_addr = 0x1c, 5798 .age_time_coeff = 3750, 5799 .g1_irqs = 10, 5800 .g2_irqs = 14, 5801 .atu_move_port_mask = 0x1f, 5802 .pvt = true, 5803 .multi_chip = true, 5804 .ptp_support = true, 5805 .ops = &mv88e6393x_ops, 5806 }, 5807 5808 [MV88E6193X] = { 5809 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6193X, 5810 .family = MV88E6XXX_FAMILY_6393, 5811 .name = "Marvell 88E6193X", 5812 .num_databases = 4096, 5813 .num_ports = 11, /* 10 + Z80 */ 5814 .num_internal_phys = 8, 5815 .internal_phys_offset = 1, 5816 .max_vid = 8191, 5817 .max_sid = 63, 5818 .port_base_addr = 0x0, 5819 .phy_base_addr = 0x0, 5820 .global1_addr = 0x1b, 5821 .global2_addr = 0x1c, 5822 .age_time_coeff = 3750, 5823 .g1_irqs = 10, 5824 .g2_irqs = 14, 5825 .atu_move_port_mask = 0x1f, 5826 .pvt = true, 5827 .multi_chip = true, 5828 .ptp_support = true, 5829 .ops = &mv88e6393x_ops, 5830 }, 5831 5832 [MV88E6220] = { 5833 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6220, 5834 .family = MV88E6XXX_FAMILY_6250, 5835 .name = "Marvell 88E6220", 5836 .num_databases = 64, 5837 5838 /* Ports 2-4 are not routed to pins 5839 * => usable ports 0, 1, 5, 6 5840 */ 5841 .num_ports = 7, 5842 .num_internal_phys = 2, 5843 .invalid_port_mask = BIT(2) | BIT(3) | BIT(4), 5844 .max_vid = 4095, 5845 .port_base_addr = 0x08, 5846 .phy_base_addr = 0x00, 5847 .global1_addr = 0x0f, 5848 .global2_addr = 0x07, 5849 .age_time_coeff = 15000, 5850 .g1_irqs = 9, 5851 .g2_irqs = 10, 5852 .atu_move_port_mask = 0xf, 5853 .dual_chip = true, 5854 .ptp_support = true, 5855 .ops = &mv88e6250_ops, 5856 }, 5857 5858 [MV88E6240] = { 5859 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240, 5860 .family = MV88E6XXX_FAMILY_6352, 5861 .name = "Marvell 88E6240", 5862 .num_databases = 4096, 5863 .num_macs = 8192, 5864 .num_ports = 7, 5865 .num_internal_phys = 5, 5866 .num_gpio = 15, 5867 .max_vid = 4095, 5868 .max_sid = 63, 5869 .port_base_addr = 0x10, 5870 .phy_base_addr = 0x0, 5871 .global1_addr = 0x1b, 5872 .global2_addr = 0x1c, 5873 .age_time_coeff = 15000, 5874 .g1_irqs = 9, 5875 .g2_irqs = 10, 5876 .atu_move_port_mask = 0xf, 5877 .pvt = true, 5878 .multi_chip = true, 5879 .edsa_support = MV88E6XXX_EDSA_SUPPORTED, 5880 .ptp_support = true, 5881 .ops = &mv88e6240_ops, 5882 }, 5883 5884 [MV88E6250] = { 5885 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6250, 5886 .family = MV88E6XXX_FAMILY_6250, 5887 .name = "Marvell 88E6250", 5888 .num_databases = 64, 5889 .num_ports = 7, 5890 .num_internal_phys = 5, 5891 .max_vid = 4095, 5892 .port_base_addr = 0x08, 5893 .phy_base_addr = 0x00, 5894 .global1_addr = 0x0f, 5895 .global2_addr = 0x07, 5896 .age_time_coeff = 15000, 5897 .g1_irqs = 9, 5898 .g2_irqs = 10, 5899 .atu_move_port_mask = 0xf, 5900 .dual_chip = true, 5901 .ptp_support = true, 5902 .ops = &mv88e6250_ops, 5903 }, 5904 5905 [MV88E6290] = { 5906 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290, 5907 .family = MV88E6XXX_FAMILY_6390, 5908 .name = "Marvell 88E6290", 5909 .num_databases = 4096, 5910 .num_ports = 11, /* 10 + Z80 */ 5911 .num_internal_phys = 9, 5912 .num_gpio = 16, 5913 .max_vid = 8191, 5914 .max_sid = 63, 5915 .port_base_addr = 0x0, 5916 .phy_base_addr = 0x0, 5917 .global1_addr = 0x1b, 5918 .global2_addr = 0x1c, 5919 .age_time_coeff = 3750, 5920 .g1_irqs = 9, 5921 .g2_irqs = 14, 5922 .atu_move_port_mask = 0x1f, 5923 .pvt = true, 5924 .multi_chip = true, 5925 .ptp_support = true, 5926 .ops = &mv88e6290_ops, 5927 }, 5928 5929 [MV88E6320] = { 5930 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320, 5931 .family = MV88E6XXX_FAMILY_6320, 5932 .name = "Marvell 88E6320", 5933 .num_databases = 4096, 5934 .num_macs = 8192, 5935 .num_ports = 7, 5936 .num_internal_phys = 5, 5937 .num_gpio = 15, 5938 .max_vid = 4095, 5939 .port_base_addr = 0x10, 5940 .phy_base_addr = 0x0, 5941 .global1_addr = 0x1b, 5942 .global2_addr = 0x1c, 5943 .age_time_coeff = 15000, 5944 .g1_irqs = 8, 5945 .g2_irqs = 10, 5946 .atu_move_port_mask = 0xf, 5947 .pvt = true, 5948 .multi_chip = true, 5949 .edsa_support = MV88E6XXX_EDSA_SUPPORTED, 5950 .ptp_support = true, 5951 .ops = &mv88e6320_ops, 5952 }, 5953 5954 [MV88E6321] = { 5955 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321, 5956 .family = MV88E6XXX_FAMILY_6320, 5957 .name = "Marvell 88E6321", 5958 .num_databases = 4096, 5959 .num_macs = 8192, 5960 .num_ports = 7, 5961 .num_internal_phys = 5, 5962 .num_gpio = 15, 5963 .max_vid = 4095, 5964 .port_base_addr = 0x10, 5965 .phy_base_addr = 0x0, 5966 .global1_addr = 0x1b, 5967 .global2_addr = 0x1c, 5968 .age_time_coeff = 15000, 5969 .g1_irqs = 8, 5970 .g2_irqs = 10, 5971 .atu_move_port_mask = 0xf, 5972 .multi_chip = true, 5973 .edsa_support = MV88E6XXX_EDSA_SUPPORTED, 5974 .ptp_support = true, 5975 .ops = &mv88e6321_ops, 5976 }, 5977 5978 [MV88E6341] = { 5979 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341, 5980 .family = MV88E6XXX_FAMILY_6341, 5981 .name = "Marvell 88E6341", 5982 .num_databases = 4096, 5983 .num_macs = 2048, 5984 .num_internal_phys = 5, 5985 .num_ports = 6, 5986 .num_gpio = 11, 5987 .max_vid = 4095, 5988 .max_sid = 63, 5989 .port_base_addr = 0x10, 5990 .phy_base_addr = 0x10, 5991 .global1_addr = 0x1b, 5992 .global2_addr = 0x1c, 5993 .age_time_coeff = 3750, 5994 .atu_move_port_mask = 0x1f, 5995 .g1_irqs = 9, 5996 .g2_irqs = 10, 5997 .pvt = true, 5998 .multi_chip = true, 5999 .edsa_support = MV88E6XXX_EDSA_SUPPORTED, 6000 .ptp_support = true, 6001 .ops = &mv88e6341_ops, 6002 }, 6003 6004 [MV88E6350] = { 6005 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350, 6006 .family = MV88E6XXX_FAMILY_6351, 6007 .name = "Marvell 88E6350", 6008 .num_databases = 4096, 6009 .num_macs = 8192, 6010 .num_ports = 7, 6011 .num_internal_phys = 5, 6012 .max_vid = 4095, 6013 .max_sid = 63, 6014 .port_base_addr = 0x10, 6015 .phy_base_addr = 0x0, 6016 .global1_addr = 0x1b, 6017 .global2_addr = 0x1c, 6018 .age_time_coeff = 15000, 6019 .g1_irqs = 9, 6020 .g2_irqs = 10, 6021 .atu_move_port_mask = 0xf, 6022 .pvt = true, 6023 .multi_chip = true, 6024 .edsa_support = MV88E6XXX_EDSA_SUPPORTED, 6025 .ops = &mv88e6350_ops, 6026 }, 6027 6028 [MV88E6351] = { 6029 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351, 6030 .family = MV88E6XXX_FAMILY_6351, 6031 .name = "Marvell 88E6351", 6032 .num_databases = 4096, 6033 .num_macs = 8192, 6034 .num_ports = 7, 6035 .num_internal_phys = 5, 6036 .max_vid = 4095, 6037 .max_sid = 63, 6038 .port_base_addr = 0x10, 6039 .phy_base_addr = 0x0, 6040 .global1_addr = 0x1b, 6041 .global2_addr = 0x1c, 6042 .age_time_coeff = 15000, 6043 .g1_irqs = 9, 6044 .g2_irqs = 10, 6045 .atu_move_port_mask = 0xf, 6046 .pvt = true, 6047 .multi_chip = true, 6048 .edsa_support = MV88E6XXX_EDSA_SUPPORTED, 6049 .ops = &mv88e6351_ops, 6050 }, 6051 6052 [MV88E6352] = { 6053 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352, 6054 .family = MV88E6XXX_FAMILY_6352, 6055 .name = "Marvell 88E6352", 6056 .num_databases = 4096, 6057 .num_macs = 8192, 6058 .num_ports = 7, 6059 .num_internal_phys = 5, 6060 .num_gpio = 15, 6061 .max_vid = 4095, 6062 .max_sid = 63, 6063 .port_base_addr = 0x10, 6064 .phy_base_addr = 0x0, 6065 .global1_addr = 0x1b, 6066 .global2_addr = 0x1c, 6067 .age_time_coeff = 15000, 6068 .g1_irqs = 9, 6069 .g2_irqs = 10, 6070 .atu_move_port_mask = 0xf, 6071 .pvt = true, 6072 .multi_chip = true, 6073 .edsa_support = MV88E6XXX_EDSA_SUPPORTED, 6074 .ptp_support = true, 6075 .ops = &mv88e6352_ops, 6076 }, 6077 [MV88E6361] = { 6078 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6361, 6079 .family = MV88E6XXX_FAMILY_6393, 6080 .name = "Marvell 88E6361", 6081 .num_databases = 4096, 6082 .num_macs = 16384, 6083 .num_ports = 11, 6084 /* Ports 1, 2 and 8 are not routed */ 6085 .invalid_port_mask = BIT(1) | BIT(2) | BIT(8), 6086 .num_internal_phys = 5, 6087 .internal_phys_offset = 3, 6088 .max_vid = 4095, 6089 .max_sid = 63, 6090 .port_base_addr = 0x0, 6091 .phy_base_addr = 0x0, 6092 .global1_addr = 0x1b, 6093 .global2_addr = 0x1c, 6094 .age_time_coeff = 3750, 6095 .g1_irqs = 10, 6096 .g2_irqs = 14, 6097 .atu_move_port_mask = 0x1f, 6098 .pvt = true, 6099 .multi_chip = true, 6100 .ptp_support = true, 6101 .ops = &mv88e6393x_ops, 6102 }, 6103 [MV88E6390] = { 6104 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390, 6105 .family = MV88E6XXX_FAMILY_6390, 6106 .name = "Marvell 88E6390", 6107 .num_databases = 4096, 6108 .num_macs = 16384, 6109 .num_ports = 11, /* 10 + Z80 */ 6110 .num_internal_phys = 9, 6111 .num_gpio = 16, 6112 .max_vid = 8191, 6113 .max_sid = 63, 6114 .port_base_addr = 0x0, 6115 .phy_base_addr = 0x0, 6116 .global1_addr = 0x1b, 6117 .global2_addr = 0x1c, 6118 .age_time_coeff = 3750, 6119 .g1_irqs = 9, 6120 .g2_irqs = 14, 6121 .atu_move_port_mask = 0x1f, 6122 .pvt = true, 6123 .multi_chip = true, 6124 .edsa_support = MV88E6XXX_EDSA_UNDOCUMENTED, 6125 .ptp_support = true, 6126 .ops = &mv88e6390_ops, 6127 }, 6128 [MV88E6390X] = { 6129 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X, 6130 .family = MV88E6XXX_FAMILY_6390, 6131 .name = "Marvell 88E6390X", 6132 .num_databases = 4096, 6133 .num_macs = 16384, 6134 .num_ports = 11, /* 10 + Z80 */ 6135 .num_internal_phys = 9, 6136 .num_gpio = 16, 6137 .max_vid = 8191, 6138 .max_sid = 63, 6139 .port_base_addr = 0x0, 6140 .phy_base_addr = 0x0, 6141 .global1_addr = 0x1b, 6142 .global2_addr = 0x1c, 6143 .age_time_coeff = 3750, 6144 .g1_irqs = 9, 6145 .g2_irqs = 14, 6146 .atu_move_port_mask = 0x1f, 6147 .pvt = true, 6148 .multi_chip = true, 6149 .edsa_support = MV88E6XXX_EDSA_UNDOCUMENTED, 6150 .ptp_support = true, 6151 .ops = &mv88e6390x_ops, 6152 }, 6153 6154 [MV88E6393X] = { 6155 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6393X, 6156 .family = MV88E6XXX_FAMILY_6393, 6157 .name = "Marvell 88E6393X", 6158 .num_databases = 4096, 6159 .num_ports = 11, /* 10 + Z80 */ 6160 .num_internal_phys = 8, 6161 .internal_phys_offset = 1, 6162 .max_vid = 8191, 6163 .max_sid = 63, 6164 .port_base_addr = 0x0, 6165 .phy_base_addr = 0x0, 6166 .global1_addr = 0x1b, 6167 .global2_addr = 0x1c, 6168 .age_time_coeff = 3750, 6169 .g1_irqs = 10, 6170 .g2_irqs = 14, 6171 .atu_move_port_mask = 0x1f, 6172 .pvt = true, 6173 .multi_chip = true, 6174 .ptp_support = true, 6175 .ops = &mv88e6393x_ops, 6176 }, 6177 }; 6178 6179 static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num) 6180 { 6181 int i; 6182 6183 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i) 6184 if (mv88e6xxx_table[i].prod_num == prod_num) 6185 return &mv88e6xxx_table[i]; 6186 6187 return NULL; 6188 } 6189 6190 static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip) 6191 { 6192 const struct mv88e6xxx_info *info; 6193 unsigned int prod_num, rev; 6194 u16 id; 6195 int err; 6196 6197 mv88e6xxx_reg_lock(chip); 6198 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id); 6199 mv88e6xxx_reg_unlock(chip); 6200 if (err) 6201 return err; 6202 6203 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK; 6204 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK; 6205 6206 info = mv88e6xxx_lookup_info(prod_num); 6207 if (!info) 6208 return -ENODEV; 6209 6210 /* Update the compatible info with the probed one */ 6211 chip->info = info; 6212 6213 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n", 6214 chip->info->prod_num, chip->info->name, rev); 6215 6216 return 0; 6217 } 6218 6219 static int mv88e6xxx_single_chip_detect(struct mv88e6xxx_chip *chip, 6220 struct mdio_device *mdiodev) 6221 { 6222 int err; 6223 6224 /* dual_chip takes precedence over single/multi-chip modes */ 6225 if (chip->info->dual_chip) 6226 return -EINVAL; 6227 6228 /* If the mdio addr is 16 indicating the first port address of a switch 6229 * (e.g. mv88e6*41) in single chip addressing mode the device may be 6230 * configured in single chip addressing mode. Setup the smi access as 6231 * single chip addressing mode and attempt to detect the model of the 6232 * switch, if this fails the device is not configured in single chip 6233 * addressing mode. 6234 */ 6235 if (mdiodev->addr != 16) 6236 return -EINVAL; 6237 6238 err = mv88e6xxx_smi_init(chip, mdiodev->bus, 0); 6239 if (err) 6240 return err; 6241 6242 return mv88e6xxx_detect(chip); 6243 } 6244 6245 static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev) 6246 { 6247 struct mv88e6xxx_chip *chip; 6248 6249 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); 6250 if (!chip) 6251 return NULL; 6252 6253 chip->dev = dev; 6254 6255 mutex_init(&chip->reg_lock); 6256 INIT_LIST_HEAD(&chip->mdios); 6257 idr_init(&chip->policies); 6258 INIT_LIST_HEAD(&chip->msts); 6259 6260 return chip; 6261 } 6262 6263 static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds, 6264 int port, 6265 enum dsa_tag_protocol m) 6266 { 6267 struct mv88e6xxx_chip *chip = ds->priv; 6268 6269 return chip->tag_protocol; 6270 } 6271 6272 static int mv88e6xxx_change_tag_protocol(struct dsa_switch *ds, 6273 enum dsa_tag_protocol proto) 6274 { 6275 struct mv88e6xxx_chip *chip = ds->priv; 6276 enum dsa_tag_protocol old_protocol; 6277 struct dsa_port *cpu_dp; 6278 int err; 6279 6280 switch (proto) { 6281 case DSA_TAG_PROTO_EDSA: 6282 switch (chip->info->edsa_support) { 6283 case MV88E6XXX_EDSA_UNSUPPORTED: 6284 return -EPROTONOSUPPORT; 6285 case MV88E6XXX_EDSA_UNDOCUMENTED: 6286 dev_warn(chip->dev, "Relying on undocumented EDSA tagging behavior\n"); 6287 fallthrough; 6288 case MV88E6XXX_EDSA_SUPPORTED: 6289 break; 6290 } 6291 break; 6292 case DSA_TAG_PROTO_DSA: 6293 break; 6294 default: 6295 return -EPROTONOSUPPORT; 6296 } 6297 6298 old_protocol = chip->tag_protocol; 6299 chip->tag_protocol = proto; 6300 6301 mv88e6xxx_reg_lock(chip); 6302 dsa_switch_for_each_cpu_port(cpu_dp, ds) { 6303 err = mv88e6xxx_setup_port_mode(chip, cpu_dp->index); 6304 if (err) { 6305 mv88e6xxx_reg_unlock(chip); 6306 goto unwind; 6307 } 6308 } 6309 mv88e6xxx_reg_unlock(chip); 6310 6311 return 0; 6312 6313 unwind: 6314 chip->tag_protocol = old_protocol; 6315 6316 mv88e6xxx_reg_lock(chip); 6317 dsa_switch_for_each_cpu_port_continue_reverse(cpu_dp, ds) 6318 mv88e6xxx_setup_port_mode(chip, cpu_dp->index); 6319 mv88e6xxx_reg_unlock(chip); 6320 6321 return err; 6322 } 6323 6324 static int mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port, 6325 const struct switchdev_obj_port_mdb *mdb, 6326 struct dsa_db db) 6327 { 6328 struct mv88e6xxx_chip *chip = ds->priv; 6329 int err; 6330 6331 mv88e6xxx_reg_lock(chip); 6332 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 6333 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC); 6334 mv88e6xxx_reg_unlock(chip); 6335 6336 return err; 6337 } 6338 6339 static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port, 6340 const struct switchdev_obj_port_mdb *mdb, 6341 struct dsa_db db) 6342 { 6343 struct mv88e6xxx_chip *chip = ds->priv; 6344 int err; 6345 6346 mv88e6xxx_reg_lock(chip); 6347 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 0); 6348 mv88e6xxx_reg_unlock(chip); 6349 6350 return err; 6351 } 6352 6353 static int mv88e6xxx_port_mirror_add(struct dsa_switch *ds, int port, 6354 struct dsa_mall_mirror_tc_entry *mirror, 6355 bool ingress, 6356 struct netlink_ext_ack *extack) 6357 { 6358 enum mv88e6xxx_egress_direction direction = ingress ? 6359 MV88E6XXX_EGRESS_DIR_INGRESS : 6360 MV88E6XXX_EGRESS_DIR_EGRESS; 6361 struct mv88e6xxx_chip *chip = ds->priv; 6362 bool other_mirrors = false; 6363 int i; 6364 int err; 6365 6366 mutex_lock(&chip->reg_lock); 6367 if ((ingress ? chip->ingress_dest_port : chip->egress_dest_port) != 6368 mirror->to_local_port) { 6369 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) 6370 other_mirrors |= ingress ? 6371 chip->ports[i].mirror_ingress : 6372 chip->ports[i].mirror_egress; 6373 6374 /* Can't change egress port when other mirror is active */ 6375 if (other_mirrors) { 6376 err = -EBUSY; 6377 goto out; 6378 } 6379 6380 err = mv88e6xxx_set_egress_port(chip, direction, 6381 mirror->to_local_port); 6382 if (err) 6383 goto out; 6384 } 6385 6386 err = mv88e6xxx_port_set_mirror(chip, port, direction, true); 6387 out: 6388 mutex_unlock(&chip->reg_lock); 6389 6390 return err; 6391 } 6392 6393 static void mv88e6xxx_port_mirror_del(struct dsa_switch *ds, int port, 6394 struct dsa_mall_mirror_tc_entry *mirror) 6395 { 6396 enum mv88e6xxx_egress_direction direction = mirror->ingress ? 6397 MV88E6XXX_EGRESS_DIR_INGRESS : 6398 MV88E6XXX_EGRESS_DIR_EGRESS; 6399 struct mv88e6xxx_chip *chip = ds->priv; 6400 bool other_mirrors = false; 6401 int i; 6402 6403 mutex_lock(&chip->reg_lock); 6404 if (mv88e6xxx_port_set_mirror(chip, port, direction, false)) 6405 dev_err(ds->dev, "p%d: failed to disable mirroring\n", port); 6406 6407 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) 6408 other_mirrors |= mirror->ingress ? 6409 chip->ports[i].mirror_ingress : 6410 chip->ports[i].mirror_egress; 6411 6412 /* Reset egress port when no other mirror is active */ 6413 if (!other_mirrors) { 6414 if (mv88e6xxx_set_egress_port(chip, direction, 6415 dsa_upstream_port(ds, port))) 6416 dev_err(ds->dev, "failed to set egress port\n"); 6417 } 6418 6419 mutex_unlock(&chip->reg_lock); 6420 } 6421 6422 static int mv88e6xxx_port_pre_bridge_flags(struct dsa_switch *ds, int port, 6423 struct switchdev_brport_flags flags, 6424 struct netlink_ext_ack *extack) 6425 { 6426 struct mv88e6xxx_chip *chip = ds->priv; 6427 const struct mv88e6xxx_ops *ops; 6428 6429 if (flags.mask & ~(BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD | 6430 BR_BCAST_FLOOD | BR_PORT_LOCKED | BR_PORT_MAB)) 6431 return -EINVAL; 6432 6433 ops = chip->info->ops; 6434 6435 if ((flags.mask & BR_FLOOD) && !ops->port_set_ucast_flood) 6436 return -EINVAL; 6437 6438 if ((flags.mask & BR_MCAST_FLOOD) && !ops->port_set_mcast_flood) 6439 return -EINVAL; 6440 6441 return 0; 6442 } 6443 6444 static int mv88e6xxx_port_bridge_flags(struct dsa_switch *ds, int port, 6445 struct switchdev_brport_flags flags, 6446 struct netlink_ext_ack *extack) 6447 { 6448 struct mv88e6xxx_chip *chip = ds->priv; 6449 int err = 0; 6450 6451 mv88e6xxx_reg_lock(chip); 6452 6453 if (flags.mask & BR_LEARNING) { 6454 bool learning = !!(flags.val & BR_LEARNING); 6455 u16 pav = learning ? (1 << port) : 0; 6456 6457 err = mv88e6xxx_port_set_assoc_vector(chip, port, pav); 6458 if (err) 6459 goto out; 6460 } 6461 6462 if (flags.mask & BR_FLOOD) { 6463 bool unicast = !!(flags.val & BR_FLOOD); 6464 6465 err = chip->info->ops->port_set_ucast_flood(chip, port, 6466 unicast); 6467 if (err) 6468 goto out; 6469 } 6470 6471 if (flags.mask & BR_MCAST_FLOOD) { 6472 bool multicast = !!(flags.val & BR_MCAST_FLOOD); 6473 6474 err = chip->info->ops->port_set_mcast_flood(chip, port, 6475 multicast); 6476 if (err) 6477 goto out; 6478 } 6479 6480 if (flags.mask & BR_BCAST_FLOOD) { 6481 bool broadcast = !!(flags.val & BR_BCAST_FLOOD); 6482 6483 err = mv88e6xxx_port_broadcast_sync(chip, port, broadcast); 6484 if (err) 6485 goto out; 6486 } 6487 6488 if (flags.mask & BR_PORT_MAB) { 6489 bool mab = !!(flags.val & BR_PORT_MAB); 6490 6491 mv88e6xxx_port_set_mab(chip, port, mab); 6492 } 6493 6494 if (flags.mask & BR_PORT_LOCKED) { 6495 bool locked = !!(flags.val & BR_PORT_LOCKED); 6496 6497 err = mv88e6xxx_port_set_lock(chip, port, locked); 6498 if (err) 6499 goto out; 6500 } 6501 out: 6502 mv88e6xxx_reg_unlock(chip); 6503 6504 return err; 6505 } 6506 6507 static bool mv88e6xxx_lag_can_offload(struct dsa_switch *ds, 6508 struct dsa_lag lag, 6509 struct netdev_lag_upper_info *info, 6510 struct netlink_ext_ack *extack) 6511 { 6512 struct mv88e6xxx_chip *chip = ds->priv; 6513 struct dsa_port *dp; 6514 int members = 0; 6515 6516 if (!mv88e6xxx_has_lag(chip)) { 6517 NL_SET_ERR_MSG_MOD(extack, "Chip does not support LAG offload"); 6518 return false; 6519 } 6520 6521 if (!lag.id) 6522 return false; 6523 6524 dsa_lag_foreach_port(dp, ds->dst, &lag) 6525 /* Includes the port joining the LAG */ 6526 members++; 6527 6528 if (members > 8) { 6529 NL_SET_ERR_MSG_MOD(extack, 6530 "Cannot offload more than 8 LAG ports"); 6531 return false; 6532 } 6533 6534 /* We could potentially relax this to include active 6535 * backup in the future. 6536 */ 6537 if (info->tx_type != NETDEV_LAG_TX_TYPE_HASH) { 6538 NL_SET_ERR_MSG_MOD(extack, 6539 "Can only offload LAG using hash TX type"); 6540 return false; 6541 } 6542 6543 /* Ideally we would also validate that the hash type matches 6544 * the hardware. Alas, this is always set to unknown on team 6545 * interfaces. 6546 */ 6547 return true; 6548 } 6549 6550 static int mv88e6xxx_lag_sync_map(struct dsa_switch *ds, struct dsa_lag lag) 6551 { 6552 struct mv88e6xxx_chip *chip = ds->priv; 6553 struct dsa_port *dp; 6554 u16 map = 0; 6555 int id; 6556 6557 /* DSA LAG IDs are one-based, hardware is zero-based */ 6558 id = lag.id - 1; 6559 6560 /* Build the map of all ports to distribute flows destined for 6561 * this LAG. This can be either a local user port, or a DSA 6562 * port if the LAG port is on a remote chip. 6563 */ 6564 dsa_lag_foreach_port(dp, ds->dst, &lag) 6565 map |= BIT(dsa_towards_port(ds, dp->ds->index, dp->index)); 6566 6567 return mv88e6xxx_g2_trunk_mapping_write(chip, id, map); 6568 } 6569 6570 static const u8 mv88e6xxx_lag_mask_table[8][8] = { 6571 /* Row number corresponds to the number of active members in a 6572 * LAG. Each column states which of the eight hash buckets are 6573 * mapped to the column:th port in the LAG. 6574 * 6575 * Example: In a LAG with three active ports, the second port 6576 * ([2][1]) would be selected for traffic mapped to buckets 6577 * 3,4,5 (0x38). 6578 */ 6579 { 0xff, 0, 0, 0, 0, 0, 0, 0 }, 6580 { 0x0f, 0xf0, 0, 0, 0, 0, 0, 0 }, 6581 { 0x07, 0x38, 0xc0, 0, 0, 0, 0, 0 }, 6582 { 0x03, 0x0c, 0x30, 0xc0, 0, 0, 0, 0 }, 6583 { 0x03, 0x0c, 0x30, 0x40, 0x80, 0, 0, 0 }, 6584 { 0x03, 0x0c, 0x10, 0x20, 0x40, 0x80, 0, 0 }, 6585 { 0x03, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0 }, 6586 { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }, 6587 }; 6588 6589 static void mv88e6xxx_lag_set_port_mask(u16 *mask, int port, 6590 int num_tx, int nth) 6591 { 6592 u8 active = 0; 6593 int i; 6594 6595 num_tx = num_tx <= 8 ? num_tx : 8; 6596 if (nth < num_tx) 6597 active = mv88e6xxx_lag_mask_table[num_tx - 1][nth]; 6598 6599 for (i = 0; i < 8; i++) { 6600 if (BIT(i) & active) 6601 mask[i] |= BIT(port); 6602 } 6603 } 6604 6605 static int mv88e6xxx_lag_sync_masks(struct dsa_switch *ds) 6606 { 6607 struct mv88e6xxx_chip *chip = ds->priv; 6608 unsigned int id, num_tx; 6609 struct dsa_port *dp; 6610 struct dsa_lag *lag; 6611 int i, err, nth; 6612 u16 mask[8]; 6613 u16 ivec; 6614 6615 /* Assume no port is a member of any LAG. */ 6616 ivec = BIT(mv88e6xxx_num_ports(chip)) - 1; 6617 6618 /* Disable all masks for ports that _are_ members of a LAG. */ 6619 dsa_switch_for_each_port(dp, ds) { 6620 if (!dp->lag) 6621 continue; 6622 6623 ivec &= ~BIT(dp->index); 6624 } 6625 6626 for (i = 0; i < 8; i++) 6627 mask[i] = ivec; 6628 6629 /* Enable the correct subset of masks for all LAG ports that 6630 * are in the Tx set. 6631 */ 6632 dsa_lags_foreach_id(id, ds->dst) { 6633 lag = dsa_lag_by_id(ds->dst, id); 6634 if (!lag) 6635 continue; 6636 6637 num_tx = 0; 6638 dsa_lag_foreach_port(dp, ds->dst, lag) { 6639 if (dp->lag_tx_enabled) 6640 num_tx++; 6641 } 6642 6643 if (!num_tx) 6644 continue; 6645 6646 nth = 0; 6647 dsa_lag_foreach_port(dp, ds->dst, lag) { 6648 if (!dp->lag_tx_enabled) 6649 continue; 6650 6651 if (dp->ds == ds) 6652 mv88e6xxx_lag_set_port_mask(mask, dp->index, 6653 num_tx, nth); 6654 6655 nth++; 6656 } 6657 } 6658 6659 for (i = 0; i < 8; i++) { 6660 err = mv88e6xxx_g2_trunk_mask_write(chip, i, true, mask[i]); 6661 if (err) 6662 return err; 6663 } 6664 6665 return 0; 6666 } 6667 6668 static int mv88e6xxx_lag_sync_masks_map(struct dsa_switch *ds, 6669 struct dsa_lag lag) 6670 { 6671 int err; 6672 6673 err = mv88e6xxx_lag_sync_masks(ds); 6674 6675 if (!err) 6676 err = mv88e6xxx_lag_sync_map(ds, lag); 6677 6678 return err; 6679 } 6680 6681 static int mv88e6xxx_port_lag_change(struct dsa_switch *ds, int port) 6682 { 6683 struct mv88e6xxx_chip *chip = ds->priv; 6684 int err; 6685 6686 mv88e6xxx_reg_lock(chip); 6687 err = mv88e6xxx_lag_sync_masks(ds); 6688 mv88e6xxx_reg_unlock(chip); 6689 return err; 6690 } 6691 6692 static int mv88e6xxx_port_lag_join(struct dsa_switch *ds, int port, 6693 struct dsa_lag lag, 6694 struct netdev_lag_upper_info *info, 6695 struct netlink_ext_ack *extack) 6696 { 6697 struct mv88e6xxx_chip *chip = ds->priv; 6698 int err, id; 6699 6700 if (!mv88e6xxx_lag_can_offload(ds, lag, info, extack)) 6701 return -EOPNOTSUPP; 6702 6703 /* DSA LAG IDs are one-based */ 6704 id = lag.id - 1; 6705 6706 mv88e6xxx_reg_lock(chip); 6707 6708 err = mv88e6xxx_port_set_trunk(chip, port, true, id); 6709 if (err) 6710 goto err_unlock; 6711 6712 err = mv88e6xxx_lag_sync_masks_map(ds, lag); 6713 if (err) 6714 goto err_clear_trunk; 6715 6716 mv88e6xxx_reg_unlock(chip); 6717 return 0; 6718 6719 err_clear_trunk: 6720 mv88e6xxx_port_set_trunk(chip, port, false, 0); 6721 err_unlock: 6722 mv88e6xxx_reg_unlock(chip); 6723 return err; 6724 } 6725 6726 static int mv88e6xxx_port_lag_leave(struct dsa_switch *ds, int port, 6727 struct dsa_lag lag) 6728 { 6729 struct mv88e6xxx_chip *chip = ds->priv; 6730 int err_sync, err_trunk; 6731 6732 mv88e6xxx_reg_lock(chip); 6733 err_sync = mv88e6xxx_lag_sync_masks_map(ds, lag); 6734 err_trunk = mv88e6xxx_port_set_trunk(chip, port, false, 0); 6735 mv88e6xxx_reg_unlock(chip); 6736 return err_sync ? : err_trunk; 6737 } 6738 6739 static int mv88e6xxx_crosschip_lag_change(struct dsa_switch *ds, int sw_index, 6740 int port) 6741 { 6742 struct mv88e6xxx_chip *chip = ds->priv; 6743 int err; 6744 6745 mv88e6xxx_reg_lock(chip); 6746 err = mv88e6xxx_lag_sync_masks(ds); 6747 mv88e6xxx_reg_unlock(chip); 6748 return err; 6749 } 6750 6751 static int mv88e6xxx_crosschip_lag_join(struct dsa_switch *ds, int sw_index, 6752 int port, struct dsa_lag lag, 6753 struct netdev_lag_upper_info *info, 6754 struct netlink_ext_ack *extack) 6755 { 6756 struct mv88e6xxx_chip *chip = ds->priv; 6757 int err; 6758 6759 if (!mv88e6xxx_lag_can_offload(ds, lag, info, extack)) 6760 return -EOPNOTSUPP; 6761 6762 mv88e6xxx_reg_lock(chip); 6763 6764 err = mv88e6xxx_lag_sync_masks_map(ds, lag); 6765 if (err) 6766 goto unlock; 6767 6768 err = mv88e6xxx_pvt_map(chip, sw_index, port); 6769 6770 unlock: 6771 mv88e6xxx_reg_unlock(chip); 6772 return err; 6773 } 6774 6775 static int mv88e6xxx_crosschip_lag_leave(struct dsa_switch *ds, int sw_index, 6776 int port, struct dsa_lag lag) 6777 { 6778 struct mv88e6xxx_chip *chip = ds->priv; 6779 int err_sync, err_pvt; 6780 6781 mv88e6xxx_reg_lock(chip); 6782 err_sync = mv88e6xxx_lag_sync_masks_map(ds, lag); 6783 err_pvt = mv88e6xxx_pvt_map(chip, sw_index, port); 6784 mv88e6xxx_reg_unlock(chip); 6785 return err_sync ? : err_pvt; 6786 } 6787 6788 static const struct dsa_switch_ops mv88e6xxx_switch_ops = { 6789 .get_tag_protocol = mv88e6xxx_get_tag_protocol, 6790 .change_tag_protocol = mv88e6xxx_change_tag_protocol, 6791 .setup = mv88e6xxx_setup, 6792 .teardown = mv88e6xxx_teardown, 6793 .port_setup = mv88e6xxx_port_setup, 6794 .port_teardown = mv88e6xxx_port_teardown, 6795 .phylink_get_caps = mv88e6xxx_get_caps, 6796 .phylink_mac_select_pcs = mv88e6xxx_mac_select_pcs, 6797 .phylink_mac_prepare = mv88e6xxx_mac_prepare, 6798 .phylink_mac_config = mv88e6xxx_mac_config, 6799 .phylink_mac_finish = mv88e6xxx_mac_finish, 6800 .phylink_mac_link_down = mv88e6xxx_mac_link_down, 6801 .phylink_mac_link_up = mv88e6xxx_mac_link_up, 6802 .get_strings = mv88e6xxx_get_strings, 6803 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats, 6804 .get_sset_count = mv88e6xxx_get_sset_count, 6805 .port_max_mtu = mv88e6xxx_get_max_mtu, 6806 .port_change_mtu = mv88e6xxx_change_mtu, 6807 .get_mac_eee = mv88e6xxx_get_mac_eee, 6808 .set_mac_eee = mv88e6xxx_set_mac_eee, 6809 .get_eeprom_len = mv88e6xxx_get_eeprom_len, 6810 .get_eeprom = mv88e6xxx_get_eeprom, 6811 .set_eeprom = mv88e6xxx_set_eeprom, 6812 .get_regs_len = mv88e6xxx_get_regs_len, 6813 .get_regs = mv88e6xxx_get_regs, 6814 .get_rxnfc = mv88e6xxx_get_rxnfc, 6815 .set_rxnfc = mv88e6xxx_set_rxnfc, 6816 .set_ageing_time = mv88e6xxx_set_ageing_time, 6817 .port_bridge_join = mv88e6xxx_port_bridge_join, 6818 .port_bridge_leave = mv88e6xxx_port_bridge_leave, 6819 .port_pre_bridge_flags = mv88e6xxx_port_pre_bridge_flags, 6820 .port_bridge_flags = mv88e6xxx_port_bridge_flags, 6821 .port_stp_state_set = mv88e6xxx_port_stp_state_set, 6822 .port_mst_state_set = mv88e6xxx_port_mst_state_set, 6823 .port_fast_age = mv88e6xxx_port_fast_age, 6824 .port_vlan_fast_age = mv88e6xxx_port_vlan_fast_age, 6825 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering, 6826 .port_vlan_add = mv88e6xxx_port_vlan_add, 6827 .port_vlan_del = mv88e6xxx_port_vlan_del, 6828 .vlan_msti_set = mv88e6xxx_vlan_msti_set, 6829 .port_fdb_add = mv88e6xxx_port_fdb_add, 6830 .port_fdb_del = mv88e6xxx_port_fdb_del, 6831 .port_fdb_dump = mv88e6xxx_port_fdb_dump, 6832 .port_mdb_add = mv88e6xxx_port_mdb_add, 6833 .port_mdb_del = mv88e6xxx_port_mdb_del, 6834 .port_mirror_add = mv88e6xxx_port_mirror_add, 6835 .port_mirror_del = mv88e6xxx_port_mirror_del, 6836 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join, 6837 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave, 6838 .port_hwtstamp_set = mv88e6xxx_port_hwtstamp_set, 6839 .port_hwtstamp_get = mv88e6xxx_port_hwtstamp_get, 6840 .port_txtstamp = mv88e6xxx_port_txtstamp, 6841 .port_rxtstamp = mv88e6xxx_port_rxtstamp, 6842 .get_ts_info = mv88e6xxx_get_ts_info, 6843 .devlink_param_get = mv88e6xxx_devlink_param_get, 6844 .devlink_param_set = mv88e6xxx_devlink_param_set, 6845 .devlink_info_get = mv88e6xxx_devlink_info_get, 6846 .port_lag_change = mv88e6xxx_port_lag_change, 6847 .port_lag_join = mv88e6xxx_port_lag_join, 6848 .port_lag_leave = mv88e6xxx_port_lag_leave, 6849 .crosschip_lag_change = mv88e6xxx_crosschip_lag_change, 6850 .crosschip_lag_join = mv88e6xxx_crosschip_lag_join, 6851 .crosschip_lag_leave = mv88e6xxx_crosschip_lag_leave, 6852 }; 6853 6854 static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip) 6855 { 6856 struct device *dev = chip->dev; 6857 struct dsa_switch *ds; 6858 6859 ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL); 6860 if (!ds) 6861 return -ENOMEM; 6862 6863 ds->dev = dev; 6864 ds->num_ports = mv88e6xxx_num_ports(chip); 6865 ds->priv = chip; 6866 ds->dev = dev; 6867 ds->ops = &mv88e6xxx_switch_ops; 6868 ds->ageing_time_min = chip->info->age_time_coeff; 6869 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX; 6870 6871 /* Some chips support up to 32, but that requires enabling the 6872 * 5-bit port mode, which we do not support. 640k^W16 ought to 6873 * be enough for anyone. 6874 */ 6875 ds->num_lag_ids = mv88e6xxx_has_lag(chip) ? 16 : 0; 6876 6877 dev_set_drvdata(dev, ds); 6878 6879 return dsa_register_switch(ds); 6880 } 6881 6882 static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip) 6883 { 6884 dsa_unregister_switch(chip->ds); 6885 } 6886 6887 static const void *pdata_device_get_match_data(struct device *dev) 6888 { 6889 const struct of_device_id *matches = dev->driver->of_match_table; 6890 const struct dsa_mv88e6xxx_pdata *pdata = dev->platform_data; 6891 6892 for (; matches->name[0] || matches->type[0] || matches->compatible[0]; 6893 matches++) { 6894 if (!strcmp(pdata->compatible, matches->compatible)) 6895 return matches->data; 6896 } 6897 return NULL; 6898 } 6899 6900 /* There is no suspend to RAM support at DSA level yet, the switch configuration 6901 * would be lost after a power cycle so prevent it to be suspended. 6902 */ 6903 static int __maybe_unused mv88e6xxx_suspend(struct device *dev) 6904 { 6905 return -EOPNOTSUPP; 6906 } 6907 6908 static int __maybe_unused mv88e6xxx_resume(struct device *dev) 6909 { 6910 return 0; 6911 } 6912 6913 static SIMPLE_DEV_PM_OPS(mv88e6xxx_pm_ops, mv88e6xxx_suspend, mv88e6xxx_resume); 6914 6915 static int mv88e6xxx_probe(struct mdio_device *mdiodev) 6916 { 6917 struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data; 6918 const struct mv88e6xxx_info *compat_info = NULL; 6919 struct device *dev = &mdiodev->dev; 6920 struct device_node *np = dev->of_node; 6921 struct mv88e6xxx_chip *chip; 6922 int port; 6923 int err; 6924 6925 if (!np && !pdata) 6926 return -EINVAL; 6927 6928 if (np) 6929 compat_info = of_device_get_match_data(dev); 6930 6931 if (pdata) { 6932 compat_info = pdata_device_get_match_data(dev); 6933 6934 if (!pdata->netdev) 6935 return -EINVAL; 6936 6937 for (port = 0; port < DSA_MAX_PORTS; port++) { 6938 if (!(pdata->enabled_ports & (1 << port))) 6939 continue; 6940 if (strcmp(pdata->cd.port_names[port], "cpu")) 6941 continue; 6942 pdata->cd.netdev[port] = &pdata->netdev->dev; 6943 break; 6944 } 6945 } 6946 6947 if (!compat_info) 6948 return -EINVAL; 6949 6950 chip = mv88e6xxx_alloc_chip(dev); 6951 if (!chip) { 6952 err = -ENOMEM; 6953 goto out; 6954 } 6955 6956 chip->info = compat_info; 6957 6958 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); 6959 if (IS_ERR(chip->reset)) { 6960 err = PTR_ERR(chip->reset); 6961 goto out; 6962 } 6963 if (chip->reset) 6964 usleep_range(10000, 20000); 6965 6966 /* Detect if the device is configured in single chip addressing mode, 6967 * otherwise continue with address specific smi init/detection. 6968 */ 6969 err = mv88e6xxx_single_chip_detect(chip, mdiodev); 6970 if (err) { 6971 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr); 6972 if (err) 6973 goto out; 6974 6975 err = mv88e6xxx_detect(chip); 6976 if (err) 6977 goto out; 6978 } 6979 6980 if (chip->info->edsa_support == MV88E6XXX_EDSA_SUPPORTED) 6981 chip->tag_protocol = DSA_TAG_PROTO_EDSA; 6982 else 6983 chip->tag_protocol = DSA_TAG_PROTO_DSA; 6984 6985 mv88e6xxx_phy_init(chip); 6986 6987 if (chip->info->ops->get_eeprom) { 6988 if (np) 6989 of_property_read_u32(np, "eeprom-length", 6990 &chip->eeprom_len); 6991 else 6992 chip->eeprom_len = pdata->eeprom_len; 6993 } 6994 6995 mv88e6xxx_reg_lock(chip); 6996 err = mv88e6xxx_switch_reset(chip); 6997 mv88e6xxx_reg_unlock(chip); 6998 if (err) 6999 goto out; 7000 7001 if (np) { 7002 chip->irq = of_irq_get(np, 0); 7003 if (chip->irq == -EPROBE_DEFER) { 7004 err = chip->irq; 7005 goto out; 7006 } 7007 } 7008 7009 if (pdata) 7010 chip->irq = pdata->irq; 7011 7012 /* Has to be performed before the MDIO bus is created, because 7013 * the PHYs will link their interrupts to these interrupt 7014 * controllers 7015 */ 7016 mv88e6xxx_reg_lock(chip); 7017 if (chip->irq > 0) 7018 err = mv88e6xxx_g1_irq_setup(chip); 7019 else 7020 err = mv88e6xxx_irq_poll_setup(chip); 7021 mv88e6xxx_reg_unlock(chip); 7022 7023 if (err) 7024 goto out; 7025 7026 if (chip->info->g2_irqs > 0) { 7027 err = mv88e6xxx_g2_irq_setup(chip); 7028 if (err) 7029 goto out_g1_irq; 7030 } 7031 7032 err = mv88e6xxx_g1_atu_prob_irq_setup(chip); 7033 if (err) 7034 goto out_g2_irq; 7035 7036 err = mv88e6xxx_g1_vtu_prob_irq_setup(chip); 7037 if (err) 7038 goto out_g1_atu_prob_irq; 7039 7040 err = mv88e6xxx_register_switch(chip); 7041 if (err) 7042 goto out_g1_vtu_prob_irq; 7043 7044 return 0; 7045 7046 out_g1_vtu_prob_irq: 7047 mv88e6xxx_g1_vtu_prob_irq_free(chip); 7048 out_g1_atu_prob_irq: 7049 mv88e6xxx_g1_atu_prob_irq_free(chip); 7050 out_g2_irq: 7051 if (chip->info->g2_irqs > 0) 7052 mv88e6xxx_g2_irq_free(chip); 7053 out_g1_irq: 7054 if (chip->irq > 0) 7055 mv88e6xxx_g1_irq_free(chip); 7056 else 7057 mv88e6xxx_irq_poll_free(chip); 7058 out: 7059 if (pdata) 7060 dev_put(pdata->netdev); 7061 7062 return err; 7063 } 7064 7065 static void mv88e6xxx_remove(struct mdio_device *mdiodev) 7066 { 7067 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev); 7068 struct mv88e6xxx_chip *chip; 7069 7070 if (!ds) 7071 return; 7072 7073 chip = ds->priv; 7074 7075 if (chip->info->ptp_support) { 7076 mv88e6xxx_hwtstamp_free(chip); 7077 mv88e6xxx_ptp_free(chip); 7078 } 7079 7080 mv88e6xxx_phy_destroy(chip); 7081 mv88e6xxx_unregister_switch(chip); 7082 7083 mv88e6xxx_g1_vtu_prob_irq_free(chip); 7084 mv88e6xxx_g1_atu_prob_irq_free(chip); 7085 7086 if (chip->info->g2_irqs > 0) 7087 mv88e6xxx_g2_irq_free(chip); 7088 7089 if (chip->irq > 0) 7090 mv88e6xxx_g1_irq_free(chip); 7091 else 7092 mv88e6xxx_irq_poll_free(chip); 7093 } 7094 7095 static void mv88e6xxx_shutdown(struct mdio_device *mdiodev) 7096 { 7097 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev); 7098 7099 if (!ds) 7100 return; 7101 7102 dsa_switch_shutdown(ds); 7103 7104 dev_set_drvdata(&mdiodev->dev, NULL); 7105 } 7106 7107 static const struct of_device_id mv88e6xxx_of_match[] = { 7108 { 7109 .compatible = "marvell,mv88e6085", 7110 .data = &mv88e6xxx_table[MV88E6085], 7111 }, 7112 { 7113 .compatible = "marvell,mv88e6190", 7114 .data = &mv88e6xxx_table[MV88E6190], 7115 }, 7116 { 7117 .compatible = "marvell,mv88e6250", 7118 .data = &mv88e6xxx_table[MV88E6250], 7119 }, 7120 { /* sentinel */ }, 7121 }; 7122 7123 MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match); 7124 7125 static struct mdio_driver mv88e6xxx_driver = { 7126 .probe = mv88e6xxx_probe, 7127 .remove = mv88e6xxx_remove, 7128 .shutdown = mv88e6xxx_shutdown, 7129 .mdiodrv.driver = { 7130 .name = "mv88e6085", 7131 .of_match_table = mv88e6xxx_of_match, 7132 .pm = &mv88e6xxx_pm_ops, 7133 }, 7134 }; 7135 7136 mdio_module_driver(mv88e6xxx_driver); 7137 7138 MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>"); 7139 MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips"); 7140 MODULE_LICENSE("GPL"); 7141