Skip to content

Commit

Permalink
net/mlx5: E-switch, Introduce and use eswitch support check helper
Browse files Browse the repository at this point in the history
Introduce an helper routine to get esw from a devlink device and use it
at eswitch callbacks and in subsequent patch.

Signed-off-by: Parav Pandit <parav@mellanox.com>
Reviewed-by: Roi Dayan <roid@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Parav Pandit authored and David S. Miller committed Jun 22, 2020
1 parent fa99782 commit bd93975
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 40 deletions.
23 changes: 23 additions & 0 deletions drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,29 @@ struct vport_addr {
static void esw_destroy_legacy_fdb_table(struct mlx5_eswitch *esw);
static void esw_cleanup_vepa_rules(struct mlx5_eswitch *esw);

static int mlx5_eswitch_check(const struct mlx5_core_dev *dev)
{
if (MLX5_CAP_GEN(dev, port_type) != MLX5_CAP_PORT_TYPE_ETH)
return -EOPNOTSUPP;

if (!MLX5_ESWITCH_MANAGER(dev))
return -EPERM;

return 0;
}

struct mlx5_eswitch *mlx5_devlink_eswitch_get(struct devlink *devlink)
{
struct mlx5_core_dev *dev = devlink_priv(devlink);
int err;

err = mlx5_eswitch_check(dev);
if (err)
return ERR_PTR(err);

return dev->priv.eswitch;
}

struct mlx5_vport *__must_check
mlx5_eswitch_get_vport(struct mlx5_eswitch *esw, u16 vport_num)
{
Expand Down
1 change: 1 addition & 0 deletions drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ void mlx5e_tc_clean_fdb_peer_flows(struct mlx5_eswitch *esw);
for ((vport) = (nvfs); \
(vport) >= (esw)->first_host_vport; (vport)--)

struct mlx5_eswitch *mlx5_devlink_eswitch_get(struct devlink *devlink);
struct mlx5_vport *__must_check
mlx5_eswitch_get_vport(struct mlx5_eswitch *esw, u16 vport_num);

Expand Down
66 changes: 26 additions & 40 deletions drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
Original file line number Diff line number Diff line change
Expand Up @@ -2279,17 +2279,6 @@ static int esw_inline_mode_to_devlink(u8 mlx5_mode, u8 *mode)
return 0;
}

static int mlx5_eswitch_check(const struct mlx5_core_dev *dev)
{
if (MLX5_CAP_GEN(dev, port_type) != MLX5_CAP_PORT_TYPE_ETH)
return -EOPNOTSUPP;

if(!MLX5_ESWITCH_MANAGER(dev))
return -EPERM;

return 0;
}

static int eswitch_devlink_esw_mode_check(const struct mlx5_eswitch *esw)
{
/* devlink commands in NONE eswitch mode are currently supported only
Expand All @@ -2302,14 +2291,13 @@ static int eswitch_devlink_esw_mode_check(const struct mlx5_eswitch *esw)
int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode,
struct netlink_ext_ack *extack)
{
struct mlx5_core_dev *dev = devlink_priv(devlink);
struct mlx5_eswitch *esw = dev->priv.eswitch;
u16 cur_mlx5_mode, mlx5_mode = 0;
struct mlx5_eswitch *esw;
int err;

err = mlx5_eswitch_check(dev);
if (err)
return err;
esw = mlx5_devlink_eswitch_get(devlink);
if (IS_ERR(esw))
return PTR_ERR(esw);

if (esw_mode_from_devlink(mode, &mlx5_mode))
return -EINVAL;
Expand Down Expand Up @@ -2338,16 +2326,15 @@ int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode,

int mlx5_devlink_eswitch_mode_get(struct devlink *devlink, u16 *mode)
{
struct mlx5_core_dev *dev = devlink_priv(devlink);
struct mlx5_eswitch *esw = dev->priv.eswitch;
struct mlx5_eswitch *esw;
int err;

err = mlx5_eswitch_check(dev);
if (err)
return err;
esw = mlx5_devlink_eswitch_get(devlink);
if (IS_ERR(esw))
return PTR_ERR(esw);

mutex_lock(&esw->mode_lock);
err = eswitch_devlink_esw_mode_check(dev->priv.eswitch);
err = eswitch_devlink_esw_mode_check(esw);
if (err)
goto unlock;

Expand All @@ -2361,13 +2348,13 @@ int mlx5_devlink_eswitch_inline_mode_set(struct devlink *devlink, u8 mode,
struct netlink_ext_ack *extack)
{
struct mlx5_core_dev *dev = devlink_priv(devlink);
struct mlx5_eswitch *esw = dev->priv.eswitch;
int err, vport, num_vport;
struct mlx5_eswitch *esw;
u8 mlx5_mode;

err = mlx5_eswitch_check(dev);
if (err)
return err;
esw = mlx5_devlink_eswitch_get(devlink);
if (IS_ERR(esw))
return PTR_ERR(esw);

mutex_lock(&esw->mode_lock);
err = eswitch_devlink_esw_mode_check(esw);
Expand Down Expand Up @@ -2424,13 +2411,12 @@ int mlx5_devlink_eswitch_inline_mode_set(struct devlink *devlink, u8 mode,

int mlx5_devlink_eswitch_inline_mode_get(struct devlink *devlink, u8 *mode)
{
struct mlx5_core_dev *dev = devlink_priv(devlink);
struct mlx5_eswitch *esw = dev->priv.eswitch;
struct mlx5_eswitch *esw;
int err;

err = mlx5_eswitch_check(dev);
if (err)
return err;
esw = mlx5_devlink_eswitch_get(devlink);
if (IS_ERR(esw))
return PTR_ERR(esw);

mutex_lock(&esw->mode_lock);
err = eswitch_devlink_esw_mode_check(esw);
Expand All @@ -2448,12 +2434,12 @@ int mlx5_devlink_eswitch_encap_mode_set(struct devlink *devlink,
struct netlink_ext_ack *extack)
{
struct mlx5_core_dev *dev = devlink_priv(devlink);
struct mlx5_eswitch *esw = dev->priv.eswitch;
struct mlx5_eswitch *esw;
int err;

err = mlx5_eswitch_check(dev);
if (err)
return err;
esw = mlx5_devlink_eswitch_get(devlink);
if (IS_ERR(esw))
return PTR_ERR(esw);

mutex_lock(&esw->mode_lock);
err = eswitch_devlink_esw_mode_check(esw);
Expand Down Expand Up @@ -2508,13 +2494,13 @@ int mlx5_devlink_eswitch_encap_mode_set(struct devlink *devlink,
int mlx5_devlink_eswitch_encap_mode_get(struct devlink *devlink,
enum devlink_eswitch_encap_mode *encap)
{
struct mlx5_core_dev *dev = devlink_priv(devlink);
struct mlx5_eswitch *esw = dev->priv.eswitch;
struct mlx5_eswitch *esw;
int err;

err = mlx5_eswitch_check(dev);
if (err)
return err;
esw = mlx5_devlink_eswitch_get(devlink);
if (IS_ERR(esw))
return PTR_ERR(esw);


mutex_lock(&esw->mode_lock);
err = eswitch_devlink_esw_mode_check(esw);
Expand Down

0 comments on commit bd93975

Please sign in to comment.