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