diff --git a/builds/any/rootfs/stretch/common/all-base-packages.yml b/builds/any/rootfs/stretch/common/all-base-packages.yml index e518d6ea39..ed3781adcf 100644 --- a/builds/any/rootfs/stretch/common/all-base-packages.yml +++ b/builds/any/rootfs/stretch/common/all-base-packages.yml @@ -88,3 +88,5 @@ - tree - memtester - ipmitool +- curl +- libcurl3-nss diff --git a/builds/any/rootfs/stretch/standard/standard.yml b/builds/any/rootfs/stretch/standard/standard.yml index ca234abea0..aeedec7907 100644 --- a/builds/any/rootfs/stretch/standard/standard.yml +++ b/builds/any/rootfs/stretch/standard/standard.yml @@ -29,14 +29,14 @@ Multistrap: Debian: packages: *Packages - source: http://${DEBIAN_MIRROR} + source: http://archive.debian.org/debian/ suite: ${ONL_DEBIAN_SUITE} keyring: debian-archive-keyring omitdebsrc: true Debian-Local: packages: *Packages - source: http://${APT_CACHE}${DEBIAN_MIRROR} + source: http://${APT_CACHE}archive.debian.org/debian/ suite: ${ONL_DEBIAN_SUITE} keyring: debian-archive-keyring omitdebsrc: true diff --git a/packages/base/any/kernels/4.19-lts/configs/x86_64-all/x86_64-all.config b/packages/base/any/kernels/4.19-lts/configs/x86_64-all/x86_64-all.config index 6d46e78196..63062851b9 100644 --- a/packages/base/any/kernels/4.19-lts/configs/x86_64-all/x86_64-all.config +++ b/packages/base/any/kernels/4.19-lts/configs/x86_64-all/x86_64-all.config @@ -1951,8 +1951,40 @@ CONFIG_USB_NET_DRIVERS=y # CONFIG_USB_RTL8150 is not set # CONFIG_USB_RTL8152 is not set # CONFIG_USB_LAN78XX is not set -# CONFIG_USB_USBNET is not set +CONFIG_USB_USBNET=y +# CONFIG_USB_NET_AX8817X is not set +# CONFIG_USB_NET_AX88179_178A is not set +CONFIG_USB_NET_CDCETHER=y +CONFIG_USB_NET_CDC_EEM=y +CONFIG_USB_NET_CDC_NCM=y +CONFIG_USB_NET_HUAWEI_CDC_NCM=y +CONFIG_USB_NET_CDC_MBIM=y +# CONFIG_USB_NET_DM9601 is not set +# CONFIG_USB_NET_SR9700 is not set +# CONFIG_USB_NET_SR9800 is not set +# CONFIG_USB_NET_SMSC75XX is not set +# CONFIG_USB_NET_SMSC95XX is not set +# CONFIG_USB_NET_GL620A is not set +# CONFIG_USB_NET_NET1080 is not set +# CONFIG_USB_NET_PLUSB is not set +# CONFIG_USB_NET_MCS7830 is not set +# CONFIG_USB_NET_RNDIS_HOST is not set +CONFIG_USB_NET_CDC_SUBSET=y +# CONFIG_USB_ALI_M5632 is not set +# CONFIG_USB_AN2720 is not set +# CONFIG_USB_BELKIN is not set +# CONFIG_USB_ARMLINUX is not set +# CONFIG_USB_EPSON2888 is not set +# CONFIG_USB_KC2190 is not set +# CONFIG_USB_NET_ZAURUS is not set +# CONFIG_USB_NET_CX82310_ETH is not set +# CONFIG_USB_NET_KALMIA is not set +# CONFIG_USB_NET_QMI_WWAN is not set +# CONFIG_USB_NET_INT51X1 is not set # CONFIG_USB_IPHETH is not set +# CONFIG_USB_SIERRA_NET is not set +# CONFIG_USB_VL600 is not set +# CONFIG_USB_NET_CH9200 is not set # CONFIG_WLAN is not set # @@ -3231,7 +3263,7 @@ CONFIG_USB_UHCI_HCD=y # CONFIG_USB_ACM=y CONFIG_USB_PRINTER=y -# CONFIG_USB_WDM is not set +CONFIG_USB_WDM=y # CONFIG_USB_TMC is not set # diff --git a/packages/base/any/onlp/src/onlplib/module/make.mk b/packages/base/any/onlp/src/onlplib/module/make.mk index 12269c44b1..0294f225a8 100644 --- a/packages/base/any/onlp/src/onlplib/module/make.mk +++ b/packages/base/any/onlp/src/onlplib/module/make.mk @@ -28,6 +28,7 @@ onlplib_INCLUDES := -I $(THIS_DIR)inc onlplib_INTERNAL_INCLUDES := -I $(THIS_DIR)src onlplib_DEPENDMODULE_ENTRIES := init:onlplib +GLOBAL_LINK_LIBS += -lcurl ifeq ($(ONL_DEBIAN_SUITE),buster) GLOBAL_CFLAGS += -DONLPLIB_CONFIG_I2C_INCLUDE_SMBUS=1 GLOBAL_LINK_LIBS += -li2c diff --git a/packages/platforms/accton/x86-64/as9516-32d/onlp/builds/x86_64_accton_as9516_32d/module/src/fani.c b/packages/platforms/accton/x86-64/as9516-32d/onlp/builds/x86_64_accton_as9516_32d/module/src/fani.c index f909aa649a..f01c69ba83 100644 --- a/packages/platforms/accton/x86-64/as9516-32d/onlp/builds/x86_64_accton_as9516_32d/module/src/fani.c +++ b/packages/platforms/accton/x86-64/as9516-32d/onlp/builds/x86_64_accton_as9516_32d/module/src/fani.c @@ -25,8 +25,8 @@ ***********************************************************/ #include #include - #include "platform_lib.h" +#include #define VALIDATE(_id) \ do { \ @@ -35,19 +35,6 @@ } \ } while(0) -#define MAX_FAN_SPEED 21000 - -enum fan_id { - FAN_1_ON_FAN_BOARD = 1, - FAN_2_ON_FAN_BOARD, - FAN_3_ON_FAN_BOARD, - FAN_4_ON_FAN_BOARD, - FAN_5_ON_FAN_BOARD, - FAN_6_ON_FAN_BOARD, -}; - -#define FAN_BOARD_PATH "/sys/bus/i2c/devices/8-0066/" - #define CHASSIS_FAN_INFO(fid) \ { \ { ONLP_FAN_ID_CREATE(FAN_##fid##_ON_FAN_BOARD), "Chassis Fan - "#fid, 0 },\ @@ -58,6 +45,16 @@ enum fan_id { ONLP_FAN_MODE_INVALID,\ } +#define PSU_FAN_INFO(pid) \ + { \ + { ONLP_FAN_ID_CREATE(FAN_ON_PSU_##pid), "PSU "#pid" - Fan ", 0 },\ + 0x0,\ + ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE,\ + 0,\ + 0,\ + ONLP_FAN_MODE_INVALID,\ + } + /* Static fan information */ onlp_fan_info_t finfo[] = { { }, /* Not used */ @@ -67,8 +64,137 @@ onlp_fan_info_t finfo[] = { CHASSIS_FAN_INFO(4), CHASSIS_FAN_INFO(5), CHASSIS_FAN_INFO(6), + PSU_FAN_INFO(1), + PSU_FAN_INFO(2) }; +static uint32_t farr[curl_data_fan_num]; +static uint32_t ps[curl_data_psu_num]; +/* + * This function will be called prior to all of onlp_fani_* functions. + */ +void fan_call_back(void *p) +{ + uint8_t i = 0; + uint8_t j = 0; + uint8_t k = 0; + char *data_loc_start; + char *data_loc_end; + char str[20]; + const char *ptr = (const char *)p; + + for (i = 0; i < curl_data_fan_num; i++) { + farr[i] = 0; + } + + if (ptr == NULL) { + AIM_LOG_ERROR("NULL POINTER PASSED to call back function\n"); + return; + } + + data_loc_start = strchr(ptr, '['); + data_loc_end = strchr(ptr, ']'); + if((data_loc_start == NULL) || (data_loc_end == NULL)) + { + AIM_LOG_ERROR("Failed CURL response data.\n"); + return; + } + + i = data_loc_start - ptr; + while (ptr[i] && ptr[i] != ']') { + j = 0; + while (ptr[i] != ',' && ptr[i] != ']') { + str[j] = ptr[i]; + j++; + i++; + } + + str[j] = '\0'; + + if (k < curl_data_fan_num) + { + if (k == 0) + farr[k] = atoi(str+1); + else + farr[k] = atoi(str); + k++; + } + + if (ptr[i] == ']') + break; + + i++; + } + + return; +} + +static void ps_call_back(void *p) +{ + int i = 0; + int j = 0; + int k = 0; + char *data_loc_start; + char *data_loc_end; + char str[32]; + const char *ptr = (const char *)p; + + for (i = 0; i < curl_data_psu_num; i++) + ps[i] = 0; + + if (ptr == NULL) + { + AIM_LOG_ERROR("NULL POINTER PASSED to call back function\n"); + return; + } + + data_loc_start = strchr(ptr, '['); + data_loc_end = strchr(ptr, ']'); + if((data_loc_start == NULL) || (data_loc_end == NULL)) + { + AIM_LOG_ERROR("Failed CURL response data.\n"); + return; + } + /* Start to parse from the first value, ignore '[' */ + i = data_loc_start - ptr + 1; + while (ptr[i] && ptr[i] != ']') + { + j = 0; + while (ptr[i] != ',' && ptr[i] != ']') + { + str[j] = ptr[i]; + j++; + i++; + } + + if (j >= PS_DESC_LEN) + { /* sanity check */ + AIM_LOG_ERROR("bad string len from BMC i %d j %d k %d 0x%02x\n", i, j, k, ptr[i]); + return; + } + + str[j] = '\0'; + + if (k < curl_data_psu_num) + { + /* There are three string - model name/serial/model ver */ + if ((k < curl_data_loc_psu_model_name) || (k > curl_data_loc_psu_model_ver)) + { + ps[k] = atoi(str); + } + + k++; + } + + if (ptr[i] == ']') + break; + + i++; + } + + return; +} + /* * This function will be called prior to all of onlp_fani_* functions. */ @@ -81,69 +207,107 @@ onlp_fani_init(void) int onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* info) { - int value = 0, fid; - char path[64] = {0}; - VALIDATE(id); + int fid; + int front_fan_speed = 0, read_fan_speed = 0; + int fan_present = 0; + char url[256] = {0}; + int curlid = 0; + int still_running = 1; + CURLMcode mc; + VALIDATE(id); fid = ONLP_OID_ID_GET(id); *info = finfo[fid]; - /* get fan present status - */ - sprintf(path, "%s""fantray%d_present", FAN_BOARD_PATH, fid ); - if (bmc_file_read_int(&value, path, 16) < 0) { - AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); - return ONLP_STATUS_E_INTERNAL; - } + if ((FAN_ON_PSU_1 == fid) || (FAN_ON_PSU_2 == fid)) + { + info->status |= ONLP_FAN_STATUS_PRESENT; + /* get fan direction */ + info->status |= ONLP_FAN_STATUS_F2B; + /* Get psu fan speed by curl */ + if (FAN_ON_PSU_1 == fid) + { + snprintf(url, sizeof(url),"%s""ps/1", BMC_CURL_PREFIX); + curlid = CURL_PSU_1_FAN; + } + else + { + snprintf(url, sizeof(url),"%s""ps/2", BMC_CURL_PREFIX); + curlid = CURL_PSU_2_FAN; + } - if (value == 1) { - return ONLP_STATUS_OK; /* fan is not present */ + curl_easy_setopt(curl[curlid], CURLOPT_URL, url); + curl_easy_setopt(curl[curlid], CURLOPT_WRITEFUNCTION, ps_call_back); + curl_multi_add_handle(multi_curl, curl[curlid]); + while(still_running) { + mc = curl_multi_perform(multi_curl, &still_running); + if(mc != CURLM_OK) + { + AIM_LOG_ERROR("multi_curl failed, code %d.\n", mc); + } + } + info->rpm = ps[curl_data_loc_psu_fan]; + info->percentage = (info->rpm * 100)/MAX_PSU_FAN_SPEED; + /* get fan fault status */ + if (!info->rpm) { + info->status |= ONLP_FAN_STATUS_FAILED; + } } - info->status |= ONLP_FAN_STATUS_PRESENT; + else + { + snprintf(url, sizeof(url),"%s""fan/get/%d", BMC_CURL_PREFIX, fid); - /* get front fan rpm - */ - sprintf(path, "%s""fan%d_input", FAN_BOARD_PATH, fid); + curlid = CURL_FAN_STATUS_1 + fid -1; - if (bmc_file_read_int(&value, path, 10) < 0) { - AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); - return ONLP_STATUS_E_INTERNAL; - } - info->rpm = value; + curl_easy_setopt(curl[curlid], CURLOPT_URL, url); + curl_easy_setopt(curl[curlid], CURLOPT_WRITEFUNCTION, fan_call_back); + curl_multi_add_handle(multi_curl, curl[curlid]); + while(still_running) { + mc = curl_multi_perform(multi_curl, &still_running); + if(mc != CURLM_OK) + { + AIM_LOG_ERROR("multi_curl failed, code %d.\n", mc); + } + } - /* get rear fan rpm - */ - sprintf(path, "%s""fan%d_input", FAN_BOARD_PATH, fid); - - if (bmc_file_read_int(&value, path, 10) < 0) { - AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); - return ONLP_STATUS_E_INTERNAL; - } - - /* take the min value from front/rear fan speed - */ - if (info->rpm > value) { - info->rpm = value; - } + /* In case of error */ + if (curl_data_normal != farr[curl_data_loc_fan_status]) + { + AIM_LOG_ERROR("Error returned from REST API with status %d \n", farr[curl_data_loc_fan_status]); + return ONLP_STATUS_E_INTERNAL; + } - /* set fan status based on rpm - */ - if (!info->rpm) { - info->status |= ONLP_FAN_STATUS_FAILED; - return ONLP_STATUS_OK; + fan_present = farr[curl_data_loc_fan_present]; + if (curl_data_fan_present == fan_present) { + return ONLP_STATUS_OK; /* fan is not present */ + } + info->status |= ONLP_FAN_STATUS_PRESENT; + /* get front fan rpm */ + front_fan_speed = farr[curl_data_loc_fan_front_rpm]; + /* get rear fan rpm */ + read_fan_speed = farr[curl_data_loc_fan_rear_rpm]; + /* take the min value from front/rear fan speed */ + if(front_fan_speed >= read_fan_speed) + { + info->rpm = read_fan_speed; + } + else + { + info->rpm = front_fan_speed; + } + /* set fan status based on rpm*/ + if (!info->rpm) { + info->status |= ONLP_FAN_STATUS_FAILED; + return ONLP_STATUS_OK; + } + /* get speed percentage */ + info->percentage = farr[curl_data_loc_fan_pwm]; + /* set fan direction */ + info->status |= ONLP_FAN_STATUS_F2B; } - /* get speed percentage from rpm - */ - info->percentage = (info->rpm * 100)/MAX_FAN_SPEED; - - /* set fan direction - */ - info->status |= ONLP_FAN_STATUS_F2B; - return ONLP_STATUS_OK; } - /* * This function sets the speed of the given fan in RPM. * @@ -169,14 +333,7 @@ onlp_fani_rpm_set(onlp_oid_t id, int rpm) int onlp_fani_percentage_set(onlp_oid_t id, int p) { - char path[64] = {0}; - - sprintf(path, "%d > %sfantray_pwm", p,FAN_BOARD_PATH); - if (bmc_file_write_int(p, path, 10) < 0) { - AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); - return ONLP_STATUS_E_INTERNAL; - } - return ONLP_STATUS_OK; + return ONLP_STATUS_E_UNSUPPORTED; } /* diff --git a/packages/platforms/accton/x86-64/as9516-32d/onlp/builds/x86_64_accton_as9516_32d/module/src/platform_lib.c b/packages/platforms/accton/x86-64/as9516-32d/onlp/builds/x86_64_accton_as9516_32d/module/src/platform_lib.c index ed1b70eac1..b8e1b24700 100644 --- a/packages/platforms/accton/x86-64/as9516-32d/onlp/builds/x86_64_accton_as9516_32d/module/src/platform_lib.c +++ b/packages/platforms/accton/x86-64/as9516-32d/onlp/builds/x86_64_accton_as9516_32d/module/src/platform_lib.c @@ -22,458 +22,49 @@ * * ***********************************************************/ -#include -#include -#include -#include -#include #include "platform_lib.h" -#define TTY_DEVICE "/dev/ttyACM0" -#define TTY_PROMPT "@bmc:" -#define TTY_I2C_TIMEOUT 55000 -#define TTY_BMC_LOGIN_TIMEOUT 1000000 -#define TTY_RETRY 10 -#define MAXIMUM_TTY_BUFFER_LENGTH 1024 -#define MAXIMUM_TTY_STRING_LENGTH (MAXIMUM_TTY_BUFFER_LENGTH - 1) - -static int tty_fd = -1; -static char tty_buf[MAXIMUM_TTY_BUFFER_LENGTH] = {0}; - -static int tty_open(void) -{ - int i = 20; - struct termios attr; - - if (tty_fd > -1) - { - return 0; - } - - do - { - if ((tty_fd = open(TTY_DEVICE, O_RDWR | O_NOCTTY | O_NDELAY)) > -1) - { - tcgetattr(tty_fd, &attr); - attr.c_cflag = B57600 | CS8 | CLOCAL | CREAD; - attr.c_iflag = IGNPAR; - attr.c_oflag = 0; - attr.c_lflag = 0; - attr.c_cc[VMIN] = (unsigned char) - ((MAXIMUM_TTY_STRING_LENGTH > 0xFF) ? 0xFF : MAXIMUM_TTY_STRING_LENGTH); - attr.c_cc[VTIME] = 0; - - cfsetospeed(&attr, B57600); - cfsetispeed(&attr, B57600); - tcsetattr(tty_fd, TCSANOW, &attr); - - return 0; - } - - i--; - usleep(100000); - } while (i > 0); - - return -1; -} - -static int tty_close(void) -{ - close(tty_fd); - tty_fd = -1; - - return 0; -} - -static int tty_exec_buf(unsigned long udelay, const char *str) -{ - if (tty_fd < 0) - return -1; - - write(tty_fd, tty_buf, strlen(tty_buf)+1); - usleep(udelay); - - memset(tty_buf, 0, MAXIMUM_TTY_BUFFER_LENGTH); - read(tty_fd, tty_buf, MAXIMUM_TTY_BUFFER_LENGTH); - - return (strstr(tty_buf, str) != NULL) ? 0 : -1; -} - -static int tty_login(void) -{ - int i = 10; - - for (i = 1; i <= TTY_RETRY; i++) - { - snprintf(tty_buf, MAXIMUM_TTY_BUFFER_LENGTH, "\r\r"); - if (!tty_exec_buf(TTY_BMC_LOGIN_TIMEOUT, TTY_PROMPT)) - { - return 0; - } - - if (strstr(tty_buf, "bmc login:") != NULL) - { - snprintf(tty_buf, MAXIMUM_TTY_BUFFER_LENGTH, "root\r"); - - if (!tty_exec_buf(TTY_BMC_LOGIN_TIMEOUT, "Password:")) - { - snprintf(tty_buf, MAXIMUM_TTY_BUFFER_LENGTH, "0penBmc\r"); - if (!tty_exec_buf(TTY_BMC_LOGIN_TIMEOUT, TTY_PROMPT)) - { - return 0; - } - } - } - - usleep(50000); - } - - return -1; -} - -int bmc_tty_init(void) +int bmc_curl_init(void) { int i; - if (tty_fd >= 0) - { - return 0; - } - for (i = 1; i <= TTY_RETRY; i++) + for(i = 0; i= sizeof(cmd)) - { - AIM_LOG_ERROR("cmd size overwrite (%d,%d)\r\n", ret, sizeof(cmd)); - - return ONLP_STATUS_E_INTERNAL; - } - - bmc_send_command(cmd); - - strtok(tty_buf, delimit); - flag = 0; - while( (curr = strtok(NULL, delimit)) != NULL ) - { - switch (*curr) - { - case '\n': - case '\r': - case '@': - case '^': - break; - default: - flag = 1; - break; - } - if(flag) - { - break; - } - } - - ret = snprintf(result, slen-1, "%s", curr); - if(ret >= (slen-1)) - { - AIM_LOG_ERROR("result size overwrite (%d,%d)\r\n", ret, slen-1); - - return ONLP_STATUS_E_INTERNAL; - } - - return 0; -} - -int chk_numeric_char(char *data, int base) -{ - int len, i, orig = 0; - if( *data == '\0' ) - { - return 0; - } - - len = (int) strlen(data); - if( base == 10 ) - { - for( i=0; i '9') - { - return 0; - } - } - - return 1; - } - else if( base == 16 ) - { - if(!memcmp(data, "0x", 2)) - { - if( len <= 2 ) - { - return 0; - } - orig = 2; - } - else if(!memcmp(data,"0X",2)) - { - if(len <= 2) - { - return 0; - } - orig = 2; - } - for(i=orig; i orig) && (*(data+i) == 0xd)) - { - break; - } - if((i > orig) && (*(data+i) == 0xa)) - { - break; - } - if(!(((*(data+i) >= '0') && (*(data+i) <= '9')) - || ((*(data+i) >= 'A') && (*(data+i) <= 'F')) - || ((*(data+i) >= 'a') && (*(data+i) <= 'f')))) - { - return 0; - } + AIM_LOG_ERROR("Unable to init curl[%d]\r\n", i); + return -1; } - - return 1; } + /* init a multi stack */ + multi_curl = curl_multi_init(); return 0; } -int -bmc_command_read_int(int* value, char *cmd, int base) +int bmc_curl_deinit(void) { - int len; int i; - char *prev_str = NULL; - char *current_str= NULL; - if (bmc_send_command(cmd) < 0) - { - return ONLP_STATUS_E_INTERNAL; - } - len = (int)strlen(cmd); - prev_str = strstr(tty_buf, cmd); - if (prev_str == NULL) + for(i = 0; i + #include "x86_64_accton_as9516_32d_log.h" #include "bf_pltfm_fpga.h" #include "bf_fpga_ioctl.h" +#include +#include +#include +#include +#include +#include #define DEBUG_MODE 0 @@ -45,6 +51,63 @@ #define CHASSIS_LED_COUNT 2 #define CHASSIS_PSU_COUNT 2 +#define PSU1_ID 1 +#define PSU2_ID 2 +#define PSU_PRESENT true +#define PSU_ABSCENT false +#define MAX_PSU_FAN_SPEED 23000 + +#define PS_DESC_LEN 32 +/* CURL data status */ +#define curl_data_normal 0 +#define curl_data_fan_present 1 +#define curl_data_fan_absent 0 +/* CURL data location - Thermal */ +enum curl_loc_data_thermal +{ + curl_data_loc_thermal_status = 0, + curl_data_loc_thermal_3_48, + curl_data_loc_thermal_3_49, + curl_data_loc_thermal_3_4a, + curl_data_loc_thermal_3_4b, + curl_data_loc_thermal_3_4c_max6658, + curl_data_loc_thermal_3_4d, + curl_data_thermal_num +}; +/* CURL data location - PSU */ +enum curl_loc_data_psu +{ + curl_data_loc_psu_status = 0, + curl_data_loc_psu_vin, + curl_data_loc_psu_vout, + curl_data_loc_psu_iin, + curl_data_loc_psu_pin, + curl_data_loc_psu_fan, + curl_data_loc_psu_fan_status, + curl_data_loc_psu_present, + curl_data_loc_psu_load_share, + curl_data_loc_psu_model_name, + curl_data_loc_psu_mode_serial, + curl_data_loc_psu_model_ver, + curl_data_psu_num +}; +/* CURL data location - FAN */ +enum curl_loc_data_fan +{ + curl_data_loc_fan_status = 0, + curl_data_loc_fan_id, + curl_data_loc_fan_front_rpm, + curl_data_loc_fan_rear_rpm, + curl_data_loc_fan_pwm, + curl_data_loc_fan_present, + curl_data_fan_num +}; + +#define BMC_CURL_PREFIX "http://[fe80::ff:fe00:1%usb0]:8080/api/sys/bmc/" +#define BMC_CPLD_CURL_PREFIX "http://[fe80::ff:fe00:1%usb0]:8080/api/sys/cpldget/" +#define BMC_FAN_CPLD_CURL_PREFIX "http://[fe80::ff:fe00:1%usb0]:8080/api/sys/fancpldget/" +#define CURL_IGNORE_OFFSET 17 + enum onlp_thermal_id { THERMAL_RESERVED = 0, @@ -54,24 +117,44 @@ enum onlp_thermal_id THERMAL_3_ON_MAIN_BROAD, THERMAL_4_ON_MAIN_BROAD, THERMAL_5_ON_MAIN_BROAD, - THERMAL_6_ON_MAIN_BROAD, + THERMAL_6_ON_MAIN_BROAD }; -int bmc_send_command(char *cmd); -int bmc_file_read_str(char *file, char *result, int slen); -int bmc_file_read_int(int* value, char *file, int base); -int bmc_file_write_int(int value, char *file, int base); -int bmc_i2c_readb(uint8_t bus, uint8_t devaddr, uint8_t addr); -int bmc_i2c_writeb(uint8_t bus, uint8_t devaddr, uint8_t addr, uint8_t value); -int bmc_i2c_write_quick_mode(uint8_t bus, uint8_t devaddr, uint8_t value); -int bmc_i2c_readw(uint8_t bus, uint8_t devaddr, uint8_t addr); -int bmc_i2c_readraw(uint8_t bus, uint8_t devaddr, uint8_t addr, char* data, int data_size); - +enum fan_id { + FAN_1_ON_FAN_BOARD = 1, + FAN_2_ON_FAN_BOARD, + FAN_3_ON_FAN_BOARD, + FAN_4_ON_FAN_BOARD, + FAN_5_ON_FAN_BOARD, + FAN_6_ON_FAN_BOARD, + FAN_ON_PSU_1, + FAN_ON_PSU_2 +}; -int bmc_tty_init(void); -int bmc_tty_deinit(void); +#define HANDLECOUNT 14 +enum curl_id +{ + CURL_THERMAL = 0, + CURL_PSU_STATUS_1, + CURL_PSU_STATUS_2, + CURL_FAN_STATUS_1, + CURL_FAN_STATUS_2, + CURL_FAN_STATUS_3, + CURL_FAN_STATUS_4, + CURL_FAN_STATUS_5, + CURL_FAN_STATUS_6, + CURL_PSU_1_FAN, + CURL_PSU_2_FAN, + CURL_SYS_CPLD_VER, + CURL_SYS_CPLD_SUBVER, + CURL_FAN_CPLD +}; +CURL *curl[HANDLECOUNT]; +CURLM *multi_curl; +CURLMsg *msg; -int getIndexOfSigns(char ch); +int bmc_curl_init(void); +int bmc_curl_deinit(void); /* fpga proc i2c read/write/addr read */ int fpga_proc_i2c_read(int fpga_id, uint8_t bus, uint8_t mux_i2c_addr, diff --git a/packages/platforms/accton/x86-64/as9516-32d/onlp/builds/x86_64_accton_as9516_32d/module/src/psui.c b/packages/platforms/accton/x86-64/as9516-32d/onlp/builds/x86_64_accton_as9516_32d/module/src/psui.c index 55f95d05de..a9c13995de 100644 --- a/packages/platforms/accton/x86-64/as9516-32d/onlp/builds/x86_64_accton_as9516_32d/module/src/psui.c +++ b/packages/platforms/accton/x86-64/as9516-32d/onlp/builds/x86_64_accton_as9516_32d/module/src/psui.c @@ -28,6 +28,7 @@ #include #include #include "platform_lib.h" +#include #define VALIDATE(_id) \ do { \ @@ -36,19 +37,14 @@ } \ } while(0) -#define PSU1_ID 1 -#define PSU2_ID 2 - -#define SYS_CPLD_PATH_FMT "/sys/bus/i2c/devices/12-0031/%s" -#define PSU_PRESENT_FMT "psu%d_present" -#define PSU_PWROK_FMT "psu%d_output_pwr_sts" - -#define PSU_PFE1500_PATH_FMT "/sys/bus/i2c/devices/7-%s/%s\r\n" -#define PSU_PFE1500_MODEL "mfr_model" -#define PSU_PFE1500_SERIAL "mfr_serial" - -static const char *psu_pfedrv_i2c_devaddr[] = {"0059", "005a"}; - +#define MODEL_LEN 21 +#define SERIAL_LEN 18 +#define STRING_STRAT_LOC 2 +static uint32_t ps[curl_data_psu_num]; +static char ps_model[PS_DESC_LEN]; +static char ps_serial[PS_DESC_LEN]; +static char ps_rev[PS_DESC_LEN]; +static bool ps_presence; /* * Get all information about the given PSU oid. */ @@ -63,159 +59,188 @@ static onlp_psu_info_t pinfo[] = } }; -int -onlp_psui_init(void) +static void ps_call_back(void *p) { - return ONLP_STATUS_OK; -} + int i = 0; + int j = 0; + int k = 0; + char *data_loc_start; + char *data_loc_end; + char str[32]; + char *ret; + ps_presence = PSU_ABSCENT; + const char *ptr = (const char *)p; + + for (i = 0; i < curl_data_psu_num; i++) + ps[i] = 0; + + if (ptr == NULL) + { + AIM_LOG_ERROR("NULL POINTER PASSED to call back function\n"); + return; + } + /* init ps var value */ + memset(ps_model, 0, sizeof(ps_model)); + memset(ps_serial, 0, sizeof(ps_serial)); + memset(ps_rev, 0, sizeof(ps_rev)); -static int -twos_complement_to_int(uint16_t data, uint8_t valid_bit, int mask) -{ - uint16_t valid_data = data & mask; - bool is_negative = valid_data >> (valid_bit - 1); + ret = strstr(ptr, "absent"); + if (ret) + { + ps_presence = PSU_ABSCENT; + return; + } + else + { + ps_presence = PSU_PRESENT; + } - return is_negative ? (-(((~valid_data) & mask) + 1)) : valid_data; + data_loc_start = strchr(ptr, '['); + data_loc_end = strchr(ptr, ']'); + if((data_loc_start == NULL) || (data_loc_end == NULL)) + { + AIM_LOG_ERROR("Failed CURL response data.\n"); + return; + } + /* Start to parse from the first value, ignore '[' */ + i = data_loc_start - ptr + 1; + while (ptr[i] && ptr[i] != ']') + { + j = 0; + while (ptr[i] != ',' && ptr[i] != ']') + { + str[j] = ptr[i]; + j++; + i++; + } + if (j >= PS_DESC_LEN) + { /* sanity check */ + AIM_LOG_ERROR("bad string len from BMC i %d j %d k %d 0x%02x\n", i, j, k, ptr[i]); + return; + } + + str[j] = '\0'; + if (k < curl_data_psu_num) + { + /* There are three string - model name/serial/model ver */ + if ((k < curl_data_loc_psu_model_name) || (k > curl_data_loc_psu_model_ver)) + { + ps[k] = atoi(str); + } + else + { + switch (k) + { + case curl_data_loc_psu_model_name: + strncpy(ps_model, str, sizeof(ps_model)); + break; + case curl_data_loc_psu_mode_serial: + strncpy(ps_serial, str, sizeof(ps_serial)); + break; + case curl_data_loc_psu_model_ver: + strncpy(ps_rev, str, sizeof(ps_rev)); + break; + } + } + + k++; + } + + if (ptr[i] == ']') + break; + + i++; + } + + return; } -static int -pmbus_parse_literal_format(uint16_t value) +int +onlp_psui_init(void) { - int exponent, mantissa, multiplier = 1000; - - exponent = twos_complement_to_int(value >> 11, 5, 0x1f); - mantissa = twos_complement_to_int(value & 0x7ff, 11, 0x7ff); - - return (exponent >= 0) ? (mantissa << exponent) * multiplier : - (mantissa * multiplier) / (1 << -exponent); + return ONLP_STATUS_OK; } int onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) { - int pid, value, addr, ret = 0; - char file[32] = {0}; - char path[80] = {0}; - + int pid; + char url[256] = {0}; + int curlid = 0; + int still_running = 1; + bool curl_response_status = 1; + CURLMcode mc; + VALIDATE(id); - pid = ONLP_OID_ID_GET(id); + pid = ONLP_OID_ID_GET(id); *info = pinfo[pid]; /* Set the onlp_oid_hdr_t */ - /* Get the present status */ - ret = snprintf(file, sizeof(file), PSU_PRESENT_FMT, pid); - if( ret >= sizeof(file) ){ - AIM_LOG_ERROR("file size overwrite (%d,%d)\r\n", ret, sizeof(file)); - return ONLP_STATUS_E_INTERNAL; - } - ret = snprintf(path, sizeof(path), SYS_CPLD_PATH_FMT, file); - if( ret >= sizeof(path) ){ - AIM_LOG_ERROR("path size overwrite (%d,%d)\r\n", ret, sizeof(path)); - return ONLP_STATUS_E_INTERNAL; - } - - if (bmc_file_read_int(&value, path, 16) < 0) { - AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); - return ONLP_STATUS_E_INTERNAL; - } + /* Get psu status by curl */ + snprintf(url, sizeof(url),"%s""ps/%d", BMC_CURL_PREFIX, pid); - if (value) { - info->status &= ~ONLP_PSU_STATUS_PRESENT; - return ONLP_STATUS_OK; - } - info->status |= ONLP_PSU_STATUS_PRESENT; - info->caps = ONLP_PSU_CAPS_AC; + curlid = CURL_PSU_STATUS_1 + pid - 1; - /* Get power good status */ - ret = snprintf(file, sizeof(file), PSU_PWROK_FMT, pid); - if( ret >= sizeof(file) ){ - AIM_LOG_ERROR("file size overwrite (%d,%d)\r\n", ret, sizeof(file)); - return ONLP_STATUS_E_INTERNAL; - } + curl_easy_setopt(curl[curlid], CURLOPT_URL, url); + curl_easy_setopt(curl[curlid], CURLOPT_WRITEFUNCTION, ps_call_back); + curl_multi_add_handle(multi_curl, curl[curlid]); - ret = snprintf(path, sizeof(path), SYS_CPLD_PATH_FMT, file); - if( ret >= sizeof(path) ){ - AIM_LOG_ERROR("path size overwrite (%d,%d)\r\n", ret, sizeof(path)); - return ONLP_STATUS_E_INTERNAL; + while(still_running) { + mc = curl_multi_perform(multi_curl, &still_running); + if(mc != CURLM_OK) + { + AIM_LOG_ERROR("multi_curl failed, code %d.\n", mc); + } } - if (bmc_file_read_int(&value, path, 16) < 0) { - AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); - return ONLP_STATUS_E_INTERNAL; - } + if (PSU_PRESENT != ps_presence) + { + info->status &= ~ONLP_PSU_STATUS_PRESENT; - if (!value) { - info->status |= ONLP_PSU_STATUS_FAILED; return ONLP_STATUS_OK; } - - /* Get input output power status */ - value = (pid == PSU1_ID) ? 0x2 : 0x1; /* mux channel for psu */ - if (bmc_i2c_write_quick_mode(7, 0x70, value) < 0) { - AIM_LOG_ERROR("Unable to set i2c device (7/0x70)\r\n"); - return ONLP_STATUS_E_INTERNAL; + info->status |= ONLP_PSU_STATUS_PRESENT; + /* only support AC type */ + info->caps = ONLP_PSU_CAPS_AC; + /* There are no power good status. We use curl status to replace power good with Openbmc v1.x */ + curl_response_status = ps[curl_data_loc_psu_status]; + if (curl_data_normal != curl_response_status) + { + info->status |= ONLP_PSU_STATUS_FAILED; } - usleep(1200); - - /* Read vin */ - addr = (pid == PSU1_ID) ? 0x59 : 0x5a; - value = bmc_i2c_readw(7, addr, 0x88); - if (value >= 0) { - info->mvin = pmbus_parse_literal_format(value); + else + { + char model[MODEL_LEN+1]; + char serial[SERIAL_LEN+1]; + + memset(model, 0, sizeof(model)); + memset(serial, 0, sizeof(serial)); + /* Parse the model name */ + memcpy(model, ps_model + STRING_STRAT_LOC, MODEL_LEN); + model[MODEL_LEN+1] = '\0'; + /* Parse the serial number */ + memcpy(serial, ps_serial + STRING_STRAT_LOC, SERIAL_LEN); + serial[SERIAL_LEN+1] = '\0'; + /* Get model name */ + strncpy(info->model, model, sizeof(info->model)); + /* Get serial number */ + strncpy(info->serial, serial, sizeof(info->serial)); + /* Read vin */ + info->mvin = ps[curl_data_loc_psu_vin] * 1000; info->caps |= ONLP_PSU_CAPS_VIN; - } - - /* Read iin */ - value = bmc_i2c_readw(7, addr, 0x89); - if (value >= 0) { - info->miin = pmbus_parse_literal_format(value); + /* Read iin */ + info->miin = ps[curl_data_loc_psu_iin]; info->caps |= ONLP_PSU_CAPS_IIN; - } - - /* Get pin */ - if ((info->caps & ONLP_PSU_CAPS_VIN) && (info->caps & ONLP_PSU_CAPS_IIN)) { - info->mpin = info->mvin * info->miin / 1000; + /* Get pin */ + info->mpin = ps[curl_data_loc_psu_pin]; info->caps |= ONLP_PSU_CAPS_PIN; - } - - /* Read iout */ - value = bmc_i2c_readw(7, addr, 0x8c); - if (value >= 0) { - info->miout = pmbus_parse_literal_format(value); - info->caps |= ONLP_PSU_CAPS_IOUT; - } + /* Get vout */ + info->mvout = ps[curl_data_loc_psu_vout] * 1000; + info->caps |= ONLP_PSU_CAPS_VOUT; - /* Read pout */ - value = bmc_i2c_readw(7, addr, 0x96); - if (value >= 0) { - info->mpout = pmbus_parse_literal_format(value); - info->caps |= ONLP_PSU_CAPS_POUT; + info->hdr.coids[0] = ONLP_FAN_ID_CREATE(pid + CHASSIS_FAN_COUNT); } - /* Get vout */ - if ((info->caps & ONLP_PSU_CAPS_IOUT) && (info->caps & ONLP_PSU_CAPS_POUT) && info->miout != 0) { - info->mvout = info->mpout / info->miout * 1000; - info->caps |= ONLP_PSU_CAPS_VOUT; - } - - /* Get model name */ - ret = snprintf(path, sizeof(path), PSU_PFE1500_PATH_FMT, psu_pfedrv_i2c_devaddr[pid-1], PSU_PFE1500_MODEL); - if( ret >= sizeof(path) ){ - AIM_LOG_ERROR("path size overwrite (%d,%d)\r\n", ret, sizeof(path)); - return ONLP_STATUS_E_INTERNAL; - } - - bmc_file_read_str(path, info->model, sizeof(info->model)); - - /* Get serial number */ - ret = snprintf(path, sizeof(path), PSU_PFE1500_PATH_FMT, psu_pfedrv_i2c_devaddr[pid-1], PSU_PFE1500_SERIAL); - if( ret >= sizeof(path) ){ - AIM_LOG_ERROR("path size overwrite (%d,%d)\r\n", ret, sizeof(path)); - return ONLP_STATUS_E_INTERNAL; - } - - bmc_file_read_str(path, info->serial, sizeof(info->serial)); - return ONLP_STATUS_OK; } diff --git a/packages/platforms/accton/x86-64/as9516-32d/onlp/builds/x86_64_accton_as9516_32d/module/src/sfpi.c b/packages/platforms/accton/x86-64/as9516-32d/onlp/builds/x86_64_accton_as9516_32d/module/src/sfpi.c index ff81b680de..34532d909e 100644 --- a/packages/platforms/accton/x86-64/as9516-32d/onlp/builds/x86_64_accton_as9516_32d/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/as9516-32d/onlp/builds/x86_64_accton_as9516_32d/module/src/sfpi.c @@ -90,13 +90,7 @@ typedef struct port_info_s uint16_t bit; } port_info_t; -typedef struct bitmap_info_s -{ - uint16_t bit; - int port; -} bitmap_info_t; - -static port_info_t port_presence_info[] = +static port_info_t port_presence_info[] = { {QSFP_1, 0x22, 0x04, BIT1}, {QSFP_2, 0x22, 0x04, BIT0}, @@ -131,49 +125,8 @@ static port_info_t port_presence_info[] = {QSFP_31, 0x23, 0x08, BIT15}, {QSFP_32, 0x23, 0x08, BIT14}, }; -/* bit-value port mapping 0-15 */ -static bitmap_info_t bitmap_port_1_info[] = -{ - {BIT0, QSFP_2}, - {BIT1, QSFP_1}, - {BIT2, QSFP_4}, - {BIT3, QSFP_3}, - {BIT4, QSFP_6}, - {BIT5, QSFP_5}, - {BIT6, QSFP_8}, - {BIT7, QSFP_7}, - {BIT8, QSFP_10}, - {BIT9, QSFP_9}, - {BIT10, QSFP_12}, - {BIT11, QSFP_11}, - {BIT12, QSFP_14}, - {BIT13, QSFP_13}, - {BIT14, QSFP_16}, - {BIT15, QSFP_15}, - -}; -/* bit-value port mapping 16-31 */ -static bitmap_info_t bitmap_port_2_info[] = -{ - {BIT0, QSFP_18}, - {BIT1, QSFP_17}, - {BIT2, QSFP_20}, - {BIT3, QSFP_19}, - {BIT4, QSFP_22}, - {BIT5, QSFP_21}, - {BIT6, QSFP_24}, - {BIT7, QSFP_23}, - {BIT8, QSFP_26}, - {BIT9, QSFP_25}, - {BIT10, QSFP_28}, - {BIT11, QSFP_27}, - {BIT12, QSFP_30}, - {BIT13, QSFP_29}, - {BIT14, QSFP_32}, - {BIT15, QSFP_31}, -}; -uint64_t g_present_port_val; +uint32_t g_present_port_val; /************************************************************ * * SFPI Entry Points @@ -201,34 +154,42 @@ onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap) } int -onlp_sfpi_reg_val_to_port_sequence(uint64_t *presence_bit_val, uint64_t presence_reg_val) +onlp_sfpi_reg_val_to_port_sequence(uint32_t *presence_val, uint32_t presence_reg_val) { - int i; - int reg_1_val, reg_2_val; - uint64_t presence_port_bit_val = 0; - /* port 0-15 */ - for (i = 0; i < 16; i++) + int index; + uint32_t presence_port_val = 0; + int port_array[NUM_OF_QSFP_PORT] = {0}; + int first_remap_port_array[NUM_OF_QSFP_PORT] = {0}; + int second_remap_port_array[NUM_OF_QSFP_PORT] = {0}; + int first_remap[NUM_OF_QSFP_PORT] = { 1, 0, 3, 2, 5, 4, 7, 6, + 9, 8, 11, 10, 13, 12, 15, 14, + 17, 16, 19, 18, 21, 20 ,23, 22, + 25, 24, 27, 26, 29, 28, 31, 30 }; + + int second_remap[NUM_OF_QSFP_PORT] = { 1, 0, 3, 2, 5, 4, 7, 6, + 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21 ,22, 23, + 25, 24, 27, 26, 28, 29, 30, 31 }; + /* mapping presence register value to the presence array according */ + for (index = 0 ; index < NUM_OF_QSFP_PORT ; index++) { - reg_1_val=(~presence_reg_val) & (bitmap_port_1_info[i].bit); - if(reg_1_val != 0) - { - presence_port_bit_val=presence_port_bit_val | (1 << (bitmap_port_1_info[i].port)); - } + if (((presence_reg_val >> index) % 2) == 1) + port_array[index] = 1; + else + port_array[index] = 0; } - /* port 16-31 */ - presence_reg_val=(presence_reg_val >> 16); - for (i = 0; i < 16; i++) - { - reg_2_val=(~presence_reg_val) & (bitmap_port_2_info[i].bit); - if(reg_2_val != 0) - { - presence_port_bit_val=presence_port_bit_val | (1 << (bitmap_port_2_info[i].port)); - } - } - - *presence_bit_val = presence_port_bit_val; - + /* first remap */ + for (index = 0 ; index < NUM_OF_QSFP_PORT ; index++) + first_remap_port_array[index] = port_array[first_remap[index]]; + /* second remap */ + for (index = 0 ; index < NUM_OF_QSFP_PORT ; index++) + second_remap_port_array[index] = first_remap_port_array[second_remap[index]]; + /* To calculate presence value */ + for (index = 0 ; index < NUM_OF_QSFP_PORT ; index++) + presence_port_val = presence_port_val + (second_remap_port_array[index] << index); + + *presence_val = ~(presence_port_val); return ONLP_STATUS_OK; } @@ -242,15 +203,7 @@ onlp_sfpi_is_present(int port) */ int present=0; - if(port < 16) - { - present=((g_present_port_val >> port) & 0x1); - } - - if((port >= 16) && (port<32)) - { - present=((g_present_port_val >> (port)) & 0x1); - } + present=((g_present_port_val >> port) & 0x1); return present; } @@ -258,8 +211,8 @@ onlp_sfpi_is_present(int port) int onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) { - uint64_t reg_presence_all = 0; - uint64_t presence_all = 0; + uint32_t reg_presence_all = 0; + uint32_t presence_all = 0; uint8_t bytes[4]; int rd_size, i; uint8_t bus, i2c_addr, mux_i2c_addr, mux_chn, fpga_id, byte_buf[128]; @@ -271,6 +224,7 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) /* port 0-15 */ mux_chn=port_presence_info[0].chan; i2c_addr=port_presence_info[0].address; + for(i=0; i<2; i++) { if((fpga_proc_i2c_read(fpga_id, bus, mux_i2c_addr, mux_chn, i2c_addr @@ -286,6 +240,7 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) mux_chn=port_presence_info[16].chan; i2c_addr=port_presence_info[16].address; + for(i=0; i<2; i++) { if((fpga_proc_i2c_read(fpga_id, bus, mux_i2c_addr, mux_chn, i2c_addr @@ -305,8 +260,8 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) } onlp_sfpi_reg_val_to_port_sequence(&presence_all, reg_presence_all); - g_present_port_val=presence_all; + g_present_port_val=presence_all; /* Populate bitmap */ for(i = 0; presence_all; i++) { AIM_BITMAP_MOD(dst, i, (presence_all & 1)); diff --git a/packages/platforms/accton/x86-64/as9516-32d/onlp/builds/x86_64_accton_as9516_32d/module/src/sysi.c b/packages/platforms/accton/x86-64/as9516-32d/onlp/builds/x86_64_accton_as9516_32d/module/src/sysi.c index 018da90bff..9d8a6539ce 100644 --- a/packages/platforms/accton/x86-64/as9516-32d/onlp/builds/x86_64_accton_as9516_32d/module/src/sysi.c +++ b/packages/platforms/accton/x86-64/as9516-32d/onlp/builds/x86_64_accton_as9516_32d/module/src/sysi.c @@ -37,16 +37,132 @@ #include "x86_64_accton_as9516_32d_int.h" #include "x86_64_accton_as9516_32d_log.h" -#define SYSTEM_CPLD_REV_PATH "/sys/bus/i2c/drivers/syscpld/12-0031/cpld_rev" -#define FAN_CPLD_REV_PATH "/sys/bus/i2c/drivers/fancpld/8-0066/cpld_rev" - typedef struct cpld_version { char *attr_name; - int version; + int major_version; + int sub_version; char *description; } cpld_version_t; +static int sys_ver = 0; +static int sys_subver = 0; +static int fan_ver = 0; + +static void cpld_ver_call_back(void *p) +{ + + int char_val[2]; + int i; + const char *ptr = (const char *)p; + + if (ptr == NULL) + { + AIM_LOG_ERROR("NULL POINTER PASSED to call back function\n"); + + return; + } + + /* get the two chars of return string and convert to integer */ + for(i = 0 ; i < 2 ; i++) + { + /* ASCII convert*/ + if (ptr[50+i] == 97) + char_val[i] = 10; + else if(ptr[50+i] == 98) + char_val[i] = 11; + else if (ptr[50+i] == 99) + char_val[i] = 12; + else if(ptr[50+i] == 100) + char_val[i] = 13; + else if (ptr[50+i] == 101) + char_val[i] = 14; + else if(ptr[50+i] == 102) + char_val[i] = 15; + else + char_val[i] = (int)(ptr[50+i]) - 48; + } + sys_ver = (int)(char_val[0]) * 16 + (int)(char_val[1]); + + return; +} + +static void cpld_subver_call_back(void *p) +{ + + int char_val[2]; + int i; + const char *ptr = (const char *)p; + + if (ptr == NULL) + { + AIM_LOG_ERROR("NULL POINTER PASSED to call back function\n"); + + return; + } + + /* get the two chars of return string and convert to integer */ + for(i = 0 ; i < 2 ; i++) + { + /* ASCII convert*/ + if (ptr[50+i] == 97) + char_val[i] = 10; + else if(ptr[50+i] == 98) + char_val[i] = 11; + else if (ptr[50+i] == 99) + char_val[i] = 12; + else if(ptr[50+i] == 100) + char_val[i] = 13; + else if (ptr[50+i] == 101) + char_val[i] = 14; + else if(ptr[50+i] == 102) + char_val[i] = 15; + else + char_val[i] = (int)(ptr[50+i]) - 48; + } + sys_subver = (int)(char_val[0]) * 16 + (int)(char_val[1]); + + return; +} + +static void fan_cpld_ver_call_back(void *p) +{ + + int char_val[2]; + int i; + const char *ptr = (const char *)p; + + if (ptr == NULL) + { + AIM_LOG_ERROR("NULL POINTER PASSED to call back function\n"); + + return; + } + + /* get the two chars of return string and convert to integer */ + for(i = 0 ; i < 2 ; i++) + { + /* ASCII convert*/ + if (ptr[50+i] == 97) + char_val[i] = 10; + else if(ptr[50+i] == 98) + char_val[i] = 11; + else if (ptr[50+i] == 99) + char_val[i] = 12; + else if(ptr[50+i] == 100) + char_val[i] = 13; + else if (ptr[50+i] == 101) + char_val[i] = 14; + else if(ptr[50+i] == 102) + char_val[i] = 15; + else + char_val[i] = (int)(ptr[50+i]) - 48; + } + fan_ver = (int)(char_val[0]) * 16 + (int)(char_val[1]); + + return; +} + const char* onlp_sysi_platform_get(void) { @@ -58,6 +174,15 @@ onlp_sysi_platform_get(void) return "x86-64-accton-as9516-32d-r0"; } +int +onlp_sysi_init(void) +{ + + bmc_curl_init(); + + return ONLP_STATUS_OK; +} + int onlp_sysi_onie_data_get(uint8_t** data, int* size) { @@ -167,7 +292,7 @@ onlp_sysi_oids_get(onlp_oid_t* table, int max) int i; onlp_oid_t* e = table; memset(table, 0, max*sizeof(onlp_oid_t)); - + /* 7 Thermal sensors on the chassis */ for (i = 1; i <= CHASSIS_THERMAL_COUNT; i++) { @@ -192,42 +317,55 @@ onlp_sysi_oids_get(onlp_oid_t* table, int max) *e++ = ONLP_FAN_ID_CREATE(i); } - bmc_tty_init(); - return 0; } int onlp_sysi_platform_info_get(onlp_platform_info_t* pi) { - int i, version; - char path[64] = {0}; - cpld_version_t cplds[] = { { "sys_cpld_ver", 0, "SYSTEM CPLD"}, - { "fan_cpld_ver", 0, "FAN CPLD"} }; + int curlid; + char url[256] = {0}; + CURLMcode mc; + int still_running = 1; - /* Read CPLD version */ - for (i = 0; i < AIM_ARRAYSIZE(cplds); i++) - { - if(strcmp("sys_cpld_ver", cplds[i].attr_name) ==0) - { - strcpy(path, SYSTEM_CPLD_REV_PATH); - } - - if(strcmp("fan_cpld_ver", cplds[i].attr_name) ==0) + cpld_version_t cplds[] = { { "sys_cpld_ver", 0, 0, "SYSTEM CPLD"}, + { "fan_cpld_ver", 0, 0, "FAN CPLD"} }; + + snprintf(url, sizeof(url),"%s""0x31/0x1", BMC_CPLD_CURL_PREFIX); + curlid = CURL_SYS_CPLD_VER; + curl_easy_setopt(curl[curlid], CURLOPT_URL, url); + curl_easy_setopt(curl[curlid], CURLOPT_WRITEFUNCTION, cpld_ver_call_back); + curl_multi_add_handle(multi_curl, curl[curlid]); + + snprintf(url, sizeof(url),"%s""0x31/0x2", BMC_CPLD_CURL_PREFIX); + curlid = CURL_SYS_CPLD_SUBVER; + curl_easy_setopt(curl[curlid], CURLOPT_URL, url); + curl_easy_setopt(curl[curlid], CURLOPT_WRITEFUNCTION, cpld_subver_call_back); + curl_multi_add_handle(multi_curl, curl[curlid]); + + snprintf(url, sizeof(url),"%s""0x08/0x66/0x01", BMC_FAN_CPLD_CURL_PREFIX); + curlid = CURL_FAN_CPLD; + curl_easy_setopt(curl[curlid], CURLOPT_URL, url); + curl_easy_setopt(curl[curlid], CURLOPT_WRITEFUNCTION, fan_cpld_ver_call_back); + curl_multi_add_handle(multi_curl, curl[curlid]); + + while(still_running) { + mc = curl_multi_perform(multi_curl, &still_running); + if(mc != CURLM_OK) { - strcpy(path, FAN_CPLD_REV_PATH); + AIM_LOG_ERROR("multi_curl failed, code %d.\n", mc); } + } - if (bmc_file_read_int(&version, path, 16) < 0) { - AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); - } + /* Read CPLD version */ + cplds[0].major_version=sys_ver; + cplds[0].sub_version=sys_subver; + cplds[1].major_version=fan_ver; - cplds[i].version=version; - } + pi->cpld_versions = aim_fstrdup("%s:%x.%x, %s:0x%x", + cplds[0].description, cplds[0].major_version, cplds[0].sub_version, + cplds[1].description, cplds[1].major_version); - pi->cpld_versions = aim_fstrdup("%s:%d, %s:%d", - cplds[0].description, cplds[0].version, - cplds[1].description, cplds[1].version); return ONLP_STATUS_OK; } diff --git a/packages/platforms/accton/x86-64/as9516-32d/onlp/builds/x86_64_accton_as9516_32d/module/src/thermali.c b/packages/platforms/accton/x86-64/as9516-32d/onlp/builds/x86_64_accton_as9516_32d/module/src/thermali.c index 50f939c4f4..f847a007e2 100644 --- a/packages/platforms/accton/x86-64/as9516-32d/onlp/builds/x86_64_accton_as9516_32d/module/src/thermali.c +++ b/packages/platforms/accton/x86-64/as9516-32d/onlp/builds/x86_64_accton_as9516_32d/module/src/thermali.c @@ -26,6 +26,7 @@ #include #include #include "platform_lib.h" +#include #define VALIDATE(_id) \ do { \ @@ -34,55 +35,123 @@ } \ } while(0) -#define THERMAL_PATH_FORMAT "/sys/bus/i2c/drivers/lm75/%s/temp1_input" -#define THERMAL_CPU_CORE_PATH_FORMAT "/sys/bus/i2c/drivers/com_e_driver/%s/temp2_input" +static char* cpu_coretemp_files[] = +{ + "/sys/devices/platform/coretemp.0*temp1_input", + "/sys/devices/platform/coretemp.0*temp2_input", + "/sys/devices/platform/coretemp.0*temp3_input", + "/sys/devices/platform/coretemp.0*temp4_input", + "/sys/devices/platform/coretemp.0*temp5_input", + NULL, +}; -static char* directory[] = /* must map with onlp_thermal_id */ +static uint32_t tmp[curl_data_thermal_num] = {0}; +static int curl_thermal_data_loc[curl_data_thermal_num] = { - NULL, - "4-0033", - "3-0048", - "3-0049", - "3-004a", - "3-004b", - "3-004c", - "3-004d", + curl_data_loc_psu_status, + /* 3-0048 tmp75_3_48_temp */ + curl_data_loc_thermal_3_48, + /* 3-0049 tmp75_3_49_temp */ + curl_data_loc_thermal_3_49, + /* 3-004a tmp75_3_4a_temp */ + curl_data_loc_thermal_3_4a, + /* 3-004b tmp75_3_4b_temp */ + curl_data_loc_thermal_3_4b, + /* 3-004c tmp75_3_4c_temp Max6658 */ + curl_data_loc_thermal_3_4c_max6658, + /* 3-004d tmp75_3_4d_temp */ + curl_data_loc_thermal_3_4d }; /* Static values */ static onlp_thermal_info_t linfo[] = { - { }, /* Not used */ + { }, /* 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), "TMP75-1", 0}, + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_MAIN_BROAD), "TMP75 0x48", 0}, ONLP_THERMAL_STATUS_PRESENT, ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS }, - { { ONLP_THERMAL_ID_CREATE(THERMAL_2_ON_MAIN_BROAD), "TMP75-2", 0}, + { { ONLP_THERMAL_ID_CREATE(THERMAL_2_ON_MAIN_BROAD), "TMP75 0x49", 0}, ONLP_THERMAL_STATUS_PRESENT, ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS }, - { { ONLP_THERMAL_ID_CREATE(THERMAL_3_ON_MAIN_BROAD), "TMP75-3", 0}, + { { ONLP_THERMAL_ID_CREATE(THERMAL_3_ON_MAIN_BROAD), "TMP75 0x4a", 0}, ONLP_THERMAL_STATUS_PRESENT, ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS }, - { { ONLP_THERMAL_ID_CREATE(THERMAL_4_ON_MAIN_BROAD), "TMP75-4", 0}, + { { ONLP_THERMAL_ID_CREATE(THERMAL_4_ON_MAIN_BROAD), "TMP75 0x4b", 0}, ONLP_THERMAL_STATUS_PRESENT, ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS }, - { { ONLP_THERMAL_ID_CREATE(THERMAL_5_ON_MAIN_BROAD), "MAX6658 Temp Sensor(JBAY)", 0}, + { { ONLP_THERMAL_ID_CREATE(THERMAL_5_ON_MAIN_BROAD), "MAX6658 0x4c", 0}, ONLP_THERMAL_STATUS_PRESENT, ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS }, - { { ONLP_THERMAL_ID_CREATE(THERMAL_6_ON_MAIN_BROAD), "TMP75-5", 0}, + { { ONLP_THERMAL_ID_CREATE(THERMAL_6_ON_MAIN_BROAD), "TMP75 0x4d", 0}, ONLP_THERMAL_STATUS_PRESENT, ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS }, }; +void tmp_call_back(void *p) +{ + int i = 0; + int j = 0; + int k = 0; + char *data_loc_start; + char *data_loc_end; + char str[40]; + char *ptr = p; + + for (i = 0; i < curl_data_thermal_num; i++) + tmp[i] = -1; + + if (ptr == NULL) + { + AIM_LOG_ERROR("NULL POINTER PASSED to call back function\n"); + return; + } + + data_loc_start = strchr(ptr, '['); + data_loc_end = strchr(ptr, ']'); + if((data_loc_start == NULL) || (data_loc_end == NULL)) + { + AIM_LOG_ERROR("Failed CURL response data.\n"); + return; + } + /* Start to parse from the first value, ignore '[' */ + i = data_loc_start - ptr + 1; + while (ptr[i] && ptr[i] != ']') + { + j = 0; + while (ptr[i] != ',' && ptr[i] != ']') + { + str[j] = ptr[i]; + j++; + i++; + } + + str[j] = '\0'; + + if (k < curl_data_thermal_num) + { + tmp[k] = atoi(str); + k++; + } + + if (ptr[i] == ']') + break; + + i++; + } + + return; +} + /* * This will be called to intiialize the thermali subsystem. */ @@ -106,22 +175,45 @@ int onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info) { int tid; - char path[64] = {0}; VALIDATE(id); + char url[256] = {0}; + CURLMcode mc; + int still_running = 1; tid = ONLP_OID_ID_GET(id); /* Set the onlp_oid_hdr_t and capabilities */ *info = linfo[tid]; - /* bmc access path */ + /* CPU core thermal */ if (THERMAL_CPU_CORE == tid) { - sprintf(path, THERMAL_CPU_CORE_PATH_FORMAT, directory[tid]); - }else { - sprintf(path, THERMAL_PATH_FORMAT, directory[tid]); + return onlp_file_read_int_max(&info->mcelsius, cpu_coretemp_files); } - - if (bmc_file_read_int(&info->mcelsius, path, 10) < 0) { - AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); - return ONLP_STATUS_E_INTERNAL; + else + { + /* just need to do curl once + tmp[0] response_status [0:success ,!=0:error], + tmp[1] temp1_input in 3-0048 + tmp[2] temp1_input in 3-0049 + tmp[3] temp1_input in 3-004a + tmp[4] temp1_input in 3-004b + tmp[5] temp1_input in 3-004c max6658 thermal sensor ,temperature in local position + tmp[7] temp1_input in 3-004d + */ + snprintf(url, sizeof(url),"%s""tmp/newport", BMC_CURL_PREFIX); + + curl_easy_setopt(curl[CURL_THERMAL], CURLOPT_URL, url); + curl_easy_setopt(curl[CURL_THERMAL], CURLOPT_WRITEFUNCTION, tmp_call_back); + curl_multi_add_handle(multi_curl, curl[CURL_THERMAL]); + while(still_running) { + mc = curl_multi_perform(multi_curl, &still_running); + if(mc != CURLM_OK) + { + AIM_LOG_ERROR("multi_curl failed, code %d.\n", mc); + + return ONLP_STATUS_E_INTERNAL; + } + } + + info->mcelsius = tmp[curl_thermal_data_loc[tid-1]]*100; } return ONLP_STATUS_OK;