xref: /onnv-gate/usr/src/cmd/picl/plugins/sun4u/frudata/fru_data.c (revision 9407:b282bcfbefd1)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*9407SMichael.Bergknoff@Sun.COM  * Common Development and Distribution License (the "License").
6*9407SMichael.Bergknoff@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*9407SMichael.Bergknoff@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #include <picl.h>
270Sstevel@tonic-gate #include <syslog.h>
280Sstevel@tonic-gate #include <strings.h>
290Sstevel@tonic-gate #include <alloca.h>
300Sstevel@tonic-gate #include <pthread.h>
310Sstevel@tonic-gate #include <synch.h>
320Sstevel@tonic-gate #include <limits.h>
330Sstevel@tonic-gate #include <ctype.h>
340Sstevel@tonic-gate #include <unistd.h>
350Sstevel@tonic-gate #include <picltree.h>
360Sstevel@tonic-gate #include <signal.h>
370Sstevel@tonic-gate #include <sys/utsname.h>
380Sstevel@tonic-gate #include <sys/systeminfo.h>
390Sstevel@tonic-gate #include <libnvpair.h>
400Sstevel@tonic-gate #include "fru_tag.h"
410Sstevel@tonic-gate #include "fru_data_impl.h"
420Sstevel@tonic-gate #include "fru_data.h"
430Sstevel@tonic-gate #include "picld_pluginutil.h"
440Sstevel@tonic-gate 
450Sstevel@tonic-gate #pragma	init(frudata_plugin_register) /* .init section */
460Sstevel@tonic-gate 
470Sstevel@tonic-gate static	void		frudata_plugin_init(void);
480Sstevel@tonic-gate static	void		frudata_plugin_fini(void);
490Sstevel@tonic-gate static	container_tbl_t *container_table[TABLE_SIZE];
500Sstevel@tonic-gate 
510Sstevel@tonic-gate /*
520Sstevel@tonic-gate  * Locking Stragtegy :
530Sstevel@tonic-gate  * calling thread should hold the cont_tbl_lock during the course
540Sstevel@tonic-gate  * of container table lookup. release the cont_tbl_lock on lookup
550Sstevel@tonic-gate  * failure or on the condition wait.
560Sstevel@tonic-gate  *
570Sstevel@tonic-gate  * thread holding the container object rwlock should release lock
580Sstevel@tonic-gate  * and signal to unblock threads blocked on the condition variable
590Sstevel@tonic-gate  * upon i/o completion.
600Sstevel@tonic-gate  *
610Sstevel@tonic-gate  */
620Sstevel@tonic-gate 
630Sstevel@tonic-gate static pthread_mutex_t	cont_tbl_lock = PTHREAD_MUTEX_INITIALIZER;
640Sstevel@tonic-gate 
650Sstevel@tonic-gate static int add_row_to_table(hash_obj_t *, picl_nodehdl_t,
660Sstevel@tonic-gate 				packet_t *, container_tbl_t *);
670Sstevel@tonic-gate 
680Sstevel@tonic-gate static picld_plugin_reg_t frudata_reg_info = {
690Sstevel@tonic-gate 		PICLD_PLUGIN_VERSION_1,
700Sstevel@tonic-gate 		PICLD_PLUGIN_NON_CRITICAL,
710Sstevel@tonic-gate 		"SUNW_piclfrudata",
720Sstevel@tonic-gate 		frudata_plugin_init,	/* init entry point */
730Sstevel@tonic-gate 		frudata_plugin_fini	/* cleanup entry point */
740Sstevel@tonic-gate };
750Sstevel@tonic-gate 
760Sstevel@tonic-gate /* initialization function */
770Sstevel@tonic-gate static void
frudata_plugin_register(void)780Sstevel@tonic-gate frudata_plugin_register(void)
790Sstevel@tonic-gate {
800Sstevel@tonic-gate 	/* register plugin with daemon */
810Sstevel@tonic-gate 	if (picld_plugin_register(&frudata_reg_info) != PICL_SUCCESS) {
820Sstevel@tonic-gate 		syslog(LOG_ERR, "SUNW_piclfrudata plugin registration failed");
830Sstevel@tonic-gate 	}
840Sstevel@tonic-gate }
850Sstevel@tonic-gate 
860Sstevel@tonic-gate static int
map_access_err(int err)870Sstevel@tonic-gate map_access_err(int err)
880Sstevel@tonic-gate {
890Sstevel@tonic-gate 	switch (err) {
900Sstevel@tonic-gate 	case	ENFILE	:
910Sstevel@tonic-gate 		return (PICL_PROPEXISTS);
920Sstevel@tonic-gate 	case	EAGAIN	:
930Sstevel@tonic-gate 		return (PICL_NOSPACE);
940Sstevel@tonic-gate 	case	EPERM	:
950Sstevel@tonic-gate 		return (PICL_PERMDENIED);
960Sstevel@tonic-gate 	case	EEXIST	:
970Sstevel@tonic-gate 		return (PICL_PROPEXISTS);
980Sstevel@tonic-gate 	default	:
990Sstevel@tonic-gate 		return (PICL_FAILURE);
1000Sstevel@tonic-gate 	}
1010Sstevel@tonic-gate }
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate /*
1040Sstevel@tonic-gate  * unlock_container_lock() should be always called by the thread holding the
1050Sstevel@tonic-gate  * container object lock. it will signal block thread waiting on the condition
1060Sstevel@tonic-gate  * variable.
1070Sstevel@tonic-gate  */
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate static void
unlock_container_lock(container_tbl_t * cont_hash)1100Sstevel@tonic-gate unlock_container_lock(container_tbl_t	*cont_hash)
1110Sstevel@tonic-gate {
1120Sstevel@tonic-gate 	(void) pthread_rwlock_unlock(&cont_hash->rwlock);
1130Sstevel@tonic-gate 	(void) pthread_mutex_lock(&cont_tbl_lock);
1140Sstevel@tonic-gate 	(void) pthread_cond_signal(&cont_hash->cond_var);
1150Sstevel@tonic-gate 	(void) pthread_mutex_unlock(&cont_tbl_lock);
1160Sstevel@tonic-gate }
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate /* volatile callback read routine */
1200Sstevel@tonic-gate /* ARGSUSED */
1210Sstevel@tonic-gate static int
frudata_read_callback(ptree_rarg_t * rarg,void * buf)1220Sstevel@tonic-gate frudata_read_callback(ptree_rarg_t *rarg, void *buf)
1230Sstevel@tonic-gate {
1240Sstevel@tonic-gate 	return (PICL_SUCCESS);
1250Sstevel@tonic-gate }
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate /*
1280Sstevel@tonic-gate  * called to get hash object for specified node and object type from
1290Sstevel@tonic-gate  * hash table.
1300Sstevel@tonic-gate  */
1310Sstevel@tonic-gate static container_tbl_t *
lookup_container_table(picl_nodehdl_t nodehdl,int object_type)1320Sstevel@tonic-gate lookup_container_table(picl_nodehdl_t nodehdl, int object_type)
1330Sstevel@tonic-gate {
1340Sstevel@tonic-gate 	int		index_to_hash;
1350Sstevel@tonic-gate 	int		retval = PICL_SUCCESS;
1360Sstevel@tonic-gate 	container_tbl_t	*first_hash;
1370Sstevel@tonic-gate 	container_tbl_t	*next_hash;
1380Sstevel@tonic-gate 	picl_nodehdl_t	parenthdl = 0;
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate 	switch (object_type) {
1410Sstevel@tonic-gate 	case	SECTION_NODE:
1420Sstevel@tonic-gate 		retval = ptree_get_propval_by_name(nodehdl, PICL_PROP_PARENT,
143*9407SMichael.Bergknoff@Sun.COM 		    &parenthdl, sizeof (picl_nodehdl_t));
1440Sstevel@tonic-gate 		break;
1450Sstevel@tonic-gate 	case	SEGMENT_NODE:
1460Sstevel@tonic-gate 		retval = ptree_get_propval_by_name(nodehdl, PICL_PROP_PARENT,
147*9407SMichael.Bergknoff@Sun.COM 		    &parenthdl, sizeof (picl_nodehdl_t));
1480Sstevel@tonic-gate 		retval = ptree_get_propval_by_name(parenthdl, PICL_PROP_PARENT,
149*9407SMichael.Bergknoff@Sun.COM 		    &parenthdl, sizeof (picl_nodehdl_t));
1500Sstevel@tonic-gate 		break;
1510Sstevel@tonic-gate 	case	CONTAINER_NODE :
1520Sstevel@tonic-gate 		parenthdl = nodehdl;
1530Sstevel@tonic-gate 		break;
1540Sstevel@tonic-gate 	default	:
1550Sstevel@tonic-gate 		return (NULL);
1560Sstevel@tonic-gate 	}
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
1590Sstevel@tonic-gate 		return (NULL);
1600Sstevel@tonic-gate 	}
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate 	index_to_hash	= (parenthdl % TABLE_SIZE);
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate 	first_hash	= container_table[index_to_hash];
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate 	for (next_hash = first_hash; next_hash != NULL;
167*9407SMichael.Bergknoff@Sun.COM 	    next_hash = next_hash->next) {
1680Sstevel@tonic-gate 		if (parenthdl == next_hash->picl_hdl) {
1690Sstevel@tonic-gate 			return (next_hash);
1700Sstevel@tonic-gate 		}
1710Sstevel@tonic-gate 	}
1720Sstevel@tonic-gate 	return (NULL);
1730Sstevel@tonic-gate }
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate static int
lock_readwrite_lock(container_tbl_t * cont_obj,int operation)1760Sstevel@tonic-gate lock_readwrite_lock(container_tbl_t *cont_obj, int operation)
1770Sstevel@tonic-gate {
1780Sstevel@tonic-gate 	/* if write operation */
1790Sstevel@tonic-gate 	if (operation == PICL_WRITE) {
1800Sstevel@tonic-gate 		return (pthread_rwlock_trywrlock(&cont_obj->rwlock));
1810Sstevel@tonic-gate 	}
1820Sstevel@tonic-gate 	/* read operation */
1830Sstevel@tonic-gate 	return (pthread_rwlock_tryrdlock(&cont_obj->rwlock));
1840Sstevel@tonic-gate }
1850Sstevel@tonic-gate 
1860Sstevel@tonic-gate /*
1870Sstevel@tonic-gate  * lock the container table, do lookup for the container object
1880Sstevel@tonic-gate  * in the container table. if container object found try to lock
1890Sstevel@tonic-gate  * the container object, if lock on container object is busy wait
1900Sstevel@tonic-gate  * on condition variable till the thread holding the container
1910Sstevel@tonic-gate  * object lock signal it.
1920Sstevel@tonic-gate  */
1930Sstevel@tonic-gate 
1940Sstevel@tonic-gate static container_tbl_t *
lock_container_lock(picl_nodehdl_t nodehdl,int object_type,int operation)1950Sstevel@tonic-gate lock_container_lock(picl_nodehdl_t nodehdl, int object_type, int operation)
1960Sstevel@tonic-gate {
1970Sstevel@tonic-gate 	container_tbl_t	*cont_obj = NULL;
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate 	(void) pthread_mutex_lock(&cont_tbl_lock);
2000Sstevel@tonic-gate 
2010Sstevel@tonic-gate 	while (((cont_obj = lookup_container_table(nodehdl, object_type)) !=
202*9407SMichael.Bergknoff@Sun.COM 	    NULL) && (lock_readwrite_lock(cont_obj, operation) == EBUSY)) {
2030Sstevel@tonic-gate 		pthread_cond_wait(&cont_obj->cond_var, &cont_tbl_lock);
2040Sstevel@tonic-gate 	}
2050Sstevel@tonic-gate 
2060Sstevel@tonic-gate 	(void) pthread_mutex_unlock(&cont_tbl_lock);
2070Sstevel@tonic-gate 
2080Sstevel@tonic-gate 	return (cont_obj);
2090Sstevel@tonic-gate }
2100Sstevel@tonic-gate 
2110Sstevel@tonic-gate static hash_obj_t *
lookup_node_object(picl_nodehdl_t nodehdl,int object_type,container_tbl_t * cont_tbl)2120Sstevel@tonic-gate lookup_node_object(picl_nodehdl_t nodehdl, int	object_type,
2130Sstevel@tonic-gate 					container_tbl_t *cont_tbl)
2140Sstevel@tonic-gate {
2150Sstevel@tonic-gate 	int		index_to_hash;
2160Sstevel@tonic-gate 	hash_obj_t	*first_hash;
2170Sstevel@tonic-gate 	hash_obj_t	*next_hash;
2180Sstevel@tonic-gate 
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate 	index_to_hash	= (nodehdl % TABLE_SIZE);
2210Sstevel@tonic-gate 
2220Sstevel@tonic-gate 	first_hash	= &cont_tbl->hash_obj[index_to_hash];
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate 	for (next_hash = first_hash->next; next_hash != NULL;
225*9407SMichael.Bergknoff@Sun.COM 	    next_hash = next_hash->next) {
2260Sstevel@tonic-gate 		if ((nodehdl == next_hash->picl_hdl) &&
227*9407SMichael.Bergknoff@Sun.COM 		    (object_type == next_hash->object_type)) {
2280Sstevel@tonic-gate 			return (next_hash);
2290Sstevel@tonic-gate 		}
2300Sstevel@tonic-gate 	}
2310Sstevel@tonic-gate 	return (NULL);
2320Sstevel@tonic-gate }
2330Sstevel@tonic-gate 
2340Sstevel@tonic-gate /*
2350Sstevel@tonic-gate  * called to add newly created container hash table into container hash table.
2360Sstevel@tonic-gate  *
2370Sstevel@tonic-gate  */
2380Sstevel@tonic-gate static void
add_tblobject_to_container_tbl(container_tbl_t * cont_tbl)2390Sstevel@tonic-gate add_tblobject_to_container_tbl(container_tbl_t	*cont_tbl)
2400Sstevel@tonic-gate {
2410Sstevel@tonic-gate 	int		cnt;
2420Sstevel@tonic-gate 	int		index_to_hash;
2430Sstevel@tonic-gate 	hash_obj_t	*hash_ptr;
2440Sstevel@tonic-gate 
2450Sstevel@tonic-gate 	index_to_hash	= ((cont_tbl->picl_hdl) % TABLE_SIZE);
2460Sstevel@tonic-gate 
2470Sstevel@tonic-gate 	cont_tbl->next	= container_table[index_to_hash];
2480Sstevel@tonic-gate 	container_table[index_to_hash] = cont_tbl;
2490Sstevel@tonic-gate 	hash_ptr	= cont_tbl->hash_obj;
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate 	/* initialize the bucket of this container hash table. */
2520Sstevel@tonic-gate 
2530Sstevel@tonic-gate 	for (cnt = 0; cnt < TABLE_SIZE; cnt++) {
2540Sstevel@tonic-gate 		hash_ptr->next = NULL;
2550Sstevel@tonic-gate 		hash_ptr->prev = NULL;
2560Sstevel@tonic-gate 		hash_ptr++;
2570Sstevel@tonic-gate 	}
2580Sstevel@tonic-gate 	if (cont_tbl->next != NULL) {
2590Sstevel@tonic-gate 		cont_tbl->next->prev = cont_tbl;
2600Sstevel@tonic-gate 	}
2610Sstevel@tonic-gate }
2620Sstevel@tonic-gate 
2630Sstevel@tonic-gate static void
add_nodeobject_to_hashtable(hash_obj_t * hash_obj,container_tbl_t * cont_tbl)2640Sstevel@tonic-gate add_nodeobject_to_hashtable(hash_obj_t	*hash_obj, container_tbl_t *cont_tbl)
2650Sstevel@tonic-gate {
2660Sstevel@tonic-gate 	int		index_to_hash;
2670Sstevel@tonic-gate 	hash_obj_t	*hash_table;
2680Sstevel@tonic-gate 
2690Sstevel@tonic-gate 	index_to_hash	= ((hash_obj->picl_hdl) % TABLE_SIZE);
2700Sstevel@tonic-gate 	hash_table	= &cont_tbl->hash_obj[index_to_hash];
2710Sstevel@tonic-gate 
2720Sstevel@tonic-gate 	hash_obj->next	= hash_table->next;
2730Sstevel@tonic-gate 	hash_table->next = hash_obj;
2740Sstevel@tonic-gate 
2750Sstevel@tonic-gate 	if (hash_obj->next != NULL) {
2760Sstevel@tonic-gate 		hash_obj->next->prev = hash_obj;
2770Sstevel@tonic-gate 	}
2780Sstevel@tonic-gate }
2790Sstevel@tonic-gate 
2800Sstevel@tonic-gate static container_tbl_t *
alloc_container_table(picl_nodehdl_t nodehdl)2810Sstevel@tonic-gate alloc_container_table(picl_nodehdl_t nodehdl)
2820Sstevel@tonic-gate {
2830Sstevel@tonic-gate 	container_tbl_t		*cont_tbl;
2840Sstevel@tonic-gate 
2850Sstevel@tonic-gate 	cont_tbl = malloc(sizeof (container_tbl_t));
2860Sstevel@tonic-gate 	if (cont_tbl == NULL) {
2870Sstevel@tonic-gate 		return (NULL);
2880Sstevel@tonic-gate 	}
2890Sstevel@tonic-gate 
2900Sstevel@tonic-gate 	cont_tbl->picl_hdl = nodehdl;
2910Sstevel@tonic-gate 
2920Sstevel@tonic-gate 	cont_tbl->hash_obj = malloc(sizeof (hash_obj_t[TABLE_SIZE]));
2930Sstevel@tonic-gate 	cont_tbl->next =	NULL;
2940Sstevel@tonic-gate 	cont_tbl->prev =	NULL;
2950Sstevel@tonic-gate 
2960Sstevel@tonic-gate 	if (cont_tbl->hash_obj == NULL) {
2970Sstevel@tonic-gate 		(void) free(cont_tbl);
2980Sstevel@tonic-gate 		return (NULL);
2990Sstevel@tonic-gate 	}
3000Sstevel@tonic-gate 
3010Sstevel@tonic-gate 	(void) pthread_rwlock_init(&cont_tbl->rwlock, NULL);
3020Sstevel@tonic-gate 	(void) pthread_cond_init(&cont_tbl->cond_var, NULL);
3030Sstevel@tonic-gate 
3040Sstevel@tonic-gate 	return (cont_tbl);
3050Sstevel@tonic-gate }
3060Sstevel@tonic-gate 
3070Sstevel@tonic-gate /*
3080Sstevel@tonic-gate  * called to allocate container node object for container property and a
3090Sstevel@tonic-gate  * container table.
3100Sstevel@tonic-gate  */
3110Sstevel@tonic-gate 
3120Sstevel@tonic-gate static hash_obj_t *
alloc_container_node_object(picl_nodehdl_t nodehdl)3130Sstevel@tonic-gate alloc_container_node_object(picl_nodehdl_t nodehdl)
3140Sstevel@tonic-gate {
3150Sstevel@tonic-gate 	hash_obj_t		*hash_obj;
3160Sstevel@tonic-gate 	fru_access_hdl_t	acc_hdl;
3170Sstevel@tonic-gate 	container_node_t	*cont_node;
3180Sstevel@tonic-gate 
3190Sstevel@tonic-gate 	/* open the container (call fruaccess) */
3200Sstevel@tonic-gate 	acc_hdl = fru_open_container(nodehdl);
3210Sstevel@tonic-gate 	if (acc_hdl == (container_hdl_t)0) {
3220Sstevel@tonic-gate 		return (NULL);
3230Sstevel@tonic-gate 	}
3240Sstevel@tonic-gate 
3250Sstevel@tonic-gate 	/* allocate container node object */
3260Sstevel@tonic-gate 	cont_node	= malloc(sizeof (container_node_t));
3270Sstevel@tonic-gate 	if (cont_node == NULL) {
3280Sstevel@tonic-gate 		return (NULL);
3290Sstevel@tonic-gate 	}
3300Sstevel@tonic-gate 
3310Sstevel@tonic-gate 	/* allocate container hash object */
3320Sstevel@tonic-gate 	hash_obj	= malloc(sizeof (hash_obj_t));
3330Sstevel@tonic-gate 	if (hash_obj == NULL) {
3340Sstevel@tonic-gate 		(void) free(cont_node);
3350Sstevel@tonic-gate 		return (NULL);
3360Sstevel@tonic-gate 	}
3370Sstevel@tonic-gate 
3380Sstevel@tonic-gate 	cont_node->cont_hdl	=	acc_hdl; /* fruaccess handle */
3390Sstevel@tonic-gate 	cont_node->section_list	=	NULL;
3400Sstevel@tonic-gate 	hash_obj->picl_hdl	=	nodehdl; /* picl node handle */
3410Sstevel@tonic-gate 	hash_obj->object_type	=	CONTAINER_NODE;
3420Sstevel@tonic-gate 	hash_obj->u.cont_node	=	cont_node;
3430Sstevel@tonic-gate 	hash_obj->next		=	NULL;
3440Sstevel@tonic-gate 	hash_obj->prev		=	NULL;
3450Sstevel@tonic-gate 
3460Sstevel@tonic-gate 	return (hash_obj);
3470Sstevel@tonic-gate }
3480Sstevel@tonic-gate 
3490Sstevel@tonic-gate /*
3500Sstevel@tonic-gate  * called to allocate node object for section node.
3510Sstevel@tonic-gate  */
3520Sstevel@tonic-gate 
3530Sstevel@tonic-gate static hash_obj_t *
alloc_section_node_object(picl_nodehdl_t nodehdl,section_t * section)3540Sstevel@tonic-gate alloc_section_node_object(picl_nodehdl_t  nodehdl, section_t  *section)
3550Sstevel@tonic-gate {
3560Sstevel@tonic-gate 	hash_obj_t		*hash_obj;
3570Sstevel@tonic-gate 	section_node_t		*sec_node;
3580Sstevel@tonic-gate 
3590Sstevel@tonic-gate 	/* allocate section node object */
3600Sstevel@tonic-gate 	sec_node = malloc(sizeof (section_node_t));
3610Sstevel@tonic-gate 	if (sec_node	== NULL) {
3620Sstevel@tonic-gate 		return (NULL);
3630Sstevel@tonic-gate 	}
3640Sstevel@tonic-gate 
3650Sstevel@tonic-gate 	/* allocate section hash object */
3660Sstevel@tonic-gate 	hash_obj = malloc(sizeof (hash_obj_t));
3670Sstevel@tonic-gate 	if (hash_obj == NULL) {
3680Sstevel@tonic-gate 		(void) free(sec_node);
3690Sstevel@tonic-gate 		return (NULL);
3700Sstevel@tonic-gate 	}
3710Sstevel@tonic-gate 
3720Sstevel@tonic-gate 	sec_node->section_hdl	=	section->handle; /* fruaccess hdl. */
3730Sstevel@tonic-gate 	sec_node->segment_list	=	NULL;
3740Sstevel@tonic-gate 	sec_node->next		=	NULL;
3750Sstevel@tonic-gate 	sec_node->num_of_segment =	-1;
3760Sstevel@tonic-gate 
3770Sstevel@tonic-gate 	hash_obj->picl_hdl	=	nodehdl; /* picl node handle */
3780Sstevel@tonic-gate 	hash_obj->object_type	=	SECTION_NODE;
3790Sstevel@tonic-gate 	hash_obj->u.sec_node	=	sec_node;
3800Sstevel@tonic-gate 	hash_obj->next		=	NULL;
3810Sstevel@tonic-gate 	hash_obj->prev		=	NULL;
3820Sstevel@tonic-gate 
3830Sstevel@tonic-gate 	return (hash_obj);
3840Sstevel@tonic-gate }
3850Sstevel@tonic-gate 
3860Sstevel@tonic-gate /*
3870Sstevel@tonic-gate  * called to allocate segment node object.
3880Sstevel@tonic-gate  */
3890Sstevel@tonic-gate 
3900Sstevel@tonic-gate static hash_obj_t *
alloc_segment_node_object(picl_nodehdl_t nodehdl,segment_t * segment)3910Sstevel@tonic-gate alloc_segment_node_object(picl_nodehdl_t nodehdl, segment_t *segment)
3920Sstevel@tonic-gate {
3930Sstevel@tonic-gate 	hash_obj_t	*hash_obj;
3940Sstevel@tonic-gate 	segment_node_t	*seg_node;
3950Sstevel@tonic-gate 
3960Sstevel@tonic-gate 	/* allocate segment node object */
3970Sstevel@tonic-gate 	seg_node = malloc(sizeof (segment_node_t));
3980Sstevel@tonic-gate 	if (seg_node == NULL) {
3990Sstevel@tonic-gate 		return (NULL);
4000Sstevel@tonic-gate 	}
4010Sstevel@tonic-gate 
4020Sstevel@tonic-gate 	/* allocate segment hash object */
4030Sstevel@tonic-gate 	hash_obj = malloc(sizeof (hash_obj_t));
4040Sstevel@tonic-gate 	if (hash_obj == NULL) {
4050Sstevel@tonic-gate 		free(seg_node);
4060Sstevel@tonic-gate 		return (NULL);
4070Sstevel@tonic-gate 	}
4080Sstevel@tonic-gate 
4090Sstevel@tonic-gate 	/* fruaccess handle */
4100Sstevel@tonic-gate 	seg_node->segment_hdl	= segment->handle;
4110Sstevel@tonic-gate 	seg_node->packet_list	= NULL;
4120Sstevel@tonic-gate 	seg_node->next		= NULL;
4130Sstevel@tonic-gate 	seg_node->num_of_pkt	= -1;
4140Sstevel@tonic-gate 
4150Sstevel@tonic-gate 	/* picl node handle */
4160Sstevel@tonic-gate 	hash_obj->picl_hdl	= nodehdl;
4170Sstevel@tonic-gate 	hash_obj->object_type	= SEGMENT_NODE;
4180Sstevel@tonic-gate 	hash_obj->u.seg_node	= seg_node;
4190Sstevel@tonic-gate 	hash_obj->next		= NULL;
4200Sstevel@tonic-gate 	hash_obj->prev		= NULL;
4210Sstevel@tonic-gate 
4220Sstevel@tonic-gate 	return (hash_obj);
4230Sstevel@tonic-gate }
4240Sstevel@tonic-gate 
4250Sstevel@tonic-gate /*
4260Sstevel@tonic-gate  * called to allocate node object for packet.
4270Sstevel@tonic-gate  */
4280Sstevel@tonic-gate 
4290Sstevel@tonic-gate static hash_obj_t *
alloc_packet_node_object(picl_nodehdl_t nodehdl,packet_t * packet)4300Sstevel@tonic-gate alloc_packet_node_object(picl_nodehdl_t	nodehdl, packet_t *packet)
4310Sstevel@tonic-gate {
4320Sstevel@tonic-gate 	hash_obj_t	*hash_obj;
4330Sstevel@tonic-gate 	packet_node_t	*pkt_node;
4340Sstevel@tonic-gate 
4350Sstevel@tonic-gate 	/* allocate packet node object */
4360Sstevel@tonic-gate 	pkt_node = malloc(sizeof (packet_node_t));
4370Sstevel@tonic-gate 	if (pkt_node == NULL) {
4380Sstevel@tonic-gate 		return (NULL);
4390Sstevel@tonic-gate 	}
4400Sstevel@tonic-gate 
4410Sstevel@tonic-gate 	/* allocate packet hash object */
4420Sstevel@tonic-gate 	hash_obj = malloc(sizeof (hash_obj_t));
4430Sstevel@tonic-gate 	if (hash_obj == NULL) {
4440Sstevel@tonic-gate 		free(pkt_node);
4450Sstevel@tonic-gate 		return (NULL);
4460Sstevel@tonic-gate 	}
4470Sstevel@tonic-gate 
4480Sstevel@tonic-gate 	/* fruaccess handle */
4490Sstevel@tonic-gate 	pkt_node->pkt_handle	= packet->handle;
4500Sstevel@tonic-gate 	pkt_node->next		= NULL;
4510Sstevel@tonic-gate 
4520Sstevel@tonic-gate 	hash_obj->picl_hdl	= nodehdl;	/* picl node handle */
4530Sstevel@tonic-gate 	hash_obj->object_type	= PACKET_NODE;
4540Sstevel@tonic-gate 	hash_obj->u.pkt_node	= pkt_node;
4550Sstevel@tonic-gate 	hash_obj->next		= NULL;
4560Sstevel@tonic-gate 	hash_obj->prev		= NULL;
4570Sstevel@tonic-gate 
4580Sstevel@tonic-gate 	return (hash_obj);
4590Sstevel@tonic-gate }
4600Sstevel@tonic-gate 
4610Sstevel@tonic-gate /* add new section hash object to the section list */
4620Sstevel@tonic-gate static void
add_to_section_list(hash_obj_t * container_hash,hash_obj_t * sect_hash)4630Sstevel@tonic-gate add_to_section_list(hash_obj_t  *container_hash, hash_obj_t *sect_hash)
4640Sstevel@tonic-gate {
4650Sstevel@tonic-gate 	hash_obj_t	*next_hash;
4660Sstevel@tonic-gate 
4670Sstevel@tonic-gate 	sect_hash->u.sec_node->container_hdl = container_hash->picl_hdl;
4680Sstevel@tonic-gate 	if (container_hash->u.cont_node->section_list == NULL) {
4690Sstevel@tonic-gate 		container_hash->u.cont_node->section_list = sect_hash;
4700Sstevel@tonic-gate 		return;
4710Sstevel@tonic-gate 	}
4720Sstevel@tonic-gate 
4730Sstevel@tonic-gate 	for (next_hash = container_hash->u.cont_node->section_list;
474*9407SMichael.Bergknoff@Sun.COM 	    next_hash->u.sec_node->next != NULL;
475*9407SMichael.Bergknoff@Sun.COM 	    next_hash = next_hash->u.sec_node->next) {
4760Sstevel@tonic-gate 		;
4770Sstevel@tonic-gate 	}
4780Sstevel@tonic-gate 
4790Sstevel@tonic-gate 	next_hash->u.sec_node->next = sect_hash;
4800Sstevel@tonic-gate }
4810Sstevel@tonic-gate 
4820Sstevel@tonic-gate /* add new segment hash object to the existing list */
4830Sstevel@tonic-gate 
4840Sstevel@tonic-gate static void
add_to_segment_list(hash_obj_t * parent_obj,hash_obj_t * child_obj)4850Sstevel@tonic-gate add_to_segment_list(hash_obj_t *parent_obj, hash_obj_t *child_obj)
4860Sstevel@tonic-gate {
4870Sstevel@tonic-gate 	hash_obj_t	*next_hash;
4880Sstevel@tonic-gate 
4890Sstevel@tonic-gate 	child_obj->u.seg_node->sec_nodehdl = parent_obj->picl_hdl;
4900Sstevel@tonic-gate 	if (parent_obj->u.sec_node->segment_list == NULL) {
4910Sstevel@tonic-gate 		parent_obj->u.sec_node->segment_list = child_obj;
4920Sstevel@tonic-gate 		return;
4930Sstevel@tonic-gate 	}
4940Sstevel@tonic-gate 
4950Sstevel@tonic-gate 	for (next_hash = parent_obj->u.sec_node->segment_list;
496*9407SMichael.Bergknoff@Sun.COM 	    next_hash->u.seg_node->next != NULL;
497*9407SMichael.Bergknoff@Sun.COM 	    next_hash = next_hash->u.seg_node->next) {
4980Sstevel@tonic-gate 		;
4990Sstevel@tonic-gate 	}
5000Sstevel@tonic-gate 	next_hash->u.seg_node->next = child_obj;
5010Sstevel@tonic-gate }
5020Sstevel@tonic-gate 
5030Sstevel@tonic-gate /*
5040Sstevel@tonic-gate  * called to add packet node object to the existing packet list.
5050Sstevel@tonic-gate  */
5060Sstevel@tonic-gate static void
add_to_packet_list(hash_obj_t * parent_obj,hash_obj_t * child_obj)5070Sstevel@tonic-gate add_to_packet_list(hash_obj_t *parent_obj, hash_obj_t *child_obj)
5080Sstevel@tonic-gate {
5090Sstevel@tonic-gate 	hash_obj_t	*next_hash;
5100Sstevel@tonic-gate 
5110Sstevel@tonic-gate 	if (parent_obj->u.seg_node->packet_list == NULL) {
5120Sstevel@tonic-gate 		parent_obj->u.seg_node->packet_list = child_obj;
5130Sstevel@tonic-gate 		return;
5140Sstevel@tonic-gate 	}
5150Sstevel@tonic-gate 
5160Sstevel@tonic-gate 	for (next_hash = parent_obj->u.seg_node->packet_list;
517*9407SMichael.Bergknoff@Sun.COM 	    next_hash->u.pkt_node->next != NULL;
518*9407SMichael.Bergknoff@Sun.COM 	    next_hash = next_hash->u.pkt_node->next) {
5190Sstevel@tonic-gate 		;
5200Sstevel@tonic-gate 	}
5210Sstevel@tonic-gate 	next_hash->u.pkt_node->next = child_obj;
5220Sstevel@tonic-gate }
5230Sstevel@tonic-gate 
5240Sstevel@tonic-gate /*
5250Sstevel@tonic-gate  * free the packet hash list.
5260Sstevel@tonic-gate  */
5270Sstevel@tonic-gate 
5280Sstevel@tonic-gate static void
free_packet_list(hash_obj_t * hash_obj,container_tbl_t * cont_tbl)5290Sstevel@tonic-gate free_packet_list(hash_obj_t	*hash_obj, container_tbl_t *cont_tbl)
5300Sstevel@tonic-gate {
5310Sstevel@tonic-gate 	hash_obj_t	*next_obj;
5320Sstevel@tonic-gate 	hash_obj_t	*free_obj;
5330Sstevel@tonic-gate 
5340Sstevel@tonic-gate 	/* packet hash object list */
5350Sstevel@tonic-gate 	next_obj = hash_obj->u.seg_node->packet_list;
5360Sstevel@tonic-gate 	while (next_obj != NULL) {
5370Sstevel@tonic-gate 		free_obj = next_obj;
5380Sstevel@tonic-gate 		next_obj = next_obj->u.pkt_node->next;
5390Sstevel@tonic-gate 		if (free_obj->prev == NULL) { /* first node object */
5400Sstevel@tonic-gate 			cont_tbl->hash_obj[(free_obj->picl_hdl %
541*9407SMichael.Bergknoff@Sun.COM 			    TABLE_SIZE)].next = free_obj->next;
5420Sstevel@tonic-gate 			if (free_obj->next != NULL) {
5430Sstevel@tonic-gate 				free_obj->next->prev = NULL;
5440Sstevel@tonic-gate 			}
5450Sstevel@tonic-gate 		} else {
5460Sstevel@tonic-gate 			free_obj->prev->next = free_obj->next;
5470Sstevel@tonic-gate 			if (free_obj->next != NULL) {
5480Sstevel@tonic-gate 				free_obj->next->prev = free_obj->prev;
5490Sstevel@tonic-gate 			}
5500Sstevel@tonic-gate 		}
5510Sstevel@tonic-gate 
5520Sstevel@tonic-gate 		free(free_obj->u.pkt_node);
5530Sstevel@tonic-gate 		free(free_obj);
5540Sstevel@tonic-gate 	}
5550Sstevel@tonic-gate 	hash_obj->u.seg_node->packet_list = NULL;
5560Sstevel@tonic-gate }
5570Sstevel@tonic-gate 
5580Sstevel@tonic-gate /*
5590Sstevel@tonic-gate  * free the segment hash node object.
5600Sstevel@tonic-gate  */
5610Sstevel@tonic-gate 
5620Sstevel@tonic-gate static void
free_segment_node(hash_obj_t * hash_obj,picl_nodehdl_t nodehdl,container_tbl_t * cont_tbl)5630Sstevel@tonic-gate free_segment_node(hash_obj_t *hash_obj, picl_nodehdl_t nodehdl,
5640Sstevel@tonic-gate 					container_tbl_t *cont_tbl)
5650Sstevel@tonic-gate {
5660Sstevel@tonic-gate 	hash_obj_t	*prev_hash_obj;
5670Sstevel@tonic-gate 	hash_obj_t	*next_obj;
5680Sstevel@tonic-gate 
5690Sstevel@tonic-gate 	/* segment hash object list */
5700Sstevel@tonic-gate 	next_obj = hash_obj->u.sec_node->segment_list;
5710Sstevel@tonic-gate 	if (next_obj == NULL) {
5720Sstevel@tonic-gate 		return;
5730Sstevel@tonic-gate 	}
5740Sstevel@tonic-gate 
5750Sstevel@tonic-gate 	/* find the segment hash from the segment list to be deleted. */
5760Sstevel@tonic-gate 	if (next_obj->picl_hdl == nodehdl) {
5770Sstevel@tonic-gate 		hash_obj->u.sec_node->segment_list =
578*9407SMichael.Bergknoff@Sun.COM 		    next_obj->u.seg_node->next;
5790Sstevel@tonic-gate 	} else {
5800Sstevel@tonic-gate 		while (next_obj != NULL) {
5810Sstevel@tonic-gate 			if (next_obj->picl_hdl != nodehdl) {
5820Sstevel@tonic-gate 				prev_hash_obj = next_obj;
5830Sstevel@tonic-gate 				next_obj = next_obj->u.seg_node->next;
5840Sstevel@tonic-gate 			} else {
5850Sstevel@tonic-gate 				prev_hash_obj->u.seg_node->next =
586*9407SMichael.Bergknoff@Sun.COM 				    next_obj->u.seg_node->next;
5870Sstevel@tonic-gate 				break;
5880Sstevel@tonic-gate 			}
5890Sstevel@tonic-gate 		}
5900Sstevel@tonic-gate 
5910Sstevel@tonic-gate 		if (next_obj == NULL) {
5920Sstevel@tonic-gate 			return;
5930Sstevel@tonic-gate 		}
5940Sstevel@tonic-gate 
5950Sstevel@tonic-gate 	}
5960Sstevel@tonic-gate 
5970Sstevel@tonic-gate 	if (next_obj->prev == NULL) {
5980Sstevel@tonic-gate 		cont_tbl->hash_obj[(next_obj->picl_hdl % TABLE_SIZE)].next =
599*9407SMichael.Bergknoff@Sun.COM 		    next_obj->next;
6000Sstevel@tonic-gate 		if (next_obj->next != NULL)
6010Sstevel@tonic-gate 			next_obj->next->prev = NULL;
6020Sstevel@tonic-gate 	} else {
6030Sstevel@tonic-gate 		next_obj->prev->next = next_obj->next;
6040Sstevel@tonic-gate 		if (next_obj->next != NULL) {
6050Sstevel@tonic-gate 			next_obj->next->prev = next_obj->prev;
6060Sstevel@tonic-gate 		}
6070Sstevel@tonic-gate 	}
6080Sstevel@tonic-gate 
6090Sstevel@tonic-gate 	free_packet_list(next_obj, cont_tbl);
6100Sstevel@tonic-gate 	free(next_obj->u.seg_node);
6110Sstevel@tonic-gate 	free(next_obj);
6120Sstevel@tonic-gate }
6130Sstevel@tonic-gate 
6140Sstevel@tonic-gate 
6150Sstevel@tonic-gate /*
6160Sstevel@tonic-gate  * Description : frudata_delete_segment is called when volatile property
6170Sstevel@tonic-gate  *              delete_segment under class segment is accessed.
6180Sstevel@tonic-gate  *
6190Sstevel@tonic-gate  * Arguments   : ptree_warg_t is holds node handle of segment node and property
6200Sstevel@tonic-gate  *              handle of delete_segment property.
6210Sstevel@tonic-gate  */
6220Sstevel@tonic-gate 
6230Sstevel@tonic-gate /* ARGSUSED */
6240Sstevel@tonic-gate static int
frudata_delete_segment(ptree_warg_t * warg,const void * buf)6250Sstevel@tonic-gate frudata_delete_segment(ptree_warg_t *warg, const void *buf)
6260Sstevel@tonic-gate {
6270Sstevel@tonic-gate 	int		retval;
6280Sstevel@tonic-gate 	int		num_of_segment;
6290Sstevel@tonic-gate 	int		num_of_pkt;
6300Sstevel@tonic-gate 	int		pkt_cnt;
6310Sstevel@tonic-gate 	int		count;
6320Sstevel@tonic-gate 	packet_t	*pkt_buf;
6330Sstevel@tonic-gate 	segment_t	*seg_buffer;
6340Sstevel@tonic-gate 	hash_obj_t	*seg_hash;
6350Sstevel@tonic-gate 	hash_obj_t	*pkt_hash;
6360Sstevel@tonic-gate 	hash_obj_t	*hash_obj;
6370Sstevel@tonic-gate 	fru_segdesc_t	*desc;
6380Sstevel@tonic-gate 	picl_nodehdl_t	sec_nodehdl;
6390Sstevel@tonic-gate 	container_tbl_t	*cont_tbl;
6400Sstevel@tonic-gate 	fru_access_hdl_t seg_acc_hdl;
6410Sstevel@tonic-gate 	fru_access_hdl_t new_sec_acc_hdl;
6420Sstevel@tonic-gate 
6430Sstevel@tonic-gate 	cont_tbl = lock_container_lock(warg->nodeh, SEGMENT_NODE, PICL_WRITE);
6440Sstevel@tonic-gate 	if (!cont_tbl) {
6450Sstevel@tonic-gate 		return (PICL_FAILURE);
6460Sstevel@tonic-gate 	}
6470Sstevel@tonic-gate 
6480Sstevel@tonic-gate 	/* segment hash */
6490Sstevel@tonic-gate 	hash_obj = lookup_node_object(warg->nodeh, SEGMENT_NODE, cont_tbl);
6500Sstevel@tonic-gate 	if (hash_obj == NULL) {
6510Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
6520Sstevel@tonic-gate 		return (PICL_FAILURE);
6530Sstevel@tonic-gate 	}
6540Sstevel@tonic-gate 
6550Sstevel@tonic-gate 	/* fruaccess segment handle */
6560Sstevel@tonic-gate 	seg_acc_hdl	= hash_obj->u.seg_node->segment_hdl;
6570Sstevel@tonic-gate 
6580Sstevel@tonic-gate 	/* call fruaccess to get new section handle */
6590Sstevel@tonic-gate 	if (fru_delete_segment(seg_acc_hdl, &new_sec_acc_hdl, &warg->cred)
660*9407SMichael.Bergknoff@Sun.COM 	    == -1) {
6610Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
6620Sstevel@tonic-gate 		return (map_access_err(errno));
6630Sstevel@tonic-gate 	}
6640Sstevel@tonic-gate 
6650Sstevel@tonic-gate 	if (ptree_delete_node(warg->nodeh) != PICL_SUCCESS) {
6660Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
6670Sstevel@tonic-gate 		return (PICL_FAILURE);
6680Sstevel@tonic-gate 	}
6690Sstevel@tonic-gate 
6700Sstevel@tonic-gate 	if (ptree_destroy_node(warg->nodeh) != PICL_SUCCESS) {
6710Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
6720Sstevel@tonic-gate 		return (PICL_FAILURE);
6730Sstevel@tonic-gate 	}
6740Sstevel@tonic-gate 
6750Sstevel@tonic-gate 
6760Sstevel@tonic-gate 	/* get section node handle */
6770Sstevel@tonic-gate 	sec_nodehdl = hash_obj->u.seg_node->sec_nodehdl;
6780Sstevel@tonic-gate 	/* get section hash */
6790Sstevel@tonic-gate 	hash_obj = lookup_node_object(sec_nodehdl, SECTION_NODE, cont_tbl);
6800Sstevel@tonic-gate 	if (hash_obj == NULL) {
6810Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
6820Sstevel@tonic-gate 		return (PICL_FAILURE);
6830Sstevel@tonic-gate 	}
6840Sstevel@tonic-gate 
6850Sstevel@tonic-gate 	free_segment_node(hash_obj, warg->nodeh, cont_tbl);
6860Sstevel@tonic-gate 
6870Sstevel@tonic-gate 	hash_obj->u.sec_node->num_of_segment = 0;
6880Sstevel@tonic-gate 
6890Sstevel@tonic-gate 	/* call fruaccess with new section handle */
6900Sstevel@tonic-gate 	num_of_segment = fru_get_num_segments(new_sec_acc_hdl, &warg->cred);
6910Sstevel@tonic-gate 	if (num_of_segment <= 0) {
6920Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
6930Sstevel@tonic-gate 		return (PICL_SUCCESS);
6940Sstevel@tonic-gate 	}
6950Sstevel@tonic-gate 
6960Sstevel@tonic-gate 	seg_buffer = alloca(sizeof (segment_t) * num_of_segment);
6970Sstevel@tonic-gate 	if (seg_buffer == NULL) {
6980Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
6990Sstevel@tonic-gate 		return (PICL_FAILURE);
7000Sstevel@tonic-gate 	}
7010Sstevel@tonic-gate 
7020Sstevel@tonic-gate 	/* get all the segments */
7030Sstevel@tonic-gate 	retval = fru_get_segments(new_sec_acc_hdl, seg_buffer,
704*9407SMichael.Bergknoff@Sun.COM 	    num_of_segment, &warg->cred);
7050Sstevel@tonic-gate 	if (retval == -1) {
7060Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
7070Sstevel@tonic-gate 		return (PICL_FAILURE);
7080Sstevel@tonic-gate 	}
7090Sstevel@tonic-gate 
7100Sstevel@tonic-gate 	seg_hash = hash_obj->u.sec_node->segment_list;
7110Sstevel@tonic-gate 	if (seg_hash == NULL) {
7120Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
7130Sstevel@tonic-gate 		return (PICL_SUCCESS);
7140Sstevel@tonic-gate 	}
7150Sstevel@tonic-gate 
7160Sstevel@tonic-gate 	/* rebuild the segment list */
7170Sstevel@tonic-gate 	for (count = 0; count < num_of_segment; count++) {
7180Sstevel@tonic-gate 		desc	= (fru_segdesc_t *)&seg_buffer[count].descriptor;
7190Sstevel@tonic-gate 		if (!(desc->field.field_perm & SEGMENT_READ)) {
7201158Sps154918 			seg_hash = seg_hash->u.seg_node->next;
7210Sstevel@tonic-gate 			continue;
7220Sstevel@tonic-gate 		}
7230Sstevel@tonic-gate 
7240Sstevel@tonic-gate 		if (desc->field.opaque) {
7251158Sps154918 			seg_hash = seg_hash->u.seg_node->next;
7260Sstevel@tonic-gate 			continue;
7270Sstevel@tonic-gate 		}
7280Sstevel@tonic-gate 
7290Sstevel@tonic-gate 		hash_obj->u.sec_node->num_of_segment++;
7300Sstevel@tonic-gate 
7310Sstevel@tonic-gate 		seg_hash->u.seg_node->segment_hdl = seg_buffer[count].handle;
7320Sstevel@tonic-gate 
733*9407SMichael.Bergknoff@Sun.COM 		num_of_pkt = fru_get_num_packets(seg_buffer[count].handle,
734*9407SMichael.Bergknoff@Sun.COM 		    &warg->cred);
7350Sstevel@tonic-gate 		if (num_of_pkt <= 0) {
7361158Sps154918 			seg_hash = seg_hash->u.seg_node->next;
7370Sstevel@tonic-gate 			continue;
7380Sstevel@tonic-gate 		}
7390Sstevel@tonic-gate 
7400Sstevel@tonic-gate 		pkt_buf	= alloca(sizeof (packet_t) * num_of_pkt);
7410Sstevel@tonic-gate 		if (pkt_buf == NULL) {
7420Sstevel@tonic-gate 			unlock_container_lock(cont_tbl);
7430Sstevel@tonic-gate 			return (PICL_FAILURE);
7440Sstevel@tonic-gate 		}
7450Sstevel@tonic-gate 
7460Sstevel@tonic-gate 		retval = fru_get_packets(seg_buffer[count].handle, pkt_buf,
747*9407SMichael.Bergknoff@Sun.COM 		    num_of_pkt, &warg->cred);
7480Sstevel@tonic-gate 		if (retval == -1) {
7491158Sps154918 			seg_hash = seg_hash->u.seg_node->next;
7500Sstevel@tonic-gate 			continue;
7510Sstevel@tonic-gate 		}
7520Sstevel@tonic-gate 
7530Sstevel@tonic-gate 		pkt_hash = seg_hash->u.seg_node->packet_list;
7540Sstevel@tonic-gate 		if (pkt_hash == NULL) {
7551158Sps154918 			seg_hash = seg_hash->u.seg_node->next;
7560Sstevel@tonic-gate 			continue;
7570Sstevel@tonic-gate 		}
7580Sstevel@tonic-gate 
7590Sstevel@tonic-gate 		/* rebuild the packet list */
7600Sstevel@tonic-gate 		for (pkt_cnt = 0; pkt_cnt < num_of_pkt; pkt_cnt++) {
7610Sstevel@tonic-gate 			pkt_hash->u.pkt_node->pkt_handle =
762*9407SMichael.Bergknoff@Sun.COM 			    pkt_buf[pkt_cnt].handle;
7630Sstevel@tonic-gate 			pkt_hash = pkt_hash->u.pkt_node->next;
7640Sstevel@tonic-gate 		}
7650Sstevel@tonic-gate 
7660Sstevel@tonic-gate 		seg_hash = seg_hash->u.seg_node->next;
7670Sstevel@tonic-gate 		if (seg_hash == NULL) {
7680Sstevel@tonic-gate 			break;
7690Sstevel@tonic-gate 		}
7700Sstevel@tonic-gate 	}
7710Sstevel@tonic-gate 
7720Sstevel@tonic-gate 	/* updated with new section handle */
7730Sstevel@tonic-gate 	hash_obj->u.sec_node->section_hdl = new_sec_acc_hdl;
7740Sstevel@tonic-gate 
7750Sstevel@tonic-gate 	unlock_container_lock(cont_tbl);
7760Sstevel@tonic-gate 
7770Sstevel@tonic-gate 	return (PICL_SUCCESS);
7780Sstevel@tonic-gate }
7790Sstevel@tonic-gate 
7800Sstevel@tonic-gate /*
7810Sstevel@tonic-gate  * Description : frudata_read_payload is called when volatile property
7820Sstevel@tonic-gate  *              payload is read.
7830Sstevel@tonic-gate  *
7840Sstevel@tonic-gate  * Arguments    : ptree_rarg_t  holds node handle of the table property.
7850Sstevel@tonic-gate  *              and property handle of the payload cell.
7860Sstevel@tonic-gate  *              p_buf contains payload data when function returns.
7870Sstevel@tonic-gate  *
7880Sstevel@tonic-gate  * Returns      : PICL_SUCCESS on success.
7890Sstevel@tonic-gate  *              PICL_FAILURE on failure.
7900Sstevel@tonic-gate  */
7910Sstevel@tonic-gate 
7920Sstevel@tonic-gate static int
frudata_read_payload(ptree_rarg_t * rarg,void * buf)7930Sstevel@tonic-gate frudata_read_payload(ptree_rarg_t *rarg, void *buf)
7940Sstevel@tonic-gate {
7950Sstevel@tonic-gate 	int		num_bytes;
7960Sstevel@tonic-gate 	hash_obj_t	*hash_obj;
7970Sstevel@tonic-gate 	fru_access_hdl_t pkt_acc_hdl;
7980Sstevel@tonic-gate 	container_tbl_t	*cont_tbl;
7990Sstevel@tonic-gate 
8000Sstevel@tonic-gate 
8010Sstevel@tonic-gate 	cont_tbl = lock_container_lock(rarg->nodeh, SEGMENT_NODE, PICL_READ);
8020Sstevel@tonic-gate 	if (!cont_tbl) {
8030Sstevel@tonic-gate 		return (PICL_FAILURE);
8040Sstevel@tonic-gate 	}
8050Sstevel@tonic-gate 
8060Sstevel@tonic-gate 	hash_obj = lookup_node_object(rarg->proph, PACKET_NODE, cont_tbl);
8070Sstevel@tonic-gate 	if (hash_obj == NULL) {
8080Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
8090Sstevel@tonic-gate 		return (PICL_FAILURE);
8100Sstevel@tonic-gate 	}
8110Sstevel@tonic-gate 
8120Sstevel@tonic-gate 	pkt_acc_hdl = hash_obj->u.pkt_node->pkt_handle;
8130Sstevel@tonic-gate 
8140Sstevel@tonic-gate 	num_bytes = fru_get_payload(pkt_acc_hdl, buf,
815*9407SMichael.Bergknoff@Sun.COM 	    hash_obj->u.pkt_node->paylen, &rarg->cred);
8160Sstevel@tonic-gate 	if (num_bytes != hash_obj->u.pkt_node->paylen) {
8170Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
8180Sstevel@tonic-gate 		return (PICL_FAILURE);
8190Sstevel@tonic-gate 	}
8200Sstevel@tonic-gate 
8210Sstevel@tonic-gate 	unlock_container_lock(cont_tbl);
8220Sstevel@tonic-gate 
8230Sstevel@tonic-gate 	return (PICL_SUCCESS);
8240Sstevel@tonic-gate }
8250Sstevel@tonic-gate 
8260Sstevel@tonic-gate /*
8270Sstevel@tonic-gate  * Description : frudata_write_payload is called when payload property cell
8280Sstevel@tonic-gate  *              is accessed.
8290Sstevel@tonic-gate  *
8300Sstevel@tonic-gate  * Arguments    : ptree_warg_t holds node handle of the packet-table.
8310Sstevel@tonic-gate  *              and property handle of the payload cell.
8320Sstevel@tonic-gate  *              p_buf contains payload data.
8330Sstevel@tonic-gate  *
8340Sstevel@tonic-gate  * Returns      : PICL_SUCCESS on success.
8350Sstevel@tonic-gate  *
8360Sstevel@tonic-gate  */
8370Sstevel@tonic-gate 
8380Sstevel@tonic-gate static int
frudata_write_payload(ptree_warg_t * warg,const void * buf)8390Sstevel@tonic-gate frudata_write_payload(ptree_warg_t *warg, const void *buf)
8400Sstevel@tonic-gate {
8410Sstevel@tonic-gate 	int		retval;
8420Sstevel@tonic-gate 	hash_obj_t	*hash_obj;
8430Sstevel@tonic-gate 	fru_access_hdl_t pkt_acc_hdl;
8440Sstevel@tonic-gate 	container_tbl_t	*cont_tbl;
8450Sstevel@tonic-gate 
8460Sstevel@tonic-gate 	cont_tbl = lock_container_lock(warg->nodeh, SEGMENT_NODE, PICL_WRITE);
8470Sstevel@tonic-gate 	if (!cont_tbl) {
8480Sstevel@tonic-gate 		return (PICL_FAILURE);
8490Sstevel@tonic-gate 	}
8500Sstevel@tonic-gate 
8510Sstevel@tonic-gate 	hash_obj = lookup_node_object(warg->proph, PACKET_NODE, cont_tbl);
8520Sstevel@tonic-gate 	if (hash_obj == NULL) {
8530Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
8540Sstevel@tonic-gate 		return (PICL_FAILURE);
8550Sstevel@tonic-gate 	}
8560Sstevel@tonic-gate 
8570Sstevel@tonic-gate 	pkt_acc_hdl = hash_obj->u.pkt_node->pkt_handle;
8580Sstevel@tonic-gate 
8590Sstevel@tonic-gate 	retval = fru_update_payload(pkt_acc_hdl, buf,
860*9407SMichael.Bergknoff@Sun.COM 	    hash_obj->u.pkt_node->paylen,
861*9407SMichael.Bergknoff@Sun.COM 	    &pkt_acc_hdl, &warg->cred);
8620Sstevel@tonic-gate 	if (retval == -1) {
8630Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
8640Sstevel@tonic-gate 		return (map_access_err(errno));
8650Sstevel@tonic-gate 	}
8660Sstevel@tonic-gate 
8670Sstevel@tonic-gate 	hash_obj->u.pkt_node->pkt_handle = pkt_acc_hdl;
8680Sstevel@tonic-gate 
8690Sstevel@tonic-gate 	unlock_container_lock(cont_tbl);
8700Sstevel@tonic-gate 
8710Sstevel@tonic-gate 	return (PICL_SUCCESS);
8720Sstevel@tonic-gate }
8730Sstevel@tonic-gate 
8740Sstevel@tonic-gate /*
8750Sstevel@tonic-gate  * callback volatile function is called when tag volatile property
8760Sstevel@tonic-gate  * is accessed. this routine holds a read lock over the hash table
8770Sstevel@tonic-gate  * and do a lookup over the property handle i.e property handle of
8780Sstevel@tonic-gate  * the tag property passed in rarg parameter.
8790Sstevel@tonic-gate  * tag value is copied into the buffer (void *buf).
8800Sstevel@tonic-gate  */
8810Sstevel@tonic-gate 
8820Sstevel@tonic-gate static int
frudata_read_tag(ptree_rarg_t * rarg,void * buf)8830Sstevel@tonic-gate frudata_read_tag(ptree_rarg_t	*rarg, void *buf)
8840Sstevel@tonic-gate {
8850Sstevel@tonic-gate 	int		retval;
8860Sstevel@tonic-gate 	hash_obj_t	*hash_obj;
8870Sstevel@tonic-gate 	picl_prophdl_t	rowproph;
8880Sstevel@tonic-gate 	container_tbl_t	*cont_tbl;
8890Sstevel@tonic-gate 
8900Sstevel@tonic-gate 	cont_tbl = lock_container_lock(rarg->nodeh, SEGMENT_NODE, PICL_READ);
8910Sstevel@tonic-gate 	if (!cont_tbl) {
8920Sstevel@tonic-gate 		return (PICL_FAILURE);
8930Sstevel@tonic-gate 	}
8940Sstevel@tonic-gate 
8950Sstevel@tonic-gate 	retval = ptree_get_next_by_row(rarg->proph, &rowproph);
8960Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
8970Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
8980Sstevel@tonic-gate 		return (retval);
8990Sstevel@tonic-gate 	}
9000Sstevel@tonic-gate 
9010Sstevel@tonic-gate 	hash_obj = lookup_node_object(rowproph, PACKET_NODE, cont_tbl);
9020Sstevel@tonic-gate 	if (hash_obj == NULL) {
9030Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
9040Sstevel@tonic-gate 		return (PICL_FAILURE);
9050Sstevel@tonic-gate 	}
9060Sstevel@tonic-gate 
9070Sstevel@tonic-gate 	(void) memcpy(buf, &hash_obj->u.pkt_node->tag, sizeof (tag_t));
9080Sstevel@tonic-gate 
9090Sstevel@tonic-gate 	unlock_container_lock(cont_tbl);
9100Sstevel@tonic-gate 	return (PICL_SUCCESS);
9110Sstevel@tonic-gate }
9120Sstevel@tonic-gate 
9130Sstevel@tonic-gate 
9140Sstevel@tonic-gate /*
9150Sstevel@tonic-gate  * Description : create_packet_table() is called by fru_delete_packet_row(),
9160Sstevel@tonic-gate  *              to create a packet-table volatile property. it's called after
9170Sstevel@tonic-gate  *              deleting the packet-table. fru_delete_packet_row() calls
9180Sstevel@tonic-gate  *              frudata_read_packet_table() to add rows into the table.
9190Sstevel@tonic-gate  */
9200Sstevel@tonic-gate 
9210Sstevel@tonic-gate static int
create_packet_table(picl_nodehdl_t seghdl,picl_prophdl_t * thdl)9220Sstevel@tonic-gate create_packet_table(picl_nodehdl_t seghdl, picl_prophdl_t *thdl)
9230Sstevel@tonic-gate {
9240Sstevel@tonic-gate 	int			retval;
9250Sstevel@tonic-gate 	picl_prophdl_t		tblhdl;
9260Sstevel@tonic-gate 	picl_nodehdl_t		prophdl;
9270Sstevel@tonic-gate 	ptree_propinfo_t	prop;
9280Sstevel@tonic-gate 
9290Sstevel@tonic-gate 	retval = ptree_create_table(&tblhdl);
9300Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
9310Sstevel@tonic-gate 		return (retval);
9320Sstevel@tonic-gate 	}
9330Sstevel@tonic-gate 
9340Sstevel@tonic-gate 	prop.version = PTREE_PROPINFO_VERSION;
9350Sstevel@tonic-gate 	prop.piclinfo.type =  PICL_PTYPE_TABLE;
9360Sstevel@tonic-gate 	prop.piclinfo.accessmode = PICL_READ|PICL_WRITE;
9370Sstevel@tonic-gate 	prop.piclinfo.size = sizeof (picl_prophdl_t);
9380Sstevel@tonic-gate 	prop.read = NULL;
9390Sstevel@tonic-gate 	prop.write = NULL;
9400Sstevel@tonic-gate 	(void) strcpy(prop.piclinfo.name, PICL_PROP_PACKET_TABLE);
9410Sstevel@tonic-gate 
9420Sstevel@tonic-gate 	retval = ptree_create_and_add_prop(seghdl, &prop, &tblhdl,
943*9407SMichael.Bergknoff@Sun.COM 	    &prophdl);
9440Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
9450Sstevel@tonic-gate 		return (retval);
9460Sstevel@tonic-gate 	}
9470Sstevel@tonic-gate 
9480Sstevel@tonic-gate 	/* hold the table handle */
9490Sstevel@tonic-gate 	*thdl = tblhdl;
9500Sstevel@tonic-gate 
9510Sstevel@tonic-gate 	return (PICL_SUCCESS);
9520Sstevel@tonic-gate }
9530Sstevel@tonic-gate 
9540Sstevel@tonic-gate /*
9550Sstevel@tonic-gate  * Description : frudata_delete_packet is called when write operation is
9560Sstevel@tonic-gate  *		performed on tag volatile property.
9570Sstevel@tonic-gate  *
9580Sstevel@tonic-gate  *
9590Sstevel@tonic-gate  * Arguments    : ptree_warg_t holds node handle to the segment node.
9600Sstevel@tonic-gate  *              and property handle of the tag cell in the packet table to be
9610Sstevel@tonic-gate  *		deleted.
9620Sstevel@tonic-gate  *              buf contains the tag data + plus DELETE_KEY_TAG
9630Sstevel@tonic-gate  *
9640Sstevel@tonic-gate  * Returns      : PICL_SUCCESS on success
9650Sstevel@tonic-gate  *
9660Sstevel@tonic-gate  */
9670Sstevel@tonic-gate 
9680Sstevel@tonic-gate static int
frudata_delete_packet(ptree_warg_t * warg,const void * buf)9690Sstevel@tonic-gate frudata_delete_packet(ptree_warg_t *warg, const void *buf)
9700Sstevel@tonic-gate {
9710Sstevel@tonic-gate 	int		count = 0;
9720Sstevel@tonic-gate 	int		retval;
9730Sstevel@tonic-gate 	int		num_of_pkt;
9740Sstevel@tonic-gate 	uint64_t	tag;
9750Sstevel@tonic-gate 	packet_t	*packet;
9760Sstevel@tonic-gate 	hash_obj_t	*seg_hash_obj;
9770Sstevel@tonic-gate 	hash_obj_t	*pkt_hash_obj;
9780Sstevel@tonic-gate 	container_tbl_t	*cont_tbl;
9790Sstevel@tonic-gate 	picl_prophdl_t	tblhdl;
9800Sstevel@tonic-gate 	picl_prophdl_t	rowproph;
9810Sstevel@tonic-gate 	fru_access_hdl_t new_seg_acc_hdl;
9820Sstevel@tonic-gate 
9830Sstevel@tonic-gate 	cont_tbl = lock_container_lock(warg->nodeh, SEGMENT_NODE, PICL_WRITE);
9840Sstevel@tonic-gate 	if (!cont_tbl) {
9850Sstevel@tonic-gate 		return (PICL_FAILURE);
9860Sstevel@tonic-gate 	}
9870Sstevel@tonic-gate 
9880Sstevel@tonic-gate 	/* get the payload property handle */
9890Sstevel@tonic-gate 	retval = ptree_get_next_by_row(warg->proph, &rowproph);
9900Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
9910Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
9920Sstevel@tonic-gate 		return (retval);
9930Sstevel@tonic-gate 	}
9940Sstevel@tonic-gate 
9950Sstevel@tonic-gate 	/* do lookup on payload property handle */
9960Sstevel@tonic-gate 	pkt_hash_obj = lookup_node_object(rowproph, PACKET_NODE, cont_tbl);
9970Sstevel@tonic-gate 	if (pkt_hash_obj == NULL) {
9980Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
9990Sstevel@tonic-gate 		return (PICL_FAILURE);
10000Sstevel@tonic-gate 	}
10010Sstevel@tonic-gate 
10020Sstevel@tonic-gate 	/* verify the tag */
10030Sstevel@tonic-gate 	tag = pkt_hash_obj->u.pkt_node->tag.raw_data;
10040Sstevel@tonic-gate 	tag &= FRUDATA_DELETE_TAG_MASK;
10050Sstevel@tonic-gate 	tag |= FRUDATA_DELETE_TAG_KEY;
10060Sstevel@tonic-gate 	if (*(uint64_t *)buf != tag) {
10070Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
10080Sstevel@tonic-gate 		return (PICL_FAILURE);
10090Sstevel@tonic-gate 	}
10100Sstevel@tonic-gate 
10110Sstevel@tonic-gate 	/* call fruaccess module */
10120Sstevel@tonic-gate 	retval = fru_delete_packet(pkt_hash_obj->u.pkt_node->pkt_handle,
1013*9407SMichael.Bergknoff@Sun.COM 	    &new_seg_acc_hdl, &warg->cred);
10140Sstevel@tonic-gate 	if (retval == -1) {
10150Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
10160Sstevel@tonic-gate 		return (map_access_err(errno));
10170Sstevel@tonic-gate 	}
10180Sstevel@tonic-gate 
10190Sstevel@tonic-gate 	/* delete the packet table */
10200Sstevel@tonic-gate 	retval = ptree_get_prop_by_name(warg->nodeh, PICL_PROP_PACKET_TABLE,
1021*9407SMichael.Bergknoff@Sun.COM 	    &tblhdl);
10220Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
10230Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
10240Sstevel@tonic-gate 		return (retval);
10250Sstevel@tonic-gate 	}
10260Sstevel@tonic-gate 
10270Sstevel@tonic-gate 	retval = ptree_delete_prop(tblhdl);
10280Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
10290Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
10300Sstevel@tonic-gate 		return (retval);
10310Sstevel@tonic-gate 	}
10320Sstevel@tonic-gate 
10330Sstevel@tonic-gate 	retval = ptree_destroy_prop(tblhdl);
10340Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
10350Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
10360Sstevel@tonic-gate 		return (retval);
10370Sstevel@tonic-gate 	}
10380Sstevel@tonic-gate 
10390Sstevel@tonic-gate 
10400Sstevel@tonic-gate 	seg_hash_obj = lookup_node_object(warg->nodeh, SEGMENT_NODE,
1041*9407SMichael.Bergknoff@Sun.COM 	    cont_tbl);
10420Sstevel@tonic-gate 	if (seg_hash_obj == NULL) {
10430Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
10440Sstevel@tonic-gate 		return (PICL_FAILURE);
10450Sstevel@tonic-gate 	}
10460Sstevel@tonic-gate 
10470Sstevel@tonic-gate 	/* free all packet hash object */
10480Sstevel@tonic-gate 	free_packet_list(seg_hash_obj, cont_tbl);
10490Sstevel@tonic-gate 
10500Sstevel@tonic-gate 	/* recreate the packet table */
10510Sstevel@tonic-gate 	retval = create_packet_table(warg->nodeh, &tblhdl);
10520Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
10530Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
10540Sstevel@tonic-gate 		return (retval);
10550Sstevel@tonic-gate 	}
10560Sstevel@tonic-gate 
10570Sstevel@tonic-gate 	seg_hash_obj->u.seg_node->segment_hdl = new_seg_acc_hdl;
10580Sstevel@tonic-gate 
10590Sstevel@tonic-gate 	seg_hash_obj->u.seg_node->num_of_pkt = 0;
10600Sstevel@tonic-gate 
10610Sstevel@tonic-gate 	num_of_pkt = fru_get_num_packets(new_seg_acc_hdl, &warg->cred);
10620Sstevel@tonic-gate 	if (num_of_pkt == -1) {
10630Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
10640Sstevel@tonic-gate 		return (PICL_FAILURE);
10650Sstevel@tonic-gate 	}
10660Sstevel@tonic-gate 
10670Sstevel@tonic-gate 	if (num_of_pkt == 0) {
10680Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
10690Sstevel@tonic-gate 		return (PICL_SUCCESS);
10700Sstevel@tonic-gate 	}
10710Sstevel@tonic-gate 
10720Sstevel@tonic-gate 	packet = alloca(sizeof (packet_t) * num_of_pkt);
10730Sstevel@tonic-gate 	if (packet == NULL) {
10740Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
10750Sstevel@tonic-gate 		return (PICL_FAILURE);
10760Sstevel@tonic-gate 	}
10770Sstevel@tonic-gate 
10780Sstevel@tonic-gate 	retval = fru_get_packets(new_seg_acc_hdl, packet,
1079*9407SMichael.Bergknoff@Sun.COM 	    num_of_pkt, &warg->cred);
10800Sstevel@tonic-gate 	if (retval == -1) {
10810Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
10820Sstevel@tonic-gate 		return (PICL_FAILURE);
10830Sstevel@tonic-gate 	}
10840Sstevel@tonic-gate 
10850Sstevel@tonic-gate 	/* rebuild the packet hash object */
10860Sstevel@tonic-gate 	for (count = 0; count < num_of_pkt; count++) {
10870Sstevel@tonic-gate 		(void) add_row_to_table(seg_hash_obj, tblhdl, packet+count,
1088*9407SMichael.Bergknoff@Sun.COM 		    cont_tbl);
10890Sstevel@tonic-gate 	}
10900Sstevel@tonic-gate 
10910Sstevel@tonic-gate 	seg_hash_obj->u.seg_node->num_of_pkt = num_of_pkt;
10920Sstevel@tonic-gate 
10930Sstevel@tonic-gate 	(void) ptree_update_propval_by_name(warg->nodeh, PICL_PROP_NUM_TAGS,
1094*9407SMichael.Bergknoff@Sun.COM 	    &num_of_pkt, sizeof (uint32_t));
10950Sstevel@tonic-gate 
10960Sstevel@tonic-gate 	unlock_container_lock(cont_tbl);
10970Sstevel@tonic-gate 
10980Sstevel@tonic-gate 	return (PICL_SUCCESS);
10990Sstevel@tonic-gate }
11000Sstevel@tonic-gate 
11010Sstevel@tonic-gate /*
11020Sstevel@tonic-gate  * called from frudata_delete_packet(), frudata_add_packet(),
11030Sstevel@tonic-gate  * frudata_read_packet() callback routine to add packet into
11040Sstevel@tonic-gate  * the packet table. it also create hash node object for each
11050Sstevel@tonic-gate  * individual packet and add the object to the packet list.
11060Sstevel@tonic-gate  */
11070Sstevel@tonic-gate 
11080Sstevel@tonic-gate static int
add_row_to_table(hash_obj_t * seg_obj,picl_nodehdl_t tblhdl,packet_t * pkt,container_tbl_t * cont_tbl)11090Sstevel@tonic-gate add_row_to_table(hash_obj_t *seg_obj, picl_nodehdl_t tblhdl, packet_t *pkt,
11100Sstevel@tonic-gate 					container_tbl_t *cont_tbl)
11110Sstevel@tonic-gate {
11120Sstevel@tonic-gate 	int			retval;
11130Sstevel@tonic-gate 	int			paylen;
11140Sstevel@tonic-gate 	size_t			tag_size;
11150Sstevel@tonic-gate 	hash_obj_t		*hash_obj;
11160Sstevel@tonic-gate 	fru_tagtype_t		tagtype;
11170Sstevel@tonic-gate 	picl_prophdl_t		prophdl[NUM_OF_COL_IN_PKT_TABLE];
11180Sstevel@tonic-gate 	ptree_propinfo_t	prop;
11190Sstevel@tonic-gate 
11200Sstevel@tonic-gate 	prop.version = PTREE_PROPINFO_VERSION;
11210Sstevel@tonic-gate 
11220Sstevel@tonic-gate 	prop.piclinfo.type =  PICL_PTYPE_BYTEARRAY;
11230Sstevel@tonic-gate 	prop.piclinfo.accessmode = PICL_READ|PICL_WRITE|PICL_VOLATILE;
11240Sstevel@tonic-gate 	prop.piclinfo.size = sizeof (fru_tag_t);
11250Sstevel@tonic-gate 	prop.read = frudata_read_tag;
11260Sstevel@tonic-gate 	prop.write = frudata_delete_packet;
11270Sstevel@tonic-gate 
11280Sstevel@tonic-gate 	/* tag property node */
11290Sstevel@tonic-gate 	(void) strcpy(prop.piclinfo.name, PICL_PROP_TAG);
11300Sstevel@tonic-gate 
11310Sstevel@tonic-gate 	paylen = get_payload_length((void *)&pkt->tag);
11320Sstevel@tonic-gate 	if (paylen < 0) {
11330Sstevel@tonic-gate 		return (PICL_FAILURE);
11340Sstevel@tonic-gate 	}
11350Sstevel@tonic-gate 
11360Sstevel@tonic-gate 	retval = ptree_create_prop(&prop, NULL, &prophdl[0]);
11370Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
11380Sstevel@tonic-gate 		return (retval);
11390Sstevel@tonic-gate 	}
11400Sstevel@tonic-gate 
11410Sstevel@tonic-gate 
11420Sstevel@tonic-gate 	/* payload property node */
11430Sstevel@tonic-gate 	prop.piclinfo.type =  PICL_PTYPE_BYTEARRAY;
11440Sstevel@tonic-gate 	prop.piclinfo.size = paylen;
11450Sstevel@tonic-gate 	(void) strcpy(prop.piclinfo.name, PICL_PROP_PAYLOAD);
11460Sstevel@tonic-gate 	prop.piclinfo.accessmode = PICL_READ|PICL_WRITE|PICL_VOLATILE;
11470Sstevel@tonic-gate 	prop.read = frudata_read_payload;
11480Sstevel@tonic-gate 	prop.write = frudata_write_payload;
11490Sstevel@tonic-gate 
11500Sstevel@tonic-gate 	retval = ptree_create_prop(&prop, NULL, &prophdl[1]);
11510Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
11520Sstevel@tonic-gate 		return (retval);
11530Sstevel@tonic-gate 	}
11540Sstevel@tonic-gate 
11550Sstevel@tonic-gate 	hash_obj = alloc_packet_node_object(prophdl[1], pkt);
11560Sstevel@tonic-gate 	if (hash_obj == NULL) {
11570Sstevel@tonic-gate 		return (PICL_FAILURE);
11580Sstevel@tonic-gate 	}
11590Sstevel@tonic-gate 
11600Sstevel@tonic-gate 	retval = ptree_add_row_to_table(tblhdl, NUM_OF_COL_IN_PKT_TABLE,
1161*9407SMichael.Bergknoff@Sun.COM 	    prophdl);
11620Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
11630Sstevel@tonic-gate 		free(hash_obj);
11640Sstevel@tonic-gate 		return (retval);
11650Sstevel@tonic-gate 	}
11660Sstevel@tonic-gate 
11670Sstevel@tonic-gate 	tagtype = get_tag_type((fru_tag_t *)&pkt->tag);
11680Sstevel@tonic-gate 	if (tagtype == -1) {
11690Sstevel@tonic-gate 		return (PICL_FAILURE);
11700Sstevel@tonic-gate 	}
11710Sstevel@tonic-gate 
11720Sstevel@tonic-gate 	tag_size = get_tag_size(tagtype);
11730Sstevel@tonic-gate 	if (tag_size == (size_t)-1) {
11740Sstevel@tonic-gate 		return (PICL_FAILURE);
11750Sstevel@tonic-gate 	}
11760Sstevel@tonic-gate 
11770Sstevel@tonic-gate 	hash_obj->u.pkt_node->paylen = paylen;
11780Sstevel@tonic-gate 	hash_obj->u.pkt_node->tag.raw_data = 0;
11790Sstevel@tonic-gate 	(void) memcpy(&hash_obj->u.pkt_node->tag, &pkt->tag, tag_size);
11800Sstevel@tonic-gate 
11810Sstevel@tonic-gate 	add_nodeobject_to_hashtable(hash_obj, cont_tbl);
11820Sstevel@tonic-gate 
11830Sstevel@tonic-gate 	add_to_packet_list(seg_obj, hash_obj);
11840Sstevel@tonic-gate 
11850Sstevel@tonic-gate 	return (PICL_SUCCESS);
11860Sstevel@tonic-gate }
11870Sstevel@tonic-gate 
11880Sstevel@tonic-gate /*
11890Sstevel@tonic-gate  * called from frudata_read_segment() callback routine. it's called after
11900Sstevel@tonic-gate  * creating the packet table under class segment. this routine reads the
11910Sstevel@tonic-gate  * segment data to get total number of packets in the segments and add
11920Sstevel@tonic-gate  * the tag and payload data into the table. it calls add_row_to_table
11930Sstevel@tonic-gate  * routine to add individual row into the packet table.
11940Sstevel@tonic-gate  */
11950Sstevel@tonic-gate 
11960Sstevel@tonic-gate static int
frudata_read_packet(picl_nodehdl_t nodeh,picl_prophdl_t * tblhdl,container_tbl_t * cont_tbl,door_cred_t * cred)11970Sstevel@tonic-gate frudata_read_packet(picl_nodehdl_t nodeh, picl_prophdl_t *tblhdl,
11980Sstevel@tonic-gate 		container_tbl_t *cont_tbl, door_cred_t *cred)
11990Sstevel@tonic-gate {
12000Sstevel@tonic-gate 	int		cnt;
12010Sstevel@tonic-gate 	int		retval;
12020Sstevel@tonic-gate 	int		num_of_pkt;
12030Sstevel@tonic-gate 	packet_t	*packet;
12040Sstevel@tonic-gate 	hash_obj_t	*hash_obj;
12050Sstevel@tonic-gate 	fru_access_hdl_t seg_acc_hdl;
12060Sstevel@tonic-gate 
12070Sstevel@tonic-gate 	hash_obj = lookup_node_object(nodeh, SEGMENT_NODE, cont_tbl);
12080Sstevel@tonic-gate 	if (hash_obj == NULL) {
12090Sstevel@tonic-gate 		return (PICL_FAILURE);
12100Sstevel@tonic-gate 	}
12110Sstevel@tonic-gate 
12120Sstevel@tonic-gate 	if (hash_obj->u.seg_node->num_of_pkt == -1) {
12130Sstevel@tonic-gate 		/* get the access handle */
12140Sstevel@tonic-gate 		seg_acc_hdl = hash_obj->u.seg_node->segment_hdl;
12150Sstevel@tonic-gate 		/* get total number of packets */
12160Sstevel@tonic-gate 		num_of_pkt = fru_get_num_packets(seg_acc_hdl, cred);
12170Sstevel@tonic-gate 		if (num_of_pkt < 0) {
12180Sstevel@tonic-gate 			hash_obj->u.seg_node->num_of_pkt = 0;
12190Sstevel@tonic-gate 			return (map_access_err(errno));
12200Sstevel@tonic-gate 		}
12210Sstevel@tonic-gate 
12220Sstevel@tonic-gate 		if (num_of_pkt == 0) {
12230Sstevel@tonic-gate 			hash_obj->u.seg_node->num_of_pkt = 0;
12240Sstevel@tonic-gate 			return (0);
12250Sstevel@tonic-gate 		}
12260Sstevel@tonic-gate 
12270Sstevel@tonic-gate 		/* allocate buffer */
12280Sstevel@tonic-gate 		packet = alloca(sizeof (packet_t) * num_of_pkt);
12290Sstevel@tonic-gate 		if (packet == NULL) {
12300Sstevel@tonic-gate 			hash_obj->u.seg_node->num_of_pkt = 0;
12310Sstevel@tonic-gate 			return (0);
12320Sstevel@tonic-gate 		}
12330Sstevel@tonic-gate 
12340Sstevel@tonic-gate 		/* get all the packet into the packet buffer */
12350Sstevel@tonic-gate 		retval = fru_get_packets(seg_acc_hdl, packet, num_of_pkt, cred);
12360Sstevel@tonic-gate 		if (retval == -1) {
12370Sstevel@tonic-gate 			return (0);
12380Sstevel@tonic-gate 		}
12390Sstevel@tonic-gate 
12400Sstevel@tonic-gate 		/* add payload and tag into the table. */
12410Sstevel@tonic-gate 		for (cnt = 0; cnt < num_of_pkt; cnt++) {
12420Sstevel@tonic-gate 			(void) add_row_to_table(hash_obj, *tblhdl, packet+cnt,
1243*9407SMichael.Bergknoff@Sun.COM 			    cont_tbl);
12440Sstevel@tonic-gate 		}
12450Sstevel@tonic-gate 
12460Sstevel@tonic-gate 		hash_obj->u.seg_node->num_of_pkt = num_of_pkt;
12470Sstevel@tonic-gate 	}
12480Sstevel@tonic-gate 	return (0);
12490Sstevel@tonic-gate }
12500Sstevel@tonic-gate 
12510Sstevel@tonic-gate 
12520Sstevel@tonic-gate /*
12530Sstevel@tonic-gate  * Description  : frudata_add_packet is called when add-packet volatile
12540Sstevel@tonic-gate  *              property is accessed.
12550Sstevel@tonic-gate  *
12560Sstevel@tonic-gate  * Arguments    : ptree_warg_t holds node handle of the segment node and
12570Sstevel@tonic-gate  *              property handle of add-packet property.
12580Sstevel@tonic-gate  *              p_buf- contains packet data to be added.
12590Sstevel@tonic-gate  *
12600Sstevel@tonic-gate  * Return       : PICL_SUCCESS on success.
12610Sstevel@tonic-gate  *
12620Sstevel@tonic-gate  */
12630Sstevel@tonic-gate 
12640Sstevel@tonic-gate /* ARGSUSED */
12650Sstevel@tonic-gate static int
frudata_add_packet(ptree_warg_t * warg,const void * buf)12660Sstevel@tonic-gate frudata_add_packet(ptree_warg_t *warg, const void *buf)
12670Sstevel@tonic-gate {
12680Sstevel@tonic-gate 	size_t		tag_size;
12690Sstevel@tonic-gate 	int		paylen;
12700Sstevel@tonic-gate 	int		retval;
12710Sstevel@tonic-gate 	int		num_of_pkt;
12720Sstevel@tonic-gate 	int		cnt;
12730Sstevel@tonic-gate 	packet_t	packet;
12740Sstevel@tonic-gate 	packet_t	*pkt_buf;
12750Sstevel@tonic-gate 	hash_obj_t	*hash_obj;
12760Sstevel@tonic-gate 	hash_obj_t	*pkt_hash;
12770Sstevel@tonic-gate 	container_tbl_t	*cont_tbl;
12780Sstevel@tonic-gate 	fru_tagtype_t	tagtype;
12790Sstevel@tonic-gate 	picl_prophdl_t	tblhdl;
12800Sstevel@tonic-gate 	fru_access_hdl_t seg_acc_hdl;
12810Sstevel@tonic-gate 	fru_access_hdl_t new_seg_acc_hdl;
12820Sstevel@tonic-gate 
12830Sstevel@tonic-gate 	cont_tbl = lock_container_lock(warg->nodeh, SEGMENT_NODE, PICL_WRITE);
12840Sstevel@tonic-gate 	if (!cont_tbl) {
12850Sstevel@tonic-gate 		return (PICL_FAILURE);
12860Sstevel@tonic-gate 	}
12870Sstevel@tonic-gate 
12880Sstevel@tonic-gate 	hash_obj = lookup_node_object(warg->nodeh, SEGMENT_NODE, cont_tbl);
12890Sstevel@tonic-gate 	if (hash_obj == NULL) {
12900Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
12910Sstevel@tonic-gate 		return (PICL_FAILURE);
12920Sstevel@tonic-gate 	}
12930Sstevel@tonic-gate 
12940Sstevel@tonic-gate 	seg_acc_hdl = hash_obj->u.seg_node->segment_hdl;
12950Sstevel@tonic-gate 
12960Sstevel@tonic-gate 	tagtype = get_tag_type((void *)buf);
12970Sstevel@tonic-gate 	if (tagtype == -1) {
12980Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
12990Sstevel@tonic-gate 		return (PICL_FAILURE);
13000Sstevel@tonic-gate 	}
13010Sstevel@tonic-gate 
13020Sstevel@tonic-gate 	tag_size = get_tag_size(tagtype);
13030Sstevel@tonic-gate 	if (tag_size == (size_t)-1) {
13040Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
13050Sstevel@tonic-gate 		return (PICL_FAILURE);
13060Sstevel@tonic-gate 	}
13070Sstevel@tonic-gate 
13080Sstevel@tonic-gate 	paylen = get_payload_length((void *)buf);
13090Sstevel@tonic-gate 	if (paylen == -1) {
13100Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
13110Sstevel@tonic-gate 		return (PICL_FAILURE);
13120Sstevel@tonic-gate 	}
13130Sstevel@tonic-gate 
13140Sstevel@tonic-gate 	packet.tag = 0;
13150Sstevel@tonic-gate 	(void) memcpy(&packet.tag, buf, tag_size);
13160Sstevel@tonic-gate 
13170Sstevel@tonic-gate 	retval = fru_append_packet(seg_acc_hdl, &packet, (char *)buf + tag_size,
1318*9407SMichael.Bergknoff@Sun.COM 	    paylen, &new_seg_acc_hdl, &warg->cred);
13190Sstevel@tonic-gate 	if (retval == -1) {
13200Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
13210Sstevel@tonic-gate 		return (map_access_err(errno));
13220Sstevel@tonic-gate 	}
13230Sstevel@tonic-gate 
13240Sstevel@tonic-gate 	retval = ptree_get_propval_by_name(warg->nodeh,
1325*9407SMichael.Bergknoff@Sun.COM 	    PICL_PROP_PACKET_TABLE, &tblhdl, sizeof (picl_prophdl_t));
13260Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
13270Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
13280Sstevel@tonic-gate 		return (retval);
13290Sstevel@tonic-gate 	}
13300Sstevel@tonic-gate 	retval = add_row_to_table(hash_obj, tblhdl, &packet, cont_tbl);
13310Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
13320Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
13330Sstevel@tonic-gate 		return (retval);
13340Sstevel@tonic-gate 	}
13350Sstevel@tonic-gate 
13360Sstevel@tonic-gate 	num_of_pkt = fru_get_num_packets(new_seg_acc_hdl, &warg->cred);
13370Sstevel@tonic-gate 	if (num_of_pkt == -1) {
13380Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
13390Sstevel@tonic-gate 		return (PICL_FAILURE);
13400Sstevel@tonic-gate 	}
13410Sstevel@tonic-gate 
13420Sstevel@tonic-gate 	pkt_buf = alloca(sizeof (packet_t) * num_of_pkt);
13430Sstevel@tonic-gate 	if (pkt_buf == NULL) {
13440Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
13450Sstevel@tonic-gate 		return (PICL_FAILURE);
13460Sstevel@tonic-gate 	}
13470Sstevel@tonic-gate 
13480Sstevel@tonic-gate 	retval = fru_get_packets(new_seg_acc_hdl, pkt_buf,
1349*9407SMichael.Bergknoff@Sun.COM 	    num_of_pkt, &warg->cred);
13500Sstevel@tonic-gate 	if (retval == -1) {
13510Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
13520Sstevel@tonic-gate 		return (PICL_FAILURE);
13530Sstevel@tonic-gate 	}
13540Sstevel@tonic-gate 
13550Sstevel@tonic-gate 	pkt_hash	= hash_obj->u.seg_node->packet_list;
13560Sstevel@tonic-gate 	if (pkt_hash == NULL) {
13570Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
13580Sstevel@tonic-gate 		return (PICL_FAILURE);
13590Sstevel@tonic-gate 	}
13600Sstevel@tonic-gate 
13610Sstevel@tonic-gate 	for (cnt = 0; cnt < num_of_pkt; cnt++) {
13620Sstevel@tonic-gate 		pkt_hash->u.pkt_node->pkt_handle = pkt_buf[cnt].handle;
13630Sstevel@tonic-gate 		pkt_hash = pkt_hash->u.pkt_node->next;
13640Sstevel@tonic-gate 	}
13650Sstevel@tonic-gate 
13660Sstevel@tonic-gate 	hash_obj->u.seg_node->num_of_pkt = num_of_pkt;
13670Sstevel@tonic-gate 
13680Sstevel@tonic-gate 	(void) ptree_update_propval_by_name(warg->nodeh, PICL_PROP_NUM_TAGS,
1369*9407SMichael.Bergknoff@Sun.COM 	    &num_of_pkt, sizeof (uint32_t));
13700Sstevel@tonic-gate 
13710Sstevel@tonic-gate 	unlock_container_lock(cont_tbl);
13720Sstevel@tonic-gate 
13730Sstevel@tonic-gate 	return (PICL_SUCCESS);
13740Sstevel@tonic-gate }
13750Sstevel@tonic-gate 
13760Sstevel@tonic-gate static void
freeup(picl_nodehdl_t nodeh)13770Sstevel@tonic-gate freeup(picl_nodehdl_t nodeh)
13780Sstevel@tonic-gate {
13790Sstevel@tonic-gate 	(void) ptree_delete_node(nodeh);
13800Sstevel@tonic-gate 	(void) ptree_destroy_node(nodeh);
13810Sstevel@tonic-gate }
13820Sstevel@tonic-gate 
13830Sstevel@tonic-gate /*
13840Sstevel@tonic-gate  * called by frudata_read_segment() and fru_data_add_segment() callback routine.
13850Sstevel@tonic-gate  * it's called to create a segment node and all it's property beneith the
13860Sstevel@tonic-gate  * segment node in the picl tree.
13870Sstevel@tonic-gate  */
13880Sstevel@tonic-gate 
13890Sstevel@tonic-gate static int
create_segment_node(hash_obj_t * sec_obj,picl_nodehdl_t sec_node,segment_t * segment,container_tbl_t * cont_tbl,door_cred_t * cred)13900Sstevel@tonic-gate create_segment_node(hash_obj_t *sec_obj, picl_nodehdl_t sec_node,
13910Sstevel@tonic-gate 	segment_t *segment, container_tbl_t *cont_tbl, door_cred_t *cred)
13920Sstevel@tonic-gate {
13930Sstevel@tonic-gate 
13940Sstevel@tonic-gate 	int			retval;
13950Sstevel@tonic-gate 	char			segname[SEG_NAME_LEN + 1];
13960Sstevel@tonic-gate 	uint32_t		numoftags = 0;
13970Sstevel@tonic-gate 	uint32_t		protection;
13980Sstevel@tonic-gate 	hash_obj_t		*hash_obj;
13990Sstevel@tonic-gate 	picl_nodehdl_t		nodehdl;
14000Sstevel@tonic-gate 	picl_prophdl_t		prophdl;
14010Sstevel@tonic-gate 	picl_nodehdl_t		tblhdl;
14020Sstevel@tonic-gate 	ptree_propinfo_t	prop;
14030Sstevel@tonic-gate 
14040Sstevel@tonic-gate 	(void) strlcpy(segname, segment->name, SEG_NAME_LEN + 1);
14050Sstevel@tonic-gate 	segname[SEG_NAME_LEN] = '\0';
14060Sstevel@tonic-gate 
14070Sstevel@tonic-gate 	if (!(isprint(segname[0]) || isprint(segname[1]))) {
14080Sstevel@tonic-gate 		return (PICL_FAILURE);
14090Sstevel@tonic-gate 	}
14100Sstevel@tonic-gate 
14110Sstevel@tonic-gate 	if (ptree_create_node(segname, PICL_CLASS_SEGMENT, &nodehdl)
1412*9407SMichael.Bergknoff@Sun.COM 	    != PICL_SUCCESS) {
14130Sstevel@tonic-gate 		return (PICL_FAILURE);
14140Sstevel@tonic-gate 	}
14150Sstevel@tonic-gate 
14160Sstevel@tonic-gate 
14170Sstevel@tonic-gate 	/* create property node */
14180Sstevel@tonic-gate 	prop.version = PTREE_PROPINFO_VERSION;
14190Sstevel@tonic-gate 	prop.piclinfo.accessmode = PICL_READ;
14200Sstevel@tonic-gate 	prop.read		= NULL;
14210Sstevel@tonic-gate 	prop.write		= NULL;
14220Sstevel@tonic-gate 
14230Sstevel@tonic-gate 	prop.piclinfo.type =  PICL_PTYPE_UNSIGNED_INT;
14240Sstevel@tonic-gate 	prop.piclinfo.size = sizeof (uint32_t);
14250Sstevel@tonic-gate 
14260Sstevel@tonic-gate 	/* descriptor property */
14270Sstevel@tonic-gate 	(void) strcpy(prop.piclinfo.name, PICL_PROP_DESCRIPTOR);
14280Sstevel@tonic-gate 	if (ptree_create_and_add_prop(nodehdl, &prop, &segment->descriptor,
1429*9407SMichael.Bergknoff@Sun.COM 	    &prophdl) != PICL_SUCCESS) {
14300Sstevel@tonic-gate 		freeup(nodehdl);
14310Sstevel@tonic-gate 		return (PICL_FAILURE);
14320Sstevel@tonic-gate 	}
14330Sstevel@tonic-gate 
14340Sstevel@tonic-gate 
14350Sstevel@tonic-gate 	/* offset property */
14360Sstevel@tonic-gate 	(void) strcpy(prop.piclinfo.name, PICL_PROP_OFFSET);
14370Sstevel@tonic-gate 	if (ptree_create_and_add_prop(nodehdl, &prop, &segment->offset,
1438*9407SMichael.Bergknoff@Sun.COM 	    &prophdl) != PICL_SUCCESS) {
14390Sstevel@tonic-gate 		freeup(nodehdl);
14400Sstevel@tonic-gate 		return (PICL_FAILURE);
14410Sstevel@tonic-gate 	}
14420Sstevel@tonic-gate 
14430Sstevel@tonic-gate 
14440Sstevel@tonic-gate 	/* length property */
14450Sstevel@tonic-gate 	(void) strcpy(prop.piclinfo.name, PICL_PROP_LENGTH);
14460Sstevel@tonic-gate 	if (ptree_create_and_add_prop(nodehdl, &prop, &segment->length,
1447*9407SMichael.Bergknoff@Sun.COM 	    &prophdl) != PICL_SUCCESS) {
14480Sstevel@tonic-gate 		freeup(nodehdl);
14490Sstevel@tonic-gate 		return (PICL_FAILURE);
14500Sstevel@tonic-gate 	}
14510Sstevel@tonic-gate 
14520Sstevel@tonic-gate 	/* Number of Tags */
14530Sstevel@tonic-gate 	(void) strcpy(prop.piclinfo.name, PICL_PROP_NUM_TAGS);
14540Sstevel@tonic-gate 	if (ptree_create_and_add_prop(nodehdl, &prop, &numoftags, &prophdl)
1455*9407SMichael.Bergknoff@Sun.COM 	    != PICL_SUCCESS) {
14560Sstevel@tonic-gate 		freeup(nodehdl);
14570Sstevel@tonic-gate 		return (PICL_FAILURE);
14580Sstevel@tonic-gate 	}
14590Sstevel@tonic-gate 
14600Sstevel@tonic-gate 	if (create_packet_table(nodehdl, &tblhdl) != PICL_SUCCESS) {
14610Sstevel@tonic-gate 		freeup(nodehdl);
14620Sstevel@tonic-gate 		return (PICL_FAILURE);
14630Sstevel@tonic-gate 	}
14640Sstevel@tonic-gate 
14650Sstevel@tonic-gate 	retval = ptree_get_propval_by_name(sec_node,
1466*9407SMichael.Bergknoff@Sun.COM 	    PICL_PROP_PROTECTED, &protection, sizeof (uint32_t));
14670Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
14680Sstevel@tonic-gate 		freeup(nodehdl);
14690Sstevel@tonic-gate 		return (PICL_FAILURE);
14700Sstevel@tonic-gate 	}
14710Sstevel@tonic-gate 
14720Sstevel@tonic-gate 	if (protection == 0) {	/* to be added only read/write section */
14730Sstevel@tonic-gate 		/* delete segment volatile property */
14740Sstevel@tonic-gate 		prop.piclinfo.type =  PICL_PTYPE_UNSIGNED_INT;
14750Sstevel@tonic-gate 		prop.piclinfo.size = sizeof (uint32_t);
14760Sstevel@tonic-gate 		prop.piclinfo.accessmode = PICL_WRITE|PICL_VOLATILE;
14770Sstevel@tonic-gate 		prop.write = frudata_delete_segment;
14780Sstevel@tonic-gate 		prop.read = frudata_read_callback;
14790Sstevel@tonic-gate 
14800Sstevel@tonic-gate 		(void) strcpy(prop.piclinfo.name, PICL_PROP_DELETE_SEGMENT);
14810Sstevel@tonic-gate 		if (ptree_create_and_add_prop(nodehdl, &prop, NULL, &prophdl)
1482*9407SMichael.Bergknoff@Sun.COM 		    != PICL_SUCCESS) {
14830Sstevel@tonic-gate 			freeup(nodehdl);
14840Sstevel@tonic-gate 			return (PICL_FAILURE);
14850Sstevel@tonic-gate 		}
14860Sstevel@tonic-gate 
14870Sstevel@tonic-gate 
14880Sstevel@tonic-gate 		/* add packet volatile property */
14890Sstevel@tonic-gate 		prop.piclinfo.type =  PICL_PTYPE_BYTEARRAY;
14900Sstevel@tonic-gate 		prop.piclinfo.size = segment->length; /* segment length */
14910Sstevel@tonic-gate 		prop.piclinfo.accessmode = PICL_READ|PICL_WRITE|PICL_VOLATILE;
14920Sstevel@tonic-gate 		prop.read = frudata_read_callback;
14930Sstevel@tonic-gate 		prop.write = frudata_add_packet;
14940Sstevel@tonic-gate 
14950Sstevel@tonic-gate 		(void) strcpy(prop.piclinfo.name, PICL_PROP_ADD_PACKET);
14960Sstevel@tonic-gate 		if (ptree_create_and_add_prop(nodehdl, &prop, NULL, &prophdl)
1497*9407SMichael.Bergknoff@Sun.COM 		    != PICL_SUCCESS) {
14980Sstevel@tonic-gate 			freeup(nodehdl);
14990Sstevel@tonic-gate 			return (PICL_FAILURE);
15000Sstevel@tonic-gate 		}
15010Sstevel@tonic-gate 	}
15020Sstevel@tonic-gate 
15030Sstevel@tonic-gate 	if (ptree_add_node(sec_node, nodehdl) != PICL_SUCCESS) {
15040Sstevel@tonic-gate 		freeup(nodehdl);
15050Sstevel@tonic-gate 		return (PICL_FAILURE);
15060Sstevel@tonic-gate 	}
15070Sstevel@tonic-gate 
15080Sstevel@tonic-gate 	hash_obj = alloc_segment_node_object(nodehdl, segment);
15090Sstevel@tonic-gate 	if (hash_obj == NULL) {
15100Sstevel@tonic-gate 		freeup(nodehdl);
15110Sstevel@tonic-gate 		return (PICL_FAILURE);
15120Sstevel@tonic-gate 	}
15130Sstevel@tonic-gate 
15140Sstevel@tonic-gate 	add_nodeobject_to_hashtable(hash_obj, cont_tbl);
15150Sstevel@tonic-gate 
15160Sstevel@tonic-gate 	add_to_segment_list(sec_obj, hash_obj);
15170Sstevel@tonic-gate 
15180Sstevel@tonic-gate 	retval = frudata_read_packet(nodehdl, &tblhdl, cont_tbl, cred);
15190Sstevel@tonic-gate 	if (retval != 0) {
15200Sstevel@tonic-gate 		return (PICL_SUCCESS);
15210Sstevel@tonic-gate 	}
15220Sstevel@tonic-gate 
15230Sstevel@tonic-gate 	(void) ptree_update_propval_by_name(nodehdl, PICL_PROP_NUM_TAGS,
1524*9407SMichael.Bergknoff@Sun.COM 	    &hash_obj->u.seg_node->num_of_pkt, sizeof (uint32_t));
15250Sstevel@tonic-gate 
15260Sstevel@tonic-gate 	return (PICL_SUCCESS);
15270Sstevel@tonic-gate }
15280Sstevel@tonic-gate 
15290Sstevel@tonic-gate /*
15300Sstevel@tonic-gate  * Description  :frudata_read_segment is called when num_segment volatile
15310Sstevel@tonic-gate  *              property is accessed.
15320Sstevel@tonic-gate  *
15330Sstevel@tonic-gate  * Arguments    : ptree_rarg_t  contains node handle of the section node.
15340Sstevel@tonic-gate  *                      and property node of num_segments.
15350Sstevel@tonic-gate  *              void * will hold number of segment.
15360Sstevel@tonic-gate  *
15370Sstevel@tonic-gate  * Returns      : PICL_SUCCESS on success.
15380Sstevel@tonic-gate  *              PICL_FAILURE on failure.
15390Sstevel@tonic-gate  */
15400Sstevel@tonic-gate 
15410Sstevel@tonic-gate static int
frudata_read_segment(ptree_rarg_t * rarg,void * buf)15420Sstevel@tonic-gate frudata_read_segment(ptree_rarg_t *rarg, void *buf)
15430Sstevel@tonic-gate {
15440Sstevel@tonic-gate 	int		num_of_segment;
15450Sstevel@tonic-gate 	int		cnt;
15460Sstevel@tonic-gate 	int		retval;
15470Sstevel@tonic-gate 	segment_t	*segment;
15480Sstevel@tonic-gate 	hash_obj_t	*hash_obj;
15490Sstevel@tonic-gate 	fru_segdesc_t	*desc;
15500Sstevel@tonic-gate 	fru_access_hdl_t sec_acc_hdl;
15510Sstevel@tonic-gate 	container_tbl_t	*cont_tbl;
15520Sstevel@tonic-gate 
15530Sstevel@tonic-gate 	cont_tbl = lock_container_lock(rarg->nodeh, SECTION_NODE, PICL_READ);
15540Sstevel@tonic-gate 	if (!cont_tbl) {
15550Sstevel@tonic-gate 		return (PICL_FAILURE);
15560Sstevel@tonic-gate 	}
15570Sstevel@tonic-gate 
15580Sstevel@tonic-gate 	hash_obj = lookup_node_object(rarg->nodeh, SECTION_NODE, cont_tbl);
15590Sstevel@tonic-gate 	if (hash_obj == NULL) {
15600Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
15610Sstevel@tonic-gate 		return (PICL_FAILURE);
15620Sstevel@tonic-gate 	}
15630Sstevel@tonic-gate 
15640Sstevel@tonic-gate 	if (hash_obj->u.sec_node->num_of_segment == -1) {
15650Sstevel@tonic-gate 		sec_acc_hdl	= hash_obj->u.sec_node->section_hdl;
15660Sstevel@tonic-gate 
15670Sstevel@tonic-gate 		hash_obj->u.sec_node->num_of_segment = 0;
15680Sstevel@tonic-gate 
15690Sstevel@tonic-gate 		num_of_segment = fru_get_num_segments(sec_acc_hdl,
1570*9407SMichael.Bergknoff@Sun.COM 		    &rarg->cred);
15710Sstevel@tonic-gate 		if (num_of_segment < 0) {
15720Sstevel@tonic-gate 			*(int *)buf = 0;
15730Sstevel@tonic-gate 			unlock_container_lock(cont_tbl);
15740Sstevel@tonic-gate 			return (PICL_FAILURE);
15750Sstevel@tonic-gate 		}
15760Sstevel@tonic-gate 
15770Sstevel@tonic-gate 		if (num_of_segment == 0) {
15780Sstevel@tonic-gate 			*(int *)buf = 0;
15790Sstevel@tonic-gate 			unlock_container_lock(cont_tbl);
15800Sstevel@tonic-gate 			return (PICL_SUCCESS);
15810Sstevel@tonic-gate 		}
15820Sstevel@tonic-gate 
15830Sstevel@tonic-gate 		segment = alloca(sizeof (segment_t) * num_of_segment);
15840Sstevel@tonic-gate 		if (segment == NULL) {
15850Sstevel@tonic-gate 			*(int *)buf = 0;
15860Sstevel@tonic-gate 			unlock_container_lock(cont_tbl);
15870Sstevel@tonic-gate 			return (PICL_SUCCESS);
15880Sstevel@tonic-gate 		}
15890Sstevel@tonic-gate 
15900Sstevel@tonic-gate 		retval = fru_get_segments(sec_acc_hdl, segment,
1591*9407SMichael.Bergknoff@Sun.COM 		    num_of_segment, &rarg->cred);
15920Sstevel@tonic-gate 		if (retval == -1) {
15930Sstevel@tonic-gate 			*(int *)buf = 0;
15940Sstevel@tonic-gate 			unlock_container_lock(cont_tbl);
15950Sstevel@tonic-gate 			return (PICL_SUCCESS);
15960Sstevel@tonic-gate 		}
15970Sstevel@tonic-gate 
15980Sstevel@tonic-gate 		for (cnt = 0; cnt < num_of_segment; cnt++) {
15990Sstevel@tonic-gate 
16000Sstevel@tonic-gate 			desc	= (fru_segdesc_t *)&segment[cnt].descriptor;
16010Sstevel@tonic-gate 			if (!(desc->field.field_perm & SEGMENT_READ)) {
16020Sstevel@tonic-gate 				continue;
16030Sstevel@tonic-gate 			}
16040Sstevel@tonic-gate 
16050Sstevel@tonic-gate 			/* if opaque segment don't create segment node */
16060Sstevel@tonic-gate 			if (desc->field.opaque) {
16070Sstevel@tonic-gate 				continue;
16080Sstevel@tonic-gate 			}
16090Sstevel@tonic-gate 			(void) create_segment_node(hash_obj, rarg->nodeh,
1610*9407SMichael.Bergknoff@Sun.COM 			    &segment[cnt], cont_tbl, &rarg->cred);
16110Sstevel@tonic-gate 			hash_obj->u.sec_node->num_of_segment++;
16120Sstevel@tonic-gate 		}
16130Sstevel@tonic-gate 	}
16140Sstevel@tonic-gate 
16150Sstevel@tonic-gate 	/* return number of segment in the section */
16160Sstevel@tonic-gate 	*(int *)buf = hash_obj->u.sec_node->num_of_segment;
16170Sstevel@tonic-gate 
16180Sstevel@tonic-gate 	unlock_container_lock(cont_tbl);
16190Sstevel@tonic-gate 
16200Sstevel@tonic-gate 	return (PICL_SUCCESS);
16210Sstevel@tonic-gate }
16220Sstevel@tonic-gate 
16230Sstevel@tonic-gate 
16240Sstevel@tonic-gate /*
16250Sstevel@tonic-gate  * Description : frudata_add_segment is called when volatile property
16260Sstevel@tonic-gate  *              add_segment under class node section is accessed.
16270Sstevel@tonic-gate  *
16280Sstevel@tonic-gate  * Arguments    : ptree_warg_t  holds node handle for the section node.
16290Sstevel@tonic-gate  *              property handle for the add_segment property.
16300Sstevel@tonic-gate  *
16310Sstevel@tonic-gate  * Returns      : PICL_SUCCESS on success.
16320Sstevel@tonic-gate  *              PICL_FAILURE on failure.
16330Sstevel@tonic-gate  */
16340Sstevel@tonic-gate 
16350Sstevel@tonic-gate static int
frudata_add_segment(ptree_warg_t * warg,const void * buf)16360Sstevel@tonic-gate frudata_add_segment(ptree_warg_t *warg, const void *buf)
16370Sstevel@tonic-gate {
16380Sstevel@tonic-gate 	int		retval;
16390Sstevel@tonic-gate 	int		cnt;
16400Sstevel@tonic-gate 	int		num_of_segment;
16410Sstevel@tonic-gate 	segment_t	*seg_buf;
16420Sstevel@tonic-gate 	segment_t	segment;
16430Sstevel@tonic-gate 	hash_obj_t	*seg_hash;
16440Sstevel@tonic-gate 	hash_obj_t	*hash_obj;
16450Sstevel@tonic-gate 	container_tbl_t	*cont_tbl;
16460Sstevel@tonic-gate 	fru_segdef_t	*seg_def;
16470Sstevel@tonic-gate 	fru_segdesc_t	*desc;
16480Sstevel@tonic-gate 	fru_access_hdl_t new_sec_acc_hdl;
16490Sstevel@tonic-gate 
16500Sstevel@tonic-gate 	seg_def	= (fru_segdef_t *)buf;
16510Sstevel@tonic-gate 
16520Sstevel@tonic-gate 	/* initialize segment_t */
16530Sstevel@tonic-gate 	segment.handle	= 0;
16540Sstevel@tonic-gate 	(void) memcpy(segment.name, seg_def->name, SEG_NAME_LEN);
16550Sstevel@tonic-gate 	segment.descriptor =  seg_def->desc.raw_data;
16560Sstevel@tonic-gate 	segment.length	= seg_def->size;	/* segment length */
16570Sstevel@tonic-gate 	segment.offset = seg_def->address;	/* segment offset */
16580Sstevel@tonic-gate 
16590Sstevel@tonic-gate 	desc    = (fru_segdesc_t *)&segment.descriptor;
16600Sstevel@tonic-gate 	if (!(desc->field.field_perm & SEGMENT_READ)) {
16610Sstevel@tonic-gate 		return (PICL_PERMDENIED);
16620Sstevel@tonic-gate 	}
16630Sstevel@tonic-gate 
16640Sstevel@tonic-gate 	cont_tbl = lock_container_lock(warg->nodeh, SECTION_NODE, PICL_WRITE);
16650Sstevel@tonic-gate 	if (!cont_tbl) {
16660Sstevel@tonic-gate 		return (PICL_FAILURE);
16670Sstevel@tonic-gate 	}
16680Sstevel@tonic-gate 
16690Sstevel@tonic-gate 	hash_obj = lookup_node_object(warg->nodeh, SECTION_NODE, cont_tbl);
16700Sstevel@tonic-gate 	if (hash_obj == NULL) {
16710Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
16720Sstevel@tonic-gate 		return (PICL_FAILURE);
16730Sstevel@tonic-gate 	}
16740Sstevel@tonic-gate 
16750Sstevel@tonic-gate 	/* call fruaccess module, get the new section handle. */
16760Sstevel@tonic-gate 	retval = fru_add_segment(hash_obj->u.sec_node->section_hdl,
1677*9407SMichael.Bergknoff@Sun.COM 	    &segment, &new_sec_acc_hdl, &warg->cred);
16780Sstevel@tonic-gate 	if (retval == -1) {
16790Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
16800Sstevel@tonic-gate 		return (map_access_err(errno));
16810Sstevel@tonic-gate 	}
16820Sstevel@tonic-gate 
16830Sstevel@tonic-gate 	/* call access module with new section handle */
16840Sstevel@tonic-gate 	num_of_segment = fru_get_num_segments(new_sec_acc_hdl, &warg->cred);
16850Sstevel@tonic-gate 
16860Sstevel@tonic-gate 	seg_buf	= alloca(sizeof (segment_t) * num_of_segment);
16870Sstevel@tonic-gate 	if (seg_buf == NULL) {
16880Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
16890Sstevel@tonic-gate 		return (PICL_FAILURE);
16900Sstevel@tonic-gate 	}
16910Sstevel@tonic-gate 
16920Sstevel@tonic-gate 	retval = fru_get_segments(new_sec_acc_hdl, seg_buf,
1693*9407SMichael.Bergknoff@Sun.COM 	    num_of_segment, &warg->cred);
16940Sstevel@tonic-gate 	if (retval ==  -1) {
16950Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
16960Sstevel@tonic-gate 		return (PICL_FAILURE);
16970Sstevel@tonic-gate 	}
16980Sstevel@tonic-gate 
16990Sstevel@tonic-gate 	segment.offset	= seg_buf[(num_of_segment -1)].offset;
17000Sstevel@tonic-gate 	segment.handle = seg_buf[(num_of_segment-1)].handle;
17010Sstevel@tonic-gate 
17020Sstevel@tonic-gate 	(void) create_segment_node(hash_obj, warg->nodeh, &segment,
1703*9407SMichael.Bergknoff@Sun.COM 	    cont_tbl, &warg->cred);
17040Sstevel@tonic-gate 
17050Sstevel@tonic-gate 	/* rebuild  segment list */
17060Sstevel@tonic-gate 	seg_hash = hash_obj->u.sec_node->segment_list;
17070Sstevel@tonic-gate 	if (seg_hash == NULL) {
17080Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
17090Sstevel@tonic-gate 		return (PICL_FAILURE);
17100Sstevel@tonic-gate 	}
17110Sstevel@tonic-gate 
17120Sstevel@tonic-gate 	hash_obj->u.sec_node->num_of_segment = 0;
17130Sstevel@tonic-gate 
17140Sstevel@tonic-gate 	for (cnt = 0; cnt < num_of_segment; cnt++) {
17150Sstevel@tonic-gate 		desc	= (fru_segdesc_t *)&seg_buf[cnt].descriptor;
17160Sstevel@tonic-gate 		if (!(desc->field.field_perm & SEGMENT_READ)) {
17170Sstevel@tonic-gate 			continue;
17180Sstevel@tonic-gate 		}
17190Sstevel@tonic-gate 
17200Sstevel@tonic-gate 		/* if opaque segment don't create segment node */
17210Sstevel@tonic-gate 		if (desc->field.opaque) {
17220Sstevel@tonic-gate 			continue;
17230Sstevel@tonic-gate 		}
17240Sstevel@tonic-gate 
17250Sstevel@tonic-gate 		seg_hash->u.seg_node->segment_hdl =
1726*9407SMichael.Bergknoff@Sun.COM 		    seg_buf[cnt].handle;
17270Sstevel@tonic-gate 		seg_hash = seg_hash->u.seg_node->next;
17280Sstevel@tonic-gate 		hash_obj->u.sec_node->num_of_segment++;
17290Sstevel@tonic-gate 	}
17300Sstevel@tonic-gate 
17310Sstevel@tonic-gate 	/* update with new section handle */
17320Sstevel@tonic-gate 	hash_obj->u.sec_node->section_hdl = new_sec_acc_hdl;
17330Sstevel@tonic-gate 
17340Sstevel@tonic-gate 	unlock_container_lock(cont_tbl);
17350Sstevel@tonic-gate 
17360Sstevel@tonic-gate 	return (PICL_SUCCESS);
17370Sstevel@tonic-gate }
17380Sstevel@tonic-gate 
17390Sstevel@tonic-gate /*
17400Sstevel@tonic-gate  * called from frudata_write_section() callback routine to create
17410Sstevel@tonic-gate  * section node and all the  property under class section. it also
17420Sstevel@tonic-gate  * allocate hash node object for each section in the container and
17430Sstevel@tonic-gate  * add the section node object in the section list.
17440Sstevel@tonic-gate  */
17450Sstevel@tonic-gate 
17460Sstevel@tonic-gate static int
create_section_node(picl_nodehdl_t nodehdl,int section_count,section_t * section,container_tbl_t * cont_tbl)17470Sstevel@tonic-gate create_section_node(picl_nodehdl_t nodehdl, int section_count,
17480Sstevel@tonic-gate 				section_t *section, container_tbl_t *cont_tbl)
17490Sstevel@tonic-gate {
17500Sstevel@tonic-gate 	char		sec_name[SECNAMESIZE];
17510Sstevel@tonic-gate 	hash_obj_t	*hash_obj;
17520Sstevel@tonic-gate 	hash_obj_t	*cont_hash;
17530Sstevel@tonic-gate 	picl_nodehdl_t	chld_node;
17540Sstevel@tonic-gate 	picl_prophdl_t	prophdl;
17550Sstevel@tonic-gate 	ptree_propinfo_t prop;
17560Sstevel@tonic-gate 
17570Sstevel@tonic-gate 	(void) snprintf(sec_name, SECNAMESIZE, "section%d", section_count);
17580Sstevel@tonic-gate 
17590Sstevel@tonic-gate 	if (ptree_create_node(sec_name, PICL_CLASS_SECTION, &chld_node)
1760*9407SMichael.Bergknoff@Sun.COM 	    != PICL_SUCCESS) {
17610Sstevel@tonic-gate 		return (PICL_FAILURE);
17620Sstevel@tonic-gate 	}
17630Sstevel@tonic-gate 	prop.version		= PTREE_PROPINFO_VERSION;
17640Sstevel@tonic-gate 	prop.piclinfo.type	= PICL_PTYPE_UNSIGNED_INT;
17650Sstevel@tonic-gate 	prop.piclinfo.accessmode = PICL_READ;
17660Sstevel@tonic-gate 	prop.piclinfo.size	= sizeof (uint32_t);
17670Sstevel@tonic-gate 	prop.read		= NULL;
17680Sstevel@tonic-gate 	prop.write		= NULL;
17690Sstevel@tonic-gate 
17700Sstevel@tonic-gate 	/* offset */
17710Sstevel@tonic-gate 	(void) strcpy(prop.piclinfo.name, PICL_PROP_OFFSET);
17720Sstevel@tonic-gate 	if (ptree_create_and_add_prop(chld_node, &prop, &section->offset,
1773*9407SMichael.Bergknoff@Sun.COM 	    &prophdl) != PICL_SUCCESS) {
17740Sstevel@tonic-gate 		freeup(chld_node);
17750Sstevel@tonic-gate 		return (PICL_FAILURE);
17760Sstevel@tonic-gate 	}
17770Sstevel@tonic-gate 
17780Sstevel@tonic-gate 	/* length */
17790Sstevel@tonic-gate 	(void) strcpy(prop.piclinfo.name, PICL_PROP_LENGTH);
17800Sstevel@tonic-gate 	if (ptree_create_and_add_prop(chld_node, &prop, &section->length,
1781*9407SMichael.Bergknoff@Sun.COM 	    &prophdl) != PICL_SUCCESS) {
17820Sstevel@tonic-gate 		freeup(chld_node);
17830Sstevel@tonic-gate 		return (PICL_FAILURE);
17840Sstevel@tonic-gate 	}
17850Sstevel@tonic-gate 
17860Sstevel@tonic-gate 
17870Sstevel@tonic-gate 	/* protected */
17880Sstevel@tonic-gate 	(void) strcpy(prop.piclinfo.name, PICL_PROP_PROTECTED);
17890Sstevel@tonic-gate 	if (ptree_create_and_add_prop(chld_node, &prop, &section->protection,
1790*9407SMichael.Bergknoff@Sun.COM 	    &prophdl) != PICL_SUCCESS) {
17910Sstevel@tonic-gate 		freeup(chld_node);
17920Sstevel@tonic-gate 		return (PICL_FAILURE);
17930Sstevel@tonic-gate 	}
17940Sstevel@tonic-gate 
17950Sstevel@tonic-gate 	prop.piclinfo.accessmode	= PICL_READ|PICL_VOLATILE;
17960Sstevel@tonic-gate 	prop.read	= frudata_read_segment;
17970Sstevel@tonic-gate 
17980Sstevel@tonic-gate 	(void) strcpy(prop.piclinfo.name, PICL_PROP_NUM_SEGMENTS);
17990Sstevel@tonic-gate 
18000Sstevel@tonic-gate 	if (ptree_create_and_add_prop(chld_node, &prop, NULL, &prophdl)
1801*9407SMichael.Bergknoff@Sun.COM 	    != PICL_SUCCESS) {
18020Sstevel@tonic-gate 		freeup(chld_node);
18030Sstevel@tonic-gate 		return (PICL_FAILURE);
18040Sstevel@tonic-gate 	}
18050Sstevel@tonic-gate 
18060Sstevel@tonic-gate 
18070Sstevel@tonic-gate 	prop.piclinfo.type = PICL_PTYPE_BYTEARRAY;
18080Sstevel@tonic-gate 	prop.piclinfo.size = sizeof (fru_segdef_t);
18090Sstevel@tonic-gate 
18100Sstevel@tonic-gate 	prop.piclinfo.accessmode = PICL_WRITE|PICL_READ|PICL_VOLATILE;
18110Sstevel@tonic-gate 	prop.write = frudata_add_segment; /* callback routine */
18120Sstevel@tonic-gate 	prop.read = frudata_read_callback;
18130Sstevel@tonic-gate 
18140Sstevel@tonic-gate 	(void) strcpy(prop.piclinfo.name, PICL_PROP_ADD_SEGMENT);
18150Sstevel@tonic-gate 	/* add-segment prop if read/write section */
18160Sstevel@tonic-gate 	if (section->protection == 0) {
18170Sstevel@tonic-gate 		if (ptree_create_and_add_prop(chld_node, &prop, NULL, &prophdl)
1818*9407SMichael.Bergknoff@Sun.COM 		    != PICL_SUCCESS) {
18190Sstevel@tonic-gate 			freeup(chld_node);
18200Sstevel@tonic-gate 			return (PICL_FAILURE);
18210Sstevel@tonic-gate 		}
18220Sstevel@tonic-gate 	}
18230Sstevel@tonic-gate 
18240Sstevel@tonic-gate 	if (ptree_add_node(nodehdl, chld_node) != PICL_SUCCESS) {
18250Sstevel@tonic-gate 		freeup(chld_node);
18260Sstevel@tonic-gate 		return (PICL_FAILURE);
18270Sstevel@tonic-gate 	}
18280Sstevel@tonic-gate 
18290Sstevel@tonic-gate 	/* lookup for container handle */
18300Sstevel@tonic-gate 	cont_hash = lookup_node_object(nodehdl, CONTAINER_NODE, cont_tbl);
18310Sstevel@tonic-gate 	if (cont_hash == NULL) {
18320Sstevel@tonic-gate 		freeup(chld_node);
18330Sstevel@tonic-gate 		return (PICL_FAILURE);
18340Sstevel@tonic-gate 	}
18350Sstevel@tonic-gate 
18360Sstevel@tonic-gate 	hash_obj = alloc_section_node_object(chld_node, section);
18370Sstevel@tonic-gate 	if (hash_obj == NULL) {
18380Sstevel@tonic-gate 		freeup(chld_node);
18390Sstevel@tonic-gate 		return (PICL_FAILURE);
18400Sstevel@tonic-gate 	}
18410Sstevel@tonic-gate 
18420Sstevel@tonic-gate 	add_nodeobject_to_hashtable(hash_obj, cont_tbl);
18430Sstevel@tonic-gate 
18440Sstevel@tonic-gate 	add_to_section_list(cont_hash, hash_obj);
18450Sstevel@tonic-gate 	return (PICL_SUCCESS);
18460Sstevel@tonic-gate }
18470Sstevel@tonic-gate 
18480Sstevel@tonic-gate 
18490Sstevel@tonic-gate /*
18500Sstevel@tonic-gate  * Description  :frudata_write_section is called when volatile container
18510Sstevel@tonic-gate  *              property is accessed. it reads the section table associated
18520Sstevel@tonic-gate  *              with the specified node handle(container) in ptree_rarg_t.
18530Sstevel@tonic-gate  *              it calls search_root_node to search the node handle to open the
18540Sstevel@tonic-gate  *              device associated with the node handle. it creates section
18550Sstevel@tonic-gate  *              node and it's associated property. it also creates
18560Sstevel@tonic-gate  *              volatile property num_segments.
18570Sstevel@tonic-gate  *
18580Sstevel@tonic-gate  * Argument     : ptree_rarg_t  : contains node handle of fru container the
18590Sstevel@tonic-gate  *                                                      container.
18600Sstevel@tonic-gate  *              property handle of the container.
18610Sstevel@tonic-gate  *
18620Sstevel@tonic-gate  * Return       : PICL_SUCCESS  on success.
18630Sstevel@tonic-gate  *
18640Sstevel@tonic-gate  */
18650Sstevel@tonic-gate 
18660Sstevel@tonic-gate /* ARGSUSED */
18670Sstevel@tonic-gate 
18680Sstevel@tonic-gate static int
frudata_write_section(ptree_warg_t * warg,const void * buf)18690Sstevel@tonic-gate frudata_write_section(ptree_warg_t *warg, const void *buf)
18700Sstevel@tonic-gate {
18710Sstevel@tonic-gate 	int		retval;
18720Sstevel@tonic-gate 	int		num_of_section;
18730Sstevel@tonic-gate 	int		count;
18740Sstevel@tonic-gate 	section_t	*section;
18750Sstevel@tonic-gate 	hash_obj_t	*hash_obj;
18760Sstevel@tonic-gate 	container_tbl_t	*cont_tbl = NULL;
18770Sstevel@tonic-gate 	fru_access_hdl_t cont_acc_hdl;
18780Sstevel@tonic-gate 
18790Sstevel@tonic-gate 	(void) pthread_mutex_lock(&cont_tbl_lock);
18800Sstevel@tonic-gate 
18810Sstevel@tonic-gate 	/*
18820Sstevel@tonic-gate 	 * if lookup succeed return from this function with PICL_SUCCESS
18830Sstevel@tonic-gate 	 * because first write operation has already occurred on this container,
18840Sstevel@tonic-gate 	 * it also means that the container has been already initialzed.
18850Sstevel@tonic-gate 	 */
18860Sstevel@tonic-gate 
18870Sstevel@tonic-gate 	cont_tbl = lookup_container_table(warg->nodeh, CONTAINER_NODE);
18880Sstevel@tonic-gate 	if (cont_tbl != NULL) { /* found the hash obj in the hash table */
18890Sstevel@tonic-gate 		(void) pthread_mutex_unlock(&cont_tbl_lock);
18900Sstevel@tonic-gate 		return (PICL_SUCCESS);
18910Sstevel@tonic-gate 	}
18920Sstevel@tonic-gate 
18930Sstevel@tonic-gate 	/*
18940Sstevel@tonic-gate 	 * lookup failed that means this is first write on the
18950Sstevel@tonic-gate 	 * container property. allocate a new container hash table for this
18960Sstevel@tonic-gate 	 * new container and add to the cont_tbl hash table.
18970Sstevel@tonic-gate 	 */
18980Sstevel@tonic-gate 
18990Sstevel@tonic-gate 	cont_tbl = alloc_container_table(warg->nodeh);
19000Sstevel@tonic-gate 	if (cont_tbl == NULL) {
19010Sstevel@tonic-gate 		(void) pthread_mutex_unlock(&cont_tbl_lock);
19020Sstevel@tonic-gate 		return (map_access_err(errno));
19030Sstevel@tonic-gate 	}
19040Sstevel@tonic-gate 
19050Sstevel@tonic-gate 	hash_obj = alloc_container_node_object(warg->nodeh);
19060Sstevel@tonic-gate 	if (hash_obj == NULL) {
19070Sstevel@tonic-gate 		(void) pthread_mutex_unlock(&cont_tbl_lock);
1908*9407SMichael.Bergknoff@Sun.COM 		free(cont_tbl->hash_obj);
1909*9407SMichael.Bergknoff@Sun.COM 		free(cont_tbl);
19100Sstevel@tonic-gate 		return (map_access_err(errno));
19110Sstevel@tonic-gate 	}
19120Sstevel@tonic-gate 
19130Sstevel@tonic-gate 	/* add container table object to container table */
19140Sstevel@tonic-gate 	add_tblobject_to_container_tbl(cont_tbl);
19150Sstevel@tonic-gate 
19160Sstevel@tonic-gate 	/* add the hash object to container hash table. */
19170Sstevel@tonic-gate 	add_nodeobject_to_hashtable(hash_obj, cont_tbl);
19180Sstevel@tonic-gate 
19190Sstevel@tonic-gate 	while (pthread_rwlock_trywrlock(&cont_tbl->rwlock) == EBUSY) {
19200Sstevel@tonic-gate 		pthread_cond_wait(&cont_tbl->cond_var, &cont_tbl_lock);
19210Sstevel@tonic-gate 	}
19220Sstevel@tonic-gate 
19230Sstevel@tonic-gate 	(void) pthread_mutex_unlock(&cont_tbl_lock);
19240Sstevel@tonic-gate 
19250Sstevel@tonic-gate 	/* fruaccess  handle */
19260Sstevel@tonic-gate 	cont_acc_hdl	= hash_obj->u.cont_node->cont_hdl;
19270Sstevel@tonic-gate 
19280Sstevel@tonic-gate 	num_of_section = fru_get_num_sections(cont_acc_hdl, &warg->cred);
19290Sstevel@tonic-gate 
19300Sstevel@tonic-gate 	if (num_of_section == -1) {
19310Sstevel@tonic-gate 		free(hash_obj);
19320Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
19330Sstevel@tonic-gate 		return (PICL_FAILURE);
19340Sstevel@tonic-gate 	}
19350Sstevel@tonic-gate 
19360Sstevel@tonic-gate 	section	= alloca(num_of_section * sizeof (section_t));
19370Sstevel@tonic-gate 
19380Sstevel@tonic-gate 	retval = fru_get_sections(cont_acc_hdl, section,
1939*9407SMichael.Bergknoff@Sun.COM 	    num_of_section, &warg->cred);
19400Sstevel@tonic-gate 	if (retval == -1) {
19410Sstevel@tonic-gate 		free(hash_obj);
19420Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
19430Sstevel@tonic-gate 		return (PICL_FAILURE);
19440Sstevel@tonic-gate 	}
19450Sstevel@tonic-gate 
19460Sstevel@tonic-gate 	hash_obj->u.cont_node->num_of_section = num_of_section;
19470Sstevel@tonic-gate 
19480Sstevel@tonic-gate 	for (count = 0; count < num_of_section; count++) {
19490Sstevel@tonic-gate 		(void) create_section_node(warg->nodeh, count,
1950*9407SMichael.Bergknoff@Sun.COM 		    section + count, cont_tbl);
19510Sstevel@tonic-gate 	}
19520Sstevel@tonic-gate 
19530Sstevel@tonic-gate 	unlock_container_lock(cont_tbl);
19540Sstevel@tonic-gate 
19550Sstevel@tonic-gate 	return (PICL_SUCCESS);
19560Sstevel@tonic-gate }
19570Sstevel@tonic-gate 
19580Sstevel@tonic-gate /* create container and add-segment property */
19590Sstevel@tonic-gate 
19600Sstevel@tonic-gate static int
create_container_prop(picl_nodehdl_t fruhdl)19610Sstevel@tonic-gate create_container_prop(picl_nodehdl_t	fruhdl)
19620Sstevel@tonic-gate {
19630Sstevel@tonic-gate 	int			retval;
19640Sstevel@tonic-gate 	picl_prophdl_t		prophdl;
19650Sstevel@tonic-gate 	ptree_propinfo_t	prop;
19660Sstevel@tonic-gate 
19670Sstevel@tonic-gate 	prop.version = PTREE_PROPINFO_VERSION;
19680Sstevel@tonic-gate 	prop.piclinfo.type = PICL_PTYPE_UNSIGNED_INT;
19690Sstevel@tonic-gate 	prop.piclinfo.size = sizeof (uint32_t);
19700Sstevel@tonic-gate 	prop.piclinfo.accessmode = PICL_WRITE|PICL_VOLATILE;
19710Sstevel@tonic-gate 	(void) strcpy(prop.piclinfo.name, PICL_PROP_CONTAINER);
19720Sstevel@tonic-gate 	prop.read =  frudata_read_callback;
19730Sstevel@tonic-gate 	prop.write = frudata_write_section; /* callback routine */
19740Sstevel@tonic-gate 
19750Sstevel@tonic-gate 	/* create a property */
19760Sstevel@tonic-gate 	retval = ptree_create_and_add_prop(fruhdl, &prop, NULL, &prophdl);
19770Sstevel@tonic-gate 
19780Sstevel@tonic-gate 	return (retval);
19790Sstevel@tonic-gate }
19800Sstevel@tonic-gate 
19810Sstevel@tonic-gate /* search for FRUDataAvailable and create container and add segment property */
19820Sstevel@tonic-gate 
19830Sstevel@tonic-gate static void
create_frudata_props(picl_prophdl_t fruhdl)19840Sstevel@tonic-gate create_frudata_props(picl_prophdl_t fruhdl)
19850Sstevel@tonic-gate {
19860Sstevel@tonic-gate 	int		retval;
19870Sstevel@tonic-gate 	picl_nodehdl_t chldhdl;
19880Sstevel@tonic-gate 	picl_nodehdl_t tmphdl;
19890Sstevel@tonic-gate 
19900Sstevel@tonic-gate 	for (retval = ptree_get_propval_by_name(fruhdl, PICL_PROP_CHILD,
1991*9407SMichael.Bergknoff@Sun.COM 	    &chldhdl, sizeof (picl_nodehdl_t)); retval != PICL_PROPNOTFOUND;
1992*9407SMichael.Bergknoff@Sun.COM 	    retval = ptree_get_propval_by_name(chldhdl, PICL_PROP_PEER,
1993*9407SMichael.Bergknoff@Sun.COM 	    &chldhdl, sizeof (picl_nodehdl_t))) {
19940Sstevel@tonic-gate 		if (retval != PICL_SUCCESS)
19950Sstevel@tonic-gate 			return;
19960Sstevel@tonic-gate 
19970Sstevel@tonic-gate 		/* Does it have a FRUDataAvailable property */
19980Sstevel@tonic-gate 		retval = ptree_get_prop_by_name(chldhdl,
1999*9407SMichael.Bergknoff@Sun.COM 		    PICL_PROP_FRUDATA_AVAIL, &tmphdl);
20000Sstevel@tonic-gate 		if (retval == PICL_SUCCESS) {
20010Sstevel@tonic-gate 			(void) create_container_prop(chldhdl);
20020Sstevel@tonic-gate 		}
20030Sstevel@tonic-gate 
20040Sstevel@tonic-gate 		/* Traverse tree recursively */
20050Sstevel@tonic-gate 		(void) create_frudata_props(chldhdl);
20060Sstevel@tonic-gate 	}
20070Sstevel@tonic-gate }
20080Sstevel@tonic-gate 
20090Sstevel@tonic-gate /*
20100Sstevel@tonic-gate  * Search for the frutree config file from the platform specific
20110Sstevel@tonic-gate  * directory to the common directory.
20120Sstevel@tonic-gate  *
20130Sstevel@tonic-gate  * The size of outfilename must be PATH_MAX
20140Sstevel@tonic-gate  */
20150Sstevel@tonic-gate static int
get_config_file(char * outfilename)20160Sstevel@tonic-gate get_config_file(char *outfilename)
20170Sstevel@tonic-gate {
20180Sstevel@tonic-gate 	char    nmbuf[SYS_NMLN];
20190Sstevel@tonic-gate 	char    pname[PATH_MAX];
20200Sstevel@tonic-gate 
20210Sstevel@tonic-gate 	if (sysinfo(SI_PLATFORM, nmbuf, sizeof (nmbuf)) != -1) {
20220Sstevel@tonic-gate 		(void) snprintf(pname, PATH_MAX, FRUDATA_CONFFILE_NAME, nmbuf);
20230Sstevel@tonic-gate 		if (access(pname, R_OK) == 0) {
20240Sstevel@tonic-gate 			(void) strlcpy(outfilename, pname, PATH_MAX);
20250Sstevel@tonic-gate 			return (0);
20260Sstevel@tonic-gate 		}
20270Sstevel@tonic-gate 	}
20280Sstevel@tonic-gate 
20290Sstevel@tonic-gate 	if (sysinfo(SI_MACHINE, nmbuf, sizeof (nmbuf)) != -1) {
20300Sstevel@tonic-gate 		(void) snprintf(pname, PATH_MAX, FRUDATA_CONFFILE_NAME, nmbuf);
20310Sstevel@tonic-gate 		if (access(pname, R_OK) == 0) {
20320Sstevel@tonic-gate 			(void) strlcpy(outfilename, pname, PATH_MAX);
20330Sstevel@tonic-gate 			return (0);
20340Sstevel@tonic-gate 		}
20350Sstevel@tonic-gate 	}
20360Sstevel@tonic-gate 
20370Sstevel@tonic-gate 	(void) snprintf(pname, PATH_MAX, "%s/%s", PICLD_COMMON_PLUGIN_DIR,
2038*9407SMichael.Bergknoff@Sun.COM 	    FRUDATA_CONFFILE_NAME);
20390Sstevel@tonic-gate 	if (access(pname, R_OK) == 0) {
20400Sstevel@tonic-gate 		(void) strlcpy(outfilename, pname, PATH_MAX);
20410Sstevel@tonic-gate 		return (0);
20420Sstevel@tonic-gate 	}
20430Sstevel@tonic-gate 	return (-1);
20440Sstevel@tonic-gate }
20450Sstevel@tonic-gate 
20460Sstevel@tonic-gate /*
20470Sstevel@tonic-gate  * called from delete_frudata_props(), this routine delete the section node
20480Sstevel@tonic-gate  * and free's the section hash object. it calls free_segment_node() to
20490Sstevel@tonic-gate  * delete segment node beneath it.
20500Sstevel@tonic-gate  */
20510Sstevel@tonic-gate 
20520Sstevel@tonic-gate static void
free_section_node(hash_obj_t * sec_hash,container_tbl_t * cont_tbl)20530Sstevel@tonic-gate free_section_node(hash_obj_t	*sec_hash, container_tbl_t *cont_tbl)
20540Sstevel@tonic-gate {
20550Sstevel@tonic-gate 	hash_obj_t	*seg_hash;
20560Sstevel@tonic-gate 
20570Sstevel@tonic-gate 	for (seg_hash = sec_hash->u.sec_node->segment_list; seg_hash != NULL;
2058*9407SMichael.Bergknoff@Sun.COM 	    seg_hash = seg_hash->u.seg_node->next) {
20590Sstevel@tonic-gate 		free_segment_node(seg_hash, seg_hash->picl_hdl, cont_tbl);
20600Sstevel@tonic-gate 	}
20610Sstevel@tonic-gate 
20620Sstevel@tonic-gate 	if (sec_hash->prev == NULL) {
20630Sstevel@tonic-gate 		cont_tbl->hash_obj[(sec_hash->picl_hdl % TABLE_SIZE)].next =
2064*9407SMichael.Bergknoff@Sun.COM 		    sec_hash->next;
20650Sstevel@tonic-gate 		if (sec_hash->next != NULL) {
20660Sstevel@tonic-gate 			sec_hash->next->prev = NULL;
20670Sstevel@tonic-gate 		}
20680Sstevel@tonic-gate 	} else {
20690Sstevel@tonic-gate 		sec_hash->prev->next = sec_hash->next;
20700Sstevel@tonic-gate 		if (sec_hash->next != NULL) {
20710Sstevel@tonic-gate 			sec_hash->next->prev = sec_hash->prev;
20720Sstevel@tonic-gate 		}
20730Sstevel@tonic-gate 	}
20740Sstevel@tonic-gate 
20750Sstevel@tonic-gate 	/* delete & destroy section node */
20760Sstevel@tonic-gate 	(void) ptree_delete_node(sec_hash->picl_hdl);
20770Sstevel@tonic-gate 	(void) ptree_destroy_node(sec_hash->picl_hdl);
20780Sstevel@tonic-gate 
20790Sstevel@tonic-gate 	free(sec_hash->u.sec_node);
20800Sstevel@tonic-gate 	free(sec_hash);
20810Sstevel@tonic-gate }
20820Sstevel@tonic-gate 
20830Sstevel@tonic-gate /*
20840Sstevel@tonic-gate  * called from delete_frudata_props(), this routine free's the container
20850Sstevel@tonic-gate  * hash object.
20860Sstevel@tonic-gate  */
20870Sstevel@tonic-gate 
20880Sstevel@tonic-gate static void
unlink_container_node(container_tbl_t * cont_hash)20890Sstevel@tonic-gate unlink_container_node(container_tbl_t	*cont_hash)
20900Sstevel@tonic-gate {
20910Sstevel@tonic-gate 	if (cont_hash->prev == NULL) {
20920Sstevel@tonic-gate 		container_table[(cont_hash->picl_hdl % TABLE_SIZE)] =
2093*9407SMichael.Bergknoff@Sun.COM 		    cont_hash->next;
20940Sstevel@tonic-gate 		if (cont_hash->next != NULL) {
20950Sstevel@tonic-gate 			cont_hash->next->prev = NULL;
20960Sstevel@tonic-gate 		}
20970Sstevel@tonic-gate 	} else {
20980Sstevel@tonic-gate 		cont_hash->prev->next = cont_hash->next;
20990Sstevel@tonic-gate 		if (cont_hash->next != NULL) {
21000Sstevel@tonic-gate 			cont_hash->next->prev = cont_hash->prev;
21010Sstevel@tonic-gate 		}
21020Sstevel@tonic-gate 	}
21030Sstevel@tonic-gate }
21040Sstevel@tonic-gate 
21050Sstevel@tonic-gate /*
21060Sstevel@tonic-gate  * called from frudata_event_handler() to free the corresponding hash object
21070Sstevel@tonic-gate  * of the removed fru.
21080Sstevel@tonic-gate  */
21090Sstevel@tonic-gate 
21100Sstevel@tonic-gate static void
delete_frudata_props(picl_nodehdl_t fru_hdl)21110Sstevel@tonic-gate delete_frudata_props(picl_nodehdl_t	fru_hdl)
21120Sstevel@tonic-gate {
21130Sstevel@tonic-gate 	hash_obj_t	*cont_hash;
21140Sstevel@tonic-gate 	hash_obj_t	*free_obj;
21150Sstevel@tonic-gate 	hash_obj_t	*sec_hash;
21160Sstevel@tonic-gate 	container_tbl_t	*cont_tbl;
21170Sstevel@tonic-gate 
21180Sstevel@tonic-gate 	(void) pthread_mutex_lock(&cont_tbl_lock);
21190Sstevel@tonic-gate 
21200Sstevel@tonic-gate 	cont_tbl = lookup_container_table(fru_hdl, CONTAINER_NODE);
21210Sstevel@tonic-gate 	if (cont_tbl == NULL) {
21220Sstevel@tonic-gate 		(void) pthread_mutex_unlock(&cont_tbl_lock);
21230Sstevel@tonic-gate 		return;
21240Sstevel@tonic-gate 	}
21250Sstevel@tonic-gate 
21260Sstevel@tonic-gate 	/* remove the container object from the container table */
21270Sstevel@tonic-gate 	unlink_container_node(cont_tbl);
21280Sstevel@tonic-gate 
21290Sstevel@tonic-gate 	(void) pthread_cond_broadcast(&cont_tbl->cond_var);
21300Sstevel@tonic-gate 
21310Sstevel@tonic-gate 	(void) pthread_mutex_unlock(&cont_tbl_lock);
21320Sstevel@tonic-gate 
21330Sstevel@tonic-gate 	/*
21340Sstevel@tonic-gate 	 * waiting/blocking calling thread for all I/O in
21350Sstevel@tonic-gate 	 * progress to complete. don't free the container
21360Sstevel@tonic-gate 	 * hash before all I/O is complete.
21370Sstevel@tonic-gate 	 */
21380Sstevel@tonic-gate 	(void) pthread_rwlock_wrlock(&cont_tbl->rwlock);
21390Sstevel@tonic-gate 
21400Sstevel@tonic-gate 	(void) pthread_rwlock_unlock(&cont_tbl->rwlock);
21410Sstevel@tonic-gate 
21420Sstevel@tonic-gate 
21430Sstevel@tonic-gate 	cont_hash = lookup_node_object(fru_hdl, CONTAINER_NODE, cont_tbl);
21440Sstevel@tonic-gate 	if (cont_hash == NULL) {
21450Sstevel@tonic-gate 		return;
21460Sstevel@tonic-gate 	}
21470Sstevel@tonic-gate 
21480Sstevel@tonic-gate 	free_obj = cont_hash->u.cont_node->section_list;
21490Sstevel@tonic-gate 	/* walk through the section list */
21500Sstevel@tonic-gate 	for (sec_hash = free_obj; sec_hash != NULL; free_obj = sec_hash) {
21510Sstevel@tonic-gate 		sec_hash = sec_hash->u.sec_node->next;
21520Sstevel@tonic-gate 		free_section_node(free_obj, cont_tbl);
21530Sstevel@tonic-gate 	}
21540Sstevel@tonic-gate 	(void) fru_close_container(cont_hash->u.cont_node->cont_hdl);
21550Sstevel@tonic-gate 
21560Sstevel@tonic-gate 	free(cont_hash->u.cont_node);
21570Sstevel@tonic-gate 	free(cont_hash);
21580Sstevel@tonic-gate 
21590Sstevel@tonic-gate 	free(cont_tbl->hash_obj);
21600Sstevel@tonic-gate 	free(cont_tbl);
21610Sstevel@tonic-gate }
21620Sstevel@tonic-gate 
21630Sstevel@tonic-gate /*
21640Sstevel@tonic-gate  * called when there is any state-change in location, fru, port nodes.
21650Sstevel@tonic-gate  * this event handler handles only location state-changes.
21660Sstevel@tonic-gate  */
21670Sstevel@tonic-gate /* ARGSUSED */
21680Sstevel@tonic-gate static void
frudata_state_change_evhandler(const char * event_name,const void * event_arg,size_t size,void * cookie)21690Sstevel@tonic-gate frudata_state_change_evhandler(const char *event_name, const void *event_arg,
21700Sstevel@tonic-gate 	size_t size, void *cookie)
21710Sstevel@tonic-gate {
21720Sstevel@tonic-gate 	int rc;
21730Sstevel@tonic-gate 	nvlist_t *nvlp;
21740Sstevel@tonic-gate 	ptree_propinfo_t prop;
21750Sstevel@tonic-gate 	picl_nodehdl_t	loch, fruh;
21760Sstevel@tonic-gate 	picl_prophdl_t	proph, prophdl;
21770Sstevel@tonic-gate 	char *present_state, *last_state;
21780Sstevel@tonic-gate 	char name[PICL_PROPNAMELEN_MAX];
21790Sstevel@tonic-gate 
21800Sstevel@tonic-gate 	if (strcmp(event_name, PICLEVENT_STATE_CHANGE) != 0)
21810Sstevel@tonic-gate 		return;
21820Sstevel@tonic-gate 
21830Sstevel@tonic-gate 	if (nvlist_unpack((char *)event_arg, size, &nvlp, NULL)) {
21840Sstevel@tonic-gate 		return;
21850Sstevel@tonic-gate 	}
21860Sstevel@tonic-gate 
21870Sstevel@tonic-gate 	if (nvlist_lookup_uint64(nvlp, PICLEVENTARG_NODEHANDLE,
2188*9407SMichael.Bergknoff@Sun.COM 	    &loch)  == -1) {
21890Sstevel@tonic-gate 		nvlist_free(nvlp);
21900Sstevel@tonic-gate 		return;
21910Sstevel@tonic-gate 	}
21920Sstevel@tonic-gate 
21930Sstevel@tonic-gate 	if (ptree_get_propval_by_name(loch, PICL_PROP_CLASSNAME, name,
2194*9407SMichael.Bergknoff@Sun.COM 	    sizeof (name)) != PICL_SUCCESS) {
21950Sstevel@tonic-gate 		nvlist_free(nvlp);
21960Sstevel@tonic-gate 		return;
21970Sstevel@tonic-gate 	}
21980Sstevel@tonic-gate 
21990Sstevel@tonic-gate 	/* handle only location events */
22000Sstevel@tonic-gate 	if (strcmp(name, PICL_CLASS_LOCATION) != 0) {
22010Sstevel@tonic-gate 		nvlist_free(nvlp);
22020Sstevel@tonic-gate 		return;
22030Sstevel@tonic-gate 	}
22040Sstevel@tonic-gate 
22050Sstevel@tonic-gate 	if (nvlist_lookup_string(nvlp, PICLEVENTARG_STATE,
2206*9407SMichael.Bergknoff@Sun.COM 	    &present_state)) {
22070Sstevel@tonic-gate 		nvlist_free(nvlp);
22080Sstevel@tonic-gate 		return;
22090Sstevel@tonic-gate 	}
22100Sstevel@tonic-gate 
22110Sstevel@tonic-gate 	rc = ptree_get_propval_by_name(loch, PICL_PROP_CHILD,
2212*9407SMichael.Bergknoff@Sun.COM 	    &fruh, sizeof (picl_nodehdl_t));
22130Sstevel@tonic-gate 	if (rc != PICL_SUCCESS) {
22140Sstevel@tonic-gate 		nvlist_free(nvlp);
22150Sstevel@tonic-gate 		return;
22160Sstevel@tonic-gate 	}
22170Sstevel@tonic-gate 
22180Sstevel@tonic-gate 	/* fru removed */
22190Sstevel@tonic-gate 	if (strcmp(present_state, PICLEVENTARGVAL_EMPTY) == 0) {
22200Sstevel@tonic-gate 		delete_frudata_props(fruh);
22210Sstevel@tonic-gate 		nvlist_free(nvlp);
22220Sstevel@tonic-gate 		return;
22230Sstevel@tonic-gate 	}
22240Sstevel@tonic-gate 
22250Sstevel@tonic-gate 	if (nvlist_lookup_string(nvlp, PICLEVENTARG_LAST_STATE,
2226*9407SMichael.Bergknoff@Sun.COM 	    &last_state)) {
22270Sstevel@tonic-gate 		nvlist_free(nvlp);
22280Sstevel@tonic-gate 		return;
22290Sstevel@tonic-gate 	}
22300Sstevel@tonic-gate 
22310Sstevel@tonic-gate 	/* fru added */
22320Sstevel@tonic-gate 	if ((strcmp(last_state, PICLEVENTARGVAL_EMPTY) == 0) ||
2233*9407SMichael.Bergknoff@Sun.COM 	    (strcmp(last_state, PICLEVENTARGVAL_UNKNOWN) == 0)) {
22340Sstevel@tonic-gate 		rc = ptree_get_prop_by_name(fruh, PICL_PROP_FRUDATA_AVAIL,
2235*9407SMichael.Bergknoff@Sun.COM 		    &proph);
22360Sstevel@tonic-gate 		if (rc != PICL_SUCCESS) {
22370Sstevel@tonic-gate 			if (fru_is_data_available(fruh) == 0) {
22380Sstevel@tonic-gate 				nvlist_free(nvlp);
22390Sstevel@tonic-gate 				return;
22400Sstevel@tonic-gate 			}
22410Sstevel@tonic-gate 			/* create the property */
22420Sstevel@tonic-gate 			prop.version = PTREE_PROPINFO_VERSION;
22430Sstevel@tonic-gate 			prop.piclinfo.type =  PICL_PTYPE_VOID;
22440Sstevel@tonic-gate 			prop.piclinfo.accessmode = PICL_READ;
22450Sstevel@tonic-gate 			prop.piclinfo.size =  0;
22460Sstevel@tonic-gate 			(void) strncpy(prop.piclinfo.name,
2247*9407SMichael.Bergknoff@Sun.COM 			    PICL_PROP_FRUDATA_AVAIL,
2248*9407SMichael.Bergknoff@Sun.COM 			    sizeof (prop.piclinfo.name));
22490Sstevel@tonic-gate 
22500Sstevel@tonic-gate 			rc = ptree_create_prop(&prop, NULL, &prophdl);
22510Sstevel@tonic-gate 			if (rc != PICL_SUCCESS) {
22520Sstevel@tonic-gate 				nvlist_free(nvlp);
22530Sstevel@tonic-gate 				return;
22540Sstevel@tonic-gate 			}
22550Sstevel@tonic-gate 			rc = ptree_add_prop(fruh,  prophdl);
22560Sstevel@tonic-gate 			if (rc != PICL_SUCCESS) {
22570Sstevel@tonic-gate 				nvlist_free(nvlp);
22580Sstevel@tonic-gate 				return;
22590Sstevel@tonic-gate 			}
22600Sstevel@tonic-gate 		}
22610Sstevel@tonic-gate 		(void) create_container_prop(fruh);
22620Sstevel@tonic-gate 	}
22630Sstevel@tonic-gate 	nvlist_free(nvlp);
22640Sstevel@tonic-gate }
22650Sstevel@tonic-gate 
22660Sstevel@tonic-gate /*
22670Sstevel@tonic-gate  * called when event is posted when is fru is either added or removed from
22680Sstevel@tonic-gate  * the picltree.
22690Sstevel@tonic-gate  */
22700Sstevel@tonic-gate 
22710Sstevel@tonic-gate /* ARGSUSED */
22720Sstevel@tonic-gate static void
frudata_event_handler(const char * event_name,const void * event_arg,size_t size,void * cookie)22730Sstevel@tonic-gate frudata_event_handler(const char *event_name, const void *event_arg,
22740Sstevel@tonic-gate 						size_t size, void *cookie)
22750Sstevel@tonic-gate {
22760Sstevel@tonic-gate 	int		retval;
22770Sstevel@tonic-gate 	char		fullfilename[PATH_MAX];
22780Sstevel@tonic-gate 	picl_nodehdl_t	fru_picl_hdl;
22790Sstevel@tonic-gate 	picl_nodehdl_t	roothdl;
22800Sstevel@tonic-gate 
22810Sstevel@tonic-gate 	if (strcmp(event_name, PICL_FRU_REMOVED) == 0) {
22820Sstevel@tonic-gate 
22830Sstevel@tonic-gate 		retval = nvlist_lookup_uint64((nvlist_t *)event_arg,
2284*9407SMichael.Bergknoff@Sun.COM 		    PICLEVENTARG_FRUHANDLE, &fru_picl_hdl);
22850Sstevel@tonic-gate 		if (retval != PICL_SUCCESS) {
22860Sstevel@tonic-gate 			return;
22870Sstevel@tonic-gate 		}
22880Sstevel@tonic-gate 
22890Sstevel@tonic-gate 		/* free the hash object */
22900Sstevel@tonic-gate 		delete_frudata_props(fru_picl_hdl);
22910Sstevel@tonic-gate 
22920Sstevel@tonic-gate 	} else  if (strcmp(event_name, PICL_FRU_ADDED) == 0) {
22930Sstevel@tonic-gate 		/*
22940Sstevel@tonic-gate 		 * reparse the configuration file to create
22950Sstevel@tonic-gate 		 * FRUDevicePath Prop.
22960Sstevel@tonic-gate 		 */
22970Sstevel@tonic-gate 		(void) get_config_file(fullfilename);
22980Sstevel@tonic-gate 		retval = ptree_get_root(&roothdl);
22990Sstevel@tonic-gate 		if (retval != PICL_SUCCESS) {
23000Sstevel@tonic-gate 			return;
23010Sstevel@tonic-gate 		}
23020Sstevel@tonic-gate 
23030Sstevel@tonic-gate 		(void) picld_pluginutil_parse_config_file(roothdl,
2304*9407SMichael.Bergknoff@Sun.COM 		    fullfilename);
23050Sstevel@tonic-gate 
23060Sstevel@tonic-gate 		retval = nvlist_lookup_uint64((nvlist_t *)event_arg,
2307*9407SMichael.Bergknoff@Sun.COM 		    PICLEVENTARG_PARENTHANDLE, &fru_picl_hdl);
23080Sstevel@tonic-gate 		if (retval != PICL_SUCCESS) {
23090Sstevel@tonic-gate 			return;
23100Sstevel@tonic-gate 		}
23110Sstevel@tonic-gate 
23120Sstevel@tonic-gate 		/* create container property */
23130Sstevel@tonic-gate 		create_frudata_props(fru_picl_hdl);
23140Sstevel@tonic-gate 	}
23150Sstevel@tonic-gate }
23160Sstevel@tonic-gate 
23170Sstevel@tonic-gate /*
23180Sstevel@tonic-gate  * Function : plugin_init() is called by daemon. this routine is specified
23190Sstevel@tonic-gate  * 		while registering with daemon. it performs the initialization
23200Sstevel@tonic-gate  *		of plugin module.
23210Sstevel@tonic-gate  */
23220Sstevel@tonic-gate 
23230Sstevel@tonic-gate static void
frudata_plugin_init(void)23240Sstevel@tonic-gate frudata_plugin_init(void)
23250Sstevel@tonic-gate {
23260Sstevel@tonic-gate 	int		retval;
23270Sstevel@tonic-gate 	int		count;
23280Sstevel@tonic-gate 	char		fullfilename[PATH_MAX];
23290Sstevel@tonic-gate 	picl_nodehdl_t	fru_nodehdl;
23300Sstevel@tonic-gate 	picl_nodehdl_t	roothdl;
23310Sstevel@tonic-gate 
23320Sstevel@tonic-gate 	retval = ptree_get_root(&roothdl);
23330Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
23340Sstevel@tonic-gate 		return;
23350Sstevel@tonic-gate 	}
23360Sstevel@tonic-gate 
23370Sstevel@tonic-gate 	(void) ptree_register_handler(PICL_FRU_ADDED,
2338*9407SMichael.Bergknoff@Sun.COM 	    frudata_event_handler, NULL);
23390Sstevel@tonic-gate 
23400Sstevel@tonic-gate 	(void) ptree_register_handler(PICL_FRU_REMOVED,
2341*9407SMichael.Bergknoff@Sun.COM 	    frudata_event_handler, NULL);
23420Sstevel@tonic-gate 
23430Sstevel@tonic-gate 	(void) ptree_register_handler(PICLEVENT_STATE_CHANGE,
2344*9407SMichael.Bergknoff@Sun.COM 	    frudata_state_change_evhandler, NULL);
23450Sstevel@tonic-gate 
23460Sstevel@tonic-gate 	(void) pthread_mutex_lock(&cont_tbl_lock);
23470Sstevel@tonic-gate 	for (count = 0; count < TABLE_SIZE; count++) {
23480Sstevel@tonic-gate 		container_table[count] = NULL;
23490Sstevel@tonic-gate 	}
23500Sstevel@tonic-gate 	(void) pthread_mutex_unlock(&cont_tbl_lock);
23510Sstevel@tonic-gate 
23520Sstevel@tonic-gate 	(void) get_config_file(fullfilename);
23530Sstevel@tonic-gate 
23540Sstevel@tonic-gate 	(void) picld_pluginutil_parse_config_file(roothdl, fullfilename);
23550Sstevel@tonic-gate 
23560Sstevel@tonic-gate 	retval = ptree_get_node_by_path(FRUTREE_PATH, &fru_nodehdl);
23570Sstevel@tonic-gate 
23580Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
23590Sstevel@tonic-gate 		return;
23600Sstevel@tonic-gate 	}
23610Sstevel@tonic-gate 
23620Sstevel@tonic-gate 	create_frudata_props(fru_nodehdl);
23630Sstevel@tonic-gate 
23640Sstevel@tonic-gate }
23650Sstevel@tonic-gate 
23660Sstevel@tonic-gate static void
free_packet_hash_object(hash_obj_t * pkt_obj)23670Sstevel@tonic-gate free_packet_hash_object(hash_obj_t *pkt_obj)
23680Sstevel@tonic-gate {
23690Sstevel@tonic-gate 	hash_obj_t	*tmp_obj;
23700Sstevel@tonic-gate 
23710Sstevel@tonic-gate 	while (pkt_obj != NULL) {
23720Sstevel@tonic-gate 		tmp_obj = pkt_obj->u.pkt_node->next;
23730Sstevel@tonic-gate 		free(pkt_obj->u.pkt_node);
23740Sstevel@tonic-gate 		free(pkt_obj);
23750Sstevel@tonic-gate 		pkt_obj = tmp_obj;
23760Sstevel@tonic-gate 	}
23770Sstevel@tonic-gate }
23780Sstevel@tonic-gate 
23790Sstevel@tonic-gate static void
free_segment_hash_object(hash_obj_t * seg_obj)23800Sstevel@tonic-gate free_segment_hash_object(hash_obj_t *seg_obj)
23810Sstevel@tonic-gate {
23820Sstevel@tonic-gate 	hash_obj_t	*tmp_obj;
23830Sstevel@tonic-gate 
23840Sstevel@tonic-gate 	while (seg_obj != NULL) {
23850Sstevel@tonic-gate 		free_packet_hash_object(seg_obj->u.seg_node->packet_list);
23860Sstevel@tonic-gate 		tmp_obj = seg_obj->u.seg_node->next;
23870Sstevel@tonic-gate 		free(seg_obj->u.seg_node);
23880Sstevel@tonic-gate 		free(seg_obj);
23890Sstevel@tonic-gate 		seg_obj = tmp_obj;
23900Sstevel@tonic-gate 	}
23910Sstevel@tonic-gate }
23920Sstevel@tonic-gate 
23930Sstevel@tonic-gate static void
free_hash_objects(hash_obj_t * sec_obj)23940Sstevel@tonic-gate free_hash_objects(hash_obj_t *sec_obj)
23950Sstevel@tonic-gate {
23960Sstevel@tonic-gate 	hash_obj_t	*tmp_obj;
23970Sstevel@tonic-gate 
23980Sstevel@tonic-gate 	while (sec_obj != NULL) {
23990Sstevel@tonic-gate 		free_segment_hash_object(sec_obj->u.sec_node->segment_list);
24000Sstevel@tonic-gate 		tmp_obj = sec_obj->u.sec_node->next;
24010Sstevel@tonic-gate 		free(sec_obj->u.sec_node);
24020Sstevel@tonic-gate 		free(sec_obj);
24030Sstevel@tonic-gate 		sec_obj = tmp_obj;
24040Sstevel@tonic-gate 	}
24050Sstevel@tonic-gate }
24060Sstevel@tonic-gate 
24070Sstevel@tonic-gate /*
24080Sstevel@tonic-gate  * called from frudata_plugin_fini() this routine walks through
24090Sstevel@tonic-gate  * the hash table to free each and very hash object in the hash table.
24100Sstevel@tonic-gate  */
24110Sstevel@tonic-gate 
24120Sstevel@tonic-gate static void
free_hash_table(void)24130Sstevel@tonic-gate free_hash_table(void)
24140Sstevel@tonic-gate {
24150Sstevel@tonic-gate 	int		cnt;
24160Sstevel@tonic-gate 	picl_nodehdl_t	nodehdl;
24170Sstevel@tonic-gate 	hash_obj_t	*next_obj;
24180Sstevel@tonic-gate 	hash_obj_t	*sec_obj;
24190Sstevel@tonic-gate 	container_tbl_t	*cont_tbl;
24200Sstevel@tonic-gate 
24210Sstevel@tonic-gate 	for (cnt = 0; cnt < TABLE_SIZE; cnt++) {
24220Sstevel@tonic-gate 
24230Sstevel@tonic-gate 		while (container_table[cnt]) {
24240Sstevel@tonic-gate 
24250Sstevel@tonic-gate 			(void) pthread_mutex_lock(&cont_tbl_lock);
24260Sstevel@tonic-gate 
24270Sstevel@tonic-gate 			cont_tbl = container_table[cnt];
24280Sstevel@tonic-gate 			nodehdl = cont_tbl->picl_hdl;
24290Sstevel@tonic-gate 
24300Sstevel@tonic-gate 			cont_tbl = lookup_container_table(nodehdl,
2431*9407SMichael.Bergknoff@Sun.COM 			    CONTAINER_NODE);
24320Sstevel@tonic-gate 			if (cont_tbl == NULL) {
24330Sstevel@tonic-gate 				(void) pthread_mutex_unlock(&cont_tbl_lock);
24340Sstevel@tonic-gate 				break;
24350Sstevel@tonic-gate 			}
24360Sstevel@tonic-gate 
24370Sstevel@tonic-gate 			unlink_container_node(cont_tbl);
24380Sstevel@tonic-gate 
24390Sstevel@tonic-gate 			pthread_cond_broadcast(&cont_tbl->cond_var);
24400Sstevel@tonic-gate 
24410Sstevel@tonic-gate 			(void) pthread_mutex_unlock(&cont_tbl_lock);
24420Sstevel@tonic-gate 
24430Sstevel@tonic-gate 			/*
24440Sstevel@tonic-gate 			 * waiting/blocking calling thread for all I/O in
24450Sstevel@tonic-gate 			 * progress to complete. don't free the container
24460Sstevel@tonic-gate 			 * hash until all I/O is complete.
24470Sstevel@tonic-gate 			 */
24480Sstevel@tonic-gate 			(void) pthread_rwlock_wrlock(&cont_tbl->rwlock);
24490Sstevel@tonic-gate 
24500Sstevel@tonic-gate 			(void) pthread_rwlock_unlock(&cont_tbl->rwlock);
24510Sstevel@tonic-gate 
24520Sstevel@tonic-gate 			next_obj = cont_tbl->hash_obj->next;
24530Sstevel@tonic-gate 			if (next_obj == NULL) {
24540Sstevel@tonic-gate 				break;
24550Sstevel@tonic-gate 			}
24560Sstevel@tonic-gate 
24570Sstevel@tonic-gate 			if (next_obj->object_type == CONTAINER_NODE) {
24580Sstevel@tonic-gate 				sec_obj = next_obj->u.cont_node->section_list;
24590Sstevel@tonic-gate 				free_hash_objects(sec_obj);
24600Sstevel@tonic-gate 			}
24610Sstevel@tonic-gate 
24620Sstevel@tonic-gate 			free(next_obj->u.cont_node);
24630Sstevel@tonic-gate 			free(next_obj);
24640Sstevel@tonic-gate 			container_table[cnt] = cont_tbl->next;
24650Sstevel@tonic-gate 
24660Sstevel@tonic-gate 			free(cont_tbl);
24670Sstevel@tonic-gate 		}
24680Sstevel@tonic-gate 	}
24690Sstevel@tonic-gate }
24700Sstevel@tonic-gate 
24710Sstevel@tonic-gate /*
24720Sstevel@tonic-gate  * called by the daemon and perform frudata cleanup. hold the write lock
24730Sstevel@tonic-gate  * over the entire hash table to free each and every hash object.
24740Sstevel@tonic-gate  */
24750Sstevel@tonic-gate 
24760Sstevel@tonic-gate static void
frudata_plugin_fini(void)24770Sstevel@tonic-gate frudata_plugin_fini(void)
24780Sstevel@tonic-gate {
24790Sstevel@tonic-gate 
24800Sstevel@tonic-gate 	free_hash_table();
24810Sstevel@tonic-gate 
24820Sstevel@tonic-gate 	(void) ptree_unregister_handler(PICL_FRU_ADDED,
2483*9407SMichael.Bergknoff@Sun.COM 	    frudata_event_handler, NULL);
24840Sstevel@tonic-gate 
24850Sstevel@tonic-gate 	(void) ptree_unregister_handler(PICL_FRU_REMOVED,
2486*9407SMichael.Bergknoff@Sun.COM 	    frudata_event_handler, NULL);
24870Sstevel@tonic-gate 
24880Sstevel@tonic-gate 	(void) ptree_unregister_handler(PICLEVENT_STATE_CHANGE,
2489*9407SMichael.Bergknoff@Sun.COM 	    frudata_state_change_evhandler, NULL);
24900Sstevel@tonic-gate }
2491