2017-04-04 18:31:42 +08: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 21:06:55 +08:00
|
|
|
#include <rdma/uverbs_ioctl.h>
|
2017-04-04 18:31:42 +08:00
|
|
|
#include <rdma/ib_verbs.h>
|
|
|
|
#include <linux/mutex.h>
|
|
|
|
|
2018-08-10 10:14:36 +08:00
|
|
|
struct ib_uverbs_device;
|
|
|
|
|
IB/core: Add new ioctl interface
In this ioctl interface, processing the command starts from
properties of the command and fetching the appropriate user objects
before calling the handler.
Parsing and validation is done according to a specifier declared by
the driver's code. In the driver, all supported objects are declared.
These objects are separated to different object namepsaces. Dividing
objects to namespaces is done at initialization by using the higher
bits of the object ids. This initialization can mix objects declared
in different places to one parsing tree using in this ioctl interface.
For each object we list all supported methods. Similarly to objects,
methods are separated to method namespaces too. Namespacing is done
similarly to the objects case. This could be used in order to add
methods to an existing object.
Each method has a specific handler, which could be either a default
handler or a driver specific handler.
Along with the handler, a bunch of attributes are specified as well.
Similarly to objects and method, attributes are namespaced and hashed
by their ids at initialization too. All supported attributes are
subject to automatic fetching and validation. These attributes include
the command, response and the method's related objects' ids.
When these entities (objects, methods and attributes) are used, the
high bits of the entities ids are used in order to calculate the hash
bucket index. Then, these high bits are masked out in order to have a
zero based index. Since we use these high bits for both bucketing and
namespacing, we get a compact representation and O(1) array access.
This is mandatory for efficient dispatching.
Each attribute has a type (PTR_IN, PTR_OUT, IDR and FD) and a length.
Attributes could be validated through some attributes, like:
(*) Minimum size / Exact size
(*) Fops for FD
(*) Object type for IDR
If an IDR/fd attribute is specified, the kernel also states the object
type and the required access (NEW, WRITE, READ or DESTROY).
All uobject/fd management is done automatically by the infrastructure,
meaning - the infrastructure will fail concurrent commands that at
least one of them requires concurrent access (WRITE/DESTROY),
synchronize actions with device removals (dissociate context events)
and take care of reference counting (increase/decrease) for concurrent
actions invocation. The reference counts on the actual kernel objects
shall be handled by the handlers.
objects
+--------+
| |
| | methods +--------+
| | ns method method_spec +-----+ |len |
+--------+ +------+[d]+-------+ +----------------+[d]+------------+ |attr1+-> |type |
| object +> |method+-> | spec +-> + attr_buckets +-> |default_chain+--> +-----+ |idr_type|
+--------+ +------+ |handler| | | +------------+ |attr2| |access |
| | | | +-------+ +----------------+ |driver chain| +-----+ +--------+
| | | | +------------+
| | +------+
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
+--------+
[d] = Hash ids to groups using the high order bits
The right types table is also chosen by using the high bits from
the ids. Currently we have either default or driver specific groups.
Once validation and object fetching (or creation) completed, we call
the handler:
int (*handler)(struct ib_device *ib_dev, struct ib_uverbs_file *ufile,
struct uverbs_attr_bundle *ctx);
ctx bundles attributes of different namespaces. Each element there
is an array of attributes which corresponds to one namespaces of
attributes. For example, in the usually used case:
ctx core
+----------------------------+ +------------+
| core: +---> | valid |
+----------------------------+ | cmd_attr |
| driver: | +------------+
|----------------------------+--+ | valid |
| | cmd_attr |
| +------------+
| | valid |
| | obj_attr |
| +------------+
|
| drivers
| +------------+
+> | valid |
| cmd_attr |
+------------+
| valid |
| cmd_attr |
+------------+
| valid |
| obj_attr |
+------------+
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 21:06:57 +08:00
|
|
|
int uverbs_ns_idx(u16 *id, unsigned int ns_count);
|
2018-07-04 13:50:23 +08:00
|
|
|
const struct uverbs_object_spec *uverbs_get_object(struct ib_uverbs_file *ufile,
|
IB/core: Add new ioctl interface
In this ioctl interface, processing the command starts from
properties of the command and fetching the appropriate user objects
before calling the handler.
Parsing and validation is done according to a specifier declared by
the driver's code. In the driver, all supported objects are declared.
These objects are separated to different object namepsaces. Dividing
objects to namespaces is done at initialization by using the higher
bits of the object ids. This initialization can mix objects declared
in different places to one parsing tree using in this ioctl interface.
For each object we list all supported methods. Similarly to objects,
methods are separated to method namespaces too. Namespacing is done
similarly to the objects case. This could be used in order to add
methods to an existing object.
Each method has a specific handler, which could be either a default
handler or a driver specific handler.
Along with the handler, a bunch of attributes are specified as well.
Similarly to objects and method, attributes are namespaced and hashed
by their ids at initialization too. All supported attributes are
subject to automatic fetching and validation. These attributes include
the command, response and the method's related objects' ids.
When these entities (objects, methods and attributes) are used, the
high bits of the entities ids are used in order to calculate the hash
bucket index. Then, these high bits are masked out in order to have a
zero based index. Since we use these high bits for both bucketing and
namespacing, we get a compact representation and O(1) array access.
This is mandatory for efficient dispatching.
Each attribute has a type (PTR_IN, PTR_OUT, IDR and FD) and a length.
Attributes could be validated through some attributes, like:
(*) Minimum size / Exact size
(*) Fops for FD
(*) Object type for IDR
If an IDR/fd attribute is specified, the kernel also states the object
type and the required access (NEW, WRITE, READ or DESTROY).
All uobject/fd management is done automatically by the infrastructure,
meaning - the infrastructure will fail concurrent commands that at
least one of them requires concurrent access (WRITE/DESTROY),
synchronize actions with device removals (dissociate context events)
and take care of reference counting (increase/decrease) for concurrent
actions invocation. The reference counts on the actual kernel objects
shall be handled by the handlers.
objects
+--------+
| |
| | methods +--------+
| | ns method method_spec +-----+ |len |
+--------+ +------+[d]+-------+ +----------------+[d]+------------+ |attr1+-> |type |
| object +> |method+-> | spec +-> + attr_buckets +-> |default_chain+--> +-----+ |idr_type|
+--------+ +------+ |handler| | | +------------+ |attr2| |access |
| | | | +-------+ +----------------+ |driver chain| +-----+ +--------+
| | | | +------------+
| | +------+
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
+--------+
[d] = Hash ids to groups using the high order bits
The right types table is also chosen by using the high bits from
the ids. Currently we have either default or driver specific groups.
Once validation and object fetching (or creation) completed, we call
the handler:
int (*handler)(struct ib_device *ib_dev, struct ib_uverbs_file *ufile,
struct uverbs_attr_bundle *ctx);
ctx bundles attributes of different namespaces. Each element there
is an array of attributes which corresponds to one namespaces of
attributes. For example, in the usually used case:
ctx core
+----------------------------+ +------------+
| core: +---> | valid |
+----------------------------+ | cmd_attr |
| driver: | +------------+
|----------------------------+--+ | valid |
| | cmd_attr |
| +------------+
| | valid |
| | obj_attr |
| +------------+
|
| drivers
| +------------+
+> | valid |
| cmd_attr |
+------------+
| valid |
| cmd_attr |
+------------+
| valid |
| obj_attr |
+------------+
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 21:06:57 +08:00
|
|
|
uint16_t object);
|
|
|
|
const struct uverbs_method_spec *uverbs_get_method(const struct uverbs_object_spec *object,
|
|
|
|
uint16_t method);
|
2018-07-04 16:32:08 +08:00
|
|
|
|
2018-07-11 10:55:19 +08:00
|
|
|
void uverbs_destroy_ufile_hw(struct ib_uverbs_file *ufile,
|
|
|
|
enum rdma_remove_reason reason);
|
2017-04-04 18:31:42 +08:00
|
|
|
|
2018-07-26 11:40:14 +08:00
|
|
|
int uobj_destroy(struct ib_uobject *uobj);
|
|
|
|
|
2017-04-04 18:31:44 +08:00
|
|
|
/*
|
|
|
|
* uverbs_uobject_get is called in order to increase the reference count on
|
|
|
|
* an uobject. This is useful when a handler wants to keep the uobject's memory
|
|
|
|
* alive, regardless if this uobject is still alive in the context's objects
|
|
|
|
* repository. Objects are put via uverbs_uobject_put.
|
|
|
|
*/
|
|
|
|
void uverbs_uobject_get(struct ib_uobject *uobject);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In order to indicate we no longer needs this uobject, uverbs_uobject_put
|
|
|
|
* is called. When the reference count is decreased, the uobject is freed.
|
|
|
|
* For example, this is used when attaching a completion channel to a CQ.
|
|
|
|
*/
|
|
|
|
void uverbs_uobject_put(struct ib_uobject *uobject);
|
|
|
|
|
2017-04-04 18:31:46 +08:00
|
|
|
/* Indicate this fd is no longer used by this consumer, but its memory isn't
|
|
|
|
* necessarily released yet. When the last reference is put, we release the
|
|
|
|
* memory. After this call is executed, calling uverbs_uobject_get isn't
|
|
|
|
* allowed.
|
|
|
|
* This must be called from the release file_operations of the file!
|
|
|
|
*/
|
|
|
|
void uverbs_close_fd(struct file *f);
|
|
|
|
|
2017-08-03 21:06:55 +08:00
|
|
|
/*
|
2018-07-04 16:32:08 +08:00
|
|
|
* Get an ib_uobject that corresponds to the given id from ufile, assuming
|
2017-08-03 21:06:55 +08: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 21:06:56 +08:00
|
|
|
* The action will be finalized only when uverbs_finalize_object or
|
|
|
|
* uverbs_finalize_objects are called.
|
2017-08-03 21:06:55 +08:00
|
|
|
*/
|
2018-07-04 16:32:08 +08:00
|
|
|
struct ib_uobject *
|
2018-08-10 10:14:37 +08:00
|
|
|
uverbs_get_uobject_from_file(u16 object_id,
|
2018-07-04 16:32:08 +08:00
|
|
|
struct ib_uverbs_file *ufile,
|
2018-07-11 10:55:14 +08:00
|
|
|
enum uverbs_obj_access access, s64 id);
|
2018-07-04 16:32:08 +08:00
|
|
|
|
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 21:06:56 +08:00
|
|
|
/*
|
|
|
|
* Note that certain finalize stages could return a status:
|
|
|
|
* (a) alloc_commit could return a failure if the object is committed at the
|
|
|
|
* same time when the context is destroyed.
|
|
|
|
* (b) remove_commit could fail if the object wasn't destroyed successfully.
|
|
|
|
* Since multiple objects could be finalized in one transaction, it is very NOT
|
|
|
|
* recommended to have several finalize actions which have side effects.
|
|
|
|
* For example, it's NOT recommended to have a certain action which has both
|
|
|
|
* a commit action and a destroy action or two destroy objects in the same
|
|
|
|
* action. The rule of thumb is to have one destroy or commit action with
|
|
|
|
* multiple lookups.
|
|
|
|
* The first non zero return value of finalize_object is returned from this
|
|
|
|
* function. For example, this could happen when we couldn't destroy an
|
|
|
|
* object.
|
|
|
|
*/
|
2018-06-17 17:59:51 +08:00
|
|
|
int uverbs_finalize_object(struct ib_uobject *uobj,
|
|
|
|
enum uverbs_obj_access access,
|
|
|
|
bool commit);
|
2017-08-03 21:06:55 +08:00
|
|
|
|
2018-07-26 11:40:20 +08:00
|
|
|
void setup_ufile_idr_uobject(struct ib_uverbs_file *ufile);
|
|
|
|
void release_ufile_idr_uobject(struct ib_uverbs_file *ufile);
|
|
|
|
|
2018-08-10 10:14:36 +08: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_object {
|
|
|
|
const struct uverbs_obj_type *type_attrs;
|
|
|
|
const struct uverbs_obj_type_class *type_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct uverbs_api_ioctl_method {
|
|
|
|
int (__rcu *handler)(struct ib_uverbs_file *ufile,
|
|
|
|
struct uverbs_attr_bundle *ctx);
|
|
|
|
DECLARE_BITMAP(attr_mandatory, UVERBS_API_ATTR_BKEY_LEN);
|
|
|
|
u8 driver_method:1;
|
|
|
|
u8 key_bitmap_len;
|
|
|
|
u8 destroy_bkey;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct uverbs_api_attr {
|
|
|
|
struct uverbs_attr_spec spec;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct uverbs_api_object;
|
|
|
|
struct uverbs_api {
|
|
|
|
/* radix tree contains struct uverbs_api_* pointers */
|
|
|
|
struct radix_tree_root radix;
|
|
|
|
enum rdma_driver_id driver_id;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline const struct uverbs_api_object *
|
|
|
|
uapi_get_object(struct uverbs_api *uapi, u16 object_id)
|
|
|
|
{
|
|
|
|
return radix_tree_lookup(&uapi->radix, uapi_key_obj(object_id));
|
|
|
|
}
|
|
|
|
|
|
|
|
char *uapi_key_format(char *S, unsigned int key);
|
|
|
|
struct uverbs_api *uverbs_alloc_api(
|
|
|
|
const struct uverbs_object_tree_def *const *driver_specs,
|
|
|
|
enum rdma_driver_id driver_id);
|
|
|
|
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);
|
|
|
|
|
2017-04-04 18:31:42 +08:00
|
|
|
#endif /* RDMA_CORE_H */
|