/* Matches for all upstream-facing ports (the CPU port and all upstream-facing *DSAlinks)thatsitbetweenthetargetedportonwhichthenotifierwas *emittedanditsdedicatedCPUport.
*/ staticbool dsa_port_host_address_match(struct dsa_port *dp, conststruct dsa_port *targeted_dp)
{ struct dsa_port *cpu_dp = targeted_dp->cpu_dp;
if (dsa_switch_is_upstream_of(dp->ds, targeted_dp->ds)) return dp->index == dsa_towards_port(dp->ds, cpu_dp->ds->index,
cpu_dp->index);
list_for_each_entry(a, addr_list, list) if (ether_addr_equal(a->addr, addr) && a->vid == vid &&
dsa_db_equal(&a->db, &db)) return a;
return NULL;
}
staticint dsa_port_do_mdb_add(struct dsa_port *dp, conststruct switchdev_obj_port_mdb *mdb, struct dsa_db db)
{ struct dsa_switch *ds = dp->ds; struct dsa_mac_addr *a; int port = dp->index; int err = 0;
/* No need to bother with refcounting for user ports */ if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))) {
err = ds->ops->port_mdb_add(ds, port, mdb, db);
trace_dsa_mdb_add_hw(dp, mdb->addr, mdb->vid, &db, err);
return err;
}
mutex_lock(&dp->addr_lists_lock);
a = dsa_mac_addr_find(&dp->mdbs, mdb->addr, mdb->vid, db); if (a) {
refcount_inc(&a->refcount);
trace_dsa_mdb_add_bump(dp, mdb->addr, mdb->vid, &db,
&a->refcount); goto out;
}
a = kzalloc(sizeof(*a), GFP_KERNEL); if (!a) {
err = -ENOMEM; goto out;
}
staticint dsa_port_do_mdb_del(struct dsa_port *dp, conststruct switchdev_obj_port_mdb *mdb, struct dsa_db db)
{ struct dsa_switch *ds = dp->ds; struct dsa_mac_addr *a; int port = dp->index; int err = 0;
/* No need to bother with refcounting for user ports */ if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))) {
err = ds->ops->port_mdb_del(ds, port, mdb, db);
trace_dsa_mdb_del_hw(dp, mdb->addr, mdb->vid, &db, err);
return err;
}
mutex_lock(&dp->addr_lists_lock);
a = dsa_mac_addr_find(&dp->mdbs, mdb->addr, mdb->vid, db); if (!a) {
trace_dsa_mdb_del_not_found(dp, mdb->addr, mdb->vid, &db);
err = -ENOENT; goto out;
}
staticint dsa_port_do_fdb_add(struct dsa_port *dp, constunsignedchar *addr,
u16 vid, struct dsa_db db)
{ struct dsa_switch *ds = dp->ds; struct dsa_mac_addr *a; int port = dp->index; int err = 0;
/* No need to bother with refcounting for user ports */ if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))) {
err = ds->ops->port_fdb_add(ds, port, addr, vid, db);
trace_dsa_fdb_add_hw(dp, addr, vid, &db, err);
return err;
}
mutex_lock(&dp->addr_lists_lock);
a = dsa_mac_addr_find(&dp->fdbs, addr, vid, db); if (a) {
refcount_inc(&a->refcount);
trace_dsa_fdb_add_bump(dp, addr, vid, &db, &a->refcount); goto out;
}
a = kzalloc(sizeof(*a), GFP_KERNEL); if (!a) {
err = -ENOMEM; goto out;
}
staticint dsa_port_do_fdb_del(struct dsa_port *dp, constunsignedchar *addr,
u16 vid, struct dsa_db db)
{ struct dsa_switch *ds = dp->ds; struct dsa_mac_addr *a; int port = dp->index; int err = 0;
/* No need to bother with refcounting for user ports */ if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))) {
err = ds->ops->port_fdb_del(ds, port, addr, vid, db);
trace_dsa_fdb_del_hw(dp, addr, vid, &db, err);
return err;
}
mutex_lock(&dp->addr_lists_lock);
a = dsa_mac_addr_find(&dp->fdbs, addr, vid, db); if (!a) {
trace_dsa_fdb_del_not_found(dp, addr, vid, &db);
err = -ENOENT; goto out;
}
/* Notify switch only if it has a port in this LAG */
dsa_switch_for_each_port(dp, ds) if (dsa_port_offloads_lag(dp, info->lag)) return dsa_switch_do_lag_fdb_add(ds, info->lag,
info->addr, info->vid,
info->db);
/* Notify switch only if it has a port in this LAG */
dsa_switch_for_each_port(dp, ds) if (dsa_port_offloads_lag(dp, info->lag)) return dsa_switch_do_lag_fdb_del(ds, info->lag,
info->addr, info->vid,
info->db);
dsa_switch_for_each_port(dp, ds) { if (dsa_port_host_address_match(dp, info->dp)) {
err = dsa_port_do_mdb_del(dp, info->mdb, info->db); if (err) break;
}
}
return err;
}
/* Port VLANs match on the targeted port and on all DSA ports */ staticbool dsa_port_vlan_match(struct dsa_port *dp, struct dsa_notifier_vlan_info *info)
{ return dsa_port_is_dsa(dp) || dp == info->dp;
}
/* Host VLANs match on the targeted port's CPU port, and on all DSA ports *(upstreamanddownstream)ofthatswitchanditsupstreamswitches.
*/ staticbool dsa_port_host_vlan_match(struct dsa_port *dp, conststruct dsa_port *targeted_dp)
{ struct dsa_port *cpu_dp = targeted_dp->cpu_dp;
if (dsa_switch_is_upstream_of(dp->ds, targeted_dp->ds)) return dsa_port_is_dsa(dp) || dp == cpu_dp;
list_for_each_entry(v, vlan_list, list) if (v->vid == vlan->vid) return v;
return NULL;
}
staticint dsa_port_do_vlan_add(struct dsa_port *dp, conststruct switchdev_obj_port_vlan *vlan, struct netlink_ext_ack *extack)
{ struct dsa_switch *ds = dp->ds; int port = dp->index; struct dsa_vlan *v; int err = 0;
/* No need to bother with refcounting for user ports. */ if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))) {
err = ds->ops->port_vlan_add(ds, port, vlan, extack);
trace_dsa_vlan_add_hw(dp, vlan, err);
return err;
}
/* No need to propagate on shared ports the existing VLANs that were *re-notifiedafterjusttheflagshavechanged.Thiswouldcausea *refcountbumpwhichweneedtoavoid,sinceitunbalancesthe *additionswiththedeletions.
*/ if (vlan->changed) return0;
mutex_lock(&dp->vlans_lock);
v = dsa_vlan_find(&dp->vlans, vlan); if (v) {
refcount_inc(&v->refcount);
trace_dsa_vlan_add_bump(dp, vlan, &v->refcount); goto out;
}
v = kzalloc(sizeof(*v), GFP_KERNEL); if (!v) {
err = -ENOMEM; goto out;
}
staticint dsa_port_do_vlan_del(struct dsa_port *dp, conststruct switchdev_obj_port_vlan *vlan)
{ struct dsa_switch *ds = dp->ds; int port = dp->index; struct dsa_vlan *v; int err = 0;
/* No need to bother with refcounting for user ports */ if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))) {
err = ds->ops->port_vlan_del(ds, port, vlan);
trace_dsa_vlan_del_hw(dp, vlan, err);
return err;
}
mutex_lock(&dp->vlans_lock);
v = dsa_vlan_find(&dp->vlans, vlan); if (!v) {
trace_dsa_vlan_del_not_found(dp, vlan);
err = -ENOENT; goto out;
}
if (!refcount_dec_and_test(&v->refcount)) {
trace_dsa_vlan_del_drop(dp, vlan, &v->refcount); goto out;
}
/* Now that changing the tag protocol can no longer fail, let's update *theremainingbitswhichare"duplicatedforfasteraccess",andthe *bitsthatdependonthetagger,suchastheMTU.
*/
dsa_switch_for_each_user_port(dp, ds) { struct net_device *user = dp->user;
dsa_user_setup_tagger(user);
/* rtnl_mutex is held in dsa_tree_change_tag_proto */
dsa_user_change_mtu(user, user->mtu);
}
return0;
}
/* We use the same cross-chip notifiers to inform both the tagger side, as well *astheswitchside,ofconnectionanddisconnectionevents. *Sinceds->tagger_dataisownedbythetagger,itisn'taharderrorifthe *switchsidedoesn'tsupportconnectingtothistagger,andtherefore,the *factthatwedon'tdisconnectthetaggersidedoesn'tconstituteamemory *leak:thetaggerwillstilloperatewithpersistentper-switchmemory,just *withtheswitchsideunconnectedtoit.Whatdoesconstituteaharderroris *whentheswitchsidesupportsconnectingbutfails.
*/ staticint
dsa_switch_connect_tag_proto(struct dsa_switch *ds, struct dsa_notifier_tag_proto_info *info)
{ conststruct dsa_device_ops *tag_ops = info->tag_ops; int err;
/* Notify the new tagger about the connection to this switch */ if (tag_ops->connect) {
err = tag_ops->connect(ds); if (err) return err;
}
if (!ds->ops->connect_tag_protocol) return -EOPNOTSUPP;
/* Notify the switch about the connection to the new tagger */
err = ds->ops->connect_tag_protocol(ds, tag_ops->proto); if (err) { /* Revert the new tagger's connection to this tree */ if (tag_ops->disconnect)
tag_ops->disconnect(ds); return err;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.