/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <libipmi.h>
#include <stddef.h>
#include <string.h>
#include <strings.h>
#include <math.h>
#include "ipmi_impl.h"
/*
* This macros are used by ipmi_sdr_conv_reading. They were taken verbatim from
* the source for ipmitool (v1.88)
*/
0xff000000) >> 24) | \
4))
/*
* Analog sensor reading data formats
*
* See Section 43.1
*/
#define IPMI_DATA_FMT_UNSIGNED 0
typedef struct ipmi_sdr_cache_ent {
char *isc_name;
typedef struct ipmi_cmd_get_sdr {
typedef struct ipmi_rsp_get_sdr {
/*
* "Get SDR Repostiory Info" command.
*/
{
return (NULL);
return (sip);
}
/*
* Issue the "Reserve SDR Repository" command.
*/
static int
{
return (-1);
return (0);
}
/*
* Returns B_TRUE if the repository has changed since the cached copy was last
* referenced.
*/
{
return (B_TRUE);
}
/*
* Refresh the cache of sensor data records.
*/
int
{
char *name;
return (-1);
return (0);
/*
* Iterate over all existing SDRs and add them to the cache.
*/
id = IPMI_SDR_FIRST;
while (id != IPMI_SDR_LAST) {
goto error;
/*
* Extract the name from the record-specific data.
*/
{
break;
}
{
break;
}
{
sizeof (tmp));
sizeof (tmp));
sizeof (tmp));
break;
}
{
sizeof (tmp));
sizeof (tmp));
sizeof (tmp));
break;
}
case IPMI_SDR_TYPE_EVENT_ONLY:
{
break;
}
{
break;
}
{
sizeof (tmp));
break;
}
default:
}
sizeof (ipmi_sdr_cache_ent_t))) == NULL) {
goto error;
}
NULL) {
goto error;
}
}
/*
* This should never happen. It means that the SP has returned
* a SDR record twice, with the same name and ID. This has
* been observed on service processors that don't correctly
* return SDR_LAST during iteration, so assume we've looped in
* the SDR and return gracefully.
*/
break;
}
}
return (0);
return (-1);
}
/*
* Hash routines. We allow lookup by name, but since not all entries have
* names, we fall back to the entry pointer, which is guaranteed to be unique.
* The end result is that entities without names cannot be looked up, but will
* show up during iteration.
*/
static const void *
ipmi_sdr_hash_convert(const void *p)
{
return (p);
}
static ulong_t
ipmi_sdr_hash_compute(const void *p)
{
else
return (ipmi_hash_ptrhash(ep));
}
static int
ipmi_sdr_hash_compare(const void *a, const void *b)
{
return (-1);
return (-1);
/*
* While it is strange for a service processor to report multiple
* entries with the same name, we allow it by treating the (name, id)
* as the unique identifier. When looking up by name, the SDR pointer
* is NULL, and we return the first matching name.
*/
return (0);
return (0);
else
return (-1);
}
int
{
ipmi_sdr_hash_compare)) == NULL)
return (-1);
return (0);
}
void
{
}
}
void
{
}
}
{
int i = 0;
char *buf;
/*
* The size of the SDR is contained in the 5th byte of the SDR header,
* so we'll read the first 5 bytes to get the size, so we know how big
* to make the buffer.
*/
req.ic_gs_offset = 0;
for (i = 0; i < ihp->ih_retries; i++) {
break;
return (NULL);
if (ipmi_sdr_reserve_repository(ihp) != 0)
return (NULL);
}
return (NULL);
return (NULL);
}
/*
* Some SDRs can be bigger than the buffer sizes for a given bmc
* interface. Therefore we break up the process of reading in an entire
* SDR into multiple smaller reads.
*/
sdr = (ipmi_sdr_t *)
i = 0;
if (i >= ihp->ih_retries ||
ipmi_sdr_reserve_repository(ihp) != 0) {
return (NULL);
}
i++;
} else {
return (NULL);
}
}
return ((ipmi_sdr_t *)buf);
}
int
const char *, ipmi_sdr_t *, void *), void *data)
{
int ret;
ipmi_sdr_refresh(ihp) != 0)
return (-1);
return (ret);
}
return (0);
}
{
ipmi_sdr_refresh(ihp) != 0)
return (NULL);
return (NULL);
}
}
static void *
{
return (NULL);
return (NULL);
}
}
{
}
{
}
{
}
{
}
/*
* Mostly taken from ipmitool source v1.88
*
* This function converts the raw sensor reading returned by
* ipmi_get_sensor_reading to a unit-based value of type double.
*/
int
double *result)
{
switch (sensor->is_fs_analog_fmt) {
case IPMI_DATA_FMT_UNSIGNED:
break;
case IPMI_DATA_FMT_ONESCOMP:
if (val & 0x80)
val++;
/* FALLTHRU */
case IPMI_DATA_FMT_TWOSCOMP:
break;
default:
/* This sensor does not return a numeric reading */
return (-1);
}
switch (sensor->is_fs_sensor_linear_type) {
case SDR_SENSOR_L_LN:
break;
case SDR_SENSOR_L_LOG10:
break;
case SDR_SENSOR_L_LOG2:
break;
case SDR_SENSOR_L_E:
break;
case SDR_SENSOR_L_EXP10:
break;
case SDR_SENSOR_L_EXP2:
break;
case SDR_SENSOR_L_1_X:
break;
case SDR_SENSOR_L_SQR:
break;
case SDR_SENSOR_L_CUBE:
break;
case SDR_SENSOR_L_SQRT:
break;
case SDR_SENSOR_L_CUBERT:
break;
case SDR_SENSOR_L_LINEAR:
default:
break;
}
return (0);
}