diff --git a/packages/platforms/lenovo/Makefile b/packages/platforms/lenovo/Makefile
new file mode 100644
index 00000000..003238cf
--- /dev/null
+++ b/packages/platforms/lenovo/Makefile
@@ -0,0 +1 @@
+include $(ONL)/make/pkg.mk
\ No newline at end of file
diff --git a/packages/platforms/lenovo/vendor-config/Makefile b/packages/platforms/lenovo/vendor-config/Makefile
new file mode 100644
index 00000000..003238cf
--- /dev/null
+++ b/packages/platforms/lenovo/vendor-config/Makefile
@@ -0,0 +1 @@
+include $(ONL)/make/pkg.mk
\ No newline at end of file
diff --git a/packages/platforms/lenovo/vendor-config/PKG.yml b/packages/platforms/lenovo/vendor-config/PKG.yml
new file mode 100644
index 00000000..4986804b
--- /dev/null
+++ b/packages/platforms/lenovo/vendor-config/PKG.yml
@@ -0,0 +1 @@
+!include $ONL_TEMPLATES/platform-config-vendor.yml VENDOR=lenovo Vendor=Lenovo
diff --git a/packages/platforms/lenovo/vendor-config/src/python/lenovo/__init__.py b/packages/platforms/lenovo/vendor-config/src/python/lenovo/__init__.py
new file mode 100644
index 00000000..722e5eff
--- /dev/null
+++ b/packages/platforms/lenovo/vendor-config/src/python/lenovo/__init__.py
@@ -0,0 +1,7 @@
+#!/usr/bin/python
+
+from onl.platform.base import *
+
+class OnlPlatformLenovo(OnlPlatformBase):
+ MANUFACTURER='Lenovo Enterprise Business Group'
+ PRIVATE_ENTERPRISE_NUMBER=19046
diff --git a/packages/platforms/lenovo/x86-64/Makefile b/packages/platforms/lenovo/x86-64/Makefile
new file mode 100644
index 00000000..003238cf
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/Makefile
@@ -0,0 +1 @@
+include $(ONL)/make/pkg.mk
\ No newline at end of file
diff --git a/packages/platforms/lenovo/x86-64/modules/Makefile b/packages/platforms/lenovo/x86-64/modules/Makefile
new file mode 100644
index 00000000..003238cf
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/modules/Makefile
@@ -0,0 +1 @@
+include $(ONL)/make/pkg.mk
\ No newline at end of file
diff --git a/packages/platforms/lenovo/x86-64/modules/PKG.yml b/packages/platforms/lenovo/x86-64/modules/PKG.yml
new file mode 100644
index 00000000..25ab6492
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/modules/PKG.yml
@@ -0,0 +1 @@
+!include $ONL_TEMPLATES/no-arch-vendor-modules.yml ARCH=amd64 VENDOR=lenovo
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/Makefile b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/Makefile
new file mode 100644
index 00000000..003238cf
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/Makefile
@@ -0,0 +1 @@
+include $(ONL)/make/pkg.mk
\ No newline at end of file
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/modules/Makefile b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/modules/Makefile
new file mode 100644
index 00000000..003238cf
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/modules/Makefile
@@ -0,0 +1 @@
+include $(ONL)/make/pkg.mk
\ No newline at end of file
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/modules/PKG.yml b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/modules/PKG.yml
new file mode 100644
index 00000000..feecc056
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/modules/PKG.yml
@@ -0,0 +1 @@
+!include $ONL_TEMPLATES/no-platform-modules.yml ARCH=amd64 VENDOR=lenovo BASENAME=x86-64-lenovo-ne10032
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/Makefile b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/Makefile
new file mode 100644
index 00000000..003238cf
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/Makefile
@@ -0,0 +1 @@
+include $(ONL)/make/pkg.mk
\ No newline at end of file
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/PKG.yml b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/PKG.yml
new file mode 100644
index 00000000..47ad6b43
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/PKG.yml
@@ -0,0 +1 @@
+!include $ONL_TEMPLATES/onlp-platform-any.yml PLATFORM=x86-64-lenovo-ne10032 ARCH=amd64 TOOLCHAIN=x86_64-linux-gnu
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/Makefile b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/Makefile
new file mode 100644
index 00000000..e7437cb2
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/Makefile
@@ -0,0 +1,2 @@
+FILTER=src
+include $(ONL)/make/subdirs.mk
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/lib/Makefile b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/lib/Makefile
new file mode 100644
index 00000000..c4d47db6
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/lib/Makefile
@@ -0,0 +1,45 @@
+############################################################
+#
+#
+# Copyright 2014 BigSwitch 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 $(ONL)/make/config.amd64.mk
+
+MODULE := libonlp-x86-64-lenovo-ne10032
+include $(BUILDER)/standardinit.mk
+
+DEPENDMODULES := AIM IOF x86_64_lenovo_ne10032 onlplib
+DEPENDMODULE_HEADERS := sff
+
+include $(BUILDER)/dependmodules.mk
+
+SHAREDLIB := libonlp-x86-64-lenovo-ne10032.so
+$(SHAREDLIB)_TARGETS := $(ALL_TARGETS)
+include $(BUILDER)/so.mk
+.DEFAULT_GOAL := $(SHAREDLIB)
+
+GLOBAL_CFLAGS += -I$(onlp_BASEDIR)/module/inc
+GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MODULES_INIT=1
+GLOBAL_CFLAGS += -fPIC
+GLOBAL_LINK_LIBS += -lpthread
+
+include $(BUILDER)/targets.mk
+
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/onlpdump/Makefile b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/onlpdump/Makefile
new file mode 100644
index 00000000..41ece0e6
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/onlpdump/Makefile
@@ -0,0 +1,46 @@
+############################################################
+#
+#
+# Copyright 2014 BigSwitch 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 $(ONL)/make/config.amd64.mk
+
+.DEFAULT_GOAL := onlpdump
+
+MODULE := onlpdump
+include $(BUILDER)/standardinit.mk
+
+DEPENDMODULES := AIM IOF onlp x86_64_lenovo_ne10032 onlplib onlp_platform_defaults sff cjson cjson_util timer_wheel OS
+
+include $(BUILDER)/dependmodules.mk
+
+BINARY := onlpdump
+$(BINARY)_LIBRARIES := $(LIBRARY_TARGETS)
+include $(BUILDER)/bin.mk
+
+GLOBAL_CFLAGS += -DAIM_CONFIG_AIM_MAIN_FUNCTION=onlpdump_main
+GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MODULES_INIT=1
+GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MAIN=1
+GLOBAL_LINK_LIBS += -lpthread -lm
+
+include $(BUILDER)/targets.mk
+
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/.module b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/.module
new file mode 100644
index 00000000..c3586f84
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/.module
@@ -0,0 +1 @@
+name: x86_64_lenovo_ne10032
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/Makefile b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/Makefile
new file mode 100644
index 00000000..8d84c90a
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/Makefile
@@ -0,0 +1,9 @@
+###############################################################################
+#
+#
+#
+###############################################################################
+include $(ONL)/make/config.mk
+MODULE := x86_64_lenovo_ne10032
+AUTOMODULE := x86_64_lenovo_ne10032
+include $(BUILDER)/definemodule.mk
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/Makefile.bak b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/Makefile.bak
new file mode 100644
index 00000000..7c41ccfe
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/Makefile.bak
@@ -0,0 +1,9 @@
+###############################################################################
+#
+#
+#
+###############################################################################
+include ../../init.mk
+MODULE := x86_64_lenovo_ne10032
+AUTOMODULE := x86_64_lenovo_ne10032
+include $(BUILDER)/definemodule.mk
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/README b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/README
new file mode 100644
index 00000000..3053d766
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/README
@@ -0,0 +1,6 @@
+###############################################################################
+#
+# x86_64_lenovo_ne10032 README
+#
+###############################################################################
+
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/auto/make.mk b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/auto/make.mk
new file mode 100644
index 00000000..50beb13c
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/auto/make.mk
@@ -0,0 +1,9 @@
+###############################################################################
+#
+# x86_64_lenovo_ne10032 Autogeneration
+#
+###############################################################################
+x86_64_lenovo_ne10032_AUTO_DEFS := module/auto/x86_64_lenovo_ne10032.yml
+x86_64_lenovo_ne10032_AUTO_DIRS := module/inc/x86_64_lenovo_ne10032 module/src
+include $(BUILDER)/auto.mk
+
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/auto/x86_64_lenovo_ne10032.yml b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/auto/x86_64_lenovo_ne10032.yml
new file mode 100644
index 00000000..996dbc9f
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/auto/x86_64_lenovo_ne10032.yml
@@ -0,0 +1,47 @@
+###############################################################################
+#
+# x86_64_lenovo_ne10032 Autogeneration Definitions.
+#
+###############################################################################
+
+cdefs: &cdefs
+- X86_64_LENOVO_NE10032_CONFIG_INCLUDE_LOGGING:
+ doc: "Include or exclude logging."
+ default: 1
+- X86_64_LENOVO_NE10032_CONFIG_LOG_OPTIONS_DEFAULT:
+ doc: "Default enabled log options."
+ default: AIM_LOG_OPTIONS_DEFAULT
+- X86_64_LENOVO_NE10032_CONFIG_LOG_BITS_DEFAULT:
+ doc: "Default enabled log bits."
+ default: AIM_LOG_BITS_DEFAULT
+- X86_64_LENOVO_NE10032_CONFIG_LOG_CUSTOM_BITS_DEFAULT:
+ doc: "Default enabled custom log bits."
+ default: 0
+- X86_64_LENOVO_NE10032_CONFIG_PORTING_STDLIB:
+ doc: "Default all porting macros to use the C standard libraries."
+ default: 1
+- X86_64_LENOVO_NE10032_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS:
+ doc: "Include standard library headers for stdlib porting macros."
+ default: X86_64_LENOVO_NE10032_CONFIG_PORTING_STDLIB
+- X86_64_LENOVO_NE10032_CONFIG_INCLUDE_UCLI:
+ doc: "Include generic uCli support."
+ default: 0
+
+
+definitions:
+ cdefs:
+ X86_64_LENOVO_NE10032_CONFIG_HEADER:
+ defs: *cdefs
+ basename: x86_64_lenovo_ne10032_config
+
+ portingmacro:
+ X86_64_LENOVO_NE10032:
+ macros:
+ - malloc
+ - free
+ - memset
+ - memcpy
+ - strncpy
+ - vsnprintf
+ - snprintf
+ - strlen
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/inc/x86_64_lenovo_ne10032/x86_64_lenovo_ne10032.x b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/inc/x86_64_lenovo_ne10032/x86_64_lenovo_ne10032.x
new file mode 100644
index 00000000..4de39289
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/inc/x86_64_lenovo_ne10032/x86_64_lenovo_ne10032.x
@@ -0,0 +1,14 @@
+/**************************************************************************//**
+ *
+ *
+ *
+ *****************************************************************************/
+#include
+
+/* <--auto.start.xmacro(ALL).define> */
+/* */
+
+/* <--auto.start.xenum(ALL).define> */
+/* */
+
+
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/inc/x86_64_lenovo_ne10032/x86_64_lenovo_ne10032_config.h b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/inc/x86_64_lenovo_ne10032/x86_64_lenovo_ne10032_config.h
new file mode 100644
index 00000000..dcc8c0df
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/inc/x86_64_lenovo_ne10032/x86_64_lenovo_ne10032_config.h
@@ -0,0 +1,127 @@
+/**************************************************************************//**
+ *
+ * @file
+ * @brief x86_64_lenovo_ne10032 Configuration Header
+ *
+ * @addtogroup x86_64_lenovo_ne10032-config
+ * @{
+ *
+ *****************************************************************************/
+#ifndef __X86_64_LENOVO_NE10032_CONFIG_H__
+#define __X86_64_LENOVO_NE10032_CONFIG_H__
+
+#ifdef GLOBAL_INCLUDE_CUSTOM_CONFIG
+#include
+#endif
+#ifdef X86_64_LENOVO_NE10032_INCLUDE_CUSTOM_CONFIG
+#include
+#endif
+
+/* */
+#include
+/**
+ * X86_64_LENOVO_NE10032_CONFIG_INCLUDE_LOGGING
+ *
+ * Include or exclude logging. */
+
+
+#ifndef X86_64_LENOVO_NE10032_CONFIG_INCLUDE_LOGGING
+#define X86_64_LENOVO_NE10032_CONFIG_INCLUDE_LOGGING 1
+#endif
+
+/**
+ * X86_64_LENOVO_NE10032_CONFIG_LOG_OPTIONS_DEFAULT
+ *
+ * Default enabled log options. */
+
+
+#ifndef X86_64_LENOVO_NE10032_CONFIG_LOG_OPTIONS_DEFAULT
+#define X86_64_LENOVO_NE10032_CONFIG_LOG_OPTIONS_DEFAULT AIM_LOG_OPTIONS_DEFAULT
+#endif
+
+/**
+ * X86_64_LENOVO_NE10032_CONFIG_LOG_BITS_DEFAULT
+ *
+ * Default enabled log bits. */
+
+
+#ifndef X86_64_LENOVO_NE10032_CONFIG_LOG_BITS_DEFAULT
+#define X86_64_LENOVO_NE10032_CONFIG_LOG_BITS_DEFAULT AIM_LOG_BITS_DEFAULT
+#endif
+
+/**
+ * X86_64_LENOVO_NE10032_CONFIG_LOG_CUSTOM_BITS_DEFAULT
+ *
+ * Default enabled custom log bits. */
+
+
+#ifndef X86_64_LENOVO_NE10032_CONFIG_LOG_CUSTOM_BITS_DEFAULT
+#define X86_64_LENOVO_NE10032_CONFIG_LOG_CUSTOM_BITS_DEFAULT 0
+#endif
+
+/**
+ * X86_64_LENOVO_NE10032_CONFIG_PORTING_STDLIB
+ *
+ * Default all porting macros to use the C standard libraries. */
+
+
+#ifndef X86_64_LENOVO_NE10032_CONFIG_PORTING_STDLIB
+#define X86_64_LENOVO_NE10032_CONFIG_PORTING_STDLIB 1
+#endif
+
+/**
+ * X86_64_LENOVO_NE10032_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS
+ *
+ * Include standard library headers for stdlib porting macros. */
+
+
+#ifndef X86_64_LENOVO_NE10032_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS
+#define X86_64_LENOVO_NE10032_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS X86_64_LENOVO_NE10032_CONFIG_PORTING_STDLIB
+#endif
+
+/**
+ * X86_64_LENOVO_NE10032_CONFIG_INCLUDE_UCLI
+ *
+ * Include generic uCli support. */
+
+
+#ifndef X86_64_LENOVO_NE10032_CONFIG_INCLUDE_UCLI
+#define X86_64_LENOVO_NE10032_CONFIG_INCLUDE_UCLI 0
+#endif
+
+
+
+/**
+ * All compile time options can be queried or displayed
+ */
+
+/** Configuration settings structure. */
+typedef struct x86_64_lenovo_ne10032_config_settings_s {
+ /** name */
+ const char* name;
+ /** value */
+ const char* value;
+} x86_64_lenovo_ne10032_config_settings_t;
+
+/** Configuration settings table. */
+/** x86_64_lenovo_ne10032_config_settings table. */
+extern x86_64_lenovo_ne10032_config_settings_t x86_64_lenovo_ne10032_config_settings[];
+
+/**
+ * @brief Lookup a configuration setting.
+ * @param setting The name of the configuration option to lookup.
+ */
+const char* x86_64_lenovo_ne10032_config_lookup(const char* setting);
+
+/**
+ * @brief Show the compile-time configuration.
+ * @param pvs The output stream.
+ */
+int x86_64_lenovo_ne10032_config_show(struct aim_pvs_s* pvs);
+
+/* */
+
+#include "x86_64_lenovo_ne10032_porting.h"
+
+#endif /* __X86_64_LENOVO_NE10032_CONFIG_H__ */
+/* @} */
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/inc/x86_64_lenovo_ne10032/x86_64_lenovo_ne10032_dox.h b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/inc/x86_64_lenovo_ne10032/x86_64_lenovo_ne10032_dox.h
new file mode 100644
index 00000000..4a1ce31f
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/inc/x86_64_lenovo_ne10032/x86_64_lenovo_ne10032_dox.h
@@ -0,0 +1,26 @@
+/**************************************************************************//**
+ *
+ * x86_64_lenovo_ne10032 Doxygen Header
+ *
+ *****************************************************************************/
+#ifndef __X86_64_LENOVO_NE10032_DOX_H__
+#define __X86_64_LENOVO_NE10032_DOX_H__
+
+/**
+ * @defgroup x86_64_lenovo_ne10032 x86_64_lenovo_ne10032 - x86_64_lenovo_ne10032 Description
+ *
+
+The documentation overview for this module should go here.
+
+ *
+ * @{
+ *
+ * @defgroup x86_64_lenovo_ne10032-x86_64_lenovo_ne10032 Public Interface
+ * @defgroup x86_64_lenovo_ne10032-config Compile Time Configuration
+ * @defgroup x86_64_lenovo_ne10032-porting Porting Macros
+ *
+ * @}
+ *
+ */
+
+#endif /* __X86_64_LENOVO_NE10032_DOX_H__ */
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/inc/x86_64_lenovo_ne10032/x86_64_lenovo_ne10032_porting.h b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/inc/x86_64_lenovo_ne10032/x86_64_lenovo_ne10032_porting.h
new file mode 100644
index 00000000..5f1abbdb
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/inc/x86_64_lenovo_ne10032/x86_64_lenovo_ne10032_porting.h
@@ -0,0 +1,107 @@
+/**************************************************************************//**
+ *
+ * @file
+ * @brief x86_64_lenovo_ne10032 Porting Macros.
+ *
+ * @addtogroup x86_64_lenovo_ne10032-porting
+ * @{
+ *
+ *****************************************************************************/
+#ifndef __X86_64_LENOVO_NE10032_PORTING_H__
+#define __X86_64_LENOVO_NE10032_PORTING_H__
+
+
+/* */
+#if X86_64_LENOVO_NE10032_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS == 1
+#include
+#include
+#include
+#include
+#include
+#endif
+
+#ifndef X86_64_LENOVO_NE10032_MALLOC
+ #if defined(GLOBAL_MALLOC)
+ #define X86_64_LENOVO_NE10032_MALLOC GLOBAL_MALLOC
+ #elif X86_64_LENOVO_NE10032_CONFIG_PORTING_STDLIB == 1
+ #define X86_64_LENOVO_NE10032_MALLOC malloc
+ #else
+ #error The macro X86_64_LENOVO_NE10032_MALLOC is required but cannot be defined.
+ #endif
+#endif
+
+#ifndef X86_64_LENOVO_NE10032_FREE
+ #if defined(GLOBAL_FREE)
+ #define X86_64_LENOVO_NE10032_FREE GLOBAL_FREE
+ #elif X86_64_LENOVO_NE10032_CONFIG_PORTING_STDLIB == 1
+ #define X86_64_LENOVO_NE10032_FREE free
+ #else
+ #error The macro X86_64_LENOVO_NE10032_FREE is required but cannot be defined.
+ #endif
+#endif
+
+#ifndef X86_64_LENOVO_NE10032_MEMSET
+ #if defined(GLOBAL_MEMSET)
+ #define X86_64_LENOVO_NE10032_MEMSET GLOBAL_MEMSET
+ #elif X86_64_LENOVO_NE10032_CONFIG_PORTING_STDLIB == 1
+ #define X86_64_LENOVO_NE10032_MEMSET memset
+ #else
+ #error The macro X86_64_LENOVO_NE10032_MEMSET is required but cannot be defined.
+ #endif
+#endif
+
+#ifndef X86_64_LENOVO_NE10032_MEMCPY
+ #if defined(GLOBAL_MEMCPY)
+ #define X86_64_LENOVO_NE10032_MEMCPY GLOBAL_MEMCPY
+ #elif X86_64_LENOVO_NE10032_CONFIG_PORTING_STDLIB == 1
+ #define X86_64_LENOVO_NE10032_MEMCPY memcpy
+ #else
+ #error The macro X86_64_LENOVO_NE10032_MEMCPY is required but cannot be defined.
+ #endif
+#endif
+
+#ifndef X86_64_LENOVO_NE10032_STRNCPY
+ #if defined(GLOBAL_STRNCPY)
+ #define X86_64_LENOVO_NE10032_STRNCPY GLOBAL_STRNCPY
+ #elif X86_64_LENOVO_NE10032_CONFIG_PORTING_STDLIB == 1
+ #define X86_64_LENOVO_NE10032_STRNCPY strncpy
+ #else
+ #error The macro X86_64_LENOVO_NE10032_STRNCPY is required but cannot be defined.
+ #endif
+#endif
+
+#ifndef X86_64_LENOVO_NE10032_VSNPRINTF
+ #if defined(GLOBAL_VSNPRINTF)
+ #define X86_64_LENOVO_NE10032_VSNPRINTF GLOBAL_VSNPRINTF
+ #elif X86_64_LENOVO_NE10032_CONFIG_PORTING_STDLIB == 1
+ #define X86_64_LENOVO_NE10032_VSNPRINTF vsnprintf
+ #else
+ #error The macro X86_64_LENOVO_NE10032_VSNPRINTF is required but cannot be defined.
+ #endif
+#endif
+
+#ifndef X86_64_LENOVO_NE10032_SNPRINTF
+ #if defined(GLOBAL_SNPRINTF)
+ #define X86_64_LENOVO_NE10032_SNPRINTF GLOBAL_SNPRINTF
+ #elif X86_64_LENOVO_NE10032_CONFIG_PORTING_STDLIB == 1
+ #define X86_64_LENOVO_NE10032_SNPRINTF snprintf
+ #else
+ #error The macro X86_64_LENOVO_NE10032_SNPRINTF is required but cannot be defined.
+ #endif
+#endif
+
+#ifndef X86_64_LENOVO_NE10032_STRLEN
+ #if defined(GLOBAL_STRLEN)
+ #define X86_64_LENOVO_NE10032_STRLEN GLOBAL_STRLEN
+ #elif X86_64_LENOVO_NE10032_CONFIG_PORTING_STDLIB == 1
+ #define X86_64_LENOVO_NE10032_STRLEN strlen
+ #else
+ #error The macro X86_64_LENOVO_NE10032_STRLEN is required but cannot be defined.
+ #endif
+#endif
+
+/* */
+
+
+#endif /* __X86_64_LENOVO_NE10032_PORTING_H__ */
+/* @} */
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/make.mk b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/make.mk
new file mode 100644
index 00000000..32723a8f
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/make.mk
@@ -0,0 +1,10 @@
+###############################################################################
+#
+#
+#
+###############################################################################
+THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
+x86_64_lenovo_ne10032_INCLUDES := -I $(THIS_DIR)inc
+x86_64_lenovo_ne10032_INTERNAL_INCLUDES := -I $(THIS_DIR)src
+x86_64_lenovo_ne10032_DEPENDMODULE_ENTRIES := init:x86_64_lenovo_ne10032 ucli:x86_64_lenovo_ne10032
+
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/Makefile b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/Makefile
new file mode 100644
index 00000000..9fbf71c1
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/Makefile
@@ -0,0 +1,9 @@
+###############################################################################
+#
+# Local source generation targets.
+#
+###############################################################################
+
+ucli:
+ @../../../../tools/uclihandlers.py x86_64_lenovo_ne10032_ucli.c
+
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/debug.c b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/debug.c
new file mode 100644
index 00000000..dc716c84
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/debug.c
@@ -0,0 +1,45 @@
+#include "x86_64_lenovo_ne10032_int.h"
+
+#if X86_64_LENOVO_NE10032_CONFIG_INCLUDE_DEBUG == 1
+
+#include
+
+static char help__[] =
+ "Usage: debug [options]\n"
+ " -c CPLD Versions\n"
+ " -h Help\n"
+ ;
+
+int
+x86_64_lenovo_ne10032_debug_main(int argc, char* argv[])
+{
+ int c = 0;
+ int help = 0;
+ int rv = 0;
+
+ while( (c = getopt(argc, argv, "ch")) != -1) {
+ switch(c)
+ {
+ case 'c': c = 1; break;
+ case 'h': help = 1; rv = 0; break;
+ default: help = 1; rv = 1; break;
+ }
+
+ }
+
+ if(help || argc == 1) {
+ printf("%s", help__);
+ return rv;
+ }
+
+ if(c) {
+ printf("Not implemented.\n");
+ }
+
+
+ return 0;
+}
+
+#endif
+
+
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/fani.c b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/fani.c
new file mode 100644
index 00000000..b3c8d2ac
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/fani.c
@@ -0,0 +1,574 @@
+/************************************************************
+ *
+ *
+ * Copyright 2014 Big Switch Networks, Inc.
+ * Copyright 2018 Alpha Networks Incorporation.
+ *
+ * Licensed under the Eclipse Public License, Version 1.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the
+ * License.
+ *
+ *
+ ************************************************************
+ *
+ * Fan Platform Implementation Defaults.
+ *
+ ***********************************************************/
+#include
+#include
+#include
+#include
+#include "platform_lib.h"
+
+#define DEBUG 0
+
+#define CPLD_I2C_BUS_ID 0
+#define CPLD_I2C_ADDR 0x5E /* Power CPLD Physical Address in the I2C */
+
+#define CPLD_FAN6_STATUS_ADDR_OFFSET 0x10
+#define CPLD_FAN5_STATUS_ADDR_OFFSET 0x11
+#define CPLD_FAN4_STATUS_ADDR_OFFSET 0x12
+#define CPLD_FAN3_STATUS_ADDR_OFFSET 0x13
+#define CPLD_FAN2_STATUS_ADDR_OFFSET 0x14
+#define CPLD_FAN1_STATUS_ADDR_OFFSET 0x15
+
+#define CPLD_FAN6_0_SPEED_ADDR_OFFSET 0x16
+#define CPLD_FAN6_1_SPEED_ADDR_OFFSET 0x17
+#define CPLD_FAN5_0_SPEED_ADDR_OFFSET 0x18
+#define CPLD_FAN5_1_SPEED_ADDR_OFFSET 0x19
+#define CPLD_FAN4_0_SPEED_ADDR_OFFSET 0x1A
+#define CPLD_FAN4_1_SPEED_ADDR_OFFSET 0x1B
+#define CPLD_FAN3_0_SPEED_ADDR_OFFSET 0x1C
+#define CPLD_FAN3_1_SPEED_ADDR_OFFSET 0x1D
+#define CPLD_FAN2_0_SPEED_ADDR_OFFSET 0x1E
+#define CPLD_FAN2_1_SPEED_ADDR_OFFSET 0x1F
+#define CPLD_FAN1_0_SPEED_ADDR_OFFSET 0x20
+#define CPLD_FAN1_1_SPEED_ADDR_OFFSET 0x21
+
+#define CPLD_FAN_MIN_RPS_ADDR_OFFSET 0x22
+#define CPLD_FAN_PWM_ADDR_OFFSET 0x23
+#define CPLD_FAN_SEL_CONTROL_ADDR_OFFSET 0x24 /* 0: CPLD control, 1: BMC control */
+
+#define FAN1_EEPROM_BUS 21
+#define FAN_EEPROM_ADDR 0x57
+#define FAN_MODEL_OFFSET 0x67
+#define FAN_MODEL_LENGTH 12
+#define FAN_SERIAL_OFFSET 0x77
+#define FAN_SERIAL_LENGTH 8
+
+#define FAN_MAX_RPM 21000
+
+#if 1 //PSU FAN
+
+#define PSU_PMBus_ADDR 0x59
+#define READ_FAN_SPEED_REG 0x90
+#define READ_FAN_STATUS_1_2_REG 0x81
+//#define PSU_ID_OFFSET 4
+#define PSU_ID_OFFSET (PSU1_BUS_ID - FAN_1_ON_PSU1)
+#endif
+
+#define FAN_DIR_FRONT_TO_BACK 0
+#define FAN_DIR_BACK_TO_FRONT 1
+
+
+
+/* Static fan information */
+onlp_fan_info_t linfo[] = {
+ { }, /* Not used */
+ {
+ { ONLP_FAN_ID_CREATE(FAN_1), "Chassis Fan 1", 0 },
+ 0x0,
+ ONLP_FAN_CAPS_GET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_SET_RPM,
+ 0,
+ 0,
+ ONLP_FAN_MODE_INVALID,
+ },
+ {
+ { ONLP_FAN_ID_CREATE(FAN_2), "Chassis Fan 2", 0 },
+ 0x0,
+ ONLP_FAN_CAPS_GET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_SET_RPM,
+ 0,
+ 0,
+ ONLP_FAN_MODE_INVALID,
+ },
+ {
+ { ONLP_FAN_ID_CREATE(FAN_3), "Chassis Fan 3", 0 },
+ 0x0,
+ ONLP_FAN_CAPS_GET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_SET_RPM,
+ 0,
+ 0,
+ ONLP_FAN_MODE_INVALID,
+ },
+ {
+ { ONLP_FAN_ID_CREATE(FAN_4), "Chassis Fan 4", 0 },
+ 0x0,
+ ONLP_FAN_CAPS_GET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_SET_RPM,
+ 0,
+ 0,
+ ONLP_FAN_MODE_INVALID,
+ },
+ {
+ { ONLP_FAN_ID_CREATE(FAN_5), "Chassis Fan 5", 0 },
+ 0x0,
+ ONLP_FAN_CAPS_GET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_SET_RPM,
+ 0,
+ 0,
+ ONLP_FAN_MODE_INVALID,
+ },
+ {
+ { ONLP_FAN_ID_CREATE(FAN_6), "Chassis Fan 6", 0 },
+ 0x0,
+ ONLP_FAN_CAPS_GET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_SET_RPM,
+ 0,
+ 0,
+ ONLP_FAN_MODE_INVALID,
+ },
+ {
+ { ONLP_FAN_ID_CREATE(FAN_1_ON_PSU1), "Chassis PSU-1 Fan 1", 0 },
+ 0x0,
+ ONLP_FAN_CAPS_GET_RPM,
+ 0,
+ 0,
+ ONLP_FAN_MODE_INVALID,
+ },
+ {
+ { ONLP_FAN_ID_CREATE(FAN_1_ON_PSU2), "Chassis PSU-2 Fan 1", 0 },
+ 0x0,
+ ONLP_FAN_CAPS_GET_RPM,
+ 0,
+ 0,
+ ONLP_FAN_MODE_INVALID,
+ },
+};
+
+#define VALIDATE(_id) \
+ do { \
+ if(!ONLP_OID_IS_FAN(_id)) { \
+ return ONLP_STATUS_E_INVALID; \
+ } \
+ } while(0)
+
+
+typedef union
+{
+ unsigned char val;
+ struct
+ {
+ unsigned char fan_direction :1;
+ unsigned char fan_present :1;
+ unsigned char fan0_rps_err :1;
+ unsigned char fan1_rps_err :1;
+ unsigned char :4; /* reserved */
+ }bit;
+
+}_CPLD_FAN_STATUS_REG_T;
+
+
+/* Get the CPLD address offset for fan status */
+static char
+_onlp_fani_get_fan_status_addr_offset(int local_id)
+{
+ DIAG_PRINT("%s, local_id=%d", __FUNCTION__, local_id);
+ switch (local_id)
+ {
+ case FAN_1:
+ return CPLD_FAN1_STATUS_ADDR_OFFSET;
+ case FAN_2:
+ return CPLD_FAN2_STATUS_ADDR_OFFSET;
+ case FAN_3:
+ return CPLD_FAN3_STATUS_ADDR_OFFSET;
+ case FAN_4:
+ return CPLD_FAN4_STATUS_ADDR_OFFSET;
+ case FAN_5:
+ return CPLD_FAN5_STATUS_ADDR_OFFSET;
+ case FAN_6:
+ return CPLD_FAN6_STATUS_ADDR_OFFSET;
+ }
+ return 0;
+}
+
+/* Get the CPLD address offset for fan speed */
+static char
+_onlp_fani_get_fan_speed_addr_offset(int local_id)
+{
+ DIAG_PRINT("%s, local_id=%d", __FUNCTION__, local_id);
+ switch (local_id)
+ {
+ case FAN_1:
+ return CPLD_FAN1_0_SPEED_ADDR_OFFSET;
+ case FAN_2:
+ return CPLD_FAN2_0_SPEED_ADDR_OFFSET;
+ case FAN_3:
+ return CPLD_FAN3_0_SPEED_ADDR_OFFSET;
+ case FAN_4:
+ return CPLD_FAN4_0_SPEED_ADDR_OFFSET;
+ case FAN_5:
+ return CPLD_FAN5_0_SPEED_ADDR_OFFSET;
+ case FAN_6:
+ return CPLD_FAN6_0_SPEED_ADDR_OFFSET;
+ }
+ return 0;
+}
+
+static int
+_onlp_fani_info_get_fan(int local_id, onlp_fan_info_t *info)
+{
+ DIAG_PRINT("%s, local_id=%d", __FUNCTION__, local_id);
+ _CPLD_FAN_STATUS_REG_T fan_status_reg;
+ char status_addr_offset = 0, speed0_addr_offset = 0, speed1_addr_offset = 0;
+ char data = 0;
+ unsigned char tach_speed0 = 0, tach_speed1 = 0;
+ int ret = 0;
+
+ /* Get the CPLD address offset for fan status */
+ status_addr_offset = _onlp_fani_get_fan_status_addr_offset(local_id);
+
+ ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, status_addr_offset, &data);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ if (DEBUG)
+ AIM_LOG_INFO("%s:%d id[%d],status_addr_offset[%02x],read_byte[%02x]\n",
+ __FUNCTION__, __LINE__, local_id, (unsigned char)status_addr_offset, (unsigned char)data);
+
+ fan_status_reg.val = data;
+
+ /* Get fan air flow direction */
+ if (fan_status_reg.bit.fan_direction == FAN_DIR_FRONT_TO_BACK)
+ info->status |= ONLP_FAN_STATUS_F2B;
+ else
+ info->status |= ONLP_FAN_STATUS_B2F;
+
+ /* Get fan present */
+ if (fan_status_reg.bit.fan_present == 1)
+ info->status |= ONLP_FAN_STATUS_PRESENT;
+ else
+ info->status |= ONLP_FAN_STATUS_FAILED;
+
+ /* Get the CPLD address offset for fan speed */
+ speed0_addr_offset = _onlp_fani_get_fan_speed_addr_offset(local_id);
+ speed1_addr_offset = speed0_addr_offset + 1;
+
+ ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, speed0_addr_offset, (char *)&tach_speed0);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ if (DEBUG)
+ AIM_LOG_INFO("%s:%d id[%d],speed0_addr_offset[%02x],read_byte[%02x]\n",
+ __FUNCTION__, __LINE__, local_id, (unsigned char)speed0_addr_offset, (unsigned char)tach_speed0);
+
+ ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, speed1_addr_offset, (char *)&tach_speed1);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ if (DEBUG)
+ AIM_LOG_INFO("%s:%d id[%d],speed1_addr_offset[%02x],read_byte[%02x]\n",
+ __FUNCTION__, __LINE__, local_id, (unsigned char)speed1_addr_offset, (unsigned char)tach_speed1);
+
+ //DIAG_PRINT("%s, speed0=%d(0x%X), speed1=%d(0x%X)", __FUNCTION__, (int)tach_speed0, tach_speed0, (int)tach_speed1, tach_speed1);
+
+ /* Get fan rpm */
+ //info->rpm = (((int)tach_speed0 + (int)tach_speed1) / 2) * 150;
+ info->rpm = (int)tach_speed1 * 150;
+
+ ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN_PWM_ADDR_OFFSET, &data);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ if (DEBUG)
+ AIM_LOG_INFO("%s:%d id[%d],pwm_addr_offset[%02x],read_byte[%02x]\n",
+ __FUNCTION__, __LINE__, local_id, CPLD_FAN_PWM_ADDR_OFFSET, (unsigned char)data);
+
+ /* Get fan duty cycle */
+ info->percentage = round(((unsigned char)data * 100) / 255);
+
+
+ ret = i2c_read(FAN1_EEPROM_BUS + local_id - 1, FAN_EEPROM_ADDR, FAN_MODEL_OFFSET, FAN_MODEL_LENGTH, (char *)info->model);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+
+ ret = i2c_read(FAN1_EEPROM_BUS + local_id - 1, FAN_EEPROM_ADDR, FAN_SERIAL_OFFSET, FAN_SERIAL_LENGTH, (char *)info->serial);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+
+ return ONLP_STATUS_OK;
+}
+
+static int
+_onlp_fani_info_get_fan_on_psu(int local_id, onlp_fan_info_t *info)
+{
+ int ret = ONLP_STATUS_OK;
+ int exponent = 0, mantissa = 0;
+ uint16_t value = 0;
+
+
+ DIAG_PRINT("%s, local_id=%d", __FUNCTION__, local_id);
+
+ /* Get PSU fan speed */
+ switch (local_id + PSU_ID_OFFSET)
+ {
+ case PSU1_BUS_ID:
+ ret = i2c_read_word(PSU1_BUS_ID, PSU_PMBus_ADDR, READ_FAN_SPEED_REG);
+ if (ret < 0 && DEBUG)
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+
+ break;
+ case PSU2_BUS_ID:
+ ret = i2c_read_word(PSU2_BUS_ID, PSU_PMBus_ADDR, READ_FAN_SPEED_REG);
+ if (ret < 0 && DEBUG)
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+
+ break;
+ }
+
+ //printf("[%s]local_id:%d i2c read ret:%d\n",__FUNCTION__, local_id, ret);
+
+ if (ret <= 0)
+ {
+ info->status |= ONLP_FAN_STATUS_FAILED;
+ }
+ else
+ {
+ info->status |= ONLP_FAN_STATUS_PRESENT;
+
+ value = ret;
+ //Linear Data Format
+ exponent = psu_two_complement_to_int(value >> 11, 5, 0x1f);
+ mantissa = psu_two_complement_to_int(value & 0x7ff, 11, 0x7ff);
+
+ info->rpm = (exponent >= 0) ? (mantissa << exponent) : (mantissa) / (1 << -exponent);
+ }
+
+ //check Fan Fault, bit 7
+ ret = i2c_read_word(PSU2_BUS_ID, PSU_PMBus_ADDR, READ_FAN_STATUS_1_2_REG);
+ if (ret < 0 && DEBUG)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ }
+ else if ((ret & 0x80) == 0x80)
+ {
+ info->status |= ONLP_FAN_STATUS_FAILED;
+ }
+
+
+
+ return ONLP_STATUS_OK;
+}
+
+/*
+ * This function will be called prior to all of onlp_fani_* functions.
+ */
+#define DEFAULT_FAN_SPEED 50
+
+int
+onlp_fani_init(void)
+{
+ DIAG_PRINT("%s", __FUNCTION__);
+
+#if 1 //By HW design, percentage is apply on all fans.
+ onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(FAN_1), DEFAULT_FAN_SPEED);
+#else
+ int i = 0;
+
+ for (i = FAN_1;
+ i <= FAN_6;
+ i++)
+ {
+ onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(i), DEFAULT_FAN_SPEED);
+ }
+#endif
+
+ return ONLP_STATUS_OK;
+}
+
+int
+onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t *info)
+{
+ DIAG_PRINT("%s, id=%d", __FUNCTION__, id);
+
+ int ret = ONLP_STATUS_OK;
+ int local_id;
+
+ VALIDATE(id);
+
+ local_id = ONLP_OID_ID_GET(id);
+
+ *info = linfo[local_id];
+
+ switch (local_id)
+ {
+ case FAN_1_ON_PSU1:
+ case FAN_1_ON_PSU2:
+ ret = _onlp_fani_info_get_fan_on_psu(local_id, info);
+ break;
+
+ default:
+ ret = _onlp_fani_info_get_fan(local_id, info);
+ break;
+ }
+
+ return ret;
+}
+
+int onlp_fani_status_get(onlp_oid_t id, uint32_t *rv)
+{
+
+ DIAG_PRINT("%s, id=%d", __FUNCTION__, id);
+ onlp_fan_info_t info;
+ onlp_fan_status_t ret = 0;
+ onlp_fani_info_get(id, &info);
+
+
+ ret = info.status & (ONLP_FAN_STATUS_PRESENT | ONLP_FAN_STATUS_FAILED);
+ *rv = (uint32_t)ret;
+ return 0;
+}
+
+int _onlp_fani_rpm_to_percentage(int rpm)
+{
+ int percentage = 0;
+ percentage = round(rpm * 100 / FAN_MAX_RPM);
+
+ if (percentage == 0 && rpm != 0)
+ {
+ percentage = 1;
+ }
+ DIAG_PRINT("%s, rpm=%d to percentage=%d", __FUNCTION__, rpm, percentage);
+
+ return percentage;
+}
+
+/*
+ * This function sets the speed of the given fan in RPM.
+ *
+ * This function will only be called if the fan supprots the RPM_SET
+ * capability.
+ *
+ * It is optional if you have no fans at all with this feature.
+ */
+/*
+ [Note]: By H/W design, fan speed is controlled using percentage.
+ RPM value will be translated to percentage and it may produce some deviation.
+ (the register size is 8-bit, so there is only 255 units to present the value.)
+*/
+int
+onlp_fani_rpm_set(onlp_oid_t id, int rpm)
+{
+ DIAG_PRINT("%s, id=%d, rpm=%d", __FUNCTION__, id, rpm);
+
+ if (rpm > FAN_MAX_RPM || rpm <= 0)
+ {
+ AIM_LOG_INFO("%s:%d rpm:%d is out of range. (1~%d)\n", __FUNCTION__, __LINE__, rpm, FAN_MAX_RPM);
+ return ONLP_STATUS_E_PARAM;
+ }
+ return onlp_fani_percentage_set(id, _onlp_fani_rpm_to_percentage(rpm));
+}
+
+
+/*
+ * This function sets the fan speed of the given OID as a percentage.
+ *
+ * This will only be called if the OID has the PERCENTAGE_SET
+ * capability.
+ *
+ * It is optional if you have no fans at all with this feature.
+ */
+int
+onlp_fani_percentage_set(onlp_oid_t id, int p)
+{
+
+ int ret = 0, local_id = 0;
+ float val = (float)p * 2.55;
+ char data = (char)round(val);
+
+ DIAG_PRINT("%s, id=%d, p=%d (0x%2X)", __FUNCTION__, id, p, (unsigned char)data);
+
+ VALIDATE(id);
+
+ local_id = ONLP_OID_ID_GET(id);
+
+ /* Not support to stop fan */
+ if (p == 0)
+ return ONLP_STATUS_E_INVALID;
+ else if (p == 100)
+ data = 0xff;
+
+ /* Cannot control PWM for each fan modules respectively.
+ * All fan modules PWM will be the same.
+ */
+
+ ret = i2c_write_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN_PWM_ADDR_OFFSET, data);
+ if (ret < 0)
+ AIM_LOG_INFO("%s:%d data[%02x] fail[%d]\n", __FUNCTION__, __LINE__, data, ret);
+
+ if (DEBUG)
+ AIM_LOG_INFO("%s:%d id[%d],pwm_addr_offset[%02x],write_byte[%02x]\n",
+ __FUNCTION__, __LINE__, local_id, CPLD_FAN_PWM_ADDR_OFFSET, (unsigned char)data);
+
+ return ONLP_STATUS_OK;
+}
+
+
+/*
+ * This function sets the fan speed of the given OID as per
+ * the predefined ONLP fan speed modes: off, slow, normal, fast, max.
+ *
+ * Interpretation of these modes is up to the platform.
+ *
+ */
+int
+onlp_fani_mode_set(onlp_oid_t id, onlp_fan_mode_t mode)
+{
+ DIAG_PRINT("%s, ONLP_STATUS_E_UNSUPPORTED", __FUNCTION__);
+ return ONLP_STATUS_E_UNSUPPORTED;
+}
+
+/*
+ * This function sets the fan direction of the given OID.
+ *
+ * This function is only relevant if the fan OID supports both direction
+ * capabilities.
+ *
+ * This function is optional unless the functionality is available.
+ */
+int
+onlp_fani_dir_set(onlp_oid_t id, onlp_fan_dir_t dir)
+{
+ DIAG_PRINT("%s, ONLP_STATUS_E_UNSUPPORTED", __FUNCTION__);
+ return ONLP_STATUS_E_UNSUPPORTED;
+}
+
+/*
+ * Generic fan ioctl. Optional.
+ */
+int
+onlp_fani_ioctl(onlp_oid_t id, va_list vargs)
+{
+ DIAG_PRINT("%s, ONLP_STATUS_E_UNSUPPORTED", __FUNCTION__);
+ return ONLP_STATUS_E_UNSUPPORTED;
+}
+
+
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/ledi.c b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/ledi.c
new file mode 100644
index 00000000..8c502f05
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/ledi.c
@@ -0,0 +1,780 @@
+/************************************************************
+ *
+ *
+ * Copyright 2014, 2015 Big Switch Networks, Inc.
+ * Copyright 2018 Alpha Networks Incorporation.
+ *
+ * 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.
+ *
+ *
+ ************************************************************
+ *
+ * LED Management
+ *
+ ***********************************************************/
+#include
+#include
+#include
+#include
+#include "platform_lib.h"
+
+#include
+//#include "onlpie_int.h"
+
+#define CPLD_I2C_BUS_ID 8
+#define CPLD_I2C_ADDR 0x5F /* System CPLD Physical Address in the I2C */
+#define CPLD_SYS_LED_ADDRESS_OFFSET 0x08
+#define CPLD_FAN1_LED_ADDRESS_OFFSET 0x09 //Fan LED Register 0
+#define CPLD_FAN2_LED_ADDRESS_OFFSET 0x09
+#define CPLD_FAN3_LED_ADDRESS_OFFSET 0x0A //Fan LED Register 1
+#define CPLD_FAN4_LED_ADDRESS_OFFSET 0x0A
+#define CPLD_FAN5_LED_ADDRESS_OFFSET 0x0B //Fan LED Register 2
+#define CPLD_FAN6_LED_ADDRESS_OFFSET 0x0B
+#define CPLD_FAN1_REAR_LED_ADDRESS_OFFSET 0x0E //Fan Rear LED Register 0
+#define CPLD_FAN2_REAR_LED_ADDRESS_OFFSET 0x0E
+#define CPLD_FAN3_REAR_LED_ADDRESS_OFFSET 0x0F //Fan Rear LED Register 1
+#define CPLD_FAN4_REAR_LED_ADDRESS_OFFSET 0x0F
+#define CPLD_FAN5_REAR_LED_ADDRESS_OFFSET 0x010 //Fan Rear LED Register 2
+#define CPLD_FAN6_REAR_LED_ADDRESS_OFFSET 0x010
+#define CPLD_SERVICE_LED_ADDRESS_OFFSET 0x11 //Service Blue LED Register
+
+
+#define STACKING_LED_OFF 0x00
+#define STACKING_LED_AMBER_SOLID 0x01
+#define STACKING_LED_AMBER_BLINKING 0x03
+#define STACKING_LED_GREEN_SOLID 0x05
+#define STACKING_LED_GREEN_BLINKING 0x07
+
+#define PWR_LED_OFF 0x00
+#define PWR_LED_AMBER_SOLID 0x01
+#define PWR_LED_AMBER_BLINKING 0x03
+#define PWR_LED_GREEN_SOLID 0x05
+#define PWR_LED_GREEN_BLINKING 0x07
+
+#define SERVICE_LED_OFF 0x00
+#define SERVICE_LED_BLUE_SOLID 0x01
+#define SERVICE_LED_BLUE_BLINKING 0x03
+
+#define FAN_LED_OFF 0x00
+#define FAN_LED_AMBER_SOLID 0x01
+#define FAN_LED_AMBER_BLINKING 0x03
+#define FAN_LED_GREEN_SOLID 0x05
+#define FAN_LED_GREEN_BLINKING 0x07
+
+#define REAR_FAN_LED_GREEN_SOLID 0x01
+#define REAR_FAN_LED_GREEN_BLINKING 0x03
+
+#define VALIDATE(_id) \
+ do { \
+ if(!ONLP_OID_IS_LED(_id)) { \
+ return ONLP_STATUS_E_INVALID; \
+ } \
+ } while(0)
+
+struct led_id_mode
+{
+ enum onlp_led_id led_id;
+ onlp_led_mode_t mode;
+ int hw_led_light_mode;
+};
+
+static struct led_id_mode led_id_mode_data[] = {
+ { LED_SERVICE, ONLP_LED_MODE_OFF, SERVICE_LED_OFF },
+ { LED_SERVICE, ONLP_LED_MODE_BLUE, SERVICE_LED_BLUE_SOLID },
+ { LED_SERVICE, ONLP_LED_MODE_BLUE_BLINKING, SERVICE_LED_BLUE_BLINKING },
+ { LED_SERVICE, ONLP_LED_MODE_ON, SERVICE_LED_BLUE_SOLID },
+
+ { LED_STACKING, ONLP_LED_MODE_OFF, STACKING_LED_OFF },
+ { LED_STACKING, ONLP_LED_MODE_GREEN, STACKING_LED_GREEN_SOLID },
+ { LED_STACKING, ONLP_LED_MODE_GREEN_BLINKING, STACKING_LED_GREEN_BLINKING },
+ { LED_STACKING, ONLP_LED_MODE_ORANGE, STACKING_LED_AMBER_SOLID },
+ { LED_STACKING, ONLP_LED_MODE_ORANGE_BLINKING, STACKING_LED_AMBER_BLINKING },
+ { LED_STACKING, ONLP_LED_MODE_ON, STACKING_LED_GREEN_SOLID },
+
+ { LED_PWR, ONLP_LED_MODE_OFF, PWR_LED_OFF },
+ { LED_PWR, ONLP_LED_MODE_GREEN, PWR_LED_GREEN_SOLID },
+ { LED_PWR, ONLP_LED_MODE_GREEN_BLINKING, PWR_LED_GREEN_BLINKING },
+ { LED_PWR, ONLP_LED_MODE_ORANGE, PWR_LED_AMBER_SOLID },
+ { LED_PWR, ONLP_LED_MODE_ORANGE_BLINKING, PWR_LED_AMBER_BLINKING },
+ { LED_PWR, ONLP_LED_MODE_ON, PWR_LED_GREEN_SOLID },
+
+ { LED_FAN1, ONLP_LED_MODE_OFF, FAN_LED_OFF },
+ { LED_FAN1, ONLP_LED_MODE_GREEN, FAN_LED_GREEN_SOLID },
+ { LED_FAN1, ONLP_LED_MODE_GREEN_BLINKING, FAN_LED_GREEN_BLINKING },
+ { LED_FAN1, ONLP_LED_MODE_ORANGE, FAN_LED_AMBER_SOLID },
+ { LED_FAN1, ONLP_LED_MODE_ORANGE_BLINKING, FAN_LED_AMBER_BLINKING },
+ { LED_FAN1, ONLP_LED_MODE_ON, FAN_LED_GREEN_SOLID },
+
+ { LED_FAN2, ONLP_LED_MODE_OFF, FAN_LED_OFF },
+ { LED_FAN2, ONLP_LED_MODE_GREEN, FAN_LED_GREEN_SOLID },
+ { LED_FAN2, ONLP_LED_MODE_GREEN_BLINKING, FAN_LED_GREEN_BLINKING },
+ { LED_FAN2, ONLP_LED_MODE_ORANGE, FAN_LED_AMBER_SOLID },
+ { LED_FAN2, ONLP_LED_MODE_ORANGE_BLINKING, FAN_LED_AMBER_BLINKING },
+ { LED_FAN2, ONLP_LED_MODE_ON, FAN_LED_GREEN_SOLID },
+
+ { LED_FAN3, ONLP_LED_MODE_OFF, FAN_LED_OFF },
+ { LED_FAN3, ONLP_LED_MODE_GREEN, FAN_LED_GREEN_SOLID },
+ { LED_FAN3, ONLP_LED_MODE_GREEN_BLINKING, FAN_LED_GREEN_BLINKING },
+ { LED_FAN3, ONLP_LED_MODE_ORANGE, FAN_LED_AMBER_SOLID },
+ { LED_FAN3, ONLP_LED_MODE_ORANGE_BLINKING, FAN_LED_AMBER_BLINKING },
+ { LED_FAN3, ONLP_LED_MODE_ON, FAN_LED_GREEN_SOLID },
+
+ { LED_FAN4, ONLP_LED_MODE_OFF, FAN_LED_OFF },
+ { LED_FAN4, ONLP_LED_MODE_GREEN, FAN_LED_GREEN_SOLID },
+ { LED_FAN4, ONLP_LED_MODE_GREEN_BLINKING, FAN_LED_GREEN_BLINKING },
+ { LED_FAN4, ONLP_LED_MODE_ORANGE, FAN_LED_AMBER_SOLID },
+ { LED_FAN4, ONLP_LED_MODE_ORANGE_BLINKING, FAN_LED_AMBER_BLINKING },
+ { LED_FAN4, ONLP_LED_MODE_ON, FAN_LED_GREEN_SOLID },
+
+ { LED_FAN5, ONLP_LED_MODE_OFF, FAN_LED_OFF },
+ { LED_FAN5, ONLP_LED_MODE_GREEN, FAN_LED_GREEN_SOLID },
+ { LED_FAN5, ONLP_LED_MODE_GREEN_BLINKING, FAN_LED_GREEN_BLINKING },
+ { LED_FAN5, ONLP_LED_MODE_ORANGE, FAN_LED_AMBER_SOLID },
+ { LED_FAN5, ONLP_LED_MODE_ORANGE_BLINKING, FAN_LED_AMBER_BLINKING },
+ { LED_FAN5, ONLP_LED_MODE_ON, FAN_LED_GREEN_SOLID },
+
+ { LED_FAN6, ONLP_LED_MODE_OFF, FAN_LED_OFF },
+ { LED_FAN6, ONLP_LED_MODE_GREEN, FAN_LED_GREEN_SOLID },
+ { LED_FAN6, ONLP_LED_MODE_GREEN_BLINKING, FAN_LED_GREEN_BLINKING },
+ { LED_FAN6, ONLP_LED_MODE_ORANGE, FAN_LED_AMBER_SOLID },
+ { LED_FAN6, ONLP_LED_MODE_ORANGE_BLINKING, FAN_LED_AMBER_BLINKING },
+ { LED_FAN6, ONLP_LED_MODE_ON, FAN_LED_GREEN_SOLID },
+
+ { LED_REAR_FAN1, ONLP_LED_MODE_OFF, FAN_LED_OFF },
+ { LED_REAR_FAN1, ONLP_LED_MODE_GREEN, REAR_FAN_LED_GREEN_SOLID },
+ { LED_REAR_FAN1, ONLP_LED_MODE_GREEN_BLINKING, REAR_FAN_LED_GREEN_BLINKING },
+ { LED_REAR_FAN1, ONLP_LED_MODE_ON, REAR_FAN_LED_GREEN_SOLID },
+
+ { LED_REAR_FAN2, ONLP_LED_MODE_OFF, FAN_LED_OFF },
+ { LED_REAR_FAN2, ONLP_LED_MODE_GREEN, REAR_FAN_LED_GREEN_SOLID },
+ { LED_REAR_FAN2, ONLP_LED_MODE_GREEN_BLINKING, REAR_FAN_LED_GREEN_BLINKING },
+ { LED_REAR_FAN2, ONLP_LED_MODE_ON, REAR_FAN_LED_GREEN_SOLID },
+
+ { LED_REAR_FAN3, ONLP_LED_MODE_OFF, FAN_LED_OFF },
+ { LED_REAR_FAN3, ONLP_LED_MODE_GREEN, REAR_FAN_LED_GREEN_SOLID },
+ { LED_REAR_FAN3, ONLP_LED_MODE_GREEN_BLINKING, REAR_FAN_LED_GREEN_BLINKING },
+ { LED_REAR_FAN3, ONLP_LED_MODE_ON, REAR_FAN_LED_GREEN_SOLID },
+
+ { LED_REAR_FAN4, ONLP_LED_MODE_OFF, FAN_LED_OFF },
+ { LED_REAR_FAN4, ONLP_LED_MODE_GREEN, REAR_FAN_LED_GREEN_SOLID },
+ { LED_REAR_FAN4, ONLP_LED_MODE_GREEN_BLINKING, REAR_FAN_LED_GREEN_BLINKING },
+ { LED_REAR_FAN4, ONLP_LED_MODE_ON, REAR_FAN_LED_GREEN_SOLID },
+
+ { LED_REAR_FAN5, ONLP_LED_MODE_OFF, FAN_LED_OFF },
+ { LED_REAR_FAN5, ONLP_LED_MODE_GREEN, REAR_FAN_LED_GREEN_SOLID },
+ { LED_REAR_FAN5, ONLP_LED_MODE_GREEN_BLINKING, REAR_FAN_LED_GREEN_BLINKING },
+ { LED_REAR_FAN5, ONLP_LED_MODE_ON, REAR_FAN_LED_GREEN_SOLID },
+
+ { LED_REAR_FAN6, ONLP_LED_MODE_OFF, FAN_LED_OFF },
+ { LED_REAR_FAN6, ONLP_LED_MODE_GREEN, REAR_FAN_LED_GREEN_SOLID },
+ { LED_REAR_FAN6, ONLP_LED_MODE_GREEN_BLINKING, REAR_FAN_LED_GREEN_BLINKING },
+ { LED_REAR_FAN6, ONLP_LED_MODE_ON, REAR_FAN_LED_GREEN_SOLID },
+};
+
+
+typedef union
+{
+ unsigned char val;
+ struct
+ {
+ unsigned char power :3;
+ unsigned char :1; /* reserved */
+ unsigned char stacking :3;
+ unsigned char :1; /* reserved */
+ }bit;
+
+}_CPLD_SYSTEM_LED_REG_T;
+
+typedef union
+{
+ unsigned char val;
+ struct
+ {
+ unsigned char locator :2;
+ unsigned char :6; /* reserved */
+ }bit;
+
+}_CPLD_LOCATOR_LED_REG_T;
+
+typedef union
+{
+ unsigned char val;
+ struct
+ {
+ unsigned char fan_a :3; /* fan_a : FAN1/FAN3/FAN5, fan_b : FAN2/FAN4/FAN6 */
+ unsigned char :1; /* reserved */
+ unsigned char fan_b :3;
+ unsigned char :1; /* reserved */
+ }bit;
+
+}_CPLD_FAN_LED_REG_T;
+
+/*
+ * Get the information for the given LED OID.
+ */
+static onlp_led_info_t linfo[] =
+{
+ { }, /* Not used */
+ {
+ { ONLP_LED_ID_CREATE(LED_SERVICE), "Chassis LED 1 (SERVICE LED)", 0 },
+ ONLP_LED_STATUS_PRESENT,
+ ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_BLUE | ONLP_LED_CAPS_BLUE_BLINKING,
+ },
+ {
+ { ONLP_LED_ID_CREATE(LED_STACKING), "Chassis LED 2 (STACKING LED)", 0 },
+ ONLP_LED_STATUS_PRESENT,
+ ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_ORANGE_BLINKING,
+ },
+ {
+ { ONLP_LED_ID_CREATE(LED_PWR), "Chassis LED 3 (POWER LED)", 0 },
+ ONLP_LED_STATUS_PRESENT,
+ ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_ORANGE_BLINKING,
+ },
+ {
+ { ONLP_LED_ID_CREATE(LED_FAN1), "Chassis LED 4 (FAN1 LED)", 0 },
+ ONLP_LED_STATUS_PRESENT,
+ ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_ORANGE_BLINKING,
+ },
+ {
+ { ONLP_LED_ID_CREATE(LED_FAN2), "Chassis LED 5 (FAN2 LED)", 0 },
+ ONLP_LED_STATUS_PRESENT,
+ ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_ORANGE_BLINKING,
+ },
+ {
+ { ONLP_LED_ID_CREATE(LED_FAN3), "Chassis LED 6 (FAN3 LED)", 0 },
+ ONLP_LED_STATUS_PRESENT,
+ ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_ORANGE_BLINKING,
+ },
+ {
+ { ONLP_LED_ID_CREATE(LED_FAN4), "Chassis LED 7 (FAN4 LED)", 0 },
+ ONLP_LED_STATUS_PRESENT,
+ ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_ORANGE_BLINKING,
+ },
+ {
+ { ONLP_LED_ID_CREATE(LED_FAN5), "Chassis LED 8 (FAN5 LED)", 0 },
+ ONLP_LED_STATUS_PRESENT,
+ ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_ORANGE_BLINKING,
+ },
+ {
+ { ONLP_LED_ID_CREATE(LED_FAN6), "Chassis LED 9 (FAN6 LED)", 0 },
+ ONLP_LED_STATUS_PRESENT,
+ ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_ORANGE_BLINKING,
+ },
+ {
+ { ONLP_LED_ID_CREATE(LED_REAR_FAN1), "FAN Rear LED 1", 0 },
+ ONLP_LED_STATUS_PRESENT,
+ ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING,
+ },
+ {
+ { ONLP_LED_ID_CREATE(LED_REAR_FAN2), "FAN Rear LED 2", 0 },
+ ONLP_LED_STATUS_PRESENT,
+ ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING,
+ },
+ {
+ { ONLP_LED_ID_CREATE(LED_REAR_FAN3), "FAN Rear LED 3", 0 },
+ ONLP_LED_STATUS_PRESENT,
+ ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING,
+ },
+ {
+ { ONLP_LED_ID_CREATE(LED_REAR_FAN4), "FAN Rear LED 4", 0 },
+ ONLP_LED_STATUS_PRESENT,
+ ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING,
+ },
+ {
+ { ONLP_LED_ID_CREATE(LED_REAR_FAN5), "FAN Rear LED 5", 0 },
+ ONLP_LED_STATUS_PRESENT,
+ ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING,
+ },
+ {
+ { ONLP_LED_ID_CREATE(LED_REAR_FAN6), "FAN Rear LED 6", 0 },
+ ONLP_LED_STATUS_PRESENT,
+ ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING,
+ },
+};
+
+static int convert_hw_led_light_mode_to_onlp(enum onlp_led_id id, int hw_mode)
+{
+ int i, nsize = sizeof(led_id_mode_data) / sizeof(led_id_mode_data[0]);
+ for (i = 0; i < nsize; i++)
+ {
+ if ((led_id_mode_data[i].led_id == id) &&
+ (led_id_mode_data[i].hw_led_light_mode == hw_mode))
+ {
+ DIAG_PRINT("%s, id:%d, hw_mode:%d mode:%d", __FUNCTION__, id, hw_mode, led_id_mode_data[i].mode);
+ return (int)led_id_mode_data[i].mode;
+ }
+ }
+
+ return -1;
+}
+
+static int convert_onlp_led_light_mode_to_hw(enum onlp_led_id id, onlp_led_mode_t mode)
+{
+ int i, nsize = sizeof(led_id_mode_data) / sizeof(led_id_mode_data[0]);
+ for (i = 0; i < nsize; i++)
+ {
+ if ((led_id_mode_data[i].led_id == id) &&
+ (led_id_mode_data[i].mode == mode))
+ {
+ DIAG_PRINT("%s, id:%d, mode:%d hw_mode:%d", __FUNCTION__, id, mode, led_id_mode_data[i].hw_led_light_mode);
+ return led_id_mode_data[i].hw_led_light_mode;
+ }
+ }
+
+ return -1;
+}
+
+/*
+ * This function will be called prior to any other onlp_ledi_* functions.
+ */
+int
+onlp_ledi_init(void)
+{
+ DIAG_PRINT("%s", __FUNCTION__);
+#if 0
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_SERVICE), ONLP_LED_MODE_OFF);
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_STACKING), ONLP_LED_MODE_OFF);
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_PWR), ONLP_LED_MODE_OFF);
+
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN1), ONLP_LED_MODE_OFF);
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN2), ONLP_LED_MODE_OFF);
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN3), ONLP_LED_MODE_OFF);
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN4), ONLP_LED_MODE_OFF);
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN5), ONLP_LED_MODE_OFF);
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN6), ONLP_LED_MODE_OFF);
+
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN1), ONLP_LED_MODE_OFF);
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN2), ONLP_LED_MODE_OFF);
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN3), ONLP_LED_MODE_OFF);
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN4), ONLP_LED_MODE_OFF);
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN5), ONLP_LED_MODE_OFF);
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN6), ONLP_LED_MODE_OFF);
+#endif
+ return ONLP_STATUS_OK;
+}
+
+int
+onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t *info)
+{
+ DIAG_PRINT("%s, id=%d", __FUNCTION__, id);
+ _CPLD_LOCATOR_LED_REG_T service_led_reg;
+ _CPLD_SYSTEM_LED_REG_T system_led_reg;
+ _CPLD_FAN_LED_REG_T fan_led_reg;
+ char data = 0;
+ int ret = 0, local_id = 0;
+
+ VALIDATE(id);
+
+ /* Set the onlp_oid_hdr_t and capabilities */
+ *info = linfo[ONLP_OID_ID_GET(id)];
+
+ local_id = ONLP_OID_ID_GET(id);
+
+ switch (local_id)
+ {
+ case LED_SERVICE:
+ ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_SERVICE_LED_ADDRESS_OFFSET, &data);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ service_led_reg.val = data;
+ break;
+ case LED_PWR:
+ case LED_STACKING:
+ ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_SYS_LED_ADDRESS_OFFSET, &data);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ system_led_reg.val = data;
+ break;
+ case LED_FAN1:
+ case LED_FAN2:
+ ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN1_LED_ADDRESS_OFFSET, &data);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ fan_led_reg.val = data;
+ break;
+ case LED_FAN3:
+ case LED_FAN4:
+ ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN3_LED_ADDRESS_OFFSET, &data);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ fan_led_reg.val = data;
+ break;
+ case LED_FAN5:
+ case LED_FAN6:
+ ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN5_LED_ADDRESS_OFFSET, &data);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ fan_led_reg.val = data;
+ break;
+
+ case LED_REAR_FAN1:
+ case LED_REAR_FAN2:
+ ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN1_REAR_LED_ADDRESS_OFFSET, &data);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ fan_led_reg.val = data;
+ break;
+ case LED_REAR_FAN3:
+ case LED_REAR_FAN4:
+ ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN3_REAR_LED_ADDRESS_OFFSET, &data);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ fan_led_reg.val = data;
+ break;
+ case LED_REAR_FAN5:
+ case LED_REAR_FAN6:
+ ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN5_REAR_LED_ADDRESS_OFFSET, &data);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ fan_led_reg.val = data;
+ break;
+ default :
+ AIM_LOG_INFO("%s:%d %d is a wrong ID\n", __FUNCTION__, __LINE__, local_id);
+ return ONLP_STATUS_E_PARAM;
+ }
+
+ /* Get LED status */
+ switch (local_id)
+ {
+ case LED_SERVICE:
+ info->mode = convert_hw_led_light_mode_to_onlp(local_id, service_led_reg.bit.locator);
+ break;
+ case LED_PWR:
+ info->mode = convert_hw_led_light_mode_to_onlp(local_id, system_led_reg.bit.power);
+ break;
+ case LED_STACKING:
+ info->mode = convert_hw_led_light_mode_to_onlp(local_id, system_led_reg.bit.stacking);
+ break;
+ case LED_FAN1:
+ case LED_FAN3:
+ case LED_FAN5:
+ case LED_REAR_FAN1:
+ case LED_REAR_FAN3:
+ case LED_REAR_FAN5:
+ //debug
+ //printf("[%s] fan_led_reg.val:0x%x \n", __FUNCTION__, fan_led_reg.val);
+ info->mode = convert_hw_led_light_mode_to_onlp(local_id, fan_led_reg.bit.fan_a);
+ break;
+ case LED_FAN2:
+ case LED_FAN4:
+ case LED_FAN6:
+ case LED_REAR_FAN2:
+ case LED_REAR_FAN4:
+ case LED_REAR_FAN6:
+ //debug
+ //printf("[%s] fan_led_reg.val:0x%x \n", __FUNCTION__, fan_led_reg.val);
+ info->mode = convert_hw_led_light_mode_to_onlp(local_id, fan_led_reg.bit.fan_b);
+ break;
+
+ default:
+ AIM_LOG_INFO("%s:%d %d is a wrong ID\n", __FUNCTION__, __LINE__, local_id);
+ return ONLP_STATUS_E_PARAM;
+ }
+
+ /* Set the on/off status */
+ if (info->mode != ONLP_LED_MODE_OFF)
+ {
+ info->status |= ONLP_LED_STATUS_ON;
+ }
+
+//debug
+//printf("[%s] local_id:%d info->mode:%d info->status:%d\n", __FUNCTION__, local_id, info->mode, info->status);
+
+ return ONLP_STATUS_OK;
+}
+
+/*
+ * Turn an LED on or off.
+ *
+ * This function will only be called if the LED OID supports the ONOFF
+ * capability.
+ *
+ * What 'on' means in terms of colors or modes for multimode LEDs is
+ * up to the platform to decide. This is intended as baseline toggle mechanism.
+ */
+int
+onlp_ledi_set(onlp_oid_t id, int on_or_off)
+{
+ DIAG_PRINT("%s, id=%d, on_or_off=%d", __FUNCTION__, id, on_or_off);
+ VALIDATE(id);
+
+ if (!on_or_off)
+ {
+ return onlp_ledi_mode_set(id, ONLP_LED_MODE_OFF);
+ }
+
+ return onlp_ledi_mode_set(id, ONLP_LED_MODE_ON);
+}
+
+/*
+ * 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)
+{
+ DIAG_PRINT("%s, id=%d, mode=%d", __FUNCTION__, id, mode);
+ _CPLD_LOCATOR_LED_REG_T service_led_reg;
+ _CPLD_SYSTEM_LED_REG_T system_led_reg;
+ _CPLD_FAN_LED_REG_T fan_led_reg;
+ char data = 0;
+ int ret = 0, local_id = 0, hw_led_mode = 0;
+
+ VALIDATE(id);
+
+ local_id = ONLP_OID_ID_GET(id);
+
+ switch (local_id)
+ {
+ case LED_SERVICE:
+ ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_SERVICE_LED_ADDRESS_OFFSET, &data);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ service_led_reg.val = data;
+ break;
+ case LED_PWR:
+ case LED_STACKING:
+ ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_SYS_LED_ADDRESS_OFFSET, &data);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ system_led_reg.val = data;
+ break;
+ case LED_FAN1:
+ case LED_FAN2:
+ ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN1_LED_ADDRESS_OFFSET, &data);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ fan_led_reg.val = data;
+ break;
+ case LED_FAN3:
+ case LED_FAN4:
+ ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN3_LED_ADDRESS_OFFSET, &data);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ fan_led_reg.val = data;
+ break;
+ case LED_FAN5:
+ case LED_FAN6:
+ ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN5_LED_ADDRESS_OFFSET, &data);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ fan_led_reg.val = data;
+ break;
+ case LED_REAR_FAN1:
+ case LED_REAR_FAN2:
+ ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN1_REAR_LED_ADDRESS_OFFSET, &data);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ fan_led_reg.val = data;
+ break;
+ case LED_REAR_FAN3:
+ case LED_REAR_FAN4:
+ ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN3_REAR_LED_ADDRESS_OFFSET, &data);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ fan_led_reg.val = data;
+ break;
+ case LED_REAR_FAN5:
+ case LED_REAR_FAN6:
+ ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN5_REAR_LED_ADDRESS_OFFSET, &data);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ fan_led_reg.val = data;
+ break;
+ default :
+ AIM_LOG_INFO("%s:%d %d is a wrong ID\n", __FUNCTION__, __LINE__, local_id);
+ return ONLP_STATUS_E_PARAM;
+ }
+
+ hw_led_mode = convert_onlp_led_light_mode_to_hw(local_id, mode);
+ if (hw_led_mode < 0)
+ return ONLP_STATUS_E_PARAM;
+
+ /* Set LED light mode */
+ switch (local_id)
+ {
+ case LED_SERVICE:
+ service_led_reg.bit.locator = hw_led_mode;
+ break;
+ case LED_PWR:
+ system_led_reg.bit.power = hw_led_mode;
+ break;
+ case LED_STACKING:
+ system_led_reg.bit.stacking = hw_led_mode;
+ break;
+ case LED_FAN1:
+ case LED_FAN3:
+ case LED_FAN5:
+ case LED_REAR_FAN1:
+ case LED_REAR_FAN3:
+ case LED_REAR_FAN5:
+ fan_led_reg.bit.fan_a = hw_led_mode;
+ break;
+ case LED_FAN2:
+ case LED_FAN4:
+ case LED_FAN6:
+ case LED_REAR_FAN2:
+ case LED_REAR_FAN4:
+ case LED_REAR_FAN6:
+ fan_led_reg.bit.fan_b = hw_led_mode;
+ break;
+ default:
+ AIM_LOG_INFO("%s:%d %d is a wrong ID\n", __FUNCTION__, __LINE__, local_id);
+ return ONLP_STATUS_E_PARAM;
+ }
+
+ switch (local_id)
+ {
+ case LED_SERVICE:
+ //printf("[debug]service_led_reg.val:0x%x\n", service_led_reg.val);
+ ret = i2c_write_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_SERVICE_LED_ADDRESS_OFFSET, service_led_reg.val);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ break;
+ case LED_PWR:
+ case LED_STACKING:
+ ret = i2c_write_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_SYS_LED_ADDRESS_OFFSET, system_led_reg.val);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ break;
+ case LED_FAN1:
+ case LED_FAN2:
+ ret = i2c_write_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN1_LED_ADDRESS_OFFSET, fan_led_reg.val);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ break;
+ case LED_FAN3:
+ case LED_FAN4:
+ ret = i2c_write_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN3_LED_ADDRESS_OFFSET, fan_led_reg.val);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ break;
+ case LED_FAN5:
+ case LED_FAN6:
+ ret = i2c_write_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN5_LED_ADDRESS_OFFSET, fan_led_reg.val);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ break;
+ case LED_REAR_FAN1:
+ case LED_REAR_FAN2:
+ ret = i2c_write_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN1_REAR_LED_ADDRESS_OFFSET, fan_led_reg.val);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ fan_led_reg.val = data;
+ break;
+ case LED_REAR_FAN3:
+ case LED_REAR_FAN4:
+ ret = i2c_write_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN3_REAR_LED_ADDRESS_OFFSET, fan_led_reg.val);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ fan_led_reg.val = data;
+ break;
+ case LED_REAR_FAN5:
+ case LED_REAR_FAN6:
+ ret = i2c_write_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN5_REAR_LED_ADDRESS_OFFSET, fan_led_reg.val);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ fan_led_reg.val = data;
+ break;
+ default :
+ AIM_LOG_INFO("%s:%d %d is a wrong ID\n", __FUNCTION__, __LINE__, local_id);
+ return ONLP_STATUS_E_PARAM;
+ }
+
+ return ONLP_STATUS_OK;
+}
+
+/*
+ * Generic LED ioctl interface.
+ */
+int
+onlp_ledi_ioctl(onlp_oid_t id, va_list vargs)
+{
+ return ONLP_STATUS_E_UNSUPPORTED;
+}
+
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/make.mk b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/make.mk
new file mode 100644
index 00000000..783c5312
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/make.mk
@@ -0,0 +1,9 @@
+###############################################################################
+#
+#
+#
+###############################################################################
+
+LIBRARY := x86_64_lenovo_ne10032
+$(LIBRARY)_SUBDIR := $(dir $(lastword $(MAKEFILE_LIST)))
+include $(BUILDER)/lib.mk
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/platform_lib.c b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/platform_lib.c
new file mode 100644
index 00000000..13a77bb9
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/platform_lib.c
@@ -0,0 +1,718 @@
+/************************************************************
+ *
+ *
+ * Copyright 2014 Big Switch Networks, Inc.
+ * Copyright 2018 Alpha Networks Incorporation
+ *
+ * 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 "platform_lib.h"
+
+#define DEBUG_FLAG 0
+
+int deviceNodeWrite(char *filename, char *buffer, int buf_size, int data_len)
+{
+ int fd;
+ int len;
+
+ if ((buffer == NULL) || (buf_size < 0)) {
+ return -1;
+ }
+
+ if ((fd = open(filename, O_WRONLY, S_IWUSR)) == -1) {
+ return -1;
+ }
+
+ if ((len = write(fd, buffer, buf_size)) < 0) {
+ close(fd);
+ return -1;
+ }
+
+ if ((close(fd) == -1)) {
+ return -1;
+ }
+
+ if ((len > buf_size) || (data_len != 0 && len != data_len)) {
+ return -1;
+ }
+
+ return 0;
+}
+
+int deviceNodeWriteInt(char *filename, int value, int data_len)
+{
+ char buf[8] = {0};
+ sprintf(buf, "%d", value);
+
+ return deviceNodeWrite(filename, buf, sizeof(buf)-1, data_len);
+}
+
+int deviceNodeReadBinary(char *filename, char *buffer, int buf_size, int data_len)
+ {
+ int fd;
+ int len;
+
+ if ((buffer == NULL) || (buf_size < 0)) {
+ return -1;
+ }
+
+ if ((fd = open(filename, O_RDONLY)) == -1) {
+ return -1;
+ }
+
+ if ((len = read(fd, buffer, buf_size)) < 0) {
+ close(fd);
+ return -1;
+ }
+
+ if ((close(fd) == -1)) {
+ return -1;
+ }
+
+ if ((len > buf_size) || (data_len != 0 && len != data_len)) {
+ return -1;
+ }
+
+ return 0;
+}
+
+int deviceNodeReadString(char *filename, char *buffer, int buf_size, int data_len)
+{
+ int ret;
+
+ if (data_len >= buf_size || data_len < 0) {
+ return -1;
+ }
+
+ ret = deviceNodeReadBinary(filename, buffer, buf_size-1, data_len);
+
+ if (ret == 0) {
+ if (data_len) {
+ buffer[data_len] = '\0';
+ }
+ else {
+ buffer[buf_size-1] = '\0';
+ }
+ }
+
+ return ret;
+}
+
+
+int psu_two_complement_to_int(uint16_t data, uint8_t valid_bit, int mask)
+{
+ uint16_t valid_data = data & mask;
+ bool is_negative = valid_data >> (valid_bit - 1);
+
+ return is_negative ? (-(((~valid_data) & mask) + 1)) : valid_data;
+}
+
+
+/*
+i2c APIs: access i2c device by ioctl
+static int i2c_read(int i2cbus, int addr, int offset, int length, char* data)
+static int i2c_read_byte(int i2cbus, int addr, int offset, char* data)
+static int i2c_read_word(int i2cbus, int addr, int command)
+static int i2c_write_byte(int i2cbus, int addr, int offset, char val)
+static int i2c_write_bit(int i2cbus, int addr, int offset, int bit, char val)
+*/
+int i2c_read(int i2cbus, int addr, int offset, int length, char* data)
+{
+ int file;
+ int i;
+ char filename[20];
+
+ /*open i2c device*/
+ snprintf(filename, sizeof(filename), "/dev/i2c/%d", i2cbus);
+ filename[sizeof(filename) - 1] = '\0';
+ file = open(filename, O_RDWR);
+
+ if (file < 0) {
+ sprintf(filename, "/dev/i2c-%d", i2cbus);
+ file = open(filename, O_RDWR);
+ }
+ if (file < 0)
+ {
+ AIM_LOG_INFO("Unable to open id:%d %s\r\n", i2cbus, filename);
+ return -1;
+ }
+
+ #if 0/*check funcs*/
+ unsigned long funcs;
+ if (ioctl(file, I2C_FUNCS, &funcs) < 0) {
+ AIM_LOG_INFO("Error: Could not get the adapter\r\n");
+ return -1;
+ }
+ //I2C_SMBUS_BLOCK_DATA
+ #endif
+
+ /*set slave address set_slave_addr(file, address, force))*/
+
+ if (ioctl(file, I2C_SLAVE_FORCE, addr) < 0)
+ //if (ioctl(file, I2C_SLAVE, addr) < 0)
+ {
+ AIM_LOG_INFO("Error: Could not set address to 0x%02x, %s \r\n", addr, strerror(errno));
+ close(file);
+ return -errno;
+ }
+
+ #if 1
+ int res = 0;
+ for (i = 0; i res)
+ {
+ AIM_LOG_INFO("Error: Size out of range offset:%d l:%d res:%d\r\n", offset, length, res);
+ return -1;
+ }
+
+ for (i = 0; i < length; i++)
+ {
+ data[i] = cblock[offset + i];
+ }
+ #endif
+
+ close(file);
+ return 0;
+}
+
+int i2c_sequential_read(int i2cbus, int addr, int offset, int length, char* data)
+{
+ int file;
+ int i;
+ char filename[20];
+ int res = 0;
+
+ /*open i2c device*/
+ snprintf(filename, sizeof(filename), "/dev/i2c/%d", i2cbus);
+ filename[sizeof(filename) - 1] = '\0';
+ file = open(filename, O_RDWR);
+
+ if (file < 0) {
+ sprintf(filename, "/dev/i2c-%d", i2cbus);
+ file = open(filename, O_RDWR);
+ }
+ if (file < 0)
+ {
+ AIM_LOG_INFO("Unable to open id:%d %s\r\n", i2cbus, filename);
+ return -1;
+ }
+
+ /*set slave address set_slave_addr(file, address, force))*/
+
+ if (ioctl(file, I2C_SLAVE_FORCE, addr) < 0)
+ {
+ AIM_LOG_INFO("Error: Could not set address to 0x%02x, %s \r\n", addr, strerror(errno));
+ close(file);
+ return -errno;
+ }
+ /*
+ Sequential Read for at24c128
+ use i2c_smbus_write_byte_data to write 24c128 address counter(two 8-bit data word addresses)
+ 24c128:
+ +----------------------------------------------------+
+ | S | Device | Wr | A | 1st Word | A | 2nd Word | A |...
+ | | Address | | | Address | | Address | |
+ +----------------------------------------------------+
+ SMbus:
+ +----------------------------------------------------+
+ | S | Device | Wr | A | Command | A | Data | A |...
+ | | Address | | | | | | |
+ +----------------------------------------------------+
+
+ */
+ res = i2c_smbus_write_byte_data(file, (uint8_t)offset>>8,(uint8_t)offset);
+
+ if(res != 0) {
+ AIM_LOG_INFO("Error: Write start address failed, return code %d\n", res);
+ return -1;
+ }
+
+ for (i = 0; i res)
+ {
+ AIM_LOG_INFO("Error: Size out of range offset:%d l:%d res:%d\r\n", offset, length, res);
+ return -1;
+ }
+
+ for (i = 0; i < length; i++)
+ {
+ data[i] = cblock[offset + i];
+ }
+ #endif
+
+ close(file);
+ return res;
+}
+
+int _i2c_read_block_data(int i2cbus, int addr, uint8_t offset, uint8_t *data, int data_length)
+{
+ int file;
+ char filename[20];
+
+ /*open i2c device*/
+ snprintf(filename, sizeof(filename), "/dev/i2c/%d", i2cbus);
+ filename[sizeof(filename) - 1] = '\0';
+ file = open(filename, O_RDWR);
+
+ if (file < 0) {
+ sprintf(filename, "/dev/i2c-%d", i2cbus);
+ file = open(filename, O_RDWR);
+ }
+ if (file < 0)
+ {
+ AIM_LOG_INFO("Unable to open id:%d %s\r\n", i2cbus, filename);
+ return -1;
+ }
+
+ #if 0/*check funcs*/
+ unsigned long funcs;
+ if (ioctl(file, I2C_FUNCS, &funcs) < 0) {
+ AIM_LOG_INFO("Error: Could not get the adapter\r\n");
+ return -1;
+ }
+ //I2C_SMBUS_BLOCK_DATA
+ #endif
+
+ /*set slave address set_slave_addr(file, address, force))*/
+
+ //if (ioctl(file, I2C_SLAVE_FORCE, addr) < 0)
+ if (ioctl(file, I2C_SLAVE, addr) < 0)
+ {
+ AIM_LOG_INFO("Error: Could not set address to 0x%02x, %s \r\n", offset, strerror(errno));
+ close(file);
+ return -errno;
+ }
+
+ int res = 0;
+ res = i2c_smbus_read_i2c_block_data(file, offset, data_length, data);
+ if (res < 0 && DEBUG_FLAG)
+ {
+ AIM_LOG_INFO("Error: i2c_smbus_read_word_data status:%d\r\n", res);
+ //close(file);
+ //return res;
+ }
+
+ close(file);
+ return res;
+}
+
+int i2c_read_byte(int i2cbus, int addr, int offset, char* data)
+{
+ int ret;
+
+ ret = i2c_read(i2cbus, addr, offset, 1, data);
+
+ if (ret < 0 && DEBUG_FLAG)
+ {
+ AIM_LOG_INFO("Error: Read failed %d\r\n",ret);
+ }
+
+ //AIM_LOG_INFO("i2c_read_byte: bus:%d add:0x%x offset:%d ret:%d data:0x%x\r\n", i2cbus, addr, offset, ret, *data);
+
+ return ret;
+}
+
+int i2c_read_word(int i2cbus, int addr, int offset)
+{
+ int ret;
+
+ ret = _i2c_read_word_data(i2cbus, addr, offset);
+
+ if (ret < 0 && DEBUG_FLAG)
+ {
+ AIM_LOG_INFO("Error: Read failed %d\r\n",ret);
+ }
+
+ //AIM_LOG_INFO("i2c_read_word: bus:%d add:0x%x offset:%d ret:%d\r\n", i2cbus, addr, offset, ret);
+
+ return ret;
+}
+
+int i2c_read_block(int i2cbus, int addr, uint8_t offset, uint8_t *data, int length)
+{
+ int ret;
+
+ ret = _i2c_read_block_data(i2cbus, addr, offset, data, length);
+
+ if (ret < 0 && DEBUG_FLAG)
+ {
+ AIM_LOG_INFO("Error: Read failed %d\r\n",ret);
+ }
+ //AIM_LOG_INFO("i2c_read_block: bus:%d add:0x%x offset:%d ret:%d data:0x%x\r\n", i2cbus, addr, offset, ret, *data);
+
+ return ret;
+}
+
+int i2c_write_byte(int i2cbus, int addr, int offset, char val)
+{
+ int file;
+ char filename[20];
+ int res = 0;
+
+ #if 0/*get current value*/
+ char cur_val=0;
+ res = i2c_read_byte(i2cbus, addr, offset, &cur_val);
+ if (ret <0)
+ {
+ return res;
+ }
+ #endif
+
+ /*open i2c device*/
+ snprintf(filename, sizeof(filename), "/dev/i2c/%d", i2cbus);
+ filename[sizeof(filename) - 1] = '\0';
+ file = open(filename, O_RDWR);
+
+ if (file < 0) {
+ sprintf(filename, "/dev/i2c-%d", i2cbus);
+ file = open(filename, O_RDWR);
+ }
+ if (file < 0)
+ {
+ AIM_LOG_INFO("Unable to open id:%d %s\r\n", i2cbus, filename);
+ return -1;
+ }
+
+ /*set slave address set_slave_addr(file, address, force))*/
+
+ //if (ioctl(file, I2C_SLAVE_FORCE, addr) < 0)
+ if (ioctl(file, I2C_SLAVE, addr) < 0)
+ {
+ AIM_LOG_INFO("Error: Could not set address to 0x%02x, %s \r\n", addr, strerror(errno));
+ close(file);
+ return -errno;
+ }
+
+ res = i2c_smbus_write_byte_data(file, offset, val);
+ if (res < 0)
+ {
+ AIM_LOG_INFO("Error: i2c_smbus_write_byte_data offset:%d val:0x%x r:%d\r\n", offset, val, res);
+ close(file);
+ return res;
+ }
+ close(file);
+ return 0;
+}
+
+int i2c_write_bit(int i2cbus, int addr, int offset, int bit, char val)
+{
+
+ int res = 0;
+ char cur_val=0;
+ char new_val=0;
+ if (val != 0 && val != 1)
+ {
+ AIM_LOG_INFO("Error: i2c_write_bit error val:%d\r\n", val);
+ return -1;
+ }
+
+ if (bit < 0 && bit > 7)
+ {
+ AIM_LOG_INFO("Error: i2c_write_bit error bit:%d\r\n", bit);
+ return -1;
+ }
+
+ res = i2c_read_byte(i2cbus, addr, offset, &cur_val);
+ if (res <0)
+ {
+ return res;
+ }
+
+ if (val == 1)
+ {
+ new_val = cur_val | (1< /tmp/onlpi_dbg_trace");
+ return 0;
+}
+
+char diag_debug_trace_off(void)
+{
+ system("echo 0 > /tmp/onlpi_dbg_trace");
+ return 0;
+}
+
+char diag_debug_trace_check(void)
+{
+ char flag = 0;
+ FILE* file = fopen ("/tmp/onlpi_dbg_trace", "r");
+ if (file == NULL)
+ {
+ return 0;
+ }
+ flag = fgetc (file);
+ fclose (file);
+
+ return (flag == '1')?1:0;
+}
+
+char* sfp_control_to_str(int value)
+{
+ switch (value)
+ {
+ case ONLP_SFP_CONTROL_RESET:
+ return "RESET";
+ case ONLP_SFP_CONTROL_RESET_STATE:
+ return "RESET_STATE";
+ case ONLP_SFP_CONTROL_RX_LOS:
+ return "RX_LOS";
+ case ONLP_SFP_CONTROL_TX_FAULT:
+ return "TX_FAULT";
+ case ONLP_SFP_CONTROL_TX_DISABLE:
+ return "TX_DISABLE";
+ case ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL:
+ return "TX_DISABLE_CHANNEL";
+ case ONLP_SFP_CONTROL_LP_MODE:
+ return "LP_MODE";
+ case ONLP_SFP_CONTROL_POWER_OVERRIDE:
+ return "POWER_OVERRIDE";
+
+ default:
+ return "UNKNOW";
+ }
+ return "";
+}
+
+char diag_debug_pause_platform_manage_on(void)
+{
+ system("echo 1 > /tmp/onlpi_dbg_pause_pm");
+ return 0;
+}
+
+char diag_debug_pause_platform_manage_off(void)
+{
+ system("echo 0 > /tmp/onlpi_dbg_pause_pm");
+ return 0;
+}
+
+char diag_debug_pause_platform_manage_check(void)
+{
+ char flag = 0;
+ FILE* file = fopen ("/tmp/onlpi_dbg_pause_pm", "r");
+ if (file == NULL)
+ {
+ return 0;
+ }
+ flag = fgetc (file);
+ fclose (file);
+
+ return (flag == '1')?1:0;
+}
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/platform_lib.h b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/platform_lib.h
new file mode 100644
index 00000000..03be299d
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/platform_lib.h
@@ -0,0 +1,224 @@
+/************************************************************
+ *
+ *
+ * Copyright 2014 Big Switch Networks, Inc.
+ * Copyright 2018 Alpha Networks Incorporation.
+ *
+ * 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 "x86_64_lenovo_ne10032_log.h"
+
+//for ne10032
+#define IDPROM_PATH "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/0-0056/eeprom"
+//#define IDPROM_PATH "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-6/i2c-10/10-0051/eeprom"
+
+#define PSU1_ID 1
+#define PSU2_ID 2
+#define PSUI_BUS_ID_OFFSET 9
+#define PSU1_BUS_ID (PSUI_BUS_ID_OFFSET + PSU1_ID)
+#define PSU2_BUS_ID (PSUI_BUS_ID_OFFSET + PSU2_ID)
+
+#define CHASSIS_THERMAL_COUNT 2
+#define CHASSIS_FAN_COUNT 6
+
+#define PSU1_AC_PMBUS_PREFIX "/sys/bus/i2c/devices/57-003c/"
+#define PSU2_AC_PMBUS_PREFIX "/sys/bus/i2c/devices/58-003f/"
+
+#define PSU1_AC_HWMON_PREFIX "/sys/bus/i2c/devices/2-0050/"
+#define PSU1_DC_HWMON_PREFIX "/sys/bus/i2c/devices/57-0050/"
+#define PSU2_AC_HWMON_PREFIX "/sys/bus/i2c/devices/3-0050/"
+#define PSU2_DC_HWMON_PREFIX "/sys/bus/i2c/devices/58-0053/"
+
+#define PSU1_AC_HWMON_NODE(node) PSU1_AC_HWMON_PREFIX#node
+#define PSU1_DC_HWMON_NODE(node) PSU1_DC_HWMON_PREFIX#node
+#define PSU2_AC_HWMON_NODE(node) PSU2_AC_HWMON_PREFIX#node
+#define PSU2_DC_HWMON_NODE(node) PSU2_DC_HWMON_PREFIX#node
+
+#define NUM_OF_SFP_PORT 32
+#define QSFP28_EEPROM_I2C_ADDR 0x50 /* QSFP28 EEPROM Physical Address in the I2C */
+
+#define QSFP28_EEPROM_TXRX_LOS_OFFSET 3
+#define QSFP28_EEPROM_TX_FAULT_OFFSET 4
+#define QSFP28_EEPROM_TX_DISABLE_OFFSET 86
+#define QSFP28_EEPROM_POWERSET_OFFSET 93
+#define QSFP28_EEPROM_PAGE_SELECT_OFFSET 127
+
+typedef long long I64_T; /* 64-bit signed */
+typedef unsigned long long UI64_T; /* 64-bit unsigned */
+typedef long I32_T; /* 32-bit signed */
+typedef unsigned long UI32_T; /* 32-bit unsigned */
+typedef short int I16_T; /* 16-bit signed */
+typedef unsigned short int UI16_T; /* 16-bit unsigned */
+typedef char I8_T; /* 8-bit signed */
+typedef unsigned char UI8_T; /* 8-bit unsigned */
+
+/*----------------------------------------------------------*/
+/* BIT operation */
+/*----------------------------------------------------------*/
+#define UTL_TEST_BITS(__type__,__var__,__pos__) \
+ (__type__)((((__type__)(__var__)>>(__type__)(__pos__))&(__type__)1)?(__type__)1:(__type__)0)
+
+#define UTL_LEFT_SHIFT_BITS(__type__,__range__,__var__,__sft_bits__) \
+ (((__type__)(__sft_bits__)>=(__range__))?0:((__type__)(__var__)<<(__type__)(__sft_bits__)))
+
+#define UTL_RIGHT_SHIFT_BITS(__type__,__range__,__var__,__sft_bits__) \
+ (((__type__)__sft_bits__>=(__range__))?(__type__)(__var__):((__type__)(__var__)>>(__type__)(__sft_bits__)))
+
+#define UTL_SET_BITS(__type__,__range__,__var__,__pos__) \
+ ((__type__)(__var__)|UTL_LEFT_SHIFT_BITS(__type__,__range__,(__type__)1U,(__type__)(__pos__)))
+
+#define UTL_RESET_BITS(__type__,__range__,__var__,__pos__) \
+ ((__type__)(__var__)&~UTL_LEFT_SHIFT_BITS(__type__,__range__,(__type__)1U,(__type__)(__pos__)))
+
+/*----------------------------------------------------------*/
+/* 64 BIT operation */
+/*----------------------------------------------------------*/
+#define UTL_TEST_BITS64(__var__,__pos__) UTL_TEST_BITS(UI64_T,__var__,__pos__)
+
+#define UTL_SET_BITS64(__var__,__pos__) (__var__) = UTL_SET_BITS(UI64_T,64,__var__,__pos__)
+#define UTL_RESET_BITS64(__var__,__pos__) (__var__) = UTL_RESET_BITS(UI64_T,64,__var__,__pos__)
+
+/*----------------------------------------------------------*/
+/* 32 BIT operation */
+/*----------------------------------------------------------*/
+/* Usage: if( UTL_TEST_BITS32(val,2) )*/
+/* pos = 0~7, 0~15, 0~31 */
+/* 0x1234 = 0001 0010 0011 0100 */
+/* UTL_TEST_BITS32( 0x1234, 2 ) ==> 1 */
+/* UTL_TEST_BITS32( 0x1234, 1 ) ==> 0 */
+#define UTL_TEST_BITS32(__var__,__pos__) UTL_TEST_BITS(UI32_T,__var__,__pos__)
+
+
+/* Usage: UTL_SET_BITS32( val, 6 ) */
+/* pos = 0~7, 0~15, 0~31 */
+/* val = 0x0100 = 0000 0001 0000 0000 */
+/* UTL_SET_BITS32( val,6 )==> 0000 0001 0100 0000 */
+/* UTL_RESET_BITS32( val,8 )=> 0000 0000 0000 0000 */
+#define UTL_SET_BITS32(__var__,__pos__) (__var__) = UTL_SET_BITS(UI32_T,32,__var__,__pos__)
+#define UTL_RESET_BITS32(__var__,__pos__) (__var__) = UTL_RESET_BITS(UI32_T,32,__var__,__pos__)
+
+/*----------------------------------------------------------*/
+/* 16 BIT operation */
+/*----------------------------------------------------------*/
+#define UTL_TEST_BITS16(__var__,__pos__) UTL_TEST_BITS(UI16_T,__var__,__pos__)
+
+#define UTL_SET_BITS16(__var__,__pos__) (__var__) = UTL_SET_BITS(UI16_T,16,__var__,__pos__)
+#define UTL_RESET_BITS16(__var__,__pos__) (__var__) = UTL_RESET_BITS(UI16_T,16,__var__,__pos__)
+
+/*----------------------------------------------------------*/
+/* 8 BIT operation */
+/*----------------------------------------------------------*/
+#define UTL_TEST_BITS8(__var__,__pos__) UTL_TEST_BITS(UI8_T,__var__,__pos__)
+
+#define UTL_SET_BITS8(__var__,__pos__) (__var__) = UTL_SET_BITS(UI8_T,8,__var__,__pos__)
+#define UTL_RESET_BITS8(__var__,__pos__) (__var__) = UTL_RESET_BITS(UI8_T,16,__var__,__pos__)
+
+
+int deviceNodeWriteInt(char *filename, int value, int data_len);
+int deviceNodeReadBinary(char *filename, char *buffer, int buf_size, int data_len);
+int deviceNodeReadString(char *filename, char *buffer, int buf_size, int data_len);
+
+typedef enum psu_type {
+ PSU_TYPE_UNKNOWN,
+ PSU_TYPE_AC_F2B,
+ PSU_TYPE_AC_B2F,
+ PSU_TYPE_DC_48V_F2B,
+ PSU_TYPE_DC_48V_B2F
+} psu_type_t;
+
+//psu_type_t get_psu_type(int id, char* modelname, int modelname_len);
+int psu_two_complement_to_int(uint16_t data, uint8_t valid_bit, int mask);
+
+/* FAN related data
+ */
+enum onlp_fan_id
+{
+ FAN_RESERVED = 0,
+ FAN_1,
+ FAN_2,
+ FAN_3,
+ FAN_4,
+ FAN_5,
+ FAN_6,
+ FAN_1_ON_PSU1,
+ FAN_1_ON_PSU2,
+};
+
+/*
+ * LED ID (need to sync with "enum onlp_led_id" defined in ledi.c)
+ */
+enum onlp_led_id
+{
+ LED_RESERVED = 0,
+ LED_SERVICE,
+ LED_STACKING,
+ LED_PWR,
+ LED_FAN1,
+ LED_FAN2,
+ LED_FAN3,
+ LED_FAN4,
+ LED_FAN5,
+ LED_FAN6,
+ LED_REAR_FAN1,
+ LED_REAR_FAN2,
+ LED_REAR_FAN3,
+ LED_REAR_FAN4,
+ LED_REAR_FAN5,
+ LED_REAR_FAN6,
+};
+
+
+/*
+i2c APIs: access i2c device by ioctl
+*/
+#include
+#include
+
+int i2c_read(int i2cbus, int addr, int offset, int length, char* data);
+int i2c_sequential_read(int i2cbus, int addr, int offset, int length, char* data);
+int i2c_read_byte(int i2cbus, int addr, int offset, char* data);
+int i2c_read_word(int i2cbus, int addr, int command);
+int i2c_read_block(int i2cbus, int addr, uint8_t offset, uint8_t *data, int length);
+int i2c_write_byte(int i2cbus, int addr, int offset, char val);
+int i2c_write_bit(int i2cbus, int addr, int offset, int bit, char val);
+int i2c_read_rps_status(int i2cbus, int addr, int offset);
+
+#define DIAG_FLAG_ON 1
+#define DIAG_FLAG_OFF 0
+char diag_flag_set(char d);
+char diag_flag_get(void);
+
+char diag_debug_trace_on(void);
+char diag_debug_trace_off(void);
+char diag_debug_trace_check(void);
+
+char diag_debug_pause_platform_manage_on(void);
+char diag_debug_pause_platform_manage_off(void);
+char diag_debug_pause_platform_manage_check(void);
+
+#define DIAG_TRACE(fmt,args...) if(diag_debug_trace_check()) printf("\n[TRACE]"fmt"\n", args)
+#define DIAG_PRINT(fmt,args...) DIAG_TRACE(fmt,args);else if(diag_flag_get()) printf("[DIAG]"fmt"\n", args)
+
+char* sfp_control_to_str(int value);
+
+#endif /* __PLATFORM_LIB_H__ */
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/psui.c b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/psui.c
new file mode 100644
index 00000000..484ab111
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/psui.c
@@ -0,0 +1,399 @@
+/************************************************************
+ *
+ *
+ * Copyright 2014 Big Switch Networks, Inc.
+ * Copyright 2018 Alpha Networks Incorporation.
+ *
+ * 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 "platform_lib.h"
+
+#define PSUI_DEBUG_FLAG 0
+
+
+#define PSU_STATUS_INTERRUPT 3
+#define PSU_STATUS_PRESENT 2
+#define PSU_STATUS_POWER_OK 1
+#define PSU_STATUS_POWER_ON 0
+
+#define PSU_NODE_MAX_INT_LEN 8
+#define PSU_NODE_MAX_PATH_LEN 64
+#define PSUI_CPLD_BUS_ID 0
+#define PSUI_POWER_CPLD_ADDR 0x5E
+#define RPS_PSU_EEPROM_ADDR 0x51
+#define RPS_PSU_MICRO_P_ADDR 0x59
+
+#define PSUI_MANUFACTURER_NAME_REG 0x0C
+#define PSUI_PRODUCT_NAME_REG 0x12
+#define PSUI_MODEL_NO_REG 0x1D
+#define PSUI_PRODUCT_VER_NO_REG 0x1F
+#define PSUI_PRODUCT_SER_NO_REG_F2B 0x23
+#define PSUI_PRODUCT_SER_NO_REG_B2F 0x25
+#define PSUI_PRODUCT_SER_NO_REG PSUI_PRODUCT_SER_NO_REG_B2F
+#define PSUI_RPS_STATUS_REG0 0x04 /* PSU Status Register for PSU#1 */
+#define PSUI_RPS_STATUS_REG1 0x03 /* PSU Status Register for PSU#2 */
+
+#define PSUI_PRODUCT_SER_NO_SIZE 14
+#define PSUI_PRODUCT_SER_NO_LEN (PSUI_PRODUCT_SER_NO_SIZE + 1)
+#define PSUI_PRODUCT_NAME_SIZE 13
+#define PSUI_PRODUCT_NAME_SIZE_F2B 11
+#define PSUI_PRODUCT_NAME_SIZE_B2F 13
+
+struct psui_reg_data_word
+{
+ uint8_t reg;
+ uint16_t value;
+};
+
+struct psui_reg_data_word regs_word[] = { { 0x88, 0 }, /* READ_Vin */
+ { 0x8b, 0 }, /* READ_Vout */
+ { 0x89, 0 }, /* READ_Iin */
+ { 0x8c, 0 }, /* READ_Iout */
+ { 0x96, 0 }, /* READ_Pout */
+ { 0x97, 0 } /* READ_Pin */
+};
+
+
+#define GET_RPS_STATUS_BIT(x,n) (((x) >> (n)) & 1)
+#define VALIDATE(_id) \
+ do { \
+ if(!ONLP_OID_IS_PSU(_id)) { \
+ return ONLP_STATUS_E_INVALID; \
+ } \
+ } while(0)
+
+
+int
+psu_ne10032_linear_format(int exponent, int mantissa)
+{
+ int multiplier = 1000; /* Units are "milli-" */
+
+ return (exponent >= 0) ? (mantissa << exponent) * multiplier :
+ (mantissa * multiplier) / (1 << -exponent);
+}
+
+int
+onlp_psui_init(void)
+{
+ DIAG_PRINT("%s", __FUNCTION__);
+ return ONLP_STATUS_OK;
+}
+
+
+static int
+psu_info_get_product_name(int id, UI8_T *data)
+{
+ DIAG_PRINT("%s, id:%d", __FUNCTION__, id);
+ int ret = 0;
+
+ ret = i2c_read_block(id, RPS_PSU_EEPROM_ADDR, PSUI_PRODUCT_NAME_REG, data, PSUI_PRODUCT_NAME_SIZE);
+ if (ret < 0 && PSUI_DEBUG_FLAG)
+ printf("I2C command 0x%X Read Fail, id=%d\n", PSUI_PRODUCT_NAME_REG, id);
+
+ return ret;
+}
+
+static int
+psu_info_get_product_ser(psu_type_t psu_type, int id, UI8_T *data)
+{
+ int ret = 0;
+ int addr = 0;
+ DIAG_PRINT("%s, id:%d", __FUNCTION__, id);
+ if (psu_type == PSU_TYPE_AC_F2B)
+ {
+ addr = PSUI_PRODUCT_SER_NO_REG_F2B;
+ }
+ else
+ {
+ addr = PSUI_PRODUCT_SER_NO_REG_B2F;
+ }
+
+ ret = i2c_read_block(id, RPS_PSU_EEPROM_ADDR, addr, data, PSUI_PRODUCT_SER_NO_SIZE);
+ if (ret < 0)
+ printf("I2C command 0x%X Read Fail, id=%d\n", addr, id);
+ return ret;
+}
+
+static int
+psu_info_get_status(int id, char *data)
+{
+ DIAG_PRINT("%s, id:%d", __FUNCTION__, id);
+ int ret = 0;
+
+ if (id == PSU1_ID)
+ {
+ ret = i2c_read_rps_status(PSUI_CPLD_BUS_ID, PSUI_POWER_CPLD_ADDR, PSUI_RPS_STATUS_REG0);
+ if (ret < 0)
+ printf("I2C command 0x%X Read Fail, id=%d\n", PSUI_RPS_STATUS_REG0, PSUI_CPLD_BUS_ID);
+ }
+ else if (id == PSU2_ID)
+ {
+ ret = i2c_read_rps_status(PSUI_CPLD_BUS_ID, PSUI_POWER_CPLD_ADDR, PSUI_RPS_STATUS_REG1);
+ if (ret < 0)
+ printf("I2C command 0x%X Read Fail, id=%d\n", PSUI_RPS_STATUS_REG1, PSUI_CPLD_BUS_ID);
+ }
+ sprintf(data, "%d\n", ret);
+ return ret;
+}
+
+
+static int
+psu_ne10032_info_get(int id, onlp_psu_info_t *info)
+{
+ DIAG_PRINT("%s, id:%d", __FUNCTION__, id);
+ //int val = 0;
+ //int index = ONLP_OID_ID_GET(info->hdr.id);
+
+ /* Set capability
+ */
+ info->caps = ONLP_PSU_CAPS_AC;
+
+ if (info->status & ONLP_PSU_STATUS_FAILED)
+ {
+ return ONLP_STATUS_OK;
+ }
+
+ /* Set the associated oid_table */
+ //info->hdr.coids[0] = ONLP_FAN_ID_CREATE(index + CHASSIS_FAN_COUNT);
+ //info->hdr.coids[1] = ONLP_THERMAL_ID_CREATE(index + CHASSIS_THERMAL_COUNT);
+
+#if 1
+ int i = 0;
+ int status;
+ int exponent, mantissa;
+ for (i = 0; i < 6; i++)
+ {
+ //printf("I2C register 0x%X \n", regs_word[i].reg);
+ status = i2c_read_word(id, RPS_PSU_MICRO_P_ADDR, regs_word[i].reg);
+ if (status < 0)
+ printf("I2C command 0x%X Read Fail\n", regs_word[i].reg);
+ else
+ {
+ //printf("I2C command 0x%X Read Success: 0x%02x\n", regs_word[i].reg, status);
+ regs_word[i].value = status;
+ }
+ }
+
+ info->caps |= ONLP_PSU_CAPS_VOUT;
+ info->caps |= ONLP_PSU_CAPS_VIN;
+ info->caps |= ONLP_PSU_CAPS_IOUT;
+ info->caps |= ONLP_PSU_CAPS_IIN;
+ info->caps |= ONLP_PSU_CAPS_POUT;
+ info->caps |= ONLP_PSU_CAPS_PIN;
+
+ /* Linear_5s_11s */
+ exponent = psu_two_complement_to_int(regs_word[0].value >> 11, 5, 0x1f);
+ mantissa = psu_two_complement_to_int(regs_word[0].value & 0x7ff, 11, 0x7ff);
+ info->mvin = psu_ne10032_linear_format(exponent, mantissa);
+
+ /* Linear_16u */
+ exponent = -12;
+ mantissa = regs_word[1].value;
+ info->mvout = psu_ne10032_linear_format(exponent, mantissa);
+
+ exponent = psu_two_complement_to_int(regs_word[2].value >> 11, 5, 0x1f);
+ mantissa = psu_two_complement_to_int(regs_word[2].value & 0x7ff, 11, 0x7ff);
+ info->miin = psu_ne10032_linear_format(exponent, mantissa);
+
+ exponent = psu_two_complement_to_int(regs_word[3].value >> 11, 5, 0x1f);
+ mantissa = psu_two_complement_to_int(regs_word[3].value & 0x7ff, 11, 0x7ff);
+ info->miout = psu_ne10032_linear_format(exponent, mantissa);
+
+ exponent = psu_two_complement_to_int(regs_word[4].value >> 11, 5, 0x1f);
+ mantissa = psu_two_complement_to_int(regs_word[4].value & 0x7ff, 11, 0x7ff);
+ info->mpout = psu_ne10032_linear_format(exponent, mantissa);
+
+ exponent = psu_two_complement_to_int(regs_word[5].value >> 11, 5, 0x1f);
+ mantissa = psu_two_complement_to_int(regs_word[5].value & 0x7ff, 11, 0x7ff);
+ info->mpin = psu_ne10032_linear_format(exponent, mantissa);
+#endif
+ return ONLP_STATUS_OK;
+}
+
+int
+psu_um400d_info_get(onlp_psu_info_t *info)
+{
+ DIAG_PRINT("%s", __FUNCTION__);
+ int index = ONLP_OID_ID_GET(info->hdr.id);
+
+ /* Set capability
+ */
+ info->caps = ONLP_PSU_CAPS_DC48;
+
+ if (info->status & ONLP_PSU_STATUS_FAILED)
+ {
+ return ONLP_STATUS_OK;
+ }
+
+ /* Set the associated oid_table */
+ info->hdr.coids[0] = ONLP_FAN_ID_CREATE(index + CHASSIS_FAN_COUNT);
+
+ return ONLP_STATUS_OK;
+}
+
+/*
+ * Get all information about the given PSU oid.
+ */
+static onlp_psu_info_t pinfo[] =
+{
+ { }, /* Not used */
+ { /* PSU-1 is on i2c channel 10 for ne10032*/
+ { ONLP_PSU_ID_CREATE(PSU1_ID), "PSU-1", 0 },
+ },
+ { /* PSU-2 is on i2c channel 11 for ne10032*/
+ { ONLP_PSU_ID_CREATE(PSU2_ID), "PSU-2", 0 },
+ }
+};
+
+psu_type_t get_psu_type(int id, char *product_name, int productname_len)
+{
+ DIAG_PRINT("%s, id:%d", __FUNCTION__, id);
+ UI8_T p_name[PSUI_PRODUCT_NAME_SIZE + 1] = { 0 };
+
+ /* Check AC model name */
+ if (psu_info_get_product_name(id, p_name) >= 0)
+ {
+ //printf("[psu_info_get_product_name] %s\n", p_name);
+ if (strncmp((char *)p_name, "DPS-770GB E", strlen("DPS-770GB E")) == 0)
+ {
+ if (product_name)
+ memcpy(product_name, p_name, PSUI_PRODUCT_NAME_SIZE_F2B);
+
+ return PSU_TYPE_AC_F2B;
+ }
+ else if (strncmp((char *)p_name, "DPS-770GB-1 A", strlen("DPS-770GB-1 A")) == 0)
+ {
+ if (product_name)
+ memcpy(product_name, p_name, PSUI_PRODUCT_NAME_SIZE_B2F);
+
+ return PSU_TYPE_AC_B2F;
+ }
+#if 0
+ else if (strncmp((char*)p_name, "DPS-770GB", strlen("DPS-770GB")) == 0)
+ {
+ if (product_name)
+ memcpy(product_name, p_name, productname_len-1);
+
+ return PSU_TYPE_AC_B2F;
+ }
+#endif
+ }
+ return PSU_TYPE_UNKNOWN;
+}
+
+
+int
+onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t *info)
+{
+ char name[ONLP_CONFIG_INFO_STR_MAX];
+ char status;
+ int ret = ONLP_STATUS_OK;
+ int index = ONLP_OID_ID_GET(id);
+ psu_type_t psu_type;
+
+ UI8_T product_ser[PSUI_PRODUCT_SER_NO_LEN];
+
+ UI8_T rps_status = 0, power_ok = 0, power_on = 0, power_present = 0;
+
+ VALIDATE(id);
+
+ memset(info, 0, sizeof(onlp_psu_info_t));
+ memset(name, 0, sizeof(name));
+ *info = pinfo[index]; /* Set the onlp_oid_hdr_t */
+
+ /* Get PSU type and product name, bus ID=index+10*/
+ psu_type = get_psu_type(index + PSUI_BUS_ID_OFFSET, info->model, sizeof(info->model));
+
+ //debug
+ DIAG_PRINT("%s, id:%d, index:%d, psu_type:%d\n", __FUNCTION__, id, index, psu_type);
+ switch (psu_type)
+ {
+ case PSU_TYPE_AC_F2B:
+ case PSU_TYPE_AC_B2F:
+ ret = psu_ne10032_info_get(index + PSUI_BUS_ID_OFFSET, info); /* Get PSU electric info from PMBus */
+ break;
+ case PSU_TYPE_DC_48V_F2B:
+ case PSU_TYPE_DC_48V_B2F:
+ ret = psu_um400d_info_get(info);
+ break;
+ default:
+ ret = ONLP_STATUS_E_UNSUPPORTED;
+ return ret;
+ }
+
+ /* Get the product serial number, bus ID=index+10 */
+ if (psu_info_get_product_ser(psu_type, index + PSUI_BUS_ID_OFFSET, product_ser) < 0)
+ {
+ printf("Unable to read PSU(%d) item(serial number)\r\n", index);
+ }
+ else
+ {
+ memcpy(info->serial, product_ser, sizeof(product_ser));
+ }
+
+ /* Get psu status from CPLD */
+ if (psu_info_get_status(index, &status) < 0)
+ {
+ printf("Unable to read PSU(%d) item(psu status)\r\n", index);
+ }
+ else
+ {
+ rps_status = (UI8_T)atoi(&status);
+ power_present = GET_RPS_STATUS_BIT(rps_status, PSU_STATUS_PRESENT);
+ power_ok = GET_RPS_STATUS_BIT(rps_status, PSU_STATUS_POWER_OK);
+ power_on = GET_RPS_STATUS_BIT(rps_status, PSU_STATUS_POWER_ON);
+
+ /* Empty */
+ if (!power_present)
+ {
+ info->status |= ONLP_PSU_STATUS_UNPLUGGED;
+ }
+
+ if (!power_ok)
+ {
+ info->status |= ONLP_PSU_STATUS_FAILED;
+ }
+
+ if (power_on)
+ {
+ info->status |= ONLP_PSU_STATUS_PRESENT;
+ }
+
+ DIAG_PRINT("rps_status:0x%x ,info->status:0x%x\n", rps_status, info->status);
+ DIAG_PRINT("present:%d, ok:%d, on:%d\n", power_present, power_ok, power_on);
+
+ }
+
+
+
+ return ret;
+}
+
+int
+onlp_psui_ioctl(onlp_oid_t pid, va_list vargs)
+{
+ DIAG_PRINT("%s, pid=%d", __FUNCTION__, pid);
+ return ONLP_STATUS_E_UNSUPPORTED;
+}
+
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/sfpi.c b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/sfpi.c
new file mode 100644
index 00000000..b15009c3
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/sfpi.c
@@ -0,0 +1,746 @@
+/************************************************************
+ *
+ *
+ * Copyright 2014 Big Switch Networks, Inc.
+ * Copyright 2018 Alpha Networks Incorporation.
+ *
+ * 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"
+
+#define DEBUG 0
+
+#define SYSTEM_CPLD_I2C_BUS_ID 8
+#define SYSTEM_CPLD_I2C_ADDR 0x5F /* System CPLD Physical Address in the I2C */
+#define SYSTEM_CPLD_RESET1_ADDR_OFFSET 0x02 /* Need to reset Port CPLD0~3 */
+
+#define PORT_CPLD0_I2C_BUS_ID 13
+#define PORT_CPLD1_I2C_BUS_ID 14
+#define PORT_CPLD2_I2C_BUS_ID 15
+#define PORT_CPLD3_I2C_BUS_ID 16
+#define PORT_CPLD_I2C_ADDR 0x5F /* Port CPLD Physical Address in the I2C */
+
+
+#define PORT_CPLD_PRESENT_ADDR_OFFSET 0x05
+#define PORT_CPLD_RESET_ADDR_OFFSET 0x07
+#define PORT_CPLD_LOWPWR_ADDR_OFFSET 0x09
+#define PORT_CPLD_MOD_SEL_ADDR_OFFSET 0x0B /* Module Select of QSFP ports */
+
+
+static int
+port_to_busid(int port)
+{
+ int ret = 0;
+ int index = 0;
+ index = (port / 8);
+ ret = index + PORT_CPLD0_I2C_BUS_ID;
+ DIAG_PRINT("%s, port:%d, busid:%d ", __FUNCTION__, port, ret);
+
+ return ret;
+}
+
+static int
+port_to_cpld_present_bit(int port)
+{
+ int index = 0;
+ index = (port % 8);
+ DIAG_PRINT("%s, port:%d, index:%d ", __FUNCTION__, port, index);
+ return index;
+}
+
+static int
+port_to_cpld_mod_sel_bit(int port)
+{
+ int index = 0;
+ index = (port % 8);
+ DIAG_PRINT("%s, port:%d, index:%d ", __FUNCTION__, port, index);
+ return index;
+}
+
+static int
+ne10032_sfp_present(int port)
+{
+ int ret = 0;
+ char data = 0;
+
+ DIAG_PRINT("%s, port:%d", __FUNCTION__, port);
+
+ ret = i2c_read_byte(port_to_busid(port), PORT_CPLD_I2C_ADDR, PORT_CPLD_PRESENT_ADDR_OFFSET, &data);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ if (DEBUG)
+ AIM_LOG_INFO("%s:%d port[%d],busid[%d],reg[%02x],read_byte[%02x]\n", __FUNCTION__, __LINE__,
+ port, port_to_busid(port), PORT_CPLD_PRESENT_ADDR_OFFSET, (unsigned char)data);
+
+ if (data & (1 << port_to_cpld_present_bit(port)))
+ {
+ return 1;
+ }
+
+ return 0;
+}
+
+static int
+ne10032_sfp_init(void)
+{
+ DIAG_PRINT("%s", __FUNCTION__);
+ int ret = 0;
+ char data = 0;
+
+ /* pull low for Reset Register 1 of Port CPLD0~3 */
+ ret = i2c_write_byte(SYSTEM_CPLD_I2C_BUS_ID, SYSTEM_CPLD_I2C_ADDR, SYSTEM_CPLD_RESET1_ADDR_OFFSET, data);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+/************************************************************
+ *
+ * SFPI Entry Points
+ *
+ ***********************************************************/
+int
+onlp_sfpi_init(void)
+{
+ DIAG_PRINT("%s", __FUNCTION__);
+ /* Called at initialization time */
+ ne10032_sfp_init();
+
+ return ONLP_STATUS_OK;
+}
+
+int
+onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t *bmap)
+{
+
+ /*
+ * Ports {0, 32}
+ */
+ int p = 0;
+ AIM_BITMAP_CLR_ALL(bmap);
+
+ for (p = 0; p < NUM_OF_SFP_PORT; p++)
+ {
+ AIM_BITMAP_SET(bmap, p);
+ }
+ DIAG_PRINT("%s", __FUNCTION__);
+
+ return ONLP_STATUS_OK;
+}
+
+int
+onlp_sfpi_is_present(int port)
+{
+ /*
+ * Return 1 if present.
+ * Return 0 if not present.
+ * Return < 0 if error.
+ */
+ int present = 0;
+
+ present = ne10032_sfp_present(port);
+
+ DIAG_PRINT("%s, port=%d, present:%d", __FUNCTION__, port, present);
+ return present;
+}
+
+int
+onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t *dst)
+{
+ DIAG_PRINT("%s", __FUNCTION__);
+ uint8_t bytes[4] = { 0 };
+ char data = 0;
+ int i = 0, ret = 0;
+
+ for (i = 0; i < 4; i++)
+ {
+ data = 0;
+ ret = i2c_read_byte(PORT_CPLD0_I2C_BUS_ID + i, PORT_CPLD_I2C_ADDR, PORT_CPLD_PRESENT_ADDR_OFFSET, &data);
+
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d [%d], fail[%d]\n", __FUNCTION__, __LINE__, PORT_CPLD0_I2C_BUS_ID + i, ret);
+ return ONLP_STATUS_E_INTERNAL;
+ }
+
+ bytes[i] = data;
+ }
+
+ //debug
+ //printf("[DEBUG]onlp_sfpi_presence_bitmap_get {0x%x 0x%x 0x%x 0x%x}\n",bytes[0],bytes[1],bytes[2],bytes[3]);
+
+ if (DEBUG)
+ AIM_LOG_INFO("onlp_sfpi_presence_bitmap_get 0x%x %x %x %x %x %x %x\r\n", bytes[3], bytes[2], bytes[1], bytes[0]);
+
+ /* Convert to 64 bit integer in port order */
+ uint32_t presence_all = 0;
+ for (i = AIM_ARRAYSIZE(bytes) - 1; i >= 0; i--)
+ {
+ presence_all <<= 8;
+ presence_all |= bytes[i];
+ }
+
+ /* Populate bitmap */
+ for (i = 0; presence_all; i++)
+ {
+ AIM_BITMAP_MOD(dst, i, (presence_all & 1));
+ presence_all >>= 1;
+ }
+
+ return ONLP_STATUS_OK;
+}
+
+int
+onlp_sfpi_eeprom_read(int port, uint8_t data[256])
+{
+ DIAG_PRINT("%s, port=%d", __FUNCTION__, port);
+ char mod_sel = 0;
+ int ret = 0;
+
+ /* Module select for the port */
+ mod_sel = (1 << port_to_cpld_mod_sel_bit(port));
+
+ ret = i2c_write_byte(port_to_busid(port), PORT_CPLD_I2C_ADDR, PORT_CPLD_MOD_SEL_ADDR_OFFSET, mod_sel);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+
+ /*
+ * Read the SFP eeprom into data[]
+ */
+ memset(data, 0x0, 256);
+
+ if (i2c_read(port_to_busid(port), QSFP28_EEPROM_I2C_ADDR, 0x0, 256, (char *)data) != 0)
+ {
+ AIM_LOG_INFO("Unable to read eeprom from port(%d)\r\n", port);
+ return ONLP_STATUS_E_INTERNAL;
+ }
+
+ return ONLP_STATUS_OK;
+}
+
+int onlp_sfpi_dom_read(int port, uint8_t data[256])
+{
+ DIAG_PRINT("%s, port=%d", __FUNCTION__, port);
+ char mod_sel = 0;
+ int ret = 0;
+
+ //Set page select to pahe 00h.
+ ret = onlp_sfpi_dev_writeb(port, QSFP28_EEPROM_I2C_ADDR, QSFP28_EEPROM_PAGE_SELECT_OFFSET, 0);
+ //ret = i2c_write_byte(port_to_busid(port), QSFP28_EEPROM_I2C_ADDR, QSFP28_EEPROM_PAGE_SELECT_OFFSET, 0);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+
+ /* Module select for the port */
+ mod_sel = (1 << port_to_cpld_mod_sel_bit(port));
+
+ ret = i2c_write_byte(port_to_busid(port), PORT_CPLD_I2C_ADDR, PORT_CPLD_MOD_SEL_ADDR_OFFSET, mod_sel);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+
+ /*
+ * Read the SFP DOM eeprom into data[]
+ */
+ memset(data, 0x0, 256);
+
+ if (i2c_read(port_to_busid(port), QSFP28_EEPROM_I2C_ADDR, 0x0, 256, (char *)data) != 0)
+ {
+ AIM_LOG_INFO("Unable to read eeprom from port(%d)\r\n", port);
+ return ONLP_STATUS_E_INTERNAL;
+ }
+
+ return ONLP_STATUS_OK;
+}
+
+int
+onlp_sfpi_dev_readb(int port, uint8_t devaddr, uint8_t addr)
+{
+ int ret;
+ int bus = port_to_busid(port);
+ char mod_sel = 0;
+
+ /* Module select for the port */
+ mod_sel = (1 << port_to_cpld_mod_sel_bit(port));
+
+ ret = i2c_write_byte(bus, PORT_CPLD_I2C_ADDR, PORT_CPLD_MOD_SEL_ADDR_OFFSET, mod_sel);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ }
+
+ ret = onlp_i2c_readb(bus, devaddr, addr, ONLP_I2C_F_FORCE);
+ DIAG_PRINT("%s, port:%d, devaddr:%d, addr:%d, ret:%d(0x%02X)", __FUNCTION__, port, devaddr, addr, ret, ret);
+ return ret;
+}
+
+int
+onlp_sfpi_dev_writeb(int port, uint8_t devaddr, uint8_t addr, uint8_t value)
+{
+
+ int ret;
+ int bus = port_to_busid(port);
+ char mod_sel = 0;
+
+ /* Module select for the port */
+ mod_sel = (1 << port_to_cpld_mod_sel_bit(port));
+ ret = i2c_write_byte(bus, PORT_CPLD_I2C_ADDR, PORT_CPLD_MOD_SEL_ADDR_OFFSET, mod_sel);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+ ret = onlp_i2c_writeb(bus, devaddr, addr, value, ONLP_I2C_F_FORCE);
+ DIAG_PRINT("%s, port:%d, devaddr:%d, addr:%d, value:%d(0x%02X), ret:%d", __FUNCTION__, port, devaddr, addr, value, value, ret);
+
+ return ret;
+}
+
+int
+onlp_sfpi_dev_readw(int port, uint8_t devaddr, uint8_t addr)
+{
+ int ret;
+ int bus = port_to_busid(port);
+ char mod_sel = 0;
+
+ /* Module select for the port */
+ mod_sel = (1 << port_to_cpld_mod_sel_bit(port));
+ ret = i2c_write_byte(bus, PORT_CPLD_I2C_ADDR, PORT_CPLD_MOD_SEL_ADDR_OFFSET, mod_sel);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ }
+
+ ret = onlp_i2c_readw(bus, devaddr, addr, ONLP_I2C_F_FORCE);
+ DIAG_PRINT("%s, port:%d, devaddr:%d, addr:%d, ret:%d(0x%04X)", __FUNCTION__, port, devaddr, addr, ret, ret);
+ return ret;
+}
+
+int
+onlp_sfpi_dev_writew(int port, uint8_t devaddr, uint8_t addr, uint16_t value)
+{
+
+ int ret;
+ int bus = port_to_busid(port);
+ char mod_sel = 0;
+
+ /* Module select for the port */
+ mod_sel = (1 << port_to_cpld_mod_sel_bit(port));
+ ret = i2c_write_byte(bus, PORT_CPLD_I2C_ADDR, PORT_CPLD_MOD_SEL_ADDR_OFFSET, mod_sel);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+
+ ret = onlp_i2c_writew(bus, devaddr, addr, value, ONLP_I2C_F_FORCE);
+ DIAG_PRINT("%s, port:%d, devaddr:%d, addr:%d, value:%d(0x%04X), ret:%d", __FUNCTION__, port, devaddr, addr, value, value, ret);
+ return ret;
+}
+
+/*
+ Reset and LP mode can control by CPLD so the setting will be keep in CPLD.
+ For other options, control is get/set to QSFP28.
+ Control options set to QSFP28 will be lost when the QSFP28 is removed.
+ Upper layer software system should keep the configuration and set it again when detect a new sfp module insert.
+
+ function R/W CPLD QSFP28 EEPROM
+ ------------------------------------ --- ------ -----------------
+ ONLP_SFP_CONTROL_RESET W 0x7
+ ONLP_SFP_CONTROL_RESET_STATE R/W 0x7
+ ONLP_SFP_CONTROL_RX_LOS R none byte 4
+ ONLP_SFP_CONTROL_TX_FAULT R none byte 3
+ ONLP_SFP_CONTROL_TX_DISABLE R/W none byte 86
+ ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL R/W none byte 86
+ ONLP_SFP_CONTROL_LP_MODE R/W 0x9
+ ONLP_SFP_CONTROL_POWER_OVERRIDE R/W none byte 93
+*/
+
+int onlp_sfpi_control_supported(int port, onlp_sfp_control_t control, int *supported)
+{
+ if (supported == NULL)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ONLP_STATUS_E_PARAM);
+ return ONLP_STATUS_E_PARAM;
+ }
+
+ *supported = 0;
+ switch (control)
+ {
+ case ONLP_SFP_CONTROL_RESET:
+ case ONLP_SFP_CONTROL_RESET_STATE:
+ case ONLP_SFP_CONTROL_LP_MODE:
+ case ONLP_SFP_CONTROL_POWER_OVERRIDE:
+ case ONLP_SFP_CONTROL_RX_LOS:
+ case ONLP_SFP_CONTROL_TX_FAULT:
+ case ONLP_SFP_CONTROL_TX_DISABLE:
+ case ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL:
+ *supported = 1;
+ break;
+
+ default:
+ *supported = 0;
+ break;
+ }
+
+ DIAG_PRINT("%s, port:%d, control:%d(%s), supported:%d", __FUNCTION__, port, control, sfp_control_to_str(control), *supported);
+ return ONLP_STATUS_OK;
+}
+
+int
+onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value)
+{
+ int rv = ONLP_STATUS_OK;
+ int bus = port_to_busid(port);
+ int mod_sel_bit = port_to_cpld_mod_sel_bit(port);
+ int supported = 0;
+ char optval = 0;
+
+ if ((onlp_sfpi_control_supported(port, control, &supported) == ONLP_STATUS_OK) && (supported == 0))
+ return ONLP_STATUS_E_UNSUPPORTED;
+
+ DIAG_PRINT("%s, port:%d, control:%d(%s), value:%d", __FUNCTION__, port, control, sfp_control_to_str(control), value);
+
+ /* Module select for the port */
+ optval = (1 << mod_sel_bit);
+ rv = i2c_write_byte(bus, PORT_CPLD_I2C_ADDR, PORT_CPLD_MOD_SEL_ADDR_OFFSET, optval);
+ if (rv < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, rv);
+ }
+
+ switch (control)
+ {
+ case ONLP_SFP_CONTROL_RESET:
+ if (value == 0) //set ONLP_SFP_CONTROL_RESET_STATE to 0
+ {
+ rv = onlp_sfpi_control_set(port, ONLP_SFP_CONTROL_RESET_STATE, 0);
+ break;
+ }
+
+ rv = onlp_sfpi_control_set(port, ONLP_SFP_CONTROL_RESET_STATE, 1);
+ if (rv < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, rv);
+ return rv;
+ }
+ rv = onlp_sfpi_control_set(port, ONLP_SFP_CONTROL_RESET_STATE, 0);
+ if (rv < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, rv);
+ return rv;
+ }
+
+ break;
+
+ case ONLP_SFP_CONTROL_RESET_STATE:
+ optval = onlp_i2c_readb(bus, PORT_CPLD_I2C_ADDR, PORT_CPLD_RESET_ADDR_OFFSET, ONLP_I2C_F_FORCE);
+ if (value != 0)
+ {
+ optval |= (1 << mod_sel_bit);
+ }
+ else
+ {
+ optval &= !(1 << mod_sel_bit);
+ }
+ rv = onlp_i2c_writeb(bus, PORT_CPLD_I2C_ADDR, PORT_CPLD_RESET_ADDR_OFFSET, optval, ONLP_I2C_F_FORCE);
+ if (rv < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, rv);
+ return rv;
+ }
+ break;
+
+ case ONLP_SFP_CONTROL_TX_DISABLE:
+ if (onlp_sfpi_is_present(port) == 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ONLP_STATUS_E_MISSING);
+ return ONLP_STATUS_E_MISSING;
+ }
+ optval = onlp_i2c_readb(bus, QSFP28_EEPROM_I2C_ADDR, QSFP28_EEPROM_TX_DISABLE_OFFSET, ONLP_I2C_F_FORCE);
+ if (value != 0)
+ {
+ optval |= 0x0f; //bit 0~3
+ }
+ else
+ {
+ optval &= !(0x0f);
+ }
+ rv = onlp_i2c_writeb(bus, QSFP28_EEPROM_I2C_ADDR, QSFP28_EEPROM_TX_DISABLE_OFFSET, optval, ONLP_I2C_F_FORCE);
+ if (rv < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, rv);
+ return rv;
+ }
+ break;
+
+ case ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL:
+ if (onlp_sfpi_is_present(port) == 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ONLP_STATUS_E_MISSING);
+ return ONLP_STATUS_E_MISSING;
+ }
+ if (value < 0 || value > 0x0f)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ONLP_STATUS_E_PARAM);
+ return ONLP_STATUS_E_PARAM;
+ }
+ optval = value;
+ rv = onlp_i2c_writeb(bus, QSFP28_EEPROM_I2C_ADDR, QSFP28_EEPROM_TX_DISABLE_OFFSET, optval, ONLP_I2C_F_FORCE);
+ if (rv < 0)
+ return rv;
+ break;
+
+ case ONLP_SFP_CONTROL_POWER_OVERRIDE:
+ if (onlp_sfpi_is_present(port) == 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ONLP_STATUS_E_MISSING);
+ return ONLP_STATUS_E_MISSING;
+ }
+ optval = onlp_i2c_readb(bus, QSFP28_EEPROM_I2C_ADDR, QSFP28_EEPROM_POWERSET_OFFSET, ONLP_I2C_F_FORCE);
+ if (value != 0)
+ {
+ optval |= 0x01;
+ }
+ else
+ {
+ optval &= !(0x01);
+ }
+ rv = onlp_i2c_writeb(bus, QSFP28_EEPROM_I2C_ADDR, QSFP28_EEPROM_POWERSET_OFFSET, optval, ONLP_I2C_F_FORCE);
+ if (rv < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, rv);
+ return rv;
+ }
+ break;
+
+ case ONLP_SFP_CONTROL_LP_MODE:
+ optval = onlp_i2c_readb(bus, PORT_CPLD_I2C_ADDR, PORT_CPLD_LOWPWR_ADDR_OFFSET, ONLP_I2C_F_FORCE);
+ if (value != 0)
+ {
+ optval |= (1 << mod_sel_bit);
+ }
+ else
+ {
+ optval &= !(1 << mod_sel_bit);
+ }
+ rv = onlp_i2c_writeb(bus, PORT_CPLD_I2C_ADDR, PORT_CPLD_LOWPWR_ADDR_OFFSET, optval, ONLP_I2C_F_FORCE);
+ if (rv < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, rv);
+ return rv;
+ }
+ break;
+
+ //Read Only
+ case ONLP_SFP_CONTROL_RX_LOS:
+ case ONLP_SFP_CONTROL_TX_FAULT:
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ONLP_STATUS_E_INVALID);
+ return ONLP_STATUS_E_INVALID;
+ break;
+ default:
+ break;
+ }
+ return rv;
+}
+
+int
+onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int *value)
+{
+ int rv = ONLP_STATUS_OK;
+ int bus = port_to_busid(port);
+ int mod_sel_bit = port_to_cpld_mod_sel_bit(port);
+ int supported = 0;
+ char optval = 0;
+
+ if (value == NULL)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ONLP_STATUS_E_PARAM);
+ return ONLP_STATUS_E_PARAM;
+ }
+
+ if ((onlp_sfpi_control_supported(port, control, &supported) == ONLP_STATUS_OK) && (supported == 0))
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ONLP_STATUS_E_UNSUPPORTED);
+ return ONLP_STATUS_E_UNSUPPORTED;
+ }
+
+ /* Module select for the port */
+ optval = (1 << mod_sel_bit);
+ rv = i2c_write_byte(bus, PORT_CPLD_I2C_ADDR, PORT_CPLD_MOD_SEL_ADDR_OFFSET, optval);
+ if (rv < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, rv);
+ }
+
+ *value = 0;
+ switch (control)
+ {
+ case ONLP_SFP_CONTROL_RESET_STATE:
+ optval = onlp_i2c_readb(bus, PORT_CPLD_I2C_ADDR, PORT_CPLD_RESET_ADDR_OFFSET, ONLP_I2C_F_FORCE);
+ if ((optval & (1 << mod_sel_bit)) != 0) //1
+ {
+ *value = 1;
+ }
+ else
+ {
+ *value = 0;
+ }
+ break;
+
+ case ONLP_SFP_CONTROL_RX_LOS:
+ if (onlp_sfpi_is_present(port) == 0)
+ {
+#if 1 //for display RX_LOS Bitmap in onlpdump
+ *value = 1;
+ break;
+#else
+ return ONLP_STATUS_E_MISSING;
+
+#endif
+ }
+ optval = onlp_i2c_readb(bus, QSFP28_EEPROM_I2C_ADDR, QSFP28_EEPROM_TXRX_LOS_OFFSET, ONLP_I2C_F_FORCE);
+ if ((optval & (0x0f)) != 0) //bit 0~3
+ {
+ *value = 1;
+ }
+ else
+ {
+ *value = 0;
+ }
+ break;
+
+ case ONLP_SFP_CONTROL_TX_FAULT:
+ if (onlp_sfpi_is_present(port) == 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ONLP_STATUS_E_MISSING);
+ return ONLP_STATUS_E_MISSING;
+ }
+ optval = onlp_i2c_readb(bus, QSFP28_EEPROM_I2C_ADDR, QSFP28_EEPROM_TX_FAULT_OFFSET, ONLP_I2C_F_FORCE);
+ if ((optval & (0x0f)) != 0) //bit 0~3
+ {
+ *value = 1;
+ }
+ else
+ {
+ *value = 0;
+ }
+ break;
+
+ case ONLP_SFP_CONTROL_TX_DISABLE:
+ if (onlp_sfpi_is_present(port) == 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ONLP_STATUS_E_MISSING);
+ return ONLP_STATUS_E_MISSING;
+ }
+ optval = onlp_i2c_readb(bus, QSFP28_EEPROM_I2C_ADDR, QSFP28_EEPROM_TX_DISABLE_OFFSET, ONLP_I2C_F_FORCE);
+ if ((optval & (0x0f)) != 0) //bit 0~3
+ {
+ *value = 1;
+ }
+ else
+ {
+ *value = 0;
+ }
+ break;
+
+ case ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL:
+ if (onlp_sfpi_is_present(port) == 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ONLP_STATUS_E_MISSING);
+ return ONLP_STATUS_E_MISSING;
+ }
+ optval = onlp_i2c_readb(bus, QSFP28_EEPROM_I2C_ADDR, QSFP28_EEPROM_TX_DISABLE_OFFSET, ONLP_I2C_F_FORCE);
+ *value = optval & (0x0f); //bit 0~3
+ break;
+
+ case ONLP_SFP_CONTROL_LP_MODE:
+ optval = onlp_i2c_readb(bus, PORT_CPLD_I2C_ADDR, PORT_CPLD_LOWPWR_ADDR_OFFSET, ONLP_I2C_F_FORCE);
+ if ((optval & (1 << mod_sel_bit)) != 0)
+ {
+ *value = 1;
+ }
+ else
+ {
+ *value = 0;
+ }
+ break;
+
+ case ONLP_SFP_CONTROL_POWER_OVERRIDE:
+ if (onlp_sfpi_is_present(port) == 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ONLP_STATUS_E_MISSING);
+ return ONLP_STATUS_E_MISSING;
+ }
+ optval = onlp_i2c_readb(bus, QSFP28_EEPROM_I2C_ADDR, QSFP28_EEPROM_POWERSET_OFFSET, ONLP_I2C_F_FORCE);
+ if ((optval & (0x01)) != 0) //bit 0
+ {
+ *value = 1;
+ }
+ else
+ {
+ *value = 0;
+ }
+ break;
+
+ //Set Only
+ case ONLP_SFP_CONTROL_RESET:
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ONLP_STATUS_E_INVALID);
+ return ONLP_STATUS_E_INVALID;
+ }
+ default:
+ break;
+ }
+
+ DIAG_PRINT("%s, port:%d, control:%d(%s), value:%d", __FUNCTION__, port, control, sfp_control_to_str(control), *value);
+
+ return rv;
+}
+
+
+int
+onlp_sfpi_denit(void)
+{
+ DIAG_PRINT("%s", __FUNCTION__);
+ return ONLP_STATUS_OK;
+}
+
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/sysi.c b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/sysi.c
new file mode 100644
index 00000000..c147c687
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/sysi.c
@@ -0,0 +1,1398 @@
+/************************************************************
+ *
+ *
+ * Copyright 2014 Big Switch Networks, Inc.
+ * Copyright 2018 Alpha Networks Incorporation.
+ *
+ * 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 "x86_64_lenovo_ne10032_int.h"
+#include "x86_64_lenovo_ne10032_log.h"
+#include "platform_lib.h"
+#include
+#include
+
+#define DEBUG 0
+
+#define PSU_NUM_ON_MAIN_BROAD 2
+#define FAN_NUM_ON_MAIN_BROAD 8
+#define LED_NUM_ON_MAIN_BROAD 15
+#define THERMAL_NUM_ON_MAIN_BROAD 2
+
+#define SYSTEM_CPLD_I2C_BUS_ID 8
+#define SYSTEM_CPLD_I2C_ADDR 0x5F /* System CPLD Physical Address in the I2C */
+#define SYSTEM_CPLD_REVISION_ADDR_OFFSET 0x00
+
+#define ONIE_EEPROM_BUS_ID 0
+#define ONIE_EEPROM_ADDR 0x56
+
+
+
+#define PLATFORM_STRING "x86-64-lenovo-ne10032-r0"
+
+const char*
+onlp_sysi_platform_get(void)
+{
+ DIAG_PRINT("%s, platform string: %s", __FUNCTION__, PLATFORM_STRING);
+ return PLATFORM_STRING;
+}
+
+#if 0
+int
+onlp_sysi_onie_data_get(uint8_t** data, int* size)
+{
+ uint8_t* rdata = aim_zmalloc(256);
+
+ if (onlp_file_read(rdata, 256, size, IDPROM_PATH) == ONLP_STATUS_OK)
+ {
+ if(*size == 256)
+ {
+ *data = rdata;
+ return ONLP_STATUS_OK;
+ }
+ }
+
+ aim_free(rdata);
+ *size = 0;
+ return ONLP_STATUS_E_INTERNAL;
+}
+
+#else // for EEPROM should be read by "i2cdump -y 0 0x56 c"(consecutive byte)
+int
+onlp_sysi_onie_data_get(uint8_t **data, int *size)
+{
+ DIAG_PRINT("%s", __FUNCTION__);
+ int ret = 0;
+ uint8_t *rdata = aim_zmalloc(256);
+
+ ret = i2c_sequential_read(ONIE_EEPROM_BUS_ID, ONIE_EEPROM_ADDR, 0, 256, (char *)rdata);
+ if (ret >= 0)
+ {
+ *data = rdata;
+
+#if 0//debug
+ int i = 0;
+ for (i=0;
+ i<256;
+ i++)
+ {
+ if ( i%8 == 0)
+ {
+ AIM_LOG_INFO("\n",rdata[i]);
+ }
+ AIM_LOG_INFO("0x%2X [%c]",rdata[i],(rdata[i]<=122 && rdata[i] >=65)?rdata[i]:' ');
+
+ }
+ AIM_LOG_INFO("\n",rdata[i]);
+#endif
+ return ONLP_STATUS_OK;
+ }
+
+ aim_free(rdata);
+ *size = 0;
+
+ return ONLP_STATUS_E_INTERNAL;
+}
+
+#endif
+
+void onlp_sysi_onie_data_free(uint8_t *data)
+{
+ DIAG_PRINT("%s", __FUNCTION__);
+ if (data)
+ aim_free(data);
+}
+
+int
+onlp_sysi_platform_info_get(onlp_platform_info_t *pi)
+{
+ DIAG_PRINT("%s", __FUNCTION__);
+ int ret = 0;
+ char data = 0;
+
+ ret = i2c_read_byte(SYSTEM_CPLD_I2C_BUS_ID, SYSTEM_CPLD_I2C_ADDR, SYSTEM_CPLD_REVISION_ADDR_OFFSET, &data);
+ if (ret < 0)
+ {
+ AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
+ return ret;
+ }
+
+ pi->cpld_versions = aim_fstrdup("%d", (int)data);
+
+ DIAG_PRINT("%s, cpld_versions:%d", __FUNCTION__, data);
+ return 0;
+}
+
+void
+onlp_sysi_platform_info_free(onlp_platform_info_t *pi)
+{
+ DIAG_PRINT("%s", __FUNCTION__);
+ aim_free(pi->cpld_versions);
+}
+
+
+int
+onlp_sysi_oids_get(onlp_oid_t *table, int max)
+{
+ DIAG_PRINT("%s, max:%d", __FUNCTION__, max);
+ onlp_oid_t *e = table;
+ memset(table, 0, max * sizeof(onlp_oid_t));
+ int i;
+
+ uint32_t oid = 0;
+
+ /* PSUs */
+ for (i = 1; i <= PSU_NUM_ON_MAIN_BROAD; i++)
+ {
+ oid = ONLP_PSU_ID_CREATE(i);
+ *e++ = oid;
+ DIAG_PRINT("PSU#%d oid:%d", i, oid);
+ }
+
+ /* LEDs */
+ for (i = 1; i <= LED_NUM_ON_MAIN_BROAD; i++)
+ {
+ oid = ONLP_LED_ID_CREATE(i);
+ *e++ = oid;
+ DIAG_PRINT("LED#%d oid:%d", i, oid);
+ }
+
+ /* Thermal sensors */
+ for (i = 1; i <= THERMAL_NUM_ON_MAIN_BROAD; i++)
+ {
+ oid = ONLP_THERMAL_ID_CREATE(i);
+ *e++ = oid;
+ DIAG_PRINT("THERMAL#%d oid:%d", i, oid);
+ }
+
+ /* Fans */
+ for (i = 1; i <= FAN_NUM_ON_MAIN_BROAD; i++)
+ {
+ oid = ONLP_FAN_ID_CREATE(i);
+ *e++ = oid;
+ DIAG_PRINT("FAN#%d oid:%d", i, oid);
+ }
+
+ return 0;
+}
+
+
+int onlp_sysi_platform_manage_init(void)
+{
+ DIAG_PRINT("%s", __FUNCTION__);
+ return 0;
+}
+
+/*
+ * 1. If any FAN failed, set all the other fans as full speed (100%)
+ * 2. When (LM75-1 + LM75-2)/2 >= 49.5 C, set fan speed from 50% to 65%.
+ * 3. When (LM75-1 + LM75-2)/2 >= 53C, set fan speed from 65% to 80%
+ * 4. When (LM75-1 + LM75-2)/2 >= 57.5C, set fan speed from 80% to 100%
+
+ * 5. When (LM75-1 + LM75-2)/2 <= 52.7C, set fan speed from 100% to 80%
+ * 6. When (LM75-1 + LM75-2)/2 <= 47.7C, set fan speed from 80% to 65%
+ * 7. When (LM75-1 + LM75-2)/2 <= 42.7C, set fan speed from 65% to 50%
+ * 8. The default FAN speed is 50%
+ */
+int
+onlp_sysi_platform_manage_fans(void)
+{
+ DIAG_PRINT("%s", __FUNCTION__);
+#define LEV1_UP_TEMP 57500 /*temperature*/
+#define LEV1_DOWN_TEMP NULL /* unused */
+#define LEV1_SPEED_PERC 100 /*percentage*/
+
+#define LEV2_UP_TEMP 53000
+#define LEV2_DOWN_TEMP 52700
+#define LEV2_SPEED_PERC 80
+
+#define LEV3_UP_TEMP 49500
+#define LEV3_DOWN_TEMP 47700
+#define LEV3_SPEED_PERC 65
+
+#define LEV4_UP_TEMP NULL /* unused */
+#define LEV4_DOWN_TEMP 42700
+#define LEV4_SPEED_PERC 50
+
+ int rc, i;
+ int is_up;
+ int new_temp, temp1, temp2, diff;
+ static int new_perc = 0, ori_perc = 0;
+ static int ori_temp = 0;
+ static int fan_failed = 0;
+ onlp_thermal_info_t thermal_info;
+ onlp_fan_info_t fan_info;
+
+ if (diag_debug_pause_platform_manage_check() == 1) //diag test mode
+ {
+ return ONLP_STATUS_OK;
+ }
+
+ /* get new temperature */
+ if ((rc = onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(1), &thermal_info)) != ONLP_STATUS_OK)
+ goto _EXIT;
+
+ temp1 = thermal_info.mcelsius;
+
+ if ((rc = onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(2), &thermal_info)) != ONLP_STATUS_OK)
+ goto _EXIT;
+
+ temp2 = thermal_info.mcelsius;
+
+ new_temp = (temp1 + temp2) / 2;
+
+ /* check fan status */
+ for (i = 1; i <= CHASSIS_FAN_COUNT; i++)
+ {
+ if ((rc = onlp_fani_info_get(ONLP_FAN_ID_CREATE(i), &fan_info)) != ONLP_STATUS_OK)
+ goto _EXIT;
+
+ if (fan_info.status & ONLP_FAN_STATUS_FAILED)
+ {
+ new_perc = LEV1_SPEED_PERC;
+ fan_failed = 1;
+ goto _CTRL;
+ }
+
+#if 0
+#define UNKNOW_SPEED_PERC 0
+ if( fan_info.rpm < 8800) //to prevent fan speed set too low by user , 8800 = lower bound speed for 50%
+ {
+ ori_perc = UNKNOW_SPEED_PERC;
+ new_perc = LEV4_SPEED_PERC;
+ fan_failed = 1;
+ goto _CTRL;
+ }
+#endif
+
+ }
+
+ if (ori_perc == LEV1_SPEED_PERC && fan_failed == 1)
+ {
+ fan_failed = 0;
+ new_perc = LEV4_SPEED_PERC;
+ goto _CTRL;
+ }
+
+ diff = new_temp - ori_temp;
+
+ if (diff == 0)
+ goto _EXIT;
+ else
+ is_up = (diff > 0) ? 1 : 0;
+
+ if (is_up)
+ {
+ if (new_temp >= LEV1_UP_TEMP)
+ new_perc = LEV1_SPEED_PERC;
+ else if (new_temp >= LEV2_UP_TEMP)
+ new_perc = LEV2_SPEED_PERC;
+ else if (new_temp >= LEV3_UP_TEMP)
+ new_perc = LEV3_SPEED_PERC;
+ else
+ new_perc = LEV4_SPEED_PERC;
+ }
+ else
+ {
+ if (new_temp <= LEV4_DOWN_TEMP)
+ new_perc = LEV4_SPEED_PERC;
+ else if (new_temp <= LEV3_DOWN_TEMP)
+ new_perc = LEV3_SPEED_PERC;
+ else if (new_temp <= LEV2_DOWN_TEMP)
+ new_perc = LEV2_SPEED_PERC;
+ else
+ new_perc = LEV1_SPEED_PERC;
+ }
+
+_CTRL :
+
+ if (DEBUG)
+ printf("\n[%s][%d]{ori:temp=%d, perc=%d} {new:temp=%d, perc=%d}\n", __FUNCTION__, __LINE__,
+ ori_temp, ori_perc, new_temp, new_perc);
+
+ if (ori_perc == new_perc)
+ goto _EXIT;
+
+ /* ctrl fans */
+#if 1 //CPLD control all fans by one register.
+ if ((rc = onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(FAN_1), new_perc)) != ONLP_STATUS_OK)
+ goto _EXIT;
+
+ AIM_LOG_INFO("Fan%d Speeds are now at %d%%", i, new_perc);
+#else
+ for (i = FAN_1;
+ i <= FAN_6;
+ i++)
+ {
+ if ((rc = onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(i), new_perc)) != ONLP_STATUS_OK)
+ goto _EXIT;
+
+ AIM_LOG_INFO("Fan%d Speeds are now at %d%%", i, new_perc);
+ }
+#endif
+
+ /* update om */
+ ori_perc = new_perc;
+ ori_temp = new_temp;
+
+_EXIT :
+
+ return rc;
+}
+
+int
+onlp_sysi_platform_manage_leds(void)
+{
+ DIAG_PRINT("%s", __FUNCTION__);
+ int i = 0, j = 0;
+ onlp_fan_info_t fan_info;
+ onlp_led_mode_t led_mode = ONLP_LED_MODE_OFF;
+ onlp_led_mode_t status_led_mode = ONLP_LED_MODE_BLUE_BLINKING;
+ onlp_psu_info_t psu1_info, psu2_info;
+
+ int fan_ok_count = 0;
+ int psu_ok_count = 0;
+
+ if (diag_debug_pause_platform_manage_check() == 1) //diag test mode
+ {
+ return ONLP_STATUS_OK;
+ }
+
+ /*
+ * FAN Indicators
+ *
+ * Green - Good
+ * Amber - Present but failed
+ * Off - Not present
+ */
+ for (i = FAN_1, j = LED_FAN1; i <= FAN_6; i++, j++)
+ {
+ if (onlp_fani_info_get(ONLP_FAN_ID_CREATE(i), &fan_info) != ONLP_STATUS_OK)
+ {
+ /* Get fan status fail */
+ led_mode = ONLP_LED_MODE_GREEN_BLINKING;
+ //status_led_mode = ONLP_LED_MODE_BLUE_BLINKING;
+ }
+ else if ((fan_info.status & ONLP_FAN_STATUS_PRESENT) == 0)
+ {
+ /* Not present -- Off */
+ led_mode = ONLP_LED_MODE_GREEN_BLINKING;
+ }
+ else if (fan_info.status & ONLP_FAN_STATUS_FAILED)
+ {
+ /* Present but Failed */
+ led_mode = ONLP_LED_MODE_GREEN_BLINKING;
+ //status_led_mode = ONLP_LED_MODE_BLUE_BLINKING;
+ }
+ else
+ {
+ led_mode = ONLP_LED_MODE_GREEN;
+ fan_ok_count++;
+ }
+
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(j), led_mode);
+ }
+
+ /*
+ * PSU Indicators, only one LED indicator for 2 PSUs.
+ */
+
+ if ((onlp_psui_info_get(ONLP_PSU_ID_CREATE(PSU1_ID), &psu1_info) != ONLP_STATUS_OK) ||
+ (onlp_psui_info_get(ONLP_PSU_ID_CREATE(PSU2_ID), &psu2_info) != ONLP_STATUS_OK))
+ {
+ /* Get PSU status fail */
+ led_mode = ONLP_LED_MODE_GREEN_BLINKING;
+ //status_led_mode = ONLP_LED_MODE_BLUE_BLINKING;
+ printf("%s:%d psu1_info.status:0x%08x, psu2_info.status:0x%08x\n", __FUNCTION__, __LINE__, psu1_info.status, psu2_info.status);
+ }
+ else if (((psu1_info.status & ONLP_PSU_STATUS_PRESENT) == 0) &&
+ ((psu2_info.status & ONLP_PSU_STATUS_PRESENT) == 0))
+ {
+ /* Not present */
+ led_mode = ONLP_LED_MODE_OFF;
+ }
+ else if ((psu1_info.status & ONLP_PSU_STATUS_FAILED) ||
+ (psu2_info.status & ONLP_PSU_STATUS_FAILED))
+ {
+ /* Present but Failed */
+ led_mode = ONLP_LED_MODE_GREEN_BLINKING;
+ //status_led_mode = ONLP_LED_MODE_BLUE_BLINKING;
+ printf("%s:%d psu1_info.status:0x%08x, psu2_info.status:0x%08x\n", __FUNCTION__, __LINE__, psu1_info.status, psu2_info.status);
+ }
+ else if ((psu1_info.status & ONLP_PSU_STATUS_UNPLUGGED) &&
+ (psu2_info.status & ONLP_PSU_STATUS_UNPLUGGED))
+ {
+ led_mode = ONLP_LED_MODE_GREEN_BLINKING;
+ }
+ else
+ {
+ led_mode = ONLP_LED_MODE_GREEN;
+ psu_ok_count = 2;
+ }
+
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_PWR), led_mode);
+
+
+ if (psu_ok_count == 2 && fan_ok_count == 6)
+ {
+ status_led_mode = ONLP_LED_MODE_OFF;
+ }
+
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_SERVICE), status_led_mode);
+
+ return ONLP_STATUS_OK;
+}
+
+int
+onlp_sysi_init(void)
+{
+ DIAG_PRINT("%s", __FUNCTION__);
+ return ONLP_STATUS_OK;
+}
+int onlp_sysi_debug_diag_fan_status(void)
+{
+ int oid = 0;
+ int i = 0;
+ uint32_t status = 0;
+ for (i = 1; i <= FAN_NUM_ON_MAIN_BROAD; i++)
+ {
+ oid = ONLP_FAN_ID_CREATE(i);
+ onlp_fani_status_get(oid, &status);
+ printf("FAN#%d oid:%d\n", i, oid);
+ printf("Status: 0x%x [%s %s]\n", status,
+ (status & ONLP_FAN_STATUS_PRESENT) ? "PRESENT" : "",
+ (status & ONLP_FAN_STATUS_FAILED) ? "FAILED" : "");
+ }
+ return 0;
+
+}
+
+int onlp_sysi_debug_diag_fan(void)
+{
+ onlp_fan_info_t fan_info;
+
+ printf("[Set fan speed to 10%% ...]\n");
+ onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(FAN_1), 10);
+ sleep(2);
+ onlp_fani_info_get(ONLP_FAN_ID_CREATE(FAN_1), &fan_info);
+ printf("FAN_1 fan_info.percentage = %d\n", fan_info.percentage);
+ printf("\n");
+ getchar();
+
+ printf("[Set fan speed to 30%% ...]\n");
+ onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(FAN_1), 30);
+ sleep(2);
+ onlp_fani_info_get(ONLP_FAN_ID_CREATE(FAN_1), &fan_info);
+ printf("FAN_1 fan_info.percentage = %d\n", fan_info.percentage);
+ printf("\n");
+ getchar();
+
+ printf("[Set fan speed to 50%% ...]\n");
+ onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(FAN_1), 50);
+ sleep(2);
+ onlp_fani_info_get(ONLP_FAN_ID_CREATE(FAN_1), &fan_info);
+ printf("FAN_1 fan_info.percentage = %d\n", fan_info.percentage);
+ printf("\n");
+ getchar();
+
+ printf("[Set fan speed to 70%% ...]\n");
+ onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(FAN_1), 70);
+ sleep(2);
+ onlp_fani_info_get(ONLP_FAN_ID_CREATE(FAN_1), &fan_info);
+ printf("FAN_1 fan_info.percentage = %d\n", fan_info.percentage);
+ printf("\n");
+ getchar();
+
+ printf("[Set fan speed to 100%% ...]\n");
+ onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(FAN_1), 100);
+ sleep(2);
+ onlp_fani_info_get(ONLP_FAN_ID_CREATE(FAN_1), &fan_info);
+ printf("FAN_1 fan_info.percentage = %d\n", fan_info.percentage);
+ printf("\n");
+ getchar();
+
+ printf("set fan speed to default(50%%) by onlp_fani_init()\n");
+ onlp_fani_init();
+ return 0;
+}
+
+int onlp_sysi_debug_diag_led(void)
+{
+
+
+ printf(" STACKING o o PSU \n");
+ printf(" FAN1~6 ----------- \n");
+ printf(" | o o | \n");
+ printf(" | o o | \n");
+ printf(" | o o | \n");
+ printf(" SERVICE o ----------- \n");
+
+
+ printf("[Stop platform manage ...]\n");
+#if 1
+ diag_debug_pause_platform_manage_on();
+#else
+ onlp_sys_platform_manage_stop(0);
+#endif
+ sleep(1);
+
+ printf("[Set All LED to OFF ...]\n");
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_SERVICE), ONLP_LED_MODE_OFF);
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_STACKING), ONLP_LED_MODE_OFF);
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_PWR), ONLP_LED_MODE_OFF);
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_FAN1), ONLP_LED_MODE_OFF);
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_FAN2), ONLP_LED_MODE_OFF);
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_FAN3), ONLP_LED_MODE_OFF);
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_FAN4), ONLP_LED_MODE_OFF);
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_FAN5), ONLP_LED_MODE_OFF);
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_FAN6), ONLP_LED_MODE_OFF);
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_REAR_FAN1), ONLP_LED_MODE_OFF);
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_REAR_FAN2), ONLP_LED_MODE_OFF);
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_REAR_FAN3), ONLP_LED_MODE_OFF);
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_REAR_FAN4), ONLP_LED_MODE_OFF);
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_REAR_FAN5), ONLP_LED_MODE_OFF);
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_REAR_FAN6), ONLP_LED_MODE_OFF);
+ printf("\n");
+ getchar();
+
+
+ printf("[Set SERVICE LED to ONLP_LED_MODE_BLUE ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_SERVICE), ONLP_LED_MODE_BLUE);
+ printf("\n");
+ getchar();
+ printf("[Set SERVICE LED to ONLP_LED_MODE_BLUE_BLINKING ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_SERVICE), ONLP_LED_MODE_BLUE_BLINKING);
+ printf("\n");
+ getchar();
+
+ printf("[Set STACKING LED to ONLP_LED_MODE_ORANGE ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_STACKING), ONLP_LED_MODE_ORANGE);
+ printf("\n");
+ getchar();
+ printf("[Set STACKING LED to ONLP_LED_MODE_ORANGE_BLINKING ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_STACKING), ONLP_LED_MODE_ORANGE_BLINKING);
+ printf("\n");
+ getchar();
+ printf("[Set STACKING LED to ONLP_LED_MODE_GREEN ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_STACKING), ONLP_LED_MODE_GREEN);
+ printf("\n");
+ getchar();
+ printf("[Set STACKING LED to ONLP_LED_MODE_GREEN_BLINKING ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_STACKING), ONLP_LED_MODE_GREEN_BLINKING);
+ printf("\n");
+ getchar();
+
+ printf("[Set PSU LED to ONLP_LED_MODE_ORANGE ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_PWR), ONLP_LED_MODE_ORANGE);
+ printf("\n");
+ getchar();
+ printf("[Set PSU LED to ONLP_LED_MODE_ORANGE_BLINKING ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_PWR), ONLP_LED_MODE_ORANGE_BLINKING);
+ printf("\n");
+ getchar();
+ printf("[Set PSU LED to ONLP_LED_MODE_GREEN ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_PWR), ONLP_LED_MODE_GREEN);
+ printf("\n");
+ getchar();
+ printf("[Set PSU LED to ONLP_LED_MODE_GREEN_BLINKING ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_PWR), ONLP_LED_MODE_GREEN_BLINKING);
+ printf("\n");
+ getchar();
+
+ printf("[Set FAN1 LED to ONLP_LED_MODE_ORANGE ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN1), ONLP_LED_MODE_ORANGE);
+ printf("\n");
+ getchar();
+ printf("[Set FAN1 LED to ONLP_LED_MODE_ORANGE_BLINKING ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN1), ONLP_LED_MODE_ORANGE_BLINKING);
+ printf("\n");
+ getchar();
+ printf("[Set FAN1 LED to ONLP_LED_MODE_GREEN ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN1), ONLP_LED_MODE_GREEN);
+ printf("\n");
+ getchar();
+ printf("[Set FAN1 LED to ONLP_LED_MODE_GREEN_BLINKING ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN1), ONLP_LED_MODE_GREEN_BLINKING);
+ printf("\n");
+ getchar();
+
+ printf("[Set FAN2 LED to ONLP_LED_MODE_ORANGE ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN2), ONLP_LED_MODE_ORANGE);
+ printf("\n");
+ getchar();
+ printf("[Set FAN2 LED to ONLP_LED_MODE_ORANGE_BLINKING ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN2), ONLP_LED_MODE_ORANGE_BLINKING);
+ printf("\n");
+ getchar();
+ printf("[Set FAN2 LED to ONLP_LED_MODE_GREEN ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN2), ONLP_LED_MODE_GREEN);
+ printf("\n");
+ getchar();
+ printf("[Set FAN2 LED to ONLP_LED_MODE_GREEN_BLINKING ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN2), ONLP_LED_MODE_GREEN_BLINKING);
+ printf("\n");
+ getchar();
+
+ printf("[Set FAN3 LED to ONLP_LED_MODE_ORANGE ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN3), ONLP_LED_MODE_ORANGE);
+ printf("\n");
+ getchar();
+ printf("[Set FAN3 LED to ONLP_LED_MODE_ORANGE_BLINKING ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN3), ONLP_LED_MODE_ORANGE_BLINKING);
+ printf("\n");
+ getchar();
+ printf("[Set FAN3 LED to ONLP_LED_MODE_GREEN ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN3), ONLP_LED_MODE_GREEN);
+ printf("\n");
+ getchar();
+ printf("[Set FAN3 LED to ONLP_LED_MODE_GREEN_BLINKING ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN3), ONLP_LED_MODE_GREEN_BLINKING);
+ printf("\n");
+ getchar();
+
+ printf("[Set FAN4 LED to ONLP_LED_MODE_ORANGE ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN4), ONLP_LED_MODE_ORANGE);
+ printf("\n");
+ getchar();
+ printf("[Set FAN4 LED to ONLP_LED_MODE_ORANGE_BLINKING ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN4), ONLP_LED_MODE_ORANGE_BLINKING);
+ printf("\n");
+ getchar();
+ printf("[Set FAN4 LED to ONLP_LED_MODE_GREEN ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN4), ONLP_LED_MODE_GREEN);
+ printf("\n");
+ getchar();
+ printf("[Set FAN4 LED to ONLP_LED_MODE_GREEN_BLINKING ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN4), ONLP_LED_MODE_GREEN_BLINKING);
+ printf("\n");
+ getchar();
+
+ printf("[Set FAN5 LED to ONLP_LED_MODE_ORANGE ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN5), ONLP_LED_MODE_ORANGE);
+ printf("\n");
+ getchar();
+ printf("[Set FAN5 LED to ONLP_LED_MODE_ORANGE_BLINKING ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN5), ONLP_LED_MODE_ORANGE_BLINKING);
+ printf("\n");
+ getchar();
+ printf("[Set FAN5 LED to ONLP_LED_MODE_GREEN ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN5), ONLP_LED_MODE_GREEN);
+ printf("\n");
+ getchar();
+ printf("[Set FAN5 LED to ONLP_LED_MODE_GREEN_BLINKING ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN5), ONLP_LED_MODE_GREEN_BLINKING);
+ printf("\n");
+ getchar();
+
+ printf("[Set FAN6 LED to ONLP_LED_MODE_ORANGE ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN6), ONLP_LED_MODE_ORANGE);
+ printf("\n");
+ getchar();
+ printf("[Set FAN6 LED to ONLP_LED_MODE_ORANGE_BLINKING ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN6), ONLP_LED_MODE_ORANGE_BLINKING);
+ printf("\n");
+ getchar();
+ printf("[Set FAN6 LED to ONLP_LED_MODE_GREEN ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN6), ONLP_LED_MODE_GREEN);
+ printf("\n");
+ getchar();
+ printf("[Set FAN6 LED to ONLP_LED_MODE_GREEN_BLINKING ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN6), ONLP_LED_MODE_GREEN_BLINKING);
+ printf("\n");
+ getchar();
+
+ printf("[Set REAR FAN1 LED to ONLP_LED_MODE_GREEN ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN1), ONLP_LED_MODE_GREEN);
+ printf("\n");
+ getchar();
+ printf("[Set REAR FAN1 LED to ONLP_LED_MODE_GREEN_BLINKING ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN1), ONLP_LED_MODE_GREEN_BLINKING);
+ printf("\n");
+ getchar();
+
+ printf("[Set REAR FAN2 LED to ONLP_LED_MODE_GREEN ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN2), ONLP_LED_MODE_GREEN);
+ printf("\n");
+ getchar();
+ printf("[Set REAR FAN2 LED to ONLP_LED_MODE_GREEN_BLINKING ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN2), ONLP_LED_MODE_GREEN_BLINKING);
+ printf("\n");
+ getchar();
+
+ printf("[Set REAR FAN3 LED to ONLP_LED_MODE_GREEN ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN3), ONLP_LED_MODE_GREEN);
+ printf("\n");
+ getchar();
+ printf("[Set REAR FAN3 LED to ONLP_LED_MODE_GREEN_BLINKING ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN3), ONLP_LED_MODE_GREEN_BLINKING);
+ printf("\n");
+ getchar();
+
+ printf("[Set REAR FAN4 LED to ONLP_LED_MODE_GREEN ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN4), ONLP_LED_MODE_GREEN);
+ printf("\n");
+ getchar();
+ printf("[Set REAR FAN4 LED to ONLP_LED_MODE_GREEN_BLINKING ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN4), ONLP_LED_MODE_GREEN_BLINKING);
+ printf("\n");
+ getchar();
+
+ printf("[Set REAR FAN5 LED to ONLP_LED_MODE_GREEN ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN5), ONLP_LED_MODE_GREEN);
+ printf("\n");
+ getchar();
+ printf("[Set REAR FAN5 LED to ONLP_LED_MODE_GREEN_BLINKING ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN5), ONLP_LED_MODE_GREEN_BLINKING);
+ printf("\n");
+ getchar();
+
+ printf("[Set REAR FAN6 LED to ONLP_LED_MODE_GREEN ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN6), ONLP_LED_MODE_GREEN);
+ printf("\n");
+ getchar();
+ printf("[Set REAR FAN6 LED to ONLP_LED_MODE_GREEN_BLINKING ...]\n");
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN6), ONLP_LED_MODE_GREEN_BLINKING);
+ printf("\n");
+ getchar();
+
+ printf("[Set All LED to OFF ...]\n");
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_SERVICE), ONLP_LED_MODE_OFF);
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_STACKING), ONLP_LED_MODE_OFF);
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_PWR), ONLP_LED_MODE_OFF);
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_FAN1), ONLP_LED_MODE_OFF);
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_FAN2), ONLP_LED_MODE_OFF);
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_FAN3), ONLP_LED_MODE_OFF);
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_FAN4), ONLP_LED_MODE_OFF);
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_FAN5), ONLP_LED_MODE_OFF);
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_FAN6), ONLP_LED_MODE_OFF);
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_REAR_FAN1), ONLP_LED_MODE_OFF);
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_REAR_FAN2), ONLP_LED_MODE_OFF);
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_REAR_FAN3), ONLP_LED_MODE_OFF);
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_REAR_FAN4), ONLP_LED_MODE_OFF);
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_REAR_FAN5), ONLP_LED_MODE_OFF);
+ onlp_ledi_set(ONLP_LED_ID_CREATE(LED_REAR_FAN6), ONLP_LED_MODE_OFF);
+
+ printf("[Restart platform manage ...]\n");
+ onlp_ledi_init();
+#if 1
+ diag_debug_pause_platform_manage_off();
+#else
+ onlp_sys_platform_manage_start(0);
+#endif
+ return 0;
+}
+
+#define SFP_DIAG_ADDR 114 //the reserved bytes 114~118 support r/w in SFF-8636 standard
+#define SFP_DIAG_PATTEN_B 0xAA
+#define SFP_DIAG_PATTEN_W 0xABCD
+
+int onlp_sysi_debug_diag_sfp(int index)
+{
+ uint8_t *data = NULL;
+ int rv = 0;
+
+ uint8_t org_b = 0;
+ uint16_t org_w = 0;
+ uint8_t temp_b = 0;
+ uint16_t temp_w = 0;
+
+ data = aim_zmalloc(256);
+ if ((rv = onlp_sfpi_eeprom_read(index, data)) < 0)
+ {
+
+ aim_printf(&aim_pvs_stdout, "Error reading eeprom: %{onlp_status}\n");
+ }
+ else
+ {
+ aim_printf(&aim_pvs_stdout, "dump eeprom:\n%{data}\n", data, 256);
+ }
+ aim_free(data);
+ data = NULL;
+
+//BYTE
+ printf("Read/Write byte test...\n");
+ org_b = onlp_sfpi_dev_readb(index, QSFP28_EEPROM_I2C_ADDR, SFP_DIAG_ADDR);
+ if (org_b < 0)
+ {
+ printf("Error, read failed!");
+ goto DONE;
+ }
+ rv = onlp_sfpi_dev_writeb(index, QSFP28_EEPROM_I2C_ADDR, SFP_DIAG_ADDR, SFP_DIAG_PATTEN_B);
+ if (rv < 0)
+ {
+ printf("Error, write failed!");
+ goto DONE;
+ }
+ sleep(2);
+ temp_b = onlp_sfpi_dev_readb(index, QSFP28_EEPROM_I2C_ADDR, SFP_DIAG_ADDR);
+ if (temp_b < 0)
+ {
+ printf("Error, read failed!");
+ goto DONE;
+ }
+ if (temp_b != SFP_DIAG_PATTEN_B)
+ {
+ printf("Error, mismatch!");
+ goto DONE;
+ }
+ rv = onlp_sfpi_dev_writeb(index, QSFP28_EEPROM_I2C_ADDR, SFP_DIAG_ADDR, org_b);
+ if (rv < 0)
+ {
+ printf("Error, write failed!");
+ goto DONE;
+ }
+ sleep(2);
+//WORD
+ printf("Read/Write word test...\n");
+ org_w = onlp_sfpi_dev_readw(index, QSFP28_EEPROM_I2C_ADDR, SFP_DIAG_ADDR);
+ if (org_w < 0)
+ {
+ printf("Error, read failed!");
+ goto DONE;
+ }
+ rv = onlp_sfpi_dev_writew(index, QSFP28_EEPROM_I2C_ADDR, SFP_DIAG_ADDR, SFP_DIAG_PATTEN_W);
+ if (rv < 0)
+ {
+ printf("Error, write failed!");
+ goto DONE;
+ }
+ sleep(2);
+ temp_w = onlp_sfpi_dev_readw(index, QSFP28_EEPROM_I2C_ADDR, SFP_DIAG_ADDR);
+ if (temp_w < 0)
+ {
+ printf("Error, read failed!");
+ goto DONE;
+ }
+ if (temp_w != SFP_DIAG_PATTEN_W)
+ {
+ printf("Error, mismatch!");
+ goto DONE;
+ }
+ rv = onlp_sfpi_dev_writew(index, QSFP28_EEPROM_I2C_ADDR, SFP_DIAG_ADDR, org_w);
+ if (rv < 0)
+ {
+ printf("Error, write failed!");
+ goto DONE;
+ }
+
+DONE:
+ return 0;
+}
+
+int onlp_sysi_debug_diag_sfp_dom(int index)
+{
+ uint8_t *data = NULL;
+ int rv = 0;
+
+ data = aim_zmalloc(256);
+ if ((rv = onlp_sfpi_dom_read(index, data)) < 0)
+ {
+
+ aim_printf(&aim_pvs_stdout, "Error reading dom eeprom: %{onlp_status}\n");
+ }
+ else
+ {
+ aim_printf(&aim_pvs_stdout, "dump DOM eeprom:\n%{data}\n", data, 256);
+ }
+ aim_free(data);
+ data = NULL;
+
+ return 0;
+}
+
+int onlp_sysi_debug_diag_sfp_ctrl(int index)
+{
+ int val = 0;
+
+ printf("[Option: %d(%s)... Set]\n", ONLP_SFP_CONTROL_RESET, sfp_control_to_str(ONLP_SFP_CONTROL_RESET));
+ printf("[Set %s...]\n", sfp_control_to_str(ONLP_SFP_CONTROL_RESET));
+ onlp_sfpi_control_set(index, ONLP_SFP_CONTROL_RESET, 1);
+ sleep(1);
+ printf("\n");
+ getchar();
+
+
+ printf("[Option: %d(%s)...Set/Get]\n", ONLP_SFP_CONTROL_RESET_STATE, sfp_control_to_str(ONLP_SFP_CONTROL_RESET_STATE));
+ printf("[Set %s... to 1]\n", sfp_control_to_str(ONLP_SFP_CONTROL_RESET_STATE));
+ onlp_sfpi_control_set(index, ONLP_SFP_CONTROL_RESET_STATE, 1);
+ sleep(1);
+ printf("[Get %s... ]\n", sfp_control_to_str(ONLP_SFP_CONTROL_RESET_STATE));
+ onlp_sfpi_control_get(index, ONLP_SFP_CONTROL_RESET_STATE, &val);
+ printf("\n");
+ getchar();
+
+ printf("[Set %s... to 0]\n", sfp_control_to_str(ONLP_SFP_CONTROL_RESET_STATE));
+ onlp_sfpi_control_set(index, ONLP_SFP_CONTROL_RESET_STATE, 0);
+ sleep(1);
+ printf("[Get %s... ]\n", sfp_control_to_str(ONLP_SFP_CONTROL_RESET_STATE));
+ onlp_sfpi_control_get(index, ONLP_SFP_CONTROL_RESET_STATE, &val);
+ printf("\n");
+ getchar();
+
+ printf("[Option: %d(%s)...Get]\n", ONLP_SFP_CONTROL_RX_LOS, sfp_control_to_str(ONLP_SFP_CONTROL_RX_LOS));
+ printf("[Get %s... ]\n", sfp_control_to_str(ONLP_SFP_CONTROL_RX_LOS));
+ onlp_sfpi_control_get(index, ONLP_SFP_CONTROL_RX_LOS, &val);
+ printf("\n");
+ getchar();
+
+ printf("[Option: %d(%s)...Get]\n", ONLP_SFP_CONTROL_TX_FAULT, sfp_control_to_str(ONLP_SFP_CONTROL_TX_FAULT));
+ printf("[Get %s... ]\n", sfp_control_to_str(ONLP_SFP_CONTROL_TX_FAULT));
+ onlp_sfpi_control_get(index, ONLP_SFP_CONTROL_TX_FAULT, &val);
+ printf("\n");
+ getchar();
+
+ printf("[Option: %d(%s)...Set/Get]\n", ONLP_SFP_CONTROL_TX_DISABLE, sfp_control_to_str(ONLP_SFP_CONTROL_TX_DISABLE));
+ printf("[Set %s... to 1]\n", sfp_control_to_str(ONLP_SFP_CONTROL_TX_DISABLE));
+ onlp_sfpi_control_set(index, ONLP_SFP_CONTROL_TX_DISABLE, 1);
+ sleep(1);
+ printf("[Get %s... ]\n", sfp_control_to_str(ONLP_SFP_CONTROL_TX_DISABLE));
+ onlp_sfpi_control_get(index, ONLP_SFP_CONTROL_TX_DISABLE, &val);
+ printf("\n");
+ getchar();
+
+ printf("[Set %s... to 0]\n", sfp_control_to_str(ONLP_SFP_CONTROL_TX_DISABLE));
+ onlp_sfpi_control_set(index, ONLP_SFP_CONTROL_TX_DISABLE, 0);
+ sleep(1);
+ printf("[Get %s... ]\n", sfp_control_to_str(ONLP_SFP_CONTROL_TX_DISABLE));
+ onlp_sfpi_control_get(index, ONLP_SFP_CONTROL_TX_DISABLE, &val);
+ printf("\n");
+ getchar();
+
+ printf("[Option: %d(%s)...Set/Get]\n", ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL, sfp_control_to_str(ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL));
+ printf("[Set %s... to 0x05]\n", sfp_control_to_str(ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL));
+ onlp_sfpi_control_set(index, ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL, 0x05);
+ sleep(1);
+ printf("[Get %s... ]\n", sfp_control_to_str(ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL));
+ onlp_sfpi_control_get(index, ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL, &val);
+ printf("\n");
+ getchar();
+
+ printf("[Set %s... to 0]\n", sfp_control_to_str(ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL));
+ onlp_sfpi_control_set(index, ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL, 0);
+ sleep(1);
+ printf("[Get %s... ]\n", sfp_control_to_str(ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL));
+ onlp_sfpi_control_get(index, ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL, &val);
+ printf("\n");
+ getchar();
+
+ printf("[Option: %d(%s)...Set/Get]\n", ONLP_SFP_CONTROL_LP_MODE, sfp_control_to_str(ONLP_SFP_CONTROL_LP_MODE));
+ printf("[Set %s... to 1]\n", sfp_control_to_str(ONLP_SFP_CONTROL_LP_MODE));
+ onlp_sfpi_control_set(index, ONLP_SFP_CONTROL_LP_MODE, 1);
+ sleep(1);
+ printf("[Get %s... ]\n", sfp_control_to_str(ONLP_SFP_CONTROL_LP_MODE));
+ onlp_sfpi_control_get(index, ONLP_SFP_CONTROL_LP_MODE, &val);
+ printf("\n");
+ getchar();
+
+ printf("[Set %s... to 0]\n", sfp_control_to_str(ONLP_SFP_CONTROL_LP_MODE));
+ onlp_sfpi_control_set(index, ONLP_SFP_CONTROL_LP_MODE, 0);
+ sleep(1);
+ printf("[Get %s... ]\n", sfp_control_to_str(ONLP_SFP_CONTROL_LP_MODE));
+ onlp_sfpi_control_get(index, ONLP_SFP_CONTROL_LP_MODE, &val);
+ printf("\n");
+ getchar();
+
+ printf("[Option: %d(%s)...Set/Get]\n", ONLP_SFP_CONTROL_POWER_OVERRIDE, sfp_control_to_str(ONLP_SFP_CONTROL_POWER_OVERRIDE));
+ printf("[Set %s... to 1]\n", sfp_control_to_str(ONLP_SFP_CONTROL_POWER_OVERRIDE));
+ onlp_sfpi_control_set(index, ONLP_SFP_CONTROL_POWER_OVERRIDE, 1);
+ sleep(1);
+ printf("[Get %s... ]\n", sfp_control_to_str(ONLP_SFP_CONTROL_POWER_OVERRIDE));
+ onlp_sfpi_control_get(index, ONLP_SFP_CONTROL_POWER_OVERRIDE, &val);
+ printf("\n");
+ getchar();
+
+ printf("[Set %s... to 0]\n", sfp_control_to_str(ONLP_SFP_CONTROL_POWER_OVERRIDE));
+ onlp_sfpi_control_set(index, ONLP_SFP_CONTROL_POWER_OVERRIDE, 0);
+ sleep(1);
+ printf("[Get %s... ]\n", sfp_control_to_str(ONLP_SFP_CONTROL_POWER_OVERRIDE));
+ onlp_sfpi_control_get(index, ONLP_SFP_CONTROL_POWER_OVERRIDE, &val);
+ printf("\n");
+ getchar();
+
+ return 0;
+}
+
+int
+onlp_sysi_debug(aim_pvs_t *pvs, int argc, char *argv[])
+{
+ int ret = 0;
+
+ /* ONLPI driver APIs debug */
+
+ if (argc > 0 && !strcmp(argv[0], "sys"))
+ {
+ diag_flag_set(DIAG_FLAG_ON);
+ printf("DIAG for SYS: \n");
+ printf("Platform : %s\n", onlp_sysi_platform_get());
+ onlp_sysi_init();
+ onlp_sysi_platform_manage_init();
+ diag_flag_set(DIAG_FLAG_OFF);
+ }
+ else if (argc > 0 && !strcmp(argv[0], "fan_rpm"))
+ {
+ onlp_fan_info_t fan_info;
+ int i = 0;
+ diag_flag_set(DIAG_FLAG_ON);
+ printf("DIAG for FAN rpm: \n");
+
+ int rpm = 0;
+ if (argc != 2)
+ {
+ printf("Parameter error, format: onlpdump debugi fan_rpm [RPM]\n");
+ return -1;
+ }
+ rpm = atoi(argv[1]);
+ onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(FAN_1), rpm);
+
+ sleep(5);
+ for (i = 1; i <= CHASSIS_FAN_COUNT; i++)
+ {
+ onlp_fani_info_get(ONLP_FAN_ID_CREATE(i), &fan_info);
+ printf("FAN#%d RPM:%d\n", i, fan_info.rpm);
+ }
+
+ diag_flag_set(DIAG_FLAG_OFF);
+ }
+ else if (argc > 0 && !strcmp(argv[0], "fan_status"))
+ {
+ diag_flag_set(DIAG_FLAG_ON);
+ printf("DIAG for FAN status: \n");
+ onlp_sysi_debug_diag_fan_status();
+ diag_flag_set(DIAG_FLAG_OFF);
+ }
+ else if (argc > 0 && !strcmp(argv[0], "fan"))
+ {
+ diag_flag_set(DIAG_FLAG_ON);
+ onlp_sysi_debug_diag_fan();
+ diag_flag_set(DIAG_FLAG_OFF);
+ }
+ else if (argc > 0 && !strcmp(argv[0], "psu"))
+ {
+ printf("DIAG for PSU: \n");
+ diag_flag_set(DIAG_FLAG_ON);
+ onlp_psui_init();
+ diag_flag_set(DIAG_FLAG_OFF);
+
+ }
+ else if (argc > 0 && !strcmp(argv[0], "led"))
+ {
+ printf("DIAG for LED: \n");
+ diag_flag_set(DIAG_FLAG_ON);
+ onlp_sysi_debug_diag_led();
+ diag_flag_set(DIAG_FLAG_OFF);
+ }
+ else if (argc > 0 && !strcmp(argv[0], "sfp_dom"))
+ {
+ int port_index = 0;
+ if (argc != 2)
+ {
+ printf("Parameter error, format: onlpdump debugi sfp_dom [PORT]\n");
+ return -1;
+ }
+ port_index = atoi(argv[1]);
+ if (port_index <= 0 || port_index > NUM_OF_SFP_PORT)
+ {
+ printf("Parameter error, PORT out of range.\n");
+ return -1;
+ }
+ printf("DIAG for SFP DOM #%d: \n", port_index - 1);
+ diag_flag_set(DIAG_FLAG_ON);
+ onlp_sysi_debug_diag_sfp_dom(port_index - 1);
+ diag_flag_set(DIAG_FLAG_OFF);
+ }
+ else if (argc > 0 && !strcmp(argv[0], "sfp_ctrl_set"))
+ {
+ int port_index = 0, ctrl = 0, val = 0;
+ if (argc != 4)
+ {
+ printf("Parameter error, format: onlpdump debugi sfp_ctrl_set [PORT] [CTRL] [VALUE]\n");
+ return -1;
+ }
+ port_index = atoi(argv[1]);
+ if (port_index <= 0 || port_index > NUM_OF_SFP_PORT)
+ {
+ printf("Parameter error, PORT out of range.\n");
+ return -1;
+ }
+ ctrl = atoi(argv[2]);
+ val = atoi(argv[3]);
+ diag_flag_set(DIAG_FLAG_ON);
+ onlp_sfpi_control_set(port_index - 1, ctrl, val);
+ diag_flag_set(DIAG_FLAG_OFF);
+
+ }
+ else if (argc > 0 && !strcmp(argv[0], "sfp_ctrl_get"))
+ {
+ int port_index = 0, ctrl = 0, val = 0;
+ if (argc != 3)
+ {
+ printf("Parameter error, format: onlpdump debugi sfp_ctrl_get [PORT] [CTRL] \n");
+ return -1;
+ }
+ port_index = atoi(argv[1]);
+ if (port_index <= 0 || port_index > NUM_OF_SFP_PORT)
+ {
+ printf("Parameter error, PORT out of range.\n");
+ return -1;
+ }
+ ctrl = atoi(argv[2]);
+ diag_flag_set(DIAG_FLAG_ON);
+ onlp_sfpi_control_get(port_index - 1, ctrl, &val);
+ printf("Value = %d(0x%X)\n", val, val);
+ diag_flag_set(DIAG_FLAG_OFF);
+
+ }
+ else if (argc > 0 && !strcmp(argv[0], "sfp_ctrl"))
+ {
+ int port_index = 0;
+ if (argc != 2)
+ {
+ printf("Parameter error, format: onlpdump debugi sfp_ctrl [PORT]\n");
+ return -1;
+ }
+ port_index = atoi(argv[1]);
+ if (port_index <= 0 || port_index > NUM_OF_SFP_PORT)
+ {
+ printf("Parameter error, PORT out of range.\n");
+ return -1;
+ }
+
+ printf("DIAG for SFP Control #%d: \n", port_index - 1);
+ diag_flag_set(DIAG_FLAG_ON);
+ onlp_sysi_debug_diag_sfp_ctrl(port_index - 1);
+ diag_flag_set(DIAG_FLAG_OFF);
+ }
+ else if (argc > 0 && !strcmp(argv[0], "sfp"))
+ {
+ if (argc > 1)
+ {
+ int port_index = atoi(argv[1]);
+ if (port_index <= 0 || port_index > NUM_OF_SFP_PORT)
+ {
+ printf("Parameter error, PORT out of range.\n");
+ return -1;
+ }
+ printf("DIAG for SFP#%d: \n", port_index - 1);
+ diag_flag_set(DIAG_FLAG_ON);
+ onlp_sysi_debug_diag_sfp(port_index - 1);
+ diag_flag_set(DIAG_FLAG_OFF);
+ }
+ else
+ {
+ printf("DIAG for SFP: \n");
+ onlp_sfp_bitmap_t bmap;
+ diag_flag_set(DIAG_FLAG_ON);
+
+ onlp_sfpi_denit();
+ onlp_sfpi_init();
+
+ onlp_sfp_bitmap_t_init(&bmap);
+ ret = onlp_sfpi_bitmap_get(&bmap);
+ if (ret < 0)
+ {
+ printf("Error, onlp_sfpi_bitmap_get failed!\n");
+ }
+ else
+ {
+ aim_printf(&aim_pvs_stdout, "sfp_bitmap:\n %{aim_bitmap}\n", &bmap);
+ }
+ diag_flag_set(DIAG_FLAG_OFF);
+
+ return 0;
+ }
+ }
+ else if (argc > 0 && !strcmp(argv[0], "sfpwb")) //write byte
+ {
+ int port;
+ uint8_t addr, value;
+
+ if (argc == 4)
+ {
+ port = atoi(argv[1]);
+ addr = (uint8_t)atoi(argv[2]);
+ value = (uint8_t)atoi(argv[3]);
+
+ if (port <= 0 || port > NUM_OF_SFP_PORT)
+ {
+ printf("Parameter error, PORT out of range.\n");
+ return -1;
+ }
+
+ diag_flag_set(DIAG_FLAG_ON);
+ onlp_sfpi_dev_writeb(port - 1, QSFP28_EEPROM_I2C_ADDR, addr, value);
+ diag_flag_set(DIAG_FLAG_OFF);
+ }
+ else
+ {
+ printf("Parameter error, format: onlpdump debugi sfpwb [PORT] [ADDR] [VALUE]\n");
+ return -1;
+ }
+
+ }
+ else if (argc > 0 && !strcmp(argv[0], "sfprb")) //read byte
+ {
+ int port;
+ uint8_t addr;
+ if (argc == 3)
+ {
+ port = atoi(argv[1]);
+ addr = (uint8_t)atoi(argv[2]);
+
+ if (port <= 0 || port > NUM_OF_SFP_PORT)
+ {
+ printf("Parameter error, PORT out of range.\n");
+ return -1;
+ }
+
+ diag_flag_set(DIAG_FLAG_ON);
+ onlp_sfpi_dev_readb(port - 1, QSFP28_EEPROM_I2C_ADDR, addr);
+ diag_flag_set(DIAG_FLAG_OFF);
+ }
+ else
+ {
+ printf("Parameter error, format: onlpdump debugi sfprb [PORT] [ADDR]\n");
+ return -1;
+ }
+ }
+ else if (argc > 0 && !strcmp(argv[0], "sfpww")) //write word
+ {
+ int port;
+ uint16_t value;
+ uint8_t addr;
+
+ if (argc == 4)
+ {
+ port = atoi(argv[1]);
+ addr = (uint8_t)atoi(argv[2]);
+ value = (uint16_t)atoi(argv[3]);
+
+ if (port <= 0 || port > NUM_OF_SFP_PORT)
+ {
+ printf("Parameter error, PORT out of range.\n");
+ return -1;
+ }
+
+ diag_flag_set(DIAG_FLAG_ON);
+ onlp_sfpi_dev_writew(port - 1, QSFP28_EEPROM_I2C_ADDR, addr, value);
+ diag_flag_set(DIAG_FLAG_OFF);
+ }
+ else
+ {
+ printf("Parameter error, format: onlpdump debugi sfpwb [PORT] [ADDR] [VALUE]\n");
+ return -1;
+ }
+ }
+ else if (argc > 0 && !strcmp(argv[0], "sfprw")) //read word
+ {
+ int port;
+ uint8_t addr;
+ if (argc == 3)
+ {
+ port = atoi(argv[1]);
+ addr = (uint8_t)atoi(argv[2]);
+
+ if (port <= 0 || port > NUM_OF_SFP_PORT)
+ {
+ printf("Parameter error, PORT out of range.\n");
+ return -1;
+ }
+
+ diag_flag_set(DIAG_FLAG_ON);
+ onlp_sfpi_dev_readw(port - 1, QSFP28_EEPROM_I2C_ADDR, addr);
+ diag_flag_set(DIAG_FLAG_OFF);
+ }
+ else
+ {
+ printf("Parameter error, format: onlpdump debugi sfprb [PORT] [ADDR]\n");
+ return -1;
+ }
+ }
+ else if (argc > 0 && !strcmp(argv[0], "thermal"))
+ {
+ printf("DIAG for Thermal: \n");
+ diag_flag_set(DIAG_FLAG_ON);
+ onlp_thermali_init();
+ diag_flag_set(DIAG_FLAG_OFF);
+ }
+ else if (argc > 0 && !strcmp(argv[0], "trace_on"))
+ {
+ diag_debug_trace_on();
+ DIAG_PRINT("%s, ONLPI TRACE: ON", __FUNCTION__);
+ }
+ else if (argc > 0 && !strcmp(argv[0], "trace_off"))
+ {
+ diag_debug_trace_off();
+ DIAG_PRINT("%s, ONLPI TRACE: OFF", __FUNCTION__);
+ }
+ else if (argc > 0 && !strcmp(argv[0], "help"))
+ {
+ printf("\nUsage: onlpdump debugi [OPTION]\n");
+ printf(" help : this message.\n");
+ printf(" trace_on : turn on ONLPI debug trace message output on screen.\n");
+ printf(" trace_off : turn off ONLPI debug trace message output on screen.\n");
+ printf(" sys : run system ONLPI diagnostic function.\n");
+ printf(" fan : run fan ONLPI diagnostic function.\n");
+ printf(" fan_status : run fan status ONLPI diagnostic function.\n");
+ printf(" fan_rpm : run fan RPM ONLPI diagnostic function.\n");
+ printf(" led : run LED ONLPI diagnostic function.\n");
+ printf(" psu : run psu ONLPI diagnostic function.\n");
+ printf(" thermal : run thermal ONLPI diagnostic function.\n");
+ printf(" sfp : run sfp ONLPI diagnostic function.\n");
+ printf(" sfp [PORT] : run sfp ONLPI diagnostic function.\n");
+ printf(" sfp_dom [PORT] : run sfp dom ONLPI diagnostic function.\n");
+ printf(" sfp_ctrl [PORT] : run sfp control ONLPI diagnostic function.\n");
+
+ printf(" (Warning! Please be careful to write a value to SFP,\n");
+ printf(" you should keep the original value to prevent lose it forever.)\n");
+ printf(" sfprb [PORT] [ADDR] : read a byte from sfp transeciver.\n");
+ printf(" sfprw [PORT] [ADDR] : read a word from sfp transeciver.\n");
+ printf(" sfpwb [PORT] [ADDR] [VALUE] : write a byte to sfp transeciver.\n");
+ printf(" sfpww [PORT] [ADDR] [VALUE] : write a word to sfp transeciver.\n");
+
+ printf(" [PORT] is the port index start from 0.\n");
+ printf(" [ADDR] is the address to read/write.\n");
+ printf(" [VALUE] is the value to read/write.\n");
+
+
+ }
+ else if (argc > 0 && !strcmp(argv[0], "test")) //for RD debug test
+ {
+ diag_flag_set(DIAG_FLAG_ON);
+ onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_SERVICE), ONLP_LED_MODE_BLUE_BLINKING);
+ }
+ else
+ {}
+
+ return 0;
+}
+
+
+
+
+
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/thermali.c b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/thermali.c
new file mode 100644
index 00000000..65eef3cb
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/thermali.c
@@ -0,0 +1,149 @@
+/************************************************************
+ *
+ *
+ * Copyright 2014, 2015 Big Switch Networks, Inc.
+ * Copyright 2018 Alpha Networks Incorporation
+ *
+ * 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
+#include
+#include
+#include "platform_lib.h"
+
+#define LOCAL_DEBUG 0
+
+#define THERMALI_LM75_HOT_SPOT_ADDR 0x4d /* NE10032 thermal addr */
+#define THERMALI_LM75_AMBIENT_ADDR 0x4c /* NE10032 thermal addr */
+
+#define THERMALI_HOTSPOT_BUS_ID 3
+#define THERMALI_AMBIENT_BUS_ID 4
+
+#define THERMALI_BUS_ID_OFFSET 2
+
+
+#define VALIDATE(_id) \
+ do { \
+ if(!ONLP_OID_IS_THERMAL(_id)) { \
+ return ONLP_STATUS_E_INVALID; \
+ } \
+ } while(0)
+
+
+
+
+enum onlp_thermal_id
+{
+ THERMAL_RESERVED = 0,
+ THERMAL_1_ON_MAIN_BROAD_HOT_SPOT, /* The LM75 on Main Board for hot spot */
+ THERMAL_2_ON_MAIN_BROAD_AMBIENT /* The LM75 on Main Board for ambient */
+};
+
+static int thermali_current_temp_get(int id, char *data)
+{
+ int ret = 0;
+ if (id == THERMALI_HOTSPOT_BUS_ID)
+ {
+ ret = i2c_read_byte(id, THERMALI_LM75_HOT_SPOT_ADDR, 0x0, data);
+ if (ret < 0)
+ printf("I2C command 0x%X Read Fail, id=%d\n", THERMALI_LM75_HOT_SPOT_ADDR, id);
+ }
+ else if (id == THERMALI_AMBIENT_BUS_ID)
+ {
+ ret = i2c_read_byte(id, THERMALI_LM75_AMBIENT_ADDR, 0x0, data);
+ if (ret < 0)
+ printf("I2C command 0x%X Read Fail, id=%d\n", THERMALI_LM75_AMBIENT_ADDR, id);
+ }
+
+ return ret;
+}
+
+
+/* Static values */
+static onlp_thermal_info_t linfo[] = {
+ { }, /* Not used */
+ { { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_MAIN_BROAD_HOT_SPOT), "Chassis Thermal Sensor 1 (HOT SPOT)", 0 },
+ ONLP_THERMAL_STATUS_PRESENT,
+ ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS
+ },
+ { { ONLP_THERMAL_ID_CREATE(THERMAL_2_ON_MAIN_BROAD_AMBIENT), "Chassis Thermal Sensor 2 (AMBIENT)", 0 },
+ ONLP_THERMAL_STATUS_PRESENT,
+ ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS
+ }
+};
+
+
+/*
+ * This will be called to intiialize the thermali subsystem.
+ */
+int
+onlp_thermali_init(void)
+{
+ DIAG_PRINT("%s", __FUNCTION__);
+ 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)
+{
+ DIAG_PRINT("%s, id=%d", __FUNCTION__, id);
+ int local_id, milli_unit = 1000;
+ char r_data[10] = { 0 };
+ VALIDATE(id);
+
+ local_id = ONLP_OID_ID_GET(id);
+
+ if (LOCAL_DEBUG)
+ printf("\n[Debug][%s][%d][local_id: %d]", __FUNCTION__, __LINE__, local_id);
+
+ /* Set the onlp_oid_hdr_t and capabilities */
+ *info = linfo[local_id];
+#if 0
+ if(local_id == THERMAL_CPU_CORE)
+ {
+ int rv = onlp_file_read_int_max(&info->mcelsius, cpu_coretemp_files);
+ return rv;
+ }
+#endif
+ if (thermali_current_temp_get(local_id + THERMALI_BUS_ID_OFFSET, r_data) < 0)
+ printf("[thermali]get current temperature fail!\n");
+
+ info->mcelsius = (*r_data) * milli_unit;
+
+ if (LOCAL_DEBUG)
+ printf("\n[Debug][%s][%d][save data: %d]\n", __FUNCTION__, __LINE__, info->mcelsius);
+
+ return ONLP_STATUS_OK;
+}
+
+
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/x86_64_lenovo_ne10032_config.c b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/x86_64_lenovo_ne10032_config.c
new file mode 100644
index 00000000..f6c2c653
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/x86_64_lenovo_ne10032_config.c
@@ -0,0 +1,76 @@
+/**************************************************************************//**
+ *
+ *
+ *
+ *****************************************************************************/
+#include
+
+/* */
+#define __x86_64_lenovo_ne10032_config_STRINGIFY_NAME(_x) #_x
+#define __x86_64_lenovo_ne10032_config_STRINGIFY_VALUE(_x) __x86_64_lenovo_ne10032_config_STRINGIFY_NAME(_x)
+x86_64_lenovo_ne10032_config_settings_t x86_64_lenovo_ne10032_config_settings[] =
+{
+#ifdef X86_64_LENOVO_NE10032_CONFIG_INCLUDE_LOGGING
+ { __x86_64_lenovo_ne10032_config_STRINGIFY_NAME(X86_64_LENOVO_NE10032_CONFIG_INCLUDE_LOGGING), __x86_64_lenovo_ne10032_config_STRINGIFY_VALUE(X86_64_LENOVO_NE10032_CONFIG_INCLUDE_LOGGING) },
+#else
+{ X86_64_LENOVO_NE10032_CONFIG_INCLUDE_LOGGING(__x86_64_lenovo_ne10032_config_STRINGIFY_NAME), "__undefined__" },
+#endif
+#ifdef X86_64_LENOVO_NE10032_CONFIG_LOG_OPTIONS_DEFAULT
+ { __x86_64_lenovo_ne10032_config_STRINGIFY_NAME(X86_64_LENOVO_NE10032_CONFIG_LOG_OPTIONS_DEFAULT), __x86_64_lenovo_ne10032_config_STRINGIFY_VALUE(X86_64_LENOVO_NE10032_CONFIG_LOG_OPTIONS_DEFAULT) },
+#else
+{ X86_64_LENOVO_NE10032_CONFIG_LOG_OPTIONS_DEFAULT(__x86_64_lenovo_ne10032_config_STRINGIFY_NAME), "__undefined__" },
+#endif
+#ifdef X86_64_LENOVO_NE10032_CONFIG_LOG_BITS_DEFAULT
+ { __x86_64_lenovo_ne10032_config_STRINGIFY_NAME(X86_64_LENOVO_NE10032_CONFIG_LOG_BITS_DEFAULT), __x86_64_lenovo_ne10032_config_STRINGIFY_VALUE(X86_64_LENOVO_NE10032_CONFIG_LOG_BITS_DEFAULT) },
+#else
+{ X86_64_LENOVO_NE10032_CONFIG_LOG_BITS_DEFAULT(__x86_64_lenovo_ne10032_config_STRINGIFY_NAME), "__undefined__" },
+#endif
+#ifdef X86_64_LENOVO_NE10032_CONFIG_LOG_CUSTOM_BITS_DEFAULT
+ { __x86_64_lenovo_ne10032_config_STRINGIFY_NAME(X86_64_LENOVO_NE10032_CONFIG_LOG_CUSTOM_BITS_DEFAULT), __x86_64_lenovo_ne10032_config_STRINGIFY_VALUE(X86_64_LENOVO_NE10032_CONFIG_LOG_CUSTOM_BITS_DEFAULT) },
+#else
+{ X86_64_LENOVO_NE10032_CONFIG_LOG_CUSTOM_BITS_DEFAULT(__x86_64_lenovo_ne10032_config_STRINGIFY_NAME), "__undefined__" },
+#endif
+#ifdef X86_64_LENOVO_NE10032_CONFIG_PORTING_STDLIB
+ { __x86_64_lenovo_ne10032_config_STRINGIFY_NAME(X86_64_LENOVO_NE10032_CONFIG_PORTING_STDLIB), __x86_64_lenovo_ne10032_config_STRINGIFY_VALUE(X86_64_LENOVO_NE10032_CONFIG_PORTING_STDLIB) },
+#else
+{ X86_64_LENOVO_NE10032_CONFIG_PORTING_STDLIB(__x86_64_lenovo_ne10032_config_STRINGIFY_NAME), "__undefined__" },
+#endif
+#ifdef X86_64_LENOVO_NE10032_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS
+ { __x86_64_lenovo_ne10032_config_STRINGIFY_NAME(X86_64_LENOVO_NE10032_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS), __x86_64_lenovo_ne10032_config_STRINGIFY_VALUE(X86_64_LENOVO_NE10032_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS) },
+#else
+{ X86_64_LENOVO_NE10032_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS(__x86_64_lenovo_ne10032_config_STRINGIFY_NAME), "__undefined__" },
+#endif
+#ifdef X86_64_LENOVO_NE10032_CONFIG_INCLUDE_UCLI
+ { __x86_64_lenovo_ne10032_config_STRINGIFY_NAME(X86_64_LENOVO_NE10032_CONFIG_INCLUDE_UCLI), __x86_64_lenovo_ne10032_config_STRINGIFY_VALUE(X86_64_LENOVO_NE10032_CONFIG_INCLUDE_UCLI) },
+#else
+{ X86_64_LENOVO_NE10032_CONFIG_INCLUDE_UCLI(__x86_64_lenovo_ne10032_config_STRINGIFY_NAME), "__undefined__" },
+#endif
+ { NULL, NULL }
+};
+#undef __x86_64_lenovo_ne10032_config_STRINGIFY_VALUE
+#undef __x86_64_lenovo_ne10032_config_STRINGIFY_NAME
+
+const char*
+x86_64_lenovo_ne10032_config_lookup(const char* setting)
+{
+ int i;
+ for(i = 0; x86_64_lenovo_ne10032_config_settings[i].name; i++) {
+ if(strcmp(x86_64_lenovo_ne10032_config_settings[i].name, setting)) {
+ return x86_64_lenovo_ne10032_config_settings[i].value;
+ }
+ }
+ return NULL;
+}
+
+int
+x86_64_lenovo_ne10032_config_show(struct aim_pvs_s* pvs)
+{
+ int i;
+ for(i = 0; x86_64_lenovo_ne10032_config_settings[i].name; i++) {
+ aim_printf(pvs, "%s = %s\n", x86_64_lenovo_ne10032_config_settings[i].name, x86_64_lenovo_ne10032_config_settings[i].value);
+ }
+ return i;
+}
+
+/* */
+
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/x86_64_lenovo_ne10032_enums.c b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/x86_64_lenovo_ne10032_enums.c
new file mode 100644
index 00000000..0230218d
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/x86_64_lenovo_ne10032_enums.c
@@ -0,0 +1,10 @@
+/**************************************************************************//**
+ *
+ *
+ *
+ *****************************************************************************/
+#include
+
+/* <--auto.start.enum(ALL).source> */
+/* */
+
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/x86_64_lenovo_ne10032_int.h b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/x86_64_lenovo_ne10032_int.h
new file mode 100644
index 00000000..3c22bcaa
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/x86_64_lenovo_ne10032_int.h
@@ -0,0 +1,12 @@
+/**************************************************************************//**
+ *
+ * x86_64_lenovo_ne10032 Internal Header
+ *
+ *****************************************************************************/
+#ifndef __X86_64_LENOVO_NE10032_INT_H__
+#define __X86_64_LENOVO_NE10032_INT_H__
+
+#include
+
+
+#endif /* __X86_64_LENOVO_NE10032_INT_H__ */
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/x86_64_lenovo_ne10032_log.c b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/x86_64_lenovo_ne10032_log.c
new file mode 100644
index 00000000..c097cc07
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/x86_64_lenovo_ne10032_log.c
@@ -0,0 +1,18 @@
+/**************************************************************************//**
+ *
+ *
+ *
+ *****************************************************************************/
+#include
+
+#include "x86_64_lenovo_ne10032_log.h"
+/*
+ * x86_64_lenovo_ne10032 log struct.
+ */
+AIM_LOG_STRUCT_DEFINE(
+ X86_64_LENOVO_NE10032_CONFIG_LOG_OPTIONS_DEFAULT,
+ X86_64_LENOVO_NE10032_CONFIG_LOG_BITS_DEFAULT,
+ NULL, /* Custom log map */
+ X86_64_LENOVO_NE10032_CONFIG_LOG_CUSTOM_BITS_DEFAULT
+ );
+
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/x86_64_lenovo_ne10032_log.h b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/x86_64_lenovo_ne10032_log.h
new file mode 100644
index 00000000..57587952
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/x86_64_lenovo_ne10032_log.h
@@ -0,0 +1,12 @@
+/**************************************************************************//**
+ *
+ *
+ *
+ *****************************************************************************/
+#ifndef __X86_64_LENOVO_NE10032_LOG_H__
+#define __X86_64_LENOVO_NE10032_LOG_H__
+
+#define AIM_LOG_MODULE_NAME x86_64_lenovo_ne10032
+#include
+
+#endif /* __X86_64_LENOVO_NE10032_LOG_H__ */
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/x86_64_lenovo_ne10032_module.c b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/x86_64_lenovo_ne10032_module.c
new file mode 100644
index 00000000..ea57305f
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/x86_64_lenovo_ne10032_module.c
@@ -0,0 +1,24 @@
+/**************************************************************************//**
+ *
+ *
+ *
+ *****************************************************************************/
+#include
+
+#include "x86_64_lenovo_ne10032_log.h"
+
+static int
+datatypes_init__(void)
+{
+#define X86_64_LENOVO_NE10032_ENUMERATION_ENTRY(_enum_name, _desc) AIM_DATATYPE_MAP_REGISTER(_enum_name, _enum_name##_map, _desc, AIM_LOG_INTERNAL);
+#include
+ return 0;
+}
+
+void __x86_64_lenovo_ne10032_module_init__(void)
+{
+ AIM_LOG_STRUCT_REGISTER();
+ datatypes_init__();
+}
+
+int __onlp_platform_version__ = 1;
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/x86_64_lenovo_ne10032_ucli.c b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/x86_64_lenovo_ne10032_ucli.c
new file mode 100644
index 00000000..9c4c6625
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/onlp/builds/src/module/src/x86_64_lenovo_ne10032_ucli.c
@@ -0,0 +1,50 @@
+/**************************************************************************//**
+ *
+ *
+ *
+ *****************************************************************************/
+#include
+
+#if X86_64_LENOVO_NE10032_CONFIG_INCLUDE_UCLI == 1
+
+#include
+#include
+#include
+
+static ucli_status_t
+x86_64_lenovo_ne10032_ucli_ucli__config__(ucli_context_t* uc)
+{
+ UCLI_HANDLER_MACRO_MODULE_CONFIG(x86_64_lenovo_ne10032)
+}
+
+/* */
+/* */
+
+static ucli_module_t
+x86_64_lenovo_ne10032_ucli_module__ =
+ {
+ "x86_64_lenovo_ne10032_ucli",
+ NULL,
+ x86_64_lenovo_ne10032_ucli_ucli_handlers__,
+ NULL,
+ NULL,
+ };
+
+ucli_node_t*
+x86_64_lenovo_ne10032_ucli_node_create(void)
+{
+ ucli_node_t* n;
+ ucli_module_init(&x86_64_lenovo_ne10032_ucli_module__);
+ n = ucli_node_create("x86_64_lenovo_ne10032", NULL, &x86_64_lenovo_ne10032_ucli_module__);
+ ucli_node_subnode_add(n, ucli_module_log_node_create("x86_64_lenovo_ne10032"));
+ return n;
+}
+
+#else
+void*
+x86_64_lenovo_ne10032_ucli_node_create(void)
+{
+ return NULL;
+}
+#endif
+
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/platform-config/Makefile b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/platform-config/Makefile
new file mode 100644
index 00000000..003238cf
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/platform-config/Makefile
@@ -0,0 +1 @@
+include $(ONL)/make/pkg.mk
\ No newline at end of file
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/platform-config/r0/Makefile b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/platform-config/r0/Makefile
new file mode 100644
index 00000000..003238cf
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/platform-config/r0/Makefile
@@ -0,0 +1 @@
+include $(ONL)/make/pkg.mk
\ No newline at end of file
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/platform-config/r0/PKG.yml b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/platform-config/r0/PKG.yml
new file mode 100644
index 00000000..98029a7e
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/platform-config/r0/PKG.yml
@@ -0,0 +1 @@
+!include $ONL_TEMPLATES/platform-config-platform.yml ARCH=amd64 VENDOR=lenovo BASENAME=x86-64-lenovo-ne10032 REVISION=r0
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/platform-config/r0/src/lib/x86-64-lenovo-ne10032-r0.yml b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/platform-config/r0/src/lib/x86-64-lenovo-ne10032-r0.yml
new file mode 100644
index 00000000..c5b14f68
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/platform-config/r0/src/lib/x86-64-lenovo-ne10032-r0.yml
@@ -0,0 +1,32 @@
+---
+
+######################################################################
+#
+# platform-config for NE10032
+#
+######################################################################
+
+x86-64-lenovo-ne10032-r0:
+
+ grub:
+
+ serial: >-
+ --port=0x2f8
+ --speed=115200
+ --word=8
+ --parity=no
+ --stop=1
+
+ kernel:
+ <<: *kernel-3-16
+
+ args: >-
+ nopat
+ i2c-ismt.enable=0
+ console=ttyS1,115200n8
+
+ ##network
+ ## interfaces:
+ ## ma1:
+ ## name: ~
+ ## syspath: pci0000:00/0000:00:14.0
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/platform-config/r0/src/lib/x86-64-lenovo-ne10032-r0.yml.bak b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/platform-config/r0/src/lib/x86-64-lenovo-ne10032-r0.yml.bak
new file mode 100644
index 00000000..205d25de
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/platform-config/r0/src/lib/x86-64-lenovo-ne10032-r0.yml.bak
@@ -0,0 +1,31 @@
+---
+
+######################################################################
+#
+# platform-config for NE10032
+#
+######################################################################
+
+x86-64-lenovo-ne10032-r0:
+
+ grub:
+
+ serial: >-
+ --port=0x2f8
+ --speed=115200
+ --word=8
+ --parity=no
+ --stop=1
+
+ kernel:
+ <<: *kernel-3-18
+
+ args: >-
+ nopat
+ console=ttyS1,115200n8
+
+ ##network
+ ## interfaces:
+ ## ma1:
+ ## name: ~
+ ## syspath: pci0000:00/0000:00:14.0
diff --git a/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/platform-config/r0/src/python/x86_64_lenovo_ne10032_r0/__init__.py b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/platform-config/r0/src/python/x86_64_lenovo_ne10032_r0/__init__.py
new file mode 100644
index 00000000..a529596e
--- /dev/null
+++ b/packages/platforms/lenovo/x86-64/x86_64_lenovo_ne10032/platform-config/r0/src/python/x86_64_lenovo_ne10032_r0/__init__.py
@@ -0,0 +1,116 @@
+from onl.platform.base import *
+from onl.platform.lenovo import *
+
+class OnlPlatform_x86_64_lenovo_ne10032_r0(OnlPlatformLenovo,
+ OnlPlatformPortConfig_32x100):
+ PLATFORM='x86-64-lenovo-ne10032-r0'
+ MODEL="NE10032"
+ SYS_OBJECT_ID=".6010.32"
+
+ def baseconfig(self):
+ ########### initialize I2C bus 0 ###########
+ self.new_i2c_devices([
+
+ # ONIE EEPROM @MB
+ ('24c128', 0x56, 0),
+
+ # PowerCPLD @MB
+ ('cpld', 0x5E, 0),
+
+ # initialize multiplexer (PCA9548 #0)
+ ('pca9548', 0x70, 0),
+
+ # FRU EEROM @MB
+ ('24c512', 0x51, 1),
+
+ # CFG EEROM @MB
+ ('24c02', 0x51, 2),
+
+ # TMP75#1 (Hot Spot) #use lm75 will cause device busy, use other name
+ ('thermal1', 0x4D, 3),
+
+ # TMP75#0 (Ambient) #use lm75 will cause device busy, use other name
+ ('thermal2', 0x4C, 4),
+
+ # initialize multiplexer (PCA9545 #0)
+ ('pca9545', 0x71, 5),
+
+ # IDT 5P49V5923A (Clock generator)
+ (' ', 0x6A, 6),
+
+ # initialize multiplexer (PCA9548 #1)
+ ('pca9548', 0x72, 7),
+
+ # SystemCPLD @MB
+ ('cpld', 0x5F, 8),
+
+ ])
+
+ ########### initialize I2C bus PCA9545 #0 ###########
+ self.new_i2c_devices(
+ [
+ # MGMT EEROM
+ ('24c02', 0x51, 9),
+ # PSU #0
+ ('psu', 0x51, 10),
+ ('psu', 0x59, 10),
+ # PSU #1
+ ('psu', 0x51, 11),
+ ('psu', 0x59, 11),
+ # reserved
+ ])
+
+ ########### initialize I2C bus PCA9548 #1 ###########
+ self.new_i2c_devices(
+ [
+ # IR3595
+ ('ir3595', 0x09, 18),
+
+ # reserved
+
+ # initialize multiplexer (PCA9548 #1)
+ ('pca9548', 0x73, 20),
+ ])
+
+
+ ########### initialize I2C bus PCA9548 #2 @Fan Expander ###########
+ self.new_i2c_devices(
+ [
+ # Fan EEROM
+ ('24c02', 0x57, 21),
+ # Fan EEROM
+ ('24c02', 0x57, 22),
+ # Fan EEROM
+ ('24c02', 0x57, 23),
+ # Fan EEROM
+ ('24c02', 0x57, 24),
+ # Fan EEROM
+ ('24c02', 0x57, 25),
+ # Fan EEROM
+ ('24c02', 0x57, 26),
+
+ ])
+
+
+ # initialize QSFP port 1~32
+ self.new_i2c_devices([
+
+ ('QSFP28', 0x50, 13),
+ ('QSFP28', 0x50, 14),
+ ('QSFP28', 0x50, 15),
+ ('QSFP28', 0x50, 16),
+
+ (' ', 0x68, 13),
+ (' ', 0x68, 14),
+ (' ', 0x68, 15),
+ (' ', 0x68, 16),
+
+ # Port CPLD0~3
+ ('cpld', 0x5F, 13),
+ ('cpld', 0x5F, 14),
+ ('cpld', 0x5F, 15),
+ ('cpld', 0x5F, 16),
+
+ ])
+
+ return True