0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 #include <linux/kernel.h>
0034 #include <linux/mlx5/driver.h>
0035 #include "mlx5_core.h"
0036
0037 int mlx5_core_create_mkey(struct mlx5_core_dev *dev, u32 *mkey, u32 *in,
0038 int inlen)
0039 {
0040 u32 lout[MLX5_ST_SZ_DW(create_mkey_out)] = {};
0041 u32 mkey_index;
0042 int err;
0043
0044 MLX5_SET(create_mkey_in, in, opcode, MLX5_CMD_OP_CREATE_MKEY);
0045
0046 err = mlx5_cmd_exec(dev, in, inlen, lout, sizeof(lout));
0047 if (err)
0048 return err;
0049
0050 mkey_index = MLX5_GET(create_mkey_out, lout, mkey_index);
0051 *mkey = MLX5_GET(create_mkey_in, in, memory_key_mkey_entry.mkey_7_0) |
0052 mlx5_idx_to_mkey(mkey_index);
0053
0054 mlx5_core_dbg(dev, "out 0x%x, mkey 0x%x\n", mkey_index, *mkey);
0055 return 0;
0056 }
0057 EXPORT_SYMBOL(mlx5_core_create_mkey);
0058
0059 int mlx5_core_destroy_mkey(struct mlx5_core_dev *dev, u32 mkey)
0060 {
0061 u32 in[MLX5_ST_SZ_DW(destroy_mkey_in)] = {};
0062
0063 MLX5_SET(destroy_mkey_in, in, opcode, MLX5_CMD_OP_DESTROY_MKEY);
0064 MLX5_SET(destroy_mkey_in, in, mkey_index, mlx5_mkey_to_idx(mkey));
0065 return mlx5_cmd_exec_in(dev, destroy_mkey, in);
0066 }
0067 EXPORT_SYMBOL(mlx5_core_destroy_mkey);
0068
0069 int mlx5_core_query_mkey(struct mlx5_core_dev *dev, u32 mkey, u32 *out,
0070 int outlen)
0071 {
0072 u32 in[MLX5_ST_SZ_DW(query_mkey_in)] = {};
0073
0074 memset(out, 0, outlen);
0075 MLX5_SET(query_mkey_in, in, opcode, MLX5_CMD_OP_QUERY_MKEY);
0076 MLX5_SET(query_mkey_in, in, mkey_index, mlx5_mkey_to_idx(mkey));
0077 return mlx5_cmd_exec(dev, in, sizeof(in), out, outlen);
0078 }
0079 EXPORT_SYMBOL(mlx5_core_query_mkey);
0080
0081 static inline u32 mlx5_get_psv(u32 *out, int psv_index)
0082 {
0083 switch (psv_index) {
0084 case 1: return MLX5_GET(create_psv_out, out, psv1_index);
0085 case 2: return MLX5_GET(create_psv_out, out, psv2_index);
0086 case 3: return MLX5_GET(create_psv_out, out, psv3_index);
0087 default: return MLX5_GET(create_psv_out, out, psv0_index);
0088 }
0089 }
0090
0091 int mlx5_core_create_psv(struct mlx5_core_dev *dev, u32 pdn,
0092 int npsvs, u32 *sig_index)
0093 {
0094 u32 out[MLX5_ST_SZ_DW(create_psv_out)] = {};
0095 u32 in[MLX5_ST_SZ_DW(create_psv_in)] = {};
0096 int i, err;
0097
0098 if (npsvs > MLX5_MAX_PSVS)
0099 return -EINVAL;
0100
0101 MLX5_SET(create_psv_in, in, opcode, MLX5_CMD_OP_CREATE_PSV);
0102 MLX5_SET(create_psv_in, in, pd, pdn);
0103 MLX5_SET(create_psv_in, in, num_psv, npsvs);
0104
0105 err = mlx5_cmd_exec_inout(dev, create_psv, in, out);
0106 if (err)
0107 return err;
0108
0109 for (i = 0; i < npsvs; i++)
0110 sig_index[i] = mlx5_get_psv(out, i);
0111
0112 return err;
0113 }
0114 EXPORT_SYMBOL(mlx5_core_create_psv);
0115
0116 int mlx5_core_destroy_psv(struct mlx5_core_dev *dev, int psv_num)
0117 {
0118 u32 in[MLX5_ST_SZ_DW(destroy_psv_in)] = {};
0119
0120 MLX5_SET(destroy_psv_in, in, opcode, MLX5_CMD_OP_DESTROY_PSV);
0121 MLX5_SET(destroy_psv_in, in, psvn, psv_num);
0122 return mlx5_cmd_exec_in(dev, destroy_psv, in);
0123 }
0124 EXPORT_SYMBOL(mlx5_core_destroy_psv);