Lines Matching +full:in +full:- +full:masks
1 // SPDX-License-Identifier: GPL-2.0
16 #include <linux/platform_data/microchip-ksz.h>
31 regmap_update_bits(dev->regmap[0], addr, bits, set ? bits : 0); in ksz_cfg()
37 regmap_update_bits(dev->regmap[0], PORT_CTRL_ADDR(port, offset), in ksz_port_cfg()
47 regs = dev->info->regs; in ksz8_ind_write8()
49 mutex_lock(&dev->alu_mutex); in ksz8_ind_write8()
56 mutex_unlock(&dev->alu_mutex); in ksz8_ind_write8()
114 const u32 *masks; in ksz8_r_mib_cnt() local
121 masks = dev->info->masks; in ksz8_r_mib_cnt()
122 regs = dev->info->regs; in ksz8_r_mib_cnt()
124 ctrl_addr = addr + dev->info->reg_mib_cnt * port; in ksz8_r_mib_cnt()
127 mutex_lock(&dev->alu_mutex); in ksz8_r_mib_cnt()
133 for (loop = 2; loop > 0; loop--) { in ksz8_r_mib_cnt()
136 if (check & masks[MIB_COUNTER_VALID]) { in ksz8_r_mib_cnt()
138 if (check & masks[MIB_COUNTER_OVERFLOW]) in ksz8_r_mib_cnt()
144 mutex_unlock(&dev->alu_mutex); in ksz8_r_mib_cnt()
150 const u32 *masks; in ksz8795_r_mib_pkt() local
157 masks = dev->info->masks; in ksz8795_r_mib_pkt()
158 regs = dev->info->regs; in ksz8795_r_mib_pkt()
160 addr -= dev->info->reg_mib_cnt; in ksz8795_r_mib_pkt()
161 ctrl_addr = (KSZ8795_MIB_TOTAL_RX_1 - KSZ8795_MIB_TOTAL_RX_0) * port; in ksz8795_r_mib_pkt()
165 mutex_lock(&dev->alu_mutex); in ksz8795_r_mib_pkt()
171 for (loop = 2; loop > 0; loop--) { in ksz8795_r_mib_pkt()
174 if (check & masks[MIB_COUNTER_VALID]) { in ksz8795_r_mib_pkt()
183 if (check & masks[MIB_COUNTER_OVERFLOW]) { in ksz8795_r_mib_pkt()
189 if (check & masks[MIB_COUNTER_OVERFLOW]) in ksz8795_r_mib_pkt()
196 mutex_unlock(&dev->alu_mutex); in ksz8795_r_mib_pkt()
208 regs = dev->info->regs; in ksz8863_r_mib_pkt()
210 addr -= dev->info->reg_mib_cnt; in ksz8863_r_mib_pkt()
216 mutex_lock(&dev->alu_mutex); in ksz8863_r_mib_pkt()
219 mutex_unlock(&dev->alu_mutex); in ksz8863_r_mib_pkt()
227 data -= cur; in ksz8863_r_mib_pkt()
258 struct ksz_port_mib *mib = &dev->ports[port].mib; in ksz8_port_init_cnt()
268 mib->cnt_ptr = 0; in ksz8_port_init_cnt()
271 while (mib->cnt_ptr < dev->info->reg_mib_cnt) { in ksz8_port_init_cnt()
272 dev->dev_ops->r_mib_cnt(dev, port, mib->cnt_ptr, in ksz8_port_init_cnt()
273 &mib->counters[mib->cnt_ptr]); in ksz8_port_init_cnt()
274 ++mib->cnt_ptr; in ksz8_port_init_cnt()
277 /* last one in storage */ in ksz8_port_init_cnt()
278 dropped = &mib->counters[dev->info->mib_cnt]; in ksz8_port_init_cnt()
281 while (mib->cnt_ptr < dev->info->mib_cnt) { in ksz8_port_init_cnt()
282 dev->dev_ops->r_mib_pkt(dev, port, mib->cnt_ptr, in ksz8_port_init_cnt()
283 dropped, &mib->counters[mib->cnt_ptr]); in ksz8_port_init_cnt()
284 ++mib->cnt_ptr; in ksz8_port_init_cnt()
293 regs = dev->info->regs; in ksz8_r_table()
297 mutex_lock(&dev->alu_mutex); in ksz8_r_table()
300 mutex_unlock(&dev->alu_mutex); in ksz8_r_table()
308 regs = dev->info->regs; in ksz8_w_table()
312 mutex_lock(&dev->alu_mutex); in ksz8_w_table()
315 mutex_unlock(&dev->alu_mutex); in ksz8_w_table()
321 const u32 *masks; in ksz8_valid_dyn_entry() local
324 masks = dev->info->masks; in ksz8_valid_dyn_entry()
325 regs = dev->info->regs; in ksz8_valid_dyn_entry()
329 timeout--; in ksz8_valid_dyn_entry()
330 } while ((*data & masks[DYNAMIC_MAC_TABLE_NOT_READY]) && timeout); in ksz8_valid_dyn_entry()
333 if (*data & masks[DYNAMIC_MAC_TABLE_NOT_READY]) { in ksz8_valid_dyn_entry()
334 return -EAGAIN; in ksz8_valid_dyn_entry()
339 /* There is no valid entry in the table. */ in ksz8_valid_dyn_entry()
340 if (*data & masks[DYNAMIC_MAC_TABLE_MAC_EMPTY]) in ksz8_valid_dyn_entry()
341 return -ENXIO; in ksz8_valid_dyn_entry()
351 const u32 *masks; in ksz8_r_dyn_mac_table() local
357 shifts = dev->info->shifts; in ksz8_r_dyn_mac_table()
358 masks = dev->info->masks; in ksz8_r_dyn_mac_table()
359 regs = dev->info->regs; in ksz8_r_dyn_mac_table()
363 mutex_lock(&dev->alu_mutex); in ksz8_r_dyn_mac_table()
367 if (rc == -EAGAIN) { in ksz8_r_dyn_mac_table()
370 } else if (rc == -ENXIO) { in ksz8_r_dyn_mac_table()
372 /* At least one valid entry in the table. */ in ksz8_r_dyn_mac_table()
381 /* Check out how many valid entry in the table. */ in ksz8_r_dyn_mac_table()
382 cnt = data & masks[DYNAMIC_MAC_TABLE_ENTRIES_H]; in ksz8_r_dyn_mac_table()
384 cnt |= (data_hi & masks[DYNAMIC_MAC_TABLE_ENTRIES]) >> in ksz8_r_dyn_mac_table()
388 *fid = (data_hi & masks[DYNAMIC_MAC_TABLE_FID]) >> in ksz8_r_dyn_mac_table()
390 *src_port = (data_hi & masks[DYNAMIC_MAC_TABLE_SRC_PORT]) >> in ksz8_r_dyn_mac_table()
392 *timestamp = (data_hi & masks[DYNAMIC_MAC_TABLE_TIMESTAMP]) >> in ksz8_r_dyn_mac_table()
404 mutex_unlock(&dev->alu_mutex); in ksz8_r_dyn_mac_table()
414 const u32 *masks; in ksz8_r_sta_mac_table() local
417 shifts = dev->info->shifts; in ksz8_r_sta_mac_table()
418 masks = dev->info->masks; in ksz8_r_sta_mac_table()
423 if (data_hi & (masks[STATIC_MAC_TABLE_VALID] | in ksz8_r_sta_mac_table()
424 masks[STATIC_MAC_TABLE_OVERRIDE])) { in ksz8_r_sta_mac_table()
425 alu->mac[5] = (u8)data_lo; in ksz8_r_sta_mac_table()
426 alu->mac[4] = (u8)(data_lo >> 8); in ksz8_r_sta_mac_table()
427 alu->mac[3] = (u8)(data_lo >> 16); in ksz8_r_sta_mac_table()
428 alu->mac[2] = (u8)(data_lo >> 24); in ksz8_r_sta_mac_table()
429 alu->mac[1] = (u8)data_hi; in ksz8_r_sta_mac_table()
430 alu->mac[0] = (u8)(data_hi >> 8); in ksz8_r_sta_mac_table()
431 alu->port_forward = in ksz8_r_sta_mac_table()
432 (data_hi & masks[STATIC_MAC_TABLE_FWD_PORTS]) >> in ksz8_r_sta_mac_table()
434 alu->is_override = in ksz8_r_sta_mac_table()
435 (data_hi & masks[STATIC_MAC_TABLE_OVERRIDE]) ? 1 : 0; in ksz8_r_sta_mac_table()
437 alu->is_static = true; in ksz8_r_sta_mac_table()
438 alu->is_use_fid = in ksz8_r_sta_mac_table()
439 (data_hi & masks[STATIC_MAC_TABLE_USE_FID]) ? 1 : 0; in ksz8_r_sta_mac_table()
440 alu->fid = (data_hi & masks[STATIC_MAC_TABLE_FID]) >> in ksz8_r_sta_mac_table()
444 return -ENXIO; in ksz8_r_sta_mac_table()
452 const u32 *masks; in ksz8_w_sta_mac_table() local
455 shifts = dev->info->shifts; in ksz8_w_sta_mac_table()
456 masks = dev->info->masks; in ksz8_w_sta_mac_table()
458 data_lo = ((u32)alu->mac[2] << 24) | in ksz8_w_sta_mac_table()
459 ((u32)alu->mac[3] << 16) | in ksz8_w_sta_mac_table()
460 ((u32)alu->mac[4] << 8) | alu->mac[5]; in ksz8_w_sta_mac_table()
461 data_hi = ((u32)alu->mac[0] << 8) | alu->mac[1]; in ksz8_w_sta_mac_table()
462 data_hi |= (u32)alu->port_forward << shifts[STATIC_MAC_FWD_PORTS]; in ksz8_w_sta_mac_table()
464 if (alu->is_override) in ksz8_w_sta_mac_table()
465 data_hi |= masks[STATIC_MAC_TABLE_OVERRIDE]; in ksz8_w_sta_mac_table()
466 if (alu->is_use_fid) { in ksz8_w_sta_mac_table()
467 data_hi |= masks[STATIC_MAC_TABLE_USE_FID]; in ksz8_w_sta_mac_table()
468 data_hi |= (u32)alu->fid << shifts[STATIC_MAC_FID]; in ksz8_w_sta_mac_table()
470 if (alu->is_static) in ksz8_w_sta_mac_table()
471 data_hi |= masks[STATIC_MAC_TABLE_VALID]; in ksz8_w_sta_mac_table()
473 data_hi &= ~masks[STATIC_MAC_TABLE_OVERRIDE]; in ksz8_w_sta_mac_table()
483 const u32 *masks; in ksz8_from_vlan() local
485 shifts = dev->info->shifts; in ksz8_from_vlan()
486 masks = dev->info->masks; in ksz8_from_vlan()
488 *fid = vlan & masks[VLAN_TABLE_FID]; in ksz8_from_vlan()
489 *member = (vlan & masks[VLAN_TABLE_MEMBERSHIP]) >> in ksz8_from_vlan()
491 *valid = !!(vlan & masks[VLAN_TABLE_VALID]); in ksz8_from_vlan()
498 const u32 *masks; in ksz8_to_vlan() local
500 shifts = dev->info->shifts; in ksz8_to_vlan()
501 masks = dev->info->masks; in ksz8_to_vlan()
506 *vlan |= masks[VLAN_TABLE_VALID]; in ksz8_to_vlan()
515 shifts = dev->info->shifts; in ksz8_r_vlan_entries()
520 dev->vlan_cache[addr + i].table[0] = (u16)data; in ksz8_r_vlan_entries()
551 dev->vlan_cache[vid].table[0] = vlan; in ksz8_w_vlan_table()
565 regs = dev->info->regs; in ksz8_r_phy()
716 regs = dev->info->regs; in ksz8_w_phy()
756 /* Fiber port does not support auto-negotiation. */ in ksz8_w_phy()
757 if (dev->ports[p].fiber) in ksz8_w_phy()
862 data |= (member & dev->port_mask); in ksz8_cfg_port_member()
873 regs = dev->info->regs; in ksz8_flush_dyn_mac_table()
875 if ((uint)port < dev->info->port_cnt) { in ksz8_flush_dyn_mac_table()
881 cnt = dev->info->port_cnt; in ksz8_flush_dyn_mac_table()
884 p = &dev->ports[index]; in ksz8_flush_dyn_mac_table()
885 if (!p->on) in ksz8_flush_dyn_mac_table()
894 p = &dev->ports[index]; in ksz8_flush_dyn_mac_table()
895 if (!p->on) in ksz8_flush_dyn_mac_table()
938 for (index = 0; index < dev->info->num_statics; index++) { in ksz8_mdb_add()
940 /* Found one already in static MAC table. */ in ksz8_mdb_add()
941 if (!memcmp(alu.mac, mdb->addr, ETH_ALEN) && in ksz8_mdb_add()
942 alu.fid == mdb->vid) in ksz8_mdb_add()
951 if (index == dev->info->num_statics && !empty) in ksz8_mdb_add()
952 return -ENOSPC; in ksz8_mdb_add()
955 if (index == dev->info->num_statics) { in ksz8_mdb_add()
956 index = empty - 1; in ksz8_mdb_add()
958 memcpy(alu.mac, mdb->addr, ETH_ALEN); in ksz8_mdb_add()
962 if (mdb->vid) { in ksz8_mdb_add()
966 alu.fid = mdb->vid; in ksz8_mdb_add()
979 for (index = 0; index < dev->info->num_statics; index++) { in ksz8_mdb_del()
981 /* Found one already in static MAC table. */ in ksz8_mdb_del()
982 if (!memcmp(alu.mac, mdb->addr, ETH_ALEN) && in ksz8_mdb_del()
983 alu.fid == mdb->vid) in ksz8_mdb_del()
989 if (index == dev->info->num_statics) in ksz8_mdb_del()
1006 return -ENOTSUPP; in ksz8_port_vlan_filtering()
1012 for (port = 0; port < dev->phy_port_cnt; ++port) in ksz8_port_vlan_filtering()
1023 0x03 << (4 - 2 * port), state); in ksz8_port_enable_pvid()
1033 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; in ksz8_port_vlan_add()
1034 struct ksz_port *p = &dev->ports[port]; in ksz8_port_vlan_add()
1039 return -ENOTSUPP; in ksz8_port_vlan_add()
1046 if (untagged != p->remove_tag && vlan->vid != 0 && in ksz8_port_vlan_add()
1047 port != dev->cpu_port) { in ksz8_port_vlan_add()
1054 for (vid = 1; vid < dev->info->num_vlans; ++vid) { in ksz8_port_vlan_add()
1056 if (vid == vlan->vid) in ksz8_port_vlan_add()
1059 ksz8_from_vlan(dev, dev->vlan_cache[vid].table[0], in ksz8_port_vlan_add()
1062 return -EINVAL; in ksz8_port_vlan_add()
1066 p->remove_tag = untagged; in ksz8_port_vlan_add()
1069 ksz8_r_vlan_table(dev, vlan->vid, &data); in ksz8_port_vlan_add()
1081 ksz8_w_vlan_table(dev, vlan->vid, data); in ksz8_port_vlan_add()
1084 if (vlan->flags & BRIDGE_VLAN_INFO_PVID) in ksz8_port_vlan_add()
1085 new_pvid = vlan->vid; in ksz8_port_vlan_add()
1108 return -ENOTSUPP; in ksz8_port_vlan_del()
1113 ksz8_r_vlan_table(dev, vlan->vid, &data); in ksz8_port_vlan_del()
1125 ksz8_w_vlan_table(dev, vlan->vid, data); in ksz8_port_vlan_del()
1127 if (pvid == vlan->vid) in ksz8_port_vlan_del()
1139 dev->mirror_rx |= BIT(port); in ksz8_port_mirror_add()
1142 dev->mirror_tx |= BIT(port); in ksz8_port_mirror_add()
1148 if (dev->mirror_rx || dev->mirror_tx) in ksz8_port_mirror_add()
1149 ksz_port_cfg(dev, mirror->to_local_port, P_MIRROR_CTRL, in ksz8_port_mirror_add()
1160 if (mirror->ingress) { in ksz8_port_mirror_del()
1162 dev->mirror_rx &= ~BIT(port); in ksz8_port_mirror_del()
1165 dev->mirror_tx &= ~BIT(port); in ksz8_port_mirror_del()
1170 if (!dev->mirror_rx && !dev->mirror_tx) in ksz8_port_mirror_del()
1171 ksz_port_cfg(dev, mirror->to_local_port, P_MIRROR_CTRL, in ksz8_port_mirror_del()
1177 struct ksz_port *p = &dev->ports[port]; in ksz8795_cpu_interface_select()
1179 if (!p->interface && dev->compat_interface) { in ksz8795_cpu_interface_select()
1180 dev_warn(dev->dev, in ksz8795_cpu_interface_select()
1181 "Using legacy switch \"phy-mode\" property, because it is missing on port %d node. " in ksz8795_cpu_interface_select()
1184 p->interface = dev->compat_interface; in ksz8795_cpu_interface_select()
1190 struct dsa_switch *ds = dev->ds; in ksz8_port_setup()
1191 const u32 *masks; in ksz8_port_setup() local
1194 masks = dev->info->masks; in ksz8_port_setup()
1207 masks[PORT_802_1P_REMAPPING], false); in ksz8_port_setup()
1226 struct ksz_device *dev = ds->priv; in ksz8_config_cpu_port()
1228 const u32 *masks; in ksz8_config_cpu_port() local
1233 masks = dev->info->masks; in ksz8_config_cpu_port()
1234 regs = dev->info->regs; in ksz8_config_cpu_port()
1238 ksz_cfg(dev, regs[S_TAIL_TAG_CTRL], masks[SW_TAIL_TAG_ENABLE], true); in ksz8_config_cpu_port()
1240 p = &dev->ports[dev->cpu_port]; in ksz8_config_cpu_port()
1241 p->on = 1; in ksz8_config_cpu_port()
1243 ksz8_port_setup(dev, dev->cpu_port, true); in ksz8_config_cpu_port()
1245 for (i = 0; i < dev->phy_port_cnt; i++) { in ksz8_config_cpu_port()
1246 p = &dev->ports[i]; in ksz8_config_cpu_port()
1251 if (i == dev->phy_port_cnt) in ksz8_config_cpu_port()
1253 p->on = 1; in ksz8_config_cpu_port()
1255 for (i = 0; i < dev->phy_port_cnt; i++) { in ksz8_config_cpu_port()
1256 p = &dev->ports[i]; in ksz8_config_cpu_port()
1257 if (!p->on) in ksz8_config_cpu_port()
1262 p->fiber = 1; in ksz8_config_cpu_port()
1264 if (p->fiber) in ksz8_config_cpu_port()
1275 struct ksz_device *dev = ds->priv; in ksz8_handle_global_errata()
1281 * KSZ879x/KSZ877x/KSZ876x and some EEE link partners may result in in ksz8_handle_global_errata()
1284 if (dev->info->ksz87xx_eee_link_erratum) in ksz8_handle_global_errata()
1299 alu.port_forward = dev->info->cpu_ports; in ksz8_enable_stp_addr()
1308 struct ksz_device *dev = ds->priv; in ksz8_setup()
1316 /* Enable aggressive back off algorithm in half duplex mode. */ in ksz8_setup()
1317 regmap_update_bits(dev->regmap[0], REG_SW_CTRL_1, in ksz8_setup()
1324 regmap_update_bits(dev->regmap[0], REG_SW_CTRL_2, in ksz8_setup()
1335 for (i = 0; i < (dev->info->num_vlans / 4); i++) in ksz8_setup()
1344 config->mac_capabilities = MAC_10 | MAC_100; in ksz8_get_caps()
1352 config->mac_capabilities |= MAC_SYM_PAUSE; in ksz8_get_caps()
1356 config->mac_capabilities |= MAC_ASYM_PAUSE; in ksz8_get_caps()
1366 dev->cpu_port = fls(dev->info->cpu_ports) - 1; in ksz8_switch_init()
1367 dev->phy_port_cnt = dev->info->port_cnt - 1; in ksz8_switch_init()
1368 dev->port_mask = (BIT(dev->phy_port_cnt) - 1) | dev->info->cpu_ports; in ksz8_switch_init()
1373 dev->ds->untag_bridge_pvid = true; in ksz8_switch_init()
1378 dev->ds->vlan_filtering_is_global = true; in ksz8_switch_init()