Lines Matching +full:timeout +full:- +full:secs
1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2017-2024 Microchip Technology Inc.
11 #include <linux/platform_data/microchip-ksz.h>
50 if (!dsa_is_cpu_port(dev->ds, port)) in ksz9477_change_mtu()
72 mutex_lock(&dev->vlan_mutex); in ksz9477_get_vlan_table()
80 dev_dbg(dev->dev, "Failed to read vlan table\n"); in ksz9477_get_vlan_table()
91 mutex_unlock(&dev->vlan_mutex); in ksz9477_get_vlan_table()
101 mutex_lock(&dev->vlan_mutex); in ksz9477_set_vlan_table()
113 dev_dbg(dev->dev, "Failed to write vlan table\n"); in ksz9477_set_vlan_table()
120 dev->vlan_cache[vid].table[0] = vlan_table[0]; in ksz9477_set_vlan_table()
121 dev->vlan_cache[vid].table[1] = vlan_table[1]; in ksz9477_set_vlan_table()
122 dev->vlan_cache[vid].table[2] = vlan_table[2]; in ksz9477_set_vlan_table()
125 mutex_unlock(&dev->vlan_mutex); in ksz9477_set_vlan_table()
186 if (dev->chip_id == KSZ9893_CHIP_ID || in ksz9477_reset_switch()
187 dev->chip_id == KSZ8563_CHIP_ID || in ksz9477_reset_switch()
188 dev->chip_id == KSZ9563_CHIP_ID) in ksz9477_reset_switch()
192 if (dev->synclko_disable) in ksz9477_reset_switch()
194 else if (dev->synclko_125) in ksz9477_reset_switch()
203 struct ksz_port *p = &dev->ports[port]; in ksz9477_r_mib_cnt()
209 data = p->freeze ? MIB_COUNTER_FLUSH_FREEZE : 0; in ksz9477_r_mib_cnt()
219 dev_dbg(dev->dev, "Failed to get MIB\n"); in ksz9477_r_mib_cnt()
231 addr = dev->info->mib_names[addr].index; in ksz9477_r_mib_pkt()
238 struct ksz_port *p = &dev->ports[port]; in ksz9477_freeze_mib()
241 mutex_lock(&p->mib.cnt_mutex); in ksz9477_freeze_mib()
245 p->freeze = freeze; in ksz9477_freeze_mib()
246 mutex_unlock(&p->mib.cnt_mutex); in ksz9477_freeze_mib()
258 * half-duplex mode. The switch might not be able to communicate anymore in ksz9477_half_duplex_monitor()
260 * errata-sheet for more information: in ksz9477_half_duplex_monitor()
261 …hip.com/downloads/aemDocuments/documents/UNG/ProductDocuments/Errata/KSZ9477S-Errata-DS80000754.pdf in ksz9477_half_duplex_monitor()
262 * To workaround this issue, half-duplex mode should be avoided. in ksz9477_half_duplex_monitor()
265 dev_warn_once(dev->dev, in ksz9477_half_duplex_monitor()
266 "Half-duplex detected on port %d, transmission halt may occur\n", in ksz9477_half_duplex_monitor()
270 dev_crit_once(dev->dev, in ksz9477_half_duplex_monitor()
288 /* Transmission halt with Half-Duplex and VLAN */ in ksz9477_half_duplex_monitor()
289 dev_crit_once(dev->dev, in ksz9477_half_duplex_monitor()
318 struct ksz_port_mib *mib = &dev->ports[port].mib; in ksz9477_port_init_cnt()
321 mutex_lock(&mib->cnt_mutex); in ksz9477_port_init_cnt()
326 mutex_unlock(&mib->cnt_mutex); in ksz9477_port_init_cnt()
335 if (dev->chip_id == KSZ8563_CHIP_ID && reg == MII_BMSR) in ksz9477_r_phy_quirks()
350 if (!dev->info->internal_phy[addr]) { in ksz9477_r_phy()
351 struct ksz_port *p = &dev->ports[addr]; in ksz9477_r_phy()
376 if (p->phydev.speed == SPEED_1000) in ksz9477_r_phy()
400 if (!dev->info->internal_phy[addr]) in ksz9477_w_phy()
406 /* Errata: When using SPI, I2C, or in-band register access, in ksz9477_w_phy()
408 * 32-bit writes instead of 16-bit writes. in ksz9477_w_phy()
427 const u16 *regs = dev->info->regs; in ksz9477_flush_dyn_mac_table()
434 if (port < dev->info->port_cnt) { in ksz9477_flush_dyn_mac_table()
469 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; in ksz9477_port_vlan_add()
472 err = ksz9477_get_vlan_table(dev, vlan->vid, vlan_table); in ksz9477_port_vlan_add()
478 vlan_table[0] = VLAN_VALID | (vlan->vid & VLAN_FID_M); in ksz9477_port_vlan_add()
483 vlan_table[1] &= ~(BIT(dev->cpu_port)); in ksz9477_port_vlan_add()
485 vlan_table[2] |= BIT(port) | BIT(dev->cpu_port); in ksz9477_port_vlan_add()
487 err = ksz9477_set_vlan_table(dev, vlan->vid, vlan_table); in ksz9477_port_vlan_add()
494 if (vlan->flags & BRIDGE_VLAN_INFO_PVID) in ksz9477_port_vlan_add()
495 ksz_pwrite16(dev, port, REG_PORT_DEFAULT_VID, vlan->vid); in ksz9477_port_vlan_add()
503 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; in ksz9477_port_vlan_del()
510 if (ksz9477_get_vlan_table(dev, vlan->vid, vlan_table)) { in ksz9477_port_vlan_del()
511 dev_dbg(dev->dev, "Failed to get vlan table\n"); in ksz9477_port_vlan_del()
512 return -ETIMEDOUT; in ksz9477_port_vlan_del()
517 if (pvid == vlan->vid) in ksz9477_port_vlan_del()
523 if (ksz9477_set_vlan_table(dev, vlan->vid, vlan_table)) { in ksz9477_port_vlan_del()
524 dev_dbg(dev->dev, "Failed to set vlan table\n"); in ksz9477_port_vlan_del()
525 return -ETIMEDOUT; in ksz9477_port_vlan_del()
540 mutex_lock(&dev->alu_mutex); in ksz9477_fdb_add()
557 dev_dbg(dev->dev, "Failed to read ALU\n"); in ksz9477_fdb_add()
581 dev_dbg(dev->dev, "Failed to write ALU\n"); in ksz9477_fdb_add()
584 mutex_unlock(&dev->alu_mutex); in ksz9477_fdb_add()
596 mutex_lock(&dev->alu_mutex); in ksz9477_fdb_del()
613 dev_dbg(dev->dev, "Failed to read ALU\n"); in ksz9477_fdb_del()
647 dev_dbg(dev->dev, "Failed to write ALU\n"); in ksz9477_fdb_del()
650 mutex_unlock(&dev->alu_mutex); in ksz9477_fdb_del()
657 alu->is_static = !!(alu_table[0] & ALU_V_STATIC_VALID); in ksz9477_convert_alu()
658 alu->is_src_filter = !!(alu_table[0] & ALU_V_SRC_FILTER); in ksz9477_convert_alu()
659 alu->is_dst_filter = !!(alu_table[0] & ALU_V_DST_FILTER); in ksz9477_convert_alu()
660 alu->prio_age = (alu_table[0] >> ALU_V_PRIO_AGE_CNT_S) & in ksz9477_convert_alu()
662 alu->mstp = alu_table[0] & ALU_V_MSTP_M; in ksz9477_convert_alu()
664 alu->is_override = !!(alu_table[1] & ALU_V_OVERRIDE); in ksz9477_convert_alu()
665 alu->is_use_fid = !!(alu_table[1] & ALU_V_USE_FID); in ksz9477_convert_alu()
666 alu->port_forward = alu_table[1] & ALU_V_PORT_MAP; in ksz9477_convert_alu()
668 alu->fid = (alu_table[2] >> ALU_V_FID_S) & ALU_V_FID_M; in ksz9477_convert_alu()
670 alu->mac[0] = (alu_table[2] >> 8) & 0xFF; in ksz9477_convert_alu()
671 alu->mac[1] = alu_table[2] & 0xFF; in ksz9477_convert_alu()
672 alu->mac[2] = (alu_table[3] >> 24) & 0xFF; in ksz9477_convert_alu()
673 alu->mac[3] = (alu_table[3] >> 16) & 0xFF; in ksz9477_convert_alu()
674 alu->mac[4] = (alu_table[3] >> 8) & 0xFF; in ksz9477_convert_alu()
675 alu->mac[5] = alu_table[3] & 0xFF; in ksz9477_convert_alu()
685 int timeout; in ksz9477_fdb_dump() local
687 mutex_lock(&dev->alu_mutex); in ksz9477_fdb_dump()
693 timeout = 1000; in ksz9477_fdb_dump()
699 } while (timeout-- > 0); in ksz9477_fdb_dump()
701 if (!timeout) { in ksz9477_fdb_dump()
702 dev_dbg(dev->dev, "Failed to search ALU\n"); in ksz9477_fdb_dump()
703 ret = -ETIMEDOUT; in ksz9477_fdb_dump()
727 mutex_unlock(&dev->alu_mutex); in ksz9477_fdb_dump()
743 shifts = dev->info->shifts; in ksz9477_mdb_add()
744 masks = dev->info->masks; in ksz9477_mdb_add()
746 mac_hi = ((mdb->addr[0] << 8) | mdb->addr[1]); in ksz9477_mdb_add()
747 mac_lo = ((mdb->addr[2] << 24) | (mdb->addr[3] << 16)); in ksz9477_mdb_add()
748 mac_lo |= ((mdb->addr[4] << 8) | mdb->addr[5]); in ksz9477_mdb_add()
750 mutex_lock(&dev->alu_mutex); in ksz9477_mdb_add()
752 for (index = 0; index < dev->info->num_statics; index++) { in ksz9477_mdb_add()
761 dev_dbg(dev->dev, "Failed to read ALU STATIC\n"); in ksz9477_mdb_add()
770 if (((static_table[2] >> ALU_V_FID_S) == mdb->vid) && in ksz9477_mdb_add()
783 if (index == dev->info->num_statics) { in ksz9477_mdb_add()
784 err = -ENOSPC; in ksz9477_mdb_add()
791 if (mdb->vid) in ksz9477_mdb_add()
793 static_table[2] = (mdb->vid << ALU_V_FID_S); in ksz9477_mdb_add()
804 dev_dbg(dev->dev, "Failed to read ALU STATIC\n"); in ksz9477_mdb_add()
807 mutex_unlock(&dev->alu_mutex); in ksz9477_mdb_add()
822 shifts = dev->info->shifts; in ksz9477_mdb_del()
823 masks = dev->info->masks; in ksz9477_mdb_del()
825 mac_hi = ((mdb->addr[0] << 8) | mdb->addr[1]); in ksz9477_mdb_del()
826 mac_lo = ((mdb->addr[2] << 24) | (mdb->addr[3] << 16)); in ksz9477_mdb_del()
827 mac_lo |= ((mdb->addr[4] << 8) | mdb->addr[5]); in ksz9477_mdb_del()
829 mutex_lock(&dev->alu_mutex); in ksz9477_mdb_del()
831 for (index = 0; index < dev->info->num_statics; index++) { in ksz9477_mdb_del()
840 dev_dbg(dev->dev, "Failed to read ALU STATIC\n"); in ksz9477_mdb_del()
850 if (((static_table[2] >> ALU_V_FID_S) == mdb->vid) && in ksz9477_mdb_del()
860 if (index == dev->info->num_statics) in ksz9477_mdb_del()
882 dev_dbg(dev->dev, "Failed to read ALU STATIC\n"); in ksz9477_mdb_del()
885 mutex_unlock(&dev->alu_mutex); in ksz9477_mdb_del()
901 for (p = 0; p < dev->info->port_cnt; p++) { in ksz9477_port_mirror_add()
903 if (p == mirror->to_local_port) in ksz9477_port_mirror_add()
911 return -EBUSY; in ksz9477_port_mirror_add()
921 ksz_port_cfg(dev, mirror->to_local_port, P_MIRROR_CTRL, in ksz9477_port_mirror_add()
936 if (mirror->ingress) in ksz9477_port_mirror_del()
943 for (p = 0; p < dev->info->port_cnt; p++) { in ksz9477_port_mirror_del()
954 ksz_port_cfg(dev, mirror->to_local_port, P_MIRROR_CTRL, in ksz9477_port_mirror_del()
963 if (dev->info->internal_phy[port]) in ksz9477_get_interface()
976 config->mac_capabilities = MAC_10 | MAC_100 | MAC_ASYM_PAUSE | in ksz9477_get_caps()
979 if (dev->info->gbit_capable[port]) in ksz9477_get_caps()
980 config->mac_capabilities |= MAC_1000FD; in ksz9477_get_caps()
985 u32 secs = msecs / 1000; in ksz9477_set_ageing_time() local
990 #define MAX_TIMER_VAL ((1 << 8) - 1) in ksz9477_set_ageing_time()
992 /* The aging timer comprises a 3-bit multiplier and an 8-bit second in ksz9477_set_ageing_time()
996 if (!secs) in ksz9477_set_ageing_time()
997 secs = 1; in ksz9477_set_ageing_time()
1000 else if (secs > 7 * MAX_TIMER_VAL) in ksz9477_set_ageing_time()
1001 return -EINVAL; in ksz9477_set_ageing_time()
1015 max_val = DIV_ROUND_UP(secs, mult); in ksz9477_set_ageing_time()
1016 if (max_val > MAX_TIMER_VAL || max_val * mult != secs) in ksz9477_set_ageing_time()
1020 data = DIV_ROUND_UP(secs, max_val); in ksz9477_set_ageing_time()
1029 value = DIV_ROUND_UP(secs, data); in ksz9477_set_ageing_time()
1037 if (dev->info->num_tx_queues == 8) in ksz9477_port_queue_split()
1039 else if (dev->info->num_tx_queues == 4) in ksz9477_port_queue_split()
1041 else if (dev->info->num_tx_queues == 2) in ksz9477_port_queue_split()
1051 const u16 *regs = dev->info->regs; in ksz9477_port_setup()
1052 struct dsa_switch *ds = dev->ds; in ksz9477_port_setup()
1077 /* force flow control for non-PHY ports only */ in ksz9477_port_setup()
1080 !dev->info->internal_phy[port]); in ksz9477_port_setup()
1090 if (dev->info->internal_phy[port]) in ksz9477_port_setup()
1106 struct ksz_device *dev = ds->priv; in ksz9477_config_cpu_port()
1110 for (i = 0; i < dev->info->port_cnt; i++) { in ksz9477_config_cpu_port()
1112 (dev->info->cpu_ports & (1 << i))) { in ksz9477_config_cpu_port()
1117 dev->cpu_port = i; in ksz9477_config_cpu_port()
1118 p = &dev->ports[i]; in ksz9477_config_cpu_port()
1125 if (!p->interface) { in ksz9477_config_cpu_port()
1126 if (dev->compat_interface) { in ksz9477_config_cpu_port()
1127 dev_warn(dev->dev, in ksz9477_config_cpu_port()
1128 "Using legacy switch \"phy-mode\" property, because it is missing on port %d node. " in ksz9477_config_cpu_port()
1131 p->interface = dev->compat_interface; in ksz9477_config_cpu_port()
1133 p->interface = interface; in ksz9477_config_cpu_port()
1136 if (interface && interface != p->interface) { in ksz9477_config_cpu_port()
1143 dev_info(dev->dev, in ksz9477_config_cpu_port()
1146 phy_modes(p->interface), in ksz9477_config_cpu_port()
1155 for (i = 0; i < dev->info->port_cnt; i++) { in ksz9477_config_cpu_port()
1156 if (i == dev->cpu_port) in ksz9477_config_cpu_port()
1161 if (dsa_is_unused_port(ds, i) && dev->info->internal_phy[i]) in ksz9477_config_cpu_port()
1172 masks = dev->info->masks; in ksz9477_enable_stp_addr()
1179 ALU_V_OVERRIDE | BIT(dev->cpu_port)); in ksz9477_enable_stp_addr()
1192 dev_err(dev->dev, "Failed to update Reserved Multicast table\n"); in ksz9477_enable_stp_addr()
1201 struct ksz_device *dev = ds->priv; in ksz9477_setup()
1202 const u16 *regs = dev->info->regs; in ksz9477_setup()
1205 ds->mtu_enforcement_ingress = true; in ksz9477_setup()
1257 * 3. PREVENTING PACKET LOOP IN THE RING BY SELF-ADDRESS FILTERING
1261 * Ones from point 2 and 3 are "best effort" - i.e. those will
1263 * frames will not be caught - to be more specific; there is a race
1278 struct ksz_device *dev = ds->priv; in ksz9477_hsr_join()
1287 if (dev->hsr_ports) { in ksz9477_hsr_join()
1289 hsr_ports |= BIT(hsr_dp->index); in ksz9477_hsr_join()
1293 ksz9477_cfg_port_member(dev, hsr_dp->index, hsr_ports); in ksz9477_hsr_join()
1296 if (!dev->hsr_ports) { in ksz9477_hsr_join()
1304 /* Enable per port self-address filtering. in ksz9477_hsr_join()
1305 * The global self-address filtering has already been enabled in the in ksz9477_hsr_join()
1311 user = dsa_to_port(ds, port)->user; in ksz9477_hsr_join()
1312 user->features |= KSZ9477_SUPPORTED_HSR_FEATURES; in ksz9477_hsr_join()
1317 struct ksz_device *dev = ds->priv; in ksz9477_hsr_leave()
1325 /* Disable per port self-address filtering */ in ksz9477_hsr_leave()
1334 dev->port_mask = (1 << dev->info->port_cnt) - 1; in ksz9477_switch_init()