From 8bbb80fc12c8c6702384dc928c8dbde2326f08fb Mon Sep 17 00:00:00 2001 From: vincent_chiang Date: Thu, 30 Apr 2026 03:24:49 +0000 Subject: [PATCH] [AS9726-32D] Add new platform (port from support_linux_6.1, kernel 4.19) Port the AS9726-32D platform from the support_linux_6.1 branch to support_new_platform_and_sync, targeting kernel 4.19 LTS. Driver adaptations for kernel 4.19: - i2c_driver remove() returns int (was void in 6.1) - Drop hwmon_chip_info / HWMON_CHANNEL_INFO usage (added in 5.5); pass NULL chip_info to hwmon_device_register_with_info() to match the existing as9716_32d / as9926-24db pattern on this branch. - modules/PKG.yml, modules/builds/Makefile and platform-config yml switched from kernel-6.1 to kernel-4.19 anchors. Verified by building modules + onlp + platform-config debs and the full amd64 INSTALLER. --- .../accton/x86-64/as9726-32d/.gitignore | 3 + .../accton/x86-64/as9726-32d/Makefile | 1 + .../accton/x86-64/as9726-32d/modules/Makefile | 1 + .../accton/x86-64/as9726-32d/modules/PKG.yml | 1 + .../as9726-32d/modules/builds/.gitignore | 1 + .../x86-64/as9726-32d/modules/builds/Makefile | 6 + .../as9726-32d/modules/builds/src/Makefile | 4 + .../src/x86-64-accton-as9726-32d-cpld.c | 1164 ++++++++++++++ .../builds/src/x86-64-accton-as9726-32d-fan.c | 529 ++++++ .../src/x86-64-accton-as9726-32d-leds.c | 456 ++++++ .../builds/src/x86-64-accton-as9726-32d-psu.c | 261 +++ .../accton/x86-64/as9726-32d/onlp/Makefile | 1 + .../accton/x86-64/as9726-32d/onlp/PKG.yml | 1 + .../x86-64/as9726-32d/onlp/builds/Makefile | 2 + .../as9726-32d/onlp/builds/lib/Makefile | 2 + .../as9726-32d/onlp/builds/onlpdump/Makefile | 2 + .../x86_64_accton_as9726_32d/.gitignore | 1 + .../builds/x86_64_accton_as9726_32d/.module | 1 + .../builds/x86_64_accton_as9726_32d/Makefile | 9 + .../builds/x86_64_accton_as9726_32d/README | 6 + .../module/auto/make.mk | 8 + .../module/auto/x86_64_accton_as9726_32d.yml | 50 + .../x86_64_accton_as9726_32d.x | 14 + .../x86_64_accton_as9726_32d_config.h | 137 ++ .../x86_64_accton_as9726_32d_dox.h | 26 + .../x86_64_accton_as9726_32d_porting.h | 97 ++ .../x86_64_accton_as9726_32d/module/make.mk | 10 + .../module/src/Makefile | 9 + .../module/src/fani.c | 359 +++++ .../module/src/ledi.c | 299 ++++ .../module/src/make.mk | 9 + .../module/src/platform_lib.c | 236 +++ .../module/src/platform_lib.h | 127 ++ .../module/src/psui.c | 188 +++ .../module/src/sfpi.c | 570 +++++++ .../module/src/sysi.c | 1089 +++++++++++++ .../module/src/thermali.c | 337 ++++ .../src/x86_64_accton_as9726_32d_config.c | 80 + .../src/x86_64_accton_as9726_32d_enums.c | 10 + .../module/src/x86_64_accton_as9726_32d_int.h | 12 + .../module/src/x86_64_accton_as9726_32d_log.c | 18 + .../module/src/x86_64_accton_as9726_32d_log.h | 12 + .../src/x86_64_accton_as9726_32d_module.c | 24 + .../src/x86_64_accton_as9726_32d_ucli.c | 50 + .../as9726-32d/platform-config/Makefile | 1 + .../as9726-32d/platform-config/r0/Makefile | 1 + .../as9726-32d/platform-config/r0/PKG.yml | 1 + .../src/lib/tech_support/show_platform_log.sh | 1416 +++++++++++++++++ .../lib/tech_support/show_platform_log_lib.sh | 132 ++ .../src/lib/x86-64-accton-as9726-32d-r0.yml | 37 + .../x86_64_accton_as9726_32d_r0/__init__.py | 76 + 51 files changed, 7887 insertions(+) create mode 100644 packages/platforms/accton/x86-64/as9726-32d/.gitignore create mode 100644 packages/platforms/accton/x86-64/as9726-32d/Makefile create mode 100644 packages/platforms/accton/x86-64/as9726-32d/modules/Makefile create mode 100644 packages/platforms/accton/x86-64/as9726-32d/modules/PKG.yml create mode 100644 packages/platforms/accton/x86-64/as9726-32d/modules/builds/.gitignore create mode 100644 packages/platforms/accton/x86-64/as9726-32d/modules/builds/Makefile create mode 100644 packages/platforms/accton/x86-64/as9726-32d/modules/builds/src/Makefile create mode 100644 packages/platforms/accton/x86-64/as9726-32d/modules/builds/src/x86-64-accton-as9726-32d-cpld.c create mode 100644 packages/platforms/accton/x86-64/as9726-32d/modules/builds/src/x86-64-accton-as9726-32d-fan.c create mode 100644 packages/platforms/accton/x86-64/as9726-32d/modules/builds/src/x86-64-accton-as9726-32d-leds.c create mode 100644 packages/platforms/accton/x86-64/as9726-32d/modules/builds/src/x86-64-accton-as9726-32d-psu.c create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/Makefile create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/PKG.yml create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/Makefile create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/lib/Makefile create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/onlpdump/Makefile create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/.gitignore create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/.module create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/Makefile create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/README create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/auto/make.mk create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/auto/x86_64_accton_as9726_32d.yml create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/inc/x86_64_accton_as9726_32d/x86_64_accton_as9726_32d.x create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/inc/x86_64_accton_as9726_32d/x86_64_accton_as9726_32d_config.h create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/inc/x86_64_accton_as9726_32d/x86_64_accton_as9726_32d_dox.h create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/inc/x86_64_accton_as9726_32d/x86_64_accton_as9726_32d_porting.h create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/make.mk create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/Makefile create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/fani.c create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/ledi.c create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/make.mk create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/platform_lib.c create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/platform_lib.h create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/psui.c create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/sfpi.c create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/sysi.c create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/thermali.c create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/x86_64_accton_as9726_32d_config.c create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/x86_64_accton_as9726_32d_enums.c create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/x86_64_accton_as9726_32d_int.h create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/x86_64_accton_as9726_32d_log.c create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/x86_64_accton_as9726_32d_log.h create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/x86_64_accton_as9726_32d_module.c create mode 100644 packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/x86_64_accton_as9726_32d_ucli.c create mode 100644 packages/platforms/accton/x86-64/as9726-32d/platform-config/Makefile create mode 100644 packages/platforms/accton/x86-64/as9726-32d/platform-config/r0/Makefile create mode 100644 packages/platforms/accton/x86-64/as9726-32d/platform-config/r0/PKG.yml create mode 100755 packages/platforms/accton/x86-64/as9726-32d/platform-config/r0/src/lib/tech_support/show_platform_log.sh create mode 100755 packages/platforms/accton/x86-64/as9726-32d/platform-config/r0/src/lib/tech_support/show_platform_log_lib.sh create mode 100644 packages/platforms/accton/x86-64/as9726-32d/platform-config/r0/src/lib/x86-64-accton-as9726-32d-r0.yml create mode 100644 packages/platforms/accton/x86-64/as9726-32d/platform-config/r0/src/python/x86_64_accton_as9726_32d_r0/__init__.py diff --git a/packages/platforms/accton/x86-64/as9726-32d/.gitignore b/packages/platforms/accton/x86-64/as9726-32d/.gitignore new file mode 100644 index 000000000..3d76e8e09 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/.gitignore @@ -0,0 +1,3 @@ +*x86*64*accton*as9726*32d*.mk +onlpdump.mk + diff --git a/packages/platforms/accton/x86-64/as9726-32d/Makefile b/packages/platforms/accton/x86-64/as9726-32d/Makefile new file mode 100644 index 000000000..003238cf6 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/as9726-32d/modules/Makefile b/packages/platforms/accton/x86-64/as9726-32d/modules/Makefile new file mode 100644 index 000000000..003238cf6 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/modules/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/as9726-32d/modules/PKG.yml b/packages/platforms/accton/x86-64/as9726-32d/modules/PKG.yml new file mode 100644 index 000000000..bdec89f52 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/modules/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/platform-modules.yml VENDOR=accton BASENAME=x86-64-accton-as9726-32d ARCH=amd64 KERNELS="onl-kernel-4.19-lts-x86-64-all:amd64" diff --git a/packages/platforms/accton/x86-64/as9726-32d/modules/builds/.gitignore b/packages/platforms/accton/x86-64/as9726-32d/modules/builds/.gitignore new file mode 100644 index 000000000..a65b41774 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/modules/builds/.gitignore @@ -0,0 +1 @@ +lib diff --git a/packages/platforms/accton/x86-64/as9726-32d/modules/builds/Makefile b/packages/platforms/accton/x86-64/as9726-32d/modules/builds/Makefile new file mode 100644 index 000000000..319cbd453 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/modules/builds/Makefile @@ -0,0 +1,6 @@ +KERNELS := onl-kernel-4.19-lts-x86-64-all:amd64 +KMODULES := src +VENDOR := accton +BASENAME := x86-64-accton-as9726-32d +ARCH := x86_64 +include $(ONL)/make/kmodule.mk diff --git a/packages/platforms/accton/x86-64/as9726-32d/modules/builds/src/Makefile b/packages/platforms/accton/x86-64/as9726-32d/modules/builds/src/Makefile new file mode 100644 index 000000000..5428a64c8 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/modules/builds/src/Makefile @@ -0,0 +1,4 @@ +obj-m += x86-64-accton-as9726-32d-cpld.o +obj-m += x86-64-accton-as9726-32d-psu.o +obj-m += x86-64-accton-as9726-32d-leds.o +obj-m += x86-64-accton-as9726-32d-fan.o diff --git a/packages/platforms/accton/x86-64/as9726-32d/modules/builds/src/x86-64-accton-as9726-32d-cpld.c b/packages/platforms/accton/x86-64/as9726-32d/modules/builds/src/x86-64-accton-as9726-32d-cpld.c new file mode 100644 index 000000000..06020f21f --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/modules/builds/src/x86-64-accton-as9726-32d-cpld.c @@ -0,0 +1,1164 @@ +/* + * Copyright (C) Alex Lai + * + * This module supports the accton cpld that hold the channel select + * mechanism for other i2c slave devices, such as SFP. + * This includes the: + * Accton as9726_32d CPLD1/CPLD2/CPLD3 + * + * Based on: + * pca954x.c from Kumar Gala + * Copyright (C) 2006 + * + * Based on: + * pca954x.c from Ken Harrenstien + * Copyright (C) 2004 Google, Inc. (Ken Harrenstien) + * + * Based on: + * i2c-virtual_cb.c from Brian Kuschak + * and + * pca9540.c from Jean Delvare . + * + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any + * warranty of any kind, whether express or implied. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define I2C_RW_RETRY_COUNT 10 +#define I2C_RW_RETRY_INTERVAL 60 /* ms */ + +#define MAC_PCIE_RESET_DELAY 100 /* ms */ + +static LIST_HEAD(cpld_client_list); +static struct mutex list_lock; + +struct cpld_client_node { + struct i2c_client *client; + struct list_head list; +}; + +enum cpld_type { + as9726_32d_fpga, + as9726_32d_cpld1, + as9726_32d_cpld2, + as9726_32d_cpu_cpld +}; + +struct as9726_32d_cpld_data { + enum cpld_type type; + struct device *hwmon_dev; + struct mutex update_lock; +}; + +static const struct i2c_device_id as9726_32d_cpld_id[] = { + { "as9726_32d_fpga", as9726_32d_fpga }, + { "as9726_32d_cpld1", as9726_32d_cpld1 }, + { "as9726_32d_cpld2", as9726_32d_cpld2 }, + { "as9726_32d_cpu_cpld", as9726_32d_cpu_cpld }, + { } +}; +MODULE_DEVICE_TABLE(i2c, as9726_32d_cpld_id); + +#define TRANSCEIVER_PRESENT_ATTR_ID(index) MODULE_PRESENT_##index +#define TRANSCEIVER_TXDISABLE_ATTR_ID(index) MODULE_TXDISABLE_##index +#define TRANSCEIVER_RXLOS_ATTR_ID(index) MODULE_RXLOS_##index +#define TRANSCEIVER_TXFAULT_ATTR_ID(index) MODULE_TXFAULT_##index +#define TRANSCEIVER_RESET_ATTR_ID(index) MODULE_RESET_##index +#define TRANSCEIVER_LPMODE_ATTR_ID(index) MODULE_LPMODE_##index + +enum as9726_32d_cpld_sysfs_attributes { + CPLD_VERSION, + BIOS_FLASH_ID, + RESET_MAC, + ACCESS, + MODULE_PRESENT_ALL, + MODULE_RXLOS_ALL, + /* transceiver attributes */ + TRANSCEIVER_PRESENT_ATTR_ID(1), + TRANSCEIVER_PRESENT_ATTR_ID(2), + TRANSCEIVER_PRESENT_ATTR_ID(3), + TRANSCEIVER_PRESENT_ATTR_ID(4), + TRANSCEIVER_PRESENT_ATTR_ID(5), + TRANSCEIVER_PRESENT_ATTR_ID(6), + TRANSCEIVER_PRESENT_ATTR_ID(7), + TRANSCEIVER_PRESENT_ATTR_ID(8), + TRANSCEIVER_PRESENT_ATTR_ID(9), + TRANSCEIVER_PRESENT_ATTR_ID(10), + TRANSCEIVER_PRESENT_ATTR_ID(11), + TRANSCEIVER_PRESENT_ATTR_ID(12), + TRANSCEIVER_PRESENT_ATTR_ID(13), + TRANSCEIVER_PRESENT_ATTR_ID(14), + TRANSCEIVER_PRESENT_ATTR_ID(15), + TRANSCEIVER_PRESENT_ATTR_ID(16), + TRANSCEIVER_PRESENT_ATTR_ID(17), + TRANSCEIVER_PRESENT_ATTR_ID(18), + TRANSCEIVER_PRESENT_ATTR_ID(19), + TRANSCEIVER_PRESENT_ATTR_ID(20), + TRANSCEIVER_PRESENT_ATTR_ID(21), + TRANSCEIVER_PRESENT_ATTR_ID(22), + TRANSCEIVER_PRESENT_ATTR_ID(23), + TRANSCEIVER_PRESENT_ATTR_ID(24), + TRANSCEIVER_PRESENT_ATTR_ID(25), + TRANSCEIVER_PRESENT_ATTR_ID(26), + TRANSCEIVER_PRESENT_ATTR_ID(27), + TRANSCEIVER_PRESENT_ATTR_ID(28), + TRANSCEIVER_PRESENT_ATTR_ID(29), + TRANSCEIVER_PRESENT_ATTR_ID(30), + TRANSCEIVER_PRESENT_ATTR_ID(31), + TRANSCEIVER_PRESENT_ATTR_ID(32), + TRANSCEIVER_PRESENT_ATTR_ID(33), + TRANSCEIVER_PRESENT_ATTR_ID(34), + TRANSCEIVER_TXDISABLE_ATTR_ID(33), + TRANSCEIVER_TXDISABLE_ATTR_ID(34), + TRANSCEIVER_RXLOS_ATTR_ID(33), + TRANSCEIVER_RXLOS_ATTR_ID(34), + TRANSCEIVER_TXFAULT_ATTR_ID(33), + TRANSCEIVER_TXFAULT_ATTR_ID(34), + TRANSCEIVER_RESET_ATTR_ID(1), + TRANSCEIVER_RESET_ATTR_ID(2), + TRANSCEIVER_RESET_ATTR_ID(3), + TRANSCEIVER_RESET_ATTR_ID(4), + TRANSCEIVER_RESET_ATTR_ID(5), + TRANSCEIVER_RESET_ATTR_ID(6), + TRANSCEIVER_RESET_ATTR_ID(7), + TRANSCEIVER_RESET_ATTR_ID(8), + TRANSCEIVER_RESET_ATTR_ID(9), + TRANSCEIVER_RESET_ATTR_ID(10), + TRANSCEIVER_RESET_ATTR_ID(11), + TRANSCEIVER_RESET_ATTR_ID(12), + TRANSCEIVER_RESET_ATTR_ID(13), + TRANSCEIVER_RESET_ATTR_ID(14), + TRANSCEIVER_RESET_ATTR_ID(15), + TRANSCEIVER_RESET_ATTR_ID(16), + TRANSCEIVER_RESET_ATTR_ID(17), + TRANSCEIVER_RESET_ATTR_ID(18), + TRANSCEIVER_RESET_ATTR_ID(19), + TRANSCEIVER_RESET_ATTR_ID(20), + TRANSCEIVER_RESET_ATTR_ID(21), + TRANSCEIVER_RESET_ATTR_ID(22), + TRANSCEIVER_RESET_ATTR_ID(23), + TRANSCEIVER_RESET_ATTR_ID(24), + TRANSCEIVER_RESET_ATTR_ID(25), + TRANSCEIVER_RESET_ATTR_ID(26), + TRANSCEIVER_RESET_ATTR_ID(27), + TRANSCEIVER_RESET_ATTR_ID(28), + TRANSCEIVER_RESET_ATTR_ID(29), + TRANSCEIVER_RESET_ATTR_ID(30), + TRANSCEIVER_RESET_ATTR_ID(31), + TRANSCEIVER_RESET_ATTR_ID(32), + TRANSCEIVER_LPMODE_ATTR_ID(1), + TRANSCEIVER_LPMODE_ATTR_ID(2), + TRANSCEIVER_LPMODE_ATTR_ID(3), + TRANSCEIVER_LPMODE_ATTR_ID(4), + TRANSCEIVER_LPMODE_ATTR_ID(5), + TRANSCEIVER_LPMODE_ATTR_ID(6), + TRANSCEIVER_LPMODE_ATTR_ID(7), + TRANSCEIVER_LPMODE_ATTR_ID(8), + TRANSCEIVER_LPMODE_ATTR_ID(9), + TRANSCEIVER_LPMODE_ATTR_ID(10), + TRANSCEIVER_LPMODE_ATTR_ID(11), + TRANSCEIVER_LPMODE_ATTR_ID(12), + TRANSCEIVER_LPMODE_ATTR_ID(13), + TRANSCEIVER_LPMODE_ATTR_ID(14), + TRANSCEIVER_LPMODE_ATTR_ID(15), + TRANSCEIVER_LPMODE_ATTR_ID(16), + TRANSCEIVER_LPMODE_ATTR_ID(17), + TRANSCEIVER_LPMODE_ATTR_ID(18), + TRANSCEIVER_LPMODE_ATTR_ID(19), + TRANSCEIVER_LPMODE_ATTR_ID(20), + TRANSCEIVER_LPMODE_ATTR_ID(21), + TRANSCEIVER_LPMODE_ATTR_ID(22), + TRANSCEIVER_LPMODE_ATTR_ID(23), + TRANSCEIVER_LPMODE_ATTR_ID(24), + TRANSCEIVER_LPMODE_ATTR_ID(25), + TRANSCEIVER_LPMODE_ATTR_ID(26), + TRANSCEIVER_LPMODE_ATTR_ID(27), + TRANSCEIVER_LPMODE_ATTR_ID(28), + TRANSCEIVER_LPMODE_ATTR_ID(29), + TRANSCEIVER_LPMODE_ATTR_ID(30), + TRANSCEIVER_LPMODE_ATTR_ID(31), + TRANSCEIVER_LPMODE_ATTR_ID(32), +}; + +/* sysfs attributes for hwmon + */ +static ssize_t show_status(struct device *dev, struct device_attribute *da, + char *buf); +static ssize_t show_present_all(struct device *dev, + struct device_attribute *da, char *buf); +static ssize_t show_rxlos_all(struct device *dev, struct device_attribute *da, + char *buf); +static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da, + const char *buf, size_t count); +static ssize_t set_port_reset(struct device *dev, struct device_attribute *da, + const char *buf, size_t count); +static ssize_t set_lp_mode(struct device *dev, struct device_attribute *da, + const char *buf, size_t count); +static ssize_t access(struct device *dev, struct device_attribute *da, + const char *buf, size_t count); +static ssize_t show_version(struct device *dev, struct device_attribute *da, + char *buf); +static ssize_t show_bios_flash_id(struct device *dev, struct device_attribute *da, + char *buf); +static int as9726_32d_cpld_read_internal(struct i2c_client *client, u8 reg); +static int as9726_32d_cpld_write_internal(struct i2c_client *client, u8 reg, + u8 value); +static ssize_t get_reset(struct device *dev, struct device_attribute *da, + char *buf); +static ssize_t set_reset(struct device *dev, struct device_attribute *da, + const char *buf, size_t count); + +/* transceiver attributes */ +#define DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(index) \ + static SENSOR_DEVICE_ATTR(module_present_##index, S_IRUGO, \ + show_status, NULL, MODULE_PRESENT_##index); \ + static SENSOR_DEVICE_ATTR(module_reset_##index, S_IRUGO | S_IWUSR, \ + show_status, set_port_reset, \ + MODULE_RESET_##index); \ + static SENSOR_DEVICE_ATTR(module_lpmode_##index, S_IRUGO | S_IWUSR, \ + show_status, set_lp_mode, \ + MODULE_LPMODE_##index); +#define DECLARE_TRANSCEIVER_PRESENT_ATTR(index) \ + &sensor_dev_attr_module_present_##index.dev_attr.attr, \ + &sensor_dev_attr_module_reset_##index.dev_attr.attr, \ + &sensor_dev_attr_module_lpmode_##index.dev_attr.attr + +#define DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(index) \ + static SENSOR_DEVICE_ATTR(module_present_##index, S_IRUGO, \ + show_status, NULL, MODULE_PRESENT_##index); \ + static SENSOR_DEVICE_ATTR(module_tx_disable_##index, \ + S_IRUGO | S_IWUSR, show_status, \ + set_tx_disable, MODULE_TXDISABLE_##index); \ + static SENSOR_DEVICE_ATTR(module_rx_los_##index, S_IRUGO, \ + show_status, NULL, MODULE_RXLOS_##index); \ + static SENSOR_DEVICE_ATTR(module_tx_fault_##index, S_IRUGO, \ + show_status, NULL, MODULE_TXFAULT_##index); + +#define DECLARE_SFP_TRANSCEIVER_ATTR(index) \ + &sensor_dev_attr_module_present_##index.dev_attr.attr, \ + &sensor_dev_attr_module_tx_disable_##index.dev_attr.attr, \ + &sensor_dev_attr_module_rx_los_##index.dev_attr.attr, \ + &sensor_dev_attr_module_tx_fault_##index.dev_attr.attr + + +static SENSOR_DEVICE_ATTR(version, S_IRUGO, show_version, NULL, CPLD_VERSION); +static SENSOR_DEVICE_ATTR(bios_flash_id, S_IRUGO, show_bios_flash_id, NULL, BIOS_FLASH_ID); +static SENSOR_DEVICE_ATTR(access, S_IWUSR, NULL, access, ACCESS); +static SENSOR_DEVICE_ATTR(reset_mac, S_IRUGO | S_IWUSR, \ + get_reset, set_reset, RESET_MAC); + +static SENSOR_DEVICE_ATTR(module_present_all, S_IRUGO, show_present_all, \ + NULL, MODULE_PRESENT_ALL); +static SENSOR_DEVICE_ATTR(module_rx_los_all, S_IRUGO, show_rxlos_all, NULL, \ + MODULE_RXLOS_ALL); + +/* transceiver attributes */ +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(1); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(2); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(3); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(4); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(5); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(6); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(7); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(8); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(9); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(10); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(11); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(12); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(13); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(14); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(15); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(16); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(17); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(18); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(19); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(20); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(21); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(22); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(23); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(24); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(25); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(26); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(27); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(28); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(29); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(30); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(31); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(32); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(33); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(34); + + +static struct attribute *as9726_32d_fpga_attributes[] = { + &sensor_dev_attr_version.dev_attr.attr, + &sensor_dev_attr_access.dev_attr.attr, + &sensor_dev_attr_reset_mac.dev_attr.attr, + NULL +}; + +static const struct attribute_group as9726_32d_fpga_group = { + .attrs = as9726_32d_fpga_attributes, +}; + +static struct attribute *as9726_32d_cpld1_attributes[] = { + &sensor_dev_attr_version.dev_attr.attr, + &sensor_dev_attr_access.dev_attr.attr, + &sensor_dev_attr_module_present_all.dev_attr.attr, + DECLARE_TRANSCEIVER_PRESENT_ATTR(1), + DECLARE_TRANSCEIVER_PRESENT_ATTR(2), + DECLARE_TRANSCEIVER_PRESENT_ATTR(3), + DECLARE_TRANSCEIVER_PRESENT_ATTR(4), + DECLARE_TRANSCEIVER_PRESENT_ATTR(5), + DECLARE_TRANSCEIVER_PRESENT_ATTR(6), + DECLARE_TRANSCEIVER_PRESENT_ATTR(7), + DECLARE_TRANSCEIVER_PRESENT_ATTR(8), + DECLARE_TRANSCEIVER_PRESENT_ATTR(9), + DECLARE_TRANSCEIVER_PRESENT_ATTR(10), + DECLARE_TRANSCEIVER_PRESENT_ATTR(11), + DECLARE_TRANSCEIVER_PRESENT_ATTR(12), + DECLARE_TRANSCEIVER_PRESENT_ATTR(13), + DECLARE_TRANSCEIVER_PRESENT_ATTR(14), + DECLARE_TRANSCEIVER_PRESENT_ATTR(15), + DECLARE_TRANSCEIVER_PRESENT_ATTR(16), + NULL +}; + +static const struct attribute_group as9726_32d_cpld1_group = { + .attrs = as9726_32d_cpld1_attributes, +}; + +static struct attribute *as9726_32d_cpld2_attributes[] = { + &sensor_dev_attr_version.dev_attr.attr, + &sensor_dev_attr_access.dev_attr.attr, + &sensor_dev_attr_module_present_all.dev_attr.attr, + &sensor_dev_attr_module_rx_los_all.dev_attr.attr, + DECLARE_TRANSCEIVER_PRESENT_ATTR(17), + DECLARE_TRANSCEIVER_PRESENT_ATTR(18), + DECLARE_TRANSCEIVER_PRESENT_ATTR(19), + DECLARE_TRANSCEIVER_PRESENT_ATTR(20), + DECLARE_TRANSCEIVER_PRESENT_ATTR(21), + DECLARE_TRANSCEIVER_PRESENT_ATTR(22), + DECLARE_TRANSCEIVER_PRESENT_ATTR(23), + DECLARE_TRANSCEIVER_PRESENT_ATTR(24), + DECLARE_TRANSCEIVER_PRESENT_ATTR(25), + DECLARE_TRANSCEIVER_PRESENT_ATTR(26), + DECLARE_TRANSCEIVER_PRESENT_ATTR(27), + DECLARE_TRANSCEIVER_PRESENT_ATTR(28), + DECLARE_TRANSCEIVER_PRESENT_ATTR(29), + DECLARE_TRANSCEIVER_PRESENT_ATTR(30), + DECLARE_TRANSCEIVER_PRESENT_ATTR(31), + DECLARE_TRANSCEIVER_PRESENT_ATTR(32), + DECLARE_SFP_TRANSCEIVER_ATTR(33), + DECLARE_SFP_TRANSCEIVER_ATTR(34), + NULL +}; + +static const struct attribute_group as9726_32d_cpld2_group = { + .attrs = as9726_32d_cpld2_attributes, +}; + +static struct attribute *as9726_32d_cpu_cpld_attributes[] = { + &sensor_dev_attr_version.dev_attr.attr, + &sensor_dev_attr_bios_flash_id.dev_attr.attr, + &sensor_dev_attr_access.dev_attr.attr, + NULL +}; + +static const struct attribute_group as9726_32d_cpu_cpld_group = { + .attrs = as9726_32d_cpu_cpld_attributes, +}; + +static ssize_t show_present_all(struct device *dev, + struct device_attribute *da, char *buf) +{ + int i, status; + + struct i2c_client *client = to_i2c_client(dev); + struct as9726_32d_cpld_data *data = i2c_get_clientdata(client); + + + if (data->type == as9726_32d_cpld1) { + u8 regs[] = {0x12, 0x13}; + u8 values[2] = {0}; + + mutex_lock(&data->update_lock); + for (i = 0; i < ARRAY_SIZE(regs); i++) { + status = as9726_32d_cpld_read_internal(client, regs[i]); + + if (status < 0) + goto exit; + + values[i] = ~(u8)status; + } + mutex_unlock(&data->update_lock); + + return sprintf(buf, "%.2x %.2x\n", values[0], values[1]); + } else if (data->type == as9726_32d_cpld2) { + u8 regs[] = {0x12, 0x13, 0x20}; + u8 values[3] = {0}; + + mutex_lock(&data->update_lock); + for (i = 0; i < ARRAY_SIZE(regs); i++) { + status = as9726_32d_cpld_read_internal(client, regs[i]); + + if (status < 0) + goto exit; + + values[i] = ~(u8)status; + } + mutex_unlock(&data->update_lock); + + values[2] &= 0x3; + return sprintf(buf, "%.2x %.2x %.2x\n", values[0], values[1], + values[2]); + } + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t show_rxlos_all(struct device *dev, struct device_attribute *da, + char *buf) +{ + int i, status; + u8 value = 0; + u8 reg = 0x26; + struct i2c_client *client = to_i2c_client(dev); + struct as9726_32d_cpld_data *data = i2c_get_clientdata(client); + + mutex_lock(&data->update_lock); + + status = as9726_32d_cpld_read_internal(client, reg); + + if (status < 0) + goto exit; + + value = ~(u8)status; + value &= 0x03; + mutex_unlock(&data->update_lock); + + /* Return values 1 -> 34 in order */ + return sprintf(buf, "00 00 00 00 %.2x\n", value); + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t show_status(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct i2c_client *client = to_i2c_client(dev); + struct as9726_32d_cpld_data *data = i2c_get_clientdata(client); + int status = 0; + u8 reg = 0, mask = 0, revert = 0; + + switch (attr->index) { + case MODULE_PRESENT_1 ... MODULE_PRESENT_8: + reg = 0x12; + mask = 0x1 << (attr->index - MODULE_PRESENT_1); + break; + case MODULE_PRESENT_9 ... MODULE_PRESENT_16: + reg = 0x13; + mask = 0x1 << (attr->index - MODULE_PRESENT_9); + break; + case MODULE_PRESENT_17 ... MODULE_PRESENT_24: + reg = 0x12; + mask = 0x1 << (attr->index - MODULE_PRESENT_17); + break; + case MODULE_PRESENT_25 ... MODULE_PRESENT_32: + reg = 0x13; + mask = 0x1 << (attr->index - MODULE_PRESENT_25); + break; + case MODULE_PRESENT_33: + reg = 0x20; + mask = 0x1; + break; + case MODULE_PRESENT_34: + reg = 0x20; + mask = 0x2; + break; + case MODULE_LPMODE_1 ... MODULE_LPMODE_8: + reg = 0x60; + mask = 0x1 << (attr->index - MODULE_LPMODE_1); + break; + case MODULE_LPMODE_9 ... MODULE_LPMODE_16: + reg = 0x61; + mask = 0x1 << (attr->index - MODULE_LPMODE_9); + break; + case MODULE_LPMODE_17 ... MODULE_LPMODE_24: + reg = 0x60; + mask = 0x1 << (attr->index - MODULE_LPMODE_17); + break; + case MODULE_LPMODE_25 ... MODULE_LPMODE_32: + reg = 0x61; + mask = 0x1 << (attr->index - MODULE_LPMODE_25); + break; + case MODULE_RXLOS_33: + reg = 0x26; + mask = 0x1; + break; + case MODULE_RXLOS_34: + reg = 0x26; + mask = 0x2; + break; + case MODULE_TXDISABLE_33: + reg = 0x21; + mask = 0x1; + break; + case MODULE_TXDISABLE_34: + reg = 0x21; + mask = 0x2; + break; + case MODULE_TXFAULT_33: + reg = 0x27; + mask = 0x1; + case MODULE_TXFAULT_34: + reg = 0x27; + mask = 0x2; + case MODULE_RESET_1 ... MODULE_RESET_8: + reg = 0x14; + mask = 0x1 << (attr->index - MODULE_RESET_1); + break; + case MODULE_RESET_9 ... MODULE_RESET_16: + reg = 0x15; + mask = 0x1 << (attr->index - MODULE_RESET_9); + break; + case MODULE_RESET_17 ... MODULE_RESET_24: + reg = 0x14; + mask = 0x1 << (attr->index - MODULE_RESET_17); + break; + case MODULE_RESET_25 ... MODULE_RESET_32: + reg = 0x15; + mask = 0x1 << (attr->index - MODULE_RESET_25); + break; + default: + return 0; + } + + if (attr->index >= MODULE_PRESENT_1 && + attr->index <= MODULE_PRESENT_34) + revert = 1; + + if (attr->index >= MODULE_RESET_1 && attr->index <= MODULE_RESET_32) + revert = 1; + + if (attr->index >= MODULE_RXLOS_33 && attr->index <= MODULE_RXLOS_34) + revert = 1; + + if (attr->index >= MODULE_TXFAULT_33 && attr->index <= MODULE_TXFAULT_34) + revert = 1; + + mutex_lock(&data->update_lock); + status = as9726_32d_cpld_read_internal(client, reg); + if (unlikely(status < 0)) + goto exit; + + mutex_unlock(&data->update_lock); + + return sprintf(buf, "%d\n", + revert ? !(status & mask) : !!(status & mask)); + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t set_lp_mode(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct i2c_client *client = to_i2c_client(dev); + struct as9726_32d_cpld_data *data = i2c_get_clientdata(client); + + long value; + int status; + u8 reg = 0, mask = 0; + + status = kstrtol(buf, 10, &value); + if (status) { + return status; + } + + switch (attr->index) { + case MODULE_LPMODE_1 ... MODULE_LPMODE_8: + reg = 0x60; + mask = 0x1 << (attr->index - MODULE_LPMODE_1); + break; + case MODULE_LPMODE_9 ... MODULE_LPMODE_16: + reg = 0x61; + mask = 0x1 << (attr->index - MODULE_LPMODE_9); + break; + case MODULE_LPMODE_17 ... MODULE_LPMODE_24: + reg = 0x60; + mask = 0x1 << (attr->index - MODULE_LPMODE_17); + break; + case MODULE_LPMODE_25 ... MODULE_LPMODE_32: + reg = 0x61; + mask = 0x1 << (attr->index - MODULE_LPMODE_25); + break; + default: + return 0; + } + + /* Read current status */ + mutex_lock(&data->update_lock); + status = as9726_32d_cpld_read_internal(client, reg); + if (unlikely(status < 0)) + goto exit; + + if (value) + status |= mask; + else + status &= ~mask; + + status = as9726_32d_cpld_write_internal(client, reg, status); + if (unlikely(status < 0)) + goto exit; + + mutex_unlock(&data->update_lock); + return count; + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct i2c_client *client = to_i2c_client(dev); + struct as9726_32d_cpld_data *data = i2c_get_clientdata(client); + long disable; + int status; + u8 reg = 0, mask = 0; + + status = kstrtol(buf, 10, &disable); + if (status) + return status; + + switch (attr->index) { + case MODULE_TXDISABLE_33: + reg = 0x21; + mask = 0x1; + break; + case MODULE_TXDISABLE_34: + reg = 0x21; + mask = 0x2; + break; + default: + return 0; + } + + /* Read current status */ + mutex_lock(&data->update_lock); + status = as9726_32d_cpld_read_internal(client, reg); + if (unlikely(status < 0)) + goto exit; + + /* Update tx_disable status */ + if (disable) { + status |= mask; + } else { + status &= ~mask; + } + + status = as9726_32d_cpld_write_internal(client, reg, status); + if (unlikely(status < 0)) + goto exit; + + mutex_unlock(&data->update_lock); + return count; + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t set_port_reset(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct i2c_client *client = to_i2c_client(dev); + struct as9726_32d_cpld_data *data = i2c_get_clientdata(client); + long reset; + int status; + u8 reg = 0, mask = 0; + + status = kstrtol(buf, 10, &reset); + if (status) + return status; + + switch (attr->index) { + case MODULE_RESET_1 ... MODULE_RESET_8: + reg = 0x14; + mask = 0x1 << (attr->index - MODULE_RESET_1); + break; + case MODULE_RESET_9 ... MODULE_RESET_16: + reg = 0x15; + mask = 0x1 << (attr->index - MODULE_RESET_9); + break; + case MODULE_RESET_17 ... MODULE_RESET_24: + reg = 0x14; + mask = 0x1 << (attr->index - MODULE_RESET_17); + break; + case MODULE_RESET_25 ... MODULE_RESET_32: + reg = 0x15; + mask = 0x1 << (attr->index - MODULE_RESET_25); + break; + default: + return -ENXIO; + } + + /* Read current status */ + mutex_lock(&data->update_lock); + status = as9726_32d_cpld_read_internal(client, reg); + if (unlikely(status < 0)) + goto exit; + + /* Update tx_disable status */ + if (reset) { + status &= ~mask; + } else { + status |= mask; + } + + status = as9726_32d_cpld_write_internal(client, reg, status); + if (unlikely(status < 0)) + goto exit; + + mutex_unlock(&data->update_lock); + return count; + +exit: + mutex_unlock(&data->update_lock); + return status; +} + + +static ssize_t access(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + int status; + u32 addr, val; + struct i2c_client *client = to_i2c_client(dev); + struct as9726_32d_cpld_data *data = i2c_get_clientdata(client); + + if (sscanf(buf, "0x%x 0x%x", &addr, &val) != 2) + return -EINVAL; + + if (addr > 0xFF || val > 0xFF) + return -EINVAL; + + mutex_lock(&data->update_lock); + status = as9726_32d_cpld_write_internal(client, addr, val); + if (unlikely(status < 0)) + goto exit; + + mutex_unlock(&data->update_lock); + return count; + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static void as9726_32d_cpld_add_client(struct i2c_client *client) +{ + struct cpld_client_node *node = kzalloc(sizeof(struct cpld_client_node) + , GFP_KERNEL); + + if (!node) { + dev_dbg(&client->dev, "Can't allocate cpld_client_node (0x%x)\n", + client->addr); + return; + } + + node->client = client; + + mutex_lock(&list_lock); + list_add(&node->list, &cpld_client_list); + mutex_unlock(&list_lock); +} + +static void as9726_32d_cpld_remove_client(struct i2c_client *client) +{ + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int found = 0; + + mutex_lock(&list_lock); + + list_for_each(list_node, &cpld_client_list) + { + cpld_node = list_entry(list_node, struct cpld_client_node, + list); + + if (cpld_node->client == client) { + found = 1; + break; + } + } + + if (found) { + list_del(list_node); + kfree(cpld_node); + } + + mutex_unlock(&list_lock); +} + +static ssize_t show_version(struct device *dev, struct device_attribute *attr, + char *buf) +{ + int val = 0; + struct i2c_client *client = to_i2c_client(dev); + + val = i2c_smbus_read_byte_data(client, 0x1); + + if (val < 0) + dev_dbg(&client->dev, "cpld(0x%x) reg(0x1) err %d\n", + client->addr, val); + + return sprintf(buf, "%d\n", val); +} + +static ssize_t show_bios_flash_id(struct device *dev, struct device_attribute *attr, char *buf) +{ + int val = 0; + struct i2c_client *client = to_i2c_client(dev); + + val = i2c_smbus_read_byte_data(client, 0x3); /*(BIT2) 1: master, 0: slave*/ + + return sprintf(buf, "%d\n", ( ((val >> 2) & 0x1) == 1 ) ? 1 : 2); /*1: master, 2: slave*/ +} + +static ssize_t get_reset(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct i2c_client *client = to_i2c_client(dev); + struct as9726_32d_cpld_data *data = i2c_get_clientdata(client); + + int status = 0, val = 0; + u8 reg = 0, mask_mac = 0x80, mask_pcie = 0x10, mask = 0; + + switch (attr->index) { + case RESET_MAC: + reg = 0x8; + mask = mask_mac | mask_pcie; + break; + default: + return 0; + } + + mutex_lock(&data->update_lock); + status = as9726_32d_cpld_read_internal(client, reg); + + if (unlikely(status < 0)) { + goto exit; + } + mutex_unlock(&data->update_lock); + + val = ((status & mask) == 0x0) ? 1 : 0; + return sprintf(buf, "%d\n", val); + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t set_reset(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct i2c_client *client = to_i2c_client(dev); + struct as9726_32d_cpld_data *data = i2c_get_clientdata(client); + long value; + int status; + u8 reg = 0, mask_mac, mask_pcie = 0; + + status = kstrtol(buf, 10, &value); + + if (status) + return status; + + if (value != 1) + return -EINVAL; + + switch (attr->index) { + case RESET_MAC: + reg = 0x8; + mask_mac = 0x80; + mask_pcie = 0x10; + + mutex_lock(&data->update_lock); + + /* put mac & pcie to low */ + status = as9726_32d_cpld_read_internal(client, reg); + if (unlikely(status < 0)) + goto exit; + + status &= ~(mask_mac | mask_pcie); + status = as9726_32d_cpld_write_internal(client, reg, status); + if (unlikely(status < 0)) + goto exit; + + /* put mac to high */ + status = as9726_32d_cpld_read_internal(client, reg); + if (unlikely(status < 0)) + goto exit; + + status |= mask_mac; + status = as9726_32d_cpld_write_internal(client, reg, status); + if (unlikely(status < 0)) + goto exit; + + msleep(MAC_PCIE_RESET_DELAY); + + /* put pcie to high */ + status = as9726_32d_cpld_read_internal(client, reg); + if (unlikely(status < 0)) + goto exit; + + status |= mask_pcie; + status = as9726_32d_cpld_write_internal(client, reg, status); + if (unlikely(status < 0)) + goto exit; + + mutex_unlock(&data->update_lock); + break; + + default: + return -EINVAL; + } + + return count; + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +/* + * I2C init/probing/exit functions + */ +static int as9726_32d_cpld_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent); + struct as9726_32d_cpld_data *data; + int ret = -ENODEV; + int status; + const struct attribute_group *group = NULL; + + if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE)) + goto exit; + + data = kzalloc(sizeof(struct as9726_32d_cpld_data), GFP_KERNEL); + if (!data) { + ret = -ENOMEM; + goto exit; + } + + i2c_set_clientdata(client, data); + mutex_init(&data->update_lock); + data->type = id->driver_data; + + /* Register sysfs hooks */ + switch (data->type) { + case as9726_32d_fpga: + group = &as9726_32d_fpga_group; + break; + case as9726_32d_cpld1: + group = &as9726_32d_cpld1_group; + break; + case as9726_32d_cpld2: + group = &as9726_32d_cpld2_group; + break; + case as9726_32d_cpu_cpld: + group = &as9726_32d_cpu_cpld_group; + /* Disable CPLD reset to avoid DUT will be reset. + */ + status=as9726_32d_cpld_write_internal(client, 0x3, 0x0); + if (status < 0) + dev_dbg(&client->dev, "cpu_cpld reg 0x65 err %d\n", status); + break; + default: + break; + } + + if (group) { + ret = sysfs_create_group(&client->dev.kobj, group); + if (ret) + goto exit_free; + } + + as9726_32d_cpld_add_client(client); + return 0; + +exit_free: + kfree(data); +exit: + return ret; +} + +static int as9726_32d_cpld_remove(struct i2c_client *client) +{ + struct as9726_32d_cpld_data *data = i2c_get_clientdata(client); + const struct attribute_group *group = NULL; + + as9726_32d_cpld_remove_client(client); + + /* Remove sysfs hooks */ + switch (data->type) { + case as9726_32d_fpga: + group = &as9726_32d_fpga_group; + break; + case as9726_32d_cpld1: + group = &as9726_32d_cpld1_group; + break; + case as9726_32d_cpld2: + group = &as9726_32d_cpld2_group; + break; + case as9726_32d_cpu_cpld: + group = &as9726_32d_cpu_cpld_group; + break; + default: + break; + } + + if (group) + sysfs_remove_group(&client->dev.kobj, group); + + kfree(data); + + return 0; +} + +static int as9726_32d_cpld_read_internal(struct i2c_client *client, u8 reg) +{ + int status = 0, retry = I2C_RW_RETRY_COUNT; + + while (retry) { + status = i2c_smbus_read_byte_data(client, reg); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; + } + break; + } + + return status; +} + +static int as9726_32d_cpld_write_internal(struct i2c_client *client, u8 reg, + u8 value) +{ + int status = 0, retry = I2C_RW_RETRY_COUNT; + + while (retry) { + status = i2c_smbus_write_byte_data(client, reg, value); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; + } + break; + } + + return status; +} + +int as9726_32d_cpld_read(unsigned short cpld_addr, u8 reg) +{ + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int ret = -EPERM; + + mutex_lock(&list_lock); + + list_for_each(list_node, &cpld_client_list) + { + cpld_node = list_entry(list_node, struct cpld_client_node, + list); + + if (cpld_node->client->addr == cpld_addr) { + ret = as9726_32d_cpld_read_internal(cpld_node->client, + reg); + break; + } + } + + mutex_unlock(&list_lock); + + return ret; +} +EXPORT_SYMBOL(as9726_32d_cpld_read); + +int as9726_32d_cpld_write(unsigned short cpld_addr, u8 reg, u8 value) +{ + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int ret = -EIO; + + mutex_lock(&list_lock); + + list_for_each(list_node, &cpld_client_list) + { + cpld_node = list_entry(list_node, struct cpld_client_node, + list); + if (cpld_node->client->addr == cpld_addr) { + ret = as9726_32d_cpld_write_internal(cpld_node->client, + reg, value); + break; + } + } + + mutex_unlock(&list_lock); + + return ret; +} +EXPORT_SYMBOL(as9726_32d_cpld_write); + +static struct i2c_driver as9726_32d_cpld_driver = { + .driver = { + .name = "as9726_32d_cpld", + .owner = THIS_MODULE, + }, + .probe = as9726_32d_cpld_probe, + .remove = as9726_32d_cpld_remove, + .id_table = as9726_32d_cpld_id, +}; + +static int __init as9726_32d_cpld_init(void) +{ + mutex_init(&list_lock); + return i2c_add_driver(&as9726_32d_cpld_driver); +} + +static void __exit as9726_32d_cpld_exit(void) +{ + i2c_del_driver(&as9726_32d_cpld_driver); +} + +MODULE_AUTHOR("Alex Lai "); +MODULE_DESCRIPTION("Accton I2C CPLD driver"); +MODULE_LICENSE("GPL"); + +module_init(as9726_32d_cpld_init); +module_exit(as9726_32d_cpld_exit); diff --git a/packages/platforms/accton/x86-64/as9726-32d/modules/builds/src/x86-64-accton-as9726-32d-fan.c b/packages/platforms/accton/x86-64/as9726-32d/modules/builds/src/x86-64-accton-as9726-32d-fan.c new file mode 100644 index 000000000..ea7a253e9 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/modules/builds/src/x86-64-accton-as9726-32d-fan.c @@ -0,0 +1,529 @@ +/* + * A hwmon driver for the Accton as9726 32d fan + * + * Copyright (C) 2014 Accton Technology Corporation. + * Alex Lai + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DRVNAME "as9726_32d_fan" + +static struct as9726_32d_fan_data *as9726_32d_fan_update_device( + struct device *dev); +static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, + char *buf); +static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da, + const char *buf, size_t count); + +/* fan related data, the index should match sysfs_fan_attributes + */ +static const u8 fan_reg[] = { + 0x01, /* fan cpld version */ + 0x0F, /* fan 1-6 present status */ + 0x10, /* fan 1-6 direction(0:F2B 1:B2F) */ + 0x11, /* fan PWM(for all fan) */ + 0x12, /* front fan 1 speed(rpm) */ + 0x13, /* front fan 2 speed(rpm) */ + 0x14, /* front fan 3 speed(rpm) */ + 0x15, /* front fan 4 speed(rpm) */ + 0x16, /* front fan 5 speed(rpm) */ + 0x17, /* front fan 6 speed(rpm) */ + 0x22, /* rear fan 1 speed(rpm) */ + 0x23, /* rear fan 2 speed(rpm) */ + 0x24, /* rear fan 3 speed(rpm) */ + 0x25, /* rear fan 4 speed(rpm) */ + 0x26, /* rear fan 5 speed(rpm) */ + 0x27, /* rear fan 6 speed(rpm) */ +}; + +/* Each client has this additional data */ +struct as9726_32d_fan_data { + struct device *hwmon_dev; + struct mutex update_lock; + char valid; /* != 0 if registers are valid */ + unsigned long last_updated; /* In jiffies */ + u8 reg_val[ARRAY_SIZE(fan_reg)]; /* Register value */ +}; + +enum fan_id { + FAN1_ID, + FAN2_ID, + FAN3_ID, + FAN4_ID, + FAN5_ID, + FAN6_ID +}; + +enum sysfs_fan_attributes { + VERSION, + FAN_PRESENT_REG, + FAN_DIRECTION_REG, + FAN_DUTY_CYCLE_PERCENTAGE, /* Only one CPLD register to control duty cycle for all fans */ + FAN1_FRONT_SPEED_RPM, + FAN2_FRONT_SPEED_RPM, + FAN3_FRONT_SPEED_RPM, + FAN4_FRONT_SPEED_RPM, + FAN5_FRONT_SPEED_RPM, + FAN6_FRONT_SPEED_RPM, + FAN1_REAR_SPEED_RPM, + FAN2_REAR_SPEED_RPM, + FAN3_REAR_SPEED_RPM, + FAN4_REAR_SPEED_RPM, + FAN5_REAR_SPEED_RPM, + FAN6_REAR_SPEED_RPM, + FAN1_DIRECTION, + FAN2_DIRECTION, + FAN3_DIRECTION, + FAN4_DIRECTION, + FAN5_DIRECTION, + FAN6_DIRECTION, + FAN1_PRESENT, + FAN2_PRESENT, + FAN3_PRESENT, + FAN4_PRESENT, + FAN5_PRESENT, + FAN6_PRESENT, + FAN1_FAULT, + FAN2_FAULT, + FAN3_FAULT, + FAN4_FAULT, + FAN5_FAULT, + FAN6_FAULT +}; + +/* Define attributes + */ +#define DECLARE_VERSION_SENSOR_DEV_ATTR() \ + static SENSOR_DEVICE_ATTR(version, S_IRUGO, fan_show_value, NULL, VERSION) +#define DECLARE_VERSION_ATTR() \ + &sensor_dev_attr_version.dev_attr.attr + +#define DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(index) \ + static SENSOR_DEVICE_ATTR(fan##index##_fault, S_IRUGO, \ + fan_show_value, NULL, FAN##index##_FAULT) +#define DECLARE_FAN_FAULT_ATTR(index) \ + &sensor_dev_attr_fan##index##_fault.dev_attr.attr + +#define DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(index) \ + static SENSOR_DEVICE_ATTR(fan##index##_direction, S_IRUGO, \ + fan_show_value, NULL, FAN##index##_DIRECTION) +#define DECLARE_FAN_DIRECTION_ATTR(index) \ + &sensor_dev_attr_fan##index##_direction.dev_attr.attr + +#define DECLARE_FAN_DUTY_CYCLE_SENSOR_DEV_ATTR(index) \ + static SENSOR_DEVICE_ATTR(fan##index##_duty_cycle_percentage, \ + S_IWUSR | S_IRUGO, fan_show_value, \ + set_duty_cycle, \ + FAN##index##_DUTY_CYCLE_PERCENTAGE) +#define DECLARE_FAN_DUTY_CYCLE_ATTR(index) \ + &sensor_dev_attr_fan##index##_duty_cycle_percentage.dev_attr.attr + +#define DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(index) \ + static SENSOR_DEVICE_ATTR(fan##index##_present, S_IRUGO, \ + fan_show_value, NULL, FAN##index##_PRESENT) +#define DECLARE_FAN_PRESENT_ATTR(index) \ + &sensor_dev_attr_fan##index##_present.dev_attr.attr + +#define DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(index) \ + static SENSOR_DEVICE_ATTR(fan##index##_front_speed_rpm, S_IRUGO, \ + fan_show_value, NULL, \ + FAN##index##_FRONT_SPEED_RPM);\ + static SENSOR_DEVICE_ATTR(fan##index##_rear_speed_rpm, S_IRUGO, \ + fan_show_value, NULL, \ + FAN##index##_REAR_SPEED_RPM) +#define DECLARE_FAN_SPEED_RPM_ATTR(index) \ + &sensor_dev_attr_fan##index##_front_speed_rpm.dev_attr.attr, \ + &sensor_dev_attr_fan##index##_rear_speed_rpm.dev_attr.attr + +/* FAN CPLD Version */ +DECLARE_VERSION_SENSOR_DEV_ATTR(); +/* 6 fan fault attributes in this platform */ +DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(1); +DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(2); +DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(3); +DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(4); +DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(5); +DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(6); +/* 6 fan speed(rpm) attributes in this platform */ +DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(1); +DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(2); +DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(3); +DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(4); +DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(5); +DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(6); +/* 6 fan present attributes in this platform */ +DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(1); +DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(2); +DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(3); +DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(4); +DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(5); +DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(6); +/* 6 fan direction attribute in this platform */ +DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(1); +DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(2); +DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(3); +DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(4); +DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(5); +DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(6); +/* 1 fan duty cycle attribute in this platform */ +DECLARE_FAN_DUTY_CYCLE_SENSOR_DEV_ATTR(); + +static struct attribute *as9726_32d_fan_attributes[] = { + /* fan related attributes */ + DECLARE_VERSION_ATTR(), + DECLARE_FAN_FAULT_ATTR(1), + DECLARE_FAN_FAULT_ATTR(2), + DECLARE_FAN_FAULT_ATTR(3), + DECLARE_FAN_FAULT_ATTR(4), + DECLARE_FAN_FAULT_ATTR(5), + DECLARE_FAN_FAULT_ATTR(6), + DECLARE_FAN_SPEED_RPM_ATTR(1), + DECLARE_FAN_SPEED_RPM_ATTR(2), + DECLARE_FAN_SPEED_RPM_ATTR(3), + DECLARE_FAN_SPEED_RPM_ATTR(4), + DECLARE_FAN_SPEED_RPM_ATTR(5), + DECLARE_FAN_SPEED_RPM_ATTR(6), + DECLARE_FAN_PRESENT_ATTR(1), + DECLARE_FAN_PRESENT_ATTR(2), + DECLARE_FAN_PRESENT_ATTR(3), + DECLARE_FAN_PRESENT_ATTR(4), + DECLARE_FAN_PRESENT_ATTR(5), + DECLARE_FAN_PRESENT_ATTR(6), + DECLARE_FAN_DIRECTION_ATTR(1), + DECLARE_FAN_DIRECTION_ATTR(2), + DECLARE_FAN_DIRECTION_ATTR(3), + DECLARE_FAN_DIRECTION_ATTR(4), + DECLARE_FAN_DIRECTION_ATTR(5), + DECLARE_FAN_DIRECTION_ATTR(6), + DECLARE_FAN_DUTY_CYCLE_ATTR(), + NULL +}; + +#define FAN_DUTY_CYCLE_REG_MASK 0xF +#define FAN_MAX_DUTY_CYCLE 100 +#define FAN_REG_VAL_TO_SPEED_RPM_STEP 200 + +static int as9726_32d_fan_read_value(struct i2c_client *client, u8 reg) +{ + return i2c_smbus_read_byte_data(client, reg); +} + +static int as9726_32d_fan_write_value(struct i2c_client *client, u8 reg, + u8 value) +{ + return i2c_smbus_write_byte_data(client, reg, value); +} + +/* fan utility functions + */ +static u32 reg_val_to_duty_cycle(u8 reg_val) +{ + reg_val &= FAN_DUTY_CYCLE_REG_MASK; + return ((u32)(reg_val+1) * 625 + 75) / 100; +} + +static u8 duty_cycle_to_reg_val(u8 duty_cycle) +{ + return ((u32)duty_cycle * 100 / 625) - 1; +} + +static u32 reg_val_to_speed_rpm(u8 reg_val) +{ + return (u32)reg_val * FAN_REG_VAL_TO_SPEED_RPM_STEP; +} + +static u8 reg_val_to_direction(u8 reg_val, enum fan_id id) +{ + u8 mask = (1 << id); + + reg_val &= mask; + + return reg_val ? 1 : 0; +} +static u8 reg_val_to_is_present(u8 reg_val, enum fan_id id) +{ + u8 mask = (1 << id); + + reg_val &= mask; + + return reg_val ? 0 : 1; +} + +static u8 is_fan_fault(struct as9726_32d_fan_data *data, enum fan_id id) +{ + u8 ret = 1; + int front_fan_index = FAN1_FRONT_SPEED_RPM + id; + int rear_fan_index = FAN1_REAR_SPEED_RPM + id; + + /* Check if the speed of front or rear fan is ZERO, + */ + if (reg_val_to_speed_rpm(data->reg_val[front_fan_index]) && + reg_val_to_speed_rpm(data->reg_val[rear_fan_index])) + ret = 0; + + return ret; +} + +static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + int error, value; + struct i2c_client *client = to_i2c_client(dev); + struct as9726_32d_fan_data *data = i2c_get_clientdata(client); + + error = kstrtoint(buf, 10, &value); + + if (error) + return error; + + if (value < 0 || value > FAN_MAX_DUTY_CYCLE) + return -EINVAL; + + mutex_lock(&data->update_lock); + + /* Disable the watchdog timer + */ + error = as9726_32d_fan_write_value(client, 0x33, 0); + if (error != 0) { + dev_dbg(&client->dev, "Unable to disable the watchdog timer\n" + ); + mutex_unlock(&data->update_lock); + return error; + } + + as9726_32d_fan_write_value(client, + fan_reg[FAN_DUTY_CYCLE_PERCENTAGE], + duty_cycle_to_reg_val(value)); + data->valid = 0; + + mutex_unlock(&data->update_lock); + return count; +} + +static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct i2c_client *client = to_i2c_client(dev); + struct as9726_32d_fan_data *data = i2c_get_clientdata(client); + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + ssize_t ret = 0; + + mutex_lock(&data->update_lock); + data = as9726_32d_fan_update_device(dev); + + if (data->valid) { + switch (attr->index) { + case FAN_DUTY_CYCLE_PERCENTAGE: { + u32 duty_cycle = + reg_val_to_duty_cycle( + data->reg_val[FAN_DUTY_CYCLE_PERCENTAGE]); + ret = sprintf(buf, "%u\n", duty_cycle); + break; + } + case FAN1_FRONT_SPEED_RPM: + case FAN2_FRONT_SPEED_RPM: + case FAN3_FRONT_SPEED_RPM: + case FAN4_FRONT_SPEED_RPM: + case FAN5_FRONT_SPEED_RPM: + case FAN6_FRONT_SPEED_RPM: + case FAN1_REAR_SPEED_RPM: + case FAN2_REAR_SPEED_RPM: + case FAN3_REAR_SPEED_RPM: + case FAN4_REAR_SPEED_RPM: + case FAN5_REAR_SPEED_RPM: + case FAN6_REAR_SPEED_RPM: + ret = sprintf(buf, "%u\n", + reg_val_to_speed_rpm( + data->reg_val[attr->index])); + break; + case FAN1_PRESENT: + case FAN2_PRESENT: + case FAN3_PRESENT: + case FAN4_PRESENT: + case FAN5_PRESENT: + case FAN6_PRESENT: + ret = sprintf(buf, "%d\n", + reg_val_to_is_present(data->reg_val[FAN_PRESENT_REG], + attr->index - FAN1_PRESENT)); + break; + case FAN1_FAULT: + case FAN2_FAULT: + case FAN3_FAULT: + case FAN4_FAULT: + case FAN5_FAULT: + case FAN6_FAULT: + ret = sprintf(buf, "%d\n", + is_fan_fault(data, attr->index - FAN1_FAULT)); + break; + case FAN1_DIRECTION: + case FAN2_DIRECTION: + case FAN3_DIRECTION: + case FAN4_DIRECTION: + case FAN5_DIRECTION: + case FAN6_DIRECTION: + ret = sprintf(buf, "%d\n", + reg_val_to_direction( + data->reg_val[FAN_DIRECTION_REG], + attr->index - FAN1_DIRECTION)); + break; + case VERSION: + ret = sprintf(buf, "%u\n", data->reg_val[VERSION]); + break; + default: + break; + } + } + + mutex_unlock(&data->update_lock); + + return ret; +} + +static const struct attribute_group as9726_32d_fan_group = { + .attrs = as9726_32d_fan_attributes, +}; + +static struct as9726_32d_fan_data *as9726_32d_fan_update_device(struct + device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct as9726_32d_fan_data *data = i2c_get_clientdata(client); + + if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || + !data->valid) { + int i; + + dev_dbg(&client->dev, "Starting as9726_32d_fan update\n"); + data->valid = 0; + + /* Update fan data + */ + for (i = 0; i < ARRAY_SIZE(data->reg_val); i++) { + int status = as9726_32d_fan_read_value(client, + fan_reg[i]); + if (status < 0) { + data->valid = 0; + dev_dbg(&client->dev, "reg %d, err %d\n", + fan_reg[i], status); + return data; + } else { + data->reg_val[i] = status; + } + } + + data->last_updated = jiffies; + data->valid = 1; + } + + return data; +} + +static int as9726_32d_fan_probe(struct i2c_client *client, + const struct i2c_device_id *dev_id) +{ + struct as9726_32d_fan_data *data; + int status; + + if (!i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_BYTE_DATA)) { + status = -EIO; + goto exit; + } + + data = kzalloc(sizeof(struct as9726_32d_fan_data), GFP_KERNEL); + if (!data) { + status = -ENOMEM; + goto exit; + } + + i2c_set_clientdata(client, data); + data->valid = 0; + mutex_init(&data->update_lock); + + dev_info(&client->dev, "chip found\n"); + + /* Register sysfs hooks */ + status = sysfs_create_group(&client->dev.kobj, &as9726_32d_fan_group); + if (status) + goto exit_free; + + data->hwmon_dev = hwmon_device_register_with_info(&client->dev, + "as9726_32d_fan", + NULL, NULL, NULL); + + if (IS_ERR(data->hwmon_dev)) { + status = PTR_ERR(data->hwmon_dev); + goto exit_remove; + } + + dev_info(&client->dev, "%s: fan '%s'\n", + dev_name(data->hwmon_dev), client->name); + + return 0; + +exit_remove: + sysfs_remove_group(&client->dev.kobj, &as9726_32d_fan_group); +exit_free: + kfree(data); +exit: + + return status; +} + +static int as9726_32d_fan_remove(struct i2c_client *client) +{ + struct as9726_32d_fan_data *data = i2c_get_clientdata(client); + hwmon_device_unregister(data->hwmon_dev); + sysfs_remove_group(&client->dev.kobj, &as9726_32d_fan_group); + return 0; +} + +/* Addresses to scan */ +static const unsigned short normal_i2c[] = { 0x66, I2C_CLIENT_END }; + +static const struct i2c_device_id as9726_32d_fan_id[] = { + { "as9726_32d_fan", 0 }, + {} +}; +MODULE_DEVICE_TABLE(i2c, as9726_32d_fan_id); + +static struct i2c_driver as9726_32d_fan_driver = { + .class = I2C_CLASS_HWMON, + .driver = { + .name = DRVNAME, + }, + .probe = as9726_32d_fan_probe, + .remove = as9726_32d_fan_remove, + .id_table = as9726_32d_fan_id, + .address_list = normal_i2c, +}; + +module_i2c_driver(as9726_32d_fan_driver); + +MODULE_AUTHOR("Alex Lai "); +MODULE_DESCRIPTION("as9726_32d_fan driver"); +MODULE_LICENSE("GPL"); diff --git a/packages/platforms/accton/x86-64/as9726-32d/modules/builds/src/x86-64-accton-as9726-32d-leds.c b/packages/platforms/accton/x86-64/as9726-32d/modules/builds/src/x86-64-accton-as9726-32d-leds.c new file mode 100644 index 000000000..f6831d358 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/modules/builds/src/x86-64-accton-as9726-32d-leds.c @@ -0,0 +1,456 @@ +/* + * A LED driver for the accton_as9726_32d_led + * + * Copyright (C) 2014 Accton Technology Corporation. + * Alex Lai + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/*#define DEBUG*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +extern int as9726_32d_cpld_read (unsigned short cpld_addr, u8 reg); +extern int as9726_32d_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); + +#define DRVNAME "accton_as9726_32d_led" + +struct accton_as9726_32d_led_data { + struct platform_device *pdev; + struct mutex update_lock; + char valid; /* != 0 if registers are valid */ + unsigned long last_updated; /* In jiffies */ + u8 reg_val[2]; /* only 1 register*/ +}; + +static struct accton_as9726_32d_led_data *ledctl = NULL; + +/* LED related data + */ + +#define LED_CNTRLER_I2C_ADDRESS (0x61) + +#define LED_TYPE_DIAG_REG_MASK (0x1|0x2|0x4) +#define LED_MODE_DIAG_GREEN_VALUE (0x01) +#define LED_MODE_DIAG_AMBER_VALUE (0x02) /*It's yellow actually. Green+Red=Yellow*/ +#define LED_MODE_DIAG_GREEN_BLINK_VALUE (0x05) +#define LED_MODE_DIAG_OFF_VALUE (0x0) + + +#define LED_TYPE_LOC_REG_MASK (0x80|0x40) +#define LED_MODE_LOC_BLINK_VALUE 0x80 +#define LED_MODE_LOC_AMBER_VALUE 0x40 +#define LED_MODE_LOC_OFF_VALUE (0x0) + +#define LED_TYPE_FAN_REG_MASK (0x20|0x10) +#define LED_MODE_FAN_AMBER_VALUE 0x20 +#define LED_MODE_FAN_GREEN_VALUE 0x10 +#define LED_MODE_FAN_OFF_VALUE (0x0) + +#define LED_TYPE_PSU2_REG_MASK (0x8|0x4) +#define LED_MODE_PSU2_AMBER_VALUE 0x8 +#define LED_MODE_PSU2_GREEN_VALUE 0x4 +#define LED_MODE_PSU2_OFF_VALUE (0x0) + +#define LED_TYPE_PSU1_REG_MASK (0x2|0x1) +#define LED_MODE_PSU1_AMBER_VALUE 0x2 +#define LED_MODE_PSU1_GREEN_VALUE 0x1 +#define LED_MODE_PSU1_OFF_VALUE (0x0) + +enum led_type { + LED_TYPE_DIAG, + LED_TYPE_LOC, + LED_TYPE_FAN, + LED_TYPE_PSU1, + LED_TYPE_PSU2 +}; + +struct led_reg { + u32 types; + u8 reg_addr; +}; + +static const struct led_reg led_reg_map[] = { + {(1<update_lock); + + if (time_after(jiffies, ledctl->last_updated + HZ + HZ / 2) + || !ledctl->valid) { + int i; + + dev_dbg(&ledctl->pdev->dev, + "Starting accton_as9726_32d_led update\n"); + + /* Update LED data + */ + for (i = 0; i < ARRAY_SIZE(ledctl->reg_val); i++) { + int status = + accton_as9726_32d_led_read_value( + led_reg_map[i].reg_addr); + + if (status < 0) { + ledctl->valid = 0; + dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", + led_reg_map[i].reg_addr, status); + goto exit; + } else { + ledctl->reg_val[i] = status; + } + } + + ledctl->last_updated = jiffies; + ledctl->valid = 1; + } + +exit: + mutex_unlock(&ledctl->update_lock); +} + +static void accton_as9726_32d_led_set(struct led_classdev *led_cdev, + enum led_brightness led_light_mode, + enum led_type type) +{ + int reg_val; + u8 reg; + mutex_lock(&ledctl->update_lock); + + if (!accton_getLedReg(type, ®)) + dev_dbg(&ledctl->pdev->dev, "Not match item for %d.\n", type); + + reg_val = accton_as9726_32d_led_read_value(reg); + + if (reg_val < 0) { + dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", reg, reg_val); + goto exit; + } + reg_val = led_light_mode_to_reg_val(type, led_light_mode, reg_val); + + accton_as9726_32d_led_write_value(reg, reg_val); + + /* to prevent the slow-update issue */ + ledctl->valid = 0; + +exit: + mutex_unlock(&ledctl->update_lock); +} + + +static void accton_as9726_32d_led_diag_set(struct led_classdev *led_cdev, + enum led_brightness led_light_mode) +{ + accton_as9726_32d_led_set(led_cdev, led_light_mode, LED_TYPE_DIAG); +} + +static enum led_brightness accton_as9726_32d_led_diag_get( + struct led_classdev *cdev) +{ + accton_as9726_32d_led_update(); + return led_reg_val_to_light_mode(LED_TYPE_DIAG, ledctl->reg_val[0]); +} + +static void accton_as9726_32d_led_loc_set(struct led_classdev *led_cdev, + enum led_brightness led_light_mode) +{ + accton_as9726_32d_led_set(led_cdev, led_light_mode, LED_TYPE_LOC); +} + +static enum led_brightness accton_as9726_32d_led_loc_get( + struct led_classdev *cdev) +{ + accton_as9726_32d_led_update(); + return led_reg_val_to_light_mode(LED_TYPE_LOC, ledctl->reg_val[1]); +} + +static void accton_as9726_32d_led_auto_set(struct led_classdev *led_cdev, + enum led_brightness led_light_mode) +{ +} + +static enum led_brightness accton_as9726_32d_led_auto_get( + struct led_classdev *cdev) +{ + return LED_MODE_AUTO; +} + +static struct led_classdev accton_as9726_32d_leds[] = { + [LED_TYPE_DIAG] = { + .name = "accton_as9726_32d_led::diag", + .default_trigger = "unused", + .brightness_set = accton_as9726_32d_led_diag_set, + .brightness_get = accton_as9726_32d_led_diag_get, + .flags = LED_CORE_SUSPENDRESUME, + .max_brightness = LED_MODE_GREEN_BLINK, + }, + [LED_TYPE_LOC] = { + .name = "accton_as9726_32d_led::loc", + .default_trigger = "unused", + .brightness_set = accton_as9726_32d_led_loc_set, + .brightness_get = accton_as9726_32d_led_loc_get, + .flags = LED_CORE_SUSPENDRESUME, + .max_brightness = LED_MODE_AMBER_BLINK, + }, + [LED_TYPE_FAN] = { + .name = "accton_as9726_32d_led::fan", + .default_trigger = "unused", + .brightness_set = accton_as9726_32d_led_auto_set, + .brightness_get = accton_as9726_32d_led_auto_get, + .flags = LED_CORE_SUSPENDRESUME, + .max_brightness = LED_MODE_AUTO, + }, + [LED_TYPE_PSU1] = { + .name = "accton_as9726_32d_led::psu1", + .default_trigger = "unused", + .brightness_set = accton_as9726_32d_led_auto_set, + .brightness_get = accton_as9726_32d_led_auto_get, + .flags = LED_CORE_SUSPENDRESUME, + .max_brightness = LED_MODE_AUTO, + }, + [LED_TYPE_PSU2] = { + .name = "accton_as9726_32d_led::psu2", + .default_trigger = "unused", + .brightness_set = accton_as9726_32d_led_auto_set, + .brightness_get = accton_as9726_32d_led_auto_get, + .flags = LED_CORE_SUSPENDRESUME, + .max_brightness = LED_MODE_AUTO, + }, +}; + +static int accton_as9726_32d_led_suspend(struct platform_device *dev, + pm_message_t state) +{ + int i = 0; + + for (i = 0; i < ARRAY_SIZE(accton_as9726_32d_leds); i++) + led_classdev_suspend(&accton_as9726_32d_leds[i]); + return 0; +} + +static int accton_as9726_32d_led_resume(struct platform_device *dev) +{ + int i = 0; + + for (i = 0; i < ARRAY_SIZE(accton_as9726_32d_leds); i++) + led_classdev_resume(&accton_as9726_32d_leds[i]); + + return 0; +} + +static int accton_as9726_32d_led_probe(struct platform_device *pdev) +{ + int ret, i; + + for (i = 0; i < ARRAY_SIZE(accton_as9726_32d_leds); i++) { + ret = led_classdev_register(&pdev->dev, + &accton_as9726_32d_leds[i]); + + if (ret < 0) + break; + } + + /* Check if all LEDs were successfully registered */ + if (i != ARRAY_SIZE(accton_as9726_32d_leds)) { + int j; + + /* only unregister the LEDs that were successfully registered */ + for (j = 0; j < i; j++) + led_classdev_unregister(&accton_as9726_32d_leds[i]); + } + + return ret; +} + +static int accton_as9726_32d_led_remove(struct platform_device *pdev) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(accton_as9726_32d_leds); i++) + led_classdev_unregister(&accton_as9726_32d_leds[i]); + + return 0; +} + +static struct platform_driver accton_as9726_32d_led_driver = { + .probe = accton_as9726_32d_led_probe, + .remove = accton_as9726_32d_led_remove, + .suspend = accton_as9726_32d_led_suspend, + .resume = accton_as9726_32d_led_resume, + .driver = { + .name = DRVNAME, + .owner = THIS_MODULE, + }, +}; + +static int __init accton_as9726_32d_led_init(void) +{ + int ret; + + ret = platform_driver_register(&accton_as9726_32d_led_driver); + if (ret < 0) + goto exit; + + ledctl = kzalloc(sizeof(struct accton_as9726_32d_led_data), + GFP_KERNEL); + if (!ledctl) { + ret = -ENOMEM; + platform_driver_unregister(&accton_as9726_32d_led_driver); + goto exit; + } + + mutex_init(&ledctl->update_lock); + + ledctl->pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0); + if (IS_ERR(ledctl->pdev)) { + ret = PTR_ERR(ledctl->pdev); + platform_driver_unregister(&accton_as9726_32d_led_driver); + kfree(ledctl); + goto exit; + } + +exit: + return ret; +} + +static void __exit accton_as9726_32d_led_exit(void) +{ + platform_device_unregister(ledctl->pdev); + platform_driver_unregister(&accton_as9726_32d_led_driver); + kfree(ledctl); +} + +module_init(accton_as9726_32d_led_init); +module_exit(accton_as9726_32d_led_exit); + +MODULE_AUTHOR("Alex Lai "); +MODULE_DESCRIPTION("accton_as9726_32d_led driver"); +MODULE_LICENSE("GPL"); diff --git a/packages/platforms/accton/x86-64/as9726-32d/modules/builds/src/x86-64-accton-as9726-32d-psu.c b/packages/platforms/accton/x86-64/as9726-32d/modules/builds/src/x86-64-accton-as9726-32d-psu.c new file mode 100644 index 000000000..adb1c626d --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/modules/builds/src/x86-64-accton-as9726-32d-psu.c @@ -0,0 +1,261 @@ +/* + * An hwmon driver for accton as9726_32d Power Module + * + * Copyright (C) 2014 Accton Technology Corporation. + * Alex Lai + * + * Based on ad7414.c + * Copyright 2006 Stefan Roese , DENX Software Engineering + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX_MODEL_NAME 16 + +static ssize_t show_status(struct device *dev, struct device_attribute *da, + char *buf); +static ssize_t show_model_name(struct device *dev, struct device_attribute *da, + char *buf); +static int as9726_32d_psu_read_block(struct i2c_client *client, u8 command, + u8 *data,int data_len); +extern int as9726_32d_cpld_read(unsigned short cpld_addr, u8 reg); + +/* Addresses scanned + */ +static const unsigned short normal_i2c[] = { 0x50, 0x51, I2C_CLIENT_END }; + +/* Each client has this additional data + */ +struct as9726_32d_psu_data { + struct device *hwmon_dev; + struct mutex update_lock; + char valid; /* !=0 if registers are valid */ + unsigned long last_updated; /* In jiffies */ + u8 index; /* PSU index */ + u8 status; /* Status(present/power_good) register read from CPLD */ + char model_name[MAX_MODEL_NAME]; /* Model name, read from eeprom */ +}; + +static struct as9726_32d_psu_data + *as9726_32d_psu_update_device(struct device *dev); + +enum as9726_32d_psu_sysfs_attributes { + PSU_PRESENT, + PSU_POWER_GOOD +}; + +/* sysfs attributes for hwmon + */ +static SENSOR_DEVICE_ATTR(psu_present, S_IRUGO, show_status, NULL, + PSU_PRESENT); +static SENSOR_DEVICE_ATTR(psu_power_good, S_IRUGO, show_status, NULL, + PSU_POWER_GOOD); + +static struct attribute *as9726_32d_psu_attributes[] = { + &sensor_dev_attr_psu_present.dev_attr.attr, + &sensor_dev_attr_psu_power_good.dev_attr.attr, + NULL +}; + +static ssize_t show_status(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct i2c_client *client = to_i2c_client(dev); + struct as9726_32d_psu_data *data = i2c_get_clientdata(client); + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + u8 status = 0; + + mutex_lock(&data->update_lock); + + data = as9726_32d_psu_update_device(dev); + if (!data->valid) { + mutex_unlock(&data->update_lock); + return sprintf(buf, "0\n"); + } + + if (attr->index == PSU_PRESENT) + status = !(data->status >> (1-data->index) & 0x1); + else /* PSU_POWER_GOOD */ + status = (data->status >> (3-data->index) & 0x1); + + mutex_unlock(&data->update_lock); + return sprintf(buf, "%d\n", status); +} + +static const struct attribute_group as9726_32d_psu_group = { + .attrs = as9726_32d_psu_attributes, +}; + +static int as9726_32d_psu_probe(struct i2c_client *client, + const struct i2c_device_id *dev_id) +{ + struct as9726_32d_psu_data *data; + int status; + + if (!i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_I2C_BLOCK)) { + status = -EIO; + goto exit; + } + + data = kzalloc(sizeof(struct as9726_32d_psu_data), GFP_KERNEL); + if (!data) { + status = -ENOMEM; + goto exit; + } + + i2c_set_clientdata(client, data); + data->valid = 0; + data->index = dev_id->driver_data; + mutex_init(&data->update_lock); + + dev_info(&client->dev, "chip found\n"); + + /* Register sysfs hooks */ + status = sysfs_create_group(&client->dev.kobj, &as9726_32d_psu_group); + if (status) + goto exit_free; + + data->hwmon_dev = hwmon_device_register_with_info(&client->dev, + "as9726_32d_psu", NULL, + NULL, NULL); + + if (IS_ERR(data->hwmon_dev)) { + status = PTR_ERR(data->hwmon_dev); + goto exit_remove; + } + + dev_info(&client->dev, "%s: psu '%s'\n", + dev_name(data->hwmon_dev), client->name); + + return 0; + +exit_remove: + sysfs_remove_group(&client->dev.kobj, &as9726_32d_psu_group); +exit_free: + kfree(data); +exit: + + return status; +} + +static int as9726_32d_psu_remove(struct i2c_client *client) +{ + struct as9726_32d_psu_data *data = i2c_get_clientdata(client); + + hwmon_device_unregister(data->hwmon_dev); + sysfs_remove_group(&client->dev.kobj, &as9726_32d_psu_group); + kfree(data); + return 0; +} + +enum psu_index +{ + as9726_32d_psu1, + as9726_32d_psu2 +}; + +static const struct i2c_device_id as9726_32d_psu_id[] = { + { "as9726_32d_psu1", as9726_32d_psu1 }, + { "as9726_32d_psu2", as9726_32d_psu2 }, + {} +}; +MODULE_DEVICE_TABLE(i2c, as9726_32d_psu_id); + +static struct i2c_driver as9726_32d_psu_driver = { + .class = I2C_CLASS_HWMON, + .driver = { + .name = "as9726_32d_psu", + }, + .probe = as9726_32d_psu_probe, + .remove = as9726_32d_psu_remove, + .id_table = as9726_32d_psu_id, + .address_list = normal_i2c, +}; + +static int as9726_32d_psu_read_block(struct i2c_client *client, u8 command, + u8 *data, int data_len) +{ + int result = 0; + int retry_count = 5; + + while (retry_count) { + + retry_count--; + result = i2c_smbus_read_i2c_block_data(client, command, + data_len, data); + + if (unlikely(result < 0)) { + continue; + } + + if (unlikely(result != data_len)) { + result = -EIO; + continue; + } + + result = 0; + break; + } + + return result; +} + +static struct as9726_32d_psu_data *as9726_32d_psu_update_device( + struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct as9726_32d_psu_data *data = i2c_get_clientdata(client); + + + if (time_after(jiffies, data->last_updated + HZ + HZ / 2) + || !data->valid) { + int status; + int power_good = 0; + + dev_dbg(&client->dev, "Starting as9726_32d update\n"); + + /* Read psu status */ + status = as9726_32d_cpld_read(0x60, 0x3); + + if (status < 0) + dev_dbg(&client->dev, "cpld reg 0x60 err %d\n", status); + else + data->status = status; + + data->last_updated = jiffies; + data->valid = 1; + } + + return data; +} + +module_i2c_driver(as9726_32d_psu_driver); + +MODULE_AUTHOR("Alex Lai "); +MODULE_DESCRIPTION("as9726_32d_psu driver"); +MODULE_LICENSE("GPL"); diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/Makefile b/packages/platforms/accton/x86-64/as9726-32d/onlp/Makefile new file mode 100644 index 000000000..003238cf6 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/PKG.yml b/packages/platforms/accton/x86-64/as9726-32d/onlp/PKG.yml new file mode 100644 index 000000000..092221ea5 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/onlp-platform-any.yml PLATFORM=x86-64-accton-as9726-32d ARCH=amd64 TOOLCHAIN=x86_64-linux-gnu diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/Makefile b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/Makefile new file mode 100644 index 000000000..e7437cb23 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/Makefile @@ -0,0 +1,2 @@ +FILTER=src +include $(ONL)/make/subdirs.mk diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/lib/Makefile b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/lib/Makefile new file mode 100644 index 000000000..485c2a26c --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/lib/Makefile @@ -0,0 +1,2 @@ +PLATFORM := x86-64-accton-as9726-32d +include $(ONL)/packages/base/any/onlp/builds/platform/libonlp-platform.mk diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/onlpdump/Makefile b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/onlpdump/Makefile new file mode 100644 index 000000000..dfb9093c3 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/onlpdump/Makefile @@ -0,0 +1,2 @@ +PLATFORM := x86-64-accton-as9726-32d +include $(ONL)/packages/base/any/onlp/builds/platform/onlps.mk diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/.gitignore b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/.gitignore new file mode 100644 index 000000000..faf378142 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/.gitignore @@ -0,0 +1 @@ +x86_64_accton_as9726_32d.mk diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/.module b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/.module new file mode 100644 index 000000000..7c8491ed4 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/.module @@ -0,0 +1 @@ +name: x86_64_accton_as9726_32d diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/Makefile b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/Makefile new file mode 100644 index 000000000..1f70f1157 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/Makefile @@ -0,0 +1,9 @@ +############################################################################### +# +# +# +############################################################################### +include $(ONL)/make/config.mk +MODULE := x86_64_accton_as9726_32d +AUTOMODULE := x86_64_accton_as9726_32d +include $(BUILDER)/definemodule.mk diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/README b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/README new file mode 100644 index 000000000..005083184 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/README @@ -0,0 +1,6 @@ +############################################################################### +# +# x86_64_accton_as9726_32x README +# +############################################################################### + diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/auto/make.mk b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/auto/make.mk new file mode 100644 index 000000000..ac7421c2d --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/auto/make.mk @@ -0,0 +1,8 @@ +############################################################################### +# +# x86_64_accton_as9726_32d Autogeneration +# +############################################################################### +x86_64_accton_as9726_32d_AUTO_DEFS := module/auto/x86_64_accton_as9726_32d.yml +x86_64_accton_as9726_32d_AUTO_DIRS := module/inc/x86_64_accton_as9726_32d module/src +include $(BUILDER)/auto.mk diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/auto/x86_64_accton_as9726_32d.yml b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/auto/x86_64_accton_as9726_32d.yml new file mode 100644 index 000000000..7c04c5e43 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/auto/x86_64_accton_as9726_32d.yml @@ -0,0 +1,50 @@ +############################################################################### +# +# x86_64_accton_as9726_32d Autogeneration Definitions. +# +############################################################################### + +cdefs: &cdefs +- X86_64_ACCTON_AS9726_32D_CONFIG_INCLUDE_LOGGING: + doc: "Include or exclude logging." + default: 1 +- X86_64_ACCTON_AS9726_32D_CONFIG_LOG_OPTIONS_DEFAULT: + doc: "Default enabled log options." + default: AIM_LOG_OPTIONS_DEFAULT +- X86_64_ACCTON_AS9726_32D_CONFIG_LOG_BITS_DEFAULT: + doc: "Default enabled log bits." + default: AIM_LOG_BITS_DEFAULT +- X86_64_ACCTON_AS9726_32D_CONFIG_LOG_CUSTOM_BITS_DEFAULT: + doc: "Default enabled custom log bits." + default: 0 +- X86_64_ACCTON_AS9726_32D_CONFIG_PORTING_STDLIB: + doc: "Default all porting macros to use the C standard libraries." + default: 1 +- X86_64_ACCTON_AS9726_32D_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS: + doc: "Include standard library headers for stdlib porting macros." + default: X86_64_ACCTON_AS9726_32D_CONFIG_PORTING_STDLIB +- X86_64_ACCTON_AS9726_32D_CONFIG_INCLUDE_UCLI: + doc: "Include generic uCli support." + default: 0 +- X86_64_ACCTON_AS9726_32D_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION: + doc: "Assume chassis fan direction is the same as the PSU fan direction." + default: 0 + + +definitions: + cdefs: + X86_64_ACCTON_AS9726_32D_CONFIG_HEADER: + defs: *cdefs + basename: x86_64_accton_as9726_32d_config + + portingmacro: + x86_64_accton_as9726_32d: + macros: + - malloc + - free + - memset + - memcpy + + - vsnprintf + - snprintf + - strlen diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/inc/x86_64_accton_as9726_32d/x86_64_accton_as9726_32d.x b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/inc/x86_64_accton_as9726_32d/x86_64_accton_as9726_32d.x new file mode 100644 index 000000000..b6b593dbc --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/inc/x86_64_accton_as9726_32d/x86_64_accton_as9726_32d.x @@ -0,0 +1,14 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +/* <--auto.start.xmacro(ALL).define> */ +/* */ + +/* <--auto.start.xenum(ALL).define> */ +/* */ + + diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/inc/x86_64_accton_as9726_32d/x86_64_accton_as9726_32d_config.h b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/inc/x86_64_accton_as9726_32d/x86_64_accton_as9726_32d_config.h new file mode 100644 index 000000000..1cc4a64f4 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/inc/x86_64_accton_as9726_32d/x86_64_accton_as9726_32d_config.h @@ -0,0 +1,137 @@ +/**************************************************************************//** + * + * @file + * @brief x86_64_accton_as9726_32d Configuration Header + * + * @addtogroup x86_64_accton_as9726_32d-config + * @{ + * + *****************************************************************************/ +#ifndef __X86_64_ACCTON_AS9726_32D_CONFIG_H__ +#define __X86_64_ACCTON_AS9726_32D_CONFIG_H__ + +#ifdef GLOBAL_INCLUDE_CUSTOM_CONFIG +#include +#endif +#ifdef X86_64_ACCTON_AS9726_32D_INCLUDE_CUSTOM_CONFIG +#include +#endif + +/* */ +#include +/** + * X86_64_ACCTON_AS9726_32D_CONFIG_INCLUDE_LOGGING + * + * Include or exclude logging. */ + + +#ifndef X86_64_ACCTON_AS9726_32D_CONFIG_INCLUDE_LOGGING +#define X86_64_ACCTON_AS9726_32D_CONFIG_INCLUDE_LOGGING 1 +#endif + +/** + * X86_64_ACCTON_AS9726_32D_CONFIG_LOG_OPTIONS_DEFAULT + * + * Default enabled log options. */ + + +#ifndef X86_64_ACCTON_AS9726_32D_CONFIG_LOG_OPTIONS_DEFAULT +#define X86_64_ACCTON_AS9726_32D_CONFIG_LOG_OPTIONS_DEFAULT AIM_LOG_OPTIONS_DEFAULT +#endif + +/** + * X86_64_ACCTON_AS9726_32D_CONFIG_LOG_BITS_DEFAULT + * + * Default enabled log bits. */ + + +#ifndef X86_64_ACCTON_AS9726_32D_CONFIG_LOG_BITS_DEFAULT +#define X86_64_ACCTON_AS9726_32D_CONFIG_LOG_BITS_DEFAULT AIM_LOG_BITS_DEFAULT +#endif + +/** + * X86_64_ACCTON_AS9726_32D_CONFIG_LOG_CUSTOM_BITS_DEFAULT + * + * Default enabled custom log bits. */ + + +#ifndef X86_64_ACCTON_AS9726_32D_CONFIG_LOG_CUSTOM_BITS_DEFAULT +#define X86_64_ACCTON_AS9726_32D_CONFIG_LOG_CUSTOM_BITS_DEFAULT 0 +#endif + +/** + * X86_64_ACCTON_AS9726_32D_CONFIG_PORTING_STDLIB + * + * Default all porting macros to use the C standard libraries. */ + + +#ifndef X86_64_ACCTON_AS9726_32D_CONFIG_PORTING_STDLIB +#define X86_64_ACCTON_AS9726_32D_CONFIG_PORTING_STDLIB 1 +#endif + +/** + * X86_64_ACCTON_AS9726_32D_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + * + * Include standard library headers for stdlib porting macros. */ + + +#ifndef X86_64_ACCTON_AS9726_32D_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS +#define X86_64_ACCTON_AS9726_32D_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS X86_64_ACCTON_AS9726_32D_CONFIG_PORTING_STDLIB +#endif + +/** + * X86_64_ACCTON_AS9726_32D_CONFIG_INCLUDE_UCLI + * + * Include generic uCli support. */ + + +#ifndef X86_64_ACCTON_AS9726_32D_CONFIG_INCLUDE_UCLI +#define X86_64_ACCTON_AS9726_32D_CONFIG_INCLUDE_UCLI 0 +#endif + +/** + * X86_64_ACCTON_AS9726_32D_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION + * + * Assume chassis fan direction is the same as the PSU fan direction. */ + + +#ifndef X86_64_ACCTON_AS9726_32D_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION +#define X86_64_ACCTON_AS9726_32D_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION 0 +#endif + + + +/** + * All compile time options can be queried or displayed + */ + +/** Configuration settings structure. */ +typedef struct x86_64_accton_as9726_32d_config_settings_s { + /** name */ + const char* name; + /** value */ + const char* value; +} x86_64_accton_as9726_32d_config_settings_t; + +/** Configuration settings table. */ +/** x86_64_accton_as9726_32d_config_settings table. */ +extern x86_64_accton_as9726_32d_config_settings_t x86_64_accton_as9726_32d_config_settings[]; + +/** + * @brief Lookup a configuration setting. + * @param setting The name of the configuration option to lookup. + */ +const char* x86_64_accton_as9726_32d_config_lookup(const char* setting); + +/** + * @brief Show the compile-time configuration. + * @param pvs The output stream. + */ +int x86_64_accton_as9726_32d_config_show(struct aim_pvs_s* pvs); + +/* */ + +#include "x86_64_accton_as9726_32d_porting.h" + +#endif /* __X86_64_ACCTON_AS9726_32D_CONFIG_H__ */ +/* @} */ diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/inc/x86_64_accton_as9726_32d/x86_64_accton_as9726_32d_dox.h b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/inc/x86_64_accton_as9726_32d/x86_64_accton_as9726_32d_dox.h new file mode 100644 index 000000000..61b87526a --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/inc/x86_64_accton_as9726_32d/x86_64_accton_as9726_32d_dox.h @@ -0,0 +1,26 @@ +/**************************************************************************//** + * + * x86_64_accton_as9726_32d Doxygen Header + * + *****************************************************************************/ +#ifndef __X86_64_ACCTON_AS9726_32D_DOX_H__ +#define __X86_64_ACCTON_AS9726_32D_DOX_H__ + +/** + * @defgroup x86_64_accton_as9726_32d x86_64_accton_as9726_32d - x86_64_accton_as9726_32d Description + * + +The documentation overview for this module should go here. + + * + * @{ + * + * @defgroup x86_64_accton_as9726_32d-x86_64_accton_as9726_32d Public Interface + * @defgroup x86_64_accton_as9726_32d-config Compile Time Configuration + * @defgroup x86_64_accton_as9726_32d-porting Porting Macros + * + * @} + * + */ + +#endif /* __X86_64_ACCTON_AS9726_32D_DOX_H__ */ diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/inc/x86_64_accton_as9726_32d/x86_64_accton_as9726_32d_porting.h b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/inc/x86_64_accton_as9726_32d/x86_64_accton_as9726_32d_porting.h new file mode 100644 index 000000000..c6ec51a4d --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/inc/x86_64_accton_as9726_32d/x86_64_accton_as9726_32d_porting.h @@ -0,0 +1,97 @@ +/**************************************************************************//** + * + * @file + * @brief x86_64_accton_as9726_32d Porting Macros. + * + * @addtogroup x86_64_accton_as9726_32d-porting + * @{ + * + *****************************************************************************/ +#ifndef __X86_64_ACCTON_AS9726_32D_PORTING_H__ +#define __X86_64_ACCTON_AS9726_32D_PORTING_H__ + + +/* */ +#if X86_64_ACCTON_AS9726_32D_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS == 1 +#include +#include +#include +#include +#include +#endif + +#ifndef X86_64_ACCTON_AS9726_32D_MALLOC + #if defined(GLOBAL_MALLOC) + #define X86_64_ACCTON_AS9726_32D_MALLOC GLOBAL_MALLOC + #elif X86_64_ACCTON_AS9726_32D_CONFIG_PORTING_STDLIB == 1 + #define X86_64_ACCTON_AS9726_32D_MALLOC malloc + #else + #error The macro X86_64_ACCTON_AS9726_32D_MALLOC is required but cannot be defined. + #endif +#endif + +#ifndef X86_64_ACCTON_AS9726_32D_FREE + #if defined(GLOBAL_FREE) + #define X86_64_ACCTON_AS9726_32D_FREE GLOBAL_FREE + #elif X86_64_ACCTON_AS9726_32D_CONFIG_PORTING_STDLIB == 1 + #define X86_64_ACCTON_AS9726_32D_FREE free + #else + #error The macro X86_64_ACCTON_AS9726_32D_FREE is required but cannot be defined. + #endif +#endif + +#ifndef X86_64_ACCTON_AS9726_32D_MEMSET + #if defined(GLOBAL_MEMSET) + #define X86_64_ACCTON_AS9726_32D_MEMSET GLOBAL_MEMSET + #elif X86_64_ACCTON_AS9726_32D_CONFIG_PORTING_STDLIB == 1 + #define X86_64_ACCTON_AS9726_32D_MEMSET memset + #else + #error The macro X86_64_ACCTON_AS9726_32D_MEMSET is required but cannot be defined. + #endif +#endif + +#ifndef X86_64_ACCTON_AS9726_32D_MEMCPY + #if defined(GLOBAL_MEMCPY) + #define X86_64_ACCTON_AS9726_32D_MEMCPY GLOBAL_MEMCPY + #elif X86_64_ACCTON_AS9726_32D_CONFIG_PORTING_STDLIB == 1 + #define X86_64_ACCTON_AS9726_32D_MEMCPY memcpy + #else + #error The macro X86_64_ACCTON_AS9726_32D_MEMCPY is required but cannot be defined. + #endif +#endif + +#ifndef X86_64_ACCTON_AS9726_32D_VSNPRINTF + #if defined(GLOBAL_VSNPRINTF) + #define X86_64_ACCTON_AS9726_32D_VSNPRINTF GLOBAL_VSNPRINTF + #elif X86_64_ACCTON_AS9726_32D_CONFIG_PORTING_STDLIB == 1 + #define X86_64_ACCTON_AS9726_32D_VSNPRINTF vsnprintf + #else + #error The macro X86_64_ACCTON_AS9726_32D_VSNPRINTF is required but cannot be defined. + #endif +#endif + +#ifndef X86_64_ACCTON_AS9726_32D_SNPRINTF + #if defined(GLOBAL_SNPRINTF) + #define X86_64_ACCTON_AS9726_32D_SNPRINTF GLOBAL_SNPRINTF + #elif X86_64_ACCTON_AS9726_32D_CONFIG_PORTING_STDLIB == 1 + #define X86_64_ACCTON_AS9726_32D_SNPRINTF snprintf + #else + #error The macro X86_64_ACCTON_AS9726_32D_SNPRINTF is required but cannot be defined. + #endif +#endif + +#ifndef X86_64_ACCTON_AS9726_32D_STRLEN + #if defined(GLOBAL_STRLEN) + #define X86_64_ACCTON_AS9726_32D_STRLEN GLOBAL_STRLEN + #elif X86_64_ACCTON_AS9726_32D_CONFIG_PORTING_STDLIB == 1 + #define X86_64_ACCTON_AS9726_32D_STRLEN strlen + #else + #error The macro X86_64_ACCTON_AS9726_32D_STRLEN is required but cannot be defined. + #endif +#endif + +/* */ + + +#endif /* __X86_64_ACCTON_AS9726_32D_PORTING_H__ */ +/* @} */ diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/make.mk b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/make.mk new file mode 100644 index 000000000..95477e155 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/make.mk @@ -0,0 +1,10 @@ +############################################################################### +# +# +# +############################################################################### +THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) +x86_64_accton_as9726_32d_INCLUDES := -I $(THIS_DIR)inc +x86_64_accton_as9726_32d_INTERNAL_INCLUDES := -I $(THIS_DIR)src +x86_64_accton_as9726_32d_DEPENDMODULE_ENTRIES := init:x86_64_accton_as9726_32d ucli:x86_64_accton_as9726_32d + diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/Makefile b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/Makefile new file mode 100644 index 000000000..1604a56b1 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/Makefile @@ -0,0 +1,9 @@ +############################################################################### +# +# Local source generation targets. +# +############################################################################### + +ucli: + @../../../../tools/uclihandlers.py x86_64_accton_as9726_32d_ucli.c + diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/fani.c b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/fani.c new file mode 100644 index 000000000..51844b979 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/fani.c @@ -0,0 +1,359 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2014 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * Fan Platform Implementation Defaults. + * + ***********************************************************/ +#include +#include "platform_lib.h" + +#define PSU_PREFIX_PATH "/sys/bus/i2c/devices/" + +#define MAX_FAN_SPEED 24800 +#define MAX_PSU_FAN_SPEED 26880 + +enum fan_id { + FAN_1_ON_FAN_BOARD = 1, + FAN_2_ON_FAN_BOARD, + FAN_3_ON_FAN_BOARD, + FAN_4_ON_FAN_BOARD, + FAN_5_ON_FAN_BOARD, + FAN_6_ON_FAN_BOARD, + FAN_1_ON_PSU_1, + FAN_1_ON_PSU_2, +}; + +#define CHASSIS_FAN_INFO(fid) \ +{ \ + { ONLP_FAN_ID_CREATE(FAN_##fid##_ON_FAN_BOARD), \ + "Chassis Fan - "#fid, 0 },\ + 0x0, \ + ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | \ + ONLP_FAN_CAPS_GET_PERCENTAGE, \ + 0, \ + 0, \ + ONLP_FAN_MODE_INVALID,\ +} + +#define PSU_FAN_INFO(pid, fid) \ +{ \ + { ONLP_FAN_ID_CREATE(FAN_##fid##_ON_PSU_##pid), \ + "PSU "#pid" - Fan "#fid, 0 }, \ + 0x0, \ + ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE, \ + 0, \ + 0, \ + ONLP_FAN_MODE_INVALID, \ +} + +/* Static fan information */ +onlp_fan_info_t finfo[] = { + { }, /* Not used */ + CHASSIS_FAN_INFO(1), + CHASSIS_FAN_INFO(2), + CHASSIS_FAN_INFO(3), + CHASSIS_FAN_INFO(4), + CHASSIS_FAN_INFO(5), + CHASSIS_FAN_INFO(6), + PSU_FAN_INFO(1,1), + PSU_FAN_INFO(2,1) +}; + +#define VALIDATE(_id) \ +do { \ + if(!ONLP_OID_IS_FAN(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ +} while(0) + +static int _onlp_fani_info_get_fan(int fid, onlp_fan_info_t* info) +{ + int value; + char path[64] = {0}; + + /* get fan present status + */ + sprintf(path, "%s""fan%d_present", FAN_BOARD_PATH, fid); + DEBUG_PRINT("Fan(%d), present path = (%s)", fid, path); + + if (onlp_file_read_int(&value, path) < 0) { + AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", + path); + return ONLP_STATUS_E_INTERNAL; + } + + if (value == 0) + return ONLP_STATUS_OK; + + info->status |= ONLP_FAN_STATUS_PRESENT; + + + /* get fan fault status (turn on when any one fails) + */ + sprintf(path, "%s""fan%d_fault", FAN_BOARD_PATH, fid); + DEBUG_PRINT("Fan(%d), fault path = (%s)", fid, path); + + if (onlp_file_read_int(&value, path) < 0) { + AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", + path); + return ONLP_STATUS_E_INTERNAL; + } + + if (value > 0) + info->status |= ONLP_FAN_STATUS_FAILED; + + /* get fan direction (both : the same) + */ + sprintf(path, "%s""fan%d_direction", FAN_BOARD_PATH, fid); + DEBUG_PRINT("Fan(%d), direction path = (%s)", fid, path); + + if (onlp_file_read_int(&value, path) < 0) { + AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", + path); + return ONLP_STATUS_E_INTERNAL; + } + + info->status |= value ? ONLP_FAN_STATUS_B2F : ONLP_FAN_STATUS_F2B; + + /* get front fan speed + */ + sprintf(path, "%s""fan%d_front_speed_rpm", FAN_BOARD_PATH, fid); + DEBUG_PRINT("Fan (%d), speed path = (%s)", fid, path); + + if (onlp_file_read_int(&value, path) < 0) { + AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", + path); + return ONLP_STATUS_E_INTERNAL; + } + info->rpm = value; + + /* get rear fan speed + */ + sprintf(path, "%s""fan%d_rear_speed_rpm", FAN_BOARD_PATH, + fid); + DEBUG_PRINT("Fan (%d), rear speed path = (%s)", fid, path); + + if (onlp_file_read_int(&value, path) < 0) { + AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", + path); + return ONLP_STATUS_E_INTERNAL; + } + + /* take the min value from front/rear fan speed + */ + if (info->rpm > value) + info->rpm = value; + + /* get speed percentage from rpm + */ + info->percentage = (info->rpm * 100)/MAX_FAN_SPEED; + + if(info->percentage > 100) + info->percentage = 100; + + return ONLP_STATUS_OK; +} + +static uint32_t _onlp_get_fan_direction_on_psu(int pid) +{ + psu_type_t psu_type; + psu_type = get_psu_type(pid, NULL, 0); + + if((PSU_TYPE_AC_ACBEL_F2B == psu_type) || + (PSU_TYPE_DC_48V_ACBEL_F2B == psu_type) || + (PSU_TYPE_AC_BELPOWER_F2B == psu_type)){ + return ONLP_FAN_STATUS_F2B; + } else if((PSU_TYPE_AC_ACBEL_B2F == psu_type) || + (PSU_TYPE_DC_48V_ACBEL_B2F == psu_type) || + (PSU_TYPE_AC_BELPOWER_B2F == psu_type)){ + return ONLP_FAN_STATUS_B2F; + } else { + return 0; + } + +} + +static int _onlp_fani_info_get_fan_on_psu(int pid, onlp_fan_info_t* info) +{ + int val = 0; + + info->status |= ONLP_FAN_STATUS_PRESENT; + /* get psu power_good */ + if (psu_status_info_get(pid, "psu_power_good", &val) == ONLP_STATUS_OK) { + info->status |= (val != PSU_STATUS_POWER_GOOD) ? ONLP_FAN_STATUS_FAILED : 0; + } + + /* get fan direction + */ + info->status |= _onlp_get_fan_direction_on_psu(pid); + + /* get fan speed + */ + if (psu_pmbus_info_get(pid, "psu_fan1_speed_rpm", &val) == + ONLP_STATUS_OK) { + info->rpm = val; + info->percentage = (info->rpm * 100) / MAX_PSU_FAN_SPEED; + + if (info->percentage > 100) + info->percentage = 100; + } + + return ONLP_STATUS_OK; +} + +/* + * This function will be called prior to all of onlp_fani_* functions. + */ +int onlp_fani_init(void) +{ + return ONLP_STATUS_OK; +} + +int onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* info) +{ + int rc = 0; + int fid; + VALIDATE(id); + + fid = ONLP_OID_ID_GET(id); + *info = finfo[fid]; + + switch (fid) { + case FAN_1_ON_PSU_1: + rc = _onlp_fani_info_get_fan_on_psu(PSU1_ID, info); + break; + case FAN_1_ON_PSU_2: + rc = _onlp_fani_info_get_fan_on_psu(PSU2_ID, info); + break; + case FAN_1_ON_FAN_BOARD: + case FAN_2_ON_FAN_BOARD: + case FAN_3_ON_FAN_BOARD: + case FAN_4_ON_FAN_BOARD: + case FAN_5_ON_FAN_BOARD: + case FAN_6_ON_FAN_BOARD: + rc =_onlp_fani_info_get_fan(fid, info); + break; + default: + rc = ONLP_STATUS_E_INVALID; + break; + } + + return rc; +} + +/* + * This function sets the speed of the given fan in RPM. + * + * This function will only be called if the fan supprots the RPM_SET + * capability. + * + * It is optional if you have no fans at all with this feature. + */ +int onlp_fani_rpm_set(onlp_oid_t id, int rpm) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +/* + * This function sets the fan speed of the given OID as a percentage. + * + * This will only be called if the OID has the PERCENTAGE_SET + * capability. + * + * It is optional if you have no fans at all with this feature. + */ +int onlp_fani_percentage_set(onlp_oid_t id, int p) +{ + int fid; + char *path = NULL; + + VALIDATE(id); + + fid = ONLP_OID_ID_GET(id); + + /* reject p=0 (p=0, stop fan) */ + if (p == 0) + return ONLP_STATUS_E_INVALID; + + switch (fid) { + case FAN_1_ON_PSU_1: + return psu_ym2651y_pmbus_info_set(PSU1_ID, + "psu_fan_duty_cycle_percentage", p); + case FAN_1_ON_PSU_2: + return psu_ym2651y_pmbus_info_set(PSU2_ID, + "psu_fan_duty_cycle_percentage", p); + case FAN_1_ON_FAN_BOARD: + case FAN_2_ON_FAN_BOARD: + case FAN_3_ON_FAN_BOARD: + case FAN_4_ON_FAN_BOARD: + case FAN_5_ON_FAN_BOARD: + case FAN_6_ON_FAN_BOARD: + path = FAN_NODE(fan_duty_cycle_percentage); + break; + default: + return ONLP_STATUS_E_INVALID; + } + + DEBUG_PRINT("Fan path = (%s)", path); + + if (onlp_file_write_int(p, path) != 0) { + AIM_LOG_ERROR("Unable to change duty cycle of fan (%d)\r\n", + fid); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + + +/* + * This function sets the fan speed of the given OID as per + * the predefined ONLP fan speed modes: off, slow, normal, fast, max. + * + * Interpretation of these modes is up to the platform. + * + */ +int onlp_fani_mode_set(onlp_oid_t id, onlp_fan_mode_t mode) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +/* + * This function sets the fan direction of the given OID. + * + * This function is only relevant if the fan OID supports both direction + * capabilities. + * + * This function is optional unless the functionality is available. + */ +int onlp_fani_dir_set(onlp_oid_t id, onlp_fan_dir_t dir) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +/* + * Generic fan ioctl. Optional. + */ +int onlp_fani_ioctl(onlp_oid_t id, va_list vargs) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/ledi.c b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/ledi.c new file mode 100644 index 000000000..89c793561 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/ledi.c @@ -0,0 +1,299 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2014 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include +#include +#include +#include +#include +#include + +#include "platform_lib.h" + +#define prefix_path "/sys/class/leds/accton_as9726_32d_led::" +#define filename "brightness" + +#define VALIDATE(_id) \ +do { \ + if(!ONLP_OID_IS_LED(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ +} while(0) + +/* LED related data + */ +enum onlp_led_id +{ + LED_RESERVED = 0, + LED_DIAG, + LED_LOC, + LED_FAN, + LED_PSU1, + LED_PSU2 +}; + +enum led_light_mode { + LED_MODE_OFF = 0, + LED_MODE_GREEN, + LED_MODE_AMBER, + LED_MODE_RED, + LED_MODE_BLUE, + LED_MODE_GREEN_BLINK, + LED_MODE_AMBER_BLINK, + LED_MODE_RED_BLINK, + LED_MODE_BLUE_BLINK, + LED_MODE_AUTO, + LED_MODE_UNKNOWN +}; + +typedef struct led_light_mode_map { + enum onlp_led_id id; + enum led_light_mode driver_led_mode; + enum onlp_led_mode_e onlp_led_mode; +} led_light_mode_map_t; + +led_light_mode_map_t led_map[] = { + {LED_DIAG, LED_MODE_OFF, ONLP_LED_MODE_OFF}, + {LED_DIAG, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, + {LED_DIAG, LED_MODE_AMBER, ONLP_LED_MODE_ORANGE}, + {LED_DIAG, LED_MODE_GREEN_BLINK, ONLP_LED_MODE_GREEN_BLINKING}, + {LED_LOC, LED_MODE_OFF, ONLP_LED_MODE_OFF}, + {LED_LOC, LED_MODE_AMBER, ONLP_LED_MODE_ORANGE}, + {LED_LOC, LED_MODE_AMBER_BLINK, ONLP_LED_MODE_ORANGE_BLINKING}, + {LED_FAN, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, + {LED_PSU1, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, + {LED_PSU2, LED_MODE_AUTO, ONLP_LED_MODE_AUTO} +}; + +static char last_path[][10] = /* must map with onlp_led_id */ +{ + "reserved", + "diag", + "loc", + "fan", + "psu1", + "psu2" +}; + +/* + * Get the information for the given LED OID. + */ +static onlp_led_info_t linfo[] = +{ + { }, /* Not used */ + { + { ONLP_LED_ID_CREATE(LED_DIAG), "LED 1 (DIAG LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE | + ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING, + }, + { + { ONLP_LED_ID_CREATE(LED_LOC), "LED 2 (LOC LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE | + ONLP_LED_CAPS_ORANGE_BLINKING, + }, + { + { ONLP_LED_ID_CREATE(LED_FAN), "LED 3 (FAN LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_AUTO, + }, + { + { ONLP_LED_ID_CREATE(LED_PSU1), "LED 4 (PSU1 LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_AUTO, + }, + { + { ONLP_LED_ID_CREATE(LED_PSU2), "LED 5 (PSU2 LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_AUTO, + }, +}; + +static int driver_to_onlp_led_mode(enum onlp_led_id id, + enum led_light_mode driver_led_mode) +{ + int i, nsize = sizeof(led_map) / sizeof(led_map[0]); + + for (i = 0; i < nsize; i++) { + if (id == led_map[i].id && driver_led_mode + == led_map[i].driver_led_mode) + return led_map[i].onlp_led_mode; + } + + return 0; +} + +static int onlp_to_driver_led_mode(enum onlp_led_id id, + onlp_led_mode_t onlp_led_mode) +{ + int i, nsize = sizeof(led_map) / sizeof(led_map[0]); + + for (i = 0; i < nsize; i++) { + if (id == led_map[i].id && onlp_led_mode + == led_map[i].onlp_led_mode) + return led_map[i].driver_led_mode; + } + + return 0; +} + +/* + * This function will be called prior to any other onlp_ledi_* functions. + */ +int onlp_ledi_init(void) +{ + return ONLP_STATUS_OK; +} + +/** Get the current character */ +int onlp_ledi_char_get(onlp_oid_t id, char* c) +{ + int lid, value; + char fullpath[PATH_MAX] = {0}; + + VALIDATE(id); + lid = ONLP_OID_ID_GET(id); + + if (!(linfo[lid].caps & ONLP_LED_CAPS_CHAR)) + return ONLP_STATUS_E_UNSUPPORTED; + + /* get fullpath */ + sprintf(fullpath, "%s%s/%s", prefix_path, last_path[lid], + filename); + + /* Get LED character */ + if (onlp_file_read_int(&value, fullpath) < 0) + return ONLP_STATUS_E_INTERNAL; + + switch (value) { + case 0 ... 9: + *c = (value + 48); // convert to number character + break; + case 15: + *c = 46; // convert to dot '.' character + break; + default: + *c = 0; + break; + } + + return ONLP_STATUS_OK; +} + +int onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) +{ + int lid, value; + char fullpath[PATH_MAX] = {0}; + + VALIDATE(id); + lid = ONLP_OID_ID_GET(id); + + /* Set the onlp_oid_hdr_t and capabilities */ + *info = linfo[ONLP_OID_ID_GET(id)]; + + if (linfo[lid].caps & ONLP_LED_CAPS_CHAR) { + int ret = onlp_ledi_char_get(id, &info->character); + + if (ret != ONLP_STATUS_OK) + return ret; + + if (info->character) + info->mode = ONLP_LED_MODE_ON; + + return ret; + } + + /* get fullpath */ + sprintf(fullpath, "%s%s/%s", prefix_path, last_path[lid], + filename); + + /* Get LED mode */ + if (onlp_file_read_int(&value, fullpath) < 0) + return ONLP_STATUS_E_INTERNAL; + + info->mode = driver_to_onlp_led_mode(lid, value); + + /* Set the on/off status */ + if (info->mode != ONLP_LED_MODE_OFF) + info->status |= ONLP_LED_STATUS_ON; + + return ONLP_STATUS_OK; +} + +/* + * Turn an LED on or off. + * + * This function will only be called if the LED OID supports the ONOFF + * capability. + * + * What 'on' means in terms of colors or modes for multimode LEDs is + * up to the platform to decide. This is intended as baseline toggle mechanism. + */ +int onlp_ledi_set(onlp_oid_t id, int on_or_off) +{ + VALIDATE(id); + + if (!on_or_off) + return onlp_ledi_mode_set(id, ONLP_LED_MODE_OFF); + + return ONLP_STATUS_E_UNSUPPORTED; +} + +/* + * This function puts the LED into the given mode. It is a more functional + * interface for multimode LEDs. + * + * Only modes reported in the LED's capabilities will be attempted. + */ +int onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) +{ + int lid; + char fullpath[PATH_MAX] = {0}; + + VALIDATE(id); + lid = ONLP_OID_ID_GET(id); + + if (linfo[lid].caps & ONLP_LED_CAPS_CHAR) + return ONLP_STATUS_E_UNSUPPORTED; + + sprintf(fullpath, "%s%s/%s", prefix_path, last_path[lid], + filename); + + if (onlp_file_write_int(onlp_to_driver_led_mode(lid, mode), fullpath) + != 0) + return ONLP_STATUS_E_INTERNAL; + + return ONLP_STATUS_OK; +} + +/* + * Generic LED ioctl interface. + */ +int onlp_ledi_ioctl(onlp_oid_t id, va_list vargs) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/make.mk b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/make.mk new file mode 100644 index 000000000..fe431ecb5 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/make.mk @@ -0,0 +1,9 @@ +############################################################################### +# +# +# +############################################################################### + +LIBRARY := x86_64_accton_as9726_32d +$(LIBRARY)_SUBDIR := $(dir $(lastword $(MAKEFILE_LIST))) +include $(BUILDER)/lib.mk diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/platform_lib.c b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/platform_lib.c new file mode 100644 index 000000000..049e97d6e --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/platform_lib.c @@ -0,0 +1,236 @@ +#include +#include +#include +#include +#include "platform_lib.h" +#include +#include "x86_64_accton_as9726_32d_log.h" + +#define I2C_PSU_MODEL_NAME_LEN 15 +#define I2C_PSU_FAN_DIR_LEN 3 + +#define AIM_FREE_IF_PTR(p) \ +do \ +{ \ + if (p) { \ + aim_free(p); \ + p = NULL; \ + } \ +} while (0) + +psu_type_t get_psu_type(int id, char* modelname, int modelname_len) +{ + int ret = 0; + char *node = NULL; + char *mn = NULL; + + /* Check AC model name */ + node = (id == PSU1_ID) ? PSU1_AC_PMBUS_NODE(psu_mfr_model) + : PSU2_AC_PMBUS_NODE(psu_mfr_model); + + ret = onlp_file_read_str(&mn, node); + + if (ret <= 0 || ret > I2C_PSU_MODEL_NAME_LEN || mn == NULL) { + AIM_FREE_IF_PTR(mn); + return PSU_TYPE_UNKNOWN; + } + + if (!strncmp(mn, "FSJ001", strlen("FSJ001"))) { + if (modelname) + aim_strlcpy(modelname, mn, strlen(mn) < + (modelname_len-1) ? (strlen(mn)+1) : + (modelname_len-1)); + AIM_FREE_IF_PTR(mn); + + return PSU_TYPE_AC_ACBEL_F2B; + } + + if (!strncmp(mn, "FSJ004", strlen("FSJ004"))) { + if (modelname) + aim_strlcpy(modelname, mn, strlen(mn) < + (modelname_len-1) ? (strlen(mn)+1) : + (modelname_len-1)); + AIM_FREE_IF_PTR(mn); + return PSU_TYPE_AC_ACBEL_B2F; + } + + if (!strncmp(mn, "FSJ035", strlen("FSJ035"))) { + if (modelname) + aim_strlcpy(modelname, mn, strlen(mn) < + (modelname_len-1) ? (strlen(mn)+1) : + (modelname_len-1)); + AIM_FREE_IF_PTR(mn); + return PSU_TYPE_DC_48V_ACBEL_F2B; + } + + + if (!strncmp(mn, "FSJ036", strlen("FSJ036"))) { + if (modelname) + aim_strlcpy(modelname, mn, strlen(mn) < + (modelname_len-1) ? (strlen(mn)+1) : + (modelname_len-1)); + AIM_FREE_IF_PTR(mn); + return PSU_TYPE_DC_48V_ACBEL_B2F; + } + + if (!strncmp(mn, "SPAACTN-02", strlen("SPAACTN-02"))) { + if (modelname) + aim_strlcpy(modelname, mn, strlen(mn) < + (modelname_len-1) ? (strlen(mn)+1) : + (modelname_len-1)); + AIM_FREE_IF_PTR(mn); + return PSU_TYPE_AC_BELPOWER_B2F; + } + + if (!strncmp(mn, "SPAACTN-01", strlen("SPAACTN-01"))) { + if (modelname) + aim_strlcpy(modelname, mn, strlen(mn) < + (modelname_len-1) ? (strlen(mn)+1) : + (modelname_len-1)); + AIM_FREE_IF_PTR(mn); + return PSU_TYPE_AC_BELPOWER_F2B; + } + + AIM_FREE_IF_PTR(mn); + return PSU_TYPE_UNKNOWN; +} + +int psu_pmbus_info_get(int id, char *node, int *value) +{ + int ret = 0; + char path[PSU_NODE_MAX_PATH_LEN] = {0}; + + *value = 0; + + if (PSU1_ID == id) { + sprintf(path, "%s%s", PSU1_AC_PMBUS_PREFIX, node); + } else { + sprintf(path, "%s%s", PSU2_AC_PMBUS_PREFIX, node); + } + + if (onlp_file_read_int(value, path) < 0) { + AIM_LOG_ERROR("Unable to read status from file(%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } + + return ret; +} + +int psu_status_info_get(int id, char *node, int *value) +{ + int ret = 0; + char path[PSU_NODE_MAX_PATH_LEN] = {0}; + + *value = 0; + + if (PSU1_ID == id) + sprintf(path, "%s%s", PSU1_AC_HWMON_PREFIX, node); + else if (PSU2_ID == id) + sprintf(path, "%s%s", PSU2_AC_HWMON_PREFIX, node); + + if (onlp_file_read_int(value, path) < 0) { + AIM_LOG_ERROR("Unable to read status from file(%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } + + return ret; +} + +int psu_ym2651y_pmbus_info_set(int id, char *node, int value) +{ + char path[PSU_NODE_MAX_PATH_LEN] = {0}; + + switch (id) { + case PSU1_ID: + sprintf(path, "%s%s", PSU1_AC_PMBUS_PREFIX, node); + break; + case PSU2_ID: + sprintf(path, "%s%s", PSU2_AC_PMBUS_PREFIX, node); + break; + default: + return ONLP_STATUS_E_UNSUPPORTED; + }; + + if (onlp_file_write_int(value, path) < 0) { + AIM_LOG_ERROR("Unable to write data to file (%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + + + +#define PSU_SERIAL_NUMBER_LEN 18 + +int psu_serial_number_get(int id, char *serial, int serial_len) +{ + int size = 0; + int ret = ONLP_STATUS_OK; + char *prefix = NULL; + + if (serial == NULL || serial_len < PSU_SERIAL_NUMBER_LEN) + return ONLP_STATUS_E_PARAM; + + prefix = (id == PSU1_ID) ? PSU1_AC_PMBUS_PREFIX : PSU2_AC_PMBUS_PREFIX; + + ret = onlp_file_read((uint8_t*)serial, PSU_SERIAL_NUMBER_LEN, &size, + "%s%s", prefix, "psu_mfr_serial"); + + if (ret != ONLP_STATUS_OK || size != PSU_SERIAL_NUMBER_LEN) + return ONLP_STATUS_E_INTERNAL; + + + serial[PSU_SERIAL_NUMBER_LEN] = '\0'; + return ONLP_STATUS_OK; +} + +enum onlp_fan_dir onlp_get_fan_dir(void) +{ + int value = FAN_DIR_F2B; + int i = 0; + char path[64] = {0}; + enum onlp_fan_dir dir = FAN_DIR_F2B; + + for(i = 0; i < CHASSIS_FAN_COUNT; i++) { + sprintf(path, "%s""fan%d_direction", FAN_BOARD_PATH, i+1); + if (onlp_file_read_int(&value, path) < 0) + continue; + + if (value == FAN_DIR_F2B || value == FAN_DIR_B2F) { + dir = value; + break; + } + } + + return dir; +} + +/** + * @brief warm reset for mac + * @param unit_id The warm reset device unit id, should be 0 + * @param reset_dev The warm reset device id, should be 1 ~ (WARM_RESET_MAX-1) + * @param ret return value. + */ +int onlp_data_path_reset(uint8_t unit_id, uint8_t reset_dev) +{ + int ret = ONLP_STATUS_OK; + char *device_id[] = { NULL, "mac" }; + char buf[4] = "1"; + + if (unit_id != 0 || reset_dev >= WARM_RESET_MAX) { + return ONLP_STATUS_E_PARAM; + } + + if (reset_dev == 0) { + return ONLP_STATUS_E_UNSUPPORTED; + } + + /* Reset device */ + ret = onlp_file_write_str(buf, WARM_RESET_FORMAT, device_id[reset_dev]); + if (ret < 0) { + AIM_LOG_ERROR("Reset device-%d:(%s) failed.", reset_dev, device_id[reset_dev]); + } + + return ret; +} diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/platform_lib.h b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/platform_lib.h new file mode 100644 index 000000000..78b0884b2 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/platform_lib.h @@ -0,0 +1,127 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2014 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#ifndef __PLATFORM_LIB_H__ +#define __PLATFORM_LIB_H__ + +#include +#include "x86_64_accton_as9726_32d_log.h" + +#define CHASSIS_FAN_COUNT 6 +#define CHASSIS_THERMAL_COUNT 7 +#define CHASSIS_PSU_COUNT 2 +#define CHASSIS_LED_COUNT 5 + +#define PSU1_ID 1 +#define PSU2_ID 2 + +#define PSU_STATUS_PRESENT 1 +#define PSU_STATUS_POWER_GOOD 1 + +#define PSU_NODE_MAX_INT_LEN 8 +#define PSU_NODE_MAX_PATH_LEN 64 + +#define PSU1_AC_PMBUS_PREFIX "/sys/bus/i2c/devices/9-0058/" +#define PSU2_AC_PMBUS_PREFIX "/sys/bus/i2c/devices/9-0059/" + +#define PSU1_AC_PMBUS_NODE(node) PSU1_AC_PMBUS_PREFIX#node +#define PSU2_AC_PMBUS_NODE(node) PSU2_AC_PMBUS_PREFIX#node + +#define PSU1_AC_HWMON_PREFIX "/sys/bus/i2c/devices/9-0050/" +#define PSU2_AC_HWMON_PREFIX "/sys/bus/i2c/devices/9-0051/" + + +#define PSU1_AC_HWMON_NODE(node) PSU1_AC_HWMON_PREFIX#node +#define PSU2_AC_HWMON_NODE(node) PSU2_AC_HWMON_PREFIX#node + +#define FAN_BOARD_PATH "/sys/bus/i2c/devices/14-0066/" +#define FAN_NODE(node) FAN_BOARD_PATH#node + +#define IDPROM_PATH "/sys/bus/i2c/devices/13-0056/eeprom" +#define WARM_RESET_FORMAT "/sys/bus/i2c/devices/1-0060/reset_mac" + +enum onlp_thermal_id +{ + THERMAL_RESERVED = 0, + THERMAL_CPU_CORE, + THERMAL_1_ON_MAIN_BROAD, + THERMAL_2_ON_MAIN_BROAD, + THERMAL_3_ON_MAIN_BROAD, + THERMAL_4_ON_MAIN_BROAD, + THERMAL_5_ON_MAIN_BROAD, + THERMAL_6_ON_MAIN_BROAD, + THERMAL_1_ON_PSU1, + THERMAL_1_ON_PSU2, + THERMAL_COUNT, +}; + +int psu_pmbus_info_get(int id, char *node, int *value); +int psu_status_info_get(int id, char *node, int *value); +int psu_ym2651y_pmbus_info_set(int id, char *node, int value); + +typedef enum psu_type { + PSU_TYPE_UNKNOWN, + PSU_TYPE_AC_ACBEL_F2B, + PSU_TYPE_AC_ACBEL_B2F, + PSU_TYPE_AC_BELPOWER_F2B, + PSU_TYPE_AC_BELPOWER_B2F, + PSU_TYPE_DC_48V_ACBEL_F2B, + PSU_TYPE_DC_48V_ACBEL_B2F, +} psu_type_t; + +enum onlp_fan_dir { + FAN_DIR_F2B, + FAN_DIR_B2F, + FAN_DIR_COUNT, +}; + +enum reset_dev_type { + WARM_RESET_MAC = 1, + WARM_RESET_MAX +}; + +enum onlp_fan_dir onlp_get_fan_dir(void); + +psu_type_t get_psu_type(int id, char* modelname, int modelname_len); +int psu_serial_number_get(int id, char *serial, int serial_len); + +//#define DEBUG_MODE 1 + +#if (DEBUG_MODE == 1) + #define DEBUG_PRINT(format, ...) printf(format, __VA_ARGS__) +#else + #define DEBUG_PRINT(format, ...) +#endif + +#define AIM_FREE_IF_PTR(p) \ + do \ + { \ + if (p) { \ + aim_free(p); \ + p = NULL; \ + } \ + } while (0) + +#endif /* __PLATFORM_LIB_H__ */ diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/psui.c b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/psui.c new file mode 100644 index 000000000..0eabd6a28 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/psui.c @@ -0,0 +1,188 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2014 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include +//#include +#include +#include "platform_lib.h" + + +#define VALIDATE(_id) \ +do { \ + if(!ONLP_OID_IS_PSU(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ +} while(0) + +int onlp_psui_init(void) +{ + return ONLP_STATUS_OK; +} + +static int psu_data_info_get(onlp_psu_info_t* info) +{ + int val = 0; + int index = ONLP_OID_ID_GET(info->hdr.id); + + if (info->status & ONLP_PSU_STATUS_FAILED) + return ONLP_STATUS_OK; + + /* Set the associated oid_table */ + info->hdr.coids[0] = ONLP_FAN_ID_CREATE(index + CHASSIS_FAN_COUNT); + info->hdr.coids[1] = ONLP_THERMAL_ID_CREATE(index + + CHASSIS_THERMAL_COUNT); + + /* Read voltage, current and power */ + if (psu_pmbus_info_get(index, "psu_v_out", &val) == 0) { + info->mvout = val; + info->caps |= ONLP_PSU_CAPS_VOUT; + } + + if (psu_pmbus_info_get(index, "psu_v_in", &val) == 0) { + info->mvin = val; + info->caps |= ONLP_PSU_CAPS_VIN; + } + + if (psu_pmbus_info_get(index, "psu_i_out", &val) == 0) { + info->miout = val; + info->caps |= ONLP_PSU_CAPS_IOUT; + } + + if (psu_pmbus_info_get(index, "psu_i_in", &val) == 0) { + info->miin = val; + info->caps |= ONLP_PSU_CAPS_IIN; + } + + if (psu_pmbus_info_get(index, "psu_p_out", &val) == 0) { + info->mpout = val; + info->caps |= ONLP_PSU_CAPS_POUT; + } + + if (psu_pmbus_info_get(index, "psu_p_in", &val) == 0) { + info->mpin = val; + info->caps |= ONLP_PSU_CAPS_PIN; + } + + if(info->status & ONLP_PSU_STATUS_UNPLUGGED) { + info->mvout = 0; + info->mvin = 0; + info->miout = 0; + info->miin = 0; + info->mpout = 0; + info->mpin = 0; + } + + psu_serial_number_get(index, info->serial, sizeof(info->serial)); + + return ONLP_STATUS_OK; +} + +/* + * Get all information about the given PSU oid. + */ +static onlp_psu_info_t pinfo[] = +{ + { }, /* Not used */ + { + { ONLP_PSU_ID_CREATE(PSU1_ID), "PSU-1", 0 }, + }, + { + { ONLP_PSU_ID_CREATE(PSU2_ID), "PSU-2", 0 }, + } +}; + +int onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) +{ + int val = 0; + int ret = ONLP_STATUS_OK; + int index = ONLP_OID_ID_GET(id); + psu_type_t psu_type; + + VALIDATE(id); + + memset(info, 0, sizeof(onlp_psu_info_t)); + *info = pinfo[index]; /* Set the onlp_oid_hdr_t */ + + /* Get the present state */ + if (psu_status_info_get(index, "psu_present", &val) != 0) + AIM_LOG_ERROR("Unable to read PSU(%d) node(psu_present)\r\n", + index); + + if (val != PSU_STATUS_PRESENT) { + info->status &= ~ONLP_PSU_STATUS_PRESENT; + return ONLP_STATUS_OK; + } + + info->status |= ONLP_PSU_STATUS_PRESENT; + + /* Get power good status */ + if (psu_status_info_get(index, "psu_power_good", &val) != 0) + AIM_LOG_ERROR("Unable to read PSU(%d) node(psu_power_good)\r\n", + index); + + /* Get PSU type + */ + psu_type = get_psu_type(index, info->model, sizeof(info->model)); + + switch (psu_type) { + case PSU_TYPE_AC_ACBEL_F2B: + case PSU_TYPE_AC_ACBEL_B2F: + case PSU_TYPE_AC_BELPOWER_F2B: + case PSU_TYPE_AC_BELPOWER_B2F: + info->caps = ONLP_PSU_CAPS_AC; + ret = psu_data_info_get(info); + break; + case PSU_TYPE_DC_48V_ACBEL_F2B: + case PSU_TYPE_DC_48V_ACBEL_B2F: + info->caps = ONLP_PSU_CAPS_DC48; + ret = psu_data_info_get(info); + break; + case PSU_TYPE_UNKNOWN: /* User insert a unknown PSU or unplugged.*/ + /* Set the associated oid_table */ + info->hdr.coids[0] = ONLP_FAN_ID_CREATE(index + CHASSIS_FAN_COUNT); + info->hdr.coids[1] = ONLP_THERMAL_ID_CREATE(index + CHASSIS_THERMAL_COUNT); + + info->status |= ONLP_PSU_STATUS_UNPLUGGED; + info->status &= ~ONLP_PSU_STATUS_FAILED; + ret = ONLP_STATUS_OK; + break; + default: + ret = ONLP_STATUS_E_UNSUPPORTED; + break; + } + + if (val != PSU_STATUS_POWER_GOOD){ + info->status |= ONLP_PSU_STATUS_UNPLUGGED; + info->caps = 0; + } + + return ret; +} + +int onlp_psui_ioctl(onlp_oid_t pid, va_list vargs) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/sfpi.c b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/sfpi.c new file mode 100644 index 000000000..033bbb77b --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/sfpi.c @@ -0,0 +1,570 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2013 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include +#include +#include "x86_64_accton_as9726_32d_int.h" +#include "x86_64_accton_as9726_32d_log.h" + +#define PORT_BUS_INDEX(port) (port+18) + +#define PORT_EEPROM_FORMAT "/sys/bus/i2c/devices/%d-0050/eeprom" +#define MODULE_PRESENT_FORMAT \ + "/sys/bus/i2c/devices/%d-00%d/module_present_%d" +#define MODULE_RXLOS_FORMAT \ + "/sys/bus/i2c/devices/%d-00%d/module_rx_los_%d" +#define MODULE_TXFAULT_FORMAT \ + "/sys/bus/i2c/devices/%d-00%d/module_tx_fault_%d" +#define MODULE_TXDISABLE_FORMAT \ + "/sys/bus/i2c/devices/%d-00%d/module_tx_disable_%d" +#define MODULE_RESET_FORMAT \ + "/sys/bus/i2c/devices/%d-00%d/module_reset_%d" +#define MODULE_LPMODE_FORMAT \ + "/sys/bus/i2c/devices/%d-00%d/module_lpmode_%d" +#define MODULE_PRESENT_ALL_ATTR \ + "/sys/bus/i2c/devices/%d-00%d/module_present_all" +#define MODULE_RXLOS_ALL_ATTR_CPLD \ + "/sys/bus/i2c/devices/10-0062/module_rx_los_all" + +/* QSFP device address of eeprom */ +#define PORT_EEPROM_DEVADDR 0x50 + +/* QSFP eeprom offsets*/ +#define QSFP_EEPROM_OFFSET_IDENTIFIER 0x0 +#define QSFP_EEPROM_OFFSET_TXDIS 0x56 +#define QSFP_EEPROM_OFFSET_BANK_SELECT 0x7E +#define QSFP_EEPROM_OFFSET_PAGE_SELECT 0x7F + +/* QSFP DD Specific*/ +#define QSFP_DD_IDENTIFIER 0x18 +#define QSFP_DD_PAGE_ADMIN_INFO 0x0 +#define QSFP_DD_PAGE_ADVERTISING 0x1 +#define QSFP_DD_PAGE_LANE_CTRL 0x10 +#define QSFP_DD_P01H_OFFSET_CONTROL_1 0x9B +#define QSFP_DD_P01H_TX_DISABLE_SUPPORT 0x2 +#define QSFP_DD_P10H_OFFSET_OUTPUT_DISABLE_TX 0x82 + +int sfp_map_bus[] = {17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, + 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, + 49, 50}; + +/************************************************************ + * + * SFPI Entry Points + * + ***********************************************************/ + +int onlp_sfpi_init(void) +{ + /* Called at initialization time */ + return ONLP_STATUS_OK; +} + +int onlp_sfpi_map_bus_index(int port) +{ + if (port < 0 || port >= 34) + return ONLP_STATUS_E_INTERNAL; + return sfp_map_bus[port]; +} + +int onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap) +{ + /* + * Ports {0, 34} + */ + int p; + + for (p = 0; p < 34; p++) + AIM_BITMAP_SET(bmap, p); + + return ONLP_STATUS_OK; +} + +int onlp_sfpi_is_present(int port) +{ + /* + * Return 1 if present. + * Return 0 if not present. + * Return < 0 if error. + */ + int present; + int bus, addr; + + if (port < 0 || port > 34) + return ONLP_STATUS_E_INTERNAL; + + if (port < 16) { + addr = 61; + bus = 10; + + if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, bus, + addr, (port+1)) < 0) { + AIM_LOG_ERROR("Unable to read present status from port(%d)\r\n" + , port); + return ONLP_STATUS_E_INTERNAL; + } + } else { + addr = 62; + bus = 10; + + if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, bus, + addr, (port+1)) < 0) { + AIM_LOG_ERROR("Unable to read present status from port(%d)\r\n" + , port); + return ONLP_STATUS_E_INTERNAL; + } + } + + return present; +} + +int onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) +{ + uint32_t bytes[5], *ptr = NULL; + FILE* fp; + int addr = 61; + int bus = 10; + char file[64] = {0}; + int count; + + ptr = bytes; + sprintf(file, MODULE_PRESENT_ALL_ATTR, bus, addr); + fp = fopen(file, "r"); + if (fp == NULL) { + AIM_LOG_ERROR("Unable to open the module_present_all device file of CPLD2."); + return ONLP_STATUS_E_INTERNAL; + } + + count = fscanf(fp, "%x %x", ptr+0, ptr+1); + fclose(fp); + if (count != 2) { + /* Likely a CPLD read timeout. */ + AIM_LOG_ERROR("Unable to read all fields the module_present_all device file of CPLD2."); + return ONLP_STATUS_E_INTERNAL; + } + + addr = 62; + + sprintf(file, MODULE_PRESENT_ALL_ATTR, bus, addr); + fp = fopen(file, "r"); + if (fp == NULL) { + AIM_LOG_ERROR("Unable to open the module_present_all device file of CPLD3."); + return ONLP_STATUS_E_INTERNAL; + } + + count = fscanf(fp, "%x %x %x", ptr+2, ptr+3, ptr+4); + fclose(fp); + if (count != 3) { + /* Likely a CPLD read timeout. */ + AIM_LOG_ERROR("Unable to read all fields the module_present_all device file of CPLD3."); + return ONLP_STATUS_E_INTERNAL; + } + + /* Convert to 64 bit integer in port order */ + uint64_t presence_all = 0 ; + int i = 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_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) +{ + uint32_t bytes[5]; + uint32_t *ptr = bytes; + FILE* fp; + + int addr = 60, i = 0; + + fp = fopen(MODULE_RXLOS_ALL_ATTR_CPLD, "r"); + if (fp == NULL) { + AIM_LOG_ERROR("Unable to open the module_rx_los_all device file of CPLD(0x%d)" + , addr); + return ONLP_STATUS_E_INTERNAL; + } + + int count = fscanf(fp, "%x %x %x %x %x", ptr+0, ptr+1, ptr+2, ptr+3, + ptr+4); + fclose(fp); + if (count != 5) { + /* Likely a CPLD read timeout. */ + AIM_LOG_ERROR("Unable to read all fields from the module_rx_los_all device file of CPLD(0x%d)" + , addr); + return ONLP_STATUS_E_INTERNAL; + } + + uint64_t rx_los_all = 0; + + for (i = AIM_ARRAYSIZE(bytes)-1; i >= 0; i--) { + rx_los_all <<= 8; + rx_los_all |= bytes[i]; + } + + /* Populate bitmap */ + for (i = 0; rx_los_all; i++) { + AIM_BITMAP_MOD(dst, i, (rx_los_all & 1)); + rx_los_all >>= 1; + } + + return ONLP_STATUS_OK; +} + +int onlp_sfpi_eeprom_read(int port, uint8_t data[256]) +{ + /* + * Read the SFP eeprom into data[] + * + * Return MISSING if SFP is missing. + * Return OK if eeprom is read + */ + int size = 0; + if (port < 0 || port > 34) + return ONLP_STATUS_E_INTERNAL; + memset(data, 0, 256); + + if (onlp_file_read(data, 256, &size, PORT_EEPROM_FORMAT, + onlp_sfpi_map_bus_index(port)) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("Unable to read eeprom from port(%d)\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + + if (size != 256) { + AIM_LOG_ERROR("Unable to read eeprom from port(%d), size is different!\r\n", + port); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +int onlp_sfpi_dom_read(int port, uint8_t data[256]) +{ + FILE* fp; + char file[64] = {0}; + + sprintf(file, PORT_EEPROM_FORMAT, onlp_sfpi_map_bus_index(port)); + fp = fopen(file, "r"); + if (fp == NULL) { + AIM_LOG_ERROR("Unable to open the eeprom device file of port(%d)", + port); + return ONLP_STATUS_E_INTERNAL; + } + + if (fseek(fp, 256, SEEK_CUR) != 0) { + fclose(fp); + AIM_LOG_ERROR("Unable to set the file position indicator of port(%d)", + port); + return ONLP_STATUS_E_INTERNAL; + } + + int ret = fread(data, 1, 256, fp); + fclose(fp); + if (ret != 256) { + AIM_LOG_ERROR("Unable to read the module_eeprom device file of port(%d)", + port); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +int onlp_sfpi_dev_readb(int port, uint8_t devaddr, uint8_t addr) +{ + int bus = onlp_sfpi_map_bus_index(port); + return onlp_i2c_readb(bus, devaddr, addr, ONLP_I2C_F_FORCE); +} + +int onlp_sfpi_dev_writeb(int port, uint8_t devaddr, uint8_t addr, + uint8_t value) +{ + int bus = onlp_sfpi_map_bus_index(port); + return onlp_i2c_writeb(bus, devaddr, addr, value, ONLP_I2C_F_FORCE); +} + +int onlp_sfpi_dev_readw(int port, uint8_t devaddr, uint8_t addr) +{ + int bus = onlp_sfpi_map_bus_index(port); + return onlp_i2c_readw(bus, devaddr, addr, ONLP_I2C_F_FORCE); +} + +int onlp_sfpi_dev_writew(int port, uint8_t devaddr, uint8_t addr, + uint16_t value) +{ + int bus = onlp_sfpi_map_bus_index(port); + return onlp_i2c_writew(bus, devaddr, addr, value, ONLP_I2C_F_FORCE); +} + +int onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) +{ + int rv; + int addr = 0; + int bus = 10; + int present = 0; + int identifier = 0; + + if (port < 0 || port >= 34){ + return ONLP_STATUS_E_UNSUPPORTED; + } + + switch(control) { + case ONLP_SFP_CONTROL_TX_DISABLE: + case ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL: + if(port >= 0 && port <= 31) { + + present = onlp_sfpi_is_present(port); + if (present == 1){ + + identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER); + if (identifier == QSFP_DD_IDENTIFIER) { + onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADVERTISING); + if (onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_P01H_OFFSET_CONTROL_1) & QSFP_DD_P01H_TX_DISABLE_SUPPORT){ + + onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_BANK_SELECT, 0); + onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_LANE_CTRL); + onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_DD_P10H_OFFSET_OUTPUT_DISABLE_TX, value); + + rv = ONLP_STATUS_OK; + } else { + AIM_LOG_ERROR("Setting tx disable to port(%d) is not supported\r\n", port); + rv = ONLP_STATUS_E_UNSUPPORTED; + } + onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADMIN_INFO); + } else { /* QSFP */ + /* txdis valid bit(bit0-bit3), xxxx 1111 */ + value = value&0xf; + + onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS, value); + + rv = ONLP_STATUS_OK; + } + } else { + rv = ONLP_STATUS_E_INTERNAL; + } + } else { + addr = 62; + if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, + bus, addr, (port + 1)) < 0) { + AIM_LOG_ERROR("Unable to set tx_disable status to port(%d)\r\n", + port); + rv = ONLP_STATUS_E_INTERNAL; + } else { + rv = ONLP_STATUS_OK; + } + } + break; + + case ONLP_SFP_CONTROL_RESET: + if (port >= 0 && port < 16) { + addr = 61; + } else if(port >= 16 && port < 32) { + addr = 62; + } else { + rv = ONLP_STATUS_E_UNSUPPORTED; + break; + } + + if (onlp_file_write_int(value, MODULE_RESET_FORMAT, + bus, addr, (port + 1)) < 0) { + AIM_LOG_ERROR("Unable to set reset status to port(%d)\r\n", + port); + rv = ONLP_STATUS_E_INTERNAL; + } else { + rv = ONLP_STATUS_OK; + } + break; + + case ONLP_SFP_CONTROL_LP_MODE: + if (port >= 0 && port < 16) { + addr = 61; + } else if(port >= 16 && port < 32) { + addr = 62; + } else { + rv = ONLP_STATUS_E_UNSUPPORTED; + break; + } + + if (onlp_file_write_int(value, MODULE_LPMODE_FORMAT, + bus, addr, (port + 1)) < 0) { + AIM_LOG_ERROR("Unable to set lp mode to port(%d)\r\n", + port); + rv = ONLP_STATUS_E_INTERNAL; + } else { + rv = ONLP_STATUS_OK; + } + break; + + default: + rv = ONLP_STATUS_E_UNSUPPORTED; + break; + } + + return rv; +} + +int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) +{ + int rv; + int addr = 0; + int bus = 10; + int present = 0; + int identifier = 0; + int tx_dis = 0; + + if (port < 0 || port >= 34){ + return ONLP_STATUS_E_UNSUPPORTED; + } + + switch (control) { + case ONLP_SFP_CONTROL_RX_LOS: + if (port == 32 || port == 33) { + addr = 62; + if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, + bus, addr, (port+1)) < 0) { + AIM_LOG_ERROR("Unable to read rx_loss status from port(%d)\r\n", + port); + rv = ONLP_STATUS_E_INTERNAL; + } else { + rv = ONLP_STATUS_OK; + } + } else { + rv = ONLP_STATUS_E_UNSUPPORTED; + } + break; + + case ONLP_SFP_CONTROL_TX_FAULT: + if (port == 32 || port == 33) { + addr = 62; + if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT, + bus, addr, (port+1)) < 0) { + AIM_LOG_ERROR("Unable to read tx_fault status from port(%d)\r\n", + port); + rv = ONLP_STATUS_E_INTERNAL; + } else { + rv = ONLP_STATUS_OK; + } + } else { + rv = ONLP_STATUS_E_UNSUPPORTED; + } + break; + + case ONLP_SFP_CONTROL_TX_DISABLE: + case ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL: + if (port >= 0 && port <= 31) { + + present = onlp_sfpi_is_present(port); + if (present == 1) { + + identifier = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_IDENTIFIER); + if (identifier == QSFP_DD_IDENTIFIER) { + onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_BANK_SELECT, 0); + onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_LANE_CTRL); + tx_dis = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_DD_P10H_OFFSET_OUTPUT_DISABLE_TX); + + onlp_sfpi_dev_writeb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_PAGE_SELECT, QSFP_DD_PAGE_ADMIN_INFO); + } else { /* QSFP */ + tx_dis = onlp_sfpi_dev_readb(port, PORT_EEPROM_DEVADDR, QSFP_EEPROM_OFFSET_TXDIS); + } + *value = tx_dis; + + rv = ONLP_STATUS_OK; + } else { + rv = ONLP_STATUS_E_INTERNAL; + } + } else { /* SFP */ + addr = 62; + if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT, + bus, addr, (port+1)) < 0) { + AIM_LOG_ERROR("Unable to read tx_disabled status from port(%d)\r\n", + port); + rv = ONLP_STATUS_E_INTERNAL; + } else { + rv = ONLP_STATUS_OK; + } + } + break; + + case ONLP_SFP_CONTROL_RESET: + if (port >= 0 && port < 16) { + addr = 61; + } else if(port >= 16 && port < 32) { + addr = 62; + } else { + rv = ONLP_STATUS_E_UNSUPPORTED; + break; + } + + if (onlp_file_read_int(value, MODULE_RESET_FORMAT, + bus, addr, (port + 1)) < 0) { + AIM_LOG_ERROR("Unable to get reset status to port(%d)\r\n", + port); + rv = ONLP_STATUS_E_INTERNAL; + } else { + rv = ONLP_STATUS_OK; + } + break; + + case ONLP_SFP_CONTROL_LP_MODE: + if (port >= 0 && port < 16) { + addr = 61; + } else if(port >= 16 && port < 32) { + addr = 62; + } else { + rv = ONLP_STATUS_E_UNSUPPORTED; + break; + } + + if (onlp_file_read_int(value, MODULE_LPMODE_FORMAT, + bus, addr, (port + 1)) < 0) { + AIM_LOG_ERROR("Unable to get lp mode to port(%d)\r\n", + port); + rv = ONLP_STATUS_E_INTERNAL; + } else { + rv = ONLP_STATUS_OK; + } + break; + + default: + rv = ONLP_STATUS_E_UNSUPPORTED; + } + + return rv; +} + +int onlp_sfpi_denit(void) +{ + return ONLP_STATUS_OK; +} diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/sysi.c b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/sysi.c new file mode 100644 index 000000000..a6c33483d --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/sysi.c @@ -0,0 +1,1089 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2014 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include +#include +#include +#include +#include +#include "platform_lib.h" +#include "x86_64_accton_as9726_32d_int.h" +#include "x86_64_accton_as9726_32d_log.h" + +#define NUM_OF_FAN_ON_MAIN_BROAD 6 +#define PREFIX_PATH_ON_CPLD_DEV "/sys/bus/i2c/devices/" +#define NUM_OF_CPLD 5 +#define FAN_DUTY_CYCLE_MAX (100) +#define FAN_DUTY_CYCLE_DEFAULT (FAN_DUTY_CYCLE_MAX) +#define BIOS_VER_PATH "/sys/devices/virtual/dmi/id/bios_version" +/* Number of sensor points considered by the fan/thermal policy */ +#define NUM_THERMAL_POLICY_SENSORS 7 + +static char arr_cplddev_name[NUM_OF_CPLD][10] = +{ + "1-0065", + "1-0060", + "10-0061", + "10-0062", + "14-0066" +}; + +const char* onlp_sysi_platform_get(void) +{ + return "x86-64-accton-as9726-32d-r0"; +} + +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; +} + +int onlp_sysi_oids_get(onlp_oid_t* table, int max) +{ + int i; + onlp_oid_t* e = table; + memset(table, 0, max*sizeof(onlp_oid_t)); + + /* 7 Thermal sensors on the chassis */ + for (i = 1; i <= CHASSIS_THERMAL_COUNT; i++) + *e++ = ONLP_THERMAL_ID_CREATE(i); + + /* 5 LEDs on the chassis */ + for (i = 1; i <= CHASSIS_LED_COUNT; i++) + *e++ = ONLP_LED_ID_CREATE(i); + + /* 2 PSUs on the chassis */ + for (i = 1; i <= CHASSIS_PSU_COUNT; i++) + *e++ = ONLP_PSU_ID_CREATE(i); + + /* 6 Fans on the chassis */ + for (i = 1; i <= CHASSIS_FAN_COUNT; i++) + *e++ = ONLP_FAN_ID_CREATE(i); + + return 0; +} + +int onlp_sysi_platform_info_get(onlp_platform_info_t* pi) +{ + int i, v[NUM_OF_CPLD]={0}; + onlp_onie_info_t onie; + char *bios_ver = NULL; + int onie_ok; + + /* BIOS version */ + onlp_file_read_str(&bios_ver, BIOS_VER_PATH); + /* ONIE version - decode_file does not zero-init onie on open failure */ + memset(&onie, 0, sizeof(onie)); + list_init(&onie.vx_list); + onie_ok = (onlp_onie_decode_file(&onie, IDPROM_PATH) >= 0); + + for (i = 0; i < NUM_OF_CPLD; i++) { + v[i] = 0; + + onlp_file_read_int(v+i, "%s%s/version", PREFIX_PATH_ON_CPLD_DEV, arr_cplddev_name[i]); + } + + pi->cpld_versions = aim_fstrdup("\r\n\t CPU CPLD(0x65): %02X" + "\r\n\t FPGA(0x60): %02X" + "\r\n\t Main CPLD2(0x61): %02X" + "\r\n\t Main CPLD3(0x62): %02X" + "\r\n\t FAN CPLD(0x66): %02X" + , v[0], v[1], v[2], v[3], v[4]); + + pi->other_versions = aim_fstrdup("\r\n\t BIOS: %s\r\n\t ONIE: %s", + bios_ver ? bios_ver : "", + onie.onie_version ? onie.onie_version : ""); + + if (onie_ok) + onlp_onie_info_free(&onie); + AIM_FREE_IF_PTR(bios_ver); + + return 0; +} + +void onlp_sysi_platform_info_free(onlp_platform_info_t* pi) +{ + aim_free(pi->cpld_versions); + aim_free(pi->other_versions); +} + +int onlp_sysi_platform_manage_leds(void) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} +/* + Thermal policy: + a.Defaut fan duty_cycle=100% + b.One fan fail, set to fan duty_cycle=100% + 1.For AFI: + Default fan duty_cycle will be 100%(fan_policy_state=LEVEL_FAN_MAX). + If all below case meet with, set to 75%(LEVEL_FAN_MID). + MB board + (MB board) + LM75-1(0X48)>=49.5 + LM75-2(0X49)>=42.9 + LM75-3(0X4A)>=46.3 + LM75-4(0X4C)>=40.1 + LM75-6(0X4F)>=39.4 + (CPU board) + Core>=46 + LM75-1(0X4B)>=34.8 + + When fan_policy_state=LEVEL_FAN_MID, meet with below case, Fan duty_cycle will be 100%(LEVEL_FAN_DAX) + (MB board) + LM75-1(0X48)>=55.9 + LM75-2(0X49)>=48.8 + LM75-3(0X4A)>=51.5 + LM75-4(0X4C)>=45.3 + LM75-6(0X4F)>=43.4 + (CPU board) + Core>=50 + LM75-1(0X4B)>=43.4 + Transceiver >=65 + + Yellow Alarm + MB board + LM75-1(0X48)>=57.9 + LM75-2(0X49)>=51.9 + LM75-3(0X4A)>=48.9 + LM75-4(0X4C)>=55.9 + LM75-6(0X4F)>=48.5 + CPU Board + Core>=52 + LM75-1(0X4B)>=41.8 + Transceiver >=73 + + Red Alarm + MB board + LM75-1(0X48)>=62.9 + LM75-2(0X49)>=56.9 + LM75-3(0X4A)>=53.9 + LM75-4(0X4C)>=58.9 + LM75-6(0X4F)>=53.5 + CPU Board + Core>=57 + LM75-1(0X4B)>=46.8 + Transceiver >=75 + + Shutdown + MB board + LM75-1(0X48)>=67.9 + LM75-2(0X49)>=61.9 + LM75-3(0X4A)>=58.9 + LM75-4(0X4C)>=63.9 + LM75-6(0X4F)>=58.5 + CPU Board + Core>=62 + LM75-1(0X4B)>=51.8 + Transceiver >=77 + + 2. For AFO: + At default, FAN duty_cycle was 100%(LEVEL_FAN_MAX). If all below case meet with, set to 75%(LEVEL_FAN_MID). + (MB board) + LM75-1(0X48)<=56 + LM75-2(0X49)<=53.5 + LM75-3(0X4A)<=52.5 + LM75-4(0X4C)<=52 + LM75-6(0X4F)<=52.8 + (CPU board) + Core<=62 + LM75-1(0X4B)<=45.8 + + When FAN duty_cycle was 75%(LEVEL_FAN_MID). If all below case meet with, set to 50%. + (MB board) + LM75-1(0X48)<=50 + LM75-2(0X49)<=47.3 + LM75-3(0X4A)<=46.4 + LM75-4(0X4C)<=44.6 + LM75-6(0X4F)<=47 + (CPU board) + Core<=56 + LM75-1(0X4B)<=38.8 + + When fan_speed 50%. + Meet with below case, Fan duty_cycle will be 75%(LEVEL_FAN_MID) + (MB board) + LM75-1(0X48)>=63 + LM75-2(0X49)>=60.5 + LM75-3(0X4A)>=60 + LM75-4(0X4C)>=60 + LM75-6(0X4F)>=61 + (CPU board) + Core>=72 + LM75-1(0X4B)>=50 + Transceiver >=55 + + When FAN duty_cycle was 75%(LEVEL_FAN_MID). If all below case meet with, set to 100%(LEVEL_FAN_MAX). + (MB board) + LM75-1(0X48)>=63 + LM75-2(0X49)>=60 + LM75-3(0X4A)>=60 + LM75-4(0X4C)>=59 + LM75-6(0X4F)>=60 + + (CPU board) + Core >=69 + LM75-1(0X4B)>=51.5 + Transceiver >=65 + + Yellow Alarm + MB board + LM75-1(0X48)>=67 + LM75-2(0X49)>=65 + LM75-3(0X4A)>=64 + LM75-4(0X4C)>=62 + LM75-6(0X4F)>=64 + CPU Board + Core>=73 + LM75-1(0X4B)>=67 + Transceiver >=73 + + Red Alarm + MB board + LM75-1(0X48)>=72 + LM75-2(0X49)>=70 + LM75-3(0X4A)>=69 + LM75-4(0X4C)>=67 + LM75-6(0X4F)>=69 + CPU Board + Core>=78 + LM75-1(0X4B)>=72 + Transceiver >=75 + + Shutdown + MB board + LM75-1(0X48)>=77 + LM75-2(0X49)>=75 + LM75-3(0X4A)>=74 + LM75-4(0X4C)>=72 + LM75-6(0X4F)>=74 + CPU Board + Core>=83 + LM75-1(0X4B)>=77 + Transceiver >=77 +*/ + +/** + * Fan direction enum + * AFI: Air Flow In + * AFO: Air Flow Out + */ +typedef enum { + FAN_DIR_AFI = 0, + FAN_DIR_AFO = 1, + FAN_DIR_MAX = 2 +} fan_direction_t; + +/* Fan Policy States */ +typedef enum { + LEVEL_FAN_INIT = 0, + LEVEL_FAN_MIN = 1, + LEVEL_FAN_MID = 2, + LEVEL_FAN_MAX = 3, + LEVEL_FAN_YELLOW_ALARM = 4, + LEVEL_FAN_RED_ALARM = 5, + LEVEL_FAN_SHUTDOWN = 6 +} fan_policy_level_t; + +/* Sensor Types */ +typedef enum { + TYPE_SENSOR = 0, + TYPE_TRANSCEIVER = 1, + TYPE_MAX = 2 +} sensor_type_t; + +/* Monitor ports for ZR/ZR+ transceivers */ +static int monitor_ports[] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31}; + +/* Fan Policy Configuration */ +typedef struct { + int duty_cycle; + int pwm_value; +} fan_policy_config_t; + +static fan_policy_config_t fan_policy_f2b[] = { /* AFO */ + [LEVEL_FAN_MIN] = {50, 0x7}, + [LEVEL_FAN_MID] = {75, 0xb}, + [LEVEL_FAN_MAX] = {100, 0xf} +}; + +static fan_policy_config_t fan_policy_b2f[] = { /* AFI */ + [LEVEL_FAN_MID] = {75, 0xb}, + [LEVEL_FAN_MAX] = {100, 0xf} +}; + +/* Thermal Specification Structure */ +typedef struct { + int threshold; +} thermal_threshold_t; + +/* Complete Thermal Specification for each sensor/transceiver */ +typedef struct { + onlp_oid_t id; + thermal_threshold_t min_to_mid; /* For AFO only */ + thermal_threshold_t mid_to_max; + thermal_threshold_t max_to_mid; + thermal_threshold_t mid_to_min; /* For AFO only */ + thermal_threshold_t max_to_yellow; + thermal_threshold_t yellow_to_red; + thermal_threshold_t red_to_shutdown; +} thermal_spec_t; + + +static thermal_spec_t thermal_specs[FAN_DIR_MAX][TYPE_MAX][NUM_THERMAL_POLICY_SENSORS] = { + /* AFI */ + [FAN_DIR_AFI] = { + [TYPE_SENSOR] = { + /* LM75-1 (0x48) - MB board */ + { + .id = ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_MAIN_BROAD), + .min_to_mid = {0}, /* AFI doesn't use min state */ + .mid_to_max = {55900}, + .max_to_mid = {49500}, + .mid_to_min = {0}, /* AFI doesn't use min state */ + .max_to_yellow = {57900}, + .yellow_to_red = {62900}, + .red_to_shutdown = {67900} + }, + /* LM75-2 (0x49) - MB board */ + { + .id = ONLP_THERMAL_ID_CREATE(THERMAL_2_ON_MAIN_BROAD), + .min_to_mid = {0}, + .mid_to_max = {48800}, + .max_to_mid = {42900}, + .mid_to_min = {0}, + .max_to_yellow = {51900}, + .yellow_to_red = {56900}, + .red_to_shutdown = {61900} + }, + /* LM75-3 (0x4A) - MB board */ + { + .id = ONLP_THERMAL_ID_CREATE(THERMAL_3_ON_MAIN_BROAD), + .min_to_mid = {0}, + .mid_to_max = {51500}, + .max_to_mid = {46300}, + .mid_to_min = {0}, + .max_to_yellow = {48900}, + .yellow_to_red = {53900}, + .red_to_shutdown = {58900} + }, + /* LM75-4 (0x4C) - MB board */ + { + .id = ONLP_THERMAL_ID_CREATE(THERMAL_5_ON_MAIN_BROAD), + .min_to_mid = {0}, + .mid_to_max = {45300}, + .max_to_mid = {40100}, + .mid_to_min = {0}, + .max_to_yellow = {55900}, + .yellow_to_red = {58900}, + .red_to_shutdown = {63900} + }, + /* LM75-6 (0x4F) - MB board */ + { + .id = ONLP_THERMAL_ID_CREATE(THERMAL_6_ON_MAIN_BROAD), + .min_to_mid = {0}, + .mid_to_max = {43400}, + .max_to_mid = {39400}, + .mid_to_min = {0}, + .max_to_yellow = {48500}, + .yellow_to_red = {53500}, + .red_to_shutdown = {58500} + }, + /* Core - CPU board */ + { + .id = ONLP_THERMAL_ID_CREATE(THERMAL_CPU_CORE), + .min_to_mid = {0}, + .mid_to_max = {50000}, + .max_to_mid = {46000}, + .mid_to_min = {0}, + .max_to_yellow = {52000}, + .yellow_to_red = {57000}, + .red_to_shutdown = {62000} + }, + /* LM75-1 (0x4B) - CPU board */ + { + .id = ONLP_THERMAL_ID_CREATE(THERMAL_4_ON_MAIN_BROAD), + .min_to_mid = {0}, + .mid_to_max = {43400}, + .max_to_mid = {34800}, + .mid_to_min = {0}, + .max_to_yellow = {41800}, + .yellow_to_red = {46800}, + .red_to_shutdown = {51800} + } + }, + [TYPE_TRANSCEIVER] = { + { + .id = 0, + .min_to_mid = {0}, + .mid_to_max = {65000}, + .max_to_mid = {64000}, + .mid_to_min = {0}, + .max_to_yellow = {73000}, + .yellow_to_red = {75000}, + .red_to_shutdown = {77000} + } + } + }, + /* AFO */ + [FAN_DIR_AFO] = { + [TYPE_SENSOR] = { + /* LM75-1 (0x48) - MB board */ + { + .id = ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_MAIN_BROAD), + .min_to_mid = {63000}, + .mid_to_max = {63000}, + .max_to_mid = {56000}, + .mid_to_min = {50000}, + .max_to_yellow = {67000}, + .yellow_to_red = {72000}, + .red_to_shutdown = {77000} + }, + /* LM75-2 (0x49) - MB board */ + { + .id = ONLP_THERMAL_ID_CREATE(THERMAL_2_ON_MAIN_BROAD), + .min_to_mid = {60500}, + .mid_to_max = {60000}, + .max_to_mid = {53500}, + .mid_to_min = {47300}, + .max_to_yellow = {65000}, + .yellow_to_red = {70000}, + .red_to_shutdown = {75000} + }, + /* LM75-3 (0x4A) - MB board */ + { + .id = ONLP_THERMAL_ID_CREATE(THERMAL_3_ON_MAIN_BROAD), + .min_to_mid = {60000}, + .mid_to_max = {60000}, + .max_to_mid = {52500}, + .mid_to_min = {46400}, + .max_to_yellow = {64000}, + .yellow_to_red = {69000}, + .red_to_shutdown = {74000} + }, + /* LM75-4 (0x4C) - MB board */ + { + .id = ONLP_THERMAL_ID_CREATE(THERMAL_5_ON_MAIN_BROAD), + .min_to_mid = {60000}, + .mid_to_max = {59000}, + .max_to_mid = {52000}, + .mid_to_min = {44600}, + .max_to_yellow = {62000}, + .yellow_to_red = {67000}, + .red_to_shutdown = {72000} + }, + /* LM75-6 (0x4F) - MB board */ + { + .id = ONLP_THERMAL_ID_CREATE(THERMAL_6_ON_MAIN_BROAD), + .min_to_mid = {61000}, + .mid_to_max = {60000}, + .max_to_mid = {52800}, + .mid_to_min = {47000}, + .max_to_yellow = {64000}, + .yellow_to_red = {69000}, + .red_to_shutdown = {74000} + }, + /* Core - CPU board */ + { + .id = ONLP_THERMAL_ID_CREATE(THERMAL_CPU_CORE), + .min_to_mid = {72000}, + .mid_to_max = {69000}, + .max_to_mid = {62000}, + .mid_to_min = {56000}, + .max_to_yellow = {73000}, + .yellow_to_red = {78000}, + .red_to_shutdown = {83000} + }, + /* LM75-1 (0x4B) - CPU board */ + { + .id = ONLP_THERMAL_ID_CREATE(THERMAL_4_ON_MAIN_BROAD), + .min_to_mid = {50000}, + .mid_to_max = {51500}, + .max_to_mid = {45800}, + .mid_to_min = {38800}, + .max_to_yellow = {67000}, + .yellow_to_red = {72000}, + .red_to_shutdown = {77000} + } + }, + [TYPE_TRANSCEIVER] = { + { + .id = 0, + .min_to_mid = {55000}, + .mid_to_max = {65000}, + .max_to_mid = {64000}, + .mid_to_min = {54000}, + .max_to_yellow = {73000}, + .yellow_to_red = {75000}, + .red_to_shutdown = {77000} + } + } + } +}; + +/* State machine API for thermal management */ +typedef struct { + sensor_type_t type; + int current_temp; + int port; + thermal_spec_t *spec; + char sensor_name[ONLP_OID_DESC_SIZE]; +} thermal_sensor_data_t; + +typedef struct { + int ori_state; + int new_state; + int max_to_mid_count; + int mid_to_min_count; + int alarm; +} thermal_state_result_t; + +typedef struct thermal_sensor_ops { + const char* name; + int (*get_temp)(int index, fan_direction_t fan_dir, thermal_sensor_data_t *data); + int (*get_count)(fan_direction_t dir); + bool (*should_process)(int index); + bool (*is_critical_error)(int error_code); /* Determine if error is critical */ +} thermal_sensor_ops_t; + +typedef struct { + thermal_sensor_ops_t *ops; + sensor_type_t type; +} sensor_handler_t; + +void onlp_sysi_over_temp_protector(void) +{ + int fpga_ver = 0; + int i; + + for (i = 0; i < AIM_ARRAYSIZE(monitor_ports); i++) { + onlp_sfpi_control_set(monitor_ports[i] - 1, ONLP_SFP_CONTROL_RESET, 1); + } + + if (onlp_file_read_int(&fpga_ver, "%s%s/version", + PREFIX_PATH_ON_CPLD_DEV, "1-0060") < 0) { + AIM_LOG_ERROR("Can not get the FPGA version. (%s%s/version)", + PREFIX_PATH_ON_CPLD_DEV, "1-0060"); + } + + system("sync;sync;sync;"); + system("/sbin/fstrim -av"); + if (fpga_ver >= 9) { + /* Power off main board & Power off cpu */ + system("i2cset -y -f 1 0x60 0x60 0x11 & i2cset -y -f 1 0x65 0x07 0x2c"); + } else { + /* Power-cycle dut */ + system("i2cset -y -f 1 0x60 0x60 0x10"); + } +} + +/* Get fan direction: 1 for B2F (AFI), 2 for F2B (AFO) */ +static fan_direction_t onlp_sysi_get_fan_direction(void) +{ + onlp_fan_info_t fan_info; + int b2f_count = 0, f2b_count = 0; + int i, rv; + + for (i = 1; i <= NUM_OF_FAN_ON_MAIN_BROAD; i++) { + rv = onlp_fani_info_get(ONLP_FAN_ID_CREATE(i), &fan_info); + if (rv < 0) { + continue; + } + + if (!(fan_info.status & ONLP_FAN_STATUS_PRESENT)) { + continue; + } + + if (fan_info.status & ONLP_FAN_STATUS_B2F) { + b2f_count++; + } else { + f2b_count++; + } + } + + return (b2f_count >= f2b_count) ? FAN_DIR_AFI : FAN_DIR_AFO; +} + +int onlp_sysi_get_fan_status(void) +{ + int i, ret; + onlp_fan_info_t fi[CHASSIS_FAN_COUNT]; + memset(fi, 0, sizeof(fi)); + + for (i = 0; i < CHASSIS_FAN_COUNT; i++) { + ret = onlp_fani_info_get(ONLP_FAN_ID_CREATE(i+1), &fi[i]); + if (ret != ONLP_STATUS_OK) { + AIM_LOG_ERROR("Unable to get '%s' status", fi[i].hdr.description); + return ONLP_STATUS_E_INTERNAL; + } + + if (!(fi[i].status & ONLP_FAN_STATUS_PRESENT)) { + AIM_LOG_ERROR("'%s' is NOT present", fi[i].hdr.description); + return ONLP_STATUS_E_INTERNAL; + } + + if (fi[i].status & ONLP_FAN_STATUS_FAILED) { + AIM_LOG_ERROR("'%s' is NOT operational", fi[i].hdr.description); + return ONLP_STATUS_E_INTERNAL; + } + } + + return ONLP_STATUS_OK; +} + +int onlp_sysi_set_fan_duty_all(int duty) +{ + int fid, ret = ONLP_STATUS_OK; + + for (fid = 1; fid <= CHASSIS_FAN_COUNT; fid++) { + if (ONLP_STATUS_OK != onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(fid), duty)) { + ret = ONLP_STATUS_E_INTERNAL; + } + } + + return ret; +} + +int onlp_sysi_get_sff8436_temp(int port, int *temp) +{ + int value; + int16_t port_temp; + + /* Read memory model */ + value = onlp_sfpi_dev_readb(port, 0x50, 0x2); + if (value & 0x04) { + *temp = ONLP_STATUS_E_MISSING; + return ONLP_STATUS_OK; + } + + value = onlp_sfpi_dev_readb(port, 0x50, 22); + if (value < 0) { + *temp = ONLP_STATUS_E_MISSING; + return ONLP_STATUS_OK; + } + port_temp = (int16_t)((value & 0xFF) << 8); + + value = onlp_sfpi_dev_readb(port, 0x50, 23); + if (value < 0) { + *temp = ONLP_STATUS_E_MISSING; + return ONLP_STATUS_OK; + } + port_temp = (port_temp | (int16_t)(value & 0xFF)); + + *temp = (int)port_temp * 1000 / 256; + return ONLP_STATUS_OK; +} + +int onlp_sysi_get_cmis_temp(int port, int *temp) +{ + int value; + int16_t port_temp; + + /* Read memory model */ + value = onlp_sfpi_dev_readb(port, 0x50, 0x2); + if (value & 0x80) { + *temp = ONLP_STATUS_E_MISSING; + return ONLP_STATUS_OK; + } + + value = onlp_sfpi_dev_readb(port, 0x50, 14); + if (value < 0) { + *temp = ONLP_STATUS_E_MISSING; + return ONLP_STATUS_OK; + } + port_temp = (int16_t)((value & 0xFF) << 8); + + value = onlp_sfpi_dev_readb(port, 0x50, 15); + if (value < 0) { + *temp = ONLP_STATUS_E_MISSING; + return ONLP_STATUS_OK; + } + port_temp = (port_temp | (int16_t)(value & 0xFF)); + + *temp = (int)port_temp * 1000 / 256; + return ONLP_STATUS_OK; +} + +int onlp_sysi_get_xcvr_temp(int port) +{ + int ret = ONLP_STATUS_OK; + int current_temp = 0; + int value; + + /* Skip if transceiver not present */ + if (onlp_sfpi_is_present(port) != 1) { + return ONLP_STATUS_E_MISSING; + } + + value = onlp_sfpi_dev_readb(port, 0x50, 0); + if (value < 0) { + AIM_LOG_ERROR("Unable to get read 'Port %02d' eeprom", port); + return ONLP_STATUS_E_MISSING; + } + + if (value == 0x18 || value == 0x19 || value == 0x1E) { + ret = onlp_sysi_get_cmis_temp(port, ¤t_temp); + if (ret == ONLP_STATUS_OK) { + return current_temp; + } + } + else if (value == 0x0C || value == 0x0D || value == 0x11 || value == 0xE1) { + ret = onlp_sysi_get_sff8436_temp(port, ¤t_temp); + if (ret == ONLP_STATUS_OK) { + return current_temp; + } + } + + return ONLP_STATUS_E_MISSING; +} + +static int sensor_get_temp(int index, fan_direction_t fan_dir, thermal_sensor_data_t *data) +{ + int ret; + onlp_thermal_info_t thermal_info; + + data->spec = &thermal_specs[fan_dir][TYPE_SENSOR][index]; + ret = onlp_thermali_info_get(data->spec->id, &thermal_info); + + if (ret != ONLP_STATUS_OK) { + AIM_SYSLOG_WARN("Temperature warning", "Temperature warning", + "Failed to read temperature from sensor '%s' (error: %d)", + thermal_info.hdr.description, ret); + return ret; + } + + data->type = TYPE_SENSOR; + data->current_temp = thermal_info.mcelsius; + snprintf(data->sensor_name, sizeof(data->sensor_name), "%s", thermal_info.hdr.description); + + return ONLP_STATUS_OK; +} + +static int sensor_get_count(fan_direction_t dir) +{ + return AIM_ARRAYSIZE(thermal_specs[dir][TYPE_SENSOR]); +} + +static bool sensor_should_process(int index) +{ + return true; /* Process all sensors */ +} + +/* Sensor critical error check: any error is critical */ +static bool sensor_is_critical_error(int error_code) +{ + return (error_code != ONLP_STATUS_OK); +} + +/* TYPE_TRANSCEIVER implementation */ +static int transceiver_get_temp(int index, fan_direction_t fan_dir, thermal_sensor_data_t *data) +{ + int current_temp; + int port; + + port = monitor_ports[index] - 1; + current_temp = onlp_sysi_get_xcvr_temp(port); + if (current_temp == ONLP_STATUS_E_MISSING) { + return ONLP_STATUS_E_MISSING; + } + + data->type = TYPE_TRANSCEIVER; + data->spec = &thermal_specs[fan_dir][TYPE_TRANSCEIVER][0]; + data->port = port; + data->current_temp = current_temp; + snprintf(data->sensor_name, sizeof(data->sensor_name), "Port %02d", port); + + return ONLP_STATUS_OK; +} + +static int transceiver_get_count(fan_direction_t dir) +{ + return AIM_ARRAYSIZE(monitor_ports); +} + +static bool transceiver_should_process(int index) +{ + return true; +} + +/* Transceiver critical error check: only non-E_MISSING errors are critical */ +static bool transceiver_is_critical_error(int error_code) +{ + /* E_MISSING (not present or temporary issue) is not critical */ + /* Other errors (e.g., E_INTERNAL) are critical */ + return (error_code != ONLP_STATUS_OK && error_code != ONLP_STATUS_E_MISSING); +} + +/* Sensor operation structures */ +static thermal_sensor_ops_t sensor_ops = { + .name = "Thermal Sensor", + .get_temp = sensor_get_temp, + .get_count = sensor_get_count, + .should_process = sensor_should_process, + .is_critical_error = sensor_is_critical_error +}; + +static thermal_sensor_ops_t transceiver_ops = { + .name = "Transceiver", + .get_temp = transceiver_get_temp, + .get_count = transceiver_get_count, + .should_process = transceiver_should_process, + .is_critical_error = transceiver_is_critical_error +}; + +/* Registered handlers */ +static sensor_handler_t sensor_handlers[] = { + { .ops = &sensor_ops, .type = TYPE_SENSOR }, + { .ops = &transceiver_ops, .type = TYPE_TRANSCEIVER } +}; + +/* State Machine API */ +void process_thermal_state(thermal_sensor_data_t *sensor_data, thermal_state_result_t *result) +{ + int current_temp = 0; + thermal_spec_t *spec = NULL; + const char *sensor_name = NULL; + + if (!sensor_data || !result) { + return; + } + + current_temp = sensor_data->current_temp; + spec = sensor_data->spec; + sensor_name = sensor_data->sensor_name; + + if (current_temp == 0) return; /* Skip invalid readings */ + + /* State machine logic */ + if (result->ori_state == LEVEL_FAN_MIN) { + if (current_temp >= spec->min_to_mid.threshold) { + result->new_state = LEVEL_FAN_MID; + } + } else if (result->ori_state == LEVEL_FAN_MID) { + if (current_temp <= spec->mid_to_min.threshold) { + result->mid_to_min_count += 1; + } else if (current_temp >= spec->mid_to_max.threshold) { + result->new_state = LEVEL_FAN_MAX; + AIM_SYSLOG_WARN("Temperature warning", "Temperature warning", + "%s: %.1f°C exceeds mid->max threshold %.1f°C", + sensor_name, current_temp/1000.0, + spec->mid_to_max.threshold/1000.0); + } + } else { /* LEVEL_FAN_MAX */ + /* Check for temperature reduction */ + if (current_temp <= spec->max_to_mid.threshold) { + result->max_to_mid_count += 1; + } + + /* Check alarm conditions */ + if (result->alarm == 0) { + if (current_temp >= spec->max_to_yellow.threshold) { + result->alarm = LEVEL_FAN_YELLOW_ALARM; + AIM_SYSLOG_WARN("Temperature warning", "Temperature warning", + "Yellow alarm - %s: %.1f°C exceeds %.1f°C", + sensor_name, current_temp/1000.0, + spec->max_to_yellow.threshold/1000.0); + } + } else if (result->alarm == LEVEL_FAN_YELLOW_ALARM) { + if (current_temp >= spec->yellow_to_red.threshold) { + result->alarm = LEVEL_FAN_RED_ALARM; + AIM_SYSLOG_CRIT("Temperature critical", "Temperature critical", + "Red alarm - %s: %.1f°C exceeds %.1f°C", + sensor_name, current_temp/1000.0, + spec->yellow_to_red.threshold/1000.0); + } + } else if (result->alarm == LEVEL_FAN_RED_ALARM) { + if (current_temp >= spec->red_to_shutdown.threshold) { + result->alarm = LEVEL_FAN_SHUTDOWN; + if (sensor_data->type == TYPE_SENSOR) { + AIM_SYSLOG_CRIT("Temperature critical", "Temperature critical", + "SHUTDOWN - %s: %.1f°C exceeds %.1f°C - powering off", + sensor_name, current_temp/1000.0, + spec->red_to_shutdown.threshold/1000.0); + onlp_sysi_over_temp_protector(); + } else if (sensor_data->type == TYPE_TRANSCEIVER) { + AIM_SYSLOG_CRIT("Temperature critical", "Temperature critical", + "SHUTDOWN - %s: %.1f°C exceeds %.1f°C - reset", + sensor_name, current_temp/1000.0, + spec->red_to_shutdown.threshold/1000.0); + onlp_sfpi_control_set(sensor_data->port, ONLP_SFP_CONTROL_RESET, 1); + result->alarm = 0; + } + } + } + } +} + +/* Generic sensor processing function */ +static int process_sensor_type(sensor_handler_t *handler, + fan_direction_t fan_dir, + thermal_state_result_t *result, + int *processed_count) +{ + int i, count; + thermal_sensor_ops_t *ops = handler->ops; + + count = ops->get_count(fan_dir); + *processed_count = 0; + + for (i = 0; i < count; i++) { + thermal_sensor_data_t sensor_data = {0}; + int ret; + + if (!ops->should_process(i)) { + continue; + } + + ret = ops->get_temp(i, fan_dir, &sensor_data); + + if (ret != ONLP_STATUS_OK) { + if (ops->is_critical_error(ret)) { + return ret; + } else { + continue; + } + } + + (*processed_count)++; + + /* Process temperature state */ + process_thermal_state(&sensor_data, result); + + if (result->new_state != result->ori_state) { + return ONLP_STATUS_OK; + } + } + + return ONLP_STATUS_OK; +} + +/* Simplified main function */ +int onlp_sysi_platform_manage_fans(void) +{ + static int current_state = LEVEL_FAN_MAX; + static bool initialized = false; + static int persistent_alarm = 0; + fan_direction_t fan_dir; + thermal_state_result_t result = {0}; + int i, total_processed = 0; + + /* Initialize */ + if (!initialized) { + onlp_sysi_set_fan_duty_all(FAN_DUTY_CYCLE_MAX); + AIM_SYSLOG_INFO("Temperature info", "Temperature info", + "Initializing fan to %d%%", FAN_DUTY_CYCLE_MAX); + initialized = true; + } + + /* Get fan direction */ + fan_dir = onlp_sysi_get_fan_direction(); + + /* Initialize result */ + result.ori_state = current_state; + result.new_state = current_state; + result.alarm = persistent_alarm; + + /* Process all sensor types */ + for (i = 0; i < AIM_ARRAYSIZE(sensor_handlers); i++) { + int processed; + int ret; + + ret = process_sensor_type(&sensor_handlers[i], fan_dir, &result, &processed); + if (ret != ONLP_STATUS_OK) { + current_state = LEVEL_FAN_MAX; + onlp_sysi_set_fan_duty_all(FAN_DUTY_CYCLE_MAX); + return ONLP_STATUS_OK; + } + + total_processed += processed; + + if (result.new_state != current_state) { + break; + } + } + + /* Check state transitions */ + if (result.max_to_mid_count == total_processed && current_state == LEVEL_FAN_MAX) { + result.new_state = LEVEL_FAN_MID; + if (result.alarm != 0) { + result.alarm = 0; + AIM_SYSLOG_INFO("Temperature info", "Temperature info", "Temperature alarms cleared"); + } + } + + if (fan_dir == FAN_DIR_AFO) { + if (result.mid_to_min_count == total_processed && current_state == LEVEL_FAN_MID) { + result.new_state = LEVEL_FAN_MIN; + AIM_SYSLOG_INFO("Temperature info", "Temperature info", + "All temperatures low - transitioning to MIN"); + } + } + + persistent_alarm = result.alarm; + + /* Check fan status */ + if (onlp_sysi_get_fan_status() != ONLP_STATUS_OK) { + AIM_SYSLOG_WARN("Temperature warning", "Temperature warning", + "Fan failure detected, setting maximum speed"); + onlp_sysi_set_fan_duty_all(FAN_DUTY_CYCLE_MAX); + current_state = LEVEL_FAN_MAX; + } else { + /* Apply fan policy changes */ + if (current_state != result.new_state) { + fan_policy_config_t *fan_policy; + + fan_policy = (fan_dir == FAN_DIR_AFI) ? fan_policy_b2f : fan_policy_f2b; + + if (result.new_state > result.ori_state) { + AIM_SYSLOG_WARN("Temperature warning", "Temperature warning", + "Increasing fan duty cycle from %d%% to %d%%", + fan_policy[result.ori_state].duty_cycle, + fan_policy[result.new_state].duty_cycle); + } else { + AIM_SYSLOG_INFO("Temperature info", "Temperature info", + "Decreasing fan duty cycle from %d%% to %d%%", + fan_policy[result.ori_state].duty_cycle, + fan_policy[result.new_state].duty_cycle); + } + onlp_sysi_set_fan_duty_all(fan_policy[result.new_state].duty_cycle); + + current_state = result.new_state; + } + } + + return ONLP_STATUS_OK; +} diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/thermali.c b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/thermali.c new file mode 100644 index 000000000..6f0a9829d --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/thermali.c @@ -0,0 +1,337 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2014 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * Thermal Sensor Platform Implementation. + * + ***********************************************************/ +//#include +#include +#include +#include "platform_lib.h" +#include +#include + +#define THERMAL_PATH_FORMAT "/sys/bus/i2c/devices/%s/*temp1_input" +#define PSU_THERMAL_PATH_FORMAT "/sys/bus/i2c/devices/%s/*psu_temp1_input" +#define CPU_CORETEMP_DIR_PATH "/sys/devices/platform/coretemp.0/hwmon" +#define MAX_ENTRIES 128 /* Maximum number of temp*_input files */ +#define MAX_NAME_LEN 256 /* Maximum file name length */ + +#define VALIDATE(_id) \ +do { \ + if(!ONLP_OID_IS_THERMAL(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ +} while(0) + +static char* devfiles__[] = /* must map with onlp_thermal_id */ +{ + NULL, + NULL, /* CPU_CORE files */ + "/sys/bus/i2c/devices/15-0048*temp1_input", + "/sys/bus/i2c/devices/15-0049*temp1_input", + "/sys/bus/i2c/devices/15-004a*temp1_input", + "/sys/bus/i2c/devices/15-004b*temp1_input", + "/sys/bus/i2c/devices/15-004c*temp1_input", + "/sys/bus/i2c/devices/15-004f*temp1_input", + "/sys/bus/i2c/devices/9-0058*psu_temp1_input", + "/sys/bus/i2c/devices/9-0059*psu_temp1_input", +}; + +typedef struct { + char name[MAX_NAME_LEN]; + int index; +} TempEntry; + + +TempEntry temp_entries[MAX_ENTRIES]; +/* Global regex variables */ +regex_t dir_regex, file_regex; +int sysfs_count = 0; +/* Function to safely concatenate paths and handle overflow */ +int safe_snprintf(char *buffer, size_t buffer_size, const char *path1, const char *path2) { + size_t needed_size = strlen(path1) + strlen(path2) + 2; /* 1 for '/', 1 for '\0' */ + if (needed_size > buffer_size) { + AIM_LOG_ERROR("Path too long: %s/%s\n", path1, path2); + return -1; + } + snprintf(buffer, buffer_size, "%s/%s", path1, path2); + return 0; +} + +#define AS9726_32D_THERMAL_CAPS (ONLP_THERMAL_CAPS_GET_TEMPERATURE | \ + ONLP_THERMAL_CAPS_GET_WARNING_THRESHOLD | \ + ONLP_THERMAL_CAPS_GET_ERROR_THRESHOLD | \ + ONLP_THERMAL_CAPS_GET_SHUTDOWN_THRESHOLD) + +/* Static values */ +static onlp_thermal_info_t linfo[] = { + { }, /* Not used */ + { { ONLP_THERMAL_ID_CREATE(THERMAL_CPU_CORE), "CPU Core", 0}, + ONLP_THERMAL_STATUS_PRESENT, + AS9726_32D_THERMAL_CAPS, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_MAIN_BROAD), "LM75-1-48", 0}, + ONLP_THERMAL_STATUS_PRESENT, + AS9726_32D_THERMAL_CAPS, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_2_ON_MAIN_BROAD), "LM75-2-49", 0}, + ONLP_THERMAL_STATUS_PRESENT, + AS9726_32D_THERMAL_CAPS, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_3_ON_MAIN_BROAD), "LM75-3-4A", 0}, + ONLP_THERMAL_STATUS_PRESENT, + AS9726_32D_THERMAL_CAPS, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_4_ON_MAIN_BROAD), "LM75-4-4B", 0}, + ONLP_THERMAL_STATUS_PRESENT, + AS9726_32D_THERMAL_CAPS, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_5_ON_MAIN_BROAD), "LM75-5-4C", 0}, + ONLP_THERMAL_STATUS_PRESENT, + AS9726_32D_THERMAL_CAPS, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_6_ON_MAIN_BROAD), "LM75-6-4F", 0}, + ONLP_THERMAL_STATUS_PRESENT, + AS9726_32D_THERMAL_CAPS, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_PSU1), + "PSU-1 Thermal Sensor 1", ONLP_PSU_ID_CREATE(PSU1_ID)}, + ONLP_THERMAL_STATUS_PRESENT, + AS9726_32D_THERMAL_CAPS, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_PSU2), + "PSU-2 Thermal Sensor 1", ONLP_PSU_ID_CREATE(PSU2_ID)}, + ONLP_THERMAL_STATUS_PRESENT, + AS9726_32D_THERMAL_CAPS, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + } +}; + +int initialize_regex() { + if (regcomp(&dir_regex, "^hwmon[0-9]+$", REG_EXTENDED) != 0) { + AIM_LOG_ERROR("Failed to compile directory regex\n"); + return -1; + } + if (regcomp(&file_regex, "^temp([0-9]+)_input$", REG_EXTENDED) != 0) { + AIM_LOG_ERROR("Failed to compile file regex\n"); + regfree(&dir_regex); + return -1; + } + return 0; +} + +void cleanup_regex() { + regfree(&dir_regex); + regfree(&file_regex); +} + +/* Function to scan hwmon directories for temp*_input files */ +void scan_hwmon_files(const char *parent_path) { + DIR *parent_dir = opendir(parent_path); + if (!parent_dir) { + AIM_LOG_ERROR("Failed to open parent directory"); + return; + } + + size_t count = 0; + + struct dirent *entry; + while ((entry = readdir(parent_dir)) != NULL) { + if (regexec(&dir_regex, entry->d_name, 0, NULL, 0) != 0) { + continue; + } + + char subdir_path[MAX_NAME_LEN]; + if (safe_snprintf(subdir_path, sizeof(subdir_path), parent_path, entry->d_name) < 0) { + continue; + } + + DIR *subdir = opendir(subdir_path); + if (!subdir) { + AIM_LOG_ERROR("Failed to open subdirectory"); + continue; + } + + struct dirent *sub_entry; + while ((sub_entry = readdir(subdir)) != NULL) { + regmatch_t pmatch[2]; + if (regexec(&file_regex, sub_entry->d_name, 2, pmatch, 0) == 0) { + if (count >= MAX_ENTRIES) { + AIM_LOG_ERROR("Maximum entries reached. Ignoring additional files.\n"); + break; + } + + char full_path[MAX_NAME_LEN]; + if (safe_snprintf(full_path, sizeof(full_path), subdir_path, sub_entry->d_name) < 0) { + continue; + } + + int index = atoi(&sub_entry->d_name[pmatch[1].rm_so]); + strncpy(temp_entries[count].name, full_path, MAX_NAME_LEN - 1); + temp_entries[count].name[MAX_NAME_LEN - 1] = '\0'; + temp_entries[count].index = index; + count++; + } + } + closedir(subdir); + } + + closedir(parent_dir); + + sysfs_count = count; +} + +typedef struct threshold_t { + int warning; + int error; + int shutdown; +} threshold_t; + +threshold_t threshold[FAN_DIR_COUNT][THERMAL_COUNT] = { + [FAN_DIR_F2B][THERMAL_CPU_CORE].warning = 73000, + [FAN_DIR_F2B][THERMAL_CPU_CORE].error = 78000, + [FAN_DIR_F2B][THERMAL_CPU_CORE].shutdown = 83000, + [FAN_DIR_F2B][THERMAL_1_ON_MAIN_BROAD].warning = 67000, + [FAN_DIR_F2B][THERMAL_1_ON_MAIN_BROAD].error = 72000, + [FAN_DIR_F2B][THERMAL_1_ON_MAIN_BROAD].shutdown = 77000, + [FAN_DIR_F2B][THERMAL_2_ON_MAIN_BROAD].warning = 65000, + [FAN_DIR_F2B][THERMAL_2_ON_MAIN_BROAD].error = 70000, + [FAN_DIR_F2B][THERMAL_2_ON_MAIN_BROAD].shutdown = 75000, + [FAN_DIR_F2B][THERMAL_3_ON_MAIN_BROAD].warning = 64000, + [FAN_DIR_F2B][THERMAL_3_ON_MAIN_BROAD].error = 69000, + [FAN_DIR_F2B][THERMAL_3_ON_MAIN_BROAD].shutdown = 74000, + [FAN_DIR_F2B][THERMAL_4_ON_MAIN_BROAD].warning = 67000, + [FAN_DIR_F2B][THERMAL_4_ON_MAIN_BROAD].error = 72000, + [FAN_DIR_F2B][THERMAL_4_ON_MAIN_BROAD].shutdown = 77000, + [FAN_DIR_F2B][THERMAL_5_ON_MAIN_BROAD].warning = 62000, + [FAN_DIR_F2B][THERMAL_5_ON_MAIN_BROAD].error = 67000, + [FAN_DIR_F2B][THERMAL_5_ON_MAIN_BROAD].shutdown = 72000, + [FAN_DIR_F2B][THERMAL_6_ON_MAIN_BROAD].warning = 64000, + [FAN_DIR_F2B][THERMAL_6_ON_MAIN_BROAD].error = 69000, + [FAN_DIR_F2B][THERMAL_6_ON_MAIN_BROAD].shutdown = 74000, + [FAN_DIR_F2B][THERMAL_1_ON_PSU1].warning = 78000, + [FAN_DIR_F2B][THERMAL_1_ON_PSU1].error = 83000, + [FAN_DIR_F2B][THERMAL_1_ON_PSU1].shutdown = 88000, + [FAN_DIR_F2B][THERMAL_1_ON_PSU2].warning = 78000, + [FAN_DIR_F2B][THERMAL_1_ON_PSU2].error = 83000, + [FAN_DIR_F2B][THERMAL_1_ON_PSU2].shutdown = 88000, + + [FAN_DIR_B2F][THERMAL_CPU_CORE].warning = 52000, + [FAN_DIR_B2F][THERMAL_CPU_CORE].error = 57000, + [FAN_DIR_B2F][THERMAL_CPU_CORE].shutdown = 62000, + [FAN_DIR_B2F][THERMAL_1_ON_MAIN_BROAD].warning = 58000, + [FAN_DIR_B2F][THERMAL_1_ON_MAIN_BROAD].error = 62900, + [FAN_DIR_B2F][THERMAL_1_ON_MAIN_BROAD].shutdown = 67900, + [FAN_DIR_B2F][THERMAL_2_ON_MAIN_BROAD].warning = 52000, + [FAN_DIR_B2F][THERMAL_2_ON_MAIN_BROAD].error = 56900, + [FAN_DIR_B2F][THERMAL_2_ON_MAIN_BROAD].shutdown = 61900, + [FAN_DIR_B2F][THERMAL_3_ON_MAIN_BROAD].warning = 49000, + [FAN_DIR_B2F][THERMAL_3_ON_MAIN_BROAD].error = 53900, + [FAN_DIR_B2F][THERMAL_3_ON_MAIN_BROAD].shutdown = 58900, + [FAN_DIR_B2F][THERMAL_4_ON_MAIN_BROAD].warning = 42000, + [FAN_DIR_B2F][THERMAL_4_ON_MAIN_BROAD].error = 46800, + [FAN_DIR_B2F][THERMAL_4_ON_MAIN_BROAD].shutdown = 51800, + [FAN_DIR_B2F][THERMAL_5_ON_MAIN_BROAD].warning = 56000, + [FAN_DIR_B2F][THERMAL_5_ON_MAIN_BROAD].error = 58900, + [FAN_DIR_B2F][THERMAL_5_ON_MAIN_BROAD].shutdown = 63900, + [FAN_DIR_B2F][THERMAL_6_ON_MAIN_BROAD].warning = 49000, + [FAN_DIR_B2F][THERMAL_6_ON_MAIN_BROAD].error = 53500, + [FAN_DIR_B2F][THERMAL_6_ON_MAIN_BROAD].shutdown = 58500, + [FAN_DIR_B2F][THERMAL_1_ON_PSU1].warning = 81000, + [FAN_DIR_B2F][THERMAL_1_ON_PSU1].error = 86000, + [FAN_DIR_B2F][THERMAL_1_ON_PSU1].shutdown = 91000, + [FAN_DIR_B2F][THERMAL_1_ON_PSU2].warning = 81000, + [FAN_DIR_B2F][THERMAL_1_ON_PSU2].error = 86000, + [FAN_DIR_B2F][THERMAL_1_ON_PSU2].shutdown = 91000, +}; + +/* + * This will be called to intiialize the thermali subsystem. + */ +int onlp_thermali_init(void) +{ + /* Initialize regex patterns */ + if (initialize_regex() != 0) { + return ONLP_STATUS_E_INTERNAL; + } + scan_hwmon_files(CPU_CORETEMP_DIR_PATH); + /* Clean up regex patterns */ + cleanup_regex(); + + return ONLP_STATUS_OK; +} + +/* + * Retrieve the information structure for the given thermal OID. + * + * If the OID is invalid, return ONLP_E_STATUS_INVALID. + * If an unexpected error occurs, return ONLP_E_STATUS_INTERNAL. + * Otherwise, return ONLP_STATUS_OK with the OID's information. + * + * Note -- it is expected that you fill out the information + * structure even if the sensor described by the OID is not present. + */ +int onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info) +{ + int tid, psu_id; + int val = 0; + enum onlp_fan_dir dir; + VALIDATE(id); + int coretemp_max = 0, coretemp_temp = 0; + + tid = ONLP_OID_ID_GET(id); + dir = onlp_get_fan_dir(); + + /* Set the onlp_oid_hdr_t and capabilities */ + *info = linfo[tid]; + info->thresholds.warning = threshold[dir][tid].warning; + info->thresholds.error = threshold[dir][tid].error; + info->thresholds.shutdown = threshold[dir][tid].shutdown; + + if (tid == THERMAL_CPU_CORE) + { + for (size_t i = 0; i < sysfs_count; i++) { + if (onlp_file_read_int(&coretemp_temp, temp_entries[i].name) < 0) { + AIM_LOG_ERROR("Unable to read status from file (%s)\r\n", temp_entries[i].name); + return ONLP_STATUS_E_INTERNAL; + } + if (coretemp_temp > coretemp_max) + coretemp_max = coretemp_temp; + } + + info->mcelsius = coretemp_max; + + return ONLP_STATUS_OK; + } + + if ((tid >= THERMAL_1_ON_PSU1) && (tid <= THERMAL_1_ON_PSU2)) { + psu_id = ( tid == THERMAL_1_ON_PSU1 ) ? PSU1_ID : PSU2_ID; + /* Get power good status */ + if (psu_status_info_get(psu_id, "psu_power_good", &val) == ONLP_STATUS_OK) { + if(val != PSU_STATUS_POWER_GOOD) { + info->status |= ONLP_THERMAL_STATUS_FAILED; + } + } + } + + return onlp_file_read_int(&info->mcelsius, devfiles__[tid]); +} diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/x86_64_accton_as9726_32d_config.c b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/x86_64_accton_as9726_32d_config.c new file mode 100644 index 000000000..e70496da7 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/x86_64_accton_as9726_32d_config.c @@ -0,0 +1,80 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +/* */ +#define __x86_64_accton_as9726_32d_config_STRINGIFY_NAME(_x) #_x +#define __x86_64_accton_as9726_32d_config_STRINGIFY_VALUE(_x) __x86_64_accton_as9726_32d_config_STRINGIFY_NAME(_x) +x86_64_accton_as9726_32d_config_settings_t x86_64_accton_as9726_32d_config_settings[] = +{ +#ifdef X86_64_ACCTON_AS9726_32D_CONFIG_INCLUDE_LOGGING + { __x86_64_accton_as9726_32d_config_STRINGIFY_NAME(X86_64_ACCTON_AS9726_32D_CONFIG_INCLUDE_LOGGING), __x86_64_accton_as9726_32d_config_STRINGIFY_VALUE(X86_64_ACCTON_AS9726_32D_CONFIG_INCLUDE_LOGGING) }, +#else +{ X86_64_ACCTON_AS9726_32D_CONFIG_INCLUDE_LOGGING(__x86_64_accton_as9726_32d_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_ACCTON_AS9726_32D_CONFIG_LOG_OPTIONS_DEFAULT + { __x86_64_accton_as9726_32d_config_STRINGIFY_NAME(X86_64_ACCTON_AS9726_32D_CONFIG_LOG_OPTIONS_DEFAULT), __x86_64_accton_as9726_32d_config_STRINGIFY_VALUE(X86_64_ACCTON_AS9726_32D_CONFIG_LOG_OPTIONS_DEFAULT) }, +#else +{ X86_64_ACCTON_AS9726_32D_CONFIG_LOG_OPTIONS_DEFAULT(__x86_64_accton_as9726_32d_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_ACCTON_AS9726_32D_CONFIG_LOG_BITS_DEFAULT + { __x86_64_accton_as9726_32d_config_STRINGIFY_NAME(X86_64_ACCTON_AS9726_32D_CONFIG_LOG_BITS_DEFAULT), __x86_64_accton_as9726_32d_config_STRINGIFY_VALUE(X86_64_ACCTON_AS9726_32D_CONFIG_LOG_BITS_DEFAULT) }, +#else +{ X86_64_ACCTON_AS9726_32D_CONFIG_LOG_BITS_DEFAULT(__x86_64_accton_as9726_32d_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_ACCTON_AS9726_32D_CONFIG_LOG_CUSTOM_BITS_DEFAULT + { __x86_64_accton_as9726_32d_config_STRINGIFY_NAME(X86_64_ACCTON_AS9726_32D_CONFIG_LOG_CUSTOM_BITS_DEFAULT), __x86_64_accton_as9726_32d_config_STRINGIFY_VALUE(X86_64_ACCTON_AS9726_32D_CONFIG_LOG_CUSTOM_BITS_DEFAULT) }, +#else +{ X86_64_ACCTON_AS9726_32D_CONFIG_LOG_CUSTOM_BITS_DEFAULT(__x86_64_accton_as9726_32d_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_ACCTON_AS9726_32D_CONFIG_PORTING_STDLIB + { __x86_64_accton_as9726_32d_config_STRINGIFY_NAME(X86_64_ACCTON_AS9726_32D_CONFIG_PORTING_STDLIB), __x86_64_accton_as9726_32d_config_STRINGIFY_VALUE(X86_64_ACCTON_AS9726_32D_CONFIG_PORTING_STDLIB) }, +#else +{ X86_64_ACCTON_AS9726_32D_CONFIG_PORTING_STDLIB(__x86_64_accton_as9726_32d_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_ACCTON_AS9726_32D_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + { __x86_64_accton_as9726_32d_config_STRINGIFY_NAME(X86_64_ACCTON_AS9726_32D_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS), __x86_64_accton_as9726_32d_config_STRINGIFY_VALUE(X86_64_ACCTON_AS9726_32D_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS) }, +#else +{ X86_64_ACCTON_AS9726_32D_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS(__x86_64_accton_as9726_32d_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_ACCTON_AS9726_32D_CONFIG_INCLUDE_UCLI + { __x86_64_accton_as9726_32d_config_STRINGIFY_NAME(X86_64_ACCTON_AS9726_32D_CONFIG_INCLUDE_UCLI), __x86_64_accton_as9726_32d_config_STRINGIFY_VALUE(X86_64_ACCTON_AS9726_32D_CONFIG_INCLUDE_UCLI) }, +#else +{ X86_64_ACCTON_AS9726_32D_CONFIG_INCLUDE_UCLI(__x86_64_accton_as9726_32d_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_ACCTON_AS9726_32D_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION + { __x86_64_accton_as9726_32d_config_STRINGIFY_NAME(X86_64_ACCTON_AS9726_32D_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION), __x86_64_accton_as9726_32d_config_STRINGIFY_VALUE(X86_64_ACCTON_AS9726_32D_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION) }, +#else +{ X86_64_ACCTON_AS9726_32D_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION(__x86_64_accton_as9726_32d_config_STRINGIFY_NAME), "__undefined__" }, +#endif + { NULL, NULL } +}; +#undef __x86_64_accton_as9726_32d_config_STRINGIFY_VALUE +#undef __x86_64_accton_as9726_32d_config_STRINGIFY_NAME + +const char* +x86_64_accton_as9726_32d_config_lookup(const char* setting) +{ + int i; + for(i = 0; x86_64_accton_as9726_32d_config_settings[i].name; i++) { + if(!strcmp(x86_64_accton_as9726_32d_config_settings[i].name, setting)) { + return x86_64_accton_as9726_32d_config_settings[i].value; + } + } + return NULL; +} + +int +x86_64_accton_as9726_32d_config_show(struct aim_pvs_s* pvs) +{ + int i; + for(i = 0; x86_64_accton_as9726_32d_config_settings[i].name; i++) { + aim_printf(pvs, "%s = %s\n", x86_64_accton_as9726_32d_config_settings[i].name, x86_64_accton_as9726_32d_config_settings[i].value); + } + return i; +} + +/* */ diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/x86_64_accton_as9726_32d_enums.c b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/x86_64_accton_as9726_32d_enums.c new file mode 100644 index 000000000..dce421bad --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/x86_64_accton_as9726_32d_enums.c @@ -0,0 +1,10 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +/* <--auto.start.enum(ALL).source> */ +/* */ + diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/x86_64_accton_as9726_32d_int.h b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/x86_64_accton_as9726_32d_int.h new file mode 100644 index 000000000..8eef816ab --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/x86_64_accton_as9726_32d_int.h @@ -0,0 +1,12 @@ +/**************************************************************************//** + * + * x86_64_accton_as9726_32x Internal Header + * + *****************************************************************************/ +#ifndef __x86_64_accton_as9726_32d_INT_H__ +#define __x86_64_accton_as9726_32d_INT_H__ + +#include + + +#endif /* __x86_64_accton_as9726_32d_INT_H__ */ diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/x86_64_accton_as9726_32d_log.c b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/x86_64_accton_as9726_32d_log.c new file mode 100644 index 000000000..5387e712d --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/x86_64_accton_as9726_32d_log.c @@ -0,0 +1,18 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +#include "x86_64_accton_as9726_32d_log.h" +/* + * x86_64_accton_as9726_32d log struct. + */ +AIM_LOG_STRUCT_DEFINE( + X86_64_ACCTON_AS9726_32D_CONFIG_LOG_OPTIONS_DEFAULT, + X86_64_ACCTON_AS9726_32D_CONFIG_LOG_BITS_DEFAULT, + NULL, /* Custom log map */ + X86_64_ACCTON_AS9726_32D_CONFIG_LOG_CUSTOM_BITS_DEFAULT + ); + diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/x86_64_accton_as9726_32d_log.h b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/x86_64_accton_as9726_32d_log.h new file mode 100644 index 000000000..51249ac7e --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/x86_64_accton_as9726_32d_log.h @@ -0,0 +1,12 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#ifndef __x86_64_accton_as9726_32d_LOG_H__ +#define __x86_64_accton_as9726_32d_LOG_H__ + +#define AIM_LOG_MODULE_NAME x86_64_accton_as9726_32d +#include + +#endif /* __x86_64_accton_as9726_32d_LOG_H__ */ diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/x86_64_accton_as9726_32d_module.c b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/x86_64_accton_as9726_32d_module.c new file mode 100644 index 000000000..99711050a --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/x86_64_accton_as9726_32d_module.c @@ -0,0 +1,24 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +#include "x86_64_accton_as9726_32d_log.h" + +static int +datatypes_init__(void) +{ +#define x86_64_accton_as9726_32d_ENUMERATION_ENTRY(_enum_name, _desc) AIM_DATATYPE_MAP_REGISTER(_enum_name, _enum_name##_map, _desc, AIM_LOG_INTERNAL); +#include + return 0; +} + +void __x86_64_accton_as9726_32d_module_init__(void) +{ + AIM_LOG_STRUCT_REGISTER(); + datatypes_init__(); +} + +int __onlp_platform_version__ = 1; diff --git a/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/x86_64_accton_as9726_32d_ucli.c b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/x86_64_accton_as9726_32d_ucli.c new file mode 100644 index 000000000..b6d7abad1 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/onlp/builds/x86_64_accton_as9726_32d/module/src/x86_64_accton_as9726_32d_ucli.c @@ -0,0 +1,50 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +#if x86_64_accton_as9726_32d_CONFIG_INCLUDE_UCLI == 1 + +#include +#include +#include + +static ucli_status_t +x86_64_accton_as9726_32d_ucli_ucli__config__(ucli_context_t* uc) +{ + UCLI_HANDLER_MACRO_MODULE_CONFIG(x86_64_accton_as9726_32d) +} + +/* */ +/* */ + +static ucli_module_t +x86_64_accton_as9726_32d_ucli_module__ = + { + "x86_64_accton_as9726_32d_ucli", + NULL, + x86_64_accton_as9726_32d_ucli_ucli_handlers__, + NULL, + NULL, + }; + +ucli_node_t* +x86_64_accton_as9726_32d_ucli_node_create(void) +{ + ucli_node_t* n; + ucli_module_init(&x86_64_accton_as9726_32d_ucli_module__); + n = ucli_node_create("x86_64_accton_as9726_32d", NULL, &x86_64_accton_as9726_32d_ucli_module__); + ucli_node_subnode_add(n, ucli_module_log_node_create("x86_64_accton_as9726_32d")); + return n; +} + +#else +void* +x86_64_accton_as9726_32d_ucli_node_create(void) +{ + return NULL; +} +#endif + diff --git a/packages/platforms/accton/x86-64/as9726-32d/platform-config/Makefile b/packages/platforms/accton/x86-64/as9726-32d/platform-config/Makefile new file mode 100644 index 000000000..003238cf6 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/platform-config/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/as9726-32d/platform-config/r0/Makefile b/packages/platforms/accton/x86-64/as9726-32d/platform-config/r0/Makefile new file mode 100644 index 000000000..003238cf6 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/platform-config/r0/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/as9726-32d/platform-config/r0/PKG.yml b/packages/platforms/accton/x86-64/as9726-32d/platform-config/r0/PKG.yml new file mode 100644 index 000000000..1280fbbca --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/platform-config/r0/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/platform-config-platform.yml ARCH=amd64 VENDOR=accton BASENAME=x86-64-accton-as9726-32d REVISION=r0 diff --git a/packages/platforms/accton/x86-64/as9726-32d/platform-config/r0/src/lib/tech_support/show_platform_log.sh b/packages/platforms/accton/x86-64/as9726-32d/platform-config/r0/src/lib/tech_support/show_platform_log.sh new file mode 100755 index 000000000..ebc5b3f87 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/platform-config/r0/src/lib/tech_support/show_platform_log.sh @@ -0,0 +1,1416 @@ +#!/bin/bash + +#Tech Support script version +TS_VERSION="0.0.1" + +# TRUE=0, FALSE=1 +TRUE=0 +FALSE=1 + +# DATESTR: The format of log folder and log file +DATESTR=$(date +"%Y%m%d%H%M%S") +DEFAULT_LOG_FOLDER_NAME="log_platform_${DATESTR}" +DEFAULT_LOG_FILE_NAME="log_platform_${DATESTR}.log" +LOG_FOLDER_NAME="" +LOG_FILE_NAME="" + +# LOG_FOLDER_ROOT: The root folder of log files +DEFAULT_LOG_FOLDER_ROOT="/tmp/log" +DEFAULT_LOG_FOLDER_PATH="${DEFAULT_LOG_FOLDER_ROOT}/${DEFAULT_LOG_FOLDER_NAME}" +DEFAULT_LOG_FILE_PATH="${DEFAULT_LOG_FOLDER_PATH}/${DEFAULT_LOG_FILE_NAME}" +LOG_FOLDER_ROOT="" +LOG_FOLDER_PATH="" +LOG_FILE_PATH="" +LOG_FAST=${FALSE} + +# HW_REV: set by function _board_info +HW_REV="" + +SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" + +# LOG_FILE_ENABLE=1: Log all the platform info to log files (${LOG_FILE_NAME}) +# LOG_FILE_ENABLE=0: Print all the platform info in console +LOG_FILE_ENABLE=1 + +# Log Redirection +# LOG_REDIRECT="2> /dev/null" : remove the error message from console +# LOG_REDIRECT="" : show the error message in console +# LOG_REDIRECT="2>> $LOG_FILE_PATH" : show the error message in stdout, then stdout may send to console or file in _echo() +LOG_REDIRECT="2>> $LOG_FILE_PATH" + +# GPIO_MAX: update by function _update_gpio_max +GPIO_MAX=0 +GPIO_MAX_INIT_FLAG=0 + +# CPLD max index +MAX_CPLD=3 + +# Execution Time +start_time=$(date +%s) +end_time=0 +elapsed_time=0 + +OPT_BYPASS_I2C_COMMAND=${FALSE} + +# NETIF name, should be changed according NOS naming +NET_IF="" + +function _echo { + str="$@" + + if [ "${LOG_FILE_ENABLE}" == "1" ] && [ -f "${LOG_FILE_PATH}" ]; then + echo "${str}" >> "${LOG_FILE_PATH}" + else + echo "${str}" + fi +} + +function _banner { + banner="$1" + + if [ ! -z "${banner}" ]; then + _echo "" + _echo "##############################" + _echo "# ${banner}" + echo "# ${banner}..." + _echo "##############################" + fi +} + +function _pkg_version { + _banner "Package Version = ${TS_VERSION}" +} + +function _show_ts_version { + echo "Package Version = ${TS_VERSION}" +} + +function _check_env { + echo "# Check Environment" + + # check basic commands + cmd_array=("ipmitool" "lsusb" "dmidecode") + for (( i=0; i<${#cmd_array[@]}; i++ )) + do + ret=`which ${cmd_array[$i]}` + + if [ ! $? -eq 0 ]; then + _echo "${cmd_array[$i]} command not found!!" + exit 1 + fi + done + + if [ "${LOG_FILE_ENABLE}" == "1" ]; then + mkdir -p "${LOG_FOLDER_PATH}" + if [ ! -d "${LOG_FOLDER_PATH}" ]; then + _echo "[ERROR] invalid log path: ${LOG_FOLDER_PATH}" + exit 1 + fi + echo "${LOG_FILE_NAME}" > "${LOG_FILE_PATH}" + fi +} + +function _check_filepath { + filepath=$1 + if [ -z "${filepath}" ]; then + _echo "ERROR, the ipnut string is empyt!!!" + return ${FALSE} + elif [ ! -f "$filepath" ]; then + _echo "ERROR: No such file: ${filepath}" + return ${FALSE} + else + #_echo "File Path: ${filepath}" + return ${TRUE} + fi +} + +function _check_dirpath { + dirpath=$1 + if [ -z "${dirpath}" ]; then + _echo "ERROR, the ipnut string is empty!!!" + return ${FALSE} + elif [ ! -d "$dirpath" ]; then + _echo "ERROR: No such directory: ${dirpath}" + return ${FALSE} + else + return ${TRUE} + fi +} + +function _check_i2c_device { + i2c_addr=$1 + + if [ -z "${i2c_addr}" ]; then + _echo "ERROR, the ipnut string is empyt!!!" + return ${FALSE} + fi + + value=$(eval "i2cget -y -f 0 ${i2c_addr} ${LOG_REDIRECT}") + ret=$? + + if [ $ret -eq 0 ]; then + return ${TRUE} + else + _echo "ERROR: No such device: ${i2c_addr}" + return ${FALSE} + fi +} + +function _check_bmc_device { + if [[ -e "/dev/ipmi0" ]] || [[ -e "/dev/ipmidev/0" ]];then + return ${TRUE} + else + return ${FALSE} + fi + +} + +function _show_system_info { + _banner "Show System Info" + + x86_date=`date` + x86_uptime=`uptime` + + _check_bmc_device + find_bmc_dev=$? + if [[ find_bmc_dev -eq ${TRUE} ]]; then + bmc_date=$(eval "ipmitool sel time get ${LOG_REDIRECT}") + fi + last_login=`last` + + _echo "[X86 Date Time ]: ${x86_date}" + if [[ find_bmc_dev -eq ${TRUE} ]]; then + _echo "[BMC Date Time ]: ${bmc_date}" + fi + _echo "[X86 Up Time ]: ${x86_uptime}" + + if [[ -f "/var/log/wtmp" ]];then + _echo "[X86 Last Login]: " + _echo "${last_login}" + _echo "" + fi + + cmd_array=("uname -a" "cat /proc/cmdline" "cat /proc/ioports" \ + "cat /proc/iomem" "cat /proc/meminfo" \ + "cat /proc/sys/kernel/printk" \ + "find /etc -name '*-release' -print -exec cat {} \;") + + for (( i=0; i<${#cmd_array[@]}; i++ )) + do + _echo "[Command]: ${cmd_array[$i]}" + ret=$(eval "${cmd_array[$i]} ${LOG_REDIRECT}") + _echo "${ret}" + _echo "" + done + +} + +function _show_cpu_usage { + _banner "Show CPU Usage" + + ret=$(eval "top -b -n 1") + + _echo "${ret}" +} + +function _show_grub { + + if [ ! -f "/mnt/onl/boot/grub/grub.cfg" ]; then + return 0 + fi + + _banner "Show GRUB Info" + + grub_info=`cat /mnt/onl/boot/grub/grub.cfg` + + _echo "[GRUB Info ]:" + _echo "${grub_info}" + +} + +function _show_driver { + _banner "Show Kernel Driver" + + cmd_array=("lsmod" \ + "cat /lib/modules/$(uname -r)/modules.builtin") + + for (( i=0; i<${#cmd_array[@]}; i++ )) + do + _echo "[Command]: ${cmd_array[$i]}" + ret=$(eval "${cmd_array[$i]} ${LOG_REDIRECT}") + _echo "${ret}" + _echo "" + done +} + +function _pre_log { + _banner "Pre Log" + + _show_i2c_tree_bus_0 + _show_i2c_tree_bus_0 + _show_i2c_tree_bus_0 +} + +function _show_board_info { + _banner "Show Board Info" + + PRODUCT_NAME=$(dmidecode -t 1 | grep "Product Name" | cut -d : -f 2 | xargs) + HW_REV=$(dmidecode -t 2 | grep "Version" | cut -d : -f 2 | xargs) + + _echo "[Product_Name]: ${PRODUCT_NAME}" + _echo "[Board Revision]: ${HW_REV}" +} + +function _show_sys_devices { + _banner "Show System Devices" + + local dir_path="/sys/class/gpio/" + if [ -d "${dir_path}" ]; then + _echo "" + _echo "[Command]: ls /sys/class/gpio/" + #ret=($(ls /sys/class/gpio/)) + #_echo "#${ret[*]}" + ret=`ls -al /sys/class/gpio/` + _echo "${ret}" + fi + + local file_path="/sys/kernel/debug/gpio" + if [ -f "${file_path}" ]; then + _echo "" + _echo "[Command]: cat ${file_path}" + _echo "$(cat ${file_path})" + fi + + _echo "" + _echo "[Command]: ls /sys/bus/i2c/devices/" + #ret=($(ls /sys/bus/i2c/devices/)) + #_echo "#${ret[*]}" + ret=`ls -al /sys/bus/i2c/devices/` + _echo "${ret}" + + _echo "" + _echo "[Command]: ls -al /dev/" + #ret=($(ls -al /dev/)) + #_echo "#${ret[*]}" + ret=`ls -al /dev/` + _echo "${ret}" +} + +function _get_netif_name { + onl=`uname -r | grep OpenNetworkLinux` + if [ -z $onl ]; then + # other NOS + if [[ $1 == "0" ]]; then + # sfp 0 + NET_IF="eth1" + else + # sfp 1 + NET_IF="eth2" + fi + else + # ONL + NET_PREFIX="enp182s0f" + if [[ $1 == "0" ]]; then + # sfp 0 + NET_IF="enp182s0f0" + else + # sfp 1 + NET_IF="enp182s0f1" + fi + fi +} + +function _show_bmc_info { + _banner "Show BMC Info" + + _check_bmc_device + find_bmc_dev=$? + if [[ find_bmc_dev -eq ${FALSE} ]]; then + _echo "Not support!" + return + fi + + cmd_array=("ipmitool mc info" "ipmitool lan print" "ipmitool sel info" \ + "ipmitool fru -v" "ipmitool power status" \ + "ipmitool channel info 0xf" "ipmitool channel info 0x1" \ + "ipmitool sol info 0x1" \ + "ipmitool mc watchdog get" "ipmitool mc info -I usb") + + for (( i=0; i<${#cmd_array[@]}; i++ )) + do + _echo "[Command]: ${cmd_array[$i]} " + ret=$(eval "${cmd_array[$i]} ${LOG_REDIRECT}") + _echo "${ret}" + _echo "" + done +} + +function _show_bmc_sensors { + _banner "Show BMC Sensors" + + _check_bmc_device + find_bmc_dev=$? + if [[ find_bmc_dev -eq ${FALSE} ]]; then + _echo "Not support!" + return + fi + + ret=$(eval "ipmitool sensor ${LOG_REDIRECT}") + _echo "[Sensors]:" + _echo "${ret}" +} + +function _show_bmc_sel_raw_data { + _banner "Show BMC SEL Raw Data" + + _check_bmc_device + find_bmc_dev=$? + if [[ find_bmc_dev -eq ${FALSE} ]]; then + _echo "Not support!" + return + fi + + echo " Show BMC SEL Raw Data, please wait..." + + if [ "${LOG_FILE_ENABLE}" == "1" ]; then + _echo "[SEL RAW Data]:" + ret=$(eval "ipmitool sel save ${LOG_FOLDER_PATH}/sel_raw_data.log > /dev/null ${LOG_REDIRECT}") + _echo "The file is located at ${LOG_FOLDER_NAME}/sel_raw_data.log" + else + _echo "[SEL RAW Data]:" + ret=$(eval "ipmitool sel save /tmp/log/sel_raw_data.log > /dev/null ${LOG_REDIRECT}") + cat /tmp/log/sel_raw_data.log + rm /tmp/log/sel_raw_data.log + fi +} + +function _show_bmc_sel_elist { + _banner "Show BMC SEL" + + _check_bmc_device + find_bmc_dev=$? + if [[ find_bmc_dev -eq ${FALSE} ]]; then + _echo "Not support!" + return + fi + + ret=$(eval "ipmitool sel elist ${LOG_REDIRECT}") + _echo "[SEL Record]:" + _echo "${ret}" +} + +function _show_bmc_sel_elist_detail { + _banner "Show BMC SEL Detail -- Abnormal Event" + + _check_bmc_device + find_bmc_dev=$? + if [[ find_bmc_dev -eq ${FALSE} ]]; then + _echo "Not support!" + return + fi + + _echo " Show BMC SEL details, please wait..." + sel_id_list="" + + readarray sel_array < <(ipmitool sel elist 2> /dev/null) + + for (( i=0; i<${#sel_array[@]}; i++ )) + do + if [[ "${sel_array[$i]}" == *"Undetermined"* ]] || + [[ "${sel_array[$i]}" == *"Bus"* ]] || + [[ "${sel_array[$i]}" == *"CATERR"* ]] || + [[ "${sel_array[$i]}" == *"OEM"* ]] ; then + _echo "${sel_array[$i]}" + sel_id=($(echo "${sel_array[$i]}" | awk -F" " '{print $1}')) + sel_id_list="${sel_id_list} 0x${sel_id}" + fi + done + + if [ ! -z "${sel_id_list}" ]; then + sel_detail=$(eval "ipmitool sel get ${sel_id_list} ${LOG_REDIRECT}") + else + sel_detail="" + fi + + _echo "[SEL Record ID]: ${sel_id_list}" + _echo "" + _echo "[SEL Detail ]:" + _echo "${sel_detail}" +} + +function _show_cpu_eeprom_i2c { + _banner "Show CPU EEPROM" + + #first read return empty content + cpu_eeprom=$(eval "i2cdump -y 0x${1} 0x${2} c") + #second read return correct content + cpu_eeprom=$(eval "i2cdump -y 0x${1} 0x${2} c") + _echo "[CPU EEPROM]:" + _echo "${cpu_eeprom}" +} + +function _show_cpu_eeprom_sysfs { + _banner "Show CPU EEPROM" + + cpu_eeprom=$(eval "cat ${cpu_eeprom_sysfs} ${LOG_REDIRECT} | hexdump -C") + _echo "[CPU EEPROM]:" + _echo "${cpu_eeprom}" +} + + + +function _show_bmc_device_status { + _banner "Show BMC Device Status" + + _check_bmc_device + find_bmc_dev=$? + if [[ find_bmc_dev -eq ${FALSE} ]]; then + _echo "Not support!" + return + fi + # Get PSU 1 + psu1_hw_revision=$(eval "ipmitool raw 0x34 0x16 ${bmc_psu1_id} 0x14 ${LOG_REDIRECT}") + psu1_mfr_id=$(eval "ipmitool raw 0x34 0x16 ${bmc_psu1_id} 0x12 ${LOG_REDIRECT}") + psu1_data=$(eval " ipmitool raw 0x34 0x16 ${bmc_psu1_id} ${LOG_REDIRECT}") + + _echo "[PSU 1 HW revision ]:" + _echo " ${psu1_hw_revision}" + _echo "[PSU 1 MFR ID ]:" + _echo " ${psu1_mfr_id}" + _echo "[PSU 1 data ]:" + _echo " ${psu1_data}" + + # Get PSU 2 + psu2_hw_revision=$(eval "ipmitool raw 0x34 0x16 ${bmc_psu2_id} 0x14 ${LOG_REDIRECT}") + psu2_mfr_id=$(eval "ipmitool raw 0x34 0x16 ${bmc_psu2_id} 0x12 ${LOG_REDIRECT}") + psu2_data=$(eval " ipmitool raw 0x34 0x16 ${bmc_psu2_id} ${LOG_REDIRECT}") + + _echo "[PSU 2 HW revision ]:" + _echo " ${psu2_hw_revision}" + _echo "[PSU 2 MFR ID ]:" + _echo " ${psu2_mfr_id}" + _echo "[PSU 2 data ]:" + _echo " ${psu2_data}" +} + +function _show_cpu_eeprom { + + if [[ -f "${cpu_eeprom_sysfs}" ]]; then + _show_cpu_eeprom_sysfs ${cpu_eeprom_sysfs} + else + _show_cpu_eeprom_i2c ${cpu_eeprom_bus_id} ${cpu_eeprom_i2c_addr} + fi +} + +function _show_psu_status_cpld_sysfs { + _banner "Show PSU Status (CPLD)" + + # Read PSU Status + _check_filepath "${psu1_present_sysfs}" + _check_filepath "${psu1_power_good_sysfs}" + _check_filepath "${psu2_present_sysfs}" + _check_filepath "${psu2_power_good_sysfs}" + + # Read PSU1 Present Status (1: psu present, 0: psu absent) + psu1_present=$(eval "cat ${psu1_present_sysfs} ${LOG_REDIRECT}") + + # Read PSU1 Power Good Status (1: power good, 0: not providing power) + psu1_power_good=$(eval "cat ${psu1_power_good_sysfs} ${LOG_REDIRECT}") + + # Read PSU2 Present Status (1: psu present, 0: psu absent) + psu2_present=$(eval "cat ${psu2_present_sysfs} ${LOG_REDIRECT}") + + # Read PSU2 Power Good Status (1: power good, 0: not providing power) + psu2_power_good=$(eval "cat ${psu2_power_good_sysfs} ${LOG_REDIRECT}") + + _echo "[PSU1 Present Status (L)]: ${psu1_present}" + _echo "[PSU1 Power Good Status]: ${psu1_power_good}" + _echo "[PSU2 Present Status (L)]: ${psu2_present}" + _echo "[PSU2 Power Good Status]: ${psu2_power_good}" +} + +function _show_psu_status_cpld { + _show_psu_status_cpld_sysfs +} + +function _show_sfp_port_status_sysfs { + _banner "Show SFP Port Status / EEPROM" + echo " Show SFP Port Status / EEPROM, please wait..." + + if [ ${support_sfp} -eq 0 ]; then + _echo "Not support!" + return + fi + + for (( i=0; i<${#sfp_port_array[@]}; i++ )) + do + # Module SFP Port RX LOS (0:Undetected, 1:Detected) + port_rx_los="" + sysfs=$(_sfp_get_rx_los_func "$i") + if [ -n "$sysfs" ] && [ -f "$sysfs" ]; then + port_rx_los=$(eval "cat $sysfs ${LOG_REDIRECT}") + fi + + # Module SFP Port Present Status (1:Present, 0:Absence) + port_present="" + sysfs=$(_sfp_get_present_func "$i") + if [ -n "$sysfs" ] && [ -f "$sysfs" ]; then + port_present=$(eval "cat $sysfs ${LOG_REDIRECT}") + fi + + # Module SFP Port TX FAULT (0:Undetected, 1:Detected) + port_tx_fault="" + sysfs=$(_sfp_get_tx_fault_func "$i") + if [ -n "$sysfs" ] && [ -f "$sysfs" ]; then + port_tx_fault=$(eval "cat $sysfs ${LOG_REDIRECT}") + fi + + # Module SFP Port TX DISABLE (0:Disabled, 1:Enabled) + port_tx_disable="" + sysfs=$(_sfp_get_tx_disable_func "$i") + if [ -n "$sysfs" ] && [ -f "$sysfs" ]; then + port_tx_disable=$(eval "cat $sysfs ${LOG_REDIRECT}") + fi + + + # Module SFP Port Dump EEPROM + if [ "${port_present}" == "1" ]; then + sysfs=$(_sfp_get_eeprom_func "$i") + _check_filepath $sysfs + port_eeprom_p0_1st=$(eval "dd if=$sysfs bs=128 count=2 skip=0 status=none ${LOG_REDIRECT} | hexdump -C") + port_eeprom_p0_2nd=$(eval "dd if=$sysfs bs=128 count=2 skip=0 status=none ${LOG_REDIRECT} | hexdump -C") + if [ -z "$port_eeprom_p0_1st" ]; then + port_eeprom_p0_1st="ERROR!!! The result is empty. It should read failed ($sysfs)!!" + fi + + # Full EEPROM Log + if [ "${LOG_FILE_ENABLE}" == "1" ]; then + hexdump -C $sysfs > ${LOG_FOLDER_PATH}/sfp_port${sfp_port_array[i]}_eeprom.log 2>&1 + fi + else + port_eeprom_p0_1st="N/A" + port_eeprom_p0_2nd="N/A" + fi + + if [ ! -z ${port_rx_los} ]; then + _echo "[SFP Port${sfp_port_array[i]} RX LOS]: ${port_rx_los}" + fi + + if [ ! -z ${port_present} ]; then + _echo "[SFP Port${sfp_port_array[i]} Module Present]: ${port_present}" + fi + + if [ ! -z ${port_tx_fault} ]; then + _echo "[SFP Port${sfp_port_array[i]} TX FAULT]: ${port_tx_fault}" + fi + + if [ ! -z ${port_tx_disable} ]; then + _echo "[SFP Port${sfp_port_array[i]} TX DISABLE]: ${port_tx_disable}" + fi + + _echo "[Port${sfp_port_array[i]} EEPROM Page0-0(1st)]:" + _echo "${port_eeprom_p0_1st}" + _echo "[Port${sfp_port_array[i]} EEPROM Page0-0(2nd)]:" + _echo "${port_eeprom_p0_2nd}" + _echo "" + done +} + +function _show_sfp_port_status { + _show_sfp_port_status_sysfs +} + +function _show_qsfpdd_port_status_sysfs { + _banner "Show QSFPDD Port Status / EEPROM" + echo " Show QSFPDD Port Status / EEPROM, please wait..." + + if [ ${support_qsfpdd} -eq 0 ]; then + _echo "Not support!" + return + fi + + for (( i=0; i<${#qsfp_port_array[@]}; i++ )) + do + # Module QSFPDD Port Present Status (1: Present, 0:Absence) + port_module_present="" + sysfs=$(_qsfpdd_get_present_func "$i") + if [ -n "$sysfs" ] && [ -f "$sysfs" ]; then + port_module_present=$(eval "cat $sysfs ${LOG_REDIRECT}") + fi + + # Module QSFPDD Port Get Low Power Mode Status (0: Normal Power Mode, 1:Low Power Mode) + port_lp_mode="" + sysfs=$(_qsfpdd_get_lp_mode_func "$i") + if [ -n "$sysfs" ] && [ -f "$sysfs" ]; then + port_lp_mode=$(eval "cat $sysfs ${LOG_REDIRECT}") + fi + + # Module QSFPDD Port Reset Status (0:Reset, 1:Normal) + port_reset="" + sysfs=$(_qsfpdd_get_reset_func "$i") + if [ -n "$sysfs" ] && [ -f "$sysfs" ]; then + port_reset=$(eval "cat $sysfs ${LOG_REDIRECT}") + fi + + # Module QSFPDD Port Dump EEPROM + if [ "${port_module_present}" == "1" ]; then + sysfs=$(_qsfpdd_get_eeprom_func "$i") + _check_filepath $sysfs + port_eeprom_p0_1st=$(eval "dd if=$sysfs bs=128 count=2 skip=0 status=none ${LOG_REDIRECT} | hexdump -C") + port_eeprom_p0_2nd=$(eval "dd if=$sysfs bs=128 count=2 skip=0 status=none ${LOG_REDIRECT} | hexdump -C") + port_eeprom_p17_1st=$(eval "dd if=$sysfs bs=128 count=1 skip=18 status=none ${LOG_REDIRECT} | hexdump -C") + port_eeprom_p17_2nd=$(eval "dd if=$sysfs bs=128 count=1 skip=18 status=none ${LOG_REDIRECT} | hexdump -C") + port_eeprom_p18=$(eval "dd if=$sysfs bs=128 count=1 skip=19 status=none ${LOG_REDIRECT} | hexdump -C") + if [ -z "$port_eeprom_p0_1st" ]; then + port_eeprom_p0_1st="ERROR!!! The result is empty. It should read failed ($sysfs)!!" + fi + + # Full EEPROM Log + if [ "${LOG_FILE_ENABLE}" == "1" ]; then + hexdump -C $sysfs > ${LOG_FOLDER_PATH}/qsfpdd_port${qsfp_port_array[i]}_eeprom.log 2>&1 + fi + else + port_eeprom_p0_1st="N/A" + port_eeprom_p0_2nd="N/A" + port_eeprom_p17_1st="N/A" + port_eeprom_p17_2nd="N/A" + port_eeprom_p18="N/A" + fi + + + + if [ ! -z ${port_module_present} ]; then + _echo "[QSFPDD Port${qsfp_port_array[i]} Module Present ]: ${port_module_present}" + fi + + if [ ! -z ${port_lp_mode} ]; then + _echo "[QSFPDD Port${qsfp_port_array[i]} Low Power Mode]: ${port_lp_mode}" + fi + + if [ ! -z ${port_reset} ]; then + _echo "[QSFPDD Port${qsfp_port_array[i]} Reset Status]: ${port_reset}" + fi + _echo "[Port${qsfp_port_array[i]} EEPROM Page0-0(1st)]:" + _echo "${port_eeprom_p0_1st}" + _echo "[Port${qsfp_port_array[i]} EEPROM Page0-0(2nd)]:" + _echo "${port_eeprom_p0_2nd}" + _echo "[Port${qsfp_port_array[i]} EEPROM Page17 (1st)]:" + _echo "${port_eeprom_p17_1st}" + _echo "[Port${qsfp_port_array[i]} EEPROM Page17 (2nd)]:" + _echo "${port_eeprom_p17_2nd}" + _echo "[Port${qsfp_port_array[i]} EEPROM Page18 ]:" + _echo "${port_eeprom_p18}" + _echo "" + done +} + +function _show_qsfpdd_port_status { + _show_qsfpdd_port_status_sysfs +} + +function _show_cpu_temperature_sysfs { + _banner "show CPU Temperature" + + for (( i=0; i<${#cpu_temp_bus_id_array[@]}; i++ )) + do + if [ -f "/sys/devices/platform/coretemp.0/hwmon/${cpu_temp_hwmon}/temp${cpu_temp_bus_id_array[i]}_input" ]; then + _check_filepath "/sys/devices/platform/coretemp.0/hwmon/${cpu_temp_hwmon}/temp${cpu_temp_bus_id_array[i]}_input" + _check_filepath "/sys/devices/platform/coretemp.0/hwmon/${cpu_temp_hwmon}/temp${cpu_temp_bus_id_array[i]}_max" + _check_filepath "/sys/devices/platform/coretemp.0/hwmon/${cpu_temp_hwmon}/temp${cpu_temp_bus_id_array[i]}_crit" + temp_input=$(eval "cat /sys/devices/platform/coretemp.0/hwmon/${cpu_temp_hwmon}/temp${cpu_temp_bus_id_array[i]}_input ${LOG_REDIRECT}") + temp_max=$(eval "cat /sys/devices/platform/coretemp.0/hwmon/${cpu_temp_hwmon}/temp${cpu_temp_bus_id_array[i]}_max ${LOG_REDIRECT}") + temp_crit=$(eval "cat /sys/devices/platform/coretemp.0/hwmon/${cpu_temp_hwmon}/temp${cpu_temp_bus_id_array[i]}_crit ${LOG_REDIRECT}") + elif [ -f "/sys/devices/platform/coretemp.0/temp${cpu_temp_bus_id_array[i]}_input" ]; then + _check_filepath "/sys/devices/platform/coretemp.0/temp${cpu_temp_bus_id_array[i]}_input" + _check_filepath "/sys/devices/platform/coretemp.0/temp${cpu_temp_bus_id_array[i]}_max" + _check_filepath "/sys/devices/platform/coretemp.0/temp${cpu_temp_bus_id_array[i]}_crit" + temp_input=$(eval "cat /sys/devices/platform/coretemp.0/temp${cpu_temp_bus_id_array[i]}_input ${LOG_REDIRECT}") + temp_max=$(eval "cat /sys/devices/platform/coretemp.0/temp${cpu_temp_bus_id_array[i]}_max ${LOG_REDIRECT}") + temp_crit=$(eval "cat /sys/devices/platform/coretemp.0/temp${cpu_temp_bus_id_array[i]}_crit ${LOG_REDIRECT}") + else + _echo "sysfs of CPU core temperature not found!!!" + fi + + _echo "[CPU Core Temp${cpu_temp_bus_id_array[i]} Input ]: ${temp_input}" + _echo "[CPU Core Temp${cpu_temp_bus_id_array[i]} Max ]: ${temp_max}" + _echo "[CPU Core Temp${cpu_temp_bus_id_array[i]} Crit ]: ${temp_crit}" + _echo "" + done +} + +function _show_cpu_temperature { + _show_cpu_temperature_sysfs +} + +function _show_system_led_sysfs { + _banner "Show System LED" + + for (( i=0; i<${#sys_led_array[@]}; i++ )) + do + sysfs=${sys_led_sysfs[i]} + _check_filepath $sysfs + + system_led=$(eval "cat $sysfs ${LOG_REDIRECT}") + _echo "[System LED ${sys_led_array[i]^^}]: ${system_led}" + done +} + +function _show_system_led { + _show_system_led_sysfs +} + +function _show_beacon_led_sysfs { + _banner "Show Beacon LED" + + sysfs=${sys_beacon_led_sysfs} + + if [[ ! -f ${sysfs} ]]; then + _echo "Not support!" + return + fi + beacon_led=$(eval "cat $sysfs ${LOG_REDIRECT}") + _echo "[Beacon LED]: ${beacon_led}" +} + +function _show_beacon_led { + _show_beacon_led_sysfs +} + +function _show_version { + + _banner "Show Version" + + ret=$(eval "onlpdump -x") + + _echo "${ret}" +} + +function _show_i2c_tree_bus_0 { + _banner "Show I2C Tree Bus 0" + + ret=$(eval "i2cdetect -y 0 ${LOG_REDIRECT}") + + _echo "[I2C Tree]:" + _echo "${ret}" +} + +function _show_i2c_mux_devices { + local chip_addr=$1 + local channel_num=$2 + local chip_dev_desc=$3 + local i=0; + + if [ -z "${chip_addr}" ] || [ -z "${channel_num}" ] || [ -z "${chip_dev_desc}" ]; then + _echo "ERROR: parameter cannot be empty!!!" + exit 99 + fi + + _check_i2c_device "$chip_addr" + ret=$? + if [ "$ret" == "0" ]; then + _echo "TCA9548 Mux ${chip_dev_desc}" + _echo "---------------------------------------------------" + for (( i=0; i<${channel_num}; i++ )) + do + _echo "TCA9548 Mux ${chip_dev_desc} - Channel ${i}" + # open mux channel + i2cset -y 0 ${chip_addr} $(( 2 ** ${i} )) + # dump i2c tree + ret=$(eval "i2cdetect -y 0 ${LOG_REDIRECT}") + _echo "${ret}" + # close mux channel + i2cset -y 0 ${chip_addr} 0x0 + _echo "" + done + fi + +} + +function _show_i2c_tree_bus_mux_i2c { + + if [ "${OPT_BYPASS_I2C_COMMAND}" == "${TRUE}" ]; then + _banner "Show I2C Tree Bus MUX (I2C) (Bypass)" + return + fi + + _banner "Show I2C Tree Bus MUX (I2C)" + + local i=0 + local chip_addr1="" + local chip_addr2="" + local chip_addr3="" + local chip_addr1_chann="" + local chip_addr2_chann="" + +} + +function _show_i2c_tree { + _banner "Show I2C Tree" + + _show_i2c_tree_bus_0 + + if [ "${BSP_INIT_FLAG}" == "1" ]; then + _echo "TBD" + else + _show_i2c_tree_bus_mux_i2c + fi + + _show_i2c_tree_bus_0 +} + +function _show_i2c_device_info { + _banner "Show I2C Device Info" + + ret=`i2cdump -y -f 0 0x77 b` + _echo "[I2C Device 0x77]:" + _echo "${ret}" + _echo "" + + local pca954x_device_id=("") + + for ((i=0;i<5;i++)) + do + _echo "[DEV PCA9548 (${i})]" + for (( j=0; j<${#pca954x_device_id[@]}; j++ )) + do + ret=`i2cget -f -y 0 ${pca954x_device_id[$j]}` + _echo "[I2C Device ${pca954x_device_id[$j]}]: $ret" + done + sleep 0.4 + done +} + +function _show_usb_info { + _banner "Show USB Info" + + _echo "[Command]: lsusb -t" + ret=$(eval "lsusb -t ${LOG_REDIRECT}") + _echo "${ret}" + _echo "" + + _echo "[Command]: lsusb -v" + ret=$(eval "lsusb -v ${LOG_REDIRECT}") + _echo "${ret}" + _echo "" + + _echo "[Command]: grep 046b /sys/bus/usb/devices/*/idVendor" + ret=$(eval "grep 046b /sys/bus/usb/devices/*/idVendor ${LOG_REDIRECT}") + _echo "${ret}" + _echo "" + + # check usb auth + _echo "[USB Port Authentication]: " + + for (( i=0; i<${#usb_auth_file_array[@]}; i++ )) + do + _check_filepath "${usb_auth_file_array[$i]}" + if [ -f "${usb_auth_file_array[$i]}" ]; then + ret=$(eval "cat ${usb_auth_file_array[$i]} ${LOG_REDIRECT}") + _echo "${usb_auth_file_array[$i]}: $ret" + else + _echo "${usb_auth_file_array[$i]}: -1" + fi + done +} + +function _show_ioport { + _banner "Show ioport (LPC)" + + _echo "Not support!" + return +} + +function _show_onlpdump { + _banner "Show onlpdump" + + which onlpdump > /dev/null 2>&1 + ret_onlpdump=$? + + if [ ${ret_onlpdump} -eq 0 ]; then + cmd_array=("onlpdump -d" \ + "onlpdump -s" \ + "onlpdump -r" \ + "onlpdump -e" \ + "onlpdump -o" \ + "onlpdump -x" \ + "onlpdump -i" \ + "onlpdump -p" \ + "onlpdump -S") + for (( i=0; i<${#cmd_array[@]}; i++ )) + do + _echo "[Command]: ${cmd_array[$i]}" + ret=$(eval "${cmd_array[$i]} ${LOG_REDIRECT} | tr -d '\0'") + _echo "${ret}" + _echo "" + done + else + _echo "Not support!" + fi +} + +function _show_onlps { + _banner "Show onlps" + + which onlps > /dev/null 2>&1 + ret_onlps=$? + + if [ ${ret_onlps} -eq 0 ]; then + cmd_array=("onlps chassis onie show -" \ + "onlps chassis asset show -" \ + "onlps chassis env -" \ + "onlps sfp inventory -" \ + "onlps sfp bitmaps -" \ + "onlps chassis debug show -") + for (( i=0; i<${#cmd_array[@]}; i++ )) + do + _echo "[Command]: ${cmd_array[$i]}" + ret=$(eval "${cmd_array[$i]} ${LOG_REDIRECT} | tr -d '\0'") + _echo "${ret}" + _echo "" + done + else + _echo "Not support!" + fi +} + +#require skld cpu cpld 1.12.016 and later +function _show_cpld_error_log { + _banner "Show CPLD Error Log" + + _echo "Not support!" + return +} + +# Note: In order to prevent affecting MCE mechanism, +# the function will not clear the 0x425 and 0x429 registers at step 1.1/1.2, +# and only use to show the current correctable error count. +function _show_memory_correctable_error_count { + _banner "Show Memory Correctable Error Count" + + which rdmsr > /dev/null 2>&1 + ret_rdmsr=$? + which wrmsr > /dev/null 2>&1 + ret_wrmsr=$? + + if [ ${ret_rdmsr} -eq 0 ] && [ ${ret_wrmsr} -eq 0 ]; then + ERROR_COUNT_THREASHOLD=12438 + modprobe msr + + # Step 0.1: Before clear the register, dump the correctable error count in channel 0 bank 9 + reg_c0_str=`rdmsr -p0 0x425 2> /dev/null` + if [ "${reg_c0_str}" == "" ]; then + reg_c0_str="0" + fi + reg_c0_value=`printf "%u\n" 0x${reg_c0_str}` + # CORRECTED_ERR_COUNT bit[52:38] + error_count_c0=$(((reg_c0_value >> 38) & 0x7FFF)) + _echo "[Ori_C0_Error_Count]: ${error_count_c0}" + + # Step 0.2: Before clear the register, dump the correctable error count in channel 1 bank 10 + reg_c1_str=`rdmsr -p0 0x429 2> /dev/null` + if [ "${reg_c1_str}" == "" ]; then + reg_c1_str="0" + fi + reg_c1_value=`printf "%u\n" 0x${reg_c1_str}` + # CORRECTED_ERR_COUNT bit[52:38] + error_count_c1=$(((reg_c1_value >> 38) & 0x7FFF)) + _echo "[Ori_C1_Error_Count]: ${error_count_c1}" + + # Step 1.1: clear correctable error count in channel 0 bank 9 + #wrmsr -p0 0x425 0x0 + + # Step 1.2: clear correctable error count in channel 1 bank 10 + #wrmsr -p0 0x429 0x0 + + # Step 2: wait 2 seconds + sleep 2 + + # Step 3.1: Read correctable error count in channel 0 bank 9 + reg_c0_str=`rdmsr -p0 0x425 2> /dev/null` + if [ "${reg_c0_str}" == "" ]; then + reg_c0_str="0" + fi + reg_c0_value=`printf "%u\n" 0x${reg_c0_str}` + # CORRECTED_ERR_COUNT bit[52:38] + error_count_c0=$(((reg_c0_value >> 38) & 0x7FFF)) + if [ ${error_count_c0} -gt ${ERROR_COUNT_THREASHOLD} ]; then + _echo "[ERROR] Channel 0 Bank 9 Register Value: 0x${reg_c0_str}, Error Count: ${error_count_c0}" + else + _echo "[Info] Channel 0 Bank 9 Register Value: 0x${reg_c0_str}, Error Count: ${error_count_c0}" + fi + + # Step 3.2: Read correctable error count in channel 1 bank 10 + reg_c1_str=`rdmsr -p0 0x429 2> /dev/null` + if [ "${reg_c1_str}" == "" ]; then + reg_c1_str="0" + fi + reg_c1_value=`printf "%u\n" 0x${reg_c1_str}` + # CORRECTED_ERR_COUNT bit[52:38] + error_count_c1=$(((reg_c1_value >> 38) & 0x7FFF)) + if [ ${error_count_c1} -gt ${ERROR_COUNT_THREASHOLD} ]; then + _echo "[ERROR] Channel 1 Bank 10 Register Value: 0x${reg_c1_str}, Error Count: ${error_count_c1}" + else + _echo "[Info] Channel 1 Bank 10 Register Value: 0x${reg_c1_str}, Error Count: ${error_count_c1}" + fi + else + _echo "Not support! Please install msr-tools to enble this function." + fi +} + +function _show_scsi_device_info { + _banner "Show SCSI Device Info" + + scsi_device_info=$(eval "cat /proc/scsi/sg/device_strs ${LOG_REDIRECT}") + _echo "[SCSI Device Info]: " + _echo "${scsi_device_info}" + _echo "" +} + +function _show_onie_upgrade_info { + _banner "Show ONIE Upgrade Info" + + if [ -d "/sys/firmware/efi" ]; then + if [ ! -d "/mnt/onie-boot/" ]; then + mkdir /mnt/onie-boot + fi + + mount LABEL=ONIE-BOOT /mnt/onie-boot/ + onie_show_version=`/mnt/onie-boot/onie/tools/bin/onie-version| tr -d '\000'` + onie_show_pending=`/mnt/onie-boot/onie/tools/bin/onie-fwpkg show-pending| tr -d '\000'` + onie_show_result=`/mnt/onie-boot/onie/tools/bin/onie-fwpkg show-results| tr -d '\000'` + onie_show_log=`/mnt/onie-boot/onie/tools/bin/onie-fwpkg show-log| tr -d '\000'` + umount /mnt/onie-boot/ + + _echo "[ONIE Show Version]:" + _echo "${onie_show_version}" + _echo "" + _echo "[ONIE Show Pending]:" + _echo "${onie_show_pending}" + _echo "" + _echo "[ONIE Show Result ]:" + _echo "${onie_show_result}" + _echo "" + _echo "[ONIE Show Log ]:" + _echo "${onie_show_log}" + else + _echo "BIOS is in Legacy Mode!!!!!" + fi +} + +function _show_disk_info { + _banner "Show Disk Info" + + cmd_array=("lsblk" \ + "parted -l /dev/sda" \ + "fdisk -l /dev/sda" \ + "find /sys/fs/ -name errors_count -print -exec cat {} \;" \ + "find /sys/fs/ -name first_error_time -print -exec cat {} \; -exec echo '' \;" \ + "find /sys/fs/ -name last_error_time -print -exec cat {} \; -exec echo '' \;" \ + "df -h") + + for (( i=0; i<${#cmd_array[@]}; i++ )) + do + _echo "[Command]: ${cmd_array[$i]}" + ret=$(eval "${cmd_array[$i]} ${LOG_REDIRECT}") + _echo "${ret}" + _echo "" + done + + # check smartctl command + cmd="smartctl -a /dev/sda" + ret=`which smartctl` + if [ ! $? -eq 0 ]; then + _echo "[command]: ($cmd) not found (SKIP)!!" + else + ret=$(eval "$cmd ${LOG_REDIRECT}") + _echo "[command]: $cmd" + _echo "${ret}" + fi +} + +function _show_lspci { + _banner "Show lspci Info" + + ret=`lspci` + _echo "${ret}" + _echo "" +} + +function _show_lspci_detail { + _banner "Show lspci Detail Info" + + ret=$(eval "lspci -xxxx -vvv ${LOG_REDIRECT}") + _echo "${ret}" +} + +function _show_proc_interrupt { + _banner "Show Proc Interrupts" + + for i in {1..5}; + do + ret=$(eval "cat /proc/interrupts ${LOG_REDIRECT}") + _echo "[Proc Interrupts ($i)]:" + _echo "${ret}" + _echo "" + sleep 1 + done +} + +function _show_ipmi_info { + _banner "Show IPMI Info" + + ipmi_folder="/proc/ipmi/0/" + + if [ -d "${ipmi_folder}" ]; then + ipmi_file_array=($(ls ${ipmi_folder})) + for (( i=0; i<${#ipmi_file_array[@]}; i++ )) + do + _echo "[Command]: cat ${ipmi_folder}/${ipmi_file_array[$i]} " + ret=$(eval "cat "${ipmi_folder}/${ipmi_file_array[$i]}" ${LOG_REDIRECT}") + _echo "${ret}" + _echo "" + done + else + _echo "Warning, folder not found (${ipmi_folder})!!!" + fi + + _echo "[Command]: lsmod | grep ipmi " + ret=`lsmod | grep ipmi` + _echo "${ret}" +} + +function _show_bios_info { + _banner "Show BIOS Info" + + cmd_array=("dmidecode -t 0" \ + "dmidecode -t 1" \ + "dmidecode -t 2" \ + "dmidecode -t 3") + + for (( i=0; i<${#cmd_array[@]}; i++ )) + do + _echo "[Command]: ${cmd_array[$i]} " + ret=$(eval "${cmd_array[$i]} ${LOG_REDIRECT}") + _echo "${ret}" + _echo "" + done +} + +function _show_bios_flash { + _banner "Show BIOS Flash" + + if [ ${support_bios_flash} -eq 0 ]; then + _echo "Not support!" + return + fi + + ret=$(eval "cat ${bios_boot_flash_sysfs} ${LOG_REDIRECT}") + + if [[ ! -z "${ret}" ]]; then + if [[ ${ret} -eq 1 ]]; then + _echo "Master" + elif [[ ${ret} -eq 2 ]]; then + _echo "Slave" + else + _echo "Not defined!" + fi + else + _echo "Not support!" + fi +} + +function _show_dmesg { + _banner "Show Dmesg" + + ret=$(eval "dmesg ${LOG_REDIRECT}") + _echo "${ret}" +} + +function _additional_log_collection { + _banner "Additional Log Collection" + + if [ -z "${LOG_FOLDER_PATH}" ] || [ ! -d "${LOG_FOLDER_PATH}" ]; then + _echo "LOG_FOLDER_PATH (${LOG_FOLDER_PATH}) not found!!!" + _echo "do nothing..." + else + #_echo "copy /var/log/syslog* to ${LOG_FOLDER_PATH}" + #cp /var/log/syslog* "${LOG_FOLDER_PATH}" + + if [ -f "/var/log/kern.log" ]; then + _echo "copy /var/log/kern.log* to ${LOG_FOLDER_PATH}" + cp /var/log/kern.log* "${LOG_FOLDER_PATH}" + fi + + if [ -f "/var/log/dmesg" ]; then + _echo "copy /var/log/dmesg* to ${LOG_FOLDER_PATH}" + cp /var/log/dmesg* "${LOG_FOLDER_PATH}" + fi + fi +} + +function _show_time { + _banner "Show Execution Time" + end_time=$(date +%s) + elapsed_time=$(( end_time - start_time )) + + ret=`date -d @${start_time}` + _echo "[Start Time ] ${ret}" + + ret=`date -d @${end_time}` + _echo "[End Time ] ${ret}" + + _echo "[Elapse Time] ${elapsed_time} seconds" +} + +function _compression { + _banner "Compression" + + if [ ! -z "${LOG_FOLDER_PATH}" ] && [ -d "${LOG_FOLDER_PATH}" ]; then + cd "${LOG_FOLDER_ROOT}" + tar -zcf "${LOG_FOLDER_NAME}".tgz "${LOG_FOLDER_NAME}" + + echo "The tarball is ready at ${LOG_FOLDER_ROOT}/${LOG_FOLDER_NAME}.tgz" + _echo "The tarball is ready at ${LOG_FOLDER_ROOT}/${LOG_FOLDER_NAME}.tgz" + fi +} + +usage() { + local f=$(basename "$0") + echo "" + echo "Usage:" + echo " $f [-b] [-d D_DIR] [-h] [-i identifier] [-v]" + echo "Description:" + echo " -b bypass i2c command (required when NOS vendor use their own platform bsp to control i2c devices)" + echo " -d specify D_DIR as log destination instead of default path /tmp/log" + echo " -i insert an identifier in the log file name" + echo " -m specify the model name" + echo " -v show tech support script version" + echo "Example:" + echo " $f -d /var/log" + echo " $f -i identifier" + echo " $f -v" + exit -1 +} + +function _getopts { + local OPTSTRING=":bd:fi:m:v" + # default log dir + local log_folder_root=$DEFAULT_LOG_FOLDER_ROOT + local identifier="" + + while getopts ${OPTSTRING} opt; do + case ${opt} in + b) + OPT_BYPASS_I2C_COMMAND=${TRUE} + ;; + d) + log_folder_root=${OPTARG} + ;; + f) + LOG_FAST=${TRUE} + ;; + i) + identifier=${OPTARG} + ;; + v) + _show_ts_version + exit 0 + ;; + ?) + echo "Invalid option: -${OPTARG}." + usage + ;; + esac + done + + MODEL=$(eval "ls /mnt/onl/boot/ | grep cpio.gz | cut -d . -f 1") + + if [ -n "${MODEL}" ]; then + LIB_PATH="/lib/platform-config/${MODEL}/onl/tech_support/show_platform_log_lib.sh" + + if [[ -f ${LIB_PATH} ]]; then + source ${LIB_PATH} + else + echo "Lib script not found!" + exit 1 + fi + else + echo "Model not found !" + exit 1 + fi + + + LOG_FOLDER_ROOT=${log_folder_root} + if [ -z "$identifier" ]; then + LOG_FOLDER_NAME="${DEFAULT_LOG_FOLDER_NAME}" + LOG_FILE_NAME="${DEFAULT_LOG_FILE_NAME}" + else + LOG_FOLDER_NAME="log_platform_${identifier}_${DATESTR}" + LOG_FILE_NAME="log_platform_${identifier}_${DATESTR}.log" + fi + LOG_FOLDER_PATH="${LOG_FOLDER_ROOT}/${LOG_FOLDER_NAME}" + LOG_FILE_PATH="${LOG_FOLDER_PATH}/${LOG_FILE_NAME}" + LOG_REDIRECT="2>> $LOG_FILE_PATH" +} + +function _main { + echo "The script will take a few minutes, please wait..." + ### Basic system info ### + _check_env + _pkg_version + _pre_log + _show_board_info + _show_version + _show_system_info + _show_cpu_usage + _show_grub + _show_onie_upgrade_info + _show_proc_interrupt + _show_bios_info + _show_bios_flash + _show_dmesg + _additional_log_collection + + ### HW related info ### + #_show_i2c_tree + #_show_i2c_device_info + _show_sys_devices + _show_cpu_eeprom + _show_usb_info + _show_scsi_device_info + _show_disk_info + _show_lspci + _show_lspci_detail + _show_ioport + _show_cpld_error_log + + ### sysfs/driver info ### + _show_driver + _show_psu_status_cpld + _show_sfp_port_status + _show_qsfpdd_port_status + _show_cpu_temperature + _show_system_led + _show_beacon_led + + ### ONLP info ### + _show_onlpdump + _show_onlps + + ### BMC info ### + _show_bmc_info + _show_bmc_sensors + _show_bmc_device_status + _show_bmc_sel_raw_data + _show_bmc_sel_elist + _show_bmc_sel_elist_detail + + ### final action ### + _show_time + _compression + + echo "# The tech-support collection is completed. Please share the tech support log file." +} + +_getopts $@ +_main diff --git a/packages/platforms/accton/x86-64/as9726-32d/platform-config/r0/src/lib/tech_support/show_platform_log_lib.sh b/packages/platforms/accton/x86-64/as9726-32d/platform-config/r0/src/lib/tech_support/show_platform_log_lib.sh new file mode 100755 index 000000000..cbc340e75 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/platform-config/r0/src/lib/tech_support/show_platform_log_lib.sh @@ -0,0 +1,132 @@ +#!/bin/bash + +# CPU eeprom +cpu_eeprom_bus_id="13" +cpu_eeprom_i2c_addr="56" + +cpu_eeprom_sysfs="/sys/bus/i2c/devices/${cpu_eeprom_bus_id}-00${cpu_eeprom_i2c_addr}/eeprom" + +# BIOS flash +support_bios_flash=1 + +cpu_cpld_bus_id="1" +cpu_cpld_i2c_addr="65" +bios_boot_flash_sysfs="/sys/bus/i2c/devices/${cpu_cpld_bus_id}-00${cpu_cpld_i2c_addr}/bios_flash_id" + +# PSU sysfs +psu1_present_sysfs="/sys/bus/i2c/devices/9-0050/psu_present" +psu2_present_sysfs="/sys/bus/i2c/devices/9-0051/psu_present" +psu1_power_good_sysfs="/sys/bus/i2c/devices/9-0050/psu_power_good" +psu2_power_good_sysfs="/sys/bus/i2c/devices/9-0051/psu_power_good" + +# QSFP/SFP +support_sfp=1 +support_qsfpdd=1 +sfp_eeprom_bus_array=(49 50) +qsfp_eeprom_bus_array=(17 18 19 20 21 22 23 24 25 26 \ + 27 28 29 30 31 32 33 34 35 36 \ + 37 38 39 40 41 42 43 44 45 46 \ + 47 48) + +port_status_cpld_i2c_bus_addr_array=("10-0061" "10-0062") +sfp_port_array=(33 34) +qsfp_port_array=(1 2 3 4 5 6 7 8 9 10 \ + 11 12 13 14 15 16 17 18 19 20 \ + 21 22 23 24 25 26 27 28 29 30 \ + 31 32) + +# CPU temp +cpu_temp_hwmon=$(eval "ls /sys/devices/platform/coretemp.0/hwmon | grep hwmon") +cpu_temp_bus_id_array=("1" "2" "3" "4" "5") + +# System led +sys_led_path_prefix="accton_as9726_32d_led" +sys_led_array=("diag" "loc" "fan" "psu1" "psu2") + +sys_led_array=("diag" "loc" "fan" "psu1" "psu2") +sys_led_sysfs=("/sys/class/leds/accton_as9726_32d_led::diag/brightness" \ + "/sys/class/leds/accton_as9726_32d_led::loc/brightness" \ + "/sys/class/leds/accton_as9726_32d_led::fan/brightness" \ + "/sys/class/leds/accton_as9726_32d_led::psu1/brightness" \ + "/sys/class/leds/accton_as9726_32d_led::psu2/brightness") + +sys_beacon_led_sysfs="/sys/class/leds/accton_as9726_32d_led::loc/brightness" + +# USB +usb_auth_file_array=("/sys/bus/usb/devices/usb1/authorized" \ + "/sys/bus/usb/devices/usb1/authorized_default" \ + "/sys/bus/usb/devices/1-0:1.0/authorized" \ + "/sys/bus/usb/devices/1-1/authorized" \ + "/sys/bus/usb/devices/1-1:1.0/authorized" \ + "/sys/bus/usb/devices/usb2/authorized" \ + "/sys/bus/usb/devices/usb2/authorized_default" \ + "/sys/bus/usb/devices/2-1/authorized" \ + "/sys/bus/usb/devices/2-0:1.0/authorized" \ + "/sys/bus/usb/devices/2-1:1.0/authorized" \ + "/sys/bus/usb/devices/usb3/authorized" \ + "/sys/bus/usb/devices/usb3/authorized_default" \ + "/sys/bus/usb/devices/3-0:1.0/authorized") + +# Function SFP +cpld_bus_idx=1 +port_status_cpld_i2c_bus_addr=${port_status_cpld_i2c_bus_addr_array[$cpld_bus_idx]} + +function _sfp_get_rx_los_func { + idx=$1 + echo "/sys/bus/i2c/devices/${port_status_cpld_i2c_bus_addr}/module_rx_los_${sfp_port_array[$idx]}" +} + +function _sfp_get_present_func { + idx=$1 + echo "/sys/bus/i2c/devices/${port_status_cpld_i2c_bus_addr}/module_present_${sfp_port_array[$idx]}" +} + +function _sfp_get_tx_fault_func { + idx=$1 + echo "/sys/bus/i2c/devices/${port_status_cpld_i2c_bus_addr}/module_tx_fault_${sfp_port_array[$idx]}" +} + +function _sfp_get_tx_disable_func { + idx=$1 + echo "/sys/bus/i2c/devices/${port_status_cpld_i2c_bus_addr}/module_tx_disable_${sfp_port_array[$idx]}" +} + +function _sfp_get_eeprom_func { + idx=$1 + echo "/sys/bus/i2c/devices/${sfp_eeprom_bus_array[$idx]}-0050/eeprom" +} + +# Function QSDP-DD +function _qsfpdd_select_cpld_i2c_bus_addr_idx { + port_idx=$(($1 + 1)) + echo $(( port_idx <= 16 ? 0 : 1 )) +} + +function _qsfpdd_get_present_func { + idx=$1 + cpld_bus_idx=$(_qsfpdd_select_cpld_i2c_bus_addr_idx "$idx") + port_status_cpld_i2c_bus_addr=${port_status_cpld_i2c_bus_addr_array[$cpld_bus_idx]} + + echo "/sys/bus/i2c/devices/${port_status_cpld_i2c_bus_addr}/module_present_${qsfp_port_array[$idx]}" +} + +function _qsfpdd_get_lp_mode_func { + idx=$1 + cpld_bus_idx=$(_qsfpdd_select_cpld_i2c_bus_addr_idx "$idx") + port_status_cpld_i2c_bus_addr=${port_status_cpld_i2c_bus_addr_array[$cpld_bus_idx]} + + echo "/sys/bus/i2c/devices/${port_status_cpld_i2c_bus_addr}/module_lpmode_${qsfp_port_array[$idx]}" +} + +function _qsfpdd_get_reset_func { + idx=$1 + cpld_bus_idx=$(_qsfpdd_select_cpld_i2c_bus_addr_idx "$idx") + port_status_cpld_i2c_bus_addr=${port_status_cpld_i2c_bus_addr_array[$cpld_bus_idx]} + + echo "/sys/bus/i2c/devices/${port_status_cpld_i2c_bus_addr}/module_reset_${qsfp_port_array[$idx]}" +} + +function _qsfpdd_get_eeprom_func { + idx=$1 + echo "/sys/bus/i2c/devices/${qsfp_eeprom_bus_array[$idx]}-0050/eeprom" +} diff --git a/packages/platforms/accton/x86-64/as9726-32d/platform-config/r0/src/lib/x86-64-accton-as9726-32d-r0.yml b/packages/platforms/accton/x86-64/as9726-32d/platform-config/r0/src/lib/x86-64-accton-as9726-32d-r0.yml new file mode 100644 index 000000000..a9fa5750f --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/platform-config/r0/src/lib/x86-64-accton-as9726-32d-r0.yml @@ -0,0 +1,37 @@ +--- + +###################################################################### +# +# platform-config for AS9726 +# +###################################################################### + +x86-64-accton-as9726-32d-r0: + + grub: + + serial: >- + --port=0x3f8 + --speed=115200 + --word=8 + --parity=no + --stop=1 + + kernel: + <<: *kernel-4-19 + + args: >- + console=tty0 + console=ttyS0,115200n8 quiet nopat + intel_iommu=off + pcie_aspm=off + intremap=off + pci=nomsi + libata.force=noncq irqpoll + hpet=disable + + ##network: + ## interfaces: + ## ma1: + ## name: ~ + ## syspath: pci0000:00/0000:00:1c.0/0000:0a:00.0 diff --git a/packages/platforms/accton/x86-64/as9726-32d/platform-config/r0/src/python/x86_64_accton_as9726_32d_r0/__init__.py b/packages/platforms/accton/x86-64/as9726-32d/platform-config/r0/src/python/x86_64_accton_as9726_32d_r0/__init__.py new file mode 100644 index 000000000..96ec0efa3 --- /dev/null +++ b/packages/platforms/accton/x86-64/as9726-32d/platform-config/r0/src/python/x86_64_accton_as9726_32d_r0/__init__.py @@ -0,0 +1,76 @@ +from onl.platform.base import * +from onl.platform.accton import * + +class OnlPlatform_x86_64_accton_as9726_32d_r0(OnlPlatformAccton, + OnlPlatformPortConfig_32x400_2x10): + + PLATFORM='x86-64-accton-as9726-32d-r0' + MODEL="AS9726-32D" + SYS_OBJECT_ID=".9726.32" + + def baseconfig(self): + self.insmod('optoe') + self.insmod('accton_i2c_psu') + for m in [ 'cpld', 'fan', 'psu', 'leds' ]: + self.insmod("x86-64-accton-as9726-32d-%s.ko" % m) + + ########### initialize I2C bus 0 ########### + # initialize multiplexer (PCA9548) + self.new_i2c_device('pca9548', 0x77, 0) + # initiate multiplexer (PCA9548) + self.new_i2c_devices( + [ + # initiate multiplexer (PCA9548) + ('pca9548', 0x71, 1), + ('pca9548', 0x72, 1), + ('pca9548', 0x73, 1), + ('pca9548', 0x74, 1), + ('pca9548', 0x75, 1), + ('pca9548', 0x76, 1) + ] + ) + + self.new_i2c_devices([ + # initialize CPLD + #initiate CPLD + ('as9726_32d_cpu_cpld', 0x65, 1), + ('as9726_32d_fpga', 0x60, 1), + ('as9726_32d_cpld1', 0x61, 10), + ('as9726_32d_cpld2', 0x62, 10), + ]) + self.new_i2c_devices([ + # initiate fan + # initiate chassis fan + ('as9726_32d_fan', 0x66, 14), + + # inititate LM75 + ('lm75', 0x48, 15), + ('lm75', 0x49, 15), + ('lm75', 0x4a, 15), + ('lm75', 0x4b, 15), + ('lm75', 0x4c, 15), + ('lm75', 0x4f, 15), + ]) + + self.new_i2c_devices([ + # initiate PSU-2 + ('as9726_32d_psu2', 0x51, 9), + ('acbel_fsh082', 0x59, 9), + + # initiate PSU-1 + ('as9726_32d_psu1', 0x50, 9), + ('acbel_fsh082', 0x58, 9), + ]) + + # initialize QSFP port 1~32. SFP port 33~34 + for port in range(1, 35): + if port <= 32 : + self.new_i2c_device('optoe1', 0x50, port+16) + else: + self.new_i2c_device('optoe2', 0x50, port+16) + + subprocess.call('echo port%d > /sys/bus/i2c/devices/%d-0050/port_name' % (port, port+16), shell=True) + + self.new_i2c_device('24c02', 0x56, 13) + + return True