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