IB/core: Pass hardware specific data in query_device
[deliverable/linux.git] / drivers / infiniband / core / device.c
CommitLineData
1da177e4
LT
1/*
2 * Copyright (c) 2004 Topspin Communications. All rights reserved.
2a1d9b7f 3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
1da177e4
LT
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.
1da177e4
LT
32 */
33
34#include <linux/module.h>
35#include <linux/string.h>
36#include <linux/errno.h>
9a6b090c 37#include <linux/kernel.h>
1da177e4
LT
38#include <linux/slab.h>
39#include <linux/init.h>
95ed644f 40#include <linux/mutex.h>
b2cbae2c 41#include <rdma/rdma_netlink.h>
1da177e4
LT
42
43#include "core_priv.h"
44
45MODULE_AUTHOR("Roland Dreier");
46MODULE_DESCRIPTION("core kernel InfiniBand API");
47MODULE_LICENSE("Dual BSD/GPL");
48
49struct ib_client_data {
50 struct list_head list;
51 struct ib_client *client;
52 void * data;
53};
54
f0626710
TH
55struct workqueue_struct *ib_wq;
56EXPORT_SYMBOL_GPL(ib_wq);
57
1da177e4
LT
58static LIST_HEAD(device_list);
59static LIST_HEAD(client_list);
60
61/*
95ed644f 62 * device_mutex protects access to both device_list and client_list.
1da177e4
LT
63 * There's no real point to using multiple locks or something fancier
64 * like an rwsem: we always access both lists, and we're always
65 * modifying one list or the other list. In any case this is not a
66 * hot path so there's no point in trying to optimize.
67 */
95ed644f 68static DEFINE_MUTEX(device_mutex);
1da177e4
LT
69
70static int ib_device_check_mandatory(struct ib_device *device)
71{
72#define IB_MANDATORY_FUNC(x) { offsetof(struct ib_device, x), #x }
73 static const struct {
74 size_t offset;
75 char *name;
76 } mandatory_table[] = {
77 IB_MANDATORY_FUNC(query_device),
78 IB_MANDATORY_FUNC(query_port),
79 IB_MANDATORY_FUNC(query_pkey),
80 IB_MANDATORY_FUNC(query_gid),
81 IB_MANDATORY_FUNC(alloc_pd),
82 IB_MANDATORY_FUNC(dealloc_pd),
83 IB_MANDATORY_FUNC(create_ah),
84 IB_MANDATORY_FUNC(destroy_ah),
85 IB_MANDATORY_FUNC(create_qp),
86 IB_MANDATORY_FUNC(modify_qp),
87 IB_MANDATORY_FUNC(destroy_qp),
88 IB_MANDATORY_FUNC(post_send),
89 IB_MANDATORY_FUNC(post_recv),
90 IB_MANDATORY_FUNC(create_cq),
91 IB_MANDATORY_FUNC(destroy_cq),
92 IB_MANDATORY_FUNC(poll_cq),
93 IB_MANDATORY_FUNC(req_notify_cq),
94 IB_MANDATORY_FUNC(get_dma_mr),
7738613e
IW
95 IB_MANDATORY_FUNC(dereg_mr),
96 IB_MANDATORY_FUNC(get_port_immutable)
1da177e4
LT
97 };
98 int i;
99
9a6b090c 100 for (i = 0; i < ARRAY_SIZE(mandatory_table); ++i) {
1da177e4
LT
101 if (!*(void **) ((void *) device + mandatory_table[i].offset)) {
102 printk(KERN_WARNING "Device %s is missing mandatory function %s\n",
103 device->name, mandatory_table[i].name);
104 return -EINVAL;
105 }
106 }
107
108 return 0;
109}
110
111static struct ib_device *__ib_device_get_by_name(const char *name)
112{
113 struct ib_device *device;
114
115 list_for_each_entry(device, &device_list, core_list)
116 if (!strncmp(name, device->name, IB_DEVICE_NAME_MAX))
117 return device;
118
119 return NULL;
120}
121
122
123static int alloc_name(char *name)
124{
65d470b3 125 unsigned long *inuse;
1da177e4
LT
126 char buf[IB_DEVICE_NAME_MAX];
127 struct ib_device *device;
128 int i;
129
65d470b3 130 inuse = (unsigned long *) get_zeroed_page(GFP_KERNEL);
1da177e4
LT
131 if (!inuse)
132 return -ENOMEM;
133
134 list_for_each_entry(device, &device_list, core_list) {
135 if (!sscanf(device->name, name, &i))
136 continue;
137 if (i < 0 || i >= PAGE_SIZE * 8)
138 continue;
139 snprintf(buf, sizeof buf, name, i);
140 if (!strncmp(buf, device->name, IB_DEVICE_NAME_MAX))
141 set_bit(i, inuse);
142 }
143
144 i = find_first_zero_bit(inuse, PAGE_SIZE * 8);
145 free_page((unsigned long) inuse);
146 snprintf(buf, sizeof buf, name, i);
147
148 if (__ib_device_get_by_name(buf))
149 return -ENFILE;
150
151 strlcpy(name, buf, IB_DEVICE_NAME_MAX);
152 return 0;
153}
154
155/**
156 * ib_alloc_device - allocate an IB device struct
157 * @size:size of structure to allocate
158 *
159 * Low-level drivers should use ib_alloc_device() to allocate &struct
160 * ib_device. @size is the size of the structure to be allocated,
161 * including any private data used by the low-level driver.
162 * ib_dealloc_device() must be used to free structures allocated with
163 * ib_alloc_device().
164 */
165struct ib_device *ib_alloc_device(size_t size)
166{
1da177e4
LT
167 BUG_ON(size < sizeof (struct ib_device));
168
de6eb66b 169 return kzalloc(size, GFP_KERNEL);
1da177e4
LT
170}
171EXPORT_SYMBOL(ib_alloc_device);
172
173/**
174 * ib_dealloc_device - free an IB device struct
175 * @device:structure to free
176 *
177 * Free a structure allocated with ib_alloc_device().
178 */
179void ib_dealloc_device(struct ib_device *device)
180{
181 if (device->reg_state == IB_DEV_UNINITIALIZED) {
182 kfree(device);
183 return;
184 }
185
186 BUG_ON(device->reg_state != IB_DEV_UNREGISTERED);
187
9206dff1 188 kobject_put(&device->dev.kobj);
1da177e4
LT
189}
190EXPORT_SYMBOL(ib_dealloc_device);
191
192static int add_client_context(struct ib_device *device, struct ib_client *client)
193{
194 struct ib_client_data *context;
195 unsigned long flags;
196
197 context = kmalloc(sizeof *context, GFP_KERNEL);
198 if (!context) {
199 printk(KERN_WARNING "Couldn't allocate client context for %s/%s\n",
200 device->name, client->name);
201 return -ENOMEM;
202 }
203
204 context->client = client;
205 context->data = NULL;
206
207 spin_lock_irqsave(&device->client_data_lock, flags);
208 list_add(&context->list, &device->client_data_list);
209 spin_unlock_irqrestore(&device->client_data_lock, flags);
210
211 return 0;
212}
213
7738613e 214static int read_port_immutable(struct ib_device *device)
5eb620c8 215{
7738613e
IW
216 int ret = -ENOMEM;
217 u8 start_port = rdma_start_port(device);
218 u8 end_port = rdma_end_port(device);
219 u8 port;
220
221 /**
222 * device->port_immutable is indexed directly by the port number to make
223 * access to this data as efficient as possible.
224 *
225 * Therefore port_immutable is declared as a 1 based array with
226 * potential empty slots at the beginning.
227 */
228 device->port_immutable = kzalloc(sizeof(*device->port_immutable)
229 * (end_port + 1),
230 GFP_KERNEL);
231 if (!device->port_immutable)
5eb620c8
YE
232 goto err;
233
7738613e
IW
234 for (port = start_port; port <= end_port; ++port) {
235 ret = device->get_port_immutable(device, port,
236 &device->port_immutable[port]);
5eb620c8
YE
237 if (ret)
238 goto err;
5eb620c8
YE
239 }
240
241 ret = 0;
242 goto out;
5eb620c8 243err:
7738613e 244 kfree(device->port_immutable);
5eb620c8 245out:
5eb620c8
YE
246 return ret;
247}
248
1da177e4
LT
249/**
250 * ib_register_device - Register an IB device with IB core
251 * @device:Device to register
252 *
253 * Low-level drivers use ib_register_device() to register their
254 * devices with the IB core. All registered clients will receive a
255 * callback for each device that is added. @device must be allocated
256 * with ib_alloc_device().
257 */
9a6edb60
RC
258int ib_register_device(struct ib_device *device,
259 int (*port_callback)(struct ib_device *,
260 u8, struct kobject *))
1da177e4
LT
261{
262 int ret;
263
95ed644f 264 mutex_lock(&device_mutex);
1da177e4
LT
265
266 if (strchr(device->name, '%')) {
267 ret = alloc_name(device->name);
268 if (ret)
269 goto out;
270 }
271
272 if (ib_device_check_mandatory(device)) {
273 ret = -EINVAL;
274 goto out;
275 }
276
277 INIT_LIST_HEAD(&device->event_handler_list);
278 INIT_LIST_HEAD(&device->client_data_list);
279 spin_lock_init(&device->event_handler_lock);
280 spin_lock_init(&device->client_data_lock);
281
7738613e 282 ret = read_port_immutable(device);
5eb620c8 283 if (ret) {
7738613e 284 printk(KERN_WARNING "Couldn't create per port immutable data %s\n",
5eb620c8
YE
285 device->name);
286 goto out;
287 }
288
9a6edb60 289 ret = ib_device_register_sysfs(device, port_callback);
1da177e4
LT
290 if (ret) {
291 printk(KERN_WARNING "Couldn't register device %s with driver model\n",
292 device->name);
7738613e 293 kfree(device->port_immutable);
1da177e4
LT
294 goto out;
295 }
296
297 list_add_tail(&device->core_list, &device_list);
298
299 device->reg_state = IB_DEV_REGISTERED;
300
301 {
302 struct ib_client *client;
303
304 list_for_each_entry(client, &client_list, list)
305 if (client->add && !add_client_context(device, client))
306 client->add(device);
307 }
308
309 out:
95ed644f 310 mutex_unlock(&device_mutex);
1da177e4
LT
311 return ret;
312}
313EXPORT_SYMBOL(ib_register_device);
314
315/**
316 * ib_unregister_device - Unregister an IB device
317 * @device:Device to unregister
318 *
319 * Unregister an IB device. All clients will receive a remove callback.
320 */
321void ib_unregister_device(struct ib_device *device)
322{
323 struct ib_client *client;
324 struct ib_client_data *context, *tmp;
325 unsigned long flags;
326
95ed644f 327 mutex_lock(&device_mutex);
1da177e4
LT
328
329 list_for_each_entry_reverse(client, &client_list, list)
330 if (client->remove)
331 client->remove(device);
332
333 list_del(&device->core_list);
334
95ed644f 335 mutex_unlock(&device_mutex);
1da177e4 336
9206dff1
RD
337 ib_device_unregister_sysfs(device);
338
1da177e4
LT
339 spin_lock_irqsave(&device->client_data_lock, flags);
340 list_for_each_entry_safe(context, tmp, &device->client_data_list, list)
341 kfree(context);
342 spin_unlock_irqrestore(&device->client_data_lock, flags);
343
344 device->reg_state = IB_DEV_UNREGISTERED;
345}
346EXPORT_SYMBOL(ib_unregister_device);
347
348/**
349 * ib_register_client - Register an IB client
350 * @client:Client to register
351 *
352 * Upper level users of the IB drivers can use ib_register_client() to
353 * register callbacks for IB device addition and removal. When an IB
354 * device is added, each registered client's add method will be called
355 * (in the order the clients were registered), and when a device is
356 * removed, each client's remove method will be called (in the reverse
357 * order that clients were registered). In addition, when
358 * ib_register_client() is called, the client will receive an add
359 * callback for all devices already registered.
360 */
361int ib_register_client(struct ib_client *client)
362{
363 struct ib_device *device;
364
95ed644f 365 mutex_lock(&device_mutex);
1da177e4
LT
366
367 list_add_tail(&client->list, &client_list);
368 list_for_each_entry(device, &device_list, core_list)
369 if (client->add && !add_client_context(device, client))
370 client->add(device);
371
95ed644f 372 mutex_unlock(&device_mutex);
1da177e4
LT
373
374 return 0;
375}
376EXPORT_SYMBOL(ib_register_client);
377
378/**
379 * ib_unregister_client - Unregister an IB client
380 * @client:Client to unregister
381 *
382 * Upper level users use ib_unregister_client() to remove their client
383 * registration. When ib_unregister_client() is called, the client
384 * will receive a remove callback for each IB device still registered.
385 */
386void ib_unregister_client(struct ib_client *client)
387{
388 struct ib_client_data *context, *tmp;
389 struct ib_device *device;
390 unsigned long flags;
391
95ed644f 392 mutex_lock(&device_mutex);
1da177e4
LT
393
394 list_for_each_entry(device, &device_list, core_list) {
395 if (client->remove)
396 client->remove(device);
397
398 spin_lock_irqsave(&device->client_data_lock, flags);
399 list_for_each_entry_safe(context, tmp, &device->client_data_list, list)
400 if (context->client == client) {
401 list_del(&context->list);
402 kfree(context);
403 }
404 spin_unlock_irqrestore(&device->client_data_lock, flags);
405 }
406 list_del(&client->list);
407
95ed644f 408 mutex_unlock(&device_mutex);
1da177e4
LT
409}
410EXPORT_SYMBOL(ib_unregister_client);
411
412/**
413 * ib_get_client_data - Get IB client context
414 * @device:Device to get context for
415 * @client:Client to get context for
416 *
417 * ib_get_client_data() returns client context set with
418 * ib_set_client_data().
419 */
420void *ib_get_client_data(struct ib_device *device, struct ib_client *client)
421{
422 struct ib_client_data *context;
423 void *ret = NULL;
424 unsigned long flags;
425
426 spin_lock_irqsave(&device->client_data_lock, flags);
427 list_for_each_entry(context, &device->client_data_list, list)
428 if (context->client == client) {
429 ret = context->data;
430 break;
431 }
432 spin_unlock_irqrestore(&device->client_data_lock, flags);
433
434 return ret;
435}
436EXPORT_SYMBOL(ib_get_client_data);
437
438/**
9cd330d3 439 * ib_set_client_data - Set IB client context
1da177e4
LT
440 * @device:Device to set context for
441 * @client:Client to set context for
442 * @data:Context to set
443 *
444 * ib_set_client_data() sets client context that can be retrieved with
445 * ib_get_client_data().
446 */
447void ib_set_client_data(struct ib_device *device, struct ib_client *client,
448 void *data)
449{
450 struct ib_client_data *context;
451 unsigned long flags;
452
453 spin_lock_irqsave(&device->client_data_lock, flags);
454 list_for_each_entry(context, &device->client_data_list, list)
455 if (context->client == client) {
456 context->data = data;
457 goto out;
458 }
459
460 printk(KERN_WARNING "No client context found for %s/%s\n",
461 device->name, client->name);
462
463out:
464 spin_unlock_irqrestore(&device->client_data_lock, flags);
465}
466EXPORT_SYMBOL(ib_set_client_data);
467
468/**
469 * ib_register_event_handler - Register an IB event handler
470 * @event_handler:Handler to register
471 *
472 * ib_register_event_handler() registers an event handler that will be
473 * called back when asynchronous IB events occur (as defined in
474 * chapter 11 of the InfiniBand Architecture Specification). This
475 * callback may occur in interrupt context.
476 */
477int ib_register_event_handler (struct ib_event_handler *event_handler)
478{
479 unsigned long flags;
480
481 spin_lock_irqsave(&event_handler->device->event_handler_lock, flags);
482 list_add_tail(&event_handler->list,
483 &event_handler->device->event_handler_list);
484 spin_unlock_irqrestore(&event_handler->device->event_handler_lock, flags);
485
486 return 0;
487}
488EXPORT_SYMBOL(ib_register_event_handler);
489
490/**
491 * ib_unregister_event_handler - Unregister an event handler
492 * @event_handler:Handler to unregister
493 *
494 * Unregister an event handler registered with
495 * ib_register_event_handler().
496 */
497int ib_unregister_event_handler(struct ib_event_handler *event_handler)
498{
499 unsigned long flags;
500
501 spin_lock_irqsave(&event_handler->device->event_handler_lock, flags);
502 list_del(&event_handler->list);
503 spin_unlock_irqrestore(&event_handler->device->event_handler_lock, flags);
504
505 return 0;
506}
507EXPORT_SYMBOL(ib_unregister_event_handler);
508
509/**
510 * ib_dispatch_event - Dispatch an asynchronous event
511 * @event:Event to dispatch
512 *
513 * Low-level drivers must call ib_dispatch_event() to dispatch the
514 * event to all registered event handlers when an asynchronous event
515 * occurs.
516 */
517void ib_dispatch_event(struct ib_event *event)
518{
519 unsigned long flags;
520 struct ib_event_handler *handler;
521
522 spin_lock_irqsave(&event->device->event_handler_lock, flags);
523
524 list_for_each_entry(handler, &event->device->event_handler_list, list)
525 handler->handler(handler, event);
526
527 spin_unlock_irqrestore(&event->device->event_handler_lock, flags);
528}
529EXPORT_SYMBOL(ib_dispatch_event);
530
531/**
532 * ib_query_device - Query IB device attributes
533 * @device:Device to query
534 * @device_attr:Device attributes
535 *
536 * ib_query_device() returns the attributes of a device through the
537 * @device_attr pointer.
538 */
539int ib_query_device(struct ib_device *device,
540 struct ib_device_attr *device_attr)
541{
2528e33e
MB
542 struct ib_udata uhw = {.outlen = 0, .inlen = 0};
543
24306dc6
MB
544 memset(device_attr, 0, sizeof(*device_attr));
545
2528e33e 546 return device->query_device(device, device_attr, &uhw);
1da177e4
LT
547}
548EXPORT_SYMBOL(ib_query_device);
549
550/**
551 * ib_query_port - Query IB port attributes
552 * @device:Device to query
553 * @port_num:Port number to query
554 * @port_attr:Port attributes
555 *
556 * ib_query_port() returns the attributes of a port through the
557 * @port_attr pointer.
558 */
559int ib_query_port(struct ib_device *device,
560 u8 port_num,
561 struct ib_port_attr *port_attr)
562{
0cf18d77 563 if (port_num < rdma_start_port(device) || port_num > rdma_end_port(device))
116c0074
RD
564 return -EINVAL;
565
1da177e4
LT
566 return device->query_port(device, port_num, port_attr);
567}
568EXPORT_SYMBOL(ib_query_port);
569
570/**
571 * ib_query_gid - Get GID table entry
572 * @device:Device to query
573 * @port_num:Port number to query
574 * @index:GID table index to query
575 * @gid:Returned GID
576 *
577 * ib_query_gid() fetches the specified GID table entry.
578 */
579int ib_query_gid(struct ib_device *device,
580 u8 port_num, int index, union ib_gid *gid)
581{
582 return device->query_gid(device, port_num, index, gid);
583}
584EXPORT_SYMBOL(ib_query_gid);
585
586/**
587 * ib_query_pkey - Get P_Key table entry
588 * @device:Device to query
589 * @port_num:Port number to query
590 * @index:P_Key table index to query
591 * @pkey:Returned P_Key
592 *
593 * ib_query_pkey() fetches the specified P_Key table entry.
594 */
595int ib_query_pkey(struct ib_device *device,
596 u8 port_num, u16 index, u16 *pkey)
597{
598 return device->query_pkey(device, port_num, index, pkey);
599}
600EXPORT_SYMBOL(ib_query_pkey);
601
602/**
603 * ib_modify_device - Change IB device attributes
604 * @device:Device to modify
605 * @device_modify_mask:Mask of attributes to change
606 * @device_modify:New attribute values
607 *
608 * ib_modify_device() changes a device's attributes as specified by
609 * the @device_modify_mask and @device_modify structure.
610 */
611int ib_modify_device(struct ib_device *device,
612 int device_modify_mask,
613 struct ib_device_modify *device_modify)
614{
10e1b54b
BVA
615 if (!device->modify_device)
616 return -ENOSYS;
617
1da177e4
LT
618 return device->modify_device(device, device_modify_mask,
619 device_modify);
620}
621EXPORT_SYMBOL(ib_modify_device);
622
623/**
624 * ib_modify_port - Modifies the attributes for the specified port.
625 * @device: The device to modify.
626 * @port_num: The number of the port to modify.
627 * @port_modify_mask: Mask used to specify which attributes of the port
628 * to change.
629 * @port_modify: New attribute values for the port.
630 *
631 * ib_modify_port() changes a port's attributes as specified by the
632 * @port_modify_mask and @port_modify structure.
633 */
634int ib_modify_port(struct ib_device *device,
635 u8 port_num, int port_modify_mask,
636 struct ib_port_modify *port_modify)
637{
10e1b54b
BVA
638 if (!device->modify_port)
639 return -ENOSYS;
640
0cf18d77 641 if (port_num < rdma_start_port(device) || port_num > rdma_end_port(device))
116c0074
RD
642 return -EINVAL;
643
1da177e4
LT
644 return device->modify_port(device, port_num, port_modify_mask,
645 port_modify);
646}
647EXPORT_SYMBOL(ib_modify_port);
648
5eb620c8
YE
649/**
650 * ib_find_gid - Returns the port number and GID table index where
651 * a specified GID value occurs.
652 * @device: The device to query.
653 * @gid: The GID value to search for.
654 * @port_num: The port number of the device where the GID value was found.
655 * @index: The index into the GID table where the GID was found. This
656 * parameter may be NULL.
657 */
658int ib_find_gid(struct ib_device *device, union ib_gid *gid,
659 u8 *port_num, u16 *index)
660{
661 union ib_gid tmp_gid;
662 int ret, port, i;
663
0cf18d77 664 for (port = rdma_start_port(device); port <= rdma_end_port(device); ++port) {
7738613e 665 for (i = 0; i < device->port_immutable[port].gid_tbl_len; ++i) {
5eb620c8
YE
666 ret = ib_query_gid(device, port, i, &tmp_gid);
667 if (ret)
668 return ret;
669 if (!memcmp(&tmp_gid, gid, sizeof *gid)) {
670 *port_num = port;
671 if (index)
672 *index = i;
673 return 0;
674 }
675 }
676 }
677
678 return -ENOENT;
679}
680EXPORT_SYMBOL(ib_find_gid);
681
682/**
683 * ib_find_pkey - Returns the PKey table index where a specified
684 * PKey value occurs.
685 * @device: The device to query.
686 * @port_num: The port number of the device to search for the PKey.
687 * @pkey: The PKey value to search for.
688 * @index: The index into the PKey table where the PKey was found.
689 */
690int ib_find_pkey(struct ib_device *device,
691 u8 port_num, u16 pkey, u16 *index)
692{
693 int ret, i;
694 u16 tmp_pkey;
ff7166c4 695 int partial_ix = -1;
5eb620c8 696
7738613e 697 for (i = 0; i < device->port_immutable[port_num].pkey_tbl_len; ++i) {
5eb620c8
YE
698 ret = ib_query_pkey(device, port_num, i, &tmp_pkey);
699 if (ret)
700 return ret;
36026ecc 701 if ((pkey & 0x7fff) == (tmp_pkey & 0x7fff)) {
ff7166c4
JM
702 /* if there is full-member pkey take it.*/
703 if (tmp_pkey & 0x8000) {
704 *index = i;
705 return 0;
706 }
707 if (partial_ix < 0)
708 partial_ix = i;
5eb620c8
YE
709 }
710 }
711
ff7166c4
JM
712 /*no full-member, if exists take the limited*/
713 if (partial_ix >= 0) {
714 *index = partial_ix;
715 return 0;
716 }
5eb620c8
YE
717 return -ENOENT;
718}
719EXPORT_SYMBOL(ib_find_pkey);
720
1da177e4
LT
721static int __init ib_core_init(void)
722{
723 int ret;
724
f0626710
TH
725 ib_wq = alloc_workqueue("infiniband", 0, 0);
726 if (!ib_wq)
727 return -ENOMEM;
728
1da177e4 729 ret = ib_sysfs_setup();
fd75c789 730 if (ret) {
1da177e4 731 printk(KERN_WARNING "Couldn't create InfiniBand device class\n");
fd75c789
NM
732 goto err;
733 }
1da177e4 734
b2cbae2c
RD
735 ret = ibnl_init();
736 if (ret) {
737 printk(KERN_WARNING "Couldn't init IB netlink interface\n");
738 goto err_sysfs;
739 }
740
1da177e4
LT
741 ret = ib_cache_setup();
742 if (ret) {
743 printk(KERN_WARNING "Couldn't set up InfiniBand P_Key/GID cache\n");
b2cbae2c 744 goto err_nl;
1da177e4
LT
745 }
746
fd75c789
NM
747 return 0;
748
b2cbae2c
RD
749err_nl:
750 ibnl_cleanup();
751
fd75c789
NM
752err_sysfs:
753 ib_sysfs_cleanup();
754
755err:
756 destroy_workqueue(ib_wq);
1da177e4
LT
757 return ret;
758}
759
760static void __exit ib_core_cleanup(void)
761{
762 ib_cache_cleanup();
b2cbae2c 763 ibnl_cleanup();
1da177e4 764 ib_sysfs_cleanup();
f7c6a7b5 765 /* Make sure that any pending umem accounting work is done. */
f0626710 766 destroy_workqueue(ib_wq);
1da177e4
LT
767}
768
769module_init(ib_core_init);
770module_exit(ib_core_cleanup);
This page took 0.991124 seconds and 5 git commands to generate.