Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (c) 2013-2015, Mellanox Technologies. All rights reserved.
0003  *
0004  * This software is available to you under a choice of one of two
0005  * licenses.  You may choose to be licensed under the terms of the GNU
0006  * General Public License (GPL) Version 2, available from the file
0007  * COPYING in the main directory of this source tree, or the
0008  * OpenIB.org BSD license below:
0009  *
0010  *     Redistribution and use in source and binary forms, with or
0011  *     without modification, are permitted provided that the following
0012  *     conditions are met:
0013  *
0014  *      - Redistributions of source code must retain the above
0015  *        copyright notice, this list of conditions and the following
0016  *        disclaimer.
0017  *
0018  *      - Redistributions in binary form must reproduce the above
0019  *        copyright notice, this list of conditions and the following
0020  *        disclaimer in the documentation and/or other materials
0021  *        provided with the distribution.
0022  *
0023  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0024  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0025  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
0026  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
0027  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
0028  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
0029  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0030  * SOFTWARE.
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);