diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/fani.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/fani.c index 931d6b0d..281105ab 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/fani.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/fani.c @@ -348,3 +348,14 @@ onlp_fani_ioctl(onlp_oid_t id, va_list vargs) return ONLP_STATUS_E_UNSUPPORTED; } +int +onlp_fani_get_min_rpm(int id) +{ + int len = 0, nbytes = 10; + char r_data[10] = {0}; + char fullpath[65] = {0}; + + snprintf(fullpath, sizeof(fullpath), "%s%s", PREFIX_PATH, fan_path[id].min); + OPEN_READ_FILE(fullpath, r_data, nbytes, len); + return atoi(r_data); +} diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/ledi.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/ledi.c index 6966e6bd..04f52be5 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/ledi.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/ledi.c @@ -52,15 +52,6 @@ /* LED related data */ -enum onlp_led_id -{ - LED_RESERVED = 0, - LED_SYSTEM, - LED_FAN, - LED_PSU1, - LED_PSU2, - LED_UID -}; typedef struct led_light_mode_map { enum onlp_led_id id; @@ -153,8 +144,11 @@ static onlp_led_info_t linfo[] = static int driver_to_onlp_led_mode(enum onlp_led_id id, char* driver_led_mode) { + char *pos; int i, nsize = sizeof(led_map)/sizeof(led_map[0]); + if ((pos=strchr(driver_led_mode, '\n')) != NULL) + *pos = '\0'; for (i = 0; i < nsize; i++) { if (id == led_map[i].id && diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/platform_lib.h b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/platform_lib.h index 863da59d..e364842e 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/platform_lib.h +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/platform_lib.h @@ -41,6 +41,18 @@ #define PSU_POWER_PREFIX "/bsp/power/psu%d_%s" #define IDPROM_PATH "/bsp/eeprom/%s%d_info" +/* LED related data + */ +enum onlp_led_id +{ + LED_RESERVED = 0, + LED_SYSTEM, + LED_FAN, + LED_PSU1, + LED_PSU2, + LED_UID +}; + typedef enum psu_type { PSU_TYPE_UNKNOWN, PSU_TYPE_AC_F2B, @@ -49,4 +61,6 @@ typedef enum psu_type { psu_type_t get_psu_type(int id, char* modelname, int modelname_len); +int onlp_fani_get_min_rpm(int id); + #endif /* __PLATFORM_LIB_H__ */ diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/sfpi.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/sfpi.c index 51fa0147..6b799584 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/sfpi.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/sfpi.c @@ -68,6 +68,13 @@ msn2100_sfp_get_port_path(int port, char *node_name) return sfp_node_path; } +static char* +msn2100_sfp_convert_i2c_path(int port, int devaddr) +{ + sprintf(sfp_node_path, "/bsp/qsfp/qsfp%d", port); + return sfp_node_path; +} + /************************************************************ * * SFPI Entry Points @@ -150,7 +157,27 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) int onlp_sfpi_dev_readb(int port, uint8_t devaddr, uint8_t addr) { - return ONLP_STATUS_E_UNSUPPORTED; + char* path = msn2100_sfp_convert_i2c_path(port, devaddr); + uint8_t data; + int fd; + int nrd; + + if (!path) + return ONLP_STATUS_E_MISSING; + + fd = open(path, O_RDONLY); + if (fd < 0) + return ONLP_STATUS_E_MISSING; + + lseek(fd, addr, SEEK_SET); + nrd = read(fd, &data, 1); + close(fd); + + if (nrd != 1) { + AIM_LOG_INTERNAL("Failed to read EEPROM file '%s'", path); + return ONLP_STATUS_E_INTERNAL; + } + return data; } int @@ -162,7 +189,27 @@ onlp_sfpi_dev_writeb(int port, uint8_t devaddr, uint8_t addr, uint8_t value) int onlp_sfpi_dev_readw(int port, uint8_t devaddr, uint8_t addr) { - return ONLP_STATUS_E_UNSUPPORTED; + char* path = msn2100_sfp_convert_i2c_path(port, devaddr); + uint16_t data; + int fd; + int nrd; + + if (!path) + return ONLP_STATUS_E_MISSING; + + fd = open(path, O_RDONLY); + if (fd < 0) + return ONLP_STATUS_E_MISSING; + + lseek(fd, addr, SEEK_SET); + nrd = read(fd, &data, 2); + close(fd); + + if (nrd != 2) { + AIM_LOG_INTERNAL("Failed to read EEPROM file '%s'", path); + return ONLP_STATUS_E_INTERNAL; + } + return data; } int diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/sysi.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/sysi.c index 621e6525..d294613d 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/sysi.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/sysi.c @@ -108,9 +108,6 @@ onlp_sysi_oids_get(onlp_oid_t* table, int max) return 0; } -#include - - int onlp_sysi_onie_info_get(onlp_onie_info_t* onie) { @@ -125,3 +122,64 @@ onlp_sysi_onie_info_get(onlp_onie_info_t* onie) return rv; } + +int +onlp_sysi_platform_manage_leds(void) +{ + int fan_number; + onlp_led_mode_t mode; + int min_fan_speed; + enum onlp_led_id fan_led_id = LED_FAN; + + /* after reboot, status LED should blink green, SW set to solid green */ + onlp_ledi_mode_set(ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_LED,LED_SYSTEM), ONLP_LED_MODE_GREEN); + /* + * FAN Indicators + * + * Green - Fan is operating + * Red - No power or Fan failure + * Off - No power + * + */ + mode = ONLP_LED_MODE_GREEN; + + for( fan_number = 1; fan_number<= CHASSIS_FAN_COUNT; fan_number+=2) + { + /* each 2 fans had same led_fan */ + onlp_fan_info_t fi; + /* check fans */ + if(onlp_fani_info_get(ONLP_FAN_ID_CREATE(fan_number), &fi) < 0) { + mode = ONLP_LED_MODE_RED; + } + else if(fi.status & ONLP_FAN_STATUS_FAILED) { + mode = ONLP_LED_MODE_RED; + } + else + { + min_fan_speed = onlp_fani_get_min_rpm(fan_number); + if( fi.rpm < min_fan_speed) + { + mode = ONLP_LED_MODE_RED; + } + } + /* check fan i+1 */ + if(onlp_fani_info_get(ONLP_FAN_ID_CREATE(fan_number+1), &fi) < 0) { + mode = ONLP_LED_MODE_RED; + } + else if(fi.status & ONLP_FAN_STATUS_FAILED) { + mode = ONLP_LED_MODE_RED; + } + else + { + min_fan_speed = onlp_fani_get_min_rpm(fan_number+1); + if( fi.rpm < min_fan_speed) + { + mode = ONLP_LED_MODE_RED; + } + } + } + onlp_ledi_mode_set(ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_LED,fan_led_id), mode); + + return ONLP_STATUS_OK; +} + diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/fani.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/fani.c index a1e23036..289a0ef1 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/fani.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/fani.c @@ -534,3 +534,14 @@ onlp_fani_ioctl(onlp_oid_t id, va_list vargs) return ONLP_STATUS_E_UNSUPPORTED; } +int +onlp_fani_get_min_rpm(int id) +{ + int len = 0, nbytes = 10; + char r_data[10] = {0}; + char fullpath[65] = {0}; + + snprintf(fullpath, sizeof(fullpath), "%s%s", PREFIX_PATH, fan_path[id].min); + OPEN_READ_FILE(fullpath, r_data, nbytes, len); + return atoi(r_data); +} diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/ledi.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/ledi.c index 592d58e1..f903c899 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/ledi.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/ledi.c @@ -52,16 +52,6 @@ /* LED related data */ -enum onlp_led_id -{ - LED_RESERVED = 0, - LED_SYSTEM, - LED_FAN1, - LED_FAN2, - LED_FAN3, - LED_FAN4, - LED_PSU, -}; typedef struct led_light_mode_map { enum onlp_led_id id; @@ -170,8 +160,11 @@ static onlp_led_info_t linfo[] = static int driver_to_onlp_led_mode(enum onlp_led_id id, char* driver_led_mode) { + char *pos; int i, nsize = sizeof(led_map)/sizeof(led_map[0]); + if ((pos=strchr(driver_led_mode, '\n')) != NULL) + *pos = '\0'; for (i = 0; i < nsize; i++) { if (id == led_map[i].id && diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/platform_lib.h b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/platform_lib.h index 68242891..3992e357 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/platform_lib.h +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/platform_lib.h @@ -42,6 +42,19 @@ #define PSU_POWER_PREFIX "/bsp/power/psu%d_%s" #define IDPROM_PATH "/bsp/eeprom/%s%d_info" +/* LED related data + */ +enum onlp_led_id +{ + LED_RESERVED = 0, + LED_SYSTEM, + LED_FAN1, + LED_FAN2, + LED_FAN3, + LED_FAN4, + LED_PSU, +}; + typedef enum psu_type { PSU_TYPE_UNKNOWN, PSU_TYPE_AC_F2B, @@ -53,4 +66,6 @@ psu_type_t get_psu_type(int id, char* modelname, int modelname_len); int psu_read_eeprom(int psu_index, onlp_psu_info_t* psu_info, onlp_fan_info_t* fan_info); +int onlp_fani_get_min_rpm(int id); + #endif /* __PLATFORM_LIB_H__ */ diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/sfpi.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/sfpi.c index 7ee8262a..bc65322a 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/sfpi.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/sfpi.c @@ -68,6 +68,13 @@ msn2410_sfp_get_port_path(int port, char *node_name) return sfp_node_path; } +static char* +sn2410_sfp_convert_i2c_path(int port, int devaddr) +{ + sprintf(sfp_node_path, "/bsp/qsfp/qsfp%d", port); + return sfp_node_path; +} + /************************************************************ * * SFPI Entry Points @@ -153,7 +160,27 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) int onlp_sfpi_dev_readb(int port, uint8_t devaddr, uint8_t addr) { - return ONLP_STATUS_E_UNSUPPORTED; + char* path = sn2410_sfp_convert_i2c_path(port, devaddr); + uint8_t data; + int fd; + int nrd; + + if (!path) + return ONLP_STATUS_E_MISSING; + + fd = open(path, O_RDONLY); + if (fd < 0) + return ONLP_STATUS_E_MISSING; + + lseek(fd, addr, SEEK_SET); + nrd = read(fd, &data, 1); + close(fd); + + if (nrd != 1) { + AIM_LOG_INTERNAL("Failed to read EEPROM file '%s'", path); + return ONLP_STATUS_E_INTERNAL; + } + return data; } int @@ -165,7 +192,29 @@ onlp_sfpi_dev_writeb(int port, uint8_t devaddr, uint8_t addr, uint8_t value) int onlp_sfpi_dev_readw(int port, uint8_t devaddr, uint8_t addr) { - return ONLP_STATUS_E_UNSUPPORTED; + char* path = sn2410_sfp_convert_i2c_path(port, devaddr); + uint16_t data; + int fd; + int nrd; + + if (!path){ + return ONLP_STATUS_E_MISSING; + } + + fd = open(path, O_RDONLY); + if (fd < 0) { + return ONLP_STATUS_E_MISSING; + } + + lseek(fd, addr, SEEK_SET); + nrd = read(fd, &data, 2); + close(fd); + + if (nrd != 2) { + AIM_LOG_INTERNAL("Failed to read EEPROM file '%s'", path); + return ONLP_STATUS_E_INTERNAL; + } + return data; } int diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/sysi.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/sysi.c index ff753835..11b3b1b6 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/sysi.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/sysi.c @@ -132,3 +132,70 @@ onlp_sysi_onie_info_get(onlp_onie_info_t* onie) return rv; } + +int +onlp_sysi_platform_manage_leds(void) +{ + int fan_number; + onlp_led_mode_t mode; + int min_fan_speed; + enum onlp_led_id fan_led_id[4] = { LED_FAN1, LED_FAN2, LED_FAN3, LED_FAN4 }; + + /* after reboot, status LED should blink green, SW set to solid green */ + onlp_ledi_mode_set(ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_LED,LED_SYSTEM), ONLP_LED_MODE_GREEN); + /* + * FAN Indicators + * + * Green - Fan is operating + * Red - No power or Fan failure + * Off - No power + * + */ + for( fan_number = 1; fan_number <= CHASSIS_FAN_COUNT; fan_number+=2) + { + /* each 2 fans had same led_fan */ + onlp_fan_info_t fi; + /* check fans */ + mode = ONLP_LED_MODE_GREEN; + if(onlp_fani_info_get(ONLP_FAN_ID_CREATE(fan_number), &fi) < 0) { + mode = ONLP_LED_MODE_RED; + } + else if( (fi.status & 0x1) == 0) { + /* Not present */ + mode = ONLP_LED_MODE_RED; + } + else if(fi.status & ONLP_FAN_STATUS_FAILED) { + mode = ONLP_LED_MODE_RED; + } + else + { + min_fan_speed = onlp_fani_get_min_rpm(fan_number); + if( fi.rpm < min_fan_speed) + { + mode = ONLP_LED_MODE_RED; + } + } + /* check fan i+1 */ + if(onlp_fani_info_get(ONLP_FAN_ID_CREATE(fan_number+1), &fi) < 0) { + mode = ONLP_LED_MODE_RED; + } + else if( (fi.status & 0x1) == 0) { + /* Not present */ + mode = ONLP_LED_MODE_RED; + } + else if(fi.status & ONLP_FAN_STATUS_FAILED) { + mode = ONLP_LED_MODE_RED; + } + else + { + min_fan_speed = onlp_fani_get_min_rpm(fan_number+1); + if( fi.rpm < min_fan_speed) + { + mode = ONLP_LED_MODE_RED; + } + } + onlp_ledi_mode_set(ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_LED,fan_led_id[fan_number/2]), mode); + } + return ONLP_STATUS_OK; +} + diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/fani.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/fani.c index c5840918..e15f7184 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/fani.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/fani.c @@ -533,3 +533,14 @@ onlp_fani_ioctl(onlp_oid_t id, va_list vargs) return ONLP_STATUS_E_UNSUPPORTED; } +int +onlp_fani_get_min_rpm(int id) +{ + int len = 0, nbytes = 10; + char r_data[10] = {0}; + char fullpath[65] = {0}; + + snprintf(fullpath, sizeof(fullpath), "%s%s", PREFIX_PATH, fan_path[id].min); + OPEN_READ_FILE(fullpath, r_data, nbytes, len); + return atoi(r_data); +} diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/ledi.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/ledi.c index bdc4d56a..dc96956a 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/ledi.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/ledi.c @@ -52,16 +52,6 @@ /* LED related data */ -enum onlp_led_id -{ - LED_RESERVED = 0, - LED_SYSTEM, - LED_FAN1, - LED_FAN2, - LED_FAN3, - LED_FAN4, - LED_PSU, -}; typedef struct led_light_mode_map { enum onlp_led_id id; @@ -170,8 +160,11 @@ static onlp_led_info_t linfo[] = static int driver_to_onlp_led_mode(enum onlp_led_id id, char* driver_led_mode) { + char *pos; int i, nsize = sizeof(led_map)/sizeof(led_map[0]); + if ((pos=strchr(driver_led_mode, '\n')) != NULL) + *pos = '\0'; for (i = 0; i < nsize; i++) { if (id == led_map[i].id && diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/platform_lib.h b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/platform_lib.h index 6169310f..c5b368c0 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/platform_lib.h +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/platform_lib.h @@ -29,8 +29,6 @@ #include #include "x86_64_mlnx_msn2700_log.h" -// ./sm/infra/modules/AIM/module/inc/AIM/aim_log.h - #define CHASSIS_PSU_COUNT 2 #define CHASSIS_TOTAL_FAN_COUNT 10 #define CHASSIS_TOTAL_THERMAL_COUNT 8 @@ -44,6 +42,19 @@ #define PSU_POWER_PREFIX "/bsp/power/psu%d_%s" #define IDPROM_PATH "/bsp/eeprom/%s%d_info" +/* LED related data + */ +enum onlp_led_id +{ + LED_RESERVED = 0, + LED_SYSTEM, + LED_FAN1, + LED_FAN2, + LED_FAN3, + LED_FAN4, + LED_PSU, +}; + typedef enum psu_type { PSU_TYPE_UNKNOWN, PSU_TYPE_AC_F2B, @@ -55,4 +66,6 @@ psu_type_t get_psu_type(int id, char* modelname, int modelname_len); int psu_read_eeprom(int psu_index, onlp_psu_info_t* psu_info, onlp_fan_info_t* fan_info); +int onlp_fani_get_min_rpm(int id); + #endif /* __PLATFORM_LIB_H__ */ diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/sfpi.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/sfpi.c index 4e9851f9..ad5b5fa7 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/sfpi.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/sfpi.c @@ -68,6 +68,13 @@ sn2700_sfp_get_port_path(int port, char *node_name) return sfp_node_path; } +static char* +sn2700_sfp_convert_i2c_path(int port, int devaddr) +{ + sprintf(sfp_node_path, "/bsp/qsfp/qsfp%d", port); + return sfp_node_path; +} + /************************************************************ * * SFPI Entry Points @@ -153,7 +160,27 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) int onlp_sfpi_dev_readb(int port, uint8_t devaddr, uint8_t addr) { - return ONLP_STATUS_E_UNSUPPORTED; + char* path = sn2700_sfp_convert_i2c_path(port, devaddr); + uint8_t data; + int fd; + int nrd; + + if (!path) + return ONLP_STATUS_E_MISSING; + + fd = open(path, O_RDONLY); + if (fd < 0) + return ONLP_STATUS_E_MISSING; + + lseek(fd, addr, SEEK_SET); + nrd = read(fd, &data, 1); + close(fd); + + if (nrd != 1) { + AIM_LOG_INTERNAL("Failed to read EEPROM file '%s'", path); + return ONLP_STATUS_E_INTERNAL; + } + return data; } int @@ -165,7 +192,27 @@ onlp_sfpi_dev_writeb(int port, uint8_t devaddr, uint8_t addr, uint8_t value) int onlp_sfpi_dev_readw(int port, uint8_t devaddr, uint8_t addr) { - return ONLP_STATUS_E_UNSUPPORTED; + char* path = sn2700_sfp_convert_i2c_path(port, devaddr); + uint16_t data; + int fd; + int nrd; + + if (!path) + return ONLP_STATUS_E_MISSING; + + fd = open(path, O_RDONLY); + if (fd < 0) + return ONLP_STATUS_E_MISSING; + + lseek(fd, addr, SEEK_SET); + nrd = read(fd, &data, 2); + close(fd); + + if (nrd != 2) { + AIM_LOG_INTERNAL("Failed to read EEPROM file '%s'", path); + return ONLP_STATUS_E_INTERNAL; + } + return data; } int diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/sysi.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/sysi.c index c9225e19..af615b8c 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/sysi.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/sysi.c @@ -133,3 +133,70 @@ onlp_sysi_onie_info_get(onlp_onie_info_t* onie) return rv; } + +int +onlp_sysi_platform_manage_leds(void) +{ + int fan_number; + onlp_led_mode_t mode; + int min_fan_speed; + enum onlp_led_id fan_led_id[4] = { LED_FAN1, LED_FAN2, LED_FAN3, LED_FAN4 }; + + /* after reboot, status LED should blink green, SW set to solid green */ + onlp_ledi_mode_set(ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_LED,LED_SYSTEM), ONLP_LED_MODE_GREEN); + /* + * FAN Indicators + * + * Green - Fan is operating + * Red - No power or Fan failure + * Off - No power + * + */ + for( fan_number = 1; fan_number <= CHASSIS_FAN_COUNT; fan_number+=2) + { + /* each 2 fans had same led_fan */ + onlp_fan_info_t fi; + /* check fan i */ + mode = ONLP_LED_MODE_GREEN; + if(onlp_fani_info_get(ONLP_FAN_ID_CREATE(fan_number), &fi) < 0) { + mode = ONLP_LED_MODE_RED; + } + else if( (fi.status & 0x1) == 0) { + /* Not present */ + mode = ONLP_LED_MODE_RED; + } + else if(fi.status & ONLP_FAN_STATUS_FAILED) { + mode = ONLP_LED_MODE_RED; + } + else + { + min_fan_speed = onlp_fani_get_min_rpm(fan_number); + if( fi.rpm < min_fan_speed) + { + mode = ONLP_LED_MODE_RED; + } + } + /* check fan i+1 */ + if(onlp_fani_info_get(ONLP_FAN_ID_CREATE(fan_number+1), &fi) < 0) { + mode = ONLP_LED_MODE_RED; + } + else if( (fi.status & 0x1) == 0) { + /* Not present */ + mode = ONLP_LED_MODE_RED; + } + else if(fi.status & ONLP_FAN_STATUS_FAILED) { + mode = ONLP_LED_MODE_RED; + } + else + { + min_fan_speed = onlp_fani_get_min_rpm(fan_number+1); + if( fi.rpm < min_fan_speed) + { + mode = ONLP_LED_MODE_RED; + } + } + onlp_ledi_mode_set(ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_LED,fan_led_id[fan_number/2]), mode); + } + return ONLP_STATUS_OK; +} +