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>
47 #include <rdma/ib_pack.h>
48 #include <rdma/ib_sa.h>
50 MODULE_AUTHOR("Roland Dreier");
51 MODULE_DESCRIPTION("InfiniBand subnet administration query support");
52 MODULE_LICENSE("Dual BSD/GPL");
60 struct ib_mad_agent *agent;
61 struct ib_sa_sm_ah *sm_ah;
62 struct work_struct update_task;
68 int start_port, end_port;
69 struct ib_event_handler event_handler;
70 struct ib_sa_port port[0];
74 void (*callback)(struct ib_sa_query *, int, struct ib_sa_mad *);
75 void (*release)(struct ib_sa_query *);
76 struct ib_sa_port *port;
77 struct ib_mad_send_buf *mad_buf;
78 struct ib_sa_sm_ah *sm_ah;
82 struct ib_sa_service_query {
83 void (*callback)(int, struct ib_sa_service_rec *, void *);
85 struct ib_sa_query sa_query;
88 struct ib_sa_path_query {
89 void (*callback)(int, struct ib_sa_path_rec *, void *);
91 struct ib_sa_query sa_query;
94 struct ib_sa_mcmember_query {
95 void (*callback)(int, struct ib_sa_mcmember_rec *, void *);
97 struct ib_sa_query sa_query;
100 static void ib_sa_add_one(struct ib_device *device);
101 static void ib_sa_remove_one(struct ib_device *device);
103 static struct ib_client sa_client = {
105 .add = ib_sa_add_one,
106 .remove = ib_sa_remove_one
109 static spinlock_t idr_lock;
110 static DEFINE_IDR(query_idr);
112 static spinlock_t tid_lock;
115 #define PATH_REC_FIELD(field) \
116 .struct_offset_bytes = offsetof(struct ib_sa_path_rec, field), \
117 .struct_size_bytes = sizeof ((struct ib_sa_path_rec *) 0)->field, \
118 .field_name = "sa_path_rec:" #field
120 static const struct ib_field path_rec_table[] = {
129 { PATH_REC_FIELD(dgid),
133 { PATH_REC_FIELD(sgid),
137 { PATH_REC_FIELD(dlid),
141 { PATH_REC_FIELD(slid),
145 { PATH_REC_FIELD(raw_traffic),
153 { PATH_REC_FIELD(flow_label),
157 { PATH_REC_FIELD(hop_limit),
161 { PATH_REC_FIELD(traffic_class),
165 { PATH_REC_FIELD(reversible),
169 { PATH_REC_FIELD(numb_path),
173 { PATH_REC_FIELD(pkey),
181 { PATH_REC_FIELD(sl),
185 { PATH_REC_FIELD(mtu_selector),
189 { PATH_REC_FIELD(mtu),
193 { PATH_REC_FIELD(rate_selector),
197 { PATH_REC_FIELD(rate),
201 { PATH_REC_FIELD(packet_life_time_selector),
205 { PATH_REC_FIELD(packet_life_time),
209 { PATH_REC_FIELD(preference),
219 #define MCMEMBER_REC_FIELD(field) \
220 .struct_offset_bytes = offsetof(struct ib_sa_mcmember_rec, field), \
221 .struct_size_bytes = sizeof ((struct ib_sa_mcmember_rec *) 0)->field, \
222 .field_name = "sa_mcmember_rec:" #field
224 static const struct ib_field mcmember_rec_table[] = {
225 { MCMEMBER_REC_FIELD(mgid),
229 { MCMEMBER_REC_FIELD(port_gid),
233 { MCMEMBER_REC_FIELD(qkey),
237 { MCMEMBER_REC_FIELD(mlid),
241 { MCMEMBER_REC_FIELD(mtu_selector),
245 { MCMEMBER_REC_FIELD(mtu),
249 { MCMEMBER_REC_FIELD(traffic_class),
253 { MCMEMBER_REC_FIELD(pkey),
257 { MCMEMBER_REC_FIELD(rate_selector),
261 { MCMEMBER_REC_FIELD(rate),
265 { MCMEMBER_REC_FIELD(packet_life_time_selector),
269 { MCMEMBER_REC_FIELD(packet_life_time),
273 { MCMEMBER_REC_FIELD(sl),
277 { MCMEMBER_REC_FIELD(flow_label),
281 { MCMEMBER_REC_FIELD(hop_limit),
285 { MCMEMBER_REC_FIELD(scope),
289 { MCMEMBER_REC_FIELD(join_state),
293 { MCMEMBER_REC_FIELD(proxy_join),
303 #define SERVICE_REC_FIELD(field) \
304 .struct_offset_bytes = offsetof(struct ib_sa_service_rec, field), \
305 .struct_size_bytes = sizeof ((struct ib_sa_service_rec *) 0)->field, \
306 .field_name = "sa_service_rec:" #field
308 static const struct ib_field service_rec_table[] = {
309 { SERVICE_REC_FIELD(id),
313 { SERVICE_REC_FIELD(gid),
317 { SERVICE_REC_FIELD(pkey),
321 { SERVICE_REC_FIELD(lease),
325 { SERVICE_REC_FIELD(key),
329 { SERVICE_REC_FIELD(name),
333 { SERVICE_REC_FIELD(data8),
337 { SERVICE_REC_FIELD(data16),
341 { SERVICE_REC_FIELD(data32),
345 { SERVICE_REC_FIELD(data64),
351 static void free_sm_ah(struct kref *kref)
353 struct ib_sa_sm_ah *sm_ah = container_of(kref, struct ib_sa_sm_ah, ref);
355 ib_destroy_ah(sm_ah->ah);
359 static void update_sm_ah(void *port_ptr)
361 struct ib_sa_port *port = port_ptr;
362 struct ib_sa_sm_ah *new_ah, *old_ah;
363 struct ib_port_attr port_attr;
364 struct ib_ah_attr ah_attr;
366 if (ib_query_port(port->agent->device, port->port_num, &port_attr)) {
367 printk(KERN_WARNING "Couldn't query port\n");
371 new_ah = kmalloc(sizeof *new_ah, GFP_KERNEL);
373 printk(KERN_WARNING "Couldn't allocate new SM AH\n");
377 kref_init(&new_ah->ref);
379 memset(&ah_attr, 0, sizeof ah_attr);
380 ah_attr.dlid = port_attr.sm_lid;
381 ah_attr.sl = port_attr.sm_sl;
382 ah_attr.port_num = port->port_num;
384 new_ah->ah = ib_create_ah(port->agent->qp->pd, &ah_attr);
385 if (IS_ERR(new_ah->ah)) {
386 printk(KERN_WARNING "Couldn't create new SM AH\n");
391 spin_lock_irq(&port->ah_lock);
392 old_ah = port->sm_ah;
393 port->sm_ah = new_ah;
394 spin_unlock_irq(&port->ah_lock);
397 kref_put(&old_ah->ref, free_sm_ah);
400 static void ib_sa_event(struct ib_event_handler *handler, struct ib_event *event)
402 if (event->event == IB_EVENT_PORT_ERR ||
403 event->event == IB_EVENT_PORT_ACTIVE ||
404 event->event == IB_EVENT_LID_CHANGE ||
405 event->event == IB_EVENT_PKEY_CHANGE ||
406 event->event == IB_EVENT_SM_CHANGE) {
407 struct ib_sa_device *sa_dev;
408 sa_dev = container_of(handler, typeof(*sa_dev), event_handler);
410 schedule_work(&sa_dev->port[event->element.port_num -
411 sa_dev->start_port].update_task);
416 * ib_sa_cancel_query - try to cancel an SA query
417 * @id:ID of query to cancel
418 * @query:query pointer to cancel
420 * Try to cancel an SA query. If the id and query don't match up or
421 * the query has already completed, nothing is done. Otherwise the
422 * query is canceled and will complete with a status of -EINTR.
424 void ib_sa_cancel_query(int id, struct ib_sa_query *query)
427 struct ib_mad_agent *agent;
428 struct ib_mad_send_buf *mad_buf;
430 spin_lock_irqsave(&idr_lock, flags);
431 if (idr_find(&query_idr, id) != query) {
432 spin_unlock_irqrestore(&idr_lock, flags);
435 agent = query->port->agent;
436 mad_buf = query->mad_buf;
437 spin_unlock_irqrestore(&idr_lock, flags);
439 ib_cancel_mad(agent, mad_buf);
441 EXPORT_SYMBOL(ib_sa_cancel_query);
443 static void init_mad(struct ib_sa_mad *mad, struct ib_mad_agent *agent)
447 memset(mad, 0, sizeof *mad);
449 mad->mad_hdr.base_version = IB_MGMT_BASE_VERSION;
450 mad->mad_hdr.mgmt_class = IB_MGMT_CLASS_SUBN_ADM;
451 mad->mad_hdr.class_version = IB_SA_CLASS_VERSION;
453 spin_lock_irqsave(&tid_lock, flags);
455 cpu_to_be64(((u64) agent->hi_tid) << 32 | tid++);
456 spin_unlock_irqrestore(&tid_lock, flags);
459 static int send_mad(struct ib_sa_query *query, int timeout_ms)
465 if (!idr_pre_get(&query_idr, GFP_ATOMIC))
467 spin_lock_irqsave(&idr_lock, flags);
468 ret = idr_get_new(&query_idr, query, &id);
469 spin_unlock_irqrestore(&idr_lock, flags);
475 query->mad_buf->timeout_ms = timeout_ms;
476 query->mad_buf->context[0] = query;
479 spin_lock_irqsave(&query->port->ah_lock, flags);
480 kref_get(&query->port->sm_ah->ref);
481 query->sm_ah = query->port->sm_ah;
482 spin_unlock_irqrestore(&query->port->ah_lock, flags);
484 query->mad_buf->ah = query->sm_ah->ah;
486 ret = ib_post_send_mad(query->mad_buf, NULL);
488 spin_lock_irqsave(&idr_lock, flags);
489 idr_remove(&query_idr, id);
490 spin_unlock_irqrestore(&idr_lock, flags);
492 kref_put(&query->sm_ah->ref, free_sm_ah);
496 * It's not safe to dereference query any more, because the
497 * send may already have completed and freed the query in
500 return ret ? ret : id;
503 static void ib_sa_path_rec_callback(struct ib_sa_query *sa_query,
505 struct ib_sa_mad *mad)
507 struct ib_sa_path_query *query =
508 container_of(sa_query, struct ib_sa_path_query, sa_query);
511 struct ib_sa_path_rec rec;
513 ib_unpack(path_rec_table, ARRAY_SIZE(path_rec_table),
515 query->callback(status, &rec, query->context);
517 query->callback(status, NULL, query->context);
520 static void ib_sa_path_rec_release(struct ib_sa_query *sa_query)
522 kfree(container_of(sa_query, struct ib_sa_path_query, sa_query));
526 * ib_sa_path_rec_get - Start a Path get query
527 * @device:device to send query on
528 * @port_num: port number to send query on
529 * @rec:Path Record to send in query
530 * @comp_mask:component mask to send in query
531 * @timeout_ms:time to wait for response
532 * @gfp_mask:GFP mask to use for internal allocations
533 * @callback:function called when query completes, times out or is
535 * @context:opaque user context passed to callback
536 * @sa_query:query context, used to cancel query
538 * Send a Path Record Get query to the SA to look up a path. The
539 * callback function will be called when the query completes (or
540 * fails); status is 0 for a successful response, -EINTR if the query
541 * is canceled, -ETIMEDOUT is the query timed out, or -EIO if an error
542 * occurred sending the query. The resp parameter of the callback is
543 * only valid if status is 0.
545 * If the return value of ib_sa_path_rec_get() is negative, it is an
546 * error code. Otherwise it is a query ID that can be used to cancel
549 int ib_sa_path_rec_get(struct ib_device *device, u8 port_num,
550 struct ib_sa_path_rec *rec,
551 ib_sa_comp_mask comp_mask,
552 int timeout_ms, gfp_t gfp_mask,
553 void (*callback)(int status,
554 struct ib_sa_path_rec *resp,
557 struct ib_sa_query **sa_query)
559 struct ib_sa_path_query *query;
560 struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client);
561 struct ib_sa_port *port;
562 struct ib_mad_agent *agent;
563 struct ib_sa_mad *mad;
569 port = &sa_dev->port[port_num - sa_dev->start_port];
572 query = kmalloc(sizeof *query, gfp_mask);
576 query->sa_query.mad_buf = ib_create_send_mad(agent, 1, 0,
578 IB_MGMT_SA_DATA, gfp_mask);
579 if (!query->sa_query.mad_buf) {
584 query->callback = callback;
585 query->context = context;
587 mad = query->sa_query.mad_buf->mad;
588 init_mad(mad, agent);
590 query->sa_query.callback = callback ? ib_sa_path_rec_callback : NULL;
591 query->sa_query.release = ib_sa_path_rec_release;
592 query->sa_query.port = port;
593 mad->mad_hdr.method = IB_MGMT_METHOD_GET;
594 mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_PATH_REC);
595 mad->sa_hdr.comp_mask = comp_mask;
597 ib_pack(path_rec_table, ARRAY_SIZE(path_rec_table), rec, mad->data);
599 *sa_query = &query->sa_query;
601 ret = send_mad(&query->sa_query, timeout_ms);
609 ib_free_send_mad(query->sa_query.mad_buf);
615 EXPORT_SYMBOL(ib_sa_path_rec_get);
617 static void ib_sa_service_rec_callback(struct ib_sa_query *sa_query,
619 struct ib_sa_mad *mad)
621 struct ib_sa_service_query *query =
622 container_of(sa_query, struct ib_sa_service_query, sa_query);
625 struct ib_sa_service_rec rec;
627 ib_unpack(service_rec_table, ARRAY_SIZE(service_rec_table),
629 query->callback(status, &rec, query->context);
631 query->callback(status, NULL, query->context);
634 static void ib_sa_service_rec_release(struct ib_sa_query *sa_query)
636 kfree(container_of(sa_query, struct ib_sa_service_query, sa_query));
640 * ib_sa_service_rec_query - Start Service Record operation
641 * @device:device to send request on
642 * @port_num: port number to send request on
643 * @method:SA method - should be get, set, or delete
644 * @rec:Service Record to send in request
645 * @comp_mask:component mask to send in request
646 * @timeout_ms:time to wait for response
647 * @gfp_mask:GFP mask to use for internal allocations
648 * @callback:function called when request completes, times out or is
650 * @context:opaque user context passed to callback
651 * @sa_query:request context, used to cancel request
653 * Send a Service Record set/get/delete to the SA to register,
654 * unregister or query a service record.
655 * The callback function will be called when the request completes (or
656 * fails); status is 0 for a successful response, -EINTR if the query
657 * is canceled, -ETIMEDOUT is the query timed out, or -EIO if an error
658 * occurred sending the query. The resp parameter of the callback is
659 * only valid if status is 0.
661 * If the return value of ib_sa_service_rec_query() is negative, it is an
662 * error code. Otherwise it is a request ID that can be used to cancel
665 int ib_sa_service_rec_query(struct ib_device *device, u8 port_num, u8 method,
666 struct ib_sa_service_rec *rec,
667 ib_sa_comp_mask comp_mask,
668 int timeout_ms, gfp_t gfp_mask,
669 void (*callback)(int status,
670 struct ib_sa_service_rec *resp,
673 struct ib_sa_query **sa_query)
675 struct ib_sa_service_query *query;
676 struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client);
677 struct ib_sa_port *port;
678 struct ib_mad_agent *agent;
679 struct ib_sa_mad *mad;
685 port = &sa_dev->port[port_num - sa_dev->start_port];
688 if (method != IB_MGMT_METHOD_GET &&
689 method != IB_MGMT_METHOD_SET &&
690 method != IB_SA_METHOD_DELETE)
693 query = kmalloc(sizeof *query, gfp_mask);
697 query->sa_query.mad_buf = ib_create_send_mad(agent, 1, 0,
699 IB_MGMT_SA_DATA, gfp_mask);
700 if (!query->sa_query.mad_buf) {
705 query->callback = callback;
706 query->context = context;
708 mad = query->sa_query.mad_buf->mad;
709 init_mad(mad, agent);
711 query->sa_query.callback = callback ? ib_sa_service_rec_callback : NULL;
712 query->sa_query.release = ib_sa_service_rec_release;
713 query->sa_query.port = port;
714 mad->mad_hdr.method = method;
715 mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_SERVICE_REC);
716 mad->sa_hdr.comp_mask = comp_mask;
718 ib_pack(service_rec_table, ARRAY_SIZE(service_rec_table),
721 *sa_query = &query->sa_query;
723 ret = send_mad(&query->sa_query, timeout_ms);
731 ib_free_send_mad(query->sa_query.mad_buf);
737 EXPORT_SYMBOL(ib_sa_service_rec_query);
739 static void ib_sa_mcmember_rec_callback(struct ib_sa_query *sa_query,
741 struct ib_sa_mad *mad)
743 struct ib_sa_mcmember_query *query =
744 container_of(sa_query, struct ib_sa_mcmember_query, sa_query);
747 struct ib_sa_mcmember_rec rec;
749 ib_unpack(mcmember_rec_table, ARRAY_SIZE(mcmember_rec_table),
751 query->callback(status, &rec, query->context);
753 query->callback(status, NULL, query->context);
756 static void ib_sa_mcmember_rec_release(struct ib_sa_query *sa_query)
758 kfree(container_of(sa_query, struct ib_sa_mcmember_query, sa_query));
761 int ib_sa_mcmember_rec_query(struct ib_device *device, u8 port_num,
763 struct ib_sa_mcmember_rec *rec,
764 ib_sa_comp_mask comp_mask,
765 int timeout_ms, gfp_t gfp_mask,
766 void (*callback)(int status,
767 struct ib_sa_mcmember_rec *resp,
770 struct ib_sa_query **sa_query)
772 struct ib_sa_mcmember_query *query;
773 struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client);
774 struct ib_sa_port *port;
775 struct ib_mad_agent *agent;
776 struct ib_sa_mad *mad;
782 port = &sa_dev->port[port_num - sa_dev->start_port];
785 query = kmalloc(sizeof *query, gfp_mask);
789 query->sa_query.mad_buf = ib_create_send_mad(agent, 1, 0,
791 IB_MGMT_SA_DATA, gfp_mask);
792 if (!query->sa_query.mad_buf) {
797 query->callback = callback;
798 query->context = context;
800 mad = query->sa_query.mad_buf->mad;
801 init_mad(mad, agent);
803 query->sa_query.callback = callback ? ib_sa_mcmember_rec_callback : NULL;
804 query->sa_query.release = ib_sa_mcmember_rec_release;
805 query->sa_query.port = port;
806 mad->mad_hdr.method = method;
807 mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_MC_MEMBER_REC);
808 mad->sa_hdr.comp_mask = comp_mask;
810 ib_pack(mcmember_rec_table, ARRAY_SIZE(mcmember_rec_table),
813 *sa_query = &query->sa_query;
815 ret = send_mad(&query->sa_query, timeout_ms);
823 ib_free_send_mad(query->sa_query.mad_buf);
829 EXPORT_SYMBOL(ib_sa_mcmember_rec_query);
831 static void send_handler(struct ib_mad_agent *agent,
832 struct ib_mad_send_wc *mad_send_wc)
834 struct ib_sa_query *query = mad_send_wc->send_buf->context[0];
838 switch (mad_send_wc->status) {
840 /* No callback -- already got recv */
842 case IB_WC_RESP_TIMEOUT_ERR:
843 query->callback(query, -ETIMEDOUT, NULL);
845 case IB_WC_WR_FLUSH_ERR:
846 query->callback(query, -EINTR, NULL);
849 query->callback(query, -EIO, NULL);
853 spin_lock_irqsave(&idr_lock, flags);
854 idr_remove(&query_idr, query->id);
855 spin_unlock_irqrestore(&idr_lock, flags);
857 ib_free_send_mad(mad_send_wc->send_buf);
858 kref_put(&query->sm_ah->ref, free_sm_ah);
859 query->release(query);
862 static void recv_handler(struct ib_mad_agent *mad_agent,
863 struct ib_mad_recv_wc *mad_recv_wc)
865 struct ib_sa_query *query;
866 struct ib_mad_send_buf *mad_buf;
868 mad_buf = (void *) (unsigned long) mad_recv_wc->wc->wr_id;
869 query = mad_buf->context[0];
871 if (query->callback) {
872 if (mad_recv_wc->wc->status == IB_WC_SUCCESS)
873 query->callback(query,
874 mad_recv_wc->recv_buf.mad->mad_hdr.status ?
876 (struct ib_sa_mad *) mad_recv_wc->recv_buf.mad);
878 query->callback(query, -EIO, NULL);
881 ib_free_recv_mad(mad_recv_wc);
884 static void ib_sa_add_one(struct ib_device *device)
886 struct ib_sa_device *sa_dev;
889 if (device->node_type == IB_NODE_SWITCH)
893 e = device->phys_port_cnt;
896 sa_dev = kmalloc(sizeof *sa_dev +
897 (e - s + 1) * sizeof (struct ib_sa_port),
902 sa_dev->start_port = s;
903 sa_dev->end_port = e;
905 for (i = 0; i <= e - s; ++i) {
906 sa_dev->port[i].sm_ah = NULL;
907 sa_dev->port[i].port_num = i + s;
908 spin_lock_init(&sa_dev->port[i].ah_lock);
910 sa_dev->port[i].agent =
911 ib_register_mad_agent(device, i + s, IB_QPT_GSI,
912 NULL, 0, send_handler,
913 recv_handler, sa_dev);
914 if (IS_ERR(sa_dev->port[i].agent))
917 INIT_WORK(&sa_dev->port[i].update_task,
918 update_sm_ah, &sa_dev->port[i]);
921 ib_set_client_data(device, &sa_client, sa_dev);
924 * We register our event handler after everything is set up,
925 * and then update our cached info after the event handler is
926 * registered to avoid any problems if a port changes state
927 * during our initialization.
930 INIT_IB_EVENT_HANDLER(&sa_dev->event_handler, device, ib_sa_event);
931 if (ib_register_event_handler(&sa_dev->event_handler))
934 for (i = 0; i <= e - s; ++i)
935 update_sm_ah(&sa_dev->port[i]);
941 ib_unregister_mad_agent(sa_dev->port[i].agent);
948 static void ib_sa_remove_one(struct ib_device *device)
950 struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client);
956 ib_unregister_event_handler(&sa_dev->event_handler);
958 for (i = 0; i <= sa_dev->end_port - sa_dev->start_port; ++i) {
959 ib_unregister_mad_agent(sa_dev->port[i].agent);
960 kref_put(&sa_dev->port[i].sm_ah->ref, free_sm_ah);
966 static int __init ib_sa_init(void)
970 spin_lock_init(&idr_lock);
971 spin_lock_init(&tid_lock);
973 get_random_bytes(&tid, sizeof tid);
975 ret = ib_register_client(&sa_client);
977 printk(KERN_ERR "Couldn't register ib_sa client\n");
982 static void __exit ib_sa_cleanup(void)
984 ib_unregister_client(&sa_client);
985 idr_destroy(&query_idr);
988 module_init(ib_sa_init);
989 module_exit(ib_sa_cleanup);