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. |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 32 | */ |
Sean Hefty | 1b52fa98 | 2006-05-12 14:57:52 -0700 | [diff] [blame] | 33 | |
| 34 | #include <linux/completion.h> |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 35 | #include <linux/init.h> |
| 36 | #include <linux/fs.h> |
| 37 | #include <linux/module.h> |
| 38 | #include <linux/device.h> |
| 39 | #include <linux/err.h> |
| 40 | #include <linux/poll.h> |
Alexey Dobriyan | a99bbaf | 2009-10-04 16:11:37 +0400 | [diff] [blame] | 41 | #include <linux/sched.h> |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 42 | #include <linux/file.h> |
| 43 | #include <linux/mount.h> |
| 44 | #include <linux/cdev.h> |
Sean Hefty | 595e726 | 2005-10-17 15:33:47 -0700 | [diff] [blame] | 45 | #include <linux/idr.h> |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 46 | #include <linux/mutex.h> |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 47 | |
| 48 | #include <asm/uaccess.h> |
| 49 | |
Sean Hefty | 595e726 | 2005-10-17 15:33:47 -0700 | [diff] [blame] | 50 | #include <rdma/ib_cm.h> |
| 51 | #include <rdma/ib_user_cm.h> |
Sean Hefty | 6a9af2e | 2006-06-17 20:37:27 -0700 | [diff] [blame] | 52 | #include <rdma/ib_marshall.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; |
Tony Jones | f4e91eb | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 60 | struct cdev cdev; |
| 61 | struct device dev; |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 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 { |
Sean Hefty | 4be10c1e | 2006-05-25 10:03:23 -0700 | [diff] [blame] | 66 | struct mutex file_mutex; |
Sean Hefty | 595e726 | 2005-10-17 15:33:47 -0700 | [diff] [blame] | 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 | 9af57b7 | 2007-07-16 21:49:35 -0700 | [diff] [blame] | 108 | /* ib_cm and ib_user_cm modules share /sys/class/infiniband_cm */ |
| 109 | extern struct class cm_class; |
| 110 | |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 111 | #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] | 112 | |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 113 | static void ib_ucm_add_one(struct ib_device *device); |
| 114 | static void ib_ucm_remove_one(struct ib_device *device); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 115 | |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 116 | static struct ib_client ucm_client = { |
| 117 | .name = "ucm", |
| 118 | .add = ib_ucm_add_one, |
| 119 | .remove = ib_ucm_remove_one |
| 120 | }; |
| 121 | |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 122 | static DEFINE_MUTEX(ctx_id_mutex); |
Roland Dreier | 762a03e | 2005-10-17 15:38:50 -0700 | [diff] [blame] | 123 | static DEFINE_IDR(ctx_id_table); |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 124 | static DECLARE_BITMAP(dev_map, IB_UCM_MAX_DEVICES); |
Sean Hefty | 595e726 | 2005-10-17 15:33:47 -0700 | [diff] [blame] | 125 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 126 | 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] | 127 | { |
| 128 | struct ib_ucm_context *ctx; |
| 129 | |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 130 | mutex_lock(&ctx_id_mutex); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 131 | ctx = idr_find(&ctx_id_table, id); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 132 | if (!ctx) |
| 133 | ctx = ERR_PTR(-ENOENT); |
| 134 | else if (ctx->file != file) |
| 135 | ctx = ERR_PTR(-EINVAL); |
| 136 | else |
| 137 | atomic_inc(&ctx->ref); |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 138 | mutex_unlock(&ctx_id_mutex); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 139 | |
| 140 | return ctx; |
| 141 | } |
| 142 | |
| 143 | static void ib_ucm_ctx_put(struct ib_ucm_context *ctx) |
| 144 | { |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 145 | if (atomic_dec_and_test(&ctx->ref)) |
Sean Hefty | 1b52fa98 | 2006-05-12 14:57:52 -0700 | [diff] [blame] | 146 | complete(&ctx->comp); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 149 | static inline int ib_ucm_new_cm_id(int event) |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 150 | { |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 151 | return event == IB_CM_REQ_RECEIVED || event == IB_CM_SIDR_REQ_RECEIVED; |
| 152 | } |
| 153 | |
| 154 | static void ib_ucm_cleanup_events(struct ib_ucm_context *ctx) |
| 155 | { |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 156 | struct ib_ucm_event *uevent; |
| 157 | |
Sean Hefty | 4be10c1e | 2006-05-25 10:03:23 -0700 | [diff] [blame] | 158 | mutex_lock(&ctx->file->file_mutex); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 159 | list_del(&ctx->file_list); |
| 160 | while (!list_empty(&ctx->events)) { |
| 161 | |
| 162 | uevent = list_entry(ctx->events.next, |
| 163 | struct ib_ucm_event, ctx_list); |
| 164 | list_del(&uevent->file_list); |
| 165 | list_del(&uevent->ctx_list); |
Michael S. Tsirkin | f469b26 | 2006-11-29 15:33:10 -0800 | [diff] [blame] | 166 | mutex_unlock(&ctx->file->file_mutex); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 167 | |
| 168 | /* clear incoming connections. */ |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 169 | if (ib_ucm_new_cm_id(uevent->resp.event)) |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 170 | ib_destroy_cm_id(uevent->cm_id); |
| 171 | |
| 172 | kfree(uevent); |
Michael S. Tsirkin | f469b26 | 2006-11-29 15:33:10 -0800 | [diff] [blame] | 173 | mutex_lock(&ctx->file->file_mutex); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 174 | } |
Sean Hefty | 4be10c1e | 2006-05-25 10:03:23 -0700 | [diff] [blame] | 175 | mutex_unlock(&ctx->file->file_mutex); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | static struct ib_ucm_context *ib_ucm_ctx_alloc(struct ib_ucm_file *file) |
| 179 | { |
| 180 | struct ib_ucm_context *ctx; |
| 181 | int result; |
| 182 | |
Roland Dreier | de6eb66 | 2005-11-02 07:23:14 -0800 | [diff] [blame] | 183 | ctx = kzalloc(sizeof *ctx, GFP_KERNEL); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 184 | if (!ctx) |
| 185 | return NULL; |
| 186 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 187 | atomic_set(&ctx->ref, 1); |
Sean Hefty | 1b52fa98 | 2006-05-12 14:57:52 -0700 | [diff] [blame] | 188 | init_completion(&ctx->comp); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 189 | ctx->file = file; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 190 | INIT_LIST_HEAD(&ctx->events); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 191 | |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 192 | do { |
| 193 | result = idr_pre_get(&ctx_id_table, GFP_KERNEL); |
| 194 | if (!result) |
| 195 | goto error; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 196 | |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 197 | mutex_lock(&ctx_id_mutex); |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 198 | result = idr_get_new(&ctx_id_table, ctx, &ctx->id); |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 199 | mutex_unlock(&ctx_id_mutex); |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 200 | } while (result == -EAGAIN); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 201 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 202 | if (result) |
| 203 | goto error; |
| 204 | |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 205 | list_add_tail(&ctx->file_list, &file->ctxs); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 206 | return ctx; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 207 | |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 208 | error: |
| 209 | kfree(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 210 | return NULL; |
| 211 | } |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 212 | |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 213 | 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] | 214 | struct ib_cm_req_event_param *kreq) |
| 215 | { |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 216 | ureq->remote_ca_guid = kreq->remote_ca_guid; |
| 217 | ureq->remote_qkey = kreq->remote_qkey; |
| 218 | ureq->remote_qpn = kreq->remote_qpn; |
| 219 | ureq->qp_type = kreq->qp_type; |
| 220 | ureq->starting_psn = kreq->starting_psn; |
| 221 | ureq->responder_resources = kreq->responder_resources; |
| 222 | ureq->initiator_depth = kreq->initiator_depth; |
| 223 | ureq->local_cm_response_timeout = kreq->local_cm_response_timeout; |
| 224 | ureq->flow_control = kreq->flow_control; |
| 225 | ureq->remote_cm_response_timeout = kreq->remote_cm_response_timeout; |
| 226 | ureq->retry_count = kreq->retry_count; |
| 227 | ureq->rnr_retry_count = kreq->rnr_retry_count; |
| 228 | ureq->srq = kreq->srq; |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 229 | ureq->port = kreq->port; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 230 | |
Sean Hefty | 6a9af2e | 2006-06-17 20:37:27 -0700 | [diff] [blame] | 231 | ib_copy_path_rec_to_user(&ureq->primary_path, kreq->primary_path); |
| 232 | if (kreq->alternate_path) |
| 233 | ib_copy_path_rec_to_user(&ureq->alternate_path, |
| 234 | kreq->alternate_path); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | static void ib_ucm_event_rep_get(struct ib_ucm_rep_event_resp *urep, |
| 238 | struct ib_cm_rep_event_param *krep) |
| 239 | { |
| 240 | urep->remote_ca_guid = krep->remote_ca_guid; |
| 241 | urep->remote_qkey = krep->remote_qkey; |
| 242 | urep->remote_qpn = krep->remote_qpn; |
| 243 | urep->starting_psn = krep->starting_psn; |
| 244 | urep->responder_resources = krep->responder_resources; |
| 245 | urep->initiator_depth = krep->initiator_depth; |
| 246 | urep->target_ack_delay = krep->target_ack_delay; |
| 247 | urep->failover_accepted = krep->failover_accepted; |
| 248 | urep->flow_control = krep->flow_control; |
| 249 | urep->rnr_retry_count = krep->rnr_retry_count; |
| 250 | urep->srq = krep->srq; |
| 251 | } |
| 252 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 253 | static void ib_ucm_event_sidr_rep_get(struct ib_ucm_sidr_rep_event_resp *urep, |
| 254 | struct ib_cm_sidr_rep_event_param *krep) |
| 255 | { |
| 256 | urep->status = krep->status; |
| 257 | urep->qkey = krep->qkey; |
| 258 | urep->qpn = krep->qpn; |
| 259 | }; |
| 260 | |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 261 | static int ib_ucm_event_process(struct ib_cm_event *evt, |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 262 | struct ib_ucm_event *uvt) |
| 263 | { |
| 264 | void *info = NULL; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 265 | |
| 266 | switch (evt->event) { |
| 267 | case IB_CM_REQ_RECEIVED: |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 268 | ib_ucm_event_req_get(&uvt->resp.u.req_resp, |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 269 | &evt->param.req_rcvd); |
| 270 | uvt->data_len = IB_CM_REQ_PRIVATE_DATA_SIZE; |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 271 | uvt->resp.present = IB_UCM_PRES_PRIMARY; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 272 | uvt->resp.present |= (evt->param.req_rcvd.alternate_path ? |
| 273 | IB_UCM_PRES_ALTERNATE : 0); |
| 274 | break; |
| 275 | case IB_CM_REP_RECEIVED: |
| 276 | ib_ucm_event_rep_get(&uvt->resp.u.rep_resp, |
| 277 | &evt->param.rep_rcvd); |
| 278 | uvt->data_len = IB_CM_REP_PRIVATE_DATA_SIZE; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 279 | break; |
| 280 | case IB_CM_RTU_RECEIVED: |
| 281 | uvt->data_len = IB_CM_RTU_PRIVATE_DATA_SIZE; |
| 282 | uvt->resp.u.send_status = evt->param.send_status; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 283 | break; |
| 284 | case IB_CM_DREQ_RECEIVED: |
| 285 | uvt->data_len = IB_CM_DREQ_PRIVATE_DATA_SIZE; |
| 286 | uvt->resp.u.send_status = evt->param.send_status; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 287 | break; |
| 288 | case IB_CM_DREP_RECEIVED: |
| 289 | uvt->data_len = IB_CM_DREP_PRIVATE_DATA_SIZE; |
| 290 | uvt->resp.u.send_status = evt->param.send_status; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 291 | break; |
| 292 | case IB_CM_MRA_RECEIVED: |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 293 | uvt->resp.u.mra_resp.timeout = |
| 294 | evt->param.mra_rcvd.service_timeout; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 295 | uvt->data_len = IB_CM_MRA_PRIVATE_DATA_SIZE; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 296 | break; |
| 297 | case IB_CM_REJ_RECEIVED: |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 298 | uvt->resp.u.rej_resp.reason = evt->param.rej_rcvd.reason; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 299 | uvt->data_len = IB_CM_REJ_PRIVATE_DATA_SIZE; |
| 300 | uvt->info_len = evt->param.rej_rcvd.ari_length; |
| 301 | info = evt->param.rej_rcvd.ari; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 302 | break; |
| 303 | case IB_CM_LAP_RECEIVED: |
Sean Hefty | 6a9af2e | 2006-06-17 20:37:27 -0700 | [diff] [blame] | 304 | ib_copy_path_rec_to_user(&uvt->resp.u.lap_resp.path, |
| 305 | evt->param.lap_rcvd.alternate_path); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 306 | uvt->data_len = IB_CM_LAP_PRIVATE_DATA_SIZE; |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 307 | uvt->resp.present = IB_UCM_PRES_ALTERNATE; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 308 | break; |
| 309 | case IB_CM_APR_RECEIVED: |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 310 | uvt->resp.u.apr_resp.status = evt->param.apr_rcvd.ap_status; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 311 | uvt->data_len = IB_CM_APR_PRIVATE_DATA_SIZE; |
| 312 | uvt->info_len = evt->param.apr_rcvd.info_len; |
| 313 | info = evt->param.apr_rcvd.apr_info; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 314 | break; |
| 315 | case IB_CM_SIDR_REQ_RECEIVED: |
Roland Dreier | 3cd9656 | 2006-09-22 15:22:46 -0700 | [diff] [blame] | 316 | uvt->resp.u.sidr_req_resp.pkey = |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 317 | evt->param.sidr_req_rcvd.pkey; |
Roland Dreier | 3cd9656 | 2006-09-22 15:22:46 -0700 | [diff] [blame] | 318 | uvt->resp.u.sidr_req_resp.port = |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 319 | evt->param.sidr_req_rcvd.port; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 320 | uvt->data_len = IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 321 | break; |
| 322 | case IB_CM_SIDR_REP_RECEIVED: |
| 323 | ib_ucm_event_sidr_rep_get(&uvt->resp.u.sidr_rep_resp, |
| 324 | &evt->param.sidr_rep_rcvd); |
| 325 | uvt->data_len = IB_CM_SIDR_REP_PRIVATE_DATA_SIZE; |
| 326 | uvt->info_len = evt->param.sidr_rep_rcvd.info_len; |
| 327 | info = evt->param.sidr_rep_rcvd.info; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 328 | break; |
| 329 | default: |
| 330 | uvt->resp.u.send_status = evt->param.send_status; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 331 | break; |
| 332 | } |
| 333 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 334 | if (uvt->data_len) { |
Eric Sesterhenn | bed8bdf | 2006-10-23 22:17:21 +0200 | [diff] [blame] | 335 | uvt->data = kmemdup(evt->private_data, uvt->data_len, GFP_KERNEL); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 336 | if (!uvt->data) |
| 337 | goto err1; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 338 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 339 | uvt->resp.present |= IB_UCM_PRES_DATA; |
| 340 | } |
| 341 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 342 | if (uvt->info_len) { |
Eric Sesterhenn | bed8bdf | 2006-10-23 22:17:21 +0200 | [diff] [blame] | 343 | uvt->info = kmemdup(info, uvt->info_len, GFP_KERNEL); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 344 | if (!uvt->info) |
| 345 | goto err2; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 346 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 347 | uvt->resp.present |= IB_UCM_PRES_INFO; |
| 348 | } |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 349 | return 0; |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 350 | |
| 351 | err2: |
Hal Rosenstock | 79d8190 | 2005-07-27 20:38:56 -0700 | [diff] [blame] | 352 | kfree(uvt->data); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 353 | err1: |
| 354 | return -ENOMEM; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | static int ib_ucm_event_handler(struct ib_cm_id *cm_id, |
| 358 | struct ib_cm_event *event) |
| 359 | { |
| 360 | struct ib_ucm_event *uevent; |
| 361 | struct ib_ucm_context *ctx; |
| 362 | int result = 0; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 363 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 364 | ctx = cm_id->context; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 365 | |
Roland Dreier | de6eb66 | 2005-11-02 07:23:14 -0800 | [diff] [blame] | 366 | uevent = kzalloc(sizeof *uevent, GFP_KERNEL); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 367 | if (!uevent) |
| 368 | goto err1; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 369 | |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 370 | uevent->ctx = ctx; |
| 371 | uevent->cm_id = cm_id; |
| 372 | uevent->resp.uid = ctx->uid; |
| 373 | uevent->resp.id = ctx->id; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 374 | uevent->resp.event = event->event; |
| 375 | |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 376 | result = ib_ucm_event_process(event, uevent); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 377 | if (result) |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 378 | goto err2; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 379 | |
Sean Hefty | 4be10c1e | 2006-05-25 10:03:23 -0700 | [diff] [blame] | 380 | mutex_lock(&ctx->file->file_mutex); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 381 | list_add_tail(&uevent->file_list, &ctx->file->events); |
| 382 | list_add_tail(&uevent->ctx_list, &ctx->events); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 383 | wake_up_interruptible(&ctx->file->poll_wait); |
Sean Hefty | 4be10c1e | 2006-05-25 10:03:23 -0700 | [diff] [blame] | 384 | mutex_unlock(&ctx->file->file_mutex); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 385 | return 0; |
| 386 | |
| 387 | err2: |
| 388 | kfree(uevent); |
| 389 | err1: |
| 390 | /* Destroy new cm_id's */ |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 391 | return ib_ucm_new_cm_id(event->event); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | static ssize_t ib_ucm_event(struct ib_ucm_file *file, |
| 395 | const char __user *inbuf, |
| 396 | int in_len, int out_len) |
| 397 | { |
| 398 | struct ib_ucm_context *ctx; |
| 399 | struct ib_ucm_event_get cmd; |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 400 | struct ib_ucm_event *uevent; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 401 | int result = 0; |
| 402 | DEFINE_WAIT(wait); |
| 403 | |
| 404 | if (out_len < sizeof(struct ib_ucm_event_resp)) |
| 405 | return -ENOSPC; |
| 406 | |
| 407 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 408 | return -EFAULT; |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 409 | |
Sean Hefty | 4be10c1e | 2006-05-25 10:03:23 -0700 | [diff] [blame] | 410 | mutex_lock(&file->file_mutex); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 411 | while (list_empty(&file->events)) { |
Sean Hefty | 4be10c1e | 2006-05-25 10:03:23 -0700 | [diff] [blame] | 412 | mutex_unlock(&file->file_mutex); |
Sean Hefty | 9d41b7f | 2007-04-05 10:51:05 -0700 | [diff] [blame] | 413 | |
| 414 | if (file->filp->f_flags & O_NONBLOCK) |
| 415 | return -EAGAIN; |
| 416 | |
| 417 | if (wait_event_interruptible(file->poll_wait, |
| 418 | !list_empty(&file->events))) |
| 419 | return -ERESTARTSYS; |
| 420 | |
Sean Hefty | 4be10c1e | 2006-05-25 10:03:23 -0700 | [diff] [blame] | 421 | mutex_lock(&file->file_mutex); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 422 | } |
| 423 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 424 | uevent = list_entry(file->events.next, struct ib_ucm_event, file_list); |
| 425 | |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 426 | if (ib_ucm_new_cm_id(uevent->resp.event)) { |
| 427 | ctx = ib_ucm_ctx_alloc(file); |
| 428 | if (!ctx) { |
| 429 | result = -ENOMEM; |
| 430 | goto done; |
| 431 | } |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 432 | |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 433 | ctx->cm_id = uevent->cm_id; |
| 434 | ctx->cm_id->context = ctx; |
| 435 | uevent->resp.id = ctx->id; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 436 | } |
| 437 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 438 | if (copy_to_user((void __user *)(unsigned long)cmd.response, |
| 439 | &uevent->resp, sizeof(uevent->resp))) { |
| 440 | result = -EFAULT; |
| 441 | goto done; |
| 442 | } |
| 443 | |
| 444 | if (uevent->data) { |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 445 | if (cmd.data_len < uevent->data_len) { |
| 446 | result = -ENOMEM; |
| 447 | goto done; |
| 448 | } |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 449 | if (copy_to_user((void __user *)(unsigned long)cmd.data, |
| 450 | uevent->data, uevent->data_len)) { |
| 451 | result = -EFAULT; |
| 452 | goto done; |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | if (uevent->info) { |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 457 | if (cmd.info_len < uevent->info_len) { |
| 458 | result = -ENOMEM; |
| 459 | goto done; |
| 460 | } |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 461 | if (copy_to_user((void __user *)(unsigned long)cmd.info, |
| 462 | uevent->info, uevent->info_len)) { |
| 463 | result = -EFAULT; |
| 464 | goto done; |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | list_del(&uevent->file_list); |
| 469 | list_del(&uevent->ctx_list); |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 470 | uevent->ctx->events_reported++; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 471 | |
Hal Rosenstock | 79d8190 | 2005-07-27 20:38:56 -0700 | [diff] [blame] | 472 | kfree(uevent->data); |
| 473 | kfree(uevent->info); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 474 | kfree(uevent); |
| 475 | done: |
Sean Hefty | 4be10c1e | 2006-05-25 10:03:23 -0700 | [diff] [blame] | 476 | mutex_unlock(&file->file_mutex); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 477 | return result; |
| 478 | } |
| 479 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 480 | static ssize_t ib_ucm_create_id(struct ib_ucm_file *file, |
| 481 | const char __user *inbuf, |
| 482 | int in_len, int out_len) |
| 483 | { |
| 484 | struct ib_ucm_create_id cmd; |
| 485 | struct ib_ucm_create_id_resp resp; |
| 486 | struct ib_ucm_context *ctx; |
| 487 | int result; |
| 488 | |
| 489 | if (out_len < sizeof(resp)) |
| 490 | return -ENOSPC; |
| 491 | |
| 492 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 493 | return -EFAULT; |
| 494 | |
Sean Hefty | 4be10c1e | 2006-05-25 10:03:23 -0700 | [diff] [blame] | 495 | mutex_lock(&file->file_mutex); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 496 | ctx = ib_ucm_ctx_alloc(file); |
Sean Hefty | 4be10c1e | 2006-05-25 10:03:23 -0700 | [diff] [blame] | 497 | mutex_unlock(&file->file_mutex); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 498 | if (!ctx) |
| 499 | return -ENOMEM; |
| 500 | |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 501 | ctx->uid = cmd.uid; |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 502 | ctx->cm_id = ib_create_cm_id(file->device->ib_dev, |
| 503 | ib_ucm_event_handler, ctx); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 504 | if (IS_ERR(ctx->cm_id)) { |
| 505 | result = PTR_ERR(ctx->cm_id); |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 506 | goto err1; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | resp.id = ctx->id; |
| 510 | if (copy_to_user((void __user *)(unsigned long)cmd.response, |
| 511 | &resp, sizeof(resp))) { |
| 512 | result = -EFAULT; |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 513 | goto err2; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 514 | } |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 515 | return 0; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 516 | |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 517 | err2: |
| 518 | ib_destroy_cm_id(ctx->cm_id); |
| 519 | err1: |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 520 | mutex_lock(&ctx_id_mutex); |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 521 | idr_remove(&ctx_id_table, ctx->id); |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 522 | mutex_unlock(&ctx_id_mutex); |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 523 | kfree(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 524 | return result; |
| 525 | } |
| 526 | |
| 527 | static ssize_t ib_ucm_destroy_id(struct ib_ucm_file *file, |
| 528 | const char __user *inbuf, |
| 529 | int in_len, int out_len) |
| 530 | { |
| 531 | struct ib_ucm_destroy_id cmd; |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 532 | struct ib_ucm_destroy_id_resp resp; |
| 533 | struct ib_ucm_context *ctx; |
| 534 | int result = 0; |
| 535 | |
| 536 | if (out_len < sizeof(resp)) |
| 537 | return -ENOSPC; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 538 | |
| 539 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 540 | return -EFAULT; |
| 541 | |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 542 | mutex_lock(&ctx_id_mutex); |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 543 | ctx = idr_find(&ctx_id_table, cmd.id); |
| 544 | if (!ctx) |
| 545 | ctx = ERR_PTR(-ENOENT); |
| 546 | else if (ctx->file != file) |
| 547 | ctx = ERR_PTR(-EINVAL); |
| 548 | else |
| 549 | idr_remove(&ctx_id_table, ctx->id); |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 550 | mutex_unlock(&ctx_id_mutex); |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 551 | |
| 552 | if (IS_ERR(ctx)) |
| 553 | return PTR_ERR(ctx); |
| 554 | |
Sean Hefty | 1b52fa98 | 2006-05-12 14:57:52 -0700 | [diff] [blame] | 555 | ib_ucm_ctx_put(ctx); |
| 556 | wait_for_completion(&ctx->comp); |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 557 | |
| 558 | /* No new events will be generated after destroying the cm_id. */ |
| 559 | ib_destroy_cm_id(ctx->cm_id); |
| 560 | /* Cleanup events not yet reported to the user. */ |
| 561 | ib_ucm_cleanup_events(ctx); |
| 562 | |
| 563 | resp.events_reported = ctx->events_reported; |
| 564 | if (copy_to_user((void __user *)(unsigned long)cmd.response, |
| 565 | &resp, sizeof(resp))) |
| 566 | result = -EFAULT; |
| 567 | |
| 568 | kfree(ctx); |
| 569 | return result; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | static ssize_t ib_ucm_attr_id(struct ib_ucm_file *file, |
| 573 | const char __user *inbuf, |
| 574 | int in_len, int out_len) |
| 575 | { |
| 576 | struct ib_ucm_attr_id_resp resp; |
| 577 | struct ib_ucm_attr_id cmd; |
| 578 | struct ib_ucm_context *ctx; |
| 579 | int result = 0; |
| 580 | |
| 581 | if (out_len < sizeof(resp)) |
| 582 | return -ENOSPC; |
| 583 | |
| 584 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 585 | return -EFAULT; |
| 586 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 587 | ctx = ib_ucm_ctx_get(file, cmd.id); |
| 588 | if (IS_ERR(ctx)) |
| 589 | return PTR_ERR(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 590 | |
| 591 | resp.service_id = ctx->cm_id->service_id; |
| 592 | resp.service_mask = ctx->cm_id->service_mask; |
| 593 | resp.local_id = ctx->cm_id->local_id; |
| 594 | resp.remote_id = ctx->cm_id->remote_id; |
| 595 | |
| 596 | if (copy_to_user((void __user *)(unsigned long)cmd.response, |
| 597 | &resp, sizeof(resp))) |
| 598 | result = -EFAULT; |
| 599 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 600 | ib_ucm_ctx_put(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 601 | return result; |
| 602 | } |
| 603 | |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 604 | static ssize_t ib_ucm_init_qp_attr(struct ib_ucm_file *file, |
| 605 | const char __user *inbuf, |
| 606 | int in_len, int out_len) |
| 607 | { |
Sean Hefty | 6a9af2e | 2006-06-17 20:37:27 -0700 | [diff] [blame] | 608 | struct ib_uverbs_qp_attr resp; |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 609 | struct ib_ucm_init_qp_attr cmd; |
| 610 | struct ib_ucm_context *ctx; |
| 611 | struct ib_qp_attr qp_attr; |
| 612 | int result = 0; |
| 613 | |
| 614 | if (out_len < sizeof(resp)) |
| 615 | return -ENOSPC; |
| 616 | |
| 617 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 618 | return -EFAULT; |
| 619 | |
| 620 | ctx = ib_ucm_ctx_get(file, cmd.id); |
| 621 | if (IS_ERR(ctx)) |
| 622 | return PTR_ERR(ctx); |
| 623 | |
| 624 | resp.qp_attr_mask = 0; |
| 625 | memset(&qp_attr, 0, sizeof qp_attr); |
| 626 | qp_attr.qp_state = cmd.qp_state; |
| 627 | result = ib_cm_init_qp_attr(ctx->cm_id, &qp_attr, &resp.qp_attr_mask); |
| 628 | if (result) |
| 629 | goto out; |
| 630 | |
Sean Hefty | 6a9af2e | 2006-06-17 20:37:27 -0700 | [diff] [blame] | 631 | ib_copy_qp_attr_to_user(&resp, &qp_attr); |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 632 | |
| 633 | if (copy_to_user((void __user *)(unsigned long)cmd.response, |
| 634 | &resp, sizeof(resp))) |
| 635 | result = -EFAULT; |
| 636 | |
| 637 | out: |
| 638 | ib_ucm_ctx_put(ctx); |
| 639 | return result; |
| 640 | } |
| 641 | |
Sean Hefty | 6e61d04 | 2006-06-17 20:37:28 -0700 | [diff] [blame] | 642 | static int ucm_validate_listen(__be64 service_id, __be64 service_mask) |
| 643 | { |
| 644 | service_id &= service_mask; |
| 645 | |
| 646 | if (((service_id & IB_CMA_SERVICE_ID_MASK) == IB_CMA_SERVICE_ID) || |
| 647 | ((service_id & IB_SDP_SERVICE_ID_MASK) == IB_SDP_SERVICE_ID)) |
| 648 | return -EINVAL; |
| 649 | |
| 650 | return 0; |
| 651 | } |
| 652 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 653 | static ssize_t ib_ucm_listen(struct ib_ucm_file *file, |
| 654 | const char __user *inbuf, |
| 655 | int in_len, int out_len) |
| 656 | { |
| 657 | struct ib_ucm_listen cmd; |
| 658 | struct ib_ucm_context *ctx; |
| 659 | int result; |
| 660 | |
| 661 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 662 | return -EFAULT; |
| 663 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 664 | ctx = ib_ucm_ctx_get(file, cmd.id); |
| 665 | if (IS_ERR(ctx)) |
| 666 | return PTR_ERR(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 667 | |
Sean Hefty | 6e61d04 | 2006-06-17 20:37:28 -0700 | [diff] [blame] | 668 | result = ucm_validate_listen(cmd.service_id, cmd.service_mask); |
| 669 | if (result) |
| 670 | goto out; |
| 671 | |
| 672 | result = ib_cm_listen(ctx->cm_id, cmd.service_id, cmd.service_mask, |
| 673 | NULL); |
| 674 | out: |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 675 | ib_ucm_ctx_put(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 676 | return result; |
| 677 | } |
| 678 | |
Sean Hefty | e1444b5 | 2006-11-28 14:57:13 -0800 | [diff] [blame] | 679 | static ssize_t ib_ucm_notify(struct ib_ucm_file *file, |
| 680 | const char __user *inbuf, |
| 681 | int in_len, int out_len) |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 682 | { |
Sean Hefty | e1444b5 | 2006-11-28 14:57:13 -0800 | [diff] [blame] | 683 | struct ib_ucm_notify cmd; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 684 | struct ib_ucm_context *ctx; |
| 685 | int result; |
| 686 | |
| 687 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 688 | return -EFAULT; |
| 689 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 690 | ctx = ib_ucm_ctx_get(file, cmd.id); |
| 691 | if (IS_ERR(ctx)) |
| 692 | return PTR_ERR(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 693 | |
Sean Hefty | e1444b5 | 2006-11-28 14:57:13 -0800 | [diff] [blame] | 694 | result = ib_cm_notify(ctx->cm_id, (enum ib_event_type) cmd.event); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 695 | ib_ucm_ctx_put(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 696 | return result; |
| 697 | } |
| 698 | |
| 699 | static int ib_ucm_alloc_data(const void **dest, u64 src, u32 len) |
| 700 | { |
| 701 | void *data; |
| 702 | |
| 703 | *dest = NULL; |
| 704 | |
| 705 | if (!len) |
| 706 | return 0; |
| 707 | |
| 708 | data = kmalloc(len, GFP_KERNEL); |
| 709 | if (!data) |
| 710 | return -ENOMEM; |
| 711 | |
| 712 | if (copy_from_user(data, (void __user *)(unsigned long)src, len)) { |
| 713 | kfree(data); |
| 714 | return -EFAULT; |
| 715 | } |
| 716 | |
| 717 | *dest = data; |
| 718 | return 0; |
| 719 | } |
| 720 | |
| 721 | static int ib_ucm_path_get(struct ib_sa_path_rec **path, u64 src) |
| 722 | { |
Sean Hefty | 6a9af2e | 2006-06-17 20:37:27 -0700 | [diff] [blame] | 723 | struct ib_user_path_rec upath; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 724 | struct ib_sa_path_rec *sa_path; |
| 725 | |
| 726 | *path = NULL; |
| 727 | |
| 728 | if (!src) |
| 729 | return 0; |
| 730 | |
| 731 | sa_path = kmalloc(sizeof(*sa_path), GFP_KERNEL); |
| 732 | if (!sa_path) |
| 733 | return -ENOMEM; |
| 734 | |
Sean Hefty | 6a9af2e | 2006-06-17 20:37:27 -0700 | [diff] [blame] | 735 | if (copy_from_user(&upath, (void __user *)(unsigned long)src, |
| 736 | sizeof(upath))) { |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 737 | |
| 738 | kfree(sa_path); |
| 739 | return -EFAULT; |
| 740 | } |
| 741 | |
Sean Hefty | 6a9af2e | 2006-06-17 20:37:27 -0700 | [diff] [blame] | 742 | ib_copy_path_rec_from_user(sa_path, &upath); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 743 | *path = sa_path; |
| 744 | return 0; |
| 745 | } |
| 746 | |
| 747 | static ssize_t ib_ucm_send_req(struct ib_ucm_file *file, |
| 748 | const char __user *inbuf, |
| 749 | int in_len, int out_len) |
| 750 | { |
| 751 | struct ib_cm_req_param param; |
| 752 | struct ib_ucm_context *ctx; |
| 753 | struct ib_ucm_req cmd; |
| 754 | int result; |
| 755 | |
| 756 | param.private_data = NULL; |
| 757 | param.primary_path = NULL; |
| 758 | param.alternate_path = NULL; |
| 759 | |
| 760 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 761 | return -EFAULT; |
| 762 | |
| 763 | result = ib_ucm_alloc_data(¶m.private_data, cmd.data, cmd.len); |
| 764 | if (result) |
| 765 | goto done; |
| 766 | |
| 767 | result = ib_ucm_path_get(¶m.primary_path, cmd.primary_path); |
| 768 | if (result) |
| 769 | goto done; |
| 770 | |
| 771 | result = ib_ucm_path_get(¶m.alternate_path, cmd.alternate_path); |
| 772 | if (result) |
| 773 | goto done; |
| 774 | |
| 775 | param.private_data_len = cmd.len; |
| 776 | param.service_id = cmd.sid; |
| 777 | param.qp_num = cmd.qpn; |
| 778 | param.qp_type = cmd.qp_type; |
| 779 | param.starting_psn = cmd.psn; |
| 780 | param.peer_to_peer = cmd.peer_to_peer; |
| 781 | param.responder_resources = cmd.responder_resources; |
| 782 | param.initiator_depth = cmd.initiator_depth; |
| 783 | param.remote_cm_response_timeout = cmd.remote_cm_response_timeout; |
| 784 | param.flow_control = cmd.flow_control; |
| 785 | param.local_cm_response_timeout = cmd.local_cm_response_timeout; |
| 786 | param.retry_count = cmd.retry_count; |
| 787 | param.rnr_retry_count = cmd.rnr_retry_count; |
| 788 | param.max_cm_retries = cmd.max_cm_retries; |
| 789 | param.srq = cmd.srq; |
| 790 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 791 | ctx = ib_ucm_ctx_get(file, cmd.id); |
| 792 | if (!IS_ERR(ctx)) { |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 793 | result = ib_send_cm_req(ctx->cm_id, ¶m); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 794 | ib_ucm_ctx_put(ctx); |
| 795 | } else |
| 796 | result = PTR_ERR(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 797 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 798 | done: |
Hal Rosenstock | 79d8190 | 2005-07-27 20:38:56 -0700 | [diff] [blame] | 799 | kfree(param.private_data); |
| 800 | kfree(param.primary_path); |
| 801 | kfree(param.alternate_path); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 802 | return result; |
| 803 | } |
| 804 | |
| 805 | static ssize_t ib_ucm_send_rep(struct ib_ucm_file *file, |
| 806 | const char __user *inbuf, |
| 807 | int in_len, int out_len) |
| 808 | { |
| 809 | struct ib_cm_rep_param param; |
| 810 | struct ib_ucm_context *ctx; |
| 811 | struct ib_ucm_rep cmd; |
| 812 | int result; |
| 813 | |
| 814 | param.private_data = NULL; |
| 815 | |
| 816 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 817 | return -EFAULT; |
| 818 | |
| 819 | result = ib_ucm_alloc_data(¶m.private_data, cmd.data, cmd.len); |
| 820 | if (result) |
| 821 | return result; |
| 822 | |
| 823 | param.qp_num = cmd.qpn; |
| 824 | param.starting_psn = cmd.psn; |
| 825 | param.private_data_len = cmd.len; |
| 826 | param.responder_resources = cmd.responder_resources; |
| 827 | param.initiator_depth = cmd.initiator_depth; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 828 | param.failover_accepted = cmd.failover_accepted; |
| 829 | param.flow_control = cmd.flow_control; |
| 830 | param.rnr_retry_count = cmd.rnr_retry_count; |
| 831 | param.srq = cmd.srq; |
| 832 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 833 | ctx = ib_ucm_ctx_get(file, cmd.id); |
| 834 | if (!IS_ERR(ctx)) { |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 835 | ctx->uid = cmd.uid; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 836 | result = ib_send_cm_rep(ctx->cm_id, ¶m); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 837 | ib_ucm_ctx_put(ctx); |
| 838 | } else |
| 839 | result = PTR_ERR(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 840 | |
Hal Rosenstock | 79d8190 | 2005-07-27 20:38:56 -0700 | [diff] [blame] | 841 | kfree(param.private_data); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 842 | return result; |
| 843 | } |
| 844 | |
| 845 | static ssize_t ib_ucm_send_private_data(struct ib_ucm_file *file, |
| 846 | const char __user *inbuf, int in_len, |
| 847 | int (*func)(struct ib_cm_id *cm_id, |
| 848 | const void *private_data, |
| 849 | u8 private_data_len)) |
| 850 | { |
| 851 | struct ib_ucm_private_data cmd; |
| 852 | struct ib_ucm_context *ctx; |
| 853 | const void *private_data = NULL; |
| 854 | int result; |
| 855 | |
| 856 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 857 | return -EFAULT; |
| 858 | |
| 859 | result = ib_ucm_alloc_data(&private_data, cmd.data, cmd.len); |
| 860 | if (result) |
| 861 | return result; |
| 862 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 863 | ctx = ib_ucm_ctx_get(file, cmd.id); |
| 864 | if (!IS_ERR(ctx)) { |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 865 | result = func(ctx->cm_id, private_data, cmd.len); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 866 | ib_ucm_ctx_put(ctx); |
| 867 | } else |
| 868 | result = PTR_ERR(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 869 | |
Hal Rosenstock | 79d8190 | 2005-07-27 20:38:56 -0700 | [diff] [blame] | 870 | kfree(private_data); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 871 | return result; |
| 872 | } |
| 873 | |
| 874 | static ssize_t ib_ucm_send_rtu(struct ib_ucm_file *file, |
| 875 | const char __user *inbuf, |
| 876 | int in_len, int out_len) |
| 877 | { |
| 878 | return ib_ucm_send_private_data(file, inbuf, in_len, ib_send_cm_rtu); |
| 879 | } |
| 880 | |
| 881 | static ssize_t ib_ucm_send_dreq(struct ib_ucm_file *file, |
| 882 | const char __user *inbuf, |
| 883 | int in_len, int out_len) |
| 884 | { |
| 885 | return ib_ucm_send_private_data(file, inbuf, in_len, ib_send_cm_dreq); |
| 886 | } |
| 887 | |
| 888 | static ssize_t ib_ucm_send_drep(struct ib_ucm_file *file, |
| 889 | const char __user *inbuf, |
| 890 | int in_len, int out_len) |
| 891 | { |
| 892 | return ib_ucm_send_private_data(file, inbuf, in_len, ib_send_cm_drep); |
| 893 | } |
| 894 | |
| 895 | static ssize_t ib_ucm_send_info(struct ib_ucm_file *file, |
| 896 | const char __user *inbuf, int in_len, |
| 897 | int (*func)(struct ib_cm_id *cm_id, |
| 898 | int status, |
| 899 | const void *info, |
| 900 | u8 info_len, |
| 901 | const void *data, |
| 902 | u8 data_len)) |
| 903 | { |
| 904 | struct ib_ucm_context *ctx; |
| 905 | struct ib_ucm_info cmd; |
| 906 | const void *data = NULL; |
| 907 | const void *info = NULL; |
| 908 | int result; |
| 909 | |
| 910 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 911 | return -EFAULT; |
| 912 | |
| 913 | result = ib_ucm_alloc_data(&data, cmd.data, cmd.data_len); |
| 914 | if (result) |
| 915 | goto done; |
| 916 | |
| 917 | result = ib_ucm_alloc_data(&info, cmd.info, cmd.info_len); |
| 918 | if (result) |
| 919 | goto done; |
| 920 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 921 | ctx = ib_ucm_ctx_get(file, cmd.id); |
| 922 | if (!IS_ERR(ctx)) { |
| 923 | result = func(ctx->cm_id, cmd.status, info, cmd.info_len, |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 924 | data, cmd.data_len); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 925 | ib_ucm_ctx_put(ctx); |
| 926 | } else |
| 927 | result = PTR_ERR(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 928 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 929 | done: |
Hal Rosenstock | 79d8190 | 2005-07-27 20:38:56 -0700 | [diff] [blame] | 930 | kfree(data); |
| 931 | kfree(info); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 932 | return result; |
| 933 | } |
| 934 | |
| 935 | static ssize_t ib_ucm_send_rej(struct ib_ucm_file *file, |
| 936 | const char __user *inbuf, |
| 937 | int in_len, int out_len) |
| 938 | { |
| 939 | return ib_ucm_send_info(file, inbuf, in_len, (void *)ib_send_cm_rej); |
| 940 | } |
| 941 | |
| 942 | static ssize_t ib_ucm_send_apr(struct ib_ucm_file *file, |
| 943 | const char __user *inbuf, |
| 944 | int in_len, int out_len) |
| 945 | { |
| 946 | return ib_ucm_send_info(file, inbuf, in_len, (void *)ib_send_cm_apr); |
| 947 | } |
| 948 | |
| 949 | static ssize_t ib_ucm_send_mra(struct ib_ucm_file *file, |
| 950 | const char __user *inbuf, |
| 951 | int in_len, int out_len) |
| 952 | { |
| 953 | struct ib_ucm_context *ctx; |
| 954 | struct ib_ucm_mra cmd; |
| 955 | const void *data = NULL; |
| 956 | int result; |
| 957 | |
| 958 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 959 | return -EFAULT; |
| 960 | |
| 961 | result = ib_ucm_alloc_data(&data, cmd.data, cmd.len); |
| 962 | if (result) |
| 963 | return result; |
| 964 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 965 | ctx = ib_ucm_ctx_get(file, cmd.id); |
| 966 | if (!IS_ERR(ctx)) { |
| 967 | result = ib_send_cm_mra(ctx->cm_id, cmd.timeout, data, cmd.len); |
| 968 | ib_ucm_ctx_put(ctx); |
| 969 | } else |
| 970 | result = PTR_ERR(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 971 | |
Hal Rosenstock | 79d8190 | 2005-07-27 20:38:56 -0700 | [diff] [blame] | 972 | kfree(data); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 973 | return result; |
| 974 | } |
| 975 | |
| 976 | static ssize_t ib_ucm_send_lap(struct ib_ucm_file *file, |
| 977 | const char __user *inbuf, |
| 978 | int in_len, int out_len) |
| 979 | { |
| 980 | struct ib_ucm_context *ctx; |
| 981 | struct ib_sa_path_rec *path = NULL; |
| 982 | struct ib_ucm_lap cmd; |
| 983 | const void *data = NULL; |
| 984 | int result; |
| 985 | |
| 986 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 987 | return -EFAULT; |
| 988 | |
| 989 | result = ib_ucm_alloc_data(&data, cmd.data, cmd.len); |
| 990 | if (result) |
| 991 | goto done; |
| 992 | |
| 993 | result = ib_ucm_path_get(&path, cmd.path); |
| 994 | if (result) |
| 995 | goto done; |
| 996 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 997 | ctx = ib_ucm_ctx_get(file, cmd.id); |
| 998 | if (!IS_ERR(ctx)) { |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 999 | result = ib_send_cm_lap(ctx->cm_id, path, data, cmd.len); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 1000 | ib_ucm_ctx_put(ctx); |
| 1001 | } else |
| 1002 | result = PTR_ERR(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1003 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1004 | done: |
Hal Rosenstock | 79d8190 | 2005-07-27 20:38:56 -0700 | [diff] [blame] | 1005 | kfree(data); |
| 1006 | kfree(path); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1007 | return result; |
| 1008 | } |
| 1009 | |
| 1010 | static ssize_t ib_ucm_send_sidr_req(struct ib_ucm_file *file, |
| 1011 | const char __user *inbuf, |
| 1012 | int in_len, int out_len) |
| 1013 | { |
| 1014 | struct ib_cm_sidr_req_param param; |
| 1015 | struct ib_ucm_context *ctx; |
| 1016 | struct ib_ucm_sidr_req cmd; |
| 1017 | int result; |
| 1018 | |
| 1019 | param.private_data = NULL; |
| 1020 | param.path = NULL; |
| 1021 | |
| 1022 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 1023 | return -EFAULT; |
| 1024 | |
| 1025 | result = ib_ucm_alloc_data(¶m.private_data, cmd.data, cmd.len); |
| 1026 | if (result) |
| 1027 | goto done; |
| 1028 | |
| 1029 | result = ib_ucm_path_get(¶m.path, cmd.path); |
| 1030 | if (result) |
| 1031 | goto done; |
| 1032 | |
| 1033 | param.private_data_len = cmd.len; |
| 1034 | param.service_id = cmd.sid; |
| 1035 | param.timeout_ms = cmd.timeout; |
| 1036 | param.max_cm_retries = cmd.max_cm_retries; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1037 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 1038 | ctx = ib_ucm_ctx_get(file, cmd.id); |
| 1039 | if (!IS_ERR(ctx)) { |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1040 | result = ib_send_cm_sidr_req(ctx->cm_id, ¶m); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 1041 | ib_ucm_ctx_put(ctx); |
| 1042 | } else |
| 1043 | result = PTR_ERR(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1044 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1045 | done: |
Hal Rosenstock | 79d8190 | 2005-07-27 20:38:56 -0700 | [diff] [blame] | 1046 | kfree(param.private_data); |
| 1047 | kfree(param.path); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1048 | return result; |
| 1049 | } |
| 1050 | |
| 1051 | static ssize_t ib_ucm_send_sidr_rep(struct ib_ucm_file *file, |
| 1052 | const char __user *inbuf, |
| 1053 | int in_len, int out_len) |
| 1054 | { |
| 1055 | struct ib_cm_sidr_rep_param param; |
| 1056 | struct ib_ucm_sidr_rep cmd; |
| 1057 | struct ib_ucm_context *ctx; |
| 1058 | int result; |
| 1059 | |
| 1060 | param.info = NULL; |
| 1061 | |
| 1062 | if (copy_from_user(&cmd, inbuf, sizeof(cmd))) |
| 1063 | return -EFAULT; |
| 1064 | |
| 1065 | result = ib_ucm_alloc_data(¶m.private_data, |
| 1066 | cmd.data, cmd.data_len); |
| 1067 | if (result) |
| 1068 | goto done; |
| 1069 | |
| 1070 | result = ib_ucm_alloc_data(¶m.info, cmd.info, cmd.info_len); |
| 1071 | if (result) |
| 1072 | goto done; |
| 1073 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 1074 | param.qp_num = cmd.qpn; |
| 1075 | param.qkey = cmd.qkey; |
| 1076 | param.status = cmd.status; |
| 1077 | param.info_length = cmd.info_len; |
| 1078 | param.private_data_len = cmd.data_len; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1079 | |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 1080 | ctx = ib_ucm_ctx_get(file, cmd.id); |
| 1081 | if (!IS_ERR(ctx)) { |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1082 | result = ib_send_cm_sidr_rep(ctx->cm_id, ¶m); |
Sean Hefty | b9ef520 | 2005-08-19 13:46:34 -0700 | [diff] [blame] | 1083 | ib_ucm_ctx_put(ctx); |
| 1084 | } else |
| 1085 | result = PTR_ERR(ctx); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1086 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1087 | done: |
Hal Rosenstock | 79d8190 | 2005-07-27 20:38:56 -0700 | [diff] [blame] | 1088 | kfree(param.private_data); |
| 1089 | kfree(param.info); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1090 | return result; |
| 1091 | } |
| 1092 | |
| 1093 | static ssize_t (*ucm_cmd_table[])(struct ib_ucm_file *file, |
| 1094 | const char __user *inbuf, |
| 1095 | int in_len, int out_len) = { |
| 1096 | [IB_USER_CM_CMD_CREATE_ID] = ib_ucm_create_id, |
| 1097 | [IB_USER_CM_CMD_DESTROY_ID] = ib_ucm_destroy_id, |
| 1098 | [IB_USER_CM_CMD_ATTR_ID] = ib_ucm_attr_id, |
| 1099 | [IB_USER_CM_CMD_LISTEN] = ib_ucm_listen, |
Sean Hefty | e1444b5 | 2006-11-28 14:57:13 -0800 | [diff] [blame] | 1100 | [IB_USER_CM_CMD_NOTIFY] = ib_ucm_notify, |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1101 | [IB_USER_CM_CMD_SEND_REQ] = ib_ucm_send_req, |
| 1102 | [IB_USER_CM_CMD_SEND_REP] = ib_ucm_send_rep, |
| 1103 | [IB_USER_CM_CMD_SEND_RTU] = ib_ucm_send_rtu, |
| 1104 | [IB_USER_CM_CMD_SEND_DREQ] = ib_ucm_send_dreq, |
| 1105 | [IB_USER_CM_CMD_SEND_DREP] = ib_ucm_send_drep, |
| 1106 | [IB_USER_CM_CMD_SEND_REJ] = ib_ucm_send_rej, |
| 1107 | [IB_USER_CM_CMD_SEND_MRA] = ib_ucm_send_mra, |
| 1108 | [IB_USER_CM_CMD_SEND_LAP] = ib_ucm_send_lap, |
| 1109 | [IB_USER_CM_CMD_SEND_APR] = ib_ucm_send_apr, |
| 1110 | [IB_USER_CM_CMD_SEND_SIDR_REQ] = ib_ucm_send_sidr_req, |
| 1111 | [IB_USER_CM_CMD_SEND_SIDR_REP] = ib_ucm_send_sidr_rep, |
| 1112 | [IB_USER_CM_CMD_EVENT] = ib_ucm_event, |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 1113 | [IB_USER_CM_CMD_INIT_QP_ATTR] = ib_ucm_init_qp_attr, |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1114 | }; |
| 1115 | |
| 1116 | static ssize_t ib_ucm_write(struct file *filp, const char __user *buf, |
| 1117 | size_t len, loff_t *pos) |
| 1118 | { |
| 1119 | struct ib_ucm_file *file = filp->private_data; |
| 1120 | struct ib_ucm_cmd_hdr hdr; |
| 1121 | ssize_t result; |
| 1122 | |
| 1123 | if (len < sizeof(hdr)) |
| 1124 | return -EINVAL; |
| 1125 | |
| 1126 | if (copy_from_user(&hdr, buf, sizeof(hdr))) |
| 1127 | return -EFAULT; |
| 1128 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1129 | if (hdr.cmd < 0 || hdr.cmd >= ARRAY_SIZE(ucm_cmd_table)) |
| 1130 | return -EINVAL; |
| 1131 | |
| 1132 | if (hdr.in + sizeof(hdr) > len) |
| 1133 | return -EINVAL; |
| 1134 | |
| 1135 | result = ucm_cmd_table[hdr.cmd](file, buf + sizeof(hdr), |
| 1136 | hdr.in, hdr.out); |
| 1137 | if (!result) |
| 1138 | result = len; |
| 1139 | |
| 1140 | return result; |
| 1141 | } |
| 1142 | |
| 1143 | static unsigned int ib_ucm_poll(struct file *filp, |
| 1144 | struct poll_table_struct *wait) |
| 1145 | { |
| 1146 | struct ib_ucm_file *file = filp->private_data; |
| 1147 | unsigned int mask = 0; |
| 1148 | |
| 1149 | poll_wait(filp, &file->poll_wait, wait); |
| 1150 | |
| 1151 | if (!list_empty(&file->events)) |
| 1152 | mask = POLLIN | POLLRDNORM; |
| 1153 | |
| 1154 | return mask; |
| 1155 | } |
| 1156 | |
Roland Dreier | 5ba18b1 | 2008-07-24 20:36:59 -0700 | [diff] [blame] | 1157 | /* |
| 1158 | * ib_ucm_open() does not need the BKL: |
| 1159 | * |
| 1160 | * - no global state is referred to; |
| 1161 | * - there is no ioctl method to race against; |
| 1162 | * - no further module initialization is required for open to work |
| 1163 | * after the device is registered. |
| 1164 | */ |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1165 | static int ib_ucm_open(struct inode *inode, struct file *filp) |
| 1166 | { |
| 1167 | struct ib_ucm_file *file; |
| 1168 | |
| 1169 | file = kmalloc(sizeof(*file), GFP_KERNEL); |
| 1170 | if (!file) |
| 1171 | return -ENOMEM; |
| 1172 | |
| 1173 | INIT_LIST_HEAD(&file->events); |
| 1174 | INIT_LIST_HEAD(&file->ctxs); |
| 1175 | init_waitqueue_head(&file->poll_wait); |
| 1176 | |
Sean Hefty | 4be10c1e | 2006-05-25 10:03:23 -0700 | [diff] [blame] | 1177 | mutex_init(&file->file_mutex); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1178 | |
| 1179 | filp->private_data = file; |
| 1180 | file->filp = filp; |
Tony Jones | f4e91eb | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1181 | file->device = container_of(inode->i_cdev, struct ib_ucm_device, cdev); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1182 | |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1183 | return 0; |
| 1184 | } |
| 1185 | |
| 1186 | static int ib_ucm_close(struct inode *inode, struct file *filp) |
| 1187 | { |
| 1188 | struct ib_ucm_file *file = filp->private_data; |
| 1189 | struct ib_ucm_context *ctx; |
| 1190 | |
Sean Hefty | 4be10c1e | 2006-05-25 10:03:23 -0700 | [diff] [blame] | 1191 | mutex_lock(&file->file_mutex); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1192 | while (!list_empty(&file->ctxs)) { |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1193 | ctx = list_entry(file->ctxs.next, |
| 1194 | struct ib_ucm_context, file_list); |
Sean Hefty | 4be10c1e | 2006-05-25 10:03:23 -0700 | [diff] [blame] | 1195 | mutex_unlock(&file->file_mutex); |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 1196 | |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 1197 | mutex_lock(&ctx_id_mutex); |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 1198 | idr_remove(&ctx_id_table, ctx->id); |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 1199 | mutex_unlock(&ctx_id_mutex); |
Sean Hefty | 0b2b35f | 2005-09-01 09:28:03 -0700 | [diff] [blame] | 1200 | |
| 1201 | ib_destroy_cm_id(ctx->cm_id); |
| 1202 | ib_ucm_cleanup_events(ctx); |
| 1203 | kfree(ctx); |
| 1204 | |
Sean Hefty | 4be10c1e | 2006-05-25 10:03:23 -0700 | [diff] [blame] | 1205 | mutex_lock(&file->file_mutex); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1206 | } |
Sean Hefty | 4be10c1e | 2006-05-25 10:03:23 -0700 | [diff] [blame] | 1207 | mutex_unlock(&file->file_mutex); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1208 | kfree(file); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1209 | return 0; |
| 1210 | } |
| 1211 | |
Tony Jones | f4e91eb | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1212 | static void ib_ucm_release_dev(struct device *dev) |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1213 | { |
Tony Jones | f4e91eb | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1214 | struct ib_ucm_device *ucm_dev; |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1215 | |
Tony Jones | f4e91eb | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1216 | ucm_dev = container_of(dev, struct ib_ucm_device, dev); |
| 1217 | cdev_del(&ucm_dev->cdev); |
| 1218 | clear_bit(ucm_dev->devnum, dev_map); |
| 1219 | kfree(ucm_dev); |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1220 | } |
| 1221 | |
Arjan van de Ven | 2b8693c | 2007-02-12 00:55:32 -0800 | [diff] [blame] | 1222 | static const struct file_operations ucm_fops = { |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1223 | .owner = THIS_MODULE, |
| 1224 | .open = ib_ucm_open, |
| 1225 | .release = ib_ucm_close, |
| 1226 | .write = ib_ucm_write, |
| 1227 | .poll = ib_ucm_poll, |
| 1228 | }; |
| 1229 | |
Tony Jones | f4e91eb | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1230 | static ssize_t show_ibdev(struct device *dev, struct device_attribute *attr, |
| 1231 | char *buf) |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1232 | { |
Tony Jones | f4e91eb | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1233 | struct ib_ucm_device *ucm_dev; |
Roland Dreier | 3cd9656 | 2006-09-22 15:22:46 -0700 | [diff] [blame] | 1234 | |
Tony Jones | f4e91eb | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1235 | ucm_dev = container_of(dev, struct ib_ucm_device, dev); |
| 1236 | return sprintf(buf, "%s\n", ucm_dev->ib_dev->name); |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1237 | } |
Tony Jones | f4e91eb | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1238 | static DEVICE_ATTR(ibdev, S_IRUGO, show_ibdev, NULL); |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1239 | |
| 1240 | static void ib_ucm_add_one(struct ib_device *device) |
| 1241 | { |
| 1242 | struct ib_ucm_device *ucm_dev; |
| 1243 | |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1244 | if (!device->alloc_ucontext || |
| 1245 | rdma_node_get_transport(device->node_type) != RDMA_TRANSPORT_IB) |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1246 | return; |
| 1247 | |
Roland Dreier | de6eb66 | 2005-11-02 07:23:14 -0800 | [diff] [blame] | 1248 | ucm_dev = kzalloc(sizeof *ucm_dev, GFP_KERNEL); |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1249 | if (!ucm_dev) |
| 1250 | return; |
| 1251 | |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1252 | ucm_dev->ib_dev = device; |
| 1253 | |
| 1254 | ucm_dev->devnum = find_first_zero_bit(dev_map, IB_UCM_MAX_DEVICES); |
| 1255 | if (ucm_dev->devnum >= IB_UCM_MAX_DEVICES) |
| 1256 | goto err; |
| 1257 | |
| 1258 | set_bit(ucm_dev->devnum, dev_map); |
| 1259 | |
Tony Jones | f4e91eb | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1260 | cdev_init(&ucm_dev->cdev, &ucm_fops); |
| 1261 | ucm_dev->cdev.owner = THIS_MODULE; |
| 1262 | kobject_set_name(&ucm_dev->cdev.kobj, "ucm%d", ucm_dev->devnum); |
| 1263 | if (cdev_add(&ucm_dev->cdev, IB_UCM_BASE_DEV + ucm_dev->devnum, 1)) |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1264 | goto err; |
| 1265 | |
Tony Jones | f4e91eb | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1266 | ucm_dev->dev.class = &cm_class; |
| 1267 | ucm_dev->dev.parent = device->dma_device; |
| 1268 | ucm_dev->dev.devt = ucm_dev->cdev.dev; |
| 1269 | ucm_dev->dev.release = ib_ucm_release_dev; |
Kay Sievers | d927e38 | 2009-01-06 10:44:39 -0800 | [diff] [blame] | 1270 | dev_set_name(&ucm_dev->dev, "ucm%d", ucm_dev->devnum); |
Tony Jones | f4e91eb | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1271 | if (device_register(&ucm_dev->dev)) |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1272 | goto err_cdev; |
| 1273 | |
Tony Jones | f4e91eb | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1274 | if (device_create_file(&ucm_dev->dev, &dev_attr_ibdev)) |
| 1275 | goto err_dev; |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1276 | |
| 1277 | ib_set_client_data(device, &ucm_client, ucm_dev); |
| 1278 | return; |
| 1279 | |
Tony Jones | f4e91eb | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1280 | err_dev: |
| 1281 | device_unregister(&ucm_dev->dev); |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1282 | err_cdev: |
Tony Jones | f4e91eb | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1283 | cdev_del(&ucm_dev->cdev); |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1284 | clear_bit(ucm_dev->devnum, dev_map); |
| 1285 | err: |
| 1286 | kfree(ucm_dev); |
| 1287 | return; |
| 1288 | } |
| 1289 | |
| 1290 | static void ib_ucm_remove_one(struct ib_device *device) |
| 1291 | { |
| 1292 | struct ib_ucm_device *ucm_dev = ib_get_client_data(device, &ucm_client); |
| 1293 | |
| 1294 | if (!ucm_dev) |
| 1295 | return; |
| 1296 | |
Tony Jones | f4e91eb | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1297 | device_unregister(&ucm_dev->dev); |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | static ssize_t show_abi_version(struct class *class, char *buf) |
| 1301 | { |
| 1302 | return sprintf(buf, "%d\n", IB_USER_CM_ABI_VERSION); |
| 1303 | } |
| 1304 | static CLASS_ATTR(abi_version, S_IRUGO, show_abi_version, NULL); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1305 | |
| 1306 | static int __init ib_ucm_init(void) |
| 1307 | { |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1308 | int ret; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1309 | |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1310 | ret = register_chrdev_region(IB_UCM_BASE_DEV, IB_UCM_MAX_DEVICES, |
| 1311 | "infiniband_cm"); |
| 1312 | if (ret) { |
| 1313 | printk(KERN_ERR "ucm: couldn't register device number\n"); |
Sean Hefty | 9af57b7 | 2007-07-16 21:49:35 -0700 | [diff] [blame] | 1314 | goto error1; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1315 | } |
| 1316 | |
Sean Hefty | 9af57b7 | 2007-07-16 21:49:35 -0700 | [diff] [blame] | 1317 | ret = class_create_file(&cm_class, &class_attr_abi_version); |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1318 | if (ret) { |
| 1319 | printk(KERN_ERR "ucm: couldn't create abi_version attribute\n"); |
Sean Hefty | 9af57b7 | 2007-07-16 21:49:35 -0700 | [diff] [blame] | 1320 | goto error2; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1321 | } |
| 1322 | |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1323 | ret = ib_register_client(&ucm_client); |
| 1324 | if (ret) { |
| 1325 | printk(KERN_ERR "ucm: couldn't register client\n"); |
Sean Hefty | 9af57b7 | 2007-07-16 21:49:35 -0700 | [diff] [blame] | 1326 | goto error3; |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1327 | } |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1328 | return 0; |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1329 | |
Sean Hefty | 9af57b7 | 2007-07-16 21:49:35 -0700 | [diff] [blame] | 1330 | error3: |
| 1331 | class_remove_file(&cm_class, &class_attr_abi_version); |
| 1332 | error2: |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1333 | unregister_chrdev_region(IB_UCM_BASE_DEV, IB_UCM_MAX_DEVICES); |
Sean Hefty | 9af57b7 | 2007-07-16 21:49:35 -0700 | [diff] [blame] | 1334 | error1: |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1335 | return ret; |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | static void __exit ib_ucm_cleanup(void) |
| 1339 | { |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1340 | ib_unregister_client(&ucm_client); |
Sean Hefty | 9af57b7 | 2007-07-16 21:49:35 -0700 | [diff] [blame] | 1341 | class_remove_file(&cm_class, &class_attr_abi_version); |
Sean Hefty | 07d357d | 2005-10-17 15:37:43 -0700 | [diff] [blame] | 1342 | unregister_chrdev_region(IB_UCM_BASE_DEV, IB_UCM_MAX_DEVICES); |
Roland Dreier | 5d7edb3 | 2005-10-24 10:53:25 -0700 | [diff] [blame] | 1343 | idr_destroy(&ctx_id_table); |
Hal Rosenstock | a5b7454 | 2005-07-27 11:45:44 -0700 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | module_init(ib_ucm_init); |
| 1347 | module_exit(ib_ucm_cleanup); |