Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1 | /* |
Saeed Mahameed | 302bdf6 | 2015-04-02 17:07:29 +0300 | [diff] [blame] | 2 | * Copyright (c) 2013-2015, Mellanox Technologies. All rights reserved. |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3 | * |
| 4 | * This software is available to you under a choice of one of two |
| 5 | * licenses. You may choose to be licensed under the terms of the GNU |
| 6 | * General Public License (GPL) Version 2, available from the file |
| 7 | * COPYING in the main directory of this source tree, or the |
| 8 | * OpenIB.org BSD license below: |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or |
| 11 | * without modification, are permitted provided that the following |
| 12 | * conditions are met: |
| 13 | * |
| 14 | * - Redistributions of source code must retain the above |
| 15 | * copyright notice, this list of conditions and the following |
| 16 | * disclaimer. |
| 17 | * |
| 18 | * - Redistributions in binary form must reproduce the above |
| 19 | * copyright notice, this list of conditions and the following |
| 20 | * disclaimer in the documentation and/or other materials |
| 21 | * provided with the distribution. |
| 22 | * |
| 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 24 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 25 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 26 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 27 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 28 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 29 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 30 | * SOFTWARE. |
| 31 | */ |
| 32 | |
| 33 | #include <linux/kernel.h> |
| 34 | #include <linux/module.h> |
| 35 | #include <linux/mlx5/driver.h> |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 36 | #include "mlx5_core.h" |
| 37 | |
Michael Guralnik | a3cfdd3 | 2020-03-10 10:22:30 +0200 | [diff] [blame] | 38 | int mlx5_core_create_mkey(struct mlx5_core_dev *dev, |
| 39 | struct mlx5_core_mkey *mkey, |
| 40 | u32 *in, int inlen) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 41 | { |
Leon Romanovsky | adda874 | 2020-04-09 16:50:37 +0300 | [diff] [blame] | 42 | u32 lout[MLX5_ST_SZ_DW(create_mkey_out)] = {}; |
Saeed Mahameed | ec22eb5 | 2016-07-16 06:28:36 +0300 | [diff] [blame] | 43 | u32 mkey_index; |
| 44 | void *mkc; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 45 | int err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 46 | |
Saeed Mahameed | ec22eb5 | 2016-07-16 06:28:36 +0300 | [diff] [blame] | 47 | MLX5_SET(create_mkey_in, in, opcode, MLX5_CMD_OP_CREATE_MKEY); |
Saeed Mahameed | ec22eb5 | 2016-07-16 06:28:36 +0300 | [diff] [blame] | 48 | |
Saeed Mahameed | ec22eb5 | 2016-07-16 06:28:36 +0300 | [diff] [blame] | 49 | err = mlx5_cmd_exec(dev, in, inlen, lout, sizeof(lout)); |
Saeed Mahameed | ec22eb5 | 2016-07-16 06:28:36 +0300 | [diff] [blame] | 50 | if (err) |
Eli Cohen | 746b558 | 2013-10-23 09:53:14 +0300 | [diff] [blame] | 51 | return err; |
Eli Cohen | 746b558 | 2013-10-23 09:53:14 +0300 | [diff] [blame] | 52 | |
Saeed Mahameed | fc6a9f8 | 2020-03-10 10:22:28 +0200 | [diff] [blame] | 53 | mkc = MLX5_ADDR_OF(create_mkey_in, in, memory_key_mkey_entry); |
Saeed Mahameed | ec22eb5 | 2016-07-16 06:28:36 +0300 | [diff] [blame] | 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); |
Aya Levin | 0232fc2 | 2021-06-10 14:20:28 +0300 | [diff] [blame] | 57 | mkey->key = (u32)mlx5_mkey_variant(mkey->key) | mlx5_idx_to_mkey(mkey_index); |
Saeed Mahameed | ec22eb5 | 2016-07-16 06:28:36 +0300 | [diff] [blame] | 58 | mkey->pd = MLX5_GET(mkc, mkc, pd); |
Yishai Hadas | db72438 | 2021-02-02 09:13:09 +0200 | [diff] [blame] | 59 | init_waitqueue_head(&mkey->wait); |
Haggai Eran | b475598 | 2014-05-22 14:50:10 +0300 | [diff] [blame] | 60 | |
Nathan Chancellor | 826096d | 2020-03-16 13:34:52 -0700 | [diff] [blame] | 61 | mlx5_core_dbg(dev, "out 0x%x, mkey 0x%x\n", mkey_index, mkey->key); |
Jason Gunthorpe | 74bddb3 | 2019-10-09 13:09:24 -0300 | [diff] [blame] | 62 | return 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 63 | } |
| 64 | EXPORT_SYMBOL(mlx5_core_create_mkey); |
| 65 | |
Matan Barak | a606b0f | 2016-02-29 18:05:28 +0200 | [diff] [blame] | 66 | int mlx5_core_destroy_mkey(struct mlx5_core_dev *dev, |
| 67 | struct mlx5_core_mkey *mkey) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 68 | { |
Leon Romanovsky | adda874 | 2020-04-09 16:50:37 +0300 | [diff] [blame] | 69 | u32 in[MLX5_ST_SZ_DW(destroy_mkey_in)] = {}; |
Sagi Grimberg | 6ef07a9 | 2014-06-08 10:00:59 +0300 | [diff] [blame] | 70 | |
Saeed Mahameed | ec22eb5 | 2016-07-16 06:28:36 +0300 | [diff] [blame] | 71 | MLX5_SET(destroy_mkey_in, in, opcode, MLX5_CMD_OP_DESTROY_MKEY); |
| 72 | MLX5_SET(destroy_mkey_in, in, mkey_index, mlx5_mkey_to_idx(mkey->key)); |
Leon Romanovsky | adda874 | 2020-04-09 16:50:37 +0300 | [diff] [blame] | 73 | return mlx5_cmd_exec_in(dev, destroy_mkey, in); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 74 | } |
| 75 | EXPORT_SYMBOL(mlx5_core_destroy_mkey); |
| 76 | |
Matan Barak | a606b0f | 2016-02-29 18:05:28 +0200 | [diff] [blame] | 77 | int mlx5_core_query_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mkey *mkey, |
Saeed Mahameed | ec22eb5 | 2016-07-16 06:28:36 +0300 | [diff] [blame] | 78 | u32 *out, int outlen) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 79 | { |
Leon Romanovsky | adda874 | 2020-04-09 16:50:37 +0300 | [diff] [blame] | 80 | u32 in[MLX5_ST_SZ_DW(query_mkey_in)] = {}; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 81 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 82 | memset(out, 0, outlen); |
Saeed Mahameed | ec22eb5 | 2016-07-16 06:28:36 +0300 | [diff] [blame] | 83 | MLX5_SET(query_mkey_in, in, opcode, MLX5_CMD_OP_QUERY_MKEY); |
| 84 | MLX5_SET(query_mkey_in, in, mkey_index, mlx5_mkey_to_idx(mkey->key)); |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 85 | return mlx5_cmd_exec(dev, in, sizeof(in), out, outlen); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 86 | } |
| 87 | EXPORT_SYMBOL(mlx5_core_query_mkey); |
| 88 | |
Saeed Mahameed | ec22eb5 | 2016-07-16 06:28:36 +0300 | [diff] [blame] | 89 | static inline u32 mlx5_get_psv(u32 *out, int psv_index) |
| 90 | { |
| 91 | switch (psv_index) { |
| 92 | case 1: return MLX5_GET(create_psv_out, out, psv1_index); |
| 93 | case 2: return MLX5_GET(create_psv_out, out, psv2_index); |
| 94 | case 3: return MLX5_GET(create_psv_out, out, psv3_index); |
| 95 | default: return MLX5_GET(create_psv_out, out, psv0_index); |
| 96 | } |
| 97 | } |
| 98 | |
Sagi Grimberg | 3121e3c | 2014-02-23 14:19:06 +0200 | [diff] [blame] | 99 | int mlx5_core_create_psv(struct mlx5_core_dev *dev, u32 pdn, |
| 100 | int npsvs, u32 *sig_index) |
| 101 | { |
Leon Romanovsky | adda874 | 2020-04-09 16:50:37 +0300 | [diff] [blame] | 102 | u32 out[MLX5_ST_SZ_DW(create_psv_out)] = {}; |
| 103 | u32 in[MLX5_ST_SZ_DW(create_psv_in)] = {}; |
Sagi Grimberg | 3121e3c | 2014-02-23 14:19:06 +0200 | [diff] [blame] | 104 | int i, err; |
| 105 | |
| 106 | if (npsvs > MLX5_MAX_PSVS) |
| 107 | return -EINVAL; |
| 108 | |
Saeed Mahameed | ec22eb5 | 2016-07-16 06:28:36 +0300 | [diff] [blame] | 109 | MLX5_SET(create_psv_in, in, opcode, MLX5_CMD_OP_CREATE_PSV); |
| 110 | MLX5_SET(create_psv_in, in, pd, pdn); |
| 111 | MLX5_SET(create_psv_in, in, num_psv, npsvs); |
Sagi Grimberg | 3121e3c | 2014-02-23 14:19:06 +0200 | [diff] [blame] | 112 | |
Leon Romanovsky | adda874 | 2020-04-09 16:50:37 +0300 | [diff] [blame] | 113 | err = mlx5_cmd_exec_inout(dev, create_psv, in, out); |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 114 | if (err) |
Sagi Grimberg | 3121e3c | 2014-02-23 14:19:06 +0200 | [diff] [blame] | 115 | return err; |
Sagi Grimberg | 3121e3c | 2014-02-23 14:19:06 +0200 | [diff] [blame] | 116 | |
Sagi Grimberg | 3121e3c | 2014-02-23 14:19:06 +0200 | [diff] [blame] | 117 | for (i = 0; i < npsvs; i++) |
Saeed Mahameed | ec22eb5 | 2016-07-16 06:28:36 +0300 | [diff] [blame] | 118 | sig_index[i] = mlx5_get_psv(out, i); |
Sagi Grimberg | 3121e3c | 2014-02-23 14:19:06 +0200 | [diff] [blame] | 119 | |
| 120 | return err; |
| 121 | } |
| 122 | EXPORT_SYMBOL(mlx5_core_create_psv); |
| 123 | |
| 124 | int mlx5_core_destroy_psv(struct mlx5_core_dev *dev, int psv_num) |
| 125 | { |
Leon Romanovsky | adda874 | 2020-04-09 16:50:37 +0300 | [diff] [blame] | 126 | u32 in[MLX5_ST_SZ_DW(destroy_psv_in)] = {}; |
Sagi Grimberg | 3121e3c | 2014-02-23 14:19:06 +0200 | [diff] [blame] | 127 | |
Saeed Mahameed | ec22eb5 | 2016-07-16 06:28:36 +0300 | [diff] [blame] | 128 | MLX5_SET(destroy_psv_in, in, opcode, MLX5_CMD_OP_DESTROY_PSV); |
| 129 | MLX5_SET(destroy_psv_in, in, psvn, psv_num); |
Leon Romanovsky | adda874 | 2020-04-09 16:50:37 +0300 | [diff] [blame] | 130 | return mlx5_cmd_exec_in(dev, destroy_psv, in); |
Sagi Grimberg | 3121e3c | 2014-02-23 14:19:06 +0200 | [diff] [blame] | 131 | } |
| 132 | EXPORT_SYMBOL(mlx5_core_destroy_psv); |