| .. | .. |
|---|
| 33 | 33 | #include <linux/kernel.h> |
|---|
| 34 | 34 | #include <linux/module.h> |
|---|
| 35 | 35 | #include <linux/mlx5/driver.h> |
|---|
| 36 | | -#include <linux/mlx5/cmd.h> |
|---|
| 37 | 36 | #include "mlx5_core.h" |
|---|
| 38 | | - |
|---|
| 39 | | -void mlx5_init_mkey_table(struct mlx5_core_dev *dev) |
|---|
| 40 | | -{ |
|---|
| 41 | | - struct mlx5_mkey_table *table = &dev->priv.mkey_table; |
|---|
| 42 | | - |
|---|
| 43 | | - memset(table, 0, sizeof(*table)); |
|---|
| 44 | | - rwlock_init(&table->lock); |
|---|
| 45 | | - INIT_RADIX_TREE(&table->tree, GFP_ATOMIC); |
|---|
| 46 | | -} |
|---|
| 47 | | - |
|---|
| 48 | | -void mlx5_cleanup_mkey_table(struct mlx5_core_dev *dev) |
|---|
| 49 | | -{ |
|---|
| 50 | | -} |
|---|
| 51 | | - |
|---|
| 52 | | -int mlx5_core_create_mkey_cb(struct mlx5_core_dev *dev, |
|---|
| 53 | | - struct mlx5_core_mkey *mkey, |
|---|
| 54 | | - u32 *in, int inlen, |
|---|
| 55 | | - u32 *out, int outlen, |
|---|
| 56 | | - mlx5_cmd_cbk_t callback, void *context) |
|---|
| 57 | | -{ |
|---|
| 58 | | - struct mlx5_mkey_table *table = &dev->priv.mkey_table; |
|---|
| 59 | | - u32 lout[MLX5_ST_SZ_DW(create_mkey_out)] = {0}; |
|---|
| 60 | | - u32 mkey_index; |
|---|
| 61 | | - void *mkc; |
|---|
| 62 | | - int err; |
|---|
| 63 | | - u8 key; |
|---|
| 64 | | - |
|---|
| 65 | | - spin_lock_irq(&dev->priv.mkey_lock); |
|---|
| 66 | | - key = dev->priv.mkey_key++; |
|---|
| 67 | | - spin_unlock_irq(&dev->priv.mkey_lock); |
|---|
| 68 | | - mkc = MLX5_ADDR_OF(create_mkey_in, in, memory_key_mkey_entry); |
|---|
| 69 | | - |
|---|
| 70 | | - MLX5_SET(create_mkey_in, in, opcode, MLX5_CMD_OP_CREATE_MKEY); |
|---|
| 71 | | - MLX5_SET(mkc, mkc, mkey_7_0, key); |
|---|
| 72 | | - |
|---|
| 73 | | - if (callback) |
|---|
| 74 | | - return mlx5_cmd_exec_cb(dev, in, inlen, out, outlen, |
|---|
| 75 | | - callback, context); |
|---|
| 76 | | - |
|---|
| 77 | | - err = mlx5_cmd_exec(dev, in, inlen, lout, sizeof(lout)); |
|---|
| 78 | | - if (err) |
|---|
| 79 | | - return err; |
|---|
| 80 | | - |
|---|
| 81 | | - mkey_index = MLX5_GET(create_mkey_out, lout, mkey_index); |
|---|
| 82 | | - mkey->iova = MLX5_GET64(mkc, mkc, start_addr); |
|---|
| 83 | | - mkey->size = MLX5_GET64(mkc, mkc, len); |
|---|
| 84 | | - mkey->key = mlx5_idx_to_mkey(mkey_index) | key; |
|---|
| 85 | | - mkey->pd = MLX5_GET(mkc, mkc, pd); |
|---|
| 86 | | - |
|---|
| 87 | | - mlx5_core_dbg(dev, "out 0x%x, key 0x%x, mkey 0x%x\n", |
|---|
| 88 | | - mkey_index, key, mkey->key); |
|---|
| 89 | | - |
|---|
| 90 | | - /* connect to mkey tree */ |
|---|
| 91 | | - write_lock_irq(&table->lock); |
|---|
| 92 | | - err = radix_tree_insert(&table->tree, mlx5_base_mkey(mkey->key), mkey); |
|---|
| 93 | | - write_unlock_irq(&table->lock); |
|---|
| 94 | | - if (err) { |
|---|
| 95 | | - mlx5_core_warn(dev, "failed radix tree insert of mkey 0x%x, %d\n", |
|---|
| 96 | | - mlx5_base_mkey(mkey->key), err); |
|---|
| 97 | | - mlx5_core_destroy_mkey(dev, mkey); |
|---|
| 98 | | - } |
|---|
| 99 | | - |
|---|
| 100 | | - return err; |
|---|
| 101 | | -} |
|---|
| 102 | | -EXPORT_SYMBOL(mlx5_core_create_mkey_cb); |
|---|
| 103 | 37 | |
|---|
| 104 | 38 | int mlx5_core_create_mkey(struct mlx5_core_dev *dev, |
|---|
| 105 | 39 | struct mlx5_core_mkey *mkey, |
|---|
| 106 | 40 | u32 *in, int inlen) |
|---|
| 107 | 41 | { |
|---|
| 108 | | - return mlx5_core_create_mkey_cb(dev, mkey, in, inlen, |
|---|
| 109 | | - NULL, 0, NULL, NULL); |
|---|
| 42 | + u32 lout[MLX5_ST_SZ_DW(create_mkey_out)] = {}; |
|---|
| 43 | + u32 mkey_index; |
|---|
| 44 | + void *mkc; |
|---|
| 45 | + int err; |
|---|
| 46 | + |
|---|
| 47 | + MLX5_SET(create_mkey_in, in, opcode, MLX5_CMD_OP_CREATE_MKEY); |
|---|
| 48 | + |
|---|
| 49 | + err = mlx5_cmd_exec(dev, in, inlen, lout, sizeof(lout)); |
|---|
| 50 | + if (err) |
|---|
| 51 | + return err; |
|---|
| 52 | + |
|---|
| 53 | + mkc = MLX5_ADDR_OF(create_mkey_in, in, memory_key_mkey_entry); |
|---|
| 54 | + mkey_index = MLX5_GET(create_mkey_out, lout, mkey_index); |
|---|
| 55 | + mkey->iova = MLX5_GET64(mkc, mkc, start_addr); |
|---|
| 56 | + mkey->size = MLX5_GET64(mkc, mkc, len); |
|---|
| 57 | + mkey->key = (u32)mlx5_mkey_variant(mkey->key) | mlx5_idx_to_mkey(mkey_index); |
|---|
| 58 | + mkey->pd = MLX5_GET(mkc, mkc, pd); |
|---|
| 59 | + |
|---|
| 60 | + mlx5_core_dbg(dev, "out 0x%x, mkey 0x%x\n", mkey_index, mkey->key); |
|---|
| 61 | + return 0; |
|---|
| 110 | 62 | } |
|---|
| 111 | 63 | EXPORT_SYMBOL(mlx5_core_create_mkey); |
|---|
| 112 | 64 | |
|---|
| 113 | 65 | int mlx5_core_destroy_mkey(struct mlx5_core_dev *dev, |
|---|
| 114 | 66 | struct mlx5_core_mkey *mkey) |
|---|
| 115 | 67 | { |
|---|
| 116 | | - struct mlx5_mkey_table *table = &dev->priv.mkey_table; |
|---|
| 117 | | - u32 out[MLX5_ST_SZ_DW(destroy_mkey_out)] = {0}; |
|---|
| 118 | | - u32 in[MLX5_ST_SZ_DW(destroy_mkey_in)] = {0}; |
|---|
| 119 | | - struct mlx5_core_mkey *deleted_mkey; |
|---|
| 120 | | - unsigned long flags; |
|---|
| 121 | | - |
|---|
| 122 | | - write_lock_irqsave(&table->lock, flags); |
|---|
| 123 | | - deleted_mkey = radix_tree_delete(&table->tree, mlx5_base_mkey(mkey->key)); |
|---|
| 124 | | - write_unlock_irqrestore(&table->lock, flags); |
|---|
| 125 | | - if (!deleted_mkey) { |
|---|
| 126 | | - mlx5_core_dbg(dev, "failed radix tree delete of mkey 0x%x\n", |
|---|
| 127 | | - mlx5_base_mkey(mkey->key)); |
|---|
| 128 | | - return -ENOENT; |
|---|
| 129 | | - } |
|---|
| 68 | + u32 in[MLX5_ST_SZ_DW(destroy_mkey_in)] = {}; |
|---|
| 130 | 69 | |
|---|
| 131 | 70 | MLX5_SET(destroy_mkey_in, in, opcode, MLX5_CMD_OP_DESTROY_MKEY); |
|---|
| 132 | 71 | MLX5_SET(destroy_mkey_in, in, mkey_index, mlx5_mkey_to_idx(mkey->key)); |
|---|
| 133 | | - return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); |
|---|
| 72 | + return mlx5_cmd_exec_in(dev, destroy_mkey, in); |
|---|
| 134 | 73 | } |
|---|
| 135 | 74 | EXPORT_SYMBOL(mlx5_core_destroy_mkey); |
|---|
| 136 | 75 | |
|---|
| 137 | 76 | int mlx5_core_query_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mkey *mkey, |
|---|
| 138 | 77 | u32 *out, int outlen) |
|---|
| 139 | 78 | { |
|---|
| 140 | | - u32 in[MLX5_ST_SZ_DW(query_mkey_in)] = {0}; |
|---|
| 79 | + u32 in[MLX5_ST_SZ_DW(query_mkey_in)] = {}; |
|---|
| 141 | 80 | |
|---|
| 142 | 81 | memset(out, 0, outlen); |
|---|
| 143 | 82 | MLX5_SET(query_mkey_in, in, opcode, MLX5_CMD_OP_QUERY_MKEY); |
|---|
| .. | .. |
|---|
| 159 | 98 | int mlx5_core_create_psv(struct mlx5_core_dev *dev, u32 pdn, |
|---|
| 160 | 99 | int npsvs, u32 *sig_index) |
|---|
| 161 | 100 | { |
|---|
| 162 | | - u32 out[MLX5_ST_SZ_DW(create_psv_out)] = {0}; |
|---|
| 163 | | - u32 in[MLX5_ST_SZ_DW(create_psv_in)] = {0}; |
|---|
| 101 | + u32 out[MLX5_ST_SZ_DW(create_psv_out)] = {}; |
|---|
| 102 | + u32 in[MLX5_ST_SZ_DW(create_psv_in)] = {}; |
|---|
| 164 | 103 | int i, err; |
|---|
| 165 | 104 | |
|---|
| 166 | 105 | if (npsvs > MLX5_MAX_PSVS) |
|---|
| .. | .. |
|---|
| 170 | 109 | MLX5_SET(create_psv_in, in, pd, pdn); |
|---|
| 171 | 110 | MLX5_SET(create_psv_in, in, num_psv, npsvs); |
|---|
| 172 | 111 | |
|---|
| 173 | | - err = mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); |
|---|
| 112 | + err = mlx5_cmd_exec_inout(dev, create_psv, in, out); |
|---|
| 174 | 113 | if (err) |
|---|
| 175 | 114 | return err; |
|---|
| 176 | 115 | |
|---|
| .. | .. |
|---|
| 183 | 122 | |
|---|
| 184 | 123 | int mlx5_core_destroy_psv(struct mlx5_core_dev *dev, int psv_num) |
|---|
| 185 | 124 | { |
|---|
| 186 | | - u32 out[MLX5_ST_SZ_DW(destroy_psv_out)] = {0}; |
|---|
| 187 | | - u32 in[MLX5_ST_SZ_DW(destroy_psv_in)] = {0}; |
|---|
| 125 | + u32 in[MLX5_ST_SZ_DW(destroy_psv_in)] = {}; |
|---|
| 188 | 126 | |
|---|
| 189 | 127 | MLX5_SET(destroy_psv_in, in, opcode, MLX5_CMD_OP_DESTROY_PSV); |
|---|
| 190 | 128 | MLX5_SET(destroy_psv_in, in, psvn, psv_num); |
|---|
| 191 | | - return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); |
|---|
| 129 | + return mlx5_cmd_exec_in(dev, destroy_psv, in); |
|---|
| 192 | 130 | } |
|---|
| 193 | 131 | EXPORT_SYMBOL(mlx5_core_destroy_psv); |
|---|