Skip to content

Commit

Permalink
Merge branch 'switchdev-obj'
Browse files Browse the repository at this point in the history
Jiri Pirko says:

====================
switchdev: bring back switchdev_obj

Second version of the patch extends to a patchset. Basically this patchset
brings object structure back which disappeared with recent Vivien's patchset.
Also it does a bit of naming changes in order to get the things in line.
Also, object id is put back into object structure.
Thanks to Scott and Vivien for review and suggestions.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Oct 3, 2015
2 parents c3fc7ac + 9e8f4a5 commit bd8762b
Show file tree
Hide file tree
Showing 11 changed files with 199 additions and 160 deletions.
15 changes: 8 additions & 7 deletions Documentation/networking/switchdev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Switch ID
^^^^^^^^^

The switchdev driver must implement the switchdev op switchdev_port_attr_get
for SWITCHDEV_ATTR_PORT_PARENT_ID for each port netdev, returning the same
for SWITCHDEV_ATTR_ID_PORT_PARENT_ID for each port netdev, returning the same
physical ID for each port of a switch. The ID must be unique between switches
on the same system. The ID does not need to be unique between switches on
different systems.
Expand Down Expand Up @@ -178,7 +178,7 @@ entries are installed, for example, using iproute2 bridge cmd:
bridge fdb add ADDR dev DEV [vlan VID] [self]

The driver should use the helper switchdev_port_fdb_xxx ops for ndo_fdb_xxx
ops, and handle add/delete/dump of SWITCHDEV_OBJ_PORT_FDB object using
ops, and handle add/delete/dump of SWITCHDEV_OBJ_ID_PORT_FDB object using
switchdev_port_obj_xxx ops.

XXX: what should be done if offloading this rule to hardware fails (for
Expand Down Expand Up @@ -233,8 +233,9 @@ the bridge's FDB. It's possible, but not optimal, to enable learning on the
device port and on the bridge port, and disable learning_sync.

To support learning and learning_sync port attributes, the driver implements
switchdev op switchdev_port_attr_get/set for SWITCHDEV_ATTR_PORT_BRIDGE_FLAGS.
The driver should initialize the attributes to the hardware defaults.
switchdev op switchdev_port_attr_get/set for
SWITCHDEV_ATTR_PORT_ID_BRIDGE_FLAGS. The driver should initialize the attributes
to the hardware defaults.

FDB Ageing
^^^^^^^^^^
Expand All @@ -260,7 +261,7 @@ STP State Change on Port
Internally or with a third-party STP protocol implementation (e.g. mstpd), the
bridge driver maintains the STP state for ports, and will notify the switch
driver of STP state change on a port using the switchdev op
switchdev_attr_port_set for SWITCHDEV_ATTR_PORT_STP_UPDATE.
switchdev_attr_port_set for SWITCHDEV_ATTR_PORT_ID_STP_UPDATE.

State is one of BR_STATE_*. The switch driver can use STP state updates to
update ingress packet filter list for the port. For example, if port is
Expand Down Expand Up @@ -316,9 +317,9 @@ SWITCHDEV_OBJ_IPV[4|6]_FIB object using switchdev_port_obj_xxx ops.
switchdev_port_obj_add is used for both adding a new FIB entry to the device,
or modifying an existing entry on the device.

XXX: Currently, only SWITCHDEV_OBJ_IPV4_FIB objects are supported.
XXX: Currently, only SWITCHDEV_OBJ_ID_IPV4_FIB objects are supported.

SWITCHDEV_OBJ_IPV4_FIB object passes:
SWITCHDEV_OBJ_ID_IPV4_FIB object passes:

struct switchdev_obj_ipv4_fib { /* IPV4_FIB */
u32 dst;
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/mellanox/mlxsw/switchx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ static int mlxsw_sx_port_attr_get(struct net_device *dev,
struct mlxsw_sx *mlxsw_sx = mlxsw_sx_port->mlxsw_sx;

switch (attr->id) {
case SWITCHDEV_ATTR_PORT_PARENT_ID:
case SWITCHDEV_ATTR_ID_PORT_PARENT_ID:
attr->u.ppid.id_len = sizeof(mlxsw_sx->hw_id);
memcpy(&attr->u.ppid.id, &mlxsw_sx->hw_id, attr->u.ppid.id_len);
break;
Expand Down
80 changes: 43 additions & 37 deletions drivers/net/ethernet/rocker/rocker.c
Original file line number Diff line number Diff line change
Expand Up @@ -4329,11 +4329,11 @@ static int rocker_port_attr_get(struct net_device *dev,
const struct rocker *rocker = rocker_port->rocker;

switch (attr->id) {
case SWITCHDEV_ATTR_PORT_PARENT_ID:
case SWITCHDEV_ATTR_ID_PORT_PARENT_ID:
attr->u.ppid.id_len = sizeof(rocker->hw.id);
memcpy(&attr->u.ppid.id, &rocker->hw.id, attr->u.ppid.id_len);
break;
case SWITCHDEV_ATTR_PORT_BRIDGE_FLAGS:
case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS:
attr->u.brport_flags = rocker_port->brport_flags;
break;
default:
Expand Down Expand Up @@ -4369,12 +4369,12 @@ static int rocker_port_attr_set(struct net_device *dev,
int err = 0;

switch (attr->id) {
case SWITCHDEV_ATTR_PORT_STP_STATE:
case SWITCHDEV_ATTR_ID_PORT_STP_STATE:
err = rocker_port_stp_update(rocker_port, trans,
ROCKER_OP_FLAG_NOWAIT,
attr->u.stp_state);
break;
case SWITCHDEV_ATTR_PORT_BRIDGE_FLAGS:
case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS:
err = rocker_port_brport_flags_set(rocker_port, trans,
attr->u.brport_flags);
break;
Expand Down Expand Up @@ -4408,7 +4408,7 @@ static int rocker_port_vlan_add(struct rocker_port *rocker_port,

static int rocker_port_vlans_add(struct rocker_port *rocker_port,
struct switchdev_trans *trans,
const struct switchdev_obj_vlan *vlan)
const struct switchdev_obj_port_vlan *vlan)
{
u16 vid;
int err;
Expand All @@ -4425,7 +4425,7 @@ static int rocker_port_vlans_add(struct rocker_port *rocker_port,

static int rocker_port_fdb_add(struct rocker_port *rocker_port,
struct switchdev_trans *trans,
const struct switchdev_obj_fdb *fdb)
const struct switchdev_obj_port_fdb *fdb)
{
__be16 vlan_id = rocker_port_vid_to_vlan(rocker_port, fdb->vid, NULL);
int flags = 0;
Expand All @@ -4437,25 +4437,27 @@ static int rocker_port_fdb_add(struct rocker_port *rocker_port,
}

static int rocker_port_obj_add(struct net_device *dev,
enum switchdev_obj_id id, const void *obj,
const struct switchdev_obj *obj,
struct switchdev_trans *trans)
{
struct rocker_port *rocker_port = netdev_priv(dev);
const struct switchdev_obj_ipv4_fib *fib4;
int err = 0;

switch (id) {
case SWITCHDEV_OBJ_PORT_VLAN:
err = rocker_port_vlans_add(rocker_port, trans, obj);
switch (obj->id) {
case SWITCHDEV_OBJ_ID_PORT_VLAN:
err = rocker_port_vlans_add(rocker_port, trans,
SWITCHDEV_OBJ_PORT_VLAN(obj));
break;
case SWITCHDEV_OBJ_IPV4_FIB:
fib4 = obj;
case SWITCHDEV_OBJ_ID_IPV4_FIB:
fib4 = SWITCHDEV_OBJ_IPV4_FIB(obj);
err = rocker_port_fib_ipv4(rocker_port, trans,
htonl(fib4->dst), fib4->dst_len,
fib4->fi, fib4->tb_id, 0);
break;
case SWITCHDEV_OBJ_PORT_FDB:
err = rocker_port_fdb_add(rocker_port, trans, obj);
case SWITCHDEV_OBJ_ID_PORT_FDB:
err = rocker_port_fdb_add(rocker_port, trans,
SWITCHDEV_OBJ_PORT_FDB(obj));
break;
default:
err = -EOPNOTSUPP;
Expand All @@ -4480,7 +4482,7 @@ static int rocker_port_vlan_del(struct rocker_port *rocker_port,
}

static int rocker_port_vlans_del(struct rocker_port *rocker_port,
const struct switchdev_obj_vlan *vlan)
const struct switchdev_obj_port_vlan *vlan)
{
u16 vid;
int err;
Expand All @@ -4496,7 +4498,7 @@ static int rocker_port_vlans_del(struct rocker_port *rocker_port,

static int rocker_port_fdb_del(struct rocker_port *rocker_port,
struct switchdev_trans *trans,
const struct switchdev_obj_fdb *fdb)
const struct switchdev_obj_port_fdb *fdb)
{
__be16 vlan_id = rocker_port_vid_to_vlan(rocker_port, fdb->vid, NULL);
int flags = ROCKER_OP_FLAG_NOWAIT | ROCKER_OP_FLAG_REMOVE;
Expand All @@ -4508,25 +4510,27 @@ static int rocker_port_fdb_del(struct rocker_port *rocker_port,
}

static int rocker_port_obj_del(struct net_device *dev,
enum switchdev_obj_id id, const void *obj)
const struct switchdev_obj *obj)
{
struct rocker_port *rocker_port = netdev_priv(dev);
const struct switchdev_obj_ipv4_fib *fib4;
int err = 0;

switch (id) {
case SWITCHDEV_OBJ_PORT_VLAN:
err = rocker_port_vlans_del(rocker_port, obj);
switch (obj->id) {
case SWITCHDEV_OBJ_ID_PORT_VLAN:
err = rocker_port_vlans_del(rocker_port,
SWITCHDEV_OBJ_PORT_VLAN(obj));
break;
case SWITCHDEV_OBJ_IPV4_FIB:
fib4 = obj;
case SWITCHDEV_OBJ_ID_IPV4_FIB:
fib4 = SWITCHDEV_OBJ_IPV4_FIB(obj);
err = rocker_port_fib_ipv4(rocker_port, NULL,
htonl(fib4->dst), fib4->dst_len,
fib4->fi, fib4->tb_id,
ROCKER_OP_FLAG_REMOVE);
break;
case SWITCHDEV_OBJ_PORT_FDB:
err = rocker_port_fdb_del(rocker_port, NULL, obj);
case SWITCHDEV_OBJ_ID_PORT_FDB:
err = rocker_port_fdb_del(rocker_port, NULL,
SWITCHDEV_OBJ_PORT_FDB(obj));
break;
default:
err = -EOPNOTSUPP;
Expand All @@ -4537,8 +4541,8 @@ static int rocker_port_obj_del(struct net_device *dev,
}

static int rocker_port_fdb_dump(const struct rocker_port *rocker_port,
struct switchdev_obj_fdb *fdb,
int (*cb)(void *obj))
struct switchdev_obj_port_fdb *fdb,
switchdev_obj_dump_cb_t *cb)
{
struct rocker *rocker = rocker_port->rocker;
struct rocker_fdb_tbl_entry *found;
Expand All @@ -4555,7 +4559,7 @@ static int rocker_port_fdb_dump(const struct rocker_port *rocker_port,
fdb->ndm_state = NUD_REACHABLE;
fdb->vid = rocker_port_vlan_to_vid(rocker_port,
found->key.vlan_id);
err = cb(fdb);
err = cb(&fdb->obj);
if (err)
break;
}
Expand All @@ -4565,8 +4569,8 @@ static int rocker_port_fdb_dump(const struct rocker_port *rocker_port,
}

static int rocker_port_vlan_dump(const struct rocker_port *rocker_port,
struct switchdev_obj_vlan *vlan,
int (*cb)(void *obj))
struct switchdev_obj_port_vlan *vlan,
switchdev_obj_dump_cb_t *cb)
{
u16 vid;
int err = 0;
Expand All @@ -4578,7 +4582,7 @@ static int rocker_port_vlan_dump(const struct rocker_port *rocker_port,
if (rocker_vlan_id_is_internal(htons(vid)))
vlan->flags |= BRIDGE_VLAN_INFO_PVID;
vlan->vid_begin = vlan->vid_end = vid;
err = cb(vlan);
err = cb(&vlan->obj);
if (err)
break;
}
Expand All @@ -4587,18 +4591,20 @@ static int rocker_port_vlan_dump(const struct rocker_port *rocker_port,
}

static int rocker_port_obj_dump(struct net_device *dev,
enum switchdev_obj_id id, void *obj,
int (*cb)(void *obj))
struct switchdev_obj *obj,
switchdev_obj_dump_cb_t *cb)
{
const struct rocker_port *rocker_port = netdev_priv(dev);
int err = 0;

switch (id) {
case SWITCHDEV_OBJ_PORT_FDB:
err = rocker_port_fdb_dump(rocker_port, obj, cb);
switch (obj->id) {
case SWITCHDEV_OBJ_ID_PORT_FDB:
err = rocker_port_fdb_dump(rocker_port,
SWITCHDEV_OBJ_PORT_FDB(obj), cb);
break;
case SWITCHDEV_OBJ_PORT_VLAN:
err = rocker_port_vlan_dump(rocker_port, obj, cb);
case SWITCHDEV_OBJ_ID_PORT_VLAN:
err = rocker_port_vlan_dump(rocker_port,
SWITCHDEV_OBJ_PORT_VLAN(obj), cb);
break;
default:
err = -EOPNOTSUPP;
Expand Down
Loading

0 comments on commit bd8762b

Please sign in to comment.