libctsmc.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* 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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This is utility library that provides APIs to interact with SMC driver
*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <poll.h>
#include <assert.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <stdarg.h>
#include <stropts.h>
#include <syslog.h>
#include "smclib.h"
static int debug_on = 0;
/* Error messages */
#define SMC_ERRMSG_OPEN "SMC open failed, cmd = %x\n"
#define SMC_ERRMSG_WRITE "SMC write failed, cmd = %x\n"
#define SMC_ERRMSG_POLLTIMEOUT "SMC poll timed out, cmd = %x\n"
#define SMC_ERRMSG_POLLFAILED "SMC poll failed, cmd = %x\n"
#define SMC_ERRMSG_POLL_T "SMC poll timed out, dest = %x\n"
#define SMC_ERRMSG_POLL_F "SMC poll failed, dest = %x\n"
#define SMC_ERRMSG_READ "SMC read response failed, cmd = %x\n"
#define SMC_ERRMSG_ERROR "SMC error, cc = %d, msg_id = %x\n"
#define SMC_ERRMSG_SETATTR "SMC setting read attribute failed\n"
#define SMC_ERRMSG_GET_SEQN "SMC error in getting seqn for %x\n"
#define SMC_ERRMSG_IPMI_ERR "SMC IPMI invalid cc:%x, dest = %x\n"
#define SMC_ERRMSG_GET_GEO "SMC get GeoAddr failed\n"
/* Macros */
#define SMC_LOCAL_SEQ_NO 10
#define NORMAL_COMPLETION_CODE 0
#define IPMI_MSG_CHANNEL_0 0x0
#define IPMI_RSP_HDR_LEN 0x8
#define SMC_NETFN_SEQ_OFFSET 5
#define SMC_CMD_OFFSET 6
#define DEFAULT_FD -1
#define DEFAULT_SEQN 128
/*
* IPMI packet header
*/
typedef struct {
/*
* debug printf
*/
static void
{
if (debug_on > 0) {
}
}
/*
* send a local command to SMC
*/
static smc_errno_t
int poll_time)
{
int poll_rc;
/* send the command to SMC */
return (SMC_REQ_FAILURE);
}
if (poll_rc == 0) {
return (SMC_ACK_FAILURE);
} else if (poll_rc == -1) {
return (SMC_ACK_FAILURE);
}
/* read the response from SMC */
return (SMC_ACK_FAILURE);
}
/* check if response is valid */
return (SMC_INVALID_SEQ);
}
return (SMC_FAILURE);
}
return (SMC_SUCCESS);
}
/*
* get_geo_addr -- returns the geographical address of a CPU board
*/
static int
{
return (SMC_FAILURE);
}
SC_MSG_LEN(&req_pkt) = 0;
/* no request data */
SMC_POLL_TIME)) != SMC_SUCCESS) {
return (rc);
}
return (SMC_SUCCESS);
}
/*
* checksum - returns a 2-complement check sum
*/
static uint8_t
{
int i;
}
return (sum);
}
/*
* func to send IPMI messages
*/
static smc_errno_t
int poll_time)
{
char data[SC_MSG_MAX_SIZE], *p;
if (debug_on) {
p = data;
for (i = 0; i < SC_MSG_LEN(req_pkt); i++) {
}
p = data;
}
if (netfn & RESPONSE_MSG) {
}
SC_MSG_LEN(req_pkt))) < 0) {
return (SMC_REQ_FAILURE);
}
return (SMC_ACK_FAILURE);
}
return (SMC_ACK_FAILURE);
}
if (is_response) { /* need not wait for response */
return (SMC_SUCCESS);
}
if (result == 0) {
return (SMC_RSP_TIMEOUT);
} else if (result < 0) {
return (SMC_RSP_ERROR);
}
if (nbytes < 0) {
return (SMC_RSP_ERROR);
}
if (debug_on) {
p = data;
for (i = 0; i < nbytes; i++) {
}
p = data;
}
return (SMC_RSP_ERROR);
}
dbg_print("SMC: Invalid sequence number in"
" IPMI Response (sent %x, received %x)\n",
}
dbg_print("SMC:IPMI response completion "
"error %x, command = %x\n",
}
return (SMC_SUCCESS);
}
/*
* Initializes the IPMI request packet
*/
{
if (msg_data_size > 0) {
(msg_data_buf == NULL)) {
return (SMC_FAILURE);
}
}
/* get the geo addr for first time */
if (geo_addr == 0) {
return (SMC_FAILURE);
}
}
} else {
}
/* copy the header */
sizeof (ipmi_header));
/* copy the msg data into request packet */
return (SMC_SUCCESS);
}
/*
* Initialize a SMC packet
*/
{
if (msg_data_size > SC_SEND_DSIZE) {
return (SMC_FAILURE);
}
/* fill the packet */
return (SMC_SUCCESS);
}
/*
* Sends SMC(local) and IPMI messages
*/
int poll_time)
{
int rc = SMC_SUCCESS;
return (SMC_FAILURE);
}
if (fd < 0) {
return (SMC_FAILURE);
}
}
if (close_fd)
return (SMC_FAILURE);
}
if (close_fd) {
}
return (rc);
}
/* This is an IPMI message */
if (close_fd) {
}
return (SMC_FAILURE);
}
/* check if sequence num is valid or not */
smc_seq.seq_numbers[0] = 0;
if (close_fd) {
}
return (SMC_FAILURE);
}
}
if (free_seqn) { /* free seqn if library reserved it */
dbg_print("SMC:Error in releasing sequence "
"number\n");
rc = SMC_FAILURE;
}
}
if (close_fd) {
}
return (rc);
}