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
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate * This file contains code for setting up environmental related nodes
297c478bd9Sstevel@tonic-gate * and properties in the PICL tree.
307c478bd9Sstevel@tonic-gate *
317c478bd9Sstevel@tonic-gate */
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate #include <stdio.h>
347c478bd9Sstevel@tonic-gate #include <fcntl.h>
357c478bd9Sstevel@tonic-gate #include <unistd.h>
367c478bd9Sstevel@tonic-gate #include <syslog.h>
377c478bd9Sstevel@tonic-gate #include <stdlib.h>
387c478bd9Sstevel@tonic-gate #include <limits.h>
397c478bd9Sstevel@tonic-gate #include <errno.h>
407c478bd9Sstevel@tonic-gate #include <sys/open.h>
417c478bd9Sstevel@tonic-gate #include <ctype.h>
427c478bd9Sstevel@tonic-gate #include <string.h>
437c478bd9Sstevel@tonic-gate #include <alloca.h>
447c478bd9Sstevel@tonic-gate #include <libintl.h>
457c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h>
467c478bd9Sstevel@tonic-gate #include <picl.h>
477c478bd9Sstevel@tonic-gate #include <picltree.h>
487c478bd9Sstevel@tonic-gate #include <picld_pluginutil.h>
497c478bd9Sstevel@tonic-gate #include <pthread.h>
507c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
517c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h>
527c478bd9Sstevel@tonic-gate #include "picldefs.h"
537c478bd9Sstevel@tonic-gate #include "envd.h"
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate * Volatile property read/write function typedef
577c478bd9Sstevel@tonic-gate */
587c478bd9Sstevel@tonic-gate typedef int ptree_vol_rdfunc_t(ptree_rarg_t *parg, void *buf);
597c478bd9Sstevel@tonic-gate typedef int ptree_vol_wrfunc_t(ptree_warg_t *parg, const void *buf);
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate extern int monitor_disk_temp;
627c478bd9Sstevel@tonic-gate extern sensor_ctrl_blk_t sensor_ctrl[];
637c478bd9Sstevel@tonic-gate extern fan_ctrl_blk_t fan_ctrl[];
647c478bd9Sstevel@tonic-gate extern env_tuneable_t tuneables[];
657c478bd9Sstevel@tonic-gate extern int errno;
667c478bd9Sstevel@tonic-gate extern int ntuneables;
677c478bd9Sstevel@tonic-gate #define PROP_FAN_SPEED_UNIT_VALUE "rpm"
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate
707c478bd9Sstevel@tonic-gate
717c478bd9Sstevel@tonic-gate /*
727c478bd9Sstevel@tonic-gate * Sensor node data structure
737c478bd9Sstevel@tonic-gate */
747c478bd9Sstevel@tonic-gate typedef struct {
757c478bd9Sstevel@tonic-gate char *parent_path; /* parent path */
767c478bd9Sstevel@tonic-gate char *sensor_name; /* sensor name */
777c478bd9Sstevel@tonic-gate env_sensor_t *sensorp; /* sensor info */
787c478bd9Sstevel@tonic-gate picl_nodehdl_t nodeh; /* sensor node handle */
797c478bd9Sstevel@tonic-gate picl_prophdl_t proph; /* "Temperature" property handle */
807c478bd9Sstevel@tonic-gate picl_prophdl_t target_proph; /* "TargetTemp" property handle */
817c478bd9Sstevel@tonic-gate } sensor_node_t;
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gate
847c478bd9Sstevel@tonic-gate /*
857c478bd9Sstevel@tonic-gate * Sensor nodes array
867c478bd9Sstevel@tonic-gate */
877c478bd9Sstevel@tonic-gate static sensor_node_t sensor_nodes[] = {
887c478bd9Sstevel@tonic-gate {"/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,58",
89*ada2da53SToomas Soome SENSOR_CPU0_DIE, NULL, 0, 0, 0},
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate {"/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,58",
92*ada2da53SToomas Soome SENSOR_CPU1_DIE, NULL, 0, 0, 0},
937c478bd9Sstevel@tonic-gate
947c478bd9Sstevel@tonic-gate {"/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,58",
95*ada2da53SToomas Soome SENSOR_INT_AMB_0, NULL, 0, 0, 0},
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate {"/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c",
98*ada2da53SToomas Soome SENSOR_SYS_OUT, NULL, 0, 0, 0},
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate {"/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c",
101*ada2da53SToomas Soome SENSOR_SYS_IN, NULL, 0, 0, 0},
1027c478bd9Sstevel@tonic-gate
1037c478bd9Sstevel@tonic-gate {"/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c",
104*ada2da53SToomas Soome SENSOR_INT_AMB_1, NULL, 0, 0, 0},
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gate };
1077c478bd9Sstevel@tonic-gate #define N_SENSOR_NODES (sizeof (sensor_nodes)/sizeof (sensor_nodes[0]))
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate
1107c478bd9Sstevel@tonic-gate /*
1117c478bd9Sstevel@tonic-gate * Fan node data structure
1127c478bd9Sstevel@tonic-gate */
1137c478bd9Sstevel@tonic-gate typedef struct {
1147c478bd9Sstevel@tonic-gate char *parent_path; /* parent node path */
1157c478bd9Sstevel@tonic-gate char *fan_name; /* fan name */
1167c478bd9Sstevel@tonic-gate env_fan_t *fanp; /* fan information */
1177c478bd9Sstevel@tonic-gate char *speed_unit; /* speed unit string */
1187c478bd9Sstevel@tonic-gate picl_nodehdl_t nodeh; /* "fan" node handle */
1197c478bd9Sstevel@tonic-gate picl_prophdl_t proph; /* "Speed" property handle */
1207c478bd9Sstevel@tonic-gate } fan_node_t;
1217c478bd9Sstevel@tonic-gate
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate /*
1247c478bd9Sstevel@tonic-gate * Fan node array
1257c478bd9Sstevel@tonic-gate */
1267c478bd9Sstevel@tonic-gate static fan_node_t fan_nodes[] = {
1277c478bd9Sstevel@tonic-gate {"/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,58",
128*ada2da53SToomas Soome ENV_CPU0_FAN, NULL, PROP_FAN_SPEED_UNIT_VALUE, 0, 0},
1297c478bd9Sstevel@tonic-gate
1307c478bd9Sstevel@tonic-gate {"/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,58",
131*ada2da53SToomas Soome ENV_CPU1_FAN, NULL, PROP_FAN_SPEED_UNIT_VALUE, 0, 0},
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate {"/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c",
134*ada2da53SToomas Soome ENV_SYSTEM_OUT_FAN, NULL, PROP_FAN_SPEED_UNIT_VALUE, 0, 0},
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate {"/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c",
137*ada2da53SToomas Soome ENV_SYSTEM_INTAKE_FAN, NULL, PROP_FAN_SPEED_UNIT_VALUE, 0, 0},
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate {"/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,52",
140*ada2da53SToomas Soome ENV_DIMM_FAN, NULL, PROP_FAN_SPEED_UNIT_VALUE, 0, 0},
1417c478bd9Sstevel@tonic-gate
1427c478bd9Sstevel@tonic-gate };
1437c478bd9Sstevel@tonic-gate #define N_FAN_NODES (sizeof (fan_nodes)/sizeof (fan_nodes[0]))
1447c478bd9Sstevel@tonic-gate
1457c478bd9Sstevel@tonic-gate /*
1467c478bd9Sstevel@tonic-gate * Disk node data structure
1477c478bd9Sstevel@tonic-gate */
1487c478bd9Sstevel@tonic-gate typedef struct {
1497c478bd9Sstevel@tonic-gate char *parent_path; /* parent node path */
1507c478bd9Sstevel@tonic-gate char *disk_name; /* disk name */
1517c478bd9Sstevel@tonic-gate env_disk_t *diskp; /* disk information */
1527c478bd9Sstevel@tonic-gate picl_nodehdl_t nodeh; /* "disk" node handle */
1537c478bd9Sstevel@tonic-gate picl_prophdl_t proph; /* "Temperature" property handle */
1547c478bd9Sstevel@tonic-gate } disk_node_t;
1557c478bd9Sstevel@tonic-gate
1567c478bd9Sstevel@tonic-gate /*
1577c478bd9Sstevel@tonic-gate * Disk node array
1587c478bd9Sstevel@tonic-gate */
1597c478bd9Sstevel@tonic-gate static disk_node_t disk_nodes[] = {
160*ada2da53SToomas Soome {DISK0_NODE_PATH, ENV_DISK0, NULL, 0, 0},
161*ada2da53SToomas Soome {DISK1_NODE_PATH, ENV_DISK1, NULL, 0, 0},
1627c478bd9Sstevel@tonic-gate };
1637c478bd9Sstevel@tonic-gate #define N_DISK_NODES (sizeof (disk_nodes)/sizeof (disk_nodes[0]))
1647c478bd9Sstevel@tonic-gate
1657c478bd9Sstevel@tonic-gate /*
1667c478bd9Sstevel@tonic-gate * Miscellaneous declarations
1677c478bd9Sstevel@tonic-gate */
1687c478bd9Sstevel@tonic-gate static void delete_sensor_nodes_and_props(void);
1697c478bd9Sstevel@tonic-gate static void delete_disk_nodes_and_props(void);
1707c478bd9Sstevel@tonic-gate static void delete_fan_nodes_and_props(void);
1717c478bd9Sstevel@tonic-gate
1727c478bd9Sstevel@tonic-gate
1737c478bd9Sstevel@tonic-gate /*
1747c478bd9Sstevel@tonic-gate * Read function for volatile "Temperature" property
1757c478bd9Sstevel@tonic-gate */
1767c478bd9Sstevel@tonic-gate static int
get_current_temp(ptree_rarg_t * parg,void * buf)1777c478bd9Sstevel@tonic-gate get_current_temp(ptree_rarg_t *parg, void *buf)
1787c478bd9Sstevel@tonic-gate {
1797c478bd9Sstevel@tonic-gate tempr_t temp;
1807c478bd9Sstevel@tonic-gate picl_prophdl_t proph;
1817c478bd9Sstevel@tonic-gate sensor_node_t *snodep;
1827c478bd9Sstevel@tonic-gate int i;
1837c478bd9Sstevel@tonic-gate
1847c478bd9Sstevel@tonic-gate /*
1857c478bd9Sstevel@tonic-gate * Locate the sensor in our sensor_nodes table by matching the
1867c478bd9Sstevel@tonic-gate * property handle and get its temperature.
1877c478bd9Sstevel@tonic-gate */
1887c478bd9Sstevel@tonic-gate proph = parg->proph;
1897c478bd9Sstevel@tonic-gate for (i = 0; i < N_SENSOR_NODES; ++i) {
1907c478bd9Sstevel@tonic-gate snodep = &sensor_nodes[i];
1917c478bd9Sstevel@tonic-gate if (snodep->proph != proph)
1927c478bd9Sstevel@tonic-gate continue;
1937c478bd9Sstevel@tonic-gate
1947c478bd9Sstevel@tonic-gate if (get_temperature(snodep->sensorp, &temp) < 0)
1957c478bd9Sstevel@tonic-gate break;
1967c478bd9Sstevel@tonic-gate (void) memcpy(buf, (caddr_t)&temp, sizeof (tempr_t));
1977c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
1987c478bd9Sstevel@tonic-gate }
1997c478bd9Sstevel@tonic-gate return (PICL_FAILURE);
2007c478bd9Sstevel@tonic-gate }
2017c478bd9Sstevel@tonic-gate
2027c478bd9Sstevel@tonic-gate /*
2037c478bd9Sstevel@tonic-gate * Read function for volatile "Temperature" property
2047c478bd9Sstevel@tonic-gate */
2057c478bd9Sstevel@tonic-gate static int
get_disk_temp(ptree_rarg_t * parg,void * buf)2067c478bd9Sstevel@tonic-gate get_disk_temp(ptree_rarg_t *parg, void *buf)
2077c478bd9Sstevel@tonic-gate {
2087c478bd9Sstevel@tonic-gate tempr_t temp;
2097c478bd9Sstevel@tonic-gate picl_prophdl_t proph;
2107c478bd9Sstevel@tonic-gate disk_node_t *dnodep;
2117c478bd9Sstevel@tonic-gate int i;
2127c478bd9Sstevel@tonic-gate
2137c478bd9Sstevel@tonic-gate /*
2147c478bd9Sstevel@tonic-gate * Locate the sensor in our sensor_nodes table by matching the
2157c478bd9Sstevel@tonic-gate * property handle and get its temperature.
2167c478bd9Sstevel@tonic-gate */
2177c478bd9Sstevel@tonic-gate proph = parg->proph;
2187c478bd9Sstevel@tonic-gate for (i = 0; i < N_DISK_NODES; ++i) {
2197c478bd9Sstevel@tonic-gate dnodep = &disk_nodes[i];
2207c478bd9Sstevel@tonic-gate if (dnodep->proph != proph)
2217c478bd9Sstevel@tonic-gate continue;
2227c478bd9Sstevel@tonic-gate
2237c478bd9Sstevel@tonic-gate if (disk_temperature(dnodep->diskp, &temp) < 0)
2247c478bd9Sstevel@tonic-gate break;
2257c478bd9Sstevel@tonic-gate (void) memcpy(buf, (caddr_t)&temp, sizeof (tempr_t));
2267c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
2277c478bd9Sstevel@tonic-gate }
2287c478bd9Sstevel@tonic-gate return (PICL_FAILURE);
2297c478bd9Sstevel@tonic-gate }
2307c478bd9Sstevel@tonic-gate
2317c478bd9Sstevel@tonic-gate /*
2327c478bd9Sstevel@tonic-gate * Read function for volatile "Speed" property on "fan" class node
2337c478bd9Sstevel@tonic-gate */
2347c478bd9Sstevel@tonic-gate static int
set_current_speed(ptree_warg_t * parg,const void * buf)2357c478bd9Sstevel@tonic-gate set_current_speed(ptree_warg_t *parg, const void *buf)
2367c478bd9Sstevel@tonic-gate {
2377c478bd9Sstevel@tonic-gate fanspeed_t speed;
2387c478bd9Sstevel@tonic-gate picl_prophdl_t proph;
2397c478bd9Sstevel@tonic-gate fan_node_t *fnodep;
2407c478bd9Sstevel@tonic-gate int i, ret;
2417c478bd9Sstevel@tonic-gate
2427c478bd9Sstevel@tonic-gate /*
2437c478bd9Sstevel@tonic-gate * Locate the fan in our fan_nodes table by matching the
2447c478bd9Sstevel@tonic-gate * property handle and get fan speed.
2457c478bd9Sstevel@tonic-gate */
2467c478bd9Sstevel@tonic-gate proph = parg->proph;
2477c478bd9Sstevel@tonic-gate for (i = 0; i < N_FAN_NODES; ++i) {
2487c478bd9Sstevel@tonic-gate fnodep = &fan_nodes[i];
2497c478bd9Sstevel@tonic-gate if (fnodep->proph != proph)
2507c478bd9Sstevel@tonic-gate continue;
2517c478bd9Sstevel@tonic-gate if (fnodep->fanp->fd == -1)
2527c478bd9Sstevel@tonic-gate continue;
2537c478bd9Sstevel@tonic-gate
2547c478bd9Sstevel@tonic-gate (void) memcpy((caddr_t)&speed, buf, sizeof (speed));
2557c478bd9Sstevel@tonic-gate
2567c478bd9Sstevel@tonic-gate ret = set_fan_speed(fnodep->fanp, speed);
2577c478bd9Sstevel@tonic-gate
2587c478bd9Sstevel@tonic-gate if (ret < 0) {
2597c478bd9Sstevel@tonic-gate if (ret == -1 && errno == EBUSY)
2607c478bd9Sstevel@tonic-gate return (PICL_NOTWRITABLE);
2617c478bd9Sstevel@tonic-gate if (ret == -2)
2627c478bd9Sstevel@tonic-gate return (PICL_INVALIDARG);
2637c478bd9Sstevel@tonic-gate break;
2647c478bd9Sstevel@tonic-gate }
2657c478bd9Sstevel@tonic-gate
2667c478bd9Sstevel@tonic-gate
2677c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
2687c478bd9Sstevel@tonic-gate }
2697c478bd9Sstevel@tonic-gate return (PICL_FAILURE);
2707c478bd9Sstevel@tonic-gate }
2717c478bd9Sstevel@tonic-gate
2727c478bd9Sstevel@tonic-gate
2737c478bd9Sstevel@tonic-gate /*
2747c478bd9Sstevel@tonic-gate * Read function for volatile "Speed" property on "fan" class node
2757c478bd9Sstevel@tonic-gate */
2767c478bd9Sstevel@tonic-gate static int
get_current_speed(ptree_rarg_t * parg,void * buf)2777c478bd9Sstevel@tonic-gate get_current_speed(ptree_rarg_t *parg, void *buf)
2787c478bd9Sstevel@tonic-gate {
2797c478bd9Sstevel@tonic-gate fanspeed_t speed;
2807c478bd9Sstevel@tonic-gate picl_prophdl_t proph;
2817c478bd9Sstevel@tonic-gate fan_node_t *fnodep;
2827c478bd9Sstevel@tonic-gate int i;
2837c478bd9Sstevel@tonic-gate
2847c478bd9Sstevel@tonic-gate /*
2857c478bd9Sstevel@tonic-gate * Locate the fan in our fan_nodes table by matching the
2867c478bd9Sstevel@tonic-gate * property handle and get fan speed.
2877c478bd9Sstevel@tonic-gate */
2887c478bd9Sstevel@tonic-gate proph = parg->proph;
2897c478bd9Sstevel@tonic-gate for (i = 0; i < N_FAN_NODES; ++i) {
2907c478bd9Sstevel@tonic-gate fnodep = &fan_nodes[i];
2917c478bd9Sstevel@tonic-gate if (fnodep->proph != proph)
2927c478bd9Sstevel@tonic-gate continue;
2937c478bd9Sstevel@tonic-gate if (fnodep->fanp->fd == -1)
2947c478bd9Sstevel@tonic-gate continue;
2957c478bd9Sstevel@tonic-gate if (get_fan_speed(fnodep->fanp, &speed) < 0)
2967c478bd9Sstevel@tonic-gate break;
2977c478bd9Sstevel@tonic-gate
2987c478bd9Sstevel@tonic-gate (void) memcpy(buf, (caddr_t)&speed, sizeof (speed));
2997c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
3007c478bd9Sstevel@tonic-gate }
3017c478bd9Sstevel@tonic-gate return (PICL_FAILURE);
3027c478bd9Sstevel@tonic-gate }
3037c478bd9Sstevel@tonic-gate
3047c478bd9Sstevel@tonic-gate /*
3057c478bd9Sstevel@tonic-gate * Create and add the specified regular property
3067c478bd9Sstevel@tonic-gate */
3077c478bd9Sstevel@tonic-gate
3087c478bd9Sstevel@tonic-gate static int
add_regular_prop(picl_nodehdl_t nodeh,char * name,int type,int access,int size,void * valbuf,picl_prophdl_t * prophp)3097c478bd9Sstevel@tonic-gate add_regular_prop(picl_nodehdl_t nodeh, char *name, int type, int access,
3107c478bd9Sstevel@tonic-gate int size, void *valbuf, picl_prophdl_t *prophp)
3117c478bd9Sstevel@tonic-gate {
3127c478bd9Sstevel@tonic-gate int err;
3137c478bd9Sstevel@tonic-gate ptree_propinfo_t propinfo;
3147c478bd9Sstevel@tonic-gate picl_prophdl_t proph;
3157c478bd9Sstevel@tonic-gate
3167c478bd9Sstevel@tonic-gate err = ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION,
3177c478bd9Sstevel@tonic-gate type, access, size, name, NULL, NULL);
3187c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
3197c478bd9Sstevel@tonic-gate return (err);
3207c478bd9Sstevel@tonic-gate
3217c478bd9Sstevel@tonic-gate err = ptree_create_and_add_prop(nodeh, &propinfo, valbuf, &proph);
3227c478bd9Sstevel@tonic-gate if (err == PICL_SUCCESS && prophp)
3237c478bd9Sstevel@tonic-gate *prophp = proph;
3247c478bd9Sstevel@tonic-gate return (err);
3257c478bd9Sstevel@tonic-gate }
3267c478bd9Sstevel@tonic-gate
3277c478bd9Sstevel@tonic-gate
3287c478bd9Sstevel@tonic-gate /*
3297c478bd9Sstevel@tonic-gate * Create and add the specified volatile property
3307c478bd9Sstevel@tonic-gate */
3317c478bd9Sstevel@tonic-gate static int
add_volatile_prop(picl_nodehdl_t nodeh,char * name,int type,int access,int size,ptree_vol_rdfunc_t * rdfunc,ptree_vol_wrfunc_t * wrfunc,picl_prophdl_t * prophp)3327c478bd9Sstevel@tonic-gate add_volatile_prop(picl_nodehdl_t nodeh, char *name, int type, int access,
3337c478bd9Sstevel@tonic-gate int size, ptree_vol_rdfunc_t *rdfunc, ptree_vol_wrfunc_t *wrfunc,
3347c478bd9Sstevel@tonic-gate picl_prophdl_t *prophp)
3357c478bd9Sstevel@tonic-gate {
3367c478bd9Sstevel@tonic-gate int err;
3377c478bd9Sstevel@tonic-gate ptree_propinfo_t propinfo;
3387c478bd9Sstevel@tonic-gate picl_prophdl_t proph;
3397c478bd9Sstevel@tonic-gate
3407c478bd9Sstevel@tonic-gate err = ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION,
3417c478bd9Sstevel@tonic-gate type, (access|PICL_VOLATILE), size, name, rdfunc, wrfunc);
3427c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
3437c478bd9Sstevel@tonic-gate return (err);
3447c478bd9Sstevel@tonic-gate
3457c478bd9Sstevel@tonic-gate err = ptree_create_and_add_prop(nodeh, &propinfo, NULL, &proph);
3467c478bd9Sstevel@tonic-gate if (err == PICL_SUCCESS && prophp)
3477c478bd9Sstevel@tonic-gate *prophp = proph;
3487c478bd9Sstevel@tonic-gate return (err);
3497c478bd9Sstevel@tonic-gate }
3507c478bd9Sstevel@tonic-gate
3517c478bd9Sstevel@tonic-gate /*
3527c478bd9Sstevel@tonic-gate * Add temperature threshold properties
3537c478bd9Sstevel@tonic-gate */
3547c478bd9Sstevel@tonic-gate static void
add_sensor_thresh_props(picl_nodehdl_t nodeh,sensor_ctrl_blk_t * threshp)3557c478bd9Sstevel@tonic-gate add_sensor_thresh_props(picl_nodehdl_t nodeh, sensor_ctrl_blk_t *threshp)
3567c478bd9Sstevel@tonic-gate {
3577c478bd9Sstevel@tonic-gate picl_prophdl_t proph;
3587c478bd9Sstevel@tonic-gate
3597c478bd9Sstevel@tonic-gate (void) add_regular_prop(nodeh, PICL_PROP_LOW_POWER_OFF,
3607c478bd9Sstevel@tonic-gate PICL_PTYPE_INT, PICL_READ,
3617c478bd9Sstevel@tonic-gate sizeof (threshp->low_power_off),
3627c478bd9Sstevel@tonic-gate (void *)&(threshp->low_power_off), &proph);
3637c478bd9Sstevel@tonic-gate
3647c478bd9Sstevel@tonic-gate (void) add_regular_prop(nodeh, PICL_PROP_LOW_SHUTDOWN,
3657c478bd9Sstevel@tonic-gate PICL_PTYPE_INT, PICL_READ,
3667c478bd9Sstevel@tonic-gate sizeof (threshp->low_shutdown),
3677c478bd9Sstevel@tonic-gate (void *)&(threshp->low_shutdown), &proph);
3687c478bd9Sstevel@tonic-gate
3697c478bd9Sstevel@tonic-gate (void) add_regular_prop(nodeh, PICL_PROP_LOW_WARNING,
3707c478bd9Sstevel@tonic-gate PICL_PTYPE_INT, PICL_READ,
3717c478bd9Sstevel@tonic-gate sizeof (threshp->low_warning),
3727c478bd9Sstevel@tonic-gate (void *)&(threshp->low_warning), &proph);
3737c478bd9Sstevel@tonic-gate
3747c478bd9Sstevel@tonic-gate (void) add_regular_prop(nodeh, PICL_PROP_HIGH_WARNING,
3757c478bd9Sstevel@tonic-gate PICL_PTYPE_INT, PICL_READ,
3767c478bd9Sstevel@tonic-gate sizeof (threshp->high_warning),
3777c478bd9Sstevel@tonic-gate (void *)&(threshp->high_warning), &proph);
3787c478bd9Sstevel@tonic-gate
3797c478bd9Sstevel@tonic-gate (void) add_regular_prop(nodeh, PICL_PROP_HIGH_SHUTDOWN,
3807c478bd9Sstevel@tonic-gate PICL_PTYPE_INT, PICL_READ,
3817c478bd9Sstevel@tonic-gate sizeof (threshp->high_shutdown),
3827c478bd9Sstevel@tonic-gate (void *)&(threshp->high_shutdown), &proph);
3837c478bd9Sstevel@tonic-gate
3847c478bd9Sstevel@tonic-gate (void) add_regular_prop(nodeh, PICL_PROP_HIGH_POWER_OFF,
3857c478bd9Sstevel@tonic-gate PICL_PTYPE_INT, PICL_READ,
3867c478bd9Sstevel@tonic-gate sizeof (threshp->high_power_off),
3877c478bd9Sstevel@tonic-gate (void *)&(threshp->high_power_off), &proph);
3887c478bd9Sstevel@tonic-gate }
3897c478bd9Sstevel@tonic-gate
3907c478bd9Sstevel@tonic-gate
3917c478bd9Sstevel@tonic-gate /*
3927c478bd9Sstevel@tonic-gate * Go through the sensor_nodes array and create those nodes
3937c478bd9Sstevel@tonic-gate * and the Temperature property to report the temperature.
3947c478bd9Sstevel@tonic-gate */
3957c478bd9Sstevel@tonic-gate static int
add_sensor_nodes_and_props()3967c478bd9Sstevel@tonic-gate add_sensor_nodes_and_props()
3977c478bd9Sstevel@tonic-gate {
3987c478bd9Sstevel@tonic-gate int err;
3997c478bd9Sstevel@tonic-gate char *pname, *nodename, *devfs_path;
4007c478bd9Sstevel@tonic-gate sensor_node_t *snodep;
4017c478bd9Sstevel@tonic-gate sensor_ctrl_blk_t *threshp;
4027c478bd9Sstevel@tonic-gate picl_nodehdl_t nodeh, cnodeh;
4037c478bd9Sstevel@tonic-gate picl_prophdl_t proph;
4047c478bd9Sstevel@tonic-gate env_sensor_t *sensorp;
4057c478bd9Sstevel@tonic-gate int i;
4067c478bd9Sstevel@tonic-gate
4077c478bd9Sstevel@tonic-gate for (i = 0; i < N_SENSOR_NODES; ++i) {
4087c478bd9Sstevel@tonic-gate snodep = &sensor_nodes[i];
4097c478bd9Sstevel@tonic-gate /*
4107c478bd9Sstevel@tonic-gate * Get the parent nodeh
4117c478bd9Sstevel@tonic-gate */
4127c478bd9Sstevel@tonic-gate err = ptree_get_node_by_path(snodep->parent_path, &nodeh);
4137c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
4147c478bd9Sstevel@tonic-gate continue;
4157c478bd9Sstevel@tonic-gate sensorp = snodep->sensorp;
4167c478bd9Sstevel@tonic-gate if (sensorp->present == B_FALSE)
4177c478bd9Sstevel@tonic-gate continue;
4187c478bd9Sstevel@tonic-gate /*
4197c478bd9Sstevel@tonic-gate * Create temperature-sensor node
4207c478bd9Sstevel@tonic-gate */
4217c478bd9Sstevel@tonic-gate nodename = snodep->sensor_name;
4227c478bd9Sstevel@tonic-gate err = ptree_create_and_add_node(nodeh, nodename,
4237c478bd9Sstevel@tonic-gate PICL_CLASS_TEMPERATURE_SENSOR, &cnodeh);
4247c478bd9Sstevel@tonic-gate if (env_debug)
4257c478bd9Sstevel@tonic-gate envd_log(LOG_INFO,
4267c478bd9Sstevel@tonic-gate "Creating PICL sensor node '%s' err:%d\n",
4277c478bd9Sstevel@tonic-gate nodename, err);
4287c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
4297c478bd9Sstevel@tonic-gate break;
4307c478bd9Sstevel@tonic-gate
4317c478bd9Sstevel@tonic-gate /* save node handle */
4327c478bd9Sstevel@tonic-gate snodep->nodeh = cnodeh;
4337c478bd9Sstevel@tonic-gate
4347c478bd9Sstevel@tonic-gate /*
4357c478bd9Sstevel@tonic-gate * Add "devfs_path" property in child node
4367c478bd9Sstevel@tonic-gate */
4377c478bd9Sstevel@tonic-gate devfs_path = sensorp->devfs_path;
4387c478bd9Sstevel@tonic-gate pname = PICL_PROP_DEVFS_PATH;
4397c478bd9Sstevel@tonic-gate err = add_regular_prop(cnodeh, pname,
4407c478bd9Sstevel@tonic-gate PICL_PTYPE_CHARSTRING, PICL_READ,
4417c478bd9Sstevel@tonic-gate strlen(devfs_path)+1, (void *)devfs_path, &proph);
4427c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
4437c478bd9Sstevel@tonic-gate break;
4447c478bd9Sstevel@tonic-gate
4457c478bd9Sstevel@tonic-gate /*
4467c478bd9Sstevel@tonic-gate * Now add volatile "temperature" volatile property
4477c478bd9Sstevel@tonic-gate * in this "temperature-sensor" class node.
4487c478bd9Sstevel@tonic-gate */
4497c478bd9Sstevel@tonic-gate pname = PICL_PROP_TEMPERATURE;
4507c478bd9Sstevel@tonic-gate err = add_volatile_prop(cnodeh, pname,
4517c478bd9Sstevel@tonic-gate PICL_PTYPE_INT, PICL_READ, sizeof (tempr_t),
4527c478bd9Sstevel@tonic-gate get_current_temp, NULL, &proph);
4537c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
4547c478bd9Sstevel@tonic-gate break;
4557c478bd9Sstevel@tonic-gate
4567c478bd9Sstevel@tonic-gate /* Save prop handle */
4577c478bd9Sstevel@tonic-gate snodep->proph = proph;
4587c478bd9Sstevel@tonic-gate
4597c478bd9Sstevel@tonic-gate /*
4607c478bd9Sstevel@tonic-gate * Add threshold related properties
4617c478bd9Sstevel@tonic-gate */
4627c478bd9Sstevel@tonic-gate threshp = sensorp->es_ptr;
4637c478bd9Sstevel@tonic-gate
4647c478bd9Sstevel@tonic-gate if (threshp != NULL)
4657c478bd9Sstevel@tonic-gate add_sensor_thresh_props(cnodeh, threshp);
4667c478bd9Sstevel@tonic-gate
4677c478bd9Sstevel@tonic-gate }
4687c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS) {
4697c478bd9Sstevel@tonic-gate delete_sensor_nodes_and_props();
4707c478bd9Sstevel@tonic-gate if (env_debug)
4717c478bd9Sstevel@tonic-gate envd_log(LOG_INFO,
4727c478bd9Sstevel@tonic-gate "Can't create prop/node for sensor '%s'\n",
4737c478bd9Sstevel@tonic-gate nodename);
4747c478bd9Sstevel@tonic-gate return (err);
4757c478bd9Sstevel@tonic-gate }
4767c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
4777c478bd9Sstevel@tonic-gate }
4787c478bd9Sstevel@tonic-gate
4797c478bd9Sstevel@tonic-gate /*
4807c478bd9Sstevel@tonic-gate * Delete all sensor nodes and related properties created by the
4817c478bd9Sstevel@tonic-gate * add_sensor_prop() for each sensor node in the PICL tree.
4827c478bd9Sstevel@tonic-gate */
4837c478bd9Sstevel@tonic-gate static void
delete_sensor_nodes_and_props(void)4847c478bd9Sstevel@tonic-gate delete_sensor_nodes_and_props(void)
4857c478bd9Sstevel@tonic-gate {
4867c478bd9Sstevel@tonic-gate sensor_node_t *snodep;
4877c478bd9Sstevel@tonic-gate int i;
4887c478bd9Sstevel@tonic-gate
4897c478bd9Sstevel@tonic-gate /*
4907c478bd9Sstevel@tonic-gate * Delete/destroy any property created in the sensed device
4917c478bd9Sstevel@tonic-gate * as well as the sensor node and all properties under it.
4927c478bd9Sstevel@tonic-gate * Note that deleiing/destroying a node deletes/destroys
4937c478bd9Sstevel@tonic-gate * all properties within that node.
4947c478bd9Sstevel@tonic-gate */
4957c478bd9Sstevel@tonic-gate
4967c478bd9Sstevel@tonic-gate for (i = 0; i < N_SENSOR_NODES; ++i) {
4977c478bd9Sstevel@tonic-gate snodep = &sensor_nodes[i];
498*ada2da53SToomas Soome if (snodep->nodeh != 0) {
4997c478bd9Sstevel@tonic-gate /* delete node and all properties under it */
5007c478bd9Sstevel@tonic-gate (void) ptree_delete_node(snodep->nodeh);
5017c478bd9Sstevel@tonic-gate (void) ptree_destroy_node(snodep->nodeh);
502*ada2da53SToomas Soome snodep->nodeh = 0;
503*ada2da53SToomas Soome snodep->proph = 0;
5047c478bd9Sstevel@tonic-gate }
5057c478bd9Sstevel@tonic-gate }
5067c478bd9Sstevel@tonic-gate }
5077c478bd9Sstevel@tonic-gate
5087c478bd9Sstevel@tonic-gate /*
5097c478bd9Sstevel@tonic-gate * Go through the disk_nodes array and create those nodes
5107c478bd9Sstevel@tonic-gate * and the Temperature property to report the temperature.
5117c478bd9Sstevel@tonic-gate */
5127c478bd9Sstevel@tonic-gate static int
add_disk_nodes_and_props()5137c478bd9Sstevel@tonic-gate add_disk_nodes_and_props()
5147c478bd9Sstevel@tonic-gate {
5157c478bd9Sstevel@tonic-gate int err;
5167c478bd9Sstevel@tonic-gate char *pname, *nodename, *devfs_path;
5177c478bd9Sstevel@tonic-gate disk_node_t *dnodep;
5187c478bd9Sstevel@tonic-gate picl_nodehdl_t nodeh, cnodeh;
5197c478bd9Sstevel@tonic-gate picl_prophdl_t proph;
5207c478bd9Sstevel@tonic-gate env_disk_t *diskp;
5217c478bd9Sstevel@tonic-gate int i;
5227c478bd9Sstevel@tonic-gate
5237c478bd9Sstevel@tonic-gate for (i = 0; i < N_DISK_NODES; ++i) {
5247c478bd9Sstevel@tonic-gate dnodep = &disk_nodes[i];
5257c478bd9Sstevel@tonic-gate /*
5267c478bd9Sstevel@tonic-gate * Get the parent nodeh
5277c478bd9Sstevel@tonic-gate */
5287c478bd9Sstevel@tonic-gate err = ptree_get_node_by_path(dnodep->parent_path, &nodeh);
5297c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS) {
5307c478bd9Sstevel@tonic-gate if (env_debug)
531*ada2da53SToomas Soome envd_log(LOG_ERR,
532*ada2da53SToomas Soome "failed to get node for path %s\n",
5337c478bd9Sstevel@tonic-gate dnodep->parent_path);
5347c478bd9Sstevel@tonic-gate err = PICL_SUCCESS;
5357c478bd9Sstevel@tonic-gate continue;
5367c478bd9Sstevel@tonic-gate }
5377c478bd9Sstevel@tonic-gate diskp = dnodep->diskp;
5387c478bd9Sstevel@tonic-gate if (diskp->present == B_FALSE)
5397c478bd9Sstevel@tonic-gate continue;
5407c478bd9Sstevel@tonic-gate /*
5417c478bd9Sstevel@tonic-gate * Create temperature-sensor node
5427c478bd9Sstevel@tonic-gate */
5437c478bd9Sstevel@tonic-gate nodename = dnodep->disk_name;
5447c478bd9Sstevel@tonic-gate err = ptree_create_and_add_node(nodeh, nodename,
5457c478bd9Sstevel@tonic-gate PICL_CLASS_TEMPERATURE_SENSOR, &cnodeh);
5467c478bd9Sstevel@tonic-gate if (env_debug)
5477c478bd9Sstevel@tonic-gate envd_log(LOG_ERR,
5487c478bd9Sstevel@tonic-gate "Creating PICL disk node '%s' err:%d\n",
5497c478bd9Sstevel@tonic-gate nodename, err);
5507c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
5517c478bd9Sstevel@tonic-gate break;
5527c478bd9Sstevel@tonic-gate
5537c478bd9Sstevel@tonic-gate /* save node handle */
5547c478bd9Sstevel@tonic-gate dnodep->nodeh = cnodeh;
5557c478bd9Sstevel@tonic-gate
5567c478bd9Sstevel@tonic-gate /*
5577c478bd9Sstevel@tonic-gate * Add "devfs_path" property in child node
5587c478bd9Sstevel@tonic-gate */
5597c478bd9Sstevel@tonic-gate devfs_path = diskp->devfs_path;
5607c478bd9Sstevel@tonic-gate pname = PICL_PROP_DEVFS_PATH;
5617c478bd9Sstevel@tonic-gate err = add_regular_prop(cnodeh, pname,
5627c478bd9Sstevel@tonic-gate PICL_PTYPE_CHARSTRING, PICL_READ,
5637c478bd9Sstevel@tonic-gate strlen(devfs_path)+1, (void *)devfs_path, &proph);
5647c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
5657c478bd9Sstevel@tonic-gate break;
5667c478bd9Sstevel@tonic-gate
5677c478bd9Sstevel@tonic-gate /*
5687c478bd9Sstevel@tonic-gate * Now add volatile "temperature" volatile property
5697c478bd9Sstevel@tonic-gate * in this "temperature-sensor" class node.
5707c478bd9Sstevel@tonic-gate */
5717c478bd9Sstevel@tonic-gate pname = PICL_PROP_TEMPERATURE;
5727c478bd9Sstevel@tonic-gate err = add_volatile_prop(cnodeh, pname,
5737c478bd9Sstevel@tonic-gate PICL_PTYPE_INT, PICL_READ, sizeof (tempr_t),
5747c478bd9Sstevel@tonic-gate get_disk_temp, NULL, &proph);
5757c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
5767c478bd9Sstevel@tonic-gate break;
5777c478bd9Sstevel@tonic-gate
5787c478bd9Sstevel@tonic-gate /* Save prop handle */
5797c478bd9Sstevel@tonic-gate dnodep->proph = proph;
5807c478bd9Sstevel@tonic-gate
5817c478bd9Sstevel@tonic-gate /*
5827c478bd9Sstevel@tonic-gate * Add threshold related properties
5837c478bd9Sstevel@tonic-gate */
5847c478bd9Sstevel@tonic-gate
5857c478bd9Sstevel@tonic-gate (void) add_regular_prop(cnodeh, PICL_PROP_LOW_SHUTDOWN,
5867c478bd9Sstevel@tonic-gate PICL_PTYPE_INT, PICL_READ,
5877c478bd9Sstevel@tonic-gate sizeof (diskp->low_shutdown),
5887c478bd9Sstevel@tonic-gate (void *)&(diskp->low_shutdown), &proph);
5897c478bd9Sstevel@tonic-gate
5907c478bd9Sstevel@tonic-gate (void) add_regular_prop(cnodeh, PICL_PROP_LOW_WARNING,
5917c478bd9Sstevel@tonic-gate PICL_PTYPE_INT, PICL_READ,
5927c478bd9Sstevel@tonic-gate sizeof (diskp->low_warning),
5937c478bd9Sstevel@tonic-gate (void *)&(diskp->low_warning), &proph);
5947c478bd9Sstevel@tonic-gate
5957c478bd9Sstevel@tonic-gate (void) add_regular_prop(cnodeh, PICL_PROP_HIGH_WARNING,
5967c478bd9Sstevel@tonic-gate PICL_PTYPE_INT, PICL_READ,
5977c478bd9Sstevel@tonic-gate sizeof (diskp->high_warning),
5987c478bd9Sstevel@tonic-gate (void *)&(diskp->high_warning), &proph);
5997c478bd9Sstevel@tonic-gate
6007c478bd9Sstevel@tonic-gate (void) add_regular_prop(cnodeh, PICL_PROP_HIGH_SHUTDOWN,
6017c478bd9Sstevel@tonic-gate PICL_PTYPE_INT, PICL_READ,
6027c478bd9Sstevel@tonic-gate sizeof (diskp->high_shutdown),
6037c478bd9Sstevel@tonic-gate (void *)&(diskp->high_shutdown), &proph);
6047c478bd9Sstevel@tonic-gate
6057c478bd9Sstevel@tonic-gate }
6067c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS) {
6077c478bd9Sstevel@tonic-gate delete_disk_nodes_and_props();
6087c478bd9Sstevel@tonic-gate if (env_debug)
6097c478bd9Sstevel@tonic-gate envd_log(LOG_INFO,
6107c478bd9Sstevel@tonic-gate "Can't create prop/node for disk '%s'\n",
6117c478bd9Sstevel@tonic-gate nodename);
6127c478bd9Sstevel@tonic-gate return (err);
6137c478bd9Sstevel@tonic-gate }
6147c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
6157c478bd9Sstevel@tonic-gate }
6167c478bd9Sstevel@tonic-gate
6177c478bd9Sstevel@tonic-gate /*
6187c478bd9Sstevel@tonic-gate * Delete all disk nodes and related properties created by the
6197c478bd9Sstevel@tonic-gate * add_disk_props() for each disk node in the PICL tree.
6207c478bd9Sstevel@tonic-gate */
6217c478bd9Sstevel@tonic-gate static void
delete_disk_nodes_and_props(void)6227c478bd9Sstevel@tonic-gate delete_disk_nodes_and_props(void)
6237c478bd9Sstevel@tonic-gate {
6247c478bd9Sstevel@tonic-gate disk_node_t *dnodep;
6257c478bd9Sstevel@tonic-gate int i;
6267c478bd9Sstevel@tonic-gate
6277c478bd9Sstevel@tonic-gate /*
6287c478bd9Sstevel@tonic-gate * Delete/destroy disk node and all properties under it.
6297c478bd9Sstevel@tonic-gate * Note that deleting/destroying a node deletes/destroys
6307c478bd9Sstevel@tonic-gate * all properties within that node.
6317c478bd9Sstevel@tonic-gate */
6327c478bd9Sstevel@tonic-gate
6337c478bd9Sstevel@tonic-gate for (i = 0; i < N_DISK_NODES; ++i) {
6347c478bd9Sstevel@tonic-gate dnodep = &disk_nodes[i];
635*ada2da53SToomas Soome if (dnodep->nodeh != 0) {
6367c478bd9Sstevel@tonic-gate (void) ptree_delete_node(dnodep->nodeh);
6377c478bd9Sstevel@tonic-gate (void) ptree_destroy_node(dnodep->nodeh);
638*ada2da53SToomas Soome dnodep->nodeh = 0;
639*ada2da53SToomas Soome dnodep->proph = 0;
6407c478bd9Sstevel@tonic-gate }
6417c478bd9Sstevel@tonic-gate }
6427c478bd9Sstevel@tonic-gate }
6437c478bd9Sstevel@tonic-gate
6447c478bd9Sstevel@tonic-gate /*
6457c478bd9Sstevel@tonic-gate * For each entry in fan_nodes[] array, do the following:
6467c478bd9Sstevel@tonic-gate * - Create specified "fan" class node.
6477c478bd9Sstevel@tonic-gate * - Create "Speed" volatile propery under "fan" class node.
6487c478bd9Sstevel@tonic-gate * - Create "SpeedUnit" property under "fan" class node.
6497c478bd9Sstevel@tonic-gate */
6507c478bd9Sstevel@tonic-gate static int
add_fan_nodes_and_props()6517c478bd9Sstevel@tonic-gate add_fan_nodes_and_props()
6527c478bd9Sstevel@tonic-gate {
6537c478bd9Sstevel@tonic-gate int err;
6547c478bd9Sstevel@tonic-gate char *pname, *nodename, *devfs_path;
6557c478bd9Sstevel@tonic-gate env_fan_t *fanp;
6567c478bd9Sstevel@tonic-gate fan_node_t *fnodep;
6577c478bd9Sstevel@tonic-gate picl_nodehdl_t nodeh, cnodeh;
6587c478bd9Sstevel@tonic-gate picl_prophdl_t proph;
6597c478bd9Sstevel@tonic-gate int i;
6607c478bd9Sstevel@tonic-gate
6617c478bd9Sstevel@tonic-gate for (i = 0; i < N_FAN_NODES; ++i) {
6627c478bd9Sstevel@tonic-gate /*
6637c478bd9Sstevel@tonic-gate * Add various fan nodes and properties
6647c478bd9Sstevel@tonic-gate */
6657c478bd9Sstevel@tonic-gate fnodep = &fan_nodes[i];
6667c478bd9Sstevel@tonic-gate if (fnodep->fanp->present == B_FALSE)
6677c478bd9Sstevel@tonic-gate continue;
6687c478bd9Sstevel@tonic-gate /*
6697c478bd9Sstevel@tonic-gate * get parent nodeh
6707c478bd9Sstevel@tonic-gate */
6717c478bd9Sstevel@tonic-gate err = ptree_get_node_by_path(fnodep->parent_path, &nodeh);
6727c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS) {
6737c478bd9Sstevel@tonic-gate if (env_debug)
6747c478bd9Sstevel@tonic-gate envd_log(LOG_ERR,
6757c478bd9Sstevel@tonic-gate "node for %s NOT FOUND.\n", fnodep->parent_path);
6767c478bd9Sstevel@tonic-gate err = PICL_SUCCESS;
6777c478bd9Sstevel@tonic-gate continue;
6787c478bd9Sstevel@tonic-gate }
6797c478bd9Sstevel@tonic-gate /*
6807c478bd9Sstevel@tonic-gate * Create "fan" class node and save node handle
6817c478bd9Sstevel@tonic-gate */
6827c478bd9Sstevel@tonic-gate nodename = fnodep->fan_name;
6837c478bd9Sstevel@tonic-gate err = ptree_create_and_add_node(nodeh, nodename,
6847c478bd9Sstevel@tonic-gate PICL_CLASS_FAN, &cnodeh);
6857c478bd9Sstevel@tonic-gate if (env_debug)
6867c478bd9Sstevel@tonic-gate envd_log(LOG_ERR,
6877c478bd9Sstevel@tonic-gate "Creating PICL fan node '%s' err:%d\n",
6887c478bd9Sstevel@tonic-gate nodename, err);
6897c478bd9Sstevel@tonic-gate
6907c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
6917c478bd9Sstevel@tonic-gate break;
6927c478bd9Sstevel@tonic-gate fnodep->nodeh = cnodeh;
6937c478bd9Sstevel@tonic-gate
6947c478bd9Sstevel@tonic-gate /*
6957c478bd9Sstevel@tonic-gate * Add "devfs_path" property in child node
6967c478bd9Sstevel@tonic-gate */
6977c478bd9Sstevel@tonic-gate fanp = fnodep->fanp;
6987c478bd9Sstevel@tonic-gate devfs_path = fanp->devfs_path;
6997c478bd9Sstevel@tonic-gate pname = PICL_PROP_DEVFS_PATH;
7007c478bd9Sstevel@tonic-gate err = add_regular_prop(cnodeh, pname,
7017c478bd9Sstevel@tonic-gate PICL_PTYPE_CHARSTRING, PICL_READ,
7027c478bd9Sstevel@tonic-gate strlen(devfs_path)+1, (void *)devfs_path, &proph);
7037c478bd9Sstevel@tonic-gate
7047c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
7057c478bd9Sstevel@tonic-gate
7067c478bd9Sstevel@tonic-gate break;
7077c478bd9Sstevel@tonic-gate
7087c478bd9Sstevel@tonic-gate /*
7097c478bd9Sstevel@tonic-gate * Add "Speed" volatile property in this "fan"
7107c478bd9Sstevel@tonic-gate * class node and save prop handle.
7117c478bd9Sstevel@tonic-gate */
7127c478bd9Sstevel@tonic-gate pname = PICL_PROP_FAN_SPEED;
7137c478bd9Sstevel@tonic-gate if (fanp->id == DIMM_FAN_ID) {
7147c478bd9Sstevel@tonic-gate /*
7157c478bd9Sstevel@tonic-gate * We do not permit setting of DIMM FAN speeds.
7167c478bd9Sstevel@tonic-gate */
7177c478bd9Sstevel@tonic-gate err = add_volatile_prop(cnodeh, pname, PICL_PTYPE_INT,
7187c478bd9Sstevel@tonic-gate PICL_READ, sizeof (fanspeed_t),
7197c478bd9Sstevel@tonic-gate get_current_speed,
7207c478bd9Sstevel@tonic-gate NULL, &proph);
7217c478bd9Sstevel@tonic-gate } else {
7227c478bd9Sstevel@tonic-gate err = add_volatile_prop(cnodeh, pname, PICL_PTYPE_INT,
7237c478bd9Sstevel@tonic-gate PICL_READ|PICL_WRITE, sizeof (fanspeed_t),
7247c478bd9Sstevel@tonic-gate get_current_speed,
7257c478bd9Sstevel@tonic-gate set_current_speed, &proph);
7267c478bd9Sstevel@tonic-gate }
7277c478bd9Sstevel@tonic-gate
7287c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
7297c478bd9Sstevel@tonic-gate break;
7307c478bd9Sstevel@tonic-gate fnodep->proph = proph;
7317c478bd9Sstevel@tonic-gate
7327c478bd9Sstevel@tonic-gate /*
7337c478bd9Sstevel@tonic-gate * Add other "fan" class properties
7347c478bd9Sstevel@tonic-gate */
7357c478bd9Sstevel@tonic-gate pname = PICL_PROP_FAN_SPEED_UNIT;
7367c478bd9Sstevel@tonic-gate err = add_regular_prop(cnodeh, pname,
7377c478bd9Sstevel@tonic-gate PICL_PTYPE_CHARSTRING, PICL_READ,
7387c478bd9Sstevel@tonic-gate strlen(fnodep->speed_unit)+1,
7397c478bd9Sstevel@tonic-gate (void *)fnodep->speed_unit, &proph);
7407c478bd9Sstevel@tonic-gate
7417c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
7427c478bd9Sstevel@tonic-gate break;
7437c478bd9Sstevel@tonic-gate }
7447c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS) {
7457c478bd9Sstevel@tonic-gate delete_fan_nodes_and_props();
7467c478bd9Sstevel@tonic-gate if (env_debug)
7477c478bd9Sstevel@tonic-gate envd_log(LOG_WARNING,
7487c478bd9Sstevel@tonic-gate "Can't create prop/node for fan '%s'\n",
7497c478bd9Sstevel@tonic-gate nodename);
7507c478bd9Sstevel@tonic-gate return (err);
7517c478bd9Sstevel@tonic-gate }
7527c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
7537c478bd9Sstevel@tonic-gate }
7547c478bd9Sstevel@tonic-gate
7557c478bd9Sstevel@tonic-gate
7567c478bd9Sstevel@tonic-gate /*
7577c478bd9Sstevel@tonic-gate * Delete all fan nodes and related properties created by the
7587c478bd9Sstevel@tonic-gate * add_fan_props() for each fan node in the PICL tree.
7597c478bd9Sstevel@tonic-gate */
7607c478bd9Sstevel@tonic-gate static void
delete_fan_nodes_and_props(void)7617c478bd9Sstevel@tonic-gate delete_fan_nodes_and_props(void)
7627c478bd9Sstevel@tonic-gate {
7637c478bd9Sstevel@tonic-gate fan_node_t *fnodep;
7647c478bd9Sstevel@tonic-gate int i;
7657c478bd9Sstevel@tonic-gate
7667c478bd9Sstevel@tonic-gate /*
7677c478bd9Sstevel@tonic-gate * Delete/destroy fan node and all properties under it.
7687c478bd9Sstevel@tonic-gate * Note that deleting/destroying a node deletes/destroys
7697c478bd9Sstevel@tonic-gate * all properties within that node.
7707c478bd9Sstevel@tonic-gate */
7717c478bd9Sstevel@tonic-gate
7727c478bd9Sstevel@tonic-gate for (i = 0; i < N_FAN_NODES; ++i) {
7737c478bd9Sstevel@tonic-gate fnodep = &fan_nodes[i];
774*ada2da53SToomas Soome if (fnodep->nodeh != 0) {
7757c478bd9Sstevel@tonic-gate (void) ptree_delete_node(fnodep->nodeh);
7767c478bd9Sstevel@tonic-gate (void) ptree_destroy_node(fnodep->nodeh);
777*ada2da53SToomas Soome fnodep->nodeh = 0;
7787c478bd9Sstevel@tonic-gate }
7797c478bd9Sstevel@tonic-gate }
7807c478bd9Sstevel@tonic-gate }
7817c478bd9Sstevel@tonic-gate /*
7827c478bd9Sstevel@tonic-gate * Tuneables publishing functions
7837c478bd9Sstevel@tonic-gate */
7847c478bd9Sstevel@tonic-gate static int
copy_persistent_tuneable(env_tuneable_t * tune,char * buf)7857c478bd9Sstevel@tonic-gate copy_persistent_tuneable(env_tuneable_t *tune, char *buf)
7867c478bd9Sstevel@tonic-gate {
7877c478bd9Sstevel@tonic-gate
7887c478bd9Sstevel@tonic-gate switch (tune->type) {
7897c478bd9Sstevel@tonic-gate case PICL_PTYPE_INT : {
7907c478bd9Sstevel@tonic-gate (void) memcpy((int *)tune->value,
7917c478bd9Sstevel@tonic-gate buf, tune->nbytes);
7927c478bd9Sstevel@tonic-gate break;
7937c478bd9Sstevel@tonic-gate }
7947c478bd9Sstevel@tonic-gate case PICL_PTYPE_CHARSTRING : {
7957c478bd9Sstevel@tonic-gate (void) memcpy((caddr_t)tune->value,
7967c478bd9Sstevel@tonic-gate buf, tune->nbytes);
7977c478bd9Sstevel@tonic-gate break;
7987c478bd9Sstevel@tonic-gate }
7997c478bd9Sstevel@tonic-gate default : {
8007c478bd9Sstevel@tonic-gate return (PICL_FAILURE);
8017c478bd9Sstevel@tonic-gate }
8027c478bd9Sstevel@tonic-gate }
8037c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
8047c478bd9Sstevel@tonic-gate }
8057c478bd9Sstevel@tonic-gate
8067c478bd9Sstevel@tonic-gate static void
env_parse_tunables(picl_nodehdl_t rooth)8077c478bd9Sstevel@tonic-gate env_parse_tunables(picl_nodehdl_t rooth)
8087c478bd9Sstevel@tonic-gate {
8097c478bd9Sstevel@tonic-gate char nmbuf[SYS_NMLN];
8107c478bd9Sstevel@tonic-gate char pname[PATH_MAX];
8117c478bd9Sstevel@tonic-gate
8127c478bd9Sstevel@tonic-gate if (sysinfo(SI_PLATFORM, nmbuf, sizeof (nmbuf)) != -1) {
8137c478bd9Sstevel@tonic-gate (void) snprintf(pname, PATH_MAX, PICLD_PLAT_PLUGIN_DIRF, nmbuf);
8147c478bd9Sstevel@tonic-gate (void) strlcat(pname, TUNABLE_CONF_FILE, PATH_MAX);
8157c478bd9Sstevel@tonic-gate if (access(pname, R_OK) == 0) {
8167c478bd9Sstevel@tonic-gate (void) picld_pluginutil_parse_config_file(rooth, pname);
8177c478bd9Sstevel@tonic-gate return;
8187c478bd9Sstevel@tonic-gate }
8197c478bd9Sstevel@tonic-gate }
8207c478bd9Sstevel@tonic-gate }
8217c478bd9Sstevel@tonic-gate
8227c478bd9Sstevel@tonic-gate int
env_picl_setup_tuneables(void)8237c478bd9Sstevel@tonic-gate env_picl_setup_tuneables(void)
8247c478bd9Sstevel@tonic-gate {
8257c478bd9Sstevel@tonic-gate int err;
8267c478bd9Sstevel@tonic-gate int i;
8277c478bd9Sstevel@tonic-gate picl_nodehdl_t nodeh;
8287c478bd9Sstevel@tonic-gate picl_nodehdl_t rooth;
8297c478bd9Sstevel@tonic-gate picl_prophdl_t proph;
8307c478bd9Sstevel@tonic-gate env_tuneable_t *tuneablep;
8317c478bd9Sstevel@tonic-gate char read_buf[BUFSIZ];
8327c478bd9Sstevel@tonic-gate
8337c478bd9Sstevel@tonic-gate if (ptree_get_root(&rooth) != PICL_SUCCESS) {
8347c478bd9Sstevel@tonic-gate return (PICL_FAILURE);
8357c478bd9Sstevel@tonic-gate }
8367c478bd9Sstevel@tonic-gate err = ptree_create_and_add_node(rooth, PICL_PLUGINS_NODE,
8377c478bd9Sstevel@tonic-gate PICL_CLASS_PICL, &nodeh);
8387c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
8397c478bd9Sstevel@tonic-gate return (PICL_FAILURE);
8407c478bd9Sstevel@tonic-gate err = ptree_create_and_add_node(nodeh, PICL_ENVIRONMENTAL_NODE,
8417c478bd9Sstevel@tonic-gate PICL_CLASS_PICL, &nodeh);
8427c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS) {
8437c478bd9Sstevel@tonic-gate return (PICL_FAILURE);
8447c478bd9Sstevel@tonic-gate }
8457c478bd9Sstevel@tonic-gate
8467c478bd9Sstevel@tonic-gate /*
8477c478bd9Sstevel@tonic-gate * Parse the conf file
8487c478bd9Sstevel@tonic-gate */
8497c478bd9Sstevel@tonic-gate env_parse_tunables(rooth);
8507c478bd9Sstevel@tonic-gate for (i = 0; i < ntuneables; i++) {
8517c478bd9Sstevel@tonic-gate tuneablep = &tuneables[i];
8527c478bd9Sstevel@tonic-gate err = ptree_get_propval_by_name(nodeh, tuneablep->name,
8537c478bd9Sstevel@tonic-gate read_buf, tuneablep->nbytes);
8547c478bd9Sstevel@tonic-gate
8557c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS) {
8567c478bd9Sstevel@tonic-gate /*
8577c478bd9Sstevel@tonic-gate * Add volitle functions to environmental node
8587c478bd9Sstevel@tonic-gate */
8597c478bd9Sstevel@tonic-gate err = add_volatile_prop(nodeh, tuneablep->name,
8607c478bd9Sstevel@tonic-gate tuneablep->type,
8617c478bd9Sstevel@tonic-gate PICL_READ|PICL_WRITE, tuneablep->nbytes,
8627c478bd9Sstevel@tonic-gate tuneablep->rfunc,
8637c478bd9Sstevel@tonic-gate tuneablep->wfunc, &proph);
8647c478bd9Sstevel@tonic-gate
8657c478bd9Sstevel@tonic-gate tuneablep->proph = proph;
8667c478bd9Sstevel@tonic-gate } else {
8677c478bd9Sstevel@tonic-gate /*
8687c478bd9Sstevel@tonic-gate * property is persistent
8697c478bd9Sstevel@tonic-gate */
8707c478bd9Sstevel@tonic-gate (void) copy_persistent_tuneable(tuneablep,
8717c478bd9Sstevel@tonic-gate read_buf);
8727c478bd9Sstevel@tonic-gate }
8737c478bd9Sstevel@tonic-gate }
8747c478bd9Sstevel@tonic-gate
8757c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
8767c478bd9Sstevel@tonic-gate }
8777c478bd9Sstevel@tonic-gate
8787c478bd9Sstevel@tonic-gate /*
8797c478bd9Sstevel@tonic-gate * Find the ENVMODEL_CONF_FILE file.
8807c478bd9Sstevel@tonic-gate */
8817c478bd9Sstevel@tonic-gate static int
get_envmodel_conf_file(char * outfilename)8827c478bd9Sstevel@tonic-gate get_envmodel_conf_file(char *outfilename)
8837c478bd9Sstevel@tonic-gate {
8847c478bd9Sstevel@tonic-gate char nmbuf[SYS_NMLN];
8857c478bd9Sstevel@tonic-gate char pname[PATH_MAX];
8867c478bd9Sstevel@tonic-gate
8877c478bd9Sstevel@tonic-gate if (sysinfo(SI_PLATFORM, nmbuf, sizeof (nmbuf)) != -1) {
8887c478bd9Sstevel@tonic-gate (void) snprintf(pname, PATH_MAX, PICLD_PLAT_PLUGIN_DIRF, nmbuf);
8897c478bd9Sstevel@tonic-gate (void) strlcat(pname, ENV_CONF_FILE, PATH_MAX);
8907c478bd9Sstevel@tonic-gate if (access(pname, R_OK) == 0) {
8917c478bd9Sstevel@tonic-gate (void) strlcpy(outfilename, pname, PATH_MAX);
8927c478bd9Sstevel@tonic-gate return (0);
8937c478bd9Sstevel@tonic-gate }
8947c478bd9Sstevel@tonic-gate }
8957c478bd9Sstevel@tonic-gate
8967c478bd9Sstevel@tonic-gate if (sysinfo(SI_MACHINE, nmbuf, sizeof (nmbuf)) != -1) {
8977c478bd9Sstevel@tonic-gate (void) snprintf(pname, PATH_MAX, PICLD_PLAT_PLUGIN_DIRF, nmbuf);
8987c478bd9Sstevel@tonic-gate (void) strlcat(pname, ENV_CONF_FILE, PATH_MAX);
8997c478bd9Sstevel@tonic-gate if (access(pname, R_OK) == 0) {
9007c478bd9Sstevel@tonic-gate (void) strlcpy(outfilename, pname, PATH_MAX);
9017c478bd9Sstevel@tonic-gate return (0);
9027c478bd9Sstevel@tonic-gate }
9037c478bd9Sstevel@tonic-gate }
9047c478bd9Sstevel@tonic-gate
9057c478bd9Sstevel@tonic-gate (void) snprintf(pname, PATH_MAX, "%s/%s", PICLD_COMMON_PLUGIN_DIR,
9067c478bd9Sstevel@tonic-gate ENV_CONF_FILE);
9077c478bd9Sstevel@tonic-gate
9087c478bd9Sstevel@tonic-gate if (access(pname, R_OK) == 0) {
9097c478bd9Sstevel@tonic-gate (void) strlcpy(outfilename, pname, PATH_MAX);
9107c478bd9Sstevel@tonic-gate return (0);
9117c478bd9Sstevel@tonic-gate }
9127c478bd9Sstevel@tonic-gate
9137c478bd9Sstevel@tonic-gate return (-1);
9147c478bd9Sstevel@tonic-gate }
9157c478bd9Sstevel@tonic-gate
9167c478bd9Sstevel@tonic-gate /* Delete all sensor/fan nodes and any properties created by this plugin */
9177c478bd9Sstevel@tonic-gate void
env_picl_destroy(void)9187c478bd9Sstevel@tonic-gate env_picl_destroy(void)
9197c478bd9Sstevel@tonic-gate {
9207c478bd9Sstevel@tonic-gate delete_fan_nodes_and_props();
9217c478bd9Sstevel@tonic-gate delete_sensor_nodes_and_props();
9227c478bd9Sstevel@tonic-gate delete_disk_nodes_and_props();
9237c478bd9Sstevel@tonic-gate }
9247c478bd9Sstevel@tonic-gate
9257c478bd9Sstevel@tonic-gate void
env_picl_setup(void)9267c478bd9Sstevel@tonic-gate env_picl_setup(void)
9277c478bd9Sstevel@tonic-gate {
9287c478bd9Sstevel@tonic-gate int err;
9297c478bd9Sstevel@tonic-gate sensor_node_t *snodep;
9307c478bd9Sstevel@tonic-gate fan_node_t *fnodep;
9317c478bd9Sstevel@tonic-gate disk_node_t *dnodep;
9327c478bd9Sstevel@tonic-gate picl_nodehdl_t plath;
9337c478bd9Sstevel@tonic-gate char fullfilename[PATH_MAX];
9347c478bd9Sstevel@tonic-gate picl_nodehdl_t rooth;
9357c478bd9Sstevel@tonic-gate int i;
9367c478bd9Sstevel@tonic-gate
9377c478bd9Sstevel@tonic-gate
9387c478bd9Sstevel@tonic-gate /*
9397c478bd9Sstevel@tonic-gate * Initialize sensorp and other fields in the sensor_nodes[] array
9407c478bd9Sstevel@tonic-gate */
9417c478bd9Sstevel@tonic-gate
9427c478bd9Sstevel@tonic-gate for (i = 0; i < N_SENSOR_NODES; ++i) {
9437c478bd9Sstevel@tonic-gate snodep = &sensor_nodes[i];
9447c478bd9Sstevel@tonic-gate snodep->sensorp = sensor_lookup(snodep->sensor_name);
945*ada2da53SToomas Soome snodep->nodeh = 0;
946*ada2da53SToomas Soome snodep->proph = 0;
947*ada2da53SToomas Soome snodep->target_proph = 0;
9487c478bd9Sstevel@tonic-gate }
9497c478bd9Sstevel@tonic-gate
9507c478bd9Sstevel@tonic-gate /*
9517c478bd9Sstevel@tonic-gate * Initialize fanp and other fields in the fan_nodes[] array
9527c478bd9Sstevel@tonic-gate */
9537c478bd9Sstevel@tonic-gate for (i = 0; i < N_FAN_NODES; ++i) {
9547c478bd9Sstevel@tonic-gate fnodep = &fan_nodes[i];
9557c478bd9Sstevel@tonic-gate fnodep->fanp = fan_lookup(fnodep->fan_name);
956*ada2da53SToomas Soome fnodep->nodeh = 0;
957*ada2da53SToomas Soome fnodep->proph = 0;
9587c478bd9Sstevel@tonic-gate }
9597c478bd9Sstevel@tonic-gate
9607c478bd9Sstevel@tonic-gate /*
9617c478bd9Sstevel@tonic-gate * Initialize diskp and other fields in the disk_nodes[] array
9627c478bd9Sstevel@tonic-gate */
9637c478bd9Sstevel@tonic-gate for (i = 0; i < N_DISK_NODES; ++i) {
9647c478bd9Sstevel@tonic-gate dnodep = &disk_nodes[i];
9657c478bd9Sstevel@tonic-gate dnodep->diskp = disk_lookup(dnodep->disk_name);
966*ada2da53SToomas Soome dnodep->nodeh = 0;
967*ada2da53SToomas Soome dnodep->proph = 0;
9687c478bd9Sstevel@tonic-gate }
9697c478bd9Sstevel@tonic-gate
9707c478bd9Sstevel@tonic-gate /*
9717c478bd9Sstevel@tonic-gate * Get platform handle and populate PICL tree with environmental
9727c478bd9Sstevel@tonic-gate * nodes and properties
9737c478bd9Sstevel@tonic-gate */
9747c478bd9Sstevel@tonic-gate err = ptree_get_node_by_path("/platform", &plath);
9757c478bd9Sstevel@tonic-gate
9767c478bd9Sstevel@tonic-gate if (err == PICL_SUCCESS)
9777c478bd9Sstevel@tonic-gate err = add_sensor_nodes_and_props();
9787c478bd9Sstevel@tonic-gate if (err == PICL_SUCCESS)
9797c478bd9Sstevel@tonic-gate err = add_fan_nodes_and_props();
9807c478bd9Sstevel@tonic-gate if ((err == PICL_SUCCESS) && (monitor_disk_temp))
9817c478bd9Sstevel@tonic-gate err = add_disk_nodes_and_props();
9827c478bd9Sstevel@tonic-gate
9837c478bd9Sstevel@tonic-gate /*
9847c478bd9Sstevel@tonic-gate * We can safely call delete_xxx_nodes_and_props even
9857c478bd9Sstevel@tonic-gate * if nodes were not added.
9867c478bd9Sstevel@tonic-gate */
9877c478bd9Sstevel@tonic-gate
9887c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS) {
9897c478bd9Sstevel@tonic-gate delete_fan_nodes_and_props();
9907c478bd9Sstevel@tonic-gate delete_disk_nodes_and_props();
9917c478bd9Sstevel@tonic-gate delete_sensor_nodes_and_props();
9927c478bd9Sstevel@tonic-gate envd_log(LOG_CRIT, ENVD_PICL_SETUP_FAILED);
9937c478bd9Sstevel@tonic-gate return;
9947c478bd9Sstevel@tonic-gate }
9957c478bd9Sstevel@tonic-gate
9967c478bd9Sstevel@tonic-gate /*
9977c478bd9Sstevel@tonic-gate * Parse the envmodel.conf file and populate the PICL tree
9987c478bd9Sstevel@tonic-gate */
9997c478bd9Sstevel@tonic-gate if (get_envmodel_conf_file(fullfilename) < 0)
10007c478bd9Sstevel@tonic-gate envd_log(LOG_CRIT, ENVD_PICL_SETUP_FAILED);
10017c478bd9Sstevel@tonic-gate if (ptree_get_root(&rooth) != PICL_SUCCESS)
10027c478bd9Sstevel@tonic-gate envd_log(LOG_CRIT, ENVD_PICL_SETUP_FAILED);
10037c478bd9Sstevel@tonic-gate err = picld_pluginutil_parse_config_file(rooth, fullfilename);
10047c478bd9Sstevel@tonic-gate
10057c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
10067c478bd9Sstevel@tonic-gate envd_log(LOG_CRIT, ENVD_PICL_SETUP_FAILED);
10077c478bd9Sstevel@tonic-gate }
1008