Lines Matching refs:dev

227 static int b53_do_vlan_op(struct b53_device *dev, u8 op)  in b53_do_vlan_op()  argument
231 b53_write8(dev, B53_ARLIO_PAGE, dev->vta_regs[0], VTA_START_CMD | op); in b53_do_vlan_op()
236 b53_read8(dev, B53_ARLIO_PAGE, dev->vta_regs[0], &vta); in b53_do_vlan_op()
246 static void b53_set_vlan_entry(struct b53_device *dev, u16 vid, in b53_set_vlan_entry() argument
249 if (is5325(dev)) { in b53_set_vlan_entry()
255 if (dev->core_rev >= 3) in b53_set_vlan_entry()
261 b53_write32(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_25, entry); in b53_set_vlan_entry()
262 b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, vid | in b53_set_vlan_entry()
264 } else if (is5365(dev)) { in b53_set_vlan_entry()
271 b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_65, entry); in b53_set_vlan_entry()
272 b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_65, vid | in b53_set_vlan_entry()
275 b53_write16(dev, B53_ARLIO_PAGE, dev->vta_regs[1], vid); in b53_set_vlan_entry()
276 b53_write32(dev, B53_ARLIO_PAGE, dev->vta_regs[2], in b53_set_vlan_entry()
279 b53_do_vlan_op(dev, VTA_CMD_WRITE); in b53_set_vlan_entry()
282 dev_dbg(dev->ds->dev, "VID: %d, members: 0x%04x, untag: 0x%04x\n", in b53_set_vlan_entry()
286 static void b53_get_vlan_entry(struct b53_device *dev, u16 vid, in b53_get_vlan_entry() argument
289 if (is5325(dev)) { in b53_get_vlan_entry()
292 b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, vid | in b53_get_vlan_entry()
294 b53_read32(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_25, &entry); in b53_get_vlan_entry()
296 if (dev->core_rev >= 3) in b53_get_vlan_entry()
303 } else if (is5365(dev)) { in b53_get_vlan_entry()
306 b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_65, vid | in b53_get_vlan_entry()
308 b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_65, &entry); in b53_get_vlan_entry()
316 b53_write16(dev, B53_ARLIO_PAGE, dev->vta_regs[1], vid); in b53_get_vlan_entry()
317 b53_do_vlan_op(dev, VTA_CMD_READ); in b53_get_vlan_entry()
318 b53_read32(dev, B53_ARLIO_PAGE, dev->vta_regs[2], &entry); in b53_get_vlan_entry()
325 static void b53_set_forwarding(struct b53_device *dev, int enable) in b53_set_forwarding() argument
329 b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt); in b53_set_forwarding()
336 b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt); in b53_set_forwarding()
340 b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_CTRL, &mgmt); in b53_set_forwarding()
342 b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_CTRL, mgmt); in b53_set_forwarding()
347 b53_read8(dev, B53_CTRL_PAGE, B53_IP_MULTICAST_CTRL, &mgmt); in b53_set_forwarding()
349 b53_write8(dev, B53_CTRL_PAGE, B53_IP_MULTICAST_CTRL, mgmt); in b53_set_forwarding()
352 static void b53_enable_vlan(struct b53_device *dev, int port, bool enable, in b53_enable_vlan() argument
357 b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt); in b53_enable_vlan()
358 b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL0, &vc0); in b53_enable_vlan()
359 b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL1, &vc1); in b53_enable_vlan()
361 if (is5325(dev) || is5365(dev)) { in b53_enable_vlan()
362 b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, &vc4); in b53_enable_vlan()
363 b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_25, &vc5); in b53_enable_vlan()
364 } else if (is63xx(dev)) { in b53_enable_vlan()
365 b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_63XX, &vc4); in b53_enable_vlan()
366 b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_63XX, &vc5); in b53_enable_vlan()
368 b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4, &vc4); in b53_enable_vlan()
369 b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5, &vc5); in b53_enable_vlan()
384 if (is5325(dev)) in b53_enable_vlan()
387 if (is5325(dev) || is5365(dev)) in b53_enable_vlan()
396 if (is5325(dev) || is5365(dev)) in b53_enable_vlan()
401 if (is5325(dev) || is5365(dev)) in b53_enable_vlan()
405 if (!is5325(dev) && !is5365(dev)) in b53_enable_vlan()
408 b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL0, vc0); in b53_enable_vlan()
409 b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL1, vc1); in b53_enable_vlan()
411 if (is5325(dev) || is5365(dev)) { in b53_enable_vlan()
413 if (is5325(dev) && enable) in b53_enable_vlan()
414 b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3, in b53_enable_vlan()
417 b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3, 0); in b53_enable_vlan()
419 b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, vc4); in b53_enable_vlan()
420 b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_25, vc5); in b53_enable_vlan()
421 } else if (is63xx(dev)) { in b53_enable_vlan()
422 b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3_63XX, 0); in b53_enable_vlan()
423 b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_63XX, vc4); in b53_enable_vlan()
424 b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_63XX, vc5); in b53_enable_vlan()
426 b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3, 0); in b53_enable_vlan()
427 b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4, vc4); in b53_enable_vlan()
428 b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5, vc5); in b53_enable_vlan()
431 b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt); in b53_enable_vlan()
433 dev->vlan_enabled = enable; in b53_enable_vlan()
435 dev_dbg(dev->dev, "Port %d VLAN enabled: %d, filtering: %d\n", in b53_enable_vlan()
439 static int b53_set_jumbo(struct b53_device *dev, bool enable, bool allow_10_100) in b53_set_jumbo() argument
444 if (is5325(dev) || is5365(dev)) in b53_set_jumbo()
448 port_mask = dev->enabled_ports; in b53_set_jumbo()
454 b53_write32(dev, B53_JUMBO_PAGE, dev->jumbo_pm_reg, port_mask); in b53_set_jumbo()
455 return b53_write16(dev, B53_JUMBO_PAGE, dev->jumbo_size_reg, max_size); in b53_set_jumbo()
458 static int b53_flush_arl(struct b53_device *dev, u8 mask) in b53_flush_arl() argument
462 b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL, in b53_flush_arl()
468 b53_read8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL, in b53_flush_arl()
480 b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL, FAST_AGE_DYNAMIC); in b53_flush_arl()
484 static int b53_fast_age_port(struct b53_device *dev, int port) in b53_fast_age_port() argument
486 b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_PORT_CTRL, port); in b53_fast_age_port()
488 return b53_flush_arl(dev, FAST_AGE_PORT); in b53_fast_age_port()
491 static int b53_fast_age_vlan(struct b53_device *dev, u16 vid) in b53_fast_age_vlan() argument
493 b53_write16(dev, B53_CTRL_PAGE, B53_FAST_AGE_VID_CTRL, vid); in b53_fast_age_vlan()
495 return b53_flush_arl(dev, FAST_AGE_VLAN); in b53_fast_age_vlan()
500 struct b53_device *dev = ds->priv; in b53_imp_vlan_setup() local
508 b53_for_each_port(dev, i) { in b53_imp_vlan_setup()
509 b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), &pvlan); in b53_imp_vlan_setup()
511 b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), pvlan); in b53_imp_vlan_setup()
516 static void b53_port_set_ucast_flood(struct b53_device *dev, int port, in b53_port_set_ucast_flood() argument
521 b53_read16(dev, B53_CTRL_PAGE, B53_UC_FLOOD_MASK, &uc); in b53_port_set_ucast_flood()
526 b53_write16(dev, B53_CTRL_PAGE, B53_UC_FLOOD_MASK, uc); in b53_port_set_ucast_flood()
529 static void b53_port_set_mcast_flood(struct b53_device *dev, int port, in b53_port_set_mcast_flood() argument
534 b53_read16(dev, B53_CTRL_PAGE, B53_MC_FLOOD_MASK, &mc); in b53_port_set_mcast_flood()
539 b53_write16(dev, B53_CTRL_PAGE, B53_MC_FLOOD_MASK, mc); in b53_port_set_mcast_flood()
541 b53_read16(dev, B53_CTRL_PAGE, B53_IPMC_FLOOD_MASK, &mc); in b53_port_set_mcast_flood()
546 b53_write16(dev, B53_CTRL_PAGE, B53_IPMC_FLOOD_MASK, mc); in b53_port_set_mcast_flood()
549 static void b53_port_set_learning(struct b53_device *dev, int port, in b53_port_set_learning() argument
554 b53_read16(dev, B53_CTRL_PAGE, B53_DIS_LEARNING, &reg); in b53_port_set_learning()
559 b53_write16(dev, B53_CTRL_PAGE, B53_DIS_LEARNING, reg); in b53_port_set_learning()
564 struct b53_device *dev = ds->priv; in b53_enable_port() local
574 b53_port_set_ucast_flood(dev, port, true); in b53_enable_port()
575 b53_port_set_mcast_flood(dev, port, true); in b53_enable_port()
576 b53_port_set_learning(dev, port, false); in b53_enable_port()
578 if (dev->ops->irq_enable) in b53_enable_port()
579 ret = dev->ops->irq_enable(dev, port); in b53_enable_port()
584 b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), 0); in b53_enable_port()
590 b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); in b53_enable_port()
593 pvlan |= dev->ports[port].vlan_ctl_mask; in b53_enable_port()
594 b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan); in b53_enable_port()
599 if (dev->ports[port].eee.eee_enabled) in b53_enable_port()
608 struct b53_device *dev = ds->priv; in b53_disable_port() local
612 b53_read8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), &reg); in b53_disable_port()
614 b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), reg); in b53_disable_port()
616 if (dev->ops->irq_disable) in b53_disable_port()
617 dev->ops->irq_disable(dev, port); in b53_disable_port()
623 struct b53_device *dev = ds->priv; in b53_brcm_hdr_setup() local
624 bool tag_en = !(dev->tag_protocol == DSA_TAG_PROTO_NONE); in b53_brcm_hdr_setup()
645 b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &hdr_ctl); in b53_brcm_hdr_setup()
650 b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, hdr_ctl); in b53_brcm_hdr_setup()
653 b53_read8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &hdr_ctl); in b53_brcm_hdr_setup()
658 b53_write8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, hdr_ctl); in b53_brcm_hdr_setup()
661 b53_read8(dev, B53_MGMT_PAGE, B53_BRCM_HDR, &hdr_ctl); in b53_brcm_hdr_setup()
666 b53_write8(dev, B53_MGMT_PAGE, B53_BRCM_HDR, hdr_ctl); in b53_brcm_hdr_setup()
669 if (!is58xx(dev)) in b53_brcm_hdr_setup()
675 b53_read16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_RX_DIS, &reg); in b53_brcm_hdr_setup()
680 b53_write16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_RX_DIS, reg); in b53_brcm_hdr_setup()
685 b53_read16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_TX_DIS, &reg); in b53_brcm_hdr_setup()
690 b53_write16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_TX_DIS, reg); in b53_brcm_hdr_setup()
694 static void b53_enable_cpu_port(struct b53_device *dev, int port) in b53_enable_cpu_port() argument
699 if ((is5325(dev) || is5365(dev)) && port == B53_CPU_PORT_25) in b53_enable_cpu_port()
705 b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), port_ctrl); in b53_enable_cpu_port()
707 b53_brcm_hdr_setup(dev->ds, port); in b53_enable_cpu_port()
709 b53_port_set_ucast_flood(dev, port, true); in b53_enable_cpu_port()
710 b53_port_set_mcast_flood(dev, port, true); in b53_enable_cpu_port()
711 b53_port_set_learning(dev, port, false); in b53_enable_cpu_port()
714 static void b53_enable_mib(struct b53_device *dev) in b53_enable_mib() argument
718 b53_read8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &gc); in b53_enable_mib()
720 b53_write8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc); in b53_enable_mib()
723 static u16 b53_default_pvid(struct b53_device *dev) in b53_default_pvid() argument
725 if (is5325(dev) || is5365(dev)) in b53_default_pvid()
733 struct b53_device *dev = ds->priv; in b53_vlan_port_needs_forced_tagged() local
735 return dev->tag_protocol == DSA_TAG_PROTO_NONE && dsa_is_cpu_port(ds, port); in b53_vlan_port_needs_forced_tagged()
740 struct b53_device *dev = ds->priv; in b53_configure_vlan() local
746 def_vid = b53_default_pvid(dev); in b53_configure_vlan()
749 if (is5325(dev) || is5365(dev)) { in b53_configure_vlan()
750 for (i = def_vid; i < dev->num_vlans; i++) in b53_configure_vlan()
751 b53_set_vlan_entry(dev, i, &vl); in b53_configure_vlan()
753 b53_do_vlan_op(dev, VTA_CMD_CLEAR); in b53_configure_vlan()
756 b53_enable_vlan(dev, -1, dev->vlan_enabled, ds->vlan_filtering); in b53_configure_vlan()
764 b53_for_each_port(dev, i) { in b53_configure_vlan()
765 v = &dev->vlans[def_vid]; in b53_configure_vlan()
769 b53_write16(dev, B53_VLAN_PAGE, in b53_configure_vlan()
776 for (vid = def_vid; vid < dev->num_vlans; vid++) { in b53_configure_vlan()
777 v = &dev->vlans[vid]; in b53_configure_vlan()
782 b53_set_vlan_entry(dev, vid, v); in b53_configure_vlan()
783 b53_fast_age_vlan(dev, vid); in b53_configure_vlan()
790 static void b53_switch_reset_gpio(struct b53_device *dev) in b53_switch_reset_gpio() argument
792 int gpio = dev->reset_gpio; in b53_switch_reset_gpio()
805 dev->current_page = 0xff; in b53_switch_reset_gpio()
808 static int b53_switch_reset(struct b53_device *dev) in b53_switch_reset() argument
813 b53_switch_reset_gpio(dev); in b53_switch_reset()
815 if (is539x(dev)) { in b53_switch_reset()
816 b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x83); in b53_switch_reset()
817 b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x00); in b53_switch_reset()
825 if (dev->chip_id == BCM58XX_DEVICE_ID || in b53_switch_reset()
826 dev->chip_id == BCM583XX_DEVICE_ID) { in b53_switch_reset()
827 b53_read8(dev, B53_CTRL_PAGE, B53_SOFTRESET, &reg); in b53_switch_reset()
829 b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, reg); in b53_switch_reset()
832 b53_read8(dev, B53_CTRL_PAGE, B53_SOFTRESET, &reg); in b53_switch_reset()
840 dev_err(dev->dev, in b53_switch_reset()
846 b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt); in b53_switch_reset()
852 b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt); in b53_switch_reset()
853 b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt); in b53_switch_reset()
856 dev_err(dev->dev, "Failed to enable switch!\n"); in b53_switch_reset()
861 b53_enable_mib(dev); in b53_switch_reset()
863 return b53_flush_arl(dev, FAST_AGE_STATIC); in b53_switch_reset()
927 static const struct b53_mib_desc *b53_get_mib(struct b53_device *dev) in b53_get_mib() argument
929 if (is5365(dev)) in b53_get_mib()
931 else if (is63xx(dev)) in b53_get_mib()
933 else if (is58xx(dev)) in b53_get_mib()
939 static unsigned int b53_get_mib_size(struct b53_device *dev) in b53_get_mib_size() argument
941 if (is5365(dev)) in b53_get_mib_size()
943 else if (is63xx(dev)) in b53_get_mib_size()
945 else if (is58xx(dev)) in b53_get_mib_size()
967 struct b53_device *dev = ds->priv; in b53_get_strings() local
968 const struct b53_mib_desc *mibs = b53_get_mib(dev); in b53_get_strings()
969 unsigned int mib_size = b53_get_mib_size(dev); in b53_get_strings()
989 struct b53_device *dev = ds->priv; in b53_get_ethtool_stats() local
990 const struct b53_mib_desc *mibs = b53_get_mib(dev); in b53_get_ethtool_stats()
991 unsigned int mib_size = b53_get_mib_size(dev); in b53_get_ethtool_stats()
996 if (is5365(dev) && port == 5) in b53_get_ethtool_stats()
999 mutex_lock(&dev->stats_mutex); in b53_get_ethtool_stats()
1005 b53_read64(dev, B53_MIB_PAGE(port), s->offset, &val); in b53_get_ethtool_stats()
1009 b53_read32(dev, B53_MIB_PAGE(port), s->offset, in b53_get_ethtool_stats()
1016 mutex_unlock(&dev->stats_mutex); in b53_get_ethtool_stats()
1034 struct b53_device *dev = ds->priv; in b53_get_sset_count() local
1038 return b53_get_mib_size(dev); in b53_get_sset_count()
1057 struct b53_device *dev = priv; in b53_devlink_vlan_table_get() local
1062 for (i = 0; i < dev->num_vlans; i++) { in b53_devlink_vlan_table_get()
1063 vl = &dev->vlans[i]; in b53_devlink_vlan_table_get()
1074 struct b53_device *dev = ds->priv; in b53_setup_devlink_resources() local
1077 devlink_resource_size_params_init(&size_params, dev->num_vlans, in b53_setup_devlink_resources()
1078 dev->num_vlans, in b53_setup_devlink_resources()
1081 err = dsa_devlink_resource_register(ds, "VLAN", dev->num_vlans, in b53_setup_devlink_resources()
1090 b53_devlink_vlan_table_get, dev); in b53_setup_devlink_resources()
1101 struct b53_device *dev = ds->priv; in b53_setup() local
1108 ds->untag_bridge_pvid = dev->tag_protocol == DSA_TAG_PROTO_NONE; in b53_setup()
1110 ret = b53_reset_switch(dev); in b53_setup()
1112 dev_err(ds->dev, "failed to reset switch\n"); in b53_setup()
1116 b53_reset_mib(dev); in b53_setup()
1118 ret = b53_apply_config(dev); in b53_setup()
1120 dev_err(ds->dev, "failed to apply configuration\n"); in b53_setup()
1127 for (port = 0; port < dev->num_ports; port++) { in b53_setup()
1129 b53_enable_cpu_port(dev, port); in b53_setup()
1142 static void b53_force_link(struct b53_device *dev, int port, int link) in b53_force_link() argument
1147 if (port == dev->imp_port) { in b53_force_link()
1155 b53_read8(dev, B53_CTRL_PAGE, off, &reg); in b53_force_link()
1161 b53_write8(dev, B53_CTRL_PAGE, off, reg); in b53_force_link()
1164 static void b53_force_port_config(struct b53_device *dev, int port, in b53_force_port_config() argument
1171 if (port == dev->imp_port) { in b53_force_port_config()
1179 b53_read8(dev, B53_CTRL_PAGE, off, &reg); in b53_force_port_config()
1200 dev_err(dev->dev, "unknown speed: %d\n", speed); in b53_force_port_config()
1209 b53_write8(dev, B53_CTRL_PAGE, off, reg); in b53_force_port_config()
1215 struct b53_device *dev = ds->priv; in b53_adjust_63xx_rgmii() local
1218 if (port == dev->imp_port) in b53_adjust_63xx_rgmii()
1223 b53_read8(dev, B53_CTRL_PAGE, off, &rgmii_ctrl); in b53_adjust_63xx_rgmii()
1243 if (port != dev->imp_port) { in b53_adjust_63xx_rgmii()
1244 if (is63268(dev)) in b53_adjust_63xx_rgmii()
1250 b53_write8(dev, B53_CTRL_PAGE, off, rgmii_ctrl); in b53_adjust_63xx_rgmii()
1252 dev_dbg(ds->dev, "Configured port %d for %s\n", port, in b53_adjust_63xx_rgmii()
1259 struct b53_device *dev = ds->priv; in b53_adjust_link() local
1260 struct ethtool_eee *p = &dev->ports[port].eee; in b53_adjust_link()
1269 if (is5301x(dev) && dsa_is_cpu_port(ds, port)) in b53_adjust_link()
1278 b53_force_port_config(dev, port, phydev->speed, phydev->duplex, in b53_adjust_link()
1280 b53_force_link(dev, port, phydev->link); in b53_adjust_link()
1282 if (is63xx(dev) && port >= B53_63XX_RGMII0) in b53_adjust_link()
1285 if (is531x5(dev) && phy_interface_is_rgmii(phydev)) { in b53_adjust_link()
1286 if (port == dev->imp_port) in b53_adjust_link()
1294 b53_read8(dev, B53_CTRL_PAGE, off, &rgmii_ctrl); in b53_adjust_link()
1317 b53_write8(dev, B53_CTRL_PAGE, off, rgmii_ctrl); in b53_adjust_link()
1319 dev_info(ds->dev, "Configured port %d for %s\n", port, in b53_adjust_link()
1324 if (is5325(dev)) { in b53_adjust_link()
1325 b53_read8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL, in b53_adjust_link()
1330 b53_write8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL, in b53_adjust_link()
1332 b53_read8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL, in b53_adjust_link()
1336 dev_err(ds->dev, in b53_adjust_link()
1349 struct b53_device *dev = ds->priv; in b53_port_event() local
1353 b53_read16(dev, B53_STAT_PAGE, B53_LINK_STAT, &sts); in b53_port_event()
1362 struct b53_device *dev = ds->priv; in b53_phylink_get_caps() local
1390 if (!(is5325(dev) || is5365(dev))) in b53_phylink_get_caps()
1394 if (dev->ops->phylink_get_caps) in b53_phylink_get_caps()
1395 dev->ops->phylink_get_caps(dev, port, config); in b53_phylink_get_caps()
1402 struct b53_device *dev = ds->priv; in b53_phylink_mac_select_pcs() local
1404 if (!dev->ops->phylink_mac_select_pcs) in b53_phylink_mac_select_pcs()
1407 return dev->ops->phylink_mac_select_pcs(dev, port, interface); in b53_phylink_mac_select_pcs()
1421 struct b53_device *dev = ds->priv; in b53_phylink_mac_link_down() local
1427 b53_force_link(dev, port, false); in b53_phylink_mac_link_down()
1432 dev->ops->serdes_link_set) in b53_phylink_mac_link_down()
1433 dev->ops->serdes_link_set(dev, port, mode, interface, false); in b53_phylink_mac_link_down()
1444 struct b53_device *dev = ds->priv; in b53_phylink_mac_link_up() local
1446 if (is63xx(dev) && port >= B53_63XX_RGMII0) in b53_phylink_mac_link_up()
1453 b53_force_port_config(dev, port, speed, duplex, in b53_phylink_mac_link_up()
1455 b53_force_link(dev, port, true); in b53_phylink_mac_link_up()
1460 dev->ops->serdes_link_set) in b53_phylink_mac_link_up()
1461 dev->ops->serdes_link_set(dev, port, mode, interface, true); in b53_phylink_mac_link_up()
1468 struct b53_device *dev = ds->priv; in b53_vlan_filtering() local
1470 b53_enable_vlan(dev, port, dev->vlan_enabled, vlan_filtering); in b53_vlan_filtering()
1479 struct b53_device *dev = ds->priv; in b53_vlan_prepare() local
1481 if ((is5325(dev) || is5365(dev)) && vlan->vid == 0) in b53_vlan_prepare()
1488 if (dev->chip_id == BCM7278_DEVICE_ID && port == 7 && in b53_vlan_prepare()
1492 if (vlan->vid >= dev->num_vlans) in b53_vlan_prepare()
1495 b53_enable_vlan(dev, port, true, ds->vlan_filtering); in b53_vlan_prepare()
1504 struct b53_device *dev = ds->priv; in b53_vlan_add() local
1514 vl = &dev->vlans[vlan->vid]; in b53_vlan_add()
1516 b53_get_vlan_entry(dev, vlan->vid, vl); in b53_vlan_add()
1518 if (vlan->vid == 0 && vlan->vid == b53_default_pvid(dev)) in b53_vlan_add()
1527 b53_set_vlan_entry(dev, vlan->vid, vl); in b53_vlan_add()
1528 b53_fast_age_vlan(dev, vlan->vid); in b53_vlan_add()
1531 b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), in b53_vlan_add()
1533 b53_fast_age_vlan(dev, vlan->vid); in b53_vlan_add()
1543 struct b53_device *dev = ds->priv; in b53_vlan_del() local
1548 b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &pvid); in b53_vlan_del()
1550 vl = &dev->vlans[vlan->vid]; in b53_vlan_del()
1552 b53_get_vlan_entry(dev, vlan->vid, vl); in b53_vlan_del()
1557 pvid = b53_default_pvid(dev); in b53_vlan_del()
1562 b53_set_vlan_entry(dev, vlan->vid, vl); in b53_vlan_del()
1563 b53_fast_age_vlan(dev, vlan->vid); in b53_vlan_del()
1565 b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), pvid); in b53_vlan_del()
1566 b53_fast_age_vlan(dev, pvid); in b53_vlan_del()
1573 static int b53_arl_op_wait(struct b53_device *dev) in b53_arl_op_wait() argument
1579 b53_read8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, &reg); in b53_arl_op_wait()
1586 dev_warn(dev->dev, "timeout waiting for ARL to finish: 0x%02x\n", reg); in b53_arl_op_wait()
1591 static int b53_arl_rw_op(struct b53_device *dev, unsigned int op) in b53_arl_rw_op() argument
1598 b53_read8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, &reg); in b53_arl_rw_op()
1604 if (dev->vlan_enabled) in b53_arl_rw_op()
1608 b53_write8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, reg); in b53_arl_rw_op()
1610 return b53_arl_op_wait(dev); in b53_arl_rw_op()
1613 static int b53_arl_read(struct b53_device *dev, u64 mac, in b53_arl_read() argument
1620 ret = b53_arl_op_wait(dev); in b53_arl_read()
1624 bitmap_zero(free_bins, dev->num_arl_bins); in b53_arl_read()
1627 for (i = 0; i < dev->num_arl_bins; i++) { in b53_arl_read()
1631 b53_read64(dev, B53_ARLIO_PAGE, in b53_arl_read()
1633 b53_read32(dev, B53_ARLIO_PAGE, in b53_arl_read()
1643 if (dev->vlan_enabled && in b53_arl_read()
1650 *idx = find_first_bit(free_bins, dev->num_arl_bins); in b53_arl_read()
1651 return *idx >= dev->num_arl_bins ? -ENOSPC : -ENOENT; in b53_arl_read()
1654 static int b53_arl_op(struct b53_device *dev, int op, int port, in b53_arl_op() argument
1667 b53_write48(dev, B53_ARLIO_PAGE, B53_MAC_ADDR_IDX, mac); in b53_arl_op()
1668 b53_write16(dev, B53_ARLIO_PAGE, B53_VLAN_ID_IDX, vid); in b53_arl_op()
1671 ret = b53_arl_rw_op(dev, 1); in b53_arl_op()
1675 ret = b53_arl_read(dev, mac, vid, &ent, &idx); in b53_arl_op()
1685 dev_dbg(dev->dev, "{%pM,%.4d} no space left in ARL\n", in b53_arl_op()
1690 dev_dbg(dev->dev, "{%pM,%.4d} not found, using idx: %d\n", in b53_arl_op()
1695 dev_dbg(dev->dev, "{%pM,%.4d} found, using idx: %d\n", in b53_arl_op()
1721 b53_write64(dev, B53_ARLIO_PAGE, in b53_arl_op()
1723 b53_write32(dev, B53_ARLIO_PAGE, in b53_arl_op()
1726 return b53_arl_rw_op(dev, 0); in b53_arl_op()
1765 static int b53_arl_search_wait(struct b53_device *dev) in b53_arl_search_wait() argument
1771 b53_read8(dev, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, &reg); in b53_arl_search_wait()
1784 static void b53_arl_search_rd(struct b53_device *dev, u8 idx, in b53_arl_search_rd() argument
1790 b53_read64(dev, B53_ARLIO_PAGE, in b53_arl_search_rd()
1792 b53_read32(dev, B53_ARLIO_PAGE, in b53_arl_search_rd()
1884 dev_err(ds->dev, "failed to delete MDB entry\n"); in b53_mdb_del()
1893 struct b53_device *dev = ds->priv; in b53_br_join() local
1901 if (dev->chip_id == BCM7278_DEVICE_ID && port == 7) in b53_br_join()
1907 if (is58xx(dev)) { in b53_br_join()
1908 b53_read16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, &reg); in b53_br_join()
1912 b53_write16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, reg); in b53_br_join()
1915 b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); in b53_br_join()
1917 b53_for_each_port(dev, i) { in b53_br_join()
1924 b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), &reg); in b53_br_join()
1926 b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), reg); in b53_br_join()
1927 dev->ports[i].vlan_ctl_mask = reg; in b53_br_join()
1935 b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan); in b53_br_join()
1936 dev->ports[port].vlan_ctl_mask = pvlan; in b53_br_join()
1944 struct b53_device *dev = ds->priv; in b53_br_leave() local
1945 struct b53_vlan *vl = &dev->vlans[0]; in b53_br_leave()
1950 b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); in b53_br_leave()
1952 b53_for_each_port(dev, i) { in b53_br_leave()
1957 b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), &reg); in b53_br_leave()
1959 b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), reg); in b53_br_leave()
1960 dev->ports[port].vlan_ctl_mask = reg; in b53_br_leave()
1967 b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan); in b53_br_leave()
1968 dev->ports[port].vlan_ctl_mask = pvlan; in b53_br_leave()
1970 pvid = b53_default_pvid(dev); in b53_br_leave()
1973 if (is58xx(dev)) { in b53_br_leave()
1974 b53_read16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, &reg); in b53_br_leave()
1978 b53_write16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, reg); in b53_br_leave()
1980 b53_get_vlan_entry(dev, pvid, vl); in b53_br_leave()
1983 b53_set_vlan_entry(dev, pvid, vl); in b53_br_leave()
1990 struct b53_device *dev = ds->priv; in b53_br_set_stp_state() local
2011 dev_err(ds->dev, "invalid STP state: %d\n", state); in b53_br_set_stp_state()
2015 b53_read8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), &reg); in b53_br_set_stp_state()
2018 b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), reg); in b53_br_set_stp_state()
2024 struct b53_device *dev = ds->priv; in b53_br_fast_age() local
2026 if (b53_fast_age_port(dev, port)) in b53_br_fast_age()
2027 dev_err(ds->dev, "fast ageing failed\n"); in b53_br_fast_age()
2081 dev_warn(ds->dev, "Port %d is not Broadcom tag capable\n", in b53_can_enable_brcm_tags()
2089 dev_warn(ds->dev, in b53_can_enable_brcm_tags()
2104 struct b53_device *dev = ds->priv; in b53_get_tag_protocol() local
2107 dev->tag_protocol = DSA_TAG_PROTO_NONE; in b53_get_tag_protocol()
2112 if (is5325(dev) || is5365(dev) || is63xx(dev)) { in b53_get_tag_protocol()
2113 dev->tag_protocol = DSA_TAG_PROTO_BRCM_LEGACY; in b53_get_tag_protocol()
2120 if (dev->chip_id == BCM58XX_DEVICE_ID && port == B53_CPU_PORT) { in b53_get_tag_protocol()
2121 dev->tag_protocol = DSA_TAG_PROTO_BRCM_PREPEND; in b53_get_tag_protocol()
2125 dev->tag_protocol = DSA_TAG_PROTO_BRCM; in b53_get_tag_protocol()
2127 return dev->tag_protocol; in b53_get_tag_protocol()
2135 struct b53_device *dev = ds->priv; in b53_mirror_add() local
2143 b53_read16(dev, B53_MGMT_PAGE, loc, &reg); in b53_mirror_add()
2145 b53_write16(dev, B53_MGMT_PAGE, loc, reg); in b53_mirror_add()
2147 b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, &reg); in b53_mirror_add()
2151 b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg); in b53_mirror_add()
2160 struct b53_device *dev = ds->priv; in b53_mirror_del() local
2170 b53_read16(dev, B53_MGMT_PAGE, loc, &reg); in b53_mirror_del()
2174 b53_write16(dev, B53_MGMT_PAGE, loc, reg); in b53_mirror_del()
2180 b53_read16(dev, B53_MGMT_PAGE, B53_EG_MIR_CTL, &reg); in b53_mirror_del()
2182 b53_read16(dev, B53_MGMT_PAGE, B53_IG_MIR_CTL, &reg); in b53_mirror_del()
2186 b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, &reg); in b53_mirror_del()
2192 b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg); in b53_mirror_del()
2198 struct b53_device *dev = ds->priv; in b53_eee_enable_set() local
2201 b53_read16(dev, B53_EEE_PAGE, B53_EEE_EN_CTRL, &reg); in b53_eee_enable_set()
2206 b53_write16(dev, B53_EEE_PAGE, B53_EEE_EN_CTRL, reg); in b53_eee_enable_set()
2229 struct b53_device *dev = ds->priv; in b53_get_mac_eee() local
2230 struct ethtool_eee *p = &dev->ports[port].eee; in b53_get_mac_eee()
2233 if (is5325(dev) || is5365(dev)) in b53_get_mac_eee()
2236 b53_read16(dev, B53_EEE_PAGE, B53_EEE_LPI_INDICATE, &reg); in b53_get_mac_eee()
2246 struct b53_device *dev = ds->priv; in b53_set_mac_eee() local
2247 struct ethtool_eee *p = &dev->ports[port].eee; in b53_set_mac_eee()
2249 if (is5325(dev) || is5365(dev)) in b53_set_mac_eee()
2261 struct b53_device *dev = ds->priv; in b53_change_mtu() local
2265 if (is5325(dev) || is5365(dev)) in b53_change_mtu()
2272 allow_10_100 = (dev->chip_id == BCM583XX_DEVICE_ID); in b53_change_mtu()
2274 return b53_set_jumbo(dev, enable_jumbo, allow_10_100); in b53_change_mtu()
2629 static int b53_switch_init(struct b53_device *dev) in b53_switch_init() argument
2637 if (chip->chip_id == dev->chip_id) { in b53_switch_init()
2638 if (!dev->enabled_ports) in b53_switch_init()
2639 dev->enabled_ports = chip->enabled_ports; in b53_switch_init()
2640 dev->name = chip->dev_name; in b53_switch_init()
2641 dev->duplex_reg = chip->duplex_reg; in b53_switch_init()
2642 dev->vta_regs[0] = chip->vta_regs[0]; in b53_switch_init()
2643 dev->vta_regs[1] = chip->vta_regs[1]; in b53_switch_init()
2644 dev->vta_regs[2] = chip->vta_regs[2]; in b53_switch_init()
2645 dev->jumbo_pm_reg = chip->jumbo_pm_reg; in b53_switch_init()
2646 dev->imp_port = chip->imp_port; in b53_switch_init()
2647 dev->num_vlans = chip->vlans; in b53_switch_init()
2648 dev->num_arl_bins = chip->arl_bins; in b53_switch_init()
2649 dev->num_arl_buckets = chip->arl_buckets; in b53_switch_init()
2655 if (is5325(dev)) { in b53_switch_init()
2658 b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, &vc4); in b53_switch_init()
2667 dev->enabled_ports &= ~BIT(4); in b53_switch_init()
2680 dev->num_ports = fls(dev->enabled_ports); in b53_switch_init()
2682 dev->ds->num_ports = min_t(unsigned int, dev->num_ports, DSA_MAX_PORTS); in b53_switch_init()
2685 if (is539x(dev) || is531x5(dev)) { in b53_switch_init()
2686 for (i = 0; i < dev->num_ports; i++) { in b53_switch_init()
2687 if (!(dev->ds->phys_mii_mask & BIT(i)) && in b53_switch_init()
2688 !b53_possible_cpu_port(dev->ds, i)) in b53_switch_init()
2689 dev->ds->phys_mii_mask |= BIT(i); in b53_switch_init()
2693 dev->ports = devm_kcalloc(dev->dev, in b53_switch_init()
2694 dev->num_ports, sizeof(struct b53_port), in b53_switch_init()
2696 if (!dev->ports) in b53_switch_init()
2699 dev->vlans = devm_kcalloc(dev->dev, in b53_switch_init()
2700 dev->num_vlans, sizeof(struct b53_vlan), in b53_switch_init()
2702 if (!dev->vlans) in b53_switch_init()
2705 dev->reset_gpio = b53_switch_get_reset_gpio(dev); in b53_switch_init()
2706 if (dev->reset_gpio >= 0) { in b53_switch_init()
2707 ret = devm_gpio_request_one(dev->dev, dev->reset_gpio, in b53_switch_init()
2721 struct b53_device *dev; in b53_switch_alloc() local
2727 ds->dev = base; in b53_switch_alloc()
2729 dev = devm_kzalloc(base, sizeof(*dev), GFP_KERNEL); in b53_switch_alloc()
2730 if (!dev) in b53_switch_alloc()
2733 ds->priv = dev; in b53_switch_alloc()
2734 dev->dev = base; in b53_switch_alloc()
2736 dev->ds = ds; in b53_switch_alloc()
2737 dev->priv = priv; in b53_switch_alloc()
2738 dev->ops = ops; in b53_switch_alloc()
2740 dev->vlan_enabled = true; in b53_switch_alloc()
2748 mutex_init(&dev->reg_mutex); in b53_switch_alloc()
2749 mutex_init(&dev->stats_mutex); in b53_switch_alloc()
2750 mutex_init(&dev->arl_mutex); in b53_switch_alloc()
2752 return dev; in b53_switch_alloc()
2756 int b53_switch_detect(struct b53_device *dev) in b53_switch_detect() argument
2763 ret = b53_read8(dev, B53_MGMT_PAGE, B53_DEVICE_ID, &id8); in b53_switch_detect()
2776 b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, 0xf); in b53_switch_detect()
2777 b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, &tmp); in b53_switch_detect()
2780 dev->chip_id = BCM5325_DEVICE_ID; in b53_switch_detect()
2782 dev->chip_id = BCM5365_DEVICE_ID; in b53_switch_detect()
2788 dev->chip_id = id8; in b53_switch_detect()
2791 ret = b53_read32(dev, B53_MGMT_PAGE, B53_DEVICE_ID, &id32); in b53_switch_detect()
2805 dev->chip_id = id32; in b53_switch_detect()
2808 dev_err(dev->dev, in b53_switch_detect()
2815 if (dev->chip_id == BCM5325_DEVICE_ID) in b53_switch_detect()
2816 return b53_read8(dev, B53_STAT_PAGE, B53_REV_ID_25, in b53_switch_detect()
2817 &dev->core_rev); in b53_switch_detect()
2819 return b53_read8(dev, B53_MGMT_PAGE, B53_REV_ID, in b53_switch_detect()
2820 &dev->core_rev); in b53_switch_detect()
2824 int b53_switch_register(struct b53_device *dev) in b53_switch_register() argument
2828 if (dev->pdata) { in b53_switch_register()
2829 dev->chip_id = dev->pdata->chip_id; in b53_switch_register()
2830 dev->enabled_ports = dev->pdata->enabled_ports; in b53_switch_register()
2833 if (!dev->chip_id && b53_switch_detect(dev)) in b53_switch_register()
2836 ret = b53_switch_init(dev); in b53_switch_register()
2840 dev_info(dev->dev, "found switch: %s, rev %i\n", in b53_switch_register()
2841 dev->name, dev->core_rev); in b53_switch_register()
2843 return dsa_register_switch(dev->ds); in b53_switch_register()