Esempio n. 1
0
int
onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info)
{
    int  lid, value;
		
    VALIDATE(id);
	
    lid = ONLP_OID_ID_GET(id);

    /* Set the onlp_oid_hdr_t and capabilities */
    *info = linfo[ONLP_OID_ID_GET(id)];

    /* Get LED mode */
    if (onlp_file_read_int(&value, LED_FORMAT, leds[lid]) < 0) {
        DEBUG_PRINT("Unable to read status from file "LED_FORMAT, leds[lid]);
        return ONLP_STATUS_E_INTERNAL;
    }

    info->mode = driver_to_onlp_led_mode(lid, value);

    /* Set the on/off status */
    if (info->mode != ONLP_LED_MODE_OFF) {
        info->status |= ONLP_LED_STATUS_ON;
    }

    return ONLP_STATUS_OK;
}
Esempio n. 2
0
int
onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info)
{
    int  local_id;
	char data[2] = {0};
    char fullpath[50] = {0};
		
    VALIDATE(id);
	
    local_id = ONLP_OID_ID_GET(id);
    		
    /* get fullpath */
    sprintf(fullpath, "%s%s/%s", prefix_path, last_path[local_id], filename);
		
	/* Set the onlp_oid_hdr_t and capabilities */
    *info = linfo[ONLP_OID_ID_GET(id)];

    /* Set LED mode */
    if (onlp_file_read_string(fullpath, data, sizeof(data), 0) != 0) {
        DEBUG_PRINT("%s(%d)\r\n", __FUNCTION__, __LINE__);
        return ONLP_STATUS_E_INTERNAL;
    }

    info->mode = driver_to_onlp_led_mode(local_id, atoi(data));

    /* Set the on/off status */
    if (info->mode != ONLP_LED_MODE_OFF) {
        info->status |= ONLP_LED_STATUS_ON;
    }

    return ONLP_STATUS_OK;
}
Esempio n. 3
0
int
onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* info)
{
    VALIDATE(id);

    *info = finfo[ONLP_OID_ID_GET(id)]; /* Set the onlp_oid_hdr_t */
    ONLP_OID_TABLE_CLEAR(info->hdr.coids);

    if (ONLP_OID_ID_GET(id) == FAN_ID_CHASSIS) {
        return chassis_fan_get_info(info);
    }
    else {
        int psu_id = ONLP_OID_ID_GET(id)-1;
        as5610_52x_psu_type_t psu_type = as5610_52x_get_psu_type(psu_id, NULL, 0);

        switch (psu_type) {
            case PSU_TYPE_AC_F2B:
                return psu_cpr_4011_f2b_fan_info_get(info);
            case PSU_TYPE_AC_B2F:
                return psu_cpr_4011_b2f_fan_info_get(info);
            case PSU_TYPE_DC_48V_F2B:
                return psu_um400d_f2b_fan_info_get(info);
            case PSU_TYPE_DC_48V_B2F:
                return psu_um400d_b2f_fan_info_get(info);
            default:
                break;
        }
    }

    return ONLP_STATUS_E_UNSUPPORTED;
}
Esempio n. 4
0
int
onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info)
{
    int  len, local_id = 0;
    uint8_t data[driver_value_len] = {0};

    VALIDATE(id);

    local_id = ONLP_OID_ID_GET(id);

    /* Set the onlp_oid_hdr_t and capabilities */
    *info = linfo[ONLP_OID_ID_GET(id)];

    /* Get LED mode */
    if (onlp_file_read(data, sizeof(data), &len, "%s%s",
    		prefix_path, file_names[local_id]) != 0) {
        return ONLP_STATUS_E_INTERNAL;
    }

    info->mode = driver_to_onlp_led_mode(local_id, (char*)data);

    /* Set the on/off status */
    if (info->mode != ONLP_LED_MODE_OFF) {
        info->status |= ONLP_LED_STATUS_ON;
    }

    return ONLP_STATUS_OK;
}
Esempio n. 5
0
int
onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* rv)
{
    *rv = fans__[ONLP_OID_ID_GET(id)];
    rv->caps |= ONLP_FAN_CAPS_GET_RPM;

    int len;
    char direction[16] = {0};

    int fid = ONLP_OID_ID_GET(id);

    /* Read the current airflow direction */
    onlp_file_read((uint8_t*)direction, sizeof(direction), &len,
                   SYS_HWMON_PREFIX "/fan_dir");

#define FAN_DIR_F2B "front-to-back"
#define FAN_DIR_B2F "back-to-front"

    if(!strncmp(direction, FAN_DIR_F2B, strlen(FAN_DIR_F2B))) {
        rv->status |= ONLP_FAN_STATUS_F2B;
        rv->caps |= ONLP_FAN_CAPS_F2B;
    }
    else if(!strncmp(direction, FAN_DIR_B2F, strlen(FAN_DIR_B2F))) {
        rv->status |= ONLP_FAN_STATUS_B2F;
        rv->caps |= ONLP_FAN_CAPS_B2F;
    }
    else {
        AIM_LOG_WARN("Invalid fan direction: '%s'", direction);
    }


    switch(fid)
        {
        case FAN_ID_FAN1:
        case FAN_ID_FAN2:
        case FAN_ID_FAN3:
        case FAN_ID_FAN4:
            {
                if(rv->status & ONLP_FAN_STATUS_F2B) {
                    return sys_fan_info_get__(rv, fid);
                }
                if(rv->status & ONLP_FAN_STATUS_B2F) {
                    return sys_fan_info_get__(rv, fid+4);
                }
                return ONLP_STATUS_E_INTERNAL;
            }

        case FAN_ID_FAN5:
        case FAN_ID_FAN6:
            {
                return psu_fan_info_get__(rv, fid);
            }
        }

    return ONLP_STATUS_E_INVALID;
}
static int
onlp_snmp_sensor_register_oid__(onlp_oid_t oid, void* cookie)
{
    onlp_oid_hdr_t hdr;
    onlp_snmp_sensor_t s;

    onlp_oid_hdr_get(oid, &hdr);

    AIM_MEMSET(&s, 0x0, sizeof(onlp_snmp_sensor_t));
    switch(ONLP_OID_TYPE_GET(oid))
        {
        case ONLP_OID_TYPE_THERMAL:
#if ONLP_SNMP_CONFIG_INCLUDE_THERMALS == 1
            s.sensor_id = oid;
            sprintf(s.name, "%d - ", ONLP_OID_ID_GET(oid));
            aim_strlcpy(s.desc, hdr.description, sizeof(s.desc));
            if(onlp_snmp_sensor_reg__(ONLP_SNMP_SENSOR_TYPE_TEMP, &s) < 0) {
                AIM_LOG_ERROR("onlp_snmp_sensor_reg for OID 0x%x failed.", oid);
            }
#endif
            break;

        case ONLP_OID_TYPE_FAN:
#if ONLP_SNMP_CONFIG_INCLUDE_FANS == 1
            s.sensor_id = oid;
            sprintf(s.name, "%d - ", ONLP_OID_ID_GET(oid));
            aim_strlcpy(s.desc, hdr.description, sizeof(s.desc));
            if(onlp_snmp_sensor_reg__(ONLP_SNMP_SENSOR_TYPE_FAN, &s) < 0) {
                AIM_LOG_ERROR("onlp_snmp_sensor_reg for OID 0x%x failed.", oid);
            }
#endif
            break;

        case ONLP_OID_TYPE_PSU:
#if ONLP_SNMP_CONFIG_INCLUDE_PSUS == 1
            /* Register Sensors for VIN,VOUT,IIN,IOUT,PIN,POUT */
            s.sensor_id = oid;
            sprintf(s.name, "%d - ", ONLP_OID_ID_GET(oid));
            aim_strlcpy(s.desc, hdr.description, sizeof(s.desc));
            if(onlp_snmp_sensor_reg__(ONLP_SNMP_SENSOR_TYPE_PSU, &s) < 0) {
                AIM_LOG_ERROR("onlp_snmp_sensor_reg for OID 0x%x failed.", oid);
            }
#endif
            break;

        default:
            AIM_LOG_INFO("snmp type %s id %d unsupported",
                         onlp_oid_type_name(ONLP_OID_TYPE_GET(oid)),
                         ONLP_OID_ID_GET(oid));
            break;
    }

    return 0;
}
Esempio n. 7
0
int
onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* info)
{
    int rc = 0;
    int local_id;
    VALIDATE(id);

    local_id = ONLP_OID_ID_GET(id);
    *info = linfo[local_id];

    switch (local_id)
    {
	    case FAN_1_ON_PSU1:
        case FAN_1_ON_PSU2:
            rc = _onlp_fani_info_get_fan_on_psu(local_id, info);
            break;
        case FAN_1_ON_MAIN_BOARD:
        case FAN_2_ON_MAIN_BOARD:
        case FAN_3_ON_MAIN_BOARD:
        case FAN_4_ON_MAIN_BOARD:
        case FAN_5_ON_MAIN_BOARD:
            rc =_onlp_fani_info_get_fan(local_id, info);
            break;
        default:
            rc = ONLP_STATUS_E_INVALID;
            break;
    }

    return rc;
}
Esempio n. 8
0
int
onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info)
{
    int val   = 0;
    int ret   = ONLP_STATUS_OK;
    int index = ONLP_OID_ID_GET(id);
    psu_type_t psu_type; 

    VALIDATE(id);

    memset(info, 0, sizeof(onlp_psu_info_t));
    *info = pinfo[index]; /* Set the onlp_oid_hdr_t */

    if (onlp_file_read_int(&val, PSU_PRESENT_FORMAT, index) < 0) {
        AIM_LOG_ERROR("Unable to read present status from PSU(%d)\r\n", index);
        return ONLP_STATUS_E_INTERNAL;
    }

    if (val != PSU_STATUS_PRESENT) {
        info->status &= ~ONLP_PSU_STATUS_PRESENT;
        return ONLP_STATUS_OK;
    }
    info->status |= ONLP_PSU_STATUS_PRESENT;


    /* Get power good status */
    if (onlp_file_read_int(&val, PSU_POWERGOOD_FORMAT, index) < 0) {
        AIM_LOG_ERROR("Unable to read power status from PSU(%d)\r\n", index);
        return ONLP_STATUS_E_INTERNAL;
    }

    if (val != PSU_STATUS_POWER_GOOD) {
        info->status |=  ONLP_PSU_STATUS_FAILED;
    }


    /* Get PSU type
     */
    psu_type = psu_type_get(index, info->model, sizeof(info->model));
    switch (psu_type) {
        case PSU_TYPE_AC_DPS850_F2B:
        case PSU_TYPE_AC_DPS850_B2F:
            ret = psu_dps850_info_get(info);      
            break;
        case PSU_TYPE_AC_YM2851_F2B:
        case PSU_TYPE_AC_YM2851_B2F:
            ret = psu_ym2651y_info_get(info);
            break;
        case PSU_TYPE_UNKNOWN:  /* User insert a unknown PSU or unplugged.*/
            info->status |= ONLP_PSU_STATUS_UNPLUGGED;
            info->status &= ~ONLP_PSU_STATUS_FAILED;
            ret = ONLP_STATUS_OK;
            break;
        default:
            ret = ONLP_STATUS_E_UNSUPPORTED;
            break;
    }

    return ret;
}
Esempio n. 9
0
/*
 * Retrieve the information structure for the given thermal OID.
 *
 * If the OID is invalid, return ONLP_E_STATUS_INVALID.
 * If an unexpected error occurs, return ONLP_E_STATUS_INTERNAL.
 * Otherwise, return ONLP_STATUS_OK with the OID's information.
 *
 * Note -- it is expected that you fill out the information
 * structure even if the sensor described by the OID is not present.
 */
int
onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info)
{
    int tid;

    VALIDATE(id);

    memset(info, 0, sizeof(onlp_thermal_info_t));
    tid = ONLP_OID_ID_GET(id);
    *info = temps__[tid];

    switch(tid)
    {
        case THERMAL_ID_THERMAL1:
        case THERMAL_ID_THERMAL2:
        case THERMAL_ID_THERMAL3:
            return sys_thermal_info_get__(info, tid);

        case THERMAL_ID_THERMAL4:
        case THERMAL_ID_THERMAL5:
            return psu1_thermal_info_get__(info, (tid - THERMAL_ID_THERMAL4 + 1));

        case THERMAL_ID_THERMAL6:
        case THERMAL_ID_THERMAL7:
            return psu2_thermal_info_get__(info, (tid - THERMAL_ID_THERMAL6 + 1));
    }

    return ONLP_STATUS_E_INVALID;
}
Esempio n. 10
0
static int
psu_um400d_fan_info_get(onlp_fan_info_t* info)
{
    unsigned char cpld_offset, data;

    info->mode       = ONLP_FAN_MODE_INVALID; /* Set current mode */
    info->rpm        = 0; /* Set rpm as 0 since the fan controller does not support rpm reading */
    info->percentage = 0;

    /* Get operating status
     */
    if (FAN_ID_PSU1 == ONLP_OID_ID_GET(info->hdr.id)) {
        cpld_offset = CPLD_REG_PSU1_STATUS;
    }
    else { /* FAN_ID_PSU2 */
        cpld_offset = CPLD_REG_PSU2_STATUS;
    }

    data = cpld_base__[cpld_offset];

    if (!(data & CPLD_PSU_FAN_FAILURE_MASK)) {
        info->status |= ONLP_FAN_STATUS_FAILED;
    }

    return ONLP_STATUS_OK;
}
Esempio n. 11
0
/**
 * @brief Get the PSU's operational status.
 * @param id The PSU OID.
 * @param rv [out] Receives the operational status.
 */
int onlp_psui_status_get(onlp_oid_t id, uint32_t* rv)
{
    int result = ONLP_STATUS_OK;
    hwmon_psu_state_t psu_state;
    int local_id;
    VALIDATE(id);
    int len;
    char buf[ONLP_CONFIG_INFO_STR_MAX];

    local_id = ONLP_OID_ID_GET(id);
    if(local_id >= ONLP_PSU_MAX) {
        result = ONLP_STATUS_E_INVALID;
    } else {
        result = onlp_file_read((uint8_t*)&buf, ONLP_CONFIG_INFO_STR_MAX, &len, "%s""psu%d", INV_HWMON_PREFIX, local_id);
        if( result != ONLP_STATUS_OK ) {return result;}
        psu_state = (uint8_t)strtoul(buf, NULL, 0);
        if( psu_state == HWMON_PSU_UNPOWERED) {
            *rv = ONLP_PSU_STATUS_PRESENT|ONLP_PSU_STATUS_UNPLUGGED;
        } else if ( psu_state == HWMON_PSU_NORMAL) {
            *rv = ONLP_PSU_STATUS_PRESENT;
        } else if( psu_state == HWMON_PSU_FAULT) {
            *rv = ONLP_PSU_STATUS_PRESENT|ONLP_PSU_STATUS_FAILED;
        } else if( psu_state == HWMON_PSU_NOT_INSTALLED) {
            *rv = 0;
        } else {
            result = ONLP_STATUS_E_INVALID;
        }
    }
    return result;
}
Esempio n. 12
0
static int
_psu_info_get(onlp_psu_info_t* info)
{
    int val   = 0;
    int index = ONLP_OID_ID_GET(info->hdr.id);

    /* Set capability */
    info->caps = ONLP_PSU_CAPS_AC;

    if (info->status & ONLP_PSU_STATUS_FAILED) {
        return ONLP_STATUS_OK;
    }

    /* Read voltage, current and power */
	if (psu_power_info_get(index, "volt", &val) == 0) {
		info->mvout = val;
		info->caps |= ONLP_PSU_CAPS_VOUT;
	}

	if (psu_power_info_get(index, "curr", &val) == 0) {
		info->miout = val;
		info->caps |= ONLP_PSU_CAPS_IOUT;
	}

	info->mpout = info->mvout * info->miout;
	info->caps |= ONLP_PSU_CAPS_POUT;

	info->mpin = ((int)(info->mpout / 91)) * 100;
	info->caps |= ONLP_PSU_CAPS_PIN;

    return ONLP_STATUS_OK;
}
Esempio n. 13
0
int
onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info)
{
    int val   = 0;
    int ret   = ONLP_STATUS_OK;
    int index = ONLP_OID_ID_GET(id);
    const char psu_model[]=PSU_MODEL;

    VALIDATE(id);

    memset(info, 0, sizeof(onlp_psu_info_t));
    *info = pinfo[index]; /* Set the onlp_oid_hdr_t */

    /* Fixed system, PSU is always present */
	info->status |= ONLP_PSU_STATUS_PRESENT;

	strncpy(info->model, psu_model, sizeof(info->model));

    /* Get the cable preset state */
    if (psu_module_info_get(index, "pwr_status", &val) != 0) {
        AIM_LOG_ERROR("Unable to read PSU(%d) node(cable_present)\r\n", index);
    }

    if (val != PSU_CABLE_PRESENT) {
        info->status |= ONLP_PSU_STATUS_UNPLUGGED;
        return ONLP_STATUS_OK;
    }

    info->status |= ONLP_PSU_STATUS_PRESENT;

    ret = _psu_info_get(info);

    return ret;
}
Esempio n. 14
0
/*
 * Retrieve the information structure for the given thermal OID.
 *
 * If the OID is invalid, return ONLP_E_STATUS_INVALID.
 * If an unexpected error occurs, return ONLP_E_STATUS_INTERNAL.
 * Otherwise, return ONLP_STATUS_OK with the OID's information.
 *
 * Note -- it is expected that you fill out the information
 * structure even if the sensor described by the OID is not present.
 */
int
onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info)
{
    int   fd, len, nbytes = 10, temp_base=1, local_id;
    char  r_data[10]   = {0};
    char  fullpath[50] = {0};
    VALIDATE(id);
	
    local_id = ONLP_OID_ID_GET(id);
	
    /* Set the onlp_oid_hdr_t and capabilities */		
    *info = linfo[local_id];

    if(local_id == THERMAL_CPU_CORE) {
        int rv = onlp_file_read_int_max(&info->mcelsius, cpu_coretemp_files);
        return rv;
    }	
	
    /* get fullpath */
    sprintf(fullpath, "%s%s", prefix_path, last_path[local_id]);

    OPEN_READ_FILE(fd, fullpath, r_data, nbytes, len);
    info->mcelsius = atoi(r_data) / temp_base;	
    DEBUG_PRINT("\n[Debug][%s][%d][save data: %d]\n", __FUNCTION__, __LINE__, info->mcelsius);

    return ONLP_STATUS_OK;								
}
Esempio n. 15
0
File: led.c Progetto: bigswitch/ONLP
void
onlp_led_show(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags)
{
    int rv;
    iof_t iof;
    onlp_led_info_t info;

    VALIDATENR(id);
    onlp_oid_show_iof_init_default(&iof, pvs);
    iof_push(&iof, "LED %d", ONLP_OID_ID_GET(id));
    rv = onlp_led_info_get(id, &info);
    if(rv < 0) {
        onlp_oid_info_get_error(&iof, rv);
    }
    else {
        onlp_oid_show_description(&iof, &info.hdr);
        if(info.status & 1) {
            /* Present */
            iof_iprintf(&iof, "Mode: %{onlp_led_mode}", info.mode);
        }
        else {
            onlp_oid_show_state_missing(&iof);
        }
    }
    iof_pop(&iof);

}
Esempio n. 16
0
static int
onlp_fan_info_get_locked__(onlp_oid_t oid, onlp_fan_info_t* fip)
{
    int rv;

    VALIDATE(oid);

    /* Get the information struct from the platform */
    rv = onlp_fani_info_get(oid, fip);

    if(rv >= 0) {

#if ONLP_CONFIG_INCLUDE_PLATFORM_OVERRIDES == 1
        /*
         * Optional override from the config file.
         * This is usually just for testing.
         */
        int id = ONLP_OID_ID_GET(oid);
        cJSON* entry = NULL;


        cjson_util_lookup(onlp_json_get(0), &entry, "overrides.fan.%d", id);
        onlp_fani_info_from_json__(entry, fip, 0);
#endif

        if(fip->percentage && fip->rpm == 0) {
            /* Approximate RPM based on a 10,000 RPM Maximum */
            fip->rpm = fip->percentage * 100;
        }
    }

    return rv;
}
Esempio n. 17
0
File: led.c Progetto: bigswitch/ONLP
void
onlp_led_dump(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags)
{
    int rv;
    iof_t iof;
    onlp_led_info_t info;

    VALIDATENR(id);
    onlp_oid_dump_iof_init_default(&iof, pvs);
    iof_push(&iof, "led @ %d", ONLP_OID_ID_GET(id));
    rv = onlp_led_info_get(id, &info);
    if(rv < 0) {
        onlp_oid_info_get_error(&iof, rv);
    }
    else {
        onlp_oid_show_description(&iof, &info.hdr);
        if(info.status & 1) {
            /* Present */
            iof_iprintf(&iof, "Status: %{onlp_led_status_flags}", info.status);
            iof_iprintf(&iof, "Caps:   %{onlp_led_caps_flags}", info.caps);
            iof_iprintf(&iof, "Mode: %{onlp_led_mode}", info.mode);
        }
        else {
            iof_iprintf(&iof, "Not present.");
        }
    }
    iof_pop(&iof);
}
Esempio n. 18
0
int
onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* rv)
{
    int fan_id ,rc;
    
    fan_id = ONLP_OID_ID_GET(id);
    *rv = fan_info[fan_id];
    rv->caps |= ONLP_FAN_CAPS_GET_RPM;
       
    switch (fan_id) {
        case FAN_ID_FAN1:
        case FAN_ID_FAN2:
        case FAN_ID_FAN3:
        case FAN_ID_FAN4:
        case FAN_ID_FAN5:
        case FAN_ID_FAN6:
        case FAN_ID_FAN7:
        case FAN_ID_FAN8:
            rc = sys_fan_info_get(rv, fan_id);
            break;
        case FAN_ID_PSU_FAN1:
        case FAN_ID_PSU_FAN2:
            rc = psu_fan_info_get(rv, fan_id);
            break;
        default:            
            return ONLP_STATUS_E_INTERNAL;
            break;
    }

    return rc;
}
Esempio n. 19
0
void
onlp_fan_dump(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags)
{
    int rv;
    iof_t iof;
    onlp_fan_info_t info;

    VALIDATENR(id);

    onlp_oid_dump_iof_init_default(&iof, pvs);
    iof_push(&iof, "fan @ %d", ONLP_OID_ID_GET(id));
    rv = onlp_fan_info_get(id, &info);
    if(rv < 0) {
        onlp_oid_info_get_error(&iof, rv);
    }
    else {
        onlp_oid_show_description(&iof, &info.hdr);
        if(info.status & 1) {
            /* Present */
            iof_iprintf(&iof, "Status: %{onlp_fan_status_flags}", info.status);
            iof_iprintf(&iof, "Caps:   %{onlp_fan_caps_flags}", info.caps);
            iof_iprintf(&iof, "RPM:    %d", info.rpm);
            iof_iprintf(&iof, "Per:    %d", info.percentage);
            iof_iprintf(&iof, "Model:  %s", info.model[0] ? info.model : "NULL");
            iof_iprintf(&iof, "SN:     %s", info.serial[0] ? info.serial : "NULL");
        }
        else {
            iof_iprintf(&iof, "Not present.");
        }
    }
    iof_pop(&iof);
}
Esempio n. 20
0
int
onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* info)
{
    int rc = 0;
    int local_id;

    VALIDATE(id);
	
    local_id = ONLP_OID_ID_GET(id);
    
    *info = linfo[local_id];
	
    if (LOCAL_DEBUG)
        printf("\n[Debug][%s][%d][local_id: %d]", __FUNCTION__, __LINE__, local_id);
		
    switch (local_id)
    {
	    case FAN_1_ON_PSU1:
        case FAN_1_ON_PSU2:
            rc = _onlp_fani_info_get_fan_on_psu(local_id, info);						
            break;

        default:
            rc =_onlp_fani_info_get_fan(local_id, info);						
            break;
    }	
    
    return rc;
}
Esempio n. 21
0
/*
 * Retrieve the information structure for the given thermal OID.
 *
 * If the OID is invalid, return ONLP_E_STATUS_INVALID.
 * If an unexpected error occurs, return ONLP_E_STATUS_INTERNAL.
 * Otherwise, return ONLP_STATUS_OK with the OID's information.
 *
 * Note -- it is expected that you fill out the information
 * structure even if the sensor described by the OID is not present.
 */
int
onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info)
{
    uint8_t local_id    = 0;
    UINT4 multiplier    = 1000;
    UINT4 u4Data        = 0;
    char device_buf[20] = {0};
    int rv;

    VALIDATE(id);
    local_id    = ONLP_OID_ID_GET(id);
    *info       = linfo[ONLP_OID_ID_GET(id)]; 
    if(local_id == THERMAL_CPU_CORE) {
        rv = onlp_file_read_int_max(&info->mcelsius, cpu_coretemp_files);
        return rv;
    }
    switch(local_id)
    {
        case THERMAL_1_ON_CPU_BOARD:
        case THERMAL_2_ON_FAN_BOARD:
        case THERMAL_3_ON_MAIN_BOARD:
        case THERMAL_4_ON_MAIN_BOARD:
        case THERMAL_5_ON_MAIN_BOARD:
            sprintf(device_buf, "Sensor_Temp_%d", local_id-1);
            rv = dni_get_bmc_data(device_buf, &u4Data, multiplier);
            break;
        case THERMAL_6_ON_PSU1:
            sprintf(device_buf, "PSU1_Temp_1");
            rv = dni_get_bmc_data(device_buf, &u4Data, multiplier);
            break;
        case THERMAL_7_ON_PSU2:
            sprintf(device_buf, "PSU2_Temp_1");
            rv = dni_get_bmc_data(device_buf, &u4Data, multiplier);
            break;
        default:
            AIM_LOG_ERROR("Invalid Thermal ID!!\n");
            return ONLP_STATUS_E_PARAM;
    }

    if (u4Data == 0 || rv == ONLP_STATUS_E_GENERIC){
        return ONLP_STATUS_E_INTERNAL;
    }
    else{
        info->mcelsius = u4Data;
        return 0;
    }
}
Esempio n. 22
0
int
onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info)
{
    int  fd, len, nbytes=1, local_id;
    char data[2] = {0};
    char fullpath[50] = {0};

    VALIDATE(id);

    local_id = ONLP_OID_ID_GET(id);

    /* get fullpath */
    if (strchr(last_path[local_id], '/') != NULL) {
        sprintf(fullpath, "%s%s", prefix_path, last_path[local_id]);
    }
    else {
        sprintf(fullpath, "%s%s/%s", prefix_path, last_path[local_id], filename);
    }

    /* Set the onlp_oid_hdr_t and capabilities */
    *info = linfo[ONLP_OID_ID_GET(id)];

    /* Set current mode */
    if ((fd = open(fullpath, O_RDONLY)) == -1) {
        return ONLP_STATUS_E_INTERNAL;
    }

    if ((len = read(fd, data, nbytes)) <= 0) {
        close(fd);
        return ONLP_STATUS_E_INTERNAL;
    }

    /* If the read byte count is less, the format is different and calc will be wrong*/
    if (close(fd) == -1) {
	    return ONLP_STATUS_E_INTERNAL;
    }

    info->mode = conver_led_light_mode_to_onl(atoi(data));

    /* Set the on/off status */
    if (info->mode != ONLP_LED_MODE_OFF) {
        info->status |= ONLP_LED_STATUS_ON;
    }

    return ONLP_STATUS_OK;
}
Esempio n. 23
0
int
onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* rv)
{
    int tid = ONLP_OID_ID_GET(id);

    static onlp_thermal_info_t info[] = {
        { }, /* Not used */
        { { ONLP_THERMAL_ID_CREATE(1),  "Chassis Thermal 1", 0}, ONLP_THERMAL_STATUS_PRESENT,
            ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS
        },
        { { ONLP_THERMAL_ID_CREATE(2),  "Chassis Thermal 2", 0}, ONLP_THERMAL_STATUS_PRESENT,
            ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS
        },
        { { ONLP_THERMAL_ID_CREATE(3),  "Chassis Thermal 3", 0}, ONLP_THERMAL_STATUS_PRESENT,
            ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS
        },
        { { ONLP_THERMAL_ID_CREATE(4),  "Chassis Thermal 4", 0}, ONLP_THERMAL_STATUS_PRESENT,
            ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS
        },
        { { ONLP_THERMAL_ID_CREATE(5),  "Chassis Thermal 5", 0}, ONLP_THERMAL_STATUS_PRESENT,
            ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS
        },
        { { ONLP_THERMAL_ID_CREATE(6),  "PSU-1 Thermal 1", 0 } },
        { { ONLP_THERMAL_ID_CREATE(7),  "PSU-1 Thermal 2", 0 } },
        { { ONLP_THERMAL_ID_CREATE(8),  "PSU-1 Thermal 3", 0 } },

        { { ONLP_THERMAL_ID_CREATE(9),  "PSU-2 Thermal 1", 0 } },
        { { ONLP_THERMAL_ID_CREATE(10), "PSU-2 Thermal 2", 0 } },
        { { ONLP_THERMAL_ID_CREATE(11), "PSU-2 Thermal 3", 0 } },
    };

    *rv = info[tid];
    rv->caps |= ONLP_THERMAL_CAPS_GET_TEMPERATURE;

    switch(tid)
        {
        case THERMAL_ID_THERMAL1:
        case THERMAL_ID_THERMAL2:
        case THERMAL_ID_THERMAL3:
        case THERMAL_ID_THERMAL4:
        case THERMAL_ID_THERMAL5:
            return sys_thermal_info_get__(rv, tid);

        case THERMAL_ID_THERMAL6:
        case THERMAL_ID_THERMAL7:
        case THERMAL_ID_THERMAL8:
            return psu_thermal_info_get__(rv, 1, tid-5);


        case THERMAL_ID_THERMAL9:
        case THERMAL_ID_THERMAL10:
        case THERMAL_ID_THERMAL11:
            return psu_thermal_info_get__(rv, 2, tid-8);

        }

    return ONLP_STATUS_E_INVALID;
}
Esempio n. 24
0
void
onlp_led_show(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags)
{
    int rv;
    iof_t iof;
    onlp_led_info_t info;
    int yaml;

    VALIDATENR(id);
    onlp_oid_show_iof_init_default(&iof, pvs, flags);

    yaml = flags & ONLP_OID_SHOW_F_YAML;

    if(yaml) {
        iof_push(&iof, " -");
        iof_iprintf(&iof, "Name: LED %d", ONLP_OID_ID_GET(id));
    }
    else {
        iof_push(&iof, "LED %d", ONLP_OID_ID_GET(id));
    }

    rv = onlp_led_info_get(id, &info);
    if(rv < 0) {
        if(yaml) {
            iof_iprintf(&iof, "State: Error");
            iof_iprintf(&iof, "Error: %{onlp_status}", rv);
        }
        else {
            onlp_oid_info_get_error(&iof, rv);
        }
    }
    else {
        onlp_oid_show_description(&iof, &info.hdr);
        if(info.status & 1) {
            /* Present */
            iof_iprintf(&iof, "State: Present");
            iof_iprintf(&iof, "Mode: %{onlp_led_mode}", info.mode);
        }
        else {
            onlp_oid_show_state_missing(&iof);
        }
    }
    iof_pop(&iof);

}
Esempio n. 25
0
/*
 * This function sets the fan speed of the given OID as a percentage.
 *
 * This will only be called if the OID has the PERCENTAGE_SET
 * capability.
 *
 * It is optional if you have no fans at all with this feature.
 */
int
onlp_fani_percentage_set(onlp_oid_t id, int p)
{
    VALIDATE(id);

    if (ONLP_OID_ID_GET(id) == FAN_ID_CHASSIS) {
        return onlp_chassis_fan_percentage_set(p);
    }
    else if ((ONLP_OID_ID_GET(id) == FAN_ID_PSU1) || (ONLP_OID_ID_GET(id) == FAN_ID_PSU2)) {
        as5610_52x_psu_type_t psu_type = as5610_52x_get_psu_type(ONLP_OID_ID_GET(id), NULL, 0);

        if (PSU_TYPE_AC_F2B == psu_type || PSU_TYPE_AC_B2F == psu_type) {
            return onlp_psu_cpr_4011_fan_percentage_set(id, p);
        }
    }

    return ONLP_STATUS_E_UNSUPPORTED;
}
Esempio n. 26
0
int
onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info)
{
    int val   = 0;
    int ret   = ONLP_STATUS_OK;
    int index = ONLP_OID_ID_GET(id);
    psu_type_t psu_type; 

    VALIDATE(id);

    memset(info, 0, sizeof(onlp_psu_info_t));
    *info = pinfo[index]; /* Set the onlp_oid_hdr_t */

    /* Get the present state */
    if (psu_status_info_get(index, "psu_present", &val) != 0) {
        printf("Unable to read PSU(%d) node(psu_present)\r\n", index);
    }

    if (val != PSU_STATUS_PRESENT) {
        info->status &= ~ONLP_PSU_STATUS_PRESENT;
        return ONLP_STATUS_OK;
    }
    info->status |= ONLP_PSU_STATUS_PRESENT;


    /* Get power good status */
    if (psu_status_info_get(index, "psu_power_good", &val) != 0) {
        printf("Unable to read PSU(%d) node(psu_power_good)\r\n", index);
    }

    if (val != PSU_STATUS_POWER_GOOD) {
		info->status |= ONLP_PSU_STATUS_UNPLUGGED;
		return ONLP_STATUS_OK;
    }


    /* Get PSU type
     */
    psu_type = get_psu_type(index, info->model, sizeof(info->model));

    switch (psu_type) {
        case PSU_TYPE_AC_F2B:
        case PSU_TYPE_AC_B2F:
            ret = psu_ym2651y_info_get(info);
            break;
        case PSU_TYPE_UNKNOWN:  /* User insert a unknown PSU or unplugged.*/
            info->status |= ONLP_PSU_STATUS_UNPLUGGED;
            info->status &= ~ONLP_PSU_STATUS_FAILED;
            ret = ONLP_STATUS_OK;
            break;
        default:
            ret = ONLP_STATUS_E_UNSUPPORTED;
            break;
    }

    return ret;
}
Esempio n. 27
0
static int
_psu_info_get(onlp_psu_info_t* info)
{
    int val   = 0;
    int index = ONLP_OID_ID_GET(info->hdr.id);

    /* Set capability
     */
    info->caps = ONLP_PSU_CAPS_AC;

    if (info->status & ONLP_PSU_STATUS_FAILED) {
        return ONLP_STATUS_OK;
    }

    /* Set the associated oid_table */
    info->hdr.coids[0] = ONLP_FAN_ID_CREATE(index + CHASSIS_FAN_COUNT);
    info->hdr.coids[1] = ONLP_THERMAL_ID_CREATE(index + CHASSIS_THERMAL_COUNT);

    /* Read voltage, current and power */
    if (psu_power_info_get(index, "volt_in", &val) == 0 &&
        0 != val) {
        info->mvin = val;
        info->caps |= ONLP_PSU_CAPS_VIN;

        if (psu_power_info_get(index, "volt", &val) == 0) {
            info->mvout = val;
            info->caps |= ONLP_PSU_CAPS_VOUT;
        }

        if (psu_power_info_get(index, "curr_in", &val) == 0) {
            info->miin = val;
            info->caps |= ONLP_PSU_CAPS_IIN;
        }

        if (psu_power_info_get(index, "curr", &val) == 0) {
            info->miout = val;
            info->caps |= ONLP_PSU_CAPS_IOUT;
        }

        if (psu_power_info_get(index, "power_in", &val) == 0) {
            info->mpin = val;
            info->caps |= ONLP_PSU_CAPS_PIN;
        }

        if (psu_power_info_get(index, "power", &val) == 0) {
            info->mpout = val;
            info->caps |= ONLP_PSU_CAPS_POUT;
        }
    } else {
        info->status |= ONLP_PSU_STATUS_FAILED;
        return ONLP_STATUS_OK;
    }

    return psu_read_eeprom(index, info, NULL);
}
Esempio n. 28
0
/*
 * This function sets the fan speed of the given OID as a percentage.
 *
 * This will only be called if the OID has the PERCENTAGE_SET
 * capability.
 *
 * It is optional if you have no fans at all with this feature.
 */
int
onlp_fani_percentage_set(onlp_oid_t id, int p)
{
    int  fd, len, nbytes=10, local_id;
    char data[10] = {0};
    char fullpath[70] = {0};

    VALIDATE(id);

    local_id = ONLP_OID_ID_GET(id);

    /* reject p=0 (p=0, stop fan) */
    if (p == 0){
        return ONLP_STATUS_E_INVALID;
    }

    /* get fullpath */
    switch (local_id)
	{
        case FAN_1_ON_PSU1:
        case FAN_1_ON_PSU2:
            sprintf(fullpath, "%s%s", PREFIX_PATH_ON_PSU, fan_path[local_id].ctrl_speed);
            break;
        case FAN_1_ON_MAIN_BOARD:
        case FAN_2_ON_MAIN_BOARD:
        case FAN_3_ON_MAIN_BOARD:
        case FAN_4_ON_MAIN_BOARD:
        case FAN_5_ON_MAIN_BOARD:
        case FAN_6_ON_MAIN_BOARD:
            sprintf(fullpath, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, fan_path[local_id].ctrl_speed);
            break;
        default:
            return ONLP_STATUS_E_INVALID;
    }
    sprintf(data, "%d", p);
    DEBUG_PRINT("[Debug][%s][%d][openfile: %s][data=%s]\n", __FUNCTION__, __LINE__, fullpath, data);

    /* Create output file descriptor */
    fd = open(fullpath, O_WRONLY,  0644);
    if (fd == -1){
        return ONLP_STATUS_E_INTERNAL;
    }

    len = write (fd, data, (ssize_t) nbytes);
    if (len != nbytes) {
        close(fd);
        return ONLP_STATUS_E_INTERNAL;
    }

    close(fd);
    return ONLP_STATUS_OK;
}
Esempio n. 29
0
/*
 * This function puts the LED into the given mode. It is a more functional
 * interface for multimode LEDs.
 *
 * Only modes reported in the LED's capabilities will be attempted.
 */
int
onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode)
{
    int  lid;	
    VALIDATE(id);

    lid = ONLP_OID_ID_GET(id);
    if (onlp_file_write_int(onlp_to_driver_led_mode(lid , mode), LED_FORMAT, leds[lid]) < 0) {
        return ONLP_STATUS_E_INTERNAL;
    }

    return ONLP_STATUS_OK;
}
Esempio n. 30
0
static int
psu_cpr_4011_info_get(onlp_psu_info_t* info)
{
    int val   = 0;
    int index = ONLP_OID_ID_GET(info->hdr.id);
    
    /* Set capability
     */
    info->caps = ONLP_PSU_CAPS_AC;
    
	if (info->status & ONLP_PSU_STATUS_FAILED) {
	    return ONLP_STATUS_OK;
	}

    /* Set the associated oid_table */
    info->hdr.coids[0] = ONLP_FAN_ID_CREATE(index + CHASSIS_FAN_COUNT);
    info->hdr.coids[1] = ONLP_THERMAL_ID_CREATE(index + CHASSIS_THERMAL_COUNT);

    /* Read voltage, current and power */
    if (psu_cpr_4011_pmbus_info_get(index, "psu_v_out", &val) == 0) {
        info->mvout = val;
        info->caps |= ONLP_PSU_CAPS_VOUT;
    }

    if (psu_cpr_4011_pmbus_info_get(index, "psu_v_in", &val) == 0) {
        info->mvin = val;
        info->caps |= ONLP_PSU_CAPS_VIN;
    }

    if (psu_cpr_4011_pmbus_info_get(index, "psu_i_out", &val) == 0) {
        info->miout = val;
        info->caps |= ONLP_PSU_CAPS_IOUT;
    }
    
    if (psu_cpr_4011_pmbus_info_get(index, "psu_i_in", &val) == 0) {
        info->miin = val;
        info->caps |= ONLP_PSU_CAPS_IIN;
    }

    if (psu_cpr_4011_pmbus_info_get(index, "psu_p_out", &val) == 0) {
        info->mpout = val;
        info->caps |= ONLP_PSU_CAPS_POUT;
    }   

    if (psu_cpr_4011_pmbus_info_get(index, "psu_p_in", &val) == 0) {
        info->mpin = val;
        info->caps |= ONLP_PSU_CAPS_PIN;
    }   

    return ONLP_STATUS_OK;
}