11cfa752Ramaswamy Tummala/*
21cfa752Ramaswamy Tummala * CDDL HEADER START
31cfa752Ramaswamy Tummala *
41cfa752Ramaswamy Tummala * The contents of this file are subject to the terms of the
51cfa752Ramaswamy Tummala * Common Development and Distribution License (the "License").
61cfa752Ramaswamy Tummala * You may not use this file except in compliance with the License.
71cfa752Ramaswamy Tummala *
81cfa752Ramaswamy Tummala * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91cfa752Ramaswamy Tummala * or http://www.opensolaris.org/os/licensing.
101cfa752Ramaswamy Tummala * See the License for the specific language governing permissions
111cfa752Ramaswamy Tummala * and limitations under the License.
121cfa752Ramaswamy Tummala *
131cfa752Ramaswamy Tummala * When distributing Covered Code, include this CDDL HEADER in each
141cfa752Ramaswamy Tummala * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151cfa752Ramaswamy Tummala * If applicable, add the following below this CDDL HEADER, with the
161cfa752Ramaswamy Tummala * fields enclosed by brackets "[]" replaced with your own identifying
171cfa752Ramaswamy Tummala * information: Portions Copyright [yyyy] [name of copyright owner]
181cfa752Ramaswamy Tummala *
191cfa752Ramaswamy Tummala * CDDL HEADER END
201cfa752Ramaswamy Tummala */
211cfa752Ramaswamy Tummala/*
221cfa752Ramaswamy Tummala * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
231cfa752Ramaswamy Tummala */
241cfa752Ramaswamy Tummala
251cfa752Ramaswamy Tummala#include <sys/types.h>
261cfa752Ramaswamy Tummala#include <sys/kmem.h>
271cfa752Ramaswamy Tummala#include <sys/ksynch.h>
281cfa752Ramaswamy Tummala#include <sys/ib/ibtl/ibti_common.h>
291cfa752Ramaswamy Tummala
301cfa752Ramaswamy Tummalakmutex_t	ibtl_part_attr_mutex;
311cfa752Ramaswamy Tummalaibt_status_t	(*ibtl_get_part_attr_cb)(datalink_id_t, ibt_part_attr_t *);
321cfa752Ramaswamy Tummalaibt_status_t	(*ibtl_get_all_part_attr_cb)(ibt_part_attr_t **, int *);
331cfa752Ramaswamy Tummala
341cfa752Ramaswamy Tummalavoid
351cfa752Ramaswamy Tummalaibt_register_part_attr_cb(
361cfa752Ramaswamy Tummala    ibt_status_t (*get_part_attr)(datalink_id_t, ibt_part_attr_t *),
371cfa752Ramaswamy Tummala    ibt_status_t (*get_all_part_attr)(ibt_part_attr_t **, int *))
381cfa752Ramaswamy Tummala{
391cfa752Ramaswamy Tummala	mutex_enter(&ibtl_part_attr_mutex);
401cfa752Ramaswamy Tummala	ibtl_get_part_attr_cb = get_part_attr;
411cfa752Ramaswamy Tummala	ibtl_get_all_part_attr_cb = get_all_part_attr;
421cfa752Ramaswamy Tummala	mutex_exit(&ibtl_part_attr_mutex);
431cfa752Ramaswamy Tummala}
441cfa752Ramaswamy Tummala
451cfa752Ramaswamy Tummalavoid
461cfa752Ramaswamy Tummalaibt_unregister_part_attr_cb(void)
471cfa752Ramaswamy Tummala{
481cfa752Ramaswamy Tummala	mutex_enter(&ibtl_part_attr_mutex);
491cfa752Ramaswamy Tummala	ibtl_get_part_attr_cb = NULL;
501cfa752Ramaswamy Tummala	ibtl_get_all_part_attr_cb = NULL;
511cfa752Ramaswamy Tummala	mutex_exit(&ibtl_part_attr_mutex);
521cfa752Ramaswamy Tummala}
531cfa752Ramaswamy Tummala
541cfa752Ramaswamy Tummalaibt_status_t
551cfa752Ramaswamy Tummalaibt_get_part_attr(datalink_id_t linkid, ibt_part_attr_t *attr)
561cfa752Ramaswamy Tummala{
571cfa752Ramaswamy Tummala	ibt_status_t	status;
581cfa752Ramaswamy Tummala
591cfa752Ramaswamy Tummala	mutex_enter(&ibtl_part_attr_mutex);
601cfa752Ramaswamy Tummala	if (ibtl_get_part_attr_cb != NULL)
611cfa752Ramaswamy Tummala		status = (*ibtl_get_part_attr_cb) (linkid, attr);
621cfa752Ramaswamy Tummala	else
631cfa752Ramaswamy Tummala		status = IBT_NO_SUCH_OBJECT;
641cfa752Ramaswamy Tummala	mutex_exit(&ibtl_part_attr_mutex);
651cfa752Ramaswamy Tummala
661cfa752Ramaswamy Tummala	return (status);
671cfa752Ramaswamy Tummala}
681cfa752Ramaswamy Tummala
691cfa752Ramaswamy Tummalaibt_status_t
701cfa752Ramaswamy Tummalaibt_get_all_part_attr(ibt_part_attr_t **attr, int *nparts)
711cfa752Ramaswamy Tummala{
721cfa752Ramaswamy Tummala	ibt_status_t	status;
731cfa752Ramaswamy Tummala
741cfa752Ramaswamy Tummala	mutex_enter(&ibtl_part_attr_mutex);
751cfa752Ramaswamy Tummala	if (ibtl_get_all_part_attr_cb != NULL)
761cfa752Ramaswamy Tummala		status = (*ibtl_get_all_part_attr_cb) (attr, nparts);
771cfa752Ramaswamy Tummala	else {
781cfa752Ramaswamy Tummala		*attr = NULL;
791cfa752Ramaswamy Tummala		*nparts = 0;
801cfa752Ramaswamy Tummala		status = IBT_SUCCESS;
811cfa752Ramaswamy Tummala	}
821cfa752Ramaswamy Tummala	mutex_exit(&ibtl_part_attr_mutex);
831cfa752Ramaswamy Tummala
841cfa752Ramaswamy Tummala	return (status);
851cfa752Ramaswamy Tummala}
861cfa752Ramaswamy Tummala
871cfa752Ramaswamy Tummalaibt_status_t
881cfa752Ramaswamy Tummalaibt_free_part_attr(ibt_part_attr_t *attr, int nparts)
891cfa752Ramaswamy Tummala{
901cfa752Ramaswamy Tummala	if (nparts > 0)
911cfa752Ramaswamy Tummala		kmem_free(attr, sizeof (ibt_part_attr_t) * nparts);
921cfa752Ramaswamy Tummala	return (IBT_SUCCESS);
931cfa752Ramaswamy Tummala}
94