diff --git a/packages/platforms/accton/x86-64/x86-64-accton-minipack/onlp/builds/src/module/src/fani.c b/packages/platforms/accton/x86-64/x86-64-accton-minipack/onlp/builds/src/module/src/fani.c old mode 100644 new mode 100755 index 3775723f..7c9334a7 --- a/packages/platforms/accton/x86-64/x86-64-accton-minipack/onlp/builds/src/module/src/fani.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-minipack/onlp/builds/src/module/src/fani.c @@ -1,222 +1,230 @@ -/************************************************************ - * - * - * Copyright 2014 Big Switch Networks, Inc. - * Copyright 2014 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. - * - * - ************************************************************ - * - * Fan Platform Implementation Defaults. - * - ***********************************************************/ -#include -#include -#include "platform_lib.h" - -#define VALIDATE(_id) \ - do { \ - if(!ONLP_OID_IS_FAN(_id)) { \ - return ONLP_STATUS_E_INVALID; \ - } \ - } while(0) - -#define MAX_FAN_SPEED 15400 -#define BIT(i) (1 << (i)) - -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, -}; - -#define FAN_BOARD_PATH "/sys/bus/i2c/devices/8-0033/" - -#define CHASSIS_FAN_INFO(fid) \ - { \ - { ONLP_FAN_ID_CREATE(FAN_##fid##_ON_FAN_BOARD), "Chassis Fan - "#fid, 0 },\ - 0x0,\ - ONLP_FAN_CAPS_SET_PERCENTAGE | 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 */ - CHASSIS_FAN_INFO(1), - CHASSIS_FAN_INFO(2), - CHASSIS_FAN_INFO(3), - CHASSIS_FAN_INFO(4), - CHASSIS_FAN_INFO(5) -}; - -/* - * This function will be called prior to all of onlp_fani_* functions. - */ -int -onlp_fani_init(void) -{ - return ONLP_STATUS_OK; -} - -int -onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* info) -{ - int value = 0, fid; - char path[64] = {0}; - VALIDATE(id); - - fid = ONLP_OID_ID_GET(id); - *info = finfo[fid]; - - /* get fan present status - */ - sprintf(path, "%s""fantray_present", FAN_BOARD_PATH); - - 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 (value & BIT(fid-1)) { - return ONLP_STATUS_OK; - } - info->status |= ONLP_FAN_STATUS_PRESENT; - - - /* get front fan rpm - */ - sprintf(path, "%s""fan%d_input", FAN_BOARD_PATH, fid*2 - 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; - - /* get rear fan rpm - */ - sprintf(path, "%s""fan%d_input", FAN_BOARD_PATH, fid*2); - - 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; - } - - - /* set fan status based on rpm - */ - if (!info->rpm) { - info->status |= ONLP_FAN_STATUS_FAILED; - return ONLP_STATUS_OK; - } - - - /* 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. - * - * 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) -{ - 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) -{ - char cmd[32] = {0}; - - sprintf(cmd, "set_fan_speed.sh %d", p); - - if (bmc_send_command(cmd) < 0) { - AIM_LOG_ERROR("Unable to send command to bmc(%s)\r\n", cmd); - return ONLP_STATUS_E_INTERNAL; - } - - 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; -} - - +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2014 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. + * + * + ************************************************************ + * + * Fan Platform Implementation Defaults. + * + ***********************************************************/ +#include +#include +#include "platform_lib.h" + +#define VALIDATE(_id) \ + do { \ + if(!ONLP_OID_IS_FAN(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ + } while(0) + +#define MAX_FAN_SPEED 15400 +#define BIT(i) (1 << (i)) + +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_7_ON_FAN_BOARD, + FAN_8_ON_FAN_BOARD, +}; + +#define FCM_TOP_BOARD_PATH "/sys/bus/i2c/devices/64-0033/fantray%d_present| head -1" +#define FCM_BOT_BOARD_PATH "/sys/bus/i2c/devices/72-0033/fantray%d_present| head -1" +#define FAN_BOARD_PATH "/sys/bus/platform/devices/minipack_psensor/" + + +#define CHASSIS_FAN_INFO(fid) \ + { \ + { ONLP_FAN_ID_CREATE(FAN_##fid##_ON_FAN_BOARD), "Chassis Fan - "#fid, 0 },\ + 0x0,\ + ONLP_FAN_CAPS_SET_PERCENTAGE | 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 */ + CHASSIS_FAN_INFO(1), + CHASSIS_FAN_INFO(2), + CHASSIS_FAN_INFO(3), + CHASSIS_FAN_INFO(4), + CHASSIS_FAN_INFO(5), + CHASSIS_FAN_INFO(6), + CHASSIS_FAN_INFO(7), + CHASSIS_FAN_INFO(8) +}; + +/* + * This function will be called prior to all of onlp_fani_* functions. + */ +int +onlp_fani_init(void) +{ + return ONLP_STATUS_OK; +} + +int +onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* info) +{ + int value = 0, fid, board_id; + char path[128]= {0}; + char *fantray_path[2] = {FCM_TOP_BOARD_PATH, FCM_BOT_BOARD_PATH}; + VALIDATE(id); + + fid = ONLP_OID_ID_GET(id); + *info = finfo[fid]; + + /* get fan present status + */ + board_id = (fid-1)/(CHASSIS_FAN_COUNT/2); + sprintf(path, fantray_path[board_id], ((fid-1)/2)+1); + 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 (value) { + return ONLP_STATUS_OK; + } + info->status |= ONLP_FAN_STATUS_PRESENT; + + + /* get front fan rpm + */ + sprintf(path, "%s""fan%d_input", FAN_BOARD_PATH, fid*2 - 1); + if (onlp_file_read_int(&value, path) < 0) { + AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } + info->rpm = value; + + /* get rear fan rpm + */ + sprintf(path, "%s""fan%d_input", FAN_BOARD_PATH, fid*2); + if (onlp_file_read_int(&value, path) < 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; + } + + + /* set fan status based on rpm + */ + if (!info->rpm) { + info->status |= ONLP_FAN_STATUS_FAILED; + return ONLP_STATUS_OK; + } + + + /* 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. + * + * 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) +{ + 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) +{ + char cmd[32] = {0}; + + sprintf(cmd, "set_fan_speed.sh %d", p); + + if (bmc_send_command(cmd) < 0) { + AIM_LOG_ERROR("Unable to send command to bmc(%s)\r\n", cmd); + return ONLP_STATUS_E_INTERNAL; + } + + 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/x86-64-accton-minipack/onlp/builds/src/module/src/ledi.c b/packages/platforms/accton/x86-64/x86-64-accton-minipack/onlp/builds/src/module/src/ledi.c old mode 100644 new mode 100755 index 1442f9a8..ebb5820f --- a/packages/platforms/accton/x86-64/x86-64-accton-minipack/onlp/builds/src/module/src/ledi.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-minipack/onlp/builds/src/module/src/ledi.c @@ -28,6 +28,7 @@ #include #include "platform_lib.h" + #define VALIDATE(_id) \ do { \ if(!ONLP_OID_IS_LED(_id)) { \ @@ -40,8 +41,8 @@ enum onlp_led_id { LED_RESERVED = 0, - LED_SYS1, - LED_SYS2 + LED_SYS, + LED_ACT }; typedef struct led_address_s { @@ -59,22 +60,39 @@ typedef struct led_mode_info_s { static led_address_t led_addr[] = { { }, /* Not used */ - {LED_SYS1, 1, 0x32, 0x3e}, - {LED_SYS2, 1, 0x32, 0x3f}, + {LED_SYS, 50, 0x20, 3}, + {LED_ACT, 50, 0x20, 3}, }; -static led_mode_info_t led_mode_info[] = -{ - {ONLP_LED_MODE_OFF, 0x0}, - {ONLP_LED_MODE_OFF, 0x8}, - {ONLP_LED_MODE_BLUE, 0x1}, - {ONLP_LED_MODE_BLUE_BLINKING, 0x9}, - {ONLP_LED_MODE_GREEN, 0x2}, - {ONLP_LED_MODE_GREEN_BLINKING, 0xa}, - {ONLP_LED_MODE_RED, 0x4}, - {ONLP_LED_MODE_RED_BLINKING, 0xc}, +struct led_type_mode { + enum onlp_led_id type; + onlp_led_mode_t mode; + int reg_bit_mask; + int mode_value; }; +#define LED_TYPE_SYS_REG_MASK (0x07) +#define LED_MODE_SYS_OFF_VALUE (0x07) +#define LED_TYPE_ACT_REG_MASK (0x38) +#define LED_MODE_ACT_OFF_VALUE (0x38) + +static struct led_type_mode led_type_mode_data[] = { + {LED_SYS, ONLP_LED_MODE_OFF, LED_TYPE_SYS_REG_MASK, LED_MODE_SYS_OFF_VALUE}, + {LED_SYS, ONLP_LED_MODE_RED, LED_TYPE_SYS_REG_MASK, 0x06}, + {LED_SYS, ONLP_LED_MODE_GREEN, LED_TYPE_SYS_REG_MASK, 0x05}, + {LED_SYS, ONLP_LED_MODE_BLUE, LED_TYPE_SYS_REG_MASK, 0x03}, + {LED_SYS, ONLP_LED_MODE_YELLOW, LED_TYPE_SYS_REG_MASK, 0x04}, + {LED_SYS, ONLP_LED_MODE_PURPLE, LED_TYPE_SYS_REG_MASK, 0x02}, + + {LED_ACT, ONLP_LED_MODE_OFF, LED_TYPE_ACT_REG_MASK, LED_MODE_ACT_OFF_VALUE}, + {LED_ACT, ONLP_LED_MODE_RED, LED_TYPE_ACT_REG_MASK, 0x30}, + {LED_ACT, ONLP_LED_MODE_GREEN, LED_TYPE_ACT_REG_MASK, 0x28}, + {LED_ACT, ONLP_LED_MODE_BLUE, LED_TYPE_ACT_REG_MASK, 0x18}, + {LED_ACT, ONLP_LED_MODE_YELLOW, LED_TYPE_ACT_REG_MASK, 0x20}, + {LED_ACT, ONLP_LED_MODE_PURPLE, LED_TYPE_ACT_REG_MASK, 0x10}, +}; + + /* * Get the information for the given LED OID. */ @@ -82,20 +100,20 @@ static onlp_led_info_t linfo[] = { { }, /* Not used */ { - { ONLP_LED_ID_CREATE(LED_SYS1), "Chassis LED 1 (SYS LED 1)", 0 }, + { ONLP_LED_ID_CREATE(LED_SYS), "SIM LED 1 (SYS LED)", 0 }, ONLP_LED_STATUS_PRESENT, ONLP_LED_CAPS_ON_OFF | - ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING | - ONLP_LED_CAPS_RED | ONLP_LED_CAPS_RED_BLINKING | - ONLP_LED_CAPS_BLUE | ONLP_LED_CAPS_BLUE_BLINKING, + ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_PURPLE | + ONLP_LED_CAPS_RED | ONLP_LED_CAPS_YELLOW | + ONLP_LED_CAPS_BLUE }, { - { ONLP_LED_ID_CREATE(LED_SYS2), "Chassis LED 1 (SYS LED 2)", 0 }, + { ONLP_LED_ID_CREATE(LED_ACT), "SIM LED 2 (ACT LED)", 0 }, ONLP_LED_STATUS_PRESENT, ONLP_LED_CAPS_ON_OFF | - ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING | - ONLP_LED_CAPS_RED | ONLP_LED_CAPS_RED_BLINKING | - ONLP_LED_CAPS_BLUE | ONLP_LED_CAPS_BLUE_BLINKING, + ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_PURPLE | + ONLP_LED_CAPS_RED | ONLP_LED_CAPS_YELLOW | + ONLP_LED_CAPS_BLUE }, }; @@ -108,38 +126,44 @@ onlp_ledi_init(void) return ONLP_STATUS_OK; } -static int -reg_value_to_onlp_led_mode(enum onlp_led_id id, int value) -{ +static int reg_value_to_onlp_led_mode(enum onlp_led_id type, uint8_t reg_val) { int i; - for (i = 0; i < AIM_ARRAYSIZE(led_mode_info); i++) { - if (value != led_mode_info[i].regval) { + for (i = 0; i < AIM_ARRAYSIZE(led_type_mode_data); i++) { + + if (type != led_type_mode_data[i].type) continue; + + if ((led_type_mode_data[i].reg_bit_mask & reg_val) == + led_type_mode_data[i].mode_value) + { + return led_type_mode_data[i].mode; } - - return led_mode_info[i].mode; - } - - return ONLP_LED_MODE_AUTO; -} - -static int -onlp_led_mode_to_reg_value(enum onlp_led_id id, onlp_led_mode_t onlp_led_mode) -{ - int i; - - for (i = 0; i < AIM_ARRAYSIZE(led_mode_info); i++) { - if (onlp_led_mode != led_mode_info[i].mode) { - continue; - } - - return led_mode_info[i].regval; } return 0; } +static uint8_t onlp_led_mode_to_reg_value(enum onlp_led_id type, + onlp_led_mode_t mode, uint8_t reg_val) { + int i; + + for (i = 0; i < AIM_ARRAYSIZE(led_type_mode_data); i++) { + if (type != led_type_mode_data[i].type) + continue; + + if (mode != led_type_mode_data[i].mode) + continue; + + reg_val = led_type_mode_data[i].mode_value | + (reg_val & (~led_type_mode_data[i].reg_bit_mask)); + break; + } + + return reg_val; +} + + int onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) { @@ -151,13 +175,12 @@ onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) /* Set the onlp_oid_hdr_t and capabilities */ *info = linfo[ONLP_OID_ID_GET(id)]; - value = onlp_i2c_readb(led_addr[lid].bus, led_addr[lid].devaddr, led_addr[lid].offset, ONLP_I2C_F_FORCE); + value = bmc_i2c_readb(led_addr[lid].bus, led_addr[lid].devaddr, led_addr[lid].offset); if (value < 0) { return ONLP_STATUS_E_INTERNAL; } info->mode = reg_value_to_onlp_led_mode(lid, value); - /* Set the on/off status */ if (info->mode != ONLP_LED_MODE_OFF) { info->status |= ONLP_LED_STATUS_ON; @@ -196,17 +219,28 @@ onlp_ledi_set(onlp_oid_t id, int on_or_off) int onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) { - int lid, value; + int lid, value, i; VALIDATE(id); lid = ONLP_OID_ID_GET(id); - value = onlp_led_mode_to_reg_value(lid, mode); - if (onlp_i2c_writeb(led_addr[lid].bus, led_addr[lid].devaddr, led_addr[lid].offset, value, ONLP_I2C_F_FORCE) < 0) { - return ONLP_STATUS_E_INTERNAL; + for (i = 1; i <= PLATFOTM_H_TTY_RETRY; i++) { + value = bmc_i2c_readb(led_addr[lid].bus, led_addr[lid].devaddr, + led_addr[lid].offset); + if (value < 0) { + continue; + } + value = onlp_led_mode_to_reg_value(lid, mode, value); + if (bmc_i2c_writeb(led_addr[lid].bus, led_addr[lid].devaddr, + led_addr[lid].offset, value) < 0) { + continue; + } else { + return ONLP_STATUS_OK; + } } - return ONLP_STATUS_OK; + return ONLP_STATUS_E_INTERNAL; + } /* diff --git a/packages/platforms/accton/x86-64/x86-64-accton-minipack/onlp/builds/src/module/src/platform_lib.c b/packages/platforms/accton/x86-64/x86-64-accton-minipack/onlp/builds/src/module/src/platform_lib.c old mode 100644 new mode 100755 index 3319a00f..21286b61 --- a/packages/platforms/accton/x86-64/x86-64-accton-minipack/onlp/builds/src/module/src/platform_lib.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-minipack/onlp/builds/src/module/src/platform_lib.c @@ -30,10 +30,10 @@ #include "platform_lib.h" #define TTY_DEVICE "/dev/ttyACM0" -#define TTY_PROMPT "@bmc:" +#define TTY_PROMPT "@bmc-oob:" #define TTY_I2C_TIMEOUT 55000 -#define TTY_BMC_LOGIN_TIMEOUT 1000000 -#define TTY_RETRY 3 +#define TTY_BMC_LOGIN_TIMEOUT 1000000 +#define TTY_RETRY PLATFOTM_H_TTY_RETRY #define MAXIMUM_TTY_BUFFER_LENGTH 1024 #define MAXIMUM_TTY_STRING_LENGTH (MAXIMUM_TTY_BUFFER_LENGTH - 1) @@ -57,7 +57,7 @@ static int tty_open(void) attr.c_oflag = 0; attr.c_lflag = 0; attr.c_cc[VMIN] = (unsigned char) - ((MAXIMUM_TTY_STRING_LENGTH > 0xFF) ? 0xFF : MAXIMUM_TTY_STRING_LENGTH); + ((MAXIMUM_TTY_STRING_LENGTH > 0xFF) ? 0xFF : MAXIMUM_TTY_STRING_LENGTH); attr.c_cc[VTIME] = 0; cfsetospeed(&attr, B57600); cfsetispeed(&attr, B57600); @@ -86,6 +86,7 @@ static int tty_exec_buf(unsigned long udelay, const char *str) write(tty_fd, tty_buf, strlen(tty_buf)+1); usleep(udelay); + usleep(50000); 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; @@ -93,18 +94,16 @@ static int tty_exec_buf(unsigned long udelay, const char *str) static int tty_login(void) { - int i = 10; + int i; for (i = 1; i <= TTY_RETRY; i++) { snprintf(tty_buf, MAXIMUM_TTY_BUFFER_LENGTH, "\r\r"); if (!tty_exec_buf(0, TTY_PROMPT)) { return 0; } - - if (strstr(tty_buf, "bmc login:") != NULL) + if (strstr(tty_buf, "bmc-oob 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)) { @@ -122,7 +121,7 @@ static int tty_login(void) int bmc_tty_init(void) { int i; - if (tty_fd >= 0){ + if (tty_fd >= 0) { return 0; } @@ -131,6 +130,7 @@ int bmc_tty_init(void) AIM_LOG_ERROR("ERROR: Cannot open TTY device\n"); continue; } + if (tty_login() != 0) { AIM_LOG_ERROR("ERROR: Cannot login TTY device\n"); tty_close(); @@ -146,19 +146,21 @@ int bmc_tty_init(void) int bmc_tty_deinit(void) { - if( tty_fd != -1 ){ - tty_close(); - } - else{ - AIM_LOG_ERROR("ERROR: TTY not open\n"); - } - return 0; + if( tty_fd != -1 ) { + tty_close(); + } + else { + AIM_LOG_ERROR("ERROR: TTY not open\n"); + } + return 0; } int bmc_send_command(char *cmd) { int i, ret = 0; - + + bmc_tty_init(); + memset(tty_buf, 0, MAXIMUM_TTY_BUFFER_LENGTH); for (i = 1; i <= TTY_RETRY; i++) { snprintf(tty_buf, MAXIMUM_TTY_BUFFER_LENGTH, "%s", cmd); ret = tty_exec_buf(TTY_I2C_TIMEOUT, TTY_PROMPT); @@ -166,10 +168,8 @@ int bmc_send_command(char *cmd) // AIM_LOG_ERROR("ERROR: bmc_send_command(%s) timed out\n", cmd); continue; } - return 0; } - AIM_LOG_ERROR("Unable to send command to bmc(%s)\r\n", cmd); return -1; } @@ -177,52 +177,53 @@ int bmc_send_command(char *cmd) int chk_numeric_char(char *data, int base) { int len, i, orig = 0; - if( *data == '\0' ){ + + if( *data == '\0' ) { return 0; } len = (int) strlen(data); - if( base == 10 ){ - for( i=0; i '9' ){ + if( *(data+i) > '9' ) { return 0; } } return 1; } - else if( base == 16 ){ - if( !memcmp(data, "0x", 2) ){ - if( len <= 2 ){ + 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 ){ + else if( !memcmp(data, "0X", 2) ) { + if( len <= 2 ) { return 0; } orig = 2; } - for( i=orig; i orig) && ( *(data+i) == 0xd ) ){ + for( i=orig; i orig) && ( *(data+i) == 0xd ) ) { break; } - if( (i > orig) && ( *(data+i) == 0xa ) ){ + 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') ) + ( (*(data+i) >= 'A') && (*(data+i) <= 'F') ) || + ( (*(data+i) >= 'a') && (*(data+i) <= 'f') ) ) - ){ + ) { return 0; } } @@ -238,6 +239,7 @@ bmc_command_read_int(int* value, char *cmd, int base) int i; char *prev_str = NULL; char *current_str= NULL; + if (bmc_send_command(cmd) < 0) { return ONLP_STATUS_E_INTERNAL; } @@ -249,12 +251,18 @@ bmc_command_read_int(int* value, char *cmd, int base) for (i = 1; i <= TTY_RETRY; i++) { current_str = strstr(prev_str + len, cmd); if(current_str == NULL) { - if( !chk_numeric_char(prev_str + len, base) ){ - return -1; + if (base == 16) { + if (sscanf(prev_str + len, "%x", value)!= 1) { + return -1; + } + } else { + if( !chk_numeric_char(prev_str + len, base) ) { + return -1; + } + *value = strtoul(prev_str + len, NULL, base); } - *value = strtoul(prev_str + len, NULL, base); break; - }else { + } else { prev_str = current_str; continue; } @@ -266,7 +274,7 @@ bmc_command_read_int(int* value, char *cmd, int base) int bmc_file_read_int(int* value, char *file, int base) { - char cmd[64] = {0}; + char cmd[128] = {0}; snprintf(cmd, sizeof(cmd), "cat %s\r\n", file); return bmc_command_read_int(value, cmd, base); } @@ -275,7 +283,7 @@ int bmc_i2c_readb(uint8_t bus, uint8_t devaddr, uint8_t addr) { int ret = 0, value; - char cmd[64] = {0}; + char cmd[128] = {0}; snprintf(cmd, sizeof(cmd), "i2cget -f -y %d 0x%x 0x%02x\r\n", bus, devaddr, addr); ret = bmc_command_read_int(&value, cmd, 16); @@ -285,7 +293,7 @@ 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) { - char cmd[64] = {0}; + char cmd[128] = {0}; snprintf(cmd, sizeof(cmd), "i2cset -f -y %d 0x%x 0x%02x 0x%x\r\n", bus, devaddr, addr, value); return bmc_send_command(cmd); } @@ -294,7 +302,7 @@ int bmc_i2c_readw(uint8_t bus, uint8_t devaddr, uint8_t addr) { int ret = 0, value; - char cmd[64] = {0}; + char cmd[128] = {0}; snprintf(cmd, sizeof(cmd), "i2cget -f -y %d 0x%x 0x%02x w\r\n", bus, devaddr, addr); ret = bmc_command_read_int(&value, cmd, 16); @@ -305,7 +313,7 @@ int bmc_i2c_readraw(uint8_t bus, uint8_t devaddr, uint8_t addr, char* data, int data_size) { int data_len, i = 0; - char cmd[64] = {0}; + char cmd[128] = {0}; char *str = NULL; snprintf(cmd, sizeof(cmd), "i2craw -w 0x%x -r 0 %d 0x%02x\r\n", addr, bus, devaddr); @@ -332,6 +340,6 @@ bmc_i2c_readraw(uint8_t bus, uint8_t devaddr, uint8_t addr, char* data, int data } data[i] = 0; - return 0; + return 0; } diff --git a/packages/platforms/accton/x86-64/x86-64-accton-minipack/onlp/builds/src/module/src/platform_lib.h b/packages/platforms/accton/x86-64/x86-64-accton-minipack/onlp/builds/src/module/src/platform_lib.h old mode 100644 new mode 100755 index a58e0bbb..1a48fe12 --- a/packages/platforms/accton/x86-64/x86-64-accton-minipack/onlp/builds/src/module/src/platform_lib.h +++ b/packages/platforms/accton/x86-64/x86-64-accton-minipack/onlp/builds/src/module/src/platform_lib.h @@ -31,18 +31,20 @@ #define DEBUG_MODE 0 #if (DEBUG_MODE == 1) - #define DEBUG_PRINT(fmt, args...) \ +#define DEBUG_PRINT(fmt, args...) \ printf("%s:%s[%d]: " fmt "\r\n", __FILE__, __FUNCTION__, __LINE__, ##args) #else - #define DEBUG_PRINT(fmt, args...) +#define DEBUG_PRINT(fmt, args...) #endif -#define CHASSIS_FAN_COUNT 5 +#define CHASSIS_FAN_COUNT 8 #define CHASSIS_THERMAL_COUNT 8 #define CHASSIS_LED_COUNT 2 -#define CHASSIS_PSU_COUNT 2 +#define CHASSIS_PSU_COUNT 4 + +#define IDPROM_PATH "/sys/bus/i2c/devices/1-0057/eeprom" +#define PLATFOTM_H_TTY_RETRY (5) -#define IDPROM_PATH "/sys/class/i2c-adapter/i2c-40/40-0050/eeprom" enum onlp_thermal_id { diff --git a/packages/platforms/accton/x86-64/x86-64-accton-minipack/onlp/builds/src/module/src/psui.c b/packages/platforms/accton/x86-64/x86-64-accton-minipack/onlp/builds/src/module/src/psui.c old mode 100644 new mode 100755 index 7b964eb6..2bc2fb57 --- a/packages/platforms/accton/x86-64/x86-64-accton-minipack/onlp/builds/src/module/src/psui.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-minipack/onlp/builds/src/module/src/psui.c @@ -36,8 +36,12 @@ } \ } while(0) -#define PSU1_ID 1 -#define PSU2_ID 2 +enum { + PSU1_ID = 1, /*Left-upper*/ + PSU2_ID, /*Left-lower*/ + PSU3_ID, /*Right-upper*/ + PSU4_ID, /*Right-lower*/ +}; /* * Get all information about the given PSU oid. @@ -45,12 +49,10 @@ static onlp_psu_info_t pinfo[] = { { }, /* Not used */ - { - { ONLP_PSU_ID_CREATE(PSU1_ID), "PSU-1", 0 }, - }, - { - { ONLP_PSU_ID_CREATE(PSU2_ID), "PSU-2", 0 }, - } + { {ONLP_PSU_ID_CREATE(PSU1_ID), "PSU-1", 0}, }, + { {ONLP_PSU_ID_CREATE(PSU2_ID), "PSU-2", 0}, }, + { {ONLP_PSU_ID_CREATE(PSU3_ID), "PSU-3", 0}, }, + { {ONLP_PSU_ID_CREATE(PSU4_ID), "PSU-4", 0}, }, }; int @@ -58,7 +60,7 @@ onlp_psui_init(void) { return ONLP_STATUS_OK; } - +/* static int twos_complement_to_int(uint16_t data, uint8_t valid_bit, int mask) { @@ -68,6 +70,7 @@ twos_complement_to_int(uint16_t data, uint8_t valid_bit, int mask) return is_negative ? (-(((~valid_data) & mask) + 1)) : valid_data; } + static int pmbus_parse_literal_format(uint16_t value) { @@ -78,14 +81,15 @@ pmbus_parse_literal_format(uint16_t value) return (exponent >= 0) ? (mantissa << exponent) * multiplier : (mantissa * multiplier) / (1 << -exponent); -} +}*/ + +#define PMBUS_PATH_FORMAT "/sys/bus/platform/devices/minipack_psensor/%s%d_input" int onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) { - int pid, value, addr; - - uint8_t mask = 0; + int pid, value, pid_in, pid_out; + char path[64] = {0}; VALIDATE(id); @@ -94,6 +98,8 @@ onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) /* Get the present status */ +#if 0 + uint8_t mask = 0; mask = 1 << ((pid-1) * 4); value = onlp_i2c_readb(1, 0x32, 0x10, ONLP_I2C_F_FORCE); if (value < 0) { @@ -123,53 +129,90 @@ onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) return ONLP_STATUS_E_INTERNAL; } usleep(1200); +#else + + info->status |= ONLP_PSU_STATUS_PRESENT; + info->caps = ONLP_PSU_CAPS_AC; +#endif + pid_in = (pid * 2) - 1; + pid_out = pid * 2; + + /* 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); + sprintf(path, PMBUS_PATH_FORMAT, "in", pid_in); + if (onlp_file_read_int(&value, path) < 0) { + AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } + + if (value >= 1000) { + info->mvin = value; info->caps |= ONLP_PSU_CAPS_VIN; } /* Read iin */ - value = bmc_i2c_readw(7, addr, 0x89); + sprintf(path, PMBUS_PATH_FORMAT, "curr", pid_in); + if (onlp_file_read_int(&value, path) < 0) { + AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } if (value >= 0) { - info->miin = pmbus_parse_literal_format(value); + info->miin = value; 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; + sprintf(path, PMBUS_PATH_FORMAT, "power", pid_in); + if (onlp_file_read_int(&value, path) < 0) { + AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } + if (value >= 0) { + info->mpin = value / 1000; /*power is in unit of microWatts.*/ info->caps |= ONLP_PSU_CAPS_PIN; } + /* Get vout */ + sprintf(path, PMBUS_PATH_FORMAT, "in", pid_out); + if (onlp_file_read_int(&value, path) < 0) { + AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } + if (value >= 0) { + info->mvout = value; + info->caps |= ONLP_PSU_CAPS_VOUT; + } /* Read iout */ - value = bmc_i2c_readw(7, addr, 0x8c); + sprintf(path, PMBUS_PATH_FORMAT, "curr", pid_out); + if (onlp_file_read_int(&value, path) < 0) { + AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } if (value >= 0) { - info->miout = pmbus_parse_literal_format(value); + info->miout = value; info->caps |= ONLP_PSU_CAPS_IOUT; } /* Read pout */ - value = bmc_i2c_readw(7, addr, 0x96); + sprintf(path, PMBUS_PATH_FORMAT, "power", pid_out); + if (onlp_file_read_int(&value, path) < 0) { + AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } if (value >= 0) { - info->mpout = pmbus_parse_literal_format(value); + info->mpout = value/1000; /*power is in unit of microWatts.*/; info->caps |= ONLP_PSU_CAPS_POUT; } - /* 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 */ - bmc_i2c_readraw(7, addr, 0x9a, info->model, sizeof(info->model)); - + //bmc_i2c_readraw(7, addr, 0x9a, info->model, sizeof(info->model)); + info->model[0] = '0'; /* Get serial number */ - return bmc_i2c_readraw(7, addr, 0x9e, info->serial, sizeof(info->serial)); + //bmc_i2c_readraw(7, addr, 0x9e, info->serial, sizeof(info->serial)); + info->serial[0] = '0'; + + return 0; } int diff --git a/packages/platforms/accton/x86-64/x86-64-accton-minipack/onlp/builds/src/module/src/sfpi.c b/packages/platforms/accton/x86-64/x86-64-accton-minipack/onlp/builds/src/module/src/sfpi.c old mode 100644 new mode 100755 index 1c069d3c..7823b144 --- a/packages/platforms/accton/x86-64/x86-64-accton-minipack/onlp/builds/src/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-minipack/onlp/builds/src/module/src/sfpi.c @@ -23,6 +23,7 @@ * * ***********************************************************/ +#include #include #include #include @@ -31,25 +32,47 @@ #include "x86_64_accton_minipack_log.h" #define BIT(i) (1 << (i)) -#define NUM_OF_SFP_PORT 32 -#define PORT_EEPROM_FORMAT "/sys/bus/i2c/devices/%d-0050/eeprom" +#define NUM_OF_PIM (8) +#define TYPES_OF_PIM (2) +#define NUM_OF_SFP_PORT (128) +#define SFP_PORT_PER_PIM (NUM_OF_SFP_PORT/NUM_OF_PIM) +#define PORT_EEPROM_FORMAT "/sys/bus/i2c/devices/%d-0050/eeprom" -static const int sfp_bus_index[] = { - 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, 33, 32 -}; +/* PIM stands for "Port Interface Module". + * For minipack, there are hot-pluggable 8 PIMs. + * Each PIM can have 16*16Q or 4*4DD ports. + */ +#define I2C_BUS (1) +#define PIM_POLL_INTERVAL (8) /*in seconds*/ +#define PORT_POLL_INTERVAL (5) /*per PIM, in seconds*/ + +typedef struct { + bool valid; + time_t last_poll; + uint32_t present; +} present_status_t; + +typedef struct { + present_status_t pim; + present_status_t port_at_pim[NUM_OF_SFP_PORT/NUM_OF_PIM]; +} port_status_t; + +static port_status_t ps; /************************************************************ * * SFPI Entry Points * ***********************************************************/ +static int +sfpi_eeprom_close_all_channels(void); + int onlp_sfpi_init(void) { - /* Called at initialization time */ + /* Called at initialization time */ + memset(&ps, 0, sizeof(ps)); + sfpi_eeprom_close_all_channels(); return ONLP_STATUS_OK; } @@ -69,24 +92,106 @@ onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap) return ONLP_STATUS_OK; } -static uint8_t -onlp_sfpi_reg_val_to_port_sequence(uint8_t value, int revert) +/* +0 @bit 14 +1 @bit 15 +2 @bit 12 +3 @bit 13 +4 @bit 10 +5 @bit 11 +6 @bit 8 +7 @bit 9 +... same order for port 8-15. +*/ +static uint32_t +onlp_sfpi_reg_val_to_port_sequence(uint32_t value, int revert) { - int i; - uint8_t ret = 0; + int i, j; + uint32_t ret = 0; - for (i = 0; i < 8; i++) { + for (i = 0; i < SFP_PORT_PER_PIM; i++) { if (i % 2) { - ret |= (value & BIT(i)) >> 1; + j = 16 - i; } else { - ret |= (value & BIT(i)) << 1; + j = 14 - i; } + ret |= (!!(value & BIT(j)) << i); } return revert ? ~ret : ret; } + +/* "PIM" stands for "Port Interface Module". + * A pim can have 16 QSFP ports of 100Gbps, or 4 DD ports of 400 Gbps. + * + * Return 1 if present. + * Return 0 if not present. + * Return < 0 if error. + */ +static int +onlp_pim_is_present(int pim) +{ + time_t cur, elapse; + uint32_t present; + int bus = 12; + int addr = 0x3e; + int offset = 0x32; + + cur = time (NULL); + elapse = cur - ps.pim.last_poll; + + if (!ps.pim.valid || (elapse > PIM_POLL_INTERVAL)) { + present = bmc_i2c_readb(bus, addr, offset); + if (present < 0) { + ps.pim.valid = 0; + return ONLP_STATUS_E_INTERNAL; + } + ps.pim.valid = 1; + ps.pim.present = present; + ps.pim.last_poll = time (NULL); + } else { + present = ps.pim.present; + } + + return !(present & BIT(pim % NUM_OF_PIM)); +} + +static int +get_port_present_bmap(int port, uint32_t *bit_array) +{ + time_t cur, elapse; + uint32_t present, pim; + present_status_t *ports; + int bus[NUM_OF_PIM] = {80, 88, 96, 104, 112, 120, 128, 136}; + int addr[TYPES_OF_PIM] = {0x60, 0x61}; /*Different for 16Q and 4DD.*/ + int offset = 0x12; + + pim = port/SFP_PORT_PER_PIM; + + ports = &ps.port_at_pim[pim]; + cur = time (NULL); + elapse = cur - ports->last_poll; + + if (!ports->valid || (elapse > PORT_POLL_INTERVAL)) { + present = bmc_i2c_readw(bus[pim], addr[0], offset); + if (present < 0) { + ports->valid = 0; + return ONLP_STATUS_E_INTERNAL; + } + ports->valid = 1; + ports->present = present; + ports->last_poll = time (NULL); + } else { + present = ports->present; + } + + *bit_array = onlp_sfpi_reg_val_to_port_sequence(present, 0); + return ONLP_STATUS_OK; +} + + int onlp_sfpi_is_present(int port) { @@ -95,58 +200,50 @@ onlp_sfpi_is_present(int port) * Return 0 if not present. * Return < 0 if error. */ - int present; - int bus = (port < 16) ? 36 : 37; - int addr = (port < 16) ? 0x22 : 0x23; /* pca9535 slave address */ - int offset; + int present, pim, ret; + uint32_t bit_array; - if (port < 8 || (port >= 16 && port <= 23)) { - offset = 0; - } - else { - offset = 1; - } - - present = onlp_i2c_readb(bus, addr, offset, ONLP_I2C_F_FORCE); + pim = port/SFP_PORT_PER_PIM; + present = onlp_pim_is_present(pim); if (present < 0) { return ONLP_STATUS_E_INTERNAL; } + if (!present) { + return 0; + } - present = onlp_sfpi_reg_val_to_port_sequence(present, 0); - return !(present & BIT(port % 8)); + ret = get_port_present_bmap(port, &bit_array); + if (ret < 0) { + return ret; + } + + + return !(bit_array & BIT(port % SFP_PORT_PER_PIM)); } int onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) { - int i; - uint8_t bytes[4] = {0}; + int i, port, ret; + uint32_t bmp; + uint32_t bmap_pim[NUM_OF_PIM] = {0}; - for (i = 0; i < AIM_ARRAYSIZE(bytes); i++) { - int bus = (i < 2) ? 36 : 37; - int addr = (i < 2) ? 0x22 : 0x23; /* pca9535 slave address */ - int offset = (i % 2); + /*Get present bitmap per PIM.*/ + for (i = 0; i < NUM_OF_PIM; i++) { + port = i*SFP_PORT_PER_PIM; + ret = get_port_present_bmap(port, &bmap_pim[i]); + if (ret < 0) + return ret; + } - bytes[i] = onlp_i2c_readb(bus, addr, offset, ONLP_I2C_F_FORCE); - if (bytes[i] < 0) { - return ONLP_STATUS_E_INTERNAL; + for (i = 0; i < NUM_OF_SFP_PORT; i++) { + AIM_BITMAP_CLR(dst, i); + } + for (i = 0; i < NUM_OF_SFP_PORT; i++) { + bmp = bmap_pim[i/SFP_PORT_PER_PIM]; + if (!(bmp & BIT(i%SFP_PORT_PER_PIM))) { + AIM_BITMAP_SET(dst, i); } - - bytes[i] = onlp_sfpi_reg_val_to_port_sequence(bytes[i], 1); - } - - /* Convert to 32 bit integer in port order */ - i = 0; - uint32_t presence_all = 0 ; - for(i = AIM_ARRAYSIZE(bytes)-1; i >= 0; i--) { - presence_all <<= 8; - presence_all |= bytes[i]; - } - - /* Populate bitmap */ - for(i = 0; presence_all; i++) { - AIM_BITMAP_MOD(dst, i, (presence_all & 1)); - presence_all >>= 1; } return ONLP_STATUS_OK; @@ -158,35 +255,143 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) return ONLP_STATUS_OK; } -int -onlp_sfpi_eeprom_read(int port, uint8_t data[256]) +static int +sfpi_eeprom_close_all_channels(void) { - int size = 0; - if(port <0 || port >= NUM_OF_SFP_PORT) - return ONLP_STATUS_E_INTERNAL; - memset(data, 0, 256); + int i, k; + int value = 0 ; + int mux_1st = 0x70; + int mux_2st[] = {0x72, 0x71}; + int offset = 0; + int channels = 8; - if(onlp_file_read(data, 256, &size, PORT_EEPROM_FORMAT, sfp_bus_index[port]) != ONLP_STATUS_OK) { - AIM_LOG_ERROR("Unable to read eeprom from port(%d)\r\n", port); + for (i = 0; i < channels; i++) { + /* Skip checking if PIM is plugged. Cuz BMC traffic may not be ready at init. + if (onlp_pim_is_present(i) != 1) + continue; + */ + value = 1<mcelsius, path, 10) < 0) { + + if (onlp_file_read_int(&info->mcelsius, path) < 0) { AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", path); return ONLP_STATUS_E_INTERNAL; }