diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/Makefile b/packages/platforms/ufispace/x86-64/s9500-22xst/Makefile new file mode 100755 index 0000000000..003238cf6d --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/modules/Makefile b/packages/platforms/ufispace/x86-64/s9500-22xst/modules/Makefile new file mode 100755 index 0000000000..003238cf6d --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/modules/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/modules/PKG.yml b/packages/platforms/ufispace/x86-64/s9500-22xst/modules/PKG.yml new file mode 100755 index 0000000000..36bdd34daa --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/modules/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/no-platform-modules.yml ARCH=amd64 VENDOR=ufispace BASENAME=x86-64-ufispace-s9500-22xst diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/Makefile b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/Makefile new file mode 100755 index 0000000000..003238cf6d --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/PKG.yml b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/PKG.yml new file mode 100755 index 0000000000..903db994b1 --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/onlp-platform-any.yml PLATFORM=x86-64-ufispace-s9500-22xst ARCH=amd64 TOOLCHAIN=x86_64-linux-gnu diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/Makefile b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/Makefile new file mode 100755 index 0000000000..e7437cb23a --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/Makefile @@ -0,0 +1,2 @@ +FILTER=src +include $(ONL)/make/subdirs.mk diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/lib/.gitignore b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/lib/.gitignore new file mode 100755 index 0000000000..c81d16be39 --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/lib/.gitignore @@ -0,0 +1 @@ +*.mk diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/lib/Makefile b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/lib/Makefile new file mode 100755 index 0000000000..b81245fbd0 --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/lib/Makefile @@ -0,0 +1,2 @@ +PLATFORM := x86-64-ufispace-s9500-22xst +include $(ONL)/packages/base/any/onlp/builds/platform/libonlp-platform.mk diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/onlpdump/Makefile b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/onlpdump/Makefile new file mode 100755 index 0000000000..baeb6e805c --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/onlpdump/Makefile @@ -0,0 +1,2 @@ +PLATFORM := x86-64-ufispace-s9500-22xst +include $(ONL)/packages/base/any/onlp/builds/platform/onlps.mk diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/.gitignore b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/.gitignore new file mode 100755 index 0000000000..65382d8f5c --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/.gitignore @@ -0,0 +1,2 @@ +/x86_64_ufispace_s9500_22xst.mk +/doc diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/.module b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/.module new file mode 100755 index 0000000000..9d78d94f1a --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/.module @@ -0,0 +1 @@ +name: x86_64_ufispace_s9500_22xst diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/Makefile b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/Makefile new file mode 100755 index 0000000000..1c9245f9f5 --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/Makefile @@ -0,0 +1,10 @@ +############################################################ +# +# +# +############################################################ +include $(ONL)/make/config.mk + +MODULE := x86_64_ufispace_s9500_22xst +AUTOMODULE := x86_64_ufispace_s9500_22xst +include $(BUILDER)/definemodule.mk diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/auto/make.mk b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/auto/make.mk new file mode 100755 index 0000000000..8a0fc1c3e4 --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/auto/make.mk @@ -0,0 +1,7 @@ +# +# x86_64_ufispace_s9500_22xst Autogeneration +# +############################################################################### +x86_64_ufispace_s9500_22xst_AUTO_DEFS := module/auto/x86_64_ufispace_s9500_22xst.yml +x86_64_ufispace_s9500_22xst_AUTO_DIRS := module/inc/x86_64_ufispace_s9500_22xst module/src +include $(BUILDER)/auto.mk diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/auto/x86_64_ufispace_s9500_22xst.yml b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/auto/x86_64_ufispace_s9500_22xst.yml new file mode 100755 index 0000000000..a9e49e91db --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/auto/x86_64_ufispace_s9500_22xst.yml @@ -0,0 +1,46 @@ +############################################################################### +# +# X86_64_UFISPACE_S9500_22XST Autogeneration Definitions. +# +############################################################################### + +cdefs: &cdefs +- X86_64_UFISPACE_S9500_22XST_CONFIG_INCLUDE_LOGGING: + doc: "Include or exclude logging." + default: 1 +- X86_64_UFISPACE_S9500_22XST_CONFIG_LOG_OPTIONS_DEFAULT: + doc: "Default enabled log options." + default: AIM_LOG_OPTIONS_DEFAULT +- X86_64_UFISPACE_S9500_22XST_CONFIG_LOG_BITS_DEFAULT: + doc: "Default enabled log bits." + default: AIM_LOG_BITS_DEFAULT +- X86_64_UFISPACE_S9500_22XST_CONFIG_LOG_CUSTOM_BITS_DEFAULT: + doc: "Default enabled custom log bits." + default: 0 +- X86_64_UFISPACE_S9500_22XST_CONFIG_PORTING_STDLIB: + doc: "Default all porting macros to use the C standard libraries." + default: 1 +- X86_64_UFISPACE_S9500_22XST_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS: + doc: "Include standard library headers for stdlib porting macros." + default: X86_64_UFISPACE_S9500_22XST_CONFIG_PORTING_STDLIB +- X86_64_UFISPACE_S9500_22XST_CONFIG_INCLUDE_UCLI: + doc: "Include generic uCli support." + default: 0 + + +definitions: + cdefs: + X86_64_UFISPACE_S9500_22XST_CONFIG_HEADER: + defs: *cdefs + basename: x86_64_ufispace_s9500_22XST_config + + portingmacro: + X86_64_UFISPACE_S9500_22XST: + macros: + - malloc + - free + - memset + - memcpy + - vsnprintf + - snprintf + - strlen diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/inc/x86_64_ufispace_s9500_22xst/x86_64_ufispace_s9500_22xst.x b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/inc/x86_64_ufispace_s9500_22xst/x86_64_ufispace_s9500_22xst.x new file mode 100755 index 0000000000..0217f3ab70 --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/inc/x86_64_ufispace_s9500_22xst/x86_64_ufispace_s9500_22xst.x @@ -0,0 +1,34 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 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 + +/* <--auto.start.xmacro(ALL).define> */ +/* */ + +/* <--auto.start.xenum(ALL).define> */ +/* */ + + diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/inc/x86_64_ufispace_s9500_22xst/x86_64_ufispace_s9500_22xst_config.h b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/inc/x86_64_ufispace_s9500_22xst/x86_64_ufispace_s9500_22xst_config.h new file mode 100755 index 0000000000..c0af00aeee --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/inc/x86_64_ufispace_s9500_22xst/x86_64_ufispace_s9500_22xst_config.h @@ -0,0 +1,152 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 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. + * + * + ************************************************************ + * + * + * + ***********************************************************/ + +/**************************************************************************//** + * + * @file + * @brief x86_64_ufispace_s9500_22xst Configuration Header + * + * @addtogroup x86_64_ufispace_s9500_22xst-config + * @{ + * + *****************************************************************************/ +#ifndef __X86_64_UFISPACE_S9500_22XST_CONFIG_H__ +#define __X86_64_UFISPACE_S9500_22XST_CONFIG_H__ + +#ifdef GLOBAL_INCLUDE_CUSTOM_CONFIG +#include +#endif +#ifdef X86_64_UFISPACE_S9500_22XST_INCLUDE_CUSTOM_CONFIG +#include +#endif + +/* */ +#include +/** + * X86_64_UFISPACE_S9500_22XST_CONFIG_INCLUDE_LOGGING + * + * Include or exclude logging. */ + + +#ifndef X86_64_UFISPACE_S9500_22XST_CONFIG_INCLUDE_LOGGING +#define X86_64_UFISPACE_S9500_22XST_CONFIG_INCLUDE_LOGGING 1 +#endif + +/** + * X86_64_UFISPACE_S9500_22XST_CONFIG_LOG_OPTIONS_DEFAULT + * + * Default enabled log options. */ + + +#ifndef X86_64_UFISPACE_S9500_22XST_CONFIG_LOG_OPTIONS_DEFAULT +#define X86_64_UFISPACE_S9500_22XST_CONFIG_LOG_OPTIONS_DEFAULT AIM_LOG_OPTIONS_DEFAULT +#endif + +/** + * X86_64_UFISPACE_S9500_22XST_CONFIG_LOG_BITS_DEFAULT + * + * Default enabled log bits. */ + + +#ifndef X86_64_UFISPACE_S9500_22XST_CONFIG_LOG_BITS_DEFAULT +#define X86_64_UFISPACE_S9500_22XST_CONFIG_LOG_BITS_DEFAULT AIM_LOG_BITS_DEFAULT +#endif + +/** + * X86_64_UFISPACE_S9500_22XST_CONFIG_LOG_CUSTOM_BITS_DEFAULT + * + * Default enabled custom log bits. */ + + +#ifndef X86_64_UFISPACE_S9500_22XST_CONFIG_LOG_CUSTOM_BITS_DEFAULT +#define X86_64_UFISPACE_S9500_22XST_CONFIG_LOG_CUSTOM_BITS_DEFAULT 0 +#endif + +/** + * X86_64_UFISPACE_S9500_22XST_CONFIG_PORTING_STDLIB + * + * Default all porting macros to use the C standard libraries. */ + + +#ifndef X86_64_UFISPACE_S9500_22XST_CONFIG_PORTING_STDLIB +#define X86_64_UFISPACE_S9500_22XST_CONFIG_PORTING_STDLIB 1 +#endif + +/** + * X86_64_UFISPACE_S9500_22XST_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + * + * Include standard library headers for stdlib porting macros. */ + + +#ifndef X86_64_UFISPACE_S9500_22XST_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS +#define X86_64_UFISPACE_S9500_22XST_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS X86_64_UFISPACE_S9500_22XST_CONFIG_PORTING_STDLIB +#endif + +/** + * X86_64_UFISPACE_S9500_22XST_CONFIG_INCLUDE_UCLI + * + * Include generic uCli support. */ + + +#ifndef X86_64_UFISPACE_S9500_22XST_CONFIG_INCLUDE_UCLI +#define X86_64_UFISPACE_S9500_22XST_CONFIG_INCLUDE_UCLI 0 +#endif + + + +/** + * All compile time options can be queried or displayed + */ + +/** Configuration settings structure. */ +typedef struct x86_64_ufispace_s9500_22xst_config_settings_s { + /** name */ + const char* name; + /** value */ + const char* value; +} x86_64_ufispace_s9500_22xst_config_settings_t; + +/** Configuration settings table. */ +/** x86_64_ufispace_s9500_22xst_config_settings table. */ +extern x86_64_ufispace_s9500_22xst_config_settings_t x86_64_ufispace_s9500_22xst_config_settings[]; + +/** + * @brief Lookup a configuration setting. + * @param setting The name of the configuration option to lookup. + */ +const char* x86_64_ufispace_s9500_22xst_config_lookup(const char* setting); + +/** + * @brief Show the compile-time configuration. + * @param pvs The output stream. + */ +int x86_64_ufispace_s9500_22xst_config_show(struct aim_pvs_s* pvs); + +/* */ + +#include "x86_64_ufispace_s9500_22xst_porting.h" + +#endif /* __X86_64_UFISPACE_S9500_22XST_CONFIG_H__ */ +/* @} */ diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/inc/x86_64_ufispace_s9500_22xst/x86_64_ufispace_s9500_22xst_dox.h b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/inc/x86_64_ufispace_s9500_22xst/x86_64_ufispace_s9500_22xst_dox.h new file mode 100755 index 0000000000..2a6965256b --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/inc/x86_64_ufispace_s9500_22xst/x86_64_ufispace_s9500_22xst_dox.h @@ -0,0 +1,26 @@ +/**************************************************************************//** + * + * x86_64_ufispace_s9500_22xst Doxygen Header + * + *****************************************************************************/ +#ifndef __x86_64_ufispace_s9500_22xst_DOX_H__ +#define __x86_64_ufispace_s9500_22xst_DOX_H__ + +/** + * @defgroup x86_64_ufispace_s9500_22xst x86_64_ufispace_s9500_22xst - x86_64_ufispace_s9500_22xst Description + * + +The documentation overview for this module should go here. + + * + * @{ + * + * @defgroup x86_64_ufispace_s9500_22xst-x86_64_ufispace_s9500_22xst Public Interface + * @defgroup x86_64_ufispace_s9500_22xst-config Compile Time Configuration + * @defgroup x86_64_ufispace_s9500_22xst-porting Porting Macros + * + * @} + * + */ + +#endif /* __x86_64_ufispace_s9500_22xst_DOX_H__ */ diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/inc/x86_64_ufispace_s9500_22xst/x86_64_ufispace_s9500_22xst_porting.h b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/inc/x86_64_ufispace_s9500_22xst/x86_64_ufispace_s9500_22xst_porting.h new file mode 100755 index 0000000000..fc2c9b87d9 --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/inc/x86_64_ufispace_s9500_22xst/x86_64_ufispace_s9500_22xst_porting.h @@ -0,0 +1,96 @@ +/********************************************************//** + * + * @file + * @brief x86_64_Ufispace_s9500_22xst Porting Macros. + * + * @addtogroup x86_64_Ufispace_s9500_22xst-porting + * @{ + * + ***********************************************************/ +#ifndef __X86_64_UFISPACE_S9500_22XST_PORTING_H__ +#define __X86_64_UFISPACE_S9500_22XST_PORTING_H__ + +/* */ +#if X86_64_UFISPACE_S9500_22XST_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS == 1 +#include +#include +#include +#include +#include +#endif + +#ifndef X86_64_UFISPACE_S9500_22XST_MALLOC + #if defined(GLOBAL_MALLOC) + #define X86_64_UFISPACE_S9500_22XST_MALLOC GLOBAL_MALLOC + #elif X86_64_UFISPACE_S9500_22XST_CONFIG_PORTING_STDLIB == 1 + #define X86_64_UFISPACE_S9500_22XST_MALLOC malloc + #else + #error The macro X86_64_UFISPACE_S9500_22XST_MALLOC is required but cannot be defined. + #endif +#endif + +#ifndef X86_64_UFISPACE_S9500_22XST_FREE + #if defined(GLOBAL_FREE) + #define X86_64_UFISPACE_S9500_22XST_FREE GLOBAL_FREE + #elif X86_64_UFISPACE_S9500_22XST_CONFIG_PORTING_STDLIB == 1 + #define X86_64_UFISPACE_S9500_22XST_FREE free + #else + #error The macro X86_64_UFISPACE_S9500_22XST_FREE is required but cannot be defined. + #endif +#endif + +#ifndef X86_64_UFISPACE_S9500_22XST_MEMSET + #if defined(GLOBAL_MEMSET) + #define X86_64_UFISPACE_S9500_22XST_MEMSET GLOBAL_MEMSET + #elif X86_64_UFISPACE_S9500_22XST_CONFIG_PORTING_STDLIB == 1 + #define X86_64_UFISPACE_S9500_22XST_MEMSET memset + #else + #error The macro X86_64_UFISPACE_S9500_22XST_MEMSET is required but cannot be defined. + #endif +#endif + +#ifndef X86_64_UFISPACE_S9500_22XST_MEMCPY + #if defined(GLOBAL_MEMCPY) + #define X86_64_UFISPACE_S9500_22XST_MEMCPY GLOBAL_MEMCPY + #elif X86_64_UFISPACE_S9500_22XST_CONFIG_PORTING_STDLIB == 1 + #define X86_64_UFISPACE_S9500_22XST_MEMCPY memcpy + #else + #error The macro X86_64_UFISPACE_S9500_22XST_MEMCPY is required but cannot be defined. + #endif +#endif + +#ifndef X86_64_UFISPACE_S9500_22XST_VSNPRINTF + #if defined(GLOBAL_VSNPRINTF) + #define X86_64_UFISPACE_S9500_22XST_VSNPRINTF GLOBAL_VSNPRINTF + #elif X86_64_UFISPACE_S9500_22XST_CONFIG_PORTING_STDLIB == 1 + #define X86_64_UFISPACE_S9500_22XST_VSNPRINTF vsnprintf + #else + #error The macro X86_64_UFISPACE_S9500_22XST_VSNPRINTF is required but cannot be defined. + #endif +#endif + +#ifndef X86_64_UFISPACE_S9500_22XST_SNPRINTF + #if defined(GLOBAL_SNPRINTF) + #define X86_64_UFISPACE_S9500_22XST_SNPRINTF GLOBAL_SNPRINTF + #elif X86_64_UFISPACE_S9500_22XST_CONFIG_PORTING_STDLIB == 1 + #define X86_64_UFISPACE_S9500_22XST_SNPRINTF snprintf + #else + #error The macro X86_64_UFISPACE_S9500_22XST_SNPRINTF is required but cannot be defined. + #endif +#endif + +#ifndef X86_64_UFISPACE_S9500_22XST_STRLEN + #if defined(GLOBAL_STRLEN) + #define X86_64_UFISPACE_S9500_22XST_STRLEN GLOBAL_STRLEN + #elif X86_64_UFISPACE_S9500_22XST_CONFIG_PORTING_STDLIB == 1 + #define X86_64_UFISPACE_S9500_22XST_STRLEN strlen + #else + #error The macro X86_64_UFISPACE_S9500_22XST_STRLEN is required but cannot be defined. + #endif +#endif + +/* */ + + +#endif /* __X86_64_UFISPACE_S9500_22XST_PORTING_H__ */ +/* @} */ diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/make.mk b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/make.mk new file mode 100755 index 0000000000..31653f867e --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/make.mk @@ -0,0 +1,29 @@ +############################################################ +# +# +# Copyright 2014, 2015 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. +# +# +############################################################ +# +# +# +############################################################ +THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) +x86_64_ufispace_s9500_22xst_INCLUDES := -I $(THIS_DIR)inc +x86_64_ufispace_s9500_22xst_INTERNAL_INCLUDES := -I $(THIS_DIR)src +x86_64_ufispace_s9500_22xst_DEPENDMODULE_ENTRIES := init:x86_64_ufispace_s9500_22xst ucli:x86_64_ufispace_s9500_22xst + diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/Makefile b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/Makefile new file mode 100755 index 0000000000..22931cb692 --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/Makefile @@ -0,0 +1,30 @@ +############################################################ +# +# +# Copyright 2014, 2015 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. +# +# +############################################################ +# +# Local source generation targets. +# +############################################################ + +include ../../../../init.mk + +ucli: + $(SUBMODULE_BIGCODE)/tools/uclihandlers.py x86_64_ufispace_s9500_22xst_ucli.c + diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/fani.c b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/fani.c new file mode 100755 index 0000000000..3690f36f3f --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/fani.c @@ -0,0 +1,145 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 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 "x86_64_ufispace_s9500_22xst_int.h" +#include +#include +#include "platform_lib.h" + +onlp_fan_info_t fan_info[] = { + { }, /* Not used */ + { + { FAN_OID_FAN1, "Chassis Fan - 1", 0 }, + ONLP_FAN_STATUS_PRESENT | ONLP_FAN_STATUS_F2B, + ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE, + 0, + 0, + ONLP_FAN_MODE_INVALID, + }, + { + { FAN_OID_FAN2, "Chassis Fan - 2", 0 }, + ONLP_FAN_STATUS_PRESENT | ONLP_FAN_STATUS_F2B, + ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE, + 0, + 0, + ONLP_FAN_MODE_INVALID, + }, + { + { FAN_OID_FAN3, "Chassis Fan - 3", 0 }, + ONLP_FAN_STATUS_PRESENT | ONLP_FAN_STATUS_F2B, + ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE, + 0, + 0, + ONLP_FAN_MODE_INVALID, + }, + { + { FAN_OID_PSU0_FAN, "PSU 1 - Fan", 0 }, + ONLP_FAN_STATUS_PRESENT | ONLP_FAN_STATUS_F2B, + ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE, + 0, + 0, + ONLP_FAN_MODE_INVALID, + }, + { + { FAN_OID_PSU1_FAN, "PSU 2 - Fan", 0 }, + ONLP_FAN_STATUS_PRESENT | ONLP_FAN_STATUS_F2B, + ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE, + 0, + 0, + ONLP_FAN_MODE_INVALID, + } +}; + +/* + * This function will be called prior to all of onlp_fani_* functions. + */ +int +onlp_fani_init(void) +{ + lock_init(); + return ONLP_STATUS_OK; +} + +int sys_fan_present_get(onlp_fan_info_t* info, int id) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +int +sys_fan_info_get(onlp_fan_info_t* info, int id) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +int +sys_fan_rpm_percent_set(int perc) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +int +onlp_fani_rpm_set(onlp_oid_t id, int rpm) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +/* + * This function sets the fan speed of the given OID as a percentage. + * + * This will only be called if the OID has the PERCENTAGE_SET + * capability. + * + * It is optional if you have no fans at all with this feature. + */ +int +onlp_fani_percentage_set(onlp_oid_t id, int percentage) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +int +onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* rv) +{ + int fan_id ,rc; + + fan_id = ONLP_OID_ID_GET(id); + *rv = fan_info[fan_id]; + rv->caps |= ONLP_FAN_CAPS_GET_RPM; + + switch (fan_id) { + case FAN_ID_FAN1: + case FAN_ID_FAN2: + case FAN_ID_FAN3: + case FAN_ID_PSU0_FAN: + case FAN_ID_PSU1_FAN: + rc = bmc_fan_info_get(rv, fan_id); + break; + default: + return ONLP_STATUS_E_INTERNAL; + break; + } + + return rc; +} diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/ledi.c b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/ledi.c new file mode 100755 index 0000000000..29d694097c --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/ledi.c @@ -0,0 +1,176 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 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 "platform_lib.h" + +/* + * Get the information for the given LED OID. + */ + +static onlp_led_info_t led_info[] = +{ + { }, // Not used * + { + { LED_OID_SYSTEM, "Chassis LED (SYS LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_YELLOW | ONLP_LED_CAPS_YELLOW_BLINKING | + ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING , + }, + { + { LED_OID_SYNC, "Chassis LED (SYNC LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_YELLOW | ONLP_LED_CAPS_YELLOW_BLINKING | + ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING , + }, + { + { LED_OID_GPS, "Chassis LED (GPS LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_YELLOW | ONLP_LED_CAPS_YELLOW_BLINKING | + ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING , + }, +}; + +/* + * This function will be called prior to any other onlp_ledi_* functions. + */ +int +onlp_ledi_init(void) +{ + lock_init(); + return ONLP_STATUS_OK; +} + +int +onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) +{ + int led_id, rc=ONLP_STATUS_OK; + + led_id = ONLP_OID_ID_GET(id); + *info = led_info[led_id]; + + switch (led_id) { + case LED_ID_SYS_SYS: + case LED_ID_SYS_SYNC: + case LED_ID_SYS_GPS: + rc = sys_led_info_get(info, led_id); + break; + default: + return ONLP_STATUS_E_INTERNAL; + break; + } + + return rc; +} + +/* + * 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) +{ + int led_id, rc=ONLP_STATUS_OK; + + led_id = ONLP_OID_ID_GET(id); + + switch (led_id) { + case LED_ID_SYS_SYS: + case LED_ID_SYS_SYNC: + case LED_ID_SYS_GPS: + rc = sys_led_set(led_id, on_or_off); + break; + default: + return ONLP_STATUS_E_INTERNAL; + break; + } + + return rc; +} + +/* + * 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 led_id, rc=ONLP_STATUS_OK; + int color, blink; + + led_id = ONLP_OID_ID_GET(id); + + switch (mode) { + case ONLP_LED_MODE_GREEN: + color = LED_COLOR_GREEN; + blink = LED_STABLE; + break; + case ONLP_LED_MODE_GREEN_BLINKING: + color = LED_COLOR_GREEN; + blink = LED_BLINKING; + break; + case ONLP_LED_MODE_YELLOW: + color = LED_COLOR_YELLOW; + blink = LED_STABLE; + break; + case ONLP_LED_MODE_YELLOW_BLINKING: + color = LED_COLOR_YELLOW; + blink = LED_BLINKING; + break; + default: + return ONLP_STATUS_E_INTERNAL; + break; + } + + switch (led_id) { + case LED_ID_SYS_SYS: + case LED_ID_SYS_SYNC: + case LED_ID_SYS_GPS: + rc = sys_led_mode_set(led_id, color, blink); + break; + default: + return ONLP_STATUS_E_INTERNAL; + break; + } + + return rc; +} + +int +onlp_ledi_ioctl(onlp_oid_t id, va_list vargs) +{ + return ONLP_STATUS_OK; +} diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/make.mk b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/make.mk new file mode 100755 index 0000000000..1ec99ebc30 --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/make.mk @@ -0,0 +1,29 @@ +############################################################ +# +# +# Copyright 2014, 2015 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. +# +# +############################################################ +# +# +# +############################################################ + +LIBRARY := x86_64_ufispace_s9500_22xst +$(LIBRARY)_SUBDIR := $(dir $(lastword $(MAKEFILE_LIST))) +#$(LIBRARY)_LAST := 1 +include $(BUILDER)/lib.mk diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/platform_lib.c b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/platform_lib.c new file mode 100755 index 0000000000..a26f839391 --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/platform_lib.c @@ -0,0 +1,1573 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2013 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "platform_lib.h" + +const char * thermal_id_str[] = { + "", + "Temp_CPU", + "Temp_MAC", + "Temp_BMC", + "Temp_100GCage", + "Temp_DDR4", + "Temp_FANCARD1", + "Temp_FANCARD2", + "PSU0_Temp", + "PSU1_Temp", + "CPU_PACKAGE", + "CPU1", + "CPU2", + "CPU3", + "CPU4", + "HWM_Temp_AMB", + "HWM_Temp_PHY1", + "HWM_Temp_Heater" +}; + +const char * fan_id_str[] = { + "", + "FAN1_RPM", + "FAN2_RPM", + "FAN3_RPM", + "PSU0_FAN", + "PSU1_FAN", +}; + +const char * fan_id_presence_str[] = { + "", + "FAN1_PRSNT_H", + "FAN2_PRSNT_H", + "FAN3_PRSNT_H", +}; + +const char * psu_id_str[] = { + "", + "PSU0", + "PSU1", + "PSU0_Presence", + "PSU1_Presence", + "PSU0_POWEROK", + "PSU1_POWEROK", + "PSU0_VIN", + "PSU0_VOUT", + "PSU0_IIN", + "PSU0_IOUT", + "PSU1_VIN", + "PSU1_VOUT", + "PSU1_IIN", + "PSU1_IOUT", +}; + +bmc_info_t bmc_cache[] = +{ + {"Temp_CPU", 0}, + {"Temp_MAC", 0}, + {"Temp_BMC", 0}, + {"Temp_100GCage", 0}, + {"Temp_DDR4", 0}, + {"Temp_FANCARD1", 0}, + {"Temp_FANCARD2", 0}, + {"PSU0_Temp", 0}, + {"PSU1_Temp", 0}, + {"FAN_1", 0}, + {"FAN_2", 0}, + {"FAN_3", 0}, + {"PSU0_FAN", 0}, + {"PSU1_FAN", 0}, + {"Fan1_Presence", 0}, + {"Fan2_Presence", 0}, + {"Fan3_Presence", 0}, + {"PSU0_Presence", 0}, + {"PSU1_Presence", 0}, + {"PSU0_POWEROK", 0}, + {"PSU1_POWEROK", 0}, + {"PSU0_VIN", 0}, + {"PSU0_VOUT", 0}, + {"PSU0_IIN",0}, + {"PSU0_IOUT",0}, + {"PSU1_VIN", 0}, + {"PSU1_VOUT", 0}, + {"PSU1_IIN", 0}, + {"PSU1_IOUT", 0}, + {"HWM_Temp_AMB", 0}, + {"HWM_Temp_PHY1", 0}, + {"HWM_Temp_Heater", 0} +}; + +static onlp_shlock_t* onlp_lock = NULL; + +#define ONLP_LOCK() \ + do{ \ + onlp_shlock_take(onlp_lock); \ + }while(0) + +#define ONLP_UNLOCK() \ + do{ \ + onlp_shlock_give(onlp_lock); \ + }while(0) + +#define LOCK_MAGIC 0xA2B4C6D8 + +void lock_init() +{ + static int sem_inited = 0; + if(!sem_inited) + { + onlp_shlock_create(LOCK_MAGIC, &onlp_lock, "bmc-file-lock"); + sem_inited = 1; + } +} + +int check_file_exist(char *file_path, long *file_time) +{ + struct stat file_info; + + if(stat(file_path, &file_info) == 0) { + if(file_info.st_size == 0) { + return 0; + } + else { + *file_time = file_info.st_mtime; + return 1; + } + } + else { + return 0; + } +} + +int bmc_cache_expired_check(long last_time, long new_time, int cache_time) +{ + int bmc_cache_expired = 0; + + if(last_time == 0) { + bmc_cache_expired = 1; + } + else { + if(new_time > last_time) { + if((new_time - last_time) > cache_time) { + bmc_cache_expired = 1; + } + else { + bmc_cache_expired = 0; + } + } + else if(new_time == last_time) { + bmc_cache_expired = 0; + } + else { + bmc_cache_expired = 1; + } + } + + return bmc_cache_expired; +} + +int bmc_sensor_read(int bmc_cache_index, int sensor_type, float *data) +{ + struct timeval new_tv; + FILE *fp = NULL; + char ipmi_cmd[400] = {0}; + char get_data_cmd[120] = {0}; + char buf[20]; + int rv = ONLP_STATUS_OK; + int dev_num = 0; + int dev_size = sizeof(bmc_cache)/sizeof(bmc_cache[0]); + int cache_time = 0; + int bmc_cache_expired = 0; + float f_rv = 0; + long file_last_time = 0; + static long bmc_cache_time = 0; + char* presence_str = "Present"; + + switch(sensor_type) { + case FAN_SENSOR: + cache_time = FAN_CACHE_TIME; + break; + case PSU_SENSOR: + cache_time = PSU_CACHE_TIME; + break; + case THERMAL_SENSOR: + cache_time = THERMAL_CACHE_TIME; + break; + } + + if(check_file_exist(BMC_SENSOR_CACHE, &file_last_time)) + { + gettimeofday(&new_tv, NULL); + if(bmc_cache_expired_check(file_last_time, new_tv.tv_sec, cache_time)) { + bmc_cache_expired = 1; + } + else { + bmc_cache_expired = 0; + } + } + else { + bmc_cache_expired = 1; + } + + if(bmc_cache_time == 0 && check_file_exist(BMC_SENSOR_CACHE, &file_last_time)) { + bmc_cache_expired = 1; + gettimeofday(&new_tv,NULL); + bmc_cache_time = new_tv.tv_sec; + } + + //update cache + if(bmc_cache_expired == 1) + { + ONLP_LOCK(); + if(bmc_cache_expired_check(file_last_time, bmc_cache_time, cache_time)) { + snprintf(ipmi_cmd, sizeof(ipmi_cmd), CMD_BMC_SENSOR_CACHE); + system(ipmi_cmd); + } + + for(dev_num = 0; dev_num < dev_size; dev_num++) + { + memset(buf, 0, sizeof(buf)); + + if( dev_num >= 14 && dev_num <=18 ) { + /* FanX_Presence */ + snprintf(get_data_cmd, sizeof(get_data_cmd), CMD_BMC_CACHE_GET, bmc_cache[dev_num].name, 5); + fp = popen(get_data_cmd, "r"); + if(fp != NULL) + { + if(fgets(buf, sizeof(buf), fp) != NULL) + { + if( strstr(buf, presence_str) != NULL ) { + f_rv = 1; + } else { + f_rv = 0; + } + bmc_cache[dev_num].data = f_rv; + } + } + pclose(fp); + } else { + snprintf(get_data_cmd, sizeof(get_data_cmd), CMD_BMC_CACHE_GET, bmc_cache[dev_num].name, 2); + + fp = popen(get_data_cmd, "r"); + if(fp != NULL) + { + if(fgets(buf, sizeof(buf), fp) != NULL) { + f_rv = atof(buf); + bmc_cache[dev_num].data = f_rv; + } + } + pclose(fp); + } + + } + gettimeofday(&new_tv,NULL); + bmc_cache_time = new_tv.tv_sec; + ONLP_UNLOCK(); + } + + //read from cache + *data = bmc_cache[bmc_cache_index].data; + + return rv; +} + +int +psu_thermal_get(onlp_thermal_info_t* info, int thermal_id) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +int +psu_fan_info_get(onlp_fan_info_t* info, int id) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +int +psu_vin_get(onlp_psu_info_t* info, int id) +{ + int i=0, token_idx=1, token_val=0; + + char cmd[48]; + char cmd_out[150]; + char* tokens[20]; + char delimiter[]=","; + const char* sensor_str; + + memset(cmd, 0, sizeof(cmd)); + memset(cmd_out, 0, sizeof(cmd_out)); + + sensor_str = (id == PSU_ID_PSU0 ? psu_id_str[PSU_ID_PSU0_VIN] : psu_id_str[PSU_ID_PSU1_VIN]); + snprintf(cmd, sizeof(cmd), CMD_BMC_SDR_GET, sensor_str); + + //Get sensor info from BMC + if (exec_cmd(cmd, cmd_out, sizeof(cmd_out)) < 0) { + AIM_LOG_ERROR("unable to read sensor info from BMC, sensor=%s\n", sensor_str); + return ONLP_STATUS_E_INTERNAL; + } + + //Check output is correct + if (strnlen(cmd_out, sizeof(cmd_out))==0 || + strchr(cmd_out, ',')==NULL || + strstr(cmd_out, sensor_str)==NULL ){ + AIM_LOG_ERROR("unable to read sensor info from BMC, sensor=%s, cmd=%s, out=%s\n", sensor_str, cmd, cmd_out); + return ONLP_STATUS_E_INTERNAL; + } + + //parse cmd_out to tokens + tokens[i++] = strtok(cmd_out, delimiter); + while (tokens[i-1] != NULL) { + tokens[i++] = strtok(NULL, delimiter); + } + + //read token_idx field + if (i>=token_idx) { + token_val = (int) (atof(tokens[token_idx])*1000); + info->mvin = token_val; + info->caps |= ONLP_PSU_CAPS_VIN; + } else { + AIM_LOG_ERROR("unable to read sensor info from BMC, sensor=%s, cmd=%s, out=%s\n", sensor_str, cmd, cmd_out); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +int +psu_vout_get(onlp_psu_info_t* info, int id) +{ + int i=0, token_idx=1, token_val=0; + + char cmd[48]; + char cmd_out[150]; + char* tokens[20]; + char delimiter[]=","; + const char* sensor_str; + + memset(cmd, 0, sizeof(cmd)); + memset(cmd_out, 0, sizeof(cmd_out)); + + sensor_str = (id == PSU_ID_PSU0 ? psu_id_str[PSU_ID_PSU0_VOUT] : psu_id_str[PSU_ID_PSU1_VOUT]); + snprintf(cmd, sizeof(cmd), CMD_BMC_SDR_GET, sensor_str); + + //Get sensor info from BMC + if (exec_cmd(cmd, cmd_out, sizeof(cmd_out)) < 0) { + AIM_LOG_ERROR("unable to read sensor info from BMC, sensor=%s\n", sensor_str); + return ONLP_STATUS_E_INTERNAL; + } + + //Check output is correct + if (strnlen(cmd_out, sizeof(cmd_out))==0 || + strchr(cmd_out, ',')==NULL || + strstr(cmd_out, sensor_str)==NULL ){ + AIM_LOG_ERROR("unable to read sensor info from BMC, sensor=%s, cmd=%s, out=%s\n", sensor_str, cmd, cmd_out); + return ONLP_STATUS_E_INTERNAL; + } + + //parse cmd_out to tokens + tokens[i++] = strtok(cmd_out, delimiter); + while (tokens[i-1] != NULL) { + tokens[i++] = strtok(NULL, delimiter); + } + + //read token_idx field + if (i>=token_idx) { + token_val = (int) (atof(tokens[token_idx])*1000); + info->mvout = token_val; + info->caps |= ONLP_PSU_CAPS_VOUT; + } else { + AIM_LOG_ERROR("unable to read sensor info from BMC, sensor=%s, cmd=%s, out=%s\n", sensor_str, cmd, cmd_out); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +int +psu_iin_get(onlp_psu_info_t* info, int id) +{ + int i=0, token_idx=1, token_val=0; + + char cmd[48]; + char cmd_out[150]; + char* tokens[20]; + char delimiter[]=","; + const char* sensor_str; + + memset(cmd, 0, sizeof(cmd)); + memset(cmd_out, 0, sizeof(cmd_out)); + + sensor_str = (id == PSU_ID_PSU0 ? psu_id_str[PSU_ID_PSU0_IIN] : psu_id_str[PSU_ID_PSU1_IIN]); + snprintf(cmd, sizeof(cmd), CMD_BMC_SDR_GET, sensor_str); + + //Get sensor info from BMC + if (exec_cmd(cmd, cmd_out, sizeof(cmd_out)) < 0) { + AIM_LOG_ERROR("unable to read sensor info from BMC, sensor=%s\n", sensor_str); + return ONLP_STATUS_E_INTERNAL; + } + + //Check output is correct + if (strnlen(cmd_out, sizeof(cmd_out))==0 || + strchr(cmd_out, ',')==NULL || + strstr(cmd_out, sensor_str)==NULL ){ + AIM_LOG_ERROR("unable to read sensor info from BMC, sensor=%s, cmd=%s, out=%s\n", sensor_str, cmd, cmd_out); + return ONLP_STATUS_E_INTERNAL; + } + + //parse cmd_out to tokens + tokens[i++] = strtok(cmd_out, delimiter); + while (tokens[i-1] != NULL) { + tokens[i++] = strtok(NULL, delimiter); + } + + //read token_idx field + if (i>=token_idx) { + token_val = (int) (atof(tokens[token_idx])*1000); + info->miin = token_val; + info->caps |= ONLP_PSU_CAPS_IIN; + } else { + AIM_LOG_ERROR("unable to read sensor info from BMC, sensor=%s, cmd=%s, out=%s\n", sensor_str, cmd, cmd_out); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +int +psu_iout_get(onlp_psu_info_t* info, int id) +{ + int i=0, token_idx=1, token_val=0; + + char cmd[48]; + char cmd_out[150]; + char* tokens[20]; + char delimiter[]=","; + const char* sensor_str; + + memset(cmd, 0, sizeof(cmd)); + memset(cmd_out, 0, sizeof(cmd_out)); + + sensor_str = (id == PSU_ID_PSU0 ? psu_id_str[PSU_ID_PSU0_IOUT] : psu_id_str[PSU_ID_PSU1_IOUT]); + snprintf(cmd, sizeof(cmd), CMD_BMC_SDR_GET, sensor_str); + + //Get sensor info from BMC + if (exec_cmd(cmd, cmd_out, sizeof(cmd_out)) < 0) { + AIM_LOG_ERROR("unable to read sensor info from BMC, sensor=%s\n", sensor_str); + return ONLP_STATUS_E_INTERNAL; + } + + //Check output is correct + if (strnlen(cmd_out, sizeof(cmd_out))==0 || + strchr(cmd_out, ',')==NULL || + strstr(cmd_out, sensor_str)==NULL ){ + AIM_LOG_ERROR("unable to read sensor info from BMC, sensor=%s, cmd=%s, out=%s\n", sensor_str, cmd, cmd_out); + return ONLP_STATUS_E_INTERNAL; + } + + //parse cmd_out to tokens + tokens[i++] = strtok(cmd_out, delimiter); + while (tokens[i-1] != NULL) { + tokens[i++] = strtok(NULL, delimiter); + } + + //read token_idx field + if (i>=token_idx) { + token_val = (int) (atof(tokens[token_idx])*1000); + info->miout = token_val; + info->caps |= ONLP_PSU_CAPS_IOUT; + } else { + AIM_LOG_ERROR("unable to read sensor info from BMC, sensor=%s, cmd=%s, out=%s\n", sensor_str, cmd, cmd_out); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +int +psu_pout_get(onlp_psu_info_t* info, int i2c_bus) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +int +psu_pin_get(onlp_psu_info_t* info, int i2c_bus) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +int +psu_eeprom_get(onlp_psu_info_t* info, int id) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +int +psu_fru_get(onlp_psu_info_t* info, int id) +{ + char cmd[100]; + char cmd_out[150]; + char fru_model[] = "Product Name"; //only Product Name can identify AC/DC + char fru_serial[] = "Product Serial"; + + //FRU (model) + + memset(cmd, 0, sizeof(cmd)); + memset(cmd_out, 0, sizeof(cmd_out)); + memset(info->model, 0, sizeof(info->model)); + + snprintf(cmd, sizeof(cmd), CMD_FRU_INFO_GET, id, fru_model); + + //Get psu fru info (model) from BMC + if (exec_cmd(cmd, cmd_out, sizeof(cmd_out)) < 0) { + AIM_LOG_ERROR("unable to read fru info from BMC, fru id=%d, cmd=%s, out=%s\n", id, cmd, cmd_out); + return ONLP_STATUS_E_INTERNAL; + } + + //Check output is correct + if (strnlen(cmd_out, sizeof(cmd_out))==0){ + AIM_LOG_ERROR("unable to read fru info from BMC, fru id=%d, cmd=%s, out=%s\n", id, cmd, cmd_out); + return ONLP_STATUS_E_INTERNAL; + } + + snprintf(info->model, sizeof(info->model), "%s", cmd_out); + + //FRU (serial) + + memset(cmd, 0, sizeof(cmd)); + memset(cmd_out, 0, sizeof(cmd_out)); + memset(info->serial, 0, sizeof(info->serial)); + + snprintf(cmd, sizeof(cmd), CMD_FRU_INFO_GET, id, fru_serial); + + //Get psu fru info (model) from BMC + if (exec_cmd(cmd, cmd_out, sizeof(cmd_out)) < 0) { + AIM_LOG_ERROR("unable to read fru info from BMC, fru id=%d, cmd=%s, out=%s\n", id, cmd, cmd_out); + return ONLP_STATUS_E_INTERNAL; + } + + //Check output is correct + if (strnlen(cmd_out, sizeof(cmd_out))==0){ + AIM_LOG_ERROR("unable to read fru info from BMC, fru id=%d, cmd=%s, out=%s\n", id, cmd, cmd_out); + return ONLP_STATUS_E_INTERNAL; + } + + snprintf(info->serial, sizeof(info->serial), "%s", cmd_out); + + return ONLP_STATUS_OK; +} + +int +psu_present_get(int *pw_present, int id) +{ + FILE *fp = NULL; + char buf[20]; + char get_data_cmd[120] = {0}; + char psu_present[20] = {0}; + int dev_num; + int dev_size = sizeof(bmc_cache)/sizeof(bmc_cache[0]); + char* presence_str = "Present"; + + if (id == PSU_ID_PSU0) { + strcpy(psu_present, "PSU0_Presence"); + } else if (id == PSU_ID_PSU1) { + strcpy(psu_present, "PSU1_Presence"); + } else { + return ONLP_STATUS_E_INTERNAL; + } + + for (dev_num = 0; dev_num < dev_size; dev_num++) { + if (strcmp(bmc_cache[dev_num].name, psu_present) != 0) + continue; + + snprintf(get_data_cmd, sizeof(get_data_cmd), CMD_BMC_CACHE_GET, bmc_cache[dev_num].name, 5); + fp = popen(get_data_cmd, "r"); + if (fp != NULL) { + if (fgets(buf, sizeof(buf), fp) != NULL) { + if (strstr(buf, presence_str) != NULL) { + *pw_present = 1; + } else { + *pw_present = 0; + } + } + } + pclose(fp); + } + + return ONLP_STATUS_OK; +} + +int +psu_pwgood_get(int *pw_good, int id) +{ + FILE *fp = NULL; + char buf[20]; + char get_data_cmd[120] = {0}; + char psu_pwgood[20] = {0}; + int dev_num; + int dev_size = sizeof(bmc_cache)/sizeof(bmc_cache[0]); + char* pwgood_str = "Enabled"; + + if (id == PSU_ID_PSU0) { + strcpy(psu_pwgood, "PSU0_POWEROK"); + } else if (id == PSU_ID_PSU1) { + strcpy(psu_pwgood, "PSU1_POWEROK"); + } else { + return ONLP_STATUS_E_INTERNAL; + } + + for (dev_num = 0; dev_num < dev_size; dev_num++) { + if (strcmp(bmc_cache[dev_num].name, psu_pwgood) != 0) + continue; + + snprintf(get_data_cmd, sizeof(get_data_cmd), CMD_BMC_CACHE_GET, bmc_cache[dev_num].name, 5); + fp = popen(get_data_cmd, "r"); + if (fp != NULL) { + if (fgets(buf, sizeof(buf), fp) != NULL) { + if (strstr(buf, pwgood_str) != NULL) { + *pw_good = 1; + } else { + *pw_good = 0; + } + } else { + pclose(fp); + return ONLP_STATUS_E_INTERNAL; + } + } else { + return ONLP_STATUS_E_INTERNAL; + } + pclose(fp); + break; + } + + return ONLP_STATUS_OK; +} + +int +qsfp_present_get(int port, int *pres_val) +{ + int status, rc; + int gpio_num = 0, gpio_base1 = 453, gpio_base2 = 452; + uint8_t data[8]; + int data_len; + + memset(data, 0, sizeof(data)); + + //for qsfp port 0&1 + if (port < (RJ45_NUM + SFP_NUM + SFP28_NUM) || port >= PORT_NUM) { + AIM_LOG_ERROR("Invalid QSFP ports, port=%d\n", port); + return ONLP_STATUS_E_INTERNAL; + } + + //gpio_num = gpio_base - (port - SFP_NUM - SFP28_NUM); + //only have 2 qsfp: 20,21 + gpio_num = (port == 20)?gpio_base1:gpio_base2; + + if ((rc = onlp_file_read(data, sizeof(data), &data_len, + "/sys/class/gpio/gpio%d/value", gpio_num)) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("onlp_file_read failed, error=%d, /sys/class/gpio/gpio%d/value", + rc, gpio_num); + return ONLP_STATUS_E_INTERNAL; + } + status = (int) strtol((char *)data, NULL, 0); + + *pres_val = !status; + + return ONLP_STATUS_OK; +} + +int +sfp_present_get(int port, int *pres_val) +{ + int status, rc; + int gpio_num = 0, gpio_base[3] = {383, 367, 355}; + uint8_t data[8]; + int data_len; + + memset(data, 0, sizeof(data)); + + //for sfp port 4~19 + if (port >= 0 && port < 4) { + AIM_LOG_ERROR("Invalid SFP ports, port=%d\n", port); + return ONLP_STATUS_E_INTERNAL; + } else if (port < 12) { + gpio_num = gpio_base[0] - (port - 4); + } else if (port < 16) { + gpio_num = gpio_base[2] - (port - 12); + } else if (port < 20) { + gpio_num = gpio_base[1] - (port - 16); + } else { + AIM_LOG_ERROR("Invalid SFP ports, port=%d\n", port); + return ONLP_STATUS_E_INTERNAL; + } + + if ((rc = onlp_file_read(data, sizeof(data), &data_len, + "/sys/class/gpio/gpio%d/value", gpio_num)) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("onlp_file_read failed, error=%d, /sys/class/gpio/gpio%d/value", + rc, gpio_num); + return ONLP_STATUS_E_INTERNAL; + } + status = (int) strtol((char *)data, NULL, 0); + + *pres_val = !status; + + return ONLP_STATUS_OK; +} + +int +sfp_rx_los_get(int port, int *ctrl_val) +{ + int status, rc; + int gpio_num = 0, gpio_base[3] = {351, 335, 323}; + uint8_t data[8]; + int data_len; + + memset(data, 0, sizeof(data)); + + //for sfp port 4~19 + if (port >= 0 && port < 4) { + AIM_LOG_ERROR("Invalid SFP ports, port=%d\n", port); + return ONLP_STATUS_E_INTERNAL; + } else if (port < 12) { + gpio_num = gpio_base[0] - (port - 4); + } else if (port < 16) { + gpio_num = gpio_base[2] - (port - 12); + } else if (port < 20) { + gpio_num = gpio_base[1] - (port - 16); + } else { + AIM_LOG_ERROR("Invalid SFP ports, port=%d\n", port); + return ONLP_STATUS_E_INTERNAL; + } + + if ((rc = onlp_file_read(data, sizeof(data), &data_len, + "/sys/class/gpio/gpio%d/value", gpio_num)) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("onlp_file_read failed, error=%d, /sys/class/gpio/gpio%d/value", + rc, gpio_num); + return ONLP_STATUS_E_INTERNAL; + } + status = (int) strtol((char *)data, NULL, 0); + + *ctrl_val = status; + + return ONLP_STATUS_OK; +} + +int +sfp_tx_fault_get(int port, int *ctrl_val) +{ + int status, rc; + int gpio_num = 0, gpio_base[3] = {447, 431, 419}; + uint8_t data[8]; + int data_len; + + memset(data, 0, sizeof(data)); + + //for sfp port 4~19 + if (port >= 0 && port < 4) { + AIM_LOG_ERROR("Invalid SFP ports, port=%d\n", port); + return ONLP_STATUS_E_INTERNAL; + } else if (port < 12) { + gpio_num = gpio_base[0] - (port - 4); + } else if (port < 16) { + gpio_num = gpio_base[2] - (port - 12); + } else if (port < 20) { + gpio_num = gpio_base[1] - (port - 16); + } else { + AIM_LOG_ERROR("Invalid SFP ports, port=%d\n", port); + return ONLP_STATUS_E_INTERNAL; + } + + if ((rc = onlp_file_read(data, sizeof(data), &data_len, + "/sys/class/gpio/gpio%d/value", gpio_num)) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("onlp_file_read failed, error=%d, /sys/class/gpio/gpio%d/value", + rc, gpio_num); + return ONLP_STATUS_E_INTERNAL; + } + status = (int) strtol((char *)data, NULL, 0); + + *ctrl_val = status; + + return ONLP_STATUS_OK; +} + +int +sfp_tx_disable_get(int port, int *ctrl_val) +{ + int status, rc; + int gpio_num = 0, gpio_base[3] = {495, 479, 467}; + uint8_t data[8]; + int data_len; + + memset(data, 0, sizeof(data)); + + //for sfp port 4~19 + if (port >= 0 && port < 4) { + AIM_LOG_ERROR("Invalid SFP ports, port=%d\n", port); + return ONLP_STATUS_E_INTERNAL; + } else if (port < 12) { + gpio_num = gpio_base[0] - (port - 4); + } else if (port < 16) { + gpio_num = gpio_base[2] - (port - 12); + } else if (port < 20) { + gpio_num = gpio_base[1] - (port - 16); + } else { + AIM_LOG_ERROR("Invalid SFP ports, port=%d\n", port); + return ONLP_STATUS_E_INTERNAL; + } + + if ((rc = onlp_file_read(data, sizeof(data), &data_len, + "/sys/class/gpio/gpio%d/value", gpio_num)) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("onlp_file_read failed, error=%d, /sys/class/gpio/gpio%d/value", + rc, gpio_num); + return ONLP_STATUS_E_INTERNAL; + } + status = (int) strtol((char *)data, NULL, 0); + + *ctrl_val = status; + + return ONLP_STATUS_OK; +} + +int +qsfp_lp_mode_get(int port, int *ctrl_val) +{ + int status, rc; + int gpio_num = 0, gpio_base1 = 457, gpio_base2 = 456; + uint8_t data[8]; + int data_len; + + memset(data, 0, sizeof(data)); + + //for qsfp port 0&1 + if (port < (RJ45_NUM + SFP_NUM + SFP28_NUM) || port >= PORT_NUM) { + AIM_LOG_ERROR("Invalid QSFP ports, port=%d\n", port); + return ONLP_STATUS_E_INTERNAL; + } + + //gpio_num = gpio_base - (port - SFP_NUM - SFP28_NUM); + //only have 2 qsfp: 20,21 + gpio_num = (port == 20)?gpio_base1:gpio_base2; + + if ((rc = onlp_file_read(data, sizeof(data), &data_len, + "/sys/class/gpio/gpio%d/value", gpio_num)) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("onlp_file_read failed, error=%d, /sys/class/gpio/gpio%d/value", + rc, gpio_num); + return ONLP_STATUS_E_INTERNAL; + } + status = (int) strtol((char *)data, NULL, 0); + + *ctrl_val = status; + + return ONLP_STATUS_OK; +} + +int +qsfp_reset_get(int port, int *ctrl_val) +{ + int status, rc; + int gpio_num = 0, gpio_base1 = 461, gpio_base2 = 460; + uint8_t data[8]; + int data_len; + + memset(data, 0, sizeof(data)); + + //for qsfp port 0&1 + if (port < (RJ45_NUM + SFP_NUM + SFP28_NUM) || port >= PORT_NUM) { + AIM_LOG_ERROR("Invalid QSFP ports, port=%d\n", port); + return ONLP_STATUS_E_INTERNAL; + } + + //gpio_num = gpio_base - (port - SFP_NUM - SFP28_NUM); + //only have 2 qsfp: 20,21 + gpio_num = (port == 20)?gpio_base1:gpio_base2; + + if ((rc = onlp_file_read(data, sizeof(data), &data_len, + "/sys/class/gpio/gpio%d/value", gpio_num)) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("onlp_file_read failed, error=%d, /sys/class/gpio/gpio%d/value", + rc, gpio_num); + return ONLP_STATUS_E_INTERNAL; + } + status = (int) strtol((char *)data, NULL, 0); + + *ctrl_val = status; + + return ONLP_STATUS_OK; +} + +int +sfp_tx_disable_set(int port, int ctrl_val) +{ + int rc; + int gpio_num = 0, gpio_base[3] = {495, 479, 467}; + + + //for sfp port 4~19 + if (port >= 0 && port < 4) { + AIM_LOG_ERROR("Invalid SFP ports, port=%d\n", port); + return ONLP_STATUS_E_INTERNAL; + } else if (port < 12) { + gpio_num = gpio_base[0] - (port - 4); + } else if (port < 16) { + gpio_num = gpio_base[2] - (port - 12); + } else if (port < 20) { + gpio_num = gpio_base[1] - (port - 16); + } else { + AIM_LOG_ERROR("Invalid SFP ports, port=%d\n", port); + return ONLP_STATUS_E_INTERNAL; + } + + if ((rc = onlp_file_write_int(ctrl_val, "/sys/class/gpio/gpio%d/value", + gpio_num)) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("onlp_file_write_int failed, error=%d, /sys/class/gpio/gpio%d/value", + rc, gpio_num); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +int +qsfp_lp_mode_set(int port, int ctrl_val) +{ + int rc; + int gpio_num = 0, gpio_base1 = 457, gpio_base2 = 456; + + //for qsfp port 0&1 + if (port < (RJ45_NUM + SFP_NUM + SFP28_NUM) || port >= PORT_NUM) { + AIM_LOG_ERROR("Invalid QSFP ports, port=%d\n", port); + return ONLP_STATUS_E_INTERNAL; + } + + //gpio_num = gpio_base - (port - SFP_NUM - SFP28_NUM); + //only have 2 qsfp: 20,21 + gpio_num = (port == 20)?gpio_base1:gpio_base2; + + if ((rc = onlp_file_write_int(ctrl_val, "/sys/class/gpio/gpio%d/value", + gpio_num)) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("onlp_file_write_int failed, error=%d, /sys/class/gpio/gpio%d/value", + rc, gpio_num); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +int +qsfp_reset_set(int port, int ctrl_val) +{ + int rc; + int gpio_num = 0, gpio_base1 = 461, gpio_base2 = 460; + + //for qsfp port 0&1 + if (port < (RJ45_NUM + SFP_NUM + SFP28_NUM) || port >= PORT_NUM) { + AIM_LOG_ERROR("Invalid QSFP ports, port=%d\n", port); + return ONLP_STATUS_E_INTERNAL; + } + + //gpio_num = gpio_base - (port - SFP_NUM - SFP28_NUM); + //only have 2 qsfp: 20,21 + gpio_num = (port == 20)?gpio_base1:gpio_base2; + + if ((rc = onlp_file_write_int(ctrl_val, "/sys/class/gpio/gpio%d/value", + gpio_num)) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("onlp_file_write_int failed, error=%d, /sys/class/gpio/gpio%d/value", + rc, gpio_num); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +int +system_led_set(onlp_led_mode_t mode) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +int +fan_led_set(onlp_led_mode_t mode) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +int +psu1_led_set(onlp_led_mode_t mode) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +int +psu2_led_set(onlp_led_mode_t mode) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +int +fan_tray_led_set(onlp_oid_t id, onlp_led_mode_t mode) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +int +read_ioport(int addr, int *reg_val) { + int ret; + + /*set r/w permission of all 65536 ports*/ + ret = iopl(3); + if(ret < 0){ + AIM_LOG_ERROR("unable to read cpu cpld version, iopl enable error %d\n", ret); + return ONLP_STATUS_E_INTERNAL; + } + *reg_val = inb(addr); + + /*set r/w permission of all 65536 ports*/ + ret = iopl(0); + if(ret < 0){ + AIM_LOG_ERROR("unable to read cpu cpld version, iopl disable error %d\n", ret); + return ONLP_STATUS_E_INTERNAL; + } + return ONLP_STATUS_OK; +} + +int +write_ioport(int addr, int val) { + int ret; + + /*set r/w permission of all 65536 ports*/ + ret = iopl(3); + if(ret < 0){ + AIM_LOG_ERROR("unable to read cpu cpld version, iopl enable error %d\n", ret); + return ONLP_STATUS_E_INTERNAL; + } + outb(addr, val); + + /*set r/w permission of all 65536 ports*/ + ret = iopl(0); + if(ret < 0){ + AIM_LOG_ERROR("unable to read cpu cpld version, iopl disable error %d\n", ret); + return ONLP_STATUS_E_INTERNAL; + } + return ONLP_STATUS_OK; +} + +int +exec_cmd(char *cmd, char* out, int size) { + FILE *fp; + + /* Open the command for reading. */ + fp = popen(cmd, "r"); + if (fp == NULL) { + AIM_LOG_ERROR("Failed to run command %s\n", cmd ); + return ONLP_STATUS_E_INTERNAL; + } + + /* Read the output a line at a time - output it. */ + while (fgets(out, size-1, fp) != NULL) { + } + + /* close */ + pclose(fp); + + return ONLP_STATUS_OK; +} + +int +get_ipmitool_len(char *ipmitool_out){ + size_t str_len = 0, ipmitool_len = 0; + + str_len = strlen(ipmitool_out); + if (str_len > 0) { + ipmitool_len = str_len / 3; + } + return ipmitool_len; +} + +int +parse_ucd_out(char *ucd_out, char *ucd_data, int start, int len){ + int i; + char data[3]; + + memset(data, 0, sizeof(data)); + + for (i = 2; i < len; ++i) { + data[0] = ucd_out[(start+i)*3 + 1]; + data[1] = ucd_out[(start+i)*3 + 2]; + //hex string to int + ucd_data[i-2] = (int) strtol(data, NULL, 16); + } + return ONLP_STATUS_OK; +} + +int +sysi_platform_info_get(onlp_platform_info_t* pi) +{ + int cpu_cpld_ver_addr = 0x600, cpu_cpld_ver; + int mb_cpld_ver_addr = 0x702, mb_cpld_ver; + int mb_board_type = 0, mb_hw_rev = 0, mb_build_rev = 0, gpio_num, gpio_base = 319; + int i, data_tmp, data_len; + uint8_t data[8]; + char bios_out[32]; + char bmc_out1[8], bmc_out2[8], bmc_out3[8]; + char ucd_out[48]; + char ucd_ver[8]; + char ucd_date[8]; + int ucd_len=0; + int rc=0; + + memset(bios_out, 0, sizeof(bios_out)); + memset(bmc_out1, 0, sizeof(bmc_out1)); + memset(bmc_out2, 0, sizeof(bmc_out2)); + memset(bmc_out3, 0, sizeof(bmc_out3)); + memset(ucd_out, 0, sizeof(ucd_out)); + memset(ucd_ver, 0, sizeof(ucd_ver)); + memset(ucd_date, 0, sizeof(ucd_date)); + + //get CPU CPLD version + if (read_ioport(cpu_cpld_ver_addr, &cpu_cpld_ver) < 0) { + AIM_LOG_ERROR("unable to read CPU CPLD version\n"); + return ONLP_STATUS_E_INTERNAL; + } + + //get MB CPLD version + if (read_ioport(mb_cpld_ver_addr, &mb_cpld_ver) < 0) { + AIM_LOG_ERROR("unable to read MB CPLD version\n"); + return ONLP_STATUS_E_INTERNAL; + } + + pi->cpld_versions = aim_fstrdup( + "\n" + "[CPU CPLD] X.%02x\n" + "[MB CPLD] X.%02x\n", + cpu_cpld_ver); + + //Get HW Build Version + for (i = 0; i < 8; i++) { + gpio_num = gpio_base - i; + if ((rc = onlp_file_read(data, sizeof(data), &data_len, + "/sys/class/gpio/gpio%d/value", gpio_num)) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("onlp_file_read failed, error=%d, /sys/class/gpio/gpio%d/value", + rc, gpio_num); + return ONLP_STATUS_E_INTERNAL; + } + data_tmp = (int) strtol((char *)data, NULL, 0); + + if (i < 4) { + mb_board_type = mb_board_type * 2 + data_tmp; + } else if (i < 6) { + mb_hw_rev = mb_hw_rev * 2 + data_tmp; + } else { + mb_build_rev = mb_build_rev * 2 + data_tmp; + } + } + + //Get BIOS version + if (exec_cmd(CMD_BIOS_VER, bios_out, sizeof(bios_out)) < 0) { + AIM_LOG_ERROR("unable to read BIOS version\n"); + return ONLP_STATUS_E_INTERNAL; + } + + //Get BMC version + if (exec_cmd(CMD_BMC_VER_1, bmc_out1, sizeof(bmc_out1)) < 0 || + exec_cmd(CMD_BMC_VER_2, bmc_out2, sizeof(bmc_out2)) < 0 || + exec_cmd(CMD_BMC_VER_3, bmc_out3, sizeof(bmc_out3))) { + AIM_LOG_ERROR("unable to read BMC version\n"); + return ONLP_STATUS_E_INTERNAL; + } + + //get UCD version + if (exec_cmd(CMD_UCD_VER, ucd_out, sizeof(ucd_out)) < 0 ) { + AIM_LOG_ERROR("unable to read UCD version\n"); + return ONLP_STATUS_E_INTERNAL; + } + + //parse UCD version and date + ucd_len = get_ipmitool_len(ucd_out); + parse_ucd_out(ucd_out, ucd_ver, 0, ucd_len); + + pi->other_versions = aim_fstrdup( + "\n" + "[HW ] %d\n" + "[BUILD] %d\n" + "[BIOS ] %s\n" + "[BMC ] %d.%d.%d\n" + "[UCD ] %s\n", + mb_hw_rev, + mb_build_rev, + bios_out, + atoi(bmc_out1), atoi(bmc_out2), atoi(bmc_out3), + ucd_ver); + + return ONLP_STATUS_OK; +} + +bool +onlp_sysi_bmc_en_get(void) +{ +//enable bmc by default +#if 0 + int value; + + if (onlp_file_read_int(&value, BMC_EN_FILE_PATH) < 0) { + // flag file not exist, default to not enable + return false; + } + + /* 1 - enable, 0 - no enable */ + if ( value ) + return true; + + return false; +#endif + return true; +} + +int +parse_bmc_sdr_cmd(char *cmd_out, int cmd_out_size, + char *tokens[], int token_size, + const char *sensor_id_str, int *idx) +{ + char cmd[BMC_CMD_SDR_SIZE]; + char delimiter[]=","; + char delimiter_c = ','; + + *idx=0; + memset(cmd, 0, sizeof(cmd)); + memset(cmd_out, 0, cmd_out_size); + + snprintf(cmd, sizeof(cmd), CMD_BMC_SDR_GET, sensor_id_str); + + if (exec_cmd(cmd, cmd_out, cmd_out_size) < 0) { + AIM_LOG_ERROR("unable to read sensor info from BMC, sensor=%s\n", sensor_id_str); + return ONLP_STATUS_E_INTERNAL; + } + + //Check output is correct + if (strnlen(cmd_out, cmd_out_size)==0 || + strchr(cmd_out, delimiter_c)==NULL || + strstr(cmd_out, sensor_id_str)==NULL ){ + AIM_LOG_ERROR("unable to read sensor info from BMC, sensor=%s, out=%s\n", sensor_id_str, cmd_out); + return ONLP_STATUS_E_INTERNAL; + } + + //parse cmd_out to tokens + tokens[(*idx)++] = strtok(cmd_out, delimiter); + while (tokens[(*idx)-1] != NULL) { + tokens[(*idx)++] = strtok(NULL, delimiter); + } + + return ONLP_STATUS_OK; +} + +int +bmc_thermal_info_get(onlp_thermal_info_t* info, int id) +{ + int rc=0; + float data=0; + int presence = 0; + + //check presence for psu thermal + if (id >= THERMAL_ID_PSU0 && id <= THERMAL_ID_PSU1) { + rc = bmc_sensor_read(id + 9, THERMAL_SENSOR, &data); + if (rc != ONLP_STATUS_OK) { + AIM_LOG_ERROR("unable to read sensor info from BMC, sensor=%d\n", id); + return rc; + } + presence = (int) data; + + if (presence == 1) { + info->status |= ONLP_THERMAL_STATUS_PRESENT; + } else { + info->status &= ~ONLP_THERMAL_STATUS_PRESENT; + return ONLP_STATUS_OK; + } + } + + if (id >= THERMAL_ID_AMB && id <= THERMAL_ID_HEATER) { + rc = bmc_sensor_read(id + 13, THERMAL_SENSOR, &data); + } else { + rc = bmc_sensor_read(id - 1, THERMAL_SENSOR, &data); + } + if ( rc != ONLP_STATUS_OK) { + AIM_LOG_ERROR("unable to read sensor info from BMC, sensor=%d\n", id); + return rc; + } + info->mcelsius = (int) (data*1000); + + return rc; +} + +int +bmc_fan_info_get(onlp_fan_info_t* info, int id) +{ + int rv = 0, rpm = 0, percentage = 0; + int presence = 0; + float data = 0; + int sys_max_fan_speed = 25000; + int psu_max_fan_speed = 19800; + + //check presence for fantray 1-3 and psu fan + if (id >= FAN_ID_FAN1 && id <= FAN_ID_PSU1_FAN) { + rv = bmc_sensor_read(id + 13, FAN_SENSOR, &data); + if (rv != ONLP_STATUS_OK) { + AIM_LOG_ERROR("unable to read sensor info from BMC, sensor=%d\n", id); + return rv; + } + presence = (int) data; + + if (presence == 1) { + info->status |= ONLP_FAN_STATUS_PRESENT; + } else { + info->status &= ~ONLP_FAN_STATUS_PRESENT; + return ONLP_STATUS_OK; + } + } + + //get fan rpm + rv = bmc_sensor_read(id + 8, FAN_SENSOR, &data); + if (rv != ONLP_STATUS_OK) { + AIM_LOG_ERROR("unable to read sensor info from BMC, sensor=%d\n", id); + return rv; + } + rpm = (int) data; + + //set rpm field + info->rpm = rpm; + + if (id >= FAN_ID_FAN1 && id <= FAN_ID_FAN3) { + percentage = (info->rpm*100)/sys_max_fan_speed; + info->percentage = percentage; + } else if (id >= FAN_ID_PSU0_FAN && id <= FAN_ID_PSU1_FAN) { + percentage = (info->rpm*100)/psu_max_fan_speed; + info->percentage = percentage; + } + + return ONLP_STATUS_OK; +} + +int +file_read_hex(int* value, const char* fmt, ...) +{ + int rv; + va_list vargs; + va_start(vargs, fmt); + rv = file_vread_hex(value, fmt, vargs); + va_end(vargs); + return rv; +} + +int +file_vread_hex(int* value, const char* fmt, va_list vargs) +{ + int rv; + uint8_t data[32]; + int len; + rv = onlp_file_vread(data, sizeof(data), &len, fmt, vargs); + if(rv < 0) { + return rv; + } + //hex to int + *value = (int) strtol((char *)data, NULL, 0); + return 0; +} + +int +sys_led_info_get(onlp_led_info_t* info, int id) +{ + int ctrl_addr, ctrl_onoff_mask, ctrl_color_mask; + int blink_addr, blink_mask; + int data; + int led_val_color, led_val_blink, led_val_onoff; + + if (id == LED_ID_SYS_SYS) { + ctrl_addr = LED_CTRL_REG; + ctrl_onoff_mask = LED_SYS_ONOFF_MASK; + ctrl_color_mask = LED_SYS_COLOR_MASK; + blink_addr = LED_BLINKING_REG; + blink_mask = LED_SYS_BLINK_MASK; + } else if (id == LED_ID_SYS_SYNC) { + ctrl_addr = LED_CTRL_REG; + ctrl_onoff_mask = LED_SYNC_ONOFF_MASK; + ctrl_color_mask = LED_SYNC_COLOR_MASK; + blink_addr = LED_BLINKING_REG; + blink_mask = LED_SYNC_BLINK_MASK; + } else if (id == LED_ID_SYS_GPS) { + ctrl_addr = LED_CTRL_REG; + ctrl_onoff_mask = LED_GPS_ONOFF_MASK; + ctrl_color_mask = LED_GPS_COLOR_MASK; + blink_addr = LED_BLINKING_REG; + blink_mask = LED_GPS_BLINK_MASK; + } else { + return ONLP_STATUS_E_INTERNAL; + } + + /* Get control status */ + if (read_ioport(ctrl_addr, &data) < 0) { + AIM_LOG_ERROR("unable to read LED control register\n"); + return ONLP_STATUS_E_INTERNAL; + } + led_val_onoff = data & ctrl_onoff_mask; + led_val_color = data & ctrl_color_mask; + /* Get blinking status */ + if (read_ioport(blink_addr, &data) < 0) { + AIM_LOG_ERROR("unable to read LED control register\n"); + return ONLP_STATUS_E_INTERNAL; + } + led_val_blink = data & blink_mask; + + //onoff + if (led_val_onoff == 0) { + info->mode = ONLP_LED_MODE_OFF; + } else { + //color + if (led_val_color == 0) { + info->mode = ONLP_LED_MODE_YELLOW; + } else { + info->mode = ONLP_LED_MODE_GREEN; + } + //blinking + if (led_val_blink > 0) { + info->mode = info->mode + 1; + } + } + + return ONLP_STATUS_OK; +} + +int +sys_led_set(int id, int on_or_off) +{ + int ctrl_addr, ctrl_onoff_mask; + int data; + + if (id == LED_ID_SYS_SYS) { + ctrl_addr = LED_CTRL_REG; + ctrl_onoff_mask = LED_SYS_ONOFF_MASK; + } else if (id == LED_ID_SYS_SYNC) { + ctrl_addr = LED_CTRL_REG; + ctrl_onoff_mask = LED_SYNC_ONOFF_MASK; + } else if (id == LED_ID_SYS_GPS) { + ctrl_addr = LED_CTRL_REG; + ctrl_onoff_mask = LED_GPS_ONOFF_MASK; + } else { + return ONLP_STATUS_E_INTERNAL; + } + + /* Get control status */ + if (read_ioport(ctrl_addr, &data) < 0) { + AIM_LOG_ERROR("unable to read LED control register\n"); + return ONLP_STATUS_E_INTERNAL; + } + + if (on_or_off) { + data |= ctrl_onoff_mask; + } else { + data &= ~ctrl_onoff_mask; + } + + /* Set control status */ + if (write_ioport(ctrl_addr, data) < 0) { + AIM_LOG_ERROR("unable to write LED control register\n"); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +int +sys_led_mode_set(int id, int color, int blink) +{ + int ctrl_addr, ctrl_color_mask; + int blink_addr, blink_mask; + int data; + + if (id == LED_ID_SYS_SYS) { + ctrl_addr = LED_CTRL_REG; + ctrl_color_mask = LED_SYS_COLOR_MASK; + blink_addr = LED_BLINKING_REG; + blink_mask = LED_SYS_BLINK_MASK; + } else if (id == LED_ID_SYS_SYNC) { + ctrl_addr = LED_CTRL_REG; + ctrl_color_mask = LED_SYNC_COLOR_MASK; + blink_addr = LED_BLINKING_REG; + blink_mask = LED_SYNC_BLINK_MASK; + } else if (id == LED_ID_SYS_GPS) { + ctrl_addr = LED_CTRL_REG; + ctrl_color_mask = LED_GPS_COLOR_MASK; + blink_addr = LED_BLINKING_REG; + blink_mask = LED_GPS_BLINK_MASK; + } else { + return ONLP_STATUS_E_INTERNAL; + } + + /* Get control status */ + if (read_ioport(ctrl_addr, &data) < 0) { + AIM_LOG_ERROR("unable to read LED control register\n"); + return ONLP_STATUS_E_INTERNAL; + } + + if (color == LED_COLOR_GREEN) { + data |= ctrl_color_mask; + } else { + data &= ~ctrl_color_mask; + } + + /* Set control status */ + if (write_ioport(ctrl_addr, data) < 0) { + AIM_LOG_ERROR("unable to write LED control register\n"); + return ONLP_STATUS_E_INTERNAL; + } + + /* Get blinking status */ + if (read_ioport(blink_addr, &data) < 0) { + AIM_LOG_ERROR("unable to read LED blinking register\n"); + return ONLP_STATUS_E_INTERNAL; + } + + if (blink == LED_BLINKING) { + data |= blink_mask; + } else { + data &= ~blink_mask; + } + + /* Set blinking status */ + if (write_ioport(blink_addr, data) < 0) { + AIM_LOG_ERROR("unable to write LED blinking register\n"); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/platform_lib.h b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/platform_lib.h new file mode 100755 index 0000000000..c2150b70bb --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/platform_lib.h @@ -0,0 +1,355 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2013 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#ifndef __PLATFORM_LIB_H__ +#define __PLATFORM_LIB_H__ + +#include +#include +#include +#include +#include +#include "x86_64_ufispace_s9500_22xst_int.h" +#include "x86_64_ufispace_s9500_22xst_log.h" + +#include +#define SYS_DEV "/sys/bus/i2c/devices/" +#define SYS_CPU_CORETEMP_PREFIX "/sys/devices/platform/coretemp.0/hwmon/hwmon0/" +#define SYS_CPU_CORETEMP_PREFIX2 "/sys/devices/platform/coretemp.0/" +#define SYS_CORE_TEMP_PREFIX "/sys/class/hwmon/hwmon2/" +#define SYS_CPU_BOARD_TEMP_PREFIX "/sys/bus/i2c/devices/0-004f/hwmon/hwmon1/" +#define SYS_CPU_BOARD_TEMP_PREFIX2 "/sys/bus/i2c/devices/0-004f/" + +#define SYS_FAN_PREFIX "/sys/class/hwmon/hwmon1/device/" +#define SYS_EEPROM_PATH "/sys/bus/i2c/devices/0-0057/eeprom" +#define SYS_EEPROM_SIZE 512 +#define PSU1_EEPROM_PATH "/sys/bus/i2c/devices/58-0050/eeprom" +#define PSU2_EEPROM_PATH "/sys/bus/i2c/devices/57-0050/eeprom" +#define BMC_EN_FILE_PATH "/etc/onl/bmc_en" +#define BMC_SENSOR_CACHE "/tmp/bmc_sensor_cache" +#define CMD_BIOS_VER "dmidecode -s bios-version | tail -1 | tr -d '\r\n'" +#define CMD_BMC_VER_1 "expr `ipmitool mc info | grep 'Firmware Revision' | cut -d':' -f2 | cut -d'.' -f1` + 0" +#define CMD_BMC_VER_2 "expr `ipmitool mc info | grep 'Firmware Revision' | cut -d':' -f2 | cut -d'.' -f2` + 0" +#define CMD_BMC_VER_3 "echo $((`ipmitool mc info | grep 'Aux Firmware Rev Info' -A 2 | sed -n '2p'`))" +#define CMD_BMC_SENSOR_CACHE "ipmitool sdr -c get Temp_CPU Temp_MAC Temp_BMC Temp_100GCage Temp_DDR4 Temp_FANCARD1 Temp_FANCARD2 PSU0_Temp PSU1_Temp FAN_1 FAN_2 FAN_3 PSU0_FAN PSU1_FAN Fan1_Presence Fan2_Presence Fan3_Presence PSU0_Presence PSU1_Presence PSU0_POWEROK PSU1_POWEROK PSU0_VIN PSU0_VOUT PSU0_IIN PSU0_IOUT PSU1_VIN PSU1_VOUT PSU1_IIN PSU1_IOUT HWM_Temp_AMB HWM_Temp_PHY1 HWM_Temp_Heater > /tmp/bmc_sensor_cache" +#define CMD_UCD_VER "ipmitool raw 0x3c 0x12 0x0 0x34 0x6 0x9b" +#define CMD_BMC_SDR_GET "ipmitool sdr -c get %s" +#define CMD_FRU_INFO_GET "ipmitool fru print %d | grep '%s' | cut -d':' -f2 | awk '{$1=$1};1' | tr -d '\n'" +#define CMD_BMC_CACHE_GET "cat "BMC_SENSOR_CACHE" | grep %s | awk -F',' '{print $%d}'" +#define PSU_STATUS_PRESENT 1 +#define PSU_STATUS_POWER_GOOD 1 +#define FAN_PRESENT 0 +#define FAN_CTRL_SET1 1 +#define FAN_CTRL_SET2 2 +#define MAX_SYS_FAN_NUM 5 +#define BOARD_THERMAL_NUM 6 +#define SYS_FAN_NUM 5 +#define QSFP_NUM 2 +#define SFP28_NUM 8 +#define SFP_NUM 8 +#define RJ45_NUM 4 +#define PORT_NUM 22 + +#define THERMAL_NUM 21 +#define LED_NUM 5 +#define FAN_NUM 3 + + + +#define THERMAL_SHUTDOWN_DEFAULT 105000 + +#define THERMAL_ERROR_DEFAULT 95000 +#define THERMAL_ERROR_FAN_PERC 100 + +#define THERMAL_WARNING_DEFAULT 77000 +#define THERMAL_WARNING_FAN_PERC 80 + +#define THERMAL_NORMAL_DEFAULT 72000 +#define THERMAL_NORMAL_FAN_PERC 50 + +/* I2C bus */ +#define I2C_BUS_0 0 +#define I2C_BUS_1 1 +#define I2C_BUS_2 2 +#define I2C_BUS_3 3 +#define I2C_BUS_4 4 +#define I2C_BUS_5 5 +#define I2C_BUS_6 6 +#define I2C_BUS_7 7 +#define I2C_BUS_8 8 +#define I2C_BUS_9 9 + +/* PSU */ + +/* LED */ +#define LED_CTRL_REG 0x718 +#define LED_SYS_ONOFF_MASK 0x40 +#define LED_SYNC_ONOFF_MASK 0x01 +#define LED_GPS_ONOFF_MASK 0x04 +#define LED_SYS_COLOR_MASK 0x80 +#define LED_SYNC_COLOR_MASK 0x02 +#define LED_GPS_COLOR_MASK 0x08 + +#define LED_BLINKING_REG 0x71A +#define LED_SYS_BLINK_MASK 0x08 +#define LED_SYNC_BLINK_MASK 0x01 +#define LED_GPS_BLINK_MASK 0x02 + +#define LED_COLOR_GREEN 1 +#define LED_COLOR_YELLOW 0 +#define LED_BLINKING 1 +#define LED_STABLE 0 + +/* SYS */ + +/* QSFP */ + +/* FAN */ + +/* BMC CMD */ +#define BMC_CACHE_EN 1 +#define BMC_CACHE_CYCLE 30 +#define BMC_CMD_SDR_SIZE 48 +#define BMC_TOKEN_SIZE 20 + +#define FAN_CACHE_TIME 5 +#define PSU_CACHE_TIME 5 +#define THERMAL_CACHE_TIME 10 + +enum sensor +{ + FAN_SENSOR = 0, + PSU_SENSOR, + THERMAL_SENSOR, +}; + +typedef struct bmc_info_s +{ + char name[20]; + float data; +}bmc_info_t; + +/** led_oid */ +typedef enum led_oid_e { + LED_OID_SYSTEM = ONLP_LED_ID_CREATE(1), + LED_OID_SYNC = ONLP_LED_ID_CREATE(2), + LED_OID_GPS = ONLP_LED_ID_CREATE(3), + LED_OID_FAN_TRAY1 = ONLP_LED_ID_CREATE(4), + LED_OID_FAN_TRAY2 = ONLP_LED_ID_CREATE(5), + LED_OID_FAN_TRAY3 = ONLP_LED_ID_CREATE(6) +} led_oid_t; + +/** led_id */ +typedef enum led_id_e { + LED_ID_SYS_SYS = 1, + LED_ID_SYS_SYNC = 2, + LED_ID_SYS_GPS = 3, + LED_ID_FAN_TRAY1 = 4, + LED_ID_FAN_TRAY2 = 5, + LED_ID_FAN_TRAY3 = 6, + LED_ID_MAX = 7 +} led_id_t; + +/** Thermal_oid */ +typedef enum thermal_oid_e { + THERMAL_OID_CPU = ONLP_THERMAL_ID_CREATE(1), + THERMAL_OID_MAC = ONLP_THERMAL_ID_CREATE(2), + THERMAL_OID_BMC = ONLP_THERMAL_ID_CREATE(3), + THERMAL_OID_100G_CAGE= ONLP_THERMAL_ID_CREATE(4), + THERMAL_OID_DDR4 = ONLP_THERMAL_ID_CREATE(5), + THERMAL_OID_FANCARD1 = ONLP_THERMAL_ID_CREATE(6), + THERMAL_OID_FANCARD2 = ONLP_THERMAL_ID_CREATE(7), + THERMAL_OID_PSU0 = ONLP_THERMAL_ID_CREATE(8), + THERMAL_OID_PSU1 = ONLP_THERMAL_ID_CREATE(9), + THERMAL_OID_CPU_PKG = ONLP_THERMAL_ID_CREATE(10), + THERMAL_OID_CPU1 = ONLP_THERMAL_ID_CREATE(11), + THERMAL_OID_CPU2 = ONLP_THERMAL_ID_CREATE(12), + THERMAL_OID_CPU3 = ONLP_THERMAL_ID_CREATE(13), + THERMAL_OID_CPU4 = ONLP_THERMAL_ID_CREATE(14), + THERMAL_OID_CPU_BOARD= ONLP_THERMAL_ID_CREATE(15), + THERMAL_OID_AMB = ONLP_THERMAL_ID_CREATE(16), + THERMAL_OID_PHY1 = ONLP_THERMAL_ID_CREATE(17), + THERMAL_OID_HEATER = ONLP_THERMAL_ID_CREATE(18), +} thermal_oid_t; + +/** thermal_id */ +typedef enum thermal_id_e { + THERMAL_ID_CPU = 1, + THERMAL_ID_MAC = 2, + THERMAL_ID_BMC = 3, + THERMAL_ID_100G_CAGE= 4, + THERMAL_ID_DDR4 = 5, + THERMAL_ID_FANCARD1 = 6, + THERMAL_ID_FANCARD2 = 7, + THERMAL_ID_PSU0 = 8, + THERMAL_ID_PSU1 = 9, + THERMAL_ID_CPU_PKG = 10, + THERMAL_ID_CPU1 = 11, + THERMAL_ID_CPU2 = 12, + THERMAL_ID_CPU3 = 13, + THERMAL_ID_CPU4 = 14, + THERMAL_ID_CPU_BOARD= 15, + THERMAL_ID_AMB = 16, + THERMAL_ID_PHY1 = 17, + THERMAL_ID_HEATER = 18, + THERMAL_ID_MAX = 19, +} thermal_id_t; + +/* Shortcut for CPU thermal threshold value. */ +#define THERMAL_THRESHOLD_INIT_DEFAULTS \ + { THERMAL_WARNING_DEFAULT, \ + THERMAL_ERROR_DEFAULT, \ + THERMAL_SHUTDOWN_DEFAULT } + +/** Fan_oid */ +typedef enum fan_oid_e { + FAN_OID_FAN1 = ONLP_FAN_ID_CREATE(1), + FAN_OID_FAN2 = ONLP_FAN_ID_CREATE(2), + FAN_OID_FAN3 = ONLP_FAN_ID_CREATE(3), + FAN_OID_PSU0_FAN = ONLP_FAN_ID_CREATE(4), + FAN_OID_PSU1_FAN = ONLP_FAN_ID_CREATE(5), +} fan_oid_t; + +/** fan_id */ +typedef enum fan_id_e { + FAN_ID_FAN1 = 1, + FAN_ID_FAN2 = 2, + FAN_ID_FAN3 = 3, + FAN_ID_PSU0_FAN = 4, + FAN_ID_PSU1_FAN = 5, + FAN_ID_MAX = 6, +} fan_id_t; + +/** led_oid */ +typedef enum psu_oid_e { + PSU_OID_PSU0 = ONLP_PSU_ID_CREATE(1), + PSU_OID_PSU1 = ONLP_PSU_ID_CREATE(2) +} psu_oid_t; + +/** psu_id */ +typedef enum psu_id_e { + PSU_ID_PSU0 = 1, + PSU_ID_PSU1 = 2, + PSU_ID_PSU0_VIN = 3, + PSU_ID_PSU0_VOUT = 4, + PSU_ID_PSU0_IIN = 5, + PSU_ID_PSU0_IOUT = 6, + PSU_ID_PSU1_VIN = 7, + PSU_ID_PSU1_VOUT = 8, + PSU_ID_PSU1_IIN = 9, + PSU_ID_PSU1_IOUT = 10, + PSU_ID_MAX = 11, +} psu_id_t; + +int psu_thermal_get(onlp_thermal_info_t* info, int id); + +int psu_fan_info_get(onlp_fan_info_t* info, int id); + +int psu_vin_get(onlp_psu_info_t* info, int id); + +int psu_vout_get(onlp_psu_info_t* info, int id); + +int psu_iin_get(onlp_psu_info_t* info, int id); + +int psu_iout_get(onlp_psu_info_t* info, int id); + +int psu_pout_get(onlp_psu_info_t* info, int id); + +int psu_pin_get(onlp_psu_info_t* info, int id); + +int psu_eeprom_get(onlp_psu_info_t* info, int id); + +int psu_present_get(int *pw_present, int id); + +int psu_pwgood_get(int *pw_good, int id); + +int psu2_led_set(onlp_led_mode_t mode); + +int psu1_led_set(onlp_led_mode_t mode); + +int fan_led_set(onlp_led_mode_t mode); + +int system_led_set(onlp_led_mode_t mode); + +int fan_tray_led_set(onlp_oid_t id, onlp_led_mode_t mode); + +int sysi_platform_info_get(onlp_platform_info_t* pi); + +int qsfp_present_get(int port, int *pres_val); + +int sfp_present_get(int port, int *pres_val); + +int sfp_rx_los_get(int port, int *ctrl_val); + +int sfp_tx_fault_get(int port, int *ctrl_val); + +int sfp_tx_disable_get(int port, int *ctrl_val); + +int qsfp_lp_mode_get(int port, int *ctrl_val); + +int qsfp_reset_get(int port, int *ctrl_val); + +int sfp_tx_disable_set(int port, int ctrl_val); + +int qsfp_lp_mode_set(int port, int ctrl_val); + +int qsfp_reset_set(int port, int ctrl_val); + +bool onlp_sysi_bmc_en_get(void); + +int read_ioport(int addr, int *reg_val); + +int write_ioport(int addr, int val); + +int bmc_thermal_info_get(onlp_thermal_info_t* info, int id); + +int bmc_fan_info_get(onlp_fan_info_t* info, int id); + +int exec_cmd(char *cmd, char* out, int size); + +int file_read_hex(int* value, const char* fmt, ...); + +int file_vread_hex(int* value, const char* fmt, va_list vargs); + +int parse_bmc_sdr_cmd(char *cmd_out, int cmd_out_size, + char *tokens[], int token_size, + const char *sensor_id_str, int *idx); + +int sys_led_info_get(onlp_led_info_t* info, int id); + +int sys_led_set(int id, int on_or_off); + +int sys_led_mode_set(int id, int color, int blink); + +int psu_fru_get(onlp_psu_info_t* info, int id); + +void +lock_init(); + +int +bmc_sensor_read(int bmc_cache_index, int sensor_type, float *data); + +extern bool bmc_enable; +#endif /* __PLATFORM_LIB_H__ */ diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/psui.c b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/psui.c new file mode 100755 index 0000000000..314c9fb562 --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/psui.c @@ -0,0 +1,168 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 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 "platform_lib.h" + +static onlp_psu_info_t pinfo[] = +{ + { }, /* Not used */ + { + { + PSU_OID_PSU0, + "PSU-1", + 0, + { + FAN_OID_PSU0_FAN, + THERMAL_OID_PSU0, + }, + } + }, + { + { + PSU_OID_PSU1, + "PSU-2", + 0, + { + FAN_OID_PSU1_FAN, + THERMAL_OID_PSU1, + }, + } + } +}; + +int +onlp_psui_init(void) +{ + lock_init(); + return ONLP_STATUS_OK; +} + +int +psu_status_info_get(int id, onlp_psu_info_t *info) +{ + int rc, pw_present, pw_good; + float data; + int index_offset = 0; + + if (id == PSU_ID_PSU1) { + index_offset = 4; + } + + /* Get power present status */ + if ((rc = psu_present_get(&pw_present, id)) + != ONLP_STATUS_OK) { + return ONLP_STATUS_E_INTERNAL; + } + + if (pw_present != PSU_STATUS_PRESENT) { + info->status &= ~ONLP_PSU_STATUS_PRESENT; + info->status |= ONLP_PSU_STATUS_UNPLUGGED; + return ONLP_STATUS_OK; + } + + info->status |= ONLP_PSU_STATUS_PRESENT; + + /* Get power good status */ + if ((rc = psu_pwgood_get(&pw_good, id)) + != ONLP_STATUS_OK) { + return ONLP_STATUS_E_INTERNAL; + } + + if (pw_good != PSU_STATUS_POWER_GOOD) { + info->status |= ONLP_PSU_STATUS_FAILED; + } else { + info->status &= ~ONLP_PSU_STATUS_FAILED; + } + + /* Get power vin status */ + if ((rc = bmc_sensor_read(21 + index_offset, PSU_SENSOR, &data)) != ONLP_STATUS_OK) { + return ONLP_STATUS_E_INTERNAL; + } else { + info->mvin = (int) (data*1000); + info->caps |= ONLP_PSU_CAPS_VIN; + } + + /* Get power vout status */ + if ((rc = bmc_sensor_read(22 + index_offset, PSU_SENSOR, &data)) != ONLP_STATUS_OK) { + return ONLP_STATUS_E_INTERNAL; + } else { + info->mvout = (int) (data*1000); + info->caps |= ONLP_PSU_CAPS_VOUT; + } + + /* Get power iin status */ + if ((rc = bmc_sensor_read(23 + index_offset, PSU_SENSOR, &data)) != ONLP_STATUS_OK) { + return ONLP_STATUS_E_INTERNAL; + } else { + info->miin = (int) (data*1000); + info->caps |= ONLP_PSU_CAPS_IIN; + } + + /* Get power iout status */ + if ((rc = bmc_sensor_read(24 + index_offset, PSU_SENSOR, &data)) != ONLP_STATUS_OK) { + return ONLP_STATUS_E_INTERNAL; + } else { + info->miout = (int) (data*1000); + info->caps |= ONLP_PSU_CAPS_IOUT; + } + + /* Get power in and out */ + info->mpin = info->miin * info->mvin / 1000; + info->mpout = info->miout * info->mvout / 1000; + info->caps |= ONLP_PSU_CAPS_PIN | ONLP_PSU_CAPS_POUT; + + /* Get FRU (model/serial) */ + if ((rc = psu_fru_get(info, id)) != ONLP_STATUS_OK) { + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +int +onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) +{ + int pid; + + pid = ONLP_OID_ID_GET(id); + memset(info, 0, sizeof(onlp_psu_info_t)); + + /* Set the onlp_oid_hdr_t */ + *info = pinfo[pid]; + + switch (pid) { + case PSU_ID_PSU0: + case PSU_ID_PSU1: + return psu_status_info_get(pid, info); + break; + default: + return ONLP_STATUS_E_UNSUPPORTED; + break; + } + + return ONLP_STATUS_OK; +} diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/sfpi.c b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/sfpi.c new file mode 100755 index 0000000000..a5d1779d38 --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/sfpi.c @@ -0,0 +1,324 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 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 "x86_64_ufispace_s9500_22xst_log.h" +#include "platform_lib.h" + +static int _sfpi_get_bus_by_port(int port) +{ + if (port < (RJ45_NUM)) { + AIM_LOG_ERROR("Invalid port has no I2C bus, port=%d\n", port); + return 999; /* invalid bus num */ + } else if (port < (RJ45_NUM + SFP_NUM)) { //SFP + return port + (9 - RJ45_NUM); + } else if (port < (RJ45_NUM + SFP_NUM + SFP28_NUM)) { //SFP28 + return port + (21 - (RJ45_NUM + SFP_NUM)); + } else if (port < (PORT_NUM - 1)) { //QSFP + return 36; + } else if (port < (PORT_NUM)) { //QSFP + return 35; + } else { //unknown ports + AIM_LOG_ERROR("unknown ports, port=%d\n", port); + return 999; /* invalid bus num */ + } +} + +int +onlp_sfpi_init(void) +{ + lock_init(); + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap) +{ + int p; + for(p = RJ45_NUM; p < PORT_NUM; p++) { + AIM_BITMAP_SET(bmap, p); + } + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_is_present(int port) +{ + int status = 1; + + // SFP, SFP28, QSFP Ports + if (port < RJ45_NUM) { + AIM_LOG_ERROR("Presence is not supported, port=%d\n", port); + return ONLP_STATUS_E_UNSUPPORTED; + }else if (port < (RJ45_NUM + SFP_NUM + SFP28_NUM)) { //SFP, SFP28 + if (sfp_present_get(port, &status) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("sfp_presnet_get() failed, port=%d\n", port); + return ONLP_STATUS_E_INTERNAL; + } + } else if (port >= (RJ45_NUM + SFP_NUM + SFP28_NUM) && port < PORT_NUM) { //QSFP + if (qsfp_present_get(port, &status) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("qsfp_present_get() failed, port=%d\n", port); + return ONLP_STATUS_E_INTERNAL; + } + } else { //unkonwn ports + AIM_LOG_ERROR("unknown ports, port=%d\n", port); + return ONLP_STATUS_E_UNSUPPORTED; + } + + return status; +} + +int +onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) +{ + int p = 0; + int rc = 0; + + AIM_BITMAP_CLR_ALL(dst); + + /* The first 4 port is RJ45 */ + for (p = RJ45_NUM; p < PORT_NUM; p++) { + rc = onlp_sfpi_is_present(p); + AIM_BITMAP_MOD(dst, p, rc); + } + + return ONLP_STATUS_OK; +} + +/* + * This function reads the SFPs idrom and returns in + * in the data buffer provided. + */ +int +onlp_sfpi_eeprom_read(int port, uint8_t data[256]) +{ + char eeprom_path[512]; + int size = 0; + + memset(eeprom_path, 0, sizeof(eeprom_path)); + memset(data, 0, 256); + + //QSFP, QSFPDD, SFP real ports + if (port < (RJ45_NUM)) { + AIM_LOG_ERROR("eeprom is not supported, port=%d\n", port); + return ONLP_STATUS_E_UNSUPPORTED; + } else if (port < (RJ45_NUM + SFP_NUM + SFP28_NUM)) { //SFP + snprintf(eeprom_path, sizeof(eeprom_path), "/sys/bus/i2c/devices/%d-0050/eeprom", _sfpi_get_bus_by_port(port)); + } else if (port >= (RJ45_NUM + SFP_NUM + SFP28_NUM) && port < PORT_NUM) { //QSFP + snprintf(eeprom_path, sizeof(eeprom_path), "/sys/bus/i2c/devices/%d-0050/eeprom", _sfpi_get_bus_by_port(port)); + } else { //unknown ports + AIM_LOG_ERROR("unknown ports, port=%d\n", port); + return ONLP_STATUS_E_UNSUPPORTED; + } + + if(onlp_file_read(data, 256, &size, eeprom_path) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("Unable to read eeprom from port(%d)\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + + if (size != 256) { + AIM_LOG_ERROR("Unable to read eeprom from port(%d), size is different!\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) +{ + int i=0, value=0, rc=0; + int sfpx_num = (SFP_NUM + SFP28_NUM); + + AIM_BITMAP_CLR_ALL(dst); + + /* Populate bitmap - SFP+ and SFP28 ports*/ + for(i = RJ45_NUM; i < (RJ45_NUM + sfpx_num); i++) { + if ((rc=onlp_sfpi_control_get(i, ONLP_SFP_CONTROL_RX_LOS, &value)) != ONLP_STATUS_OK) { + return ONLP_STATUS_E_INTERNAL; + } else { + AIM_BITMAP_MOD(dst, i, value); + } + } + + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) +{ + int rc, status; + int sfpx_num = (SFP_NUM + SFP28_NUM); + + if (port >= RJ45_NUM && port < (RJ45_NUM + sfpx_num)) { + switch(control) { + case ONLP_SFP_CONTROL_RX_LOS: + if (sfp_rx_los_get(port, &status) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("sfp_rx_los_get() failed, port=%d\n", port); + return ONLP_STATUS_E_INTERNAL; + } + *value = status; + rc = ONLP_STATUS_OK; + break; + case ONLP_SFP_CONTROL_TX_FAULT: + if (control == ONLP_SFP_CONTROL_TX_FAULT) { + if (sfp_tx_fault_get(port, &status) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("sfp_tx_fault_get() failed, port=%d\n", port); + return ONLP_STATUS_E_INTERNAL; + } + } + *value = status; + rc = ONLP_STATUS_OK; + break; + case ONLP_SFP_CONTROL_TX_DISABLE: + if (control == ONLP_SFP_CONTROL_TX_DISABLE) { + if (sfp_tx_disable_get(port, &status) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("sfp_tx_disable_get() failed, port=%d\n", port); + return ONLP_STATUS_E_INTERNAL; + } + } + *value = status; + rc = ONLP_STATUS_OK; + break; + default: + rc = ONLP_STATUS_E_UNSUPPORTED; + break; + } + } else if (port >= (RJ45_NUM + sfpx_num) && port < PORT_NUM) { + switch (control) { + case ONLP_SFP_CONTROL_LP_MODE: + if (qsfp_lp_mode_get(port, &status) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("qsfp_lp_mode_get() failed, port=%d\n", port); + return ONLP_STATUS_E_INTERNAL; + } + *value = status; + rc = ONLP_STATUS_OK; + break; + case ONLP_SFP_CONTROL_RESET: + if (qsfp_reset_get(port, &status) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("qsfp_reset_get() failed, port=%d\n", port); + return ONLP_STATUS_E_INTERNAL; + } + *value = status; + rc = ONLP_STATUS_OK; + break; + default: + rc = ONLP_STATUS_E_UNSUPPORTED; + break; + } + } else { + return ONLP_STATUS_E_UNSUPPORTED; + } + + return rc; +} + +int +onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) +{ + int rc; + int sfpx_num = (SFP_NUM + SFP28_NUM); + + if (port >= RJ45_NUM && port < (RJ45_NUM + sfpx_num)) { + switch (control) { + case ONLP_SFP_CONTROL_TX_DISABLE: + if (sfp_tx_disable_set(port, value) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("sfp_tx_disable_set() failed, port=%d\n", port); + return ONLP_STATUS_E_INTERNAL; + } + rc = ONLP_STATUS_OK; + break; + default: + return ONLP_STATUS_E_UNSUPPORTED; + } + } else if (port >= (RJ45_NUM + sfpx_num) && port < PORT_NUM) { + switch (control) { + case ONLP_SFP_CONTROL_LP_MODE: + if (qsfp_lp_mode_set(port, value) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("qsfp_lp_mode_set() failed, port=%d\n", port); + return ONLP_STATUS_E_INTERNAL; + } + rc = ONLP_STATUS_OK; + break; + case ONLP_SFP_CONTROL_RESET: + if (qsfp_reset_set(port, value) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("qsfp_reset_set() failed, port=%d\n", port); + return ONLP_STATUS_E_INTERNAL; + } + rc = ONLP_STATUS_OK; + break; + default: + rc = ONLP_STATUS_E_UNSUPPORTED; + break; + } + } else { + return ONLP_STATUS_E_UNSUPPORTED; + } + + return rc; +} + +int +onlp_sfpi_dev_readb(int port, uint8_t devaddr, uint8_t addr) +{ + int bus = _sfpi_get_bus_by_port(port); + return onlp_i2c_readb(bus, devaddr, addr, ONLP_I2C_F_FORCE); +} + +int +onlp_sfpi_dev_writeb(int port, uint8_t devaddr, uint8_t addr, uint8_t value) +{ + int bus = _sfpi_get_bus_by_port(port); + return onlp_i2c_writeb(bus, devaddr, addr, value, ONLP_I2C_F_FORCE); +} + +int +onlp_sfpi_dev_readw(int port, uint8_t devaddr, uint8_t addr) +{ + int bus = _sfpi_get_bus_by_port(port); + return onlp_i2c_readw(bus, devaddr, addr, ONLP_I2C_F_FORCE); +} + +int +onlp_sfpi_dev_writew(int port, uint8_t devaddr, uint8_t addr, uint16_t value) +{ + int bus = _sfpi_get_bus_by_port(port); + return onlp_i2c_writew(bus, devaddr, addr, value, ONLP_I2C_F_FORCE); +} + +/* + * De-initialize the SFPI subsystem. + */ +int +onlp_sfpi_denit(void) +{ + return ONLP_STATUS_OK; +} diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/sysi.c b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/sysi.c new file mode 100755 index 0000000000..502435e137 --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/sysi.c @@ -0,0 +1,183 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 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" + +bool bmc_enable = false; + +const char* +onlp_sysi_platform_get(void) +{ + return "x86-64-ufispace-s9500-22xst-r0"; +} + +int +onlp_sysi_platform_set(const char* platform) +{ + AIM_LOG_INFO("Set ONL platform interface to '%s'\n", platform); + AIM_LOG_INFO("Real HW Platform: '%s'\n", onlp_sysi_platform_get()); + return ONLP_STATUS_OK; +} + +int +onlp_sysi_init(void) +{ + /* check if the platform is bmc enabled */ + if ( onlp_sysi_bmc_en_get() ) { + bmc_enable = true; + } else { + bmc_enable = false; + } + + return ONLP_STATUS_OK; +} + +int +onlp_sysi_onie_data_get(uint8_t** data, int* size) +{ + uint8_t* rdata = aim_zmalloc(SYS_EEPROM_SIZE); + if(onlp_file_read(rdata, SYS_EEPROM_SIZE, size, SYS_EEPROM_PATH) == ONLP_STATUS_OK) { + if(*size == SYS_EEPROM_SIZE) { + *data = rdata; + return ONLP_STATUS_OK; + } + } + + AIM_LOG_INFO("Unable to get data from eeprom \n"); + aim_free(rdata); + *size = 0; + return ONLP_STATUS_E_INTERNAL; +} + +void +onlp_sysi_onie_data_free(uint8_t* data) +{ + if (data) { + aim_free(data); + } +} + +int +onlp_sysi_oids_get(onlp_oid_t* table, int max) +{ + onlp_oid_t* e = table; + memset(table, 0, max*sizeof(onlp_oid_t)); + int i; + + if ( !bmc_enable ) { + /* 2 PSUs */ + *e++ = ONLP_PSU_ID_CREATE(1); + *e++ = ONLP_PSU_ID_CREATE(2); + + /* LEDs Item */ + for (i=1; i<=LED_NUM; i++) { + *e++ = ONLP_LED_ID_CREATE(i); + } + + /* Fans Item */ + for (i=1; i<=FAN_NUM; i++) { + *e++ = ONLP_FAN_ID_CREATE(i); + } + + for (i=1; i<=THERMAL_NUM; i++) { + *e++ = ONLP_THERMAL_ID_CREATE(i); + } + } else { + *e++ = THERMAL_OID_CPU; + *e++ = THERMAL_OID_MAC; + *e++ = THERMAL_OID_BMC; + *e++ = THERMAL_OID_100G_CAGE; + *e++ = THERMAL_OID_DDR4; + *e++ = THERMAL_OID_FANCARD1; + *e++ = THERMAL_OID_FANCARD2; + *e++ = THERMAL_OID_PSU0; + *e++ = THERMAL_OID_PSU1; + *e++ = THERMAL_OID_CPU_PKG; + *e++ = THERMAL_OID_CPU1; + *e++ = THERMAL_OID_CPU2; + *e++ = THERMAL_OID_CPU3; + *e++ = THERMAL_OID_CPU4; + *e++ = THERMAL_OID_CPU_BOARD; + *e++ = THERMAL_OID_AMB; + *e++ = THERMAL_OID_PHY1; + *e++ = THERMAL_OID_HEATER; + + *e++ = LED_OID_SYSTEM; + *e++ = LED_OID_SYNC; + *e++ = LED_OID_GPS; + + *e++ = PSU_OID_PSU0; + *e++ = PSU_OID_PSU1; + + *e++ = FAN_OID_FAN1; + *e++ = FAN_OID_FAN2; + *e++ = FAN_OID_FAN3; + //*e++ = FAN_OID_PSU0_FAN; + //*e++ = FAN_OID_PSU1_FAN; + } + + return ONLP_STATUS_OK; +} + +int +onlp_sysi_platform_manage_fans(void) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +int +onlp_sysi_platform_info_get(onlp_platform_info_t* pi) +{ + int rc; + if ((rc = sysi_platform_info_get(pi)) != ONLP_STATUS_OK) { + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +void +onlp_sysi_platform_info_free(onlp_platform_info_t* pi) +{ + if (pi->cpld_versions) { + aim_free(pi->cpld_versions); + } + + if (pi->other_versions) { + aim_free(pi->other_versions); + } +} + diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/thermali.c b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/thermali.c new file mode 100755 index 0000000000..9590dea565 --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/thermali.c @@ -0,0 +1,234 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 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 Sensor Platform Implementation. + * + ***********************************************************/ +#include +#include +#include "x86_64_ufispace_s9500_22xst_log.h" +#include "platform_lib.h" + +static onlp_thermal_info_t thermal_info[] = { + { }, /* Not used */ + { { THERMAL_OID_CPU, "Temp_CPU", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, {92000, 97000, 102000} + }, + { { THERMAL_OID_MAC, "Temp_MAC", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, {96000, 101000, 106000} + }, + { { THERMAL_OID_BMC, "Temp_BMC", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, {80000, 85000, 89000} + }, + { { THERMAL_OID_100G_CAGE, "Temp_100GCage", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, {79000, 82000, 85000} + }, + { { THERMAL_OID_DDR4, "Temp_DDR4", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, {85000, 90000, 92000} + }, + { { THERMAL_OID_FANCARD1, "Temp_FANCARD1", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, {80000, 85000, 89000} + }, + { { THERMAL_OID_FANCARD2, "Temp_FANCARD2", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, {80000, 85000, 89000} + }, + { { THERMAL_OID_PSU0, "PSU 1 - Thermal Sensor", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, {86000, 90000, 95000} + }, + { { THERMAL_OID_PSU1, "PSU 2 - Thermal Sensor", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, {86000, 90000, 95000} + }, + { { THERMAL_OID_CPU_PKG, "CPU Package", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { THERMAL_OID_CPU1, "CPU Thermal 1", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { THERMAL_OID_CPU2, "CPU Thermal 2", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { THERMAL_OID_CPU3, "CPU Thermal 3", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { THERMAL_OID_CPU4, "CPU Thermal 4", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { THERMAL_OID_CPU_BOARD, "CPU Board", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { THERMAL_OID_AMB, "Ambient Thermal", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, {76000, 80000, 84000} + }, + { { THERMAL_OID_PHY1, "Temp_PHY1", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, {86000, 90000, 95000} + }, + { { THERMAL_OID_HEATER, "Temp_Heater", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, {73000, 75000, 78000} + }, +}; + +/* + * This will be called to intiialize the thermali subsystem. + */ +int +onlp_thermali_init(void) +{ + lock_init(); + return ONLP_STATUS_OK; +} + +static int +cpu_thermal_info_get(onlp_thermal_info_t* info, int id) +{ + int rv; + + rv = onlp_file_read_int(&info->mcelsius, + SYS_CPU_CORETEMP_PREFIX "temp%d_input", (id - THERMAL_ID_CPU_PKG) + 1); + + if(rv != ONLP_STATUS_OK) { + + rv = onlp_file_read_int(&info->mcelsius, + SYS_CPU_CORETEMP_PREFIX2 "temp%d_input", (id - THERMAL_ID_CPU_PKG) + 1); + + if(rv != ONLP_STATUS_OK) { + return rv; + } + } + + if(rv == ONLP_STATUS_E_MISSING) { + info->status &= ~1; + return 0; + } + + return ONLP_STATUS_OK; +} + +int +psu_thermal_info_get(onlp_thermal_info_t* info, int id) +{ + int rv; + + if ( bmc_enable ) { + return ONLP_STATUS_E_UNSUPPORTED; + } + + rv = psu_thermal_get(info, id); + if(rv == ONLP_STATUS_E_INTERNAL) { + return rv; + } + + return ONLP_STATUS_OK; +} + +static int +cpu_board_thermal_info_get(onlp_thermal_info_t* info) +{ + int rv; + + rv = onlp_file_read_int(&info->mcelsius, + SYS_CPU_BOARD_TEMP_PREFIX "temp1_input"); + + if (rv != ONLP_STATUS_OK) { + rv = onlp_file_read_int(&info->mcelsius, + SYS_CPU_BOARD_TEMP_PREFIX2 "temp1_input"); + + if (rv != ONLP_STATUS_OK) { + return rv; + } + } + + if (rv == ONLP_STATUS_E_MISSING) { + info->status &= ~1; + return 0; + } + + 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 sensor_id, rc; + sensor_id = ONLP_OID_ID_GET(id); + + *info = thermal_info[sensor_id]; + info->caps |= ONLP_THERMAL_CAPS_GET_TEMPERATURE; + + switch (sensor_id) { + case THERMAL_ID_CPU_PKG: + case THERMAL_ID_CPU1: + case THERMAL_ID_CPU2: + case THERMAL_ID_CPU3: + case THERMAL_ID_CPU4: + rc = cpu_thermal_info_get(info, sensor_id); + break; + case THERMAL_ID_CPU_BOARD: + rc = cpu_board_thermal_info_get(info); + break; + case THERMAL_ID_CPU: + case THERMAL_ID_MAC: + case THERMAL_ID_BMC: + case THERMAL_ID_100G_CAGE: + case THERMAL_ID_DDR4: + case THERMAL_ID_FANCARD1: + case THERMAL_ID_FANCARD2: + case THERMAL_ID_PSU0: + case THERMAL_ID_PSU1: + case THERMAL_ID_AMB: + case THERMAL_ID_PHY1: + case THERMAL_ID_HEATER: + rc = bmc_thermal_info_get(info, sensor_id); + break; + default: + return ONLP_STATUS_E_INTERNAL; + break; + } + + return rc; +} diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/x86_64_ufispace_s9500_22xst_config.c b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/x86_64_ufispace_s9500_22xst_config.c new file mode 100755 index 0000000000..02e0909035 --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/x86_64_ufispace_s9500_22xst_config.c @@ -0,0 +1,96 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 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 + +/* */ +#define __x86_64_ufispace_s9500_22xst_config_STRINGIFY_NAME(_x) #_x +#define __x86_64_ufispace_s9500_22xst_config_STRINGIFY_VALUE(_x) __x86_64_ufispace_s9500_22xst_config_STRINGIFY_NAME(_x) +x86_64_ufispace_s9500_22xst_config_settings_t x86_64_ufispace_s9500_22xst_config_settings[] = +{ +#ifdef X86_64_UFISPACE_S9500_22XST_CONFIG_INCLUDE_LOGGING + { __x86_64_ufispace_s9500_22xst_config_STRINGIFY_NAME(X86_64_UFISPACE_S9500_22XST_CONFIG_INCLUDE_LOGGING), __x86_64_ufispace_s9500_22xst_config_STRINGIFY_VALUE(X86_64_UFISPACE_S9500_22XST_CONFIG_INCLUDE_LOGGING) }, +#else +{ X86_64_UFISPACE_S9500_22XST_CONFIG_INCLUDE_LOGGING(__x86_64_ufispace_s9500_22xst_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_UFISPACE_S9500_22XST_CONFIG_LOG_OPTIONS_DEFAULT + { __x86_64_ufispace_s9500_22xst_config_STRINGIFY_NAME(X86_64_UFISPACE_S9500_22XST_CONFIG_LOG_OPTIONS_DEFAULT), __x86_64_ufispace_s9500_22xst_config_STRINGIFY_VALUE(X86_64_UFISPACE_S9500_22XST_CONFIG_LOG_OPTIONS_DEFAULT) }, +#else +{ X86_64_UFISPACE_S9500_22XST_CONFIG_LOG_OPTIONS_DEFAULT(__x86_64_ufispace_s9500_22xst_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_UFISPACE_S9500_22XST_CONFIG_LOG_BITS_DEFAULT + { __x86_64_ufispace_s9500_22xst_config_STRINGIFY_NAME(X86_64_UFISPACE_S9500_22XST_CONFIG_LOG_BITS_DEFAULT), __x86_64_ufispace_s9500_22xst_config_STRINGIFY_VALUE(X86_64_UFISPACE_S9500_22XST_CONFIG_LOG_BITS_DEFAULT) }, +#else +{ X86_64_UFISPACE_S9500_22XST_CONFIG_LOG_BITS_DEFAULT(__x86_64_ufispace_s9500_22xst_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_UFISPACE_S9500_22XST_CONFIG_LOG_CUSTOM_BITS_DEFAULT + { __x86_64_ufispace_s9500_22xst_config_STRINGIFY_NAME(X86_64_UFISPACE_S9500_22XST_CONFIG_LOG_CUSTOM_BITS_DEFAULT), __x86_64_ufispace_s9500_22xst_config_STRINGIFY_VALUE(X86_64_UFISPACE_S9500_22XST_CONFIG_LOG_CUSTOM_BITS_DEFAULT) }, +#else +{ X86_64_UFISPACE_S9500_22XST_CONFIG_LOG_CUSTOM_BITS_DEFAULT(__x86_64_ufispace_s9500_22xst_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_UFISPACE_S9500_22XST_CONFIG_PORTING_STDLIB + { __x86_64_ufispace_s9500_22xst_config_STRINGIFY_NAME(X86_64_UFISPACE_S9500_22XST_CONFIG_PORTING_STDLIB), __x86_64_ufispace_s9500_22xst_config_STRINGIFY_VALUE(X86_64_UFISPACE_S9500_22XST_CONFIG_PORTING_STDLIB) }, +#else +{ X86_64_UFISPACE_S9500_22XST_CONFIG_PORTING_STDLIB(__x86_64_ufispace_s9500_22xst_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_UFISPACE_S9500_22XST_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + { __x86_64_ufispace_s9500_22xst_config_STRINGIFY_NAME(X86_64_UFISPACE_S9500_22XST_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS), __x86_64_ufispace_s9500_22xst_config_STRINGIFY_VALUE(X86_64_UFISPACE_S9500_22XST_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS) }, +#else +{ X86_64_UFISPACE_S9500_22XST_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS(__x86_64_ufispace_s9500_22xst_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_UFISPACE_S9500_22XST_CONFIG_INCLUDE_UCLI + { __x86_64_ufispace_s9500_22xst_config_STRINGIFY_NAME(X86_64_UFISPACE_S9500_22XST_CONFIG_INCLUDE_UCLI), __x86_64_ufispace_s9500_22xst_config_STRINGIFY_VALUE(X86_64_UFISPACE_S9500_22XST_CONFIG_INCLUDE_UCLI) }, +#else +{ X86_64_UFISPACE_S9500_22XST_CONFIG_INCLUDE_UCLI(__x86_64_ufispace_s9500_22xst_config_STRINGIFY_NAME), "__undefined__" }, +#endif + { NULL, NULL } +}; +#undef __x86_64_ufispace_s9500_22xst_config_STRINGIFY_VALUE +#undef __x86_64_ufispace_s9500_22xst_config_STRINGIFY_NAME + +const char* +x86_64_ufispace_s9500_22xst_config_lookup(const char* setting) +{ + int i; + for(i = 0; x86_64_ufispace_s9500_22xst_config_settings[i].name; i++) { + if(!strcmp(x86_64_ufispace_s9500_22xst_config_settings[i].name, setting)) { + return x86_64_ufispace_s9500_22xst_config_settings[i].value; + } + } + return NULL; +} + +int +x86_64_ufispace_s9500_22xst_config_show(struct aim_pvs_s* pvs) +{ + int i; + for(i = 0; x86_64_ufispace_s9500_22xst_config_settings[i].name; i++) { + aim_printf(pvs, "%s = %s\n", x86_64_ufispace_s9500_22xst_config_settings[i].name, x86_64_ufispace_s9500_22xst_config_settings[i].value); + } + return i; +} + +/* */ + diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/x86_64_ufispace_s9500_22xst_enums.c b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/x86_64_ufispace_s9500_22xst_enums.c new file mode 100755 index 0000000000..84cf393e6f --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/x86_64_ufispace_s9500_22xst_enums.c @@ -0,0 +1,30 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 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 + +/* <--auto.start.enum(ALL).source> */ +/* */ + diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/x86_64_ufispace_s9500_22xst_int.h b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/x86_64_ufispace_s9500_22xst_int.h new file mode 100755 index 0000000000..5f39ed0885 --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/x86_64_ufispace_s9500_22xst_int.h @@ -0,0 +1,29 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 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. + * + * + ************************************************************ + * + * + * + ***********************************************************/ + +#ifndef __x86_64_ufispace_s9500_22xst_INT_H__ +#define __x86_64_ufispace_s9500_22xst_INT_H__ + +#endif /* __x86_64_ufispace_s9500_22xst_INT_H__ */ diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/x86_64_ufispace_s9500_22xst_log.c b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/x86_64_ufispace_s9500_22xst_log.c new file mode 100755 index 0000000000..3b2043fa9f --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/x86_64_ufispace_s9500_22xst_log.c @@ -0,0 +1,38 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 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 "x86_64_ufispace_s9500_22xst_log.h" +/* + * x86_64_ufispace_s9500_22xst log struct. + */ +AIM_LOG_STRUCT_DEFINE( + X86_64_UFISPACE_S9500_22XST_CONFIG_LOG_OPTIONS_DEFAULT, + X86_64_UFISPACE_S9500_22XST_CONFIG_LOG_BITS_DEFAULT, + NULL, /* Custom log map */ + X86_64_UFISPACE_S9500_22XST_CONFIG_LOG_CUSTOM_BITS_DEFAULT + ); + diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/x86_64_ufispace_s9500_22xst_log.h b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/x86_64_ufispace_s9500_22xst_log.h new file mode 100755 index 0000000000..fc57402956 --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/x86_64_ufispace_s9500_22xst_log.h @@ -0,0 +1,32 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 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. + * + * + ************************************************************ + * + * + * + ***********************************************************/ + +#ifndef __x86_64_ufispace_s9500_22xst_LOG_H__ +#define __x86_64_ufispace_s9500_22xst_LOG_H__ + +#define AIM_LOG_MODULE_NAME x86_64_ufispace_s9500_22xst +#include + +#endif /* __x86_64_ufispace_s9500_22xst_LOG_H__ */ diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/x86_64_ufispace_s9500_22xst_module.c b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/x86_64_ufispace_s9500_22xst_module.c new file mode 100755 index 0000000000..f7f907b081 --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/x86_64_ufispace_s9500_22xst_module.c @@ -0,0 +1,44 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 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 "x86_64_ufispace_s9500_22xst_log.h" + +static int +datatypes_init__(void) +{ +#define UFISPACE_S9500_22XST_ENUMERATION_ENTRY(_enum_name, _desc) AIM_DATATYPE_MAP_REGISTER(_enum_name, _enum_name##_map, _desc, AIM_LOG_INTERNAL); +#include + return 0; +} + +void __x86_64_ufispace_s9500_22xst_module_init__(void) +{ + AIM_LOG_STRUCT_REGISTER(); + datatypes_init__(); +} + +int __onlp_platform_version__ = 1; diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/x86_64_ufispace_s9500_22xst_ucli.c b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/x86_64_ufispace_s9500_22xst_ucli.c new file mode 100755 index 0000000000..bafed69bb6 --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/onlp/builds/x86_64_ufispace_s9500_22xst/module/src/x86_64_ufispace_s9500_22xst_ucli.c @@ -0,0 +1,82 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 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 + +#if X86_64_UFISPACE_S9500_22XST_CONFIG_INCLUDE_UCLI == 1 + +#include +#include +#include + +static ucli_status_t +x86_64_ufispace_s9500_22xst_ucli_ucli__config__(ucli_context_t* uc) +{ + UCLI_HANDLER_MACRO_MODULE_CONFIG(x86_64_ufispace_s9500_22xst) +} + +/* */ +/****************************************************************************** + * + * These handler table(s) were autogenerated from the symbols in this + * source file. + * + *****************************************************************************/ +static ucli_command_handler_f x86_64_ufispace_s9500_22xst_ucli_ucli_handlers__[] = +{ + x86_64_ufispace_s9500_22xst_ucli_ucli__config__, + NULL +}; +/******************************************************************************/ +/* */ + +static ucli_module_t +x86_64_ufispace_s9500_22xst_ucli_module__ = + { + "x86_64_ufispace_s9500_22xst_ucli", + NULL, + x86_64_ufispace_s9500_22xst_ucli_ucli_handlers__, + NULL, + NULL, + }; + +ucli_node_t* +x86_64_ufispace_s9500_22xst_ucli_node_create(void) +{ + ucli_node_t* n; + ucli_module_init(&x86_64_ufispace_s9500_22xst_ucli_module__); + n = ucli_node_create("x86_64_ufispace_s9500_22xst", NULL, &x86_64_ufispace_s9500_22xst_ucli_module__); + ucli_node_subnode_add(n, ucli_module_log_node_create("x86_64_ufispace_s9500_22xst")); + return n; +} + +#else +void* +x86_64_ufispace_s9500_22xst_ucli_node_create(void) +{ + return NULL; +} +#endif + diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/platform-config/Makefile b/packages/platforms/ufispace/x86-64/s9500-22xst/platform-config/Makefile new file mode 100755 index 0000000000..003238cf6d --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/platform-config/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/platform-config/r0/Makefile b/packages/platforms/ufispace/x86-64/s9500-22xst/platform-config/r0/Makefile new file mode 100755 index 0000000000..003238cf6d --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/platform-config/r0/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/platform-config/r0/PKG.yml b/packages/platforms/ufispace/x86-64/s9500-22xst/platform-config/r0/PKG.yml new file mode 100755 index 0000000000..70cd4de633 --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/platform-config/r0/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/platform-config-platform.yml ARCH=amd64 VENDOR=ufispace BASENAME=x86-64-ufispace-s9500-22xst REVISION=r0 diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/platform-config/r0/src/lib/tech_support/ioget b/packages/platforms/ufispace/x86-64/s9500-22xst/platform-config/r0/src/lib/tech_support/ioget new file mode 100755 index 0000000000..ef1e7c17ba Binary files /dev/null and b/packages/platforms/ufispace/x86-64/s9500-22xst/platform-config/r0/src/lib/tech_support/ioget differ diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/platform-config/r0/src/lib/tech_support/show_platform_log.sh b/packages/platforms/ufispace/x86-64/s9500-22xst/platform-config/r0/src/lib/tech_support/show_platform_log.sh new file mode 100755 index 0000000000..36ae2b5a16 --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/platform-config/r0/src/lib/tech_support/show_platform_log.sh @@ -0,0 +1,1469 @@ +#!/bin/bash + +SH_VER="20211005" + +# TRUE=0, FALSE=1 +TRUE=0 +FALSE=1 + + +# DATESTR: The format of log folder and log file +DATESTR=$(date +"%Y%m%d%H%M%S") +LOG_FOLDER_NAME="log_platform_${DATESTR}" +LOG_FILE_NAME="log_platform_${DATESTR}.log" + +# LOG_FOLDER_ROOT: The root folder of log files +LOG_FOLDER_ROOT="/tmp/log" +LOG_FOLDER_PATH="${LOG_FOLDER_ROOT}/${LOG_FOLDER_NAME}" +LOG_FILE_PATH="${LOG_FOLDER_PATH}/${LOG_FILE_NAME}" + + +# MODEL_NAME: set by function _board_info +MODEL_NAME="" +# HW_REV: set by function _board_info +HW_REV="" +# BSP_INIT_FLAG: set bu function _check_bsp_init +BSP_INIT_FLAG="" + +SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" +IOGET="${SCRIPTPATH}/ioget" + +# LOG_FILE_ENABLE=1: Log all the platform info to log files (${LOG_FILE_NAME}) +# LOG_FILE_ENABLE=0: Print all the platform info in console +LOG_FILE_ENABLE=1 + + +# Log Redirection +# LOG_REDIRECT="2> /dev/null": remove the error message from console +# LOG_REDIRECT="" : show the error message in console +LOG_REDIRECT="2> /dev/null" + +# GPIO_OFFSET: update by function _update_gpio_offset +GPIO_OFFSET=0 + + + +function _echo { + str="$1" + + if [ "${LOG_FILE_ENABLE}" == "1" ] && [ -f "${LOG_FILE_PATH}" ]; then + echo "${str}" >> "${LOG_FILE_PATH}" + else + echo "${str}" + fi +} + +function _run_echo { + str="$1" + + if [ "${LOG_FILE_ENABLE}" == "1" ] && [ -f "${LOG_FILE_PATH}" ]; then + eval ${str} >> "${LOG_FILE_PATH}" + else + eval ${str} + fi +} + +function _banner { + banner="$1" + + if [ ! -z "${banner}" ]; then + _echo "" + _echo "##############################" + _echo "# ${banner}" + echo "# ${banner}..." + _echo "##############################" + fi +} + +function _pkg_version { + _banner "Package Version = ${SH_VER}" +} + +function _update_gpio_offset { + _banner "Update GPIO Offset" + + max_gpiochip=`ls /sys/class/gpio/ | sort -r | grep -m1 gpiochip` + max_gpiochip_num="${max_gpiochip#*gpiochip}" + + if [ -z "${max_gpiochip_num}" ]; then + GPIO_OFFSET=0 + elif [ ${max_gpiochip_num} -lt 256 ]; then + GPIO_OFFSET=256 + else + GPIO_OFFSET=0 + fi + + _echo "[GPIOCHIP MAX ]: ${max_gpiochip}" + _echo "[GPIOCHIP MAX NUM]: ${max_gpiochip_num}" + _echo "[GPIO OFFSET ]: ${GPIO_OFFSET}" +} + +function _check_env { + #_banner "Check Environment" + + # check utility + if [ ! -f "${IOGET}" ]; then + echo "Error!!! ioget(${IOGET}) file not found!!! Exit!!!" + echo "Please update the ioget file path in script or put the ioget under ${IOGET}." + exit 1 + fi + + # check basic commands + cmd_array=("ipmitool" "lsusb" "dmidecode") + for (( i=0; i<${#cmd_array[@]}; i++ )) + do + ret=`which ${cmd_array[$i]}` + + if [ ! $? -eq 0 ]; then + _echo "${cmd_array[$i]} command not found!!" + exit 1 + fi + done + + if [ "${LOG_FILE_ENABLE}" == "1" ]; then + mkdir -p "${LOG_FOLDER_PATH}" + echo "${LOG_FILE_NAME}" > "${LOG_FILE_PATH}" + fi + + # check BSP init + _check_bsp_init + _update_gpio_offset +} + +function _check_filepath { + filepath=$1 + if [ -z "${filepath}" ]; then + _echo "ERROR, the ipnut string is empyt!!!" + return ${FALSE} + elif [ ! -f "$filepath" ]; then + _echo "ERROR: No such file: ${filepath}" + return ${FALSE} + else + #_echo "File Path: ${filepath}" + return ${TRUE} + fi +} + +function _check_i2c_device { + i2c_addr=$1 + + if [ -z "${i2c_addr}" ]; then + _echo "ERROR, the ipnut string is empyt!!!" + return ${FALSE} + fi + + value=$(eval "i2cget -y -f 0 ${i2c_addr} ${LOG_REDIRECT}") + ret=$? + + if [ $ret -eq 0 ]; then + return ${TRUE} + else + _echo "ERROR: No such device: ${i2c_addr}" + return ${FALSE} + fi +} + +function _check_bsp_init { + _banner "Check BSP Init" + + i2c_bus_0=$(eval "i2cdetect -y 0 ${LOG_REDIRECT} | grep UU") + ret=$? + if [ $ret -eq 0 ] && [ ! -z "${i2c_bus_0}" ] ; then + BSP_INIT_FLAG=1 + else + BSP_INIT_FLAG=0 + fi + + _echo "[BSP_INIT_FLAG]: ${BSP_INIT_FLAG}" +} + +function _show_system_info { + _banner "Show System Info" + + x86_date=`date` + x86_uptime=`uptime` + bmc_date=$(eval "ipmitool sel time get ${LOG_REDIRECT}") + last_login=`last` + + _echo "[X86 Date Time ]: ${x86_date}" + _echo "[BMC Date Time ]: ${bmc_date}" + _echo "[X86 Up Time ]: ${x86_uptime}" + _echo "[X86 Last Login]: " + _echo "${last_login}" + _echo "" + + cmd_array=("uname -a" "cat /proc/cmdline" "cat /proc/ioports" \ + "cat /proc/iomem" "cat /proc/meminfo" \ + "cat /proc/sys/kernel/printk" ) + + for (( i=0; i<${#cmd_array[@]}; i++ )) + do + _echo "[Command]: ${cmd_array[$i]}" + ret=$(eval "${cmd_array[$i]} ${LOG_REDIRECT}") + _echo "${ret}" + _echo "" + done + +} + +function _show_board_info { + _banner "Show Board Info" + + #check hw rev value + if [ "${BSP_INIT_FLAG}" == "1" ]; then + hw_rev_value=`i2cget -y -f 3 0x20 0x1` + rov_raw_value=`i2cget -y -f 3 0x20 0x0` + else + i2cset -y 0 0x75 0x4 + if [ "$?" != "0" ]; then + _echo "0x75 does not exist, Exit!!" + exit 255; + fi + + hw_rev_value=`i2cget -y 0 0x20 0x1` + rov_raw_value=`i2cget -y 0 0x20 0x0` + fi + + if [ "$((hw_rev_value & 0xC))" == 12 ]; then + hw_rev="PVT" + elif [ "$((hw_rev_value & 0x8))" == 8 ]; then + hw_rev="ALPHA" + elif [ "$((hw_rev_value & 0x4))" == 4 ]; then + hw_rev="BETA" + else + hw_rev="PROTO" + fi + + #check board id value + if [ "$((hw_rev_value & 0xf0))" == "$((16#00))" ]; then + model_name="S9500-22XST" + MODEL_NAME=${model_name} + else + _echo "Not support platform, Exit!!" + exit 255; + fi + + #check build rev value + if [ "$((hw_rev_value & 0x3))" == 3 ]; then + build_rev="3" + elif [ "$((hw_rev_value & 0x3))" == 1 ]; then + build_rev="2" + elif [ "$((hw_rev_value & 0x3))" == 2 ]; then + build_rev="1" + else + build_rev="0" + fi + + # finish work + if [ "${BSP_INIT_FLAG}" == "0" ]; then + i2cset -y 0 0x75 0x0 + fi + + _echo "[Board Type and Revision]: ${model_name} ${hw_rev} ${build_rev}" + _echo "[Misc. ROV Raw Info]: ${rov_raw_value}" +} + +function _bios_version { + _banner "Show BIOS Version" + + bios_ver=$(eval "dmidecode -s bios-version ${LOG_REDIRECT}") + bios_boot_rom=`${IOGET} 0x602` + if [ $? -eq 0 ]; then + bios_boot_rom=`echo ${bios_boot_rom} | awk -F" " '{print $NF}'` + fi + + _echo "[BIOS Vesion ]: ${bios_ver}" + _echo "[BIOS Boot ROM]: ${bios_boot_rom}" +} + +function _bmc_version { + _banner "Show BMC Version" + + bmc_rom1_ver=$(eval "ipmitool raw 0x32 0x8f 0x8 0x1 ${LOG_REDIRECT}") + bmc_rom2_ver=$(eval "ipmitool raw 0x32 0x8f 0x8 0x2 ${LOG_REDIRECT}") + bmc_active_rom=$(eval "ipmitool raw 0x32 0x8f 0x7 ${LOG_REDIRECT}") + + _echo "[BMC ROM1 Ver ]: ${bmc_rom1_ver}" + _echo "[BMC ROM2 Ver ]: ${bmc_rom2_ver}" + _echo "[BMC Active ROM]: ${bmc_active_rom}" +} + +function _cpld_version { + _banner "Show CPLD Version" + + # CPU CPLD + cpu_cpld_info=`${IOGET} 0x600` + ret=$? + if [ $ret -eq 0 ]; then + cpu_cpld_info=`echo ${cpu_cpld_info} | awk -F" " '{print $NF}'` + else + _echo "Get CPU CPLD version info failed ($ret), Exit!!" + exit $ret + fi + + _echo "[CPU CPLD Reg Raw]: ${cpu_cpld_info} " + _echo "[CPU CPLD Version]: $(( (cpu_cpld_info & 2#01000000) >> 6)).$(( cpu_cpld_info & 2#00111111 ))" + + # Main CPLD + mb_cpld_info=`${IOGET} 0x702` + ret=$? + if [ $ret -eq 0 ]; then + mb_cpld_info=`echo ${mb_cpld_info} | awk -F" " '{print $NF}'` + else + _echo "Get MB CPLD version info failed ($ret), Exit!!" + exit $ret + fi + + _echo "[MB CPLD Reg Raw]: ${mb_cpld_info} " + _echo "[MB CPLD Version]: $(( (mb_cpld_info & 2#01000000) >> 6)).$(( mb_cpld_info & 2#00111111 ))" + +} + +function _ucd_version { + _banner "Show UCD Version" + + + brd=("MB") + + + #get ucd date via BMC + ucd_date_raw=$(eval "ipmitool raw 0x3c 0x12 0x0 0x34 0x7 0x9d ${LOG_REDIRECT}") + + ret=$? + + #check return code + if [ ! $ret -eq 0 ] ; then + _echo "Get UCD date fail!" + return $ret + fi + + #add prefix 0x for each byte + ucd_date_hex=${ucd_date_raw// /0x} + + #convert hex to ascii + ucd_date_ascii=`echo $ucd_date_hex | xxd -r` + + ucd_date_revision=${ucd_date_ascii} + + #get ucd version via BMC + ucd_ver_raw=$(eval "ipmitool raw 0x3c 0x12 0x0 0x34 0x6 0x9b ${LOG_REDIRECT}") + + ret=$? + + #check return code + if [ ! $ret -eq 0 ] ; then + _echo "Get UCD version fail!" + return $ret + fi + + #add prefix 0x for each byte + ucd_ver_hex=${ucd_ver_raw// /0x} + + #convert hex to ascii + ucd_ver_ascii=`echo $ucd_ver_hex | xxd -r` + + #first len-6 char are for revision + ucd_ver_revision=${ucd_ver_ascii} + + _echo "[${brd[i]} MFR_REVISION]: ${ucd_ver_revision}" + _echo "[${brd[i]} MFR_DATE ]: ${ucd_date_revision}" +} + +function _show_version { + _bios_version + _bmc_version + _cpld_version + _ucd_version +} + +function _show_i2c_tree_bus_0 { + _banner "Show I2C Tree Bus 0" + + ret=$(eval "i2cdetect -y 0 ${LOG_REDIRECT}") + + _echo "[I2C Tree]:" + _echo "${ret}" +} + +function _show_i2c_mux_devices { + local chip_addr=$1 + local channel_num=$2 + local chip_dev_desc=$3 + local i=0; + + if [ -z "${chip_addr}" ] || [ -z "${channel_num}" ] || [ -z "${chip_dev_desc}" ]; then + _echo "ERROR: parameter cannot be empty!!!" + exit 99 + fi + + _check_i2c_device "$chip_addr" + ret=$? + if [ "$ret" == "0" ]; then + _echo "TCA9548 Mux ${chip_dev_desc}" + _echo "---------------------------------------------------" + for (( i=0; i<${channel_num}; i++ )) + do + _echo "TCA9548 Mux ${chip_dev_desc} - Channel ${i}" + # open mux channel - 0x75 + i2cset -y 0 ${chip_addr} $(( 2 ** ${i} )) + # dump i2c tree + ret=$(eval "i2cdetect -y 0 ${LOG_REDIRECT}") + _echo "${ret}" + # close mux channel + i2cset -y 0 ${chip_addr} 0x0 + _echo "" + done + fi + +} + +function _show_i2c_tree_bus_mux_i2c { + _banner "Show I2C Tree Bus MUX (I2C)" + + local chip_addr1="" + local chip_addr2_1="" + local chip_addr2_2="" + local chip_addr2_3="" + local chip_addr2_4="" + + if [ "${MODEL_NAME}" == "S9500-22XST" ]; then + ## ROOT-0x75 + _show_i2c_mux_devices "0x75" "8" "ROOT-0x75" + + ## ROOT-0x76 + _show_i2c_mux_devices "0x76" "8" "ROOT-0x76" + + ## ROOT-0x76-Channel(0~7)-0x76-Channel(0~7) + chip_addr1="0x76" + chip_addr2_1="0x72" + chip_addr2_2="0x73" + chip_addr2_3="0x74" + chip_addr2_4="0x70" + _check_i2c_device "${chip_addr1}" + ret=$? + if [ "$ret" == "0" ]; then + # open mux channel - 0x76 (chip_addr1) + i2cset -y 0 ${chip_addr1} 0x8 + _show_i2c_mux_devices "${chip_addr2_1}" "8" "ROOT-${chip_addr1}-3-${chip_addr2_1}" + # close mux channel - 0x72 (chip_addr1) + i2cset -y 0 ${chip_addr1} 0x0 + + # open mux channel - 0x76 (chip_addr1) + i2cset -y 0 ${chip_addr1} 0x8 + _show_i2c_mux_devices "${chip_addr2_2}" "8" "ROOT-${chip_addr1}-3-${chip_addr2_2}" + # close mux channel - 0x72 (chip_addr1) + i2cset -y 0 ${chip_addr1} 0x0 + + # open mux channel - 0x76 (chip_addr1) + i2cset -y 0 ${chip_addr1} 0x8 + _show_i2c_mux_devices "${chip_addr2_3}" "8" "ROOT-${chip_addr1}-3-${chip_addr2_3}" + # close mux channel - 0x72 (chip_addr1) + i2cset -y 0 ${chip_addr1} 0x0 + + # open mux channel - 0x76 (chip_addr1) + i2cset -y 0 ${chip_addr1} 0x8 + _show_i2c_mux_devices "${chip_addr2_4}" "8" "ROOT-${chip_addr1}-3-${chip_addr2_4}" + # close mux channel - 0x72 (chip_addr1) + i2cset -y 0 ${chip_addr1} 0x0 + fi + else + echo "Unknown MODEL_NAME (${MODEL_NAME}), exit!!!" + exit 1 + fi +} + +function _show_i2c_tree_bus_mux_sysfs { + _banner "Show I2C Tree Bus MUX (sysfs)" + + local i2c_bus="" + + if [ "${MODEL_NAME}" == "S9500-22XST" ]; then + all_i2c_bus=`ls /dev/i2c-* | awk -F"-" '{print $2}'` + for i2c_bus in ${all_i2c_bus} + do + _echo "I2C bus: ${i2c_bus}" + _echo "---------------------------------------------------" + ret=$(eval "i2cdetect -y ${i2c_bus} ${LOG_REDIRECT}") + _echo "${ret}" + done + else + echo "Unknown MODEL_NAME (${MODEL_NAME}), exit!!!" + exit 1 + fi +} + +function _show_i2c_tree { + _banner "Show I2C Tree" + + _show_i2c_tree_bus_0 + + if [ "${BSP_INIT_FLAG}" == "1" ]; then + _show_i2c_tree_bus_mux_sysfs + else + _show_i2c_tree_bus_mux_i2c + fi + + _show_i2c_tree_bus_0 +} + +function _show_i2c_device_info { + _banner "Show I2C Device Info" + + ret=`i2cdump -y -f 0 0x77 b` + _echo "[I2C Device 0x77]:" + _echo "${ret}" + _echo "" + + local pca954x_device_id=("") + if [ "${MODEL_NAME}" == "S9500-22XST" ]; then + pca954x_device_id=("0x75" "0x76") + else + _echo "Unknown MODEL_NAME (${MODEL_NAME}), exit!!!" + exit 1 + fi + + for ((i=0;i<5;i++)) + do + _echo "[DEV PCA9548 (${i})]" + for (( j=0; j<${#pca954x_device_id[@]}; j++ )) + do + ret=`i2cget -f -y 0 ${pca954x_device_id[$j]}` + _echo "[I2C Device ${pca954x_device_id[$j]}]: $ret" + done + sleep 0.4 + done +} + +function _show_sys_devices { + _banner "Show System Devices" + + _echo "[Command]: ls /sys/class/gpio/" + ret=($(ls /sys/class/gpio/)) + _echo "#${ret[*]}" + + # show all gpio value and direction + dev_num=`ls /sys/class/gpio | grep -v 'gpiochip\|export'` + for i in ${dev_num} + do + gpio_dir=`cat /sys/class/gpio/${i}/direction` + gpio_val=`cat /sys/class/gpio/${i}/value` + _echo "[${i}] Direction: ${gpio_dir} Value: ${gpio_val}" + done + + local file_path="/sys/kernel/debug/gpio" + if [ -f "${file_path}" ]; then + _echo "" + _echo "[Command]: cat ${file_path}" + _echo "$(cat ${file_path})" + fi + + _echo "" + _echo "[Command]: ls /sys/bus/i2c/devices/" + ret=($(ls /sys/bus/i2c/devices/)) + _echo "#${ret[*]}" + + _echo "" + _echo "[Command]: ls /dev/" + ret=($(ls /dev/)) + _echo "#${ret[*]}" +} + +function _show_cpu_eeprom_i2c { + _banner "Show CPU EEPROM" + + cpu_eeprom=$(eval "i2cdump -y 0 0x57 c") + cpu_eeprom=$(eval "i2cdump -y 0 0x57 c") + _echo "[CPU EEPROM]:" + _echo "${cpu_eeprom}" +} + +function _show_cpu_eeprom_sysfs { + _banner "Show CPU EEPROM" + + cpu_eeprom=$(eval "cat /sys/bus/i2c/devices/0-0057/eeprom ${LOG_REDIRECT} | hexdump -C") + _echo "[CPU EEPROM]:" + _echo "${cpu_eeprom}" +} + +function _show_cpu_eeprom { + if [ "${BSP_INIT_FLAG}" == "1" ]; then + _show_cpu_eeprom_sysfs + else + _show_cpu_eeprom_i2c + fi +} + +function _show_psu_status { + _banner "Show PSU Status" + + bus_id="" + if [ "${MODEL_NAME}" != "S9500-22XST" ]; then + _echo "Unknown MODEL_NAME (${MODEL_NAME}), exit!!!" + exit 1 + fi + + # Read PSU0 Power Good Status (1: power good, 0: not providing power) + cpld_psu_status_0_reg=`${IOGET} 0x708 | awk -F'is ' '{print $2}'` + psu0_power_ok=$(((cpld_psu_status_0_reg & 2#00001000) >> 3)) + + # Read PSU0 Absent Status (0: psu present, 1: psu absent) + psu0_absent_l=$(((cpld_psu_status_0_reg & 2#00000010) >> 1)) + + # Read PSU1 Power Good Status (1: power good, 0: not providing power) + psu1_power_ok=$(((cpld_psu_status_0_reg & 2#00000100) >> 2)) + + # Read PSU1 Absent Status (0: psu present, 1: psu absent) + psu1_absent_l=$(((cpld_psu_status_0_reg & 2#00000001))) + + + _echo "[PSU0 Status Reg Raw ]: ${cpld_psu_status_0_reg}" + _echo "[PSU0 Power Good Status]: ${psu0_power_ok}" + _echo "[PSU0 Absent Status (L)]: ${psu0_absent_l}" + _echo "[PSU1 Status Reg Raw ]: ${cpld_psu_status_0_reg}" + _echo "[PSU1 Power Good Status]: ${psu1_power_ok}" + _echo "[PSU1 Absent Status (L)]: ${psu1_absent_l}" +} + +function _show_rov { + _echo "ROV info is included in _show_board_info" +} + +function _show_port_status_sysfs { + _banner "Show Port Status / EEPROM" + echo " Show Port Status / EEPROM, please wait..." + + bus_id="" + + if [ "${MODEL_NAME}" == "S9500-22XST" ]; then + sfp_bus_id="7" + qsfp_bus_id="5" + + sfp_eeprom_bus_id_array=( "-1" "-1" "-1" "-1" "9" \ + "10" "11" "12" "13" "14" \ + "15" "16" "21" "22" "23" \ + "24" "25" "26" "27" "28" ) + + sfp_status_ioexp_addr_array=("-1" "-1" "-1" "-1" "0x20" \ + "0x20" "0x20" "0x20" "0x20" "0x20" \ + "0x20" "0x20" "0x22" "0x22" "0x22" \ + "0x22" "0x22" "0x22" "0x22" "0x22" ) + + sfp_status_ioexp_reg_array=( "-1" "-1" "-1" "-1" "1" \ + "1" "1" "1" "1" "1" \ + "1" "1" "0" "0" "0" \ + "0" "1" "1" "1" "1" ) + + sfp_status_ioexp_index_array=( "-1" "-1" "-1" "-1" "80" \ + "40" "20" "10" "08" "04" \ + "02" "01" "08" "04" "02" \ + "01" "80" "40" "20" "10" ) + + for (( i=4; i<${#sfp_eeprom_bus_id_array[@]}; i++ )) + do + # Module NIF Port present status (0: Present, 1:Absence) + sfp_port_status_reg=$(eval "i2cget -y -f ${sfp_bus_id} ${sfp_status_ioexp_addr_array[${i}]} ${sfp_status_ioexp_reg_array[${i}]} ${LOG_REDIRECT}") + sfp_module_absent=$((sfp_port_status_reg & 16#${sfp_status_ioexp_index_array[${i}]})) + if [ "${sfp_module_absent}" == "0" ]; then + sfp_module_absent=0 + else + sfp_module_absent=1 + fi + + + # Module NIF Port Dump EEPROM + if [ "${sfp_module_absent}" == "0" ]; then + _check_filepath "/sys/bus/i2c/devices/${sfp_eeprom_bus_id_array[${i}]}-0050/eeprom" + port_eeprom_A0_1st=$(eval "dd if=/sys/bus/i2c/devices/${sfp_eeprom_bus_id_array[${i}]}-0050/eeprom bs=128 count=2 skip=0 status=none ${LOG_REDIRECT} | hexdump -C") + port_eeprom_A0_2nd=$(eval "dd if=/sys/bus/i2c/devices/${sfp_eeprom_bus_id_array[${i}]}-0050/eeprom bs=128 count=2 skip=0 status=none ${LOG_REDIRECT} | hexdump -C") + port_eeprom_A2_1st=$(eval "i2cdump -y -f ${sfp_eeprom_bus_id_array[${i}]} 0x51 ${LOG_REDIRECT}") + port_eeprom_A2_2nd=$(eval "i2cdump -y -f ${sfp_eeprom_bus_id_array[${i}]} 0x51 ${LOG_REDIRECT}") + if [ -z "$port_eeprom_A0_1st" ]; then + port_eeprom_A0_1st="ERROR!!! The result is empty. It should read failed (/sys/bus/i2c/devices/${sfp_eeprom_bus_id_array[${i}]}-0050/eeprom)!!" + fi + + # Full EEPROM Log + #if [ "${LOG_FILE_ENABLE}" == "1" ]; then + # hexdump -C "/sys/bus/i2c/devices/${sfp_eeprom_bus_id_array[${i}]}-0050/eeprom" > ${LOG_FOLDER_PATH}/qsfp_port${i}_eeprom.log 2>&1 + #fi + else + port_eeprom_A0_1st="N/A" + port_eeprom_A0_2nd="N/A" + port_eeprom_A2_1st="N/A" + port_eeprom_A2_2nd="N/A" + fi + + _echo "[Port${i} Status Reg Raw]: ${sfp_port_status_reg}" + #_echo "[Port${i} Module INT (L)]: ${port_module_interrupt_l}" + _echo "[Port${i} Module Absent ]: ${sfp_module_absent}" + #_echo "[Port${i} Config Reg Raw]: ${cpld_qsfp_port_config_reg}" + #_echo "[Port${i} Low Power Mode]: ${port_lp_mode}" + _echo "[Port${i} EEPROM A0h(1st)]:" + _echo "${port_eeprom_A0_1st}" + _echo "[Port${i} EEPROM A0h(2nd)]:" + _echo "${port_eeprom_A0_2nd}" + _echo "[Port${i} EEPROM A2h (1st)]:" + _echo "${port_eeprom_A2_1st}" + _echo "[Port${i} EEPROM A2h (2nd)]:" + _echo "${port_eeprom_A2_2nd}" + _echo "" + done + + qsfp_eeprom_bus_id_array=( "36" "35" ) + + qsfp_status_ioexp_addr_array=( "0x21" "0x21" ) + + qsfp_status_ioexp_reg_array=( "0" "0" ) + + qsfp_status_ioexp_index_array=( "20" "10" ) + + for (( i=0; i<${#qsfp_eeprom_bus_id_array[@]}; i++ )) + do + # Module NIF Port present status (0: Present, 1:Absence) + qsfp_port_status_reg=$(eval "i2cget -y -f ${qsfp_bus_id} ${qsfp_status_ioexp_addr_array[${i}]} ${qsfp_status_ioexp_reg_array[${i}]} ${LOG_REDIRECT}") + qsfp_module_absent=$((qsfp_port_status_reg & 16#${qsfp_status_ioexp_index_array[${i}]})) + if [ "${qsfp_module_absent}" == "0" ]; then + qsfp_module_absent=0 + else + qsfp_module_absent=1 + fi + + + # Module NIF Port Dump EEPROM + if [ "${qsfp_module_absent}" == "0" ]; then + _check_filepath "/sys/bus/i2c/devices/${qsfp_eeprom_bus_id_array[${i}]}-0050/eeprom" + port_eeprom_p0_1st=$(eval "dd if=/sys/bus/i2c/devices/${qsfp_eeprom_bus_id_array[${i}]}-0050/eeprom bs=128 count=2 skip=0 status=none ${LOG_REDIRECT} | hexdump -C") + port_eeprom_p0_2nd=$(eval "dd if=/sys/bus/i2c/devices/${qsfp_eeprom_bus_id_array[${i}]}-0050/eeprom bs=128 count=2 skip=0 status=none ${LOG_REDIRECT} | hexdump -C") + port_eeprom_p17_1st=$(eval "dd if=/sys/bus/i2c/devices/${qsfp_eeprom_bus_id_array[${i}]}-0050/eeprom bs=128 count=1 skip=18 status=none ${LOG_REDIRECT} | hexdump -C") + port_eeprom_p17_2nd=$(eval "dd if=/sys/bus/i2c/devices/${qsfp_eeprom_bus_id_array[${i}]}-0050/eeprom bs=128 count=1 skip=18 status=none ${LOG_REDIRECT} | hexdump -C") + if [ -z "$port_eeprom_p0_1st" ]; then + port_eeprom_p0_1st="ERROR!!! The result is empty. It should read failed (/sys/bus/i2c/devices/${qsfp_eeprom_bus_id_array[${i}]}-0050/eeprom)!!" + fi + + # Full EEPROM Log + if [ "${LOG_FILE_ENABLE}" == "1" ]; then + hexdump -C "/sys/bus/i2c/devices/${qsfp_eeprom_bus_id_array[${i}]}-0050/eeprom" > ${LOG_FOLDER_PATH}/qsfp_port${i}_eeprom.log 2>&1 + fi + else + port_eeprom_p0_1st="N/A" + port_eeprom_p0_2nd="N/A" + port_eeprom_p17_1st="N/A" + port_eeprom_p17_2nd="N/A" + fi + + _echo "[Port${i} Status Reg Raw]: ${qsfp_port_status_reg}" + #_echo "[Port${i} Module INT (L)]: ${port_module_interrupt_l}" + _echo "[Port${i} Module Absent ]: ${port_module_absent}" + #_echo "[Port${i} Config Reg Raw]: ${cpld_qsfp_port_config_reg}" + #_echo "[Port${i} Low Power Mode]: ${port_lp_mode}" + _echo "[Port${i} EEPROM Page0-0(1st)]:" + _echo "${port_eeprom_p0_1st}" + _echo "[Port${i} EEPROM Page0-0(2nd)]:" + _echo "${port_eeprom_p0_2nd}" + _echo "[Port${i} EEPROM Page17 (1st)]:" + _echo "${port_eeprom_p17_1st}" + _echo "[Port${i} EEPROM Page17 (2nd)]:" + _echo "${port_eeprom_p17_2nd}" + _echo "" + done + else + _echo "Unknown MODEL_NAME (${MODEL_NAME}), exit!!!" + exit 1 + fi +} + +function _show_port_status { + if [ "${BSP_INIT_FLAG}" == "1" ]; then + _show_port_status_sysfs + fi +} + +function _show_cpu_temperature_sysfs { + _banner "show CPU Temperature" + + for ((i=1;i<=5;i++)) + do + if [ -f "/sys/devices/platform/coretemp.0/hwmon/hwmon0/temp${i}_input" ]; then + _check_filepath "/sys/devices/platform/coretemp.0/hwmon/hwmon0/temp${i}_input" + _check_filepath "/sys/devices/platform/coretemp.0/hwmon/hwmon0/temp${i}_max" + _check_filepath "/sys/devices/platform/coretemp.0/hwmon/hwmon0/temp${i}_crit" + temp_input=$(eval "cat /sys/devices/platform/coretemp.0/hwmon/hwmon0/temp${i}_input ${LOG_REDIRECT}") + temp_max=$(eval "cat /sys/devices/platform/coretemp.0/hwmon/hwmon0/temp${i}_max ${LOG_REDIRECT}") + temp_crit=$(eval "cat /sys/devices/platform/coretemp.0/hwmon/hwmon0/temp${i}_crit ${LOG_REDIRECT}") + elif [ -f "/sys/devices/platform/coretemp.0/temp${i}_input" ]; then + _check_filepath "/sys/devices/platform/coretemp.0/temp${i}_input" + _check_filepath "/sys/devices/platform/coretemp.0/temp${i}_max" + _check_filepath "/sys/devices/platform/coretemp.0/temp${i}_crit" + temp_input=$(eval "cat /sys/devices/platform/coretemp.0/temp${i}_input ${LOG_REDIRECT}") + temp_max=$(eval "cat /sys/devices/platform/coretemp.0/temp${i}_max ${LOG_REDIRECT}") + temp_crit=$(eval "cat /sys/devices/platform/coretemp.0/temp${i}_crit ${LOG_REDIRECT}") + else + _echo "sysfs of CPU core temperature not found!!!" + fi + + _echo "[CPU Core Temp${i} Input ]: ${temp_input}" + _echo "[CPU Core Temp${i} Max ]: ${temp_max}" + _echo "[CPU Core Temp${i} Crit ]: ${temp_crit}" + _echo "" + done + + if [ -f "/sys/bus/i2c/devices/0-004f/hwmon/hwmon1/temp1_input" ]; then + _check_filepath "/sys/bus/i2c/devices/0-004f/hwmon/hwmon1/temp1_input" + _check_filepath "/sys/bus/i2c/devices/0-004f/hwmon/hwmon1/temp1_max" + _check_filepath "/sys/bus/i2c/devices/0-004f/hwmon/hwmon1/temp1_max_hyst" + temp_input=$(eval "cat /sys/bus/i2c/devices/0-004f/hwmon/hwmon1/temp1_input ${LOG_REDIRECT}") + temp_max=$(eval "cat /sys/bus/i2c/devices/0-004f/hwmon/hwmon1/temp1_max ${LOG_REDIRECT}") + temp_max_hyst=$(eval "cat /sys/bus/i2c/devices/0-004f/hwmon/hwmon1/temp1_max_hyst ${LOG_REDIRECT}") + elif [ -f "/sys/bus/i2c/devices/0-004f/hwmon/hwmon1/device/temp1_input" ]; then + _check_filepath "/sys/bus/i2c/devices/0-004f/hwmon/hwmon1/device/temp1_input" + _check_filepath "/sys/bus/i2c/devices/0-004f/hwmon/hwmon1/device/temp1_max" + _check_filepath "/sys/bus/i2c/devices/0-004f/hwmon/hwmon1/device/temp1_max_hyst" + temp_input=$(eval "cat /sys/bus/i2c/devices/0-004f/hwmon/hwmon1/device/temp1_input ${LOG_REDIRECT}") + temp_max=$(eval "cat /sys/bus/i2c/devices/0-004f/hwmon/hwmon1/device/temp1_max ${LOG_REDIRECT}") + temp_max_hyst=$(eval "cat /sys/bus/i2c/devices/0-004f/hwmon/hwmon1/device/temp1_max_hyst ${LOG_REDIRECT}") + else + _echo "sysfs of CPU board temperature not found!!!" + fi + + _echo "[CPU Board Temp Input ]: ${temp_input}" + _echo "[CPU Board Temp Max ]: ${temp_max}" + _echo "[CPU Board Temp Max Hyst]: ${temp_max_hyst}" +} + +function _show_cpu_temperature { + if [ "${BSP_INIT_FLAG}" == "1" ]; then + _show_cpu_temperature_sysfs + fi +} + +function _show_cpld_cpudebug_register { + _banner "Show CPLD all and some CPU debug register" + + if [ "${MODEL_NAME}" == "S9500-22XST" ]; then + mb_start_cpld_reg=0x700 + mb_end_cpld_reg=0x71c + + # MB CPLD register value + _echo "[MB CPLD]:" + for (( i=${mb_start_cpld_reg}; i<=${mb_end_cpld_reg}; i++ )) + do + addr=$(eval "printf '%x' ${i}") + ret=$(eval "${IOGET} ${addr} ${LOG_REDIRECT}") + _echo "${ret}" + done + + cpu_start_cpld_reg=0x600 + cpu_end_cpld_reg=0x606 + + # CPU CPLD register value + _echo "[CPU CPLD]:" + for (( i=${cpu_start_cpld_reg}; i<=${cpu_end_cpld_reg}; i++ )) + do + addr=$(eval "printf '%x' ${i}") + ret=$(eval "${IOGET} ${addr} ${LOG_REDIRECT}") + _echo "${ret}" + done + + _run_echo "${IOGET} 0x501 ${LOG_REDIRECT}" + _run_echo "${IOGET} 0xf000 ${LOG_REDIRECT}" + _run_echo "${IOGET} 0xf011 ${LOG_REDIRECT}" + else + _echo "Unknown MODEL_NAME (${MODEL_NAME}), exit!!!" + exit 1 + fi + +} + +function _show_cpld_error_log { + _banner "Show CPLD Error Log" + + _echo "Register: 0xB7 0xB6 0xB5 0xB4" + _echo "=============================" + for ((i=0;i<256;i++)) + do + i2cset -y 0 0x66 0xbf 0x00 + i2cset -y 0 0x66 0xb9 0x00 + i2cset -y 0 0x66 0xb8 ${i} + i2cset -y 0 0x66 0xba 0x01 + i2cset -y 0 0x66 0xbb 0x01 + + reg_0xb7=`i2cget -y 0 0x66 0xb7` + reg_0xb6=`i2cget -y 0 0x66 0xb6` + reg_0xb5=`i2cget -y 0 0x66 0xb5` + ret_0xb4=`i2cget -y 0 0x66 0xb4` + + _echo "$(printf "Addr_%03d: %s %s %s %s\n" $i ${reg_0xb7} ${reg_0xb6} ${reg_0xb5} ${ret_0xb4})" + done +} + +# Note: In order to prevent affecting MCE mechanism, +# the function will not clear the 0x425 and 0x429 registers at step 1.1/1.2, +# and only use to show the current correctable error count. +function _show_memory_correctable_error_count { + _banner "Show Memory Correctable Error Count" + + which rdmsr > /dev/null 2>&1 + ret_rdmsr=$? + which wrmsr > /dev/null 2>&1 + ret_wrmsr=$? + + if [ ${ret_rdmsr} -eq 0 ] && [ ${ret_wrmsr} -eq 0 ]; then + ERROR_COUNT_THREASHOLD=12438 + modprobe msr + + # Step 0.1: Before clear the register, dump the correctable error count in channel 0 bank 9 + reg_c0_str=`rdmsr -p0 0x425` + reg_c0_value=`printf "%u\n" 0x${reg_c0_str}` + # CORRECTED_ERR_COUNT bit[52:38] + error_count_c0=$(((reg_c0_value >> 38) & 0x7FFF)) + _echo "[Ori_C0_Error_Count]: ${error_count_c0}" + + # Step 0.2: Before clear the register, dump the correctable error count in channel 1 bank 10 + reg_c1_str=`rdmsr -p0 0x429` + reg_c1_value=`printf "%u\n" 0x${reg_c1_str}` + # CORRECTED_ERR_COUNT bit[52:38] + error_count_c1=$(((reg_c1_value >> 38) & 0x7FFF)) + _echo "[Ori_C1_Error_Count]: ${error_count_c1}" + + # Step 1.1: clear correctable error count in channel 0 bank 9 + #wrmsr -p0 0x425 0x0 + + # Step 1.2: clear correctable error count in channel 1 bank 10 + #wrmsr -p0 0x429 0x0 + + # Step 2: wait 2 seconds + sleep 2 + + # Step 3.1: Read correctable error count in channel 0 bank 9 + reg_c0_str=`rdmsr -p0 0x425` + reg_c0_value=`printf "%u\n" 0x${reg_c0_str}` + # CORRECTED_ERR_COUNT bit[52:38] + error_count_c0=$(((reg_c0_value >> 38) & 0x7FFF)) + if [ ${error_count_c0} -gt ${ERROR_COUNT_THREASHOLD} ]; then + _echo "[ERROR] Channel 0 Bank 9 Register Value: 0x${reg_c0_str}, Error Count: ${error_count_c0}" + else + _echo "[Info] Channel 0 Bank 9 Register Value: 0x${reg_c0_str}, Error Count: ${error_count_c0}" + fi + + # Step 3.2: Read correctable error count in channel 1 bank 10 + reg_c1_str=`rdmsr -p0 0x429` + reg_c1_value=`printf "%u\n" 0x${reg_c1_str}` + # CORRECTED_ERR_COUNT bit[52:38] + error_count_c1=$(((reg_c1_value >> 38) & 0x7FFF)) + if [ ${error_count_c1} -gt ${ERROR_COUNT_THREASHOLD} ]; then + _echo "[ERROR] Channel 1 Bank 10 Register Value: 0x${reg_c1_str}, Error Count: ${error_count_c1}" + else + _echo "[Info] Channel 1 Bank 10 Register Value: 0x${reg_c1_str}, Error Count: ${error_count_c1}" + fi + else + _echo "Not support! Please install msr-tools to enble this function." + fi +} + +function _show_usb_info { + _banner "Show USB Info" + + _echo "[Command]: lsusb -v" + ret=$(eval "lsusb -v ${LOG_REDIRECT}") + _echo "${ret}" + _echo "" + + _echo "[Command]: lsusb -t" + ret=$(eval "lsusb -t ${LOG_REDIRECT}") + _echo "${ret}" + _echo "" + + # check usb auth + _echo "[USB Port Authentication]: " + usb_auth_file_array=("/sys/bus/usb/devices/usb2/authorized" \ + "/sys/bus/usb/devices/usb2/authorized_default" \ + "/sys/bus/usb/devices/usb2/2-4/authorized" \ + "/sys/bus/usb/devices/usb2/2-4/2-4.1/authorized" \ + "/sys/bus/usb/devices/usb2/2-4/2-4:1.0/authorized" ) + + for (( i=0; i<${#usb_auth_file_array[@]}; i++ )) + do + _check_filepath "${usb_auth_file_array[$i]}" + if [ -f "${usb_auth_file_array[$i]}" ]; then + ret=$(eval "cat ${usb_auth_file_array[$i]} ${LOG_REDIRECT}") + _echo "${usb_auth_file_array[$i]}: $ret" + else + _echo "${usb_auth_file_array[$i]}: -1" + fi + done +} + +function _show_scsi_device_info { + _banner "Show SCSI Device Info" + + scsi_device_info=$(eval "cat /proc/scsi/sg/device_strs ${LOG_REDIRECT}") + _echo "[SCSI Device Info]: " + _echo "${scsi_device_info}" + _echo "" +} + +function _show_onie_upgrade_info { + _banner "Show ONIE Upgrade Info" + + if [ -d "/sys/firmware/efi" ]; then + if [ ! -d "/mnt/onie-boot/" ]; then + mkdir /mnt/onie-boot + fi + + mount LABEL=ONIE-BOOT /mnt/onie-boot/ + onie_show_version=`/mnt/onie-boot/onie/tools/bin/onie-version` + onie_show_pending=`/mnt/onie-boot/onie/tools/bin/onie-fwpkg show-pending` + onie_show_result=`/mnt/onie-boot/onie/tools/bin/onie-fwpkg show-results` + onie_show_log=`/mnt/onie-boot/onie/tools/bin/onie-fwpkg show-log` + umount /mnt/onie-boot/ + + _echo "[ONIE Show Version]:" + _echo "${onie_show_version}" + _echo "" + else + _echo "BIOS is in Legacy Mode!!!!!" + fi +} + +function _show_disk_info { + _banner "Show Disk Info" + + cmd_array=("lsblk" "parted -l /dev/sda" "fdisk -l /dev/sda" "cat /sys/fs/*/*/errors_count") + + for (( i=0; i<${#cmd_array[@]}; i++ )) + do + _echo "[Command]: ${cmd_array[$i]}" + ret=$(eval "${cmd_array[$i]} ${LOG_REDIRECT}") + _echo "${ret}" + _echo "" + done + + # check smartctl command + cmd="smartctl -a /dev/sda" + ret=`which smartctl` + if [ ! $? -eq 0 ]; then + _echo "[command]: ($cmd) not found (SKIP)!!" + else + ret=$(eval "$cmd ${LOG_REDIRECT}") + _echo "[command]: $cmd" + _echo "${ret}" + fi + +} + +function _show_lspci { + _banner "Show lspci Info" + + ret=`lspci` + _echo "${ret}" + _echo "" + + _echo "[PCI Bridge Hotplug Status]: " + pci_device_id=($(lspci | grep "PLX Technology" | awk '{print $1}')) + for i in "${pci_device_id[@]}" + do + ret=`lspci -vvv -s ${i} | grep HotPlug` + _echo "${i} ${ret}" + done +} + +function _show_lspci_detail { + _banner "Show lspci Detail Info" + + ret=$(eval "lspci -xxxx -vvv ${LOG_REDIRECT}") + _echo "${ret}" +} + +function _show_proc_interrupt { + _banner "Show Proc Interrupts" + + for i in {1..5}; + do + ret=$(eval "cat /proc/interrupts ${LOG_REDIRECT}") + _echo "[Proc Interrupts ($i)]:" + _echo "${ret}" + _echo "" + sleep 1 + done +} + +function _show_ipmi_info { + _banner "Show IPMI Info" + + ipmi_folder="/proc/ipmi/0/" + + if [ -d "${ipmi_folder}" ]; then + ipmi_file_array=($(ls ${ipmi_folder})) + for (( i=0; i<${#ipmi_file_array[@]}; i++ )) + do + _echo "[Command]: cat ${ipmi_folder}/${ipmi_file_array[$i]} " + ret=$(eval "cat "${ipmi_folder}/${ipmi_file_array[$i]}" ${LOG_REDIRECT}") + _echo "${ret}" + _echo "" + done + else + _echo "Warning, folder not found (${ipmi_folder})!!!" + fi + + _echo "[Command]: lsmod | grep ipmi " + ret=`lsmod | grep ipmi` + _echo "${ret}" +} + +function _show_bios_info { + _banner "Show BIOS Info" + + cmd_array=("dmidecode -t 0" \ + "dmidecode -t 1" \ + "dmidecode -t 2" \ + "dmidecode -t 3") + + for (( i=0; i<${#cmd_array[@]}; i++ )) + do + _echo "[Command]: ${cmd_array[$i]} " + ret=$(eval "${cmd_array[$i]} ${LOG_REDIRECT}") + _echo "${ret}" + _echo "" + done +} + +function _show_bmc_info { + _banner "Show BMC Info" + + cmd_array=("ipmitool mc info" "ipmitool lan print" "ipmitool sel info" \ + "ipmitool fru -v" "ipmitool power status" \ + "ipmitool channel info 0xf" "ipmitool channel info 0x1" \ + "ipmitool sol info 0x1" "ipmitool i2c bus=2 0x80 0x1 0x45" \ + "ipmitool mc watchdog get" "ipmitool mc info -I usb") + + for (( i=0; i<${#cmd_array[@]}; i++ )) + do + _echo "[Command]: ${cmd_array[$i]} " + ret=$(eval "${cmd_array[$i]} ${LOG_REDIRECT}") + _echo "${ret}" + _echo "" + done + +} + +function _show_bmc_device_status { + _banner "Show BMC Device Status" + + # Step1: Stop IPMI Polling + ret=$(eval "ipmitool raw 0x3c 0x07 0x1 ${LOG_REDIRECT}") + _echo "[Stop IPMI Polling ]: ${ret}" + _echo "" + sleep 3 + + # UCD Device + # Step1: Stop IPMI Polling + # Step2: Switch I2C MUX to UCD related channel + # Step3: Check status register of UCD + # Step4: Re-start IPMI polling + _echo "[UCD Device Status (BMC) ]" + if [ "${MODEL_NAME}" == "S9500-22XST" ]; then + ## Step1: Stop IPMI Polling + #ret=$(eval "ipmitool raw 0x3c 0x4 0x9 0x1 0x0 ${LOG_REDIRECT}") + #_echo "[Stop IPMI Polling ]: ${ret}" + #sleep 3 + + # Step2: Switch I2C MUX to UCD related channel + # Nothing to do + + # Step3: Check Status Register of UCD + status_word=$(eval "ipmitool raw 0x3c 0x12 0x0 0x34 0x2 0x79 ${LOG_REDIRECT}" | head -n 1) + logged_faults=$(eval "ipmitool raw 0x3c 0x12 0x0 0x34 0xf 0xea ${LOG_REDIRECT}") + mfr_status=$(eval "ipmitool raw 0x3c 0x12 0x0 0x34 0x5 0xf3 ${LOG_REDIRECT}") + status_vout=$(eval "ipmitool raw 0x3c 0x12 0x0 0x34 0x1 0x7a ${LOG_REDIRECT}" | head -n 1) + status_iout=$(eval "ipmitool raw 0x3c 0x12 0x0 0x34 0x1 0x7b ${LOG_REDIRECT}" | head -n 1) + status_temperature=$(eval "ipmitool raw 0x3c 0x12 0x0 0x34 0x1 0x7d ${LOG_REDIRECT}" | head -n 1) + status_cml=$(eval "ipmitool raw 0x3c 0x12 0x0 0x34 0x1 0x7e ${LOG_REDIRECT}" | head -n 1) + _echo "[UCD Status Word ]: ${status_word}" + _echo "[UCD Logged Faults ]: ${logged_faults}" + _echo "[UCD MFR Status ]: ${mfr_status}" + _echo "[UCD Status VOUT ]: ${status_vout}" + _echo "[UCD Status IOUT ]: ${status_iout}" + _echo "[UCD Status Tempe ]: ${status_temperature}" + _echo "[UCD Status CML ]: ${status_cml}" + _echo "" + + ## Step4: Re-start IPMI polling + #ret=$(eval "ipmitool raw 0x3c 0x4 0x9 0x1 0x1 ${LOG_REDIRECT}") + #_echo "[Start IPMI Polling]: ${ret}" + #_echo "" + else + _echo "Unknown MODEL_NAME (${MODEL_NAME}), exit!!!" + exit 1 + fi + + # PSU Device + # Step1: Stop IPMI Polling + # Step2: Switch I2C MUX to PSU0 Channel and Check Status Registers + # Step3: Switch I2C MUX to PSU1 Channel and Check Status Registers + # Step4: Re-start IPMI polling + _echo "[PSU Device Status (BMC) ]" + if [ "${MODEL_NAME}" == "S9500-22XST" ]; then + ## Step1: Stop IPMI Polling + #ret=$(eval "ipmitool raw 0x3c 0x4 0x9 0x1 0x0 ${LOG_REDIRECT}") + #_echo "[Stop IPMI Polling ]: ${ret}" + #sleep 3 + + # Step2: Switch I2C MUX to PSU0 Channel and Check Status Registers + ret=$(eval "ipmitool raw 0x3c 0x12 0x2 0x33 0x1 0x6 0xe8 ${LOG_REDIRECT}") + ret=$(eval "i2cset -y -f 0 0x70 0x1 ${LOG_REDIRECT}") + status_word_psu0=$(eval "i2cget -y -f 0 0x58 0x79 w ${LOG_REDIRECT}" | head -n 1) + status_vout_psu0=$(eval "i2cget -y -f 0 0x58 0x7a ${LOG_REDIRECT}" | head -n 1) + status_iout_psu0=$(eval "i2cget -y -f 0 0x58 0x7b ${LOG_REDIRECT}" | head -n 1) + status_temperature_psu0=$(eval "i2cget -y -f 0 0x58 0x7d ${LOG_REDIRECT}" | head -n 1) + status_fan_psu0=$(eval "i2cget -y -f 0 0x58 0x81 ${LOG_REDIRECT}" | head -n 1) + _echo "[PSU0 Status Word ]: ${status_word_psu0}" + _echo "[PSU0 Status VOUT ]: ${status_vout_psu0}" + _echo "[PSU0 Status IOUT ]: ${status_iout_psu0}" + _echo "[PSU0 Status Tempe ]: ${status_temperature_psu0}" + _echo "[PSU0 Status FAN ]: ${status_fan_psu0}" + + # Step3: Switch I2C MUX to PSU1 Channel and Check Status Registers + ret=$(eval "i2cset -y -f 0 0x70 0x2 ${LOG_REDIRECT}") + status_word_psu1=$(eval "ipmitool i2c bus=2 0xb0 0x2 0x79 ${LOG_REDIRECT}" | head -n 1) + status_vout_psu1=$(eval "ipmitool i2c bus=2 0xb0 0x1 0x7a ${LOG_REDIRECT}" | head -n 1) + status_iout_psu1=$(eval "ipmitool i2c bus=2 0xb0 0x1 0x7b ${LOG_REDIRECT}" | head -n 1) + status_temperature_psu1=$(eval "ipmitool i2c bus=2 0xb0 0x1 0x7d ${LOG_REDIRECT}" | head -n 1) + status_fan_psu1=$(eval "ipmitool i2c bus=2 0xb0 0x1 0x81 ${LOG_REDIRECT}" | head -n 1) + _echo "[PSU1 Status Word ]: ${status_word_psu1}" + _echo "[PSU1 Status VOUT ]: ${status_vout_psu1}" + _echo "[PSU1 Status IOUT ]: ${status_iout_psu1}" + _echo "[PSU1 Status Tempe ]: ${status_temperature_psu1}" + _echo "[PSU1 Status FAN ]: ${status_fan_psu1}" + _echo "" + + ## Step4: Re-start IPMI polling + #ret=$(eval "ipmitool raw 0x3c 0x4 0x9 0x1 0x1 ${LOG_REDIRECT}") + #_echo "[Start IPMI Polling]: ${ret}" + #_echo "" + + ret=$(eval "ipmitool raw 0x3c 0x12 0x2 0x33 0x1 0x6 0x40 ${LOG_REDIRECT}") + else + _echo "Unknown MODEL_NAME (${MODEL_NAME}), exit!!!" + exit 1 + fi + + # Step4: Re-start IPMI polling + ret=$(eval "ipmitool raw 0x3c 0x07 0x0 ${LOG_REDIRECT}") + _echo "[Start IPMI Polling]: ${ret}" + _echo "" + + sleep 3 +} + +function _show_bmc_sensors { + _banner "Show BMC Sensors" + + ret=$(eval "ipmitool sensor ${LOG_REDIRECT}") + _echo "[Sensors]:" + _echo "${ret}" +} + +function _show_bmc_sel_raw_data { + _banner "Show BMC SEL Raw Data" + echo " Show BMC SEL Raw Data, please wait..." + + if [ "${LOG_FILE_ENABLE}" == "1" ]; then + _echo "[SEL RAW Data]:" + ret=$(eval "ipmitool sel save ${LOG_FOLDER_PATH}/sel_raw_data.log ${LOG_REDIRECT}") + _echo "The file is located at ${LOG_FOLDER_NAME}/sel_raw_data.log" + fi +} + +function _show_bmc_sel_elist { + _banner "Show BMC SEL" + + ret=$(eval "ipmitool sel elist ${LOG_REDIRECT}") + _echo "[SEL Record]:" + _echo "${ret}" +} + +function _show_bmc_sel_elist_detail { + _banner "Show BMC SEL Detail -- Abnormal Event" + + echo " Show BMC SEL details, please wait..." + sel_id_list="" + + readarray sel_array < <(ipmitool sel elist 2> /dev/null) + + for (( i=0; i<${#sel_array[@]}; i++ )) + do + if [[ "${sel_array[$i]}" == *"Undetermined"* ]] || + [[ "${sel_array[$i]}" == *"Bus"* ]] || + [[ "${sel_array[$i]}" == *"CATERR"* ]] || + [[ "${sel_array[$i]}" == *"OEM"* ]] ; then + _echo "${sel_array[$i]}" + sel_id=($(echo "${sel_array[$i]}" | awk -F" " '{print $1}')) + sel_id_list="${sel_id_list} 0x${sel_id}" + fi + done + + if [ ! -z "${sel_id_list}" ]; then + sel_detail=$(eval "ipmitool sel get ${sel_id_list} ${LOG_REDIRECT}") + else + sel_detail="" + fi + + _echo "[SEL Record ID]: ${sel_id_list}" + _echo "" + _echo "[SEL Detail ]:" + _echo "${sel_detail}" + + + #sel_rid_array=`ipmitool sel elist | grep -P -i '(Undetermined|Bus|CATERR|OEM)' | awk '{printf("0x%s ",$1)}'` + #sel_detail=`ipmitool sel get ${sel_rid_array}` + + #_echo "[SEL Record ID]: ${sel_rid_array}" + #_echo "" + #_echo "[SEL Detail ]:" + #_echo "${sel_detail}" + + #sel_elist_number=10 + #bmc_sel_id_array=($(ipmitool sel list | awk -F" " '{print $1}' | tail -n ${sel_elist_number})) + # + #for (( i=0; i<${#bmc_sel_id_array[@]}; i++ )) + #do + # _echo "" + # _echo "[Command]: ipmitool sel get 0x${bmc_sel_id_array[${i}]} " + # ret=`ipmitool sel get 0x${bmc_sel_id_array[${i}]}` + # _echo "${ret}" + #done +} + +function _show_dpll_register { + _banner "Show DPLL all register" + + if [ "${BSP_INIT_FLAG}" == "1" ]; then + dpll_bus_num=4 + else + i2cset -y 0 0x75 8 + if [ "$?" != "0" ]; then + _echo "0x75 does not exist, Exit!!" + exit 255; + fi + + dpll_bus_num=0 + fi + + _echo "i2cset -y ${dpll_bus_num} 0x53 0x7f 0" + i2cset -y ${dpll_bus_num} 0x53 0x7f 0 + _run_echo "i2cdump -y ${dpll_bus_num} 0x53 b" + + _echo "i2cset -y ${dpll_bus_num} 0x53 0x7f 1" + i2cset -y ${dpll_bus_num} 0x53 0x7f 1 + _run_echo "i2cdump -y ${dpll_bus_num} 0x53 b" + + _echo "i2cset -y ${dpll_bus_num} 0x53 0x7f 2" + i2cset -y ${dpll_bus_num} 0x53 0x7f 2 + _run_echo "i2cdump -y ${dpll_bus_num} 0x53 b" + + _echo "i2cset -y ${dpll_bus_num} 0x53 0x7f 3" + i2cset -y ${dpll_bus_num} 0x53 0x7f 3 + _run_echo "i2cdump -y ${dpll_bus_num} 0x53 b" + + _echo "i2cset -y ${dpll_bus_num} 0x53 0x7f 4" + i2cset -y ${dpll_bus_num} 0x53 0x7f 4 + _run_echo "i2cdump -y ${dpll_bus_num} 0x53 b" + + _echo "i2cset -y ${dpll_bus_num} 0x53 0x7f 5" + i2cset -y ${dpll_bus_num} 0x53 0x7f 5 + _run_echo "i2cdump -y ${dpll_bus_num} 0x53 b" + + _echo "i2cset -y ${dpll_bus_num} 0x53 0x7f 6" + i2cset -y ${dpll_bus_num} 0x53 0x7f 6 + _run_echo "i2cdump -y ${dpll_bus_num} 0x53 b" + + _echo "i2cset -y ${dpll_bus_num} 0x53 0x7f 7" + i2cset -y ${dpll_bus_num} 0x53 0x7f 7 + _run_echo "i2cdump -y ${dpll_bus_num} 0x53 b" + + if [ "${BSP_INIT_FLAG}" != "1" ]; then + i2cset -y 0 0x75 0 + fi +} + +function _show_dmesg { + _banner "Show Dmesg" + + ret=$(eval "dmesg ${LOG_REDIRECT}") + _echo "${ret}" +} + +function _additional_log_collection { + _banner "Additional Log Collection" + + if [ -z "${LOG_FOLDER_PATH}" ] || [ ! -d "${LOG_FOLDER_PATH}" ]; then + _echo "LOG_FOLDER_PATH (${LOG_FOLDER_PATH}) not found!!!" + _echo "do nothing..." + else + #_echo "copy /var/log/syslog* to ${LOG_FOLDER_PATH}" + #cp /var/log/syslog* "${LOG_FOLDER_PATH}" + + if [ -f "/var/log/kern.log" ]; then + _echo "copy /var/log/kern.log* to ${LOG_FOLDER_PATH}" + cp /var/log/kern.log* "${LOG_FOLDER_PATH}" + fi + + if [ -f "/var/log/dmesg" ]; then + _echo "copy /var/log/dmesg* to ${LOG_FOLDER_PATH}" + cp /var/log/dmesg* "${LOG_FOLDER_PATH}" + fi + fi +} + +function _compression { + _banner "Compression" + + if [ ! -z "${LOG_FOLDER_PATH}" ] && [ -d "${LOG_FOLDER_PATH}" ]; then + cd "${LOG_FOLDER_ROOT}" + tar -zcf "${LOG_FOLDER_NAME}".tgz "${LOG_FOLDER_NAME}" + + echo " The tarball is ready at ${LOG_FOLDER_ROOT}/${LOG_FOLDER_NAME}.tgz" + _echo " The tarball is ready at ${LOG_FOLDER_ROOT}/${LOG_FOLDER_NAME}.tgz" + fi +} + +function _main { + echo "The script will take a few minutes, please wait..." + _check_env + _pkg_version + _show_board_info + _show_version + _show_i2c_tree + _show_i2c_device_info + _show_sys_devices + _show_cpu_eeprom + _show_psu_status + _show_rov + _show_port_status + _show_cpu_temperature + _show_cpld_cpudebug_register + _show_system_info + _show_memory_correctable_error_count + _show_usb_info + _show_scsi_device_info + _show_onie_upgrade_info + _show_disk_info + _show_lspci + _show_lspci_detail + _show_proc_interrupt + _show_bios_info + _show_bmc_info + _show_bmc_device_status + _show_bmc_sensors + _show_bmc_sel_raw_data + _show_bmc_sel_elist + _show_bmc_sel_elist_detail + _show_dpll_register + _show_dmesg + _additional_log_collection + _compression + + echo "# done..." +} + +_main + diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/platform-config/r0/src/lib/x86-64-ufispace-s9500-22xst-r0.yml b/packages/platforms/ufispace/x86-64/s9500-22xst/platform-config/r0/src/lib/x86-64-ufispace-s9500-22xst-r0.yml new file mode 100755 index 0000000000..1fc1081d34 --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/platform-config/r0/src/lib/x86-64-ufispace-s9500-22xst-r0.yml @@ -0,0 +1,30 @@ +--- + +###################################################################### +# +# platform-config for x86-64-ufispace-s9500-22xst +# +###################################################################### + +x86-64-ufispace-s9500-22xst-r0: + + grub: + + serial: >- + --port=0x3f8 + --speed=115200 + --word=8 + --parity=no + --stop=1 + + kernel: + <<: *kernel-4-19 + + args: >- + console=ttyS0,115200n8 + + ##network + ## interfaces: + ## ma1: + ## name: ~ + ## syspath: pci0000:00/0000:00:03.0 diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/platform-config/r0/src/python/x86_64_ufispace_s9500_22xst_r0/__init__.py b/packages/platforms/ufispace/x86-64/s9500-22xst/platform-config/r0/src/python/x86_64_ufispace_s9500_22xst_r0/__init__.py new file mode 100755 index 0000000000..db30205ae0 --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/platform-config/r0/src/python/x86_64_ufispace_s9500_22xst_r0/__init__.py @@ -0,0 +1,339 @@ +from onl.platform.base import * +from onl.platform.ufispace import * +from struct import * +from ctypes import c_int, sizeof +import os +import sys +import subprocess +import time +import fcntl + +def msg(s, fatal=False): + sys.stderr.write(s) + sys.stderr.flush() + if fatal: + sys.exit(1) + +class IPMI_Ioctl(object): + _IONONE = 0 + _IOWRITE = 1 + _IOREAD = 2 + + IPMI_MAINTENANCE_MODE_AUTO = 0 + IPMI_MAINTENANCE_MODE_OFF = 1 + IPMI_MAINTENANCE_MODE_ON = 2 + + IPMICTL_GET_MAINTENANCE_MODE_CMD = _IOREAD << 30 | sizeof(c_int) << 16 | \ + ord('i') << 8 | 30 # from ipmi.h + IPMICTL_SET_MAINTENANCE_MODE_CMD = _IOWRITE << 30 | sizeof(c_int) << 16 | \ + ord('i') << 8 | 31 # from ipmi.h + + def __init__(self): + self.ipmidev = None + devnodes=["/dev/ipmi0", "/dev/ipmi/0", "/dev/ipmidev/0"] + for dev in devnodes: + try: + self.ipmidev = open(dev, 'rw') + break + except Exception as e: + print("open file {} failed, error: {}".format(dev, e)) + + def __del__(self): + if self.ipmidev is not None: + self.ipmidev.close() + + def get_ipmi_maintenance_mode(self): + input_buffer=pack('i',0) + out_buffer=fcntl.ioctl(self.ipmidev, self.IPMICTL_GET_MAINTENANCE_MODE_CMD, input_buffer) + maintanence_mode=unpack('i',out_buffer)[0] + + return maintanence_mode + + def set_ipmi_maintenance_mode(self, mode): + fcntl.ioctl(self.ipmidev, self.IPMICTL_SET_MAINTENANCE_MODE_CMD, c_int(mode)) + +class OnlPlatform_x86_64_ufispace_s9500_22xst_r0(OnlPlatformUfiSpace): + PLATFORM='x86-64-ufispace-s9500-22xst-r0' + MODEL="S9500-22XST" + SYS_OBJECT_ID=".9500.22" + PORT_COUNT=22 + PORT_CONFIG="2x100 + 8x25 + 8x10 + 4x1" + + I2C_ADDR_TPS53667 = 0x61 + TPS53667_ROV_ADDR = 0x21 + ROV_List = ['N/A' , '1.00' , '0.95' , 'N/A' , '1.04'] + TPS53667_voltage = [ + {"rov": "1.00", "vol": 0x0097}, + {"rov": "0.95", "vol": 0x008D}, + {"rov": "1.04", "vol": 0x009F} + ] + + def check_bmc_enable(self): + return 1 + + def baseconfig(self): + + bmc_enable = self.check_bmc_enable() + msg("bmc enable : %r\n" % (True if bmc_enable else False)) + + # record the result for onlp + os.system("echo %d > /etc/onl/bmc_en" % bmc_enable) + + ########### initialize I2C bus 0 ########### + msg("****** Start S9500-22XST platform initializing ... ******\n") + # init PCA9546, PCA9548 + msg("Insert I2C Mux\n") + self.new_i2c_devices( + [ + ('pca9546', 0x75, 0), + ('pca9546', 0x76, 0), + ('pca9548', 0x72, 8), + ('pca9548', 0x73, 8), + ('pca9548', 0x74, 8), + ('pca9546', 0x70, 8), + ] + ) + + # Config MUX as MUX_IDLE_DISCONNECT mode + os.system("ls /sys/devices/pci0000:00/0000:00:1f.3/i2c-0/0-0075/idle_state > /dev/null 2>&1 &&" + "echo -2 > /sys/devices/pci0000:00/0000:00:1f.3/i2c-0/0-0075/idle_state") + os.system("ls /sys/devices/pci0000:00/0000:00:1f.3/i2c-0/0-0076/idle_state > /dev/null 2>&1 &&" + "echo -2 > /sys/devices/pci0000:00/0000:00:1f.3/i2c-0/0-0076/idle_state") + os.system("ls /sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-8/8-0070/idle_state > /dev/null 2>&1 &&" + "echo -2 > /sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-8/8-0070/idle_state") + os.system("ls /sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-8/8-0072/idle_state > /dev/null 2>&1 &&" + "echo -2 > /sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-8/8-0072/idle_state") + os.system("ls /sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-8/8-0073/idle_state > /dev/null 2>&1 &&" + "echo -2 > /sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-8/8-0073/idle_state") + os.system("ls /sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-8/8-0074/idle_state > /dev/null 2>&1 &&" + "echo -2 > /sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-8/8-0074/idle_state") + + self.insmod("x86-64-ufispace-eeprom-mb") + self.insmod("optoe") + + # init SYS EEPROM devices + msg("Insert EEPROM\n") + self.new_i2c_devices( + [ + # on cpu board + ('mb_eeprom', 0x57, 0), + ] + ) + + # init SFP+ EEPROM + msg("Insert SFP+ EEPROM\n") + for port in range(9, 17): + self.new_i2c_device('optoe2', 0x50, port) + subprocess.call("echo {} > /sys/bus/i2c/devices/{}-0050/port_name".format(port-5, port), shell=True) + + # init SFP28 EEPROM + msg("Insert SFP28 EEPROM\n") + for port in range(21, 29): + self.new_i2c_device('optoe2', 0x50, port) + subprocess.call("echo {} > /sys/bus/i2c/devices/{}-0050/port_name".format(port-9, port), shell=True) + + # init QSFP28 EEPROM + msg("Insert QSFP EEPROM\n") + for port in range(35, 37): + self.new_i2c_device('optoe1', 0x50, port) + #self.new_i2c_device('sff8436', 0x50, port) + subprocess.call("echo {} > /sys/bus/i2c/devices/{}-0050/port_name".format(56-port, port), shell=True) + + # init Temperature + msg("Insert CPU TMP75\n") + self.new_i2c_devices( + [ + # CPU Board Temp + ('tmp75', 0x4F, 0), + ] + ) + + # init GPIO sysfs + msg("Insert IOExp\n") + #9539_CPU_STATUS + self.new_i2c_device('pca9539', 0x77, 0) + #9535_SFP+_TX_DIS_1 + self.new_i2c_device('pca9535', 0x22, 5) + #9535_SFP+_TX_DIS_2 + self.new_i2c_device('pca9535', 0x24, 5) + #9535_QSFP28 + self.new_i2c_device('pca9535', 0x21, 5) + #9535_SFP+_TX_FLT_1 + self.new_i2c_device('pca9535', 0x26, 6) + #9535_SFP+_TX_FLT_2 + self.new_i2c_device('pca9535', 0x27, 6) + #9535_SFP+_RATE_SEL_1 + self.new_i2c_device('pca9535', 0x25, 6) + #9535_SFP+_RATE_SEL_2 + self.new_i2c_device('pca9535', 0x23, 6) + #9535_SFP+_MOD_ABS_1 + self.new_i2c_device('pca9535', 0x20, 7) + #9535_SFP+_MOD_ABS_2 + self.new_i2c_device('pca9535', 0x22, 7) + #9535_SFP+_RX_LOS_1 + self.new_i2c_device('pca9535', 0x21, 7) + #9535_SFP+_RX_LOS_2 + self.new_i2c_device('pca9535', 0x24, 7) + #9535_BOARD_ID + self.new_i2c_device('pca9539', 0x20, 3) + + # export GPIO + msg("Export GPIO\n") + for i in reversed(range(304, 512)): + os.system("echo {} > /sys/class/gpio/export".format(i)) + + # init GPIO direction + msg("Config GPIO\n") + # 9539_CPU_STATUS + for i in range(496, 512): + os.system("echo in > /sys/class/gpio/gpio{}/direction".format(i)) + + # init GPIO direction + # 9535_SFP+_TX_DIS_1 + for i in range(480, 496): + os.system("echo out > /sys/class/gpio/gpio{}/direction".format(i)) + # init GPIO value + # 9535_SFP+_TX_DIS_1 + for i in range(480, 496): + os.system("echo 0 > /sys/class/gpio/gpio{}/value".format(i)) + + # init GPIO direction + # 9535_SFP+_TX_DIS_2 + for i in range(464, 480): + os.system("echo out > /sys/class/gpio/gpio{}/direction".format(i)) + # init GPIO value + # 9535_SFP+_TX_DIS_2 + for i in range(464, 480): + os.system("echo 0 > /sys/class/gpio/gpio{}/value".format(i)) + + # init GPIO direction + # 9535_QSFP28 + os.system("echo in > /sys/class/gpio/gpio463/direction") + os.system("echo in > /sys/class/gpio/gpio462/direction") + os.system("echo out > /sys/class/gpio/gpio461/direction") + os.system("echo out > /sys/class/gpio/gpio460/direction") + os.system("echo in > /sys/class/gpio/gpio459/direction") + os.system("echo in > /sys/class/gpio/gpio458/direction") + os.system("echo out > /sys/class/gpio/gpio457/direction") + os.system("echo out > /sys/class/gpio/gpio456/direction") + os.system("echo in > /sys/class/gpio/gpio455/direction") + os.system("echo in > /sys/class/gpio/gpio454/direction") + os.system("echo in > /sys/class/gpio/gpio453/direction") + os.system("echo in > /sys/class/gpio/gpio452/direction") + os.system("echo in > /sys/class/gpio/gpio451/direction") + os.system("echo in > /sys/class/gpio/gpio450/direction") + os.system("echo in > /sys/class/gpio/gpio449/direction") + os.system("echo in > /sys/class/gpio/gpio448/direction") + # init GPIO value + # 9535_QSFP28 + os.system("echo 1 > /sys/class/gpio/gpio461/value") + os.system("echo 1 > /sys/class/gpio/gpio460/value") + os.system("echo 0 > /sys/class/gpio/gpio457/value") + os.system("echo 0 > /sys/class/gpio/gpio456/value") + + # init GPIO direction + # 9535_SFP+_TX_FLT_1, 9535_SFP+_TX_FLT_2 + for i in range(416, 448): + os.system("echo in > /sys/class/gpio/gpio{}/direction".format(i)) + + # init GPIO direction + # 9535_SFP+_RATE_SEL_1 + for i in range(400, 416): + os.system("echo out > /sys/class/gpio/gpio{}/direction".format(i)) + # init GPIO value + # 9535_SFP+_RATE_SEL_1 + for i in range(400, 416): + os.system("echo 1 > /sys/class/gpio/gpio{}/value".format(i)) + + # init GPIO direction + # 9535_SFP+_RATE_SEL_2 + os.system("echo out > /sys/class/gpio/gpio399/direction") + os.system("echo out > /sys/class/gpio/gpio398/direction") + os.system("echo out > /sys/class/gpio/gpio397/direction") + os.system("echo out > /sys/class/gpio/gpio396/direction") + os.system("echo in > /sys/class/gpio/gpio395/direction") + os.system("echo in > /sys/class/gpio/gpio394/direction") + os.system("echo in > /sys/class/gpio/gpio393/direction") + os.system("echo in > /sys/class/gpio/gpio392/direction") + os.system("echo out > /sys/class/gpio/gpio391/direction") + os.system("echo out > /sys/class/gpio/gpio390/direction") + os.system("echo out > /sys/class/gpio/gpio389/direction") + os.system("echo out > /sys/class/gpio/gpio388/direction") + os.system("echo in > /sys/class/gpio/gpio387/direction") + os.system("echo in > /sys/class/gpio/gpio386/direction") + os.system("echo in > /sys/class/gpio/gpio385/direction") + os.system("echo in > /sys/class/gpio/gpio384/direction") + # init GPIO value + # 9535_SFP+_RATE_SEL_2 + os.system("echo 1 > /sys/class/gpio/gpio399/value") + os.system("echo 1 > /sys/class/gpio/gpio398/value") + os.system("echo 1 > /sys/class/gpio/gpio397/value") + os.system("echo 1 > /sys/class/gpio/gpio396/value") + os.system("echo 1 > /sys/class/gpio/gpio391/value") + os.system("echo 1 > /sys/class/gpio/gpio390/value") + os.system("echo 1 > /sys/class/gpio/gpio389/value") + os.system("echo 1 > /sys/class/gpio/gpio388/value") + + # init GPIO direction + # 9535_SFP+_MOD_ABS_1, 9535_SFP+_MOD_ABS_2, 9535_SFP+_RX_LOS_1, + # 9535_SFP+_RX_LOS_2, 9535_BOARD_ID + for i in range(304, 384): + os.system("echo in > /sys/class/gpio/gpio{}/direction".format(i)) + + # get mac rov config + msg("Config MAC ROV\n") + data_4 = "" + data_2 = "" + data_1 = "" + if (os.path.exists("/sys/class/gpio/gpio306")): + with open("/sys/class/gpio/gpio306/value") as f: + data_4 = f.read() + if (os.path.exists("/sys/class/gpio/gpio305")): + with open("/sys/class/gpio/gpio305/value") as f: + data_2 = f.read() + if (os.path.exists("/sys/class/gpio/gpio304")): + with open("/sys/class/gpio/gpio304/value") as f: + data_1 = f.read() + if data_4 != "" and data_2 != "" and data_1 != "": + data = int(data_4)*4 + int(data_2)*2 + int(data_1)*1 + + # set mac rov + for element in self.TPS53667_voltage: + if element["rov"] == self.ROV_List[data]: + msg("ROV: {}\n".format(element["vol"])) + os.system("i2cset -y 3 {} {} {} w".format(self.I2C_ADDR_TPS53667, self.TPS53667_ROV_ADDR, element["vol"])) + + # clear port interrupts + for gpio in range(416, 450): + with open("/sys/class/gpio/gpio{}/value".format(gpio)) as f: + f.read() + for gpio in range(320, 384): + with open("/sys/class/gpio/gpio{}/value".format(gpio)) as f: + f.read() + + self.enable_ipmi_maintenance_mode() + + msg("Platform hardware initialization done, set SYS_LED as stable green.\n") + output = subprocess.check_output('iorw -r -b 0x700 -o 0x18 -l 1 -F', shell=True) + val = output.splitlines()[0].rsplit(' ', 1)[-1] + new_val = hex(int(val, 16) | 0x80) + os.system("iorw -w -b 0x700 -o 0x18 -l 1 -v {} -F".format(new_val)) + output = subprocess.check_output('iorw -r -b 0x700 -o 0x1a -l 1 -F', shell=True) + val = output.splitlines()[0].rsplit(' ', 1)[-1] + new_val = hex(int(val, 16) & 0xf7) + os.system("iorw -w -b 0x700 -o 0x1a -l 1 -v {} -F".format(new_val)) + + msg("****** End S9500-22XST platform initializing ... ******\n") + + return True + + def enable_ipmi_maintenance_mode(self): + ipmi_ioctl = IPMI_Ioctl() + + mode=ipmi_ioctl.get_ipmi_maintenance_mode() + msg("Current IPMI_MAINTENANCE_MODE=%d\n" % (mode) ) + + ipmi_ioctl.set_ipmi_maintenance_mode(IPMI_Ioctl.IPMI_MAINTENANCE_MODE_ON) + + mode=ipmi_ioctl.get_ipmi_maintenance_mode() + msg("After IPMI_IOCTL IPMI_MAINTENANCE_MODE=%d\n" % (mode) ) diff --git a/packages/platforms/ufispace/x86-64/s9500-22xst/platform-config/r0/src/python/x86_64_ufispace_s9500_22xst_r0/__init__.py.bak b/packages/platforms/ufispace/x86-64/s9500-22xst/platform-config/r0/src/python/x86_64_ufispace_s9500_22xst_r0/__init__.py.bak new file mode 100755 index 0000000000..9abe622833 --- /dev/null +++ b/packages/platforms/ufispace/x86-64/s9500-22xst/platform-config/r0/src/python/x86_64_ufispace_s9500_22xst_r0/__init__.py.bak @@ -0,0 +1,317 @@ +from onl.platform.base import * +from onl.platform.ufispace import * +from struct import * +from ctypes import c_int, sizeof +import os +import sys +import subprocess +import time +import fcntl + +def msg(s, fatal=False): + sys.stderr.write(s) + sys.stderr.flush() + if fatal: + sys.exit(1) + +class IPMI_Ioctl(object): + _IONONE = 0 + _IOWRITE = 1 + _IOREAD = 2 + + IPMI_MAINTENANCE_MODE_AUTO = 0 + IPMI_MAINTENANCE_MODE_OFF = 1 + IPMI_MAINTENANCE_MODE_ON = 2 + + IPMICTL_GET_MAINTENANCE_MODE_CMD = _IOREAD << 30 | sizeof(c_int) << 16 | \ + ord('i') << 8 | 30 # from ipmi.h + IPMICTL_SET_MAINTENANCE_MODE_CMD = _IOWRITE << 30 | sizeof(c_int) << 16 | \ + ord('i') << 8 | 31 # from ipmi.h + + def __init__(self): + self.ipmidev = None + devnodes=["/dev/ipmi0", "/dev/ipmi/0", "/dev/ipmidev/0"] + for dev in devnodes: + try: + self.ipmidev = open(dev, 'rw') + break + except Exception as e: + print("open file {} failed, error: {}".format(dev, e)) + + def __del__(self): + if self.ipmidev is not None: + self.ipmidev.close() + + def get_ipmi_maintenance_mode(self): + input_buffer=pack('i',0) + out_buffer=fcntl.ioctl(self.ipmidev, self.IPMICTL_GET_MAINTENANCE_MODE_CMD, input_buffer) + maintanence_mode=unpack('i',out_buffer)[0] + + return maintanence_mode + + def set_ipmi_maintenance_mode(self, mode): + fcntl.ioctl(self.ipmidev, self.IPMICTL_SET_MAINTENANCE_MODE_CMD, c_int(mode)) + +class OnlPlatform_x86_64_ufispace_s9500_22xst_r0(OnlPlatformUfiSpace): + PLATFORM='x86-64-ufispace-s9500-22xst-r0' + MODEL="S9500-22XST" + SYS_OBJECT_ID=".9500.22" + PORT_COUNT=22 + PORT_CONFIG="2x100 + 8x25 + 8x10 + 4x1" + + I2C_ADDR_TPS53667 = 0x61 + TPS53667_ROV_ADDR = 0x21 + ROV_List = ['N/A' , '1.00' , '0.95' , 'N/A' , '1.04'] + TPS53667_voltage = [ + {"rov": "1.00", "vol": 0x0097}, + {"rov": "0.95", "vol": 0x008D}, + {"rov": "1.04", "vol": 0x009F} + ] + + def check_bmc_enable(self): + return 1 + + def baseconfig(self): + + bmc_enable = self.check_bmc_enable() + msg("bmc enable : %r\n" % (True if bmc_enable else False)) + + # record the result for onlp + os.system("echo %d > /etc/onl/bmc_en" % bmc_enable) + + ########### initialize I2C bus 0 ########### + msg("****** Start S9500-22XST platform initializing ... ******\n") + # init PCA9546, PCA9548 + msg("Insert I2C Mux\n") + self.new_i2c_devices( + [ + ('pca9546', 0x75, 0), + ('pca9546', 0x76, 0), + ('pca9548', 0x72, 8), + ('pca9548', 0x73, 8), + ('pca9548', 0x74, 8), + ('pca9546', 0x70, 8), + ] + ) + + self.insmod("eeprom_mb") + self.insmod("optoe") + + # init SYS EEPROM devices + msg("Insert EEPROM\n") + self.new_i2c_devices( + [ + # on cpu board + ('mb_eeprom', 0x57, 0), + ] + ) + + # init SFP+ EEPROM + msg("Insert SFP EEPROM\n") + for port in range(9, 33): + self.new_i2c_device('optoe2', 0x50, port) + + # init QSFP28 EEPROM + msg("Insert QSFP EEPROM\n") + for port in range(35, 37): + self.new_i2c_device('optoe1', 0x50, port) + #self.new_i2c_device('sff8436', 0x50, port) + + # init Temperature + msg("Insert CPU TMP75\n") + self.new_i2c_devices( + [ + # CPU Board Temp + ('tmp75', 0x4F, 0), + ] + ) + + # init GPIO sysfs + msg("Insert IOExp\n") + #9539_CPU_STATUS + self.new_i2c_device('pca9539', 0x77, 0) + #9535_SFP+_TX_DIS_1 + self.new_i2c_device('pca9535', 0x22, 5) + #9535_SFP+_TX_DIS_2 + self.new_i2c_device('pca9535', 0x24, 5) + #9535_QSFP28 + self.new_i2c_device('pca9535', 0x21, 5) + #9535_SFP+_TX_FLT_1 + self.new_i2c_device('pca9535', 0x26, 6) + #9535_SFP+_TX_FLT_2 + self.new_i2c_device('pca9535', 0x27, 6) + #9535_SFP+_RATE_SEL_1 + self.new_i2c_device('pca9535', 0x25, 6) + #9535_SFP+_RATE_SEL_2 + self.new_i2c_device('pca9535', 0x23, 6) + #9535_SFP+_MOD_ABS_1 + self.new_i2c_device('pca9535', 0x20, 7) + #9535_SFP+_MOD_ABS_2 + self.new_i2c_device('pca9535', 0x22, 7) + #9535_SFP+_RX_LOS_1 + self.new_i2c_device('pca9535', 0x21, 7) + #9535_SFP+_RX_LOS_2 + self.new_i2c_device('pca9535', 0x24, 7) + #9535_BOARD_ID + self.new_i2c_device('pca9539', 0x20, 3) + + # export GPIO + msg("Export GPIO\n") + for i in reversed(range(304, 512)): + os.system("echo {} > /sys/class/gpio/export".format(i)) + + # init GPIO direction + msg("Config GPIO\n") + # 9539_CPU_STATUS + for i in range(496, 512): + os.system("echo in > /sys/class/gpio/gpio{}/direction".format(i)) + + # init GPIO direction + # 9535_SFP+_TX_DIS_1 + for i in range(480, 496): + os.system("echo out > /sys/class/gpio/gpio{}/direction".format(i)) + # init GPIO value + # 9535_SFP+_TX_DIS_1 + for i in range(480, 496): + os.system("echo 0 > /sys/class/gpio/gpio{}/value".format(i)) + + # init GPIO direction + # 9535_SFP+_TX_DIS_2 + for i in range(464, 480): + os.system("echo out > /sys/class/gpio/gpio{}/direction".format(i)) + # init GPIO value + # 9535_SFP+_TX_DIS_2 + for i in range(464, 480): + os.system("echo 0 > /sys/class/gpio/gpio{}/value".format(i)) + + # init GPIO direction + # 9535_QSFP28 + os.system("echo in > /sys/class/gpio/gpio463/direction") + os.system("echo in > /sys/class/gpio/gpio462/direction") + os.system("echo out > /sys/class/gpio/gpio461/direction") + os.system("echo out > /sys/class/gpio/gpio460/direction") + os.system("echo in > /sys/class/gpio/gpio459/direction") + os.system("echo in > /sys/class/gpio/gpio458/direction") + os.system("echo out > /sys/class/gpio/gpio457/direction") + os.system("echo out > /sys/class/gpio/gpio456/direction") + os.system("echo in > /sys/class/gpio/gpio455/direction") + os.system("echo in > /sys/class/gpio/gpio454/direction") + os.system("echo in > /sys/class/gpio/gpio453/direction") + os.system("echo in > /sys/class/gpio/gpio452/direction") + os.system("echo in > /sys/class/gpio/gpio451/direction") + os.system("echo in > /sys/class/gpio/gpio450/direction") + os.system("echo in > /sys/class/gpio/gpio449/direction") + os.system("echo in > /sys/class/gpio/gpio448/direction") + # init GPIO value + # 9535_QSFP28 + os.system("echo 1 > /sys/class/gpio/gpio461/value") + os.system("echo 1 > /sys/class/gpio/gpio460/value") + os.system("echo 0 > /sys/class/gpio/gpio457/value") + os.system("echo 0 > /sys/class/gpio/gpio456/value") + + # init GPIO direction + # 9535_SFP+_TX_FLT_1, 9535_SFP+_TX_FLT_2 + for i in range(416, 448): + os.system("echo in > /sys/class/gpio/gpio{}/direction".format(i)) + + # init GPIO direction + # 9535_SFP+_RATE_SEL_1 + for i in range(400, 416): + os.system("echo out > /sys/class/gpio/gpio{}/direction".format(i)) + # init GPIO value + # 9535_SFP+_RATE_SEL_1 + for i in range(400, 416): + os.system("echo 1 > /sys/class/gpio/gpio{}/value".format(i)) + + # init GPIO direction + # 9535_SFP+_RATE_SEL_2 + os.system("echo out > /sys/class/gpio/gpio399/direction") + os.system("echo out > /sys/class/gpio/gpio398/direction") + os.system("echo out > /sys/class/gpio/gpio397/direction") + os.system("echo out > /sys/class/gpio/gpio396/direction") + os.system("echo in > /sys/class/gpio/gpio395/direction") + os.system("echo in > /sys/class/gpio/gpio394/direction") + os.system("echo in > /sys/class/gpio/gpio393/direction") + os.system("echo in > /sys/class/gpio/gpio392/direction") + os.system("echo out > /sys/class/gpio/gpio391/direction") + os.system("echo out > /sys/class/gpio/gpio390/direction") + os.system("echo out > /sys/class/gpio/gpio389/direction") + os.system("echo out > /sys/class/gpio/gpio388/direction") + os.system("echo in > /sys/class/gpio/gpio387/direction") + os.system("echo in > /sys/class/gpio/gpio386/direction") + os.system("echo in > /sys/class/gpio/gpio385/direction") + os.system("echo in > /sys/class/gpio/gpio384/direction") + # init GPIO value + # 9535_SFP+_RATE_SEL_2 + os.system("echo 1 > /sys/class/gpio/gpio399/value") + os.system("echo 1 > /sys/class/gpio/gpio398/value") + os.system("echo 1 > /sys/class/gpio/gpio397/value") + os.system("echo 1 > /sys/class/gpio/gpio396/value") + os.system("echo 1 > /sys/class/gpio/gpio391/value") + os.system("echo 1 > /sys/class/gpio/gpio390/value") + os.system("echo 1 > /sys/class/gpio/gpio389/value") + os.system("echo 1 > /sys/class/gpio/gpio388/value") + + # init GPIO direction + # 9535_SFP+_MOD_ABS_1, 9535_SFP+_MOD_ABS_2, 9535_SFP+_RX_LOS_1, + # 9535_SFP+_RX_LOS_2, 9535_BOARD_ID + for i in range(304, 384): + os.system("echo in > /sys/class/gpio/gpio{}/direction".format(i)) + + # get mac rov config + msg("Config MAC ROV\n") + data_4 = "" + data_2 = "" + data_1 = "" + if (os.path.exists("/sys/class/gpio/gpio306")): + with open("/sys/class/gpio/gpio306/value") as f: + data_4 = f.read() + if (os.path.exists("/sys/class/gpio/gpio305")): + with open("/sys/class/gpio/gpio305/value") as f: + data_2 = f.read() + if (os.path.exists("/sys/class/gpio/gpio304")): + with open("/sys/class/gpio/gpio304/value") as f: + data_1 = f.read() + if data_4 != "" and data_2 != "" and data_1 != "": + data = int(data_4)*4 + int(data_2)*2 + int(data_1)*1 + + # set mac rov + for element in self.TPS53667_voltage: + if element["rov"] == self.ROV_List[data]: + msg("ROV: {}\n".format(element["vol"])) + os.system("i2cset -y 3 {} {} {} w".format(self.I2C_ADDR_TPS53667, self.TPS53667_ROV_ADDR, element["vol"])) + + # clear port interrupts + for gpio in range(416, 450): + with open("/sys/class/gpio/gpio{}/value".format(gpio)) as f: + f.read() + for gpio in range(320, 384): + with open("/sys/class/gpio/gpio{}/value".format(gpio)) as f: + f.read() + + self.enable_ipmi_maintenance_mode() + + msg("Platform hardware initialization done, set SYS_LED as stable green.\n") + output = subprocess.check_output('iorw -r -b 0x700 -o 0x18 -l 1 -F', shell=True) + val = output.splitlines()[0].rsplit(' ', 1)[-1] + new_val = hex(int(val, 16) | 0x80) + os.system("iorw -w -b 0x700 -o 0x18 -l 1 -v {} -F".format(new_val)) + output = subprocess.check_output('iorw -r -b 0x700 -o 0x1a -l 1 -F', shell=True) + val = output.splitlines()[0].rsplit(' ', 1)[-1] + new_val = hex(int(val, 16) & 0xf7) + os.system("iorw -w -b 0x700 -o 0x1a -l 1 -v {} -F".format(new_val)) + + msg("****** End S9500-22XST platform initializing ... ******\n") + + return True + + def enable_ipmi_maintenance_mode(self): + ipmi_ioctl = IPMI_Ioctl() + + mode=ipmi_ioctl.get_ipmi_maintenance_mode() + msg("Current IPMI_MAINTENANCE_MODE=%d\n" % (mode) ) + + ipmi_ioctl.set_ipmi_maintenance_mode(IPMI_Ioctl.IPMI_MAINTENANCE_MODE_ON) + + mode=ipmi_ioctl.get_ipmi_maintenance_mode() + msg("After IPMI_IOCTL IPMI_MAINTENANCE_MODE=%d\n" % (mode) )