Merge remote-tracking branch 'origin/master'
[unleashed/lotheac.git] / usr / src / uts / common / io / ib / ibtl / ibtl_part.c
blobc1a8a0a531d2611437a1ad9a79b01d13b39d28e4
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
25 #include <sys/types.h>
26 #include <sys/kmem.h>
27 #include <sys/ksynch.h>
28 #include <sys/ib/ibtl/ibti_common.h>
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 *);
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 *))
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);
45 void
46 ibt_unregister_part_attr_cb(void)
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);
54 ibt_status_t
55 ibt_get_part_attr(datalink_id_t linkid, ibt_part_attr_t *attr)
57 ibt_status_t status;
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);
66 return (status);
69 ibt_status_t
70 ibt_get_all_part_attr(ibt_part_attr_t **attr, int *nparts)
72 ibt_status_t status;
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;
82 mutex_exit(&ibtl_part_attr_mutex);
84 return (status);
87 ibt_status_t
88 ibt_free_part_attr(ibt_part_attr_t *attr, int nparts)
90 if (nparts > 0)
91 kmem_free(attr, sizeof (ibt_part_attr_t) * nparts);
92 return (IBT_SUCCESS);