psvcpolicy.c revision 298b7f4ca426d69789dddfabc7fd2863cf7a0ea4
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This file contains routines to support the Platform Services Plugin
* These routines implement the platform independent environment monitoring
* and control policies that may be invoked by a daemon thread within
* the plugin
*/
#include <syslog.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <libintl.h>
#include <errno.h>
#include <fcntl.h>
#include <strings.h>
#include <libintl.h>
#include <string.h>
#include <limits.h>
#include <picl.h>
#include <picltree.h>
#include <string.h>
#include <psvc_objects.h>
#define LOWTEMP_CRITICAL_MSG \
gettext("CRITICAL : LOW TEMPERATURE DETECTED %d, %s")
#define LOWTEMP_WARNING_MSG \
gettext("WARNING : LOW TEMPERATURE DETECTED %d, %s")
#define HIGHTEMP_CRITICAL_MSG \
gettext("CRITICAL : HIGH TEMPERATURE DETECTED %d, %s")
#define HIGHTEMP_WARNING_MSG \
gettext("WARNING : HIGH TEMPERATURE DETECTED %d, %s")
#define DEVICE_FAILURE_MSG \
gettext("CRITICAL: Device %s failure detected by sensor %s\n")
#define KEYSWITCH_POS_READ_FAILED_MSG \
gettext("Keyswitch position could not be determined")
#define GET_PRESENCE_FAILED_MSG \
gettext("Failed to get presence attribute, id = %s, errno = %d\n")
#define GET_SENSOR_FAILED_MSG \
gettext("Failed to get sensor value, id = %s, errno = %d\n")
#define PS_OVER_CURRENT_MSG \
gettext("WARNING: Power Supply overcurrent detected for %s\n")
#define SET_LED_FAILED_MSG \
gettext("Failed to set LED state, id = %s, errno = %d\n")
#define SET_FANSPEED_FAILED_MSG \
gettext("Failed to set fan speed, id = %s, errno = %d\n")
#define FAN_MISSING_MSG \
gettext("WARNING: Fan missing, id = %s\n")
#define TEMP_SENSOR_FAULT \
gettext("WARNING: Temperature Sensor %s returning faulty temp\n")
#define TEMP_OFFSET 17
static char *shutdown_string = "shutdown -y -g 60 -i 5 \"OVERTEMP condition\"";
static int cpus_online = 0;
typedef struct seg_desc {
} seg_desc_t;
static int32_t threshold_names[] = {
PSVC_NOT_USED, /* LOW MODE which is not used */
};
/*
* The I2C bus is noisy, and the state may be incorrectly reported as
* having changed. When the state changes, we attempt to confirm by
* retrying. If any retries indicate that the state has not changed, we
* assume the state change(s) were incorrect and the state has not changed.
* The following variables are used to store the tuneable values read in
* from the optional i2cparam.conf file for this shared object library.
*/
static int n_read_temp = PSVC_THRESHOLD_COUNTER;
static int n_retry_keyswitch = PSVC_NUM_OF_RETRIES;
static int retry_sleep_keyswitch = 1;
static int n_retry_hotplug = PSVC_NUM_OF_RETRIES;
static int retry_sleep_hotplug = 1;
static int n_retry_fan_hotplug = PSVC_NUM_OF_RETRIES;
static int retry_sleep_fan_hotplug = 1;
static int n_retry_fan_present = PSVC_NUM_OF_RETRIES;
static int retry_sleep_fan_present = 1;
typedef struct {
int *pvar;
char *texttag;
static i2c_noise_param_t i2cparams_sun4u[] = {
&n_read_temp, "n_read_temp",
&n_retry_keyswitch, "n_retry_keyswitch",
&retry_sleep_keyswitch, "retry_sleep_keyswitch",
&n_retry_hotplug, "n_retry_hotplug",
&retry_sleep_hotplug, "retry_sleep_hotplug",
&n_retry_fan_hotplug, "n_retry_fan_hotplug",
&retry_sleep_fan_hotplug, "retry_sleep_fan_hotplug",
&n_retry_fan_present, "n_retry_fan_present",
&retry_sleep_fan_present, "retry_sleep_fan_present",
};
#pragma init(i2cparams_sun4u_load)
static void
{
char s[128];
if (!usingDefaults) {
(void) strncpy(s,
"# Values from /usr/platform/sun4u/lib/i2cparam.conf\n",
sizeof (s) - 1);
} else {
/* no file - we're using the defaults */
(void) strncpy(s,
"# No /usr/platform/sun4u/lib/i2cparam.conf file, using defaults\n",
sizeof (s) - 1);
}
p = pi2cparams;
*(p->pvar));
if (!usingDefaults)
p++;
}
}
static void
i2cparams_sun4u_load(void)
{
char s[128];
char var[128];
int val;
/* read thru the i2cparam.conf file and set variables */
if (s[0] == '#') /* skip comment lines */
continue;
/* try to find a string match and get the value */
continue;
if (val < 1)
p = &(i2cparams_sun4u[0]);
0) {
break;
}
p++;
}
}
}
/* output the values of the parameters */
}
{
return (status);
PSVC_FRU);
if (status == PSVC_FAILURE)
return (status);
for (i = 0; i < match_count; i++) {
seg_found = 0;
if (status != PSVC_SUCCESS)
return (status);
&fru_data);
if (status != PSVC_SUCCESS) {
return (status);
}
&fru_data);
&fru_data);
if (status != PSVC_SUCCESS) {
"Failed psvc_get_attr for FRU info\n");
return (status);
}
seg_found = 1;
}
if (seg_found) {
&fru_data);
if (status != PSVC_SUCCESS) {
"Failed psvc_get_attr for FRU info\n");
return (status);
} else {
for (j = 0; j < sizeof (temp_array); j++) {
if (threshold_names[j] == PSVC_NOT_USED)
continue;
temp = temp_array[j];
threshold_names[j], &temp);
if (status != PSVC_SUCCESS) {
return (status);
}
}
}
} else {
" using default temperatures\n", id);
}
}
return (status);
}
#define MAX_TEMP_SENSORS 256
static int32_t
{
char previous_state[32];
char led_state[32];
char state[32];
char fault[32];
char label[32];
static int threshold_low_shut[MAX_TEMP_SENSORS] = {0};
static int threshold_high_shut[MAX_TEMP_SENSORS] = {0};
static int threshold_low_warn[MAX_TEMP_SENSORS] = {0};
static int threshold_high_warn[MAX_TEMP_SENSORS] = {0};
if (status != PSVC_SUCCESS)
return (status);
return (status);
}
if (status == PSVC_FAILURE)
return (status);
return (PSVC_SUCCESS);
}
if (status != PSVC_SUCCESS)
return (status);
if (status != PSVC_SUCCESS)
return (status);
if (status != PSVC_SUCCESS)
return (status);
if (status != PSVC_SUCCESS)
return (status);
if (status != PSVC_SUCCESS)
return (status);
if (status != PSVC_SUCCESS) {
return (status);
}
/*
* The following code is to check to see if the temp sensor is
* returning a faulty reading due to it either being bad or the
* CPU being powered off for some reason. Is so we will alert the user
* and just label the sensor bad but not the WHOLE CPU module.
*/
if (status != PSVC_SUCCESS)
return (status);
if (status != PSVC_SUCCESS)
return (status);
return (status);
}
if (status != PSVC_SUCCESS)
return (status);
/*
* if any of the four temperature states (lo_shut, lo_warn,
* hi_shut, hi_warn) is detected we will not take an action
* until the number of similar back-to-back readings equals
* 'n_read_temp' (default is PSVC_THRESHOLD_COUNTER).
*/
/*
* once we are in one state, clear all the
* counters for the other three states since
* back-to-back readings of these other three
* states could not happen anymore.
*/
threshold_low_warn[instance] = 0;
threshold_high_shut[instance] = 0;
threshold_high_warn[instance] = 0;
threshold_low_shut[instance] = 0;
fail = 1;
if (silent == 0)
} else { /* Threshold for showing error not reached */
return (PSVC_SUCCESS);
}
threshold_low_shut[instance] = 0;
threshold_high_shut[instance] = 0;
threshold_high_warn[instance] = 0;
threshold_low_warn[instance] = 0;
fail = 1;
if (silent == 0)
} else { /* Threshold for showing error not reached */
return (PSVC_SUCCESS);
}
threshold_low_warn[instance] = 0;
threshold_low_shut[instance] = 0;
threshold_high_warn[instance] = 0;
threshold_high_shut[instance] = 0;
fail = 1;
if (silent == 0)
} else { /* Threshold for showing error not reached */
return (PSVC_SUCCESS);
}
threshold_low_warn[instance] = 0;
threshold_low_shut[instance] = 0;
threshold_high_shut[instance] = 0;
threshold_high_warn[instance] = 0;
fail = 1;
if (silent == 0)
} else { /* Threshold for showing error not reached */
return (PSVC_SUCCESS);
}
}
/*
* If we reached this point then that means that we are either
* okay, or we have showed error n_read_temp times.
*/
if (fail != 1) {
/* within limits */
}
if (status != PSVC_SUCCESS)
return (status);
if (status != PSVC_SUCCESS)
return (status);
if (status != PSVC_SUCCESS)
return (status);
char *led_id;
int32_t i;
/* change state of fault LEDs */
for (i = 0; i < led_count; ++i) {
PSVC_TS_OVERTEMP_LED, i);
if (status == PSVC_FAILURE)
return (status);
if (status == PSVC_FAILURE)
return (status);
}
}
return (PSVC_SUCCESS);
}
{
}
{
}
{
char *backup_fan;
char label[32];
int retry;
if (status != PSVC_SUCCESS)
return (status);
retry = 0;
do {
if (retry)
(void) sleep(retry_sleep_fan_present);
if (status != PSVC_SUCCESS)
return (status);
retry++;
if (presence == PSVC_ABSENT) {
if (status != PSVC_SUCCESS)
return (status);
if (status != PSVC_SUCCESS)
return (status);
if (features & PSVC_DEV_PRIMARY) {
&backup_fan, PSVC_ALTERNATE, 0);
if (status != PSVC_SUCCESS)
return (status);
&enable);
if (status != PSVC_SUCCESS)
return (status);
if (status != PSVC_SUCCESS)
return (status);
} else {
&enable);
if (status != PSVC_SUCCESS)
return (status);
}
return (PSVC_SUCCESS);
}
/* device was present */
if (status != PSVC_SUCCESS)
return (status);
if (status != PSVC_SUCCESS)
return (status);
if (features & PSVC_DEV_PRIMARY) {
&backup_fan, PSVC_ALTERNATE, 0);
if (status != PSVC_SUCCESS)
return (status);
&enable);
if (status != PSVC_SUCCESS)
return (status);
if (status != PSVC_SUCCESS)
return (status);
}
&enable);
if (status != PSVC_SUCCESS)
return (status);
if (status != PSVC_SUCCESS)
return (status);
}
} else {
label);
if (status != PSVC_SUCCESS)
return (status);
}
}
return (status);
}
/*
* psvc_switch_fan_onoff_policy_0
* Turn a fan on if it is enabled, turn it off if it is disabled.
*/
{
char *switchid;
char state[32];
if (status != PSVC_SUCCESS)
return (status);
if (status != PSVC_SUCCESS)
return (status);
if (enable == PSVC_DISABLED) {
} else {
}
return (status);
}
static int32_t
{
char *sensorid;
int32_t i;
char fault[32];
if (status == PSVC_FAILURE)
return (status);
for (i = 0; i < sensor_count; ++i) {
&sensorid, PSVC_DEV_TEMP_SENSOR, i);
if (status == PSVC_FAILURE)
return (status);
fault);
if (status == PSVC_FAILURE)
return (status);
!(features & PSVC_DEV_HOTPLUG)) {
} else {
/* FIX offline cpu */
--cpus_online;
}
}
}
return (status);
}
{
char *cpuid;
int32_t i;
if (cpus_online == 0) {
/* obviously, zero isn't correct, count present cpu's */
PSVC_CPU);
for (i = 0; i < cpu_count; ++i) {
if (status == PSVC_FAILURE)
return (status);
return (status);
if (present == PSVC_PRESENT)
++cpus_online;
}
}
PSVC_CPU);
for (i = 0; i < cpu_count; ++i) {
PSVC_CPU, i);
if (status == PSVC_FAILURE)
return (status);
return (status);
}
return (PSVC_SUCCESS);
}
/*
* psvc_keyswitch_position_policy_0
* Checks the state of the keyswitch sensors.
* If a keyswitch position sensor's state is on, the position
* of the key is written to syslog. If none of the sensors
* are on (keyswitch is not at one of the detents), a message is sent
* to syslog stating that the position is unknown.
*/
{
char position[32];
static int error_reported = 0;
static char local_previous_position[32];
int retry;
if (first_time) {
first_time = 0;
if (status != PSVC_SUCCESS)
return (status);
}
retry = 0;
do {
if (retry)
(void) sleep(retry_sleep_keyswitch);
position);
if (status != PSVC_SUCCESS)
return (status);
error_reported = 1;
return (PSVC_SUCCESS);
}
}
retry++;
} while ((retry < n_retry_keyswitch) &&
if (status != PSVC_SUCCESS)
return (status);
error_reported = 0;
}
return (status);
}
{
char label[32];
int retry;
if (status != PSVC_SUCCESS)
return (status);
retry = 0;
do {
if (retry)
(void) sleep(retry_sleep_hotplug);
if (status != PSVC_SUCCESS)
return (status);
retry++;
} while ((retry < n_retry_hotplug) &&
(presence != previous_presence));
if (presence != previous_presence) {
char parent_path[256];
if (status != PSVC_SUCCESS)
return (status);
/* return parent path and node for an object */
if (presence == PSVC_PRESENT) {
state);
if (status != PSVC_SUCCESS)
return (status);
fault);
if (status != PSVC_SUCCESS) {
return (status);
}
&parent_node);
if (status != 0)
return (PSVC_FAILURE);
if (status != 0)
return (PSVC_FAILURE);
} else {
}
}
if (status != PSVC_SUCCESS)
return (status);
return (status);
}
{
char label[32];
int retry;
if (status != PSVC_SUCCESS)
return (status);
retry = 0;
do {
if (retry)
(void) sleep(retry_sleep_fan_hotplug);
if (status != PSVC_SUCCESS)
return (status);
retry++;
} while ((retry < n_retry_fan_hotplug) &&
(presence != previous_presence));
if (presence != previous_presence) {
char parent_path[256];
if (status != PSVC_SUCCESS)
return (status);
/* return parent path and node for an object */
if (presence == PSVC_PRESENT) {
char *slot_id;
char *led_id;
char led_state[32];
state);
if (status != PSVC_SUCCESS)
return (status);
fault);
if (status != PSVC_SUCCESS)
return (status);
/* turn off fault LEDs */
for (i = 0; i < led_count; ++i) {
PSVC_DEV_FAULT_LED, i);
if (status == PSVC_FAILURE)
return (status);
if (status == PSVC_FAILURE)
return (status);
}
/* turn off OK to remove LEDs */
&slot_id, PSVC_PARENT, 0);
if (status != PSVC_SUCCESS)
return (status);
for (i = 0; i < led_count; ++i) {
PSVC_SLOT_REMOVE_LED, i);
if (status == PSVC_FAILURE)
return (status);
if (status == PSVC_FAILURE)
return (status);
}
} else {
}
}
if (status != PSVC_SUCCESS)
return (status);
return (status);
}
{
return (status);
}
{
return (status);
}
{
char *sensor_id;
int32_t i;
&present);
if (status == PSVC_FAILURE) {
errno);
return (status);
}
if (present == PSVC_ABSENT) {
return (PSVC_FAILURE);
}
for (i = 0; i < sensor_count; ++i) {
if (status != PSVC_SUCCESS)
return (status);
&hi_warn);
if (status != PSVC_SUCCESS)
return (status);
if (status != PSVC_SUCCESS) {
errno);
return (status);
}
char label[32];
PSVC_LABEL_ATTR, &label);
if (status != PSVC_SUCCESS)
return (status);
}
}
return (PSVC_SUCCESS);
}
{
int i;
char led_state[32];
if (status == PSVC_FAILURE)
return (status);
if (present == PSVC_ABSENT) {
return (PSVC_FAILURE);
}
for (i = 0; i < sensor_count; ++i) {
&sensor_id, PSVC_DEV_FAULT_SENSOR, i);
if (status != PSVC_SUCCESS)
return (status);
if (status != PSVC_SUCCESS)
return (status);
} else {
}
if (status != PSVC_SUCCESS)
return (status);
if (status != PSVC_SUCCESS)
return (status);
if (status != PSVC_SUCCESS)
return (status);
char sensor_label[32];
char dev_label[32];
int32_t j;
} else {
}
for (j = 0; j < led_count; j++) {
PSVC_DEV_FAULT_LED, j);
if (status != PSVC_SUCCESS)
return (status);
if (status != PSVC_SUCCESS) {
return (status);
}
}
}
}
return (PSVC_SUCCESS);
}
static float
{
float error;
float adder;
int i = 0;
adder = last_errors[0];
for (i = 1; i < PSVC_MAXERRORS; i++) {
}
return (error);
}
static int32_t
{
int err = PSVC_SUCCESS;
int i;
char *control_id;
if (control_count == 0)
return (PSVC_SUCCESS);
if (err != PSVC_SUCCESS)
return (err);
/*
* this call will return PSVC_FAILURE on the first pass,
* because no value has been set.
*/
return (PSVC_SUCCESS);
for (i = 0; i < control_count; i++) {
&control_id, PSVC_FAN_DRIVE_CONTROL, i);
if (err != PSVC_SUCCESS)
return (err);
&fan_speed);
if (err == PSVC_FAILURE) {
errno);
return (err);
}
}
return (err);
}
static int32_t
{
int i;
char *sensor_id;
*hot_device = 0;
for (i = 0; i < sensor_count; i++) {
&sensor_id, PSVC_DEV_TEMP_SENSOR, i);
if (err == PSVC_FAILURE)
return (err);
&temp);
if (err == PSVC_FAILURE) {
temp = 0;
} else {
return (err);
}
}
if (*hot_device < temp)
*hot_device = temp;
}
return (PSVC_SUCCESS);
}
{
int current_error; /* Holds current error */
/* Signal before signaling */
float filtered_error; /* Holds the filtered error signal */
int ampout; /* output of loop amplifier */
int hot_device;
/* from the last n iterations */
if (is_enabled == PSVC_DISABLED)
return (PSVC_SUCCESS);
if (err != PSVC_SUCCESS)
return (err);
&hysteresis);
if (err != PSVC_SUCCESS)
return (err);
if (err != PSVC_SUCCESS)
return (err);
if (err != PSVC_SUCCESS)
return (err);
if (err != PSVC_SUCCESS)
return (err);
&error_number);
if (err != PSVC_SUCCESS)
return (err);
if (err != PSVC_SUCCESS) {
printf("psvc_fan_control failure in device_temp_check\n");
return (err);
}
if (ampout < 0)
ampout = 0;
if (ampout > 1023)
ampout = 1023;
if (err != PSVC_SUCCESS)
return (err);
}
if (error_number == PSVC_MAXERRORS)
error_number = 0;
if (err != PSVC_SUCCESS)
return (err);
&error_number);
if (err != PSVC_SUCCESS)
return (err);
return (PSVC_SUCCESS);
}
{
int fd;
int retry;
retry = 0;
do {
if (retry)
(void) sleep(retry_sleep_fan_present);
if (status != PSVC_SUCCESS)
return (status);
retry++;
if (presence == PSVC_ABSENT) {
/*
* We make this open, write, close, call because picld
* starts in rcS.d while print services does not start
* until later (either rc2.d or rc3.d)
*/
if (fd != -1) {
}
}
}
return (status);
}