.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Broadcom Starfighter 2 DSA switch driver |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2014, Broadcom Corporation |
---|
5 | | - * |
---|
6 | | - * This program is free software; you can redistribute it and/or modify |
---|
7 | | - * it under the terms of the GNU General Public License as published by |
---|
8 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
9 | | - * (at your option) any later version. |
---|
10 | 6 | */ |
---|
11 | 7 | |
---|
12 | 8 | #include <linux/list.h> |
---|
.. | .. |
---|
18 | 14 | #include <linux/phy_fixed.h> |
---|
19 | 15 | #include <linux/phylink.h> |
---|
20 | 16 | #include <linux/mii.h> |
---|
| 17 | +#include <linux/clk.h> |
---|
21 | 18 | #include <linux/of.h> |
---|
22 | 19 | #include <linux/of_irq.h> |
---|
23 | 20 | #include <linux/of_address.h> |
---|
.. | .. |
---|
34 | 31 | #include "bcm_sf2_regs.h" |
---|
35 | 32 | #include "b53/b53_priv.h" |
---|
36 | 33 | #include "b53/b53_regs.h" |
---|
| 34 | + |
---|
| 35 | +/* Return the number of active ports, not counting the IMP (CPU) port */ |
---|
| 36 | +static unsigned int bcm_sf2_num_active_ports(struct dsa_switch *ds) |
---|
| 37 | +{ |
---|
| 38 | + struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
---|
| 39 | + unsigned int port, count = 0; |
---|
| 40 | + |
---|
| 41 | + for (port = 0; port < ds->num_ports; port++) { |
---|
| 42 | + if (dsa_is_cpu_port(ds, port)) |
---|
| 43 | + continue; |
---|
| 44 | + if (priv->port_sts[port].enabled) |
---|
| 45 | + count++; |
---|
| 46 | + } |
---|
| 47 | + |
---|
| 48 | + return count; |
---|
| 49 | +} |
---|
| 50 | + |
---|
| 51 | +static void bcm_sf2_recalc_clock(struct dsa_switch *ds) |
---|
| 52 | +{ |
---|
| 53 | + struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
---|
| 54 | + unsigned long new_rate; |
---|
| 55 | + unsigned int ports_active; |
---|
| 56 | + /* Frequenty in Mhz */ |
---|
| 57 | + static const unsigned long rate_table[] = { |
---|
| 58 | + 59220000, |
---|
| 59 | + 60820000, |
---|
| 60 | + 62500000, |
---|
| 61 | + 62500000, |
---|
| 62 | + }; |
---|
| 63 | + |
---|
| 64 | + ports_active = bcm_sf2_num_active_ports(ds); |
---|
| 65 | + if (ports_active == 0 || !priv->clk_mdiv) |
---|
| 66 | + return; |
---|
| 67 | + |
---|
| 68 | + /* If we overflow our table, just use the recommended operational |
---|
| 69 | + * frequency |
---|
| 70 | + */ |
---|
| 71 | + if (ports_active > ARRAY_SIZE(rate_table)) |
---|
| 72 | + new_rate = 90000000; |
---|
| 73 | + else |
---|
| 74 | + new_rate = rate_table[ports_active - 1]; |
---|
| 75 | + clk_set_rate(priv->clk_mdiv, new_rate); |
---|
| 76 | +} |
---|
37 | 77 | |
---|
38 | 78 | static void bcm_sf2_imp_setup(struct dsa_switch *ds, int port) |
---|
39 | 79 | { |
---|
.. | .. |
---|
86 | 126 | reg &= ~(RX_DIS | TX_DIS); |
---|
87 | 127 | core_writel(priv, reg, CORE_G_PCTL_PORT(port)); |
---|
88 | 128 | } |
---|
| 129 | + |
---|
| 130 | + priv->port_sts[port].enabled = true; |
---|
89 | 131 | } |
---|
90 | 132 | |
---|
91 | 133 | static void bcm_sf2_gphy_enable_set(struct dsa_switch *ds, bool enable) |
---|
.. | .. |
---|
168 | 210 | unsigned int i; |
---|
169 | 211 | u32 reg; |
---|
170 | 212 | |
---|
| 213 | + if (!dsa_is_user_port(ds, port)) |
---|
| 214 | + return 0; |
---|
| 215 | + |
---|
| 216 | + priv->port_sts[port].enabled = true; |
---|
| 217 | + |
---|
| 218 | + bcm_sf2_recalc_clock(ds); |
---|
| 219 | + |
---|
171 | 220 | /* Clear the memory power down */ |
---|
172 | 221 | reg = core_readl(priv, CORE_MEM_PSM_VDD_CTRL); |
---|
173 | 222 | reg &= ~P_TXQ_PSM_VDD(port); |
---|
.. | .. |
---|
223 | 272 | return b53_enable_port(ds, port, phy); |
---|
224 | 273 | } |
---|
225 | 274 | |
---|
226 | | -static void bcm_sf2_port_disable(struct dsa_switch *ds, int port, |
---|
227 | | - struct phy_device *phy) |
---|
| 275 | +static void bcm_sf2_port_disable(struct dsa_switch *ds, int port) |
---|
228 | 276 | { |
---|
229 | 277 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
---|
230 | 278 | u32 reg; |
---|
.. | .. |
---|
243 | 291 | if (priv->int_phy_mask & 1 << port && priv->hw_params.num_gphy == 1) |
---|
244 | 292 | bcm_sf2_gphy_enable_set(ds, false); |
---|
245 | 293 | |
---|
246 | | - b53_disable_port(ds, port, phy); |
---|
| 294 | + b53_disable_port(ds, port); |
---|
247 | 295 | |
---|
248 | 296 | /* Power down the port memory */ |
---|
249 | 297 | reg = core_readl(priv, CORE_MEM_PSM_VDD_CTRL); |
---|
250 | 298 | reg |= P_TXQ_PSM_VDD(port); |
---|
251 | 299 | core_writel(priv, reg, CORE_MEM_PSM_VDD_CTRL); |
---|
| 300 | + |
---|
| 301 | + priv->port_sts[port].enabled = false; |
---|
| 302 | + |
---|
| 303 | + bcm_sf2_recalc_clock(ds); |
---|
252 | 304 | } |
---|
253 | 305 | |
---|
254 | 306 | |
---|
.. | .. |
---|
348 | 400 | { |
---|
349 | 401 | unsigned int timeout = 1000; |
---|
350 | 402 | u32 reg; |
---|
| 403 | + int ret; |
---|
| 404 | + |
---|
| 405 | + /* The watchdog reset does not work on 7278, we need to hit the |
---|
| 406 | + * "external" reset line through the reset controller. |
---|
| 407 | + */ |
---|
| 408 | + if (priv->type == BCM7278_DEVICE_ID && !IS_ERR(priv->rcdev)) { |
---|
| 409 | + ret = reset_control_assert(priv->rcdev); |
---|
| 410 | + if (ret) |
---|
| 411 | + return ret; |
---|
| 412 | + |
---|
| 413 | + return reset_control_deassert(priv->rcdev); |
---|
| 414 | + } |
---|
351 | 415 | |
---|
352 | 416 | reg = core_readl(priv, CORE_WATCHDOG_CTRL); |
---|
353 | 417 | reg |= SOFTWARE_RESET | EN_CHIP_RST | EN_SW_RESET; |
---|
.. | .. |
---|
379 | 443 | struct device_node *dn) |
---|
380 | 444 | { |
---|
381 | 445 | struct device_node *port; |
---|
382 | | - int mode; |
---|
383 | 446 | unsigned int port_num; |
---|
| 447 | + struct property *prop; |
---|
| 448 | + phy_interface_t mode; |
---|
| 449 | + int err; |
---|
384 | 450 | |
---|
385 | 451 | priv->moca_port = -1; |
---|
386 | 452 | |
---|
.. | .. |
---|
393 | 459 | * has completed, since they might be turned off at that |
---|
394 | 460 | * time |
---|
395 | 461 | */ |
---|
396 | | - mode = of_get_phy_mode(port); |
---|
397 | | - if (mode < 0) |
---|
| 462 | + err = of_get_phy_mode(port, &mode); |
---|
| 463 | + if (err) |
---|
398 | 464 | continue; |
---|
399 | 465 | |
---|
400 | 466 | if (mode == PHY_INTERFACE_MODE_INTERNAL) |
---|
.. | .. |
---|
405 | 471 | |
---|
406 | 472 | if (of_property_read_bool(port, "brcm,use-bcm-hdr")) |
---|
407 | 473 | priv->brcm_tag_mask |= 1 << port_num; |
---|
| 474 | + |
---|
| 475 | + /* Ensure that port 5 is not picked up as a DSA CPU port |
---|
| 476 | + * flavour but a regular port instead. We should be using |
---|
| 477 | + * devlink to be able to set the port flavour. |
---|
| 478 | + */ |
---|
| 479 | + if (port_num == 5 && priv->type == BCM7278_DEVICE_ID) { |
---|
| 480 | + prop = of_find_property(port, "ethernet", NULL); |
---|
| 481 | + if (prop) |
---|
| 482 | + of_remove_property(port, prop); |
---|
| 483 | + } |
---|
408 | 484 | } |
---|
409 | 485 | } |
---|
410 | 486 | |
---|
411 | 487 | static int bcm_sf2_mdio_register(struct dsa_switch *ds) |
---|
412 | 488 | { |
---|
413 | 489 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
---|
414 | | - struct device_node *dn; |
---|
| 490 | + struct device_node *dn, *child; |
---|
| 491 | + struct phy_device *phydev; |
---|
| 492 | + struct property *prop; |
---|
415 | 493 | static int index; |
---|
416 | | - int err; |
---|
| 494 | + int err, reg; |
---|
417 | 495 | |
---|
418 | 496 | /* Find our integrated MDIO bus node */ |
---|
419 | 497 | dn = of_find_compatible_node(NULL, NULL, "brcm,unimac-mdio"); |
---|
.. | .. |
---|
426 | 504 | get_device(&priv->master_mii_bus->dev); |
---|
427 | 505 | priv->master_mii_dn = dn; |
---|
428 | 506 | |
---|
429 | | - priv->slave_mii_bus = devm_mdiobus_alloc(ds->dev); |
---|
| 507 | + priv->slave_mii_bus = mdiobus_alloc(); |
---|
430 | 508 | if (!priv->slave_mii_bus) { |
---|
431 | 509 | of_node_put(dn); |
---|
432 | 510 | return -ENOMEM; |
---|
.. | .. |
---|
451 | 529 | * driver. |
---|
452 | 530 | */ |
---|
453 | 531 | if (of_machine_is_compatible("brcm,bcm7445d0")) |
---|
454 | | - priv->indir_phy_mask |= (1 << BRCM_PSEUDO_PHY_ADDR); |
---|
| 532 | + priv->indir_phy_mask |= (1 << BRCM_PSEUDO_PHY_ADDR) | (1 << 0); |
---|
455 | 533 | else |
---|
456 | 534 | priv->indir_phy_mask = 0; |
---|
457 | 535 | |
---|
.. | .. |
---|
460 | 538 | priv->slave_mii_bus->parent = ds->dev->parent; |
---|
461 | 539 | priv->slave_mii_bus->phy_mask = ~priv->indir_phy_mask; |
---|
462 | 540 | |
---|
| 541 | + /* We need to make sure that of_phy_connect() will not work by |
---|
| 542 | + * removing the 'phandle' and 'linux,phandle' properties and |
---|
| 543 | + * unregister the existing PHY device that was already registered. |
---|
| 544 | + */ |
---|
| 545 | + for_each_available_child_of_node(dn, child) { |
---|
| 546 | + if (of_property_read_u32(child, "reg", ®) || |
---|
| 547 | + reg >= PHY_MAX_ADDR) |
---|
| 548 | + continue; |
---|
| 549 | + |
---|
| 550 | + if (!(priv->indir_phy_mask & BIT(reg))) |
---|
| 551 | + continue; |
---|
| 552 | + |
---|
| 553 | + prop = of_find_property(child, "phandle", NULL); |
---|
| 554 | + if (prop) |
---|
| 555 | + of_remove_property(child, prop); |
---|
| 556 | + |
---|
| 557 | + prop = of_find_property(child, "linux,phandle", NULL); |
---|
| 558 | + if (prop) |
---|
| 559 | + of_remove_property(child, prop); |
---|
| 560 | + |
---|
| 561 | + phydev = of_phy_find_device(child); |
---|
| 562 | + if (phydev) |
---|
| 563 | + phy_device_remove(phydev); |
---|
| 564 | + } |
---|
| 565 | + |
---|
463 | 566 | err = mdiobus_register(priv->slave_mii_bus); |
---|
464 | | - if (err && dn) |
---|
| 567 | + if (err && dn) { |
---|
| 568 | + mdiobus_free(priv->slave_mii_bus); |
---|
465 | 569 | of_node_put(dn); |
---|
| 570 | + } |
---|
466 | 571 | |
---|
467 | 572 | return err; |
---|
468 | 573 | } |
---|
.. | .. |
---|
470 | 575 | static void bcm_sf2_mdio_unregister(struct bcm_sf2_priv *priv) |
---|
471 | 576 | { |
---|
472 | 577 | mdiobus_unregister(priv->slave_mii_bus); |
---|
473 | | - if (priv->master_mii_dn) |
---|
474 | | - of_node_put(priv->master_mii_dn); |
---|
| 578 | + mdiobus_free(priv->slave_mii_bus); |
---|
| 579 | + of_node_put(priv->master_mii_dn); |
---|
475 | 580 | } |
---|
476 | 581 | |
---|
477 | 582 | static u32 bcm_sf2_sw_get_phy_flags(struct dsa_switch *ds, int port) |
---|
.. | .. |
---|
492 | 597 | unsigned long *supported, |
---|
493 | 598 | struct phylink_link_state *state) |
---|
494 | 599 | { |
---|
| 600 | + struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
---|
495 | 601 | __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, }; |
---|
496 | 602 | |
---|
497 | 603 | if (!phy_interface_mode_is_rgmii(state->interface) && |
---|
.. | .. |
---|
501 | 607 | state->interface != PHY_INTERFACE_MODE_INTERNAL && |
---|
502 | 608 | state->interface != PHY_INTERFACE_MODE_MOCA) { |
---|
503 | 609 | bitmap_zero(supported, __ETHTOOL_LINK_MODE_MASK_NBITS); |
---|
504 | | - dev_err(ds->dev, |
---|
505 | | - "Unsupported interface: %d\n", state->interface); |
---|
| 610 | + if (port != core_readl(priv, CORE_IMP0_PRT_ID)) |
---|
| 611 | + dev_err(ds->dev, |
---|
| 612 | + "Unsupported interface: %d for port %d\n", |
---|
| 613 | + state->interface, port); |
---|
506 | 614 | return; |
---|
507 | 615 | } |
---|
508 | 616 | |
---|
.. | .. |
---|
538 | 646 | { |
---|
539 | 647 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
---|
540 | 648 | u32 id_mode_dis = 0, port_mode; |
---|
541 | | - u32 reg, offset; |
---|
| 649 | + u32 reg; |
---|
542 | 650 | |
---|
543 | | - if (priv->type == BCM7445_DEVICE_ID) |
---|
544 | | - offset = CORE_STS_OVERRIDE_GMIIP_PORT(port); |
---|
545 | | - else |
---|
546 | | - offset = CORE_STS_OVERRIDE_GMIIP2_PORT(port); |
---|
| 651 | + if (port == core_readl(priv, CORE_IMP0_PRT_ID)) |
---|
| 652 | + return; |
---|
547 | 653 | |
---|
548 | 654 | switch (state->interface) { |
---|
549 | 655 | case PHY_INTERFACE_MODE_RGMII: |
---|
550 | 656 | id_mode_dis = 1; |
---|
551 | | - /* fallthrough */ |
---|
| 657 | + fallthrough; |
---|
552 | 658 | case PHY_INTERFACE_MODE_RGMII_TXID: |
---|
553 | 659 | port_mode = EXT_GPHY; |
---|
554 | 660 | break; |
---|
.. | .. |
---|
559 | 665 | port_mode = EXT_REVMII; |
---|
560 | 666 | break; |
---|
561 | 667 | default: |
---|
562 | | - /* all other PHYs: internal and MoCA */ |
---|
563 | | - goto force_link; |
---|
| 668 | + /* Nothing required for all other PHYs: internal and MoCA */ |
---|
| 669 | + return; |
---|
564 | 670 | } |
---|
565 | 671 | |
---|
566 | 672 | /* Clear id_mode_dis bit, and the existing port mode, let |
---|
.. | .. |
---|
569 | 675 | reg = reg_readl(priv, REG_RGMII_CNTRL_P(port)); |
---|
570 | 676 | reg &= ~ID_MODE_DIS; |
---|
571 | 677 | reg &= ~(PORT_MODE_MASK << PORT_MODE_SHIFT); |
---|
572 | | - reg &= ~(RX_PAUSE_EN | TX_PAUSE_EN); |
---|
573 | 678 | |
---|
574 | 679 | reg |= port_mode; |
---|
575 | 680 | if (id_mode_dis) |
---|
576 | 681 | reg |= ID_MODE_DIS; |
---|
577 | 682 | |
---|
578 | | - if (state->pause & MLO_PAUSE_TXRX_MASK) { |
---|
579 | | - if (state->pause & MLO_PAUSE_TX) |
---|
580 | | - reg |= TX_PAUSE_EN; |
---|
581 | | - reg |= RX_PAUSE_EN; |
---|
582 | | - } |
---|
583 | | - |
---|
584 | 683 | reg_writel(priv, reg, REG_RGMII_CNTRL_P(port)); |
---|
585 | | - |
---|
586 | | -force_link: |
---|
587 | | - /* Force link settings detected from the PHY */ |
---|
588 | | - reg = SW_OVERRIDE; |
---|
589 | | - switch (state->speed) { |
---|
590 | | - case SPEED_1000: |
---|
591 | | - reg |= SPDSTS_1000 << SPEED_SHIFT; |
---|
592 | | - break; |
---|
593 | | - case SPEED_100: |
---|
594 | | - reg |= SPDSTS_100 << SPEED_SHIFT; |
---|
595 | | - break; |
---|
596 | | - } |
---|
597 | | - |
---|
598 | | - if (state->link) |
---|
599 | | - reg |= LINK_STS; |
---|
600 | | - if (state->duplex == DUPLEX_FULL) |
---|
601 | | - reg |= DUPLX_MODE; |
---|
602 | | - |
---|
603 | | - core_writel(priv, reg, offset); |
---|
604 | 684 | } |
---|
605 | 685 | |
---|
606 | 686 | static void bcm_sf2_sw_mac_link_set(struct dsa_switch *ds, int port, |
---|
.. | .. |
---|
627 | 707 | unsigned int mode, |
---|
628 | 708 | phy_interface_t interface) |
---|
629 | 709 | { |
---|
| 710 | + struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
---|
| 711 | + u32 reg, offset; |
---|
| 712 | + |
---|
| 713 | + if (priv->wol_ports_mask & BIT(port)) |
---|
| 714 | + return; |
---|
| 715 | + |
---|
| 716 | + if (port != core_readl(priv, CORE_IMP0_PRT_ID)) { |
---|
| 717 | + if (priv->type == BCM7445_DEVICE_ID) |
---|
| 718 | + offset = CORE_STS_OVERRIDE_GMIIP_PORT(port); |
---|
| 719 | + else |
---|
| 720 | + offset = CORE_STS_OVERRIDE_GMIIP2_PORT(port); |
---|
| 721 | + |
---|
| 722 | + reg = core_readl(priv, offset); |
---|
| 723 | + reg &= ~LINK_STS; |
---|
| 724 | + core_writel(priv, reg, offset); |
---|
| 725 | + } |
---|
| 726 | + |
---|
630 | 727 | bcm_sf2_sw_mac_link_set(ds, port, interface, false); |
---|
631 | 728 | } |
---|
632 | 729 | |
---|
633 | 730 | static void bcm_sf2_sw_mac_link_up(struct dsa_switch *ds, int port, |
---|
634 | 731 | unsigned int mode, |
---|
635 | 732 | phy_interface_t interface, |
---|
636 | | - struct phy_device *phydev) |
---|
| 733 | + struct phy_device *phydev, |
---|
| 734 | + int speed, int duplex, |
---|
| 735 | + bool tx_pause, bool rx_pause) |
---|
637 | 736 | { |
---|
638 | 737 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
---|
639 | 738 | struct ethtool_eee *p = &priv->dev->ports[port].eee; |
---|
| 739 | + u32 reg, offset; |
---|
640 | 740 | |
---|
641 | 741 | bcm_sf2_sw_mac_link_set(ds, port, interface, true); |
---|
| 742 | + |
---|
| 743 | + if (port != core_readl(priv, CORE_IMP0_PRT_ID)) { |
---|
| 744 | + if (priv->type == BCM7445_DEVICE_ID) |
---|
| 745 | + offset = CORE_STS_OVERRIDE_GMIIP_PORT(port); |
---|
| 746 | + else |
---|
| 747 | + offset = CORE_STS_OVERRIDE_GMIIP2_PORT(port); |
---|
| 748 | + |
---|
| 749 | + if (interface == PHY_INTERFACE_MODE_RGMII || |
---|
| 750 | + interface == PHY_INTERFACE_MODE_RGMII_TXID || |
---|
| 751 | + interface == PHY_INTERFACE_MODE_MII || |
---|
| 752 | + interface == PHY_INTERFACE_MODE_REVMII) { |
---|
| 753 | + reg = reg_readl(priv, REG_RGMII_CNTRL_P(port)); |
---|
| 754 | + reg &= ~(RX_PAUSE_EN | TX_PAUSE_EN); |
---|
| 755 | + |
---|
| 756 | + if (tx_pause) |
---|
| 757 | + reg |= TX_PAUSE_EN; |
---|
| 758 | + if (rx_pause) |
---|
| 759 | + reg |= RX_PAUSE_EN; |
---|
| 760 | + |
---|
| 761 | + reg_writel(priv, reg, REG_RGMII_CNTRL_P(port)); |
---|
| 762 | + } |
---|
| 763 | + |
---|
| 764 | + reg = SW_OVERRIDE | LINK_STS; |
---|
| 765 | + switch (speed) { |
---|
| 766 | + case SPEED_1000: |
---|
| 767 | + reg |= SPDSTS_1000 << SPEED_SHIFT; |
---|
| 768 | + break; |
---|
| 769 | + case SPEED_100: |
---|
| 770 | + reg |= SPDSTS_100 << SPEED_SHIFT; |
---|
| 771 | + break; |
---|
| 772 | + } |
---|
| 773 | + |
---|
| 774 | + if (duplex == DUPLEX_FULL) |
---|
| 775 | + reg |= DUPLX_MODE; |
---|
| 776 | + |
---|
| 777 | + if (tx_pause) |
---|
| 778 | + reg |= TXFLOW_CNTL; |
---|
| 779 | + if (rx_pause) |
---|
| 780 | + reg |= RXFLOW_CNTL; |
---|
| 781 | + |
---|
| 782 | + core_writel(priv, reg, offset); |
---|
| 783 | + } |
---|
642 | 784 | |
---|
643 | 785 | if (mode == MLO_AN_PHY && phydev) |
---|
644 | 786 | p->eee_enabled = b53_eee_init(ds, port, phydev); |
---|
.. | .. |
---|
667 | 809 | * state machine and make it go in PHY_FORCING state instead. |
---|
668 | 810 | */ |
---|
669 | 811 | if (!status->link) |
---|
670 | | - netif_carrier_off(ds->ports[port].slave); |
---|
| 812 | + netif_carrier_off(dsa_to_port(ds, port)->slave); |
---|
671 | 813 | status->duplex = DUPLEX_FULL; |
---|
672 | 814 | } else { |
---|
673 | 815 | status->link = true; |
---|
.. | .. |
---|
701 | 843 | */ |
---|
702 | 844 | for (port = 0; port < ds->num_ports; port++) { |
---|
703 | 845 | if (dsa_is_user_port(ds, port) || dsa_is_cpu_port(ds, port)) |
---|
704 | | - bcm_sf2_port_disable(ds, port, NULL); |
---|
| 846 | + bcm_sf2_port_disable(ds, port); |
---|
705 | 847 | } |
---|
| 848 | + |
---|
| 849 | + if (!priv->wol_ports_mask) |
---|
| 850 | + clk_disable_unprepare(priv->clk); |
---|
706 | 851 | |
---|
707 | 852 | return 0; |
---|
708 | 853 | } |
---|
.. | .. |
---|
712 | 857 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
---|
713 | 858 | int ret; |
---|
714 | 859 | |
---|
| 860 | + if (!priv->wol_ports_mask) |
---|
| 861 | + clk_prepare_enable(priv->clk); |
---|
| 862 | + |
---|
715 | 863 | ret = bcm_sf2_sw_rst(priv); |
---|
716 | 864 | if (ret) { |
---|
717 | 865 | pr_err("%s: failed to software reset switch\n", __func__); |
---|
718 | 866 | return ret; |
---|
719 | 867 | } |
---|
| 868 | + |
---|
| 869 | + ret = bcm_sf2_cfp_resume(ds); |
---|
| 870 | + if (ret) |
---|
| 871 | + return ret; |
---|
720 | 872 | |
---|
721 | 873 | if (priv->hw_params.num_gphy == 1) |
---|
722 | 874 | bcm_sf2_gphy_enable_set(ds, true); |
---|
.. | .. |
---|
729 | 881 | static void bcm_sf2_sw_get_wol(struct dsa_switch *ds, int port, |
---|
730 | 882 | struct ethtool_wolinfo *wol) |
---|
731 | 883 | { |
---|
732 | | - struct net_device *p = ds->ports[port].cpu_dp->master; |
---|
| 884 | + struct net_device *p = dsa_to_port(ds, port)->cpu_dp->master; |
---|
733 | 885 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
---|
734 | 886 | struct ethtool_wolinfo pwol = { }; |
---|
735 | 887 | |
---|
.. | .. |
---|
753 | 905 | static int bcm_sf2_sw_set_wol(struct dsa_switch *ds, int port, |
---|
754 | 906 | struct ethtool_wolinfo *wol) |
---|
755 | 907 | { |
---|
756 | | - struct net_device *p = ds->ports[port].cpu_dp->master; |
---|
| 908 | + struct net_device *p = dsa_to_port(ds, port)->cpu_dp->master; |
---|
757 | 909 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
---|
758 | | - s8 cpu_port = ds->ports[port].cpu_dp->index; |
---|
| 910 | + s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index; |
---|
759 | 911 | struct ethtool_wolinfo pwol = { }; |
---|
760 | 912 | |
---|
761 | 913 | if (p->ethtool_ops->get_wol) |
---|
.. | .. |
---|
793 | 945 | else if (dsa_is_cpu_port(ds, port)) |
---|
794 | 946 | bcm_sf2_imp_setup(ds, port); |
---|
795 | 947 | else |
---|
796 | | - bcm_sf2_port_disable(ds, port, NULL); |
---|
| 948 | + bcm_sf2_port_disable(ds, port); |
---|
797 | 949 | } |
---|
798 | 950 | |
---|
799 | 951 | b53_configure_vlan(ds); |
---|
800 | 952 | bcm_sf2_enable_acb(ds); |
---|
801 | 953 | |
---|
802 | | - return 0; |
---|
| 954 | + return b53_setup_devlink_resources(ds); |
---|
| 955 | +} |
---|
| 956 | + |
---|
| 957 | +static void bcm_sf2_sw_teardown(struct dsa_switch *ds) |
---|
| 958 | +{ |
---|
| 959 | + dsa_devlink_resources_unregister(ds); |
---|
803 | 960 | } |
---|
804 | 961 | |
---|
805 | 962 | /* The SWITCH_CORE register space is managed by b53 but operates on a page + |
---|
.. | .. |
---|
901 | 1058 | .write64 = bcm_sf2_core_write64, |
---|
902 | 1059 | }; |
---|
903 | 1060 | |
---|
| 1061 | +static void bcm_sf2_sw_get_strings(struct dsa_switch *ds, int port, |
---|
| 1062 | + u32 stringset, uint8_t *data) |
---|
| 1063 | +{ |
---|
| 1064 | + int cnt = b53_get_sset_count(ds, port, stringset); |
---|
| 1065 | + |
---|
| 1066 | + b53_get_strings(ds, port, stringset, data); |
---|
| 1067 | + bcm_sf2_cfp_get_strings(ds, port, stringset, |
---|
| 1068 | + data + cnt * ETH_GSTRING_LEN); |
---|
| 1069 | +} |
---|
| 1070 | + |
---|
| 1071 | +static void bcm_sf2_sw_get_ethtool_stats(struct dsa_switch *ds, int port, |
---|
| 1072 | + uint64_t *data) |
---|
| 1073 | +{ |
---|
| 1074 | + int cnt = b53_get_sset_count(ds, port, ETH_SS_STATS); |
---|
| 1075 | + |
---|
| 1076 | + b53_get_ethtool_stats(ds, port, data); |
---|
| 1077 | + bcm_sf2_cfp_get_ethtool_stats(ds, port, data + cnt); |
---|
| 1078 | +} |
---|
| 1079 | + |
---|
| 1080 | +static int bcm_sf2_sw_get_sset_count(struct dsa_switch *ds, int port, |
---|
| 1081 | + int sset) |
---|
| 1082 | +{ |
---|
| 1083 | + int cnt = b53_get_sset_count(ds, port, sset); |
---|
| 1084 | + |
---|
| 1085 | + if (cnt < 0) |
---|
| 1086 | + return cnt; |
---|
| 1087 | + |
---|
| 1088 | + cnt += bcm_sf2_cfp_get_sset_count(ds, port, sset); |
---|
| 1089 | + |
---|
| 1090 | + return cnt; |
---|
| 1091 | +} |
---|
| 1092 | + |
---|
904 | 1093 | static const struct dsa_switch_ops bcm_sf2_ops = { |
---|
905 | 1094 | .get_tag_protocol = b53_get_tag_protocol, |
---|
906 | 1095 | .setup = bcm_sf2_sw_setup, |
---|
907 | | - .get_strings = b53_get_strings, |
---|
908 | | - .get_ethtool_stats = b53_get_ethtool_stats, |
---|
909 | | - .get_sset_count = b53_get_sset_count, |
---|
| 1096 | + .teardown = bcm_sf2_sw_teardown, |
---|
| 1097 | + .get_strings = bcm_sf2_sw_get_strings, |
---|
| 1098 | + .get_ethtool_stats = bcm_sf2_sw_get_ethtool_stats, |
---|
| 1099 | + .get_sset_count = bcm_sf2_sw_get_sset_count, |
---|
910 | 1100 | .get_ethtool_phy_stats = b53_get_ethtool_phy_stats, |
---|
911 | 1101 | .get_phy_flags = bcm_sf2_sw_get_phy_flags, |
---|
912 | 1102 | .phylink_validate = bcm_sf2_sw_validate, |
---|
.. | .. |
---|
937 | 1127 | .set_rxnfc = bcm_sf2_set_rxnfc, |
---|
938 | 1128 | .port_mirror_add = b53_mirror_add, |
---|
939 | 1129 | .port_mirror_del = b53_mirror_del, |
---|
| 1130 | + .port_mdb_prepare = b53_mdb_prepare, |
---|
| 1131 | + .port_mdb_add = b53_mdb_add, |
---|
| 1132 | + .port_mdb_del = b53_mdb_del, |
---|
940 | 1133 | }; |
---|
941 | 1134 | |
---|
942 | 1135 | struct bcm_sf2_of_data { |
---|
.. | .. |
---|
1020 | 1213 | struct b53_device *dev; |
---|
1021 | 1214 | struct dsa_switch *ds; |
---|
1022 | 1215 | void __iomem **base; |
---|
1023 | | - struct resource *r; |
---|
1024 | 1216 | unsigned int i; |
---|
1025 | 1217 | u32 reg, rev; |
---|
1026 | 1218 | int ret; |
---|
.. | .. |
---|
1053 | 1245 | priv->core_reg_align = data->core_reg_align; |
---|
1054 | 1246 | priv->num_cfp_rules = data->num_cfp_rules; |
---|
1055 | 1247 | |
---|
| 1248 | + priv->rcdev = devm_reset_control_get_optional_exclusive(&pdev->dev, |
---|
| 1249 | + "switch"); |
---|
| 1250 | + if (PTR_ERR(priv->rcdev) == -EPROBE_DEFER) |
---|
| 1251 | + return PTR_ERR(priv->rcdev); |
---|
| 1252 | + |
---|
1056 | 1253 | /* Auto-detection using standard registers will not work, so |
---|
1057 | 1254 | * provide an indication of what kind of device we are for |
---|
1058 | 1255 | * b53_common to work with |
---|
.. | .. |
---|
1070 | 1267 | dev_set_drvdata(&pdev->dev, priv); |
---|
1071 | 1268 | |
---|
1072 | 1269 | spin_lock_init(&priv->indir_lock); |
---|
1073 | | - mutex_init(&priv->stats_mutex); |
---|
1074 | 1270 | mutex_init(&priv->cfp.lock); |
---|
| 1271 | + INIT_LIST_HEAD(&priv->cfp.rules_list); |
---|
1075 | 1272 | |
---|
1076 | 1273 | /* CFP rule #0 cannot be used for specific classifications, flag it as |
---|
1077 | 1274 | * permanently used |
---|
.. | .. |
---|
1092 | 1289 | |
---|
1093 | 1290 | base = &priv->core; |
---|
1094 | 1291 | for (i = 0; i < BCM_SF2_REGS_NUM; i++) { |
---|
1095 | | - r = platform_get_resource(pdev, IORESOURCE_MEM, i); |
---|
1096 | | - *base = devm_ioremap_resource(&pdev->dev, r); |
---|
| 1292 | + *base = devm_platform_ioremap_resource(pdev, i); |
---|
1097 | 1293 | if (IS_ERR(*base)) { |
---|
1098 | 1294 | pr_err("unable to find register: %s\n", reg_names[i]); |
---|
1099 | 1295 | return PTR_ERR(*base); |
---|
.. | .. |
---|
1101 | 1297 | base++; |
---|
1102 | 1298 | } |
---|
1103 | 1299 | |
---|
| 1300 | + priv->clk = devm_clk_get_optional(&pdev->dev, "sw_switch"); |
---|
| 1301 | + if (IS_ERR(priv->clk)) |
---|
| 1302 | + return PTR_ERR(priv->clk); |
---|
| 1303 | + |
---|
| 1304 | + ret = clk_prepare_enable(priv->clk); |
---|
| 1305 | + if (ret) |
---|
| 1306 | + return ret; |
---|
| 1307 | + |
---|
| 1308 | + priv->clk_mdiv = devm_clk_get_optional(&pdev->dev, "sw_switch_mdiv"); |
---|
| 1309 | + if (IS_ERR(priv->clk_mdiv)) { |
---|
| 1310 | + ret = PTR_ERR(priv->clk_mdiv); |
---|
| 1311 | + goto out_clk; |
---|
| 1312 | + } |
---|
| 1313 | + |
---|
| 1314 | + ret = clk_prepare_enable(priv->clk_mdiv); |
---|
| 1315 | + if (ret) |
---|
| 1316 | + goto out_clk; |
---|
| 1317 | + |
---|
1104 | 1318 | ret = bcm_sf2_sw_rst(priv); |
---|
1105 | 1319 | if (ret) { |
---|
1106 | 1320 | pr_err("unable to software reset switch: %d\n", ret); |
---|
1107 | | - return ret; |
---|
| 1321 | + goto out_clk_mdiv; |
---|
1108 | 1322 | } |
---|
1109 | 1323 | |
---|
1110 | 1324 | bcm_sf2_gphy_enable_set(priv->dev->ds, true); |
---|
.. | .. |
---|
1112 | 1326 | ret = bcm_sf2_mdio_register(ds); |
---|
1113 | 1327 | if (ret) { |
---|
1114 | 1328 | pr_err("failed to register MDIO bus\n"); |
---|
1115 | | - return ret; |
---|
| 1329 | + goto out_clk_mdiv; |
---|
1116 | 1330 | } |
---|
1117 | 1331 | |
---|
1118 | 1332 | bcm_sf2_gphy_enable_set(priv->dev->ds, false); |
---|
.. | .. |
---|
1169 | 1383 | if (ret) |
---|
1170 | 1384 | goto out_mdio; |
---|
1171 | 1385 | |
---|
1172 | | - pr_info("Starfighter 2 top: %x.%02x, core: %x.%02x base: 0x%p, IRQs: %d, %d\n", |
---|
1173 | | - priv->hw_params.top_rev >> 8, priv->hw_params.top_rev & 0xff, |
---|
1174 | | - priv->hw_params.core_rev >> 8, priv->hw_params.core_rev & 0xff, |
---|
1175 | | - priv->core, priv->irq0, priv->irq1); |
---|
| 1386 | + dev_info(&pdev->dev, |
---|
| 1387 | + "Starfighter 2 top: %x.%02x, core: %x.%02x, IRQs: %d, %d\n", |
---|
| 1388 | + priv->hw_params.top_rev >> 8, priv->hw_params.top_rev & 0xff, |
---|
| 1389 | + priv->hw_params.core_rev >> 8, priv->hw_params.core_rev & 0xff, |
---|
| 1390 | + priv->irq0, priv->irq1); |
---|
1176 | 1391 | |
---|
1177 | 1392 | return 0; |
---|
1178 | 1393 | |
---|
1179 | 1394 | out_mdio: |
---|
1180 | 1395 | bcm_sf2_mdio_unregister(priv); |
---|
| 1396 | +out_clk_mdiv: |
---|
| 1397 | + clk_disable_unprepare(priv->clk_mdiv); |
---|
| 1398 | +out_clk: |
---|
| 1399 | + clk_disable_unprepare(priv->clk); |
---|
1181 | 1400 | return ret; |
---|
1182 | 1401 | } |
---|
1183 | 1402 | |
---|
.. | .. |
---|
1186 | 1405 | struct bcm_sf2_priv *priv = platform_get_drvdata(pdev); |
---|
1187 | 1406 | |
---|
1188 | 1407 | priv->wol_ports_mask = 0; |
---|
| 1408 | + /* Disable interrupts */ |
---|
| 1409 | + bcm_sf2_intr_disable(priv); |
---|
1189 | 1410 | dsa_unregister_switch(priv->dev->ds); |
---|
1190 | | - /* Disable all ports and interrupts */ |
---|
1191 | | - bcm_sf2_sw_suspend(priv->dev->ds); |
---|
| 1411 | + bcm_sf2_cfp_exit(priv->dev->ds); |
---|
1192 | 1412 | bcm_sf2_mdio_unregister(priv); |
---|
| 1413 | + clk_disable_unprepare(priv->clk_mdiv); |
---|
| 1414 | + clk_disable_unprepare(priv->clk); |
---|
| 1415 | + if (priv->type == BCM7278_DEVICE_ID && !IS_ERR(priv->rcdev)) |
---|
| 1416 | + reset_control_assert(priv->rcdev); |
---|
1193 | 1417 | |
---|
1194 | 1418 | return 0; |
---|
1195 | 1419 | } |
---|
.. | .. |
---|
1211 | 1435 | #ifdef CONFIG_PM_SLEEP |
---|
1212 | 1436 | static int bcm_sf2_suspend(struct device *dev) |
---|
1213 | 1437 | { |
---|
1214 | | - struct platform_device *pdev = to_platform_device(dev); |
---|
1215 | | - struct bcm_sf2_priv *priv = platform_get_drvdata(pdev); |
---|
| 1438 | + struct bcm_sf2_priv *priv = dev_get_drvdata(dev); |
---|
1216 | 1439 | |
---|
1217 | 1440 | return dsa_switch_suspend(priv->dev->ds); |
---|
1218 | 1441 | } |
---|
1219 | 1442 | |
---|
1220 | 1443 | static int bcm_sf2_resume(struct device *dev) |
---|
1221 | 1444 | { |
---|
1222 | | - struct platform_device *pdev = to_platform_device(dev); |
---|
1223 | | - struct bcm_sf2_priv *priv = platform_get_drvdata(pdev); |
---|
| 1445 | + struct bcm_sf2_priv *priv = dev_get_drvdata(dev); |
---|
1224 | 1446 | |
---|
1225 | 1447 | return dsa_switch_resume(priv->dev->ds); |
---|
1226 | 1448 | } |
---|