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