Exemplo n.º 1
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);
}
/**
 * Fan Sensor Handlers
 */
static void
fan_update_handler__(netsnmp_request_info *req,
                     uint32_t index,
                     onlp_snmp_sensor_t *ss)
{
    uint64_t current = os_time_monotonic();

    if (SENSOR_NEEDS_UPDATE(current, ss)) {
        onlp_fan_info_t *fi = &ss->sensor_info.fi;
        onlp_oid_t oid = (onlp_oid_t) ss->sensor_id;

        int rv = onlp_fan_info_get(oid, fi);
        SENSOR_SET_VALIDITY(rv, current, ss);
    }

    /* else use the last update info */
}
Exemplo n.º 3
0
void
onlp_fan_show(onlp_oid_t oid, aim_pvs_t* pvs, uint32_t flags)
{
    int rv;
    iof_t iof;
    onlp_fan_info_t fi;
    int yaml;

    onlp_oid_show_iof_init_default(&iof, pvs, flags);

    rv = onlp_fan_info_get(oid, &fi);

    yaml = flags & ONLP_OID_SHOW_F_YAML;

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

    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, &fi.hdr);
        if(fi.status & 0x1) {
            /* Present */
            iof_iprintf(&iof, "State: Present");
            if(fi.status & ONLP_FAN_STATUS_FAILED) {
                iof_iprintf(&iof, "Status: Failed");
            }
            else {
                iof_iprintf(&iof, "Status: Running");
                if(fi.model[0]) {
                    iof_iprintf(&iof, "Model: %s", fi.model);
                }
                if(fi.serial[0]) {
                    iof_iprintf(&iof, "SN: %s", fi.serial);
                }
                if(fi.caps & ONLP_FAN_CAPS_GET_RPM) {
                    iof_iprintf(&iof, "RPM: %d", fi.rpm);
                }
                if(fi.caps & ONLP_FAN_CAPS_GET_PERCENTAGE) {
                    iof_iprintf(&iof, "Speed: %d%%", fi.percentage);
                }
                if(fi.status & ONLP_FAN_STATUS_B2F) {
                    iof_iprintf(&iof, "Airflow: Back-to-Front");
                }
                if(fi.status & ONLP_FAN_STATUS_F2B) {
                    iof_iprintf(&iof, "Airflow: Front-to-Back");
                }
            }
        }
        else {
            /* Not present */
            onlp_oid_show_state_missing(&iof);
        }
    }
    iof_pop(&iof);
}
Exemplo n.º 4
0
/*
 * For AC power Front to Back :
 *	* If any fan fail, please fan speed register to 15
 *	* The max value of Fan speed register is 9
 *		[LM75(48) + LM75(49) + LM75(4A)] > 174  => set Fan speed value from 4 to 5
 *		[LM75(48) + LM75(49) + LM75(4A)] > 182  => set Fan speed value from 5 to 7
 *		[LM75(48) + LM75(49) + LM75(4A)] > 190  => set Fan speed value from 7 to 9
 *
 *		[LM75(48) + LM75(49) + LM75(4A)] < 170  => set Fan speed value from 5 to 4
 *		[LM75(48) + LM75(49) + LM75(4A)] < 178  => set Fan speed value from 7 to 5
 *		[LM75(48) + LM75(49) + LM75(4A)] < 186  => set Fan speed value from 9 to 7
 *
 *
 * For  AC power Back to Front :
 *	* If any fan fail, please fan speed register to 15
 *	* The max value of Fan speed register is 10
 *		[LM75(48) + LM75(49) + LM75(4A)] > 140  => set Fan speed value from 4 to 5
 *		[LM75(48) + LM75(49) + LM75(4A)] > 150  => set Fan speed value from 5 to 7
 *		[LM75(48) + LM75(49) + LM75(4A)] > 160  => set Fan speed value from 7 to 10
 *
 *		[LM75(48) + LM75(49) + LM75(4A)] < 135  => set Fan speed value from 5 to 4
 *		[LM75(48) + LM75(49) + LM75(4A)] < 145  => set Fan speed value from 7 to 5
 *		[LM75(48) + LM75(49) + LM75(4A)] < 155  => set Fan speed value from 10 to 7
 */
int
onlp_sysi_platform_manage_fans(void)
{
    int i = 0, arr_size, temp;
    fan_ctrl_policy_t *policy;
    int cur_duty_cycle, new_duty_cycle;
    onlp_thermal_info_t thermal_1, thermal_2, thermal_3;

    int  fd, len;
    char  buf[10] = {0};

    /* Get each fan status
     */
    for (i = 1; i <= NUM_OF_FAN_ON_MAIN_BROAD; i++)
    {
        onlp_fan_info_t fan_info;

        if (onlp_fan_info_get(ONLP_FAN_ID_CREATE(i), &fan_info) != ONLP_STATUS_OK) {
            AIM_LOG_ERROR("Unable to get fan(%d) status\r\n", i);
            return ONLP_STATUS_E_INTERNAL;
        }

        /* Decision 1: Set fan as full speed if any fan is failed.
         */
        if (fan_info.status & ONLP_FAN_STATUS_FAILED) {
            AIM_LOG_ERROR("Fan(%d) is not working, set the other fans as full speed\r\n", i);
            return onlp_fan_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_CYCLE_MAX);
        }

        /* Decision 1.1: Set fan as full speed if any fan is not present.
         */
        if (!(fan_info.status & ONLP_FAN_STATUS_PRESENT)) {
            AIM_LOG_ERROR("Fan(%d) is not present, set the other fans as full speed\r\n", i);
            return onlp_fan_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_CYCLE_MAX);
        }

        /* Get fan direction (Only get the first one since all fan direction are the same)
         */
        if (i == 1) {
            if (fan_info.status & ONLP_FAN_STATUS_F2B) {
                policy   = fan_ctrl_policy_f2b;
                arr_size = AIM_ARRAYSIZE(fan_ctrl_policy_f2b);
            }
            else {
                policy   = fan_ctrl_policy_b2f;
                arr_size = AIM_ARRAYSIZE(fan_ctrl_policy_b2f);
            }
        }
    }

    /* Get current fan speed
     */
    fd = open(FAN_SPEED_CTRL_PATH, O_RDONLY);
    if (fd == -1){
        AIM_LOG_ERROR("Unable to open fan speed control node (%s)", FAN_SPEED_CTRL_PATH);
        return ONLP_STATUS_E_INTERNAL;
    }

    len = read(fd, buf, sizeof(buf));
    close(fd);
    if (len <= 0) {
        AIM_LOG_ERROR("Unable to read fan speed from (%s)", FAN_SPEED_CTRL_PATH);
        return ONLP_STATUS_E_INTERNAL;
    }
    cur_duty_cycle = atoi(buf);


    /* Decision 2: If no matched fan speed is found from the policy,
     *             use FAN_DUTY_CYCLE_MIN as default speed
     */
	for (i = 0; i < arr_size; i++) {
	    if (policy[i].duty_cycle != cur_duty_cycle)
		    continue;

		break;
	}

	if (i == arr_size) {
        return onlp_fan_percentage_set(ONLP_FAN_ID_CREATE(1), policy[0].duty_cycle);
	}

    /* Get current temperature
     */
    if (onlp_thermal_info_get(ONLP_THERMAL_ID_CREATE(2), &thermal_1) != ONLP_STATUS_OK ||
        onlp_thermal_info_get(ONLP_THERMAL_ID_CREATE(3), &thermal_2) != ONLP_STATUS_OK ||
        onlp_thermal_info_get(ONLP_THERMAL_ID_CREATE(4), &thermal_3) != ONLP_STATUS_OK) {
        AIM_LOG_ERROR("Unable to read thermal status");
        return ONLP_STATUS_E_INTERNAL;
    }
    temp = thermal_1.mcelsius + thermal_2.mcelsius + thermal_3.mcelsius;


    /* Decision 3: Decide new fan speed depend on fan direction/current fan speed/temperature
     */
    new_duty_cycle = cur_duty_cycle;

    if ((temp >= policy[i].temp_up_adjust) && (i != (arr_size-1))) {
	    new_duty_cycle = policy[i+1].duty_cycle;
	}
	else if ((temp <= policy[i].temp_down_adjust) && (i != 0)) {
	    new_duty_cycle = policy[i-1].duty_cycle;
	}

	if (new_duty_cycle == cur_duty_cycle) {
        /* Duty cycle does not change, just return */
	    return ONLP_STATUS_OK;
	}

    return onlp_fan_percentage_set(ONLP_FAN_ID_CREATE(1), new_duty_cycle);
}