orcm/mca/sensor/nodepower/sensor_nodepower.c
/*
use read_ein command to get input power of PSU. refer to PSU spec for details.
 */
use read_ein command to get input power of PSU. refer to PSU spec for details.
use read_ein command to get input power of PSU . refer to PSU spec for details .
static int call_readein(node_power_data *data, int to_print, unsigned char psu)
{
    unsigned char responseData[MAX_IPMI_RESPONSE];
    int responseLength = MAX_IPMI_RESPONSE;
    unsigned char completionCode;
    int ret, i, len;
    unsigned char netfn, lun;
    unsigned char cmd[16];
    unsigned char temp_value[8];
    char *error_string;
    cmd[0]=(unsigned char)0x00;
    cmd[1]=(unsigned char)0x20;
    cmd[2]=(unsigned char)0x18;
    cmd[3]=(unsigned char)0x52;
    cmd[4]=(unsigned char)0x0f;
    cmd[5]=psu;
    cmd[6]=(unsigned char)0x07;
    cmd[7]=(unsigned char)0x86;
    len=8;
    netfn=cmd[2]>>2;
    lun=cmd[2]&0x03;
    ret = ipmi_cmdraw(cmd[3], netfn, cmd[1], cmd[0], lun, &cmd[4], (unsigned char)(len-4), responseData, &responseLength, &completionCode, 0);
    if(ret) {
        error_string = decode_rv(ret);
        opal_output(0,"ipmi_cmdraw ERROR : %s \n", error_string);
        ipmi_close();
        return ORCM_ERROR;
    }
    if (to_print){
        opal_output(0, "ret=%d, respData[len=%d]: ",ret, responseLength);
        for (i = 0; i < responseLength; i++){
           opal_output(0, "%02x ",responseData[i]);
        }
        opal_output(0, "\n");
    }
    if (completionCode==(unsigned char)0){
        data->str_len=responseLength;
        for (i=0; i<responseLength; i++){
            data->raw_string[i]=responseData[i];
        }
        temp_value[0]=responseData[1];
        temp_value[1]=responseData[2];
        temp_value[1]&=0x7f;
        temp_value[2]=responseData[3];
        if (temp_value[2]&0x1){
            temp_value[1]|=0x80;
        }
        temp_value[2]>>=1;
        data->ret_val[0]=*((unsigned long *)temp_value);
        memset(temp_value, 0, 8);
        temp_value[0]=responseData[4];
        temp_value[1]=responseData[5];
        temp_value[2]=responseData[6];
        data->ret_val[1]=*((unsigned long *)temp_value);
    } else {
        memset(data->raw_string, 0, 7);
        data->ret_val[0]=0;
        data->ret_val[1]=0;
    }
    if (to_print){
        opal_output(0, "ret_val[0]=%lu, ret_val[1]=%lu\n", data->ret_val[0], data->ret_val[1]);
    }
    ipmi_close();
    return ORCM_SUCCESS;
}
static int call_readein ( node_power_data * data , int to_print , unsigned char psu ) { unsigned char responseData [ MAX_IPMI_RESPONSE ] ; int responseLength = MAX_IPMI_RESPONSE ; unsigned char completionCode ; int ret , i , len ; unsigned char netfn , lun ; unsigned char cmd [ 16 ] ; unsigned char temp_value [ 8 ] ; char * error_string ; cmd [ 0 ] = ( unsigned char ) 0x00 ; cmd [ 1 ] = ( unsigned char ) 0x20 ; cmd [ 2 ] = ( unsigned char ) 0x18 ; cmd [ 3 ] = ( unsigned char ) 0x52 ; cmd [ 4 ] = ( unsigned char ) 0x0f ; cmd [ 5 ] = psu ; cmd [ 6 ] = ( unsigned char ) 0x07 ; cmd [ 7 ] = ( unsigned char ) 0x86 ; len = 8 ; netfn = cmd [ 2 ] >> 2 ; lun = cmd [ 2 ] & 0x03 ; ret = ipmi_cmdraw ( cmd [ 3 ] , netfn , cmd [ 1 ] , cmd [ 0 ] , lun , & cmd [ 4 ] , ( unsigned char ) ( len - 4 ) , responseData , & responseLength , & completionCode , 0 ) ; if ( ret ) { error_string = decode_rv ( ret ) ; opal_output ( 0 , " \n " , error_string ) ; ipmi_close ( ) ; return ORCM_ERROR ; } if ( to_print ) { opal_output ( 0 , " " , ret , responseLength ) ; for ( i = 0 ; i < responseLength ; i ++ ) { opal_output ( 0 , " " , responseData [ i ] ) ; } opal_output ( 0 , " \n " ) ; } if ( completionCode == ( unsigned char ) 0 ) { data -> str_len = responseLength ; for ( i = 0 ; i < responseLength ; i ++ ) { data -> raw_string [ i ] = responseData [ i ] ; } temp_value [ 0 ] = responseData [ 1 ] ; temp_value [ 1 ] = responseData [ 2 ] ; temp_value [ 1 ] &= 0x7f ; temp_value [ 2 ] = responseData [ 3 ] ; if ( temp_value [ 2 ] & 0x1 ) { temp_value [ 1 ] |= 0x80 ; } temp_value [ 2 ] >>= 1 ; data -> ret_val [ 0 ] = * ( ( unsigned long * ) temp_value ) ; memset ( temp_value , 0 , 8 ) ; temp_value [ 0 ] = responseData [ 4 ] ; temp_value [ 1 ] = responseData [ 5 ] ; temp_value [ 2 ] = responseData [ 6 ] ; data -> ret_val [ 1 ] = * ( ( unsigned long * ) temp_value ) ; } else { memset ( data -> raw_string , 0 , 7 ) ; data -> ret_val [ 0 ] = 0 ; data -> ret_val [ 1 ] = 0 ; } if ( to_print ) { opal_output ( 0 , " \n " , data -> ret_val [ 0 ] , data -> ret_val [ 1 ] ) ; } ipmi_close ( ) ; return ORCM_SUCCESS ; }
use read_ein command to get input power of PSU.
use read_ein command to get input power of PSU .
/* parameters needed to read psu power */ /* bus # */ /* sa */ /* netfn and lun */ /* command */ /* pointer to ipmi data (4 bytes) */