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