2017-04-04 13:31:42 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2005 Topspin Communications. All rights reserved.
|
|
|
|
* Copyright (c) 2005, 2006 Cisco Systems. All rights reserved.
|
|
|
|
* Copyright (c) 2005-2017 Mellanox Technologies. All rights reserved.
|
|
|
|
* Copyright (c) 2005 Voltaire, Inc. All rights reserved.
|
|
|
|
* Copyright (c) 2005 PathScale, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* This software is available to you under a choice of one of two
|
|
|
|
* licenses. You may choose to be licensed under the terms of the GNU
|
|
|
|
* General Public License (GPL) Version 2, available from the file
|
|
|
|
* COPYING in the main directory of this source tree, or the
|
|
|
|
* OpenIB.org BSD license below:
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or
|
|
|
|
* without modification, are permitted provided that the following
|
|
|
|
* conditions are met:
|
|
|
|
*
|
|
|
|
* - Redistributions of source code must retain the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer.
|
|
|
|
*
|
|
|
|
* - Redistributions in binary form must reproduce the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer in the documentation and/or other materials
|
|
|
|
* provided with the distribution.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef RDMA_CORE_H
|
|
|
|
#define RDMA_CORE_H
|
|
|
|
|
|
|
|
#include <linux/idr.h>
|
|
|
|
#include <rdma/uverbs_types.h>
|
2017-08-03 16:06:55 +03:00
|
|
|
#include <rdma/uverbs_ioctl.h>
|
2017-04-04 13:31:42 +03:00
|
|
|
#include <rdma/ib_verbs.h>
|
|
|
|
#include <linux/mutex.h>
|
|
|
|
|
2018-08-10 05:14:36 +03:00
|
|
|
struct ib_uverbs_device;
|
|
|
|
|
2018-07-11 05:55:19 +03:00
|
|
|
void uverbs_destroy_ufile_hw(struct ib_uverbs_file *ufile,
|
|
|
|
enum rdma_remove_reason reason);
|
2017-04-04 13:31:42 +03:00
|
|
|
|
2019-03-31 19:10:04 +03:00
|
|
|
int uobj_destroy(struct ib_uobject *uobj, struct uverbs_attr_bundle *attrs);
|
2018-07-26 06:40:14 +03:00
|
|
|
|
2017-08-03 16:06:55 +03:00
|
|
|
/*
|
2018-07-04 11:32:08 +03:00
|
|
|
* Get an ib_uobject that corresponds to the given id from ufile, assuming
|
2017-08-03 16:06:55 +03:00
|
|
|
* the object is from the given type. Lock it to the required access when
|
|
|
|
* applicable.
|
|
|
|
* This function could create (access == NEW), destroy (access == DESTROY)
|
|
|
|
* or unlock (access == READ || access == WRITE) objects if required.
|
IB/core: Add support to finalize objects in one transaction
The new ioctl based infrastructure either commits or rollbacks
all objects of the method as one transaction. In order to do
that, we introduce a notion of dealing with a collection of
objects that are related to a specific method.
This also requires adding a notion of a method and attribute.
A method contains a hash of attributes, where each bucket
contains several attributes. The attributes are hashed according
to their namespace which resides in the four upper bits of the id.
For example, an object could be a CQ, which has an action of CREATE_CQ.
This action has multiple attributes. For example, the CQ's new handle
and the comp_channel. Each layer in this hierarchy - objects, methods
and attributes is split into namespaces. The basic example for that is
one namespace representing the default entities and another one
representing the driver specific entities.
When declaring these methods and attributes, we actually declare
their specifications. When a method is executed, we actually
allocates some space to hold auxiliary information. This auxiliary
information contains meta-data about the required objects, such
as pointers to their type information, pointers to the uobjects
themselves (if exist), etc.
The specification, along with the auxiliary information we allocated
and filled is given to the finalize_objects function.
Signed-off-by: Matan Barak <matanb@mellanox.com>
Reviewed-by: Yishai Hadas <yishaih@mellanox.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
2017-08-03 16:06:56 +03:00
|
|
|
* The action will be finalized only when uverbs_finalize_object or
|
|
|
|
* uverbs_finalize_objects are called.
|
2017-08-03 16:06:55 +03:00
|
|
|
*/
|
2018-07-04 11:32:08 +03:00
|
|
|
struct ib_uobject *
|
2019-03-31 19:10:03 +03:00
|
|
|
uverbs_get_uobject_from_file(u16 object_id, enum uverbs_obj_access access,
|
|
|
|
s64 id, struct uverbs_attr_bundle *attrs);
|
2018-07-04 11:32:08 +03:00
|
|
|
|
2020-01-08 20:21:56 +03:00
|
|
|
void uverbs_finalize_object(struct ib_uobject *uobj,
|
2020-05-19 10:27:05 +03:00
|
|
|
enum uverbs_obj_access access, bool hw_obj_valid,
|
|
|
|
bool commit, struct uverbs_attr_bundle *attrs);
|
2017-08-03 16:06:55 +03:00
|
|
|
|
2019-01-11 09:21:44 +03:00
|
|
|
int uverbs_output_written(const struct uverbs_attr_bundle *bundle, size_t idx);
|
|
|
|
|
2018-07-26 06:40:20 +03:00
|
|
|
void setup_ufile_idr_uobject(struct ib_uverbs_file *ufile);
|
|
|
|
void release_ufile_idr_uobject(struct ib_uverbs_file *ufile);
|
|
|
|
|
2019-05-21 20:55:22 +03:00
|
|
|
struct ib_udata *uverbs_get_cleared_udata(struct uverbs_attr_bundle *attrs);
|
|
|
|
|
2018-08-10 05:14:36 +03:00
|
|
|
/*
|
|
|
|
* This is the runtime description of the uverbs API, used by the syscall
|
|
|
|
* machinery to validate and dispatch calls.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Depending on ID the slot pointer in the radix tree points at one of these
|
|
|
|
* structs.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct uverbs_api_ioctl_method {
|
2018-11-25 21:51:15 +03:00
|
|
|
int(__rcu *handler)(struct uverbs_attr_bundle *attrs);
|
2018-08-10 05:14:36 +03:00
|
|
|
DECLARE_BITMAP(attr_mandatory, UVERBS_API_ATTR_BKEY_LEN);
|
2018-08-10 05:14:42 +03:00
|
|
|
u16 bundle_size;
|
|
|
|
u8 use_stack:1;
|
2018-08-10 05:14:36 +03:00
|
|
|
u8 driver_method:1;
|
2018-11-12 23:59:52 +03:00
|
|
|
u8 disabled:1;
|
2018-11-25 21:51:20 +03:00
|
|
|
u8 has_udata:1;
|
2018-08-10 05:14:36 +03:00
|
|
|
u8 key_bitmap_len;
|
|
|
|
u8 destroy_bkey;
|
|
|
|
};
|
|
|
|
|
2018-11-12 23:59:55 +03:00
|
|
|
struct uverbs_api_write_method {
|
2018-11-25 21:58:45 +03:00
|
|
|
int (*handler)(struct uverbs_attr_bundle *attrs);
|
2018-11-12 23:59:55 +03:00
|
|
|
u8 disabled:1;
|
|
|
|
u8 is_ex:1;
|
2018-11-25 21:51:16 +03:00
|
|
|
u8 has_udata:1;
|
|
|
|
u8 has_resp:1;
|
|
|
|
u8 req_size;
|
|
|
|
u8 resp_size;
|
2018-11-12 23:59:55 +03:00
|
|
|
};
|
|
|
|
|
2018-08-10 05:14:36 +03:00
|
|
|
struct uverbs_api_attr {
|
|
|
|
struct uverbs_attr_spec spec;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct uverbs_api {
|
|
|
|
/* radix tree contains struct uverbs_api_* pointers */
|
|
|
|
struct radix_tree_root radix;
|
|
|
|
enum rdma_driver_id driver_id;
|
2018-11-12 23:59:55 +03:00
|
|
|
|
|
|
|
unsigned int num_write;
|
|
|
|
unsigned int num_write_ex;
|
|
|
|
struct uverbs_api_write_method notsupp_method;
|
|
|
|
const struct uverbs_api_write_method **write_methods;
|
|
|
|
const struct uverbs_api_write_method **write_ex_methods;
|
2018-08-10 05:14:36 +03:00
|
|
|
};
|
|
|
|
|
2018-11-26 09:28:33 +03:00
|
|
|
/*
|
|
|
|
* Get an uverbs_api_object that corresponds to the given object_id.
|
|
|
|
* Note:
|
|
|
|
* -ENOMSG means that any object is allowed to match during lookup.
|
|
|
|
*/
|
2018-08-10 05:14:36 +03:00
|
|
|
static inline const struct uverbs_api_object *
|
|
|
|
uapi_get_object(struct uverbs_api *uapi, u16 object_id)
|
|
|
|
{
|
2018-11-26 09:28:33 +03:00
|
|
|
const struct uverbs_api_object *res;
|
|
|
|
|
|
|
|
if (object_id == UVERBS_IDR_ANY_OBJECT)
|
|
|
|
return ERR_PTR(-ENOMSG);
|
|
|
|
|
|
|
|
res = radix_tree_lookup(&uapi->radix, uapi_key_obj(object_id));
|
|
|
|
if (!res)
|
|
|
|
return ERR_PTR(-ENOENT);
|
|
|
|
|
|
|
|
return res;
|
2018-08-10 05:14:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
char *uapi_key_format(char *S, unsigned int key);
|
2018-11-12 23:59:52 +03:00
|
|
|
struct uverbs_api *uverbs_alloc_api(struct ib_device *ibdev);
|
2018-08-10 05:14:36 +03:00
|
|
|
void uverbs_disassociate_api_pre(struct ib_uverbs_device *uverbs_dev);
|
|
|
|
void uverbs_disassociate_api(struct uverbs_api *uapi);
|
|
|
|
void uverbs_destroy_api(struct uverbs_api *uapi);
|
2018-08-10 05:14:42 +03:00
|
|
|
void uapi_compute_bundle_size(struct uverbs_api_ioctl_method *method_elm,
|
|
|
|
unsigned int num_attrs);
|
2018-09-16 20:43:08 +03:00
|
|
|
void uverbs_user_mmap_disassociate(struct ib_uverbs_file *ufile);
|
2018-08-10 05:14:36 +03:00
|
|
|
|
2020-01-08 20:22:05 +03:00
|
|
|
extern const struct uapi_definition uverbs_def_obj_async_fd[];
|
2018-11-12 23:59:54 +03:00
|
|
|
extern const struct uapi_definition uverbs_def_obj_counters[];
|
|
|
|
extern const struct uapi_definition uverbs_def_obj_cq[];
|
2018-11-30 14:06:21 +03:00
|
|
|
extern const struct uapi_definition uverbs_def_obj_device[];
|
2018-11-12 23:59:54 +03:00
|
|
|
extern const struct uapi_definition uverbs_def_obj_dm[];
|
|
|
|
extern const struct uapi_definition uverbs_def_obj_flow_action[];
|
2018-11-12 23:59:50 +03:00
|
|
|
extern const struct uapi_definition uverbs_def_obj_intf[];
|
2018-11-12 23:59:54 +03:00
|
|
|
extern const struct uapi_definition uverbs_def_obj_mr[];
|
2020-05-19 10:27:11 +03:00
|
|
|
extern const struct uapi_definition uverbs_def_obj_qp[];
|
2020-05-19 10:27:09 +03:00
|
|
|
extern const struct uapi_definition uverbs_def_obj_srq[];
|
2020-05-19 10:27:10 +03:00
|
|
|
extern const struct uapi_definition uverbs_def_obj_wq[];
|
2018-11-12 23:59:56 +03:00
|
|
|
extern const struct uapi_definition uverbs_def_write_intf[];
|
|
|
|
|
|
|
|
static inline const struct uverbs_api_write_method *
|
|
|
|
uapi_get_method(const struct uverbs_api *uapi, u32 command)
|
|
|
|
{
|
|
|
|
u32 cmd_idx = command & IB_USER_VERBS_CMD_COMMAND_MASK;
|
|
|
|
|
|
|
|
if (command & ~(u32)(IB_USER_VERBS_CMD_FLAG_EXTENDED |
|
|
|
|
IB_USER_VERBS_CMD_COMMAND_MASK))
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
|
|
|
if (command & IB_USER_VERBS_CMD_FLAG_EXTENDED) {
|
|
|
|
if (cmd_idx >= uapi->num_write_ex)
|
|
|
|
return ERR_PTR(-EOPNOTSUPP);
|
|
|
|
return uapi->write_ex_methods[cmd_idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cmd_idx >= uapi->num_write)
|
|
|
|
return ERR_PTR(-EOPNOTSUPP);
|
|
|
|
return uapi->write_methods[cmd_idx];
|
|
|
|
}
|
2018-11-12 23:59:50 +03:00
|
|
|
|
2018-11-30 14:06:21 +03:00
|
|
|
void uverbs_fill_udata(struct uverbs_attr_bundle *bundle,
|
|
|
|
struct ib_udata *udata, unsigned int attr_in,
|
|
|
|
unsigned int attr_out);
|
|
|
|
|
2017-04-04 13:31:42 +03:00
|
|
|
#endif /* RDMA_CORE_H */
|