Commit c7e920b5 authored by Ido Schimmel's avatar Ido Schimmel Committed by David S. Miller

mlxsw: spectrum: Use only one function to create vFIDs

Simplify the code and use only one function for vFID creation /
destruction.

Unlike before, the function receives a FID index as its argument and not
a vFID index. Instead of passing 0, now one would need to pass 4K, which
is the first vFID.

This is the first step in creating a generic FID struct that will be
used for all three types of FIDs.
Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 47a0a9e6
...@@ -652,68 +652,61 @@ static u16 mlxsw_sp_avail_vfid_get(const struct mlxsw_sp *mlxsw_sp) ...@@ -652,68 +652,61 @@ static u16 mlxsw_sp_avail_vfid_get(const struct mlxsw_sp *mlxsw_sp)
MLXSW_SP_VFID_PORT_MAX); MLXSW_SP_VFID_PORT_MAX);
} }
static int __mlxsw_sp_vfid_create(struct mlxsw_sp *mlxsw_sp, u16 vfid) static int mlxsw_sp_vfid_op(struct mlxsw_sp *mlxsw_sp, u16 fid, bool create)
{ {
u16 fid = mlxsw_sp_vfid_to_fid(vfid);
char sfmr_pl[MLXSW_REG_SFMR_LEN]; char sfmr_pl[MLXSW_REG_SFMR_LEN];
mlxsw_reg_sfmr_pack(sfmr_pl, MLXSW_REG_SFMR_OP_CREATE_FID, fid, 0); mlxsw_reg_sfmr_pack(sfmr_pl, !create, fid, 0);
return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfmr), sfmr_pl); return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfmr), sfmr_pl);
} }
static void __mlxsw_sp_vfid_destroy(struct mlxsw_sp *mlxsw_sp, u16 vfid)
{
u16 fid = mlxsw_sp_vfid_to_fid(vfid);
char sfmr_pl[MLXSW_REG_SFMR_LEN];
mlxsw_reg_sfmr_pack(sfmr_pl, MLXSW_REG_SFMR_OP_DESTROY_FID, fid, 0);
mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfmr), sfmr_pl);
}
static struct mlxsw_sp_vfid *mlxsw_sp_vfid_create(struct mlxsw_sp *mlxsw_sp, static struct mlxsw_sp_vfid *mlxsw_sp_vfid_create(struct mlxsw_sp *mlxsw_sp,
u16 vid) u16 vid)
{ {
struct device *dev = mlxsw_sp->bus_info->dev; struct device *dev = mlxsw_sp->bus_info->dev;
struct mlxsw_sp_vfid *vfid; struct mlxsw_sp_vfid *f;
u16 n_vfid; u16 vfid, fid;
int err; int err;
n_vfid = mlxsw_sp_avail_vfid_get(mlxsw_sp); vfid = mlxsw_sp_avail_vfid_get(mlxsw_sp);
if (n_vfid == MLXSW_SP_VFID_PORT_MAX) { if (vfid == MLXSW_SP_VFID_PORT_MAX) {
dev_err(dev, "No available vFIDs\n"); dev_err(dev, "No available vFIDs\n");
return ERR_PTR(-ERANGE); return ERR_PTR(-ERANGE);
} }
err = __mlxsw_sp_vfid_create(mlxsw_sp, n_vfid); fid = mlxsw_sp_vfid_to_fid(vfid);
err = mlxsw_sp_vfid_op(mlxsw_sp, fid, true);
if (err) { if (err) {
dev_err(dev, "Failed to create vFID=%d\n", n_vfid); dev_err(dev, "Failed to create FID=%d\n", fid);
return ERR_PTR(err); return ERR_PTR(err);
} }
vfid = kzalloc(sizeof(*vfid), GFP_KERNEL); f = kzalloc(sizeof(*f), GFP_KERNEL);
if (!vfid) if (!f)
goto err_allocate_vfid; goto err_allocate_vfid;
vfid->vfid = n_vfid; f->vfid = vfid;
vfid->vid = vid; f->vid = vid;
list_add(&vfid->list, &mlxsw_sp->port_vfids.list); list_add(&f->list, &mlxsw_sp->port_vfids.list);
set_bit(n_vfid, mlxsw_sp->port_vfids.mapped); set_bit(vfid, mlxsw_sp->port_vfids.mapped);
return vfid; return f;
err_allocate_vfid: err_allocate_vfid:
__mlxsw_sp_vfid_destroy(mlxsw_sp, n_vfid); mlxsw_sp_vfid_op(mlxsw_sp, fid, false);
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
static void mlxsw_sp_vfid_destroy(struct mlxsw_sp *mlxsw_sp, static void mlxsw_sp_vfid_destroy(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_vfid *vfid) struct mlxsw_sp_vfid *vfid)
{ {
u16 fid = mlxsw_sp_vfid_to_fid(vfid->vfid);
clear_bit(vfid->vfid, mlxsw_sp->port_vfids.mapped); clear_bit(vfid->vfid, mlxsw_sp->port_vfids.mapped);
list_del(&vfid->list); list_del(&vfid->list);
__mlxsw_sp_vfid_destroy(mlxsw_sp, vfid->vfid); mlxsw_sp_vfid_op(mlxsw_sp, fid, false);
kfree(vfid); kfree(vfid);
} }
...@@ -3164,36 +3157,37 @@ static struct mlxsw_sp_vfid *mlxsw_sp_br_vfid_create(struct mlxsw_sp *mlxsw_sp, ...@@ -3164,36 +3157,37 @@ static struct mlxsw_sp_vfid *mlxsw_sp_br_vfid_create(struct mlxsw_sp *mlxsw_sp,
struct net_device *br_dev) struct net_device *br_dev)
{ {
struct device *dev = mlxsw_sp->bus_info->dev; struct device *dev = mlxsw_sp->bus_info->dev;
struct mlxsw_sp_vfid *vfid; struct mlxsw_sp_vfid *f;
u16 n_vfid; u16 vfid, fid;
int err; int err;
n_vfid = mlxsw_sp_br_vfid_to_vfid(mlxsw_sp_avail_br_vfid_get(mlxsw_sp)); vfid = mlxsw_sp_br_vfid_to_vfid(mlxsw_sp_avail_br_vfid_get(mlxsw_sp));
if (n_vfid == MLXSW_SP_VFID_MAX) { if (vfid == MLXSW_SP_VFID_MAX) {
dev_err(dev, "No available vFIDs\n"); dev_err(dev, "No available vFIDs\n");
return ERR_PTR(-ERANGE); return ERR_PTR(-ERANGE);
} }
err = __mlxsw_sp_vfid_create(mlxsw_sp, n_vfid); fid = mlxsw_sp_vfid_to_fid(vfid);
err = mlxsw_sp_vfid_op(mlxsw_sp, fid, true);
if (err) { if (err) {
dev_err(dev, "Failed to create vFID=%d\n", n_vfid); dev_err(dev, "Failed to create FID=%d\n", fid);
return ERR_PTR(err); return ERR_PTR(err);
} }
vfid = kzalloc(sizeof(*vfid), GFP_KERNEL); f = kzalloc(sizeof(*f), GFP_KERNEL);
if (!vfid) if (!f)
goto err_allocate_vfid; goto err_allocate_vfid;
vfid->vfid = n_vfid; f->vfid = vfid;
vfid->br_dev = br_dev; f->br_dev = br_dev;
list_add(&vfid->list, &mlxsw_sp->br_vfids.list); list_add(&f->list, &mlxsw_sp->br_vfids.list);
set_bit(mlxsw_sp_vfid_to_br_vfid(n_vfid), mlxsw_sp->br_vfids.mapped); set_bit(mlxsw_sp_vfid_to_br_vfid(vfid), mlxsw_sp->br_vfids.mapped);
return vfid; return f;
err_allocate_vfid: err_allocate_vfid:
__mlxsw_sp_vfid_destroy(mlxsw_sp, n_vfid); mlxsw_sp_vfid_op(mlxsw_sp, fid, false);
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
...@@ -3201,11 +3195,12 @@ static void mlxsw_sp_br_vfid_destroy(struct mlxsw_sp *mlxsw_sp, ...@@ -3201,11 +3195,12 @@ static void mlxsw_sp_br_vfid_destroy(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_vfid *vfid) struct mlxsw_sp_vfid *vfid)
{ {
u16 br_vfid = mlxsw_sp_vfid_to_br_vfid(vfid->vfid); u16 br_vfid = mlxsw_sp_vfid_to_br_vfid(vfid->vfid);
u16 fid = mlxsw_sp_vfid_to_fid(vfid->vfid);
clear_bit(br_vfid, mlxsw_sp->br_vfids.mapped); clear_bit(br_vfid, mlxsw_sp->br_vfids.mapped);
list_del(&vfid->list); list_del(&vfid->list);
__mlxsw_sp_vfid_destroy(mlxsw_sp, vfid->vfid); mlxsw_sp_vfid_op(mlxsw_sp, fid, false);
kfree(vfid); kfree(vfid);
} }
......
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