mlxsw: spectrum_router: Extend the RIF struct
authorIdo Schimmel <idosch@mellanox.com>
Fri, 26 May 2017 06:37:34 +0000 (08:37 +0200)
committerDavid S. Miller <davem@davemloft.net>
Fri, 26 May 2017 19:18:48 +0000 (15:18 -0400)
Currently, when a Subport RIF is configured, the LAG status and VLAN of
the underlying port are read from the port itself. This is problematic,
as we would like to have common code to configure all types of RIFs,
which aren't necessarily bound to a port.

Instead, embed the RIF in a struct specific to the Subport type, which
contains all the necessary information.

Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c

index e81d45c8a827d1de46c36d0fb3c8ab6004c270eb..28ba5d323a374a6c2f0a55b0760f83644732e84d 100644 (file)
@@ -97,6 +97,16 @@ struct mlxsw_sp_rif {
        bool counter_egress_valid;
 };
 
+struct mlxsw_sp_rif_subport {
+       struct mlxsw_sp_rif common;
+       union {
+               u16 system_port;
+               u16 lag_id;
+       };
+       u16 vid;
+       bool lag;
+};
+
 static unsigned int *
 mlxsw_sp_rif_p_counter_get(struct mlxsw_sp_rif *rif,
                           enum mlxsw_sp_rif_counter_dir dir)
@@ -2965,11 +2975,13 @@ mlxsw_sp_rfid_alloc(u16 fid, struct net_device *l3_dev)
 
 static struct mlxsw_sp_rif *
 mlxsw_sp_rif_alloc(u16 rif_index, u16 vr_id, struct net_device *l3_dev,
-                  struct mlxsw_sp_fid *f)
+                  struct mlxsw_sp_fid *f, bool is_subport)
 {
+       size_t size = is_subport ? sizeof(struct mlxsw_sp_rif_subport) :
+                                  sizeof(struct mlxsw_sp_rif);
        struct mlxsw_sp_rif *rif;
 
-       rif = kzalloc(sizeof(*rif), GFP_KERNEL);
+       rif = kzalloc(size, GFP_KERNEL);
        if (!rif)
                return NULL;
 
@@ -3007,6 +3019,7 @@ mlxsw_sp_port_vlan_rif_sp_create(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan,
 {
        struct mlxsw_sp_port *mlxsw_sp_port = mlxsw_sp_port_vlan->mlxsw_sp_port;
        struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
+       struct mlxsw_sp_rif_subport *rif_subport;
        u32 tb_id = l3mdev_fib_table(l3_dev);
        struct mlxsw_sp_vr *vr;
        struct mlxsw_sp_fid *f;
@@ -3029,12 +3042,22 @@ mlxsw_sp_port_vlan_rif_sp_create(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan,
                goto err_vr_get;
        }
 
-       rif = mlxsw_sp_rif_alloc(rif_index, vr->id, l3_dev, f);
+       rif = mlxsw_sp_rif_alloc(rif_index, vr->id, l3_dev, f, true);
        if (!rif) {
                err = -ENOMEM;
                goto err_rif_alloc;
        }
 
+       rif_subport = container_of(rif, struct mlxsw_sp_rif_subport, common);
+       rif_subport->vid = mlxsw_sp_port_vlan->vid;
+       if (mlxsw_sp_port->lagged) {
+               rif_subport->lag = true;
+               rif_subport->lag_id = mlxsw_sp_port->lag_id;
+       } else {
+               rif_subport->lag = false;
+               rif_subport->system_port = mlxsw_sp_port->local_port;
+       }
+
        err = mlxsw_sp_port_vlan_rif_sp_op(mlxsw_sp_port_vlan, vr->id, l3_dev,
                                           rif_index, true);
        if (err)
@@ -3341,7 +3364,7 @@ static int mlxsw_sp_rif_bridge_create(struct mlxsw_sp *mlxsw_sp,
        if (err)
                goto err_port_flood_set;
 
-       rif = mlxsw_sp_rif_alloc(rif_index, vr->id, l3_dev, f);
+       rif = mlxsw_sp_rif_alloc(rif_index, vr->id, l3_dev, f, false);
        if (!rif) {
                err = -ENOMEM;
                goto err_rif_alloc;