2017-08-03 16:06:55 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017, Mellanox Technologies 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 _UVERBS_IOCTL_
|
|
|
|
#define _UVERBS_IOCTL_
|
|
|
|
|
|
|
|
#include <rdma/uverbs_types.h>
|
2017-08-03 16:07:01 +03:00
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <rdma/rdma_user_ioctl.h>
|
2017-08-03 16:07:04 +03:00
|
|
|
#include <rdma/ib_user_ioctl_verbs.h>
|
2018-03-19 16:02:33 +03:00
|
|
|
#include <rdma/ib_user_ioctl_cmds.h>
|
2017-08-03 16:06:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* =======================================
|
|
|
|
* Verbs action specifications
|
|
|
|
* =======================================
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
enum uverbs_attr_type {
|
|
|
|
UVERBS_ATTR_TYPE_NA,
|
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 16:06:57 +03:00
|
|
|
UVERBS_ATTR_TYPE_PTR_IN,
|
|
|
|
UVERBS_ATTR_TYPE_PTR_OUT,
|
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
|
|
|
UVERBS_ATTR_TYPE_IDR,
|
|
|
|
UVERBS_ATTR_TYPE_FD,
|
2018-03-28 09:27:42 +03:00
|
|
|
UVERBS_ATTR_TYPE_ENUM_IN,
|
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
|
|
|
};
|
|
|
|
|
2017-08-03 16:06:55 +03:00
|
|
|
enum uverbs_obj_access {
|
|
|
|
UVERBS_ACCESS_READ,
|
|
|
|
UVERBS_ACCESS_WRITE,
|
|
|
|
UVERBS_ACCESS_NEW,
|
|
|
|
UVERBS_ACCESS_DESTROY
|
|
|
|
};
|
|
|
|
|
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 16:06:57 +03:00
|
|
|
enum {
|
|
|
|
UVERBS_ATTR_SPEC_F_MANDATORY = 1U << 0,
|
2018-03-19 16:02:36 +03:00
|
|
|
/* Support extending attributes by length, validate all unknown size == zero */
|
|
|
|
UVERBS_ATTR_SPEC_F_MIN_SZ_OR_ZERO = 1U << 1,
|
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 16:06:57 +03:00
|
|
|
};
|
|
|
|
|
2018-03-19 16:02:35 +03:00
|
|
|
/* Specification of a single attribute inside the ioctl message */
|
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
|
|
|
struct uverbs_attr_spec {
|
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 16:06:57 +03:00
|
|
|
union {
|
2018-03-19 16:02:35 +03:00
|
|
|
/* Header shared by all following union members - to reduce space. */
|
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 16:06:57 +03:00
|
|
|
struct {
|
2018-03-19 16:02:35 +03:00
|
|
|
enum uverbs_attr_type type;
|
|
|
|
/* Combination of bits from enum UVERBS_ATTR_SPEC_F_XXXX */
|
|
|
|
u8 flags;
|
|
|
|
};
|
|
|
|
struct {
|
|
|
|
enum uverbs_attr_type type;
|
|
|
|
/* Combination of bits from enum UVERBS_ATTR_SPEC_F_XXXX */
|
|
|
|
u8 flags;
|
2018-03-19 16:02:36 +03:00
|
|
|
/* Current known size to kernel */
|
2018-03-19 16:02:35 +03:00
|
|
|
u16 len;
|
2018-03-19 16:02:36 +03:00
|
|
|
/* User isn't allowed to provide something < min_len */
|
|
|
|
u16 min_len;
|
2018-03-19 16:02:35 +03:00
|
|
|
} ptr;
|
|
|
|
struct {
|
|
|
|
enum uverbs_attr_type type;
|
|
|
|
/* Combination of bits from enum UVERBS_ATTR_SPEC_F_XXXX */
|
|
|
|
u8 flags;
|
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 16:06:57 +03:00
|
|
|
/*
|
|
|
|
* higher bits mean the namespace and lower bits mean
|
|
|
|
* the type id within the namespace.
|
|
|
|
*/
|
|
|
|
u16 obj_type;
|
|
|
|
u8 access;
|
|
|
|
} obj;
|
2018-03-28 09:27:42 +03:00
|
|
|
struct {
|
|
|
|
enum uverbs_attr_type type;
|
|
|
|
/* Combination of bits from enum UVERBS_ATTR_SPEC_F_XXXX */
|
|
|
|
u8 flags;
|
|
|
|
u8 num_elems;
|
|
|
|
/*
|
|
|
|
* The enum attribute can select one of the attributes
|
|
|
|
* contained in the ids array. Currently only PTR_IN
|
|
|
|
* attributes are supported in the ids array.
|
|
|
|
*/
|
|
|
|
const struct uverbs_attr_spec *ids;
|
|
|
|
} enum_def;
|
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 16:06:57 +03: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 16:06:56 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct uverbs_attr_spec_hash {
|
|
|
|
size_t num_attrs;
|
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 16:06:57 +03:00
|
|
|
unsigned long *mandatory_attrs_bitmask;
|
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
|
|
|
struct uverbs_attr_spec attrs[0];
|
|
|
|
};
|
|
|
|
|
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 16:06:57 +03:00
|
|
|
struct uverbs_attr_bundle;
|
|
|
|
struct ib_uverbs_file;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
/*
|
|
|
|
* Action marked with this flag creates a context (or root for all
|
|
|
|
* objects).
|
|
|
|
*/
|
|
|
|
UVERBS_ACTION_FLAG_CREATE_ROOT = 1U << 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct uverbs_method_spec {
|
|
|
|
/* Combination of bits from enum UVERBS_ACTION_FLAG_XXXX */
|
|
|
|
u32 flags;
|
|
|
|
size_t num_buckets;
|
|
|
|
size_t num_child_attrs;
|
|
|
|
int (*handler)(struct ib_device *ib_dev, struct ib_uverbs_file *ufile,
|
|
|
|
struct uverbs_attr_bundle *ctx);
|
|
|
|
struct uverbs_attr_spec_hash *attr_buckets[0];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct uverbs_method_spec_hash {
|
|
|
|
size_t num_methods;
|
|
|
|
struct uverbs_method_spec *methods[0];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct uverbs_object_spec {
|
|
|
|
const struct uverbs_obj_type *type_attrs;
|
|
|
|
size_t num_buckets;
|
|
|
|
struct uverbs_method_spec_hash *method_buckets[0];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct uverbs_object_spec_hash {
|
|
|
|
size_t num_objects;
|
|
|
|
struct uverbs_object_spec *objects[0];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct uverbs_root_spec {
|
|
|
|
size_t num_buckets;
|
|
|
|
struct uverbs_object_spec_hash *object_buckets[0];
|
|
|
|
};
|
|
|
|
|
2017-08-03 16:06:58 +03:00
|
|
|
/*
|
|
|
|
* =======================================
|
|
|
|
* Verbs definitions
|
|
|
|
* =======================================
|
|
|
|
*/
|
|
|
|
|
2017-08-03 16:06:59 +03:00
|
|
|
struct uverbs_attr_def {
|
|
|
|
u16 id;
|
|
|
|
struct uverbs_attr_spec attr;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct uverbs_method_def {
|
|
|
|
u16 id;
|
|
|
|
/* Combination of bits from enum UVERBS_ACTION_FLAG_XXXX */
|
|
|
|
u32 flags;
|
|
|
|
size_t num_attrs;
|
|
|
|
const struct uverbs_attr_def * const (*attrs)[];
|
|
|
|
int (*handler)(struct ib_device *ib_dev, struct ib_uverbs_file *ufile,
|
|
|
|
struct uverbs_attr_bundle *ctx);
|
|
|
|
};
|
|
|
|
|
2017-08-03 16:06:58 +03:00
|
|
|
struct uverbs_object_def {
|
2017-08-03 16:06:59 +03:00
|
|
|
u16 id;
|
2017-08-03 16:06:58 +03:00
|
|
|
const struct uverbs_obj_type *type_attrs;
|
2017-08-03 16:06:59 +03:00
|
|
|
size_t num_methods;
|
|
|
|
const struct uverbs_method_def * const (*methods)[];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct uverbs_object_tree_def {
|
|
|
|
size_t num_objects;
|
|
|
|
const struct uverbs_object_def * const (*objects)[];
|
2017-08-03 16:06:58 +03:00
|
|
|
};
|
|
|
|
|
2017-08-03 16:07:01 +03:00
|
|
|
#define UA_FLAGS(_flags) .flags = _flags
|
2018-03-19 16:02:36 +03:00
|
|
|
#define __UVERBS_ATTR0(_id, _type, _fld, _attr, ...) \
|
2017-08-03 16:07:01 +03:00
|
|
|
((const struct uverbs_attr_def) \
|
2018-03-19 16:02:36 +03:00
|
|
|
{.id = _id, .attr = {{._fld = {.type = _type, _attr, .flags = 0, } }, } })
|
|
|
|
#define __UVERBS_ATTR1(_id, _type, _fld, _attr, _extra1, ...) \
|
2017-08-03 16:07:01 +03:00
|
|
|
((const struct uverbs_attr_def) \
|
2018-03-19 16:02:36 +03:00
|
|
|
{.id = _id, .attr = {{._fld = {.type = _type, _attr, _extra1 } },} })
|
|
|
|
#define __UVERBS_ATTR2(_id, _type, _fld, _attr, _extra1, _extra2) \
|
|
|
|
((const struct uverbs_attr_def) \
|
|
|
|
{.id = _id, .attr = {{._fld = {.type = _type, _attr, _extra1, _extra2 } },} })
|
|
|
|
#define __UVERBS_ATTR(_id, _type, _fld, _attr, _extra1, _extra2, _n, ...) \
|
|
|
|
__UVERBS_ATTR##_n(_id, _type, _fld, _attr, _extra1, _extra2)
|
|
|
|
|
|
|
|
#define UVERBS_ATTR_TYPE(_type) \
|
|
|
|
.min_len = sizeof(_type), .len = sizeof(_type)
|
|
|
|
#define UVERBS_ATTR_STRUCT(_type, _last) \
|
|
|
|
.min_len = ((uintptr_t)(&((_type *)0)->_last + 1)), .len = sizeof(_type)
|
|
|
|
#define UVERBS_ATTR_SIZE(_min_len, _len) \
|
|
|
|
.min_len = _min_len, .len = _len
|
|
|
|
|
2017-08-03 16:07:01 +03:00
|
|
|
/*
|
|
|
|
* In new compiler, UVERBS_ATTR could be simplified by declaring it as
|
|
|
|
* [_id] = {.type = _type, .len = _len, ##__VA_ARGS__}
|
|
|
|
* But since we support older compilers too, we need the more complex code.
|
|
|
|
*/
|
2018-03-19 16:02:36 +03:00
|
|
|
#define UVERBS_ATTR(_id, _type, _fld, _attr, ...) \
|
|
|
|
__UVERBS_ATTR(_id, _type, _fld, _attr, ##__VA_ARGS__, 2, 1, 0)
|
2017-08-03 16:07:01 +03:00
|
|
|
#define UVERBS_ATTR_PTR_IN_SZ(_id, _len, ...) \
|
2018-03-19 16:02:36 +03:00
|
|
|
UVERBS_ATTR(_id, UVERBS_ATTR_TYPE_PTR_IN, ptr, _len, ##__VA_ARGS__)
|
2017-08-03 16:07:01 +03:00
|
|
|
/* If sizeof(_type) <= sizeof(u64), this will be inlined rather than a pointer */
|
|
|
|
#define UVERBS_ATTR_PTR_IN(_id, _type, ...) \
|
2018-03-19 16:02:36 +03:00
|
|
|
UVERBS_ATTR_PTR_IN_SZ(_id, _type, ##__VA_ARGS__)
|
2017-08-03 16:07:01 +03:00
|
|
|
#define UVERBS_ATTR_PTR_OUT_SZ(_id, _len, ...) \
|
2018-03-19 16:02:36 +03:00
|
|
|
UVERBS_ATTR(_id, UVERBS_ATTR_TYPE_PTR_OUT, ptr, _len, ##__VA_ARGS__)
|
2017-08-03 16:07:01 +03:00
|
|
|
#define UVERBS_ATTR_PTR_OUT(_id, _type, ...) \
|
2018-03-19 16:02:36 +03:00
|
|
|
UVERBS_ATTR_PTR_OUT_SZ(_id, _type, ##__VA_ARGS__)
|
2018-03-28 09:27:42 +03:00
|
|
|
#define UVERBS_ATTR_ENUM_IN(_id, _enum_arr, ...) \
|
|
|
|
UVERBS_ATTR(_id, UVERBS_ATTR_TYPE_ENUM_IN, enum_def, \
|
|
|
|
.ids = (_enum_arr), \
|
|
|
|
.num_elems = ARRAY_SIZE(_enum_arr), ##__VA_ARGS__)
|
2017-08-03 16:07:01 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* In new compiler, UVERBS_ATTR_IDR (and FD) could be simplified by declaring
|
|
|
|
* it as
|
|
|
|
* {.id = _id, \
|
|
|
|
* .attr {.type = __obj_class, \
|
|
|
|
* .obj = {.obj_type = _idr_type, \
|
|
|
|
* .access = _access \
|
|
|
|
* }, ##__VA_ARGS__ } }
|
|
|
|
* But since we support older compilers too, we need the more complex code.
|
|
|
|
*/
|
|
|
|
#define ___UVERBS_ATTR_OBJ0(_id, _obj_class, _obj_type, _access, ...)\
|
|
|
|
((const struct uverbs_attr_def) \
|
|
|
|
{.id = _id, \
|
2018-03-19 16:02:35 +03:00
|
|
|
.attr = { {.obj = {.type = _obj_class, .obj_type = _obj_type, \
|
|
|
|
.access = _access, .flags = 0 } }, } })
|
2017-08-03 16:07:01 +03:00
|
|
|
#define ___UVERBS_ATTR_OBJ1(_id, _obj_class, _obj_type, _access, _flags)\
|
|
|
|
((const struct uverbs_attr_def) \
|
|
|
|
{.id = _id, \
|
2018-03-19 16:02:35 +03:00
|
|
|
.attr = { {.obj = {.type = _obj_class, .obj_type = _obj_type, \
|
|
|
|
.access = _access, _flags} }, } })
|
2017-08-03 16:07:01 +03:00
|
|
|
#define ___UVERBS_ATTR_OBJ(_id, _obj_class, _obj_type, _access, _flags, \
|
|
|
|
_n, ...) \
|
|
|
|
___UVERBS_ATTR_OBJ##_n(_id, _obj_class, _obj_type, _access, _flags)
|
|
|
|
#define __UVERBS_ATTR_OBJ(_id, _obj_class, _obj_type, _access, ...) \
|
|
|
|
___UVERBS_ATTR_OBJ(_id, _obj_class, _obj_type, _access, \
|
|
|
|
##__VA_ARGS__, 1, 0)
|
|
|
|
#define UVERBS_ATTR_IDR(_id, _idr_type, _access, ...) \
|
|
|
|
__UVERBS_ATTR_OBJ(_id, UVERBS_ATTR_TYPE_IDR, _idr_type, _access,\
|
|
|
|
##__VA_ARGS__)
|
|
|
|
#define UVERBS_ATTR_FD(_id, _fd_type, _access, ...) \
|
|
|
|
__UVERBS_ATTR_OBJ(_id, UVERBS_ATTR_TYPE_FD, _fd_type, \
|
|
|
|
(_access) + BUILD_BUG_ON_ZERO( \
|
|
|
|
(_access) != UVERBS_ACCESS_NEW && \
|
|
|
|
(_access) != UVERBS_ACCESS_READ), \
|
|
|
|
##__VA_ARGS__)
|
|
|
|
#define DECLARE_UVERBS_ATTR_SPEC(_name, ...) \
|
|
|
|
const struct uverbs_attr_def _name = __VA_ARGS__
|
|
|
|
|
2018-03-28 09:27:42 +03:00
|
|
|
#define DECLARE_UVERBS_ENUM(_name, ...) \
|
|
|
|
const struct uverbs_enum_spec _name = { \
|
|
|
|
.len = ARRAY_SIZE(((struct uverbs_attr_spec[]){__VA_ARGS__})),\
|
|
|
|
.ids = {__VA_ARGS__}, \
|
|
|
|
}
|
2017-08-03 16:07:01 +03:00
|
|
|
#define _UVERBS_METHOD_ATTRS_SZ(...) \
|
|
|
|
(sizeof((const struct uverbs_attr_def * const []){__VA_ARGS__}) /\
|
|
|
|
sizeof(const struct uverbs_attr_def *))
|
|
|
|
#define _UVERBS_METHOD(_id, _handler, _flags, ...) \
|
|
|
|
((const struct uverbs_method_def) { \
|
|
|
|
.id = _id, \
|
|
|
|
.flags = _flags, \
|
|
|
|
.handler = _handler, \
|
|
|
|
.num_attrs = _UVERBS_METHOD_ATTRS_SZ(__VA_ARGS__), \
|
|
|
|
.attrs = &(const struct uverbs_attr_def * const []){__VA_ARGS__} })
|
|
|
|
#define DECLARE_UVERBS_METHOD(_name, _id, _handler, ...) \
|
|
|
|
const struct uverbs_method_def _name = \
|
|
|
|
_UVERBS_METHOD(_id, _handler, 0, ##__VA_ARGS__)
|
|
|
|
#define DECLARE_UVERBS_CTX_METHOD(_name, _id, _handler, _flags, ...) \
|
|
|
|
const struct uverbs_method_def _name = \
|
|
|
|
_UVERBS_METHOD(_id, _handler, \
|
|
|
|
UVERBS_ACTION_FLAG_CREATE_ROOT, \
|
|
|
|
##__VA_ARGS__)
|
|
|
|
#define _UVERBS_OBJECT_METHODS_SZ(...) \
|
|
|
|
(sizeof((const struct uverbs_method_def * const []){__VA_ARGS__}) / \
|
|
|
|
sizeof(const struct uverbs_method_def *))
|
2017-08-03 16:06:58 +03:00
|
|
|
#define _UVERBS_OBJECT(_id, _type_attrs, ...) \
|
|
|
|
((const struct uverbs_object_def) { \
|
2017-08-03 16:06:59 +03:00
|
|
|
.id = _id, \
|
2017-08-03 16:07:01 +03:00
|
|
|
.type_attrs = _type_attrs, \
|
|
|
|
.num_methods = _UVERBS_OBJECT_METHODS_SZ(__VA_ARGS__), \
|
|
|
|
.methods = &(const struct uverbs_method_def * const []){__VA_ARGS__} })
|
2017-08-03 16:06:58 +03:00
|
|
|
#define DECLARE_UVERBS_OBJECT(_name, _id, _type_attrs, ...) \
|
|
|
|
const struct uverbs_object_def _name = \
|
|
|
|
_UVERBS_OBJECT(_id, _type_attrs, ##__VA_ARGS__)
|
2017-08-03 16:06:59 +03:00
|
|
|
#define _UVERBS_TREE_OBJECTS_SZ(...) \
|
|
|
|
(sizeof((const struct uverbs_object_def * const []){__VA_ARGS__}) / \
|
|
|
|
sizeof(const struct uverbs_object_def *))
|
|
|
|
#define _UVERBS_OBJECT_TREE(...) \
|
|
|
|
((const struct uverbs_object_tree_def) { \
|
|
|
|
.num_objects = _UVERBS_TREE_OBJECTS_SZ(__VA_ARGS__), \
|
|
|
|
.objects = &(const struct uverbs_object_def * const []){__VA_ARGS__} })
|
|
|
|
#define DECLARE_UVERBS_OBJECT_TREE(_name, ...) \
|
|
|
|
const struct uverbs_object_tree_def _name = \
|
|
|
|
_UVERBS_OBJECT_TREE(__VA_ARGS__)
|
|
|
|
|
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 16:06:57 +03:00
|
|
|
/* =================================================
|
|
|
|
* Parsing infrastructure
|
|
|
|
* =================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct uverbs_ptr_attr {
|
2018-02-13 13:18:31 +03:00
|
|
|
u64 data;
|
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 16:06:57 +03:00
|
|
|
u16 len;
|
|
|
|
/* Combination of bits from enum UVERBS_ATTR_F_XXXX */
|
|
|
|
u16 flags;
|
2018-03-28 09:27:42 +03:00
|
|
|
u8 enum_id;
|
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 16:06:57 +03: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 16:06:56 +03:00
|
|
|
struct uverbs_obj_attr {
|
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 16:06:57 +03:00
|
|
|
/* pointer to the kernel descriptor -> type, access, etc */
|
|
|
|
const struct uverbs_obj_type *type;
|
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
|
|
|
struct ib_uobject *uobject;
|
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 16:06:57 +03:00
|
|
|
/* fd or id in idr of this object */
|
|
|
|
int id;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
struct uverbs_attr {
|
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 16:06:57 +03:00
|
|
|
/*
|
|
|
|
* pointer to the user-space given attribute, in order to write the
|
|
|
|
* new uobject's id or update flags.
|
|
|
|
*/
|
|
|
|
struct ib_uverbs_attr __user *uattr;
|
|
|
|
union {
|
|
|
|
struct uverbs_ptr_attr ptr_attr;
|
|
|
|
struct uverbs_obj_attr obj_attr;
|
|
|
|
};
|
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
|
|
|
};
|
|
|
|
|
|
|
|
struct uverbs_attr_bundle_hash {
|
|
|
|
/* if bit i is set, it means attrs[i] contains valid information */
|
|
|
|
unsigned long *valid_bitmap;
|
|
|
|
size_t num_attrs;
|
|
|
|
/*
|
|
|
|
* arrays of attributes, each element corresponds to the specification
|
|
|
|
* of the attribute in the same index.
|
|
|
|
*/
|
|
|
|
struct uverbs_attr *attrs;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct uverbs_attr_bundle {
|
|
|
|
size_t num_buckets;
|
|
|
|
struct uverbs_attr_bundle_hash hash[];
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline bool uverbs_attr_is_valid_in_hash(const struct uverbs_attr_bundle_hash *attrs_hash,
|
|
|
|
unsigned int idx)
|
|
|
|
{
|
|
|
|
return test_bit(idx, attrs_hash->valid_bitmap);
|
|
|
|
}
|
|
|
|
|
2017-08-03 16:07:01 +03:00
|
|
|
static inline bool uverbs_attr_is_valid(const struct uverbs_attr_bundle *attrs_bundle,
|
|
|
|
unsigned int idx)
|
|
|
|
{
|
|
|
|
u16 idx_bucket = idx >> UVERBS_ID_NS_SHIFT;
|
|
|
|
|
|
|
|
if (attrs_bundle->num_buckets <= idx_bucket)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return uverbs_attr_is_valid_in_hash(&attrs_bundle->hash[idx_bucket],
|
|
|
|
idx & ~UVERBS_ID_NS_MASK);
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:02:38 +03:00
|
|
|
#define IS_UVERBS_COPY_ERR(_ret) ((_ret) && (_ret) != -ENOENT)
|
|
|
|
|
2017-08-03 16:07:04 +03:00
|
|
|
static inline const struct uverbs_attr *uverbs_attr_get(const struct uverbs_attr_bundle *attrs_bundle,
|
|
|
|
u16 idx)
|
|
|
|
{
|
|
|
|
u16 idx_bucket = idx >> UVERBS_ID_NS_SHIFT;
|
|
|
|
|
|
|
|
if (!uverbs_attr_is_valid(attrs_bundle, idx))
|
|
|
|
return ERR_PTR(-ENOENT);
|
|
|
|
|
|
|
|
return &attrs_bundle->hash[idx_bucket].attrs[idx & ~UVERBS_ID_NS_MASK];
|
|
|
|
}
|
|
|
|
|
2018-03-28 09:27:42 +03:00
|
|
|
static inline int uverbs_attr_get_enum_id(const struct uverbs_attr_bundle *attrs_bundle,
|
|
|
|
u16 idx)
|
|
|
|
{
|
|
|
|
const struct uverbs_attr *attr = uverbs_attr_get(attrs_bundle, idx);
|
|
|
|
|
|
|
|
if (IS_ERR(attr))
|
|
|
|
return PTR_ERR(attr);
|
|
|
|
|
|
|
|
return attr->ptr_attr.enum_id;
|
|
|
|
}
|
|
|
|
|
2018-04-05 18:53:25 +03:00
|
|
|
static inline void *uverbs_attr_get_obj(const struct uverbs_attr_bundle *attrs_bundle,
|
|
|
|
u16 idx)
|
|
|
|
{
|
|
|
|
struct ib_uobject *uobj =
|
|
|
|
uverbs_attr_get(attrs_bundle, idx)->obj_attr.uobject;
|
|
|
|
|
|
|
|
if (IS_ERR(uobj))
|
|
|
|
return uobj;
|
|
|
|
|
|
|
|
return uobj->object;
|
|
|
|
}
|
|
|
|
|
2017-08-03 16:07:04 +03:00
|
|
|
static inline int uverbs_copy_to(const struct uverbs_attr_bundle *attrs_bundle,
|
2018-02-13 13:18:29 +03:00
|
|
|
size_t idx, const void *from, size_t size)
|
2017-08-03 16:07:04 +03:00
|
|
|
{
|
|
|
|
const struct uverbs_attr *attr = uverbs_attr_get(attrs_bundle, idx);
|
|
|
|
u16 flags;
|
2018-02-13 13:18:29 +03:00
|
|
|
size_t min_size;
|
2017-08-03 16:07:04 +03:00
|
|
|
|
|
|
|
if (IS_ERR(attr))
|
|
|
|
return PTR_ERR(attr);
|
|
|
|
|
2018-02-13 13:18:29 +03:00
|
|
|
min_size = min_t(size_t, attr->ptr_attr.len, size);
|
2018-02-13 13:18:31 +03:00
|
|
|
if (copy_to_user(u64_to_user_ptr(attr->ptr_attr.data), from, min_size))
|
2018-02-13 13:18:29 +03:00
|
|
|
return -EFAULT;
|
|
|
|
|
2017-08-03 16:07:04 +03:00
|
|
|
flags = attr->ptr_attr.flags | UVERBS_ATTR_F_VALID_OUTPUT;
|
2018-02-13 13:18:29 +03:00
|
|
|
if (put_user(flags, &attr->uattr->flags))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
return 0;
|
2017-08-03 16:07:04 +03:00
|
|
|
}
|
|
|
|
|
2018-02-13 13:18:29 +03:00
|
|
|
static inline bool uverbs_attr_ptr_is_inline(const struct uverbs_attr *attr)
|
|
|
|
{
|
|
|
|
return attr->ptr_attr.len <= sizeof(attr->ptr_attr.data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int _uverbs_copy_from(void *to,
|
2017-08-03 16:07:04 +03:00
|
|
|
const struct uverbs_attr_bundle *attrs_bundle,
|
2018-02-13 13:18:29 +03:00
|
|
|
size_t idx,
|
|
|
|
size_t size)
|
2017-08-03 16:07:04 +03:00
|
|
|
{
|
|
|
|
const struct uverbs_attr *attr = uverbs_attr_get(attrs_bundle, idx);
|
|
|
|
|
|
|
|
if (IS_ERR(attr))
|
|
|
|
return PTR_ERR(attr);
|
|
|
|
|
2018-02-13 13:18:29 +03:00
|
|
|
/*
|
|
|
|
* Validation ensures attr->ptr_attr.len >= size. If the caller is
|
2018-03-19 16:02:36 +03:00
|
|
|
* using UVERBS_ATTR_SPEC_F_MIN_SZ_OR_ZERO then it must call
|
|
|
|
* uverbs_copy_from_or_zero.
|
2018-02-13 13:18:29 +03:00
|
|
|
*/
|
|
|
|
if (unlikely(size < attr->ptr_attr.len))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (uverbs_attr_ptr_is_inline(attr))
|
2017-08-03 16:07:04 +03:00
|
|
|
memcpy(to, &attr->ptr_attr.data, attr->ptr_attr.len);
|
2018-02-13 13:18:31 +03:00
|
|
|
else if (copy_from_user(to, u64_to_user_ptr(attr->ptr_attr.data),
|
|
|
|
attr->ptr_attr.len))
|
2017-08-03 16:07:04 +03:00
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:02:36 +03:00
|
|
|
static inline int _uverbs_copy_from_or_zero(void *to,
|
|
|
|
const struct uverbs_attr_bundle *attrs_bundle,
|
|
|
|
size_t idx,
|
|
|
|
size_t size)
|
|
|
|
{
|
|
|
|
const struct uverbs_attr *attr = uverbs_attr_get(attrs_bundle, idx);
|
|
|
|
size_t min_size;
|
|
|
|
|
|
|
|
if (IS_ERR(attr))
|
|
|
|
return PTR_ERR(attr);
|
|
|
|
|
|
|
|
min_size = min_t(size_t, size, attr->ptr_attr.len);
|
|
|
|
|
|
|
|
if (uverbs_attr_ptr_is_inline(attr))
|
|
|
|
memcpy(to, &attr->ptr_attr.data, min_size);
|
|
|
|
else if (copy_from_user(to, u64_to_user_ptr(attr->ptr_attr.data),
|
|
|
|
min_size))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
if (size > min_size)
|
|
|
|
memset(to + min_size, 0, size - min_size);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-03 16:07:04 +03:00
|
|
|
#define uverbs_copy_from(to, attrs_bundle, idx) \
|
2018-02-13 13:18:29 +03:00
|
|
|
_uverbs_copy_from(to, attrs_bundle, idx, sizeof(*to))
|
2017-08-03 16:07:04 +03:00
|
|
|
|
2018-03-19 16:02:36 +03:00
|
|
|
#define uverbs_copy_from_or_zero(to, attrs_bundle, idx) \
|
|
|
|
_uverbs_copy_from_or_zero(to, attrs_bundle, idx, sizeof(*to))
|
|
|
|
|
2017-08-03 16:07:00 +03:00
|
|
|
/* =================================================
|
|
|
|
* Definitions -> Specs infrastructure
|
|
|
|
* =================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* uverbs_alloc_spec_tree - Merges different common and driver specific feature
|
|
|
|
* into one parsing tree that every uverbs command will be parsed upon.
|
|
|
|
*
|
|
|
|
* @num_trees: Number of trees in the array @trees.
|
|
|
|
* @trees: Array of pointers to tree root definitions to merge. Each such tree
|
|
|
|
* possibly contains objects, methods and attributes definitions.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* uverbs_root_spec *: The root of the merged parsing tree.
|
|
|
|
* On error, we return an error code. Error is checked via IS_ERR.
|
|
|
|
*
|
|
|
|
* The following merges could take place:
|
|
|
|
* a. Two trees representing the same method with different handler
|
|
|
|
* -> We take the handler of the tree that its handler != NULL
|
|
|
|
* and its index in the trees array is greater. The incentive for that
|
|
|
|
* is that developers are expected to first merge common trees and then
|
|
|
|
* merge trees that gives specialized the behaviour.
|
|
|
|
* b. Two trees representing the same object with different
|
|
|
|
* type_attrs (struct uverbs_obj_type):
|
|
|
|
* -> We take the type_attrs of the tree that its type_attr != NULL
|
|
|
|
* and its index in the trees array is greater. This could be used
|
|
|
|
* in order to override the free function, allocation size, etc.
|
|
|
|
* c. Two trees representing the same method attribute (same id but possibly
|
|
|
|
* different attributes):
|
|
|
|
* -> ERROR (-ENOENT), we believe that's not the programmer's intent.
|
|
|
|
*
|
|
|
|
* An object without any methods is considered invalid and will abort the
|
|
|
|
* function with -ENOENT error.
|
|
|
|
*/
|
2017-08-03 16:07:06 +03:00
|
|
|
#if IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS)
|
2017-08-03 16:07:00 +03:00
|
|
|
struct uverbs_root_spec *uverbs_alloc_spec_tree(unsigned int num_trees,
|
|
|
|
const struct uverbs_object_tree_def **trees);
|
|
|
|
void uverbs_free_spec_tree(struct uverbs_root_spec *root);
|
2017-08-03 16:07:06 +03:00
|
|
|
#else
|
|
|
|
static inline struct uverbs_root_spec *uverbs_alloc_spec_tree(unsigned int num_trees,
|
|
|
|
const struct uverbs_object_tree_def **trees)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void uverbs_free_spec_tree(struct uverbs_root_spec *root)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
2017-08-03 16:06:55 +03:00
|
|
|
|
2017-08-03 16:07:00 +03:00
|
|
|
#endif
|