blob: 9164a09b6ccd1d0aeea7153d29c8307e3c5903ca [file] [log] [blame]
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001/*
2 * Copyright (c) 2005 Topspin Communications. All rights reserved.
Sean Heftyb9ef5202005-08-19 13:46:34 -07003 * Copyright (c) 2005 Intel Corporation. All rights reserved.
Hal Rosenstocka5b74542005-07-27 11:45:44 -07004 *
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 Hefty1b52fa982006-05-12 14:57:52 -070035
36#include <linux/completion.h>
Hal Rosenstocka5b74542005-07-27 11:45:44 -070037#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 Hefty595e7262005-10-17 15:33:47 -070046#include <linux/idr.h>
Ingo Molnar95ed6442006-01-13 14:51:39 -080047#include <linux/mutex.h>
Hal Rosenstocka5b74542005-07-27 11:45:44 -070048
49#include <asm/uaccess.h>
50
Sean Hefty595e7262005-10-17 15:33:47 -070051#include <rdma/ib_cm.h>
52#include <rdma/ib_user_cm.h>
Hal Rosenstocka5b74542005-07-27 11:45:44 -070053
54MODULE_AUTHOR("Libor Michalek");
55MODULE_DESCRIPTION("InfiniBand userspace Connection Manager access");
56MODULE_LICENSE("Dual BSD/GPL");
57
Sean Hefty07d357d2005-10-17 15:37:43 -070058struct 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 Hefty595e7262005-10-17 15:33:47 -070065struct ib_ucm_file {
66 struct semaphore mutex;
67 struct file *filp;
Sean Hefty07d357d2005-10-17 15:37:43 -070068 struct ib_ucm_device *device;
Hal Rosenstock79d81902005-07-27 20:38:56 -070069
Sean Hefty07d357d2005-10-17 15:37:43 -070070 struct list_head ctxs;
71 struct list_head events;
Sean Hefty595e7262005-10-17 15:33:47 -070072 wait_queue_head_t poll_wait;
73};
74
75struct ib_ucm_context {
76 int id;
Sean Hefty1b52fa982006-05-12 14:57:52 -070077 struct completion comp;
Sean Hefty595e7262005-10-17 15:33:47 -070078 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
89struct 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 Rosenstock79d81902005-07-27 20:38:56 -0700101
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700102enum {
103 IB_UCM_MAJOR = 231,
Sean Hefty07d357d2005-10-17 15:37:43 -0700104 IB_UCM_BASE_MINOR = 224,
105 IB_UCM_MAX_DEVICES = 32
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700106};
107
Sean Hefty07d357d2005-10-17 15:37:43 -0700108#define IB_UCM_BASE_DEV MKDEV(IB_UCM_MAJOR, IB_UCM_BASE_MINOR)
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700109
Sean Hefty07d357d2005-10-17 15:37:43 -0700110static void ib_ucm_add_one(struct ib_device *device);
111static void ib_ucm_remove_one(struct ib_device *device);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700112
Sean Hefty07d357d2005-10-17 15:37:43 -0700113static struct ib_client ucm_client = {
114 .name = "ucm",
115 .add = ib_ucm_add_one,
116 .remove = ib_ucm_remove_one
117};
118
Ingo Molnar95ed6442006-01-13 14:51:39 -0800119static DEFINE_MUTEX(ctx_id_mutex);
Roland Dreier762a03e2005-10-17 15:38:50 -0700120static DEFINE_IDR(ctx_id_table);
Sean Hefty07d357d2005-10-17 15:37:43 -0700121static DECLARE_BITMAP(dev_map, IB_UCM_MAX_DEVICES);
Sean Hefty595e7262005-10-17 15:33:47 -0700122
Sean Heftyb9ef5202005-08-19 13:46:34 -0700123static struct ib_ucm_context *ib_ucm_ctx_get(struct ib_ucm_file *file, int id)
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700124{
125 struct ib_ucm_context *ctx;
126
Ingo Molnar95ed6442006-01-13 14:51:39 -0800127 mutex_lock(&ctx_id_mutex);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700128 ctx = idr_find(&ctx_id_table, id);
Sean Heftyb9ef5202005-08-19 13:46:34 -0700129 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 Molnar95ed6442006-01-13 14:51:39 -0800135 mutex_unlock(&ctx_id_mutex);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700136
137 return ctx;
138}
139
140static void ib_ucm_ctx_put(struct ib_ucm_context *ctx)
141{
Sean Heftyb9ef5202005-08-19 13:46:34 -0700142 if (atomic_dec_and_test(&ctx->ref))
Sean Hefty1b52fa982006-05-12 14:57:52 -0700143 complete(&ctx->comp);
Sean Heftyb9ef5202005-08-19 13:46:34 -0700144}
145
Sean Hefty0b2b35f2005-09-01 09:28:03 -0700146static inline int ib_ucm_new_cm_id(int event)
Sean Heftyb9ef5202005-08-19 13:46:34 -0700147{
Sean Hefty0b2b35f2005-09-01 09:28:03 -0700148 return event == IB_CM_REQ_RECEIVED || event == IB_CM_SIDR_REQ_RECEIVED;
149}
150
151static void ib_ucm_cleanup_events(struct ib_ucm_context *ctx)
152{
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700153 struct ib_ucm_event *uevent;
154
Sean Hefty0b2b35f2005-09-01 09:28:03 -0700155 down(&ctx->file->mutex);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700156 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 Hefty0b2b35f2005-09-01 09:28:03 -0700165 if (ib_ucm_new_cm_id(uevent->resp.event))
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700166 ib_destroy_cm_id(uevent->cm_id);
167
168 kfree(uevent);
169 }
Sean Hefty0b2b35f2005-09-01 09:28:03 -0700170 up(&ctx->file->mutex);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700171}
172
173static 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 Dreierde6eb662005-11-02 07:23:14 -0800178 ctx = kzalloc(sizeof *ctx, GFP_KERNEL);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700179 if (!ctx)
180 return NULL;
181
Sean Heftyb9ef5202005-08-19 13:46:34 -0700182 atomic_set(&ctx->ref, 1);
Sean Hefty1b52fa982006-05-12 14:57:52 -0700183 init_completion(&ctx->comp);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700184 ctx->file = file;
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700185 INIT_LIST_HEAD(&ctx->events);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700186
Sean Hefty0b2b35f2005-09-01 09:28:03 -0700187 do {
188 result = idr_pre_get(&ctx_id_table, GFP_KERNEL);
189 if (!result)
190 goto error;
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700191
Ingo Molnar95ed6442006-01-13 14:51:39 -0800192 mutex_lock(&ctx_id_mutex);
Sean Hefty0b2b35f2005-09-01 09:28:03 -0700193 result = idr_get_new(&ctx_id_table, ctx, &ctx->id);
Ingo Molnar95ed6442006-01-13 14:51:39 -0800194 mutex_unlock(&ctx_id_mutex);
Sean Hefty0b2b35f2005-09-01 09:28:03 -0700195 } while (result == -EAGAIN);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700196
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700197 if (result)
198 goto error;
199
Sean Hefty0b2b35f2005-09-01 09:28:03 -0700200 list_add_tail(&ctx->file_list, &file->ctxs);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700201 return ctx;
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700202
Sean Hefty0b2b35f2005-09-01 09:28:03 -0700203error:
204 kfree(ctx);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700205 return NULL;
206}
Sean Hefty07d357d2005-10-17 15:37:43 -0700207
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700208static 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 Heftyb9ef5202005-08-19 13:46:34 -0700214 memcpy(upath->dgid, kpath->dgid.raw, sizeof *upath->dgid);
215 memcpy(upath->sgid, kpath->sgid.raw, sizeof *upath->sgid);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700216
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 Hefty0b2b35f2005-09-01 09:28:03 -0700238static void ib_ucm_event_req_get(struct ib_ucm_req_event_resp *ureq,
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700239 struct ib_cm_req_event_param *kreq)
240{
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700241 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 Hefty07d357d2005-10-17 15:37:43 -0700254 ureq->port = kreq->port;
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700255
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
260static 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 Rosenstocka5b74542005-07-27 11:45:44 -0700276static 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 Hefty0b2b35f2005-09-01 09:28:03 -0700284static int ib_ucm_event_process(struct ib_cm_event *evt,
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700285 struct ib_ucm_event *uvt)
286{
287 void *info = NULL;
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700288
289 switch (evt->event) {
290 case IB_CM_REQ_RECEIVED:
Sean Hefty0b2b35f2005-09-01 09:28:03 -0700291 ib_ucm_event_req_get(&uvt->resp.u.req_resp,
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700292 &evt->param.req_rcvd);
293 uvt->data_len = IB_CM_REQ_PRIVATE_DATA_SIZE;
Sean Heftyb9ef5202005-08-19 13:46:34 -0700294 uvt->resp.present = IB_UCM_PRES_PRIMARY;
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700295 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 Rosenstocka5b74542005-07-27 11:45:44 -0700302 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 Rosenstocka5b74542005-07-27 11:45:44 -0700306 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 Rosenstocka5b74542005-07-27 11:45:44 -0700310 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 Rosenstocka5b74542005-07-27 11:45:44 -0700314 break;
315 case IB_CM_MRA_RECEIVED:
Sean Heftyb9ef5202005-08-19 13:46:34 -0700316 uvt->resp.u.mra_resp.timeout =
317 evt->param.mra_rcvd.service_timeout;
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700318 uvt->data_len = IB_CM_MRA_PRIVATE_DATA_SIZE;
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700319 break;
320 case IB_CM_REJ_RECEIVED:
Sean Heftyb9ef5202005-08-19 13:46:34 -0700321 uvt->resp.u.rej_resp.reason = evt->param.rej_rcvd.reason;
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700322 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 Rosenstocka5b74542005-07-27 11:45:44 -0700325 break;
326 case IB_CM_LAP_RECEIVED:
Sean Heftyb9ef5202005-08-19 13:46:34 -0700327 ib_ucm_event_path_get(&uvt->resp.u.lap_resp.path,
328 evt->param.lap_rcvd.alternate_path);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700329 uvt->data_len = IB_CM_LAP_PRIVATE_DATA_SIZE;
Sean Heftyb9ef5202005-08-19 13:46:34 -0700330 uvt->resp.present = IB_UCM_PRES_ALTERNATE;
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700331 break;
332 case IB_CM_APR_RECEIVED:
Sean Heftyb9ef5202005-08-19 13:46:34 -0700333 uvt->resp.u.apr_resp.status = evt->param.apr_rcvd.ap_status;
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700334 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 Rosenstocka5b74542005-07-27 11:45:44 -0700337 break;
338 case IB_CM_SIDR_REQ_RECEIVED:
Sean Hefty0b2b35f2005-09-01 09:28:03 -0700339 uvt->resp.u.sidr_req_resp.pkey =
340 evt->param.sidr_req_rcvd.pkey;
Sean Hefty07d357d2005-10-17 15:37:43 -0700341 uvt->resp.u.sidr_req_resp.port =
342 evt->param.sidr_req_rcvd.port;
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700343 uvt->data_len = IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE;
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700344 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 Rosenstocka5b74542005-07-27 11:45:44 -0700351 break;
352 default:
353 uvt->resp.u.send_status = evt->param.send_status;
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700354 break;
355 }
356
Sean Heftyb9ef5202005-08-19 13:46:34 -0700357 if (uvt->data_len) {
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700358 uvt->data = kmalloc(uvt->data_len, GFP_KERNEL);
Sean Heftyb9ef5202005-08-19 13:46:34 -0700359 if (!uvt->data)
360 goto err1;
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700361
362 memcpy(uvt->data, evt->private_data, uvt->data_len);
363 uvt->resp.present |= IB_UCM_PRES_DATA;
364 }
365
Sean Heftyb9ef5202005-08-19 13:46:34 -0700366 if (uvt->info_len) {
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700367 uvt->info = kmalloc(uvt->info_len, GFP_KERNEL);
Sean Heftyb9ef5202005-08-19 13:46:34 -0700368 if (!uvt->info)
369 goto err2;
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700370
371 memcpy(uvt->info, info, uvt->info_len);
372 uvt->resp.present |= IB_UCM_PRES_INFO;
373 }
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700374 return 0;
Sean Heftyb9ef5202005-08-19 13:46:34 -0700375
376err2:
Hal Rosenstock79d81902005-07-27 20:38:56 -0700377 kfree(uvt->data);
Sean Heftyb9ef5202005-08-19 13:46:34 -0700378err1:
379 return -ENOMEM;
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700380}
381
382static 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 Rosenstocka5b74542005-07-27 11:45:44 -0700388
Sean Heftyb9ef5202005-08-19 13:46:34 -0700389 ctx = cm_id->context;
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700390
Roland Dreierde6eb662005-11-02 07:23:14 -0800391 uevent = kzalloc(sizeof *uevent, GFP_KERNEL);
Sean Heftyb9ef5202005-08-19 13:46:34 -0700392 if (!uevent)
393 goto err1;
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700394
Sean Hefty0b2b35f2005-09-01 09:28:03 -0700395 uevent->ctx = ctx;
396 uevent->cm_id = cm_id;
397 uevent->resp.uid = ctx->uid;
398 uevent->resp.id = ctx->id;
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700399 uevent->resp.event = event->event;
400
Sean Hefty0b2b35f2005-09-01 09:28:03 -0700401 result = ib_ucm_event_process(event, uevent);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700402 if (result)
Sean Heftyb9ef5202005-08-19 13:46:34 -0700403 goto err2;
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700404
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700405 down(&ctx->file->mutex);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700406 list_add_tail(&uevent->file_list, &ctx->file->events);
407 list_add_tail(&uevent->ctx_list, &ctx->events);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700408 wake_up_interruptible(&ctx->file->poll_wait);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700409 up(&ctx->file->mutex);
Sean Heftyb9ef5202005-08-19 13:46:34 -0700410 return 0;
411
412err2:
413 kfree(uevent);
414err1:
415 /* Destroy new cm_id's */
Sean Hefty0b2b35f2005-09-01 09:28:03 -0700416 return ib_ucm_new_cm_id(event->event);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700417}
418
419static 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 Hefty0b2b35f2005-09-01 09:28:03 -0700425 struct ib_ucm_event *uevent;
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700426 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 Hefty07d357d2005-10-17 15:37:43 -0700434
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700435 down(&file->mutex);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700436 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 Hefty0b2b35f2005-09-01 09:28:03 -0700462 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 Rosenstocka5b74542005-07-27 11:45:44 -0700468
Sean Hefty0b2b35f2005-09-01 09:28:03 -0700469 ctx->cm_id = uevent->cm_id;
470 ctx->cm_id->context = ctx;
471 uevent->resp.id = ctx->id;
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700472 }
473
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700474 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 Rosenstocka5b74542005-07-27 11:45:44 -0700481 if (cmd.data_len < uevent->data_len) {
482 result = -ENOMEM;
483 goto done;
484 }
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700485 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 Rosenstocka5b74542005-07-27 11:45:44 -0700493 if (cmd.info_len < uevent->info_len) {
494 result = -ENOMEM;
495 goto done;
496 }
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700497 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 Hefty0b2b35f2005-09-01 09:28:03 -0700506 uevent->ctx->events_reported++;
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700507
Hal Rosenstock79d81902005-07-27 20:38:56 -0700508 kfree(uevent->data);
509 kfree(uevent->info);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700510 kfree(uevent);
511done:
512 up(&file->mutex);
513 return result;
514}
515
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700516static 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 Heftyb9ef5202005-08-19 13:46:34 -0700531 down(&file->mutex);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700532 ctx = ib_ucm_ctx_alloc(file);
Sean Heftyb9ef5202005-08-19 13:46:34 -0700533 up(&file->mutex);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700534 if (!ctx)
535 return -ENOMEM;
536
Sean Hefty0b2b35f2005-09-01 09:28:03 -0700537 ctx->uid = cmd.uid;
Sean Hefty07d357d2005-10-17 15:37:43 -0700538 ctx->cm_id = ib_create_cm_id(file->device->ib_dev,
539 ib_ucm_event_handler, ctx);
Sean Heftyb9ef5202005-08-19 13:46:34 -0700540 if (IS_ERR(ctx->cm_id)) {
541 result = PTR_ERR(ctx->cm_id);
Sean Hefty07d357d2005-10-17 15:37:43 -0700542 goto err1;
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700543 }
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 Hefty07d357d2005-10-17 15:37:43 -0700549 goto err2;
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700550 }
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700551 return 0;
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700552
Sean Hefty07d357d2005-10-17 15:37:43 -0700553err2:
554 ib_destroy_cm_id(ctx->cm_id);
555err1:
Ingo Molnar95ed6442006-01-13 14:51:39 -0800556 mutex_lock(&ctx_id_mutex);
Sean Hefty0b2b35f2005-09-01 09:28:03 -0700557 idr_remove(&ctx_id_table, ctx->id);
Ingo Molnar95ed6442006-01-13 14:51:39 -0800558 mutex_unlock(&ctx_id_mutex);
Sean Hefty0b2b35f2005-09-01 09:28:03 -0700559 kfree(ctx);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700560 return result;
561}
562
563static 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 Hefty0b2b35f2005-09-01 09:28:03 -0700568 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 Rosenstocka5b74542005-07-27 11:45:44 -0700574
575 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
576 return -EFAULT;
577
Ingo Molnar95ed6442006-01-13 14:51:39 -0800578 mutex_lock(&ctx_id_mutex);
Sean Hefty0b2b35f2005-09-01 09:28:03 -0700579 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 Molnar95ed6442006-01-13 14:51:39 -0800586 mutex_unlock(&ctx_id_mutex);
Sean Hefty0b2b35f2005-09-01 09:28:03 -0700587
588 if (IS_ERR(ctx))
589 return PTR_ERR(ctx);
590
Sean Hefty1b52fa982006-05-12 14:57:52 -0700591 ib_ucm_ctx_put(ctx);
592 wait_for_completion(&ctx->comp);
Sean Hefty0b2b35f2005-09-01 09:28:03 -0700593
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 Rosenstocka5b74542005-07-27 11:45:44 -0700606}
607
608static 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 Heftyb9ef5202005-08-19 13:46:34 -0700623 ctx = ib_ucm_ctx_get(file, cmd.id);
624 if (IS_ERR(ctx))
625 return PTR_ERR(ctx);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700626
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 Heftyb9ef5202005-08-19 13:46:34 -0700636 ib_ucm_ctx_put(ctx);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700637 return result;
638}
639
Sean Hefty0b2b35f2005-09-01 09:28:03 -0700640static 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
658static 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
694static 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
727out:
728 ib_ucm_ctx_put(ctx);
729 return result;
730}
731
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700732static 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 Heftyb9ef5202005-08-19 13:46:34 -0700743 ctx = ib_ucm_ctx_get(file, cmd.id);
744 if (IS_ERR(ctx))
745 return PTR_ERR(ctx);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700746
Sean Heftyb9ef5202005-08-19 13:46:34 -0700747 result = ib_cm_listen(ctx->cm_id, cmd.service_id, cmd.service_mask);
748 ib_ucm_ctx_put(ctx);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700749 return result;
750}
751
752static 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 Heftyb9ef5202005-08-19 13:46:34 -0700763 ctx = ib_ucm_ctx_get(file, cmd.id);
764 if (IS_ERR(ctx))
765 return PTR_ERR(ctx);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700766
Sean Heftyb9ef5202005-08-19 13:46:34 -0700767 result = ib_cm_establish(ctx->cm_id);
768 ib_ucm_ctx_put(ctx);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700769 return result;
770}
771
772static 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
794static 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 Heftyb9ef5202005-08-19 13:46:34 -0700815 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 Rosenstocka5b74542005-07-27 11:45:44 -0700817
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
842static 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(&param.private_data, cmd.data, cmd.len);
859 if (result)
860 goto done;
861
862 result = ib_ucm_path_get(&param.primary_path, cmd.primary_path);
863 if (result)
864 goto done;
865
866 result = ib_ucm_path_get(&param.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 Heftyb9ef5202005-08-19 13:46:34 -0700886 ctx = ib_ucm_ctx_get(file, cmd.id);
887 if (!IS_ERR(ctx)) {
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700888 result = ib_send_cm_req(ctx->cm_id, &param);
Sean Heftyb9ef5202005-08-19 13:46:34 -0700889 ib_ucm_ctx_put(ctx);
890 } else
891 result = PTR_ERR(ctx);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700892
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700893done:
Hal Rosenstock79d81902005-07-27 20:38:56 -0700894 kfree(param.private_data);
895 kfree(param.primary_path);
896 kfree(param.alternate_path);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700897 return result;
898}
899
900static 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(&param.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 Heftyb9ef5202005-08-19 13:46:34 -0700929 ctx = ib_ucm_ctx_get(file, cmd.id);
930 if (!IS_ERR(ctx)) {
Sean Hefty0b2b35f2005-09-01 09:28:03 -0700931 ctx->uid = cmd.uid;
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700932 result = ib_send_cm_rep(ctx->cm_id, &param);
Sean Heftyb9ef5202005-08-19 13:46:34 -0700933 ib_ucm_ctx_put(ctx);
934 } else
935 result = PTR_ERR(ctx);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700936
Hal Rosenstock79d81902005-07-27 20:38:56 -0700937 kfree(param.private_data);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700938 return result;
939}
940
941static 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 Heftyb9ef5202005-08-19 13:46:34 -0700959 ctx = ib_ucm_ctx_get(file, cmd.id);
960 if (!IS_ERR(ctx)) {
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700961 result = func(ctx->cm_id, private_data, cmd.len);
Sean Heftyb9ef5202005-08-19 13:46:34 -0700962 ib_ucm_ctx_put(ctx);
963 } else
964 result = PTR_ERR(ctx);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700965
Hal Rosenstock79d81902005-07-27 20:38:56 -0700966 kfree(private_data);
Hal Rosenstocka5b74542005-07-27 11:45:44 -0700967 return result;
968}
969
970static 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
977static 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
984static 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
991static 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 Heftyb9ef5202005-08-19 13:46:34 -07001017 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 Rosenstocka5b74542005-07-27 11:45:44 -07001020 data, cmd.data_len);
Sean Heftyb9ef5202005-08-19 13:46:34 -07001021 ib_ucm_ctx_put(ctx);
1022 } else
1023 result = PTR_ERR(ctx);
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001024
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001025done:
Hal Rosenstock79d81902005-07-27 20:38:56 -07001026 kfree(data);
1027 kfree(info);
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001028 return result;
1029}
1030
1031static 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
1038static 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
1045static 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 Heftyb9ef5202005-08-19 13:46:34 -07001061 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 Rosenstocka5b74542005-07-27 11:45:44 -07001067
Hal Rosenstock79d81902005-07-27 20:38:56 -07001068 kfree(data);
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001069 return result;
1070}
1071
1072static 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 Heftyb9ef5202005-08-19 13:46:34 -07001093 ctx = ib_ucm_ctx_get(file, cmd.id);
1094 if (!IS_ERR(ctx)) {
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001095 result = ib_send_cm_lap(ctx->cm_id, path, data, cmd.len);
Sean Heftyb9ef5202005-08-19 13:46:34 -07001096 ib_ucm_ctx_put(ctx);
1097 } else
1098 result = PTR_ERR(ctx);
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001099
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001100done:
Hal Rosenstock79d81902005-07-27 20:38:56 -07001101 kfree(data);
1102 kfree(path);
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001103 return result;
1104}
1105
1106static 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(&param.private_data, cmd.data, cmd.len);
1122 if (result)
1123 goto done;
1124
1125 result = ib_ucm_path_get(&param.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 Heftyb9ef5202005-08-19 13:46:34 -07001135 ctx = ib_ucm_ctx_get(file, cmd.id);
1136 if (!IS_ERR(ctx)) {
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001137 result = ib_send_cm_sidr_req(ctx->cm_id, &param);
Sean Heftyb9ef5202005-08-19 13:46:34 -07001138 ib_ucm_ctx_put(ctx);
1139 } else
1140 result = PTR_ERR(ctx);
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001141
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001142done:
Hal Rosenstock79d81902005-07-27 20:38:56 -07001143 kfree(param.private_data);
1144 kfree(param.path);
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001145 return result;
1146}
1147
1148static 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(&param.private_data,
1163 cmd.data, cmd.data_len);
1164 if (result)
1165 goto done;
1166
1167 result = ib_ucm_alloc_data(&param.info, cmd.info, cmd.info_len);
1168 if (result)
1169 goto done;
1170
Sean Heftyb9ef5202005-08-19 13:46:34 -07001171 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 Rosenstocka5b74542005-07-27 11:45:44 -07001176
Sean Heftyb9ef5202005-08-19 13:46:34 -07001177 ctx = ib_ucm_ctx_get(file, cmd.id);
1178 if (!IS_ERR(ctx)) {
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001179 result = ib_send_cm_sidr_rep(ctx->cm_id, &param);
Sean Heftyb9ef5202005-08-19 13:46:34 -07001180 ib_ucm_ctx_put(ctx);
1181 } else
1182 result = PTR_ERR(ctx);
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001183
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001184done:
Hal Rosenstock79d81902005-07-27 20:38:56 -07001185 kfree(param.private_data);
1186 kfree(param.info);
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001187 return result;
1188}
1189
1190static 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 Hefty0b2b35f2005-09-01 09:28:03 -07001210 [IB_USER_CM_CMD_INIT_QP_ATTR] = ib_ucm_init_qp_attr,
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001211};
1212
1213static 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 Rosenstocka5b74542005-07-27 11:45:44 -07001226 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
1240static 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
1254static 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 Hefty07d357d2005-10-17 15:37:43 -07001270 file->device = container_of(inode->i_cdev, struct ib_ucm_device, dev);
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001271
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001272 return 0;
1273}
1274
1275static 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 Rosenstocka5b74542005-07-27 11:45:44 -07001281 while (!list_empty(&file->ctxs)) {
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001282 ctx = list_entry(file->ctxs.next,
1283 struct ib_ucm_context, file_list);
Sean Heftyb9ef5202005-08-19 13:46:34 -07001284 up(&file->mutex);
Sean Hefty0b2b35f2005-09-01 09:28:03 -07001285
Ingo Molnar95ed6442006-01-13 14:51:39 -08001286 mutex_lock(&ctx_id_mutex);
Sean Hefty0b2b35f2005-09-01 09:28:03 -07001287 idr_remove(&ctx_id_table, ctx->id);
Ingo Molnar95ed6442006-01-13 14:51:39 -08001288 mutex_unlock(&ctx_id_mutex);
Sean Hefty0b2b35f2005-09-01 09:28:03 -07001289
1290 ib_destroy_cm_id(ctx->cm_id);
1291 ib_ucm_cleanup_events(ctx);
1292 kfree(ctx);
1293
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001294 down(&file->mutex);
1295 }
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001296 up(&file->mutex);
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001297 kfree(file);
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001298 return 0;
1299}
1300
Sean Hefty07d357d2005-10-17 15:37:43 -07001301static 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
1311static struct file_operations ucm_fops = {
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001312 .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 Hefty07d357d2005-10-17 15:37:43 -07001319static struct class ucm_class = {
1320 .name = "infiniband_cm",
1321 .release = ib_ucm_release_class_dev
1322};
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001323
Sean Hefty07d357d2005-10-17 15:37:43 -07001324static 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}
1331static CLASS_DEVICE_ATTR(ibdev, S_IRUGO, show_ibdev, NULL);
1332
1333static 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 Dreierde6eb662005-11-02 07:23:14 -08001340 ucm_dev = kzalloc(sizeof *ucm_dev, GFP_KERNEL);
Sean Hefty07d357d2005-10-17 15:37:43 -07001341 if (!ucm_dev)
1342 return;
1343
Sean Hefty07d357d2005-10-17 15:37:43 -07001344 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-Hartman68f5f992006-01-20 14:08:59 -08001360 ucm_dev->class_dev.devt = ucm_dev->dev.dev;
Sean Hefty07d357d2005-10-17 15:37:43 -07001361 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 Hefty07d357d2005-10-17 15:37:43 -07001367 &class_device_attr_ibdev))
1368 goto err_class;
1369
1370 ib_set_client_data(device, &ucm_client, ucm_dev);
1371 return;
1372
1373err_class:
1374 class_device_unregister(&ucm_dev->class_dev);
1375err_cdev:
1376 cdev_del(&ucm_dev->dev);
1377 clear_bit(ucm_dev->devnum, dev_map);
1378err:
1379 kfree(ucm_dev);
1380 return;
1381}
1382
1383static 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
1393static ssize_t show_abi_version(struct class *class, char *buf)
1394{
1395 return sprintf(buf, "%d\n", IB_USER_CM_ABI_VERSION);
1396}
1397static CLASS_ATTR(abi_version, S_IRUGO, show_abi_version, NULL);
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001398
1399static int __init ib_ucm_init(void)
1400{
Sean Hefty07d357d2005-10-17 15:37:43 -07001401 int ret;
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001402
Sean Hefty07d357d2005-10-17 15:37:43 -07001403 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 Rosenstocka5b74542005-07-27 11:45:44 -07001408 }
1409
Sean Hefty07d357d2005-10-17 15:37:43 -07001410 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 Rosenstocka5b74542005-07-27 11:45:44 -07001414 }
1415
Sean Hefty07d357d2005-10-17 15:37:43 -07001416 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 Rosenstocka5b74542005-07-27 11:45:44 -07001419 goto err_class;
1420 }
1421
Sean Hefty07d357d2005-10-17 15:37:43 -07001422 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 Rosenstocka5b74542005-07-27 11:45:44 -07001427 return 0;
Sean Hefty07d357d2005-10-17 15:37:43 -07001428
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001429err_class:
Sean Hefty07d357d2005-10-17 15:37:43 -07001430 class_unregister(&ucm_class);
1431err_chrdev:
1432 unregister_chrdev_region(IB_UCM_BASE_DEV, IB_UCM_MAX_DEVICES);
1433err:
1434 return ret;
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001435}
1436
1437static void __exit ib_ucm_cleanup(void)
1438{
Sean Hefty07d357d2005-10-17 15:37:43 -07001439 ib_unregister_client(&ucm_client);
1440 class_unregister(&ucm_class);
1441 unregister_chrdev_region(IB_UCM_BASE_DEV, IB_UCM_MAX_DEVICES);
Roland Dreier5d7edb32005-10-24 10:53:25 -07001442 idr_destroy(&ctx_id_table);
Hal Rosenstocka5b74542005-07-27 11:45:44 -07001443}
1444
1445module_init(ib_ucm_init);
1446module_exit(ib_ucm_cleanup);