Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2005 Topspin Communications. All rights reserved. |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 3 | * Copyright (c) 2005 Intel Corporation. All rights reserved. |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 4 | * |
| 5 | * This software is available to you under a choice of one of two |
| 6 | * licenses. You may choose to be licensed under the terms of the GNU |
| 7 | * General Public License (GPL) Version 2, available from the file |
| 8 | * COPYING in the main directory of this source tree, or the |
| 9 | * OpenIB.org BSD license below: |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or |
| 12 | * without modification, are permitted provided that the following |
| 13 | * conditions are met: |
| 14 | * |
| 15 | * - Redistributions of source code must retain the above |
| 16 | * copyright notice, this list of conditions and the following |
| 17 | * disclaimer. |
| 18 | * |
| 19 | * - Redistributions in binary form must reproduce the above |
| 20 | * copyright notice, this list of conditions and the following |
| 21 | * disclaimer in the documentation and/or other materials |
| 22 | * provided with the distribution. |
| 23 | * |
| 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 25 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 26 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 27 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 28 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 29 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 30 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 31 | * SOFTWARE. |
| 32 | * |
| 33 | * $Id: ucm.c 2594 2005-06-13 19:46:02Z libor $ |
| 34 | */ |
Sean Hefty | 1b52fa98 | 2006-05-12 14:57:52 -0700 | [diff] [blame] | 35 | |
| 36 | #include <linux/completion.h> |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 37 | #include <linux/init.h> |
| 38 | #include <linux/fs.h> |
| 39 | #include <linux/module.h> |
| 40 | #include <linux/device.h> |
| 41 | #include <linux/err.h> |
| 42 | #include <linux/poll.h> |
| 43 | #include <linux/file.h> |
| 44 | #include <linux/mount.h> |
| 45 | #include <linux/cdev.h> |
Sean Hefty | 595e726 | 2005-10-17 15:33:47 -0700 | [diff] [blame] | 46 | #include <linux/idr.h> |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 47 | #include <linux/mutex.h> |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 48 | |
| 49 | #include <asm/uaccess.h> |
| 50 | |
Sean Hefty | 595e726 | 2005-10-17 15:33:47 -0700 | [diff] [blame] | 51 | #include <rdma/ib_cm.h> |
| 52 | #include <rdma/ib_user_cm.h> |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 53 | |
| 54 | MODULE_AUTHOR("Libor Michalek"); |
| 55 | MODULE_DESCRIPTION("InfiniBand userspace Connection Manager access"); |
| 56 | MODULE_LICENSE("Dual BSD/GPL"); |
| 57 | |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 58 | struct ib_ucm_device { |
| 59 | int devnum; |
| 60 | struct cdev dev; |
| 61 | struct class_device class_dev; |
| 62 | struct ib_device *ib_dev; |
| 63 | }; |
| 64 | |
Sean Hefty | 595e726 | 2005-10-17 15:33:47 -0700 | [diff] [blame] | 65 | struct ib_ucm_file { |
| 66 | struct semaphore mutex; |
| 67 | struct file *filp; |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 68 | struct ib_ucm_device *device; |
Hal Rosenstock | 79d8190 | 2005-07-27 20:38:56 -0700 | [diff] [blame] | 69 | |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 70 | struct list_head ctxs; |
| 71 | struct list_head events; |
Sean Hefty | 595e726 | 2005-10-17 15:33:47 -0700 | [diff] [blame] | 72 | wait_queue_head_t poll_wait; |
| 73 | }; |
| 74 | |
| 75 | struct ib_ucm_context { |
| 76 | int id; |
Sean Hefty | 1b52fa98 | 2006-05-12 14:57:52 -0700 | [diff] [blame] | 77 | struct completion comp; |
Sean Hefty | 595e726 | 2005-10-17 15:33:47 -0700 | [diff] [blame] | 78 | atomic_t ref; |
| 79 | int events_reported; |
| 80 | |
| 81 | struct ib_ucm_file *file; |
| 82 | struct ib_cm_id *cm_id; |
| 83 | __u64 uid; |
| 84 | |
| 85 | struct list_head events; /* list of pending events. */ |
| 86 | struct list_head file_list; /* member in file ctx list */ |
| 87 | }; |
| 88 | |
| 89 | struct ib_ucm_event { |
| 90 | struct ib_ucm_context *ctx; |
| 91 | struct list_head file_list; /* member in file event list */ |
| 92 | struct list_head ctx_list; /* member in ctx event list */ |
| 93 | |
| 94 | struct ib_cm_id *cm_id; |
| 95 | struct ib_ucm_event_resp resp; |
| 96 | void *data; |
| 97 | void *info; |
| 98 | int data_len; |
| 99 | int info_len; |
| 100 | }; |
Hal Rosenstock | 79d8190 | 2005-07-27 20:38:56 -0700 | [diff] [blame] | 101 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 102 | enum { |
| 103 | IB_UCM_MAJOR = 231, |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 104 | IB_UCM_BASE_MINOR = 224, |
| 105 | IB_UCM_MAX_DEVICES = 32 |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 106 | }; |
| 107 | |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 108 | #define IB_UCM_BASE_DEV MKDEV(IB_UCM_MAJOR, IB_UCM_BASE_MINOR) |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 109 | |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 110 | static void ib_ucm_add_one(struct ib_device *device); |
| 111 | static void ib_ucm_remove_one(struct ib_device *device); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 112 | |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 113 | static struct ib_client ucm_client = { |
| 114 | .name = "ucm", |
| 115 | .add = ib_ucm_add_one, |
| 116 | .remove = ib_ucm_remove_one |
| 117 | }; |
| 118 | |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 119 | static DEFINE_MUTEX(ctx_id_mutex); |
Roland Dreier | 762a03e | 2005-10-17 15:38:50 -0700 | [diff] [blame] | 120 | static DEFINE_IDR(ctx_id_table); |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 121 | static DECLARE_BITMAP(dev_map, IB_UCM_MAX_DEVICES); |
Sean Hefty | 595e726 | 2005-10-17 15:33:47 -0700 | [diff] [blame] | 122 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 123 | static struct ib_ucm_context *ib_ucm_ctx_get(struct ib_ucm_file *file, int id) |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 124 | { |
| 125 | struct ib_ucm_context *ctx; |
| 126 | |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 127 | mutex_lock(&ctx_id_mutex); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 128 | ctx = idr_find(&ctx_id_table, id); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 129 | if (!ctx) |
| 130 | ctx = ERR_PTR(-ENOENT); |
| 131 | else if (ctx->file != file) |
| 132 | ctx = ERR_PTR(-EINVAL); |
| 133 | else |
| 134 | atomic_inc(&ctx->ref); |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 135 | mutex_unlock(&ctx_id_mutex); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 136 | |
| 137 | return ctx; |
| 138 | } |
| 139 | |
| 140 | static void ib_ucm_ctx_put(struct ib_ucm_context *ctx) |
| 141 | { |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 142 | if (atomic_dec_and_test(&ctx->ref)) |
Sean Hefty | 1b52fa98 | 2006-05-12 14:57:52 -0700 | [diff] [blame] | 143 | complete(&ctx->comp); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 146 | static inline int ib_ucm_new_cm_id(int event) |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 147 | { |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 148 | return event == IB_CM_REQ_RECEIVED || event == IB_CM_SIDR_REQ_RECEIVED; |
| 149 | } |
| 150 | |
| 151 | static void ib_ucm_cleanup_events(struct ib_ucm_context *ctx) |
| 152 | { |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 153 | struct ib_ucm_event *uevent; |
| 154 | |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 155 | down(&ctx->file->mutex); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 156 | list_del(&ctx->file_list); |
| 157 | while (!list_empty(&ctx->events)) { |
| 158 | |
| 159 | uevent = list_entry(ctx->events.next, |
| 160 | struct ib_ucm_event, ctx_list); |
| 161 | list_del(&uevent->file_list); |
| 162 | list_del(&uevent->ctx_list); |
| 163 | |
| 164 | /* clear incoming connections. */ |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 165 | if (ib_ucm_new_cm_id(uevent->resp.event)) |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 166 | ib_destroy_cm_id(uevent->cm_id); |
| 167 | |
| 168 | kfree(uevent); |
| 169 | } |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 170 | up(&ctx->file->mutex); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | static struct ib_ucm_context *ib_ucm_ctx_alloc(struct ib_ucm_file *file) |
| 174 | { |
| 175 | struct ib_ucm_context *ctx; |
| 176 | int result; |
| 177 | |
Roland Dreier | de6eb66 | 2005-11-02 07:23:14 -0800 | [diff] [blame] | 178 | ctx = kzalloc(sizeof *ctx, GFP_KERNEL); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 179 | if (!ctx) |
| 180 | return NULL; |
| 181 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 182 | atomic_set(&ctx->ref, 1); |
Sean Hefty | 1b52fa98 | 2006-05-12 14:57:52 -0700 | [diff] [blame] | 183 | init_completion(&ctx->comp); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 184 | ctx->file = file; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 185 | INIT_LIST_HEAD(&ctx->events); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 186 | |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 187 | do { |
| 188 | result = idr_pre_get(&ctx_id_table, GFP_KERNEL); |
| 189 | if (!result) |
| 190 | goto error; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 191 | |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 192 | mutex_lock(&ctx_id_mutex); |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 193 | result = idr_get_new(&ctx_id_table, ctx, &ctx->id); |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 194 | mutex_unlock(&ctx_id_mutex); |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 195 | } while (result == -EAGAIN); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 196 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 197 | if (result) |
| 198 | goto error; |
| 199 | |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 200 | list_add_tail(&ctx->file_list, &file->ctxs); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 201 | return ctx; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 202 | |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 203 | error: |
| 204 | kfree(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 205 | return NULL; |
| 206 | } |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 207 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 208 | static void ib_ucm_event_path_get(struct ib_ucm_path_rec *upath, |
| 209 | struct ib_sa_path_rec *kpath) |
| 210 | { |
| 211 | if (!kpath || !upath) |
| 212 | return; |
| 213 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 214 | memcpy(upath->dgid, kpath->dgid.raw, sizeof *upath->dgid); |
| 215 | memcpy(upath->sgid, kpath->sgid.raw, sizeof *upath->sgid); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 216 | |
| 217 | upath->dlid = kpath->dlid; |
| 218 | upath->slid = kpath->slid; |
| 219 | upath->raw_traffic = kpath->raw_traffic; |
| 220 | upath->flow_label = kpath->flow_label; |
| 221 | upath->hop_limit = kpath->hop_limit; |
| 222 | upath->traffic_class = kpath->traffic_class; |
| 223 | upath->reversible = kpath->reversible; |
| 224 | upath->numb_path = kpath->numb_path; |
| 225 | upath->pkey = kpath->pkey; |
| 226 | upath->sl = kpath->sl; |
| 227 | upath->mtu_selector = kpath->mtu_selector; |
| 228 | upath->mtu = kpath->mtu; |
| 229 | upath->rate_selector = kpath->rate_selector; |
| 230 | upath->rate = kpath->rate; |
| 231 | upath->packet_life_time = kpath->packet_life_time; |
| 232 | upath->preference = kpath->preference; |
| 233 | |
| 234 | upath->packet_life_time_selector = |
| 235 | kpath->packet_life_time_selector; |
| 236 | } |
| 237 | |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 238 | static void ib_ucm_event_req_get(struct ib_ucm_req_event_resp *ureq, |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 239 | struct ib_cm_req_event_param *kreq) |
| 240 | { |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 241 | ureq->remote_ca_guid = kreq->remote_ca_guid; |
| 242 | ureq->remote_qkey = kreq->remote_qkey; |
| 243 | ureq->remote_qpn = kreq->remote_qpn; |
| 244 | ureq->qp_type = kreq->qp_type; |
| 245 | ureq->starting_psn = kreq->starting_psn; |
| 246 | ureq->responder_resources = kreq->responder_resources; |
| 247 | ureq->initiator_depth = kreq->initiator_depth; |
| 248 | ureq->local_cm_response_timeout = kreq->local_cm_response_timeout; |
| 249 | ureq->flow_control = kreq->flow_control; |
| 250 | ureq->remote_cm_response_timeout = kreq->remote_cm_response_timeout; |
| 251 | ureq->retry_count = kreq->retry_count; |
| 252 | ureq->rnr_retry_count = kreq->rnr_retry_count; |
| 253 | ureq->srq = kreq->srq; |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 254 | ureq->port = kreq->port; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 255 | |
| 256 | ib_ucm_event_path_get(&ureq->primary_path, kreq->primary_path); |
| 257 | ib_ucm_event_path_get(&ureq->alternate_path, kreq->alternate_path); |
| 258 | } |
| 259 | |
| 260 | static void ib_ucm_event_rep_get(struct ib_ucm_rep_event_resp *urep, |
| 261 | struct ib_cm_rep_event_param *krep) |
| 262 | { |
| 263 | urep->remote_ca_guid = krep->remote_ca_guid; |
| 264 | urep->remote_qkey = krep->remote_qkey; |
| 265 | urep->remote_qpn = krep->remote_qpn; |
| 266 | urep->starting_psn = krep->starting_psn; |
| 267 | urep->responder_resources = krep->responder_resources; |
| 268 | urep->initiator_depth = krep->initiator_depth; |
| 269 | urep->target_ack_delay = krep->target_ack_delay; |
| 270 | urep->failover_accepted = krep->failover_accepted; |
| 271 | urep->flow_control = krep->flow_control; |
| 272 | urep->rnr_retry_count = krep->rnr_retry_count; |
| 273 | urep->srq = krep->srq; |
| 274 | } |
| 275 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 276 | static void ib_ucm_event_sidr_rep_get(struct ib_ucm_sidr_rep_event_resp *urep, |
| 277 | struct ib_cm_sidr_rep_event_param *krep) |
| 278 | { |
| 279 | urep->status = krep->status; |
| 280 | urep->qkey = krep->qkey; |
| 281 | urep->qpn = krep->qpn; |
| 282 | }; |
| 283 | |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 284 | static int ib_ucm_event_process(struct ib_cm_event *evt, |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 285 | struct ib_ucm_event *uvt) |
| 286 | { |
| 287 | void *info = NULL; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 288 | |
| 289 | switch (evt->event) { |
| 290 | case IB_CM_REQ_RECEIVED: |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 291 | ib_ucm_event_req_get(&uvt->resp.u.req_resp, |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 292 | &evt->param.req_rcvd); |
| 293 | uvt->data_len = IB_CM_REQ_PRIVATE_DATA_SIZE; |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 294 | uvt->resp.present = IB_UCM_PRES_PRIMARY; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 295 | uvt->resp.present |= (evt->param.req_rcvd.alternate_path ? |
| 296 | IB_UCM_PRES_ALTERNATE : 0); |
| 297 | break; |
| 298 | case IB_CM_REP_RECEIVED: |
| 299 | ib_ucm_event_rep_get(&uvt->resp.u.rep_resp, |
| 300 | &evt->param.rep_rcvd); |
| 301 | uvt->data_len = IB_CM_REP_PRIVATE_DATA_SIZE; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 302 | break; |
| 303 | case IB_CM_RTU_RECEIVED: |
| 304 | uvt->data_len = IB_CM_RTU_PRIVATE_DATA_SIZE; |
| 305 | uvt->resp.u.send_status = evt->param.send_status; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 306 | break; |
| 307 | case IB_CM_DREQ_RECEIVED: |
| 308 | uvt->data_len = IB_CM_DREQ_PRIVATE_DATA_SIZE; |
| 309 | uvt->resp.u.send_status = evt->param.send_status; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 310 | break; |
| 311 | case IB_CM_DREP_RECEIVED: |
| 312 | uvt->data_len = IB_CM_DREP_PRIVATE_DATA_SIZE; |
| 313 | uvt->resp.u.send_status = evt->param.send_status; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 314 | break; |
| 315 | case IB_CM_MRA_RECEIVED: |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 316 | uvt->resp.u.mra_resp.timeout = |
| 317 | evt->param.mra_rcvd.service_timeout; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 318 | uvt->data_len = IB_CM_MRA_PRIVATE_DATA_SIZE; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 319 | break; |
| 320 | case IB_CM_REJ_RECEIVED: |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 321 | uvt->resp.u.rej_resp.reason = evt->param.rej_rcvd.reason; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 322 | uvt->data_len = IB_CM_REJ_PRIVATE_DATA_SIZE; |
| 323 | uvt->info_len = evt->param.rej_rcvd.ari_length; |
| 324 | info = evt->param.rej_rcvd.ari; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 325 | break; |
| 326 | case IB_CM_LAP_RECEIVED: |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 327 | ib_ucm_event_path_get(&uvt->resp.u.lap_resp.path, |
| 328 | evt->param.lap_rcvd.alternate_path); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 329 | uvt->data_len = IB_CM_LAP_PRIVATE_DATA_SIZE; |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 330 | uvt->resp.present = IB_UCM_PRES_ALTERNATE; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 331 | break; |
| 332 | case IB_CM_APR_RECEIVED: |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 333 | uvt->resp.u.apr_resp.status = evt->param.apr_rcvd.ap_status; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 334 | uvt->data_len = IB_CM_APR_PRIVATE_DATA_SIZE; |
| 335 | uvt->info_len = evt->param.apr_rcvd.info_len; |
| 336 | info = evt->param.apr_rcvd.apr_info; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 337 | break; |
| 338 | case IB_CM_SIDR_REQ_RECEIVED: |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 339 | uvt->resp.u.sidr_req_resp.pkey = |
| 340 | evt->param.sidr_req_rcvd.pkey; |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 341 | uvt->resp.u.sidr_req_resp.port = |
| 342 | evt->param.sidr_req_rcvd.port; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 343 | uvt->data_len = IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 344 | break; |
| 345 | case IB_CM_SIDR_REP_RECEIVED: |
| 346 | ib_ucm_event_sidr_rep_get(&uvt->resp.u.sidr_rep_resp, |
| 347 | &evt->param.sidr_rep_rcvd); |
| 348 | uvt->data_len = IB_CM_SIDR_REP_PRIVATE_DATA_SIZE; |
| 349 | uvt->info_len = evt->param.sidr_rep_rcvd.info_len; |
| 350 | info = evt->param.sidr_rep_rcvd.info; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 351 | break; |
| 352 | default: |
| 353 | uvt->resp.u.send_status = evt->param.send_status; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 354 | break; |
| 355 | } |
| 356 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 357 | if (uvt->data_len) { |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 358 | uvt->data = kmalloc(uvt->data_len, GFP_KERNEL); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 359 | if (!uvt->data) |
| 360 | goto err1; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 361 | |
| 362 | memcpy(uvt->data, evt->private_data, uvt->data_len); |
| 363 | uvt->resp.present |= IB_UCM_PRES_DATA; |
| 364 | } |
| 365 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 366 | if (uvt->info_len) { |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 367 | uvt->info = kmalloc(uvt->info_len, GFP_KERNEL); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 368 | if (!uvt->info) |
| 369 | goto err2; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 370 | |
| 371 | memcpy(uvt->info, info, uvt->info_len); |
| 372 | uvt->resp.present |= IB_UCM_PRES_INFO; |
| 373 | } |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 374 | return 0; |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 375 | |
| 376 | err2: |
Hal Rosenstock | 79d8190 | 2005-07-27 20:38:56 -0700 | [diff] [blame] | 377 | kfree(uvt->data); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 378 | err1: |
| 379 | return -ENOMEM; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | static int ib_ucm_event_handler(struct ib_cm_id *cm_id, |
| 383 | struct ib_cm_event *event) |
| 384 | { |
| 385 | struct ib_ucm_event *uevent; |
| 386 | struct ib_ucm_context *ctx; |
| 387 | int result = 0; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 388 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 389 | ctx = cm_id->context; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 390 | |
Roland Dreier | de6eb66 | 2005-11-02 07:23:14 -0800 | [diff] [blame] | 391 | uevent = kzalloc(sizeof *uevent, GFP_KERNEL); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 392 | if (!uevent) |
| 393 | goto err1; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 394 | |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 395 | uevent->ctx = ctx; |
| 396 | uevent->cm_id = cm_id; |
| 397 | uevent->resp.uid = ctx->uid; |
| 398 | uevent->resp.id = ctx->id; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 399 | uevent->resp.event = event->event; |
| 400 | |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 401 | result = ib_ucm_event_process(event, uevent); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 402 | if (result) |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 403 | goto err2; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 404 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 405 | down(&ctx->file->mutex); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 406 | list_add_tail(&uevent->file_list, &ctx->file->events); |
| 407 | list_add_tail(&uevent->ctx_list, &ctx->events); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 408 | wake_up_interruptible(&ctx->file->poll_wait); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 409 | up(&ctx->file->mutex); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 410 | return 0; |
| 411 | |
| 412 | err2: |
| 413 | kfree(uevent); |
| 414 | err1: |
| 415 | /* Destroy new cm_id's */ |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 416 | return ib_ucm_new_cm_id(event->event); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | static ssize_t ib_ucm_event(struct ib_ucm_file *file, |
| 420 | const char __user *inbuf, |
| 421 | int in_len, int out_len) |
| 422 | { |
| 423 | struct ib_ucm_context *ctx; |
| 424 | struct ib_ucm_event_get cmd; |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 425 | struct ib_ucm_event *uevent; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 426 | int result = 0; |
| 427 | DEFINE_WAIT(wait); |
| 428 | |
| 429 | if (out_len < sizeof(struct ib_ucm_event_resp)) |
| 430 | return -ENOSPC; |
| 431 | |
| 432 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 433 | return -EFAULT; |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 434 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 435 | down(&file->mutex); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 436 | while (list_empty(&file->events)) { |
| 437 | |
| 438 | if (file->filp->f_flags & O_NONBLOCK) { |
| 439 | result = -EAGAIN; |
| 440 | break; |
| 441 | } |
| 442 | |
| 443 | if (signal_pending(current)) { |
| 444 | result = -ERESTARTSYS; |
| 445 | break; |
| 446 | } |
| 447 | |
| 448 | prepare_to_wait(&file->poll_wait, &wait, TASK_INTERRUPTIBLE); |
| 449 | |
| 450 | up(&file->mutex); |
| 451 | schedule(); |
| 452 | down(&file->mutex); |
| 453 | |
| 454 | finish_wait(&file->poll_wait, &wait); |
| 455 | } |
| 456 | |
| 457 | if (result) |
| 458 | goto done; |
| 459 | |
| 460 | uevent = list_entry(file->events.next, struct ib_ucm_event, file_list); |
| 461 | |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 462 | if (ib_ucm_new_cm_id(uevent->resp.event)) { |
| 463 | ctx = ib_ucm_ctx_alloc(file); |
| 464 | if (!ctx) { |
| 465 | result = -ENOMEM; |
| 466 | goto done; |
| 467 | } |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 468 | |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 469 | ctx->cm_id = uevent->cm_id; |
| 470 | ctx->cm_id->context = ctx; |
| 471 | uevent->resp.id = ctx->id; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 474 | if (copy_to_user((void __user *)(unsigned long)cmd.response, |
| 475 | &uevent->resp, sizeof(uevent->resp))) { |
| 476 | result = -EFAULT; |
| 477 | goto done; |
| 478 | } |
| 479 | |
| 480 | if (uevent->data) { |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 481 | if (cmd.data_len < uevent->data_len) { |
| 482 | result = -ENOMEM; |
| 483 | goto done; |
| 484 | } |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 485 | if (copy_to_user((void __user *)(unsigned long)cmd.data, |
| 486 | uevent->data, uevent->data_len)) { |
| 487 | result = -EFAULT; |
| 488 | goto done; |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | if (uevent->info) { |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 493 | if (cmd.info_len < uevent->info_len) { |
| 494 | result = -ENOMEM; |
| 495 | goto done; |
| 496 | } |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 497 | if (copy_to_user((void __user *)(unsigned long)cmd.info, |
| 498 | uevent->info, uevent->info_len)) { |
| 499 | result = -EFAULT; |
| 500 | goto done; |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | list_del(&uevent->file_list); |
| 505 | list_del(&uevent->ctx_list); |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 506 | uevent->ctx->events_reported++; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 507 | |
Hal Rosenstock | 79d8190 | 2005-07-27 20:38:56 -0700 | [diff] [blame] | 508 | kfree(uevent->data); |
| 509 | kfree(uevent->info); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 510 | kfree(uevent); |
| 511 | done: |
| 512 | up(&file->mutex); |
| 513 | return result; |
| 514 | } |
| 515 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 516 | static ssize_t ib_ucm_create_id(struct ib_ucm_file *file, |
| 517 | const char __user *inbuf, |
| 518 | int in_len, int out_len) |
| 519 | { |
| 520 | struct ib_ucm_create_id cmd; |
| 521 | struct ib_ucm_create_id_resp resp; |
| 522 | struct ib_ucm_context *ctx; |
| 523 | int result; |
| 524 | |
| 525 | if (out_len < sizeof(resp)) |
| 526 | return -ENOSPC; |
| 527 | |
| 528 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 529 | return -EFAULT; |
| 530 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 531 | down(&file->mutex); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 532 | ctx = ib_ucm_ctx_alloc(file); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 533 | up(&file->mutex); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 534 | if (!ctx) |
| 535 | return -ENOMEM; |
| 536 | |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 537 | ctx->uid = cmd.uid; |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 538 | ctx->cm_id = ib_create_cm_id(file->device->ib_dev, |
| 539 | ib_ucm_event_handler, ctx); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 540 | if (IS_ERR(ctx->cm_id)) { |
| 541 | result = PTR_ERR(ctx->cm_id); |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 542 | goto err1; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | resp.id = ctx->id; |
| 546 | if (copy_to_user((void __user *)(unsigned long)cmd.response, |
| 547 | &resp, sizeof(resp))) { |
| 548 | result = -EFAULT; |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 549 | goto err2; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 550 | } |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 551 | return 0; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 552 | |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 553 | err2: |
| 554 | ib_destroy_cm_id(ctx->cm_id); |
| 555 | err1: |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 556 | mutex_lock(&ctx_id_mutex); |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 557 | idr_remove(&ctx_id_table, ctx->id); |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 558 | mutex_unlock(&ctx_id_mutex); |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 559 | kfree(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 560 | return result; |
| 561 | } |
| 562 | |
| 563 | static ssize_t ib_ucm_destroy_id(struct ib_ucm_file *file, |
| 564 | const char __user *inbuf, |
| 565 | int in_len, int out_len) |
| 566 | { |
| 567 | struct ib_ucm_destroy_id cmd; |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 568 | struct ib_ucm_destroy_id_resp resp; |
| 569 | struct ib_ucm_context *ctx; |
| 570 | int result = 0; |
| 571 | |
| 572 | if (out_len < sizeof(resp)) |
| 573 | return -ENOSPC; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 574 | |
| 575 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 576 | return -EFAULT; |
| 577 | |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 578 | mutex_lock(&ctx_id_mutex); |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 579 | ctx = idr_find(&ctx_id_table, cmd.id); |
| 580 | if (!ctx) |
| 581 | ctx = ERR_PTR(-ENOENT); |
| 582 | else if (ctx->file != file) |
| 583 | ctx = ERR_PTR(-EINVAL); |
| 584 | else |
| 585 | idr_remove(&ctx_id_table, ctx->id); |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 586 | mutex_unlock(&ctx_id_mutex); |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 587 | |
| 588 | if (IS_ERR(ctx)) |
| 589 | return PTR_ERR(ctx); |
| 590 | |
Sean Hefty | 1b52fa98 | 2006-05-12 14:57:52 -0700 | [diff] [blame] | 591 | ib_ucm_ctx_put(ctx); |
| 592 | wait_for_completion(&ctx->comp); |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 593 | |
| 594 | /* No new events will be generated after destroying the cm_id. */ |
| 595 | ib_destroy_cm_id(ctx->cm_id); |
| 596 | /* Cleanup events not yet reported to the user. */ |
| 597 | ib_ucm_cleanup_events(ctx); |
| 598 | |
| 599 | resp.events_reported = ctx->events_reported; |
| 600 | if (copy_to_user((void __user *)(unsigned long)cmd.response, |
| 601 | &resp, sizeof(resp))) |
| 602 | result = -EFAULT; |
| 603 | |
| 604 | kfree(ctx); |
| 605 | return result; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | static ssize_t ib_ucm_attr_id(struct ib_ucm_file *file, |
| 609 | const char __user *inbuf, |
| 610 | int in_len, int out_len) |
| 611 | { |
| 612 | struct ib_ucm_attr_id_resp resp; |
| 613 | struct ib_ucm_attr_id cmd; |
| 614 | struct ib_ucm_context *ctx; |
| 615 | int result = 0; |
| 616 | |
| 617 | if (out_len < sizeof(resp)) |
| 618 | return -ENOSPC; |
| 619 | |
| 620 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 621 | return -EFAULT; |
| 622 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 623 | ctx = ib_ucm_ctx_get(file, cmd.id); |
| 624 | if (IS_ERR(ctx)) |
| 625 | return PTR_ERR(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 626 | |
| 627 | resp.service_id = ctx->cm_id->service_id; |
| 628 | resp.service_mask = ctx->cm_id->service_mask; |
| 629 | resp.local_id = ctx->cm_id->local_id; |
| 630 | resp.remote_id = ctx->cm_id->remote_id; |
| 631 | |
| 632 | if (copy_to_user((void __user *)(unsigned long)cmd.response, |
| 633 | &resp, sizeof(resp))) |
| 634 | result = -EFAULT; |
| 635 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 636 | ib_ucm_ctx_put(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 637 | return result; |
| 638 | } |
| 639 | |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 640 | static void ib_ucm_copy_ah_attr(struct ib_ucm_ah_attr *dest_attr, |
| 641 | struct ib_ah_attr *src_attr) |
| 642 | { |
| 643 | memcpy(dest_attr->grh_dgid, src_attr->grh.dgid.raw, |
| 644 | sizeof src_attr->grh.dgid); |
| 645 | dest_attr->grh_flow_label = src_attr->grh.flow_label; |
| 646 | dest_attr->grh_sgid_index = src_attr->grh.sgid_index; |
| 647 | dest_attr->grh_hop_limit = src_attr->grh.hop_limit; |
| 648 | dest_attr->grh_traffic_class = src_attr->grh.traffic_class; |
| 649 | |
| 650 | dest_attr->dlid = src_attr->dlid; |
| 651 | dest_attr->sl = src_attr->sl; |
| 652 | dest_attr->src_path_bits = src_attr->src_path_bits; |
| 653 | dest_attr->static_rate = src_attr->static_rate; |
| 654 | dest_attr->is_global = (src_attr->ah_flags & IB_AH_GRH); |
| 655 | dest_attr->port_num = src_attr->port_num; |
| 656 | } |
| 657 | |
| 658 | static void ib_ucm_copy_qp_attr(struct ib_ucm_init_qp_attr_resp *dest_attr, |
| 659 | struct ib_qp_attr *src_attr) |
| 660 | { |
| 661 | dest_attr->cur_qp_state = src_attr->cur_qp_state; |
| 662 | dest_attr->path_mtu = src_attr->path_mtu; |
| 663 | dest_attr->path_mig_state = src_attr->path_mig_state; |
| 664 | dest_attr->qkey = src_attr->qkey; |
| 665 | dest_attr->rq_psn = src_attr->rq_psn; |
| 666 | dest_attr->sq_psn = src_attr->sq_psn; |
| 667 | dest_attr->dest_qp_num = src_attr->dest_qp_num; |
| 668 | dest_attr->qp_access_flags = src_attr->qp_access_flags; |
| 669 | |
| 670 | dest_attr->max_send_wr = src_attr->cap.max_send_wr; |
| 671 | dest_attr->max_recv_wr = src_attr->cap.max_recv_wr; |
| 672 | dest_attr->max_send_sge = src_attr->cap.max_send_sge; |
| 673 | dest_attr->max_recv_sge = src_attr->cap.max_recv_sge; |
| 674 | dest_attr->max_inline_data = src_attr->cap.max_inline_data; |
| 675 | |
| 676 | ib_ucm_copy_ah_attr(&dest_attr->ah_attr, &src_attr->ah_attr); |
| 677 | ib_ucm_copy_ah_attr(&dest_attr->alt_ah_attr, &src_attr->alt_ah_attr); |
| 678 | |
| 679 | dest_attr->pkey_index = src_attr->pkey_index; |
| 680 | dest_attr->alt_pkey_index = src_attr->alt_pkey_index; |
| 681 | dest_attr->en_sqd_async_notify = src_attr->en_sqd_async_notify; |
| 682 | dest_attr->sq_draining = src_attr->sq_draining; |
| 683 | dest_attr->max_rd_atomic = src_attr->max_rd_atomic; |
| 684 | dest_attr->max_dest_rd_atomic = src_attr->max_dest_rd_atomic; |
| 685 | dest_attr->min_rnr_timer = src_attr->min_rnr_timer; |
| 686 | dest_attr->port_num = src_attr->port_num; |
| 687 | dest_attr->timeout = src_attr->timeout; |
| 688 | dest_attr->retry_cnt = src_attr->retry_cnt; |
| 689 | dest_attr->rnr_retry = src_attr->rnr_retry; |
| 690 | dest_attr->alt_port_num = src_attr->alt_port_num; |
| 691 | dest_attr->alt_timeout = src_attr->alt_timeout; |
| 692 | } |
| 693 | |
| 694 | static ssize_t ib_ucm_init_qp_attr(struct ib_ucm_file *file, |
| 695 | const char __user *inbuf, |
| 696 | int in_len, int out_len) |
| 697 | { |
| 698 | struct ib_ucm_init_qp_attr_resp resp; |
| 699 | struct ib_ucm_init_qp_attr cmd; |
| 700 | struct ib_ucm_context *ctx; |
| 701 | struct ib_qp_attr qp_attr; |
| 702 | int result = 0; |
| 703 | |
| 704 | if (out_len < sizeof(resp)) |
| 705 | return -ENOSPC; |
| 706 | |
| 707 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 708 | return -EFAULT; |
| 709 | |
| 710 | ctx = ib_ucm_ctx_get(file, cmd.id); |
| 711 | if (IS_ERR(ctx)) |
| 712 | return PTR_ERR(ctx); |
| 713 | |
| 714 | resp.qp_attr_mask = 0; |
| 715 | memset(&qp_attr, 0, sizeof qp_attr); |
| 716 | qp_attr.qp_state = cmd.qp_state; |
| 717 | result = ib_cm_init_qp_attr(ctx->cm_id, &qp_attr, &resp.qp_attr_mask); |
| 718 | if (result) |
| 719 | goto out; |
| 720 | |
| 721 | ib_ucm_copy_qp_attr(&resp, &qp_attr); |
| 722 | |
| 723 | if (copy_to_user((void __user *)(unsigned long)cmd.response, |
| 724 | &resp, sizeof(resp))) |
| 725 | result = -EFAULT; |
| 726 | |
| 727 | out: |
| 728 | ib_ucm_ctx_put(ctx); |
| 729 | return result; |
| 730 | } |
| 731 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 732 | static ssize_t ib_ucm_listen(struct ib_ucm_file *file, |
| 733 | const char __user *inbuf, |
| 734 | int in_len, int out_len) |
| 735 | { |
| 736 | struct ib_ucm_listen cmd; |
| 737 | struct ib_ucm_context *ctx; |
| 738 | int result; |
| 739 | |
| 740 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 741 | return -EFAULT; |
| 742 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 743 | ctx = ib_ucm_ctx_get(file, cmd.id); |
| 744 | if (IS_ERR(ctx)) |
| 745 | return PTR_ERR(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 746 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 747 | result = ib_cm_listen(ctx->cm_id, cmd.service_id, cmd.service_mask); |
| 748 | ib_ucm_ctx_put(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 749 | return result; |
| 750 | } |
| 751 | |
| 752 | static ssize_t ib_ucm_establish(struct ib_ucm_file *file, |
| 753 | const char __user *inbuf, |
| 754 | int in_len, int out_len) |
| 755 | { |
| 756 | struct ib_ucm_establish cmd; |
| 757 | struct ib_ucm_context *ctx; |
| 758 | int result; |
| 759 | |
| 760 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 761 | return -EFAULT; |
| 762 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 763 | ctx = ib_ucm_ctx_get(file, cmd.id); |
| 764 | if (IS_ERR(ctx)) |
| 765 | return PTR_ERR(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 766 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 767 | result = ib_cm_establish(ctx->cm_id); |
| 768 | ib_ucm_ctx_put(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 769 | return result; |
| 770 | } |
| 771 | |
| 772 | static int ib_ucm_alloc_data(const void **dest, u64 src, u32 len) |
| 773 | { |
| 774 | void *data; |
| 775 | |
| 776 | *dest = NULL; |
| 777 | |
| 778 | if (!len) |
| 779 | return 0; |
| 780 | |
| 781 | data = kmalloc(len, GFP_KERNEL); |
| 782 | if (!data) |
| 783 | return -ENOMEM; |
| 784 | |
| 785 | if (copy_from_user(data, (void __user *)(unsigned long)src, len)) { |
| 786 | kfree(data); |
| 787 | return -EFAULT; |
| 788 | } |
| 789 | |
| 790 | *dest = data; |
| 791 | return 0; |
| 792 | } |
| 793 | |
| 794 | static int ib_ucm_path_get(struct ib_sa_path_rec **path, u64 src) |
| 795 | { |
| 796 | struct ib_ucm_path_rec ucm_path; |
| 797 | struct ib_sa_path_rec *sa_path; |
| 798 | |
| 799 | *path = NULL; |
| 800 | |
| 801 | if (!src) |
| 802 | return 0; |
| 803 | |
| 804 | sa_path = kmalloc(sizeof(*sa_path), GFP_KERNEL); |
| 805 | if (!sa_path) |
| 806 | return -ENOMEM; |
| 807 | |
| 808 | if (copy_from_user(&ucm_path, (void __user *)(unsigned long)src, |
| 809 | sizeof(ucm_path))) { |
| 810 | |
| 811 | kfree(sa_path); |
| 812 | return -EFAULT; |
| 813 | } |
| 814 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 815 | memcpy(sa_path->dgid.raw, ucm_path.dgid, sizeof sa_path->dgid); |
| 816 | memcpy(sa_path->sgid.raw, ucm_path.sgid, sizeof sa_path->sgid); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 817 | |
| 818 | sa_path->dlid = ucm_path.dlid; |
| 819 | sa_path->slid = ucm_path.slid; |
| 820 | sa_path->raw_traffic = ucm_path.raw_traffic; |
| 821 | sa_path->flow_label = ucm_path.flow_label; |
| 822 | sa_path->hop_limit = ucm_path.hop_limit; |
| 823 | sa_path->traffic_class = ucm_path.traffic_class; |
| 824 | sa_path->reversible = ucm_path.reversible; |
| 825 | sa_path->numb_path = ucm_path.numb_path; |
| 826 | sa_path->pkey = ucm_path.pkey; |
| 827 | sa_path->sl = ucm_path.sl; |
| 828 | sa_path->mtu_selector = ucm_path.mtu_selector; |
| 829 | sa_path->mtu = ucm_path.mtu; |
| 830 | sa_path->rate_selector = ucm_path.rate_selector; |
| 831 | sa_path->rate = ucm_path.rate; |
| 832 | sa_path->packet_life_time = ucm_path.packet_life_time; |
| 833 | sa_path->preference = ucm_path.preference; |
| 834 | |
| 835 | sa_path->packet_life_time_selector = |
| 836 | ucm_path.packet_life_time_selector; |
| 837 | |
| 838 | *path = sa_path; |
| 839 | return 0; |
| 840 | } |
| 841 | |
| 842 | static ssize_t ib_ucm_send_req(struct ib_ucm_file *file, |
| 843 | const char __user *inbuf, |
| 844 | int in_len, int out_len) |
| 845 | { |
| 846 | struct ib_cm_req_param param; |
| 847 | struct ib_ucm_context *ctx; |
| 848 | struct ib_ucm_req cmd; |
| 849 | int result; |
| 850 | |
| 851 | param.private_data = NULL; |
| 852 | param.primary_path = NULL; |
| 853 | param.alternate_path = NULL; |
| 854 | |
| 855 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 856 | return -EFAULT; |
| 857 | |
| 858 | result = ib_ucm_alloc_data(¶m.private_data, cmd.data, cmd.len); |
| 859 | if (result) |
| 860 | goto done; |
| 861 | |
| 862 | result = ib_ucm_path_get(¶m.primary_path, cmd.primary_path); |
| 863 | if (result) |
| 864 | goto done; |
| 865 | |
| 866 | result = ib_ucm_path_get(¶m.alternate_path, cmd.alternate_path); |
| 867 | if (result) |
| 868 | goto done; |
| 869 | |
| 870 | param.private_data_len = cmd.len; |
| 871 | param.service_id = cmd.sid; |
| 872 | param.qp_num = cmd.qpn; |
| 873 | param.qp_type = cmd.qp_type; |
| 874 | param.starting_psn = cmd.psn; |
| 875 | param.peer_to_peer = cmd.peer_to_peer; |
| 876 | param.responder_resources = cmd.responder_resources; |
| 877 | param.initiator_depth = cmd.initiator_depth; |
| 878 | param.remote_cm_response_timeout = cmd.remote_cm_response_timeout; |
| 879 | param.flow_control = cmd.flow_control; |
| 880 | param.local_cm_response_timeout = cmd.local_cm_response_timeout; |
| 881 | param.retry_count = cmd.retry_count; |
| 882 | param.rnr_retry_count = cmd.rnr_retry_count; |
| 883 | param.max_cm_retries = cmd.max_cm_retries; |
| 884 | param.srq = cmd.srq; |
| 885 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 886 | ctx = ib_ucm_ctx_get(file, cmd.id); |
| 887 | if (!IS_ERR(ctx)) { |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 888 | result = ib_send_cm_req(ctx->cm_id, ¶m); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 889 | ib_ucm_ctx_put(ctx); |
| 890 | } else |
| 891 | result = PTR_ERR(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 892 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 893 | done: |
Hal Rosenstock | 79d8190 | 2005-07-27 20:38:56 -0700 | [diff] [blame] | 894 | kfree(param.private_data); |
| 895 | kfree(param.primary_path); |
| 896 | kfree(param.alternate_path); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 897 | return result; |
| 898 | } |
| 899 | |
| 900 | static ssize_t ib_ucm_send_rep(struct ib_ucm_file *file, |
| 901 | const char __user *inbuf, |
| 902 | int in_len, int out_len) |
| 903 | { |
| 904 | struct ib_cm_rep_param param; |
| 905 | struct ib_ucm_context *ctx; |
| 906 | struct ib_ucm_rep cmd; |
| 907 | int result; |
| 908 | |
| 909 | param.private_data = NULL; |
| 910 | |
| 911 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 912 | return -EFAULT; |
| 913 | |
| 914 | result = ib_ucm_alloc_data(¶m.private_data, cmd.data, cmd.len); |
| 915 | if (result) |
| 916 | return result; |
| 917 | |
| 918 | param.qp_num = cmd.qpn; |
| 919 | param.starting_psn = cmd.psn; |
| 920 | param.private_data_len = cmd.len; |
| 921 | param.responder_resources = cmd.responder_resources; |
| 922 | param.initiator_depth = cmd.initiator_depth; |
| 923 | param.target_ack_delay = cmd.target_ack_delay; |
| 924 | param.failover_accepted = cmd.failover_accepted; |
| 925 | param.flow_control = cmd.flow_control; |
| 926 | param.rnr_retry_count = cmd.rnr_retry_count; |
| 927 | param.srq = cmd.srq; |
| 928 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 929 | ctx = ib_ucm_ctx_get(file, cmd.id); |
| 930 | if (!IS_ERR(ctx)) { |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 931 | ctx->uid = cmd.uid; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 932 | result = ib_send_cm_rep(ctx->cm_id, ¶m); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 933 | ib_ucm_ctx_put(ctx); |
| 934 | } else |
| 935 | result = PTR_ERR(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 936 | |
Hal Rosenstock | 79d8190 | 2005-07-27 20:38:56 -0700 | [diff] [blame] | 937 | kfree(param.private_data); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 938 | return result; |
| 939 | } |
| 940 | |
| 941 | static ssize_t ib_ucm_send_private_data(struct ib_ucm_file *file, |
| 942 | const char __user *inbuf, int in_len, |
| 943 | int (*func)(struct ib_cm_id *cm_id, |
| 944 | const void *private_data, |
| 945 | u8 private_data_len)) |
| 946 | { |
| 947 | struct ib_ucm_private_data cmd; |
| 948 | struct ib_ucm_context *ctx; |
| 949 | const void *private_data = NULL; |
| 950 | int result; |
| 951 | |
| 952 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 953 | return -EFAULT; |
| 954 | |
| 955 | result = ib_ucm_alloc_data(&private_data, cmd.data, cmd.len); |
| 956 | if (result) |
| 957 | return result; |
| 958 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 959 | ctx = ib_ucm_ctx_get(file, cmd.id); |
| 960 | if (!IS_ERR(ctx)) { |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 961 | result = func(ctx->cm_id, private_data, cmd.len); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 962 | ib_ucm_ctx_put(ctx); |
| 963 | } else |
| 964 | result = PTR_ERR(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 965 | |
Hal Rosenstock | 79d8190 | 2005-07-27 20:38:56 -0700 | [diff] [blame] | 966 | kfree(private_data); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 967 | return result; |
| 968 | } |
| 969 | |
| 970 | static ssize_t ib_ucm_send_rtu(struct ib_ucm_file *file, |
| 971 | const char __user *inbuf, |
| 972 | int in_len, int out_len) |
| 973 | { |
| 974 | return ib_ucm_send_private_data(file, inbuf, in_len, ib_send_cm_rtu); |
| 975 | } |
| 976 | |
| 977 | static ssize_t ib_ucm_send_dreq(struct ib_ucm_file *file, |
| 978 | const char __user *inbuf, |
| 979 | int in_len, int out_len) |
| 980 | { |
| 981 | return ib_ucm_send_private_data(file, inbuf, in_len, ib_send_cm_dreq); |
| 982 | } |
| 983 | |
| 984 | static ssize_t ib_ucm_send_drep(struct ib_ucm_file *file, |
| 985 | const char __user *inbuf, |
| 986 | int in_len, int out_len) |
| 987 | { |
| 988 | return ib_ucm_send_private_data(file, inbuf, in_len, ib_send_cm_drep); |
| 989 | } |
| 990 | |
| 991 | static ssize_t ib_ucm_send_info(struct ib_ucm_file *file, |
| 992 | const char __user *inbuf, int in_len, |
| 993 | int (*func)(struct ib_cm_id *cm_id, |
| 994 | int status, |
| 995 | const void *info, |
| 996 | u8 info_len, |
| 997 | const void *data, |
| 998 | u8 data_len)) |
| 999 | { |
| 1000 | struct ib_ucm_context *ctx; |
| 1001 | struct ib_ucm_info cmd; |
| 1002 | const void *data = NULL; |
| 1003 | const void *info = NULL; |
| 1004 | int result; |
| 1005 | |
| 1006 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 1007 | return -EFAULT; |
| 1008 | |
| 1009 | result = ib_ucm_alloc_data(&data, cmd.data, cmd.data_len); |
| 1010 | if (result) |
| 1011 | goto done; |
| 1012 | |
| 1013 | result = ib_ucm_alloc_data(&info, cmd.info, cmd.info_len); |
| 1014 | if (result) |
| 1015 | goto done; |
| 1016 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 1017 | ctx = ib_ucm_ctx_get(file, cmd.id); |
| 1018 | if (!IS_ERR(ctx)) { |
| 1019 | result = func(ctx->cm_id, cmd.status, info, cmd.info_len, |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1020 | data, cmd.data_len); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 1021 | ib_ucm_ctx_put(ctx); |
| 1022 | } else |
| 1023 | result = PTR_ERR(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1024 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1025 | done: |
Hal Rosenstock | 79d8190 | 2005-07-27 20:38:56 -0700 | [diff] [blame] | 1026 | kfree(data); |
| 1027 | kfree(info); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1028 | return result; |
| 1029 | } |
| 1030 | |
| 1031 | static ssize_t ib_ucm_send_rej(struct ib_ucm_file *file, |
| 1032 | const char __user *inbuf, |
| 1033 | int in_len, int out_len) |
| 1034 | { |
| 1035 | return ib_ucm_send_info(file, inbuf, in_len, (void *)ib_send_cm_rej); |
| 1036 | } |
| 1037 | |
| 1038 | static ssize_t ib_ucm_send_apr(struct ib_ucm_file *file, |
| 1039 | const char __user *inbuf, |
| 1040 | int in_len, int out_len) |
| 1041 | { |
| 1042 | return ib_ucm_send_info(file, inbuf, in_len, (void *)ib_send_cm_apr); |
| 1043 | } |
| 1044 | |
| 1045 | static ssize_t ib_ucm_send_mra(struct ib_ucm_file *file, |
| 1046 | const char __user *inbuf, |
| 1047 | int in_len, int out_len) |
| 1048 | { |
| 1049 | struct ib_ucm_context *ctx; |
| 1050 | struct ib_ucm_mra cmd; |
| 1051 | const void *data = NULL; |
| 1052 | int result; |
| 1053 | |
| 1054 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 1055 | return -EFAULT; |
| 1056 | |
| 1057 | result = ib_ucm_alloc_data(&data, cmd.data, cmd.len); |
| 1058 | if (result) |
| 1059 | return result; |
| 1060 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 1061 | ctx = ib_ucm_ctx_get(file, cmd.id); |
| 1062 | if (!IS_ERR(ctx)) { |
| 1063 | result = ib_send_cm_mra(ctx->cm_id, cmd.timeout, data, cmd.len); |
| 1064 | ib_ucm_ctx_put(ctx); |
| 1065 | } else |
| 1066 | result = PTR_ERR(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1067 | |
Hal Rosenstock | 79d8190 | 2005-07-27 20:38:56 -0700 | [diff] [blame] | 1068 | kfree(data); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1069 | return result; |
| 1070 | } |
| 1071 | |
| 1072 | static ssize_t ib_ucm_send_lap(struct ib_ucm_file *file, |
| 1073 | const char __user *inbuf, |
| 1074 | int in_len, int out_len) |
| 1075 | { |
| 1076 | struct ib_ucm_context *ctx; |
| 1077 | struct ib_sa_path_rec *path = NULL; |
| 1078 | struct ib_ucm_lap cmd; |
| 1079 | const void *data = NULL; |
| 1080 | int result; |
| 1081 | |
| 1082 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 1083 | return -EFAULT; |
| 1084 | |
| 1085 | result = ib_ucm_alloc_data(&data, cmd.data, cmd.len); |
| 1086 | if (result) |
| 1087 | goto done; |
| 1088 | |
| 1089 | result = ib_ucm_path_get(&path, cmd.path); |
| 1090 | if (result) |
| 1091 | goto done; |
| 1092 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 1093 | ctx = ib_ucm_ctx_get(file, cmd.id); |
| 1094 | if (!IS_ERR(ctx)) { |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1095 | result = ib_send_cm_lap(ctx->cm_id, path, data, cmd.len); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 1096 | ib_ucm_ctx_put(ctx); |
| 1097 | } else |
| 1098 | result = PTR_ERR(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1099 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1100 | done: |
Hal Rosenstock | 79d8190 | 2005-07-27 20:38:56 -0700 | [diff] [blame] | 1101 | kfree(data); |
| 1102 | kfree(path); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1103 | return result; |
| 1104 | } |
| 1105 | |
| 1106 | static ssize_t ib_ucm_send_sidr_req(struct ib_ucm_file *file, |
| 1107 | const char __user *inbuf, |
| 1108 | int in_len, int out_len) |
| 1109 | { |
| 1110 | struct ib_cm_sidr_req_param param; |
| 1111 | struct ib_ucm_context *ctx; |
| 1112 | struct ib_ucm_sidr_req cmd; |
| 1113 | int result; |
| 1114 | |
| 1115 | param.private_data = NULL; |
| 1116 | param.path = NULL; |
| 1117 | |
| 1118 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 1119 | return -EFAULT; |
| 1120 | |
| 1121 | result = ib_ucm_alloc_data(¶m.private_data, cmd.data, cmd.len); |
| 1122 | if (result) |
| 1123 | goto done; |
| 1124 | |
| 1125 | result = ib_ucm_path_get(¶m.path, cmd.path); |
| 1126 | if (result) |
| 1127 | goto done; |
| 1128 | |
| 1129 | param.private_data_len = cmd.len; |
| 1130 | param.service_id = cmd.sid; |
| 1131 | param.timeout_ms = cmd.timeout; |
| 1132 | param.max_cm_retries = cmd.max_cm_retries; |
| 1133 | param.pkey = cmd.pkey; |
| 1134 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 1135 | ctx = ib_ucm_ctx_get(file, cmd.id); |
| 1136 | if (!IS_ERR(ctx)) { |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1137 | result = ib_send_cm_sidr_req(ctx->cm_id, ¶m); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 1138 | ib_ucm_ctx_put(ctx); |
| 1139 | } else |
| 1140 | result = PTR_ERR(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1141 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1142 | done: |
Hal Rosenstock | 79d8190 | 2005-07-27 20:38:56 -0700 | [diff] [blame] | 1143 | kfree(param.private_data); |
| 1144 | kfree(param.path); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1145 | return result; |
| 1146 | } |
| 1147 | |
| 1148 | static ssize_t ib_ucm_send_sidr_rep(struct ib_ucm_file *file, |
| 1149 | const char __user *inbuf, |
| 1150 | int in_len, int out_len) |
| 1151 | { |
| 1152 | struct ib_cm_sidr_rep_param param; |
| 1153 | struct ib_ucm_sidr_rep cmd; |
| 1154 | struct ib_ucm_context *ctx; |
| 1155 | int result; |
| 1156 | |
| 1157 | param.info = NULL; |
| 1158 | |
| 1159 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 1160 | return -EFAULT; |
| 1161 | |
| 1162 | result = ib_ucm_alloc_data(¶m.private_data, |
| 1163 | cmd.data, cmd.data_len); |
| 1164 | if (result) |
| 1165 | goto done; |
| 1166 | |
| 1167 | result = ib_ucm_alloc_data(¶m.info, cmd.info, cmd.info_len); |
| 1168 | if (result) |
| 1169 | goto done; |
| 1170 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 1171 | param.qp_num = cmd.qpn; |
| 1172 | param.qkey = cmd.qkey; |
| 1173 | param.status = cmd.status; |
| 1174 | param.info_length = cmd.info_len; |
| 1175 | param.private_data_len = cmd.data_len; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1176 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 1177 | ctx = ib_ucm_ctx_get(file, cmd.id); |
| 1178 | if (!IS_ERR(ctx)) { |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1179 | result = ib_send_cm_sidr_rep(ctx->cm_id, ¶m); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 1180 | ib_ucm_ctx_put(ctx); |
| 1181 | } else |
| 1182 | result = PTR_ERR(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1183 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1184 | done: |
Hal Rosenstock | 79d8190 | 2005-07-27 20:38:56 -0700 | [diff] [blame] | 1185 | kfree(param.private_data); |
| 1186 | kfree(param.info); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1187 | return result; |
| 1188 | } |
| 1189 | |
| 1190 | static ssize_t (*ucm_cmd_table[])(struct ib_ucm_file *file, |
| 1191 | const char __user *inbuf, |
| 1192 | int in_len, int out_len) = { |
| 1193 | [IB_USER_CM_CMD_CREATE_ID] = ib_ucm_create_id, |
| 1194 | [IB_USER_CM_CMD_DESTROY_ID] = ib_ucm_destroy_id, |
| 1195 | [IB_USER_CM_CMD_ATTR_ID] = ib_ucm_attr_id, |
| 1196 | [IB_USER_CM_CMD_LISTEN] = ib_ucm_listen, |
| 1197 | [IB_USER_CM_CMD_ESTABLISH] = ib_ucm_establish, |
| 1198 | [IB_USER_CM_CMD_SEND_REQ] = ib_ucm_send_req, |
| 1199 | [IB_USER_CM_CMD_SEND_REP] = ib_ucm_send_rep, |
| 1200 | [IB_USER_CM_CMD_SEND_RTU] = ib_ucm_send_rtu, |
| 1201 | [IB_USER_CM_CMD_SEND_DREQ] = ib_ucm_send_dreq, |
| 1202 | [IB_USER_CM_CMD_SEND_DREP] = ib_ucm_send_drep, |
| 1203 | [IB_USER_CM_CMD_SEND_REJ] = ib_ucm_send_rej, |
| 1204 | [IB_USER_CM_CMD_SEND_MRA] = ib_ucm_send_mra, |
| 1205 | [IB_USER_CM_CMD_SEND_LAP] = ib_ucm_send_lap, |
| 1206 | [IB_USER_CM_CMD_SEND_APR] = ib_ucm_send_apr, |
| 1207 | [IB_USER_CM_CMD_SEND_SIDR_REQ] = ib_ucm_send_sidr_req, |
| 1208 | [IB_USER_CM_CMD_SEND_SIDR_REP] = ib_ucm_send_sidr_rep, |
| 1209 | [IB_USER_CM_CMD_EVENT] = ib_ucm_event, |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 1210 | [IB_USER_CM_CMD_INIT_QP_ATTR] = ib_ucm_init_qp_attr, |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1211 | }; |
| 1212 | |
| 1213 | static ssize_t ib_ucm_write(struct file *filp, const char __user *buf, |
| 1214 | size_t len, loff_t *pos) |
| 1215 | { |
| 1216 | struct ib_ucm_file *file = filp->private_data; |
| 1217 | struct ib_ucm_cmd_hdr hdr; |
| 1218 | ssize_t result; |
| 1219 | |
| 1220 | if (len < sizeof(hdr)) |
| 1221 | return -EINVAL; |
| 1222 | |
| 1223 | if (copy_from_user(&hdr, buf, sizeof(hdr))) |
| 1224 | return -EFAULT; |
| 1225 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1226 | if (hdr.cmd < 0 || hdr.cmd >= ARRAY_SIZE(ucm_cmd_table)) |
| 1227 | return -EINVAL; |
| 1228 | |
| 1229 | if (hdr.in + sizeof(hdr) > len) |
| 1230 | return -EINVAL; |
| 1231 | |
| 1232 | result = ucm_cmd_table[hdr.cmd](file, buf + sizeof(hdr), |
| 1233 | hdr.in, hdr.out); |
| 1234 | if (!result) |
| 1235 | result = len; |
| 1236 | |
| 1237 | return result; |
| 1238 | } |
| 1239 | |
| 1240 | static unsigned int ib_ucm_poll(struct file *filp, |
| 1241 | struct poll_table_struct *wait) |
| 1242 | { |
| 1243 | struct ib_ucm_file *file = filp->private_data; |
| 1244 | unsigned int mask = 0; |
| 1245 | |
| 1246 | poll_wait(filp, &file->poll_wait, wait); |
| 1247 | |
| 1248 | if (!list_empty(&file->events)) |
| 1249 | mask = POLLIN | POLLRDNORM; |
| 1250 | |
| 1251 | return mask; |
| 1252 | } |
| 1253 | |
| 1254 | static int ib_ucm_open(struct inode *inode, struct file *filp) |
| 1255 | { |
| 1256 | struct ib_ucm_file *file; |
| 1257 | |
| 1258 | file = kmalloc(sizeof(*file), GFP_KERNEL); |
| 1259 | if (!file) |
| 1260 | return -ENOMEM; |
| 1261 | |
| 1262 | INIT_LIST_HEAD(&file->events); |
| 1263 | INIT_LIST_HEAD(&file->ctxs); |
| 1264 | init_waitqueue_head(&file->poll_wait); |
| 1265 | |
| 1266 | init_MUTEX(&file->mutex); |
| 1267 | |
| 1268 | filp->private_data = file; |
| 1269 | file->filp = filp; |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1270 | file->device = container_of(inode->i_cdev, struct ib_ucm_device, dev); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1271 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1272 | return 0; |
| 1273 | } |
| 1274 | |
| 1275 | static int ib_ucm_close(struct inode *inode, struct file *filp) |
| 1276 | { |
| 1277 | struct ib_ucm_file *file = filp->private_data; |
| 1278 | struct ib_ucm_context *ctx; |
| 1279 | |
| 1280 | down(&file->mutex); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1281 | while (!list_empty(&file->ctxs)) { |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1282 | ctx = list_entry(file->ctxs.next, |
| 1283 | struct ib_ucm_context, file_list); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 1284 | up(&file->mutex); |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 1285 | |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 1286 | mutex_lock(&ctx_id_mutex); |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 1287 | idr_remove(&ctx_id_table, ctx->id); |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 1288 | mutex_unlock(&ctx_id_mutex); |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 1289 | |
| 1290 | ib_destroy_cm_id(ctx->cm_id); |
| 1291 | ib_ucm_cleanup_events(ctx); |
| 1292 | kfree(ctx); |
| 1293 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1294 | down(&file->mutex); |
| 1295 | } |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1296 | up(&file->mutex); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1297 | kfree(file); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1298 | return 0; |
| 1299 | } |
| 1300 | |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1301 | static void ib_ucm_release_class_dev(struct class_device *class_dev) |
| 1302 | { |
| 1303 | struct ib_ucm_device *dev; |
| 1304 | |
| 1305 | dev = container_of(class_dev, struct ib_ucm_device, class_dev); |
| 1306 | cdev_del(&dev->dev); |
| 1307 | clear_bit(dev->devnum, dev_map); |
| 1308 | kfree(dev); |
| 1309 | } |
| 1310 | |
| 1311 | static struct file_operations ucm_fops = { |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1312 | .owner = THIS_MODULE, |
| 1313 | .open = ib_ucm_open, |
| 1314 | .release = ib_ucm_close, |
| 1315 | .write = ib_ucm_write, |
| 1316 | .poll = ib_ucm_poll, |
| 1317 | }; |
| 1318 | |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1319 | static struct class ucm_class = { |
| 1320 | .name = "infiniband_cm", |
| 1321 | .release = ib_ucm_release_class_dev |
| 1322 | }; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1323 | |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1324 | static ssize_t show_ibdev(struct class_device *class_dev, char *buf) |
| 1325 | { |
| 1326 | struct ib_ucm_device *dev; |
| 1327 | |
| 1328 | dev = container_of(class_dev, struct ib_ucm_device, class_dev); |
| 1329 | return sprintf(buf, "%s\n", dev->ib_dev->name); |
| 1330 | } |
| 1331 | static CLASS_DEVICE_ATTR(ibdev, S_IRUGO, show_ibdev, NULL); |
| 1332 | |
| 1333 | static void ib_ucm_add_one(struct ib_device *device) |
| 1334 | { |
| 1335 | struct ib_ucm_device *ucm_dev; |
| 1336 | |
| 1337 | if (!device->alloc_ucontext) |
| 1338 | return; |
| 1339 | |
Roland Dreier | de6eb66 | 2005-11-02 07:23:14 -0800 | [diff] [blame] | 1340 | ucm_dev = kzalloc(sizeof *ucm_dev, GFP_KERNEL); |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1341 | if (!ucm_dev) |
| 1342 | return; |
| 1343 | |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1344 | ucm_dev->ib_dev = device; |
| 1345 | |
| 1346 | ucm_dev->devnum = find_first_zero_bit(dev_map, IB_UCM_MAX_DEVICES); |
| 1347 | if (ucm_dev->devnum >= IB_UCM_MAX_DEVICES) |
| 1348 | goto err; |
| 1349 | |
| 1350 | set_bit(ucm_dev->devnum, dev_map); |
| 1351 | |
| 1352 | cdev_init(&ucm_dev->dev, &ucm_fops); |
| 1353 | ucm_dev->dev.owner = THIS_MODULE; |
| 1354 | kobject_set_name(&ucm_dev->dev.kobj, "ucm%d", ucm_dev->devnum); |
| 1355 | if (cdev_add(&ucm_dev->dev, IB_UCM_BASE_DEV + ucm_dev->devnum, 1)) |
| 1356 | goto err; |
| 1357 | |
| 1358 | ucm_dev->class_dev.class = &ucm_class; |
| 1359 | ucm_dev->class_dev.dev = device->dma_device; |
Greg Kroah-Hartman | 68f5f99 | 2006-01-20 14:08:59 -0800 | [diff] [blame] | 1360 | ucm_dev->class_dev.devt = ucm_dev->dev.dev; |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1361 | snprintf(ucm_dev->class_dev.class_id, BUS_ID_SIZE, "ucm%d", |
| 1362 | ucm_dev->devnum); |
| 1363 | if (class_device_register(&ucm_dev->class_dev)) |
| 1364 | goto err_cdev; |
| 1365 | |
| 1366 | if (class_device_create_file(&ucm_dev->class_dev, |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1367 | &class_device_attr_ibdev)) |
| 1368 | goto err_class; |
| 1369 | |
| 1370 | ib_set_client_data(device, &ucm_client, ucm_dev); |
| 1371 | return; |
| 1372 | |
| 1373 | err_class: |
| 1374 | class_device_unregister(&ucm_dev->class_dev); |
| 1375 | err_cdev: |
| 1376 | cdev_del(&ucm_dev->dev); |
| 1377 | clear_bit(ucm_dev->devnum, dev_map); |
| 1378 | err: |
| 1379 | kfree(ucm_dev); |
| 1380 | return; |
| 1381 | } |
| 1382 | |
| 1383 | static void ib_ucm_remove_one(struct ib_device *device) |
| 1384 | { |
| 1385 | struct ib_ucm_device *ucm_dev = ib_get_client_data(device, &ucm_client); |
| 1386 | |
| 1387 | if (!ucm_dev) |
| 1388 | return; |
| 1389 | |
| 1390 | class_device_unregister(&ucm_dev->class_dev); |
| 1391 | } |
| 1392 | |
| 1393 | static ssize_t show_abi_version(struct class *class, char *buf) |
| 1394 | { |
| 1395 | return sprintf(buf, "%d\n", IB_USER_CM_ABI_VERSION); |
| 1396 | } |
| 1397 | static CLASS_ATTR(abi_version, S_IRUGO, show_abi_version, NULL); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1398 | |
| 1399 | static int __init ib_ucm_init(void) |
| 1400 | { |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1401 | int ret; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1402 | |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1403 | ret = register_chrdev_region(IB_UCM_BASE_DEV, IB_UCM_MAX_DEVICES, |
| 1404 | "infiniband_cm"); |
| 1405 | if (ret) { |
| 1406 | printk(KERN_ERR "ucm: couldn't register device number\n"); |
| 1407 | goto err; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1408 | } |
| 1409 | |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1410 | ret = class_register(&ucm_class); |
| 1411 | if (ret) { |
| 1412 | printk(KERN_ERR "ucm: couldn't create class infiniband_cm\n"); |
| 1413 | goto err_chrdev; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1414 | } |
| 1415 | |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1416 | ret = class_create_file(&ucm_class, &class_attr_abi_version); |
| 1417 | if (ret) { |
| 1418 | printk(KERN_ERR "ucm: couldn't create abi_version attribute\n"); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1419 | goto err_class; |
| 1420 | } |
| 1421 | |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1422 | ret = ib_register_client(&ucm_client); |
| 1423 | if (ret) { |
| 1424 | printk(KERN_ERR "ucm: couldn't register client\n"); |
| 1425 | goto err_class; |
| 1426 | } |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1427 | return 0; |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1428 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1429 | err_class: |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1430 | class_unregister(&ucm_class); |
| 1431 | err_chrdev: |
| 1432 | unregister_chrdev_region(IB_UCM_BASE_DEV, IB_UCM_MAX_DEVICES); |
| 1433 | err: |
| 1434 | return ret; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1435 | } |
| 1436 | |
| 1437 | static void __exit ib_ucm_cleanup(void) |
| 1438 | { |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1439 | ib_unregister_client(&ucm_client); |
| 1440 | class_unregister(&ucm_class); |
| 1441 | unregister_chrdev_region(IB_UCM_BASE_DEV, IB_UCM_MAX_DEVICES); |
Roland Dreier | 5d7edb3 | 2005-10-24 10:53:25 -0700 | [diff] [blame] | 1442 | idr_destroy(&ctx_id_table); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1443 | } |
| 1444 | |
| 1445 | module_init(ib_ucm_init); |
| 1446 | module_exit(ib_ucm_cleanup); |