Lines Matching +full:8 +full:- +full:port
4 * Copyright (C) 2011-2013 Jonas Gorski <[email protected]>
44 { 8, 0x00, "TxOctets" },
56 { 8, 0x44, "RxOctets" },
69 { 8, 0x7c, "RxGoodOctets" },
82 { 8, 0x00, "TxOctets" },
95 { 8, 0x3c, "TxQoSOctets" },
96 { 8, 0x44, "RxOctets" },
109 { 8, 0x7c, "RxGoodOctets" },
118 { 8, 0xa8, "RxQoSOctets" },
130 { 8, 0x00, "TxOctets" },
142 { 8, 0x50, "RxOctets" },
155 { 8, 0x88, "RxGoodOctets" },
170 { 8, 0x00, "TxOctets" },
189 { 8, 0x50, "RxOctets" },
202 { 8, 0x88, "RxGoodOctets" },
228 #define B53_MAX_MTU_25 (1536 - ETH_HLEN - VLAN_HLEN - ETH_FCS_LEN)
229 #define B53_MAX_MTU (9720 - ETH_HLEN - VLAN_HLEN - ETH_FCS_LEN)
235 b53_write8(dev, B53_ARLIO_PAGE, dev->vta_regs[0], VTA_START_CMD | op); in b53_do_vlan_op()
240 b53_read8(dev, B53_ARLIO_PAGE, dev->vta_regs[0], &vta); in b53_do_vlan_op()
247 return -EIO; in b53_do_vlan_op()
256 if (vlan->members) { in b53_set_vlan_entry()
257 entry = ((vlan->untag & VA_UNTAG_MASK_25) << in b53_set_vlan_entry()
258 VA_UNTAG_S_25) | vlan->members; in b53_set_vlan_entry()
259 if (dev->core_rev >= 3) in b53_set_vlan_entry()
271 if (vlan->members) in b53_set_vlan_entry()
272 entry = ((vlan->untag & VA_UNTAG_MASK_65) << in b53_set_vlan_entry()
273 VA_UNTAG_S_65) | vlan->members | VA_VALID_65; in b53_set_vlan_entry()
279 b53_write16(dev, B53_ARLIO_PAGE, dev->vta_regs[1], vid); in b53_set_vlan_entry()
280 b53_write32(dev, B53_ARLIO_PAGE, dev->vta_regs[2], in b53_set_vlan_entry()
281 (vlan->untag << VTE_UNTAG_S) | vlan->members); in b53_set_vlan_entry()
286 dev_dbg(dev->ds->dev, "VID: %d, members: 0x%04x, untag: 0x%04x\n", in b53_set_vlan_entry()
287 vid, vlan->members, vlan->untag); in b53_set_vlan_entry()
300 if (dev->core_rev >= 3) in b53_get_vlan_entry()
301 vlan->valid = !!(entry & VA_VALID_25_R4); in b53_get_vlan_entry()
303 vlan->valid = !!(entry & VA_VALID_25); in b53_get_vlan_entry()
304 vlan->members = entry & VA_MEMBER_MASK; in b53_get_vlan_entry()
305 vlan->untag = (entry >> VA_UNTAG_S_25) & VA_UNTAG_MASK_25; in b53_get_vlan_entry()
314 vlan->valid = !!(entry & VA_VALID_65); in b53_get_vlan_entry()
315 vlan->members = entry & VA_MEMBER_MASK; in b53_get_vlan_entry()
316 vlan->untag = (entry >> VA_UNTAG_S_65) & VA_UNTAG_MASK_65; in b53_get_vlan_entry()
320 b53_write16(dev, B53_ARLIO_PAGE, dev->vta_regs[1], vid); in b53_get_vlan_entry()
322 b53_read32(dev, B53_ARLIO_PAGE, dev->vta_regs[2], &entry); in b53_get_vlan_entry()
323 vlan->members = entry & VTE_MEMBERS; in b53_get_vlan_entry()
324 vlan->untag = (entry >> VTE_UNTAG_S) & VTE_MEMBERS; in b53_get_vlan_entry()
325 vlan->valid = true; in b53_get_vlan_entry()
342 /* Include IMP port in dumb forwarding mode in b53_set_forwarding()
356 static void b53_enable_vlan(struct b53_device *dev, int port, bool enable, in b53_enable_vlan() argument
416 /* enable the high 8 bit vid check on 5325 */ in b53_enable_vlan()
437 dev->vlan_enabled = enable; in b53_enable_vlan()
439 dev_dbg(dev->dev, "Port %d VLAN enabled: %d, filtering: %d\n", in b53_enable_vlan()
440 port, enable, enable_filtering); in b53_enable_vlan()
449 return -EINVAL; in b53_set_jumbo()
452 port_mask = dev->enabled_ports; in b53_set_jumbo()
458 b53_write32(dev, B53_JUMBO_PAGE, dev->jumbo_pm_reg, port_mask); in b53_set_jumbo()
459 return b53_write16(dev, B53_JUMBO_PAGE, dev->jumbo_size_reg, max_size); in b53_set_jumbo()
481 return -ETIMEDOUT; in b53_flush_arl()
488 static int b53_fast_age_port(struct b53_device *dev, int port) in b53_fast_age_port() argument
490 b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_PORT_CTRL, port); in b53_fast_age_port()
504 struct b53_device *dev = ds->priv; in b53_imp_vlan_setup()
508 /* Enable the IMP port to be in the same VLAN as the other ports in b53_imp_vlan_setup()
509 * on a per-port basis such that we only have Port i and IMP in in b53_imp_vlan_setup()
520 static void b53_port_set_ucast_flood(struct b53_device *dev, int port, in b53_port_set_ucast_flood() argument
527 uc |= BIT(port); in b53_port_set_ucast_flood()
529 uc &= ~BIT(port); in b53_port_set_ucast_flood()
533 static void b53_port_set_mcast_flood(struct b53_device *dev, int port, in b53_port_set_mcast_flood() argument
540 mc |= BIT(port); in b53_port_set_mcast_flood()
542 mc &= ~BIT(port); in b53_port_set_mcast_flood()
547 mc |= BIT(port); in b53_port_set_mcast_flood()
549 mc &= ~BIT(port); in b53_port_set_mcast_flood()
553 static void b53_port_set_learning(struct b53_device *dev, int port, in b53_port_set_learning() argument
560 reg &= ~BIT(port); in b53_port_set_learning()
562 reg |= BIT(port); in b53_port_set_learning()
566 static void b53_eee_enable_set(struct dsa_switch *ds, int port, bool enable) in b53_eee_enable_set() argument
568 struct b53_device *dev = ds->priv; in b53_eee_enable_set()
573 reg |= BIT(port); in b53_eee_enable_set()
575 reg &= ~BIT(port); in b53_eee_enable_set()
579 int b53_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy) in b53_enable_port() argument
581 struct b53_device *dev = ds->priv; in b53_enable_port()
586 if (!dsa_is_user_port(ds, port)) in b53_enable_port()
589 cpu_port = dsa_to_port(ds, port)->cpu_dp->index; in b53_enable_port()
591 b53_port_set_ucast_flood(dev, port, true); in b53_enable_port()
592 b53_port_set_mcast_flood(dev, port, true); in b53_enable_port()
593 b53_port_set_learning(dev, port, false); in b53_enable_port()
595 if (dev->ops->irq_enable) in b53_enable_port()
596 ret = dev->ops->irq_enable(dev, port); in b53_enable_port()
601 b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), 0); in b53_enable_port()
603 /* Set this port, and only this one to be in the default VLAN, in b53_enable_port()
605 * bringing down this port. in b53_enable_port()
607 b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); in b53_enable_port()
609 pvlan |= BIT(port); in b53_enable_port()
610 pvlan |= dev->ports[port].vlan_ctl_mask; in b53_enable_port()
611 b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan); in b53_enable_port()
616 if (dev->ports[port].eee.eee_enabled) in b53_enable_port()
617 b53_eee_enable_set(ds, port, true); in b53_enable_port()
623 void b53_disable_port(struct dsa_switch *ds, int port) in b53_disable_port() argument
625 struct b53_device *dev = ds->priv; in b53_disable_port()
628 /* Disable Tx/Rx for the port */ in b53_disable_port()
629 b53_read8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), ®); in b53_disable_port()
631 b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), reg); in b53_disable_port()
633 if (dev->ops->irq_disable) in b53_disable_port()
634 dev->ops->irq_disable(dev, port); in b53_disable_port()
638 void b53_brcm_hdr_setup(struct dsa_switch *ds, int port) in b53_brcm_hdr_setup() argument
640 struct b53_device *dev = ds->priv; in b53_brcm_hdr_setup()
641 bool tag_en = !(dev->tag_protocol == DSA_TAG_PROTO_NONE); in b53_brcm_hdr_setup()
646 switch (port) { in b53_brcm_hdr_setup()
647 case 8: in b53_brcm_hdr_setup()
669 /* Configure the appropriate IMP port */ in b53_brcm_hdr_setup()
671 if (port == 8) in b53_brcm_hdr_setup()
673 else if (port == 5) in b53_brcm_hdr_setup()
677 /* Enable Broadcom tags for IMP port */ in b53_brcm_hdr_setup()
694 reg &= ~BIT(port); in b53_brcm_hdr_setup()
696 reg |= BIT(port); in b53_brcm_hdr_setup()
700 * allow delivering frames to the per-port net_devices in b53_brcm_hdr_setup()
704 reg &= ~BIT(port); in b53_brcm_hdr_setup()
706 reg |= BIT(port); in b53_brcm_hdr_setup()
711 static void b53_enable_cpu_port(struct b53_device *dev, int port) in b53_enable_cpu_port() argument
715 /* BCM5325 CPU port is at 8 */ in b53_enable_cpu_port()
716 if ((is5325(dev) || is5365(dev)) && port == B53_CPU_PORT_25) in b53_enable_cpu_port()
717 port = B53_CPU_PORT; in b53_enable_cpu_port()
722 b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), port_ctrl); in b53_enable_cpu_port()
724 b53_brcm_hdr_setup(dev->ds, port); in b53_enable_cpu_port()
726 b53_port_set_ucast_flood(dev, port, true); in b53_enable_cpu_port()
727 b53_port_set_mcast_flood(dev, port, true); in b53_enable_cpu_port()
728 b53_port_set_learning(dev, port, false); in b53_enable_cpu_port()
757 static bool b53_vlan_port_needs_forced_tagged(struct dsa_switch *ds, int port) in b53_vlan_port_needs_forced_tagged() argument
759 struct b53_device *dev = ds->priv; in b53_vlan_port_needs_forced_tagged()
761 return dev->tag_protocol == DSA_TAG_PROTO_NONE && dsa_is_cpu_port(ds, port); in b53_vlan_port_needs_forced_tagged()
766 struct b53_device *dev = ds->priv; in b53_configure_vlan()
776 for (i = def_vid; i < dev->num_vlans; i++) in b53_configure_vlan()
782 b53_enable_vlan(dev, -1, dev->vlan_enabled, ds->vlan_filtering); in b53_configure_vlan()
791 v = &dev->vlans[def_vid]; in b53_configure_vlan()
792 v->members |= BIT(i); in b53_configure_vlan()
794 v->untag = v->members; in b53_configure_vlan()
799 /* Upon initial call we have not set-up any VLANs, but upon in b53_configure_vlan()
802 for (vid = def_vid; vid < dev->num_vlans; vid++) { in b53_configure_vlan()
803 v = &dev->vlans[vid]; in b53_configure_vlan()
805 if (!v->members) in b53_configure_vlan()
818 int gpio = dev->reset_gpio; in b53_switch_reset_gpio()
823 /* Reset sequence: RESET low(50ms)->high(20ms) in b53_switch_reset_gpio()
831 dev->current_page = 0xff; in b53_switch_reset_gpio()
851 if (dev->chip_id == BCM58XX_DEVICE_ID || in b53_switch_reset()
852 dev->chip_id == BCM583XX_DEVICE_ID) { in b53_switch_reset()
863 } while (timeout-- > 0); in b53_switch_reset()
866 dev_err(dev->dev, in b53_switch_reset()
868 return -ETIMEDOUT; in b53_switch_reset()
882 dev_err(dev->dev, "Failed to enable switch!\n"); in b53_switch_reset()
883 return -EINVAL; in b53_switch_reset()
895 struct b53_device *priv = ds->priv; in b53_phy_read16()
899 if (priv->ops->phy_read16) in b53_phy_read16()
900 ret = priv->ops->phy_read16(priv, addr, reg, &value); in b53_phy_read16()
910 struct b53_device *priv = ds->priv; in b53_phy_write16()
912 if (priv->ops->phy_write16) in b53_phy_write16()
913 return priv->ops->phy_write16(priv, addr, reg, val); in b53_phy_write16()
921 memset(priv->vlans, 0, sizeof(*priv->vlans) * priv->num_vlans); in b53_reset_switch()
922 memset(priv->ports, 0, sizeof(*priv->ports) * priv->num_ports); in b53_reset_switch()
924 priv->serdes_lane = B53_INVALID_LANE; in b53_reset_switch()
934 b53_configure_vlan(priv->ds); in b53_apply_config()
978 static struct phy_device *b53_get_phy_device(struct dsa_switch *ds, int port) in b53_get_phy_device() argument
980 /* These ports typically do not have built-in PHYs */ in b53_get_phy_device()
981 switch (port) { in b53_get_phy_device()
988 return mdiobus_get_phy(ds->user_mii_bus, port); in b53_get_phy_device()
991 void b53_get_strings(struct dsa_switch *ds, int port, u32 stringset, in b53_get_strings() argument
994 struct b53_device *dev = ds->priv; in b53_get_strings()
1004 phydev = b53_get_phy_device(ds, port); in b53_get_strings()
1013 void b53_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data) in b53_get_ethtool_stats() argument
1015 struct b53_device *dev = ds->priv; in b53_get_ethtool_stats()
1022 if (is5365(dev) && port == 5) in b53_get_ethtool_stats()
1023 port = 8; in b53_get_ethtool_stats()
1025 mutex_lock(&dev->stats_mutex); in b53_get_ethtool_stats()
1030 if (s->size == 8) { in b53_get_ethtool_stats()
1031 b53_read64(dev, B53_MIB_PAGE(port), s->offset, &val); in b53_get_ethtool_stats()
1035 b53_read32(dev, B53_MIB_PAGE(port), s->offset, in b53_get_ethtool_stats()
1042 mutex_unlock(&dev->stats_mutex); in b53_get_ethtool_stats()
1046 void b53_get_ethtool_phy_stats(struct dsa_switch *ds, int port, uint64_t *data) in b53_get_ethtool_phy_stats() argument
1050 phydev = b53_get_phy_device(ds, port); in b53_get_ethtool_phy_stats()
1058 int b53_get_sset_count(struct dsa_switch *ds, int port, int sset) in b53_get_sset_count() argument
1060 struct b53_device *dev = ds->priv; in b53_get_sset_count()
1066 phydev = b53_get_phy_device(ds, port); in b53_get_sset_count()
1088 for (i = 0; i < dev->num_vlans; i++) { in b53_devlink_vlan_table_get()
1089 vl = &dev->vlans[i]; in b53_devlink_vlan_table_get()
1090 if (vl->members) in b53_devlink_vlan_table_get()
1100 struct b53_device *dev = ds->priv; in b53_setup_devlink_resources()
1103 devlink_resource_size_params_init(&size_params, dev->num_vlans, in b53_setup_devlink_resources()
1104 dev->num_vlans, in b53_setup_devlink_resources()
1107 err = dsa_devlink_resource_register(ds, "VLAN", dev->num_vlans, in b53_setup_devlink_resources()
1127 struct b53_device *dev = ds->priv; in b53_setup()
1128 unsigned int port; in b53_setup() local
1132 * which forces the CPU port to be tagged in all VLANs. in b53_setup()
1134 ds->untag_bridge_pvid = dev->tag_protocol == DSA_TAG_PROTO_NONE; in b53_setup()
1138 dev_err(ds->dev, "failed to reset switch\n"); in b53_setup()
1146 dev_err(ds->dev, "failed to apply configuration\n"); in b53_setup()
1150 /* Configure IMP/CPU port, disable all other ports. Enabled in b53_setup()
1153 for (port = 0; port < dev->num_ports; port++) { in b53_setup()
1154 if (dsa_is_cpu_port(ds, port)) in b53_setup()
1155 b53_enable_cpu_port(dev, port); in b53_setup()
1157 b53_disable_port(ds, port); in b53_setup()
1168 static void b53_force_link(struct b53_device *dev, int port, int link) in b53_force_link() argument
1172 /* Override the port settings */ in b53_force_link()
1173 if (port == dev->imp_port) { in b53_force_link()
1177 off = B53_GMII_PORT_OVERRIDE_CTRL(port); in b53_force_link()
1190 static void b53_force_port_config(struct b53_device *dev, int port, in b53_force_port_config() argument
1196 /* Override the port settings */ in b53_force_port_config()
1197 if (port == dev->imp_port) { in b53_force_port_config()
1201 off = B53_GMII_PORT_OVERRIDE_CTRL(port); in b53_force_port_config()
1226 dev_err(dev->dev, "unknown speed: %d\n", speed); in b53_force_port_config()
1238 static void b53_adjust_63xx_rgmii(struct dsa_switch *ds, int port, in b53_adjust_63xx_rgmii() argument
1241 struct b53_device *dev = ds->priv; in b53_adjust_63xx_rgmii()
1244 if (port == dev->imp_port) in b53_adjust_63xx_rgmii()
1247 off = B53_RGMII_CTRL_P(port); in b53_adjust_63xx_rgmii()
1269 if (port != dev->imp_port) { in b53_adjust_63xx_rgmii()
1278 dev_dbg(ds->dev, "Configured port %d for %s\n", port, in b53_adjust_63xx_rgmii()
1282 static void b53_adjust_531x5_rgmii(struct dsa_switch *ds, int port, in b53_adjust_531x5_rgmii() argument
1285 struct b53_device *dev = ds->priv; in b53_adjust_531x5_rgmii()
1288 if (port == dev->imp_port) in b53_adjust_531x5_rgmii()
1291 off = B53_RGMII_CTRL_P(port); in b53_adjust_531x5_rgmii()
1293 /* Configure the port RGMII clock delay by DLL disabled and in b53_adjust_531x5_rgmii()
1301 * sure that we enable the port TX clock internal delay to in b53_adjust_531x5_rgmii()
1321 dev_info(ds->dev, "Configured port %d for %s\n", port, in b53_adjust_531x5_rgmii()
1325 static void b53_adjust_5325_mii(struct dsa_switch *ds, int port) in b53_adjust_5325_mii() argument
1327 struct b53_device *dev = ds->priv; in b53_adjust_5325_mii()
1341 dev_err(ds->dev, in b53_adjust_5325_mii()
1348 void b53_port_event(struct dsa_switch *ds, int port) in b53_port_event() argument
1350 struct b53_device *dev = ds->priv; in b53_port_event()
1355 link = !!(sts & BIT(port)); in b53_port_event()
1356 dsa_port_phylink_mac_change(ds, port, link); in b53_port_event()
1360 static void b53_phylink_get_caps(struct dsa_switch *ds, int port, in b53_phylink_get_caps() argument
1363 struct b53_device *dev = ds->priv; in b53_phylink_get_caps()
1366 __set_bit(PHY_INTERFACE_MODE_GMII, config->supported_interfaces); in b53_phylink_get_caps()
1377 * For MDIO, port 8 can be RGMII_TXID. in b53_phylink_get_caps()
1379 __set_bit(PHY_INTERFACE_MODE_MII, config->supported_interfaces); in b53_phylink_get_caps()
1380 __set_bit(PHY_INTERFACE_MODE_REVMII, config->supported_interfaces); in b53_phylink_get_caps()
1382 config->mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE | in b53_phylink_get_caps()
1392 config->mac_capabilities |= MAC_1000; in b53_phylink_get_caps()
1395 if (dev->ops->phylink_get_caps) in b53_phylink_get_caps()
1396 dev->ops->phylink_get_caps(dev, port, config); in b53_phylink_get_caps()
1403 struct b53_device *dev = dp->ds->priv; in b53_phylink_mac_select_pcs()
1405 if (!dev->ops->phylink_mac_select_pcs) in b53_phylink_mac_select_pcs()
1408 return dev->ops->phylink_mac_select_pcs(dev, dp->index, interface); in b53_phylink_mac_select_pcs()
1416 phy_interface_t interface = state->interface; in b53_phylink_mac_config()
1417 struct dsa_switch *ds = dp->ds; in b53_phylink_mac_config()
1418 struct b53_device *dev = ds->priv; in b53_phylink_mac_config()
1419 int port = dp->index; in b53_phylink_mac_config() local
1421 if (is63xx(dev) && port >= B53_63XX_RGMII0) in b53_phylink_mac_config()
1422 b53_adjust_63xx_rgmii(ds, port, interface); in b53_phylink_mac_config()
1426 b53_adjust_531x5_rgmii(ds, port, interface); in b53_phylink_mac_config()
1428 /* configure MII port if necessary */ in b53_phylink_mac_config()
1430 b53_adjust_5325_mii(ds, port); in b53_phylink_mac_config()
1439 struct b53_device *dev = dp->ds->priv; in b53_phylink_mac_link_down()
1440 int port = dp->index; in b53_phylink_mac_link_down() local
1446 b53_force_link(dev, port, false); in b53_phylink_mac_link_down()
1451 dev->ops->serdes_link_set) in b53_phylink_mac_link_down()
1452 dev->ops->serdes_link_set(dev, port, mode, interface, false); in b53_phylink_mac_link_down()
1463 struct dsa_switch *ds = dp->ds; in b53_phylink_mac_link_up()
1464 struct b53_device *dev = ds->priv; in b53_phylink_mac_link_up()
1465 struct ethtool_keee *p = &dev->ports[dp->index].eee; in b53_phylink_mac_link_up()
1466 int port = dp->index; in b53_phylink_mac_link_up() local
1469 /* Re-negotiate EEE if it was enabled already */ in b53_phylink_mac_link_up()
1470 p->eee_enabled = b53_eee_init(ds, port, phydev); in b53_phylink_mac_link_up()
1475 /* Force flow control on BCM5301x's CPU port */ in b53_phylink_mac_link_up()
1476 if (is5301x(dev) && dsa_is_cpu_port(ds, port)) in b53_phylink_mac_link_up()
1479 b53_force_port_config(dev, port, speed, duplex, in b53_phylink_mac_link_up()
1481 b53_force_link(dev, port, true); in b53_phylink_mac_link_up()
1486 dev->ops->serdes_link_set) in b53_phylink_mac_link_up()
1487 dev->ops->serdes_link_set(dev, port, mode, interface, true); in b53_phylink_mac_link_up()
1490 int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering, in b53_vlan_filtering() argument
1493 struct b53_device *dev = ds->priv; in b53_vlan_filtering()
1495 b53_enable_vlan(dev, port, dev->vlan_enabled, vlan_filtering); in b53_vlan_filtering()
1501 static int b53_vlan_prepare(struct dsa_switch *ds, int port, in b53_vlan_prepare() argument
1504 struct b53_device *dev = ds->priv; in b53_vlan_prepare()
1506 if ((is5325(dev) || is5365(dev)) && vlan->vid == 0) in b53_vlan_prepare()
1507 return -EOPNOTSUPP; in b53_vlan_prepare()
1509 /* Port 7 on 7278 connects to the ASP's UniMAC which is not capable of in b53_vlan_prepare()
1510 * receiving VLAN tagged frames at all, we can still allow the port to in b53_vlan_prepare()
1513 if (dev->chip_id == BCM7278_DEVICE_ID && port == 7 && in b53_vlan_prepare()
1514 !(vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED)) in b53_vlan_prepare()
1515 return -EINVAL; in b53_vlan_prepare()
1517 if (vlan->vid >= dev->num_vlans) in b53_vlan_prepare()
1518 return -ERANGE; in b53_vlan_prepare()
1520 b53_enable_vlan(dev, port, true, ds->vlan_filtering); in b53_vlan_prepare()
1525 int b53_vlan_add(struct dsa_switch *ds, int port, in b53_vlan_add() argument
1529 struct b53_device *dev = ds->priv; in b53_vlan_add()
1530 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; in b53_vlan_add()
1531 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID; in b53_vlan_add()
1535 err = b53_vlan_prepare(ds, port, vlan); in b53_vlan_add()
1539 vl = &dev->vlans[vlan->vid]; in b53_vlan_add()
1541 b53_get_vlan_entry(dev, vlan->vid, vl); in b53_vlan_add()
1543 if (vlan->vid == 0 && vlan->vid == b53_default_pvid(dev)) in b53_vlan_add()
1546 vl->members |= BIT(port); in b53_vlan_add()
1547 if (untagged && !b53_vlan_port_needs_forced_tagged(ds, port)) in b53_vlan_add()
1548 vl->untag |= BIT(port); in b53_vlan_add()
1550 vl->untag &= ~BIT(port); in b53_vlan_add()
1552 b53_set_vlan_entry(dev, vlan->vid, vl); in b53_vlan_add()
1553 b53_fast_age_vlan(dev, vlan->vid); in b53_vlan_add()
1555 if (pvid && !dsa_is_cpu_port(ds, port)) { in b53_vlan_add()
1556 b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), in b53_vlan_add()
1557 vlan->vid); in b53_vlan_add()
1558 b53_fast_age_vlan(dev, vlan->vid); in b53_vlan_add()
1565 int b53_vlan_del(struct dsa_switch *ds, int port, in b53_vlan_del() argument
1568 struct b53_device *dev = ds->priv; in b53_vlan_del()
1569 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; in b53_vlan_del()
1573 b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &pvid); in b53_vlan_del()
1575 vl = &dev->vlans[vlan->vid]; in b53_vlan_del()
1577 b53_get_vlan_entry(dev, vlan->vid, vl); in b53_vlan_del()
1579 vl->members &= ~BIT(port); in b53_vlan_del()
1581 if (pvid == vlan->vid) in b53_vlan_del()
1584 if (untagged && !b53_vlan_port_needs_forced_tagged(ds, port)) in b53_vlan_del()
1585 vl->untag &= ~(BIT(port)); in b53_vlan_del()
1587 b53_set_vlan_entry(dev, vlan->vid, vl); in b53_vlan_del()
1588 b53_fast_age_vlan(dev, vlan->vid); in b53_vlan_del()
1590 b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), pvid); in b53_vlan_del()
1597 /* Address Resolution Logic routines. Caller must hold &dev->arl_mutex. */
1609 } while (timeout--); in b53_arl_op_wait()
1611 dev_warn(dev->dev, "timeout waiting for ARL to finish: 0x%02x\n", reg); in b53_arl_op_wait()
1613 return -ETIMEDOUT; in b53_arl_op_wait()
1621 return -EINVAL; in b53_arl_rw_op()
1629 if (dev->vlan_enabled) in b53_arl_rw_op()
1649 bitmap_zero(free_bins, dev->num_arl_bins); in b53_arl_read()
1652 for (i = 0; i < dev->num_arl_bins; i++) { in b53_arl_read()
1668 if (dev->vlan_enabled && in b53_arl_read()
1675 *idx = find_first_bit(free_bins, dev->num_arl_bins); in b53_arl_read()
1676 return *idx >= dev->num_arl_bins ? -ENOSPC : -ENOENT; in b53_arl_read()
1679 static int b53_arl_op(struct b53_device *dev, int op, int port, in b53_arl_op() argument
1688 /* Convert the array into a 64-bit MAC */ in b53_arl_op()
1707 case -ETIMEDOUT: in b53_arl_op()
1709 case -ENOSPC: in b53_arl_op()
1710 dev_dbg(dev->dev, "{%pM,%.4d} no space left in ARL\n", in b53_arl_op()
1713 case -ENOENT: in b53_arl_op()
1715 dev_dbg(dev->dev, "{%pM,%.4d} not found, using idx: %d\n", in b53_arl_op()
1720 dev_dbg(dev->dev, "{%pM,%.4d} found, using idx: %d\n", in b53_arl_op()
1725 /* For multicast address, the port is a bitmask and the validity in b53_arl_op()
1726 * is determined by having at least one port being still active in b53_arl_op()
1729 ent.port = port; in b53_arl_op()
1733 ent.port |= BIT(port); in b53_arl_op()
1735 ent.port &= ~BIT(port); in b53_arl_op()
1737 ent.is_valid = !!(ent.port); in b53_arl_op()
1754 int b53_fdb_add(struct dsa_switch *ds, int port, in b53_fdb_add() argument
1758 struct b53_device *priv = ds->priv; in b53_fdb_add()
1765 return -EOPNOTSUPP; in b53_fdb_add()
1767 mutex_lock(&priv->arl_mutex); in b53_fdb_add()
1768 ret = b53_arl_op(priv, 0, port, addr, vid, true); in b53_fdb_add()
1769 mutex_unlock(&priv->arl_mutex); in b53_fdb_add()
1775 int b53_fdb_del(struct dsa_switch *ds, int port, in b53_fdb_del() argument
1779 struct b53_device *priv = ds->priv; in b53_fdb_del()
1782 mutex_lock(&priv->arl_mutex); in b53_fdb_del()
1783 ret = b53_arl_op(priv, 0, port, addr, vid, false); in b53_fdb_del()
1784 mutex_unlock(&priv->arl_mutex); in b53_fdb_del()
1804 } while (timeout--); in b53_arl_search_wait()
1806 return -ETIMEDOUT; in b53_arl_search_wait()
1822 static int b53_fdb_copy(int port, const struct b53_arl_entry *ent, in b53_fdb_copy() argument
1825 if (!ent->is_valid) in b53_fdb_copy()
1828 if (port != ent->port) in b53_fdb_copy()
1831 return cb(ent->mac, ent->vid, ent->is_static, data); in b53_fdb_copy()
1834 int b53_fdb_dump(struct dsa_switch *ds, int port, in b53_fdb_dump() argument
1837 struct b53_device *priv = ds->priv; in b53_fdb_dump()
1843 mutex_lock(&priv->arl_mutex); in b53_fdb_dump()
1855 ret = b53_fdb_copy(port, &results[0], cb, data); in b53_fdb_dump()
1859 if (priv->num_arl_bins > 2) { in b53_fdb_dump()
1861 ret = b53_fdb_copy(port, &results[1], cb, data); in b53_fdb_dump()
1871 mutex_unlock(&priv->arl_mutex); in b53_fdb_dump()
1877 int b53_mdb_add(struct dsa_switch *ds, int port, in b53_mdb_add() argument
1881 struct b53_device *priv = ds->priv; in b53_mdb_add()
1888 return -EOPNOTSUPP; in b53_mdb_add()
1890 mutex_lock(&priv->arl_mutex); in b53_mdb_add()
1891 ret = b53_arl_op(priv, 0, port, mdb->addr, mdb->vid, true); in b53_mdb_add()
1892 mutex_unlock(&priv->arl_mutex); in b53_mdb_add()
1898 int b53_mdb_del(struct dsa_switch *ds, int port, in b53_mdb_del() argument
1902 struct b53_device *priv = ds->priv; in b53_mdb_del()
1905 mutex_lock(&priv->arl_mutex); in b53_mdb_del()
1906 ret = b53_arl_op(priv, 0, port, mdb->addr, mdb->vid, false); in b53_mdb_del()
1907 mutex_unlock(&priv->arl_mutex); in b53_mdb_del()
1909 dev_err(ds->dev, "failed to delete MDB entry\n"); in b53_mdb_del()
1915 int b53_br_join(struct dsa_switch *ds, int port, struct dsa_bridge bridge, in b53_br_join() argument
1918 struct b53_device *dev = ds->priv; in b53_br_join()
1919 s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index; in b53_br_join()
1923 /* On 7278, port 7 which connects to the ASP should only receive in b53_br_join()
1926 if (dev->chip_id == BCM7278_DEVICE_ID && port == 7) in b53_br_join()
1927 return -EINVAL; in b53_br_join()
1929 /* Make this port leave the all VLANs join since we will have proper in b53_br_join()
1934 reg &= ~BIT(port); in b53_br_join()
1940 b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); in b53_br_join()
1946 /* Add this local port to the remote port VLAN control in b53_br_join()
1947 * membership and update the remote port bitmask in b53_br_join()
1950 reg |= BIT(port); in b53_br_join()
1952 dev->ports[i].vlan_ctl_mask = reg; in b53_br_join()
1957 /* Configure the local port VLAN control membership to include in b53_br_join()
1958 * remote ports and update the local port bitmask in b53_br_join()
1960 b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan); in b53_br_join()
1961 dev->ports[port].vlan_ctl_mask = pvlan; in b53_br_join()
1967 void b53_br_leave(struct dsa_switch *ds, int port, struct dsa_bridge bridge) in b53_br_leave() argument
1969 struct b53_device *dev = ds->priv; in b53_br_leave()
1970 struct b53_vlan *vl = &dev->vlans[0]; in b53_br_leave()
1971 s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index; in b53_br_leave()
1975 b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); in b53_br_leave()
1983 reg &= ~BIT(port); in b53_br_leave()
1985 dev->ports[port].vlan_ctl_mask = reg; in b53_br_leave()
1988 if (port != i) in b53_br_leave()
1992 b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan); in b53_br_leave()
1993 dev->ports[port].vlan_ctl_mask = pvlan; in b53_br_leave()
1997 /* Make this port join all VLANs without VLAN entries */ in b53_br_leave()
2000 reg |= BIT(port); in b53_br_leave()
2006 vl->members |= BIT(port) | BIT(cpu_port); in b53_br_leave()
2007 vl->untag |= BIT(port) | BIT(cpu_port); in b53_br_leave()
2013 void b53_br_set_stp_state(struct dsa_switch *ds, int port, u8 state) in b53_br_set_stp_state() argument
2015 struct b53_device *dev = ds->priv; in b53_br_set_stp_state()
2036 dev_err(ds->dev, "invalid STP state: %d\n", state); in b53_br_set_stp_state()
2040 b53_read8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), ®); in b53_br_set_stp_state()
2043 b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), reg); in b53_br_set_stp_state()
2047 void b53_br_fast_age(struct dsa_switch *ds, int port) in b53_br_fast_age() argument
2049 struct b53_device *dev = ds->priv; in b53_br_fast_age()
2051 if (b53_fast_age_port(dev, port)) in b53_br_fast_age()
2052 dev_err(ds->dev, "fast ageing failed\n"); in b53_br_fast_age()
2056 int b53_br_flags_pre(struct dsa_switch *ds, int port, in b53_br_flags_pre() argument
2061 return -EINVAL; in b53_br_flags_pre()
2067 int b53_br_flags(struct dsa_switch *ds, int port, in b53_br_flags() argument
2072 b53_port_set_ucast_flood(ds->priv, port, in b53_br_flags()
2075 b53_port_set_mcast_flood(ds->priv, port, in b53_br_flags()
2078 b53_port_set_learning(ds->priv, port, in b53_br_flags()
2085 static bool b53_possible_cpu_port(struct dsa_switch *ds, int port) in b53_possible_cpu_port() argument
2088 * following ports: 5, 7 and 8, any other port is not supported in b53_possible_cpu_port()
2090 switch (port) { in b53_possible_cpu_port()
2100 static bool b53_can_enable_brcm_tags(struct dsa_switch *ds, int port, in b53_can_enable_brcm_tags() argument
2103 bool ret = b53_possible_cpu_port(ds, port); in b53_can_enable_brcm_tags()
2106 dev_warn(ds->dev, "Port %d is not Broadcom tag capable\n", in b53_can_enable_brcm_tags()
2107 port); in b53_can_enable_brcm_tags()
2114 dev_warn(ds->dev, in b53_can_enable_brcm_tags()
2115 "Port %d is stacked to Broadcom tag switch\n", port); in b53_can_enable_brcm_tags()
2126 enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds, int port, in b53_get_tag_protocol() argument
2129 struct b53_device *dev = ds->priv; in b53_get_tag_protocol()
2131 if (!b53_can_enable_brcm_tags(ds, port, mprot)) { in b53_get_tag_protocol()
2132 dev->tag_protocol = DSA_TAG_PROTO_NONE; in b53_get_tag_protocol()
2138 dev->tag_protocol = DSA_TAG_PROTO_BRCM_LEGACY; in b53_get_tag_protocol()
2142 /* Broadcom BCM58xx chips have a flow accelerator on Port 8 in b53_get_tag_protocol()
2145 if (dev->chip_id == BCM58XX_DEVICE_ID && port == B53_CPU_PORT) { in b53_get_tag_protocol()
2146 dev->tag_protocol = DSA_TAG_PROTO_BRCM_PREPEND; in b53_get_tag_protocol()
2150 dev->tag_protocol = DSA_TAG_PROTO_BRCM; in b53_get_tag_protocol()
2152 return dev->tag_protocol; in b53_get_tag_protocol()
2156 int b53_mirror_add(struct dsa_switch *ds, int port, in b53_mirror_add() argument
2160 struct b53_device *dev = ds->priv; in b53_mirror_add()
2169 reg |= BIT(port); in b53_mirror_add()
2174 reg |= mirror->to_local_port; in b53_mirror_add()
2182 void b53_mirror_del(struct dsa_switch *ds, int port, in b53_mirror_del() argument
2185 struct b53_device *dev = ds->priv; in b53_mirror_del()
2189 if (mirror->ingress) in b53_mirror_del()
2196 reg &= ~BIT(port); in b53_mirror_del()
2204 if (mirror->ingress) in b53_mirror_del()
2215 reg &= ~mirror->to_local_port; in b53_mirror_del()
2223 int b53_eee_init(struct dsa_switch *ds, int port, struct phy_device *phy) in b53_eee_init() argument
2231 b53_eee_enable_set(ds, port, true); in b53_eee_init()
2237 bool b53_support_eee(struct dsa_switch *ds, int port) in b53_support_eee() argument
2239 struct b53_device *dev = ds->priv; in b53_support_eee()
2245 int b53_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_keee *e) in b53_set_mac_eee() argument
2247 struct b53_device *dev = ds->priv; in b53_set_mac_eee()
2248 struct ethtool_keee *p = &dev->ports[port].eee; in b53_set_mac_eee()
2250 p->eee_enabled = e->eee_enabled; in b53_set_mac_eee()
2251 b53_eee_enable_set(ds, port, e->eee_enabled); in b53_set_mac_eee()
2257 static int b53_change_mtu(struct dsa_switch *ds, int port, int mtu) in b53_change_mtu() argument
2259 struct b53_device *dev = ds->priv; in b53_change_mtu()
2266 if (!dsa_is_cpu_port(ds, port)) in b53_change_mtu()
2275 static int b53_get_max_mtu(struct dsa_switch *ds, int port) in b53_get_max_mtu() argument
2277 struct b53_device *dev = ds->priv; in b53_get_max_mtu()
2377 .imp_port = 8,
2390 .imp_port = 8,
2403 .imp_port = 8,
2416 .imp_port = 8,
2430 .imp_port = 8,
2442 .imp_port = 8,
2455 .imp_port = 8,
2468 .imp_port = 8,
2481 .imp_port = 8,
2494 .imp_port = 8,
2507 .imp_port = 8,
2520 .imp_port = 8,
2533 .imp_port = 8,
2546 .imp_port = 8,
2559 .imp_port = 8,
2572 .imp_port = 8,
2586 .imp_port = 8,
2599 .imp_port = 8,
2612 .imp_port = 8,
2623 .imp_port = 8,
2642 if (chip->chip_id == dev->chip_id) { in b53_switch_init()
2643 if (!dev->enabled_ports) in b53_switch_init()
2644 dev->enabled_ports = chip->enabled_ports; in b53_switch_init()
2645 dev->name = chip->dev_name; in b53_switch_init()
2646 dev->duplex_reg = chip->duplex_reg; in b53_switch_init()
2647 dev->vta_regs[0] = chip->vta_regs[0]; in b53_switch_init()
2648 dev->vta_regs[1] = chip->vta_regs[1]; in b53_switch_init()
2649 dev->vta_regs[2] = chip->vta_regs[2]; in b53_switch_init()
2650 dev->jumbo_pm_reg = chip->jumbo_pm_reg; in b53_switch_init()
2651 dev->imp_port = chip->imp_port; in b53_switch_init()
2652 dev->num_vlans = chip->vlans; in b53_switch_init()
2653 dev->num_arl_bins = chip->arl_bins; in b53_switch_init()
2654 dev->num_arl_buckets = chip->arl_buckets; in b53_switch_init()
2671 /* BCM5325F - do not use port 4 */ in b53_switch_init()
2672 dev->enabled_ports &= ~BIT(4); in b53_switch_init()
2678 return -EINVAL; in b53_switch_init()
2685 dev->num_ports = fls(dev->enabled_ports); in b53_switch_init()
2687 dev->ds->num_ports = min_t(unsigned int, dev->num_ports, DSA_MAX_PORTS); in b53_switch_init()
2689 /* Include non standard CPU port built-in PHYs to be probed */ in b53_switch_init()
2691 for (i = 0; i < dev->num_ports; i++) { in b53_switch_init()
2692 if (!(dev->ds->phys_mii_mask & BIT(i)) && in b53_switch_init()
2693 !b53_possible_cpu_port(dev->ds, i)) in b53_switch_init()
2694 dev->ds->phys_mii_mask |= BIT(i); in b53_switch_init()
2698 dev->ports = devm_kcalloc(dev->dev, in b53_switch_init()
2699 dev->num_ports, sizeof(struct b53_port), in b53_switch_init()
2701 if (!dev->ports) in b53_switch_init()
2702 return -ENOMEM; in b53_switch_init()
2704 dev->vlans = devm_kcalloc(dev->dev, in b53_switch_init()
2705 dev->num_vlans, sizeof(struct b53_vlan), in b53_switch_init()
2707 if (!dev->vlans) in b53_switch_init()
2708 return -ENOMEM; in b53_switch_init()
2710 dev->reset_gpio = b53_switch_get_reset_gpio(dev); in b53_switch_init()
2711 if (dev->reset_gpio >= 0) { in b53_switch_init()
2712 ret = devm_gpio_request_one(dev->dev, dev->reset_gpio, in b53_switch_init()
2732 ds->dev = base; in b53_switch_alloc()
2738 ds->priv = dev; in b53_switch_alloc()
2739 dev->dev = base; in b53_switch_alloc()
2741 dev->ds = ds; in b53_switch_alloc()
2742 dev->priv = priv; in b53_switch_alloc()
2743 dev->ops = ops; in b53_switch_alloc()
2744 ds->ops = &b53_switch_ops; in b53_switch_alloc()
2745 ds->phylink_mac_ops = &b53_phylink_mac_ops; in b53_switch_alloc()
2746 dev->vlan_enabled = true; in b53_switch_alloc()
2752 ds->vlan_filtering_is_global = true; in b53_switch_alloc()
2754 mutex_init(&dev->reg_mutex); in b53_switch_alloc()
2755 mutex_init(&dev->stats_mutex); in b53_switch_alloc()
2756 mutex_init(&dev->arl_mutex); in b53_switch_alloc()
2786 dev->chip_id = BCM5325_DEVICE_ID; in b53_switch_detect()
2788 dev->chip_id = BCM5365_DEVICE_ID; in b53_switch_detect()
2794 dev->chip_id = id8; in b53_switch_detect()
2811 dev->chip_id = id32; in b53_switch_detect()
2814 dev_err(dev->dev, in b53_switch_detect()
2817 return -ENODEV; in b53_switch_detect()
2821 if (dev->chip_id == BCM5325_DEVICE_ID) in b53_switch_detect()
2823 &dev->core_rev); in b53_switch_detect()
2826 &dev->core_rev); in b53_switch_detect()
2834 if (dev->pdata) { in b53_switch_register()
2835 dev->chip_id = dev->pdata->chip_id; in b53_switch_register()
2836 dev->enabled_ports = dev->pdata->enabled_ports; in b53_switch_register()
2839 if (!dev->chip_id && b53_switch_detect(dev)) in b53_switch_register()
2840 return -EINVAL; in b53_switch_register()
2846 dev_info(dev->dev, "found switch: %s, rev %i\n", in b53_switch_register()
2847 dev->name, dev->core_rev); in b53_switch_register()
2849 return dsa_register_switch(dev->ds); in b53_switch_register()