Matan Barak | a0aa309 | 2017-08-03 16:06:55 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017, Mellanox Technologies inc. All rights reserved. |
| 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 | #ifndef _UVERBS_IOCTL_ |
| 34 | #define _UVERBS_IOCTL_ |
| 35 | |
| 36 | #include <rdma/uverbs_types.h> |
| 37 | |
| 38 | /* |
| 39 | * ======================================= |
| 40 | * Verbs action specifications |
| 41 | * ======================================= |
| 42 | */ |
| 43 | |
Matan Barak | f43dbeb | 2017-08-03 16:06:56 +0300 | [diff] [blame] | 44 | enum uverbs_attr_type { |
| 45 | UVERBS_ATTR_TYPE_NA, |
Matan Barak | fac9658 | 2017-08-03 16:06:57 +0300 | [diff] [blame^] | 46 | UVERBS_ATTR_TYPE_PTR_IN, |
| 47 | UVERBS_ATTR_TYPE_PTR_OUT, |
Matan Barak | f43dbeb | 2017-08-03 16:06:56 +0300 | [diff] [blame] | 48 | UVERBS_ATTR_TYPE_IDR, |
| 49 | UVERBS_ATTR_TYPE_FD, |
| 50 | }; |
| 51 | |
Matan Barak | a0aa309 | 2017-08-03 16:06:55 +0300 | [diff] [blame] | 52 | enum uverbs_obj_access { |
| 53 | UVERBS_ACCESS_READ, |
| 54 | UVERBS_ACCESS_WRITE, |
| 55 | UVERBS_ACCESS_NEW, |
| 56 | UVERBS_ACCESS_DESTROY |
| 57 | }; |
| 58 | |
Matan Barak | fac9658 | 2017-08-03 16:06:57 +0300 | [diff] [blame^] | 59 | enum { |
| 60 | UVERBS_ATTR_SPEC_F_MANDATORY = 1U << 0, |
| 61 | /* Support extending attributes by length */ |
| 62 | UVERBS_ATTR_SPEC_F_MIN_SZ = 1U << 1, |
| 63 | }; |
| 64 | |
Matan Barak | f43dbeb | 2017-08-03 16:06:56 +0300 | [diff] [blame] | 65 | struct uverbs_attr_spec { |
| 66 | enum uverbs_attr_type type; |
Matan Barak | fac9658 | 2017-08-03 16:06:57 +0300 | [diff] [blame^] | 67 | union { |
| 68 | u16 len; |
| 69 | struct { |
| 70 | /* |
| 71 | * higher bits mean the namespace and lower bits mean |
| 72 | * the type id within the namespace. |
| 73 | */ |
| 74 | u16 obj_type; |
| 75 | u8 access; |
| 76 | } obj; |
| 77 | }; |
| 78 | /* Combination of bits from enum UVERBS_ATTR_SPEC_F_XXXX */ |
| 79 | u8 flags; |
Matan Barak | f43dbeb | 2017-08-03 16:06:56 +0300 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | struct uverbs_attr_spec_hash { |
| 83 | size_t num_attrs; |
Matan Barak | fac9658 | 2017-08-03 16:06:57 +0300 | [diff] [blame^] | 84 | unsigned long *mandatory_attrs_bitmask; |
Matan Barak | f43dbeb | 2017-08-03 16:06:56 +0300 | [diff] [blame] | 85 | struct uverbs_attr_spec attrs[0]; |
| 86 | }; |
| 87 | |
Matan Barak | fac9658 | 2017-08-03 16:06:57 +0300 | [diff] [blame^] | 88 | struct uverbs_attr_bundle; |
| 89 | struct ib_uverbs_file; |
| 90 | |
| 91 | enum { |
| 92 | /* |
| 93 | * Action marked with this flag creates a context (or root for all |
| 94 | * objects). |
| 95 | */ |
| 96 | UVERBS_ACTION_FLAG_CREATE_ROOT = 1U << 0, |
| 97 | }; |
| 98 | |
| 99 | struct uverbs_method_spec { |
| 100 | /* Combination of bits from enum UVERBS_ACTION_FLAG_XXXX */ |
| 101 | u32 flags; |
| 102 | size_t num_buckets; |
| 103 | size_t num_child_attrs; |
| 104 | int (*handler)(struct ib_device *ib_dev, struct ib_uverbs_file *ufile, |
| 105 | struct uverbs_attr_bundle *ctx); |
| 106 | struct uverbs_attr_spec_hash *attr_buckets[0]; |
| 107 | }; |
| 108 | |
| 109 | struct uverbs_method_spec_hash { |
| 110 | size_t num_methods; |
| 111 | struct uverbs_method_spec *methods[0]; |
| 112 | }; |
| 113 | |
| 114 | struct uverbs_object_spec { |
| 115 | const struct uverbs_obj_type *type_attrs; |
| 116 | size_t num_buckets; |
| 117 | struct uverbs_method_spec_hash *method_buckets[0]; |
| 118 | }; |
| 119 | |
| 120 | struct uverbs_object_spec_hash { |
| 121 | size_t num_objects; |
| 122 | struct uverbs_object_spec *objects[0]; |
| 123 | }; |
| 124 | |
| 125 | struct uverbs_root_spec { |
| 126 | size_t num_buckets; |
| 127 | struct uverbs_object_spec_hash *object_buckets[0]; |
| 128 | }; |
| 129 | |
| 130 | /* ================================================= |
| 131 | * Parsing infrastructure |
| 132 | * ================================================= |
| 133 | */ |
| 134 | |
| 135 | struct uverbs_ptr_attr { |
| 136 | union { |
| 137 | u64 data; |
| 138 | void __user *ptr; |
| 139 | }; |
| 140 | u16 len; |
| 141 | /* Combination of bits from enum UVERBS_ATTR_F_XXXX */ |
| 142 | u16 flags; |
| 143 | }; |
| 144 | |
Matan Barak | f43dbeb | 2017-08-03 16:06:56 +0300 | [diff] [blame] | 145 | struct uverbs_obj_attr { |
Matan Barak | fac9658 | 2017-08-03 16:06:57 +0300 | [diff] [blame^] | 146 | /* pointer to the kernel descriptor -> type, access, etc */ |
| 147 | const struct uverbs_obj_type *type; |
Matan Barak | f43dbeb | 2017-08-03 16:06:56 +0300 | [diff] [blame] | 148 | struct ib_uobject *uobject; |
Matan Barak | fac9658 | 2017-08-03 16:06:57 +0300 | [diff] [blame^] | 149 | /* fd or id in idr of this object */ |
| 150 | int id; |
Matan Barak | f43dbeb | 2017-08-03 16:06:56 +0300 | [diff] [blame] | 151 | }; |
| 152 | |
| 153 | struct uverbs_attr { |
Matan Barak | fac9658 | 2017-08-03 16:06:57 +0300 | [diff] [blame^] | 154 | /* |
| 155 | * pointer to the user-space given attribute, in order to write the |
| 156 | * new uobject's id or update flags. |
| 157 | */ |
| 158 | struct ib_uverbs_attr __user *uattr; |
| 159 | union { |
| 160 | struct uverbs_ptr_attr ptr_attr; |
| 161 | struct uverbs_obj_attr obj_attr; |
| 162 | }; |
Matan Barak | f43dbeb | 2017-08-03 16:06:56 +0300 | [diff] [blame] | 163 | }; |
| 164 | |
| 165 | struct uverbs_attr_bundle_hash { |
| 166 | /* if bit i is set, it means attrs[i] contains valid information */ |
| 167 | unsigned long *valid_bitmap; |
| 168 | size_t num_attrs; |
| 169 | /* |
| 170 | * arrays of attributes, each element corresponds to the specification |
| 171 | * of the attribute in the same index. |
| 172 | */ |
| 173 | struct uverbs_attr *attrs; |
| 174 | }; |
| 175 | |
| 176 | struct uverbs_attr_bundle { |
| 177 | size_t num_buckets; |
| 178 | struct uverbs_attr_bundle_hash hash[]; |
| 179 | }; |
| 180 | |
| 181 | static inline bool uverbs_attr_is_valid_in_hash(const struct uverbs_attr_bundle_hash *attrs_hash, |
| 182 | unsigned int idx) |
| 183 | { |
| 184 | return test_bit(idx, attrs_hash->valid_bitmap); |
| 185 | } |
| 186 | |
Matan Barak | a0aa309 | 2017-08-03 16:06:55 +0300 | [diff] [blame] | 187 | #endif |
| 188 | |