root/drivers/infiniband/core/uverbs_std_types_cq.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. uverbs_free_cq
  2. UVERBS_HANDLER
  3. UVERBS_HANDLER

   1 /*
   2  * Copyright (c) 2017, Mellanox Technologies inc.  All rights reserved.
   3  *
   4  * This software is available to you under a choice of one of two
   5  * licenses.  You may choose to be licensed under the terms of the GNU
   6  * General Public License (GPL) Version 2, available from the file
   7  * COPYING in the main directory of this source tree, or the
   8  * OpenIB.org BSD license below:
   9  *
  10  *     Redistribution and use in source and binary forms, with or
  11  *     without modification, are permitted provided that the following
  12  *     conditions are met:
  13  *
  14  *      - Redistributions of source code must retain the above
  15  *        copyright notice, this list of conditions and the following
  16  *        disclaimer.
  17  *
  18  *      - Redistributions in binary form must reproduce the above
  19  *        copyright notice, this list of conditions and the following
  20  *        disclaimer in the documentation and/or other materials
  21  *        provided with the distribution.
  22  *
  23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30  * SOFTWARE.
  31  */
  32 
  33 #include <rdma/uverbs_std_types.h>
  34 #include "rdma_core.h"
  35 #include "uverbs.h"
  36 
  37 static int uverbs_free_cq(struct ib_uobject *uobject,
  38                           enum rdma_remove_reason why,
  39                           struct uverbs_attr_bundle *attrs)
  40 {
  41         struct ib_cq *cq = uobject->object;
  42         struct ib_uverbs_event_queue *ev_queue = cq->cq_context;
  43         struct ib_ucq_object *ucq =
  44                 container_of(uobject, struct ib_ucq_object, uobject);
  45         int ret;
  46 
  47         ret = ib_destroy_cq_user(cq, &attrs->driver_udata);
  48         if (ib_is_destroy_retryable(ret, why, uobject))
  49                 return ret;
  50 
  51         ib_uverbs_release_ucq(
  52                 attrs->ufile,
  53                 ev_queue ? container_of(ev_queue,
  54                                         struct ib_uverbs_completion_event_file,
  55                                         ev_queue) :
  56                            NULL,
  57                 ucq);
  58         return ret;
  59 }
  60 
  61 static int UVERBS_HANDLER(UVERBS_METHOD_CQ_CREATE)(
  62         struct uverbs_attr_bundle *attrs)
  63 {
  64         struct ib_ucq_object *obj = container_of(
  65                 uverbs_attr_get_uobject(attrs, UVERBS_ATTR_CREATE_CQ_HANDLE),
  66                 typeof(*obj), uobject);
  67         struct ib_device *ib_dev = attrs->context->device;
  68         int ret;
  69         u64 user_handle;
  70         struct ib_cq_init_attr attr = {};
  71         struct ib_cq                   *cq;
  72         struct ib_uverbs_completion_event_file    *ev_file = NULL;
  73         struct ib_uobject *ev_file_uobj;
  74 
  75         if (!ib_dev->ops.create_cq || !ib_dev->ops.destroy_cq)
  76                 return -EOPNOTSUPP;
  77 
  78         ret = uverbs_copy_from(&attr.comp_vector, attrs,
  79                                UVERBS_ATTR_CREATE_CQ_COMP_VECTOR);
  80         if (!ret)
  81                 ret = uverbs_copy_from(&attr.cqe, attrs,
  82                                        UVERBS_ATTR_CREATE_CQ_CQE);
  83         if (!ret)
  84                 ret = uverbs_copy_from(&user_handle, attrs,
  85                                        UVERBS_ATTR_CREATE_CQ_USER_HANDLE);
  86         if (ret)
  87                 return ret;
  88 
  89         ret = uverbs_get_flags32(&attr.flags, attrs,
  90                                  UVERBS_ATTR_CREATE_CQ_FLAGS,
  91                                  IB_UVERBS_CQ_FLAGS_TIMESTAMP_COMPLETION |
  92                                          IB_UVERBS_CQ_FLAGS_IGNORE_OVERRUN);
  93         if (ret)
  94                 return ret;
  95 
  96         ev_file_uobj = uverbs_attr_get_uobject(attrs, UVERBS_ATTR_CREATE_CQ_COMP_CHANNEL);
  97         if (!IS_ERR(ev_file_uobj)) {
  98                 ev_file = container_of(ev_file_uobj,
  99                                        struct ib_uverbs_completion_event_file,
 100                                        uobj);
 101                 uverbs_uobject_get(ev_file_uobj);
 102         }
 103 
 104         if (attr.comp_vector >= attrs->ufile->device->num_comp_vectors) {
 105                 ret = -EINVAL;
 106                 goto err_event_file;
 107         }
 108 
 109         obj->comp_events_reported  = 0;
 110         obj->async_events_reported = 0;
 111         INIT_LIST_HEAD(&obj->comp_list);
 112         INIT_LIST_HEAD(&obj->async_list);
 113 
 114         cq = rdma_zalloc_drv_obj(ib_dev, ib_cq);
 115         if (!cq) {
 116                 ret = -ENOMEM;
 117                 goto err_event_file;
 118         }
 119 
 120         cq->device        = ib_dev;
 121         cq->uobject       = &obj->uobject;
 122         cq->comp_handler  = ib_uverbs_comp_handler;
 123         cq->event_handler = ib_uverbs_cq_event_handler;
 124         cq->cq_context    = ev_file ? &ev_file->ev_queue : NULL;
 125         atomic_set(&cq->usecnt, 0);
 126         cq->res.type = RDMA_RESTRACK_CQ;
 127 
 128         ret = ib_dev->ops.create_cq(cq, &attr, &attrs->driver_udata);
 129         if (ret)
 130                 goto err_free;
 131 
 132         obj->uobject.object = cq;
 133         obj->uobject.user_handle = user_handle;
 134         rdma_restrack_uadd(&cq->res);
 135 
 136         ret = uverbs_copy_to(attrs, UVERBS_ATTR_CREATE_CQ_RESP_CQE, &cq->cqe,
 137                              sizeof(cq->cqe));
 138         if (ret)
 139                 goto err_cq;
 140 
 141         return 0;
 142 err_cq:
 143         ib_destroy_cq_user(cq, uverbs_get_cleared_udata(attrs));
 144         cq = NULL;
 145 err_free:
 146         kfree(cq);
 147 err_event_file:
 148         if (ev_file)
 149                 uverbs_uobject_put(ev_file_uobj);
 150         return ret;
 151 };
 152 
 153 DECLARE_UVERBS_NAMED_METHOD(
 154         UVERBS_METHOD_CQ_CREATE,
 155         UVERBS_ATTR_IDR(UVERBS_ATTR_CREATE_CQ_HANDLE,
 156                         UVERBS_OBJECT_CQ,
 157                         UVERBS_ACCESS_NEW,
 158                         UA_MANDATORY),
 159         UVERBS_ATTR_PTR_IN(UVERBS_ATTR_CREATE_CQ_CQE,
 160                            UVERBS_ATTR_TYPE(u32),
 161                            UA_MANDATORY),
 162         UVERBS_ATTR_PTR_IN(UVERBS_ATTR_CREATE_CQ_USER_HANDLE,
 163                            UVERBS_ATTR_TYPE(u64),
 164                            UA_MANDATORY),
 165         UVERBS_ATTR_FD(UVERBS_ATTR_CREATE_CQ_COMP_CHANNEL,
 166                        UVERBS_OBJECT_COMP_CHANNEL,
 167                        UVERBS_ACCESS_READ,
 168                        UA_OPTIONAL),
 169         UVERBS_ATTR_PTR_IN(UVERBS_ATTR_CREATE_CQ_COMP_VECTOR,
 170                            UVERBS_ATTR_TYPE(u32),
 171                            UA_MANDATORY),
 172         UVERBS_ATTR_FLAGS_IN(UVERBS_ATTR_CREATE_CQ_FLAGS,
 173                              enum ib_uverbs_ex_create_cq_flags),
 174         UVERBS_ATTR_PTR_OUT(UVERBS_ATTR_CREATE_CQ_RESP_CQE,
 175                             UVERBS_ATTR_TYPE(u32),
 176                             UA_MANDATORY),
 177         UVERBS_ATTR_UHW());
 178 
 179 static int UVERBS_HANDLER(UVERBS_METHOD_CQ_DESTROY)(
 180         struct uverbs_attr_bundle *attrs)
 181 {
 182         struct ib_uobject *uobj =
 183                 uverbs_attr_get_uobject(attrs, UVERBS_ATTR_DESTROY_CQ_HANDLE);
 184         struct ib_ucq_object *obj =
 185                 container_of(uobj, struct ib_ucq_object, uobject);
 186         struct ib_uverbs_destroy_cq_resp resp = {
 187                 .comp_events_reported = obj->comp_events_reported,
 188                 .async_events_reported = obj->async_events_reported
 189         };
 190 
 191         return uverbs_copy_to(attrs, UVERBS_ATTR_DESTROY_CQ_RESP, &resp,
 192                               sizeof(resp));
 193 }
 194 
 195 DECLARE_UVERBS_NAMED_METHOD(
 196         UVERBS_METHOD_CQ_DESTROY,
 197         UVERBS_ATTR_IDR(UVERBS_ATTR_DESTROY_CQ_HANDLE,
 198                         UVERBS_OBJECT_CQ,
 199                         UVERBS_ACCESS_DESTROY,
 200                         UA_MANDATORY),
 201         UVERBS_ATTR_PTR_OUT(UVERBS_ATTR_DESTROY_CQ_RESP,
 202                             UVERBS_ATTR_TYPE(struct ib_uverbs_destroy_cq_resp),
 203                             UA_MANDATORY));
 204 
 205 DECLARE_UVERBS_NAMED_OBJECT(
 206         UVERBS_OBJECT_CQ,
 207         UVERBS_TYPE_ALLOC_IDR_SZ(sizeof(struct ib_ucq_object), uverbs_free_cq),
 208 
 209 #if IS_ENABLED(CONFIG_INFINIBAND_EXP_LEGACY_VERBS_NEW_UAPI)
 210         &UVERBS_METHOD(UVERBS_METHOD_CQ_CREATE),
 211         &UVERBS_METHOD(UVERBS_METHOD_CQ_DESTROY)
 212 #endif
 213 );
 214 
 215 const struct uapi_definition uverbs_def_obj_cq[] = {
 216         UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_CQ,
 217                                       UAPI_DEF_OBJ_NEEDS_FN(destroy_cq)),
 218         {}
 219 };

/* [<][>][^][v][top][bottom][index][help] */