switchdev: move transaction phase enum under transaction structure
Before it disappears completely, move transaction phase enum under transaction structure and make attr/obj structures a bit cleaner. Signed-off-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
7ea6eb3f56
commit
f8db83486e
|
@ -4389,7 +4389,7 @@ static int rocker_port_attr_set(struct net_device *dev,
|
||||||
struct rocker_port *rocker_port = netdev_priv(dev);
|
struct rocker_port *rocker_port = netdev_priv(dev);
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
switch (attr->trans_ph) {
|
switch (trans->ph) {
|
||||||
case SWITCHDEV_TRANS_PREPARE:
|
case SWITCHDEV_TRANS_PREPARE:
|
||||||
BUG_ON(!list_empty(&rocker_port->trans_mem));
|
BUG_ON(!list_empty(&rocker_port->trans_mem));
|
||||||
break;
|
break;
|
||||||
|
@ -4402,12 +4402,12 @@ static int rocker_port_attr_set(struct net_device *dev,
|
||||||
|
|
||||||
switch (attr->id) {
|
switch (attr->id) {
|
||||||
case SWITCHDEV_ATTR_PORT_STP_STATE:
|
case SWITCHDEV_ATTR_PORT_STP_STATE:
|
||||||
err = rocker_port_stp_update(rocker_port, attr->trans_ph,
|
err = rocker_port_stp_update(rocker_port, trans->ph,
|
||||||
ROCKER_OP_FLAG_NOWAIT,
|
ROCKER_OP_FLAG_NOWAIT,
|
||||||
attr->u.stp_state);
|
attr->u.stp_state);
|
||||||
break;
|
break;
|
||||||
case SWITCHDEV_ATTR_PORT_BRIDGE_FLAGS:
|
case SWITCHDEV_ATTR_PORT_BRIDGE_FLAGS:
|
||||||
err = rocker_port_brport_flags_set(rocker_port, attr->trans_ph,
|
err = rocker_port_brport_flags_set(rocker_port, trans->ph,
|
||||||
attr->u.brport_flags);
|
attr->u.brport_flags);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -4475,7 +4475,7 @@ static int rocker_port_obj_add(struct net_device *dev,
|
||||||
const struct switchdev_obj_ipv4_fib *fib4;
|
const struct switchdev_obj_ipv4_fib *fib4;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
switch (obj->trans_ph) {
|
switch (trans->ph) {
|
||||||
case SWITCHDEV_TRANS_PREPARE:
|
case SWITCHDEV_TRANS_PREPARE:
|
||||||
BUG_ON(!list_empty(&rocker_port->trans_mem));
|
BUG_ON(!list_empty(&rocker_port->trans_mem));
|
||||||
break;
|
break;
|
||||||
|
@ -4488,17 +4488,17 @@ static int rocker_port_obj_add(struct net_device *dev,
|
||||||
|
|
||||||
switch (obj->id) {
|
switch (obj->id) {
|
||||||
case SWITCHDEV_OBJ_PORT_VLAN:
|
case SWITCHDEV_OBJ_PORT_VLAN:
|
||||||
err = rocker_port_vlans_add(rocker_port, obj->trans_ph,
|
err = rocker_port_vlans_add(rocker_port, trans->ph,
|
||||||
&obj->u.vlan);
|
&obj->u.vlan);
|
||||||
break;
|
break;
|
||||||
case SWITCHDEV_OBJ_IPV4_FIB:
|
case SWITCHDEV_OBJ_IPV4_FIB:
|
||||||
fib4 = &obj->u.ipv4_fib;
|
fib4 = &obj->u.ipv4_fib;
|
||||||
err = rocker_port_fib_ipv4(rocker_port, obj->trans_ph,
|
err = rocker_port_fib_ipv4(rocker_port, trans->ph,
|
||||||
htonl(fib4->dst), fib4->dst_len,
|
htonl(fib4->dst), fib4->dst_len,
|
||||||
fib4->fi, fib4->tb_id, 0);
|
fib4->fi, fib4->tb_id, 0);
|
||||||
break;
|
break;
|
||||||
case SWITCHDEV_OBJ_PORT_FDB:
|
case SWITCHDEV_OBJ_PORT_FDB:
|
||||||
err = rocker_port_fdb_add(rocker_port, obj->trans_ph, &obj->u.fdb);
|
err = rocker_port_fdb_add(rocker_port, trans->ph, &obj->u.fdb);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
err = -EOPNOTSUPP;
|
err = -EOPNOTSUPP;
|
||||||
|
@ -4569,7 +4569,8 @@ static int rocker_port_obj_del(struct net_device *dev,
|
||||||
ROCKER_OP_FLAG_REMOVE);
|
ROCKER_OP_FLAG_REMOVE);
|
||||||
break;
|
break;
|
||||||
case SWITCHDEV_OBJ_PORT_FDB:
|
case SWITCHDEV_OBJ_PORT_FDB:
|
||||||
err = rocker_port_fdb_del(rocker_port, obj->trans_ph, &obj->u.fdb);
|
err = rocker_port_fdb_del(rocker_port, SWITCHDEV_TRANS_NONE,
|
||||||
|
&obj->u.fdb);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
err = -EOPNOTSUPP;
|
err = -EOPNOTSUPP;
|
||||||
|
|
|
@ -32,6 +32,7 @@ struct switchdev_trans_item {
|
||||||
|
|
||||||
struct switchdev_trans {
|
struct switchdev_trans {
|
||||||
struct list_head item_list;
|
struct list_head item_list;
|
||||||
|
enum switchdev_trans_ph ph;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum switchdev_attr_id {
|
enum switchdev_attr_id {
|
||||||
|
@ -43,7 +44,6 @@ enum switchdev_attr_id {
|
||||||
|
|
||||||
struct switchdev_attr {
|
struct switchdev_attr {
|
||||||
enum switchdev_attr_id id;
|
enum switchdev_attr_id id;
|
||||||
enum switchdev_trans_ph trans_ph;
|
|
||||||
u32 flags;
|
u32 flags;
|
||||||
union {
|
union {
|
||||||
struct netdev_phys_item_id ppid; /* PORT_PARENT_ID */
|
struct netdev_phys_item_id ppid; /* PORT_PARENT_ID */
|
||||||
|
@ -63,7 +63,6 @@ enum switchdev_obj_id {
|
||||||
|
|
||||||
struct switchdev_obj {
|
struct switchdev_obj {
|
||||||
enum switchdev_obj_id id;
|
enum switchdev_obj_id id;
|
||||||
enum switchdev_trans_ph trans_ph;
|
|
||||||
int (*cb)(struct net_device *dev, struct switchdev_obj *obj);
|
int (*cb)(struct net_device *dev, struct switchdev_obj *obj);
|
||||||
union {
|
union {
|
||||||
struct switchdev_obj_vlan { /* PORT_VLAN */
|
struct switchdev_obj_vlan { /* PORT_VLAN */
|
||||||
|
|
|
@ -242,7 +242,8 @@ static int dsa_bridge_check_vlan_range(struct dsa_switch *ds,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dsa_slave_port_vlan_add(struct net_device *dev,
|
static int dsa_slave_port_vlan_add(struct net_device *dev,
|
||||||
struct switchdev_obj *obj)
|
struct switchdev_obj *obj,
|
||||||
|
struct switchdev_trans *trans)
|
||||||
{
|
{
|
||||||
struct switchdev_obj_vlan *vlan = &obj->u.vlan;
|
struct switchdev_obj_vlan *vlan = &obj->u.vlan;
|
||||||
struct dsa_slave_priv *p = netdev_priv(dev);
|
struct dsa_slave_priv *p = netdev_priv(dev);
|
||||||
|
@ -250,7 +251,7 @@ static int dsa_slave_port_vlan_add(struct net_device *dev,
|
||||||
u16 vid;
|
u16 vid;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
switch (obj->trans_ph) {
|
switch (trans->ph) {
|
||||||
case SWITCHDEV_TRANS_PREPARE:
|
case SWITCHDEV_TRANS_PREPARE:
|
||||||
if (!ds->drv->port_vlan_add || !ds->drv->port_pvid_set)
|
if (!ds->drv->port_vlan_add || !ds->drv->port_pvid_set)
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
|
@ -347,16 +348,17 @@ static int dsa_slave_port_vlan_dump(struct net_device *dev,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dsa_slave_port_fdb_add(struct net_device *dev,
|
static int dsa_slave_port_fdb_add(struct net_device *dev,
|
||||||
struct switchdev_obj *obj)
|
struct switchdev_obj *obj,
|
||||||
|
struct switchdev_trans *trans)
|
||||||
{
|
{
|
||||||
struct switchdev_obj_fdb *fdb = &obj->u.fdb;
|
struct switchdev_obj_fdb *fdb = &obj->u.fdb;
|
||||||
struct dsa_slave_priv *p = netdev_priv(dev);
|
struct dsa_slave_priv *p = netdev_priv(dev);
|
||||||
struct dsa_switch *ds = p->parent;
|
struct dsa_switch *ds = p->parent;
|
||||||
int ret = -EOPNOTSUPP;
|
int ret = -EOPNOTSUPP;
|
||||||
|
|
||||||
if (obj->trans_ph == SWITCHDEV_TRANS_PREPARE)
|
if (trans->ph == SWITCHDEV_TRANS_PREPARE)
|
||||||
ret = ds->drv->port_fdb_add ? 0 : -EOPNOTSUPP;
|
ret = ds->drv->port_fdb_add ? 0 : -EOPNOTSUPP;
|
||||||
else if (obj->trans_ph == SWITCHDEV_TRANS_COMMIT)
|
else if (trans->ph == SWITCHDEV_TRANS_COMMIT)
|
||||||
ret = ds->drv->port_fdb_add(ds, p->port, fdb->addr, fdb->vid);
|
ret = ds->drv->port_fdb_add(ds, p->port, fdb->addr, fdb->vid);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -463,7 +465,7 @@ static int dsa_slave_port_attr_set(struct net_device *dev,
|
||||||
|
|
||||||
switch (attr->id) {
|
switch (attr->id) {
|
||||||
case SWITCHDEV_ATTR_PORT_STP_STATE:
|
case SWITCHDEV_ATTR_PORT_STP_STATE:
|
||||||
if (attr->trans_ph == SWITCHDEV_TRANS_COMMIT)
|
if (trans->ph == SWITCHDEV_TRANS_COMMIT)
|
||||||
ret = dsa_slave_stp_update(dev, attr->u.stp_state);
|
ret = dsa_slave_stp_update(dev, attr->u.stp_state);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -487,10 +489,10 @@ static int dsa_slave_port_obj_add(struct net_device *dev,
|
||||||
|
|
||||||
switch (obj->id) {
|
switch (obj->id) {
|
||||||
case SWITCHDEV_OBJ_PORT_FDB:
|
case SWITCHDEV_OBJ_PORT_FDB:
|
||||||
err = dsa_slave_port_fdb_add(dev, obj);
|
err = dsa_slave_port_fdb_add(dev, obj, trans);
|
||||||
break;
|
break;
|
||||||
case SWITCHDEV_OBJ_PORT_VLAN:
|
case SWITCHDEV_OBJ_PORT_VLAN:
|
||||||
err = dsa_slave_port_vlan_add(dev, obj);
|
err = dsa_slave_port_vlan_add(dev, obj, trans);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
err = -EOPNOTSUPP;
|
err = -EOPNOTSUPP;
|
||||||
|
|
|
@ -240,7 +240,7 @@ int switchdev_port_attr_set(struct net_device *dev, struct switchdev_attr *attr)
|
||||||
* but should not commit the attr.
|
* but should not commit the attr.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
attr->trans_ph = SWITCHDEV_TRANS_PREPARE;
|
trans.ph = SWITCHDEV_TRANS_PREPARE;
|
||||||
err = __switchdev_port_attr_set(dev, attr, &trans);
|
err = __switchdev_port_attr_set(dev, attr, &trans);
|
||||||
if (err) {
|
if (err) {
|
||||||
/* Prepare phase failed: abort the transaction. Any
|
/* Prepare phase failed: abort the transaction. Any
|
||||||
|
@ -249,7 +249,7 @@ int switchdev_port_attr_set(struct net_device *dev, struct switchdev_attr *attr)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (err != -EOPNOTSUPP) {
|
if (err != -EOPNOTSUPP) {
|
||||||
attr->trans_ph = SWITCHDEV_TRANS_ABORT;
|
trans.ph = SWITCHDEV_TRANS_ABORT;
|
||||||
__switchdev_port_attr_set(dev, attr, &trans);
|
__switchdev_port_attr_set(dev, attr, &trans);
|
||||||
switchdev_trans_items_destroy(&trans);
|
switchdev_trans_items_destroy(&trans);
|
||||||
}
|
}
|
||||||
|
@ -262,7 +262,7 @@ int switchdev_port_attr_set(struct net_device *dev, struct switchdev_attr *attr)
|
||||||
* because the driver said everythings was OK in phase I.
|
* because the driver said everythings was OK in phase I.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
attr->trans_ph = SWITCHDEV_TRANS_COMMIT;
|
trans.ph = SWITCHDEV_TRANS_COMMIT;
|
||||||
err = __switchdev_port_attr_set(dev, attr, &trans);
|
err = __switchdev_port_attr_set(dev, attr, &trans);
|
||||||
WARN(err, "%s: Commit of attribute (id=%d) failed.\n",
|
WARN(err, "%s: Commit of attribute (id=%d) failed.\n",
|
||||||
dev->name, attr->id);
|
dev->name, attr->id);
|
||||||
|
@ -326,7 +326,7 @@ int switchdev_port_obj_add(struct net_device *dev, struct switchdev_obj *obj)
|
||||||
* but should not commit the obj.
|
* but should not commit the obj.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
obj->trans_ph = SWITCHDEV_TRANS_PREPARE;
|
trans.ph = SWITCHDEV_TRANS_PREPARE;
|
||||||
err = __switchdev_port_obj_add(dev, obj, &trans);
|
err = __switchdev_port_obj_add(dev, obj, &trans);
|
||||||
if (err) {
|
if (err) {
|
||||||
/* Prepare phase failed: abort the transaction. Any
|
/* Prepare phase failed: abort the transaction. Any
|
||||||
|
@ -335,7 +335,7 @@ int switchdev_port_obj_add(struct net_device *dev, struct switchdev_obj *obj)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (err != -EOPNOTSUPP) {
|
if (err != -EOPNOTSUPP) {
|
||||||
obj->trans_ph = SWITCHDEV_TRANS_ABORT;
|
trans.ph = SWITCHDEV_TRANS_ABORT;
|
||||||
__switchdev_port_obj_add(dev, obj, &trans);
|
__switchdev_port_obj_add(dev, obj, &trans);
|
||||||
switchdev_trans_items_destroy(&trans);
|
switchdev_trans_items_destroy(&trans);
|
||||||
}
|
}
|
||||||
|
@ -348,7 +348,7 @@ int switchdev_port_obj_add(struct net_device *dev, struct switchdev_obj *obj)
|
||||||
* because the driver said everythings was OK in phase I.
|
* because the driver said everythings was OK in phase I.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
obj->trans_ph = SWITCHDEV_TRANS_COMMIT;
|
trans.ph = SWITCHDEV_TRANS_COMMIT;
|
||||||
err = __switchdev_port_obj_add(dev, obj, &trans);
|
err = __switchdev_port_obj_add(dev, obj, &trans);
|
||||||
WARN(err, "%s: Commit of object (id=%d) failed.\n", dev->name, obj->id);
|
WARN(err, "%s: Commit of object (id=%d) failed.\n", dev->name, obj->id);
|
||||||
switchdev_trans_items_warn_destroy(dev, &trans);
|
switchdev_trans_items_warn_destroy(dev, &trans);
|
||||||
|
|
Loading…
Reference in New Issue