• Home
  • Raw
  • Download

Lines Matching +full:fiber +full:- +full:mode

1 // SPDX-License-Identifier: GPL-2.0
14 #include <linux/platform_data/microchip-ksz.h>
67 regmap_update_bits(dev->regmap[0], addr, bits, set ? bits : 0); in ksz_cfg()
73 regmap_update_bits(dev->regmap[0], PORT_CTRL_ADDR(port, offset), in ksz_port_cfg()
131 mutex_lock(&dev->alu_mutex); in ksz8795_r_mib_cnt()
137 for (loop = 2; loop > 0; loop--) { in ksz8795_r_mib_cnt()
148 mutex_unlock(&dev->alu_mutex); in ksz8795_r_mib_cnt()
159 addr -= SWITCH_COUNTER_NUM; in ksz8795_r_mib_pkt()
160 ctrl_addr = (KS_MIB_TOTAL_RX_1 - KS_MIB_TOTAL_RX_0) * port; in ksz8795_r_mib_pkt()
164 mutex_lock(&dev->alu_mutex); in ksz8795_r_mib_pkt()
170 for (loop = 2; loop > 0; loop--) { in ksz8795_r_mib_pkt()
195 mutex_unlock(&dev->alu_mutex); in ksz8795_r_mib_pkt()
212 struct ksz_port_mib *mib = &dev->ports[port].mib; in ksz8795_port_init_cnt()
219 mib->cnt_ptr = 0; in ksz8795_port_init_cnt()
222 while (mib->cnt_ptr < dev->reg_mib_cnt) { in ksz8795_port_init_cnt()
223 dev->dev_ops->r_mib_cnt(dev, port, mib->cnt_ptr, in ksz8795_port_init_cnt()
224 &mib->counters[mib->cnt_ptr]); in ksz8795_port_init_cnt()
225 ++mib->cnt_ptr; in ksz8795_port_init_cnt()
229 while (mib->cnt_ptr < dev->mib_cnt) { in ksz8795_port_init_cnt()
230 dev->dev_ops->r_mib_pkt(dev, port, mib->cnt_ptr, in ksz8795_port_init_cnt()
231 NULL, &mib->counters[mib->cnt_ptr]); in ksz8795_port_init_cnt()
232 ++mib->cnt_ptr; in ksz8795_port_init_cnt()
234 mib->cnt_ptr = 0; in ksz8795_port_init_cnt()
235 memset(mib->counters, 0, dev->mib_cnt * sizeof(u64)); in ksz8795_port_init_cnt()
245 mutex_lock(&dev->alu_mutex); in ksz8795_r_table()
248 mutex_unlock(&dev->alu_mutex); in ksz8795_r_table()
258 mutex_lock(&dev->alu_mutex); in ksz8795_w_table()
261 mutex_unlock(&dev->alu_mutex); in ksz8795_w_table()
270 timeout--; in ksz8795_valid_dyn_entry()
275 return -EAGAIN; in ksz8795_valid_dyn_entry()
282 return -ENXIO; in ksz8795_valid_dyn_entry()
298 mutex_lock(&dev->alu_mutex); in ksz8795_r_dyn_mac_table()
302 if (rc == -EAGAIN) { in ksz8795_r_dyn_mac_table()
305 } else if (rc == -ENXIO) { in ksz8795_r_dyn_mac_table()
339 mutex_unlock(&dev->alu_mutex); in ksz8795_r_dyn_mac_table()
354 alu->mac[5] = (u8)data_lo; in ksz8795_r_sta_mac_table()
355 alu->mac[4] = (u8)(data_lo >> 8); in ksz8795_r_sta_mac_table()
356 alu->mac[3] = (u8)(data_lo >> 16); in ksz8795_r_sta_mac_table()
357 alu->mac[2] = (u8)(data_lo >> 24); in ksz8795_r_sta_mac_table()
358 alu->mac[1] = (u8)data_hi; in ksz8795_r_sta_mac_table()
359 alu->mac[0] = (u8)(data_hi >> 8); in ksz8795_r_sta_mac_table()
360 alu->port_forward = (data_hi & STATIC_MAC_TABLE_FWD_PORTS) >> in ksz8795_r_sta_mac_table()
362 alu->is_override = in ksz8795_r_sta_mac_table()
365 alu->is_use_fid = (data_hi & STATIC_MAC_TABLE_USE_FID) ? 1 : 0; in ksz8795_r_sta_mac_table()
366 alu->fid = (data_hi & STATIC_MAC_TABLE_FID) >> in ksz8795_r_sta_mac_table()
370 return -ENXIO; in ksz8795_r_sta_mac_table()
379 data_lo = ((u32)alu->mac[2] << 24) | in ksz8795_w_sta_mac_table()
380 ((u32)alu->mac[3] << 16) | in ksz8795_w_sta_mac_table()
381 ((u32)alu->mac[4] << 8) | alu->mac[5]; in ksz8795_w_sta_mac_table()
382 data_hi = ((u32)alu->mac[0] << 8) | alu->mac[1]; in ksz8795_w_sta_mac_table()
383 data_hi |= (u32)alu->port_forward << STATIC_MAC_FWD_PORTS_S; in ksz8795_w_sta_mac_table()
385 if (alu->is_override) in ksz8795_w_sta_mac_table()
387 if (alu->is_use_fid) { in ksz8795_w_sta_mac_table()
389 data_hi |= (u32)alu->fid << STATIC_MAC_FID_S; in ksz8795_w_sta_mac_table()
391 if (alu->is_static) in ksz8795_w_sta_mac_table()
423 dev->vlan_cache[addr + i].table[0] = (u16)data; in ksz8795_r_vlan_entries()
454 dev->vlan_cache[vid].table[0] = vlan; in ksz8795_w_vlan_table()
575 /* Fiber port does not support auto-negotiation. */ in ksz8795_w_phy()
576 if (dev->ports[p].fiber) in ksz8795_w_phy()
672 data |= (member & dev->port_mask); in ksz8795_cfg_port_member()
674 dev->ports[port].member = member; in ksz8795_cfg_port_member()
680 struct ksz_device *dev = ds->priv; in ksz8795_port_stp_state_set()
681 int forward = dev->member; in ksz8795_port_stp_state_set()
683 int member = -1; in ksz8795_port_stp_state_set()
686 p = &dev->ports[port]; in ksz8795_port_stp_state_set()
700 p->stp_state == BR_STATE_DISABLED) in ksz8795_port_stp_state_set()
701 member = dev->host_mask | p->vid_member; in ksz8795_port_stp_state_set()
710 if (port == dev->cpu_port) in ksz8795_port_stp_state_set()
714 if (dev->br_member & BIT(port)) { in ksz8795_port_stp_state_set()
715 dev->member |= BIT(port); in ksz8795_port_stp_state_set()
716 member = dev->member; in ksz8795_port_stp_state_set()
718 member = dev->host_mask | p->vid_member; in ksz8795_port_stp_state_set()
724 p->stp_state == BR_STATE_DISABLED) in ksz8795_port_stp_state_set()
725 member = dev->host_mask | p->vid_member; in ksz8795_port_stp_state_set()
728 dev_err(ds->dev, "invalid STP state: %d\n", state); in ksz8795_port_stp_state_set()
733 p->stp_state = state; in ksz8795_port_stp_state_set()
735 if (member >= 0 && member != p->member) in ksz8795_port_stp_state_set()
740 if (dev->br_member & BIT(port)) in ksz8795_port_stp_state_set()
741 dev->member &= ~BIT(port); in ksz8795_port_stp_state_set()
747 if (forward != dev->member) in ksz8795_port_stp_state_set()
763 cnt = dev->mib_port_cnt; in ksz8795_flush_dyn_mac_table()
766 p = &dev->ports[index]; in ksz8795_flush_dyn_mac_table()
767 if (!p->on) in ksz8795_flush_dyn_mac_table()
776 p = &dev->ports[index]; in ksz8795_flush_dyn_mac_table()
777 if (!p->on) in ksz8795_flush_dyn_mac_table()
788 struct ksz_device *dev = ds->priv; in ksz8795_port_vlan_filtering()
797 for (port = 0; port < dev->phy_port_cnt; ++port) in ksz8795_port_vlan_filtering()
808 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; in ksz8795_port_vlan_changes_remove_tag()
809 struct ksz_device *dev = ds->priv; in ksz8795_port_vlan_changes_remove_tag()
810 struct ksz_port *p = &dev->ports[port]; in ksz8795_port_vlan_changes_remove_tag()
817 return untagged != p->remove_tag && in ksz8795_port_vlan_changes_remove_tag()
818 !(vlan->vid_begin == 0 && vlan->vid_end == 0) && in ksz8795_port_vlan_changes_remove_tag()
819 port != dev->cpu_port; in ksz8795_port_vlan_changes_remove_tag()
825 struct ksz_device *dev = ds->priv; in ksz8795_port_vlan_prepare()
834 for (vid = 1; vid < dev->num_vlans; ++vid) { in ksz8795_port_vlan_prepare()
838 if (vid == vlan->vid_begin) { in ksz8795_port_vlan_prepare()
839 vid = vlan->vid_end; in ksz8795_port_vlan_prepare()
843 ksz8795_from_vlan(dev->vlan_cache[vid].table[0], in ksz8795_port_vlan_prepare()
846 return -EINVAL; in ksz8795_port_vlan_prepare()
856 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; in ksz8795_port_vlan_add()
857 struct ksz_device *dev = ds->priv; in ksz8795_port_vlan_add()
858 struct ksz_port *p = &dev->ports[port]; in ksz8795_port_vlan_add()
864 p->remove_tag = untagged; in ksz8795_port_vlan_add()
867 for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) { in ksz8795_port_vlan_add()
883 if (vlan->flags & BRIDGE_VLAN_INFO_PVID) in ksz8795_port_vlan_add()
900 struct ksz_device *dev = ds->priv; in ksz8795_port_vlan_del()
908 for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) { in ksz8795_port_vlan_del()
937 struct ksz_device *dev = ds->priv; in ksz8795_port_mirror_add()
941 dev->mirror_rx |= BIT(port); in ksz8795_port_mirror_add()
944 dev->mirror_tx |= BIT(port); in ksz8795_port_mirror_add()
950 if (dev->mirror_rx || dev->mirror_tx) in ksz8795_port_mirror_add()
951 ksz_port_cfg(dev, mirror->to_local_port, P_MIRROR_CTRL, in ksz8795_port_mirror_add()
960 struct ksz_device *dev = ds->priv; in ksz8795_port_mirror_del()
963 if (mirror->ingress) { in ksz8795_port_mirror_del()
965 dev->mirror_rx &= ~BIT(port); in ksz8795_port_mirror_del()
968 dev->mirror_tx &= ~BIT(port); in ksz8795_port_mirror_del()
973 if (!dev->mirror_rx && !dev->mirror_tx) in ksz8795_port_mirror_del()
974 ksz_port_cfg(dev, mirror->to_local_port, P_MIRROR_CTRL, in ksz8795_port_mirror_del()
980 struct ksz_port *p = &dev->ports[port]; in ksz8795_port_setup()
998 if (!p->interface && dev->compat_interface) { in ksz8795_port_setup()
999 dev_warn(dev->dev, in ksz8795_port_setup()
1000 "Using legacy switch \"phy-mode\" property, because it is missing on port %d node. " in ksz8795_port_setup()
1003 p->interface = dev->compat_interface; in ksz8795_port_setup()
1010 switch (p->interface) { in ksz8795_port_setup()
1012 p->phydev.speed = SPEED_100; in ksz8795_port_setup()
1016 p->phydev.speed = SPEED_100; in ksz8795_port_setup()
1021 p->phydev.speed = SPEED_1000; in ksz8795_port_setup()
1026 if (p->interface == PHY_INTERFACE_MODE_RGMII_ID || in ksz8795_port_setup()
1027 p->interface == PHY_INTERFACE_MODE_RGMII_RXID) in ksz8795_port_setup()
1029 if (p->interface == PHY_INTERFACE_MODE_RGMII_ID || in ksz8795_port_setup()
1030 p->interface == PHY_INTERFACE_MODE_RGMII_TXID) in ksz8795_port_setup()
1034 p->phydev.speed = SPEED_1000; in ksz8795_port_setup()
1038 p->phydev.duplex = 1; in ksz8795_port_setup()
1040 member = dev->port_mask; in ksz8795_port_setup()
1042 member = dev->host_mask | p->vid_member; in ksz8795_port_setup()
1049 struct ksz_device *dev = ds->priv; in ksz8795_config_cpu_port()
1054 ds->num_ports = dev->port_cnt + 1; in ksz8795_config_cpu_port()
1060 p = &dev->ports[dev->cpu_port]; in ksz8795_config_cpu_port()
1061 p->vid_member = dev->port_mask; in ksz8795_config_cpu_port()
1062 p->on = 1; in ksz8795_config_cpu_port()
1064 ksz8795_port_setup(dev, dev->cpu_port, true); in ksz8795_config_cpu_port()
1065 dev->member = dev->host_mask; in ksz8795_config_cpu_port()
1068 p = &dev->ports[i]; in ksz8795_config_cpu_port()
1070 /* Initialize to non-zero so that ksz_cfg_port_member() will in ksz8795_config_cpu_port()
1073 p->vid_member = BIT(i); in ksz8795_config_cpu_port()
1074 p->member = dev->port_mask; in ksz8795_config_cpu_port()
1078 if (i == dev->port_cnt) in ksz8795_config_cpu_port()
1080 p->on = 1; in ksz8795_config_cpu_port()
1081 p->phy = 1; in ksz8795_config_cpu_port()
1083 for (i = 0; i < dev->phy_port_cnt; i++) { in ksz8795_config_cpu_port()
1084 p = &dev->ports[i]; in ksz8795_config_cpu_port()
1085 if (!p->on) in ksz8795_config_cpu_port()
1089 p->fiber = 1; in ksz8795_config_cpu_port()
1090 if (p->fiber) in ksz8795_config_cpu_port()
1101 struct ksz_device *dev = ds->priv; in ksz8795_setup()
1105 dev->vlan_cache = devm_kcalloc(dev->dev, sizeof(struct vlan_table), in ksz8795_setup()
1106 dev->num_vlans, GFP_KERNEL); in ksz8795_setup()
1107 if (!dev->vlan_cache) in ksz8795_setup()
1108 return -ENOMEM; in ksz8795_setup()
1112 dev_err(ds->dev, "failed to reset switch\n"); in ksz8795_setup()
1121 /* Enable aggressive back off algorithm in half duplex mode. */ in ksz8795_setup()
1122 regmap_update_bits(dev->regmap[0], REG_SW_CTRL_1, in ksz8795_setup()
1129 regmap_update_bits(dev->regmap[0], REG_SW_CTRL_2, in ksz8795_setup()
1144 regmap_update_bits(dev->regmap[1], S_REPLACE_VID_CTRL, in ksz8795_setup()
1157 alu.port_forward = dev->host_mask; in ksz8795_setup()
1212 return -ENODEV; in ksz8795_switch_detect()
1214 dev->mib_port_cnt = TOTAL_PORT_NUM; in ksz8795_switch_detect()
1215 dev->phy_port_cnt = SWITCH_PORT_NUM; in ksz8795_switch_detect()
1216 dev->port_cnt = SWITCH_PORT_NUM; in ksz8795_switch_detect()
1226 dev->port_cnt--; in ksz8795_switch_detect()
1227 dev->last_port = dev->port_cnt; in ksz8795_switch_detect()
1232 dev->chip_id = id16; in ksz8795_switch_detect()
1234 dev->cpu_port = dev->mib_port_cnt - 1; in ksz8795_switch_detect()
1235 dev->host_mask = BIT(dev->cpu_port); in ksz8795_switch_detect()
1284 dev->ds->ops = &ksz8795_switch_ops; in ksz8795_switch_init()
1289 if (dev->chip_id == chip->chip_id) { in ksz8795_switch_init()
1290 dev->name = chip->dev_name; in ksz8795_switch_init()
1291 dev->num_vlans = chip->num_vlans; in ksz8795_switch_init()
1292 dev->num_alus = chip->num_alus; in ksz8795_switch_init()
1293 dev->num_statics = chip->num_statics; in ksz8795_switch_init()
1294 dev->port_cnt = chip->port_cnt; in ksz8795_switch_init()
1295 dev->cpu_ports = chip->cpu_ports; in ksz8795_switch_init()
1302 if (!dev->cpu_ports) in ksz8795_switch_init()
1303 return -ENODEV; in ksz8795_switch_init()
1305 dev->port_mask = BIT(dev->port_cnt) - 1; in ksz8795_switch_init()
1306 dev->port_mask |= dev->host_mask; in ksz8795_switch_init()
1308 dev->reg_mib_cnt = SWITCH_COUNTER_NUM; in ksz8795_switch_init()
1309 dev->mib_cnt = TOTAL_SWITCH_COUNTER_NUM; in ksz8795_switch_init()
1311 i = dev->mib_port_cnt; in ksz8795_switch_init()
1312 dev->ports = devm_kzalloc(dev->dev, sizeof(struct ksz_port) * i, in ksz8795_switch_init()
1314 if (!dev->ports) in ksz8795_switch_init()
1315 return -ENOMEM; in ksz8795_switch_init()
1316 for (i = 0; i < dev->mib_port_cnt; i++) { in ksz8795_switch_init()
1317 mutex_init(&dev->ports[i].mib.cnt_mutex); in ksz8795_switch_init()
1318 dev->ports[i].mib.counters = in ksz8795_switch_init()
1319 devm_kzalloc(dev->dev, in ksz8795_switch_init()
1323 if (!dev->ports[i].mib.counters) in ksz8795_switch_init()
1324 return -ENOMEM; in ksz8795_switch_init()
1328 dev->ds->num_ports = dev->port_cnt + 1; in ksz8795_switch_init()
1333 dev->ds->untag_bridge_pvid = true; in ksz8795_switch_init()
1338 dev->ds->vlan_filtering_is_global = true; in ksz8795_switch_init()