Commit d66e4348 authored by Petr Machata's avatar Petr Machata Committed by David S. Miller

net: bridge: Extract boilerplate around switchdev_port_obj_*()

A call to switchdev_port_obj_add() or switchdev_port_obj_del() involves
initializing a struct switchdev_obj_port_vlan, a piece of code that
repeats on each call site almost verbatim. While in the current codebase
there is just one duplicated add call, the follow-up patches add more of
both add and del calls.

Thus to remove the duplication, extract the repetition into named
functions and reuse.
Signed-off-by: default avatarPetr Machata <petrm@mellanox.com>
Reviewed-by: default avatarVivien Didelot <vivien.didelot@savoirfairelinux.com>
Reviewed-by: default avatarNikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 32d26a68
...@@ -1139,6 +1139,8 @@ int br_switchdev_set_port_flag(struct net_bridge_port *p, ...@@ -1139,6 +1139,8 @@ int br_switchdev_set_port_flag(struct net_bridge_port *p,
unsigned long mask); unsigned long mask);
void br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb, void br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb,
int type); int type);
int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags);
int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid);
static inline void br_switchdev_frame_unmark(struct sk_buff *skb) static inline void br_switchdev_frame_unmark(struct sk_buff *skb)
{ {
...@@ -1168,6 +1170,17 @@ static inline int br_switchdev_set_port_flag(struct net_bridge_port *p, ...@@ -1168,6 +1170,17 @@ static inline int br_switchdev_set_port_flag(struct net_bridge_port *p,
return 0; return 0;
} }
static inline int br_switchdev_port_vlan_add(struct net_device *dev,
u16 vid, u16 flags)
{
return -EOPNOTSUPP;
}
static inline int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid)
{
return -EOPNOTSUPP;
}
static inline void static inline void
br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb, int type) br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb, int type)
{ {
......
...@@ -136,3 +136,28 @@ br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb, int type) ...@@ -136,3 +136,28 @@ br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb, int type)
break; break;
} }
} }
int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags)
{
struct switchdev_obj_port_vlan v = {
.obj.orig_dev = dev,
.obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
.flags = flags,
.vid_begin = vid,
.vid_end = vid,
};
return switchdev_port_obj_add(dev, &v.obj);
}
int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid)
{
struct switchdev_obj_port_vlan v = {
.obj.orig_dev = dev,
.obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
.vid_begin = vid,
.vid_end = vid,
};
return switchdev_port_obj_del(dev, &v.obj);
}
...@@ -82,19 +82,12 @@ static bool __vlan_add_flags(struct net_bridge_vlan *v, u16 flags) ...@@ -82,19 +82,12 @@ static bool __vlan_add_flags(struct net_bridge_vlan *v, u16 flags)
static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br, static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br,
u16 vid, u16 flags) u16 vid, u16 flags)
{ {
struct switchdev_obj_port_vlan v = {
.obj.orig_dev = dev,
.obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
.flags = flags,
.vid_begin = vid,
.vid_end = vid,
};
int err; int err;
/* Try switchdev op first. In case it is not supported, fallback to /* Try switchdev op first. In case it is not supported, fallback to
* 8021q add. * 8021q add.
*/ */
err = switchdev_port_obj_add(dev, &v.obj); err = br_switchdev_port_vlan_add(dev, vid, flags);
if (err == -EOPNOTSUPP) if (err == -EOPNOTSUPP)
return vlan_vid_add(dev, br->vlan_proto, vid); return vlan_vid_add(dev, br->vlan_proto, vid);
return err; return err;
...@@ -130,18 +123,12 @@ static void __vlan_del_list(struct net_bridge_vlan *v) ...@@ -130,18 +123,12 @@ static void __vlan_del_list(struct net_bridge_vlan *v)
static int __vlan_vid_del(struct net_device *dev, struct net_bridge *br, static int __vlan_vid_del(struct net_device *dev, struct net_bridge *br,
u16 vid) u16 vid)
{ {
struct switchdev_obj_port_vlan v = {
.obj.orig_dev = dev,
.obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
.vid_begin = vid,
.vid_end = vid,
};
int err; int err;
/* Try switchdev op first. In case it is not supported, fallback to /* Try switchdev op first. In case it is not supported, fallback to
* 8021q del. * 8021q del.
*/ */
err = switchdev_port_obj_del(dev, &v.obj); err = br_switchdev_port_vlan_del(dev, vid);
if (err == -EOPNOTSUPP) { if (err == -EOPNOTSUPP) {
vlan_vid_del(dev, br->vlan_proto, vid); vlan_vid_del(dev, br->vlan_proto, vid);
return 0; return 0;
...@@ -1053,13 +1040,6 @@ int nbp_vlan_init(struct net_bridge_port *p) ...@@ -1053,13 +1040,6 @@ int nbp_vlan_init(struct net_bridge_port *p)
int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags, int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
bool *changed) bool *changed)
{ {
struct switchdev_obj_port_vlan v = {
.obj.orig_dev = port->dev,
.obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
.flags = flags,
.vid_begin = vid,
.vid_end = vid,
};
struct net_bridge_vlan *vlan; struct net_bridge_vlan *vlan;
int ret; int ret;
...@@ -1069,7 +1049,7 @@ int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags, ...@@ -1069,7 +1049,7 @@ int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
vlan = br_vlan_find(nbp_vlan_group(port), vid); vlan = br_vlan_find(nbp_vlan_group(port), vid);
if (vlan) { if (vlan) {
/* Pass the flags to the hardware bridge */ /* Pass the flags to the hardware bridge */
ret = switchdev_port_obj_add(port->dev, &v.obj); ret = br_switchdev_port_vlan_add(port->dev, vid, flags);
if (ret && ret != -EOPNOTSUPP) if (ret && ret != -EOPNOTSUPP)
return ret; return ret;
*changed = __vlan_add_flags(vlan, flags); *changed = __vlan_add_flags(vlan, flags);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment