Skip to content

Commit 3563606

Browse files
scottfeldmandavem330
authored andcommitted
switchdev: convert STP update to switchdev attr set
STP update is just a settable port attribute, so convert switchdev_port_stp_update to an attr set. For DSA, the prepare phase is skipped and STP updates are only done in the commit phase. This is because currently the DSA drivers don't need to allocate any memory for STP updates and the STP update will not fail to HW (unless something horrible goes wrong on the MDIO bus, in which case the prepare phase wouldn't have been able to predict anyway). Signed-off-by: Scott Feldman <sfeldma@gmail.com> Acked-by: Jiri Pirko <jiri@resnulli.us> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c4f2032 commit 3563606

File tree

5 files changed

+31
-50
lines changed

5 files changed

+31
-50
lines changed

drivers/net/ethernet/rocker/rocker.c

+5-9
Original file line numberDiff line numberDiff line change
@@ -4395,14 +4395,6 @@ static int rocker_port_attr_get(struct net_device *dev,
43954395
return 0;
43964396
}
43974397

4398-
static int rocker_port_switchdev_port_stp_update(struct net_device *dev,
4399-
u8 state)
4400-
{
4401-
struct rocker_port *rocker_port = netdev_priv(dev);
4402-
4403-
return rocker_port_stp_update(rocker_port, SWITCHDEV_TRANS_NONE, state);
4404-
}
4405-
44064398
static void rocker_port_trans_abort(struct rocker_port *rocker_port)
44074399
{
44084400
struct list_head *mem, *tmp;
@@ -4431,6 +4423,10 @@ static int rocker_port_attr_set(struct net_device *dev,
44314423
}
44324424

44334425
switch (attr->id) {
4426+
case SWITCHDEV_ATTR_PORT_STP_STATE:
4427+
err = rocker_port_stp_update(rocker_port, attr->trans,
4428+
attr->stp_state);
4429+
break;
44344430
default:
44354431
err = -EOPNOTSUPP;
44364432
break;
@@ -4466,7 +4462,7 @@ static int rocker_port_switchdev_fib_ipv4_del(struct net_device *dev,
44664462

44674463
static const struct switchdev_ops rocker_port_switchdev_ops = {
44684464
.switchdev_port_attr_get = rocker_port_attr_get,
4469-
.switchdev_port_stp_update = rocker_port_switchdev_port_stp_update,
4465+
.switchdev_port_attr_set = rocker_port_attr_set,
44704466
.switchdev_fib_ipv4_add = rocker_port_switchdev_fib_ipv4_add,
44714467
.switchdev_fib_ipv4_del = rocker_port_switchdev_fib_ipv4_del,
44724468
};

include/net/switchdev.h

+2-11
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ enum switchdev_trans {
2626
enum switchdev_attr_id {
2727
SWITCHDEV_ATTR_UNDEFINED,
2828
SWITCHDEV_ATTR_PORT_PARENT_ID,
29+
SWITCHDEV_ATTR_PORT_STP_STATE,
2930
};
3031

3132
struct switchdev_attr {
@@ -34,6 +35,7 @@ struct switchdev_attr {
3435
u32 flags;
3536
union {
3637
struct netdev_phys_item_id ppid; /* PORT_PARENT_ID */
38+
u8 stp_state; /* PORT_STP_STATE */
3739
};
3840
};
3941

@@ -46,9 +48,6 @@ struct fib_info;
4648
*
4749
* @switchdev_port_attr_set: Set a port attribute (see switchdev_attr).
4850
*
49-
* @switchdev_port_stp_update: Called to notify switch device port of bridge
50-
* port STP state change.
51-
*
5251
* @switchdev_fib_ipv4_add: Called to add/modify IPv4 route to switch device.
5352
*
5453
* @switchdev_fib_ipv4_del: Called to delete IPv4 route from switch device.
@@ -58,7 +57,6 @@ struct switchdev_ops {
5857
struct switchdev_attr *attr);
5958
int (*switchdev_port_attr_set)(struct net_device *dev,
6059
struct switchdev_attr *attr);
61-
int (*switchdev_port_stp_update)(struct net_device *dev, u8 state);
6260
int (*switchdev_fib_ipv4_add)(struct net_device *dev, __be32 dst,
6361
int dst_len, struct fib_info *fi,
6462
u8 tos, u8 type, u32 nlflags,
@@ -95,7 +93,6 @@ int switchdev_port_attr_get(struct net_device *dev,
9593
struct switchdev_attr *attr);
9694
int switchdev_port_attr_set(struct net_device *dev,
9795
struct switchdev_attr *attr);
98-
int switchdev_port_stp_update(struct net_device *dev, u8 state);
9996
int register_switchdev_notifier(struct notifier_block *nb);
10097
int unregister_switchdev_notifier(struct notifier_block *nb);
10198
int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
@@ -128,12 +125,6 @@ static inline int switchdev_port_attr_set(struct net_device *dev,
128125
return -EOPNOTSUPP;
129126
}
130127

131-
static inline int switchdev_port_stp_update(struct net_device *dev,
132-
u8 state)
133-
{
134-
return -EOPNOTSUPP;
135-
}
136-
137128
static inline int register_switchdev_notifier(struct notifier_block *nb)
138129
{
139130
return 0;

net/bridge/br_stp.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,14 @@ void br_log_state(const struct net_bridge_port *p)
3939

4040
void br_set_state(struct net_bridge_port *p, unsigned int state)
4141
{
42+
struct switchdev_attr attr = {
43+
.id = SWITCHDEV_ATTR_PORT_STP_STATE,
44+
.stp_state = state,
45+
};
4246
int err;
4347

4448
p->state = state;
45-
err = switchdev_port_stp_update(p->dev, state);
49+
err = switchdev_port_attr_set(p->dev, &attr);
4650
if (err && err != -EOPNOTSUPP)
4751
br_warn(p->br, "error setting offload STP state on port %u(%s)\n",
4852
(unsigned int) p->port_no, p->dev->name);

net/dsa/slave.c

+19-1
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,24 @@ static int dsa_slave_stp_update(struct net_device *dev, u8 state)
345345
return ret;
346346
}
347347

348+
static int dsa_slave_port_attr_set(struct net_device *dev,
349+
struct switchdev_attr *attr)
350+
{
351+
int ret = 0;
352+
353+
switch (attr->id) {
354+
case SWITCHDEV_ATTR_PORT_STP_STATE:
355+
if (attr->trans == SWITCHDEV_TRANS_COMMIT)
356+
ret = dsa_slave_stp_update(dev, attr->stp_state);
357+
break;
358+
default:
359+
ret = -EOPNOTSUPP;
360+
break;
361+
}
362+
363+
return ret;
364+
}
365+
348366
static int dsa_slave_bridge_port_join(struct net_device *dev,
349367
struct net_device *br)
350368
{
@@ -683,7 +701,7 @@ static const struct net_device_ops dsa_slave_netdev_ops = {
683701

684702
static const struct switchdev_ops dsa_slave_switchdev_ops = {
685703
.switchdev_port_attr_get = dsa_slave_port_attr_get,
686-
.switchdev_port_stp_update = dsa_slave_stp_update,
704+
.switchdev_port_attr_set = dsa_slave_port_attr_set,
687705
};
688706

689707
static void dsa_slave_adjust_link(struct net_device *dev)

net/switchdev/switchdev.c

-28
Original file line numberDiff line numberDiff line change
@@ -187,34 +187,6 @@ int switchdev_port_attr_set(struct net_device *dev, struct switchdev_attr *attr)
187187
}
188188
EXPORT_SYMBOL_GPL(switchdev_port_attr_set);
189189

190-
/**
191-
* switchdev_port_stp_update - Notify switch device port of STP
192-
* state change
193-
* @dev: port device
194-
* @state: port STP state
195-
*
196-
* Notify switch device port of bridge port STP state change.
197-
*/
198-
int switchdev_port_stp_update(struct net_device *dev, u8 state)
199-
{
200-
const struct switchdev_ops *ops = dev->switchdev_ops;
201-
struct net_device *lower_dev;
202-
struct list_head *iter;
203-
int err = -EOPNOTSUPP;
204-
205-
if (ops && ops->switchdev_port_stp_update)
206-
return ops->switchdev_port_stp_update(dev, state);
207-
208-
netdev_for_each_lower_dev(dev, lower_dev, iter) {
209-
err = switchdev_port_stp_update(lower_dev, state);
210-
if (err && err != -EOPNOTSUPP)
211-
return err;
212-
}
213-
214-
return err;
215-
}
216-
EXPORT_SYMBOL_GPL(switchdev_port_stp_update);
217-
218190
static DEFINE_MUTEX(switchdev_mutex);
219191
static RAW_NOTIFIER_HEAD(switchdev_notif_chain);
220192

0 commit comments

Comments
 (0)