diff --git a/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/modules/builds/dni_agc7648sv1_psu.c b/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/modules/builds/dni_agc7648sv1_psu.c index 4ba6e2c8..1257252f 100644 --- a/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/modules/builds/dni_agc7648sv1_psu.c +++ b/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/modules/builds/dni_agc7648sv1_psu.c @@ -59,8 +59,8 @@ struct dps_800ab_16_d_data { u8 fan_fault; u16 fan_duty_cycle[2]; u16 fan_speed[2]; - u8 mfr_model[14]; - u8 mfr_serial[14]; + u8 mfr_model[16]; + u8 mfr_serial[16]; }; static int two_complement_to_int(u16 data, u8 valid_bit, int mask); diff --git a/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/fani.c b/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/fani.c index b46061a0..c344c7aa 100755 --- a/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/fani.c +++ b/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/fani.c @@ -34,6 +34,7 @@ typedef struct fan_path_S char *ctrl_speed; }fan_path_T; +#ifdef I2C static fan_path_T fan_path[] = /* must map with onlp_fan_id */ { { NULL, NULL, NULL }, @@ -48,6 +49,7 @@ static fan_path_T fan_path[] = /* must map with onlp_fan_id */ { "31-0058/psu_fan1_fault", "31-0058/psu_fan1_speed_rpm", "31-0058/psu_fan1_duty_cycle_percentage" }, { "32-0058/psu_fan1_fault", "32-0058/psu_fan1_speed_rpm", "32-0058/psu_fan1_duty_cycle_percentage" } }; +#endif #define MAKE_FAN_INFO_NODE_ON_FAN_BOARD(id) \ { \ @@ -93,186 +95,181 @@ onlp_fan_info_t linfo[] = { static int dni_fani_info_get_fan(int local_id, onlp_fan_info_t* info, char *dev_name) { - int bit_data = 0; - int rpm = 0; - char fullpath[100] = {0}; int rv = ONLP_STATUS_OK; - uint8_t present_bit = 0x00; - UINT4 multiplier = 1; +#ifdef BMC + uint8_t bit_data = 0x00; UINT4 u4Data = 0; - int fantray_present = -1; + UINT4 multiplier = 1; + uint8_t present_bit = 0x00; - if(dni_bmc_check() == BMC_ON) + if(dni_bmc_sensor_read(dev_name, &u4Data, multiplier, FAN_SENSOR) == ONLP_STATUS_OK) { - if(dni_bmc_sensor_read(dev_name, &u4Data, multiplier) == ONLP_STATUS_OK) - { - info->rpm = u4Data; - info->percentage = (info->rpm * 100) / MAX_FRONT_FAN_SPEED; - } + info->rpm = u4Data; + info->percentage = (info->rpm * 100) / MAX_FRONT_FAN_SPEED; + } - rv = dni_bmc_fanpresent_info_get(&bit_data); - if(rv == ONLP_STATUS_OK && bit_data != 0) - present_bit = bit_data; - else - rv = ONLP_STATUS_E_INVALID; - - switch(local_id) { - case FAN_4_ON_FAN_BOARD: - case FAN_8_ON_FAN_BOARD: - if((present_bit & 1) == 0) - info->status |= ONLP_FAN_STATUS_PRESENT; - else - info->status |= ONLP_FAN_STATUS_FAILED; - break; - case FAN_3_ON_FAN_BOARD: - case FAN_7_ON_FAN_BOARD: - if((present_bit & (1 << 1)) == 0) - info->status |= ONLP_FAN_STATUS_PRESENT; - else - info->status |= ONLP_FAN_STATUS_FAILED; - break; - case FAN_2_ON_FAN_BOARD: - case FAN_6_ON_FAN_BOARD: - if((present_bit & (1 << 2)) == 0) - info->status |= ONLP_FAN_STATUS_PRESENT; - else - info->status |= ONLP_FAN_STATUS_FAILED; - break; - case FAN_1_ON_FAN_BOARD: - case FAN_5_ON_FAN_BOARD: - if((present_bit & (1 << 3)) == 0) - info->status |= ONLP_FAN_STATUS_PRESENT; - else - info->status |= ONLP_FAN_STATUS_FAILED; - break; - } - } + rv = dni_bmc_fanpresent_info_get(&bit_data); + if(rv == ONLP_STATUS_OK && bit_data != 0x00) + present_bit = bit_data; else - { - sprintf(fullpath, "%s%s", PREFIX_PATH, fan_path[local_id].speed); - rpm = dni_i2c_lock_read_attribute(NULL, fullpath); - info->rpm = rpm; + rv = ONLP_STATUS_E_INVALID; - /* If rpm is FAN_ZERO_TACH, then the rpm value is zero. */ - if(info->rpm == 960) - info->rpm = 0; - - /* get speed percentage from rpm */ - info->percentage = (info->rpm * 100)/MAX_FRONT_FAN_SPEED; - - switch(local_id) { - case FAN_4_ON_FAN_BOARD: - case FAN_8_ON_FAN_BOARD: - fantray_present = dni_i2c_lock_read_attribute(NULL, FAN4_PRESENT_PATH); - if(fantray_present == 0) - info->status |= ONLP_FAN_STATUS_PRESENT; - else - info->status |= ONLP_FAN_STATUS_FAILED; - break; - case FAN_3_ON_FAN_BOARD: - case FAN_7_ON_FAN_BOARD: - fantray_present = dni_i2c_lock_read_attribute(NULL, FAN3_PRESENT_PATH); - if(fantray_present == 0) - info->status |= ONLP_FAN_STATUS_PRESENT; - else - info->status |= ONLP_FAN_STATUS_FAILED; - break; - case FAN_2_ON_FAN_BOARD: - case FAN_6_ON_FAN_BOARD: - fantray_present = dni_i2c_lock_read_attribute(NULL, FAN2_PRESENT_PATH); - if(fantray_present == 0) - info->status |= ONLP_FAN_STATUS_PRESENT; - else - info->status |= ONLP_FAN_STATUS_FAILED; - break; - case FAN_1_ON_FAN_BOARD: - case FAN_5_ON_FAN_BOARD: - fantray_present = dni_i2c_lock_read_attribute(NULL, FAN1_PRESENT_PATH); - if(fantray_present == 0) - info->status |= ONLP_FAN_STATUS_PRESENT; - else - info->status |= ONLP_FAN_STATUS_FAILED; - break; - } + switch(local_id) { + case FAN_4_ON_FAN_BOARD: + case FAN_8_ON_FAN_BOARD: + if((present_bit & 1) == 0) + info->status |= ONLP_FAN_STATUS_PRESENT; + else + info->status |= ONLP_FAN_STATUS_FAILED; + break; + case FAN_3_ON_FAN_BOARD: + case FAN_7_ON_FAN_BOARD: + if((present_bit & (1 << 1)) == 0) + info->status |= ONLP_FAN_STATUS_PRESENT; + else + info->status |= ONLP_FAN_STATUS_FAILED; + break; + case FAN_2_ON_FAN_BOARD: + case FAN_6_ON_FAN_BOARD: + if((present_bit & (1 << 2)) == 0) + info->status |= ONLP_FAN_STATUS_PRESENT; + else + info->status |= ONLP_FAN_STATUS_FAILED; + break; + case FAN_1_ON_FAN_BOARD: + case FAN_5_ON_FAN_BOARD: + if((present_bit & (1 << 3)) == 0) + info->status |= ONLP_FAN_STATUS_PRESENT; + else + info->status |= ONLP_FAN_STATUS_FAILED; + break; } +#elif defined I2C + int rpm = 0; + int fantray_present = -1; + char fullpath[100] = {0}; + sprintf(fullpath, "%s%s", PREFIX_PATH, fan_path[local_id].speed); + rpm = dni_i2c_lock_read_attribute(NULL, fullpath); + info->rpm = rpm; + + /* If rpm is FAN_ZERO_TACH, then the rpm value is zero. */ + if(info->rpm == 960) + info->rpm = 0; + + /* get speed percentage from rpm */ + info->percentage = (info->rpm * 100)/MAX_FRONT_FAN_SPEED; + + switch(local_id) { + case FAN_4_ON_FAN_BOARD: + case FAN_8_ON_FAN_BOARD: + fantray_present = dni_i2c_lock_read_attribute(NULL, FAN4_PRESENT_PATH); + if(fantray_present == 0) + info->status |= ONLP_FAN_STATUS_PRESENT; + else + info->status |= ONLP_FAN_STATUS_FAILED; + break; + case FAN_3_ON_FAN_BOARD: + case FAN_7_ON_FAN_BOARD: + fantray_present = dni_i2c_lock_read_attribute(NULL, FAN3_PRESENT_PATH); + if(fantray_present == 0) + info->status |= ONLP_FAN_STATUS_PRESENT; + else + info->status |= ONLP_FAN_STATUS_FAILED; + break; + case FAN_2_ON_FAN_BOARD: + case FAN_6_ON_FAN_BOARD: + fantray_present = dni_i2c_lock_read_attribute(NULL, FAN2_PRESENT_PATH); + if(fantray_present == 0) + info->status |= ONLP_FAN_STATUS_PRESENT; + else + info->status |= ONLP_FAN_STATUS_FAILED; + break; + case FAN_1_ON_FAN_BOARD: + case FAN_5_ON_FAN_BOARD: + fantray_present = dni_i2c_lock_read_attribute(NULL, FAN1_PRESENT_PATH); + if(fantray_present == 0) + info->status |= ONLP_FAN_STATUS_PRESENT; + else + info->status |= ONLP_FAN_STATUS_FAILED; + break; + } +#endif return rv; } static int dni_fani_info_get_fan_on_psu(int local_id, onlp_fan_info_t* info, char *dev_name) { - int rpm_data = 0; - int r_data = 0; - int bit_data = 0; int rv = ONLP_STATUS_OK; - int psu_present = 0; +#ifdef BMC UINT4 multiplier = 1; UINT4 u4Data = 0; + uint8_t psu_present_bit = 0x00; + int rpm_data = 0; + int bit_data = 0; + + dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_1_ADDR, PSU_REGISTER, &bit_data); + psu_present_bit = bit_data; + rv = dni_bmc_sensor_read(dev_name, &u4Data, multiplier, FAN_SENSOR); + rpm_data = (int)u4Data; + + switch(local_id) { + case FAN_1_ON_PSU1: + psu_present_bit = bit_data; + if((psu_present_bit & 0x01) != 0x01) + { + info->rpm = rpm_data; + info->percentage = (info->rpm * 100) / MAX_FRONT_FAN_SPEED; + info->status |= ONLP_FAN_STATUS_PRESENT | ONLP_FAN_STATUS_B2F; + } + else + { + info->status |= ONLP_FAN_STATUS_FAILED; + rv = ONLP_STATUS_E_INVALID; + } + break; + case FAN_1_ON_PSU2: + if((psu_present_bit & 0x02) != 0x02) + { + info->rpm = rpm_data; + info->percentage = (info->rpm * 100) / MAX_FRONT_FAN_SPEED; + info->status |= ONLP_FAN_STATUS_PRESENT | ONLP_FAN_STATUS_B2F; + } + else + { + info->status |= ONLP_FAN_STATUS_FAILED; + rv = ONLP_STATUS_E_INVALID; + } + break; + } +#elif defined I2C + int psu_present = 0; + int r_data = 0; char fullpath[100] = {0}; - if(dni_bmc_check() == BMC_ON) - { - rv = dni_psu_present(&bit_data); - psu_present = bit_data; - rv = dni_bmc_sensor_read(dev_name, &u4Data, multiplier); - rpm_data = (int)u4Data; - - switch(local_id) - { - case FAN_1_ON_PSU1: - if((psu_present & 0x01) != 0x01) - { - info->rpm = rpm_data; - info->percentage = (info->rpm * 100) / MAX_FRONT_FAN_SPEED; - info->status |= ONLP_FAN_STATUS_PRESENT | ONLP_FAN_STATUS_B2F; - } - else - { - info->status |= ONLP_FAN_STATUS_FAILED; - rv = ONLP_STATUS_E_INVALID; - } - break; - case FAN_1_ON_PSU2: - if((psu_present & 0x02) != 0x02) - { - info->rpm = rpm_data; - info->percentage = (info->rpm * 100) / MAX_FRONT_FAN_SPEED; - info->status |= ONLP_FAN_STATUS_PRESENT | ONLP_FAN_STATUS_B2F; - } - else - { - info->status |= ONLP_FAN_STATUS_FAILED; - rv = ONLP_STATUS_E_INVALID; - } - break; - } + switch(local_id) { + case FAN_1_ON_PSU1: + psu_present = dni_i2c_lock_read_attribute(NULL, PSU1_PRESENT_PATH); + break; + case FAN_1_ON_PSU2: + psu_present = dni_i2c_lock_read_attribute(NULL, PSU2_PRESENT_PATH); + break; + default: + break; } - else - { - switch(local_id) { - case FAN_1_ON_PSU1: - psu_present = dni_i2c_lock_read_attribute(NULL, PSU1_PRESENT_PATH); - break; - case FAN_1_ON_PSU2: - psu_present = dni_i2c_lock_read_attribute(NULL, PSU2_PRESENT_PATH); - break; - default: - break; - } - if(psu_present == 0) - info->status |= ONLP_FAN_STATUS_PRESENT | ONLP_FAN_STATUS_B2F; - else if(psu_present == 1) - info->status |= ONLP_FAN_STATUS_FAILED; + if(psu_present == 0) + info->status |= ONLP_FAN_STATUS_PRESENT | ONLP_FAN_STATUS_B2F; + else if(psu_present == 1) + info->status |= ONLP_FAN_STATUS_FAILED; - /* Read PSU FAN speed from psu_fan1_speed_rpm */ - sprintf(fullpath, "%s%s", PREFIX_PATH, fan_path[local_id].speed); - r_data = dni_i2c_lock_read_attribute(NULL, fullpath); - info->rpm = r_data; - - /* Calculate psu fan duty cycle based on rpm */ - info->percentage = (info->rpm * 100) / MAX_PSU_FAN_SPEED; - } + /* Read PSU FAN speed from psu_fan1_speed_rpm */ + sprintf(fullpath, "%s%s", PREFIX_PATH, fan_path[local_id].speed); + r_data = dni_i2c_lock_read_attribute(NULL, fullpath); + info->rpm = r_data; + /* Calculate psu fan duty cycle based on rpm */ + info->percentage = (info->rpm * 100) / MAX_PSU_FAN_SPEED; +#endif return rv; } @@ -343,41 +340,34 @@ int onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* info) */ int onlp_fani_rpm_set(onlp_oid_t id, int rpm) { + int rv = ONLP_STATUS_OK; + +#ifdef I2C int local_id; char data[10] = {0}; char fullpath[70] = {0}; - int rv; VALIDATE(id); local_id = ONLP_OID_ID_GET(id); - if(dni_bmc_check() == BMC_ON) - { - rv = ONLP_STATUS_OK; + /* get fullpath */ + switch (local_id) { + case FAN_1_ON_FAN_BOARD: + case FAN_2_ON_FAN_BOARD: + case FAN_3_ON_FAN_BOARD: + case FAN_4_ON_FAN_BOARD: + case FAN_5_ON_FAN_BOARD: + case FAN_6_ON_FAN_BOARD: + case FAN_7_ON_FAN_BOARD: + case FAN_8_ON_FAN_BOARD: + sprintf(fullpath, "%s%s", PREFIX_PATH, fan_path[local_id].speed); + break; + default: + return ONLP_STATUS_E_INVALID; } - else - { - /* get fullpath */ - switch (local_id) { - case FAN_1_ON_FAN_BOARD: - case FAN_2_ON_FAN_BOARD: - case FAN_3_ON_FAN_BOARD: - case FAN_4_ON_FAN_BOARD: - case FAN_5_ON_FAN_BOARD: - case FAN_6_ON_FAN_BOARD: - case FAN_7_ON_FAN_BOARD: - case FAN_8_ON_FAN_BOARD: - sprintf(fullpath, "%s%s", PREFIX_PATH, fan_path[local_id].speed); - break; - default: - return ONLP_STATUS_E_INVALID; - } - sprintf(data, "%d", rpm); - dni_i2c_lock_write_attribute(NULL, data, fullpath); - - rv = ONLP_STATUS_OK; - } - + sprintf(data, "%d", rpm); + dni_i2c_lock_write_attribute(NULL, data, fullpath); +#endif return rv; } @@ -391,44 +381,36 @@ int onlp_fani_rpm_set(onlp_oid_t id, int rpm) */ int onlp_fani_percentage_set(onlp_oid_t id, int p) { + int rv = ONLP_STATUS_OK; +#ifdef I2C int local_id; char data[10] = {0}; char fullpath[70] = {0}; - int rv; VALIDATE(id); local_id = ONLP_OID_ID_GET(id); - if(dni_bmc_check() == BMC_ON) - { - rv = ONLP_STATUS_OK; + /* Select PSU member */ + switch (local_id) { + case FAN_1_ON_FAN_BOARD: + case FAN_2_ON_FAN_BOARD: + case FAN_3_ON_FAN_BOARD: + case FAN_4_ON_FAN_BOARD: + case FAN_5_ON_FAN_BOARD: + case FAN_6_ON_FAN_BOARD: + case FAN_7_ON_FAN_BOARD: + case FAN_8_ON_FAN_BOARD: + case FAN_1_ON_PSU1: + case FAN_1_ON_PSU2: + break; + default: + return ONLP_STATUS_E_INVALID; } - else - { - /* Select PSU member */ - switch (local_id) { - case FAN_1_ON_FAN_BOARD: - case FAN_2_ON_FAN_BOARD: - case FAN_3_ON_FAN_BOARD: - case FAN_4_ON_FAN_BOARD: - case FAN_5_ON_FAN_BOARD: - case FAN_6_ON_FAN_BOARD: - case FAN_7_ON_FAN_BOARD: - case FAN_8_ON_FAN_BOARD: - case FAN_1_ON_PSU1: - case FAN_1_ON_PSU2: - break; - default: - return ONLP_STATUS_E_INVALID; - } - sprintf(fullpath, "%s%s", PREFIX_PATH, fan_path[local_id].ctrl_speed); - /* Write percentage to psu_fan1_duty_cycle_percentage */ - sprintf(data, "%d", p); - dni_i2c_lock_write_attribute(NULL, data, fullpath); - - rv = ONLP_STATUS_OK; - } - + sprintf(fullpath, "%s%s", PREFIX_PATH, fan_path[local_id].ctrl_speed); + /* Write percentage to psu_fan1_duty_cycle_percentage */ + sprintf(data, "%d", p); + dni_i2c_lock_write_attribute(NULL, data, fullpath); +#endif return rv; } diff --git a/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/ledi.c b/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/ledi.c index 6c858fd0..9d5e4c92 100755 --- a/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/ledi.c +++ b/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/ledi.c @@ -89,221 +89,219 @@ int onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) { int local_id; int r_data = 0; - int bit_data = 0; VALIDATE(id); local_id = ONLP_OID_ID_GET(id); *info = linfo[ONLP_OID_ID_GET(id)]; - if(dni_bmc_check() == BMC_ON) - { - switch(local_id) { - case LED_FRONT_FAN: - if( dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_1_ADDR, SYS_LED_REGISTER, 1, &bit_data) != ONLP_STATUS_OK){ - return ONLP_STATUS_E_INTERNAL; - } - r_data = bit_data; - if((r_data & 0x03) == 0x01) - info->mode = ONLP_LED_MODE_GREEN; - else if((r_data & 0x03) == 0x02) - info->mode = ONLP_LED_MODE_YELLOW; - else if((r_data & 0x03) == 0x03) - info->mode = ONLP_LED_MODE_YELLOW_BLINKING; - else if((r_data & 0x03) == 0x00) - info->mode = ONLP_LED_MODE_OFF; - else - return ONLP_STATUS_E_INTERNAL; - break; +#ifdef BMC + int bit_data = 0; - case LED_FRONT_PWR: - if( dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_1_ADDR, SYS_LED_REGISTER, 1, &bit_data) != ONLP_STATUS_OK){ - return ONLP_STATUS_E_INTERNAL; - } - r_data = bit_data; + switch(local_id) { + case LED_FRONT_FAN: + if( dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_1_ADDR, SYS_LED_REGISTER, &bit_data) != ONLP_STATUS_OK){ + return ONLP_STATUS_E_INTERNAL; + } + r_data = bit_data; + if((r_data & 0x03) == 0x01) + info->mode = ONLP_LED_MODE_GREEN; + else if((r_data & 0x03) == 0x02) + info->mode = ONLP_LED_MODE_YELLOW; + else if((r_data & 0x03) == 0x03) + info->mode = ONLP_LED_MODE_YELLOW_BLINKING; + else if((r_data & 0x03) == 0x00) + info->mode = ONLP_LED_MODE_OFF; + else + return ONLP_STATUS_E_INTERNAL; + break; + + case LED_FRONT_PWR: + if( dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_1_ADDR, SYS_LED_REGISTER, &bit_data) != ONLP_STATUS_OK){ + return ONLP_STATUS_E_INTERNAL; + } + r_data = bit_data; + if((r_data & 0x0c) == 0x04) + info->mode = ONLP_LED_MODE_GREEN; + else if((r_data & 0x0c) == 0x08) + info->mode = ONLP_LED_MODE_YELLOW; + else if((r_data & 0x0c) == 0x0c || (r_data & 0x0c) == 0x00) + info->mode = ONLP_LED_MODE_OFF; + else + return ONLP_STATUS_E_INTERNAL; + break; + + case LED_FRONT_SYS: + if( dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_1_ADDR, SYS_LED_REGISTER, &bit_data) != ONLP_STATUS_OK){ + return ONLP_STATUS_E_INTERNAL; + } + r_data = bit_data; + if((r_data & 0xf0) == 0x10) + info->mode = ONLP_LED_MODE_YELLOW; + else if((r_data & 0xf0) == 0x20) + info->mode = ONLP_LED_MODE_GREEN; + else if((r_data & 0xf0) == 0x90) // 0.5S + info->mode = ONLP_LED_MODE_GREEN_BLINKING; + else if((r_data & 0xf0) == 0xa0) // 0.5S + info->mode = ONLP_LED_MODE_YELLOW_BLINKING; + else if ((r_data & 0xf0) == 0x00) + info->mode = ONLP_LED_MODE_OFF; + else + return ONLP_STATUS_E_INTERNAL; + break; + + case LED_REAR_FAN_TRAY_1: + if( dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_1_ADDR, FAN_LED_REGISTER, &bit_data) != ONLP_STATUS_OK){ + return ONLP_STATUS_E_INTERNAL; + } + r_data = bit_data; + if(dni_fan_present(LED_REAR_FAN_TRAY_1) == ONLP_STATUS_OK){ + if((r_data & 0xc0) == 0x40) + info->mode = ONLP_LED_MODE_GREEN; + else if((r_data & 0xc0) == 0x80) + info->mode = ONLP_LED_MODE_RED; + } + else + info->mode = ONLP_LED_MODE_OFF; + break; + + case LED_REAR_FAN_TRAY_2: + if( dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_1_ADDR, FAN_LED_REGISTER, &bit_data) != ONLP_STATUS_OK){ + return ONLP_STATUS_E_INTERNAL; + } + r_data = bit_data; + if(dni_fan_present(LED_REAR_FAN_TRAY_2) == ONLP_STATUS_OK){ + if((r_data & 0x30) == 0x10) + info->mode = ONLP_LED_MODE_GREEN; + else if((r_data & 0x30) == 0x20) + info->mode = ONLP_LED_MODE_RED; + } + else + info->mode = ONLP_LED_MODE_OFF; + break; + case LED_REAR_FAN_TRAY_3: + if( dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_1_ADDR, FAN_LED_REGISTER, &bit_data) != ONLP_STATUS_OK){ + return ONLP_STATUS_E_INTERNAL; + } + r_data = bit_data; + if(dni_fan_present(LED_REAR_FAN_TRAY_3) == ONLP_STATUS_OK){ if((r_data & 0x0c) == 0x04) info->mode = ONLP_LED_MODE_GREEN; else if((r_data & 0x0c) == 0x08) - info->mode = ONLP_LED_MODE_YELLOW; - else if((r_data & 0x0c) == 0x0c || (r_data & 0x0c) == 0x00) - info->mode = ONLP_LED_MODE_OFF; - else - return ONLP_STATUS_E_INTERNAL; - break; + info->mode = ONLP_LED_MODE_RED; + } + else + info->mode = ONLP_LED_MODE_OFF; + break; - case LED_FRONT_SYS: - if( dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_1_ADDR, SYS_LED_REGISTER, 1, &bit_data) != ONLP_STATUS_OK){ - return ONLP_STATUS_E_INTERNAL; - } - r_data = bit_data; - if((r_data & 0xf0) == 0x10) - info->mode = ONLP_LED_MODE_YELLOW; - else if((r_data & 0xf0) == 0x20) - info->mode = ONLP_LED_MODE_GREEN; - else if((r_data & 0xf0) == 0x90) // 0.5S - info->mode = ONLP_LED_MODE_GREEN_BLINKING; - else if((r_data & 0xf0) == 0xa0) // 0.5S - info->mode = ONLP_LED_MODE_YELLOW_BLINKING; - else if ((r_data & 0xf0) == 0x00) - info->mode = ONLP_LED_MODE_OFF; - else - return ONLP_STATUS_E_INTERNAL; - break; - - case LED_REAR_FAN_TRAY_1: - if( dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_1_ADDR, FAN_LED_REGISTER, 1, &bit_data) != ONLP_STATUS_OK){ - return ONLP_STATUS_E_INTERNAL; - } - r_data = bit_data; - if(dni_fan_present(LED_REAR_FAN_TRAY_1) == ONLP_STATUS_OK){ - if((r_data & 0xc0) == 0x40) - info->mode = ONLP_LED_MODE_GREEN; - else if((r_data & 0xc0) == 0x80) - info->mode = ONLP_LED_MODE_RED; - } - else - info->mode = ONLP_LED_MODE_OFF; - break; - - case LED_REAR_FAN_TRAY_2: - if( dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_1_ADDR, FAN_LED_REGISTER, 1, &bit_data) != ONLP_STATUS_OK){ - return ONLP_STATUS_E_INTERNAL; - } - r_data = bit_data; - if(dni_fan_present(LED_REAR_FAN_TRAY_2) == ONLP_STATUS_OK){ - if((r_data & 0x30) == 0x10) - info->mode = ONLP_LED_MODE_GREEN; - else if((r_data & 0x30) == 0x20) - info->mode = ONLP_LED_MODE_RED; - } - else - info->mode = ONLP_LED_MODE_OFF; - break; - case LED_REAR_FAN_TRAY_3: - if( dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_1_ADDR, FAN_LED_REGISTER, 1, &bit_data) != ONLP_STATUS_OK){ - return ONLP_STATUS_E_INTERNAL; - } - r_data = bit_data; - if(dni_fan_present(LED_REAR_FAN_TRAY_3) == ONLP_STATUS_OK){ - if((r_data & 0x0c) == 0x04) - info->mode = ONLP_LED_MODE_GREEN; - else if((r_data & 0x0c) == 0x08) - info->mode = ONLP_LED_MODE_RED; - } - else - info->mode = ONLP_LED_MODE_OFF; - break; - - case LED_REAR_FAN_TRAY_4: - if( dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_1_ADDR, FAN_LED_REGISTER, 1, &bit_data) != ONLP_STATUS_OK){ - return ONLP_STATUS_E_INTERNAL; - } - r_data = bit_data; - if(dni_fan_present(LED_REAR_FAN_TRAY_4) == ONLP_STATUS_OK){ - if((r_data & 0x03) == 0x01) - info->mode = ONLP_LED_MODE_GREEN; - else if((r_data & 0x03) == 0x02) - info->mode = ONLP_LED_MODE_RED; - } - else - info->mode = ONLP_LED_MODE_OFF; - break; - } - } - else{ - switch(local_id) - { - case LED_FRONT_FAN: - r_data = dni_lock_cpld_read_attribute(SWPLD1_PATH, SYS_LED_REGISTER); + case LED_REAR_FAN_TRAY_4: + if( dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_1_ADDR, FAN_LED_REGISTER, &bit_data) != ONLP_STATUS_OK){ + return ONLP_STATUS_E_INTERNAL; + } + r_data = bit_data; + if(dni_fan_present(LED_REAR_FAN_TRAY_4) == ONLP_STATUS_OK){ if((r_data & 0x03) == 0x01) info->mode = ONLP_LED_MODE_GREEN; else if((r_data & 0x03) == 0x02) - info->mode = ONLP_LED_MODE_YELLOW; - else if((r_data & 0x03) == 0x03) - info->mode = ONLP_LED_MODE_YELLOW_BLINKING; - else if((r_data & 0x03) == 0x00) - info->mode = ONLP_LED_MODE_OFF; - else - return ONLP_STATUS_E_INTERNAL; - break; - - case LED_FRONT_PWR: - r_data = dni_lock_cpld_read_attribute(SWPLD1_PATH, SYS_LED_REGISTER); - if((r_data & 0x0c) == 0x4) - info->mode = ONLP_LED_MODE_GREEN; - else if((r_data & 0x0c) == 0x8) - info->mode = ONLP_LED_MODE_YELLOW; - else if((r_data & 0x0c) == 0xc || (r_data & 0x0c) == 0x00) - info->mode = ONLP_LED_MODE_OFF; - else - return ONLP_STATUS_E_INTERNAL; - break; - - case LED_FRONT_SYS: - r_data = dni_lock_cpld_read_attribute(SWPLD1_PATH, SYS_LED_REGISTER); - if((r_data & 0xf0) == 0x10) - info->mode = ONLP_LED_MODE_YELLOW; - else if((r_data & 0xf0) == 0x20) - info->mode = ONLP_LED_MODE_GREEN; - else if((r_data & 0xf0) == 0x90) // 0.5S - info->mode = ONLP_LED_MODE_GREEN_BLINKING; - else if((r_data & 0xf0) == 0xa0) // 0.5S - info->mode = ONLP_LED_MODE_YELLOW_BLINKING; - else if ((r_data & 0xf0) == 0x00) - info->mode = ONLP_LED_MODE_OFF; - else - return ONLP_STATUS_E_INTERNAL; - break; - - case LED_REAR_FAN_TRAY_1: - r_data = dni_lock_cpld_read_attribute(SWPLD1_PATH, FAN_LED_REGISTER); - if(dni_fan_present(LED_REAR_FAN_TRAY_1) == ONLP_STATUS_OK){ - if((r_data & 0xc0) == 0x40) - info->mode = ONLP_LED_MODE_GREEN; - else if((r_data & 0xc0) == 0x80) - info->mode = ONLP_LED_MODE_RED; - } - else - info->mode = ONLP_LED_MODE_OFF; - break; - - case LED_REAR_FAN_TRAY_2: - r_data = dni_lock_cpld_read_attribute(SWPLD1_PATH, FAN_LED_REGISTER); - if(dni_fan_present(LED_REAR_FAN_TRAY_2) == ONLP_STATUS_OK){ - if((r_data & 0x30) == 0x10) - info->mode = ONLP_LED_MODE_GREEN; - else if((r_data & 0x30) == 0x20) - info->mode = ONLP_LED_MODE_RED; - } - else - info->mode = ONLP_LED_MODE_OFF; - break; - - case LED_REAR_FAN_TRAY_3: - r_data = dni_lock_cpld_read_attribute(SWPLD1_PATH, FAN_LED_REGISTER); - if(dni_fan_present(LED_REAR_FAN_TRAY_3) == ONLP_STATUS_OK){ - if((r_data & 0x0c) == 0x04) - info->mode = ONLP_LED_MODE_GREEN; - else if((r_data & 0x0c) == 0x08) - info->mode = ONLP_LED_MODE_RED; - } - else - info->mode = ONLP_LED_MODE_OFF; - break; - - case LED_REAR_FAN_TRAY_4: - r_data = dni_lock_cpld_read_attribute(SWPLD1_PATH, FAN_LED_REGISTER); - if(dni_fan_present(LED_REAR_FAN_TRAY_4) == ONLP_STATUS_OK){ - if((r_data & 0x03) == 0x01) - info->mode = ONLP_LED_MODE_GREEN; - else if((r_data & 0x03) == 0x02) - info->mode = ONLP_LED_MODE_RED; - } - else - info->mode = ONLP_LED_MODE_OFF; - break; - } + info->mode = ONLP_LED_MODE_RED; + } + else + info->mode = ONLP_LED_MODE_OFF; + break; } +#elif defined I2C + switch(local_id) + { + case LED_FRONT_FAN: + r_data = dni_lock_cpld_read_attribute(SWPLD1_PATH, SYS_LED_REGISTER); + if((r_data & 0x03) == 0x01) + info->mode = ONLP_LED_MODE_GREEN; + else if((r_data & 0x03) == 0x02) + info->mode = ONLP_LED_MODE_YELLOW; + else if((r_data & 0x03) == 0x03) + info->mode = ONLP_LED_MODE_YELLOW_BLINKING; + else if((r_data & 0x03) == 0x00) + info->mode = ONLP_LED_MODE_OFF; + else + return ONLP_STATUS_E_INTERNAL; + break; + case LED_FRONT_PWR: + r_data = dni_lock_cpld_read_attribute(SWPLD1_PATH, SYS_LED_REGISTER); + if((r_data & 0x0c) == 0x4) + info->mode = ONLP_LED_MODE_GREEN; + else if((r_data & 0x0c) == 0x8) + info->mode = ONLP_LED_MODE_YELLOW; + else if((r_data & 0x0c) == 0xc || (r_data & 0x0c) == 0x00) + info->mode = ONLP_LED_MODE_OFF; + else + return ONLP_STATUS_E_INTERNAL; + break; + + case LED_FRONT_SYS: + r_data = dni_lock_cpld_read_attribute(SWPLD1_PATH, SYS_LED_REGISTER); + if((r_data & 0xf0) == 0x10) + info->mode = ONLP_LED_MODE_YELLOW; + else if((r_data & 0xf0) == 0x20) + info->mode = ONLP_LED_MODE_GREEN; + else if((r_data & 0xf0) == 0x90) // 0.5S + info->mode = ONLP_LED_MODE_GREEN_BLINKING; + else if((r_data & 0xf0) == 0xa0) // 0.5S + info->mode = ONLP_LED_MODE_YELLOW_BLINKING; + else if ((r_data & 0xf0) == 0x00) + info->mode = ONLP_LED_MODE_OFF; + else + return ONLP_STATUS_E_INTERNAL; + break; + + case LED_REAR_FAN_TRAY_1: + r_data = dni_lock_cpld_read_attribute(SWPLD1_PATH, FAN_LED_REGISTER); + if(dni_fan_present(LED_REAR_FAN_TRAY_1) == ONLP_STATUS_OK){ + if((r_data & 0xc0) == 0x40) + info->mode = ONLP_LED_MODE_GREEN; + else if((r_data & 0xc0) == 0x80) + info->mode = ONLP_LED_MODE_RED; + } + else + info->mode = ONLP_LED_MODE_OFF; + break; + + case LED_REAR_FAN_TRAY_2: + r_data = dni_lock_cpld_read_attribute(SWPLD1_PATH, FAN_LED_REGISTER); + if(dni_fan_present(LED_REAR_FAN_TRAY_2) == ONLP_STATUS_OK){ + if((r_data & 0x30) == 0x10) + info->mode = ONLP_LED_MODE_GREEN; + else if((r_data & 0x30) == 0x20) + info->mode = ONLP_LED_MODE_RED; + } + else + info->mode = ONLP_LED_MODE_OFF; + break; + + case LED_REAR_FAN_TRAY_3: + r_data = dni_lock_cpld_read_attribute(SWPLD1_PATH, FAN_LED_REGISTER); + if(dni_fan_present(LED_REAR_FAN_TRAY_3) == ONLP_STATUS_OK){ + if((r_data & 0x0c) == 0x04) + info->mode = ONLP_LED_MODE_GREEN; + else if((r_data & 0x0c) == 0x08) + info->mode = ONLP_LED_MODE_RED; + } + else + info->mode = ONLP_LED_MODE_OFF; + break; + + case LED_REAR_FAN_TRAY_4: + r_data = dni_lock_cpld_read_attribute(SWPLD1_PATH, FAN_LED_REGISTER); + if(dni_fan_present(LED_REAR_FAN_TRAY_4) == ONLP_STATUS_OK){ + if((r_data & 0x03) == 0x01) + info->mode = ONLP_LED_MODE_GREEN; + else if((r_data & 0x03) == 0x02) + info->mode = ONLP_LED_MODE_RED; + } + else + info->mode = ONLP_LED_MODE_OFF; + break; + } +#endif /* Set the on/off status */ if (info->mode == ONLP_LED_MODE_OFF) info->status = ONLP_LED_STATUS_FAILED; @@ -335,164 +333,161 @@ int onlp_ledi_set(onlp_oid_t id, int on_or_off) * 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 rv = ONLP_STATUS_OK; +#ifdef I2C VALIDATE(id); int local_id = ONLP_OID_ID_GET(id); uint8_t front_panel_led_value = 0; uint8_t fan_tray_led_reg_value = 0; - if(dni_bmc_check() == BMC_ON) + switch(local_id) { - return ONLP_STATUS_OK; + case LED_FRONT_FAN: + front_panel_led_value = dni_lock_cpld_read_attribute(SWPLD1_PATH, SYS_LED_REGISTER); + front_panel_led_value &= ~0x03; + + if(mode == ONLP_LED_MODE_GREEN){ + front_panel_led_value |= 0x01; + } + else if(mode == ONLP_LED_MODE_YELLOW){ + front_panel_led_value |= 0x02; + } + else{ + front_panel_led_value = front_panel_led_value; + } + + if(dni_lock_cpld_write_attribute(SWPLD1_PATH, SYS_LED_REGISTER, front_panel_led_value) != 0){ + AIM_LOG_ERROR("Unable to set led(%d) status\r\n", local_id); + return ONLP_STATUS_E_INTERNAL; + } + break; + + case LED_FRONT_PWR: + front_panel_led_value = dni_lock_cpld_read_attribute(SWPLD1_PATH, SYS_LED_REGISTER); + front_panel_led_value &= ~0x0c; + + if(mode == ONLP_LED_MODE_GREEN){ + front_panel_led_value |= 0x04; + } + else if(mode == ONLP_LED_MODE_YELLOW){ + front_panel_led_value |= 0x08; + } + else{ + front_panel_led_value = front_panel_led_value; + } + if(dni_lock_cpld_write_attribute(SWPLD1_PATH, SYS_LED_REGISTER, front_panel_led_value) != 0){ + AIM_LOG_ERROR("Unable to set led(%d) status\r\n", local_id); + return ONLP_STATUS_E_INTERNAL; + } + break; + + case LED_FRONT_SYS: + front_panel_led_value = dni_lock_cpld_read_attribute(SWPLD1_PATH, SYS_LED_REGISTER); + front_panel_led_value &= ~0xf0; + + if(mode == ONLP_LED_MODE_YELLOW){ + front_panel_led_value |= 0x10; + } + else if(mode == ONLP_LED_MODE_GREEN){ + front_panel_led_value |= 0x20; + } + else if(mode == ONLP_LED_MODE_GREEN_BLINKING){ // 0.5S + front_panel_led_value |= 0x90; + } + else if(mode == ONLP_LED_MODE_YELLOW_BLINKING){ // 0.5S + front_panel_led_value |= 0xa0; + } + else{ + front_panel_led_value = front_panel_led_value; + } + if(dni_lock_cpld_write_attribute(SWPLD1_PATH, SYS_LED_REGISTER, front_panel_led_value) != 0){ + AIM_LOG_ERROR("Unable to set led(%d) status\r\n", local_id); + return ONLP_STATUS_E_INTERNAL; + } + break; + + case LED_REAR_FAN_TRAY_1: + fan_tray_led_reg_value = dni_lock_cpld_read_attribute(SWPLD1_PATH, FAN_LED_REGISTER); + fan_tray_led_reg_value &= ~0xc0; + + if(mode == ONLP_LED_MODE_GREEN){ + fan_tray_led_reg_value |= 0x40; + } + else if(mode == ONLP_LED_MODE_RED){ + fan_tray_led_reg_value |= 0x80; + } + else{ + fan_tray_led_reg_value = fan_tray_led_reg_value;; + } + + if(dni_lock_cpld_write_attribute(SWPLD1_PATH, FAN_LED_REGISTER, fan_tray_led_reg_value) != 0){ + AIM_LOG_ERROR("Unable to set led(%d) status\r\n", local_id); + return ONLP_STATUS_E_INTERNAL; + } + break; + + case LED_REAR_FAN_TRAY_2: + fan_tray_led_reg_value = dni_lock_cpld_read_attribute(SWPLD1_PATH, FAN_LED_REGISTER); + fan_tray_led_reg_value &= ~0x30; + + if(mode == ONLP_LED_MODE_GREEN){ + fan_tray_led_reg_value |= 0x10; + } + else if(mode == ONLP_LED_MODE_RED){ + fan_tray_led_reg_value |= 0x20; + } + else{ + fan_tray_led_reg_value = fan_tray_led_reg_value;; + } + + if(dni_lock_cpld_write_attribute(SWPLD1_PATH, FAN_LED_REGISTER, fan_tray_led_reg_value) != 0){ + AIM_LOG_ERROR("Unable to set led(%d) status\r\n", local_id); + return ONLP_STATUS_E_INTERNAL; + } + break; + + case LED_REAR_FAN_TRAY_3: + fan_tray_led_reg_value = dni_lock_cpld_read_attribute(SWPLD1_PATH, FAN_LED_REGISTER); + fan_tray_led_reg_value &= ~0x0c; + + if(mode == ONLP_LED_MODE_GREEN){ + fan_tray_led_reg_value |= 0x04; + } + else if(mode == ONLP_LED_MODE_RED){ + fan_tray_led_reg_value |= 0x08; + } + else{ + fan_tray_led_reg_value = fan_tray_led_reg_value;; + } + + if(dni_lock_cpld_write_attribute(SWPLD1_PATH, FAN_LED_REGISTER, fan_tray_led_reg_value) != 0){ + AIM_LOG_ERROR("Unable to set led(%d) status\r\n", local_id); + return ONLP_STATUS_E_INTERNAL; + } + break; + + case LED_REAR_FAN_TRAY_4: + fan_tray_led_reg_value = dni_lock_cpld_read_attribute(SWPLD1_PATH, FAN_LED_REGISTER); + fan_tray_led_reg_value &= ~0x03; + + if(mode == ONLP_LED_MODE_GREEN){ + fan_tray_led_reg_value |= 0x01; + } + else if(mode == ONLP_LED_MODE_RED){ + fan_tray_led_reg_value |= 0x02; + } + else{ + fan_tray_led_reg_value = fan_tray_led_reg_value;; + } + + if(dni_lock_cpld_write_attribute(SWPLD1_PATH, FAN_LED_REGISTER, fan_tray_led_reg_value) != 0){ + AIM_LOG_ERROR("Unable to set led(%d) status\r\n", local_id); + return ONLP_STATUS_E_INTERNAL; + } + break; } - else{ - switch(local_id) - { - case LED_FRONT_FAN: - front_panel_led_value = dni_lock_cpld_read_attribute(SWPLD1_PATH, SYS_LED_REGISTER); - front_panel_led_value &= ~0x03; - - if(mode == ONLP_LED_MODE_GREEN){ - front_panel_led_value |= 0x01; - } - else if(mode == ONLP_LED_MODE_YELLOW){ - front_panel_led_value |= 0x02; - } - else{ - front_panel_led_value = front_panel_led_value; - } - - if(dni_lock_cpld_write_attribute(SWPLD1_PATH, SYS_LED_REGISTER, front_panel_led_value) != 0){ - AIM_LOG_ERROR("Unable to set led(%d) status\r\n", local_id); - return ONLP_STATUS_E_INTERNAL; - } - break; - - case LED_FRONT_PWR: - front_panel_led_value = dni_lock_cpld_read_attribute(SWPLD1_PATH, SYS_LED_REGISTER); - front_panel_led_value &= ~0x0c; - - if(mode == ONLP_LED_MODE_GREEN){ - front_panel_led_value |= 0x04; - } - else if(mode == ONLP_LED_MODE_YELLOW){ - front_panel_led_value |= 0x08; - } - else{ - front_panel_led_value = front_panel_led_value; - } - if(dni_lock_cpld_write_attribute(SWPLD1_PATH, SYS_LED_REGISTER, front_panel_led_value) != 0){ - AIM_LOG_ERROR("Unable to set led(%d) status\r\n", local_id); - return ONLP_STATUS_E_INTERNAL; - } - break; - - case LED_FRONT_SYS: - front_panel_led_value = dni_lock_cpld_read_attribute(SWPLD1_PATH, SYS_LED_REGISTER); - front_panel_led_value &= ~0xf0; - - if(mode == ONLP_LED_MODE_YELLOW){ - front_panel_led_value |= 0x10; - } - else if(mode == ONLP_LED_MODE_GREEN){ - front_panel_led_value |= 0x20; - } - else if(mode == ONLP_LED_MODE_GREEN_BLINKING){ // 0.5S - front_panel_led_value |= 0x90; - } - else if(mode == ONLP_LED_MODE_YELLOW_BLINKING){ // 0.5S - front_panel_led_value |= 0xa0; - } - else{ - front_panel_led_value = front_panel_led_value; - } - if(dni_lock_cpld_write_attribute(SWPLD1_PATH, SYS_LED_REGISTER, front_panel_led_value) != 0){ - AIM_LOG_ERROR("Unable to set led(%d) status\r\n", local_id); - return ONLP_STATUS_E_INTERNAL; - } - break; - - case LED_REAR_FAN_TRAY_1: - fan_tray_led_reg_value = dni_lock_cpld_read_attribute(SWPLD1_PATH, FAN_LED_REGISTER); - fan_tray_led_reg_value &= ~0xc0; - - if(mode == ONLP_LED_MODE_GREEN){ - fan_tray_led_reg_value |= 0x40; - } - else if(mode == ONLP_LED_MODE_RED){ - fan_tray_led_reg_value |= 0x80; - } - else{ - fan_tray_led_reg_value = fan_tray_led_reg_value;; - } - - if(dni_lock_cpld_write_attribute(SWPLD1_PATH, FAN_LED_REGISTER, fan_tray_led_reg_value) != 0){ - AIM_LOG_ERROR("Unable to set led(%d) status\r\n", local_id); - return ONLP_STATUS_E_INTERNAL; - } - break; - - case LED_REAR_FAN_TRAY_2: - fan_tray_led_reg_value = dni_lock_cpld_read_attribute(SWPLD1_PATH, FAN_LED_REGISTER); - fan_tray_led_reg_value &= ~0x30; - - if(mode == ONLP_LED_MODE_GREEN){ - fan_tray_led_reg_value |= 0x10; - } - else if(mode == ONLP_LED_MODE_RED){ - fan_tray_led_reg_value |= 0x20; - } - else{ - fan_tray_led_reg_value = fan_tray_led_reg_value;; - } - - if(dni_lock_cpld_write_attribute(SWPLD1_PATH, FAN_LED_REGISTER, fan_tray_led_reg_value) != 0){ - AIM_LOG_ERROR("Unable to set led(%d) status\r\n", local_id); - return ONLP_STATUS_E_INTERNAL; - } - break; - - case LED_REAR_FAN_TRAY_3: - fan_tray_led_reg_value = dni_lock_cpld_read_attribute(SWPLD1_PATH, FAN_LED_REGISTER); - fan_tray_led_reg_value &= ~0x0c; - - if(mode == ONLP_LED_MODE_GREEN){ - fan_tray_led_reg_value |= 0x04; - } - else if(mode == ONLP_LED_MODE_RED){ - fan_tray_led_reg_value |= 0x08; - } - else{ - fan_tray_led_reg_value = fan_tray_led_reg_value;; - } - - if(dni_lock_cpld_write_attribute(SWPLD1_PATH, FAN_LED_REGISTER, fan_tray_led_reg_value) != 0){ - AIM_LOG_ERROR("Unable to set led(%d) status\r\n", local_id); - return ONLP_STATUS_E_INTERNAL; - } - break; - - case LED_REAR_FAN_TRAY_4: - fan_tray_led_reg_value = dni_lock_cpld_read_attribute(SWPLD1_PATH, FAN_LED_REGISTER); - fan_tray_led_reg_value &= ~0x03; - - if(mode == ONLP_LED_MODE_GREEN){ - fan_tray_led_reg_value |= 0x01; - } - else if(mode == ONLP_LED_MODE_RED){ - fan_tray_led_reg_value |= 0x02; - } - else{ - fan_tray_led_reg_value = fan_tray_led_reg_value;; - } - - if(dni_lock_cpld_write_attribute(SWPLD1_PATH, FAN_LED_REGISTER, fan_tray_led_reg_value) != 0){ - AIM_LOG_ERROR("Unable to set led(%d) status\r\n", local_id); - return ONLP_STATUS_E_INTERNAL; - } - break; - } - } - return ONLP_STATUS_OK; +#endif + return rv; } /* Generic LED ioctl interface. */ diff --git a/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/platform_lib.c b/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/platform_lib.c index 50e7de17..0085cddd 100755 --- a/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/platform_lib.c +++ b/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/platform_lib.c @@ -36,15 +36,18 @@ #include #include "platform_lib.h" #include +#include +#include +#include static onlp_shlock_t* dni_lock = NULL; -#define DNI_BUS_LOCK() \ +#define DNI_LOCK() \ do{ \ onlp_shlock_take(dni_lock); \ }while(0) -#define DNI_BUS_UNLOCK() \ +#define DNI_UNLOCK() \ do{ \ onlp_shlock_give(dni_lock); \ }while(0) @@ -61,74 +64,266 @@ void lockinit() } } -int dni_bmc_sensor_read(char *device_name, UINT4 *num, UINT4 multiplier) +#ifdef BMC +int dni_ipmi_data_time_check(long last_time, long new_time, int time_threshold) { - FILE *fpRead; - char Buf[10] = {0}; - char ipmi_command[120] = {0}; - int lenth = 10; - float num_f; + int ipmi_data_update = 0; - sprintf(ipmi_command, "ipmitool sdr get %s |grep 'Sensor Reading'| awk -F':' '{print $2}'| awk -F' ' '{ print $1}'", device_name); - fpRead = popen(ipmi_command, "r"); - - if(fpRead == NULL){ - pclose(fpRead); - return ONLP_STATUS_E_GENERIC; - } - fgets(Buf, lenth , fpRead); - num_f = atof(Buf); - *num = num_f * multiplier; - pclose(fpRead); - - return ONLP_STATUS_OK; -} - -int dni_bmc_check() -{ - char cmd[30] = {0}; - char str_data[100] = {0}; - FILE *fptr = NULL; - int rv = 0; - - sprintf(cmd, "ipmitool raw 0x38 0x1a 0x00"); - fptr = popen(cmd, "r"); - if(fptr != NULL) + if(last_time == 0) { - if(fgets(str_data, sizeof(str_data), fptr) != NULL) - rv = strtol(str_data, NULL, 16); - if(rv == 1) - rv = BMC_OFF; - else - rv = BMC_ON; + ipmi_data_update = 1; } else - rv = ONLP_STATUS_E_INVALID; - pclose(fptr); + { + if(new_time > last_time) + { + if((new_time - last_time) > time_threshold) + { + ipmi_data_update = 1; + } + else + ipmi_data_update = 0; + } + else if(new_time == last_time) + { + ipmi_data_update = 0; + } + else + { + ipmi_data_update = 1; + } + } + return ipmi_data_update; +} + +int dni_check_file_exist(char *file_path, long *file_time) +{ + struct stat file_info; + + if(stat(file_path, &file_info) == 0) + { + if(file_info.st_size == 0) + { + return 0; + } + else + { + *file_time = file_info.st_mtime; + return 1; + } + } + else + { + return 1; + } +} + +bmc_info_t dev[] = +{ + {"Fantray_1_1", 0}, + {"Fantray_1_2", 0}, + {"Fantray_1_3", 0}, + {"Fantray_1_4", 0}, + {"Fantray_2_1", 0}, + {"Fantray_2_2", 0}, + {"Fantray_2_3", 0}, + {"Fantray_2_4", 0}, + {"PSU1_Fan", 0}, + {"PSU2_Fan", 0}, + {"PSU1_Vin", 0}, + {"PSU1_Vout", 0}, + {"PSU1_Iin", 0}, + {"PSU1_Iout", 0}, + {"PSU1_Pin",0}, + {"PSU1_Pout",0}, + {"PSU2_Vin", 0}, + {"PSU2_Vout", 0}, + {"PSU2_Iin", 0}, + {"PSU2_Iout", 0}, + {"PSU2_Pin",0}, + {"PSU2_Pout",0}, + {"Fan_Temp", 0}, + {"Temp_Sensor_1", 0}, + {"Temp_Sensor_2", 0}, + {"Temp_Sensor_3", 0}, + {"Temp_Sensor_4", 0}, + {"Temp_Sensor_5", 0}, + {"Temp_Sensor_6", 0}, + {"Temp_Sensor_7", 0}, + {"Temp_Sensor_8", 0}, + {"PSU1_Temp_1", 0}, + {"PSU2_Temp_1", 0} +}; + +check_time_t bmc_check = {0}; + +int dni_bmc_sensor_read(char *device_name, UINT4 *num, UINT4 multiplier, int sensor_type) +{ + struct timeval new_tv; + FILE *fpRead = NULL; + char ipmi_cmd[120] = {0}; + char get_data_cmd[120] = {0}; + char Buf[10]; + int rv = ONLP_STATUS_OK; + int dev_num = 0; + int time_threshold = 0; + int ipmi_data_update = 0; + float num_f = 0; + long file_last_time = 0; + + switch(sensor_type) + { + case FAN_SENSOR: + time_threshold = FAN_TIME_THRESHOLD; + break; + case PSU_SENSOR: + time_threshold = PSU_TIME_THRESHOLD; + break; + case THERMAL_SENSOR: + time_threshold = THERMAL_TIME_THRESHOLD; + break; + } + + if(dni_check_file_exist(BMC_INFO_TABLE, &file_last_time)) + { + gettimeofday(&new_tv,NULL); + if(dni_ipmi_data_time_check(file_last_time, new_tv.tv_sec, time_threshold)) + { + ipmi_data_update = 1; + } + else + { + ipmi_data_update = 0; + } + } + else + { + ipmi_data_update = 1; + } + + if(bmc_check.time == 0 && dni_check_file_exist(BMC_INFO_TABLE, &file_last_time)) + { + ipmi_data_update = 1; + gettimeofday(&new_tv,NULL); + bmc_check.time = new_tv.tv_sec; + } + + if(ipmi_data_update == 1) + { + DNI_LOCK(); + if(dni_ipmi_data_time_check(file_last_time, bmc_check.time, time_threshold)) + { + sprintf(ipmi_cmd, "ipmitool sdr > /tmp/bmc_info"); + system(ipmi_cmd); + } + + for(dev_num = 0; dev_num < DEV_NUM; dev_num++) + { + memset(Buf, 0, sizeof(Buf)); + sprintf(get_data_cmd, "cat /tmp/bmc_info | grep %s | awk -F'|' '{print $2}' | awk -F' ' '{ print $1}'", dev[dev_num].tag); + fpRead = popen(get_data_cmd, "r"); + if(fpRead != NULL) + { + if(fgets(Buf, sizeof(Buf), fpRead) != NULL) + { + num_f = atof(Buf); + dev[dev_num].data = num_f; + } + } + pclose(fpRead); + } + gettimeofday(&new_tv,NULL); + bmc_check.time = new_tv.tv_sec; + DNI_UNLOCK(); + } + + for(dev_num = 0; dev_num < DEV_NUM; dev_num++) + { + if(strstr(dev[dev_num].tag, device_name) != NULL) + { + *num = dev[dev_num].data * multiplier; + rv = ONLP_STATUS_OK; + goto END; + } + } +END: return rv; } -int dni_bmc_data_get(int bus, int addr, int reg, int len, int *r_data) +swpld_info_t swpld_table[]= { - int rv = ONLP_STATUS_OK; - char cmd[50] = {0}; - char rdata[10] = {0}; - FILE *fptr = NULL; + {"SWPLD_1", 0x6a, 0}, + {"SWPLD_2", 0x75, 0}, +}; - sprintf(cmd, "ipmitool raw 0x38 0x2 %d 0x%x 0x%x %d", bus ,addr, reg, len); - fptr = popen(cmd, "r"); - if(fptr != NULL) +int dni_bmc_data_get(int bus, int addr, int reg, int *r_data) +{ + char cmd[120] = {0}; + char data_path[120] = {0}; + char file_path[120] = {0}; + char buf[10] = {0}; + struct timeval new_tv; + int rv = ONLP_STATUS_OK; + int ipmi_data_update = 0; + int swpld_num = 0; + int div_val = 0; + int rem_val = 0; + int dis_val = 0; + long file_last_time = 0; + FILE *fp = NULL; + + div_val = (reg / 16); + rem_val = (reg % 16); + dis_val = (div_val * 45) + (div_val * 3) + div_val + 1 + (rem_val * 3); + + gettimeofday(&new_tv,NULL); + + for(swpld_num = 0; swpld_num < 2; swpld_num++) { - if(fgets(rdata, sizeof(rdata), fptr) != NULL) - *r_data = strtol(rdata, NULL, 16); + if(swpld_table[swpld_num].addr == addr) + { + break; + } + } + sprintf(file_path, "/tmp/%s_data", swpld_table[swpld_num].name); + if(dni_check_file_exist(file_path, &file_last_time)) + { + gettimeofday(&new_tv,NULL); + if(dni_ipmi_data_time_check(file_last_time, new_tv.tv_sec, SWPLD_DATA_TIME_THRESHOLD)) + { + ipmi_data_update = 1; + } else - rv = ONLP_STATUS_E_INVALID; + { + ipmi_data_update = 0; + } } else - rv = ONLP_STATUS_E_INVALID; - pclose(fptr); + { + ipmi_data_update = 1; + } + if(ipmi_data_update == 1) + { + DNI_LOCK(); + swpld_table[swpld_num].time = new_tv.tv_sec; + sprintf(cmd, "ipmitool raw 0x38 0x2 %d 0x%x 0x00 255 > /tmp/%s_data", bus, addr, swpld_table[swpld_num].name); + system(cmd); + DNI_UNLOCK(); + } + + sprintf(data_path, "/tmp/%s_data",swpld_table[swpld_num].name); + fp = fopen(data_path,"r"); + if(fp != NULL) + { + fseek(fp, dis_val, SEEK_SET); + if(fgets(buf, 4, fp) != NULL) + { + *r_data = strtol(buf, NULL, 16); + } + } + pclose(fp); return rv; } @@ -138,6 +333,7 @@ int dni_bmc_data_set(int bus, int addr, int reg, uint8_t w_data) char cmd[50] = {0}; FILE *fptr = NULL; + DNI_LOCK(); sprintf(cmd, "ipmitool raw 0x38 0x3 %d 0x%x 0x%x %d > /dev/null", bus, addr, reg, w_data); fptr = popen(cmd, "w"); if(fptr != NULL) @@ -145,33 +341,164 @@ int dni_bmc_data_set(int bus, int addr, int reg, uint8_t w_data) else rv = ONLP_STATUS_E_INVALID; pclose(fptr); - + DNI_UNLOCK(); return rv; } -int dni_bmc_fanpresent_info_get(int *r_data) -{ - int rv = ONLP_STATUS_OK; - char cmd[30] = {0}; - char str_data[100] = {0}; - FILE *fptr = NULL; +platform_info_t fan = {0, 0}; - sprintf(cmd, "ipmitool raw 0x38 0x0e"); - fptr = popen(cmd, "r"); - if(fptr != NULL) +int dni_bmc_fanpresent_info_get(uint8_t *fan_present_bit) +{ + int ipmi_data_update = 0; + int rv = ONLP_STATUS_OK; + char fanpresent_cmd[120] = {0}; + char str_data[100] = {0}; + long present_bit = 0; + FILE *fptr = NULL; + struct timeval new_tv; + + gettimeofday(&new_tv,NULL); + + ipmi_data_update = dni_ipmi_data_time_check(fan.time, new_tv.tv_sec, FAN_TIME_THRESHOLD); + + if(ipmi_data_update == 1) { - if(fgets(str_data, sizeof(str_data), fptr) != NULL) - *r_data = strtol(str_data, NULL, 16); + DNI_LOCK(); + fan.time = new_tv.tv_sec; + sprintf(fanpresent_cmd, "ipmitool raw 0x38 0x0e"); + fptr = popen(fanpresent_cmd, "r"); + if(fptr != NULL) + { + if(fgets(str_data, sizeof(str_data), fptr) != NULL) + { + present_bit = strtol(str_data, NULL, 16); + fan.data = present_bit; + } + else + rv = ONLP_STATUS_E_INVALID; + } else rv = ONLP_STATUS_E_INVALID; + pclose(fptr); + DNI_UNLOCK(); } - else - rv = ONLP_STATUS_E_INVALID; - pclose(fptr); + *fan_present_bit = fan.data; return rv; } +onlp_psu_dev_t psu_eeprom_info_table[] = +{ + { + { + {"Product Name", {0}}, + {"Product Serial", {0}} + } + }, + { + { + {"Product Name", {0}}, + {"Product Serial", {0}} + } + } +}; + +check_time_t psu_eeprom_check = {0}; + +int dni_bmc_psueeprom_info_get(char * r_data, char *device_name, int number) +{ + struct timeval new_tv; + int psu_num = 0; + int table_num = 0; + int chr_num = 0; + int rv = ONLP_STATUS_OK; + int ipmi_data_update = 0; + long file_last_time = 0; + FILE *fptr = NULL; + char cmd[120] = {0}; + char get_cmd[120] = {0}; + char file_path[120] = {0}; + char buf; + char* renewCh; + + gettimeofday(&new_tv,NULL); + sprintf(file_path, "/tmp/psu%d_eeprom", number); + if(dni_check_file_exist(file_path, &file_last_time)) + { + gettimeofday(&new_tv,NULL); + if(dni_ipmi_data_time_check(file_last_time, new_tv.tv_sec, PSU_EEPROM_TIME_THRESHOLD)) + { + ipmi_data_update = 1; + } + else + { + ipmi_data_update = 0; + } + } + else + { + ipmi_data_update = 1; + } + + if(psu_eeprom_check.time == 0 && dni_check_file_exist(file_path, &file_last_time))/*onlpdump*/ + { + ipmi_data_update = 1; + gettimeofday(&new_tv,NULL); + psu_eeprom_check.time = new_tv.tv_sec; + } + + if(ipmi_data_update == 1) + { + DNI_LOCK(); + if(dni_ipmi_data_time_check(file_last_time, psu_eeprom_check.time, PSU_EEPROM_TIME_THRESHOLD)) + { + for(psu_num = 1; psu_num < 3; psu_num++) + { + sprintf(cmd, "ipmitool fru print %d > /tmp/psu%d_eeprom", psu_num, psu_num); + system(cmd); + } + } + + for(psu_num = 1; psu_num < 3; psu_num++) + { + for(table_num = 0; table_num < 2 ; table_num++) + { + sprintf(get_cmd, "cat /tmp/psu%d_eeprom | grep '%s' | awk -F':' '{print $2}'", psu_num, psu_eeprom_info_table[psu_num-1].psu_eeprom_table[table_num].tag); + fptr = popen(get_cmd, "r"); + while((buf = fgetc(fptr)) != EOF) + { + if(buf != ' ') + { + psu_eeprom_info_table[psu_num-1].psu_eeprom_table[table_num].data[chr_num] = buf; + chr_num++; + } + } + chr_num = 0; + pclose(fptr); + + } + } + psu_eeprom_check.time = new_tv.tv_sec; + DNI_UNLOCK(); + } + for(table_num = 0; table_num < 2 ; table_num++) + { + if(strstr(psu_eeprom_info_table[number - 1].psu_eeprom_table[table_num].tag, device_name) != NULL) + { + for(chr_num = 0; chr_num < PSU_NUM_LENGTH; chr_num++) + { + r_data[chr_num] = psu_eeprom_info_table[number - 1].psu_eeprom_table[table_num].data[chr_num]; + } + renewCh = strstr(r_data,"\n"); + if(renewCh) + *renewCh= '\0'; + goto END; + } + } +END: + return rv; +} +#endif int hex_to_int(char hex_input) { int first = hex_input / 16 - 3; @@ -190,84 +517,30 @@ int hex_to_ascii(char hex_high, char hex_low) return high + low; } -int dni_psu_present(int *r_data) -{ - FILE *fptr = NULL; - int rv = ONLP_STATUS_OK; - char cmd[35] = {0}; - char str_data[50] = {0}; - - sprintf(cmd, "ipmitool raw 0x38 0x2 2 0x6a 0x0d 1"); - fptr = popen(cmd, "r"); - if(fptr != NULL) - { - if(fgets(str_data, sizeof(str_data), fptr) != NULL) - *r_data = strtol(str_data, NULL, 16); - else - rv = ONLP_STATUS_E_INVALID; - } - else - rv = ONLP_STATUS_E_INVALID; - pclose(fptr); - - return rv; -} - -int dni_psui_eeprom_info_get(char * r_data, char *device_name, int number) -{ - int i = 0; - int rv = ONLP_STATUS_OK; - FILE *fptr = NULL; - char cmd[35] = {0}; - char str_data[50] = {0}; - char buf; - char* renewCh; - - sprintf(cmd, "ipmitool fru print %d | grep '%s' | awk -F':' '{print $2}'",number,device_name); - fptr = popen(cmd, "r"); - while((buf = fgetc(fptr)) != EOF) - { - if(buf != ' ') - { - str_data[i] = buf; - i++; - } - } - for(i = 0; i < PSU_NUM_LENGTH; i++) - r_data[i] = str_data[i]; - pclose(fptr); - - renewCh = strstr(r_data,"\n"); - if(renewCh) - *renewCh= '\0'; - - return rv; -} - int dni_i2c_lock_read(mux_info_t * mux_info, dev_info_t * dev_info) { int r_data = 0; - DNI_BUS_LOCK(); + DNI_LOCK(); if(dev_info->size == 1) r_data = onlp_i2c_readb(dev_info->bus, dev_info->addr, dev_info->offset, dev_info->flags); else r_data = onlp_i2c_readw(dev_info->bus, dev_info->addr, dev_info->offset, dev_info->flags); - DNI_BUS_UNLOCK(); + DNI_UNLOCK(); return r_data; } int dni_i2c_lock_write(mux_info_t * mux_info, dev_info_t * dev_info) { - DNI_BUS_LOCK(); + DNI_LOCK(); /* Write size */ if(dev_info->size == 1) onlp_i2c_write(dev_info->bus, dev_info->addr, dev_info->offset, 1, &dev_info->data_8, dev_info->flags); else onlp_i2c_writew(dev_info->bus, dev_info->addr, dev_info->offset, dev_info->data_16, dev_info->flags); - DNI_BUS_UNLOCK(); + DNI_UNLOCK(); return 0; } @@ -276,14 +549,14 @@ int dni_i2c_lock_read_attribute(mux_info_t * mux_info, char * fullpath) int fd, nbytes = 10, rv = -1; char r_data[10] = {0}; - DNI_BUS_LOCK(); + DNI_LOCK(); if ((fd = open(fullpath, O_RDONLY)) >= 0) { if ((read(fd, r_data, nbytes)) > 0) rv = atoi(r_data); } close(fd); - DNI_BUS_UNLOCK(); + DNI_UNLOCK(); return rv; } @@ -291,7 +564,7 @@ int dni_i2c_lock_write_attribute(mux_info_t * mux_info, char * data,char * fullp { int fd, rv = -1; - DNI_BUS_LOCK(); + DNI_LOCK(); /* Create output file descriptor */ if ((fd = open(fullpath, O_WRONLY, 0644)) >= 0) { @@ -302,7 +575,7 @@ int dni_i2c_lock_write_attribute(mux_info_t * mux_info, char * data,char * fullp } } close(fd); - DNI_BUS_UNLOCK(); + DNI_UNLOCK(); return rv; } @@ -318,7 +591,7 @@ int dni_lock_cpld_read_attribute(char *cpld_path, int addr) sprintf(cpld_data_path, "%s/swpld1_reg_value", cpld_path); sprintf(cpld_addr_path, "%s/swpld1_reg_addr", cpld_path); sprintf(address, "0x%02x", addr); - DNI_BUS_LOCK(); + DNI_LOCK(); /* Create output file descriptor */ if ((fd = open(cpld_addr_path, O_WRONLY, 0644)) >= 0) { @@ -337,7 +610,7 @@ int dni_lock_cpld_read_attribute(char *cpld_path, int addr) } } close(fd); - DNI_BUS_UNLOCK(); + DNI_UNLOCK(); return rv; } @@ -353,7 +626,7 @@ int dni_lock_cpld_write_attribute(char *cpld_path, int addr, int data) sprintf(cpld_data_path, "%s/swpld1_reg_value", cpld_path); sprintf(cpld_addr_path, "%s/swpld1_reg_addr", cpld_path); sprintf(address, "0x%02x", addr); - DNI_BUS_LOCK(); + DNI_LOCK(); /* Create output file descriptor */ if ((fd = open(cpld_addr_path, O_WRONLY, 0644)) >= 0) { @@ -373,57 +646,51 @@ int dni_lock_cpld_write_attribute(char *cpld_path, int addr, int data) } } close(fd); - DNI_BUS_UNLOCK(); + DNI_UNLOCK(); return rv; } int dni_fan_present(int id) { int rv; - int bit_data = 0; +#ifdef BMC + uint8_t bit_data = 0; int data = 0; uint8_t present_bit = 0x00; - int fantray_present = -1; - if(dni_bmc_check() == BMC_ON) + rv = dni_bmc_fanpresent_info_get(&bit_data); + if(rv == ONLP_STATUS_OK) { - rv = dni_bmc_fanpresent_info_get(&bit_data); - if(rv == ONLP_STATUS_OK) - { - present_bit = bit_data; - data = (present_bit & (1 << -(id - NUM_OF_LED_ON_MAIN_BROAD))); - if(data == 0) - rv = ONLP_STATUS_OK; - else - rv = ONLP_STATUS_E_INVALID; - } - else - rv = ONLP_STATUS_E_INVALID; - } - else if(dni_bmc_check() == BMC_OFF) - { - switch(id) { - case LED_REAR_FAN_TRAY_1: - fantray_present = dni_i2c_lock_read_attribute(NULL, FAN1_PRESENT_PATH); - break; - case LED_REAR_FAN_TRAY_2: - fantray_present = dni_i2c_lock_read_attribute(NULL, FAN2_PRESENT_PATH); - break; - case LED_REAR_FAN_TRAY_3: - fantray_present = dni_i2c_lock_read_attribute(NULL, FAN3_PRESENT_PATH); - break; - case LED_REAR_FAN_TRAY_4: - fantray_present = dni_i2c_lock_read_attribute(NULL, FAN4_PRESENT_PATH); - break; - } - if(fantray_present == 0) + present_bit = bit_data; + data = (present_bit & (1 << -(id - NUM_OF_LED_ON_MAIN_BROAD))); + if(data == 0) rv = ONLP_STATUS_OK; - else if(fantray_present == 1) + else rv = ONLP_STATUS_E_INVALID; } else - rv = ONLP_STATUS_E_INVALID; - + rv = ONLP_STATUS_E_INVALID; +#elif defined I2C + int fantray_present = -1; + switch(id) { + case LED_REAR_FAN_TRAY_1: + fantray_present = dni_i2c_lock_read_attribute(NULL, FAN1_PRESENT_PATH); + break; + case LED_REAR_FAN_TRAY_2: + fantray_present = dni_i2c_lock_read_attribute(NULL, FAN2_PRESENT_PATH); + break; + case LED_REAR_FAN_TRAY_3: + fantray_present = dni_i2c_lock_read_attribute(NULL, FAN3_PRESENT_PATH); + break; + case LED_REAR_FAN_TRAY_4: + fantray_present = dni_i2c_lock_read_attribute(NULL, FAN4_PRESENT_PATH); + break; + } + if(fantray_present == 0) + rv = ONLP_STATUS_OK; + else if(fantray_present == 1) + rv = ONLP_STATUS_E_INVALID; +#endif return rv; } @@ -458,7 +725,7 @@ int dni_i2c_read_attribute_binary(char *filename, char *buffer, int buf_size, in { int fd, rv = 0; int len; - DNI_BUS_LOCK(); + DNI_LOCK(); if ((buffer == NULL) || (buf_size < 0)) { rv = -1; @@ -487,7 +754,7 @@ int dni_i2c_read_attribute_binary(char *filename, char *buffer, int buf_size, in } ERROR: - DNI_BUS_UNLOCK(); + DNI_UNLOCK(); return rv; } diff --git a/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/platform_lib.h b/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/platform_lib.h index bfe93522..3b9d15ad 100755 --- a/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/platform_lib.h +++ b/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/platform_lib.h @@ -30,6 +30,9 @@ #include #include +#define BMC +//#define I2C + typedef unsigned int UINT4; /* CPLD numbrt & peripherals */ @@ -56,6 +59,12 @@ typedef unsigned int UINT4; #define BMC_OFF (1) #define BMC_ON (0) #define PSU_NODE_MAX_PATH_LEN (64) +#define FAN_TIME_THRESHOLD (5) +#define PSU_TIME_THRESHOLD (5) +#define THERMAL_TIME_THRESHOLD (10) +#define PSU_EEPROM_TIME_THRESHOLD (10) +#define SWPLD_DATA_TIME_THRESHOLD (5) +#define DEV_NUM (33) #define CPU_CPLD_VERSION "/sys/devices/platform/delta-agc7648sv1-cpld.0/cpuld_ver" #define IDPROM_PATH "/sys/class/i2c-adapter/i2c-1/1-0053/eeprom" @@ -89,6 +98,8 @@ typedef unsigned int UINT4; #define FAN4_PRESENT_PATH "/sys/class/gpio/gpio496/value" #define PSU1_PRESENT_PATH "/sys/devices/platform/delta-agc7648sv1-swpld1.0/psu1_present" #define PSU2_PRESENT_PATH "/sys/devices/platform/delta-agc7648sv1-swpld1.0/psu2_present" +#define CHECK_TIME_FILE "/tmp/check_time_file" +#define BMC_INFO_TABLE "/tmp/bmc_info" /* REG define */ #define SWPLD_1_ADDR (0x6A) @@ -105,6 +116,7 @@ typedef unsigned int UINT4; #define POWER_STATUS_REGISTER (0x0B) #define POWER_INT_REGISTER (0x0E) #define DEFAULT_FLAG (0x00) +#define PSU_REGISTER (0x0D) /* BMC BUS define */ #define BMC_SWPLD_BUS (2) @@ -167,21 +179,54 @@ typedef struct dev_info_s }dev_info_t; +typedef struct swpld_info_s +{ + char name[20]; + uint8_t addr; + long time; +}swpld_info_t; + +typedef struct check_time_s +{ + long time; +}check_time_t; + +typedef struct platform_info_s +{ + uint8_t data; + long time; +}platform_info_t; + +typedef struct bmc_info_s +{ + char tag[20]; + float data; +}bmc_info_t; + +typedef struct eeprom_info_s +{ + char tag[20]; + char data[20]; +}eeprom_info_t; + +typedef struct onlp_psu_dev_s +{ + eeprom_info_t psu_eeprom_table[2]; +}onlp_psu_dev_t; + int dni_i2c_read_attribute_binary(char *filename, char *buffer, int buf_size, int data_len); int dni_lock_cpld_write_attribute(char *cpld_path, int addr, int data); int dni_lock_cpld_read_attribute(char *cpld_path, int addr); int dni_fan_present(int id); int dni_fan_speed_good(); int dni_i2c_read_attribute_string(char *filename, char *buffer, int buf_size, int data_len); -int dni_bmc_sensor_read(char *device_name, UINT4 *num, UINT4 multiplier); -int dni_psui_eeprom_info_get(char *r_data,char *device_name,int number); -int dni_bmc_check(); -int dni_bmc_fanpresent_info_get(int *r_data); +int dni_bmc_sensor_read(char *device_name, UINT4 *num, UINT4 multiplier, int sensor_type); +int dni_bmc_psueeprom_info_get(char *r_data,char *device_name,int number); +int dni_bmc_fanpresent_info_get(uint8_t *fan_present_bit); int dni_i2c_lock_read( mux_info_t * mux_info, dev_info_t * dev_info); int dni_i2c_lock_read_attribute(mux_info_t * mux_info, char * fullpath); int dni_i2c_lock_write_attribute(mux_info_t * mux_info, char * data,char * fullpath); -int dni_psu_present(int *r_data); -int dni_bmc_data_get(int bus, int addr, int reg, int len, int *r_data); +int dni_bmc_data_get(int bus, int addr, int reg, int *r_data); int dni_bmc_data_set(int bus, int addr, int reg, uint8_t w_data); void lockinit(); @@ -255,5 +300,13 @@ enum bus I2C_BUS_31 = 31, I2C_BUS_32 }; + +enum sensor +{ + FAN_SENSOR = 0, + PSU_SENSOR, + THERMAL_SENSOR, +}; + #endif /* __PLATFORM_LIB_H__ */ diff --git a/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/psui.c b/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/psui.c index d4283b4e..a3fe7bc7 100755 --- a/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/psui.c +++ b/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/psui.c @@ -49,6 +49,7 @@ static onlp_psu_info_t pinfo[] = } }; +#ifdef I2C static int dni_psu_pmbus_info_get(int id, char *node, int *value) { int ret = ONLP_STATUS_OK; @@ -56,7 +57,8 @@ static int dni_psu_pmbus_info_get(int id, char *node, int *value) *value = 0; - switch (id) { + switch(id) + { case PSU1_ID: sprintf(node_path, "%s%s", PSU1_AC_PMBUS_PREFIX, node); break; @@ -71,6 +73,7 @@ static int dni_psu_pmbus_info_get(int id, char *node, int *value) return ret; } +#endif int onlp_psui_init(void) { @@ -80,19 +83,8 @@ int onlp_psui_init(void) static int dni_psu_info_get(onlp_oid_t id, onlp_psu_info_t* info) { - int i = 0; int ret = ONLP_STATUS_OK; int local_id; - char device_name[10] = {0}; - UINT4 u4Data = 0; - UINT4 multiplier = 1000; - char name[20] = {0}; - char name1[20] = {0}; - char *module_name = name; - char *module_name1 = name1; - int val = 0; - char val_char[16] = {'\0'}; - char node_path[PSU_NODE_MAX_PATH_LEN] = {'\0'}; local_id = ONLP_OID_ID_GET(info->hdr.id); @@ -100,210 +92,236 @@ static int dni_psu_info_get(onlp_oid_t id, onlp_psu_info_t* info) * Set PSU's fan and thermal to child OID */ info->hdr.coids[0] = ONLP_FAN_ID_CREATE(local_id + CHASSIS_FAN_COUNT); info->hdr.coids[1] = ONLP_THERMAL_ID_CREATE(local_id + CHASSIS_THERMAL_COUNT); - if(dni_bmc_check() == BMC_ON) +#ifdef BMC + int i = 0; + char device_name[10] = {0}; + UINT4 u4Data = 0; + UINT4 multiplier = 1000; + char name[20] = {0}; + char name1[20] = {0}; + char *module_name = name; + char *module_name1 = name1; + + + /* get psu model name */ + if(dni_bmc_psueeprom_info_get(name, "Product Name", local_id) == ONLP_STATUS_OK) { - /* get psu model name */ - if(dni_psui_eeprom_info_get(name, "Product Name", local_id) == ONLP_STATUS_OK) - { - for(i = 0; i < PSU_NUM_LENGTH; i++) - name[i] = *(module_name + i); - strcpy(info->model, module_name); - } - else - strcpy(info->model, "ONLP_STATUS_E_UNSUPPORTED"); - - /* get psu serial number */ - if(dni_psui_eeprom_info_get(name1, "Product Serial", local_id) == ONLP_STATUS_OK) - { - for(i = 0; i < PSU_NUM_LENGTH; i++) - name1[i] = *(module_name1 + i); - strcpy(info->serial, module_name1); - } - else - strcpy(info->serial, "ONLP_STATUS_E_UNSUPPORTED"); - - /* get psu Vin/Vout */ - sprintf(device_name, "PSU%d_Vin", local_id); - if(dni_bmc_sensor_read(device_name, &u4Data, multiplier) == ONLP_STATUS_OK) - { - info->mvin = u4Data; - info->status = ONLP_PSU_STATUS_PRESENT; - info->caps |= ONLP_PSU_CAPS_VIN; - } - else - info->caps |= ONLP_PSU_STATUS_UNPLUGGED; - - sprintf(device_name, "PSU%d_Vout", local_id); - if(dni_bmc_sensor_read(device_name, &u4Data, multiplier) == ONLP_STATUS_OK) - { - info->mvout = u4Data; - info->status = ONLP_PSU_STATUS_PRESENT; - info->caps |= ONLP_PSU_CAPS_VOUT; - } - else - info->caps |= ONLP_PSU_STATUS_UNPLUGGED; - - /* get psu Iin/Iout */ - sprintf(device_name, "PSU%d_Iin", local_id); - if(dni_bmc_sensor_read(device_name, &u4Data, multiplier) == ONLP_STATUS_OK) - { - info->miin = u4Data; - info->status = ONLP_PSU_STATUS_PRESENT; - info->caps |= ONLP_PSU_CAPS_IIN; - } - else - info->caps |= ONLP_PSU_STATUS_UNPLUGGED; - - sprintf(device_name, "PSU%d_Iout", local_id); - if(dni_bmc_sensor_read(device_name, &u4Data, multiplier) == ONLP_STATUS_OK) - { - info->miout = u4Data; - info->status = ONLP_PSU_STATUS_PRESENT; - info->caps |= ONLP_PSU_CAPS_IOUT; - } - else - info->caps |= ONLP_PSU_STATUS_UNPLUGGED; - - /* get psu Pin/Pout */ - sprintf(device_name, "PSU%d_Pin", local_id); - if(dni_bmc_sensor_read(device_name, &u4Data, multiplier) == ONLP_STATUS_OK) - { - info->mpin = u4Data; - info->status = ONLP_PSU_STATUS_PRESENT; - info->caps |= ONLP_PSU_CAPS_PIN; - } - else - info->caps |= ONLP_PSU_STATUS_UNPLUGGED; - - sprintf(device_name, "PSU%d_Pout", local_id); - if(dni_bmc_sensor_read(device_name, &u4Data, multiplier) == ONLP_STATUS_OK) - { - info->mpout = u4Data; - info->status = ONLP_PSU_STATUS_PRESENT; - info->caps |= ONLP_PSU_CAPS_POUT; - } - else - info->caps |= ONLP_PSU_STATUS_UNPLUGGED; - } - else - { - int index = ONLP_OID_ID_GET(info->hdr.id); - - /* Read PSU product name from attribute */ - sprintf(node_path, "%s%s", PSU1_AC_PMBUS_PREFIX, "psu_mfr_model"); - dni_i2c_read_attribute_string(node_path, val_char, sizeof(val_char), 0); - strcpy(info->model, val_char); - - /* Read PSU serial number from attribute */ - sprintf(node_path, "%s%s", PSU1_AC_PMBUS_PREFIX, "psu_mfr_serial"); - dni_i2c_read_attribute_string(node_path, val_char, sizeof(val_char), 0); - strcpy(info->serial, val_char); - - /* Read voltage, current and power */ - if (dni_psu_pmbus_info_get(index, "psu_v_in", &val) == 0) - { - info->mvin = val; - info->caps |= ONLP_PSU_CAPS_VIN; - } - - if (dni_psu_pmbus_info_get(index, "psu_v_out", &val) == 0) - { - info->mvout = val; - info->caps |= ONLP_PSU_CAPS_VOUT; - } - - if (dni_psu_pmbus_info_get(index, "psu_i_in", &val) == 0) - { - info->miin = val; - info->caps |= ONLP_PSU_CAPS_IIN; - } - - if (dni_psu_pmbus_info_get(index, "psu_i_out", &val) == 0) - { - info->miout = val; - info->caps |= ONLP_PSU_CAPS_IOUT; - } - - if (dni_psu_pmbus_info_get(index, "psu_p_in", &val) == 0) - { - info->mpin = val; - info->caps |= ONLP_PSU_CAPS_PIN; - } - - if (dni_psu_pmbus_info_get(index, "psu_p_out", &val) == 0) - { - info->mpout = val; - info->caps |= ONLP_PSU_CAPS_POUT; - } + for(i = 0; i < PSU_NUM_LENGTH; i++) + name[i] = *(module_name + i); + strcpy(info->model, module_name); } + else + strcpy(info->model, "ONLP_STATUS_E_UNSUPPORTED"); + + /* get psu serial number */ + if(dni_bmc_psueeprom_info_get(name1, "Product Serial", local_id) == ONLP_STATUS_OK) + { + for(i = 0; i < PSU_NUM_LENGTH; i++) + name1[i] = *(module_name1 + i); + strcpy(info->serial, module_name1); + } + else + strcpy(info->serial, "ONLP_STATUS_E_UNSUPPORTED"); + + /* get psu Vin/Vout */ + sprintf(device_name, "PSU%d_Vin", local_id); + if(dni_bmc_sensor_read(device_name, &u4Data, multiplier, PSU_SENSOR) == ONLP_STATUS_OK) + { + info->mvin = u4Data; + info->status = ONLP_PSU_STATUS_PRESENT; + info->caps |= ONLP_PSU_CAPS_VIN; + } + else + info->caps |= ONLP_PSU_STATUS_UNPLUGGED; + + sprintf(device_name, "PSU%d_Vout", local_id); + if(dni_bmc_sensor_read(device_name, &u4Data, multiplier, PSU_SENSOR) == ONLP_STATUS_OK) + { + info->mvout = u4Data; + info->status = ONLP_PSU_STATUS_PRESENT; + info->caps |= ONLP_PSU_CAPS_VOUT; + } + else + info->caps |= ONLP_PSU_STATUS_UNPLUGGED; + + /* get psu Iin/Iout */ + sprintf(device_name, "PSU%d_Iin", local_id); + if(dni_bmc_sensor_read(device_name, &u4Data, multiplier, PSU_SENSOR) == ONLP_STATUS_OK) + { + info->miin = u4Data; + info->status = ONLP_PSU_STATUS_PRESENT; + info->caps |= ONLP_PSU_CAPS_IIN; + } + else + info->caps |= ONLP_PSU_STATUS_UNPLUGGED; + + sprintf(device_name, "PSU%d_Iout", local_id); + if(dni_bmc_sensor_read(device_name, &u4Data, multiplier, PSU_SENSOR) == ONLP_STATUS_OK) + { + info->miout = u4Data; + info->status = ONLP_PSU_STATUS_PRESENT; + info->caps |= ONLP_PSU_CAPS_IOUT; + } + else + info->caps |= ONLP_PSU_STATUS_UNPLUGGED; + + /* get psu Pin/Pout */ + sprintf(device_name, "PSU%d_Pin", local_id); + if(dni_bmc_sensor_read(device_name, &u4Data, multiplier, PSU_SENSOR) == ONLP_STATUS_OK) + { + info->mpin = u4Data; + info->status = ONLP_PSU_STATUS_PRESENT; + info->caps |= ONLP_PSU_CAPS_PIN; + } + else + info->caps |= ONLP_PSU_STATUS_UNPLUGGED; + + sprintf(device_name, "PSU%d_Pout", local_id); + if(dni_bmc_sensor_read(device_name, &u4Data, multiplier, PSU_SENSOR) == ONLP_STATUS_OK) + { + info->mpout = u4Data; + info->status = ONLP_PSU_STATUS_PRESENT; + info->caps |= ONLP_PSU_CAPS_POUT; + } + else + info->caps |= ONLP_PSU_STATUS_UNPLUGGED; + +#elif defined I2C + int val = 0; + char val_char[15] = {'\0'}; + char node_path[PSU_NODE_MAX_PATH_LEN] = {'\0'}; + char psu_path[PSU_NODE_MAX_PATH_LEN] = {'\0'}; + + int index = ONLP_OID_ID_GET(info->hdr.id); + + switch(index) + { + case PSU1_ID: + sprintf(psu_path, "%s", PSU1_AC_PMBUS_PREFIX); + break; + case PSU2_ID: + sprintf(psu_path, "%s", PSU2_AC_PMBUS_PREFIX); + break; + default: + break; + } + + /* Read PSU product name from attribute */ + sprintf(node_path, "%s%s", psu_path, "psu_mfr_model"); + dni_i2c_read_attribute_string(node_path, val_char, sizeof(val_char), 0); + strcpy(info->model, val_char); + + /* Read PSU serial number from attribute */ + sprintf(node_path, "%s%s", psu_path, "psu_mfr_serial"); + dni_i2c_read_attribute_string(node_path, val_char, sizeof(val_char), 0); + strcpy(info->serial, val_char); + + /* Read voltage, current and power */ + if (dni_psu_pmbus_info_get(index, "psu_v_in", &val) == 0) + { + info->mvin = val; + info->caps |= ONLP_PSU_CAPS_VIN; + } + + if (dni_psu_pmbus_info_get(index, "psu_v_out", &val) == 0) + { + info->mvout = val; + info->caps |= ONLP_PSU_CAPS_VOUT; + } + + if (dni_psu_pmbus_info_get(index, "psu_i_in", &val) == 0) + { + info->miin = val; + info->caps |= ONLP_PSU_CAPS_IIN; + } + + if (dni_psu_pmbus_info_get(index, "psu_i_out", &val) == 0) + { + info->miout = val; + info->caps |= ONLP_PSU_CAPS_IOUT; + } + + if (dni_psu_pmbus_info_get(index, "psu_p_in", &val) == 0) + { + info->mpin = val; + info->caps |= ONLP_PSU_CAPS_PIN; + } + + if (dni_psu_pmbus_info_get(index, "psu_p_out", &val) == 0) + { + info->mpout = val; + info->caps |= ONLP_PSU_CAPS_POUT; + } + +#endif return ret; } 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); - char device_name[10] = {0}; - UINT4 u4Data = 0; - UINT4 multiplier = 1000; - int psu_present = -1; VALIDATE(id); /* Set the onlp_oid_hdr_t */ memset(info, 0, sizeof(onlp_psu_info_t)); *info = pinfo[index]; +#ifdef BMC + char device_name[10] = {0}; + UINT4 u4Data = 0; + UINT4 multiplier = 1000; - if(dni_bmc_check() == BMC_ON) + /* Check PSU have voltage input or not */ + sprintf(device_name, "PSU%d_Vin", index); + if(dni_bmc_sensor_read(device_name, &u4Data, multiplier, PSU_SENSOR) == ONLP_STATUS_OK) { - /* Check PSU have voltage input or not */ - sprintf(device_name, "PSU%d_Vin", index); - if(dni_bmc_sensor_read(device_name, &u4Data, multiplier) == ONLP_STATUS_OK) + if(u4Data == 0) { - if(u4Data == 0) - { - info->status = ONLP_PSU_STATUS_FAILED; - return ret; - } - info->mpin = u4Data; - info->status = ONLP_PSU_STATUS_PRESENT; - info->caps |= ONLP_PSU_CAPS_VIN; + info->status = ONLP_PSU_STATUS_FAILED; + return ret; } + info->mpin = u4Data; + info->status = ONLP_PSU_STATUS_PRESENT; + info->caps |= ONLP_PSU_CAPS_VIN; + } +#elif defined I2C + int psu_present = -1; + int val = 0; + + switch(index) + { + case PSU1_ID: + psu_present = dni_i2c_lock_read_attribute(NULL, PSU1_PRESENT_PATH); + break; + case PSU2_ID: + psu_present = dni_i2c_lock_read_attribute(NULL, PSU2_PRESENT_PATH); + break; + default: + break; + } + + /* Check PSU have voltage input or not */ + dni_psu_pmbus_info_get(index, "psu_v_in", &val); + + /* Check PSU is PRESENT or not */ + if(val == 0 && psu_present == 1) + { + /* PSU is not PRESENT */ + /* Able to read PSU VIN(psu_power_not_good) */ + info->status |= ONLP_PSU_STATUS_FAILED; + return ret; + } + else if(val == 0 && psu_present == 0) + { + /* Unable to read PSU VIN(psu_power_good) */ + info->status |= ONLP_PSU_STATUS_UNPLUGGED; } else { - switch (index) { - case PSU1_ID: - psu_present = dni_i2c_lock_read_attribute(NULL, PSU1_PRESENT_PATH); - break; - case PSU2_ID: - psu_present = dni_i2c_lock_read_attribute(NULL, PSU2_PRESENT_PATH); - break; - default: - break; - } - - /* Check PSU have voltage input or not */ - dni_psu_pmbus_info_get(index, "psu_v_in", &val); - - /* Check PSU is PRESENT or not */ - if(psu_present == 0) - info->status |= ONLP_PSU_STATUS_PRESENT; - else if(val == 0 && psu_present == 1) - { - /* PSU is not PRESENT */ - /* Able to read PSU VIN(psu_power_not_good) */ - info->status |= ONLP_PSU_STATUS_FAILED; - return ret; - } - else - { - /* Unable to read PSU VIN(psu_power_good) */ - info->status |= ONLP_PSU_STATUS_UNPLUGGED; - } + info->status |= ONLP_PSU_STATUS_PRESENT; } - +#endif ret = dni_psu_info_get(id, info); return ret; } diff --git a/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/sfpi.c b/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/sfpi.c index d7c68a89..0678dce0 100755 --- a/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/sfpi.c +++ b/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/sfpi.c @@ -77,9 +77,10 @@ int onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap) int onlp_sfpi_is_present(int port) { + int present, present_bit = 0x00; +#ifdef BMC uint8_t reg_t = 0x00; int bit_t = 0x00; - int present, present_bit = 0x00; if (port > 0 && port < 9) { /* SFP Port 1-8 */ reg_t = SFP_PRESENCE_1; @@ -100,21 +101,39 @@ int onlp_sfpi_is_present(int port) } if (port > 48 && port < 55) { /* QSFP */ - if (dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_1_ADDR, reg_t, 1, &present_bit) != ONLP_STATUS_OK) + if (dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_1_ADDR, reg_t, &present_bit) != ONLP_STATUS_OK) return ONLP_STATUS_E_INTERNAL; port = port - 1; bit_t = 1 << (port % 8); present_bit = present_bit & bit_t; present_bit = present_bit / bit_t; - } + } else { /* SFP */ - if (dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_2_ADDR, reg_t, 1, &present_bit) != ONLP_STATUS_OK) + if (dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_2_ADDR, reg_t, &present_bit) != ONLP_STATUS_OK) return ONLP_STATUS_E_INTERNAL; port = port - 1; bit_t = 1 << (port % 8); present_bit = present_bit & bit_t; present_bit = present_bit / bit_t; } +#elif defined I2C + char port_data[3] = {'\0'}; + + if(port > 0 && port < 55) + { + /* Select QSFP/SFP port */ + sprintf(port_data, "%d", port ); + if(dni_i2c_lock_write_attribute(NULL, port_data, SFP_SELECT_PORT_PATH) < 0){ + AIM_LOG_ERROR("Unable to select port(%d)\r\n", port); + } + + /* Read QSFP/SFP MODULE is present or not */ + present_bit = dni_i2c_lock_read_attribute(NULL, SFP_IS_PRESENT_PATH); + if(present_bit < 0){ + AIM_LOG_ERROR("Unable to read present or not from port(%d)\r\n", port); + } + } +#endif /* From sfp_is_present value, * return 0 = The module is preset @@ -134,11 +153,12 @@ int onlp_sfpi_is_present(int port) int onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) { + int count = 0; + uint8_t bytes[7] = {0}; +#ifdef BMC uint8_t reg_t = 0x00; int present_data = 0x00; uint8_t r_array[7] = {0}; - uint8_t bytes[7] = {0}; - int count = 0; /* Read presence bitmap from SWPLD2 SFP+ and SWPLD1 QSFP28 Presence Register * if only port 0 is present, return 3F FF FF FF FF FF FE @@ -147,13 +167,13 @@ int onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) for (count = 0; count < 7; count++) { if (count < 6) { /* SFP Port 1-48 */ reg_t = SFP_PRESENCE_1 + count; - if (dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_2_ADDR, reg_t, 1, &present_data) != ONLP_STATUS_OK) + if (dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_2_ADDR, reg_t, &present_data) != ONLP_STATUS_OK) return ONLP_STATUS_E_INTERNAL; r_array[count] = present_data; } else { /* QSFP Port 49-54 */ reg_t = QSFP_PRESENCE; - if (dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_1_ADDR, reg_t, 1, &present_data) != ONLP_STATUS_OK) + if (dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_1_ADDR, reg_t, &present_data) != ONLP_STATUS_OK) return ONLP_STATUS_E_INTERNAL; r_array[count] = present_data; } @@ -163,7 +183,34 @@ int onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) for (count = 0; count < 7; count++) { bytes[count] = ~r_array[6 - count]; } +#elif defined I2C + char present_all_data[21] = {'\0'}; + char *r_byte; + char *r_array[7]; + /* Read presence bitmap from SWPLD2 SFP+ and SWPLD1 QSFP28 Presence Register + * if only port 0 is present, return 3F FF FF FF FF FF FE + * if only port 0 and 1 present, return 3F FF FF FF FF FF FC */ + + if(dni_i2c_read_attribute_string(SFP_IS_PRESENT_ALL_PATH, present_all_data, + sizeof(present_all_data), 0) < 0) { + return -1; + } + + /* String split */ + r_byte = strtok(present_all_data, " "); + while (r_byte != NULL) { + r_array[count++] = r_byte; + r_byte = strtok(NULL, " "); + } + + /* Convert a string to unsigned 8 bit integer + * and saved into bytes[] */ + for (count = 0; count < 7; count++) { + bytes[count] = ~strtol(r_array[count], NULL, 16); + } + +#endif /* Mask out non-existant SFP/QSFP ports */ bytes[0] &= 0x3F; @@ -171,6 +218,7 @@ int onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) int i = 0; uint64_t presence_all = 0; + for(i = 0; i < AIM_ARRAYSIZE(bytes); i++) { presence_all <<= 8; presence_all |= bytes[i]; @@ -212,11 +260,12 @@ int onlp_sfpi_port_map(int port, int* rport) int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { int value_t; +#ifdef BMC uint8_t reg_t = 0x00; int rdata_bit = 0x00; int bit_t = 0x00; - switch (control) { + switch (control) { case ONLP_SFP_CONTROL_RESET_STATE: /* From sfp_reset value, * return 0 = The module is in Reset @@ -224,7 +273,7 @@ int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) if (port > 48 && port < 55) { /* QSFP Port 49-54 */ reg_t = QSFP_RESET; - if (dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_1_ADDR, reg_t, 1, &rdata_bit) != ONLP_STATUS_OK) + if (dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_1_ADDR, reg_t, &rdata_bit) != ONLP_STATUS_OK) return ONLP_STATUS_E_INTERNAL; port = port - 1; bit_t = 1 << (port % 8); @@ -260,12 +309,12 @@ int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) } else if (port > 40 && port < 49) { /* SFP Port 41-48 */ reg_t = SFP_RXLOS_6; } - if (dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_2_ADDR, reg_t, 1, &rdata_bit) != ONLP_STATUS_OK) + if (dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_2_ADDR, reg_t, &rdata_bit) != ONLP_STATUS_OK) return ONLP_STATUS_E_INTERNAL; - port = port - 1; - bit_t = 1 << (port % 8); - rdata_bit = rdata_bit & bit_t; - rdata_bit = rdata_bit / bit_t; + port = port - 1; + bit_t = 1 << (port % 8); + rdata_bit = rdata_bit & bit_t; + rdata_bit = rdata_bit / bit_t; } else { /* In agc7648sv1 only SFP support control RX_LOS MODE */ rdata_bit = 1; /* return 1, module Error */ @@ -293,12 +342,12 @@ int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) } else if (port > 40 && port < 49) { /* SFP Port 41-48 */ reg_t = SFP_TXDIS_6; } - if (dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_2_ADDR, reg_t, 1, &rdata_bit) != ONLP_STATUS_OK) + if (dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_2_ADDR, reg_t, &rdata_bit) != ONLP_STATUS_OK) return ONLP_STATUS_E_INTERNAL; - port = port - 1; - bit_t = 1 << (port % 8); - rdata_bit = rdata_bit & bit_t; - rdata_bit = rdata_bit / bit_t; + port = port - 1; + bit_t = 1 << (port % 8); + rdata_bit = rdata_bit & bit_t; + rdata_bit = rdata_bit / bit_t; } else { /* In agc7648sv1 only SFP support control TX_DISABLE MODE */ rdata_bit = 1; /* return 1, module Transmitter Disabled */ @@ -326,12 +375,12 @@ int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) } else if (port > 40 && port < 49) { /* SFP Port 41-48 */ reg_t = SFP_TXFAULT_6; } - if (dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_2_ADDR, reg_t, 1, &rdata_bit) != ONLP_STATUS_OK) + if (dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_2_ADDR, reg_t, &rdata_bit) != ONLP_STATUS_OK) return ONLP_STATUS_E_INTERNAL; - port = port - 1; - bit_t = 1 << (port % 8); - rdata_bit = rdata_bit & bit_t; - rdata_bit = rdata_bit / bit_t; + port = port - 1; + bit_t = 1 << (port % 8); + rdata_bit = rdata_bit & bit_t; + rdata_bit = rdata_bit / bit_t; } else { /* In agc7648sv1 only SFP support control TX_FAULT MODE */ rdata_bit = 1; /* return 1, module is Fault */ @@ -347,7 +396,7 @@ int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) if (port > 48 && port < 55) { /* QSFP Port 49-54 */ reg_t = QSFP_LPMODE; - if (dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_1_ADDR, reg_t, 1, &rdata_bit) != ONLP_STATUS_OK) + if (dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_1_ADDR, reg_t, &rdata_bit) != ONLP_STATUS_OK) return ONLP_STATUS_E_INTERNAL; port = port - 1; bit_t = 1 << (port % 8); @@ -364,12 +413,75 @@ int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) value_t = ONLP_STATUS_E_UNSUPPORTED; break; } +#elif defined I2C + char port_data[3] = {'\0'}; + + if(port > 0 && port < 55) + { + /* Select SFP(1-48), QSFP(49-54) port */ + sprintf(port_data, "%d", port ); + if(dni_i2c_lock_write_attribute(NULL, port_data, SFP_SELECT_PORT_PATH) < 0){ + AIM_LOG_INFO("Unable to select port(%d)\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + } + + switch (control) { + case ONLP_SFP_CONTROL_RESET_STATE: + /* From sfp_reset value, + * return 0 = The module is in Reset + * return 1 = The module is NOT in Reset */ + *value = dni_i2c_lock_read_attribute(NULL, QSFP_RESET_PATH); + if (*value == 0) + { + *value = 1; + } + else if (*value == 1) + { + *value = 0; + } + value_t = ONLP_STATUS_OK; + break; + case ONLP_SFP_CONTROL_RX_LOS: + /* From sfp_rx_los value, + * return 0 = The module is Normal Operation + * return 1 = The module is Error */ + *value = dni_i2c_lock_read_attribute(NULL, SFP_RX_LOS_PATH); + value_t = ONLP_STATUS_OK; + break; + case ONLP_SFP_CONTROL_TX_DISABLE: + /* From sfp_tx_disable value, + * return 0 = The module is Enable Transmitter on + * return 1 = The module is Transmitter Disabled */ + *value = dni_i2c_lock_read_attribute(NULL, SFP_TX_DISABLE_PATH); + value_t = ONLP_STATUS_OK; + break; + case ONLP_SFP_CONTROL_TX_FAULT: + /* From sfp_tx_fault value, + * return 0 = The module is Normal + * return 1 = The module is Fault */ + *value = dni_i2c_lock_read_attribute(NULL, SFP_TX_FAULT_PATH); + value_t = ONLP_STATUS_OK; + break; + case ONLP_SFP_CONTROL_LP_MODE: + /* From sfp_lp_mode value, + * return 0 = The module is NOT in LP mode + * return 1 = The module is in LP mode */ + *value = dni_i2c_lock_read_attribute(NULL, QSFP_LP_MODE_PATH); + value_t = ONLP_STATUS_OK; + break; + default: + value_t = ONLP_STATUS_E_UNSUPPORTED; + break; + } +#endif return value_t; } int onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) { int value_t; +#ifdef BMC uint8_t reg_t = 0x00; int data_bit = 0x00; int bit_t = 0x00; @@ -378,7 +490,7 @@ int onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) case ONLP_SFP_CONTROL_RESET_STATE: if (port > 48 && port < 55) { /* QSFP Port 49-54 */ reg_t = QSFP_RESET; - if (dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_1_ADDR, reg_t, 1, &data_bit) != ONLP_STATUS_OK) + if (dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_1_ADDR, reg_t, &data_bit) != ONLP_STATUS_OK) return ONLP_STATUS_E_INTERNAL; /* Indicate the module is in reset mode or not * 0 = Reset @@ -419,7 +531,7 @@ int onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) reg_t = SFP_TXDIS_6; } - if (dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_2_ADDR, reg_t, 1, &data_bit) != ONLP_STATUS_OK) + if (dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_2_ADDR, reg_t, &data_bit) != ONLP_STATUS_OK) return ONLP_STATUS_E_INTERNAL; /* Indicate the module is Enable Transmitter on or not * 0 = Enable @@ -447,7 +559,7 @@ int onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) case ONLP_SFP_CONTROL_LP_MODE: if (port > 48 && port < 55) { /* QSFP Port 49-54 */ reg_t = QSFP_LPMODE; - if (dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_1_ADDR, reg_t, 1, &data_bit) != ONLP_STATUS_OK) + if (dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_1_ADDR, reg_t, &data_bit) != ONLP_STATUS_OK) return ONLP_STATUS_E_INTERNAL; /* Indicate the module is in LP mode or not * 0 = Disable @@ -473,6 +585,55 @@ int onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) value_t = ONLP_STATUS_E_UNSUPPORTED; break; } +#elif defined I2C + char port_data[3] = {'\0'}; + + if(port > 0 && port < 55) + { + /* Select SFP(1-48), QSFP(49-54) port */ + sprintf(port_data, "%d", port ); + if(dni_i2c_lock_write_attribute(NULL, port_data, SFP_SELECT_PORT_PATH) < 0){ + AIM_LOG_INFO("Unable to select port(%d)\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + } + + switch (control) { + case ONLP_SFP_CONTROL_RESET_STATE: + sprintf(port_data, "%d", value); + if(dni_i2c_lock_write_attribute(NULL, port_data, QSFP_RESET_PATH) < 0){ + AIM_LOG_INFO("Unable to control reset state from port(%d)\r\n", port); + value_t = ONLP_STATUS_E_INTERNAL; + } + value_t = ONLP_STATUS_OK; + break; + case ONLP_SFP_CONTROL_RX_LOS: + value_t = ONLP_STATUS_E_UNSUPPORTED; + break; + case ONLP_SFP_CONTROL_TX_DISABLE: + sprintf(port_data, "%d", value); + if(dni_i2c_lock_write_attribute(NULL, port_data, SFP_TX_DISABLE_PATH) < 0){ + AIM_LOG_INFO("Unable to control tx disable from port(%d)\r\n", port); + value_t = ONLP_STATUS_E_INTERNAL; + } + value_t = ONLP_STATUS_OK; + break; + case ONLP_SFP_CONTROL_TX_FAULT: + value_t = ONLP_STATUS_E_UNSUPPORTED; + break; + case ONLP_SFP_CONTROL_LP_MODE: + sprintf(port_data, "%d", value); + if(dni_i2c_lock_write_attribute(NULL, port_data, QSFP_LP_MODE_PATH) < 0){ + AIM_LOG_INFO("Unable to control LP mode from port(%d)\r\n", port); + value_t = ONLP_STATUS_E_INTERNAL; + } + value_t = ONLP_STATUS_OK; + break; + default: + value_t = ONLP_STATUS_E_UNSUPPORTED; + break; + } +#endif return value_t; } @@ -511,6 +672,19 @@ int onlp_sfpi_dev_writew(int port, uint8_t devaddr, uint8_t addr, uint16_t value int onlp_sfpi_control_supported(int port, onlp_sfp_control_t control, int* rv) { +#ifdef I2C + char port_data[3] = {'\0'}; + + if(port > 0 && port < 55) + { + /* Select SFP(1-48), QSFP(49-54) port */ + sprintf(port_data, "%d", port); + if(dni_i2c_lock_write_attribute(NULL, port_data, SFP_SELECT_PORT_PATH) < 0){ + AIM_LOG_INFO("Unable to select port(%d)\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + } +#endif switch (control) { case ONLP_SFP_CONTROL_RESET_STATE: if(port > 48 && port < 55) /* QSFP */ @@ -555,11 +729,12 @@ int onlp_sfpi_denit(void) int onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) { + int count = 0; + uint8_t bytes[6] = {0}; +#ifdef BMC uint8_t reg_t = 0x00; int rxlos_data = 0x00; uint8_t r_array[6] = {0}; - uint8_t bytes[6] = {0}; - int count = 0; /* Read rx_los bitmap from SWPLD2 SFP+ LOSS Register * if only port 0 is normal operation, return FF FF FF FF FF FE @@ -567,7 +742,7 @@ int onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) for (count = 0; count < 6; count++) { /* SFP Port 1-48 */ reg_t = SFP_RXLOS_1 + count; - if (dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_2_ADDR, reg_t, 1, &rxlos_data) != ONLP_STATUS_OK) + if (dni_bmc_data_get(BMC_SWPLD_BUS, SWPLD_2_ADDR, reg_t, &rxlos_data) != ONLP_STATUS_OK) return ONLP_STATUS_E_INTERNAL; r_array[count] = rxlos_data; } @@ -576,6 +751,33 @@ int onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) for (count = 0; count < 6; count++) { bytes[count] = r_array[5 - count]; } +#elif defined I2C + char rxlos_all_data[18] = {'\0'}; + char *r_byte; + char *r_array[6]; + + /* Read rx_los bitmap from SWPLD2 SFP+ LOSS Register + * if only port 0 is normal operation, return FF FF FF FF FF FE + * if only port 0 and 1 normal operation, return FF FF FF FF FF FC */ + + if(dni_i2c_read_attribute_string(SFP_RX_LOS_ALL_PATH, rxlos_all_data, + sizeof(rxlos_all_data), 0) < 0) { + return -1; + } + + /* String split */ + r_byte = strtok(rxlos_all_data, " "); + while (r_byte != NULL) { + r_array[count++] = r_byte; + r_byte = strtok(NULL, " "); + } + + /* Convert a string to unsigned 8 bit integer + * and saved into bytes[] */ + for (count = 0; count < 6; count++) { + bytes[count] = strtol(r_array[count], NULL, 16); + } +#endif /* Convert to 64 bit integer in port order */ int i = 0; @@ -597,6 +799,7 @@ int onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) AIM_BITMAP_MOD(dst, i+1, 0); return ONLP_STATUS_OK; + } int onlp_sfpi_dom_read(int port, uint8_t data[256]) diff --git a/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/sysi.c b/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/sysi.c index f9f78e85..146e3a0d 100755 --- a/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/sysi.c +++ b/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/sysi.c @@ -38,6 +38,7 @@ #include #include +#ifdef I2C int decide_percentage(int *percentage, int temper) { int level; @@ -75,6 +76,7 @@ int decide_percentage(int *percentage, int temper) return level; } +#endif const char* onlp_sysi_platform_get(void) { @@ -156,196 +158,174 @@ int onlp_sysi_oids_get(onlp_oid_t* table, int max) int onlp_sysi_platform_manage_fans(void) { + int rv = ONLP_STATUS_OK; + +#ifdef I2C int i, new_percentage, highest_temp = 0; onlp_thermal_info_t thermal; - int rv; - if(dni_bmc_check() == BMC_ON) + /* Get all thermal current temperature and decide fan percentage */ + for(i = 1; i <= NUM_OF_THERMAL; ++i) { - rv = ONLP_STATUS_OK; - } - else{ - /* Get all thermal current temperature and decide fan percentage */ - for(i = 1; i <= NUM_OF_THERMAL; ++i) + if(onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(i), &thermal) != ONLP_STATUS_OK) { - if(onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(i), &thermal) != ONLP_STATUS_OK) - { - AIM_LOG_ERROR("Unable to read thermal status"); - return ONLP_STATUS_E_INTERNAL; - } - - thermal.mcelsius /= 1000; - if(thermal.mcelsius > highest_temp) - { - highest_temp = thermal.mcelsius; - } - decide_percentage(&new_percentage, highest_temp); + AIM_LOG_ERROR("Unable to read thermal status"); + return ONLP_STATUS_E_INTERNAL; } - /* Set fantray RPM and PSU fan percentage */ - onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_1_ON_FAN_BOARD), MAX_FRONT_FAN_SPEED * new_percentage / 100); - onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_2_ON_FAN_BOARD), MAX_FRONT_FAN_SPEED * new_percentage / 100); - onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_3_ON_FAN_BOARD), MAX_FRONT_FAN_SPEED * new_percentage / 100); - onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_4_ON_FAN_BOARD), MAX_FRONT_FAN_SPEED * new_percentage / 100); - onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_5_ON_FAN_BOARD), MAX_REAR_FAN_SPEED * new_percentage / 100); - onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_6_ON_FAN_BOARD), MAX_REAR_FAN_SPEED * new_percentage / 100); - onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_7_ON_FAN_BOARD), MAX_REAR_FAN_SPEED * new_percentage / 100); - onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_8_ON_FAN_BOARD), MAX_REAR_FAN_SPEED * new_percentage / 100); - onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(FAN_1_ON_PSU1), new_percentage); - onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(FAN_1_ON_PSU2), new_percentage); - - rv = ONLP_STATUS_OK; + thermal.mcelsius /= 1000; + if(thermal.mcelsius > highest_temp) + { + highest_temp = thermal.mcelsius; + } + decide_percentage(&new_percentage, highest_temp); } + + /* Set fantray RPM and PSU fan percentage */ + onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_1_ON_FAN_BOARD), MAX_FRONT_FAN_SPEED * new_percentage / 100); + onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_2_ON_FAN_BOARD), MAX_FRONT_FAN_SPEED * new_percentage / 100); + onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_3_ON_FAN_BOARD), MAX_FRONT_FAN_SPEED * new_percentage / 100); + onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_4_ON_FAN_BOARD), MAX_FRONT_FAN_SPEED * new_percentage / 100); + onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_5_ON_FAN_BOARD), MAX_REAR_FAN_SPEED * new_percentage / 100); + onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_6_ON_FAN_BOARD), MAX_REAR_FAN_SPEED * new_percentage / 100); + onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_7_ON_FAN_BOARD), MAX_REAR_FAN_SPEED * new_percentage / 100); + onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_8_ON_FAN_BOARD), MAX_REAR_FAN_SPEED * new_percentage / 100); + onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(FAN_1_ON_PSU1), new_percentage); + onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(FAN_1_ON_PSU2), new_percentage); + +#endif return rv; } int onlp_sysi_platform_manage_leds(void) { + int rv = ONLP_STATUS_OK; +#ifdef I2C int rpm = 0, rpm1 = 0, count = 0; - int rv; int fantray_count; char fantray_count_str[2] = {'\0'}; - uint8_t psu_state; + uint8_t psu1_state, psu2_state; int psu_pwr_status = 0; int psu_pwr_int = 0; int fantray_present = -1; char fullpath[50] = {'\0'}; - if(dni_bmc_check() == BMC_ON) + /* Fan tray 1 */ + fantray_present = dni_i2c_lock_read_attribute(NULL, FAN1_PRESENT_PATH); + rpm = dni_i2c_lock_read_attribute(NULL, FAN1_FRONT); + rpm1 = dni_i2c_lock_read_attribute(NULL, FAN1_REAR); + + if(fantray_present == 0 && rpm != FAN_ZERO_RPM && rpm != 0 && rpm1 != FAN_ZERO_RPM && rpm1 != 0 ) { - rv = ONLP_STATUS_OK; + /* Green */ + if(onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_1),ONLP_LED_MODE_GREEN) != ONLP_STATUS_OK) + rv = ONLP_STATUS_E_INTERNAL; } - else { - /* Fan tray 1 */ - fantray_present = dni_i2c_lock_read_attribute(NULL, FAN1_PRESENT_PATH); - rpm = dni_i2c_lock_read_attribute(NULL, FAN1_FRONT); - rpm1 = dni_i2c_lock_read_attribute(NULL, FAN1_REAR); - - if(fantray_present == 0 && rpm != FAN_ZERO_RPM && rpm != 0 && rpm1 != FAN_ZERO_RPM && rpm1 != 0 ) - { - /* Green */ - if(onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_1),ONLP_LED_MODE_GREEN) != ONLP_STATUS_OK) - rv = ONLP_STATUS_E_INTERNAL; - } - else - { - /* Red */ - if(onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_1),ONLP_LED_MODE_RED) != ONLP_STATUS_OK) - rv = ONLP_STATUS_E_INTERNAL; - } - - /* Fan tray 2 */ - fantray_present = dni_i2c_lock_read_attribute(NULL, FAN2_PRESENT_PATH); - rpm = dni_i2c_lock_read_attribute(NULL, FAN2_FRONT); - rpm1 = dni_i2c_lock_read_attribute(NULL, FAN2_REAR); - - if(fantray_present == 0 && rpm != FAN_ZERO_RPM && rpm != 0 && rpm1 != FAN_ZERO_RPM && rpm1 != 0 ) - { - /* Green */ - if(onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_2),ONLP_LED_MODE_GREEN) != ONLP_STATUS_OK) - rv = ONLP_STATUS_E_INTERNAL; - } - else - { - /* Red */ - if(onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_2),ONLP_LED_MODE_RED) != ONLP_STATUS_OK) - rv = ONLP_STATUS_E_INTERNAL; - } - - /* Fan tray 3 */ - fantray_present = dni_i2c_lock_read_attribute(NULL, FAN3_PRESENT_PATH); - rpm = dni_i2c_lock_read_attribute(NULL, FAN3_FRONT); - rpm1 = dni_i2c_lock_read_attribute(NULL, FAN3_REAR); - - if(fantray_present == 0 && rpm != FAN_ZERO_RPM && rpm != 0 && rpm1 != FAN_ZERO_RPM && rpm1 != 0 ) - { - /* Green */ - if(onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_3),ONLP_LED_MODE_GREEN) != ONLP_STATUS_OK) - rv = ONLP_STATUS_E_INTERNAL; - } - else - { - /* Red */ - if(onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_3),ONLP_LED_MODE_RED) != ONLP_STATUS_OK) - rv = ONLP_STATUS_E_INTERNAL; - } - - /* Fan tray 4 */ - fantray_present = dni_i2c_lock_read_attribute(NULL, FAN4_PRESENT_PATH); - rpm = dni_i2c_lock_read_attribute(NULL, FAN4_FRONT); - rpm1 = dni_i2c_lock_read_attribute(NULL, FAN4_REAR); - - if(fantray_present == 0 && rpm != FAN_ZERO_RPM && rpm != 0 && rpm1 != FAN_ZERO_RPM && rpm1 != 0 ) - { - /* Green */ - if(onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_4),ONLP_LED_MODE_GREEN) != ONLP_STATUS_OK) - rv = ONLP_STATUS_E_INTERNAL; - } - else - { - /* Red */ - if(onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_4),ONLP_LED_MODE_RED) != ONLP_STATUS_OK) - rv = ONLP_STATUS_E_INTERNAL; - } - - /* FRONT FAN & SYS LED */ - for(fantray_count = 9; fantray_count > 5 ; fantray_count--) - { - sprintf(fantray_count_str, "%d", fantray_count); - sprintf(fullpath, "/sys/class/gpio/gpio49%s/value", fantray_count_str); - fantray_present = dni_i2c_lock_read_attribute(NULL, fullpath); - if(fantray_present == 0) - count++; - } - - if(count == ALL_FAN_TRAY_EXIST && dni_fan_speed_good() == FAN_SPEED_NORMALLY) - { - /* Green */ - if((onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FRONT_FAN),ONLP_LED_MODE_GREEN) != ONLP_STATUS_OK) || - (onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FRONT_SYS),ONLP_LED_MODE_GREEN) != ONLP_STATUS_OK)) - rv = ONLP_STATUS_E_INTERNAL; - } - else - { - /* Solid Amber FAN or more failed*/ - if((onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FRONT_FAN),ONLP_LED_MODE_YELLOW) != ONLP_STATUS_OK) || - (onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FRONT_SYS),ONLP_LED_MODE_YELLOW) != ONLP_STATUS_OK)) - rv = ONLP_STATUS_E_INTERNAL; - } - - /* Set front light of PWR */ - psu_state = dni_i2c_lock_read_attribute(NULL, PSU1_PRESENT_PATH); - psu_pwr_status = dni_lock_cpld_read_attribute(SWPLD1_PATH,POWER_STATUS_REGISTER); - psu_pwr_int = dni_lock_cpld_read_attribute(SWPLD1_PATH,POWER_INT_REGISTER); - - if(psu_state == 0 && (psu_pwr_status & 0x80) == 0x80 && (psu_pwr_int & 0x10) == 0x10) - { - /* Green */ - if(onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FRONT_PWR),ONLP_LED_MODE_GREEN) != ONLP_STATUS_OK) - rv = ONLP_STATUS_E_INTERNAL; - } - else - { - /* Amber */ - if(onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FRONT_PWR),ONLP_LED_MODE_YELLOW) != ONLP_STATUS_OK) - rv = ONLP_STATUS_E_INTERNAL; - } - - psu_state = dni_i2c_lock_read_attribute(NULL, PSU2_PRESENT_PATH); - - if(psu_state == 0 && (psu_pwr_status & 0x40) == 0x40 && (psu_pwr_int & 0x20) == 0x20) - { - /* Green */ - if(onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FRONT_PWR),ONLP_LED_MODE_GREEN) != ONLP_STATUS_OK) - rv = ONLP_STATUS_E_INTERNAL; - } - else - { - /* Amber */ - if(onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FRONT_PWR),ONLP_LED_MODE_YELLOW) != ONLP_STATUS_OK) - rv = ONLP_STATUS_E_INTERNAL; - } - rv = ONLP_STATUS_OK; + else + { + /* Red */ + if(onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_1),ONLP_LED_MODE_RED) != ONLP_STATUS_OK) + rv = ONLP_STATUS_E_INTERNAL; } + + /* Fan tray 2 */ + fantray_present = dni_i2c_lock_read_attribute(NULL, FAN2_PRESENT_PATH); + rpm = dni_i2c_lock_read_attribute(NULL, FAN2_FRONT); + rpm1 = dni_i2c_lock_read_attribute(NULL, FAN2_REAR); + + if(fantray_present == 0 && rpm != FAN_ZERO_RPM && rpm != 0 && rpm1 != FAN_ZERO_RPM && rpm1 != 0 ) + { + /* Green */ + if(onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_2),ONLP_LED_MODE_GREEN) != ONLP_STATUS_OK) + rv = ONLP_STATUS_E_INTERNAL; + } + else + { + /* Red */ + if(onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_2),ONLP_LED_MODE_RED) != ONLP_STATUS_OK) + rv = ONLP_STATUS_E_INTERNAL; + } + + /* Fan tray 3 */ + fantray_present = dni_i2c_lock_read_attribute(NULL, FAN3_PRESENT_PATH); + rpm = dni_i2c_lock_read_attribute(NULL, FAN3_FRONT); + rpm1 = dni_i2c_lock_read_attribute(NULL, FAN3_REAR); + + if(fantray_present == 0 && rpm != FAN_ZERO_RPM && rpm != 0 && rpm1 != FAN_ZERO_RPM && rpm1 != 0 ) + { + /* Green */ + if(onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_3),ONLP_LED_MODE_GREEN) != ONLP_STATUS_OK) + rv = ONLP_STATUS_E_INTERNAL; + } + else + { + /* Red */ + if(onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_3),ONLP_LED_MODE_RED) != ONLP_STATUS_OK) + rv = ONLP_STATUS_E_INTERNAL; + } + + /* Fan tray 4 */ + fantray_present = dni_i2c_lock_read_attribute(NULL, FAN4_PRESENT_PATH); + rpm = dni_i2c_lock_read_attribute(NULL, FAN4_FRONT); + rpm1 = dni_i2c_lock_read_attribute(NULL, FAN4_REAR); + + if(fantray_present == 0 && rpm != FAN_ZERO_RPM && rpm != 0 && rpm1 != FAN_ZERO_RPM && rpm1 != 0 ) + { + /* Green */ + if(onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_4),ONLP_LED_MODE_GREEN) != ONLP_STATUS_OK) + rv = ONLP_STATUS_E_INTERNAL; + } + else + { + /* Red */ + if(onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_4),ONLP_LED_MODE_RED) != ONLP_STATUS_OK) + rv = ONLP_STATUS_E_INTERNAL; + } + + /* FRONT FAN & SYS LED */ + for(fantray_count = 9; fantray_count > 5 ; fantray_count--) + { + sprintf(fantray_count_str, "%d", fantray_count); + sprintf(fullpath, "/sys/class/gpio/gpio49%s/value", fantray_count_str); + fantray_present = dni_i2c_lock_read_attribute(NULL, fullpath); + if(fantray_present == 0) + count++; + } + + if(count == ALL_FAN_TRAY_EXIST && dni_fan_speed_good() == FAN_SPEED_NORMALLY) + { + /* Green */ + if((onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FRONT_FAN),ONLP_LED_MODE_GREEN) != ONLP_STATUS_OK) || + (onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FRONT_SYS),ONLP_LED_MODE_GREEN) != ONLP_STATUS_OK)) + rv = ONLP_STATUS_E_INTERNAL; + } + else + { + /* Solid Amber FAN or more failed*/ + if((onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FRONT_FAN),ONLP_LED_MODE_YELLOW) != ONLP_STATUS_OK) || + (onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FRONT_SYS),ONLP_LED_MODE_YELLOW) != ONLP_STATUS_OK)) + rv = ONLP_STATUS_E_INTERNAL; + } + + /* Set front light of PWR */ + psu1_state = dni_i2c_lock_read_attribute(NULL, PSU1_PRESENT_PATH); + psu2_state = dni_i2c_lock_read_attribute(NULL, PSU2_PRESENT_PATH); + psu_pwr_status = dni_lock_cpld_read_attribute(SWPLD1_PATH,POWER_STATUS_REGISTER); + psu_pwr_int = dni_lock_cpld_read_attribute(SWPLD1_PATH,POWER_INT_REGISTER); + + + if(psu1_state == 0 && psu2_state == 0 && (psu_pwr_status & 0xc0) == 0xc0 && (psu_pwr_int & 0x30) == 0x30) + { + /* Green */ + if(onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FRONT_PWR),ONLP_LED_MODE_GREEN) != ONLP_STATUS_OK) + rv = ONLP_STATUS_E_INTERNAL; + } + else + { + /* Amber */ + if(onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FRONT_PWR),ONLP_LED_MODE_YELLOW) != ONLP_STATUS_OK) + rv = ONLP_STATUS_E_INTERNAL; + } +#endif return rv; } diff --git a/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/thermali.c b/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/thermali.c index 1a232070..cf25b90e 100755 --- a/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/thermali.c +++ b/packages/platforms/delta/x86-64/x86-64-delta-agc7648sv1/onlp/builds/src/module/src/thermali.c @@ -42,6 +42,7 @@ ERROR_DEFAULT, \ SHUTDOWN_DEFAULT, \ } +#ifdef I2C static char* path[] = /* must map with onlp_thermal_id */ { "reserved", @@ -57,6 +58,7 @@ static char* path[] = /* must map with onlp_thermal_id */ "31-0058/psu_temp1_input", "32-0058/psu_temp1_input" }; +#endif /* Static values */ static onlp_thermal_info_t linfo[] = { @@ -131,97 +133,96 @@ 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 temp_base = 1; - int rv; - char fullpath[50] = {0}; - int r_data = 0; + int rv = ONLP_STATUS_OK; VALIDATE(id); local_id = ONLP_OID_ID_GET(id); *info = linfo[local_id]; - if(dni_bmc_check() == BMC_ON) - { - switch(local_id) { - case THERMAL_1_ON_FAN_BOARD: - sprintf(device_buf, "Fan_Temp"); - rv = dni_bmc_sensor_read(device_buf, &u4Data, multiplier); - break; - case THERMAL_2_ON_CPU_BOARD: - case THERMAL_3_ON_MAIN_BOARD_TEMP_1: - case THERMAL_4_ON_MAIN_BOARD_TEMP_2: - case THERMAL_5_ON_MAIN_BOARD_TEMP_1: - case THERMAL_6_ON_MAIN_BOARD_TEMP_2: - case THERMAL_7_ON_MAIN_BOARD_TEMP_3: - case THERMAL_8_ON_MAIN_BOARD: - case THERMAL_9_ON_MAIN_BOARD: - local_id--; - sprintf(device_buf, "Temp_Sensor_%d", local_id); - rv = dni_bmc_sensor_read(device_buf, &u4Data, multiplier); - break; - case THERMAL_10_ON_PSU1: - sprintf(device_buf, "PSU1_Temp_1"); - rv = dni_bmc_sensor_read(device_buf, &u4Data, multiplier); - break; - case THERMAL_11_ON_PSU2: - sprintf(device_buf, "PSU2_Temp_1"); - rv = dni_bmc_sensor_read(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; - } +#ifdef BMC + UINT4 multiplier = 1000; + UINT4 u4Data = 0; + char device_buf[20] = {0}; + + switch(local_id) { + case THERMAL_1_ON_FAN_BOARD: + sprintf(device_buf, "Fan_Temp"); + rv = dni_bmc_sensor_read(device_buf, &u4Data, multiplier, THERMAL_SENSOR); + break; + case THERMAL_2_ON_CPU_BOARD: + case THERMAL_3_ON_MAIN_BOARD_TEMP_1: + case THERMAL_4_ON_MAIN_BOARD_TEMP_2: + case THERMAL_5_ON_MAIN_BOARD_TEMP_1: + case THERMAL_6_ON_MAIN_BOARD_TEMP_2: + case THERMAL_7_ON_MAIN_BOARD_TEMP_3: + case THERMAL_8_ON_MAIN_BOARD: + case THERMAL_9_ON_MAIN_BOARD: + local_id--; + sprintf(device_buf, "Temp_Sensor_%d", local_id); + rv = dni_bmc_sensor_read(device_buf, &u4Data, multiplier, THERMAL_SENSOR); + break; + case THERMAL_10_ON_PSU1: + sprintf(device_buf, "PSU1_Temp_1"); + rv = dni_bmc_sensor_read(device_buf, &u4Data, multiplier, THERMAL_SENSOR); + break; + case THERMAL_11_ON_PSU2: + sprintf(device_buf, "PSU2_Temp_1"); + rv = dni_bmc_sensor_read(device_buf, &u4Data, multiplier, THERMAL_SENSOR); + break; + default: + AIM_LOG_ERROR("Invalid Thermal ID!!\n"); + return ONLP_STATUS_E_PARAM; } - else - { - switch (local_id) { - case THERMAL_1_ON_FAN_BOARD: - sprintf(fullpath,"%s%s", PREFIX_PATH, path[local_id]); - break; - case THERMAL_2_ON_CPU_BOARD: - sprintf(fullpath,"%s%s", PREFIX_PATH, path[local_id]); - break; - case THERMAL_3_ON_MAIN_BOARD_TEMP_1: - sprintf(fullpath,"%s%s", PREFIX_PATH, path[local_id]); - break; - case THERMAL_4_ON_MAIN_BOARD_TEMP_2: - sprintf(fullpath,"%s%s", PREFIX_PATH, path[local_id]); - break; - case THERMAL_5_ON_MAIN_BOARD_TEMP_1: - sprintf(fullpath,"%s%s", PREFIX_PATH, path[local_id]); - break; - case THERMAL_6_ON_MAIN_BOARD_TEMP_2: - sprintf(fullpath,"%s%s", PREFIX_PATH, path[local_id]); - break; - case THERMAL_7_ON_MAIN_BOARD_TEMP_3: - sprintf(fullpath,"%s%s", PREFIX_PATH, path[local_id]); - break; - case THERMAL_8_ON_MAIN_BOARD: - sprintf(fullpath,"%s%s", PREFIX_PATH, path[local_id]); - break; - case THERMAL_9_ON_MAIN_BOARD: - sprintf(fullpath,"%s%s", PREFIX_PATH, path[local_id]); - break; - case THERMAL_10_ON_PSU1: - sprintf(fullpath,"%s%s", PREFIX_PATH, path[local_id]); - break; - case THERMAL_11_ON_PSU2: - sprintf(fullpath,"%s%s", PREFIX_PATH, path[local_id]); - break; - } - r_data = dni_i2c_lock_read_attribute(NULL, fullpath); - info->mcelsius = r_data / temp_base; + + if (u4Data == 0 || rv == ONLP_STATUS_E_GENERIC){ + return ONLP_STATUS_E_INTERNAL; } - return ONLP_STATUS_OK; + else{ + info->mcelsius = u4Data; + return 0; + } +#elif defined I2C + int temp_base = 1; + char fullpath[50] = {0}; + int r_data = 0; + + switch (local_id) { + case THERMAL_1_ON_FAN_BOARD: + sprintf(fullpath,"%s%s", PREFIX_PATH, path[local_id]); + break; + case THERMAL_2_ON_CPU_BOARD: + sprintf(fullpath,"%s%s", PREFIX_PATH, path[local_id]); + break; + case THERMAL_3_ON_MAIN_BOARD_TEMP_1: + sprintf(fullpath,"%s%s", PREFIX_PATH, path[local_id]); + break; + case THERMAL_4_ON_MAIN_BOARD_TEMP_2: + sprintf(fullpath,"%s%s", PREFIX_PATH, path[local_id]); + break; + case THERMAL_5_ON_MAIN_BOARD_TEMP_1: + sprintf(fullpath,"%s%s", PREFIX_PATH, path[local_id]); + break; + case THERMAL_6_ON_MAIN_BOARD_TEMP_2: + sprintf(fullpath,"%s%s", PREFIX_PATH, path[local_id]); + break; + case THERMAL_7_ON_MAIN_BOARD_TEMP_3: + sprintf(fullpath,"%s%s", PREFIX_PATH, path[local_id]); + break; + case THERMAL_8_ON_MAIN_BOARD: + sprintf(fullpath,"%s%s", PREFIX_PATH, path[local_id]); + break; + case THERMAL_9_ON_MAIN_BOARD: + sprintf(fullpath,"%s%s", PREFIX_PATH, path[local_id]); + break; + case THERMAL_10_ON_PSU1: + sprintf(fullpath,"%s%s", PREFIX_PATH, path[local_id]); + break; + case THERMAL_11_ON_PSU2: + sprintf(fullpath,"%s%s", PREFIX_PATH, path[local_id]); + break; + } + r_data = dni_i2c_lock_read_attribute(NULL, fullpath); + info->mcelsius = r_data / temp_base; +#endif + return rv; }