Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
0002 /* Copyright (c) 2019 Mellanox Technologies. */
0003 
0004 #include "ecpf.h"
0005 
0006 bool mlx5_read_embedded_cpu(struct mlx5_core_dev *dev)
0007 {
0008     return (ioread32be(&dev->iseg->initializing) >> MLX5_ECPU_BIT_NUM) & 1;
0009 }
0010 
0011 static bool mlx5_ecpf_esw_admins_host_pf(const struct mlx5_core_dev *dev)
0012 {
0013     /* In separate host mode, PF enables itself.
0014      * When ECPF is eswitch manager, eswitch enables host PF after
0015      * eswitch is setup.
0016      */
0017     return mlx5_core_is_ecpf_esw_manager(dev);
0018 }
0019 
0020 int mlx5_cmd_host_pf_enable_hca(struct mlx5_core_dev *dev)
0021 {
0022     u32 out[MLX5_ST_SZ_DW(enable_hca_out)] = {};
0023     u32 in[MLX5_ST_SZ_DW(enable_hca_in)]   = {};
0024 
0025     MLX5_SET(enable_hca_in, in, opcode, MLX5_CMD_OP_ENABLE_HCA);
0026     MLX5_SET(enable_hca_in, in, function_id, 0);
0027     MLX5_SET(enable_hca_in, in, embedded_cpu_function, 0);
0028     return mlx5_cmd_exec(dev, &in, sizeof(in), &out, sizeof(out));
0029 }
0030 
0031 int mlx5_cmd_host_pf_disable_hca(struct mlx5_core_dev *dev)
0032 {
0033     u32 out[MLX5_ST_SZ_DW(disable_hca_out)] = {};
0034     u32 in[MLX5_ST_SZ_DW(disable_hca_in)]   = {};
0035 
0036     MLX5_SET(disable_hca_in, in, opcode, MLX5_CMD_OP_DISABLE_HCA);
0037     MLX5_SET(disable_hca_in, in, function_id, 0);
0038     MLX5_SET(disable_hca_in, in, embedded_cpu_function, 0);
0039     return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
0040 }
0041 
0042 static int mlx5_host_pf_init(struct mlx5_core_dev *dev)
0043 {
0044     int err;
0045 
0046     if (mlx5_ecpf_esw_admins_host_pf(dev))
0047         return 0;
0048 
0049     /* ECPF shall enable HCA for host PF in the same way a PF
0050      * does this for its VFs when ECPF is not a eswitch manager.
0051      */
0052     err = mlx5_cmd_host_pf_enable_hca(dev);
0053     if (err)
0054         mlx5_core_err(dev, "Failed to enable external host PF HCA err(%d)\n", err);
0055 
0056     return err;
0057 }
0058 
0059 static void mlx5_host_pf_cleanup(struct mlx5_core_dev *dev)
0060 {
0061     int err;
0062 
0063     if (mlx5_ecpf_esw_admins_host_pf(dev))
0064         return;
0065 
0066     err = mlx5_cmd_host_pf_disable_hca(dev);
0067     if (err) {
0068         mlx5_core_err(dev, "Failed to disable external host PF HCA err(%d)\n", err);
0069         return;
0070     }
0071 }
0072 
0073 int mlx5_ec_init(struct mlx5_core_dev *dev)
0074 {
0075     if (!mlx5_core_is_ecpf(dev))
0076         return 0;
0077 
0078     return mlx5_host_pf_init(dev);
0079 }
0080 
0081 void mlx5_ec_cleanup(struct mlx5_core_dev *dev)
0082 {
0083     int err;
0084 
0085     if (!mlx5_core_is_ecpf(dev))
0086         return;
0087 
0088     mlx5_host_pf_cleanup(dev);
0089 
0090     err = mlx5_wait_for_pages(dev, &dev->priv.host_pf_pages);
0091     if (err)
0092         mlx5_core_warn(dev, "Timeout reclaiming external host PF pages err(%d)\n", err);
0093 }