From 193e5d9cc00f8cf6f931cdc4e70289b9e26b5729 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Sat, 12 Jan 2019 21:54:41 +0000 Subject: [PATCH] AS5812-54X ONLPv2 Support. --- .../module/src/attributei.c | 26 +- .../module/src/chassisi.c | 30 ++ .../module/src/fani.c | 301 ++++++------------ .../module/src/ledi.c | 134 +++----- .../module/src/platformi.c | 125 +++++++- .../module/src/psui.c | 101 +++--- .../module/src/sfpi.c | 73 +---- .../module/src/sysi.c | 274 ---------------- .../module/src/thermali.c | 67 +--- 9 files changed, 384 insertions(+), 747 deletions(-) delete mode 100644 packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/sysi.c diff --git a/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/attributei.c b/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/attributei.c index ea4c9ed2..62101505 100644 --- a/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/attributei.c +++ b/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/attributei.c @@ -1,6 +1,7 @@ #include #include #include +#include "platform_lib.h" int onlp_attributei_onie_info_get(onlp_oid_t oid, onlp_onie_info_t* rp) @@ -9,8 +10,11 @@ onlp_attributei_onie_info_get(onlp_oid_t oid, onlp_onie_info_t* rp) return ONLP_STATUS_E_UNSUPPORTED; } - //return onlp_onie_decode_file(rp, IDPROM_PATH); - return ONLP_STATUS_E_UNSUPPORTED; + if(rp == NULL) { + return ONLP_STATUS_OK; + } + + return onlp_onie_decode_file(rp, IDPROM_PATH); } int @@ -20,7 +24,23 @@ onlp_attributei_asset_info_get(onlp_oid_t oid, onlp_asset_info_t* rp) return ONLP_STATUS_E_UNSUPPORTED; } + if(rp == NULL) { + return ONLP_STATUS_OK; + } + rp->oid = oid; - rp->firmware_revision = "fixme"; + + rp->manufacturer = aim_strdup("Accton"); + + char* versions[] = { + "/sys/bus/i2c/devices/0-0060/version", + "/sys/bus/i2c/devices/0-0061/version", + "/sys/bus/i2c/devices/0-0062/version", + NULL, + }; + + onlp_file_join_files(&rp->firmware_revision, + ".", versions); + return ONLP_STATUS_OK; } diff --git a/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/chassisi.c b/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/chassisi.c index 98e89d58..989cc445 100644 --- a/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/chassisi.c +++ b/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/chassisi.c @@ -1,4 +1,5 @@ #include +#include "platform_lib.h" int onlp_chassisi_hdr_get(onlp_oid_id_t id, onlp_oid_hdr_t* hdr) @@ -8,4 +9,33 @@ onlp_chassisi_hdr_get(onlp_oid_id_t id, onlp_oid_hdr_t* hdr) ONLP_OID_STATUS_FLAG_SET(hdr, PRESENT); ONLP_OID_STATUS_FLAG_SET(hdr, OPERATIONAL); + + /* 2 PSUs */ + *e++ = ONLP_PSU_ID_CREATE(1); + *e++ = ONLP_PSU_ID_CREATE(2); + + /* LEDs Item */ + for (i=1; i<=CHASSIS_LED_COUNT; i++) + { + *e++ = ONLP_LED_ID_CREATE(i); + } + + /* THERMALs Item */ + for (i=1; i<=CHASSIS_THERMAL_COUNT; i++) + { + *e++ = ONLP_THERMAL_ID_CREATE(i); + } + + /* Fans Item */ + for (i=1; i<=CHASSIS_FAN_COUNT; i++) + { + *e++ = ONLP_FAN_ID_CREATE(i); + } + + /* 54 SFPs */ + for(i = 1; i <= 54; i++) { + *e++ = ONLP_SFP_ID_CREATE(i); + } + + return ONLP_STATUS_OK; } diff --git a/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/fani.c b/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/fani.c index 9c9200c1..67f65744 100644 --- a/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/fani.c +++ b/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/fani.c @@ -44,7 +44,7 @@ #define FAN_1_ON_PSU1 6 #define FAN_1_ON_PSU2 7 -#define PROJECT_NAME +#define PROJECT_NAME #define LEN_FILE_NAME 50 @@ -53,7 +53,7 @@ typedef struct last_path_S char status[LEN_FILE_NAME]; char speed[LEN_FILE_NAME]; char direction[LEN_FILE_NAME]; - char ctrl_speed[LEN_FILE_NAME]; + char ctrl_speed[LEN_FILE_NAME]; char r_status[LEN_FILE_NAME]; char r_speed[LEN_FILE_NAME]; }last_path_T; @@ -76,35 +76,32 @@ static last_path_T last_path[] = /* must map with onlp_fan_id */ MAKE_FAN_LAST_PATH_ON_MAIN_BOARD(PROJECT_NAME, FAN_2_ON_MAIN_BOARD), MAKE_FAN_LAST_PATH_ON_MAIN_BOARD(PROJECT_NAME, FAN_3_ON_MAIN_BOARD), MAKE_FAN_LAST_PATH_ON_MAIN_BOARD(PROJECT_NAME, FAN_4_ON_MAIN_BOARD), - MAKE_FAN_LAST_PATH_ON_MAIN_BOARD(PROJECT_NAME, FAN_5_ON_MAIN_BOARD), + MAKE_FAN_LAST_PATH_ON_MAIN_BOARD(PROJECT_NAME, FAN_5_ON_MAIN_BOARD), - MAKE_FAN_LAST_PATH_ON_PSU(57-003c), - MAKE_FAN_LAST_PATH_ON_PSU(58-003f), + MAKE_FAN_LAST_PATH_ON_PSU(57-003c), + MAKE_FAN_LAST_PATH_ON_PSU(58-003f), }; #define MAKE_FAN_INFO_NODE_ON_MAIN_BOARD(id) \ { \ - { ONLP_FAN_ID_CREATE(FAN_##id##_ON_MAIN_BOARD), "Chassis Fan "#id, 0 }, \ + { ONLP_FAN_ID_CREATE(FAN_##id##_ON_MAIN_BOARD), "Chassis Fan "#id, ONLP_OID_CHASSIS }, \ 0x0, \ ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE, \ 0, \ 0, \ - ONLP_FAN_MODE_INVALID, \ - } + } #define MAKE_FAN_INFO_NODE_ON_PSU(psu_id, fan_id) \ { \ - { ONLP_FAN_ID_CREATE(FAN_##fan_id##_ON_PSU##psu_id), "Chassis PSU-"#psu_id " Fan "#fan_id, 0 }, \ + { ONLP_FAN_ID_CREATE(FAN_##fan_id##_ON_PSU##psu_id), "Chassis PSU-"#psu_id " Fan "#fan_id, ONLP_PSU_ID_CREATE(psu_id) }, \ 0x0, \ 0, \ 0, \ 0, \ - ONLP_FAN_MODE_INVALID, \ } - /* Static fan information */ -onlp_fan_info_t linfo[] = { +static onlp_fan_info_t finfo[] = { { }, /* Not used */ MAKE_FAN_INFO_NODE_ON_MAIN_BOARD(1), MAKE_FAN_INFO_NODE_ON_MAIN_BOARD(2), @@ -115,88 +112,76 @@ onlp_fan_info_t linfo[] = { MAKE_FAN_INFO_NODE_ON_PSU(2,1), }; -#define VALIDATE(_id) \ - do { \ - if(!ONLP_OID_IS_FAN(_id)) { \ - return ONLP_STATUS_E_INVALID; \ - } \ - } while(0) - -#define OPEN_READ_FILE(fd,fullpath,data,nbytes,len) \ - if (LOCAL_DEBUG) \ - printf("[Debug][%s][%d][openfile: %s]\n", __FUNCTION__, __LINE__, fullpath); \ - if ((fd = open(fullpath, O_RDONLY)) == -1) \ - return ONLP_STATUS_E_INTERNAL; \ - if ((len = read(fd, r_data, nbytes)) <= 0){ \ - close(fd); \ - return ONLP_STATUS_E_INTERNAL;} \ - if (LOCAL_DEBUG) \ - printf("[Debug][%s][%d][read data: %s]\n", __FUNCTION__, __LINE__, r_data); \ - if (close(fd) == -1) \ - return ONLP_STATUS_E_INTERNAL - /* PSU relative marco */ -#define SET_PSU_TYPE_AC_F2B_FAN(info) \ - info->status |= (ONLP_FAN_STATUS_PRESENT | ONLP_FAN_STATUS_F2B); \ - info->caps |= ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE +#define SET_PSU_TYPE_AC_F2B_FAN(info) \ + do { \ + ONLP_OID_STATUS_FLAG_SET(info, PRESENT); \ + info->dir = ONLP_FAN_DIR_F2B; \ + info->caps |= ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE; \ + } while(0) -#define SET_PSU_TYPE_AC_B2F_FAN(info) \ - info->status |= (ONLP_FAN_STATUS_PRESENT | ONLP_FAN_STATUS_B2F); \ - info->caps |= ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE - -#define SET_PSU_TYPE_UM400D_F2B_FAN(info) \ - info->status |= (ONLP_FAN_STATUS_PRESENT | ONLP_FAN_STATUS_F2B) +#define SET_PSU_TYPE_AC_B2F_FAN(info) \ + do { \ + ONLP_OID_STATUS_FLAG_SET(info, PRESENT); \ + info->dir = ONLP_FAN_DIR_B2F; \ + info->caps |= ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE; \ + } while(0) + +#define SET_PSU_TYPE_UM400D_F2B_FAN(info) \ + do { \ + ONLP_OID_STATUS_FLAG_SET(info, PRESENT); \ + info->dir = ONLP_FAN_DIR_F2B; \ + } while(0) #define SET_PSU_TYPE_UM400D_B2F_FAN(info) \ - info->status |= (ONLP_FAN_STATUS_PRESENT | ONLP_FAN_STATUS_B2F) + do { \ + ONLP_OID_STATUS_FLAG_SET(info, PRESENT); \ + info->dir = ONLP_FAN_DIR_B2F; \ + } while(0) static int _onlp_fani_info_get_fan(int local_id, onlp_fan_info_t* info) { - int fd, len, nbytes = 10; - char r_data[10] = {0}; - char fullpath[65] = {0}; - + int v; + /* get fan/fanr fault status (turn on when any one fails) */ - sprintf(fullpath, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].status); - OPEN_READ_FILE(fd,fullpath,r_data,nbytes,len); - if (atoi(r_data) > 0) - info->status |= ONLP_FAN_STATUS_FAILED; + ONLP_TRY(onlp_file_read_int(&v, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].status)); + if (v > 0) { + ONLP_OID_STATUS_FLAG_SET(info, FAILED); + } - sprintf(fullpath, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].r_status); - OPEN_READ_FILE(fd,fullpath,r_data,nbytes,len); - if (atoi(r_data) > 0) - info->status |= ONLP_FAN_STATUS_FAILED; + ONLP_TRY(onlp_file_read_int(&v, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].r_status)); + if(v > 0) { + ONLP_OID_STATUS_FLAG_SET(info, FAILED); + } - /* get fan/fanr direction (both : the same) + /* get fan/fanr direction (both : the same) */ - sprintf(fullpath, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].direction); - OPEN_READ_FILE(fd,fullpath,r_data,nbytes,len); - - if (atoi(r_data) == 0) /*F2B*/ - info->status |= ONLP_FAN_STATUS_F2B; - else - info->status |= ONLP_FAN_STATUS_B2F; + ONLP_TRY(onlp_file_read_int(&v, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].direction)); + if (v == 0) { + /*F2B*/ + info->dir = ONLP_FAN_DIR_F2B; + } + else { + info->dir = ONLP_FAN_DIR_B2F; + } /* get fan/fanr speed (take the average of two speeds) */ - sprintf(fullpath, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].speed); - OPEN_READ_FILE(fd,fullpath,r_data,nbytes,len); - info->rpm = atoi(r_data); - - sprintf(fullpath, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].r_speed); - OPEN_READ_FILE(fd,fullpath,r_data,nbytes,len); - info->rpm = (info->rpm + atoi(r_data))/2; + ONLP_TRY(onlp_file_read_int(&info->rpm, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].speed)); + ONLP_TRY(onlp_file_read_int(&v, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].r_speed)); + info->rpm = (info->rpm + v)/2; /* get speed percentage from rpm */ info->percentage = (info->rpm * 100)/x86_64_accton_as5812_54x_CONFIG_SYS_FAN_FRONT_RPM_MAX; - /* check present */ - if (info->rpm > 0) - info->status |= ONLP_FAN_STATUS_PRESENT; + /* check present */ + if (info->rpm > 0) { + ONLP_OID_STATUS_FLAG_SET(info, PRESENT); + } return ONLP_STATUS_OK; } @@ -209,9 +194,9 @@ _onlp_fani_info_get_fan_on_psu_ym2401(int pid, onlp_fan_info_t* info) /* get fan status */ if (psu_ym2401_pmbus_info_get(pid, "psu_fan1_speed_rpm", &val) == ONLP_STATUS_OK) { - info->status |= (val > 0) ? 0 : ONLP_FAN_STATUS_FAILED; + ONLP_OID_STATUS_FLAG_SET_VALUE(info, FAILED, val <= 0); info->rpm = val; - info->percentage = (info->rpm * 100) / 21600; + info->percentage = (info->rpm * 100) / 21600; } return ONLP_STATUS_OK; @@ -220,19 +205,15 @@ _onlp_fani_info_get_fan_on_psu_ym2401(int pid, onlp_fan_info_t* info) static int _onlp_fani_info_get_fan_on_psu(int local_id, onlp_fan_info_t* info) { + int v; int psu_id; - int fd, len, nbytes = 10; - char r_data[10] = {0}; - char fullpath[50] = {0}; psu_type_t psu_type; - - /* get fan other cap status according to psu type + + /* get fan other cap status according to psu type */ psu_id = (local_id-FAN_1_ON_PSU1) + 1; - DEBUG_PRINT("[psu_id: %d]", psu_id); - + psu_type = get_psu_type(psu_id, NULL, 0); /* psu_id = 1 , present PSU1. pus_id =2 , present PSU2 */ - DEBUG_PRINT("[psu_type: %d]", psu_type); switch (psu_type) { case PSU_TYPE_AC_COMPUWARE_F2B: @@ -251,27 +232,24 @@ _onlp_fani_info_get_fan_on_psu(int local_id, onlp_fan_info_t* info) break; default: if (LOCAL_DEBUG) - printf("[Debug][%s][%d][psu_type=%d]\n", __FUNCTION__, __LINE__, psu_type); + printf("[Debug][%s][%d][psu_type=%d]\n", __FUNCTION__, __LINE__, psu_type); break; } - + if (psu_type == PSU_TYPE_AC_COMPUWARE_F2B || psu_type == PSU_TYPE_AC_COMPUWARE_B2F ) { - /* get fan fault status + /* get fan fault status */ - sprintf(fullpath, "%s%s", PREFIX_PATH_ON_PSU, last_path[local_id].status); - OPEN_READ_FILE(fd,fullpath,r_data,nbytes,len); - if (atoi(r_data) > 0) - info->status |= ONLP_FAN_STATUS_FAILED; - + ONLP_TRY(onlp_file_read_int(&v, "%s%s", PREFIX_PATH_ON_PSU, last_path[local_id].status)); + if (v > 0) { + ONLP_OID_STATUS_FLAG_SET(info, FAILED); + } + /* get fan speed */ - sprintf(fullpath, "%s%s", PREFIX_PATH_ON_PSU, last_path[local_id].speed); - OPEN_READ_FILE(fd,fullpath,r_data,nbytes,len); - info->rpm = atoi(r_data); - + ONLP_TRY(onlp_file_read_int(&info->rpm, "%s%s", PREFIX_PATH_ON_PSU, last_path[local_id].speed)); /* get speed percentage from rpm */ info->percentage = (info->rpm * 100)/19328; } @@ -280,17 +258,7 @@ _onlp_fani_info_get_fan_on_psu(int local_id, onlp_fan_info_t* info) { return _onlp_fani_info_get_fan_on_psu_ym2401(psu_id, info); } - - return ONLP_STATUS_OK; -} - -/* - * This function will be called prior to all of onlp_fani_* functions. - */ -int -onlp_fani_init(void) -{ return ONLP_STATUS_OK; } @@ -299,73 +267,38 @@ int onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* info) { int rc = 0; - int local_id; - VALIDATE(id); - - local_id = ONLP_OID_ID_GET(id); - - *info = linfo[local_id]; - - if (LOCAL_DEBUG) - printf("\n[Debug][%s][%d][local_id: %d]", __FUNCTION__, __LINE__, local_id); - - switch (local_id) - { - case FAN_1_ON_PSU1: + *info = finfo[id]; + + switch (id) + { + case FAN_1_ON_PSU1: case FAN_1_ON_PSU2: - rc = _onlp_fani_info_get_fan_on_psu(local_id, info); + rc = _onlp_fani_info_get_fan_on_psu(id, info); break; default: - rc =_onlp_fani_info_get_fan(local_id, info); + rc =_onlp_fani_info_get_fan(id, info); break; - } - + } + return rc; } -/* - * This function sets the speed of the given fan in RPM. - * - * This function will only be called if the fan supprots the RPM_SET - * capability. - * - * It is optional if you have no fans at all with this feature. - */ int -onlp_fani_rpm_set(onlp_oid_t id, int rpm) +onlp_fani_percentage_set(onlp_oid_id_t id, int p) { - return ONLP_STATUS_E_UNSUPPORTED; -} - - -/* - * This function sets the fan speed of the given OID as a percentage. - * - * This will only be called if the OID has the PERCENTAGE_SET - * capability. - * - * It is optional if you have no fans at all with this feature. - */ -int -onlp_fani_percentage_set(onlp_oid_t id, int p) -{ - int fd, len, nbytes=10, local_id; - char data[10] = {0}; - char fullpath[70] = {0}; - - VALIDATE(id); - - local_id = ONLP_OID_ID_GET(id); + int fd, len, nbytes=10; + char data[10] = {0}; + char fullpath[70] = {0}; /* reject p=0 (p=0, stop fan) */ if (p == 0){ return ONLP_STATUS_E_INVALID; } - + /* get fullpath */ - switch (local_id) + switch (id) { case FAN_1_ON_PSU1: case FAN_1_ON_PSU2: @@ -373,7 +306,7 @@ onlp_fani_percentage_set(onlp_oid_t id, int p) int psu_id; psu_type_t psu_type; - psu_id = local_id - FAN_1_ON_PSU1 + 1; + psu_id = id - FAN_1_ON_PSU1 + 1; psu_type = get_psu_type(psu_id, NULL, 0); if (psu_type == PSU_TYPE_AC_3YPOWER_F2B || @@ -381,72 +314,32 @@ onlp_fani_percentage_set(onlp_oid_t id, int p) return psu_ym2401_pmbus_info_set(psu_id, "psu_fan1_duty_cycle_percentage", p); } - sprintf(fullpath, "%s%s", PREFIX_PATH_ON_PSU, last_path[local_id].ctrl_speed); + sprintf(fullpath, "%s%s", PREFIX_PATH_ON_PSU, last_path[id].ctrl_speed); break; } default: - sprintf(fullpath, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[local_id].ctrl_speed); + sprintf(fullpath, "%s%s", PREFIX_PATH_ON_MAIN_BOARD, last_path[id].ctrl_speed); break; } - + sprintf(data, "%d", p); if (LOCAL_DEBUG) printf("[Debug][%s][%d][openfile: %s][data=%s]\n", __FUNCTION__, __LINE__, fullpath, data); - + /* Create output file descriptor */ fd = open(fullpath, O_WRONLY, 0644); if(fd == -1){ - return ONLP_STATUS_E_INTERNAL; + return ONLP_STATUS_E_INTERNAL; } - + len = write (fd, data, (ssize_t) nbytes); if(len != nbytes){ - close(fd); - return ONLP_STATUS_E_INTERNAL; - } + close(fd); + return ONLP_STATUS_E_INTERNAL; + } close(fd); return ONLP_STATUS_OK; } - - - -/* - * This function sets the fan speed of the given OID as per - * the predefined ONLP fan speed modes: off, slow, normal, fast, max. - * - * Interpretation of these modes is up to the platform. - * - */ -int -onlp_fani_mode_set(onlp_oid_t id, onlp_fan_mode_t mode) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - -/* - * This function sets the fan direction of the given OID. - * - * This function is only relevant if the fan OID supports both direction - * capabilities. - * - * This function is optional unless the functionality is available. - */ -int -onlp_fani_dir_set(onlp_oid_t id, onlp_fan_dir_t dir) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - -/* - * Generic fan ioctl. Optional. - */ -int -onlp_fani_ioctl(onlp_oid_t id, va_list vargs) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - - diff --git a/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/ledi.c b/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/ledi.c index c84ebe5a..9efe8e7c 100644 --- a/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/ledi.c +++ b/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/ledi.c @@ -50,20 +50,20 @@ enum led_light_mode { /*must be the same with the definition @ kernel driver */ LED_MODE_GREEN_BLINK, LED_MODE_AMBER_BLINK, LED_MODE_RED_BLINK, - LED_MODE_AUTO, + LED_MODE_AUTO, }; int led_light_map_mode[][2] = { - {LED_MODE_OFF, ONLP_LED_MODE_OFF}, + {LED_MODE_OFF, ONLP_LED_MODE_OFF}, {LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, {LED_MODE_AMBER, ONLP_LED_MODE_ORANGE}, - {LED_MODE_RED, ONLP_LED_MODE_RED}, + {LED_MODE_RED, ONLP_LED_MODE_RED}, {LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, {LED_MODE_AMBER_BLINK, ONLP_LED_MODE_ORANGE_BLINKING}, {LED_MODE_RED_BLINK, ONLP_LED_MODE_RED_BLINKING}, - {LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, -}; + {LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, +}; #define prefix_path "/sys/class/leds/accton_as5812_54x_led::" @@ -81,7 +81,7 @@ enum onlp_led_id LED_FAN2, LED_FAN3, LED_FAN4, - LED_FAN5, + LED_FAN5, }; static char last_path[][10] = /* must map with onlp_led_id */ @@ -96,7 +96,7 @@ static char last_path[][10] = /* must map with onlp_led_id */ "fan2", "fan3", "fan4", - "fan5", + "fan5", }; /* @@ -105,51 +105,21 @@ static char last_path[][10] = /* must map with onlp_led_id */ static onlp_led_info_t linfo[] = { { }, /* Not used */ - { - { ONLP_LED_ID_CREATE(LED_DIAG), "Chassis LED 1 (DIAG LED)", 0 }, - ONLP_LED_STATUS_PRESENT, - ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_GREEN, - }, - { - { ONLP_LED_ID_CREATE(LED_FAN), "Chassis LED 2 (FAN LED)", 0 }, - ONLP_LED_STATUS_PRESENT, - ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_AUTO, - }, - { - { ONLP_LED_ID_CREATE(LED_LOC), "Chassis LED 3 (LOC LED)", 0 }, - ONLP_LED_STATUS_PRESENT, - ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_ORANGE_BLINKING, - }, - { - { ONLP_LED_ID_CREATE(LED_PSU1), "Chassis LED 4 (PSU1 LED)", 0 }, - ONLP_LED_STATUS_PRESENT, - ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_AUTO, - }, - { - { ONLP_LED_ID_CREATE(LED_PSU2), "Chassis LED 5 (PSU2 LED)", 0 }, - ONLP_LED_STATUS_PRESENT, - ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_AUTO, - }, - { - { ONLP_LED_ID_CREATE(LED_FAN1), "Chassis LED 6 (FAN1 LED)", 0 }, - ONLP_LED_STATUS_PRESENT, 0, - }, - { - { ONLP_LED_ID_CREATE(LED_FAN2), "Chassis LED 7 (FAN2 LED)", 0 }, - ONLP_LED_STATUS_PRESENT, 0, - }, - { - { ONLP_LED_ID_CREATE(LED_FAN3), "Chassis LED 8 (FAN3 LED)", 0 }, - ONLP_LED_STATUS_PRESENT, 0, - }, - { - { ONLP_LED_ID_CREATE(LED_FAN4), "Chassis LED 9 (FAN4 LED)", 0 }, - ONLP_LED_STATUS_PRESENT, 0, - }, - { - { ONLP_LED_ID_CREATE(LED_FAN5), "Chassis LED 10 (FAN5 LED)", 0 }, - ONLP_LED_STATUS_PRESENT, 0, - }, + ONLP_CHASSIS_LED_INFO_ENTRY_INIT(LED_DIAG, "Chassis LED 1 (DIAG LED)", + ONLP_LED_CAPS_OFF | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_GREEN), + ONLP_CHASSIS_LED_INFO_ENTRY_INIT(LED_FAN, "Chassis LED 2 (FAN LED)", + ONLP_LED_CAPS_OFF | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_AUTO), + ONLP_CHASSIS_LED_INFO_ENTRY_INIT(LED_LOC, "Chassis LED 3 (LOC LED)", + ONLP_LED_CAPS_OFF | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_ORANGE_BLINKING), + ONLP_CHASSIS_LED_INFO_ENTRY_INIT(LED_PSU1, "Chassis LED 4 (PSU1 LED)", + ONLP_LED_CAPS_OFF | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_AUTO), + ONLP_CHASSIS_LED_INFO_ENTRY_INIT(LED_PSU2, "Chassis LED 5 (PSU2 LED)", + ONLP_LED_CAPS_OFF | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_AUTO), + ONLP_CHASSIS_LED_INFO_ENTRY_INIT(LED_FAN1, "Chassis LED 6 (FAN1 LED)", 0), + ONLP_CHASSIS_LED_INFO_ENTRY_INIT(LED_FAN2, "Chassis LED 7 (FAN2 LED)", 0), + ONLP_CHASSIS_LED_INFO_ENTRY_INIT(LED_FAN3, "Chassis LED 8 (FAN3 LED)", 0), + ONLP_CHASSIS_LED_INFO_ENTRY_INIT(LED_FAN4, "Chassis LED 9 (FAN4 LED)", 0), + ONLP_CHASSIS_LED_INFO_ENTRY_INIT(LED_FAN5, "Chassis LED 10 (FAN5 LED)", 0), }; @@ -160,7 +130,7 @@ static int conver_led_light_mode_to_onl(int led_ligth_mode) { if (led_ligth_mode == led_light_map_mode[i][0]) { - return led_light_map_mode[i][1]; + return led_light_map_mode[i][1]; } } return 0; @@ -174,7 +144,7 @@ static int conver_led_light_mode_to_driver(int led_ligth_mode) { if (led_ligth_mode == led_light_map_mode[i][1]) { - return led_light_map_mode[i][0]; + return led_light_map_mode[i][0]; } } return 0; @@ -201,49 +171,44 @@ onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) int fd, len, nbytes=1, local_id; char data[2] = {0}; char fullpath[50] = {0}; - + VALIDATE(id); - + local_id = ONLP_OID_ID_GET(id); - + /* get fullpath */ if (strchr(last_path[local_id], '/') != NULL) { - sprintf(fullpath, "%s%s", prefix_path, last_path[local_id]); + sprintf(fullpath, "%s%s", prefix_path, last_path[local_id]); } else { - sprintf(fullpath, "%s%s/%s", prefix_path, last_path[local_id], filename); + sprintf(fullpath, "%s%s/%s", prefix_path, last_path[local_id], filename); } - - /* Set the onlp_oid_hdr_t and capabilities */ + + /* Set the onlp_oid_hdr_t and capabilities */ *info = linfo[ONLP_OID_ID_GET(id)]; /* Set current mode */ if ((fd = open(fullpath, O_RDONLY)) == -1) - { + { return ONLP_STATUS_E_INTERNAL; } - + if ((len = read(fd, data, nbytes)) <= 0) { - close(fd); + close(fd); return ONLP_STATUS_E_INTERNAL; } - + /* If the read byte count is less, the format is different and calc will be wrong*/ if (close(fd) == -1) - { + { return ONLP_STATUS_E_INTERNAL; } info->mode = conver_led_light_mode_to_onl(atoi(data)); - /* Set the on/off status */ - if (info->mode != ONLP_LED_MODE_OFF) { - info->status |= ONLP_LED_STATUS_ON; - } - return ONLP_STATUS_OK; } @@ -278,37 +243,37 @@ int onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) { int fd, len, driver_mode, nbytes=1, local_id; - char data[2] = {0}; - char fullpath[50] = {0}; + char data[2] = {0}; + char fullpath[50] = {0}; VALIDATE(id); - + local_id = ONLP_OID_ID_GET(id); - + /* get fullpath */ if (strchr(last_path[local_id], '/') != NULL) { - sprintf(fullpath, "%s%s", prefix_path, last_path[local_id]); + sprintf(fullpath, "%s%s", prefix_path, last_path[local_id]); } else { - sprintf(fullpath, "%s%s/%s", prefix_path, last_path[local_id], filename); + sprintf(fullpath, "%s%s/%s", prefix_path, last_path[local_id], filename); } - + driver_mode = conver_led_light_mode_to_driver(mode); sprintf(data, "%d", driver_mode); - + /* Create output file descriptor */ fd = open(fullpath, O_WRONLY, 0644); if(fd == -1){ - return ONLP_STATUS_E_INTERNAL; + return ONLP_STATUS_E_INTERNAL; } - + len = write (fd, data, (ssize_t) nbytes); if(len != nbytes){ - close(fd); - return ONLP_STATUS_E_INTERNAL; - } + close(fd); + return ONLP_STATUS_E_INTERNAL; + } close(fd); return ONLP_STATUS_OK; @@ -322,4 +287,3 @@ onlp_ledi_ioctl(onlp_oid_t id, va_list vargs) { return ONLP_STATUS_E_UNSUPPORTED; } - diff --git a/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/platformi.c b/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/platformi.c index 77bd1e43..4c8970c4 100644 --- a/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/platformi.c +++ b/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/platformi.c @@ -1,5 +1,6 @@ #include +#include "x86_64_accton_as5812_54x_log.h" const char* onlp_platformi_get(void) @@ -13,14 +14,126 @@ onlp_platformi_sw_init(void) return ONLP_STATUS_OK; } + + + + + +/* + * 1. If any FAN failed, set all the other fans as full speed (100%) + * 2. When (LM75-1 + LM75-2)/2 >= 49.5 C, set fan speed from 40% to 65%. + * 3. When (LM75-1 + LM75-2)/2 >= 53C, set fan speed from 65% to 80% + * 4. When (LM75-1 + LM75-2)/2 >= 57.7C, set fan speed from 80% to 100% + + * 5. When (LM75-1 + LM75-2)/2 <= 52.7C, set fan speed from 100% to 80% + * 6. When (LM75-1 + LM75-2)/2 <= 47.7C, set fan speed from 80% to 65% + * 7. When (LM75-1 + LM75-2)/2 <= 42.7C, set fan speed from 65% to 40% + * 8. The default FAN speed is 40% + */ + int onlp_platformi_manage_fans(void) { - return ONLP_STATUS_E_UNSUPPORTED; -} -int -onlp_platformi_manage_leds(void) -{ - return ONLP_STATUS_E_UNSUPPORTED; +#define LEV1_UP_TEMP 57500 /*temperature*/ +#define LEV1_DOWN_TEMP NULL /* unused */ +#define LEV1_SPEED_PERC 100 /*percentage*/ + +#define LEV2_UP_TEMP 53000 +#define LEV2_DOWN_TEMP 52700 +#define LEV2_SPEED_PERC 80 + +#define LEV3_UP_TEMP 49500 +#define LEV3_DOWN_TEMP 47700 +#define LEV3_SPEED_PERC 65 + +#define LEV4_UP_TEMP NULL /* unused */ +#define LEV4_DOWN_TEMP 42700 +#define LEV4_SPEED_PERC 40 + +#define FAN_NUM_ON_MAIN_BROAD 5 + + + int rc, i; + int is_up; + int new_temp, temp1, temp2, diff; + static int new_perc = 0, ori_perc = 0; + static int ori_temp = 0; + onlp_thermal_info_t thermal_info; + onlp_fan_info_t fan_info; + + /* get new temperature */ + if ((rc = onlp_thermal_info_get(ONLP_THERMAL_ID_CREATE(1), &thermal_info)) != ONLP_STATUS_OK) + goto _EXIT; + + temp1 = thermal_info.mcelsius; + + if ((rc = onlp_thermal_info_get(ONLP_THERMAL_ID_CREATE(2), &thermal_info)) != ONLP_STATUS_OK) + goto _EXIT; + + temp2 = thermal_info.mcelsius; + + new_temp = (temp1+temp2)/2; + + /* check fan status */ + for (i=1; i<=FAN_NUM_ON_MAIN_BROAD; i++) + { + if ((rc = onlp_fan_info_get(ONLP_FAN_ID_CREATE(i), &fan_info)) != ONLP_STATUS_OK) + goto _EXIT; + + if (ONLP_OID_FAILED(&fan_info)) + { + new_perc = LEV1_SPEED_PERC; + goto _CTRL; + } + } + + diff = new_temp - ori_temp; + + if (diff == 0) + goto _EXIT; + else + is_up = (diff > 0 ? 1 : 0); + + if (is_up) + { + if (new_temp >= LEV1_UP_TEMP) + new_perc = LEV1_SPEED_PERC; + else if (new_temp >= LEV2_UP_TEMP) + new_perc = LEV2_SPEED_PERC; + else if (new_temp >= LEV3_UP_TEMP) + new_perc = LEV3_SPEED_PERC; + else + new_perc = LEV4_SPEED_PERC; + } + else + { + if (new_temp <= LEV4_DOWN_TEMP) + new_perc = LEV4_SPEED_PERC; + else if (new_temp <= LEV3_DOWN_TEMP) + new_perc = LEV3_SPEED_PERC; + else if (new_temp <= LEV2_DOWN_TEMP) + new_perc = LEV2_SPEED_PERC; + else + new_perc = LEV1_SPEED_PERC; + } + +_CTRL : + + if (ori_perc == new_perc) + goto _EXIT; + + /* ctrl fans */ + AIM_LOG_INFO("Fan Speeds are now at %d%%", new_perc); + + if ((rc = onlp_fan_percentage_set(ONLP_FAN_ID_CREATE(1), new_perc)) != ONLP_STATUS_OK) + goto _EXIT; + + /* update om */ + ori_perc = new_perc; + ori_temp = new_temp; + +_EXIT : + + return rc; } diff --git a/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/psui.c b/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/psui.c index bc753041..a6e6e3bd 100755 --- a/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/psui.c +++ b/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/psui.c @@ -34,20 +34,13 @@ #define PSU_NODE_MAX_INT_LEN 8 #define PSU_NODE_MAX_PATH_LEN 64 -#define VALIDATE(_id) \ - do { \ - if(!ONLP_OID_IS_PSU(_id)) { \ - return ONLP_STATUS_E_INVALID; \ - } \ - } while(0) - -static int +static int psu_status_info_get(int id, int is_ac, char *node, int *value) { int ret = 0; char buf[PSU_NODE_MAX_INT_LEN + 1] = {0}; char node_path[PSU_NODE_MAX_PATH_LEN] = {0}; - + *value = 0; if (PSU1_ID == id) { @@ -66,13 +59,13 @@ psu_status_info_get(int id, int is_ac, char *node, int *value) return ret; } -static int +static int psu_cpr_4011_pmbus_info_get(int id, char *node, int *value) { int ret = 0; char buf[PSU_NODE_MAX_INT_LEN + 1] = {0}; char node_path[PSU_NODE_MAX_PATH_LEN] = {0}; - + *value = 0; if (PSU1_ID == id) { @@ -102,14 +95,14 @@ psu_cpr_4011_info_get(onlp_psu_info_t* info) { int val = 0; int index = ONLP_OID_ID_GET(info->hdr.id); - + /* Set capability */ - info->caps = ONLP_PSU_CAPS_AC; - - if (info->status & ONLP_PSU_STATUS_FAILED) { - return ONLP_STATUS_OK; - } + info->type = ONLP_PSU_TYPE_AC; + + if (ONLP_OID_FAILED(info)) { + return ONLP_STATUS_OK; + } /* Set the associated oid_table */ info->hdr.coids[0] = ONLP_FAN_ID_CREATE(index + CHASSIS_FAN_COUNT); @@ -118,33 +111,33 @@ psu_cpr_4011_info_get(onlp_psu_info_t* info) /* Read voltage, current and power */ if (psu_cpr_4011_pmbus_info_get(index, "psu_v_out", &val) == 0) { info->mvout = val; - info->caps |= ONLP_PSU_CAPS_VOUT; + info->caps |= ONLP_PSU_CAPS_GET_VOUT; } if (psu_cpr_4011_pmbus_info_get(index, "psu_v_in", &val) == 0) { info->mvin = val; - info->caps |= ONLP_PSU_CAPS_VIN; + info->caps |= ONLP_PSU_CAPS_GET_VIN; } if (psu_cpr_4011_pmbus_info_get(index, "psu_i_out", &val) == 0) { info->miout = val; - info->caps |= ONLP_PSU_CAPS_IOUT; + info->caps |= ONLP_PSU_CAPS_GET_IOUT; } - + if (psu_cpr_4011_pmbus_info_get(index, "psu_i_in", &val) == 0) { info->miin = val; - info->caps |= ONLP_PSU_CAPS_IIN; + info->caps |= ONLP_PSU_CAPS_GET_IIN; } if (psu_cpr_4011_pmbus_info_get(index, "psu_p_out", &val) == 0) { info->mpout = val; - info->caps |= ONLP_PSU_CAPS_POUT; - } + info->caps |= ONLP_PSU_CAPS_GET_POUT; + } if (psu_cpr_4011_pmbus_info_get(index, "psu_p_in", &val) == 0) { info->mpin = val; - info->caps |= ONLP_PSU_CAPS_PIN; - } + info->caps |= ONLP_PSU_CAPS_GET_PIN; + } return ONLP_STATUS_OK; } @@ -156,9 +149,9 @@ psu_um400d_info_get(onlp_psu_info_t* info) /* Set capability */ - info->caps = ONLP_PSU_CAPS_DC48; + info->type = ONLP_PSU_TYPE_DC48; - if (info->status & ONLP_PSU_STATUS_FAILED) { + if (ONLP_OID_FAILED(info)) { return ONLP_STATUS_OK; } @@ -173,12 +166,12 @@ psu_ym2401_info_get(onlp_psu_info_t* info) { int val = 0; int index = ONLP_OID_ID_GET(info->hdr.id); - + /* Set capability */ - info->caps = ONLP_PSU_CAPS_AC; - - if (info->status & ONLP_PSU_STATUS_FAILED) { + info->type = ONLP_PSU_TYPE_AC; + + if (ONLP_OID_FAILED(info)) { return ONLP_STATUS_OK; } @@ -189,18 +182,18 @@ psu_ym2401_info_get(onlp_psu_info_t* info) /* Read voltage, current and power */ if (psu_ym2401_pmbus_info_get(index, "psu_v_out", &val) == 0) { info->mvout = val; - info->caps |= ONLP_PSU_CAPS_VOUT; + info->caps |= ONLP_PSU_CAPS_GET_VOUT; } if (psu_ym2401_pmbus_info_get(index, "psu_i_out", &val) == 0) { info->miout = val; - info->caps |= ONLP_PSU_CAPS_IOUT; + info->caps |= ONLP_PSU_CAPS_GET_IOUT; } if (psu_ym2401_pmbus_info_get(index, "psu_p_out", &val) == 0) { info->mpout = val; - info->caps |= ONLP_PSU_CAPS_POUT; - } + info->caps |= ONLP_PSU_CAPS_GET_POUT; + } return ONLP_STATUS_OK; } @@ -220,45 +213,42 @@ static onlp_psu_info_t pinfo[] = }; int -onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) +onlp_psui_info_get(onlp_oid_id_t id, onlp_psu_info_t* info) { int val = 0; int ret = ONLP_STATUS_OK; - int index = ONLP_OID_ID_GET(id); int is_ac=1; - psu_type_t psu_type; - - VALIDATE(id); + psu_type_t psu_type; memset(info, 0, sizeof(onlp_psu_info_t)); - *info = pinfo[index]; /* Set the onlp_oid_hdr_t */ + *info = pinfo[id]; /* Set the onlp_oid_hdr_t */ /* Get the present state */ - if (psu_status_info_get(index, 1, "psu_present", &val) != 0) { - printf("Unable to read PSU(%d) node(psu_present)\r\n", index); + if (psu_status_info_get(id, 1, "psu_present", &val) != 0) { + printf("Unable to read PSU(%d) node(psu_present)\r\n", id); } if (val != PSU_STATUS_PRESENT) { - info->status &= ~ONLP_PSU_STATUS_PRESENT; + ONLP_OID_STATUS_FLAG_CLR(info, PRESENT); return ONLP_STATUS_OK; } - info->status |= ONLP_PSU_STATUS_PRESENT; - + ONLP_OID_STATUS_FLAG_SET(info, PRESENT); + /* Get power good status */ - if (psu_status_info_get(index, 1, "psu_power_good", &val) != 0) { - printf("Unable to read PSU(%d) node(psu_power_good)\r\n", index); + if (psu_status_info_get(id, 1, "psu_power_good", &val) != 0) { + printf("Unable to read PSU(%d) node(psu_power_good)\r\n", id); } if (val != PSU_STATUS_POWER_GOOD) { - info->status |= ONLP_PSU_STATUS_FAILED; + ONLP_OID_STATUS_FLAG_SET(info, FAILED); return 0; } /* Get PSU type */ - psu_type = get_psu_type(index, info->model, sizeof(info->model)); + psu_type = get_psu_type(id, info->model, sizeof(info->model)); switch (psu_type) { case PSU_TYPE_AC_COMPUWARE_F2B: @@ -278,14 +268,7 @@ onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) ret = ONLP_STATUS_E_UNSUPPORTED; break; } - psu_serial_number_get(index, is_ac, info->serial, sizeof(info->serial)); + psu_serial_number_get(id, is_ac, info->serial, sizeof(info->serial)); return ret; } - -int -onlp_psui_ioctl(onlp_oid_t pid, va_list vargs) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - diff --git a/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/sfpi.c b/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/sfpi.c index f731e0d3..b41198bb 100644 --- a/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/sfpi.c @@ -95,7 +95,7 @@ onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap) } int -onlp_sfpi_port_map(int port, int* rport) +onlp_sfpi_port_map(onlp_oid_id_t port, int* rport) { /* * The QSFP port numbering on the powerpc-as5812-54x-r0b platform @@ -167,7 +167,7 @@ port_qsfp_cpld_map__(int port, int* rport) } int -onlp_sfpi_is_present(int port) +onlp_sfpi_is_present(onlp_oid_id_t port) { /* * Return 1 if present. @@ -176,7 +176,7 @@ onlp_sfpi_is_present(int port) */ int present; int addr = (port < 24) ? 61 : 62; - + if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, addr, (port+1)) < 0) { AIM_LOG_ERROR("Unable to read present status from port(%d)\r\n", port); return ONLP_STATUS_E_INTERNAL; @@ -297,89 +297,43 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) } int -onlp_sfpi_eeprom_read(int port, uint8_t data[256]) +onlp_sfpi_dev_read(onlp_oid_id_t port, int devaddr, int addr, + uint8_t* dst, int size) { - /* - * Read the SFP eeprom into data[] - * - * Return MISSING if SFP is missing. - * Return OK if eeprom is read - */ - int size = 0; - memset(data, 0, 256); - - if(onlp_file_read(data, 256, &size, PORT_EEPROM_FORMAT, front_port_bus_index(port)) != ONLP_STATUS_OK) { - AIM_LOG_ERROR("Unable to read eeprom from port(%d)\r\n", port); - return ONLP_STATUS_E_INTERNAL; - } - - if (size != 256) { - AIM_LOG_ERROR("Unable to read eeprom from port(%d), size is different!\r\n", port); - return ONLP_STATUS_E_INTERNAL; - } - - return ONLP_STATUS_OK; + int bus = front_port_bus_index(port); + return onlp_i2c_block_read(bus, devaddr, addr, size, dst, ONLP_I2C_F_FORCE); } int -onlp_sfpi_dom_read(int port, uint8_t data[256]) -{ - FILE* fp; - char file[64] = {0}; - - sprintf(file, PORT_EEPROM_FORMAT, front_port_bus_index(port)); - fp = fopen(file, "r"); - if(fp == NULL) { - AIM_LOG_ERROR("Unable to open the eeprom device file of port(%d)", port); - return ONLP_STATUS_E_INTERNAL; - } - - if (fseek(fp, 256, SEEK_CUR) != 0) { - fclose(fp); - AIM_LOG_ERROR("Unable to set the file position indicator of port(%d)", port); - return ONLP_STATUS_E_INTERNAL; - } - - int ret = fread(data, 1, 256, fp); - fclose(fp); - if (ret != 256) { - AIM_LOG_ERROR("Unable to read the module_eeprom device file of port(%d)", port); - return ONLP_STATUS_E_INTERNAL; - } - - return ONLP_STATUS_OK; -} - -int -onlp_sfpi_dev_readb(int port, uint8_t devaddr, uint8_t addr) +onlp_sfpi_dev_readb(onlp_oid_id_t port, int devaddr, int addr) { int bus = front_port_bus_index(port); return onlp_i2c_readb(bus, devaddr, addr, ONLP_I2C_F_FORCE); } int -onlp_sfpi_dev_writeb(int port, uint8_t devaddr, uint8_t addr, uint8_t value) +onlp_sfpi_dev_writeb(onlp_oid_id_t port, int devaddr, int addr, uint8_t value) { int bus = front_port_bus_index(port); return onlp_i2c_writeb(bus, devaddr, addr, value, ONLP_I2C_F_FORCE); } int -onlp_sfpi_dev_readw(int port, uint8_t devaddr, uint8_t addr) +onlp_sfpi_dev_readw(onlp_oid_id_t port, int devaddr, int addr) { int bus = front_port_bus_index(port); return onlp_i2c_readw(bus, devaddr, addr, ONLP_I2C_F_FORCE); } int -onlp_sfpi_dev_writew(int port, uint8_t devaddr, uint8_t addr, uint16_t value) +onlp_sfpi_dev_writew(onlp_oid_id_t port, int devaddr, int addr, uint16_t value) { int bus = front_port_bus_index(port); return onlp_i2c_writew(bus, devaddr, addr, value, ONLP_I2C_F_FORCE); } int -onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) +onlp_sfpi_control_set(onlp_oid_id_t port, onlp_sfp_control_t control, int value) { int rv; @@ -412,7 +366,7 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) } int -onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) +onlp_sfpi_control_get(onlp_oid_id_t port, onlp_sfp_control_t control, int* value) { int rv; @@ -472,4 +426,3 @@ onlp_sfpi_denit(void) { return ONLP_STATUS_OK; } - diff --git a/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/sysi.c b/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/sysi.c deleted file mode 100644 index 156fc771..00000000 --- a/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/sysi.c +++ /dev/null @@ -1,274 +0,0 @@ -/************************************************************ - * - * - * Copyright 2014 Big Switch Networks, Inc. - * Copyright 2015 Accton Technology Corporation. - * - * Licensed under the Eclipse Public License, Version 1.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific - * language governing permissions and limitations under the - * License. - * - * - ************************************************************ - * - * - * - ***********************************************************/ -#include -#include -#include -#include -#include -#include - -#include "x86_64_accton_as5812_54x_int.h" -#include "x86_64_accton_as5812_54x_log.h" -#include "platform_lib.h" -#include -#include - -#define LOCAL_DEBUG 0 - -#define OPEN_READ_FILE(fd,fullpath,data,nbytes,len) \ - if (LOCAL_DEBUG) \ - printf("[Debug][%s][%d][openfile: %s]\n", __FUNCTION__, __LINE__, fullpath); \ - if ((fd = open(fullpath, O_RDONLY)) == -1) \ - return ONLP_STATUS_E_INTERNAL; \ - if ((len = read(fd, r_data, nbytes)) <= 0){ \ - close(fd); \ - return ONLP_STATUS_E_INTERNAL;} \ - if (LOCAL_DEBUG) \ - printf("[Debug][%s][%d][read data: %s][len:%d]\n", __FUNCTION__, __LINE__, r_data, len); \ - if (close(fd) == -1) \ - return ONLP_STATUS_E_INTERNAL - - -#define PREFIX_PATH_ON_CPLD_DEV "/sys/bus/i2c/devices/" -#define NUM_OF_CPLD 3 -static char arr_cplddev_name[NUM_OF_CPLD][10] = -{ - "0-0060", - "0-0061", - "0-0062" -}; - -const char* -onlp_sysi_platform_get(void) -{ - return "x86-64-accton-as5812-54x-r0"; -} - -int -onlp_sysi_onie_data_get(uint8_t** data, int* size) -{ - uint8_t* rdata = aim_zmalloc(256); - if(onlp_file_read(rdata, 256, size, IDPROM_PATH) == ONLP_STATUS_OK) { - if(*size == 256) { - *data = rdata; - return ONLP_STATUS_OK; - } - } - - aim_free(rdata); - *size = 0; - return ONLP_STATUS_E_INTERNAL; -} - -int -onlp_sysi_platform_info_get(onlp_platform_info_t* pi) -{ - int i, siz=NUM_OF_CPLD, v[NUM_OF_CPLD]={0}; - int fd, len, nbytes = 10; - char r_data[10] = {0}; - char fullpath[65] = {0}; - - for (i=0; icpld_versions = aim_fstrdup("%d.%d.%d", v[0], v[1], v[2]); - else - printf("This CPLD numbers are wrong !! \n"); - - return 0; -} - -void -onlp_sysi_platform_info_free(onlp_platform_info_t* pi) -{ - aim_free(pi->cpld_versions); -} - - -int -onlp_sysi_oids_get(onlp_oid_t* table, int max) -{ - onlp_oid_t* e = table; - memset(table, 0, max*sizeof(onlp_oid_t)); - int i; - - /* 2 PSUs */ - *e++ = ONLP_PSU_ID_CREATE(1); - *e++ = ONLP_PSU_ID_CREATE(2); - - /* LEDs Item */ - for (i=1; i<=CHASSIS_LED_COUNT; i++) - { - *e++ = ONLP_LED_ID_CREATE(i); - } - - /* THERMALs Item */ - for (i=1; i<=CHASSIS_THERMAL_COUNT; i++) - { - *e++ = ONLP_THERMAL_ID_CREATE(i); - } - - /* Fans Item */ - for (i=1; i<=CHASSIS_FAN_COUNT; i++) - { - *e++ = ONLP_FAN_ID_CREATE(i); - } - - return 0; -} - -/* - * 1. If any FAN failed, set all the other fans as full speed (100%) - * 2. When (LM75-1 + LM75-2)/2 >= 49.5 C, set fan speed from 40% to 65%. - * 3. When (LM75-1 + LM75-2)/2 >= 53C, set fan speed from 65% to 80% - * 4. When (LM75-1 + LM75-2)/2 >= 57.7C, set fan speed from 80% to 100% - - * 5. When (LM75-1 + LM75-2)/2 <= 52.7C, set fan speed from 100% to 80% - * 6. When (LM75-1 + LM75-2)/2 <= 47.7C, set fan speed from 80% to 65% - * 7. When (LM75-1 + LM75-2)/2 <= 42.7C, set fan speed from 65% to 40% - * 8. The default FAN speed is 40% - */ -int -onlp_sysi_platform_manage_fans(void) -{ -#define LEV1_UP_TEMP 57500 /*temperature*/ -#define LEV1_DOWN_TEMP NULL /* unused */ -#define LEV1_SPEED_PERC 100 /*percentage*/ - -#define LEV2_UP_TEMP 53000 -#define LEV2_DOWN_TEMP 52700 -#define LEV2_SPEED_PERC 80 - -#define LEV3_UP_TEMP 49500 -#define LEV3_DOWN_TEMP 47700 -#define LEV3_SPEED_PERC 65 - -#define LEV4_UP_TEMP NULL /* unused */ -#define LEV4_DOWN_TEMP 42700 -#define LEV4_SPEED_PERC 40 - -#define FAN_NUM_ON_MAIN_BROAD 5 - - - int rc, i; - int is_up; - int new_temp, temp1, temp2, diff; - static int new_perc = 0, ori_perc = 0; - static int ori_temp = 0; - onlp_thermal_info_t thermal_info; - onlp_fan_info_t fan_info; - - /* get new temperature */ - if ((rc = onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(1), &thermal_info)) != ONLP_STATUS_OK) - goto _EXIT; - - temp1 = thermal_info.mcelsius; - - if ((rc = onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(2), &thermal_info)) != ONLP_STATUS_OK) - goto _EXIT; - - temp2 = thermal_info.mcelsius; - - new_temp = (temp1+temp2)/2; - - /* check fan status */ - for (i=1; i<=FAN_NUM_ON_MAIN_BROAD; i++) - { - if ((rc = onlp_fani_info_get(ONLP_FAN_ID_CREATE(i), &fan_info)) != ONLP_STATUS_OK) - goto _EXIT; - - if (fan_info.status & ONLP_FAN_STATUS_FAILED) - { - new_perc = LEV1_SPEED_PERC; - goto _CTRL; - } - } - - diff = new_temp - ori_temp; - - if (diff == 0) - goto _EXIT; - else - is_up = (diff > 0 ? 1 : 0); - - if (is_up) - { - if (new_temp >= LEV1_UP_TEMP) - new_perc = LEV1_SPEED_PERC; - else if (new_temp >= LEV2_UP_TEMP) - new_perc = LEV2_SPEED_PERC; - else if (new_temp >= LEV3_UP_TEMP) - new_perc = LEV3_SPEED_PERC; - else - new_perc = LEV4_SPEED_PERC; - } - else - { - if (new_temp <= LEV4_DOWN_TEMP) - new_perc = LEV4_SPEED_PERC; - else if (new_temp <= LEV3_DOWN_TEMP) - new_perc = LEV3_SPEED_PERC; - else if (new_temp <= LEV2_DOWN_TEMP) - new_perc = LEV2_SPEED_PERC; - else - new_perc = LEV1_SPEED_PERC; - } - -_CTRL : - - if (LOCAL_DEBUG) - printf("\n[DEBUG][%s][%d]{ori:temp=%d, perc=%d} {new:temp=%d, perc=%d}\n", __FUNCTION__, __LINE__, - ori_temp, ori_perc, new_temp, new_perc); - - if (ori_perc == new_perc) - goto _EXIT; - - /* ctrl fans */ - AIM_LOG_INFO("Fan Speeds are now at %d%%", new_perc); - - if ((rc = onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), new_perc)) != ONLP_STATUS_OK) - goto _EXIT; - - /* update om */ - ori_perc = new_perc; - ori_temp = new_temp; - -_EXIT : - - return rc; -} - -int -onlp_sysi_platform_manage_leds(void) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} diff --git a/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/thermali.c b/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/thermali.c index c4b2e2e5..1d679a2a 100644 --- a/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/thermali.c +++ b/packages/platforms/accton/x86-64/as5812-54x/onlp/builds/x86_64_accton_as5812_54x/module/src/thermali.c @@ -28,15 +28,6 @@ #include #include "platform_lib.h" - -#define VALIDATE(_id) \ - do { \ - if(!ONLP_OID_IS_THERMAL(_id)) { \ - return ONLP_STATUS_E_INVALID; \ - } \ - } while(0) - - enum onlp_thermal_id { THERMAL_RESERVED = 0, THERMAL_CPU_CORE, @@ -69,45 +60,14 @@ static char* cpu_coretemp_files[] = /* Static values */ static onlp_thermal_info_t linfo[] = { { }, /* Not used */ - { { ONLP_THERMAL_ID_CREATE(THERMAL_CPU_CORE), "CPU Core", 0}, - ONLP_THERMAL_STATUS_PRESENT, - ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS - }, - { { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_MAIN_BROAD), "Chassis Thermal Sensor 1 (Front middle)", 0}, - ONLP_THERMAL_STATUS_PRESENT, - ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS - }, - { { ONLP_THERMAL_ID_CREATE(THERMAL_2_ON_MAIN_BROAD), "Chassis Thermal Sensor 2 (Rear right)", 0}, - ONLP_THERMAL_STATUS_PRESENT, - ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS - }, - { { ONLP_THERMAL_ID_CREATE(THERMAL_3_ON_MAIN_BROAD), "Chassis Thermal Sensor 3 (Front right)", 0}, - ONLP_THERMAL_STATUS_PRESENT, - ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS - }, - { { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_PSU1), "PSU-1 Thermal Sensor 1", ONLP_PSU_ID_CREATE(1)}, - ONLP_THERMAL_STATUS_PRESENT, - ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS - }, - { { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_PSU2), "PSU-2 Thermal Sensor 1", ONLP_PSU_ID_CREATE(2)}, - ONLP_THERMAL_STATUS_PRESENT, - ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS - } + ONLP_CHASSIS_THERMAL_INFO_ENTRY_INIT(THERMAL_CPU_CORE, "CPU Core"), + ONLP_CHASSIS_THERMAL_INFO_ENTRY_INIT(THERMAL_1_ON_MAIN_BROAD, "Chassis Thermal Sensor 1 (Front middle)"), + ONLP_CHASSIS_THERMAL_INFO_ENTRY_INIT(THERMAL_2_ON_MAIN_BROAD, "Chassis Thermal Sensor 2 (Rear right)"), + ONLP_CHASSIS_THERMAL_INFO_ENTRY_INIT(THERMAL_3_ON_MAIN_BROAD, "Chassis Thermal Sensor 3 (Front right)"), + ONLP_PSU_THERMAL_INFO_ENTRY_INIT(THERMAL_1_ON_PSU1, "PSU-1 Thermal Sensor 1", 1), + ONLP_PSU_THERMAL_INFO_ENTRY_INIT(THERMAL_1_ON_PSU2, "PSU-2 Thermal Sensor 1", 2), }; - - - -/* - * This will be called to intiialize the thermali subsystem. - */ -int -onlp_thermali_init(void) -{ - return ONLP_STATUS_OK; -} - - /* * Retrieve the information structure for the given thermal OID. * @@ -119,25 +79,20 @@ onlp_thermali_init(void) * structure even if the sensor described by the OID is not present. */ int -onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info) +onlp_thermali_info_get(onlp_oid_id_t id, onlp_thermal_info_t* info) { - int local_id; int psu_id; psu_type_t psu_type; - VALIDATE(id); - - local_id = ONLP_OID_ID_GET(id); - /* Set the onlp_oid_hdr_t and capabilities */ - *info = linfo[local_id]; + *info = linfo[id]; - if(local_id == THERMAL_CPU_CORE) { + if(id == THERMAL_CPU_CORE) { int rv = onlp_file_read_int_max(&info->mcelsius, cpu_coretemp_files); return rv; } - psu_id = local_id - THERMAL_1_ON_PSU1 + 1; + psu_id = id - THERMAL_1_ON_PSU1 + 1; psu_type = get_psu_type(psu_id, NULL, 0); if (psu_type == PSU_TYPE_AC_3YPOWER_F2B || psu_type == PSU_TYPE_AC_3YPOWER_B2F ) { @@ -145,5 +100,5 @@ onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info) return rv; } - return onlp_file_read_int(&info->mcelsius, devfiles[local_id]); + return onlp_file_read_int(&info->mcelsius, devfiles[id]); }