Add LED manager function to sysi.c to 2100, 2410 and 2700 systems

Add API for read min_fan_speed.
Fix led_mode compare ledi.c
General code cleunup
This commit is contained in:
Oleksandr Shamray oleksandrs@mellanox.com
2017-06-07 18:39:33 +00:00
parent 845ac9878d
commit 9fc5037615
12 changed files with 281 additions and 34 deletions

View File

@@ -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);
}

View File

@@ -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 &&

View File

@@ -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__ */

View File

@@ -108,9 +108,6 @@ onlp_sysi_oids_get(onlp_oid_t* table, int max)
return 0;
}
#include <onlplib/onie.h>
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;
}

View File

@@ -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);
}

View File

@@ -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 &&

View File

@@ -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__ */

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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 &&

View File

@@ -29,8 +29,6 @@
#include <onlp/psu.h>
#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__ */

View File

@@ -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;
}