Lines Matching +full:dsa +full:- +full:v1
1 // SPDX-License-Identifier: GPL-2.0
7 #include <net/dsa.h>
50 #define XRS700X_MIB_ETHTOOL_ONLY(o, n) {o, n, -1}
103 return -EOPNOTSUPP; in xrs700x_get_sset_count()
110 struct xrs700x_port *p = &priv->ports[port]; in xrs700x_read_port_counters()
117 mutex_lock(&p->mib_mutex); in xrs700x_read_port_counters()
120 regmap_write(priv->regmap, XRS_CNT_CTRL(port), 1); in xrs700x_read_port_counters()
126 regmap_read(priv->regmap, reg, &low); in xrs700x_read_port_counters()
127 regmap_read(priv->regmap, reg + 2, &high); in xrs700x_read_port_counters()
129 p->mib_data[i] += (high << 16) | low; in xrs700x_read_port_counters()
133 *(u64 *)s += p->mib_data[i]; in xrs700x_read_port_counters()
142 flags = u64_stats_update_begin_irqsave(&p->syncp); in xrs700x_read_port_counters()
143 p->stats64 = stats; in xrs700x_read_port_counters()
144 u64_stats_update_end_irqrestore(&p->syncp, flags); in xrs700x_read_port_counters()
146 mutex_unlock(&p->mib_mutex); in xrs700x_read_port_counters()
155 for (i = 0; i < priv->ds->num_ports; i++) in xrs700x_mib_work()
158 schedule_delayed_work(&priv->mib_work, XRS700X_MIB_INTERVAL); in xrs700x_mib_work()
164 struct xrs700x *priv = ds->priv; in xrs700x_get_ethtool_stats()
165 struct xrs700x_port *p = &priv->ports[port]; in xrs700x_get_ethtool_stats()
169 mutex_lock(&p->mib_mutex); in xrs700x_get_ethtool_stats()
170 memcpy(data, p->mib_data, sizeof(*data) * ARRAY_SIZE(xrs700x_mibs)); in xrs700x_get_ethtool_stats()
171 mutex_unlock(&p->mib_mutex); in xrs700x_get_ethtool_stats()
177 struct xrs700x *priv = ds->priv; in xrs700x_get_stats64()
178 struct xrs700x_port *p = &priv->ports[port]; in xrs700x_get_stats64()
182 start = u64_stats_fetch_begin(&p->syncp); in xrs700x_get_stats64()
183 *s = p->stats64; in xrs700x_get_stats64()
184 } while (u64_stats_fetch_retry(&p->syncp, start)); in xrs700x_get_stats64()
192 priv->ds->num_ports, in xrs700x_setup_regmap_range()
194 .rmf = &priv->ps_forward in xrs700x_setup_regmap_range()
198 priv->ds->num_ports, in xrs700x_setup_regmap_range()
200 .rmf = &priv->ps_management in xrs700x_setup_regmap_range()
204 priv->ds->num_ports, in xrs700x_setup_regmap_range()
206 .rmf = &priv->ps_sel_speed in xrs700x_setup_regmap_range()
210 priv->ds->num_ports, in xrs700x_setup_regmap_range()
212 .rmf = &priv->ps_cur_speed in xrs700x_setup_regmap_range()
218 *regfields[i].rmf = devm_regmap_field_alloc(priv->dev, in xrs700x_setup_regmap_range()
219 priv->regmap, in xrs700x_setup_regmap_range()
237 struct xrs700x *priv = ds->priv; in xrs700x_reset()
241 ret = regmap_write(priv->regmap, XRS_GENERAL, XRS_GENERAL_RESET); in xrs700x_reset()
245 ret = regmap_read_poll_timeout(priv->regmap, XRS_GENERAL, in xrs700x_reset()
250 dev_err_ratelimited(priv->dev, "error resetting switch: %d\n", in xrs700x_reset()
260 struct xrs700x *priv = ds->priv; in xrs700x_port_stp_state_set()
279 dev_err(ds->dev, "invalid STP state: %d\n", state); in xrs700x_port_stp_state_set()
283 regmap_fields_write(priv->ps_forward, port, val); in xrs700x_port_stp_state_set()
289 regmap_update_bits(priv->regmap, XRS_ETH_ADDR_CFG(port, 0), 1, bpdus); in xrs700x_port_stp_state_set()
291 dev_dbg_ratelimited(priv->dev, "%s - port: %d, state: %u, val: 0x%x\n", in xrs700x_port_stp_state_set()
301 struct xrs700x *priv = ds->priv; in xrs700x_port_add_bpdu_ipf()
307 ret = regmap_write(priv->regmap, XRS_ETH_ADDR_CFG(port, 0), 48 << 2); in xrs700x_port_add_bpdu_ipf()
313 ret = regmap_write(priv->regmap, XRS_ETH_ADDR_0(port, 0) + i, in xrs700x_port_add_bpdu_ipf()
321 for (i = 0; i < ds->num_ports; i++) { in xrs700x_port_add_bpdu_ipf()
326 ret = regmap_write(priv->regmap, XRS_ETH_ADDR_FWD_MIRROR(port, 0), val); in xrs700x_port_add_bpdu_ipf()
330 ret = regmap_write(priv->regmap, XRS_ETH_ADDR_FWD_ALLOW(port, 0), 0); in xrs700x_port_add_bpdu_ipf()
345 struct xrs700x *priv = ds->priv; in xrs700x_port_add_hsrsup_ipf()
351 ret = regmap_write(priv->regmap, XRS_ETH_ADDR_CFG(port, 1), 40 << 2); in xrs700x_port_add_hsrsup_ipf()
357 ret = regmap_write(priv->regmap, XRS_ETH_ADDR_0(port, 1) + i, in xrs700x_port_add_hsrsup_ipf()
365 for (i = 0; i < ds->num_ports; i++) { in xrs700x_port_add_hsrsup_ipf()
370 ret = regmap_write(priv->regmap, XRS_ETH_ADDR_FWD_MIRROR(port, 1), val); in xrs700x_port_add_hsrsup_ipf()
378 ret = regmap_write(priv->regmap, XRS_ETH_ADDR_FWD_ALLOW(port, 1), val); in xrs700x_port_add_hsrsup_ipf()
388 struct xrs700x *priv = ds->priv; in xrs700x_port_setup()
394 /* Disable forwarding to non-CPU ports */ in xrs700x_port_setup()
395 for (i = 0; i < ds->num_ports; i++) { in xrs700x_port_setup()
401 ret = regmap_write(priv->regmap, XRS_PORT_FWD_MASK(port), val); in xrs700x_port_setup()
406 ret = regmap_fields_write(priv->ps_management, port, val); in xrs700x_port_setup()
421 struct xrs700x *priv = ds->priv; in xrs700x_setup()
428 for (i = 0; i < ds->num_ports; i++) { in xrs700x_setup()
434 schedule_delayed_work(&priv->mib_work, XRS700X_MIB_INTERVAL); in xrs700x_setup()
441 struct xrs700x *priv = ds->priv; in xrs700x_teardown()
443 cancel_delayed_work_sync(&priv->mib_work); in xrs700x_teardown()
452 config->supported_interfaces); in xrs700x_phylink_get_caps()
453 config->mac_capabilities = MAC_10FD | MAC_100FD; in xrs700x_phylink_get_caps()
459 phy_interface_set_rgmii(config->supported_interfaces); in xrs700x_phylink_get_caps()
460 config->mac_capabilities = MAC_10FD | MAC_100FD | MAC_1000FD; in xrs700x_phylink_get_caps()
464 dev_err(ds->dev, "Unsupported port: %i\n", port); in xrs700x_phylink_get_caps()
486 struct xrs700x *priv = dp->ds->priv; in xrs700x_mac_link_up()
487 int port = dp->index; in xrs700x_mac_link_up()
504 regmap_fields_write(priv->ps_sel_speed, port, val); in xrs700x_mac_link_up()
506 dev_dbg_ratelimited(priv->dev, "%s: port: %d mode: %u speed: %u\n", in xrs700x_mac_link_up()
514 struct xrs700x *priv = ds->priv; in xrs700x_bridge_common()
517 for (i = 0; i < ds->num_ports; i++) { in xrs700x_bridge_common()
529 for (i = 0; i < ds->num_ports; i++) { in xrs700x_bridge_common()
534 ret = regmap_write(priv->regmap, XRS_PORT_FWD_MASK(i), mask); in xrs700x_bridge_common()
540 ret = regmap_write(priv->regmap, XRS_PORT_FWD_MASK(port), in xrs700x_bridge_common()
568 struct xrs700x *priv = ds->priv; in xrs700x_hsr_join()
581 return -EOPNOTSUPP; in xrs700x_hsr_join()
590 "Only HSR v1 and PRP v1 can be offloaded"); in xrs700x_hsr_join()
591 return -EOPNOTSUPP; in xrs700x_hsr_join()
595 if (dp->index != port) { in xrs700x_hsr_join()
607 regmap_fields_write(priv->ps_forward, partner->index, in xrs700x_hsr_join()
609 regmap_fields_write(priv->ps_forward, port, XRS_PORT_DISABLED); in xrs700x_hsr_join()
611 regmap_write(priv->regmap, XRS_HSR_CFG(partner->index), in xrs700x_hsr_join()
613 regmap_write(priv->regmap, XRS_HSR_CFG(port), in xrs700x_hsr_join()
619 val = GENMASK(ds->num_ports - 1, 0); in xrs700x_hsr_join()
621 val &= ~BIT(partner->index); in xrs700x_hsr_join()
626 regmap_write(priv->regmap, XRS_PORT_FWD_MASK(partner->index), val); in xrs700x_hsr_join()
627 regmap_write(priv->regmap, XRS_PORT_FWD_MASK(port), val); in xrs700x_hsr_join()
629 regmap_fields_write(priv->ps_forward, partner->index, in xrs700x_hsr_join()
631 regmap_fields_write(priv->ps_forward, port, XRS_PORT_FORWARDING); in xrs700x_hsr_join()
638 ret = xrs700x_port_add_hsrsup_ipf(ds, partner->index, fwd ? port : -1); in xrs700x_hsr_join()
642 ret = xrs700x_port_add_hsrsup_ipf(ds, port, fwd ? partner->index : -1); in xrs700x_hsr_join()
646 regmap_update_bits(priv->regmap, in xrs700x_hsr_join()
647 XRS_ETH_ADDR_CFG(partner->index, 1), 1, 1); in xrs700x_hsr_join()
648 regmap_update_bits(priv->regmap, XRS_ETH_ADDR_CFG(port, 1), 1, 1); in xrs700x_hsr_join()
651 hsr_pair[1] = partner->index; in xrs700x_hsr_join()
653 user = dsa_to_port(ds, hsr_pair[i])->user; in xrs700x_hsr_join()
654 user->features |= XRS7000X_SUPPORTED_HSR_FEATURES; in xrs700x_hsr_join()
664 struct xrs700x *priv = ds->priv; in xrs700x_hsr_leave()
670 if (dp->index != port) { in xrs700x_hsr_leave()
679 regmap_fields_write(priv->ps_forward, partner->index, in xrs700x_hsr_leave()
681 regmap_fields_write(priv->ps_forward, port, XRS_PORT_DISABLED); in xrs700x_hsr_leave()
683 regmap_write(priv->regmap, XRS_HSR_CFG(partner->index), 0); in xrs700x_hsr_leave()
684 regmap_write(priv->regmap, XRS_HSR_CFG(port), 0); in xrs700x_hsr_leave()
687 val = GENMASK(ds->num_ports - 1, 0); in xrs700x_hsr_leave()
689 regmap_write(priv->regmap, XRS_PORT_FWD_MASK(partner->index), val); in xrs700x_hsr_leave()
690 regmap_write(priv->regmap, XRS_PORT_FWD_MASK(port), val); in xrs700x_hsr_leave()
692 regmap_fields_write(priv->ps_forward, partner->index, in xrs700x_hsr_leave()
694 regmap_fields_write(priv->ps_forward, port, XRS_PORT_FORWARDING); in xrs700x_hsr_leave()
700 regmap_update_bits(priv->regmap, in xrs700x_hsr_leave()
701 XRS_ETH_ADDR_CFG(partner->index, 1), 1, 0); in xrs700x_hsr_leave()
702 regmap_update_bits(priv->regmap, XRS_ETH_ADDR_CFG(port, 1), 1, 0); in xrs700x_hsr_leave()
705 hsr_pair[1] = partner->index; in xrs700x_hsr_leave()
707 user = dsa_to_port(ds, hsr_pair[i])->user; in xrs700x_hsr_leave()
708 user->features &= ~XRS7000X_SUPPORTED_HSR_FEATURES; in xrs700x_hsr_leave()
742 ret = regmap_read(priv->regmap, XRS_DEV_ID0, &id); in xrs700x_detect()
744 dev_err(priv->dev, "error %d while reading switch id.\n", in xrs700x_detect()
749 info = of_device_get_match_data(priv->dev); in xrs700x_detect()
751 return -EINVAL; in xrs700x_detect()
753 if (info->id == id) { in xrs700x_detect()
754 priv->ds->num_ports = info->num_ports; in xrs700x_detect()
755 dev_info(priv->dev, "%s detected.\n", info->name); in xrs700x_detect()
759 dev_err(priv->dev, "expected switch id 0x%x but found 0x%x.\n", in xrs700x_detect()
760 info->id, id); in xrs700x_detect()
762 return -ENODEV; in xrs700x_detect()
774 ds->dev = base; in xrs700x_switch_alloc()
780 INIT_DELAYED_WORK(&priv->mib_work, xrs700x_mib_work); in xrs700x_switch_alloc()
782 ds->ops = &xrs700x_ops; in xrs700x_switch_alloc()
783 ds->phylink_mac_ops = &xrs700x_phylink_mac_ops; in xrs700x_switch_alloc()
784 ds->priv = priv; in xrs700x_switch_alloc()
785 priv->dev = base; in xrs700x_switch_alloc()
787 priv->ds = ds; in xrs700x_switch_alloc()
788 priv->priv = devpriv; in xrs700x_switch_alloc()
796 struct xrs700x_port *p = &priv->ports[port]; in xrs700x_alloc_port_mib()
798 p->mib_data = devm_kcalloc(priv->dev, ARRAY_SIZE(xrs700x_mibs), in xrs700x_alloc_port_mib()
799 sizeof(*p->mib_data), GFP_KERNEL); in xrs700x_alloc_port_mib()
800 if (!p->mib_data) in xrs700x_alloc_port_mib()
801 return -ENOMEM; in xrs700x_alloc_port_mib()
803 mutex_init(&p->mib_mutex); in xrs700x_alloc_port_mib()
804 u64_stats_init(&p->syncp); in xrs700x_alloc_port_mib()
822 priv->ports = devm_kcalloc(priv->dev, priv->ds->num_ports, in xrs700x_switch_register()
823 sizeof(*priv->ports), GFP_KERNEL); in xrs700x_switch_register()
824 if (!priv->ports) in xrs700x_switch_register()
825 return -ENOMEM; in xrs700x_switch_register()
827 for (i = 0; i < priv->ds->num_ports; i++) { in xrs700x_switch_register()
833 return dsa_register_switch(priv->ds); in xrs700x_switch_register()
839 dsa_unregister_switch(priv->ds); in xrs700x_switch_remove()
845 dsa_switch_shutdown(priv->ds); in xrs700x_switch_shutdown()
850 MODULE_DESCRIPTION("Arrow SpeedChips XRS700x DSA driver");