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