2 * Copyright (c) 2004 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Voltaire, Inc. All rights reserved.
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:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
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.
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
33 * $Id: sa_query.c 2811 2005-07-06 18:11:43Z halr $
36 #include <linux/module.h>
37 #include <linux/init.h>
38 #include <linux/err.h>
39 #include <linux/random.h>
40 #include <linux/spinlock.h>
41 #include <linux/slab.h>
42 #include <linux/pci.h>
43 #include <linux/dma-mapping.h>
44 #include <linux/kref.h>
45 #include <linux/idr.h>
46 #include <linux/workqueue.h>
48 #include <rdma/ib_pack.h>
49 #include <rdma/ib_sa.h>
51 MODULE_AUTHOR("Roland Dreier");
52 MODULE_DESCRIPTION("InfiniBand subnet administration query support");
53 MODULE_LICENSE("Dual BSD/GPL");
61 struct ib_mad_agent *agent;
62 struct ib_sa_sm_ah *sm_ah;
63 struct work_struct update_task;
69 int start_port, end_port;
70 struct ib_event_handler event_handler;
71 struct ib_sa_port port[0];
75 void (*callback)(struct ib_sa_query *, int, struct ib_sa_mad *);
76 void (*release)(struct ib_sa_query *);
77 struct ib_sa_port *port;
78 struct ib_mad_send_buf *mad_buf;
79 struct ib_sa_sm_ah *sm_ah;
83 struct ib_sa_service_query {
84 void (*callback)(int, struct ib_sa_service_rec *, void *);
86 struct ib_sa_query sa_query;
89 struct ib_sa_path_query {
90 void (*callback)(int, struct ib_sa_path_rec *, void *);
92 struct ib_sa_query sa_query;
95 struct ib_sa_mcmember_query {
96 void (*callback)(int, struct ib_sa_mcmember_rec *, void *);
98 struct ib_sa_query sa_query;
101 static void ib_sa_add_one(struct ib_device *device);
102 static void ib_sa_remove_one(struct ib_device *device);
104 static struct ib_client sa_client = {
106 .add = ib_sa_add_one,
107 .remove = ib_sa_remove_one
110 static spinlock_t idr_lock;
111 static DEFINE_IDR(query_idr);
113 static spinlock_t tid_lock;
116 #define PATH_REC_FIELD(field) \
117 .struct_offset_bytes = offsetof(struct ib_sa_path_rec, field), \
118 .struct_size_bytes = sizeof ((struct ib_sa_path_rec *) 0)->field, \
119 .field_name = "sa_path_rec:" #field
121 static const struct ib_field path_rec_table[] = {
130 { PATH_REC_FIELD(dgid),
134 { PATH_REC_FIELD(sgid),
138 { PATH_REC_FIELD(dlid),
142 { PATH_REC_FIELD(slid),
146 { PATH_REC_FIELD(raw_traffic),
154 { PATH_REC_FIELD(flow_label),
158 { PATH_REC_FIELD(hop_limit),
162 { PATH_REC_FIELD(traffic_class),
166 { PATH_REC_FIELD(reversible),
170 { PATH_REC_FIELD(numb_path),
174 { PATH_REC_FIELD(pkey),
182 { PATH_REC_FIELD(sl),
186 { PATH_REC_FIELD(mtu_selector),
190 { PATH_REC_FIELD(mtu),
194 { PATH_REC_FIELD(rate_selector),
198 { PATH_REC_FIELD(rate),
202 { PATH_REC_FIELD(packet_life_time_selector),
206 { PATH_REC_FIELD(packet_life_time),
210 { PATH_REC_FIELD(preference),
220 #define MCMEMBER_REC_FIELD(field) \
221 .struct_offset_bytes = offsetof(struct ib_sa_mcmember_rec, field), \
222 .struct_size_bytes = sizeof ((struct ib_sa_mcmember_rec *) 0)->field, \
223 .field_name = "sa_mcmember_rec:" #field
225 static const struct ib_field mcmember_rec_table[] = {
226 { MCMEMBER_REC_FIELD(mgid),
230 { MCMEMBER_REC_FIELD(port_gid),
234 { MCMEMBER_REC_FIELD(qkey),
238 { MCMEMBER_REC_FIELD(mlid),
242 { MCMEMBER_REC_FIELD(mtu_selector),
246 { MCMEMBER_REC_FIELD(mtu),
250 { MCMEMBER_REC_FIELD(traffic_class),
254 { MCMEMBER_REC_FIELD(pkey),
258 { MCMEMBER_REC_FIELD(rate_selector),
262 { MCMEMBER_REC_FIELD(rate),
266 { MCMEMBER_REC_FIELD(packet_life_time_selector),
270 { MCMEMBER_REC_FIELD(packet_life_time),
274 { MCMEMBER_REC_FIELD(sl),
278 { MCMEMBER_REC_FIELD(flow_label),
282 { MCMEMBER_REC_FIELD(hop_limit),
286 { MCMEMBER_REC_FIELD(scope),
290 { MCMEMBER_REC_FIELD(join_state),
294 { MCMEMBER_REC_FIELD(proxy_join),
304 #define SERVICE_REC_FIELD(field) \
305 .struct_offset_bytes = offsetof(struct ib_sa_service_rec, field), \
306 .struct_size_bytes = sizeof ((struct ib_sa_service_rec *) 0)->field, \
307 .field_name = "sa_service_rec:" #field
309 static const struct ib_field service_rec_table[] = {
310 { SERVICE_REC_FIELD(id),
314 { SERVICE_REC_FIELD(gid),
318 { SERVICE_REC_FIELD(pkey),
322 { SERVICE_REC_FIELD(lease),
326 { SERVICE_REC_FIELD(key),
330 { SERVICE_REC_FIELD(name),
334 { SERVICE_REC_FIELD(data8),
338 { SERVICE_REC_FIELD(data16),
342 { SERVICE_REC_FIELD(data32),
346 { SERVICE_REC_FIELD(data64),
352 static void free_sm_ah(struct kref *kref)
354 struct ib_sa_sm_ah *sm_ah = container_of(kref, struct ib_sa_sm_ah, ref);
356 ib_destroy_ah(sm_ah->ah);
360 static void update_sm_ah(void *port_ptr)
362 struct ib_sa_port *port = port_ptr;
363 struct ib_sa_sm_ah *new_ah, *old_ah;
364 struct ib_port_attr port_attr;
365 struct ib_ah_attr ah_attr;
367 if (ib_query_port(port->agent->device, port->port_num, &port_attr)) {
368 printk(KERN_WARNING "Couldn't query port\n");
372 new_ah = kmalloc(sizeof *new_ah, GFP_KERNEL);
374 printk(KERN_WARNING "Couldn't allocate new SM AH\n");
378 kref_init(&new_ah->ref);
380 memset(&ah_attr, 0, sizeof ah_attr);
381 ah_attr.dlid = port_attr.sm_lid;
382 ah_attr.sl = port_attr.sm_sl;
383 ah_attr.port_num = port->port_num;
385 new_ah->ah = ib_create_ah(port->agent->qp->pd, &ah_attr);
386 if (IS_ERR(new_ah->ah)) {
387 printk(KERN_WARNING "Couldn't create new SM AH\n");
392 spin_lock_irq(&port->ah_lock);
393 old_ah = port->sm_ah;
394 port->sm_ah = new_ah;
395 spin_unlock_irq(&port->ah_lock);
398 kref_put(&old_ah->ref, free_sm_ah);
401 static void ib_sa_event(struct ib_event_handler *handler, struct ib_event *event)
403 if (event->event == IB_EVENT_PORT_ERR ||
404 event->event == IB_EVENT_PORT_ACTIVE ||
405 event->event == IB_EVENT_LID_CHANGE ||
406 event->event == IB_EVENT_PKEY_CHANGE ||
407 event->event == IB_EVENT_SM_CHANGE) {
408 struct ib_sa_device *sa_dev;
409 sa_dev = container_of(handler, typeof(*sa_dev), event_handler);
411 schedule_work(&sa_dev->port[event->element.port_num -
412 sa_dev->start_port].update_task);
417 * ib_sa_cancel_query - try to cancel an SA query
418 * @id:ID of query to cancel
419 * @query:query pointer to cancel
421 * Try to cancel an SA query. If the id and query don't match up or
422 * the query has already completed, nothing is done. Otherwise the
423 * query is canceled and will complete with a status of -EINTR.
425 void ib_sa_cancel_query(int id, struct ib_sa_query *query)
428 struct ib_mad_agent *agent;
429 struct ib_mad_send_buf *mad_buf;
431 spin_lock_irqsave(&idr_lock, flags);
432 if (idr_find(&query_idr, id) != query) {
433 spin_unlock_irqrestore(&idr_lock, flags);
436 agent = query->port->agent;
437 mad_buf = query->mad_buf;
438 spin_unlock_irqrestore(&idr_lock, flags);
440 ib_cancel_mad(agent, mad_buf);
442 EXPORT_SYMBOL(ib_sa_cancel_query);
444 static void init_mad(struct ib_sa_mad *mad, struct ib_mad_agent *agent)
448 memset(mad, 0, sizeof *mad);
450 mad->mad_hdr.base_version = IB_MGMT_BASE_VERSION;
451 mad->mad_hdr.mgmt_class = IB_MGMT_CLASS_SUBN_ADM;
452 mad->mad_hdr.class_version = IB_SA_CLASS_VERSION;
454 spin_lock_irqsave(&tid_lock, flags);
456 cpu_to_be64(((u64) agent->hi_tid) << 32 | tid++);
457 spin_unlock_irqrestore(&tid_lock, flags);
460 static int send_mad(struct ib_sa_query *query, int timeout_ms)
466 if (!idr_pre_get(&query_idr, GFP_ATOMIC))
468 spin_lock_irqsave(&idr_lock, flags);
469 ret = idr_get_new(&query_idr, query, &id);
470 spin_unlock_irqrestore(&idr_lock, flags);
476 query->mad_buf->timeout_ms = timeout_ms;
477 query->mad_buf->context[0] = query;
480 spin_lock_irqsave(&query->port->ah_lock, flags);
481 kref_get(&query->port->sm_ah->ref);
482 query->sm_ah = query->port->sm_ah;
483 spin_unlock_irqrestore(&query->port->ah_lock, flags);
485 query->mad_buf->ah = query->sm_ah->ah;
487 ret = ib_post_send_mad(query->mad_buf, NULL);
489 spin_lock_irqsave(&idr_lock, flags);
490 idr_remove(&query_idr, id);
491 spin_unlock_irqrestore(&idr_lock, flags);
493 kref_put(&query->sm_ah->ref, free_sm_ah);
497 * It's not safe to dereference query any more, because the
498 * send may already have completed and freed the query in
501 return ret ? ret : id;
504 static void ib_sa_path_rec_callback(struct ib_sa_query *sa_query,
506 struct ib_sa_mad *mad)
508 struct ib_sa_path_query *query =
509 container_of(sa_query, struct ib_sa_path_query, sa_query);
512 struct ib_sa_path_rec rec;
514 ib_unpack(path_rec_table, ARRAY_SIZE(path_rec_table),
516 query->callback(status, &rec, query->context);
518 query->callback(status, NULL, query->context);
521 static void ib_sa_path_rec_release(struct ib_sa_query *sa_query)
523 kfree(container_of(sa_query, struct ib_sa_path_query, sa_query));
527 * ib_sa_path_rec_get - Start a Path get query
528 * @device:device to send query on
529 * @port_num: port number to send query on
530 * @rec:Path Record to send in query
531 * @comp_mask:component mask to send in query
532 * @timeout_ms:time to wait for response
533 * @gfp_mask:GFP mask to use for internal allocations
534 * @callback:function called when query completes, times out or is
536 * @context:opaque user context passed to callback
537 * @sa_query:query context, used to cancel query
539 * Send a Path Record Get query to the SA to look up a path. The
540 * callback function will be called when the query completes (or
541 * fails); status is 0 for a successful response, -EINTR if the query
542 * is canceled, -ETIMEDOUT is the query timed out, or -EIO if an error
543 * occurred sending the query. The resp parameter of the callback is
544 * only valid if status is 0.
546 * If the return value of ib_sa_path_rec_get() is negative, it is an
547 * error code. Otherwise it is a query ID that can be used to cancel
550 int ib_sa_path_rec_get(struct ib_device *device, u8 port_num,
551 struct ib_sa_path_rec *rec,
552 ib_sa_comp_mask comp_mask,
553 int timeout_ms, gfp_t gfp_mask,
554 void (*callback)(int status,
555 struct ib_sa_path_rec *resp,
558 struct ib_sa_query **sa_query)
560 struct ib_sa_path_query *query;
561 struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client);
562 struct ib_sa_port *port;
563 struct ib_mad_agent *agent;
564 struct ib_sa_mad *mad;
570 port = &sa_dev->port[port_num - sa_dev->start_port];
573 query = kmalloc(sizeof *query, gfp_mask);
577 query->sa_query.mad_buf = ib_create_send_mad(agent, 1, 0,
579 IB_MGMT_SA_DATA, gfp_mask);
580 if (!query->sa_query.mad_buf) {
585 query->callback = callback;
586 query->context = context;
588 mad = query->sa_query.mad_buf->mad;
589 init_mad(mad, agent);
591 query->sa_query.callback = callback ? ib_sa_path_rec_callback : NULL;
592 query->sa_query.release = ib_sa_path_rec_release;
593 query->sa_query.port = port;
594 mad->mad_hdr.method = IB_MGMT_METHOD_GET;
595 mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_PATH_REC);
596 mad->sa_hdr.comp_mask = comp_mask;
598 ib_pack(path_rec_table, ARRAY_SIZE(path_rec_table), rec, mad->data);
600 *sa_query = &query->sa_query;
602 ret = send_mad(&query->sa_query, timeout_ms);
610 ib_free_send_mad(query->sa_query.mad_buf);
616 EXPORT_SYMBOL(ib_sa_path_rec_get);
618 static void ib_sa_service_rec_callback(struct ib_sa_query *sa_query,
620 struct ib_sa_mad *mad)
622 struct ib_sa_service_query *query =
623 container_of(sa_query, struct ib_sa_service_query, sa_query);
626 struct ib_sa_service_rec rec;
628 ib_unpack(service_rec_table, ARRAY_SIZE(service_rec_table),
630 query->callback(status, &rec, query->context);
632 query->callback(status, NULL, query->context);
635 static void ib_sa_service_rec_release(struct ib_sa_query *sa_query)
637 kfree(container_of(sa_query, struct ib_sa_service_query, sa_query));
641 * ib_sa_service_rec_query - Start Service Record operation
642 * @device:device to send request on
643 * @port_num: port number to send request on
644 * @method:SA method - should be get, set, or delete
645 * @rec:Service Record to send in request
646 * @comp_mask:component mask to send in request
647 * @timeout_ms:time to wait for response
648 * @gfp_mask:GFP mask to use for internal allocations
649 * @callback:function called when request completes, times out or is
651 * @context:opaque user context passed to callback
652 * @sa_query:request context, used to cancel request
654 * Send a Service Record set/get/delete to the SA to register,
655 * unregister or query a service record.
656 * The callback function will be called when the request completes (or
657 * fails); status is 0 for a successful response, -EINTR if the query
658 * is canceled, -ETIMEDOUT is the query timed out, or -EIO if an error
659 * occurred sending the query. The resp parameter of the callback is
660 * only valid if status is 0.
662 * If the return value of ib_sa_service_rec_query() is negative, it is an
663 * error code. Otherwise it is a request ID that can be used to cancel
666 int ib_sa_service_rec_query(struct ib_device *device, u8 port_num, u8 method,
667 struct ib_sa_service_rec *rec,
668 ib_sa_comp_mask comp_mask,
669 int timeout_ms, gfp_t gfp_mask,
670 void (*callback)(int status,
671 struct ib_sa_service_rec *resp,
674 struct ib_sa_query **sa_query)
676 struct ib_sa_service_query *query;
677 struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client);
678 struct ib_sa_port *port;
679 struct ib_mad_agent *agent;
680 struct ib_sa_mad *mad;
686 port = &sa_dev->port[port_num - sa_dev->start_port];
689 if (method != IB_MGMT_METHOD_GET &&
690 method != IB_MGMT_METHOD_SET &&
691 method != IB_SA_METHOD_DELETE)
694 query = kmalloc(sizeof *query, gfp_mask);
698 query->sa_query.mad_buf = ib_create_send_mad(agent, 1, 0,
700 IB_MGMT_SA_DATA, gfp_mask);
701 if (!query->sa_query.mad_buf) {
706 query->callback = callback;
707 query->context = context;
709 mad = query->sa_query.mad_buf->mad;
710 init_mad(mad, agent);
712 query->sa_query.callback = callback ? ib_sa_service_rec_callback : NULL;
713 query->sa_query.release = ib_sa_service_rec_release;
714 query->sa_query.port = port;
715 mad->mad_hdr.method = method;
716 mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_SERVICE_REC);
717 mad->sa_hdr.comp_mask = comp_mask;
719 ib_pack(service_rec_table, ARRAY_SIZE(service_rec_table),
722 *sa_query = &query->sa_query;
724 ret = send_mad(&query->sa_query, timeout_ms);
732 ib_free_send_mad(query->sa_query.mad_buf);
738 EXPORT_SYMBOL(ib_sa_service_rec_query);
740 static void ib_sa_mcmember_rec_callback(struct ib_sa_query *sa_query,
742 struct ib_sa_mad *mad)
744 struct ib_sa_mcmember_query *query =
745 container_of(sa_query, struct ib_sa_mcmember_query, sa_query);
748 struct ib_sa_mcmember_rec rec;
750 ib_unpack(mcmember_rec_table, ARRAY_SIZE(mcmember_rec_table),
752 query->callback(status, &rec, query->context);
754 query->callback(status, NULL, query->context);
757 static void ib_sa_mcmember_rec_release(struct ib_sa_query *sa_query)
759 kfree(container_of(sa_query, struct ib_sa_mcmember_query, sa_query));
762 int ib_sa_mcmember_rec_query(struct ib_device *device, u8 port_num,
764 struct ib_sa_mcmember_rec *rec,
765 ib_sa_comp_mask comp_mask,
766 int timeout_ms, gfp_t gfp_mask,
767 void (*callback)(int status,
768 struct ib_sa_mcmember_rec *resp,
771 struct ib_sa_query **sa_query)
773 struct ib_sa_mcmember_query *query;
774 struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client);
775 struct ib_sa_port *port;
776 struct ib_mad_agent *agent;
777 struct ib_sa_mad *mad;
783 port = &sa_dev->port[port_num - sa_dev->start_port];
786 query = kmalloc(sizeof *query, gfp_mask);
790 query->sa_query.mad_buf = ib_create_send_mad(agent, 1, 0,
792 IB_MGMT_SA_DATA, gfp_mask);
793 if (!query->sa_query.mad_buf) {
798 query->callback = callback;
799 query->context = context;
801 mad = query->sa_query.mad_buf->mad;
802 init_mad(mad, agent);
804 query->sa_query.callback = callback ? ib_sa_mcmember_rec_callback : NULL;
805 query->sa_query.release = ib_sa_mcmember_rec_release;
806 query->sa_query.port = port;
807 mad->mad_hdr.method = method;
808 mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_MC_MEMBER_REC);
809 mad->sa_hdr.comp_mask = comp_mask;
811 ib_pack(mcmember_rec_table, ARRAY_SIZE(mcmember_rec_table),
814 *sa_query = &query->sa_query;
816 ret = send_mad(&query->sa_query, timeout_ms);
824 ib_free_send_mad(query->sa_query.mad_buf);
830 EXPORT_SYMBOL(ib_sa_mcmember_rec_query);
832 static void send_handler(struct ib_mad_agent *agent,
833 struct ib_mad_send_wc *mad_send_wc)
835 struct ib_sa_query *query = mad_send_wc->send_buf->context[0];
839 switch (mad_send_wc->status) {
841 /* No callback -- already got recv */
843 case IB_WC_RESP_TIMEOUT_ERR:
844 query->callback(query, -ETIMEDOUT, NULL);
846 case IB_WC_WR_FLUSH_ERR:
847 query->callback(query, -EINTR, NULL);
850 query->callback(query, -EIO, NULL);
854 spin_lock_irqsave(&idr_lock, flags);
855 idr_remove(&query_idr, query->id);
856 spin_unlock_irqrestore(&idr_lock, flags);
858 ib_free_send_mad(mad_send_wc->send_buf);
859 kref_put(&query->sm_ah->ref, free_sm_ah);
860 query->release(query);
863 static void recv_handler(struct ib_mad_agent *mad_agent,
864 struct ib_mad_recv_wc *mad_recv_wc)
866 struct ib_sa_query *query;
867 struct ib_mad_send_buf *mad_buf;
869 mad_buf = (void *) (unsigned long) mad_recv_wc->wc->wr_id;
870 query = mad_buf->context[0];
872 if (query->callback) {
873 if (mad_recv_wc->wc->status == IB_WC_SUCCESS)
874 query->callback(query,
875 mad_recv_wc->recv_buf.mad->mad_hdr.status ?
877 (struct ib_sa_mad *) mad_recv_wc->recv_buf.mad);
879 query->callback(query, -EIO, NULL);
882 ib_free_recv_mad(mad_recv_wc);
885 static void ib_sa_add_one(struct ib_device *device)
887 struct ib_sa_device *sa_dev;
890 if (device->node_type == IB_NODE_SWITCH)
894 e = device->phys_port_cnt;
897 sa_dev = kmalloc(sizeof *sa_dev +
898 (e - s + 1) * sizeof (struct ib_sa_port),
903 sa_dev->start_port = s;
904 sa_dev->end_port = e;
906 for (i = 0; i <= e - s; ++i) {
907 sa_dev->port[i].sm_ah = NULL;
908 sa_dev->port[i].port_num = i + s;
909 spin_lock_init(&sa_dev->port[i].ah_lock);
911 sa_dev->port[i].agent =
912 ib_register_mad_agent(device, i + s, IB_QPT_GSI,
913 NULL, 0, send_handler,
914 recv_handler, sa_dev);
915 if (IS_ERR(sa_dev->port[i].agent))
918 INIT_WORK(&sa_dev->port[i].update_task,
919 update_sm_ah, &sa_dev->port[i]);
922 ib_set_client_data(device, &sa_client, sa_dev);
925 * We register our event handler after everything is set up,
926 * and then update our cached info after the event handler is
927 * registered to avoid any problems if a port changes state
928 * during our initialization.
931 INIT_IB_EVENT_HANDLER(&sa_dev->event_handler, device, ib_sa_event);
932 if (ib_register_event_handler(&sa_dev->event_handler))
935 for (i = 0; i <= e - s; ++i)
936 update_sm_ah(&sa_dev->port[i]);
942 ib_unregister_mad_agent(sa_dev->port[i].agent);
949 static void ib_sa_remove_one(struct ib_device *device)
951 struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client);
957 ib_unregister_event_handler(&sa_dev->event_handler);
959 flush_scheduled_work();
961 for (i = 0; i <= sa_dev->end_port - sa_dev->start_port; ++i) {
962 ib_unregister_mad_agent(sa_dev->port[i].agent);
963 kref_put(&sa_dev->port[i].sm_ah->ref, free_sm_ah);
969 static int __init ib_sa_init(void)
973 spin_lock_init(&idr_lock);
974 spin_lock_init(&tid_lock);
976 get_random_bytes(&tid, sizeof tid);
978 ret = ib_register_client(&sa_client);
980 printk(KERN_ERR "Couldn't register ib_sa client\n");
985 static void __exit ib_sa_cleanup(void)
987 ib_unregister_client(&sa_client);
988 idr_destroy(&query_idr);
991 module_init(ib_sa_init);
992 module_exit(ib_sa_cleanup);