net/mlx5: Relax mlx5_devlink_eswitch_get() return value checking
authorJiri Pirko <jiri@nvidia.com>
Thu, 1 Jun 2023 11:59:52 +0000 (13:59 +0200)
committerSaeed Mahameed <saeedm@nvidia.com>
Wed, 23 Aug 2023 04:34:17 +0000 (21:34 -0700)
If called from port ops, it is not needed to perform the checks in
mlx5_devlink_eswitch_get(). The reason is devlink port would not be
registered if the checks are not true. Introduce relaxed version
mlx5_devlink_eswitch_nocheck_get() and use it in port ops.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Shay Drory <shayd@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c

index 5368b33fde638dbce1c672ec6f4a7424285afb2d..db1c2a0763643ad5377ef3ec8b2263922a1282eb 100644 (file)
@@ -77,18 +77,31 @@ static int mlx5_eswitch_check(const struct mlx5_core_dev *dev)
        return 0;
 }
 
-struct mlx5_eswitch *mlx5_devlink_eswitch_get(struct devlink *devlink)
+static struct mlx5_eswitch *__mlx5_devlink_eswitch_get(struct devlink *devlink, bool check)
 {
        struct mlx5_core_dev *dev = devlink_priv(devlink);
        int err;
 
-       err = mlx5_eswitch_check(dev);
-       if (err)
-               return ERR_PTR(err);
+       if (check) {
+               err = mlx5_eswitch_check(dev);
+               if (err)
+                       return ERR_PTR(err);
+       }
 
        return dev->priv.eswitch;
 }
 
+struct mlx5_eswitch *__must_check
+mlx5_devlink_eswitch_get(struct devlink *devlink)
+{
+       return __mlx5_devlink_eswitch_get(devlink, true);
+}
+
+struct mlx5_eswitch *mlx5_devlink_eswitch_nocheck_get(struct devlink *devlink)
+{
+       return __mlx5_devlink_eswitch_get(devlink, false);
+}
+
 struct mlx5_vport *__must_check
 mlx5_eswitch_get_vport(struct mlx5_eswitch *esw, u16 vport_num)
 {
index 8d03d4fe6eec20860aa157b2379c666c29dcd75f..9f94c3d6d6e5530a1bed11a92dd1f801b415e4e1 100644 (file)
@@ -679,7 +679,11 @@ void mlx5e_tc_clean_fdb_peer_flows(struct mlx5_eswitch *esw);
                          MLX5_CAP_GEN_2((esw->dev), ec_vf_vport_base) +\
                          (last) - 1)
 
-struct mlx5_eswitch *mlx5_devlink_eswitch_get(struct devlink *devlink);
+struct mlx5_eswitch *__must_check
+mlx5_devlink_eswitch_get(struct devlink *devlink);
+
+struct mlx5_eswitch *mlx5_devlink_eswitch_nocheck_get(struct devlink *devlink);
+
 struct mlx5_vport *__must_check
 mlx5_eswitch_get_vport(struct mlx5_eswitch *esw, u16 vport_num);
 
index 87cc6ad2e17fd85ddf0e580f38118e0b80e4672a..23b562f07c68da6b2787f38ce84b7fefbb87759a 100644 (file)
@@ -3634,7 +3634,7 @@ static bool esw_offloads_devlink_ns_eq_netdev_ns(struct devlink *devlink)
        struct net *devl_net, *netdev_net;
        struct mlx5_eswitch *esw;
 
-       esw = mlx5_devlink_eswitch_get(devlink);
+       esw = mlx5_devlink_eswitch_nocheck_get(devlink);
        netdev_net = dev_net(esw->dev->mlx5e_res.uplink_netdev);
        devl_net = devlink_net(devlink);
 
@@ -4222,13 +4222,10 @@ int mlx5_devlink_port_fn_hw_addr_get(struct devlink_port *port,
                                     u8 *hw_addr, int *hw_addr_len,
                                     struct netlink_ext_ack *extack)
 {
-       struct mlx5_eswitch *esw;
+       struct mlx5_eswitch *esw = mlx5_devlink_eswitch_nocheck_get(port->devlink);
        struct mlx5_vport *vport;
        u16 vport_num;
 
-       esw = mlx5_devlink_eswitch_get(port->devlink);
-       if (IS_ERR(esw))
-               return PTR_ERR(esw);
 
        vport_num = mlx5_esw_devlink_port_index_to_vport_num(port->index);
 
@@ -4249,15 +4246,9 @@ int mlx5_devlink_port_fn_hw_addr_set(struct devlink_port *port,
                                     const u8 *hw_addr, int hw_addr_len,
                                     struct netlink_ext_ack *extack)
 {
-       struct mlx5_eswitch *esw;
+       struct mlx5_eswitch *esw = mlx5_devlink_eswitch_nocheck_get(port->devlink);
        u16 vport_num;
 
-       esw = mlx5_devlink_eswitch_get(port->devlink);
-       if (IS_ERR(esw)) {
-               NL_SET_ERR_MSG_MOD(extack, "Eswitch doesn't support set hw_addr");
-               return PTR_ERR(esw);
-       }
-
        vport_num = mlx5_esw_devlink_port_index_to_vport_num(port->index);
        return mlx5_eswitch_set_vport_mac(esw, vport_num, hw_addr);
 }
@@ -4277,13 +4268,9 @@ mlx5_devlink_port_fn_get_vport(struct devlink_port *port, struct mlx5_eswitch *e
 int mlx5_devlink_port_fn_migratable_get(struct devlink_port *port, bool *is_enabled,
                                        struct netlink_ext_ack *extack)
 {
-       struct mlx5_eswitch *esw;
+       struct mlx5_eswitch *esw = mlx5_devlink_eswitch_nocheck_get(port->devlink);
        struct mlx5_vport *vport;
 
-       esw = mlx5_devlink_eswitch_get(port->devlink);
-       if (IS_ERR(esw))
-               return PTR_ERR(esw);
-
        if (!MLX5_CAP_GEN(esw->dev, migration)) {
                NL_SET_ERR_MSG_MOD(extack, "Device doesn't support migration");
                return -EOPNOTSUPP;
@@ -4304,17 +4291,13 @@ int mlx5_devlink_port_fn_migratable_get(struct devlink_port *port, bool *is_enab
 int mlx5_devlink_port_fn_migratable_set(struct devlink_port *port, bool enable,
                                        struct netlink_ext_ack *extack)
 {
+       struct mlx5_eswitch *esw = mlx5_devlink_eswitch_nocheck_get(port->devlink);
        int query_out_sz = MLX5_ST_SZ_BYTES(query_hca_cap_out);
-       struct mlx5_eswitch *esw;
        struct mlx5_vport *vport;
        void *query_ctx;
        void *hca_caps;
        int err;
 
-       esw = mlx5_devlink_eswitch_get(port->devlink);
-       if (IS_ERR(esw))
-               return PTR_ERR(esw);
-
        if (!MLX5_CAP_GEN(esw->dev, migration)) {
                NL_SET_ERR_MSG_MOD(extack, "Device doesn't support migration");
                return -EOPNOTSUPP;
@@ -4368,13 +4351,9 @@ out:
 int mlx5_devlink_port_fn_roce_get(struct devlink_port *port, bool *is_enabled,
                                  struct netlink_ext_ack *extack)
 {
-       struct mlx5_eswitch *esw;
+       struct mlx5_eswitch *esw = mlx5_devlink_eswitch_nocheck_get(port->devlink);
        struct mlx5_vport *vport;
 
-       esw = mlx5_devlink_eswitch_get(port->devlink);
-       if (IS_ERR(esw))
-               return PTR_ERR(esw);
-
        vport = mlx5_devlink_port_fn_get_vport(port, esw);
        if (IS_ERR(vport)) {
                NL_SET_ERR_MSG_MOD(extack, "Invalid port");
@@ -4390,18 +4369,14 @@ int mlx5_devlink_port_fn_roce_get(struct devlink_port *port, bool *is_enabled,
 int mlx5_devlink_port_fn_roce_set(struct devlink_port *port, bool enable,
                                  struct netlink_ext_ack *extack)
 {
+       struct mlx5_eswitch *esw = mlx5_devlink_eswitch_nocheck_get(port->devlink);
        int query_out_sz = MLX5_ST_SZ_BYTES(query_hca_cap_out);
-       struct mlx5_eswitch *esw;
        struct mlx5_vport *vport;
        void *query_ctx;
        void *hca_caps;
        u16 vport_num;
        int err;
 
-       esw = mlx5_devlink_eswitch_get(port->devlink);
-       if (IS_ERR(esw))
-               return PTR_ERR(esw);
-
        vport = mlx5_devlink_port_fn_get_vport(port, esw);
        if (IS_ERR(vport)) {
                NL_SET_ERR_MSG_MOD(extack, "Invalid port");