From 9856e658997797f8590c57e0ca7e2924bc79e49a Mon Sep 17 00:00:00 2001 From: Nataliya Yakuts Date: Mon, 26 Mar 2018 14:20:06 +0000 Subject: [PATCH] Mellanox common code restructuring. MSN2100, MSN2410, MSN2700 platforms support. Signed-off-by: Nataliya Yakuts Reviewed-by: Michael Shych --- .../mellanox/any/src/mlnx_common/.module | 1 + .../mellanox/any/src/mlnx_common/Makefile | 9 + .../mellanox/any/src/mlnx_common/README | 5 + .../any/src/mlnx_common/mlnx_common.doxy | 0 .../any/src/mlnx_common/mlnx_common.mk | 13 + .../any/src/mlnx_common/module/auto/make.mk | 8 + .../mlnx_common/module/auto/mlnx_common.yml | 47 ++ .../module/inc/mlnx_common/mlnx_common.h | 183 +++++++ .../module/inc/mlnx_common/mlnx_common.x | 12 + .../inc/mlnx_common/mlnx_common_config.h | 127 +++++ .../module/inc/mlnx_common/mlnx_common_dox.h | 26 + .../inc/mlnx_common/mlnx_common_porting.h | 107 ++++ .../any/src/mlnx_common/module/make.mk | 9 + .../any/src/mlnx_common/module/src/Makefile | 8 + .../any/src/mlnx_common/module/src/make.mk | 9 + .../module/src/mlnx_common_config.c | 75 +++ .../module/src/mlnx_common_enums.c | 9 + .../mlnx_common/module/src/mlnx_common_fani.c | 411 +++++++++++++++ .../mlnx_common/module/src/mlnx_common_int.h | 17 + .../mlnx_common/module/src/mlnx_common_ledi.c | 346 +++++++++++++ .../mlnx_common/module/src/mlnx_common_log.c | 17 + .../mlnx_common/module/src/mlnx_common_log.h | 12 + .../module/src/mlnx_common_module.c | 22 + .../module/src/mlnx_common_psui.c} | 155 ++++-- .../module/src/mlnx_common_sfpi.c} | 69 +-- .../mlnx_common/module/src/mlnx_common_sysi.c | 391 ++++++++++++++ .../module/src/mlnx_common_thermali.c | 74 +++ .../mlnx_common/module/src/mlnx_common_ucli.c | 49 ++ .../module/src/mlnx_common_utils.c} | 8 +- .../module/src/mlnx_platform_common_int.h | 17 + .../any/src/mlnx_common/utest/_make.mk | 8 + .../mellanox/any/src/mlnx_common/utest/main.c | 18 + .../onlp/builds/lib/Makefile | 3 +- .../onlp/builds/onlpdump/Makefile | 3 +- .../onlp/builds/src/module/src/fani.c | 309 +---------- .../onlp/builds/src/module/src/ledi.c | 292 +---------- .../onlp/builds/src/module/src/platform_lib.c | 63 --- .../onlp/builds/src/module/src/platform_lib.h | 40 +- .../onlp/builds/src/module/src/psui.c | 173 ------- .../onlp/builds/src/module/src/sysi.c | 185 +------ .../onlp/builds/src/module/src/thermali.c | 75 +-- .../x86-64/x86-64-mlnx-msn2410/onlp/Makefile | 2 +- .../onlp/builds/lib/Makefile | 3 +- .../onlp/builds/onlpdump/Makefile | 3 +- .../onlp/builds/src/module/src/fani.c | 478 +----------------- .../onlp/builds/src/module/src/ledi.c | 304 +---------- .../onlp/builds/src/module/src/platform_lib.c | 109 ---- .../onlp/builds/src/module/src/platform_lib.h | 43 +- .../onlp/builds/src/module/src/sfpi.c | 262 ---------- .../onlp/builds/src/module/src/sysi.c | 231 ++------- .../onlp/builds/src/module/src/thermali.c | 80 +-- .../onlp/builds/lib/Makefile | 3 +- .../onlp/builds/onlpdump/Makefile | 2 +- .../onlp/builds/src/module/src/fani.c | 478 +----------------- .../onlp/builds/src/module/src/ledi.c | 304 +---------- .../onlp/builds/src/module/src/platform_lib.h | 43 +- .../onlp/builds/src/module/src/psui.c | 200 -------- .../onlp/builds/src/module/src/sfpi.c | 262 ---------- .../onlp/builds/src/module/src/sysi.c | 231 ++------- .../onlp/builds/src/module/src/thermali.c | 80 +-- 60 files changed, 2347 insertions(+), 4176 deletions(-) create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/.module create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/Makefile create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/README create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/mlnx_common.doxy create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/mlnx_common.mk create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/module/auto/make.mk create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/module/auto/mlnx_common.yml create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/module/inc/mlnx_common/mlnx_common.h create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/module/inc/mlnx_common/mlnx_common.x create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/module/inc/mlnx_common/mlnx_common_config.h create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/module/inc/mlnx_common/mlnx_common_dox.h create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/module/inc/mlnx_common/mlnx_common_porting.h create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/module/make.mk create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/module/src/Makefile create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/module/src/make.mk create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_config.c create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_enums.c create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_fani.c create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_int.h create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_ledi.c create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_log.c create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_log.h create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_module.c rename packages/platforms/mellanox/{x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/psui.c => any/src/mlnx_common/module/src/mlnx_common_psui.c} (59%) rename packages/platforms/mellanox/{x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/sfpi.c => any/src/mlnx_common/module/src/mlnx_common_sfpi.c} (75%) create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_sysi.c create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_thermali.c create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_ucli.c rename packages/platforms/mellanox/{x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/platform_lib.c => any/src/mlnx_common/module/src/mlnx_common_utils.c} (94%) create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_platform_common_int.h create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/utest/_make.mk create mode 100644 packages/platforms/mellanox/any/src/mlnx_common/utest/main.c delete mode 100644 packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/platform_lib.c delete mode 100644 packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/psui.c delete mode 100644 packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/platform_lib.c delete mode 100644 packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/sfpi.c delete mode 100644 packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/psui.c delete mode 100644 packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/sfpi.c diff --git a/packages/platforms/mellanox/any/src/mlnx_common/.module b/packages/platforms/mellanox/any/src/mlnx_common/.module new file mode 100644 index 00000000..404e7177 --- /dev/null +++ b/packages/platforms/mellanox/any/src/mlnx_common/.module @@ -0,0 +1 @@ +name: mlnx_common diff --git a/packages/platforms/mellanox/any/src/mlnx_common/Makefile b/packages/platforms/mellanox/any/src/mlnx_common/Makefile new file mode 100644 index 00000000..79031835 --- /dev/null +++ b/packages/platforms/mellanox/any/src/mlnx_common/Makefile @@ -0,0 +1,9 @@ +############################################################################### +# +# +# +############################################################################### +include $(ONL)/make/config.mk +MODULE := mlnx_common +AUTOMODULE := mlnx_common +include $(BUILDER)/definemodule.mk diff --git a/packages/platforms/mellanox/any/src/mlnx_common/README b/packages/platforms/mellanox/any/src/mlnx_common/README new file mode 100644 index 00000000..2134ce57 --- /dev/null +++ b/packages/platforms/mellanox/any/src/mlnx_common/README @@ -0,0 +1,5 @@ +############################################################################### +# +# mlnx_common README +# +############################################################################### diff --git a/packages/platforms/mellanox/any/src/mlnx_common/mlnx_common.doxy b/packages/platforms/mellanox/any/src/mlnx_common/mlnx_common.doxy new file mode 100644 index 00000000..e69de29b diff --git a/packages/platforms/mellanox/any/src/mlnx_common/mlnx_common.mk b/packages/platforms/mellanox/any/src/mlnx_common/mlnx_common.mk new file mode 100644 index 00000000..6670b8fa --- /dev/null +++ b/packages/platforms/mellanox/any/src/mlnx_common/mlnx_common.mk @@ -0,0 +1,13 @@ + +############################################################################### +# +# Inclusive Makefile for the mlnx_common module. +# +# Autogenerated 2017-11-15 18:52:06.437798 +# +############################################################################### +mlnx_common_BASEDIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) +include $(mlnx_common_BASEDIR)/module/make.mk +include $(mlnx_common_BASEDIR)/module/auto/make.mk +include $(mlnx_common_BASEDIR)/module/src/make.mk +include $(mlnx_common_BASEDIR)/utest/_make.mk diff --git a/packages/platforms/mellanox/any/src/mlnx_common/module/auto/make.mk b/packages/platforms/mellanox/any/src/mlnx_common/module/auto/make.mk new file mode 100644 index 00000000..b4dd174b --- /dev/null +++ b/packages/platforms/mellanox/any/src/mlnx_common/module/auto/make.mk @@ -0,0 +1,8 @@ +############################################################################### +# +# mlnx_common Autogeneration +# +############################################################################### +mlnx_common_AUTO_DEFS := module/auto/mlnx_common.yml +mlnx_common_AUTO_DIRS := module/inc/mlnx_common module/src +include $(BUILDER)/auto.mk diff --git a/packages/platforms/mellanox/any/src/mlnx_common/module/auto/mlnx_common.yml b/packages/platforms/mellanox/any/src/mlnx_common/module/auto/mlnx_common.yml new file mode 100644 index 00000000..d79c0cb7 --- /dev/null +++ b/packages/platforms/mellanox/any/src/mlnx_common/module/auto/mlnx_common.yml @@ -0,0 +1,47 @@ +############################################################################### +# +# mlnx_common Autogeneration Definitions. +# +############################################################################### + +cdefs: &cdefs +- MLNX_COMMON_CONFIG_INCLUDE_LOGGING: + doc: "Include or exclude logging." + default: 1 +- MLNX_COMMON_CONFIG_LOG_OPTIONS_DEFAULT: + doc: "Default enabled log options." + default: AIM_LOG_OPTIONS_DEFAULT +- MLNX_COMMON_CONFIG_LOG_BITS_DEFAULT: + doc: "Default enabled log bits." + default: AIM_LOG_BITS_DEFAULT +- MLNX_COMMON_CONFIG_LOG_CUSTOM_BITS_DEFAULT: + doc: "Default enabled custom log bits." + default: 0 +- MLNX_COMMON_CONFIG_PORTING_STDLIB: + doc: "Default all porting macros to use the C standard libraries." + default: 1 +- MLNX_COMMON_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS: + doc: "Include standard library headers for stdlib porting macros." + default: MLNX_COMMON_CONFIG_PORTING_STDLIB +- MLNX_COMMON_CONFIG_INCLUDE_UCLI: + doc: "Include generic uCli support." + default: 0 + + +definitions: + cdefs: + MLNX_COMMON_CONFIG_HEADER: + defs: *cdefs + basename: mlnx_common_config + + portingmacro: + MLNX_COMMON: + macros: + - malloc + - free + - memset + - memcpy + - strncpy + - vsnprintf + - snprintf + - strlen diff --git a/packages/platforms/mellanox/any/src/mlnx_common/module/inc/mlnx_common/mlnx_common.h b/packages/platforms/mellanox/any/src/mlnx_common/module/inc/mlnx_common/mlnx_common.h new file mode 100644 index 00000000..f2bd7dbe --- /dev/null +++ b/packages/platforms/mellanox/any/src/mlnx_common/module/inc/mlnx_common/mlnx_common.h @@ -0,0 +1,183 @@ +/**************************************************************************//** + * + * @file + * @brief mlnx_common Main Interface Header + * + * @addtogroup mlnx_common + * @{ + * + *****************************************************************************/ +#ifndef __MLNX_COMMON_H__ +#define __MLNX_COMMON_H__ + +#include +#include +#include +#include +#include + +#define PLATFORM_NAME_MAX_LEN 64 + +#ifndef KERNEL_VERSION +#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) +#endif + +#define LED_TYPE_1 1 +#define LED_TYPE_2 2 + +/* led common id */ +#define LED_RESERVED 0 +#define LED_SYSTEM 1 +/*led type 1 id */ +#define LED_FAN1 2 +#define LED_FAN2 3 +#define LED_FAN3 4 +#define LED_FAN4 5 +#define LED_PSU 6 +/*led type 2 id */ +#define LED_FAN 2 +#define LED_PSU1 3 +#define LED_PSU2 4 +#define LED_UID 5 + +#define PERCENTAGE_MIN 60.0 +#define PERCENTAGE_MAX 100.0 +#define RPM_MAGIC_MIN 153.0 +#define RPM_MAGIC_MAX 255.0 + +#define PSU_FAN_RPM_MIN 11700.0 +#define PSU_FAN_RPM_MAX 19500.0 + +#define PROJECT_NAME +#define LEN_FILE_NAME 80 + +/* 1 -without eeprom, 2 - with eeprom */ +#define PSU_TYPE_1 1 +#define PSU_TYPE_2 2 + +#define FAN_MODEL "MEC012579" + +#define FAN_TYPE_NO_EEPROM 1 +#define FAN_TYPE_EEPROM 2 + +#define _MAKE_FAN_PATH_ON_MAIN_BOARD(prj,id) \ + { #prj"fan"#id"_status", \ + #prj"fan"#id"_speed_get", \ + #prj"fan"#id"_speed_set", \ + #prj"fan"#id"_min", \ + #prj"fan"#id"_max" } + +#define MAKE_FAN_PATH_ON_MAIN_BOARD(prj,id) _MAKE_FAN_PATH_ON_MAIN_BOARD(prj,id) + +#define MAKE_FAN_PATH_ON_PSU(psu_id, fan_id) \ + {"psu"#psu_id"_status", \ + "psu"#psu_id"_fan"#fan_id"_speed_get", "", "", "",} + +#define MAKE_FAN_INFO_NODE_ON_MAIN_BOARD(id) \ + { \ + { ONLP_FAN_ID_CREATE(FAN_##id##_ON_MAIN_BOARD), "Chassis Fan "#id, 0 }, \ + 0x0, \ + (ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_GET_PERCENTAGE | \ + ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_SET_RPM), \ + 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 }, \ + 0x0, \ + (ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE), \ + 0, \ + 0, \ + ONLP_FAN_MODE_INVALID, \ + } + +typedef struct fan_path_S +{ + char status[LEN_FILE_NAME]; + char r_speed_get[LEN_FILE_NAME]; + char r_speed_set[LEN_FILE_NAME]; + char min[LEN_FILE_NAME]; + char max[LEN_FILE_NAME]; +} fan_path_T; + +/** Specific platform info structure. */ +typedef struct mlnx_platform_info_s { + char onl_platform_name[PLATFORM_NAME_MAX_LEN]; + int sfp_num; + int led_num; + int psu_num; + int fan_num; + int thermal_num; + int cpld_num; + bool psu_fixed; + bool fan_fixed; + int* min_fan_speed; + int* max_fan_speed; + onlp_thermal_info_t* tinfo; + char** thermal_fnames; + onlp_led_info_t* linfo; + char** led_fnames; + int psu_type; + int led_type; + onlp_fan_info_t* finfo; + fan_path_T* fan_fnames; + int fan_type; + int first_psu_fan_id; +} mlnx_platform_info_t; + +#define PSU1_ID 1 +#define PSU2_ID 2 +#define PSU_MODULE_PREFIX "/bsp/module/psu%d_%s" +#define PSU_POWER_PREFIX "/bsp/power/psu%d_%s" +#define IDPROM_PATH "/bsp/eeprom/%s%d_info" + +typedef enum psu_type { + PSU_TYPE_UNKNOWN, + PSU_TYPE_AC_F2B, + PSU_TYPE_AC_B2F +} psu_type_t; + +/* CPU thermal_threshold */ +typedef enum cpu_thermal_threshold_e { + CPU_THERMAL_THRESHOLD_WARNING_DEFAULT = 87000, + CPU_THERMAL_THRESHOLD_ERROR_DEFAULT = 100000, + CPU_THERMAL_THRESHOLD_SHUTDOWN_DEFAULT = 105000, +} cpu_thermal_threshold_t; + +/* Shortcut for CPU thermal threshold value. */ +#define CPU_THERMAL_THRESHOLD_INIT_DEFAULTS \ + { CPU_THERMAL_THRESHOLD_WARNING_DEFAULT, \ + CPU_THERMAL_THRESHOLD_ERROR_DEFAULT, \ + CPU_THERMAL_THRESHOLD_SHUTDOWN_DEFAULT } + +/* Asic thermal_threshold */ +typedef enum asic_thermal_threshold_e { + ASIC_THERMAL_THRESHOLD_WARNING_DEFAULT = 105000, + ASIC_THERMAL_THRESHOLD_ERROR_DEFAULT = 115000, + ASIC_THERMAL_THRESHOLD_SHUTDOWN_DEFAULT = 120000, +} asic_thermal_threshold_t; + +/* Shortcut for CPU thermal threshold value. */ +#define ASIC_THERMAL_THRESHOLD_INIT_DEFAULTS \ + { ASIC_THERMAL_THRESHOLD_WARNING_DEFAULT, \ + ASIC_THERMAL_THRESHOLD_ERROR_DEFAULT, \ + ASIC_THERMAL_THRESHOLD_SHUTDOWN_DEFAULT } + +int mc_get_kernel_ver(void); + +int mc_get_platform_info(mlnx_platform_info_t* mlnx_platform); + +int onlp_fani_get_min_rpm(int id); + +int psu_read_eeprom(int psu_index, onlp_psu_info_t* psu_info, + onlp_fan_info_t* fan_info); + +mlnx_platform_info_t* get_platform_info(); + +psu_type_t get_psu_type(int id, char* modelname, int modelname_len); + +#endif /* __MLNX_COMMON_H__ */ +/* @} */ diff --git a/packages/platforms/mellanox/any/src/mlnx_common/module/inc/mlnx_common/mlnx_common.x b/packages/platforms/mellanox/any/src/mlnx_common/module/inc/mlnx_common/mlnx_common.x new file mode 100644 index 00000000..2ab1c9da --- /dev/null +++ b/packages/platforms/mellanox/any/src/mlnx_common/module/inc/mlnx_common/mlnx_common.x @@ -0,0 +1,12 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +/* <--auto.start.xmacro(ALL).define> */ +/* */ + +/* <--auto.start.xenum(ALL).define> */ +/* */ diff --git a/packages/platforms/mellanox/any/src/mlnx_common/module/inc/mlnx_common/mlnx_common_config.h b/packages/platforms/mellanox/any/src/mlnx_common/module/inc/mlnx_common/mlnx_common_config.h new file mode 100644 index 00000000..8de249db --- /dev/null +++ b/packages/platforms/mellanox/any/src/mlnx_common/module/inc/mlnx_common/mlnx_common_config.h @@ -0,0 +1,127 @@ +/**************************************************************************//** + * + * @file + * @brief mlnx_common Configuration Header + * + * @addtogroup mlnx_common-config + * @{ + * + *****************************************************************************/ +#ifndef __MLNX_COMMON_CONFIG_H__ +#define __MLNX_COMMON_CONFIG_H__ + +#ifdef GLOBAL_INCLUDE_CUSTOM_CONFIG +#include +#endif +#ifdef MLNX_COMMON_INCLUDE_CUSTOM_CONFIG +#include +#endif + +/* */ +#include +/** + * MLNX_COMMON_CONFIG_INCLUDE_LOGGING + * + * Include or exclude logging. */ + + +#ifndef MLNX_COMMON_CONFIG_INCLUDE_LOGGING +#define MLNX_COMMON_CONFIG_INCLUDE_LOGGING 1 +#endif + +/** + * MLNX_COMMON_CONFIG_LOG_OPTIONS_DEFAULT + * + * Default enabled log options. */ + + +#ifndef MLNX_COMMON_CONFIG_LOG_OPTIONS_DEFAULT +#define MLNX_COMMON_CONFIG_LOG_OPTIONS_DEFAULT AIM_LOG_OPTIONS_DEFAULT +#endif + +/** + * MLNX_COMMON_CONFIG_LOG_BITS_DEFAULT + * + * Default enabled log bits. */ + + +#ifndef MLNX_COMMON_CONFIG_LOG_BITS_DEFAULT +#define MLNX_COMMON_CONFIG_LOG_BITS_DEFAULT AIM_LOG_BITS_DEFAULT +#endif + +/** + * MLNX_COMMON_CONFIG_LOG_CUSTOM_BITS_DEFAULT + * + * Default enabled custom log bits. */ + + +#ifndef MLNX_COMMON_CONFIG_LOG_CUSTOM_BITS_DEFAULT +#define MLNX_COMMON_CONFIG_LOG_CUSTOM_BITS_DEFAULT 0 +#endif + +/** + * MLNX_COMMON_CONFIG_PORTING_STDLIB + * + * Default all porting macros to use the C standard libraries. */ + + +#ifndef MLNX_COMMON_CONFIG_PORTING_STDLIB +#define MLNX_COMMON_CONFIG_PORTING_STDLIB 1 +#endif + +/** + * MLNX_COMMON_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + * + * Include standard library headers for stdlib porting macros. */ + + +#ifndef MLNX_COMMON_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS +#define MLNX_COMMON_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS MLNX_COMMON_CONFIG_PORTING_STDLIB +#endif + +/** + * MLNX_COMMON_CONFIG_INCLUDE_UCLI + * + * Include generic uCli support. */ + + +#ifndef MLNX_COMMON_CONFIG_INCLUDE_UCLI +#define MLNX_COMMON_CONFIG_INCLUDE_UCLI 0 +#endif + + + +/** + * All compile time options can be queried or displayed + */ + +/** Configuration settings structure. */ +typedef struct mlnx_common_config_settings_s { + /** name */ + const char* name; + /** value */ + const char* value; +} mlnx_common_config_settings_t; + +/** Configuration settings table. */ +/** mlnx_common_config_settings table. */ +extern mlnx_common_config_settings_t mlnx_common_config_settings[]; + +/** + * @brief Lookup a configuration setting. + * @param setting The name of the configuration option to lookup. + */ +const char* mlnx_common_config_lookup(const char* setting); + +/** + * @brief Show the compile-time configuration. + * @param pvs The output stream. + */ +int mlnx_common_config_show(struct aim_pvs_s* pvs); + +/* */ + +#include "mlnx_common_porting.h" + +#endif /* __MLNX_COMMON_CONFIG_H__ */ +/* @} */ diff --git a/packages/platforms/mellanox/any/src/mlnx_common/module/inc/mlnx_common/mlnx_common_dox.h b/packages/platforms/mellanox/any/src/mlnx_common/module/inc/mlnx_common/mlnx_common_dox.h new file mode 100644 index 00000000..e81bf8e0 --- /dev/null +++ b/packages/platforms/mellanox/any/src/mlnx_common/module/inc/mlnx_common/mlnx_common_dox.h @@ -0,0 +1,26 @@ +/**************************************************************************//** + * + * mlnx_common Doxygen Header + * + *****************************************************************************/ +#ifndef __MLNX_COMMON_DOX_H__ +#define __MLNX_COMMON_DOX_H__ + +/** + * @defgroup mlnx_common mlnx_common - mlnx_common Description + * + +The documentation overview for this module should go here. + + * + * @{ + * + * @defgroup mlnx_common-mlnx_common Public Interface + * @defgroup mlnx_common-config Compile Time Configuration + * @defgroup mlnx_common-porting Porting Macros + * + * @} + * + */ + +#endif /* __MLNX_COMMON_DOX_H__ */ diff --git a/packages/platforms/mellanox/any/src/mlnx_common/module/inc/mlnx_common/mlnx_common_porting.h b/packages/platforms/mellanox/any/src/mlnx_common/module/inc/mlnx_common/mlnx_common_porting.h new file mode 100644 index 00000000..7ee1207a --- /dev/null +++ b/packages/platforms/mellanox/any/src/mlnx_common/module/inc/mlnx_common/mlnx_common_porting.h @@ -0,0 +1,107 @@ +/**************************************************************************//** + * + * @file + * @brief mlnx_common Porting Macros. + * + * @addtogroup mlnx_common-porting + * @{ + * + *****************************************************************************/ +#ifndef __MLNX_COMMON_PORTING_H__ +#define __MLNX_COMMON_PORTING_H__ + + +/* */ +#if MLNX_COMMON_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS == 1 +#include +#include +#include +#include +#include +#endif + +#ifndef MLNX_COMMON_MALLOC + #if defined(GLOBAL_MALLOC) + #define MLNX_COMMON_MALLOC GLOBAL_MALLOC + #elif MLNX_COMMON_CONFIG_PORTING_STDLIB == 1 + #define MLNX_COMMON_MALLOC malloc + #else + #error The macro MLNX_COMMON_MALLOC is required but cannot be defined. + #endif +#endif + +#ifndef MLNX_COMMON_FREE + #if defined(GLOBAL_FREE) + #define MLNX_COMMON_FREE GLOBAL_FREE + #elif MLNX_COMMON_CONFIG_PORTING_STDLIB == 1 + #define MLNX_COMMON_FREE free + #else + #error The macro MLNX_COMMON_FREE is required but cannot be defined. + #endif +#endif + +#ifndef MLNX_COMMON_MEMSET + #if defined(GLOBAL_MEMSET) + #define MLNX_COMMON_MEMSET GLOBAL_MEMSET + #elif MLNX_COMMON_CONFIG_PORTING_STDLIB == 1 + #define MLNX_COMMON_MEMSET memset + #else + #error The macro MLNX_COMMON_MEMSET is required but cannot be defined. + #endif +#endif + +#ifndef MLNX_COMMON_MEMCPY + #if defined(GLOBAL_MEMCPY) + #define MLNX_COMMON_MEMCPY GLOBAL_MEMCPY + #elif MLNX_COMMON_CONFIG_PORTING_STDLIB == 1 + #define MLNX_COMMON_MEMCPY memcpy + #else + #error The macro MLNX_COMMON_MEMCPY is required but cannot be defined. + #endif +#endif + +#ifndef MLNX_COMMON_STRNCPY + #if defined(GLOBAL_STRNCPY) + #define MLNX_COMMON_STRNCPY GLOBAL_STRNCPY + #elif MLNX_COMMON_CONFIG_PORTING_STDLIB == 1 + #define MLNX_COMMON_STRNCPY strncpy + #else + #error The macro MLNX_COMMON_STRNCPY is required but cannot be defined. + #endif +#endif + +#ifndef MLNX_COMMON_VSNPRINTF + #if defined(GLOBAL_VSNPRINTF) + #define MLNX_COMMON_VSNPRINTF GLOBAL_VSNPRINTF + #elif MLNX_COMMON_CONFIG_PORTING_STDLIB == 1 + #define MLNX_COMMON_VSNPRINTF vsnprintf + #else + #error The macro MLNX_COMMON_VSNPRINTF is required but cannot be defined. + #endif +#endif + +#ifndef MLNX_COMMON_SNPRINTF + #if defined(GLOBAL_SNPRINTF) + #define MLNX_COMMON_SNPRINTF GLOBAL_SNPRINTF + #elif MLNX_COMMON_CONFIG_PORTING_STDLIB == 1 + #define MLNX_COMMON_SNPRINTF snprintf + #else + #error The macro MLNX_COMMON_SNPRINTF is required but cannot be defined. + #endif +#endif + +#ifndef MLNX_COMMON_STRLEN + #if defined(GLOBAL_STRLEN) + #define MLNX_COMMON_STRLEN GLOBAL_STRLEN + #elif MLNX_COMMON_CONFIG_PORTING_STDLIB == 1 + #define MLNX_COMMON_STRLEN strlen + #else + #error The macro MLNX_COMMON_STRLEN is required but cannot be defined. + #endif +#endif + +/* */ + + +#endif /* __MLNX_COMMON_PORTING_H__ */ +/* @} */ diff --git a/packages/platforms/mellanox/any/src/mlnx_common/module/make.mk b/packages/platforms/mellanox/any/src/mlnx_common/module/make.mk new file mode 100644 index 00000000..c6e5d32e --- /dev/null +++ b/packages/platforms/mellanox/any/src/mlnx_common/module/make.mk @@ -0,0 +1,9 @@ +############################################################################### +# +# +# +############################################################################### +THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) +mlnx_common_INCLUDES := -I $(THIS_DIR)inc +mlnx_common_INTERNAL_INCLUDES := -I $(THIS_DIR)src +mlnx_common_DEPENDMODULE_ENTRIES := init:mlnx_common ucli:mlnx_common diff --git a/packages/platforms/mellanox/any/src/mlnx_common/module/src/Makefile b/packages/platforms/mellanox/any/src/mlnx_common/module/src/Makefile new file mode 100644 index 00000000..df367563 --- /dev/null +++ b/packages/platforms/mellanox/any/src/mlnx_common/module/src/Makefile @@ -0,0 +1,8 @@ +############################################################################### +# +# Local source generation targets. +# +############################################################################### + +ucli: + @../../../../tools/uclihandlers.py mlnx_common_ucli.c diff --git a/packages/platforms/mellanox/any/src/mlnx_common/module/src/make.mk b/packages/platforms/mellanox/any/src/mlnx_common/module/src/make.mk new file mode 100644 index 00000000..5153671b --- /dev/null +++ b/packages/platforms/mellanox/any/src/mlnx_common/module/src/make.mk @@ -0,0 +1,9 @@ +############################################################################### +# +# +# +############################################################################### + +LIBRARY := mlnx_common +$(LIBRARY)_SUBDIR := $(dir $(lastword $(MAKEFILE_LIST))) +include $(BUILDER)/lib.mk diff --git a/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_config.c b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_config.c new file mode 100644 index 00000000..72849a4f --- /dev/null +++ b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_config.c @@ -0,0 +1,75 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +/* */ +#define __mlnx_common_config_STRINGIFY_NAME(_x) #_x +#define __mlnx_common_config_STRINGIFY_VALUE(_x) __mlnx_common_config_STRINGIFY_NAME(_x) +mlnx_common_config_settings_t mlnx_common_config_settings[] = +{ +#ifdef MLNX_COMMON_CONFIG_INCLUDE_LOGGING + { __mlnx_common_config_STRINGIFY_NAME(MLNX_COMMON_CONFIG_INCLUDE_LOGGING), __mlnx_common_config_STRINGIFY_VALUE(MLNX_COMMON_CONFIG_INCLUDE_LOGGING) }, +#else +{ MLNX_COMMON_CONFIG_INCLUDE_LOGGING(__mlnx_common_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef MLNX_COMMON_CONFIG_LOG_OPTIONS_DEFAULT + { __mlnx_common_config_STRINGIFY_NAME(MLNX_COMMON_CONFIG_LOG_OPTIONS_DEFAULT), __mlnx_common_config_STRINGIFY_VALUE(MLNX_COMMON_CONFIG_LOG_OPTIONS_DEFAULT) }, +#else +{ MLNX_COMMON_CONFIG_LOG_OPTIONS_DEFAULT(__mlnx_common_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef MLNX_COMMON_CONFIG_LOG_BITS_DEFAULT + { __mlnx_common_config_STRINGIFY_NAME(MLNX_COMMON_CONFIG_LOG_BITS_DEFAULT), __mlnx_common_config_STRINGIFY_VALUE(MLNX_COMMON_CONFIG_LOG_BITS_DEFAULT) }, +#else +{ MLNX_COMMON_CONFIG_LOG_BITS_DEFAULT(__mlnx_common_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef MLNX_COMMON_CONFIG_LOG_CUSTOM_BITS_DEFAULT + { __mlnx_common_config_STRINGIFY_NAME(MLNX_COMMON_CONFIG_LOG_CUSTOM_BITS_DEFAULT), __mlnx_common_config_STRINGIFY_VALUE(MLNX_COMMON_CONFIG_LOG_CUSTOM_BITS_DEFAULT) }, +#else +{ MLNX_COMMON_CONFIG_LOG_CUSTOM_BITS_DEFAULT(__mlnx_common_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef MLNX_COMMON_CONFIG_PORTING_STDLIB + { __mlnx_common_config_STRINGIFY_NAME(MLNX_COMMON_CONFIG_PORTING_STDLIB), __mlnx_common_config_STRINGIFY_VALUE(MLNX_COMMON_CONFIG_PORTING_STDLIB) }, +#else +{ MLNX_COMMON_CONFIG_PORTING_STDLIB(__mlnx_common_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef MLNX_COMMON_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + { __mlnx_common_config_STRINGIFY_NAME(MLNX_COMMON_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS), __mlnx_common_config_STRINGIFY_VALUE(MLNX_COMMON_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS) }, +#else +{ MLNX_COMMON_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS(__mlnx_common_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef MLNX_COMMON_CONFIG_INCLUDE_UCLI + { __mlnx_common_config_STRINGIFY_NAME(MLNX_COMMON_CONFIG_INCLUDE_UCLI), __mlnx_common_config_STRINGIFY_VALUE(MLNX_COMMON_CONFIG_INCLUDE_UCLI) }, +#else +{ MLNX_COMMON_CONFIG_INCLUDE_UCLI(__mlnx_common_config_STRINGIFY_NAME), "__undefined__" }, +#endif + { NULL, NULL } +}; +#undef __mlnx_common_config_STRINGIFY_VALUE +#undef __mlnx_common_config_STRINGIFY_NAME + +const char* +mlnx_common_config_lookup(const char* setting) +{ + int i; + for(i = 0; mlnx_common_config_settings[i].name; i++) { + if(strcmp(mlnx_common_config_settings[i].name, setting)) { + return mlnx_common_config_settings[i].value; + } + } + return NULL; +} + +int +mlnx_common_config_show(struct aim_pvs_s* pvs) +{ + int i; + for(i = 0; mlnx_common_config_settings[i].name; i++) { + aim_printf(pvs, "%s = %s\n", mlnx_common_config_settings[i].name, mlnx_common_config_settings[i].value); + } + return i; +} + +/* */ diff --git a/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_enums.c b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_enums.c new file mode 100644 index 00000000..924d6e6e --- /dev/null +++ b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_enums.c @@ -0,0 +1,9 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +/* <--auto.start.enum(ALL).source> */ +/* */ diff --git a/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_fani.c b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_fani.c new file mode 100644 index 00000000..caa088ca --- /dev/null +++ b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_fani.c @@ -0,0 +1,411 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * + * 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 +#include +#include +#include +#include "mlnx_common/mlnx_common.h" +#include "mlnx_common_log.h" + +#define PREFIX_PATH "/bsp/fan/" +#define PREFIX_MODULE_PATH "/bsp/module/" + +#define FAN_STATUS_OK 1 + +#define VALIDATE(_id) \ + do { \ + if(!ONLP_OID_IS_FAN(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ + } while(0) + + +int onlp_fani_get_min_rpm(int id); + +static int +_onlp_fani_read_fan_eeprom(int local_id, onlp_fan_info_t* info) +{ + const char sanity_checker[] = "MLNX"; + const uint8_t sanity_offset = 8; + const uint8_t sanity_len = 4; + const uint8_t block1_start = 12; + const uint8_t block1_type = 1; + const uint8_t block2_start = 14; + const uint8_t block2_type = 5; + const uint8_t serial_offset = 8; + const uint8_t serial_len = 24; + const uint8_t part_len = 20; + const uint8_t fan_offset = 14; + const uint8_t multiplier = 16; + uint8_t data[256] = {0}; + uint8_t offset = 0; + uint8_t temp = 0; + int rv = 0; + int len = 0; + + /* We have 4 FRU with 2 fans(total 8 fans). + Eeprom is per FRU but not per fan. + So, need to convert fan ID to FRU ID.*/ + if (local_id % 2) { + local_id = local_id / 2 + 1; + } else { + local_id /= 2; + } + + rv = onlp_file_read(data, sizeof(data), &len, + IDPROM_PATH, "fan", local_id); + if (rv < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + /* Sanity checker */ + if (strncmp(sanity_checker, (char*)&data[sanity_offset], sanity_len)) { + return ONLP_STATUS_E_INVALID; + } + + /* Checking eeprom block type with S/N and P/N */ + if (data[block1_start + 1] != block1_type) { + return ONLP_STATUS_E_INVALID; + } + + /* Reading serial number */ + offset = data[block1_start] * multiplier + serial_offset; + strncpy(info->serial, (char *)&data[offset], serial_len); + + /* Reading part number */ + offset += serial_len; + strncpy(info->model, (char *)&data[offset], part_len); + + /* Reading fan direction */ + if (data[block2_start + 1] != block2_type) { + return ONLP_STATUS_E_INVALID; + } + offset = data[block2_start] * multiplier + fan_offset; + temp = data[offset]; + switch (temp) { + case 1: + info->caps |= ONLP_FAN_CAPS_F2B; + break; + case 2: + info->caps |= ONLP_FAN_CAPS_B2F; + break; + default: + break; + } + + return ONLP_STATUS_OK; +} + +static int +_onlp_fani_info_get_fan(int local_id, onlp_fan_info_t* info) +{ + int r_val, ret; + float range = 0; + float temp = 0; + float fru_index = 0; + const char fan_model[]=FAN_MODEL; + mlnx_platform_info_t* mlnx_platform_info = get_platform_info(); + if(mlnx_platform_info->fan_type == FAN_TYPE_NO_EEPROM) + strncpy(info->model, fan_model, sizeof(info->model)); + + if(!mlnx_platform_info->fan_fixed) { + /* We have 4 FRU with 2 fans(total 8 fans). + Eeprom is per FRU but not per fan. + So, need to convert fan ID to FRU ID.*/ + if (local_id % 2) { + fru_index = local_id / 2 + 1; + } else { + fru_index = local_id / 2; + } + /* get fan status + */ + if(mlnx_platform_info->fan_type == FAN_TYPE_EEPROM) { + ret = onlp_file_read_int(&r_val, "%s%s", PREFIX_MODULE_PATH, mlnx_platform_info->fan_fnames[(int)fru_index].status); + if (ret < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + if (r_val != FAN_STATUS_OK) { + info->status &= ~ONLP_FAN_STATUS_PRESENT; + return ONLP_STATUS_OK; + } + } + else { + ret = onlp_file_read_int(&r_val, "%s%s", PREFIX_MODULE_PATH, mlnx_platform_info->fan_fnames[local_id].status); + if (ret < 0) { + return ONLP_STATUS_E_INTERNAL; + } + if (r_val != FAN_STATUS_OK) { + return ONLP_STATUS_OK; + } + } + } + /* Fixed system FAN is always present */ + info->status |= ONLP_FAN_STATUS_PRESENT; + + /* get fan speed */ + ret = onlp_file_read_int(&r_val, "%s%s", PREFIX_PATH, mlnx_platform_info->fan_fnames[local_id].r_speed_get); + if (ret < 0) { + return ONLP_STATUS_E_INTERNAL; + } + info->rpm = r_val; + + /* check failure */ + if (info->rpm <= 0) { + info->status |= ONLP_FAN_STATUS_FAILED; + return ONLP_STATUS_OK; + } + + if (ONLP_FAN_CAPS_GET_PERCENTAGE & info->caps) { + /* get fan min speed */ + ret = onlp_file_read_int(&r_val, "%s%s", PREFIX_PATH, mlnx_platform_info->fan_fnames[local_id].min); + if (ret < 0) { + return ONLP_STATUS_E_INTERNAL; + } + mlnx_platform_info->min_fan_speed[local_id] = r_val; + + /* get fan max speed */ + ret = onlp_file_read_int(&r_val, "%s%s", PREFIX_PATH, mlnx_platform_info->fan_fnames[local_id].max); + if (ret < 0) { + return ONLP_STATUS_E_INTERNAL; + } + mlnx_platform_info->max_fan_speed[local_id] = r_val; + + /* get speed percentage from rpm */ + range = mlnx_platform_info->max_fan_speed[local_id] - mlnx_platform_info->min_fan_speed[local_id]; + if (range > 0) { + temp = ((float)info->rpm - (float)mlnx_platform_info->min_fan_speed[local_id]) / range * 40.0 + 60.0; + if (temp < PERCENTAGE_MIN) { + temp = PERCENTAGE_MIN; + } + info->percentage = (int)temp; + } else { + return ONLP_STATUS_E_INTERNAL; + } + } + if(mlnx_platform_info->fan_type == FAN_TYPE_NO_EEPROM) + return ONLP_STATUS_OK; + else + return _onlp_fani_read_fan_eeprom(local_id, info); + +} + + +static int +_onlp_fani_info_get_fan_on_psu(int local_id, int psu_id, onlp_fan_info_t* info) +{ + int r_val, ret; + float rpms_per_perc = 0.0; + float temp = 0.0; + mlnx_platform_info_t* mlnx_platform_info = get_platform_info(); + /* get fan status + */ + ret = onlp_file_read_int(&r_val, "%s%s", PREFIX_MODULE_PATH, mlnx_platform_info->fan_fnames[local_id].status); + if (ret < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + if (r_val != FAN_STATUS_OK) { + if(mlnx_platform_info->fan_type == FAN_TYPE_EEPROM) + info->status &= ~ONLP_FAN_STATUS_PRESENT; + return ONLP_STATUS_OK; + } + info->status |= ONLP_FAN_STATUS_PRESENT; + + /* get fan speed + */ + ret = onlp_file_read_int(&r_val, "%s%s", PREFIX_PATH, mlnx_platform_info->fan_fnames[local_id].r_speed_get); + if (ret < 0) { + return ONLP_STATUS_E_INTERNAL; + } + info->rpm = r_val; + + /* check failure */ + if (info->rpm <= 0) { + info->status |= ONLP_FAN_STATUS_FAILED; + return ONLP_STATUS_OK; + } + + /* get speed percentage from rpm */ + rpms_per_perc = PSU_FAN_RPM_MIN / PERCENTAGE_MIN; + temp = (float)info->rpm / rpms_per_perc; + if (temp < PERCENTAGE_MIN) { + temp = PERCENTAGE_MIN; + } + info->percentage = (int)temp; + + if (0 != psu_read_eeprom((local_id-mlnx_platform_info->first_psu_fan_id)+1, NULL, info)) + return ONLP_STATUS_E_INTERNAL; + + return ONLP_STATUS_OK; +} + + +int +onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* info) +{ + int rc = 0; + int local_id = 0; + VALIDATE(id); + mlnx_platform_info_t* mlnx_platform_info = get_platform_info(); + local_id = ONLP_OID_ID_GET(id); + + *info = mlnx_platform_info->finfo[local_id]; + + if(local_idfirst_psu_fan_id) + rc =_onlp_fani_info_get_fan(local_id, info); + else + rc = _onlp_fani_info_get_fan_on_psu(local_id, (local_id-mlnx_platform_info->first_psu_fan_id)+1, info); + 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) +{ + float temp = 0.0; + int rv = 0, local_id = 0, nbytes = 10; + char r_data[10] = {0}; + onlp_fan_info_t* info = NULL; + + mlnx_platform_info_t* mlnx_platform_info = get_platform_info(); + VALIDATE(id); + + local_id = ONLP_OID_ID_GET(id); + info = &mlnx_platform_info->finfo[local_id]; + + if (0 == (ONLP_FAN_CAPS_SET_RPM & info->caps)) { + return ONLP_STATUS_E_UNSUPPORTED; + } + + /* reject rpm=0% (rpm=0%, stop fan) */ + if (0 == rpm) { + return ONLP_STATUS_E_INVALID; + } + + /* Set fan speed + Converting percent to driver value. + Driver accept value in range between 153 and 255. + Value 153 is minimum rpm. + Value 255 is maximum rpm. + */ + if (local_id > sizeof(mlnx_platform_info->min_fan_speed)/sizeof(mlnx_platform_info->min_fan_speed[0])) { + return ONLP_STATUS_E_INTERNAL; + } + if (mlnx_platform_info->max_fan_speed[local_id] - mlnx_platform_info->min_fan_speed[local_id] < 0) { + return ONLP_STATUS_E_INTERNAL; + } + if (rpm < mlnx_platform_info->min_fan_speed[local_id] || rpm > mlnx_platform_info->max_fan_speed[local_id]) { + return ONLP_STATUS_E_PARAM; + } + + temp = (rpm - mlnx_platform_info->min_fan_speed[local_id]) * (RPM_MAGIC_MAX - RPM_MAGIC_MIN) / + (mlnx_platform_info->max_fan_speed[local_id] - mlnx_platform_info->min_fan_speed[local_id]) + RPM_MAGIC_MIN; + + snprintf(r_data, sizeof(r_data), "%d", (int)temp); + nbytes = strnlen(r_data, sizeof(r_data)); + rv = onlp_file_write((uint8_t*)r_data, nbytes, "%s%s", PREFIX_PATH, + mlnx_platform_info->fan_fnames[local_id].r_speed_set); + if (rv < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +/* + * 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) +{ + float temp = 0.0; + int rv = 0, local_id = 0, nbytes = 10; + char r_data[10] = {0}; + onlp_fan_info_t* info = NULL; + mlnx_platform_info_t* mlnx_platform_info = get_platform_info(); + VALIDATE(id); + local_id = ONLP_OID_ID_GET(id); + info = &mlnx_platform_info->finfo[local_id]; + + if (0 == (ONLP_FAN_CAPS_SET_PERCENTAGE & info->caps)) { + return ONLP_STATUS_E_UNSUPPORTED; + } + + /* reject p=0% (p=0%, stop fan) */ + if (0 == p) { + return ONLP_STATUS_E_INVALID; + } + + if (p < PERCENTAGE_MIN || p > PERCENTAGE_MAX) { + return ONLP_STATUS_E_PARAM; + } + + /* Set fan speed + Converting percent to driver value. + Driver accept value in range between 153 and 255. + Value 153 is 60%. + Value 255 is 100%. + */ + temp = (p - PERCENTAGE_MIN) * (RPM_MAGIC_MAX - RPM_MAGIC_MIN) / + (PERCENTAGE_MAX - PERCENTAGE_MIN) + RPM_MAGIC_MIN; + + snprintf(r_data, sizeof(r_data), "%d", (int)temp); + nbytes = strnlen(r_data, sizeof(r_data)); + rv = onlp_file_write((uint8_t*)r_data, nbytes, "%s%s", PREFIX_PATH, + mlnx_platform_info->fan_fnames[local_id].r_speed_set); + if (rv < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +int +onlp_fani_get_min_rpm(int id) +{ + int r_val; + + mlnx_platform_info_t* mlnx_platform_info = get_platform_info(); + + if (onlp_file_read_int(&r_val, "%s%s", PREFIX_PATH, mlnx_platform_info->fan_fnames[id].min) < 0) + return ONLP_STATUS_E_INTERNAL; + + return r_val; +} diff --git a/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_int.h b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_int.h new file mode 100644 index 00000000..d75227d9 --- /dev/null +++ b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_int.h @@ -0,0 +1,17 @@ +/**************************************************************************//** + * + * mlnx_common Internal Header + * + *****************************************************************************/ +#ifndef __MLNX_COMMON_INT_H__ +#define __MLNX_COMMON_INT_H__ + +#include +#include + +#define MAX_NUM_OF_CPLD 3 +#define PREFIX_PATH_ON_CPLD_DEV "/bsp/cpld" + +mlnx_platform_info_t* get_platform_info(void); + +#endif /* __MLNX_COMMON_INT_H__ */ diff --git a/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_ledi.c b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_ledi.c new file mode 100644 index 00000000..8669cf52 --- /dev/null +++ b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_ledi.c @@ -0,0 +1,346 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * + * 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 +#include + +#define prefix_path "/bsp/led/led_" +#define driver_value_len 50 + +#define LED_MODE_OFF "none" +#define LED_MODE_GREEN "green" +#define LED_MODE_RED "red" +#define LED_MODE_BLUE "blue" +#define LED_MODE_GREEN_BLINK "green_blink" +#define LED_MODE_RED_BLINK "red_blink" +#define LED_MODE_BLUE_BLINK "blue_blink" +#define LED_MODE_AUTO "cpld_control" + +#define LED_BLINK_PERIOD "100" +#define LED_ON "1" +#define LED_OFF "0" +#define LED_BLINK_PERIOD_LEN 3 +#define LED_MODE_LEN 1 + +#define VALIDATE(_id) \ + do { \ + if(!ONLP_OID_IS_LED(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ + } while(0) + +/* LED related data + */ + +typedef struct led_light_mode_map { + int id; + char* driver_led_mode; + enum onlp_led_mode_e onlp_led_mode; +} led_light_mode_map_t; + +led_light_mode_map_t led_map[] = { + {LED_SYSTEM, LED_MODE_OFF, ONLP_LED_MODE_OFF}, + {LED_SYSTEM, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, + {LED_SYSTEM, LED_MODE_RED, ONLP_LED_MODE_RED}, + {LED_SYSTEM, LED_MODE_RED_BLINK, ONLP_LED_MODE_RED_BLINKING}, + {LED_SYSTEM, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, + {LED_SYSTEM, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, + + {LED_FAN1, LED_MODE_OFF, ONLP_LED_MODE_OFF}, + {LED_FAN1, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, + {LED_FAN1, LED_MODE_RED, ONLP_LED_MODE_RED}, + {LED_FAN1, LED_MODE_RED_BLINK, ONLP_LED_MODE_RED_BLINKING}, + {LED_FAN1, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, + {LED_FAN1, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, + + {LED_FAN2, LED_MODE_OFF, ONLP_LED_MODE_OFF}, + {LED_FAN2, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, + {LED_FAN2, LED_MODE_RED, ONLP_LED_MODE_RED}, + {LED_FAN2, LED_MODE_RED_BLINK, ONLP_LED_MODE_RED_BLINKING}, + {LED_FAN2, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, + {LED_FAN2, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, + + {LED_FAN3, LED_MODE_OFF, ONLP_LED_MODE_OFF}, + {LED_FAN3, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, + {LED_FAN3, LED_MODE_RED, ONLP_LED_MODE_RED}, + {LED_FAN3, LED_MODE_RED_BLINK, ONLP_LED_MODE_RED_BLINKING}, + {LED_FAN3, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, + {LED_FAN3, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, + + {LED_FAN4, LED_MODE_OFF, ONLP_LED_MODE_OFF}, + {LED_FAN4, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, + {LED_FAN4, LED_MODE_RED, ONLP_LED_MODE_RED}, + {LED_FAN4, LED_MODE_RED_BLINK, ONLP_LED_MODE_RED_BLINKING}, + {LED_FAN4, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, + {LED_FAN4, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, + + {LED_PSU, LED_MODE_OFF, ONLP_LED_MODE_OFF}, + {LED_PSU, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, + {LED_PSU, LED_MODE_RED, ONLP_LED_MODE_RED}, + {LED_PSU, LED_MODE_RED_BLINK, ONLP_LED_MODE_RED_BLINKING}, + {LED_PSU, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, + {LED_PSU, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, + + {LED_FAN, LED_MODE_OFF, ONLP_LED_MODE_OFF}, + {LED_FAN, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, + {LED_FAN, LED_MODE_RED, ONLP_LED_MODE_RED}, + {LED_FAN, LED_MODE_RED_BLINK, ONLP_LED_MODE_RED_BLINKING}, + {LED_FAN, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, + {LED_FAN, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, + + {LED_PSU1, LED_MODE_OFF, ONLP_LED_MODE_OFF}, + {LED_PSU1, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, + {LED_PSU1, LED_MODE_RED, ONLP_LED_MODE_RED}, + {LED_PSU1, LED_MODE_RED_BLINK, ONLP_LED_MODE_RED_BLINKING}, + {LED_PSU1, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, + {LED_PSU1, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, + + {LED_PSU2, LED_MODE_OFF, ONLP_LED_MODE_OFF}, + {LED_PSU2, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, + {LED_PSU2, LED_MODE_RED, ONLP_LED_MODE_RED}, + {LED_PSU2, LED_MODE_RED_BLINK, ONLP_LED_MODE_RED_BLINKING}, + {LED_PSU2, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, + {LED_PSU2, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, + + {LED_UID, LED_MODE_OFF, ONLP_LED_MODE_OFF}, + {LED_UID, LED_MODE_BLUE, ONLP_LED_MODE_BLUE}, + {LED_UID, LED_MODE_BLUE_BLINK, ONLP_LED_MODE_BLUE_BLINKING}, + {LED_UID, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, +}; + +typedef struct led_colors { + int id; + const char* color1; + const char* color2; +} led_colors_t; + +static led_colors_t led_colors_map[] = { + {LED_SYSTEM, "green", "red"}, + {LED_FAN1, "green", "red"}, + {LED_FAN2, "green", "red"}, + {LED_FAN3, "green", "red"}, + {LED_FAN4, "green", "red"}, + {LED_PSU, "green", "red"}, + {LED_FAN, "green", "red"}, + {LED_PSU1, "green", "red"}, + {LED_PSU2, "green", "red"}, + {LED_UID, "blue", NULL}, +}; + +static int driver_to_onlp_led_mode(int id, char* driver_led_mode) +{ + char *pos; + int i, nsize = sizeof(led_map)/sizeof(led_map[0]); + + if ((pos=strchr(driver_led_mode, '\n')) != NULL) + *pos = '\0'; + for (i = 0; i < nsize; i++) + { + if (id == led_map[i].id && + !strncmp(led_map[i].driver_led_mode, driver_led_mode, driver_value_len)) + { + return led_map[i].onlp_led_mode; + } + } + + return ONLP_STATUS_OK; +} + +static char* onlp_to_driver_led_mode(int id, onlp_led_mode_t onlp_led_mode) +{ + int i, nsize = sizeof(led_map)/sizeof(led_map[0]); + + for (i = 0; i < nsize; i++) + { + if (id == led_map[i].id && onlp_led_mode == led_map[i].onlp_led_mode) + { + return led_map[i].driver_led_mode; + } + } + + return LED_MODE_OFF; +} + +static int led_set_mode(onlp_oid_t id, onlp_led_mode_t mode) +{ + int local_id = ONLP_OID_ID_GET(id); + char color[10]= {0}; + int blinking = 0; + + switch (mode) { + case ONLP_LED_MODE_RED_BLINKING: + strcpy(color, "red"); + blinking = 1; + break; + case ONLP_LED_MODE_GREEN_BLINKING: + strcpy(color, "green"); + blinking = 1; + break; + case ONLP_LED_MODE_BLUE_BLINKING: + strcpy(color, "blue"); + blinking = 1; + break; + case ONLP_LED_MODE_YELLOW_BLINKING: + strcpy(color, "yellow"); + blinking = 1; + break; + case ONLP_LED_MODE_RED: + strcpy(color, "red"); + break; + case ONLP_LED_MODE_GREEN: + strcpy(color, "green"); + break; + case ONLP_LED_MODE_BLUE: + strcpy(color, "blue"); + break; + case ONLP_LED_MODE_YELLOW: + strcpy(color, "yellow"); + break; + default: + return ONLP_STATUS_E_PARAM; + } + mlnx_platform_info_t* mlnx_platform_info = get_platform_info(); + if (blinking) { + onlp_file_write((uint8_t*)LED_BLINK_PERIOD, LED_BLINK_PERIOD_LEN, + "%s%s_%s_delay_off", prefix_path, mlnx_platform_info->led_fnames[local_id], color); + onlp_file_write((uint8_t*)LED_BLINK_PERIOD, LED_BLINK_PERIOD_LEN, + "%s%s_%s_delay_on", prefix_path, mlnx_platform_info->led_fnames[local_id], color); + } + onlp_file_write((uint8_t*)LED_ON, LED_MODE_LEN, + "%s%s_%s", prefix_path, mlnx_platform_info->led_fnames[local_id], color); + + return ONLP_STATUS_OK; +} + +int +onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) +{ + int len, local_id = 0; + uint8_t data[driver_value_len] = {0}; + + VALIDATE(id); + + local_id = ONLP_OID_ID_GET(id); + + mlnx_platform_info_t* mlnx_platform_info = get_platform_info(); + /* Set the onlp_oid_hdr_t and capabilities */ + *info = mlnx_platform_info->linfo[ONLP_OID_ID_GET(id)]; + + /* Get LED mode */ + if (mc_get_kernel_ver() >= KERNEL_VERSION(4,9,30)) { + char* cmd = aim_fstrdup("%s%s_state", prefix_path, mlnx_platform_info->led_fnames[local_id]); + if(system(cmd) != 0) { + aim_free(cmd); + return ONLP_STATUS_E_INTERNAL; + } + aim_free(cmd); + } + + if (onlp_file_read(data, sizeof(data), &len, "%s%s", + prefix_path, mlnx_platform_info->led_fnames[local_id]) != 0) { + return ONLP_STATUS_E_INTERNAL; + } + + info->mode = driver_to_onlp_led_mode(local_id, (char*)data); + + /* Set the on/off status */ + if (info->mode != ONLP_LED_MODE_OFF) { + info->status |= ONLP_LED_STATUS_ON; + } + + return ONLP_STATUS_OK; +} + +/* + * Turn an LED on or off. + * + * This function will only be called if the LED OID supports the ONOFF + * capability. + * + * What 'on' means in terms of colors or modes for multimode LEDs is + * up to the platform to decide. This is intended as baseline toggle mechanism. + */ +int +onlp_ledi_set(onlp_oid_t id, int on_or_off) +{ + VALIDATE(id); + + mlnx_platform_info_t* mlnx_platform_info = get_platform_info(); + if (!on_or_off) { + if (mc_get_kernel_ver() < KERNEL_VERSION(4,9,30)) + return onlp_ledi_mode_set(id, ONLP_LED_MODE_OFF); + else { + int i, nsize = sizeof(led_colors_map)/sizeof(led_colors_map[0]); + for (i = 0; i < nsize; i++) + { + if (id == led_colors_map[i].id) + break; + } + if (led_colors_map[i].color1) + onlp_file_write((uint8_t*)LED_OFF, LED_MODE_LEN, + "%s%s_%s", prefix_path, mlnx_platform_info->led_fnames[id], led_colors_map[i].color1); + } + } + + return ONLP_STATUS_E_UNSUPPORTED; +} + +/* + * This function puts the LED into the given mode. It is a more functional + * interface for multimode LEDs. + * + * Only modes reported in the LED's capabilities will be attempted. + */ +int +onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) +{ + int local_id; + char* driver_led_mode; + int nbytes; + + VALIDATE(id); + + mlnx_platform_info_t* mlnx_platform_info = get_platform_info(); + if (mc_get_kernel_ver() < KERNEL_VERSION(4,9,30)) { + local_id = ONLP_OID_ID_GET(id); + driver_led_mode = onlp_to_driver_led_mode(local_id, mode); + nbytes = strnlen(driver_led_mode, driver_value_len); + if (onlp_file_write((uint8_t*)driver_led_mode, nbytes, + "%s%s", prefix_path, mlnx_platform_info->led_fnames[local_id]) != 0) { + return ONLP_STATUS_E_INTERNAL; + } + } else { + if (led_set_mode(id, mode) != 0) { + return ONLP_STATUS_E_INTERNAL; + } + } + + return ONLP_STATUS_OK; +} diff --git a/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_log.c b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_log.c new file mode 100644 index 00000000..4bb47490 --- /dev/null +++ b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_log.c @@ -0,0 +1,17 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +#include "mlnx_common_log.h" +/* + * mlnx_common log struct. + */ +AIM_LOG_STRUCT_DEFINE( + MLNX_COMMON_CONFIG_LOG_OPTIONS_DEFAULT, + MLNX_COMMON_CONFIG_LOG_BITS_DEFAULT, + NULL, /* Custom log map */ + MLNX_COMMON_CONFIG_LOG_CUSTOM_BITS_DEFAULT + ); diff --git a/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_log.h b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_log.h new file mode 100644 index 00000000..7034e9af --- /dev/null +++ b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_log.h @@ -0,0 +1,12 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#ifndef __MLNX_COMMON_LOG_H__ +#define __MLNX_COMMON_LOG_H__ + +#define AIM_LOG_MODULE_NAME mlnx_common +#include + +#endif /* __MLNX_COMMON_LOG_H__ */ diff --git a/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_module.c b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_module.c new file mode 100644 index 00000000..e2454d05 --- /dev/null +++ b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_module.c @@ -0,0 +1,22 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +#include "mlnx_common_log.h" + +static int +datatypes_init__(void) +{ +#define MLNX_COMMON_ENUMERATION_ENTRY(_enum_name, _desc) AIM_DATATYPE_MAP_REGISTER(_enum_name, _enum_name##_map, _desc, AIM_LOG_INTERNAL); +#include + return 0; +} + +void __mlnx_common_module_init__(void) +{ + AIM_LOG_STRUCT_REGISTER(); + datatypes_init__(); +} diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/psui.c b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_psui.c similarity index 59% rename from packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/psui.c rename to packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_psui.c index f5555b60..e9c557ec 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/psui.c +++ b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_psui.c @@ -19,7 +19,7 @@ * ************************************************************ * - * + * PSU Platform Implementation Defaults. * ***********************************************************/ #include @@ -27,7 +27,8 @@ #include #include #include -#include "platform_lib.h" +#include +#include "mlnx_common_log.h" #define PSU_STATUS_PRESENT 1 #define PSU_CABLE_PRESENT 1 @@ -35,6 +36,8 @@ #define PSU_NODE_MAX_INT_LEN 8 #define PSU_NODE_MAX_PATH_LEN 64 +#define PSU_MODEL "POW000167" + #define VALIDATE(_id) \ do { \ if(!ONLP_OID_IS_PSU(_id)) { \ @@ -42,35 +45,31 @@ } \ } while(0) -static int +int psu_module_info_get(int id, char *node, int *value) { - int len, ret = 0; - char buf[PSU_NODE_MAX_INT_LEN + 1] = {0}; + int ret = 0; *value = 0; - ret = onlp_file_read((uint8_t*)buf, sizeof(buf), &len, - PSU_MODULE_PREFIX, id, node); - if (ret == 0) { - *value = atoi(buf); + ret = onlp_file_read_int(value, PSU_MODULE_PREFIX, id, node); + if (ret < 0) { + return ONLP_STATUS_E_INTERNAL; } return ret; } -static int +int psu_power_info_get(int id, char *node, int *value) { - int len, ret = 0; - char buf[PSU_NODE_MAX_INT_LEN + 1] = {0}; + int ret = 0; *value = 0; - ret = onlp_file_read((uint8_t*)buf, sizeof(buf), &len, - PSU_POWER_PREFIX, id, node); - if (ret == 0) { - *value = atoi(buf); + ret = onlp_file_read_int(value, PSU_POWER_PREFIX, id, node); + if (ret < 0) { + return ONLP_STATUS_E_INTERNAL; } return ret; @@ -82,12 +81,63 @@ onlp_psui_init(void) return ONLP_STATUS_OK; } +/* + * Get all information about the given PSU oid. + */ +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 }, + } +}; + static int -_psu_info_get(onlp_psu_info_t* info) +_psu_info_get_type1(onlp_psu_info_t* info) +{ + int val = 0; + int index = ONLP_OID_ID_GET(info->hdr.id); + const char psu_model[]=PSU_MODEL; + + strncpy(info->model, psu_model, sizeof(info->model)); + + /* Set capability */ + info->caps = ONLP_PSU_CAPS_AC; + + if (info->status & ONLP_PSU_STATUS_FAILED) { + return ONLP_STATUS_OK; + } + + /* Read voltage, current and power */ + if (psu_power_info_get(index, "volt", &val) == 0) { + info->mvout = val; + info->caps |= ONLP_PSU_CAPS_VOUT; + } + + if (psu_power_info_get(index, "curr", &val) == 0) { + info->miout = val; + info->caps |= ONLP_PSU_CAPS_IOUT; + } + + info->mpout = info->mvout * info->miout; + info->caps |= ONLP_PSU_CAPS_POUT; + + info->mpin = ((int)(info->mpout / 91)) * 100; + info->caps |= ONLP_PSU_CAPS_PIN; + + return ONLP_STATUS_OK; +} + +static int +_psu_info_get_type2(onlp_psu_info_t* info) { int val = 0; int index = ONLP_OID_ID_GET(info->hdr.id); + mlnx_platform_info_t* mlnx_platform_info = get_platform_info(); /* Set capability */ info->caps = ONLP_PSU_CAPS_AC; @@ -97,12 +147,12 @@ _psu_info_get(onlp_psu_info_t* info) } /* Set the associated oid_table */ - info->hdr.coids[0] = ONLP_FAN_ID_CREATE(index + CHASSIS_FAN_COUNT); - info->hdr.coids[1] = ONLP_THERMAL_ID_CREATE(index + CHASSIS_THERMAL_COUNT); + info->hdr.coids[0] = ONLP_FAN_ID_CREATE(index + mlnx_platform_info->fan_num); + info->hdr.coids[1] = ONLP_THERMAL_ID_CREATE(index + mlnx_platform_info->thermal_num); /* Read voltage, current and power */ if (psu_power_info_get(index, "volt_in", &val) == 0 && - 0 != val) { + 0 != val) { info->mvin = val; info->caps |= ONLP_PSU_CAPS_VIN; @@ -138,19 +188,20 @@ _psu_info_get(onlp_psu_info_t* info) return psu_read_eeprom(index, info, NULL); } -/* - * Get all information about the given PSU oid. - */ -static onlp_psu_info_t pinfo[] = +int _psu_info_get(onlp_psu_info_t* info) { - { }, /* Not used */ - { - { ONLP_PSU_ID_CREATE(PSU1_ID), "PSU-1", 0 }, - }, - { - { ONLP_PSU_ID_CREATE(PSU2_ID), "PSU-2", 0 }, + int res; + mlnx_platform_info_t* mlnx_platform_info = get_platform_info(); + switch(mlnx_platform_info->psu_type) { + case PSU_TYPE_1: + res=_psu_info_get_type1(info); + break; + case PSU_TYPE_2: + res=_psu_info_get_type2(info); + break; } -}; + return res; +} int onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) @@ -164,37 +215,39 @@ onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) memset(info, 0, sizeof(onlp_psu_info_t)); *info = pinfo[index]; /* Set the onlp_oid_hdr_t */ - /* Get the present state */ - if (psu_module_info_get(index, "status", &val) != 0) { - AIM_LOG_ERROR("Unable to read PSU(%d) node(psu_present)\r\n", index); - } + mlnx_platform_info_t* mlnx_platform_info = get_platform_info(); + if(mlnx_platform_info->psu_fixed == false) { + /* Get the present state */ + if (psu_module_info_get(index, "status", &val) != 0) { + AIM_LOG_ERROR("Unable to read PSU(%d) node(psu_present)\r\n", index); + } - if (val != PSU_STATUS_PRESENT) { - info->status &= ~ONLP_PSU_STATUS_PRESENT; - info->status |= ONLP_PSU_STATUS_UNPLUGGED; - return ONLP_STATUS_OK; - } - else - info->status |= ONLP_PSU_STATUS_PRESENT; + if (val != PSU_STATUS_PRESENT) { + info->status &= ~ONLP_PSU_STATUS_PRESENT; + info->status |= ONLP_PSU_STATUS_UNPLUGGED; + return ONLP_STATUS_OK; + } + else + info->status |= ONLP_PSU_STATUS_PRESENT; + } + else { + /* Fixed system, PSU is always present */ + info->status |= ONLP_PSU_STATUS_PRESENT; + } /* Get the cable preset state */ if (psu_module_info_get(index, "pwr_status", &val) != 0) { - AIM_LOG_ERROR("Unable to read PSU(%d) node(cable_present)\r\n", index); + AIM_LOG_ERROR("Unable to read PSU(%d) node(cable_present)\r\n", index); } if (val != PSU_CABLE_PRESENT) { info->status |= ONLP_PSU_STATUS_UNPLUGGED; return ONLP_STATUS_OK; } - + if(mlnx_platform_info->psu_fixed == false) { + info->status |= ONLP_PSU_STATUS_PRESENT; + } ret = _psu_info_get(info); return ret; } - -int -onlp_psui_ioctl(onlp_oid_t pid, va_list vargs) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/sfpi.c b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_sfpi.c similarity index 75% rename from packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/sfpi.c rename to packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_sfpi.c index 95050cc0..1a11a2f3 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/sfpi.c +++ b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_sfpi.c @@ -23,8 +23,7 @@ * ***********************************************************/ #include - -#include /* For O_RDWR && open */ +#include #include #include #include @@ -32,17 +31,17 @@ #include #include #include -#include "platform_lib.h" +#include "mlnx_common_log.h" +#include "mlnx_common_int.h" #define MAX_SFP_PATH 64 #define SFP_SYSFS_VALUE_LEN 20 static char sfp_node_path[MAX_SFP_PATH] = {0}; -#define NUM_OF_SFP_PORT 16 -#define SFP_PRESENT_STATUS "good" -#define SFP_NOT_PRESENT_STATUS "not_connected" + +int get_sfp_port_num(void); static int -msn2100_sfp_node_read_int(char *node_path, int *value) +mc_sfp_node_read_int(char *node_path, int *value) { int data_len = 0, ret = 0; char buf[SFP_SYSFS_VALUE_LEN] = {0}; @@ -50,7 +49,7 @@ msn2100_sfp_node_read_int(char *node_path, int *value) char sfp_present_status[16]; char sfp_not_present_status[16]; - if (onlp_get_kernel_ver() >= KERNEL_VERSION(4,9,30)) { + if (mc_get_kernel_ver() >= KERNEL_VERSION(4,9,30)) { strcpy(sfp_present_status, "1"); strcpy(sfp_not_present_status, "0"); } else { @@ -72,17 +71,17 @@ msn2100_sfp_node_read_int(char *node_path, int *value) } static char* -msn2100_sfp_get_port_path(int port, char *node_name) +mc_sfp_get_port_path(int port, char *node_name) { if (node_name) - sprintf(sfp_node_path, "/bsp/qsfp/qsfp%d%s", port, node_name); + sprintf(sfp_node_path, "/bsp/qsfp/qsfp%d%s", port, node_name); else sprintf(sfp_node_path, "/bsp/qsfp/qsfp%d", port); return sfp_node_path; } static char* -msn2100_sfp_convert_i2c_path(int port, int devaddr) +mc_sfp_convert_i2c_path(int port, int devaddr) { sprintf(sfp_node_path, "/bsp/qsfp/qsfp%d", port); return sfp_node_path; @@ -104,9 +103,11 @@ int onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap) { int p = 1; + mlnx_platform_info_t* platform_info = get_platform_info(); + AIM_BITMAP_CLR_ALL(bmap); - for (; p <= NUM_OF_SFP_PORT; p++) { + for (; p <= platform_info->sfp_num; p++) { AIM_BITMAP_SET(bmap, p); } @@ -122,9 +123,9 @@ onlp_sfpi_is_present(int port) * Return < 0 if error. */ int present = -1; - char* path = msn2100_sfp_get_port_path(port, "_status"); + char* path = mc_sfp_get_port_path(port, "_status"); - if (msn2100_sfp_node_read_int(path, &present) != 0) { + if (mc_sfp_node_read_int(path, &present) != 0) { AIM_LOG_ERROR("Unable to read present status from port(%d)\r\n", port); return ONLP_STATUS_E_INTERNAL; } @@ -137,8 +138,9 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) { int ii = 1; int rc = 0; + mlnx_platform_info_t* platform_info = get_platform_info(); - for (;ii <= NUM_OF_SFP_PORT; ii++) { + for (;ii <= platform_info->sfp_num; ii++) { rc = onlp_sfpi_is_present(ii); AIM_BITMAP_MOD(dst, ii, (1 == rc) ? 1 : 0); } @@ -149,7 +151,7 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) int onlp_sfpi_eeprom_read(int port, uint8_t data[256]) { - char* path = msn2100_sfp_get_port_path(port, NULL); + char* path = mc_sfp_get_port_path(port, NULL); /* * Read the SFP eeprom into data[] @@ -170,7 +172,7 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) int onlp_sfpi_dev_readb(int port, uint8_t devaddr, uint8_t addr) { - char* path = msn2100_sfp_convert_i2c_path(port, devaddr); + char* path = mc_sfp_convert_i2c_path(port, devaddr); uint8_t data; int fd; int nrd; @@ -193,16 +195,10 @@ onlp_sfpi_dev_readb(int port, uint8_t devaddr, uint8_t addr) return data; } -int -onlp_sfpi_dev_writeb(int port, uint8_t devaddr, uint8_t addr, uint8_t value) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - int onlp_sfpi_dev_readw(int port, uint8_t devaddr, uint8_t addr) { - char* path = msn2100_sfp_convert_i2c_path(port, devaddr); + char* path = mc_sfp_convert_i2c_path(port, devaddr); uint16_t data; int fd; int nrd; @@ -227,33 +223,8 @@ onlp_sfpi_dev_readw(int port, uint8_t devaddr, uint8_t addr) return data; } -int -onlp_sfpi_dev_writew(int port, uint8_t devaddr, uint8_t addr, uint16_t value) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - -int -onlp_sfpi_control_supported(int port, onlp_sfp_control_t control, int* rv) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - -int -onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - -int -onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - int onlp_sfpi_denit(void) { return ONLP_STATUS_OK; } - diff --git a/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_sysi.c b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_sysi.c new file mode 100644 index 00000000..6fa3a415 --- /dev/null +++ b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_sysi.c @@ -0,0 +1,391 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * + * 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 +#include +#include +#include +#include "mlnx_common_log.h" +#include "mlnx_common_int.h" +#include "mlnx_common/mlnx_common.h" + +mlnx_platform_info_t mlnx_platform_info; + +static char arr_cplddev_name[MAX_NUM_OF_CPLD][30] = +{ + "cpld_brd_version", + "cpld_mgmt_version", + "cpld_port_version" +}; + +mlnx_platform_info_t* get_platform_info() +{ + return &mlnx_platform_info; +} + +const char* onlp_sysi_platform_get() +{ + if (mc_get_platform_info(&mlnx_platform_info) < 0) { + AIM_LOG_ERROR("Unable to get paltform info!\n"); + return NULL; + } + else + return mlnx_platform_info.onl_platform_name; +} + +int +onlp_sysi_platform_info_get(onlp_platform_info_t* pi) +{ + int i, v[MAX_NUM_OF_CPLD]={0}; + mlnx_platform_info_t* platform_info = get_platform_info(); + + for (i=0; i < platform_info->cpld_num; i++) { + v[i] = 0; + if(onlp_file_read_int(v+i, "%s/%s", PREFIX_PATH_ON_CPLD_DEV, arr_cplddev_name[i]) < 0) { + return ONLP_STATUS_E_INTERNAL; + } + } + switch (platform_info->cpld_num) { + case 1: + pi->cpld_versions = aim_fstrdup("unified=%d", v[0]); /* TBD Currently not exist */ + break; + case 2: + pi->cpld_versions = aim_fstrdup("brd=%d, mgmt=%d", v[0], v[1]); + break; + case 3: + pi->cpld_versions = aim_fstrdup("brd=%d, mgmt=%d, port=%d", v[0], v[1], v[2]); + break; + case 0: + default: + AIM_LOG_ERROR("Incorrect CPLD Number %d\n", platform_info->cpld_num); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +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) +{ + int i; + onlp_oid_t* e = table; + memset(table, 0, max*sizeof(onlp_oid_t)); + + for (i = 1; i <= mlnx_platform_info.thermal_num; i++) + { + *e++ = ONLP_THERMAL_ID_CREATE(i); + } + + for (i = 1; i <= mlnx_platform_info.led_num; i++) + { + *e++ = ONLP_LED_ID_CREATE(i); + } + + for (i = 1; i <= mlnx_platform_info.psu_num; i++) + { + *e++ = ONLP_PSU_ID_CREATE(i); + } + + for (i = 1; i <= mlnx_platform_info.fan_num; i++) + { + *e++ = ONLP_FAN_ID_CREATE(i); + } + + return ONLP_STATUS_OK; +} + +int +onlp_sysi_onie_info_get(onlp_onie_info_t* onie) +{ + int rv = onlp_onie_read_json(onie, + "/lib/platform-config/current/onl/etc/onie/eeprom.json"); + if(rv >= 0) { + if(onie->platform_name) { + aim_free(onie->platform_name); + } + onie->platform_name = aim_strdup(mlnx_platform_info.onl_platform_name); + } + + return rv; +} + +int +onlp_sysi_platform_manage_leds_type1(void) +{ + int fan_number, psu_number; + onlp_led_mode_t mode, system_mode; + int min_fan_speed; + int psu_led_id[2] = { LED_PSU1, LED_PSU2 }; + int fan_problem = 0; + int psu_problem = 0; + + /* + * FAN Indicators + * + * Green - Fan is operating + * Red - No power or Fan failure + * Off - No power + * + */ + mode = ONLP_LED_MODE_GREEN; + for( fan_number = 1; fan_number<= mlnx_platform_info.fan_num; fan_number+=2) + { + /* each 2 fans had same led_fan */ + onlp_fan_info_t fi; + /* check fans */ + if(onlp_fani_info_get(ONLP_FAN_ID_CREATE(fan_number), &fi) < 0) { + mode = ONLP_LED_MODE_RED; + fan_problem = 1; + } + else if( (fi.status & ONLP_FAN_STATUS_PRESENT) == 0) { + if(mlnx_platform_info.fan_fixed == false) { + /* Not present */ + mode = ONLP_LED_MODE_RED; + fan_problem = 1; + } + } + else if(fi.status & ONLP_FAN_STATUS_FAILED) { + mode = ONLP_LED_MODE_RED; + fan_problem = 1; + } + else + { + min_fan_speed = onlp_fani_get_min_rpm(fan_number); + if( fi.rpm < min_fan_speed) + { + mode = ONLP_LED_MODE_RED; + fan_problem = 1; + } + } + /* check fan i+1 */ + if(onlp_fani_info_get(ONLP_FAN_ID_CREATE(fan_number+1), &fi) < 0) { + mode = ONLP_LED_MODE_RED; + fan_problem = 1; + } + else if( (fi.status & 0x1) == 0) { + if(mlnx_platform_info.fan_fixed == false) { + /* Not present */ + mode = ONLP_LED_MODE_RED; + fan_problem = 1; + } + } + else if(fi.status & ONLP_FAN_STATUS_FAILED) { + mode = ONLP_LED_MODE_RED; + fan_problem = 1; + } + else + { + min_fan_speed = onlp_fani_get_min_rpm(fan_number+1); + if( fi.rpm < min_fan_speed) + { + mode = ONLP_LED_MODE_RED; + fan_problem = 1; + } + } + } + onlp_ledi_mode_set(ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_LED, LED_FAN), mode); + + for (psu_number = 1; psu_number <= mlnx_platform_info.psu_num; psu_number++) + { + onlp_psu_info_t pi; + mode = ONLP_LED_MODE_GREEN; + if(onlp_psui_info_get(ONLP_PSU_ID_CREATE(psu_number), &pi) < 0) { + mode = ONLP_LED_MODE_RED; + psu_problem = 1; + } + else { + if(mlnx_platform_info.psu_fixed) { + /* Fixed system, PSU always in. Check only cable plugged. */ + if(pi.status & ONLP_PSU_STATUS_UNPLUGGED) { + mode = ONLP_LED_MODE_RED; + psu_problem = 1; + } + } + else { + if((pi.status & ONLP_PSU_STATUS_PRESENT) == 0) { + /* Not present */ + psu_problem = 1; + } + else if(pi.status & ONLP_PSU_STATUS_UNPLUGGED) { + psu_problem = 1; + } + } + } + onlp_ledi_mode_set(ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_LED, psu_led_id[(psu_number-1)]), mode); + } + + /* Set System status LED green if no problem in FANs or PSUs */ + if (fan_problem || psu_problem) + system_mode = ONLP_LED_MODE_RED; + else + system_mode = ONLP_LED_MODE_GREEN; + + onlp_ledi_mode_set(ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_LED, LED_SYSTEM), system_mode); + + return ONLP_STATUS_OK; +} + +int +onlp_sysi_platform_manage_leds_type2(void) +{ + int fan_number, psu_number; + onlp_led_mode_t mode, system_mode; + int min_fan_speed; + + int fan_led_id[4] = { LED_FAN1, LED_FAN2, LED_FAN3, LED_FAN4 }; + + int fan_problem = 0; + int psu_problem = 0; + + /* + * FAN Indicators + * + * Green - Fan is operating + * Red - No power or Fan failure + * Off - No power + * + */ + for( fan_number = 1; fan_number <= mlnx_platform_info.fan_num; fan_number+=2) + { + /* each 2 fans had same led_fan */ + onlp_fan_info_t fi; + /* check fans */ + mode = ONLP_LED_MODE_GREEN; + if(onlp_fani_info_get(ONLP_FAN_ID_CREATE(fan_number), &fi) < 0) { + mode = ONLP_LED_MODE_RED; + fan_problem = 1; + } + else if( (fi.status & ONLP_FAN_STATUS_PRESENT) == 0) { + if(mlnx_platform_info.fan_fixed == false) { + /* Not present */ + mode = ONLP_LED_MODE_RED; + fan_problem = 1; + } + } + else if(fi.status & ONLP_FAN_STATUS_FAILED) { + mode = ONLP_LED_MODE_RED; + fan_problem = 1; + } + else + { + min_fan_speed = onlp_fani_get_min_rpm(fan_number); + if( fi.rpm < min_fan_speed) + { + mode = ONLP_LED_MODE_RED; + fan_problem = 1; + } + } + /* check fan i+1 */ + if(onlp_fani_info_get(ONLP_FAN_ID_CREATE(fan_number+1), &fi) < 0) { + mode = ONLP_LED_MODE_RED; + fan_problem = 1; + } + else if( (fi.status & 0x1) == 0) { + if(mlnx_platform_info.fan_fixed == false) { + /* Not present */ + mode = ONLP_LED_MODE_RED; + fan_problem = 1; + } + } + else if(fi.status & ONLP_FAN_STATUS_FAILED) { + mode = ONLP_LED_MODE_RED; + fan_problem = 1; + } + else + { + min_fan_speed = onlp_fani_get_min_rpm(fan_number+1); + if( fi.rpm < min_fan_speed) + { + mode = ONLP_LED_MODE_RED; + fan_problem = 1; + } + } + onlp_ledi_mode_set(ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_LED,fan_led_id[fan_number/2]), mode); + } + + for (psu_number = 1; psu_number <= mlnx_platform_info.psu_num; psu_number++) + { + onlp_psu_info_t pi; + if(onlp_psui_info_get(ONLP_PSU_ID_CREATE(psu_number), &pi) < 0) { + psu_problem = 1; + } + else { + if(mlnx_platform_info.psu_fixed) { + /* Fixed system, PSU always in. Check only cable plugged. */ + if(pi.status & ONLP_PSU_STATUS_UNPLUGGED) { + mode = ONLP_LED_MODE_RED; + psu_problem = 1; + } + } + else { + if((pi.status & ONLP_PSU_STATUS_PRESENT) == 0) { + /* Not present */ + psu_problem = 1; + } + else if(pi.status & ONLP_PSU_STATUS_UNPLUGGED) { + psu_problem = 1; + } + } + } + } + + if (psu_problem) + mode = ONLP_LED_MODE_RED; + else + mode = ONLP_LED_MODE_GREEN; + onlp_ledi_mode_set(ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_LED, LED_PSU), mode); + + /* Set System status LED green if no problem in FANs or PSUs */ + if (fan_problem || psu_problem) + system_mode = ONLP_LED_MODE_RED; + else + system_mode = ONLP_LED_MODE_GREEN; + + onlp_ledi_mode_set(ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_LED,LED_SYSTEM), system_mode); + + return ONLP_STATUS_OK; +} + +int +onlp_sysi_platform_manage_leds(void) +{ + int res; + if(mlnx_platform_info.led_type == 1) + res=onlp_sysi_platform_manage_leds_type1(); + else + res=onlp_sysi_platform_manage_leds_type2(); + return res; +} diff --git a/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_thermali.c b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_thermali.c new file mode 100644 index 00000000..4727d3a5 --- /dev/null +++ b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_thermali.c @@ -0,0 +1,74 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * + * 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. + * + * + ************************************************************ + * + * Thermal Platform Implementation Defaults. + * + ***********************************************************/ +#include +#include +#include +#include +#include +#include +#include "mlnx_common/mlnx_common.h" + +#define prefix_path "/bsp/thermal" + +#define VALIDATE(_id) \ + do { \ + if(!ONLP_OID_IS_THERMAL(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ + } while(0) + +/* + * Retrieve the information structure for the given thermal OID. + * + * If the OID is invalid, return ONLP_E_STATUS_INVALID. + * If an unexpected error occurs, return ONLP_E_STATUS_INTERNAL. + * Otherwise, return ONLP_STATUS_OK with the OID's information. + * + * Note -- it is expected that you fill out the information + * 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) +{ + int rv, temp_base=1, local_id = 0; + int r_val; + VALIDATE(id); + + local_id = ONLP_OID_ID_GET(id); + + mlnx_platform_info_t* mlnx_platform_info = get_platform_info(); + + /* Set the onlp_oid_hdr_t and capabilities */ + *info = mlnx_platform_info->tinfo[local_id]; + + rv = onlp_file_read_int(&r_val, "%s/%s", prefix_path, mlnx_platform_info->thermal_fnames[local_id]); + if (rv < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + info->mcelsius = r_val / temp_base; + + return ONLP_STATUS_OK; +} diff --git a/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_ucli.c b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_ucli.c new file mode 100644 index 00000000..296d3510 --- /dev/null +++ b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_ucli.c @@ -0,0 +1,49 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +#if MLNX_COMMON_CONFIG_INCLUDE_UCLI == 1 + +#include +#include +#include + +static ucli_status_t +mlnx_common_ucli_ucli__config__(ucli_context_t* uc) +{ + UCLI_HANDLER_MACRO_MODULE_CONFIG(mlnx_common) +} + +/* */ +/* */ + +static ucli_module_t +mlnx_common_ucli_module__ = + { + "mlnx_common_ucli", + NULL, + mlnx_common_ucli_ucli_handlers__, + NULL, + NULL, + }; + +ucli_node_t* +mlnx_common_ucli_node_create(void) +{ + ucli_node_t* n; + ucli_module_init(&mlnx_common_ucli_module__); + n = ucli_node_create("mlnx_common", NULL, &mlnx_common_ucli_module__); + ucli_node_subnode_add(n, ucli_module_log_node_create("mlnx_common")); + return n; +} + +#else +void* +mlnx_common_ucli_node_create(void) +{ + return NULL; +} +#endif diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/platform_lib.c b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_utils.c similarity index 94% rename from packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/platform_lib.c rename to packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_utils.c index 5035bc48..6a45a7a6 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/platform_lib.c +++ b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_common_utils.c @@ -32,8 +32,10 @@ #include #include #include +#include #include -#include "platform_lib.h" +#include "mlnx_common_log.h" +#include "mlnx_common_int.h" int psu_read_eeprom(int psu_index, onlp_psu_info_t* psu_info, onlp_fan_info_t* fan_info) @@ -45,7 +47,7 @@ psu_read_eeprom(int psu_index, onlp_psu_info_t* psu_info, onlp_fan_info_t* fan_i int index = 0, rv = 0, len = 0; rv = onlp_file_read((uint8_t* )data, sizeof(data)-1, &len, - IDPROM_PATH, "psu", psu_index); + IDPROM_PATH, "psu", psu_index); if (rv < 0) { return ONLP_STATUS_E_INTERNAL; } @@ -82,7 +84,7 @@ psu_read_eeprom(int psu_index, onlp_psu_info_t* psu_info, onlp_fan_info_t* fan_i } int -onlp_get_kernel_ver() +mc_get_kernel_ver() { struct utsname buff; char ver[4]; diff --git a/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_platform_common_int.h b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_platform_common_int.h new file mode 100644 index 00000000..314f1644 --- /dev/null +++ b/packages/platforms/mellanox/any/src/mlnx_common/module/src/mlnx_platform_common_int.h @@ -0,0 +1,17 @@ +/**************************************************************************//** + * + * mlnx_platform_common Internal Header + * + *****************************************************************************/ +#ifndef __MLNX_PLATFORM_COMMON_INT_H__ +#define __MLNX_PLATFORM_COMMON_INT_H__ + +#include + +#ifndef KERNEL_VERSION +#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) +#endif + +int mpc_get_kernel_ver(void); + +#endif /* __MLNX_PLATFORM_COMMON_INT_H__ */ diff --git a/packages/platforms/mellanox/any/src/mlnx_common/utest/_make.mk b/packages/platforms/mellanox/any/src/mlnx_common/utest/_make.mk new file mode 100644 index 00000000..0eb8ffeb --- /dev/null +++ b/packages/platforms/mellanox/any/src/mlnx_common/utest/_make.mk @@ -0,0 +1,8 @@ +############################################################################### +# +# mlnx_common Unit Test Makefile. +# +############################################################################### +UMODULE := mlnx_common +UMODULE_SUBDIR := $(dir $(lastword $(MAKEFILE_LIST))) +include $(BUILDER)/utest.mk diff --git a/packages/platforms/mellanox/any/src/mlnx_common/utest/main.c b/packages/platforms/mellanox/any/src/mlnx_common/utest/main.c new file mode 100644 index 00000000..2563add8 --- /dev/null +++ b/packages/platforms/mellanox/any/src/mlnx_common/utest/main.c @@ -0,0 +1,18 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +#include +#include +#include +#include + +int aim_main(int argc, char* argv[]) +{ + printf("mlnx_common Utest Is Empty\n"); + mlnx_common_config_show(&aim_pvs_stdout); + return ONLP_STATUS_OK; +} diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/lib/Makefile b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/lib/Makefile index 7ed38df4..ff8eab0d 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/lib/Makefile +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/lib/Makefile @@ -26,7 +26,7 @@ include $(ONL)/make/config.amd64.mk MODULE := libonlp-x86-64-mlnx-msn2100 include $(BUILDER)/standardinit.mk -DEPENDMODULES := AIM IOF x86_64_mlnx_msn2100 onlplib +DEPENDMODULES := AIM IOF mlnx_common x86_64_mlnx_msn2100 onlplib DEPENDMODULE_HEADERS := sff include $(BUILDER)/dependmodules.mk @@ -37,6 +37,7 @@ include $(BUILDER)/so.mk .DEFAULT_GOAL := $(SHAREDLIB) GLOBAL_CFLAGS += -I$(onlp_BASEDIR)/module/inc +GLOBAL_CFLAGS += -I$(mlnx_common_BASEDIR)/module/inc GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MODULES_INIT=1 GLOBAL_CFLAGS += -fPIC GLOBAL_LINK_LIBS += -lpthread diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/onlpdump/Makefile b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/onlpdump/Makefile index 491f363d..31edf7c0 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/onlpdump/Makefile +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/onlpdump/Makefile @@ -29,7 +29,7 @@ include $(ONL)/make/config.amd64.mk MODULE := onlpdump include $(BUILDER)/standardinit.mk -DEPENDMODULES := AIM IOF onlp x86_64_mlnx_msn2100 onlplib onlp_platform_defaults sff cjson cjson_util timer_wheel OS +DEPENDMODULES := AIM IOF onlp mlnx_common x86_64_mlnx_msn2100 onlplib onlp_platform_defaults sff cjson cjson_util timer_wheel OS include $(BUILDER)/dependmodules.mk @@ -40,6 +40,7 @@ include $(BUILDER)/bin.mk GLOBAL_CFLAGS += -DAIM_CONFIG_AIM_MAIN_FUNCTION=onlpdump_main GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MODULES_INIT=1 GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MAIN=1 +GLOBAL_CFLAGS += -I$(mlnx_common_BASEDIR)/module/inc GLOBAL_LINK_LIBS += -lpthread -lm include $(BUILDER)/targets.mk diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/fani.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/fani.c index f1de974e..8f05fe8a 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/fani.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/fani.c @@ -27,47 +27,20 @@ #include #include #include "platform_lib.h" - -#define PREFIX_PATH "/bsp/fan/" - -#define FAN_STATUS_OK 1 - -#define PERCENTAGE_MIN 60.0 -#define PERCENTAGE_MAX 100.0 -#define RPM_MAGIC_MIN 153.0 -#define RPM_MAGIC_MAX 255.0 - -#define PROJECT_NAME -#define LEN_FILE_NAME 80 +#include "mlnx_common/mlnx_common.h" #define FAN_RESERVED 0 #define FAN_1_ON_MAIN_BOARD 1 #define FAN_2_ON_MAIN_BOARD 2 #define FAN_3_ON_MAIN_BOARD 3 #define FAN_4_ON_MAIN_BOARD 4 -#define FAN_MODEL "MEC012579" + +/* No PSU with fan, set to bigger then last fan id*/ +#define FIRST_PSU_FAN_ID 5 static int min_fan_speed[CHASSIS_FAN_COUNT+1] = {0}; static int max_fan_speed[CHASSIS_FAN_COUNT+1] = {0}; -typedef struct fan_path_S -{ - char status[LEN_FILE_NAME]; - char r_speed_get[LEN_FILE_NAME]; - char r_speed_set[LEN_FILE_NAME]; - char min[LEN_FILE_NAME]; - char max[LEN_FILE_NAME]; -}fan_path_T; - -#define _MAKE_FAN_PATH_ON_MAIN_BOARD(prj,id) \ - { #prj"fan"#id"_status", \ - #prj"fan"#id"_speed_get", \ - #prj"fan"#id"_speed_set", \ - #prj"fan"#id"_min", \ - #prj"fan"#id"_max" } - -#define MAKE_FAN_PATH_ON_MAIN_BOARD(prj,id) _MAKE_FAN_PATH_ON_MAIN_BOARD(prj,id) - static fan_path_T fan_path[] = /* must map with onlp_fan_id */ { MAKE_FAN_PATH_ON_MAIN_BOARD(PROJECT_NAME, FAN_RESERVED), @@ -77,19 +50,8 @@ static fan_path_T fan_path[] = /* must map with onlp_fan_id */ MAKE_FAN_PATH_ON_MAIN_BOARD(PROJECT_NAME, FAN_4_ON_MAIN_BOARD) }; -#define MAKE_FAN_INFO_NODE_ON_MAIN_BOARD(id) \ - { \ - { ONLP_FAN_ID_CREATE(FAN_##id##_ON_MAIN_BOARD), "Chassis Fan "#id, 0 }, \ - 0x0, \ - (ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_GET_PERCENTAGE | \ - ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_SET_RPM), \ - 0, \ - 0, \ - ONLP_FAN_MODE_INVALID, \ - } - /* Static fan information */ -onlp_fan_info_t linfo[] = { +onlp_fan_info_t finfo[] = { { }, /* Not used */ MAKE_FAN_INFO_NODE_ON_MAIN_BOARD(1), MAKE_FAN_INFO_NODE_ON_MAIN_BOARD(2), @@ -97,265 +59,18 @@ onlp_fan_info_t linfo[] = { MAKE_FAN_INFO_NODE_ON_MAIN_BOARD(4) }; -#define VALIDATE(_id) \ - do { \ - if(!ONLP_OID_IS_FAN(_id)) { \ - return ONLP_STATUS_E_INVALID; \ - } \ - } while(0) - -#define OPEN_READ_FILE(fullpath, data, nbytes, len) \ - if (onlp_file_read((uint8_t*)data, nbytes, &len, fullpath) < 0) \ - return ONLP_STATUS_E_INTERNAL; \ - else \ - AIM_LOG_VERBOSE("read data: %s\n", r_data); \ - -static int -_onlp_fani_info_get_fan(int local_id, onlp_fan_info_t* info) -{ - int len = 0, nbytes = 10; - float range = 0; - float temp = 0; - char r_data[10] = {0}; - char fullpath[65] = {0}; - const char fan_model[]=FAN_MODEL; - - /* Fixed system FAN is always present */ - info->status |= ONLP_FAN_STATUS_PRESENT; - - strncpy(info->model, fan_model, sizeof(info->model)); - - /* get fan speed */ - snprintf(fullpath, sizeof(fullpath), "%s%s", PREFIX_PATH, fan_path[local_id].r_speed_get); - OPEN_READ_FILE(fullpath, r_data, nbytes, len); - info->rpm = atoi(r_data); - - /* check failure */ - if (info->rpm <= 0) { - info->status |= ONLP_FAN_STATUS_FAILED; - return ONLP_STATUS_OK; - } - - if (ONLP_FAN_CAPS_GET_PERCENTAGE & info->caps) { - /* get fan min speed */ - snprintf(fullpath, sizeof(fullpath), "%s%s", PREFIX_PATH, fan_path[local_id].min); - OPEN_READ_FILE(fullpath, r_data, nbytes, len); - min_fan_speed[local_id] = atoi(r_data); - - /* get fan max speed */ - snprintf(fullpath, sizeof(fullpath), "%s%s", PREFIX_PATH, fan_path[local_id].max); - OPEN_READ_FILE(fullpath, r_data, nbytes, len); - max_fan_speed[local_id] = atoi(r_data); - - /* get speed percentage from rpm */ - range = max_fan_speed[local_id] - min_fan_speed[local_id]; - if (range > 0) { - temp = ((float)info->rpm - (float)min_fan_speed[local_id]) / range * 40.0 + 60.0; - if (temp < PERCENTAGE_MIN) { - temp = PERCENTAGE_MIN; - } - info->percentage = (int)temp; - } else { - return ONLP_STATUS_E_INTERNAL; - } - } - - return ONLP_STATUS_OK; -} - /* * This function will be called prior to all of onlp_fani_* functions. */ int onlp_fani_init(void) { + mlnx_platform_info_t* mlnx_platform_info = get_platform_info(); + mlnx_platform_info->min_fan_speed=min_fan_speed; + mlnx_platform_info->max_fan_speed=max_fan_speed; + mlnx_platform_info->finfo = finfo; + mlnx_platform_info->fan_fnames = fan_path; + mlnx_platform_info->fan_type = FAN_TYPE_NO_EEPROM; + mlnx_platform_info->first_psu_fan_id = FIRST_PSU_FAN_ID; return ONLP_STATUS_OK; } - -int -onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* info) -{ - int rc = 0; - int local_id = 0; - VALIDATE(id); - - local_id = ONLP_OID_ID_GET(id); - - *info = linfo[local_id]; - - switch (local_id) - { - case FAN_1_ON_MAIN_BOARD: - case FAN_2_ON_MAIN_BOARD: - case FAN_3_ON_MAIN_BOARD: - case FAN_4_ON_MAIN_BOARD: - rc =_onlp_fani_info_get_fan(local_id, info); - break; - default: - rc = ONLP_STATUS_E_INVALID; - 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) -{ - float temp = 0.0; - int rv = 0, local_id = 0, nbytes = 10; - char r_data[10] = {0}; - onlp_fan_info_t* info = NULL; - - VALIDATE(id); - - local_id = ONLP_OID_ID_GET(id); - info = &linfo[local_id]; - - if (0 == (ONLP_FAN_CAPS_SET_RPM & info->caps)) { - return ONLP_STATUS_E_UNSUPPORTED; - } - - /* reject rpm=0% (rpm=0%, stop fan) */ - if (0 == rpm) { - return ONLP_STATUS_E_INVALID; - } - - /* Set fan speed - Converting percent to driver value. - Driver accept value in range between 153 and 255. - Value 153 is minimum rpm. - Value 255 is maximum rpm. - */ - if (local_id > sizeof(min_fan_speed)/sizeof(min_fan_speed[0])) { - return ONLP_STATUS_E_INTERNAL; - } - if (max_fan_speed[local_id] - min_fan_speed[local_id] < 0) { - return ONLP_STATUS_E_INTERNAL; - } - if (rpm < min_fan_speed[local_id] || rpm > max_fan_speed[local_id]) { - return ONLP_STATUS_E_PARAM; - } - - temp = (rpm - min_fan_speed[local_id]) * (RPM_MAGIC_MAX - RPM_MAGIC_MIN) / - (max_fan_speed[local_id] - min_fan_speed[local_id]) + RPM_MAGIC_MIN; - - snprintf(r_data, sizeof(r_data), "%d", (int)temp); - nbytes = strnlen(r_data, sizeof(r_data)); - rv = onlp_file_write((uint8_t*)r_data, nbytes, "%s%s", PREFIX_PATH, - fan_path[local_id].r_speed_set); - if (rv < 0) { - return ONLP_STATUS_E_INTERNAL; - } - - return ONLP_STATUS_OK; -} - -/* - * 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) -{ - float temp = 0.0; - int rv = 0, local_id = 0, nbytes = 10; - char r_data[10] = {0}; - onlp_fan_info_t* info = NULL; - - VALIDATE(id); - local_id = ONLP_OID_ID_GET(id); - info = &linfo[local_id]; - - if (0 == (ONLP_FAN_CAPS_SET_PERCENTAGE & info->caps)) { - return ONLP_STATUS_E_UNSUPPORTED; - } - - /* reject p=0% (p=0%, stop fan) */ - if (0 == p) { - return ONLP_STATUS_E_INVALID; - } - - if (p < PERCENTAGE_MIN || p > PERCENTAGE_MAX) { - return ONLP_STATUS_E_PARAM; - } - - /* Set fan speed - Converting percent to driver value. - Driver accept value in range between 153 and 255. - Value 153 is 60%. - Value 255 is 100%. - */ - temp = (p - PERCENTAGE_MIN) * (RPM_MAGIC_MAX - RPM_MAGIC_MIN) / - (PERCENTAGE_MAX - PERCENTAGE_MIN) + RPM_MAGIC_MIN; - - snprintf(r_data, sizeof(r_data), "%d", (int)temp); - nbytes = strnlen(r_data, sizeof(r_data)); - rv = onlp_file_write((uint8_t*)r_data, nbytes, "%s%s", - PREFIX_PATH, fan_path[local_id].r_speed_set); - if (rv < 0) { - 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; -} - -int -onlp_fani_get_min_rpm(int id) -{ - int len = 0, nbytes = 10; - char r_data[10] = {0}; - - if (onlp_file_read((uint8_t*)r_data, nbytes, &len, "%s%s", PREFIX_PATH, fan_path[id].min) < 0) - return ONLP_STATUS_E_INTERNAL; - - return atoi(r_data); -} diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/ledi.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/ledi.c index b6e6e8ad..872e6a49 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/ledi.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/ledi.c @@ -30,98 +30,17 @@ #include #include #include "platform_lib.h" +#include -#define prefix_path "/bsp/led/led_" -#define driver_value_len 50 -#define LED_MODE_OFF "none" -#define LED_MODE_GREEN "green" -#define LED_MODE_RED "red" -#define LED_MODE_BLUE "blue" -#define LED_MODE_GREEN_BLINK "green_blink" -#define LED_MODE_RED_BLINK "red_blink" -#define LED_MODE_BLUE_BLINK "blue_blink" -#define LED_MODE_AUTO "cpld_control" - -#define LED_BLINK_PERIOD "100" -#define LED_ON "1" -#define LED_OFF "0" -#define LED_BLINK_PERIOD_LEN 3 -#define LED_MODE_LEN 1 - -#define VALIDATE(_id) \ - do { \ - if(!ONLP_OID_IS_LED(_id)) { \ - return ONLP_STATUS_E_INVALID; \ - } \ - } while(0) - -/* LED related data - */ - -typedef struct led_light_mode_map { - enum onlp_led_id id; - char* driver_led_mode; - enum onlp_led_mode_e onlp_led_mode; -} led_light_mode_map_t; - -led_light_mode_map_t led_map[] = { -{LED_SYSTEM, LED_MODE_OFF, ONLP_LED_MODE_OFF}, -{LED_SYSTEM, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, -{LED_SYSTEM, LED_MODE_RED, ONLP_LED_MODE_RED}, -{LED_SYSTEM, LED_MODE_RED_BLINK, ONLP_LED_MODE_RED_BLINKING}, -{LED_SYSTEM, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, -{LED_SYSTEM, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, - -{LED_FAN, LED_MODE_OFF, ONLP_LED_MODE_OFF}, -{LED_FAN, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, -{LED_FAN, LED_MODE_RED, ONLP_LED_MODE_RED}, -{LED_FAN, LED_MODE_RED_BLINK, ONLP_LED_MODE_RED_BLINKING}, -{LED_FAN, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, -{LED_FAN, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, - -{LED_PSU1, LED_MODE_OFF, ONLP_LED_MODE_OFF}, -{LED_PSU1, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, -{LED_PSU1, LED_MODE_RED, ONLP_LED_MODE_RED}, -{LED_PSU1, LED_MODE_RED_BLINK, ONLP_LED_MODE_RED_BLINKING}, -{LED_PSU1, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, -{LED_PSU1, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, - -{LED_PSU2, LED_MODE_OFF, ONLP_LED_MODE_OFF}, -{LED_PSU2, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, -{LED_PSU2, LED_MODE_RED, ONLP_LED_MODE_RED}, -{LED_PSU2, LED_MODE_RED_BLINK, ONLP_LED_MODE_RED_BLINKING}, -{LED_PSU2, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, -{LED_PSU2, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, - -{LED_UID, LED_MODE_OFF, ONLP_LED_MODE_OFF}, -{LED_UID, LED_MODE_BLUE, ONLP_LED_MODE_BLUE}, -{LED_UID, LED_MODE_BLUE_BLINK, ONLP_LED_MODE_BLUE_BLINKING}, -{LED_UID, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, -}; - -typedef struct led_colors { - enum onlp_led_id id; - const char* color1; - const char* color2; -} led_colors_t; - -static led_colors_t led_colors_map[] = { - {LED_SYSTEM, "green", "red"}, - {LED_FAN, "green", "red"}, - {LED_PSU1, "green", "red"}, - {LED_PSU2, "green", "red"}, - {LED_UID, "blue", NULL}, -}; - -static char file_names[][10] = /* must map with onlp_led_id */ +static char* file_names[] = /* must map with onlp_led_id */ { "reserved", "status", "fan", "psu1", "psu2", - "uid" + "uid" }; /* @@ -162,213 +81,14 @@ static onlp_led_info_t linfo[] = } }; -static int driver_to_onlp_led_mode(enum onlp_led_id id, char* driver_led_mode) -{ - char *pos; - int i, nsize = sizeof(led_map)/sizeof(led_map[0]); - - if ((pos=strchr(driver_led_mode, '\n')) != NULL) - *pos = '\0'; - for (i = 0; i < nsize; i++) - { - if (id == led_map[i].id && - !strncmp(led_map[i].driver_led_mode, driver_led_mode, driver_value_len)) - { - return led_map[i].onlp_led_mode; - } - } - - return 0; -} - -static char* onlp_to_driver_led_mode(enum onlp_led_id id, onlp_led_mode_t onlp_led_mode) -{ - int i, nsize = sizeof(led_map)/sizeof(led_map[0]); - - for (i = 0; i < nsize; i++) - { - if (id == led_map[i].id && onlp_led_mode == led_map[i].onlp_led_mode) - { - return led_map[i].driver_led_mode; - } - } - - return LED_MODE_OFF; -} - -static int led_set_mode(onlp_oid_t id, onlp_led_mode_t mode) -{ - int local_id = ONLP_OID_ID_GET(id); - char color[10]={0}; - int blinking = 0; - - switch (mode) { - case ONLP_LED_MODE_RED_BLINKING: - strcpy(color, "red"); - blinking = 1; - break; - case ONLP_LED_MODE_GREEN_BLINKING: - strcpy(color, "green"); - blinking = 1; - break; - case ONLP_LED_MODE_BLUE_BLINKING: - strcpy(color, "blue"); - blinking = 1; - break; - case ONLP_LED_MODE_YELLOW_BLINKING: - strcpy(color, "yellow"); - blinking = 1; - break; - case ONLP_LED_MODE_RED: - strcpy(color, "red"); - break; - case ONLP_LED_MODE_GREEN: - strcpy(color, "green"); - break; - case ONLP_LED_MODE_BLUE: - strcpy(color, "blue"); - break; - case ONLP_LED_MODE_YELLOW: - strcpy(color, "yellow"); - break; - default: - return ONLP_STATUS_E_PARAM; - } - - if (blinking) { - onlp_file_write((uint8_t*)LED_BLINK_PERIOD, LED_BLINK_PERIOD_LEN, - "%s%s_%s_delay_off", prefix_path, file_names[local_id], color); - onlp_file_write((uint8_t*)LED_BLINK_PERIOD, LED_BLINK_PERIOD_LEN, - "%s%s_%s_delay_on", prefix_path, file_names[local_id], color); - } - onlp_file_write((uint8_t*)LED_ON, LED_MODE_LEN, - "%s%s_%s", prefix_path, file_names[local_id], color); - - return ONLP_STATUS_OK; -} - /* * This function will be called prior to any other onlp_ledi_* functions. */ int onlp_ledi_init(void) { - /* - * ONLPD calls it too early before all BSP insfrastructure is set - */ - + mlnx_platform_info_t* mlnx_platform_info = get_platform_info(); + mlnx_platform_info->linfo = linfo; + mlnx_platform_info->led_fnames = file_names; return ONLP_STATUS_OK; } - -int -onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) -{ - int len, local_id = 0; - uint8_t data[driver_value_len] = {0}; - - VALIDATE(id); - - local_id = ONLP_OID_ID_GET(id); - - /* Set the onlp_oid_hdr_t and capabilities */ - *info = linfo[ONLP_OID_ID_GET(id)]; - - /* Get LED mode */ - if (onlp_get_kernel_ver() >= KERNEL_VERSION(4,9,30)) { - char* cmd = aim_fstrdup("%s%s_state", prefix_path, file_names[local_id]); - if(system(cmd) != 0) { - aim_free(cmd); - return ONLP_STATUS_E_INTERNAL; - } - aim_free(cmd); - } - - if (onlp_file_read(data, sizeof(data), &len, "%s%s", - prefix_path, file_names[local_id]) != 0) { - return ONLP_STATUS_E_INTERNAL; - } - - info->mode = driver_to_onlp_led_mode(local_id, (char*)data); - - /* Set the on/off status */ - if (info->mode != ONLP_LED_MODE_OFF) { - info->status |= ONLP_LED_STATUS_ON; - } - - return ONLP_STATUS_OK; -} - -/* - * Turn an LED on or off. - * - * This function will only be called if the LED OID supports the ONOFF - * capability. - * - * What 'on' means in terms of colors or modes for multimode LEDs is - * up to the platform to decide. This is intended as baseline toggle mechanism. - */ -int -onlp_ledi_set(onlp_oid_t id, int on_or_off) -{ - VALIDATE(id); - - if (!on_or_off) { - if (onlp_get_kernel_ver() < KERNEL_VERSION(4,9,30)) - return onlp_ledi_mode_set(id, ONLP_LED_MODE_OFF); - else { - int i, nsize = sizeof(led_colors_map)/sizeof(led_colors_map[0]); - for (i = 0; i < nsize; i++) - { - if (id == led_colors_map[i].id) - break; - } - if (led_colors_map[i].color1) - onlp_file_write((uint8_t*)LED_OFF, LED_MODE_LEN, - "%s%s_%s", prefix_path, file_names[id], led_colors_map[i].color1); - } - } - - return ONLP_STATUS_E_UNSUPPORTED; -} - -/* - * This function puts the LED into the given mode. It is a more functional - * interface for multimode LEDs. - * - * Only modes reported in the LED's capabilities will be attempted. - */ -int -onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) -{ - int local_id; - char* driver_led_mode; - int nbytes; - - VALIDATE(id); - - if (onlp_get_kernel_ver() < KERNEL_VERSION(4,9,30)) { - local_id = ONLP_OID_ID_GET(id); - driver_led_mode = onlp_to_driver_led_mode(local_id, mode); - nbytes = strnlen(driver_led_mode, driver_value_len); - if (onlp_file_write((uint8_t*)driver_led_mode, nbytes, - "%s%s", prefix_path, file_names[local_id]) != 0) { - return ONLP_STATUS_E_INTERNAL; - } - } else { - if (led_set_mode(id, mode) != 0) { - return ONLP_STATUS_E_INTERNAL; - } - } - - return ONLP_STATUS_OK; -} - -/* - * Generic LED ioctl interface. - */ -int -onlp_ledi_ioctl(onlp_oid_t id, va_list vargs) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/platform_lib.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/platform_lib.c deleted file mode 100644 index 5c7d11f4..00000000 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/platform_lib.c +++ /dev/null @@ -1,63 +0,0 @@ -/************************************************************ - * - * - * Copyright 2014 Big Switch Networks, Inc. - * - * 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 -#include -#include -#include -#include -#include "platform_lib.h" - -int -onlp_get_kernel_ver() -{ - struct utsname buff; - char ver[4]; - char *p; - int i = 0; - - if (uname(&buff) != 0) - return ONLP_STATUS_E_INTERNAL; - - p = buff.release; - - while (*p) { - if (isdigit(*p)) { - ver[i] = strtol(p, &p, 10); - i++; - if (i >= 3) - break; - } else { - p++; - } - } - - return KERNEL_VERSION(ver[0], ver[1], ver[2]); -} diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/platform_lib.h b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/platform_lib.h index 357bf8c4..fd6ff537 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/platform_lib.h +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/platform_lib.h @@ -25,47 +25,13 @@ #ifndef __PLATFORM_LIB_H__ #define __PLATFORM_LIB_H__ -#include -#include #include "x86_64_mlnx_msn2100_log.h" -#define CHASSIS_LED_COUNT 5 +#define CHASSIS_LED_COUNT 5 #define CHASSIS_PSU_COUNT 2 #define CHASSIS_FAN_COUNT 4 #define CHASSIS_THERMAL_COUNT 7 - -#define PSU1_ID 1 -#define PSU2_ID 2 - -#define PSU_MODULE_PREFIX "/bsp/module/psu%d_%s" -#define PSU_POWER_PREFIX "/bsp/power/psu%d_%s" -#define IDPROM_PATH "/bsp/eeprom/%s%d_info" - -#ifndef KERNEL_VERSION -#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) -#endif - -/* LED related data - */ -enum onlp_led_id -{ - LED_RESERVED = 0, - LED_SYSTEM, - LED_FAN, - LED_PSU1, - LED_PSU2, - LED_UID -}; - -typedef enum psu_type { - PSU_TYPE_UNKNOWN, - PSU_TYPE_AC_F2B, - PSU_TYPE_AC_B2F -} psu_type_t; - -psu_type_t get_psu_type(int id, char* modelname, int modelname_len); - -int onlp_fani_get_min_rpm(int id); -int onlp_get_kernel_ver(void); +#define SFP_PORT_COUNT 16 +#define CPLD_COUNT 2 #endif /* __PLATFORM_LIB_H__ */ diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/psui.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/psui.c deleted file mode 100644 index e371e303..00000000 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/psui.c +++ /dev/null @@ -1,173 +0,0 @@ -/************************************************************ - * - * - * Copyright 2014 Big Switch Networks, Inc. - * - * 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 "platform_lib.h" - -#define PSU_STATUS_PRESENT 1 -#define PSU_CABLE_PRESENT 1 - -#define PSU_NODE_MAX_INT_LEN 8 -#define PSU_NODE_MAX_PATH_LEN 64 - -#define PSU_MODEL "POW000167" - -#define VALIDATE(_id) \ - do { \ - if(!ONLP_OID_IS_PSU(_id)) { \ - return ONLP_STATUS_E_INVALID; \ - } \ - } while(0) - -static int -psu_module_info_get(int id, char *node, int *value) -{ - int len, ret = 0; - char buf[PSU_NODE_MAX_INT_LEN + 1] = {0}; - - *value = 0; - - ret = onlp_file_read((uint8_t*)buf, sizeof(buf), &len, - PSU_MODULE_PREFIX, id, node); - if (ret == 0) { - *value = atoi(buf); - } - - return ret; -} - -static int -psu_power_info_get(int id, char *node, int *value) -{ - int len, ret = 0; - char buf[PSU_NODE_MAX_INT_LEN + 1] = {0}; - - *value = 0; - - ret = onlp_file_read((uint8_t*)buf, sizeof(buf), &len, - PSU_POWER_PREFIX, id, node); - if (ret == 0) { - *value = atoi(buf); - } - - return ret; -} - -int -onlp_psui_init(void) -{ - return ONLP_STATUS_OK; -} - -static int -_psu_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; - } - - /* Read voltage, current and power */ - if (psu_power_info_get(index, "volt", &val) == 0) { - info->mvout = val; - info->caps |= ONLP_PSU_CAPS_VOUT; - } - - if (psu_power_info_get(index, "curr", &val) == 0) { - info->miout = val; - info->caps |= ONLP_PSU_CAPS_IOUT; - } - - info->mpout = info->mvout * info->miout; - info->caps |= ONLP_PSU_CAPS_POUT; - - info->mpin = ((int)(info->mpout / 91)) * 100; - info->caps |= ONLP_PSU_CAPS_PIN; - - return ONLP_STATUS_OK; -} - -/* - * Get all information about the given PSU oid. - */ -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 }, - } -}; - -int -onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) -{ - int val = 0; - int index = ONLP_OID_ID_GET(id); - const char psu_model[]=PSU_MODEL; - - VALIDATE(id); - - memset(info, 0, sizeof(onlp_psu_info_t)); - *info = pinfo[index]; /* Set the onlp_oid_hdr_t */ - - /* Fixed system, PSU is always present */ - info->status |= ONLP_PSU_STATUS_PRESENT; - - strncpy(info->model, psu_model, sizeof(info->model)); - - /* Get the cable preset state */ - if (psu_module_info_get(index, "pwr_status", &val) != 0) { - AIM_LOG_ERROR("Unable to read PSU(%d) node(cable_present)\r\n", index); - } - - if (val != PSU_CABLE_PRESENT) { - info->status |= ONLP_PSU_STATUS_UNPLUGGED; - } - else { - info->status &= ~ONLP_PSU_STATUS_UNPLUGGED; - } - - _psu_info_get(info); - - return ONLP_STATUS_OK; -} - -int -onlp_psui_ioctl(onlp_oid_t pid, va_list vargs) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/sysi.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/sysi.c index c2c4a420..d0c181e4 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/sysi.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/sysi.c @@ -35,179 +35,32 @@ #include "platform_lib.h" #include "x86_64_mlnx_msn2100_int.h" #include "x86_64_mlnx_msn2100_log.h" +#include #define ONL_PLATFORM_NAME "x86-64-mlnx-msn2100-r0" -#define ONIE_PLATFORM_NAME "x86_64-mlnx_msn2100-r0" #define COMMAND_OUTPUT_BUFFER 256 -#define PREFIX_PATH_ON_CPLD_DEV "/bsp/cpld" -#define NUM_OF_CPLD 2 -static char arr_cplddev_name[NUM_OF_CPLD][30] = +int mc_get_platform_info(mlnx_platform_info_t* mlnx_platform) { - "cpld_brd_version", - "cpld_mgmt_version" -}; - -const char* -onlp_sysi_platform_get(void) -{ - return ONL_PLATFORM_NAME; -} - -int -onlp_sysi_platform_info_get(onlp_platform_info_t* pi) -{ - int i, v[NUM_OF_CPLD]={0}; - - for (i=0; i < NUM_OF_CPLD; i++) { - v[i] = 0; - if(onlp_file_read_int(v+i, "%s/%s", PREFIX_PATH_ON_CPLD_DEV, arr_cplddev_name[i]) < 0) { - return ONLP_STATUS_E_INTERNAL; - } - } - pi->cpld_versions = aim_fstrdup("brd=%d, mgmt=%d", v[0], v[1]); - - return ONLP_STATUS_OK; -} - -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) -{ - int i; - onlp_oid_t* e = table; - memset(table, 0, max*sizeof(onlp_oid_t)); - - for (i = 1; i <= CHASSIS_THERMAL_COUNT; i++) - { - *e++ = ONLP_THERMAL_ID_CREATE(i); - } - - for (i = 1; i <= CHASSIS_LED_COUNT; i++) - { - *e++ = ONLP_LED_ID_CREATE(i); - } - - for (i = 1; i <= CHASSIS_PSU_COUNT; i++) - { - *e++ = ONLP_PSU_ID_CREATE(i); - } - - for (i = 1; i <= CHASSIS_FAN_COUNT; i++) - { - *e++ = ONLP_FAN_ID_CREATE(i); - } - - return 0; -} - -int -onlp_sysi_onie_info_get(onlp_onie_info_t* onie) -{ - int rv = onlp_onie_read_json(onie, - "/lib/platform-config/current/onl/etc/onie/eeprom.json"); - if(rv >= 0) { - if(onie->platform_name) { - aim_free(onie->platform_name); - } - onie->platform_name = aim_strdup(ONIE_PLATFORM_NAME); - } - - return rv; -} - -int -onlp_sysi_platform_manage_leds(void) -{ - int fan_number, psu_number; - onlp_led_mode_t mode, system_mode; - int min_fan_speed; - enum onlp_led_id psu_led_id[2] = { LED_PSU1, LED_PSU2 }; - int fan_problem = 0; - int psu_problem = 0; - - /* - * FAN Indicators - * - * Green - Fan is operating - * Red - No power or Fan failure - * Off - No power - * - */ - mode = ONLP_LED_MODE_GREEN; - for( fan_number = 1; fan_number<= CHASSIS_FAN_COUNT; fan_number+=2) - { - /* each 2 fans had same led_fan */ - onlp_fan_info_t fi; - /* check fans */ - if(onlp_fani_info_get(ONLP_FAN_ID_CREATE(fan_number), &fi) < 0) { - mode = ONLP_LED_MODE_RED; - fan_problem = 1; - } - else if(fi.status & ONLP_FAN_STATUS_FAILED) { - mode = ONLP_LED_MODE_RED; - fan_problem = 1; - } - else - { - min_fan_speed = onlp_fani_get_min_rpm(fan_number); - if( fi.rpm < min_fan_speed) - { - mode = ONLP_LED_MODE_RED; - fan_problem = 1; - } - } - /* check fan i+1 */ - if(onlp_fani_info_get(ONLP_FAN_ID_CREATE(fan_number+1), &fi) < 0) { - mode = ONLP_LED_MODE_RED; - } - else if(fi.status & ONLP_FAN_STATUS_FAILED) { - mode = ONLP_LED_MODE_RED; - fan_problem = 1; - } - else - { - min_fan_speed = onlp_fani_get_min_rpm(fan_number+1); - if( fi.rpm < min_fan_speed) - { - mode = ONLP_LED_MODE_RED; - fan_problem = 1; - } - } - } - onlp_ledi_mode_set(ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_LED, LED_FAN), mode); - - for (psu_number = 1; psu_number <= CHASSIS_PSU_COUNT; psu_number++) - { - onlp_psu_info_t pi; - mode = ONLP_LED_MODE_GREEN; - if(onlp_psui_info_get(ONLP_PSU_ID_CREATE(psu_number), &pi) < 0) { - mode = ONLP_LED_MODE_RED; - psu_problem = 1; - } - /* Fixed system, PSU always in. Check only cable plugged. */ - else if(pi.status & ONLP_PSU_STATUS_UNPLUGGED) { - mode = ONLP_LED_MODE_RED; - psu_problem = 1; - } - onlp_ledi_mode_set(ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_LED, psu_led_id[(psu_number-1)]), mode); - } - - /* Set System status LED green if no problem in FANs or PSUs */ - if (fan_problem || psu_problem) - system_mode = ONLP_LED_MODE_RED; - else - system_mode = ONLP_LED_MODE_GREEN; - - onlp_ledi_mode_set(ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_LED, LED_SYSTEM), system_mode); + strncpy(mlnx_platform->onl_platform_name, ONL_PLATFORM_NAME, PLATFORM_NAME_MAX_LEN); + mlnx_platform->sfp_num = SFP_PORT_COUNT; + mlnx_platform->led_num = CHASSIS_LED_COUNT; + mlnx_platform->psu_num = CHASSIS_PSU_COUNT; + mlnx_platform->fan_num = CHASSIS_FAN_COUNT; + mlnx_platform->thermal_num = CHASSIS_THERMAL_COUNT; + mlnx_platform->cpld_num = CPLD_COUNT; + mlnx_platform->psu_fixed = true; + mlnx_platform->fan_fixed = true; + mlnx_platform->psu_type = PSU_TYPE_1; + mlnx_platform->led_type = LED_TYPE_1; return ONLP_STATUS_OK; } + +int +onlp_sysi_init(void) +{ + return ONLP_STATUS_OK; +} diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/thermali.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/thermali.c index faaa08c8..eb3126dc 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/thermali.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/thermali.c @@ -29,41 +29,8 @@ #include #include #include "platform_lib.h" +#include "mlnx_common/mlnx_common.h" -#define prefix_path "/bsp/thermal" - -/* CPU thermal_threshold */ -typedef enum cpu_thermal_threshold_e { - CPU_THERMAL_THRESHOLD_WARNING_DEFAULT = 87000, - CPU_THERMAL_THRESHOLD_ERROR_DEFAULT = 100000, - CPU_THERMAL_THRESHOLD_SHUTDOWN_DEFAULT = 105000, -} cpu_thermal_threshold_t; - -/* Shortcut for CPU thermal threshold value. */ -#define CPU_THERMAL_THRESHOLD_INIT_DEFAULTS \ - { CPU_THERMAL_THRESHOLD_WARNING_DEFAULT, \ - CPU_THERMAL_THRESHOLD_ERROR_DEFAULT, \ - CPU_THERMAL_THRESHOLD_SHUTDOWN_DEFAULT } - -/* Asic thermal_threshold */ -typedef enum asic_thermal_threshold_e { - ASIC_THERMAL_THRESHOLD_WARNING_DEFAULT = 105000, - ASIC_THERMAL_THRESHOLD_ERROR_DEFAULT = 115000, - ASIC_THERMAL_THRESHOLD_SHUTDOWN_DEFAULT = 120000, -} asic_thermal_threshold_t; - -/* Shortcut for CPU thermal threshold value. */ -#define ASIC_THERMAL_THRESHOLD_INIT_DEFAULTS \ - { ASIC_THERMAL_THRESHOLD_WARNING_DEFAULT, \ - ASIC_THERMAL_THRESHOLD_ERROR_DEFAULT, \ - ASIC_THERMAL_THRESHOLD_SHUTDOWN_DEFAULT } - -#define VALIDATE(_id) \ - do { \ - if(!ONLP_OID_IS_THERMAL(_id)) { \ - return ONLP_STATUS_E_INVALID; \ - } \ - } while(0) enum onlp_thermal_id { @@ -77,7 +44,7 @@ enum onlp_thermal_id THERMAL_PORT }; -static char* last_path[] = /* must map with onlp_thermal_id */ +static char* thermal_fnames[] = /* must map with onlp_thermal_id */ { "reserved", "cpu_core0", @@ -90,7 +57,7 @@ static char* last_path[] = /* must map with onlp_thermal_id */ }; /* Static values */ -static onlp_thermal_info_t linfo[] = { +static onlp_thermal_info_t tinfo[] = { { }, /* Not used */ { { ONLP_THERMAL_ID_CREATE(THERMAL_CPU_CORE_0), "CPU Core 0", 0}, ONLP_THERMAL_STATUS_PRESENT, @@ -128,39 +95,9 @@ static onlp_thermal_info_t linfo[] = { int onlp_thermali_init(void) { - return ONLP_STATUS_OK; -} - -/* - * Retrieve the information structure for the given thermal OID. - * - * If the OID is invalid, return ONLP_E_STATUS_INVALID. - * If an unexpected error occurs, return ONLP_E_STATUS_INTERNAL. - * Otherwise, return ONLP_STATUS_OK with the OID's information. - * - * Note -- it is expected that you fill out the information - * 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) -{ - int rv, len = 10, temp_base=1, local_id = 0; - char r_data[10] = {0}; - VALIDATE(id); - - local_id = ONLP_OID_ID_GET(id); - - /* Set the onlp_oid_hdr_t and capabilities */ - *info = linfo[local_id]; - - rv = onlp_file_read((uint8_t*)r_data, sizeof(r_data), &len, "%s/%s", - prefix_path, last_path[local_id]); - if (rv < 0) { - return ONLP_STATUS_E_INTERNAL; - } - - info->mcelsius = atoi(r_data) / temp_base; - + mlnx_platform_info_t* mlnx_platform_info = get_platform_info(); + mlnx_platform_info->tinfo=tinfo; + mlnx_platform_info->thermal_fnames=thermal_fnames; return ONLP_STATUS_OK; } diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/Makefile b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/Makefile index 003238cf..dc1e7b86 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/Makefile +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/Makefile @@ -1 +1 @@ -include $(ONL)/make/pkg.mk \ No newline at end of file +include $(ONL)/make/pkg.mk diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/lib/Makefile b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/lib/Makefile index 375c940e..14c80951 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/lib/Makefile +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/lib/Makefile @@ -26,7 +26,7 @@ include $(ONL)/make/config.amd64.mk MODULE := libonlp-x86-64-mlnx-msn2410 include $(BUILDER)/standardinit.mk -DEPENDMODULES := AIM IOF x86_64_mlnx_msn2410 onlplib +DEPENDMODULES := AIM IOF mlnx_common x86_64_mlnx_msn2410 onlplib DEPENDMODULE_HEADERS := sff include $(BUILDER)/dependmodules.mk @@ -37,6 +37,7 @@ include $(BUILDER)/so.mk .DEFAULT_GOAL := $(SHAREDLIB) GLOBAL_CFLAGS += -I$(onlp_BASEDIR)/module/inc +GLOBAL_CFLAGS += -I$(mlnx_common_BASEDIR)/module/inc GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MODULES_INIT=1 GLOBAL_CFLAGS += -fPIC GLOBAL_LINK_LIBS += -lpthread diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/onlpdump/Makefile b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/onlpdump/Makefile index d2523a26..5adaf05b 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/onlpdump/Makefile +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/onlpdump/Makefile @@ -29,7 +29,7 @@ include $(ONL)/make/config.amd64.mk MODULE := onlpdump include $(BUILDER)/standardinit.mk -DEPENDMODULES := AIM IOF onlp x86_64_mlnx_msn2410 onlplib onlp_platform_defaults sff cjson cjson_util timer_wheel OS +DEPENDMODULES := AIM IOF onlp mlnx_common x86_64_mlnx_msn2410 onlplib onlp_platform_defaults sff cjson cjson_util timer_wheel OS include $(BUILDER)/dependmodules.mk @@ -40,6 +40,7 @@ include $(BUILDER)/bin.mk GLOBAL_CFLAGS += -DAIM_CONFIG_AIM_MAIN_FUNCTION=onlpdump_main GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MODULES_INIT=1 GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MAIN=1 +GLOBAL_CFLAGS += -I$(mlnx_common_BASEDIR)/module/inc GLOBAL_LINK_LIBS += -lpthread -lm include $(BUILDER)/targets.mk diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/fani.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/fani.c index e0f07471..9a47a312 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/fani.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/fani.c @@ -27,22 +27,7 @@ #include #include #include "platform_lib.h" - -#define PREFIX_PATH "/bsp/fan/" -#define PREFIX_MODULE_PATH "/bsp/module/" - -#define FAN_STATUS_OK 1 - -#define PERCENTAGE_MIN 60.0 -#define PERCENTAGE_MAX 100.0 -#define RPM_MAGIC_MIN 153.0 -#define RPM_MAGIC_MAX 255.0 - -#define PSU_FAN_RPM_MIN 11700.0 -#define PSU_FAN_RPM_MAX 19500.0 - -#define PROJECT_NAME -#define LEN_FILE_NAME 80 +#include "mlnx_common/mlnx_common.h" #define FAN_RESERVED 0 #define FAN_1_ON_MAIN_BOARD 1 @@ -56,31 +41,11 @@ #define FAN_1_ON_PSU1 9 #define FAN_1_ON_PSU2 10 +#define FIRST_PSU_FAN_ID 9 + static int min_fan_speed[CHASSIS_FAN_COUNT+1] = {0}; static int max_fan_speed[CHASSIS_FAN_COUNT+1] = {0}; -typedef struct fan_path_S -{ - char status[LEN_FILE_NAME]; - char r_speed_get[LEN_FILE_NAME]; - char r_speed_set[LEN_FILE_NAME]; - char min[LEN_FILE_NAME]; - char max[LEN_FILE_NAME]; -}fan_path_T; - -#define _MAKE_FAN_PATH_ON_MAIN_BOARD(prj,id) \ - { #prj"fan"#id"_status", \ - #prj"fan"#id"_speed_get", \ - #prj"fan"#id"_speed_set", \ - #prj"fan"#id"_min", \ - #prj"fan"#id"_max" } - -#define MAKE_FAN_PATH_ON_MAIN_BOARD(prj,id) _MAKE_FAN_PATH_ON_MAIN_BOARD(prj,id) - -#define MAKE_FAN_PATH_ON_PSU(psu_id, fan_id) \ - {"psu"#psu_id"_status", \ - "psu"#psu_id"_fan"#fan_id"_speed_get", "", "", "",} - static fan_path_T fan_path[] = /* must map with onlp_fan_id */ { MAKE_FAN_PATH_ON_MAIN_BOARD(PROJECT_NAME, FAN_RESERVED), @@ -96,29 +61,8 @@ static fan_path_T fan_path[] = /* must map with onlp_fan_id */ MAKE_FAN_PATH_ON_PSU(2, 1) }; -#define MAKE_FAN_INFO_NODE_ON_MAIN_BOARD(id) \ - { \ - { ONLP_FAN_ID_CREATE(FAN_##id##_ON_MAIN_BOARD), "Chassis Fan "#id, 0 }, \ - 0x0, \ - (ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_GET_PERCENTAGE | \ - ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_SET_RPM), \ - 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 }, \ - 0x0, \ - (ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE), \ - 0, \ - 0, \ - ONLP_FAN_MODE_INVALID, \ - } - /* Static fan information */ -onlp_fan_info_t linfo[] = { +onlp_fan_info_t finfo[] = { { }, /* Not used */ MAKE_FAN_INFO_NODE_ON_MAIN_BOARD(1), MAKE_FAN_INFO_NODE_ON_MAIN_BOARD(2), @@ -132,418 +76,18 @@ 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(fullpath, data, nbytes, len) \ - if (onlp_file_read((uint8_t*)data, nbytes, &len, fullpath) < 0) \ - return ONLP_STATUS_E_INTERNAL; \ - else \ - AIM_LOG_VERBOSE("read data: %s\n", r_data); \ - - -static int -_onlp_fani_read_fan_eeprom(int local_id, onlp_fan_info_t* info) -{ - const char sanity_checker[] = "MLNX"; - const uint8_t sanity_offset = 8; - const uint8_t sanity_len = 4; - const uint8_t block1_start = 12; - const uint8_t block1_type = 1; - const uint8_t block2_start = 14; - const uint8_t block2_type = 5; - const uint8_t serial_offset = 8; - const uint8_t serial_len = 24; - const uint8_t part_len = 20; - const uint8_t fan_offset = 14; - const uint8_t multiplier = 16; - uint8_t data[256] = {0}; - uint8_t offset = 0; - uint8_t temp = 0; - int rv = 0; - int len = 0; - - /* We have 4 FRU with 2 fans(total 8 fans). - Eeprom is per FRU but not per fan. - So, need to convert fan ID to FRU ID.*/ - if (local_id % 2) { - local_id = local_id / 2 + 1; - } else { - local_id /= 2; - } - - rv = onlp_file_read(data, sizeof(data), &len, - IDPROM_PATH, "fan", local_id); - if (rv < 0) { - return ONLP_STATUS_E_INTERNAL; - } - - /* Sanity checker */ - if (strncmp(sanity_checker, (char*)&data[sanity_offset], sanity_len)) { - return ONLP_STATUS_E_INVALID; - } - - /* Checking eeprom block type with S/N and P/N */ - if (data[block1_start + 1] != block1_type) { - return ONLP_STATUS_E_INVALID; - } - - /* Reading serial number */ - offset = data[block1_start] * multiplier + serial_offset; - strncpy(info->serial, (char *)&data[offset], serial_len); - - /* Reading part number */ - offset += serial_len; - strncpy(info->model, (char *)&data[offset], part_len); - - /* Reading fan direction */ - if (data[block2_start + 1] != block2_type) { - return ONLP_STATUS_E_INVALID; - } - offset = data[block2_start] * multiplier + fan_offset; - temp = data[offset]; - switch (temp) { - case 1: - info->caps |= ONLP_FAN_CAPS_F2B; - break; - case 2: - info->caps |= ONLP_FAN_CAPS_B2F; - break; - default: - break; - } - - return ONLP_STATUS_OK; -} - -static int -_onlp_fani_info_get_fan(int local_id, onlp_fan_info_t* info) -{ - int len = 0, nbytes = 10; - float range = 0; - float temp = 0; - float fru_index = 0; - char r_data[10] = {0}; - char fullpath[65] = {0}; - - /* We have 4 FRU with 2 fans(total 8 fans). - Eeprom is per FRU but not per fan. - So, need to convert fan ID to FRU ID.*/ - if (local_id % 2) { - fru_index = local_id / 2 + 1; - } else { - fru_index = local_id / 2; - } - - /* get fan status - */ - snprintf(fullpath, sizeof(fullpath), "%s%s", PREFIX_MODULE_PATH, fan_path[(int)fru_index].status); - OPEN_READ_FILE(fullpath, r_data, nbytes, len); - if (atoi(r_data) != FAN_STATUS_OK) { - info->status &= ~ONLP_FAN_STATUS_PRESENT; - return ONLP_STATUS_OK; - } - info->status |= ONLP_FAN_STATUS_PRESENT; - - /* get fan speed - */ - snprintf(fullpath, sizeof(fullpath), "%s%s", PREFIX_PATH, fan_path[local_id].r_speed_get); - OPEN_READ_FILE(fullpath, r_data, nbytes, len); - info->rpm = atoi(r_data); - - /* check failure */ - if (info->rpm <= 0) { - info->status |= ONLP_FAN_STATUS_FAILED; - return ONLP_STATUS_OK; - } - - if (ONLP_FAN_CAPS_GET_PERCENTAGE & info->caps) { - /* get fan min speed - */ - snprintf(fullpath, sizeof(fullpath), "%s%s", PREFIX_PATH, fan_path[local_id].min); - OPEN_READ_FILE(fullpath, r_data, nbytes, len); - min_fan_speed[local_id] = atoi(r_data); - - /* get fan max speed - */ - snprintf(fullpath, sizeof(fullpath), "%s%s", PREFIX_PATH, fan_path[local_id].max); - OPEN_READ_FILE(fullpath, r_data, nbytes, len); - max_fan_speed[local_id] = atoi(r_data); - - /* get speed percentage from rpm */ - range = max_fan_speed[local_id] - min_fan_speed[local_id]; - if (range > 0) { - temp = ((float)info->rpm - (float)min_fan_speed[local_id]) / range * 40.0 + 60.0; - if (temp < PERCENTAGE_MIN) { - temp = PERCENTAGE_MIN; - } - info->percentage = (int)temp; - } else { - return ONLP_STATUS_E_INTERNAL; - } - } - - return _onlp_fani_read_fan_eeprom(local_id, info); -} - -static int -_onlp_fani_info_get_fan_on_psu(int local_id, int psu_id, onlp_fan_info_t* info) -{ - int len = 0, nbytes = 10; - char r_data[10] = {0}; - char fullpath[80] = {0}; - float rpms_per_perc = 0.0; - float temp = 0.0; - - /* get fan status - */ - snprintf(fullpath, sizeof(fullpath), "%s%s", PREFIX_MODULE_PATH, fan_path[local_id].status); - OPEN_READ_FILE(fullpath, r_data, nbytes, len); - if (atoi(r_data) != FAN_STATUS_OK) { - info->status &= ~ONLP_FAN_STATUS_PRESENT; - return ONLP_STATUS_OK; - } - info->status |= ONLP_FAN_STATUS_PRESENT; - - /* get fan speed - */ - snprintf(fullpath, sizeof(fullpath), "%s%s", PREFIX_PATH, fan_path[local_id].r_speed_get); - OPEN_READ_FILE(fullpath, r_data, nbytes, len); - info->rpm = atoi(r_data); - - /* check failure */ - if (info->rpm <= 0) { - info->status |= ONLP_FAN_STATUS_FAILED; - return ONLP_STATUS_OK; - } - - /* get speed percentage from rpm */ - rpms_per_perc = PSU_FAN_RPM_MIN / PERCENTAGE_MIN; - temp = (float)info->rpm / rpms_per_perc; - if (temp < PERCENTAGE_MIN) { - temp = PERCENTAGE_MIN; - } - info->percentage = (int)temp; - - /* Serial number and model for PSU fan is the same as for appropriate PSU */ - if (FAN_1_ON_PSU1 == local_id) { - if (0 != psu_read_eeprom(PSU1_ID, NULL, info)) - return ONLP_STATUS_E_INTERNAL; - } else if (FAN_1_ON_PSU2 == local_id) { - if (0 != psu_read_eeprom(PSU2_ID, NULL, info)) - return ONLP_STATUS_E_INTERNAL; - } - - return ONLP_STATUS_OK; -} - /* * This function will be called prior to all of onlp_fani_* functions. */ int onlp_fani_init(void) { + mlnx_platform_info_t* mlnx_platform_info = get_platform_info(); + mlnx_platform_info->min_fan_speed=min_fan_speed; + mlnx_platform_info->max_fan_speed=max_fan_speed; + mlnx_platform_info->finfo = finfo; + mlnx_platform_info->fan_fnames = fan_path; + mlnx_platform_info->fan_type = FAN_TYPE_EEPROM; + mlnx_platform_info->first_psu_fan_id = FIRST_PSU_FAN_ID; return ONLP_STATUS_OK; } - -int -onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* info) -{ - int rc = 0; - int local_id = 0; - VALIDATE(id); - - local_id = ONLP_OID_ID_GET(id); - - *info = linfo[local_id]; - - switch (local_id) - { - case FAN_1_ON_PSU1: - rc = _onlp_fani_info_get_fan_on_psu(local_id, PSU1_ID, info); - break; - case FAN_1_ON_PSU2: - rc = _onlp_fani_info_get_fan_on_psu(local_id, PSU2_ID, info); - break; - case FAN_1_ON_MAIN_BOARD: - case FAN_2_ON_MAIN_BOARD: - case FAN_3_ON_MAIN_BOARD: - case FAN_4_ON_MAIN_BOARD: - case FAN_5_ON_MAIN_BOARD: - case FAN_6_ON_MAIN_BOARD: - case FAN_7_ON_MAIN_BOARD: - case FAN_8_ON_MAIN_BOARD: - rc =_onlp_fani_info_get_fan(local_id, info); - break; - default: - rc = ONLP_STATUS_E_INVALID; - 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) -{ - float temp = 0.0; - int rv = 0, local_id = 0, nbytes = 10; - char r_data[10] = {0}; - onlp_fan_info_t* info = NULL; - - VALIDATE(id); - - local_id = ONLP_OID_ID_GET(id); - info = &linfo[local_id]; - - if (0 == (ONLP_FAN_CAPS_SET_RPM & info->caps)) { - return ONLP_STATUS_E_UNSUPPORTED; - } - - /* reject rpm=0% (rpm=0%, stop fan) */ - if (0 == rpm) { - return ONLP_STATUS_E_INVALID; - } - - /* Set fan speed - Converting percent to driver value. - Driver accept value in range between 153 and 255. - Value 153 is minimum rpm. - Value 255 is maximum rpm. - */ - if (local_id > sizeof(min_fan_speed)/sizeof(min_fan_speed[0])) { - return ONLP_STATUS_E_INTERNAL; - } - if (max_fan_speed[local_id] - min_fan_speed[local_id] < 0) { - return ONLP_STATUS_E_INTERNAL; - } - if (rpm < min_fan_speed[local_id] || rpm > max_fan_speed[local_id]) { - return ONLP_STATUS_E_PARAM; - } - - temp = (rpm - min_fan_speed[local_id]) * (RPM_MAGIC_MAX - RPM_MAGIC_MIN) / - (max_fan_speed[local_id] - min_fan_speed[local_id]) + RPM_MAGIC_MIN; - - snprintf(r_data, sizeof(r_data), "%d", (int)temp); - nbytes = strnlen(r_data, sizeof(r_data)); - rv = onlp_file_write((uint8_t*)r_data, nbytes, "%s%s", PREFIX_PATH, - fan_path[local_id].r_speed_set); - if (rv < 0) { - return ONLP_STATUS_E_INTERNAL; - } - - return ONLP_STATUS_OK; -} - -/* - * 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) -{ - float temp = 0.0; - int rv = 0, local_id = 0, nbytes = 10; - char r_data[10] = {0}; - onlp_fan_info_t* info = NULL; - - VALIDATE(id); - local_id = ONLP_OID_ID_GET(id); - info = &linfo[local_id]; - - if (0 == (ONLP_FAN_CAPS_SET_PERCENTAGE & info->caps)) { - return ONLP_STATUS_E_UNSUPPORTED; - } - - /* reject p=0% (p=0%, stop fan) */ - if (0 == p) { - return ONLP_STATUS_E_INVALID; - } - - if (p < PERCENTAGE_MIN || p > PERCENTAGE_MAX) { - return ONLP_STATUS_E_PARAM; - } - - /* Set fan speed - Converting percent to driver value. - Driver accept value in range between 153 and 255. - Value 153 is 60%. - Value 255 is 100%. - */ - temp = (p - PERCENTAGE_MIN) * (RPM_MAGIC_MAX - RPM_MAGIC_MIN) / - (PERCENTAGE_MAX - PERCENTAGE_MIN) + RPM_MAGIC_MIN; - - snprintf(r_data, sizeof(r_data), "%d", (int)temp); - nbytes = strnlen(r_data, sizeof(r_data)); - rv = onlp_file_write((uint8_t*)r_data, nbytes, "%s%s", PREFIX_PATH, - fan_path[local_id].r_speed_set); - if (rv < 0) { - 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; -} - -int -onlp_fani_get_min_rpm(int id) -{ - int len = 0, nbytes = 10; - char r_data[10] = {0}; - - if (onlp_file_read((uint8_t*)r_data, nbytes, &len, "%s%s", PREFIX_PATH, fan_path[id].min) < 0) - return ONLP_STATUS_E_INTERNAL; - - return atoi(r_data); -} diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/ledi.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/ledi.c index 74386ff0..7fdb1f37 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/ledi.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/ledi.c @@ -30,101 +30,9 @@ #include #include #include "platform_lib.h" +#include -#define prefix_path "/bsp/led/led_" -#define driver_value_len 50 - -#define LED_MODE_OFF "none" -#define LED_MODE_GREEN "green" -#define LED_MODE_RED "red" -#define LED_MODE_BLUE "blue" -#define LED_MODE_GREEN_BLINK "green_blink" -#define LED_MODE_RED_BLINK "red_blink" -#define LED_MODE_BLUE_BLINK "blue_blink" -#define LED_MODE_AUTO "cpld_control" - -#define LED_BLINK_PERIOD "100" -#define LED_ON "1" -#define LED_OFF "0" -#define LED_BLINK_PERIOD_LEN 3 -#define LED_MODE_LEN 1 - -#define VALIDATE(_id) \ - do { \ - if(!ONLP_OID_IS_LED(_id)) { \ - return ONLP_STATUS_E_INVALID; \ - } \ - } while(0) - -/* LED related data - */ - -typedef struct led_light_mode_map { - enum onlp_led_id id; - char* driver_led_mode; - enum onlp_led_mode_e onlp_led_mode; -} led_light_mode_map_t; - -led_light_mode_map_t led_map[] = { -{LED_SYSTEM, LED_MODE_OFF, ONLP_LED_MODE_OFF}, -{LED_SYSTEM, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, -{LED_SYSTEM, LED_MODE_RED, ONLP_LED_MODE_RED}, -{LED_SYSTEM, LED_MODE_RED_BLINK, ONLP_LED_MODE_RED_BLINKING}, -{LED_SYSTEM, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, -{LED_SYSTEM, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, - -{LED_FAN1, LED_MODE_OFF, ONLP_LED_MODE_OFF}, -{LED_FAN1, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, -{LED_FAN1, LED_MODE_RED, ONLP_LED_MODE_RED}, -{LED_FAN1, LED_MODE_RED_BLINK, ONLP_LED_MODE_RED_BLINKING}, -{LED_FAN1, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, -{LED_FAN1, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, - -{LED_FAN2, LED_MODE_OFF, ONLP_LED_MODE_OFF}, -{LED_FAN2, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, -{LED_FAN2, LED_MODE_RED, ONLP_LED_MODE_RED}, -{LED_FAN2, LED_MODE_RED_BLINK, ONLP_LED_MODE_RED_BLINKING}, -{LED_FAN2, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, -{LED_FAN2, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, - -{LED_FAN3, LED_MODE_OFF, ONLP_LED_MODE_OFF}, -{LED_FAN3, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, -{LED_FAN3, LED_MODE_RED, ONLP_LED_MODE_RED}, -{LED_FAN3, LED_MODE_RED_BLINK, ONLP_LED_MODE_RED_BLINKING}, -{LED_FAN3, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, -{LED_FAN3, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, - -{LED_FAN4, LED_MODE_OFF, ONLP_LED_MODE_OFF}, -{LED_FAN4, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, -{LED_FAN4, LED_MODE_RED, ONLP_LED_MODE_RED}, -{LED_FAN4, LED_MODE_RED_BLINK, ONLP_LED_MODE_RED_BLINKING}, -{LED_FAN4, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, -{LED_FAN4, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, - -{LED_PSU, LED_MODE_OFF, ONLP_LED_MODE_OFF}, -{LED_PSU, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, -{LED_PSU, LED_MODE_RED, ONLP_LED_MODE_RED}, -{LED_PSU, LED_MODE_RED_BLINK, ONLP_LED_MODE_RED_BLINKING}, -{LED_PSU, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, -{LED_PSU, LED_MODE_AUTO, ONLP_LED_MODE_AUTO} -}; - -typedef struct led_colors { - enum onlp_led_id id; - const char* color1; - const char* color2; -} led_colors_t; - -static led_colors_t led_colors_map[] = { - {LED_SYSTEM, "green", "red"}, - {LED_FAN1, "green", "red"}, - {LED_FAN2, "green", "red"}, - {LED_FAN3, "green", "red"}, - {LED_FAN4, "green", "red"}, - {LED_PSU, "green", "red"}, -}; - -static char file_names[][10] = /* must map with onlp_led_id */ +static char* file_names[] = /* must map with onlp_led_id */ { "reserved", "status", @@ -179,213 +87,11 @@ static onlp_led_info_t linfo[] = } }; -static int driver_to_onlp_led_mode(enum onlp_led_id id, char* driver_led_mode) -{ - char *pos; - int i, nsize = sizeof(led_map)/sizeof(led_map[0]); - - if ((pos=strchr(driver_led_mode, '\n')) != NULL) - *pos = '\0'; - for (i = 0; i < nsize; i++) - { - if (id == led_map[i].id && - !strncmp(led_map[i].driver_led_mode, driver_led_mode, driver_value_len)) - { - return led_map[i].onlp_led_mode; - } - } - - return 0; -} - -static char* onlp_to_driver_led_mode(enum onlp_led_id id, onlp_led_mode_t onlp_led_mode) -{ - int i, nsize = sizeof(led_map)/sizeof(led_map[0]); - - for (i = 0; i < nsize; i++) - { - if (id == led_map[i].id && onlp_led_mode == led_map[i].onlp_led_mode) - { - return led_map[i].driver_led_mode; - } - } - - return LED_MODE_OFF; -} - -static int led_set_mode(onlp_oid_t id, onlp_led_mode_t mode) -{ - int local_id = ONLP_OID_ID_GET(id); - char color[10]={0}; - int blinking = 0; - - switch (mode) { - case ONLP_LED_MODE_RED_BLINKING: - strcpy(color, "red"); - blinking = 1; - break; - case ONLP_LED_MODE_GREEN_BLINKING: - strcpy(color, "green"); - blinking = 1; - break; - case ONLP_LED_MODE_BLUE_BLINKING: - strcpy(color, "blue"); - blinking = 1; - break; - case ONLP_LED_MODE_YELLOW_BLINKING: - strcpy(color, "yellow"); - blinking = 1; - break; - case ONLP_LED_MODE_RED: - strcpy(color, "red"); - break; - case ONLP_LED_MODE_GREEN: - strcpy(color, "green"); - break; - case ONLP_LED_MODE_BLUE: - strcpy(color, "blue"); - break; - case ONLP_LED_MODE_YELLOW: - strcpy(color, "yellow"); - break; - default: - return ONLP_STATUS_E_PARAM; - } - - if (blinking) { - onlp_file_write((uint8_t*)LED_BLINK_PERIOD, LED_BLINK_PERIOD_LEN, - "%s%s_%s_delay_off", prefix_path, file_names[local_id], color); - onlp_file_write((uint8_t*)LED_BLINK_PERIOD, LED_BLINK_PERIOD_LEN, - "%s%s_%s_delay_on", prefix_path, file_names[local_id], color); - } - onlp_file_write((uint8_t*)LED_ON, LED_MODE_LEN, - "%s%s_%s", prefix_path, file_names[local_id], color); - - return ONLP_STATUS_OK; -} - -/* - * This function will be called prior to any other onlp_ledi_* functions. - */ int onlp_ledi_init(void) { - /* - * ONLPD calls it too early before all BSP insfrastructure is set - */ - + mlnx_platform_info_t* mlnx_platform_info = get_platform_info(); + mlnx_platform_info->linfo = linfo; + mlnx_platform_info->led_fnames = file_names; return ONLP_STATUS_OK; } - -int -onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) -{ - int len, local_id = 0; - uint8_t data[driver_value_len] = {0}; - - VALIDATE(id); - - local_id = ONLP_OID_ID_GET(id); - - /* Set the onlp_oid_hdr_t and capabilities */ - *info = linfo[ONLP_OID_ID_GET(id)]; - - /* Get LED mode */ - if (onlp_get_kernel_ver() >= KERNEL_VERSION(4,9,30)) { - char* cmd = aim_fstrdup("%s%s_state", prefix_path, file_names[local_id]); - if(system(cmd) != 0) { - aim_free(cmd); - return ONLP_STATUS_E_INTERNAL; - } - aim_free(cmd); - } - - if (onlp_file_read(data, sizeof(data), &len, "%s%s", - prefix_path, file_names[local_id]) != 0) { - return ONLP_STATUS_E_INTERNAL; - } - - info->mode = driver_to_onlp_led_mode(local_id, (char*)data); - - /* Set the on/off status */ - if (info->mode != ONLP_LED_MODE_OFF) { - info->status |= ONLP_LED_STATUS_ON; - } - - return ONLP_STATUS_OK; -} - -/* - * Turn an LED on or off. - * - * This function will only be called if the LED OID supports the ONOFF - * capability. - * - * What 'on' means in terms of colors or modes for multimode LEDs is - * up to the platform to decide. This is intended as baseline toggle mechanism. - */ -int -onlp_ledi_set(onlp_oid_t id, int on_or_off) -{ - VALIDATE(id); - - if (!on_or_off) { - if (onlp_get_kernel_ver() < KERNEL_VERSION(4,9,30)) - return onlp_ledi_mode_set(id, ONLP_LED_MODE_OFF); - else { - int i, nsize = sizeof(led_colors_map)/sizeof(led_colors_map[0]); - for (i = 0; i < nsize; i++) - { - if (id == led_colors_map[i].id) - break; - } - if (led_colors_map[i].color1) - onlp_file_write((uint8_t*)LED_OFF, LED_MODE_LEN, - "%s%s_%s", prefix_path, file_names[id], led_colors_map[i].color1); - } - } - - return ONLP_STATUS_E_UNSUPPORTED; -} - -/* - * This function puts the LED into the given mode. It is a more functional - * interface for multimode LEDs. - * - * Only modes reported in the LED's capabilities will be attempted. - */ -int -onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) -{ - int local_id; - char* driver_led_mode; - int nbytes; - - VALIDATE(id); - - if (onlp_get_kernel_ver() < KERNEL_VERSION(4,9,30)) { - local_id = ONLP_OID_ID_GET(id); - driver_led_mode = onlp_to_driver_led_mode(local_id, mode); - nbytes = strnlen(driver_led_mode, driver_value_len); - if (onlp_file_write((uint8_t*)driver_led_mode, nbytes, - "%s%s", prefix_path, file_names[local_id]) != 0) { - return ONLP_STATUS_E_INTERNAL; - } - } else { - if (led_set_mode(id, mode) != 0) { - return ONLP_STATUS_E_INTERNAL; - } - } - - return ONLP_STATUS_OK; -} - -/* - * Generic LED ioctl interface. - */ -int -onlp_ledi_ioctl(onlp_oid_t id, va_list vargs) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/platform_lib.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/platform_lib.c deleted file mode 100644 index 5035bc48..00000000 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/platform_lib.c +++ /dev/null @@ -1,109 +0,0 @@ -/************************************************************ - * - * - * Copyright 2014 Big Switch Networks, Inc. - * - * 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 -#include -#include -#include -#include -#include "platform_lib.h" - -int -psu_read_eeprom(int psu_index, onlp_psu_info_t* psu_info, onlp_fan_info_t* fan_info) -{ - const char sanity_check[] = "MLNX"; - const uint8_t serial_len = 24; - char data[256] = {0}; - bool sanity_found = false; - int index = 0, rv = 0, len = 0; - - rv = onlp_file_read((uint8_t* )data, sizeof(data)-1, &len, - IDPROM_PATH, "psu", psu_index); - if (rv < 0) { - return ONLP_STATUS_E_INTERNAL; - } - - /* Looking for sanity checker */ - while (index < sizeof(data) - sizeof(sanity_check) - 1) { - if (!strncmp(&data[index], sanity_check, sizeof(sanity_check) - 1)) { - sanity_found = true; - break; - } - index++; - } - if (false == sanity_found) { - return ONLP_STATUS_E_INVALID; - } - - /* Serial number */ - index += strlen(sanity_check); - if (psu_info) { - strncpy(psu_info->serial, &data[index], sizeof(psu_info->serial)); - } else if (fan_info) { - strncpy(fan_info->serial, &data[index], sizeof(fan_info->serial)); - } - - /* Part number */ - index += serial_len; - if (psu_info) { - strncpy(psu_info->model, &data[index], sizeof(psu_info->model)); - } else if (fan_info) { - strncpy(fan_info->model, &data[index], sizeof(fan_info->model)); - } - - return ONLP_STATUS_OK; -} - -int -onlp_get_kernel_ver() -{ - struct utsname buff; - char ver[4]; - char *p; - int i = 0; - - if (uname(&buff) != 0) - return ONLP_STATUS_E_INTERNAL; - - p = buff.release; - - while (*p) { - if (isdigit(*p)) { - ver[i] = strtol(p, &p, 10); - i++; - if (i >= 3) - break; - } else { - p++; - } - } - - return KERNEL_VERSION(ver[0], ver[1], ver[2]); -} diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/platform_lib.h b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/platform_lib.h index 80b9faa8..1895605c 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/platform_lib.h +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/platform_lib.h @@ -25,8 +25,6 @@ #ifndef __PLATFORM_LIB_H__ #define __PLATFORM_LIB_H__ -#include -#include #include "x86_64_mlnx_msn2410_log.h" #define CHASSIS_PSU_COUNT 2 @@ -34,43 +32,8 @@ #define CHASSIS_TOTAL_THERMAL_COUNT 8 #define CHASSIS_FAN_COUNT (CHASSIS_TOTAL_FAN_COUNT - CHASSIS_PSU_COUNT) #define CHASSIS_THERMAL_COUNT (CHASSIS_TOTAL_THERMAL_COUNT - CHASSIS_PSU_COUNT) - -#define PSU1_ID 1 -#define PSU2_ID 2 - -#define PSU_MODULE_PREFIX "/bsp/module/psu%d_%s" -#define PSU_POWER_PREFIX "/bsp/power/psu%d_%s" -#define IDPROM_PATH "/bsp/eeprom/%s%d_info" - -#ifndef KERNEL_VERSION -#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) -#endif - -/* LED related data - */ -enum onlp_led_id -{ - LED_RESERVED = 0, - LED_SYSTEM, - LED_FAN1, - LED_FAN2, - LED_FAN3, - LED_FAN4, - LED_PSU, -}; - -typedef enum psu_type { - PSU_TYPE_UNKNOWN, - PSU_TYPE_AC_F2B, - PSU_TYPE_AC_B2F -} psu_type_t; - -psu_type_t get_psu_type(int id, char* modelname, int modelname_len); - -int psu_read_eeprom(int psu_index, onlp_psu_info_t* psu_info, - onlp_fan_info_t* fan_info); - -int onlp_fani_get_min_rpm(int id); -int onlp_get_kernel_ver(void); +#define CHASSIS_LED_COUNT 6 +#define SFP_PORT_COUNT 56 +#define CPLD_COUNT 3 #endif /* __PLATFORM_LIB_H__ */ diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/sfpi.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/sfpi.c deleted file mode 100644 index e2c3f56d..00000000 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/sfpi.c +++ /dev/null @@ -1,262 +0,0 @@ -/************************************************************ - * - * - * Copyright 2014 Big Switch Networks, Inc. - * - * 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 /* For O_RDWR && open */ -#include -#include -#include -#include -#include -#include -#include -#include "platform_lib.h" - -#define MAX_SFP_PATH 64 -#define SFP_SYSFS_VALUE_LEN 20 -static char sfp_node_path[MAX_SFP_PATH] = {0}; -#define NUM_OF_SFP_PORT 56 -#define SFP_PRESENT_STATUS "good" -#define SFP_NOT_PRESENT_STATUS "not_connected" - -static int -msn2410_sfp_node_read_int(char *node_path, int *value) -{ - int data_len = 0, ret = 0; - char buf[SFP_SYSFS_VALUE_LEN] = {0}; - *value = -1; - char sfp_present_status[16]; - char sfp_not_present_status[16]; - - if (onlp_get_kernel_ver() >= KERNEL_VERSION(4,9,30)) { - strcpy(sfp_present_status, "1"); - strcpy(sfp_not_present_status, "0"); - } else { - strcpy(sfp_present_status, "good"); - strcpy(sfp_not_present_status, "not_connected"); - } - - ret = onlp_file_read((uint8_t*)buf, sizeof(buf), &data_len, node_path); - - if (ret == 0) { - if (!strncmp(buf, sfp_present_status, strlen(sfp_present_status))) { - *value = 1; - } else if (!strncmp(buf, sfp_not_present_status, strlen(sfp_not_present_status))) { - *value = 0; - } - } - - return ret; -} - -static char* -msn2410_sfp_get_port_path(int port, char *node_name) -{ - if (node_name) - sprintf(sfp_node_path, "/bsp/qsfp/qsfp%d%s", port, node_name); - else - sprintf(sfp_node_path, "/bsp/qsfp/qsfp%d", port); - return sfp_node_path; -} - -static char* -sn2410_sfp_convert_i2c_path(int port, int devaddr) -{ - sprintf(sfp_node_path, "/bsp/qsfp/qsfp%d", port); - return sfp_node_path; -} - -/************************************************************ - * - * SFPI Entry Points - * - ***********************************************************/ -int -onlp_sfpi_init(void) -{ - /* Called at initialization time */ - return ONLP_STATUS_OK; -} - -int -onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap) -{ - /* - * Ports {1, 32} - */ - int p = 1; - AIM_BITMAP_CLR_ALL(bmap); - - for (; p <= NUM_OF_SFP_PORT; p++) { - AIM_BITMAP_SET(bmap, p); - } - - return ONLP_STATUS_OK; -} - -int -onlp_sfpi_is_present(int port) -{ - /* - * Return 1 if present. - * Return 0 if not present. - * Return < 0 if error. - */ - int present = -1; - char* path = msn2410_sfp_get_port_path(port, "_status"); - - if (msn2410_sfp_node_read_int(path, &present) != 0) { - AIM_LOG_ERROR("Unable to read present status from port(%d)\r\n", port); - return ONLP_STATUS_E_INTERNAL; - } - - return present; -} - -int -onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) -{ - int ii = 1; - int rc = 0; - - for (;ii <= NUM_OF_SFP_PORT; ii++) { - rc = onlp_sfpi_is_present(ii); - AIM_BITMAP_MOD(dst, ii, (1 == rc) ? 1 : 0); - } - - return ONLP_STATUS_OK; -} - -int -onlp_sfpi_eeprom_read(int port, uint8_t data[256]) -{ - char* path = msn2410_sfp_get_port_path(port, NULL); - - /* - * Read the SFP eeprom into data[] - * - * Return MISSING if SFP is missing. - * Return OK if eeprom is read - */ - memset(data, 0, 256); - - if (onlplib_sfp_eeprom_read_file(path, data) != 0) { - AIM_LOG_ERROR("Unable to read eeprom from port(%d)\r\n", port); - return ONLP_STATUS_E_INTERNAL; - } - - return ONLP_STATUS_OK; -} - -int -onlp_sfpi_dev_readb(int port, uint8_t devaddr, uint8_t addr) -{ - char* path = sn2410_sfp_convert_i2c_path(port, devaddr); - uint8_t data; - int fd; - int nrd; - - if (!path) - return ONLP_STATUS_E_MISSING; - - fd = open(path, O_RDONLY); - if (fd < 0) - return ONLP_STATUS_E_MISSING; - - lseek(fd, addr, SEEK_SET); - nrd = read(fd, &data, 1); - close(fd); - - if (nrd != 1) { - AIM_LOG_INTERNAL("Failed to read EEPROM file '%s'", path); - return ONLP_STATUS_E_INTERNAL; - } - return data; -} - -int -onlp_sfpi_dev_writeb(int port, uint8_t devaddr, uint8_t addr, uint8_t value) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - -int -onlp_sfpi_dev_readw(int port, uint8_t devaddr, uint8_t addr) -{ - char* path = sn2410_sfp_convert_i2c_path(port, devaddr); - uint16_t data; - int fd; - int nrd; - - if (!path){ - return ONLP_STATUS_E_MISSING; - } - - fd = open(path, O_RDONLY); - if (fd < 0) { - return ONLP_STATUS_E_MISSING; - } - - lseek(fd, addr, SEEK_SET); - nrd = read(fd, &data, 2); - close(fd); - - if (nrd != 2) { - AIM_LOG_INTERNAL("Failed to read EEPROM file '%s'", path); - return ONLP_STATUS_E_INTERNAL; - } - return data; -} - -int -onlp_sfpi_dev_writew(int port, uint8_t devaddr, uint8_t addr, uint16_t value) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - -int -onlp_sfpi_control_supported(int port, onlp_sfp_control_t control, int* rv) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - -int -onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - -int -onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - -int -onlp_sfpi_denit(void) -{ - return ONLP_STATUS_OK; -} - diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/sysi.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/sysi.c index 0e9f2549..6ee04ede 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/sysi.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/sysi.c @@ -35,205 +35,54 @@ #include "platform_lib.h" #include "x86_64_mlnx_msn2410_int.h" #include "x86_64_mlnx_msn2410_log.h" +#include -#define ONL_PLATFORM_NAME "x86-64-mlnx-msn2410-r0" -#define ONIE_PLATFORM_NAME "x86-64-mlnx_msn2410-r0" - -#define NUM_OF_THERMAL_ON_MAIN_BROAD CHASSIS_THERMAL_COUNT -#define NUM_OF_FAN_ON_MAIN_BROAD CHASSIS_FAN_COUNT -#define NUM_OF_PSU_ON_MAIN_BROAD 2 -#define NUM_OF_LED_ON_MAIN_BROAD 6 +static const char* __ONL_PLATFORM_NAME = NULL; #define COMMAND_OUTPUT_BUFFER 256 -#define PREFIX_PATH_ON_CPLD_DEV "/bsp/cpld" -#define NUM_OF_CPLD 3 -static char arr_cplddev_name[NUM_OF_CPLD][30] = +int mc_get_platform_info(mlnx_platform_info_t* mlnx_platform) { - "cpld_brd_version", - "cpld_mgmt_version", - "cpld_port_version" -}; - -const char* -onlp_sysi_platform_get(void) -{ - return ONL_PLATFORM_NAME; -} - -int -onlp_sysi_platform_info_get(onlp_platform_info_t* pi) -{ - int i, v[NUM_OF_CPLD]={0}; - - for (i=0; i < NUM_OF_CPLD; i++) { - v[i] = 0; - if(onlp_file_read_int(v+i, "%s/%s", PREFIX_PATH_ON_CPLD_DEV, arr_cplddev_name[i]) < 0) { - return ONLP_STATUS_E_INTERNAL; - } - } - pi->cpld_versions = aim_fstrdup("brd=%d, mgmt=%d, port=%d", v[0], v[1], v[2]); - - return ONLP_STATUS_OK; -} - -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) -{ - int i; - onlp_oid_t* e = table; - memset(table, 0, max*sizeof(onlp_oid_t)); - - /* 8 Thermal sensors on the chassis */ - for (i = 1; i <= NUM_OF_THERMAL_ON_MAIN_BROAD; i++) - { - *e++ = ONLP_THERMAL_ID_CREATE(i); - } - - /* 6 LEDs on the chassis */ - for (i = 1; i <= NUM_OF_LED_ON_MAIN_BROAD; i++) - { - *e++ = ONLP_LED_ID_CREATE(i); - } - - /* 2 PSUs on the chassis */ - for (i = 1; i <= NUM_OF_PSU_ON_MAIN_BROAD; i++) - { - *e++ = ONLP_PSU_ID_CREATE(i); - } - - /* 8 Fans and 2 PSU fans on the chassis */ - for (i = 1; i <= NUM_OF_FAN_ON_MAIN_BROAD; i++) - { - *e++ = ONLP_FAN_ID_CREATE(i); - } - - return 0; -} - -int -onlp_sysi_onie_info_get(onlp_onie_info_t* onie) -{ - int rv = onlp_onie_read_json(onie, - "/lib/platform-config/current/onl/etc/onie/eeprom.json"); - if(rv >= 0) { - if(onie->platform_name) { - aim_free(onie->platform_name); - } - onie->platform_name = aim_strdup(ONIE_PLATFORM_NAME); - } - - return rv; -} - -int -onlp_sysi_platform_manage_leds(void) -{ - int fan_number, psu_number; - onlp_led_mode_t mode, system_mode; - int min_fan_speed; - enum onlp_led_id fan_led_id[4] = { LED_FAN1, LED_FAN2, LED_FAN3, LED_FAN4 }; - int fan_problem = 0; - int psu_problem = 0; - - /* - * FAN Indicators - * - * Green - Fan is operating - * Red - No power or Fan failure - * Off - No power - * - */ - for( fan_number = 1; fan_number <= CHASSIS_FAN_COUNT; fan_number+=2) - { - /* each 2 fans had same led_fan */ - onlp_fan_info_t fi; - /* check fans */ - mode = ONLP_LED_MODE_GREEN; - if(onlp_fani_info_get(ONLP_FAN_ID_CREATE(fan_number), &fi) < 0) { - mode = ONLP_LED_MODE_RED; - fan_problem = 1; - } - else if( (fi.status & ONLP_FAN_STATUS_PRESENT) == 0) { - /* Not present */ - mode = ONLP_LED_MODE_RED; - fan_problem = 1; - } - else if(fi.status & ONLP_FAN_STATUS_FAILED) { - mode = ONLP_LED_MODE_RED; - fan_problem = 1; - } - else - { - min_fan_speed = onlp_fani_get_min_rpm(fan_number); - if( fi.rpm < min_fan_speed) - { - mode = ONLP_LED_MODE_RED; - fan_problem = 1; - } - } - /* check fan i+1 */ - if(onlp_fani_info_get(ONLP_FAN_ID_CREATE(fan_number+1), &fi) < 0) { - mode = ONLP_LED_MODE_RED; - fan_problem = 1; - } - else if( (fi.status & 0x1) == 0) { - /* Not present */ - mode = ONLP_LED_MODE_RED; - fan_problem = 1; - } - else if(fi.status & ONLP_FAN_STATUS_FAILED) { - mode = ONLP_LED_MODE_RED; - fan_problem = 1; - } - else - { - min_fan_speed = onlp_fani_get_min_rpm(fan_number+1); - if( fi.rpm < min_fan_speed) - { - mode = ONLP_LED_MODE_RED; - fan_problem = 1; - } - } - onlp_ledi_mode_set(ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_LED,fan_led_id[fan_number/2]), mode); + if (!__ONL_PLATFORM_NAME) { + strncpy(mlnx_platform->onl_platform_name, "x86-64-mlnx-msn2410-all", PLATFORM_NAME_MAX_LEN); } - - for (psu_number = 1; psu_number <= CHASSIS_PSU_COUNT; psu_number++) - { - onlp_psu_info_t pi; - if(onlp_psui_info_get(ONLP_PSU_ID_CREATE(psu_number), &pi) < 0) { - psu_problem = 1; - } - else if((pi.status & ONLP_PSU_STATUS_PRESENT) == 0) { - /* Not present */ - psu_problem = 1; - } - else if(pi.status & ONLP_PSU_STATUS_UNPLUGGED) { - psu_problem = 1; - } + else { + strncpy(mlnx_platform->onl_platform_name, __ONL_PLATFORM_NAME, PLATFORM_NAME_MAX_LEN); } - - if (psu_problem) - mode = ONLP_LED_MODE_RED; - else - mode = ONLP_LED_MODE_GREEN; - onlp_ledi_mode_set(ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_LED, LED_PSU), mode); - - /* Set System status LED green if no problem in FANs or PSUs */ - if (fan_problem || psu_problem) - system_mode = ONLP_LED_MODE_RED; - else - system_mode = ONLP_LED_MODE_GREEN; - - onlp_ledi_mode_set(ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_LED,LED_SYSTEM), system_mode); + mlnx_platform->sfp_num = SFP_PORT_COUNT; + mlnx_platform->led_num = CHASSIS_LED_COUNT; + mlnx_platform->psu_num = CHASSIS_PSU_COUNT; + mlnx_platform->fan_num = CHASSIS_FAN_COUNT; + mlnx_platform->thermal_num = CHASSIS_THERMAL_COUNT; + mlnx_platform->cpld_num = CPLD_COUNT; + mlnx_platform->psu_fixed = false; + mlnx_platform->fan_fixed = false; + mlnx_platform->psu_type = PSU_TYPE_2; + mlnx_platform->led_type = LED_TYPE_2; return ONLP_STATUS_OK; } +int +onlp_sysi_platform_set(const char* platform) +{ + mlnx_platform_info_t* mlnx_platform; + + if(!strcmp(platform, "x86-64-mlnx-msn2410-r0")) { + __ONL_PLATFORM_NAME = "x86-64-mlnx_msn2410-r0"; + mlnx_platform = get_platform_info(); + mc_get_platform_info(mlnx_platform); + return ONLP_STATUS_OK; + } + if(!strcmp(platform, "x86-64-mlnx-msn2410-all")) { + __ONL_PLATFORM_NAME = "x86-64-mlnx-msn2410-all"; + return ONLP_STATUS_OK; + } + return ONLP_STATUS_E_UNSUPPORTED; +} + +int +onlp_sysi_init(void) +{ + return ONLP_STATUS_OK; +} diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/thermali.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/thermali.c index 7b563eec..82b44635 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/thermali.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/thermali.c @@ -29,45 +29,7 @@ #include #include #include "platform_lib.h" - -#define prefix_path "/bsp/thermal" - -/** CPU thermal_threshold */ -typedef enum cpu_thermal_threshold_e { - CPU_THERMAL_THRESHOLD_WARNING_DEFAULT = 87000, - CPU_THERMAL_THRESHOLD_ERROR_DEFAULT = 100000, - CPU_THERMAL_THRESHOLD_SHUTDOWN_DEFAULT = 105000, -} cpu_thermal_threshold_t; - -/** - * Shortcut for CPU thermal threshold value. - */ -#define CPU_THERMAL_THRESHOLD_INIT_DEFAULTS \ - { CPU_THERMAL_THRESHOLD_WARNING_DEFAULT, \ - CPU_THERMAL_THRESHOLD_ERROR_DEFAULT, \ - CPU_THERMAL_THRESHOLD_SHUTDOWN_DEFAULT } - -/** Asic thermal_threshold */ -typedef enum asic_thermal_threshold_e { - ASIC_THERMAL_THRESHOLD_WARNING_DEFAULT = 105000, - ASIC_THERMAL_THRESHOLD_ERROR_DEFAULT = 115000, - ASIC_THERMAL_THRESHOLD_SHUTDOWN_DEFAULT = 120000, -} asic_thermal_threshold_t; - -/** - * Shortcut for CPU thermal threshold value. - */ -#define ASIC_THERMAL_THRESHOLD_INIT_DEFAULTS \ - { ASIC_THERMAL_THRESHOLD_WARNING_DEFAULT, \ - ASIC_THERMAL_THRESHOLD_ERROR_DEFAULT, \ - ASIC_THERMAL_THRESHOLD_SHUTDOWN_DEFAULT } - -#define VALIDATE(_id) \ - do { \ - if(!ONLP_OID_IS_THERMAL(_id)) { \ - return ONLP_STATUS_E_INVALID; \ - } \ - } while(0) +#include "mlnx_common/mlnx_common.h" enum onlp_thermal_id { @@ -82,7 +44,7 @@ enum onlp_thermal_id THERMAL_ON_PSU2, }; -static char* last_path[] = /* must map with onlp_thermal_id */ +static char* thermal_fnames[] = /* must map with onlp_thermal_id */ { "reserved", "cpu_core0", @@ -96,7 +58,7 @@ static char* last_path[] = /* must map with onlp_thermal_id */ }; /* Static values */ -static onlp_thermal_info_t linfo[] = { +static onlp_thermal_info_t tinfo[] = { { }, /* Not used */ { { ONLP_THERMAL_ID_CREATE(THERMAL_CPU_CORE_0), "CPU Core 0", 0}, ONLP_THERMAL_STATUS_PRESENT, @@ -138,39 +100,9 @@ static onlp_thermal_info_t linfo[] = { int onlp_thermali_init(void) { - return ONLP_STATUS_OK; -} - -/* - * Retrieve the information structure for the given thermal OID. - * - * If the OID is invalid, return ONLP_E_STATUS_INVALID. - * If an unexpected error occurs, return ONLP_E_STATUS_INTERNAL. - * Otherwise, return ONLP_STATUS_OK with the OID's information. - * - * Note -- it is expected that you fill out the information - * 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) -{ - int rv, len = 10, temp_base=1, local_id = 0; - char r_data[10] = {0}; - VALIDATE(id); - - local_id = ONLP_OID_ID_GET(id); - - /* Set the onlp_oid_hdr_t and capabilities */ - *info = linfo[local_id]; - - rv = onlp_file_read((uint8_t*)r_data, sizeof(r_data), &len, - "%s/%s", prefix_path, last_path[local_id]); - if (rv < 0) { - return ONLP_STATUS_E_INTERNAL; - } - - info->mcelsius = atoi(r_data) / temp_base; - + mlnx_platform_info_t* mlnx_platform_info = get_platform_info(); + mlnx_platform_info->tinfo=tinfo; + mlnx_platform_info->thermal_fnames=thermal_fnames; return ONLP_STATUS_OK; } diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/lib/Makefile b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/lib/Makefile index 023532c4..002f4816 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/lib/Makefile +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/lib/Makefile @@ -26,7 +26,7 @@ include $(ONL)/make/config.amd64.mk MODULE := libonlp-x86-64-mlnx-msn2700 include $(BUILDER)/standardinit.mk -DEPENDMODULES := AIM IOF x86_64_mlnx_msn2700 onlplib +DEPENDMODULES := AIM IOF mlnx_common x86_64_mlnx_msn2700 onlplib DEPENDMODULE_HEADERS := sff include $(BUILDER)/dependmodules.mk @@ -37,6 +37,7 @@ include $(BUILDER)/so.mk .DEFAULT_GOAL := $(SHAREDLIB) GLOBAL_CFLAGS += -I$(onlp_BASEDIR)/module/inc +GLOBAL_CFLAGS += -I$(mlnx_common_BASEDIR)/module/inc GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MODULES_INIT=1 GLOBAL_CFLAGS += -fPIC GLOBAL_LINK_LIBS += -lpthread diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/onlpdump/Makefile b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/onlpdump/Makefile index 7087c1be..24d431c7 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/onlpdump/Makefile +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/onlpdump/Makefile @@ -29,7 +29,7 @@ include $(ONL)/make/config.amd64.mk MODULE := onlpdump include $(BUILDER)/standardinit.mk -DEPENDMODULES := AIM IOF onlp x86_64_mlnx_msn2700 onlplib onlp_platform_defaults sff cjson cjson_util timer_wheel OS +DEPENDMODULES := AIM IOF onlp mlnx_common x86_64_mlnx_msn2700 onlplib onlp_platform_defaults sff cjson cjson_util timer_wheel OS include $(BUILDER)/dependmodules.mk diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/fani.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/fani.c index 9abef68f..69914db2 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/fani.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/fani.c @@ -27,22 +27,7 @@ #include #include #include "platform_lib.h" - -#define PREFIX_PATH "/bsp/fan/" -#define PREFIX_MODULE_PATH "/bsp/module/" - -#define FAN_STATUS_OK 1 - -#define PERCENTAGE_MIN 60.0 -#define PERCENTAGE_MAX 100.0 -#define RPM_MAGIC_MIN 153.0 -#define RPM_MAGIC_MAX 255.0 - -#define PSU_FAN_RPM_MIN 11700.0 -#define PSU_FAN_RPM_MAX 19500.0 - -#define PROJECT_NAME -#define LEN_FILE_NAME 80 +#include "mlnx_common/mlnx_common.h" #define FAN_RESERVED 0 #define FAN_1_ON_MAIN_BOARD 1 @@ -56,31 +41,11 @@ #define FAN_1_ON_PSU1 9 #define FAN_1_ON_PSU2 10 +#define FIRST_PSU_FAN_ID 9 + static int min_fan_speed[CHASSIS_FAN_COUNT+1] = {0}; static int max_fan_speed[CHASSIS_FAN_COUNT+1] = {0}; -typedef struct fan_path_S -{ - char status[LEN_FILE_NAME]; - char r_speed_get[LEN_FILE_NAME]; - char r_speed_set[LEN_FILE_NAME]; - char min[LEN_FILE_NAME]; - char max[LEN_FILE_NAME]; -}fan_path_T; - -#define _MAKE_FAN_PATH_ON_MAIN_BOARD(prj,id) \ - { #prj"fan"#id"_status", \ - #prj"fan"#id"_speed_get", \ - #prj"fan"#id"_speed_set", \ - #prj"fan"#id"_min", \ - #prj"fan"#id"_max" } - -#define MAKE_FAN_PATH_ON_MAIN_BOARD(prj,id) _MAKE_FAN_PATH_ON_MAIN_BOARD(prj,id) - -#define MAKE_FAN_PATH_ON_PSU(psu_id, fan_id) \ - {"psu"#psu_id"_status", \ - "psu"#psu_id"_fan"#fan_id"_speed_get", "", "", "",} - static fan_path_T fan_path[] = /* must map with onlp_fan_id */ { MAKE_FAN_PATH_ON_MAIN_BOARD(PROJECT_NAME, FAN_RESERVED), @@ -96,29 +61,8 @@ static fan_path_T fan_path[] = /* must map with onlp_fan_id */ MAKE_FAN_PATH_ON_PSU(2, 1) }; -#define MAKE_FAN_INFO_NODE_ON_MAIN_BOARD(id) \ - { \ - { ONLP_FAN_ID_CREATE(FAN_##id##_ON_MAIN_BOARD), "Chassis Fan "#id, 0 }, \ - 0x0, \ - (ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_GET_PERCENTAGE | \ - ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_SET_RPM), \ - 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 }, \ - 0x0, \ - (ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE), \ - 0, \ - 0, \ - ONLP_FAN_MODE_INVALID, \ - } - /* Static fan information */ -onlp_fan_info_t linfo[] = { +onlp_fan_info_t finfo[] = { { }, /* Not used */ MAKE_FAN_INFO_NODE_ON_MAIN_BOARD(1), MAKE_FAN_INFO_NODE_ON_MAIN_BOARD(2), @@ -132,418 +76,18 @@ 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(fullpath, data, nbytes, len) \ - if (onlp_file_read((uint8_t*)data, nbytes, &len, fullpath) < 0) \ - return ONLP_STATUS_E_INTERNAL; \ - else \ - AIM_LOG_VERBOSE("read data: %s\n", r_data); \ - - -static int -_onlp_fani_read_fan_eeprom(int local_id, onlp_fan_info_t* info) -{ - const char sanity_checker[] = "MLNX"; - const uint8_t sanity_offset = 8; - const uint8_t sanity_len = 4; - const uint8_t block1_start = 12; - const uint8_t block1_type = 1; - const uint8_t block2_start = 14; - const uint8_t block2_type = 5; - const uint8_t serial_offset = 8; - const uint8_t serial_len = 24; - const uint8_t part_len = 20; - const uint8_t fan_offset = 14; - const uint8_t multiplier = 16; - uint8_t data[256] = {0}; - uint8_t offset = 0; - uint8_t temp = 0; - int rv = 0; - int len = 0; - - /* We have 4 FRU with 2 fans(total 8 fans). - Eeprom is per FRU but not per fan. - So, need to convert fan ID to FRU ID.*/ - if (local_id % 2) { - local_id = local_id / 2 + 1; - } else { - local_id /= 2; - } - - rv = onlp_file_read(data, sizeof(data), &len, - IDPROM_PATH, "fan", local_id); - if (rv < 0) { - return ONLP_STATUS_E_INTERNAL; - } - - /* Sanity checker */ - if (strncmp(sanity_checker, (char*)&data[sanity_offset], sanity_len)) { - return ONLP_STATUS_E_INVALID; - } - - /* Checking eeprom block type with S/N and P/N */ - if (data[block1_start + 1] != block1_type) { - return ONLP_STATUS_E_INVALID; - } - - /* Reading serial number */ - offset = data[block1_start] * multiplier + serial_offset; - strncpy(info->serial, (char *)&data[offset], serial_len); - - /* Reading part number */ - offset += serial_len; - strncpy(info->model, (char *)&data[offset], part_len); - - /* Reading fan direction */ - if (data[block2_start + 1] != block2_type) { - return ONLP_STATUS_E_INVALID; - } - offset = data[block2_start] * multiplier + fan_offset; - temp = data[offset]; - switch (temp) { - case 1: - info->caps |= ONLP_FAN_CAPS_F2B; - break; - case 2: - info->caps |= ONLP_FAN_CAPS_B2F; - break; - default: - break; - } - - return ONLP_STATUS_OK; -} - -static int -_onlp_fani_info_get_fan(int local_id, onlp_fan_info_t* info) -{ - int len = 0, nbytes = 10; - float range = 0; - float temp = 0; - float fru_index = 0; - char r_data[10] = {0}; - char fullpath[65] = {0}; - - /* We have 4 FRU with 2 fans(total 8 fans). - Eeprom is per FRU but not per fan. - So, need to convert fan ID to FRU ID.*/ - if (local_id % 2) { - fru_index = local_id / 2 + 1; - } else { - fru_index = local_id / 2; - } - - /* get fan status - */ - snprintf(fullpath, sizeof(fullpath), "%s%s", PREFIX_MODULE_PATH, fan_path[(int)fru_index].status); - OPEN_READ_FILE(fullpath, r_data, nbytes, len); - if (atoi(r_data) != FAN_STATUS_OK) { - info->status &= ~ONLP_FAN_STATUS_PRESENT; - return ONLP_STATUS_OK; - } - info->status |= ONLP_FAN_STATUS_PRESENT; - - /* get fan speed - */ - snprintf(fullpath, sizeof(fullpath), "%s%s", PREFIX_PATH, fan_path[local_id].r_speed_get); - OPEN_READ_FILE(fullpath, r_data, nbytes, len); - info->rpm = atoi(r_data); - - /* check failure */ - if (info->rpm <= 0) { - info->status |= ONLP_FAN_STATUS_FAILED; - return ONLP_STATUS_OK; - } - - if (ONLP_FAN_CAPS_GET_PERCENTAGE & info->caps) { - /* get fan min speed - */ - snprintf(fullpath, sizeof(fullpath), "%s%s", PREFIX_PATH, fan_path[local_id].min); - OPEN_READ_FILE(fullpath, r_data, nbytes, len); - min_fan_speed[local_id] = atoi(r_data); - - /* get fan max speed - */ - snprintf(fullpath, sizeof(fullpath), "%s%s", PREFIX_PATH, fan_path[local_id].max); - OPEN_READ_FILE(fullpath, r_data, nbytes, len); - max_fan_speed[local_id] = atoi(r_data); - - /* get speed percentage from rpm */ - range = max_fan_speed[local_id] - min_fan_speed[local_id]; - if (range > 0) { - temp = ((float)info->rpm - (float)min_fan_speed[local_id]) / range * 40.0 + 60.0; - if (temp < PERCENTAGE_MIN) { - temp = PERCENTAGE_MIN; - } - info->percentage = (int)temp; - } else { - return ONLP_STATUS_E_INTERNAL; - } - } - - return _onlp_fani_read_fan_eeprom(local_id, info); -} - -static int -_onlp_fani_info_get_fan_on_psu(int local_id, int psu_id, onlp_fan_info_t* info) -{ - int len = 0, nbytes = 10; - char r_data[10] = {0}; - char fullpath[80] = {0}; - float rpms_per_perc = 0.0; - float temp = 0.0; - - /* get fan status - */ - snprintf(fullpath, sizeof(fullpath), "%s%s", PREFIX_MODULE_PATH, fan_path[local_id].status); - OPEN_READ_FILE(fullpath, r_data, nbytes, len); - if (atoi(r_data) != FAN_STATUS_OK) { - info->status &= ~ONLP_FAN_STATUS_PRESENT; - return ONLP_STATUS_OK; - } - info->status |= ONLP_FAN_STATUS_PRESENT; - - /* get fan speed - */ - snprintf(fullpath, sizeof(fullpath), "%s%s", PREFIX_PATH, fan_path[local_id].r_speed_get); - OPEN_READ_FILE(fullpath, r_data, nbytes, len); - info->rpm = atoi(r_data); - - /* check failure */ - if (info->rpm <= 0) { - info->status |= ONLP_FAN_STATUS_FAILED; - return ONLP_STATUS_OK; - } - - /* get speed percentage from rpm */ - rpms_per_perc = PSU_FAN_RPM_MIN / PERCENTAGE_MIN; - temp = (float)info->rpm / rpms_per_perc; - if (temp < PERCENTAGE_MIN) { - temp = PERCENTAGE_MIN; - } - info->percentage = (int)temp; - - /* Serial number and model for PSU fan is the same as for appropriate PSU */ - if (FAN_1_ON_PSU1 == local_id) { - if (0 != psu_read_eeprom(PSU1_ID, NULL, info)) - return ONLP_STATUS_E_INTERNAL; - } else if (FAN_1_ON_PSU2 == local_id) { - if (0 != psu_read_eeprom(PSU2_ID, NULL, info)) - return ONLP_STATUS_E_INTERNAL; - } - - return ONLP_STATUS_OK; -} - /* * This function will be called prior to all of onlp_fani_* functions. */ int onlp_fani_init(void) { + mlnx_platform_info_t* mlnx_platform_info = get_platform_info(); + mlnx_platform_info->min_fan_speed=min_fan_speed; + mlnx_platform_info->max_fan_speed=max_fan_speed; + mlnx_platform_info->finfo = finfo; + mlnx_platform_info->fan_fnames = fan_path; + mlnx_platform_info->fan_type = FAN_TYPE_EEPROM; + mlnx_platform_info->first_psu_fan_id = FIRST_PSU_FAN_ID; return ONLP_STATUS_OK; } - -int -onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* info) -{ - int rc = 0; - int local_id = 0; - VALIDATE(id); - - local_id = ONLP_OID_ID_GET(id); - - *info = linfo[local_id]; - - switch (local_id) - { - case FAN_1_ON_PSU1: - rc = _onlp_fani_info_get_fan_on_psu(local_id, PSU1_ID, info); - break; - case FAN_1_ON_PSU2: - rc = _onlp_fani_info_get_fan_on_psu(local_id, PSU2_ID, info); - break; - case FAN_1_ON_MAIN_BOARD: - case FAN_2_ON_MAIN_BOARD: - case FAN_3_ON_MAIN_BOARD: - case FAN_4_ON_MAIN_BOARD: - case FAN_5_ON_MAIN_BOARD: - case FAN_6_ON_MAIN_BOARD: - case FAN_7_ON_MAIN_BOARD: - case FAN_8_ON_MAIN_BOARD: - rc =_onlp_fani_info_get_fan(local_id, info); - break; - default: - rc = ONLP_STATUS_E_INVALID; - 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) -{ - float temp = 0.0; - int rv = 0, local_id = 0, nbytes = 10; - char r_data[10] = {0}; - onlp_fan_info_t* info = NULL; - - VALIDATE(id); - - local_id = ONLP_OID_ID_GET(id); - info = &linfo[local_id]; - - if (0 == (ONLP_FAN_CAPS_SET_RPM & info->caps)) { - return ONLP_STATUS_E_UNSUPPORTED; - } - - /* reject rpm=0% (rpm=0%, stop fan) */ - if (0 == rpm) { - return ONLP_STATUS_E_INVALID; - } - - /* Set fan speed - Converting percent to driver value. - Driver accept value in range between 153 and 255. - Value 153 is minimum rpm. - Value 255 is maximum rpm. - */ - if (local_id > sizeof(min_fan_speed)/sizeof(min_fan_speed[0])) { - return ONLP_STATUS_E_INTERNAL; - } - if (max_fan_speed[local_id] - min_fan_speed[local_id] < 0) { - return ONLP_STATUS_E_INTERNAL; - } - if (rpm < min_fan_speed[local_id] || rpm > max_fan_speed[local_id]) { - return ONLP_STATUS_E_PARAM; - } - - temp = (rpm - min_fan_speed[local_id]) * (RPM_MAGIC_MAX - RPM_MAGIC_MIN) / - (max_fan_speed[local_id] - min_fan_speed[local_id]) + RPM_MAGIC_MIN; - - snprintf(r_data, sizeof(r_data), "%d", (int)temp); - nbytes = strnlen(r_data, sizeof(r_data)); - rv = onlp_file_write((uint8_t*)r_data, nbytes, "%s%s", PREFIX_PATH, - fan_path[local_id].r_speed_set); - if (rv < 0) { - return ONLP_STATUS_E_INTERNAL; - } - - return ONLP_STATUS_OK; -} - -/* - * 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) -{ - float temp = 0.0; - int rv = 0, local_id = 0, nbytes = 10; - char r_data[10] = {0}; - onlp_fan_info_t* info = NULL; - - VALIDATE(id); - local_id = ONLP_OID_ID_GET(id); - info = &linfo[local_id]; - - if (0 == (ONLP_FAN_CAPS_SET_PERCENTAGE & info->caps)) { - return ONLP_STATUS_E_UNSUPPORTED; - } - - /* reject p=0% (p=0%, stop fan) */ - if (0 == p) { - return ONLP_STATUS_E_INVALID; - } - - if (p < PERCENTAGE_MIN || p > PERCENTAGE_MAX) { - return ONLP_STATUS_E_PARAM; - } - - /* Set fan speed - Converting percent to driver value. - Driver accept value in range between 153 and 255. - Value 153 is 60%. - Value 255 is 100%. - */ - temp = (p - PERCENTAGE_MIN) * (RPM_MAGIC_MAX - RPM_MAGIC_MIN) / - (PERCENTAGE_MAX - PERCENTAGE_MIN) + RPM_MAGIC_MIN; - - snprintf(r_data, sizeof(r_data), "%d", (int)temp); - nbytes = strnlen(r_data, sizeof(r_data)); - rv = onlp_file_write((uint8_t*)r_data, nbytes, "%s%s", PREFIX_PATH, - fan_path[local_id].r_speed_set); - if (rv < 0) { - 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; -} - -int -onlp_fani_get_min_rpm(int id) -{ - int len = 0, nbytes = 10; - char r_data[10] = {0}; - - if (onlp_file_read((uint8_t*)r_data, nbytes, &len, "%s%s", PREFIX_PATH, fan_path[id].min) < 0) - return ONLP_STATUS_E_INTERNAL; - - return atoi(r_data); -} diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/ledi.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/ledi.c index 74386ff0..7fdb1f37 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/ledi.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/ledi.c @@ -30,101 +30,9 @@ #include #include #include "platform_lib.h" +#include -#define prefix_path "/bsp/led/led_" -#define driver_value_len 50 - -#define LED_MODE_OFF "none" -#define LED_MODE_GREEN "green" -#define LED_MODE_RED "red" -#define LED_MODE_BLUE "blue" -#define LED_MODE_GREEN_BLINK "green_blink" -#define LED_MODE_RED_BLINK "red_blink" -#define LED_MODE_BLUE_BLINK "blue_blink" -#define LED_MODE_AUTO "cpld_control" - -#define LED_BLINK_PERIOD "100" -#define LED_ON "1" -#define LED_OFF "0" -#define LED_BLINK_PERIOD_LEN 3 -#define LED_MODE_LEN 1 - -#define VALIDATE(_id) \ - do { \ - if(!ONLP_OID_IS_LED(_id)) { \ - return ONLP_STATUS_E_INVALID; \ - } \ - } while(0) - -/* LED related data - */ - -typedef struct led_light_mode_map { - enum onlp_led_id id; - char* driver_led_mode; - enum onlp_led_mode_e onlp_led_mode; -} led_light_mode_map_t; - -led_light_mode_map_t led_map[] = { -{LED_SYSTEM, LED_MODE_OFF, ONLP_LED_MODE_OFF}, -{LED_SYSTEM, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, -{LED_SYSTEM, LED_MODE_RED, ONLP_LED_MODE_RED}, -{LED_SYSTEM, LED_MODE_RED_BLINK, ONLP_LED_MODE_RED_BLINKING}, -{LED_SYSTEM, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, -{LED_SYSTEM, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, - -{LED_FAN1, LED_MODE_OFF, ONLP_LED_MODE_OFF}, -{LED_FAN1, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, -{LED_FAN1, LED_MODE_RED, ONLP_LED_MODE_RED}, -{LED_FAN1, LED_MODE_RED_BLINK, ONLP_LED_MODE_RED_BLINKING}, -{LED_FAN1, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, -{LED_FAN1, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, - -{LED_FAN2, LED_MODE_OFF, ONLP_LED_MODE_OFF}, -{LED_FAN2, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, -{LED_FAN2, LED_MODE_RED, ONLP_LED_MODE_RED}, -{LED_FAN2, LED_MODE_RED_BLINK, ONLP_LED_MODE_RED_BLINKING}, -{LED_FAN2, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, -{LED_FAN2, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, - -{LED_FAN3, LED_MODE_OFF, ONLP_LED_MODE_OFF}, -{LED_FAN3, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, -{LED_FAN3, LED_MODE_RED, ONLP_LED_MODE_RED}, -{LED_FAN3, LED_MODE_RED_BLINK, ONLP_LED_MODE_RED_BLINKING}, -{LED_FAN3, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, -{LED_FAN3, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, - -{LED_FAN4, LED_MODE_OFF, ONLP_LED_MODE_OFF}, -{LED_FAN4, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, -{LED_FAN4, LED_MODE_RED, ONLP_LED_MODE_RED}, -{LED_FAN4, LED_MODE_RED_BLINK, ONLP_LED_MODE_RED_BLINKING}, -{LED_FAN4, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, -{LED_FAN4, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, - -{LED_PSU, LED_MODE_OFF, ONLP_LED_MODE_OFF}, -{LED_PSU, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, -{LED_PSU, LED_MODE_RED, ONLP_LED_MODE_RED}, -{LED_PSU, LED_MODE_RED_BLINK, ONLP_LED_MODE_RED_BLINKING}, -{LED_PSU, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, -{LED_PSU, LED_MODE_AUTO, ONLP_LED_MODE_AUTO} -}; - -typedef struct led_colors { - enum onlp_led_id id; - const char* color1; - const char* color2; -} led_colors_t; - -static led_colors_t led_colors_map[] = { - {LED_SYSTEM, "green", "red"}, - {LED_FAN1, "green", "red"}, - {LED_FAN2, "green", "red"}, - {LED_FAN3, "green", "red"}, - {LED_FAN4, "green", "red"}, - {LED_PSU, "green", "red"}, -}; - -static char file_names[][10] = /* must map with onlp_led_id */ +static char* file_names[] = /* must map with onlp_led_id */ { "reserved", "status", @@ -179,213 +87,11 @@ static onlp_led_info_t linfo[] = } }; -static int driver_to_onlp_led_mode(enum onlp_led_id id, char* driver_led_mode) -{ - char *pos; - int i, nsize = sizeof(led_map)/sizeof(led_map[0]); - - if ((pos=strchr(driver_led_mode, '\n')) != NULL) - *pos = '\0'; - for (i = 0; i < nsize; i++) - { - if (id == led_map[i].id && - !strncmp(led_map[i].driver_led_mode, driver_led_mode, driver_value_len)) - { - return led_map[i].onlp_led_mode; - } - } - - return 0; -} - -static char* onlp_to_driver_led_mode(enum onlp_led_id id, onlp_led_mode_t onlp_led_mode) -{ - int i, nsize = sizeof(led_map)/sizeof(led_map[0]); - - for (i = 0; i < nsize; i++) - { - if (id == led_map[i].id && onlp_led_mode == led_map[i].onlp_led_mode) - { - return led_map[i].driver_led_mode; - } - } - - return LED_MODE_OFF; -} - -static int led_set_mode(onlp_oid_t id, onlp_led_mode_t mode) -{ - int local_id = ONLP_OID_ID_GET(id); - char color[10]={0}; - int blinking = 0; - - switch (mode) { - case ONLP_LED_MODE_RED_BLINKING: - strcpy(color, "red"); - blinking = 1; - break; - case ONLP_LED_MODE_GREEN_BLINKING: - strcpy(color, "green"); - blinking = 1; - break; - case ONLP_LED_MODE_BLUE_BLINKING: - strcpy(color, "blue"); - blinking = 1; - break; - case ONLP_LED_MODE_YELLOW_BLINKING: - strcpy(color, "yellow"); - blinking = 1; - break; - case ONLP_LED_MODE_RED: - strcpy(color, "red"); - break; - case ONLP_LED_MODE_GREEN: - strcpy(color, "green"); - break; - case ONLP_LED_MODE_BLUE: - strcpy(color, "blue"); - break; - case ONLP_LED_MODE_YELLOW: - strcpy(color, "yellow"); - break; - default: - return ONLP_STATUS_E_PARAM; - } - - if (blinking) { - onlp_file_write((uint8_t*)LED_BLINK_PERIOD, LED_BLINK_PERIOD_LEN, - "%s%s_%s_delay_off", prefix_path, file_names[local_id], color); - onlp_file_write((uint8_t*)LED_BLINK_PERIOD, LED_BLINK_PERIOD_LEN, - "%s%s_%s_delay_on", prefix_path, file_names[local_id], color); - } - onlp_file_write((uint8_t*)LED_ON, LED_MODE_LEN, - "%s%s_%s", prefix_path, file_names[local_id], color); - - return ONLP_STATUS_OK; -} - -/* - * This function will be called prior to any other onlp_ledi_* functions. - */ int onlp_ledi_init(void) { - /* - * ONLPD calls it too early before all BSP insfrastructure is set - */ - + mlnx_platform_info_t* mlnx_platform_info = get_platform_info(); + mlnx_platform_info->linfo = linfo; + mlnx_platform_info->led_fnames = file_names; return ONLP_STATUS_OK; } - -int -onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) -{ - int len, local_id = 0; - uint8_t data[driver_value_len] = {0}; - - VALIDATE(id); - - local_id = ONLP_OID_ID_GET(id); - - /* Set the onlp_oid_hdr_t and capabilities */ - *info = linfo[ONLP_OID_ID_GET(id)]; - - /* Get LED mode */ - if (onlp_get_kernel_ver() >= KERNEL_VERSION(4,9,30)) { - char* cmd = aim_fstrdup("%s%s_state", prefix_path, file_names[local_id]); - if(system(cmd) != 0) { - aim_free(cmd); - return ONLP_STATUS_E_INTERNAL; - } - aim_free(cmd); - } - - if (onlp_file_read(data, sizeof(data), &len, "%s%s", - prefix_path, file_names[local_id]) != 0) { - return ONLP_STATUS_E_INTERNAL; - } - - info->mode = driver_to_onlp_led_mode(local_id, (char*)data); - - /* Set the on/off status */ - if (info->mode != ONLP_LED_MODE_OFF) { - info->status |= ONLP_LED_STATUS_ON; - } - - return ONLP_STATUS_OK; -} - -/* - * Turn an LED on or off. - * - * This function will only be called if the LED OID supports the ONOFF - * capability. - * - * What 'on' means in terms of colors or modes for multimode LEDs is - * up to the platform to decide. This is intended as baseline toggle mechanism. - */ -int -onlp_ledi_set(onlp_oid_t id, int on_or_off) -{ - VALIDATE(id); - - if (!on_or_off) { - if (onlp_get_kernel_ver() < KERNEL_VERSION(4,9,30)) - return onlp_ledi_mode_set(id, ONLP_LED_MODE_OFF); - else { - int i, nsize = sizeof(led_colors_map)/sizeof(led_colors_map[0]); - for (i = 0; i < nsize; i++) - { - if (id == led_colors_map[i].id) - break; - } - if (led_colors_map[i].color1) - onlp_file_write((uint8_t*)LED_OFF, LED_MODE_LEN, - "%s%s_%s", prefix_path, file_names[id], led_colors_map[i].color1); - } - } - - return ONLP_STATUS_E_UNSUPPORTED; -} - -/* - * This function puts the LED into the given mode. It is a more functional - * interface for multimode LEDs. - * - * Only modes reported in the LED's capabilities will be attempted. - */ -int -onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) -{ - int local_id; - char* driver_led_mode; - int nbytes; - - VALIDATE(id); - - if (onlp_get_kernel_ver() < KERNEL_VERSION(4,9,30)) { - local_id = ONLP_OID_ID_GET(id); - driver_led_mode = onlp_to_driver_led_mode(local_id, mode); - nbytes = strnlen(driver_led_mode, driver_value_len); - if (onlp_file_write((uint8_t*)driver_led_mode, nbytes, - "%s%s", prefix_path, file_names[local_id]) != 0) { - return ONLP_STATUS_E_INTERNAL; - } - } else { - if (led_set_mode(id, mode) != 0) { - return ONLP_STATUS_E_INTERNAL; - } - } - - return ONLP_STATUS_OK; -} - -/* - * Generic LED ioctl interface. - */ -int -onlp_ledi_ioctl(onlp_oid_t id, va_list vargs) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/platform_lib.h b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/platform_lib.h index 66581253..99bea7dc 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/platform_lib.h +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/platform_lib.h @@ -25,8 +25,6 @@ #ifndef __PLATFORM_LIB_H__ #define __PLATFORM_LIB_H__ -#include -#include #include "x86_64_mlnx_msn2700_log.h" #define CHASSIS_PSU_COUNT 2 @@ -34,43 +32,8 @@ #define CHASSIS_TOTAL_THERMAL_COUNT 8 #define CHASSIS_FAN_COUNT (CHASSIS_TOTAL_FAN_COUNT - CHASSIS_PSU_COUNT) #define CHASSIS_THERMAL_COUNT (CHASSIS_TOTAL_THERMAL_COUNT - CHASSIS_PSU_COUNT) - -#define PSU1_ID 1 -#define PSU2_ID 2 - -#define PSU_MODULE_PREFIX "/bsp/module/psu%d_%s" -#define PSU_POWER_PREFIX "/bsp/power/psu%d_%s" -#define IDPROM_PATH "/bsp/eeprom/%s%d_info" - -#ifndef KERNEL_VERSION -#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) -#endif - -/* LED related data - */ -enum onlp_led_id -{ - LED_RESERVED = 0, - LED_SYSTEM, - LED_FAN1, - LED_FAN2, - LED_FAN3, - LED_FAN4, - LED_PSU, -}; - -typedef enum psu_type { - PSU_TYPE_UNKNOWN, - PSU_TYPE_AC_F2B, - PSU_TYPE_AC_B2F -} psu_type_t; - -psu_type_t get_psu_type(int id, char* modelname, int modelname_len); - -int psu_read_eeprom(int psu_index, onlp_psu_info_t* psu_info, - onlp_fan_info_t* fan_info); - -int onlp_fani_get_min_rpm(int id); -int onlp_get_kernel_ver(void); +#define CPLD_COUNT 3 +#define SFP_PORT_COUNT 32 +#define CHASSIS_LED_COUNT 6 #endif /* __PLATFORM_LIB_H__ */ diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/psui.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/psui.c deleted file mode 100644 index f5555b60..00000000 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/psui.c +++ /dev/null @@ -1,200 +0,0 @@ -/************************************************************ - * - * - * Copyright 2014 Big Switch Networks, Inc. - * - * 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 "platform_lib.h" - -#define PSU_STATUS_PRESENT 1 -#define PSU_CABLE_PRESENT 1 - -#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 -psu_module_info_get(int id, char *node, int *value) -{ - int len, ret = 0; - char buf[PSU_NODE_MAX_INT_LEN + 1] = {0}; - - *value = 0; - - ret = onlp_file_read((uint8_t*)buf, sizeof(buf), &len, - PSU_MODULE_PREFIX, id, node); - if (ret == 0) { - *value = atoi(buf); - } - - return ret; -} - -static int -psu_power_info_get(int id, char *node, int *value) -{ - int len, ret = 0; - char buf[PSU_NODE_MAX_INT_LEN + 1] = {0}; - - *value = 0; - - ret = onlp_file_read((uint8_t*)buf, sizeof(buf), &len, - PSU_POWER_PREFIX, id, node); - if (ret == 0) { - *value = atoi(buf); - } - - return ret; -} - -int -onlp_psui_init(void) -{ - return ONLP_STATUS_OK; -} - -static int -_psu_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; - } - - /* Set the associated oid_table */ - info->hdr.coids[0] = ONLP_FAN_ID_CREATE(index + CHASSIS_FAN_COUNT); - info->hdr.coids[1] = ONLP_THERMAL_ID_CREATE(index + CHASSIS_THERMAL_COUNT); - - /* Read voltage, current and power */ - if (psu_power_info_get(index, "volt_in", &val) == 0 && - 0 != val) { - info->mvin = val; - info->caps |= ONLP_PSU_CAPS_VIN; - - if (psu_power_info_get(index, "volt", &val) == 0) { - info->mvout = val; - info->caps |= ONLP_PSU_CAPS_VOUT; - } - - if (psu_power_info_get(index, "curr_in", &val) == 0) { - info->miin = val; - info->caps |= ONLP_PSU_CAPS_IIN; - } - - if (psu_power_info_get(index, "curr", &val) == 0) { - info->miout = val; - info->caps |= ONLP_PSU_CAPS_IOUT; - } - - if (psu_power_info_get(index, "power_in", &val) == 0) { - info->mpin = val; - info->caps |= ONLP_PSU_CAPS_PIN; - } - - if (psu_power_info_get(index, "power", &val) == 0) { - info->mpout = val; - info->caps |= ONLP_PSU_CAPS_POUT; - } - } else { - info->status |= ONLP_PSU_STATUS_FAILED; - return ONLP_STATUS_OK; - } - - return psu_read_eeprom(index, info, NULL); -} - -/* - * Get all information about the given PSU oid. - */ -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 }, - } -}; - -int -onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) -{ - int val = 0; - int ret = ONLP_STATUS_OK; - int index = ONLP_OID_ID_GET(id); - - VALIDATE(id); - - memset(info, 0, sizeof(onlp_psu_info_t)); - *info = pinfo[index]; /* Set the onlp_oid_hdr_t */ - - /* Get the present state */ - if (psu_module_info_get(index, "status", &val) != 0) { - AIM_LOG_ERROR("Unable to read PSU(%d) node(psu_present)\r\n", index); - } - - if (val != PSU_STATUS_PRESENT) { - info->status &= ~ONLP_PSU_STATUS_PRESENT; - info->status |= ONLP_PSU_STATUS_UNPLUGGED; - return ONLP_STATUS_OK; - } - else - info->status |= ONLP_PSU_STATUS_PRESENT; - - /* Get the cable preset state */ - if (psu_module_info_get(index, "pwr_status", &val) != 0) { - AIM_LOG_ERROR("Unable to read PSU(%d) node(cable_present)\r\n", index); - } - - if (val != PSU_CABLE_PRESENT) { - info->status |= ONLP_PSU_STATUS_UNPLUGGED; - return ONLP_STATUS_OK; - } - - ret = _psu_info_get(info); - - return ret; -} - -int -onlp_psui_ioctl(onlp_oid_t pid, va_list vargs) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/sfpi.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/sfpi.c deleted file mode 100644 index 65cd8893..00000000 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/sfpi.c +++ /dev/null @@ -1,262 +0,0 @@ -/************************************************************ - * - * - * Copyright 2014 Big Switch Networks, Inc. - * - * 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 /* For O_RDWR && open */ -#include -#include -#include -#include -#include -#include -#include -#include "platform_lib.h" - -#define MAX_SFP_PATH 64 -#define SFP_SYSFS_VALUE_LEN 20 -static char sfp_node_path[MAX_SFP_PATH] = {0}; -#define NUM_OF_SFP_PORT 32 -#define SFP_PRESENT_STATUS "good" -#define SFP_NOT_PRESENT_STATUS "not_connected" - -static int -sn2700_sfp_node_read_int(char *node_path, int *value) -{ - int data_len = 0, ret = 0; - char buf[SFP_SYSFS_VALUE_LEN] = {0}; - *value = -1; - char sfp_present_status[16]; - char sfp_not_present_status[16]; - - if (onlp_get_kernel_ver() >= KERNEL_VERSION(4,9,30)) { - strcpy(sfp_present_status, "1"); - strcpy(sfp_not_present_status, "0"); - } else { - strcpy(sfp_present_status, "good"); - strcpy(sfp_not_present_status, "not_connected"); - } - - ret = onlp_file_read((uint8_t*)buf, sizeof(buf), &data_len, node_path); - - if (ret == 0) { - if (!strncmp(buf, sfp_present_status, strlen(sfp_present_status))) { - *value = 1; - } else if (!strncmp(buf, sfp_not_present_status, strlen(sfp_not_present_status))) { - *value = 0; - } - } - - return ret; -} - -static char* -sn2700_sfp_get_port_path(int port, char *node_name) -{ - if (node_name) - sprintf(sfp_node_path, "/bsp/qsfp/qsfp%d%s", port, node_name); - else - sprintf(sfp_node_path, "/bsp/qsfp/qsfp%d", port); - return sfp_node_path; -} - -static char* -sn2700_sfp_convert_i2c_path(int port, int devaddr) -{ - sprintf(sfp_node_path, "/bsp/qsfp/qsfp%d", port); - return sfp_node_path; -} - -/************************************************************ - * - * SFPI Entry Points - * - ***********************************************************/ -int -onlp_sfpi_init(void) -{ - /* Called at initialization time */ - return ONLP_STATUS_OK; -} - -int -onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap) -{ - /* - * Ports {1, 32} - */ - int p = 1; - AIM_BITMAP_CLR_ALL(bmap); - - for (; p <= NUM_OF_SFP_PORT; p++) { - AIM_BITMAP_SET(bmap, p); - } - - return ONLP_STATUS_OK; -} - -int -onlp_sfpi_is_present(int port) -{ - /* - * Return 1 if present. - * Return 0 if not present. - * Return < 0 if error. - */ - int present = -1; - char* path = sn2700_sfp_get_port_path(port, "_status"); - - if (sn2700_sfp_node_read_int(path, &present) != 0) { - AIM_LOG_ERROR("Unable to read present status from port(%d)\r\n", port); - return ONLP_STATUS_E_INTERNAL; - } - - return present; -} - -int -onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) -{ - int ii = 1; - int rc = 0; - - for (;ii <= NUM_OF_SFP_PORT; ii++) { - rc = onlp_sfpi_is_present(ii); - AIM_BITMAP_MOD(dst, ii, (1 == rc) ? 1 : 0); - } - - return ONLP_STATUS_OK; -} - -int -onlp_sfpi_eeprom_read(int port, uint8_t data[256]) -{ - char* path = sn2700_sfp_get_port_path(port, NULL); - - /* - * Read the SFP eeprom into data[] - * - * Return MISSING if SFP is missing. - * Return OK if eeprom is read - */ - memset(data, 0, 256); - - if (onlplib_sfp_eeprom_read_file(path, data) != 0) { - AIM_LOG_ERROR("Unable to read eeprom from port(%d)\r\n", port); - return ONLP_STATUS_E_INTERNAL; - } - - return ONLP_STATUS_OK; -} - -int -onlp_sfpi_dev_readb(int port, uint8_t devaddr, uint8_t addr) -{ - char* path = sn2700_sfp_convert_i2c_path(port, devaddr); - uint8_t data; - int fd; - int nrd; - - if (!path) - return ONLP_STATUS_E_MISSING; - - fd = open(path, O_RDONLY); - if (fd < 0) - return ONLP_STATUS_E_MISSING; - - lseek(fd, addr, SEEK_SET); - nrd = read(fd, &data, 1); - close(fd); - - if (nrd != 1) { - AIM_LOG_INTERNAL("Failed to read EEPROM file '%s'", path); - return ONLP_STATUS_E_INTERNAL; - } - return data; -} - -int -onlp_sfpi_dev_writeb(int port, uint8_t devaddr, uint8_t addr, uint8_t value) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - -int -onlp_sfpi_dev_readw(int port, uint8_t devaddr, uint8_t addr) -{ - char* path = sn2700_sfp_convert_i2c_path(port, devaddr); - uint16_t data; - int fd; - int nrd; - - if (!path){ - return ONLP_STATUS_E_MISSING; - } - - fd = open(path, O_RDONLY); - if (fd < 0) { - return ONLP_STATUS_E_MISSING; - } - - lseek(fd, addr, SEEK_SET); - nrd = read(fd, &data, 2); - close(fd); - - if (nrd != 2) { - AIM_LOG_INTERNAL("Failed to read EEPROM file '%s'", path); - return ONLP_STATUS_E_INTERNAL; - } - return data; -} - -int -onlp_sfpi_dev_writew(int port, uint8_t devaddr, uint8_t addr, uint16_t value) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - -int -onlp_sfpi_control_supported(int port, onlp_sfp_control_t control, int* rv) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - -int -onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - -int -onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) -{ - return ONLP_STATUS_E_UNSUPPORTED; -} - -int -onlp_sfpi_denit(void) -{ - return ONLP_STATUS_OK; -} - diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/sysi.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/sysi.c index 7b267507..fd56b98a 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/sysi.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/sysi.c @@ -35,205 +35,54 @@ #include "platform_lib.h" #include "x86_64_mlnx_msn2700_int.h" #include "x86_64_mlnx_msn2700_log.h" +#include -#define ONL_PLATFORM_NAME "x86-64-mlnx-msn2700-r0" -#define ONIE_PLATFORM_NAME "x86_64-mlnx_msn2700-r0" - -#define NUM_OF_THERMAL_ON_MAIN_BROAD CHASSIS_THERMAL_COUNT -#define NUM_OF_FAN_ON_MAIN_BROAD CHASSIS_FAN_COUNT -#define NUM_OF_PSU_ON_MAIN_BROAD 2 -#define NUM_OF_LED_ON_MAIN_BROAD 6 +static const char* __ONL_PLATFORM_NAME = NULL; #define COMMAND_OUTPUT_BUFFER 256 -#define PREFIX_PATH_ON_CPLD_DEV "/bsp/cpld" -#define NUM_OF_CPLD 3 -static char arr_cplddev_name[NUM_OF_CPLD][30] = +int mc_get_platform_info(mlnx_platform_info_t* mlnx_platform) { - "cpld_brd_version", - "cpld_mgmt_version", - "cpld_port_version" -}; - -const char* -onlp_sysi_platform_get(void) -{ - return ONL_PLATFORM_NAME; -} - -int -onlp_sysi_platform_info_get(onlp_platform_info_t* pi) -{ - int i, v[NUM_OF_CPLD]={0}; - - for (i=0; i < NUM_OF_CPLD; i++) { - v[i] = 0; - if(onlp_file_read_int(v+i, "%s/%s", PREFIX_PATH_ON_CPLD_DEV, arr_cplddev_name[i]) < 0) { - return ONLP_STATUS_E_INTERNAL; - } - } - pi->cpld_versions = aim_fstrdup("brd=%d, mgmt=%d, port=%d", v[0], v[1], v[2]); - - return ONLP_STATUS_OK; -} - -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) -{ - int i; - onlp_oid_t* e = table; - memset(table, 0, max*sizeof(onlp_oid_t)); - - /* 8 Thermal sensors on the chassis */ - for (i = 1; i <= NUM_OF_THERMAL_ON_MAIN_BROAD; i++) - { - *e++ = ONLP_THERMAL_ID_CREATE(i); - } - - /* 6 LEDs on the chassis */ - for (i = 1; i <= NUM_OF_LED_ON_MAIN_BROAD; i++) - { - *e++ = ONLP_LED_ID_CREATE(i); - } - - /* 2 PSUs on the chassis */ - for (i = 1; i <= NUM_OF_PSU_ON_MAIN_BROAD; i++) - { - *e++ = ONLP_PSU_ID_CREATE(i); - } - - /* 8 Fans and 2 PSU fans on the chassis */ - for (i = 1; i <= NUM_OF_FAN_ON_MAIN_BROAD; i++) - { - *e++ = ONLP_FAN_ID_CREATE(i); - } - - return 0; -} - -int -onlp_sysi_onie_info_get(onlp_onie_info_t* onie) -{ - int rv = onlp_onie_read_json(onie, - "/lib/platform-config/current/onl/etc/onie/eeprom.json"); - if(rv >= 0) { - if(onie->platform_name) { - aim_free(onie->platform_name); - } - onie->platform_name = aim_strdup(ONIE_PLATFORM_NAME); - } - - return rv; -} - -int -onlp_sysi_platform_manage_leds(void) -{ - int fan_number, psu_number; - onlp_led_mode_t mode, system_mode; - int min_fan_speed; - enum onlp_led_id fan_led_id[4] = { LED_FAN1, LED_FAN2, LED_FAN3, LED_FAN4 }; - int fan_problem = 0; - int psu_problem = 0; - - /* - * FAN Indicators - * - * Green - Fan is operating - * Red - No power or Fan failure - * Off - No power - * - */ - for( fan_number = 1; fan_number <= CHASSIS_FAN_COUNT; fan_number+=2) - { - /* each 2 fans had same led_fan */ - onlp_fan_info_t fi; - /* check fan i */ - mode = ONLP_LED_MODE_GREEN; - if(onlp_fani_info_get(ONLP_FAN_ID_CREATE(fan_number), &fi) < 0) { - mode = ONLP_LED_MODE_RED; - fan_problem = 1; - } - else if( (fi.status & ONLP_FAN_STATUS_PRESENT) == 0) { - /* Not present */ - mode = ONLP_LED_MODE_RED; - fan_problem = 1; - } - else if(fi.status & ONLP_FAN_STATUS_FAILED) { - mode = ONLP_LED_MODE_RED; - fan_problem = 1; - } - else - { - min_fan_speed = onlp_fani_get_min_rpm(fan_number); - if( fi.rpm < min_fan_speed) - { - mode = ONLP_LED_MODE_RED; - fan_problem = 1; - } - } - /* check fan i+1 */ - if(onlp_fani_info_get(ONLP_FAN_ID_CREATE(fan_number+1), &fi) < 0) { - mode = ONLP_LED_MODE_RED; - fan_problem = 1; - } - else if( (fi.status & 0x1) == 0) { - /* Not present */ - mode = ONLP_LED_MODE_RED; - fan_problem = 1; - } - else if(fi.status & ONLP_FAN_STATUS_FAILED) { - mode = ONLP_LED_MODE_RED; - fan_problem = 1; - } - else - { - min_fan_speed = onlp_fani_get_min_rpm(fan_number+1); - if( fi.rpm < min_fan_speed) - { - mode = ONLP_LED_MODE_RED; - fan_problem = 1; - } - } - onlp_ledi_mode_set(ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_LED,fan_led_id[fan_number/2]), mode); + if (!__ONL_PLATFORM_NAME) { + strncpy(mlnx_platform->onl_platform_name, "x86-64-mlnx-msn2700-all", PLATFORM_NAME_MAX_LEN); } - - for (psu_number = 1; psu_number <= CHASSIS_PSU_COUNT; psu_number++) - { - onlp_psu_info_t pi; - if(onlp_psui_info_get(ONLP_PSU_ID_CREATE(psu_number), &pi) < 0) { - psu_problem = 1; - } - else if((pi.status & ONLP_PSU_STATUS_PRESENT) == 0) { - /* Not present */ - psu_problem = 1; - } - else if(pi.status & ONLP_PSU_STATUS_UNPLUGGED) { - psu_problem = 1; - } + else { + strncpy(mlnx_platform->onl_platform_name, __ONL_PLATFORM_NAME, PLATFORM_NAME_MAX_LEN); } - - if (psu_problem) - mode = ONLP_LED_MODE_RED; - else - mode = ONLP_LED_MODE_GREEN; - onlp_ledi_mode_set(ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_LED, LED_PSU), mode); - - /* Set System status LED green if no problem in FANs or PSUs */ - if (fan_problem || psu_problem) - system_mode = ONLP_LED_MODE_RED; - else - system_mode = ONLP_LED_MODE_GREEN; - - onlp_ledi_mode_set(ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_LED,LED_SYSTEM), system_mode); + mlnx_platform->sfp_num = SFP_PORT_COUNT; + mlnx_platform->led_num = CHASSIS_LED_COUNT; + mlnx_platform->psu_num = CHASSIS_PSU_COUNT; + mlnx_platform->fan_num = CHASSIS_FAN_COUNT; + mlnx_platform->thermal_num = CHASSIS_THERMAL_COUNT; + mlnx_platform->cpld_num = CPLD_COUNT; + mlnx_platform->psu_fixed = false; + mlnx_platform->fan_fixed = false; + mlnx_platform->psu_type = PSU_TYPE_2; + mlnx_platform->led_type = LED_TYPE_2; return ONLP_STATUS_OK; } +int +onlp_sysi_platform_set(const char* platform) +{ + mlnx_platform_info_t* mlnx_platform; + + if(!strcmp(platform, "x86-64-mlnx-msn2700-r0")) { + __ONL_PLATFORM_NAME = "x86-64-mlnx_msn2700-r0"; + mlnx_platform = get_platform_info(); + mc_get_platform_info(mlnx_platform); + return ONLP_STATUS_OK; + } + if(!strcmp(platform, "x86-64-mlnx-msn2700-all")) { + __ONL_PLATFORM_NAME = "x86-64-mlnx-msn2700-all"; + return ONLP_STATUS_OK; + } + return ONLP_STATUS_E_UNSUPPORTED; +} + +int +onlp_sysi_init(void) +{ + return ONLP_STATUS_OK; +} diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/thermali.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/thermali.c index 698be008..82b44635 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/thermali.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/thermali.c @@ -29,45 +29,7 @@ #include #include #include "platform_lib.h" - -#define prefix_path "/bsp/thermal" - -/** CPU thermal_threshold */ -typedef enum cpu_thermal_threshold_e { - CPU_THERMAL_THRESHOLD_WARNING_DEFAULT = 87000, - CPU_THERMAL_THRESHOLD_ERROR_DEFAULT = 100000, - CPU_THERMAL_THRESHOLD_SHUTDOWN_DEFAULT = 105000, -} cpu_thermal_threshold_t; - -/** - * Shortcut for CPU thermal threshold value. - */ -#define CPU_THERMAL_THRESHOLD_INIT_DEFAULTS \ - { CPU_THERMAL_THRESHOLD_WARNING_DEFAULT, \ - CPU_THERMAL_THRESHOLD_ERROR_DEFAULT, \ - CPU_THERMAL_THRESHOLD_SHUTDOWN_DEFAULT } - -/** Asic thermal_threshold */ -typedef enum asic_thermal_threshold_e { - ASIC_THERMAL_THRESHOLD_WARNING_DEFAULT = 105000, - ASIC_THERMAL_THRESHOLD_ERROR_DEFAULT = 115000, - ASIC_THERMAL_THRESHOLD_SHUTDOWN_DEFAULT = 120000, -} asic_thermal_threshold_t; - -/** - * Shortcut for CPU thermal threshold value. - */ -#define ASIC_THERMAL_THRESHOLD_INIT_DEFAULTS \ - { ASIC_THERMAL_THRESHOLD_WARNING_DEFAULT, \ - ASIC_THERMAL_THRESHOLD_ERROR_DEFAULT, \ - ASIC_THERMAL_THRESHOLD_SHUTDOWN_DEFAULT } - -#define VALIDATE(_id) \ - do { \ - if(!ONLP_OID_IS_THERMAL(_id)) { \ - return ONLP_STATUS_E_INVALID; \ - } \ - } while(0) +#include "mlnx_common/mlnx_common.h" enum onlp_thermal_id { @@ -82,7 +44,7 @@ enum onlp_thermal_id THERMAL_ON_PSU2, }; -static char* last_path[] = /* must map with onlp_thermal_id */ +static char* thermal_fnames[] = /* must map with onlp_thermal_id */ { "reserved", "cpu_core0", @@ -96,7 +58,7 @@ static char* last_path[] = /* must map with onlp_thermal_id */ }; /* Static values */ -static onlp_thermal_info_t linfo[] = { +static onlp_thermal_info_t tinfo[] = { { }, /* Not used */ { { ONLP_THERMAL_ID_CREATE(THERMAL_CPU_CORE_0), "CPU Core 0", 0}, ONLP_THERMAL_STATUS_PRESENT, @@ -138,39 +100,9 @@ static onlp_thermal_info_t linfo[] = { int onlp_thermali_init(void) { - return ONLP_STATUS_OK; -} - -/* - * Retrieve the information structure for the given thermal OID. - * - * If the OID is invalid, return ONLP_E_STATUS_INVALID. - * If an unexpected error occurs, return ONLP_E_STATUS_INTERNAL. - * Otherwise, return ONLP_STATUS_OK with the OID's information. - * - * Note -- it is expected that you fill out the information - * 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) -{ - int rv, len = 10, temp_base=1, local_id = 0; - char r_data[10] = {0}; - VALIDATE(id); - - local_id = ONLP_OID_ID_GET(id); - - /* Set the onlp_oid_hdr_t and capabilities */ - *info = linfo[local_id]; - - rv = onlp_file_read((uint8_t*)r_data, sizeof(r_data), &len, "%s/%s", - prefix_path, last_path[local_id]); - if (rv < 0) { - return ONLP_STATUS_E_INTERNAL; - } - - info->mcelsius = atoi(r_data) / temp_base; - + mlnx_platform_info_t* mlnx_platform_info = get_platform_info(); + mlnx_platform_info->tinfo=tinfo; + mlnx_platform_info->thermal_fnames=thermal_fnames; return ONLP_STATUS_OK; }