17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
55705cefcSMichael Bergknoff  * Common Development and Distribution License (the "License").
65705cefcSMichael Bergknoff  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
225705cefcSMichael Bergknoff  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #include <picl.h>
277c478bd9Sstevel@tonic-gate #include <syslog.h>
287c478bd9Sstevel@tonic-gate #include <strings.h>
297c478bd9Sstevel@tonic-gate #include <alloca.h>
307c478bd9Sstevel@tonic-gate #include <pthread.h>
317c478bd9Sstevel@tonic-gate #include <synch.h>
327c478bd9Sstevel@tonic-gate #include <limits.h>
337c478bd9Sstevel@tonic-gate #include <ctype.h>
347c478bd9Sstevel@tonic-gate #include <unistd.h>
357c478bd9Sstevel@tonic-gate #include <picltree.h>
367c478bd9Sstevel@tonic-gate #include <signal.h>
377c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
387c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h>
397c478bd9Sstevel@tonic-gate #include <libnvpair.h>
407c478bd9Sstevel@tonic-gate #include "fru_tag.h"
417c478bd9Sstevel@tonic-gate #include "fru_data_impl.h"
427c478bd9Sstevel@tonic-gate #include "fru_data.h"
437c478bd9Sstevel@tonic-gate #include "picld_pluginutil.h"
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #pragma	init(frudata_plugin_register) /* .init section */
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate static	void		frudata_plugin_init(void);
487c478bd9Sstevel@tonic-gate static	void		frudata_plugin_fini(void);
497c478bd9Sstevel@tonic-gate static	container_tbl_t *container_table[TABLE_SIZE];
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate  * Locking Stragtegy :
537c478bd9Sstevel@tonic-gate  * calling thread should hold the cont_tbl_lock during the course
547c478bd9Sstevel@tonic-gate  * of container table lookup. release the cont_tbl_lock on lookup
557c478bd9Sstevel@tonic-gate  * failure or on the condition wait.
567c478bd9Sstevel@tonic-gate  *
577c478bd9Sstevel@tonic-gate  * thread holding the container object rwlock should release lock
587c478bd9Sstevel@tonic-gate  * and signal to unblock threads blocked on the condition variable
597c478bd9Sstevel@tonic-gate  * upon i/o completion.
607c478bd9Sstevel@tonic-gate  *
617c478bd9Sstevel@tonic-gate  */
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate static pthread_mutex_t	cont_tbl_lock = PTHREAD_MUTEX_INITIALIZER;
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate static int add_row_to_table(hash_obj_t *, picl_nodehdl_t,
667c478bd9Sstevel@tonic-gate 				packet_t *, container_tbl_t *);
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate static picld_plugin_reg_t frudata_reg_info = {
697c478bd9Sstevel@tonic-gate 		PICLD_PLUGIN_VERSION_1,
707c478bd9Sstevel@tonic-gate 		PICLD_PLUGIN_NON_CRITICAL,
717c478bd9Sstevel@tonic-gate 		"SUNW_piclfrudata",
727c478bd9Sstevel@tonic-gate 		frudata_plugin_init,	/* init entry point */
737c478bd9Sstevel@tonic-gate 		frudata_plugin_fini	/* cleanup entry point */
747c478bd9Sstevel@tonic-gate };
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate /* initialization function */
777c478bd9Sstevel@tonic-gate static void
frudata_plugin_register(void)787c478bd9Sstevel@tonic-gate frudata_plugin_register(void)
797c478bd9Sstevel@tonic-gate {
807c478bd9Sstevel@tonic-gate 	/* register plugin with daemon */
817c478bd9Sstevel@tonic-gate 	if (picld_plugin_register(&frudata_reg_info) != PICL_SUCCESS) {
827c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, "SUNW_piclfrudata plugin registration failed");
837c478bd9Sstevel@tonic-gate 	}
847c478bd9Sstevel@tonic-gate }
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate static int
map_access_err(int err)877c478bd9Sstevel@tonic-gate map_access_err(int err)
887c478bd9Sstevel@tonic-gate {
897c478bd9Sstevel@tonic-gate 	switch (err) {
907c478bd9Sstevel@tonic-gate 	case	ENFILE	:
917c478bd9Sstevel@tonic-gate 		return (PICL_PROPEXISTS);
927c478bd9Sstevel@tonic-gate 	case	EAGAIN	:
937c478bd9Sstevel@tonic-gate 		return (PICL_NOSPACE);
947c478bd9Sstevel@tonic-gate 	case	EPERM	:
957c478bd9Sstevel@tonic-gate 		return (PICL_PERMDENIED);
967c478bd9Sstevel@tonic-gate 	case	EEXIST	:
977c478bd9Sstevel@tonic-gate 		return (PICL_PROPEXISTS);
987c478bd9Sstevel@tonic-gate 	default	:
997c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
1007c478bd9Sstevel@tonic-gate 	}
1017c478bd9Sstevel@tonic-gate }
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate /*
1047c478bd9Sstevel@tonic-gate  * unlock_container_lock() should be always called by the thread holding the
1057c478bd9Sstevel@tonic-gate  * container object lock. it will signal block thread waiting on the condition
1067c478bd9Sstevel@tonic-gate  * variable.
1077c478bd9Sstevel@tonic-gate  */
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate static void
unlock_container_lock(container_tbl_t * cont_hash)1107c478bd9Sstevel@tonic-gate unlock_container_lock(container_tbl_t	*cont_hash)
1117c478bd9Sstevel@tonic-gate {
1127c478bd9Sstevel@tonic-gate 	(void) pthread_rwlock_unlock(&cont_hash->rwlock);
1137c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_lock(&cont_tbl_lock);
1147c478bd9Sstevel@tonic-gate 	(void) pthread_cond_signal(&cont_hash->cond_var);
1157c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_unlock(&cont_tbl_lock);
1167c478bd9Sstevel@tonic-gate }
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate /* volatile callback read routine */
1207c478bd9Sstevel@tonic-gate /* ARGSUSED */
1217c478bd9Sstevel@tonic-gate static int
frudata_read_callback(ptree_rarg_t * rarg,void * buf)1227c478bd9Sstevel@tonic-gate frudata_read_callback(ptree_rarg_t *rarg, void *buf)
1237c478bd9Sstevel@tonic-gate {
1247c478bd9Sstevel@tonic-gate 	return (PICL_SUCCESS);
1257c478bd9Sstevel@tonic-gate }
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate /*
1287c478bd9Sstevel@tonic-gate  * called to get hash object for specified node and object type from
1297c478bd9Sstevel@tonic-gate  * hash table.
1307c478bd9Sstevel@tonic-gate  */
1317c478bd9Sstevel@tonic-gate static container_tbl_t *
lookup_container_table(picl_nodehdl_t nodehdl,int object_type)1327c478bd9Sstevel@tonic-gate lookup_container_table(picl_nodehdl_t nodehdl, int object_type)
1337c478bd9Sstevel@tonic-gate {
1347c478bd9Sstevel@tonic-gate 	int		index_to_hash;
1357c478bd9Sstevel@tonic-gate 	int		retval = PICL_SUCCESS;
1367c478bd9Sstevel@tonic-gate 	container_tbl_t	*first_hash;
1377c478bd9Sstevel@tonic-gate 	container_tbl_t	*next_hash;
1387c478bd9Sstevel@tonic-gate 	picl_nodehdl_t	parenthdl = 0;
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate 	switch (object_type) {
1417c478bd9Sstevel@tonic-gate 	case	SECTION_NODE:
1427c478bd9Sstevel@tonic-gate 		retval = ptree_get_propval_by_name(nodehdl, PICL_PROP_PARENT,
1435705cefcSMichael Bergknoff 		    &parenthdl, sizeof (picl_nodehdl_t));
1447c478bd9Sstevel@tonic-gate 		break;
1457c478bd9Sstevel@tonic-gate 	case	SEGMENT_NODE:
1467c478bd9Sstevel@tonic-gate 		retval = ptree_get_propval_by_name(nodehdl, PICL_PROP_PARENT,
1475705cefcSMichael Bergknoff 		    &parenthdl, sizeof (picl_nodehdl_t));
1487c478bd9Sstevel@tonic-gate 		retval = ptree_get_propval_by_name(parenthdl, PICL_PROP_PARENT,
1495705cefcSMichael Bergknoff 		    &parenthdl, sizeof (picl_nodehdl_t));
1507c478bd9Sstevel@tonic-gate 		break;
1517c478bd9Sstevel@tonic-gate 	case	CONTAINER_NODE :
1527c478bd9Sstevel@tonic-gate 		parenthdl = nodehdl;
1537c478bd9Sstevel@tonic-gate 		break;
1547c478bd9Sstevel@tonic-gate 	default	:
1557c478bd9Sstevel@tonic-gate 		return (NULL);
1567c478bd9Sstevel@tonic-gate 	}
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
1597c478bd9Sstevel@tonic-gate 		return (NULL);
1607c478bd9Sstevel@tonic-gate 	}
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate 	index_to_hash	= (parenthdl % TABLE_SIZE);
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 	first_hash	= container_table[index_to_hash];
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate 	for (next_hash = first_hash; next_hash != NULL;
1675705cefcSMichael Bergknoff 	    next_hash = next_hash->next) {
1687c478bd9Sstevel@tonic-gate 		if (parenthdl == next_hash->picl_hdl) {
1697c478bd9Sstevel@tonic-gate 			return (next_hash);
1707c478bd9Sstevel@tonic-gate 		}
1717c478bd9Sstevel@tonic-gate 	}
1727c478bd9Sstevel@tonic-gate 	return (NULL);
1737c478bd9Sstevel@tonic-gate }
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate static int
lock_readwrite_lock(container_tbl_t * cont_obj,int operation)1767c478bd9Sstevel@tonic-gate lock_readwrite_lock(container_tbl_t *cont_obj, int operation)
1777c478bd9Sstevel@tonic-gate {
1787c478bd9Sstevel@tonic-gate 	/* if write operation */
1797c478bd9Sstevel@tonic-gate 	if (operation == PICL_WRITE) {
1807c478bd9Sstevel@tonic-gate 		return (pthread_rwlock_trywrlock(&cont_obj->rwlock));
1817c478bd9Sstevel@tonic-gate 	}
1827c478bd9Sstevel@tonic-gate 	/* read operation */
1837c478bd9Sstevel@tonic-gate 	return (pthread_rwlock_tryrdlock(&cont_obj->rwlock));
1847c478bd9Sstevel@tonic-gate }
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate /*
1877c478bd9Sstevel@tonic-gate  * lock the container table, do lookup for the container object
1887c478bd9Sstevel@tonic-gate  * in the container table. if container object found try to lock
1897c478bd9Sstevel@tonic-gate  * the container object, if lock on container object is busy wait
1907c478bd9Sstevel@tonic-gate  * on condition variable till the thread holding the container
1917c478bd9Sstevel@tonic-gate  * object lock signal it.
1927c478bd9Sstevel@tonic-gate  */
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate static container_tbl_t *
lock_container_lock(picl_nodehdl_t nodehdl,int object_type,int operation)1957c478bd9Sstevel@tonic-gate lock_container_lock(picl_nodehdl_t nodehdl, int object_type, int operation)
1967c478bd9Sstevel@tonic-gate {
1977c478bd9Sstevel@tonic-gate 	container_tbl_t	*cont_obj = NULL;
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_lock(&cont_tbl_lock);
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 	while (((cont_obj = lookup_container_table(nodehdl, object_type)) !=
2025705cefcSMichael Bergknoff 	    NULL) && (lock_readwrite_lock(cont_obj, operation) == EBUSY)) {
2037c478bd9Sstevel@tonic-gate 		pthread_cond_wait(&cont_obj->cond_var, &cont_tbl_lock);
2047c478bd9Sstevel@tonic-gate 	}
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_unlock(&cont_tbl_lock);
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate 	return (cont_obj);
2097c478bd9Sstevel@tonic-gate }
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate static hash_obj_t *
lookup_node_object(picl_nodehdl_t nodehdl,int object_type,container_tbl_t * cont_tbl)2127c478bd9Sstevel@tonic-gate lookup_node_object(picl_nodehdl_t nodehdl, int	object_type,
213*ada2da53SToomas Soome     container_tbl_t *cont_tbl)
2147c478bd9Sstevel@tonic-gate {
2157c478bd9Sstevel@tonic-gate 	int		index_to_hash;
2167c478bd9Sstevel@tonic-gate 	hash_obj_t	*first_hash;
2177c478bd9Sstevel@tonic-gate 	hash_obj_t	*next_hash;
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate 	index_to_hash	= (nodehdl % TABLE_SIZE);
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate 	first_hash	= &cont_tbl->hash_obj[index_to_hash];
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate 	for (next_hash = first_hash->next; next_hash != NULL;
2255705cefcSMichael Bergknoff 	    next_hash = next_hash->next) {
2267c478bd9Sstevel@tonic-gate 		if ((nodehdl == next_hash->picl_hdl) &&
2275705cefcSMichael Bergknoff 		    (object_type == next_hash->object_type)) {
2287c478bd9Sstevel@tonic-gate 			return (next_hash);
2297c478bd9Sstevel@tonic-gate 		}
2307c478bd9Sstevel@tonic-gate 	}
2317c478bd9Sstevel@tonic-gate 	return (NULL);
2327c478bd9Sstevel@tonic-gate }
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate /*
2357c478bd9Sstevel@tonic-gate  * called to add newly created container hash table into container hash table.
2367c478bd9Sstevel@tonic-gate  *
2377c478bd9Sstevel@tonic-gate  */
2387c478bd9Sstevel@tonic-gate static void
add_tblobject_to_container_tbl(container_tbl_t * cont_tbl)2397c478bd9Sstevel@tonic-gate add_tblobject_to_container_tbl(container_tbl_t	*cont_tbl)
2407c478bd9Sstevel@tonic-gate {
2417c478bd9Sstevel@tonic-gate 	int		cnt;
2427c478bd9Sstevel@tonic-gate 	int		index_to_hash;
2437c478bd9Sstevel@tonic-gate 	hash_obj_t	*hash_ptr;
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate 	index_to_hash	= ((cont_tbl->picl_hdl) % TABLE_SIZE);
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate 	cont_tbl->next	= container_table[index_to_hash];
2487c478bd9Sstevel@tonic-gate 	container_table[index_to_hash] = cont_tbl;
2497c478bd9Sstevel@tonic-gate 	hash_ptr	= cont_tbl->hash_obj;
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 	/* initialize the bucket of this container hash table. */
2527c478bd9Sstevel@tonic-gate 
2537c478bd9Sstevel@tonic-gate 	for (cnt = 0; cnt < TABLE_SIZE; cnt++) {
2547c478bd9Sstevel@tonic-gate 		hash_ptr->next = NULL;
2557c478bd9Sstevel@tonic-gate 		hash_ptr->prev = NULL;
2567c478bd9Sstevel@tonic-gate 		hash_ptr++;
2577c478bd9Sstevel@tonic-gate 	}
2587c478bd9Sstevel@tonic-gate 	if (cont_tbl->next != NULL) {
2597c478bd9Sstevel@tonic-gate 		cont_tbl->next->prev = cont_tbl;
2607c478bd9Sstevel@tonic-gate 	}
2617c478bd9Sstevel@tonic-gate }
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate static void
add_nodeobject_to_hashtable(hash_obj_t * hash_obj,container_tbl_t * cont_tbl)2647c478bd9Sstevel@tonic-gate add_nodeobject_to_hashtable(hash_obj_t	*hash_obj, container_tbl_t *cont_tbl)
2657c478bd9Sstevel@tonic-gate {
2667c478bd9Sstevel@tonic-gate 	int		index_to_hash;
2677c478bd9Sstevel@tonic-gate 	hash_obj_t	*hash_table;
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 	index_to_hash	= ((hash_obj->picl_hdl) % TABLE_SIZE);
2707c478bd9Sstevel@tonic-gate 	hash_table	= &cont_tbl->hash_obj[index_to_hash];
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate 	hash_obj->next	= hash_table->next;
2737c478bd9Sstevel@tonic-gate 	hash_table->next = hash_obj;
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate 	if (hash_obj->next != NULL) {
2767c478bd9Sstevel@tonic-gate 		hash_obj->next->prev = hash_obj;
2777c478bd9Sstevel@tonic-gate 	}
2787c478bd9Sstevel@tonic-gate }
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate static container_tbl_t *
alloc_container_table(picl_nodehdl_t nodehdl)2817c478bd9Sstevel@tonic-gate alloc_container_table(picl_nodehdl_t nodehdl)
2827c478bd9Sstevel@tonic-gate {
2837c478bd9Sstevel@tonic-gate 	container_tbl_t		*cont_tbl;
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate 	cont_tbl = malloc(sizeof (container_tbl_t));
2867c478bd9Sstevel@tonic-gate 	if (cont_tbl == NULL) {
2877c478bd9Sstevel@tonic-gate 		return (NULL);
2887c478bd9Sstevel@tonic-gate 	}
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 	cont_tbl->picl_hdl = nodehdl;
2917c478bd9Sstevel@tonic-gate 
2927c478bd9Sstevel@tonic-gate 	cont_tbl->hash_obj = malloc(sizeof (hash_obj_t[TABLE_SIZE]));
2937c478bd9Sstevel@tonic-gate 	cont_tbl->next =	NULL;
2947c478bd9Sstevel@tonic-gate 	cont_tbl->prev =	NULL;
2957c478bd9Sstevel@tonic-gate 
2967c478bd9Sstevel@tonic-gate 	if (cont_tbl->hash_obj == NULL) {
2977c478bd9Sstevel@tonic-gate 		(void) free(cont_tbl);
2987c478bd9Sstevel@tonic-gate 		return (NULL);
2997c478bd9Sstevel@tonic-gate 	}
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate 	(void) pthread_rwlock_init(&cont_tbl->rwlock, NULL);
3027c478bd9Sstevel@tonic-gate 	(void) pthread_cond_init(&cont_tbl->cond_var, NULL);
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate 	return (cont_tbl);
3057c478bd9Sstevel@tonic-gate }
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate /*
3087c478bd9Sstevel@tonic-gate  * called to allocate container node object for container property and a
3097c478bd9Sstevel@tonic-gate  * container table.
3107c478bd9Sstevel@tonic-gate  */
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate static hash_obj_t *
alloc_container_node_object(picl_nodehdl_t nodehdl)3137c478bd9Sstevel@tonic-gate alloc_container_node_object(picl_nodehdl_t nodehdl)
3147c478bd9Sstevel@tonic-gate {
3157c478bd9Sstevel@tonic-gate 	hash_obj_t		*hash_obj;
3167c478bd9Sstevel@tonic-gate 	fru_access_hdl_t	acc_hdl;
3177c478bd9Sstevel@tonic-gate 	container_node_t	*cont_node;
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate 	/* open the container (call fruaccess) */
3207c478bd9Sstevel@tonic-gate 	acc_hdl = fru_open_container(nodehdl);
3217c478bd9Sstevel@tonic-gate 	if (acc_hdl == (container_hdl_t)0) {
3227c478bd9Sstevel@tonic-gate 		return (NULL);
3237c478bd9Sstevel@tonic-gate 	}
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate 	/* allocate container node object */
3267c478bd9Sstevel@tonic-gate 	cont_node	= malloc(sizeof (container_node_t));
3277c478bd9Sstevel@tonic-gate 	if (cont_node == NULL) {
3287c478bd9Sstevel@tonic-gate 		return (NULL);
3297c478bd9Sstevel@tonic-gate 	}
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate 	/* allocate container hash object */
3327c478bd9Sstevel@tonic-gate 	hash_obj	= malloc(sizeof (hash_obj_t));
3337c478bd9Sstevel@tonic-gate 	if (hash_obj == NULL) {
3347c478bd9Sstevel@tonic-gate 		(void) free(cont_node);
3357c478bd9Sstevel@tonic-gate 		return (NULL);
3367c478bd9Sstevel@tonic-gate 	}
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate 	cont_node->cont_hdl	=	acc_hdl; /* fruaccess handle */
3397c478bd9Sstevel@tonic-gate 	cont_node->section_list	=	NULL;
3407c478bd9Sstevel@tonic-gate 	hash_obj->picl_hdl	=	nodehdl; /* picl node handle */
3417c478bd9Sstevel@tonic-gate 	hash_obj->object_type	=	CONTAINER_NODE;
3427c478bd9Sstevel@tonic-gate 	hash_obj->u.cont_node	=	cont_node;
3437c478bd9Sstevel@tonic-gate 	hash_obj->next		=	NULL;
3447c478bd9Sstevel@tonic-gate 	hash_obj->prev		=	NULL;
3457c478bd9Sstevel@tonic-gate 
3467c478bd9Sstevel@tonic-gate 	return (hash_obj);
3477c478bd9Sstevel@tonic-gate }
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate /*
3507c478bd9Sstevel@tonic-gate  * called to allocate node object for section node.
3517c478bd9Sstevel@tonic-gate  */
3527c478bd9Sstevel@tonic-gate 
3537c478bd9Sstevel@tonic-gate static hash_obj_t *
alloc_section_node_object(picl_nodehdl_t nodehdl,section_t * section)3547c478bd9Sstevel@tonic-gate alloc_section_node_object(picl_nodehdl_t  nodehdl, section_t  *section)
3557c478bd9Sstevel@tonic-gate {
3567c478bd9Sstevel@tonic-gate 	hash_obj_t		*hash_obj;
3577c478bd9Sstevel@tonic-gate 	section_node_t		*sec_node;
3587c478bd9Sstevel@tonic-gate 
3597c478bd9Sstevel@tonic-gate 	/* allocate section node object */
3607c478bd9Sstevel@tonic-gate 	sec_node = malloc(sizeof (section_node_t));
3617c478bd9Sstevel@tonic-gate 	if (sec_node	== NULL) {
3627c478bd9Sstevel@tonic-gate 		return (NULL);
3637c478bd9Sstevel@tonic-gate 	}
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate 	/* allocate section hash object */
3667c478bd9Sstevel@tonic-gate 	hash_obj = malloc(sizeof (hash_obj_t));
3677c478bd9Sstevel@tonic-gate 	if (hash_obj == NULL) {
3687c478bd9Sstevel@tonic-gate 		(void) free(sec_node);
3697c478bd9Sstevel@tonic-gate 		return (NULL);
3707c478bd9Sstevel@tonic-gate 	}
3717c478bd9Sstevel@tonic-gate 
3727c478bd9Sstevel@tonic-gate 	sec_node->section_hdl	=	section->handle; /* fruaccess hdl. */
3737c478bd9Sstevel@tonic-gate 	sec_node->segment_list	=	NULL;
3747c478bd9Sstevel@tonic-gate 	sec_node->next		=	NULL;
3757c478bd9Sstevel@tonic-gate 	sec_node->num_of_segment =	-1;
3767c478bd9Sstevel@tonic-gate 
3777c478bd9Sstevel@tonic-gate 	hash_obj->picl_hdl	=	nodehdl; /* picl node handle */
3787c478bd9Sstevel@tonic-gate 	hash_obj->object_type	=	SECTION_NODE;
3797c478bd9Sstevel@tonic-gate 	hash_obj->u.sec_node	=	sec_node;
3807c478bd9Sstevel@tonic-gate 	hash_obj->next		=	NULL;
3817c478bd9Sstevel@tonic-gate 	hash_obj->prev		=	NULL;
3827c478bd9Sstevel@tonic-gate 
3837c478bd9Sstevel@tonic-gate 	return (hash_obj);
3847c478bd9Sstevel@tonic-gate }
3857c478bd9Sstevel@tonic-gate 
3867c478bd9Sstevel@tonic-gate /*
3877c478bd9Sstevel@tonic-gate  * called to allocate segment node object.
3887c478bd9Sstevel@tonic-gate  */
3897c478bd9Sstevel@tonic-gate 
3907c478bd9Sstevel@tonic-gate static hash_obj_t *
alloc_segment_node_object(picl_nodehdl_t nodehdl,segment_t * segment)3917c478bd9Sstevel@tonic-gate alloc_segment_node_object(picl_nodehdl_t nodehdl, segment_t *segment)
3927c478bd9Sstevel@tonic-gate {
3937c478bd9Sstevel@tonic-gate 	hash_obj_t	*hash_obj;
3947c478bd9Sstevel@tonic-gate 	segment_node_t	*seg_node;
3957c478bd9Sstevel@tonic-gate 
3967c478bd9Sstevel@tonic-gate 	/* allocate segment node object */
3977c478bd9Sstevel@tonic-gate 	seg_node = malloc(sizeof (segment_node_t));
3987c478bd9Sstevel@tonic-gate 	if (seg_node == NULL) {
3997c478bd9Sstevel@tonic-gate 		return (NULL);
4007c478bd9Sstevel@tonic-gate 	}
4017c478bd9Sstevel@tonic-gate 
4027c478bd9Sstevel@tonic-gate 	/* allocate segment hash object */
4037c478bd9Sstevel@tonic-gate 	hash_obj = malloc(sizeof (hash_obj_t));
4047c478bd9Sstevel@tonic-gate 	if (hash_obj == NULL) {
4057c478bd9Sstevel@tonic-gate 		free(seg_node);
4067c478bd9Sstevel@tonic-gate 		return (NULL);
4077c478bd9Sstevel@tonic-gate 	}
4087c478bd9Sstevel@tonic-gate 
4097c478bd9Sstevel@tonic-gate 	/* fruaccess handle */
4107c478bd9Sstevel@tonic-gate 	seg_node->segment_hdl	= segment->handle;
4117c478bd9Sstevel@tonic-gate 	seg_node->packet_list	= NULL;
4127c478bd9Sstevel@tonic-gate 	seg_node->next		= NULL;
4137c478bd9Sstevel@tonic-gate 	seg_node->num_of_pkt	= -1;
4147c478bd9Sstevel@tonic-gate 
4157c478bd9Sstevel@tonic-gate 	/* picl node handle */
4167c478bd9Sstevel@tonic-gate 	hash_obj->picl_hdl	= nodehdl;
4177c478bd9Sstevel@tonic-gate 	hash_obj->object_type	= SEGMENT_NODE;
4187c478bd9Sstevel@tonic-gate 	hash_obj->u.seg_node	= seg_node;
4197c478bd9Sstevel@tonic-gate 	hash_obj->next		= NULL;
4207c478bd9Sstevel@tonic-gate 	hash_obj->prev		= NULL;
4217c478bd9Sstevel@tonic-gate 
4227c478bd9Sstevel@tonic-gate 	return (hash_obj);
4237c478bd9Sstevel@tonic-gate }
4247c478bd9Sstevel@tonic-gate 
4257c478bd9Sstevel@tonic-gate /*
4267c478bd9Sstevel@tonic-gate  * called to allocate node object for packet.
4277c478bd9Sstevel@tonic-gate  */
4287c478bd9Sstevel@tonic-gate 
4297c478bd9Sstevel@tonic-gate static hash_obj_t *
alloc_packet_node_object(picl_nodehdl_t nodehdl,packet_t * packet)4307c478bd9Sstevel@tonic-gate alloc_packet_node_object(picl_nodehdl_t	nodehdl, packet_t *packet)
4317c478bd9Sstevel@tonic-gate {
4327c478bd9Sstevel@tonic-gate 	hash_obj_t	*hash_obj;
4337c478bd9Sstevel@tonic-gate 	packet_node_t	*pkt_node;
4347c478bd9Sstevel@tonic-gate 
4357c478bd9Sstevel@tonic-gate 	/* allocate packet node object */
4367c478bd9Sstevel@tonic-gate 	pkt_node = malloc(sizeof (packet_node_t));
4377c478bd9Sstevel@tonic-gate 	if (pkt_node == NULL) {
4387c478bd9Sstevel@tonic-gate 		return (NULL);
4397c478bd9Sstevel@tonic-gate 	}
4407c478bd9Sstevel@tonic-gate 
4417c478bd9Sstevel@tonic-gate 	/* allocate packet hash object */
4427c478bd9Sstevel@tonic-gate 	hash_obj = malloc(sizeof (hash_obj_t));
4437c478bd9Sstevel@tonic-gate 	if (hash_obj == NULL) {
4447c478bd9Sstevel@tonic-gate 		free(pkt_node);
4457c478bd9Sstevel@tonic-gate 		return (NULL);
4467c478bd9Sstevel@tonic-gate 	}
4477c478bd9Sstevel@tonic-gate 
4487c478bd9Sstevel@tonic-gate 	/* fruaccess handle */
4497c478bd9Sstevel@tonic-gate 	pkt_node->pkt_handle	= packet->handle;
4507c478bd9Sstevel@tonic-gate 	pkt_node->next		= NULL;
4517c478bd9Sstevel@tonic-gate 
4527c478bd9Sstevel@tonic-gate 	hash_obj->picl_hdl	= nodehdl;	/* picl node handle */
4537c478bd9Sstevel@tonic-gate 	hash_obj->object_type	= PACKET_NODE;
4547c478bd9Sstevel@tonic-gate 	hash_obj->u.pkt_node	= pkt_node;
4557c478bd9Sstevel@tonic-gate 	hash_obj->next		= NULL;
4567c478bd9Sstevel@tonic-gate 	hash_obj->prev		= NULL;
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate 	return (hash_obj);
4597c478bd9Sstevel@tonic-gate }
4607c478bd9Sstevel@tonic-gate 
4617c478bd9Sstevel@tonic-gate /* add new section hash object to the section list */
4627c478bd9Sstevel@tonic-gate static void
add_to_section_list(hash_obj_t * container_hash,hash_obj_t * sect_hash)4637c478bd9Sstevel@tonic-gate add_to_section_list(hash_obj_t  *container_hash, hash_obj_t *sect_hash)
4647c478bd9Sstevel@tonic-gate {
4657c478bd9Sstevel@tonic-gate 	hash_obj_t	*next_hash;
4667c478bd9Sstevel@tonic-gate 
4677c478bd9Sstevel@tonic-gate 	sect_hash->u.sec_node->container_hdl = container_hash->picl_hdl;
4687c478bd9Sstevel@tonic-gate 	if (container_hash->u.cont_node->section_list == NULL) {
4697c478bd9Sstevel@tonic-gate 		container_hash->u.cont_node->section_list = sect_hash;
4707c478bd9Sstevel@tonic-gate 		return;
4717c478bd9Sstevel@tonic-gate 	}
4727c478bd9Sstevel@tonic-gate 
4737c478bd9Sstevel@tonic-gate 	for (next_hash = container_hash->u.cont_node->section_list;
4745705cefcSMichael Bergknoff 	    next_hash->u.sec_node->next != NULL;
4755705cefcSMichael Bergknoff 	    next_hash = next_hash->u.sec_node->next) {
4767c478bd9Sstevel@tonic-gate 		;
4777c478bd9Sstevel@tonic-gate 	}
4787c478bd9Sstevel@tonic-gate 
4797c478bd9Sstevel@tonic-gate 	next_hash->u.sec_node->next = sect_hash;
4807c478bd9Sstevel@tonic-gate }
4817c478bd9Sstevel@tonic-gate 
4827c478bd9Sstevel@tonic-gate /* add new segment hash object to the existing list */
4837c478bd9Sstevel@tonic-gate 
4847c478bd9Sstevel@tonic-gate static void
add_to_segment_list(hash_obj_t * parent_obj,hash_obj_t * child_obj)4857c478bd9Sstevel@tonic-gate add_to_segment_list(hash_obj_t *parent_obj, hash_obj_t *child_obj)
4867c478bd9Sstevel@tonic-gate {
4877c478bd9Sstevel@tonic-gate 	hash_obj_t	*next_hash;
4887c478bd9Sstevel@tonic-gate 
4897c478bd9Sstevel@tonic-gate 	child_obj->u.seg_node->sec_nodehdl = parent_obj->picl_hdl;
4907c478bd9Sstevel@tonic-gate 	if (parent_obj->u.sec_node->segment_list == NULL) {
4917c478bd9Sstevel@tonic-gate 		parent_obj->u.sec_node->segment_list = child_obj;
4927c478bd9Sstevel@tonic-gate 		return;
4937c478bd9Sstevel@tonic-gate 	}
4947c478bd9Sstevel@tonic-gate 
4957c478bd9Sstevel@tonic-gate 	for (next_hash = parent_obj->u.sec_node->segment_list;
4965705cefcSMichael Bergknoff 	    next_hash->u.seg_node->next != NULL;
4975705cefcSMichael Bergknoff 	    next_hash = next_hash->u.seg_node->next) {
4987c478bd9Sstevel@tonic-gate 		;
4997c478bd9Sstevel@tonic-gate 	}
5007c478bd9Sstevel@tonic-gate 	next_hash->u.seg_node->next = child_obj;
5017c478bd9Sstevel@tonic-gate }
5027c478bd9Sstevel@tonic-gate 
5037c478bd9Sstevel@tonic-gate /*
5047c478bd9Sstevel@tonic-gate  * called to add packet node object to the existing packet list.
5057c478bd9Sstevel@tonic-gate  */
5067c478bd9Sstevel@tonic-gate static void
add_to_packet_list(hash_obj_t * parent_obj,hash_obj_t * child_obj)5077c478bd9Sstevel@tonic-gate add_to_packet_list(hash_obj_t *parent_obj, hash_obj_t *child_obj)
5087c478bd9Sstevel@tonic-gate {
5097c478bd9Sstevel@tonic-gate 	hash_obj_t	*next_hash;
5107c478bd9Sstevel@tonic-gate 
5117c478bd9Sstevel@tonic-gate 	if (parent_obj->u.seg_node->packet_list == NULL) {
5127c478bd9Sstevel@tonic-gate 		parent_obj->u.seg_node->packet_list = child_obj;
5137c478bd9Sstevel@tonic-gate 		return;
5147c478bd9Sstevel@tonic-gate 	}
5157c478bd9Sstevel@tonic-gate 
5167c478bd9Sstevel@tonic-gate 	for (next_hash = parent_obj->u.seg_node->packet_list;
5175705cefcSMichael Bergknoff 	    next_hash->u.pkt_node->next != NULL;
5185705cefcSMichael Bergknoff 	    next_hash = next_hash->u.pkt_node->next) {
5197c478bd9Sstevel@tonic-gate 		;
5207c478bd9Sstevel@tonic-gate 	}
5217c478bd9Sstevel@tonic-gate 	next_hash->u.pkt_node->next = child_obj;
5227c478bd9Sstevel@tonic-gate }
5237c478bd9Sstevel@tonic-gate 
5247c478bd9Sstevel@tonic-gate /*
5257c478bd9Sstevel@tonic-gate  * free the packet hash list.
5267c478bd9Sstevel@tonic-gate  */
5277c478bd9Sstevel@tonic-gate 
5287c478bd9Sstevel@tonic-gate static void
free_packet_list(hash_obj_t * hash_obj,container_tbl_t * cont_tbl)5297c478bd9Sstevel@tonic-gate free_packet_list(hash_obj_t	*hash_obj, container_tbl_t *cont_tbl)
5307c478bd9Sstevel@tonic-gate {
5317c478bd9Sstevel@tonic-gate 	hash_obj_t	*next_obj;
5327c478bd9Sstevel@tonic-gate 	hash_obj_t	*free_obj;
5337c478bd9Sstevel@tonic-gate 
5347c478bd9Sstevel@tonic-gate 	/* packet hash object list */
5357c478bd9Sstevel@tonic-gate 	next_obj = hash_obj->u.seg_node->packet_list;
5367c478bd9Sstevel@tonic-gate 	while (next_obj != NULL) {
5377c478bd9Sstevel@tonic-gate 		free_obj = next_obj;
5387c478bd9Sstevel@tonic-gate 		next_obj = next_obj->u.pkt_node->next;
5397c478bd9Sstevel@tonic-gate 		if (free_obj->prev == NULL) { /* first node object */
5407c478bd9Sstevel@tonic-gate 			cont_tbl->hash_obj[(free_obj->picl_hdl %
5415705cefcSMichael Bergknoff 			    TABLE_SIZE)].next = free_obj->next;
5427c478bd9Sstevel@tonic-gate 			if (free_obj->next != NULL) {
5437c478bd9Sstevel@tonic-gate 				free_obj->next->prev = NULL;
5447c478bd9Sstevel@tonic-gate 			}
5457c478bd9Sstevel@tonic-gate 		} else {
5467c478bd9Sstevel@tonic-gate 			free_obj->prev->next = free_obj->next;
5477c478bd9Sstevel@tonic-gate 			if (free_obj->next != NULL) {
5487c478bd9Sstevel@tonic-gate 				free_obj->next->prev = free_obj->prev;
5497c478bd9Sstevel@tonic-gate 			}
5507c478bd9Sstevel@tonic-gate 		}
5517c478bd9Sstevel@tonic-gate 
5527c478bd9Sstevel@tonic-gate 		free(free_obj->u.pkt_node);
5537c478bd9Sstevel@tonic-gate 		free(free_obj);
5547c478bd9Sstevel@tonic-gate 	}
5557c478bd9Sstevel@tonic-gate 	hash_obj->u.seg_node->packet_list = NULL;
5567c478bd9Sstevel@tonic-gate }
5577c478bd9Sstevel@tonic-gate 
5587c478bd9Sstevel@tonic-gate /*
5597c478bd9Sstevel@tonic-gate  * free the segment hash node object.
5607c478bd9Sstevel@tonic-gate  */
5617c478bd9Sstevel@tonic-gate 
5627c478bd9Sstevel@tonic-gate static void
free_segment_node(hash_obj_t * hash_obj,picl_nodehdl_t nodehdl,container_tbl_t * cont_tbl)5637c478bd9Sstevel@tonic-gate free_segment_node(hash_obj_t *hash_obj, picl_nodehdl_t nodehdl,
564*ada2da53SToomas Soome     container_tbl_t *cont_tbl)
5657c478bd9Sstevel@tonic-gate {
5667c478bd9Sstevel@tonic-gate 	hash_obj_t	*prev_hash_obj;
5677c478bd9Sstevel@tonic-gate 	hash_obj_t	*next_obj;
5687c478bd9Sstevel@tonic-gate 
5697c478bd9Sstevel@tonic-gate 	/* segment hash object list */
5707c478bd9Sstevel@tonic-gate 	next_obj = hash_obj->u.sec_node->segment_list;
5717c478bd9Sstevel@tonic-gate 	if (next_obj == NULL) {
5727c478bd9Sstevel@tonic-gate 		return;
5737c478bd9Sstevel@tonic-gate 	}
5747c478bd9Sstevel@tonic-gate 
5757c478bd9Sstevel@tonic-gate 	/* find the segment hash from the segment list to be deleted. */
5767c478bd9Sstevel@tonic-gate 	if (next_obj->picl_hdl == nodehdl) {
5777c478bd9Sstevel@tonic-gate 		hash_obj->u.sec_node->segment_list =
5785705cefcSMichael Bergknoff 		    next_obj->u.seg_node->next;
5797c478bd9Sstevel@tonic-gate 	} else {
5807c478bd9Sstevel@tonic-gate 		while (next_obj != NULL) {
5817c478bd9Sstevel@tonic-gate 			if (next_obj->picl_hdl != nodehdl) {
5827c478bd9Sstevel@tonic-gate 				prev_hash_obj = next_obj;
5837c478bd9Sstevel@tonic-gate 				next_obj = next_obj->u.seg_node->next;
5847c478bd9Sstevel@tonic-gate 			} else {
5857c478bd9Sstevel@tonic-gate 				prev_hash_obj->u.seg_node->next =
5865705cefcSMichael Bergknoff 				    next_obj->u.seg_node->next;
5877c478bd9Sstevel@tonic-gate 				break;
5887c478bd9Sstevel@tonic-gate 			}
5897c478bd9Sstevel@tonic-gate 		}
5907c478bd9Sstevel@tonic-gate 
5917c478bd9Sstevel@tonic-gate 		if (next_obj == NULL) {
5927c478bd9Sstevel@tonic-gate 			return;
5937c478bd9Sstevel@tonic-gate 		}
5947c478bd9Sstevel@tonic-gate 
5957c478bd9Sstevel@tonic-gate 	}
5967c478bd9Sstevel@tonic-gate 
5977c478bd9Sstevel@tonic-gate 	if (next_obj->prev == NULL) {
5987c478bd9Sstevel@tonic-gate 		cont_tbl->hash_obj[(next_obj->picl_hdl % TABLE_SIZE)].next =
5995705cefcSMichael Bergknoff 		    next_obj->next;
6007c478bd9Sstevel@tonic-gate 		if (next_obj->next != NULL)
6017c478bd9Sstevel@tonic-gate 			next_obj->next->prev = NULL;
6027c478bd9Sstevel@tonic-gate 	} else {
6037c478bd9Sstevel@tonic-gate 		next_obj->prev->next = next_obj->next;
6047c478bd9Sstevel@tonic-gate 		if (next_obj->next != NULL) {
6057c478bd9Sstevel@tonic-gate 			next_obj->next->prev = next_obj->prev;
6067c478bd9Sstevel@tonic-gate 		}
6077c478bd9Sstevel@tonic-gate 	}
6087c478bd9Sstevel@tonic-gate 
6097c478bd9Sstevel@tonic-gate 	free_packet_list(next_obj, cont_tbl);
6107c478bd9Sstevel@tonic-gate 	free(next_obj->u.seg_node);
6117c478bd9Sstevel@tonic-gate 	free(next_obj);
6127c478bd9Sstevel@tonic-gate }
6137c478bd9Sstevel@tonic-gate 
6147c478bd9Sstevel@tonic-gate 
6157c478bd9Sstevel@tonic-gate /*
6167c478bd9Sstevel@tonic-gate  * Description : frudata_delete_segment is called when volatile property
6177c478bd9Sstevel@tonic-gate  *              delete_segment under class segment is accessed.
6187c478bd9Sstevel@tonic-gate  *
6197c478bd9Sstevel@tonic-gate  * Arguments   : ptree_warg_t is holds node handle of segment node and property
6207c478bd9Sstevel@tonic-gate  *              handle of delete_segment property.
6217c478bd9Sstevel@tonic-gate  */
6227c478bd9Sstevel@tonic-gate 
6237c478bd9Sstevel@tonic-gate /* ARGSUSED */
6247c478bd9Sstevel@tonic-gate static int
frudata_delete_segment(ptree_warg_t * warg,const void * buf)6257c478bd9Sstevel@tonic-gate frudata_delete_segment(ptree_warg_t *warg, const void *buf)
6267c478bd9Sstevel@tonic-gate {
6277c478bd9Sstevel@tonic-gate 	int		retval;
6287c478bd9Sstevel@tonic-gate 	int		num_of_segment;
6297c478bd9Sstevel@tonic-gate 	int		num_of_pkt;
6307c478bd9Sstevel@tonic-gate 	int		pkt_cnt;
6317c478bd9Sstevel@tonic-gate 	int		count;
6327c478bd9Sstevel@tonic-gate 	packet_t	*pkt_buf;
6337c478bd9Sstevel@tonic-gate 	segment_t	*seg_buffer;
6347c478bd9Sstevel@tonic-gate 	hash_obj_t	*seg_hash;
6357c478bd9Sstevel@tonic-gate 	hash_obj_t	*pkt_hash;
6367c478bd9Sstevel@tonic-gate 	hash_obj_t	*hash_obj;
6377c478bd9Sstevel@tonic-gate 	fru_segdesc_t	*desc;
6387c478bd9Sstevel@tonic-gate 	picl_nodehdl_t	sec_nodehdl;
6397c478bd9Sstevel@tonic-gate 	container_tbl_t	*cont_tbl;
6407c478bd9Sstevel@tonic-gate 	fru_access_hdl_t seg_acc_hdl;
6417c478bd9Sstevel@tonic-gate 	fru_access_hdl_t new_sec_acc_hdl;
6427c478bd9Sstevel@tonic-gate 
6437c478bd9Sstevel@tonic-gate 	cont_tbl = lock_container_lock(warg->nodeh, SEGMENT_NODE, PICL_WRITE);
6447c478bd9Sstevel@tonic-gate 	if (!cont_tbl) {
6457c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
6467c478bd9Sstevel@tonic-gate 	}
6477c478bd9Sstevel@tonic-gate 
6487c478bd9Sstevel@tonic-gate 	/* segment hash */
6497c478bd9Sstevel@tonic-gate 	hash_obj = lookup_node_object(warg->nodeh, SEGMENT_NODE, cont_tbl);
6507c478bd9Sstevel@tonic-gate 	if (hash_obj == NULL) {
6517c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
6527c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
6537c478bd9Sstevel@tonic-gate 	}
6547c478bd9Sstevel@tonic-gate 
6557c478bd9Sstevel@tonic-gate 	/* fruaccess segment handle */
6567c478bd9Sstevel@tonic-gate 	seg_acc_hdl	= hash_obj->u.seg_node->segment_hdl;
6577c478bd9Sstevel@tonic-gate 
6587c478bd9Sstevel@tonic-gate 	/* call fruaccess to get new section handle */
6597c478bd9Sstevel@tonic-gate 	if (fru_delete_segment(seg_acc_hdl, &new_sec_acc_hdl, &warg->cred)
6605705cefcSMichael Bergknoff 	    == -1) {
6617c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
6627c478bd9Sstevel@tonic-gate 		return (map_access_err(errno));
6637c478bd9Sstevel@tonic-gate 	}
6647c478bd9Sstevel@tonic-gate 
6657c478bd9Sstevel@tonic-gate 	if (ptree_delete_node(warg->nodeh) != PICL_SUCCESS) {
6667c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
6677c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
6687c478bd9Sstevel@tonic-gate 	}
6697c478bd9Sstevel@tonic-gate 
6707c478bd9Sstevel@tonic-gate 	if (ptree_destroy_node(warg->nodeh) != PICL_SUCCESS) {
6717c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
6727c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
6737c478bd9Sstevel@tonic-gate 	}
6747c478bd9Sstevel@tonic-gate 
6757c478bd9Sstevel@tonic-gate 
6767c478bd9Sstevel@tonic-gate 	/* get section node handle */
6777c478bd9Sstevel@tonic-gate 	sec_nodehdl = hash_obj->u.seg_node->sec_nodehdl;
6787c478bd9Sstevel@tonic-gate 	/* get section hash */
6797c478bd9Sstevel@tonic-gate 	hash_obj = lookup_node_object(sec_nodehdl, SECTION_NODE, cont_tbl);
6807c478bd9Sstevel@tonic-gate 	if (hash_obj == NULL) {
6817c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
6827c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
6837c478bd9Sstevel@tonic-gate 	}
6847c478bd9Sstevel@tonic-gate 
6857c478bd9Sstevel@tonic-gate 	free_segment_node(hash_obj, warg->nodeh, cont_tbl);
6867c478bd9Sstevel@tonic-gate 
6877c478bd9Sstevel@tonic-gate 	hash_obj->u.sec_node->num_of_segment = 0;
6887c478bd9Sstevel@tonic-gate 
6897c478bd9Sstevel@tonic-gate 	/* call fruaccess with new section handle */
6907c478bd9Sstevel@tonic-gate 	num_of_segment = fru_get_num_segments(new_sec_acc_hdl, &warg->cred);
6917c478bd9Sstevel@tonic-gate 	if (num_of_segment <= 0) {
6927c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
6937c478bd9Sstevel@tonic-gate 		return (PICL_SUCCESS);
6947c478bd9Sstevel@tonic-gate 	}
6957c478bd9Sstevel@tonic-gate 
6967c478bd9Sstevel@tonic-gate 	seg_buffer = alloca(sizeof (segment_t) * num_of_segment);
6977c478bd9Sstevel@tonic-gate 	if (seg_buffer == NULL) {
6987c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
6997c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
7007c478bd9Sstevel@tonic-gate 	}
7017c478bd9Sstevel@tonic-gate 
7027c478bd9Sstevel@tonic-gate 	/* get all the segments */
7037c478bd9Sstevel@tonic-gate 	retval = fru_get_segments(new_sec_acc_hdl, seg_buffer,
7045705cefcSMichael Bergknoff 	    num_of_segment, &warg->cred);
7057c478bd9Sstevel@tonic-gate 	if (retval == -1) {
7067c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
7077c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
7087c478bd9Sstevel@tonic-gate 	}
7097c478bd9Sstevel@tonic-gate 
7107c478bd9Sstevel@tonic-gate 	seg_hash = hash_obj->u.sec_node->segment_list;
7117c478bd9Sstevel@tonic-gate 	if (seg_hash == NULL) {
7127c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
7137c478bd9Sstevel@tonic-gate 		return (PICL_SUCCESS);
7147c478bd9Sstevel@tonic-gate 	}
7157c478bd9Sstevel@tonic-gate 
7167c478bd9Sstevel@tonic-gate 	/* rebuild the segment list */
7177c478bd9Sstevel@tonic-gate 	for (count = 0; count < num_of_segment; count++) {
7187c478bd9Sstevel@tonic-gate 		desc	= (fru_segdesc_t *)&seg_buffer[count].descriptor;
7197c478bd9Sstevel@tonic-gate 		if (!(desc->field.field_perm & SEGMENT_READ)) {
720161c3e5aSps 			seg_hash = seg_hash->u.seg_node->next;
7217c478bd9Sstevel@tonic-gate 			continue;
7227c478bd9Sstevel@tonic-gate 		}
7237c478bd9Sstevel@tonic-gate 
7247c478bd9Sstevel@tonic-gate 		if (desc->field.opaque) {
725161c3e5aSps 			seg_hash = seg_hash->u.seg_node->next;
7267c478bd9Sstevel@tonic-gate 			continue;
7277c478bd9Sstevel@tonic-gate 		}
7287c478bd9Sstevel@tonic-gate 
7297c478bd9Sstevel@tonic-gate 		hash_obj->u.sec_node->num_of_segment++;
7307c478bd9Sstevel@tonic-gate 
7317c478bd9Sstevel@tonic-gate 		seg_hash->u.seg_node->segment_hdl = seg_buffer[count].handle;
7327c478bd9Sstevel@tonic-gate 
7335705cefcSMichael Bergknoff 		num_of_pkt = fru_get_num_packets(seg_buffer[count].handle,
7345705cefcSMichael Bergknoff 		    &warg->cred);
7357c478bd9Sstevel@tonic-gate 		if (num_of_pkt <= 0) {
736161c3e5aSps 			seg_hash = seg_hash->u.seg_node->next;
7377c478bd9Sstevel@tonic-gate 			continue;
7387c478bd9Sstevel@tonic-gate 		}
7397c478bd9Sstevel@tonic-gate 
7407c478bd9Sstevel@tonic-gate 		pkt_buf	= alloca(sizeof (packet_t) * num_of_pkt);
7417c478bd9Sstevel@tonic-gate 		if (pkt_buf == NULL) {
7427c478bd9Sstevel@tonic-gate 			unlock_container_lock(cont_tbl);
7437c478bd9Sstevel@tonic-gate 			return (PICL_FAILURE);
7447c478bd9Sstevel@tonic-gate 		}
7457c478bd9Sstevel@tonic-gate 
7467c478bd9Sstevel@tonic-gate 		retval = fru_get_packets(seg_buffer[count].handle, pkt_buf,
7475705cefcSMichael Bergknoff 		    num_of_pkt, &warg->cred);
7487c478bd9Sstevel@tonic-gate 		if (retval == -1) {
749161c3e5aSps 			seg_hash = seg_hash->u.seg_node->next;
7507c478bd9Sstevel@tonic-gate 			continue;
7517c478bd9Sstevel@tonic-gate 		}
7527c478bd9Sstevel@tonic-gate 
7537c478bd9Sstevel@tonic-gate 		pkt_hash = seg_hash->u.seg_node->packet_list;
7547c478bd9Sstevel@tonic-gate 		if (pkt_hash == NULL) {
755161c3e5aSps 			seg_hash = seg_hash->u.seg_node->next;
7567c478bd9Sstevel@tonic-gate 			continue;
7577c478bd9Sstevel@tonic-gate 		}
7587c478bd9Sstevel@tonic-gate 
7597c478bd9Sstevel@tonic-gate 		/* rebuild the packet list */
7607c478bd9Sstevel@tonic-gate 		for (pkt_cnt = 0; pkt_cnt < num_of_pkt; pkt_cnt++) {
7617c478bd9Sstevel@tonic-gate 			pkt_hash->u.pkt_node->pkt_handle =
7625705cefcSMichael Bergknoff 			    pkt_buf[pkt_cnt].handle;
7637c478bd9Sstevel@tonic-gate 			pkt_hash = pkt_hash->u.pkt_node->next;
7647c478bd9Sstevel@tonic-gate 		}
7657c478bd9Sstevel@tonic-gate 
7667c478bd9Sstevel@tonic-gate 		seg_hash = seg_hash->u.seg_node->next;
7677c478bd9Sstevel@tonic-gate 		if (seg_hash == NULL) {
7687c478bd9Sstevel@tonic-gate 			break;
7697c478bd9Sstevel@tonic-gate 		}
7707c478bd9Sstevel@tonic-gate 	}
7717c478bd9Sstevel@tonic-gate 
7727c478bd9Sstevel@tonic-gate 	/* updated with new section handle */
7737c478bd9Sstevel@tonic-gate 	hash_obj->u.sec_node->section_hdl = new_sec_acc_hdl;
7747c478bd9Sstevel@tonic-gate 
7757c478bd9Sstevel@tonic-gate 	unlock_container_lock(cont_tbl);
7767c478bd9Sstevel@tonic-gate 
7777c478bd9Sstevel@tonic-gate 	return (PICL_SUCCESS);
7787c478bd9Sstevel@tonic-gate }
7797c478bd9Sstevel@tonic-gate 
7807c478bd9Sstevel@tonic-gate /*
7817c478bd9Sstevel@tonic-gate  * Description : frudata_read_payload is called when volatile property
7827c478bd9Sstevel@tonic-gate  *              payload is read.
7837c478bd9Sstevel@tonic-gate  *
7847c478bd9Sstevel@tonic-gate  * Arguments    : ptree_rarg_t  holds node handle of the table property.
7857c478bd9Sstevel@tonic-gate  *              and property handle of the payload cell.
7867c478bd9Sstevel@tonic-gate  *              p_buf contains payload data when function returns.
7877c478bd9Sstevel@tonic-gate  *
7887c478bd9Sstevel@tonic-gate  * Returns      : PICL_SUCCESS on success.
7897c478bd9Sstevel@tonic-gate  *              PICL_FAILURE on failure.
7907c478bd9Sstevel@tonic-gate  */
7917c478bd9Sstevel@tonic-gate 
7927c478bd9Sstevel@tonic-gate static int
frudata_read_payload(ptree_rarg_t * rarg,void * buf)7937c478bd9Sstevel@tonic-gate frudata_read_payload(ptree_rarg_t *rarg, void *buf)
7947c478bd9Sstevel@tonic-gate {
7957c478bd9Sstevel@tonic-gate 	int		num_bytes;
7967c478bd9Sstevel@tonic-gate 	hash_obj_t	*hash_obj;
7977c478bd9Sstevel@tonic-gate 	fru_access_hdl_t pkt_acc_hdl;
7987c478bd9Sstevel@tonic-gate 	container_tbl_t	*cont_tbl;
7997c478bd9Sstevel@tonic-gate 
8007c478bd9Sstevel@tonic-gate 
8017c478bd9Sstevel@tonic-gate 	cont_tbl = lock_container_lock(rarg->nodeh, SEGMENT_NODE, PICL_READ);
8027c478bd9Sstevel@tonic-gate 	if (!cont_tbl) {
8037c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
8047c478bd9Sstevel@tonic-gate 	}
8057c478bd9Sstevel@tonic-gate 
8067c478bd9Sstevel@tonic-gate 	hash_obj = lookup_node_object(rarg->proph, PACKET_NODE, cont_tbl);
8077c478bd9Sstevel@tonic-gate 	if (hash_obj == NULL) {
8087c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
8097c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
8107c478bd9Sstevel@tonic-gate 	}
8117c478bd9Sstevel@tonic-gate 
8127c478bd9Sstevel@tonic-gate 	pkt_acc_hdl = hash_obj->u.pkt_node->pkt_handle;
8137c478bd9Sstevel@tonic-gate 
8147c478bd9Sstevel@tonic-gate 	num_bytes = fru_get_payload(pkt_acc_hdl, buf,
8155705cefcSMichael Bergknoff 	    hash_obj->u.pkt_node->paylen, &rarg->cred);
8167c478bd9Sstevel@tonic-gate 	if (num_bytes != hash_obj->u.pkt_node->paylen) {
8177c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
8187c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
8197c478bd9Sstevel@tonic-gate 	}
8207c478bd9Sstevel@tonic-gate 
8217c478bd9Sstevel@tonic-gate 	unlock_container_lock(cont_tbl);
8227c478bd9Sstevel@tonic-gate 
8237c478bd9Sstevel@tonic-gate 	return (PICL_SUCCESS);
8247c478bd9Sstevel@tonic-gate }
8257c478bd9Sstevel@tonic-gate 
8267c478bd9Sstevel@tonic-gate /*
8277c478bd9Sstevel@tonic-gate  * Description : frudata_write_payload is called when payload property cell
8287c478bd9Sstevel@tonic-gate  *              is accessed.
8297c478bd9Sstevel@tonic-gate  *
8307c478bd9Sstevel@tonic-gate  * Arguments    : ptree_warg_t holds node handle of the packet-table.
8317c478bd9Sstevel@tonic-gate  *              and property handle of the payload cell.
8327c478bd9Sstevel@tonic-gate  *              p_buf contains payload data.
8337c478bd9Sstevel@tonic-gate  *
8347c478bd9Sstevel@tonic-gate  * Returns      : PICL_SUCCESS on success.
8357c478bd9Sstevel@tonic-gate  *
8367c478bd9Sstevel@tonic-gate  */
8377c478bd9Sstevel@tonic-gate 
8387c478bd9Sstevel@tonic-gate static int
frudata_write_payload(ptree_warg_t * warg,const void * buf)8397c478bd9Sstevel@tonic-gate frudata_write_payload(ptree_warg_t *warg, const void *buf)
8407c478bd9Sstevel@tonic-gate {
8417c478bd9Sstevel@tonic-gate 	int		retval;
8427c478bd9Sstevel@tonic-gate 	hash_obj_t	*hash_obj;
8437c478bd9Sstevel@tonic-gate 	fru_access_hdl_t pkt_acc_hdl;
8447c478bd9Sstevel@tonic-gate 	container_tbl_t	*cont_tbl;
8457c478bd9Sstevel@tonic-gate 
8467c478bd9Sstevel@tonic-gate 	cont_tbl = lock_container_lock(warg->nodeh, SEGMENT_NODE, PICL_WRITE);
8477c478bd9Sstevel@tonic-gate 	if (!cont_tbl) {
8487c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
8497c478bd9Sstevel@tonic-gate 	}
8507c478bd9Sstevel@tonic-gate 
8517c478bd9Sstevel@tonic-gate 	hash_obj = lookup_node_object(warg->proph, PACKET_NODE, cont_tbl);
8527c478bd9Sstevel@tonic-gate 	if (hash_obj == NULL) {
8537c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
8547c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
8557c478bd9Sstevel@tonic-gate 	}
8567c478bd9Sstevel@tonic-gate 
8577c478bd9Sstevel@tonic-gate 	pkt_acc_hdl = hash_obj->u.pkt_node->pkt_handle;
8587c478bd9Sstevel@tonic-gate 
8597c478bd9Sstevel@tonic-gate 	retval = fru_update_payload(pkt_acc_hdl, buf,
8605705cefcSMichael Bergknoff 	    hash_obj->u.pkt_node->paylen,
8615705cefcSMichael Bergknoff 	    &pkt_acc_hdl, &warg->cred);
8627c478bd9Sstevel@tonic-gate 	if (retval == -1) {
8637c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
8647c478bd9Sstevel@tonic-gate 		return (map_access_err(errno));
8657c478bd9Sstevel@tonic-gate 	}
8667c478bd9Sstevel@tonic-gate 
8677c478bd9Sstevel@tonic-gate 	hash_obj->u.pkt_node->pkt_handle = pkt_acc_hdl;
8687c478bd9Sstevel@tonic-gate 
8697c478bd9Sstevel@tonic-gate 	unlock_container_lock(cont_tbl);
8707c478bd9Sstevel@tonic-gate 
8717c478bd9Sstevel@tonic-gate 	return (PICL_SUCCESS);
8727c478bd9Sstevel@tonic-gate }
8737c478bd9Sstevel@tonic-gate 
8747c478bd9Sstevel@tonic-gate /*
8757c478bd9Sstevel@tonic-gate  * callback volatile function is called when tag volatile property
8767c478bd9Sstevel@tonic-gate  * is accessed. this routine holds a read lock over the hash table
8777c478bd9Sstevel@tonic-gate  * and do a lookup over the property handle i.e property handle of
8787c478bd9Sstevel@tonic-gate  * the tag property passed in rarg parameter.
8797c478bd9Sstevel@tonic-gate  * tag value is copied into the buffer (void *buf).
8807c478bd9Sstevel@tonic-gate  */
8817c478bd9Sstevel@tonic-gate 
8827c478bd9Sstevel@tonic-gate static int
frudata_read_tag(ptree_rarg_t * rarg,void * buf)8837c478bd9Sstevel@tonic-gate frudata_read_tag(ptree_rarg_t	*rarg, void *buf)
8847c478bd9Sstevel@tonic-gate {
8857c478bd9Sstevel@tonic-gate 	int		retval;
8867c478bd9Sstevel@tonic-gate 	hash_obj_t	*hash_obj;
8877c478bd9Sstevel@tonic-gate 	picl_prophdl_t	rowproph;
8887c478bd9Sstevel@tonic-gate 	container_tbl_t	*cont_tbl;
8897c478bd9Sstevel@tonic-gate 
8907c478bd9Sstevel@tonic-gate 	cont_tbl = lock_container_lock(rarg->nodeh, SEGMENT_NODE, PICL_READ);
8917c478bd9Sstevel@tonic-gate 	if (!cont_tbl) {
8927c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
8937c478bd9Sstevel@tonic-gate 	}
8947c478bd9Sstevel@tonic-gate 
8957c478bd9Sstevel@tonic-gate 	retval = ptree_get_next_by_row(rarg->proph, &rowproph);
8967c478bd9Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
8977c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
8987c478bd9Sstevel@tonic-gate 		return (retval);
8997c478bd9Sstevel@tonic-gate 	}
9007c478bd9Sstevel@tonic-gate 
9017c478bd9Sstevel@tonic-gate 	hash_obj = lookup_node_object(rowproph, PACKET_NODE, cont_tbl);
9027c478bd9Sstevel@tonic-gate 	if (hash_obj == NULL) {
9037c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
9047c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
9057c478bd9Sstevel@tonic-gate 	}
9067c478bd9Sstevel@tonic-gate 
9077c478bd9Sstevel@tonic-gate 	(void) memcpy(buf, &hash_obj->u.pkt_node->tag, sizeof (tag_t));
9087c478bd9Sstevel@tonic-gate 
9097c478bd9Sstevel@tonic-gate 	unlock_container_lock(cont_tbl);
9107c478bd9Sstevel@tonic-gate 	return (PICL_SUCCESS);
9117c478bd9Sstevel@tonic-gate }
9127c478bd9Sstevel@tonic-gate 
9137c478bd9Sstevel@tonic-gate 
9147c478bd9Sstevel@tonic-gate /*
9157c478bd9Sstevel@tonic-gate  * Description : create_packet_table() is called by fru_delete_packet_row(),
9167c478bd9Sstevel@tonic-gate  *              to create a packet-table volatile property. it's called after
9177c478bd9Sstevel@tonic-gate  *              deleting the packet-table. fru_delete_packet_row() calls
9187c478bd9Sstevel@tonic-gate  *              frudata_read_packet_table() to add rows into the table.
9197c478bd9Sstevel@tonic-gate  */
9207c478bd9Sstevel@tonic-gate 
9217c478bd9Sstevel@tonic-gate static int
create_packet_table(picl_nodehdl_t seghdl,picl_prophdl_t * thdl)9227c478bd9Sstevel@tonic-gate create_packet_table(picl_nodehdl_t seghdl, picl_prophdl_t *thdl)
9237c478bd9Sstevel@tonic-gate {
9247c478bd9Sstevel@tonic-gate 	int			retval;
9257c478bd9Sstevel@tonic-gate 	picl_prophdl_t		tblhdl;
9267c478bd9Sstevel@tonic-gate 	picl_nodehdl_t		prophdl;
9277c478bd9Sstevel@tonic-gate 	ptree_propinfo_t	prop;
9287c478bd9Sstevel@tonic-gate 
9297c478bd9Sstevel@tonic-gate 	retval = ptree_create_table(&tblhdl);
9307c478bd9Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
9317c478bd9Sstevel@tonic-gate 		return (retval);
9327c478bd9Sstevel@tonic-gate 	}
9337c478bd9Sstevel@tonic-gate 
9347c478bd9Sstevel@tonic-gate 	prop.version = PTREE_PROPINFO_VERSION;
9357c478bd9Sstevel@tonic-gate 	prop.piclinfo.type =  PICL_PTYPE_TABLE;
9367c478bd9Sstevel@tonic-gate 	prop.piclinfo.accessmode = PICL_READ|PICL_WRITE;
9377c478bd9Sstevel@tonic-gate 	prop.piclinfo.size = sizeof (picl_prophdl_t);
9387c478bd9Sstevel@tonic-gate 	prop.read = NULL;
9397c478bd9Sstevel@tonic-gate 	prop.write = NULL;
9407c478bd9Sstevel@tonic-gate 	(void) strcpy(prop.piclinfo.name, PICL_PROP_PACKET_TABLE);
9417c478bd9Sstevel@tonic-gate 
9427c478bd9Sstevel@tonic-gate 	retval = ptree_create_and_add_prop(seghdl, &prop, &tblhdl,
9435705cefcSMichael Bergknoff 	    &prophdl);
9447c478bd9Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
9457c478bd9Sstevel@tonic-gate 		return (retval);
9467c478bd9Sstevel@tonic-gate 	}
9477c478bd9Sstevel@tonic-gate 
9487c478bd9Sstevel@tonic-gate 	/* hold the table handle */
9497c478bd9Sstevel@tonic-gate 	*thdl = tblhdl;
9507c478bd9Sstevel@tonic-gate 
9517c478bd9Sstevel@tonic-gate 	return (PICL_SUCCESS);
9527c478bd9Sstevel@tonic-gate }
9537c478bd9Sstevel@tonic-gate 
9547c478bd9Sstevel@tonic-gate /*
9557c478bd9Sstevel@tonic-gate  * Description : frudata_delete_packet is called when write operation is
9567c478bd9Sstevel@tonic-gate  *		performed on tag volatile property.
9577c478bd9Sstevel@tonic-gate  *
9587c478bd9Sstevel@tonic-gate  *
9597c478bd9Sstevel@tonic-gate  * Arguments    : ptree_warg_t holds node handle to the segment node.
9607c478bd9Sstevel@tonic-gate  *              and property handle of the tag cell in the packet table to be
9617c478bd9Sstevel@tonic-gate  *		deleted.
9627c478bd9Sstevel@tonic-gate  *              buf contains the tag data + plus DELETE_KEY_TAG
9637c478bd9Sstevel@tonic-gate  *
9647c478bd9Sstevel@tonic-gate  * Returns      : PICL_SUCCESS on success
9657c478bd9Sstevel@tonic-gate  *
9667c478bd9Sstevel@tonic-gate  */
9677c478bd9Sstevel@tonic-gate 
9687c478bd9Sstevel@tonic-gate static int
frudata_delete_packet(ptree_warg_t * warg,const void * buf)9697c478bd9Sstevel@tonic-gate frudata_delete_packet(ptree_warg_t *warg, const void *buf)
9707c478bd9Sstevel@tonic-gate {
9717c478bd9Sstevel@tonic-gate 	int		count = 0;
9727c478bd9Sstevel@tonic-gate 	int		retval;
9737c478bd9Sstevel@tonic-gate 	int		num_of_pkt;
9747c478bd9Sstevel@tonic-gate 	uint64_t	tag;
9757c478bd9Sstevel@tonic-gate 	packet_t	*packet;
9767c478bd9Sstevel@tonic-gate 	hash_obj_t	*seg_hash_obj;
9777c478bd9Sstevel@tonic-gate 	hash_obj_t	*pkt_hash_obj;
9787c478bd9Sstevel@tonic-gate 	container_tbl_t	*cont_tbl;
9797c478bd9Sstevel@tonic-gate 	picl_prophdl_t	tblhdl;
9807c478bd9Sstevel@tonic-gate 	picl_prophdl_t	rowproph;
9817c478bd9Sstevel@tonic-gate 	fru_access_hdl_t new_seg_acc_hdl;
9827c478bd9Sstevel@tonic-gate 
9837c478bd9Sstevel@tonic-gate 	cont_tbl = lock_container_lock(warg->nodeh, SEGMENT_NODE, PICL_WRITE);
9847c478bd9Sstevel@tonic-gate 	if (!cont_tbl) {
9857c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
9867c478bd9Sstevel@tonic-gate 	}
9877c478bd9Sstevel@tonic-gate 
9887c478bd9Sstevel@tonic-gate 	/* get the payload property handle */
9897c478bd9Sstevel@tonic-gate 	retval = ptree_get_next_by_row(warg->proph, &rowproph);
9907c478bd9Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
9917c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
9927c478bd9Sstevel@tonic-gate 		return (retval);
9937c478bd9Sstevel@tonic-gate 	}
9947c478bd9Sstevel@tonic-gate 
9957c478bd9Sstevel@tonic-gate 	/* do lookup on payload property handle */
9967c478bd9Sstevel@tonic-gate 	pkt_hash_obj = lookup_node_object(rowproph, PACKET_NODE, cont_tbl);
9977c478bd9Sstevel@tonic-gate 	if (pkt_hash_obj == NULL) {
9987c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
9997c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
10007c478bd9Sstevel@tonic-gate 	}
10017c478bd9Sstevel@tonic-gate 
10027c478bd9Sstevel@tonic-gate 	/* verify the tag */
10037c478bd9Sstevel@tonic-gate 	tag = pkt_hash_obj->u.pkt_node->tag.raw_data;
10047c478bd9Sstevel@tonic-gate 	tag &= FRUDATA_DELETE_TAG_MASK;
10057c478bd9Sstevel@tonic-gate 	tag |= FRUDATA_DELETE_TAG_KEY;
10067c478bd9Sstevel@tonic-gate 	if (*(uint64_t *)buf != tag) {
10077c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
10087c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
10097c478bd9Sstevel@tonic-gate 	}
10107c478bd9Sstevel@tonic-gate 
10117c478bd9Sstevel@tonic-gate 	/* call fruaccess module */
10127c478bd9Sstevel@tonic-gate 	retval = fru_delete_packet(pkt_hash_obj->u.pkt_node->pkt_handle,
10135705cefcSMichael Bergknoff 	    &new_seg_acc_hdl, &warg->cred);
10147c478bd9Sstevel@tonic-gate 	if (retval == -1) {
10157c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
10167c478bd9Sstevel@tonic-gate 		return (map_access_err(errno));
10177c478bd9Sstevel@tonic-gate 	}
10187c478bd9Sstevel@tonic-gate 
10197c478bd9Sstevel@tonic-gate 	/* delete the packet table */
10207c478bd9Sstevel@tonic-gate 	retval = ptree_get_prop_by_name(warg->nodeh, PICL_PROP_PACKET_TABLE,
10215705cefcSMichael Bergknoff 	    &tblhdl);
10227c478bd9Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
10237c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
10247c478bd9Sstevel@tonic-gate 		return (retval);
10257c478bd9Sstevel@tonic-gate 	}
10267c478bd9Sstevel@tonic-gate 
10277c478bd9Sstevel@tonic-gate 	retval = ptree_delete_prop(tblhdl);
10287c478bd9Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
10297c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
10307c478bd9Sstevel@tonic-gate 		return (retval);
10317c478bd9Sstevel@tonic-gate 	}
10327c478bd9Sstevel@tonic-gate 
10337c478bd9Sstevel@tonic-gate 	retval = ptree_destroy_prop(tblhdl);
10347c478bd9Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
10357c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
10367c478bd9Sstevel@tonic-gate 		return (retval);
10377c478bd9Sstevel@tonic-gate 	}
10387c478bd9Sstevel@tonic-gate 
10397c478bd9Sstevel@tonic-gate 
10407c478bd9Sstevel@tonic-gate 	seg_hash_obj = lookup_node_object(warg->nodeh, SEGMENT_NODE,
10415705cefcSMichael Bergknoff 	    cont_tbl);
10427c478bd9Sstevel@tonic-gate 	if (seg_hash_obj == NULL) {
10437c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
10447c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
10457c478bd9Sstevel@tonic-gate 	}
10467c478bd9Sstevel@tonic-gate 
10477c478bd9Sstevel@tonic-gate 	/* free all packet hash object */
10487c478bd9Sstevel@tonic-gate 	free_packet_list(seg_hash_obj, cont_tbl);
10497c478bd9Sstevel@tonic-gate 
10507c478bd9Sstevel@tonic-gate 	/* recreate the packet table */
10517c478bd9Sstevel@tonic-gate 	retval = create_packet_table(warg->nodeh, &tblhdl);
10527c478bd9Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
10537c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
10547c478bd9Sstevel@tonic-gate 		return (retval);
10557c478bd9Sstevel@tonic-gate 	}
10567c478bd9Sstevel@tonic-gate 
10577c478bd9Sstevel@tonic-gate 	seg_hash_obj->u.seg_node->segment_hdl = new_seg_acc_hdl;
10587c478bd9Sstevel@tonic-gate 
10597c478bd9Sstevel@tonic-gate 	seg_hash_obj->u.seg_node->num_of_pkt = 0;
10607c478bd9Sstevel@tonic-gate 
10617c478bd9Sstevel@tonic-gate 	num_of_pkt = fru_get_num_packets(new_seg_acc_hdl, &warg->cred);
10627c478bd9Sstevel@tonic-gate 	if (num_of_pkt == -1) {
10637c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
10647c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
10657c478bd9Sstevel@tonic-gate 	}
10667c478bd9Sstevel@tonic-gate 
10677c478bd9Sstevel@tonic-gate 	if (num_of_pkt == 0) {
10687c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
10697c478bd9Sstevel@tonic-gate 		return (PICL_SUCCESS);
10707c478bd9Sstevel@tonic-gate 	}
10717c478bd9Sstevel@tonic-gate 
10727c478bd9Sstevel@tonic-gate 	packet = alloca(sizeof (packet_t) * num_of_pkt);
10737c478bd9Sstevel@tonic-gate 	if (packet == NULL) {
10747c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
10757c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
10767c478bd9Sstevel@tonic-gate 	}
10777c478bd9Sstevel@tonic-gate 
10787c478bd9Sstevel@tonic-gate 	retval = fru_get_packets(new_seg_acc_hdl, packet,
10795705cefcSMichael Bergknoff 	    num_of_pkt, &warg->cred);
10807c478bd9Sstevel@tonic-gate 	if (retval == -1) {
10817c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
10827c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
10837c478bd9Sstevel@tonic-gate 	}
10847c478bd9Sstevel@tonic-gate 
10857c478bd9Sstevel@tonic-gate 	/* rebuild the packet hash object */
10867c478bd9Sstevel@tonic-gate 	for (count = 0; count < num_of_pkt; count++) {
10877c478bd9Sstevel@tonic-gate 		(void) add_row_to_table(seg_hash_obj, tblhdl, packet+count,
10885705cefcSMichael Bergknoff 		    cont_tbl);
10897c478bd9Sstevel@tonic-gate 	}
10907c478bd9Sstevel@tonic-gate 
10917c478bd9Sstevel@tonic-gate 	seg_hash_obj->u.seg_node->num_of_pkt = num_of_pkt;
10927c478bd9Sstevel@tonic-gate 
10937c478bd9Sstevel@tonic-gate 	(void) ptree_update_propval_by_name(warg->nodeh, PICL_PROP_NUM_TAGS,
10945705cefcSMichael Bergknoff 	    &num_of_pkt, sizeof (uint32_t));
10957c478bd9Sstevel@tonic-gate 
10967c478bd9Sstevel@tonic-gate 	unlock_container_lock(cont_tbl);
10977c478bd9Sstevel@tonic-gate 
10987c478bd9Sstevel@tonic-gate 	return (PICL_SUCCESS);
10997c478bd9Sstevel@tonic-gate }
11007c478bd9Sstevel@tonic-gate 
11017c478bd9Sstevel@tonic-gate /*
11027c478bd9Sstevel@tonic-gate  * called from frudata_delete_packet(), frudata_add_packet(),
11037c478bd9Sstevel@tonic-gate  * frudata_read_packet() callback routine to add packet into
11047c478bd9Sstevel@tonic-gate  * the packet table. it also create hash node object for each
11057c478bd9Sstevel@tonic-gate  * individual packet and add the object to the packet list.
11067c478bd9Sstevel@tonic-gate  */
11077c478bd9Sstevel@tonic-gate 
11087c478bd9Sstevel@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)11097c478bd9Sstevel@tonic-gate add_row_to_table(hash_obj_t *seg_obj, picl_nodehdl_t tblhdl, packet_t *pkt,
1110*ada2da53SToomas Soome     container_tbl_t *cont_tbl)
11117c478bd9Sstevel@tonic-gate {
11127c478bd9Sstevel@tonic-gate 	int			retval;
11137c478bd9Sstevel@tonic-gate 	int			paylen;
11147c478bd9Sstevel@tonic-gate 	size_t			tag_size;
11157c478bd9Sstevel@tonic-gate 	hash_obj_t		*hash_obj;
11167c478bd9Sstevel@tonic-gate 	fru_tagtype_t		tagtype;
11177c478bd9Sstevel@tonic-gate 	picl_prophdl_t		prophdl[NUM_OF_COL_IN_PKT_TABLE];
11187c478bd9Sstevel@tonic-gate 	ptree_propinfo_t	prop;
11197c478bd9Sstevel@tonic-gate 
11207c478bd9Sstevel@tonic-gate 	prop.version = PTREE_PROPINFO_VERSION;
11217c478bd9Sstevel@tonic-gate 
11227c478bd9Sstevel@tonic-gate 	prop.piclinfo.type =  PICL_PTYPE_BYTEARRAY;
11237c478bd9Sstevel@tonic-gate 	prop.piclinfo.accessmode = PICL_READ|PICL_WRITE|PICL_VOLATILE;
11247c478bd9Sstevel@tonic-gate 	prop.piclinfo.size = sizeof (fru_tag_t);
11257c478bd9Sstevel@tonic-gate 	prop.read = frudata_read_tag;
11267c478bd9Sstevel@tonic-gate 	prop.write = frudata_delete_packet;
11277c478bd9Sstevel@tonic-gate 
11287c478bd9Sstevel@tonic-gate 	/* tag property node */
11297c478bd9Sstevel@tonic-gate 	(void) strcpy(prop.piclinfo.name, PICL_PROP_TAG);
11307c478bd9Sstevel@tonic-gate 
11317c478bd9Sstevel@tonic-gate 	paylen = get_payload_length((void *)&pkt->tag);
11327c478bd9Sstevel@tonic-gate 	if (paylen < 0) {
11337c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
11347c478bd9Sstevel@tonic-gate 	}
11357c478bd9Sstevel@tonic-gate 
11367c478bd9Sstevel@tonic-gate 	retval = ptree_create_prop(&prop, NULL, &prophdl[0]);
11377c478bd9Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
11387c478bd9Sstevel@tonic-gate 		return (retval);
11397c478bd9Sstevel@tonic-gate 	}
11407c478bd9Sstevel@tonic-gate 
11417c478bd9Sstevel@tonic-gate 
11427c478bd9Sstevel@tonic-gate 	/* payload property node */
11437c478bd9Sstevel@tonic-gate 	prop.piclinfo.type =  PICL_PTYPE_BYTEARRAY;
11447c478bd9Sstevel@tonic-gate 	prop.piclinfo.size = paylen;
11457c478bd9Sstevel@tonic-gate 	(void) strcpy(prop.piclinfo.name, PICL_PROP_PAYLOAD);
11467c478bd9Sstevel@tonic-gate 	prop.piclinfo.accessmode = PICL_READ|PICL_WRITE|PICL_VOLATILE;
11477c478bd9Sstevel@tonic-gate 	prop.read = frudata_read_payload;
11487c478bd9Sstevel@tonic-gate 	prop.write = frudata_write_payload;
11497c478bd9Sstevel@tonic-gate 
11507c478bd9Sstevel@tonic-gate 	retval = ptree_create_prop(&prop, NULL, &prophdl[1]);
11517c478bd9Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
11527c478bd9Sstevel@tonic-gate 		return (retval);
11537c478bd9Sstevel@tonic-gate 	}
11547c478bd9Sstevel@tonic-gate 
11557c478bd9Sstevel@tonic-gate 	hash_obj = alloc_packet_node_object(prophdl[1], pkt);
11567c478bd9Sstevel@tonic-gate 	if (hash_obj == NULL) {
11577c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
11587c478bd9Sstevel@tonic-gate 	}
11597c478bd9Sstevel@tonic-gate 
11607c478bd9Sstevel@tonic-gate 	retval = ptree_add_row_to_table(tblhdl, NUM_OF_COL_IN_PKT_TABLE,
11615705cefcSMichael Bergknoff 	    prophdl);
11627c478bd9Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
11637c478bd9Sstevel@tonic-gate 		free(hash_obj);
11647c478bd9Sstevel@tonic-gate 		return (retval);
11657c478bd9Sstevel@tonic-gate 	}
11667c478bd9Sstevel@tonic-gate 
11677c478bd9Sstevel@tonic-gate 	tagtype = get_tag_type((fru_tag_t *)&pkt->tag);
11687c478bd9Sstevel@tonic-gate 	if (tagtype == -1) {
11697c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
11707c478bd9Sstevel@tonic-gate 	}
11717c478bd9Sstevel@tonic-gate 
11727c478bd9Sstevel@tonic-gate 	tag_size = get_tag_size(tagtype);
11737c478bd9Sstevel@tonic-gate 	if (tag_size == (size_t)-1) {
11747c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
11757c478bd9Sstevel@tonic-gate 	}
11767c478bd9Sstevel@tonic-gate 
11777c478bd9Sstevel@tonic-gate 	hash_obj->u.pkt_node->paylen = paylen;
11787c478bd9Sstevel@tonic-gate 	hash_obj->u.pkt_node->tag.raw_data = 0;
11797c478bd9Sstevel@tonic-gate 	(void) memcpy(&hash_obj->u.pkt_node->tag, &pkt->tag, tag_size);
11807c478bd9Sstevel@tonic-gate 
11817c478bd9Sstevel@tonic-gate 	add_nodeobject_to_hashtable(hash_obj, cont_tbl);
11827c478bd9Sstevel@tonic-gate 
11837c478bd9Sstevel@tonic-gate 	add_to_packet_list(seg_obj, hash_obj);
11847c478bd9Sstevel@tonic-gate 
11857c478bd9Sstevel@tonic-gate 	return (PICL_SUCCESS);
11867c478bd9Sstevel@tonic-gate }
11877c478bd9Sstevel@tonic-gate 
11887c478bd9Sstevel@tonic-gate /*
11897c478bd9Sstevel@tonic-gate  * called from frudata_read_segment() callback routine. it's called after
11907c478bd9Sstevel@tonic-gate  * creating the packet table under class segment. this routine reads the
11917c478bd9Sstevel@tonic-gate  * segment data to get total number of packets in the segments and add
11927c478bd9Sstevel@tonic-gate  * the tag and payload data into the table. it calls add_row_to_table
11937c478bd9Sstevel@tonic-gate  * routine to add individual row into the packet table.
11947c478bd9Sstevel@tonic-gate  */
11957c478bd9Sstevel@tonic-gate 
11967c478bd9Sstevel@tonic-gate static int
frudata_read_packet(picl_nodehdl_t nodeh,picl_prophdl_t * tblhdl,container_tbl_t * cont_tbl,door_cred_t * cred)11977c478bd9Sstevel@tonic-gate frudata_read_packet(picl_nodehdl_t nodeh, picl_prophdl_t *tblhdl,
1198*ada2da53SToomas Soome     container_tbl_t *cont_tbl, door_cred_t *cred)
11997c478bd9Sstevel@tonic-gate {
12007c478bd9Sstevel@tonic-gate 	int		cnt;
12017c478bd9Sstevel@tonic-gate 	int		retval;
12027c478bd9Sstevel@tonic-gate 	int		num_of_pkt;
12037c478bd9Sstevel@tonic-gate 	packet_t	*packet;
12047c478bd9Sstevel@tonic-gate 	hash_obj_t	*hash_obj;
12057c478bd9Sstevel@tonic-gate 	fru_access_hdl_t seg_acc_hdl;
12067c478bd9Sstevel@tonic-gate 
12077c478bd9Sstevel@tonic-gate 	hash_obj = lookup_node_object(nodeh, SEGMENT_NODE, cont_tbl);
12087c478bd9Sstevel@tonic-gate 	if (hash_obj == NULL) {
12097c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
12107c478bd9Sstevel@tonic-gate 	}
12117c478bd9Sstevel@tonic-gate 
12127c478bd9Sstevel@tonic-gate 	if (hash_obj->u.seg_node->num_of_pkt == -1) {
12137c478bd9Sstevel@tonic-gate 		/* get the access handle */
12147c478bd9Sstevel@tonic-gate 		seg_acc_hdl = hash_obj->u.seg_node->segment_hdl;
12157c478bd9Sstevel@tonic-gate 		/* get total number of packets */
12167c478bd9Sstevel@tonic-gate 		num_of_pkt = fru_get_num_packets(seg_acc_hdl, cred);
12177c478bd9Sstevel@tonic-gate 		if (num_of_pkt < 0) {
12187c478bd9Sstevel@tonic-gate 			hash_obj->u.seg_node->num_of_pkt = 0;
12197c478bd9Sstevel@tonic-gate 			return (map_access_err(errno));
12207c478bd9Sstevel@tonic-gate 		}
12217c478bd9Sstevel@tonic-gate 
12227c478bd9Sstevel@tonic-gate 		if (num_of_pkt == 0) {
12237c478bd9Sstevel@tonic-gate 			hash_obj->u.seg_node->num_of_pkt = 0;
12247c478bd9Sstevel@tonic-gate 			return (0);
12257c478bd9Sstevel@tonic-gate 		}
12267c478bd9Sstevel@tonic-gate 
12277c478bd9Sstevel@tonic-gate 		/* allocate buffer */
12287c478bd9Sstevel@tonic-gate 		packet = alloca(sizeof (packet_t) * num_of_pkt);
12297c478bd9Sstevel@tonic-gate 		if (packet == NULL) {
12307c478bd9Sstevel@tonic-gate 			hash_obj->u.seg_node->num_of_pkt = 0;
12317c478bd9Sstevel@tonic-gate 			return (0);
12327c478bd9Sstevel@tonic-gate 		}
12337c478bd9Sstevel@tonic-gate 
12347c478bd9Sstevel@tonic-gate 		/* get all the packet into the packet buffer */
12357c478bd9Sstevel@tonic-gate 		retval = fru_get_packets(seg_acc_hdl, packet, num_of_pkt, cred);
12367c478bd9Sstevel@tonic-gate 		if (retval == -1) {
12377c478bd9Sstevel@tonic-gate 			return (0);
12387c478bd9Sstevel@tonic-gate 		}
12397c478bd9Sstevel@tonic-gate 
12407c478bd9Sstevel@tonic-gate 		/* add payload and tag into the table. */
12417c478bd9Sstevel@tonic-gate 		for (cnt = 0; cnt < num_of_pkt; cnt++) {
12427c478bd9Sstevel@tonic-gate 			(void) add_row_to_table(hash_obj, *tblhdl, packet+cnt,
12435705cefcSMichael Bergknoff 			    cont_tbl);
12447c478bd9Sstevel@tonic-gate 		}
12457c478bd9Sstevel@tonic-gate 
12467c478bd9Sstevel@tonic-gate 		hash_obj->u.seg_node->num_of_pkt = num_of_pkt;
12477c478bd9Sstevel@tonic-gate 	}
12487c478bd9Sstevel@tonic-gate 	return (0);
12497c478bd9Sstevel@tonic-gate }
12507c478bd9Sstevel@tonic-gate 
12517c478bd9Sstevel@tonic-gate 
12527c478bd9Sstevel@tonic-gate /*
12537c478bd9Sstevel@tonic-gate  * Description  : frudata_add_packet is called when add-packet volatile
12547c478bd9Sstevel@tonic-gate  *              property is accessed.
12557c478bd9Sstevel@tonic-gate  *
12567c478bd9Sstevel@tonic-gate  * Arguments    : ptree_warg_t holds node handle of the segment node and
12577c478bd9Sstevel@tonic-gate  *              property handle of add-packet property.
12587c478bd9Sstevel@tonic-gate  *              p_buf- contains packet data to be added.
12597c478bd9Sstevel@tonic-gate  *
12607c478bd9Sstevel@tonic-gate  * Return       : PICL_SUCCESS on success.
12617c478bd9Sstevel@tonic-gate  *
12627c478bd9Sstevel@tonic-gate  */
12637c478bd9Sstevel@tonic-gate 
12647c478bd9Sstevel@tonic-gate /* ARGSUSED */
12657c478bd9Sstevel@tonic-gate static int
frudata_add_packet(ptree_warg_t * warg,const void * buf)12667c478bd9Sstevel@tonic-gate frudata_add_packet(ptree_warg_t *warg, const void *buf)
12677c478bd9Sstevel@tonic-gate {
12687c478bd9Sstevel@tonic-gate 	size_t		tag_size;
12697c478bd9Sstevel@tonic-gate 	int		paylen;
12707c478bd9Sstevel@tonic-gate 	int		retval;
12717c478bd9Sstevel@tonic-gate 	int		num_of_pkt;
12727c478bd9Sstevel@tonic-gate 	int		cnt;
12737c478bd9Sstevel@tonic-gate 	packet_t	packet;
12747c478bd9Sstevel@tonic-gate 	packet_t	*pkt_buf;
12757c478bd9Sstevel@tonic-gate 	hash_obj_t	*hash_obj;
12767c478bd9Sstevel@tonic-gate 	hash_obj_t	*pkt_hash;
12777c478bd9Sstevel@tonic-gate 	container_tbl_t	*cont_tbl;
12787c478bd9Sstevel@tonic-gate 	fru_tagtype_t	tagtype;
12797c478bd9Sstevel@tonic-gate 	picl_prophdl_t	tblhdl;
12807c478bd9Sstevel@tonic-gate 	fru_access_hdl_t seg_acc_hdl;
12817c478bd9Sstevel@tonic-gate 	fru_access_hdl_t new_seg_acc_hdl;
12827c478bd9Sstevel@tonic-gate 
12837c478bd9Sstevel@tonic-gate 	cont_tbl = lock_container_lock(warg->nodeh, SEGMENT_NODE, PICL_WRITE);
12847c478bd9Sstevel@tonic-gate 	if (!cont_tbl) {
12857c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
12867c478bd9Sstevel@tonic-gate 	}
12877c478bd9Sstevel@tonic-gate 
12887c478bd9Sstevel@tonic-gate 	hash_obj = lookup_node_object(warg->nodeh, SEGMENT_NODE, cont_tbl);
12897c478bd9Sstevel@tonic-gate 	if (hash_obj == NULL) {
12907c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
12917c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
12927c478bd9Sstevel@tonic-gate 	}
12937c478bd9Sstevel@tonic-gate 
12947c478bd9Sstevel@tonic-gate 	seg_acc_hdl = hash_obj->u.seg_node->segment_hdl;
12957c478bd9Sstevel@tonic-gate 
12967c478bd9Sstevel@tonic-gate 	tagtype = get_tag_type((void *)buf);
12977c478bd9Sstevel@tonic-gate 	if (tagtype == -1) {
12987c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
12997c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
13007c478bd9Sstevel@tonic-gate 	}
13017c478bd9Sstevel@tonic-gate 
13027c478bd9Sstevel@tonic-gate 	tag_size = get_tag_size(tagtype);
13037c478bd9Sstevel@tonic-gate 	if (tag_size == (size_t)-1) {
13047c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
13057c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
13067c478bd9Sstevel@tonic-gate 	}
13077c478bd9Sstevel@tonic-gate 
13087c478bd9Sstevel@tonic-gate 	paylen = get_payload_length((void *)buf);
13097c478bd9Sstevel@tonic-gate 	if (paylen == -1) {
13107c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
13117c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
13127c478bd9Sstevel@tonic-gate 	}
13137c478bd9Sstevel@tonic-gate 
13147c478bd9Sstevel@tonic-gate 	packet.tag = 0;
13157c478bd9Sstevel@tonic-gate 	(void) memcpy(&packet.tag, buf, tag_size);
13167c478bd9Sstevel@tonic-gate 
13177c478bd9Sstevel@tonic-gate 	retval = fru_append_packet(seg_acc_hdl, &packet, (char *)buf + tag_size,
13185705cefcSMichael Bergknoff 	    paylen, &new_seg_acc_hdl, &warg->cred);
13197c478bd9Sstevel@tonic-gate 	if (retval == -1) {
13207c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
13217c478bd9Sstevel@tonic-gate 		return (map_access_err(errno));
13227c478bd9Sstevel@tonic-gate 	}
13237c478bd9Sstevel@tonic-gate 
13247c478bd9Sstevel@tonic-gate 	retval = ptree_get_propval_by_name(warg->nodeh,
13255705cefcSMichael Bergknoff 	    PICL_PROP_PACKET_TABLE, &tblhdl, sizeof (picl_prophdl_t));
13267c478bd9Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
13277c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
13287c478bd9Sstevel@tonic-gate 		return (retval);
13297c478bd9Sstevel@tonic-gate 	}
13307c478bd9Sstevel@tonic-gate 	retval = add_row_to_table(hash_obj, tblhdl, &packet, cont_tbl);
13317c478bd9Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
13327c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
13337c478bd9Sstevel@tonic-gate 		return (retval);
13347c478bd9Sstevel@tonic-gate 	}
13357c478bd9Sstevel@tonic-gate 
13367c478bd9Sstevel@tonic-gate 	num_of_pkt = fru_get_num_packets(new_seg_acc_hdl, &warg->cred);
13377c478bd9Sstevel@tonic-gate 	if (num_of_pkt == -1) {
13387c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
13397c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
13407c478bd9Sstevel@tonic-gate 	}
13417c478bd9Sstevel@tonic-gate 
13427c478bd9Sstevel@tonic-gate 	pkt_buf = alloca(sizeof (packet_t) * num_of_pkt);
13437c478bd9Sstevel@tonic-gate 	if (pkt_buf == NULL) {
13447c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
13457c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
13467c478bd9Sstevel@tonic-gate 	}
13477c478bd9Sstevel@tonic-gate 
13487c478bd9Sstevel@tonic-gate 	retval = fru_get_packets(new_seg_acc_hdl, pkt_buf,
13495705cefcSMichael Bergknoff 	    num_of_pkt, &warg->cred);
13507c478bd9Sstevel@tonic-gate 	if (retval == -1) {
13517c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
13527c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
13537c478bd9Sstevel@tonic-gate 	}
13547c478bd9Sstevel@tonic-gate 
13557c478bd9Sstevel@tonic-gate 	pkt_hash	= hash_obj->u.seg_node->packet_list;
13567c478bd9Sstevel@tonic-gate 	if (pkt_hash == NULL) {
13577c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
13587c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
13597c478bd9Sstevel@tonic-gate 	}
13607c478bd9Sstevel@tonic-gate 
13617c478bd9Sstevel@tonic-gate 	for (cnt = 0; cnt < num_of_pkt; cnt++) {
13627c478bd9Sstevel@tonic-gate 		pkt_hash->u.pkt_node->pkt_handle = pkt_buf[cnt].handle;
13637c478bd9Sstevel@tonic-gate 		pkt_hash = pkt_hash->u.pkt_node->next;
13647c478bd9Sstevel@tonic-gate 	}
13657c478bd9Sstevel@tonic-gate 
13667c478bd9Sstevel@tonic-gate 	hash_obj->u.seg_node->num_of_pkt = num_of_pkt;
13677c478bd9Sstevel@tonic-gate 
13687c478bd9Sstevel@tonic-gate 	(void) ptree_update_propval_by_name(warg->nodeh, PICL_PROP_NUM_TAGS,
13695705cefcSMichael Bergknoff 	    &num_of_pkt, sizeof (uint32_t));
13707c478bd9Sstevel@tonic-gate 
13717c478bd9Sstevel@tonic-gate 	unlock_container_lock(cont_tbl);
13727c478bd9Sstevel@tonic-gate 
13737c478bd9Sstevel@tonic-gate 	return (PICL_SUCCESS);
13747c478bd9Sstevel@tonic-gate }
13757c478bd9Sstevel@tonic-gate 
13767c478bd9Sstevel@tonic-gate static void
freeup(picl_nodehdl_t nodeh)13777c478bd9Sstevel@tonic-gate freeup(picl_nodehdl_t nodeh)
13787c478bd9Sstevel@tonic-gate {
13797c478bd9Sstevel@tonic-gate 	(void) ptree_delete_node(nodeh);
13807c478bd9Sstevel@tonic-gate 	(void) ptree_destroy_node(nodeh);
13817c478bd9Sstevel@tonic-gate }
13827c478bd9Sstevel@tonic-gate 
13837c478bd9Sstevel@tonic-gate /*
13847c478bd9Sstevel@tonic-gate  * called by frudata_read_segment() and fru_data_add_segment() callback routine.
13857c478bd9Sstevel@tonic-gate  * it's called to create a segment node and all it's property beneith the
13867c478bd9Sstevel@tonic-gate  * segment node in the picl tree.
13877c478bd9Sstevel@tonic-gate  */
13887c478bd9Sstevel@tonic-gate 
13897c478bd9Sstevel@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)13907c478bd9Sstevel@tonic-gate create_segment_node(hash_obj_t *sec_obj, picl_nodehdl_t sec_node,
1391*ada2da53SToomas Soome     segment_t *segment, container_tbl_t *cont_tbl, door_cred_t *cred)
13927c478bd9Sstevel@tonic-gate {
13937c478bd9Sstevel@tonic-gate 
13947c478bd9Sstevel@tonic-gate 	int			retval;
13957c478bd9Sstevel@tonic-gate 	char			segname[SEG_NAME_LEN + 1];
13967c478bd9Sstevel@tonic-gate 	uint32_t		numoftags = 0;
13977c478bd9Sstevel@tonic-gate 	uint32_t		protection;
13987c478bd9Sstevel@tonic-gate 	hash_obj_t		*hash_obj;
13997c478bd9Sstevel@tonic-gate 	picl_nodehdl_t		nodehdl;
14007c478bd9Sstevel@tonic-gate 	picl_prophdl_t		prophdl;
14017c478bd9Sstevel@tonic-gate 	picl_nodehdl_t		tblhdl;
14027c478bd9Sstevel@tonic-gate 	ptree_propinfo_t	prop;
14037c478bd9Sstevel@tonic-gate 
14047c478bd9Sstevel@tonic-gate 	(void) strlcpy(segname, segment->name, SEG_NAME_LEN + 1);
14057c478bd9Sstevel@tonic-gate 	segname[SEG_NAME_LEN] = '\0';
14067c478bd9Sstevel@tonic-gate 
14077c478bd9Sstevel@tonic-gate 	if (!(isprint(segname[0]) || isprint(segname[1]))) {
14087c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
14097c478bd9Sstevel@tonic-gate 	}
14107c478bd9Sstevel@tonic-gate 
14117c478bd9Sstevel@tonic-gate 	if (ptree_create_node(segname, PICL_CLASS_SEGMENT, &nodehdl)
14125705cefcSMichael Bergknoff 	    != PICL_SUCCESS) {
14137c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
14147c478bd9Sstevel@tonic-gate 	}
14157c478bd9Sstevel@tonic-gate 
14167c478bd9Sstevel@tonic-gate 
14177c478bd9Sstevel@tonic-gate 	/* create property node */
14187c478bd9Sstevel@tonic-gate 	prop.version = PTREE_PROPINFO_VERSION;
14197c478bd9Sstevel@tonic-gate 	prop.piclinfo.accessmode = PICL_READ;
14207c478bd9Sstevel@tonic-gate 	prop.read		= NULL;
14217c478bd9Sstevel@tonic-gate 	prop.write		= NULL;
14227c478bd9Sstevel@tonic-gate 
14237c478bd9Sstevel@tonic-gate 	prop.piclinfo.type =  PICL_PTYPE_UNSIGNED_INT;
14247c478bd9Sstevel@tonic-gate 	prop.piclinfo.size = sizeof (uint32_t);
14257c478bd9Sstevel@tonic-gate 
14267c478bd9Sstevel@tonic-gate 	/* descriptor property */
14277c478bd9Sstevel@tonic-gate 	(void) strcpy(prop.piclinfo.name, PICL_PROP_DESCRIPTOR);
14287c478bd9Sstevel@tonic-gate 	if (ptree_create_and_add_prop(nodehdl, &prop, &segment->descriptor,
14295705cefcSMichael Bergknoff 	    &prophdl) != PICL_SUCCESS) {
14307c478bd9Sstevel@tonic-gate 		freeup(nodehdl);
14317c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
14327c478bd9Sstevel@tonic-gate 	}
14337c478bd9Sstevel@tonic-gate 
14347c478bd9Sstevel@tonic-gate 
14357c478bd9Sstevel@tonic-gate 	/* offset property */
14367c478bd9Sstevel@tonic-gate 	(void) strcpy(prop.piclinfo.name, PICL_PROP_OFFSET);
14377c478bd9Sstevel@tonic-gate 	if (ptree_create_and_add_prop(nodehdl, &prop, &segment->offset,
14385705cefcSMichael Bergknoff 	    &prophdl) != PICL_SUCCESS) {
14397c478bd9Sstevel@tonic-gate 		freeup(nodehdl);
14407c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
14417c478bd9Sstevel@tonic-gate 	}
14427c478bd9Sstevel@tonic-gate 
14437c478bd9Sstevel@tonic-gate 
14447c478bd9Sstevel@tonic-gate 	/* length property */
14457c478bd9Sstevel@tonic-gate 	(void) strcpy(prop.piclinfo.name, PICL_PROP_LENGTH);
14467c478bd9Sstevel@tonic-gate 	if (ptree_create_and_add_prop(nodehdl, &prop, &segment->length,
14475705cefcSMichael Bergknoff 	    &prophdl) != PICL_SUCCESS) {
14487c478bd9Sstevel@tonic-gate 		freeup(nodehdl);
14497c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
14507c478bd9Sstevel@tonic-gate 	}
14517c478bd9Sstevel@tonic-gate 
14527c478bd9Sstevel@tonic-gate 	/* Number of Tags */
14537c478bd9Sstevel@tonic-gate 	(void) strcpy(prop.piclinfo.name, PICL_PROP_NUM_TAGS);
14547c478bd9Sstevel@tonic-gate 	if (ptree_create_and_add_prop(nodehdl, &prop, &numoftags, &prophdl)
14555705cefcSMichael Bergknoff 	    != PICL_SUCCESS) {
14567c478bd9Sstevel@tonic-gate 		freeup(nodehdl);
14577c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
14587c478bd9Sstevel@tonic-gate 	}
14597c478bd9Sstevel@tonic-gate 
14607c478bd9Sstevel@tonic-gate 	if (create_packet_table(nodehdl, &tblhdl) != PICL_SUCCESS) {
14617c478bd9Sstevel@tonic-gate 		freeup(nodehdl);
14627c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
14637c478bd9Sstevel@tonic-gate 	}
14647c478bd9Sstevel@tonic-gate 
14657c478bd9Sstevel@tonic-gate 	retval = ptree_get_propval_by_name(sec_node,
14665705cefcSMichael Bergknoff 	    PICL_PROP_PROTECTED, &protection, sizeof (uint32_t));
14677c478bd9Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
14687c478bd9Sstevel@tonic-gate 		freeup(nodehdl);
14697c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
14707c478bd9Sstevel@tonic-gate 	}
14717c478bd9Sstevel@tonic-gate 
14727c478bd9Sstevel@tonic-gate 	if (protection == 0) {	/* to be added only read/write section */
14737c478bd9Sstevel@tonic-gate 		/* delete segment volatile property */
14747c478bd9Sstevel@tonic-gate 		prop.piclinfo.type =  PICL_PTYPE_UNSIGNED_INT;
14757c478bd9Sstevel@tonic-gate 		prop.piclinfo.size = sizeof (uint32_t);
14767c478bd9Sstevel@tonic-gate 		prop.piclinfo.accessmode = PICL_WRITE|PICL_VOLATILE;
14777c478bd9Sstevel@tonic-gate 		prop.write = frudata_delete_segment;
14787c478bd9Sstevel@tonic-gate 		prop.read = frudata_read_callback;
14797c478bd9Sstevel@tonic-gate 
14807c478bd9Sstevel@tonic-gate 		(void) strcpy(prop.piclinfo.name, PICL_PROP_DELETE_SEGMENT);
14817c478bd9Sstevel@tonic-gate 		if (ptree_create_and_add_prop(nodehdl, &prop, NULL, &prophdl)
14825705cefcSMichael Bergknoff 		    != PICL_SUCCESS) {
14837c478bd9Sstevel@tonic-gate 			freeup(nodehdl);
14847c478bd9Sstevel@tonic-gate 			return (PICL_FAILURE);
14857c478bd9Sstevel@tonic-gate 		}
14867c478bd9Sstevel@tonic-gate 
14877c478bd9Sstevel@tonic-gate 
14887c478bd9Sstevel@tonic-gate 		/* add packet volatile property */
14897c478bd9Sstevel@tonic-gate 		prop.piclinfo.type =  PICL_PTYPE_BYTEARRAY;
14907c478bd9Sstevel@tonic-gate 		prop.piclinfo.size = segment->length; /* segment length */
14917c478bd9Sstevel@tonic-gate 		prop.piclinfo.accessmode = PICL_READ|PICL_WRITE|PICL_VOLATILE;
14927c478bd9Sstevel@tonic-gate 		prop.read = frudata_read_callback;
14937c478bd9Sstevel@tonic-gate 		prop.write = frudata_add_packet;
14947c478bd9Sstevel@tonic-gate 
14957c478bd9Sstevel@tonic-gate 		(void) strcpy(prop.piclinfo.name, PICL_PROP_ADD_PACKET);
14967c478bd9Sstevel@tonic-gate 		if (ptree_create_and_add_prop(nodehdl, &prop, NULL, &prophdl)
14975705cefcSMichael Bergknoff 		    != PICL_SUCCESS) {
14987c478bd9Sstevel@tonic-gate 			freeup(nodehdl);
14997c478bd9Sstevel@tonic-gate 			return (PICL_FAILURE);
15007c478bd9Sstevel@tonic-gate 		}
15017c478bd9Sstevel@tonic-gate 	}
15027c478bd9Sstevel@tonic-gate 
15037c478bd9Sstevel@tonic-gate 	if (ptree_add_node(sec_node, nodehdl) != PICL_SUCCESS) {
15047c478bd9Sstevel@tonic-gate 		freeup(nodehdl);
15057c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
15067c478bd9Sstevel@tonic-gate 	}
15077c478bd9Sstevel@tonic-gate 
15087c478bd9Sstevel@tonic-gate 	hash_obj = alloc_segment_node_object(nodehdl, segment);
15097c478bd9Sstevel@tonic-gate 	if (hash_obj == NULL) {
15107c478bd9Sstevel@tonic-gate 		freeup(nodehdl);
15117c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
15127c478bd9Sstevel@tonic-gate 	}
15137c478bd9Sstevel@tonic-gate 
15147c478bd9Sstevel@tonic-gate 	add_nodeobject_to_hashtable(hash_obj, cont_tbl);
15157c478bd9Sstevel@tonic-gate 
15167c478bd9Sstevel@tonic-gate 	add_to_segment_list(sec_obj, hash_obj);
15177c478bd9Sstevel@tonic-gate 
15187c478bd9Sstevel@tonic-gate 	retval = frudata_read_packet(nodehdl, &tblhdl, cont_tbl, cred);
15197c478bd9Sstevel@tonic-gate 	if (retval != 0) {
15207c478bd9Sstevel@tonic-gate 		return (PICL_SUCCESS);
15217c478bd9Sstevel@tonic-gate 	}
15227c478bd9Sstevel@tonic-gate 
15237c478bd9Sstevel@tonic-gate 	(void) ptree_update_propval_by_name(nodehdl, PICL_PROP_NUM_TAGS,
15245705cefcSMichael Bergknoff 	    &hash_obj->u.seg_node->num_of_pkt, sizeof (uint32_t));
15257c478bd9Sstevel@tonic-gate 
15267c478bd9Sstevel@tonic-gate 	return (PICL_SUCCESS);
15277c478bd9Sstevel@tonic-gate }
15287c478bd9Sstevel@tonic-gate 
15297c478bd9Sstevel@tonic-gate /*
15307c478bd9Sstevel@tonic-gate  * Description  :frudata_read_segment is called when num_segment volatile
15317c478bd9Sstevel@tonic-gate  *              property is accessed.
15327c478bd9Sstevel@tonic-gate  *
15337c478bd9Sstevel@tonic-gate  * Arguments    : ptree_rarg_t  contains node handle of the section node.
15347c478bd9Sstevel@tonic-gate  *                      and property node of num_segments.
15357c478bd9Sstevel@tonic-gate  *              void * will hold number of segment.
15367c478bd9Sstevel@tonic-gate  *
15377c478bd9Sstevel@tonic-gate  * Returns      : PICL_SUCCESS on success.
15387c478bd9Sstevel@tonic-gate  *              PICL_FAILURE on failure.
15397c478bd9Sstevel@tonic-gate  */
15407c478bd9Sstevel@tonic-gate 
15417c478bd9Sstevel@tonic-gate static int
frudata_read_segment(ptree_rarg_t * rarg,void * buf)15427c478bd9Sstevel@tonic-gate frudata_read_segment(ptree_rarg_t *rarg, void *buf)
15437c478bd9Sstevel@tonic-gate {
15447c478bd9Sstevel@tonic-gate 	int		num_of_segment;
15457c478bd9Sstevel@tonic-gate 	int		cnt;
15467c478bd9Sstevel@tonic-gate 	int		retval;
15477c478bd9Sstevel@tonic-gate 	segment_t	*segment;
15487c478bd9Sstevel@tonic-gate 	hash_obj_t	*hash_obj;
15497c478bd9Sstevel@tonic-gate 	fru_segdesc_t	*desc;
15507c478bd9Sstevel@tonic-gate 	fru_access_hdl_t sec_acc_hdl;
15517c478bd9Sstevel@tonic-gate 	container_tbl_t	*cont_tbl;
15527c478bd9Sstevel@tonic-gate 
15537c478bd9Sstevel@tonic-gate 	cont_tbl = lock_container_lock(rarg->nodeh, SECTION_NODE, PICL_READ);
15547c478bd9Sstevel@tonic-gate 	if (!cont_tbl) {
15557c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
15567c478bd9Sstevel@tonic-gate 	}
15577c478bd9Sstevel@tonic-gate 
15587c478bd9Sstevel@tonic-gate 	hash_obj = lookup_node_object(rarg->nodeh, SECTION_NODE, cont_tbl);
15597c478bd9Sstevel@tonic-gate 	if (hash_obj == NULL) {
15607c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
15617c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
15627c478bd9Sstevel@tonic-gate 	}
15637c478bd9Sstevel@tonic-gate 
15647c478bd9Sstevel@tonic-gate 	if (hash_obj->u.sec_node->num_of_segment == -1) {
15657c478bd9Sstevel@tonic-gate 		sec_acc_hdl	= hash_obj->u.sec_node->section_hdl;
15667c478bd9Sstevel@tonic-gate 
15677c478bd9Sstevel@tonic-gate 		hash_obj->u.sec_node->num_of_segment = 0;
15687c478bd9Sstevel@tonic-gate 
15697c478bd9Sstevel@tonic-gate 		num_of_segment = fru_get_num_segments(sec_acc_hdl,
15705705cefcSMichael Bergknoff 		    &rarg->cred);
15717c478bd9Sstevel@tonic-gate 		if (num_of_segment < 0) {
15727c478bd9Sstevel@tonic-gate 			*(int *)buf = 0;
15737c478bd9Sstevel@tonic-gate 			unlock_container_lock(cont_tbl);
15747c478bd9Sstevel@tonic-gate 			return (PICL_FAILURE);
15757c478bd9Sstevel@tonic-gate 		}
15767c478bd9Sstevel@tonic-gate 
15777c478bd9Sstevel@tonic-gate 		if (num_of_segment == 0) {
15787c478bd9Sstevel@tonic-gate 			*(int *)buf = 0;
15797c478bd9Sstevel@tonic-gate 			unlock_container_lock(cont_tbl);
15807c478bd9Sstevel@tonic-gate 			return (PICL_SUCCESS);
15817c478bd9Sstevel@tonic-gate 		}
15827c478bd9Sstevel@tonic-gate 
15837c478bd9Sstevel@tonic-gate 		segment = alloca(sizeof (segment_t) * num_of_segment);
15847c478bd9Sstevel@tonic-gate 		if (segment == NULL) {
15857c478bd9Sstevel@tonic-gate 			*(int *)buf = 0;
15867c478bd9Sstevel@tonic-gate 			unlock_container_lock(cont_tbl);
15877c478bd9Sstevel@tonic-gate 			return (PICL_SUCCESS);
15887c478bd9Sstevel@tonic-gate 		}
15897c478bd9Sstevel@tonic-gate 
15907c478bd9Sstevel@tonic-gate 		retval = fru_get_segments(sec_acc_hdl, segment,
15915705cefcSMichael Bergknoff 		    num_of_segment, &rarg->cred);
15927c478bd9Sstevel@tonic-gate 		if (retval == -1) {
15937c478bd9Sstevel@tonic-gate 			*(int *)buf = 0;
15947c478bd9Sstevel@tonic-gate 			unlock_container_lock(cont_tbl);
15957c478bd9Sstevel@tonic-gate 			return (PICL_SUCCESS);
15967c478bd9Sstevel@tonic-gate 		}
15977c478bd9Sstevel@tonic-gate 
15987c478bd9Sstevel@tonic-gate 		for (cnt = 0; cnt < num_of_segment; cnt++) {
15997c478bd9Sstevel@tonic-gate 
16007c478bd9Sstevel@tonic-gate 			desc	= (fru_segdesc_t *)&segment[cnt].descriptor;
16017c478bd9Sstevel@tonic-gate 			if (!(desc->field.field_perm & SEGMENT_READ)) {
16027c478bd9Sstevel@tonic-gate 				continue;
16037c478bd9Sstevel@tonic-gate 			}
16047c478bd9Sstevel@tonic-gate 
16057c478bd9Sstevel@tonic-gate 			/* if opaque segment don't create segment node */
16067c478bd9Sstevel@tonic-gate 			if (desc->field.opaque) {
16077c478bd9Sstevel@tonic-gate 				continue;
16087c478bd9Sstevel@tonic-gate 			}
16097c478bd9Sstevel@tonic-gate 			(void) create_segment_node(hash_obj, rarg->nodeh,
16105705cefcSMichael Bergknoff 			    &segment[cnt], cont_tbl, &rarg->cred);
16117c478bd9Sstevel@tonic-gate 			hash_obj->u.sec_node->num_of_segment++;
16127c478bd9Sstevel@tonic-gate 		}
16137c478bd9Sstevel@tonic-gate 	}
16147c478bd9Sstevel@tonic-gate 
16157c478bd9Sstevel@tonic-gate 	/* return number of segment in the section */
16167c478bd9Sstevel@tonic-gate 	*(int *)buf = hash_obj->u.sec_node->num_of_segment;
16177c478bd9Sstevel@tonic-gate 
16187c478bd9Sstevel@tonic-gate 	unlock_container_lock(cont_tbl);
16197c478bd9Sstevel@tonic-gate 
16207c478bd9Sstevel@tonic-gate 	return (PICL_SUCCESS);
16217c478bd9Sstevel@tonic-gate }
16227c478bd9Sstevel@tonic-gate 
16237c478bd9Sstevel@tonic-gate 
16247c478bd9Sstevel@tonic-gate /*
16257c478bd9Sstevel@tonic-gate  * Description : frudata_add_segment is called when volatile property
16267c478bd9Sstevel@tonic-gate  *              add_segment under class node section is accessed.
16277c478bd9Sstevel@tonic-gate  *
16287c478bd9Sstevel@tonic-gate  * Arguments    : ptree_warg_t  holds node handle for the section node.
16297c478bd9Sstevel@tonic-gate  *              property handle for the add_segment property.
16307c478bd9Sstevel@tonic-gate  *
16317c478bd9Sstevel@tonic-gate  * Returns      : PICL_SUCCESS on success.
16327c478bd9Sstevel@tonic-gate  *              PICL_FAILURE on failure.
16337c478bd9Sstevel@tonic-gate  */
16347c478bd9Sstevel@tonic-gate 
16357c478bd9Sstevel@tonic-gate static int
frudata_add_segment(ptree_warg_t * warg,const void * buf)16367c478bd9Sstevel@tonic-gate frudata_add_segment(ptree_warg_t *warg, const void *buf)
16377c478bd9Sstevel@tonic-gate {
16387c478bd9Sstevel@tonic-gate 	int		retval;
16397c478bd9Sstevel@tonic-gate 	int		cnt;
16407c478bd9Sstevel@tonic-gate 	int		num_of_segment;
16417c478bd9Sstevel@tonic-gate 	segment_t	*seg_buf;
16427c478bd9Sstevel@tonic-gate 	segment_t	segment;
16437c478bd9Sstevel@tonic-gate 	hash_obj_t	*seg_hash;
16447c478bd9Sstevel@tonic-gate 	hash_obj_t	*hash_obj;
16457c478bd9Sstevel@tonic-gate 	container_tbl_t	*cont_tbl;
16467c478bd9Sstevel@tonic-gate 	fru_segdef_t	*seg_def;
16477c478bd9Sstevel@tonic-gate 	fru_segdesc_t	*desc;
16487c478bd9Sstevel@tonic-gate 	fru_access_hdl_t new_sec_acc_hdl;
16497c478bd9Sstevel@tonic-gate 
16507c478bd9Sstevel@tonic-gate 	seg_def	= (fru_segdef_t *)buf;
16517c478bd9Sstevel@tonic-gate 
16527c478bd9Sstevel@tonic-gate 	/* initialize segment_t */
16537c478bd9Sstevel@tonic-gate 	segment.handle	= 0;
16547c478bd9Sstevel@tonic-gate 	(void) memcpy(segment.name, seg_def->name, SEG_NAME_LEN);
16557c478bd9Sstevel@tonic-gate 	segment.descriptor =  seg_def->desc.raw_data;
16567c478bd9Sstevel@tonic-gate 	segment.length	= seg_def->size;	/* segment length */
16577c478bd9Sstevel@tonic-gate 	segment.offset = seg_def->address;	/* segment offset */
16587c478bd9Sstevel@tonic-gate 
16597c478bd9Sstevel@tonic-gate 	desc    = (fru_segdesc_t *)&segment.descriptor;
16607c478bd9Sstevel@tonic-gate 	if (!(desc->field.field_perm & SEGMENT_READ)) {
16617c478bd9Sstevel@tonic-gate 		return (PICL_PERMDENIED);
16627c478bd9Sstevel@tonic-gate 	}
16637c478bd9Sstevel@tonic-gate 
16647c478bd9Sstevel@tonic-gate 	cont_tbl = lock_container_lock(warg->nodeh, SECTION_NODE, PICL_WRITE);
16657c478bd9Sstevel@tonic-gate 	if (!cont_tbl) {
16667c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
16677c478bd9Sstevel@tonic-gate 	}
16687c478bd9Sstevel@tonic-gate 
16697c478bd9Sstevel@tonic-gate 	hash_obj = lookup_node_object(warg->nodeh, SECTION_NODE, cont_tbl);
16707c478bd9Sstevel@tonic-gate 	if (hash_obj == NULL) {
16717c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
16727c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
16737c478bd9Sstevel@tonic-gate 	}
16747c478bd9Sstevel@tonic-gate 
16757c478bd9Sstevel@tonic-gate 	/* call fruaccess module, get the new section handle. */
16767c478bd9Sstevel@tonic-gate 	retval = fru_add_segment(hash_obj->u.sec_node->section_hdl,
16775705cefcSMichael Bergknoff 	    &segment, &new_sec_acc_hdl, &warg->cred);
16787c478bd9Sstevel@tonic-gate 	if (retval == -1) {
16797c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
16807c478bd9Sstevel@tonic-gate 		return (map_access_err(errno));
16817c478bd9Sstevel@tonic-gate 	}
16827c478bd9Sstevel@tonic-gate 
16837c478bd9Sstevel@tonic-gate 	/* call access module with new section handle */
16847c478bd9Sstevel@tonic-gate 	num_of_segment = fru_get_num_segments(new_sec_acc_hdl, &warg->cred);
16857c478bd9Sstevel@tonic-gate 
16867c478bd9Sstevel@tonic-gate 	seg_buf	= alloca(sizeof (segment_t) * num_of_segment);
16877c478bd9Sstevel@tonic-gate 	if (seg_buf == NULL) {
16887c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
16897c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
16907c478bd9Sstevel@tonic-gate 	}
16917c478bd9Sstevel@tonic-gate 
16927c478bd9Sstevel@tonic-gate 	retval = fru_get_segments(new_sec_acc_hdl, seg_buf,
16935705cefcSMichael Bergknoff 	    num_of_segment, &warg->cred);
16947c478bd9Sstevel@tonic-gate 	if (retval ==  -1) {
16957c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
16967c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
16977c478bd9Sstevel@tonic-gate 	}
16987c478bd9Sstevel@tonic-gate 
16997c478bd9Sstevel@tonic-gate 	segment.offset	= seg_buf[(num_of_segment -1)].offset;
17007c478bd9Sstevel@tonic-gate 	segment.handle = seg_buf[(num_of_segment-1)].handle;
17017c478bd9Sstevel@tonic-gate 
17027c478bd9Sstevel@tonic-gate 	(void) create_segment_node(hash_obj, warg->nodeh, &segment,
17035705cefcSMichael Bergknoff 	    cont_tbl, &warg->cred);
17047c478bd9Sstevel@tonic-gate 
17057c478bd9Sstevel@tonic-gate 	/* rebuild  segment list */
17067c478bd9Sstevel@tonic-gate 	seg_hash = hash_obj->u.sec_node->segment_list;
17077c478bd9Sstevel@tonic-gate 	if (seg_hash == NULL) {
17087c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
17097c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
17107c478bd9Sstevel@tonic-gate 	}
17117c478bd9Sstevel@tonic-gate 
17127c478bd9Sstevel@tonic-gate 	hash_obj->u.sec_node->num_of_segment = 0;
17137c478bd9Sstevel@tonic-gate 
17147c478bd9Sstevel@tonic-gate 	for (cnt = 0; cnt < num_of_segment; cnt++) {
17157c478bd9Sstevel@tonic-gate 		desc	= (fru_segdesc_t *)&seg_buf[cnt].descriptor;
17167c478bd9Sstevel@tonic-gate 		if (!(desc->field.field_perm & SEGMENT_READ)) {
17177c478bd9Sstevel@tonic-gate 			continue;
17187c478bd9Sstevel@tonic-gate 		}
17197c478bd9Sstevel@tonic-gate 
17207c478bd9Sstevel@tonic-gate 		/* if opaque segment don't create segment node */
17217c478bd9Sstevel@tonic-gate 		if (desc->field.opaque) {
17227c478bd9Sstevel@tonic-gate 			continue;
17237c478bd9Sstevel@tonic-gate 		}
17247c478bd9Sstevel@tonic-gate 
17257c478bd9Sstevel@tonic-gate 		seg_hash->u.seg_node->segment_hdl =
17265705cefcSMichael Bergknoff 		    seg_buf[cnt].handle;
17277c478bd9Sstevel@tonic-gate 		seg_hash = seg_hash->u.seg_node->next;
17287c478bd9Sstevel@tonic-gate 		hash_obj->u.sec_node->num_of_segment++;
17297c478bd9Sstevel@tonic-gate 	}
17307c478bd9Sstevel@tonic-gate 
17317c478bd9Sstevel@tonic-gate 	/* update with new section handle */
17327c478bd9Sstevel@tonic-gate 	hash_obj->u.sec_node->section_hdl = new_sec_acc_hdl;
17337c478bd9Sstevel@tonic-gate 
17347c478bd9Sstevel@tonic-gate 	unlock_container_lock(cont_tbl);
17357c478bd9Sstevel@tonic-gate 
17367c478bd9Sstevel@tonic-gate 	return (PICL_SUCCESS);
17377c478bd9Sstevel@tonic-gate }
17387c478bd9Sstevel@tonic-gate 
17397c478bd9Sstevel@tonic-gate /*
17407c478bd9Sstevel@tonic-gate  * called from frudata_write_section() callback routine to create
17417c478bd9Sstevel@tonic-gate  * section node and all the  property under class section. it also
17427c478bd9Sstevel@tonic-gate  * allocate hash node object for each section in the container and
17437c478bd9Sstevel@tonic-gate  * add the section node object in the section list.
17447c478bd9Sstevel@tonic-gate  */
17457c478bd9Sstevel@tonic-gate 
17467c478bd9Sstevel@tonic-gate static int
create_section_node(picl_nodehdl_t nodehdl,int section_count,section_t * section,container_tbl_t * cont_tbl)17477c478bd9Sstevel@tonic-gate create_section_node(picl_nodehdl_t nodehdl, int section_count,
1748*ada2da53SToomas Soome     section_t *section, container_tbl_t *cont_tbl)
17497c478bd9Sstevel@tonic-gate {
17507c478bd9Sstevel@tonic-gate 	char		sec_name[SECNAMESIZE];
17517c478bd9Sstevel@tonic-gate 	hash_obj_t	*hash_obj;
17527c478bd9Sstevel@tonic-gate 	hash_obj_t	*cont_hash;
17537c478bd9Sstevel@tonic-gate 	picl_nodehdl_t	chld_node;
17547c478bd9Sstevel@tonic-gate 	picl_prophdl_t	prophdl;
17557c478bd9Sstevel@tonic-gate 	ptree_propinfo_t prop;
17567c478bd9Sstevel@tonic-gate 
17577c478bd9Sstevel@tonic-gate 	(void) snprintf(sec_name, SECNAMESIZE, "section%d", section_count);
17587c478bd9Sstevel@tonic-gate 
17597c478bd9Sstevel@tonic-gate 	if (ptree_create_node(sec_name, PICL_CLASS_SECTION, &chld_node)
17605705cefcSMichael Bergknoff 	    != PICL_SUCCESS) {
17617c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
17627c478bd9Sstevel@tonic-gate 	}
17637c478bd9Sstevel@tonic-gate 	prop.version		= PTREE_PROPINFO_VERSION;
17647c478bd9Sstevel@tonic-gate 	prop.piclinfo.type	= PICL_PTYPE_UNSIGNED_INT;
17657c478bd9Sstevel@tonic-gate 	prop.piclinfo.accessmode = PICL_READ;
17667c478bd9Sstevel@tonic-gate 	prop.piclinfo.size	= sizeof (uint32_t);
17677c478bd9Sstevel@tonic-gate 	prop.read		= NULL;
17687c478bd9Sstevel@tonic-gate 	prop.write		= NULL;
17697c478bd9Sstevel@tonic-gate 
17707c478bd9Sstevel@tonic-gate 	/* offset */
17717c478bd9Sstevel@tonic-gate 	(void) strcpy(prop.piclinfo.name, PICL_PROP_OFFSET);
17727c478bd9Sstevel@tonic-gate 	if (ptree_create_and_add_prop(chld_node, &prop, &section->offset,
17735705cefcSMichael Bergknoff 	    &prophdl) != PICL_SUCCESS) {
17747c478bd9Sstevel@tonic-gate 		freeup(chld_node);
17757c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
17767c478bd9Sstevel@tonic-gate 	}
17777c478bd9Sstevel@tonic-gate 
17787c478bd9Sstevel@tonic-gate 	/* length */
17797c478bd9Sstevel@tonic-gate 	(void) strcpy(prop.piclinfo.name, PICL_PROP_LENGTH);
17807c478bd9Sstevel@tonic-gate 	if (ptree_create_and_add_prop(chld_node, &prop, &section->length,
17815705cefcSMichael Bergknoff 	    &prophdl) != PICL_SUCCESS) {
17827c478bd9Sstevel@tonic-gate 		freeup(chld_node);
17837c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
17847c478bd9Sstevel@tonic-gate 	}
17857c478bd9Sstevel@tonic-gate 
17867c478bd9Sstevel@tonic-gate 
17877c478bd9Sstevel@tonic-gate 	/* protected */
17887c478bd9Sstevel@tonic-gate 	(void) strcpy(prop.piclinfo.name, PICL_PROP_PROTECTED);
17897c478bd9Sstevel@tonic-gate 	if (ptree_create_and_add_prop(chld_node, &prop, &section->protection,
17905705cefcSMichael Bergknoff 	    &prophdl) != PICL_SUCCESS) {
17917c478bd9Sstevel@tonic-gate 		freeup(chld_node);
17927c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
17937c478bd9Sstevel@tonic-gate 	}
17947c478bd9Sstevel@tonic-gate 
17957c478bd9Sstevel@tonic-gate 	prop.piclinfo.accessmode	= PICL_READ|PICL_VOLATILE;
17967c478bd9Sstevel@tonic-gate 	prop.read	= frudata_read_segment;
17977c478bd9Sstevel@tonic-gate 
17987c478bd9Sstevel@tonic-gate 	(void) strcpy(prop.piclinfo.name, PICL_PROP_NUM_SEGMENTS);
17997c478bd9Sstevel@tonic-gate 
18007c478bd9Sstevel@tonic-gate 	if (ptree_create_and_add_prop(chld_node, &prop, NULL, &prophdl)
18015705cefcSMichael Bergknoff 	    != PICL_SUCCESS) {
18027c478bd9Sstevel@tonic-gate 		freeup(chld_node);
18037c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
18047c478bd9Sstevel@tonic-gate 	}
18057c478bd9Sstevel@tonic-gate 
18067c478bd9Sstevel@tonic-gate 
18077c478bd9Sstevel@tonic-gate 	prop.piclinfo.type = PICL_PTYPE_BYTEARRAY;
18087c478bd9Sstevel@tonic-gate 	prop.piclinfo.size = sizeof (fru_segdef_t);
18097c478bd9Sstevel@tonic-gate 
18107c478bd9Sstevel@tonic-gate 	prop.piclinfo.accessmode = PICL_WRITE|PICL_READ|PICL_VOLATILE;
18117c478bd9Sstevel@tonic-gate 	prop.write = frudata_add_segment; /* callback routine */
18127c478bd9Sstevel@tonic-gate 	prop.read = frudata_read_callback;
18137c478bd9Sstevel@tonic-gate 
18147c478bd9Sstevel@tonic-gate 	(void) strcpy(prop.piclinfo.name, PICL_PROP_ADD_SEGMENT);
18157c478bd9Sstevel@tonic-gate 	/* add-segment prop if read/write section */
18167c478bd9Sstevel@tonic-gate 	if (section->protection == 0) {
18177c478bd9Sstevel@tonic-gate 		if (ptree_create_and_add_prop(chld_node, &prop, NULL, &prophdl)
18185705cefcSMichael Bergknoff 		    != PICL_SUCCESS) {
18197c478bd9Sstevel@tonic-gate 			freeup(chld_node);
18207c478bd9Sstevel@tonic-gate 			return (PICL_FAILURE);
18217c478bd9Sstevel@tonic-gate 		}
18227c478bd9Sstevel@tonic-gate 	}
18237c478bd9Sstevel@tonic-gate 
18247c478bd9Sstevel@tonic-gate 	if (ptree_add_node(nodehdl, chld_node) != PICL_SUCCESS) {
18257c478bd9Sstevel@tonic-gate 		freeup(chld_node);
18267c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
18277c478bd9Sstevel@tonic-gate 	}
18287c478bd9Sstevel@tonic-gate 
18297c478bd9Sstevel@tonic-gate 	/* lookup for container handle */
18307c478bd9Sstevel@tonic-gate 	cont_hash = lookup_node_object(nodehdl, CONTAINER_NODE, cont_tbl);
18317c478bd9Sstevel@tonic-gate 	if (cont_hash == NULL) {
18327c478bd9Sstevel@tonic-gate 		freeup(chld_node);
18337c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
18347c478bd9Sstevel@tonic-gate 	}
18357c478bd9Sstevel@tonic-gate 
18367c478bd9Sstevel@tonic-gate 	hash_obj = alloc_section_node_object(chld_node, section);
18377c478bd9Sstevel@tonic-gate 	if (hash_obj == NULL) {
18387c478bd9Sstevel@tonic-gate 		freeup(chld_node);
18397c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
18407c478bd9Sstevel@tonic-gate 	}
18417c478bd9Sstevel@tonic-gate 
18427c478bd9Sstevel@tonic-gate 	add_nodeobject_to_hashtable(hash_obj, cont_tbl);
18437c478bd9Sstevel@tonic-gate 
18447c478bd9Sstevel@tonic-gate 	add_to_section_list(cont_hash, hash_obj);
18457c478bd9Sstevel@tonic-gate 	return (PICL_SUCCESS);
18467c478bd9Sstevel@tonic-gate }
18477c478bd9Sstevel@tonic-gate 
18487c478bd9Sstevel@tonic-gate 
18497c478bd9Sstevel@tonic-gate /*
18507c478bd9Sstevel@tonic-gate  * Description  :frudata_write_section is called when volatile container
18517c478bd9Sstevel@tonic-gate  *              property is accessed. it reads the section table associated
18527c478bd9Sstevel@tonic-gate  *              with the specified node handle(container) in ptree_rarg_t.
18537c478bd9Sstevel@tonic-gate  *              it calls search_root_node to search the node handle to open the
18547c478bd9Sstevel@tonic-gate  *              device associated with the node handle. it creates section
18557c478bd9Sstevel@tonic-gate  *              node and it's associated property. it also creates
18567c478bd9Sstevel@tonic-gate  *              volatile property num_segments.
18577c478bd9Sstevel@tonic-gate  *
18587c478bd9Sstevel@tonic-gate  * Argument     : ptree_rarg_t  : contains node handle of fru container the
18597c478bd9Sstevel@tonic-gate  *                                                      container.
18607c478bd9Sstevel@tonic-gate  *              property handle of the container.
18617c478bd9Sstevel@tonic-gate  *
18627c478bd9Sstevel@tonic-gate  * Return       : PICL_SUCCESS  on success.
18637c478bd9Sstevel@tonic-gate  *
18647c478bd9Sstevel@tonic-gate  */
18657c478bd9Sstevel@tonic-gate 
18667c478bd9Sstevel@tonic-gate /* ARGSUSED */
18677c478bd9Sstevel@tonic-gate 
18687c478bd9Sstevel@tonic-gate static int
frudata_write_section(ptree_warg_t * warg,const void * buf)18697c478bd9Sstevel@tonic-gate frudata_write_section(ptree_warg_t *warg, const void *buf)
18707c478bd9Sstevel@tonic-gate {
18717c478bd9Sstevel@tonic-gate 	int		retval;
18727c478bd9Sstevel@tonic-gate 	int		num_of_section;
18737c478bd9Sstevel@tonic-gate 	int		count;
18747c478bd9Sstevel@tonic-gate 	section_t	*section;
18757c478bd9Sstevel@tonic-gate 	hash_obj_t	*hash_obj;
18767c478bd9Sstevel@tonic-gate 	container_tbl_t	*cont_tbl = NULL;
18777c478bd9Sstevel@tonic-gate 	fru_access_hdl_t cont_acc_hdl;
18787c478bd9Sstevel@tonic-gate 
18797c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_lock(&cont_tbl_lock);
18807c478bd9Sstevel@tonic-gate 
18817c478bd9Sstevel@tonic-gate 	/*
18827c478bd9Sstevel@tonic-gate 	 * if lookup succeed return from this function with PICL_SUCCESS
18837c478bd9Sstevel@tonic-gate 	 * because first write operation has already occurred on this container,
18847c478bd9Sstevel@tonic-gate 	 * it also means that the container has been already initialzed.
18857c478bd9Sstevel@tonic-gate 	 */
18867c478bd9Sstevel@tonic-gate 
18877c478bd9Sstevel@tonic-gate 	cont_tbl = lookup_container_table(warg->nodeh, CONTAINER_NODE);
18887c478bd9Sstevel@tonic-gate 	if (cont_tbl != NULL) { /* found the hash obj in the hash table */
18897c478bd9Sstevel@tonic-gate 		(void) pthread_mutex_unlock(&cont_tbl_lock);
18907c478bd9Sstevel@tonic-gate 		return (PICL_SUCCESS);
18917c478bd9Sstevel@tonic-gate 	}
18927c478bd9Sstevel@tonic-gate 
18937c478bd9Sstevel@tonic-gate 	/*
18947c478bd9Sstevel@tonic-gate 	 * lookup failed that means this is first write on the
18957c478bd9Sstevel@tonic-gate 	 * container property. allocate a new container hash table for this
18967c478bd9Sstevel@tonic-gate 	 * new container and add to the cont_tbl hash table.
18977c478bd9Sstevel@tonic-gate 	 */
18987c478bd9Sstevel@tonic-gate 
18997c478bd9Sstevel@tonic-gate 	cont_tbl = alloc_container_table(warg->nodeh);
19007c478bd9Sstevel@tonic-gate 	if (cont_tbl == NULL) {
19017c478bd9Sstevel@tonic-gate 		(void) pthread_mutex_unlock(&cont_tbl_lock);
19027c478bd9Sstevel@tonic-gate 		return (map_access_err(errno));
19037c478bd9Sstevel@tonic-gate 	}
19047c478bd9Sstevel@tonic-gate 
19057c478bd9Sstevel@tonic-gate 	hash_obj = alloc_container_node_object(warg->nodeh);
19067c478bd9Sstevel@tonic-gate 	if (hash_obj == NULL) {
19077c478bd9Sstevel@tonic-gate 		(void) pthread_mutex_unlock(&cont_tbl_lock);
19085705cefcSMichael Bergknoff 		free(cont_tbl->hash_obj);
19095705cefcSMichael Bergknoff 		free(cont_tbl);
19107c478bd9Sstevel@tonic-gate 		return (map_access_err(errno));
19117c478bd9Sstevel@tonic-gate 	}
19127c478bd9Sstevel@tonic-gate 
19137c478bd9Sstevel@tonic-gate 	/* add container table object to container table */
19147c478bd9Sstevel@tonic-gate 	add_tblobject_to_container_tbl(cont_tbl);
19157c478bd9Sstevel@tonic-gate 
19167c478bd9Sstevel@tonic-gate 	/* add the hash object to container hash table. */
19177c478bd9Sstevel@tonic-gate 	add_nodeobject_to_hashtable(hash_obj, cont_tbl);
19187c478bd9Sstevel@tonic-gate 
19197c478bd9Sstevel@tonic-gate 	while (pthread_rwlock_trywrlock(&cont_tbl->rwlock) == EBUSY) {
19207c478bd9Sstevel@tonic-gate 		pthread_cond_wait(&cont_tbl->cond_var, &cont_tbl_lock);
19217c478bd9Sstevel@tonic-gate 	}
19227c478bd9Sstevel@tonic-gate 
19237c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_unlock(&cont_tbl_lock);
19247c478bd9Sstevel@tonic-gate 
19257c478bd9Sstevel@tonic-gate 	/* fruaccess  handle */
19267c478bd9Sstevel@tonic-gate 	cont_acc_hdl	= hash_obj->u.cont_node->cont_hdl;
19277c478bd9Sstevel@tonic-gate 
19287c478bd9Sstevel@tonic-gate 	num_of_section = fru_get_num_sections(cont_acc_hdl, &warg->cred);
19297c478bd9Sstevel@tonic-gate 
19307c478bd9Sstevel@tonic-gate 	if (num_of_section == -1) {
19317c478bd9Sstevel@tonic-gate 		free(hash_obj);
19327c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
19337c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
19347c478bd9Sstevel@tonic-gate 	}
19357c478bd9Sstevel@tonic-gate 
19367c478bd9Sstevel@tonic-gate 	section	= alloca(num_of_section * sizeof (section_t));
19377c478bd9Sstevel@tonic-gate 
19387c478bd9Sstevel@tonic-gate 	retval = fru_get_sections(cont_acc_hdl, section,
19395705cefcSMichael Bergknoff 	    num_of_section, &warg->cred);
19407c478bd9Sstevel@tonic-gate 	if (retval == -1) {
19417c478bd9Sstevel@tonic-gate 		free(hash_obj);
19427c478bd9Sstevel@tonic-gate 		unlock_container_lock(cont_tbl);
19437c478bd9Sstevel@tonic-gate 		return (PICL_FAILURE);
19447c478bd9Sstevel@tonic-gate 	}
19457c478bd9Sstevel@tonic-gate 
19467c478bd9Sstevel@tonic-gate 	hash_obj->u.cont_node->num_of_section = num_of_section;
19477c478bd9Sstevel@tonic-gate 
19487c478bd9Sstevel@tonic-gate 	for (count = 0; count < num_of_section; count++) {
19497c478bd9Sstevel@tonic-gate 		(void) create_section_node(warg->nodeh, count,
19505705cefcSMichael Bergknoff 		    section + count, cont_tbl);
19517c478bd9Sstevel@tonic-gate 	}
19527c478bd9Sstevel@tonic-gate 
19537c478bd9Sstevel@tonic-gate 	unlock_container_lock(cont_tbl);
19547c478bd9Sstevel@tonic-gate 
19557c478bd9Sstevel@tonic-gate 	return (PICL_SUCCESS);
19567c478bd9Sstevel@tonic-gate }
19577c478bd9Sstevel@tonic-gate 
19587c478bd9Sstevel@tonic-gate /* create container and add-segment property */
19597c478bd9Sstevel@tonic-gate 
19607c478bd9Sstevel@tonic-gate static int
create_container_prop(picl_nodehdl_t fruhdl)19617c478bd9Sstevel@tonic-gate create_container_prop(picl_nodehdl_t	fruhdl)
19627c478bd9Sstevel@tonic-gate {
19637c478bd9Sstevel@tonic-gate 	int			retval;
19647c478bd9Sstevel@tonic-gate 	picl_prophdl_t		prophdl;
19657c478bd9Sstevel@tonic-gate 	ptree_propinfo_t	prop;
19667c478bd9Sstevel@tonic-gate 
19677c478bd9Sstevel@tonic-gate 	prop.version = PTREE_PROPINFO_VERSION;
19687c478bd9Sstevel@tonic-gate 	prop.piclinfo.type = PICL_PTYPE_UNSIGNED_INT;
19697c478bd9Sstevel@tonic-gate 	prop.piclinfo.size = sizeof (uint32_t);
19707c478bd9Sstevel@tonic-gate 	prop.piclinfo.accessmode = PICL_WRITE|PICL_VOLATILE;
19717c478bd9Sstevel@tonic-gate 	(void) strcpy(prop.piclinfo.name, PICL_PROP_CONTAINER);
19727c478bd9Sstevel@tonic-gate 	prop.read =  frudata_read_callback;
19737c478bd9Sstevel@tonic-gate 	prop.write = frudata_write_section; /* callback routine */
19747c478bd9Sstevel@tonic-gate 
19757c478bd9Sstevel@tonic-gate 	/* create a property */
19767c478bd9Sstevel@tonic-gate 	retval = ptree_create_and_add_prop(fruhdl, &prop, NULL, &prophdl);
19777c478bd9Sstevel@tonic-gate 
19787c478bd9Sstevel@tonic-gate 	return (retval);
19797c478bd9Sstevel@tonic-gate }
19807c478bd9Sstevel@tonic-gate 
19817c478bd9Sstevel@tonic-gate /* search for FRUDataAvailable and create container and add segment property */
19827c478bd9Sstevel@tonic-gate 
19837c478bd9Sstevel@tonic-gate static void
create_frudata_props(picl_prophdl_t fruhdl)19847c478bd9Sstevel@tonic-gate create_frudata_props(picl_prophdl_t fruhdl)
19857c478bd9Sstevel@tonic-gate {
19867c478bd9Sstevel@tonic-gate 	int		retval;
19877c478bd9Sstevel@tonic-gate 	picl_nodehdl_t chldhdl;
19887c478bd9Sstevel@tonic-gate 	picl_nodehdl_t tmphdl;
19897c478bd9Sstevel@tonic-gate 
19907c478bd9Sstevel@tonic-gate 	for (retval = ptree_get_propval_by_name(fruhdl, PICL_PROP_CHILD,
19915705cefcSMichael Bergknoff 	    &chldhdl, sizeof (picl_nodehdl_t)); retval != PICL_PROPNOTFOUND;
19925705cefcSMichael Bergknoff 	    retval = ptree_get_propval_by_name(chldhdl, PICL_PROP_PEER,
19935705cefcSMichael Bergknoff 	    &chldhdl, sizeof (picl_nodehdl_t))) {
19947c478bd9Sstevel@tonic-gate 		if (retval != PICL_SUCCESS)
19957c478bd9Sstevel@tonic-gate 			return;
19967c478bd9Sstevel@tonic-gate 
19977c478bd9Sstevel@tonic-gate 		/* Does it have a FRUDataAvailable property */
19987c478bd9Sstevel@tonic-gate 		retval = ptree_get_prop_by_name(chldhdl,
19995705cefcSMichael Bergknoff 		    PICL_PROP_FRUDATA_AVAIL, &tmphdl);
20007c478bd9Sstevel@tonic-gate 		if (retval == PICL_SUCCESS) {
20017c478bd9Sstevel@tonic-gate 			(void) create_container_prop(chldhdl);
20027c478bd9Sstevel@tonic-gate 		}
20037c478bd9Sstevel@tonic-gate 
20047c478bd9Sstevel@tonic-gate 		/* Traverse tree recursively */
20057c478bd9Sstevel@tonic-gate 		(void) create_frudata_props(chldhdl);
20067c478bd9Sstevel@tonic-gate 	}
20077c478bd9Sstevel@tonic-gate }
20087c478bd9Sstevel@tonic-gate 
20097c478bd9Sstevel@tonic-gate /*
20107c478bd9Sstevel@tonic-gate  * Search for the frutree config file from the platform specific
20117c478bd9Sstevel@tonic-gate  * directory to the common directory.
20127c478bd9Sstevel@tonic-gate  *
20137c478bd9Sstevel@tonic-gate  * The size of outfilename must be PATH_MAX
20147c478bd9Sstevel@tonic-gate  */
20157c478bd9Sstevel@tonic-gate static int
get_config_file(char * outfilename)20167c478bd9Sstevel@tonic-gate get_config_file(char *outfilename)
20177c478bd9Sstevel@tonic-gate {
20187c478bd9Sstevel@tonic-gate 	char    nmbuf[SYS_NMLN];
20197c478bd9Sstevel@tonic-gate 	char    pname[PATH_MAX];
20207c478bd9Sstevel@tonic-gate 
20217c478bd9Sstevel@tonic-gate 	if (sysinfo(SI_PLATFORM, nmbuf, sizeof (nmbuf)) != -1) {
20227c478bd9Sstevel@tonic-gate 		(void) snprintf(pname, PATH_MAX, FRUDATA_CONFFILE_NAME, nmbuf);
20237c478bd9Sstevel@tonic-gate 		if (access(pname, R_OK) == 0) {
20247c478bd9Sstevel@tonic-gate 			(void) strlcpy(outfilename, pname, PATH_MAX);
20257c478bd9Sstevel@tonic-gate 			return (0);
20267c478bd9Sstevel@tonic-gate 		}
20277c478bd9Sstevel@tonic-gate 	}
20287c478bd9Sstevel@tonic-gate 
20297c478bd9Sstevel@tonic-gate 	if (sysinfo(SI_MACHINE, nmbuf, sizeof (nmbuf)) != -1) {
20307c478bd9Sstevel@tonic-gate 		(void) snprintf(pname, PATH_MAX, FRUDATA_CONFFILE_NAME, nmbuf);
20317c478bd9Sstevel@tonic-gate 		if (access(pname, R_OK) == 0) {
20327c478bd9Sstevel@tonic-gate 			(void) strlcpy(outfilename, pname, PATH_MAX);
20337c478bd9Sstevel@tonic-gate 			return (0);
20347c478bd9Sstevel@tonic-gate 		}
20357c478bd9Sstevel@tonic-gate 	}
20367c478bd9Sstevel@tonic-gate 
20377c478bd9Sstevel@tonic-gate 	(void) snprintf(pname, PATH_MAX, "%s/%s", PICLD_COMMON_PLUGIN_DIR,
20385705cefcSMichael Bergknoff 	    FRUDATA_CONFFILE_NAME);
20397c478bd9Sstevel@tonic-gate 	if (access(pname, R_OK) == 0) {
20407c478bd9Sstevel@tonic-gate 		(void) strlcpy(outfilename, pname, PATH_MAX);
20417c478bd9Sstevel@tonic-gate 		return (0);
20427c478bd9Sstevel@tonic-gate 	}
20437c478bd9Sstevel@tonic-gate 	return (-1);
20447c478bd9Sstevel@tonic-gate }
20457c478bd9Sstevel@tonic-gate 
20467c478bd9Sstevel@tonic-gate /*
20477c478bd9Sstevel@tonic-gate  * called from delete_frudata_props(), this routine delete the section node
20487c478bd9Sstevel@tonic-gate  * and free's the section hash object. it calls free_segment_node() to
20497c478bd9Sstevel@tonic-gate  * delete segment node beneath it.
20507c478bd9Sstevel@tonic-gate  */
20517c478bd9Sstevel@tonic-gate 
20527c478bd9Sstevel@tonic-gate static void
free_section_node(hash_obj_t * sec_hash,container_tbl_t * cont_tbl)20537c478bd9Sstevel@tonic-gate free_section_node(hash_obj_t	*sec_hash, container_tbl_t *cont_tbl)
20547c478bd9Sstevel@tonic-gate {
20557c478bd9Sstevel@tonic-gate 	hash_obj_t	*seg_hash;
20567c478bd9Sstevel@tonic-gate 
20577c478bd9Sstevel@tonic-gate 	for (seg_hash = sec_hash->u.sec_node->segment_list; seg_hash != NULL;
20585705cefcSMichael Bergknoff 	    seg_hash = seg_hash->u.seg_node->next) {
20597c478bd9Sstevel@tonic-gate 		free_segment_node(seg_hash, seg_hash->picl_hdl, cont_tbl);
20607c478bd9Sstevel@tonic-gate 	}
20617c478bd9Sstevel@tonic-gate 
20627c478bd9Sstevel@tonic-gate 	if (sec_hash->prev == NULL) {
20637c478bd9Sstevel@tonic-gate 		cont_tbl->hash_obj[(sec_hash->picl_hdl % TABLE_SIZE)].next =
20645705cefcSMichael Bergknoff 		    sec_hash->next;
20657c478bd9Sstevel@tonic-gate 		if (sec_hash->next != NULL) {
20667c478bd9Sstevel@tonic-gate 			sec_hash->next->prev = NULL;
20677c478bd9Sstevel@tonic-gate 		}
20687c478bd9Sstevel@tonic-gate 	} else {
20697c478bd9Sstevel@tonic-gate 		sec_hash->prev->next = sec_hash->next;
20707c478bd9Sstevel@tonic-gate 		if (sec_hash->next != NULL) {
20717c478bd9Sstevel@tonic-gate 			sec_hash->next->prev = sec_hash->prev;
20727c478bd9Sstevel@tonic-gate 		}
20737c478bd9Sstevel@tonic-gate 	}
20747c478bd9Sstevel@tonic-gate 
20757c478bd9Sstevel@tonic-gate 	/* delete & destroy section node */
20767c478bd9Sstevel@tonic-gate 	(void) ptree_delete_node(sec_hash->picl_hdl);
20777c478bd9Sstevel@tonic-gate 	(void) ptree_destroy_node(sec_hash->picl_hdl);
20787c478bd9Sstevel@tonic-gate 
20797c478bd9Sstevel@tonic-gate 	free(sec_hash->u.sec_node);
20807c478bd9Sstevel@tonic-gate 	free(sec_hash);
20817c478bd9Sstevel@tonic-gate }
20827c478bd9Sstevel@tonic-gate 
20837c478bd9Sstevel@tonic-gate /*
20847c478bd9Sstevel@tonic-gate  * called from delete_frudata_props(), this routine free's the container
20857c478bd9Sstevel@tonic-gate  * hash object.
20867c478bd9Sstevel@tonic-gate  */
20877c478bd9Sstevel@tonic-gate 
20887c478bd9Sstevel@tonic-gate static void
unlink_container_node(container_tbl_t * cont_hash)20897c478bd9Sstevel@tonic-gate unlink_container_node(container_tbl_t	*cont_hash)
20907c478bd9Sstevel@tonic-gate {
20917c478bd9Sstevel@tonic-gate 	if (cont_hash->prev == NULL) {
20927c478bd9Sstevel@tonic-gate 		container_table[(cont_hash->picl_hdl % TABLE_SIZE)] =
20935705cefcSMichael Bergknoff 		    cont_hash->next;
20947c478bd9Sstevel@tonic-gate 		if (cont_hash->next != NULL) {
20957c478bd9Sstevel@tonic-gate 			cont_hash->next->prev = NULL;
20967c478bd9Sstevel@tonic-gate 		}
20977c478bd9Sstevel@tonic-gate 	} else {
20987c478bd9Sstevel@tonic-gate 		cont_hash->prev->next = cont_hash->next;
20997c478bd9Sstevel@tonic-gate 		if (cont_hash->next != NULL) {
21007c478bd9Sstevel@tonic-gate 			cont_hash->next->prev = cont_hash->prev;
21017c478bd9Sstevel@tonic-gate 		}
21027c478bd9Sstevel@tonic-gate 	}
21037c478bd9Sstevel@tonic-gate }
21047c478bd9Sstevel@tonic-gate 
21057c478bd9Sstevel@tonic-gate /*
21067c478bd9Sstevel@tonic-gate  * called from frudata_event_handler() to free the corresponding hash object
21077c478bd9Sstevel@tonic-gate  * of the removed fru.
21087c478bd9Sstevel@tonic-gate  */
21097c478bd9Sstevel@tonic-gate 
21107c478bd9Sstevel@tonic-gate static void
delete_frudata_props(picl_nodehdl_t fru_hdl)21117c478bd9Sstevel@tonic-gate delete_frudata_props(picl_nodehdl_t	fru_hdl)
21127c478bd9Sstevel@tonic-gate {
21137c478bd9Sstevel@tonic-gate 	hash_obj_t	*cont_hash;
21147c478bd9Sstevel@tonic-gate 	hash_obj_t	*free_obj;
21157c478bd9Sstevel@tonic-gate 	hash_obj_t	*sec_hash;
21167c478bd9Sstevel@tonic-gate 	container_tbl_t	*cont_tbl;
21177c478bd9Sstevel@tonic-gate 
21187c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_lock(&cont_tbl_lock);
21197c478bd9Sstevel@tonic-gate 
21207c478bd9Sstevel@tonic-gate 	cont_tbl = lookup_container_table(fru_hdl, CONTAINER_NODE);
21217c478bd9Sstevel@tonic-gate 	if (cont_tbl == NULL) {
21227c478bd9Sstevel@tonic-gate 		(void) pthread_mutex_unlock(&cont_tbl_lock);
21237c478bd9Sstevel@tonic-gate 		return;
21247c478bd9Sstevel@tonic-gate 	}
21257c478bd9Sstevel@tonic-gate 
21267c478bd9Sstevel@tonic-gate 	/* remove the container object from the container table */
21277c478bd9Sstevel@tonic-gate 	unlink_container_node(cont_tbl);
21287c478bd9Sstevel@tonic-gate 
21297c478bd9Sstevel@tonic-gate 	(void) pthread_cond_broadcast(&cont_tbl->cond_var);
21307c478bd9Sstevel@tonic-gate 
21317c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_unlock(&cont_tbl_lock);
21327c478bd9Sstevel@tonic-gate 
21337c478bd9Sstevel@tonic-gate 	/*
21347c478bd9Sstevel@tonic-gate 	 * waiting/blocking calling thread for all I/O in
21357c478bd9Sstevel@tonic-gate 	 * progress to complete. don't free the container
21367c478bd9Sstevel@tonic-gate 	 * hash before all I/O is complete.
21377c478bd9Sstevel@tonic-gate 	 */
21387c478bd9Sstevel@tonic-gate 	(void) pthread_rwlock_wrlock(&cont_tbl->rwlock);
21397c478bd9Sstevel@tonic-gate 
21407c478bd9Sstevel@tonic-gate 	(void) pthread_rwlock_unlock(&cont_tbl->rwlock);
21417c478bd9Sstevel@tonic-gate 
21427c478bd9Sstevel@tonic-gate 
21437c478bd9Sstevel@tonic-gate 	cont_hash = lookup_node_object(fru_hdl, CONTAINER_NODE, cont_tbl);
21447c478bd9Sstevel@tonic-gate 	if (cont_hash == NULL) {
21457c478bd9Sstevel@tonic-gate 		return;
21467c478bd9Sstevel@tonic-gate 	}
21477c478bd9Sstevel@tonic-gate 
21487c478bd9Sstevel@tonic-gate 	free_obj = cont_hash->u.cont_node->section_list;
21497c478bd9Sstevel@tonic-gate 	/* walk through the section list */
21507c478bd9Sstevel@tonic-gate 	for (sec_hash = free_obj; sec_hash != NULL; free_obj = sec_hash) {
21517c478bd9Sstevel@tonic-gate 		sec_hash = sec_hash->u.sec_node->next;
21527c478bd9Sstevel@tonic-gate 		free_section_node(free_obj, cont_tbl);
21537c478bd9Sstevel@tonic-gate 	}
21547c478bd9Sstevel@tonic-gate 	(void) fru_close_container(cont_hash->u.cont_node->cont_hdl);
21557c478bd9Sstevel@tonic-gate 
21567c478bd9Sstevel@tonic-gate 	free(cont_hash->u.cont_node);
21577c478bd9Sstevel@tonic-gate 	free(cont_hash);
21587c478bd9Sstevel@tonic-gate 
21597c478bd9Sstevel@tonic-gate 	free(cont_tbl->hash_obj);
21607c478bd9Sstevel@tonic-gate 	free(cont_tbl);
21617c478bd9Sstevel@tonic-gate }
21627c478bd9Sstevel@tonic-gate 
21637c478bd9Sstevel@tonic-gate /*
21647c478bd9Sstevel@tonic-gate  * called when there is any state-change in location, fru, port nodes.
21657c478bd9Sstevel@tonic-gate  * this event handler handles only location state-changes.
21667c478bd9Sstevel@tonic-gate  */
21677c478bd9Sstevel@tonic-gate /* ARGSUSED */
21687c478bd9Sstevel@tonic-gate static void
frudata_state_change_evhandler(const char * event_name,const void * event_arg,size_t size,void * cookie)21697c478bd9Sstevel@tonic-gate frudata_state_change_evhandler(const char *event_name, const void *event_arg,
2170*ada2da53SToomas Soome     size_t size, void *cookie)
21717c478bd9Sstevel@tonic-gate {
21727c478bd9Sstevel@tonic-gate 	int rc;
21737c478bd9Sstevel@tonic-gate 	nvlist_t *nvlp;
21747c478bd9Sstevel@tonic-gate 	ptree_propinfo_t prop;
21757c478bd9Sstevel@tonic-gate 	picl_nodehdl_t	loch, fruh;
21767c478bd9Sstevel@tonic-gate 	picl_prophdl_t	proph, prophdl;
21777c478bd9Sstevel@tonic-gate 	char *present_state, *last_state;
21787c478bd9Sstevel@tonic-gate 	char name[PICL_PROPNAMELEN_MAX];
21797c478bd9Sstevel@tonic-gate 
21807c478bd9Sstevel@tonic-gate 	if (strcmp(event_name, PICLEVENT_STATE_CHANGE) != 0)
21817c478bd9Sstevel@tonic-gate 		return;
21827c478bd9Sstevel@tonic-gate 
2183*ada2da53SToomas Soome 	if (nvlist_unpack((char *)event_arg, size, &nvlp, 0)) {
21847c478bd9Sstevel@tonic-gate 		return;
21857c478bd9Sstevel@tonic-gate 	}
21867c478bd9Sstevel@tonic-gate 
21877c478bd9Sstevel@tonic-gate 	if (nvlist_lookup_uint64(nvlp, PICLEVENTARG_NODEHANDLE,
21885705cefcSMichael Bergknoff 	    &loch)  == -1) {
21897c478bd9Sstevel@tonic-gate 		nvlist_free(nvlp);
21907c478bd9Sstevel@tonic-gate 		return;
21917c478bd9Sstevel@tonic-gate 	}
21927c478bd9Sstevel@tonic-gate 
21937c478bd9Sstevel@tonic-gate 	if (ptree_get_propval_by_name(loch, PICL_PROP_CLASSNAME, name,
21945705cefcSMichael Bergknoff 	    sizeof (name)) != PICL_SUCCESS) {
21957c478bd9Sstevel@tonic-gate 		nvlist_free(nvlp);
21967c478bd9Sstevel@tonic-gate 		return;
21977c478bd9Sstevel@tonic-gate 	}
21987c478bd9Sstevel@tonic-gate 
21997c478bd9Sstevel@tonic-gate 	/* handle only location events */
22007c478bd9Sstevel@tonic-gate 	if (strcmp(name, PICL_CLASS_LOCATION) != 0) {
22017c478bd9Sstevel@tonic-gate 		nvlist_free(nvlp);
22027c478bd9Sstevel@tonic-gate 		return;
22037c478bd9Sstevel@tonic-gate 	}
22047c478bd9Sstevel@tonic-gate 
22057c478bd9Sstevel@tonic-gate 	if (nvlist_lookup_string(nvlp, PICLEVENTARG_STATE,
22065705cefcSMichael Bergknoff 	    &present_state)) {
22077c478bd9Sstevel@tonic-gate 		nvlist_free(nvlp);
22087c478bd9Sstevel@tonic-gate 		return;
22097c478bd9Sstevel@tonic-gate 	}
22107c478bd9Sstevel@tonic-gate 
22117c478bd9Sstevel@tonic-gate 	rc = ptree_get_propval_by_name(loch, PICL_PROP_CHILD,
22125705cefcSMichael Bergknoff 	    &fruh, sizeof (picl_nodehdl_t));
22137c478bd9Sstevel@tonic-gate 	if (rc != PICL_SUCCESS) {
22147c478bd9Sstevel@tonic-gate 		nvlist_free(nvlp);
22157c478bd9Sstevel@tonic-gate 		return;
22167c478bd9Sstevel@tonic-gate 	}
22177c478bd9Sstevel@tonic-gate 
22187c478bd9Sstevel@tonic-gate 	/* fru removed */
22197c478bd9Sstevel@tonic-gate 	if (strcmp(present_state, PICLEVENTARGVAL_EMPTY) == 0) {
22207c478bd9Sstevel@tonic-gate 		delete_frudata_props(fruh);
22217c478bd9Sstevel@tonic-gate 		nvlist_free(nvlp);
22227c478bd9Sstevel@tonic-gate 		return;
22237c478bd9Sstevel@tonic-gate 	}
22247c478bd9Sstevel@tonic-gate 
22257c478bd9Sstevel@tonic-gate 	if (nvlist_lookup_string(nvlp, PICLEVENTARG_LAST_STATE,
22265705cefcSMichael Bergknoff 	    &last_state)) {
22277c478bd9Sstevel@tonic-gate 		nvlist_free(nvlp);
22287c478bd9Sstevel@tonic-gate 		return;
22297c478bd9Sstevel@tonic-gate 	}
22307c478bd9Sstevel@tonic-gate 
22317c478bd9Sstevel@tonic-gate 	/* fru added */
22327c478bd9Sstevel@tonic-gate 	if ((strcmp(last_state, PICLEVENTARGVAL_EMPTY) == 0) ||
22335705cefcSMichael Bergknoff 	    (strcmp(last_state, PICLEVENTARGVAL_UNKNOWN) == 0)) {
22347c478bd9Sstevel@tonic-gate 		rc = ptree_get_prop_by_name(fruh, PICL_PROP_FRUDATA_AVAIL,
22355705cefcSMichael Bergknoff 		    &proph);
22367c478bd9Sstevel@tonic-gate 		if (rc != PICL_SUCCESS) {
22377c478bd9Sstevel@tonic-gate 			if (fru_is_data_available(fruh) == 0) {
22387c478bd9Sstevel@tonic-gate 				nvlist_free(nvlp);
22397c478bd9Sstevel@tonic-gate 				return;
22407c478bd9Sstevel@tonic-gate 			}
22417c478bd9Sstevel@tonic-gate 			/* create the property */
22427c478bd9Sstevel@tonic-gate 			prop.version = PTREE_PROPINFO_VERSION;
22437c478bd9Sstevel@tonic-gate 			prop.piclinfo.type =  PICL_PTYPE_VOID;
22447c478bd9Sstevel@tonic-gate 			prop.piclinfo.accessmode = PICL_READ;
22457c478bd9Sstevel@tonic-gate 			prop.piclinfo.size =  0;
22467c478bd9Sstevel@tonic-gate 			(void) strncpy(prop.piclinfo.name,
22475705cefcSMichael Bergknoff 			    PICL_PROP_FRUDATA_AVAIL,
22485705cefcSMichael Bergknoff 			    sizeof (prop.piclinfo.name));
22497c478bd9Sstevel@tonic-gate 
22507c478bd9Sstevel@tonic-gate 			rc = ptree_create_prop(&prop, NULL, &prophdl);
22517c478bd9Sstevel@tonic-gate 			if (rc != PICL_SUCCESS) {
22527c478bd9Sstevel@tonic-gate 				nvlist_free(nvlp);
22537c478bd9Sstevel@tonic-gate 				return;
22547c478bd9Sstevel@tonic-gate 			}
22557c478bd9Sstevel@tonic-gate 			rc = ptree_add_prop(fruh,  prophdl);
22567c478bd9Sstevel@tonic-gate 			if (rc != PICL_SUCCESS) {
22577c478bd9Sstevel@tonic-gate 				nvlist_free(nvlp);
22587c478bd9Sstevel@tonic-gate 				return;
22597c478bd9Sstevel@tonic-gate 			}
22607c478bd9Sstevel@tonic-gate 		}
22617c478bd9Sstevel@tonic-gate 		(void) create_container_prop(fruh);
22627c478bd9Sstevel@tonic-gate 	}
22637c478bd9Sstevel@tonic-gate 	nvlist_free(nvlp);
22647c478bd9Sstevel@tonic-gate }
22657c478bd9Sstevel@tonic-gate 
22667c478bd9Sstevel@tonic-gate /*
22677c478bd9Sstevel@tonic-gate  * called when event is posted when is fru is either added or removed from
22687c478bd9Sstevel@tonic-gate  * the picltree.
22697c478bd9Sstevel@tonic-gate  */
22707c478bd9Sstevel@tonic-gate 
22717c478bd9Sstevel@tonic-gate /* ARGSUSED */
22727c478bd9Sstevel@tonic-gate static void
frudata_event_handler(const char * event_name,const void * event_arg,size_t size,void * cookie)22737c478bd9Sstevel@tonic-gate frudata_event_handler(const char *event_name, const void *event_arg,
2274*ada2da53SToomas Soome     size_t size, void *cookie)
22757c478bd9Sstevel@tonic-gate {
22767c478bd9Sstevel@tonic-gate 	int		retval;
22777c478bd9Sstevel@tonic-gate 	char		fullfilename[PATH_MAX];
22787c478bd9Sstevel@tonic-gate 	picl_nodehdl_t	fru_picl_hdl;
22797c478bd9Sstevel@tonic-gate 	picl_nodehdl_t	roothdl;
22807c478bd9Sstevel@tonic-gate 
22817c478bd9Sstevel@tonic-gate 	if (strcmp(event_name, PICL_FRU_REMOVED) == 0) {
22827c478bd9Sstevel@tonic-gate 
22837c478bd9Sstevel@tonic-gate 		retval = nvlist_lookup_uint64((nvlist_t *)event_arg,
22845705cefcSMichael Bergknoff 		    PICLEVENTARG_FRUHANDLE, &fru_picl_hdl);
22857c478bd9Sstevel@tonic-gate 		if (retval != PICL_SUCCESS) {
22867c478bd9Sstevel@tonic-gate 			return;
22877c478bd9Sstevel@tonic-gate 		}
22887c478bd9Sstevel@tonic-gate 
22897c478bd9Sstevel@tonic-gate 		/* free the hash object */
22907c478bd9Sstevel@tonic-gate 		delete_frudata_props(fru_picl_hdl);
22917c478bd9Sstevel@tonic-gate 
22927c478bd9Sstevel@tonic-gate 	} else  if (strcmp(event_name, PICL_FRU_ADDED) == 0) {
22937c478bd9Sstevel@tonic-gate 		/*
22947c478bd9Sstevel@tonic-gate 		 * reparse the configuration file to create
22957c478bd9Sstevel@tonic-gate 		 * FRUDevicePath Prop.
22967c478bd9Sstevel@tonic-gate 		 */
22977c478bd9Sstevel@tonic-gate 		(void) get_config_file(fullfilename);
22987c478bd9Sstevel@tonic-gate 		retval = ptree_get_root(&roothdl);
22997c478bd9Sstevel@tonic-gate 		if (retval != PICL_SUCCESS) {
23007c478bd9Sstevel@tonic-gate 			return;
23017c478bd9Sstevel@tonic-gate 		}
23027c478bd9Sstevel@tonic-gate 
23037c478bd9Sstevel@tonic-gate 		(void) picld_pluginutil_parse_config_file(roothdl,
23045705cefcSMichael Bergknoff 		    fullfilename);
23057c478bd9Sstevel@tonic-gate 
23067c478bd9Sstevel@tonic-gate 		retval = nvlist_lookup_uint64((nvlist_t *)event_arg,
23075705cefcSMichael Bergknoff 		    PICLEVENTARG_PARENTHANDLE, &fru_picl_hdl);
23087c478bd9Sstevel@tonic-gate 		if (retval != PICL_SUCCESS) {
23097c478bd9Sstevel@tonic-gate 			return;
23107c478bd9Sstevel@tonic-gate 		}
23117c478bd9Sstevel@tonic-gate 
23127c478bd9Sstevel@tonic-gate 		/* create container property */
23137c478bd9Sstevel@tonic-gate 		create_frudata_props(fru_picl_hdl);
23147c478bd9Sstevel@tonic-gate 	}
23157c478bd9Sstevel@tonic-gate }
23167c478bd9Sstevel@tonic-gate 
23177c478bd9Sstevel@tonic-gate /*
23187c478bd9Sstevel@tonic-gate  * Function : plugin_init() is called by daemon. this routine is specified
2319*ada2da53SToomas Soome  *		while registering with daemon. it performs the initialization
23207c478bd9Sstevel@tonic-gate  *		of plugin module.
23217c478bd9Sstevel@tonic-gate  */
23227c478bd9Sstevel@tonic-gate 
23237c478bd9Sstevel@tonic-gate static void
frudata_plugin_init(void)23247c478bd9Sstevel@tonic-gate frudata_plugin_init(void)
23257c478bd9Sstevel@tonic-gate {
23267c478bd9Sstevel@tonic-gate 	int		retval;
23277c478bd9Sstevel@tonic-gate 	int		count;
23287c478bd9Sstevel@tonic-gate 	char		fullfilename[PATH_MAX];
23297c478bd9Sstevel@tonic-gate 	picl_nodehdl_t	fru_nodehdl;
23307c478bd9Sstevel@tonic-gate 	picl_nodehdl_t	roothdl;
23317c478bd9Sstevel@tonic-gate 
23327c478bd9Sstevel@tonic-gate 	retval = ptree_get_root(&roothdl);
23337c478bd9Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
23347c478bd9Sstevel@tonic-gate 		return;
23357c478bd9Sstevel@tonic-gate 	}
23367c478bd9Sstevel@tonic-gate 
23377c478bd9Sstevel@tonic-gate 	(void) ptree_register_handler(PICL_FRU_ADDED,
23385705cefcSMichael Bergknoff 	    frudata_event_handler, NULL);
23397c478bd9Sstevel@tonic-gate 
23407c478bd9Sstevel@tonic-gate 	(void) ptree_register_handler(PICL_FRU_REMOVED,
23415705cefcSMichael Bergknoff 	    frudata_event_handler, NULL);
23427c478bd9Sstevel@tonic-gate 
23437c478bd9Sstevel@tonic-gate 	(void) ptree_register_handler(PICLEVENT_STATE_CHANGE,
23445705cefcSMichael Bergknoff 	    frudata_state_change_evhandler, NULL);
23457c478bd9Sstevel@tonic-gate 
23467c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_lock(&cont_tbl_lock);
23477c478bd9Sstevel@tonic-gate 	for (count = 0; count < TABLE_SIZE; count++) {
23487c478bd9Sstevel@tonic-gate 		container_table[count] = NULL;
23497c478bd9Sstevel@tonic-gate 	}
23507c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_unlock(&cont_tbl_lock);
23517c478bd9Sstevel@tonic-gate 
23527c478bd9Sstevel@tonic-gate 	(void) get_config_file(fullfilename);
23537c478bd9Sstevel@tonic-gate 
23547c478bd9Sstevel@tonic-gate 	(void) picld_pluginutil_parse_config_file(roothdl, fullfilename);
23557c478bd9Sstevel@tonic-gate 
23567c478bd9Sstevel@tonic-gate 	retval = ptree_get_node_by_path(FRUTREE_PATH, &fru_nodehdl);
23577c478bd9Sstevel@tonic-gate 
23587c478bd9Sstevel@tonic-gate 	if (retval != PICL_SUCCESS) {
23597c478bd9Sstevel@tonic-gate 		return;
23607c478bd9Sstevel@tonic-gate 	}
23617c478bd9Sstevel@tonic-gate 
23627c478bd9Sstevel@tonic-gate 	create_frudata_props(fru_nodehdl);
23637c478bd9Sstevel@tonic-gate 
23647c478bd9Sstevel@tonic-gate }
23657c478bd9Sstevel@tonic-gate 
23667c478bd9Sstevel@tonic-gate static void
free_packet_hash_object(hash_obj_t * pkt_obj)23677c478bd9Sstevel@tonic-gate free_packet_hash_object(hash_obj_t *pkt_obj)
23687c478bd9Sstevel@tonic-gate {
23697c478bd9Sstevel@tonic-gate 	hash_obj_t	*tmp_obj;
23707c478bd9Sstevel@tonic-gate 
23717c478bd9Sstevel@tonic-gate 	while (pkt_obj != NULL) {
23727c478bd9Sstevel@tonic-gate 		tmp_obj = pkt_obj->u.pkt_node->next;
23737c478bd9Sstevel@tonic-gate 		free(pkt_obj->u.pkt_node);
23747c478bd9Sstevel@tonic-gate 		free(pkt_obj);
23757c478bd9Sstevel@tonic-gate 		pkt_obj = tmp_obj;
23767c478bd9Sstevel@tonic-gate 	}
23777c478bd9Sstevel@tonic-gate }
23787c478bd9Sstevel@tonic-gate 
23797c478bd9Sstevel@tonic-gate static void
free_segment_hash_object(hash_obj_t * seg_obj)23807c478bd9Sstevel@tonic-gate free_segment_hash_object(hash_obj_t *seg_obj)
23817c478bd9Sstevel@tonic-gate {
23827c478bd9Sstevel@tonic-gate 	hash_obj_t	*tmp_obj;
23837c478bd9Sstevel@tonic-gate 
23847c478bd9Sstevel@tonic-gate 	while (seg_obj != NULL) {
23857c478bd9Sstevel@tonic-gate 		free_packet_hash_object(seg_obj->u.seg_node->packet_list);
23867c478bd9Sstevel@tonic-gate 		tmp_obj = seg_obj->u.seg_node->next;
23877c478bd9Sstevel@tonic-gate 		free(seg_obj->u.seg_node);
23887c478bd9Sstevel@tonic-gate 		free(seg_obj);
23897c478bd9Sstevel@tonic-gate 		seg_obj = tmp_obj;
23907c478bd9Sstevel@tonic-gate 	}
23917c478bd9Sstevel@tonic-gate }
23927c478bd9Sstevel@tonic-gate 
23937c478bd9Sstevel@tonic-gate static void
free_hash_objects(hash_obj_t * sec_obj)23947c478bd9Sstevel@tonic-gate free_hash_objects(hash_obj_t *sec_obj)
23957c478bd9Sstevel@tonic-gate {
23967c478bd9Sstevel@tonic-gate 	hash_obj_t	*tmp_obj;
23977c478bd9Sstevel@tonic-gate 
23987c478bd9Sstevel@tonic-gate 	while (sec_obj != NULL) {
23997c478bd9Sstevel@tonic-gate 		free_segment_hash_object(sec_obj->u.sec_node->segment_list);
24007c478bd9Sstevel@tonic-gate 		tmp_obj = sec_obj->u.sec_node->next;
24017c478bd9Sstevel@tonic-gate 		free(sec_obj->u.sec_node);
24027c478bd9Sstevel@tonic-gate 		free(sec_obj);
24037c478bd9Sstevel@tonic-gate 		sec_obj = tmp_obj;
24047c478bd9Sstevel@tonic-gate 	}
24057c478bd9Sstevel@tonic-gate }
24067c478bd9Sstevel@tonic-gate 
24077c478bd9Sstevel@tonic-gate /*
24087c478bd9Sstevel@tonic-gate  * called from frudata_plugin_fini() this routine walks through
24097c478bd9Sstevel@tonic-gate  * the hash table to free each and very hash object in the hash table.
24107c478bd9Sstevel@tonic-gate  */
24117c478bd9Sstevel@tonic-gate 
24127c478bd9Sstevel@tonic-gate static void
free_hash_table(void)24137c478bd9Sstevel@tonic-gate free_hash_table(void)
24147c478bd9Sstevel@tonic-gate {
24157c478bd9Sstevel@tonic-gate 	int		cnt;
24167c478bd9Sstevel@tonic-gate 	picl_nodehdl_t	nodehdl;
24177c478bd9Sstevel@tonic-gate 	hash_obj_t	*next_obj;
24187c478bd9Sstevel@tonic-gate 	hash_obj_t	*sec_obj;
24197c478bd9Sstevel@tonic-gate 	container_tbl_t	*cont_tbl;
24207c478bd9Sstevel@tonic-gate 
24217c478bd9Sstevel@tonic-gate 	for (cnt = 0; cnt < TABLE_SIZE; cnt++) {
24227c478bd9Sstevel@tonic-gate 
24237c478bd9Sstevel@tonic-gate 		while (container_table[cnt]) {
24247c478bd9Sstevel@tonic-gate 
24257c478bd9Sstevel@tonic-gate 			(void) pthread_mutex_lock(&cont_tbl_lock);
24267c478bd9Sstevel@tonic-gate 
24277c478bd9Sstevel@tonic-gate 			cont_tbl = container_table[cnt];
24287c478bd9Sstevel@tonic-gate 			nodehdl = cont_tbl->picl_hdl;
24297c478bd9Sstevel@tonic-gate 
24307c478bd9Sstevel@tonic-gate 			cont_tbl = lookup_container_table(nodehdl,
24315705cefcSMichael Bergknoff 			    CONTAINER_NODE);
24327c478bd9Sstevel@tonic-gate 			if (cont_tbl == NULL) {
24337c478bd9Sstevel@tonic-gate 				(void) pthread_mutex_unlock(&cont_tbl_lock);
24347c478bd9Sstevel@tonic-gate 				break;
24357c478bd9Sstevel@tonic-gate 			}
24367c478bd9Sstevel@tonic-gate 
24377c478bd9Sstevel@tonic-gate 			unlink_container_node(cont_tbl);
24387c478bd9Sstevel@tonic-gate 
24397c478bd9Sstevel@tonic-gate 			pthread_cond_broadcast(&cont_tbl->cond_var);
24407c478bd9Sstevel@tonic-gate 
24417c478bd9Sstevel@tonic-gate 			(void) pthread_mutex_unlock(&cont_tbl_lock);
24427c478bd9Sstevel@tonic-gate 
24437c478bd9Sstevel@tonic-gate 			/*
24447c478bd9Sstevel@tonic-gate 			 * waiting/blocking calling thread for all I/O in
24457c478bd9Sstevel@tonic-gate 			 * progress to complete. don't free the container
24467c478bd9Sstevel@tonic-gate 			 * hash until all I/O is complete.
24477c478bd9Sstevel@tonic-gate 			 */
24487c478bd9Sstevel@tonic-gate 			(void) pthread_rwlock_wrlock(&cont_tbl->rwlock);
24497c478bd9Sstevel@tonic-gate 
24507c478bd9Sstevel@tonic-gate 			(void) pthread_rwlock_unlock(&cont_tbl->rwlock);
24517c478bd9Sstevel@tonic-gate 
24527c478bd9Sstevel@tonic-gate 			next_obj = cont_tbl->hash_obj->next;
24537c478bd9Sstevel@tonic-gate 			if (next_obj == NULL) {
24547c478bd9Sstevel@tonic-gate 				break;
24557c478bd9Sstevel@tonic-gate 			}
24567c478bd9Sstevel@tonic-gate 
24577c478bd9Sstevel@tonic-gate 			if (next_obj->object_type == CONTAINER_NODE) {
24587c478bd9Sstevel@tonic-gate 				sec_obj = next_obj->u.cont_node->section_list;
24597c478bd9Sstevel@tonic-gate 				free_hash_objects(sec_obj);
24607c478bd9Sstevel@tonic-gate 			}
24617c478bd9Sstevel@tonic-gate 
24627c478bd9Sstevel@tonic-gate 			free(next_obj->u.cont_node);
24637c478bd9Sstevel@tonic-gate 			free(next_obj);
24647c478bd9Sstevel@tonic-gate 			container_table[cnt] = cont_tbl->next;
24657c478bd9Sstevel@tonic-gate 
24667c478bd9Sstevel@tonic-gate 			free(cont_tbl);
24677c478bd9Sstevel@tonic-gate 		}
24687c478bd9Sstevel@tonic-gate 	}
24697c478bd9Sstevel@tonic-gate }
24707c478bd9Sstevel@tonic-gate 
24717c478bd9Sstevel@tonic-gate /*
24727c478bd9Sstevel@tonic-gate  * called by the daemon and perform frudata cleanup. hold the write lock
24737c478bd9Sstevel@tonic-gate  * over the entire hash table to free each and every hash object.
24747c478bd9Sstevel@tonic-gate  */
24757c478bd9Sstevel@tonic-gate 
24767c478bd9Sstevel@tonic-gate static void
frudata_plugin_fini(void)24777c478bd9Sstevel@tonic-gate frudata_plugin_fini(void)
24787c478bd9Sstevel@tonic-gate {
24797c478bd9Sstevel@tonic-gate 
24807c478bd9Sstevel@tonic-gate 	free_hash_table();
24817c478bd9Sstevel@tonic-gate 
24827c478bd9Sstevel@tonic-gate 	(void) ptree_unregister_handler(PICL_FRU_ADDED,
24835705cefcSMichael Bergknoff 	    frudata_event_handler, NULL);
24847c478bd9Sstevel@tonic-gate 
24857c478bd9Sstevel@tonic-gate 	(void) ptree_unregister_handler(PICL_FRU_REMOVED,
24865705cefcSMichael Bergknoff 	    frudata_event_handler, NULL);
24877c478bd9Sstevel@tonic-gate 
24887c478bd9Sstevel@tonic-gate 	(void) ptree_unregister_handler(PICLEVENT_STATE_CHANGE,
24895705cefcSMichael Bergknoff 	    frudata_state_change_evhandler, NULL);
24907c478bd9Sstevel@tonic-gate }
2491