Lines Matching +full:int +full:- +full:fwd +full:- +full:mask
1 // SPDX-License-Identifier: GPL-2.0
45 unsigned int offset;
47 int stats64_offset;
50 #define XRS700X_MIB_ETHTOOL_ONLY(o, n) {o, n, -1}
86 static void xrs700x_get_strings(struct dsa_switch *ds, int port, in xrs700x_get_strings()
89 int i; in xrs700x_get_strings()
100 static int xrs700x_get_sset_count(struct dsa_switch *ds, int port, int sset) in xrs700x_get_sset_count()
103 return -EOPNOTSUPP; in xrs700x_get_sset_count()
108 static void xrs700x_read_port_counters(struct xrs700x *priv, int port) in xrs700x_read_port_counters()
110 struct xrs700x_port *p = &priv->ports[port]; in xrs700x_read_port_counters()
113 int i; 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()
123 unsigned int high = 0, low = 0, reg; 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()
153 int i; in xrs700x_mib_work()
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()
161 static void xrs700x_get_ethtool_stats(struct dsa_switch *ds, int port, in xrs700x_get_ethtool_stats()
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()
174 static void xrs700x_get_stats64(struct dsa_switch *ds, int port, in xrs700x_get_stats64()
177 struct xrs700x *priv = ds->priv; in xrs700x_get_stats64()
178 struct xrs700x_port *p = &priv->ports[port]; in xrs700x_get_stats64()
179 unsigned int start; 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()
187 static int xrs700x_setup_regmap_range(struct xrs700x *priv) in xrs700x_setup_regmap_range()
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()
215 int i = 0; 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()
229 int port, in xrs700x_get_tag_protocol()
235 static int xrs700x_reset(struct dsa_switch *ds) in xrs700x_reset()
237 struct xrs700x *priv = ds->priv; in xrs700x_reset()
238 unsigned int val; in xrs700x_reset()
239 int ret; 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()
257 static void xrs700x_port_stp_state_set(struct dsa_switch *ds, int port, in xrs700x_port_stp_state_set()
260 struct xrs700x *priv = ds->priv; in xrs700x_port_stp_state_set()
261 unsigned int bpdus = 1; in xrs700x_port_stp_state_set()
262 unsigned int val; 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()
299 static int xrs700x_port_add_bpdu_ipf(struct dsa_switch *ds, int port) in xrs700x_port_add_bpdu_ipf()
301 struct xrs700x *priv = ds->priv; in xrs700x_port_add_bpdu_ipf()
302 unsigned int val = 0; in xrs700x_port_add_bpdu_ipf()
303 int i = 0; in xrs700x_port_add_bpdu_ipf()
304 int ret; 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()
342 static int xrs700x_port_add_hsrsup_ipf(struct dsa_switch *ds, int port, in xrs700x_port_add_hsrsup_ipf()
343 int fwdport) in xrs700x_port_add_hsrsup_ipf()
345 struct xrs700x *priv = ds->priv; in xrs700x_port_add_hsrsup_ipf()
346 unsigned int val = 0; in xrs700x_port_add_hsrsup_ipf()
347 int i = 0; in xrs700x_port_add_hsrsup_ipf()
348 int ret; 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()
385 static int xrs700x_port_setup(struct dsa_switch *ds, int port) in xrs700x_port_setup()
388 struct xrs700x *priv = ds->priv; in xrs700x_port_setup()
389 unsigned int val = 0; in xrs700x_port_setup()
390 int ret, i; 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()
419 static int xrs700x_setup(struct dsa_switch *ds) in xrs700x_setup()
421 struct xrs700x *priv = ds->priv; in xrs700x_setup()
422 int ret, i; 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()
446 static void xrs700x_phylink_get_caps(struct dsa_switch *ds, int port, in xrs700x_phylink_get_caps()
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()
469 static void xrs700x_mac_link_up(struct dsa_switch *ds, int port, in xrs700x_mac_link_up()
470 unsigned int mode, phy_interface_t interface, in xrs700x_mac_link_up()
472 int speed, int duplex, in xrs700x_mac_link_up()
475 struct xrs700x *priv = ds->priv; in xrs700x_mac_link_up()
476 unsigned int val; in xrs700x_mac_link_up()
492 regmap_fields_write(priv->ps_sel_speed, port, val); in xrs700x_mac_link_up()
494 dev_dbg_ratelimited(priv->dev, "%s: port: %d mode: %u speed: %u\n", in xrs700x_mac_link_up()
498 static int xrs700x_bridge_common(struct dsa_switch *ds, int port, in xrs700x_bridge_common()
501 unsigned int i, cpu_mask = 0, mask = 0; in xrs700x_bridge_common() local
502 struct xrs700x *priv = ds->priv; in xrs700x_bridge_common()
503 int ret; in xrs700x_bridge_common()
505 for (i = 0; i < ds->num_ports; i++) { in xrs700x_bridge_common()
514 mask |= BIT(i); in xrs700x_bridge_common()
517 for (i = 0; i < ds->num_ports; i++) { in xrs700x_bridge_common()
522 ret = regmap_write(priv->regmap, XRS_PORT_FWD_MASK(i), mask); in xrs700x_bridge_common()
528 ret = regmap_write(priv->regmap, XRS_PORT_FWD_MASK(port), in xrs700x_bridge_common()
537 static int xrs700x_bridge_join(struct dsa_switch *ds, int port, in xrs700x_bridge_join()
544 static void xrs700x_bridge_leave(struct dsa_switch *ds, int port, in xrs700x_bridge_leave()
550 static int xrs700x_hsr_join(struct dsa_switch *ds, int port, in xrs700x_hsr_join()
553 unsigned int val = XRS_HSR_CFG_HSR_PRP; in xrs700x_hsr_join()
555 struct xrs700x *priv = ds->priv; in xrs700x_hsr_join()
557 int ret, i, hsr_pair[2]; in xrs700x_hsr_join()
559 bool fwd = false; in xrs700x_hsr_join() local
567 return -EOPNOTSUPP; in xrs700x_hsr_join()
574 return -EOPNOTSUPP; in xrs700x_hsr_join()
577 if (dp->index != port) { in xrs700x_hsr_join()
589 regmap_fields_write(priv->ps_forward, partner->index, in xrs700x_hsr_join()
591 regmap_fields_write(priv->ps_forward, port, XRS_PORT_DISABLED); in xrs700x_hsr_join()
593 regmap_write(priv->regmap, XRS_HSR_CFG(partner->index), in xrs700x_hsr_join()
595 regmap_write(priv->regmap, XRS_HSR_CFG(port), in xrs700x_hsr_join()
601 val = GENMASK(ds->num_ports - 1, 0); in xrs700x_hsr_join()
603 val &= ~BIT(partner->index); in xrs700x_hsr_join()
605 fwd = true; in xrs700x_hsr_join()
608 regmap_write(priv->regmap, XRS_PORT_FWD_MASK(partner->index), val); in xrs700x_hsr_join()
609 regmap_write(priv->regmap, XRS_PORT_FWD_MASK(port), val); in xrs700x_hsr_join()
611 regmap_fields_write(priv->ps_forward, partner->index, in xrs700x_hsr_join()
613 regmap_fields_write(priv->ps_forward, port, XRS_PORT_FORWARDING); in xrs700x_hsr_join()
620 ret = xrs700x_port_add_hsrsup_ipf(ds, partner->index, fwd ? port : -1); in xrs700x_hsr_join()
624 ret = xrs700x_port_add_hsrsup_ipf(ds, port, fwd ? partner->index : -1); in xrs700x_hsr_join()
628 regmap_update_bits(priv->regmap, in xrs700x_hsr_join()
629 XRS_ETH_ADDR_CFG(partner->index, 1), 1, 1); in xrs700x_hsr_join()
630 regmap_update_bits(priv->regmap, XRS_ETH_ADDR_CFG(port, 1), 1, 1); in xrs700x_hsr_join()
633 hsr_pair[1] = partner->index; in xrs700x_hsr_join()
635 slave = dsa_to_port(ds, hsr_pair[i])->slave; in xrs700x_hsr_join()
636 slave->features |= XRS7000X_SUPPORTED_HSR_FEATURES; in xrs700x_hsr_join()
642 static int xrs700x_hsr_leave(struct dsa_switch *ds, int port, in xrs700x_hsr_leave()
646 struct xrs700x *priv = ds->priv; in xrs700x_hsr_leave()
648 int i, hsr_pair[2]; in xrs700x_hsr_leave()
649 unsigned int val; in xrs700x_hsr_leave()
652 if (dp->index != port) { in xrs700x_hsr_leave()
661 regmap_fields_write(priv->ps_forward, partner->index, in xrs700x_hsr_leave()
663 regmap_fields_write(priv->ps_forward, port, XRS_PORT_DISABLED); in xrs700x_hsr_leave()
665 regmap_write(priv->regmap, XRS_HSR_CFG(partner->index), 0); in xrs700x_hsr_leave()
666 regmap_write(priv->regmap, XRS_HSR_CFG(port), 0); in xrs700x_hsr_leave()
669 val = GENMASK(ds->num_ports - 1, 0); in xrs700x_hsr_leave()
671 regmap_write(priv->regmap, XRS_PORT_FWD_MASK(partner->index), val); in xrs700x_hsr_leave()
672 regmap_write(priv->regmap, XRS_PORT_FWD_MASK(port), val); in xrs700x_hsr_leave()
674 regmap_fields_write(priv->ps_forward, partner->index, in xrs700x_hsr_leave()
676 regmap_fields_write(priv->ps_forward, port, XRS_PORT_FORWARDING); in xrs700x_hsr_leave()
682 regmap_update_bits(priv->regmap, in xrs700x_hsr_leave()
683 XRS_ETH_ADDR_CFG(partner->index, 1), 1, 0); in xrs700x_hsr_leave()
684 regmap_update_bits(priv->regmap, XRS_ETH_ADDR_CFG(port, 1), 1, 0); in xrs700x_hsr_leave()
687 hsr_pair[1] = partner->index; in xrs700x_hsr_leave()
689 slave = dsa_to_port(ds, hsr_pair[i])->slave; in xrs700x_hsr_leave()
690 slave->features &= ~XRS7000X_SUPPORTED_HSR_FEATURES; in xrs700x_hsr_leave()
713 static int xrs700x_detect(struct xrs700x *priv) in xrs700x_detect()
716 unsigned int id; in xrs700x_detect()
717 int ret; in xrs700x_detect()
719 ret = regmap_read(priv->regmap, XRS_DEV_ID0, &id); in xrs700x_detect()
721 dev_err(priv->dev, "error %d while reading switch id.\n", in xrs700x_detect()
726 info = of_device_get_match_data(priv->dev); in xrs700x_detect()
728 return -EINVAL; in xrs700x_detect()
730 if (info->id == id) { in xrs700x_detect()
731 priv->ds->num_ports = info->num_ports; in xrs700x_detect()
732 dev_info(priv->dev, "%s detected.\n", info->name); in xrs700x_detect()
736 dev_err(priv->dev, "expected switch id 0x%x but found 0x%x.\n", in xrs700x_detect()
737 info->id, id); in xrs700x_detect()
739 return -ENODEV; in xrs700x_detect()
751 ds->dev = base; in xrs700x_switch_alloc()
757 INIT_DELAYED_WORK(&priv->mib_work, xrs700x_mib_work); in xrs700x_switch_alloc()
759 ds->ops = &xrs700x_ops; in xrs700x_switch_alloc()
760 ds->priv = priv; in xrs700x_switch_alloc()
761 priv->dev = base; in xrs700x_switch_alloc()
763 priv->ds = ds; in xrs700x_switch_alloc()
764 priv->priv = devpriv; in xrs700x_switch_alloc()
770 static int xrs700x_alloc_port_mib(struct xrs700x *priv, int port) in xrs700x_alloc_port_mib()
772 struct xrs700x_port *p = &priv->ports[port]; in xrs700x_alloc_port_mib()
774 p->mib_data = devm_kcalloc(priv->dev, ARRAY_SIZE(xrs700x_mibs), in xrs700x_alloc_port_mib()
775 sizeof(*p->mib_data), GFP_KERNEL); in xrs700x_alloc_port_mib()
776 if (!p->mib_data) in xrs700x_alloc_port_mib()
777 return -ENOMEM; in xrs700x_alloc_port_mib()
779 mutex_init(&p->mib_mutex); in xrs700x_alloc_port_mib()
780 u64_stats_init(&p->syncp); in xrs700x_alloc_port_mib()
785 int xrs700x_switch_register(struct xrs700x *priv) in xrs700x_switch_register()
787 int ret; in xrs700x_switch_register()
788 int i; in xrs700x_switch_register()
798 priv->ports = devm_kcalloc(priv->dev, priv->ds->num_ports, in xrs700x_switch_register()
799 sizeof(*priv->ports), GFP_KERNEL); in xrs700x_switch_register()
800 if (!priv->ports) in xrs700x_switch_register()
801 return -ENOMEM; in xrs700x_switch_register()
803 for (i = 0; i < priv->ds->num_ports; i++) { in xrs700x_switch_register()
809 return dsa_register_switch(priv->ds); in xrs700x_switch_register()
815 dsa_unregister_switch(priv->ds); in xrs700x_switch_remove()
821 dsa_switch_shutdown(priv->ds); in xrs700x_switch_shutdown()