Commit bd939753 authored by Parav Pandit's avatar Parav Pandit Committed by David S. Miller

net/mlx5: E-switch, Introduce and use eswitch support check helper

Introduce an helper routine to get esw from a devlink device and use it
at eswitch callbacks and in subsequent patch.
Signed-off-by: default avatarParav Pandit <parav@mellanox.com>
Reviewed-by: default avatarRoi Dayan <roid@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent fa997825
...@@ -63,6 +63,29 @@ struct vport_addr { ...@@ -63,6 +63,29 @@ struct vport_addr {
static void esw_destroy_legacy_fdb_table(struct mlx5_eswitch *esw); static void esw_destroy_legacy_fdb_table(struct mlx5_eswitch *esw);
static void esw_cleanup_vepa_rules(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 struct mlx5_vport *__must_check
mlx5_eswitch_get_vport(struct mlx5_eswitch *esw, u16 vport_num) mlx5_eswitch_get_vport(struct mlx5_eswitch *esw, u16 vport_num)
{ {
......
...@@ -634,6 +634,7 @@ void mlx5e_tc_clean_fdb_peer_flows(struct mlx5_eswitch *esw); ...@@ -634,6 +634,7 @@ void mlx5e_tc_clean_fdb_peer_flows(struct mlx5_eswitch *esw);
for ((vport) = (nvfs); \ for ((vport) = (nvfs); \
(vport) >= (esw)->first_host_vport; (vport)--) (vport) >= (esw)->first_host_vport; (vport)--)
struct mlx5_eswitch *mlx5_devlink_eswitch_get(struct devlink *devlink);
struct mlx5_vport *__must_check struct mlx5_vport *__must_check
mlx5_eswitch_get_vport(struct mlx5_eswitch *esw, u16 vport_num); mlx5_eswitch_get_vport(struct mlx5_eswitch *esw, u16 vport_num);
......
...@@ -2279,17 +2279,6 @@ static int esw_inline_mode_to_devlink(u8 mlx5_mode, u8 *mode) ...@@ -2279,17 +2279,6 @@ static int esw_inline_mode_to_devlink(u8 mlx5_mode, u8 *mode)
return 0; 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) static int eswitch_devlink_esw_mode_check(const struct mlx5_eswitch *esw)
{ {
/* devlink commands in NONE eswitch mode are currently supported only /* devlink commands in NONE eswitch mode are currently supported only
...@@ -2302,14 +2291,13 @@ static int eswitch_devlink_esw_mode_check(const struct mlx5_eswitch *esw) ...@@ -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, int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode,
struct netlink_ext_ack *extack) 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; u16 cur_mlx5_mode, mlx5_mode = 0;
struct mlx5_eswitch *esw;
int err; int err;
err = mlx5_eswitch_check(dev); esw = mlx5_devlink_eswitch_get(devlink);
if (err) if (IS_ERR(esw))
return err; return PTR_ERR(esw);
if (esw_mode_from_devlink(mode, &mlx5_mode)) if (esw_mode_from_devlink(mode, &mlx5_mode))
return -EINVAL; return -EINVAL;
...@@ -2338,16 +2326,15 @@ int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode, ...@@ -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) int mlx5_devlink_eswitch_mode_get(struct devlink *devlink, u16 *mode)
{ {
struct mlx5_core_dev *dev = devlink_priv(devlink); struct mlx5_eswitch *esw;
struct mlx5_eswitch *esw = dev->priv.eswitch;
int err; int err;
err = mlx5_eswitch_check(dev); esw = mlx5_devlink_eswitch_get(devlink);
if (err) if (IS_ERR(esw))
return err; return PTR_ERR(esw);
mutex_lock(&esw->mode_lock); mutex_lock(&esw->mode_lock);
err = eswitch_devlink_esw_mode_check(dev->priv.eswitch); err = eswitch_devlink_esw_mode_check(esw);
if (err) if (err)
goto unlock; goto unlock;
...@@ -2361,13 +2348,13 @@ int mlx5_devlink_eswitch_inline_mode_set(struct devlink *devlink, u8 mode, ...@@ -2361,13 +2348,13 @@ int mlx5_devlink_eswitch_inline_mode_set(struct devlink *devlink, u8 mode,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct mlx5_core_dev *dev = devlink_priv(devlink); struct mlx5_core_dev *dev = devlink_priv(devlink);
struct mlx5_eswitch *esw = dev->priv.eswitch;
int err, vport, num_vport; int err, vport, num_vport;
struct mlx5_eswitch *esw;
u8 mlx5_mode; u8 mlx5_mode;
err = mlx5_eswitch_check(dev); esw = mlx5_devlink_eswitch_get(devlink);
if (err) if (IS_ERR(esw))
return err; return PTR_ERR(esw);
mutex_lock(&esw->mode_lock); mutex_lock(&esw->mode_lock);
err = eswitch_devlink_esw_mode_check(esw); err = eswitch_devlink_esw_mode_check(esw);
...@@ -2424,13 +2411,12 @@ int mlx5_devlink_eswitch_inline_mode_set(struct devlink *devlink, u8 mode, ...@@ -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) int mlx5_devlink_eswitch_inline_mode_get(struct devlink *devlink, u8 *mode)
{ {
struct mlx5_core_dev *dev = devlink_priv(devlink); struct mlx5_eswitch *esw;
struct mlx5_eswitch *esw = dev->priv.eswitch;
int err; int err;
err = mlx5_eswitch_check(dev); esw = mlx5_devlink_eswitch_get(devlink);
if (err) if (IS_ERR(esw))
return err; return PTR_ERR(esw);
mutex_lock(&esw->mode_lock); mutex_lock(&esw->mode_lock);
err = eswitch_devlink_esw_mode_check(esw); err = eswitch_devlink_esw_mode_check(esw);
...@@ -2448,12 +2434,12 @@ int mlx5_devlink_eswitch_encap_mode_set(struct devlink *devlink, ...@@ -2448,12 +2434,12 @@ int mlx5_devlink_eswitch_encap_mode_set(struct devlink *devlink,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct mlx5_core_dev *dev = devlink_priv(devlink); struct mlx5_core_dev *dev = devlink_priv(devlink);
struct mlx5_eswitch *esw = dev->priv.eswitch; struct mlx5_eswitch *esw;
int err; int err;
err = mlx5_eswitch_check(dev); esw = mlx5_devlink_eswitch_get(devlink);
if (err) if (IS_ERR(esw))
return err; return PTR_ERR(esw);
mutex_lock(&esw->mode_lock); mutex_lock(&esw->mode_lock);
err = eswitch_devlink_esw_mode_check(esw); err = eswitch_devlink_esw_mode_check(esw);
...@@ -2508,13 +2494,13 @@ int mlx5_devlink_eswitch_encap_mode_set(struct devlink *devlink, ...@@ -2508,13 +2494,13 @@ int mlx5_devlink_eswitch_encap_mode_set(struct devlink *devlink,
int mlx5_devlink_eswitch_encap_mode_get(struct devlink *devlink, int mlx5_devlink_eswitch_encap_mode_get(struct devlink *devlink,
enum devlink_eswitch_encap_mode *encap) enum devlink_eswitch_encap_mode *encap)
{ {
struct mlx5_core_dev *dev = devlink_priv(devlink); struct mlx5_eswitch *esw;
struct mlx5_eswitch *esw = dev->priv.eswitch;
int err; int err;
err = mlx5_eswitch_check(dev); esw = mlx5_devlink_eswitch_get(devlink);
if (err) if (IS_ERR(esw))
return err; return PTR_ERR(esw);
mutex_lock(&esw->mode_lock); mutex_lock(&esw->mode_lock);
err = eswitch_devlink_esw_mode_check(esw); err = eswitch_devlink_esw_mode_check(esw);
......
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