xref: /illumos-gate/usr/src/uts/common/io/ib/ibtl/ibtl_part.c (revision 1cfa752f4e24c34133009b0f6c139127a5c461de)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #include <sys/types.h>
26 #include <sys/kmem.h>
27 #include <sys/ksynch.h>
28 #include <sys/ib/ibtl/ibti_common.h>
29 
30 kmutex_t	ibtl_part_attr_mutex;
31 ibt_status_t	(*ibtl_get_part_attr_cb)(datalink_id_t, ibt_part_attr_t *);
32 ibt_status_t	(*ibtl_get_all_part_attr_cb)(ibt_part_attr_t **, int *);
33 
34 void
35 ibt_register_part_attr_cb(
36     ibt_status_t (*get_part_attr)(datalink_id_t, ibt_part_attr_t *),
37     ibt_status_t (*get_all_part_attr)(ibt_part_attr_t **, int *))
38 {
39 	mutex_enter(&ibtl_part_attr_mutex);
40 	ibtl_get_part_attr_cb = get_part_attr;
41 	ibtl_get_all_part_attr_cb = get_all_part_attr;
42 	mutex_exit(&ibtl_part_attr_mutex);
43 }
44 
45 void
46 ibt_unregister_part_attr_cb(void)
47 {
48 	mutex_enter(&ibtl_part_attr_mutex);
49 	ibtl_get_part_attr_cb = NULL;
50 	ibtl_get_all_part_attr_cb = NULL;
51 	mutex_exit(&ibtl_part_attr_mutex);
52 }
53 
54 ibt_status_t
55 ibt_get_part_attr(datalink_id_t linkid, ibt_part_attr_t *attr)
56 {
57 	ibt_status_t	status;
58 
59 	mutex_enter(&ibtl_part_attr_mutex);
60 	if (ibtl_get_part_attr_cb != NULL)
61 		status = (*ibtl_get_part_attr_cb) (linkid, attr);
62 	else
63 		status = IBT_NO_SUCH_OBJECT;
64 	mutex_exit(&ibtl_part_attr_mutex);
65 
66 	return (status);
67 }
68 
69 ibt_status_t
70 ibt_get_all_part_attr(ibt_part_attr_t **attr, int *nparts)
71 {
72 	ibt_status_t	status;
73 
74 	mutex_enter(&ibtl_part_attr_mutex);
75 	if (ibtl_get_all_part_attr_cb != NULL)
76 		status = (*ibtl_get_all_part_attr_cb) (attr, nparts);
77 	else {
78 		*attr = NULL;
79 		*nparts = 0;
80 		status = IBT_SUCCESS;
81 	}
82 	mutex_exit(&ibtl_part_attr_mutex);
83 
84 	return (status);
85 }
86 
87 ibt_status_t
88 ibt_free_part_attr(ibt_part_attr_t *attr, int nparts)
89 {
90 	if (nparts > 0)
91 		kmem_free(attr, sizeof (ibt_part_attr_t) * nparts);
92 	return (IBT_SUCCESS);
93 }
94